USBB low-level driver for USB host mode.
The defines UHD_ENABLE and UDD_ENABLE must be added in project to allow the USB low level (UHD) to manage or not the dual role (device and host).
The following USBB driver configuration must be defined in conf_usb_host.h file of the application.
UHD_USB_INT_LEVEL
Option to change the interrupt priority (0 to 3) by default 0 (recommended).
UHD_ISOCHRONOUS_NB_BANK
Feature to reduce or increase isochronous endpoints buffering (1 to 2). Default value 2.
UHD_BULK_NB_BANK
Feature to reduce or increase bulk endpoints buffering (1 to 2). Default value 2.
UHD_INTERRUPT_NB_BANK
Feature to reduce or increase interrupt endpoints buffering (1 to 2). Default value 1.
UHD_BULK_INTERVAL_MIN
Feature to reduce or increase bulk token rate when it's NAKed (0, 1 ...). To adjust bandwidth usage. Default value 1.
The USB driver is fully managed by interrupt and does not request periodic task. Thereby, the USB events use callbacks to transfer the information. The callbacks can be declared in static during compilation or dynamically during code execution.
The driver uses the sleepmgr service to manage the different sleep modes. The sleep mode depends on USB driver state (uhd_usbb_state_enum).
Data Structures | |
struct | uhd_ctrl_request_t |
Structure to store the high level setup request. More... | |
struct | uhd_pipe_job_t |
Structure definition to store registered jobs on a pipe. More... | |
Macros | |
#define | UHD_BULK_INTERVAL_MIN 1 |
Minimal bulk interval value. More... | |
#define | UHD_BULK_NB_BANK 2 |
#define | UHD_INTERRUPT_NB_BANK 1 |
#define | UHD_ISOCHRONOUS_NB_BANK 2 |
Functions | |
ISR (otg_interrupt, AVR32_USBB_IRQ_GROUP, UHD_USB_INT_LEVEL) | |
Function called by USBB interrupt handler to manage USB interrupts. More... | |
void | otg_dual_disable (void) |
Uninitialize the dual role This function is implemented in usbb_host.c file. More... | |
bool | otg_dual_enable (void) |
Initialize the dual role This function is implemented in usbb_host.c file. More... | |
static void | uhd_ctrl_interrupt (void) |
Manages the events related to control endpoint. More... | |
static void | uhd_ctrl_phase_data_in (void) |
Manages the DATA IN phase on control endpoint. More... | |
static void | uhd_ctrl_phase_data_in_start (void) |
Starts the DATA IN phase on control endpoint. More... | |
static void | uhd_ctrl_phase_data_out (void) |
Manages the DATA OUT phase on control endpoint. More... | |
static void | uhd_ctrl_phase_setup (void) |
Sends a USB setup packet to start a control request sequence. More... | |
static void | uhd_ctrl_phase_zlp_in (void) |
Starts the ZLP IN phase on control endpoint. More... | |
static void | uhd_ctrl_phase_zlp_out (void) |
Starts the ZLP OUT phase on control endpoint. More... | |
static void | uhd_ctrl_request_end (uhd_trans_status_t status) |
Call the callback linked to control request and start the next request from the queue. More... | |
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... | |
bool | uhd_ep0_alloc (usb_add_t add, uint8_t ep_size) |
Configures and enables a control endpoint 0. More... | |
void | uhd_ep_abort (usb_add_t add, usb_ep_t endp) |
Aborts an on-going transfer on an endpoint. More... | |
static void | uhd_ep_abort_pipe (uint8_t pipe, uhd_trans_status_t status) |
Aborts the on going transfer on a pipe. 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... | |
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... | |
static uint8_t | uhd_get_pipe (usb_add_t add, usb_ep_t endp) |
Returns the pipe number matching a USB endpoint. More... | |
uhd_speed_t | uhd_get_speed (void) |
Returns the speed of connected device. More... | |
static void | uhd_interrupt (void) |
Function called by USBB interrupt to manage USB host interrupts. More... | |
bool | uhd_is_suspend (void) |
Test if the suspend state is enabled on the USB line. More... | |
static void | uhd_pipe_finish_job (uint8_t pipe, uhd_trans_status_t status) |
Call the callback linked to the end of pipe transfer. More... | |
static uhd_trans_status_t | uhd_pipe_get_error (uint8_t pipe) |
Translates the USBB pipe error to UHD error. More... | |
static void | uhd_pipe_interrupt (uint8_t pipe) |
Manages the following pipe interrupts: More... | |
static void | uhd_pipe_interrupt_dma (uint8_t pipe) |
Manages the pipe DMA interrupt. More... | |
static void | uhd_pipe_trans_complet (uint8_t pipe) |
Computes and starts the next transfer on a pipe. 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... | |
static void | uhd_sof_interrupt (void) |
Manages timeouts and actions based on SOF events. More... | |
void | uhd_suspend (void) |
Enables the suspend state on the USB line. More... | |
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) |
Variables | |
static bool | otg_initialized = false |
State of USBB OTG initialization. More... | |
static uhd_callback_reset_t | uhd_reset_callback = NULL |
Store the callback to be call at the end of reset signal. More... | |
Power management | |
enum | uhd_usbb_state_enum { UHD_STATE_OFF = 0, UHD_STATE_WAIT_ID_HOST = 1, UHD_STATE_NO_VBUS = 2, UHD_STATE_DISCONNECT = 3, UHD_STATE_SUSPEND = 4, UHD_STATE_IDLE = 5 } |
States of USBB interface. More... | |
static void | uhd_sleep_mode (enum uhd_usbb_state_enum new_state) |
Manages the sleep mode following the USBB state. More... | |
Control endpoint low level management routine. | |
This function performs control endpoint management. It handles the SETUP/DATA/HANDSHAKE phases of a control transaction. | |
enum | uhd_ctrl_request_phase_t { UHD_CTRL_REQ_PHASE_SETUP = 0, UHD_CTRL_REQ_PHASE_DATA_OUT = 1, UHD_CTRL_REQ_PHASE_DATA_IN = 2, UHD_CTRL_REQ_PHASE_ZLP_IN = 3, UHD_CTRL_REQ_PHASE_ZLP_OUT = 4 } |
Bit definitions to store setup request state machine. More... | |
struct uhd_ctrl_request_t * | uhd_ctrl_request_first |
Entry points of setup request list. More... | |
struct uhd_ctrl_request_t * | uhd_ctrl_request_last |
volatile uint16_t | uhd_ctrl_request_timeout |
Remaining time for on-going setup request (No request on-going if equal 0) More... | |
uint16_t | uhd_ctrl_nb_trans |
Number of transfered byte on DATA phase of current setup request. More... | |
static bool | uhd_b_suspend_requested |
Flag to delay a suspend request after all on-going setup request. More... | |
uhd_ctrl_request_phase_t | uhd_ctrl_request_phase |
Management of bulk/interrupt/isochronous endpoints | |
The UHD manages the data transfer on endpoints:
| |
static uhd_pipe_job_t | uhd_pipe_job [AVR32_USBB_EPT_NUM-1] |
Array to register a job on bulk/interrupt/isochronous endpoint. More... | |
static uint8_t | uhd_suspend_start |
Variables to manage the suspend/resume sequence. More... | |
static uint8_t | uhd_resume_start |
static uint8_t | uhd_pipes_unfreeze |
USBB Host IP properties | |
These macros give access to IP properties Get maximal number of endpoints | |
#define | uhd_get_pipe_max_nbr() |
Host Vbus line control | |
VBOF is an optional output pin which allows to enable or disable the external VBus generator. Enables hardware control of USB_VBOF output pin when a Vbus error occur | |
#define | uhd_enable_vbus_error_hw_control() USBB_CLR_BITS(USBCON,VBUSHWC) |
#define | uhd_disable_vbus_error_hw_control() USBB_SET_BITS(USBCON,VBUSHWC) |
Disables hardware control of USB_VBOF output pin when a Vbus error occur. More... | |
#define | USB_VBOF_PIN ATPASTE2(USB_VBOF, _PIN) |
Pin and function for USB_VBOF according to configuration from USB_VBOF. More... | |
#define | USB_VBOF_FUNCTION ATPASTE2(USB_VBOF, _FUNCTION) |
#define | uhd_output_vbof_pin() |
Output USB_VBOF onto its pin. More... | |
#define | uhd_set_vbof_active_high() USBB_CLR_BITS(USBCON,VBUSPO) |
Set USB_VBOF output pin polarity. More... | |
#define | uhd_set_vbof_active_low() USBB_SET_BITS(USBCON,VBUSPO) |
#define | uhd_enable_vbus() USBB_REG_SET(USBSTA,VBUSRQ) |
Requests VBus activation. More... | |
#define | uhd_disable_vbus() USBB_REG_CLR(USBSTA,VBUSRQ) |
Requests VBus deactivation. More... | |
#define | Is_uhd_vbus_enabled() USBB_TST_BITS(USBSTA,VBUSRQ) |
Tests if VBus activation has been requested. More... | |
Host Vbus line monitoring | |
#define | uhd_enable_vbus_error_interrupt() USBB_SET_BITS(USBCON,VBERRE) |
#define | uhd_disable_vbus_error_interrupt() USBB_CLR_BITS(USBCON,VBERRE) |
#define | Is_uhd_vbus_error_interrupt_enabled() USBB_TST_BITS(USBCON,VBERRE) |
#define | uhd_ack_vbus_error_interrupt() USBB_REG_CLR(USBSTA,VBERRI) |
#define | Is_uhd_vbus_error_interrupt() USBB_TST_BITS(USBSTA,VBERRI) |
USB device connection/disconnection monitoring | |
#define | uhd_enable_connection_int() USBB_REG_SET(UHINTE,DCONNIE) |
#define | uhd_disable_connection_int() USBB_REG_CLR(UHINTE,DCONNIE) |
#define | Is_uhd_connection_int_enabled() USBB_TST_BITS(UHINTE,DCONNIE) |
#define | uhd_ack_connection() USBB_REG_CLR(UHINT,DCONNI) |
#define | Is_uhd_connection() USBB_TST_BITS(UHINT,DCONNI) |
#define | uhd_enable_disconnection_int() USBB_REG_SET(UHINTE,DDISCIE) |
#define | uhd_disable_disconnection_int() USBB_REG_CLR(UHINTE,DDISCIE) |
#define | Is_uhd_disconnection_int_enabled() USBB_TST_BITS(UHINTE,DDISCIE) |
#define | uhd_ack_disconnection() USBB_REG_CLR(UHINT,DDISCI) |
#define | Is_uhd_disconnection() USBB_TST_BITS(UHINT,DDISCI) |
USB device speed control | |
#define | uhd_get_speed_mode() USBB_RD_BITFIELD(USBSTA,SPEED) |
#define | Is_uhd_low_speed_mode() (USBB_RD_BITFIELD(USBSTA,SPEED) == AVR32_USBB_USBSTA_SPEED_LOW) |
#define | Is_uhd_full_speed_mode() (USBB_RD_BITFIELD(USBSTA,SPEED) == AVR32_USBB_USBSTA_SPEED_FULL) |
#define | Is_uhd_high_speed_mode() false |
#define Is_uhd_connection | ( | ) | USBB_TST_BITS(UHINT,DCONNI) |
Referenced by uhd_interrupt().
#define Is_uhd_connection_int_enabled | ( | ) | USBB_TST_BITS(UHINTE,DCONNIE) |
Referenced by uhd_interrupt().
#define Is_uhd_disconnection | ( | ) | USBB_TST_BITS(UHINT,DDISCI) |
Referenced by uhd_interrupt(), and uhd_sof_interrupt().
#define Is_uhd_disconnection_int_enabled | ( | ) | USBB_TST_BITS(UHINTE,DDISCIE) |
Referenced by uhd_interrupt().
#define Is_uhd_downstream_resume | ( | ) | USBB_TST_BITS(UHINT,RSMEDI) |
Referenced by uhd_interrupt().
#define Is_uhd_downstream_resume_interrupt_enabled | ( | ) | USBB_TST_BITS(UHINTE,RSMEDIE) |
#define Is_uhd_full_speed_mode | ( | ) | (USBB_RD_BITFIELD(USBSTA,SPEED) == AVR32_USBB_USBSTA_SPEED_FULL) |
#define Is_uhd_high_speed_mode | ( | ) | false |
Referenced by uhd_interrupt(), and uhd_sof_interrupt().
#define Is_uhd_low_speed_mode | ( | ) | (USBB_RD_BITFIELD(USBSTA,SPEED) == AVR32_USBB_USBSTA_SPEED_LOW) |
#define Is_uhd_reset_sent | ( | ) | USBB_TST_BITS(UHINT,RSTI) |
Referenced by uhd_interrupt().
#define Is_uhd_reset_sent_interrupt_enabled | ( | ) | USBB_TST_BITS(UHINTE,RSTIE) |
#define Is_uhd_sending_resume | ( | ) | USBB_TST_BITS(UHCON,RESUME) |
#define Is_uhd_sof | ( | ) | USBB_TST_BITS(UHINT,HSOFI) |
Referenced by uhd_interrupt().
#define Is_uhd_sof_enabled | ( | ) | USBB_TST_BITS(UHCON,SOFE) |
Referenced by uhd_is_suspend(), and uhd_resume().
#define Is_uhd_sof_interrupt_enabled | ( | ) | USBB_TST_BITS(UHINTE,HSOFIE) |
#define Is_uhd_starting_reset | ( | ) | USBB_TST_BITS(UHCON,RESET) |
#define Is_uhd_upstream_resume | ( | ) | USBB_TST_BITS(UHINT,RXRSMI) |
Referenced by uhd_interrupt().
#define Is_uhd_upstream_resume_interrupt_enabled | ( | ) | USBB_TST_BITS(UHINTE,RXRSMIE) |
#define Is_uhd_vbus_enabled | ( | ) | USBB_TST_BITS(USBSTA,VBUSRQ) |
Tests if VBus activation has been requested.
#define Is_uhd_vbus_error_interrupt | ( | ) | USBB_TST_BITS(USBSTA,VBERRI) |
Referenced by uhd_interrupt().
#define Is_uhd_vbus_error_interrupt_enabled | ( | ) | USBB_TST_BITS(USBCON,VBERRE) |
#define Is_uhd_wakeup | ( | ) | USBB_TST_BITS(UHINT,HWUPI) |
Referenced by uhd_interrupt().
#define Is_uhd_wakeup_interrupt_enabled | ( | ) | USBB_TST_BITS(UHINTE,HWUPIE) |
Referenced by uhd_interrupt().
#define uhd_ack_connection | ( | ) | USBB_REG_CLR(UHINT,DCONNI) |
Referenced by uhd_interrupt().
#define uhd_ack_disconnection | ( | ) | USBB_REG_CLR(UHINT,DDISCI) |
Referenced by uhd_interrupt().
#define uhd_ack_downstream_resume | ( | ) | USBB_REG_CLR(UHINT,RSMEDI) |
#define uhd_ack_reset_sent | ( | ) | USBB_REG_CLR(UHINT,RSTI) |
Referenced by uhd_interrupt().
#define uhd_ack_sof | ( | ) | USBB_REG_CLR(UHINT,HSOFI) |
Referenced by uhd_interrupt().
#define uhd_ack_upstream_resume | ( | ) | USBB_REG_CLR(UHINT,RXRSMI) |
#define uhd_ack_vbus_error_interrupt | ( | ) | USBB_REG_CLR(USBSTA,VBERRI) |
Referenced by uhd_interrupt().
#define uhd_ack_wakeup | ( | ) | USBB_REG_CLR(UHINT,HWUPI) |
#define UHD_BULK_INTERVAL_MIN 1 |
Minimal bulk interval value.
Referenced by uhd_ep_alloc().
#define UHD_BULK_NB_BANK 2 |
Referenced by uhd_ep_alloc().
#define uhd_disable_connection_int | ( | ) | USBB_REG_CLR(UHINTE,DCONNIE) |
Referenced by uhd_interrupt().
#define uhd_disable_disconnection_int | ( | ) | USBB_REG_CLR(UHINTE,DDISCIE) |
Referenced by uhd_interrupt().
#define uhd_disable_downstream_resume_interrupt | ( | ) | USBB_REG_CLR(UHINTE,RSMEDIE) |
#define uhd_disable_reset_sent_interrupt | ( | ) | USBB_REG_CLR(UHINTE,RSTIE) |
#define uhd_disable_sof | ( | ) | USBB_CLR_BITS(UHCON,SOFE) |
Referenced by uhd_disable(), and uhd_sof_interrupt().
#define uhd_disable_sof_interrupt | ( | ) | USBB_REG_CLR(UHINTE,HSOFIE) |
#define uhd_disable_upstream_resume_interrupt | ( | ) | USBB_REG_CLR(UHINTE,RXRSMIE) |
#define uhd_disable_vbus | ( | ) | USBB_REG_CLR(USBSTA,VBUSRQ) |
Requests VBus deactivation.
Referenced by uhd_disable().
#define uhd_disable_vbus_error_hw_control | ( | ) | USBB_SET_BITS(USBCON,VBUSHWC) |
Disables hardware control of USB_VBOF output pin when a Vbus error occur.
#define uhd_disable_vbus_error_interrupt | ( | ) | USBB_CLR_BITS(USBCON,VBERRE) |
#define uhd_disable_wakeup_interrupt | ( | ) | USBB_REG_CLR(UHINTE,HWUPIE) |
#define uhd_enable_connection_int | ( | ) | USBB_REG_SET(UHINTE,DCONNIE) |
Referenced by uhd_interrupt().
#define uhd_enable_disconnection_int | ( | ) | USBB_REG_SET(UHINTE,DDISCIE) |
Referenced by uhd_interrupt().
#define uhd_enable_downstream_resume_interrupt | ( | ) | USBB_REG_SET(UHINTE,RSMEDIE) |
#define uhd_enable_reset_sent_interrupt | ( | ) | USBB_REG_SET(UHINTE,RSTIE) |
#define uhd_enable_sof | ( | ) | USBB_SET_BITS(UHCON,SOFE) |
Initiates a SOF events.
Referenced by uhd_interrupt(), and uhd_resume().
#define uhd_enable_sof_interrupt | ( | ) | USBB_REG_SET(UHINTE,HSOFIE) |
#define uhd_enable_upstream_resume_interrupt | ( | ) | USBB_REG_SET(UHINTE,RXRSMIE) |
#define uhd_enable_vbus | ( | ) | USBB_REG_SET(USBSTA,VBUSRQ) |
Requests VBus activation.
Referenced by uhd_enable().
#define uhd_enable_vbus_error_hw_control | ( | ) | USBB_CLR_BITS(USBCON,VBUSHWC) |
#define uhd_enable_vbus_error_interrupt | ( | ) | USBB_SET_BITS(USBCON,VBERRE) |
#define uhd_enable_wakeup_interrupt | ( | ) | USBB_REG_SET(UHINTE,HWUPIE) |
Detection of a wake-up event A wake-up event is received when the host controller is in the suspend mode:
#define uhd_get_frame_position | ( | ) | USBB_RD_BITFIELD(UHFNUM,FLENHIGH) |
Referenced by uhd_sof_interrupt().
#define uhd_get_microsof_number | ( | ) |
Referenced by uhd_get_microframe_number().
#define uhd_get_pipe_max_nbr | ( | ) |
#define uhd_get_sof_number | ( | ) | USBB_RD_BITFIELD(UHFNUM,FNUM) |
Referenced by uhd_get_frame_number().
#define uhd_get_speed_mode | ( | ) | USBB_RD_BITFIELD(USBSTA,SPEED) |
Referenced by uhd_get_speed().
#define UHD_INTERRUPT_NB_BANK 1 |
Referenced by uhd_ep_alloc().
#define UHD_ISOCHRONOUS_NB_BANK 2 |
Referenced by uhd_ep_alloc().
#define uhd_output_vbof_pin | ( | ) |
Output USB_VBOF onto its pin.
Referenced by uhd_enable().
#define uhd_send_resume | ( | ) | USBB_SET_BITS(UHCON,RESUME) |
Initiates a resume event It is called downstream resume event.
Referenced by uhd_interrupt(), and uhd_resume().
#define uhd_set_vbof_active_high | ( | ) | USBB_CLR_BITS(USBCON,VBUSPO) |
Set USB_VBOF output pin polarity.
Referenced by uhd_enable().
#define uhd_set_vbof_active_low | ( | ) | USBB_SET_BITS(USBCON,VBUSPO) |
Referenced by uhd_enable().
#define uhd_start_reset | ( | ) | USBB_SET_BITS(UHCON,RESET) |
Initiates a reset event.
Referenced by uhd_send_reset().
#define uhd_stop_reset | ( | ) | USBB_CLR_BITS(UHCON,RESET) |
Referenced by uhd_interrupt().
Pin and function for USB_VBOF according to configuration from USB_VBOF.
Bit definitions to store setup request state machine.
enum uhd_usbb_state_enum |
ISR | ( | otg_interrupt | , |
AVR32_USBB_IRQ_GROUP | , | ||
UHD_USB_INT_LEVEL | |||
) |
Function called by USBB interrupt handler to manage USB interrupts.
It manages the interrupt redirection between host or device interrupt. It answers to OTG events (ID pin change).
Note: Here, the global interrupt mask is not cleared when an USB interrupt is enabled because this one can not occurred during the USB ISR (=during INTX is masked). See Technical reference $3.8.3 Masking interrupt requests in peripheral modules.
References Is_otg_clock_usable, Is_otg_device_mode_forced, Is_otg_id_device, Is_otg_id_transition, otg_ack_id_transition, otg_data_memory_barrier, otg_freeze_clock, otg_unfreeze_clock, udc_start(), udc_stop(), udd_interrupt(), UHC_MODE_CHANGE, uhc_start(), uhc_stop(), and uhd_interrupt().
void otg_dual_disable | ( | void | ) |
Uninitialize the dual role This function is implemented in usbb_host.c file.
References otg_disable, otg_disable_id_interrupt, otg_disable_pad, otg_initialized, otg_unfreeze_clock, sysclk_disable_usb(), uhd_sleep_mode(), and UHD_STATE_OFF.
Referenced by uhd_disable().
bool otg_dual_enable | ( | void | ) |
Initialize the dual role This function is implemented in usbb_host.c file.
true
if the ID pin management has been started, otherwise false
. References irq_register_handler, Is_otg_id_device, otg_ack_id_transition, otg_enable, otg_enable_id_interrupt, otg_freeze_clock, otg_initialized, otg_input_id_pin, otg_unfreeze_clock, pm_asyn_wake_up_enable(), sysclk_enable_usb(), udc_start(), UHC_MODE_CHANGE, uhc_start(), uhd_sleep_mode(), UHD_STATE_OFF, UHD_STATE_WAIT_ID_HOST, and UHD_USB_INT_LEVEL.
Referenced by udd_enable(), and uhd_enable().
|
static |
Manages the events related to control endpoint.
References Assert, usb_setup_req_t::bmRequestType, Is_uhd_in_received, Is_uhd_out_ready, Is_uhd_pipe_error, Is_uhd_pipe_frozen, Is_uhd_setup_ready, Is_uhd_stall, uhd_ctrl_request_t::req, uhd_ack_in_received, uhd_ack_out_ready, uhd_ack_setup_ready, uhd_ack_stall, uhd_ctrl_phase_data_in(), uhd_ctrl_phase_data_in_start(), uhd_ctrl_phase_data_out(), uhd_ctrl_phase_zlp_in(), UHD_CTRL_REQ_PHASE_DATA_IN, UHD_CTRL_REQ_PHASE_DATA_OUT, UHD_CTRL_REQ_PHASE_SETUP, UHD_CTRL_REQ_PHASE_ZLP_IN, UHD_CTRL_REQ_PHASE_ZLP_OUT, uhd_ctrl_request_end(), uhd_ctrl_request_phase, uhd_ctrl_request_timeout, uhd_freeze_pipe, uhd_pipe_get_error(), UHD_TRANS_NOERROR, UHD_TRANS_STALL, USB_REQ_DIR_IN, USB_REQ_DIR_MASK, and usb_setup_req_t::wLength.
Referenced by uhd_interrupt().
|
static |
Manages the DATA IN phase on control endpoint.
References uhd_ctrl_request_t::callback_run, Is_uhd_short_packet, uhd_ctrl_request_t::payload, uhd_ctrl_request_t::payload_size, uhd_ctrl_request_t::req, uhd_ack_fifocon, uhd_ack_short_packet, uhd_byte_count, uhd_ctrl_nb_trans, uhd_ctrl_phase_zlp_out(), uhd_enable_in_received_interrupt, uhd_get_configured_address, uhd_get_pipe_fifo_access, uhd_get_pipe_size, uhd_unfreeze_pipe, and usb_setup_req_t::wLength.
Referenced by uhd_ctrl_interrupt().
|
static |
Starts the DATA IN phase on control endpoint.
References uhd_ack_fifocon, uhd_ack_in_received, uhd_ack_short_packet, uhd_configure_pipe_token, UHD_CTRL_REQ_PHASE_DATA_IN, uhd_ctrl_request_phase, uhd_enable_in_received_interrupt, and uhd_unfreeze_pipe.
Referenced by uhd_ctrl_interrupt().
|
static |
Manages the DATA OUT phase on control endpoint.
References uhd_ctrl_request_t::callback_run, uhd_ctrl_request_t::payload, uhd_ctrl_request_t::payload_size, uhd_ctrl_request_t::req, uhd_ack_fifocon, uhd_ack_out_ready, uhd_configure_pipe_token, uhd_ctrl_nb_trans, uhd_ctrl_phase_zlp_in(), UHD_CTRL_REQ_PHASE_DATA_OUT, uhd_ctrl_request_phase, uhd_enable_out_ready_interrupt, uhd_get_configured_address, uhd_get_pipe_fifo_access, uhd_get_pipe_size, uhd_unfreeze_pipe, and usb_setup_req_t::wLength.
Referenced by uhd_ctrl_interrupt().
|
static |
Sends a USB setup packet to start a control request sequence.
References uhd_ctrl_request_t::add, Assert, cpu_to_le16, Is_uhd_pipe_enabled, uhd_ctrl_request_t::req, uhd_ack_fifocon, uhd_ack_setup_ready, uhd_configure_address, uhd_configure_pipe_token, uhd_ctrl_nb_trans, UHD_CTRL_REQ_PHASE_SETUP, uhd_ctrl_request_end(), uhd_ctrl_request_phase, uhd_ctrl_request_timeout, uhd_enable_setup_ready_interrupt, uhd_get_configured_address, uhd_get_pipe_fifo_access, UHD_TRANS_DISCONNECT, and uhd_unfreeze_pipe.
Referenced by uhd_ctrl_request_end(), and uhd_setup_request().
|
static |
Starts the ZLP IN phase on control endpoint.
References uhd_ack_fifocon, uhd_ack_in_received, uhd_ack_short_packet, uhd_configure_pipe_token, UHD_CTRL_REQ_PHASE_ZLP_IN, uhd_ctrl_request_phase, uhd_enable_in_received_interrupt, and uhd_unfreeze_pipe.
Referenced by uhd_ctrl_interrupt(), and uhd_ctrl_phase_data_out().
|
static |
Starts the ZLP OUT phase on control endpoint.
References uhd_ack_fifocon, uhd_ack_out_ready, uhd_configure_pipe_token, UHD_CTRL_REQ_PHASE_ZLP_OUT, uhd_ctrl_request_phase, uhd_enable_out_ready_interrupt, and uhd_unfreeze_pipe.
Referenced by uhd_ctrl_phase_data_in().
|
static |
Call the callback linked to control request and start the next request from the queue.
References uhd_ctrl_request_t::callback_end, cpu_irq_restore(), cpu_irq_save(), uhd_ctrl_request_t::next_request, uhd_b_suspend_requested, uhd_ctrl_nb_trans, uhd_ctrl_phase_setup(), uhd_ctrl_request_first, uhd_ctrl_request_timeout, uhd_get_configured_address, and uhd_suspend().
Referenced by uhd_ctrl_interrupt(), uhd_ctrl_phase_setup(), uhd_ep_free(), and uhd_sof_interrupt().
void uhd_disable | ( | bool | b_id_stop | ) |
Disables the USB host mode.
b_id_stop | Stop ID pin management, if true. |
References Clr_bits, cpu_irq_restore(), cpu_irq_save(), Is_otg_clock_usable, otg_dual_disable(), otg_freeze_clock, otg_unfreeze_clock, uhc_notify_connection(), uhd_disable_sof, uhd_disable_vbus, uhd_sleep_mode(), and UHD_STATE_WAIT_ID_HOST.
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_otg_id_host, Is_otg_vbus_high, otg_ack_vbus_transition, otg_disable_id_pin, otg_dual_enable(), otg_enable, otg_enable_pad, otg_force_host_mode, otg_freeze_clock, otg_raise_vbus_transition, otg_unfreeze_clock, Set_bits, uhd_b_suspend_requested, uhd_ctrl_request_timeout, uhd_enable_vbus, uhd_output_vbof_pin, uhd_resume_start, uhd_set_vbof_active_high, uhd_set_vbof_active_low, uhd_sleep_mode(), UHD_STATE_NO_VBUS, and uhd_suspend_start.
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_configured, Is_uhd_pipe_enabled, uhd_allocate_memory, uhd_configure_address, uhd_configure_pipe, uhd_disable_pipe, uhd_enable_pipe, uhd_enable_pipe_error_interrupt, uhd_enable_pipe_interrupt, and uhd_enable_stall_interrupt.
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(), and UHD_TRANS_ABORTED.
|
static |
Aborts the on going transfer on a pipe.
pipe | Pipe number |
status | Reason of abort |
References uhd_disable_nak_received_interrupt, uhd_disable_out_ready_interrupt, uhd_enable_pipe_bank_autoswitch, uhd_enable_pipe_error_interrupt, uhd_enable_stall_interrupt, uhd_pipe_dma_set_control, uhd_pipe_finish_job(), and uhd_reset_pipe.
Referenced by uhd_ep_abort(), uhd_ep_free(), uhd_pipe_interrupt(), and uhd_sof_interrupt().
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 Assert, usb_ep_desc_t::bEndpointAddress, usb_ep_desc_t::bInterval, usb_ep_desc_t::bmAttributes, Is_uhd_pipe_configured, Is_uhd_pipe_enabled, le16_to_cpu, uhd_allocate_memory, UHD_BULK_INTERVAL_MIN, UHD_BULK_NB_BANK, uhd_configure_address, uhd_configure_pipe, uhd_disable_pipe, uhd_enable_pipe, uhd_enable_pipe_dma_interrupt, uhd_enable_pipe_error_interrupt, uhd_enable_pipe_interrupt, uhd_enable_stall_interrupt, UHD_INTERRUPT_NB_BANK, UHD_ISOCHRONOUS_NB_BANK, UHD_SPEED_HIGH, USB_EP_ADDR_MASK, USB_EP_DIR_IN, USB_EP_TYPE_BULK, USB_EP_TYPE_INTERRUPT, USB_EP_TYPE_ISOCHRONOUS, USB_EP_TYPE_MASK, and usb_ep_desc_t::wMaxPacketSize.
Referenced by uhi_hid_mouse_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, Is_uhd_pipe_enabled, uhd_ctrl_request_end(), uhd_ctrl_request_timeout, uhd_disable_pipe, uhd_ep_abort_pipe(), uhd_get_configured_address, uhd_get_pipe_endpoint_address, UHD_TRANS_DISCONNECT, and uhd_unallocate_memory.
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(), Is_uhd_pipe_bulk_in, uhd_pipe_job_t::nb_trans, uhd_pipe_job_t::timeout, uhd_ack_nak_received, uhd_enable_nak_received_interrupt, uhd_get_pipe(), and uhd_pipe_trans_complet().
Referenced by uhi_hid_mouse_start_trans_report().
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.
Returns the pipe number matching a USB endpoint.
add | USB address |
endp | Endpoint number |
References Is_uhd_pipe_enabled, uhd_get_configured_address, and uhd_get_pipe_endpoint_address.
Referenced by uhd_ep_abort(), and uhd_ep_run().
uhd_speed_t uhd_get_speed | ( | void | ) |
Returns the speed of connected device.
References Assert, uhd_get_speed_mode, UHD_SPEED_FULL, UHD_SPEED_HIGH, and UHD_SPEED_LOW.
Referenced by uhc_enumeration_step4().
|
static |
Function called by USBB interrupt to manage USB host interrupts.
USB host interrupt events are split into four sections:
References Assert, Is_otg_clock_usable, Is_otg_vbus_high, Is_otg_vbus_transition, Is_uhd_connection, Is_uhd_connection_int_enabled, Is_uhd_disconnection, Is_uhd_disconnection_int_enabled, Is_uhd_downstream_resume, Is_uhd_high_speed_mode, Is_uhd_reset_sent, Is_uhd_sof, Is_uhd_upstream_resume, Is_uhd_vbus_error_interrupt, Is_uhd_wakeup, Is_uhd_wakeup_interrupt_enabled, otg_ack_vbus_transition, otg_freeze_clock, otg_unfreeze_clock, uhc_notify_connection(), UHC_VBUS_CHANGE, UHC_VBUS_ERROR, uhd_ack_connection, uhd_ack_disconnection, uhd_ack_reset_sent, uhd_ack_sof, uhd_ack_vbus_error_interrupt, uhd_ctrl_interrupt(), uhd_disable_connection_int, uhd_disable_disconnection_int, uhd_enable_connection_int, uhd_enable_disconnection_int, uhd_enable_sof, uhd_get_interrupt_pipe_number, uhd_get_pipe_dma_interrupt_number, uhd_pipe_interrupt(), uhd_pipe_interrupt_dma(), uhd_reset_callback, uhd_resume_start, uhd_send_resume, uhd_sleep_mode(), uhd_sof_interrupt(), UHD_STATE_DISCONNECT, UHD_STATE_IDLE, UHD_STATE_NO_VBUS, uhd_stop_reset, and uhd_suspend_start.
Referenced by ISR().
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().
|
static |
Call the callback linked to the end of pipe transfer.
pipe | Pipe number |
status | Status of the transfer |
References uhd_pipe_job_t::busy, uhd_pipe_job_t::call_end, uhd_pipe_job_t::nb_trans, uhd_get_configured_address, and uhd_get_pipe_endpoint_address.
Referenced by uhd_ep_abort_pipe(), uhd_pipe_interrupt(), and uhd_pipe_trans_complet().
|
static |
Translates the USBB pipe error to UHD error.
pipe | Pipe number to use |
References uhd_ack_all_errors, uhd_error_status, UHD_TRANS_DT_MISMATCH, UHD_TRANS_NOTRESPONDING, and UHD_TRANS_PIDFAILURE.
Referenced by uhd_ctrl_interrupt(), and uhd_pipe_interrupt().
|
static |
Manages the following pipe interrupts:
pipe | Pipe number |
References Assert, Is_uhd_bank_interrupt_enabled, Is_uhd_nak_received, Is_uhd_nak_received_interrupt_enabled, Is_uhd_out_ready, Is_uhd_out_ready_interrupt_enabled, Is_uhd_pipe_bulk_in, Is_uhd_pipe_error, Is_uhd_stall, uhd_ack_fifocon, uhd_ack_nak_received, uhd_ack_out_ready, uhd_ack_stall, uhd_disable_bank_interrupt, uhd_disable_out_ready_interrupt, uhd_enable_bank_interrupt, uhd_ep_abort_pipe(), uhd_freeze_pipe, uhd_nb_busy_bank, uhd_pipe_finish_job(), uhd_pipe_get_error(), uhd_reset_data_toggle, UHD_TRANS_NOERROR, UHD_TRANS_STALL, and uhd_unfreeze_pipe.
Referenced by uhd_interrupt().
|
static |
Manages the pipe DMA interrupt.
pipe | Pipe number |
References uhd_pipe_job_t::buf_size, Is_uhd_pipe_frozen, uhd_pipe_job_t::nb_trans, uhd_enable_bank_interrupt, uhd_freeze_pipe, uhd_is_pipe_out, uhd_pipe_dma_get_status, and uhd_pipe_trans_complet().
Referenced by uhd_interrupt().
|
static |
Computes and starts the next transfer on a pipe.
pipe | Pipe number |
References uhd_pipe_job_t::b_shortpacket, uhd_pipe_job_t::buf, uhd_pipe_job_t::buf_size, uhd_pipe_job_t::busy, cpu_irq_restore(), cpu_irq_save(), Is_uhd_write_enabled, uhd_pipe_job_t::nb_trans, uhd_ack_out_ready, uhd_disable_bank_interrupt, uhd_disable_nak_received_interrupt, uhd_enable_out_ready_interrupt, uhd_get_pipe_size, uhd_get_pipe_type, uhd_in_request_number, uhd_is_pipe_in, uhd_is_pipe_out, uhd_pipe_dma_get_status, uhd_pipe_dma_set_addr, uhd_pipe_dma_set_control, uhd_pipe_finish_job(), UHD_PIPE_MAX_TRANS, uhd_raise_out_ready, UHD_TRANS_NOERROR, uhd_unfreeze_pipe, and USB_EP_TYPE_ISOCHRONOUS.
Referenced by uhd_ep_run(), and uhd_pipe_interrupt_dma().
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(), and uhc_remotewakeup().
|
static |
Manages the sleep mode following the USBB state.
new_state | New USBB state |
References SLEEPMGR_FROZEN, SLEEPMGR_IDLE, sleepmgr_lock_mode(), SLEEPMGR_STATIC, SLEEPMGR_STOP, sleepmgr_unlock_mode(), and UHD_STATE_OFF.
Referenced by otg_dual_disable(), otg_dual_enable(), uhd_disable(), uhd_enable(), uhd_interrupt(), uhd_resume(), and uhd_sof_interrupt().
|
static |
Manages timeouts and actions based on SOF events.
References uhd_pipe_job_t::busy, Is_uhd_disconnection, Is_uhd_high_speed_mode, Is_uhd_pipe_bulk_in, Is_uhd_pipe_frozen, otg_freeze_clock, uhd_pipe_job_t::timeout, uhc_notify_resume(), uhc_notify_sof(), UHC_SOF_EVENT, uhd_ctrl_request_end(), uhd_ctrl_request_timeout, uhd_disable_sof, uhd_ep_abort_pipe(), uhd_freeze_pipe, uhd_get_frame_position, uhd_pipes_unfreeze, uhd_resume_start, uhd_sleep_mode(), UHD_STATE_SUSPEND, uhd_suspend_start, UHD_TRANS_TIMEOUT, and uhd_unfreeze_pipe.
Referenced by uhd_interrupt().
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_pipes_unfreeze, and uhd_suspend_start.
Referenced by uhc_enumeration_suspend(), uhc_suspend(), and uhd_ctrl_request_end().
void uhd_test_mode_j | ( | void | ) |
References Assert.
void uhd_test_mode_k | ( | void | ) |
References Assert.
void uhd_test_mode_packet | ( | void | ) |
References Assert.
void uhd_test_mode_se0_nak | ( | void | ) |
References Assert.
State of USBB OTG initialization.
Referenced by otg_dual_disable(), and otg_dual_enable().
|
static |
Flag to delay a suspend request after all on-going setup request.
Referenced by uhd_ctrl_request_end(), uhd_enable(), and uhd_suspend().
uint16_t uhd_ctrl_nb_trans |
Number of transfered byte on DATA phase of current setup request.
Referenced by uhd_ctrl_phase_data_in(), uhd_ctrl_phase_data_out(), uhd_ctrl_phase_setup(), and uhd_ctrl_request_end().
struct uhd_ctrl_request_t* uhd_ctrl_request_first |
Entry points of setup request list.
Referenced by uhd_ctrl_request_end().
struct uhd_ctrl_request_t* uhd_ctrl_request_last |
uhd_ctrl_request_phase_t uhd_ctrl_request_phase |
volatile uint16_t uhd_ctrl_request_timeout |
Remaining time for on-going setup request (No request on-going if equal 0)
Referenced by uhd_ctrl_interrupt(), uhd_ctrl_phase_setup(), uhd_ctrl_request_end(), uhd_enable(), uhd_ep_free(), uhd_sof_interrupt(), and uhd_suspend().
|
static |
Array to register a job on bulk/interrupt/isochronous endpoint.
|
static |
Referenced by uhd_sof_interrupt(), and uhd_suspend().
|
static |
Store the callback to be call at the end of reset signal.
Referenced by uhd_interrupt(), and uhd_send_reset().
|
static |
Referenced by uhd_enable(), uhd_interrupt(), uhd_resume(), and uhd_sof_interrupt().
|
static |
Variables to manage the suspend/resume sequence.
Referenced by uhd_enable(), uhd_interrupt(), uhd_resume(), uhd_sof_interrupt(), and uhd_suspend().