Internal implementation.
Functions | |
static void | uhc_remotewakeup (bool b_enable) |
Enables or disables the remote wakeup feature of all devices connected. More... | |
static void | uhc_setup_request_callback (usb_add_t add, uhd_trans_status_t status, uint16_t payload_trans) |
Callback used to signal the end of a setup request. More... | |
Internal variables to manage the USB host stack | |
typedef void(* | uhc_sof_timeout_callback_t )(void) |
Type of callback on a SOF timeout. More... | |
static uhc_device_t | g_uhc_device_root |
Entry point of all devices connected on USB tree. More... | |
static uint8_t | uhc_enum_try |
Number of enumeration try. More... | |
static uhc_sof_timeout_callback_t | uhc_sof_timeout_callback |
Callback currently registered on a SOF timeout. More... | |
uint8_t | uhc_sof_timeout |
Number of SOF remaining before call uhc_sof_timeout_callback callback. More... | |
static uhi_api_t | uhc_uhis [] = {USB_HOST_UHI} |
Array of all UHI available. More... | |
static volatile bool | uhc_setup_request_finish |
Volatile flag to pool the end of Get USB string setup request. More... | |
static volatile bool | uhc_setup_request_finish_status |
Volatile flag to know the status of Get USB string setup request. More... | |
#define | UHC_ENUM_NB_TRY 4 |
Maximum try to enumerate a device. More... | |
#define | UHC_USB_ADD_NOT_VALID 0xFF |
Entry point of all devices connected on USB tree. More... | |
#define | UHC_DEVICE_ENUM_ADD 1 |
USB address of the USB device under enumeration process. More... | |
#define | uhc_dev_enum (&g_uhc_device_root) |
Device under enumeration process. More... | |
#define | uhc_power_running 0 |
Total power of the devices connected. More... | |
#define | UHC_NB_UHI (sizeof(uhc_uhis)/sizeof(uhc_uhis[0])) |
Number of UHI available. More... | |
Internal functions to manage the USB device enumeration | |
static void | uhc_enable_timeout_callback (uint8_t timeout, uhc_sof_timeout_callback_t callback) |
Enable a internal timeout on SOF events. More... | |
static void | uhc_enumeration_suspend (void) |
Enters a specific device in USB suspend mode Suspend the USB line or a port on USB hub. More... | |
static void | uhc_enumeration_reset (uhd_callback_reset_t callback) |
Sends the USB Reset signal on the USB line of a device. More... | |
static void | uhc_connection_tree (bool b_plug, uhc_device_t *dev) |
Manage a device plug or unplug on the USB tree. More... | |
static void | uhc_enumeration_step1 (void) |
Device enumeration step 1 Reset USB line. More... | |
static void | uhc_enumeration_step2 (void) |
Device enumeration step 2 Lets USB line in IDLE state during 20ms. More... | |
static void | uhc_enumeration_step3 (void) |
Device enumeration step 3 Reset USB line. More... | |
static void | uhc_enumeration_step4 (void) |
Device enumeration step 4 Lets USB line in IDLE state during 100ms. More... | |
static void | uhc_enumeration_step5 (void) |
Device enumeration step 5 Requests the USB device descriptor. More... | |
static void | uhc_enumeration_step6 (usb_add_t add, uhd_trans_status_t status, uint16_t payload_trans) |
Device enumeration step 6 End of Get device descriptor request. More... | |
static void | uhc_enumeration_step7 (void) |
Device enumeration step 7 Reset USB line. More... | |
static void | uhc_enumeration_step8 (void) |
Device enumeration step 8 Lets USB line in IDLE state during 100ms. More... | |
static void | uhc_enumeration_step9 (void) |
Device enumeration step 9 Send a Set address setup request. More... | |
static void | uhc_enumeration_step10 (usb_add_t add, uhd_trans_status_t status, uint16_t payload_trans) |
Device enumeration step 10 End of Set address request. More... | |
static void | uhc_enumeration_step11 (void) |
Device enumeration step 11 Updates USB host pipe with the new USB address. More... | |
static void | uhc_enumeration_step12 (usb_add_t add, uhd_trans_status_t status, uint16_t payload_trans) |
Device enumeration step 12 Requests the first USB structure of the USB configuration descriptor. More... | |
static void | uhc_enumeration_step13 (usb_add_t add, uhd_trans_status_t status, uint16_t payload_trans) |
Device enumeration step 13 Requests a complete Get configuration descriptor. More... | |
static void | uhc_enumeration_step14 (usb_add_t add, uhd_trans_status_t status, uint16_t payload_trans) |
Device enumeration step 14 Enable USB configuration, if unless one USB interface is supported by UHIs. More... | |
static void | uhc_enumeration_step15 (usb_add_t add, uhd_trans_status_t status, uint16_t payload_trans) |
Device enumeration step 15 Enables UHI interfaces. More... | |
static void | uhc_enumeration_error (uhc_enum_status_t status) |
Manage error during device enumeration. More... | |
Callbacks used by USB Host Driver (UHD) to notify events | |
void | uhc_notify_connection (bool b_plug) |
Notify device connection or disconnection. More... | |
void | uhc_notify_sof (bool b_micro) |
Notify each start of frame sent by driver. More... | |
void | uhc_notify_resume (void) |
Notify that a resume bus occurs A resume can occur after a downstream or an upstream resume. More... | |
Functions to control the USB host stack | |
void | uhc_start (void) |
Starts the host mode. More... | |
void | uhc_stop (bool b_id_stop) |
Stops the host mode. More... | |
void | uhc_suspend (bool b_remotewakeup) |
bool | uhc_is_suspend (void) |
void | uhc_resume (void) |
User functions to manage the devices | |
uint8_t | uhc_get_device_number (void) |
char * | uhc_dev_get_string_manufacturer (uhc_device_t *dev) |
char * | uhc_dev_get_string_product (uhc_device_t *dev) |
char * | uhc_dev_get_string_serial (uhc_device_t *dev) |
char * | uhc_dev_get_string (uhc_device_t *dev, uint8_t str_id) |
uint16_t | uhc_dev_get_power (uhc_device_t *dev) |
uhd_speed_t | uhc_dev_get_speed (uhc_device_t *dev) |
bool | uhc_dev_is_high_speed_support (uhc_device_t *dev) |
void | uhc_dev_reset (uhc_device_t *dev) |
#define uhc_dev_enum (&g_uhc_device_root) |
Device under enumeration process.
Referenced by uhc_connection_tree(), uhc_dev_reset(), uhc_enumeration_error(), uhc_enumeration_reset(), uhc_enumeration_step11(), uhc_enumeration_step12(), uhc_enumeration_step13(), uhc_enumeration_step14(), uhc_enumeration_step15(), uhc_enumeration_step4(), uhc_enumeration_step5(), uhc_enumeration_step6(), uhc_enumeration_step9(), and uhc_enumeration_suspend().
#define UHC_DEVICE_ENUM_ADD 1 |
USB address of the USB device under enumeration process.
Referenced by uhc_enumeration_step11(), uhc_enumeration_step12(), uhc_enumeration_step13(), uhc_enumeration_step14(), and uhc_enumeration_step9().
#define UHC_ENUM_NB_TRY 4 |
Maximum try to enumerate a device.
Referenced by uhc_enumeration_error().
Number of UHI available.
Referenced by uhc_connection_tree(), uhc_dev_reset(), uhc_enumeration_step14(), uhc_enumeration_step15(), and uhc_notify_sof().
#define uhc_power_running 0 |
Total power of the devices connected.
Referenced by uhc_connection_tree(), uhc_enumeration_step13(), and uhc_notify_connection().
#define UHC_USB_ADD_NOT_VALID 0xFF |
Entry point of all devices connected on USB tree.
Referenced by uhc_connection_tree(), uhc_get_device_number(), uhc_is_suspend(), uhc_notify_connection(), and uhc_start().
typedef void(* uhc_sof_timeout_callback_t)(void) |
Type of callback on a SOF timeout.
|
static |
Manage a device plug or unplug on the USB tree.
b_plug | true, if it is a device connection |
dev | Information about device connected or disconnected |
References g_uhc_device_root, UHC_CONNECTION_EVENT, uhc_dev_enum, uhc_enum_try, uhc_enumeration_step1(), UHC_NB_UHI, uhc_power_running, uhc_sof_timeout, UHC_USB_ADD_NOT_VALID, uhd_ep_free(), and uhi_api_t::uninstall.
Referenced by uhc_notify_connection().
uint16_t uhc_dev_get_power | ( | uhc_device_t * | dev | ) |
uhd_speed_t uhc_dev_get_speed | ( | uhc_device_t * | dev | ) |
char* uhc_dev_get_string | ( | uhc_device_t * | dev, |
uint8_t | str_id | ||
) |
References usb_str_desc_t::bLength, usb_setup_req_t::bmRequestType, usb_setup_req_t::bRequest, le16_to_cpu, usb_str_lgid_desc_t::string, uhc_setup_request_callback(), uhc_setup_request_finish, uhc_setup_request_finish_status, uhd_setup_request(), UNUSED, USB_DT_STRING, USB_REQ_DIR_IN, USB_REQ_GET_DESCRIPTOR, USB_REQ_RECIP_DEVICE, USB_REQ_TYPE_STANDARD, usb_setup_req_t::wIndex, usb_setup_req_t::wLength, and usb_setup_req_t::wValue.
Referenced by uhc_dev_get_string_manufacturer(), uhc_dev_get_string_product(), and uhc_dev_get_string_serial().
char* uhc_dev_get_string_manufacturer | ( | uhc_device_t * | dev | ) |
References uhc_dev_get_string().
char* uhc_dev_get_string_product | ( | uhc_device_t * | dev | ) |
References uhc_dev_get_string().
char* uhc_dev_get_string_serial | ( | uhc_device_t * | dev | ) |
References uhc_dev_get_string().
bool uhc_dev_is_high_speed_support | ( | uhc_device_t * | dev | ) |
References usb_setup_req_t::bmRequestType, usb_setup_req_t::bRequest, uhc_setup_request_callback(), uhc_setup_request_finish, uhc_setup_request_finish_status, uhd_setup_request(), UHD_SPEED_FULL, UHD_SPEED_HIGH, USB_DT_DEVICE_QUALIFIER, USB_REQ_DIR_IN, USB_REQ_GET_DESCRIPTOR, USB_REQ_RECIP_DEVICE, USB_REQ_TYPE_STANDARD, usb_setup_req_t::wIndex, usb_setup_req_t::wLength, and usb_setup_req_t::wValue.
void uhc_dev_reset | ( | uhc_device_t * | dev | ) |
References uhc_dev_enum, uhc_enum_try, uhc_enumeration_step3(), UHC_NB_UHI, and uhi_api_t::uninstall.
|
static |
Enable a internal timeout on SOF events.
timeout | value of timeout (ms) |
callback | Callback to call at the end of timeout |
References uhc_sof_timeout, and uhc_sof_timeout_callback.
Referenced by uhc_enumeration_step10(), uhc_enumeration_step2(), uhc_enumeration_step4(), uhc_enumeration_step6(), and uhc_enumeration_step8().
|
static |
Manage error during device enumeration.
status | Enumeration error occurred |
References uhc_dev_enum, UHC_ENUM_EVENT, UHC_ENUM_NB_TRY, uhc_enum_try, uhc_enumeration_step1(), uhc_enumeration_suspend(), and uhd_ep_free().
Referenced by uhc_enumeration_step10(), uhc_enumeration_step11(), uhc_enumeration_step12(), uhc_enumeration_step13(), uhc_enumeration_step14(), uhc_enumeration_step15(), uhc_enumeration_step5(), uhc_enumeration_step6(), and uhc_enumeration_step9().
|
static |
Sends the USB Reset signal on the USB line of a device.
callback | Callback to call at the end of Reset signal |
References g_uhc_device_root, uhc_dev_enum, and uhd_send_reset().
Referenced by uhc_enumeration_step1(), uhc_enumeration_step3(), and uhc_enumeration_step7().
|
static |
Device enumeration step 1 Reset USB line.
References uhc_enumeration_reset(), and uhc_enumeration_step2().
Referenced by uhc_connection_tree(), and uhc_enumeration_error().
|
static |
Device enumeration step 10 End of Set address request.
Lets USB line in IDLE state during 20ms.
add | USB address of the setup request |
status | Transfer status |
payload_trans | Number of data transfered during DATA phase |
References uhc_enable_timeout_callback(), uhc_enumeration_error(), uhc_enumeration_step11(), UHD_TRANS_DISCONNECT, UHD_TRANS_NOERROR, and UNUSED.
Referenced by uhc_enumeration_step9().
|
static |
Device enumeration step 11 Updates USB host pipe with the new USB address.
Requests a complete USB device descriptor.
References usb_setup_req_t::bmRequestType, usb_setup_req_t::bRequest, uhc_dev_enum, UHC_DEVICE_ENUM_ADD, uhc_enumeration_error(), uhc_enumeration_step12(), uhd_ep0_alloc(), uhd_ep_free(), uhd_setup_request(), USB_DT_DEVICE, USB_REQ_DIR_IN, USB_REQ_GET_DESCRIPTOR, USB_REQ_RECIP_DEVICE, USB_REQ_TYPE_STANDARD, usb_setup_req_t::wIndex, usb_setup_req_t::wLength, and usb_setup_req_t::wValue.
Referenced by uhc_enumeration_step10().
|
static |
Device enumeration step 12 Requests the first USB structure of the USB configuration descriptor.
add | USB address of the setup request |
status | Transfer status |
payload_trans | Number of data transfered during DATA phase |
References Assert, usb_setup_req_t::bmRequestType, usb_setup_req_t::bRequest, uhc_dev_enum, UHC_DEVICE_CONF, UHC_DEVICE_ENUM_ADD, uhc_enumeration_error(), uhc_enumeration_step13(), uhd_setup_request(), UHD_TRANS_DISCONNECT, UHD_TRANS_NOERROR, UNUSED, USB_DT_CONFIGURATION, USB_DT_DEVICE, USB_REQ_DIR_IN, USB_REQ_GET_DESCRIPTOR, USB_REQ_RECIP_DEVICE, USB_REQ_TYPE_STANDARD, usb_setup_req_t::wIndex, usb_setup_req_t::wLength, and usb_setup_req_t::wValue.
Referenced by uhc_enumeration_step11().
|
static |
Device enumeration step 13 Requests a complete Get configuration descriptor.
add | USB address of the setup request |
status | Transfer status |
payload_trans | Number of data transfered during DATA phase |
References Assert, usb_setup_req_t::bmRequestType, usb_setup_req_t::bRequest, g_uhc_device_root, le16_to_cpu, uhc_dev_enum, UHC_DEVICE_ENUM_ADD, UHC_ENUM_EVENT, uhc_enumeration_error(), uhc_enumeration_step14(), uhc_enumeration_suspend(), uhc_power_running, uhd_setup_request(), UHD_TRANS_DISCONNECT, UHD_TRANS_NOERROR, UNUSED, USB_CONFIG_ATTR_SELF_POWERED, USB_DT_CONFIGURATION, USB_HOST_POWER_MAX, USB_REQ_DIR_IN, USB_REQ_GET_DESCRIPTOR, USB_REQ_RECIP_DEVICE, USB_REQ_TYPE_STANDARD, usb_setup_req_t::wIndex, usb_setup_req_t::wLength, and usb_setup_req_t::wValue.
Referenced by uhc_enumeration_step12().
|
static |
Device enumeration step 14 Enable USB configuration, if unless one USB interface is supported by UHIs.
add | USB address of the setup request |
status | Transfer status |
payload_trans | Number of data transfered during DATA phase |
References usb_setup_req_t::bmRequestType, usb_setup_req_t::bRequest, le16_to_cpu, uhc_dev_enum, UHC_DEVICE_ENUM_ADD, UHC_ENUM_EVENT, uhc_enumeration_error(), uhc_enumeration_step15(), uhc_enumeration_suspend(), UHC_NB_UHI, uhd_ep_free(), uhd_setup_request(), UHD_TRANS_DISCONNECT, UHD_TRANS_NOERROR, UNUSED, USB_DT_CONFIGURATION, USB_REQ_DIR_OUT, USB_REQ_RECIP_DEVICE, USB_REQ_SET_CONFIGURATION, USB_REQ_TYPE_STANDARD, usb_setup_req_t::wIndex, usb_setup_req_t::wLength, and usb_setup_req_t::wValue.
Referenced by uhc_enumeration_step13().
|
static |
Device enumeration step 15 Enables UHI interfaces.
add | USB address of the setup request |
status | Transfer status |
payload_trans | Number of data transfered during DATA phase |
References uhi_api_t::enable, g_uhc_device_root, LE16, uhc_dev_enum, UHC_ENUM_EVENT, uhc_enum_try, uhc_enumeration_error(), UHC_NB_UHI, UHD_TRANS_DISCONNECT, UHD_TRANS_NOERROR, uhi_api_t::uninstall, UNUSED, and USB_V2_1.
Referenced by uhc_enumeration_step14().
|
static |
Device enumeration step 2 Lets USB line in IDLE state during 20ms.
References uhc_enable_timeout_callback(), and uhc_enumeration_step3().
Referenced by uhc_enumeration_step1().
|
static |
Device enumeration step 3 Reset USB line.
References uhc_enumeration_reset(), and uhc_enumeration_step4().
Referenced by uhc_dev_reset(), and uhc_enumeration_step2().
|
static |
Device enumeration step 4 Lets USB line in IDLE state during 100ms.
References uhc_dev_enum, uhc_enable_timeout_callback(), uhc_enumeration_step5(), and uhd_get_speed().
Referenced by uhc_enumeration_step3().
|
static |
Device enumeration step 5 Requests the USB device descriptor.
This setup request can be aborted because the control endpoint size is unknown.
References usb_setup_req_t::bmRequestType, usb_setup_req_t::bRequest, uhc_dev_enum, uhc_enumeration_error(), uhc_enumeration_step6(), uhd_ep0_alloc(), uhd_ep_free(), uhd_setup_request(), USB_DT_DEVICE, USB_REQ_DIR_IN, USB_REQ_GET_DESCRIPTOR, USB_REQ_RECIP_DEVICE, USB_REQ_TYPE_STANDARD, usb_setup_req_t::wIndex, usb_setup_req_t::wLength, and usb_setup_req_t::wValue.
Referenced by uhc_enumeration_step4().
|
static |
Device enumeration step 6 End of Get device descriptor request.
Wait 20ms in IDLE state.
add | USB address of the setup request |
status | Transfer status |
payload_trans | Number of data transfered during DATA phase |
References uhc_dev_enum, uhc_enable_timeout_callback(), uhc_enumeration_error(), uhc_enumeration_step7(), UHD_TRANS_DISCONNECT, UHD_TRANS_NOERROR, UNUSED, and USB_DT_DEVICE.
Referenced by uhc_enumeration_step5().
|
static |
Device enumeration step 7 Reset USB line.
References uhc_enumeration_reset(), and uhc_enumeration_step8().
Referenced by uhc_enumeration_step6().
|
static |
Device enumeration step 8 Lets USB line in IDLE state during 100ms.
References uhc_enable_timeout_callback(), and uhc_enumeration_step9().
Referenced by uhc_enumeration_step7().
|
static |
Device enumeration step 9 Send a Set address setup request.
References usb_setup_req_t::bmRequestType, usb_setup_req_t::bRequest, g_uhc_device_root, uhc_dev_enum, UHC_DEVICE_ENUM_ADD, uhc_enumeration_error(), uhc_enumeration_step10(), uhd_ep0_alloc(), uhd_ep_free(), uhd_setup_request(), USB_REQ_DIR_OUT, USB_REQ_RECIP_DEVICE, USB_REQ_SET_ADDRESS, USB_REQ_TYPE_STANDARD, usb_setup_req_t::wIndex, usb_setup_req_t::wLength, and usb_setup_req_t::wValue.
Referenced by uhc_enumeration_step8().
|
static |
Enters a specific device in USB suspend mode Suspend the USB line or a port on USB hub.
References g_uhc_device_root, uhc_dev_enum, and uhd_suspend().
Referenced by uhc_enumeration_error(), uhc_enumeration_step13(), and uhc_enumeration_step14().
uint8_t uhc_get_device_number | ( | void | ) |
References g_uhc_device_root, and UHC_USB_ADD_NOT_VALID.
bool uhc_is_suspend | ( | void | ) |
References g_uhc_device_root, UHC_USB_ADD_NOT_VALID, and uhd_is_suspend().
Referenced by uhc_resume(), and UI_WAKEUP_HANDLER().
void uhc_notify_connection | ( | bool | b_plug | ) |
Notify device connection or disconnection.
b_plug | Device connection, if true |
References Assert, g_uhc_device_root, uhc_connection_tree(), uhc_power_running, and UHC_USB_ADD_NOT_VALID.
Referenced by uhd_disable(), and uhd_interrupt().
void uhc_notify_resume | ( | void | ) |
Notify that a resume bus occurs A resume can occur after a downstream or an upstream resume.
References uhc_remotewakeup(), and UHC_WAKEUP_EVENT.
Referenced by uhd_sof_interrupt().
void uhc_notify_sof | ( | bool | b_micro | ) |
Notify each start of frame sent by driver.
b_micro | It is a micro start of frame, if true |
References uhi_api_t::sof_notify, UHC_NB_UHI, uhc_sof_timeout, and uhc_sof_timeout_callback.
Referenced by uhd_sof_interrupt().
|
static |
Enables or disables the remote wakeup feature of all devices connected.
b_enable | true to enable remote wakeup feature, else disable. |
References usb_setup_req_t::bmRequestType, usb_setup_req_t::bRequest, g_uhc_device_root, uhd_setup_request(), USB_CONFIG_ATTR_REMOTE_WAKEUP, USB_DEV_FEATURE_REMOTE_WAKEUP, USB_REQ_CLEAR_FEATURE, USB_REQ_DIR_OUT, USB_REQ_RECIP_DEVICE, USB_REQ_SET_FEATURE, USB_REQ_TYPE_STANDARD, usb_setup_req_t::wIndex, usb_setup_req_t::wLength, and usb_setup_req_t::wValue.
Referenced by uhc_notify_resume(), and uhc_suspend().
void uhc_resume | ( | void | ) |
References uhc_is_suspend(), and uhd_resume().
Referenced by UI_WAKEUP_HANDLER().
|
static |
Callback used to signal the end of a setup request.
add | USB address of the setup request |
status | Transfer status |
payload_trans | Number of data transfered during DATA phase |
References uhc_setup_request_finish, uhc_setup_request_finish_status, UHD_TRANS_NOERROR, and UNUSED.
Referenced by uhc_dev_get_string(), and uhc_dev_is_high_speed_support().
void uhc_start | ( | void | ) |
Starts the host mode.
References g_uhc_device_root, uhc_sof_timeout, UHC_USB_ADD_NOT_VALID, and uhd_enable().
Referenced by main(), otg_dual_enable(), and otg_id_handler().
void uhc_stop | ( | bool | b_id_stop | ) |
void uhc_suspend | ( | bool | b_remotewakeup | ) |
References uhc_enum_try, uhc_remotewakeup(), and uhd_suspend().
Referenced by ui_host_sof_event().
|
static |
Entry point of all devices connected on USB tree.
Referenced by uhc_connection_tree(), uhc_enumeration_reset(), uhc_enumeration_step13(), uhc_enumeration_step15(), uhc_enumeration_step9(), uhc_enumeration_suspend(), uhc_get_device_number(), uhc_is_suspend(), uhc_notify_connection(), uhc_remotewakeup(), and uhc_start().
|
static |
Number of enumeration try.
Referenced by uhc_connection_tree(), uhc_dev_reset(), uhc_enumeration_error(), uhc_enumeration_step15(), and uhc_suspend().
|
static |
Volatile flag to pool the end of Get USB string setup request.
Referenced by uhc_dev_get_string(), uhc_dev_is_high_speed_support(), and uhc_setup_request_callback().
|
static |
Volatile flag to know the status of Get USB string setup request.
Referenced by uhc_dev_get_string(), uhc_dev_is_high_speed_support(), and uhc_setup_request_callback().
uint8_t uhc_sof_timeout |
Number of SOF remaining before call uhc_sof_timeout_callback callback.
Referenced by uhc_connection_tree(), uhc_enable_timeout_callback(), uhc_notify_sof(), and uhc_start().
|
static |
Callback currently registered on a SOF timeout.
Referenced by uhc_enable_timeout_callback(), and uhc_notify_sof().
|
static |
Array of all UHI available.