The UDD driver provides a low-level abstraction of the device controller hardware.
Most events coming from the hardware such as interrupts, which may cause the UDD to call into the UDC and UDI.
Modules | |
USB High-Speed Port for device mode (USBHS) | |
USBHS low-level driver for USB device mode. | |
Data Structures | |
struct | udd_ctrl_request_t |
Global variable to give and record information of the setup request management. More... | |
Macros | |
#define | Udd_setup_is_in() (USB_REQ_DIR_IN == (udd_g_ctrlreq.req.bmRequestType & USB_REQ_DIR_MASK)) |
Return true if the setup request udd_g_ctrlreq indicates IN data transfer. More... | |
#define | Udd_setup_is_out() (USB_REQ_DIR_OUT == (udd_g_ctrlreq.req.bmRequestType & USB_REQ_DIR_MASK)) |
Return true if the setup request udd_g_ctrlreq indicates OUT data transfer. More... | |
#define | Udd_setup_recipient() (udd_g_ctrlreq.req.bmRequestType & USB_REQ_RECIP_MASK) |
Return the recipient of the SETUP request udd_g_ctrlreq. More... | |
#define | Udd_setup_type() (udd_g_ctrlreq.req.bmRequestType & USB_REQ_TYPE_MASK) |
Return the type of the SETUP request udd_g_ctrlreq. More... | |
Typedefs | |
typedef void(* | udd_callback_halt_cleared_t )(void) |
End of halt callback function type. More... | |
typedef void(* | udd_callback_trans_t )(udd_ep_status_t status, iram_size_t nb_transfered, udd_ep_id_t ep) |
End of transfer callback function type. More... | |
typedef uint8_t | udd_ep_id_t |
Endpoint identifier. More... | |
Enumerations | |
enum | udd_ep_status_t { UDD_EP_TRANSFER_OK = 0, UDD_EP_TRANSFER_ABORT = 1 } |
Endpoint transfer status Returned in parameters of callback register via udd_ep_run routine. More... | |
Functions | |
void | udd_attach (void) |
Attach device to the bus when possible. More... | |
void | udd_detach (void) |
Detaches the device from the bus. More... | |
void | udd_disable (void) |
Disables the USB Device mode. More... | |
void | udd_enable (void) |
Enables the USB Device mode. More... | |
uint16_t | udd_get_frame_number (void) |
Returns the current start of frame number. More... | |
uint16_t | udd_get_micro_frame_number (void) |
Returns the current micro start of frame number. More... | |
uint8_t | udd_getaddress (void) |
Returns the USB address of device. More... | |
bool | udd_include_vbus_monitoring (void) |
Authorizes the VBUS event. More... | |
bool | udd_is_high_speed (void) |
Test whether the USB Device Controller is running at high speed or not. More... | |
void | udd_send_remotewakeup (void) |
The USB driver sends a resume signal called Upstream Resume. More... | |
void | udd_set_address (uint8_t address) |
Changes the USB address of device. More... | |
void | udd_set_setup_payload (uint8_t *payload, uint16_t payload_size) |
Load setup payload. More... | |
Variables | |
udd_ctrl_request_t | udd_g_ctrlreq |
Global variable to give and record information about setup request management. 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 | udd_ep_alloc (udd_ep_id_t ep, uint8_t bmAttributes, uint16_t MaxEndpointSize) |
Configures and enables an endpoint. More... | |
void | udd_ep_free (udd_ep_id_t ep) |
Disables an endpoint. More... | |
bool | udd_ep_is_halted (udd_ep_id_t ep) |
Check if the endpoint ep is halted. More... | |
bool | udd_ep_set_halt (udd_ep_id_t ep) |
Set the halted state of the endpoint ep. More... | |
bool | udd_ep_clear_halt (udd_ep_id_t ep) |
Clear the halted state of the endpoint ep. More... | |
bool | udd_ep_wait_stall_clear (udd_ep_id_t ep, udd_callback_halt_cleared_t callback) |
Registers a callback to call when endpoint halt is cleared. More... | |
bool | udd_ep_run (udd_ep_id_t ep, bool b_shortpacket, uint8_t *buf, iram_size_t buf_size, udd_callback_trans_t callback) |
Allows to receive or send data on an endpoint. More... | |
void | udd_ep_abort (udd_ep_id_t ep) |
Aborts transfer on going on endpoint. More... | |
High speed test mode management | |
The following functions allow the device to jump to a specific test mode required in high speed mode. | |
void | udd_test_mode_j (void) |
void | udd_test_mode_k (void) |
void | udd_test_mode_se0_nak (void) |
void | udd_test_mode_packet (void) |
UDC callbacks to provide for UDD | |
bool | udc_process_setup (void) |
Decodes and manages a setup request. More... | |
void | udc_reset (void) |
Reset the UDC. More... | |
void | udc_sof_notify (void) |
To signal that a SOF is occurred. More... | |
#define Udd_setup_is_in | ( | ) | (USB_REQ_DIR_IN == (udd_g_ctrlreq.req.bmRequestType & USB_REQ_DIR_MASK)) |
Return true if the setup request udd_g_ctrlreq indicates IN data transfer.
Referenced by udc_process_setup(), udc_reqstd(), udd_ctrl_setup_received(), and udi_hid_setup().
#define Udd_setup_is_out | ( | ) | (USB_REQ_DIR_OUT == (udd_g_ctrlreq.req.bmRequestType & USB_REQ_DIR_MASK)) |
Return true if the setup request udd_g_ctrlreq indicates OUT data transfer.
Referenced by udi_hid_setup().
#define Udd_setup_recipient | ( | ) | (udd_g_ctrlreq.req.bmRequestType & USB_REQ_RECIP_MASK) |
Return the recipient of the SETUP request udd_g_ctrlreq.
Referenced by udc_process_setup(), and udc_reqstd().
#define Udd_setup_type | ( | ) | (udd_g_ctrlreq.req.bmRequestType & USB_REQ_TYPE_MASK) |
Return the type of the SETUP request udd_g_ctrlreq.
Referenced by udc_process_setup(), and udi_hid_setup().
typedef void(* udd_callback_halt_cleared_t)(void) |
End of halt callback function type.
Registered by routine udd_ep_wait_stall_clear() Callback called when endpoint stall is cleared.
typedef void(* udd_callback_trans_t)(udd_ep_status_t status, iram_size_t nb_transfered, udd_ep_id_t ep) |
End of transfer callback function type.
Registered by routine udd_ep_run() Callback called by USB interrupt after data transfer or abort (reset,...).
status | UDD_EP_TRANSFER_OK, if transfer is complete |
status | UDD_EP_TRANSFER_ABORT, if transfer is aborted |
n | number of data transfered |
typedef uint8_t udd_ep_id_t |
Endpoint identifier.
enum udd_ep_status_t |
bool udc_process_setup | ( | void | ) |
Decodes and manages a setup request.
The driver call it when a SETUP packet is received. The udd_g_ctrlreq
contains the data of SETUP packet. If this callback accepts the setup request then it must return 1
and eventually update udd_g_ctrlreq
to send or receive data.
1
if the request is accepted, otherwise 0
.Decodes and manages a setup request.
This function parses a USB SETUP request and submits an appropriate response back to the host or, in the case of SETUP OUT requests with data, sets up a buffer for receiving the data payload.
The main standard requests defined by the USB 2.0 standard are handled internally. The interface requests are sent to UDI, and the specific request sent to a specific application callback.
References udd_ctrl_request_t::callback, udd_ctrl_request_t::over_under_run, udd_ctrl_request_t::payload_size, udd_ctrl_request_t::req, udc_req_ep(), udc_req_iface(), udc_reqstd(), udd_g_ctrlreq, Udd_setup_is_in, Udd_setup_recipient, Udd_setup_type, USB_REQ_RECIP_ENDPOINT, USB_REQ_RECIP_INTERFACE, USB_REQ_TYPE_STANDARD, and usb_setup_req_t::wLength.
Referenced by udd_ctrl_setup_received().
void udc_reset | ( | void | ) |
Reset the UDC.
The UDC must reset all configuration.
Reset the UDC.
References usb_conf_desc_t::bNumInterfaces, CPU_TO_LE16, udc_config_speed_t::desc, udc_device_status, udc_iface_disable(), udc_num_configuration, udc_ptr_conf, UDC_REMOTEWAKEUP_DISABLE, USB_DEV_STATUS_BUS_POWERED, USB_DEV_STATUS_REMOTEWAKEUP, and USB_DEV_STATUS_SELF_POWERED.
Referenced by if(), udc_req_std_dev_set_configuration(), udc_req_std_dev_set_feature(), and udc_stop().
void udc_sof_notify | ( | void | ) |
To signal that a SOF is occurred.
The UDC must send the signal to all UDIs enabled
References usb_conf_desc_t::bNumInterfaces, udc_config_speed_t::desc, udi_api_t::sof_notify, udc_num_configuration, udc_ptr_conf, and udc_config_speed_t::udi_apis.
void udd_attach | ( | void | ) |
Attach device to the bus when possible.
References cpu_irq_restore(), cpu_irq_save(), Is_otg_clock_usable, otg_freeze_clock, otg_unfreeze_clock, udd_ack_msof, udd_ack_reset, udd_ack_sof, udd_ack_wake_up, udd_attach_device, udd_enable_msof_interrupt, udd_enable_reset_interrupt, udd_enable_sof_interrupt, udd_enable_suspend_interrupt, udd_enable_wake_up_interrupt, udd_raise_suspend, and udd_sleep_mode().
Referenced by udc_attach(), udd_enable(), and udd_vbus_handler().
void udd_detach | ( | void | ) |
Detaches the device from the bus.
The driver must remove pull-up on USB line D- or D+.
References otg_freeze_clock, otg_unfreeze_clock, udd_detach_device, and udd_sleep_mode().
Referenced by udc_detach(), udd_disable(), and udd_vbus_handler().
void udd_disable | ( | void | ) |
Disables the USB Device mode.
References cpu_irq_restore(), cpu_irq_save(), Is_otg_host_mode_forced, Is_otg_id_host, otg_disable, otg_freeze_clock, otg_unfreeze_clock, pmc_disable_periph_clk(), sleepmgr_unlock_mode(), sysclk_disable_usb(), udd_b_sleep_initialized, udd_detach(), and USBHS_SLEEP_MODE_USB_SUSPEND.
Referenced by udc_stop().
void udd_enable | ( | void | ) |
Enables the USB Device mode.
References cpu_irq_restore(), cpu_irq_save(), Is_otg_clock_usable, Is_otg_id_device, Is_otg_vbus_high, otg_dual_enable(), otg_enable, otg_freeze_clock, otg_unfreeze_clock, otg_vbus_init, pmc_enable_periph_clk(), pmc_set_fast_startup_input(), sleepmgr_lock_mode(), sysclk_enable_usb(), udd_attach(), udd_b_idle, udd_b_sleep_initialized, udd_ep_job_table_reset(), udd_high_speed_disable, udd_high_speed_enable, udd_low_speed_disable, udd_low_speed_enable, udd_sleep_mode(), UDD_USB_INT_LEVEL, udd_vbus_handler(), udd_vbus_monitor_sleep_mode, USB_VBUS_PIO_ID, USB_VBUS_PIO_MASK, and USBHS_SLEEP_MODE_USB_SUSPEND.
Referenced by udc_start().
void udd_ep_abort | ( | udd_ep_id_t | ep | ) |
Aborts transfer on going on 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.
ep | Endpoint to abort |
References Is_udd_endpoint_dma_supported, Is_udd_kill_last, udd_disable_endpoint_dma_interrupt, udd_disable_endpoint_interrupt, udd_disable_in_send_interrupt, udd_disable_out_received_interrupt, udd_endpoint_dma_set_control, udd_ep_abort_job(), udd_kill_last_in_bank, udd_nb_busy_bank, USB_EP_ADDR_MASK, and USB_EP_DIR_IN.
Referenced by udc_req_std_ep_set_feature(), and udd_ep_interrupt().
bool udd_ep_alloc | ( | udd_ep_id_t | ep, |
uint8_t | bmAttributes, | ||
uint16_t | MaxEndpointSize | ||
) |
Configures and enables an endpoint.
ep | Endpoint number including direction (USB_EP_DIR_IN/USB_EP_DIR_OUT). |
bmAttributes | Attributes of endpoint declared in the descriptor. |
MaxEndpointSize | Endpoint maximum size |
1
if the endpoint is enabled, otherwise 0
. References Assert, udd_ep_job_t::b_shortpacket, udd_ep_job_t::buf, udd_ep_job_t::buf_cnt, udd_ep_job_t::buf_load, udd_ep_job_t::buf_size, udd_ep_job_t::busy, udd_ep_job_t::call_trans, dbg_print, Is_udd_endpoint_configured, Is_udd_endpoint_dma_supported, Is_udd_endpoint_enabled, Is_udd_endpoint_in, udd_allocate_memory, UDD_BULK_NB_BANK, udd_configure_endpoint, udd_disable_endpoint, udd_enable_endpoint, udd_enable_endpoint_bank_autoswitch, udd_ep_run(), UDD_EP_TRANSFER_ABORT, UDD_INTERRUPT_NB_BANK, UDD_ISOCHRONOUS_NB_BANK, udd_unallocate_memory, USB_DEVICE_MAX_EP, USB_EP_ADDR_MASK, USB_EP_DIR_IN, USB_EP_TYPE_BULK, USB_EP_TYPE_INTERRUPT, USB_EP_TYPE_ISOCHRONOUS, and USB_EP_TYPE_MASK.
Referenced by udc_iface_enable().
bool udd_ep_clear_halt | ( | udd_ep_id_t | ep | ) |
Clear the halted state of the endpoint ep.
After calling this function, any transaction on ep will be handled normally, i.e. a STALL handshake will not be sent, and the data toggle sequence will start at DATA0.
ep | The ID of the endpoint to be un-halted |
1
if function was successfully done, otherwise 0
. References udd_ep_job_t::busy, udd_ep_job_t::call_nohalt, Is_udd_endpoint_stall_requested, Is_udd_stall, udd_ep_job_t::stall_requested, udd_ack_stall, udd_disable_bank_interrupt, udd_disable_endpoint_interrupt, udd_disable_stall_handshake, udd_enable_endpoint_bank_autoswitch, udd_reset_data_toggle, USB_DEVICE_MAX_EP, and USB_EP_ADDR_MASK.
Referenced by udc_req_std_ep_clear_feature().
void udd_ep_free | ( | udd_ep_id_t | ep | ) |
Disables an endpoint.
ep | Endpoint number including direction (USB_EP_DIR_IN/USB_EP_DIR_OUT). |
References udd_ep_job_t::stall_requested, udd_disable_endpoint, udd_ep_abort_job(), udd_unallocate_memory, USB_DEVICE_MAX_EP, and USB_EP_ADDR_MASK.
Referenced by udc_iface_disable().
bool udd_ep_is_halted | ( | udd_ep_id_t | ep | ) |
Check if the endpoint ep is halted.
ep | The ID of the endpoint to check. |
1
if ep is halted, otherwise 0
. References Is_udd_endpoint_stall_requested, and USB_EP_ADDR_MASK.
Referenced by udc_req_std_ep_get_status().
bool udd_ep_run | ( | udd_ep_id_t | ep, |
bool | b_shortpacket, | ||
uint8_t * | buf, | ||
iram_size_t | buf_size, | ||
udd_callback_trans_t | callback | ||
) |
Allows to receive or send data on an endpoint.
The driver uses a specific DMA USB to transfer data from internal RAM to endpoint, if this one is available. When the transfer is finished or aborted (stall, reset, ...), the callback is called. The callback returns the transfer status and eventually the number of byte transfered. Note: The control endpoint is not authorized.
ep | The ID of the endpoint to use |
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 |
callback | NULL or function to call at the end of transfer |
1
if function was successfully done, otherwise 0
. References _dcache_flush(), _dcache_invalidate_prepare(), udd_ep_job_t::b_shortpacket, udd_ep_job_t::buf, udd_ep_job_t::buf_cnt, udd_ep_job_t::buf_load, udd_ep_job_t::buf_size, udd_ep_job_t::busy, udd_ep_job_t::call_trans, cpu_irq_restore(), cpu_irq_save(), dbg_print, Is_udd_endpoint_dma_supported, Is_udd_endpoint_enabled, Is_udd_endpoint_in, Is_udd_endpoint_stall_requested, udd_ep_job_t::stall_requested, udd_disable_endpoint_bank_autoswitch, udd_enable_endpoint_interrupt, udd_enable_in_send_interrupt, udd_enable_out_received_interrupt, udd_ep_trans_done(), USB_DEVICE_MAX_EP, and USB_EP_ADDR_MASK.
Referenced by udd_ep_alloc(), and udi_hid_kbd_send_report().
bool udd_ep_set_halt | ( | udd_ep_id_t | ep | ) |
Set the halted state of the endpoint ep.
After calling this function, any transaction on ep will result in a STALL handshake being sent. Any pending transactions will be performed first, however.
ep | The ID of the endpoint to be halted |
1
if ep is halted, otherwise 0
. References udd_ep_job_t::busy, cpu_irq_restore(), cpu_irq_save(), Is_udd_endpoint_stall_requested, udd_ep_job_t::stall_requested, udd_ack_stall, udd_disable_endpoint_bank_autoswitch, udd_disable_in_send_interrupt, udd_enable_bank_interrupt, udd_enable_endpoint_bank_autoswitch, udd_enable_endpoint_interrupt, udd_enable_stall_handshake, udd_nb_busy_bank, USB_DEVICE_MAX_EP, USB_EP_ADDR_MASK, and USB_EP_DIR_IN.
Referenced by udc_req_std_ep_set_feature().
bool udd_ep_wait_stall_clear | ( | udd_ep_id_t | ep, |
udd_callback_halt_cleared_t | callback | ||
) |
Registers a callback to call when endpoint halt is cleared.
ep | The ID of the endpoint to use |
callback | NULL or function to call when endpoint halt is cleared |
1
if the register is accepted, otherwise 0
. References udd_ep_job_t::busy, udd_ep_job_t::call_nohalt, Is_udd_endpoint_enabled, Is_udd_endpoint_stall_requested, udd_ep_job_t::stall_requested, USB_DEVICE_MAX_EP, and USB_EP_ADDR_MASK.
uint16_t udd_get_frame_number | ( | void | ) |
Returns the current start of frame number.
References udd_frame_number.
Referenced by main_sof_action().
uint16_t udd_get_micro_frame_number | ( | void | ) |
Returns the current micro start of frame number.
References udd_micro_frame_number.
uint8_t udd_getaddress | ( | void | ) |
Returns the USB address of device.
References udd_get_configured_address.
Referenced by udc_req_std_dev_set_configuration().
bool udd_include_vbus_monitoring | ( | void | ) |
Authorizes the VBUS event.
Referenced by udc_include_vbus_monitoring().
bool udd_is_high_speed | ( | void | ) |
Test whether the USB Device Controller is running at high speed or not.
true
if the Device is running at high speed mode, otherwise false
. References Is_udd_full_speed_mode.
Referenced by udc_req_std_dev_get_descriptor(), udc_req_std_dev_set_configuration(), and udc_req_std_dev_set_feature().
void udd_send_remotewakeup | ( | void | ) |
The USB driver sends a resume signal called Upstream Resume.
References otg_unfreeze_clock, udd_b_idle, udd_initiate_remote_wake_up, and udd_sleep_mode().
Referenced by udc_remotewakeup().
void udd_set_address | ( | uint8_t | address | ) |
Changes the USB address of device.
address | New USB address |
References udd_configure_address, udd_disable_address, and udd_enable_address.
Referenced by udc_valid_address().
void udd_set_setup_payload | ( | uint8_t * | payload, |
uint16_t | payload_size | ||
) |
Load setup payload.
payload | Pointer on payload |
payload_size | Size of payload |
Referenced by udc_req_std_dev_get_configuration(), udc_req_std_dev_get_descriptor(), udc_req_std_dev_get_status(), udc_req_std_dev_get_str_desc(), udc_req_std_ep_get_status(), and udc_req_std_iface_get_setting().
void udd_test_mode_j | ( | void | ) |
Referenced by udc_req_std_dev_set_feature().
void udd_test_mode_k | ( | void | ) |
Referenced by udc_req_std_dev_set_feature().
void udd_test_mode_packet | ( | void | ) |
Referenced by udc_req_std_dev_set_feature().
void udd_test_mode_se0_nak | ( | void | ) |
Referenced by udc_req_std_dev_set_feature().
udd_ctrl_request_t udd_g_ctrlreq |
Global variable to give and record information about setup request management.
Referenced by udc_process_setup(), udc_req_ep(), udc_req_iface(), udc_req_std_dev_clear_feature(), udc_req_std_dev_get_configuration(), udc_req_std_dev_get_descriptor(), udc_req_std_dev_get_status(), udc_req_std_dev_get_str_desc(), udc_req_std_dev_set_address(), udc_req_std_dev_set_configuration(), udc_req_std_dev_set_feature(), udc_req_std_ep_clear_feature(), udc_req_std_ep_get_status(), udc_req_std_ep_set_feature(), udc_req_std_iface_get_setting(), udc_req_std_iface_set_setting(), udc_reqstd(), udc_valid_address(), udi_hid_kbd_setreport(), udi_hid_reqstdifaceget_descriptor(), and udi_hid_setup().