How function CyU3PUsbGetSpeed() inside?
Is it macros?
How it function detect type of connection (USB3 or USB2) ?
The device detection happens based on the termination resistors put by the host (down stream device).
There are different Rx terminations resistors for SuperSpeed signaling, high-speed and full-speed signalling.
Here is the abbrevation of connected in the USB 3.0 Spec (Page no. 44).
A downstream device is connected to an upstream device when it is attached to the upstream device, and when the downstream device has asserted Rx terminations for SuperSpeed signaling or has asserted the D+ or D- data line in order to enter low-speed, full-speed, or high-speed signaling.
Here is the example for USB high speed and full speed device detection. But in USB SuperSpeed case, the device connection will happen in SuperSpeed mode itself. There is no switching (Full-Speed connection first then High-Speed connection) of the connection like High Speed case.
Look in the source files for the SDK.
usb/cyu3usbpp.c and usb/cyu3usb.c contain the code that does the speed negotiation with hardware assistance. Search for "usbSpeed" and you'll find all the places where the actual speed state variable is touched. (Note that there's a glUibDeviceInfo.usbSpeed and an instance of state information at 0x40002000. You can mostly ignore the latter and focus on glUibDeviceInfo.usbSpeed and places and reasons it's being set.