The UHD driver provides a low-level abstraction of the host controller hardware.
Most events coming from the hardware such as interrupts may cause the UHD performing function call in UHC and UHI.
Modules | |
USBC Host Driver | |
Typedefs | |
typedef void(* | uhd_callback_reset_t )(void) |
End of reset callback function type. More... | |
typedef void(* | uhd_callback_setup_end_t )(usb_add_t add, uhd_trans_status_t status, uint16_t payload_trans) |
End of setup callback function type. More... | |
typedef bool(* | uhd_callback_setup_run_t )(usb_add_t add, uint8_t **payload, uint16_t *payload_size) |
Data setup transfer callback function type. More... | |
typedef void(* | uhd_callback_trans_t )(usb_add_t add, usb_ep_t ep, uhd_trans_status_t status, iram_size_t nb_transfered) |
End of transfer callback function type. More... | |
Enumerations | |
enum | uhd_speed_t { UHD_SPEED_LOW = 0, UHD_SPEED_FULL = 1, UHD_SPEED_HIGH = 2 } |
Device speed. More... | |
enum | uhd_trans_status_t { UHD_TRANS_NOERROR = 0, UHD_TRANS_DISCONNECT, UHD_TRANS_CRC, UHD_TRANS_DT_MISMATCH, UHD_TRANS_STALL, UHD_TRANS_NOTRESPONDING, UHD_TRANS_PIDFAILURE, UHD_TRANS_TIMEOUT, UHD_TRANS_ABORTED } |
Endpoint transfer status The status field is updated after each transaction attempt, whether successful or not. More... | |
Functions | |
void | uhd_disable (bool b_id_stop) |
Disables the USB host mode. More... | |
void | uhd_enable (void) |
Enables the USB host mode Start the ID pin management if the ID pin is available. More... | |
uint16_t | uhd_get_frame_number (void) |
Returns the current Start Of Frame (SOF) number. More... | |
uint16_t | uhd_get_microframe_number (void) |
Returns the current micro start of frame number. More... | |
uhd_speed_t | uhd_get_speed (void) |
Returns the speed of connected device. More... | |
bool | uhd_is_suspend (void) |
Test if the suspend state is enabled on the USB line. More... | |
void | uhd_resume (void) |
Enables the IDLE state on the USB line. More... | |
void | uhd_send_reset (uhd_callback_reset_t callback) |
Enables the Reset state on the USB line. More... | |
bool | uhd_setup_request (usb_add_t add, usb_setup_req_t *req, uint8_t *payload, uint16_t payload_size, uhd_callback_setup_run_t callback_run, uhd_callback_setup_end_t callback_end) |
Add a setup request in the control endpoint setup queue. More... | |
void | uhd_suspend (void) |
Enables the suspend state on the USB line. More... | |
Endpoint Management | |
The following functions allow drivers to create and remove endpoints, as well as set, clear and query their "halted" and "wedged" states. | |
bool | uhd_ep0_alloc (usb_add_t add, uint8_t ep_size) |
Configures and enables a control endpoint 0. More... | |
bool | uhd_ep_alloc (usb_add_t add, usb_ep_desc_t *ep_desc, uhd_speed_t speed) |
Configures and enables an endpoint. More... | |
void | uhd_ep_free (usb_add_t add, usb_ep_t endp) |
Disables an endpoint or all endpoint of a device. More... | |
bool | uhd_ep_run (usb_add_t add, usb_ep_t endp, bool b_shortpacket, uint8_t *buf, iram_size_t buf_size, uint16_t timeout, uhd_callback_trans_t callback) |
Allows to receive or send data on an endpoint. More... | |
void | uhd_ep_abort (usb_add_t add, usb_ep_t endp) |
Aborts an on-going transfer on an endpoint. More... | |
High speed test mode management | |
The following functions allow the host to jump to a specific test mode required in high speed mode. | |
void | uhd_test_mode_j (void) |
void | uhd_test_mode_k (void) |
void | uhd_test_mode_se0_nak (void) |
void | uhd_test_mode_packet (void) |
UHC callbacks to provide for UHD | |
void | uhc_start (void) |
Starts the host mode. More... | |
void | uhc_stop (bool b_id_stop) |
Stops the host mode. More... | |
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... | |
typedef void(* uhd_callback_reset_t)(void) |
End of reset callback function type.
Registered by uhd_send_reset() Callback called when reset event is completed.
typedef void(* uhd_callback_setup_end_t)(usb_add_t add, uhd_trans_status_t status, uint16_t payload_trans) |
End of setup callback function type.
Registered by uhd_setup_request() Called when the setup request is completed.
add | USB address of the setup request |
status | Transfer status |
payload_trans | Number of data transfered during DATA phase |
Data setup transfer callback function type.
Registered by uhd_setup_request() Called during DATA phase when the (payload) buffer is full or empty. Then the setup request is halted. A new buffer can be provided to continue the DATA phase or abort DATA phase.
add | USB address of the setup request |
payload | To return the next buffer address |
payload_size | To return the size of next buffer |
true
, if a new buffer is available, otherwise stop the request. typedef void(* uhd_callback_trans_t)(usb_add_t add, usb_ep_t ep, uhd_trans_status_t status, iram_size_t nb_transfered) |
End of transfer callback function type.
Registered by uhd_ep_run() Callback called by USB interrupt after data transfer or abort (reset,...).
add | USB address used by the transfer |
status | Transfer status |
nb_transfered | Number of data transfered |
enum uhd_speed_t |
enum uhd_trans_status_t |
Endpoint transfer status The status field is updated after each transaction attempt, whether successful or not.
void uhc_notify_connection | ( | bool | b_plug | ) |
Notify device connection or disconnection.
b_plug | Device connection, if true |
References uhc_device_t::address, Assert, 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().
void uhc_start | ( | void | ) |
Starts the host mode.
References uhc_device_t::address, 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 | ) |
Stops the host mode.
b_id_stop | Stop USB ID pin management, if true. |
References uhd_disable().
Referenced by otg_id_handler().
void uhd_disable | ( | bool | b_id_stop | ) |
Disables the USB host mode.
b_id_stop | Stop ID pin management, if true. |
References cpu_irq_restore(), cpu_irq_save(), Is_otg_clock_usable, otg_dual_disable(), otg_freeze_clock, otg_unfreeze_clock, pad_vbus_disable, pad_vbus_error_interrupt_disable, pad_vbus_interrupt_disable, uhc_notify_connection(), uhd_disable_all_interrupts, uhd_disable_sof, uhd_sleep_mode(), UHD_STATE_WAIT_ID_HOST, and UNUSED.
Referenced by uhc_stop().
void uhd_enable | ( | void | ) |
Enables the USB host mode Start the ID pin management if the ID pin is available.
References cpu_irq_restore(), cpu_irq_save(), Is_pad_id_device, Is_pad_vbus_high, otg_dual_enable(), otg_enable, otg_enable_host_mode, otg_freeze_clock, otg_register_desc_tab, otg_unfreeze_clock, pad_vbus_enable, pad_vbus_error_init, pad_vbus_init, UHC_VBUS_CHANGE, uhd_ack_all_interrupts, uhd_b_suspend_requested, uhd_ctrl_request_timeout, uhd_enable_connection_int, uhd_enable_reset_sent_interrupt, uhd_enable_sof_interrupt, uhd_enable_wakeup_interrupt, uhd_g_pipe_table, uhd_resume_start, uhd_sleep_mode(), UHD_STATE_DISCONNECT, UHD_STATE_NO_VBUS, uhd_suspend_start, UHD_USB_INT_LEVEL, uhd_vbus_handler(), and uhd_vbus_is_on.
Referenced by uhc_start().
Configures and enables a control endpoint 0.
add | USB address of endpoint |
ep_size | Endpoint control maximum size |
1
if the endpoint is enabled, otherwise 0
. References Is_uhd_pipe_enabled, uhd_configure_pipe, uhd_ctrl_buffer, uhd_enable_pipe, uhd_enable_pipe_error_interrupt, uhd_enable_pipe_interrupt, uhd_enable_stall_interrupt, uhd_g_pipe_table, uhd_udesc_set_buf0_addr, and uhd_udesc_set_uhaddr.
Referenced by uhc_enumeration_step11(), uhc_enumeration_step5(), and uhc_enumeration_step9().
Aborts an on-going transfer on an endpoint.
If a transfer is on going, then it is stopped and the callback registered is called to signal the end of transfer. Note: The control endpoint is not authorized.
add | USB address of endpoint |
endp | Endpoint to abort |
References uhd_ep_abort_pipe(), uhd_get_pipe(), UHD_PEP_NB, and UHD_TRANS_ABORTED.
bool uhd_ep_alloc | ( | usb_add_t | add, |
usb_ep_desc_t * | ep_desc, | ||
uhd_speed_t | speed | ||
) |
Configures and enables an endpoint.
add | USB address of endpoint |
ep_desc | Endpoint descriptor |
speed | Endpoint working speed |
1
if the endpoint is enabled, otherwise 0
. References usb_ep_desc_t::bEndpointAddress, usb_ep_desc_t::bInterval, usb_ep_desc_t::bmAttributes, Is_uhd_pipe_enabled, le16_to_cpu, uhd_ack_out_ready, UHD_BULK_INTERVAL_MIN, uhd_configure_pipe, uhd_enable_pipe, uhd_enable_pipe_error_interrupt, uhd_enable_pipe_interrupt, uhd_enable_stall_interrupt, uhd_g_pipe_table, UHD_PEP_NB, uhd_udesc_set_uhaddr, USB_EP_ADDR_MASK, USB_EP_DIR_IN, USB_EP_TYPE_BULK, USB_EP_TYPE_MASK, and usb_ep_desc_t::wMaxPacketSize.
Referenced by uhi_vendor_install().
Disables an endpoint or all endpoint of a device.
add | USB address of endpoint |
endp | Endpoint number and direction (USB_EP_DIR_IN/OUT). Remove all endpoints of USB address, if 0xFF. |
References uhd_ctrl_request_t::add, uhd_ctrl_request_end(), uhd_ctrl_request_timeout, uhd_disable_pipe, uhd_get_pipe_endpoint_address, UHD_PEP_NB, uhd_pipe_finish_job(), uhd_pipes_error, UHD_TRANS_DISCONNECT, uhd_udesc_get_epnum, and uhd_udesc_get_uhaddr.
Referenced by uhc_connection_tree(), uhc_enumeration_error(), uhc_enumeration_step11(), uhc_enumeration_step14(), uhc_enumeration_step5(), and uhc_enumeration_step9().
bool uhd_ep_run | ( | usb_add_t | add, |
usb_ep_t | endp, | ||
bool | b_shortpacket, | ||
uint8_t * | buf, | ||
iram_size_t | buf_size, | ||
uint16_t | timeout, | ||
uhd_callback_trans_t | callback | ||
) |
Allows to receive or send data on an endpoint.
If a USB DMA is available, the driver uses it to transfer endpoint data from or to internal RAM. When the transfer is finished or aborted (stall, reset, ...), the callback is called. This callback returns the transfer status and eventually the number of byte transfered. Note: The control endpoint is not authorized.
add | USB address of endpoint |
endp | Endpoint number |
b_shortpacket | Enabled automatic short packet |
buf | Buffer on Internal RAM to send or fill. It must be align, then use COMPILER_WORD_ALIGNED. |
buf_size | Buffer size to send or fill |
timeout | Transfer timeout (ms) |
callback | NULL or function to call at the end of transfer |
1
if function was successfully done, otherwise 0
. References uhd_pipe_job_t::b_shortpacket, uhd_pipe_job_t::buf, uhd_pipe_job_t::buf_size, uhd_pipe_job_t::busy, uhd_pipe_job_t::call_end, cpu_irq_restore(), cpu_irq_save(), uhd_pipe_job_t::nb_trans, uhd_pipe_job_t::timeout, uhd_get_pipe(), UHD_PEP_NB, uhd_pipe_trans_complet(), uhd_udesc_rst_buf0_ctn, and uhd_udesc_rst_buf0_size.
Referenced by uhi_vendor_bulk_in_run(), uhi_vendor_bulk_out_run(), uhi_vendor_int_in_run(), uhi_vendor_int_out_run(), uhi_vendor_iso_in_run(), and uhi_vendor_iso_out_run().
uint16_t uhd_get_frame_number | ( | void | ) |
Returns the current Start Of Frame (SOF) number.
References uhd_get_sof_number.
uint16_t uhd_get_microframe_number | ( | void | ) |
Returns the current micro start of frame number.
References uhd_get_microsof_number.
uhd_speed_t uhd_get_speed | ( | void | ) |
Returns the speed of connected device.
References Assert, uhd_get_speed_mode, UHD_SPEED_FULL, and UHD_SPEED_LOW.
Referenced by uhc_enumeration_step4().
bool uhd_is_suspend | ( | void | ) |
Test if the suspend state is enabled on the USB line.
References Is_uhd_sof_enabled.
Referenced by uhc_is_suspend().
void uhd_resume | ( | void | ) |
Enables the IDLE state on the USB line.
The IDLE state is enable when SOF are present on USB line. A Downstream Resume signal can be sent.
References Is_otg_clock_usable, Is_uhd_sof_enabled, otg_unfreeze_clock, uhd_enable_sof, uhd_resume_start, uhd_send_resume, uhd_sleep_mode(), UHD_STATE_IDLE, and uhd_suspend_start.
Referenced by uhc_resume().
void uhd_send_reset | ( | uhd_callback_reset_t | callback | ) |
Enables the Reset state on the USB line.
callback | Callback when reset sequence is finished |
References uhd_reset_callback, and uhd_start_reset.
Referenced by uhc_enumeration_reset().
bool uhd_setup_request | ( | usb_add_t | add, |
usb_setup_req_t * | req, | ||
uint8_t * | payload, | ||
uint16_t | payload_size, | ||
uhd_callback_setup_run_t | callback_run, | ||
uhd_callback_setup_end_t | callback_end | ||
) |
Add a setup request in the control endpoint setup queue.
Note: Request timeout is 5s.
add | USB address of control endpoint |
req | Setup request definition |
payload | Buffer to use in setup DATA phase |
payload_size | Size of buffer used in DATA phase |
callback_run | Callback to call if buffer is empty or full |
callback_end | Callback to call when request is finish |
true
if the request has been accepted, otherwise false
. Note: The swap of "req.wValues" from uin16_t to le16_t is done by UHD. References uhd_ctrl_request_t::add, Assert, uhd_ctrl_request_t::callback_end, uhd_ctrl_request_t::callback_run, cpu_irq_restore(), cpu_irq_save(), uhd_ctrl_request_t::next_request, uhd_ctrl_request_t::payload, uhd_ctrl_request_t::payload_size, uhd_ctrl_request_t::req, and uhd_ctrl_phase_setup().
Referenced by uhc_dev_get_string(), uhc_dev_is_high_speed_support(), uhc_enumeration_step11(), uhc_enumeration_step12(), uhc_enumeration_step13(), uhc_enumeration_step14(), uhc_enumeration_step5(), uhc_enumeration_step9(), uhc_remotewakeup(), uhi_vendor_control_in_run(), uhi_vendor_control_out_run(), and uhi_vendor_enable().
void uhd_suspend | ( | void | ) |
Enables the suspend state on the USB line.
The SUSPEND state is enable when SOF are disabled on USB line.
References Is_uhd_pipe_frozen, uhd_b_suspend_requested, uhd_ctrl_request_timeout, uhd_freeze_pipe, UHD_PEP_NB, uhd_pipes_unfreeze, and uhd_suspend_start.
Referenced by uhc_enumeration_suspend(), uhc_suspend(), and uhd_ctrl_request_end().
void uhd_test_mode_j | ( | void | ) |
void uhd_test_mode_k | ( | void | ) |
void uhd_test_mode_packet | ( | void | ) |
void uhd_test_mode_se0_nak | ( | void | ) |