Microchip® Advanced Software Framework

 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
Implementation of UHC

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_request_bos_desc (uint16_t length, const uhd_callback_setup_end_t callback)
 Requests the USB structure of the USB BOS descriptor. 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_step16_lpm (void)
 Device enumeration step 16 (LPM only) Requests first part of the USB BOS descriptor. More...
 
static void uhc_enumeration_step17_lpm (usb_add_t add, uhd_trans_status_t status, uint16_t payload_trans)
 Device enumeration step 17 (LPM only) Check LPM support through the BOS descriptor received and request the whole BOS descriptor. More...
 
static void uhc_enumeration_step18_lpm (usb_add_t add, uhd_trans_status_t status, uint16_t payload_trans)
 Device enumeration step 18 (LPM only) Check LPM support through the BOS descriptor received. 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...
 
void uhc_notify_resume_lpm (void)
 Notify that a resume bus occurs after a L1 state 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)
 
bool uhc_suspend_lpm (bool b_remotewakeup, uint8_t hird)
 

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_DEVICE_ENUM_ADD   1
#define UHC_ENUM_NB_TRY   4

Maximum try to enumerate a device.

Referenced by uhc_enumeration_error().

#define UHC_NB_UHI   (sizeof(uhc_uhis)/sizeof(uhc_uhis[0]))
#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 void uhc_connection_tree ( bool  b_plug,
uhc_device_t *  dev 
)
static

Manage a device plug or unplug on the USB tree.

Parameters
b_plugtrue, if it is a device connection
devInformation about device connected or disconnected

References dev, 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_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().

void uhc_dev_reset ( uhc_device_t *  dev)
static void uhc_enable_timeout_callback ( uint8_t  timeout,
uhc_sof_timeout_callback_t  callback 
)
static

Enable a internal timeout on SOF events.

Parameters
timeoutvalue of timeout (ms)
callbackCallback 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 void uhc_enumeration_reset ( uhd_callback_reset_t  callback)
static

Sends the USB Reset signal on the USB line of a device.

Parameters
callbackCallback 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 void uhc_enumeration_step1 ( void  )
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 void uhc_enumeration_step10 ( usb_add_t  add,
uhd_trans_status_t  status,
uint16_t  payload_trans 
)
static

Device enumeration step 10 End of Set address request.

Lets USB line in IDLE state during 20ms.

Parameters
addUSB address of the setup request
statusTransfer status
payload_transNumber 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 void uhc_enumeration_step12 ( usb_add_t  add,
uhd_trans_status_t  status,
uint16_t  payload_trans 
)
static

Device enumeration step 12 Requests the first USB structure of the USB configuration descriptor.

Parameters
addUSB address of the setup request
statusTransfer status
payload_transNumber 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 void uhc_enumeration_step13 ( usb_add_t  add,
uhd_trans_status_t  status,
uint16_t  payload_trans 
)
static
static void uhc_enumeration_step14 ( usb_add_t  add,
uhd_trans_status_t  status,
uint16_t  payload_trans 
)
static
static void uhc_enumeration_step15 ( usb_add_t  add,
uhd_trans_status_t  status,
uint16_t  payload_trans 
)
static

Device enumeration step 15 Enables UHI interfaces.

Parameters
addUSB address of the setup request
statusTransfer status
payload_transNumber 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_enumeration_step16_lpm(), UHC_NB_UHI, UHD_TRANS_DISCONNECT, UHD_TRANS_NOERROR, uhi_api_t::uninstall, UNUSED, and USB_V2_1.

Referenced by uhc_enumeration_step14().

static void uhc_enumeration_step16_lpm ( void  )
static

Device enumeration step 16 (LPM only) Requests first part of the USB BOS descriptor.

References uhc_enumeration_step17_lpm(), and uhc_request_bos_desc().

Referenced by uhc_enumeration_step15().

static void uhc_enumeration_step17_lpm ( usb_add_t  add,
uhd_trans_status_t  status,
uint16_t  payload_trans 
)
static

Device enumeration step 17 (LPM only) Check LPM support through the BOS descriptor received and request the whole BOS descriptor.

