|
|
@@ -14,7 +14,7 @@
|
|
|
#include "esp_intr_alloc.h"
|
|
|
#include "esp_err.h"
|
|
|
#include "esp_rom_gpio.h"
|
|
|
-#include "hal/usbh_hal.h"
|
|
|
+#include "hal/usb_dwc_hal.h"
|
|
|
#include "hal/usb_types_private.h"
|
|
|
#include "soc/gpio_pins.h"
|
|
|
#include "soc/gpio_sig_map.h"
|
|
|
@@ -52,7 +52,7 @@ typedef struct {
|
|
|
*
|
|
|
* RXFIFO
|
|
|
* - Recommended: ((LPS/4) * 2) + 2
|
|
|
- * - Actual: Whatever leftover size: USBH_HAL_FIFO_TOTAL_USABLE_LINES(200) - 48 - 48 = 104
|
|
|
+ * - Actual: Whatever leftover size: USB_DWC_HAL_FIFO_TOTAL_USABLE_LINES(200) - 48 - 48 = 104
|
|
|
* - Worst case can accommodate two packets of 204 bytes, or one packet of 408
|
|
|
* NPTXFIFO
|
|
|
* - Recommended: (LPS/4) * 2
|
|
|
@@ -63,7 +63,7 @@ typedef struct {
|
|
|
* - Actual: Assume LPS is 64, and 3 packets: (64/4) * 3 = 48
|
|
|
* - Worst case can accommodate three packets of 64 bytes or one packet of 192
|
|
|
*/
|
|
|
-const usbh_hal_fifo_config_t fifo_config_default = {
|
|
|
+const usb_dwc_hal_fifo_config_t fifo_config_default = {
|
|
|
.rx_fifo_lines = 104,
|
|
|
.nptx_fifo_lines = 48,
|
|
|
.ptx_fifo_lines = 48,
|
|
|
@@ -80,7 +80,7 @@ const fifo_mps_limits_t mps_limits_default = {
|
|
|
*
|
|
|
* RXFIFO
|
|
|
* - Recommended: ((LPS/4) * 2) + 2
|
|
|
- * - Actual: Whatever leftover size: USBH_HAL_FIFO_TOTAL_USABLE_LINES(200) - 32 - 16 = 152
|
|
|
+ * - Actual: Whatever leftover size: USB_DWC_HAL_FIFO_TOTAL_USABLE_LINES(200) - 32 - 16 = 152
|
|
|
* - Worst case can accommodate two packets of 300 bytes or one packet of 600 bytes
|
|
|
* NPTXFIFO
|
|
|
* - Recommended: (LPS/4) * 2
|
|
|
@@ -91,7 +91,7 @@ const fifo_mps_limits_t mps_limits_default = {
|
|
|
* - Actual: Assume LPS is 64, and 3 packets: (64/4) * 2 = 32
|
|
|
* - Worst case can accommodate two packets of 64 bytes or one packet of 128
|
|
|
*/
|
|
|
-const usbh_hal_fifo_config_t fifo_config_bias_rx = {
|
|
|
+const usb_dwc_hal_fifo_config_t fifo_config_bias_rx = {
|
|
|
.rx_fifo_lines = 152,
|
|
|
.nptx_fifo_lines = 16,
|
|
|
.ptx_fifo_lines = 32,
|
|
|
@@ -116,10 +116,10 @@ const fifo_mps_limits_t mps_limits_bias_rx = {
|
|
|
* - Worst case can accommodate one packet of 64 bytes
|
|
|
* PTXFIFO
|
|
|
* - Recommended: (LPS/4) * 2
|
|
|
- * - Actual: Whatever leftover size: USBH_HAL_FIFO_TOTAL_USABLE_LINES(200) - 34 - 16 = 150
|
|
|
+ * - Actual: Whatever leftover size: USB_DWC_HAL_FIFO_TOTAL_USABLE_LINES(200) - 34 - 16 = 150
|
|
|
* - Worst case can accommodate two packets of 300 bytes or one packet of 600 bytes
|
|
|
*/
|
|
|
-const usbh_hal_fifo_config_t fifo_config_bias_ptx = {
|
|
|
+const usb_dwc_hal_fifo_config_t fifo_config_bias_ptx = {
|
|
|
.rx_fifo_lines = 34,
|
|
|
.nptx_fifo_lines = 16,
|
|
|
.ptx_fifo_lines = 150,
|
|
|
@@ -248,8 +248,8 @@ struct pipe_obj {
|
|
|
uint32_t val;
|
|
|
} multi_buffer_control;
|
|
|
//HAL related
|
|
|
- usbh_hal_chan_t *chan_obj;
|
|
|
- usbh_hal_ep_char_t ep_char;
|
|
|
+ usb_dwc_hal_chan_t *chan_obj;
|
|
|
+ usb_dwc_hal_ep_char_t ep_char;
|
|
|
//Port related
|
|
|
port_t *port; //The port to which this pipe is routed through
|
|
|
TAILQ_ENTRY(pipe_obj) tailq_entry; //TailQ entry for port's list of pipes
|
|
|
@@ -278,7 +278,7 @@ struct pipe_obj {
|
|
|
* @brief Object representing a port in the HCD layer
|
|
|
*/
|
|
|
struct port_obj {
|
|
|
- usbh_hal_context_t *hal;
|
|
|
+ usb_dwc_hal_context_t *hal;
|
|
|
void *frame_list;
|
|
|
//Pipes routed through this port
|
|
|
TAILQ_HEAD(tailhead_pipes_idle, pipe_obj) pipes_idle_tailq;
|
|
|
@@ -304,7 +304,7 @@ struct port_obj {
|
|
|
} flags;
|
|
|
bool initialized;
|
|
|
//FIFO biasing related
|
|
|
- const usbh_hal_fifo_config_t *fifo_config;
|
|
|
+ const usb_dwc_hal_fifo_config_t *fifo_config;
|
|
|
const fifo_mps_limits_t *fifo_mps_limits;
|
|
|
//Port callback and context
|
|
|
hcd_port_callback_t callback;
|
|
|
@@ -389,7 +389,7 @@ static void _buffer_exec(pipe_t *pipe);
|
|
|
/**
|
|
|
* @brief Check if a buffer as completed execution
|
|
|
*
|
|
|
- * This should only be called after receiving a USBH_HAL_CHAN_EVENT_CPLT event to check if a buffer is actually
|
|
|
+ * This should only be called after receiving a USB_DWC_HAL_CHAN_EVENT_CPLT event to check if a buffer is actually
|
|
|
* done.
|
|
|
*
|
|
|
* @param pipe Pipe object
|
|
|
@@ -489,7 +489,7 @@ static bool _buffer_flush_all(pipe_t *pipe, bool canceled);
|
|
|
* @param chan_error The HAL channel error
|
|
|
* @return hcd_pipe_event_t The corresponding pipe error event
|
|
|
*/
|
|
|
-static inline hcd_pipe_event_t pipe_decode_error_event(usbh_hal_chan_error_t chan_error);
|
|
|
+static inline hcd_pipe_event_t pipe_decode_error_event(usb_dwc_hal_chan_error_t chan_error);
|
|
|
|
|
|
/**
|
|
|
* @brief Halt a pipe
|
|
|
@@ -764,30 +764,30 @@ static bool _internal_pipe_event_notify(pipe_t *pipe, bool from_isr)
|
|
|
* @param[out] yield Set to true if a yield is required as a result of handling the interrupt
|
|
|
* @return hcd_port_event_t Returns a port event, or HCD_PORT_EVENT_NONE if no port event occurred
|
|
|
*/
|
|
|
-static hcd_port_event_t _intr_hdlr_hprt(port_t *port, usbh_hal_port_event_t hal_port_event, bool *yield)
|
|
|
+static hcd_port_event_t _intr_hdlr_hprt(port_t *port, usb_dwc_hal_port_event_t hal_port_event, bool *yield)
|
|
|
{
|
|
|
hcd_port_event_t port_event = HCD_PORT_EVENT_NONE;
|
|
|
switch (hal_port_event) {
|
|
|
- case USBH_HAL_PORT_EVENT_CONN: {
|
|
|
+ case USB_DWC_HAL_PORT_EVENT_CONN: {
|
|
|
//Don't update state immediately, we still need to debounce.
|
|
|
port_event = HCD_PORT_EVENT_CONNECTION;
|
|
|
break;
|
|
|
}
|
|
|
- case USBH_HAL_PORT_EVENT_DISCONN: {
|
|
|
+ case USB_DWC_HAL_PORT_EVENT_DISCONN: {
|
|
|
port->state = HCD_PORT_STATE_RECOVERY;
|
|
|
port_event = HCD_PORT_EVENT_DISCONNECTION;
|
|
|
port->flags.conn_dev_ena = 0;
|
|
|
break;
|
|
|
}
|
|
|
- case USBH_HAL_PORT_EVENT_ENABLED: {
|
|
|
- usbh_hal_port_enable(port->hal); //Initialize remaining host port registers
|
|
|
- port->speed = (usbh_hal_port_get_conn_speed(port->hal) == USB_PRIV_SPEED_FULL) ? USB_SPEED_FULL : USB_SPEED_LOW;
|
|
|
+ case USB_DWC_HAL_PORT_EVENT_ENABLED: {
|
|
|
+ usb_dwc_hal_port_enable(port->hal); //Initialize remaining host port registers
|
|
|
+ port->speed = (usb_dwc_hal_port_get_conn_speed(port->hal) == USB_PRIV_SPEED_FULL) ? USB_SPEED_FULL : USB_SPEED_LOW;
|
|
|
port->state = HCD_PORT_STATE_ENABLED;
|
|
|
port->flags.conn_dev_ena = 1;
|
|
|
//This was triggered by a command, so no event needs to be propagated.
|
|
|
break;
|
|
|
}
|
|
|
- case USBH_HAL_PORT_EVENT_DISABLED: {
|
|
|
+ case USB_DWC_HAL_PORT_EVENT_DISABLED: {
|
|
|
port->flags.conn_dev_ena = 0;
|
|
|
//Disabled could be due to a disable request or reset request, or due to a port error
|
|
|
if (port->state != HCD_PORT_STATE_RESETTING) { //Ignore the disable event if it's due to a reset request
|
|
|
@@ -804,11 +804,11 @@ static hcd_port_event_t _intr_hdlr_hprt(port_t *port, usbh_hal_port_event_t hal_
|
|
|
}
|
|
|
break;
|
|
|
}
|
|
|
- case USBH_HAL_PORT_EVENT_OVRCUR:
|
|
|
- case USBH_HAL_PORT_EVENT_OVRCUR_CLR: { //Could occur if a quick overcurrent then clear happens
|
|
|
+ case USB_DWC_HAL_PORT_EVENT_OVRCUR:
|
|
|
+ case USB_DWC_HAL_PORT_EVENT_OVRCUR_CLR: { //Could occur if a quick overcurrent then clear happens
|
|
|
if (port->state != HCD_PORT_STATE_NOT_POWERED) {
|
|
|
//We need to power OFF the port to protect it
|
|
|
- usbh_hal_port_toggle_power(port->hal, false);
|
|
|
+ usb_dwc_hal_port_toggle_power(port->hal, false);
|
|
|
port->state = HCD_PORT_STATE_RECOVERY;
|
|
|
port_event = HCD_PORT_EVENT_OVERCURRENT;
|
|
|
}
|
|
|
@@ -834,13 +834,13 @@ static hcd_port_event_t _intr_hdlr_hprt(port_t *port, usbh_hal_port_event_t hal_
|
|
|
* @param[out] yield Set to true if a yield is required as a result of handling the interrupt
|
|
|
* @return hcd_pipe_event_t The pipe event
|
|
|
*/
|
|
|
-static hcd_pipe_event_t _intr_hdlr_chan(pipe_t *pipe, usbh_hal_chan_t *chan_obj, bool *yield)
|
|
|
+static hcd_pipe_event_t _intr_hdlr_chan(pipe_t *pipe, usb_dwc_hal_chan_t *chan_obj, bool *yield)
|
|
|
{
|
|
|
- usbh_hal_chan_event_t chan_event = usbh_hal_chan_decode_intr(chan_obj);
|
|
|
+ usb_dwc_hal_chan_event_t chan_event = usb_dwc_hal_chan_decode_intr(chan_obj);
|
|
|
hcd_pipe_event_t event = HCD_PIPE_EVENT_NONE;
|
|
|
|
|
|
switch (chan_event) {
|
|
|
- case USBH_HAL_CHAN_EVENT_CPLT: {
|
|
|
+ case USB_DWC_HAL_CHAN_EVENT_CPLT: {
|
|
|
if (!_buffer_check_done(pipe)) {
|
|
|
_buffer_exec_cont(pipe);
|
|
|
break;
|
|
|
@@ -848,7 +848,7 @@ static hcd_pipe_event_t _intr_hdlr_chan(pipe_t *pipe, usbh_hal_chan_t *chan_obj,
|
|
|
pipe->last_event = HCD_PIPE_EVENT_URB_DONE;
|
|
|
event = pipe->last_event;
|
|
|
//Mark the buffer as done
|
|
|
- int stop_idx = usbh_hal_chan_get_qtd_idx(chan_obj);
|
|
|
+ int stop_idx = usb_dwc_hal_chan_get_qtd_idx(chan_obj);
|
|
|
_buffer_done(pipe, stop_idx, pipe->last_event, false);
|
|
|
//First check if there is another buffer we can execute. But we only want to execute if there's still a valid device
|
|
|
if (_buffer_can_exec(pipe) && pipe->port->flags.conn_dev_ena) {
|
|
|
@@ -864,27 +864,27 @@ static hcd_pipe_event_t _intr_hdlr_chan(pipe_t *pipe, usbh_hal_chan_t *chan_obj,
|
|
|
}
|
|
|
break;
|
|
|
}
|
|
|
- case USBH_HAL_CHAN_EVENT_ERROR: {
|
|
|
+ case USB_DWC_HAL_CHAN_EVENT_ERROR: {
|
|
|
//Get and store the pipe error event
|
|
|
- usbh_hal_chan_error_t chan_error = usbh_hal_chan_get_error(chan_obj);
|
|
|
+ usb_dwc_hal_chan_error_t chan_error = usb_dwc_hal_chan_get_error(chan_obj);
|
|
|
pipe->last_event = pipe_decode_error_event(chan_error);
|
|
|
event = pipe->last_event;
|
|
|
pipe->state = HCD_PIPE_STATE_HALTED;
|
|
|
//Mark the buffer as done with an error
|
|
|
- int stop_idx = usbh_hal_chan_get_qtd_idx(chan_obj);
|
|
|
+ int stop_idx = usb_dwc_hal_chan_get_qtd_idx(chan_obj);
|
|
|
_buffer_done(pipe, stop_idx, pipe->last_event, false);
|
|
|
//Parse the buffer
|
|
|
_buffer_parse(pipe);
|
|
|
break;
|
|
|
}
|
|
|
- case USBH_HAL_CHAN_EVENT_HALT_REQ: {
|
|
|
+ case USB_DWC_HAL_CHAN_EVENT_HALT_REQ: {
|
|
|
assert(pipe->cs_flags.waiting_halt);
|
|
|
//We've halted a transfer, so we need to trigger the pipe callback
|
|
|
pipe->last_event = HCD_PIPE_EVENT_URB_DONE;
|
|
|
event = pipe->last_event;
|
|
|
//Halt request event is triggered when packet is successful completed. But just treat all halted transfers as errors
|
|
|
pipe->state = HCD_PIPE_STATE_HALTED;
|
|
|
- int stop_idx = usbh_hal_chan_get_qtd_idx(chan_obj);
|
|
|
+ int stop_idx = usb_dwc_hal_chan_get_qtd_idx(chan_obj);
|
|
|
_buffer_done(pipe, stop_idx, HCD_PIPE_EVENT_NONE, true);
|
|
|
//Parse the buffer
|
|
|
_buffer_parse(pipe);
|
|
|
@@ -892,7 +892,7 @@ static hcd_pipe_event_t _intr_hdlr_chan(pipe_t *pipe, usbh_hal_chan_t *chan_obj,
|
|
|
*yield |= _internal_pipe_event_notify(pipe, true);
|
|
|
break;
|
|
|
}
|
|
|
- case USBH_HAL_CHAN_EVENT_NONE: {
|
|
|
+ case USB_DWC_HAL_CHAN_EVENT_NONE: {
|
|
|
break; //Nothing to do
|
|
|
}
|
|
|
default:
|
|
|
@@ -919,12 +919,12 @@ static void intr_hdlr_main(void *arg)
|
|
|
bool yield = false;
|
|
|
|
|
|
HCD_ENTER_CRITICAL_ISR();
|
|
|
- usbh_hal_port_event_t hal_port_evt = usbh_hal_decode_intr(port->hal);
|
|
|
- if (hal_port_evt == USBH_HAL_PORT_EVENT_CHAN) {
|
|
|
+ usb_dwc_hal_port_event_t hal_port_evt = usb_dwc_hal_decode_intr(port->hal);
|
|
|
+ if (hal_port_evt == USB_DWC_HAL_PORT_EVENT_CHAN) {
|
|
|
//Channel event. Cycle through each pending channel
|
|
|
- usbh_hal_chan_t *chan_obj = usbh_hal_get_chan_pending_intr(port->hal);
|
|
|
+ usb_dwc_hal_chan_t *chan_obj = usb_dwc_hal_get_chan_pending_intr(port->hal);
|
|
|
while (chan_obj != NULL) {
|
|
|
- pipe_t *pipe = (pipe_t *)usbh_hal_chan_get_context(chan_obj);
|
|
|
+ pipe_t *pipe = (pipe_t *)usb_dwc_hal_chan_get_context(chan_obj);
|
|
|
hcd_pipe_event_t event = _intr_hdlr_chan(pipe, chan_obj, &yield);
|
|
|
//Run callback if a pipe event has occurred and the pipe also has a callback
|
|
|
if (event != HCD_PIPE_EVENT_NONE && pipe->callback != NULL) {
|
|
|
@@ -933,9 +933,9 @@ static void intr_hdlr_main(void *arg)
|
|
|
HCD_ENTER_CRITICAL_ISR();
|
|
|
}
|
|
|
//Check for more channels with pending interrupts. Returns NULL if there are no more
|
|
|
- chan_obj = usbh_hal_get_chan_pending_intr(port->hal);
|
|
|
+ chan_obj = usb_dwc_hal_get_chan_pending_intr(port->hal);
|
|
|
}
|
|
|
- } else if (hal_port_evt != USBH_HAL_PORT_EVENT_NONE) { //Port event
|
|
|
+ } else if (hal_port_evt != USB_DWC_HAL_PORT_EVENT_NONE) { //Port event
|
|
|
hcd_port_event_t port_event = _intr_hdlr_hprt(port, hal_port_evt, &yield);
|
|
|
if (port_event != HCD_PORT_EVENT_NONE) {
|
|
|
port->last_event = port_event;
|
|
|
@@ -959,8 +959,8 @@ static void intr_hdlr_main(void *arg)
|
|
|
static port_t *port_obj_alloc(void)
|
|
|
{
|
|
|
port_t *port = calloc(1, sizeof(port_t));
|
|
|
- usbh_hal_context_t *hal = malloc(sizeof(usbh_hal_context_t));
|
|
|
- void *frame_list = heap_caps_aligned_calloc(USBH_HAL_FRAME_LIST_MEM_ALIGN, FRAME_LIST_LEN,sizeof(uint32_t), MALLOC_CAP_DMA);
|
|
|
+ usb_dwc_hal_context_t *hal = malloc(sizeof(usb_dwc_hal_context_t));
|
|
|
+ void *frame_list = heap_caps_aligned_calloc(USB_DWC_HAL_FRAME_LIST_MEM_ALIGN, FRAME_LIST_LEN,sizeof(uint32_t), MALLOC_CAP_DMA);
|
|
|
SemaphoreHandle_t port_mux = xSemaphoreCreateMutex();
|
|
|
if (port == NULL || hal == NULL || frame_list == NULL || port_mux == NULL) {
|
|
|
free(port);
|
|
|
@@ -1081,7 +1081,7 @@ static bool _port_persist_all_pipes(port_t *port)
|
|
|
}
|
|
|
TAILQ_FOREACH(pipe, &port->pipes_idle_tailq, tailq_entry) {
|
|
|
pipe->cs_flags.reset_lock = 1;
|
|
|
- usbh_hal_chan_free(port->hal, pipe->chan_obj);
|
|
|
+ usb_dwc_hal_chan_free(port->hal, pipe->chan_obj);
|
|
|
}
|
|
|
return true;
|
|
|
}
|
|
|
@@ -1092,8 +1092,8 @@ static void _port_recover_all_pipes(port_t *port)
|
|
|
TAILQ_FOREACH(pipe, &port->pipes_idle_tailq, tailq_entry) {
|
|
|
pipe->cs_flags.persist = 0;
|
|
|
pipe->cs_flags.reset_lock = 0;
|
|
|
- usbh_hal_chan_alloc(port->hal, pipe->chan_obj, (void *)pipe);
|
|
|
- usbh_hal_chan_set_ep_char(port->hal, pipe->chan_obj, &pipe->ep_char);
|
|
|
+ usb_dwc_hal_chan_alloc(port->hal, pipe->chan_obj, (void *)pipe);
|
|
|
+ usb_dwc_hal_chan_set_ep_char(port->hal, pipe->chan_obj, &pipe->ep_char);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -1126,14 +1126,14 @@ static bool _port_debounce(port_t *port)
|
|
|
vTaskDelay(pdMS_TO_TICKS(DEBOUNCE_DELAY_MS));
|
|
|
HCD_ENTER_CRITICAL();
|
|
|
//Check the post-debounce state of the bus (i.e., whether it's actually connected/disconnected)
|
|
|
- bool is_connected = usbh_hal_port_check_if_connected(port->hal);
|
|
|
+ bool is_connected = usb_dwc_hal_port_check_if_connected(port->hal);
|
|
|
if (is_connected) {
|
|
|
port->state = HCD_PORT_STATE_DISABLED;
|
|
|
} else {
|
|
|
port->state = HCD_PORT_STATE_DISCONNECTED;
|
|
|
}
|
|
|
//Disable debounce lock
|
|
|
- usbh_hal_disable_debounce_lock(port->hal);
|
|
|
+ usb_dwc_hal_disable_debounce_lock(port->hal);
|
|
|
return is_connected;
|
|
|
}
|
|
|
|
|
|
@@ -1145,8 +1145,8 @@ static esp_err_t _port_cmd_power_on(port_t *port)
|
|
|
//Port can only be powered on if it's currently unpowered
|
|
|
if (port->state == HCD_PORT_STATE_NOT_POWERED) {
|
|
|
port->state = HCD_PORT_STATE_DISCONNECTED;
|
|
|
- usbh_hal_port_init(port->hal);
|
|
|
- usbh_hal_port_toggle_power(port->hal, true);
|
|
|
+ usb_dwc_hal_port_init(port->hal);
|
|
|
+ usb_dwc_hal_port_toggle_power(port->hal, true);
|
|
|
ret = ESP_OK;
|
|
|
} else {
|
|
|
ret = ESP_ERR_INVALID_STATE;
|
|
|
@@ -1160,8 +1160,8 @@ static esp_err_t _port_cmd_power_off(port_t *port)
|
|
|
//Port can only be unpowered if already powered
|
|
|
if (port->state != HCD_PORT_STATE_NOT_POWERED) {
|
|
|
port->state = HCD_PORT_STATE_NOT_POWERED;
|
|
|
- usbh_hal_port_deinit(port->hal);
|
|
|
- usbh_hal_port_toggle_power(port->hal, false);
|
|
|
+ usb_dwc_hal_port_deinit(port->hal);
|
|
|
+ usb_dwc_hal_port_toggle_power(port->hal, false);
|
|
|
//If a device is currently connected, this should trigger a disconnect event
|
|
|
ret = ESP_OK;
|
|
|
} else {
|
|
|
@@ -1187,7 +1187,7 @@ static esp_err_t _port_cmd_reset(port_t *port)
|
|
|
//All pipes (if any_) are guaranteed to be persistent at this point. Proceed to resetting the bus
|
|
|
port->state = HCD_PORT_STATE_RESETTING;
|
|
|
//Put and hold the bus in the reset state. If the port was previously enabled, a disabled event will occur after this
|
|
|
- usbh_hal_port_toggle_reset(port->hal, true);
|
|
|
+ usb_dwc_hal_port_toggle_reset(port->hal, true);
|
|
|
HCD_EXIT_CRITICAL();
|
|
|
vTaskDelay(pdMS_TO_TICKS(RESET_HOLD_MS));
|
|
|
HCD_ENTER_CRITICAL();
|
|
|
@@ -1197,7 +1197,7 @@ static esp_err_t _port_cmd_reset(port_t *port)
|
|
|
goto bailout;
|
|
|
}
|
|
|
//Return the bus to the idle state and hold it for the required reset recovery time. Port enabled event should occur
|
|
|
- usbh_hal_port_toggle_reset(port->hal, false);
|
|
|
+ usb_dwc_hal_port_toggle_reset(port->hal, false);
|
|
|
HCD_EXIT_CRITICAL();
|
|
|
vTaskDelay(pdMS_TO_TICKS(RESET_RECOVERY_MS));
|
|
|
HCD_ENTER_CRITICAL();
|
|
|
@@ -1207,10 +1207,10 @@ static esp_err_t _port_cmd_reset(port_t *port)
|
|
|
goto bailout;
|
|
|
}
|
|
|
//Set FIFO sizes based on the selected biasing
|
|
|
- usbh_hal_set_fifo_size(port->hal, port->fifo_config);
|
|
|
+ usb_dwc_hal_set_fifo_size(port->hal, port->fifo_config);
|
|
|
//We start periodic scheduling only after a RESET command since SOFs only start after a reset
|
|
|
- usbh_hal_port_set_frame_list(port->hal, port->frame_list, FRAME_LIST_LEN);
|
|
|
- usbh_hal_port_periodic_enable(port->hal);
|
|
|
+ usb_dwc_hal_port_set_frame_list(port->hal, port->frame_list, FRAME_LIST_LEN);
|
|
|
+ usb_dwc_hal_port_periodic_enable(port->hal);
|
|
|
ret = ESP_OK;
|
|
|
bailout:
|
|
|
if (is_runtime_reset) {
|
|
|
@@ -1229,7 +1229,7 @@ static esp_err_t _port_cmd_bus_suspend(port_t *port)
|
|
|
goto exit;
|
|
|
}
|
|
|
//All pipes are guaranteed halted at this point. Proceed to suspend the port
|
|
|
- usbh_hal_port_suspend(port->hal);
|
|
|
+ usb_dwc_hal_port_suspend(port->hal);
|
|
|
port->state = HCD_PORT_STATE_SUSPENDED;
|
|
|
ret = ESP_OK;
|
|
|
exit:
|
|
|
@@ -1245,13 +1245,13 @@ static esp_err_t _port_cmd_bus_resume(port_t *port)
|
|
|
goto exit;
|
|
|
}
|
|
|
//Put and hold the bus in the K state.
|
|
|
- usbh_hal_port_toggle_resume(port->hal, true);
|
|
|
+ usb_dwc_hal_port_toggle_resume(port->hal, true);
|
|
|
port->state = HCD_PORT_STATE_RESUMING;
|
|
|
HCD_EXIT_CRITICAL();
|
|
|
vTaskDelay(pdMS_TO_TICKS(RESUME_HOLD_MS));
|
|
|
HCD_ENTER_CRITICAL();
|
|
|
//Return and hold the bus to the J state (as port of the LS EOP)
|
|
|
- usbh_hal_port_toggle_resume(port->hal, false);
|
|
|
+ usb_dwc_hal_port_toggle_resume(port->hal, false);
|
|
|
if (port->state != HCD_PORT_STATE_RESUMING || !port->flags.conn_dev_ena) {
|
|
|
//Port state unexpectedly changed
|
|
|
ret = ESP_ERR_INVALID_RESPONSE;
|
|
|
@@ -1285,7 +1285,7 @@ static esp_err_t _port_cmd_disable(port_t *port)
|
|
|
}
|
|
|
//All pipes are guaranteed to be halted or freed at this point. Proceed to disable the port
|
|
|
port->flags.disable_requested = 1;
|
|
|
- usbh_hal_port_disable(port->hal);
|
|
|
+ usb_dwc_hal_port_disable(port->hal);
|
|
|
_internal_port_event_wait(port);
|
|
|
if (port->state != HCD_PORT_STATE_DISABLED) {
|
|
|
//Port state unexpectedly changed
|
|
|
@@ -1305,7 +1305,7 @@ esp_err_t hcd_port_init(int port_number, const hcd_port_config_t *port_config, h
|
|
|
HCD_CHECK(port_number <= NUM_PORTS, ESP_ERR_NOT_FOUND);
|
|
|
|
|
|
//Get a pointer to the correct FIFO bias constant values
|
|
|
- const usbh_hal_fifo_config_t *fifo_config;
|
|
|
+ const usb_dwc_hal_fifo_config_t *fifo_config;
|
|
|
const fifo_mps_limits_t *mps_limits;
|
|
|
switch (port_config->fifo_bias) {
|
|
|
case HCD_PORT_FIFO_BIAS_BALANCED:
|
|
|
@@ -1340,7 +1340,7 @@ esp_err_t hcd_port_init(int port_number, const hcd_port_config_t *port_config, h
|
|
|
port_obj->callback = port_config->callback;
|
|
|
port_obj->callback_arg = port_config->callback_arg;
|
|
|
port_obj->context = port_config->context;
|
|
|
- usbh_hal_init(port_obj->hal);
|
|
|
+ usb_dwc_hal_init(port_obj->hal);
|
|
|
port_obj->initialized = true;
|
|
|
//Clear the frame list. We set the frame list register and enable periodic scheduling after a successful reset
|
|
|
memset(port_obj->frame_list, 0, FRAME_LIST_LEN * sizeof(uint32_t));
|
|
|
@@ -1364,7 +1364,7 @@ esp_err_t hcd_port_deinit(hcd_port_handle_t port_hdl)
|
|
|
ESP_ERR_INVALID_STATE);
|
|
|
port->initialized = false;
|
|
|
esp_intr_disable(s_hcd_obj->isr_hdl);
|
|
|
- usbh_hal_deinit(port->hal);
|
|
|
+ usb_dwc_hal_deinit(port->hal);
|
|
|
HCD_EXIT_CRITICAL();
|
|
|
|
|
|
return ESP_OK;
|
|
|
@@ -1428,7 +1428,7 @@ esp_err_t hcd_port_get_speed(hcd_port_handle_t port_hdl, usb_speed_t *speed)
|
|
|
HCD_ENTER_CRITICAL();
|
|
|
//Device speed is only valid if there is device connected to the port that has been reset
|
|
|
HCD_CHECK_FROM_CRIT(port->flags.conn_dev_ena, ESP_ERR_INVALID_STATE);
|
|
|
- usb_priv_speed_t hal_speed = usbh_hal_port_get_conn_speed(port->hal);
|
|
|
+ usb_priv_speed_t hal_speed = usb_dwc_hal_port_get_conn_speed(port->hal);
|
|
|
if (hal_speed == USB_PRIV_SPEED_FULL) {
|
|
|
*speed = USB_SPEED_FULL;
|
|
|
} else {
|
|
|
@@ -1483,12 +1483,12 @@ esp_err_t hcd_port_recover(hcd_port_handle_t port_hdl)
|
|
|
ESP_ERR_INVALID_STATE);
|
|
|
//We are about to do a soft reset on the peripheral. Disable the peripheral throughout
|
|
|
esp_intr_disable(s_hcd_obj->isr_hdl);
|
|
|
- usbh_hal_core_soft_reset(port->hal);
|
|
|
+ usb_dwc_hal_core_soft_reset(port->hal);
|
|
|
port->state = HCD_PORT_STATE_NOT_POWERED;
|
|
|
port->last_event = HCD_PORT_EVENT_NONE;
|
|
|
port->flags.val = 0;
|
|
|
//Soft reset wipes all registers so we need to reinitialize the HAL
|
|
|
- usbh_hal_init(port->hal);
|
|
|
+ usb_dwc_hal_init(port->hal);
|
|
|
//Clear the frame list. We set the frame list register and enable periodic scheduling after a successful reset
|
|
|
memset(port->frame_list, 0, FRAME_LIST_LEN * sizeof(uint32_t));
|
|
|
esp_intr_enable(s_hcd_obj->isr_hdl);
|
|
|
@@ -1510,7 +1510,7 @@ esp_err_t hcd_port_set_fifo_bias(hcd_port_handle_t port_hdl, hcd_port_fifo_bias_
|
|
|
{
|
|
|
esp_err_t ret;
|
|
|
//Get a pointer to the correct FIFO bias constant values
|
|
|
- const usbh_hal_fifo_config_t *fifo_config;
|
|
|
+ const usb_dwc_hal_fifo_config_t *fifo_config;
|
|
|
const fifo_mps_limits_t *mps_limits;
|
|
|
switch (bias) {
|
|
|
case HCD_PORT_FIFO_BIAS_BALANCED:
|
|
|
@@ -1537,7 +1537,7 @@ esp_err_t hcd_port_set_fifo_bias(hcd_port_handle_t port_hdl, hcd_port_fifo_bias_
|
|
|
HCD_ENTER_CRITICAL();
|
|
|
//Check that port is in the correct state to update FIFO sizes
|
|
|
if (port->initialized && !port->flags.event_pending && port->num_pipes_idle == 0 && port->num_pipes_queued == 0) {
|
|
|
- usbh_hal_set_fifo_size(port->hal, fifo_config);
|
|
|
+ usb_dwc_hal_set_fifo_size(port->hal, fifo_config);
|
|
|
port->fifo_config = fifo_config;
|
|
|
port->fifo_mps_limits = mps_limits;
|
|
|
ret = ESP_OK;
|
|
|
@@ -1553,20 +1553,20 @@ esp_err_t hcd_port_set_fifo_bias(hcd_port_handle_t port_hdl, hcd_port_fifo_bias_
|
|
|
|
|
|
// ----------------------- Private -------------------------
|
|
|
|
|
|
-static inline hcd_pipe_event_t pipe_decode_error_event(usbh_hal_chan_error_t chan_error)
|
|
|
+static inline hcd_pipe_event_t pipe_decode_error_event(usb_dwc_hal_chan_error_t chan_error)
|
|
|
{
|
|
|
hcd_pipe_event_t event = HCD_PIPE_EVENT_NONE;
|
|
|
switch (chan_error) {
|
|
|
- case USBH_HAL_CHAN_ERROR_XCS_XACT:
|
|
|
+ case USB_DWC_HAL_CHAN_ERROR_XCS_XACT:
|
|
|
event = HCD_PIPE_EVENT_ERROR_XFER;
|
|
|
break;
|
|
|
- case USBH_HAL_CHAN_ERROR_BNA:
|
|
|
+ case USB_DWC_HAL_CHAN_ERROR_BNA:
|
|
|
event = HCD_PIPE_EVENT_ERROR_URB_NOT_AVAIL;
|
|
|
break;
|
|
|
- case USBH_HAL_CHAN_ERROR_PKT_BBL:
|
|
|
+ case USB_DWC_HAL_CHAN_ERROR_PKT_BBL:
|
|
|
event = HCD_PIPE_EVENT_ERROR_OVERFLOW;
|
|
|
break;
|
|
|
- case USBH_HAL_CHAN_ERROR_STALL:
|
|
|
+ case USB_DWC_HAL_CHAN_ERROR_STALL:
|
|
|
event = HCD_PIPE_EVENT_ERROR_STALL;
|
|
|
break;
|
|
|
}
|
|
|
@@ -1591,7 +1591,7 @@ static dma_buffer_block_t *buffer_block_alloc(usb_transfer_type_t type)
|
|
|
break;
|
|
|
}
|
|
|
dma_buffer_block_t *buffer = calloc(1, sizeof(dma_buffer_block_t));
|
|
|
- void *xfer_desc_list = heap_caps_aligned_calloc(USBH_HAL_DMA_MEM_ALIGN, desc_list_len, sizeof(usbh_ll_dma_qtd_t), MALLOC_CAP_DMA);
|
|
|
+ void *xfer_desc_list = heap_caps_aligned_calloc(USB_DWC_HAL_DMA_MEM_ALIGN, desc_list_len, sizeof(usb_dwc_ll_dma_qtd_t), MALLOC_CAP_DMA);
|
|
|
if (buffer == NULL || xfer_desc_list == NULL) {
|
|
|
free(buffer);
|
|
|
heap_caps_free(xfer_desc_list);
|
|
|
@@ -1649,7 +1649,7 @@ static bool pipe_alloc_check_args(const hcd_pipe_config_t *pipe_config, usb_spee
|
|
|
return (pipe_config->ep_desc->wMaxPacketSize <= limit);
|
|
|
}
|
|
|
|
|
|
-static void pipe_set_ep_char(const hcd_pipe_config_t *pipe_config, usb_transfer_type_t type, bool is_default_pipe, int pipe_idx, usb_speed_t port_speed, usbh_hal_ep_char_t *ep_char)
|
|
|
+static void pipe_set_ep_char(const hcd_pipe_config_t *pipe_config, usb_transfer_type_t type, bool is_default_pipe, int pipe_idx, usb_speed_t port_speed, usb_dwc_hal_ep_char_t *ep_char)
|
|
|
{
|
|
|
//Initialize EP characteristics
|
|
|
usb_priv_xfer_type_t hal_xfer_type;
|
|
|
@@ -1722,7 +1722,7 @@ static esp_err_t _pipe_cmd_halt(pipe_t *pipe)
|
|
|
}
|
|
|
//If the pipe's port is invalid, we just mark the pipe as halted without needing to halt the underlying channel
|
|
|
if (pipe->port->flags.conn_dev_ena //Skip halting the underlying channel if the port is invalid
|
|
|
- && !usbh_hal_chan_request_halt(pipe->chan_obj)) { //Check if the channel is already halted
|
|
|
+ && !usb_dwc_hal_chan_request_halt(pipe->chan_obj)) { //Check if the channel is already halted
|
|
|
//Channel is not halted, we need to request and wait for a haltWe need to wait for channel to be halted.
|
|
|
pipe->cs_flags.waiting_halt = 1;
|
|
|
_internal_pipe_event_wait(pipe);
|
|
|
@@ -1730,7 +1730,7 @@ static esp_err_t _pipe_cmd_halt(pipe_t *pipe)
|
|
|
assert(pipe->state == HCD_PIPE_STATE_HALTED);
|
|
|
} else {
|
|
|
//We are already halted, just need to update the state
|
|
|
- usbh_hal_chan_mark_halted(pipe->chan_obj);
|
|
|
+ usb_dwc_hal_chan_mark_halted(pipe->chan_obj);
|
|
|
pipe->state = HCD_PIPE_STATE_HALTED;
|
|
|
}
|
|
|
ret = ESP_OK;
|
|
|
@@ -1842,7 +1842,7 @@ esp_err_t hcd_pipe_alloc(hcd_port_handle_t port_hdl, const hcd_pipe_config_t *pi
|
|
|
esp_err_t ret;
|
|
|
//Allocate the pipe resources
|
|
|
pipe_t *pipe = calloc(1, sizeof(pipe_t));
|
|
|
- usbh_hal_chan_t *chan_obj = calloc(1, sizeof(usbh_hal_chan_t));
|
|
|
+ usb_dwc_hal_chan_t *chan_obj = calloc(1, sizeof(usb_dwc_hal_chan_t));
|
|
|
dma_buffer_block_t *buffers[NUM_BUFFERS] = {0};
|
|
|
if (pipe == NULL|| chan_obj == NULL) {
|
|
|
ret = ESP_ERR_NO_MEM;
|
|
|
@@ -1865,9 +1865,9 @@ esp_err_t hcd_pipe_alloc(hcd_port_handle_t port_hdl, const hcd_pipe_config_t *pi
|
|
|
pipe->multi_buffer_control.buffer_num_to_fill = NUM_BUFFERS;
|
|
|
pipe->port = port;
|
|
|
pipe->chan_obj = chan_obj;
|
|
|
- usbh_hal_ep_char_t ep_char;
|
|
|
+ usb_dwc_hal_ep_char_t ep_char;
|
|
|
pipe_set_ep_char(pipe_config, type, is_default, pipe_idx, port_speed, &ep_char);
|
|
|
- memcpy(&pipe->ep_char, &ep_char, sizeof(usbh_hal_ep_char_t));
|
|
|
+ memcpy(&pipe->ep_char, &ep_char, sizeof(usb_dwc_hal_ep_char_t));
|
|
|
pipe->state = HCD_PIPE_STATE_ACTIVE;
|
|
|
pipe->callback = pipe_config->callback;
|
|
|
pipe->callback_arg = pipe_config->callback_arg;
|
|
|
@@ -1880,13 +1880,13 @@ esp_err_t hcd_pipe_alloc(hcd_port_handle_t port_hdl, const hcd_pipe_config_t *pi
|
|
|
ret = ESP_ERR_INVALID_STATE;
|
|
|
goto err;
|
|
|
}
|
|
|
- bool chan_allocated = usbh_hal_chan_alloc(port->hal, pipe->chan_obj, (void *) pipe);
|
|
|
+ bool chan_allocated = usb_dwc_hal_chan_alloc(port->hal, pipe->chan_obj, (void *) pipe);
|
|
|
if (!chan_allocated) {
|
|
|
HCD_EXIT_CRITICAL();
|
|
|
ret = ESP_ERR_NOT_SUPPORTED;
|
|
|
goto err;
|
|
|
}
|
|
|
- usbh_hal_chan_set_ep_char(port->hal, pipe->chan_obj, &pipe->ep_char);
|
|
|
+ usb_dwc_hal_chan_set_ep_char(port->hal, pipe->chan_obj, &pipe->ep_char);
|
|
|
//Add the pipe to the list of idle pipes in the port object
|
|
|
TAILQ_INSERT_TAIL(&port->pipes_idle_tailq, pipe, tailq_entry);
|
|
|
port->num_pipes_idle++;
|
|
|
@@ -1916,7 +1916,7 @@ esp_err_t hcd_pipe_free(hcd_pipe_handle_t pipe_hdl)
|
|
|
//Remove pipe from the list of idle pipes (it must be in the idle list because it should have no queued URBs)
|
|
|
TAILQ_REMOVE(&pipe->port->pipes_idle_tailq, pipe, tailq_entry);
|
|
|
pipe->port->num_pipes_idle--;
|
|
|
- usbh_hal_chan_free(pipe->port->hal, pipe->chan_obj);
|
|
|
+ usb_dwc_hal_chan_free(pipe->port->hal, pipe->chan_obj);
|
|
|
HCD_EXIT_CRITICAL();
|
|
|
|
|
|
//Free pipe resources
|
|
|
@@ -1939,7 +1939,7 @@ esp_err_t hcd_pipe_update_mps(hcd_pipe_handle_t pipe_hdl, int mps)
|
|
|
ESP_ERR_INVALID_STATE);
|
|
|
pipe->ep_char.mps = mps;
|
|
|
//Update the underlying channel's registers
|
|
|
- usbh_hal_chan_set_ep_char(pipe->port->hal, pipe->chan_obj, &pipe->ep_char);
|
|
|
+ usb_dwc_hal_chan_set_ep_char(pipe->port->hal, pipe->chan_obj, &pipe->ep_char);
|
|
|
HCD_EXIT_CRITICAL();
|
|
|
return ESP_OK;
|
|
|
}
|
|
|
@@ -1955,7 +1955,7 @@ esp_err_t hcd_pipe_update_dev_addr(hcd_pipe_handle_t pipe_hdl, uint8_t dev_addr)
|
|
|
ESP_ERR_INVALID_STATE);
|
|
|
pipe->ep_char.dev_addr = dev_addr;
|
|
|
//Update the underlying channel's registers
|
|
|
- usbh_hal_chan_set_ep_char(pipe->port->hal, pipe->chan_obj, &pipe->ep_char);
|
|
|
+ usb_dwc_hal_chan_set_ep_char(pipe->port->hal, pipe->chan_obj, &pipe->ep_char);
|
|
|
HCD_EXIT_CRITICAL();
|
|
|
return ESP_OK;
|
|
|
}
|
|
|
@@ -2060,20 +2060,20 @@ static inline void _buffer_fill_ctrl(dma_buffer_block_t *buffer, usb_transfer_t
|
|
|
bool data_stg_in = (setup_pkt->bmRequestType & USB_BM_REQUEST_TYPE_DIR_IN);
|
|
|
bool data_stg_skip = (setup_pkt->wLength == 0);
|
|
|
//Fill setup stage
|
|
|
- usbh_hal_xfer_desc_fill(buffer->xfer_desc_list, 0, transfer->data_buffer, sizeof(usb_setup_packet_t),
|
|
|
- USBH_HAL_XFER_DESC_FLAG_SETUP | USBH_HAL_XFER_DESC_FLAG_HOC);
|
|
|
+ usb_dwc_hal_xfer_desc_fill(buffer->xfer_desc_list, 0, transfer->data_buffer, sizeof(usb_setup_packet_t),
|
|
|
+ USB_DWC_HAL_XFER_DESC_FLAG_SETUP | USB_DWC_HAL_XFER_DESC_FLAG_HOC);
|
|
|
//Fill data stage
|
|
|
if (data_stg_skip) {
|
|
|
//Not data stage. Fill with an empty descriptor
|
|
|
- usbh_hal_xfer_desc_clear(buffer->xfer_desc_list, 1);
|
|
|
+ usb_dwc_hal_xfer_desc_clear(buffer->xfer_desc_list, 1);
|
|
|
} else {
|
|
|
//Fill data stage. Note that we still fill with transfer->num_bytes instead of setup_pkt->wLength as it's possible to require more bytes than wLength
|
|
|
- usbh_hal_xfer_desc_fill(buffer->xfer_desc_list, 1, transfer->data_buffer + sizeof(usb_setup_packet_t), transfer->num_bytes - sizeof(usb_setup_packet_t),
|
|
|
- ((data_stg_in) ? USBH_HAL_XFER_DESC_FLAG_IN : 0) | USBH_HAL_XFER_DESC_FLAG_HOC);
|
|
|
+ usb_dwc_hal_xfer_desc_fill(buffer->xfer_desc_list, 1, transfer->data_buffer + sizeof(usb_setup_packet_t), transfer->num_bytes - sizeof(usb_setup_packet_t),
|
|
|
+ ((data_stg_in) ? USB_DWC_HAL_XFER_DESC_FLAG_IN : 0) | USB_DWC_HAL_XFER_DESC_FLAG_HOC);
|
|
|
}
|
|
|
//Fill status stage (i.e., a zero length packet). If data stage is skipped, the status stage is always IN.
|
|
|
- usbh_hal_xfer_desc_fill(buffer->xfer_desc_list, 2, NULL, 0,
|
|
|
- ((data_stg_in && !data_stg_skip) ? 0 : USBH_HAL_XFER_DESC_FLAG_IN) | USBH_HAL_XFER_DESC_FLAG_HOC);
|
|
|
+ usb_dwc_hal_xfer_desc_fill(buffer->xfer_desc_list, 2, NULL, 0,
|
|
|
+ ((data_stg_in && !data_stg_skip) ? 0 : USB_DWC_HAL_XFER_DESC_FLAG_IN) | USB_DWC_HAL_XFER_DESC_FLAG_HOC);
|
|
|
//Update buffer flags
|
|
|
buffer->flags.ctrl.data_stg_in = data_stg_in;
|
|
|
buffer->flags.ctrl.data_stg_skip = data_stg_skip;
|
|
|
@@ -2086,16 +2086,16 @@ static inline void _buffer_fill_bulk(dma_buffer_block_t *buffer, usb_transfer_t
|
|
|
//Minor optimization: Do the mod operation last
|
|
|
bool zero_len_packet = !is_in && (transfer->flags & USB_TRANSFER_FLAG_ZERO_PACK) && (transfer->num_bytes % mps == 0);
|
|
|
if (is_in) {
|
|
|
- usbh_hal_xfer_desc_fill(buffer->xfer_desc_list, 0, transfer->data_buffer, transfer->num_bytes,
|
|
|
- USBH_HAL_XFER_DESC_FLAG_IN | USBH_HAL_XFER_DESC_FLAG_HOC);
|
|
|
+ usb_dwc_hal_xfer_desc_fill(buffer->xfer_desc_list, 0, transfer->data_buffer, transfer->num_bytes,
|
|
|
+ USB_DWC_HAL_XFER_DESC_FLAG_IN | USB_DWC_HAL_XFER_DESC_FLAG_HOC);
|
|
|
} else { //OUT
|
|
|
if (zero_len_packet) {
|
|
|
//Adding a zero length packet, so two descriptors are used.
|
|
|
- usbh_hal_xfer_desc_fill(buffer->xfer_desc_list, 0, transfer->data_buffer, transfer->num_bytes, 0);
|
|
|
- usbh_hal_xfer_desc_fill(buffer->xfer_desc_list, 1, NULL, 0, USBH_HAL_XFER_DESC_FLAG_HOC);
|
|
|
+ usb_dwc_hal_xfer_desc_fill(buffer->xfer_desc_list, 0, transfer->data_buffer, transfer->num_bytes, 0);
|
|
|
+ usb_dwc_hal_xfer_desc_fill(buffer->xfer_desc_list, 1, NULL, 0, USB_DWC_HAL_XFER_DESC_FLAG_HOC);
|
|
|
} else {
|
|
|
//Zero length packet not required. One descriptor is enough
|
|
|
- usbh_hal_xfer_desc_fill(buffer->xfer_desc_list, 0, transfer->data_buffer, transfer->num_bytes, USBH_HAL_XFER_DESC_FLAG_HOC);
|
|
|
+ usb_dwc_hal_xfer_desc_fill(buffer->xfer_desc_list, 0, transfer->data_buffer, transfer->num_bytes, USB_DWC_HAL_XFER_DESC_FLAG_HOC);
|
|
|
}
|
|
|
}
|
|
|
//Update buffer flags
|
|
|
@@ -2119,24 +2119,24 @@ static inline void _buffer_fill_intr(dma_buffer_block_t *buffer, usb_transfer_t
|
|
|
}
|
|
|
assert((zero_len_packet) ? num_qtds + 1 : num_qtds <= XFER_LIST_LEN_INTR); //Check that the number of QTDs doesn't exceed the QTD list's length
|
|
|
|
|
|
- uint32_t xfer_desc_flags = (is_in) ? USBH_HAL_XFER_DESC_FLAG_IN : 0;
|
|
|
+ uint32_t xfer_desc_flags = (is_in) ? USB_DWC_HAL_XFER_DESC_FLAG_IN : 0;
|
|
|
int bytes_filled = 0;
|
|
|
//Fill all but last QTD
|
|
|
for (int i = 0; i < num_qtds - 1; i++) {
|
|
|
- usbh_hal_xfer_desc_fill(buffer->xfer_desc_list, i, &transfer->data_buffer[bytes_filled], mps, xfer_desc_flags);
|
|
|
+ usb_dwc_hal_xfer_desc_fill(buffer->xfer_desc_list, i, &transfer->data_buffer[bytes_filled], mps, xfer_desc_flags);
|
|
|
bytes_filled += mps;
|
|
|
}
|
|
|
//Fill last QTD and zero length packet
|
|
|
if (zero_len_packet) {
|
|
|
//Fill in last data packet without HOC flag
|
|
|
- usbh_hal_xfer_desc_fill(buffer->xfer_desc_list, num_qtds - 1, &transfer->data_buffer[bytes_filled], transfer->num_bytes - bytes_filled,
|
|
|
+ usb_dwc_hal_xfer_desc_fill(buffer->xfer_desc_list, num_qtds - 1, &transfer->data_buffer[bytes_filled], transfer->num_bytes - bytes_filled,
|
|
|
xfer_desc_flags);
|
|
|
//HOC flag goes to zero length packet instead
|
|
|
- usbh_hal_xfer_desc_fill(buffer->xfer_desc_list, num_qtds, NULL, 0, USBH_HAL_XFER_DESC_FLAG_HOC);
|
|
|
+ usb_dwc_hal_xfer_desc_fill(buffer->xfer_desc_list, num_qtds, NULL, 0, USB_DWC_HAL_XFER_DESC_FLAG_HOC);
|
|
|
} else {
|
|
|
//Zero length packet not required. Fill in last QTD with HOC flag
|
|
|
- usbh_hal_xfer_desc_fill(buffer->xfer_desc_list, num_qtds - 1, &transfer->data_buffer[bytes_filled], transfer->num_bytes - bytes_filled,
|
|
|
- xfer_desc_flags | USBH_HAL_XFER_DESC_FLAG_HOC);
|
|
|
+ usb_dwc_hal_xfer_desc_fill(buffer->xfer_desc_list, num_qtds - 1, &transfer->data_buffer[bytes_filled], transfer->num_bytes - bytes_filled,
|
|
|
+ xfer_desc_flags | USB_DWC_HAL_XFER_DESC_FLAG_HOC);
|
|
|
}
|
|
|
|
|
|
//Update buffer members and flags
|
|
|
@@ -2154,19 +2154,19 @@ static inline void _buffer_fill_isoc(dma_buffer_block_t *buffer, usb_transfer_t
|
|
|
//For each packet, fill in a descriptor and a interval-1 blank descriptor after it
|
|
|
for (int pkt_idx = 0; pkt_idx < transfer->num_isoc_packets; pkt_idx++) {
|
|
|
int xfer_len = transfer->isoc_packet_desc[pkt_idx].num_bytes;
|
|
|
- uint32_t flags = (is_in) ? USBH_HAL_XFER_DESC_FLAG_IN : 0;
|
|
|
+ uint32_t flags = (is_in) ? USB_DWC_HAL_XFER_DESC_FLAG_IN : 0;
|
|
|
if (pkt_idx == transfer->num_isoc_packets - 1) {
|
|
|
//Last packet, set the the HOC flag
|
|
|
- flags |= USBH_HAL_XFER_DESC_FLAG_HOC;
|
|
|
+ flags |= USB_DWC_HAL_XFER_DESC_FLAG_HOC;
|
|
|
}
|
|
|
- usbh_hal_xfer_desc_fill(buffer->xfer_desc_list, desc_idx, &transfer->data_buffer[bytes_filled], xfer_len, flags);
|
|
|
+ usb_dwc_hal_xfer_desc_fill(buffer->xfer_desc_list, desc_idx, &transfer->data_buffer[bytes_filled], xfer_len, flags);
|
|
|
bytes_filled += xfer_len;
|
|
|
if (++desc_idx >= XFER_LIST_LEN_ISOC) {
|
|
|
desc_idx = 0;
|
|
|
}
|
|
|
//Clear descriptors for unscheduled frames
|
|
|
for (int i = 0; i < interval - 1; i++) {
|
|
|
- usbh_hal_xfer_desc_clear(buffer->xfer_desc_list, desc_idx);
|
|
|
+ usb_dwc_hal_xfer_desc_clear(buffer->xfer_desc_list, desc_idx);
|
|
|
if (++desc_idx >= XFER_LIST_LEN_ISOC) {
|
|
|
desc_idx = 0;
|
|
|
}
|
|
|
@@ -2204,7 +2204,7 @@ static void _buffer_fill(pipe_t *pipe)
|
|
|
uint32_t start_idx;
|
|
|
if (pipe->multi_buffer_control.buffer_num_to_exec == 0) {
|
|
|
//There are no more previously filled buffers to execute. We need to calculate a new start index based on HFNUM and the pipe's schedule
|
|
|
- uint32_t cur_frame_num = usbh_hal_port_get_cur_frame_num(pipe->port->hal);
|
|
|
+ uint32_t cur_frame_num = usb_dwc_hal_port_get_cur_frame_num(pipe->port->hal);
|
|
|
uint32_t cur_mod_idx_no_offset = (cur_frame_num - pipe->ep_char.periodic.phase_offset_frames) & (XFER_LIST_LEN_ISOC - 1); //Get the modulated index (i.e., the Nth desc in the descriptor list)
|
|
|
//This is the non-offset modulated QTD index of the last scheduled interval
|
|
|
uint32_t last_interval_mod_idx_no_offset = (cur_mod_idx_no_offset / pipe->ep_char.periodic.interval) * pipe->ep_char.periodic.interval; //Floor divide and the multiply again
|
|
|
@@ -2260,8 +2260,8 @@ static void _buffer_exec(pipe_t *pipe)
|
|
|
start_idx = 0;
|
|
|
desc_list_len = XFER_LIST_LEN_CTRL;
|
|
|
//Set the channel's direction to OUT and PID to 0 respectively for the the setup stage
|
|
|
- usbh_hal_chan_set_dir(pipe->chan_obj, false); //Setup stage is always OUT
|
|
|
- usbh_hal_chan_set_pid(pipe->chan_obj, 0); //Setup stage always has a PID of DATA0
|
|
|
+ usb_dwc_hal_chan_set_dir(pipe->chan_obj, false); //Setup stage is always OUT
|
|
|
+ usb_dwc_hal_chan_set_pid(pipe->chan_obj, 0); //Setup stage always has a PID of DATA0
|
|
|
break;
|
|
|
}
|
|
|
case USB_PRIV_XFER_TYPE_ISOCHRONOUS: {
|
|
|
@@ -2289,7 +2289,7 @@ static void _buffer_exec(pipe_t *pipe)
|
|
|
//Update buffer and multi buffer flags
|
|
|
buffer_to_exec->status_flags.executing = 1;
|
|
|
pipe->multi_buffer_control.buffer_is_executing = 1;
|
|
|
- usbh_hal_chan_activate(pipe->chan_obj, buffer_to_exec->xfer_desc_list, desc_list_len, start_idx);
|
|
|
+ usb_dwc_hal_chan_activate(pipe->chan_obj, buffer_to_exec->xfer_desc_list, desc_list_len, start_idx);
|
|
|
}
|
|
|
|
|
|
static void _buffer_exec_cont(pipe_t *pipe)
|
|
|
@@ -2318,9 +2318,9 @@ static void _buffer_exec_cont(pipe_t *pipe)
|
|
|
buffer_inflight->flags.ctrl.cur_stg = 2;
|
|
|
}
|
|
|
//Continue the control transfer
|
|
|
- usbh_hal_chan_set_dir(pipe->chan_obj, next_dir_is_in);
|
|
|
- usbh_hal_chan_set_pid(pipe->chan_obj, next_pid);
|
|
|
- usbh_hal_chan_activate(pipe->chan_obj, buffer_inflight->xfer_desc_list, XFER_LIST_LEN_CTRL, buffer_inflight->flags.ctrl.cur_stg);
|
|
|
+ usb_dwc_hal_chan_set_dir(pipe->chan_obj, next_dir_is_in);
|
|
|
+ usb_dwc_hal_chan_set_pid(pipe->chan_obj, next_pid);
|
|
|
+ usb_dwc_hal_chan_activate(pipe->chan_obj, buffer_inflight->xfer_desc_list, XFER_LIST_LEN_CTRL, buffer_inflight->flags.ctrl.cur_stg);
|
|
|
}
|
|
|
|
|
|
static inline void _buffer_parse_ctrl(dma_buffer_block_t *buffer)
|
|
|
@@ -2334,15 +2334,15 @@ static inline void _buffer_parse_ctrl(dma_buffer_block_t *buffer)
|
|
|
//Parse the data stage for the remaining length
|
|
|
int rem_len;
|
|
|
int desc_status;
|
|
|
- usbh_hal_xfer_desc_parse(buffer->xfer_desc_list, 1, &rem_len, &desc_status);
|
|
|
- assert(desc_status == USBH_HAL_XFER_DESC_STS_SUCCESS);
|
|
|
+ usb_dwc_hal_xfer_desc_parse(buffer->xfer_desc_list, 1, &rem_len, &desc_status);
|
|
|
+ assert(desc_status == USB_DWC_HAL_XFER_DESC_STS_SUCCESS);
|
|
|
assert(rem_len <= (transfer->num_bytes - sizeof(usb_setup_packet_t)));
|
|
|
transfer->actual_num_bytes = transfer->num_bytes - rem_len;
|
|
|
}
|
|
|
//Update URB status
|
|
|
transfer->status = USB_TRANSFER_STATUS_COMPLETED;
|
|
|
//Clear the descriptor list
|
|
|
- memset(buffer->xfer_desc_list, 0, XFER_LIST_LEN_CTRL * sizeof(usbh_ll_dma_qtd_t));
|
|
|
+ memset(buffer->xfer_desc_list, 0, XFER_LIST_LEN_CTRL * sizeof(usb_dwc_ll_dma_qtd_t));
|
|
|
}
|
|
|
|
|
|
static inline void _buffer_parse_bulk(dma_buffer_block_t *buffer)
|
|
|
@@ -2351,14 +2351,14 @@ static inline void _buffer_parse_bulk(dma_buffer_block_t *buffer)
|
|
|
//Update URB's actual number of bytes
|
|
|
int rem_len;
|
|
|
int desc_status;
|
|
|
- usbh_hal_xfer_desc_parse(buffer->xfer_desc_list, 0, &rem_len, &desc_status);
|
|
|
- assert(desc_status == USBH_HAL_XFER_DESC_STS_SUCCESS);
|
|
|
+ usb_dwc_hal_xfer_desc_parse(buffer->xfer_desc_list, 0, &rem_len, &desc_status);
|
|
|
+ assert(desc_status == USB_DWC_HAL_XFER_DESC_STS_SUCCESS);
|
|
|
assert(rem_len <= transfer->num_bytes);
|
|
|
transfer->actual_num_bytes = transfer->num_bytes - rem_len;
|
|
|
//Update URB's status
|
|
|
transfer->status = USB_TRANSFER_STATUS_COMPLETED;
|
|
|
//Clear the descriptor list
|
|
|
- memset(buffer->xfer_desc_list, 0, XFER_LIST_LEN_BULK * sizeof(usbh_ll_dma_qtd_t));
|
|
|
+ memset(buffer->xfer_desc_list, 0, XFER_LIST_LEN_BULK * sizeof(usb_dwc_ll_dma_qtd_t));
|
|
|
}
|
|
|
|
|
|
static inline void _buffer_parse_intr(dma_buffer_block_t *buffer, bool is_in, int mps)
|
|
|
@@ -2371,12 +2371,12 @@ static inline void _buffer_parse_intr(dma_buffer_block_t *buffer, bool is_in, in
|
|
|
int rem_len;
|
|
|
int desc_status;
|
|
|
for (int i = 0; i < intr_stop_idx - 1; i++) { //Check all packets before the short
|
|
|
- usbh_hal_xfer_desc_parse(buffer->xfer_desc_list, i, &rem_len, &desc_status);
|
|
|
- assert(rem_len == 0 && desc_status == USBH_HAL_XFER_DESC_STS_SUCCESS);
|
|
|
+ usb_dwc_hal_xfer_desc_parse(buffer->xfer_desc_list, i, &rem_len, &desc_status);
|
|
|
+ assert(rem_len == 0 && desc_status == USB_DWC_HAL_XFER_DESC_STS_SUCCESS);
|
|
|
}
|
|
|
//Check the short packet
|
|
|
- usbh_hal_xfer_desc_parse(buffer->xfer_desc_list, intr_stop_idx - 1, &rem_len, &desc_status);
|
|
|
- assert(rem_len > 0 && desc_status == USBH_HAL_XFER_DESC_STS_SUCCESS);
|
|
|
+ usb_dwc_hal_xfer_desc_parse(buffer->xfer_desc_list, intr_stop_idx - 1, &rem_len, &desc_status);
|
|
|
+ assert(rem_len > 0 && desc_status == USB_DWC_HAL_XFER_DESC_STS_SUCCESS);
|
|
|
//Update actual bytes
|
|
|
transfer->actual_num_bytes = (mps * intr_stop_idx - 2) + (mps - rem_len);
|
|
|
} else {
|
|
|
@@ -2384,14 +2384,14 @@ static inline void _buffer_parse_intr(dma_buffer_block_t *buffer, bool is_in, in
|
|
|
for (int i = 0; i < buffer->flags.intr.num_qtds - 1; i++) {
|
|
|
int rem_len;
|
|
|
int desc_status;
|
|
|
- usbh_hal_xfer_desc_parse(buffer->xfer_desc_list, i, &rem_len, &desc_status);
|
|
|
- assert(rem_len == 0 && desc_status == USBH_HAL_XFER_DESC_STS_SUCCESS);
|
|
|
+ usb_dwc_hal_xfer_desc_parse(buffer->xfer_desc_list, i, &rem_len, &desc_status);
|
|
|
+ assert(rem_len == 0 && desc_status == USB_DWC_HAL_XFER_DESC_STS_SUCCESS);
|
|
|
}
|
|
|
//Check the last packet
|
|
|
int last_packet_rem_len;
|
|
|
int last_packet_desc_status;
|
|
|
- usbh_hal_xfer_desc_parse(buffer->xfer_desc_list, buffer->flags.intr.num_qtds - 1, &last_packet_rem_len, &last_packet_desc_status);
|
|
|
- assert(last_packet_desc_status == USBH_HAL_XFER_DESC_STS_SUCCESS);
|
|
|
+ usb_dwc_hal_xfer_desc_parse(buffer->xfer_desc_list, buffer->flags.intr.num_qtds - 1, &last_packet_rem_len, &last_packet_desc_status);
|
|
|
+ assert(last_packet_desc_status == USB_DWC_HAL_XFER_DESC_STS_SUCCESS);
|
|
|
//All packets except last MUST be MPS. So just deduct the remaining length of the last packet to get actual number of bytes
|
|
|
transfer->actual_num_bytes = transfer->num_bytes - last_packet_rem_len;
|
|
|
}
|
|
|
@@ -2400,15 +2400,15 @@ static inline void _buffer_parse_intr(dma_buffer_block_t *buffer, bool is_in, in
|
|
|
for (int i = 0 ; i < buffer->flags.intr.num_qtds; i++) {
|
|
|
int rem_len;
|
|
|
int desc_status;
|
|
|
- usbh_hal_xfer_desc_parse(buffer->xfer_desc_list, i, &rem_len, &desc_status);
|
|
|
- assert(rem_len == 0 && desc_status == USBH_HAL_XFER_DESC_STS_SUCCESS);
|
|
|
+ usb_dwc_hal_xfer_desc_parse(buffer->xfer_desc_list, i, &rem_len, &desc_status);
|
|
|
+ assert(rem_len == 0 && desc_status == USB_DWC_HAL_XFER_DESC_STS_SUCCESS);
|
|
|
}
|
|
|
transfer->actual_num_bytes = transfer->num_bytes;
|
|
|
}
|
|
|
//Update URB's status
|
|
|
transfer->status = USB_TRANSFER_STATUS_COMPLETED;
|
|
|
//Clear the descriptor list
|
|
|
- memset(buffer->xfer_desc_list, 0, XFER_LIST_LEN_INTR * sizeof(usbh_ll_dma_qtd_t));
|
|
|
+ memset(buffer->xfer_desc_list, 0, XFER_LIST_LEN_INTR * sizeof(usb_dwc_ll_dma_qtd_t));
|
|
|
}
|
|
|
|
|
|
static inline void _buffer_parse_isoc(dma_buffer_block_t *buffer, bool is_in)
|
|
|
@@ -2420,15 +2420,15 @@ static inline void _buffer_parse_isoc(dma_buffer_block_t *buffer, bool is_in)
|
|
|
//Clear the filled descriptor
|
|
|
int rem_len;
|
|
|
int desc_status;
|
|
|
- usbh_hal_xfer_desc_parse(buffer->xfer_desc_list, desc_idx, &rem_len, &desc_status);
|
|
|
- usbh_hal_xfer_desc_clear(buffer->xfer_desc_list, desc_idx);
|
|
|
+ usb_dwc_hal_xfer_desc_parse(buffer->xfer_desc_list, desc_idx, &rem_len, &desc_status);
|
|
|
+ usb_dwc_hal_xfer_desc_clear(buffer->xfer_desc_list, desc_idx);
|
|
|
assert(rem_len == 0 || is_in);
|
|
|
- assert(desc_status == USBH_HAL_XFER_DESC_STS_SUCCESS || USBH_HAL_XFER_DESC_STS_NOT_EXECUTED);
|
|
|
+ assert(desc_status == USB_DWC_HAL_XFER_DESC_STS_SUCCESS || USB_DWC_HAL_XFER_DESC_STS_NOT_EXECUTED);
|
|
|
assert(rem_len <= transfer->isoc_packet_desc[pkt_idx].num_bytes); //Check for DMA errata
|
|
|
//Update ISO packet actual length and status
|
|
|
transfer->isoc_packet_desc[pkt_idx].actual_num_bytes = transfer->isoc_packet_desc[pkt_idx].num_bytes - rem_len;
|
|
|
total_actual_num_bytes += transfer->isoc_packet_desc[pkt_idx].actual_num_bytes;
|
|
|
- transfer->isoc_packet_desc[pkt_idx].status = (desc_status == USBH_HAL_XFER_DESC_STS_NOT_EXECUTED) ? USB_TRANSFER_STATUS_SKIPPED : USB_TRANSFER_STATUS_COMPLETED;
|
|
|
+ transfer->isoc_packet_desc[pkt_idx].status = (desc_status == USB_DWC_HAL_XFER_DESC_STS_NOT_EXECUTED) ? USB_TRANSFER_STATUS_SKIPPED : USB_TRANSFER_STATUS_COMPLETED;
|
|
|
//A descriptor is also allocated for unscheduled frames. We need to skip over them
|
|
|
desc_idx += buffer->flags.isoc.interval;
|
|
|
if (desc_idx >= XFER_LIST_LEN_INTR) {
|