Parameters
addUSB address of the setup request
statusTransfer status
payload_transNumber of data transfered during DATA phase

References le16_to_cpu, uhc_dev_enum, UHC_ENUM_EVENT, uhc_enum_try, uhc_enumeration_error(), uhc_enumeration_step18_lpm(), uhc_request_bos_desc(), UHD_TRANS_DISCONNECT, UHD_TRANS_NOERROR, UHD_TRANS_STALL, UNUSED, and USB_DT_BOS.

Referenced by uhc_enumeration_step16_lpm().

static void uhc_enumeration_step18_lpm ( usb_add_t  add,
uhd_trans_status_t  status,
uint16_t  payload_trans 
)
static

Device enumeration step 18 (LPM only) Check LPM support through the BOS descriptor received.

Parameters
addUSB address of the setup request
statusTransfer status
payload_transNumber of data transfered during DATA phase

References le16_to_cpu, uhc_dev_enum, UHC_ENUM_EVENT, uhc_enum_try, uhc_enumeration_error(), UHD_TRANS_DISCONNECT, UHD_TRANS_NOERROR, UHD_TRANS_STALL, UNUSED, USB_DC_EXT_LPM, USB_DC_USB20_EXTENSION, USB_DT_BOS, and USB_DT_DEVICE_CAPABILITY.

Referenced by uhc_enumeration_step17_lpm().

static void uhc_enumeration_step2 ( void  )
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 void uhc_enumeration_step3 ( void  )
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 void uhc_enumeration_step4 ( void  )
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 void uhc_enumeration_step5 ( void  )
static
static void uhc_enumeration_step6 ( usb_add_t  add,
uhd_trans_status_t  status,
uint16_t  payload_trans 
)
static

Device enumeration step 6 End of Get device descriptor request.

Wait 20ms in IDLE state.

Parameters
addUSB address of the setup request
statusTransfer status
payload_transNumber 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 void uhc_enumeration_step7 ( void  )
static

Device enumeration step 7 Reset USB line.

References uhc_enumeration_reset(), and uhc_enumeration_step8().

Referenced by uhc_enumeration_step6().

static void uhc_enumeration_step8 ( void  )
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 void uhc_enumeration_suspend ( void  )
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  )
bool uhc_is_suspend ( void  )
void uhc_notify_connection ( bool  b_plug)

Notify device connection or disconnection.

Parameters
b_plugDevice connection, if true

References Assert, g_uhc_device_root, uhc_connection_tree(), uhc_power_running, and UHC_USB_ADD_NOT_VALID.

Referenced by _uhd_connect(), _uhd_disconnect(), and uhd_disable().

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_resume_lpm ( void  )

Notify that a resume bus occurs after a L1 state A resume can occur after a downstream or an upstream resume.

References UHC_WAKEUP_EVENT.

Referenced by _uhd_downstream_resume(), _uhd_upstream_resume(), and _uhd_wakeup().

void uhc_notify_sof ( bool  b_micro)

Notify each start of frame sent by driver.

Parameters
b_microIt 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 void uhc_remotewakeup ( bool  b_enable)
static
void uhc_resume ( void  )

References uhc_is_suspend(), and uhd_resume().

static void uhc_setup_request_callback ( usb_add_t  add,
uhd_trans_status_t  status,
uint16_t  payload_trans 
)
static

Callback used to signal the end of a setup request.

Parameters
addUSB address of the setup request
statusTransfer status
payload_transNumber 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(), and usb_dual_enable().

void uhc_stop ( bool  b_id_stop)

Stops the host mode.

References uhd_disable().

void uhc_suspend ( bool  b_remotewakeup)
bool uhc_suspend_lpm ( bool  b_remotewakeup,
uint8_t  hird 
)

volatile bool uhc_setup_request_finish
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().

volatile bool uhc_setup_request_finish_status
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().

uhc_sof_timeout_callback_t uhc_sof_timeout_callback
static

Callback currently registered on a SOF timeout.

Referenced by uhc_enable_timeout_callback(), and uhc_notify_sof().

uhi_api_t uhc_uhis[] = {USB_HOST_UHI}
static

Array of all UHI available.