summaryrefslogtreecommitdiffstats
path: root/tinyusb/src/portable
diff options
context:
space:
mode:
authorWillian Paixao <willian@ufpa.br>2021-12-05 19:16:34 +0100
committerWillian Paixao <willian@ufpa.br>2021-12-05 19:16:34 +0100
commitac2e205ae9f465c27297ea542c72e8cfe4966f8c (patch)
tree16e4d1268b2631ba7e17dcda8f366f070fbd7475 /tinyusb/src/portable
parentbbd394a19aaa334a179c36cf2ed2a066f1bb312c (diff)
downloadSensor-Watch-ac2e205ae9f465c27297ea542c72e8cfe4966f8c.tar.gz
Sensor-Watch-ac2e205ae9f465c27297ea542c72e8cfe4966f8c.tar.bz2
Sensor-Watch-ac2e205ae9f465c27297ea542c72e8cfe4966f8c.zip
remove tinyusb directory
Diffstat (limited to 'tinyusb/src/portable')
-rwxr-xr-xtinyusb/src/portable/dialog/da146xx/dcd_da146xx.c1067
-rwxr-xr-xtinyusb/src/portable/ehci/ehci.c893
-rwxr-xr-xtinyusb/src/portable/ehci/ehci.h420
-rwxr-xr-xtinyusb/src/portable/ehci/ehci_api.h45
-rwxr-xr-xtinyusb/src/portable/espressif/esp32sx/dcd_esp32sx.c867
-rwxr-xr-xtinyusb/src/portable/microchip/samd/dcd_samd.c411
-rwxr-xr-xtinyusb/src/portable/microchip/samg/dcd_samg.c486
-rwxr-xr-xtinyusb/src/portable/microchip/samx7x/common_usb_regs.h2108
-rwxr-xr-xtinyusb/src/portable/microchip/samx7x/dcd_samx7x.c762
-rwxr-xr-xtinyusb/src/portable/mindmotion/mm32/dcd_mm32f327x_otg.c471
-rwxr-xr-xtinyusb/src/portable/nordic/nrf5x/dcd_nrf5x.c1050
-rwxr-xr-xtinyusb/src/portable/nuvoton/nuc120/dcd_nuc120.c494
-rwxr-xr-xtinyusb/src/portable/nuvoton/nuc121/dcd_nuc121.c534
-rwxr-xr-xtinyusb/src/portable/nuvoton/nuc505/dcd_nuc505.c712
-rwxr-xr-xtinyusb/src/portable/nxp/khci/dcd_khci.c479
-rwxr-xr-xtinyusb/src/portable/nxp/lpc17_40/dcd_lpc17_40.c582
-rwxr-xr-xtinyusb/src/portable/nxp/lpc17_40/dcd_lpc17_40.h152
-rwxr-xr-xtinyusb/src/portable/nxp/lpc17_40/hcd_lpc17_40.c47
-rwxr-xr-xtinyusb/src/portable/nxp/lpc_ip3511/dcd_lpc_ip3511.c537
-rwxr-xr-xtinyusb/src/portable/nxp/transdimension/common_transdimension.h136
-rwxr-xr-xtinyusb/src/portable/nxp/transdimension/dcd_transdimension.c492
-rwxr-xr-xtinyusb/src/portable/nxp/transdimension/hcd_transdimension.c117
-rwxr-xr-xtinyusb/src/portable/ohci/ohci.c657
-rwxr-xr-xtinyusb/src/portable/ohci/ohci.h275
-rwxr-xr-xtinyusb/src/portable/raspberrypi/rp2040/dcd_rp2040.c485
-rwxr-xr-xtinyusb/src/portable/raspberrypi/rp2040/hcd_rp2040.c564
-rwxr-xr-xtinyusb/src/portable/raspberrypi/rp2040/rp2040_usb.c326
-rwxr-xr-xtinyusb/src/portable/raspberrypi/rp2040/rp2040_usb.h147
-rwxr-xr-xtinyusb/src/portable/renesas/usba/dcd_usba.c891
-rwxr-xr-xtinyusb/src/portable/silabs/efm32/dcd_efm32.c931
-rwxr-xr-xtinyusb/src/portable/sony/cxd56/dcd_cxd56.c408
-rwxr-xr-xtinyusb/src/portable/st/stm32_fsdev/dcd_stm32_fsdev.c1129
-rwxr-xr-xtinyusb/src/portable/st/stm32_fsdev/dcd_stm32_fsdev_pvt_st.h411
-rwxr-xr-xtinyusb/src/portable/st/synopsys/dcd_synopsys.c1186
-rwxr-xr-xtinyusb/src/portable/st/synopsys/synopsys_common.h1465
-rwxr-xr-xtinyusb/src/portable/template/dcd_template.c131
-rwxr-xr-xtinyusb/src/portable/ti/msp430x5xx/dcd_msp430x5xx.c694
-rwxr-xr-xtinyusb/src/portable/valentyusb/eptri/dcd_eptri.c643
-rwxr-xr-xtinyusb/src/portable/valentyusb/eptri/dcd_eptri.h39
39 files changed, 0 insertions, 23244 deletions
diff --git a/tinyusb/src/portable/dialog/da146xx/dcd_da146xx.c b/tinyusb/src/portable/dialog/da146xx/dcd_da146xx.c
deleted file mode 100755
index 5fcf3bc5..00000000
--- a/tinyusb/src/portable/dialog/da146xx/dcd_da146xx.c
+++ /dev/null
@@ -1,1067 +0,0 @@
-/*
- * The MIT License (MIT)
- *
- * Copyright (c) 2020 Jerzy Kasenberg
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- *
- * This file is part of the TinyUSB stack.
- */
-
-#include "tusb_option.h"
-
-#if TUSB_OPT_DEVICE_ENABLED && CFG_TUSB_MCU == OPT_MCU_DA1469X
-
-#include "mcu/mcu.h"
-
-#include "device/dcd.h"
-
-/*------------------------------------------------------------------*/
-/* MACRO TYPEDEF CONSTANT ENUM
- *------------------------------------------------------------------*/
-
-// Since TinyUSB doesn't use SOF for now, and this interrupt too often (1ms interval)
-// We disable SOF for now until needed later on
-#define USE_SOF 0
-
-// Size of RX or TX FIFO.
-#define FIFO_SIZE 64
-
-#ifndef TU_DA1469X_FIFO_READ_THRESHOLD
-// RX FIFO is 64 bytes. When endpoint size is greater then 64, FIFO warning interrupt
-// is enabled to allow read incoming data during frame reception.
-// It is possible to stay in interrupt reading whole packet at once, but it may be
-// more efficient for MCU to read as much data as possible and when FIFO is hardly
-// filled exit interrupt handler waiting for next FIFO warning level interrupt
-// or packet end.
-// When running at 96MHz code that reads FIFO based on number of bytes stored in
-// USB_RXSx_REG.USB_RXCOUNT takes enough time to fill FIFO with two additional bytes.
-// Settings this threshold above this allows to leave interrupt handler and wait
-// for more bytes to before next ISR. This allows reduce overall ISR time to 1/3
-// of time that would be needed if ISR read as fast as possible.
-#define TU_DA1469X_FIFO_READ_THRESHOLD 4
-#endif
-
-#define EP_MAX 4
-
-#define NFSR_NODE_RESET 0
-#define NFSR_NODE_RESUME 1
-#define NFSR_NODE_OPERATIONAL 2
-#define NFSR_NODE_SUSPEND 3
-
-static TU_ATTR_ALIGNED(4) uint8_t _setup_packet[8];
-
-typedef struct
-{
- union
- {
- __IOM uint32_t epc_in;
- __IOM uint32_t USB_EPC0_REG; /*!< (@ 0x00000080) Endpoint Control 0 Register */
- __IOM uint32_t USB_EPC1_REG; /*!< (@ 0x000000A0) Endpoint Control Register 1 */
- __IOM uint32_t USB_EPC3_REG; /*!< (@ 0x000000C0) Endpoint Control Register 3 */
- __IOM uint32_t USB_EPC5_REG; /*!< (@ 0x000000E0) Endpoint Control Register 5 */
- };
- union
- {
- __IOM uint32_t txd;
- __IOM uint32_t USB_TXD0_REG; /*!< (@ 0x00000084) Transmit Data 0 Register */
- __IOM uint32_t USB_TXD1_REG; /*!< (@ 0x000000A4) Transmit Data Register 1 */
- __IOM uint32_t USB_TXD2_REG; /*!< (@ 0x000000C4) Transmit Data Register 2 */
- __IOM uint32_t USB_TXD3_REG; /*!< (@ 0x000000E4) Transmit Data Register 3 */
- };
- union
- {
- __IOM uint32_t txs;
- __IOM uint32_t USB_TXS0_REG; /*!< (@ 0x00000088) Transmit Status 0 Register */
- __IOM uint32_t USB_TXS1_REG; /*!< (@ 0x000000A8) Transmit Status Register 1 */
- __IOM uint32_t USB_TXS2_REG; /*!< (@ 0x000000C8) Transmit Status Register 2 */
- __IOM uint32_t USB_TXS3_REG; /*!< (@ 0x000000E8) Transmit Status Register 3 */
- };
- union
- {
- __IOM uint32_t txc;
- __IOM uint32_t USB_TXC0_REG; /*!< (@ 0x0000008C) Transmit command 0 Register */
- __IOM uint32_t USB_TXC1_REG; /*!< (@ 0x000000AC) Transmit Command Register 1 */
- __IOM uint32_t USB_TXC2_REG; /*!< (@ 0x000000CC) Transmit Command Register 2 */
- __IOM uint32_t USB_TXC3_REG; /*!< (@ 0x000000EC) Transmit Command Register 3 */
- };
- union
- {
- __IOM uint32_t epc_out;
- __IOM uint32_t USB_EP0_NAK_REG; /*!< (@ 0x00000090) EP0 INNAK and OUTNAK Register */
- __IOM uint32_t USB_EPC2_REG; /*!< (@ 0x000000B0) Endpoint Control Register 2 */
- __IOM uint32_t USB_EPC4_REG; /*!< (@ 0x000000D0) Endpoint Control Register 4 */
- __IOM uint32_t USB_EPC6_REG; /*!< (@ 0x000000F0) Endpoint Control Register 6 */
- };
- union
- {
- __IOM uint32_t rxd;
- __IOM uint32_t USB_RXD0_REG; /*!< (@ 0x00000094) Receive Data 0 Register */
- __IOM uint32_t USB_RXD1_REG; /*!< (@ 0x000000B4) Receive Data Register,1 */
- __IOM uint32_t USB_RXD2_REG; /*!< (@ 0x000000D4) Receive Data Register 2 */
- __IOM uint32_t USB_RXD3_REG; /*!< (@ 0x000000F4) Receive Data Register 3 */
- };
- union
- {
- __IOM uint32_t rxs;
- __IOM uint32_t USB_RXS0_REG; /*!< (@ 0x00000098) Receive Status 0 Register */
- __IOM uint32_t USB_RXS1_REG; /*!< (@ 0x000000B8) Receive Status Register 1 */
- __IOM uint32_t USB_RXS2_REG; /*!< (@ 0x000000D8) Receive Status Register 2 */
- __IOM uint32_t USB_RXS3_REG; /*!< (@ 0x000000F8) Receive Status Register 3 */
- };
- union
- {
- __IOM uint32_t rxc;
- __IOM uint32_t USB_RXC0_REG; /*!< (@ 0x0000009C) Receive Command 0 Register */
- __IOM uint32_t USB_RXC1_REG; /*!< (@ 0x000000BC) Receive Command Register 1 */
- __IOM uint32_t USB_RXC2_REG; /*!< (@ 0x000000DC) Receive Command Register 2 */
- __IOM uint32_t USB_RXC3_REG; /*!< (@ 0x000000FC) Receive Command Register 3 */
- };
-} EPx_REGS;
-
-#define EP_REGS(first_ep_reg) (EPx_REGS*)(&USB->first_ep_reg)
-
-// DMA channel pair to use, channel 6 will be used for RX channel 7 for TX direction.
-#ifndef TU_DA146XX_DMA_RX_CHANNEL
-#define TU_DA146XX_DMA_RX_CHANNEL 6
-#endif
-#define DA146XX_DMA_USB_MUX (0x6 << (TU_DA146XX_DMA_RX_CHANNEL * 2))
-#define DA146XX_DMA_USB_MUX_MASK (0xF << (TU_DA146XX_DMA_RX_CHANNEL * 2))
-
-typedef struct
-{
- __IOM uint32_t DMAx_A_START_REG;
- __IOM uint32_t DMAx_B_START_REG;
- __IOM uint32_t DMAx_INT_REG;
- __IOM uint32_t DMAx_LEN_REG;
- __IOM uint32_t DMAx_CTRL_REG;
- __IOM uint32_t DMAx_IDX_REG;
- __IM uint32_t RESERVED[2]; // Extend structure size for array like usage, registers for each channel are 0x20 bytes apart.
-} da146xx_dma_channel_t;
-
-#define DMA_CHANNEL_REGS(n) ((da146xx_dma_channel_t *)(DMA) + n)
-#define RX_DMA_REGS DMA_CHANNEL_REGS(TU_DA146XX_DMA_RX_CHANNEL)
-#define TX_DMA_REGS DMA_CHANNEL_REGS((TU_DA146XX_DMA_RX_CHANNEL) + 1)
-
-#define RX_DMA_START ((1 << DMA_DMA0_CTRL_REG_DMA_ON_Pos) |\
- (0 << DMA_DMA0_CTRL_REG_BW_Pos) | \
- (1 << DMA_DMA0_CTRL_REG_DREQ_MODE_Pos) | \
- (1 << DMA_DMA0_CTRL_REG_BINC_Pos) | \
- (0 << DMA_DMA0_CTRL_REG_AINC_Pos) | \
- (0 << DMA_DMA0_CTRL_REG_CIRCULAR_Pos) | \
- (2 << DMA_DMA0_CTRL_REG_DMA_PRIO_Pos) | \
- (0 << DMA_DMA0_CTRL_REG_DMA_IDLE_Pos) | \
- (0 << DMA_DMA0_CTRL_REG_DMA_INIT_Pos) | \
- (0 << DMA_DMA0_CTRL_REG_REQ_SENSE_Pos) | \
- (0 << DMA_DMA0_CTRL_REG_BURST_MODE_Pos) | \
- (0 << DMA_DMA0_CTRL_REG_BUS_ERROR_DETECT_Pos))
-
-#define TX_DMA_START ((1 << DMA_DMA0_CTRL_REG_DMA_ON_Pos) |\
- (0 << DMA_DMA0_CTRL_REG_BW_Pos) | \
- (1 << DMA_DMA0_CTRL_REG_DREQ_MODE_Pos) | \
- (0 << DMA_DMA0_CTRL_REG_BINC_Pos) | \
- (1 << DMA_DMA0_CTRL_REG_AINC_Pos) | \
- (0 << DMA_DMA0_CTRL_REG_CIRCULAR_Pos) | \
- (2 << DMA_DMA0_CTRL_REG_DMA_PRIO_Pos) | \
- (0 << DMA_DMA0_CTRL_REG_DMA_IDLE_Pos) | \
- (0 << DMA_DMA0_CTRL_REG_DMA_INIT_Pos) | \
- (1 << DMA_DMA0_CTRL_REG_REQ_SENSE_Pos) | \
- (0 << DMA_DMA0_CTRL_REG_BURST_MODE_Pos) | \
- (0 << DMA_DMA0_CTRL_REG_BUS_ERROR_DETECT_Pos))
-
-// Dialog register fields and bit mask are very long. Filed masks repeat register names.
-// Those convenience macros are a way to reduce complexity of register modification lines.
-#define GET_BIT(val, field) (val & field ## _Msk) >> field ## _Pos
-#define REG_GET_BIT(reg, field) (USB->reg & USB_ ## reg ## _ ## field ## _Msk)
-#define REG_SET_BIT(reg, field) USB->reg |= USB_ ## reg ## _ ## field ## _Msk
-#define REG_CLR_BIT(reg, field) USB->reg &= ~USB_ ## reg ## _ ## field ## _Msk
-#define REG_SET_VAL(reg, field, val) USB->reg = (USB->reg & ~USB_ ## reg ## _ ## field ## _Msk) | (val << USB_ ## reg ## _ ## field ## _Pos)
-
-typedef struct {
- EPx_REGS * regs;
- uint8_t * buffer;
- // Total length of current transfer
- uint16_t total_len;
- // Bytes transferred so far
- uint16_t transferred;
- uint16_t max_packet_size;
- // Packet size sent or received so far. It is used to modify transferred field
- // after ACK is received or when filling ISO endpoint with size larger then
- // FIFO size.
- uint16_t last_packet_size;
- uint8_t ep_addr;
- // DATA0/1 toggle bit 1 DATA1 is expected or transmitted
- uint8_t data1 : 1;
- // Endpoint is stalled
- uint8_t stall : 1;
- // ISO endpoint
- uint8_t iso : 1;
-} xfer_ctl_t;
-
-static struct
-{
- bool vbus_present;
- bool in_reset;
- xfer_ctl_t xfer_status[EP_MAX][2];
- // Endpoints that use DMA, one for each direction
- uint8_t dma_ep[2];
-} _dcd =
-{
- .vbus_present = false,
- .xfer_status =
- {
- { { .regs = EP_REGS(USB_EPC0_REG) }, { .regs = EP_REGS(USB_EPC0_REG) } },
- { { .regs = EP_REGS(USB_EPC1_REG) }, { .regs = EP_REGS(USB_EPC1_REG) } },
- { { .regs = EP_REGS(USB_EPC3_REG) }, { .regs = EP_REGS(USB_EPC3_REG) } },
- { { .regs = EP_REGS(USB_EPC5_REG) }, { .regs = EP_REGS(USB_EPC5_REG) } },
- }
-};
-
-// Two endpoint 0 descriptor definition for unified dcd_edpt_open()
-static const tusb_desc_endpoint_t ep0OUT_desc =
-{
- .bLength = sizeof(tusb_desc_endpoint_t),
- .bDescriptorType = TUSB_DESC_ENDPOINT,
-
- .bEndpointAddress = 0x00,
- .bmAttributes = { .xfer = TUSB_XFER_CONTROL },
- .wMaxPacketSize = { .size = CFG_TUD_ENDPOINT0_SIZE },
- .bInterval = 0
-};
-
-static const tusb_desc_endpoint_t ep0IN_desc =
-{
- .bLength = sizeof(tusb_desc_endpoint_t),
- .bDescriptorType = TUSB_DESC_ENDPOINT,
-
- .bEndpointAddress = 0x80,
- .bmAttributes = { .xfer = TUSB_XFER_CONTROL },
- .wMaxPacketSize = { .size = CFG_TUD_ENDPOINT0_SIZE },
- .bInterval = 0
-};
-
-#define XFER_CTL_BASE(_ep, _dir) &_dcd.xfer_status[_ep][_dir]
-
-static void fill_tx_fifo(xfer_ctl_t * xfer)
-{
- int left_to_send;
- uint8_t const *src;
- EPx_REGS *regs = xfer->regs;
- uint8_t const epnum = tu_edpt_number(xfer->ep_addr);
-
- src = &xfer->buffer[xfer->transferred];
- left_to_send = xfer->total_len - xfer->transferred;
- if (left_to_send > xfer->max_packet_size - xfer->last_packet_size)
- {
- left_to_send = xfer->max_packet_size - xfer->last_packet_size;
- }
-
- // Loop checks TCOUNT all the time since this value is saturated to 31
- // and can't be read just once before.
- while ((regs->txs & USB_USB_TXS1_REG_USB_TCOUNT_Msk) > 0 && left_to_send > 0)
- {
- regs->txd = *src++;
- xfer->last_packet_size++;
- left_to_send--;
- }
- if (epnum != 0)
- {
- if (left_to_send > 0)
- {
- // Max packet size is set to value greater then FIFO. Enable fifo level warning
- // to handle larger packets.
- regs->txc |= (3 << USB_USB_TXC1_REG_USB_TFWL_Pos);
- USB->USB_FWMSK_REG |= 1 << (epnum - 1 + USB_USB_FWMSK_REG_USB_M_TXWARN31_Pos);
- }
- else
- {
- xfer->regs->txc &= ~USB_USB_TXC1_REG_USB_TFWL_Msk;
- USB->USB_FWMSK_REG &= ~(1 << (epnum - 1 + USB_USB_FWMSK_REG_USB_M_TXWARN31_Pos));
- // Whole packet already in fifo, no need to refill it later. Mark last.
- regs->txc |= USB_USB_TXC1_REG_USB_LAST_Msk;
- }
- }
-}
-
-static bool try_allocate_dma(uint8_t epnum, uint8_t dir)
-{
- // TODO: Disable interrupts while checking
- if (_dcd.dma_ep[dir] == 0)
- {
- _dcd.dma_ep[dir] = epnum;
- if (dir == TUSB_DIR_OUT)
- USB->USB_DMA_CTRL_REG = (USB->USB_DMA_CTRL_REG & ~USB_USB_DMA_CTRL_REG_USB_DMA_RX_Msk) |
- ((epnum - 1) << USB_USB_DMA_CTRL_REG_USB_DMA_RX_Pos);
- else
- USB->USB_DMA_CTRL_REG = (USB->USB_DMA_CTRL_REG & ~USB_USB_DMA_CTRL_REG_USB_DMA_TX_Msk) |
- ((epnum - 1) << USB_USB_DMA_CTRL_REG_USB_DMA_TX_Pos);
- USB->USB_DMA_CTRL_REG |= USB_USB_DMA_CTRL_REG_USB_DMA_EN_Msk;
- }
- return _dcd.dma_ep[dir] == epnum;
-}
-
-static void start_rx_dma(volatile void *src, void *dst, uint16_t size)
-{
- // Setup SRC and DST registers
- RX_DMA_REGS->DMAx_A_START_REG = (uint32_t)src;
- RX_DMA_REGS->DMAx_B_START_REG = (uint32_t)dst;
- // Don't need DMA interrupt, read end is determined by RX_LAST or RX_ERR events.
- RX_DMA_REGS->DMAx_INT_REG = size - 1;
- RX_DMA_REGS->DMAx_LEN_REG = size - 1;
- RX_DMA_REGS->DMAx_CTRL_REG = RX_DMA_START;
-}
-
-static void start_rx_packet(xfer_ctl_t *xfer)
-{
- uint8_t const epnum = tu_edpt_number(xfer->ep_addr);
- uint16_t remaining = xfer->total_len - xfer->transferred;
- uint16_t size = tu_min16(remaining, xfer->max_packet_size);
-
- xfer->last_packet_size = 0;
- if (xfer->max_packet_size > FIFO_SIZE && remaining > FIFO_SIZE)
- {
- if (try_allocate_dma(epnum, TUSB_DIR_OUT))
- {
- start_rx_dma(&xfer->regs->rxd, xfer->buffer + xfer->transferred, size);
- }
- else
- {
- // Other endpoint is using DMA in that direction, fall back to interrupts.
- // For endpoint size greater then FIFO size enable FIFO level warning interrupt
- // when FIFO has less then 17 bytes free.
- xfer->regs->rxc |= USB_USB_RXC1_REG_USB_RFWL_Msk;
- USB->USB_FWMSK_REG |= 1 << (epnum - 1 + USB_USB_FWMSK_REG_USB_M_RXWARN31_Pos);
- }
- }
- else if (epnum != 0)
- {
- // If max_packet_size would fit in FIFO no need for FIFO level warning interrupt.
- xfer->regs->rxc &= ~USB_USB_RXC1_REG_USB_RFWL_Msk;
- USB->USB_FWMSK_REG &= ~(1 << (epnum - 1 + USB_USB_FWMSK_REG_USB_M_RXWARN31_Pos));
- }
- xfer->regs->rxc |= USB_USB_RXC1_REG_USB_RX_EN_Msk;
-}
-
-static void start_tx_dma(void *src, volatile void *dst, uint16_t size)
-{
- // Setup SRC and DST registers
- TX_DMA_REGS->DMAx_A_START_REG = (uint32_t)src;
- TX_DMA_REGS->DMAx_B_START_REG = (uint32_t)dst;
- // Interrupt not needed
- TX_DMA_REGS->DMAx_INT_REG = size;
- TX_DMA_REGS->DMAx_LEN_REG = size - 1;
- TX_DMA_REGS->DMAx_CTRL_REG = TX_DMA_START;
-}
-
-static void start_tx_packet(xfer_ctl_t *xfer)
-{
- uint8_t const epnum = tu_edpt_number(xfer->ep_addr);
- uint16_t remaining = xfer->total_len - xfer->transferred;
- uint16_t size = tu_min16(remaining, xfer->max_packet_size);
- EPx_REGS *regs = xfer->regs;
-
- xfer->last_packet_size = 0;
-
- regs->txc = USB_USB_TXC1_REG_USB_FLUSH_Msk;
- regs->txc = USB_USB_TXC1_REG_USB_IGN_ISOMSK_Msk;
- if (xfer->data1) xfer->regs->txc |= USB_USB_TXC1_REG_USB_TOGGLE_TX_Msk;
-
- if (xfer->max_packet_size > FIFO_SIZE && remaining > FIFO_SIZE && try_allocate_dma(epnum, TUSB_DIR_IN))
- {
- // Whole packet will be put in FIFO by DMA. Set LAST bit before start.
- start_tx_dma(xfer->buffer + xfer->transferred, &regs->txd, size);
- regs->txc |= USB_USB_TXC1_REG_USB_LAST_Msk;
- }
- else
- {
- fill_tx_fifo(xfer);
- }
- regs->txc |= USB_USB_TXC1_REG_USB_TX_EN_Msk;
-}
-
-static void read_rx_fifo(xfer_ctl_t *xfer, uint16_t bytes_in_fifo)
-{
- EPx_REGS *regs = xfer->regs;
- uint16_t remaining = xfer->total_len - xfer->transferred - xfer->last_packet_size;
- uint16_t receive_this_time = bytes_in_fifo;
-
- if (remaining < bytes_in_fifo) receive_this_time = remaining;
-
- uint8_t *buf = xfer->buffer + xfer->transferred + xfer->last_packet_size;
-
- for (int i = 0; i < receive_this_time; ++i) buf[i] = regs->rxd;
-
- xfer->last_packet_size += receive_this_time;
-}
-
-static void handle_ep0_rx(void)
-{
- int fifo_bytes;
- uint32_t rxs0 = USB->USB_RXS0_REG;
-
- xfer_ctl_t *xfer = XFER_CTL_BASE(0, TUSB_DIR_OUT);
-
- fifo_bytes = GET_BIT(rxs0, USB_USB_RXS0_REG_USB_RCOUNT);
- if (rxs0 & USB_USB_RXS0_REG_USB_SETUP_Msk)
- {
- xfer_ctl_t *xfer_in = XFER_CTL_BASE(0, TUSB_DIR_IN);
- // Setup packet is in
- for (int i = 0; i < fifo_bytes; ++i) _setup_packet[i] = USB->USB_RXD0_REG;
-
- xfer->stall = 0;
- xfer->data1 = 1;
- xfer_in->stall = 0;
- xfer_in->data1 = 1;
- REG_SET_BIT(USB_TXC0_REG, USB_TOGGLE_TX0);
- REG_CLR_BIT(USB_EPC0_REG, USB_STALL);
- dcd_event_setup_received(0, _setup_packet,true);
- }
- else
- {
- if (GET_BIT(rxs0, USB_USB_RXS0_REG_USB_TOGGLE_RX0) != xfer->data1)
- {
- // Toggle bit does not match discard packet
- REG_SET_BIT(USB_RXC0_REG, USB_FLUSH);
- xfer->last_packet_size = 0;
- }
- else
- {
- read_rx_fifo(xfer, fifo_bytes);
- if (rxs0 & USB_USB_RXS0_REG_USB_RX_LAST_Msk)
- {
- xfer->transferred += xfer->last_packet_size;
- xfer->data1 ^= 1;
-
- if (xfer->total_len == xfer->transferred || xfer->last_packet_size < xfer->max_packet_size)
- {
- dcd_event_xfer_complete(0, 0, xfer->transferred, XFER_RESULT_SUCCESS, true);
- }
- else
- {
- // Re-enable reception
- REG_SET_BIT(USB_RXC0_REG, USB_RX_EN);
- }
- xfer->last_packet_size = 0;
- }
- }
- }
-}
-
-static void handle_ep0_tx(void)
-{
- uint32_t txs0;
- xfer_ctl_t *xfer = XFER_CTL_BASE(0, TUSB_DIR_IN);
- EPx_REGS *regs = xfer->regs;
-
- txs0 = regs->USB_TXS0_REG;
-
- if (GET_BIT(txs0, USB_USB_TXS0_REG_USB_TX_DONE))
- {
- // ACK received
- if (GET_BIT(txs0, USB_USB_TXS0_REG_USB_ACK_STAT))
- {
- xfer->transferred += xfer->last_packet_size;
- xfer->last_packet_size = 0;
- xfer->data1 ^= 1;
- REG_SET_VAL(USB_TXC0_REG, USB_TOGGLE_TX0, xfer->data1);
- if (xfer->transferred == xfer->total_len)
- {
- dcd_event_xfer_complete(0, 0 | TUSB_DIR_IN_MASK, xfer->total_len, XFER_RESULT_SUCCESS, true);
- return;
- }
- }
- else
- {
- // Start from the beginning
- xfer->last_packet_size = 0;
- }
- fill_tx_fifo(xfer);
- }
-}
-
-static void handle_epx_rx_ev(uint8_t ep)
-{
- uint32_t rxs;
- int fifo_bytes;
- xfer_ctl_t *xfer = XFER_CTL_BASE(ep, TUSB_DIR_OUT);
-
- EPx_REGS *regs = xfer->regs;
-
- do
- {
- rxs = regs->rxs;
-
- if (GET_BIT(rxs, USB_USB_RXS1_REG_USB_RX_ERR))
- {
- regs->rxc |= USB_USB_RXC1_REG_USB_FLUSH_Msk;
- xfer->last_packet_size = 0;
- if (_dcd.dma_ep[TUSB_DIR_OUT] == ep)
- {
- // Stop DMA
- RX_DMA_REGS->DMAx_CTRL_REG &= ~DMA_DMA0_CTRL_REG_DMA_ON_Msk;
- // Restart DMA since packet was dropped, all parameters should still work.
- RX_DMA_REGS->DMAx_CTRL_REG |= DMA_DMA0_CTRL_REG_DMA_ON_Msk;
- }
- break;
- }
- else
- {
- if (_dcd.dma_ep[TUSB_DIR_OUT] == ep)
- {
- // Disable DMA and update last_packet_size with what DMA reported.
- RX_DMA_REGS->DMAx_CTRL_REG &= ~DMA_DMA0_CTRL_REG_DMA_ON_Msk;
- xfer->last_packet_size = RX_DMA_REGS->DMAx_IDX_REG;
- // When DMA did not finished (packet was smaller then MPS), DMAx_IDX_REG holds exact number of bytes transmitted.
- // When DMA finished value in DMAx_IDX_REG is one less then actual number of transmitted bytes.
- if (xfer->last_packet_size == RX_DMA_REGS->DMAx_LEN_REG) xfer->last_packet_size++;
- // Release DMA to use by other endpoints.
- _dcd.dma_ep[TUSB_DIR_OUT] = 0;
- }
- fifo_bytes = GET_BIT(rxs, USB_USB_RXS1_REG_USB_RXCOUNT);
- // FIFO maybe empty if DMA read it before or it's final iteration and function already read all that was to read.
- if (fifo_bytes > 0)
- {
- read_rx_fifo(xfer, fifo_bytes);
- }
- if (GET_BIT(rxs, USB_USB_RXS1_REG_USB_RX_LAST))
- {
- if (!xfer->iso && GET_BIT(rxs, USB_USB_RXS1_REG_USB_TOGGLE_RX) != xfer->data1)
- {
- // Toggle bit does not match discard packet
- regs->rxc |= USB_USB_RXC1_REG_USB_FLUSH_Msk;
- }
- else
- {
- xfer->data1 ^= 1;
- xfer->transferred += xfer->last_packet_size;
- if (xfer->total_len == xfer->transferred || xfer->last_packet_size < xfer->max_packet_size || xfer->iso)
- {
- dcd_event_xfer_complete(0, xfer->ep_addr, xfer->transferred, XFER_RESULT_SUCCESS, true);
- }
- else
- {
- // Re-enable reception
- start_rx_packet(xfer);
- }
- }
- xfer->last_packet_size = 0;
- }
- }
- } while (fifo_bytes > TU_DA1469X_FIFO_READ_THRESHOLD);
-}
-
-static void handle_rx_ev(void)
-{
- if (USB->USB_RXEV_REG & 1)
- handle_epx_rx_ev(1);
- if (USB->USB_RXEV_REG & 2)
- handle_epx_rx_ev(2);
- if (USB->USB_RXEV_REG & 4)
- handle_epx_rx_ev(3);
-}
-
-static void handle_epx_tx_ev(xfer_ctl_t *xfer)
-{
- uint8_t const epnum = tu_edpt_number(xfer->ep_addr);
- uint32_t txs;
- EPx_REGS *regs = xfer->regs;
-
- txs = regs->txs;
-
- if (GET_BIT(txs, USB_USB_TXS1_REG_USB_TX_DONE))
- {
- if (_dcd.dma_ep[TUSB_DIR_IN] == epnum)
- {
- // Disable DMA and update last_packet_size with what DMA reported.
- TX_DMA_REGS->DMAx_CTRL_REG &= ~DMA_DMA1_CTRL_REG_DMA_ON_Msk;
- xfer->last_packet_size = TX_DMA_REGS->DMAx_IDX_REG + 1;
- // Release DMA to used by other endpoints.
- _dcd.dma_ep[TUSB_DIR_IN] = 0;
- }
- if (GET_BIT(txs, USB_USB_TXS1_REG_USB_ACK_STAT))
- {
- // ACK received, update transfer state and DATA0/1 bit
- xfer->transferred += xfer->last_packet_size;
- xfer->last_packet_size = 0;
- xfer->data1 ^= 1;
-
- if (xfer->transferred == xfer->total_len)
- {
- dcd_event_xfer_complete(0, xfer->ep_addr, xfer->total_len, XFER_RESULT_SUCCESS, true);
- return;
- }
- }
- }
- if (txs & USB_USB_TXS1_REG_USB_TX_URUN_Msk)
- {
- TU_LOG1("EP %d FIFO underrun\n", epnum);
- }
- // Start next or repeated packet.
- start_tx_packet(xfer);
-}
-
-static void handle_tx_ev(void)
-{
- if (USB->USB_TXEV_REG & 1)
- handle_epx_tx_ev(XFER_CTL_BASE(1, TUSB_DIR_IN));
- if (USB->USB_TXEV_REG & 2)
- handle_epx_tx_ev(XFER_CTL_BASE(2, TUSB_DIR_IN));
- if (USB->USB_TXEV_REG & 4)
- handle_epx_tx_ev(XFER_CTL_BASE(3, TUSB_DIR_IN));
-}
-
-static void handle_bus_reset(void)
-{
- USB->USB_NFSR_REG = 0;
- USB->USB_FAR_REG = 0x80;
- USB->USB_ALTMSK_REG = 0;
- USB->USB_NFSR_REG = NFSR_NODE_RESET;
- USB->USB_TXMSK_REG = 0;
- USB->USB_RXMSK_REG = 0;
- (void)USB->USB_ALTEV_REG;
- _dcd.in_reset = true;
-
- dcd_event_bus_reset(0, TUSB_SPEED_FULL, true);
- USB->USB_DMA_CTRL_REG = 0;
-
- USB->USB_MAMSK_REG = USB_USB_MAMSK_REG_USB_M_INTR_Msk |
-#if USE_SOF
- USB_USB_MAMSK_REG_USB_M_FRAME_Msk |
-#endif
- USB_USB_MAMSK_REG_USB_M_WARN_Msk |
- USB_USB_MAMSK_REG_USB_M_ALT_Msk;
- USB->USB_NFSR_REG = NFSR_NODE_OPERATIONAL;
- USB->USB_ALTMSK_REG = USB_USB_ALTMSK_REG_USB_M_SD3_Msk |
- USB_USB_ALTMSK_REG_USB_M_RESUME_Msk;
- // There is no information about end of reset state
- // USB_FRAME event will be used to enable reset detection again
- REG_SET_BIT(USB_MAEV_REG, USB_FRAME);
- dcd_edpt_open (0, &ep0OUT_desc);
- dcd_edpt_open (0, &ep0IN_desc);
-}
-
-static void handle_alt_ev(void)
-{
- uint32_t alt_ev = USB->USB_ALTEV_REG;
-
- if (GET_BIT(alt_ev, USB_USB_ALTEV_REG_USB_RESET))
- {
- handle_bus_reset();
- }
- else
- {
- if (GET_BIT(alt_ev, USB_USB_ALTEV_REG_USB_RESUME))
- {
- USB->USB_NFSR_REG = NFSR_NODE_OPERATIONAL;
- USB->USB_ALTMSK_REG &= ~USB_USB_ALTMSK_REG_USB_M_RESUME_Msk;
- USB->USB_ALTMSK_REG |= USB_USB_ALTMSK_REG_USB_M_SD3_Msk;
- dcd_event_bus_signal(0, DCD_EVENT_RESUME, true);
- }
- if (GET_BIT(alt_ev, USB_USB_ALTEV_REG_USB_SD3))
- {
- USB->USB_NFSR_REG = NFSR_NODE_SUSPEND;
- USB->USB_ALTMSK_REG |= USB_USB_ALTMSK_REG_USB_M_RESUME_Msk;
- USB->USB_ALTMSK_REG &= ~USB_USB_ALTMSK_REG_USB_M_SD3_Msk | USB_USB_ALTMSK_REG_USB_M_SD5_Msk;
- dcd_event_bus_signal(0, DCD_EVENT_SUSPEND, true);
- }
- }
-}
-
-static void handle_epx_tx_warn_ev(uint8_t ep)
-{
- fill_tx_fifo(XFER_CTL_BASE(ep, TUSB_DIR_IN));
-}
-
-static void handle_fifo_warning(void)
-{
- uint32_t fifo_warning = USB->USB_FWEV_REG;
-
- if (fifo_warning & 0x01)
- handle_epx_tx_warn_ev(1);
- if (fifo_warning & 0x02)
- handle_epx_tx_warn_ev(2);
- if (fifo_warning & 0x04)
- handle_epx_tx_warn_ev(3);
- if (fifo_warning & 0x10)
- handle_epx_rx_ev(1);
- if (fifo_warning & 0x20)
- handle_epx_rx_ev(2);
- if (fifo_warning & 0x40)
- handle_epx_rx_ev(3);
-}
-
-static void handle_ep0_nak(void)
-{
- uint32_t ep0_nak = USB->USB_EP0_NAK_REG;
-
- if (REG_GET_BIT(USB_EPC0_REG, USB_STALL))
- {
- if (GET_BIT(ep0_nak, USB_USB_EP0_NAK_REG_USB_EP0_INNAK))
- {
- // EP0 is stalled and NAK was sent, it means that RX is enabled
- // Disable RX for now.
- REG_CLR_BIT(USB_RXC0_REG, USB_RX_EN);
- REG_SET_BIT(USB_TXC0_REG, USB_TX_EN);
- }
- if (GET_BIT(ep0_nak, USB_USB_EP0_NAK_REG_USB_EP0_OUTNAK))
- {
- REG_SET_BIT(USB_RXC0_REG, USB_RX_EN);
- }
- }
- else
- {
- REG_CLR_BIT(USB_MAMSK_REG, USB_M_EP0_NAK);
- }
-}
-
-/*------------------------------------------------------------------*/
-/* Controller API
- *------------------------------------------------------------------*/
-void dcd_init(uint8_t rhport)
-{
- USB->USB_MCTRL_REG = USB_USB_MCTRL_REG_USBEN_Msk;
- USB->USB_NFSR_REG = 0;
- USB->USB_FAR_REG = 0x80;
- USB->USB_NFSR_REG = NFSR_NODE_RESET;
- USB->USB_TXMSK_REG = 0;
- USB->USB_RXMSK_REG = 0;
-
- USB->USB_MAMSK_REG = USB_USB_MAMSK_REG_USB_M_INTR_Msk |
- USB_USB_MAMSK_REG_USB_M_ALT_Msk |
- USB_USB_MAMSK_REG_USB_M_WARN_Msk;
- USB->USB_ALTMSK_REG = USB_USB_ALTMSK_REG_USB_M_RESET_Msk;
-
- dcd_connect(rhport);
-}
-
-void dcd_int_enable(uint8_t rhport)
-{
- (void)rhport;
-
- NVIC_EnableIRQ(USB_IRQn);
-}
-
-void dcd_int_disable(uint8_t rhport)
-{
- (void)rhport;
-
- NVIC_DisableIRQ(USB_IRQn);
-}
-
-void dcd_set_address(uint8_t rhport, uint8_t dev_addr)
-{
- (void)rhport;
-
- // Set default address for one ZLP
- USB->USB_EPC0_REG = USB_USB_EPC0_REG_USB_DEF_Msk;
- USB->USB_FAR_REG = (dev_addr & USB_USB_FAR_REG_USB_AD_Msk) | USB_USB_FAR_REG_USB_AD_EN_Msk;
- dcd_edpt_xfer(rhport, tu_edpt_addr(0, TUSB_DIR_IN), NULL, 0);
-}
-
-void dcd_remote_wakeup(uint8_t rhport)
-{
- (void)rhport;
-}
-
-void dcd_connect(uint8_t rhport)
-{
- (void)rhport;
-
- REG_SET_BIT(USB_MCTRL_REG, USB_NAT);
-
- // Select chosen DMA to be triggered by USB.
- DMA->DMA_REQ_MUX_REG = (DMA->DMA_REQ_MUX_REG & ~DA146XX_DMA_USB_MUX_MASK) | DA146XX_DMA_USB_MUX;
-}
-
-void dcd_disconnect(uint8_t rhport)
-{
- (void)rhport;
-
- REG_CLR_BIT(USB_MCTRL_REG, USB_NAT);
-}
-
-
-/*------------------------------------------------------------------*/
-/* DCD Endpoint port
- *------------------------------------------------------------------*/
-
-bool dcd_edpt_open(uint8_t rhport, tusb_desc_endpoint_t const * desc_edpt)
-{
- (void)rhport;
-
- uint8_t const epnum = tu_edpt_number(desc_edpt->bEndpointAddress);
- uint8_t const dir = tu_edpt_dir(desc_edpt->bEndpointAddress);
- xfer_ctl_t * xfer = XFER_CTL_BASE(epnum, dir);
- uint8_t iso_mask = 0;
-
- TU_ASSERT(epnum < EP_MAX);
-
- xfer->max_packet_size = desc_edpt->wMaxPacketSize.size;
- xfer->ep_addr = desc_edpt->bEndpointAddress;
- xfer->data1 = 0;
- xfer->iso = 0;
-
- if (epnum != 0 && desc_edpt->bmAttributes.xfer == 1)
- {
- iso_mask = USB_USB_EPC1_REG_USB_ISO_Msk;
- xfer->iso = 1;
- }
-
- if (epnum == 0)
- {
- USB->USB_MAMSK_REG |= USB_USB_MAMSK_REG_USB_M_EP0_RX_Msk |
- USB_USB_MAMSK_REG_USB_M_EP0_TX_Msk;
- }
- else
- {
- if (dir == TUSB_DIR_OUT)
- {
- xfer->regs->epc_out = epnum | USB_USB_EPC1_REG_USB_EP_EN_Msk | iso_mask;
- USB->USB_RXMSK_REG |= 0x101 << (epnum - 1);
- REG_SET_BIT(USB_MAMSK_REG, USB_M_RX_EV);
- }
- else
- {
- xfer->regs->epc_in = epnum | USB_USB_EPC1_REG_USB_EP_EN_Msk | iso_mask;
- USB->USB_TXMSK_REG |= 0x101 << (epnum - 1);
- REG_SET_BIT(USB_MAMSK_REG, USB_M_TX_EV);
- }
- }
-
- return true;
-}
-
-void dcd_edpt_close(uint8_t rhport, uint8_t ep_addr)
-{
- uint8_t const epnum = tu_edpt_number(ep_addr);
- uint8_t const dir = tu_edpt_dir(ep_addr);
- xfer_ctl_t * xfer = XFER_CTL_BASE(epnum, dir);
-
- (void)rhport;
-
- TU_ASSERT(epnum < EP_MAX,);
-
- if (epnum == 0)
- {
- USB->USB_MAMSK_REG &= ~(USB_USB_MAMSK_REG_USB_M_EP0_RX_Msk |
- USB_USB_MAMSK_REG_USB_M_EP0_TX_Msk);
- }
- else
- {
- if (dir == TUSB_DIR_OUT)
- {
- xfer->regs->rxc = USB_USB_RXC1_REG_USB_FLUSH_Msk;
- xfer->regs->epc_out = 0;
- USB->USB_RXMSK_REG &= ~(0x101 << (epnum - 1));
- // Release DMA if needed
- if (_dcd.dma_ep[TUSB_DIR_OUT] == epnum)
- {
- RX_DMA_REGS->DMAx_CTRL_REG &= ~DMA_DMA0_CTRL_REG_DMA_ON_Msk;
- _dcd.dma_ep[TUSB_DIR_OUT] = 0;
- }
- }
- else
- {
- xfer->regs->txc = USB_USB_TXC1_REG_USB_FLUSH_Msk;
- xfer->regs->epc_in = 0;
- USB->USB_TXMSK_REG &= ~(0x101 << (epnum - 1));
- // Release DMA if needed
- if (_dcd.dma_ep[TUSB_DIR_IN] == epnum)
- {
- TX_DMA_REGS->DMAx_CTRL_REG &= ~DMA_DMA1_CTRL_REG_DMA_ON_Msk;
- _dcd.dma_ep[TUSB_DIR_IN] = 0;
- }
- }
- }
-}
-
-bool dcd_edpt_xfer(uint8_t rhport, uint8_t ep_addr, uint8_t * buffer, uint16_t total_bytes)
-{
- uint8_t const epnum = tu_edpt_number(ep_addr);
- uint8_t const dir = tu_edpt_dir(ep_addr);
- xfer_ctl_t * xfer = XFER_CTL_BASE(epnum, dir);
-
- (void)rhport;
-
- xfer->buffer = buffer;
- xfer->total_len = total_bytes;
- xfer->last_packet_size = 0;
- xfer->transferred = 0;
-
- if (dir == TUSB_DIR_OUT)
- {
- start_rx_packet(xfer);
- }
- else // IN
- {
- start_tx_packet(xfer);
- }
-
- return true;
-}
-
-void dcd_edpt_stall(uint8_t rhport, uint8_t ep_addr)
-{
- uint8_t const epnum = tu_edpt_number(ep_addr);
- uint8_t const dir = tu_edpt_dir(ep_addr);
-
- (void)rhport;
-
- xfer_ctl_t * xfer = XFER_CTL_BASE(epnum, dir);
- xfer->stall = 1;
-
- if (epnum == 0)
- {
- // EP0 has just one registers to control stall for IN and OUT
- REG_SET_BIT(USB_EPC0_REG, USB_STALL);
- if (dir == TUSB_DIR_OUT)
- {
- xfer->regs->USB_RXC0_REG = USB_USB_RXC0_REG_USB_RX_EN_Msk;
- }
- else
- {
- if (xfer->regs->USB_RXC0_REG & USB_USB_RXC0_REG_USB_RX_EN_Msk)
- {
- // If RX is also enabled TX will not be stalled since RX has
- // higher priority. Enable NAK interrupt to handle stall.
- REG_SET_BIT(USB_MAMSK_REG, USB_M_EP0_NAK);
- }
- else
- {
- xfer->regs->USB_TXC0_REG |= USB_USB_TXC0_REG_USB_TX_EN_Msk;
- }
- }
- }
- else
- {
- if (dir == TUSB_DIR_OUT)
- {
- xfer->regs->epc_out |= USB_USB_EPC1_REG_USB_STALL_Msk;
- xfer->regs->rxc |= USB_USB_RXC1_REG_USB_RX_EN_Msk;
- }
- else
- {
- xfer->regs->epc_in |= USB_USB_EPC1_REG_USB_STALL_Msk;
- xfer->regs->txc |= USB_USB_TXC1_REG_USB_TX_EN_Msk | USB_USB_TXC1_REG_USB_LAST_Msk;
- }
- }
-}
-
-void dcd_edpt_clear_stall(uint8_t rhport, uint8_t ep_addr)
-{
- uint8_t const epnum = tu_edpt_number(ep_addr);
- uint8_t const dir = tu_edpt_dir(ep_addr);
-
- (void)rhport;
-
- xfer_ctl_t * xfer = XFER_CTL_BASE(epnum, dir);
-
- // Clear stall is called in response to Clear Feature ENDPOINT_HALT, reset toggle
- xfer->data1 = 0;
- xfer->stall = 0;
-
- if (dir == TUSB_DIR_OUT)
- {
- xfer->regs->epc_out &= ~USB_USB_EPC1_REG_USB_STALL_Msk;
- }
- else
- {
- xfer->regs->epc_in &= ~USB_USB_EPC1_REG_USB_STALL_Msk;
- }
- if (epnum == 0)
- {
- REG_CLR_BIT(USB_MAMSK_REG, USB_M_EP0_NAK);
- }
-}
-
-/*------------------------------------------------------------------*/
-/* Interrupt Handler
- *------------------------------------------------------------------*/
-
-void dcd_int_handler(uint8_t rhport)
-{
- uint32_t int_status = USB->USB_MAEV_REG;
-
- (void)rhport;
-
- if (GET_BIT(int_status, USB_USB_MAEV_REG_USB_WARN))
- {
- handle_fifo_warning();
- }
-
- if (GET_BIT(int_status, USB_USB_MAEV_REG_USB_CH_EV))
- {
- // TODO: for now just clear interrupt
- (void)USB->USB_CHARGER_STAT_REG;
- }
-
- if (GET_BIT(int_status, USB_USB_MAEV_REG_USB_EP0_NAK))
- {
- handle_ep0_nak();
- }
-
- if (GET_BIT(int_status, USB_USB_MAEV_REG_USB_EP0_RX))
- {
- handle_ep0_rx();
- }
-
- if (GET_BIT(int_status, USB_USB_MAEV_REG_USB_EP0_TX))
- {
- handle_ep0_tx();
- }
-
- if (GET_BIT(int_status, USB_USB_MAEV_REG_USB_RX_EV))
- {
- handle_rx_ev();
- }
-
- if (GET_BIT(int_status, USB_USB_MAEV_REG_USB_NAK))
- {
- (void)USB->USB_NAKEV_REG;
- }
-
- if (GET_BIT(int_status, USB_USB_MAEV_REG_USB_FRAME))
- {
- if (_dcd.in_reset)
- {
- // Enable reset detection
- _dcd.in_reset = false;
- (void)USB->USB_ALTEV_REG;
- }
-#if USE_SOF
- dcd_event_bus_signal(0, DCD_EVENT_SOF, true);
-#else
- // SOF was used to re-enable reset detection
- // No need to keep it enabled
- USB->USB_MAMSK_REG &= ~USB_USB_MAMSK_REG_USB_M_FRAME_Msk;
-#endif
- }
-
- if (GET_BIT(int_status, USB_USB_MAEV_REG_USB_TX_EV))
- {
- handle_tx_ev();
- }
-
- if (GET_BIT(int_status, USB_USB_MAEV_REG_USB_ALT))
- {
- handle_alt_ev();
- }
-}
-
-#endif
diff --git a/tinyusb/src/portable/ehci/ehci.c b/tinyusb/src/portable/ehci/ehci.c
deleted file mode 100755
index e3b7499c..00000000
--- a/tinyusb/src/portable/ehci/ehci.c
+++ /dev/null
@@ -1,893 +0,0 @@
-/*
- * The MIT License (MIT)
- *
- * Copyright (c) 2019 Ha Thach (tinyusb.org)
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- *
- * This file is part of the TinyUSB stack.
- */
-
-#include "host/hcd_attr.h"
-
-#if TUSB_OPT_HOST_ENABLED && defined(HCD_ATTR_EHCI_TRANSDIMENSION)
-
-//--------------------------------------------------------------------+
-// INCLUDE
-//--------------------------------------------------------------------+
-#include "osal/osal.h"
-
-#include "host/hcd.h"
-#include "ehci_api.h"
-#include "ehci.h"
-
-//--------------------------------------------------------------------+
-// MACRO CONSTANT TYPEDEF
-//--------------------------------------------------------------------+
-
-// Debug level of EHCI
-#define EHCI_DBG 2
-
-// Framelist size as small as possible to save SRAM
-#ifdef HCD_ATTR_EHCI_TRANSDIMENSION
- // NXP Transdimension: 8 elements
- #define FRAMELIST_SIZE_BIT_VALUE 7u
- #define FRAMELIST_SIZE_USBCMD_VALUE (((FRAMELIST_SIZE_BIT_VALUE & 3) << EHCI_USBCMD_POS_FRAMELIST_SIZE) | \
- ((FRAMELIST_SIZE_BIT_VALUE >> 2) << EHCI_USBCMD_POS_NXP_FRAMELIST_SIZE_MSB))
-#else
- // STD EHCI: 256 elements
- #define FRAMELIST_SIZE_BIT_VALUE 2u
- #define FRAMELIST_SIZE_USBCMD_VALUE ((FRAMELIST_SIZE_BIT_VALUE & 3) << EHCI_USBCMD_POS_FRAMELIST_SIZE)
-#endif
-
-#define FRAMELIST_SIZE (1024 >> FRAMELIST_SIZE_BIT_VALUE)
-
-typedef struct
-{
- ehci_link_t period_framelist[FRAMELIST_SIZE];
-
- // TODO only implement 1 ms & 2 ms & 4 ms, 8 ms (framelist)
- // [0] : 1ms, [1] : 2ms, [2] : 4ms, [3] : 8 ms
- // TODO better implementation without dummy head to save SRAM
- ehci_qhd_t period_head_arr[4];
-
- // Note control qhd of dev0 is used as head of async list
- struct {
- ehci_qhd_t qhd;
- ehci_qtd_t qtd;
- }control[CFG_TUH_DEVICE_MAX+CFG_TUH_HUB+1];
-
- ehci_qhd_t qhd_pool[HCD_MAX_ENDPOINT];
- ehci_qtd_t qtd_pool[HCD_MAX_XFER] TU_ATTR_ALIGNED(32);
-
- ehci_registers_t* regs;
-
- volatile uint32_t uframe_number;
-}ehci_data_t;
-
-// Periodic frame list must be 4K alignment
-CFG_TUSB_MEM_SECTION TU_ATTR_ALIGNED(4096) static ehci_data_t ehci_data;
-
-//--------------------------------------------------------------------+
-// PROTOTYPE
-//--------------------------------------------------------------------+
-static inline ehci_link_t* get_period_head(uint8_t rhport, uint32_t interval_ms)
-{
- (void) rhport;
- return (ehci_link_t*) &ehci_data.period_head_arr[ tu_log2( tu_min32(FRAMELIST_SIZE, interval_ms) ) ];
-}
-
-static inline ehci_qhd_t* qhd_control(uint8_t dev_addr)
-{
- return &ehci_data.control[dev_addr].qhd;
-}
-
-static inline ehci_qhd_t* qhd_async_head(uint8_t rhport)
-{
- (void) rhport;
- // control qhd of dev0 is used as async head
- return qhd_control(0);
-}
-
-static inline ehci_qtd_t* qtd_control(uint8_t dev_addr)
-{
- return &ehci_data.control[dev_addr].qtd;
-}
-
-
-static inline ehci_qhd_t* qhd_next (ehci_qhd_t const * p_qhd);
-static inline ehci_qhd_t* qhd_find_free (void);
-static inline ehci_qhd_t* qhd_get_from_addr (uint8_t dev_addr, uint8_t ep_addr);
-
-// determine if a queue head has bus-related error
-static inline bool qhd_has_xact_error (ehci_qhd_t * p_qhd)
-{
- return (p_qhd->qtd_overlay.buffer_err || p_qhd->qtd_overlay.babble_err || p_qhd->qtd_overlay.xact_err);
- //p_qhd->qtd_overlay.non_hs_period_missed_uframe || p_qhd->qtd_overlay.pingstate_err TODO split transaction error
-}
-
-static void qhd_init(ehci_qhd_t *p_qhd, uint8_t dev_addr, tusb_desc_endpoint_t const * ep_desc);
-
-static inline ehci_qtd_t* qtd_find_free (void);
-static inline ehci_qtd_t* qtd_next (ehci_qtd_t const * p_qtd);
-static inline void qtd_insert_to_qhd (ehci_qhd_t *p_qhd, ehci_qtd_t *p_qtd_new);
-static inline void qtd_remove_1st_from_qhd (ehci_qhd_t *p_qhd);
-static void qtd_init (ehci_qtd_t* p_qtd, void* buffer, uint16_t total_bytes);
-
-static inline void list_insert (ehci_link_t *current, ehci_link_t *new, uint8_t new_type);
-static inline ehci_link_t* list_next (ehci_link_t *p_link_pointer);
-
-//--------------------------------------------------------------------+
-// HCD API
-//--------------------------------------------------------------------+
-
-uint32_t hcd_frame_number(uint8_t rhport)
-{
- (void) rhport;
- return (ehci_data.uframe_number + ehci_data.regs->frame_index) >> 3;
-}
-
-void hcd_port_reset(uint8_t rhport)
-{
- (void) rhport;
-
- ehci_registers_t* regs = ehci_data.regs;
-
-// regs->portsc_bm.port_enabled = 0; // disable port before reset
-// regs->portsc_bm.port_reset = 1;
-
- uint32_t portsc = regs->portsc;
-
- portsc &= ~(EHCI_PORTSC_MASK_PORT_EANBLED);
- portsc |= EHCI_PORTSC_MASK_PORT_RESET;
-
- regs->portsc = portsc;
-}
-
-#if 0
-void hcd_port_reset_end(uint8_t rhport)
-{
- (void) rhport;
-
- ehci_registers_t* regs = ehci_data.regs;
- regs->portsc_bm.port_reset = 0;
-}
-#endif
-
-bool hcd_port_connect_status(uint8_t rhport)
-{
- (void) rhport;
- return ehci_data.regs->portsc_bm.current_connect_status;
-}
-
-tusb_speed_t hcd_port_speed_get(uint8_t rhport)
-{
- (void) rhport;
- return (tusb_speed_t) ehci_data.regs->portsc_bm.nxp_port_speed; // NXP specific port speed
-}
-
-static void list_remove_qhd_by_addr(ehci_link_t* list_head, uint8_t dev_addr)
-{
- for(ehci_link_t* prev = list_head;
- !prev->terminate && (tu_align32(prev->address) != (uint32_t) list_head);
- prev = list_next(prev) )
- {
- // TODO check type for ISO iTD and siTD
- ehci_qhd_t* qhd = (ehci_qhd_t*) list_next(prev);
- if ( qhd->dev_addr == dev_addr )
- {
- // TODO deactive all TD, wait for QHD to inactive before removal
- prev->address = qhd->next.address;
-
- // EHCI 4.8.2 link the removed qhd to async head (which always reachable by Host Controller)
- qhd->next.address = ((uint32_t) list_head) | (EHCI_QTYPE_QHD << 1);
-
- if ( qhd->int_smask )
- {
- // period list queue element is guarantee to be free in the next frame (1 ms)
- qhd->used = 0;
- }else
- {
- // async list use async advance handshake
- // mark as removing, will completely re-usable when async advance isr occurs
- qhd->removing = 1;
- }
- }
- }
-}
-
-// Close all opened endpoint belong to this device
-void hcd_device_close(uint8_t rhport, uint8_t dev_addr)
-{
- // skip dev0
- if (dev_addr == 0) return;
-
- // Remove from async list
- list_remove_qhd_by_addr( (ehci_link_t*) qhd_async_head(rhport), dev_addr );
-
- // Remove from all interval period list
- for(uint8_t i = 0; i < TU_ARRAY_SIZE(ehci_data.period_head_arr); i++)
- {
- list_remove_qhd_by_addr( (ehci_link_t*) &ehci_data.period_head_arr[i], dev_addr);
- }
-
- // Async doorbell (EHCI 4.8.2 for operational details)
- ehci_data.regs->command_bm.async_adv_doorbell = 1;
-}
-
-bool ehci_init(uint8_t rhport, uint32_t capability_reg, uint32_t operatial_reg)
-{
- (void) capability_reg; // not used yet
-
- tu_memclr(&ehci_data, sizeof(ehci_data_t));
-
- ehci_data.regs = (ehci_registers_t* ) operatial_reg;
-
- ehci_registers_t* regs = ehci_data.regs;
-
- //------------- CTRLDSSEGMENT Register (skip) -------------//
- //------------- USB INT Register -------------//
- regs->inten = 0; // 1. disable all the interrupt
- regs->status = EHCI_INT_MASK_ALL; // 2. clear all status
-
- regs->inten = EHCI_INT_MASK_ERROR | EHCI_INT_MASK_PORT_CHANGE | EHCI_INT_MASK_ASYNC_ADVANCE |
- EHCI_INT_MASK_NXP_PERIODIC | EHCI_INT_MASK_NXP_ASYNC | EHCI_INT_MASK_FRAMELIST_ROLLOVER;
-
- //------------- Asynchronous List -------------//
- ehci_qhd_t * const async_head = qhd_async_head(rhport);
- tu_memclr(async_head, sizeof(ehci_qhd_t));
-
- async_head->next.address = (uint32_t) async_head; // circular list, next is itself
- async_head->next.type = EHCI_QTYPE_QHD;
- async_head->head_list_flag = 1;
- async_head->qtd_overlay.halted = 1; // inactive most of time
- async_head->qtd_overlay.next.terminate = 1; // TODO removed if verified
-
- regs->async_list_addr = (uint32_t) async_head;
-
- //------------- Periodic List -------------//
- // Build the polling interval tree with 1 ms, 2 ms, 4 ms and 8 ms (framesize) only
- for ( uint32_t i = 0; i < TU_ARRAY_SIZE(ehci_data.period_head_arr); i++ )
- {
- ehci_data.period_head_arr[i].int_smask = 1; // queue head in period list must have smask non-zero
- ehci_data.period_head_arr[i].qtd_overlay.halted = 1; // dummy node, always inactive
- }
-
- ehci_link_t * const framelist = ehci_data.period_framelist;
- ehci_link_t * const period_1ms = get_period_head(rhport, 1u);
-
- // all links --> period_head_arr[0] (1ms)
- // 0, 2, 4, 6 etc --> period_head_arr[1] (2ms)
- // 1, 5 --> period_head_arr[2] (4ms)
- // 3 --> period_head_arr[3] (8ms)
-
- // TODO EHCI_FRAMELIST_SIZE with other size than 8
- for(uint32_t i=0; i<FRAMELIST_SIZE; i++)
- {
- framelist[i].address = (uint32_t) period_1ms;
- framelist[i].type = EHCI_QTYPE_QHD;
- }
-
- for(uint32_t i=0; i<FRAMELIST_SIZE; i+=2)
- {
- list_insert(framelist + i, get_period_head(rhport, 2u), EHCI_QTYPE_QHD);
- }
-
- for(uint32_t i=1; i<FRAMELIST_SIZE; i+=4)
- {
- list_insert(framelist + i, get_period_head(rhport, 4u), EHCI_QTYPE_QHD);
- }
-
- list_insert(framelist+3, get_period_head(rhport, 8u), EHCI_QTYPE_QHD);
-
- period_1ms->terminate = 1;
-
- regs->periodic_list_base = (uint32_t) framelist;
-
- //------------- TT Control (NXP only) -------------//
- regs->nxp_tt_control = 0;
-
- //------------- USB CMD Register -------------//
- regs->command |= TU_BIT(EHCI_USBCMD_POS_RUN_STOP) | TU_BIT(EHCI_USBCMD_POS_ASYNC_ENABLE) |
- TU_BIT(EHCI_USBCMD_POS_PERIOD_ENABLE) | // TODO enable period list only there is int/iso endpoint
- FRAMELIST_SIZE_USBCMD_VALUE;
-
- //------------- ConfigFlag Register (skip) -------------//
- regs->portsc_bm.port_power = 1; // enable port power
-
- return true;
-}
-
-#if 0
-static void ehci_stop(uint8_t rhport)
-{
- (void) rhport;
-
- ehci_registers_t* regs = ehci_data.regs;
-
- regs->command_bm.run_stop = 0;
-
- // USB Spec: controller has to stop within 16 uframe = 2 frames
- while( regs->status_bm.hc_halted == 0 ) {}
-}
-#endif
-
-//--------------------------------------------------------------------+
-// Endpoint API
-//--------------------------------------------------------------------+
-
-bool hcd_edpt_open(uint8_t rhport, uint8_t dev_addr, tusb_desc_endpoint_t const * ep_desc)
-{
- (void) rhport;
-
- // TODO not support ISO yet
- TU_ASSERT (ep_desc->bmAttributes.xfer != TUSB_XFER_ISOCHRONOUS);
-
- //------------- Prepare Queue Head -------------//
- ehci_qhd_t * p_qhd;
-
- if ( ep_desc->bEndpointAddress == 0 )
- {
- p_qhd = qhd_control(dev_addr);
- }else
- {
- p_qhd = qhd_find_free();
- }
- TU_ASSERT(p_qhd);
-
- qhd_init(p_qhd, dev_addr, ep_desc);
-
- // control of dev0 is always present as async head
- if ( dev_addr == 0 ) return true;
-
- // Insert to list
- ehci_link_t * list_head = NULL;
-
- switch (ep_desc->bmAttributes.xfer)
- {
- case TUSB_XFER_CONTROL:
- case TUSB_XFER_BULK:
- list_head = (ehci_link_t*) qhd_async_head(rhport);
- break;
-
- case TUSB_XFER_INTERRUPT:
- list_head = get_period_head(rhport, p_qhd->interval_ms);
- break;
-
- case TUSB_XFER_ISOCHRONOUS:
- // TODO iso is not supported
- break;
-
- default: break;
- }
-
- TU_ASSERT(list_head);
-
- // TODO might need to disable async/period list
- list_insert(list_head, (ehci_link_t*) p_qhd, EHCI_QTYPE_QHD);
-
- return true;
-}
-
-bool hcd_setup_send(uint8_t rhport, uint8_t dev_addr, uint8_t const setup_packet[8])
-{
- (void) rhport;
-
- ehci_qhd_t* qhd = &ehci_data.control[dev_addr].qhd;
- ehci_qtd_t* td = &ehci_data.control[dev_addr].qtd;
-
- qtd_init(td, (void*) setup_packet, 8);
- td->pid = EHCI_PID_SETUP;
- td->int_on_complete = 1;
- td->next.terminate = 1;
-
- // sw region
- qhd->p_qtd_list_head = td;
- qhd->p_qtd_list_tail = td;
-
- // attach TD
- qhd->qtd_overlay.next.address = (uint32_t) td;
-
- return true;
-}
-
-bool hcd_edpt_xfer(uint8_t rhport, uint8_t dev_addr, uint8_t ep_addr, uint8_t * buffer, uint16_t buflen)
-{
- (void) rhport;
-
- uint8_t const epnum = tu_edpt_number(ep_addr);
- uint8_t const dir = tu_edpt_dir(ep_addr);
-
- if ( epnum == 0 )
- {
- ehci_qhd_t* qhd = qhd_control(dev_addr);
- ehci_qtd_t* qtd = qtd_control(dev_addr);
-
- qtd_init(qtd, buffer, buflen);
-
- // first first data toggle is always 1 (data & setup stage)
- qtd->data_toggle = 1;
- qtd->pid = dir ? EHCI_PID_IN : EHCI_PID_OUT;
- qtd->int_on_complete = 1;
- qtd->next.terminate = 1;
-
- // sw region
- qhd->p_qtd_list_head = qtd;
- qhd->p_qtd_list_tail = qtd;
-
- // attach TD
- qhd->qtd_overlay.next.address = (uint32_t) qtd;
- }else
- {
- ehci_qhd_t *p_qhd = qhd_get_from_addr(dev_addr, ep_addr);
- ehci_qtd_t *p_qtd = qtd_find_free();
- TU_ASSERT(p_qtd);
-
- qtd_init(p_qtd, buffer, buflen);
- p_qtd->pid = p_qhd->pid;
-
- // Insert TD to QH
- qtd_insert_to_qhd(p_qhd, p_qtd);
-
- p_qhd->p_qtd_list_tail->int_on_complete = 1;
-
- // attach head QTD to QHD start transferring
- p_qhd->qtd_overlay.next.address = (uint32_t) p_qhd->p_qtd_list_head;
- }
-
- return true;
-}
-
-bool hcd_edpt_clear_stall(uint8_t dev_addr, uint8_t ep_addr)
-{
- ehci_qhd_t *p_qhd = qhd_get_from_addr(dev_addr, ep_addr);
- p_qhd->qtd_overlay.halted = 0;
- // TODO reset data toggle ?
- return true;
-}
-
-//--------------------------------------------------------------------+
-// EHCI Interrupt Handler
-//--------------------------------------------------------------------+
-
-// async_advance is handshake between usb stack & ehci controller.
-// This isr mean it is safe to modify previously removed queue head from async list.
-// In tinyusb, queue head is only removed when device is unplugged.
-static void async_advance_isr(uint8_t rhport)
-{
- (void) rhport;
-
- ehci_qhd_t* qhd_pool = ehci_data.qhd_pool;
- for(uint32_t i = 0; i < HCD_MAX_ENDPOINT; i++)
- {
- if ( qhd_pool[i].removing )
- {
- qhd_pool[i].removing = 0;
- qhd_pool[i].used = 0;
- }
- }
-}
-
-static void port_connect_status_change_isr(uint8_t rhport)
-{
- // NOTE There is an sequence plug->unplug->…..-> plug if device is powering with pre-plugged device
- if (ehci_data.regs->portsc_bm.current_connect_status)
- {
- hcd_port_reset(rhport);
- hcd_event_device_attach(rhport, true);
- }else // device unplugged
- {
- hcd_event_device_remove(rhport, true);
- }
-}
-
-static void qhd_xfer_complete_isr(ehci_qhd_t * p_qhd)
-{
- // free all TDs from the head td to the first active TD
- while(p_qhd->p_qtd_list_head != NULL && !p_qhd->p_qtd_list_head->active)
- {
- ehci_qtd_t * volatile qtd = (ehci_qtd_t * volatile) p_qhd->p_qtd_list_head;
- bool const is_ioc = (qtd->int_on_complete != 0);
- uint8_t const ep_addr = tu_edpt_addr(p_qhd->ep_number, qtd->pid == EHCI_PID_IN ? 1 : 0);
-
- p_qhd->total_xferred_bytes += qtd->expected_bytes - qtd->total_bytes;
-
- // TD need to be freed and removed from qhd, before invoking callback
- qtd->used = 0; // free QTD
- qtd_remove_1st_from_qhd(p_qhd);
-
- if (is_ioc)
- {
- hcd_event_xfer_complete(p_qhd->dev_addr, ep_addr, p_qhd->total_xferred_bytes, XFER_RESULT_SUCCESS, true);
- p_qhd->total_xferred_bytes = 0;
- }
- }
-}
-
-static void async_list_xfer_complete_isr(ehci_qhd_t * const async_head)
-{
- ehci_qhd_t *p_qhd = async_head;
- do
- {
- if ( !p_qhd->qtd_overlay.halted ) // halted or error is processed in error isr
- {
- qhd_xfer_complete_isr(p_qhd);
- }
- p_qhd = qhd_next(p_qhd);
- }while(p_qhd != async_head); // async list traversal, stop if loop around
-}
-
-static void period_list_xfer_complete_isr(uint8_t hostid, uint32_t interval_ms)
-{
- uint16_t max_loop = 0;
- uint32_t const period_1ms_addr = (uint32_t) get_period_head(hostid, 1u);
- ehci_link_t next_item = * get_period_head(hostid, interval_ms);
-
- // TODO abstract max loop guard for period
- while( !next_item.terminate &&
- !(interval_ms > 1 && period_1ms_addr == tu_align32(next_item.address)) &&
- max_loop < (HCD_MAX_ENDPOINT + EHCI_MAX_ITD + EHCI_MAX_SITD)*CFG_TUH_DEVICE_MAX)
- {
- switch ( next_item.type )
- {
- case EHCI_QTYPE_QHD:
- {
- ehci_qhd_t *p_qhd_int = (ehci_qhd_t *) tu_align32(next_item.address);
- if ( !p_qhd_int->qtd_overlay.halted )
- {
- qhd_xfer_complete_isr(p_qhd_int);
- }
- }
- break;
-
- case EHCI_QTYPE_ITD: // TODO support hs/fs ISO
- case EHCI_QTYPE_SITD:
- case EHCI_QTYPE_FSTN:
-
- default: break;
- }
-
- next_item = *list_next(&next_item);
- max_loop++;
- }
-}
-
-static void qhd_xfer_error_isr(ehci_qhd_t * p_qhd)
-{
- if ( (p_qhd->dev_addr != 0 && p_qhd->qtd_overlay.halted) || // addr0 cannot be protocol STALL
- qhd_has_xact_error(p_qhd) )
- {
- // current qhd has error in transaction
- xfer_result_t error_event;
-
- // no error bits are set, endpoint is halted due to STALL
- error_event = qhd_has_xact_error(p_qhd) ? XFER_RESULT_FAILED : XFER_RESULT_STALLED;
-
- p_qhd->total_xferred_bytes += p_qhd->p_qtd_list_head->expected_bytes - p_qhd->p_qtd_list_head->total_bytes;
-
-// if ( XFER_RESULT_FAILED == error_event ) TU_BREAKPOINT(); // TODO skip unplugged device
-
- p_qhd->p_qtd_list_head->used = 0; // free QTD
- qtd_remove_1st_from_qhd(p_qhd);
-
- if ( 0 == p_qhd->ep_number )
- {
- // control cannot be halted --> clear all qtd list
- p_qhd->p_qtd_list_head = NULL;
- p_qhd->p_qtd_list_tail = NULL;
-
- p_qhd->qtd_overlay.next.terminate = 1;
- p_qhd->qtd_overlay.alternate.terminate = 1;
- p_qhd->qtd_overlay.halted = 0;
-
- ehci_qtd_t *p_setup = qtd_control(p_qhd->dev_addr);
- p_setup->used = 0;
- }
-
- // call USBH callback
- hcd_event_xfer_complete(p_qhd->dev_addr, tu_edpt_addr(p_qhd->ep_number, p_qhd->pid == EHCI_PID_IN ? 1 : 0), p_qhd->total_xferred_bytes, error_event, true);
-
- p_qhd->total_xferred_bytes = 0;
- }
-}
-
-static void xfer_error_isr(uint8_t hostid)
-{
- //------------- async list -------------//
- ehci_qhd_t * const async_head = qhd_async_head(hostid);
- ehci_qhd_t *p_qhd = async_head;
- do
- {
- qhd_xfer_error_isr( p_qhd );
- p_qhd = qhd_next(p_qhd);
- }while(p_qhd != async_head); // async list traversal, stop if loop around
-
- //------------- TODO refractor period list -------------//
- uint32_t const period_1ms_addr = (uint32_t) get_period_head(hostid, 1u);
- for (uint32_t interval_ms=1; interval_ms <= FRAMELIST_SIZE; interval_ms *= 2)
- {
- ehci_link_t next_item = * get_period_head(hostid, interval_ms);
-
- // TODO abstract max loop guard for period
- while( !next_item.terminate &&
- !(interval_ms > 1 && period_1ms_addr == tu_align32(next_item.address)) )
- {
- switch ( next_item.type )
- {
- case EHCI_QTYPE_QHD:
- {
- ehci_qhd_t *p_qhd_int = (ehci_qhd_t *) tu_align32(next_item.address);
- qhd_xfer_error_isr(p_qhd_int);
- }
- break;
-
- // TODO support hs/fs ISO
- case EHCI_QTYPE_ITD:
- case EHCI_QTYPE_SITD:
- case EHCI_QTYPE_FSTN:
- default: break;
- }
-
- next_item = *list_next(&next_item);
- }
- }
-}
-
-//------------- Host Controller Driver's Interrupt Handler -------------//
-void hcd_int_handler(uint8_t rhport)
-{
- ehci_registers_t* regs = ehci_data.regs;
-
- uint32_t int_status = regs->status;
- int_status &= regs->inten;
-
- regs->status |= int_status; // Acknowledge handled interrupt
-
- if (int_status == 0) return;
-
- if (int_status & EHCI_INT_MASK_FRAMELIST_ROLLOVER)
- {
- ehci_data.uframe_number += (FRAMELIST_SIZE << 3);
- }
-
- if (int_status & EHCI_INT_MASK_PORT_CHANGE)
- {
- uint32_t port_status = regs->portsc & EHCI_PORTSC_MASK_ALL;
-
- TU_LOG_HEX(EHCI_DBG, regs->portsc);
-
- if (regs->portsc_bm.connect_status_change)
- {
- port_connect_status_change_isr(rhport);
- }
-
- regs->portsc |= port_status; // Acknowledge change bits in portsc
- }
-
- if (int_status & EHCI_INT_MASK_ERROR)
- {
- xfer_error_isr(rhport);
- }
-
- //------------- some QTD/SITD/ITD with IOC set is completed -------------//
- if (int_status & EHCI_INT_MASK_NXP_ASYNC)
- {
- async_list_xfer_complete_isr( qhd_async_head(rhport) );
- }
-
- if (int_status & EHCI_INT_MASK_NXP_PERIODIC)
- {
- for (uint32_t i=1; i <= FRAMELIST_SIZE; i *= 2)
- {
- period_list_xfer_complete_isr( rhport, i );
- }
- }
-
- //------------- There is some removed async previously -------------//
- if (int_status & EHCI_INT_MASK_ASYNC_ADVANCE) // need to place after EHCI_INT_MASK_NXP_ASYNC
- {
- async_advance_isr(rhport);
- }
-}
-
-//--------------------------------------------------------------------+
-// HELPER
-//--------------------------------------------------------------------+
-
-
-//------------- queue head helper -------------//
-static inline ehci_qhd_t* qhd_find_free (void)
-{
- for (uint32_t i=0; i<HCD_MAX_ENDPOINT; i++)
- {
- if ( !ehci_data.qhd_pool[i].used ) return &ehci_data.qhd_pool[i];
- }
-
- return NULL;
-}
-
-static inline ehci_qhd_t* qhd_next(ehci_qhd_t const * p_qhd)
-{
- return (ehci_qhd_t*) tu_align32(p_qhd->next.address);
-}
-
-static inline ehci_qhd_t* qhd_get_from_addr(uint8_t dev_addr, uint8_t ep_addr)
-{
- ehci_qhd_t* qhd_pool = ehci_data.qhd_pool;
-
- for(uint32_t i=0; i<HCD_MAX_ENDPOINT; i++)
- {
- if ( (qhd_pool[i].dev_addr == dev_addr) &&
- ep_addr == tu_edpt_addr(qhd_pool[i].ep_number, qhd_pool[i].pid) )
- {
- return &qhd_pool[i];
- }
- }
-
- return NULL;
-}
-
-//------------- TD helper -------------//
-static inline ehci_qtd_t* qtd_find_free(void)
-{
- for (uint32_t i=0; i<HCD_MAX_XFER; i++)
- {
- if ( !ehci_data.qtd_pool[i].used ) return &ehci_data.qtd_pool[i];
- }
-
- return NULL;
-}
-
-static inline ehci_qtd_t* qtd_next(ehci_qtd_t const * p_qtd )
-{
- return (ehci_qtd_t*) tu_align32(p_qtd->next.address);
-}
-
-static inline void qtd_remove_1st_from_qhd(ehci_qhd_t *p_qhd)
-{
- if (p_qhd->p_qtd_list_head == p_qhd->p_qtd_list_tail) // last TD --> make it NULL
- {
- p_qhd->p_qtd_list_head = p_qhd->p_qtd_list_tail = NULL;
- }else
- {
- p_qhd->p_qtd_list_head = qtd_next( p_qhd->p_qtd_list_head );
- }
-}
-
-static inline void qtd_insert_to_qhd(ehci_qhd_t *p_qhd, ehci_qtd_t *p_qtd_new)
-{
- if (p_qhd->p_qtd_list_head == NULL) // empty list
- {
- p_qhd->p_qtd_list_head = p_qhd->p_qtd_list_tail = p_qtd_new;
- }else
- {
- p_qhd->p_qtd_list_tail->next.address = (uint32_t) p_qtd_new;
- p_qhd->p_qtd_list_tail = p_qtd_new;
- }
-}
-
-static void qhd_init(ehci_qhd_t *p_qhd, uint8_t dev_addr, tusb_desc_endpoint_t const * ep_desc)
-{
- // address 0 is used as async head, which always on the list --> cannot be cleared (ehci halted otherwise)
- if (dev_addr != 0)
- {
- tu_memclr(p_qhd, sizeof(ehci_qhd_t));
- }
-
- hcd_devtree_info_t devtree_info;
- hcd_devtree_get_info(dev_addr, &devtree_info);
-
- uint8_t const xfer_type = ep_desc->bmAttributes.xfer;
- uint8_t const interval = ep_desc->bInterval;
-
- p_qhd->dev_addr = dev_addr;
- p_qhd->fl_inactive_next_xact = 0;
- p_qhd->ep_number = tu_edpt_number(ep_desc->bEndpointAddress);
- p_qhd->ep_speed = devtree_info.speed;
- p_qhd->data_toggle_control= (xfer_type == TUSB_XFER_CONTROL) ? 1 : 0;
- p_qhd->head_list_flag = (dev_addr == 0) ? 1 : 0; // addr0's endpoint is the static asyn list head
- p_qhd->max_packet_size = ep_desc->wMaxPacketSize.size;
- p_qhd->fl_ctrl_ep_flag = ((xfer_type == TUSB_XFER_CONTROL) && (p_qhd->ep_speed != TUSB_SPEED_HIGH)) ? 1 : 0;
- p_qhd->nak_reload = 0;
-
- // Bulk/Control -> smask = cmask = 0
- // TODO Isochronous
- if (TUSB_XFER_INTERRUPT == xfer_type)
- {
- if (TUSB_SPEED_HIGH == p_qhd->ep_speed)
- {
- TU_ASSERT( interval <= 16, );
- if ( interval < 4) // sub milisecond interval
- {
- p_qhd->interval_ms = 0;
- p_qhd->int_smask = (interval == 1) ? TU_BIN8(11111111) :
- (interval == 2) ? TU_BIN8(10101010) : TU_BIN8(01000100);
- }else
- {
- p_qhd->interval_ms = (uint8_t) tu_min16( 1 << (interval-4), 255 );
- p_qhd->int_smask = TU_BIT(interval % 8);
- }
- }else
- {
- TU_ASSERT( 0 != interval, );
- // Full/Low: 4.12.2.1 (EHCI) case 1 schedule start split at 1 us & complete split at 2,3,4 uframes
- p_qhd->int_smask = 0x01;
- p_qhd->fl_int_cmask = TU_BIN8(11100);
- p_qhd->interval_ms = interval;
- }
- }else
- {
- p_qhd->int_smask = p_qhd->fl_int_cmask = 0;
- }
-
- p_qhd->fl_hub_addr = devtree_info.hub_addr;
- p_qhd->fl_hub_port = devtree_info.hub_port;
- p_qhd->mult = 1; // TODO not use high bandwidth/park mode yet
-
- //------------- HCD Management Data -------------//
- p_qhd->used = 1;
- p_qhd->removing = 0;
- p_qhd->p_qtd_list_head = NULL;
- p_qhd->p_qtd_list_tail = NULL;
- p_qhd->pid = tu_edpt_dir(ep_desc->bEndpointAddress) ? EHCI_PID_IN : EHCI_PID_OUT; // PID for TD under this endpoint
-
- //------------- active, but no TD list -------------//
- p_qhd->qtd_overlay.halted = 0;
- p_qhd->qtd_overlay.next.terminate = 1;
- p_qhd->qtd_overlay.alternate.terminate = 1;
- if (TUSB_XFER_BULK == xfer_type && p_qhd->ep_speed == TUSB_SPEED_HIGH && p_qhd->pid == EHCI_PID_OUT)
- {
- p_qhd->qtd_overlay.ping_err = 1; // do PING for Highspeed Bulk OUT, EHCI section 4.11
- }
-}
-
-static void qtd_init(ehci_qtd_t* p_qtd, void* buffer, uint16_t total_bytes)
-{
- tu_memclr(p_qtd, sizeof(ehci_qtd_t));
-
- p_qtd->used = 1;
-
- p_qtd->next.terminate = 1; // init to null
- p_qtd->alternate.terminate = 1; // not used, always set to terminated
- p_qtd->active = 1;
- p_qtd->err_count = 3; // TODO 3 consecutive errors tolerance
- p_qtd->data_toggle = 0;
- p_qtd->total_bytes = total_bytes;
- p_qtd->expected_bytes = total_bytes;
-
- p_qtd->buffer[0] = (uint32_t) buffer;
- for(uint8_t i=1; i<5; i++)
- {
- p_qtd->buffer[i] |= tu_align4k( p_qtd->buffer[i-1] ) + 4096;
- }
-}
-
-//------------- List Managing Helper -------------//
-static inline void list_insert(ehci_link_t *current, ehci_link_t *new, uint8_t new_type)
-{
- new->address = current->address;
- current->address = ((uint32_t) new) | (new_type << 1);
-}
-
-static inline ehci_link_t* list_next(ehci_link_t *p_link_pointer)
-{
- return (ehci_link_t*) tu_align32(p_link_pointer->address);
-}
-
-#endif
diff --git a/tinyusb/src/portable/ehci/ehci.h b/tinyusb/src/portable/ehci/ehci.h
deleted file mode 100755
index c2bee67a..00000000
--- a/tinyusb/src/portable/ehci/ehci.h
+++ /dev/null
@@ -1,420 +0,0 @@
-/*
- * The MIT License (MIT)
- *
- * Copyright (c) 2019 Ha Thach (tinyusb.org)
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- *
- * This file is part of the TinyUSB stack.
- */
-
-#ifndef _TUSB_EHCI_H_
-#define _TUSB_EHCI_H_
-
-
-/* Abbreviation
- * HC: Host Controller
- * HCD: Host Controller Driver
- * QHD: Queue Head for non-ISO transfer
- * QTD: Queue Transfer Descriptor for non-ISO transfer
- * ITD: Iso Transfer Descriptor for highspeed
- * SITD: Split ISO Transfer Descriptor for full-speed
- * SMASK: Start Split mask for Slipt Transaction
- * CMASK: Complete Split mask for Slipt Transaction
-*/
-
-#ifdef __cplusplus
- extern "C" {
-#endif
-
-//--------------------------------------------------------------------+
-// EHCI CONFIGURATION & CONSTANTS
-//--------------------------------------------------------------------+
-
-// TODO merge OHCI with EHCI
-enum {
- EHCI_MAX_ITD = 4,
- EHCI_MAX_SITD = 16
-};
-
-//--------------------------------------------------------------------+
-// EHCI Data Structure
-//--------------------------------------------------------------------+
-enum
-{
- EHCI_QTYPE_ITD = 0 ,
- EHCI_QTYPE_QHD ,
- EHCI_QTYPE_SITD ,
- EHCI_QTYPE_FSTN
-};
-
-/// EHCI PID
-enum
-{
- EHCI_PID_OUT = 0 ,
- EHCI_PID_IN ,
- EHCI_PID_SETUP
-};
-
-/// Link pointer
-typedef union {
- uint32_t address;
- struct {
- uint32_t terminate : 1;
- uint32_t type : 2;
- };
-}ehci_link_t;
-
-/// Queue Element Transfer Descriptor
-/// Qtd is used to declare overlay in ehci_qhd_t -> cannot be declared with TU_ATTR_ALIGNED(32)
-typedef struct
-{
- // Word 0: Next QTD Pointer
- ehci_link_t next;
-
- // Word 1: Alternate Next QTD Pointer (not used)
- union{
- ehci_link_t alternate;
- struct {
- uint32_t : 5;
- uint32_t used : 1;
- uint32_t : 10;
- uint32_t expected_bytes : 16;
- };
- };
-
- // Word 2: qTQ Token
- volatile uint32_t ping_err : 1 ; ///< For Highspeed: 0 Out, 1 Ping. Full/Slow used as error indicator
- volatile uint32_t non_hs_split_state : 1 ; ///< Used by HC to track the state of slipt transaction
- volatile uint32_t non_hs_missed_uframe : 1 ; ///< HC misses a complete slip transaction
- volatile uint32_t xact_err : 1 ; ///< Error (Timeout, CRC, Bad PID ... )
- volatile uint32_t babble_err : 1 ; ///< Babble detected, also set Halted bit to 1
- volatile uint32_t buffer_err : 1 ; ///< Data overrun/underrun error
- volatile uint32_t halted : 1 ; ///< Serious error or STALL received
- volatile uint32_t active : 1 ; ///< Start transfer, clear by HC when complete
-
- uint32_t pid : 2 ; ///< 0: OUT, 1: IN, 2 Setup
- volatile uint32_t err_count : 2 ; ///< Error Counter of consecutive errors
- volatile uint32_t current_page : 3 ; ///< Index into the qTD buffer pointer list
- uint32_t int_on_complete : 1 ; ///< Interrupt on complete
- volatile uint32_t total_bytes : 15 ; ///< Transfer bytes, decreased during transaction
- volatile uint32_t data_toggle : 1 ; ///< Data Toogle bit
-
-
- /// Buffer Page Pointer List, Each element in the list is a 4K page aligned, physical memory address. The lower 12 bits in each pointer are reserved (except for the first one) as each memory pointer must reference the start of a 4K page
- uint32_t buffer[5];
-} ehci_qtd_t;
-
-TU_VERIFY_STATIC( sizeof(ehci_qtd_t) == 32, "size is not correct" );
-
-/// Queue Head
-typedef struct TU_ATTR_ALIGNED(32)
-{
- // Word 0: Next QHD
- ehci_link_t next;
-
- // Word 1: Endpoint Characteristics
- uint32_t dev_addr : 7 ; ///< device address
- uint32_t fl_inactive_next_xact : 1 ; ///< Only valid for Periodic with Full/Slow speed
- uint32_t ep_number : 4 ; ///< EP number
- uint32_t ep_speed : 2 ; ///< 0: Full, 1: Low, 2: High
- uint32_t data_toggle_control : 1 ; ///< 0: use DT in qHD, 1: use DT in qTD
- uint32_t head_list_flag : 1 ; ///< Head of the queue
- uint32_t max_packet_size : 11 ; ///< Max packet size
- uint32_t fl_ctrl_ep_flag : 1 ; ///< 1 if is Full/Low speed control endpoint
- uint32_t nak_reload : 4 ; ///< Used by HC
-
- // Word 2: Endpoint Capabilities
- uint32_t int_smask : 8 ; ///< Interrupt Schedule Mask
- uint32_t fl_int_cmask : 8 ; ///< Split Completion Mask for Full/Slow speed
- uint32_t fl_hub_addr : 7 ; ///< Hub Address for Full/Slow speed
- uint32_t fl_hub_port : 7 ; ///< Hub Port for Full/Slow speed
- uint32_t mult : 2 ; ///< Transaction per micro frame
-
- // Word 3: Current qTD Pointer
- volatile uint32_t qtd_addr;
-
- // Word 4-11: Transfer Overlay
- volatile ehci_qtd_t qtd_overlay;
-
- //--------------------------------------------------------------------+
- /// Due to the fact QHD is 32 bytes aligned but occupies only 48 bytes
- /// thus there are 16 bytes padding free that we can make use of.
- //--------------------------------------------------------------------+
- uint8_t used;
- uint8_t removing; // removed from asyn list, waiting for async advance
- uint8_t pid;
- uint8_t interval_ms; // polling interval in frames (or milisecond)
-
- uint16_t total_xferred_bytes; // number of bytes xferred until a qtd with ioc bit set
- uint8_t reserved2[2];
-
- ehci_qtd_t * volatile p_qtd_list_head; // head of the scheduled TD list
- ehci_qtd_t * volatile p_qtd_list_tail; // tail of the scheduled TD list
-} ehci_qhd_t;
-
-TU_VERIFY_STATIC( sizeof(ehci_qhd_t) == 64, "size is not correct" );
-
-/// Highspeed Isochronous Transfer Descriptor (section 3.3)
-typedef struct TU_ATTR_ALIGNED(32) {
- // Word 0: Next Link Pointer
- ehci_link_t next;
-
- // Word 1-8: iTD Transaction Status and Control List
- struct {
- // iTD Control
- volatile uint32_t offset : 12 ; ///< This field is a value that is an offset, expressed in bytes, from the beginning of a buffer.
- volatile uint32_t page_select : 3 ; ///< These bits are set by software to indicate which of the buffer page pointers the offset field in this slot should be concatenated to produce the starting memory address for this transaction. The valid range of values for this field is 0 to 6
- uint32_t int_on_complete : 1 ; ///< If this bit is set to a one, it specifies that when this transaction completes, the Host Controller should issue an interrupt at the next interrupt threshold
- volatile uint32_t length : 12 ; ///< For an OUT, this field is the number of data bytes the host controller will send during the transaction. The host controller is not required to update this field to reflect the actual number of bytes transferred during the transfer
- ///< For an IN, the initial value of the field is the number of bytes the host expects the endpoint to deliver. During the status update, the host controller writes back the number of bytes successfully received. The value in this register is the actual byte count
- // iTD Status
- volatile uint32_t error : 1 ; ///< Set to a one by the Host Controller during status update in the case where the host did not receive a valid response from the device (Timeout, CRC, Bad PID, etc.). This bit may only be set for isochronous IN transactions.
- volatile uint32_t babble_err : 1 ; ///< Set to a 1 by the Host Controller during status update when a babble is detected during the transaction
- volatile uint32_t buffer_err : 1 ; ///< Set to a 1 by the Host Controller during status update to indicate that the Host Controller is unable to keep up with the reception of incoming data (overrun) or is unable to supply data fast enough during transmission (underrun).
- volatile uint32_t active : 1 ; ///< Set to 1 by software to enable the execution of an isochronous transaction by the Host Controller
- } xact[8];
-
- // Word 9-15 Buffer Page Pointer List (Plus)
- uint32_t BufferPointer[7];
-
-// // FIXME: Store meta data into buffer pointer reserved for saving memory
-// /*---------- HCD Area ----------*/
-// uint32_t used;
-// uint32_t IhdIdx;
-// uint32_t reserved[6];
-} ehci_itd_t;
-
-TU_VERIFY_STATIC( sizeof(ehci_itd_t) == 64, "size is not correct" );
-
-/// Split (Full-Speed) Isochronous Transfer Descriptor
-typedef struct TU_ATTR_ALIGNED(32)
-{
- // Word 0: Next Link Pointer
- ehci_link_t next;
-
- // Word 1: siTD Endpoint Characteristics
- uint32_t dev_addr : 7; ///< This field selects the specific device serving as the data source or sink.
- uint32_t : 1; ///< reserved
- uint32_t ep_number : 4; ///< This 4-bit field selects the particular endpoint number on the device serving as the data source or sink.
- uint32_t : 4; ///< This field is reserved and should be set to zero.
- uint32_t hub_addr : 7; ///< This field holds the device address of the transaction translators’ hub.
- uint32_t : 1; ///< reserved
- uint32_t port_number : 7; ///< This field is the port number of the recipient transaction translator.
- uint32_t direction : 1; ///< 0 = OUT; 1 = IN. This field encodes whether the full-speed transaction should be an IN or OUT.
-
- // Word 2: Micro-frame Schedule Control
- uint8_t int_smask ; ///< This field (along with the Activeand SplitX-statefields in the Statusbyte) are used to determine during which micro-frames the host controller should execute complete-split transactions
- uint8_t fl_int_cmask; ///< This field (along with the Activeand SplitX-statefields in the Statusbyte) are used to determine during which micro-frames the host controller should execute start-split transactions.
- uint16_t reserved ; ///< reserved
-
- // Word 3: siTD Transfer Status and Control
- // Status [7:0] TODO indentical to qTD Token'status --> refractor later
- volatile uint32_t : 1 ; // reserved
- volatile uint32_t split_state : 1 ;
- volatile uint32_t missed_uframe : 1 ;
- volatile uint32_t xact_err : 1 ;
- volatile uint32_t babble_err : 1 ;
- volatile uint32_t buffer_err : 1 ;
- volatile uint32_t error : 1 ;
- volatile uint32_t active : 1 ;
- // Micro-frame Schedule Control
- volatile uint32_t cmask_progress : 8 ; ///< This field is used by the host controller to record which split-completes have been executed. See Section 4.12.3.3.2 for behavioral requirements.
- volatile uint32_t total_bytes : 10 ; ///< This field is initialized by software to the total number of bytes expected in this transfer. Maximum value is 1023
- volatile uint32_t : 4 ; ///< reserved
- volatile uint32_t page_select : 1 ; ///< Used to indicate which data page pointer should be concatenated with the CurrentOffsetfield to construct a data buffer pointer
- uint32_t int_on_complete : 1 ; ///< Do not interrupt when transaction is complete. 1 = Do interrupt when transaction is complete
- uint32_t : 0 ; // padding to the end of current storage unit
-
- /// Word 4-5: Buffer Pointer List
- uint32_t buffer[2]; // buffer[1] TP: Transaction Position - T-Count: Transaction Count
-
-// union{
-// uint32_t BufferPointer1;
-// struct {
-// volatile uint32_t TCount : 3;
-// volatile uint32_t TPosition : 2;
-// };
-// };
-
- /*---------- Word 6 ----------*/
- ehci_link_t back;
-
- /// SITD is 32-byte aligned but occupies only 28 --> 4 bytes for storing extra data
- uint8_t used;
- uint8_t ihd_idx;
- uint8_t reserved2[2];
-} ehci_sitd_t;
-
-TU_VERIFY_STATIC( sizeof(ehci_sitd_t) == 32, "size is not correct" );
-
-//--------------------------------------------------------------------+
-// EHCI Operational Register
-//--------------------------------------------------------------------+
-enum ehci_interrupt_mask_{
- EHCI_INT_MASK_USB = TU_BIT(0),
- EHCI_INT_MASK_ERROR = TU_BIT(1),
- EHCI_INT_MASK_PORT_CHANGE = TU_BIT(2),
-
- EHCI_INT_MASK_FRAMELIST_ROLLOVER = TU_BIT(3),
- EHCI_INT_MASK_PCI_HOST_SYSTEM_ERROR = TU_BIT(4),
- EHCI_INT_MASK_ASYNC_ADVANCE = TU_BIT(5),
- EHCI_INT_MASK_NXP_SOF = TU_BIT(7),
-
- EHCI_INT_MASK_NXP_ASYNC = TU_BIT(18),
- EHCI_INT_MASK_NXP_PERIODIC = TU_BIT(19),
-
- EHCI_INT_MASK_ALL =
- EHCI_INT_MASK_USB | EHCI_INT_MASK_ERROR | EHCI_INT_MASK_PORT_CHANGE |
- EHCI_INT_MASK_FRAMELIST_ROLLOVER | EHCI_INT_MASK_PCI_HOST_SYSTEM_ERROR |
- EHCI_INT_MASK_ASYNC_ADVANCE | EHCI_INT_MASK_NXP_SOF |
- EHCI_INT_MASK_NXP_ASYNC | EHCI_INT_MASK_NXP_PERIODIC
-};
-
-enum ehci_usbcmd_pos_ {
- EHCI_USBCMD_POS_RUN_STOP = 0,
- EHCI_USBCMD_POS_FRAMELIST_SIZE = 2,
- EHCI_USBCMD_POS_PERIOD_ENABLE = 4,
- EHCI_USBCMD_POS_ASYNC_ENABLE = 5,
- EHCI_USBCMD_POS_NXP_FRAMELIST_SIZE_MSB = 15,
- EHCI_USBCMD_POS_INTERRUPT_THRESHOLD = 16
-};
-
-enum ehci_portsc_change_mask_{
- EHCI_PORTSC_MASK_CURRENT_CONNECT_STATUS = TU_BIT(0),
- EHCI_PORTSC_MASK_CONNECT_STATUS_CHANGE = TU_BIT(1),
- EHCI_PORTSC_MASK_PORT_EANBLED = TU_BIT(2),
- EHCI_PORTSC_MASK_PORT_ENABLE_CHAGNE = TU_BIT(3),
- EHCI_PORTSC_MASK_OVER_CURRENT_CHANGE = TU_BIT(5),
- EHCI_PORTSC_MASK_PORT_RESET = TU_BIT(8),
-
- EHCI_PORTSC_MASK_ALL =
- EHCI_PORTSC_MASK_CONNECT_STATUS_CHANGE |
- EHCI_PORTSC_MASK_PORT_ENABLE_CHAGNE |
- EHCI_PORTSC_MASK_OVER_CURRENT_CHANGE
-};
-
-typedef volatile struct
-{
- union {
- uint32_t command;
-
- struct {
- uint32_t run_stop : 1 ; ///< 1=Run. 0=Stop
- uint32_t reset : 1 ; ///< SW write 1 to reset HC, clear by HC when complete
- uint32_t framelist_size : 2 ; ///< Frame List size 0: 1024, 1: 512, 2: 256
- uint32_t periodic_enable : 1 ; ///< This bit controls whether the host controller skips processing the Periodic Schedule. Values mean: 0b Do not process the Periodic Schedule 1b Use the PERIODICLISTBASE register to access the Periodic Schedule.
- uint32_t async_enable : 1 ; ///< This bit controls whether the host controller skips processing the Asynchronous Schedule. Values mean: 0b Do not process the Asynchronous Schedule 1b Use the ASYNCLISTADDR register to access the Asynchronous Schedule.
- uint32_t async_adv_doorbell : 1 ; ///< Tell HC to interrupt next time it advances async list. Clear by HC
- uint32_t light_reset : 1 ; ///< Reset HC without affecting ports state
- uint32_t async_park_count : 2 ; ///< not used by tinyusb
- uint32_t : 1 ;
- uint32_t async_park_enable : 1 ; ///< Enable park mode, not used by tinyusb
- uint32_t : 3 ;
- uint32_t nxp_framelist_size_msb : 1 ; ///< NXP customized : Bit 2 of the Frame List Size bits \n 011b: 128 elements \n 100b: 64 elements \n 101b: 32 elements \n 110b: 16 elements \n 111b: 8 elements
- uint32_t int_threshold : 8 ; ///< Default 08h. Interrupt rate in unit of micro frame
- }command_bm;
- };
-
- union {
- uint32_t status;
-
- struct {
- uint32_t usb : 1 ; ///< qTD with IOC is retired
- uint32_t usb_error : 1 ; ///< qTD retired due to error
- uint32_t port_change_detect : 1 ; ///< Set when PortOwner or ForcePortResume change from 0 -> 1
- uint32_t framelist_rollover : 1 ; ///< R/WC The Host Controller sets this bit to a one when the Frame List Index(see Section 2.3.4) rolls over from its maximum value to zero. The exact value at which the rollover occurs depends on the frame list size. For example, if the frame list size (as programmed in the Frame List Sizefield of the USBCMD register) is 1024, the Frame Index Registerrolls over every time FRINDEX[13] toggles. Similarly, if the size is 512, the Host Controller sets this bit to a one every time FRINDEX[12] toggles.
- uint32_t pci_host_system_error : 1 ; ///< R/WC (not used by NXP) The Host Controller sets this bit to 1 when a serious error occurs during a host system access involving the Host Controller module. In a PCI system, conditions that set this bit to 1 include PCI Parity error, PCI Master Abort, and PCI Target Abort. When this error occurs, the Host Controller clears the Run/Stop bit in the Command register to prevent further execution of the scheduled TDs.
- uint32_t async_adv : 1 ; ///< Async Advance interrupt
- uint32_t : 1 ;
- uint32_t nxp_int_sof : 1 ; ///< NXP customized: this bit will be set every 125us and can be used by host controller driver as a time base.
- uint32_t : 4 ;
- uint32_t hc_halted : 1 ; ///< Opposite value to run_stop bit.
- uint32_t reclamation : 1 ; ///< Used to detect empty async shecudle
- uint32_t periodic_status : 1 ; ///< Periodic schedule status
- uint32_t async_status : 1 ; ///< Async schedule status
- uint32_t : 2 ;
- uint32_t nxp_int_async : 1 ; ///< NXP customized: This bit is set by the Host Controller when the cause of an interrupt is a completion of a USB transaction where the Transfer Descriptor (TD) has an interrupt on complete (IOC) bit set andthe TD was from the asynchronous schedule. This bit is also set by the Host when a short packet is detected andthe packet is on the asynchronous schedule.
- uint32_t nxp_int_period : 1 ; ///< NXP customized: This bit is set by the Host Controller when the cause of an interrupt is a completion of a USB transaction where the Transfer Descriptor (TD) has an interrupt on complete (IOC) bit set andthe TD was from the periodic schedule.
- uint32_t : 12 ;
- }status_bm;
- };
-
- union{
- uint32_t inten;
-
- struct {
- uint32_t usb : 1 ;
- uint32_t usb_error : 1 ;
- uint32_t port_change_detect : 1 ;
- uint32_t framelist_rollover : 1 ;
- uint32_t pci_host_system_error : 1 ;
- uint32_t async_adv : 1 ;
- uint32_t : 1 ;
- uint32_t nxp_int_sof : 1 ;
- uint32_t : 10 ;
- uint32_t nxp_int_async : 1 ;
- uint32_t nxp_int_period : 1 ;
- uint32_t : 12 ;
- }inten_bm;
- };
-
- uint32_t frame_index ; ///< Micro frame counter
- uint32_t ctrl_ds_seg ; ///< Control Data Structure Segment
- uint32_t periodic_list_base ; ///< Beginning address of perodic frame list
- uint32_t async_list_addr ; ///< Address of next async QHD to be executed
- uint32_t nxp_tt_control ; ///< nxp embedded transaction translator (reserved by EHCI specs)
- uint32_t reserved[8] ;
- uint32_t config_flag ; ///< not used by NXP
-
- union {
- uint32_t portsc ; ///< port status and control
- struct {
- uint32_t current_connect_status : 1; ///< 0: No device, 1: Device is present on port
- uint32_t connect_status_change : 1; ///< Change in Current Connect Status
- uint32_t port_enabled : 1; ///< Ports can only be enabled by HC as a part of the reset and enable. SW can write 0 to disable
- uint32_t port_enable_change : 1; ///< Port Enabled has changed
- uint32_t over_current_active : 1; ///< Port has an over-current condition
- uint32_t over_current_change : 1; ///< Change to Over-current Active
- uint32_t force_port_resume : 1; ///< Resume detected/driven on port. This functionality defined for manipulating this bit depends on the value of the Suspend bit.
- uint32_t suspend : 1; ///< Port in suspend state
- uint32_t port_reset : 1; ///< 1=Port is in Reset. 0=Port is not in Reset
- uint32_t nxp_highspeed_status : 1; ///< NXP customized: 0=connected to the port is not in High-speed mode, 1=connected to the port is in High-speed mode
- uint32_t line_status : 2; ///< D+/D- state: 00: SE0, 10: J-state, 01: K-state
- uint32_t port_power : 1; ///< 0= power off, 1= power on
- uint32_t port_owner : 1; ///< not used by NXP
- uint32_t port_indicator_control : 2; ///< 00b: off, 01b: Amber, 10b: green, 11b: undefined
- uint32_t port_test_control : 4; ///< Port test mode, not used by tinyusb
- uint32_t wake_on_connect_enable : 1; ///< Enables device connects as wake-up events
- uint32_t wake_on_disconnect_enable : 1; ///< Enables device disconnects as wake-up events
- uint32_t wake_on_over_current_enable : 1; ///< Enables over-current conditions as wake-up events
- uint32_t nxp_phy_clock_disable : 1; ///< NXP customized: the PHY can be put into Low Power Suspend – Clock Disable when the downstream device has been put into suspend mode or when no downstream device is connected. Low power suspend is completely under the control of software. 0: enable PHY clock, 1: disable PHY clock
- uint32_t nxp_port_force_fullspeed : 1; ///< NXP customized: Writing this bit to a 1 will force the port to only connect at Full Speed. It disables the chirp sequence that allowsthe port to identify itself as High Speed. This is useful for testing FS configurations with a HS host, hub or device.
- uint32_t TU_RESERVED : 1;
- uint32_t nxp_port_speed : 2; ///< NXP customized: This register field indicates the speed atwhich the port is operating. For HS mode operation in the host controllerand HS/FS operation in the device controller the port routing steers data to the Protocol engine. For FS and LS mode operation in the host controller, the port routing steers data to the Protocol Engine w/ Embedded Transaction Translator. 0x0: Fullspeed, 0x1: Lowspeed, 0x2: Highspeed
- uint32_t TU_RESERVED : 4;
- }portsc_bm;
- };
-}ehci_registers_t;
-
-#ifdef __cplusplus
- }
-#endif
-
-#endif /* _TUSB_EHCI_H_ */
diff --git a/tinyusb/src/portable/ehci/ehci_api.h b/tinyusb/src/portable/ehci/ehci_api.h
deleted file mode 100755
index 12e0a73d..00000000
--- a/tinyusb/src/portable/ehci/ehci_api.h
+++ /dev/null
@@ -1,45 +0,0 @@
-/*
- * The MIT License (MIT)
- *
- * Copyright (c) 2021, Ha Thach (tinyusb.org)
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- *
- * This file is part of the TinyUSB stack.
- */
-
-#ifndef _TUSB_EHCI_API_H_
-#define _TUSB_EHCI_API_H_
-
-#ifdef __cplusplus
- extern "C" {
-#endif
-
-//--------------------------------------------------------------------+
-// API Implemented by EHCI
-//--------------------------------------------------------------------+
-
-// Initialize EHCI driver
-bool ehci_init(uint8_t rhport, uint32_t capability_reg, uint32_t operatial_reg);
-
-#ifdef __cplusplus
- }
-#endif
-
-#endif
diff --git a/tinyusb/src/portable/espressif/esp32sx/dcd_esp32sx.c b/tinyusb/src/portable/espressif/esp32sx/dcd_esp32sx.c
deleted file mode 100755
index d728487c..00000000
--- a/tinyusb/src/portable/espressif/esp32sx/dcd_esp32sx.c
+++ /dev/null
@@ -1,867 +0,0 @@
-/*
- * The MIT License (MIT)
- *
- * Copyright (c) 2018 Scott Shawcroft, 2019 William D. Jones for Adafruit Industries
- * Copyright (c) 2019 Ha Thach (tinyusb.org)
- * Additions Copyright (c) 2020, Espressif Systems (Shanghai) Co. Ltd.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- *
- * This file is part of the TinyUSB stack.
- */
-
-#include "tusb_option.h"
-
-#if (((CFG_TUSB_MCU == OPT_MCU_ESP32S2) || (CFG_TUSB_MCU == OPT_MCU_ESP32S3)) && TUSB_OPT_DEVICE_ENABLED)
-
-// Espressif
-#include "driver/periph_ctrl.h"
-#include "freertos/xtensa_api.h"
-#include "esp_intr_alloc.h"
-#include "esp_log.h"
-#include "driver/gpio.h"
-#include "soc/dport_reg.h"
-#include "soc/gpio_sig_map.h"
-#include "soc/usb_periph.h"
-
-#include "device/dcd.h"
-
-// Since TinyUSB doesn't use SOF for now, and this interrupt too often (1ms interval)
-// We disable SOF for now until needed later on
-#define USE_SOF 0
-
-// Max number of bi-directional endpoints including EP0
-// Note: ESP32S2 specs say there are only up to 5 IN active endpoints include EP0
-// We should probably prohibit enabling Endpoint IN > 4 (not done yet)
-#define EP_MAX USB_OUT_EP_NUM
-
-// FIFO size in bytes
-#define EP_FIFO_SIZE 1024
-
-// Max number of IN EP FIFOs
-#define EP_FIFO_NUM 5
-
-typedef struct {
- uint8_t *buffer;
- // tu_fifo_t * ff; // TODO support dcd_edpt_xfer_fifo API
- uint16_t total_len;
- uint16_t queued_len;
- uint16_t max_size;
- bool short_packet;
-} xfer_ctl_t;
-
-static const char *TAG = "TUSB:DCD";
-static intr_handle_t usb_ih;
-
-
-static uint32_t _setup_packet[2];
-
-#define XFER_CTL_BASE(_ep, _dir) &xfer_status[_ep][_dir]
-static xfer_ctl_t xfer_status[EP_MAX][2];
-
-// Keep count of how many FIFOs are in use
-static uint8_t _allocated_fifos = 1; //FIFO0 is always in use
-
-// Will either return an unused FIFO number, or 0 if all are used.
-static uint8_t get_free_fifo(void)
-{
- if (_allocated_fifos < EP_FIFO_NUM) return _allocated_fifos++;
- return 0;
-}
-
-// Setup the control endpoint 0.
-static void bus_reset(void)
-{
- for (int ep_num = 0; ep_num < USB_OUT_EP_NUM; ep_num++) {
- USB0.out_ep_reg[ep_num].doepctl |= USB_DO_SNAK0_M; // DOEPCTL0_SNAK
- }
-
- USB0.dcfg &= ~USB_DEVADDR_M; // reset address
-
- USB0.daintmsk |= USB_OUTEPMSK0_M | USB_INEPMSK0_M;
- USB0.doepmsk |= USB_SETUPMSK_M | USB_XFERCOMPLMSK;
- USB0.diepmsk |= USB_TIMEOUTMSK_M | USB_DI_XFERCOMPLMSK_M /*| USB_INTKNTXFEMPMSK_M*/;
-
- // "USB Data FIFOs" section in reference manual
- // Peripheral FIFO architecture
- //
- // --------------- 320 or 1024 ( 1280 or 4096 bytes )
- // | IN FIFO MAX |
- // ---------------
- // | ... |
- // --------------- y + x + 16 + GRXFSIZ
- // | IN FIFO 2 |
- // --------------- x + 16 + GRXFSIZ
- // | IN FIFO 1 |
- // --------------- 16 + GRXFSIZ
- // | IN FIFO 0 |
- // --------------- GRXFSIZ
- // | OUT FIFO |
- // | ( Shared ) |
- // --------------- 0
- //
- // According to "FIFO RAM allocation" section in RM, FIFO RAM are allocated as follows (each word 32-bits):
- // - Each EP IN needs at least max packet size, 16 words is sufficient for EP0 IN
- //
- // - All EP OUT shared a unique OUT FIFO which uses
- // * 10 locations in hardware for setup packets + setup control words (up to 3 setup packets).
- // * 2 locations for OUT endpoint control words.
- // * 16 for largest packet size of 64 bytes. ( TODO Highspeed is 512 bytes)
- // * 1 location for global NAK (not required/used here).
- // * It is recommended to allocate 2 times the largest packet size, therefore
- // Recommended value = 10 + 1 + 2 x (16+2) = 47 --> Let's make it 52
- USB0.grstctl |= 0x10 << USB_TXFNUM_S; // fifo 0x10,
- USB0.grstctl |= USB_TXFFLSH_M; // Flush fifo
- USB0.grxfsiz = 52;
-
- // Control IN uses FIFO 0 with 64 bytes ( 16 32-bit word )
- USB0.gnptxfsiz = (16 << USB_NPTXFDEP_S) | (USB0.grxfsiz & 0x0000ffffUL);
-
- // Ready to receive SETUP packet
- USB0.out_ep_reg[0].doeptsiz |= USB_SUPCNT0_M;
-
- USB0.gintmsk |= USB_IEPINTMSK_M | USB_OEPINTMSK_M;
-}
-
-static void enum_done_processing(void)
-{
- ESP_EARLY_LOGV(TAG, "dcd_int_handler - Speed enumeration done! Sending DCD_EVENT_BUS_RESET then");
- // On current silicon on the Full Speed core, speed is fixed to Full Speed.
- // However, keep for debugging and in case Low Speed is ever supported.
- uint32_t enum_spd = (USB0.dsts >> USB_ENUMSPD_S) & (USB_ENUMSPD_V);
-
- // Maximum packet size for EP 0 is set for both directions by writing DIEPCTL
- if (enum_spd == 0x03) { // Full-Speed (PHY on 48 MHz)
- USB0.in_ep_reg[0].diepctl &= ~USB_D_MPS0_V; // 64 bytes
- USB0.in_ep_reg[0].diepctl &= ~USB_D_STALL0_M; // clear Stall
- xfer_status[0][TUSB_DIR_OUT].max_size = 64;
- xfer_status[0][TUSB_DIR_IN].max_size = 64;
- } else {
- USB0.in_ep_reg[0].diepctl |= USB_D_MPS0_V; // 8 bytes
- USB0.in_ep_reg[0].diepctl &= ~USB_D_STALL0_M; // clear Stall
- xfer_status[0][TUSB_DIR_OUT].max_size = 8;
- xfer_status[0][TUSB_DIR_IN].max_size = 8;
- }
-}
-
-
-/*------------------------------------------------------------------*/
-/* Controller API
- *------------------------------------------------------------------*/
-void dcd_init(uint8_t rhport)
-{
- ESP_LOGV(TAG, "DCD init - Start");
-
- // A. Disconnect
- ESP_LOGV(TAG, "DCD init - Soft DISCONNECT and Setting up");
- USB0.dctl |= USB_SFTDISCON_M; // Soft disconnect
-
- // B. Programming DCFG
- /* If USB host misbehaves during status portion of control xfer
- (non zero-length packet), send STALL back and discard. Full speed. */
- USB0.dcfg |= USB_NZSTSOUTHSHK_M | // NonZero .... STALL
- (3 << 0); // dev speed: fullspeed 1.1 on 48 mhz // TODO no value in usb_reg.h (IDF-1476)
-
- USB0.gahbcfg |= USB_NPTXFEMPLVL_M | USB_GLBLLNTRMSK_M; // Global interruptions ON
- USB0.gusbcfg |= USB_FORCEDEVMODE_M; // force devmode
- USB0.gotgctl &= ~(USB_BVALIDOVVAL_M | USB_BVALIDOVEN_M | USB_VBVALIDOVVAL_M); //no overrides
-
- // C. Setting SNAKs, then connect
- for (int n = 0; n < USB_OUT_EP_NUM; n++) {
- USB0.out_ep_reg[n].doepctl |= USB_DO_SNAK0_M; // DOEPCTL0_SNAK
- }
-
- // D. Interruption masking
- USB0.gintmsk = 0; //mask all
- USB0.gotgint = ~0U; //clear OTG ints
- USB0.gintsts = ~0U; //clear pending ints
- USB0.gintmsk = USB_OTGINTMSK_M |
- USB_MODEMISMSK_M |
- #if USE_SOF
- USB_SOFMSK_M |
- #endif
- USB_RXFLVIMSK_M |
- USB_ERLYSUSPMSK_M |
- USB_USBSUSPMSK_M |
- USB_USBRSTMSK_M |
- USB_ENUMDONEMSK_M |
- USB_RESETDETMSK_M |
- USB_DISCONNINTMSK_M; // host most only
-
- dcd_connect(rhport);
-}
-
-void dcd_set_address(uint8_t rhport, uint8_t dev_addr)
-{
- (void)rhport;
- ESP_LOGV(TAG, "DCD init - Set address : %u", dev_addr);
- USB0.dcfg |= ((dev_addr & USB_DEVADDR_V) << USB_DEVADDR_S);
- // Response with status after changing device address
- dcd_edpt_xfer(rhport, tu_edpt_addr(0, TUSB_DIR_IN), NULL, 0);
-}
-
-void dcd_remote_wakeup(uint8_t rhport)
-{
- (void)rhport;
-
- // TODO must manually clear this bit after 1-15 ms
- // USB0.DCTL |= USB_RMTWKUPSIG_M;
-}
-
-// connect by enabling internal pull-up resistor on D+/D-
-void dcd_connect(uint8_t rhport)
-{
- (void) rhport;
- USB0.dctl &= ~USB_SFTDISCON_M;
-}
-
-// disconnect by disabling internal pull-up resistor on D+/D-
-void dcd_disconnect(uint8_t rhport)
-{
- (void) rhport;
- USB0.dctl |= USB_SFTDISCON_M;
-}
-
-/*------------------------------------------------------------------*/
-/* DCD Endpoint port
- *------------------------------------------------------------------*/
-
-bool dcd_edpt_open(uint8_t rhport, tusb_desc_endpoint_t const *desc_edpt)
-{
- ESP_LOGV(TAG, "DCD endpoint opened");
- (void)rhport;
-
- usb_out_endpoint_t *out_ep = &(USB0.out_ep_reg[0]);
- usb_in_endpoint_t *in_ep = &(USB0.in_ep_reg[0]);
-
- uint8_t const epnum = tu_edpt_number(desc_edpt->bEndpointAddress);
- uint8_t const dir = tu_edpt_dir(desc_edpt->bEndpointAddress);
-
- TU_ASSERT(desc_edpt->wMaxPacketSize.size <= 64);
- TU_ASSERT(epnum < EP_MAX);
-
- xfer_ctl_t *xfer = XFER_CTL_BASE(epnum, dir);
- xfer->max_size = desc_edpt->wMaxPacketSize.size;
-
- if (dir == TUSB_DIR_OUT) {
- out_ep[epnum].doepctl |= USB_USBACTEP0_M |
- desc_edpt->bmAttributes.xfer << USB_EPTYPE0_S |
- desc_edpt->wMaxPacketSize.size << USB_MPS0_S;
- USB0.daintmsk |= (1 << (16 + epnum));
- } else {
- // "USB Data FIFOs" section in reference manual
- // Peripheral FIFO architecture
- //
- // --------------- 320 or 1024 ( 1280 or 4096 bytes )
- // | IN FIFO MAX |
- // ---------------
- // | ... |
- // --------------- y + x + 16 + GRXFSIZ
- // | IN FIFO 2 |
- // --------------- x + 16 + GRXFSIZ
- // | IN FIFO 1 |
- // --------------- 16 + GRXFSIZ
- // | IN FIFO 0 |
- // --------------- GRXFSIZ
- // | OUT FIFO |
- // | ( Shared ) |
- // --------------- 0
- //
- // Since OUT FIFO = GRXFSIZ, FIFO 0 = 16, for simplicity, we equally allocated for the rest of endpoints
- // - Size : (FIFO_SIZE/4 - GRXFSIZ - 16) / (EP_MAX-1)
- // - Offset: GRXFSIZ + 16 + Size*(epnum-1)
- // - IN EP 1 gets FIFO 1, IN EP "n" gets FIFO "n".
-
- uint8_t fifo_num = get_free_fifo();
- TU_ASSERT(fifo_num != 0);
-
- in_ep[epnum].diepctl &= ~(USB_D_TXFNUM1_M | USB_D_EPTYPE1_M | USB_DI_SETD0PID1 | USB_D_MPS1_M);
- in_ep[epnum].diepctl |= USB_D_USBACTEP1_M |
- fifo_num << USB_D_TXFNUM1_S |
- desc_edpt->bmAttributes.xfer << USB_D_EPTYPE1_S |
- (desc_edpt->bmAttributes.xfer != TUSB_XFER_ISOCHRONOUS ? (1 << USB_DI_SETD0PID1_S) : 0) |
- desc_edpt->wMaxPacketSize.size << 0;
-
- USB0.daintmsk |= (1 << (0 + epnum));
-
- // Both TXFD and TXSA are in unit of 32-bit words.
- // IN FIFO 0 was configured during enumeration, hence the "+ 16".
- uint16_t const allocated_size = (USB0.grxfsiz & 0x0000ffff) + 16;
- uint16_t const fifo_size = (EP_FIFO_SIZE/4 - allocated_size) / (EP_FIFO_NUM-1);
- uint32_t const fifo_offset = allocated_size + fifo_size*(fifo_num-1);
-
- // DIEPTXF starts at FIFO #1.
- USB0.dieptxf[epnum - 1] = (fifo_size << USB_NPTXFDEP_S) | fifo_offset;
- }
- return true;
-}
-
-bool dcd_edpt_xfer(uint8_t rhport, uint8_t ep_addr, uint8_t *buffer, uint16_t total_bytes)
-{
- (void)rhport;
-
- uint8_t const epnum = tu_edpt_number(ep_addr);
- uint8_t const dir = tu_edpt_dir(ep_addr);
-
- xfer_ctl_t * xfer = XFER_CTL_BASE(epnum, dir);
- xfer->buffer = buffer;
- // xfer->ff = NULL; // TODO support dcd_edpt_xfer_fifo API
- xfer->total_len = total_bytes;
- xfer->queued_len = 0;
- xfer->short_packet = false;
-
- uint16_t num_packets = (total_bytes / xfer->max_size);
- uint8_t short_packet_size = total_bytes % xfer->max_size;
-
- // Zero-size packet is special case.
- if (short_packet_size > 0 || (total_bytes == 0)) {
- num_packets++;
- }
-
- ESP_LOGV(TAG, "Transfer <-> EP%i, %s, pkgs: %i, bytes: %i",
- epnum, ((dir == TUSB_DIR_IN) ? "USB0.HOST (in)" : "HOST->DEV (out)"),
- num_packets, total_bytes);
-
- // IN and OUT endpoint xfers are interrupt-driven, we just schedule them
- // here.
- if (dir == TUSB_DIR_IN) {
- // A full IN transfer (multiple packets, possibly) triggers XFRC.
- USB0.in_ep_reg[epnum].dieptsiz = (num_packets << USB_D_PKTCNT0_S) | total_bytes;
- USB0.in_ep_reg[epnum].diepctl |= USB_D_EPENA1_M | USB_D_CNAK1_M; // Enable | CNAK
-
- // Enable fifo empty interrupt only if there are something to put in the fifo.
- if(total_bytes != 0) {
- USB0.dtknqr4_fifoemptymsk |= (1 << epnum);
- }
- } else {
- // Each complete packet for OUT xfers triggers XFRC.
- USB0.out_ep_reg[epnum].doeptsiz |= USB_PKTCNT0_M | ((xfer->max_size & USB_XFERSIZE0_V) << USB_XFERSIZE0_S);
- USB0.out_ep_reg[epnum].doepctl |= USB_EPENA0_M | USB_CNAK0_M;
- }
- return true;
-}
-
-#if 0 // TODO support dcd_edpt_xfer_fifo API
-bool dcd_edpt_xfer_fifo (uint8_t rhport, uint8_t ep_addr, tu_fifo_t * ff, uint16_t total_bytes)
-{
- (void)rhport;
-
- // USB buffers always work in bytes so to avoid unnecessary divisions we demand item_size = 1
- TU_ASSERT(ff->item_size == 1);
-
- uint8_t const epnum = tu_edpt_number(ep_addr);
- uint8_t const dir = tu_edpt_dir(ep_addr);
-
- xfer_ctl_t * xfer = XFER_CTL_BASE(epnum, dir);
- xfer->buffer = NULL;
- xfer->ff = ff;
- xfer->total_len = total_bytes;
- xfer->queued_len = 0;
- xfer->short_packet = false;
-
- uint16_t num_packets = (total_bytes / xfer->max_size);
- uint8_t short_packet_size = total_bytes % xfer->max_size;
-
- // Zero-size packet is special case.
- if (short_packet_size > 0 || (total_bytes == 0)) {
- num_packets++;
- }
-
- ESP_LOGV(TAG, "Transfer <-> EP%i, %s, pkgs: %i, bytes: %i",
- epnum, ((dir == TUSB_DIR_IN) ? "USB0.HOST (in)" : "HOST->DEV (out)"),
- num_packets, total_bytes);
-
- // IN and OUT endpoint xfers are interrupt-driven, we just schedule them
- // here.
- if (dir == TUSB_DIR_IN) {
- // A full IN transfer (multiple packets, possibly) triggers XFRC.
- USB0.in_ep_reg[epnum].dieptsiz = (num_packets << USB_D_PKTCNT0_S) | total_bytes;
- USB0.in_ep_reg[epnum].diepctl |= USB_D_EPENA1_M | USB_D_CNAK1_M; // Enable | CNAK
-
- // Enable fifo empty interrupt only if there are something to put in the fifo.
- if(total_bytes != 0) {
- USB0.dtknqr4_fifoemptymsk |= (1 << epnum);
- }
- } else {
- // Each complete packet for OUT xfers triggers XFRC.
- USB0.out_ep_reg[epnum].doeptsiz |= USB_PKTCNT0_M | ((xfer->max_size & USB_XFERSIZE0_V) << USB_XFERSIZE0_S);
- USB0.out_ep_reg[epnum].doepctl |= USB_EPENA0_M | USB_CNAK0_M;
- }
- return true;
-}
-#endif
-
-void dcd_edpt_stall(uint8_t rhport, uint8_t ep_addr)
-{
- (void)rhport;
-
- usb_out_endpoint_t *out_ep = &(USB0.out_ep_reg[0]);
- usb_in_endpoint_t *in_ep = &(USB0.in_ep_reg[0]);
-
- uint8_t const epnum = tu_edpt_number(ep_addr);
- uint8_t const dir = tu_edpt_dir(ep_addr);
-
- if (dir == TUSB_DIR_IN) {
- // Only disable currently enabled non-control endpoint
- if ((epnum == 0) || !(in_ep[epnum].diepctl & USB_D_EPENA1_M)) {
- in_ep[epnum].diepctl |= (USB_DI_SNAK1_M | USB_D_STALL1_M);
- } else {
- // Stop transmitting packets and NAK IN xfers.
- in_ep[epnum].diepctl |= USB_DI_SNAK1_M;
- while ((in_ep[epnum].diepint & USB_DI_SNAK1_M) == 0) ;
-
- // Disable the endpoint. Note that both SNAK and STALL are set here.
- in_ep[epnum].diepctl |= (USB_DI_SNAK1_M | USB_D_STALL1_M | USB_D_EPDIS1_M);
- while ((in_ep[epnum].diepint & USB_D_EPDISBLD0_M) == 0) ;
- in_ep[epnum].diepint = USB_D_EPDISBLD0_M;
- }
-
- // Flush the FIFO, and wait until we have confirmed it cleared.
- uint8_t const fifo_num = ((in_ep[epnum].diepctl >> USB_D_TXFNUM1_S) & USB_D_TXFNUM1_V);
- USB0.grstctl |= (fifo_num << USB_TXFNUM_S);
- USB0.grstctl |= USB_TXFFLSH_M;
- while ((USB0.grstctl & USB_TXFFLSH_M) != 0) ;
- } else {
- // Only disable currently enabled non-control endpoint
- if ((epnum == 0) || !(out_ep[epnum].doepctl & USB_EPENA0_M)) {
- out_ep[epnum].doepctl |= USB_STALL0_M;
- } else {
- // Asserting GONAK is required to STALL an OUT endpoint.
- // Simpler to use polling here, we don't use the "B"OUTNAKEFF interrupt
- // anyway, and it can't be cleared by user code. If this while loop never
- // finishes, we have bigger problems than just the stack.
- USB0.dctl |= USB_SGOUTNAK_M;
- while ((USB0.gintsts & USB_GOUTNAKEFF_M) == 0) ;
-
- // Ditto here- disable the endpoint. Note that only STALL and not SNAK
- // is set here.
- out_ep[epnum].doepctl |= (USB_STALL0_M | USB_EPDIS0_M);
- while ((out_ep[epnum].doepint & USB_EPDISBLD0_M) == 0) ;
- out_ep[epnum].doepint = USB_EPDISBLD0_M;
-
- // Allow other OUT endpoints to keep receiving.
- USB0.dctl |= USB_CGOUTNAK_M;
- }
- }
-}
-
-void dcd_edpt_clear_stall(uint8_t rhport, uint8_t ep_addr)
-{
- (void)rhport;
-
- usb_out_endpoint_t *out_ep = &(USB0.out_ep_reg[0]);
- usb_in_endpoint_t *in_ep = &(USB0.in_ep_reg[0]);
-
- uint8_t const epnum = tu_edpt_number(ep_addr);
- uint8_t const dir = tu_edpt_dir(ep_addr);
-
- if (dir == TUSB_DIR_IN) {
- in_ep[epnum].diepctl &= ~USB_D_STALL1_M;
-
- uint8_t eptype = (in_ep[epnum].diepctl & USB_D_EPTYPE1_M) >> USB_D_EPTYPE1_S;
- // Required by USB spec to reset DATA toggle bit to DATA0 on interrupt
- // and bulk endpoints.
- if (eptype == 2 || eptype == 3) {
- in_ep[epnum].diepctl |= USB_DI_SETD0PID1_M;
- }
- } else {
- out_ep[epnum].doepctl &= ~USB_STALL1_M;
-
- uint8_t eptype = (out_ep[epnum].doepctl & USB_EPTYPE1_M) >> USB_EPTYPE1_S;
- // Required by USB spec to reset DATA toggle bit to DATA0 on interrupt
- // and bulk endpoints.
- if (eptype == 2 || eptype == 3) {
- out_ep[epnum].doepctl |= USB_DO_SETD0PID1_M;
- }
- }
-}
-
-/*------------------------------------------------------------------*/
-
-static void receive_packet(xfer_ctl_t *xfer, /* usb_out_endpoint_t * out_ep, */ uint16_t xfer_size)
-{
- ESP_EARLY_LOGV(TAG, "USB - receive_packet");
- volatile uint32_t *rx_fifo = USB0.fifo[0];
-
- // See above TODO
- // uint16_t remaining = (out_ep->DOEPTSIZ & UsbDOEPTSIZ_XFRSIZ_Msk) >> UsbDOEPTSIZ_XFRSIZ_Pos;
- // xfer->queued_len = xfer->total_len - remaining;
-
- uint16_t remaining = xfer->total_len - xfer->queued_len;
- uint16_t to_recv_size;
-
- if (remaining <= xfer->max_size) {
- // Avoid buffer overflow.
- to_recv_size = (xfer_size > remaining) ? remaining : xfer_size;
- } else {
- // Room for full packet, choose recv_size based on what the microcontroller
- // claims.
- to_recv_size = (xfer_size > xfer->max_size) ? xfer->max_size : xfer_size;
- }
-
- // Common buffer read
-#if 0 // TODO support dcd_edpt_xfer_fifo API
- if (xfer->ff)
- {
- // Ring buffer
- tu_fifo_write_n_const_addr_full_words(xfer->ff, (const void *) rx_fifo, to_recv_size);
- }
- else
-#endif
- {
- uint8_t to_recv_rem = to_recv_size % 4;
- uint16_t to_recv_size_aligned = to_recv_size - to_recv_rem;
-
- // Do not assume xfer buffer is aligned.
- uint8_t *base = (xfer->buffer + xfer->queued_len);
-
- // This for loop always runs at least once- skip if less than 4 bytes
- // to collect.
- if (to_recv_size >= 4) {
- for (uint16_t i = 0; i < to_recv_size_aligned; i += 4) {
- uint32_t tmp = (*rx_fifo);
- base[i] = tmp & 0x000000FF;
- base[i + 1] = (tmp & 0x0000FF00) >> 8;
- base[i + 2] = (tmp & 0x00FF0000) >> 16;
- base[i + 3] = (tmp & 0xFF000000) >> 24;
- }
- }
-
- // Do not read invalid bytes from RX FIFO.
- if (to_recv_rem != 0) {
- uint32_t tmp = (*rx_fifo);
- uint8_t *last_32b_bound = base + to_recv_size_aligned;
-
- last_32b_bound[0] = tmp & 0x000000FF;
- if (to_recv_rem > 1) {
- last_32b_bound[1] = (tmp & 0x0000FF00) >> 8;
- }
- if (to_recv_rem > 2) {
- last_32b_bound[2] = (tmp & 0x00FF0000) >> 16;
- }
- }
- }
-
- xfer->queued_len += xfer_size;
-
- // Per USB spec, a short OUT packet (including length 0) is always
- // indicative of the end of a transfer (at least for ctl, bulk, int).
- xfer->short_packet = (xfer_size < xfer->max_size);
-}
-
-static void transmit_packet(xfer_ctl_t *xfer, volatile usb_in_endpoint_t *in_ep, uint8_t fifo_num)
-{
- ESP_EARLY_LOGV(TAG, "USB - transmit_packet");
- volatile uint32_t *tx_fifo = USB0.fifo[fifo_num];
-
- uint16_t remaining = (in_ep->dieptsiz & 0x7FFFFU) >> USB_D_XFERSIZE0_S;
- xfer->queued_len = xfer->total_len - remaining;
-
- uint16_t to_xfer_size = (remaining > xfer->max_size) ? xfer->max_size : remaining;
-
-#if 0 // TODO support dcd_edpt_xfer_fifo API
- if (xfer->ff)
- {
- tu_fifo_read_n_const_addr_full_words(xfer->ff, (void *) tx_fifo, to_xfer_size);
- }
- else
-#endif
- {
- uint8_t to_xfer_rem = to_xfer_size % 4;
- uint16_t to_xfer_size_aligned = to_xfer_size - to_xfer_rem;
-
- // Buffer might not be aligned to 32b, so we need to force alignment
- // by copying to a temp var.
- uint8_t *base = (xfer->buffer + xfer->queued_len);
-
- // This for loop always runs at least once- skip if less than 4 bytes
- // to send off.
- if (to_xfer_size >= 4) {
- for (uint16_t i = 0; i < to_xfer_size_aligned; i += 4) {
- uint32_t tmp = base[i] | (base[i + 1] << 8) |
- (base[i + 2] << 16) | (base[i + 3] << 24);
- (*tx_fifo) = tmp;
- }
- }
-
- // Do not read beyond end of buffer if not divisible by 4.
- if (to_xfer_rem != 0) {
- uint32_t tmp = 0;
- uint8_t *last_32b_bound = base + to_xfer_size_aligned;
-
- tmp |= last_32b_bound[0];
- if (to_xfer_rem > 1) {
- tmp |= (last_32b_bound[1] << 8);
- }
- if (to_xfer_rem > 2) {
- tmp |= (last_32b_bound[2] << 16);
- }
-
- (*tx_fifo) = tmp;
- }
- }
-}
-
-static void read_rx_fifo(void)
-{
- // Pop control word off FIFO (completed xfers will have 2 control words,
- // we only pop one ctl word each interrupt).
- uint32_t const ctl_word = USB0.grxstsp;
- uint8_t const pktsts = (ctl_word & USB_PKTSTS_M) >> USB_PKTSTS_S;
- uint8_t const epnum = (ctl_word & USB_CHNUM_M ) >> USB_CHNUM_S;
- uint16_t const bcnt = (ctl_word & USB_BCNT_M ) >> USB_BCNT_S;
-
- switch (pktsts) {
- case 0x01: // Global OUT NAK (Interrupt)
- ESP_EARLY_LOGV(TAG, "TUSB IRQ - RX type : Global OUT NAK");
- break;
-
- case 0x02: { // Out packet recvd
- ESP_EARLY_LOGV(TAG, "TUSB IRQ - RX type : Out packet");
- xfer_ctl_t *xfer = XFER_CTL_BASE(epnum, TUSB_DIR_OUT);
- receive_packet(xfer, bcnt);
- }
- break;
-
- case 0x03: // Out packet done (Interrupt)
- ESP_EARLY_LOGV(TAG, "TUSB IRQ - RX type : Out packet done");
- break;
-
- case 0x04: // Step 2: Setup transaction completed (Interrupt)
- // After this event, OEPINT interrupt will occur with SETUP bit set
- ESP_EARLY_LOGV(TAG, "TUSB IRQ - RX : Setup packet done");
- USB0.out_ep_reg[epnum].doeptsiz |= USB_SUPCNT0_M;
- break;
-
- case 0x06: { // Step1: Setup data packet received
- volatile uint32_t *rx_fifo = USB0.fifo[0];
-
- // We can receive up to three setup packets in succession, but
- // only the last one is valid. Therefore we just overwrite it
- _setup_packet[0] = (*rx_fifo);
- _setup_packet[1] = (*rx_fifo);
-
- ESP_EARLY_LOGV(TAG, "TUSB IRQ - RX : Setup packet : 0x%08x 0x%08x", _setup_packet[0], _setup_packet[1]);
- }
- break;
-
- default: // Invalid, do something here, like breakpoint?
- TU_BREAKPOINT();
- break;
- }
-}
-
-static void handle_epout_ints(void)
-{
- // GINTSTS will be cleared with DAINT == 0
- // DAINT for a given EP clears when DOEPINTx is cleared.
- // DOEPINT will be cleared when DAINT's out bits are cleared.
- for (int n = 0; n < USB_OUT_EP_NUM; n++) {
- xfer_ctl_t *xfer = XFER_CTL_BASE(n, TUSB_DIR_OUT);
-
- if (USB0.daint & (1 << (16 + n))) {
- // SETUP packet Setup Phase done.
- if ((USB0.out_ep_reg[n].doepint & USB_SETUP0_M)) {
- USB0.out_ep_reg[n].doepint = USB_STUPPKTRCVD0_M | USB_SETUP0_M; // clear
- dcd_event_setup_received(0, (uint8_t *)&_setup_packet[0], true);
- }
-
- // OUT XFER complete (single packet).q
- if (USB0.out_ep_reg[n].doepint & USB_XFERCOMPL0_M) {
-
- ESP_EARLY_LOGV(TAG, "TUSB IRQ - EP OUT - XFER complete (single packet)");
- USB0.out_ep_reg[n].doepint = USB_XFERCOMPL0_M;
-
- // Transfer complete if short packet or total len is transferred
- if (xfer->short_packet || (xfer->queued_len == xfer->total_len)) {
- xfer->short_packet = false;
- dcd_event_xfer_complete(0, n, xfer->queued_len, XFER_RESULT_SUCCESS, true);
- } else {
- // Schedule another packet to be received.
- USB0.out_ep_reg[n].doeptsiz |= USB_PKTCNT0_M | ((xfer->max_size & USB_XFERSIZE0_V) << USB_XFERSIZE0_S);
- USB0.out_ep_reg[n].doepctl |= USB_EPENA0_M | USB_CNAK0_M;
- }
- }
- }
- }
-}
-
-static void handle_epin_ints(void)
-{
- // GINTSTS will be cleared with DAINT == 0
- // DAINT for a given EP clears when DIEPINTx is cleared.
- // IEPINT will be cleared when DAINT's out bits are cleared.
- for (uint32_t n = 0; n < USB_IN_EP_NUM; n++) {
- xfer_ctl_t *xfer = &xfer_status[n][TUSB_DIR_IN];
-
- if (USB0.daint & (1 << (0 + n))) {
- ESP_EARLY_LOGV(TAG, "TUSB IRQ - EP IN %u", n);
- // IN XFER complete (entire xfer).
- if (USB0.in_ep_reg[n].diepint & USB_D_XFERCOMPL0_M) {
- ESP_EARLY_LOGV(TAG, "TUSB IRQ - IN XFER complete!");
- USB0.in_ep_reg[n].diepint = USB_D_XFERCOMPL0_M;
- dcd_event_xfer_complete(0, n | TUSB_DIR_IN_MASK, xfer->total_len, XFER_RESULT_SUCCESS, true);
- }
-
- // XFER FIFO empty
- if (USB0.in_ep_reg[n].diepint & USB_D_TXFEMP0_M) {
- ESP_EARLY_LOGV(TAG, "TUSB IRQ - IN XFER FIFO empty!");
- USB0.in_ep_reg[n].diepint = USB_D_TXFEMP0_M;
- transmit_packet(xfer, &USB0.in_ep_reg[n], n);
-
- // Turn off TXFE if all bytes are written.
- if (xfer->queued_len == xfer->total_len)
- {
- USB0.dtknqr4_fifoemptymsk &= ~(1 << n);
- }
- }
-
- // XFER Timeout
- if (USB0.in_ep_reg[n].diepint & USB_D_TIMEOUT0_M) {
- // Clear interrupt or enpoint will hang.
- USB0.in_ep_reg[n].diepint = USB_D_TIMEOUT0_M;
- // Maybe retry?
- }
- }
- }
-}
-
-
-static void _dcd_int_handler(void* arg)
-{
- (void) arg;
- uint8_t const rhport = 0;
-
- const uint32_t int_status = USB0.gintsts;
- //const uint32_t int_msk = USB0.gintmsk;
-
- if (int_status & USB_USBRST_M) {
- // start of reset
- ESP_EARLY_LOGV(TAG, "dcd_int_handler - reset");
- USB0.gintsts = USB_USBRST_M;
- // FIFOs will be reassigned when the endpoints are reopen
- _allocated_fifos = 1;
- bus_reset();
- }
-
- if (int_status & USB_RESETDET_M) {
- ESP_EARLY_LOGV(TAG, "dcd_int_handler - reset while suspend");
- USB0.gintsts = USB_RESETDET_M;
- bus_reset();
- }
-
- if (int_status & USB_ENUMDONE_M) {
- // ENUMDNE detects speed of the link. For full-speed, we
- // always expect the same value. This interrupt is considered
- // the end of reset.
- USB0.gintsts = USB_ENUMDONE_M;
- enum_done_processing();
- dcd_event_bus_reset(rhport, TUSB_SPEED_FULL, true);
- }
-
- if(int_status & USB_USBSUSP_M)
- {
- USB0.gintsts = USB_USBSUSP_M;
- dcd_event_bus_signal(rhport, DCD_EVENT_SUSPEND, true);
- }
-
- if(int_status & USB_WKUPINT_M)
- {
- USB0.gintsts = USB_WKUPINT_M;
- dcd_event_bus_signal(rhport, DCD_EVENT_RESUME, true);
- }
-
- if (int_status & USB_OTGINT_M)
- {
- // OTG INT bit is read-only
- ESP_EARLY_LOGV(TAG, "dcd_int_handler - disconnected");
-
- uint32_t const otg_int = USB0.gotgint;
-
- if (otg_int & USB_SESENDDET_M)
- {
- dcd_event_bus_signal(rhport, DCD_EVENT_UNPLUGGED, true);
- }
-
- USB0.gotgint = otg_int;
- }
-
-#if USE_SOF
- if (int_status & USB_SOF_M) {
- USB0.gintsts = USB_SOF_M;
- dcd_event_bus_signal(rhport, DCD_EVENT_SOF, true); // do nothing actually
- }
-#endif
-
- if (int_status & USB_RXFLVI_M) {
- // RXFLVL bit is read-only
- ESP_EARLY_LOGV(TAG, "dcd_int_handler - rx!");
-
- // Mask out RXFLVL while reading data from FIFO
- USB0.gintmsk &= ~USB_RXFLVIMSK_M;
- read_rx_fifo();
- USB0.gintmsk |= USB_RXFLVIMSK_M;
- }
-
- // OUT endpoint interrupt handling.
- if (int_status & USB_OEPINT_M) {
- // OEPINT is read-only
- ESP_EARLY_LOGV(TAG, "dcd_int_handler - OUT endpoint!");
- handle_epout_ints();
- }
-
- // IN endpoint interrupt handling.
- if (int_status & USB_IEPINT_M) {
- // IEPINT bit read-only
- ESP_EARLY_LOGV(TAG, "dcd_int_handler - IN endpoint!");
- handle_epin_ints();
- }
-
- // Without handling
- USB0.gintsts |= USB_CURMOD_INT_M |
- USB_MODEMIS_M |
- USB_OTGINT_M |
- USB_NPTXFEMP_M |
- USB_GINNAKEFF_M |
- USB_GOUTNAKEFF |
- USB_ERLYSUSP_M |
- USB_USBSUSP_M |
- USB_ISOOUTDROP_M |
- USB_EOPF_M |
- USB_EPMIS_M |
- USB_INCOMPISOIN_M |
- USB_INCOMPIP_M |
- USB_FETSUSP_M |
- USB_PTXFEMP_M;
-}
-
-void dcd_int_enable (uint8_t rhport)
-{
- (void) rhport;
- esp_intr_alloc(ETS_USB_INTR_SOURCE, ESP_INTR_FLAG_LOWMED, (intr_handler_t) _dcd_int_handler, NULL, &usb_ih);
-}
-
-void dcd_int_disable (uint8_t rhport)
-{
- (void) rhport;
- esp_intr_free(usb_ih);
-}
-
-#endif // #if OPT_MCU_ESP32S2 || OPT_MCU_ESP32S3
-
diff --git a/tinyusb/src/portable/microchip/samd/dcd_samd.c b/tinyusb/src/portable/microchip/samd/dcd_samd.c
deleted file mode 100755
index 577bd0e0..00000000
--- a/tinyusb/src/portable/microchip/samd/dcd_samd.c
+++ /dev/null
@@ -1,411 +0,0 @@
-/*
- * The MIT License (MIT)
- *
- * Copyright (c) 2018 Scott Shawcroft for Adafruit Industries
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- *
- * This file is part of the TinyUSB stack.
- */
-
-#include "tusb_option.h"
-
-#if TUSB_OPT_DEVICE_ENABLED && \
- (CFG_TUSB_MCU == OPT_MCU_SAMD11 || CFG_TUSB_MCU == OPT_MCU_SAMD21 || \
- CFG_TUSB_MCU == OPT_MCU_SAMD51 || CFG_TUSB_MCU == OPT_MCU_SAME5X || \
- CFG_TUSB_MCU == OPT_MCU_SAML22 || CFG_TUSB_MCU == OPT_MCU_SAML21)
-
-#include "sam.h"
-#include "device/dcd.h"
-
-/*------------------------------------------------------------------*/
-/* MACRO TYPEDEF CONSTANT ENUM
- *------------------------------------------------------------------*/
-static TU_ATTR_ALIGNED(4) UsbDeviceDescBank sram_registers[8][2];
-
-// Setup packet is only 8 bytes in length. However under certain scenario,
-// USB DMA controller may decide to overwrite/overflow the buffer with
-// 2 extra bytes of CRC. From datasheet's "Management of SETUP Transactions" section
-// If the number of received data bytes is the maximum data payload specified by
-// PCKSIZE.SIZE minus one, only the first CRC data is written to the data buffer.
-// If the number of received data is equal or less than the data payload specified
-// by PCKSIZE.SIZE minus two, both CRC data bytes are written to the data buffer.
-// Therefore we will need to increase it to 10 bytes here.
-static TU_ATTR_ALIGNED(4) uint8_t _setup_packet[8+2];
-
-// ready for receiving SETUP packet
-static inline void prepare_setup(void)
-{
- // Only make sure the EP0 OUT buffer is ready
- sram_registers[0][0].ADDR.reg = (uint32_t) _setup_packet;
- sram_registers[0][0].PCKSIZE.bit.MULTI_PACKET_SIZE = sizeof(tusb_control_request_t);
- sram_registers[0][0].PCKSIZE.bit.BYTE_COUNT = 0;
-}
-
-// Setup the control endpoint 0.
-static void bus_reset(void)
-{
- // Max size of packets is 64 bytes.
- UsbDeviceDescBank* bank_out = &sram_registers[0][TUSB_DIR_OUT];
- bank_out->PCKSIZE.bit.SIZE = 0x3;
- UsbDeviceDescBank* bank_in = &sram_registers[0][TUSB_DIR_IN];
- bank_in->PCKSIZE.bit.SIZE = 0x3;
-
- UsbDeviceEndpoint* ep = &USB->DEVICE.DeviceEndpoint[0];
- ep->EPCFG.reg = USB_DEVICE_EPCFG_EPTYPE0(0x1) | USB_DEVICE_EPCFG_EPTYPE1(0x1);
- ep->EPINTENSET.reg = USB_DEVICE_EPINTENSET_TRCPT0 | USB_DEVICE_EPINTENSET_TRCPT1 | USB_DEVICE_EPINTENSET_RXSTP;
-
- // Prepare for setup packet
- prepare_setup();
-}
-
-/*------------------------------------------------------------------*/
-/* Controller API
- *------------------------------------------------------------------*/
-void dcd_init (uint8_t rhport)
-{
- (void) rhport;
-
- // Reset to get in a clean state.
- USB->DEVICE.CTRLA.bit.SWRST = true;
- while (USB->DEVICE.SYNCBUSY.bit.SWRST == 0) {}
- while (USB->DEVICE.SYNCBUSY.bit.SWRST == 1) {}
-
- USB->DEVICE.PADCAL.bit.TRANSP = (*((uint32_t*) USB_FUSES_TRANSP_ADDR) & USB_FUSES_TRANSP_Msk) >> USB_FUSES_TRANSP_Pos;
- USB->DEVICE.PADCAL.bit.TRANSN = (*((uint32_t*) USB_FUSES_TRANSN_ADDR) & USB_FUSES_TRANSN_Msk) >> USB_FUSES_TRANSN_Pos;
- USB->DEVICE.PADCAL.bit.TRIM = (*((uint32_t*) USB_FUSES_TRIM_ADDR) & USB_FUSES_TRIM_Msk) >> USB_FUSES_TRIM_Pos;
-
- USB->DEVICE.QOSCTRL.bit.CQOS = 3; // High Quality
- USB->DEVICE.QOSCTRL.bit.DQOS = 3; // High Quality
-
- // Configure registers
- USB->DEVICE.DESCADD.reg = (uint32_t) &sram_registers;
- USB->DEVICE.CTRLB.reg = USB_DEVICE_CTRLB_SPDCONF_FS;
- USB->DEVICE.CTRLA.reg = USB_CTRLA_MODE_DEVICE | USB_CTRLA_ENABLE | USB_CTRLA_RUNSTDBY;
- while (USB->DEVICE.SYNCBUSY.bit.ENABLE == 1) {}
-
- USB->DEVICE.INTFLAG.reg |= USB->DEVICE.INTFLAG.reg; // clear pending
- USB->DEVICE.INTENSET.reg = /* USB_DEVICE_INTENSET_SOF | */ USB_DEVICE_INTENSET_EORST;
-}
-
-#if CFG_TUSB_MCU == OPT_MCU_SAMD51 || CFG_TUSB_MCU == OPT_MCU_SAME5X
-
-void dcd_int_enable(uint8_t rhport)
-{
- (void) rhport;
- NVIC_EnableIRQ(USB_0_IRQn);
- NVIC_EnableIRQ(USB_1_IRQn);
- NVIC_EnableIRQ(USB_2_IRQn);
- NVIC_EnableIRQ(USB_3_IRQn);
-}
-
-void dcd_int_disable(uint8_t rhport)
-{
- (void) rhport;
- NVIC_DisableIRQ(USB_3_IRQn);
- NVIC_DisableIRQ(USB_2_IRQn);
- NVIC_DisableIRQ(USB_1_IRQn);
- NVIC_DisableIRQ(USB_0_IRQn);
-}
-
-#elif CFG_TUSB_MCU == OPT_MCU_SAMD11 || CFG_TUSB_MCU == OPT_MCU_SAMD21 || \
- CFG_TUSB_MCU == OPT_MCU_SAML22 || CFG_TUSB_MCU == OPT_MCU_SAML21
-
-void dcd_int_enable(uint8_t rhport)
-{
- (void) rhport;
- NVIC_EnableIRQ(USB_IRQn);
-}
-
-void dcd_int_disable(uint8_t rhport)
-{
- (void) rhport;
- NVIC_DisableIRQ(USB_IRQn);
-}
-
-#else
-
-#error "No implementation available for dcd_int_enable / dcd_int_disable"
-
-#endif
-
-void dcd_set_address (uint8_t rhport, uint8_t dev_addr)
-{
- (void) dev_addr;
-
- // Response with zlp status
- dcd_edpt_xfer(rhport, 0x80, NULL, 0);
-
- // DCD can only set address after status for this request is complete
- // do it at dcd_edpt0_status_complete()
-
- // Enable SUSPEND interrupt since the bus signal D+/D- are stable now.
- USB->DEVICE.INTFLAG.reg = USB_DEVICE_INTENCLR_SUSPEND; // clear pending
- USB->DEVICE.INTENSET.reg = USB_DEVICE_INTENSET_SUSPEND;
-}
-
-void dcd_remote_wakeup(uint8_t rhport)
-{
- (void) rhport;
- USB->DEVICE.CTRLB.bit.UPRSM = 1;
-}
-
-// disconnect by disabling internal pull-up resistor on D+/D-
-void dcd_disconnect(uint8_t rhport)
-{
- (void) rhport;
- USB->DEVICE.CTRLB.reg |= USB_DEVICE_CTRLB_DETACH;
-}
-
-// connect by enabling internal pull-up resistor on D+/D-
-void dcd_connect(uint8_t rhport)
-{
- (void) rhport;
- USB->DEVICE.CTRLB.reg &= ~USB_DEVICE_CTRLB_DETACH;
-}
-
-/*------------------------------------------------------------------*/
-/* DCD Endpoint port
- *------------------------------------------------------------------*/
-
-// Invoked when a control transfer's status stage is complete.
-// May help DCD to prepare for next control transfer, this API is optional.
-void dcd_edpt0_status_complete(uint8_t rhport, tusb_control_request_t const * request)
-{
- (void) rhport;
-
- if (request->bmRequestType_bit.recipient == TUSB_REQ_RCPT_DEVICE &&
- request->bmRequestType_bit.type == TUSB_REQ_TYPE_STANDARD &&
- request->bRequest == TUSB_REQ_SET_ADDRESS )
- {
- uint8_t const dev_addr = (uint8_t) request->wValue;
- USB->DEVICE.DADD.reg = USB_DEVICE_DADD_DADD(dev_addr) | USB_DEVICE_DADD_ADDEN;
- }
-
- // Just finished status stage, prepare for next setup packet
- // Note: we may already prepare setup when queueing the control status.
- // but it has no harm to do it again here
- prepare_setup();
-}
-
-bool dcd_edpt_open (uint8_t rhport, tusb_desc_endpoint_t const * desc_edpt)
-{
- (void) rhport;
-
- uint8_t const epnum = tu_edpt_number(desc_edpt->bEndpointAddress);
- uint8_t const dir = tu_edpt_dir(desc_edpt->bEndpointAddress);
-
- UsbDeviceDescBank* bank = &sram_registers[epnum][dir];
- uint32_t size_value = 0;
- while (size_value < 7) {
- if (1 << (size_value + 3) == desc_edpt->wMaxPacketSize.size) {
- break;
- }
- size_value++;
- }
-
- // unsupported endpoint size
- if ( size_value == 7 && desc_edpt->wMaxPacketSize.size != 1023 ) return false;
-
- bank->PCKSIZE.bit.SIZE = size_value;
-
- UsbDeviceEndpoint* ep = &USB->DEVICE.DeviceEndpoint[epnum];
-
- if ( dir == TUSB_DIR_OUT )
- {
- ep->EPCFG.bit.EPTYPE0 = desc_edpt->bmAttributes.xfer + 1;
- ep->EPINTENSET.bit.TRCPT0 = true;
- }else
- {
- ep->EPCFG.bit.EPTYPE1 = desc_edpt->bmAttributes.xfer + 1;
- ep->EPINTENSET.bit.TRCPT1 = true;
- }
-
- return true;
-}
-
-bool dcd_edpt_xfer (uint8_t rhport, uint8_t ep_addr, uint8_t * buffer, uint16_t total_bytes)
-{
- (void) rhport;
-
- uint8_t const epnum = tu_edpt_number(ep_addr);
- uint8_t const dir = tu_edpt_dir(ep_addr);
-
- UsbDeviceDescBank* bank = &sram_registers[epnum][dir];
- UsbDeviceEndpoint* ep = &USB->DEVICE.DeviceEndpoint[epnum];
-
- bank->ADDR.reg = (uint32_t) buffer;
-
- // A SETUP token can occur immediately after an ZLP Status.
- // So make sure we have a valid buffer for setup packet.
- // Status = ZLP EP0 with direction opposite to one in the dir bit of current setup
- if ( (epnum == 0) && (buffer == NULL) && (total_bytes == 0) && (dir != tu_edpt_dir(_setup_packet[0])) ) {
- prepare_setup();
- }
-
- if ( dir == TUSB_DIR_OUT )
- {
- bank->PCKSIZE.bit.MULTI_PACKET_SIZE = total_bytes;
- bank->PCKSIZE.bit.BYTE_COUNT = 0;
- ep->EPSTATUSCLR.reg |= USB_DEVICE_EPSTATUSCLR_BK0RDY;
- ep->EPINTFLAG.reg |= USB_DEVICE_EPINTFLAG_TRFAIL0;
- } else
- {
- bank->PCKSIZE.bit.MULTI_PACKET_SIZE = 0;
- bank->PCKSIZE.bit.BYTE_COUNT = total_bytes;
- ep->EPSTATUSSET.reg |= USB_DEVICE_EPSTATUSSET_BK1RDY;
- ep->EPINTFLAG.reg |= USB_DEVICE_EPINTFLAG_TRFAIL1;
- }
-
- return true;
-}
-
-void dcd_edpt_stall (uint8_t rhport, uint8_t ep_addr)
-{
- (void) rhport;
-
- uint8_t const epnum = tu_edpt_number(ep_addr);
- UsbDeviceEndpoint* ep = &USB->DEVICE.DeviceEndpoint[epnum];
-
- if (tu_edpt_dir(ep_addr) == TUSB_DIR_IN) {
- ep->EPSTATUSSET.reg = USB_DEVICE_EPSTATUSSET_STALLRQ1;
- } else {
- ep->EPSTATUSSET.reg = USB_DEVICE_EPSTATUSSET_STALLRQ0;
- }
-}
-
-void dcd_edpt_clear_stall (uint8_t rhport, uint8_t ep_addr)
-{
- (void) rhport;
-
- uint8_t const epnum = tu_edpt_number(ep_addr);
- UsbDeviceEndpoint* ep = &USB->DEVICE.DeviceEndpoint[epnum];
-
- if (tu_edpt_dir(ep_addr) == TUSB_DIR_IN) {
- ep->EPSTATUSCLR.reg = USB_DEVICE_EPSTATUSCLR_STALLRQ1 | USB_DEVICE_EPSTATUSCLR_DTGLIN;
- } else {
- ep->EPSTATUSCLR.reg = USB_DEVICE_EPSTATUSCLR_STALLRQ0 | USB_DEVICE_EPSTATUSCLR_DTGLOUT;
- }
-}
-
-//--------------------------------------------------------------------+
-// Interrupt Handler
-//--------------------------------------------------------------------+
-void maybe_transfer_complete(void) {
- uint32_t epints = USB->DEVICE.EPINTSMRY.reg;
-
- for (uint8_t epnum = 0; epnum < USB_EPT_NUM; epnum++) {
- if ((epints & (1 << epnum)) == 0) {
- continue;
- }
-
- UsbDeviceEndpoint* ep = &USB->DEVICE.DeviceEndpoint[epnum];
- uint32_t epintflag = ep->EPINTFLAG.reg;
-
- // Handle IN completions
- if ((epintflag & USB_DEVICE_EPINTFLAG_TRCPT1) != 0) {
- UsbDeviceDescBank* bank = &sram_registers[epnum][TUSB_DIR_IN];
- uint16_t const total_transfer_size = bank->PCKSIZE.bit.BYTE_COUNT;
-
- dcd_event_xfer_complete(0, epnum | TUSB_DIR_IN_MASK, total_transfer_size, XFER_RESULT_SUCCESS, true);
-
- ep->EPINTFLAG.reg = USB_DEVICE_EPINTFLAG_TRCPT1;
- }
-
- // Handle OUT completions
- if ((epintflag & USB_DEVICE_EPINTFLAG_TRCPT0) != 0) {
- UsbDeviceDescBank* bank = &sram_registers[epnum][TUSB_DIR_OUT];
- uint16_t const total_transfer_size = bank->PCKSIZE.bit.BYTE_COUNT;
-
- dcd_event_xfer_complete(0, epnum, total_transfer_size, XFER_RESULT_SUCCESS, true);
-
- ep->EPINTFLAG.reg = USB_DEVICE_EPINTFLAG_TRCPT0;
- }
- }
-}
-
-
-void dcd_int_handler (uint8_t rhport)
-{
- (void) rhport;
-
- uint32_t int_status = USB->DEVICE.INTFLAG.reg & USB->DEVICE.INTENSET.reg;
-
- // Start of Frame
- if ( int_status & USB_DEVICE_INTFLAG_SOF )
- {
- USB->DEVICE.INTFLAG.reg = USB_DEVICE_INTFLAG_SOF;
- dcd_event_bus_signal(0, DCD_EVENT_SOF, true);
- }
-
- // SAMD doesn't distinguish between Suspend and Disconnect state.
- // Both condition will cause SUSPEND interrupt triggered.
- // To prevent being triggered when D+/D- are not stable, SUSPEND interrupt is only
- // enabled when we received SET_ADDRESS request and cleared on Bus Reset
- if ( int_status & USB_DEVICE_INTFLAG_SUSPEND )
- {
- USB->DEVICE.INTFLAG.reg = USB_DEVICE_INTFLAG_SUSPEND;
-
- // Enable wakeup interrupt
- USB->DEVICE.INTFLAG.reg = USB_DEVICE_INTFLAG_WAKEUP; // clear pending
- USB->DEVICE.INTENSET.reg = USB_DEVICE_INTFLAG_WAKEUP;
-
- dcd_event_bus_signal(0, DCD_EVENT_SUSPEND, true);
- }
-
- // Wakeup interrupt is only enabled when we got suspended.
- // Wakeup interrupt will disable itself
- if ( int_status & USB_DEVICE_INTFLAG_WAKEUP )
- {
- USB->DEVICE.INTFLAG.reg = USB_DEVICE_INTFLAG_WAKEUP;
-
- // disable wakeup interrupt itself
- USB->DEVICE.INTENCLR.reg = USB_DEVICE_INTFLAG_WAKEUP;
- dcd_event_bus_signal(0, DCD_EVENT_RESUME, true);
- }
-
- // Enable of Reset
- if ( int_status & USB_DEVICE_INTFLAG_EORST )
- {
- USB->DEVICE.INTFLAG.reg = USB_DEVICE_INTFLAG_EORST;
-
- // Disable both suspend and wakeup interrupt
- USB->DEVICE.INTENCLR.reg = USB_DEVICE_INTFLAG_WAKEUP | USB_DEVICE_INTFLAG_SUSPEND;
-
- bus_reset();
- dcd_event_bus_reset(0, TUSB_SPEED_FULL, true);
- }
-
- // Handle SETUP packet
- if (USB->DEVICE.DeviceEndpoint[0].EPINTFLAG.bit.RXSTP)
- {
- // This copies the data elsewhere so we can reuse the buffer.
- dcd_event_setup_received(0, _setup_packet, true);
-
- // Although Setup packet only set RXSTP bit,
- // TRCPT0 bit could already be set by previous ZLP OUT Status (not handled until now).
- // Since control status complete event is optional, we can just clear TRCPT0 and skip the status event
- USB->DEVICE.DeviceEndpoint[0].EPINTFLAG.reg = USB_DEVICE_EPINTFLAG_RXSTP | USB_DEVICE_EPINTFLAG_TRCPT0;
- }
-
- // Handle complete transfer
- maybe_transfer_complete();
-}
-
-#endif
diff --git a/tinyusb/src/portable/microchip/samg/dcd_samg.c b/tinyusb/src/portable/microchip/samg/dcd_samg.c
deleted file mode 100755
index d50621ce..00000000
--- a/tinyusb/src/portable/microchip/samg/dcd_samg.c
+++ /dev/null
@@ -1,486 +0,0 @@
-/*
- * The MIT License (MIT)
- *
- * Copyright (c) 2018, hathach (tinyusb.org)
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- *
- * This file is part of the TinyUSB stack.
- */
-
-#include "tusb_option.h"
-
-#if CFG_TUSB_MCU == OPT_MCU_SAMG
-
-#include "sam.h"
-#include "device/dcd.h"
-
-// TODO should support (SAM3S || SAM4S || SAM4E || SAMG55)
-
-//--------------------------------------------------------------------+
-// MACRO TYPEDEF CONSTANT ENUM DECLARATION
-//--------------------------------------------------------------------+
-
-#define EP_COUNT 6
-
-// Transfer descriptor
-typedef struct
-{
- uint8_t* buffer;
- // tu_fifo_t* ff; // TODO support dcd_edpt_xfer_fifo API
- uint16_t total_len;
- volatile uint16_t actual_len;
- uint16_t epsize;
-} xfer_desc_t;
-
-// Endpoint 0-5, each can only be either OUT or In
-xfer_desc_t _dcd_xfer[EP_COUNT];
-
-void xfer_epsize_set(xfer_desc_t* xfer, uint16_t epsize)
-{
- xfer->epsize = epsize;
-}
-
-void xfer_begin(xfer_desc_t* xfer, uint8_t * buffer, uint16_t total_bytes)
-{
- xfer->buffer = buffer;
- // xfer->ff = NULL; // TODO support dcd_edpt_xfer_fifo API
- xfer->total_len = total_bytes;
- xfer->actual_len = 0;
-}
-
-void xfer_end(xfer_desc_t* xfer)
-{
- xfer->buffer = NULL;
- // xfer->ff = NULL; // TODO support dcd_edpt_xfer_fifo API
- xfer->total_len = 0;
- xfer->actual_len = 0;
-}
-
-uint16_t xfer_packet_len(xfer_desc_t* xfer)
-{
- // also cover zero-length packet
- return tu_min16(xfer->total_len - xfer->actual_len, xfer->epsize);
-}
-
-void xfer_packet_done(xfer_desc_t* xfer)
-{
- uint16_t const xact_len = xfer_packet_len(xfer);
-
- xfer->buffer += xact_len;
- xfer->actual_len += xact_len;
-}
-
-//------------- Transaction helpers -------------//
-
-// Write data to EP FIFO, return number of written bytes
-static void xact_ep_write(uint8_t epnum, uint8_t* buffer, uint16_t xact_len)
-{
- for(uint16_t i=0; i<xact_len; i++)
- {
- UDP->UDP_FDR[epnum] = (uint32_t) buffer[i];
- }
-}
-
-// Read data from EP FIFO
-static void xact_ep_read(uint8_t epnum, uint8_t* buffer, uint16_t xact_len)
-{
- for(uint16_t i=0; i<xact_len; i++)
- {
- buffer[i] = (uint8_t) UDP->UDP_FDR[epnum];
- }
-}
-
-
-//! Bitmap for all status bits in CSR that are not affected by a value 1.
-#define CSR_NO_EFFECT_1_ALL (UDP_CSR_RX_DATA_BK0 | UDP_CSR_RX_DATA_BK1 | UDP_CSR_STALLSENT | UDP_CSR_RXSETUP | UDP_CSR_TXCOMP)
-
-// Per Specs: CSR need synchronization each write
-static inline void csr_write(uint8_t epnum, uint32_t value)
-{
- uint32_t const csr = value;
- UDP->UDP_CSR[epnum] = csr;
-
- volatile uint32_t nop_count;
- for (nop_count = 0; nop_count < 20; nop_count ++) __NOP();
-}
-
-// Per Specs: CSR need synchronization each write
-static inline void csr_set(uint8_t epnum, uint32_t mask)
-{
- csr_write(epnum, UDP->UDP_CSR[epnum] | CSR_NO_EFFECT_1_ALL | mask);
-}
-
-// Per Specs: CSR need synchronization each write
-static inline void csr_clear(uint8_t epnum, uint32_t mask)
-{
- csr_write(epnum, (UDP->UDP_CSR[epnum] | CSR_NO_EFFECT_1_ALL) & ~mask);
-}
-
-/*------------------------------------------------------------------*/
-/* Device API
- *------------------------------------------------------------------*/
-
-// Set up endpoint 0, clear all other endpoints
-static void bus_reset(void)
-{
- tu_memclr(_dcd_xfer, sizeof(_dcd_xfer));
-
- xfer_epsize_set(&_dcd_xfer[0], CFG_TUD_ENDPOINT0_SIZE);
-
- // Enable EP0 control
- csr_write(0, UDP_CSR_EPEDS_Msk);
-
- // Enable interrupt : EP0, Suspend, Resume, Wakeup
- UDP->UDP_IER = UDP_IER_EP0INT_Msk | UDP_IER_RXSUSP_Msk | UDP_IER_RXRSM_Msk | UDP_IER_WAKEUP_Msk;
-
- // Enable transceiver
- UDP->UDP_TXVC &= ~UDP_TXVC_TXVDIS_Msk;
-}
-
-// Initialize controller to device mode
-void dcd_init (uint8_t rhport)
-{
- tu_memclr(_dcd_xfer, sizeof(_dcd_xfer));
- dcd_connect(rhport);
-}
-
-// Enable device interrupt
-void dcd_int_enable (uint8_t rhport)
-{
- (void) rhport;
- NVIC_EnableIRQ(UDP_IRQn);
-}
-
-// Disable device interrupt
-void dcd_int_disable (uint8_t rhport)
-{
- (void) rhport;
- NVIC_DisableIRQ(UDP_IRQn);
-}
-
-// Receive Set Address request, mcu port must also include status IN response
-void dcd_set_address (uint8_t rhport, uint8_t dev_addr)
-{
- (void) rhport;
- (void) dev_addr;
-
- // Response with zlp status
- dcd_edpt_xfer(rhport, 0x80, NULL, 0);
-
- // DCD can only set address after status for this request is complete.
- // do it at dcd_edpt0_status_complete()
-}
-
-// Wake up host
-void dcd_remote_wakeup (uint8_t rhport)
-{
- (void) rhport;
-}
-
-void dcd_connect(uint8_t rhport)
-{
- (void) rhport;
-
- // Enable pull-up, disable transceiver
- UDP->UDP_TXVC = UDP_TXVC_PUON | UDP_TXVC_TXVDIS_Msk;
-}
-
-void dcd_disconnect(uint8_t rhport)
-{
- (void) rhport;
-
- // disable both pullup and transceiver
- UDP->UDP_TXVC = UDP_TXVC_TXVDIS_Msk;
-}
-
-//--------------------------------------------------------------------+
-// Endpoint API
-//--------------------------------------------------------------------+
-
-// Invoked when a control transfer's status stage is complete.
-// May help DCD to prepare for next control transfer, this API is optional.
-void dcd_edpt0_status_complete(uint8_t rhport, tusb_control_request_t const * request)
-{
- (void) rhport;
-
- if (request->bmRequestType_bit.recipient == TUSB_REQ_RCPT_DEVICE &&
- request->bmRequestType_bit.type == TUSB_REQ_TYPE_STANDARD )
- {
- if (request->bRequest == TUSB_REQ_SET_ADDRESS)
- {
- uint8_t const dev_addr = (uint8_t) request->wValue;
-
- // Enable addressed state
- UDP->UDP_GLB_STAT |= UDP_GLB_STAT_FADDEN_Msk;
-
- // Set new address & Function enable bit
- UDP->UDP_FADDR = UDP_FADDR_FEN_Msk | UDP_FADDR_FADD(dev_addr);
- }
- else if (request->bRequest == TUSB_REQ_SET_CONFIGURATION)
- {
- // Configured State
- UDP->UDP_GLB_STAT |= UDP_GLB_STAT_CONFG_Msk;
- }
- }
-}
-
-// Configure endpoint's registers according to descriptor
-// SAMG doesn't support a same endpoint number with IN and OUT
-// e.g EP1 OUT & EP1 IN cannot exist together
-bool dcd_edpt_open (uint8_t rhport, tusb_desc_endpoint_t const * ep_desc)
-{
- (void) rhport;
-
- uint8_t const epnum = tu_edpt_number(ep_desc->bEndpointAddress);
- uint8_t const dir = tu_edpt_dir(ep_desc->bEndpointAddress);
-
- // TODO Isochronous is not supported yet
- TU_VERIFY(ep_desc->bmAttributes.xfer != TUSB_XFER_ISOCHRONOUS);
- TU_VERIFY(epnum < EP_COUNT);
-
- // Must not already enabled
- TU_ASSERT((UDP->UDP_CSR[epnum] & UDP_CSR_EPEDS_Msk) == 0);
-
- xfer_epsize_set(&_dcd_xfer[epnum], ep_desc->wMaxPacketSize.size);
-
- // Configure type and enable EP
- csr_write(epnum, UDP_CSR_EPEDS_Msk | UDP_CSR_EPTYPE(ep_desc->bmAttributes.xfer + 4*dir));
-
- // Enable EP Interrupt for IN
- if (dir == TUSB_DIR_IN) UDP->UDP_IER |= (1 << epnum);
-
- return true;
-}
-
-// Submit a transfer, When complete dcd_event_xfer_complete() is invoked to notify the stack
-bool dcd_edpt_xfer (uint8_t rhport, uint8_t ep_addr, uint8_t * buffer, uint16_t total_bytes)
-{
- (void) rhport;
-
- uint8_t const epnum = tu_edpt_number(ep_addr);
- uint8_t const dir = tu_edpt_dir(ep_addr);
-
- xfer_desc_t* xfer = &_dcd_xfer[epnum];
- xfer_begin(xfer, buffer, total_bytes);
-
- if (dir == TUSB_DIR_OUT)
- {
- // Enable interrupt when starting OUT transfer
- if (epnum != 0) UDP->UDP_IER |= (1 << epnum);
- }
- else
- {
- xact_ep_write(epnum, xfer->buffer, xfer_packet_len(xfer));
-
- // TX ready for transfer
- csr_set(epnum, UDP_CSR_TXPKTRDY_Msk);
- }
-
- return true;
-}
-
-#if 0 // TODO support dcd_edpt_xfer_fifo API
-bool dcd_edpt_xfer_fifo (uint8_t rhport, uint8_t ep_addr, tu_fifo_t * ff, uint16_t total_bytes)
-{
- (void) rhport;
- return true;
-}
-#endif
-
-// Stall endpoint
-void dcd_edpt_stall (uint8_t rhport, uint8_t ep_addr)
-{
- (void) rhport;
-
- // For EP0 USBD will stall both EP0 Out and In with 0x00 and 0x80
- // only handle one by skipping 0x80
- if ( ep_addr == tu_edpt_addr(0, TUSB_DIR_IN_MASK) ) return;
-
- uint8_t const epnum = tu_edpt_number(ep_addr);
-
- // Set force stall bit
- csr_set(epnum, UDP_CSR_FORCESTALL_Msk);
-}
-
-// clear stall, data toggle is also reset to DATA0
-void dcd_edpt_clear_stall (uint8_t rhport, uint8_t ep_addr)
-{
- (void) rhport;
-
- uint8_t const epnum = tu_edpt_number(ep_addr);
-
- // clear stall
- csr_clear(epnum, UDP_CSR_FORCESTALL_Msk);
-
- // must also reset EP to clear data toggle
- UDP->UDP_RST_EP |= (1 << epnum);
- UDP->UDP_RST_EP &= ~(1 << epnum);
-}
-
-//--------------------------------------------------------------------+
-// ISR
-//--------------------------------------------------------------------+
-void dcd_int_handler(uint8_t rhport)
-{
- uint32_t const intr_mask = UDP->UDP_IMR;
- uint32_t const intr_status = UDP->UDP_ISR & intr_mask;
-
- // clear interrupt
- UDP->UDP_ICR = intr_status;
-
- // Bus reset
- if (intr_status & UDP_ISR_ENDBUSRES_Msk)
- {
- bus_reset();
- dcd_event_bus_reset(rhport, TUSB_SPEED_FULL, true);
- }
-
- // SOF
-// if (intr_status & UDP_ISR_SOFINT_Msk) dcd_event_bus_signal(rhport, DCD_EVENT_SOF, true);
-
- // Suspend
- if (intr_status & UDP_ISR_RXSUSP_Msk) dcd_event_bus_signal(rhport, DCD_EVENT_SUSPEND, true);
-
- // Resume
- if (intr_status & UDP_ISR_RXRSM_Msk) dcd_event_bus_signal(rhport, DCD_EVENT_RESUME, true);
-
- // Wakeup
- if (intr_status & UDP_ISR_WAKEUP_Msk) dcd_event_bus_signal(rhport, DCD_EVENT_RESUME, true);
-
- //------------- Endpoints -------------//
-
- if ( intr_status & TU_BIT(0) )
- {
- // setup packet
- if ( UDP->UDP_CSR[0] & UDP_CSR_RXSETUP )
- {
- // get setup from FIFO
- uint8_t setup[8];
- for(uint8_t i=0; i<sizeof(setup); i++)
- {
- setup[i] = (uint8_t) UDP->UDP_FDR[0];
- }
-
- // notify usbd
- dcd_event_setup_received(rhport, setup, true);
-
- // Set EP direction bit according to DATA stage
- // MUST only be set before RXSETUP is clear per specs
- if ( tu_edpt_dir(setup[0]) )
- {
- csr_set(0, UDP_CSR_DIR_Msk);
- }
- else
- {
- csr_clear(0, UDP_CSR_DIR_Msk);
- }
-
- // Clear Setup, stall and other on-going transfer bits
- csr_clear(0, UDP_CSR_RXSETUP_Msk | UDP_CSR_TXPKTRDY_Msk | UDP_CSR_TXCOMP_Msk | UDP_CSR_RX_DATA_BK0 | UDP_CSR_RX_DATA_BK1 | UDP_CSR_STALLSENT_Msk | UDP_CSR_FORCESTALL_Msk);
- }
- }
-
- for(uint8_t epnum = 0; epnum < EP_COUNT; epnum++)
- {
- if ( intr_status & TU_BIT(epnum) )
- {
- xfer_desc_t* xfer = &_dcd_xfer[epnum];
-
- //------------- Endpoint IN -------------//
- if (UDP->UDP_CSR[epnum] & UDP_CSR_TXCOMP_Msk)
- {
- xfer_packet_done(xfer);
-
- uint16_t const xact_len = xfer_packet_len(xfer);
-
- if (xact_len)
- {
- // write to EP fifo
-#if 0 // TODO support dcd_edpt_xfer_fifo
- if (xfer->ff)
- {
- tu_fifo_read_n_const_addr_full_words(xfer->ff, (void *) &UDP->UDP_FDR[epnum], xact_len);
- }
- else
-#endif
- {
- xact_ep_write(epnum, xfer->buffer, xact_len);
- }
-
- // TX ready for transfer
- csr_set(epnum, UDP_CSR_TXPKTRDY_Msk);
- }else
- {
- // xfer is complete
- dcd_event_xfer_complete(rhport, epnum | TUSB_DIR_IN_MASK, xfer->actual_len, XFER_RESULT_SUCCESS, true);
-
- // Required since control OUT can happen right after before stack handle this event
- xfer_end(xfer);
- }
-
- // Clear TX Complete bit
- csr_clear(epnum, UDP_CSR_TXCOMP_Msk);
- }
-
- //------------- Endpoint OUT -------------//
- // Ping-Pong is a MUST for Bulk/Iso
- // NOTE: When both Bank0 and Bank1 are both set, there is no way to know which one comes first
- uint32_t const banks_complete = UDP->UDP_CSR[epnum] & (UDP_CSR_RX_DATA_BK0_Msk | UDP_CSR_RX_DATA_BK1_Msk);
- if (banks_complete)
- {
- uint16_t const xact_len = (uint16_t) ((UDP->UDP_CSR[epnum] & UDP_CSR_RXBYTECNT_Msk) >> UDP_CSR_RXBYTECNT_Pos);
-
- // Read from EP fifo
-#if 0 // TODO support dcd_edpt_xfer_fifo API
- if (xfer->ff)
- {
- tu_fifo_write_n_const_addr_full_words(xfer->ff, (const void *) &UDP->UDP_FDR[epnum], xact_len);
- }
- else
-#endif
- {
- xact_ep_read(epnum, xfer->buffer, xact_len);
- }
-
- xfer_packet_done(xfer);
-
- if ( 0 == xfer_packet_len(xfer) )
- {
- // Disable OUT EP interrupt when transfer is complete
- if (epnum != 0) UDP->UDP_IDR |= (1 << epnum);
-
- dcd_event_xfer_complete(rhport, epnum, xfer->actual_len, XFER_RESULT_SUCCESS, true);
- xfer_end(xfer);
- }
-
- // Clear DATA Bank0/1 bit
- csr_clear(epnum, banks_complete);
- }
-
- // Stall sent to host
- if (UDP->UDP_CSR[epnum] & UDP_CSR_STALLSENT_Msk)
- {
- csr_clear(epnum, UDP_CSR_STALLSENT_Msk);
- }
- }
- }
-}
-
-#endif
diff --git a/tinyusb/src/portable/microchip/samx7x/common_usb_regs.h b/tinyusb/src/portable/microchip/samx7x/common_usb_regs.h
deleted file mode 100755
index d232f0bc..00000000
--- a/tinyusb/src/portable/microchip/samx7x/common_usb_regs.h
+++ /dev/null
@@ -1,2108 +0,0 @@
- /*
-* The MIT License (MIT)
-*
-* Copyright (c) 2019 Microchip Technology Inc.
-* Copyright (c) 2018, hathach (tinyusb.org)
-* Copyright (c) 2021, HiFiPhile
-*
-* Permission is hereby granted, free of charge, to any person obtaining a copy
-* of this software and associated documentation files (the "Software"), to deal
-* in the Software without restriction, including without limitation the rights
-* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-* copies of the Software, and to permit persons to whom the Software is
-* furnished to do so, subject to the following conditions:
-*
-* The above copyright notice and this permission notice shall be included in
-* all copies or substantial portions of the Software.
-*
-* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
-* THE SOFTWARE.
-*
-* This file is part of the TinyUSB stack.
-*/
-
-#ifndef _COMMON_USB_REGS_H_
-#define _COMMON_USB_REGS_H_
-
-#if CFG_TUSB_MCU == OPT_MCU_SAMX7X
-
-/* -------- DEVDMANXTDSC : (USBHS Offset: 0x00) (R/W 32) Device DMA Channel Next Descriptor Address Register -------- */
-
-#define DEVDMANXTDSC_OFFSET (0x00) /**< (DEVDMANXTDSC) Device DMA Channel Next Descriptor Address Register Offset */
-
-#define DEVDMANXTDSC_NXT_DSC_ADD_Pos 0 /**< (DEVDMANXTDSC) Next Descriptor Address Position */
-#define DEVDMANXTDSC_NXT_DSC_ADD (_U_(0xFFFFFFFF) << DEVDMANXTDSC_NXT_DSC_ADD_Pos) /**< (DEVDMANXTDSC) Next Descriptor Address Mask */
-#define DEVDMANXTDSC_Msk _U_(0xFFFFFFFF) /**< (DEVDMANXTDSC) Register Mask */
-
-
-/* -------- DEVDMAADDRESS : (USBHS Offset: 0x04) (R/W 32) Device DMA Channel Address Register -------- */
-
-#define DEVDMAADDRESS_OFFSET (0x04) /**< (DEVDMAADDRESS) Device DMA Channel Address Register Offset */
-
-#define DEVDMAADDRESS_BUFF_ADD_Pos 0 /**< (DEVDMAADDRESS) Buffer Address Position */
-#define DEVDMAADDRESS_BUFF_ADD (_U_(0xFFFFFFFF) << DEVDMAADDRESS_BUFF_ADD_Pos) /**< (DEVDMAADDRESS) Buffer Address Mask */
-#define DEVDMAADDRESS_Msk _U_(0xFFFFFFFF) /**< (DEVDMAADDRESS) Register Mask */
-
-
-/* -------- DEVDMACONTROL : (USBHS Offset: 0x08) (R/W 32) Device DMA Channel Control Register -------- */
-
-#define DEVDMACONTROL_OFFSET (0x08) /**< (DEVDMACONTROL) Device DMA Channel Control Register Offset */
-
-#define DEVDMACONTROL_CHANN_ENB_Pos 0 /**< (DEVDMACONTROL) Channel Enable Command Position */
-#define DEVDMACONTROL_CHANN_ENB (_U_(0x1) << DEVDMACONTROL_CHANN_ENB_Pos) /**< (DEVDMACONTROL) Channel Enable Command Mask */
-#define DEVDMACONTROL_LDNXT_DSC_Pos 1 /**< (DEVDMACONTROL) Load Next Channel Transfer Descriptor Enable Command Position */
-#define DEVDMACONTROL_LDNXT_DSC (_U_(0x1) << DEVDMACONTROL_LDNXT_DSC_Pos) /**< (DEVDMACONTROL) Load Next Channel Transfer Descriptor Enable Command Mask */
-#define DEVDMACONTROL_END_TR_EN_Pos 2 /**< (DEVDMACONTROL) End of Transfer Enable Control (OUT transfers only) Position */
-#define DEVDMACONTROL_END_TR_EN (_U_(0x1) << DEVDMACONTROL_END_TR_EN_Pos) /**< (DEVDMACONTROL) End of Transfer Enable Control (OUT transfers only) Mask */
-#define DEVDMACONTROL_END_B_EN_Pos 3 /**< (DEVDMACONTROL) End of Buffer Enable Control Position */
-#define DEVDMACONTROL_END_B_EN (_U_(0x1) << DEVDMACONTROL_END_B_EN_Pos) /**< (DEVDMACONTROL) End of Buffer Enable Control Mask */
-#define DEVDMACONTROL_END_TR_IT_Pos 4 /**< (DEVDMACONTROL) End of Transfer Interrupt Enable Position */
-#define DEVDMACONTROL_END_TR_IT (_U_(0x1) << DEVDMACONTROL_END_TR_IT_Pos) /**< (DEVDMACONTROL) End of Transfer Interrupt Enable Mask */
-#define DEVDMACONTROL_END_BUFFIT_Pos 5 /**< (DEVDMACONTROL) End of Buffer Interrupt Enable Position */
-#define DEVDMACONTROL_END_BUFFIT (_U_(0x1) << DEVDMACONTROL_END_BUFFIT_Pos) /**< (DEVDMACONTROL) End of Buffer Interrupt Enable Mask */
-#define DEVDMACONTROL_DESC_LD_IT_Pos 6 /**< (DEVDMACONTROL) Descriptor Loaded Interrupt Enable Position */
-#define DEVDMACONTROL_DESC_LD_IT (_U_(0x1) << DEVDMACONTROL_DESC_LD_IT_Pos) /**< (DEVDMACONTROL) Descriptor Loaded Interrupt Enable Mask */
-#define DEVDMACONTROL_BURST_LCK_Pos 7 /**< (DEVDMACONTROL) Burst Lock Enable Position */
-#define DEVDMACONTROL_BURST_LCK (_U_(0x1) << DEVDMACONTROL_BURST_LCK_Pos) /**< (DEVDMACONTROL) Burst Lock Enable Mask */
-#define DEVDMACONTROL_BUFF_LENGTH_Pos 16 /**< (DEVDMACONTROL) Buffer Byte Length (Write-only) Position */
-#define DEVDMACONTROL_BUFF_LENGTH (_U_(0xFFFF) << DEVDMACONTROL_BUFF_LENGTH_Pos) /**< (DEVDMACONTROL) Buffer Byte Length (Write-only) Mask */
-#define DEVDMACONTROL_Msk _U_(0xFFFF00FF) /**< (DEVDMACONTROL) Register Mask */
-
-
-/* -------- DEVDMASTATUS : (USBHS Offset: 0x0c) (R/W 32) Device DMA Channel Status Register -------- */
-
-#define DEVDMASTATUS_OFFSET (0x0C) /**< (DEVDMASTATUS) Device DMA Channel Status Register Offset */
-
-#define DEVDMASTATUS_CHANN_ENB_Pos 0 /**< (DEVDMASTATUS) Channel Enable Status Position */
-#define DEVDMASTATUS_CHANN_ENB (_U_(0x1) << DEVDMASTATUS_CHANN_ENB_Pos) /**< (DEVDMASTATUS) Channel Enable Status Mask */
-#define DEVDMASTATUS_CHANN_ACT_Pos 1 /**< (DEVDMASTATUS) Channel Active Status Position */
-#define DEVDMASTATUS_CHANN_ACT (_U_(0x1) << DEVDMASTATUS_CHANN_ACT_Pos) /**< (DEVDMASTATUS) Channel Active Status Mask */
-#define DEVDMASTATUS_END_TR_ST_Pos 4 /**< (DEVDMASTATUS) End of Channel Transfer Status Position */
-#define DEVDMASTATUS_END_TR_ST (_U_(0x1) << DEVDMASTATUS_END_TR_ST_Pos) /**< (DEVDMASTATUS) End of Channel Transfer Status Mask */
-#define DEVDMASTATUS_END_BF_ST_Pos 5 /**< (DEVDMASTATUS) End of Channel Buffer Status Position */
-#define DEVDMASTATUS_END_BF_ST (_U_(0x1) << DEVDMASTATUS_END_BF_ST_Pos) /**< (DEVDMASTATUS) End of Channel Buffer Status Mask */
-#define DEVDMASTATUS_DESC_LDST_Pos 6 /**< (DEVDMASTATUS) Descriptor Loaded Status Position */
-#define DEVDMASTATUS_DESC_LDST (_U_(0x1) << DEVDMASTATUS_DESC_LDST_Pos) /**< (DEVDMASTATUS) Descriptor Loaded Status Mask */
-#define DEVDMASTATUS_BUFF_COUNT_Pos 16 /**< (DEVDMASTATUS) Buffer Byte Count Position */
-#define DEVDMASTATUS_BUFF_COUNT (_U_(0xFFFF) << DEVDMASTATUS_BUFF_COUNT_Pos) /**< (DEVDMASTATUS) Buffer Byte Count Mask */
-#define DEVDMASTATUS_Msk _U_(0xFFFF0073) /**< (DEVDMASTATUS) Register Mask */
-
-
-/* -------- HSTDMANXTDSC : (USBHS Offset: 0x00) (R/W 32) Host DMA Channel Next Descriptor Address Register -------- */
-
-#define HSTDMANXTDSC_OFFSET (0x00) /**< (HSTDMANXTDSC) Host DMA Channel Next Descriptor Address Register Offset */
-
-#define HSTDMANXTDSC_NXT_DSC_ADD_Pos 0 /**< (HSTDMANXTDSC) Next Descriptor Address Position */
-#define HSTDMANXTDSC_NXT_DSC_ADD (_U_(0xFFFFFFFF) << HSTDMANXTDSC_NXT_DSC_ADD_Pos) /**< (HSTDMANXTDSC) Next Descriptor Address Mask */
-#define HSTDMANXTDSC_Msk _U_(0xFFFFFFFF) /**< (HSTDMANXTDSC) Register Mask */
-
-
-/* -------- HSTDMAADDRESS : (USBHS Offset: 0x04) (R/W 32) Host DMA Channel Address Register -------- */
-
-#define HSTDMAADDRESS_OFFSET (0x04) /**< (HSTDMAADDRESS) Host DMA Channel Address Register Offset */
-
-#define HSTDMAADDRESS_BUFF_ADD_Pos 0 /**< (HSTDMAADDRESS) Buffer Address Position */
-#define HSTDMAADDRESS_BUFF_ADD (_U_(0xFFFFFFFF) << HSTDMAADDRESS_BUFF_ADD_Pos) /**< (HSTDMAADDRESS) Buffer Address Mask */
-#define HSTDMAADDRESS_Msk _U_(0xFFFFFFFF) /**< (HSTDMAADDRESS) Register Mask */
-
-
-/* -------- HSTDMACONTROL : (USBHS Offset: 0x08) (R/W 32) Host DMA Channel Control Register -------- */
-
-#define HSTDMACONTROL_OFFSET (0x08) /**< (HSTDMACONTROL) Host DMA Channel Control Register Offset */
-
-#define HSTDMACONTROL_CHANN_ENB_Pos 0 /**< (HSTDMACONTROL) Channel Enable Command Position */
-#define HSTDMACONTROL_CHANN_ENB (_U_(0x1) << HSTDMACONTROL_CHANN_ENB_Pos) /**< (HSTDMACONTROL) Channel Enable Command Mask */
-#define HSTDMACONTROL_LDNXT_DSC_Pos 1 /**< (HSTDMACONTROL) Load Next Channel Transfer Descriptor Enable Command Position */
-#define HSTDMACONTROL_LDNXT_DSC (_U_(0x1) << HSTDMACONTROL_LDNXT_DSC_Pos) /**< (HSTDMACONTROL) Load Next Channel Transfer Descriptor Enable Command Mask */
-#define HSTDMACONTROL_END_TR_EN_Pos 2 /**< (HSTDMACONTROL) End of Transfer Enable Control (OUT transfers only) Position */
-#define HSTDMACONTROL_END_TR_EN (_U_(0x1) << HSTDMACONTROL_END_TR_EN_Pos) /**< (HSTDMACONTROL) End of Transfer Enable Control (OUT transfers only) Mask */
-#define HSTDMACONTROL_END_B_EN_Pos 3 /**< (HSTDMACONTROL) End of Buffer Enable Control Position */
-#define HSTDMACONTROL_END_B_EN (_U_(0x1) << HSTDMACONTROL_END_B_EN_Pos) /**< (HSTDMACONTROL) End of Buffer Enable Control Mask */
-#define HSTDMACONTROL_END_TR_IT_Pos 4 /**< (HSTDMACONTROL) End of Transfer Interrupt Enable Position */
-#define HSTDMACONTROL_END_TR_IT (_U_(0x1) << HSTDMACONTROL_END_TR_IT_Pos) /**< (HSTDMACONTROL) End of Transfer Interrupt Enable Mask */
-#define HSTDMACONTROL_END_BUFFIT_Pos 5 /**< (HSTDMACONTROL) End of Buffer Interrupt Enable Position */
-#define HSTDMACONTROL_END_BUFFIT (_U_(0x1) << HSTDMACONTROL_END_BUFFIT_Pos) /**< (HSTDMACONTROL) End of Buffer Interrupt Enable Mask */
-#define HSTDMACONTROL_DESC_LD_IT_Pos 6 /**< (HSTDMACONTROL) Descriptor Loaded Interrupt Enable Position */
-#define HSTDMACONTROL_DESC_LD_IT (_U_(0x1) << HSTDMACONTROL_DESC_LD_IT_Pos) /**< (HSTDMACONTROL) Descriptor Loaded Interrupt Enable Mask */
-#define HSTDMACONTROL_BURST_LCK_Pos 7 /**< (HSTDMACONTROL) Burst Lock Enable Position */
-#define HSTDMACONTROL_BURST_LCK (_U_(0x1) << HSTDMACONTROL_BURST_LCK_Pos) /**< (HSTDMACONTROL) Burst Lock Enable Mask */
-#define HSTDMACONTROL_BUFF_LENGTH_Pos 16 /**< (HSTDMACONTROL) Buffer Byte Length (Write-only) Position */
-#define HSTDMACONTROL_BUFF_LENGTH (_U_(0xFFFF) << HSTDMACONTROL_BUFF_LENGTH_Pos) /**< (HSTDMACONTROL) Buffer Byte Length (Write-only) Mask */
-#define HSTDMACONTROL_Msk _U_(0xFFFF00FF) /**< (HSTDMACONTROL) Register Mask */
-
-
-/* -------- HSTDMASTATUS : (USBHS Offset: 0x0c) (R/W 32) Host DMA Channel Status Register -------- */
-
-#define HSTDMASTATUS_OFFSET (0x0C) /**< (HSTDMASTATUS) Host DMA Channel Status Register Offset */
-
-#define HSTDMASTATUS_CHANN_ENB_Pos 0 /**< (HSTDMASTATUS) Channel Enable Status Position */
-#define HSTDMASTATUS_CHANN_ENB (_U_(0x1) << HSTDMASTATUS_CHANN_ENB_Pos) /**< (HSTDMASTATUS) Channel Enable Status Mask */
-#define HSTDMASTATUS_CHANN_ACT_Pos 1 /**< (HSTDMASTATUS) Channel Active Status Position */
-#define HSTDMASTATUS_CHANN_ACT (_U_(0x1) << HSTDMASTATUS_CHANN_ACT_Pos) /**< (HSTDMASTATUS) Channel Active Status Mask */
-#define HSTDMASTATUS_END_TR_ST_Pos 4 /**< (HSTDMASTATUS) End of Channel Transfer Status Position */
-#define HSTDMASTATUS_END_TR_ST (_U_(0x1) << HSTDMASTATUS_END_TR_ST_Pos) /**< (HSTDMASTATUS) End of Channel Transfer Status Mask */
-#define HSTDMASTATUS_END_BF_ST_Pos 5 /**< (HSTDMASTATUS) End of Channel Buffer Status Position */
-#define HSTDMASTATUS_END_BF_ST (_U_(0x1) << HSTDMASTATUS_END_BF_ST_Pos) /**< (HSTDMASTATUS) End of Channel Buffer Status Mask */
-#define HSTDMASTATUS_DESC_LDST_Pos 6 /**< (HSTDMASTATUS) Descriptor Loaded Status Position */
-#define HSTDMASTATUS_DESC_LDST (_U_(0x1) << HSTDMASTATUS_DESC_LDST_Pos) /**< (HSTDMASTATUS) Descriptor Loaded Status Mask */
-#define HSTDMASTATUS_BUFF_COUNT_Pos 16 /**< (HSTDMASTATUS) Buffer Byte Count Position */
-#define HSTDMASTATUS_BUFF_COUNT (_U_(0xFFFF) << HSTDMASTATUS_BUFF_COUNT_Pos) /**< (HSTDMASTATUS) Buffer Byte Count Mask */
-#define HSTDMASTATUS_Msk _U_(0xFFFF0073) /**< (HSTDMASTATUS) Register Mask */
-
-
-/* -------- DEVCTRL : (USBHS Offset: 0x00) (R/W 32) Device General Control Register -------- */
-
-#define DEVCTRL_OFFSET (0x00) /**< (DEVCTRL) Device General Control Register Offset */
-
-#define DEVCTRL_UADD_Pos 0 /**< (DEVCTRL) USB Address Position */
-#define DEVCTRL_UADD (_U_(0x7F) << DEVCTRL_UADD_Pos) /**< (DEVCTRL) USB Address Mask */
-#define DEVCTRL_ADDEN_Pos 7 /**< (DEVCTRL) Address Enable Position */
-#define DEVCTRL_ADDEN (_U_(0x1) << DEVCTRL_ADDEN_Pos) /**< (DEVCTRL) Address Enable Mask */
-#define DEVCTRL_DETACH_Pos 8 /**< (DEVCTRL) Detach Position */
-#define DEVCTRL_DETACH (_U_(0x1) << DEVCTRL_DETACH_Pos) /**< (DEVCTRL) Detach Mask */
-#define DEVCTRL_RMWKUP_Pos 9 /**< (DEVCTRL) Remote Wake-Up Position */
-#define DEVCTRL_RMWKUP (_U_(0x1) << DEVCTRL_RMWKUP_Pos) /**< (DEVCTRL) Remote Wake-Up Mask */
-#define DEVCTRL_SPDCONF_Pos 10 /**< (DEVCTRL) Mode Configuration Position */
-#define DEVCTRL_SPDCONF (_U_(0x3) << DEVCTRL_SPDCONF_Pos) /**< (DEVCTRL) Mode Configuration Mask */
-#define DEVCTRL_SPDCONF_NORMAL_Val _U_(0x0) /**< (DEVCTRL) The peripheral starts in Full-speed mode and performs a high-speed reset to switch to High-speed mode if the host is high-speed-capable. */
-#define DEVCTRL_SPDCONF_LOW_POWER_Val _U_(0x1) /**< (DEVCTRL) For a better consumption, if high speed is not needed. */
-#define DEVCTRL_SPDCONF_HIGH_SPEED_Val _U_(0x2) /**< (DEVCTRL) Forced high speed. */
-#define DEVCTRL_SPDCONF_FORCED_FS_Val _U_(0x3) /**< (DEVCTRL) The peripheral remains in Full-speed mode whatever the host speed capability. */
-#define DEVCTRL_SPDCONF_NORMAL (DEVCTRL_SPDCONF_NORMAL_Val << DEVCTRL_SPDCONF_Pos) /**< (DEVCTRL) The peripheral starts in Full-speed mode and performs a high-speed reset to switch to High-speed mode if the host is high-speed-capable. Position */
-#define DEVCTRL_SPDCONF_LOW_POWER (DEVCTRL_SPDCONF_LOW_POWER_Val << DEVCTRL_SPDCONF_Pos) /**< (DEVCTRL) For a better consumption, if high speed is not needed. Position */
-#define DEVCTRL_SPDCONF_HIGH_SPEED (DEVCTRL_SPDCONF_HIGH_SPEED_Val << DEVCTRL_SPDCONF_Pos) /**< (DEVCTRL) Forced high speed. Position */
-#define DEVCTRL_SPDCONF_FORCED_FS (DEVCTRL_SPDCONF_FORCED_FS_Val << DEVCTRL_SPDCONF_Pos) /**< (DEVCTRL) The peripheral remains in Full-speed mode whatever the host speed capability. Position */
-#define DEVCTRL_LS_Pos 12 /**< (DEVCTRL) Low-Speed Mode Force Position */
-#define DEVCTRL_LS (_U_(0x1) << DEVCTRL_LS_Pos) /**< (DEVCTRL) Low-Speed Mode Force Mask */
-#define DEVCTRL_TSTJ_Pos 13 /**< (DEVCTRL) Test mode J Position */
-#define DEVCTRL_TSTJ (_U_(0x1) << DEVCTRL_TSTJ_Pos) /**< (DEVCTRL) Test mode J Mask */
-#define DEVCTRL_TSTK_Pos 14 /**< (DEVCTRL) Test mode K Position */
-#define DEVCTRL_TSTK (_U_(0x1) << DEVCTRL_TSTK_Pos) /**< (DEVCTRL) Test mode K Mask */
-#define DEVCTRL_TSTPCKT_Pos 15 /**< (DEVCTRL) Test packet mode Position */
-#define DEVCTRL_TSTPCKT (_U_(0x1) << DEVCTRL_TSTPCKT_Pos) /**< (DEVCTRL) Test packet mode Mask */
-#define DEVCTRL_OPMODE2_Pos 16 /**< (DEVCTRL) Specific Operational mode Position */
-#define DEVCTRL_OPMODE2 (_U_(0x1) << DEVCTRL_OPMODE2_Pos) /**< (DEVCTRL) Specific Operational mode Mask */
-#define DEVCTRL_Msk _U_(0x1FFFF) /**< (DEVCTRL) Register Mask */
-
-#define DEVCTRL_OPMODE_Pos 16 /**< (DEVCTRL Position) Specific Operational mode */
-#define DEVCTRL_OPMODE (_U_(0x1) << DEVCTRL_OPMODE_Pos) /**< (DEVCTRL Mask) OPMODE */
-
-/* -------- DEVISR : (USBHS Offset: 0x04) (R/ 32) Device Global Interrupt Status Register -------- */
-
-#define DEVISR_OFFSET (0x04) /**< (DEVISR) Device Global Interrupt Status Register Offset */
-
-#define DEVISR_SUSP_Pos 0 /**< (DEVISR) Suspend Interrupt Position */
-#define DEVISR_SUSP (_U_(0x1) << DEVISR_SUSP_Pos) /**< (DEVISR) Suspend Interrupt Mask */
-#define DEVISR_MSOF_Pos 1 /**< (DEVISR) Micro Start of Frame Interrupt Position */
-#define DEVISR_MSOF (_U_(0x1) << DEVISR_MSOF_Pos) /**< (DEVISR) Micro Start of Frame Interrupt Mask */
-#define DEVISR_SOF_Pos 2 /**< (DEVISR) Start of Frame Interrupt Position */
-#define DEVISR_SOF (_U_(0x1) << DEVISR_SOF_Pos) /**< (DEVISR) Start of Frame Interrupt Mask */
-#define DEVISR_EORST_Pos 3 /**< (DEVISR) End of Reset Interrupt Position */
-#define DEVISR_EORST (_U_(0x1) << DEVISR_EORST_Pos) /**< (DEVISR) End of Reset Interrupt Mask */
-#define DEVISR_WAKEUP_Pos 4 /**< (DEVISR) Wake-Up Interrupt Position */
-#define DEVISR_WAKEUP (_U_(0x1) << DEVISR_WAKEUP_Pos) /**< (DEVISR) Wake-Up Interrupt Mask */
-#define DEVISR_EORSM_Pos 5 /**< (DEVISR) End of Resume Interrupt Position */
-#define DEVISR_EORSM (_U_(0x1) << DEVISR_EORSM_Pos) /**< (DEVISR) End of Resume Interrupt Mask */
-#define DEVISR_UPRSM_Pos 6 /**< (DEVISR) Upstream Resume Interrupt Position */
-#define DEVISR_UPRSM (_U_(0x1) << DEVISR_UPRSM_Pos) /**< (DEVISR) Upstream Resume Interrupt Mask */
-#define DEVISR_PEP_0_Pos 12 /**< (DEVISR) Endpoint 0 Interrupt Position */
-#define DEVISR_PEP_0 (_U_(0x1) << DEVISR_PEP_0_Pos) /**< (DEVISR) Endpoint 0 Interrupt Mask */
-#define DEVISR_PEP_1_Pos 13 /**< (DEVISR) Endpoint 1 Interrupt Position */
-#define DEVISR_PEP_1 (_U_(0x1) << DEVISR_PEP_1_Pos) /**< (DEVISR) Endpoint 1 Interrupt Mask */
-#define DEVISR_PEP_2_Pos 14 /**< (DEVISR) Endpoint 2 Interrupt Position */
-#define DEVISR_PEP_2 (_U_(0x1) << DEVISR_PEP_2_Pos) /**< (DEVISR) Endpoint 2 Interrupt Mask */
-#define DEVISR_PEP_3_Pos 15 /**< (DEVISR) Endpoint 3 Interrupt Position */
-#define DEVISR_PEP_3 (_U_(0x1) << DEVISR_PEP_3_Pos) /**< (DEVISR) Endpoint 3 Interrupt Mask */
-#define DEVISR_PEP_4_Pos 16 /**< (DEVISR) Endpoint 4 Interrupt Position */
-#define DEVISR_PEP_4 (_U_(0x1) << DEVISR_PEP_4_Pos) /**< (DEVISR) Endpoint 4 Interrupt Mask */
-#define DEVISR_PEP_5_Pos 17 /**< (DEVISR) Endpoint 5 Interrupt Position */
-#define DEVISR_PEP_5 (_U_(0x1) << DEVISR_PEP_5_Pos) /**< (DEVISR) Endpoint 5 Interrupt Mask */
-#define DEVISR_PEP_6_Pos 18 /**< (DEVISR) Endpoint 6 Interrupt Position */
-#define DEVISR_PEP_6 (_U_(0x1) << DEVISR_PEP_6_Pos) /**< (DEVISR) Endpoint 6 Interrupt Mask */
-#define DEVISR_PEP_7_Pos 19 /**< (DEVISR) Endpoint 7 Interrupt Position */
-#define DEVISR_PEP_7 (_U_(0x1) << DEVISR_PEP_7_Pos) /**< (DEVISR) Endpoint 7 Interrupt Mask */
-#define DEVISR_PEP_8_Pos 20 /**< (DEVISR) Endpoint 8 Interrupt Position */
-#define DEVISR_PEP_8 (_U_(0x1) << DEVISR_PEP_8_Pos) /**< (DEVISR) Endpoint 8 Interrupt Mask */
-#define DEVISR_PEP_9_Pos 21 /**< (DEVISR) Endpoint 9 Interrupt Position */
-#define DEVISR_PEP_9 (_U_(0x1) << DEVISR_PEP_9_Pos) /**< (DEVISR) Endpoint 9 Interrupt Mask */
-#define DEVISR_DMA_1_Pos 25 /**< (DEVISR) DMA Channel 1 Interrupt Position */
-#define DEVISR_DMA_1 (_U_(0x1) << DEVISR_DMA_1_Pos) /**< (DEVISR) DMA Channel 1 Interrupt Mask */
-#define DEVISR_DMA_2_Pos 26 /**< (DEVISR) DMA Channel 2 Interrupt Position */
-#define DEVISR_DMA_2 (_U_(0x1) << DEVISR_DMA_2_Pos) /**< (DEVISR) DMA Channel 2 Interrupt Mask */
-#define DEVISR_DMA_3_Pos 27 /**< (DEVISR) DMA Channel 3 Interrupt Position */
-#define DEVISR_DMA_3 (_U_(0x1) << DEVISR_DMA_3_Pos) /**< (DEVISR) DMA Channel 3 Interrupt Mask */
-#define DEVISR_DMA_4_Pos 28 /**< (DEVISR) DMA Channel 4 Interrupt Position */
-#define DEVISR_DMA_4 (_U_(0x1) << DEVISR_DMA_4_Pos) /**< (DEVISR) DMA Channel 4 Interrupt Mask */
-#define DEVISR_DMA_5_Pos 29 /**< (DEVISR) DMA Channel 5 Interrupt Position */
-#define DEVISR_DMA_5 (_U_(0x1) << DEVISR_DMA_5_Pos) /**< (DEVISR) DMA Channel 5 Interrupt Mask */
-#define DEVISR_DMA_6_Pos 30 /**< (DEVISR) DMA Channel 6 Interrupt Position */
-#define DEVISR_DMA_6 (_U_(0x1) << DEVISR_DMA_6_Pos) /**< (DEVISR) DMA Channel 6 Interrupt Mask */
-#define DEVISR_DMA_7_Pos 31 /**< (DEVISR) DMA Channel 7 Interrupt Position */
-#define DEVISR_DMA_7 (_U_(0x1) << DEVISR_DMA_7_Pos) /**< (DEVISR) DMA Channel 7 Interrupt Mask */
-#define DEVISR_Msk _U_(0xFE3FF07F) /**< (DEVISR) Register Mask */
-
-#define DEVISR_PEP__Pos 12 /**< (DEVISR Position) Endpoint x Interrupt */
-#define DEVISR_PEP_ (_U_(0x3FF) << DEVISR_PEP__Pos) /**< (DEVISR Mask) PEP_ */
-#define DEVISR_DMA__Pos 25 /**< (DEVISR Position) DMA Channel 7 Interrupt */
-#define DEVISR_DMA_ (_U_(0x7F) << DEVISR_DMA__Pos) /**< (DEVISR Mask) DMA_ */
-
-/* -------- DEVICR : (USBHS Offset: 0x08) (/W 32) Device Global Interrupt Clear Register -------- */
-
-#define DEVICR_OFFSET (0x08) /**< (DEVICR) Device Global Interrupt Clear Register Offset */
-
-#define DEVICR_SUSPC_Pos 0 /**< (DEVICR) Suspend Interrupt Clear Position */
-#define DEVICR_SUSPC (_U_(0x1) << DEVICR_SUSPC_Pos) /**< (DEVICR) Suspend Interrupt Clear Mask */
-#define DEVICR_MSOFC_Pos 1 /**< (DEVICR) Micro Start of Frame Interrupt Clear Position */
-#define DEVICR_MSOFC (_U_(0x1) << DEVICR_MSOFC_Pos) /**< (DEVICR) Micro Start of Frame Interrupt Clear Mask */
-#define DEVICR_SOFC_Pos 2 /**< (DEVICR) Start of Frame Interrupt Clear Position */
-#define DEVICR_SOFC (_U_(0x1) << DEVICR_SOFC_Pos) /**< (DEVICR) Start of Frame Interrupt Clear Mask */
-#define DEVICR_EORSTC_Pos 3 /**< (DEVICR) End of Reset Interrupt Clear Position */
-#define DEVICR_EORSTC (_U_(0x1) << DEVICR_EORSTC_Pos) /**< (DEVICR) End of Reset Interrupt Clear Mask */
-#define DEVICR_WAKEUPC_Pos 4 /**< (DEVICR) Wake-Up Interrupt Clear Position */
-#define DEVICR_WAKEUPC (_U_(0x1) << DEVICR_WAKEUPC_Pos) /**< (DEVICR) Wake-Up Interrupt Clear Mask */
-#define DEVICR_EORSMC_Pos 5 /**< (DEVICR) End of Resume Interrupt Clear Position */
-#define DEVICR_EORSMC (_U_(0x1) << DEVICR_EORSMC_Pos) /**< (DEVICR) End of Resume Interrupt Clear Mask */
-#define DEVICR_UPRSMC_Pos 6 /**< (DEVICR) Upstream Resume Interrupt Clear Position */
-#define DEVICR_UPRSMC (_U_(0x1) << DEVICR_UPRSMC_Pos) /**< (DEVICR) Upstream Resume Interrupt Clear Mask */
-#define DEVICR_Msk _U_(0x7F) /**< (DEVICR) Register Mask */
-
-
-/* -------- DEVIFR : (USBHS Offset: 0x0c) (/W 32) Device Global Interrupt Set Register -------- */
-
-#define DEVIFR_OFFSET (0x0C) /**< (DEVIFR) Device Global Interrupt Set Register Offset */
-
-#define DEVIFR_SUSPS_Pos 0 /**< (DEVIFR) Suspend Interrupt Set Position */
-#define DEVIFR_SUSPS (_U_(0x1) << DEVIFR_SUSPS_Pos) /**< (DEVIFR) Suspend Interrupt Set Mask */
-#define DEVIFR_MSOFS_Pos 1 /**< (DEVIFR) Micro Start of Frame Interrupt Set Position */
-#define DEVIFR_MSOFS (_U_(0x1) << DEVIFR_MSOFS_Pos) /**< (DEVIFR) Micro Start of Frame Interrupt Set Mask */
-#define DEVIFR_SOFS_Pos 2 /**< (DEVIFR) Start of Frame Interrupt Set Position */
-#define DEVIFR_SOFS (_U_(0x1) << DEVIFR_SOFS_Pos) /**< (DEVIFR) Start of Frame Interrupt Set Mask */
-#define DEVIFR_EORSTS_Pos 3 /**< (DEVIFR) End of Reset Interrupt Set Position */
-#define DEVIFR_EORSTS (_U_(0x1) << DEVIFR_EORSTS_Pos) /**< (DEVIFR) End of Reset Interrupt Set Mask */
-#define DEVIFR_WAKEUPS_Pos 4 /**< (DEVIFR) Wake-Up Interrupt Set Position */
-#define DEVIFR_WAKEUPS (_U_(0x1) << DEVIFR_WAKEUPS_Pos) /**< (DEVIFR) Wake-Up Interrupt Set Mask */
-#define DEVIFR_EORSMS_Pos 5 /**< (DEVIFR) End of Resume Interrupt Set Position */
-#define DEVIFR_EORSMS (_U_(0x1) << DEVIFR_EORSMS_Pos) /**< (DEVIFR) End of Resume Interrupt Set Mask */
-#define DEVIFR_UPRSMS_Pos 6 /**< (DEVIFR) Upstream Resume Interrupt Set Position */
-#define DEVIFR_UPRSMS (_U_(0x1) << DEVIFR_UPRSMS_Pos) /**< (DEVIFR) Upstream Resume Interrupt Set Mask */
-#define DEVIFR_DMA_1_Pos 25 /**< (DEVIFR) DMA Channel 1 Interrupt Set Position */
-#define DEVIFR_DMA_1 (_U_(0x1) << DEVIFR_DMA_1_Pos) /**< (DEVIFR) DMA Channel 1 Interrupt Set Mask */
-#define DEVIFR_DMA_2_Pos 26 /**< (DEVIFR) DMA Channel 2 Interrupt Set Position */
-#define DEVIFR_DMA_2 (_U_(0x1) << DEVIFR_DMA_2_Pos) /**< (DEVIFR) DMA Channel 2 Interrupt Set Mask */
-#define DEVIFR_DMA_3_Pos 27 /**< (DEVIFR) DMA Channel 3 Interrupt Set Position */
-#define DEVIFR_DMA_3 (_U_(0x1) << DEVIFR_DMA_3_Pos) /**< (DEVIFR) DMA Channel 3 Interrupt Set Mask */
-#define DEVIFR_DMA_4_Pos 28 /**< (DEVIFR) DMA Channel 4 Interrupt Set Position */
-#define DEVIFR_DMA_4 (_U_(0x1) << DEVIFR_DMA_4_Pos) /**< (DEVIFR) DMA Channel 4 Interrupt Set Mask */
-#define DEVIFR_DMA_5_Pos 29 /**< (DEVIFR) DMA Channel 5 Interrupt Set Position */
-#define DEVIFR_DMA_5 (_U_(0x1) << DEVIFR_DMA_5_Pos) /**< (DEVIFR) DMA Channel 5 Interrupt Set Mask */
-#define DEVIFR_DMA_6_Pos 30 /**< (DEVIFR) DMA Channel 6 Interrupt Set Position */
-#define DEVIFR_DMA_6 (_U_(0x1) << DEVIFR_DMA_6_Pos) /**< (DEVIFR) DMA Channel 6 Interrupt Set Mask */
-#define DEVIFR_DMA_7_Pos 31 /**< (DEVIFR) DMA Channel 7 Interrupt Set Position */
-#define DEVIFR_DMA_7 (_U_(0x1) << DEVIFR_DMA_7_Pos) /**< (DEVIFR) DMA Channel 7 Interrupt Set Mask */
-#define DEVIFR_Msk _U_(0xFE00007F) /**< (DEVIFR) Register Mask */
-
-#define DEVIFR_DMA__Pos 25 /**< (DEVIFR Position) DMA Channel 7 Interrupt Set */
-#define DEVIFR_DMA_ (_U_(0x7F) << DEVIFR_DMA__Pos) /**< (DEVIFR Mask) DMA_ */
-
-/* -------- DEVIMR : (USBHS Offset: 0x10) (R/ 32) Device Global Interrupt Mask Register -------- */
-
-#define DEVIMR_OFFSET (0x10) /**< (DEVIMR) Device Global Interrupt Mask Register Offset */
-
-#define DEVIMR_SUSPE_Pos 0 /**< (DEVIMR) Suspend Interrupt Mask Position */
-#define DEVIMR_SUSPE (_U_(0x1) << DEVIMR_SUSPE_Pos) /**< (DEVIMR) Suspend Interrupt Mask Mask */
-#define DEVIMR_MSOFE_Pos 1 /**< (DEVIMR) Micro Start of Frame Interrupt Mask Position */
-#define DEVIMR_MSOFE (_U_(0x1) << DEVIMR_MSOFE_Pos) /**< (DEVIMR) Micro Start of Frame Interrupt Mask Mask */
-#define DEVIMR_SOFE_Pos 2 /**< (DEVIMR) Start of Frame Interrupt Mask Position */
-#define DEVIMR_SOFE (_U_(0x1) << DEVIMR_SOFE_Pos) /**< (DEVIMR) Start of Frame Interrupt Mask Mask */
-#define DEVIMR_EORSTE_Pos 3 /**< (DEVIMR) End of Reset Interrupt Mask Position */
-#define DEVIMR_EORSTE (_U_(0x1) << DEVIMR_EORSTE_Pos) /**< (DEVIMR) End of Reset Interrupt Mask Mask */
-#define DEVIMR_WAKEUPE_Pos 4 /**< (DEVIMR) Wake-Up Interrupt Mask Position */
-#define DEVIMR_WAKEUPE (_U_(0x1) << DEVIMR_WAKEUPE_Pos) /**< (DEVIMR) Wake-Up Interrupt Mask Mask */
-#define DEVIMR_EORSME_Pos 5 /**< (DEVIMR) End of Resume Interrupt Mask Position */
-#define DEVIMR_EORSME (_U_(0x1) << DEVIMR_EORSME_Pos) /**< (DEVIMR) End of Resume Interrupt Mask Mask */
-#define DEVIMR_UPRSME_Pos 6 /**< (DEVIMR) Upstream Resume Interrupt Mask Position */
-#define DEVIMR_UPRSME (_U_(0x1) << DEVIMR_UPRSME_Pos) /**< (DEVIMR) Upstream Resume Interrupt Mask Mask */
-#define DEVIMR_PEP_0_Pos 12 /**< (DEVIMR) Endpoint 0 Interrupt Mask Position */
-#define DEVIMR_PEP_0 (_U_(0x1) << DEVIMR_PEP_0_Pos) /**< (DEVIMR) Endpoint 0 Interrupt Mask Mask */
-#define DEVIMR_PEP_1_Pos 13 /**< (DEVIMR) Endpoint 1 Interrupt Mask Position */
-#define DEVIMR_PEP_1 (_U_(0x1) << DEVIMR_PEP_1_Pos) /**< (DEVIMR) Endpoint 1 Interrupt Mask Mask */
-#define DEVIMR_PEP_2_Pos 14 /**< (DEVIMR) Endpoint 2 Interrupt Mask Position */
-#define DEVIMR_PEP_2 (_U_(0x1) << DEVIMR_PEP_2_Pos) /**< (DEVIMR) Endpoint 2 Interrupt Mask Mask */
-#define DEVIMR_PEP_3_Pos 15 /**< (DEVIMR) Endpoint 3 Interrupt Mask Position */
-#define DEVIMR_PEP_3 (_U_(0x1) << DEVIMR_PEP_3_Pos) /**< (DEVIMR) Endpoint 3 Interrupt Mask Mask */
-#define DEVIMR_PEP_4_Pos 16 /**< (DEVIMR) Endpoint 4 Interrupt Mask Position */
-#define DEVIMR_PEP_4 (_U_(0x1) << DEVIMR_PEP_4_Pos) /**< (DEVIMR) Endpoint 4 Interrupt Mask Mask */
-#define DEVIMR_PEP_5_Pos 17 /**< (DEVIMR) Endpoint 5 Interrupt Mask Position */
-#define DEVIMR_PEP_5 (_U_(0x1) << DEVIMR_PEP_5_Pos) /**< (DEVIMR) Endpoint 5 Interrupt Mask Mask */
-#define DEVIMR_PEP_6_Pos 18 /**< (DEVIMR) Endpoint 6 Interrupt Mask Position */
-#define DEVIMR_PEP_6 (_U_(0x1) << DEVIMR_PEP_6_Pos) /**< (DEVIMR) Endpoint 6 Interrupt Mask Mask */
-#define DEVIMR_PEP_7_Pos 19 /**< (DEVIMR) Endpoint 7 Interrupt Mask Position */
-#define DEVIMR_PEP_7 (_U_(0x1) << DEVIMR_PEP_7_Pos) /**< (DEVIMR) Endpoint 7 Interrupt Mask Mask */
-#define DEVIMR_PEP_8_Pos 20 /**< (DEVIMR) Endpoint 8 Interrupt Mask Position */
-#define DEVIMR_PEP_8 (_U_(0x1) << DEVIMR_PEP_8_Pos) /**< (DEVIMR) Endpoint 8 Interrupt Mask Mask */
-#define DEVIMR_PEP_9_Pos 21 /**< (DEVIMR) Endpoint 9 Interrupt Mask Position */
-#define DEVIMR_PEP_9 (_U_(0x1) << DEVIMR_PEP_9_Pos) /**< (DEVIMR) Endpoint 9 Interrupt Mask Mask */
-#define DEVIMR_DMA_1_Pos 25 /**< (DEVIMR) DMA Channel 1 Interrupt Mask Position */
-#define DEVIMR_DMA_1 (_U_(0x1) << DEVIMR_DMA_1_Pos) /**< (DEVIMR) DMA Channel 1 Interrupt Mask Mask */
-#define DEVIMR_DMA_2_Pos 26 /**< (DEVIMR) DMA Channel 2 Interrupt Mask Position */
-#define DEVIMR_DMA_2 (_U_(0x1) << DEVIMR_DMA_2_Pos) /**< (DEVIMR) DMA Channel 2 Interrupt Mask Mask */
-#define DEVIMR_DMA_3_Pos 27 /**< (DEVIMR) DMA Channel 3 Interrupt Mask Position */
-#define DEVIMR_DMA_3 (_U_(0x1) << DEVIMR_DMA_3_Pos) /**< (DEVIMR) DMA Channel 3 Interrupt Mask Mask */
-#define DEVIMR_DMA_4_Pos 28 /**< (DEVIMR) DMA Channel 4 Interrupt Mask Position */
-#define DEVIMR_DMA_4 (_U_(0x1) << DEVIMR_DMA_4_Pos) /**< (DEVIMR) DMA Channel 4 Interrupt Mask Mask */
-#define DEVIMR_DMA_5_Pos 29 /**< (DEVIMR) DMA Channel 5 Interrupt Mask Position */
-#define DEVIMR_DMA_5 (_U_(0x1) << DEVIMR_DMA_5_Pos) /**< (DEVIMR) DMA Channel 5 Interrupt Mask Mask */
-#define DEVIMR_DMA_6_Pos 30 /**< (DEVIMR) DMA Channel 6 Interrupt Mask Position */
-#define DEVIMR_DMA_6 (_U_(0x1) << DEVIMR_DMA_6_Pos) /**< (DEVIMR) DMA Channel 6 Interrupt Mask Mask */
-#define DEVIMR_DMA_7_Pos 31 /**< (DEVIMR) DMA Channel 7 Interrupt Mask Position */
-#define DEVIMR_DMA_7 (_U_(0x1) << DEVIMR_DMA_7_Pos) /**< (DEVIMR) DMA Channel 7 Interrupt Mask Mask */
-#define DEVIMR_Msk _U_(0xFE3FF07F) /**< (DEVIMR) Register Mask */
-
-#define DEVIMR_PEP__Pos 12 /**< (DEVIMR Position) Endpoint x Interrupt Mask */
-#define DEVIMR_PEP_ (_U_(0x3FF) << DEVIMR_PEP__Pos) /**< (DEVIMR Mask) PEP_ */
-#define DEVIMR_DMA__Pos 25 /**< (DEVIMR Position) DMA Channel 7 Interrupt Mask */
-#define DEVIMR_DMA_ (_U_(0x7F) << DEVIMR_DMA__Pos) /**< (DEVIMR Mask) DMA_ */
-
-/* -------- DEVIDR : (USBHS Offset: 0x14) (/W 32) Device Global Interrupt Disable Register -------- */
-
-#define DEVIDR_OFFSET (0x14) /**< (DEVIDR) Device Global Interrupt Disable Register Offset */
-
-#define DEVIDR_SUSPEC_Pos 0 /**< (DEVIDR) Suspend Interrupt Disable Position */
-#define DEVIDR_SUSPEC (_U_(0x1) << DEVIDR_SUSPEC_Pos) /**< (DEVIDR) Suspend Interrupt Disable Mask */
-#define DEVIDR_MSOFEC_Pos 1 /**< (DEVIDR) Micro Start of Frame Interrupt Disable Position */
-#define DEVIDR_MSOFEC (_U_(0x1) << DEVIDR_MSOFEC_Pos) /**< (DEVIDR) Micro Start of Frame Interrupt Disable Mask */
-#define DEVIDR_SOFEC_Pos 2 /**< (DEVIDR) Start of Frame Interrupt Disable Position */
-#define DEVIDR_SOFEC (_U_(0x1) << DEVIDR_SOFEC_Pos) /**< (DEVIDR) Start of Frame Interrupt Disable Mask */
-#define DEVIDR_EORSTEC_Pos 3 /**< (DEVIDR) End of Reset Interrupt Disable Position */
-#define DEVIDR_EORSTEC (_U_(0x1) << DEVIDR_EORSTEC_Pos) /**< (DEVIDR) End of Reset Interrupt Disable Mask */
-#define DEVIDR_WAKEUPEC_Pos 4 /**< (DEVIDR) Wake-Up Interrupt Disable Position */
-#define DEVIDR_WAKEUPEC (_U_(0x1) << DEVIDR_WAKEUPEC_Pos) /**< (DEVIDR) Wake-Up Interrupt Disable Mask */
-#define DEVIDR_EORSMEC_Pos 5 /**< (DEVIDR) End of Resume Interrupt Disable Position */
-#define DEVIDR_EORSMEC (_U_(0x1) << DEVIDR_EORSMEC_Pos) /**< (DEVIDR) End of Resume Interrupt Disable Mask */
-#define DEVIDR_UPRSMEC_Pos 6 /**< (DEVIDR) Upstream Resume Interrupt Disable Position */
-#define DEVIDR_UPRSMEC (_U_(0x1) << DEVIDR_UPRSMEC_Pos) /**< (DEVIDR) Upstream Resume Interrupt Disable Mask */
-#define DEVIDR_PEP_0_Pos 12 /**< (DEVIDR) Endpoint 0 Interrupt Disable Position */
-#define DEVIDR_PEP_0 (_U_(0x1) << DEVIDR_PEP_0_Pos) /**< (DEVIDR) Endpoint 0 Interrupt Disable Mask */
-#define DEVIDR_PEP_1_Pos 13 /**< (DEVIDR) Endpoint 1 Interrupt Disable Position */
-#define DEVIDR_PEP_1 (_U_(0x1) << DEVIDR_PEP_1_Pos) /**< (DEVIDR) Endpoint 1 Interrupt Disable Mask */
-#define DEVIDR_PEP_2_Pos 14 /**< (DEVIDR) Endpoint 2 Interrupt Disable Position */
-#define DEVIDR_PEP_2 (_U_(0x1) << DEVIDR_PEP_2_Pos) /**< (DEVIDR) Endpoint 2 Interrupt Disable Mask */
-#define DEVIDR_PEP_3_Pos 15 /**< (DEVIDR) Endpoint 3 Interrupt Disable Position */
-#define DEVIDR_PEP_3 (_U_(0x1) << DEVIDR_PEP_3_Pos) /**< (DEVIDR) Endpoint 3 Interrupt Disable Mask */
-#define DEVIDR_PEP_4_Pos 16 /**< (DEVIDR) Endpoint 4 Interrupt Disable Position */
-#define DEVIDR_PEP_4 (_U_(0x1) << DEVIDR_PEP_4_Pos) /**< (DEVIDR) Endpoint 4 Interrupt Disable Mask */
-#define DEVIDR_PEP_5_Pos 17 /**< (DEVIDR) Endpoint 5 Interrupt Disable Position */
-#define DEVIDR_PEP_5 (_U_(0x1) << DEVIDR_PEP_5_Pos) /**< (DEVIDR) Endpoint 5 Interrupt Disable Mask */
-#define DEVIDR_PEP_6_Pos 18 /**< (DEVIDR) Endpoint 6 Interrupt Disable Position */
-#define DEVIDR_PEP_6 (_U_(0x1) << DEVIDR_PEP_6_Pos) /**< (DEVIDR) Endpoint 6 Interrupt Disable Mask */
-#define DEVIDR_PEP_7_Pos 19 /**< (DEVIDR) Endpoint 7 Interrupt Disable Position */
-#define DEVIDR_PEP_7 (_U_(0x1) << DEVIDR_PEP_7_Pos) /**< (DEVIDR) Endpoint 7 Interrupt Disable Mask */
-#define DEVIDR_PEP_8_Pos 20 /**< (DEVIDR) Endpoint 8 Interrupt Disable Position */
-#define DEVIDR_PEP_8 (_U_(0x1) << DEVIDR_PEP_8_Pos) /**< (DEVIDR) Endpoint 8 Interrupt Disable Mask */
-#define DEVIDR_PEP_9_Pos 21 /**< (DEVIDR) Endpoint 9 Interrupt Disable Position */
-#define DEVIDR_PEP_9 (_U_(0x1) << DEVIDR_PEP_9_Pos) /**< (DEVIDR) Endpoint 9 Interrupt Disable Mask */
-#define DEVIDR_DMA_1_Pos 25 /**< (DEVIDR) DMA Channel 1 Interrupt Disable Position */
-#define DEVIDR_DMA_1 (_U_(0x1) << DEVIDR_DMA_1_Pos) /**< (DEVIDR) DMA Channel 1 Interrupt Disable Mask */
-#define DEVIDR_DMA_2_Pos 26 /**< (DEVIDR) DMA Channel 2 Interrupt Disable Position */
-#define DEVIDR_DMA_2 (_U_(0x1) << DEVIDR_DMA_2_Pos) /**< (DEVIDR) DMA Channel 2 Interrupt Disable Mask */
-#define DEVIDR_DMA_3_Pos 27 /**< (DEVIDR) DMA Channel 3 Interrupt Disable Position */
-#define DEVIDR_DMA_3 (_U_(0x1) << DEVIDR_DMA_3_Pos) /**< (DEVIDR) DMA Channel 3 Interrupt Disable Mask */
-#define DEVIDR_DMA_4_Pos 28 /**< (DEVIDR) DMA Channel 4 Interrupt Disable Position */
-#define DEVIDR_DMA_4 (_U_(0x1) << DEVIDR_DMA_4_Pos) /**< (DEVIDR) DMA Channel 4 Interrupt Disable Mask */
-#define DEVIDR_DMA_5_Pos 29 /**< (DEVIDR) DMA Channel 5 Interrupt Disable Position */
-#define DEVIDR_DMA_5 (_U_(0x1) << DEVIDR_DMA_5_Pos) /**< (DEVIDR) DMA Channel 5 Interrupt Disable Mask */
-#define DEVIDR_DMA_6_Pos 30 /**< (DEVIDR) DMA Channel 6 Interrupt Disable Position */
-#define DEVIDR_DMA_6 (_U_(0x1) << DEVIDR_DMA_6_Pos) /**< (DEVIDR) DMA Channel 6 Interrupt Disable Mask */
-#define DEVIDR_DMA_7_Pos 31 /**< (DEVIDR) DMA Channel 7 Interrupt Disable Position */
-#define DEVIDR_DMA_7 (_U_(0x1) << DEVIDR_DMA_7_Pos) /**< (DEVIDR) DMA Channel 7 Interrupt Disable Mask */
-#define DEVIDR_Msk _U_(0xFE3FF07F) /**< (DEVIDR) Register Mask */
-
-#define DEVIDR_PEP__Pos 12 /**< (DEVIDR Position) Endpoint x Interrupt Disable */
-#define DEVIDR_PEP_ (_U_(0x3FF) << DEVIDR_PEP__Pos) /**< (DEVIDR Mask) PEP_ */
-#define DEVIDR_DMA__Pos 25 /**< (DEVIDR Position) DMA Channel 7 Interrupt Disable */
-#define DEVIDR_DMA_ (_U_(0x7F) << DEVIDR_DMA__Pos) /**< (DEVIDR Mask) DMA_ */
-
-/* -------- DEVIER : (USBHS Offset: 0x18) (/W 32) Device Global Interrupt Enable Register -------- */
-
-#define DEVIER_OFFSET (0x18) /**< (DEVIER) Device Global Interrupt Enable Register Offset */
-
-#define DEVIER_SUSPES_Pos 0 /**< (DEVIER) Suspend Interrupt Enable Position */
-#define DEVIER_SUSPES (_U_(0x1) << DEVIER_SUSPES_Pos) /**< (DEVIER) Suspend Interrupt Enable Mask */
-#define DEVIER_MSOFES_Pos 1 /**< (DEVIER) Micro Start of Frame Interrupt Enable Position */
-#define DEVIER_MSOFES (_U_(0x1) << DEVIER_MSOFES_Pos) /**< (DEVIER) Micro Start of Frame Interrupt Enable Mask */
-#define DEVIER_SOFES_Pos 2 /**< (DEVIER) Start of Frame Interrupt Enable Position */
-#define DEVIER_SOFES (_U_(0x1) << DEVIER_SOFES_Pos) /**< (DEVIER) Start of Frame Interrupt Enable Mask */
-#define DEVIER_EORSTES_Pos 3 /**< (DEVIER) End of Reset Interrupt Enable Position */
-#define DEVIER_EORSTES (_U_(0x1) << DEVIER_EORSTES_Pos) /**< (DEVIER) End of Reset Interrupt Enable Mask */
-#define DEVIER_WAKEUPES_Pos 4 /**< (DEVIER) Wake-Up Interrupt Enable Position */
-#define DEVIER_WAKEUPES (_U_(0x1) << DEVIER_WAKEUPES_Pos) /**< (DEVIER) Wake-Up Interrupt Enable Mask */
-#define DEVIER_EORSMES_Pos 5 /**< (DEVIER) End of Resume Interrupt Enable Position */
-#define DEVIER_EORSMES (_U_(0x1) << DEVIER_EORSMES_Pos) /**< (DEVIER) End of Resume Interrupt Enable Mask */
-#define DEVIER_UPRSMES_Pos 6 /**< (DEVIER) Upstream Resume Interrupt Enable Position */
-#define DEVIER_UPRSMES (_U_(0x1) << DEVIER_UPRSMES_Pos) /**< (DEVIER) Upstream Resume Interrupt Enable Mask */
-#define DEVIER_PEP_0_Pos 12 /**< (DEVIER) Endpoint 0 Interrupt Enable Position */
-#define DEVIER_PEP_0 (_U_(0x1) << DEVIER_PEP_0_Pos) /**< (DEVIER) Endpoint 0 Interrupt Enable Mask */
-#define DEVIER_PEP_1_Pos 13 /**< (DEVIER) Endpoint 1 Interrupt Enable Position */
-#define DEVIER_PEP_1 (_U_(0x1) << DEVIER_PEP_1_Pos) /**< (DEVIER) Endpoint 1 Interrupt Enable Mask */
-#define DEVIER_PEP_2_Pos 14 /**< (DEVIER) Endpoint 2 Interrupt Enable Position */
-#define DEVIER_PEP_2 (_U_(0x1) << DEVIER_PEP_2_Pos) /**< (DEVIER) Endpoint 2 Interrupt Enable Mask */
-#define DEVIER_PEP_3_Pos 15 /**< (DEVIER) Endpoint 3 Interrupt Enable Position */
-#define DEVIER_PEP_3 (_U_(0x1) << DEVIER_PEP_3_Pos) /**< (DEVIER) Endpoint 3 Interrupt Enable Mask */
-#define DEVIER_PEP_4_Pos 16 /**< (DEVIER) Endpoint 4 Interrupt Enable Position */
-#define DEVIER_PEP_4 (_U_(0x1) << DEVIER_PEP_4_Pos) /**< (DEVIER) Endpoint 4 Interrupt Enable Mask */
-#define DEVIER_PEP_5_Pos 17 /**< (DEVIER) Endpoint 5 Interrupt Enable Position */
-#define DEVIER_PEP_5 (_U_(0x1) << DEVIER_PEP_5_Pos) /**< (DEVIER) Endpoint 5 Interrupt Enable Mask */
-#define DEVIER_PEP_6_Pos 18 /**< (DEVIER) Endpoint 6 Interrupt Enable Position */
-#define DEVIER_PEP_6 (_U_(0x1) << DEVIER_PEP_6_Pos) /**< (DEVIER) Endpoint 6 Interrupt Enable Mask */
-#define DEVIER_PEP_7_Pos 19 /**< (DEVIER) Endpoint 7 Interrupt Enable Position */
-#define DEVIER_PEP_7 (_U_(0x1) << DEVIER_PEP_7_Pos) /**< (DEVIER) Endpoint 7 Interrupt Enable Mask */
-#define DEVIER_PEP_8_Pos 20 /**< (DEVIER) Endpoint 8 Interrupt Enable Position */
-#define DEVIER_PEP_8 (_U_(0x1) << DEVIER_PEP_8_Pos) /**< (DEVIER) Endpoint 8 Interrupt Enable Mask */
-#define DEVIER_PEP_9_Pos 21 /**< (DEVIER) Endpoint 9 Interrupt Enable Position */
-#define DEVIER_PEP_9 (_U_(0x1) << DEVIER_PEP_9_Pos) /**< (DEVIER) Endpoint 9 Interrupt Enable Mask */
-#define DEVIER_DMA_1_Pos 25 /**< (DEVIER) DMA Channel 1 Interrupt Enable Position */
-#define DEVIER_DMA_1 (_U_(0x1) << DEVIER_DMA_1_Pos) /**< (DEVIER) DMA Channel 1 Interrupt Enable Mask */
-#define DEVIER_DMA_2_Pos 26 /**< (DEVIER) DMA Channel 2 Interrupt Enable Position */
-#define DEVIER_DMA_2 (_U_(0x1) << DEVIER_DMA_2_Pos) /**< (DEVIER) DMA Channel 2 Interrupt Enable Mask */
-#define DEVIER_DMA_3_Pos 27 /**< (DEVIER) DMA Channel 3 Interrupt Enable Position */
-#define DEVIER_DMA_3 (_U_(0x1) << DEVIER_DMA_3_Pos) /**< (DEVIER) DMA Channel 3 Interrupt Enable Mask */
-#define DEVIER_DMA_4_Pos 28 /**< (DEVIER) DMA Channel 4 Interrupt Enable Position */
-#define DEVIER_DMA_4 (_U_(0x1) << DEVIER_DMA_4_Pos) /**< (DEVIER) DMA Channel 4 Interrupt Enable Mask */
-#define DEVIER_DMA_5_Pos 29 /**< (DEVIER) DMA Channel 5 Interrupt Enable Position */
-#define DEVIER_DMA_5 (_U_(0x1) << DEVIER_DMA_5_Pos) /**< (DEVIER) DMA Channel 5 Interrupt Enable Mask */
-#define DEVIER_DMA_6_Pos 30 /**< (DEVIER) DMA Channel 6 Interrupt Enable Position */
-#define DEVIER_DMA_6 (_U_(0x1) << DEVIER_DMA_6_Pos) /**< (DEVIER) DMA Channel 6 Interrupt Enable Mask */
-#define DEVIER_DMA_7_Pos 31 /**< (DEVIER) DMA Channel 7 Interrupt Enable Position */
-#define DEVIER_DMA_7 (_U_(0x1) << DEVIER_DMA_7_Pos) /**< (DEVIER) DMA Channel 7 Interrupt Enable Mask */
-#define DEVIER_Msk _U_(0xFE3FF07F) /**< (DEVIER) Register Mask */
-
-#define DEVIER_PEP__Pos 12 /**< (DEVIER Position) Endpoint x Interrupt Enable */
-#define DEVIER_PEP_ (_U_(0x3FF) << DEVIER_PEP__Pos) /**< (DEVIER Mask) PEP_ */
-#define DEVIER_DMA__Pos 25 /**< (DEVIER Position) DMA Channel 7 Interrupt Enable */
-#define DEVIER_DMA_ (_U_(0x7F) << DEVIER_DMA__Pos) /**< (DEVIER Mask) DMA_ */
-
-/* -------- DEVEPT : (USBHS Offset: 0x1c) (R/W 32) Device Endpoint Register -------- */
-
-#define DEVEPT_OFFSET (0x1C) /**< (DEVEPT) Device Endpoint Register Offset */
-
-#define DEVEPT_EPEN0_Pos 0 /**< (DEVEPT) Endpoint 0 Enable Position */
-#define DEVEPT_EPEN0 (_U_(0x1) << DEVEPT_EPEN0_Pos) /**< (DEVEPT) Endpoint 0 Enable Mask */
-#define DEVEPT_EPEN1_Pos 1 /**< (DEVEPT) Endpoint 1 Enable Position */
-#define DEVEPT_EPEN1 (_U_(0x1) << DEVEPT_EPEN1_Pos) /**< (DEVEPT) Endpoint 1 Enable Mask */
-#define DEVEPT_EPEN2_Pos 2 /**< (DEVEPT) Endpoint 2 Enable Position */
-#define DEVEPT_EPEN2 (_U_(0x1) << DEVEPT_EPEN2_Pos) /**< (DEVEPT) Endpoint 2 Enable Mask */
-#define DEVEPT_EPEN3_Pos 3 /**< (DEVEPT) Endpoint 3 Enable Position */
-#define DEVEPT_EPEN3 (_U_(0x1) << DEVEPT_EPEN3_Pos) /**< (DEVEPT) Endpoint 3 Enable Mask */
-#define DEVEPT_EPEN4_Pos 4 /**< (DEVEPT) Endpoint 4 Enable Position */
-#define DEVEPT_EPEN4 (_U_(0x1) << DEVEPT_EPEN4_Pos) /**< (DEVEPT) Endpoint 4 Enable Mask */
-#define DEVEPT_EPEN5_Pos 5 /**< (DEVEPT) Endpoint 5 Enable Position */
-#define DEVEPT_EPEN5 (_U_(0x1) << DEVEPT_EPEN5_Pos) /**< (DEVEPT) Endpoint 5 Enable Mask */
-#define DEVEPT_EPEN6_Pos 6 /**< (DEVEPT) Endpoint 6 Enable Position */
-#define DEVEPT_EPEN6 (_U_(0x1) << DEVEPT_EPEN6_Pos) /**< (DEVEPT) Endpoint 6 Enable Mask */
-#define DEVEPT_EPEN7_Pos 7 /**< (DEVEPT) Endpoint 7 Enable Position */
-#define DEVEPT_EPEN7 (_U_(0x1) << DEVEPT_EPEN7_Pos) /**< (DEVEPT) Endpoint 7 Enable Mask */
-#define DEVEPT_EPEN8_Pos 8 /**< (DEVEPT) Endpoint 8 Enable Position */
-#define DEVEPT_EPEN8 (_U_(0x1) << DEVEPT_EPEN8_Pos) /**< (DEVEPT) Endpoint 8 Enable Mask */
-#define DEVEPT_EPEN9_Pos 9 /**< (DEVEPT) Endpoint 9 Enable Position */
-#define DEVEPT_EPEN9 (_U_(0x1) << DEVEPT_EPEN9_Pos) /**< (DEVEPT) Endpoint 9 Enable Mask */
-#define DEVEPT_EPRST0_Pos 16 /**< (DEVEPT) Endpoint 0 Reset Position */
-#define DEVEPT_EPRST0 (_U_(0x1) << DEVEPT_EPRST0_Pos) /**< (DEVEPT) Endpoint 0 Reset Mask */
-#define DEVEPT_EPRST1_Pos 17 /**< (DEVEPT) Endpoint 1 Reset Position */
-#define DEVEPT_EPRST1 (_U_(0x1) << DEVEPT_EPRST1_Pos) /**< (DEVEPT) Endpoint 1 Reset Mask */
-#define DEVEPT_EPRST2_Pos 18 /**< (DEVEPT) Endpoint 2 Reset Position */
-#define DEVEPT_EPRST2 (_U_(0x1) << DEVEPT_EPRST2_Pos) /**< (DEVEPT) Endpoint 2 Reset Mask */
-#define DEVEPT_EPRST3_Pos 19 /**< (DEVEPT) Endpoint 3 Reset Position */
-#define DEVEPT_EPRST3 (_U_(0x1) << DEVEPT_EPRST3_Pos) /**< (DEVEPT) Endpoint 3 Reset Mask */
-#define DEVEPT_EPRST4_Pos 20 /**< (DEVEPT) Endpoint 4 Reset Position */
-#define DEVEPT_EPRST4 (_U_(0x1) << DEVEPT_EPRST4_Pos) /**< (DEVEPT) Endpoint 4 Reset Mask */
-#define DEVEPT_EPRST5_Pos 21 /**< (DEVEPT) Endpoint 5 Reset Position */
-#define DEVEPT_EPRST5 (_U_(0x1) << DEVEPT_EPRST5_Pos) /**< (DEVEPT) Endpoint 5 Reset Mask */
-#define DEVEPT_EPRST6_Pos 22 /**< (DEVEPT) Endpoint 6 Reset Position */
-#define DEVEPT_EPRST6 (_U_(0x1) << DEVEPT_EPRST6_Pos) /**< (DEVEPT) Endpoint 6 Reset Mask */
-#define DEVEPT_EPRST7_Pos 23 /**< (DEVEPT) Endpoint 7 Reset Position */
-#define DEVEPT_EPRST7 (_U_(0x1) << DEVEPT_EPRST7_Pos) /**< (DEVEPT) Endpoint 7 Reset Mask */
-#define DEVEPT_EPRST8_Pos 24 /**< (DEVEPT) Endpoint 8 Reset Position */
-#define DEVEPT_EPRST8 (_U_(0x1) << DEVEPT_EPRST8_Pos) /**< (DEVEPT) Endpoint 8 Reset Mask */
-#define DEVEPT_EPRST9_Pos 25 /**< (DEVEPT) Endpoint 9 Reset Position */
-#define DEVEPT_EPRST9 (_U_(0x1) << DEVEPT_EPRST9_Pos) /**< (DEVEPT) Endpoint 9 Reset Mask */
-#define DEVEPT_Msk _U_(0x3FF03FF) /**< (DEVEPT) Register Mask */
-
-#define DEVEPT_EPEN_Pos 0 /**< (DEVEPT Position) Endpoint x Enable */
-#define DEVEPT_EPEN (_U_(0x3FF) << DEVEPT_EPEN_Pos) /**< (DEVEPT Mask) EPEN */
-#define DEVEPT_EPRST_Pos 16 /**< (DEVEPT Position) Endpoint 9 Reset */
-#define DEVEPT_EPRST (_U_(0x3FF) << DEVEPT_EPRST_Pos) /**< (DEVEPT Mask) EPRST */
-
-/* -------- DEVFNUM : (USBHS Offset: 0x20) (R/ 32) Device Frame Number Register -------- */
-
-#define DEVFNUM_OFFSET (0x20) /**< (DEVFNUM) Device Frame Number Register Offset */
-
-#define DEVFNUM_MFNUM_Pos 0 /**< (DEVFNUM) Micro Frame Number Position */
-#define DEVFNUM_MFNUM (_U_(0x7) << DEVFNUM_MFNUM_Pos) /**< (DEVFNUM) Micro Frame Number Mask */
-#define DEVFNUM_FNUM_Pos 3 /**< (DEVFNUM) Frame Number Position */
-#define DEVFNUM_FNUM (_U_(0x7FF) << DEVFNUM_FNUM_Pos) /**< (DEVFNUM) Frame Number Mask */
-#define DEVFNUM_FNCERR_Pos 15 /**< (DEVFNUM) Frame Number CRC Error Position */
-#define DEVFNUM_FNCERR (_U_(0x1) << DEVFNUM_FNCERR_Pos) /**< (DEVFNUM) Frame Number CRC Error Mask */
-#define DEVFNUM_Msk _U_(0xBFFF) /**< (DEVFNUM) Register Mask */
-
-
-/* -------- DEVEPTCFG : (USBHS Offset: 0x100) (R/W 32) Device Endpoint Configuration Register -------- */
-
-#define DEVEPTCFG_OFFSET (0x100) /**< (DEVEPTCFG) Device Endpoint Configuration Register Offset */
-
-#define DEVEPTCFG_ALLOC_Pos 1 /**< (DEVEPTCFG) Endpoint Memory Allocate Position */
-#define DEVEPTCFG_ALLOC (_U_(0x1) << DEVEPTCFG_ALLOC_Pos) /**< (DEVEPTCFG) Endpoint Memory Allocate Mask */
-#define DEVEPTCFG_EPBK_Pos 2 /**< (DEVEPTCFG) Endpoint Banks Position */
-#define DEVEPTCFG_EPBK (_U_(0x3) << DEVEPTCFG_EPBK_Pos) /**< (DEVEPTCFG) Endpoint Banks Mask */
-#define DEVEPTCFG_EPBK_1_BANK_Val _U_(0x0) /**< (DEVEPTCFG) Single-bank endpoint */
-#define DEVEPTCFG_EPBK_2_BANK_Val _U_(0x1) /**< (DEVEPTCFG) Double-bank endpoint */
-#define DEVEPTCFG_EPBK_3_BANK_Val _U_(0x2) /**< (DEVEPTCFG) Triple-bank endpoint */
-#define DEVEPTCFG_EPBK_1_BANK (DEVEPTCFG_EPBK_1_BANK_Val << DEVEPTCFG_EPBK_Pos) /**< (DEVEPTCFG) Single-bank endpoint Position */
-#define DEVEPTCFG_EPBK_2_BANK (DEVEPTCFG_EPBK_2_BANK_Val << DEVEPTCFG_EPBK_Pos) /**< (DEVEPTCFG) Double-bank endpoint Position */
-#define DEVEPTCFG_EPBK_3_BANK (DEVEPTCFG_EPBK_3_BANK_Val << DEVEPTCFG_EPBK_Pos) /**< (DEVEPTCFG) Triple-bank endpoint Position */
-#define DEVEPTCFG_EPSIZE_Pos 4 /**< (DEVEPTCFG) Endpoint Size Position */
-#define DEVEPTCFG_EPSIZE (_U_(0x7) << DEVEPTCFG_EPSIZE_Pos) /**< (DEVEPTCFG) Endpoint Size Mask */
-#define DEVEPTCFG_EPSIZE_8_BYTE_Val _U_(0x0) /**< (DEVEPTCFG) 8 bytes */
-#define DEVEPTCFG_EPSIZE_16_BYTE_Val _U_(0x1) /**< (DEVEPTCFG) 16 bytes */
-#define DEVEPTCFG_EPSIZE_32_BYTE_Val _U_(0x2) /**< (DEVEPTCFG) 32 bytes */
-#define DEVEPTCFG_EPSIZE_64_BYTE_Val _U_(0x3) /**< (DEVEPTCFG) 64 bytes */
-#define DEVEPTCFG_EPSIZE_128_BYTE_Val _U_(0x4) /**< (DEVEPTCFG) 128 bytes */
-#define DEVEPTCFG_EPSIZE_256_BYTE_Val _U_(0x5) /**< (DEVEPTCFG) 256 bytes */
-#define DEVEPTCFG_EPSIZE_512_BYTE_Val _U_(0x6) /**< (DEVEPTCFG) 512 bytes */
-#define DEVEPTCFG_EPSIZE_1024_BYTE_Val _U_(0x7) /**< (DEVEPTCFG) 1024 bytes */
-#define DEVEPTCFG_EPSIZE_8_BYTE (DEVEPTCFG_EPSIZE_8_BYTE_Val << DEVEPTCFG_EPSIZE_Pos) /**< (DEVEPTCFG) 8 bytes Position */
-#define DEVEPTCFG_EPSIZE_16_BYTE (DEVEPTCFG_EPSIZE_16_BYTE_Val << DEVEPTCFG_EPSIZE_Pos) /**< (DEVEPTCFG) 16 bytes Position */
-#define DEVEPTCFG_EPSIZE_32_BYTE (DEVEPTCFG_EPSIZE_32_BYTE_Val << DEVEPTCFG_EPSIZE_Pos) /**< (DEVEPTCFG) 32 bytes Position */
-#define DEVEPTCFG_EPSIZE_64_BYTE (DEVEPTCFG_EPSIZE_64_BYTE_Val << DEVEPTCFG_EPSIZE_Pos) /**< (DEVEPTCFG) 64 bytes Position */
-#define DEVEPTCFG_EPSIZE_128_BYTE (DEVEPTCFG_EPSIZE_128_BYTE_Val << DEVEPTCFG_EPSIZE_Pos) /**< (DEVEPTCFG) 128 bytes Position */
-#define DEVEPTCFG_EPSIZE_256_BYTE (DEVEPTCFG_EPSIZE_256_BYTE_Val << DEVEPTCFG_EPSIZE_Pos) /**< (DEVEPTCFG) 256 bytes Position */
-#define DEVEPTCFG_EPSIZE_512_BYTE (DEVEPTCFG_EPSIZE_512_BYTE_Val << DEVEPTCFG_EPSIZE_Pos) /**< (DEVEPTCFG) 512 bytes Position */
-#define DEVEPTCFG_EPSIZE_1024_BYTE (DEVEPTCFG_EPSIZE_1024_BYTE_Val << DEVEPTCFG_EPSIZE_Pos) /**< (DEVEPTCFG) 1024 bytes Position */
-#define DEVEPTCFG_EPDIR_Pos 8 /**< (DEVEPTCFG) Endpoint Direction Position */
-#define DEVEPTCFG_EPDIR (_U_(0x1) << DEVEPTCFG_EPDIR_Pos) /**< (DEVEPTCFG) Endpoint Direction Mask */
-#define DEVEPTCFG_EPDIR_OUT_Val _U_(0x0) /**< (DEVEPTCFG) The endpoint direction is OUT. */
-#define DEVEPTCFG_EPDIR_IN_Val _U_(0x1) /**< (DEVEPTCFG) The endpoint direction is IN (nor for control endpoints). */
-#define DEVEPTCFG_EPDIR_OUT (DEVEPTCFG_EPDIR_OUT_Val << DEVEPTCFG_EPDIR_Pos) /**< (DEVEPTCFG) The endpoint direction is OUT. Position */
-#define DEVEPTCFG_EPDIR_IN (DEVEPTCFG_EPDIR_IN_Val << DEVEPTCFG_EPDIR_Pos) /**< (DEVEPTCFG) The endpoint direction is IN (nor for control endpoints). Position */
-#define DEVEPTCFG_AUTOSW_Pos 9 /**< (DEVEPTCFG) Automatic Switch Position */
-#define DEVEPTCFG_AUTOSW (_U_(0x1) << DEVEPTCFG_AUTOSW_Pos) /**< (DEVEPTCFG) Automatic Switch Mask */
-#define DEVEPTCFG_EPTYPE_Pos 11 /**< (DEVEPTCFG) Endpoint Type Position */
-#define DEVEPTCFG_EPTYPE (_U_(0x3) << DEVEPTCFG_EPTYPE_Pos) /**< (DEVEPTCFG) Endpoint Type Mask */
-#define DEVEPTCFG_EPTYPE_CTRL_Val _U_(0x0) /**< (DEVEPTCFG) Control */
-#define DEVEPTCFG_EPTYPE_ISO_Val _U_(0x1) /**< (DEVEPTCFG) Isochronous */
-#define DEVEPTCFG_EPTYPE_BLK_Val _U_(0x2) /**< (DEVEPTCFG) Bulk */
-#define DEVEPTCFG_EPTYPE_INTRPT_Val _U_(0x3) /**< (DEVEPTCFG) Interrupt */
-#define DEVEPTCFG_EPTYPE_CTRL (DEVEPTCFG_EPTYPE_CTRL_Val << DEVEPTCFG_EPTYPE_Pos) /**< (DEVEPTCFG) Control Position */
-#define DEVEPTCFG_EPTYPE_ISO (DEVEPTCFG_EPTYPE_ISO_Val << DEVEPTCFG_EPTYPE_Pos) /**< (DEVEPTCFG) Isochronous Position */
-#define DEVEPTCFG_EPTYPE_BLK (DEVEPTCFG_EPTYPE_BLK_Val << DEVEPTCFG_EPTYPE_Pos) /**< (DEVEPTCFG) Bulk Position */
-#define DEVEPTCFG_EPTYPE_INTRPT (DEVEPTCFG_EPTYPE_INTRPT_Val << DEVEPTCFG_EPTYPE_Pos) /**< (DEVEPTCFG) Interrupt Position */
-#define DEVEPTCFG_NBTRANS_Pos 13 /**< (DEVEPTCFG) Number of transactions per microframe for isochronous endpoint Position */
-#define DEVEPTCFG_NBTRANS (_U_(0x3) << DEVEPTCFG_NBTRANS_Pos) /**< (DEVEPTCFG) Number of transactions per microframe for isochronous endpoint Mask */
-#define DEVEPTCFG_NBTRANS_0_TRANS_Val _U_(0x0) /**< (DEVEPTCFG) Reserved to endpoint that does not have the high-bandwidth isochronous capability. */
-#define DEVEPTCFG_NBTRANS_1_TRANS_Val _U_(0x1) /**< (DEVEPTCFG) Default value: one transaction per microframe. */
-#define DEVEPTCFG_NBTRANS_2_TRANS_Val _U_(0x2) /**< (DEVEPTCFG) Two transactions per microframe. This endpoint should be configured as double-bank. */
-#define DEVEPTCFG_NBTRANS_3_TRANS_Val _U_(0x3) /**< (DEVEPTCFG) Three transactions per microframe. This endpoint should be configured as triple-bank. */
-#define DEVEPTCFG_NBTRANS_0_TRANS (DEVEPTCFG_NBTRANS_0_TRANS_Val << DEVEPTCFG_NBTRANS_Pos) /**< (DEVEPTCFG) Reserved to endpoint that does not have the high-bandwidth isochronous capability. Position */
-#define DEVEPTCFG_NBTRANS_1_TRANS (DEVEPTCFG_NBTRANS_1_TRANS_Val << DEVEPTCFG_NBTRANS_Pos) /**< (DEVEPTCFG) Default value: one transaction per microframe. Position */
-#define DEVEPTCFG_NBTRANS_2_TRANS (DEVEPTCFG_NBTRANS_2_TRANS_Val << DEVEPTCFG_NBTRANS_Pos) /**< (DEVEPTCFG) Two transactions per microframe. This endpoint should be configured as double-bank. Position */
-#define DEVEPTCFG_NBTRANS_3_TRANS (DEVEPTCFG_NBTRANS_3_TRANS_Val << DEVEPTCFG_NBTRANS_Pos) /**< (DEVEPTCFG) Three transactions per microframe. This endpoint should be configured as triple-bank. Position */
-#define DEVEPTCFG_Msk _U_(0x7B7E) /**< (DEVEPTCFG) Register Mask */
-
-
-/* -------- DEVEPTISR : (USBHS Offset: 0x130) (R/ 32) Device Endpoint Interrupt Status Register -------- */
-
-#define DEVEPTISR_OFFSET (0x130) /**< (DEVEPTISR) Device Endpoint Interrupt Status Register Offset */
-
-#define DEVEPTISR_TXINI_Pos 0 /**< (DEVEPTISR) Transmitted IN Data Interrupt Position */
-#define DEVEPTISR_TXINI (_U_(0x1) << DEVEPTISR_TXINI_Pos) /**< (DEVEPTISR) Transmitted IN Data Interrupt Mask */
-#define DEVEPTISR_RXOUTI_Pos 1 /**< (DEVEPTISR) Received OUT Data Interrupt Position */
-#define DEVEPTISR_RXOUTI (_U_(0x1) << DEVEPTISR_RXOUTI_Pos) /**< (DEVEPTISR) Received OUT Data Interrupt Mask */
-#define DEVEPTISR_OVERFI_Pos 5 /**< (DEVEPTISR) Overflow Interrupt Position */
-#define DEVEPTISR_OVERFI (_U_(0x1) << DEVEPTISR_OVERFI_Pos) /**< (DEVEPTISR) Overflow Interrupt Mask */
-#define DEVEPTISR_SHORTPACKET_Pos 7 /**< (DEVEPTISR) Short Packet Interrupt Position */
-#define DEVEPTISR_SHORTPACKET (_U_(0x1) << DEVEPTISR_SHORTPACKET_Pos) /**< (DEVEPTISR) Short Packet Interrupt Mask */
-#define DEVEPTISR_DTSEQ_Pos 8 /**< (DEVEPTISR) Data Toggle Sequence Position */
-#define DEVEPTISR_DTSEQ (_U_(0x3) << DEVEPTISR_DTSEQ_Pos) /**< (DEVEPTISR) Data Toggle Sequence Mask */
-#define DEVEPTISR_DTSEQ_DATA0_Val _U_(0x0) /**< (DEVEPTISR) Data0 toggle sequence */
-#define DEVEPTISR_DTSEQ_DATA1_Val _U_(0x1) /**< (DEVEPTISR) Data1 toggle sequence */
-#define DEVEPTISR_DTSEQ_DATA2_Val _U_(0x2) /**< (DEVEPTISR) Reserved for high-bandwidth isochronous endpoint */
-#define DEVEPTISR_DTSEQ_MDATA_Val _U_(0x3) /**< (DEVEPTISR) Reserved for high-bandwidth isochronous endpoint */
-#define DEVEPTISR_DTSEQ_DATA0 (DEVEPTISR_DTSEQ_DATA0_Val << DEVEPTISR_DTSEQ_Pos) /**< (DEVEPTISR) Data0 toggle sequence Position */
-#define DEVEPTISR_DTSEQ_DATA1 (DEVEPTISR_DTSEQ_DATA1_Val << DEVEPTISR_DTSEQ_Pos) /**< (DEVEPTISR) Data1 toggle sequence Position */
-#define DEVEPTISR_DTSEQ_DATA2 (DEVEPTISR_DTSEQ_DATA2_Val << DEVEPTISR_DTSEQ_Pos) /**< (DEVEPTISR) Reserved for high-bandwidth isochronous endpoint Position */
-#define DEVEPTISR_DTSEQ_MDATA (DEVEPTISR_DTSEQ_MDATA_Val << DEVEPTISR_DTSEQ_Pos) /**< (DEVEPTISR) Reserved for high-bandwidth isochronous endpoint Position */
-#define DEVEPTISR_NBUSYBK_Pos 12 /**< (DEVEPTISR) Number of Busy Banks Position */
-#define DEVEPTISR_NBUSYBK (_U_(0x3) << DEVEPTISR_NBUSYBK_Pos) /**< (DEVEPTISR) Number of Busy Banks Mask */
-#define DEVEPTISR_NBUSYBK_0_BUSY_Val _U_(0x0) /**< (DEVEPTISR) 0 busy bank (all banks free) */
-#define DEVEPTISR_NBUSYBK_1_BUSY_Val _U_(0x1) /**< (DEVEPTISR) 1 busy bank */
-#define DEVEPTISR_NBUSYBK_2_BUSY_Val _U_(0x2) /**< (DEVEPTISR) 2 busy banks */
-#define DEVEPTISR_NBUSYBK_3_BUSY_Val _U_(0x3) /**< (DEVEPTISR) 3 busy banks */
-#define DEVEPTISR_NBUSYBK_0_BUSY (DEVEPTISR_NBUSYBK_0_BUSY_Val << DEVEPTISR_NBUSYBK_Pos) /**< (DEVEPTISR) 0 busy bank (all banks free) Position */
-#define DEVEPTISR_NBUSYBK_1_BUSY (DEVEPTISR_NBUSYBK_1_BUSY_Val << DEVEPTISR_NBUSYBK_Pos) /**< (DEVEPTISR) 1 busy bank Position */
-#define DEVEPTISR_NBUSYBK_2_BUSY (DEVEPTISR_NBUSYBK_2_BUSY_Val << DEVEPTISR_NBUSYBK_Pos) /**< (DEVEPTISR) 2 busy banks Position */
-#define DEVEPTISR_NBUSYBK_3_BUSY (DEVEPTISR_NBUSYBK_3_BUSY_Val << DEVEPTISR_NBUSYBK_Pos) /**< (DEVEPTISR) 3 busy banks Position */
-#define DEVEPTISR_CURRBK_Pos 14 /**< (DEVEPTISR) Current Bank Position */
-#define DEVEPTISR_CURRBK (_U_(0x3) << DEVEPTISR_CURRBK_Pos) /**< (DEVEPTISR) Current Bank Mask */
-#define DEVEPTISR_CURRBK_BANK0_Val _U_(0x0) /**< (DEVEPTISR) Current bank is bank0 */
-#define DEVEPTISR_CURRBK_BANK1_Val _U_(0x1) /**< (DEVEPTISR) Current bank is bank1 */
-#define DEVEPTISR_CURRBK_BANK2_Val _U_(0x2) /**< (DEVEPTISR) Current bank is bank2 */
-#define DEVEPTISR_CURRBK_BANK0 (DEVEPTISR_CURRBK_BANK0_Val << DEVEPTISR_CURRBK_Pos) /**< (DEVEPTISR) Current bank is bank0 Position */
-#define DEVEPTISR_CURRBK_BANK1 (DEVEPTISR_CURRBK_BANK1_Val << DEVEPTISR_CURRBK_Pos) /**< (DEVEPTISR) Current bank is bank1 Position */
-#define DEVEPTISR_CURRBK_BANK2 (DEVEPTISR_CURRBK_BANK2_Val << DEVEPTISR_CURRBK_Pos) /**< (DEVEPTISR) Current bank is bank2 Position */
-#define DEVEPTISR_RWALL_Pos 16 /**< (DEVEPTISR) Read/Write Allowed Position */
-#define DEVEPTISR_RWALL (_U_(0x1) << DEVEPTISR_RWALL_Pos) /**< (DEVEPTISR) Read/Write Allowed Mask */
-#define DEVEPTISR_CFGOK_Pos 18 /**< (DEVEPTISR) Configuration OK Status Position */
-#define DEVEPTISR_CFGOK (_U_(0x1) << DEVEPTISR_CFGOK_Pos) /**< (DEVEPTISR) Configuration OK Status Mask */
-#define DEVEPTISR_BYCT_Pos 20 /**< (DEVEPTISR) Byte Count Position */
-#define DEVEPTISR_BYCT (_U_(0x7FF) << DEVEPTISR_BYCT_Pos) /**< (DEVEPTISR) Byte Count Mask */
-#define DEVEPTISR_Msk _U_(0x7FF5F3A3) /**< (DEVEPTISR) Register Mask */
-
-/* CTRL mode */
-#define DEVEPTISR_CTRL_RXSTPI_Pos 2 /**< (DEVEPTISR) Received SETUP Interrupt Position */
-#define DEVEPTISR_CTRL_RXSTPI (_U_(0x1) << DEVEPTISR_CTRL_RXSTPI_Pos) /**< (DEVEPTISR) Received SETUP Interrupt Mask */
-#define DEVEPTISR_CTRL_NAKOUTI_Pos 3 /**< (DEVEPTISR) NAKed OUT Interrupt Position */
-#define DEVEPTISR_CTRL_NAKOUTI (_U_(0x1) << DEVEPTISR_CTRL_NAKOUTI_Pos) /**< (DEVEPTISR) NAKed OUT Interrupt Mask */
-#define DEVEPTISR_CTRL_NAKINI_Pos 4 /**< (DEVEPTISR) NAKed IN Interrupt Position */
-#define DEVEPTISR_CTRL_NAKINI (_U_(0x1) << DEVEPTISR_CTRL_NAKINI_Pos) /**< (DEVEPTISR) NAKed IN Interrupt Mask */
-#define DEVEPTISR_CTRL_STALLEDI_Pos 6 /**< (DEVEPTISR) STALLed Interrupt Position */
-#define DEVEPTISR_CTRL_STALLEDI (_U_(0x1) << DEVEPTISR_CTRL_STALLEDI_Pos) /**< (DEVEPTISR) STALLed Interrupt Mask */
-#define DEVEPTISR_CTRL_CTRLDIR_Pos 17 /**< (DEVEPTISR) Control Direction Position */
-#define DEVEPTISR_CTRL_CTRLDIR (_U_(0x1) << DEVEPTISR_CTRL_CTRLDIR_Pos) /**< (DEVEPTISR) Control Direction Mask */
-#define DEVEPTISR_CTRL_Msk _U_(0x2005C) /**< (DEVEPTISR_CTRL) Register Mask */
-
-/* ISO mode */
-#define DEVEPTISR_ISO_UNDERFI_Pos 2 /**< (DEVEPTISR) Underflow Interrupt Position */
-#define DEVEPTISR_ISO_UNDERFI (_U_(0x1) << DEVEPTISR_ISO_UNDERFI_Pos) /**< (DEVEPTISR) Underflow Interrupt Mask */
-#define DEVEPTISR_ISO_HBISOINERRI_Pos 3 /**< (DEVEPTISR) High Bandwidth Isochronous IN Underflow Error Interrupt Position */
-#define DEVEPTISR_ISO_HBISOINERRI (_U_(0x1) << DEVEPTISR_ISO_HBISOINERRI_Pos) /**< (DEVEPTISR) High Bandwidth Isochronous IN Underflow Error Interrupt Mask */
-#define DEVEPTISR_ISO_HBISOFLUSHI_Pos 4 /**< (DEVEPTISR) High Bandwidth Isochronous IN Flush Interrupt Position */
-#define DEVEPTISR_ISO_HBISOFLUSHI (_U_(0x1) << DEVEPTISR_ISO_HBISOFLUSHI_Pos) /**< (DEVEPTISR) High Bandwidth Isochronous IN Flush Interrupt Mask */
-#define DEVEPTISR_ISO_CRCERRI_Pos 6 /**< (DEVEPTISR) CRC Error Interrupt Position */
-#define DEVEPTISR_ISO_CRCERRI (_U_(0x1) << DEVEPTISR_ISO_CRCERRI_Pos) /**< (DEVEPTISR) CRC Error Interrupt Mask */
-#define DEVEPTISR_ISO_ERRORTRANS_Pos 10 /**< (DEVEPTISR) High-bandwidth Isochronous OUT Endpoint Transaction Error Interrupt Position */
-#define DEVEPTISR_ISO_ERRORTRANS (_U_(0x1) << DEVEPTISR_ISO_ERRORTRANS_Pos) /**< (DEVEPTISR) High-bandwidth Isochronous OUT Endpoint Transaction Error Interrupt Mask */
-#define DEVEPTISR_ISO_Msk _U_(0x45C) /**< (DEVEPTISR_ISO) Register Mask */
-
-/* BLK mode */
-#define DEVEPTISR_BLK_RXSTPI_Pos 2 /**< (DEVEPTISR) Received SETUP Interrupt Position */
-#define DEVEPTISR_BLK_RXSTPI (_U_(0x1) << DEVEPTISR_BLK_RXSTPI_Pos) /**< (DEVEPTISR) Received SETUP Interrupt Mask */
-#define DEVEPTISR_BLK_NAKOUTI_Pos 3 /**< (DEVEPTISR) NAKed OUT Interrupt Position */
-#define DEVEPTISR_BLK_NAKOUTI (_U_(0x1) << DEVEPTISR_BLK_NAKOUTI_Pos) /**< (DEVEPTISR) NAKed OUT Interrupt Mask */
-#define DEVEPTISR_BLK_NAKINI_Pos 4 /**< (DEVEPTISR) NAKed IN Interrupt Position */
-#define DEVEPTISR_BLK_NAKINI (_U_(0x1) << DEVEPTISR_BLK_NAKINI_Pos) /**< (DEVEPTISR) NAKed IN Interrupt Mask */
-#define DEVEPTISR_BLK_STALLEDI_Pos 6 /**< (DEVEPTISR) STALLed Interrupt Position */
-#define DEVEPTISR_BLK_STALLEDI (_U_(0x1) << DEVEPTISR_BLK_STALLEDI_Pos) /**< (DEVEPTISR) STALLed Interrupt Mask */
-#define DEVEPTISR_BLK_CTRLDIR_Pos 17 /**< (DEVEPTISR) Control Direction Position */
-#define DEVEPTISR_BLK_CTRLDIR (_U_(0x1) << DEVEPTISR_BLK_CTRLDIR_Pos) /**< (DEVEPTISR) Control Direction Mask */
-#define DEVEPTISR_BLK_Msk _U_(0x2005C) /**< (DEVEPTISR_BLK) Register Mask */
-
-/* INTRPT mode */
-#define DEVEPTISR_INTRPT_RXSTPI_Pos 2 /**< (DEVEPTISR) Received SETUP Interrupt Position */
-#define DEVEPTISR_INTRPT_RXSTPI (_U_(0x1) << DEVEPTISR_INTRPT_RXSTPI_Pos) /**< (DEVEPTISR) Received SETUP Interrupt Mask */
-#define DEVEPTISR_INTRPT_NAKOUTI_Pos 3 /**< (DEVEPTISR) NAKed OUT Interrupt Position */
-#define DEVEPTISR_INTRPT_NAKOUTI (_U_(0x1) << DEVEPTISR_INTRPT_NAKOUTI_Pos) /**< (DEVEPTISR) NAKed OUT Interrupt Mask */
-#define DEVEPTISR_INTRPT_NAKINI_Pos 4 /**< (DEVEPTISR) NAKed IN Interrupt Position */
-#define DEVEPTISR_INTRPT_NAKINI (_U_(0x1) << DEVEPTISR_INTRPT_NAKINI_Pos) /**< (DEVEPTISR) NAKed IN Interrupt Mask */
-#define DEVEPTISR_INTRPT_STALLEDI_Pos 6 /**< (DEVEPTISR) STALLed Interrupt Position */
-#define DEVEPTISR_INTRPT_STALLEDI (_U_(0x1) << DEVEPTISR_INTRPT_STALLEDI_Pos) /**< (DEVEPTISR) STALLed Interrupt Mask */
-#define DEVEPTISR_INTRPT_CTRLDIR_Pos 17 /**< (DEVEPTISR) Control Direction Position */
-#define DEVEPTISR_INTRPT_CTRLDIR (_U_(0x1) << DEVEPTISR_INTRPT_CTRLDIR_Pos) /**< (DEVEPTISR) Control Direction Mask */
-#define DEVEPTISR_INTRPT_Msk _U_(0x2005C) /**< (DEVEPTISR_INTRPT) Register Mask */
-
-
-/* -------- DEVEPTICR : (USBHS Offset: 0x160) (/W 32) Device Endpoint Interrupt Clear Register -------- */
-
-#define DEVEPTICR_OFFSET (0x160) /**< (DEVEPTICR) Device Endpoint Interrupt Clear Register Offset */
-
-#define DEVEPTICR_TXINIC_Pos 0 /**< (DEVEPTICR) Transmitted IN Data Interrupt Clear Position */
-#define DEVEPTICR_TXINIC (_U_(0x1) << DEVEPTICR_TXINIC_Pos) /**< (DEVEPTICR) Transmitted IN Data Interrupt Clear Mask */
-#define DEVEPTICR_RXOUTIC_Pos 1 /**< (DEVEPTICR) Received OUT Data Interrupt Clear Position */
-#define DEVEPTICR_RXOUTIC (_U_(0x1) << DEVEPTICR_RXOUTIC_Pos) /**< (DEVEPTICR) Received OUT Data Interrupt Clear Mask */
-#define DEVEPTICR_OVERFIC_Pos 5 /**< (DEVEPTICR) Overflow Interrupt Clear Position */
-#define DEVEPTICR_OVERFIC (_U_(0x1) << DEVEPTICR_OVERFIC_Pos) /**< (DEVEPTICR) Overflow Interrupt Clear Mask */
-#define DEVEPTICR_SHORTPACKETC_Pos 7 /**< (DEVEPTICR) Short Packet Interrupt Clear Position */
-#define DEVEPTICR_SHORTPACKETC (_U_(0x1) << DEVEPTICR_SHORTPACKETC_Pos) /**< (DEVEPTICR) Short Packet Interrupt Clear Mask */
-#define DEVEPTICR_Msk _U_(0xA3) /**< (DEVEPTICR) Register Mask */
-
-/* CTRL mode */
-#define DEVEPTICR_CTRL_RXSTPIC_Pos 2 /**< (DEVEPTICR) Received SETUP Interrupt Clear Position */
-#define DEVEPTICR_CTRL_RXSTPIC (_U_(0x1) << DEVEPTICR_CTRL_RXSTPIC_Pos) /**< (DEVEPTICR) Received SETUP Interrupt Clear Mask */
-#define DEVEPTICR_CTRL_NAKOUTIC_Pos 3 /**< (DEVEPTICR) NAKed OUT Interrupt Clear Position */
-#define DEVEPTICR_CTRL_NAKOUTIC (_U_(0x1) << DEVEPTICR_CTRL_NAKOUTIC_Pos) /**< (DEVEPTICR) NAKed OUT Interrupt Clear Mask */
-#define DEVEPTICR_CTRL_NAKINIC_Pos 4 /**< (DEVEPTICR) NAKed IN Interrupt Clear Position */
-#define DEVEPTICR_CTRL_NAKINIC (_U_(0x1) << DEVEPTICR_CTRL_NAKINIC_Pos) /**< (DEVEPTICR) NAKed IN Interrupt Clear Mask */
-#define DEVEPTICR_CTRL_STALLEDIC_Pos 6 /**< (DEVEPTICR) STALLed Interrupt Clear Position */
-#define DEVEPTICR_CTRL_STALLEDIC (_U_(0x1) << DEVEPTICR_CTRL_STALLEDIC_Pos) /**< (DEVEPTICR) STALLed Interrupt Clear Mask */
-#define DEVEPTICR_CTRL_Msk _U_(0x5C) /**< (DEVEPTICR_CTRL) Register Mask */
-
-/* ISO mode */
-#define DEVEPTICR_ISO_UNDERFIC_Pos 2 /**< (DEVEPTICR) Underflow Interrupt Clear Position */
-#define DEVEPTICR_ISO_UNDERFIC (_U_(0x1) << DEVEPTICR_ISO_UNDERFIC_Pos) /**< (DEVEPTICR) Underflow Interrupt Clear Mask */
-#define DEVEPTICR_ISO_HBISOINERRIC_Pos 3 /**< (DEVEPTICR) High Bandwidth Isochronous IN Underflow Error Interrupt Clear Position */
-#define DEVEPTICR_ISO_HBISOINERRIC (_U_(0x1) << DEVEPTICR_ISO_HBISOINERRIC_Pos) /**< (DEVEPTICR) High Bandwidth Isochronous IN Underflow Error Interrupt Clear Mask */
-#define DEVEPTICR_ISO_HBISOFLUSHIC_Pos 4 /**< (DEVEPTICR) High Bandwidth Isochronous IN Flush Interrupt Clear Position */
-#define DEVEPTICR_ISO_HBISOFLUSHIC (_U_(0x1) << DEVEPTICR_ISO_HBISOFLUSHIC_Pos) /**< (DEVEPTICR) High Bandwidth Isochronous IN Flush Interrupt Clear Mask */
-#define DEVEPTICR_ISO_CRCERRIC_Pos 6 /**< (DEVEPTICR) CRC Error Interrupt Clear Position */
-#define DEVEPTICR_ISO_CRCERRIC (_U_(0x1) << DEVEPTICR_ISO_CRCERRIC_Pos) /**< (DEVEPTICR) CRC Error Interrupt Clear Mask */
-#define DEVEPTICR_ISO_Msk _U_(0x5C) /**< (DEVEPTICR_ISO) Register Mask */
-
-/* BLK mode */
-#define DEVEPTICR_BLK_RXSTPIC_Pos 2 /**< (DEVEPTICR) Received SETUP Interrupt Clear Position */
-#define DEVEPTICR_BLK_RXSTPIC (_U_(0x1) << DEVEPTICR_BLK_RXSTPIC_Pos) /**< (DEVEPTICR) Received SETUP Interrupt Clear Mask */
-#define DEVEPTICR_BLK_NAKOUTIC_Pos 3 /**< (DEVEPTICR) NAKed OUT Interrupt Clear Position */
-#define DEVEPTICR_BLK_NAKOUTIC (_U_(0x1) << DEVEPTICR_BLK_NAKOUTIC_Pos) /**< (DEVEPTICR) NAKed OUT Interrupt Clear Mask */
-#define DEVEPTICR_BLK_NAKINIC_Pos 4 /**< (DEVEPTICR) NAKed IN Interrupt Clear Position */
-#define DEVEPTICR_BLK_NAKINIC (_U_(0x1) << DEVEPTICR_BLK_NAKINIC_Pos) /**< (DEVEPTICR) NAKed IN Interrupt Clear Mask */
-#define DEVEPTICR_BLK_STALLEDIC_Pos 6 /**< (DEVEPTICR) STALLed Interrupt Clear Position */
-#define DEVEPTICR_BLK_STALLEDIC (_U_(0x1) << DEVEPTICR_BLK_STALLEDIC_Pos) /**< (DEVEPTICR) STALLed Interrupt Clear Mask */
-#define DEVEPTICR_BLK_Msk _U_(0x5C) /**< (DEVEPTICR_BLK) Register Mask */
-
-/* INTRPT mode */
-#define DEVEPTICR_INTRPT_RXSTPIC_Pos 2 /**< (DEVEPTICR) Received SETUP Interrupt Clear Position */
-#define DEVEPTICR_INTRPT_RXSTPIC (_U_(0x1) << DEVEPTICR_INTRPT_RXSTPIC_Pos) /**< (DEVEPTICR) Received SETUP Interrupt Clear Mask */
-#define DEVEPTICR_INTRPT_NAKOUTIC_Pos 3 /**< (DEVEPTICR) NAKed OUT Interrupt Clear Position */
-#define DEVEPTICR_INTRPT_NAKOUTIC (_U_(0x1) << DEVEPTICR_INTRPT_NAKOUTIC_Pos) /**< (DEVEPTICR) NAKed OUT Interrupt Clear Mask */
-#define DEVEPTICR_INTRPT_NAKINIC_Pos 4 /**< (DEVEPTICR) NAKed IN Interrupt Clear Position */
-#define DEVEPTICR_INTRPT_NAKINIC (_U_(0x1) << DEVEPTICR_INTRPT_NAKINIC_Pos) /**< (DEVEPTICR) NAKed IN Interrupt Clear Mask */
-#define DEVEPTICR_INTRPT_STALLEDIC_Pos 6 /**< (DEVEPTICR) STALLed Interrupt Clear Position */
-#define DEVEPTICR_INTRPT_STALLEDIC (_U_(0x1) << DEVEPTICR_INTRPT_STALLEDIC_Pos) /**< (DEVEPTICR) STALLed Interrupt Clear Mask */
-#define DEVEPTICR_INTRPT_Msk _U_(0x5C) /**< (DEVEPTICR_INTRPT) Register Mask */
-
-
-/* -------- DEVEPTIFR : (USBHS Offset: 0x190) (/W 32) Device Endpoint Interrupt Set Register -------- */
-
-#define DEVEPTIFR_OFFSET (0x190) /**< (DEVEPTIFR) Device Endpoint Interrupt Set Register Offset */
-
-#define DEVEPTIFR_TXINIS_Pos 0 /**< (DEVEPTIFR) Transmitted IN Data Interrupt Set Position */
-#define DEVEPTIFR_TXINIS (_U_(0x1) << DEVEPTIFR_TXINIS_Pos) /**< (DEVEPTIFR) Transmitted IN Data Interrupt Set Mask */
-#define DEVEPTIFR_RXOUTIS_Pos 1 /**< (DEVEPTIFR) Received OUT Data Interrupt Set Position */
-#define DEVEPTIFR_RXOUTIS (_U_(0x1) << DEVEPTIFR_RXOUTIS_Pos) /**< (DEVEPTIFR) Received OUT Data Interrupt Set Mask */
-#define DEVEPTIFR_OVERFIS_Pos 5 /**< (DEVEPTIFR) Overflow Interrupt Set Position */
-#define DEVEPTIFR_OVERFIS (_U_(0x1) << DEVEPTIFR_OVERFIS_Pos) /**< (DEVEPTIFR) Overflow Interrupt Set Mask */
-#define DEVEPTIFR_SHORTPACKETS_Pos 7 /**< (DEVEPTIFR) Short Packet Interrupt Set Position */
-#define DEVEPTIFR_SHORTPACKETS (_U_(0x1) << DEVEPTIFR_SHORTPACKETS_Pos) /**< (DEVEPTIFR) Short Packet Interrupt Set Mask */
-#define DEVEPTIFR_NBUSYBKS_Pos 12 /**< (DEVEPTIFR) Number of Busy Banks Interrupt Set Position */
-#define DEVEPTIFR_NBUSYBKS (_U_(0x1) << DEVEPTIFR_NBUSYBKS_Pos) /**< (DEVEPTIFR) Number of Busy Banks Interrupt Set Mask */
-#define DEVEPTIFR_Msk _U_(0x10A3) /**< (DEVEPTIFR) Register Mask */
-
-/* CTRL mode */
-#define DEVEPTIFR_CTRL_RXSTPIS_Pos 2 /**< (DEVEPTIFR) Received SETUP Interrupt Set Position */
-#define DEVEPTIFR_CTRL_RXSTPIS (_U_(0x1) << DEVEPTIFR_CTRL_RXSTPIS_Pos) /**< (DEVEPTIFR) Received SETUP Interrupt Set Mask */
-#define DEVEPTIFR_CTRL_NAKOUTIS_Pos 3 /**< (DEVEPTIFR) NAKed OUT Interrupt Set Position */
-#define DEVEPTIFR_CTRL_NAKOUTIS (_U_(0x1) << DEVEPTIFR_CTRL_NAKOUTIS_Pos) /**< (DEVEPTIFR) NAKed OUT Interrupt Set Mask */
-#define DEVEPTIFR_CTRL_NAKINIS_Pos 4 /**< (DEVEPTIFR) NAKed IN Interrupt Set Position */
-#define DEVEPTIFR_CTRL_NAKINIS (_U_(0x1) << DEVEPTIFR_CTRL_NAKINIS_Pos) /**< (DEVEPTIFR) NAKed IN Interrupt Set Mask */
-#define DEVEPTIFR_CTRL_STALLEDIS_Pos 6 /**< (DEVEPTIFR) STALLed Interrupt Set Position */
-#define DEVEPTIFR_CTRL_STALLEDIS (_U_(0x1) << DEVEPTIFR_CTRL_STALLEDIS_Pos) /**< (DEVEPTIFR) STALLed Interrupt Set Mask */
-#define DEVEPTIFR_CTRL_Msk _U_(0x5C) /**< (DEVEPTIFR_CTRL) Register Mask */
-
-/* ISO mode */
-#define DEVEPTIFR_ISO_UNDERFIS_Pos 2 /**< (DEVEPTIFR) Underflow Interrupt Set Position */
-#define DEVEPTIFR_ISO_UNDERFIS (_U_(0x1) << DEVEPTIFR_ISO_UNDERFIS_Pos) /**< (DEVEPTIFR) Underflow Interrupt Set Mask */
-#define DEVEPTIFR_ISO_HBISOINERRIS_Pos 3 /**< (DEVEPTIFR) High Bandwidth Isochronous IN Underflow Error Interrupt Set Position */
-#define DEVEPTIFR_ISO_HBISOINERRIS (_U_(0x1) << DEVEPTIFR_ISO_HBISOINERRIS_Pos) /**< (DEVEPTIFR) High Bandwidth Isochronous IN Underflow Error Interrupt Set Mask */
-#define DEVEPTIFR_ISO_HBISOFLUSHIS_Pos 4 /**< (DEVEPTIFR) High Bandwidth Isochronous IN Flush Interrupt Set Position */
-#define DEVEPTIFR_ISO_HBISOFLUSHIS (_U_(0x1) << DEVEPTIFR_ISO_HBISOFLUSHIS_Pos) /**< (DEVEPTIFR) High Bandwidth Isochronous IN Flush Interrupt Set Mask */
-#define DEVEPTIFR_ISO_CRCERRIS_Pos 6 /**< (DEVEPTIFR) CRC Error Interrupt Set Position */
-#define DEVEPTIFR_ISO_CRCERRIS (_U_(0x1) << DEVEPTIFR_ISO_CRCERRIS_Pos) /**< (DEVEPTIFR) CRC Error Interrupt Set Mask */
-#define DEVEPTIFR_ISO_Msk _U_(0x5C) /**< (DEVEPTIFR_ISO) Register Mask */
-
-/* BLK mode */
-#define DEVEPTIFR_BLK_RXSTPIS_Pos 2 /**< (DEVEPTIFR) Received SETUP Interrupt Set Position */
-#define DEVEPTIFR_BLK_RXSTPIS (_U_(0x1) << DEVEPTIFR_BLK_RXSTPIS_Pos) /**< (DEVEPTIFR) Received SETUP Interrupt Set Mask */
-#define DEVEPTIFR_BLK_NAKOUTIS_Pos 3 /**< (DEVEPTIFR) NAKed OUT Interrupt Set Position */
-#define DEVEPTIFR_BLK_NAKOUTIS (_U_(0x1) << DEVEPTIFR_BLK_NAKOUTIS_Pos) /**< (DEVEPTIFR) NAKed OUT Interrupt Set Mask */
-#define DEVEPTIFR_BLK_NAKINIS_Pos 4 /**< (DEVEPTIFR) NAKed IN Interrupt Set Position */
-#define DEVEPTIFR_BLK_NAKINIS (_U_(0x1) << DEVEPTIFR_BLK_NAKINIS_Pos) /**< (DEVEPTIFR) NAKed IN Interrupt Set Mask */
-#define DEVEPTIFR_BLK_STALLEDIS_Pos 6 /**< (DEVEPTIFR) STALLed Interrupt Set Position */
-#define DEVEPTIFR_BLK_STALLEDIS (_U_(0x1) << DEVEPTIFR_BLK_STALLEDIS_Pos) /**< (DEVEPTIFR) STALLed Interrupt Set Mask */
-#define DEVEPTIFR_BLK_Msk _U_(0x5C) /**< (DEVEPTIFR_BLK) Register Mask */
-
-/* INTRPT mode */
-#define DEVEPTIFR_INTRPT_RXSTPIS_Pos 2 /**< (DEVEPTIFR) Received SETUP Interrupt Set Position */
-#define DEVEPTIFR_INTRPT_RXSTPIS (_U_(0x1) << DEVEPTIFR_INTRPT_RXSTPIS_Pos) /**< (DEVEPTIFR) Received SETUP Interrupt Set Mask */
-#define DEVEPTIFR_INTRPT_NAKOUTIS_Pos 3 /**< (DEVEPTIFR) NAKed OUT Interrupt Set Position */
-#define DEVEPTIFR_INTRPT_NAKOUTIS (_U_(0x1) << DEVEPTIFR_INTRPT_NAKOUTIS_Pos) /**< (DEVEPTIFR) NAKed OUT Interrupt Set Mask */
-#define DEVEPTIFR_INTRPT_NAKINIS_Pos 4 /**< (DEVEPTIFR) NAKed IN Interrupt Set Position */
-#define DEVEPTIFR_INTRPT_NAKINIS (_U_(0x1) << DEVEPTIFR_INTRPT_NAKINIS_Pos) /**< (DEVEPTIFR) NAKed IN Interrupt Set Mask */
-#define DEVEPTIFR_INTRPT_STALLEDIS_Pos 6 /**< (DEVEPTIFR) STALLed Interrupt Set Position */
-#define DEVEPTIFR_INTRPT_STALLEDIS (_U_(0x1) << DEVEPTIFR_INTRPT_STALLEDIS_Pos) /**< (DEVEPTIFR) STALLed Interrupt Set Mask */
-#define DEVEPTIFR_INTRPT_Msk _U_(0x5C) /**< (DEVEPTIFR_INTRPT) Register Mask */
-
-
-/* -------- DEVEPTIMR : (USBHS Offset: 0x1c0) (R/ 32) Device Endpoint Interrupt Mask Register -------- */
-
-#define DEVEPTIMR_OFFSET (0x1C0) /**< (DEVEPTIMR) Device Endpoint Interrupt Mask Register Offset */
-
-#define DEVEPTIMR_TXINE_Pos 0 /**< (DEVEPTIMR) Transmitted IN Data Interrupt Position */
-#define DEVEPTIMR_TXINE (_U_(0x1) << DEVEPTIMR_TXINE_Pos) /**< (DEVEPTIMR) Transmitted IN Data Interrupt Mask */
-#define DEVEPTIMR_RXOUTE_Pos 1 /**< (DEVEPTIMR) Received OUT Data Interrupt Position */
-#define DEVEPTIMR_RXOUTE (_U_(0x1) << DEVEPTIMR_RXOUTE_Pos) /**< (DEVEPTIMR) Received OUT Data Interrupt Mask */
-#define DEVEPTIMR_OVERFE_Pos 5 /**< (DEVEPTIMR) Overflow Interrupt Position */
-#define DEVEPTIMR_OVERFE (_U_(0x1) << DEVEPTIMR_OVERFE_Pos) /**< (DEVEPTIMR) Overflow Interrupt Mask */
-#define DEVEPTIMR_SHORTPACKETE_Pos 7 /**< (DEVEPTIMR) Short Packet Interrupt Position */
-#define DEVEPTIMR_SHORTPACKETE (_U_(0x1) << DEVEPTIMR_SHORTPACKETE_Pos) /**< (DEVEPTIMR) Short Packet Interrupt Mask */
-#define DEVEPTIMR_NBUSYBKE_Pos 12 /**< (DEVEPTIMR) Number of Busy Banks Interrupt Position */
-#define DEVEPTIMR_NBUSYBKE (_U_(0x1) << DEVEPTIMR_NBUSYBKE_Pos) /**< (DEVEPTIMR) Number of Busy Banks Interrupt Mask */
-#define DEVEPTIMR_KILLBK_Pos 13 /**< (DEVEPTIMR) Kill IN Bank Position */
-#define DEVEPTIMR_KILLBK (_U_(0x1) << DEVEPTIMR_KILLBK_Pos) /**< (DEVEPTIMR) Kill IN Bank Mask */
-#define DEVEPTIMR_FIFOCON_Pos 14 /**< (DEVEPTIMR) FIFO Control Position */
-#define DEVEPTIMR_FIFOCON (_U_(0x1) << DEVEPTIMR_FIFOCON_Pos) /**< (DEVEPTIMR) FIFO Control Mask */
-#define DEVEPTIMR_EPDISHDMA_Pos 16 /**< (DEVEPTIMR) Endpoint Interrupts Disable HDMA Request Position */
-#define DEVEPTIMR_EPDISHDMA (_U_(0x1) << DEVEPTIMR_EPDISHDMA_Pos) /**< (DEVEPTIMR) Endpoint Interrupts Disable HDMA Request Mask */
-#define DEVEPTIMR_RSTDT_Pos 18 /**< (DEVEPTIMR) Reset Data Toggle Position */
-#define DEVEPTIMR_RSTDT (_U_(0x1) << DEVEPTIMR_RSTDT_Pos) /**< (DEVEPTIMR) Reset Data Toggle Mask */
-#define DEVEPTIMR_Msk _U_(0x570A3) /**< (DEVEPTIMR) Register Mask */
-
-/* CTRL mode */
-#define DEVEPTIMR_CTRL_RXSTPE_Pos 2 /**< (DEVEPTIMR) Received SETUP Interrupt Position */
-#define DEVEPTIMR_CTRL_RXSTPE (_U_(0x1) << DEVEPTIMR_CTRL_RXSTPE_Pos) /**< (DEVEPTIMR) Received SETUP Interrupt Mask */
-#define DEVEPTIMR_CTRL_NAKOUTE_Pos 3 /**< (DEVEPTIMR) NAKed OUT Interrupt Position */
-#define DEVEPTIMR_CTRL_NAKOUTE (_U_(0x1) << DEVEPTIMR_CTRL_NAKOUTE_Pos) /**< (DEVEPTIMR) NAKed OUT Interrupt Mask */
-#define DEVEPTIMR_CTRL_NAKINE_Pos 4 /**< (DEVEPTIMR) NAKed IN Interrupt Position */
-#define DEVEPTIMR_CTRL_NAKINE (_U_(0x1) << DEVEPTIMR_CTRL_NAKINE_Pos) /**< (DEVEPTIMR) NAKed IN Interrupt Mask */
-#define DEVEPTIMR_CTRL_STALLEDE_Pos 6 /**< (DEVEPTIMR) STALLed Interrupt Position */
-#define DEVEPTIMR_CTRL_STALLEDE (_U_(0x1) << DEVEPTIMR_CTRL_STALLEDE_Pos) /**< (DEVEPTIMR) STALLed Interrupt Mask */
-#define DEVEPTIMR_CTRL_NYETDIS_Pos 17 /**< (DEVEPTIMR) NYET Token Disable Position */
-#define DEVEPTIMR_CTRL_NYETDIS (_U_(0x1) << DEVEPTIMR_CTRL_NYETDIS_Pos) /**< (DEVEPTIMR) NYET Token Disable Mask */
-#define DEVEPTIMR_CTRL_STALLRQ_Pos 19 /**< (DEVEPTIMR) STALL Request Position */
-#define DEVEPTIMR_CTRL_STALLRQ (_U_(0x1) << DEVEPTIMR_CTRL_STALLRQ_Pos) /**< (DEVEPTIMR) STALL Request Mask */
-#define DEVEPTIMR_CTRL_Msk _U_(0xA005C) /**< (DEVEPTIMR_CTRL) Register Mask */
-
-/* ISO mode */
-#define DEVEPTIMR_ISO_UNDERFE_Pos 2 /**< (DEVEPTIMR) Underflow Interrupt Position */
-#define DEVEPTIMR_ISO_UNDERFE (_U_(0x1) << DEVEPTIMR_ISO_UNDERFE_Pos) /**< (DEVEPTIMR) Underflow Interrupt Mask */
-#define DEVEPTIMR_ISO_HBISOINERRE_Pos 3 /**< (DEVEPTIMR) High Bandwidth Isochronous IN Underflow Error Interrupt Position */
-#define DEVEPTIMR_ISO_HBISOINERRE (_U_(0x1) << DEVEPTIMR_ISO_HBISOINERRE_Pos) /**< (DEVEPTIMR) High Bandwidth Isochronous IN Underflow Error Interrupt Mask */
-#define DEVEPTIMR_ISO_HBISOFLUSHE_Pos 4 /**< (DEVEPTIMR) High Bandwidth Isochronous IN Flush Interrupt Position */
-#define DEVEPTIMR_ISO_HBISOFLUSHE (_U_(0x1) << DEVEPTIMR_ISO_HBISOFLUSHE_Pos) /**< (DEVEPTIMR) High Bandwidth Isochronous IN Flush Interrupt Mask */
-#define DEVEPTIMR_ISO_CRCERRE_Pos 6 /**< (DEVEPTIMR) CRC Error Interrupt Position */
-#define DEVEPTIMR_ISO_CRCERRE (_U_(0x1) << DEVEPTIMR_ISO_CRCERRE_Pos) /**< (DEVEPTIMR) CRC Error Interrupt Mask */
-#define DEVEPTIMR_ISO_MDATAE_Pos 8 /**< (DEVEPTIMR) MData Interrupt Position */
-#define DEVEPTIMR_ISO_MDATAE (_U_(0x1) << DEVEPTIMR_ISO_MDATAE_Pos) /**< (DEVEPTIMR) MData Interrupt Mask */
-#define DEVEPTIMR_ISO_DATAXE_Pos 9 /**< (DEVEPTIMR) DataX Interrupt Position */
-#define DEVEPTIMR_ISO_DATAXE (_U_(0x1) << DEVEPTIMR_ISO_DATAXE_Pos) /**< (DEVEPTIMR) DataX Interrupt Mask */
-#define DEVEPTIMR_ISO_ERRORTRANSE_Pos 10 /**< (DEVEPTIMR) Transaction Error Interrupt Position */
-#define DEVEPTIMR_ISO_ERRORTRANSE (_U_(0x1) << DEVEPTIMR_ISO_ERRORTRANSE_Pos) /**< (DEVEPTIMR) Transaction Error Interrupt Mask */
-#define DEVEPTIMR_ISO_Msk _U_(0x75C) /**< (DEVEPTIMR_ISO) Register Mask */
-
-/* BLK mode */
-#define DEVEPTIMR_BLK_RXSTPE_Pos 2 /**< (DEVEPTIMR) Received SETUP Interrupt Position */
-#define DEVEPTIMR_BLK_RXSTPE (_U_(0x1) << DEVEPTIMR_BLK_RXSTPE_Pos) /**< (DEVEPTIMR) Received SETUP Interrupt Mask */
-#define DEVEPTIMR_BLK_NAKOUTE_Pos 3 /**< (DEVEPTIMR) NAKed OUT Interrupt Position */
-#define DEVEPTIMR_BLK_NAKOUTE (_U_(0x1) << DEVEPTIMR_BLK_NAKOUTE_Pos) /**< (DEVEPTIMR) NAKed OUT Interrupt Mask */
-#define DEVEPTIMR_BLK_NAKINE_Pos 4 /**< (DEVEPTIMR) NAKed IN Interrupt Position */
-#define DEVEPTIMR_BLK_NAKINE (_U_(0x1) << DEVEPTIMR_BLK_NAKINE_Pos) /**< (DEVEPTIMR) NAKed IN Interrupt Mask */
-#define DEVEPTIMR_BLK_STALLEDE_Pos 6 /**< (DEVEPTIMR) STALLed Interrupt Position */
-#define DEVEPTIMR_BLK_STALLEDE (_U_(0x1) << DEVEPTIMR_BLK_STALLEDE_Pos) /**< (DEVEPTIMR) STALLed Interrupt Mask */
-#define DEVEPTIMR_BLK_NYETDIS_Pos 17 /**< (DEVEPTIMR) NYET Token Disable Position */
-#define DEVEPTIMR_BLK_NYETDIS (_U_(0x1) << DEVEPTIMR_BLK_NYETDIS_Pos) /**< (DEVEPTIMR) NYET Token Disable Mask */
-#define DEVEPTIMR_BLK_STALLRQ_Pos 19 /**< (DEVEPTIMR) STALL Request Position */
-#define DEVEPTIMR_BLK_STALLRQ (_U_(0x1) << DEVEPTIMR_BLK_STALLRQ_Pos) /**< (DEVEPTIMR) STALL Request Mask */
-#define DEVEPTIMR_BLK_Msk _U_(0xA005C) /**< (DEVEPTIMR_BLK) Register Mask */
-
-/* INTRPT mode */
-#define DEVEPTIMR_INTRPT_RXSTPE_Pos 2 /**< (DEVEPTIMR) Received SETUP Interrupt Position */
-#define DEVEPTIMR_INTRPT_RXSTPE (_U_(0x1) << DEVEPTIMR_INTRPT_RXSTPE_Pos) /**< (DEVEPTIMR) Received SETUP Interrupt Mask */
-#define DEVEPTIMR_INTRPT_NAKOUTE_Pos 3 /**< (DEVEPTIMR) NAKed OUT Interrupt Position */
-#define DEVEPTIMR_INTRPT_NAKOUTE (_U_(0x1) << DEVEPTIMR_INTRPT_NAKOUTE_Pos) /**< (DEVEPTIMR) NAKed OUT Interrupt Mask */
-#define DEVEPTIMR_INTRPT_NAKINE_Pos 4 /**< (DEVEPTIMR) NAKed IN Interrupt Position */
-#define DEVEPTIMR_INTRPT_NAKINE (_U_(0x1) << DEVEPTIMR_INTRPT_NAKINE_Pos) /**< (DEVEPTIMR) NAKed IN Interrupt Mask */
-#define DEVEPTIMR_INTRPT_STALLEDE_Pos 6 /**< (DEVEPTIMR) STALLed Interrupt Position */
-#define DEVEPTIMR_INTRPT_STALLEDE (_U_(0x1) << DEVEPTIMR_INTRPT_STALLEDE_Pos) /**< (DEVEPTIMR) STALLed Interrupt Mask */
-#define DEVEPTIMR_INTRPT_NYETDIS_Pos 17 /**< (DEVEPTIMR) NYET Token Disable Position */
-#define DEVEPTIMR_INTRPT_NYETDIS (_U_(0x1) << DEVEPTIMR_INTRPT_NYETDIS_Pos) /**< (DEVEPTIMR) NYET Token Disable Mask */
-#define DEVEPTIMR_INTRPT_STALLRQ_Pos 19 /**< (DEVEPTIMR) STALL Request Position */
-#define DEVEPTIMR_INTRPT_STALLRQ (_U_(0x1) << DEVEPTIMR_INTRPT_STALLRQ_Pos) /**< (DEVEPTIMR) STALL Request Mask */
-#define DEVEPTIMR_INTRPT_Msk _U_(0xA005C) /**< (DEVEPTIMR_INTRPT) Register Mask */
-
-
-/* -------- DEVEPTIER : (USBHS Offset: 0x1f0) (/W 32) Device Endpoint Interrupt Enable Register -------- */
-
-#define DEVEPTIER_OFFSET (0x1F0) /**< (DEVEPTIER) Device Endpoint Interrupt Enable Register Offset */
-
-#define DEVEPTIER_TXINES_Pos 0 /**< (DEVEPTIER) Transmitted IN Data Interrupt Enable Position */
-#define DEVEPTIER_TXINES (_U_(0x1) << DEVEPTIER_TXINES_Pos) /**< (DEVEPTIER) Transmitted IN Data Interrupt Enable Mask */
-#define DEVEPTIER_RXOUTES_Pos 1 /**< (DEVEPTIER) Received OUT Data Interrupt Enable Position */
-#define DEVEPTIER_RXOUTES (_U_(0x1) << DEVEPTIER_RXOUTES_Pos) /**< (DEVEPTIER) Received OUT Data Interrupt Enable Mask */
-#define DEVEPTIER_OVERFES_Pos 5 /**< (DEVEPTIER) Overflow Interrupt Enable Position */
-#define DEVEPTIER_OVERFES (_U_(0x1) << DEVEPTIER_OVERFES_Pos) /**< (DEVEPTIER) Overflow Interrupt Enable Mask */
-#define DEVEPTIER_SHORTPACKETES_Pos 7 /**< (DEVEPTIER) Short Packet Interrupt Enable Position */
-#define DEVEPTIER_SHORTPACKETES (_U_(0x1) << DEVEPTIER_SHORTPACKETES_Pos) /**< (DEVEPTIER) Short Packet Interrupt Enable Mask */
-#define DEVEPTIER_NBUSYBKES_Pos 12 /**< (DEVEPTIER) Number of Busy Banks Interrupt Enable Position */
-#define DEVEPTIER_NBUSYBKES (_U_(0x1) << DEVEPTIER_NBUSYBKES_Pos) /**< (DEVEPTIER) Number of Busy Banks Interrupt Enable Mask */
-#define DEVEPTIER_KILLBKS_Pos 13 /**< (DEVEPTIER) Kill IN Bank Position */
-#define DEVEPTIER_KILLBKS (_U_(0x1) << DEVEPTIER_KILLBKS_Pos) /**< (DEVEPTIER) Kill IN Bank Mask */
-#define DEVEPTIER_FIFOCONS_Pos 14 /**< (DEVEPTIER) FIFO Control Position */
-#define DEVEPTIER_FIFOCONS (_U_(0x1) << DEVEPTIER_FIFOCONS_Pos) /**< (DEVEPTIER) FIFO Control Mask */
-#define DEVEPTIER_EPDISHDMAS_Pos 16 /**< (DEVEPTIER) Endpoint Interrupts Disable HDMA Request Enable Position */
-#define DEVEPTIER_EPDISHDMAS (_U_(0x1) << DEVEPTIER_EPDISHDMAS_Pos) /**< (DEVEPTIER) Endpoint Interrupts Disable HDMA Request Enable Mask */
-#define DEVEPTIER_RSTDTS_Pos 18 /**< (DEVEPTIER) Reset Data Toggle Enable Position */
-#define DEVEPTIER_RSTDTS (_U_(0x1) << DEVEPTIER_RSTDTS_Pos) /**< (DEVEPTIER) Reset Data Toggle Enable Mask */
-#define DEVEPTIER_Msk _U_(0x570A3) /**< (DEVEPTIER) Register Mask */
-
-/* CTRL mode */
-#define DEVEPTIER_CTRL_RXSTPES_Pos 2 /**< (DEVEPTIER) Received SETUP Interrupt Enable Position */
-#define DEVEPTIER_CTRL_RXSTPES (_U_(0x1) << DEVEPTIER_CTRL_RXSTPES_Pos) /**< (DEVEPTIER) Received SETUP Interrupt Enable Mask */
-#define DEVEPTIER_CTRL_NAKOUTES_Pos 3 /**< (DEVEPTIER) NAKed OUT Interrupt Enable Position */
-#define DEVEPTIER_CTRL_NAKOUTES (_U_(0x1) << DEVEPTIER_CTRL_NAKOUTES_Pos) /**< (DEVEPTIER) NAKed OUT Interrupt Enable Mask */
-#define DEVEPTIER_CTRL_NAKINES_Pos 4 /**< (DEVEPTIER) NAKed IN Interrupt Enable Position */
-#define DEVEPTIER_CTRL_NAKINES (_U_(0x1) << DEVEPTIER_CTRL_NAKINES_Pos) /**< (DEVEPTIER) NAKed IN Interrupt Enable Mask */
-#define DEVEPTIER_CTRL_STALLEDES_Pos 6 /**< (DEVEPTIER) STALLed Interrupt Enable Position */
-#define DEVEPTIER_CTRL_STALLEDES (_U_(0x1) << DEVEPTIER_CTRL_STALLEDES_Pos) /**< (DEVEPTIER) STALLed Interrupt Enable Mask */
-#define DEVEPTIER_CTRL_NYETDISS_Pos 17 /**< (DEVEPTIER) NYET Token Disable Enable Position */
-#define DEVEPTIER_CTRL_NYETDISS (_U_(0x1) << DEVEPTIER_CTRL_NYETDISS_Pos) /**< (DEVEPTIER) NYET Token Disable Enable Mask */
-#define DEVEPTIER_CTRL_STALLRQS_Pos 19 /**< (DEVEPTIER) STALL Request Enable Position */
-#define DEVEPTIER_CTRL_STALLRQS (_U_(0x1) << DEVEPTIER_CTRL_STALLRQS_Pos) /**< (DEVEPTIER) STALL Request Enable Mask */
-#define DEVEPTIER_CTRL_Msk _U_(0xA005C) /**< (DEVEPTIER_CTRL) Register Mask */
-
-/* ISO mode */
-#define DEVEPTIER_ISO_UNDERFES_Pos 2 /**< (DEVEPTIER) Underflow Interrupt Enable Position */
-#define DEVEPTIER_ISO_UNDERFES (_U_(0x1) << DEVEPTIER_ISO_UNDERFES_Pos) /**< (DEVEPTIER) Underflow Interrupt Enable Mask */
-#define DEVEPTIER_ISO_HBISOINERRES_Pos 3 /**< (DEVEPTIER) High Bandwidth Isochronous IN Underflow Error Interrupt Enable Position */
-#define DEVEPTIER_ISO_HBISOINERRES (_U_(0x1) << DEVEPTIER_ISO_HBISOINERRES_Pos) /**< (DEVEPTIER) High Bandwidth Isochronous IN Underflow Error Interrupt Enable Mask */
-#define DEVEPTIER_ISO_HBISOFLUSHES_Pos 4 /**< (DEVEPTIER) High Bandwidth Isochronous IN Flush Interrupt Enable Position */
-#define DEVEPTIER_ISO_HBISOFLUSHES (_U_(0x1) << DEVEPTIER_ISO_HBISOFLUSHES_Pos) /**< (DEVEPTIER) High Bandwidth Isochronous IN Flush Interrupt Enable Mask */
-#define DEVEPTIER_ISO_CRCERRES_Pos 6 /**< (DEVEPTIER) CRC Error Interrupt Enable Position */
-#define DEVEPTIER_ISO_CRCERRES (_U_(0x1) << DEVEPTIER_ISO_CRCERRES_Pos) /**< (DEVEPTIER) CRC Error Interrupt Enable Mask */
-#define DEVEPTIER_ISO_MDATAES_Pos 8 /**< (DEVEPTIER) MData Interrupt Enable Position */
-#define DEVEPTIER_ISO_MDATAES (_U_(0x1) << DEVEPTIER_ISO_MDATAES_Pos) /**< (DEVEPTIER) MData Interrupt Enable Mask */
-#define DEVEPTIER_ISO_DATAXES_Pos 9 /**< (DEVEPTIER) DataX Interrupt Enable Position */
-#define DEVEPTIER_ISO_DATAXES (_U_(0x1) << DEVEPTIER_ISO_DATAXES_Pos) /**< (DEVEPTIER) DataX Interrupt Enable Mask */
-#define DEVEPTIER_ISO_ERRORTRANSES_Pos 10 /**< (DEVEPTIER) Transaction Error Interrupt Enable Position */
-#define DEVEPTIER_ISO_ERRORTRANSES (_U_(0x1) << DEVEPTIER_ISO_ERRORTRANSES_Pos) /**< (DEVEPTIER) Transaction Error Interrupt Enable Mask */
-#define DEVEPTIER_ISO_Msk _U_(0x75C) /**< (DEVEPTIER_ISO) Register Mask */
-
-/* BLK mode */
-#define DEVEPTIER_BLK_RXSTPES_Pos 2 /**< (DEVEPTIER) Received SETUP Interrupt Enable Position */
-#define DEVEPTIER_BLK_RXSTPES (_U_(0x1) << DEVEPTIER_BLK_RXSTPES_Pos) /**< (DEVEPTIER) Received SETUP Interrupt Enable Mask */
-#define DEVEPTIER_BLK_NAKOUTES_Pos 3 /**< (DEVEPTIER) NAKed OUT Interrupt Enable Position */
-#define DEVEPTIER_BLK_NAKOUTES (_U_(0x1) << DEVEPTIER_BLK_NAKOUTES_Pos) /**< (DEVEPTIER) NAKed OUT Interrupt Enable Mask */
-#define DEVEPTIER_BLK_NAKINES_Pos 4 /**< (DEVEPTIER) NAKed IN Interrupt Enable Position */
-#define DEVEPTIER_BLK_NAKINES (_U_(0x1) << DEVEPTIER_BLK_NAKINES_Pos) /**< (DEVEPTIER) NAKed IN Interrupt Enable Mask */
-#define DEVEPTIER_BLK_STALLEDES_Pos 6 /**< (DEVEPTIER) STALLed Interrupt Enable Position */
-#define DEVEPTIER_BLK_STALLEDES (_U_(0x1) << DEVEPTIER_BLK_STALLEDES_Pos) /**< (DEVEPTIER) STALLed Interrupt Enable Mask */
-#define DEVEPTIER_BLK_NYETDISS_Pos 17 /**< (DEVEPTIER) NYET Token Disable Enable Position */
-#define DEVEPTIER_BLK_NYETDISS (_U_(0x1) << DEVEPTIER_BLK_NYETDISS_Pos) /**< (DEVEPTIER) NYET Token Disable Enable Mask */
-#define DEVEPTIER_BLK_STALLRQS_Pos 19 /**< (DEVEPTIER) STALL Request Enable Position */
-#define DEVEPTIER_BLK_STALLRQS (_U_(0x1) << DEVEPTIER_BLK_STALLRQS_Pos) /**< (DEVEPTIER) STALL Request Enable Mask */
-#define DEVEPTIER_BLK_Msk _U_(0xA005C) /**< (DEVEPTIER_BLK) Register Mask */
-
-/* INTRPT mode */
-#define DEVEPTIER_INTRPT_RXSTPES_Pos 2 /**< (DEVEPTIER) Received SETUP Interrupt Enable Position */
-#define DEVEPTIER_INTRPT_RXSTPES (_U_(0x1) << DEVEPTIER_INTRPT_RXSTPES_Pos) /**< (DEVEPTIER) Received SETUP Interrupt Enable Mask */
-#define DEVEPTIER_INTRPT_NAKOUTES_Pos 3 /**< (DEVEPTIER) NAKed OUT Interrupt Enable Position */
-#define DEVEPTIER_INTRPT_NAKOUTES (_U_(0x1) << DEVEPTIER_INTRPT_NAKOUTES_Pos) /**< (DEVEPTIER) NAKed OUT Interrupt Enable Mask */
-#define DEVEPTIER_INTRPT_NAKINES_Pos 4 /**< (DEVEPTIER) NAKed IN Interrupt Enable Position */
-#define DEVEPTIER_INTRPT_NAKINES (_U_(0x1) << DEVEPTIER_INTRPT_NAKINES_Pos) /**< (DEVEPTIER) NAKed IN Interrupt Enable Mask */
-#define DEVEPTIER_INTRPT_STALLEDES_Pos 6 /**< (DEVEPTIER) STALLed Interrupt Enable Position */
-#define DEVEPTIER_INTRPT_STALLEDES (_U_(0x1) << DEVEPTIER_INTRPT_STALLEDES_Pos) /**< (DEVEPTIER) STALLed Interrupt Enable Mask */
-#define DEVEPTIER_INTRPT_NYETDISS_Pos 17 /**< (DEVEPTIER) NYET Token Disable Enable Position */
-#define DEVEPTIER_INTRPT_NYETDISS (_U_(0x1) << DEVEPTIER_INTRPT_NYETDISS_Pos) /**< (DEVEPTIER) NYET Token Disable Enable Mask */
-#define DEVEPTIER_INTRPT_STALLRQS_Pos 19 /**< (DEVEPTIER) STALL Request Enable Position */
-#define DEVEPTIER_INTRPT_STALLRQS (_U_(0x1) << DEVEPTIER_INTRPT_STALLRQS_Pos) /**< (DEVEPTIER) STALL Request Enable Mask */
-#define DEVEPTIER_INTRPT_Msk _U_(0xA005C) /**< (DEVEPTIER_INTRPT) Register Mask */
-
-
-/* -------- DEVEPTIDR : (USBHS Offset: 0x220) (/W 32) Device Endpoint Interrupt Disable Register -------- */
-
-#define DEVEPTIDR_OFFSET (0x220) /**< (DEVEPTIDR) Device Endpoint Interrupt Disable Register Offset */
-
-#define DEVEPTIDR_TXINEC_Pos 0 /**< (DEVEPTIDR) Transmitted IN Interrupt Clear Position */
-#define DEVEPTIDR_TXINEC (_U_(0x1) << DEVEPTIDR_TXINEC_Pos) /**< (DEVEPTIDR) Transmitted IN Interrupt Clear Mask */
-#define DEVEPTIDR_RXOUTEC_Pos 1 /**< (DEVEPTIDR) Received OUT Data Interrupt Clear Position */
-#define DEVEPTIDR_RXOUTEC (_U_(0x1) << DEVEPTIDR_RXOUTEC_Pos) /**< (DEVEPTIDR) Received OUT Data Interrupt Clear Mask */
-#define DEVEPTIDR_OVERFEC_Pos 5 /**< (DEVEPTIDR) Overflow Interrupt Clear Position */
-#define DEVEPTIDR_OVERFEC (_U_(0x1) << DEVEPTIDR_OVERFEC_Pos) /**< (DEVEPTIDR) Overflow Interrupt Clear Mask */
-#define DEVEPTIDR_SHORTPACKETEC_Pos 7 /**< (DEVEPTIDR) Shortpacket Interrupt Clear Position */
-#define DEVEPTIDR_SHORTPACKETEC (_U_(0x1) << DEVEPTIDR_SHORTPACKETEC_Pos) /**< (DEVEPTIDR) Shortpacket Interrupt Clear Mask */
-#define DEVEPTIDR_NBUSYBKEC_Pos 12 /**< (DEVEPTIDR) Number of Busy Banks Interrupt Clear Position */
-#define DEVEPTIDR_NBUSYBKEC (_U_(0x1) << DEVEPTIDR_NBUSYBKEC_Pos) /**< (DEVEPTIDR) Number of Busy Banks Interrupt Clear Mask */
-#define DEVEPTIDR_FIFOCONC_Pos 14 /**< (DEVEPTIDR) FIFO Control Clear Position */
-#define DEVEPTIDR_FIFOCONC (_U_(0x1) << DEVEPTIDR_FIFOCONC_Pos) /**< (DEVEPTIDR) FIFO Control Clear Mask */
-#define DEVEPTIDR_EPDISHDMAC_Pos 16 /**< (DEVEPTIDR) Endpoint Interrupts Disable HDMA Request Clear Position */
-#define DEVEPTIDR_EPDISHDMAC (_U_(0x1) << DEVEPTIDR_EPDISHDMAC_Pos) /**< (DEVEPTIDR) Endpoint Interrupts Disable HDMA Request Clear Mask */
-#define DEVEPTIDR_Msk _U_(0x150A3) /**< (DEVEPTIDR) Register Mask */
-
-/* CTRL mode */
-#define DEVEPTIDR_CTRL_RXSTPEC_Pos 2 /**< (DEVEPTIDR) Received SETUP Interrupt Clear Position */
-#define DEVEPTIDR_CTRL_RXSTPEC (_U_(0x1) << DEVEPTIDR_CTRL_RXSTPEC_Pos) /**< (DEVEPTIDR) Received SETUP Interrupt Clear Mask */
-#define DEVEPTIDR_CTRL_NAKOUTEC_Pos 3 /**< (DEVEPTIDR) NAKed OUT Interrupt Clear Position */
-#define DEVEPTIDR_CTRL_NAKOUTEC (_U_(0x1) << DEVEPTIDR_CTRL_NAKOUTEC_Pos) /**< (DEVEPTIDR) NAKed OUT Interrupt Clear Mask */
-#define DEVEPTIDR_CTRL_NAKINEC_Pos 4 /**< (DEVEPTIDR) NAKed IN Interrupt Clear Position */
-#define DEVEPTIDR_CTRL_NAKINEC (_U_(0x1) << DEVEPTIDR_CTRL_NAKINEC_Pos) /**< (DEVEPTIDR) NAKed IN Interrupt Clear Mask */
-#define DEVEPTIDR_CTRL_STALLEDEC_Pos 6 /**< (DEVEPTIDR) STALLed Interrupt Clear Position */
-#define DEVEPTIDR_CTRL_STALLEDEC (_U_(0x1) << DEVEPTIDR_CTRL_STALLEDEC_Pos) /**< (DEVEPTIDR) STALLed Interrupt Clear Mask */
-#define DEVEPTIDR_CTRL_NYETDISC_Pos 17 /**< (DEVEPTIDR) NYET Token Disable Clear Position */
-#define DEVEPTIDR_CTRL_NYETDISC (_U_(0x1) << DEVEPTIDR_CTRL_NYETDISC_Pos) /**< (DEVEPTIDR) NYET Token Disable Clear Mask */
-#define DEVEPTIDR_CTRL_STALLRQC_Pos 19 /**< (DEVEPTIDR) STALL Request Clear Position */
-#define DEVEPTIDR_CTRL_STALLRQC (_U_(0x1) << DEVEPTIDR_CTRL_STALLRQC_Pos) /**< (DEVEPTIDR) STALL Request Clear Mask */
-#define DEVEPTIDR_CTRL_Msk _U_(0xA005C) /**< (DEVEPTIDR_CTRL) Register Mask */
-
-/* ISO mode */
-#define DEVEPTIDR_ISO_UNDERFEC_Pos 2 /**< (DEVEPTIDR) Underflow Interrupt Clear Position */
-#define DEVEPTIDR_ISO_UNDERFEC (_U_(0x1) << DEVEPTIDR_ISO_UNDERFEC_Pos) /**< (DEVEPTIDR) Underflow Interrupt Clear Mask */
-#define DEVEPTIDR_ISO_HBISOINERREC_Pos 3 /**< (DEVEPTIDR) High Bandwidth Isochronous IN Underflow Error Interrupt Clear Position */
-#define DEVEPTIDR_ISO_HBISOINERREC (_U_(0x1) << DEVEPTIDR_ISO_HBISOINERREC_Pos) /**< (DEVEPTIDR) High Bandwidth Isochronous IN Underflow Error Interrupt Clear Mask */
-#define DEVEPTIDR_ISO_HBISOFLUSHEC_Pos 4 /**< (DEVEPTIDR) High Bandwidth Isochronous IN Flush Interrupt Clear Position */
-#define DEVEPTIDR_ISO_HBISOFLUSHEC (_U_(0x1) << DEVEPTIDR_ISO_HBISOFLUSHEC_Pos) /**< (DEVEPTIDR) High Bandwidth Isochronous IN Flush Interrupt Clear Mask */
-#define DEVEPTIDR_ISO_MDATAEC_Pos 8 /**< (DEVEPTIDR) MData Interrupt Clear Position */
-#define DEVEPTIDR_ISO_MDATAEC (_U_(0x1) << DEVEPTIDR_ISO_MDATAEC_Pos) /**< (DEVEPTIDR) MData Interrupt Clear Mask */
-#define DEVEPTIDR_ISO_DATAXEC_Pos 9 /**< (DEVEPTIDR) DataX Interrupt Clear Position */
-#define DEVEPTIDR_ISO_DATAXEC (_U_(0x1) << DEVEPTIDR_ISO_DATAXEC_Pos) /**< (DEVEPTIDR) DataX Interrupt Clear Mask */
-#define DEVEPTIDR_ISO_ERRORTRANSEC_Pos 10 /**< (DEVEPTIDR) Transaction Error Interrupt Clear Position */
-#define DEVEPTIDR_ISO_ERRORTRANSEC (_U_(0x1) << DEVEPTIDR_ISO_ERRORTRANSEC_Pos) /**< (DEVEPTIDR) Transaction Error Interrupt Clear Mask */
-#define DEVEPTIDR_ISO_Msk _U_(0x71C) /**< (DEVEPTIDR_ISO) Register Mask */
-
-/* BLK mode */
-#define DEVEPTIDR_BLK_RXSTPEC_Pos 2 /**< (DEVEPTIDR) Received SETUP Interrupt Clear Position */
-#define DEVEPTIDR_BLK_RXSTPEC (_U_(0x1) << DEVEPTIDR_BLK_RXSTPEC_Pos) /**< (DEVEPTIDR) Received SETUP Interrupt Clear Mask */
-#define DEVEPTIDR_BLK_NAKOUTEC_Pos 3 /**< (DEVEPTIDR) NAKed OUT Interrupt Clear Position */
-#define DEVEPTIDR_BLK_NAKOUTEC (_U_(0x1) << DEVEPTIDR_BLK_NAKOUTEC_Pos) /**< (DEVEPTIDR) NAKed OUT Interrupt Clear Mask */
-#define DEVEPTIDR_BLK_NAKINEC_Pos 4 /**< (DEVEPTIDR) NAKed IN Interrupt Clear Position */
-#define DEVEPTIDR_BLK_NAKINEC (_U_(0x1) << DEVEPTIDR_BLK_NAKINEC_Pos) /**< (DEVEPTIDR) NAKed IN Interrupt Clear Mask */
-#define DEVEPTIDR_BLK_STALLEDEC_Pos 6 /**< (DEVEPTIDR) STALLed Interrupt Clear Position */
-#define DEVEPTIDR_BLK_STALLEDEC (_U_(0x1) << DEVEPTIDR_BLK_STALLEDEC_Pos) /**< (DEVEPTIDR) STALLed Interrupt Clear Mask */
-#define DEVEPTIDR_BLK_NYETDISC_Pos 17 /**< (DEVEPTIDR) NYET Token Disable Clear Position */
-#define DEVEPTIDR_BLK_NYETDISC (_U_(0x1) << DEVEPTIDR_BLK_NYETDISC_Pos) /**< (DEVEPTIDR) NYET Token Disable Clear Mask */
-#define DEVEPTIDR_BLK_STALLRQC_Pos 19 /**< (DEVEPTIDR) STALL Request Clear Position */
-#define DEVEPTIDR_BLK_STALLRQC (_U_(0x1) << DEVEPTIDR_BLK_STALLRQC_Pos) /**< (DEVEPTIDR) STALL Request Clear Mask */
-#define DEVEPTIDR_BLK_Msk _U_(0xA005C) /**< (DEVEPTIDR_BLK) Register Mask */
-
-/* INTRPT mode */
-#define DEVEPTIDR_INTRPT_RXSTPEC_Pos 2 /**< (DEVEPTIDR) Received SETUP Interrupt Clear Position */
-#define DEVEPTIDR_INTRPT_RXSTPEC (_U_(0x1) << DEVEPTIDR_INTRPT_RXSTPEC_Pos) /**< (DEVEPTIDR) Received SETUP Interrupt Clear Mask */
-#define DEVEPTIDR_INTRPT_NAKOUTEC_Pos 3 /**< (DEVEPTIDR) NAKed OUT Interrupt Clear Position */
-#define DEVEPTIDR_INTRPT_NAKOUTEC (_U_(0x1) << DEVEPTIDR_INTRPT_NAKOUTEC_Pos) /**< (DEVEPTIDR) NAKed OUT Interrupt Clear Mask */
-#define DEVEPTIDR_INTRPT_NAKINEC_Pos 4 /**< (DEVEPTIDR) NAKed IN Interrupt Clear Position */
-#define DEVEPTIDR_INTRPT_NAKINEC (_U_(0x1) << DEVEPTIDR_INTRPT_NAKINEC_Pos) /**< (DEVEPTIDR) NAKed IN Interrupt Clear Mask */
-#define DEVEPTIDR_INTRPT_STALLEDEC_Pos 6 /**< (DEVEPTIDR) STALLed Interrupt Clear Position */
-#define DEVEPTIDR_INTRPT_STALLEDEC (_U_(0x1) << DEVEPTIDR_INTRPT_STALLEDEC_Pos) /**< (DEVEPTIDR) STALLed Interrupt Clear Mask */
-#define DEVEPTIDR_INTRPT_NYETDISC_Pos 17 /**< (DEVEPTIDR) NYET Token Disable Clear Position */
-#define DEVEPTIDR_INTRPT_NYETDISC (_U_(0x1) << DEVEPTIDR_INTRPT_NYETDISC_Pos) /**< (DEVEPTIDR) NYET Token Disable Clear Mask */
-#define DEVEPTIDR_INTRPT_STALLRQC_Pos 19 /**< (DEVEPTIDR) STALL Request Clear Position */
-#define DEVEPTIDR_INTRPT_STALLRQC (_U_(0x1) << DEVEPTIDR_INTRPT_STALLRQC_Pos) /**< (DEVEPTIDR) STALL Request Clear Mask */
-#define DEVEPTIDR_INTRPT_Msk _U_(0xA005C) /**< (DEVEPTIDR_INTRPT) Register Mask */
-
-
-/* -------- HSTCTRL : (USBHS Offset: 0x400) (R/W 32) Host General Control Register -------- */
-
-#define HSTCTRL_OFFSET (0x400) /**< (HSTCTRL) Host General Control Register Offset */
-
-#define HSTCTRL_SOFE_Pos 8 /**< (HSTCTRL) Start of Frame Generation Enable Position */
-#define HSTCTRL_SOFE (_U_(0x1) << HSTCTRL_SOFE_Pos) /**< (HSTCTRL) Start of Frame Generation Enable Mask */
-#define HSTCTRL_RESET_Pos 9 /**< (HSTCTRL) Send USB Reset Position */
-#define HSTCTRL_RESET (_U_(0x1) << HSTCTRL_RESET_Pos) /**< (HSTCTRL) Send USB Reset Mask */
-#define HSTCTRL_RESUME_Pos 10 /**< (HSTCTRL) Send USB Resume Position */
-#define HSTCTRL_RESUME (_U_(0x1) << HSTCTRL_RESUME_Pos) /**< (HSTCTRL) Send USB Resume Mask */
-#define HSTCTRL_SPDCONF_Pos 12 /**< (HSTCTRL) Mode Configuration Position */
-#define HSTCTRL_SPDCONF (_U_(0x3) << HSTCTRL_SPDCONF_Pos) /**< (HSTCTRL) Mode Configuration Mask */
-#define HSTCTRL_SPDCONF_NORMAL_Val _U_(0x0) /**< (HSTCTRL) The host starts in Full-speed mode and performs a high-speed reset to switch to High-speed mode if the downstream peripheral is high-speed capable. */
-#define HSTCTRL_SPDCONF_LOW_POWER_Val _U_(0x1) /**< (HSTCTRL) For a better consumption, if high speed is not needed. */
-#define HSTCTRL_SPDCONF_HIGH_SPEED_Val _U_(0x2) /**< (HSTCTRL) Forced high speed. */
-#define HSTCTRL_SPDCONF_FORCED_FS_Val _U_(0x3) /**< (HSTCTRL) The host remains in Full-speed mode whatever the peripheral speed capability. */
-#define HSTCTRL_SPDCONF_NORMAL (HSTCTRL_SPDCONF_NORMAL_Val << HSTCTRL_SPDCONF_Pos) /**< (HSTCTRL) The host starts in Full-speed mode and performs a high-speed reset to switch to High-speed mode if the downstream peripheral is high-speed capable. Position */
-#define HSTCTRL_SPDCONF_LOW_POWER (HSTCTRL_SPDCONF_LOW_POWER_Val << HSTCTRL_SPDCONF_Pos) /**< (HSTCTRL) For a better consumption, if high speed is not needed. Position */
-#define HSTCTRL_SPDCONF_HIGH_SPEED (HSTCTRL_SPDCONF_HIGH_SPEED_Val << HSTCTRL_SPDCONF_Pos) /**< (HSTCTRL) Forced high speed. Position */
-#define HSTCTRL_SPDCONF_FORCED_FS (HSTCTRL_SPDCONF_FORCED_FS_Val << HSTCTRL_SPDCONF_Pos) /**< (HSTCTRL) The host remains in Full-speed mode whatever the peripheral speed capability. Position */
-#define HSTCTRL_Msk _U_(0x3700) /**< (HSTCTRL) Register Mask */
-
-
-/* -------- HSTISR : (USBHS Offset: 0x404) (R/ 32) Host Global Interrupt Status Register -------- */
-
-#define HSTISR_OFFSET (0x404) /**< (HSTISR) Host Global Interrupt Status Register Offset */
-
-#define HSTISR_DCONNI_Pos 0 /**< (HSTISR) Device Connection Interrupt Position */
-#define HSTISR_DCONNI (_U_(0x1) << HSTISR_DCONNI_Pos) /**< (HSTISR) Device Connection Interrupt Mask */
-#define HSTISR_DDISCI_Pos 1 /**< (HSTISR) Device Disconnection Interrupt Position */
-#define HSTISR_DDISCI (_U_(0x1) << HSTISR_DDISCI_Pos) /**< (HSTISR) Device Disconnection Interrupt Mask */
-#define HSTISR_RSTI_Pos 2 /**< (HSTISR) USB Reset Sent Interrupt Position */
-#define HSTISR_RSTI (_U_(0x1) << HSTISR_RSTI_Pos) /**< (HSTISR) USB Reset Sent Interrupt Mask */
-#define HSTISR_RSMEDI_Pos 3 /**< (HSTISR) Downstream Resume Sent Interrupt Position */
-#define HSTISR_RSMEDI (_U_(0x1) << HSTISR_RSMEDI_Pos) /**< (HSTISR) Downstream Resume Sent Interrupt Mask */
-#define HSTISR_RXRSMI_Pos 4 /**< (HSTISR) Upstream Resume Received Interrupt Position */
-#define HSTISR_RXRSMI (_U_(0x1) << HSTISR_RXRSMI_Pos) /**< (HSTISR) Upstream Resume Received Interrupt Mask */
-#define HSTISR_HSOFI_Pos 5 /**< (HSTISR) Host Start of Frame Interrupt Position */
-#define HSTISR_HSOFI (_U_(0x1) << HSTISR_HSOFI_Pos) /**< (HSTISR) Host Start of Frame Interrupt Mask */
-#define HSTISR_HWUPI_Pos 6 /**< (HSTISR) Host Wake-Up Interrupt Position */
-#define HSTISR_HWUPI (_U_(0x1) << HSTISR_HWUPI_Pos) /**< (HSTISR) Host Wake-Up Interrupt Mask */
-#define HSTISR_PEP_0_Pos 8 /**< (HSTISR) Pipe 0 Interrupt Position */
-#define HSTISR_PEP_0 (_U_(0x1) << HSTISR_PEP_0_Pos) /**< (HSTISR) Pipe 0 Interrupt Mask */
-#define HSTISR_PEP_1_Pos 9 /**< (HSTISR) Pipe 1 Interrupt Position */
-#define HSTISR_PEP_1 (_U_(0x1) << HSTISR_PEP_1_Pos) /**< (HSTISR) Pipe 1 Interrupt Mask */
-#define HSTISR_PEP_2_Pos 10 /**< (HSTISR) Pipe 2 Interrupt Position */
-#define HSTISR_PEP_2 (_U_(0x1) << HSTISR_PEP_2_Pos) /**< (HSTISR) Pipe 2 Interrupt Mask */
-#define HSTISR_PEP_3_Pos 11 /**< (HSTISR) Pipe 3 Interrupt Position */
-#define HSTISR_PEP_3 (_U_(0x1) << HSTISR_PEP_3_Pos) /**< (HSTISR) Pipe 3 Interrupt Mask */
-#define HSTISR_PEP_4_Pos 12 /**< (HSTISR) Pipe 4 Interrupt Position */
-#define HSTISR_PEP_4 (_U_(0x1) << HSTISR_PEP_4_Pos) /**< (HSTISR) Pipe 4 Interrupt Mask */
-#define HSTISR_PEP_5_Pos 13 /**< (HSTISR) Pipe 5 Interrupt Position */
-#define HSTISR_PEP_5 (_U_(0x1) << HSTISR_PEP_5_Pos) /**< (HSTISR) Pipe 5 Interrupt Mask */
-#define HSTISR_PEP_6_Pos 14 /**< (HSTISR) Pipe 6 Interrupt Position */
-#define HSTISR_PEP_6 (_U_(0x1) << HSTISR_PEP_6_Pos) /**< (HSTISR) Pipe 6 Interrupt Mask */
-#define HSTISR_PEP_7_Pos 15 /**< (HSTISR) Pipe 7 Interrupt Position */
-#define HSTISR_PEP_7 (_U_(0x1) << HSTISR_PEP_7_Pos) /**< (HSTISR) Pipe 7 Interrupt Mask */
-#define HSTISR_PEP_8_Pos 16 /**< (HSTISR) Pipe 8 Interrupt Position */
-#define HSTISR_PEP_8 (_U_(0x1) << HSTISR_PEP_8_Pos) /**< (HSTISR) Pipe 8 Interrupt Mask */
-#define HSTISR_PEP_9_Pos 17 /**< (HSTISR) Pipe 9 Interrupt Position */
-#define HSTISR_PEP_9 (_U_(0x1) << HSTISR_PEP_9_Pos) /**< (HSTISR) Pipe 9 Interrupt Mask */
-#define HSTISR_DMA_0_Pos 25 /**< (HSTISR) DMA Channel 0 Interrupt Position */
-#define HSTISR_DMA_0 (_U_(0x1) << HSTISR_DMA_0_Pos) /**< (HSTISR) DMA Channel 0 Interrupt Mask */
-#define HSTISR_DMA_1_Pos 26 /**< (HSTISR) DMA Channel 1 Interrupt Position */
-#define HSTISR_DMA_1 (_U_(0x1) << HSTISR_DMA_1_Pos) /**< (HSTISR) DMA Channel 1 Interrupt Mask */
-#define HSTISR_DMA_2_Pos 27 /**< (HSTISR) DMA Channel 2 Interrupt Position */
-#define HSTISR_DMA_2 (_U_(0x1) << HSTISR_DMA_2_Pos) /**< (HSTISR) DMA Channel 2 Interrupt Mask */
-#define HSTISR_DMA_3_Pos 28 /**< (HSTISR) DMA Channel 3 Interrupt Position */
-#define HSTISR_DMA_3 (_U_(0x1) << HSTISR_DMA_3_Pos) /**< (HSTISR) DMA Channel 3 Interrupt Mask */
-#define HSTISR_DMA_4_Pos 29 /**< (HSTISR) DMA Channel 4 Interrupt Position */
-#define HSTISR_DMA_4 (_U_(0x1) << HSTISR_DMA_4_Pos) /**< (HSTISR) DMA Channel 4 Interrupt Mask */
-#define HSTISR_DMA_5_Pos 30 /**< (HSTISR) DMA Channel 5 Interrupt Position */
-#define HSTISR_DMA_5 (_U_(0x1) << HSTISR_DMA_5_Pos) /**< (HSTISR) DMA Channel 5 Interrupt Mask */
-#define HSTISR_DMA_6_Pos 31 /**< (HSTISR) DMA Channel 6 Interrupt Position */
-#define HSTISR_DMA_6 (_U_(0x1) << HSTISR_DMA_6_Pos) /**< (HSTISR) DMA Channel 6 Interrupt Mask */
-#define HSTISR_Msk _U_(0xFE03FF7F) /**< (HSTISR) Register Mask */
-
-#define HSTISR_PEP__Pos 8 /**< (HSTISR Position) Pipe x Interrupt */
-#define HSTISR_PEP_ (_U_(0x3FF) << HSTISR_PEP__Pos) /**< (HSTISR Mask) PEP_ */
-#define HSTISR_DMA__Pos 25 /**< (HSTISR Position) DMA Channel 6 Interrupt */
-#define HSTISR_DMA_ (_U_(0x7F) << HSTISR_DMA__Pos) /**< (HSTISR Mask) DMA_ */
-
-/* -------- HSTICR : (USBHS Offset: 0x408) (/W 32) Host Global Interrupt Clear Register -------- */
-
-#define HSTICR_OFFSET (0x408) /**< (HSTICR) Host Global Interrupt Clear Register Offset */
-
-#define HSTICR_DCONNIC_Pos 0 /**< (HSTICR) Device Connection Interrupt Clear Position */
-#define HSTICR_DCONNIC (_U_(0x1) << HSTICR_DCONNIC_Pos) /**< (HSTICR) Device Connection Interrupt Clear Mask */
-#define HSTICR_DDISCIC_Pos 1 /**< (HSTICR) Device Disconnection Interrupt Clear Position */
-#define HSTICR_DDISCIC (_U_(0x1) << HSTICR_DDISCIC_Pos) /**< (HSTICR) Device Disconnection Interrupt Clear Mask */
-#define HSTICR_RSTIC_Pos 2 /**< (HSTICR) USB Reset Sent Interrupt Clear Position */
-#define HSTICR_RSTIC (_U_(0x1) << HSTICR_RSTIC_Pos) /**< (HSTICR) USB Reset Sent Interrupt Clear Mask */
-#define HSTICR_RSMEDIC_Pos 3 /**< (HSTICR) Downstream Resume Sent Interrupt Clear Position */
-#define HSTICR_RSMEDIC (_U_(0x1) << HSTICR_RSMEDIC_Pos) /**< (HSTICR) Downstream Resume Sent Interrupt Clear Mask */
-#define HSTICR_RXRSMIC_Pos 4 /**< (HSTICR) Upstream Resume Received Interrupt Clear Position */
-#define HSTICR_RXRSMIC (_U_(0x1) << HSTICR_RXRSMIC_Pos) /**< (HSTICR) Upstream Resume Received Interrupt Clear Mask */
-#define HSTICR_HSOFIC_Pos 5 /**< (HSTICR) Host Start of Frame Interrupt Clear Position */
-#define HSTICR_HSOFIC (_U_(0x1) << HSTICR_HSOFIC_Pos) /**< (HSTICR) Host Start of Frame Interrupt Clear Mask */
-#define HSTICR_HWUPIC_Pos 6 /**< (HSTICR) Host Wake-Up Interrupt Clear Position */
-#define HSTICR_HWUPIC (_U_(0x1) << HSTICR_HWUPIC_Pos) /**< (HSTICR) Host Wake-Up Interrupt Clear Mask */
-#define HSTICR_Msk _U_(0x7F) /**< (HSTICR) Register Mask */
-
-
-/* -------- HSTIFR : (USBHS Offset: 0x40c) (/W 32) Host Global Interrupt Set Register -------- */
-
-#define HSTIFR_OFFSET (0x40C) /**< (HSTIFR) Host Global Interrupt Set Register Offset */
-
-#define HSTIFR_DCONNIS_Pos 0 /**< (HSTIFR) Device Connection Interrupt Set Position */
-#define HSTIFR_DCONNIS (_U_(0x1) << HSTIFR_DCONNIS_Pos) /**< (HSTIFR) Device Connection Interrupt Set Mask */
-#define HSTIFR_DDISCIS_Pos 1 /**< (HSTIFR) Device Disconnection Interrupt Set Position */
-#define HSTIFR_DDISCIS (_U_(0x1) << HSTIFR_DDISCIS_Pos) /**< (HSTIFR) Device Disconnection Interrupt Set Mask */
-#define HSTIFR_RSTIS_Pos 2 /**< (HSTIFR) USB Reset Sent Interrupt Set Position */
-#define HSTIFR_RSTIS (_U_(0x1) << HSTIFR_RSTIS_Pos) /**< (HSTIFR) USB Reset Sent Interrupt Set Mask */
-#define HSTIFR_RSMEDIS_Pos 3 /**< (HSTIFR) Downstream Resume Sent Interrupt Set Position */
-#define HSTIFR_RSMEDIS (_U_(0x1) << HSTIFR_RSMEDIS_Pos) /**< (HSTIFR) Downstream Resume Sent Interrupt Set Mask */
-#define HSTIFR_RXRSMIS_Pos 4 /**< (HSTIFR) Upstream Resume Received Interrupt Set Position */
-#define HSTIFR_RXRSMIS (_U_(0x1) << HSTIFR_RXRSMIS_Pos) /**< (HSTIFR) Upstream Resume Received Interrupt Set Mask */
-#define HSTIFR_HSOFIS_Pos 5 /**< (HSTIFR) Host Start of Frame Interrupt Set Position */
-#define HSTIFR_HSOFIS (_U_(0x1) << HSTIFR_HSOFIS_Pos) /**< (HSTIFR) Host Start of Frame Interrupt Set Mask */
-#define HSTIFR_HWUPIS_Pos 6 /**< (HSTIFR) Host Wake-Up Interrupt Set Position */
-#define HSTIFR_HWUPIS (_U_(0x1) << HSTIFR_HWUPIS_Pos) /**< (HSTIFR) Host Wake-Up Interrupt Set Mask */
-#define HSTIFR_DMA_0_Pos 25 /**< (HSTIFR) DMA Channel 0 Interrupt Set Position */
-#define HSTIFR_DMA_0 (_U_(0x1) << HSTIFR_DMA_0_Pos) /**< (HSTIFR) DMA Channel 0 Interrupt Set Mask */
-#define HSTIFR_DMA_1_Pos 26 /**< (HSTIFR) DMA Channel 1 Interrupt Set Position */
-#define HSTIFR_DMA_1 (_U_(0x1) << HSTIFR_DMA_1_Pos) /**< (HSTIFR) DMA Channel 1 Interrupt Set Mask */
-#define HSTIFR_DMA_2_Pos 27 /**< (HSTIFR) DMA Channel 2 Interrupt Set Position */
-#define HSTIFR_DMA_2 (_U_(0x1) << HSTIFR_DMA_2_Pos) /**< (HSTIFR) DMA Channel 2 Interrupt Set Mask */
-#define HSTIFR_DMA_3_Pos 28 /**< (HSTIFR) DMA Channel 3 Interrupt Set Position */
-#define HSTIFR_DMA_3 (_U_(0x1) << HSTIFR_DMA_3_Pos) /**< (HSTIFR) DMA Channel 3 Interrupt Set Mask */
-#define HSTIFR_DMA_4_Pos 29 /**< (HSTIFR) DMA Channel 4 Interrupt Set Position */
-#define HSTIFR_DMA_4 (_U_(0x1) << HSTIFR_DMA_4_Pos) /**< (HSTIFR) DMA Channel 4 Interrupt Set Mask */
-#define HSTIFR_DMA_5_Pos 30 /**< (HSTIFR) DMA Channel 5 Interrupt Set Position */
-#define HSTIFR_DMA_5 (_U_(0x1) << HSTIFR_DMA_5_Pos) /**< (HSTIFR) DMA Channel 5 Interrupt Set Mask */
-#define HSTIFR_DMA_6_Pos 31 /**< (HSTIFR) DMA Channel 6 Interrupt Set Position */
-#define HSTIFR_DMA_6 (_U_(0x1) << HSTIFR_DMA_6_Pos) /**< (HSTIFR) DMA Channel 6 Interrupt Set Mask */
-#define HSTIFR_Msk _U_(0xFE00007F) /**< (HSTIFR) Register Mask */
-
-#define HSTIFR_DMA__Pos 25 /**< (HSTIFR Position) DMA Channel 6 Interrupt Set */
-#define HSTIFR_DMA_ (_U_(0x7F) << HSTIFR_DMA__Pos) /**< (HSTIFR Mask) DMA_ */
-
-/* -------- HSTIMR : (USBHS Offset: 0x410) (R/ 32) Host Global Interrupt Mask Register -------- */
-
-#define HSTIMR_OFFSET (0x410) /**< (HSTIMR) Host Global Interrupt Mask Register Offset */
-
-#define HSTIMR_DCONNIE_Pos 0 /**< (HSTIMR) Device Connection Interrupt Enable Position */
-#define HSTIMR_DCONNIE (_U_(0x1) << HSTIMR_DCONNIE_Pos) /**< (HSTIMR) Device Connection Interrupt Enable Mask */
-#define HSTIMR_DDISCIE_Pos 1 /**< (HSTIMR) Device Disconnection Interrupt Enable Position */
-#define HSTIMR_DDISCIE (_U_(0x1) << HSTIMR_DDISCIE_Pos) /**< (HSTIMR) Device Disconnection Interrupt Enable Mask */
-#define HSTIMR_RSTIE_Pos 2 /**< (HSTIMR) USB Reset Sent Interrupt Enable Position */
-#define HSTIMR_RSTIE (_U_(0x1) << HSTIMR_RSTIE_Pos) /**< (HSTIMR) USB Reset Sent Interrupt Enable Mask */
-#define HSTIMR_RSMEDIE_Pos 3 /**< (HSTIMR) Downstream Resume Sent Interrupt Enable Position */
-#define HSTIMR_RSMEDIE (_U_(0x1) << HSTIMR_RSMEDIE_Pos) /**< (HSTIMR) Downstream Resume Sent Interrupt Enable Mask */
-#define HSTIMR_RXRSMIE_Pos 4 /**< (HSTIMR) Upstream Resume Received Interrupt Enable Position */
-#define HSTIMR_RXRSMIE (_U_(0x1) << HSTIMR_RXRSMIE_Pos) /**< (HSTIMR) Upstream Resume Received Interrupt Enable Mask */
-#define HSTIMR_HSOFIE_Pos 5 /**< (HSTIMR) Host Start of Frame Interrupt Enable Position */
-#define HSTIMR_HSOFIE (_U_(0x1) << HSTIMR_HSOFIE_Pos) /**< (HSTIMR) Host Start of Frame Interrupt Enable Mask */
-#define HSTIMR_HWUPIE_Pos 6 /**< (HSTIMR) Host Wake-Up Interrupt Enable Position */
-#define HSTIMR_HWUPIE (_U_(0x1) << HSTIMR_HWUPIE_Pos) /**< (HSTIMR) Host Wake-Up Interrupt Enable Mask */
-#define HSTIMR_PEP_0_Pos 8 /**< (HSTIMR) Pipe 0 Interrupt Enable Position */
-#define HSTIMR_PEP_0 (_U_(0x1) << HSTIMR_PEP_0_Pos) /**< (HSTIMR) Pipe 0 Interrupt Enable Mask */
-#define HSTIMR_PEP_1_Pos 9 /**< (HSTIMR) Pipe 1 Interrupt Enable Position */
-#define HSTIMR_PEP_1 (_U_(0x1) << HSTIMR_PEP_1_Pos) /**< (HSTIMR) Pipe 1 Interrupt Enable Mask */
-#define HSTIMR_PEP_2_Pos 10 /**< (HSTIMR) Pipe 2 Interrupt Enable Position */
-#define HSTIMR_PEP_2 (_U_(0x1) << HSTIMR_PEP_2_Pos) /**< (HSTIMR) Pipe 2 Interrupt Enable Mask */
-#define HSTIMR_PEP_3_Pos 11 /**< (HSTIMR) Pipe 3 Interrupt Enable Position */
-#define HSTIMR_PEP_3 (_U_(0x1) << HSTIMR_PEP_3_Pos) /**< (HSTIMR) Pipe 3 Interrupt Enable Mask */
-#define HSTIMR_PEP_4_Pos 12 /**< (HSTIMR) Pipe 4 Interrupt Enable Position */
-#define HSTIMR_PEP_4 (_U_(0x1) << HSTIMR_PEP_4_Pos) /**< (HSTIMR) Pipe 4 Interrupt Enable Mask */
-#define HSTIMR_PEP_5_Pos 13 /**< (HSTIMR) Pipe 5 Interrupt Enable Position */
-#define HSTIMR_PEP_5 (_U_(0x1) << HSTIMR_PEP_5_Pos) /**< (HSTIMR) Pipe 5 Interrupt Enable Mask */
-#define HSTIMR_PEP_6_Pos 14 /**< (HSTIMR) Pipe 6 Interrupt Enable Position */
-#define HSTIMR_PEP_6 (_U_(0x1) << HSTIMR_PEP_6_Pos) /**< (HSTIMR) Pipe 6 Interrupt Enable Mask */
-#define HSTIMR_PEP_7_Pos 15 /**< (HSTIMR) Pipe 7 Interrupt Enable Position */
-#define HSTIMR_PEP_7 (_U_(0x1) << HSTIMR_PEP_7_Pos) /**< (HSTIMR) Pipe 7 Interrupt Enable Mask */
-#define HSTIMR_PEP_8_Pos 16 /**< (HSTIMR) Pipe 8 Interrupt Enable Position */
-#define HSTIMR_PEP_8 (_U_(0x1) << HSTIMR_PEP_8_Pos) /**< (HSTIMR) Pipe 8 Interrupt Enable Mask */
-#define HSTIMR_PEP_9_Pos 17 /**< (HSTIMR) Pipe 9 Interrupt Enable Position */
-#define HSTIMR_PEP_9 (_U_(0x1) << HSTIMR_PEP_9_Pos) /**< (HSTIMR) Pipe 9 Interrupt Enable Mask */
-#define HSTIMR_DMA_0_Pos 25 /**< (HSTIMR) DMA Channel 0 Interrupt Enable Position */
-#define HSTIMR_DMA_0 (_U_(0x1) << HSTIMR_DMA_0_Pos) /**< (HSTIMR) DMA Channel 0 Interrupt Enable Mask */
-#define HSTIMR_DMA_1_Pos 26 /**< (HSTIMR) DMA Channel 1 Interrupt Enable Position */
-#define HSTIMR_DMA_1 (_U_(0x1) << HSTIMR_DMA_1_Pos) /**< (HSTIMR) DMA Channel 1 Interrupt Enable Mask */
-#define HSTIMR_DMA_2_Pos 27 /**< (HSTIMR) DMA Channel 2 Interrupt Enable Position */
-#define HSTIMR_DMA_2 (_U_(0x1) << HSTIMR_DMA_2_Pos) /**< (HSTIMR) DMA Channel 2 Interrupt Enable Mask */
-#define HSTIMR_DMA_3_Pos 28 /**< (HSTIMR) DMA Channel 3 Interrupt Enable Position */
-#define HSTIMR_DMA_3 (_U_(0x1) << HSTIMR_DMA_3_Pos) /**< (HSTIMR) DMA Channel 3 Interrupt Enable Mask */
-#define HSTIMR_DMA_4_Pos 29 /**< (HSTIMR) DMA Channel 4 Interrupt Enable Position */
-#define HSTIMR_DMA_4 (_U_(0x1) << HSTIMR_DMA_4_Pos) /**< (HSTIMR) DMA Channel 4 Interrupt Enable Mask */
-#define HSTIMR_DMA_5_Pos 30 /**< (HSTIMR) DMA Channel 5 Interrupt Enable Position */
-#define HSTIMR_DMA_5 (_U_(0x1) << HSTIMR_DMA_5_Pos) /**< (HSTIMR) DMA Channel 5 Interrupt Enable Mask */
-#define HSTIMR_DMA_6_Pos 31 /**< (HSTIMR) DMA Channel 6 Interrupt Enable Position */
-#define HSTIMR_DMA_6 (_U_(0x1) << HSTIMR_DMA_6_Pos) /**< (HSTIMR) DMA Channel 6 Interrupt Enable Mask */
-#define HSTIMR_Msk _U_(0xFE03FF7F) /**< (HSTIMR) Register Mask */
-
-#define HSTIMR_PEP__Pos 8 /**< (HSTIMR Position) Pipe x Interrupt Enable */
-#define HSTIMR_PEP_ (_U_(0x3FF) << HSTIMR_PEP__Pos) /**< (HSTIMR Mask) PEP_ */
-#define HSTIMR_DMA__Pos 25 /**< (HSTIMR Position) DMA Channel 6 Interrupt Enable */
-#define HSTIMR_DMA_ (_U_(0x7F) << HSTIMR_DMA__Pos) /**< (HSTIMR Mask) DMA_ */
-
-/* -------- HSTIDR : (USBHS Offset: 0x414) (/W 32) Host Global Interrupt Disable Register -------- */
-
-#define HSTIDR_OFFSET (0x414) /**< (HSTIDR) Host Global Interrupt Disable Register Offset */
-
-#define HSTIDR_DCONNIEC_Pos 0 /**< (HSTIDR) Device Connection Interrupt Disable Position */
-#define HSTIDR_DCONNIEC (_U_(0x1) << HSTIDR_DCONNIEC_Pos) /**< (HSTIDR) Device Connection Interrupt Disable Mask */
-#define HSTIDR_DDISCIEC_Pos 1 /**< (HSTIDR) Device Disconnection Interrupt Disable Position */
-#define HSTIDR_DDISCIEC (_U_(0x1) << HSTIDR_DDISCIEC_Pos) /**< (HSTIDR) Device Disconnection Interrupt Disable Mask */
-#define HSTIDR_RSTIEC_Pos 2 /**< (HSTIDR) USB Reset Sent Interrupt Disable Position */
-#define HSTIDR_RSTIEC (_U_(0x1) << HSTIDR_RSTIEC_Pos) /**< (HSTIDR) USB Reset Sent Interrupt Disable Mask */
-#define HSTIDR_RSMEDIEC_Pos 3 /**< (HSTIDR) Downstream Resume Sent Interrupt Disable Position */
-#define HSTIDR_RSMEDIEC (_U_(0x1) << HSTIDR_RSMEDIEC_Pos) /**< (HSTIDR) Downstream Resume Sent Interrupt Disable Mask */
-#define HSTIDR_RXRSMIEC_Pos 4 /**< (HSTIDR) Upstream Resume Received Interrupt Disable Position */
-#define HSTIDR_RXRSMIEC (_U_(0x1) << HSTIDR_RXRSMIEC_Pos) /**< (HSTIDR) Upstream Resume Received Interrupt Disable Mask */
-#define HSTIDR_HSOFIEC_Pos 5 /**< (HSTIDR) Host Start of Frame Interrupt Disable Position */
-#define HSTIDR_HSOFIEC (_U_(0x1) << HSTIDR_HSOFIEC_Pos) /**< (HSTIDR) Host Start of Frame Interrupt Disable Mask */
-#define HSTIDR_HWUPIEC_Pos 6 /**< (HSTIDR) Host Wake-Up Interrupt Disable Position */
-#define HSTIDR_HWUPIEC (_U_(0x1) << HSTIDR_HWUPIEC_Pos) /**< (HSTIDR) Host Wake-Up Interrupt Disable Mask */
-#define HSTIDR_PEP_0_Pos 8 /**< (HSTIDR) Pipe 0 Interrupt Disable Position */
-#define HSTIDR_PEP_0 (_U_(0x1) << HSTIDR_PEP_0_Pos) /**< (HSTIDR) Pipe 0 Interrupt Disable Mask */
-#define HSTIDR_PEP_1_Pos 9 /**< (HSTIDR) Pipe 1 Interrupt Disable Position */
-#define HSTIDR_PEP_1 (_U_(0x1) << HSTIDR_PEP_1_Pos) /**< (HSTIDR) Pipe 1 Interrupt Disable Mask */
-#define HSTIDR_PEP_2_Pos 10 /**< (HSTIDR) Pipe 2 Interrupt Disable Position */
-#define HSTIDR_PEP_2 (_U_(0x1) << HSTIDR_PEP_2_Pos) /**< (HSTIDR) Pipe 2 Interrupt Disable Mask */
-#define HSTIDR_PEP_3_Pos 11 /**< (HSTIDR) Pipe 3 Interrupt Disable Position */
-#define HSTIDR_PEP_3 (_U_(0x1) << HSTIDR_PEP_3_Pos) /**< (HSTIDR) Pipe 3 Interrupt Disable Mask */
-#define HSTIDR_PEP_4_Pos 12 /**< (HSTIDR) Pipe 4 Interrupt Disable Position */
-#define HSTIDR_PEP_4 (_U_(0x1) << HSTIDR_PEP_4_Pos) /**< (HSTIDR) Pipe 4 Interrupt Disable Mask */
-#define HSTIDR_PEP_5_Pos 13 /**< (HSTIDR) Pipe 5 Interrupt Disable Position */
-#define HSTIDR_PEP_5 (_U_(0x1) << HSTIDR_PEP_5_Pos) /**< (HSTIDR) Pipe 5 Interrupt Disable Mask */
-#define HSTIDR_PEP_6_Pos 14 /**< (HSTIDR) Pipe 6 Interrupt Disable Position */
-#define HSTIDR_PEP_6 (_U_(0x1) << HSTIDR_PEP_6_Pos) /**< (HSTIDR) Pipe 6 Interrupt Disable Mask */
-#define HSTIDR_PEP_7_Pos 15 /**< (HSTIDR) Pipe 7 Interrupt Disable Position */
-#define HSTIDR_PEP_7 (_U_(0x1) << HSTIDR_PEP_7_Pos) /**< (HSTIDR) Pipe 7 Interrupt Disable Mask */
-#define HSTIDR_PEP_8_Pos 16 /**< (HSTIDR) Pipe 8 Interrupt Disable Position */
-#define HSTIDR_PEP_8 (_U_(0x1) << HSTIDR_PEP_8_Pos) /**< (HSTIDR) Pipe 8 Interrupt Disable Mask */
-#define HSTIDR_PEP_9_Pos 17 /**< (HSTIDR) Pipe 9 Interrupt Disable Position */
-#define HSTIDR_PEP_9 (_U_(0x1) << HSTIDR_PEP_9_Pos) /**< (HSTIDR) Pipe 9 Interrupt Disable Mask */
-#define HSTIDR_DMA_0_Pos 25 /**< (HSTIDR) DMA Channel 0 Interrupt Disable Position */
-#define HSTIDR_DMA_0 (_U_(0x1) << HSTIDR_DMA_0_Pos) /**< (HSTIDR) DMA Channel 0 Interrupt Disable Mask */
-#define HSTIDR_DMA_1_Pos 26 /**< (HSTIDR) DMA Channel 1 Interrupt Disable Position */
-#define HSTIDR_DMA_1 (_U_(0x1) << HSTIDR_DMA_1_Pos) /**< (HSTIDR) DMA Channel 1 Interrupt Disable Mask */
-#define HSTIDR_DMA_2_Pos 27 /**< (HSTIDR) DMA Channel 2 Interrupt Disable Position */
-#define HSTIDR_DMA_2 (_U_(0x1) << HSTIDR_DMA_2_Pos) /**< (HSTIDR) DMA Channel 2 Interrupt Disable Mask */
-#define HSTIDR_DMA_3_Pos 28 /**< (HSTIDR) DMA Channel 3 Interrupt Disable Position */
-#define HSTIDR_DMA_3 (_U_(0x1) << HSTIDR_DMA_3_Pos) /**< (HSTIDR) DMA Channel 3 Interrupt Disable Mask */
-#define HSTIDR_DMA_4_Pos 29 /**< (HSTIDR) DMA Channel 4 Interrupt Disable Position */
-#define HSTIDR_DMA_4 (_U_(0x1) << HSTIDR_DMA_4_Pos) /**< (HSTIDR) DMA Channel 4 Interrupt Disable Mask */
-#define HSTIDR_DMA_5_Pos 30 /**< (HSTIDR) DMA Channel 5 Interrupt Disable Position */
-#define HSTIDR_DMA_5 (_U_(0x1) << HSTIDR_DMA_5_Pos) /**< (HSTIDR) DMA Channel 5 Interrupt Disable Mask */
-#define HSTIDR_DMA_6_Pos 31 /**< (HSTIDR) DMA Channel 6 Interrupt Disable Position */
-#define HSTIDR_DMA_6 (_U_(0x1) << HSTIDR_DMA_6_Pos) /**< (HSTIDR) DMA Channel 6 Interrupt Disable Mask */
-#define HSTIDR_Msk _U_(0xFE03FF7F) /**< (HSTIDR) Register Mask */
-
-#define HSTIDR_PEP__Pos 8 /**< (HSTIDR Position) Pipe x Interrupt Disable */
-#define HSTIDR_PEP_ (_U_(0x3FF) << HSTIDR_PEP__Pos) /**< (HSTIDR Mask) PEP_ */
-#define HSTIDR_DMA__Pos 25 /**< (HSTIDR Position) DMA Channel 6 Interrupt Disable */
-#define HSTIDR_DMA_ (_U_(0x7F) << HSTIDR_DMA__Pos) /**< (HSTIDR Mask) DMA_ */
-
-/* -------- HSTIER : (USBHS Offset: 0x418) (/W 32) Host Global Interrupt Enable Register -------- */
-
-#define HSTIER_OFFSET (0x418) /**< (HSTIER) Host Global Interrupt Enable Register Offset */
-
-#define HSTIER_DCONNIES_Pos 0 /**< (HSTIER) Device Connection Interrupt Enable Position */
-#define HSTIER_DCONNIES (_U_(0x1) << HSTIER_DCONNIES_Pos) /**< (HSTIER) Device Connection Interrupt Enable Mask */
-#define HSTIER_DDISCIES_Pos 1 /**< (HSTIER) Device Disconnection Interrupt Enable Position */
-#define HSTIER_DDISCIES (_U_(0x1) << HSTIER_DDISCIES_Pos) /**< (HSTIER) Device Disconnection Interrupt Enable Mask */
-#define HSTIER_RSTIES_Pos 2 /**< (HSTIER) USB Reset Sent Interrupt Enable Position */
-#define HSTIER_RSTIES (_U_(0x1) << HSTIER_RSTIES_Pos) /**< (HSTIER) USB Reset Sent Interrupt Enable Mask */
-#define HSTIER_RSMEDIES_Pos 3 /**< (HSTIER) Downstream Resume Sent Interrupt Enable Position */
-#define HSTIER_RSMEDIES (_U_(0x1) << HSTIER_RSMEDIES_Pos) /**< (HSTIER) Downstream Resume Sent Interrupt Enable Mask */
-#define HSTIER_RXRSMIES_Pos 4 /**< (HSTIER) Upstream Resume Received Interrupt Enable Position */
-#define HSTIER_RXRSMIES (_U_(0x1) << HSTIER_RXRSMIES_Pos) /**< (HSTIER) Upstream Resume Received Interrupt Enable Mask */
-#define HSTIER_HSOFIES_Pos 5 /**< (HSTIER) Host Start of Frame Interrupt Enable Position */
-#define HSTIER_HSOFIES (_U_(0x1) << HSTIER_HSOFIES_Pos) /**< (HSTIER) Host Start of Frame Interrupt Enable Mask */
-#define HSTIER_HWUPIES_Pos 6 /**< (HSTIER) Host Wake-Up Interrupt Enable Position */
-#define HSTIER_HWUPIES (_U_(0x1) << HSTIER_HWUPIES_Pos) /**< (HSTIER) Host Wake-Up Interrupt Enable Mask */
-#define HSTIER_PEP_0_Pos 8 /**< (HSTIER) Pipe 0 Interrupt Enable Position */
-#define HSTIER_PEP_0 (_U_(0x1) << HSTIER_PEP_0_Pos) /**< (HSTIER) Pipe 0 Interrupt Enable Mask */
-#define HSTIER_PEP_1_Pos 9 /**< (HSTIER) Pipe 1 Interrupt Enable Position */
-#define HSTIER_PEP_1 (_U_(0x1) << HSTIER_PEP_1_Pos) /**< (HSTIER) Pipe 1 Interrupt Enable Mask */
-#define HSTIER_PEP_2_Pos 10 /**< (HSTIER) Pipe 2 Interrupt Enable Position */
-#define HSTIER_PEP_2 (_U_(0x1) << HSTIER_PEP_2_Pos) /**< (HSTIER) Pipe 2 Interrupt Enable Mask */
-#define HSTIER_PEP_3_Pos 11 /**< (HSTIER) Pipe 3 Interrupt Enable Position */
-#define HSTIER_PEP_3 (_U_(0x1) << HSTIER_PEP_3_Pos) /**< (HSTIER) Pipe 3 Interrupt Enable Mask */
-#define HSTIER_PEP_4_Pos 12 /**< (HSTIER) Pipe 4 Interrupt Enable Position */
-#define HSTIER_PEP_4 (_U_(0x1) << HSTIER_PEP_4_Pos) /**< (HSTIER) Pipe 4 Interrupt Enable Mask */
-#define HSTIER_PEP_5_Pos 13 /**< (HSTIER) Pipe 5 Interrupt Enable Position */
-#define HSTIER_PEP_5 (_U_(0x1) << HSTIER_PEP_5_Pos) /**< (HSTIER) Pipe 5 Interrupt Enable Mask */
-#define HSTIER_PEP_6_Pos 14 /**< (HSTIER) Pipe 6 Interrupt Enable Position */
-#define HSTIER_PEP_6 (_U_(0x1) << HSTIER_PEP_6_Pos) /**< (HSTIER) Pipe 6 Interrupt Enable Mask */
-#define HSTIER_PEP_7_Pos 15 /**< (HSTIER) Pipe 7 Interrupt Enable Position */
-#define HSTIER_PEP_7 (_U_(0x1) << HSTIER_PEP_7_Pos) /**< (HSTIER) Pipe 7 Interrupt Enable Mask */
-#define HSTIER_PEP_8_Pos 16 /**< (HSTIER) Pipe 8 Interrupt Enable Position */
-#define HSTIER_PEP_8 (_U_(0x1) << HSTIER_PEP_8_Pos) /**< (HSTIER) Pipe 8 Interrupt Enable Mask */
-#define HSTIER_PEP_9_Pos 17 /**< (HSTIER) Pipe 9 Interrupt Enable Position */
-#define HSTIER_PEP_9 (_U_(0x1) << HSTIER_PEP_9_Pos) /**< (HSTIER) Pipe 9 Interrupt Enable Mask */
-#define HSTIER_DMA_0_Pos 25 /**< (HSTIER) DMA Channel 0 Interrupt Enable Position */
-#define HSTIER_DMA_0 (_U_(0x1) << HSTIER_DMA_0_Pos) /**< (HSTIER) DMA Channel 0 Interrupt Enable Mask */
-#define HSTIER_DMA_1_Pos 26 /**< (HSTIER) DMA Channel 1 Interrupt Enable Position */
-#define HSTIER_DMA_1 (_U_(0x1) << HSTIER_DMA_1_Pos) /**< (HSTIER) DMA Channel 1 Interrupt Enable Mask */
-#define HSTIER_DMA_2_Pos 27 /**< (HSTIER) DMA Channel 2 Interrupt Enable Position */
-#define HSTIER_DMA_2 (_U_(0x1) << HSTIER_DMA_2_Pos) /**< (HSTIER) DMA Channel 2 Interrupt Enable Mask */
-#define HSTIER_DMA_3_Pos 28 /**< (HSTIER) DMA Channel 3 Interrupt Enable Position */
-#define HSTIER_DMA_3 (_U_(0x1) << HSTIER_DMA_3_Pos) /**< (HSTIER) DMA Channel 3 Interrupt Enable Mask */
-#define HSTIER_DMA_4_Pos 29 /**< (HSTIER) DMA Channel 4 Interrupt Enable Position */
-#define HSTIER_DMA_4 (_U_(0x1) << HSTIER_DMA_4_Pos) /**< (HSTIER) DMA Channel 4 Interrupt Enable Mask */
-#define HSTIER_DMA_5_Pos 30 /**< (HSTIER) DMA Channel 5 Interrupt Enable Position */
-#define HSTIER_DMA_5 (_U_(0x1) << HSTIER_DMA_5_Pos) /**< (HSTIER) DMA Channel 5 Interrupt Enable Mask */
-#define HSTIER_DMA_6_Pos 31 /**< (HSTIER) DMA Channel 6 Interrupt Enable Position */
-#define HSTIER_DMA_6 (_U_(0x1) << HSTIER_DMA_6_Pos) /**< (HSTIER) DMA Channel 6 Interrupt Enable Mask */
-#define HSTIER_Msk _U_(0xFE03FF7F) /**< (HSTIER) Register Mask */
-
-#define HSTIER_PEP__Pos 8 /**< (HSTIER Position) Pipe x Interrupt Enable */
-#define HSTIER_PEP_ (_U_(0x3FF) << HSTIER_PEP__Pos) /**< (HSTIER Mask) PEP_ */
-#define HSTIER_DMA__Pos 25 /**< (HSTIER Position) DMA Channel 6 Interrupt Enable */
-#define HSTIER_DMA_ (_U_(0x7F) << HSTIER_DMA__Pos) /**< (HSTIER Mask) DMA_ */
-
-/* -------- HSTPIP : (USBHS Offset: 0x41c) (R/W 32) Host Pipe Register -------- */
-
-#define HSTPIP_OFFSET (0x41C) /**< (HSTPIP) Host Pipe Register Offset */
-
-#define HSTPIP_PEN0_Pos 0 /**< (HSTPIP) Pipe 0 Enable Position */
-#define HSTPIP_PEN0 (_U_(0x1) << HSTPIP_PEN0_Pos) /**< (HSTPIP) Pipe 0 Enable Mask */
-#define HSTPIP_PEN1_Pos 1 /**< (HSTPIP) Pipe 1 Enable Position */
-#define HSTPIP_PEN1 (_U_(0x1) << HSTPIP_PEN1_Pos) /**< (HSTPIP) Pipe 1 Enable Mask */
-#define HSTPIP_PEN2_Pos 2 /**< (HSTPIP) Pipe 2 Enable Position */
-#define HSTPIP_PEN2 (_U_(0x1) << HSTPIP_PEN2_Pos) /**< (HSTPIP) Pipe 2 Enable Mask */
-#define HSTPIP_PEN3_Pos 3 /**< (HSTPIP) Pipe 3 Enable Position */
-#define HSTPIP_PEN3 (_U_(0x1) << HSTPIP_PEN3_Pos) /**< (HSTPIP) Pipe 3 Enable Mask */
-#define HSTPIP_PEN4_Pos 4 /**< (HSTPIP) Pipe 4 Enable Position */
-#define HSTPIP_PEN4 (_U_(0x1) << HSTPIP_PEN4_Pos) /**< (HSTPIP) Pipe 4 Enable Mask */
-#define HSTPIP_PEN5_Pos 5 /**< (HSTPIP) Pipe 5 Enable Position */
-#define HSTPIP_PEN5 (_U_(0x1) << HSTPIP_PEN5_Pos) /**< (HSTPIP) Pipe 5 Enable Mask */
-#define HSTPIP_PEN6_Pos 6 /**< (HSTPIP) Pipe 6 Enable Position */
-#define HSTPIP_PEN6 (_U_(0x1) << HSTPIP_PEN6_Pos) /**< (HSTPIP) Pipe 6 Enable Mask */
-#define HSTPIP_PEN7_Pos 7 /**< (HSTPIP) Pipe 7 Enable Position */
-#define HSTPIP_PEN7 (_U_(0x1) << HSTPIP_PEN7_Pos) /**< (HSTPIP) Pipe 7 Enable Mask */
-#define HSTPIP_PEN8_Pos 8 /**< (HSTPIP) Pipe 8 Enable Position */
-#define HSTPIP_PEN8 (_U_(0x1) << HSTPIP_PEN8_Pos) /**< (HSTPIP) Pipe 8 Enable Mask */
-#define HSTPIP_PRST0_Pos 16 /**< (HSTPIP) Pipe 0 Reset Position */
-#define HSTPIP_PRST0 (_U_(0x1) << HSTPIP_PRST0_Pos) /**< (HSTPIP) Pipe 0 Reset Mask */
-#define HSTPIP_PRST1_Pos 17 /**< (HSTPIP) Pipe 1 Reset Position */
-#define HSTPIP_PRST1 (_U_(0x1) << HSTPIP_PRST1_Pos) /**< (HSTPIP) Pipe 1 Reset Mask */
-#define HSTPIP_PRST2_Pos 18 /**< (HSTPIP) Pipe 2 Reset Position */
-#define HSTPIP_PRST2 (_U_(0x1) << HSTPIP_PRST2_Pos) /**< (HSTPIP) Pipe 2 Reset Mask */
-#define HSTPIP_PRST3_Pos 19 /**< (HSTPIP) Pipe 3 Reset Position */
-#define HSTPIP_PRST3 (_U_(0x1) << HSTPIP_PRST3_Pos) /**< (HSTPIP) Pipe 3 Reset Mask */
-#define HSTPIP_PRST4_Pos 20 /**< (HSTPIP) Pipe 4 Reset Position */
-#define HSTPIP_PRST4 (_U_(0x1) << HSTPIP_PRST4_Pos) /**< (HSTPIP) Pipe 4 Reset Mask */
-#define HSTPIP_PRST5_Pos 21 /**< (HSTPIP) Pipe 5 Reset Position */
-#define HSTPIP_PRST5 (_U_(0x1) << HSTPIP_PRST5_Pos) /**< (HSTPIP) Pipe 5 Reset Mask */
-#define HSTPIP_PRST6_Pos 22 /**< (HSTPIP) Pipe 6 Reset Position */
-#define HSTPIP_PRST6 (_U_(0x1) << HSTPIP_PRST6_Pos) /**< (HSTPIP) Pipe 6 Reset Mask */
-#define HSTPIP_PRST7_Pos 23 /**< (HSTPIP) Pipe 7 Reset Position */
-#define HSTPIP_PRST7 (_U_(0x1) << HSTPIP_PRST7_Pos) /**< (HSTPIP) Pipe 7 Reset Mask */
-#define HSTPIP_PRST8_Pos 24 /**< (HSTPIP) Pipe 8 Reset Position */
-#define HSTPIP_PRST8 (_U_(0x1) << HSTPIP_PRST8_Pos) /**< (HSTPIP) Pipe 8 Reset Mask */
-#define HSTPIP_Msk _U_(0x1FF01FF) /**< (HSTPIP) Register Mask */
-
-#define HSTPIP_PEN_Pos 0 /**< (HSTPIP Position) Pipe x Enable */
-#define HSTPIP_PEN (_U_(0x1FF) << HSTPIP_PEN_Pos) /**< (HSTPIP Mask) PEN */
-#define HSTPIP_PRST_Pos 16 /**< (HSTPIP Position) Pipe 8 Reset */
-#define HSTPIP_PRST (_U_(0x1FF) << HSTPIP_PRST_Pos) /**< (HSTPIP Mask) PRST */
-
-/* -------- HSTFNUM : (USBHS Offset: 0x420) (R/W 32) Host Frame Number Register -------- */
-
-#define HSTFNUM_OFFSET (0x420) /**< (HSTFNUM) Host Frame Number Register Offset */
-
-#define HSTFNUM_MFNUM_Pos 0 /**< (HSTFNUM) Micro Frame Number Position */
-#define HSTFNUM_MFNUM (_U_(0x7) << HSTFNUM_MFNUM_Pos) /**< (HSTFNUM) Micro Frame Number Mask */
-#define HSTFNUM_FNUM_Pos 3 /**< (HSTFNUM) Frame Number Position */
-#define HSTFNUM_FNUM (_U_(0x7FF) << HSTFNUM_FNUM_Pos) /**< (HSTFNUM) Frame Number Mask */
-#define HSTFNUM_FLENHIGH_Pos 16 /**< (HSTFNUM) Frame Length Position */
-#define HSTFNUM_FLENHIGH (_U_(0xFF) << HSTFNUM_FLENHIGH_Pos) /**< (HSTFNUM) Frame Length Mask */
-#define HSTFNUM_Msk _U_(0xFF3FFF) /**< (HSTFNUM) Register Mask */
-
-
-/* -------- HSTADDR1 : (USBHS Offset: 0x424) (R/W 32) Host Address 1 Register -------- */
-
-#define HSTADDR1_OFFSET (0x424) /**< (HSTADDR1) Host Address 1 Register Offset */
-
-#define HSTADDR1_HSTADDRP0_Pos 0 /**< (HSTADDR1) USB Host Address Position */
-#define HSTADDR1_HSTADDRP0 (_U_(0x7F) << HSTADDR1_HSTADDRP0_Pos) /**< (HSTADDR1) USB Host Address Mask */
-#define HSTADDR1_HSTADDRP1_Pos 8 /**< (HSTADDR1) USB Host Address Position */
-#define HSTADDR1_HSTADDRP1 (_U_(0x7F) << HSTADDR1_HSTADDRP1_Pos) /**< (HSTADDR1) USB Host Address Mask */
-#define HSTADDR1_HSTADDRP2_Pos 16 /**< (HSTADDR1) USB Host Address Position */
-#define HSTADDR1_HSTADDRP2 (_U_(0x7F) << HSTADDR1_HSTADDRP2_Pos) /**< (HSTADDR1) USB Host Address Mask */
-#define HSTADDR1_HSTADDRP3_Pos 24 /**< (HSTADDR1) USB Host Address Position */
-#define HSTADDR1_HSTADDRP3 (_U_(0x7F) << HSTADDR1_HSTADDRP3_Pos) /**< (HSTADDR1) USB Host Address Mask */
-#define HSTADDR1_Msk _U_(0x7F7F7F7F) /**< (HSTADDR1) Register Mask */
-
-
-/* -------- HSTADDR2 : (USBHS Offset: 0x428) (R/W 32) Host Address 2 Register -------- */
-
-#define HSTADDR2_OFFSET (0x428) /**< (HSTADDR2) Host Address 2 Register Offset */
-
-#define HSTADDR2_HSTADDRP4_Pos 0 /**< (HSTADDR2) USB Host Address Position */
-#define HSTADDR2_HSTADDRP4 (_U_(0x7F) << HSTADDR2_HSTADDRP4_Pos) /**< (HSTADDR2) USB Host Address Mask */
-#define HSTADDR2_HSTADDRP5_Pos 8 /**< (HSTADDR2) USB Host Address Position */
-#define HSTADDR2_HSTADDRP5 (_U_(0x7F) << HSTADDR2_HSTADDRP5_Pos) /**< (HSTADDR2) USB Host Address Mask */
-#define HSTADDR2_HSTADDRP6_Pos 16 /**< (HSTADDR2) USB Host Address Position */
-#define HSTADDR2_HSTADDRP6 (_U_(0x7F) << HSTADDR2_HSTADDRP6_Pos) /**< (HSTADDR2) USB Host Address Mask */
-#define HSTADDR2_HSTADDRP7_Pos 24 /**< (HSTADDR2) USB Host Address Position */
-#define HSTADDR2_HSTADDRP7 (_U_(0x7F) << HSTADDR2_HSTADDRP7_Pos) /**< (HSTADDR2) USB Host Address Mask */
-#define HSTADDR2_Msk _U_(0x7F7F7F7F) /**< (HSTADDR2) Register Mask */
-
-
-/* -------- HSTADDR3 : (USBHS Offset: 0x42c) (R/W 32) Host Address 3 Register -------- */
-
-#define HSTADDR3_OFFSET (0x42C) /**< (HSTADDR3) Host Address 3 Register Offset */
-
-#define HSTADDR3_HSTADDRP8_Pos 0 /**< (HSTADDR3) USB Host Address Position */
-#define HSTADDR3_HSTADDRP8 (_U_(0x7F) << HSTADDR3_HSTADDRP8_Pos) /**< (HSTADDR3) USB Host Address Mask */
-#define HSTADDR3_HSTADDRP9_Pos 8 /**< (HSTADDR3) USB Host Address Position */
-#define HSTADDR3_HSTADDRP9 (_U_(0x7F) << HSTADDR3_HSTADDRP9_Pos) /**< (HSTADDR3) USB Host Address Mask */
-#define HSTADDR3_Msk _U_(0x7F7F) /**< (HSTADDR3) Register Mask */
-
-
-/* -------- HSTPIPCFG : (USBHS Offset: 0x500) (R/W 32) Host Pipe Configuration Register -------- */
-
-#define HSTPIPCFG_OFFSET (0x500) /**< (HSTPIPCFG) Host Pipe Configuration Register Offset */
-
-#define HSTPIPCFG_ALLOC_Pos 1 /**< (HSTPIPCFG) Pipe Memory Allocate Position */
-#define HSTPIPCFG_ALLOC (_U_(0x1) << HSTPIPCFG_ALLOC_Pos) /**< (HSTPIPCFG) Pipe Memory Allocate Mask */
-#define HSTPIPCFG_PBK_Pos 2 /**< (HSTPIPCFG) Pipe Banks Position */
-#define HSTPIPCFG_PBK (_U_(0x3) << HSTPIPCFG_PBK_Pos) /**< (HSTPIPCFG) Pipe Banks Mask */
-#define HSTPIPCFG_PBK_1_BANK_Val _U_(0x0) /**< (HSTPIPCFG) Single-bank pipe */
-#define HSTPIPCFG_PBK_2_BANK_Val _U_(0x1) /**< (HSTPIPCFG) Double-bank pipe */
-#define HSTPIPCFG_PBK_3_BANK_Val _U_(0x2) /**< (HSTPIPCFG) Triple-bank pipe */
-#define HSTPIPCFG_PBK_1_BANK (HSTPIPCFG_PBK_1_BANK_Val << HSTPIPCFG_PBK_Pos) /**< (HSTPIPCFG) Single-bank pipe Position */
-#define HSTPIPCFG_PBK_2_BANK (HSTPIPCFG_PBK_2_BANK_Val << HSTPIPCFG_PBK_Pos) /**< (HSTPIPCFG) Double-bank pipe Position */
-#define HSTPIPCFG_PBK_3_BANK (HSTPIPCFG_PBK_3_BANK_Val << HSTPIPCFG_PBK_Pos) /**< (HSTPIPCFG) Triple-bank pipe Position */
-#define HSTPIPCFG_PSIZE_Pos 4 /**< (HSTPIPCFG) Pipe Size Position */
-#define HSTPIPCFG_PSIZE (_U_(0x7) << HSTPIPCFG_PSIZE_Pos) /**< (HSTPIPCFG) Pipe Size Mask */
-#define HSTPIPCFG_PSIZE_8_BYTE_Val _U_(0x0) /**< (HSTPIPCFG) 8 bytes */
-#define HSTPIPCFG_PSIZE_16_BYTE_Val _U_(0x1) /**< (HSTPIPCFG) 16 bytes */
-#define HSTPIPCFG_PSIZE_32_BYTE_Val _U_(0x2) /**< (HSTPIPCFG) 32 bytes */
-#define HSTPIPCFG_PSIZE_64_BYTE_Val _U_(0x3) /**< (HSTPIPCFG) 64 bytes */
-#define HSTPIPCFG_PSIZE_128_BYTE_Val _U_(0x4) /**< (HSTPIPCFG) 128 bytes */
-#define HSTPIPCFG_PSIZE_256_BYTE_Val _U_(0x5) /**< (HSTPIPCFG) 256 bytes */
-#define HSTPIPCFG_PSIZE_512_BYTE_Val _U_(0x6) /**< (HSTPIPCFG) 512 bytes */
-#define HSTPIPCFG_PSIZE_1024_BYTE_Val _U_(0x7) /**< (HSTPIPCFG) 1024 bytes */
-#define HSTPIPCFG_PSIZE_8_BYTE (HSTPIPCFG_PSIZE_8_BYTE_Val << HSTPIPCFG_PSIZE_Pos) /**< (HSTPIPCFG) 8 bytes Position */
-#define HSTPIPCFG_PSIZE_16_BYTE (HSTPIPCFG_PSIZE_16_BYTE_Val << HSTPIPCFG_PSIZE_Pos) /**< (HSTPIPCFG) 16 bytes Position */
-#define HSTPIPCFG_PSIZE_32_BYTE (HSTPIPCFG_PSIZE_32_BYTE_Val << HSTPIPCFG_PSIZE_Pos) /**< (HSTPIPCFG) 32 bytes Position */
-#define HSTPIPCFG_PSIZE_64_BYTE (HSTPIPCFG_PSIZE_64_BYTE_Val << HSTPIPCFG_PSIZE_Pos) /**< (HSTPIPCFG) 64 bytes Position */
-#define HSTPIPCFG_PSIZE_128_BYTE (HSTPIPCFG_PSIZE_128_BYTE_Val << HSTPIPCFG_PSIZE_Pos) /**< (HSTPIPCFG) 128 bytes Position */
-#define HSTPIPCFG_PSIZE_256_BYTE (HSTPIPCFG_PSIZE_256_BYTE_Val << HSTPIPCFG_PSIZE_Pos) /**< (HSTPIPCFG) 256 bytes Position */
-#define HSTPIPCFG_PSIZE_512_BYTE (HSTPIPCFG_PSIZE_512_BYTE_Val << HSTPIPCFG_PSIZE_Pos) /**< (HSTPIPCFG) 512 bytes Position */
-#define HSTPIPCFG_PSIZE_1024_BYTE (HSTPIPCFG_PSIZE_1024_BYTE_Val << HSTPIPCFG_PSIZE_Pos) /**< (HSTPIPCFG) 1024 bytes Position */
-#define HSTPIPCFG_PTOKEN_Pos 8 /**< (HSTPIPCFG) Pipe Token Position */
-#define HSTPIPCFG_PTOKEN (_U_(0x3) << HSTPIPCFG_PTOKEN_Pos) /**< (HSTPIPCFG) Pipe Token Mask */
-#define HSTPIPCFG_PTOKEN_SETUP_Val _U_(0x0) /**< (HSTPIPCFG) SETUP */
-#define HSTPIPCFG_PTOKEN_IN_Val _U_(0x1) /**< (HSTPIPCFG) IN */
-#define HSTPIPCFG_PTOKEN_OUT_Val _U_(0x2) /**< (HSTPIPCFG) OUT */
-#define HSTPIPCFG_PTOKEN_SETUP (HSTPIPCFG_PTOKEN_SETUP_Val << HSTPIPCFG_PTOKEN_Pos) /**< (HSTPIPCFG) SETUP Position */
-#define HSTPIPCFG_PTOKEN_IN (HSTPIPCFG_PTOKEN_IN_Val << HSTPIPCFG_PTOKEN_Pos) /**< (HSTPIPCFG) IN Position */
-#define HSTPIPCFG_PTOKEN_OUT (HSTPIPCFG_PTOKEN_OUT_Val << HSTPIPCFG_PTOKEN_Pos) /**< (HSTPIPCFG) OUT Position */
-#define HSTPIPCFG_AUTOSW_Pos 10 /**< (HSTPIPCFG) Automatic Switch Position */
-#define HSTPIPCFG_AUTOSW (_U_(0x1) << HSTPIPCFG_AUTOSW_Pos) /**< (HSTPIPCFG) Automatic Switch Mask */
-#define HSTPIPCFG_PTYPE_Pos 12 /**< (HSTPIPCFG) Pipe Type Position */
-#define HSTPIPCFG_PTYPE (_U_(0x3) << HSTPIPCFG_PTYPE_Pos) /**< (HSTPIPCFG) Pipe Type Mask */
-#define HSTPIPCFG_PTYPE_CTRL_Val _U_(0x0) /**< (HSTPIPCFG) Control */
-#define HSTPIPCFG_PTYPE_ISO_Val _U_(0x1) /**< (HSTPIPCFG) Isochronous */
-#define HSTPIPCFG_PTYPE_BLK_Val _U_(0x2) /**< (HSTPIPCFG) Bulk */
-#define HSTPIPCFG_PTYPE_INTRPT_Val _U_(0x3) /**< (HSTPIPCFG) Interrupt */
-#define HSTPIPCFG_PTYPE_CTRL (HSTPIPCFG_PTYPE_CTRL_Val << HSTPIPCFG_PTYPE_Pos) /**< (HSTPIPCFG) Control Position */
-#define HSTPIPCFG_PTYPE_ISO (HSTPIPCFG_PTYPE_ISO_Val << HSTPIPCFG_PTYPE_Pos) /**< (HSTPIPCFG) Isochronous Position */
-#define HSTPIPCFG_PTYPE_BLK (HSTPIPCFG_PTYPE_BLK_Val << HSTPIPCFG_PTYPE_Pos) /**< (HSTPIPCFG) Bulk Position */
-#define HSTPIPCFG_PTYPE_INTRPT (HSTPIPCFG_PTYPE_INTRPT_Val << HSTPIPCFG_PTYPE_Pos) /**< (HSTPIPCFG) Interrupt Position */
-#define HSTPIPCFG_PEPNUM_Pos 16 /**< (HSTPIPCFG) Pipe Endpoint Number Position */
-#define HSTPIPCFG_PEPNUM (_U_(0xF) << HSTPIPCFG_PEPNUM_Pos) /**< (HSTPIPCFG) Pipe Endpoint Number Mask */
-#define HSTPIPCFG_INTFRQ_Pos 24 /**< (HSTPIPCFG) Pipe Interrupt Request Frequency Position */
-#define HSTPIPCFG_INTFRQ (_U_(0xFF) << HSTPIPCFG_INTFRQ_Pos) /**< (HSTPIPCFG) Pipe Interrupt Request Frequency Mask */
-#define HSTPIPCFG_Msk _U_(0xFF0F377E) /**< (HSTPIPCFG) Register Mask */
-
-/* CTRL_BULK mode */
-#define HSTPIPCFG_CTRL_BULK_PINGEN_Pos 20 /**< (HSTPIPCFG) Ping Enable Position */
-#define HSTPIPCFG_CTRL_BULK_PINGEN (_U_(0x1) << HSTPIPCFG_CTRL_BULK_PINGEN_Pos) /**< (HSTPIPCFG) Ping Enable Mask */
-#define HSTPIPCFG_CTRL_BULK_BINTERVAL_Pos 24 /**< (HSTPIPCFG) bInterval Parameter for the Bulk-Out/Ping Transaction Position */
-#define HSTPIPCFG_CTRL_BULK_BINTERVAL (_U_(0xFF) << HSTPIPCFG_CTRL_BULK_BINTERVAL_Pos) /**< (HSTPIPCFG) bInterval Parameter for the Bulk-Out/Ping Transaction Mask */
-#define HSTPIPCFG_CTRL_BULK_Msk _U_(0xFF100000) /**< (HSTPIPCFG_CTRL_BULK) Register Mask */
-
-
-/* -------- HSTPIPISR : (USBHS Offset: 0x530) (R/ 32) Host Pipe Status Register -------- */
-
-#define HSTPIPISR_OFFSET (0x530) /**< (HSTPIPISR) Host Pipe Status Register Offset */
-
-#define HSTPIPISR_RXINI_Pos 0 /**< (HSTPIPISR) Received IN Data Interrupt Position */
-#define HSTPIPISR_RXINI (_U_(0x1) << HSTPIPISR_RXINI_Pos) /**< (HSTPIPISR) Received IN Data Interrupt Mask */
-#define HSTPIPISR_TXOUTI_Pos 1 /**< (HSTPIPISR) Transmitted OUT Data Interrupt Position */
-#define HSTPIPISR_TXOUTI (_U_(0x1) << HSTPIPISR_TXOUTI_Pos) /**< (HSTPIPISR) Transmitted OUT Data Interrupt Mask */
-#define HSTPIPISR_PERRI_Pos 3 /**< (HSTPIPISR) Pipe Error Interrupt Position */
-#define HSTPIPISR_PERRI (_U_(0x1) << HSTPIPISR_PERRI_Pos) /**< (HSTPIPISR) Pipe Error Interrupt Mask */
-#define HSTPIPISR_NAKEDI_Pos 4 /**< (HSTPIPISR) NAKed Interrupt Position */
-#define HSTPIPISR_NAKEDI (_U_(0x1) << HSTPIPISR_NAKEDI_Pos) /**< (HSTPIPISR) NAKed Interrupt Mask */
-#define HSTPIPISR_OVERFI_Pos 5 /**< (HSTPIPISR) Overflow Interrupt Position */
-#define HSTPIPISR_OVERFI (_U_(0x1) << HSTPIPISR_OVERFI_Pos) /**< (HSTPIPISR) Overflow Interrupt Mask */
-#define HSTPIPISR_SHORTPACKETI_Pos 7 /**< (HSTPIPISR) Short Packet Interrupt Position */
-#define HSTPIPISR_SHORTPACKETI (_U_(0x1) << HSTPIPISR_SHORTPACKETI_Pos) /**< (HSTPIPISR) Short Packet Interrupt Mask */
-#define HSTPIPISR_DTSEQ_Pos 8 /**< (HSTPIPISR) Data Toggle Sequence Position */
-#define HSTPIPISR_DTSEQ (_U_(0x3) << HSTPIPISR_DTSEQ_Pos) /**< (HSTPIPISR) Data Toggle Sequence Mask */
-#define HSTPIPISR_DTSEQ_DATA0_Val _U_(0x0) /**< (HSTPIPISR) Data0 toggle sequence */
-#define HSTPIPISR_DTSEQ_DATA1_Val _U_(0x1) /**< (HSTPIPISR) Data1 toggle sequence */
-#define HSTPIPISR_DTSEQ_DATA0 (HSTPIPISR_DTSEQ_DATA0_Val << HSTPIPISR_DTSEQ_Pos) /**< (HSTPIPISR) Data0 toggle sequence Position */
-#define HSTPIPISR_DTSEQ_DATA1 (HSTPIPISR_DTSEQ_DATA1_Val << HSTPIPISR_DTSEQ_Pos) /**< (HSTPIPISR) Data1 toggle sequence Position */
-#define HSTPIPISR_NBUSYBK_Pos 12 /**< (HSTPIPISR) Number of Busy Banks Position */
-#define HSTPIPISR_NBUSYBK (_U_(0x3) << HSTPIPISR_NBUSYBK_Pos) /**< (HSTPIPISR) Number of Busy Banks Mask */
-#define HSTPIPISR_NBUSYBK_0_BUSY_Val _U_(0x0) /**< (HSTPIPISR) 0 busy bank (all banks free) */
-#define HSTPIPISR_NBUSYBK_1_BUSY_Val _U_(0x1) /**< (HSTPIPISR) 1 busy bank */
-#define HSTPIPISR_NBUSYBK_2_BUSY_Val _U_(0x2) /**< (HSTPIPISR) 2 busy banks */
-#define HSTPIPISR_NBUSYBK_3_BUSY_Val _U_(0x3) /**< (HSTPIPISR) 3 busy banks */
-#define HSTPIPISR_NBUSYBK_0_BUSY (HSTPIPISR_NBUSYBK_0_BUSY_Val << HSTPIPISR_NBUSYBK_Pos) /**< (HSTPIPISR) 0 busy bank (all banks free) Position */
-#define HSTPIPISR_NBUSYBK_1_BUSY (HSTPIPISR_NBUSYBK_1_BUSY_Val << HSTPIPISR_NBUSYBK_Pos) /**< (HSTPIPISR) 1 busy bank Position */
-#define HSTPIPISR_NBUSYBK_2_BUSY (HSTPIPISR_NBUSYBK_2_BUSY_Val << HSTPIPISR_NBUSYBK_Pos) /**< (HSTPIPISR) 2 busy banks Position */
-#define HSTPIPISR_NBUSYBK_3_BUSY (HSTPIPISR_NBUSYBK_3_BUSY_Val << HSTPIPISR_NBUSYBK_Pos) /**< (HSTPIPISR) 3 busy banks Position */
-#define HSTPIPISR_CURRBK_Pos 14 /**< (HSTPIPISR) Current Bank Position */
-#define HSTPIPISR_CURRBK (_U_(0x3) << HSTPIPISR_CURRBK_Pos) /**< (HSTPIPISR) Current Bank Mask */
-#define HSTPIPISR_CURRBK_BANK0_Val _U_(0x0) /**< (HSTPIPISR) Current bank is bank0 */
-#define HSTPIPISR_CURRBK_BANK1_Val _U_(0x1) /**< (HSTPIPISR) Current bank is bank1 */
-#define HSTPIPISR_CURRBK_BANK2_Val _U_(0x2) /**< (HSTPIPISR) Current bank is bank2 */
-#define HSTPIPISR_CURRBK_BANK0 (HSTPIPISR_CURRBK_BANK0_Val << HSTPIPISR_CURRBK_Pos) /**< (HSTPIPISR) Current bank is bank0 Position */
-#define HSTPIPISR_CURRBK_BANK1 (HSTPIPISR_CURRBK_BANK1_Val << HSTPIPISR_CURRBK_Pos) /**< (HSTPIPISR) Current bank is bank1 Position */
-#define HSTPIPISR_CURRBK_BANK2 (HSTPIPISR_CURRBK_BANK2_Val << HSTPIPISR_CURRBK_Pos) /**< (HSTPIPISR) Current bank is bank2 Position */
-#define HSTPIPISR_RWALL_Pos 16 /**< (HSTPIPISR) Read/Write Allowed Position */
-#define HSTPIPISR_RWALL (_U_(0x1) << HSTPIPISR_RWALL_Pos) /**< (HSTPIPISR) Read/Write Allowed Mask */
-#define HSTPIPISR_CFGOK_Pos 18 /**< (HSTPIPISR) Configuration OK Status Position */
-#define HSTPIPISR_CFGOK (_U_(0x1) << HSTPIPISR_CFGOK_Pos) /**< (HSTPIPISR) Configuration OK Status Mask */
-#define HSTPIPISR_PBYCT_Pos 20 /**< (HSTPIPISR) Pipe Byte Count Position */
-#define HSTPIPISR_PBYCT (_U_(0x7FF) << HSTPIPISR_PBYCT_Pos) /**< (HSTPIPISR) Pipe Byte Count Mask */
-#define HSTPIPISR_Msk _U_(0x7FF5F3BB) /**< (HSTPIPISR) Register Mask */
-
-/* CTRL mode */
-#define HSTPIPISR_CTRL_TXSTPI_Pos 2 /**< (HSTPIPISR) Transmitted SETUP Interrupt Position */
-#define HSTPIPISR_CTRL_TXSTPI (_U_(0x1) << HSTPIPISR_CTRL_TXSTPI_Pos) /**< (HSTPIPISR) Transmitted SETUP Interrupt Mask */
-#define HSTPIPISR_CTRL_RXSTALLDI_Pos 6 /**< (HSTPIPISR) Received STALLed Interrupt Position */
-#define HSTPIPISR_CTRL_RXSTALLDI (_U_(0x1) << HSTPIPISR_CTRL_RXSTALLDI_Pos) /**< (HSTPIPISR) Received STALLed Interrupt Mask */
-#define HSTPIPISR_CTRL_Msk _U_(0x44) /**< (HSTPIPISR_CTRL) Register Mask */
-
-/* ISO mode */
-#define HSTPIPISR_ISO_UNDERFI_Pos 2 /**< (HSTPIPISR) Underflow Interrupt Position */
-#define HSTPIPISR_ISO_UNDERFI (_U_(0x1) << HSTPIPISR_ISO_UNDERFI_Pos) /**< (HSTPIPISR) Underflow Interrupt Mask */
-#define HSTPIPISR_ISO_CRCERRI_Pos 6 /**< (HSTPIPISR) CRC Error Interrupt Position */
-#define HSTPIPISR_ISO_CRCERRI (_U_(0x1) << HSTPIPISR_ISO_CRCERRI_Pos) /**< (HSTPIPISR) CRC Error Interrupt Mask */
-#define HSTPIPISR_ISO_Msk _U_(0x44) /**< (HSTPIPISR_ISO) Register Mask */
-
-/* BLK mode */
-#define HSTPIPISR_BLK_TXSTPI_Pos 2 /**< (HSTPIPISR) Transmitted SETUP Interrupt Position */
-#define HSTPIPISR_BLK_TXSTPI (_U_(0x1) << HSTPIPISR_BLK_TXSTPI_Pos) /**< (HSTPIPISR) Transmitted SETUP Interrupt Mask */
-#define HSTPIPISR_BLK_RXSTALLDI_Pos 6 /**< (HSTPIPISR) Received STALLed Interrupt Position */
-#define HSTPIPISR_BLK_RXSTALLDI (_U_(0x1) << HSTPIPISR_BLK_RXSTALLDI_Pos) /**< (HSTPIPISR) Received STALLed Interrupt Mask */
-#define HSTPIPISR_BLK_Msk _U_(0x44) /**< (HSTPIPISR_BLK) Register Mask */
-
-/* INTRPT mode */
-#define HSTPIPISR_INTRPT_UNDERFI_Pos 2 /**< (HSTPIPISR) Underflow Interrupt Position */
-#define HSTPIPISR_INTRPT_UNDERFI (_U_(0x1) << HSTPIPISR_INTRPT_UNDERFI_Pos) /**< (HSTPIPISR) Underflow Interrupt Mask */
-#define HSTPIPISR_INTRPT_RXSTALLDI_Pos 6 /**< (HSTPIPISR) Received STALLed Interrupt Position */
-#define HSTPIPISR_INTRPT_RXSTALLDI (_U_(0x1) << HSTPIPISR_INTRPT_RXSTALLDI_Pos) /**< (HSTPIPISR) Received STALLed Interrupt Mask */
-#define HSTPIPISR_INTRPT_Msk _U_(0x44) /**< (HSTPIPISR_INTRPT) Register Mask */
-
-
-/* -------- HSTPIPICR : (USBHS Offset: 0x560) (/W 32) Host Pipe Clear Register -------- */
-
-#define HSTPIPICR_OFFSET (0x560) /**< (HSTPIPICR) Host Pipe Clear Register Offset */
-
-#define HSTPIPICR_RXINIC_Pos 0 /**< (HSTPIPICR) Received IN Data Interrupt Clear Position */
-#define HSTPIPICR_RXINIC (_U_(0x1) << HSTPIPICR_RXINIC_Pos) /**< (HSTPIPICR) Received IN Data Interrupt Clear Mask */
-#define HSTPIPICR_TXOUTIC_Pos 1 /**< (HSTPIPICR) Transmitted OUT Data Interrupt Clear Position */
-#define HSTPIPICR_TXOUTIC (_U_(0x1) << HSTPIPICR_TXOUTIC_Pos) /**< (HSTPIPICR) Transmitted OUT Data Interrupt Clear Mask */
-#define HSTPIPICR_NAKEDIC_Pos 4 /**< (HSTPIPICR) NAKed Interrupt Clear Position */
-#define HSTPIPICR_NAKEDIC (_U_(0x1) << HSTPIPICR_NAKEDIC_Pos) /**< (HSTPIPICR) NAKed Interrupt Clear Mask */
-#define HSTPIPICR_OVERFIC_Pos 5 /**< (HSTPIPICR) Overflow Interrupt Clear Position */
-#define HSTPIPICR_OVERFIC (_U_(0x1) << HSTPIPICR_OVERFIC_Pos) /**< (HSTPIPICR) Overflow Interrupt Clear Mask */
-#define HSTPIPICR_SHORTPACKETIC_Pos 7 /**< (HSTPIPICR) Short Packet Interrupt Clear Position */
-#define HSTPIPICR_SHORTPACKETIC (_U_(0x1) << HSTPIPICR_SHORTPACKETIC_Pos) /**< (HSTPIPICR) Short Packet Interrupt Clear Mask */
-#define HSTPIPICR_Msk _U_(0xB3) /**< (HSTPIPICR) Register Mask */
-
-/* CTRL mode */
-#define HSTPIPICR_CTRL_TXSTPIC_Pos 2 /**< (HSTPIPICR) Transmitted SETUP Interrupt Clear Position */
-#define HSTPIPICR_CTRL_TXSTPIC (_U_(0x1) << HSTPIPICR_CTRL_TXSTPIC_Pos) /**< (HSTPIPICR) Transmitted SETUP Interrupt Clear Mask */
-#define HSTPIPICR_CTRL_RXSTALLDIC_Pos 6 /**< (HSTPIPICR) Received STALLed Interrupt Clear Position */
-#define HSTPIPICR_CTRL_RXSTALLDIC (_U_(0x1) << HSTPIPICR_CTRL_RXSTALLDIC_Pos) /**< (HSTPIPICR) Received STALLed Interrupt Clear Mask */
-#define HSTPIPICR_CTRL_Msk _U_(0x44) /**< (HSTPIPICR_CTRL) Register Mask */
-
-/* ISO mode */
-#define HSTPIPICR_ISO_UNDERFIC_Pos 2 /**< (HSTPIPICR) Underflow Interrupt Clear Position */
-#define HSTPIPICR_ISO_UNDERFIC (_U_(0x1) << HSTPIPICR_ISO_UNDERFIC_Pos) /**< (HSTPIPICR) Underflow Interrupt Clear Mask */
-#define HSTPIPICR_ISO_CRCERRIC_Pos 6 /**< (HSTPIPICR) CRC Error Interrupt Clear Position */
-#define HSTPIPICR_ISO_CRCERRIC (_U_(0x1) << HSTPIPICR_ISO_CRCERRIC_Pos) /**< (HSTPIPICR) CRC Error Interrupt Clear Mask */
-#define HSTPIPICR_ISO_Msk _U_(0x44) /**< (HSTPIPICR_ISO) Register Mask */
-
-/* BLK mode */
-#define HSTPIPICR_BLK_TXSTPIC_Pos 2 /**< (HSTPIPICR) Transmitted SETUP Interrupt Clear Position */
-#define HSTPIPICR_BLK_TXSTPIC (_U_(0x1) << HSTPIPICR_BLK_TXSTPIC_Pos) /**< (HSTPIPICR) Transmitted SETUP Interrupt Clear Mask */
-#define HSTPIPICR_BLK_RXSTALLDIC_Pos 6 /**< (HSTPIPICR) Received STALLed Interrupt Clear Position */
-#define HSTPIPICR_BLK_RXSTALLDIC (_U_(0x1) << HSTPIPICR_BLK_RXSTALLDIC_Pos) /**< (HSTPIPICR) Received STALLed Interrupt Clear Mask */
-#define HSTPIPICR_BLK_Msk _U_(0x44) /**< (HSTPIPICR_BLK) Register Mask */
-
-/* INTRPT mode */
-#define HSTPIPICR_INTRPT_UNDERFIC_Pos 2 /**< (HSTPIPICR) Underflow Interrupt Clear Position */
-#define HSTPIPICR_INTRPT_UNDERFIC (_U_(0x1) << HSTPIPICR_INTRPT_UNDERFIC_Pos) /**< (HSTPIPICR) Underflow Interrupt Clear Mask */
-#define HSTPIPICR_INTRPT_RXSTALLDIC_Pos 6 /**< (HSTPIPICR) Received STALLed Interrupt Clear Position */
-#define HSTPIPICR_INTRPT_RXSTALLDIC (_U_(0x1) << HSTPIPICR_INTRPT_RXSTALLDIC_Pos) /**< (HSTPIPICR) Received STALLed Interrupt Clear Mask */
-#define HSTPIPICR_INTRPT_Msk _U_(0x44) /**< (HSTPIPICR_INTRPT) Register Mask */
-
-
-/* -------- HSTPIPIFR : (USBHS Offset: 0x590) (/W 32) Host Pipe Set Register -------- */
-
-#define HSTPIPIFR_OFFSET (0x590) /**< (HSTPIPIFR) Host Pipe Set Register Offset */
-
-#define HSTPIPIFR_RXINIS_Pos 0 /**< (HSTPIPIFR) Received IN Data Interrupt Set Position */
-#define HSTPIPIFR_RXINIS (_U_(0x1) << HSTPIPIFR_RXINIS_Pos) /**< (HSTPIPIFR) Received IN Data Interrupt Set Mask */
-#define HSTPIPIFR_TXOUTIS_Pos 1 /**< (HSTPIPIFR) Transmitted OUT Data Interrupt Set Position */
-#define HSTPIPIFR_TXOUTIS (_U_(0x1) << HSTPIPIFR_TXOUTIS_Pos) /**< (HSTPIPIFR) Transmitted OUT Data Interrupt Set Mask */
-#define HSTPIPIFR_PERRIS_Pos 3 /**< (HSTPIPIFR) Pipe Error Interrupt Set Position */
-#define HSTPIPIFR_PERRIS (_U_(0x1) << HSTPIPIFR_PERRIS_Pos) /**< (HSTPIPIFR) Pipe Error Interrupt Set Mask */
-#define HSTPIPIFR_NAKEDIS_Pos 4 /**< (HSTPIPIFR) NAKed Interrupt Set Position */
-#define HSTPIPIFR_NAKEDIS (_U_(0x1) << HSTPIPIFR_NAKEDIS_Pos) /**< (HSTPIPIFR) NAKed Interrupt Set Mask */
-#define HSTPIPIFR_OVERFIS_Pos 5 /**< (HSTPIPIFR) Overflow Interrupt Set Position */
-#define HSTPIPIFR_OVERFIS (_U_(0x1) << HSTPIPIFR_OVERFIS_Pos) /**< (HSTPIPIFR) Overflow Interrupt Set Mask */
-#define HSTPIPIFR_SHORTPACKETIS_Pos 7 /**< (HSTPIPIFR) Short Packet Interrupt Set Position */
-#define HSTPIPIFR_SHORTPACKETIS (_U_(0x1) << HSTPIPIFR_SHORTPACKETIS_Pos) /**< (HSTPIPIFR) Short Packet Interrupt Set Mask */
-#define HSTPIPIFR_NBUSYBKS_Pos 12 /**< (HSTPIPIFR) Number of Busy Banks Set Position */
-#define HSTPIPIFR_NBUSYBKS (_U_(0x1) << HSTPIPIFR_NBUSYBKS_Pos) /**< (HSTPIPIFR) Number of Busy Banks Set Mask */
-#define HSTPIPIFR_Msk _U_(0x10BB) /**< (HSTPIPIFR) Register Mask */
-
-/* CTRL mode */
-#define HSTPIPIFR_CTRL_TXSTPIS_Pos 2 /**< (HSTPIPIFR) Transmitted SETUP Interrupt Set Position */
-#define HSTPIPIFR_CTRL_TXSTPIS (_U_(0x1) << HSTPIPIFR_CTRL_TXSTPIS_Pos) /**< (HSTPIPIFR) Transmitted SETUP Interrupt Set Mask */
-#define HSTPIPIFR_CTRL_RXSTALLDIS_Pos 6 /**< (HSTPIPIFR) Received STALLed Interrupt Set Position */
-#define HSTPIPIFR_CTRL_RXSTALLDIS (_U_(0x1) << HSTPIPIFR_CTRL_RXSTALLDIS_Pos) /**< (HSTPIPIFR) Received STALLed Interrupt Set Mask */
-#define HSTPIPIFR_CTRL_Msk _U_(0x44) /**< (HSTPIPIFR_CTRL) Register Mask */
-
-/* ISO mode */
-#define HSTPIPIFR_ISO_UNDERFIS_Pos 2 /**< (HSTPIPIFR) Underflow Interrupt Set Position */
-#define HSTPIPIFR_ISO_UNDERFIS (_U_(0x1) << HSTPIPIFR_ISO_UNDERFIS_Pos) /**< (HSTPIPIFR) Underflow Interrupt Set Mask */
-#define HSTPIPIFR_ISO_CRCERRIS_Pos 6 /**< (HSTPIPIFR) CRC Error Interrupt Set Position */
-#define HSTPIPIFR_ISO_CRCERRIS (_U_(0x1) << HSTPIPIFR_ISO_CRCERRIS_Pos) /**< (HSTPIPIFR) CRC Error Interrupt Set Mask */
-#define HSTPIPIFR_ISO_Msk _U_(0x44) /**< (HSTPIPIFR_ISO) Register Mask */
-
-/* BLK mode */
-#define HSTPIPIFR_BLK_TXSTPIS_Pos 2 /**< (HSTPIPIFR) Transmitted SETUP Interrupt Set Position */
-#define HSTPIPIFR_BLK_TXSTPIS (_U_(0x1) << HSTPIPIFR_BLK_TXSTPIS_Pos) /**< (HSTPIPIFR) Transmitted SETUP Interrupt Set Mask */
-#define HSTPIPIFR_BLK_RXSTALLDIS_Pos 6 /**< (HSTPIPIFR) Received STALLed Interrupt Set Position */
-#define HSTPIPIFR_BLK_RXSTALLDIS (_U_(0x1) << HSTPIPIFR_BLK_RXSTALLDIS_Pos) /**< (HSTPIPIFR) Received STALLed Interrupt Set Mask */
-#define HSTPIPIFR_BLK_Msk _U_(0x44) /**< (HSTPIPIFR_BLK) Register Mask */
-
-/* INTRPT mode */
-#define HSTPIPIFR_INTRPT_UNDERFIS_Pos 2 /**< (HSTPIPIFR) Underflow Interrupt Set Position */
-#define HSTPIPIFR_INTRPT_UNDERFIS (_U_(0x1) << HSTPIPIFR_INTRPT_UNDERFIS_Pos) /**< (HSTPIPIFR) Underflow Interrupt Set Mask */
-#define HSTPIPIFR_INTRPT_RXSTALLDIS_Pos 6 /**< (HSTPIPIFR) Received STALLed Interrupt Set Position */
-#define HSTPIPIFR_INTRPT_RXSTALLDIS (_U_(0x1) << HSTPIPIFR_INTRPT_RXSTALLDIS_Pos) /**< (HSTPIPIFR) Received STALLed Interrupt Set Mask */
-#define HSTPIPIFR_INTRPT_Msk _U_(0x44) /**< (HSTPIPIFR_INTRPT) Register Mask */
-
-
-/* -------- HSTPIPIMR : (USBHS Offset: 0x5c0) (R/ 32) Host Pipe Mask Register -------- */
-
-#define HSTPIPIMR_OFFSET (0x5C0) /**< (HSTPIPIMR) Host Pipe Mask Register Offset */
-
-#define HSTPIPIMR_RXINE_Pos 0 /**< (HSTPIPIMR) Received IN Data Interrupt Enable Position */
-#define HSTPIPIMR_RXINE (_U_(0x1) << HSTPIPIMR_RXINE_Pos) /**< (HSTPIPIMR) Received IN Data Interrupt Enable Mask */
-#define HSTPIPIMR_TXOUTE_Pos 1 /**< (HSTPIPIMR) Transmitted OUT Data Interrupt Enable Position */
-#define HSTPIPIMR_TXOUTE (_U_(0x1) << HSTPIPIMR_TXOUTE_Pos) /**< (HSTPIPIMR) Transmitted OUT Data Interrupt Enable Mask */
-#define HSTPIPIMR_PERRE_Pos 3 /**< (HSTPIPIMR) Pipe Error Interrupt Enable Position */
-#define HSTPIPIMR_PERRE (_U_(0x1) << HSTPIPIMR_PERRE_Pos) /**< (HSTPIPIMR) Pipe Error Interrupt Enable Mask */
-#define HSTPIPIMR_NAKEDE_Pos 4 /**< (HSTPIPIMR) NAKed Interrupt Enable Position */
-#define HSTPIPIMR_NAKEDE (_U_(0x1) << HSTPIPIMR_NAKEDE_Pos) /**< (HSTPIPIMR) NAKed Interrupt Enable Mask */
-#define HSTPIPIMR_OVERFIE_Pos 5 /**< (HSTPIPIMR) Overflow Interrupt Enable Position */
-#define HSTPIPIMR_OVERFIE (_U_(0x1) << HSTPIPIMR_OVERFIE_Pos) /**< (HSTPIPIMR) Overflow Interrupt Enable Mask */
-#define HSTPIPIMR_SHORTPACKETIE_Pos 7 /**< (HSTPIPIMR) Short Packet Interrupt Enable Position */
-#define HSTPIPIMR_SHORTPACKETIE (_U_(0x1) << HSTPIPIMR_SHORTPACKETIE_Pos) /**< (HSTPIPIMR) Short Packet Interrupt Enable Mask */
-#define HSTPIPIMR_NBUSYBKE_Pos 12 /**< (HSTPIPIMR) Number of Busy Banks Interrupt Enable Position */
-#define HSTPIPIMR_NBUSYBKE (_U_(0x1) << HSTPIPIMR_NBUSYBKE_Pos) /**< (HSTPIPIMR) Number of Busy Banks Interrupt Enable Mask */
-#define HSTPIPIMR_FIFOCON_Pos 14 /**< (HSTPIPIMR) FIFO Control Position */
-#define HSTPIPIMR_FIFOCON (_U_(0x1) << HSTPIPIMR_FIFOCON_Pos) /**< (HSTPIPIMR) FIFO Control Mask */
-#define HSTPIPIMR_PDISHDMA_Pos 16 /**< (HSTPIPIMR) Pipe Interrupts Disable HDMA Request Enable Position */
-#define HSTPIPIMR_PDISHDMA (_U_(0x1) << HSTPIPIMR_PDISHDMA_Pos) /**< (HSTPIPIMR) Pipe Interrupts Disable HDMA Request Enable Mask */
-#define HSTPIPIMR_PFREEZE_Pos 17 /**< (HSTPIPIMR) Pipe Freeze Position */
-#define HSTPIPIMR_PFREEZE (_U_(0x1) << HSTPIPIMR_PFREEZE_Pos) /**< (HSTPIPIMR) Pipe Freeze Mask */
-#define HSTPIPIMR_RSTDT_Pos 18 /**< (HSTPIPIMR) Reset Data Toggle Position */
-#define HSTPIPIMR_RSTDT (_U_(0x1) << HSTPIPIMR_RSTDT_Pos) /**< (HSTPIPIMR) Reset Data Toggle Mask */
-#define HSTPIPIMR_Msk _U_(0x750BB) /**< (HSTPIPIMR) Register Mask */
-
-/* CTRL mode */
-#define HSTPIPIMR_CTRL_TXSTPE_Pos 2 /**< (HSTPIPIMR) Transmitted SETUP Interrupt Enable Position */
-#define HSTPIPIMR_CTRL_TXSTPE (_U_(0x1) << HSTPIPIMR_CTRL_TXSTPE_Pos) /**< (HSTPIPIMR) Transmitted SETUP Interrupt Enable Mask */
-#define HSTPIPIMR_CTRL_RXSTALLDE_Pos 6 /**< (HSTPIPIMR) Received STALLed Interrupt Enable Position */
-#define HSTPIPIMR_CTRL_RXSTALLDE (_U_(0x1) << HSTPIPIMR_CTRL_RXSTALLDE_Pos) /**< (HSTPIPIMR) Received STALLed Interrupt Enable Mask */
-#define HSTPIPIMR_CTRL_Msk _U_(0x44) /**< (HSTPIPIMR_CTRL) Register Mask */
-
-/* ISO mode */
-#define HSTPIPIMR_ISO_UNDERFIE_Pos 2 /**< (HSTPIPIMR) Underflow Interrupt Enable Position */
-#define HSTPIPIMR_ISO_UNDERFIE (_U_(0x1) << HSTPIPIMR_ISO_UNDERFIE_Pos) /**< (HSTPIPIMR) Underflow Interrupt Enable Mask */
-#define HSTPIPIMR_ISO_CRCERRE_Pos 6 /**< (HSTPIPIMR) CRC Error Interrupt Enable Position */
-#define HSTPIPIMR_ISO_CRCERRE (_U_(0x1) << HSTPIPIMR_ISO_CRCERRE_Pos) /**< (HSTPIPIMR) CRC Error Interrupt Enable Mask */
-#define HSTPIPIMR_ISO_Msk _U_(0x44) /**< (HSTPIPIMR_ISO) Register Mask */
-
-/* BLK mode */
-#define HSTPIPIMR_BLK_TXSTPE_Pos 2 /**< (HSTPIPIMR) Transmitted SETUP Interrupt Enable Position */
-#define HSTPIPIMR_BLK_TXSTPE (_U_(0x1) << HSTPIPIMR_BLK_TXSTPE_Pos) /**< (HSTPIPIMR) Transmitted SETUP Interrupt Enable Mask */
-#define HSTPIPIMR_BLK_RXSTALLDE_Pos 6 /**< (HSTPIPIMR) Received STALLed Interrupt Enable Position */
-#define HSTPIPIMR_BLK_RXSTALLDE (_U_(0x1) << HSTPIPIMR_BLK_RXSTALLDE_Pos) /**< (HSTPIPIMR) Received STALLed Interrupt Enable Mask */
-#define HSTPIPIMR_BLK_Msk _U_(0x44) /**< (HSTPIPIMR_BLK) Register Mask */
-
-/* INTRPT mode */
-#define HSTPIPIMR_INTRPT_UNDERFIE_Pos 2 /**< (HSTPIPIMR) Underflow Interrupt Enable Position */
-#define HSTPIPIMR_INTRPT_UNDERFIE (_U_(0x1) << HSTPIPIMR_INTRPT_UNDERFIE_Pos) /**< (HSTPIPIMR) Underflow Interrupt Enable Mask */
-#define HSTPIPIMR_INTRPT_RXSTALLDE_Pos 6 /**< (HSTPIPIMR) Received STALLed Interrupt Enable Position */
-#define HSTPIPIMR_INTRPT_RXSTALLDE (_U_(0x1) << HSTPIPIMR_INTRPT_RXSTALLDE_Pos) /**< (HSTPIPIMR) Received STALLed Interrupt Enable Mask */
-#define HSTPIPIMR_INTRPT_Msk _U_(0x44) /**< (HSTPIPIMR_INTRPT) Register Mask */
-
-
-/* -------- HSTPIPIER : (USBHS Offset: 0x5f0) (/W 32) Host Pipe Enable Register -------- */
-
-#define HSTPIPIER_OFFSET (0x5F0) /**< (HSTPIPIER) Host Pipe Enable Register Offset */
-
-#define HSTPIPIER_RXINES_Pos 0 /**< (HSTPIPIER) Received IN Data Interrupt Enable Position */
-#define HSTPIPIER_RXINES (_U_(0x1) << HSTPIPIER_RXINES_Pos) /**< (HSTPIPIER) Received IN Data Interrupt Enable Mask */
-#define HSTPIPIER_TXOUTES_Pos 1 /**< (HSTPIPIER) Transmitted OUT Data Interrupt Enable Position */
-#define HSTPIPIER_TXOUTES (_U_(0x1) << HSTPIPIER_TXOUTES_Pos) /**< (HSTPIPIER) Transmitted OUT Data Interrupt Enable Mask */
-#define HSTPIPIER_PERRES_Pos 3 /**< (HSTPIPIER) Pipe Error Interrupt Enable Position */
-#define HSTPIPIER_PERRES (_U_(0x1) << HSTPIPIER_PERRES_Pos) /**< (HSTPIPIER) Pipe Error Interrupt Enable Mask */
-#define HSTPIPIER_NAKEDES_Pos 4 /**< (HSTPIPIER) NAKed Interrupt Enable Position */
-#define HSTPIPIER_NAKEDES (_U_(0x1) << HSTPIPIER_NAKEDES_Pos) /**< (HSTPIPIER) NAKed Interrupt Enable Mask */
-#define HSTPIPIER_OVERFIES_Pos 5 /**< (HSTPIPIER) Overflow Interrupt Enable Position */
-#define HSTPIPIER_OVERFIES (_U_(0x1) << HSTPIPIER_OVERFIES_Pos) /**< (HSTPIPIER) Overflow Interrupt Enable Mask */
-#define HSTPIPIER_SHORTPACKETIES_Pos 7 /**< (HSTPIPIER) Short Packet Interrupt Enable Position */
-#define HSTPIPIER_SHORTPACKETIES (_U_(0x1) << HSTPIPIER_SHORTPACKETIES_Pos) /**< (HSTPIPIER) Short Packet Interrupt Enable Mask */
-#define HSTPIPIER_NBUSYBKES_Pos 12 /**< (HSTPIPIER) Number of Busy Banks Enable Position */
-#define HSTPIPIER_NBUSYBKES (_U_(0x1) << HSTPIPIER_NBUSYBKES_Pos) /**< (HSTPIPIER) Number of Busy Banks Enable Mask */
-#define HSTPIPIER_PDISHDMAS_Pos 16 /**< (HSTPIPIER) Pipe Interrupts Disable HDMA Request Enable Position */
-#define HSTPIPIER_PDISHDMAS (_U_(0x1) << HSTPIPIER_PDISHDMAS_Pos) /**< (HSTPIPIER) Pipe Interrupts Disable HDMA Request Enable Mask */
-#define HSTPIPIER_PFREEZES_Pos 17 /**< (HSTPIPIER) Pipe Freeze Enable Position */
-#define HSTPIPIER_PFREEZES (_U_(0x1) << HSTPIPIER_PFREEZES_Pos) /**< (HSTPIPIER) Pipe Freeze Enable Mask */
-#define HSTPIPIER_RSTDTS_Pos 18 /**< (HSTPIPIER) Reset Data Toggle Enable Position */
-#define HSTPIPIER_RSTDTS (_U_(0x1) << HSTPIPIER_RSTDTS_Pos) /**< (HSTPIPIER) Reset Data Toggle Enable Mask */
-#define HSTPIPIER_Msk _U_(0x710BB) /**< (HSTPIPIER) Register Mask */
-
-/* CTRL mode */
-#define HSTPIPIER_CTRL_TXSTPES_Pos 2 /**< (HSTPIPIER) Transmitted SETUP Interrupt Enable Position */
-#define HSTPIPIER_CTRL_TXSTPES (_U_(0x1) << HSTPIPIER_CTRL_TXSTPES_Pos) /**< (HSTPIPIER) Transmitted SETUP Interrupt Enable Mask */
-#define HSTPIPIER_CTRL_RXSTALLDES_Pos 6 /**< (HSTPIPIER) Received STALLed Interrupt Enable Position */
-#define HSTPIPIER_CTRL_RXSTALLDES (_U_(0x1) << HSTPIPIER_CTRL_RXSTALLDES_Pos) /**< (HSTPIPIER) Received STALLed Interrupt Enable Mask */
-#define HSTPIPIER_CTRL_Msk _U_(0x44) /**< (HSTPIPIER_CTRL) Register Mask */
-
-/* ISO mode */
-#define HSTPIPIER_ISO_UNDERFIES_Pos 2 /**< (HSTPIPIER) Underflow Interrupt Enable Position */
-#define HSTPIPIER_ISO_UNDERFIES (_U_(0x1) << HSTPIPIER_ISO_UNDERFIES_Pos) /**< (HSTPIPIER) Underflow Interrupt Enable Mask */
-#define HSTPIPIER_ISO_CRCERRES_Pos 6 /**< (HSTPIPIER) CRC Error Interrupt Enable Position */
-#define HSTPIPIER_ISO_CRCERRES (_U_(0x1) << HSTPIPIER_ISO_CRCERRES_Pos) /**< (HSTPIPIER) CRC Error Interrupt Enable Mask */
-#define HSTPIPIER_ISO_Msk _U_(0x44) /**< (HSTPIPIER_ISO) Register Mask */
-
-/* BLK mode */
-#define HSTPIPIER_BLK_TXSTPES_Pos 2 /**< (HSTPIPIER) Transmitted SETUP Interrupt Enable Position */
-#define HSTPIPIER_BLK_TXSTPES (_U_(0x1) << HSTPIPIER_BLK_TXSTPES_Pos) /**< (HSTPIPIER) Transmitted SETUP Interrupt Enable Mask */
-#define HSTPIPIER_BLK_RXSTALLDES_Pos 6 /**< (HSTPIPIER) Received STALLed Interrupt Enable Position */
-#define HSTPIPIER_BLK_RXSTALLDES (_U_(0x1) << HSTPIPIER_BLK_RXSTALLDES_Pos) /**< (HSTPIPIER) Received STALLed Interrupt Enable Mask */
-#define HSTPIPIER_BLK_Msk _U_(0x44) /**< (HSTPIPIER_BLK) Register Mask */
-
-/* INTRPT mode */
-#define HSTPIPIER_INTRPT_UNDERFIES_Pos 2 /**< (HSTPIPIER) Underflow Interrupt Enable Position */
-#define HSTPIPIER_INTRPT_UNDERFIES (_U_(0x1) << HSTPIPIER_INTRPT_UNDERFIES_Pos) /**< (HSTPIPIER) Underflow Interrupt Enable Mask */
-#define HSTPIPIER_INTRPT_RXSTALLDES_Pos 6 /**< (HSTPIPIER) Received STALLed Interrupt Enable Position */
-#define HSTPIPIER_INTRPT_RXSTALLDES (_U_(0x1) << HSTPIPIER_INTRPT_RXSTALLDES_Pos) /**< (HSTPIPIER) Received STALLed Interrupt Enable Mask */
-#define HSTPIPIER_INTRPT_Msk _U_(0x44) /**< (HSTPIPIER_INTRPT) Register Mask */
-
-
-/* -------- HSTPIPIDR : (USBHS Offset: 0x620) (/W 32) Host Pipe Disable Register -------- */
-
-#define HSTPIPIDR_OFFSET (0x620) /**< (HSTPIPIDR) Host Pipe Disable Register Offset */
-
-#define HSTPIPIDR_RXINEC_Pos 0 /**< (HSTPIPIDR) Received IN Data Interrupt Disable Position */
-#define HSTPIPIDR_RXINEC (_U_(0x1) << HSTPIPIDR_RXINEC_Pos) /**< (HSTPIPIDR) Received IN Data Interrupt Disable Mask */
-#define HSTPIPIDR_TXOUTEC_Pos 1 /**< (HSTPIPIDR) Transmitted OUT Data Interrupt Disable Position */
-#define HSTPIPIDR_TXOUTEC (_U_(0x1) << HSTPIPIDR_TXOUTEC_Pos) /**< (HSTPIPIDR) Transmitted OUT Data Interrupt Disable Mask */
-#define HSTPIPIDR_PERREC_Pos 3 /**< (HSTPIPIDR) Pipe Error Interrupt Disable Position */
-#define HSTPIPIDR_PERREC (_U_(0x1) << HSTPIPIDR_PERREC_Pos) /**< (HSTPIPIDR) Pipe Error Interrupt Disable Mask */
-#define HSTPIPIDR_NAKEDEC_Pos 4 /**< (HSTPIPIDR) NAKed Interrupt Disable Position */
-#define HSTPIPIDR_NAKEDEC (_U_(0x1) << HSTPIPIDR_NAKEDEC_Pos) /**< (HSTPIPIDR) NAKed Interrupt Disable Mask */
-#define HSTPIPIDR_OVERFIEC_Pos 5 /**< (HSTPIPIDR) Overflow Interrupt Disable Position */
-#define HSTPIPIDR_OVERFIEC (_U_(0x1) << HSTPIPIDR_OVERFIEC_Pos) /**< (HSTPIPIDR) Overflow Interrupt Disable Mask */
-#define HSTPIPIDR_SHORTPACKETIEC_Pos 7 /**< (HSTPIPIDR) Short Packet Interrupt Disable Position */
-#define HSTPIPIDR_SHORTPACKETIEC (_U_(0x1) << HSTPIPIDR_SHORTPACKETIEC_Pos) /**< (HSTPIPIDR) Short Packet Interrupt Disable Mask */
-#define HSTPIPIDR_NBUSYBKEC_Pos 12 /**< (HSTPIPIDR) Number of Busy Banks Disable Position */
-#define HSTPIPIDR_NBUSYBKEC (_U_(0x1) << HSTPIPIDR_NBUSYBKEC_Pos) /**< (HSTPIPIDR) Number of Busy Banks Disable Mask */
-#define HSTPIPIDR_FIFOCONC_Pos 14 /**< (HSTPIPIDR) FIFO Control Disable Position */
-#define HSTPIPIDR_FIFOCONC (_U_(0x1) << HSTPIPIDR_FIFOCONC_Pos) /**< (HSTPIPIDR) FIFO Control Disable Mask */
-#define HSTPIPIDR_PDISHDMAC_Pos 16 /**< (HSTPIPIDR) Pipe Interrupts Disable HDMA Request Disable Position */
-#define HSTPIPIDR_PDISHDMAC (_U_(0x1) << HSTPIPIDR_PDISHDMAC_Pos) /**< (HSTPIPIDR) Pipe Interrupts Disable HDMA Request Disable Mask */
-#define HSTPIPIDR_PFREEZEC_Pos 17 /**< (HSTPIPIDR) Pipe Freeze Disable Position */
-#define HSTPIPIDR_PFREEZEC (_U_(0x1) << HSTPIPIDR_PFREEZEC_Pos) /**< (HSTPIPIDR) Pipe Freeze Disable Mask */
-#define HSTPIPIDR_Msk _U_(0x350BB) /**< (HSTPIPIDR) Register Mask */
-
-/* CTRL mode */
-#define HSTPIPIDR_CTRL_TXSTPEC_Pos 2 /**< (HSTPIPIDR) Transmitted SETUP Interrupt Disable Position */
-#define HSTPIPIDR_CTRL_TXSTPEC (_U_(0x1) << HSTPIPIDR_CTRL_TXSTPEC_Pos) /**< (HSTPIPIDR) Transmitted SETUP Interrupt Disable Mask */
-#define HSTPIPIDR_CTRL_RXSTALLDEC_Pos 6 /**< (HSTPIPIDR) Received STALLed Interrupt Disable Position */
-#define HSTPIPIDR_CTRL_RXSTALLDEC (_U_(0x1) << HSTPIPIDR_CTRL_RXSTALLDEC_Pos) /**< (HSTPIPIDR) Received STALLed Interrupt Disable Mask */
-#define HSTPIPIDR_CTRL_Msk _U_(0x44) /**< (HSTPIPIDR_CTRL) Register Mask */
-
-/* ISO mode */
-#define HSTPIPIDR_ISO_UNDERFIEC_Pos 2 /**< (HSTPIPIDR) Underflow Interrupt Disable Position */
-#define HSTPIPIDR_ISO_UNDERFIEC (_U_(0x1) << HSTPIPIDR_ISO_UNDERFIEC_Pos) /**< (HSTPIPIDR) Underflow Interrupt Disable Mask */
-#define HSTPIPIDR_ISO_CRCERREC_Pos 6 /**< (HSTPIPIDR) CRC Error Interrupt Disable Position */
-#define HSTPIPIDR_ISO_CRCERREC (_U_(0x1) << HSTPIPIDR_ISO_CRCERREC_Pos) /**< (HSTPIPIDR) CRC Error Interrupt Disable Mask */
-#define HSTPIPIDR_ISO_Msk _U_(0x44) /**< (HSTPIPIDR_ISO) Register Mask */
-
-/* BLK mode */
-#define HSTPIPIDR_BLK_TXSTPEC_Pos 2 /**< (HSTPIPIDR) Transmitted SETUP Interrupt Disable Position */
-#define HSTPIPIDR_BLK_TXSTPEC (_U_(0x1) << HSTPIPIDR_BLK_TXSTPEC_Pos) /**< (HSTPIPIDR) Transmitted SETUP Interrupt Disable Mask */
-#define HSTPIPIDR_BLK_RXSTALLDEC_Pos 6 /**< (HSTPIPIDR) Received STALLed Interrupt Disable Position */
-#define HSTPIPIDR_BLK_RXSTALLDEC (_U_(0x1) << HSTPIPIDR_BLK_RXSTALLDEC_Pos) /**< (HSTPIPIDR) Received STALLed Interrupt Disable Mask */
-#define HSTPIPIDR_BLK_Msk _U_(0x44) /**< (HSTPIPIDR_BLK) Register Mask */
-
-/* INTRPT mode */
-#define HSTPIPIDR_INTRPT_UNDERFIEC_Pos 2 /**< (HSTPIPIDR) Underflow Interrupt Disable Position */
-#define HSTPIPIDR_INTRPT_UNDERFIEC (_U_(0x1) << HSTPIPIDR_INTRPT_UNDERFIEC_Pos) /**< (HSTPIPIDR) Underflow Interrupt Disable Mask */
-#define HSTPIPIDR_INTRPT_RXSTALLDEC_Pos 6 /**< (HSTPIPIDR) Received STALLed Interrupt Disable Position */
-#define HSTPIPIDR_INTRPT_RXSTALLDEC (_U_(0x1) << HSTPIPIDR_INTRPT_RXSTALLDEC_Pos) /**< (HSTPIPIDR) Received STALLed Interrupt Disable Mask */
-#define HSTPIPIDR_INTRPT_Msk _U_(0x44) /**< (HSTPIPIDR_INTRPT) Register Mask */
-
-
-/* -------- HSTPIPINRQ : (USBHS Offset: 0x650) (R/W 32) Host Pipe IN Request Register -------- */
-
-#define HSTPIPINRQ_OFFSET (0x650) /**< (HSTPIPINRQ) Host Pipe IN Request Register Offset */
-
-#define HSTPIPINRQ_INRQ_Pos 0 /**< (HSTPIPINRQ) IN Request Number before Freeze Position */
-#define HSTPIPINRQ_INRQ (_U_(0xFF) << HSTPIPINRQ_INRQ_Pos) /**< (HSTPIPINRQ) IN Request Number before Freeze Mask */
-#define HSTPIPINRQ_INMODE_Pos 8 /**< (HSTPIPINRQ) IN Request Mode Position */
-#define HSTPIPINRQ_INMODE (_U_(0x1) << HSTPIPINRQ_INMODE_Pos) /**< (HSTPIPINRQ) IN Request Mode Mask */
-#define HSTPIPINRQ_Msk _U_(0x1FF) /**< (HSTPIPINRQ) Register Mask */
-
-
-/* -------- HSTPIPERR : (USBHS Offset: 0x680) (R/W 32) Host Pipe Error Register -------- */
-
-#define HSTPIPERR_OFFSET (0x680) /**< (HSTPIPERR) Host Pipe Error Register Offset */
-
-#define HSTPIPERR_DATATGL_Pos 0 /**< (HSTPIPERR) Data Toggle Error Position */
-#define HSTPIPERR_DATATGL (_U_(0x1) << HSTPIPERR_DATATGL_Pos) /**< (HSTPIPERR) Data Toggle Error Mask */
-#define HSTPIPERR_DATAPID_Pos 1 /**< (HSTPIPERR) Data PID Error Position */
-#define HSTPIPERR_DATAPID (_U_(0x1) << HSTPIPERR_DATAPID_Pos) /**< (HSTPIPERR) Data PID Error Mask */
-#define HSTPIPERR_PID_Pos 2 /**< (HSTPIPERR) Data PID Error Position */
-#define HSTPIPERR_PID (_U_(0x1) << HSTPIPERR_PID_Pos) /**< (HSTPIPERR) Data PID Error Mask */
-#define HSTPIPERR_TIMEOUT_Pos 3 /**< (HSTPIPERR) Time-Out Error Position */
-#define HSTPIPERR_TIMEOUT (_U_(0x1) << HSTPIPERR_TIMEOUT_Pos) /**< (HSTPIPERR) Time-Out Error Mask */
-#define HSTPIPERR_CRC16_Pos 4 /**< (HSTPIPERR) CRC16 Error Position */
-#define HSTPIPERR_CRC16 (_U_(0x1) << HSTPIPERR_CRC16_Pos) /**< (HSTPIPERR) CRC16 Error Mask */
-#define HSTPIPERR_COUNTER_Pos 5 /**< (HSTPIPERR) Error Counter Position */
-#define HSTPIPERR_COUNTER (_U_(0x3) << HSTPIPERR_COUNTER_Pos) /**< (HSTPIPERR) Error Counter Mask */
-#define HSTPIPERR_Msk _U_(0x7F) /**< (HSTPIPERR) Register Mask */
-
-#define HSTPIPERR_CRC_Pos 4 /**< (HSTPIPERR Position) CRCx6 Error */
-#define HSTPIPERR_CRC (_U_(0x1) << HSTPIPERR_CRC_Pos) /**< (HSTPIPERR Mask) CRC */
-
-/* -------- CTRL : (USBHS Offset: 0x800) (R/W 32) General Control Register -------- */
-
-#define CTRL_OFFSET (0x800) /**< (CTRL) General Control Register Offset */
-
-#define CTRL_RDERRE_Pos 4 /**< (CTRL) Remote Device Connection Error Interrupt Enable Position */
-#define CTRL_RDERRE (_U_(0x1) << CTRL_RDERRE_Pos) /**< (CTRL) Remote Device Connection Error Interrupt Enable Mask */
-#define CTRL_VBUSHWC_Pos 8 /**< (CTRL) VBUS Hardware Control Position */
-#define CTRL_VBUSHWC (_U_(0x1) << CTRL_VBUSHWC_Pos) /**< (CTRL) VBUS Hardware Control Mask */
-#define CTRL_FRZCLK_Pos 14 /**< (CTRL) Freeze USB Clock Position */
-#define CTRL_FRZCLK (_U_(0x1) << CTRL_FRZCLK_Pos) /**< (CTRL) Freeze USB Clock Mask */
-#define CTRL_USBE_Pos 15 /**< (CTRL) USBHS Enable Position */
-#define CTRL_USBE (_U_(0x1) << CTRL_USBE_Pos) /**< (CTRL) USBHS Enable Mask */
-#define CTRL_UID_Pos 24 /**< (CTRL) UID Pin Enable Position */
-#define CTRL_UID (_U_(0x1) << CTRL_UID_Pos) /**< (CTRL) UID Pin Enable Mask */
-#define CTRL_UIMOD_Pos 25 /**< (CTRL) USBHS Mode Position */
-#define CTRL_UIMOD (_U_(0x1) << CTRL_UIMOD_Pos) /**< (CTRL) USBHS Mode Mask */
-#define CTRL_UIMOD_HOST_Val _U_(0x0) /**< (CTRL) The module is in USB Host mode. */
-#define CTRL_UIMOD_DEVICE_Val _U_(0x1) /**< (CTRL) The module is in USB Device mode. */
-#define CTRL_UIMOD_HOST (CTRL_UIMOD_HOST_Val << CTRL_UIMOD_Pos) /**< (CTRL) The module is in USB Host mode. Position */
-#define CTRL_UIMOD_DEVICE (CTRL_UIMOD_DEVICE_Val << CTRL_UIMOD_Pos) /**< (CTRL) The module is in USB Device mode. Position */
-#define CTRL_Msk _U_(0x300C110) /**< (CTRL) Register Mask */
-
-
-/* -------- SR : (USBHS Offset: 0x804) (R/ 32) General Status Register -------- */
-
-#define SR_OFFSET (0x804) /**< (SR) General Status Register Offset */
-
-#define SR_RDERRI_Pos 4 /**< (SR) Remote Device Connection Error Interrupt (Host mode only) Position */
-#define SR_RDERRI (_U_(0x1) << SR_RDERRI_Pos) /**< (SR) Remote Device Connection Error Interrupt (Host mode only) Mask */
-#define SR_SPEED_Pos 12 /**< (SR) Speed Status (Device mode only) Position */
-#define SR_SPEED (_U_(0x3) << SR_SPEED_Pos) /**< (SR) Speed Status (Device mode only) Mask */
-#define SR_SPEED_FULL_SPEED_Val _U_(0x0) /**< (SR) Full-Speed mode */
-#define SR_SPEED_HIGH_SPEED_Val _U_(0x1) /**< (SR) High-Speed mode */
-#define SR_SPEED_LOW_SPEED_Val _U_(0x2) /**< (SR) Low-Speed mode */
-#define SR_SPEED_FULL_SPEED (SR_SPEED_FULL_SPEED_Val << SR_SPEED_Pos) /**< (SR) Full-Speed mode Position */
-#define SR_SPEED_HIGH_SPEED (SR_SPEED_HIGH_SPEED_Val << SR_SPEED_Pos) /**< (SR) High-Speed mode Position */
-#define SR_SPEED_LOW_SPEED (SR_SPEED_LOW_SPEED_Val << SR_SPEED_Pos) /**< (SR) Low-Speed mode Position */
-#define SR_CLKUSABLE_Pos 14 /**< (SR) UTMI Clock Usable Position */
-#define SR_CLKUSABLE (_U_(0x1) << SR_CLKUSABLE_Pos) /**< (SR) UTMI Clock Usable Mask */
-#define SR_Msk _U_(0x7010) /**< (SR) Register Mask */
-
-
-/* -------- SCR : (USBHS Offset: 0x808) (/W 32) General Status Clear Register -------- */
-
-#define SCR_OFFSET (0x808) /**< (SCR) General Status Clear Register Offset */
-
-#define SCR_RDERRIC_Pos 4 /**< (SCR) Remote Device Connection Error Interrupt Clear Position */
-#define SCR_RDERRIC (_U_(0x1) << SCR_RDERRIC_Pos) /**< (SCR) Remote Device Connection Error Interrupt Clear Mask */
-#define SCR_Msk _U_(0x10) /**< (SCR) Register Mask */
-
-
-/* -------- SFR : (USBHS Offset: 0x80c) (/W 32) General Status Set Register -------- */
-
-#define SFR_OFFSET (0x80C) /**< (SFR) General Status Set Register Offset */
-
-#define SFR_RDERRIS_Pos 4 /**< (SFR) Remote Device Connection Error Interrupt Set Position */
-#define SFR_RDERRIS (_U_(0x1) << SFR_RDERRIS_Pos) /**< (SFR) Remote Device Connection Error Interrupt Set Mask */
-#define SFR_VBUSRQS_Pos 9 /**< (SFR) VBUS Request Set Position */
-#define SFR_VBUSRQS (_U_(0x1) << SFR_VBUSRQS_Pos) /**< (SFR) VBUS Request Set Mask */
-#define SFR_Msk _U_(0x210) /**< (SFR) Register Mask */
-
-
-/** \brief DEVDMA hardware registers */
-typedef struct
-{
- __IO uint32_t DEVDMANXTDSC; /**< (DEVDMA Offset: 0x00) Device DMA Channel Next Descriptor Address Register */
- __IO uint32_t DEVDMAADDRESS; /**< (DEVDMA Offset: 0x04) Device DMA Channel Address Register */
- __IO uint32_t DEVDMACONTROL; /**< (DEVDMA Offset: 0x08) Device DMA Channel Control Register */
- __IO uint32_t DEVDMASTATUS; /**< (DEVDMA Offset: 0x0C) Device DMA Channel Status Register */
-} devdma_t;
-
-/** \brief HSTDMA hardware registers */
-typedef struct
-{
- __IO uint32_t HSTDMANXTDSC; /**< (HSTDMA Offset: 0x00) Host DMA Channel Next Descriptor Address Register */
- __IO uint32_t HSTDMAADDRESS; /**< (HSTDMA Offset: 0x04) Host DMA Channel Address Register */
- __IO uint32_t HSTDMACONTROL; /**< (HSTDMA Offset: 0x08) Host DMA Channel Control Register */
- __IO uint32_t HSTDMASTATUS; /**< (HSTDMA Offset: 0x0C) Host DMA Channel Status Register */
-} hstdma_t;
-
-/** \brief USBHS hardware registers */
-typedef struct
-{
- __IO uint32_t DEVCTRL; /**< (USBHS Offset: 0x00) Device General Control Register */
- __I uint32_t DEVISR; /**< (USBHS Offset: 0x04) Device Global Interrupt Status Register */
- __O uint32_t DEVICR; /**< (USBHS Offset: 0x08) Device Global Interrupt Clear Register */
- __O uint32_t DEVIFR; /**< (USBHS Offset: 0x0C) Device Global Interrupt Set Register */
- __I uint32_t DEVIMR; /**< (USBHS Offset: 0x10) Device Global Interrupt Mask Register */
- __O uint32_t DEVIDR; /**< (USBHS Offset: 0x14) Device Global Interrupt Disable Register */
- __O uint32_t DEVIER; /**< (USBHS Offset: 0x18) Device Global Interrupt Enable Register */
- __IO uint32_t DEVEPT; /**< (USBHS Offset: 0x1C) Device Endpoint Register */
- __I uint32_t DEVFNUM; /**< (USBHS Offset: 0x20) Device Frame Number Register */
- __I uint8_t Reserved1[220];
- __IO uint32_t DEVEPTCFG[10]; /**< (USBHS Offset: 0x100) Device Endpoint Configuration Register */
- __I uint8_t Reserved2[8];
- __I uint32_t DEVEPTISR[10]; /**< (USBHS Offset: 0x130) Device Endpoint Interrupt Status Register */
- __I uint8_t Reserved3[8];
- __O uint32_t DEVEPTICR[10]; /**< (USBHS Offset: 0x160) Device Endpoint Interrupt Clear Register */
- __I uint8_t Reserved4[8];
- __O uint32_t DEVEPTIFR[10]; /**< (USBHS Offset: 0x190) Device Endpoint Interrupt Set Register */
- __I uint8_t Reserved5[8];
- __I uint32_t DEVEPTIMR[10]; /**< (USBHS Offset: 0x1C0) Device Endpoint Interrupt Mask Register */
- __I uint8_t Reserved6[8];
- __O uint32_t DEVEPTIER[10]; /**< (USBHS Offset: 0x1F0) Device Endpoint Interrupt Enable Register */
- __I uint8_t Reserved7[8];
- __O uint32_t DEVEPTIDR[10]; /**< (USBHS Offset: 0x220) Device Endpoint Interrupt Disable Register */
- __I uint8_t Reserved8[200];
- devdma_t DEVDMA[7]; /**< Offset: 0x310 Device DMA Channel Next Descriptor Address Register */
- __I uint8_t Reserved9[128];
- __IO uint32_t HSTCTRL; /**< (USBHS Offset: 0x400) Host General Control Register */
- __I uint32_t HSTISR; /**< (USBHS Offset: 0x404) Host Global Interrupt Status Register */
- __O uint32_t HSTICR; /**< (USBHS Offset: 0x408) Host Global Interrupt Clear Register */
- __O uint32_t HSTIFR; /**< (USBHS Offset: 0x40C) Host Global Interrupt Set Register */
- __I uint32_t HSTIMR; /**< (USBHS Offset: 0x410) Host Global Interrupt Mask Register */
- __O uint32_t HSTIDR; /**< (USBHS Offset: 0x414) Host Global Interrupt Disable Register */
- __O uint32_t HSTIER; /**< (USBHS Offset: 0x418) Host Global Interrupt Enable Register */
- __IO uint32_t HSTPIP; /**< (USBHS Offset: 0x41C) Host Pipe Register */
- __IO uint32_t HSTFNUM; /**< (USBHS Offset: 0x420) Host Frame Number Register */
- __IO uint32_t HSTADDR1; /**< (USBHS Offset: 0x424) Host Address 1 Register */
- __IO uint32_t HSTADDR2; /**< (USBHS Offset: 0x428) Host Address 2 Register */
- __IO uint32_t HSTADDR3; /**< (USBHS Offset: 0x42C) Host Address 3 Register */
- __I uint8_t Reserved10[208];
- __IO uint32_t HSTPIPCFG[10]; /**< (USBHS Offset: 0x500) Host Pipe Configuration Register */
- __I uint8_t Reserved11[8];
- __I uint32_t HSTPIPISR[10]; /**< (USBHS Offset: 0x530) Host Pipe Status Register */
- __I uint8_t Reserved12[8];
- __O uint32_t HSTPIPICR[10]; /**< (USBHS Offset: 0x560) Host Pipe Clear Register */
- __I uint8_t Reserved13[8];
- __O uint32_t HSTPIPIFR[10]; /**< (USBHS Offset: 0x590) Host Pipe Set Register */
- __I uint8_t Reserved14[8];
- __I uint32_t HSTPIPIMR[10]; /**< (USBHS Offset: 0x5C0) Host Pipe Mask Register */
- __I uint8_t Reserved15[8];
- __O uint32_t HSTPIPIER[10]; /**< (USBHS Offset: 0x5F0) Host Pipe Enable Register */
- __I uint8_t Reserved16[8];
- __O uint32_t HSTPIPIDR[10]; /**< (USBHS Offset: 0x620) Host Pipe Disable Register */
- __I uint8_t Reserved17[8];
- __IO uint32_t HSTPIPINRQ[10]; /**< (USBHS Offset: 0x650) Host Pipe IN Request Register */
- __I uint8_t Reserved18[8];
- __IO uint32_t HSTPIPERR[10]; /**< (USBHS Offset: 0x680) Host Pipe Error Register */
- __I uint8_t Reserved19[104];
- hstdma_t HSTDMA[7]; /**< Offset: 0x710 Host DMA Channel Next Descriptor Address Register */
- __I uint8_t Reserved20[128];
- __IO uint32_t CTRL; /**< (USBHS Offset: 0x800) General Control Register */
- __I uint32_t SR; /**< (USBHS Offset: 0x804) General Status Register */
- __O uint32_t SCR; /**< (USBHS Offset: 0x808) General Status Clear Register */
- __O uint32_t SFR; /**< (USBHS Offset: 0x80C) General Status Set Register */
-} dcd_registers_t;
-
-#define USB_REG ((dcd_registers_t *)0x40038000U) /**< \brief (USBHS) Base Address */
-
-#define EP_MAX 10
-
-#define FIFO_RAM_ADDR 0xA0100000u
-
-// Errata: The DMA feature is not available for Pipe/Endpoint 7
-#define EP_DMA_SUPPORT(epnum) (epnum >= 1 && epnum <= 6)
-
-#else // TODO : SAM3U
-
-
-#endif
-
-#endif /* _COMMON_USB_REGS_H_ */
diff --git a/tinyusb/src/portable/microchip/samx7x/dcd_samx7x.c b/tinyusb/src/portable/microchip/samx7x/dcd_samx7x.c
deleted file mode 100755
index 0d9e184f..00000000
--- a/tinyusb/src/portable/microchip/samx7x/dcd_samx7x.c
+++ /dev/null
@@ -1,762 +0,0 @@
-/*
-* The MIT License (MIT)
-*
-* Copyright (c) 2018, hathach (tinyusb.org)
-* Copyright (c) 2021, HiFiPhile
-*
-* Permission is hereby granted, free of charge, to any person obtaining a copy
-* of this software and associated documentation files (the "Software"), to deal
-* in the Software without restriction, including without limitation the rights
-* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-* copies of the Software, and to permit persons to whom the Software is
-* furnished to do so, subject to the following conditions:
-*
-* The above copyright notice and this permission notice shall be included in
-* all copies or substantial portions of the Software.
-*
-* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
-* THE SOFTWARE.
-*
-* This file is part of the TinyUSB stack.
-*/
-
-#include "tusb_option.h"
-
-#if TUSB_OPT_DEVICE_ENABLED && CFG_TUSB_MCU == OPT_MCU_SAMX7X
-
-#include "device/dcd.h"
-#include "sam.h"
-#include "common_usb_regs.h"
-//--------------------------------------------------------------------+
-// MACRO TYPEDEF CONSTANT ENUM DECLARATION
-//--------------------------------------------------------------------+
-
-// Since TinyUSB doesn't use SOF for now, and this interrupt too often (1ms interval)
-// We disable SOF for now until needed later on
-#ifndef USE_SOF
-# define USE_SOF 0
-#endif
-
-// Dual bank can imporve performance, but need 2 times bigger packet buffer
-// As SAM7x has only 4KB packet buffer, use with caution !
-// Enable in FS mode as packets are smaller
-#ifndef USE_DUAL_BANK
-# if TUD_OPT_HIGH_SPEED
-# define USE_DUAL_BANK 0
-# else
-# define USE_DUAL_BANK 1
-# endif
-#endif
-
-#define EP_GET_FIFO_PTR(ep, scale) (((TU_XSTRCAT(TU_STRCAT(uint, scale),_t) (*)[0x8000 / ((scale) / 8)])FIFO_RAM_ADDR)[(ep)])
-
-// DMA Channel Transfer Descriptor
-typedef struct {
- volatile uint32_t next_desc;
- volatile uint32_t buff_addr;
- volatile uint32_t chnl_ctrl;
- uint32_t padding;
-} dma_desc_t;
-
-// Transfer control context
-typedef struct {
- uint8_t * buffer;
- uint16_t total_len;
- uint16_t queued_len;
- uint16_t max_packet_size;
- uint8_t interval;
- tu_fifo_t * fifo;
-} xfer_ctl_t;
-
-static tusb_speed_t get_speed(void);
-static void dcd_transmit_packet(xfer_ctl_t * xfer, uint8_t ep_ix);
-
-// DMA descriptors shouldn't be placed in ITCM !
-CFG_TUSB_MEM_SECTION static dma_desc_t dma_desc[6];
-
-static xfer_ctl_t xfer_status[EP_MAX];
-
-static const tusb_desc_endpoint_t ep0_desc =
-{
- .bEndpointAddress = 0x00,
- .wMaxPacketSize = { .size = CFG_TUD_ENDPOINT0_SIZE },
-};
-
-TU_ATTR_ALWAYS_INLINE static inline void CleanInValidateCache(uint32_t *addr, int32_t size)
-{
- if (SCB->CCR & SCB_CCR_DC_Msk)
- {
- SCB_CleanInvalidateDCache_by_Addr(addr, size);
- }
- else
- {
- __DSB();
- __ISB();
- }
-}
-//------------------------------------------------------------------
-// Device API
-//------------------------------------------------------------------
-
-// Initialize controller to device mode
-void dcd_init (uint8_t rhport)
-{
- dcd_connect(rhport);
-}
-
-// Enable device interrupt
-void dcd_int_enable (uint8_t rhport)
-{
- (void) rhport;
- NVIC_EnableIRQ((IRQn_Type) ID_USBHS);
-}
-
-// Disable device interrupt
-void dcd_int_disable (uint8_t rhport)
-{
- (void) rhport;
- NVIC_DisableIRQ((IRQn_Type) ID_USBHS);
-}
-
-// Receive Set Address request, mcu port must also include status IN response
-void dcd_set_address (uint8_t rhport, uint8_t dev_addr)
-{
- (void) dev_addr;
- // DCD can only set address after status for this request is complete
- // do it at dcd_edpt0_status_complete()
-
- // Response with zlp status
- dcd_edpt_xfer(rhport, tu_edpt_addr(0, TUSB_DIR_IN), NULL, 0);
-}
-
-// Wake up host
-void dcd_remote_wakeup (uint8_t rhport)
-{
- (void) rhport;
- USB_REG->DEVCTRL |= DEVCTRL_RMWKUP;
-}
-
-// Connect by enabling internal pull-up resistor on D+/D-
-void dcd_connect(uint8_t rhport)
-{
- (void) rhport;
- dcd_int_disable(rhport);
- // Enable the USB controller in device mode
- USB_REG->CTRL = CTRL_UIMOD | CTRL_USBE;
- while (!(USB_REG->SR & SR_CLKUSABLE));
-#if TUD_OPT_HIGH_SPEED
- USB_REG->DEVCTRL &= ~DEVCTRL_SPDCONF;
-#else
- USB_REG->DEVCTRL |= DEVCTRL_SPDCONF_LOW_POWER;
-#endif
- // Enable the End Of Reset, Suspend & Wakeup interrupts
- USB_REG->DEVIER = (DEVIER_EORSTES | DEVIER_SUSPES | DEVIER_WAKEUPES);
-#if USE_SOF
- USB_REG->DEVIER = DEVIER_SOFES;
-#endif
- // Clear the End Of Reset, SOF & Wakeup interrupts
- USB_REG->DEVICR = (DEVICR_EORSTC | DEVICR_SOFC | DEVICR_WAKEUPC);
- // Manually set the Suspend Interrupt
- USB_REG->DEVIFR |= DEVIFR_SUSPS;
- // Ack the Wakeup Interrupt
- USB_REG->DEVICR = DEVICR_WAKEUPC;
- // Attach the device
- USB_REG->DEVCTRL &= ~DEVCTRL_DETACH;
- // Freeze USB clock
- USB_REG->CTRL |= CTRL_FRZCLK;
-}
-
-// Disconnect by disabling internal pull-up resistor on D+/D-
-void dcd_disconnect(uint8_t rhport)
-{
- (void) rhport;
- dcd_int_disable(rhport);
- // Disable all endpoints
- USB_REG->DEVEPT &= ~(0x3FF << DEVEPT_EPEN0_Pos);
- // Unfreeze USB clock
- USB_REG->CTRL &= ~CTRL_FRZCLK;
- while (!(USB_REG->SR & SR_CLKUSABLE));
- // Clear all the pending interrupts
- USB_REG->DEVICR = DEVICR_Msk;
- // Disable all interrupts
- USB_REG->DEVIDR = DEVIDR_Msk;
- // Detach the device
- USB_REG->DEVCTRL |= DEVCTRL_DETACH;
- // Disable the device address
- USB_REG->DEVCTRL &=~(DEVCTRL_ADDEN | DEVCTRL_UADD);
-}
-
-static tusb_speed_t get_speed(void)
-{
- switch (USB_REG->SR & SR_SPEED) {
- case SR_SPEED_FULL_SPEED:
- default:
- return TUSB_SPEED_FULL;
- case SR_SPEED_HIGH_SPEED:
- return TUSB_SPEED_HIGH;
- case SR_SPEED_LOW_SPEED:
- return TUSB_SPEED_LOW;
- }
-}
-
-static void dcd_ep_handler(uint8_t ep_ix)
-{
- uint32_t int_status = USB_REG->DEVEPTISR[ep_ix];
- int_status &= USB_REG->DEVEPTIMR[ep_ix];
-
- uint16_t count = (USB_REG->DEVEPTISR[ep_ix] &
- DEVEPTISR_BYCT) >> DEVEPTISR_BYCT_Pos;
- xfer_ctl_t *xfer = &xfer_status[ep_ix];
-
- if (ep_ix == 0U)
- {
- static uint8_t ctrl_dir;
-
- if (int_status & DEVEPTISR_CTRL_RXSTPI)
- {
- ctrl_dir = (USB_REG->DEVEPTISR[0] & DEVEPTISR_CTRL_CTRLDIR) >> DEVEPTISR_CTRL_CTRLDIR_Pos;
- // Setup packet should always be 8 bytes. If not, ignore it, and try again.
- if (count == 8)
- {
- uint8_t *ptr = EP_GET_FIFO_PTR(0,8);
- dcd_event_setup_received(0, ptr, true);
- }
- // Ack and disable SETUP interrupt
- USB_REG->DEVEPTICR[0] = DEVEPTICR_CTRL_RXSTPIC;
- USB_REG->DEVEPTIDR[0] = DEVEPTIDR_CTRL_RXSTPEC;
- }
- if (int_status & DEVEPTISR_RXOUTI)
- {
- uint8_t *ptr = EP_GET_FIFO_PTR(0,8);
-
- if (count && xfer->total_len)
- {
- uint16_t remain = xfer->total_len - xfer->queued_len;
- if (count > remain)
- {
- count = remain;
- }
- if (xfer->buffer)
- {
- memcpy(xfer->buffer + xfer->queued_len, ptr, count);
- } else
- {
- tu_fifo_write_n(xfer->fifo, ptr, count);
- }
- xfer->queued_len = (uint16_t)(xfer->queued_len + count);
- }
- // Acknowledge the interrupt
- USB_REG->DEVEPTICR[0] = DEVEPTICR_RXOUTIC;
- if ((count < xfer->max_packet_size) || (xfer->queued_len == xfer->total_len))
- {
- // RX COMPLETE
- dcd_event_xfer_complete(0, 0, xfer->queued_len, XFER_RESULT_SUCCESS, true);
- // Disable the interrupt
- USB_REG->DEVEPTIDR[0] = DEVEPTIDR_RXOUTEC;
- // Re-enable SETUP interrupt
- if (ctrl_dir == 1)
- {
- USB_REG->DEVEPTIER[0] = DEVEPTIER_CTRL_RXSTPES;
- }
- }
- }
- if (int_status & DEVEPTISR_TXINI)
- {
- // Disable the interrupt
- USB_REG->DEVEPTIDR[0] = DEVEPTIDR_TXINEC;
- if ((xfer->total_len != xfer->queued_len))
- {
- // TX not complete
- dcd_transmit_packet(xfer, 0);
- } else
- {
- // TX complete
- dcd_event_xfer_complete(0, 0x80 + 0, xfer->total_len, XFER_RESULT_SUCCESS, true);
- // Re-enable SETUP interrupt
- if (ctrl_dir == 0)
- {
- USB_REG->DEVEPTIER[0] = DEVEPTIER_CTRL_RXSTPES;
- }
- }
- }
- } else
- {
- if (int_status & DEVEPTISR_RXOUTI)
- {
- if (count && xfer->total_len)
- {
- uint16_t remain = xfer->total_len - xfer->queued_len;
- if (count > remain)
- {
- count = remain;
- }
- uint8_t *ptr = EP_GET_FIFO_PTR(ep_ix,8);
- if (xfer->buffer)
- {
- memcpy(xfer->buffer + xfer->queued_len, ptr, count);
- } else {
- tu_fifo_write_n(xfer->fifo, ptr, count);
- }
- xfer->queued_len = (uint16_t)(xfer->queued_len + count);
- }
- // Clear the FIFO control flag to receive more data.
- USB_REG->DEVEPTIDR[ep_ix] = DEVEPTIDR_FIFOCONC;
- // Acknowledge the interrupt
- USB_REG->DEVEPTICR[ep_ix] = DEVEPTICR_RXOUTIC;
- if ((count < xfer->max_packet_size) || (xfer->queued_len == xfer->total_len))
- {
- // RX COMPLETE
- dcd_event_xfer_complete(0, ep_ix, xfer->queued_len, XFER_RESULT_SUCCESS, true);
- // Disable the interrupt
- USB_REG->DEVEPTIDR[ep_ix] = DEVEPTIDR_RXOUTEC;
- // Though the host could still send, we don't know.
- }
- }
- if (int_status & DEVEPTISR_TXINI)
- {
- // Acknowledge the interrupt
- USB_REG->DEVEPTICR[ep_ix] = DEVEPTICR_TXINIC;
- if ((xfer->total_len != xfer->queued_len))
- {
- // TX not complete
- dcd_transmit_packet(xfer, ep_ix);
- } else
- {
- // TX complete
- dcd_event_xfer_complete(0, 0x80 + ep_ix, xfer->total_len, XFER_RESULT_SUCCESS, true);
- // Disable the interrupt
- USB_REG->DEVEPTIDR[ep_ix] = DEVEPTIDR_TXINEC;
- }
- }
- }
-}
-
-static void dcd_dma_handler(uint8_t ep_ix)
-{
- uint32_t status = USB_REG->DEVDMA[ep_ix - 1].DEVDMASTATUS;
- if (status & DEVDMASTATUS_CHANN_ENB)
- {
- return; // Ignore EOT_STA interrupt
- }
- // Disable DMA interrupt
- USB_REG->DEVIDR = DEVIDR_DMA_1 << (ep_ix - 1);
-
- xfer_ctl_t *xfer = &xfer_status[ep_ix];
- uint16_t count = xfer->total_len - ((status & DEVDMASTATUS_BUFF_COUNT) >> DEVDMASTATUS_BUFF_COUNT_Pos);
- if(USB_REG->DEVEPTCFG[ep_ix] & DEVEPTCFG_EPDIR)
- {
- dcd_event_xfer_complete(0, 0x80 + ep_ix, count, XFER_RESULT_SUCCESS, true);
- } else
- {
- dcd_event_xfer_complete(0, ep_ix, count, XFER_RESULT_SUCCESS, true);
- }
-}
-
-void dcd_int_handler(uint8_t rhport)
-{
- (void) rhport;
- uint32_t int_status = USB_REG->DEVISR;
- int_status &= USB_REG->DEVIMR;
- // End of reset interrupt
- if (int_status & DEVISR_EORST)
- {
- // Unfreeze USB clock
- USB_REG->CTRL &= ~CTRL_FRZCLK;
- while(!(USB_REG->SR & SR_CLKUSABLE));
- // Reset all endpoints
- for (int ep_ix = 1; ep_ix < EP_MAX; ep_ix++)
- {
- USB_REG->DEVEPT |= 1 << (DEVEPT_EPRST0_Pos + ep_ix);
- USB_REG->DEVEPT &=~(1 << (DEVEPT_EPRST0_Pos + ep_ix));
- }
- dcd_edpt_open (0, &ep0_desc);
- USB_REG->DEVICR = DEVICR_EORSTC;
- USB_REG->DEVICR = DEVICR_WAKEUPC;
- USB_REG->DEVICR = DEVICR_SUSPC;
- USB_REG->DEVIER = DEVIER_SUSPES;
-
- dcd_event_bus_reset(rhport, get_speed(), true);
- }
- // End of Wakeup interrupt
- if (int_status & DEVISR_WAKEUP)
- {
- USB_REG->CTRL &= ~CTRL_FRZCLK;
- while (!(USB_REG->SR & SR_CLKUSABLE));
- USB_REG->DEVICR = DEVICR_WAKEUPC;
- USB_REG->DEVIDR = DEVIDR_WAKEUPEC;
- USB_REG->DEVIER = DEVIER_SUSPES;
-
- dcd_event_bus_signal(0, DCD_EVENT_RESUME, true);
- }
- // Suspend interrupt
- if (int_status & DEVISR_SUSP)
- {
- // Unfreeze USB clock
- USB_REG->CTRL &= ~CTRL_FRZCLK;
- while (!(USB_REG->SR & SR_CLKUSABLE));
- USB_REG->DEVICR = DEVICR_SUSPC;
- USB_REG->DEVIDR = DEVIDR_SUSPEC;
- USB_REG->DEVIER = DEVIER_WAKEUPES;
- USB_REG->CTRL |= CTRL_FRZCLK;
-
- dcd_event_bus_signal(0, DCD_EVENT_SUSPEND, true);
- }
-#if USE_SOF
- if(int_status & DEVISR_SOF)
- {
- USB_REG->DEVICR = DEVICR_SOFC;
-
- dcd_event_bus_signal(0, DCD_EVENT_SOF, true);
- }
-#endif
- // Endpoints interrupt
- for (int ep_ix = 0; ep_ix < EP_MAX; ep_ix++)
- {
- if (int_status & (DEVISR_PEP_0 << ep_ix))
- {
- dcd_ep_handler(ep_ix);
- }
- }
- // Endpoints DMA interrupt
- for (int ep_ix = 0; ep_ix < EP_MAX; ep_ix++)
- {
- if (EP_DMA_SUPPORT(ep_ix))
- {
- if (int_status & (DEVISR_DMA_1 << (ep_ix - 1)))
- {
- dcd_dma_handler(ep_ix);
- }
- }
- }
-}
-
-//--------------------------------------------------------------------+
-// Endpoint API
-//--------------------------------------------------------------------+
-// Invoked when a control transfer's status stage is complete.
-// May help DCD to prepare for next control transfer, this API is optional.
-void dcd_edpt0_status_complete(uint8_t rhport, tusb_control_request_t const * request)
-{
- (void) rhport;
-
- if (request->bmRequestType_bit.recipient == TUSB_REQ_RCPT_DEVICE &&
- request->bmRequestType_bit.type == TUSB_REQ_TYPE_STANDARD &&
- request->bRequest == TUSB_REQ_SET_ADDRESS )
- {
- uint8_t const dev_addr = (uint8_t) request->wValue;
-
- USB_REG->DEVCTRL |= dev_addr | DEVCTRL_ADDEN;
- }
-}
-
-// Configure endpoint's registers according to descriptor
-bool dcd_edpt_open (uint8_t rhport, tusb_desc_endpoint_t const * ep_desc)
-{
- (void) rhport;
- uint8_t const epnum = tu_edpt_number(ep_desc->bEndpointAddress);
- uint8_t const dir = tu_edpt_dir(ep_desc->bEndpointAddress);
- uint16_t const epMaxPktSize = ep_desc->wMaxPacketSize.size;
- tusb_xfer_type_t const eptype = (tusb_xfer_type_t)ep_desc->bmAttributes.xfer;
- uint8_t fifoSize = 0; // FIFO size
- uint16_t defaultEndpointSize = 8; // Default size of Endpoint
- // Find upper 2 power number of epMaxPktSize
- if (epMaxPktSize)
- {
- while (defaultEndpointSize < epMaxPktSize)
- {
- fifoSize++;
- defaultEndpointSize <<= 1;
- }
- }
- xfer_status[epnum].max_packet_size = epMaxPktSize;
-
- USB_REG->DEVEPT |= 1 << (DEVEPT_EPRST0_Pos + epnum);
- USB_REG->DEVEPT &=~(1 << (DEVEPT_EPRST0_Pos + epnum));
-
- if (epnum == 0)
- {
- // Enable the control endpoint - Endpoint 0
- USB_REG->DEVEPT |= DEVEPT_EPEN0;
- // Configure the Endpoint 0 configuration register
- USB_REG->DEVEPTCFG[0] =
- (
- (fifoSize << DEVEPTCFG_EPSIZE_Pos) |
- (TUSB_XFER_CONTROL << DEVEPTCFG_EPTYPE_Pos) |
- (DEVEPTCFG_EPBK_1_BANK << DEVEPTCFG_EPBK_Pos) |
- DEVEPTCFG_ALLOC
- );
- USB_REG->DEVEPTIER[0] = DEVEPTIER_RSTDTS;
- USB_REG->DEVEPTIDR[0] = DEVEPTIDR_CTRL_STALLRQC;
- if (DEVEPTISR_CFGOK == (USB_REG->DEVEPTISR[0] & DEVEPTISR_CFGOK))
- {
- // Endpoint configuration is successful
- USB_REG->DEVEPTIER[0] = DEVEPTIER_CTRL_RXSTPES;
- // Enable Endpoint 0 Interrupts
- USB_REG->DEVIER = DEVIER_PEP_0;
- return true;
- } else
- {
- // Endpoint configuration is not successful
- return false;
- }
- } else
- {
- // Enable the endpoint
- USB_REG->DEVEPT |= ((0x01 << epnum) << DEVEPT_EPEN0_Pos);
- // Set up the maxpacket size, fifo start address fifosize
- // and enable the interrupt. CLear the data toggle.
- // AUTOSW is needed for DMA ack !
- USB_REG->DEVEPTCFG[epnum] =
- (
- (fifoSize << DEVEPTCFG_EPSIZE_Pos) |
- (eptype << DEVEPTCFG_EPTYPE_Pos) |
- (DEVEPTCFG_EPBK_1_BANK << DEVEPTCFG_EPBK_Pos) |
- DEVEPTCFG_AUTOSW |
- ((dir & 0x01) << DEVEPTCFG_EPDIR_Pos)
- );
- if (eptype == TUSB_XFER_ISOCHRONOUS)
- {
- USB_REG->DEVEPTCFG[epnum] |= DEVEPTCFG_NBTRANS_1_TRANS;
- }
-#if USE_DUAL_BANK
- if (eptype == TUSB_XFER_ISOCHRONOUS || eptype == TUSB_XFER_BULK)
- {
- USB_REG->DEVEPTCFG[epnum] |= DEVEPTCFG_EPBK_2_BANK;
- }
-#endif
- USB_REG->DEVEPTCFG[epnum] |= DEVEPTCFG_ALLOC;
- USB_REG->DEVEPTIER[epnum] = DEVEPTIER_RSTDTS;
- USB_REG->DEVEPTIDR[epnum] = DEVEPTIDR_CTRL_STALLRQC;
- if (DEVEPTISR_CFGOK == (USB_REG->DEVEPTISR[epnum] & DEVEPTISR_CFGOK))
- {
- USB_REG->DEVIER = ((0x01 << epnum) << DEVIER_PEP_0_Pos);
- return true;
- } else
- {
- // Endpoint configuration is not successful
- return false;
- }
- }
-}
-
-void dcd_edpt_close(uint8_t rhport, uint8_t ep_addr)
-{
- (void) rhport;
- uint8_t const epnum = tu_edpt_number(ep_addr);
-
- // Disable endpoint interrupt
- USB_REG->DEVIDR = 1 << (DEVIDR_PEP_0_Pos + epnum);
- // Disable EP
- USB_REG->DEVEPT &=~(1 << (DEVEPT_EPEN0_Pos + epnum));
-}
-
-static void dcd_transmit_packet(xfer_ctl_t * xfer, uint8_t ep_ix)
-{
- uint16_t len = (uint16_t)(xfer->total_len - xfer->queued_len);
- if (len)
- {
- if (len > xfer->max_packet_size)
- {
- len = xfer->max_packet_size;
- }
- uint8_t *ptr = EP_GET_FIFO_PTR(ep_ix,8);
- if(xfer->buffer)
- {
- memcpy(ptr, xfer->buffer + xfer->queued_len, len);
- }
- else
- {
- tu_fifo_read_n(xfer->fifo, ptr, len);
- }
- __DSB();
- __ISB();
- xfer->queued_len = (uint16_t)(xfer->queued_len + len);
- }
- if (ep_ix == 0U)
- {
- // Control endpoint: clear the interrupt flag to send the data
- USB_REG->DEVEPTICR[0] = DEVEPTICR_TXINIC;
- } else
- {
- // Other endpoint types: clear the FIFO control flag to send the data
- USB_REG->DEVEPTIDR[ep_ix] = DEVEPTIDR_FIFOCONC;
- }
- USB_REG->DEVEPTIER[ep_ix] = DEVEPTIER_TXINES;
-}
-
-// Submit a transfer, When complete dcd_event_xfer_complete() is invoked to notify the stack
-bool dcd_edpt_xfer (uint8_t rhport, uint8_t ep_addr, uint8_t * buffer, uint16_t total_bytes)
-{
- (void) rhport;
- uint8_t const epnum = tu_edpt_number(ep_addr);
- uint8_t const dir = tu_edpt_dir(ep_addr);
-
- xfer_ctl_t * xfer = &xfer_status[epnum];
-
- xfer->buffer = buffer;
- xfer->total_len = total_bytes;
- xfer->queued_len = 0;
- xfer->fifo = NULL;
-
- if (EP_DMA_SUPPORT(epnum) && total_bytes != 0)
- {
- // Force the CPU to flush the buffer. We increase the size by 32 because the call aligns the
- // address to 32-byte boundaries.
- CleanInValidateCache((uint32_t*) tu_align((uint32_t) buffer, 4), total_bytes + 31);
- uint32_t udd_dma_ctrl = total_bytes << DEVDMACONTROL_BUFF_LENGTH_Pos;
- if (dir == TUSB_DIR_OUT)
- {
- udd_dma_ctrl |= DEVDMACONTROL_END_TR_IT | DEVDMACONTROL_END_TR_EN;
- } else {
- udd_dma_ctrl |= DEVDMACONTROL_END_B_EN;
- }
- USB_REG->DEVDMA[epnum - 1].DEVDMAADDRESS = (uint32_t)buffer;
- udd_dma_ctrl |= DEVDMACONTROL_END_BUFFIT | DEVDMACONTROL_CHANN_ENB;
- // Disable IRQs to have a short sequence
- // between read of EOT_STA and DMA enable
- uint32_t irq_state = __get_PRIMASK();
- __disable_irq();
- if (!(USB_REG->DEVDMA[epnum - 1].DEVDMASTATUS & DEVDMASTATUS_END_TR_ST))
- {
- USB_REG->DEVDMA[epnum - 1].DEVDMACONTROL = udd_dma_ctrl;
- USB_REG->DEVIER = DEVIER_DMA_1 << (epnum - 1);
- __set_PRIMASK(irq_state);
- return true;
- }
- __set_PRIMASK(irq_state);
-
- // Here a ZLP has been recieved
- // and the DMA transfer must be not started.
- // It is the end of transfer
- return false;
- } else
- {
- if (dir == TUSB_DIR_OUT)
- {
- USB_REG->DEVEPTIER[epnum] = DEVEPTIER_RXOUTES;
- } else
- {
- dcd_transmit_packet(xfer,epnum);
- }
- }
- return true;
-}
-
-// The number of bytes has to be given explicitly to allow more flexible control of how many
-// bytes should be written and second to keep the return value free to give back a boolean
-// success message. If total_bytes is too big, the FIFO will copy only what is available
-// into the USB buffer!
-bool dcd_edpt_xfer_fifo (uint8_t rhport, uint8_t ep_addr, tu_fifo_t * ff, uint16_t total_bytes)
-{
- (void) rhport;
- uint8_t const epnum = tu_edpt_number(ep_addr);
- uint8_t const dir = tu_edpt_dir(ep_addr);
-
- xfer_ctl_t * xfer = &xfer_status[epnum];
- if(epnum == 0x80)
- xfer = &xfer_status[EP_MAX];
-
- xfer->buffer = NULL;
- xfer->total_len = total_bytes;
- xfer->queued_len = 0;
- xfer->fifo = ff;
-
- if (EP_DMA_SUPPORT(epnum) && total_bytes != 0)
- {
- tu_fifo_buffer_info_t info;
- uint32_t udd_dma_ctrl_lin = DEVDMACONTROL_CHANN_ENB;
- uint32_t udd_dma_ctrl_wrap = DEVDMACONTROL_CHANN_ENB | DEVDMACONTROL_END_BUFFIT;
- if (dir == TUSB_DIR_OUT)
- {
- tu_fifo_get_write_info(ff, &info);
- udd_dma_ctrl_lin |= DEVDMACONTROL_END_TR_IT | DEVDMACONTROL_END_TR_EN;
- udd_dma_ctrl_wrap |= DEVDMACONTROL_END_TR_IT | DEVDMACONTROL_END_TR_EN;
- } else {
- tu_fifo_get_read_info(ff, &info);
- if(info.len_wrap == 0)
- {
- udd_dma_ctrl_lin |= DEVDMACONTROL_END_B_EN;
- }
- udd_dma_ctrl_wrap |= DEVDMACONTROL_END_B_EN;
- }
-
- // Clean invalidate cache of linear part
- CleanInValidateCache((uint32_t*) tu_align((uint32_t) info.ptr_lin, 4), info.len_lin + 31);
-
- USB_REG->DEVDMA[epnum - 1].DEVDMAADDRESS = (uint32_t)info.ptr_lin;
- if (info.len_wrap)
- {
- // Clean invalidate cache of wrapped part
- CleanInValidateCache((uint32_t*) tu_align((uint32_t) info.ptr_wrap, 4), info.len_wrap + 31);
-
- dma_desc[epnum - 1].next_desc = 0;
- dma_desc[epnum - 1].buff_addr = (uint32_t)info.ptr_wrap;
- dma_desc[epnum - 1].chnl_ctrl =
- udd_dma_ctrl_wrap | (info.len_wrap << DEVDMACONTROL_BUFF_LENGTH_Pos);
- // Clean cache of wrapped DMA descriptor
- CleanInValidateCache((uint32_t*)&dma_desc[epnum - 1], sizeof(dma_desc_t));
-
- udd_dma_ctrl_lin |= DEVDMASTATUS_DESC_LDST;
- USB_REG->DEVDMA[epnum - 1].DEVDMANXTDSC = (uint32_t)&dma_desc[epnum - 1];
- } else {
- udd_dma_ctrl_lin |= DEVDMACONTROL_END_BUFFIT;
- }
- udd_dma_ctrl_lin |= (info.len_lin << DEVDMACONTROL_BUFF_LENGTH_Pos);
- // Disable IRQs to have a short sequence
- // between read of EOT_STA and DMA enable
- uint32_t irq_state = __get_PRIMASK();
- __disable_irq();
- if (!(USB_REG->DEVDMA[epnum - 1].DEVDMASTATUS & DEVDMASTATUS_END_TR_ST))
- {
- USB_REG->DEVDMA[epnum - 1].DEVDMACONTROL = udd_dma_ctrl_lin;
- USB_REG->DEVIER = DEVIER_DMA_1 << (epnum - 1);
- __set_PRIMASK(irq_state);
- return true;
- }
- __set_PRIMASK(irq_state);
-
- // Here a ZLP has been recieved
- // and the DMA transfer must be not started.
- // It is the end of transfer
- return false;
- } else
- {
- if (dir == TUSB_DIR_OUT)
- {
- USB_REG->DEVEPTIER[epnum] = DEVEPTIER_RXOUTES;
- } else
- {
- dcd_transmit_packet(xfer,epnum);
- }
- }
- return true;
-}
-
-// Stall endpoint
-void dcd_edpt_stall (uint8_t rhport, uint8_t ep_addr)
-{
- (void) rhport;
- uint8_t const epnum = tu_edpt_number(ep_addr);
- USB_REG->DEVEPTIER[epnum] = DEVEPTIER_CTRL_STALLRQS;
- // Re-enable SETUP interrupt
- if (epnum == 0)
- {
- USB_REG->DEVEPTIER[0] = DEVEPTIER_CTRL_RXSTPES;
- }
-}
-
-// clear stall, data toggle is also reset to DATA0
-void dcd_edpt_clear_stall (uint8_t rhport, uint8_t ep_addr)
-{
- (void) rhport;
- uint8_t const epnum = tu_edpt_number(ep_addr);
- USB_REG->DEVEPTIDR[epnum] = DEVEPTIDR_CTRL_STALLRQC;
- USB_REG->DEVEPTIER[epnum] = HSTPIPIER_RSTDTS;
-}
-
-#endif
diff --git a/tinyusb/src/portable/mindmotion/mm32/dcd_mm32f327x_otg.c b/tinyusb/src/portable/mindmotion/mm32/dcd_mm32f327x_otg.c
deleted file mode 100755
index 59a40dc6..00000000
--- a/tinyusb/src/portable/mindmotion/mm32/dcd_mm32f327x_otg.c
+++ /dev/null
@@ -1,471 +0,0 @@
-/*
- * The MIT License (MIT)
- *
- * Copyright (c) 2020 SE TEAM
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- *
- * This file is part of the TinyUSB stack.
- */
-
-#include "tusb_option.h"
-
-#if TUSB_OPT_DEVICE_ENABLED && ( CFG_TUSB_MCU == OPT_MCU_MM32F327X )
-
-#include "reg_usb_otg_fs.h"
-#include "mm32_device.h"
-#include "hal_conf.h"
-#include "device/dcd.h"
-
-//--------------------------------------------------------------------+
-// MACRO TYPEDEF CONSTANT ENUM DECLARATION
-//--------------------------------------------------------------------+
-
-enum {
- TOK_PID_OUT = 0x1u,
- TOK_PID_IN = 0x9u,
- TOK_PID_SETUP = 0xDu,
-};
-
-typedef struct TU_ATTR_PACKED
-{
- union {
- uint32_t head;
- struct {
- union {
- struct {
- uint16_t : 2;
- uint16_t tok_pid : 4;
- uint16_t data : 1;
- uint16_t own : 1;
- uint16_t : 8;
- };
- struct {
- uint16_t : 2;
- uint16_t bdt_stall: 1;
- uint16_t dts : 1;
- uint16_t ninc : 1;
- uint16_t keep : 1;
- uint16_t : 10;
- };
- };
- uint16_t bc : 10;
- uint16_t : 6;
- };
- };
- uint8_t *addr;
-}buffer_descriptor_t;
-
-TU_VERIFY_STATIC( sizeof(buffer_descriptor_t) == 8, "size is not correct" );
-
-typedef struct TU_ATTR_PACKED
-{
- union {
- uint32_t state;
- struct {
- uint32_t max_packet_size :11;
- uint32_t : 5;
- uint32_t odd : 1;
- uint32_t :15;
- };
- };
- uint16_t length;
- uint16_t remaining;
-}endpoint_state_t;
-
-TU_VERIFY_STATIC( sizeof(endpoint_state_t) == 8, "size is not correct" );
-
-typedef struct
-{
- union {
- /* [#EP][OUT,IN][EVEN,ODD] */
- buffer_descriptor_t bdt[16][2][2];
- uint16_t bda[512];
- };
- TU_ATTR_ALIGNED(4) union {
- endpoint_state_t endpoint[16][2];
- endpoint_state_t endpoint_unified[16 * 2];
- };
- uint8_t setup_packet[8];
- uint8_t addr;
-}dcd_data_t;
-
-//--------------------------------------------------------------------+
-// INTERNAL OBJECT & FUNCTION DECLARATION
-//--------------------------------------------------------------------+
-// BDT(Buffer Descriptor Table) must be 256-byte aligned
-CFG_TUSB_MEM_SECTION TU_ATTR_ALIGNED(512) static dcd_data_t _dcd;
-
-TU_VERIFY_STATIC( sizeof(_dcd.bdt) == 512, "size is not correct" );
-
-static void prepare_next_setup_packet(uint8_t rhport)
-{
- const unsigned out_odd = _dcd.endpoint[0][0].odd;
- const unsigned in_odd = _dcd.endpoint[0][1].odd;
- if (_dcd.bdt[0][0][out_odd].own) {
- TU_LOG1("DCD fail to prepare the next SETUP %d %d\r\n", out_odd, in_odd);
- return;
- }
- _dcd.bdt[0][0][out_odd].data = 0;
- _dcd.bdt[0][0][out_odd ^ 1].data = 1;
- _dcd.bdt[0][1][in_odd].data = 1;
- _dcd.bdt[0][1][in_odd ^ 1].data = 0;
- dcd_edpt_xfer(rhport, tu_edpt_addr(0, TUSB_DIR_OUT),
- _dcd.setup_packet, sizeof(_dcd.setup_packet));
-}
-
-static void process_stall(uint8_t rhport)
-{
- if (USB_OTG_FS->EP_CTL[0] & USB_ENDPT_EPSTALL_MASK) {
- /* clear stall condition of the control pipe */
- prepare_next_setup_packet(rhport);
- USB_OTG_FS->EP_CTL[0] &= ~USB_ENDPT_EPSTALL_MASK;
- }
-}
-
-static void process_tokdne(uint8_t rhport)
-{
- const unsigned s = USB_OTG_FS->STAT;
- USB_OTG_FS->INT_STAT = USB_ISTAT_TOKDNE_MASK; /* fetch the next token if received */
- buffer_descriptor_t *bd = (buffer_descriptor_t *)&_dcd.bda[s];
- endpoint_state_t *ep = &_dcd.endpoint_unified[s >> 3];
- unsigned odd = (s & USB_STAT_ODD_MASK) ? 1 : 0;
-
- /* fetch pid before discarded by the next steps */
- const unsigned pid = bd->tok_pid;
- /* reset values for a next transfer */
- bd->bdt_stall = 0;
- bd->dts = 1;
- bd->ninc = 0;
- bd->keep = 0;
- /* update the odd variable to prepare for the next transfer */
- ep->odd = odd ^ 1;
- if (pid == TOK_PID_SETUP) {
- dcd_event_setup_received(rhport, bd->addr, true);
- USB_OTG_FS->CTL &= ~USB_CTL_TXSUSPENDTOKENBUSY_MASK;
- return;
- }
- if (s >> 4) {
- TU_LOG1("TKDNE %x\r\n", s);
- }
-
- const unsigned bc = bd->bc;
- const unsigned remaining = ep->remaining - bc;
- if (remaining && bc == ep->max_packet_size) {
- /* continue the transferring consecutive data */
- ep->remaining = remaining;
- const int next_remaining = remaining - ep->max_packet_size;
- if (next_remaining > 0) {
- /* prepare to the after next transfer */
- bd->addr += ep->max_packet_size * 2;
- bd->bc = next_remaining > ep->max_packet_size ? ep->max_packet_size: next_remaining;
- __DSB();
- bd->own = 1; /* the own bit must set after addr */
- }
- return;
- }
- const unsigned length = ep->length;
- dcd_event_xfer_complete(rhport,
- ((s & USB_STAT_TX_MASK) << 4) | (s >> USB_STAT_ENDP_SHIFT),
- length - remaining, XFER_RESULT_SUCCESS, true);
- if (0 == (s & USB_STAT_ENDP_MASK) && 0 == length) {
- /* After completion a ZLP of control transfer,
- * it prepares for the next steup transfer. */
- if (_dcd.addr) {
- /* When the transfer was the SetAddress,
- * the device address should be updated here. */
- USB_OTG_FS->ADDR = _dcd.addr;
- _dcd.addr = 0;
- }
- prepare_next_setup_packet(rhport);
- }
-}
-
-static void process_bus_reset(uint8_t rhport)
-{
- USB_OTG_FS->CTL |= USB_CTL_ODDRST_MASK;
- USB_OTG_FS->ADDR = 0;
- USB_OTG_FS->INT_ENB = (USB_OTG_FS->INT_ENB & ~USB_INTEN_RESUMEEN_MASK) | USB_INTEN_SLEEPEN_MASK;
-
- USB_OTG_FS->EP_CTL[0] = USB_ENDPT_EPHSHK_MASK | USB_ENDPT_EPRXEN_MASK | USB_ENDPT_EPTXEN_MASK;
- for (unsigned i = 1; i < 16; ++i) {
- USB_OTG_FS->EP_CTL[i] = 0;
- }
- buffer_descriptor_t *bd = _dcd.bdt[0][0];
- for (unsigned i = 0; i < sizeof(_dcd.bdt)/sizeof(*bd); ++i, ++bd) {
- bd->head = 0;
- }
- const endpoint_state_t ep0 = {
- .max_packet_size = CFG_TUD_ENDPOINT0_SIZE,
- .odd = 0,
- .length = 0,
- .remaining = 0,
- };
- _dcd.endpoint[0][0] = ep0;
- _dcd.endpoint[0][1] = ep0;
- tu_memclr(_dcd.endpoint[1], sizeof(_dcd.endpoint) - sizeof(_dcd.endpoint[0]));
- _dcd.addr = 0;
- prepare_next_setup_packet(rhport);
- USB_OTG_FS->CTL &= ~USB_CTL_ODDRST_MASK;
- dcd_event_bus_reset(rhport, TUSB_SPEED_FULL, true);
-}
-
-static void process_bus_inactive(uint8_t rhport)
-{
- (void) rhport;
- const unsigned inten = USB_OTG_FS->INT_ENB;
- USB_OTG_FS->INT_ENB = (inten & ~USB_INTEN_SLEEPEN_MASK) | USB_INTEN_RESUMEEN_MASK;
- dcd_event_bus_signal(rhport, DCD_EVENT_SUSPEND, true);
-}
-
-static void process_bus_active(uint8_t rhport)
-{
- (void) rhport;
- const unsigned inten = USB_OTG_FS->INT_ENB;
- USB_OTG_FS->INT_ENB = (inten & ~USB_INTEN_RESUMEEN_MASK) | USB_INTEN_SLEEPEN_MASK;
- dcd_event_bus_signal(rhport, DCD_EVENT_RESUME, true);
-}
-
-/*------------------------------------------------------------------*/
-/* Device API
- *------------------------------------------------------------------*/
-void dcd_init(uint8_t rhport)
-{
- (void) rhport;
-
- tu_memclr(&_dcd, sizeof(_dcd));
- USB_OTG_FS->BDT_PAGE_01 = (uint8_t)((uintptr_t)_dcd.bdt >> 8);
- USB_OTG_FS->BDT_PAGE_02 = (uint8_t)((uintptr_t)_dcd.bdt >> 16);
- USB_OTG_FS->BDT_PAGE_03 = (uint8_t)((uintptr_t)_dcd.bdt >> 24);
-
- dcd_connect(rhport);
- NVIC_ClearPendingIRQ(USB_FS_IRQn);
-}
-#define USB_DEVICE_INTERRUPT_PRIORITY (3U)
-void dcd_int_enable(uint8_t rhport)
-{
- uint8_t irqNumber;
- irqNumber = USB_FS_IRQn;
- (void) rhport;
- USB_OTG_FS->INT_ENB = USB_INTEN_USBRSTEN_MASK | USB_INTEN_TOKDNEEN_MASK |
- USB_INTEN_SLEEPEN_MASK | USB_INTEN_ERROREN_MASK | USB_INTEN_STALLEN_MASK;
- NVIC_SetPriority((IRQn_Type)irqNumber, USB_DEVICE_INTERRUPT_PRIORITY);
- NVIC_EnableIRQ(USB_FS_IRQn);
-}
-
-void dcd_int_disable(uint8_t rhport)
-{
- (void) rhport;
- NVIC_DisableIRQ(USB_FS_IRQn);
- USB_OTG_FS->INT_ENB = 0;
-}
-
-void dcd_set_address(uint8_t rhport, uint8_t dev_addr)
-{
- (void) rhport;
- _dcd.addr = dev_addr & 0x7F;
- /* Response with status first before changing device address */
- dcd_edpt_xfer(rhport, tu_edpt_addr(0, TUSB_DIR_IN), NULL, 0);
-}
-extern u32 SystemCoreClock ;
-void dcd_remote_wakeup(uint8_t rhport)
-{
- (void) rhport;
- unsigned cnt = SystemCoreClock / 100;
- USB_OTG_FS->CTL |= USB_CTL_RESUME_MASK;
- while (cnt--) __NOP();
- USB_OTG_FS->CTL &= ~USB_CTL_RESUME_MASK;
-}
-
-void dcd_connect(uint8_t rhport)
-{
- (void) rhport;
- USB_OTG_FS->CTL |= USB_CTL_USBENSOFEN_MASK;
-}
-
-void dcd_disconnect(uint8_t rhport)
-{
- (void) rhport;
- USB_OTG_FS->CTL = 0;
-}
-
-//--------------------------------------------------------------------+
-// Endpoint API
-//--------------------------------------------------------------------+
-bool dcd_edpt_open(uint8_t rhport, tusb_desc_endpoint_t const * ep_desc)
-{
- (void) rhport;
-
- const unsigned ep_addr = ep_desc->bEndpointAddress;
- const unsigned epn = ep_addr & 0xFu;
- const unsigned dir = (ep_addr & TUSB_DIR_IN_MASK) ? TUSB_DIR_IN : TUSB_DIR_OUT;
- const unsigned xfer = ep_desc->bmAttributes.xfer;
- endpoint_state_t *ep = &_dcd.endpoint[epn][dir];
- const unsigned odd = ep->odd;
- buffer_descriptor_t *bd = &_dcd.bdt[epn][dir][0];
-
- /* No support for control transfer */
- TU_ASSERT(epn && (xfer != TUSB_XFER_CONTROL));
-
- ep->max_packet_size = ep_desc->wMaxPacketSize.size;
- unsigned val = USB_ENDPT_EPCTLDIS_MASK;
- val |= (xfer != TUSB_XFER_ISOCHRONOUS) ? USB_ENDPT_EPHSHK_MASK: 0;
- val |= dir ? USB_ENDPT_EPTXEN_MASK : USB_ENDPT_EPRXEN_MASK;
- USB_OTG_FS->EP_CTL[epn] |= val;
-
- if (xfer != TUSB_XFER_ISOCHRONOUS) {
- bd[odd].dts = 1;
- bd[odd].data = 0;
- bd[odd ^ 1].dts = 1;
- bd[odd ^ 1].data = 1;
- }
-
- return true;
-}
-
-void dcd_edpt_close(uint8_t rhport, uint8_t ep_addr)
-{
- (void) rhport;
-
- const unsigned epn = ep_addr & 0xFu;
- const unsigned dir = (ep_addr & TUSB_DIR_IN_MASK) ? TUSB_DIR_IN : TUSB_DIR_OUT;
- endpoint_state_t *ep = &_dcd.endpoint[epn][dir];
- buffer_descriptor_t *bd = &_dcd.bdt[epn][dir][0];
- const unsigned msk = dir ? USB_ENDPT_EPTXEN_MASK : USB_ENDPT_EPRXEN_MASK;
- USB_OTG_FS->EP_CTL[epn] &= ~msk;
- ep->max_packet_size = 0;
- ep->length = 0;
- ep->remaining = 0;
- bd->head = 0;
-}
-
-bool dcd_edpt_xfer(uint8_t rhport, uint8_t ep_addr, uint8_t* buffer, uint16_t total_bytes)
-{
- (void) rhport;
- NVIC_DisableIRQ(USB_FS_IRQn);
- const unsigned epn = ep_addr & 0xFu;
- const unsigned dir = (ep_addr & TUSB_DIR_IN_MASK) ? TUSB_DIR_IN : TUSB_DIR_OUT;
- endpoint_state_t *ep = &_dcd.endpoint[epn][dir];
- buffer_descriptor_t *bd = &_dcd.bdt[epn][dir][ep->odd];
-
- if (bd->own) {
- TU_LOG1("DCD XFER fail %x %d %lx %lx\r\n", ep_addr, total_bytes, ep->state, bd->head);
- return false; /* The last transfer has not completed */
- }
- ep->length = total_bytes;
- ep->remaining = total_bytes;
-
- const unsigned mps = ep->max_packet_size;
- if (total_bytes > mps) {
- buffer_descriptor_t *next = ep->odd ? bd - 1: bd + 1;
- /* When total_bytes is greater than the max packet size,
- * it prepares to the next transfer to avoid NAK in advance. */
- next->bc = total_bytes >= 2 * mps ? mps: total_bytes - mps;
- next->addr = buffer + mps;
- next->own = 1;
- }
- bd->bc = total_bytes >= mps ? mps: total_bytes;
- bd->addr = buffer;
- __DSB();
- bd->own = 1; /* the own bit must set after addr */
- NVIC_EnableIRQ(USB_FS_IRQn);
- return true;
-}
-
-void dcd_edpt_stall(uint8_t rhport, uint8_t ep_addr)
-{
- (void) rhport;
- const unsigned epn = ep_addr & 0xFu;
- if (0 == epn) {
- USB_OTG_FS->EP_CTL[epn] |= USB_ENDPT_EPSTALL_MASK;
- } else {
- const unsigned dir = (ep_addr & TUSB_DIR_IN_MASK) ? TUSB_DIR_IN : TUSB_DIR_OUT;
- buffer_descriptor_t *bd = _dcd.bdt[epn][dir];
- bd[0].bdt_stall = 1;
- bd[1].bdt_stall = 1;
- }
-}
-
-void dcd_edpt_clear_stall(uint8_t rhport, uint8_t ep_addr)
-{
- (void) rhport;
- const unsigned epn = ep_addr & 0xFu;
- const unsigned dir = (ep_addr & TUSB_DIR_IN_MASK) ? TUSB_DIR_IN : TUSB_DIR_OUT;
- const unsigned odd = _dcd.endpoint[epn][dir].odd;
- buffer_descriptor_t *bd = _dcd.bdt[epn][dir];
-
- bd[odd ^ 1].own = 0;
- bd[odd ^ 1].data = 1;
- bd[odd ^ 1].bdt_stall = 0;
- bd[odd].own = 0;
- bd[odd].data = 0;
- bd[odd].bdt_stall = 0;
-}
-
-//--------------------------------------------------------------------+
-// ISR
-//--------------------------------------------------------------------+
-void dcd_int_handler(uint8_t rhport)
-{
- (void) rhport;
-
- uint32_t is = USB_OTG_FS->INT_STAT;
- uint32_t msk = USB_OTG_FS->INT_ENB;
- USB_OTG_FS->INT_STAT = is & ~msk;
- is &= msk;
- if (is & USB_ISTAT_ERROR_MASK) {
- /* TODO: */
- uint32_t es = USB_OTG_FS->ERR_STAT;
- USB_OTG_FS->ERR_STAT = es;
- USB_OTG_FS->INT_STAT = is; /* discard any pending events */
- return;
- }
-
- if (is & USB_ISTAT_USBRST_MASK) {
- USB_OTG_FS->INT_STAT = is; /* discard any pending events */
- process_bus_reset(rhport);
- return;
- }
- if (is & USB_ISTAT_SLEEP_MASK) {
- USB_OTG_FS->INT_STAT = USB_ISTAT_SLEEP_MASK;
- process_bus_inactive(rhport);
- return;
- }
- if (is & USB_ISTAT_RESUME_MASK) {
- USB_OTG_FS->INT_STAT = USB_ISTAT_RESUME_MASK;
- process_bus_active(rhport);
- return;
- }
- if (is & USB_ISTAT_SOFTOK_MASK) {
- USB_OTG_FS->INT_STAT = USB_ISTAT_SOFTOK_MASK;
- dcd_event_bus_signal(rhport, DCD_EVENT_SOF, true);
- return;
- }
- if (is & USB_ISTAT_STALL_MASK) {
- USB_OTG_FS->INT_STAT = USB_ISTAT_STALL_MASK;
- process_stall(rhport);
- return;
- }
- if (is & USB_ISTAT_TOKDNE_MASK) {
- process_tokdne(rhport);
- return;
- }
-}
-
-#endif
diff --git a/tinyusb/src/portable/nordic/nrf5x/dcd_nrf5x.c b/tinyusb/src/portable/nordic/nrf5x/dcd_nrf5x.c
deleted file mode 100755
index f6b64c98..00000000
--- a/tinyusb/src/portable/nordic/nrf5x/dcd_nrf5x.c
+++ /dev/null
@@ -1,1050 +0,0 @@
-/*
- * The MIT License (MIT)
- *
- * Copyright (c) 2019 Ha Thach (tinyusb.org)
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- *
- * This file is part of the TinyUSB stack.
- */
-
-#include "tusb_option.h"
-
-#if TUSB_OPT_DEVICE_ENABLED && CFG_TUSB_MCU == OPT_MCU_NRF5X
-
-#include "nrf.h"
-#include "nrf_clock.h"
-#include "nrf_power.h"
-#include "nrfx_usbd_errata.h"
-#include "device/dcd.h"
-
-// TODO remove later
-#include "device/usbd.h"
-#include "device/usbd_pvt.h" // to use defer function helper
-
-/*------------------------------------------------------------------*/
-/* MACRO TYPEDEF CONSTANT ENUM
- *------------------------------------------------------------------*/
-enum
-{
- // Max allowed by USB specs
- MAX_PACKET_SIZE = 64,
-
- // Mask of all END event (IN & OUT) for all endpoints. ENDEPIN0-7, ENDEPOUT0-7, ENDISOIN, ENDISOOUT
- EDPT_END_ALL_MASK = (0xff << USBD_INTEN_ENDEPIN0_Pos) | (0xff << USBD_INTEN_ENDEPOUT0_Pos) |
- USBD_INTENCLR_ENDISOIN_Msk | USBD_INTEN_ENDISOOUT_Msk
-};
-
-enum
-{
- EP_ISO_NUM = 8, // Endpoint number is fixed (8) for ISOOUT and ISOIN
- EP_CBI_COUNT = 8 // Control Bulk Interrupt endpoints count
-};
-
-// Transfer Descriptor
-typedef struct
-{
- uint8_t* buffer;
- uint16_t total_len;
- volatile uint16_t actual_len;
- uint16_t mps; // max packet size
-
- // nRF will auto accept OUT packet after DMA is done
- // indicate packet is already ACK
- volatile bool data_received;
-
- // Set to true when data was transferred from RAM to ISO IN output buffer.
- // New data can be put in ISO IN output buffer after SOF.
- bool iso_in_transfer_ready;
-
-} xfer_td_t;
-
-// Data for managing dcd
-static struct
-{
- // All 8 endpoints including control IN & OUT (offset 1)
- // +1 for ISO endpoints
- xfer_td_t xfer[EP_CBI_COUNT + 1][2];
-
- // Number of pending DMA that is started but not handled yet by dcd_int_handler().
- // Since nRF can only carry one DMA can run at a time, this value is normally be either 0 or 1.
- // However, in critical section with interrupt disabled, the DMA can be finished and added up
- // until handled by dcd_int_handler() when exiting critical section.
- volatile uint8_t dma_pending;
-}_dcd;
-
-/*------------------------------------------------------------------*/
-/* Control / Bulk / Interrupt (CBI) Transfer
- *------------------------------------------------------------------*/
-
-// NVIC_GetEnableIRQ is only available in CMSIS v5
-#ifndef NVIC_GetEnableIRQ
-static inline uint32_t NVIC_GetEnableIRQ(IRQn_Type IRQn)
-{
- if ((int32_t)(IRQn) >= 0)
- {
- return((uint32_t)(((NVIC->ISER[(((uint32_t)(int32_t)IRQn) >> 5UL)] & (1UL << (((uint32_t)(int32_t)IRQn) & 0x1FUL))) != 0UL) ? 1UL : 0UL));
- }
- else
- {
- return(0U);
- }
-}
-#endif
-
-// check if we are in ISR
-TU_ATTR_ALWAYS_INLINE static inline bool is_in_isr(void)
-{
- return (SCB->ICSR & SCB_ICSR_VECTACTIVE_Msk) ? true : false;
-}
-
-// helper to start DMA
-// TODO use Cortex M4 LDREX and STREX command (atomic) to have better mutex access to EasyDMA
-// since current implementation does not 100% guarded against race condition
-static void edpt_dma_start(volatile uint32_t* reg_startep)
-{
- // Only one dma can be active
- if ( _dcd.dma_pending )
- {
- if (is_in_isr())
- {
- // Called within ISR, use usbd task to defer later
- usbd_defer_func( (osal_task_func_t) edpt_dma_start, (void*) reg_startep, true );
- return;
- }
- else
- {
- if ( __get_PRIMASK() || !NVIC_GetEnableIRQ(USBD_IRQn) )
- {
- // Called in critical section with interrupt disabled. We have to manually check
- // for the DMA complete by comparing current pending DMA with number of ENDED Events
- uint32_t ended = 0;
-
- while ( _dcd.dma_pending > ((uint8_t) ended) )
- {
- ended = NRF_USBD->EVENTS_ENDISOIN + NRF_USBD->EVENTS_ENDISOOUT;
-
- for (uint8_t i=0; i<EP_CBI_COUNT; i++)
- {
- ended += NRF_USBD->EVENTS_ENDEPIN[i] + NRF_USBD->EVENTS_ENDEPOUT[i];
- }
- }
- }else
- {
- // Called in non-critical thread-mode, should be 99% of the time.
- // Should be safe to blocking wait until previous DMA transfer complete
- while ( _dcd.dma_pending ) { }
- }
- }
- }
-
- _dcd.dma_pending++;
-
- (*reg_startep) = 1;
- __ISB(); __DSB();
-}
-
-// DMA is complete
-static void edpt_dma_end(void)
-{
- TU_ASSERT(_dcd.dma_pending, );
- _dcd.dma_pending = 0;
-}
-
-// helper to set TASKS_EP0STATUS / TASKS_EP0RCVOUT since they also need EasyDMA
-// However TASKS_EP0STATUS doesn't trigger any DMA transfer and got ENDED event subsequently
-// Therefore dma_running state will be corrected right away
-void start_ep0_task(volatile uint32_t* reg_task)
-{
- edpt_dma_start(reg_task);
-
- // correct the dma_running++ in dma start
- if (_dcd.dma_pending) _dcd.dma_pending--;
-}
-
-// helper getting td
-static inline xfer_td_t* get_td(uint8_t epnum, uint8_t dir)
-{
- return &_dcd.xfer[epnum][dir];
-}
-
-// Start DMA to move data from Endpoint -> RAM
-static void xact_out_dma(uint8_t epnum)
-{
- xfer_td_t* xfer = get_td(epnum, TUSB_DIR_OUT);
- uint32_t xact_len;
-
- if (epnum == EP_ISO_NUM)
- {
- xact_len = NRF_USBD->SIZE.ISOOUT;
- // If ZERO bit is set, ignore ISOOUT length
- if (xact_len & USBD_SIZE_ISOOUT_ZERO_Msk) xact_len = 0;
- else
- {
- // Trigger DMA move data from Endpoint -> SRAM
- NRF_USBD->ISOOUT.PTR = (uint32_t) xfer->buffer;
- NRF_USBD->ISOOUT.MAXCNT = xact_len;
-
- edpt_dma_start(&NRF_USBD->TASKS_STARTISOOUT);
- }
- }
- else
- {
- xact_len = (uint8_t)NRF_USBD->SIZE.EPOUT[epnum];
-
- // Trigger DMA move data from Endpoint -> SRAM
- NRF_USBD->EPOUT[epnum].PTR = (uint32_t) xfer->buffer;
- NRF_USBD->EPOUT[epnum].MAXCNT = xact_len;
-
- edpt_dma_start(&NRF_USBD->TASKS_STARTEPOUT[epnum]);
- }
-
- xfer->buffer += xact_len;
- xfer->actual_len += xact_len;
-}
-
-// Prepare for a CBI transaction IN, call at the start
-// it start DMA to transfer data from RAM -> Endpoint
-static void xact_in_dma(uint8_t epnum)
-{
- xfer_td_t* xfer = get_td(epnum, TUSB_DIR_IN);
-
- // Each transaction is up to Max Packet Size
- uint16_t const xact_len = tu_min16(xfer->total_len - xfer->actual_len, xfer->mps);
-
- NRF_USBD->EPIN[epnum].PTR = (uint32_t) xfer->buffer;
- NRF_USBD->EPIN[epnum].MAXCNT = xact_len;
-
- xfer->buffer += xact_len;
-
- edpt_dma_start(&NRF_USBD->TASKS_STARTEPIN[epnum]);
-}
-
-//--------------------------------------------------------------------+
-// Controller API
-//--------------------------------------------------------------------+
-void dcd_init (uint8_t rhport)
-{
- (void) rhport;
-}
-
-void dcd_int_enable(uint8_t rhport)
-{
- (void) rhport;
- NVIC_EnableIRQ(USBD_IRQn);
-}
-
-void dcd_int_disable(uint8_t rhport)
-{
- (void) rhport;
- NVIC_DisableIRQ(USBD_IRQn);
-}
-
-void dcd_set_address (uint8_t rhport, uint8_t dev_addr)
-{
- (void) rhport;
- (void) dev_addr;
- // Set Address is automatically update by hw controller, nothing to do
-
- // Enable usbevent for suspend and resume detection
- // Since the bus signal D+/D- are stable now.
-
- // Clear current pending first
- NRF_USBD->EVENTCAUSE |= NRF_USBD->EVENTCAUSE;
- NRF_USBD->EVENTS_USBEVENT = 0;
-
- NRF_USBD->INTENSET = USBD_INTEN_USBEVENT_Msk;
-}
-
-void dcd_remote_wakeup(uint8_t rhport)
-{
- (void) rhport;
-
- // Bring controller out of low power mode
- // will start wakeup when USBWUALLOWED is set
- NRF_USBD->LOWPOWER = 0;
-}
-
-// disconnect by disabling internal pull-up resistor on D+/D-
-void dcd_disconnect(uint8_t rhport)
-{
- (void) rhport;
- NRF_USBD->USBPULLUP = 0;
-
- // Disable Pull-up does not trigger Power USB Removed, in fact it have no
- // impact on the USB Power status at all -> need to submit unplugged event to the stack.
- dcd_event_bus_signal(0, DCD_EVENT_UNPLUGGED, false);
-}
-
-// connect by enabling internal pull-up resistor on D+/D-
-void dcd_connect(uint8_t rhport)
-{
- (void) rhport;
- NRF_USBD->USBPULLUP = 1;
-}
-
-//--------------------------------------------------------------------+
-// Endpoint API
-//--------------------------------------------------------------------+
-bool dcd_edpt_open (uint8_t rhport, tusb_desc_endpoint_t const * desc_edpt)
-{
- (void) rhport;
-
- uint8_t const epnum = tu_edpt_number(desc_edpt->bEndpointAddress);
- uint8_t const dir = tu_edpt_dir(desc_edpt->bEndpointAddress);
-
- _dcd.xfer[epnum][dir].mps = desc_edpt->wMaxPacketSize.size;
-
- if (desc_edpt->bmAttributes.xfer != TUSB_XFER_ISOCHRONOUS)
- {
- if (dir == TUSB_DIR_OUT)
- {
- NRF_USBD->INTENSET = TU_BIT(USBD_INTEN_ENDEPOUT0_Pos + epnum);
- NRF_USBD->EPOUTEN |= TU_BIT(epnum);
-
- // Write any value to SIZE register will allow nRF to ACK/accept data
- NRF_USBD->SIZE.EPOUT[epnum] = 0;
- }else
- {
- NRF_USBD->INTENSET = TU_BIT(USBD_INTEN_ENDEPIN0_Pos + epnum);
- NRF_USBD->EPINEN |= TU_BIT(epnum);
- }
- }
- else
- {
- TU_ASSERT(epnum == EP_ISO_NUM);
- if (dir == TUSB_DIR_OUT)
- {
- // SPLIT ISO buffer when ISO IN endpoint is already opened.
- if (_dcd.xfer[EP_ISO_NUM][TUSB_DIR_IN].mps) NRF_USBD->ISOSPLIT = USBD_ISOSPLIT_SPLIT_HalfIN;
-
- // Clear old events
- NRF_USBD->EVENTS_ENDISOOUT = 0;
-
- // Clear SOF event in case interrupt was not enabled yet.
- if ((NRF_USBD->INTEN & USBD_INTEN_SOF_Msk) == 0) NRF_USBD->EVENTS_SOF = 0;
-
- // Enable SOF and ISOOUT interrupts, and ISOOUT endpoint.
- NRF_USBD->INTENSET = USBD_INTENSET_ENDISOOUT_Msk | USBD_INTENSET_SOF_Msk;
- NRF_USBD->EPOUTEN |= USBD_EPOUTEN_ISOOUT_Msk;
- }
- else
- {
- NRF_USBD->EVENTS_ENDISOIN = 0;
-
- // SPLIT ISO buffer when ISO OUT endpoint is already opened.
- if (_dcd.xfer[EP_ISO_NUM][TUSB_DIR_OUT].mps) NRF_USBD->ISOSPLIT = USBD_ISOSPLIT_SPLIT_HalfIN;
-
- // Clear SOF event in case interrupt was not enabled yet.
- if ((NRF_USBD->INTEN & USBD_INTEN_SOF_Msk) == 0) NRF_USBD->EVENTS_SOF = 0;
-
- // Enable SOF and ISOIN interrupts, and ISOIN endpoint.
- NRF_USBD->INTENSET = USBD_INTENSET_ENDISOIN_Msk | USBD_INTENSET_SOF_Msk;
- NRF_USBD->EPINEN |= USBD_EPINEN_ISOIN_Msk;
- }
- }
- __ISB(); __DSB();
-
- return true;
-}
-
-void dcd_edpt_close (uint8_t rhport, uint8_t ep_addr)
-{
- (void) rhport;
-
- uint8_t const epnum = tu_edpt_number(ep_addr);
- uint8_t const dir = tu_edpt_dir(ep_addr);
-
- if (epnum != EP_ISO_NUM)
- {
- // CBI
- if (dir == TUSB_DIR_OUT)
- {
- NRF_USBD->INTENCLR = TU_BIT(USBD_INTEN_ENDEPOUT0_Pos + epnum);
- NRF_USBD->EPOUTEN &= ~TU_BIT(epnum);
- }
- else
- {
- NRF_USBD->INTENCLR = TU_BIT(USBD_INTEN_ENDEPIN0_Pos + epnum);
- NRF_USBD->EPINEN &= ~TU_BIT(epnum);
- }
- }
- else
- {
- _dcd.xfer[EP_ISO_NUM][dir].mps = 0;
- // ISO
- if (dir == TUSB_DIR_OUT)
- {
- NRF_USBD->INTENCLR = USBD_INTENCLR_ENDISOOUT_Msk;
- NRF_USBD->EPOUTEN &= ~USBD_EPOUTEN_ISOOUT_Msk;
- NRF_USBD->EVENTS_ENDISOOUT = 0;
- }
- else
- {
- NRF_USBD->INTENCLR = USBD_INTENCLR_ENDISOIN_Msk;
- NRF_USBD->EPINEN &= ~USBD_EPINEN_ISOIN_Msk;
- }
- // One of the ISO endpoints closed, no need to split buffers any more.
- NRF_USBD->ISOSPLIT = USBD_ISOSPLIT_SPLIT_OneDir;
- // When both ISO endpoint are close there is no need for SOF any more.
- if (_dcd.xfer[EP_ISO_NUM][TUSB_DIR_IN].mps + _dcd.xfer[EP_ISO_NUM][TUSB_DIR_OUT].mps == 0) NRF_USBD->INTENCLR = USBD_INTENCLR_SOF_Msk;
- }
- __ISB(); __DSB();
-}
-
-bool dcd_edpt_xfer (uint8_t rhport, uint8_t ep_addr, uint8_t * buffer, uint16_t total_bytes)
-{
- (void) rhport;
-
- uint8_t const epnum = tu_edpt_number(ep_addr);
- uint8_t const dir = tu_edpt_dir(ep_addr);
-
- xfer_td_t* xfer = get_td(epnum, dir);
-
- xfer->buffer = buffer;
- xfer->total_len = total_bytes;
- xfer->actual_len = 0;
-
- // Control endpoint with zero-length packet and opposite direction to 1st request byte --> status stage
- bool const control_status = (epnum == 0 && total_bytes == 0 && dir != tu_edpt_dir(NRF_USBD->BMREQUESTTYPE));
-
- if ( control_status )
- {
- // Status Phase also requires EasyDMA has to be available as well !!!!
- start_ep0_task(&NRF_USBD->TASKS_EP0STATUS);
-
- // The nRF doesn't interrupt on status transmit so we queue up a success response.
- dcd_event_xfer_complete(0, ep_addr, 0, XFER_RESULT_SUCCESS, is_in_isr());
- }
- else if ( dir == TUSB_DIR_OUT )
- {
- if ( epnum == 0 )
- {
- // Accept next Control Out packet. TASKS_EP0RCVOUT also require EasyDMA
- start_ep0_task(&NRF_USBD->TASKS_EP0RCVOUT);
- }else
- {
- if ( xfer->data_received )
- {
- // Data may already be received previously
- xfer->data_received = false;
-
- // start DMA to copy to SRAM
- xact_out_dma(epnum);
- }
- else
- {
- // nRF auto accept next Bulk/Interrupt OUT packet
- // nothing to do
- }
- }
- }
- else
- {
- // Start DMA to copy data from RAM -> Endpoint
- xact_in_dma(epnum);
- }
-
- return true;
-}
-
-void dcd_edpt_stall (uint8_t rhport, uint8_t ep_addr)
-{
- (void) rhport;
- uint8_t const epnum = tu_edpt_number(ep_addr);
-
- if ( epnum == 0 )
- {
- NRF_USBD->TASKS_EP0STALL = 1;
- }else if (epnum != EP_ISO_NUM)
- {
- NRF_USBD->EPSTALL = (USBD_EPSTALL_STALL_Stall << USBD_EPSTALL_STALL_Pos) | ep_addr;
- }
-
- __ISB(); __DSB();
-}
-
-void dcd_edpt_clear_stall (uint8_t rhport, uint8_t ep_addr)
-{
- (void) rhport;
- uint8_t const epnum = tu_edpt_number(ep_addr);
- uint8_t const dir = tu_edpt_dir(ep_addr);
-
- if ( epnum != 0 && epnum != EP_ISO_NUM )
- {
- // clear stall
- NRF_USBD->EPSTALL = (USBD_EPSTALL_STALL_UnStall << USBD_EPSTALL_STALL_Pos) | ep_addr;
-
- // reset data toggle to DATA0
- NRF_USBD->DTOGGLE = (USBD_DTOGGLE_VALUE_Data0 << USBD_DTOGGLE_VALUE_Pos) | ep_addr;
-
- // Write any value to SIZE register will allow nRF to ACK/accept data
- // Drop any pending data
- if (dir == TUSB_DIR_OUT) NRF_USBD->SIZE.EPOUT[epnum] = 0;
-
- __ISB(); __DSB();
- }
-}
-
-/*------------------------------------------------------------------*/
-/* Interrupt Handler
- *------------------------------------------------------------------*/
-void bus_reset(void)
-{
- // 6.35.6 USB controller automatically disabled all endpoints (except control)
- // i.e EPOUTEN and EPINEN and reset USBADDR to 0
- for(int i=0; i<8; i++)
- {
- NRF_USBD->TASKS_STARTEPIN[i] = 0;
- NRF_USBD->TASKS_STARTEPOUT[i] = 0;
- }
-
- NRF_USBD->TASKS_STARTISOIN = 0;
- NRF_USBD->TASKS_STARTISOOUT = 0;
-
- // Clear USB Event Interrupt
- NRF_USBD->EVENTS_USBEVENT = 0;
- NRF_USBD->EVENTCAUSE |= NRF_USBD->EVENTCAUSE;
-
- // Reset interrupt
- NRF_USBD->INTENCLR = NRF_USBD->INTEN;
- NRF_USBD->INTENSET = USBD_INTEN_USBRESET_Msk | USBD_INTEN_USBEVENT_Msk | USBD_INTEN_EPDATA_Msk |
- USBD_INTEN_EP0SETUP_Msk | USBD_INTEN_EP0DATADONE_Msk | USBD_INTEN_ENDEPIN0_Msk | USBD_INTEN_ENDEPOUT0_Msk;
-
- tu_varclr(&_dcd);
- _dcd.xfer[0][TUSB_DIR_IN].mps = MAX_PACKET_SIZE;
- _dcd.xfer[0][TUSB_DIR_OUT].mps = MAX_PACKET_SIZE;
-}
-
-void dcd_int_handler(uint8_t rhport)
-{
- (void) rhport;
-
- uint32_t const inten = NRF_USBD->INTEN;
- uint32_t int_status = 0;
-
- volatile uint32_t* regevt = &NRF_USBD->EVENTS_USBRESET;
-
- for(uint8_t i=0; i<USBD_INTEN_EPDATA_Pos+1; i++)
- {
- if ( tu_bit_test(inten, i) && regevt[i] )
- {
- int_status |= TU_BIT(i);
-
- // event clear
- regevt[i] = 0;
- __ISB(); __DSB();
- }
- }
-
- if ( int_status & USBD_INTEN_USBRESET_Msk )
- {
- bus_reset();
- dcd_event_bus_reset(0, TUSB_SPEED_FULL, true);
- }
-
- // ISOIN: Data was moved to endpoint buffer, client will be notified in SOF
- if ( int_status & USBD_INTEN_ENDISOIN_Msk )
- {
- xfer_td_t* xfer = get_td(EP_ISO_NUM, TUSB_DIR_IN);
-
- xfer->actual_len = NRF_USBD->ISOIN.AMOUNT;
- // Data transferred from RAM to endpoint output buffer.
- // Next transfer can be scheduled after SOF.
- xfer->iso_in_transfer_ready = true;
- }
-
- if ( int_status & USBD_INTEN_SOF_Msk )
- {
- bool iso_enabled = false;
-
- // ISOOUT: Transfer data gathered in previous frame from buffer to RAM
- if (NRF_USBD->EPOUTEN & USBD_EPOUTEN_ISOOUT_Msk)
- {
- iso_enabled = true;
- xact_out_dma(EP_ISO_NUM);
- }
-
- // ISOIN: Notify client that data was transferred
- if (NRF_USBD->EPINEN & USBD_EPINEN_ISOIN_Msk)
- {
- iso_enabled = true;
-
- xfer_td_t* xfer = get_td(EP_ISO_NUM, TUSB_DIR_IN);
- if ( xfer->iso_in_transfer_ready )
- {
- xfer->iso_in_transfer_ready = false;
- dcd_event_xfer_complete(0, EP_ISO_NUM | TUSB_DIR_IN_MASK, xfer->actual_len, XFER_RESULT_SUCCESS, true);
- }
- }
-
- if ( !iso_enabled )
- {
- // ISO endpoint is not used, SOF is only enabled one-time for remote wakeup
- // so we disable it now
- NRF_USBD->INTENCLR = USBD_INTENSET_SOF_Msk;
- }
-
- dcd_event_bus_signal(0, DCD_EVENT_SOF, true);
- }
-
- if ( int_status & USBD_INTEN_USBEVENT_Msk )
- {
- TU_LOG(2, "EVENTCAUSE = 0x%04lX\r\n", NRF_USBD->EVENTCAUSE);
-
- enum { EVT_CAUSE_MASK = USBD_EVENTCAUSE_SUSPEND_Msk | USBD_EVENTCAUSE_RESUME_Msk | USBD_EVENTCAUSE_USBWUALLOWED_Msk };
- uint32_t const evt_cause = NRF_USBD->EVENTCAUSE & EVT_CAUSE_MASK;
- NRF_USBD->EVENTCAUSE = evt_cause; // clear interrupt
-
- if ( evt_cause & USBD_EVENTCAUSE_SUSPEND_Msk )
- {
- // Put controller into low power mode
- // Leave HFXO disable to application, since it may be used by other peripherals
- NRF_USBD->LOWPOWER = 1;
-
- dcd_event_bus_signal(0, DCD_EVENT_SUSPEND, true);
- }
-
- if ( evt_cause & USBD_EVENTCAUSE_USBWUALLOWED_Msk )
- {
- // USB is out of low power mode, and wakeup is allowed
- // Initiate RESUME signal
- NRF_USBD->DPDMVALUE = USBD_DPDMVALUE_STATE_Resume;
- NRF_USBD->TASKS_DPDMDRIVE = 1;
-
- // There is no Resume interrupt for remote wakeup, enable SOF for to report bus ready state
- // Clear SOF event in case interrupt was not enabled yet.
- if ((NRF_USBD->INTEN & USBD_INTEN_SOF_Msk) == 0) NRF_USBD->EVENTS_SOF = 0;
- NRF_USBD->INTENSET = USBD_INTENSET_SOF_Msk;
- }
-
- if ( evt_cause & USBD_EVENTCAUSE_RESUME_Msk )
- {
- dcd_event_bus_signal(0, DCD_EVENT_RESUME, true);
- }
- }
-
- // Setup tokens are specific to the Control endpoint.
- if ( int_status & USBD_INTEN_EP0SETUP_Msk )
- {
- uint8_t const setup[8] =
- {
- NRF_USBD->BMREQUESTTYPE , NRF_USBD->BREQUEST, NRF_USBD->WVALUEL , NRF_USBD->WVALUEH,
- NRF_USBD->WINDEXL , NRF_USBD->WINDEXH , NRF_USBD->WLENGTHL, NRF_USBD->WLENGTHH
- };
-
- // nrf5x hw auto handle set address, there is no need to inform usb stack
- tusb_control_request_t const * request = (tusb_control_request_t const *) setup;
-
- if ( !(TUSB_REQ_RCPT_DEVICE == request->bmRequestType_bit.recipient &&
- TUSB_REQ_TYPE_STANDARD == request->bmRequestType_bit.type &&
- TUSB_REQ_SET_ADDRESS == request->bRequest) )
- {
- dcd_event_setup_received(0, setup, true);
- }
- }
-
- if ( int_status & EDPT_END_ALL_MASK )
- {
- // DMA complete move data from SRAM -> Endpoint
- edpt_dma_end();
- }
-
- //--------------------------------------------------------------------+
- /* Control/Bulk/Interrupt (CBI) Transfer
- *
- * Data flow is:
- * (bus) (dma)
- * Host <-------> Endpoint <-------> RAM
- *
- * For CBI OUT:
- * - Host -> Endpoint
- * EPDATA (or EP0DATADONE) interrupted, check EPDATASTATUS.EPOUT[i]
- * to start DMA. For Bulk/Interrupt, this step can occur automatically (without sw),
- * which means data may or may not be ready (data_received flag).
- * - Endpoint -> RAM
- * ENDEPOUT[i] interrupted, transaction complete, sw prepare next transaction
- *
- * For CBI IN:
- * - RAM -> Endpoint
- * ENDEPIN[i] interrupted indicate DMA is complete. HW will start
- * to move data to host
- * - Endpoint -> Host
- * EPDATA (or EP0DATADONE) interrupted, check EPDATASTATUS.EPIN[i].
- * Transaction is complete, sw prepare next transaction
- *
- * Note: in both Control In and Out of Data stage from Host <-> Endpoint
- * EP0DATADONE will be set as interrupt source
- */
- //--------------------------------------------------------------------+
-
- /* CBI OUT: Endpoint -> SRAM (aka transaction complete)
- * Note: Since nRF controller auto ACK next packet without SW awareness
- * We must handle this stage before Host -> Endpoint just in case 2 event happens at once
- *
- * ISO OUT: Transaction must fit in single packet, it can be shorter then total
- * len if Host decides to sent fewer bytes, it this case transaction is also
- * complete and next transfer is not initiated here like for CBI.
- */
- for(uint8_t epnum=0; epnum<EP_CBI_COUNT+1; epnum++)
- {
- if ( tu_bit_test(int_status, USBD_INTEN_ENDEPOUT0_Pos+epnum))
- {
- xfer_td_t* xfer = get_td(epnum, TUSB_DIR_OUT);
- uint8_t const xact_len = NRF_USBD->EPOUT[epnum].AMOUNT;
-
- // Transfer complete if transaction len < Max Packet Size or total len is transferred
- if ( (epnum != EP_ISO_NUM) && (xact_len == xfer->mps) && (xfer->actual_len < xfer->total_len) )
- {
- if ( epnum == 0 )
- {
- // Accept next Control Out packet. TASKS_EP0RCVOUT also require EasyDMA
- if ( _dcd.dma_pending )
- {
- // use usbd task to defer later
- usbd_defer_func( (osal_task_func_t) start_ep0_task, (void*) &NRF_USBD->TASKS_EP0RCVOUT, true );
- }else
- {
- start_ep0_task(&NRF_USBD->TASKS_EP0RCVOUT);
- }
- }else
- {
- // nRF auto accept next Bulk/Interrupt OUT packet
- // nothing to do
- }
- }else
- {
- xfer->total_len = xfer->actual_len;
-
- // CBI OUT complete
- dcd_event_xfer_complete(0, epnum, xfer->actual_len, XFER_RESULT_SUCCESS, true);
- }
- }
-
- // Ended event for CBI IN : nothing to do
- }
-
- // Endpoint <-> Host ( In & OUT )
- if ( int_status & (USBD_INTEN_EPDATA_Msk | USBD_INTEN_EP0DATADONE_Msk) )
- {
- uint32_t data_status = NRF_USBD->EPDATASTATUS;
- NRF_USBD->EPDATASTATUS = data_status;
- __ISB(); __DSB();
-
- // EP0DATADONE is set with either Control Out on IN Data
- // Since EPDATASTATUS cannot be used to determine whether it is control OUT or IN.
- // We will use BMREQUESTTYPE in setup packet to determine the direction
- bool const is_control_in = (int_status & USBD_INTEN_EP0DATADONE_Msk) && (NRF_USBD->BMREQUESTTYPE & TUSB_DIR_IN_MASK);
- bool const is_control_out = (int_status & USBD_INTEN_EP0DATADONE_Msk) && !(NRF_USBD->BMREQUESTTYPE & TUSB_DIR_IN_MASK);
-
- // CBI In: Endpoint -> Host (transaction complete)
- for(uint8_t epnum=0; epnum<EP_CBI_COUNT; epnum++)
- {
- if ( tu_bit_test(data_status, epnum) || (epnum == 0 && is_control_in) )
- {
- xfer_td_t* xfer = get_td(epnum, TUSB_DIR_IN);
-
- xfer->actual_len += NRF_USBD->EPIN[epnum].MAXCNT;
-
- if ( xfer->actual_len < xfer->total_len )
- {
- // Start DMA to copy next data packet
- xact_in_dma(epnum);
- } else
- {
- // CBI IN complete
- dcd_event_xfer_complete(0, epnum | TUSB_DIR_IN_MASK, xfer->actual_len, XFER_RESULT_SUCCESS, true);
- }
- }
- }
-
- // CBI OUT: Host -> Endpoint
- for(uint8_t epnum=0; epnum<EP_CBI_COUNT; epnum++)
- {
- if ( tu_bit_test(data_status, 16+epnum) || (epnum == 0 && is_control_out) )
- {
- xfer_td_t* xfer = get_td(epnum, TUSB_DIR_OUT);
-
- if (xfer->actual_len < xfer->total_len)
- {
- xact_out_dma(epnum);
- }else
- {
- // Data overflow !!! Nah, nRF will auto accept next Bulk/Interrupt OUT packet
- // Mark this endpoint with data received
- xfer->data_received = true;
- }
- }
- }
- }
-}
-
-//--------------------------------------------------------------------+
-// HFCLK helper
-//--------------------------------------------------------------------+
-#ifdef SOFTDEVICE_PRESENT
-
-// For enable/disable hfclk with SoftDevice
-#include "nrf_mbr.h"
-#include "nrf_sdm.h"
-#include "nrf_soc.h"
-
-#ifndef SD_MAGIC_NUMBER
- #define SD_MAGIC_NUMBER 0x51B1E5DB
-#endif
-
-static inline bool is_sd_existed(void)
-{
- return *((uint32_t*)(SOFTDEVICE_INFO_STRUCT_ADDRESS+4)) == SD_MAGIC_NUMBER;
-}
-
-// check if SD is existed and enabled
-static inline bool is_sd_enabled(void)
-{
- if ( !is_sd_existed() ) return false;
-
- uint8_t sd_en = false;
- (void) sd_softdevice_is_enabled(&sd_en);
- return sd_en;
-}
-#endif
-
-static bool hfclk_running(void)
-{
-#ifdef SOFTDEVICE_PRESENT
- if ( is_sd_enabled() )
- {
- uint32_t is_running = 0;
- (void) sd_clock_hfclk_is_running(&is_running);
- return (is_running ? true : false);
- }
-#endif
-
- return nrf_clock_hf_is_running(NRF_CLOCK, NRF_CLOCK_HFCLK_HIGH_ACCURACY);
-}
-
-static void hfclk_enable(void)
-{
- // already running, nothing to do
- if ( hfclk_running() ) return;
-
-#ifdef SOFTDEVICE_PRESENT
- if ( is_sd_enabled() )
- {
- (void)sd_clock_hfclk_request();
- return;
- }
-#endif
-
- nrf_clock_event_clear(NRF_CLOCK, NRF_CLOCK_EVENT_HFCLKSTARTED);
- nrf_clock_task_trigger(NRF_CLOCK, NRF_CLOCK_TASK_HFCLKSTART);
-}
-
-static void hfclk_disable(void)
-{
-#ifdef SOFTDEVICE_PRESENT
- if ( is_sd_enabled() )
- {
- (void)sd_clock_hfclk_release();
- return;
- }
-#endif
-
- nrf_clock_task_trigger(NRF_CLOCK, NRF_CLOCK_TASK_HFCLKSTOP);
-}
-
-// Power & Clock Peripheral on nRF5x to manage USB
-//
-// USB Bus power is managed by Power module, there are 3 VBUS power events:
-// Detected, Ready, Removed. Upon these power events, This function will
-// enable ( or disable ) usb & hfclk peripheral, set the usb pin pull up
-// accordingly to the controller Startup/Standby Sequence in USBD 51.4 specs.
-//
-// Therefore this function must be called to handle USB power event by
-// - nrfx_power_usbevt_init() : if Softdevice is not used or enabled
-// - SoftDevice SOC event : if SD is used and enabled
-void tusb_hal_nrf_power_event (uint32_t event)
-{
- // Value is chosen to be as same as NRFX_POWER_USB_EVT_* in nrfx_power.h
- enum {
- USB_EVT_DETECTED = 0,
- USB_EVT_REMOVED = 1,
- USB_EVT_READY = 2
- };
-
-#if CFG_TUSB_DEBUG >= 2
- const char* const power_evt_str[] = { "Detected", "Removed", "Ready" };
- TU_LOG(2, "Power USB event: %s\r\n", power_evt_str[event]);
-#endif
-
- switch ( event )
- {
- case USB_EVT_DETECTED:
- if ( !NRF_USBD->ENABLE )
- {
- // Prepare for receiving READY event: disable interrupt since we will blocking wait
- NRF_USBD->INTENCLR = USBD_INTEN_USBEVENT_Msk;
- NRF_USBD->EVENTCAUSE = USBD_EVENTCAUSE_READY_Msk;
- __ISB(); __DSB(); // for sync
-
-#ifdef NRF52_SERIES // NRF53 does not need this errata
- // ERRATA 171, 187, 166
- if ( nrfx_usbd_errata_187() )
- {
- // CRITICAL_REGION_ENTER();
- if ( *((volatile uint32_t *) (0x4006EC00)) == 0x00000000 )
- {
- *((volatile uint32_t *) (0x4006EC00)) = 0x00009375;
- *((volatile uint32_t *) (0x4006ED14)) = 0x00000003;
- *((volatile uint32_t *) (0x4006EC00)) = 0x00009375;
- }
- else
- {
- *((volatile uint32_t *) (0x4006ED14)) = 0x00000003;
- }
- // CRITICAL_REGION_EXIT();
- }
-
- if ( nrfx_usbd_errata_171() )
- {
- // CRITICAL_REGION_ENTER();
- if ( *((volatile uint32_t *) (0x4006EC00)) == 0x00000000 )
- {
- *((volatile uint32_t *) (0x4006EC00)) = 0x00009375;
- *((volatile uint32_t *) (0x4006EC14)) = 0x000000C0;
- *((volatile uint32_t *) (0x4006EC00)) = 0x00009375;
- }
- else
- {
- *((volatile uint32_t *) (0x4006EC14)) = 0x000000C0;
- }
- // CRITICAL_REGION_EXIT();
- }
-#endif
-
- // Enable the peripheral (will cause Ready event)
- NRF_USBD->ENABLE = 1;
- __ISB(); __DSB(); // for sync
-
- // Enable HFCLK
- hfclk_enable();
- }
- break;
-
- case USB_EVT_READY:
- // Skip if pull-up is enabled and HCLK is already running.
- // Application probably call this more than necessary.
- if ( NRF_USBD->USBPULLUP && hfclk_running() ) break;
-
- // Waiting for USBD peripheral enabled
- while ( !(USBD_EVENTCAUSE_READY_Msk & NRF_USBD->EVENTCAUSE) ) { }
-
- NRF_USBD->EVENTCAUSE = USBD_EVENTCAUSE_READY_Msk;
- __ISB(); __DSB(); // for sync
-
-#ifdef NRF52_SERIES
- if ( nrfx_usbd_errata_171() )
- {
- // CRITICAL_REGION_ENTER();
- if ( *((volatile uint32_t *) (0x4006EC00)) == 0x00000000 )
- {
- *((volatile uint32_t *) (0x4006EC00)) = 0x00009375;
- *((volatile uint32_t *) (0x4006EC14)) = 0x00000000;
- *((volatile uint32_t *) (0x4006EC00)) = 0x00009375;
- }
- else
- {
- *((volatile uint32_t *) (0x4006EC14)) = 0x00000000;
- }
-
- // CRITICAL_REGION_EXIT();
- }
-
- if ( nrfx_usbd_errata_187() )
- {
- // CRITICAL_REGION_ENTER();
- if ( *((volatile uint32_t *) (0x4006EC00)) == 0x00000000 )
- {
- *((volatile uint32_t *) (0x4006EC00)) = 0x00009375;
- *((volatile uint32_t *) (0x4006ED14)) = 0x00000000;
- *((volatile uint32_t *) (0x4006EC00)) = 0x00009375;
- }
- else
- {
- *((volatile uint32_t *) (0x4006ED14)) = 0x00000000;
- }
- // CRITICAL_REGION_EXIT();
- }
-
- if ( nrfx_usbd_errata_166() )
- {
- *((volatile uint32_t *) (NRF_USBD_BASE + 0x800)) = 0x7E3;
- *((volatile uint32_t *) (NRF_USBD_BASE + 0x804)) = 0x40;
-
- __ISB(); __DSB();
- }
-#endif
-
- // ISO buffer Lower half for IN, upper half for OUT
- NRF_USBD->ISOSPLIT = USBD_ISOSPLIT_SPLIT_HalfIN;
-
- // Enable bus-reset interrupt
- NRF_USBD->INTENSET = USBD_INTEN_USBRESET_Msk;
-
- // Enable interrupt, priorities should be set by application
- NVIC_ClearPendingIRQ(USBD_IRQn);
- NVIC_EnableIRQ(USBD_IRQn);
-
- // Wait for HFCLK
- while ( !hfclk_running() ) { }
-
- // Enable pull up
- NRF_USBD->USBPULLUP = 1;
- __ISB(); __DSB(); // for sync
- break;
-
- case USB_EVT_REMOVED:
- if ( NRF_USBD->ENABLE )
- {
- // Abort all transfers
-
- // Disable pull up
- NRF_USBD->USBPULLUP = 0;
- __ISB(); __DSB(); // for sync
-
- // Disable Interrupt
- NVIC_DisableIRQ(USBD_IRQn);
-
- // disable all interrupt
- NRF_USBD->INTENCLR = NRF_USBD->INTEN;
-
- NRF_USBD->ENABLE = 0;
- __ISB(); __DSB(); // for sync
-
- hfclk_disable();
-
- dcd_event_bus_signal(0, DCD_EVENT_UNPLUGGED, is_in_isr());
- }
- break;
-
- default: break;
- }
-}
-
-#endif
diff --git a/tinyusb/src/portable/nuvoton/nuc120/dcd_nuc120.c b/tinyusb/src/portable/nuvoton/nuc120/dcd_nuc120.c
deleted file mode 100755
index 57cc76e8..00000000
--- a/tinyusb/src/portable/nuvoton/nuc120/dcd_nuc120.c
+++ /dev/null
@@ -1,494 +0,0 @@
-/*
- * The MIT License (MIT)
- *
- * Copyright (c) 2019-2020 Peter Lawrence
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- *
- * This file is part of the TinyUSB stack.
- */
-
-/*
- Theory of operation:
-
- The NUC100/NUC120 USBD peripheral has six "EP"s, but each is simplex,
- so two collectively (peripheral nomenclature of "EP0" and "EP1") are needed to
- implement USB EP0. PERIPH_EP0 and PERIPH_EP1 are used by this driver for
- EP0_IN and EP0_OUT respectively. This leaves up to four for user usage.
-*/
-
-#include "tusb_option.h"
-
-#if TUSB_OPT_DEVICE_ENABLED && (CFG_TUSB_MCU == OPT_MCU_NUC120)
-
-#include "device/dcd.h"
-#include "NUC100Series.h"
-
-/* allocation of USBD RAM for Setup, EP0_IN, and and EP_OUT */
-#define PERIPH_SETUP_BUF_BASE 0
-#define PERIPH_SETUP_BUF_LEN 8
-#define PERIPH_EP0_BUF_BASE (PERIPH_SETUP_BUF_BASE + PERIPH_SETUP_BUF_LEN)
-#define PERIPH_EP0_BUF_LEN CFG_TUD_ENDPOINT0_SIZE
-#define PERIPH_EP1_BUF_BASE (PERIPH_EP0_BUF_BASE + PERIPH_EP0_BUF_LEN)
-#define PERIPH_EP1_BUF_LEN CFG_TUD_ENDPOINT0_SIZE
-#define PERIPH_EP2_BUF_BASE (PERIPH_EP1_BUF_BASE + PERIPH_EP1_BUF_LEN)
-
-/* rather important info unfortunately not provided by device include files: how much there is */
-#define USBD_BUF_SIZE 512
-
-enum ep_enum
-{
- PERIPH_EP0 = 0,
- PERIPH_EP1 = 1,
- PERIPH_EP2 = 2,
- PERIPH_EP3 = 3,
- PERIPH_EP4 = 4,
- PERIPH_EP5 = 5,
- PERIPH_MAX_EP,
-};
-
-/* set by dcd_set_address() */
-static volatile uint8_t assigned_address;
-
-/* reset by dcd_init(), this is used by dcd_edpt_open() to assign USBD peripheral buffer addresses */
-static uint32_t bufseg_addr;
-
-/* used by dcd_edpt_xfer() and the ISR to reset the data sync (DATA0/DATA1) in an EP0_IN transfer */
-static bool active_ep0_xfer;
-
-/* RAM table needed to track ongoing transfers performed by dcd_edpt_xfer(), dcd_in_xfer(), and the ISR */
-static struct xfer_ctl_t
-{
- uint8_t *data_ptr; /* data_ptr tracks where to next copy data to (for OUT) or from (for IN) */
- // tu_fifo_t * ff; /* pointer to FIFO required for dcd_edpt_xfer_fifo() */ // TODO support dcd_edpt_xfer_fifo API
- union {
- uint16_t in_remaining_bytes; /* for IN endpoints, we track how many bytes are left to transfer */
- uint16_t out_bytes_so_far; /* but for OUT endpoints, we track how many bytes we've transferred so far */
- };
- uint16_t max_packet_size; /* needed since device driver only finds out this at runtime */
- uint16_t total_bytes; /* quantity needed to pass as argument to dcd_event_xfer_complete() (for IN endpoints) */
-} xfer_table[PERIPH_MAX_EP];
-
-/*
- local helper functions
-*/
-
-static void usb_attach(void)
-{
- USBD->DRVSE0 &= ~USBD_DRVSE0_DRVSE0_Msk;
-}
-
-static void usb_detach(void)
-{
- USBD->DRVSE0 |= USBD_DRVSE0_DRVSE0_Msk;
-}
-
-static inline void usb_memcpy(uint8_t *dest, uint8_t *src, uint16_t size)
-{
- while(size--) *dest++ = *src++;
-}
-
-static void usb_control_send_zlp(void)
-{
- USBD->EP[PERIPH_EP0].CFG |= USBD_CFG_DSQ_SYNC_Msk;
- USBD->EP[PERIPH_EP0].MXPLD = 0;
-}
-
-/* reconstruct ep_addr from particular USB Configuration Register */
-static uint8_t decode_ep_addr(USBD_EP_T *ep)
-{
- uint8_t ep_addr = ep->CFG & USBD_CFG_EP_NUM_Msk;
- if ( USBD_CFG_EPMODE_IN == (ep->CFG & USBD_CFG_STATE_Msk) )
- ep_addr |= TUSB_DIR_IN_MASK;
- return ep_addr;
-}
-
-/* map 8-bit ep_addr into peripheral endpoint index (PERIPH_EP0...) */
-static USBD_EP_T *ep_entry(uint8_t ep_addr, bool add)
-{
- USBD_EP_T *ep;
- enum ep_enum ep_index;
-
- for (ep_index = PERIPH_EP0, ep = USBD->EP; ep_index < PERIPH_MAX_EP; ep_index++, ep++)
- {
- if (add)
- {
- /* take first peripheral endpoint that is unused */
- if (0 == (ep->CFG & USBD_CFG_STATE_Msk)) return ep;
- }
- else
- {
- /* find a peripheral endpoint that matches ep_addr */
- uint8_t candidate_ep_addr = decode_ep_addr(ep);
- if (candidate_ep_addr == ep_addr) return ep;
- }
- }
-
- return NULL;
-}
-
-/* perform an IN endpoint transfer; this is called by dcd_edpt_xfer() and the ISR */
-static void dcd_in_xfer(struct xfer_ctl_t *xfer, USBD_EP_T *ep)
-{
- uint16_t bytes_now = tu_min16(xfer->in_remaining_bytes, xfer->max_packet_size);
-
-#if 0 // TODO support dcd_edpt_xfer_fifo API
- if (xfer->ff)
- {
- tu_fifo_read_n(xfer->ff, (void *) (USBD_BUF_BASE + ep->BUFSEG), bytes_now);
- }
- else
-#endif
- {
- // USB SRAM seems to only support byte access and memcpy could possibly do it by words
- usb_memcpy((uint8_t *)(USBD_BUF_BASE + ep->BUFSEG), xfer->data_ptr, bytes_now);
- }
-
- ep->MXPLD = bytes_now;
-}
-
-/* called by dcd_init() as well as by the ISR during a USB bus reset */
-static void bus_reset(void)
-{
- USBD->STBUFSEG = PERIPH_SETUP_BUF_BASE;
-
- for (enum ep_enum ep_index = PERIPH_EP0; ep_index < PERIPH_MAX_EP; ep_index++)
- {
- USBD->EP[ep_index].CFG = 0;
- USBD->EP[ep_index].CFGP = 0;
- }
-
- /* allocate the default EP0 endpoints */
-
- USBD->EP[PERIPH_EP0].CFG = USBD_CFG_CSTALL_Msk | USBD_CFG_EPMODE_IN;
- USBD->EP[PERIPH_EP0].BUFSEG = PERIPH_EP0_BUF_BASE;
- xfer_table[PERIPH_EP0].max_packet_size = PERIPH_EP0_BUF_LEN;
-
- USBD->EP[PERIPH_EP1].CFG = USBD_CFG_CSTALL_Msk | USBD_CFG_EPMODE_OUT;
- USBD->EP[PERIPH_EP1].BUFSEG = PERIPH_EP1_BUF_BASE;
- xfer_table[PERIPH_EP1].max_packet_size = PERIPH_EP1_BUF_LEN;
-
- /* USB RAM beyond what we've allocated above is available to the user */
- bufseg_addr = PERIPH_EP2_BUF_BASE;
-
- /* Reset USB device address */
- USBD->FADDR = 0;
-
- /* reset EP0_IN flag */
- active_ep0_xfer = false;
-}
-
-/* centralized location for USBD interrupt enable bit mask */
-static const uint32_t enabled_irqs = USBD_INTSTS_FLDET_STS_Msk | USBD_INTSTS_BUS_STS_Msk | USBD_INTSTS_SETUP_Msk | USBD_INTSTS_USB_STS_Msk;
-
-/*
- NUC100/NUC120 TinyUSB API driver implementation
-*/
-
-void dcd_init(uint8_t rhport)
-{
- (void) rhport;
-
- USBD->ATTR = 0x7D0;
-
- usb_detach();
-
- bus_reset();
-
- usb_attach();
-
- USBD->INTSTS = enabled_irqs;
- USBD->INTEN = enabled_irqs;
-}
-
-void dcd_int_enable(uint8_t rhport)
-{
- (void) rhport;
- NVIC_EnableIRQ(USBD_IRQn);
-}
-
-void dcd_int_disable(uint8_t rhport)
-{
- (void) rhport;
- NVIC_DisableIRQ(USBD_IRQn);
-}
-
-void dcd_set_address(uint8_t rhport, uint8_t dev_addr)
-{
- (void) rhport;
- usb_control_send_zlp(); /* SET_ADDRESS is the one exception where TinyUSB doesn't use dcd_edpt_xfer() to generate a ZLP */
- assigned_address = dev_addr;
-}
-
-void dcd_remote_wakeup(uint8_t rhport)
-{
- (void) rhport;
- USBD->ATTR = USBD_ATTR_RWAKEUP_Msk;
-}
-
-bool dcd_edpt_open(uint8_t rhport, tusb_desc_endpoint_t const * p_endpoint_desc)
-{
- (void) rhport;
-
- USBD_EP_T *ep = ep_entry(p_endpoint_desc->bEndpointAddress, true);
- TU_ASSERT(ep);
-
- /* mine the data for the information we need */
- int const dir = tu_edpt_dir(p_endpoint_desc->bEndpointAddress);
- int const size = p_endpoint_desc->wMaxPacketSize.size;
- tusb_xfer_type_t const type = (tusb_xfer_type_t) p_endpoint_desc->bmAttributes.xfer;
- struct xfer_ctl_t *xfer = &xfer_table[ep - USBD->EP];
-
- /* allocate buffer from USB RAM */
- ep->BUFSEG = bufseg_addr;
- bufseg_addr += size;
- TU_ASSERT(bufseg_addr <= USBD_BUF_SIZE);
-
- /* construct USB Configuration Register value and then write it */
- uint32_t cfg = tu_edpt_number(p_endpoint_desc->bEndpointAddress);
- cfg |= (TUSB_DIR_IN == dir) ? USBD_CFG_EPMODE_IN : USBD_CFG_EPMODE_OUT;
- if (TUSB_XFER_ISOCHRONOUS == type)
- cfg |= USBD_CFG_TYPE_ISO;
- ep->CFG = cfg;
-
- /* make a note of the endpoint size */
- xfer->max_packet_size = size;
-
- return true;
-}
-
-bool dcd_edpt_xfer(uint8_t rhport, uint8_t ep_addr, uint8_t *buffer, uint16_t total_bytes)
-{
- (void) rhport;
-
- /* mine the data for the information we need */
- tusb_dir_t dir = tu_edpt_dir(ep_addr);
- USBD_EP_T *ep = ep_entry(ep_addr, false);
- struct xfer_ctl_t *xfer = &xfer_table[ep - USBD->EP];
-
- /* store away the information we'll needing now and later */
- xfer->data_ptr = buffer;
- // xfer->ff = NULL; // TODO support dcd_edpt_xfer_fifo API
- xfer->in_remaining_bytes = total_bytes;
- xfer->total_bytes = total_bytes;
-
- /* for the first of one or more EP0_IN packets in a message, the first must be DATA1 */
- if ( (0x80 == ep_addr) && !active_ep0_xfer ) ep->CFG |= USBD_CFG_DSQ_SYNC_Msk;
-
- if (TUSB_DIR_IN == dir)
- {
- dcd_in_xfer(xfer, ep);
- }
- else
- {
- xfer->out_bytes_so_far = 0;
- ep->MXPLD = xfer->max_packet_size;
- }
-
- return true;
-}
-
-#if 0 // TODO support dcd_edpt_xfer_fifo API
-bool dcd_edpt_xfer_fifo (uint8_t rhport, uint8_t ep_addr, tu_fifo_t * ff, uint16_t total_bytes)
-{
- (void) rhport;
-
- /* mine the data for the information we need */
- tusb_dir_t dir = tu_edpt_dir(ep_addr);
- USBD_EP_T *ep = ep_entry(ep_addr, false);
- struct xfer_ctl_t *xfer = &xfer_table[ep - USBD->EP];
-
- /* store away the information we'll needing now and later */
- xfer->data_ptr = NULL; // Indicates a FIFO shall be used
- xfer->ff = ff;
- xfer->in_remaining_bytes = total_bytes;
- xfer->total_bytes = total_bytes;
-
- if (TUSB_DIR_IN == dir)
- {
- dcd_in_xfer(xfer, ep);
- }
- else
- {
- xfer->out_bytes_so_far = 0;
- ep->MXPLD = xfer->max_packet_size;
- }
-
- return true;
-}
-#endif
-
-void dcd_edpt_stall(uint8_t rhport, uint8_t ep_addr)
-{
- (void) rhport;
- USBD_EP_T *ep = ep_entry(ep_addr, false);
- ep->CFGP |= USBD_CFGP_SSTALL_Msk;
-}
-
-void dcd_edpt_clear_stall(uint8_t rhport, uint8_t ep_addr)
-{
- (void) rhport;
- USBD_EP_T *ep = ep_entry(ep_addr, false);
- ep->CFG |= USBD_CFG_CSTALL_Msk;
-}
-
-void dcd_int_handler(uint8_t rhport)
-{
- (void) rhport;
-
- uint32_t status = USBD->INTSTS;
- uint32_t state = USBD->ATTR & 0xf;
-
- if(status & USBD_INTSTS_FLDET_STS_Msk)
- {
- if(USBD->FLDET & USBD_FLDET_FLDET_Msk)
- {
- /* USB connect */
- USBD->ATTR |= USBD_ATTR_USB_EN_Msk | USBD_ATTR_PHY_EN_Msk;
- }
- else
- {
- /* USB disconnect */
- USBD->ATTR &= ~USBD_ATTR_USB_EN_Msk;
- }
- }
-
- if(status & USBD_INTSTS_BUS_STS_Msk)
- {
- if(state & USBD_STATE_USBRST)
- {
- /* USB bus reset */
- USBD->ATTR |= USBD_ATTR_USB_EN_Msk | USBD_ATTR_PHY_EN_Msk;
-
- bus_reset();
- dcd_event_bus_reset(0, TUSB_SPEED_FULL, true);
- }
-
- if(state & USBD_STATE_SUSPEND)
- {
- /* Enable USB but disable PHY */
- USBD->ATTR &= ~USBD_ATTR_PHY_EN_Msk;
- dcd_event_bus_signal(0, DCD_EVENT_SUSPEND, true);
- }
-
- if(state & USBD_STATE_RESUME)
- {
- /* Enable USB and enable PHY */
- USBD->ATTR |= USBD_ATTR_USB_EN_Msk | USBD_ATTR_PHY_EN_Msk;
- dcd_event_bus_signal(0, DCD_EVENT_RESUME, true);
- }
- }
-
- if(status & USBD_INTSTS_SETUP_Msk)
- {
- /* clear the data ready flag of control endpoints */
- USBD->EP[PERIPH_EP0].CFGP |= USBD_CFGP_CLRRDY_Msk;
- USBD->EP[PERIPH_EP1].CFGP |= USBD_CFGP_CLRRDY_Msk;
-
- /* get SETUP packet from USB buffer */
- dcd_event_setup_received(0, (uint8_t *)USBD_BUF_BASE, true);
- }
-
- if(status & USBD_INTSTS_USB_STS_Msk)
- {
- if (status & (1UL << USBD_INTSTS_EPEVT_Pos)) /* PERIPH_EP0 (EP0_IN) event: this is treated separately from the rest */
- {
- /* given ACK from host has happened, we can now set the address (if not already done) */
- if((USBD->FADDR != assigned_address) && (USBD->FADDR == 0)) USBD->FADDR = assigned_address;
-
- uint16_t const available_bytes = USBD->EP[PERIPH_EP0].MXPLD;
-
- active_ep0_xfer = (available_bytes == xfer_table[PERIPH_EP0].max_packet_size);
-
- dcd_event_xfer_complete(0, 0x80, available_bytes, XFER_RESULT_SUCCESS, true);
- }
-
- /* service PERIPH_EP1 through PERIPH_EP7 */
- enum ep_enum ep_index;
- uint32_t mask;
- struct xfer_ctl_t *xfer;
- USBD_EP_T *ep;
- for (ep_index = PERIPH_EP1, mask = (2UL << USBD_INTSTS_EPEVT_Pos), xfer = &xfer_table[PERIPH_EP1], ep = &USBD->EP[PERIPH_EP1]; ep_index < PERIPH_MAX_EP; ep_index++, mask <<= 1, xfer++, ep++)
- {
- if(status & mask)
- {
- USBD->INTSTS = mask;
-
- uint16_t const available_bytes = ep->MXPLD;
- uint8_t const ep_addr = decode_ep_addr(ep);
- bool const out_ep = !(ep_addr & TUSB_DIR_IN_MASK);
-
- if (out_ep)
- {
- /* copy the data from the PC to the previously provided buffer */
-#if 0 // // TODO support dcd_edpt_xfer_fifo API
- if (xfer->ff)
- {
- tu_fifo_write_n(xfer->ff, (const void *) (USBD_BUF_BASE + ep->BUFSEG), available_bytes);
- }
- else
-#endif
- {
- // USB SRAM seems to only support byte access and memcpy could possibly do it by words
- usb_memcpy(xfer->data_ptr, (uint8_t *)(USBD_BUF_BASE + ep->BUFSEG), available_bytes);
- xfer->data_ptr += available_bytes;
- }
-
- xfer->out_bytes_so_far += available_bytes;
-
- /* when the transfer is finished, alert TinyUSB; otherwise, accept more data */
- if ( (xfer->total_bytes == xfer->out_bytes_so_far) || (available_bytes < xfer->max_packet_size) )
- dcd_event_xfer_complete(0, ep_addr, xfer->out_bytes_so_far, XFER_RESULT_SUCCESS, true);
- else
- ep->MXPLD = xfer->max_packet_size;
- }
- else
- {
- /* update the bookkeeping to reflect the data that has now been sent to the PC */
- xfer->in_remaining_bytes -= available_bytes;
-
- xfer->data_ptr += available_bytes;
-
- /* if more data to send, send it; otherwise, alert TinyUSB that we've finished */
- if (xfer->in_remaining_bytes)
- dcd_in_xfer(xfer, ep);
- else
- dcd_event_xfer_complete(0, ep_addr, xfer->total_bytes, XFER_RESULT_SUCCESS, true);
- }
- }
- }
- }
-
- /* acknowledge all interrupts */
- USBD->INTSTS = status & enabled_irqs;
-}
-
-void dcd_disconnect(uint8_t rhport)
-{
- (void) rhport;
- usb_detach();
-}
-
-void dcd_connect(uint8_t rhport)
-{
- (void) rhport;
- usb_attach();
-}
-
-#endif
diff --git a/tinyusb/src/portable/nuvoton/nuc121/dcd_nuc121.c b/tinyusb/src/portable/nuvoton/nuc121/dcd_nuc121.c
deleted file mode 100755
index a776e46f..00000000
--- a/tinyusb/src/portable/nuvoton/nuc121/dcd_nuc121.c
+++ /dev/null
@@ -1,534 +0,0 @@
-/*
- * The MIT License (MIT)
- *
- * Copyright (c) 2019 Peter Lawrence
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- *
- * This file is part of the TinyUSB stack.
- */
-
-/*
- Theory of operation:
-
- The NUC121/NUC125/NUC126 USBD peripheral has eight "EP"s, but each is simplex,
- so two collectively (peripheral nomenclature of "EP0" and "EP1") are needed to
- implement USB EP0. PERIPH_EP0 and PERIPH_EP1 are used by this driver for
- EP0_IN and EP0_OUT respectively. This leaves up to six for user usage.
-*/
-
-#include "tusb_option.h"
-
-#if TUSB_OPT_DEVICE_ENABLED && ( (CFG_TUSB_MCU == OPT_MCU_NUC121) || (CFG_TUSB_MCU == OPT_MCU_NUC126) )
-
-#include "device/dcd.h"
-#include "NuMicro.h"
-
-// Since TinyUSB doesn't use SOF for now, and this interrupt too often (1ms interval)
-// We disable SOF for now until needed later on
-#ifndef USE_SOF
-# define USE_SOF 0
-#endif
-
-/* allocation of USBD RAM for Setup, EP0_IN, and and EP_OUT */
-#define PERIPH_SETUP_BUF_BASE 0
-#define PERIPH_SETUP_BUF_LEN 8
-#define PERIPH_EP0_BUF_BASE (PERIPH_SETUP_BUF_BASE + PERIPH_SETUP_BUF_LEN)
-#define PERIPH_EP0_BUF_LEN CFG_TUD_ENDPOINT0_SIZE
-#define PERIPH_EP1_BUF_BASE (PERIPH_EP0_BUF_BASE + PERIPH_EP0_BUF_LEN)
-#define PERIPH_EP1_BUF_LEN CFG_TUD_ENDPOINT0_SIZE
-#define PERIPH_EP2_BUF_BASE (PERIPH_EP1_BUF_BASE + PERIPH_EP1_BUF_LEN)
-
-/* rather important info unfortunately not provided by device include files: how much there is */
-#define USBD_BUF_SIZE ((CFG_TUSB_MCU == OPT_MCU_NUC121) ? 768 : 512)
-
-enum ep_enum
-{
- PERIPH_EP0 = 0,
- PERIPH_EP1 = 1,
- PERIPH_EP2 = 2,
- PERIPH_EP3 = 3,
- PERIPH_EP4 = 4,
- PERIPH_EP5 = 5,
- PERIPH_EP6 = 6,
- PERIPH_EP7 = 7,
- PERIPH_MAX_EP,
-};
-
-/* reset by dcd_init(), this is used by dcd_edpt_open() to assign USBD peripheral buffer addresses */
-static uint32_t bufseg_addr;
-
-/* used by dcd_edpt_xfer() and the ISR to reset the data sync (DATA0/DATA1) in an EP0_IN transfer */
-static bool active_ep0_xfer;
-
-/* RAM table needed to track ongoing transfers performed by dcd_edpt_xfer(), dcd_in_xfer(), and the ISR */
-static struct xfer_ctl_t
-{
- uint8_t *data_ptr; /* data_ptr tracks where to next copy data to (for OUT) or from (for IN) */
- // tu_fifo_t * ff; // TODO support dcd_edpt_xfer_fifo API
- union {
- uint16_t in_remaining_bytes; /* for IN endpoints, we track how many bytes are left to transfer */
- uint16_t out_bytes_so_far; /* but for OUT endpoints, we track how many bytes we've transferred so far */
- };
- uint16_t max_packet_size; /* needed since device driver only finds out this at runtime */
- uint16_t total_bytes; /* quantity needed to pass as argument to dcd_event_xfer_complete() (for IN endpoints) */
-} xfer_table[PERIPH_MAX_EP];
-
-/*
- local helper functions
-*/
-
-static void usb_attach(void)
-{
- USBD->SE0 &= ~USBD_SE0_SE0_Msk;
-}
-
-static void usb_detach(void)
-{
- USBD->SE0 |= USBD_SE0_SE0_Msk;
-}
-
-static inline void usb_memcpy(uint8_t *dest, uint8_t *src, uint16_t size)
-{
- while(size--) *dest++ = *src++;
-}
-
-static void usb_control_send_zlp(void)
-{
- USBD->EP[PERIPH_EP0].CFG |= USBD_CFG_DSQSYNC_Msk;
- USBD->EP[PERIPH_EP0].MXPLD = 0;
-}
-
-/* reconstruct ep_addr from particular USB Configuration Register */
-static uint8_t decode_ep_addr(USBD_EP_T *ep)
-{
- uint8_t ep_addr = ep->CFG & USBD_CFG_EPNUM_Msk;
- if ( USBD_CFG_EPMODE_IN == (ep->CFG & USBD_CFG_STATE_Msk) )
- ep_addr |= TUSB_DIR_IN_MASK;
- return ep_addr;
-}
-
-/* map 8-bit ep_addr into peripheral endpoint index (PERIPH_EP0...) */
-static USBD_EP_T *ep_entry(uint8_t ep_addr, bool add)
-{
- USBD_EP_T *ep;
- enum ep_enum ep_index;
-
- for (ep_index = PERIPH_EP0, ep = USBD->EP; ep_index < PERIPH_MAX_EP; ep_index++, ep++)
- {
- if (add)
- {
- /* take first peripheral endpoint that is unused */
- if (0 == (ep->CFG & USBD_CFG_STATE_Msk)) return ep;
- }
- else
- {
- /* find a peripheral endpoint that matches ep_addr */
- uint8_t candidate_ep_addr = decode_ep_addr(ep);
- if (candidate_ep_addr == ep_addr) return ep;
- }
- }
-
- return NULL;
-}
-
-/* perform an IN endpoint transfer; this is called by dcd_edpt_xfer() and the ISR */
-static void dcd_in_xfer(struct xfer_ctl_t *xfer, USBD_EP_T *ep)
-{
- uint16_t bytes_now = tu_min16(xfer->in_remaining_bytes, xfer->max_packet_size);
-
-#if 0 // TODO support dcd_edpt_xfer_fifo API
- if (xfer->ff)
- {
- tu_fifo_read_n(xfer->ff, (void *) (USBD_BUF_BASE + ep->BUFSEG), bytes_now);
- }
- else
-#endif
- {
- // USB SRAM seems to only support byte access and memcpy could possibly do it by words
- usb_memcpy((uint8_t *)(USBD_BUF_BASE + ep->BUFSEG), xfer->data_ptr, bytes_now);
- }
-
- ep->MXPLD = bytes_now;
-}
-
-/* called by dcd_init() as well as by the ISR during a USB bus reset */
-static void bus_reset(void)
-{
- USBD->STBUFSEG = PERIPH_SETUP_BUF_BASE;
-
- for (enum ep_enum ep_index = PERIPH_EP0; ep_index < PERIPH_MAX_EP; ep_index++)
- {
- USBD->EP[ep_index].CFG = 0;
- USBD->EP[ep_index].CFGP = 0;
- }
-
- /* allocate the default EP0 endpoints */
-
- USBD->EP[PERIPH_EP0].CFG = USBD_CFG_CSTALL_Msk | USBD_CFG_EPMODE_IN;
- USBD->EP[PERIPH_EP0].BUFSEG = PERIPH_EP0_BUF_BASE;
- xfer_table[PERIPH_EP0].max_packet_size = PERIPH_EP0_BUF_LEN;
-
- USBD->EP[PERIPH_EP1].CFG = USBD_CFG_CSTALL_Msk | USBD_CFG_EPMODE_OUT;
- USBD->EP[PERIPH_EP1].BUFSEG = PERIPH_EP1_BUF_BASE;
- xfer_table[PERIPH_EP1].max_packet_size = PERIPH_EP1_BUF_LEN;
-
- /* USB RAM beyond what we've allocated above is available to the user */
- bufseg_addr = PERIPH_EP2_BUF_BASE;
-
- /* Reset USB device address */
- USBD->FADDR = 0;
-
- /* reset EP0_IN flag */
- active_ep0_xfer = false;
-}
-
-/* centralized location for USBD interrupt enable bit mask */
-#if USE_SOF
-static const uint32_t enabled_irqs = USBD_INTSTS_VBDETIF_Msk | USBD_INTSTS_BUSIF_Msk | USBD_INTSTS_SETUP_Msk | USBD_INTSTS_USBIF_Msk | USBD_INTSTS_SOFIF_Msk;
-#else
-static const uint32_t enabled_irqs = USBD_INTSTS_VBDETIF_Msk | USBD_INTSTS_BUSIF_Msk | USBD_INTSTS_SETUP_Msk | USBD_INTSTS_USBIF_Msk;
-#endif
-
-/*
- NUC121/NUC125/NUC126 TinyUSB API driver implementation
-*/
-
-void dcd_init(uint8_t rhport)
-{
- (void) rhport;
-
-#ifdef SUPPORT_LPM
- USBD->ATTR = 0x7D0 | USBD_LPMACK;
-#else
- USBD->ATTR = 0x7D0;
-#endif
-
- usb_detach();
-
- bus_reset();
-
- usb_attach();
-
- USBD->INTSTS = enabled_irqs;
- USBD->INTEN = enabled_irqs;
-}
-
-void dcd_int_enable(uint8_t rhport)
-{
- (void) rhport;
- NVIC_EnableIRQ(USBD_IRQn);
-}
-
-void dcd_int_disable(uint8_t rhport)
-{
- (void) rhport;
- NVIC_DisableIRQ(USBD_IRQn);
-}
-
-void dcd_set_address(uint8_t rhport, uint8_t dev_addr)
-{
- (void) rhport;
- (void) dev_addr;
- usb_control_send_zlp(); /* SET_ADDRESS is the one exception where TinyUSB doesn't use dcd_edpt_xfer() to generate a ZLP */
-
- // DCD can only set address after status for this request is complete.
- // do it at dcd_edpt0_status_complete()
-}
-
-void dcd_remote_wakeup(uint8_t rhport)
-{
- (void) rhport;
- USBD->ATTR = USBD_ATTR_RWAKEUP_Msk;
-}
-
-bool dcd_edpt_open(uint8_t rhport, tusb_desc_endpoint_t const * p_endpoint_desc)
-{
- (void) rhport;
-
- USBD_EP_T *ep = ep_entry(p_endpoint_desc->bEndpointAddress, true);
- TU_ASSERT(ep);
-
- /* mine the data for the information we need */
- int const dir = tu_edpt_dir(p_endpoint_desc->bEndpointAddress);
- int const size = p_endpoint_desc->wMaxPacketSize.size;
- tusb_xfer_type_t const type = (tusb_xfer_type_t) p_endpoint_desc->bmAttributes.xfer;
- struct xfer_ctl_t *xfer = &xfer_table[ep - USBD->EP];
-
- /* allocate buffer from USB RAM */
- ep->BUFSEG = bufseg_addr;
- bufseg_addr += size;
- TU_ASSERT(bufseg_addr <= USBD_BUF_SIZE);
-
- /* construct USB Configuration Register value and then write it */
- uint32_t cfg = tu_edpt_number(p_endpoint_desc->bEndpointAddress);
- cfg |= (TUSB_DIR_IN == dir) ? USBD_CFG_EPMODE_IN : USBD_CFG_EPMODE_OUT;
- if (TUSB_XFER_ISOCHRONOUS == type)
- cfg |= USBD_CFG_TYPE_ISO;
- ep->CFG = cfg;
-
- /* make a note of the endpoint size */
- xfer->max_packet_size = size;
-
- return true;
-}
-
-bool dcd_edpt_xfer(uint8_t rhport, uint8_t ep_addr, uint8_t *buffer, uint16_t total_bytes)
-{
- (void) rhport;
-
- /* mine the data for the information we need */
- tusb_dir_t dir = tu_edpt_dir(ep_addr);
- USBD_EP_T *ep = ep_entry(ep_addr, false);
- struct xfer_ctl_t *xfer = &xfer_table[ep - USBD->EP];
-
- /* store away the information we'll needing now and later */
- xfer->data_ptr = buffer;
- // xfer->ff = NULL; // TODO support dcd_edpt_xfer_fifo API
- xfer->in_remaining_bytes = total_bytes;
- xfer->total_bytes = total_bytes;
-
- /* for the first of one or more EP0_IN packets in a message, the first must be DATA1 */
- if ( (0x80 == ep_addr) && !active_ep0_xfer ) ep->CFG |= USBD_CFG_DSQSYNC_Msk;
-
- if (TUSB_DIR_IN == dir)
- {
- dcd_in_xfer(xfer, ep);
- }
- else
- {
- xfer->out_bytes_so_far = 0;
- ep->MXPLD = xfer->max_packet_size;
- }
-
- return true;
-}
-
-#if 0 // TODO support dcd_edpt_xfer_fifo API
-bool dcd_edpt_xfer_fifo (uint8_t rhport, uint8_t ep_addr, tu_fifo_t * ff, uint16_t total_bytes)
-{
- (void) rhport;
-
- /* mine the data for the information we need */
- tusb_dir_t dir = tu_edpt_dir(ep_addr);
- USBD_EP_T *ep = ep_entry(ep_addr, false);
- struct xfer_ctl_t *xfer = &xfer_table[ep - USBD->EP];
-
- /* store away the information we'll needing now and later */
- xfer->data_ptr = NULL; // Indicates a FIFO shall be used
- xfer->ff = ff;
- xfer->in_remaining_bytes = total_bytes;
- xfer->total_bytes = total_bytes;
-
- if (TUSB_DIR_IN == dir)
- {
- dcd_in_xfer(xfer, ep);
- }
- else
- {
- xfer->out_bytes_so_far = 0;
- ep->MXPLD = xfer->max_packet_size;
- }
-
- return true;
-}
-#endif
-
-void dcd_edpt_stall(uint8_t rhport, uint8_t ep_addr)
-{
- (void) rhport;
- USBD_EP_T *ep = ep_entry(ep_addr, false);
- ep->CFGP |= USBD_CFGP_SSTALL_Msk;
-}
-
-void dcd_edpt_clear_stall(uint8_t rhport, uint8_t ep_addr)
-{
- (void) rhport;
- USBD_EP_T *ep = ep_entry(ep_addr, false);
- ep->CFG |= USBD_CFG_CSTALL_Msk;
-}
-
-void dcd_int_handler(uint8_t rhport)
-{
- (void) rhport;
-
- uint32_t status = USBD->INTSTS;
-#ifdef SUPPORT_LPM
- uint32_t state = USBD->ATTR & 0x300f;
-#else
- uint32_t state = USBD->ATTR & 0xf;
-#endif
-
- if(status & USBD_INTSTS_VBDETIF_Msk)
- {
- if(USBD->VBUSDET & USBD_VBUSDET_VBUSDET_Msk)
- {
- /* USB connect */
- USBD->ATTR |= USBD_ATTR_USBEN_Msk | USBD_ATTR_PHYEN_Msk;
- }
- else
- {
- /* USB disconnect */
- USBD->ATTR &= ~USBD_ATTR_USBEN_Msk;
- }
- }
-
- if(status & USBD_INTSTS_BUSIF_Msk)
- {
- if(state & USBD_ATTR_USBRST_Msk)
- {
- /* USB bus reset */
- USBD->ATTR |= USBD_ATTR_USBEN_Msk | USBD_ATTR_PHYEN_Msk;
-
- bus_reset();
-
- dcd_event_bus_reset(0, TUSB_SPEED_FULL, true);
- }
-
- if(state & USBD_ATTR_SUSPEND_Msk)
- {
- /* Enable USB but disable PHY */
- USBD->ATTR &= ~USBD_ATTR_PHYEN_Msk;
- dcd_event_bus_signal(0, DCD_EVENT_SUSPEND, true);
- }
-
- if(state & USBD_ATTR_RESUME_Msk)
- {
- /* Enable USB and enable PHY */
- USBD->ATTR |= USBD_ATTR_USBEN_Msk | USBD_ATTR_PHYEN_Msk;
- dcd_event_bus_signal(0, DCD_EVENT_RESUME, true);
- }
- }
-
- if(status & USBD_INTSTS_SETUP_Msk)
- {
- /* clear the data ready flag of control endpoints */
- USBD->EP[PERIPH_EP0].CFGP |= USBD_CFGP_CLRRDY_Msk;
- USBD->EP[PERIPH_EP1].CFGP |= USBD_CFGP_CLRRDY_Msk;
-
- /* get SETUP packet from USB buffer */
- dcd_event_setup_received(0, (uint8_t *)USBD_BUF_BASE, true);
- }
-
- if(status & USBD_INTSTS_USBIF_Msk)
- {
- if (status & USBD_INTSTS_EPEVT0_Msk) /* PERIPH_EP0 (EP0_IN) event: this is treated separately from the rest */
- {
- uint16_t const available_bytes = USBD->EP[PERIPH_EP0].MXPLD;
-
- active_ep0_xfer = (available_bytes == xfer_table[PERIPH_EP0].max_packet_size);
-
- dcd_event_xfer_complete(0, 0x80, available_bytes, XFER_RESULT_SUCCESS, true);
- }
-
- /* service PERIPH_EP1 through PERIPH_EP7 */
- enum ep_enum ep_index;
- uint32_t mask;
- struct xfer_ctl_t *xfer;
- USBD_EP_T *ep;
- for (ep_index = PERIPH_EP1, mask = USBD_INTSTS_EPEVT1_Msk, xfer = &xfer_table[PERIPH_EP1], ep = &USBD->EP[PERIPH_EP1]; ep_index <= PERIPH_EP7; ep_index++, mask <<= 1, xfer++, ep++)
- {
- if(status & mask)
- {
- USBD->INTSTS = mask;
-
- uint16_t const available_bytes = ep->MXPLD;
- uint8_t const ep_addr = decode_ep_addr(ep);
- bool const out_ep = !(ep_addr & TUSB_DIR_IN_MASK);
-
- if (out_ep)
- {
- /* copy the data from the PC to the previously provided buffer */
-#if 0 // TODO support dcd_edpt_xfer_fifo API
- if (xfer->ff)
- {
- tu_fifo_write_n(xfer->ff, (const void *) (USBD_BUF_BASE + ep->BUFSEG), available_bytes);
- }
- else
-#endif
- {
- // USB SRAM seems to only support byte access and memcpy could possibly do it by words
- usb_memcpy(xfer->data_ptr, (uint8_t *)(USBD_BUF_BASE + ep->BUFSEG), available_bytes);
- xfer->data_ptr += available_bytes;
- }
-
- xfer->out_bytes_so_far += available_bytes;
-
- /* when the transfer is finished, alert TinyUSB; otherwise, accept more data */
- if ( (xfer->total_bytes == xfer->out_bytes_so_far) || (available_bytes < xfer->max_packet_size) )
- dcd_event_xfer_complete(0, ep_addr, xfer->out_bytes_so_far, XFER_RESULT_SUCCESS, true);
- else
- ep->MXPLD = xfer->max_packet_size;
- }
- else
- {
- /* update the bookkeeping to reflect the data that has now been sent to the PC */
- xfer->in_remaining_bytes -= available_bytes;
- xfer->data_ptr += available_bytes;
-
- /* if more data to send, send it; otherwise, alert TinyUSB that we've finished */
- if (xfer->in_remaining_bytes)
- dcd_in_xfer(xfer, ep);
- else
- dcd_event_xfer_complete(0, ep_addr, xfer->total_bytes, XFER_RESULT_SUCCESS, true);
- }
- }
- }
- }
-
- if(status & USBD_INTSTS_SOFIF_Msk)
- {
- /* Start-Of-Frame event */
- dcd_event_bus_signal(0, DCD_EVENT_SOF, true);
- }
-
- /* acknowledge all interrupts */
- USBD->INTSTS = status & enabled_irqs;
-}
-
-// Invoked when a control transfer's status stage is complete.
-// May help DCD to prepare for next control transfer, this API is optional.
-void dcd_edpt0_status_complete(uint8_t rhport, tusb_control_request_t const * request)
-{
- (void) rhport;
-
- if (request->bmRequestType_bit.recipient == TUSB_REQ_RCPT_DEVICE &&
- request->bmRequestType_bit.type == TUSB_REQ_TYPE_STANDARD &&
- request->bRequest == TUSB_REQ_SET_ADDRESS )
- {
- uint8_t const dev_addr = (uint8_t) request->wValue;
-
- // Setting new address after the whole request is complete
- USBD->FADDR = dev_addr;
- }
-}
-
-void dcd_disconnect(uint8_t rhport)
-{
- (void) rhport;
- usb_detach();
-}
-
-void dcd_connect(uint8_t rhport)
-{
- (void) rhport;
- usb_attach();
-}
-
-#endif
diff --git a/tinyusb/src/portable/nuvoton/nuc505/dcd_nuc505.c b/tinyusb/src/portable/nuvoton/nuc505/dcd_nuc505.c
deleted file mode 100755
index 4e633086..00000000
--- a/tinyusb/src/portable/nuvoton/nuc505/dcd_nuc505.c
+++ /dev/null
@@ -1,712 +0,0 @@
-/*
- * The MIT License (MIT)
- *
- * Copyright (c) 2020 Peter Lawrence
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- *
- * This file is part of the TinyUSB stack.
- */
-
-/*
- Theory of operation:
-
- The NUC505 USBD peripheral has twelve "EP"s, where each is simplex, in addition
- to dedicated support for the control endpoint (EP0). The non-user endpoints
- are referred to as "user" EPs in this code, and follow the datasheet
- nomenclature of EPA through EPL.
-*/
-
-#include "tusb_option.h"
-
-#if TUSB_OPT_DEVICE_ENABLED && (CFG_TUSB_MCU == OPT_MCU_NUC505)
-
-#include "device/dcd.h"
-#include "NUC505Series.h"
-
-/*
- * The DMA functionality of the USBD peripheral does not appear to succeed with
- * transfer lengths that are longer (> 64 bytes) and are not a multiple of 4.
- * Keep disabled for now.
- */
-#define USE_DMA 0
-
-/* rather important info unfortunately not provided by device include files */
-#define USBD_BUF_SIZE 2048 /* how much USB buffer space there is */
-#define USBD_MAX_DMA_LEN 0x1000 /* max bytes that can be DMAed at one time */
-
-enum ep_enum
-{
- PERIPH_EPA = 0,
- PERIPH_EPB = 1,
- PERIPH_EPC = 2,
- PERIPH_EPD = 3,
- PERIPH_EPE = 4,
- PERIPH_EPF = 5,
- PERIPH_EPG = 6,
- PERIPH_EPH = 7,
- PERIPH_EPI = 8,
- PERIPH_EPJ = 9,
- PERIPH_EPK = 10,
- PERIPH_EPL = 11,
- PERIPH_MAX_EP,
-};
-
-static const uint8_t epcfg_eptype_table[] =
-{
- [TUSB_XFER_CONTROL] = 0, /* won't happen, since control EPs have dedicated registers */
- [TUSB_XFER_ISOCHRONOUS] = 3 << USBD_EPCFG_EPTYPE_Pos,
- [TUSB_XFER_BULK] = 1 << USBD_EPCFG_EPTYPE_Pos,
- [TUSB_XFER_INTERRUPT] = 2 << USBD_EPCFG_EPTYPE_Pos,
-};
-
-static const uint8_t eprspctl_eptype_table[] =
-{
- [TUSB_XFER_CONTROL] = 0, /* won't happen, since control EPs have dedicated registers */
- [TUSB_XFER_ISOCHRONOUS] = 2 << USBD_EPRSPCTL_MODE_Pos, /* Fly Mode */
- [TUSB_XFER_BULK] = 0 << USBD_EPRSPCTL_MODE_Pos, /* Auto-Validate Mode */
- [TUSB_XFER_INTERRUPT] = 1 << USBD_EPRSPCTL_MODE_Pos, /* Manual-Validate Mode */
-};
-
-/* set by dcd_set_address() */
-static volatile uint8_t assigned_address;
-
-/* reset by bus_reset(), this is used by dcd_edpt_open() to assign USBD peripheral buffer addresses */
-static uint32_t bufseg_addr;
-
-/* RAM table needed to track ongoing transfers performed by dcd_edpt_xfer(), dcd_userEP_in_xfer(), and the ISR */
-static struct xfer_ctl_t
-{
- uint8_t *data_ptr; /* data_ptr tracks where to next copy data to (for OUT) or from (for IN) */
- // tu_fifo_t* ff; // TODO support dcd_edpt_xfer_fifo API
- union {
- uint16_t in_remaining_bytes; /* for IN endpoints, we track how many bytes are left to transfer */
- uint16_t out_bytes_so_far; /* but for OUT endpoints, we track how many bytes we've transferred so far */
- };
- uint16_t max_packet_size; /* needed since device driver only finds out this at runtime */
- uint16_t total_bytes; /* quantity needed to pass as argument to dcd_event_xfer_complete() (for IN endpoints) */
- uint8_t ep_addr;
- bool dma_requested;
-} xfer_table[PERIPH_MAX_EP];
-
-/* in addition to xfer_table, additional bespoke bookkeeping is maintained for control EP0 IN */
-static struct
-{
- uint8_t *data_ptr;
- uint16_t in_remaining_bytes;
- uint16_t total_bytes;
-} ctrl_in_xfer;
-
-static volatile struct xfer_ctl_t *current_dma_xfer;
-
-
-/*
- local helper functions
-*/
-
-static void usb_attach(void)
-{
- USBD->PHYCTL |= USBD_PHYCTL_DPPUEN_Msk;
-}
-
-static void usb_detach(void)
-{
- USBD->PHYCTL &= ~USBD_PHYCTL_DPPUEN_Msk;
-}
-
-static void usb_control_send_zlp(void)
-{
- USBD->CEPINTSTS = USBD_CEPINTSTS_STSDONEIF_Msk;
- USBD->CEPCTL = 0; /* clear NAKCLR bit */
- USBD->CEPINTEN = USBD_CEPINTEN_STSDONEIEN_Msk;
-}
-
-/* map 8-bit ep_addr into peripheral endpoint index (PERIPH_EPA...) */
-static USBD_EP_T *ep_entry(uint8_t ep_addr, bool add)
-{
- USBD_EP_T *ep;
- enum ep_enum ep_index;
- struct xfer_ctl_t *xfer;
-
- for (ep_index = PERIPH_EPA, xfer = &xfer_table[PERIPH_EPA], ep = USBD->EP; ep_index < PERIPH_MAX_EP; ep_index++, xfer++, ep++)
- {
- if (add)
- {
- /* take first peripheral endpoint that is unused */
- if (0 == (ep->EPCFG & USBD_EPCFG_EPEN_Msk)) return ep;
- }
- else
- {
- /* find a peripheral endpoint that matches ep_addr */
- if (xfer->ep_addr == ep_addr) return ep;
- }
- }
-
- return NULL;
-}
-
-/* perform a non-control IN endpoint transfer; this is called by the ISR */
-static void dcd_userEP_in_xfer(struct xfer_ctl_t *xfer, USBD_EP_T *ep)
-{
- uint16_t const bytes_now = tu_min16(xfer->in_remaining_bytes, xfer->max_packet_size);
-
- /* precompute what amount of data will be left */
- xfer->in_remaining_bytes -= bytes_now;
-
- /*
- if there will be no more data to send, we replace the BUFEMPTYIF EP interrupt with TXPKIF;
- that way, we alert TinyUSB as soon as this last packet has been sent
- */
- if (0 == xfer->in_remaining_bytes)
- {
- ep->EPINTSTS = USBD_EPINTSTS_TXPKIF_Msk;
- ep->EPINTEN = USBD_EPINTEN_TXPKIEN_Msk;
- }
-
- /* provided buffers are thankfully 32-bit aligned, allowing most data to be transfered as 32-bit */
-#if 0 // TODO support dcd_edpt_xfer_fifo API
- if (xfer->ff)
- {
- tu_fifo_read_n_const_addr_full_words(xfer->ff, (void *) (&ep->EPDAT_BYTE), bytes_now);
- }
- else
-#endif
- {
- uint16_t countdown = bytes_now;
- while (countdown > 3)
- {
- uint32_t u32;
- memcpy(&u32, xfer->data_ptr, 4);
-
- ep->EPDAT = u32;
- xfer->data_ptr += 4; countdown -= 4;
- }
-
- while (countdown--) ep->EPDAT_BYTE = *xfer->data_ptr++;
- }
-
- /* for short packets, we must nudge the peripheral to say 'that's all folks' */
- if (bytes_now != xfer->max_packet_size) ep->EPRSPCTL = USBD_EPRSPCTL_SHORTTXEN_Msk;
-}
-
-/* called by dcd_init() as well as by the ISR during a USB bus reset */
-static void bus_reset(void)
-{
- for (enum ep_enum ep_index = PERIPH_EPA; ep_index < PERIPH_MAX_EP; ep_index++)
- {
- USBD->EP[ep_index].EPCFG = 0;
- xfer_table[ep_index].dma_requested = false;
- }
-
- USBD->DMACNT = 0;
- USBD->DMACTL = USBD_DMACTL_DMARST_Msk;
- USBD->DMACTL = 0;
-
- /* allocate the default EP0 endpoints */
-
- USBD->CEPBUFSTART = 0;
- USBD->CEPBUFEND = 0 + CFG_TUD_ENDPOINT0_SIZE - 1;
-
- /* USB RAM beyond what we've allocated above is available to the user */
- bufseg_addr = CFG_TUD_ENDPOINT0_SIZE;
-
- /* Reset USB device address */
- USBD->FADDR = 0;
-
- current_dma_xfer = NULL;
-}
-
-#if USE_DMA
-/* this must only be called by the ISR; it does its best to share the single DMA engine across all user EPs (IN and OUT) */
-static void service_dma(void)
-{
- if (current_dma_xfer)
- return;
-
- enum ep_enum ep_index;
- struct xfer_ctl_t *xfer;
- USBD_EP_T *ep;
-
- for (ep_index = PERIPH_EPA, xfer = &xfer_table[PERIPH_EPA], ep = &USBD->EP[PERIPH_EPA]; ep_index < PERIPH_MAX_EP; ep_index++, xfer++, ep++)
- {
- uint16_t const available_bytes = ep->EPDATCNT & USBD_EPDATCNT_DATCNT_Msk;
-
- if (!xfer->dma_requested || !available_bytes)
- continue;
-
- /*
- instruct DMA to copy the data from the PC to the previously provided buffer
- when the bus interrupt DMADONEIEN subsequently fires, the transfer will have finished
- */
- USBD->DMACTL = xfer->ep_addr & USBD_DMACTL_EPNUM_Msk;
- USBD->DMAADDR = (uint32_t)xfer->data_ptr;
- USBD->DMACNT = available_bytes;
- USBD->BUSINTSTS = USBD_BUSINTSTS_DMADONEIF_Msk;
- xfer->out_bytes_so_far += available_bytes;
- current_dma_xfer = xfer;
- USBD->DMACTL |= USBD_DMACTL_DMAEN_Msk;
-
- return;
- }
-}
-#endif
-
-/* centralized location for USBD interrupt enable bit masks */
-static const uint32_t enabled_irqs = USBD_GINTEN_USBIEN_Msk | \
- USBD_GINTEN_EPAIEN_Msk | USBD_GINTEN_EPBIEN_Msk | USBD_GINTEN_EPCIEN_Msk | USBD_GINTEN_EPDIEN_Msk | USBD_GINTEN_EPEIEN_Msk | USBD_GINTEN_EPFIEN_Msk | \
- USBD_GINTEN_EPGIEN_Msk | USBD_GINTEN_EPHIEN_Msk | USBD_GINTEN_EPIIEN_Msk | USBD_GINTEN_EPJIEN_Msk | USBD_GINTEN_EPKIEN_Msk | USBD_GINTEN_EPLIEN_Msk | \
- USBD_GINTEN_CEPIEN_Msk;
-
-/*
- NUC505 TinyUSB API driver implementation
-*/
-
-void dcd_init(uint8_t rhport)
-{
- (void) rhport;
-
- /* configure interrupts in their initial state; BUSINTEN and CEPINTEN will be subsequently and dynamically re-written as needed */
- USBD->GINTEN = enabled_irqs;
- USBD->BUSINTEN = USBD_BUSINTEN_RSTIEN_Msk | USBD_BUSINTEN_VBUSDETIEN_Msk | USBD_BUSINTEN_RESUMEIEN_Msk | USBD_BUSINTEN_DMADONEIEN_Msk;
- USBD->CEPINTEN = 0;
-
- bus_reset();
-
- usb_attach();
-}
-
-void dcd_int_enable(uint8_t rhport)
-{
- (void) rhport;
- NVIC_EnableIRQ(USBD_IRQn);
-}
-
-void dcd_int_disable(uint8_t rhport)
-{
- (void) rhport;
- NVIC_DisableIRQ(USBD_IRQn);
-}
-
-void dcd_set_address(uint8_t rhport, uint8_t dev_addr)
-{
- (void) rhport;
- usb_control_send_zlp(); /* SET_ADDRESS is the one exception where TinyUSB doesn't use dcd_edpt_xfer() to generate a ZLP */
- assigned_address = dev_addr;
-}
-
-void dcd_remote_wakeup(uint8_t rhport)
-{
- (void) rhport;
- USBD->OPER |= USBD_OPER_RESUMEEN_Msk;
-}
-
-bool dcd_edpt_open(uint8_t rhport, tusb_desc_endpoint_t const * p_endpoint_desc)
-{
- (void) rhport;
-
- USBD_EP_T *ep = ep_entry(p_endpoint_desc->bEndpointAddress, true);
- TU_ASSERT(ep);
-
- /* mine the data for the information we need */
- int const dir = tu_edpt_dir(p_endpoint_desc->bEndpointAddress);
- int const size = p_endpoint_desc->wMaxPacketSize.size;
- tusb_xfer_type_t const type = p_endpoint_desc->bmAttributes.xfer;
- struct xfer_ctl_t *xfer = &xfer_table[ep - USBD->EP];
-
- /* allocate buffer from USB RAM */
- ep->EPBUFSTART = bufseg_addr;
- bufseg_addr += size;
- ep->EPBUFEND = bufseg_addr - 1;
- TU_ASSERT(bufseg_addr <= USBD_BUF_SIZE);
-
- ep->EPMPS = size;
-
- ep->EPRSPCTL = USB_EP_RSPCTL_FLUSH | eprspctl_eptype_table[type];
-
- /* construct USB Configuration Register value and then write it */
- uint32_t cfg = (uint32_t)tu_edpt_number(p_endpoint_desc->bEndpointAddress) << USBD_EPCFG_EPNUM_Pos;
- if (TUSB_DIR_IN == dir)
- cfg |= USBD_EPCFG_EPDIR_Msk;
- cfg |= epcfg_eptype_table[type] | USBD_EPCFG_EPEN_Msk;
- ep->EPCFG = cfg;
-
- /* make a note of the endpoint particulars */
- xfer->max_packet_size = size;
- xfer->ep_addr = p_endpoint_desc->bEndpointAddress;
-
- return true;
-}
-
-bool dcd_edpt_xfer(uint8_t rhport, uint8_t ep_addr, uint8_t *buffer, uint16_t total_bytes)
-{
- (void) rhport;
-
- if (0x80 == ep_addr) /* control EP0 IN */
- {
- if (total_bytes)
- {
- USBD->CEPCTL = USBD_CEPCTL_FLUSH_Msk;
- ctrl_in_xfer.data_ptr = buffer;
- ctrl_in_xfer.in_remaining_bytes = total_bytes;
- ctrl_in_xfer.total_bytes = total_bytes;
- USBD->CEPINTSTS = USBD_CEPINTSTS_INTKIF_Msk;
- USBD->CEPINTEN = USBD_CEPINTEN_INTKIEN_Msk;
- }
- else
- {
- usb_control_send_zlp();
- }
- }
- else if (0x00 == ep_addr) /* control EP0 OUT */
- {
- if (total_bytes)
- {
- /* if TinyUSB is asking for EP0 OUT data, it is almost certainly already in the buffer */
- while (total_bytes < USBD->CEPRXCNT);
- for (int count = 0; count < total_bytes; count++)
- *buffer++ = USBD->CEPDAT_BYTE;
-
- dcd_event_xfer_complete(0, ep_addr, total_bytes, XFER_RESULT_SUCCESS, true);
- }
- }
- else
- {
- /* mine the data for the information we need */
- tusb_dir_t dir = tu_edpt_dir(ep_addr);
- USBD_EP_T *ep = ep_entry(ep_addr, false);
- struct xfer_ctl_t *xfer = &xfer_table[ep - USBD->EP];
-
- /* store away the information we'll needing now and later */
- xfer->data_ptr = buffer;
- // xfer->ff = NULL; // TODO support dcd_edpt_xfer_fifo API
- xfer->in_remaining_bytes = total_bytes;
- xfer->total_bytes = total_bytes;
-
- if (TUSB_DIR_IN == dir)
- {
- ep->EPINTEN = USBD_EPINTEN_BUFEMPTYIEN_Msk;
- }
- else
- {
- xfer->out_bytes_so_far = 0;
- ep->EPINTEN = USBD_EPINTEN_RXPKIEN_Msk;
- }
- }
-
- return true;
-}
-
-#if 0 // TODO support dcd_edpt_xfer_fifo API
-bool dcd_edpt_xfer_fifo (uint8_t rhport, uint8_t ep_addr, tu_fifo_t * ff, uint16_t total_bytes)
-{
- (void) rhport;
-
- TU_ASSERT(0x80 != ep_addr && 0x00 != ep_addr); // Must not be used for control stuff
-
- /* mine the data for the information we need */
- tusb_dir_t dir = tu_edpt_dir(ep_addr);
- USBD_EP_T *ep = ep_entry(ep_addr, false);
- struct xfer_ctl_t *xfer = &xfer_table[ep - USBD->EP];
-
- /* store away the information we'll needing now and later */
- xfer->data_ptr = NULL; // Indicates a FIFO shall be used
- xfer->ff = ff;
- xfer->in_remaining_bytes = total_bytes;
- xfer->total_bytes = total_bytes;
-
- if (TUSB_DIR_IN == dir)
- {
- ep->EPINTEN = USBD_EPINTEN_BUFEMPTYIEN_Msk;
- }
- else
- {
- xfer->out_bytes_so_far = 0;
- ep->EPINTEN = USBD_EPINTEN_RXPKIEN_Msk;
- }
-
- return true;
-}
-#endif
-
-void dcd_edpt_stall(uint8_t rhport, uint8_t ep_addr)
-{
- (void) rhport;
-
- if (tu_edpt_number(ep_addr))
- {
- USBD_EP_T *ep = ep_entry(ep_addr, false);
- ep->EPRSPCTL = (ep->EPRSPCTL & 0xf7) | USBD_EPRSPCTL_HALT_Msk;
- }
- else
- {
- USBD->CEPCTL = USBD_CEPCTL_STALLEN_Msk;
- }
-}
-
-void dcd_edpt_clear_stall(uint8_t rhport, uint8_t ep_addr)
-{
- (void) rhport;
-
- if (tu_edpt_number(ep_addr))
- {
- USBD_EP_T *ep = ep_entry(ep_addr, false);
- ep->EPRSPCTL = USBD_EPRSPCTL_TOGGLE_Msk;
- }
-}
-
-void dcd_int_handler(uint8_t rhport)
-{
- (void) rhport;
-
- uint32_t status = USBD->GINTSTS;
-
- /* USB interrupt */
- if (status & USBD_GINTSTS_USBIF_Msk)
- {
- uint32_t bus_state = USBD->BUSINTSTS;
-
- if (bus_state & USBD_BUSINTSTS_SOFIF_Msk)
- {
- /* Start-Of-Frame event */
- dcd_event_bus_signal(0, DCD_EVENT_SOF, true);
- }
-
- if (bus_state & USBD_BUSINTSTS_RSTIF_Msk)
- {
- bus_reset();
-
- USBD->CEPINTEN = USBD_CEPINTEN_SETUPPKIEN_Msk;
- USBD->BUSINTEN = USBD_BUSINTEN_RSTIEN_Msk | USBD_BUSINTEN_RESUMEIEN_Msk | USBD_BUSINTEN_SUSPENDIEN_Msk | USBD_BUSINTEN_DMADONEIEN_Msk;
- USBD->CEPINTSTS = 0x1ffc;
-
- tusb_speed_t speed = (USBD->OPER & USBD_OPER_CURSPD_Msk) ? TUSB_SPEED_HIGH : TUSB_SPEED_FULL;
- dcd_event_bus_reset(0, speed, true);
- }
-
- if (bus_state & USBD_BUSINTSTS_RESUMEIF_Msk)
- {
- USBD->BUSINTEN = USBD_BUSINTEN_RSTIEN_Msk | USBD_BUSINTEN_SUSPENDIEN_Msk | USBD_BUSINTEN_DMADONEIEN_Msk;
- dcd_event_bus_signal(0, DCD_EVENT_RESUME, true);
- }
-
- if (bus_state & USBD_BUSINTSTS_SUSPENDIF_Msk)
- {
- USBD->BUSINTEN = USBD_BUSINTEN_RSTIEN_Msk | USBD_BUSINTEN_RESUMEIEN_Msk | USBD_BUSINTEN_DMADONEIEN_Msk;
- dcd_event_bus_signal(0, DCD_EVENT_SUSPEND, true);
- }
-
- if (bus_state & USBD_BUSINTSTS_HISPDIF_Msk)
- {
- USBD->CEPINTEN = USBD_CEPINTEN_SETUPPKIEN_Msk;
- }
-
- if (bus_state & USBD_BUSINTSTS_DMADONEIF_Msk)
- {
-#if USE_DMA
- if (current_dma_xfer)
- {
- current_dma_xfer->dma_requested = false;
-
- uint16_t available_bytes = USBD->DMACNT & USBD_DMACNT_DMACNT_Msk;
-
- /* if the most recent DMA finishes the transfer, alert TinyUSB; otherwise, the next RXPKIF/INTKIF endpoint interrupt will prompt the next DMA */
- if ( (current_dma_xfer->total_bytes == current_dma_xfer->out_bytes_so_far) || (available_bytes < current_dma_xfer->max_packet_size) )
- {
- dcd_event_xfer_complete(0, current_dma_xfer->ep_addr, current_dma_xfer->out_bytes_so_far, XFER_RESULT_SUCCESS, true);
- }
-
- current_dma_xfer = NULL;
- service_dma();
- }
-#endif
- }
-
- if (bus_state & USBD_BUSINTSTS_VBUSDETIF_Msk)
- {
- if (USBD->PHYCTL & USBD_PHYCTL_VBUSDET_Msk)
- {
- /* USB connect */
- USBD->PHYCTL |= USBD_PHYCTL_PHYEN_Msk | USBD_PHYCTL_DPPUEN_Msk;
- }
- else
- {
- /* USB disconnect */
- USBD->PHYCTL &= ~USBD_PHYCTL_DPPUEN_Msk;
- }
- }
-
- USBD->BUSINTSTS = bus_state & (USBD_BUSINTSTS_SOFIF_Msk | USBD_BUSINTSTS_RSTIF_Msk | USBD_BUSINTSTS_RESUMEIF_Msk | USBD_BUSINTSTS_SUSPENDIF_Msk | USBD_BUSINTSTS_HISPDIF_Msk | USBD_BUSINTSTS_DMADONEIF_Msk | USBD_BUSINTSTS_PHYCLKVLDIF_Msk | USBD_BUSINTSTS_VBUSDETIF_Msk);
- }
-
- if (status & USBD_GINTSTS_CEPIF_Msk)
- {
- uint32_t cep_state = USBD->CEPINTSTS & USBD->CEPINTEN;
-
- if (cep_state & USBD_CEPINTSTS_SETUPPKIF_Msk)
- {
- /* get SETUP packet from USB buffer */
- uint8_t setup_packet[8];
- setup_packet[0] = (uint8_t)(USBD->SETUP1_0 >> 0);
- setup_packet[1] = (uint8_t)(USBD->SETUP1_0 >> 8);
- setup_packet[2] = (uint8_t)(USBD->SETUP3_2 >> 0);
- setup_packet[3] = (uint8_t)(USBD->SETUP3_2 >> 8);
- setup_packet[4] = (uint8_t)(USBD->SETUP5_4 >> 0);
- setup_packet[5] = (uint8_t)(USBD->SETUP5_4 >> 8);
- setup_packet[6] = (uint8_t)(USBD->SETUP7_6 >> 0);
- setup_packet[7] = (uint8_t)(USBD->SETUP7_6 >> 8);
- dcd_event_setup_received(0, setup_packet, true);
- }
- else if (cep_state & USBD_CEPINTSTS_INTKIF_Msk)
- {
- USBD->CEPINTSTS = USBD_CEPINTSTS_TXPKIF_Msk;
-
- if (!(cep_state & USBD_CEPINTSTS_STSDONEIF_Msk))
- {
- USBD->CEPINTEN = USBD_CEPINTEN_TXPKIEN_Msk;
- uint16_t bytes_now = tu_min16(ctrl_in_xfer.in_remaining_bytes, CFG_TUD_ENDPOINT0_SIZE);
- for (int count = 0; count < bytes_now; count++)
- USBD->CEPDAT_BYTE = *ctrl_in_xfer.data_ptr++;
- ctrl_in_xfer.in_remaining_bytes -= bytes_now;
- USBD_START_CEP_IN(bytes_now);
- }
- else
- {
- USBD->CEPINTEN = USBD_CEPINTEN_TXPKIEN_Msk | USBD_CEPINTEN_STSDONEIEN_Msk;
- }
- }
- else if (cep_state & USBD_CEPINTSTS_TXPKIF_Msk)
- {
- USBD->CEPINTSTS = USBD_CEPINTSTS_STSDONEIF_Msk;
- USBD_SET_CEP_STATE(USB_CEPCTL_NAKCLR);
-
- /* alert TinyUSB that the EP0 IN transfer has finished */
- if ( (0 == ctrl_in_xfer.in_remaining_bytes) || (0 == ctrl_in_xfer.total_bytes) )
- dcd_event_xfer_complete(0, 0x80, ctrl_in_xfer.total_bytes, XFER_RESULT_SUCCESS, true);
-
- if (ctrl_in_xfer.in_remaining_bytes)
- {
- USBD->CEPINTSTS = USBD_CEPINTSTS_INTKIF_Msk;
- USBD->CEPINTEN = USBD_CEPINTEN_INTKIEN_Msk;
- }
- else
- {
- /* TinyUSB does its own fragmentation and ZLP for EP0; a transfer of zero means a ZLP */
- if (0 == ctrl_in_xfer.total_bytes) USBD->CEPCTL = USBD_CEPCTL_ZEROLEN_Msk;
-
- USBD->CEPINTSTS = USBD_CEPINTSTS_STSDONEIF_Msk;
- USBD->CEPINTEN = USBD_CEPINTEN_SETUPPKIEN_Msk | USBD_CEPINTEN_STSDONEIEN_Msk;
- }
- }
- else if (cep_state & USBD_CEPINTSTS_STSDONEIF_Msk)
- {
- /* given ACK from host has happened, we can now set the address (if not already done) */
- if((USBD->FADDR != assigned_address) && (USBD->FADDR == 0))
- {
- USBD->FADDR = assigned_address;
-
- for (enum ep_enum ep_index = PERIPH_EPA; ep_index < PERIPH_MAX_EP; ep_index++)
- {
- if (USBD->EP[ep_index].EPCFG & USBD_EPCFG_EPEN_Msk) USBD->EP[ep_index].EPRSPCTL = USBD_EPRSPCTL_TOGGLE_Msk;
- }
- }
-
- USBD->CEPINTEN = USBD_CEPINTEN_SETUPPKIEN_Msk;
- }
-
- USBD->CEPINTSTS = cep_state;
-
- return;
- }
-
- if (status & (USBD_GINTSTS_EPAIF_Msk | USBD_GINTSTS_EPBIF_Msk | USBD_GINTSTS_EPCIF_Msk | USBD_GINTSTS_EPDIF_Msk | USBD_GINTSTS_EPEIF_Msk | USBD_GINTSTS_EPFIF_Msk | USBD_GINTSTS_EPGIF_Msk | USBD_GINTSTS_EPHIF_Msk | USBD_GINTSTS_EPIIF_Msk | USBD_GINTSTS_EPJIF_Msk | USBD_GINTSTS_EPKIF_Msk | USBD_GINTSTS_EPLIF_Msk))
- {
- /* service PERIPH_EPA through PERIPH_EPL */
- enum ep_enum ep_index;
- uint32_t mask;
- struct xfer_ctl_t *xfer;
- USBD_EP_T *ep;
- for (ep_index = PERIPH_EPA, mask = USBD_GINTSTS_EPAIF_Msk, xfer = &xfer_table[PERIPH_EPA], ep = &USBD->EP[PERIPH_EPA]; ep_index < PERIPH_MAX_EP; ep_index++, mask <<= 1, xfer++, ep++)
- {
- if(status & mask)
- {
- uint8_t const ep_addr = xfer->ep_addr;
- bool const out_ep = !(ep_addr & TUSB_DIR_IN_MASK);
- uint32_t ep_state = ep->EPINTSTS & ep->EPINTEN;
-
- if (out_ep)
- {
-#if USE_DMA
- xfer->dma_requested = true;
- service_dma();
-#else
- uint16_t const available_bytes = ep->EPDATCNT & USBD_EPDATCNT_DATCNT_Msk;
- /* copy the data from the PC to the previously provided buffer */
-#if 0 // TODO support dcd_edpt_xfer_fifo API
- if (xfer->ff)
- {
- tu_fifo_write_n_const_addr_full_words(xfer->ff, (const void *) &ep->EPDAT_BYTE, tu_min16(available_bytes, xfer->total_bytes - xfer->out_bytes_so_far));
- }
- else
-#endif
- {
- for (int count = 0; (count < available_bytes) && (xfer->out_bytes_so_far < xfer->total_bytes); count++, xfer->out_bytes_so_far++)
- {
- *xfer->data_ptr++ = ep->EPDAT_BYTE;
- }
- }
-
- /* when the transfer is finished, alert TinyUSB; otherwise, continue accepting more data */
- if ( (xfer->total_bytes == xfer->out_bytes_so_far) || (available_bytes < xfer->max_packet_size) )
- {
- dcd_event_xfer_complete(0, ep_addr, xfer->out_bytes_so_far, XFER_RESULT_SUCCESS, true);
- }
-#endif
-
- }
- else if (ep_state & USBD_EPINTSTS_BUFEMPTYIF_Msk)
- {
- /* send any remaining data */
- dcd_userEP_in_xfer(xfer, ep);
- }
- else if (ep_state & USBD_EPINTSTS_TXPKIF_Msk)
- {
- /* alert TinyUSB that we've finished */
- dcd_event_xfer_complete(0, ep_addr, xfer->total_bytes, XFER_RESULT_SUCCESS, true);
- ep->EPINTEN = 0;
- }
-
- ep->EPINTSTS = ep_state;
- }
- }
- }
-}
-
-void dcd_disconnect(uint8_t rhport)
-{
- (void) rhport;
- usb_detach();
-}
-
-void dcd_connect(uint8_t rhport)
-{
- (void) rhport;
- usb_attach();
-}
-
-#endif
diff --git a/tinyusb/src/portable/nxp/khci/dcd_khci.c b/tinyusb/src/portable/nxp/khci/dcd_khci.c
deleted file mode 100755
index dce464fd..00000000
--- a/tinyusb/src/portable/nxp/khci/dcd_khci.c
+++ /dev/null
@@ -1,479 +0,0 @@
-/*
- * The MIT License (MIT)
- *
- * Copyright (c) 2020 Koji Kitayama
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- *
- * This file is part of the TinyUSB stack.
- */
-
-#include "tusb_option.h"
-
-#if TUSB_OPT_DEVICE_ENABLED && ( \
- ( CFG_TUSB_MCU == OPT_MCU_MKL25ZXX ) || ( CFG_TUSB_MCU == OPT_MCU_K32L2BXX ) \
- )
-
-#include "fsl_device_registers.h"
-#define KHCI USB0
-
-#include "device/dcd.h"
-
-//--------------------------------------------------------------------+
-// MACRO TYPEDEF CONSTANT ENUM DECLARATION
-//--------------------------------------------------------------------+
-
-enum {
- TOK_PID_OUT = 0x1u,
- TOK_PID_IN = 0x9u,
- TOK_PID_SETUP = 0xDu,
-};
-
-typedef struct TU_ATTR_PACKED
-{
- union {
- uint32_t head;
- struct {
- union {
- struct {
- uint16_t : 2;
- uint16_t tok_pid : 4;
- uint16_t data : 1;
- uint16_t own : 1;
- uint16_t : 8;
- };
- struct {
- uint16_t : 2;
- uint16_t bdt_stall: 1;
- uint16_t dts : 1;
- uint16_t ninc : 1;
- uint16_t keep : 1;
- uint16_t : 10;
- };
- };
- uint16_t bc : 10;
- uint16_t : 6;
- };
- };
- uint8_t *addr;
-}buffer_descriptor_t;
-
-TU_VERIFY_STATIC( sizeof(buffer_descriptor_t) == 8, "size is not correct" );
-
-typedef struct TU_ATTR_PACKED
-{
- union {
- uint32_t state;
- struct {
- uint32_t max_packet_size :11;
- uint32_t : 5;
- uint32_t odd : 1;
- uint32_t :15;
- };
- };
- uint16_t length;
- uint16_t remaining;
-}endpoint_state_t;
-
-TU_VERIFY_STATIC( sizeof(endpoint_state_t) == 8, "size is not correct" );
-
-typedef struct
-{
- union {
- /* [#EP][OUT,IN][EVEN,ODD] */
- buffer_descriptor_t bdt[16][2][2];
- uint16_t bda[512];
- };
- TU_ATTR_ALIGNED(4) union {
- endpoint_state_t endpoint[16][2];
- endpoint_state_t endpoint_unified[16 * 2];
- };
- uint8_t setup_packet[8];
- uint8_t addr;
-}dcd_data_t;
-
-//--------------------------------------------------------------------+
-// INTERNAL OBJECT & FUNCTION DECLARATION
-//--------------------------------------------------------------------+
-// BDT(Buffer Descriptor Table) must be 256-byte aligned
-CFG_TUSB_MEM_SECTION TU_ATTR_ALIGNED(512) static dcd_data_t _dcd;
-
-TU_VERIFY_STATIC( sizeof(_dcd.bdt) == 512, "size is not correct" );
-
-static void prepare_next_setup_packet(uint8_t rhport)
-{
- const unsigned out_odd = _dcd.endpoint[0][0].odd;
- const unsigned in_odd = _dcd.endpoint[0][1].odd;
- if (_dcd.bdt[0][0][out_odd].own) {
- TU_LOG1("DCD fail to prepare the next SETUP %d %d\r\n", out_odd, in_odd);
- return;
- }
- _dcd.bdt[0][0][out_odd].data = 0;
- _dcd.bdt[0][0][out_odd ^ 1].data = 1;
- _dcd.bdt[0][1][in_odd].data = 1;
- _dcd.bdt[0][1][in_odd ^ 1].data = 0;
- dcd_edpt_xfer(rhport, tu_edpt_addr(0, TUSB_DIR_OUT),
- _dcd.setup_packet, sizeof(_dcd.setup_packet));
-}
-
-static void process_stall(uint8_t rhport)
-{
- if (KHCI->ENDPOINT[0].ENDPT & USB_ENDPT_EPSTALL_MASK) {
- /* clear stall condition of the control pipe */
- prepare_next_setup_packet(rhport);
- KHCI->ENDPOINT[0].ENDPT &= ~USB_ENDPT_EPSTALL_MASK;
- }
-}
-
-static void process_tokdne(uint8_t rhport)
-{
- const unsigned s = KHCI->STAT;
- KHCI->ISTAT = USB_ISTAT_TOKDNE_MASK; /* fetch the next token if received */
- buffer_descriptor_t *bd = (buffer_descriptor_t *)&_dcd.bda[s];
- endpoint_state_t *ep = &_dcd.endpoint_unified[s >> 3];
- unsigned odd = (s & USB_STAT_ODD_MASK) ? 1 : 0;
-
- /* fetch pid before discarded by the next steps */
- const unsigned pid = bd->tok_pid;
- /* reset values for a next transfer */
- bd->bdt_stall = 0;
- bd->dts = 1;
- bd->ninc = 0;
- bd->keep = 0;
- /* update the odd variable to prepare for the next transfer */
- ep->odd = odd ^ 1;
- if (pid == TOK_PID_SETUP) {
- dcd_event_setup_received(rhport, bd->addr, true);
- KHCI->CTL &= ~USB_CTL_TXSUSPENDTOKENBUSY_MASK;
- return;
- }
- if (s >> 4) {
- TU_LOG1("TKDNE %x\r\n", s);
- }
-
- const unsigned bc = bd->bc;
- const unsigned remaining = ep->remaining - bc;
- if (remaining && bc == ep->max_packet_size) {
- /* continue the transferring consecutive data */
- ep->remaining = remaining;
- const int next_remaining = remaining - ep->max_packet_size;
- if (next_remaining > 0) {
- /* prepare to the after next transfer */
- bd->addr += ep->max_packet_size * 2;
- bd->bc = next_remaining > ep->max_packet_size ? ep->max_packet_size: next_remaining;
- __DSB();
- bd->own = 1; /* the own bit must set after addr */
- }
- return;
- }
- const unsigned length = ep->length;
- dcd_event_xfer_complete(rhport,
- ((s & USB_STAT_TX_MASK) << 4) | (s >> USB_STAT_ENDP_SHIFT),
- length - remaining, XFER_RESULT_SUCCESS, true);
- if (0 == (s & USB_STAT_ENDP_MASK) && 0 == length) {
- /* After completion a ZLP of control transfer,
- * it prepares for the next steup transfer. */
- if (_dcd.addr) {
- /* When the transfer was the SetAddress,
- * the device address should be updated here. */
- KHCI->ADDR = _dcd.addr;
- _dcd.addr = 0;
- }
- prepare_next_setup_packet(rhport);
- }
-}
-
-static void process_bus_reset(uint8_t rhport)
-{
- KHCI->USBCTRL &= ~USB_USBCTRL_SUSP_MASK;
- KHCI->CTL |= USB_CTL_ODDRST_MASK;
- KHCI->ADDR = 0;
- KHCI->INTEN = (KHCI->INTEN & ~USB_INTEN_RESUMEEN_MASK) | USB_INTEN_SLEEPEN_MASK;
-
- KHCI->ENDPOINT[0].ENDPT = USB_ENDPT_EPHSHK_MASK | USB_ENDPT_EPRXEN_MASK | USB_ENDPT_EPTXEN_MASK;
- for (unsigned i = 1; i < 16; ++i) {
- KHCI->ENDPOINT[i].ENDPT = 0;
- }
- buffer_descriptor_t *bd = _dcd.bdt[0][0];
- for (unsigned i = 0; i < sizeof(_dcd.bdt)/sizeof(*bd); ++i, ++bd) {
- bd->head = 0;
- }
- const endpoint_state_t ep0 = {
- .max_packet_size = CFG_TUD_ENDPOINT0_SIZE,
- .odd = 0,
- .length = 0,
- .remaining = 0,
- };
- _dcd.endpoint[0][0] = ep0;
- _dcd.endpoint[0][1] = ep0;
- tu_memclr(_dcd.endpoint[1], sizeof(_dcd.endpoint) - sizeof(_dcd.endpoint[0]));
- _dcd.addr = 0;
- prepare_next_setup_packet(rhport);
- KHCI->CTL &= ~USB_CTL_ODDRST_MASK;
- dcd_event_bus_reset(rhport, TUSB_SPEED_FULL, true);
-}
-
-static void process_bus_inactive(uint8_t rhport)
-{
- (void) rhport;
- const unsigned inten = KHCI->INTEN;
- KHCI->INTEN = (inten & ~USB_INTEN_SLEEPEN_MASK) | USB_INTEN_RESUMEEN_MASK;
- KHCI->USBCTRL |= USB_USBCTRL_SUSP_MASK;
- dcd_event_bus_signal(rhport, DCD_EVENT_SUSPEND, true);
-}
-
-static void process_bus_active(uint8_t rhport)
-{
- (void) rhport;
- KHCI->USBCTRL &= ~USB_USBCTRL_SUSP_MASK;
- const unsigned inten = KHCI->INTEN;
- KHCI->INTEN = (inten & ~USB_INTEN_RESUMEEN_MASK) | USB_INTEN_SLEEPEN_MASK;
- dcd_event_bus_signal(rhport, DCD_EVENT_RESUME, true);
-}
-
-/*------------------------------------------------------------------*/
-/* Device API
- *------------------------------------------------------------------*/
-void dcd_init(uint8_t rhport)
-{
- (void) rhport;
-
- KHCI->USBTRC0 |= USB_USBTRC0_USBRESET_MASK;
- while (KHCI->USBTRC0 & USB_USBTRC0_USBRESET_MASK);
- tu_memclr(&_dcd, sizeof(_dcd));
- KHCI->USBTRC0 |= TU_BIT(6); /* software must set this bit to 1 */
- KHCI->BDTPAGE1 = (uint8_t)((uintptr_t)_dcd.bdt >> 8);
- KHCI->BDTPAGE2 = (uint8_t)((uintptr_t)_dcd.bdt >> 16);
- KHCI->BDTPAGE3 = (uint8_t)((uintptr_t)_dcd.bdt >> 24);
-
- dcd_connect(rhport);
- NVIC_ClearPendingIRQ(USB0_IRQn);
-}
-
-void dcd_int_enable(uint8_t rhport)
-{
- (void) rhport;
- KHCI->INTEN = USB_INTEN_USBRSTEN_MASK | USB_INTEN_TOKDNEEN_MASK |
- USB_INTEN_SLEEPEN_MASK | USB_INTEN_ERROREN_MASK | USB_INTEN_STALLEN_MASK;
- NVIC_EnableIRQ(USB0_IRQn);
-}
-
-void dcd_int_disable(uint8_t rhport)
-{
- (void) rhport;
- NVIC_DisableIRQ(USB0_IRQn);
- KHCI->INTEN = 0;
-}
-
-void dcd_set_address(uint8_t rhport, uint8_t dev_addr)
-{
- (void) rhport;
- _dcd.addr = dev_addr & 0x7F;
- /* Response with status first before changing device address */
- dcd_edpt_xfer(rhport, tu_edpt_addr(0, TUSB_DIR_IN), NULL, 0);
-}
-
-void dcd_remote_wakeup(uint8_t rhport)
-{
- (void) rhport;
- unsigned cnt = SystemCoreClock / 100;
- KHCI->CTL |= USB_CTL_RESUME_MASK;
- while (cnt--) __NOP();
- KHCI->CTL &= ~USB_CTL_RESUME_MASK;
-}
-
-void dcd_connect(uint8_t rhport)
-{
- (void) rhport;
- KHCI->USBCTRL = 0;
- KHCI->CONTROL |= USB_CONTROL_DPPULLUPNONOTG_MASK;
- KHCI->CTL |= USB_CTL_USBENSOFEN_MASK;
-}
-
-void dcd_disconnect(uint8_t rhport)
-{
- (void) rhport;
- KHCI->CTL = 0;
- KHCI->CONTROL &= ~USB_CONTROL_DPPULLUPNONOTG_MASK;
-}
-
-//--------------------------------------------------------------------+
-// Endpoint API
-//--------------------------------------------------------------------+
-bool dcd_edpt_open(uint8_t rhport, tusb_desc_endpoint_t const * ep_desc)
-{
- (void) rhport;
-
- const unsigned ep_addr = ep_desc->bEndpointAddress;
- const unsigned epn = ep_addr & 0xFu;
- const unsigned dir = (ep_addr & TUSB_DIR_IN_MASK) ? TUSB_DIR_IN : TUSB_DIR_OUT;
- const unsigned xfer = ep_desc->bmAttributes.xfer;
- endpoint_state_t *ep = &_dcd.endpoint[epn][dir];
- const unsigned odd = ep->odd;
- buffer_descriptor_t *bd = &_dcd.bdt[epn][dir][0];
-
- /* No support for control transfer */
- TU_ASSERT(epn && (xfer != TUSB_XFER_CONTROL));
-
- ep->max_packet_size = ep_desc->wMaxPacketSize.size;
- unsigned val = USB_ENDPT_EPCTLDIS_MASK;
- val |= (xfer != TUSB_XFER_ISOCHRONOUS) ? USB_ENDPT_EPHSHK_MASK: 0;
- val |= dir ? USB_ENDPT_EPTXEN_MASK : USB_ENDPT_EPRXEN_MASK;
- KHCI->ENDPOINT[epn].ENDPT |= val;
-
- if (xfer != TUSB_XFER_ISOCHRONOUS) {
- bd[odd].dts = 1;
- bd[odd].data = 0;
- bd[odd ^ 1].dts = 1;
- bd[odd ^ 1].data = 1;
- }
-
- return true;
-}
-
-void dcd_edpt_close(uint8_t rhport, uint8_t ep_addr)
-{
- (void) rhport;
-
- const unsigned epn = ep_addr & 0xFu;
- const unsigned dir = (ep_addr & TUSB_DIR_IN_MASK) ? TUSB_DIR_IN : TUSB_DIR_OUT;
- endpoint_state_t *ep = &_dcd.endpoint[epn][dir];
- buffer_descriptor_t *bd = &_dcd.bdt[epn][dir][0];
- const unsigned msk = dir ? USB_ENDPT_EPTXEN_MASK : USB_ENDPT_EPRXEN_MASK;
- KHCI->ENDPOINT[epn].ENDPT &= ~msk;
- ep->max_packet_size = 0;
- ep->length = 0;
- ep->remaining = 0;
- bd->head = 0;
-}
-
-bool dcd_edpt_xfer(uint8_t rhport, uint8_t ep_addr, uint8_t* buffer, uint16_t total_bytes)
-{
- (void) rhport;
- NVIC_DisableIRQ(USB0_IRQn);
- const unsigned epn = ep_addr & 0xFu;
- const unsigned dir = (ep_addr & TUSB_DIR_IN_MASK) ? TUSB_DIR_IN : TUSB_DIR_OUT;
- endpoint_state_t *ep = &_dcd.endpoint[epn][dir];
- buffer_descriptor_t *bd = &_dcd.bdt[epn][dir][ep->odd];
-
- if (bd->own) {
- TU_LOG1("DCD XFER fail %x %d %lx %lx\r\n", ep_addr, total_bytes, ep->state, bd->head);
- return false; /* The last transfer has not completed */
- }
- ep->length = total_bytes;
- ep->remaining = total_bytes;
-
- const unsigned mps = ep->max_packet_size;
- if (total_bytes > mps) {
- buffer_descriptor_t *next = ep->odd ? bd - 1: bd + 1;
- /* When total_bytes is greater than the max packet size,
- * it prepares to the next transfer to avoid NAK in advance. */
- next->bc = total_bytes >= 2 * mps ? mps: total_bytes - mps;
- next->addr = buffer + mps;
- next->own = 1;
- }
- bd->bc = total_bytes >= mps ? mps: total_bytes;
- bd->addr = buffer;
- __DSB();
- bd->own = 1; /* the own bit must set after addr */
- NVIC_EnableIRQ(USB0_IRQn);
- return true;
-}
-
-void dcd_edpt_stall(uint8_t rhport, uint8_t ep_addr)
-{
- (void) rhport;
- const unsigned epn = ep_addr & 0xFu;
- if (0 == epn) {
- KHCI->ENDPOINT[epn].ENDPT |= USB_ENDPT_EPSTALL_MASK;
- } else {
- const unsigned dir = (ep_addr & TUSB_DIR_IN_MASK) ? TUSB_DIR_IN : TUSB_DIR_OUT;
- buffer_descriptor_t *bd = _dcd.bdt[epn][dir];
- bd[0].bdt_stall = 1;
- bd[1].bdt_stall = 1;
- }
-}
-
-void dcd_edpt_clear_stall(uint8_t rhport, uint8_t ep_addr)
-{
- (void) rhport;
- const unsigned epn = ep_addr & 0xFu;
- const unsigned dir = (ep_addr & TUSB_DIR_IN_MASK) ? TUSB_DIR_IN : TUSB_DIR_OUT;
- const unsigned odd = _dcd.endpoint[epn][dir].odd;
- buffer_descriptor_t *bd = _dcd.bdt[epn][dir];
-
- bd[odd ^ 1].own = 0;
- bd[odd ^ 1].data = 1;
- bd[odd ^ 1].bdt_stall = 0;
- bd[odd].own = 0;
- bd[odd].data = 0;
- bd[odd].bdt_stall = 0;
-}
-
-//--------------------------------------------------------------------+
-// ISR
-//--------------------------------------------------------------------+
-void dcd_int_handler(uint8_t rhport)
-{
- (void) rhport;
-
- uint32_t is = KHCI->ISTAT;
- uint32_t msk = KHCI->INTEN;
- KHCI->ISTAT = is & ~msk;
- is &= msk;
- if (is & USB_ISTAT_ERROR_MASK) {
- /* TODO: */
- uint32_t es = KHCI->ERRSTAT;
- KHCI->ERRSTAT = es;
- KHCI->ISTAT = is; /* discard any pending events */
- return;
- }
-
- if (is & USB_ISTAT_USBRST_MASK) {
- KHCI->ISTAT = is; /* discard any pending events */
- process_bus_reset(rhport);
- return;
- }
- if (is & USB_ISTAT_SLEEP_MASK) {
- KHCI->ISTAT = USB_ISTAT_SLEEP_MASK;
- process_bus_inactive(rhport);
- return;
- }
- if (is & USB_ISTAT_RESUME_MASK) {
- KHCI->ISTAT = USB_ISTAT_RESUME_MASK;
- process_bus_active(rhport);
- return;
- }
- if (is & USB_ISTAT_SOFTOK_MASK) {
- KHCI->ISTAT = USB_ISTAT_SOFTOK_MASK;
- dcd_event_bus_signal(rhport, DCD_EVENT_SOF, true);
- return;
- }
- if (is & USB_ISTAT_STALL_MASK) {
- KHCI->ISTAT = USB_ISTAT_STALL_MASK;
- process_stall(rhport);
- return;
- }
- if (is & USB_ISTAT_TOKDNE_MASK) {
- process_tokdne(rhport);
- return;
- }
-}
-
-#endif
diff --git a/tinyusb/src/portable/nxp/lpc17_40/dcd_lpc17_40.c b/tinyusb/src/portable/nxp/lpc17_40/dcd_lpc17_40.c
deleted file mode 100755
index 519d0915..00000000
--- a/tinyusb/src/portable/nxp/lpc17_40/dcd_lpc17_40.c
+++ /dev/null
@@ -1,582 +0,0 @@
-/*
- * The MIT License (MIT)
- *
- * Copyright (c) 2019 Ha Thach (tinyusb.org)
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- *
- * This file is part of the TinyUSB stack.
- */
-
-#include "tusb_option.h"
-
-#if TUSB_OPT_DEVICE_ENABLED && \
- (CFG_TUSB_MCU == OPT_MCU_LPC175X_6X || CFG_TUSB_MCU == OPT_MCU_LPC177X_8X || CFG_TUSB_MCU == OPT_MCU_LPC40XX)
-
-#include "device/dcd.h"
-#include "dcd_lpc17_40.h"
-#include "chip.h"
-
-//--------------------------------------------------------------------+
-// MACRO CONSTANT TYPEDEF
-//--------------------------------------------------------------------+
-#define DCD_ENDPOINT_MAX 32
-
-typedef struct TU_ATTR_ALIGNED(4)
-{
- //------------- Word 0 -------------//
- uint32_t next;
-
- //------------- Word 1 -------------//
- uint16_t atle_mode : 2; // 00: normal, 01: ATLE (auto length extraction)
- uint16_t next_valid : 1;
- uint16_t : 1; ///< reserved
- uint16_t isochronous : 1; // is an iso endpoint
- uint16_t max_packet_size : 11;
-
- volatile uint16_t buflen; // bytes for non-iso, number of packets for iso endpoint
-
- //------------- Word 2 -------------//
- volatile uint32_t buffer;
-
- //------------- Word 3 -------------//
- volatile uint16_t retired : 1; // initialized to zero
- volatile uint16_t status : 4;
- volatile uint16_t iso_last_packet_valid : 1;
- volatile uint16_t atle_lsb_extracted : 1; // used in ATLE mode
- volatile uint16_t atle_msb_extracted : 1; // used in ATLE mode
- volatile uint16_t atle_mess_len_position : 6; // used in ATLE mode
- uint16_t : 2;
-
- volatile uint16_t present_count; // For non-iso : The number of bytes transferred by the DMA engine
- // For iso : number of packets
-
- //------------- Word 4 -------------//
- // uint32_t iso_packet_size_addr; // iso only, can be omitted for non-iso
-}dma_desc_t;
-
-TU_VERIFY_STATIC( sizeof(dma_desc_t) == 16, "size is not correct"); // TODO not support ISO for now
-
-typedef struct
-{
- // must be 128 byte aligned
- volatile dma_desc_t* udca[DCD_ENDPOINT_MAX];
-
- // TODO DMA does not support control transfer (0-1 are not used, offset to reduce memory)
- dma_desc_t dd[DCD_ENDPOINT_MAX];
-
- struct
- {
- uint8_t* out_buffer;
- uint8_t out_bytes;
- volatile bool out_received; // indicate if data is already received in endpoint
-
- uint8_t in_bytes;
- } control;
-
-} dcd_data_t;
-
-CFG_TUSB_MEM_SECTION TU_ATTR_ALIGNED(128) static dcd_data_t _dcd;
-
-
-//--------------------------------------------------------------------+
-// SIE Command
-//--------------------------------------------------------------------+
-static void sie_cmd_code (sie_cmdphase_t phase, uint8_t code_data)
-{
- LPC_USB->DevIntClr = (DEV_INT_COMMAND_CODE_EMPTY_MASK | DEV_INT_COMMAND_DATA_FULL_MASK);
- LPC_USB->CmdCode = (phase << 8) | (code_data << 16);
-
- uint32_t const wait_flag = (phase == SIE_CMDPHASE_READ) ? DEV_INT_COMMAND_DATA_FULL_MASK : DEV_INT_COMMAND_CODE_EMPTY_MASK;
- while ((LPC_USB->DevIntSt & wait_flag) == 0) {}
-
- LPC_USB->DevIntClr = wait_flag;
-}
-
-static void sie_write (uint8_t cmd_code, uint8_t data_len, uint8_t data)
-{
- sie_cmd_code(SIE_CMDPHASE_COMMAND, cmd_code);
-
- if (data_len)
- {
- sie_cmd_code(SIE_CMDPHASE_WRITE, data);
- }
-}
-
-static uint8_t sie_read (uint8_t cmd_code)
-{
- sie_cmd_code(SIE_CMDPHASE_COMMAND , cmd_code);
- sie_cmd_code(SIE_CMDPHASE_READ , cmd_code);
- return (uint8_t) LPC_USB->CmdData;
-}
-
-//--------------------------------------------------------------------+
-// PIPE HELPER
-//--------------------------------------------------------------------+
-static inline uint8_t ep_addr2idx(uint8_t ep_addr)
-{
- return 2*(ep_addr & 0x0F) + ((ep_addr & TUSB_DIR_IN_MASK) ? 1 : 0);
-}
-
-static void set_ep_size(uint8_t ep_id, uint16_t max_packet_size)
-{
- // follows example in 11.10.4.2
- LPC_USB->ReEp |= TU_BIT(ep_id);
- LPC_USB->EpInd = ep_id; // select index before setting packet size
- LPC_USB->MaxPSize = max_packet_size;
-
- while ((LPC_USB->DevIntSt & DEV_INT_ENDPOINT_REALIZED_MASK) == 0) {}
- LPC_USB->DevIntClr = DEV_INT_ENDPOINT_REALIZED_MASK;
-}
-
-
-//--------------------------------------------------------------------+
-// CONTROLLER API
-//--------------------------------------------------------------------+
-static void bus_reset(void)
-{
- // step 7 : slave mode set up
- LPC_USB->EpIntClr = 0xFFFFFFFF; // clear all pending interrupt
- LPC_USB->DevIntClr = 0xFFFFFFFF; // clear all pending interrupt
- LPC_USB->EpIntEn = 0x03UL; // control endpoint cannot use DMA, non-control all use DMA
- LPC_USB->EpIntPri = 0x03UL; // fast for control endpoint
-
- // step 8 : DMA set up
- LPC_USB->EpDMADis = 0xFFFFFFFF; // firstly disable all dma
- LPC_USB->DMARClr = 0xFFFFFFFF; // clear all pending interrupt
- LPC_USB->EoTIntClr = 0xFFFFFFFF;
- LPC_USB->NDDRIntClr = 0xFFFFFFFF;
- LPC_USB->SysErrIntClr = 0xFFFFFFFF;
-
- tu_memclr(&_dcd, sizeof(dcd_data_t));
-}
-
-void dcd_init(uint8_t rhport)
-{
- (void) rhport;
-
- //------------- user manual 11.13 usb device controller initialization -------------//
- // step 6 : set up control endpoint
- set_ep_size(0, CFG_TUD_ENDPOINT0_SIZE);
- set_ep_size(1, CFG_TUD_ENDPOINT0_SIZE);
-
- bus_reset();
-
- LPC_USB->DevIntEn = (DEV_INT_DEVICE_STATUS_MASK | DEV_INT_ENDPOINT_FAST_MASK | DEV_INT_ENDPOINT_SLOW_MASK | DEV_INT_ERROR_MASK);
- LPC_USB->UDCAH = (uint32_t) _dcd.udca;
- LPC_USB->DMAIntEn = (DMA_INT_END_OF_XFER_MASK /*| DMA_INT_NEW_DD_REQUEST_MASK*/ | DMA_INT_ERROR_MASK);
-
- dcd_connect(rhport);
-
- // Clear pending IRQ
- NVIC_ClearPendingIRQ(USB_IRQn);
-}
-
-void dcd_int_enable(uint8_t rhport)
-{
- (void) rhport;
- NVIC_EnableIRQ(USB_IRQn);
-}
-
-void dcd_int_disable(uint8_t rhport)
-{
- (void) rhport;
- NVIC_DisableIRQ(USB_IRQn);
-}
-
-void dcd_set_address(uint8_t rhport, uint8_t dev_addr)
-{
- // Response with status first before changing device address
- dcd_edpt_xfer(rhport, tu_edpt_addr(0, TUSB_DIR_IN), NULL, 0);
-
- sie_write(SIE_CMDCODE_SET_ADDRESS, 1, 0x80 | dev_addr); // 7th bit is : device_enable
-
- // Also Set Configure Device to enable non-control endpoint response
- sie_write(SIE_CMDCODE_CONFIGURE_DEVICE, 1, 1);
-}
-
-void dcd_remote_wakeup(uint8_t rhport)
-{
- (void) rhport;
-}
-
-void dcd_connect(uint8_t rhport)
-{
- (void) rhport;
- sie_write(SIE_CMDCODE_DEVICE_STATUS, 1, SIE_DEV_STATUS_CONNECT_STATUS_MASK);
-}
-
-void dcd_disconnect(uint8_t rhport)
-{
- (void) rhport;
- sie_write(SIE_CMDCODE_DEVICE_STATUS, 1, 0);
-}
-
-//--------------------------------------------------------------------+
-// CONTROL HELPER
-//--------------------------------------------------------------------+
-static inline uint8_t byte2dword(uint8_t bytes)
-{
- return (bytes + 3) / 4; // length in dwords
-}
-
-static void control_ep_write(void const * buffer, uint8_t len)
-{
- uint32_t const * buf32 = (uint32_t const *) buffer;
-
- LPC_USB->Ctrl = USBCTRL_WRITE_ENABLE_MASK; // logical endpoint = 0
- LPC_USB->TxPLen = (uint32_t) len;
-
- for (uint8_t count = 0; count < byte2dword(len); count++)
- {
- LPC_USB->TxData = *buf32; // NOTE: cortex M3 have no problem with alignment
- buf32++;
- }
-
- LPC_USB->Ctrl = 0;
-
- // select control IN & validate the endpoint
- sie_write(SIE_CMDCODE_ENDPOINT_SELECT+1, 0, 0);
- sie_write(SIE_CMDCODE_BUFFER_VALIDATE , 0, 0);
-}
-
-static uint8_t control_ep_read(void * buffer, uint8_t len)
-{
- LPC_USB->Ctrl = USBCTRL_READ_ENABLE_MASK; // logical endpoint = 0
- while ((LPC_USB->RxPLen & USBRXPLEN_PACKET_READY_MASK) == 0) {} // TODO blocking, should have timeout
-
- len = tu_min8(len, (uint8_t) (LPC_USB->RxPLen & USBRXPLEN_PACKET_LENGTH_MASK) );
- uint32_t *buf32 = (uint32_t*) buffer;
-
- for (uint8_t count=0; count < byte2dword(len); count++)
- {
- *buf32 = LPC_USB->RxData;
- buf32++;
- }
-
- LPC_USB->Ctrl = 0;
-
- // select control OUT & clear the endpoint
- sie_write(SIE_CMDCODE_ENDPOINT_SELECT+0, 0, 0);
- sie_write(SIE_CMDCODE_BUFFER_CLEAR , 0, 0);
-
- return len;
-}
-
-//--------------------------------------------------------------------+
-// DCD Endpoint Port
-//--------------------------------------------------------------------+
-
-bool dcd_edpt_open(uint8_t rhport, tusb_desc_endpoint_t const * p_endpoint_desc)
-{
- (void) rhport;
-
- uint8_t const epnum = tu_edpt_number(p_endpoint_desc->bEndpointAddress);
- uint8_t const ep_id = ep_addr2idx(p_endpoint_desc->bEndpointAddress);
-
- // Endpoint type is fixed to endpoint number
- // 1: interrupt, 2: Bulk, 3: Iso and so on
- switch ( p_endpoint_desc->bmAttributes.xfer )
- {
- case TUSB_XFER_INTERRUPT:
- TU_ASSERT((epnum % 3) == 1);
- break;
-
- case TUSB_XFER_BULK:
- TU_ASSERT((epnum % 3) == 2 || (epnum == 15));
- break;
-
- case TUSB_XFER_ISOCHRONOUS:
- TU_ASSERT((epnum % 3) == 0 && (epnum != 0) && (epnum != 15));
- break;
-
- default:
- break;
- }
-
- //------------- Realize Endpoint with Max Packet Size -------------//
- set_ep_size(ep_id, p_endpoint_desc->wMaxPacketSize.size);
-
- //------------- first DD prepare -------------//
- dma_desc_t* const dd = &_dcd.dd[ep_id];
- tu_memclr(dd, sizeof(dma_desc_t));
-
- dd->isochronous = (p_endpoint_desc->bmAttributes.xfer == TUSB_XFER_ISOCHRONOUS) ? 1 : 0;
- dd->max_packet_size = p_endpoint_desc->wMaxPacketSize.size;
- dd->retired = 1; // invalid at first
-
- sie_write(SIE_CMDCODE_ENDPOINT_SET_STATUS + ep_id, 1, 0); // clear all endpoint status
-
- return true;
-}
-
-void dcd_edpt_stall(uint8_t rhport, uint8_t ep_addr)
-{
- (void) rhport;
-
- if ( tu_edpt_number(ep_addr) == 0 )
- {
- sie_write(SIE_CMDCODE_ENDPOINT_SET_STATUS+0, 1, SIE_SET_ENDPOINT_STALLED_MASK | SIE_SET_ENDPOINT_CONDITION_STALLED_MASK);
- }else
- {
- uint8_t ep_id = ep_addr2idx( ep_addr );
- sie_write(SIE_CMDCODE_ENDPOINT_SET_STATUS+ep_id, 1, SIE_SET_ENDPOINT_STALLED_MASK);
- }
-}
-
-void dcd_edpt_clear_stall(uint8_t rhport, uint8_t ep_addr)
-{
- (void) rhport;
- uint8_t ep_id = ep_addr2idx(ep_addr);
-
- sie_write(SIE_CMDCODE_ENDPOINT_SET_STATUS+ep_id, 1, 0);
-}
-
-static bool control_xact(uint8_t rhport, uint8_t dir, uint8_t * buffer, uint8_t len)
-{
- (void) rhport;
-
- if ( dir )
- {
- _dcd.control.in_bytes = len;
- control_ep_write(buffer, len);
- }else
- {
- if ( _dcd.control.out_received )
- {
- // Already received the DATA OUT packet
- _dcd.control.out_received = false;
- _dcd.control.out_buffer = NULL;
- _dcd.control.out_bytes = 0;
-
- uint8_t received = control_ep_read(buffer, len);
- dcd_event_xfer_complete(0, 0, received, XFER_RESULT_SUCCESS, true);
- }else
- {
- _dcd.control.out_buffer = buffer;
- _dcd.control.out_bytes = len;
- }
- }
-
- return true;
-}
-
-bool dcd_edpt_xfer (uint8_t rhport, uint8_t ep_addr, uint8_t* buffer, uint16_t total_bytes)
-{
- // Control transfer is not DMA support, and must be done in slave mode
- if ( tu_edpt_number(ep_addr) == 0 )
- {
- return control_xact(rhport, tu_edpt_dir(ep_addr), buffer, (uint8_t) total_bytes);
- }
- else
- {
- uint8_t ep_id = ep_addr2idx(ep_addr);
- dma_desc_t* dd = &_dcd.dd[ep_id];
-
- // Prepare DMA descriptor
- // Isochronous & max packet size must be preserved, Other fields of dd should be clear
- uint16_t const ep_size = dd->max_packet_size;
- uint8_t is_iso = dd->isochronous;
-
- tu_memclr(dd, sizeof(dma_desc_t));
- dd->isochronous = is_iso;
- dd->max_packet_size = ep_size;
- dd->buffer = (uint32_t) buffer;
- dd->buflen = total_bytes;
-
- _dcd.udca[ep_id] = dd;
-
- if ( ep_id % 2 )
- {
- // Clear EP interrupt before Enable DMA
- LPC_USB->EpIntEn &= ~TU_BIT(ep_id);
- LPC_USB->EpDMAEn = TU_BIT(ep_id);
-
- // endpoint IN need to actively raise DMA request
- LPC_USB->DMARSet = TU_BIT(ep_id);
- }else
- {
- // Enable DMA
- LPC_USB->EpDMAEn = TU_BIT(ep_id);
- }
-
- return true;
- }
-}
-
-//--------------------------------------------------------------------+
-// ISR
-//--------------------------------------------------------------------+
-
-// handle control xfer (slave mode)
-static void control_xfer_isr(uint8_t rhport, uint32_t ep_int_status)
-{
- // Control out complete
- if ( ep_int_status & TU_BIT(0) )
- {
- bool is_setup = sie_read(SIE_CMDCODE_ENDPOINT_SELECT+0) & SIE_SELECT_ENDPOINT_SETUP_RECEIVED_MASK;
-
- LPC_USB->EpIntClr = TU_BIT(0);
-
- if (is_setup)
- {
- uint8_t setup_packet[8];
- control_ep_read(setup_packet, 8); // TODO read before clear setup above
-
- dcd_event_setup_received(rhport, setup_packet, true);
- }
- else if ( _dcd.control.out_buffer )
- {
- // software queued transfer previously
- uint8_t received = control_ep_read(_dcd.control.out_buffer, _dcd.control.out_bytes);
-
- _dcd.control.out_buffer = NULL;
- _dcd.control.out_bytes = 0;
-
- dcd_event_xfer_complete(rhport, 0, received, XFER_RESULT_SUCCESS, true);
- }else
- {
- // hardware auto ack packet -> mark as received
- _dcd.control.out_received = true;
- }
- }
-
- // Control In complete
- if ( ep_int_status & TU_BIT(1) )
- {
- LPC_USB->EpIntClr = TU_BIT(1);
- dcd_event_xfer_complete(rhport, TUSB_DIR_IN_MASK, _dcd.control.in_bytes, XFER_RESULT_SUCCESS, true);
- }
-}
-
-// handle bus event signal
-static void bus_event_isr(uint8_t rhport)
-{
- uint8_t const dev_status = sie_read(SIE_CMDCODE_DEVICE_STATUS);
- if (dev_status & SIE_DEV_STATUS_RESET_MASK)
- {
- bus_reset();
- dcd_event_bus_reset(rhport, TUSB_SPEED_FULL, true);
- }
-
- if (dev_status & SIE_DEV_STATUS_CONNECT_CHANGE_MASK)
- {
- // device is disconnected, require using VBUS (P1_30)
- dcd_event_bus_signal(rhport, DCD_EVENT_UNPLUGGED, true);
- }
-
- if (dev_status & SIE_DEV_STATUS_SUSPEND_CHANGE_MASK)
- {
- if (dev_status & SIE_DEV_STATUS_SUSPEND_MASK)
- {
- dcd_event_bus_signal(rhport, DCD_EVENT_SUSPEND, true);
- }
- else
- {
- dcd_event_bus_signal(rhport, DCD_EVENT_RESUME, true);
- }
- }
-}
-
-// Helper to complete a DMA descriptor for non-control transfer
-static void dd_complete_isr(uint8_t rhport, uint8_t ep_id)
-{
- dma_desc_t* const dd = &_dcd.dd[ep_id];
- uint8_t result = (dd->status == DD_STATUS_NORMAL || dd->status == DD_STATUS_DATA_UNDERUN) ? XFER_RESULT_SUCCESS : XFER_RESULT_FAILED;
- uint8_t const ep_addr = (ep_id / 2) | ((ep_id & 0x01) ? TUSB_DIR_IN_MASK : 0);
-
- dcd_event_xfer_complete(rhport, ep_addr, dd->present_count, result, true);
-}
-
-// main USB IRQ handler
-void dcd_int_handler(uint8_t rhport)
-{
- uint32_t const dev_int_status = LPC_USB->DevIntSt & LPC_USB->DevIntEn;
- LPC_USB->DevIntClr = dev_int_status;// Acknowledge handled interrupt
-
- // Bus event
- if (dev_int_status & DEV_INT_DEVICE_STATUS_MASK)
- {
- bus_event_isr(rhport);
- }
-
- // Endpoint interrupt
- uint32_t const ep_int_status = LPC_USB->EpIntSt & LPC_USB->EpIntEn;
-
- // Control Endpoint are fast
- if (dev_int_status & DEV_INT_ENDPOINT_FAST_MASK)
- {
- // Note clear USBEpIntClr will also clear the setup received bit --> clear after handle setup packet
- // Only clear USBEpIntClr 1 endpoint each, and should wait for CDFULL bit set
- control_xfer_isr(rhport, ep_int_status);
- }
-
- // non-control IN are slow
- if (dev_int_status & DEV_INT_ENDPOINT_SLOW_MASK)
- {
- for ( uint8_t ep_id = 3; ep_id < DCD_ENDPOINT_MAX; ep_id += 2 )
- {
- if ( tu_bit_test(ep_int_status, ep_id) )
- {
- LPC_USB->EpIntClr = TU_BIT(ep_id);
-
- // Clear Ep interrupt for next DMA
- LPC_USB->EpIntEn &= ~TU_BIT(ep_id);
-
- dd_complete_isr(rhport, ep_id);
- }
- }
- }
-
- // DMA transfer complete (RAM <-> EP) for Non-Control
- // OUT: USB transfer is fully complete
- // IN : UBS transfer is still on-going -> enable EpIntEn to know when it is complete
- uint32_t const dma_int_status = LPC_USB->DMAIntSt & LPC_USB->DMAIntEn;
- if (dma_int_status & DMA_INT_END_OF_XFER_MASK)
- {
- uint32_t const eot = LPC_USB->EoTIntSt;
- LPC_USB->EoTIntClr = eot; // acknowledge interrupt source
-
- for ( uint8_t ep_id = 2; ep_id < DCD_ENDPOINT_MAX; ep_id++ )
- {
- if ( tu_bit_test(eot, ep_id) )
- {
- if ( ep_id & 0x01 )
- {
- // IN enable EpInt for end of usb transfer
- LPC_USB->EpIntEn |= TU_BIT(ep_id);
- }else
- {
- // OUT
- dd_complete_isr(rhport, ep_id);
- }
- }
- }
- }
-
- // Errors
- if ( (dev_int_status & DEV_INT_ERROR_MASK) || (dma_int_status & DMA_INT_ERROR_MASK) )
- {
- uint32_t error_status = sie_read(SIE_CMDCODE_READ_ERROR_STATUS);
- (void) error_status;
- TU_BREAKPOINT();
- }
-}
-
-#endif
diff --git a/tinyusb/src/portable/nxp/lpc17_40/dcd_lpc17_40.h b/tinyusb/src/portable/nxp/lpc17_40/dcd_lpc17_40.h
deleted file mode 100755
index 07daa32e..00000000
--- a/tinyusb/src/portable/nxp/lpc17_40/dcd_lpc17_40.h
+++ /dev/null
@@ -1,152 +0,0 @@
-/*
- * The MIT License (MIT)
- *
- * Copyright (c) 2019 Ha Thach (tinyusb.org)
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- *
- * This file is part of the TinyUSB stack.
- */
-
-#ifndef _TUSB_DCD_LPC17_40_H_
-#define _TUSB_DCD_LPC17_40_H_
-
-#include "common/tusb_common.h"
-
-#ifdef __cplusplus
- extern "C" {
-#endif
-
-//--------------------------------------------------------------------+
-// Register Interface
-//--------------------------------------------------------------------+
-
-//------------- USB Interrupt USBIntSt -------------//
-//enum {
-// DCD_USB_REQ_LOW_PRIO_MASK = TU_BIT(0),
-// DCD_USB_REQ_HIGH_PRIO_MASK = TU_BIT(1),
-// DCD_USB_REQ_DMA_MASK = TU_BIT(2),
-// DCD_USB_REQ_NEED_CLOCK_MASK = TU_BIT(8),
-// DCD_USB_REQ_ENABLE_MASK = TU_BIT(31)
-//};
-
-//------------- Device Interrupt USBDevInt -------------//
-enum {
- DEV_INT_FRAME_MASK = TU_BIT(0),
- DEV_INT_ENDPOINT_FAST_MASK = TU_BIT(1),
- DEV_INT_ENDPOINT_SLOW_MASK = TU_BIT(2),
- DEV_INT_DEVICE_STATUS_MASK = TU_BIT(3),
- DEV_INT_COMMAND_CODE_EMPTY_MASK = TU_BIT(4),
- DEV_INT_COMMAND_DATA_FULL_MASK = TU_BIT(5),
- DEV_INT_RX_ENDPOINT_PACKET_MASK = TU_BIT(6),
- DEV_INT_TX_ENDPOINT_PACKET_MASK = TU_BIT(7),
- DEV_INT_ENDPOINT_REALIZED_MASK = TU_BIT(8),
- DEV_INT_ERROR_MASK = TU_BIT(9)
-};
-
-//------------- DMA Interrupt USBDMAInt-------------//
-enum {
- DMA_INT_END_OF_XFER_MASK = TU_BIT(0),
- DMA_INT_NEW_DD_REQUEST_MASK = TU_BIT(1),
- DMA_INT_ERROR_MASK = TU_BIT(2)
-};
-
-//------------- USBCtrl -------------//
-enum {
- USBCTRL_READ_ENABLE_MASK = TU_BIT(0),
- USBCTRL_WRITE_ENABLE_MASK = TU_BIT(1),
-};
-
-//------------- USBRxPLen -------------//
-enum {
- USBRXPLEN_PACKET_LENGTH_MASK = (TU_BIT(10)-1),
- USBRXPLEN_DATA_VALID_MASK = TU_BIT(10),
- USBRXPLEN_PACKET_READY_MASK = TU_BIT(11),
-};
-
-//------------- SIE Command Code -------------//
-typedef enum
-{
- SIE_CMDPHASE_WRITE = 1,
- SIE_CMDPHASE_READ = 2,
- SIE_CMDPHASE_COMMAND = 5
-} sie_cmdphase_t;
-
-enum {
- // device commands
- SIE_CMDCODE_SET_ADDRESS = 0xd0,
- SIE_CMDCODE_CONFIGURE_DEVICE = 0xd8,
- SIE_CMDCODE_SET_MODE = 0xf3,
- SIE_CMDCODE_READ_FRAME_NUMBER = 0xf5,
- SIE_CMDCODE_READ_TEST_REGISTER = 0xfd,
- SIE_CMDCODE_DEVICE_STATUS = 0xfe,
- SIE_CMDCODE_GET_ERROR = 0xff,
- SIE_CMDCODE_READ_ERROR_STATUS = 0xfb,
-
- // endpoint commands
- SIE_CMDCODE_ENDPOINT_SELECT = 0x00, // + endpoint index
- SIE_CMDCODE_ENDPOINT_SELECT_CLEAR_INTERRUPT = 0x40, // + endpoint index, should use USBEpIntClr instead
- SIE_CMDCODE_ENDPOINT_SET_STATUS = 0x40, // + endpoint index
- SIE_CMDCODE_BUFFER_CLEAR = 0xf2,
- SIE_CMDCODE_BUFFER_VALIDATE = 0xfa
-};
-
-//------------- SIE Device Status (get/set from SIE_CMDCODE_DEVICE_STATUS) -------------//
-enum {
- SIE_DEV_STATUS_CONNECT_STATUS_MASK = TU_BIT(0),
- SIE_DEV_STATUS_CONNECT_CHANGE_MASK = TU_BIT(1),
- SIE_DEV_STATUS_SUSPEND_MASK = TU_BIT(2),
- SIE_DEV_STATUS_SUSPEND_CHANGE_MASK = TU_BIT(3),
- SIE_DEV_STATUS_RESET_MASK = TU_BIT(4)
-};
-
-//------------- SIE Select Endpoint Command -------------//
-enum {
- SIE_SELECT_ENDPOINT_FULL_EMPTY_MASK = TU_BIT(0), // 0: empty, 1 full. IN endpoint checks empty, OUT endpoint check full
- SIE_SELECT_ENDPOINT_STALL_MASK = TU_BIT(1),
- SIE_SELECT_ENDPOINT_SETUP_RECEIVED_MASK = TU_BIT(2), // clear by SIE_CMDCODE_ENDPOINT_SELECT_CLEAR_INTERRUPT
- SIE_SELECT_ENDPOINT_PACKET_OVERWRITTEN_MASK = TU_BIT(3), // previous packet is overwritten by a SETUP packet
- SIE_SELECT_ENDPOINT_NAK_MASK = TU_BIT(4), // last packet response is NAK (auto clear by an ACK)
- SIE_SELECT_ENDPOINT_BUFFER1_FULL_MASK = TU_BIT(5),
- SIE_SELECT_ENDPOINT_BUFFER2_FULL_MASK = TU_BIT(6)
-};
-
-typedef enum
-{
- SIE_SET_ENDPOINT_STALLED_MASK = TU_BIT(0),
- SIE_SET_ENDPOINT_DISABLED_MASK = TU_BIT(5),
- SIE_SET_ENDPOINT_RATE_FEEDBACK_MASK = TU_BIT(6),
- SIE_SET_ENDPOINT_CONDITION_STALLED_MASK = TU_BIT(7),
-}sie_endpoint_set_status_mask_t;
-
-//------------- DMA Descriptor Status -------------//
-enum {
- DD_STATUS_NOT_SERVICED = 0,
- DD_STATUS_BEING_SERVICED,
- DD_STATUS_NORMAL,
- DD_STATUS_DATA_UNDERUN, // short packet
- DD_STATUS_DATA_OVERRUN,
- DD_STATUS_SYSTEM_ERROR
-};
-
-#ifdef __cplusplus
- }
-#endif
-
-#endif
diff --git a/tinyusb/src/portable/nxp/lpc17_40/hcd_lpc17_40.c b/tinyusb/src/portable/nxp/lpc17_40/hcd_lpc17_40.c
deleted file mode 100755
index 1c1faed9..00000000
--- a/tinyusb/src/portable/nxp/lpc17_40/hcd_lpc17_40.c
+++ /dev/null
@@ -1,47 +0,0 @@
-/*
- * The MIT License (MIT)
- *
- * Copyright (c) 2019, Ha Thach (tinyusb.org)
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- *
- * This file is part of the TinyUSB stack.
- */
-
-#include "tusb_option.h"
-
-#if TUSB_OPT_HOST_ENABLED && \
- (CFG_TUSB_MCU == OPT_MCU_LPC175X_6X || CFG_TUSB_MCU == OPT_MCU_LPC177X_8X || CFG_TUSB_MCU == OPT_MCU_LPC40XX)
-
-#include "chip.h"
-
-void hcd_int_enable(uint8_t rhport)
-{
- (void) rhport;
- NVIC_EnableIRQ(USB_IRQn);
-}
-
-void hcd_int_disable(uint8_t rhport)
-{
- (void) rhport;
- NVIC_DisableIRQ(USB_IRQn);
-}
-
-#endif
-
diff --git a/tinyusb/src/portable/nxp/lpc_ip3511/dcd_lpc_ip3511.c b/tinyusb/src/portable/nxp/lpc_ip3511/dcd_lpc_ip3511.c
deleted file mode 100755
index 4392d188..00000000
--- a/tinyusb/src/portable/nxp/lpc_ip3511/dcd_lpc_ip3511.c
+++ /dev/null
@@ -1,537 +0,0 @@
-/*
- * The MIT License (MIT)
- *
- * Copyright (c) 2019 Ha Thach (tinyusb.org)
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- *
- * This file is part of the TinyUSB stack.
- */
-
-#include "tusb_option.h"
-
-/* Since 2012 starting with LPC11uxx, NXP start to use common USB Device Controller with code name LPC IP3511
- * for almost their new MCUs. Currently supported and tested families are
- * - LPC11U68, LPC11U37
- * - LPC1347
- * - LPC51U68
- * - LPC54114
- * - LPC55s69
- */
-#if TUSB_OPT_DEVICE_ENABLED && ( CFG_TUSB_MCU == OPT_MCU_LPC11UXX || \
- CFG_TUSB_MCU == OPT_MCU_LPC13XX || \
- CFG_TUSB_MCU == OPT_MCU_LPC15XX || \
- CFG_TUSB_MCU == OPT_MCU_LPC51UXX || \
- CFG_TUSB_MCU == OPT_MCU_LPC54XXX || \
- CFG_TUSB_MCU == OPT_MCU_LPC55XX)
-
-//--------------------------------------------------------------------+
-// INCLUDE
-//--------------------------------------------------------------------+
-
-#if CFG_TUSB_MCU == OPT_MCU_LPC11UXX || CFG_TUSB_MCU == OPT_MCU_LPC13XX || CFG_TUSB_MCU == OPT_MCU_LPC15XX
- // LPCOpen
- #include "chip.h"
-#else
- // SDK
- #include "fsl_device_registers.h"
- #define INCLUDE_FSL_DEVICE_REGISTERS
-#endif
-
-#include "device/dcd.h"
-
-//--------------------------------------------------------------------+
-// IP3511 Registers
-//--------------------------------------------------------------------+
-
-typedef struct {
- __IO uint32_t DEVCMDSTAT; // Device Command/Status register, offset: 0x0
- __I uint32_t INFO; // Info register, offset: 0x4
- __IO uint32_t EPLISTSTART; // EP Command/Status List start address, offset: 0x8
- __IO uint32_t DATABUFSTART; // Data buffer start address, offset: 0xC
- __IO uint32_t LPM; // Link Power Management register, offset: 0x10
- __IO uint32_t EPSKIP; // Endpoint skip, offset: 0x14
- __IO uint32_t EPINUSE; // Endpoint Buffer in use, offset: 0x18
- __IO uint32_t EPBUFCFG; // Endpoint Buffer Configuration register, offset: 0x1C
- __IO uint32_t INTSTAT; // interrupt status register, offset: 0x20
- __IO uint32_t INTEN; // interrupt enable register, offset: 0x24
- __IO uint32_t INTSETSTAT; // set interrupt status register, offset: 0x28
- uint8_t RESERVED_0[8];
- __I uint32_t EPTOGGLE; // Endpoint toggle register, offset: 0x34
-} dcd_registers_t;
-
-// Max nbytes for each control/bulk/interrupt transfer
-enum {
- NBYTES_CBI_FULLSPEED_MAX = 64,
- NBYTES_CBI_HIGHSPEED_MAX = 32767 // can be up to all 15-bit, but only tested with 4096
-};
-
-enum {
- INT_SOF_MASK = TU_BIT(30),
- INT_DEVICE_STATUS_MASK = TU_BIT(31)
-};
-
-enum {
- CMDSTAT_DEVICE_ADDR_MASK = TU_BIT(7 )-1,
- CMDSTAT_DEVICE_ENABLE_MASK = TU_BIT(7 ),
- CMDSTAT_SETUP_RECEIVED_MASK = TU_BIT(8 ),
- CMDSTAT_DEVICE_CONNECT_MASK = TU_BIT(16), // reflect the soft-connect only, does not reflect the actual attached state
- CMDSTAT_DEVICE_SUSPEND_MASK = TU_BIT(17),
- // 23-22 is link speed (only available for HighSpeed port)
- CMDSTAT_CONNECT_CHANGE_MASK = TU_BIT(24),
- CMDSTAT_SUSPEND_CHANGE_MASK = TU_BIT(25),
- CMDSTAT_RESET_CHANGE_MASK = TU_BIT(26),
- CMDSTAT_VBUS_DEBOUNCED_MASK = TU_BIT(28),
-};
-
-enum {
- CMDSTAT_SPEED_SHIFT = 22
-};
-
-//--------------------------------------------------------------------+
-// Endpoint Command/Status List
-//--------------------------------------------------------------------+
-
-// Endpoint Command/Status
-typedef union TU_ATTR_PACKED
-{
- // Full and High speed has different bit layout for buffer_offset and nbytes
-
- // Buffer (aligned 64) = DATABUFSTART [31:22] | buffer_offset [21:6]
- volatile struct {
- uint32_t offset : 16;
- uint32_t nbytes : 10;
- uint32_t TU_RESERVED : 6;
- } buffer_fs;
-
- // Buffer (aligned 64) = USB_RAM [31:17] | buffer_offset [16:6]
- volatile struct {
- uint32_t offset : 11 ;
- uint32_t nbytes : 15 ;
- uint32_t TU_RESERVED : 6 ;
- } buffer_hs;
-
- volatile struct {
- uint32_t TU_RESERVED : 26;
- uint32_t is_iso : 1 ;
- uint32_t toggle_mode : 1 ;
- uint32_t toggle_reset : 1 ;
- uint32_t stall : 1 ;
- uint32_t disable : 1 ;
- uint32_t active : 1 ;
- };
-}ep_cmd_sts_t;
-
-TU_VERIFY_STATIC( sizeof(ep_cmd_sts_t) == 4, "size is not correct" );
-
-// Software transfer management
-typedef struct
-{
- uint16_t total_bytes;
- uint16_t xferred_bytes;
-
- uint16_t nbytes;
-
- // prevent unaligned access on Highspeed port on USB_SRAM
- uint16_t TU_RESERVED;
-}xfer_dma_t;
-
-// Absolute max of endpoints pairs for all port
-// - 11 13 15 51 54 has 5x2 endpoints
-// - 55 usb0 (FS) has 5x2 endpoints, usb1 (HS) has 6x2 endpoints
-#define MAX_EP_PAIRS 6
-
-// NOTE data will be transferred as soon as dcd get request by dcd_pipe(_queue)_xfer using double buffering.
-// current_td is used to keep track of number of remaining & xferred bytes of the current request.
-typedef struct
-{
- // 256 byte aligned, 2 for double buffer (not used)
- // Each cmd_sts can only transfer up to DMA_NBYTES_MAX bytes each
- ep_cmd_sts_t ep[2*MAX_EP_PAIRS][2];
- xfer_dma_t dma[2*MAX_EP_PAIRS];
-
- TU_ATTR_ALIGNED(64) uint8_t setup_packet[8];
-}dcd_data_t;
-
-// EP list must be 256-byte aligned
-// Some MCU controller may require this variable to be placed in specific SRAM region.
-// For example: LPC55s69 port1 Highspeed must be USB_RAM (0x40100000)
-// Use CFG_TUSB_MEM_SECTION to place it accordingly.
-CFG_TUSB_MEM_SECTION TU_ATTR_ALIGNED(256) static dcd_data_t _dcd;
-
-//--------------------------------------------------------------------+
-// Multiple Controllers
-//--------------------------------------------------------------------+
-
-typedef struct
-{
- dcd_registers_t* regs; // registers
- const tusb_speed_t max_speed; // max link speed
- const IRQn_Type irqnum; // IRQ number
- const uint8_t ep_pairs; // Max bi-directional Endpoints
-}dcd_controller_t;
-
-#ifdef INCLUDE_FSL_DEVICE_REGISTERS
-
-static const dcd_controller_t _dcd_controller[] =
-{
- { .regs = (dcd_registers_t*) USB0_BASE , .max_speed = TUSB_SPEED_FULL, .irqnum = USB0_IRQn, .ep_pairs = FSL_FEATURE_USB_EP_NUM },
- #if defined(FSL_FEATURE_SOC_USBHSD_COUNT) && FSL_FEATURE_SOC_USBHSD_COUNT
- { .regs = (dcd_registers_t*) USBHSD_BASE, .max_speed = TUSB_SPEED_HIGH, .irqnum = USB1_IRQn, .ep_pairs = FSL_FEATURE_USBHSD_EP_NUM }
- #endif
-};
-
-#else
-
-static const dcd_controller_t _dcd_controller[] =
-{
- { .regs = (dcd_registers_t*) LPC_USB0_BASE, .max_speed = TUSB_SPEED_FULL, .irqnum = USB0_IRQn, .ep_pairs = 5 },
-};
-
-#endif
-
-//--------------------------------------------------------------------+
-// INTERNAL OBJECT & FUNCTION DECLARATION
-//--------------------------------------------------------------------+
-
-static inline uint16_t get_buf_offset(void const * buffer)
-{
- uint32_t addr = (uint32_t) buffer;
- TU_ASSERT( (addr & 0x3f) == 0, 0 );
- return ( (addr >> 6) & 0xFFFFUL ) ;
-}
-
-static inline uint8_t ep_addr2id(uint8_t ep_addr)
-{
- return 2*(ep_addr & 0x0F) + ((ep_addr & TUSB_DIR_IN_MASK) ? 1 : 0);
-}
-
-//--------------------------------------------------------------------+
-// CONTROLLER API
-//--------------------------------------------------------------------+
-void dcd_init(uint8_t rhport)
-{
- dcd_registers_t* dcd_reg = _dcd_controller[rhport].regs;
-
- dcd_reg->EPLISTSTART = (uint32_t) _dcd.ep;
- dcd_reg->DATABUFSTART = tu_align((uint32_t) &_dcd, TU_BIT(22)); // 22-bit alignment
- dcd_reg->INTSTAT |= dcd_reg->INTSTAT; // clear all pending interrupt
- dcd_reg->INTEN = INT_DEVICE_STATUS_MASK;
- dcd_reg->DEVCMDSTAT |= CMDSTAT_DEVICE_ENABLE_MASK | CMDSTAT_DEVICE_CONNECT_MASK |
- CMDSTAT_RESET_CHANGE_MASK | CMDSTAT_CONNECT_CHANGE_MASK | CMDSTAT_SUSPEND_CHANGE_MASK;
-
- NVIC_ClearPendingIRQ(_dcd_controller[rhport].irqnum);
-}
-
-void dcd_int_enable(uint8_t rhport)
-{
- NVIC_EnableIRQ(_dcd_controller[rhport].irqnum);
-}
-
-void dcd_int_disable(uint8_t rhport)
-{
- NVIC_DisableIRQ(_dcd_controller[rhport].irqnum);
-}
-
-void dcd_set_address(uint8_t rhport, uint8_t dev_addr)
-{
- dcd_registers_t* dcd_reg = _dcd_controller[rhport].regs;
-
- // Response with status first before changing device address
- dcd_edpt_xfer(rhport, tu_edpt_addr(0, TUSB_DIR_IN), NULL, 0);
-
- dcd_reg->DEVCMDSTAT &= ~CMDSTAT_DEVICE_ADDR_MASK;
- dcd_reg->DEVCMDSTAT |= dev_addr;
-}
-
-void dcd_remote_wakeup(uint8_t rhport)
-{
- (void) rhport;
-}
-
-void dcd_connect(uint8_t rhport)
-{
- dcd_registers_t* dcd_reg = _dcd_controller[rhport].regs;
- dcd_reg->DEVCMDSTAT |= CMDSTAT_DEVICE_CONNECT_MASK;
-}
-
-void dcd_disconnect(uint8_t rhport)
-{
- dcd_registers_t* dcd_reg = _dcd_controller[rhport].regs;
- dcd_reg->DEVCMDSTAT &= ~CMDSTAT_DEVICE_CONNECT_MASK;
-}
-
-//--------------------------------------------------------------------+
-// DCD Endpoint Port
-//--------------------------------------------------------------------+
-void dcd_edpt_stall(uint8_t rhport, uint8_t ep_addr)
-{
- (void) rhport;
-
- // TODO cannot able to STALL Control OUT endpoint !!!!! FIXME try some walk-around
- uint8_t const ep_id = ep_addr2id(ep_addr);
- _dcd.ep[ep_id][0].stall = 1;
-}
-
-void dcd_edpt_clear_stall(uint8_t rhport, uint8_t ep_addr)
-{
- (void) rhport;
-
- uint8_t const ep_id = ep_addr2id(ep_addr);
-
- _dcd.ep[ep_id][0].stall = 0;
- _dcd.ep[ep_id][0].toggle_reset = 1;
- _dcd.ep[ep_id][0].toggle_mode = 0;
-}
-
-bool dcd_edpt_open(uint8_t rhport, tusb_desc_endpoint_t const * p_endpoint_desc)
-{
- (void) rhport;
-
- // TODO not support ISO yet
- TU_VERIFY(p_endpoint_desc->bmAttributes.xfer != TUSB_XFER_ISOCHRONOUS);
-
- //------------- Prepare Queue Head -------------//
- uint8_t ep_id = ep_addr2id(p_endpoint_desc->bEndpointAddress);
-
- // Check if endpoint is available
- TU_ASSERT( _dcd.ep[ep_id][0].disable && _dcd.ep[ep_id][1].disable );
-
- tu_memclr(_dcd.ep[ep_id], 2*sizeof(ep_cmd_sts_t));
- _dcd.ep[ep_id][0].is_iso = (p_endpoint_desc->bmAttributes.xfer == TUSB_XFER_ISOCHRONOUS);
-
- // Enable EP interrupt
- dcd_registers_t* dcd_reg = _dcd_controller[rhport].regs;
- dcd_reg->INTEN |= TU_BIT(ep_id);
-
- return true;
-}
-
-static void prepare_setup_packet(uint8_t rhport)
-{
- if (_dcd_controller[rhport].max_speed == TUSB_SPEED_FULL )
- {
- _dcd.ep[0][1].buffer_fs.offset = get_buf_offset(_dcd.setup_packet);;
- }else
- {
- _dcd.ep[0][1].buffer_hs.offset = get_buf_offset(_dcd.setup_packet);;
- }
-}
-
-static void prepare_ep_xfer(uint8_t rhport, uint8_t ep_id, uint16_t buf_offset, uint16_t total_bytes)
-{
- uint16_t nbytes;
-
- if (_dcd_controller[rhport].max_speed == TUSB_SPEED_FULL )
- {
- // TODO ISO FullSpeed can have up to 1023 bytes
- nbytes = tu_min16(total_bytes, NBYTES_CBI_FULLSPEED_MAX);
- _dcd.ep[ep_id][0].buffer_fs.offset = buf_offset;
- _dcd.ep[ep_id][0].buffer_fs.nbytes = nbytes;
- }else
- {
- nbytes = tu_min16(total_bytes, NBYTES_CBI_HIGHSPEED_MAX);
- _dcd.ep[ep_id][0].buffer_hs.offset = buf_offset;
- _dcd.ep[ep_id][0].buffer_hs.nbytes = nbytes;
- }
-
- _dcd.dma[ep_id].nbytes = nbytes;
-
- _dcd.ep[ep_id][0].active = 1;
-}
-
-bool dcd_edpt_xfer(uint8_t rhport, uint8_t ep_addr, uint8_t* buffer, uint16_t total_bytes)
-{
- (void) rhport;
-
- uint8_t const ep_id = ep_addr2id(ep_addr);
-
- tu_memclr(&_dcd.dma[ep_id], sizeof(xfer_dma_t));
- _dcd.dma[ep_id].total_bytes = total_bytes;
-
- prepare_ep_xfer(rhport, ep_id, get_buf_offset(buffer), total_bytes);
-
- return true;
-}
-
-//--------------------------------------------------------------------+
-// IRQ
-//--------------------------------------------------------------------+
-static void bus_reset(uint8_t rhport)
-{
- tu_memclr(&_dcd, sizeof(dcd_data_t));
-
- // disable all non-control endpoints on bus reset
- for(uint8_t ep_id = 2; ep_id < 2*MAX_EP_PAIRS; ep_id++)
- {
- _dcd.ep[ep_id][0].disable = _dcd.ep[ep_id][1].disable = 1;
- }
-
- prepare_setup_packet(rhport);
-
- dcd_registers_t* dcd_reg = _dcd_controller[rhport].regs;
-
- dcd_reg->EPINUSE = 0;
- dcd_reg->EPBUFCFG = 0;
- dcd_reg->EPSKIP = 0xFFFFFFFF;
-
- dcd_reg->INTSTAT = dcd_reg->INTSTAT; // clear all pending interrupt
- dcd_reg->DEVCMDSTAT |= CMDSTAT_SETUP_RECEIVED_MASK; // clear setup received interrupt
- dcd_reg->INTEN = INT_DEVICE_STATUS_MASK | TU_BIT(0) | TU_BIT(1); // enable device status & control endpoints
-}
-
-static void process_xfer_isr(uint8_t rhport, uint32_t int_status)
-{
- uint8_t const max_ep = 2*_dcd_controller[rhport].ep_pairs;
-
- for(uint8_t ep_id = 0; ep_id < max_ep; ep_id++ )
- {
- if ( tu_bit_test(int_status, ep_id) )
- {
- ep_cmd_sts_t * ep_cs = &_dcd.ep[ep_id][0];
- xfer_dma_t* xfer_dma = &_dcd.dma[ep_id];
-
- if ( ep_id == 0 || ep_id == 1)
- {
- // For control endpoint, we need to manually clear Active bit
- ep_cs->active = 0;
- }
-
- uint16_t buf_offset;
- uint16_t buf_nbytes;
-
- if (_dcd_controller[rhport].max_speed == TUSB_SPEED_FULL)
- {
- buf_offset = ep_cs->buffer_fs.offset;
- buf_nbytes = ep_cs->buffer_fs.nbytes;
- }else
- {
- buf_offset = ep_cs->buffer_hs.offset;
- buf_nbytes = ep_cs->buffer_hs.nbytes;
- }
-
- xfer_dma->xferred_bytes += xfer_dma->nbytes - buf_nbytes;
-
- if ( (buf_nbytes == 0) && (xfer_dma->total_bytes > xfer_dma->xferred_bytes) )
- {
- // There is more data to transfer
- // buff_offset has been already increased by hw to correct value for next transfer
- prepare_ep_xfer(rhport, ep_id, buf_offset, xfer_dma->total_bytes - xfer_dma->xferred_bytes);
- }
- else
- {
- // for detecting ZLP
- xfer_dma->total_bytes = xfer_dma->xferred_bytes;
-
- uint8_t const ep_addr = tu_edpt_addr(ep_id / 2, ep_id & 0x01);
-
- // TODO no way determine if the transfer is failed or not
- dcd_event_xfer_complete(rhport, ep_addr, xfer_dma->xferred_bytes, XFER_RESULT_SUCCESS, true);
- }
- }
- }
-}
-
-void dcd_int_handler(uint8_t rhport)
-{
- dcd_registers_t* dcd_reg = _dcd_controller[rhport].regs;
-
- uint32_t const cmd_stat = dcd_reg->DEVCMDSTAT;
-
- uint32_t int_status = dcd_reg->INTSTAT & dcd_reg->INTEN;
- dcd_reg->INTSTAT = int_status; // Acknowledge handled interrupt
-
- if (int_status == 0) return;
-
- //------------- Device Status -------------//
- if ( int_status & INT_DEVICE_STATUS_MASK )
- {
- dcd_reg->DEVCMDSTAT |= CMDSTAT_RESET_CHANGE_MASK | CMDSTAT_CONNECT_CHANGE_MASK | CMDSTAT_SUSPEND_CHANGE_MASK;
-
- if ( cmd_stat & CMDSTAT_RESET_CHANGE_MASK) // bus reset
- {
- bus_reset(rhport);
-
- tusb_speed_t speed = TUSB_SPEED_FULL;
-
- if (_dcd_controller[rhport].max_speed == TUSB_SPEED_HIGH)
- {
- // 0 : reserved, 1 : full, 2 : high, 3: super
- if ( 2 == ((cmd_stat >> CMDSTAT_SPEED_SHIFT) & 0x3UL) )
- {
- speed= TUSB_SPEED_HIGH;
- }
- }
-
- dcd_event_bus_reset(rhport, speed, true);
- }
-
- if (cmd_stat & CMDSTAT_CONNECT_CHANGE_MASK)
- {
- // device disconnect
- if (cmd_stat & CMDSTAT_DEVICE_ADDR_MASK)
- {
- // debouncing as this can be set when device is powering
- dcd_event_bus_signal(rhport, DCD_EVENT_UNPLUGGED, true);
- }
- }
-
- // TODO support suspend & resume
- if (cmd_stat & CMDSTAT_SUSPEND_CHANGE_MASK)
- {
- if (cmd_stat & CMDSTAT_DEVICE_SUSPEND_MASK)
- { // suspend signal, bus idle for more than 3ms
- // Note: Host may delay more than 3 ms before and/or after bus reset before doing enumeration.
- if (cmd_stat & CMDSTAT_DEVICE_ADDR_MASK)
- {
- dcd_event_bus_signal(rhport, DCD_EVENT_SUSPEND, true);
- }
- }
- }
-// else
-// { // resume signal
-// dcd_event_bus_signal(rhport, DCD_EVENT_RESUME, true);
-// }
-// }
- }
-
- // Setup Receive
- if ( tu_bit_test(int_status, 0) && (cmd_stat & CMDSTAT_SETUP_RECEIVED_MASK) )
- {
- // Follow UM flowchart to clear Active & Stall on both Control IN/OUT endpoints
- _dcd.ep[0][0].active = _dcd.ep[1][0].active = 0;
- _dcd.ep[0][0].stall = _dcd.ep[1][0].stall = 0;
-
- dcd_reg->DEVCMDSTAT |= CMDSTAT_SETUP_RECEIVED_MASK;
-
- dcd_event_setup_received(rhport, _dcd.setup_packet, true);
-
- // keep waiting for next setup
- prepare_setup_packet(rhport);
-
- // clear bit0
- int_status = tu_bit_clear(int_status, 0);
- }
-
- // Endpoint transfer complete interrupt
- process_xfer_isr(rhport, int_status);
-}
-
-#endif
-
diff --git a/tinyusb/src/portable/nxp/transdimension/common_transdimension.h b/tinyusb/src/portable/nxp/transdimension/common_transdimension.h
deleted file mode 100755
index 69074de4..00000000
--- a/tinyusb/src/portable/nxp/transdimension/common_transdimension.h
+++ /dev/null
@@ -1,136 +0,0 @@
-/*
- * The MIT License (MIT)
- *
- * Copyright (c) 2021, Ha Thach (tinyusb.org)
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- *
- * This file is part of the TinyUSB stack.
- */
-
-#ifndef COMMON_TRANSDIMENSION_H_
-#define COMMON_TRANSDIMENSION_H_
-
-#ifdef __cplusplus
- extern "C" {
-#endif
-
-// USBCMD
-enum {
- USBCMD_RUN_STOP = TU_BIT(0),
- USBCMD_RESET = TU_BIT(1),
- USBCMD_SETUP_TRIPWIRE = TU_BIT(13),
- USBCMD_ADD_QTD_TRIPWIRE = TU_BIT(14) ///< This bit is used as a semaphore to ensure the to proper addition of a new dTD to an active (primed) endpoint’s linked list. This bit is set and cleared by software during the process of adding a new dTD
-// Interrupt Threshold bit 23:16
-};
-
-// PORTSC1
-#define PORTSC1_PORT_SPEED_POS 26
-
-enum {
- PORTSC1_CURRENT_CONNECT_STATUS = TU_BIT(0),
- PORTSC1_FORCE_PORT_RESUME = TU_BIT(6),
- PORTSC1_SUSPEND = TU_BIT(7),
- PORTSC1_FORCE_FULL_SPEED = TU_BIT(24),
- PORTSC1_PORT_SPEED = TU_BIT(26) | TU_BIT(27)
-};
-
-// OTGSC
-enum {
- OTGSC_VBUS_DISCHARGE = TU_BIT(0),
- OTGSC_VBUS_CHARGE = TU_BIT(1),
-// OTGSC_HWASSIST_AUTORESET = TU_BIT(2),
- OTGSC_OTG_TERMINATION = TU_BIT(3), ///< Must set to 1 when OTG go to device mode
- OTGSC_DATA_PULSING = TU_BIT(4),
- OTGSC_ID_PULLUP = TU_BIT(5),
-// OTGSC_HWASSIT_DATA_PULSE = TU_BIT(6),
-// OTGSC_HWASSIT_BDIS_ACONN = TU_BIT(7),
- OTGSC_ID = TU_BIT(8), ///< 0 = A device, 1 = B Device
- OTGSC_A_VBUS_VALID = TU_BIT(9),
- OTGSC_A_SESSION_VALID = TU_BIT(10),
- OTGSC_B_SESSION_VALID = TU_BIT(11),
- OTGSC_B_SESSION_END = TU_BIT(12),
- OTGSC_1MS_TOGGLE = TU_BIT(13),
- OTGSC_DATA_BUS_PULSING_STATUS = TU_BIT(14),
-};
-
-// USBMode
-enum {
- USBMODE_CM_DEVICE = 2,
- USBMODE_CM_HOST = 3,
-
- USBMODE_SLOM = TU_BIT(3),
- USBMODE_SDIS = TU_BIT(4),
-
- USBMODE_VBUS_POWER_SELECT = TU_BIT(5), // Need to be enabled for LPC18XX/43XX in host mode
-};
-
-// Device Registers
-typedef struct
-{
- //------------- ID + HW Parameter Registers-------------//
- __I uint32_t TU_RESERVED[64]; ///< For iMX RT10xx, but not used by LPC18XX/LPC43XX
-
- //------------- Capability Registers-------------//
- __I uint8_t CAPLENGTH; ///< Capability Registers Length
- __I uint8_t TU_RESERVED[1];
- __I uint16_t HCIVERSION; ///< Host Controller Interface Version
-
- __I uint32_t HCSPARAMS; ///< Host Controller Structural Parameters
- __I uint32_t HCCPARAMS; ///< Host Controller Capability Parameters
- __I uint32_t TU_RESERVED[5];
-
- __I uint16_t DCIVERSION; ///< Device Controller Interface Version
- __I uint8_t TU_RESERVED[2];
-
- __I uint32_t DCCPARAMS; ///< Device Controller Capability Parameters
- __I uint32_t TU_RESERVED[6];
-
- //------------- Operational Registers -------------//
- __IO uint32_t USBCMD; ///< USB Command Register
- __IO uint32_t USBSTS; ///< USB Status Register
- __IO uint32_t USBINTR; ///< Interrupt Enable Register
- __IO uint32_t FRINDEX; ///< USB Frame Index
- __I uint32_t TU_RESERVED;
- __IO uint32_t DEVICEADDR; ///< Device Address
- __IO uint32_t ENDPTLISTADDR; ///< Endpoint List Address
- __I uint32_t TU_RESERVED;
- __IO uint32_t BURSTSIZE; ///< Programmable Burst Size
- __IO uint32_t TXFILLTUNING; ///< TX FIFO Fill Tuning
- uint32_t TU_RESERVED[4];
- __IO uint32_t ENDPTNAK; ///< Endpoint NAK
- __IO uint32_t ENDPTNAKEN; ///< Endpoint NAK Enable
- __I uint32_t TU_RESERVED;
- __IO uint32_t PORTSC1; ///< Port Status & Control
- __I uint32_t TU_RESERVED[7];
- __IO uint32_t OTGSC; ///< On-The-Go Status & control
- __IO uint32_t USBMODE; ///< USB Device Mode
- __IO uint32_t ENDPTSETUPSTAT; ///< Endpoint Setup Status
- __IO uint32_t ENDPTPRIME; ///< Endpoint Prime
- __IO uint32_t ENDPTFLUSH; ///< Endpoint Flush
- __I uint32_t ENDPTSTAT; ///< Endpoint Status
- __IO uint32_t ENDPTCOMPLETE; ///< Endpoint Complete
- __IO uint32_t ENDPTCTRL[8]; ///< Endpoint Control 0 - 7
-} dcd_registers_t, hcd_registers_t;
-
-#ifdef __cplusplus
- }
-#endif
-
-#endif /* COMMON_TRANSDIMENSION_H_ */
diff --git a/tinyusb/src/portable/nxp/transdimension/dcd_transdimension.c b/tinyusb/src/portable/nxp/transdimension/dcd_transdimension.c
deleted file mode 100755
index eeab3f48..00000000
--- a/tinyusb/src/portable/nxp/transdimension/dcd_transdimension.c
+++ /dev/null
@@ -1,492 +0,0 @@
-/*
- * The MIT License (MIT)
- *
- * Copyright (c) 2019 Ha Thach (tinyusb.org)
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- *
- * This file is part of the TinyUSB stack.
- */
-
-#include "tusb_option.h"
-
-#if TUSB_OPT_DEVICE_ENABLED && \
- (CFG_TUSB_MCU == OPT_MCU_LPC18XX || CFG_TUSB_MCU == OPT_MCU_LPC43XX || CFG_TUSB_MCU == OPT_MCU_MIMXRT10XX)
-
-//--------------------------------------------------------------------+
-// INCLUDE
-//--------------------------------------------------------------------+
-#if CFG_TUSB_MCU == OPT_MCU_MIMXRT10XX
- #include "fsl_device_registers.h"
- #define INCLUDE_FSL_DEVICE_REGISTERS
-#else
- // LPCOpen for 18xx & 43xx
- #include "chip.h"
-#endif
-
-#include "common/tusb_common.h"
-#include "device/dcd.h"
-#include "common_transdimension.h"
-
-#if defined(__CORTEX_M) && __CORTEX_M == 7 && __DCACHE_PRESENT == 1
- #define CleanInvalidateDCache_by_Addr SCB_CleanInvalidateDCache_by_Addr
-#else
- #define CleanInvalidateDCache_by_Addr(_addr, _dsize)
-#endif
-
-//--------------------------------------------------------------------+
-// MACRO CONSTANT TYPEDEF
-//--------------------------------------------------------------------+
-
-// ENDPTCTRL
-enum {
- ENDPTCTRL_STALL = TU_BIT(0),
- ENDPTCTRL_TOGGLE_INHIBIT = TU_BIT(5), ///< used for test only
- ENDPTCTRL_TOGGLE_RESET = TU_BIT(6),
- ENDPTCTRL_ENABLE = TU_BIT(7)
-};
-
-// USBSTS, USBINTR
-enum {
- INTR_USB = TU_BIT(0),
- INTR_ERROR = TU_BIT(1),
- INTR_PORT_CHANGE = TU_BIT(2),
- INTR_RESET = TU_BIT(6),
- INTR_SOF = TU_BIT(7),
- INTR_SUSPEND = TU_BIT(8),
- INTR_NAK = TU_BIT(16)
-};
-
-// Queue Transfer Descriptor
-typedef struct
-{
- // Word 0: Next QTD Pointer
- uint32_t next; ///< Next link pointer This field contains the physical memory address of the next dTD to be processed
-
- // Word 1: qTQ Token
- uint32_t : 3 ;
- volatile uint32_t xact_err : 1 ;
- uint32_t : 1 ;
- volatile uint32_t buffer_err : 1 ;
- volatile uint32_t halted : 1 ;
- volatile uint32_t active : 1 ;
- uint32_t : 2 ;
- uint32_t iso_mult_override : 2 ; ///< This field can be used for transmit ISOs to override the MULT field in the dQH. This field must be zero for all packet types that are not transmit-ISO.
- uint32_t : 3 ;
- uint32_t int_on_complete : 1 ;
- volatile uint32_t total_bytes : 15 ;
- uint32_t : 0 ;
-
- // Word 2-6: Buffer Page Pointer List, Each element in the list is a 4K page aligned, physical memory address. The lower 12 bits in each pointer are reserved (except for the first one) as each memory pointer must reference the start of a 4K page
- uint32_t buffer[5]; ///< buffer1 has frame_n for TODO Isochronous
-
- //------------- DCD Area -------------//
- uint16_t expected_bytes;
- uint8_t reserved[2];
-} dcd_qtd_t;
-
-TU_VERIFY_STATIC( sizeof(dcd_qtd_t) == 32, "size is not correct");
-
-// Queue Head
-typedef struct
-{
- // Word 0: Capabilities and Characteristics
- uint32_t : 15 ; ///< Number of packets executed per transaction descriptor 00 - Execute N transactions as demonstrated by the USB variable length protocol where N is computed using Max_packet_length and the Total_bytes field in the dTD. 01 - Execute one transaction 10 - Execute two transactions 11 - Execute three transactions Remark: Non-isochronous endpoints must set MULT = 00. Remark: Isochronous endpoints must set MULT = 01, 10, or 11 as needed.
- uint32_t int_on_setup : 1 ; ///< Interrupt on setup This bit is used on control type endpoints to indicate if USBINT is set in response to a setup being received.
- uint32_t max_package_size : 11 ; ///< This directly corresponds to the maximum packet size of the associated endpoint (wMaxPacketSize)
- uint32_t : 2 ;
- uint32_t zero_length_termination : 1 ; ///< This bit is used for non-isochronous endpoints to indicate when a zero-length packet is received to terminate transfers in case the total transfer length is “multiple”. 0 - Enable zero-length packet to terminate transfers equal to a multiple of Max_packet_length (default). 1 - Disable zero-length packet on transfers that are equal in length to a multiple Max_packet_length.
- uint32_t iso_mult : 2 ; ///<
- uint32_t : 0 ;
-
- // Word 1: Current qTD Pointer
- volatile uint32_t qtd_addr;
-
- // Word 2-9: Transfer Overlay
- volatile dcd_qtd_t qtd_overlay;
-
- // Word 10-11: Setup request (control OUT only)
- volatile tusb_control_request_t setup_request;
-
- //--------------------------------------------------------------------+
- /// Due to the fact QHD is 64 bytes aligned but occupies only 48 bytes
- /// thus there are 16 bytes padding free that we can make use of.
- //--------------------------------------------------------------------+
- uint8_t reserved[16];
-} dcd_qhd_t;
-
-TU_VERIFY_STATIC( sizeof(dcd_qhd_t) == 64, "size is not correct");
-
-//--------------------------------------------------------------------+
-// Variables
-//--------------------------------------------------------------------+
-
-typedef struct
-{
- dcd_registers_t* regs; // registers
- const IRQn_Type irqnum; // IRQ number
- const uint8_t ep_count; // Max bi-directional Endpoints
-}dcd_controller_t;
-
-#if CFG_TUSB_MCU == OPT_MCU_MIMXRT10XX
- // Each endpoint with direction (IN/OUT) occupies a queue head
- // Therefore QHD_MAX is 2 x max endpoint count
- #define QHD_MAX (8*2)
-
- static const dcd_controller_t _dcd_controller[] =
- {
- // RT1010 and RT1020 only has 1 USB controller
- #if FSL_FEATURE_SOC_USBHS_COUNT == 1
- { .regs = (dcd_registers_t*) USB_BASE , .irqnum = USB_OTG1_IRQn, .ep_count = 8 }
- #else
- { .regs = (dcd_registers_t*) USB1_BASE, .irqnum = USB_OTG1_IRQn, .ep_count = 8 },
- { .regs = (dcd_registers_t*) USB2_BASE, .irqnum = USB_OTG2_IRQn, .ep_count = 8 }
- #endif
- };
-
-#else
- #define QHD_MAX (6*2)
-
- static const dcd_controller_t _dcd_controller[] =
- {
- { .regs = (dcd_registers_t*) LPC_USB0_BASE, .irqnum = USB0_IRQn, .ep_count = 6 },
- { .regs = (dcd_registers_t*) LPC_USB1_BASE, .irqnum = USB1_IRQn, .ep_count = 4 }
- };
-#endif
-
-#define QTD_NEXT_INVALID 0x01
-
-typedef struct {
- // Must be at 2K alignment
- dcd_qhd_t qhd[QHD_MAX] TU_ATTR_ALIGNED(64);
- dcd_qtd_t qtd[QHD_MAX] TU_ATTR_ALIGNED(32); // for portability, TinyUSB only queue 1 TD for each Qhd
-}dcd_data_t;
-
-CFG_TUSB_MEM_SECTION TU_ATTR_ALIGNED(2048)
-static dcd_data_t _dcd_data;
-
-//--------------------------------------------------------------------+
-// Controller API
-//--------------------------------------------------------------------+
-
-/// follows LPC43xx User Manual 23.10.3
-static void bus_reset(uint8_t rhport)
-{
- dcd_registers_t* dcd_reg = _dcd_controller[rhport].regs;
-
- // The reset value for all endpoint types is the control endpoint. If one endpoint
- // direction is enabled and the paired endpoint of opposite direction is disabled, then the
- // endpoint type of the unused direction must be changed from the control type to any other
- // type (e.g. bulk). Leaving an un-configured endpoint control will cause undefined behavior
- // for the data PID tracking on the active endpoint.
- for( int i=1; i < _dcd_controller[rhport].ep_count; i++)
- {
- dcd_reg->ENDPTCTRL[i] = (TUSB_XFER_BULK << 2) | (TUSB_XFER_BULK << 18);
- }
-
- //------------- Clear All Registers -------------//
- dcd_reg->ENDPTNAK = dcd_reg->ENDPTNAK;
- dcd_reg->ENDPTNAKEN = 0;
- dcd_reg->USBSTS = dcd_reg->USBSTS;
- dcd_reg->ENDPTSETUPSTAT = dcd_reg->ENDPTSETUPSTAT;
- dcd_reg->ENDPTCOMPLETE = dcd_reg->ENDPTCOMPLETE;
-
- while (dcd_reg->ENDPTPRIME) {}
- dcd_reg->ENDPTFLUSH = 0xFFFFFFFF;
- while (dcd_reg->ENDPTFLUSH) {}
-
- // read reset bit in portsc
-
- //------------- Queue Head & Queue TD -------------//
- tu_memclr(&_dcd_data, sizeof(dcd_data_t));
-
- //------------- Set up Control Endpoints (0 OUT, 1 IN) -------------//
- _dcd_data.qhd[0].zero_length_termination = _dcd_data.qhd[1].zero_length_termination = 1;
- _dcd_data.qhd[0].max_package_size = _dcd_data.qhd[1].max_package_size = CFG_TUD_ENDPOINT0_SIZE;
- _dcd_data.qhd[0].qtd_overlay.next = _dcd_data.qhd[1].qtd_overlay.next = QTD_NEXT_INVALID;
-
- _dcd_data.qhd[0].int_on_setup = 1; // OUT only
-}
-
-void dcd_init(uint8_t rhport)
-{
- tu_memclr(&_dcd_data, sizeof(dcd_data_t));
-
- dcd_registers_t* dcd_reg = _dcd_controller[rhport].regs;
-
- // Reset controller
- dcd_reg->USBCMD |= USBCMD_RESET;
- while( dcd_reg->USBCMD & USBCMD_RESET ) {}
-
- // Set mode to device, must be set immediately after reset
- dcd_reg->USBMODE = USBMODE_CM_DEVICE;
- dcd_reg->OTGSC = OTGSC_VBUS_DISCHARGE | OTGSC_OTG_TERMINATION;
-
- // TODO Force fullspeed on non-highspeed port
- // dcd_reg->PORTSC1 = PORTSC1_FORCE_FULL_SPEED;
-
- CleanInvalidateDCache_by_Addr((uint32_t*) &_dcd_data, sizeof(dcd_data_t));
-
- dcd_reg->ENDPTLISTADDR = (uint32_t) _dcd_data.qhd; // Endpoint List Address has to be 2K alignment
- dcd_reg->USBSTS = dcd_reg->USBSTS;
- dcd_reg->USBINTR = INTR_USB | INTR_ERROR | INTR_PORT_CHANGE | INTR_RESET | INTR_SUSPEND /*| INTR_SOF*/;
-
- dcd_reg->USBCMD &= ~0x00FF0000; // Interrupt Threshold Interval = 0
- dcd_reg->USBCMD |= USBCMD_RUN_STOP; // Connect
-}
-
-void dcd_int_enable(uint8_t rhport)
-{
- NVIC_EnableIRQ(_dcd_controller[rhport].irqnum);
-}
-
-void dcd_int_disable(uint8_t rhport)
-{
- NVIC_DisableIRQ(_dcd_controller[rhport].irqnum);
-}
-
-void dcd_set_address(uint8_t rhport, uint8_t dev_addr)
-{
- // Response with status first before changing device address
- dcd_edpt_xfer(rhport, tu_edpt_addr(0, TUSB_DIR_IN), NULL, 0);
-
- dcd_registers_t* dcd_reg = _dcd_controller[rhport].regs;
- dcd_reg->DEVICEADDR = (dev_addr << 25) | TU_BIT(24);
-}
-
-void dcd_remote_wakeup(uint8_t rhport)
-{
- (void) rhport;
-}
-
-void dcd_connect(uint8_t rhport)
-{
- dcd_registers_t* dcd_reg = _dcd_controller[rhport].regs;
- dcd_reg->USBCMD |= USBCMD_RUN_STOP;
-}
-
-void dcd_disconnect(uint8_t rhport)
-{
- dcd_registers_t* dcd_reg = _dcd_controller[rhport].regs;
- dcd_reg->USBCMD &= ~USBCMD_RUN_STOP;
-}
-
-//--------------------------------------------------------------------+
-// HELPER
-//--------------------------------------------------------------------+
-// index to bit position in register
-static inline uint8_t ep_idx2bit(uint8_t ep_idx)
-{
- return ep_idx/2 + ( (ep_idx%2) ? 16 : 0);
-}
-
-static void qtd_init(dcd_qtd_t* p_qtd, void * data_ptr, uint16_t total_bytes)
-{
- tu_memclr(p_qtd, sizeof(dcd_qtd_t));
-
- p_qtd->next = QTD_NEXT_INVALID;
- p_qtd->active = 1;
- p_qtd->total_bytes = p_qtd->expected_bytes = total_bytes;
-
- if (data_ptr != NULL)
- {
- p_qtd->buffer[0] = (uint32_t) data_ptr;
- for(uint8_t i=1; i<5; i++)
- {
- p_qtd->buffer[i] |= tu_align4k( p_qtd->buffer[i-1] ) + 4096;
- }
- }
-}
-
-//--------------------------------------------------------------------+
-// DCD Endpoint Port
-//--------------------------------------------------------------------+
-void dcd_edpt_stall(uint8_t rhport, uint8_t ep_addr)
-{
- uint8_t const epnum = tu_edpt_number(ep_addr);
- uint8_t const dir = tu_edpt_dir(ep_addr);
-
- dcd_registers_t* dcd_reg = _dcd_controller[rhport].regs;
- dcd_reg->ENDPTCTRL[epnum] |= ENDPTCTRL_STALL << (dir ? 16 : 0);
-}
-
-void dcd_edpt_clear_stall(uint8_t rhport, uint8_t ep_addr)
-{
- uint8_t const epnum = tu_edpt_number(ep_addr);
- uint8_t const dir = tu_edpt_dir(ep_addr);
-
- // data toggle also need to be reset
- dcd_registers_t* dcd_reg = _dcd_controller[rhport].regs;
- dcd_reg->ENDPTCTRL[epnum] |= ENDPTCTRL_TOGGLE_RESET << ( dir ? 16 : 0 );
- dcd_reg->ENDPTCTRL[epnum] &= ~(ENDPTCTRL_STALL << ( dir ? 16 : 0));
-}
-
-bool dcd_edpt_open(uint8_t rhport, tusb_desc_endpoint_t const * p_endpoint_desc)
-{
- // TODO not support ISO yet
- TU_VERIFY ( p_endpoint_desc->bmAttributes.xfer != TUSB_XFER_ISOCHRONOUS);
-
- uint8_t const epnum = tu_edpt_number(p_endpoint_desc->bEndpointAddress);
- uint8_t const dir = tu_edpt_dir(p_endpoint_desc->bEndpointAddress);
- uint8_t const ep_idx = 2*epnum + dir;
-
- // Must not exceed max endpoint number
- TU_ASSERT( epnum < _dcd_controller[rhport].ep_count );
-
- //------------- Prepare Queue Head -------------//
- dcd_qhd_t * p_qhd = &_dcd_data.qhd[ep_idx];
- tu_memclr(p_qhd, sizeof(dcd_qhd_t));
-
- p_qhd->zero_length_termination = 1;
- p_qhd->max_package_size = p_endpoint_desc->wMaxPacketSize.size;
- p_qhd->qtd_overlay.next = QTD_NEXT_INVALID;
-
- CleanInvalidateDCache_by_Addr((uint32_t*) &_dcd_data, sizeof(dcd_data_t));
-
- // Enable EP Control
- dcd_registers_t* dcd_reg = _dcd_controller[rhport].regs;
- dcd_reg->ENDPTCTRL[epnum] |= ((p_endpoint_desc->bmAttributes.xfer << 2) | ENDPTCTRL_ENABLE | ENDPTCTRL_TOGGLE_RESET) << (dir ? 16 : 0);
-
- return true;
-}
-
-bool dcd_edpt_xfer(uint8_t rhport, uint8_t ep_addr, uint8_t * buffer, uint16_t total_bytes)
-{
- dcd_registers_t* dcd_reg = _dcd_controller[rhport].regs;
- uint8_t const epnum = tu_edpt_number(ep_addr);
- uint8_t const dir = tu_edpt_dir(ep_addr);
- uint8_t const ep_idx = 2*epnum + dir;
-
- if ( epnum == 0 )
- {
- // follows UM 24.10.8.1.1 Setup packet handling using setup lockout mechanism
- // wait until ENDPTSETUPSTAT before priming data/status in response TODO add time out
- while(dcd_reg->ENDPTSETUPSTAT & TU_BIT(0)) {}
- }
-
- dcd_qhd_t * p_qhd = &_dcd_data.qhd[ep_idx];
- dcd_qtd_t * p_qtd = &_dcd_data.qtd[ep_idx];
-
- // Force the CPU to flush the buffer. We increase the size by 32 because the call aligns the
- // address to 32-byte boundaries.
- // void* cast to suppress cast-align warning, buffer must be
- CleanInvalidateDCache_by_Addr((uint32_t*) tu_align((uint32_t) buffer, 4), total_bytes + 31);
-
- //------------- Prepare qtd -------------//
- qtd_init(p_qtd, buffer, total_bytes);
- p_qtd->int_on_complete = true;
- p_qhd->qtd_overlay.next = (uint32_t) p_qtd; // link qtd to qhd
-
- CleanInvalidateDCache_by_Addr((uint32_t*) &_dcd_data, sizeof(dcd_data_t));
-
- // start transfer
- dcd_reg->ENDPTPRIME = TU_BIT( ep_idx2bit(ep_idx) ) ;
-
- return true;
-}
-
-//--------------------------------------------------------------------+
-// ISR
-//--------------------------------------------------------------------+
-void dcd_int_handler(uint8_t rhport)
-{
- dcd_registers_t* const dcd_reg = _dcd_controller[rhport].regs;
-
- uint32_t const int_enable = dcd_reg->USBINTR;
- uint32_t const int_status = dcd_reg->USBSTS & int_enable;
- dcd_reg->USBSTS = int_status; // Acknowledge handled interrupt
-
- // disabled interrupt sources
- if (int_status == 0) return;
-
- if (int_status & INTR_RESET)
- {
- bus_reset(rhport);
- uint32_t speed = (dcd_reg->PORTSC1 & PORTSC1_PORT_SPEED) >> PORTSC1_PORT_SPEED_POS;
- dcd_event_bus_reset(rhport, (tusb_speed_t) speed, true);
- }
-
- if (int_status & INTR_SUSPEND)
- {
- if (dcd_reg->PORTSC1 & PORTSC1_SUSPEND)
- {
- // Note: Host may delay more than 3 ms before and/or after bus reset before doing enumeration.
- if ((dcd_reg->DEVICEADDR >> 25) & 0x0f)
- {
- dcd_event_bus_signal(rhport, DCD_EVENT_SUSPEND, true);
- }
- }
- }
-
- // Make sure we read the latest version of _dcd_data.
- CleanInvalidateDCache_by_Addr((uint32_t*) &_dcd_data, sizeof(dcd_data_t));
-
- // TODO disconnection does not generate interrupt !!!!!!
-// if (int_status & INTR_PORT_CHANGE)
-// {
-// if ( !(dcd_reg->PORTSC1 & PORTSC1_CURRENT_CONNECT_STATUS) )
-// {
-// dcd_event_t event = { .rhport = rhport, .event_id = DCD_EVENT_UNPLUGGED };
-// dcd_event_handler(&event, true);
-// }
-// }
-
- if (int_status & INTR_USB)
- {
- uint32_t const edpt_complete = dcd_reg->ENDPTCOMPLETE;
- dcd_reg->ENDPTCOMPLETE = edpt_complete; // acknowledge
-
- if (dcd_reg->ENDPTSETUPSTAT)
- {
- //------------- Set up Received -------------//
- // 23.10.10.2 Operational model for setup transfers
- dcd_reg->ENDPTSETUPSTAT = dcd_reg->ENDPTSETUPSTAT;// acknowledge
-
- dcd_event_setup_received(rhport, (uint8_t*) &_dcd_data.qhd[0].setup_request, true);
- }
-
- if ( edpt_complete )
- {
- for(uint8_t ep_idx = 0; ep_idx < QHD_MAX; ep_idx++)
- {
- if ( tu_bit_test(edpt_complete, ep_idx2bit(ep_idx)) )
- {
- // 23.10.12.3 Failed QTD also get ENDPTCOMPLETE set
- dcd_qtd_t * p_qtd = &_dcd_data.qtd[ep_idx];
-
- uint8_t result = p_qtd->halted ? XFER_RESULT_STALLED :
- ( p_qtd->xact_err ||p_qtd->buffer_err ) ? XFER_RESULT_FAILED : XFER_RESULT_SUCCESS;
-
- uint8_t const ep_addr = (ep_idx/2) | ( (ep_idx & 0x01) ? TUSB_DIR_IN_MASK : 0 );
- dcd_event_xfer_complete(rhport, ep_addr, p_qtd->expected_bytes - p_qtd->total_bytes, result, true); // only number of bytes in the IOC qtd
- }
- }
- }
- }
-
- if (int_status & INTR_SOF)
- {
- dcd_event_bus_signal(rhport, DCD_EVENT_SOF, true);
- }
-
- if (int_status & INTR_NAK) {}
- if (int_status & INTR_ERROR) TU_ASSERT(false, );
-}
-
-#endif
diff --git a/tinyusb/src/portable/nxp/transdimension/hcd_transdimension.c b/tinyusb/src/portable/nxp/transdimension/hcd_transdimension.c
deleted file mode 100755
index d216f072..00000000
--- a/tinyusb/src/portable/nxp/transdimension/hcd_transdimension.c
+++ /dev/null
@@ -1,117 +0,0 @@
-/*
- * The MIT License (MIT)
- *
- * Copyright (c) 2019 Ha Thach (tinyusb.org)
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- *
- * This file is part of the TinyUSB stack.
- */
-
-#include "tusb_option.h"
-
-// NXP Trans-Dimension USB IP implement EHCI for host functionality
-
-#if TUSB_OPT_HOST_ENABLED && \
- (CFG_TUSB_MCU == OPT_MCU_LPC18XX || CFG_TUSB_MCU == OPT_MCU_LPC43XX || CFG_TUSB_MCU == OPT_MCU_MIMXRT10XX)
-
-//--------------------------------------------------------------------+
-// INCLUDE
-//--------------------------------------------------------------------+
-#if CFG_TUSB_MCU == OPT_MCU_MIMXRT10XX
- #include "fsl_device_registers.h"
-#else
- // LPCOpen for 18xx & 43xx
- #include "chip.h"
-#endif
-
-#include "common/tusb_common.h"
-#include "common_transdimension.h"
-#include "portable/ehci/ehci_api.h"
-
-//--------------------------------------------------------------------+
-// MACRO CONSTANT TYPEDEF
-//--------------------------------------------------------------------+
-
-// TODO can be merged with dcd_controller_t
-typedef struct
-{
- uint32_t regs_base; // registers base
- const IRQn_Type irqnum; // IRQ number
-}hcd_controller_t;
-
-#if CFG_TUSB_MCU == OPT_MCU_MIMXRT10XX
- static const hcd_controller_t _hcd_controller[] =
- {
- // RT1010 and RT1020 only has 1 USB controller
- #if FSL_FEATURE_SOC_USBHS_COUNT == 1
- { .regs_base = USB_BASE , .irqnum = USB_OTG1_IRQn }
- #else
- { .regs_base = USB1_BASE, .irqnum = USB_OTG1_IRQn },
- { .regs_base = USB2_BASE, .irqnum = USB_OTG2_IRQn }
- #endif
- };
-
-#else
- static const hcd_controller_t _hcd_controller[] =
- {
- { .regs_base = LPC_USB0_BASE, .irqnum = USB0_IRQn },
- { .regs_base = LPC_USB1_BASE, .irqnum = USB1_IRQn }
- };
-#endif
-
-//--------------------------------------------------------------------+
-// Controller API
-//--------------------------------------------------------------------+
-
-bool hcd_init(uint8_t rhport)
-{
- hcd_registers_t* hcd_reg = (hcd_registers_t*) _hcd_controller[rhport].regs_base;
-
- // Reset controller
- hcd_reg->USBCMD |= USBCMD_RESET;
- while( hcd_reg->USBCMD & USBCMD_RESET ) {}
-
- // Set mode to device, must be set immediately after reset
-#if CFG_TUSB_MCU == OPT_MCU_LPC18XX || CFG_TUSB_MCU == OPT_MCU_LPC43XX
- // LPC18XX/43XX need to set VBUS Power Select to HIGH
- // RHPORT1 is fullspeed only (need external PHY for Highspeed)
- hcd_reg->USBMODE = USBMODE_CM_HOST | USBMODE_VBUS_POWER_SELECT;
- if (rhport == 1) hcd_reg->PORTSC1 |= PORTSC1_FORCE_FULL_SPEED;
-#else
- hcd_reg->USBMODE = USBMODE_CM_HOST;
-#endif
-
- // FIXME force full speed, still have issue with Highspeed enumeration
- hcd_reg->PORTSC1 |= PORTSC1_FORCE_FULL_SPEED;
-
- return ehci_init(rhport, (uint32_t) &hcd_reg->CAPLENGTH, (uint32_t) &hcd_reg->USBCMD);
-}
-
-void hcd_int_enable(uint8_t rhport)
-{
- NVIC_EnableIRQ(_hcd_controller[rhport].irqnum);
-}
-
-void hcd_int_disable(uint8_t rhport)
-{
- NVIC_DisableIRQ(_hcd_controller[rhport].irqnum);
-}
-
-#endif
diff --git a/tinyusb/src/portable/ohci/ohci.c b/tinyusb/src/portable/ohci/ohci.c
deleted file mode 100755
index bcee3493..00000000
--- a/tinyusb/src/portable/ohci/ohci.c
+++ /dev/null
@@ -1,657 +0,0 @@
-/*
- * The MIT License (MIT)
- *
- * Copyright (c) 2019 Ha Thach (tinyusb.org)
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- *
- * This file is part of the TinyUSB stack.
- */
-
-#include "host/hcd_attr.h"
-
-#if TUSB_OPT_HOST_ENABLED && defined(HCD_ATTR_OHCI)
-
-//--------------------------------------------------------------------+
-// INCLUDE
-//--------------------------------------------------------------------+
-#include "osal/osal.h"
-
-#include "host/hcd.h"
-#include "ohci.h"
-
-// TODO remove
-#include "chip.h"
-
-//--------------------------------------------------------------------+
-// MACRO CONSTANT TYPEDEF
-//--------------------------------------------------------------------+
-#define OHCI_REG ((ohci_registers_t *) LPC_USB_BASE)
-
-enum {
- OHCI_CONTROL_FUNCSTATE_RESET = 0,
- OHCI_CONTROL_FUNCSTATE_RESUME,
- OHCI_CONTROL_FUNCSTATE_OPERATIONAL,
- OHCI_CONTROL_FUNCSTATE_SUSPEND
-};
-
-enum {
- OHCI_CONTROL_CONTROL_BULK_RATIO = 3, ///< This specifies the service ratio between Control and Bulk EDs. 0 = 1:1, 3 = 4:1
- OHCI_CONTROL_LIST_PERIODIC_ENABLE_MASK = TU_BIT(2),
- OHCI_CONTROL_LIST_ISOCHRONOUS_ENABLE_MASK = TU_BIT(3),
- OHCI_CONTROL_LIST_CONTROL_ENABLE_MASK = TU_BIT(4),
- OHCI_CONTROL_LIST_BULK_ENABLE_MASK = TU_BIT(5),
-};
-
-enum {
- OHCI_FMINTERVAL_FI = 0x2EDF, // 7.3.1 nominal (reset) value
- OHCI_FMINTERVAL_FSMPS = (6*(OHCI_FMINTERVAL_FI-210)) / 7, // 5.4 calculated based on maximum overhead + bit stuffing
-};
-
-enum {
- OHCI_PERIODIC_START = 0x3E67
-};
-
-enum {
- OHCI_INT_SCHEDULING_OVERUN_MASK = TU_BIT(0),
- OHCI_INT_WRITEBACK_DONEHEAD_MASK = TU_BIT(1),
- OHCI_INT_SOF_MASK = TU_BIT(2),
- OHCI_INT_RESUME_DETECTED_MASK = TU_BIT(3),
- OHCI_INT_UNRECOVERABLE_ERROR_MASK = TU_BIT(4),
- OHCI_INT_FRAME_OVERFLOW_MASK = TU_BIT(5),
- OHCI_INT_RHPORT_STATUS_CHANGE_MASK = TU_BIT(6),
-
- OHCI_INT_OWNERSHIP_CHANGE_MASK = TU_BIT(30),
- OHCI_INT_MASTER_ENABLE_MASK = TU_BIT(31),
-};
-
-enum {
- RHPORT_CURRENT_CONNECT_STATUS_MASK = TU_BIT(0),
- RHPORT_PORT_ENABLE_STATUS_MASK = TU_BIT(1),
- RHPORT_PORT_SUSPEND_STATUS_MASK = TU_BIT(2),
- RHPORT_PORT_OVER_CURRENT_INDICATOR_MASK = TU_BIT(3),
- RHPORT_PORT_RESET_STATUS_MASK = TU_BIT(4), ///< write '1' to reset port
-
- RHPORT_PORT_POWER_STATUS_MASK = TU_BIT(8),
- RHPORT_LOW_SPEED_DEVICE_ATTACHED_MASK = TU_BIT(9),
-
- RHPORT_CONNECT_STATUS_CHANGE_MASK = TU_BIT(16),
- RHPORT_PORT_ENABLE_CHANGE_MASK = TU_BIT(17),
- RHPORT_PORT_SUSPEND_CHANGE_MASK = TU_BIT(18),
- RHPORT_OVER_CURRENT_CHANGE_MASK = TU_BIT(19),
- RHPORT_PORT_RESET_CHANGE_MASK = TU_BIT(20),
-
- RHPORT_ALL_CHANGE_MASK = RHPORT_CONNECT_STATUS_CHANGE_MASK | RHPORT_PORT_ENABLE_CHANGE_MASK |
- RHPORT_PORT_SUSPEND_CHANGE_MASK | RHPORT_OVER_CURRENT_CHANGE_MASK | RHPORT_PORT_RESET_CHANGE_MASK
-};
-
-enum {
- OHCI_CCODE_NO_ERROR = 0,
- OHCI_CCODE_CRC = 1,
- OHCI_CCODE_BIT_STUFFING = 2,
- OHCI_CCODE_DATA_TOGGLE_MISMATCH = 3,
- OHCI_CCODE_STALL = 4,
- OHCI_CCODE_DEVICE_NOT_RESPONDING = 5,
- OHCI_CCODE_PID_CHECK_FAILURE = 6,
- OHCI_CCODE_UNEXPECTED_PID = 7,
- OHCI_CCODE_DATA_OVERRUN = 8,
- OHCI_CCODE_DATA_UNDERRUN = 9,
- OHCI_CCODE_BUFFER_OVERRUN = 12,
- OHCI_CCODE_BUFFER_UNDERRUN = 13,
- OHCI_CCODE_NOT_ACCESSED = 14,
-};
-
-enum {
- OHCI_INT_ON_COMPLETE_YES = 0,
- OHCI_INT_ON_COMPLETE_NO = TU_BIN8(111)
-};
-
-enum {
- GTD_DT_TOGGLE_CARRY = 0,
- GTD_DT_DATA0 = TU_BIT(1) | 0,
- GTD_DT_DATA1 = TU_BIT(1) | 1,
-};
-
-enum {
- PID_SETUP = 0,
- PID_OUT,
- PID_IN,
-};
-
-enum {
- PID_FROM_TD = 0,
-};
-
-//--------------------------------------------------------------------+
-// INTERNAL OBJECT & FUNCTION DECLARATION
-//--------------------------------------------------------------------+
-CFG_TUSB_MEM_SECTION TU_ATTR_ALIGNED(256) static ohci_data_t ohci_data;
-
-static ohci_ed_t * const p_ed_head[] =
-{
- [TUSB_XFER_CONTROL] = &ohci_data.control[0].ed,
- [TUSB_XFER_BULK ] = &ohci_data.bulk_head_ed,
- [TUSB_XFER_INTERRUPT] = &ohci_data.period_head_ed,
- [TUSB_XFER_ISOCHRONOUS] = NULL // TODO Isochronous
-};
-
-static void ed_list_insert(ohci_ed_t * p_pre, ohci_ed_t * p_ed);
-static void ed_list_remove_by_addr(ohci_ed_t * p_head, uint8_t dev_addr);
-
-//--------------------------------------------------------------------+
-// USBH-HCD API
-//--------------------------------------------------------------------+
-// Initialization according to 5.1.1.4
-bool hcd_init(uint8_t rhport)
-{
- (void) rhport;
-
- //------------- Data Structure init -------------//
- tu_memclr(&ohci_data, sizeof(ohci_data_t));
- for(uint8_t i=0; i<32; i++)
- { // assign all interrupt pointes to period head ed
- ohci_data.hcca.interrupt_table[i] = (uint32_t) &ohci_data.period_head_ed;
- }
-
- ohci_data.control[0].ed.skip = 1;
- ohci_data.bulk_head_ed.skip = 1;
- ohci_data.period_head_ed.skip = 1;
-
- // reset controller
- OHCI_REG->command_status_bit.controller_reset = 1;
- while( OHCI_REG->command_status_bit.controller_reset ) {} // should not take longer than 10 us
-
- //------------- init ohci registers -------------//
- OHCI_REG->control_head_ed = (uint32_t) &ohci_data.control[0].ed;
- OHCI_REG->bulk_head_ed = (uint32_t) &ohci_data.bulk_head_ed;
- OHCI_REG->hcca = (uint32_t) &ohci_data.hcca;
-
- OHCI_REG->interrupt_disable = OHCI_REG->interrupt_enable; // disable all interrupts
- OHCI_REG->interrupt_status = OHCI_REG->interrupt_status; // clear current set bits
- OHCI_REG->interrupt_enable = OHCI_INT_WRITEBACK_DONEHEAD_MASK | OHCI_INT_RESUME_DETECTED_MASK |
- OHCI_INT_UNRECOVERABLE_ERROR_MASK | OHCI_INT_FRAME_OVERFLOW_MASK | OHCI_INT_RHPORT_STATUS_CHANGE_MASK |
- OHCI_INT_MASTER_ENABLE_MASK;
-
- OHCI_REG->control |= OHCI_CONTROL_CONTROL_BULK_RATIO | OHCI_CONTROL_LIST_CONTROL_ENABLE_MASK |
- OHCI_CONTROL_LIST_BULK_ENABLE_MASK | OHCI_CONTROL_LIST_PERIODIC_ENABLE_MASK; // TODO Isochronous
-
- OHCI_REG->frame_interval = (OHCI_FMINTERVAL_FSMPS << 16) | OHCI_FMINTERVAL_FI;
- OHCI_REG->periodic_start = (OHCI_FMINTERVAL_FI * 9) / 10; // Periodic start is 90% of frame interval
-
- OHCI_REG->control_bit.hc_functional_state = OHCI_CONTROL_FUNCSTATE_OPERATIONAL; // make HC's state to operational state TODO use this to suspend (save power)
- OHCI_REG->rh_status_bit.local_power_status_change = 1; // set global power for ports
-
- return true;
-}
-
-uint32_t hcd_frame_number(uint8_t rhport)
-{
- (void) rhport;
- return (ohci_data.frame_number_hi << 16) | OHCI_REG->frame_number;
-}
-
-
-//--------------------------------------------------------------------+
-// PORT API
-//--------------------------------------------------------------------+
-void hcd_port_reset(uint8_t hostid)
-{
- (void) hostid;
- OHCI_REG->rhport_status[0] = RHPORT_PORT_RESET_STATUS_MASK;
-}
-
-bool hcd_port_connect_status(uint8_t hostid)
-{
- (void) hostid;
- return OHCI_REG->rhport_status_bit[0].current_connect_status;
-}
-
-tusb_speed_t hcd_port_speed_get(uint8_t hostid)
-{
- (void) hostid;
- return OHCI_REG->rhport_status_bit[0].low_speed_device_attached ? TUSB_SPEED_LOW : TUSB_SPEED_FULL;
-}
-
-// endpoints are tied to an address, which only reclaim after a long delay when enumerating
-// thus there is no need to make sure ED is not in HC's cahed as it will not for sure
-void hcd_device_close(uint8_t rhport, uint8_t dev_addr)
-{
- // TODO OHCI
- (void) rhport;
-
- // addr0 serves as static head --> only set skip bit
- if ( dev_addr == 0 )
- {
- ohci_data.control[0].ed.skip = 1;
- }else
- {
- // remove control
- ed_list_remove_by_addr( p_ed_head[TUSB_XFER_CONTROL], dev_addr);
-
- // remove bulk
- ed_list_remove_by_addr(p_ed_head[TUSB_XFER_BULK], dev_addr);
-
- // remove interrupt
- ed_list_remove_by_addr(p_ed_head[TUSB_XFER_INTERRUPT], dev_addr);
-
- // TODO remove ISO
- }
-}
-
-//--------------------------------------------------------------------+
-// Controller API
-//--------------------------------------------------------------------+
-
-//--------------------------------------------------------------------+
-// List Helper
-//--------------------------------------------------------------------+
-static inline tusb_xfer_type_t ed_get_xfer_type(ohci_ed_t const * const p_ed)
-{
- return (p_ed->ep_number == 0 ) ? TUSB_XFER_CONTROL :
- (p_ed->is_iso ) ? TUSB_XFER_ISOCHRONOUS :
- (p_ed->is_interrupt_xfer) ? TUSB_XFER_INTERRUPT : TUSB_XFER_BULK;
-}
-
-static void ed_init(ohci_ed_t *p_ed, uint8_t dev_addr, uint16_t ep_size, uint8_t ep_addr, uint8_t xfer_type, uint8_t interval)
-{
- (void) interval;
-
- // address 0 is used as async head, which always on the list --> cannot be cleared
- if (dev_addr != 0)
- {
- tu_memclr(p_ed, sizeof(ohci_ed_t));
- }
-
- hcd_devtree_info_t devtree_info;
- hcd_devtree_get_info(dev_addr, &devtree_info);
-
- p_ed->dev_addr = dev_addr;
- p_ed->ep_number = ep_addr & 0x0F;
- p_ed->pid = (xfer_type == TUSB_XFER_CONTROL) ? PID_FROM_TD : (tu_edpt_dir(ep_addr) ? PID_IN : PID_OUT);
- p_ed->speed = devtree_info.speed;
- p_ed->is_iso = (xfer_type == TUSB_XFER_ISOCHRONOUS) ? 1 : 0;
- p_ed->max_packet_size = ep_size;
-
- p_ed->used = 1;
- p_ed->is_interrupt_xfer = (xfer_type == TUSB_XFER_INTERRUPT ? 1 : 0);
-}
-
-static void gtd_init(ohci_gtd_t* p_td, uint8_t* data_ptr, uint16_t total_bytes)
-{
- tu_memclr(p_td, sizeof(ohci_gtd_t));
-
- p_td->used = 1;
- p_td->expected_bytes = total_bytes;
-
- p_td->buffer_rounding = 1; // less than queued length is not a error
- p_td->delay_interrupt = OHCI_INT_ON_COMPLETE_NO;
- p_td->condition_code = OHCI_CCODE_NOT_ACCESSED;
-
- p_td->current_buffer_pointer = data_ptr;
- p_td->buffer_end = total_bytes ? (data_ptr + total_bytes-1) : data_ptr;
-}
-
-static ohci_ed_t * ed_from_addr(uint8_t dev_addr, uint8_t ep_addr)
-{
- if ( tu_edpt_number(ep_addr) == 0 ) return &ohci_data.control[dev_addr].ed;
-
- ohci_ed_t* ed_pool = ohci_data.ed_pool;
-
- for(uint32_t i=0; i<HCD_MAX_ENDPOINT; i++)
- {
- if ( (ed_pool[i].dev_addr == dev_addr) &&
- ep_addr == tu_edpt_addr(ed_pool[i].ep_number, ed_pool[i].pid == PID_IN) )
- {
- return &ed_pool[i];
- }
- }
-
- return NULL;
-}
-
-static ohci_ed_t * ed_find_free(void)
-{
- ohci_ed_t* ed_pool = ohci_data.ed_pool;
-
- for(uint8_t i = 0; i < HCD_MAX_ENDPOINT; i++)
- {
- if ( !ed_pool[i].used ) return &ed_pool[i];
- }
-
- return NULL;
-}
-
-static void ed_list_insert(ohci_ed_t * p_pre, ohci_ed_t * p_ed)
-{
- p_ed->next = p_pre->next;
- p_pre->next = (uint32_t) p_ed;
-}
-
-static void ed_list_remove_by_addr(ohci_ed_t * p_head, uint8_t dev_addr)
-{
- ohci_ed_t* p_prev = p_head;
-
- while( p_prev->next )
- {
- ohci_ed_t* ed = (ohci_ed_t*) p_prev->next;
-
- if (ed->dev_addr == dev_addr)
- {
- // unlink ed
- p_prev->next = ed->next;
-
- // point the removed ED's next pointer to list head to make sure HC can always safely move away from this ED
- ed->next = (uint32_t) p_head;
- ed->used = 0;
- }
-
- // check next valid since we could remove it
- if (p_prev->next) p_prev = (ohci_ed_t*) p_prev->next;
- }
-}
-
-static ohci_gtd_t * gtd_find_free(void)
-{
- for(uint8_t i=0; i < HCD_MAX_XFER; i++)
- {
- if ( !ohci_data.gtd_pool[i].used ) return &ohci_data.gtd_pool[i];
- }
-
- return NULL;
-}
-
-static void td_insert_to_ed(ohci_ed_t* p_ed, ohci_gtd_t * p_gtd)
-{
- // tail is always NULL
- if ( tu_align16(p_ed->td_head.address) == 0 )
- { // TD queue is empty --> head = TD
- p_ed->td_head.address |= (uint32_t) p_gtd;
- }
- else
- { // TODO currently only support queue up to 2 TD each endpoint at a time
- ((ohci_gtd_t*) tu_align16(p_ed->td_head.address))->next = (uint32_t) p_gtd;
- }
-}
-
-//--------------------------------------------------------------------+
-// Endpoint API
-//--------------------------------------------------------------------+
-
-bool hcd_edpt_open(uint8_t rhport, uint8_t dev_addr, tusb_desc_endpoint_t const * ep_desc)
-{
- (void) rhport;
-
- // TODO iso support
- TU_ASSERT(ep_desc->bmAttributes.xfer != TUSB_XFER_ISOCHRONOUS);
-
- //------------- Prepare Queue Head -------------//
- ohci_ed_t * p_ed;
-
- if ( ep_desc->bEndpointAddress == 0 )
- {
- p_ed = &ohci_data.control[dev_addr].ed;
- }else
- {
- p_ed = ed_find_free();
- }
- TU_ASSERT(p_ed);
-
- ed_init( p_ed, dev_addr, ep_desc->wMaxPacketSize.size, ep_desc->bEndpointAddress,
- ep_desc->bmAttributes.xfer, ep_desc->bInterval );
-
- // control of dev0 is used as static async head
- if ( dev_addr == 0 )
- {
- p_ed->skip = 0; // only need to clear skip bit
- return true;
- }
-
- ed_list_insert( p_ed_head[ep_desc->bmAttributes.xfer], p_ed );
-
- return true;
-}
-
-bool hcd_setup_send(uint8_t rhport, uint8_t dev_addr, uint8_t const setup_packet[8])
-{
- (void) rhport;
-
- ohci_ed_t* ed = &ohci_data.control[dev_addr].ed;
- ohci_gtd_t *qtd = &ohci_data.control[dev_addr].gtd;
-
- gtd_init(qtd, (uint8_t*) setup_packet, 8);
- qtd->index = dev_addr;
- qtd->pid = PID_SETUP;
- qtd->data_toggle = GTD_DT_DATA0;
- qtd->delay_interrupt = 0;
-
- //------------- Attach TDs list to Control Endpoint -------------//
- ed->td_head.address = (uint32_t) qtd;
-
- OHCI_REG->command_status_bit.control_list_filled = 1;
-
- return true;
-}
-
-bool hcd_edpt_xfer(uint8_t rhport, uint8_t dev_addr, uint8_t ep_addr, uint8_t * buffer, uint16_t buflen)
-{
- (void) rhport;
-
- uint8_t const epnum = tu_edpt_number(ep_addr);
- uint8_t const dir = tu_edpt_dir(ep_addr);
-
- if ( epnum == 0 )
- {
- ohci_ed_t* ed = &ohci_data.control[dev_addr].ed;
- ohci_gtd_t* gtd = &ohci_data.control[dev_addr].gtd;
-
- gtd_init(gtd, buffer, buflen);
-
- gtd->index = dev_addr;
- gtd->pid = dir ? PID_IN : PID_OUT;
- gtd->data_toggle = GTD_DT_DATA1; // Both Data and Ack stage start with DATA1
- gtd->delay_interrupt = 0;
-
- ed->td_head.address = (uint32_t) gtd;
-
- OHCI_REG->command_status_bit.control_list_filled = 1;
- }else
- {
- ohci_ed_t * ed = ed_from_addr(dev_addr, ep_addr);
- ohci_gtd_t* gtd = gtd_find_free();
-
- TU_ASSERT(gtd);
-
- gtd_init(gtd, buffer, buflen);
- gtd->index = ed-ohci_data.ed_pool;
- gtd->delay_interrupt = 0;
-
- td_insert_to_ed(ed, gtd);
-
- tusb_xfer_type_t xfer_type = ed_get_xfer_type( ed_from_addr(dev_addr, ep_addr) );
- if (TUSB_XFER_BULK == xfer_type) OHCI_REG->command_status_bit.bulk_list_filled = 1;
- }
-
- return true;
-}
-
-bool hcd_edpt_clear_stall(uint8_t dev_addr, uint8_t ep_addr)
-{
- ohci_ed_t * const p_ed = ed_from_addr(dev_addr, ep_addr);
-
- p_ed->is_stalled = 0;
- p_ed->td_tail &= 0x0Ful; // set tail pointer back to NULL
-
- p_ed->td_head.toggle = 0; // reset data toggle
- p_ed->td_head.halted = 0;
-
- if ( TUSB_XFER_BULK == ed_get_xfer_type(p_ed) ) OHCI_REG->command_status_bit.bulk_list_filled = 1;
-
- return true;
-}
-
-
-//--------------------------------------------------------------------+
-// OHCI Interrupt Handler
-//--------------------------------------------------------------------+
-static ohci_td_item_t* list_reverse(ohci_td_item_t* td_head)
-{
- ohci_td_item_t* td_reverse_head = NULL;
-
- while(td_head != NULL)
- {
- uint32_t next = td_head->next;
-
- // make current's item become reverse's first item
- td_head->next = (uint32_t) td_reverse_head;
- td_reverse_head = td_head;
-
- td_head = (ohci_td_item_t*) next; // advance to next item
- }
-
- return td_reverse_head;
-}
-
-static inline bool gtd_is_control(ohci_gtd_t const * const p_qtd)
-{
- return ((uint32_t) p_qtd) < ((uint32_t) ohci_data.gtd_pool); // check ohci_data_t for memory layout
-}
-
-static inline ohci_ed_t* gtd_get_ed(ohci_gtd_t const * const p_qtd)
-{
- if ( gtd_is_control(p_qtd) )
- {
- return &ohci_data.control[p_qtd->index].ed;
- }else
- {
- return &ohci_data.ed_pool[p_qtd->index];
- }
-}
-
-static inline uint32_t gtd_xfer_byte_left(uint32_t buffer_end, uint32_t current_buffer)
-{
- // 5.2.9 OHCI sample code
-
- // CBP is 0 mean all data is transferred
- if (current_buffer == 0) return 0;
-
- return (tu_align4k(buffer_end ^ current_buffer) ? 0x1000 : 0) +
- tu_offset4k(buffer_end) - tu_offset4k(current_buffer) + 1;
-}
-
-static void done_queue_isr(uint8_t hostid)
-{
- (void) hostid;
-
- // done head is written in reversed order of completion --> need to reverse the done queue first
- ohci_td_item_t* td_head = list_reverse ( (ohci_td_item_t*) tu_align16(ohci_data.hcca.done_head) );
-
- while( td_head != NULL )
- {
- // TODO check if td_head is iso td
- //------------- Non ISO transfer -------------//
- ohci_gtd_t * const qtd = (ohci_gtd_t *) td_head;
- xfer_result_t const event = (qtd->condition_code == OHCI_CCODE_NO_ERROR) ? XFER_RESULT_SUCCESS :
- (qtd->condition_code == OHCI_CCODE_STALL) ? XFER_RESULT_STALLED : XFER_RESULT_FAILED;
-
- qtd->used = 0; // free TD
- if ( (qtd->delay_interrupt == OHCI_INT_ON_COMPLETE_YES) || (event != XFER_RESULT_SUCCESS) )
- {
- ohci_ed_t * const ed = gtd_get_ed(qtd);
-
- uint32_t const xferred_bytes = qtd->expected_bytes - gtd_xfer_byte_left((uint32_t) qtd->buffer_end, (uint32_t) qtd->current_buffer_pointer);
-
- // NOTE Assuming the current list is BULK and there is no other EDs in the list has queued TDs.
- // When there is a error resulting this ED is halted, and this EP still has other queued TD
- // --> the Bulk list only has this halted EP queueing TDs (remaining)
- // --> Bulk list will be considered as not empty by HC !!! while there is no attempt transaction on this list
- // --> HC will not process Control list (due to service ratio when Bulk list not empty)
- // To walk-around this, the halted ED will have TailP = HeadP (empty list condition), when clearing halt
- // the TailP must be set back to NULL for processing remaining TDs
- if ((event != XFER_RESULT_SUCCESS))
- {
- ed->td_tail &= 0x0Ful;
- ed->td_tail |= tu_align16(ed->td_head.address); // mark halted EP as empty queue
- if ( event == XFER_RESULT_STALLED ) ed->is_stalled = 1;
- }
-
- uint8_t dir = (ed->ep_number == 0) ? (qtd->pid == PID_IN) : (ed->pid == PID_IN);
-
- hcd_event_xfer_complete(ed->dev_addr, tu_edpt_addr(ed->ep_number, dir), xferred_bytes, event, true);
- }
-
- td_head = (ohci_td_item_t*) td_head->next;
- }
-}
-
-void hcd_int_handler(uint8_t hostid)
-{
- uint32_t const int_en = OHCI_REG->interrupt_enable;
- uint32_t const int_status = OHCI_REG->interrupt_status & int_en;
-
- if (int_status == 0) return;
-
- // Frame number overflow
- if ( int_status & OHCI_INT_FRAME_OVERFLOW_MASK )
- {
- ohci_data.frame_number_hi++;
- }
-
- //------------- RootHub status -------------//
- if ( int_status & OHCI_INT_RHPORT_STATUS_CHANGE_MASK )
- {
- uint32_t const rhport_status = OHCI_REG->rhport_status[0] & RHPORT_ALL_CHANGE_MASK;
-
- // TODO dual port is not yet supported
- if ( rhport_status & RHPORT_CONNECT_STATUS_CHANGE_MASK )
- {
- // TODO check if remote wake-up
- if ( OHCI_REG->rhport_status_bit[0].current_connect_status )
- {
- // TODO reset port immediately, without this controller will got 2-3 (debouncing connection status change)
- OHCI_REG->rhport_status[0] = RHPORT_PORT_RESET_STATUS_MASK;
- hcd_event_device_attach(hostid, true);
- }else
- {
- hcd_event_device_remove(hostid, true);
- }
- }
-
- if ( rhport_status & RHPORT_PORT_SUSPEND_CHANGE_MASK)
- {
-
- }
-
- OHCI_REG->rhport_status[0] = rhport_status; // acknowledge all interrupt
- }
-
- //------------- Transfer Complete -------------//
- if (int_status & OHCI_INT_WRITEBACK_DONEHEAD_MASK)
- {
- done_queue_isr(hostid);
- }
-
- OHCI_REG->interrupt_status = int_status; // Acknowledge handled interrupt
-}
-//--------------------------------------------------------------------+
-// HELPER
-//--------------------------------------------------------------------+
-
-
-#endif
-
diff --git a/tinyusb/src/portable/ohci/ohci.h b/tinyusb/src/portable/ohci/ohci.h
deleted file mode 100755
index cd90aa45..00000000
--- a/tinyusb/src/portable/ohci/ohci.h
+++ /dev/null
@@ -1,275 +0,0 @@
-/*
- * The MIT License (MIT)
- *
- * Copyright (c) 2019 Ha Thach (tinyusb.org)
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- *
- * This file is part of the TinyUSB stack.
- */
-
-#ifndef _TUSB_OHCI_H_
-#define _TUSB_OHCI_H_
-
-#ifdef __cplusplus
- extern "C" {
-#endif
-
-//--------------------------------------------------------------------+
-// OHCI CONFIGURATION & CONSTANTS
-//--------------------------------------------------------------------+
-#define HOST_HCD_XFER_INTERRUPT // TODO interrupt is used widely, should always be enalbed
-#define OHCI_PERIODIC_LIST (defined HOST_HCD_XFER_INTERRUPT || defined HOST_HCD_XFER_ISOCHRONOUS)
-
-// TODO merge OHCI with EHCI
-enum {
- OHCI_MAX_ITD = 4
-};
-
-//--------------------------------------------------------------------+
-// OHCI Data Structure
-//--------------------------------------------------------------------+
-typedef struct {
- uint32_t interrupt_table[32];
- volatile uint16_t frame_number;
- volatile uint16_t frame_pad;
- volatile uint32_t done_head;
- uint8_t reserved[116+4]; // TODO try to make use of this area if possible, extra 4 byte to make the whole struct size = 256
-}ohci_hcca_t; // TU_ATTR_ALIGNED(256)
-
-TU_VERIFY_STATIC( sizeof(ohci_hcca_t) == 256, "size is not correct" );
-
-typedef struct {
- uint32_t reserved[2];
- volatile uint32_t next;
- uint32_t reserved2;
-}ohci_td_item_t;
-
-typedef struct TU_ATTR_ALIGNED(16)
-{
- // Word 0
- uint32_t used : 1;
- uint32_t index : 4; // endpoint index the td belongs to, or device address in case of control xfer
- uint32_t expected_bytes : 13; // TODO available for hcd
-
- uint32_t buffer_rounding : 1;
- uint32_t pid : 2;
- uint32_t delay_interrupt : 3;
- volatile uint32_t data_toggle : 2;
- volatile uint32_t error_count : 2;
- volatile uint32_t condition_code : 4;
-
- // Word 1
- volatile uint8_t* current_buffer_pointer;
-
- // Word 2 : next TD
- volatile uint32_t next;
-
- // Word 3
- uint8_t* buffer_end;
-} ohci_gtd_t;
-
-TU_VERIFY_STATIC( sizeof(ohci_gtd_t) == 16, "size is not correct" );
-
-typedef struct TU_ATTR_ALIGNED(16)
-{
- // Word 0
- uint32_t dev_addr : 7;
- uint32_t ep_number : 4;
- uint32_t pid : 2;
- uint32_t speed : 1;
- uint32_t skip : 1;
- uint32_t is_iso : 1;
- uint32_t max_packet_size : 11;
- // HCD: make use of 5 reserved bits
- uint32_t used : 1;
- uint32_t is_interrupt_xfer : 1;
- uint32_t is_stalled : 1;
- uint32_t : 2;
-
- // Word 1
- uint32_t td_tail;
-
- // Word 2
- volatile union {
- uint32_t address;
- struct {
- uint32_t halted : 1;
- uint32_t toggle : 1;
- uint32_t : 30;
- };
- }td_head;
-
- // Word 3: next ED
- uint32_t next;
-} ohci_ed_t;
-
-TU_VERIFY_STATIC( sizeof(ohci_ed_t) == 16, "size is not correct" );
-
-typedef struct TU_ATTR_ALIGNED(32)
-{
- /*---------- Word 1 ----------*/
- uint32_t starting_frame : 16;
- uint32_t : 5; // can be used
- uint32_t delay_interrupt : 3;
- uint32_t frame_count : 3;
- uint32_t : 1; // can be used
- volatile uint32_t condition_code : 4;
-
- /*---------- Word 2 ----------*/
- uint32_t buffer_page0; // 12 lsb bits can be used
-
- /*---------- Word 3 ----------*/
- volatile uint32_t next;
-
- /*---------- Word 4 ----------*/
- uint32_t buffer_end;
-
- /*---------- Word 5-8 ----------*/
- volatile uint16_t offset_packetstatus[8];
-} ochi_itd_t;
-
-TU_VERIFY_STATIC( sizeof(ochi_itd_t) == 32, "size is not correct" );
-
-// structure with member alignment required from large to small
-typedef struct TU_ATTR_ALIGNED(256)
-{
- ohci_hcca_t hcca;
-
- ohci_ed_t bulk_head_ed; // static bulk head (dummy)
- ohci_ed_t period_head_ed; // static periodic list head (dummy)
-
- // control endpoints has reserved resources
- struct {
- ohci_ed_t ed;
- ohci_gtd_t gtd;
- }control[CFG_TUH_DEVICE_MAX+1];
-
- // ochi_itd_t itd[OHCI_MAX_ITD]; // itd requires alignment of 32
- ohci_ed_t ed_pool[HCD_MAX_ENDPOINT];
- ohci_gtd_t gtd_pool[HCD_MAX_XFER];
-
- volatile uint16_t frame_number_hi;
-
-} ohci_data_t;
-
-//--------------------------------------------------------------------+
-// OHCI Operational Register
-//--------------------------------------------------------------------+
-
-
-//--------------------------------------------------------------------+
-// OHCI Data Organization
-//--------------------------------------------------------------------+
-typedef volatile struct
-{
- uint32_t revision;
-
- union {
- uint32_t control;
- struct {
- uint32_t control_bulk_service_ratio : 2;
- uint32_t periodic_list_enable : 1;
- uint32_t isochronous_enable : 1;
- uint32_t control_list_enable : 1;
- uint32_t bulk_list_enable : 1;
- uint32_t hc_functional_state : 2;
- uint32_t interrupt_routing : 1;
- uint32_t remote_wakeup_connected : 1;
- uint32_t remote_wakeup_enale : 1;
- uint32_t TU_RESERVED : 21;
- }control_bit;
- };
-
- union {
- uint32_t command_status;
- struct {
- uint32_t controller_reset : 1;
- uint32_t control_list_filled : 1;
- uint32_t bulk_list_filled : 1;
- uint32_t ownership_change_request : 1;
- uint32_t : 12;
- uint32_t scheduling_overrun_count : 2;
- }command_status_bit;
- };
-
- uint32_t interrupt_status;
- uint32_t interrupt_enable;
- uint32_t interrupt_disable;
-
- uint32_t hcca;
- uint32_t period_current_ed;
- uint32_t control_head_ed;
- uint32_t control_current_ed;
- uint32_t bulk_head_ed;
- uint32_t bulk_current_ed;
- uint32_t done_head;
-
- uint32_t frame_interval;
- uint32_t frame_remaining;
- uint32_t frame_number;
- uint32_t periodic_start;
- uint32_t lowspeed_threshold;
-
- uint32_t rh_descriptorA;
- uint32_t rh_descriptorB;
-
- union {
- uint32_t rh_status;
- struct {
- uint32_t local_power_status : 1; // read Local Power Status; write: Clear Global Power
- uint32_t over_current_indicator : 1;
- uint32_t : 13;
- uint32_t device_remote_wakeup_enable : 1;
- uint32_t local_power_status_change : 1;
- uint32_t over_current_indicator_change : 1;
- uint32_t : 13;
- uint32_t clear_remote_wakeup_enable : 1;
- }rh_status_bit;
- };
-
- union {
- uint32_t rhport_status[2]; // TODO NXP OHCI controller only has 2 ports
- struct {
- uint32_t current_connect_status : 1;
- uint32_t port_enable_status : 1;
- uint32_t port_suspend_status : 1;
- uint32_t port_over_current_indicator : 1;
- uint32_t port_reset_status : 1;
- uint32_t : 3;
- uint32_t port_power_status : 1;
- uint32_t low_speed_device_attached : 1;
- uint32_t : 6;
- uint32_t connect_status_change : 1;
- uint32_t port_enable_status_change : 1;
- uint32_t port_suspend_status_change : 1;
- uint32_t port_over_current_indicator_change : 1;
- uint32_t port_reset_status_change : 1;
- uint32_t TU_RESERVED : 11;
- }rhport_status_bit[2];
- };
-}ohci_registers_t;
-
-TU_VERIFY_STATIC( sizeof(ohci_registers_t) == 0x5c, "size is not correct");
-
-#ifdef __cplusplus
- }
-#endif
-
-#endif /* _TUSB_OHCI_H_ */
diff --git a/tinyusb/src/portable/raspberrypi/rp2040/dcd_rp2040.c b/tinyusb/src/portable/raspberrypi/rp2040/dcd_rp2040.c
deleted file mode 100755
index 49284e92..00000000
--- a/tinyusb/src/portable/raspberrypi/rp2040/dcd_rp2040.c
+++ /dev/null
@@ -1,485 +0,0 @@
-/*
- * The MIT License (MIT)
- *
- * Copyright (c) 2020 Raspberry Pi (Trading) Ltd.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- *
- * This file is part of the TinyUSB stack.
- */
-
-#include "tusb_option.h"
-
-#if TUSB_OPT_DEVICE_ENABLED && CFG_TUSB_MCU == OPT_MCU_RP2040
-
-#include "pico.h"
-#include "rp2040_usb.h"
-
-#if TUD_OPT_RP2040_USB_DEVICE_ENUMERATION_FIX
-#include "pico/fix/rp2040_usb_device_enumeration.h"
-#endif
-
-#include "device/dcd.h"
-
-// Current implementation force vbus detection as always present, causing device think it is always plugged into host.
-// Therefore it cannot detect disconnect event, mistaken it as suspend.
-// Note: won't work if change to 0 (for now)
-#define FORCE_VBUS_DETECT 1
-
-/*------------------------------------------------------------------*/
-/* Low level controller
- *------------------------------------------------------------------*/
-
-#define usb_hw_set hw_set_alias(usb_hw)
-#define usb_hw_clear hw_clear_alias(usb_hw)
-
-// Init these in dcd_init
-static uint8_t *next_buffer_ptr;
-
-// USB_MAX_ENDPOINTS Endpoints, direction TUSB_DIR_OUT for out and TUSB_DIR_IN for in.
-static struct hw_endpoint hw_endpoints[USB_MAX_ENDPOINTS][2];
-
-static inline struct hw_endpoint *hw_endpoint_get_by_num(uint8_t num, tusb_dir_t dir)
-{
- return &hw_endpoints[num][dir];
-}
-
-static struct hw_endpoint *hw_endpoint_get_by_addr(uint8_t ep_addr)
-{
- uint8_t num = tu_edpt_number(ep_addr);
- tusb_dir_t dir = tu_edpt_dir(ep_addr);
- return hw_endpoint_get_by_num(num, dir);
-}
-
-static void _hw_endpoint_alloc(struct hw_endpoint *ep, uint8_t transfer_type)
-{
- // size must be multiple of 64
- uint16_t size = tu_div_ceil(ep->wMaxPacketSize, 64) * 64u;
-
- // double buffered Bulk endpoint
- if ( transfer_type == TUSB_XFER_BULK )
- {
- size *= 2u;
- }
-
- ep->hw_data_buf = next_buffer_ptr;
- next_buffer_ptr += size;
-
- assert(((uintptr_t )next_buffer_ptr & 0b111111u) == 0);
- uint dpram_offset = hw_data_offset(ep->hw_data_buf);
- assert(hw_data_offset(next_buffer_ptr) <= USB_DPRAM_MAX);
-
- pico_info(" Alloced %d bytes at offset 0x%x (0x%p)\r\n", size, dpram_offset, ep->hw_data_buf);
-
- // Fill in endpoint control register with buffer offset
- uint32_t const reg = EP_CTRL_ENABLE_BITS | (transfer_type << EP_CTRL_BUFFER_TYPE_LSB) | dpram_offset;
-
- *ep->endpoint_control = reg;
-}
-
-#if 0 // todo unused
-static void _hw_endpoint_close(struct hw_endpoint *ep)
-{
- // Clear hardware registers and then zero the struct
- // Clears endpoint enable
- *ep->endpoint_control = 0;
- // Clears buffer available, etc
- *ep->buffer_control = 0;
- // Clear any endpoint state
- memset(ep, 0, sizeof(struct hw_endpoint));
-}
-
-static void hw_endpoint_close(uint8_t ep_addr)
-{
- struct hw_endpoint *ep = hw_endpoint_get_by_addr(ep_addr);
- _hw_endpoint_close(ep);
-}
-#endif
-
-static void hw_endpoint_init(uint8_t ep_addr, uint16_t wMaxPacketSize, uint8_t transfer_type)
-{
- struct hw_endpoint *ep = hw_endpoint_get_by_addr(ep_addr);
-
- const uint8_t num = tu_edpt_number(ep_addr);
- const tusb_dir_t dir = tu_edpt_dir(ep_addr);
-
- ep->ep_addr = ep_addr;
-
- // For device, IN is a tx transfer and OUT is an rx transfer
- ep->rx = (dir == TUSB_DIR_OUT);
-
- // Response to a setup packet on EP0 starts with pid of 1
- ep->next_pid = (num == 0 ? 1u : 0u);
-
- ep->wMaxPacketSize = wMaxPacketSize;
- ep->transfer_type = transfer_type;
-
- // Every endpoint has a buffer control register in dpram
- if ( dir == TUSB_DIR_IN )
- {
- ep->buffer_control = &usb_dpram->ep_buf_ctrl[num].in;
- }
- else
- {
- ep->buffer_control = &usb_dpram->ep_buf_ctrl[num].out;
- }
-
- // Clear existing buffer control state
- *ep->buffer_control = 0;
-
- if ( num == 0 )
- {
- // EP0 has no endpoint control register because
- // the buffer offsets are fixed
- ep->endpoint_control = NULL;
-
- // Buffer offset is fixed (also double buffered)
- ep->hw_data_buf = (uint8_t*) &usb_dpram->ep0_buf_a[0];
- }
- else
- {
- // Set the endpoint control register (starts at EP1, hence num-1)
- if ( dir == TUSB_DIR_IN )
- {
- ep->endpoint_control = &usb_dpram->ep_ctrl[num - 1].in;
- }
- else
- {
- ep->endpoint_control = &usb_dpram->ep_ctrl[num - 1].out;
- }
-
- // alloc a buffer and fill in endpoint control register
- _hw_endpoint_alloc(ep, transfer_type);
- }
-}
-
-static void hw_endpoint_xfer(uint8_t ep_addr, uint8_t *buffer, uint16_t total_bytes)
-{
- struct hw_endpoint *ep = hw_endpoint_get_by_addr(ep_addr);
- hw_endpoint_xfer_start(ep, buffer, total_bytes);
-}
-
-static void hw_handle_buff_status(void)
-{
- uint32_t remaining_buffers = usb_hw->buf_status;
- pico_trace("buf_status 0x%08x\n", remaining_buffers);
- uint bit = 1u;
- for (uint i = 0; remaining_buffers && i < USB_MAX_ENDPOINTS * 2; i++)
- {
- if (remaining_buffers & bit)
- {
- // clear this in advance
- usb_hw_clear->buf_status = bit;
- // IN transfer for even i, OUT transfer for odd i
- struct hw_endpoint *ep = hw_endpoint_get_by_num(i >> 1u, !(i & 1u));
- // Continue xfer
- bool done = hw_endpoint_xfer_continue(ep);
- if (done)
- {
- // Notify
- dcd_event_xfer_complete(0, ep->ep_addr, ep->xferred_len, XFER_RESULT_SUCCESS, true);
- hw_endpoint_reset_transfer(ep);
- }
- remaining_buffers &= ~bit;
- }
- bit <<= 1u;
- }
-}
-
-static void reset_ep0(void)
-{
- // If we have finished this transfer on EP0 set pid back to 1 for next
- // setup transfer. Also clear a stall in case
- uint8_t addrs[] = {0x0, 0x80};
- for (uint i = 0 ; i < TU_ARRAY_SIZE(addrs); i++)
- {
- struct hw_endpoint *ep = hw_endpoint_get_by_addr(addrs[i]);
- ep->next_pid = 1u;
- }
-}
-
-static void reset_all_endpoints(void)
-{
- memset(hw_endpoints, 0, sizeof(hw_endpoints));
- next_buffer_ptr = &usb_dpram->epx_data[0];
-
- // Init Control endpoint out & in
- hw_endpoint_init(0x0, 64, TUSB_XFER_CONTROL);
- hw_endpoint_init(0x80, 64, TUSB_XFER_CONTROL);
-}
-
-static void dcd_rp2040_irq(void)
-{
- uint32_t const status = usb_hw->ints;
- uint32_t handled = 0;
-
- if (status & USB_INTS_SETUP_REQ_BITS)
- {
- handled |= USB_INTS_SETUP_REQ_BITS;
- uint8_t const *setup = (uint8_t const *)&usb_dpram->setup_packet;
- // Clear stall bits and reset pid
- reset_ep0();
- // Pass setup packet to tiny usb
- dcd_event_setup_received(0, setup, true);
- usb_hw_clear->sie_status = USB_SIE_STATUS_SETUP_REC_BITS;
- }
-
- if (status & USB_INTS_BUFF_STATUS_BITS)
- {
- handled |= USB_INTS_BUFF_STATUS_BITS;
- hw_handle_buff_status();
- }
-
-#if FORCE_VBUS_DETECT == 0
- // Since we force VBUS detect On, device will always think it is connected and
- // couldn't distinguish between disconnect and suspend
- if (status & USB_INTS_DEV_CONN_DIS_BITS)
- {
- handled |= USB_INTS_DEV_CONN_DIS_BITS;
-
- if ( usb_hw->sie_status & USB_SIE_STATUS_CONNECTED_BITS )
- {
- // Connected: nothing to do
- }else
- {
- // Disconnected
- dcd_event_bus_signal(0, DCD_EVENT_UNPLUGGED, true);
- }
-
- usb_hw_clear->sie_status = USB_SIE_STATUS_CONNECTED_BITS;
- }
-#endif
-
- // SE0 for 2.5 us or more (will last at least 10ms)
- if (status & USB_INTS_BUS_RESET_BITS)
- {
- pico_trace("BUS RESET\n");
-
- handled |= USB_INTS_BUS_RESET_BITS;
-
- usb_hw->dev_addr_ctrl = 0;
- reset_all_endpoints();
- dcd_event_bus_reset(0, TUSB_SPEED_FULL, true);
- usb_hw_clear->sie_status = USB_SIE_STATUS_BUS_RESET_BITS;
-
-#if TUD_OPT_RP2040_USB_DEVICE_ENUMERATION_FIX
- // Only run enumeration walk-around if pull up is enabled
- if ( usb_hw->sie_ctrl & USB_SIE_CTRL_PULLUP_EN_BITS ) rp2040_usb_device_enumeration_fix();
-#endif
- }
-
- /* Note from pico datasheet 4.1.2.6.4 (v1.2)
- * If you enable the suspend interrupt, it is likely you will see a suspend interrupt when
- * the device is first connected but the bus is idle. The bus can be idle for a few ms before
- * the host begins sending start of frame packets. You will also see a suspend interrupt
- * when the device is disconnected if you do not have a VBUS detect circuit connected. This is
- * because without VBUS detection, it is impossible to tell the difference between
- * being disconnected and suspended.
- */
- if (status & USB_INTS_DEV_SUSPEND_BITS)
- {
- handled |= USB_INTS_DEV_SUSPEND_BITS;
- dcd_event_bus_signal(0, DCD_EVENT_SUSPEND, true);
- usb_hw_clear->sie_status = USB_SIE_STATUS_SUSPENDED_BITS;
- }
-
- if (status & USB_INTS_DEV_RESUME_FROM_HOST_BITS)
- {
- handled |= USB_INTS_DEV_RESUME_FROM_HOST_BITS;
- dcd_event_bus_signal(0, DCD_EVENT_RESUME, true);
- usb_hw_clear->sie_status = USB_SIE_STATUS_RESUME_BITS;
- }
-
- if (status ^ handled)
- {
- panic("Unhandled IRQ 0x%x\n", (uint) (status ^ handled));
- }
-}
-
-#define USB_INTS_ERROR_BITS ( \
- USB_INTS_ERROR_DATA_SEQ_BITS | \
- USB_INTS_ERROR_BIT_STUFF_BITS | \
- USB_INTS_ERROR_CRC_BITS | \
- USB_INTS_ERROR_RX_OVERFLOW_BITS | \
- USB_INTS_ERROR_RX_TIMEOUT_BITS)
-
-/*------------------------------------------------------------------*/
-/* Controller API
- *------------------------------------------------------------------*/
-
-void dcd_init (uint8_t rhport)
-{
- pico_trace("dcd_init %d\n", rhport);
- assert(rhport == 0);
-
- // Reset hardware to default state
- rp2040_usb_init();
-
-#if FORCE_VBUS_DETECT
- // Force VBUS detect so the device thinks it is plugged into a host
- usb_hw->pwr = USB_USB_PWR_VBUS_DETECT_BITS | USB_USB_PWR_VBUS_DETECT_OVERRIDE_EN_BITS;
-#endif
-
- irq_set_exclusive_handler(USBCTRL_IRQ, dcd_rp2040_irq);
-
- // reset endpoints
- reset_all_endpoints();
-
- // Initializes the USB peripheral for device mode and enables it.
- // Don't need to enable the pull up here. Force VBUS
- usb_hw->main_ctrl = USB_MAIN_CTRL_CONTROLLER_EN_BITS;
-
- // Enable individual controller IRQS here. Processor interrupt enable will be used
- // for the global interrupt enable...
- // Note: Force VBUS detect cause disconnection not detectable
- usb_hw->sie_ctrl = USB_SIE_CTRL_EP0_INT_1BUF_BITS;
- usb_hw->inte = USB_INTS_BUFF_STATUS_BITS | USB_INTS_BUS_RESET_BITS | USB_INTS_SETUP_REQ_BITS |
- USB_INTS_DEV_SUSPEND_BITS | USB_INTS_DEV_RESUME_FROM_HOST_BITS |
- (FORCE_VBUS_DETECT ? 0 : USB_INTS_DEV_CONN_DIS_BITS);
-
- dcd_connect(rhport);
-}
-
-void dcd_int_enable(uint8_t rhport)
-{
- assert(rhport == 0);
- irq_set_enabled(USBCTRL_IRQ, true);
-}
-
-void dcd_int_disable(uint8_t rhport)
-{
- assert(rhport == 0);
- irq_set_enabled(USBCTRL_IRQ, false);
-}
-
-void dcd_set_address (uint8_t rhport, uint8_t dev_addr)
-{
- pico_trace("dcd_set_address %d %d\n", rhport, dev_addr);
- assert(rhport == 0);
-
- // Can't set device address in hardware until status xfer has complete
- // Send 0len complete response on EP0 IN
- reset_ep0();
- hw_endpoint_xfer(0x80, NULL, 0);
-}
-
-void dcd_remote_wakeup(uint8_t rhport)
-{
- pico_info("dcd_remote_wakeup %d\n", rhport);
- assert(rhport == 0);
- usb_hw_set->sie_ctrl = USB_SIE_CTRL_RESUME_BITS;
-}
-
-// disconnect by disabling internal pull-up resistor on D+/D-
-void dcd_disconnect(uint8_t rhport)
-{
- pico_info("dcd_disconnect %d\n", rhport);
- assert(rhport == 0);
- usb_hw_clear->sie_ctrl = USB_SIE_CTRL_PULLUP_EN_BITS;
-}
-
-// connect by enabling internal pull-up resistor on D+/D-
-void dcd_connect(uint8_t rhport)
-{
- pico_info("dcd_connect %d\n", rhport);
- assert(rhport == 0);
- usb_hw_set->sie_ctrl = USB_SIE_CTRL_PULLUP_EN_BITS;
-}
-
-/*------------------------------------------------------------------*/
-/* DCD Endpoint port
- *------------------------------------------------------------------*/
-
-void dcd_edpt0_status_complete(uint8_t rhport, tusb_control_request_t const * request)
-{
- (void) rhport;
-
- if ( request->bmRequestType_bit.recipient == TUSB_REQ_RCPT_DEVICE &&
- request->bmRequestType_bit.type == TUSB_REQ_TYPE_STANDARD &&
- request->bRequest == TUSB_REQ_SET_ADDRESS )
- {
- pico_trace("Set HW address %d\n", request->wValue);
- usb_hw->dev_addr_ctrl = (uint8_t) request->wValue;
- }
-
- reset_ep0();
-}
-
-bool dcd_edpt_open (uint8_t rhport, tusb_desc_endpoint_t const * desc_edpt)
-{
- assert(rhport == 0);
- hw_endpoint_init(desc_edpt->bEndpointAddress, desc_edpt->wMaxPacketSize.size, desc_edpt->bmAttributes.xfer);
- return true;
-}
-
-bool dcd_edpt_xfer(uint8_t rhport, uint8_t ep_addr, uint8_t * buffer, uint16_t total_bytes)
-{
- assert(rhport == 0);
- hw_endpoint_xfer(ep_addr, buffer, total_bytes);
- return true;
-}
-
-void dcd_edpt_stall(uint8_t rhport, uint8_t ep_addr)
-{
- pico_trace("dcd_edpt_stall %02x\n", ep_addr);
- assert(rhport == 0);
-
- if ( tu_edpt_number(ep_addr) == 0 )
- {
- // A stall on EP0 has to be armed so it can be cleared on the next setup packet
- usb_hw_set->ep_stall_arm = (tu_edpt_dir(ep_addr) == TUSB_DIR_IN) ? USB_EP_STALL_ARM_EP0_IN_BITS : USB_EP_STALL_ARM_EP0_OUT_BITS;
- }
-
- struct hw_endpoint *ep = hw_endpoint_get_by_addr(ep_addr);
-
- // TODO check with double buffered
- _hw_endpoint_buffer_control_set_mask32(ep, USB_BUF_CTRL_STALL);
-}
-
-void dcd_edpt_clear_stall(uint8_t rhport, uint8_t ep_addr)
-{
- pico_trace("dcd_edpt_clear_stall %02x\n", ep_addr);
- assert(rhport == 0);
-
- if (tu_edpt_number(ep_addr))
- {
- struct hw_endpoint *ep = hw_endpoint_get_by_addr(ep_addr);
-
- // clear stall also reset toggle to DATA0
- // TODO check with double buffered
- _hw_endpoint_buffer_control_clear_mask32(ep, USB_BUF_CTRL_STALL | USB_BUF_CTRL_DATA1_PID);
- }
-}
-
-void dcd_edpt_close (uint8_t rhport, uint8_t ep_addr)
-{
- (void) rhport;
- (void) ep_addr;
-
- // usbd.c says: In progress transfers on this EP may be delivered after this call
- pico_trace("dcd_edpt_close %02x\n", ep_addr);
-}
-
-void dcd_int_handler(uint8_t rhport)
-{
- (void) rhport;
- dcd_rp2040_irq();
-}
-
-#endif
diff --git a/tinyusb/src/portable/raspberrypi/rp2040/hcd_rp2040.c b/tinyusb/src/portable/raspberrypi/rp2040/hcd_rp2040.c
deleted file mode 100755
index e51dfac2..00000000
--- a/tinyusb/src/portable/raspberrypi/rp2040/hcd_rp2040.c
+++ /dev/null
@@ -1,564 +0,0 @@
-/*
- * The MIT License (MIT)
- *
- * Copyright (c) 2020 Raspberry Pi (Trading) Ltd.
- * Copyright (c) 2021 Ha Thach (tinyusb.org) for Double Buffered
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- *
- * This file is part of the TinyUSB stack.
- */
-
-#include "tusb_option.h"
-
-#if TUSB_OPT_HOST_ENABLED && CFG_TUSB_MCU == OPT_MCU_RP2040
-
-#include "pico.h"
-#include "rp2040_usb.h"
-
-//--------------------------------------------------------------------+
-// INCLUDE
-//--------------------------------------------------------------------+
-#include "osal/osal.h"
-
-#include "host/hcd.h"
-#include "host/usbh.h"
-
-#define ROOT_PORT 0
-
-//--------------------------------------------------------------------+
-// Low level rp2040 controller functions
-//--------------------------------------------------------------------+
-
-#ifndef PICO_USB_HOST_INTERRUPT_ENDPOINTS
-#define PICO_USB_HOST_INTERRUPT_ENDPOINTS (USB_MAX_ENDPOINTS - 1)
-#endif
-static_assert(PICO_USB_HOST_INTERRUPT_ENDPOINTS <= USB_MAX_ENDPOINTS, "");
-
-// Host mode uses one shared endpoint register for non-interrupt endpoint
-static struct hw_endpoint ep_pool[1 + PICO_USB_HOST_INTERRUPT_ENDPOINTS];
-#define epx (ep_pool[0])
-
-#define usb_hw_set hw_set_alias(usb_hw)
-#define usb_hw_clear hw_clear_alias(usb_hw)
-
-// Flags we set by default in sie_ctrl (we add other bits on top)
-enum {
- SIE_CTRL_BASE = USB_SIE_CTRL_SOF_EN_BITS | USB_SIE_CTRL_KEEP_ALIVE_EN_BITS |
- USB_SIE_CTRL_PULLDOWN_EN_BITS | USB_SIE_CTRL_EP0_INT_1BUF_BITS
-};
-
-static struct hw_endpoint *get_dev_ep(uint8_t dev_addr, uint8_t ep_addr)
-{
- uint8_t num = tu_edpt_number(ep_addr);
- if ( num == 0 ) return &epx;
-
- for ( uint32_t i = 1; i < TU_ARRAY_SIZE(ep_pool); i++ )
- {
- struct hw_endpoint *ep = &ep_pool[i];
- if ( ep->configured && (ep->dev_addr == dev_addr) && (ep->ep_addr == ep_addr) ) return ep;
- }
-
- return NULL;
-}
-
-static inline uint8_t dev_speed(void)
-{
- return (usb_hw->sie_status & USB_SIE_STATUS_SPEED_BITS) >> USB_SIE_STATUS_SPEED_LSB;
-}
-
-static bool need_pre(uint8_t dev_addr)
-{
- // If this device is different to the speed of the root device
- // (i.e. is a low speed device on a full speed hub) then need pre
- return hcd_port_speed_get(0) != tuh_speed_get(dev_addr);
-}
-
-static void hw_xfer_complete(struct hw_endpoint *ep, xfer_result_t xfer_result)
-{
- // Mark transfer as done before we tell the tinyusb stack
- uint8_t dev_addr = ep->dev_addr;
- uint8_t ep_addr = ep->ep_addr;
- uint xferred_len = ep->xferred_len;
- hw_endpoint_reset_transfer(ep);
- hcd_event_xfer_complete(dev_addr, ep_addr, xferred_len, xfer_result, true);
-}
-
-static void _handle_buff_status_bit(uint bit, struct hw_endpoint *ep)
-{
- usb_hw_clear->buf_status = bit;
- bool done = hw_endpoint_xfer_continue(ep);
- if (done)
- {
- hw_xfer_complete(ep, XFER_RESULT_SUCCESS);
- }
-}
-
-static void hw_handle_buff_status(void)
-{
- uint32_t remaining_buffers = usb_hw->buf_status;
- pico_trace("buf_status 0x%08x\n", remaining_buffers);
-
- // Check EPX first
- uint bit = 0b1;
- if (remaining_buffers & bit)
- {
- remaining_buffers &= ~bit;
- struct hw_endpoint *ep = &epx;
-
- uint32_t ep_ctrl = *ep->endpoint_control;
- if (ep_ctrl & EP_CTRL_DOUBLE_BUFFERED_BITS)
- {
- TU_LOG(3, "Double Buffered: ");
- }else
- {
- TU_LOG(3, "Single Buffered: ");
- }
- TU_LOG_HEX(3, ep_ctrl);
-
- _handle_buff_status_bit(bit, ep);
- }
-
- // Check interrupt endpoints
- for (uint i = 1; i <= USB_HOST_INTERRUPT_ENDPOINTS && remaining_buffers; i++)
- {
- // EPX is bit 0
- // IEP1 is bit 2
- // IEP2 is bit 4
- // IEP3 is bit 6
- // etc
- bit = 1 << (i*2);
-
- if (remaining_buffers & bit)
- {
- remaining_buffers &= ~bit;
- _handle_buff_status_bit(bit, &ep_pool[i]);
- }
- }
-
- if (remaining_buffers)
- {
- panic("Unhandled buffer %d\n", remaining_buffers);
- }
-}
-
-static void hw_trans_complete(void)
-{
- struct hw_endpoint *ep = &epx;
- assert(ep->active);
-
- if (usb_hw->sie_ctrl & USB_SIE_CTRL_SEND_SETUP_BITS)
- {
- pico_trace("Sent setup packet\n");
- hw_xfer_complete(ep, XFER_RESULT_SUCCESS);
- }
- else
- {
- // Don't care. Will handle this in buff status
- return;
- }
-}
-
-static void hcd_rp2040_irq(void)
-{
- uint32_t status = usb_hw->ints;
- uint32_t handled = 0;
-
- if (status & USB_INTS_HOST_CONN_DIS_BITS)
- {
- handled |= USB_INTS_HOST_CONN_DIS_BITS;
-
- if (dev_speed())
- {
- hcd_event_device_attach(ROOT_PORT, true);
- }
- else
- {
- hcd_event_device_remove(ROOT_PORT, true);
- }
-
- // Clear speed change interrupt
- usb_hw_clear->sie_status = USB_SIE_STATUS_SPEED_BITS;
- }
-
- if (status & USB_INTS_BUFF_STATUS_BITS)
- {
- handled |= USB_INTS_BUFF_STATUS_BITS;
- TU_LOG(2, "Buffer complete\n");
- // print_bufctrl32(*epx.buffer_control);
- hw_handle_buff_status();
- }
-
- if (status & USB_INTS_TRANS_COMPLETE_BITS)
- {
- handled |= USB_INTS_TRANS_COMPLETE_BITS;
- usb_hw_clear->sie_status = USB_SIE_STATUS_TRANS_COMPLETE_BITS;
- TU_LOG(2, "Transfer complete\n");
- hw_trans_complete();
- }
-
- if (status & USB_INTS_STALL_BITS)
- {
- // We have rx'd a stall from the device
- pico_trace("Stall REC\n");
- handled |= USB_INTS_STALL_BITS;
- usb_hw_clear->sie_status = USB_SIE_STATUS_STALL_REC_BITS;
- hw_xfer_complete(&epx, XFER_RESULT_STALLED);
- }
-
- if (status & USB_INTS_ERROR_RX_TIMEOUT_BITS)
- {
- handled |= USB_INTS_ERROR_RX_TIMEOUT_BITS;
- usb_hw_clear->sie_status = USB_SIE_STATUS_RX_TIMEOUT_BITS;
- }
-
- if (status & USB_INTS_ERROR_DATA_SEQ_BITS)
- {
- usb_hw_clear->sie_status = USB_SIE_STATUS_DATA_SEQ_ERROR_BITS;
- print_bufctrl32(*epx.buffer_control);
- panic("Data Seq Error \n");
- }
-
- if (status ^ handled)
- {
- panic("Unhandled IRQ 0x%x\n", (uint) (status ^ handled));
- }
-}
-
-static struct hw_endpoint *_next_free_interrupt_ep(void)
-{
- struct hw_endpoint *ep = NULL;
- for (uint i = 1; i < TU_ARRAY_SIZE(ep_pool); i++)
- {
- ep = &ep_pool[i];
- if (!ep->configured)
- {
- // Will be configured by _hw_endpoint_init / _hw_endpoint_allocate
- ep->interrupt_num = i - 1;
- return ep;
- }
- }
- return ep;
-}
-
-static struct hw_endpoint *_hw_endpoint_allocate(uint8_t transfer_type)
-{
- struct hw_endpoint *ep = NULL;
-
- if (transfer_type == TUSB_XFER_INTERRUPT)
- {
- ep = _next_free_interrupt_ep();
- pico_info("Allocate interrupt ep %d\n", ep->interrupt_num);
- assert(ep);
- ep->buffer_control = &usbh_dpram->int_ep_buffer_ctrl[ep->interrupt_num].ctrl;
- ep->endpoint_control = &usbh_dpram->int_ep_ctrl[ep->interrupt_num].ctrl;
- // 0 for epx (double buffered): TODO increase to 1024 for ISO
- // 2x64 for intep0
- // 3x64 for intep1
- // etc
- ep->hw_data_buf = &usbh_dpram->epx_data[64 * (ep->interrupt_num + 2)];
- }
- else
- {
- ep = &epx;
- ep->buffer_control = &usbh_dpram->epx_buf_ctrl;
- ep->endpoint_control = &usbh_dpram->epx_ctrl;
- ep->hw_data_buf = &usbh_dpram->epx_data[0];
- }
-
- return ep;
-}
-
-static void _hw_endpoint_init(struct hw_endpoint *ep, uint8_t dev_addr, uint8_t ep_addr, uint wMaxPacketSize, uint8_t transfer_type, uint8_t bmInterval)
-{
- // Already has data buffer, endpoint control, and buffer control allocated at this point
- assert(ep->endpoint_control);
- assert(ep->buffer_control);
- assert(ep->hw_data_buf);
-
- uint8_t const num = tu_edpt_number(ep_addr);
- tusb_dir_t const dir = tu_edpt_dir(ep_addr);
-
- ep->ep_addr = ep_addr;
- ep->dev_addr = dev_addr;
-
- // For host, IN to host == RX, anything else rx == false
- ep->rx = (dir == TUSB_DIR_IN);
-
- // Response to a setup packet on EP0 starts with pid of 1
- ep->next_pid = (num == 0 ? 1u : 0u);
- ep->wMaxPacketSize = wMaxPacketSize;
- ep->transfer_type = transfer_type;
-
- pico_trace("hw_endpoint_init dev %d ep %d %s xfer %d\n", ep->dev_addr, tu_edpt_number(ep->ep_addr), ep_dir_string[tu_edpt_dir(ep->ep_addr)], ep->transfer_type);
- pico_trace("dev %d ep %d %s setup buffer @ 0x%p\n", ep->dev_addr, tu_edpt_number(ep->ep_addr), ep_dir_string[tu_edpt_dir(ep->ep_addr)], ep->hw_data_buf);
- uint dpram_offset = hw_data_offset(ep->hw_data_buf);
- // Bits 0-5 should be 0
- assert(!(dpram_offset & 0b111111));
-
- // Fill in endpoint control register with buffer offset
- uint32_t ep_reg = EP_CTRL_ENABLE_BITS
- | EP_CTRL_INTERRUPT_PER_BUFFER
- | (ep->transfer_type << EP_CTRL_BUFFER_TYPE_LSB)
- | dpram_offset;
- ep_reg |= bmInterval ? (bmInterval - 1) << EP_CTRL_HOST_INTERRUPT_INTERVAL_LSB : 0;
- *ep->endpoint_control = ep_reg;
- pico_trace("endpoint control (0x%p) <- 0x%x\n", ep->endpoint_control, ep_reg);
- ep->configured = true;
-
- if (bmInterval)
- {
- // This is an interrupt endpoint
- // so need to set up interrupt endpoint address control register with:
- // device address
- // endpoint number / direction
- // preamble
- uint32_t reg = dev_addr | (num << USB_ADDR_ENDP1_ENDPOINT_LSB);
- // Assert the interrupt endpoint is IN_TO_HOST
- // TODO Interrupt can also be OUT
- assert(dir == TUSB_DIR_IN);
-
- if (need_pre(dev_addr))
- {
- reg |= USB_ADDR_ENDP1_INTEP_PREAMBLE_BITS;
- }
- usb_hw->int_ep_addr_ctrl[ep->interrupt_num] = reg;
-
- // Finally, enable interrupt that endpoint
- usb_hw_set->int_ep_ctrl = 1 << (ep->interrupt_num + 1);
-
- // If it's an interrupt endpoint we need to set up the buffer control
- // register
- }
-}
-
-//--------------------------------------------------------------------+
-// HCD API
-//--------------------------------------------------------------------+
-bool hcd_init(uint8_t rhport)
-{
- pico_trace("hcd_init %d\n", rhport);
- assert(rhport == 0);
-
- // Reset any previous state
- rp2040_usb_init();
-
- // Force VBUS detect to always present, for now we assume vbus is always provided (without using VBUS En)
- usb_hw->pwr = USB_USB_PWR_VBUS_DETECT_BITS | USB_USB_PWR_VBUS_DETECT_OVERRIDE_EN_BITS;
-
- irq_set_exclusive_handler(USBCTRL_IRQ, hcd_rp2040_irq);
-
- // clear epx and interrupt eps
- memset(&ep_pool, 0, sizeof(ep_pool));
-
- // Enable in host mode with SOF / Keep alive on
- usb_hw->main_ctrl = USB_MAIN_CTRL_CONTROLLER_EN_BITS | USB_MAIN_CTRL_HOST_NDEVICE_BITS;
- usb_hw->sie_ctrl = SIE_CTRL_BASE;
- usb_hw->inte = USB_INTE_BUFF_STATUS_BITS |
- USB_INTE_HOST_CONN_DIS_BITS |
- USB_INTE_HOST_RESUME_BITS |
- USB_INTE_STALL_BITS |
- USB_INTE_TRANS_COMPLETE_BITS |
- USB_INTE_ERROR_RX_TIMEOUT_BITS |
- USB_INTE_ERROR_DATA_SEQ_BITS ;
-
- return true;
-}
-
-void hcd_port_reset(uint8_t rhport)
-{
- pico_trace("hcd_port_reset\n");
- assert(rhport == 0);
- // TODO: Nothing to do here yet. Perhaps need to reset some state?
-}
-
-bool hcd_port_connect_status(uint8_t rhport)
-{
- pico_trace("hcd_port_connect_status\n");
- assert(rhport == 0);
- return usb_hw->sie_status & USB_SIE_STATUS_SPEED_BITS;
-}
-
-tusb_speed_t hcd_port_speed_get(uint8_t rhport)
-{
- assert(rhport == 0);
- // TODO: Should enumval this register
- switch (dev_speed())
- {
- case 1:
- return TUSB_SPEED_LOW;
- case 2:
- return TUSB_SPEED_FULL;
- default:
- panic("Invalid speed\n");
- return TUSB_SPEED_INVALID;
- }
-}
-
-// Close all opened endpoint belong to this device
-void hcd_device_close(uint8_t rhport, uint8_t dev_addr)
-{
- (void) rhport;
- (void) dev_addr;
-
- pico_trace("hcd_device_close %d\n", dev_addr);
-}
-
-uint32_t hcd_frame_number(uint8_t rhport)
-{
- (void) rhport;
- return usb_hw->sof_rd;
-}
-
-void hcd_int_enable(uint8_t rhport)
-{
- assert(rhport == 0);
- irq_set_enabled(USBCTRL_IRQ, true);
-}
-
-void hcd_int_disable(uint8_t rhport)
-{
- // todo we should check this is disabling from the correct core; note currently this is never called
- assert(rhport == 0);
- irq_set_enabled(USBCTRL_IRQ, false);
-}
-
-//--------------------------------------------------------------------+
-// Endpoint API
-//--------------------------------------------------------------------+
-
-bool hcd_edpt_open(uint8_t rhport, uint8_t dev_addr, tusb_desc_endpoint_t const * ep_desc)
-{
- (void) rhport;
-
- pico_trace("hcd_edpt_open dev_addr %d, ep_addr %d\n", dev_addr, ep_desc->bEndpointAddress);
-
- // Allocated differently based on if it's an interrupt endpoint or not
- struct hw_endpoint *ep = _hw_endpoint_allocate(ep_desc->bmAttributes.xfer);
-
- _hw_endpoint_init(ep,
- dev_addr,
- ep_desc->bEndpointAddress,
- ep_desc->wMaxPacketSize.size,
- ep_desc->bmAttributes.xfer,
- ep_desc->bInterval);
-
- return true;
-}
-
-bool hcd_edpt_xfer(uint8_t rhport, uint8_t dev_addr, uint8_t ep_addr, uint8_t * buffer, uint16_t buflen)
-{
- (void) rhport;
-
- pico_trace("hcd_edpt_xfer dev_addr %d, ep_addr 0x%x, len %d\n", dev_addr, ep_addr, buflen);
-
- uint8_t const ep_num = tu_edpt_number(ep_addr);
- tusb_dir_t const ep_dir = tu_edpt_dir(ep_addr);
-
- // Get appropriate ep. Either EPX or interrupt endpoint
- struct hw_endpoint *ep = get_dev_ep(dev_addr, ep_addr);
- assert(ep);
-
- // Control endpoint can change direction 0x00 <-> 0x80
- if ( ep_addr != ep->ep_addr )
- {
- assert(ep_num == 0);
-
- // Direction has flipped on endpoint control so re init it but with same properties
- _hw_endpoint_init(ep, dev_addr, ep_addr, ep->wMaxPacketSize, ep->transfer_type, 0);
- }
-
- // If a normal transfer (non-interrupt) then initiate using
- // sie ctrl registers. Otherwise interrupt ep registers should
- // already be configured
- if (ep == &epx) {
- hw_endpoint_xfer_start(ep, buffer, buflen);
-
- // That has set up buffer control, endpoint control etc
- // for host we have to initiate the transfer
- usb_hw->dev_addr_ctrl = dev_addr | (ep_num << USB_ADDR_ENDP_ENDPOINT_LSB);
-
- uint32_t flags = USB_SIE_CTRL_START_TRANS_BITS | SIE_CTRL_BASE |
- (ep_dir ? USB_SIE_CTRL_RECEIVE_DATA_BITS : USB_SIE_CTRL_SEND_DATA_BITS);
- // Set pre if we are a low speed device on full speed hub
- flags |= need_pre(dev_addr) ? USB_SIE_CTRL_PREAMBLE_EN_BITS : 0;
-
- usb_hw->sie_ctrl = flags;
- }else
- {
- hw_endpoint_xfer_start(ep, buffer, buflen);
- }
-
- return true;
-}
-
-bool hcd_setup_send(uint8_t rhport, uint8_t dev_addr, uint8_t const setup_packet[8])
-{
- (void) rhport;
-
- // Copy data into setup packet buffer
- memcpy((void*)&usbh_dpram->setup_packet[0], setup_packet, 8);
-
- // Configure EP0 struct with setup info for the trans complete
- struct hw_endpoint *ep = _hw_endpoint_allocate(0);
-
- // EP0 out
- _hw_endpoint_init(ep, dev_addr, 0x00, ep->wMaxPacketSize, 0, 0);
- assert(ep->configured);
-
- ep->remaining_len = 8;
- ep->active = true;
-
- // Set device address
- usb_hw->dev_addr_ctrl = dev_addr;
-
- // Set pre if we are a low speed device on full speed hub
- uint32_t const flags = SIE_CTRL_BASE | USB_SIE_CTRL_SEND_SETUP_BITS | USB_SIE_CTRL_START_TRANS_BITS |
- (need_pre(dev_addr) ? USB_SIE_CTRL_PREAMBLE_EN_BITS : 0);
-
- usb_hw->sie_ctrl = flags;
-
- return true;
-}
-
-
-//bool hcd_edpt_busy(uint8_t dev_addr, uint8_t ep_addr)
-//{
-// // EPX is shared, so multiple device addresses and endpoint addresses share that
-// // so if any transfer is active on epx, we are busy. Interrupt endpoints have their own
-// // EPX so ep->active will only be busy if there is a pending transfer on that interrupt endpoint
-// // on that device
-// pico_trace("hcd_edpt_busy dev addr %d ep_addr 0x%x\n", dev_addr, ep_addr);
-// struct hw_endpoint *ep = get_dev_ep(dev_addr, ep_addr);
-// assert(ep);
-// bool busy = ep->active;
-// pico_trace("busy == %d\n", busy);
-// return busy;
-//}
-
-bool hcd_edpt_clear_stall(uint8_t dev_addr, uint8_t ep_addr)
-{
- (void) dev_addr;
- (void) ep_addr;
-
- panic("hcd_clear_stall");
- return true;
-}
-
-#endif
diff --git a/tinyusb/src/portable/raspberrypi/rp2040/rp2040_usb.c b/tinyusb/src/portable/raspberrypi/rp2040/rp2040_usb.c
deleted file mode 100755
index 43554d28..00000000
--- a/tinyusb/src/portable/raspberrypi/rp2040/rp2040_usb.c
+++ /dev/null
@@ -1,326 +0,0 @@
-/*
- * The MIT License (MIT)
- *
- * Copyright (c) 2020 Raspberry Pi (Trading) Ltd.
- * Copyright (c) 2021 Ha Thach (tinyusb.org) for Double Buffered
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- *
- * This file is part of the TinyUSB stack.
- */
-
-#include "tusb_option.h"
-
-#if CFG_TUSB_MCU == OPT_MCU_RP2040
-
-#include <stdlib.h>
-#include "rp2040_usb.h"
-
-// Direction strings for debug
-const char *ep_dir_string[] = {
- "out",
- "in",
-};
-
-static inline void _hw_endpoint_lock_update(struct hw_endpoint *ep, int delta) {
- // todo add critsec as necessary to prevent issues between worker and IRQ...
- // note that this is perhaps as simple as disabling IRQs because it would make
- // sense to have worker and IRQ on same core, however I think using critsec is about equivalent.
-}
-
-static void _hw_endpoint_xfer_sync(struct hw_endpoint *ep);
-static void _hw_endpoint_start_next_buffer(struct hw_endpoint *ep);
-
-//--------------------------------------------------------------------+
-//
-//--------------------------------------------------------------------+
-
-void rp2040_usb_init(void)
-{
- // Reset usb controller
- reset_block(RESETS_RESET_USBCTRL_BITS);
- unreset_block_wait(RESETS_RESET_USBCTRL_BITS);
-
- // Clear any previous state just in case
- memset(usb_hw, 0, sizeof(*usb_hw));
- memset(usb_dpram, 0, sizeof(*usb_dpram));
-
- // Mux the controller to the onboard usb phy
- usb_hw->muxing = USB_USB_MUXING_TO_PHY_BITS | USB_USB_MUXING_SOFTCON_BITS;
-}
-
-void hw_endpoint_reset_transfer(struct hw_endpoint *ep)
-{
- ep->stalled = false;
- ep->active = false;
- ep->remaining_len = 0;
- ep->xferred_len = 0;
- ep->user_buf = 0;
-}
-
-void _hw_endpoint_buffer_control_update32(struct hw_endpoint *ep, uint32_t and_mask, uint32_t or_mask) {
- uint32_t value = 0;
- if (and_mask) {
- value = *ep->buffer_control & and_mask;
- }
- if (or_mask) {
- value |= or_mask;
- if (or_mask & USB_BUF_CTRL_AVAIL) {
- if (*ep->buffer_control & USB_BUF_CTRL_AVAIL) {
- panic("ep %d %s was already available", tu_edpt_number(ep->ep_addr), ep_dir_string[tu_edpt_dir(ep->ep_addr)]);
- }
- *ep->buffer_control = value & ~USB_BUF_CTRL_AVAIL;
- // 12 cycle delay.. (should be good for 48*12Mhz = 576Mhz)
- // Don't need delay in host mode as host is in charge
-#if !TUSB_OPT_HOST_ENABLED
- __asm volatile (
- "b 1f\n"
- "1: b 1f\n"
- "1: b 1f\n"
- "1: b 1f\n"
- "1: b 1f\n"
- "1: b 1f\n"
- "1:\n"
- : : : "memory");
-#endif
- }
- }
- *ep->buffer_control = value;
-}
-
-// prepare buffer, return buffer control
-static uint32_t prepare_ep_buffer(struct hw_endpoint *ep, uint8_t buf_id)
-{
- uint16_t const buflen = tu_min16(ep->remaining_len, ep->wMaxPacketSize);
- ep->remaining_len -= buflen;
-
- uint32_t buf_ctrl = buflen | USB_BUF_CTRL_AVAIL;
-
- // PID
- buf_ctrl |= ep->next_pid ? USB_BUF_CTRL_DATA1_PID : USB_BUF_CTRL_DATA0_PID;
- ep->next_pid ^= 1u;
-
- if ( !ep->rx )
- {
- // Copy data from user buffer to hw buffer
- memcpy(ep->hw_data_buf + buf_id*64, ep->user_buf, buflen);
- ep->user_buf += buflen;
-
- // Mark as full
- buf_ctrl |= USB_BUF_CTRL_FULL;
- }
-
- // Is this the last buffer? Only really matters for host mode. Will trigger
- // the trans complete irq but also stop it polling. We only really care about
- // trans complete for setup packets being sent
- if (ep->remaining_len == 0)
- {
- buf_ctrl |= USB_BUF_CTRL_LAST;
- }
-
- if (buf_id) buf_ctrl = buf_ctrl << 16;
-
- return buf_ctrl;
-}
-
-// Prepare buffer control register value
-static void _hw_endpoint_start_next_buffer(struct hw_endpoint *ep)
-{
- uint32_t ep_ctrl = *ep->endpoint_control;
-
- // always compute and start with buffer 0
- uint32_t buf_ctrl = prepare_ep_buffer(ep, 0) | USB_BUF_CTRL_SEL;
-
- // For now: skip double buffered for Device mode, OUT endpoint since
- // host could send < 64 bytes and cause short packet on buffer0
- // NOTE this could happen to Host mode IN endpoint
- bool const force_single = !(usb_hw->main_ctrl & USB_MAIN_CTRL_HOST_NDEVICE_BITS) && !tu_edpt_dir(ep->ep_addr);
-
- if(ep->remaining_len && !force_single)
- {
- // Use buffer 1 (double buffered) if there is still data
- // TODO: Isochronous for buffer1 bit-field is different than CBI (control bulk, interrupt)
-
- buf_ctrl |= prepare_ep_buffer(ep, 1);
-
- // Set endpoint control double buffered bit if needed
- ep_ctrl &= ~EP_CTRL_INTERRUPT_PER_BUFFER;
- ep_ctrl |= EP_CTRL_DOUBLE_BUFFERED_BITS | EP_CTRL_INTERRUPT_PER_DOUBLE_BUFFER;
- }else
- {
- // Single buffered since 1 is enough
- ep_ctrl &= ~(EP_CTRL_DOUBLE_BUFFERED_BITS | EP_CTRL_INTERRUPT_PER_DOUBLE_BUFFER);
- ep_ctrl |= EP_CTRL_INTERRUPT_PER_BUFFER;
- }
-
- *ep->endpoint_control = ep_ctrl;
-
- TU_LOG(3, "Prepare Buffer Control:\r\n");
- print_bufctrl32(buf_ctrl);
-
- // Finally, write to buffer_control which will trigger the transfer
- // the next time the controller polls this dpram address
- _hw_endpoint_buffer_control_set_value32(ep, buf_ctrl);
-}
-
-void hw_endpoint_xfer_start(struct hw_endpoint *ep, uint8_t *buffer, uint16_t total_len)
-{
- _hw_endpoint_lock_update(ep, 1);
-
- if ( ep->active )
- {
- // TODO: Is this acceptable for interrupt packets?
- TU_LOG(1, "WARN: starting new transfer on already active ep %d %s\n", tu_edpt_number(ep->ep_addr),
- ep_dir_string[tu_edpt_dir(ep->ep_addr)]);
-
- hw_endpoint_reset_transfer(ep);
- }
-
- // Fill in info now that we're kicking off the hw
- ep->remaining_len = total_len;
- ep->xferred_len = 0;
- ep->active = true;
- ep->user_buf = buffer;
-
- _hw_endpoint_start_next_buffer(ep);
- _hw_endpoint_lock_update(ep, -1);
-}
-
-// sync endpoint buffer and return transferred bytes
-static uint16_t sync_ep_buffer(struct hw_endpoint *ep, uint8_t buf_id)
-{
- uint32_t buf_ctrl = _hw_endpoint_buffer_control_get_value32(ep);
- if (buf_id) buf_ctrl = buf_ctrl >> 16;
-
- uint16_t xferred_bytes = buf_ctrl & USB_BUF_CTRL_LEN_MASK;
-
- if ( !ep->rx )
- {
- // We are continuing a transfer here. If we are TX, we have successfully
- // sent some data can increase the length we have sent
- assert(!(buf_ctrl & USB_BUF_CTRL_FULL));
-
- ep->xferred_len += xferred_bytes;
- }else
- {
- // If we have received some data, so can increase the length
- // we have received AFTER we have copied it to the user buffer at the appropriate offset
- assert(buf_ctrl & USB_BUF_CTRL_FULL);
-
- memcpy(ep->user_buf, ep->hw_data_buf + buf_id*64, xferred_bytes);
- ep->xferred_len += xferred_bytes;
- ep->user_buf += xferred_bytes;
- }
-
- // Short packet
- if (xferred_bytes < ep->wMaxPacketSize)
- {
- pico_trace("Short rx transfer on buffer %d with %u bytes\n", buf_id, xferred_bytes);
- // Reduce total length as this is last packet
- ep->remaining_len = 0;
- }
-
- return xferred_bytes;
-}
-
-static void _hw_endpoint_xfer_sync (struct hw_endpoint *ep)
-{
- // Update hw endpoint struct with info from hardware
- // after a buff status interrupt
-
- uint32_t buf_ctrl = _hw_endpoint_buffer_control_get_value32(ep);
- TU_LOG(3, "_hw_endpoint_xfer_sync:\r\n");
- print_bufctrl32(buf_ctrl);
-
- // always sync buffer 0
- uint16_t buf0_bytes = sync_ep_buffer(ep, 0);
-
- // sync buffer 1 if double buffered
- if ( (*ep->endpoint_control) & EP_CTRL_DOUBLE_BUFFERED_BITS )
- {
- if (buf0_bytes == ep->wMaxPacketSize)
- {
- // sync buffer 1 if not short packet
- sync_ep_buffer(ep, 1);
- }else
- {
- // short packet on buffer 0
- // TODO couldn't figure out how to handle this case which happen with net_lwip_webserver example
- // At this time (currently trigger per 2 buffer), the buffer1 is probably filled with data from
- // the next transfer (not current one). For now we disable double buffered for device OUT
- // NOTE this could happen to Host IN
-#if 0
- uint8_t const ep_num = tu_edpt_number(ep->ep_addr);
- uint8_t const dir = (uint8_t) tu_edpt_dir(ep->ep_addr);
- uint8_t const ep_id = 2*ep_num + (dir ? 0 : 1);
-
- // abort queued transfer on buffer 1
- usb_hw->abort |= TU_BIT(ep_id);
-
- while ( !(usb_hw->abort_done & TU_BIT(ep_id)) ) {}
-
- uint32_t ep_ctrl = *ep->endpoint_control;
- ep_ctrl &= ~(EP_CTRL_DOUBLE_BUFFERED_BITS | EP_CTRL_INTERRUPT_PER_DOUBLE_BUFFER);
- ep_ctrl |= EP_CTRL_INTERRUPT_PER_BUFFER;
-
- _hw_endpoint_buffer_control_set_value32(ep, 0);
-
- usb_hw->abort &= ~TU_BIT(ep_id);
-
- TU_LOG(3, "----SHORT PACKET buffer0 on EP %02X:\r\n", ep->ep_addr);
- print_bufctrl32(buf_ctrl);
-#endif
- }
- }
-}
-
-// Returns true if transfer is complete
-bool hw_endpoint_xfer_continue(struct hw_endpoint *ep)
-{
- _hw_endpoint_lock_update(ep, 1);
- // Part way through a transfer
- if (!ep->active)
- {
- panic("Can't continue xfer on inactive ep %d %s", tu_edpt_number(ep->ep_addr), ep_dir_string);
- }
-
- // Update EP struct from hardware state
- _hw_endpoint_xfer_sync(ep);
-
- // Now we have synced our state with the hardware. Is there more data to transfer?
- // If we are done then notify tinyusb
- if (ep->remaining_len == 0)
- {
- pico_trace("Completed transfer of %d bytes on ep %d %s\n",
- ep->xferred_len, tu_edpt_number(ep->ep_addr), ep_dir_string[tu_edpt_dir(ep->ep_addr)]);
- // Notify caller we are done so it can notify the tinyusb stack
- _hw_endpoint_lock_update(ep, -1);
- return true;
- }
- else
- {
- _hw_endpoint_start_next_buffer(ep);
- }
-
- _hw_endpoint_lock_update(ep, -1);
- // More work to do
- return false;
-}
-
-#endif
diff --git a/tinyusb/src/portable/raspberrypi/rp2040/rp2040_usb.h b/tinyusb/src/portable/raspberrypi/rp2040/rp2040_usb.h
deleted file mode 100755
index 5570a731..00000000
--- a/tinyusb/src/portable/raspberrypi/rp2040/rp2040_usb.h
+++ /dev/null
@@ -1,147 +0,0 @@
-#ifndef RP2040_COMMON_H_
-#define RP2040_COMMON_H_
-
-#if defined(RP2040_USB_HOST_MODE) && defined(RP2040_USB_DEVICE_MODE)
-#error TinyUSB device and host mode not supported at the same time
-#endif
-
-#include "common/tusb_common.h"
-
-#include "pico.h"
-#include "hardware/structs/usb.h"
-#include "hardware/irq.h"
-#include "hardware/resets.h"
-
-#if defined(PICO_RP2040_USB_DEVICE_ENUMERATION_FIX) && !defined(TUD_OPT_RP2040_USB_DEVICE_ENUMERATION_FIX)
-#define TUD_OPT_RP2040_USB_DEVICE_ENUMERATION_FIX PICO_RP2040_USB_DEVICE_ENUMERATION_FIX
-#endif
-
-
-#define pico_info(...) TU_LOG(2, __VA_ARGS__)
-#define pico_trace(...) TU_LOG(3, __VA_ARGS__)
-
-// Hardware information per endpoint
-struct hw_endpoint
-{
- // Is this a valid struct
- bool configured;
-
- // Transfer direction (i.e. IN is rx for host but tx for device)
- // allows us to common up transfer functions
- bool rx;
-
- uint8_t ep_addr;
- uint8_t next_pid;
-
- // Endpoint control register
- io_rw_32 *endpoint_control;
-
- // Buffer control register
- io_rw_32 *buffer_control;
-
- // Buffer pointer in usb dpram
- uint8_t *hw_data_buf;
-
- // Have we been stalled TODO remove later
- bool stalled;
-
- // Current transfer information
- bool active;
- uint16_t remaining_len;
- uint16_t xferred_len;
-
- // User buffer in main memory
- uint8_t *user_buf;
-
- // Data needed from EP descriptor
- uint16_t wMaxPacketSize;
-
- // Interrupt, bulk, etc
- uint8_t transfer_type;
-
-#if TUSB_OPT_HOST_ENABLED
- // Only needed for host
- uint8_t dev_addr;
-
- // If interrupt endpoint
- uint8_t interrupt_num;
-#endif
-};
-
-void rp2040_usb_init(void);
-
-void hw_endpoint_xfer_start(struct hw_endpoint *ep, uint8_t *buffer, uint16_t total_len);
-bool hw_endpoint_xfer_continue(struct hw_endpoint *ep);
-void hw_endpoint_reset_transfer(struct hw_endpoint *ep);
-
-void _hw_endpoint_buffer_control_update32(struct hw_endpoint *ep, uint32_t and_mask, uint32_t or_mask);
-static inline uint32_t _hw_endpoint_buffer_control_get_value32(struct hw_endpoint *ep) {
- return *ep->buffer_control;
-}
-static inline void _hw_endpoint_buffer_control_set_value32(struct hw_endpoint *ep, uint32_t value) {
- return _hw_endpoint_buffer_control_update32(ep, 0, value);
-}
-static inline void _hw_endpoint_buffer_control_set_mask32(struct hw_endpoint *ep, uint32_t value) {
- return _hw_endpoint_buffer_control_update32(ep, ~value, value);
-}
-static inline void _hw_endpoint_buffer_control_clear_mask32(struct hw_endpoint *ep, uint32_t value) {
- return _hw_endpoint_buffer_control_update32(ep, ~value, 0);
-}
-
-static inline uintptr_t hw_data_offset(uint8_t *buf)
-{
- // Remove usb base from buffer pointer
- return (uintptr_t)buf ^ (uintptr_t)usb_dpram;
-}
-
-extern const char *ep_dir_string[];
-
-typedef union TU_ATTR_PACKED
-{
- uint16_t u16;
- struct TU_ATTR_PACKED
- {
- uint16_t xfer_len : 10;
- uint16_t available : 1;
- uint16_t stall : 1;
- uint16_t reset_bufsel : 1;
- uint16_t data_toggle : 1;
- uint16_t last_buf : 1;
- uint16_t full : 1;
- };
-} rp2040_buffer_control_t;
-
-TU_VERIFY_STATIC(sizeof(rp2040_buffer_control_t) == 2, "size is not correct");
-
-#if CFG_TUSB_DEBUG >= 3
-static inline void print_bufctrl16(uint32_t u16)
-{
- rp2040_buffer_control_t bufctrl = {
- .u16 = u16
- };
-
- TU_LOG(3, "len = %u, available = %u, full = %u, last = %u, stall = %u, reset = %u, toggle = %u\r\n",
- bufctrl.xfer_len, bufctrl.available, bufctrl.full, bufctrl.last_buf, bufctrl.stall, bufctrl.reset_bufsel, bufctrl.data_toggle);
-}
-
-static inline void print_bufctrl32(uint32_t u32)
-{
- uint16_t u16;
-
- u16 = u32 >> 16;
- TU_LOG(3, " Buffer Control 1 0x%x: ", u16);
- print_bufctrl16(u16);
-
- u16 = u32 & 0x0000ffff;
- TU_LOG(3, " Buffer Control 0 0x%x: ", u16);
- print_bufctrl16(u16);
-}
-
-#else
-
-#define print_bufctrl16(u16)
-#define print_bufctrl32(u32)
-
-#endif
-
-#endif
diff --git a/tinyusb/src/portable/renesas/usba/dcd_usba.c b/tinyusb/src/portable/renesas/usba/dcd_usba.c
deleted file mode 100755
index 095dcc13..00000000
--- a/tinyusb/src/portable/renesas/usba/dcd_usba.c
+++ /dev/null
@@ -1,891 +0,0 @@
-/*
- * The MIT License (MIT)
- *
- * Copyright (c) 2020 Koji Kitayama
- * Portions copyrighted (c) 2021 Roland Winistoerfer
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- *
- * This file is part of the TinyUSB stack.
- */
-
-#include "tusb_option.h"
-
-// Since TinyUSB doesn't use SOF for now, and this interrupt too often (1ms interval)
-// We disable SOF for now until needed later on
-#define USE_SOF 0
-
-#if TUSB_OPT_DEVICE_ENABLED && ( CFG_TUSB_MCU == OPT_MCU_RX63X || \
- CFG_TUSB_MCU == OPT_MCU_RX65X || \
- CFG_TUSB_MCU == OPT_MCU_RX72N )
-#include "device/dcd.h"
-#include "iodefine.h"
-
-//--------------------------------------------------------------------+
-// MACRO TYPEDEF CONSTANT ENUM DECLARATION
-//--------------------------------------------------------------------+
-#define SYSTEM_PRCR_PRC1 (1<<1)
-#define SYSTEM_PRCR_PRKEY (0xA5u<<8)
-
-#define USB_FIFOSEL_TX ((uint16_t)(1u<<5))
-#define USB_FIFOSEL_BIGEND ((uint16_t)(1u<<8))
-#define USB_FIFOSEL_MBW_8 ((uint16_t)(0u<<10))
-#define USB_FIFOSEL_MBW_16 ((uint16_t)(1u<<10))
-#define USB_IS0_CTSQ ((uint16_t)(7u))
-#define USB_IS0_DVSQ ((uint16_t)(7u<<4))
-#define USB_IS0_VALID ((uint16_t)(1u<<3))
-#define USB_IS0_BRDY ((uint16_t)(1u<<8))
-#define USB_IS0_NRDY ((uint16_t)(1u<<9))
-#define USB_IS0_BEMP ((uint16_t)(1u<<10))
-#define USB_IS0_CTRT ((uint16_t)(1u<<11))
-#define USB_IS0_DVST ((uint16_t)(1u<<12))
-#define USB_IS0_SOFR ((uint16_t)(1u<<13))
-#define USB_IS0_RESM ((uint16_t)(1u<<14))
-#define USB_IS0_VBINT ((uint16_t)(1u<<15))
-#define USB_IS1_SACK ((uint16_t)(1u<<4))
-#define USB_IS1_SIGN ((uint16_t)(1u<<5))
-#define USB_IS1_EOFERR ((uint16_t)(1u<<6))
-#define USB_IS1_ATTCH ((uint16_t)(1u<<11))
-#define USB_IS1_DTCH ((uint16_t)(1u<<12))
-#define USB_IS1_BCHG ((uint16_t)(1u<<14))
-#define USB_IS1_OVRCR ((uint16_t)(1u<<15))
-
-#define USB_IS0_CTSQ_MSK (7u)
-#define USB_IS0_CTSQ_SETUP (1u)
-#define USB_IS0_DVSQ_DEF (1u<<4)
-#define USB_IS0_DVSQ_ADDR (2u<<4)
-#define USB_IS0_DVSQ_SUSP0 (4u<<4)
-#define USB_IS0_DVSQ_SUSP1 (5u<<4)
-#define USB_IS0_DVSQ_SUSP2 (6u<<4)
-#define USB_IS0_DVSQ_SUSP3 (7u<<4)
-
-#define USB_PIPECTR_PID_NAK (0u)
-#define USB_PIPECTR_PID_BUF (1u)
-#define USB_PIPECTR_PID_STALL (2u)
-#define USB_PIPECTR_CCPL (1u<<2)
-#define USB_PIPECTR_SQMON (1u<<6)
-#define USB_PIPECTR_SQCLR (1u<<8)
-#define USB_PIPECTR_ACLRM (1u<<9)
-#define USB_PIPECTR_INBUFM (1u<<14)
-#define USB_PIPECTR_BSTS (1u<<15)
-
-#define USB_FIFOCTR_DTLN (0x1FF)
-#define USB_FIFOCTR_FRDY (1u<<13)
-#define USB_FIFOCTR_BCLR (1u<<14)
-#define USB_FIFOCTR_BVAL (1u<<15)
-
-#define USB_PIPECFG_SHTNAK (1u<<7)
-#define USB_PIPECFG_DBLB (1u<<9)
-#define USB_PIPECFG_BULK (1u<<14)
-#define USB_PIPECFG_ISO (3u<<14)
-#define USB_PIPECFG_INT (2u<<14)
-
-#define FIFO_REQ_CLR (1u)
-#define FIFO_COMPLETE (1u<<1)
-
-// Start of definition of packed structs (used by the CCRX toolchain)
-TU_ATTR_PACKED_BEGIN
-TU_ATTR_BIT_FIELD_ORDER_BEGIN
-
-typedef struct {
- union {
- struct {
- uint16_t : 8;
- uint16_t TRCLR: 1;
- uint16_t TRENB: 1;
- uint16_t : 0;
- };
- uint16_t TRE;
- };
- uint16_t TRN;
-} reg_pipetre_t;
-
-typedef union {
- struct {
- volatile uint16_t u8: 8;
- volatile uint16_t : 0;
- };
- volatile uint16_t u16;
-} hw_fifo_t;
-
-typedef struct TU_ATTR_PACKED
-{
- void *buf; /* the start address of a transfer data buffer */
- uint16_t length; /* the number of bytes in the buffer */
- uint16_t remaining; /* the number of bytes remaining in the buffer */
- struct {
- uint32_t ep : 8; /* an assigned endpoint address */
- uint32_t ff : 1; /* `buf` is TU_FUFO or POD */
- uint32_t : 0;
- };
-} pipe_state_t;
-
-TU_ATTR_PACKED_END // End of definition of packed structs (used by the CCRX toolchain)
-TU_ATTR_BIT_FIELD_ORDER_END
-
-typedef struct
-{
- pipe_state_t pipe[10];
- uint8_t ep[2][16]; /* a lookup table for a pipe index from an endpoint address */
-} dcd_data_t;
-
-//--------------------------------------------------------------------+
-// INTERNAL OBJECT & FUNCTION DECLARATION
-//--------------------------------------------------------------------+
-static dcd_data_t _dcd;
-
-static uint32_t disable_interrupt(void)
-{
- uint32_t pswi;
-#if defined(__CCRX__)
- pswi = get_psw() & 0x010000;
- clrpsw_i();
-#else
- pswi = __builtin_rx_mvfc(0) & 0x010000;
- __builtin_rx_clrpsw('I');
-#endif
- return pswi;
-}
-
-static void enable_interrupt(uint32_t pswi)
-{
-#if defined(__CCRX__)
- set_psw(get_psw() | pswi);
-#else
- __builtin_rx_mvtc(0, __builtin_rx_mvfc(0) | pswi);
-#endif
-}
-
-static unsigned find_pipe(unsigned xfer)
-{
- switch (xfer) {
- case TUSB_XFER_ISOCHRONOUS:
- for (int i = 1; i <= 2; ++i) {
- if (0 == _dcd.pipe[i].ep) return i;
- }
- break;
- case TUSB_XFER_BULK:
- for (int i = 3; i <= 5; ++i) {
- if (0 == _dcd.pipe[i].ep) return i;
- }
- for (int i = 1; i <= 1; ++i) {
- if (0 == _dcd.pipe[i].ep) return i;
- }
- break;
- case TUSB_XFER_INTERRUPT:
- for (int i = 6; i <= 9; ++i) {
- if (0 == _dcd.pipe[i].ep) return i;
- }
- break;
- default:
- /* No support for control transfer */
- break;
- }
- return 0;
-}
-
-static volatile uint16_t* get_pipectr(unsigned num)
-{
- volatile uint16_t *ctr = NULL;
- if (num) {
- ctr = (volatile uint16_t*)&USB0.PIPE1CTR.WORD;
- ctr += num - 1;
- } else {
- ctr = (volatile uint16_t*)&USB0.DCPCTR.WORD;
- }
- return ctr;
-}
-
-static volatile reg_pipetre_t* get_pipetre(unsigned num)
-{
- volatile reg_pipetre_t* tre = NULL;
- if ((1 <= num) && (num <= 5)) {
- tre = (volatile reg_pipetre_t*)&USB0.PIPE1TRE.WORD;
- tre += num - 1;
- }
- return tre;
-}
-
-static volatile uint16_t* ep_addr_to_pipectr(uint8_t rhport, unsigned ep_addr)
-{
- (void)rhport;
- volatile uint16_t *ctr = NULL;
- const unsigned epn = tu_edpt_number(ep_addr);
- if (epn) {
- const unsigned dir = tu_edpt_dir(ep_addr);
- const unsigned num = _dcd.ep[dir][epn];
- if (num) {
- ctr = (volatile uint16_t*)&USB0.PIPE1CTR.WORD;
- ctr += num - 1;
- }
- } else {
- ctr = (volatile uint16_t*)&USB0.DCPCTR.WORD;
- }
- return ctr;
-}
-
-static unsigned edpt0_max_packet_size(void)
-{
- return USB0.DCPMAXP.BIT.MXPS;
-}
-
-static unsigned edpt_max_packet_size(unsigned num)
-{
- USB0.PIPESEL.WORD = num;
- return USB0.PIPEMAXP.WORD;
-}
-
-static inline void pipe_wait_for_ready(unsigned num)
-{
- while (USB0.D0FIFOSEL.BIT.CURPIPE != num) ;
- while (!USB0.D0FIFOCTR.BIT.FRDY) ;
-}
-
-static void pipe_write_packet(void *buf, volatile void *fifo, unsigned len)
-{
- hw_fifo_t *reg = (hw_fifo_t*)fifo;
- uintptr_t addr = (uintptr_t)buf;
- while (len >= 2) {
- reg->u16 = *(const uint16_t *)addr;
- addr += 2;
- len -= 2;
- }
- if (len) {
- reg->u8 = *(const uint8_t *)addr;
- ++addr;
- }
-}
-
-static void pipe_read_packet(void *buf, volatile void *fifo, unsigned len)
-{
- uint8_t *p = (uint8_t*)buf;
- uint8_t *reg = (uint8_t*)fifo; /* byte access is always at base register address */
- while (len--) *p++ = *reg;
-}
-
-static void pipe_read_write_packet_ff(tu_fifo_t *f, volatile void *fifo, unsigned len, unsigned dir)
-{
- static const struct {
- void (*tu_fifo_get_info)(tu_fifo_t *f, tu_fifo_buffer_info_t *info);
- void (*tu_fifo_advance)(tu_fifo_t *f, uint16_t n);
- void (*pipe_read_write)(void *buf, volatile void *fifo, unsigned len);
- } ops[] = {
- /* OUT */ {tu_fifo_get_write_info,tu_fifo_advance_write_pointer,pipe_read_packet},
- /* IN */ {tu_fifo_get_read_info, tu_fifo_advance_read_pointer, pipe_write_packet},
- };
- tu_fifo_buffer_info_t info;
- ops[dir].tu_fifo_get_info(f, &info);
- unsigned total_len = len;
- len = TU_MIN(total_len, info.len_lin);
- ops[dir].pipe_read_write(info.ptr_lin, fifo, len);
- unsigned rem = total_len - len;
- if (rem) {
- len = TU_MIN(rem, info.len_wrap);
- ops[dir].pipe_read_write(info.ptr_wrap, fifo, len);
- rem -= len;
- }
- ops[dir].tu_fifo_advance(f, total_len - rem);
-}
-
-static bool pipe0_xfer_in(void)
-{
- pipe_state_t *pipe = &_dcd.pipe[0];
- const unsigned rem = pipe->remaining;
- if (!rem) {
- pipe->buf = NULL;
- return true;
- }
- const unsigned mps = edpt0_max_packet_size();
- const unsigned len = TU_MIN(mps, rem);
- void *buf = pipe->buf;
- if (len) {
- if (pipe->ff) {
- pipe_read_write_packet_ff((tu_fifo_t*)buf, (volatile void*)&USB0.CFIFO.WORD, len, TUSB_DIR_IN);
- } else {
- pipe_write_packet(buf, (volatile void*)&USB0.CFIFO.WORD, len);
- pipe->buf = (uint8_t*)buf + len;
- }
- }
- if (len < mps) USB0.CFIFOCTR.WORD = USB_FIFOCTR_BVAL;
- pipe->remaining = rem - len;
- return false;
-}
-
-static bool pipe0_xfer_out(void)
-{
- pipe_state_t *pipe = &_dcd.pipe[0];
- const unsigned rem = pipe->remaining;
-
- const unsigned mps = edpt0_max_packet_size();
- const unsigned vld = USB0.CFIFOCTR.BIT.DTLN;
- const unsigned len = TU_MIN(TU_MIN(rem, mps), vld);
- void *buf = pipe->buf;
- if (len) {
- if (pipe->ff) {
- pipe_read_write_packet_ff((tu_fifo_t*)buf, (volatile void*)&USB0.CFIFO.WORD, len, TUSB_DIR_OUT);
- } else {
- pipe_read_packet(buf, (volatile void*)&USB0.CFIFO.WORD, len);
- pipe->buf = (uint8_t*)buf + len;
- }
- }
- if (len < mps) USB0.CFIFOCTR.WORD = USB_FIFOCTR_BCLR;
- pipe->remaining = rem - len;
- if ((len < mps) || (rem == len)) {
- pipe->buf = NULL;
- return true;
- }
- return false;
-}
-
-static bool pipe_xfer_in(unsigned num)
-{
- pipe_state_t *pipe = &_dcd.pipe[num];
- const unsigned rem = pipe->remaining;
-
- if (!rem) {
- pipe->buf = NULL;
- return true;
- }
-
- USB0.D0FIFOSEL.WORD = num | USB_FIFOSEL_MBW_16 | (TU_BYTE_ORDER == TU_BIG_ENDIAN ? USB_FIFOSEL_BIGEND : 0);
- const unsigned mps = edpt_max_packet_size(num);
- pipe_wait_for_ready(num);
- const unsigned len = TU_MIN(rem, mps);
- void *buf = pipe->buf;
- if (len) {
- if (pipe->ff) {
- pipe_read_write_packet_ff((tu_fifo_t*)buf, (volatile void*)&USB0.D0FIFO.WORD, len, TUSB_DIR_IN);
- } else {
- pipe_write_packet(buf, (volatile void*)&USB0.D0FIFO.WORD, len);
- pipe->buf = (uint8_t*)buf + len;
- }
- }
- if (len < mps) USB0.D0FIFOCTR.WORD = USB_FIFOCTR_BVAL;
- USB0.D0FIFOSEL.WORD = 0;
- while (USB0.D0FIFOSEL.BIT.CURPIPE) ; /* if CURPIPE bits changes, check written value */
- pipe->remaining = rem - len;
- return false;
-}
-
-static bool pipe_xfer_out(unsigned num)
-{
- pipe_state_t *pipe = &_dcd.pipe[num];
- const unsigned rem = pipe->remaining;
-
- USB0.D0FIFOSEL.WORD = num | USB_FIFOSEL_MBW_8;
- const unsigned mps = edpt_max_packet_size(num);
- pipe_wait_for_ready(num);
- const unsigned vld = USB0.D0FIFOCTR.BIT.DTLN;
- const unsigned len = TU_MIN(TU_MIN(rem, mps), vld);
- void *buf = pipe->buf;
- if (len) {
- if (pipe->ff) {
- pipe_read_write_packet_ff((tu_fifo_t*)buf, (volatile void*)&USB0.D0FIFO.WORD, len, TUSB_DIR_OUT);
- } else {
- pipe_read_packet(buf, (volatile void*)&USB0.D0FIFO.WORD, len);
- pipe->buf = (uint8_t*)buf + len;
- }
- }
- if (len < mps) USB0.D0FIFOCTR.WORD = USB_FIFOCTR_BCLR;
- USB0.D0FIFOSEL.WORD = 0;
- while (USB0.D0FIFOSEL.BIT.CURPIPE) ; /* if CURPIPE bits changes, check written value */
- pipe->remaining = rem - len;
- if ((len < mps) || (rem == len)) {
- pipe->buf = NULL;
- return NULL != buf;
- }
- return false;
-}
-
-static void process_setup_packet(uint8_t rhport)
-{
- uint16_t setup_packet[4];
- if (0 == (USB0.INTSTS0.WORD & USB_IS0_VALID)) return;
- USB0.CFIFOCTR.WORD = USB_FIFOCTR_BCLR;
- setup_packet[0] = tu_le16toh(USB0.USBREQ.WORD);
- setup_packet[1] = USB0.USBVAL;
- setup_packet[2] = USB0.USBINDX;
- setup_packet[3] = USB0.USBLENG;
- USB0.INTSTS0.WORD = ~USB_IS0_VALID;
- dcd_event_setup_received(rhport, (const uint8_t*)&setup_packet[0], true);
-}
-
-static void process_status_completion(uint8_t rhport)
-{
- uint8_t ep_addr;
- /* Check the data stage direction */
- if (USB0.CFIFOSEL.WORD & USB_FIFOSEL_TX) {
- /* IN transfer. */
- ep_addr = tu_edpt_addr(0, TUSB_DIR_IN);
- } else {
- /* OUT transfer. */
- ep_addr = tu_edpt_addr(0, TUSB_DIR_OUT);
- }
- dcd_event_xfer_complete(rhport, ep_addr, 0, XFER_RESULT_SUCCESS, true);
-}
-
-static bool process_pipe0_xfer(int buffer_type, uint8_t ep_addr, void* buffer, uint16_t total_bytes)
-{
- /* configure fifo direction and access unit settings */
- if (ep_addr) { /* IN, 2 bytes */
- USB0.CFIFOSEL.WORD = USB_FIFOSEL_TX | USB_FIFOSEL_MBW_16 | (TU_BYTE_ORDER == TU_BIG_ENDIAN ? USB_FIFOSEL_BIGEND : 0);
- while (!(USB0.CFIFOSEL.WORD & USB_FIFOSEL_TX)) ;
- } else { /* OUT, a byte */
- USB0.CFIFOSEL.WORD = USB_FIFOSEL_MBW_8;
- while (USB0.CFIFOSEL.WORD & USB_FIFOSEL_TX) ;
- }
-
- pipe_state_t *pipe = &_dcd.pipe[0];
- pipe->ff = buffer_type;
- pipe->length = total_bytes;
- pipe->remaining = total_bytes;
- if (total_bytes) {
- pipe->buf = buffer;
- if (ep_addr) { /* IN */
- TU_ASSERT(USB0.DCPCTR.BIT.BSTS && (USB0.USBREQ.WORD & 0x80));
- pipe0_xfer_in();
- }
- USB0.DCPCTR.WORD = USB_PIPECTR_PID_BUF;
- } else {
- /* ZLP */
- pipe->buf = NULL;
- USB0.DCPCTR.WORD = USB_PIPECTR_CCPL | USB_PIPECTR_PID_BUF;
- }
- return true;
-}
-
-static bool process_pipe_xfer(int buffer_type, uint8_t ep_addr, void* buffer, uint16_t total_bytes)
-{
- const unsigned epn = tu_edpt_number(ep_addr);
- const unsigned dir = tu_edpt_dir(ep_addr);
- const unsigned num = _dcd.ep[dir][epn];
-
- TU_ASSERT(num);
-
- pipe_state_t *pipe = &_dcd.pipe[num];
- pipe->ff = buffer_type;
- pipe->buf = buffer;
- pipe->length = total_bytes;
- pipe->remaining = total_bytes;
- if (dir) { /* IN */
- if (total_bytes) {
- pipe_xfer_in(num);
- } else { /* ZLP */
- USB0.D0FIFOSEL.WORD = num;
- pipe_wait_for_ready(num);
- USB0.D0FIFOCTR.WORD = USB_FIFOCTR_BVAL;
- USB0.D0FIFOSEL.WORD = 0;
- while (USB0.D0FIFOSEL.BIT.CURPIPE) ; /* if CURPIPE bits changes, check written value */
- }
- } else {
- volatile reg_pipetre_t *pt = get_pipetre(num);
- if (pt) {
- const unsigned mps = edpt_max_packet_size(num);
- volatile uint16_t *ctr = get_pipectr(num);
- if (*ctr & 0x3) *ctr = USB_PIPECTR_PID_NAK;
- pt->TRE = TU_BIT(8);
- pt->TRN = (total_bytes + mps - 1) / mps;
- pt->TRENB = 1;
- *ctr = USB_PIPECTR_PID_BUF;
- }
- }
- // TU_LOG1("X %x %d %d\r\n", ep_addr, total_bytes, buffer_type);
- return true;
-}
-
-static bool process_edpt_xfer(int buffer_type, uint8_t ep_addr, void* buffer, uint16_t total_bytes)
-{
- const unsigned epn = tu_edpt_number(ep_addr);
- if (0 == epn) {
- return process_pipe0_xfer(buffer_type, ep_addr, buffer, total_bytes);
- } else {
- return process_pipe_xfer(buffer_type, ep_addr, buffer, total_bytes);
- }
-}
-
-static void process_pipe0_bemp(uint8_t rhport)
-{
- bool completed = pipe0_xfer_in();
- if (completed) {
- pipe_state_t *pipe = &_dcd.pipe[0];
- dcd_event_xfer_complete(rhport, tu_edpt_addr(0, TUSB_DIR_IN),
- pipe->length, XFER_RESULT_SUCCESS, true);
- }
-}
-
-static void process_pipe_brdy(uint8_t rhport, unsigned num)
-{
- pipe_state_t *pipe = &_dcd.pipe[num];
- const unsigned dir = tu_edpt_dir(pipe->ep);
- bool completed;
-
- if (dir) { /* IN */
- completed = pipe_xfer_in(num);
- } else {
- if (num) {
- completed = pipe_xfer_out(num);
- } else {
- completed = pipe0_xfer_out();
- }
- }
- if (completed) {
- dcd_event_xfer_complete(rhport, pipe->ep,
- pipe->length - pipe->remaining,
- XFER_RESULT_SUCCESS, true);
- // TU_LOG1("C %d %d\r\n", num, pipe->length - pipe->remaining);
- }
-}
-
-static void process_bus_reset(uint8_t rhport)
-{
- USB0.BEMPENB.WORD = 1;
- USB0.BRDYENB.WORD = 1;
- USB0.CFIFOCTR.WORD = USB_FIFOCTR_BCLR;
- USB0.D0FIFOSEL.WORD = 0;
- while (USB0.D0FIFOSEL.BIT.CURPIPE) ; /* if CURPIPE bits changes, check written value */
- USB0.D1FIFOSEL.WORD = 0;
- while (USB0.D1FIFOSEL.BIT.CURPIPE) ; /* if CURPIPE bits changes, check written value */
- volatile uint16_t *ctr = (volatile uint16_t*)((uintptr_t)(&USB0.PIPE1CTR.WORD));
- volatile uint16_t *tre = (volatile uint16_t*)((uintptr_t)(&USB0.PIPE1TRE.WORD));
- for (int i = 1; i <= 5; ++i) {
- USB0.PIPESEL.WORD = i;
- USB0.PIPECFG.WORD = 0;
- *ctr = USB_PIPECTR_ACLRM;
- *ctr = 0;
- ++ctr;
- *tre = TU_BIT(8);
- tre += 2;
- }
- for (int i = 6; i <= 9; ++i) {
- USB0.PIPESEL.WORD = i;
- USB0.PIPECFG.WORD = 0;
- *ctr = USB_PIPECTR_ACLRM;
- *ctr = 0;
- ++ctr;
- }
- tu_varclr(&_dcd);
- dcd_event_bus_reset(rhport, TUSB_SPEED_FULL, true);
-}
-
-static void process_set_address(uint8_t rhport)
-{
- const uint32_t addr = USB0.USBADDR.BIT.USBADDR;
- if (!addr) return;
- const tusb_control_request_t setup_packet = {
-#if defined(__CCRX__)
- .bmRequestType = { 0 }, /* Note: CCRX needs the braces over this struct member */
-#else
- .bmRequestType = 0,
-#endif
- .bRequest = TUSB_REQ_SET_ADDRESS,
- .wValue = addr,
- .wIndex = 0,
- .wLength = 0,
- };
- dcd_event_setup_received(rhport, (const uint8_t*)&setup_packet, true);
-}
-
-/*------------------------------------------------------------------*/
-/* Device API
- *------------------------------------------------------------------*/
-void dcd_init(uint8_t rhport)
-{
- (void)rhport;
- /* Enable USB0 */
- uint32_t pswi = disable_interrupt();
- SYSTEM.PRCR.WORD = SYSTEM_PRCR_PRKEY | SYSTEM_PRCR_PRC1;
- MSTP(USB0) = 0;
- SYSTEM.PRCR.WORD = SYSTEM_PRCR_PRKEY;
- enable_interrupt(pswi);
- USB0.SYSCFG.BIT.SCKE = 1;
- while (!USB0.SYSCFG.BIT.SCKE) ;
- USB0.SYSCFG.BIT.DRPD = 0;
- USB0.SYSCFG.BIT.DCFM = 0;
- USB0.SYSCFG.BIT.USBE = 1;
-
- USB.DPUSR0R.BIT.FIXPHY0 = 0u; /* USB0 Transceiver Output fixed */
-#if ( CFG_TUSB_MCU == OPT_MCU_RX72N )
- USB0.PHYSLEW.LONG = 0x5;
- IR(PERIB, INTB185) = 0;
-#else
- IR(USB0, USBI0) = 0;
-#endif
-
- /* Setup default control pipe */
- USB0.DCPMAXP.BIT.MXPS = 64;
- USB0.INTENB0.WORD = USB_IS0_VBINT | USB_IS0_BRDY | USB_IS0_BEMP |
- USB_IS0_DVST | USB_IS0_CTRT | (USE_SOF ? USB_IS0_SOFR: 0) | USB_IS0_RESM;
- USB0.BEMPENB.WORD = 1;
- USB0.BRDYENB.WORD = 1;
-
- if (USB0.INTSTS0.BIT.VBSTS) {
- dcd_connect(rhport);
- }
-}
-
-void dcd_int_enable(uint8_t rhport)
-{
- (void)rhport;
-#if ( CFG_TUSB_MCU == OPT_MCU_RX72N )
- IEN(PERIB, INTB185) = 1;
-#else
- IEN(USB0, USBI0) = 1;
-#endif
-}
-
-void dcd_int_disable(uint8_t rhport)
-{
- (void)rhport;
-#if ( CFG_TUSB_MCU == OPT_MCU_RX72N )
- IEN(PERIB, INTB185) = 0;
-#else
- IEN(USB0, USBI0) = 0;
-#endif
-}
-
-void dcd_set_address(uint8_t rhport, uint8_t dev_addr)
-{
- (void)rhport;
- (void)dev_addr;
-}
-
-void dcd_remote_wakeup(uint8_t rhport)
-{
- (void)rhport;
- USB0.DVSTCTR0.BIT.WKUP = 1;
-}
-
-void dcd_connect(uint8_t rhport)
-{
- (void)rhport;
- USB0.SYSCFG.BIT.DPRPU = 1;
-}
-
-void dcd_disconnect(uint8_t rhport)
-{
- (void)rhport;
- USB0.SYSCFG.BIT.DPRPU = 0;
-}
-
-//--------------------------------------------------------------------+
-// Endpoint API
-//--------------------------------------------------------------------+
-bool dcd_edpt_open(uint8_t rhport, tusb_desc_endpoint_t const * ep_desc)
-{
- (void)rhport;
-
- const unsigned ep_addr = ep_desc->bEndpointAddress;
- const unsigned epn = tu_edpt_number(ep_addr);
- const unsigned dir = tu_edpt_dir(ep_addr);
- const unsigned xfer = ep_desc->bmAttributes.xfer;
-
- const unsigned mps = tu_le16toh(ep_desc->wMaxPacketSize.size);
- if (xfer == TUSB_XFER_ISOCHRONOUS && mps > 256) {
- /* USBa supports up to 256 bytes */
- return false;
- }
-
- const unsigned num = find_pipe(xfer);
- if (!num) return false;
- _dcd.pipe[num].ep = ep_addr;
- _dcd.ep[dir][epn] = num;
-
- /* setup pipe */
- dcd_int_disable(rhport);
- USB0.PIPESEL.WORD = num;
- USB0.PIPEMAXP.WORD = mps;
- volatile uint16_t *ctr = get_pipectr(num);
- *ctr = USB_PIPECTR_ACLRM;
- *ctr = 0;
- unsigned cfg = (dir << 4) | epn;
- if (xfer == TUSB_XFER_BULK) {
- cfg |= USB_PIPECFG_BULK | USB_PIPECFG_SHTNAK | USB_PIPECFG_DBLB;
- } else if (xfer == TUSB_XFER_INTERRUPT) {
- cfg |= USB_PIPECFG_INT;
- } else {
- cfg |= USB_PIPECFG_ISO | USB_PIPECFG_DBLB;
- }
- USB0.PIPECFG.WORD = cfg;
- USB0.BRDYSTS.WORD = 0x1FFu ^ TU_BIT(num);
- USB0.BRDYENB.WORD |= TU_BIT(num);
- if (dir || (xfer != TUSB_XFER_BULK)) {
- *ctr = USB_PIPECTR_PID_BUF;
- }
- // TU_LOG1("O %d %x %x\r\n", USB0.PIPESEL.WORD, USB0.PIPECFG.WORD, USB0.PIPEMAXP.WORD);
- dcd_int_enable(rhport);
-
- return true;
-}
-
-void dcd_edpt_close(uint8_t rhport, uint8_t ep_addr)
-{
- (void)rhport;
- const unsigned epn = tu_edpt_number(ep_addr);
- const unsigned dir = tu_edpt_dir(ep_addr);
- const unsigned num = _dcd.ep[dir][epn];
-
- USB0.BRDYENB.WORD &= ~TU_BIT(num);
- volatile uint16_t *ctr = get_pipectr(num);
- *ctr = 0;
- USB0.PIPESEL.WORD = num;
- USB0.PIPECFG.WORD = 0;
- _dcd.pipe[num].ep = 0;
- _dcd.ep[dir][epn] = 0;
-}
-
-bool dcd_edpt_xfer(uint8_t rhport, uint8_t ep_addr, uint8_t* buffer, uint16_t total_bytes)
-{
- bool r;
- dcd_int_disable(rhport);
- r = process_edpt_xfer(0, ep_addr, buffer, total_bytes);
- dcd_int_enable(rhport);
- return r;
-}
-
-bool dcd_edpt_xfer_fifo(uint8_t rhport, uint8_t ep_addr, tu_fifo_t * ff, uint16_t total_bytes)
-{
- // USB buffers always work in bytes so to avoid unnecessary divisions we demand item_size = 1
- TU_ASSERT(ff->item_size == 1);
- bool r;
- dcd_int_disable(rhport);
- r = process_edpt_xfer(1, ep_addr, ff, total_bytes);
- dcd_int_enable(rhport);
- return r;
-}
-
-void dcd_edpt_stall(uint8_t rhport, uint8_t ep_addr)
-{
- volatile uint16_t *ctr = ep_addr_to_pipectr(rhport, ep_addr);
- if (!ctr) return;
- dcd_int_disable(rhport);
- const uint32_t pid = *ctr & 0x3;
- *ctr = pid | USB_PIPECTR_PID_STALL;
- *ctr = USB_PIPECTR_PID_STALL;
- dcd_int_enable(rhport);
-}
-
-void dcd_edpt_clear_stall(uint8_t rhport, uint8_t ep_addr)
-{
- volatile uint16_t *ctr = ep_addr_to_pipectr(rhport, ep_addr);
- if (!ctr) return;
- dcd_int_disable(rhport);
- *ctr = USB_PIPECTR_SQCLR;
-
- if (tu_edpt_dir(ep_addr)) { /* IN */
- *ctr = USB_PIPECTR_PID_BUF;
- } else {
- const unsigned num = _dcd.ep[0][tu_edpt_number(ep_addr)];
- USB0.PIPESEL.WORD = num;
- if (USB0.PIPECFG.BIT.TYPE != 1) {
- *ctr = USB_PIPECTR_PID_BUF;
- }
- }
- dcd_int_enable(rhport);
-}
-
-//--------------------------------------------------------------------+
-// ISR
-//--------------------------------------------------------------------+
-void dcd_int_handler(uint8_t rhport)
-{
- (void)rhport;
-
- unsigned is0 = USB0.INTSTS0.WORD;
- /* clear active bits except VALID (don't write 0 to already cleared bits according to the HW manual) */
- USB0.INTSTS0.WORD = ~((USB_IS0_CTRT | USB_IS0_DVST | USB_IS0_SOFR | USB_IS0_RESM | USB_IS0_VBINT) & is0) | USB_IS0_VALID;
- if (is0 & USB_IS0_VBINT) {
- if (USB0.INTSTS0.BIT.VBSTS) {
- dcd_connect(rhport);
- } else {
- dcd_disconnect(rhport);
- }
- }
- if (is0 & USB_IS0_RESM) {
- dcd_event_bus_signal(rhport, DCD_EVENT_RESUME, true);
-#if (0==USE_SOF)
- USB0.INTENB0.BIT.SOFE = 0;
-#endif
- }
- if ((is0 & USB_IS0_SOFR) && USB0.INTENB0.BIT.SOFE) {
- // USBD will exit suspended mode when SOF event is received
- dcd_event_bus_signal(rhport, DCD_EVENT_SOF, true);
-#if (0==USE_SOF)
- USB0.INTENB0.BIT.SOFE = 0;
-#endif
- }
- if (is0 & USB_IS0_DVST) {
- switch (is0 & USB_IS0_DVSQ) {
- case USB_IS0_DVSQ_DEF:
- process_bus_reset(rhport);
- break;
- case USB_IS0_DVSQ_ADDR:
- process_set_address(rhport);
- break;
- case USB_IS0_DVSQ_SUSP0:
- case USB_IS0_DVSQ_SUSP1:
- case USB_IS0_DVSQ_SUSP2:
- case USB_IS0_DVSQ_SUSP3:
- dcd_event_bus_signal(rhport, DCD_EVENT_SUSPEND, true);
-#if (0==USE_SOF)
- USB0.INTENB0.BIT.SOFE = 1;
-#endif
- default:
- break;
- }
- }
- if (is0 & USB_IS0_CTRT) {
- if (is0 & USB_IS0_CTSQ_SETUP) {
- /* A setup packet has been received. */
- process_setup_packet(rhport);
- } else if (0 == (is0 & USB_IS0_CTSQ_MSK)) {
- /* A ZLP has been sent/received. */
- process_status_completion(rhport);
- }
- }
- if (is0 & USB_IS0_BEMP) {
- const unsigned s = USB0.BEMPSTS.WORD;
- USB0.BEMPSTS.WORD = 0;
- if (s & 1) {
- process_pipe0_bemp(rhport);
- }
- }
- if (is0 & USB_IS0_BRDY) {
- const unsigned m = USB0.BRDYENB.WORD;
- unsigned s = USB0.BRDYSTS.WORD & m;
- /* clear active bits (don't write 0 to already cleared bits according to the HW manual) */
- USB0.BRDYSTS.WORD = ~s;
- while (s) {
-#if defined(__CCRX__)
- static const int Mod37BitPosition[] = {
- -1, 0, 1, 26, 2, 23, 27, 0, 3, 16, 24, 30, 28, 11, 0, 13, 4,
- 7, 17, 0, 25, 22, 31, 15, 29, 10, 12, 6, 0, 21, 14, 9, 5,
- 20, 8, 19, 18
- };
-
- const unsigned num = Mod37BitPosition[(-s & s) % 37];
-#else
- const unsigned num = __builtin_ctz(s);
-#endif
- process_pipe_brdy(rhport, num);
- s &= ~TU_BIT(num);
- }
- }
-}
-
-#endif
diff --git a/tinyusb/src/portable/silabs/efm32/dcd_efm32.c b/tinyusb/src/portable/silabs/efm32/dcd_efm32.c
deleted file mode 100755
index bd1f32e6..00000000
--- a/tinyusb/src/portable/silabs/efm32/dcd_efm32.c
+++ /dev/null
@@ -1,931 +0,0 @@
-/*
- * The MIT License (MIT)
- *
- * Copyright (c) 2021 Rafael Silva (@perigoso)
- * Copyright (c) 2021 Ha Thach (tinyusb.org)
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- *
- * This file is part of the TinyUSB stack.
- */
-
-#include "tusb_option.h"
-
-#if TUSB_OPT_DEVICE_ENABLED && ( \
- (CFG_TUSB_MCU == OPT_MCU_EFM32GG) || \
- (CFG_TUSB_MCU == OPT_MCU_EFM32GG11) || \
- (CFG_TUSB_MCU == OPT_MCU_EFM32GG12) )
-
-/* Silabs */
-#include "em_device.h"
-
-#include "device/dcd.h"
-
-/*
- * Since TinyUSB doesn't use SOF for now, and this interrupt too often (1ms interval)
- * We disable SOF for now until needed later on
- */
-#define USE_SOF 0
-
-/*
- * Number of endpoints
- * 12 software-configurable endpoints (6 IN, 6 OUT) in addition to endpoint 0
- */
-#define EP_COUNT 7
-
-/* FIFO size in bytes */
-#define EP_FIFO_SIZE 2048
-
-/* Max number of IN EP FIFOs */
-#define EP_FIFO_NUM 7
-
-/* */
-typedef struct {
- uint8_t *buffer;
- uint16_t total_len;
- uint16_t queued_len;
- uint16_t max_size;
- bool short_packet;
-} xfer_ctl_t;
-
-static uint32_t _setup_packet[2];
-
-#define XFER_CTL_BASE(_ep, _dir) &xfer_status[_ep][_dir]
-static xfer_ctl_t xfer_status[EP_COUNT][2];
-
-/* Keep count of how many FIFOs are in use */
-static uint8_t _allocated_fifos = 1; /* FIFO0 is always in use */
-
-static volatile uint32_t* tx_fifo[EP_FIFO_NUM] = {
- USB->FIFO0D,
- USB->FIFO1D,
- USB->FIFO2D,
- USB->FIFO3D,
- USB->FIFO4D,
- USB->FIFO5D,
- USB->FIFO6D,
-};
-
-/* Register Helpers */
-#define DCTL_WO_BITMASK (USB_DCTL_CGOUTNAK | USB_DCTL_SGOUTNAK | USB_DCTL_CGNPINNAK | USB_DCTL_SGNPINNAK)
-#define GUSBCFG_WO_BITMASK (USB_GUSBCFG_CORRUPTTXPKT)
-#define DEPCTL_WO_BITMASK (USB_DIEP_CTL_CNAK | USB_DIEP_CTL_SNAK | USB_DIEP_CTL_SETD0PIDEF | USB_DIEP_CTL_SETD1PIDOF)
-
-/* Will either return an unused FIFO number, or 0 if all are used. */
-static uint8_t get_free_fifo(void)
-{
- if(_allocated_fifos < EP_FIFO_NUM) return _allocated_fifos++;
- return 0;
-}
-
-/*
-static void flush_rx_fifo(void)
-{
- USB->GRSTCTL = USB_GRSTCTL_RXFFLSH;
- while(USB->GRSTCTL & USB_GRSTCTL_RXFFLSH);
-}
-*/
-
-static void flush_tx_fifo(uint8_t fifo_num)
-{
- USB->GRSTCTL = USB_GRSTCTL_TXFFLSH | (fifo_num << _USB_GRSTCTL_TXFNUM_SHIFT);
- while(USB->GRSTCTL & USB_GRSTCTL_TXFFLSH);
-}
-
-/* Setup the control endpoint 0. */
-static void bus_reset(void)
-{
- USB->DOEP0CTL |= USB_DIEP_CTL_SNAK;
- for(uint8_t i = 0; i < EP_COUNT - 1; i++)
- {
- USB->DOEP[i].CTL |= USB_DIEP_CTL_SNAK;
- }
-
- /* reset address */
- USB->DCFG &= ~_USB_DCFG_DEVADDR_MASK;
-
- USB->DAINTMSK |= USB_DAINTMSK_OUTEPMSK0 | USB_DAINTMSK_INEPMSK0;
- USB->DOEPMSK |= USB_DOEPMSK_SETUPMSK | USB_DOEPMSK_XFERCOMPLMSK;
- USB->DIEPMSK |= USB_DIEPMSK_TIMEOUTMSK | USB_DIEPMSK_XFERCOMPLMSK;
-
- /*
- * - All EP OUT shared a unique OUT FIFO which uses
- * * 10 locations in hardware for setup packets + setup control words (up to 3 setup packets).
- * * 2 locations for OUT endpoint control words.
- * * 16 for largest packet size of 64 bytes. ( TODO Highspeed is 512 bytes)
- * * 1 location for global NAK (not required/used here).
- * * It is recommended to allocate 2 times the largest packet size, therefore
- * Recommended value = 10 + 1 + 2 x (16+2) = 47 --> Let's make it 52
- */
- flush_tx_fifo(_USB_GRSTCTL_TXFNUM_FALL); // Flush All
- USB->GRXFSIZ = 52;
-
- /* Control IN uses FIFO 0 with 64 bytes ( 16 32-bit word ) */
- USB->GNPTXFSIZ = (16 << _USB_GNPTXFSIZ_NPTXFINEPTXF0DEP_SHIFT) | (USB->GRXFSIZ & _USB_GNPTXFSIZ_NPTXFSTADDR_MASK);
-
- /* Ready to receive SETUP packet */
- USB->DOEP0TSIZ |= (1 << _USB_DOEP0TSIZ_SUPCNT_SHIFT);
-
- USB->GINTMSK |= USB_GINTMSK_IEPINTMSK | USB_GINTMSK_OEPINTMSK;
-}
-
-static void enum_done_processing(void)
-{
- /* Maximum packet size for EP 0 is set for both directions by writing DIEPCTL */
- if((USB->DSTS & _USB_DSTS_ENUMSPD_MASK) == USB_DSTS_ENUMSPD_FS)
- {
- /* Full Speed (PHY on 48 MHz) */
- USB->DOEP0CTL = (USB->DOEP0CTL & ~_USB_DOEP0CTL_MPS_MASK) | _USB_DOEP0CTL_MPS_64B; /* Maximum Packet Size 64 bytes */
- USB->DOEP0CTL &= ~_USB_DOEP0CTL_STALL_MASK; /* clear Stall */
- xfer_status[0][TUSB_DIR_OUT].max_size = 64;
- xfer_status[0][TUSB_DIR_IN].max_size = 64;
- }
- else
- {
- /* Low Speed (PHY on 6 MHz) */
- USB->DOEP0CTL = (USB->DOEP0CTL & ~_USB_DOEP0CTL_MPS_MASK) | _USB_DOEP0CTL_MPS_8B; /* Maximum Packet Size 64 bytes */
- USB->DOEP0CTL &= ~_USB_DOEP0CTL_STALL_MASK; /* clear Stall */
- xfer_status[0][TUSB_DIR_OUT].max_size = 8;
- xfer_status[0][TUSB_DIR_IN].max_size = 8;
- }
-}
-
-
-/*------------------------------------------------------------------*/
-/* Controller API */
-/*------------------------------------------------------------------*/
-void dcd_init(uint8_t rhport)
-{
- (void) rhport;
-
- /* Reset Core */
- USB->PCGCCTL &= ~USB_PCGCCTL_STOPPCLK;
- USB->PCGCCTL &= ~(USB_PCGCCTL_PWRCLMP | USB_PCGCCTL_RSTPDWNMODULE);
-
- /* Core Soft Reset */
- USB->GRSTCTL |= USB_GRSTCTL_CSFTRST;
- while(USB->GRSTCTL & USB_GRSTCTL_CSFTRST);
-
- while(!(USB->GRSTCTL & USB_GRSTCTL_AHBIDLE));
-
- /* Enable PHY pins */
- USB->ROUTE = USB_ROUTE_PHYPEN;
-
- dcd_disconnect(rhport);
-
- /*
- * Set device speed (Full speed PHY)
- * Stall on non-zero len status OUT packets (ctrl transfers)
- * periodic frame interval to 80%
- */
- USB->DCFG = (USB->DCFG & ~(_USB_DCFG_DEVSPD_MASK | _USB_DCFG_PERFRINT_MASK)) | USB_DCFG_DEVSPD_FS | USB_DCFG_NZSTSOUTHSHK;
-
- /* Enable Global Interrupts */
- USB->GAHBCFG = (USB->GAHBCFG & ~_USB_GAHBCFG_HBSTLEN_MASK) | USB_GAHBCFG_GLBLINTRMSK;
-
- /* Force Device Mode */
- USB->GUSBCFG = (USB->GUSBCFG & ~(GUSBCFG_WO_BITMASK | USB_GUSBCFG_FORCEHSTMODE)) | USB_GUSBCFG_FORCEDEVMODE;
-
- /* No Overrides */
- USB->GOTGCTL &= ~(USB_GOTGCTL_BVALIDOVVAL | USB_GOTGCTL_BVALIDOVEN | USB_GOTGCTL_VBVALIDOVVAL);
-
- /* Ignore frame numbers on ISO transfers. */
- USB->DCTL = (USB->DCTL & ~DCTL_WO_BITMASK) | USB_DCTL_IGNRFRMNUM;
-
- /* Setting SNAKs */
- USB->DOEP0CTL |= USB_DIEP_CTL_SNAK;
- for(uint8_t i = 0; i < EP_COUNT - 1; i++)
- {
- USB->DOEP[i].CTL |= USB_DIEP_CTL_SNAK;
- }
-
- /* D. Interruption masking */
- /* Disable all device interrupts */
- USB->DIEPMSK = 0;
- USB->DOEPMSK = 0;
- USB->DAINTMSK = 0;
- USB->DIEPEMPMSK = 0;
- USB->GINTMSK = 0;
- USB->GOTGINT = ~0U; /* clear OTG ints */
- USB->GINTSTS = ~0U; /* clear pending ints */
- USB->GINTMSK = USB_GINTMSK_MODEMISMSK |
- #if USE_SOF
- USB_GINTMSK_SOFMSK |
- #endif
- USB_GINTMSK_ERLYSUSPMSK |
- USB_GINTMSK_USBSUSPMSK |
- USB_GINTMSK_USBRSTMSK |
- USB_GINTMSK_ENUMDONEMSK |
- USB_GINTMSK_RESETDETMSK |
- USB_GINTMSK_DISCONNINTMSK;
-
- NVIC_ClearPendingIRQ(USB_IRQn);
-
- dcd_connect(rhport);
-}
-
-void dcd_set_address(uint8_t rhport, uint8_t dev_addr)
-{
- (void) rhport;
-
- USB->DCFG = (USB->DCFG & ~_USB_DCFG_DEVADDR_MASK) | (dev_addr << _USB_DCFG_DEVADDR_SHIFT);
-
- /* Response with status after changing device address */
- dcd_edpt_xfer(rhport, tu_edpt_addr(0, TUSB_DIR_IN), NULL, 0);
-}
-
-void dcd_remote_wakeup(uint8_t rhport)
-{
- (void) rhport;
-}
-
-void dcd_connect(uint8_t rhport)
-{
- (void) rhport;
-
- /* connect by enabling internal pull-up resistor on D+/D- */
- USB->DCTL &= ~(DCTL_WO_BITMASK | USB_DCTL_SFTDISCON);
-}
-
-void dcd_disconnect(uint8_t rhport)
-{
- (void) rhport;
-
- /* disconnect by disabling internal pull-up resistor on D+/D- */
- USB->DCTL = (USB->DCTL & ~(DCTL_WO_BITMASK)) | USB_DCTL_SFTDISCON;
-}
-
-/*------------------------------------------------------------------*/
-/* DCD Endpoint Port */
-/*------------------------------------------------------------------*/
-void dcd_edpt_stall(uint8_t rhport, uint8_t ep_addr)
-{
- (void) rhport;
-
- uint8_t const epnum = tu_edpt_number(ep_addr);
- uint8_t const dir = tu_edpt_dir(ep_addr);
-
- if(dir == TUSB_DIR_IN)
- {
- if(epnum == 0)
- {
- USB->DIEP0CTL = (USB->DIEP0CTL & ~DEPCTL_WO_BITMASK) | USB_DIEP0CTL_SNAK | USB_DIEP0CTL_STALL;
-
- flush_tx_fifo(_USB_GRSTCTL_TXFNUM_F0);
- }
- else
- {
- /* Only disable currently enabled non-control endpoint */
- if(USB->DIEP[epnum - 1].CTL & USB_DIEP_CTL_EPENA)
- {
- USB->DIEP[epnum - 1].CTL = (USB->DIEP[epnum - 1].CTL & ~DEPCTL_WO_BITMASK) | USB_DIEP_CTL_EPDIS | USB_DIEP_CTL_SNAK | USB_DIEP_CTL_STALL;
- while(!(USB->DIEP[epnum - 1].INT & USB_DIEP_INT_EPDISBLD));
- USB->DIEP[epnum - 1].INT |= USB_DIEP_INT_EPDISBLD;
- }
- else
- {
- USB->DIEP[epnum - 1].CTL = (USB->DIEP[epnum - 1].CTL & ~DEPCTL_WO_BITMASK) | USB_DIEP_CTL_SNAK | USB_DIEP_CTL_STALL;
- }
-
- /* Flush the FIFO */
- uint8_t const fifo_num = ((USB->DIEP[epnum - 1].CTL & _USB_DIEP_CTL_TXFNUM_MASK) >> _USB_DIEP_CTL_TXFNUM_SHIFT);
- flush_tx_fifo(fifo_num);
- }
- }
- else
- {
- if(epnum == 0)
- {
- USB->DOEP0CTL = (USB->DOEP0CTL & ~DEPCTL_WO_BITMASK) | USB_DIEP0CTL_STALL;
- }
- else
- {
- /* Only disable currently enabled non-control endpoint */
- if(USB->DOEP[epnum - 1].CTL & USB_DIEP_CTL_EPENA)
- {
- /* Asserting GONAK is required to STALL an OUT endpoint. */
- USB->DCTL |= USB_DCTL_SGOUTNAK;
- while(!(USB->GINTSTS & USB_GINTSTS_GOUTNAKEFF));
-
- /* Disable the endpoint. Note that only STALL and not SNAK is set here. */
- USB->DOEP[epnum - 1].CTL = (USB->DOEP[epnum - 1].CTL & ~DEPCTL_WO_BITMASK) | USB_DIEP_CTL_EPDIS | USB_DIEP_CTL_STALL;
- while(USB->DOEP[epnum - 1].INT & USB_DIEP_INT_EPDISBLD);
- USB->DOEP[epnum - 1].INT |= USB_DIEP_INT_EPDISBLD;
-
- /* Allow other OUT endpoints to keep receiving. */
- USB->DCTL |= USB_DCTL_CGOUTNAK;
- }
- else
- {
- USB->DIEP[epnum - 1].CTL = (USB->DIEP[epnum - 1].CTL & ~DEPCTL_WO_BITMASK) | USB_DIEP_CTL_STALL;
- }
- }
- }
-}
-
-void dcd_edpt_clear_stall(uint8_t rhport, uint8_t ep_addr)
-{
- (void) rhport;
-
- uint8_t const epnum = tu_edpt_number(ep_addr);
- uint8_t const dir = tu_edpt_dir(ep_addr);
-
- if(dir == TUSB_DIR_IN)
- {
- if(epnum == 0)
- {
- USB->DIEP0CTL &= ~(DEPCTL_WO_BITMASK | USB_DIEP0CTL_STALL);
- }
- else
- {
- USB->DIEP[epnum - 1].CTL &= ~(DEPCTL_WO_BITMASK | USB_DIEP_CTL_STALL);
-
- /* Required by USB spec to reset DATA toggle bit to DATA0 on interrupt and bulk endpoints. */
- uint8_t eptype = (USB->DIEP[epnum - 1].CTL & _USB_DIEP_CTL_EPTYPE_MASK) >> _USB_DIEP_CTL_EPTYPE_SHIFT;
-
- if((eptype == _USB_DIEP_CTL_EPTYPE_BULK) || (eptype == _USB_DIEP_CTL_EPTYPE_INT))
- {
- USB->DIEP[epnum - 1].CTL |= USB_DIEP_CTL_SETD0PIDEF;
- }
- }
- }
- else
- {
- if(epnum == 0)
- {
- USB->DOEP0CTL &= ~(DEPCTL_WO_BITMASK | USB_DOEP0CTL_STALL);
- }
- else
- {
- USB->DOEP[epnum - 1].CTL &= ~(DEPCTL_WO_BITMASK | USB_DOEP_CTL_STALL);
-
- /* Required by USB spec to reset DATA toggle bit to DATA0 on interrupt and bulk endpoints. */
- uint8_t eptype = (USB->DOEP[epnum - 1].CTL & _USB_DOEP_CTL_EPTYPE_MASK) >> _USB_DOEP_CTL_EPTYPE_SHIFT;
-
- if((eptype == _USB_DOEP_CTL_EPTYPE_BULK) || (eptype == _USB_DOEP_CTL_EPTYPE_INT))
- {
- USB->DOEP[epnum - 1].CTL |= USB_DOEP_CTL_SETD0PIDEF;
- }
- }
- }
-}
-
-bool dcd_edpt_open(uint8_t rhport, tusb_desc_endpoint_t const * p_endpoint_desc)
-{
- (void)rhport;
-
- uint8_t const epnum = tu_edpt_number(p_endpoint_desc->bEndpointAddress);
- uint8_t const dir = tu_edpt_dir(p_endpoint_desc->bEndpointAddress);
-
- TU_ASSERT(p_endpoint_desc->wMaxPacketSize.size <= 64);
- TU_ASSERT(epnum < EP_COUNT);
- TU_ASSERT(epnum != 0);
-
- xfer_ctl_t *xfer = XFER_CTL_BASE(epnum, dir);
- xfer->max_size = p_endpoint_desc->wMaxPacketSize.size;
-
- if(dir == TUSB_DIR_OUT)
- {
- USB->DOEP[epnum - 1].CTL |= USB_DOEP_CTL_USBACTEP |
- (p_endpoint_desc->bmAttributes.xfer << _USB_DOEP_CTL_EPTYPE_SHIFT) |
- (p_endpoint_desc->wMaxPacketSize.size << _USB_DOEP_CTL_MPS_SHIFT);
- USB->DAINTMSK |= (1 << (_USB_DAINTMSK_OUTEPMSK0_SHIFT + epnum));
- }
- else
- {
- uint8_t fifo_num = get_free_fifo();
- TU_ASSERT(fifo_num != 0);
-
- USB->DIEP[epnum - 1].CTL &= ~(_USB_DIEP_CTL_TXFNUM_MASK | _USB_DIEP_CTL_EPTYPE_MASK | USB_DIEP_CTL_SETD0PIDEF | _USB_DIEP_CTL_MPS_MASK);
- USB->DIEP[epnum - 1].CTL |= USB_DIEP_CTL_USBACTEP |
- (fifo_num << _USB_DIEP_CTL_TXFNUM_SHIFT) |
- (p_endpoint_desc->bmAttributes.xfer << _USB_DIEP_CTL_EPTYPE_SHIFT) |
- ((p_endpoint_desc->bmAttributes.xfer != TUSB_XFER_ISOCHRONOUS) ? USB_DIEP_CTL_SETD0PIDEF : 0) |
- (p_endpoint_desc->wMaxPacketSize.size << 0);
-
- USB->DAINTMSK |= (1 << epnum);
-
- /* Both TXFD and TXSA are in unit of 32-bit words. */
- /* IN FIFO 0 was configured during enumeration, hence the "+ 16". */
- uint16_t const allocated_size = (USB->GRXFSIZ & _USB_GRXFSIZ_RXFDEP_MASK) + 16;
- uint16_t const fifo_size = (EP_FIFO_SIZE/4 - allocated_size) / (EP_FIFO_NUM-1);
- uint32_t const fifo_offset = allocated_size + fifo_size*(fifo_num-1);
-
- /* DIEPTXF starts at FIFO #1. */
- volatile uint32_t* usb_dieptxf = &USB->DIEPTXF1;
- usb_dieptxf[epnum - 1] = (fifo_size << _USB_DIEPTXF1_INEPNTXFDEP_SHIFT) | fifo_offset;
- }
- return true;
-}
-
-bool dcd_edpt_xfer(uint8_t rhport, uint8_t ep_addr, uint8_t* buffer, uint16_t total_bytes)
-{
- (void)rhport;
-
- uint8_t const epnum = tu_edpt_number(ep_addr);
- uint8_t const dir = tu_edpt_dir(ep_addr);
-
- xfer_ctl_t * xfer = XFER_CTL_BASE(epnum, dir);
- xfer->buffer = buffer;
- xfer->total_len = total_bytes;
- xfer->queued_len = 0;
- xfer->short_packet = false;
-
- uint16_t num_packets = (total_bytes / xfer->max_size);
- uint8_t short_packet_size = total_bytes % xfer->max_size;
-
- // Zero-size packet is special case.
- if(short_packet_size > 0 || (total_bytes == 0))
- {
- num_packets++;
- }
-
- // IN and OUT endpoint xfers are interrupt-driven, we just schedule them
- // here.
- if(dir == TUSB_DIR_IN)
- {
- if(epnum == 0)
- {
- // A full IN transfer (multiple packets, possibly) triggers XFRC.
- USB->DIEP0TSIZ = (num_packets << _USB_DIEP0TSIZ_PKTCNT_SHIFT) | total_bytes;
- USB->DIEP0CTL |= USB_DIEP0CTL_EPENA | USB_DIEP0CTL_CNAK; // Enable | CNAK
- }
- else
- {
- // A full IN transfer (multiple packets, possibly) triggers XFRC.
- USB->DIEP[epnum - 1].TSIZ = (num_packets << _USB_DIEP_TSIZ_PKTCNT_SHIFT) | total_bytes;
- USB->DIEP[epnum - 1].CTL |= USB_DIEP_CTL_EPENA | USB_DIEP_CTL_CNAK; // Enable | CNAK
- }
-
- // Enable fifo empty interrupt only if there are something to put in the fifo.
- if(total_bytes != 0)
- {
- USB->DIEPEMPMSK |= (1 << epnum);
- }
- }
- else
- {
- if(epnum == 0)
- {
- // A full IN transfer (multiple packets, possibly) triggers XFRC.
- USB->DOEP0TSIZ |= (1 << _USB_DOEP0TSIZ_PKTCNT_SHIFT) | ((xfer->max_size & _USB_DOEP0TSIZ_XFERSIZE_MASK) << _USB_DOEP0TSIZ_XFERSIZE_SHIFT);
- USB->DOEP0CTL |= USB_DOEP0CTL_EPENA | USB_DOEP0CTL_CNAK;
- }
- else
- {
- // A full IN transfer (multiple packets, possibly) triggers XFRC.
- USB->DOEP[epnum - 1].TSIZ |= (1 << _USB_DOEP_TSIZ_PKTCNT_SHIFT) | ((xfer->max_size & _USB_DOEP_TSIZ_XFERSIZE_MASK) << _USB_DOEP_TSIZ_XFERSIZE_SHIFT);
- USB->DOEP[epnum - 1].CTL |= USB_DOEP_CTL_EPENA | USB_DOEP_CTL_CNAK;
- }
- }
- return true;
-}
-
-/*------------------------------------------------------------------*/
-/* IRQ */
-/*------------------------------------------------------------------*/
-void dcd_int_enable(uint8_t rhport)
-{
- (void) rhport;
-
- NVIC_EnableIRQ(USB_IRQn);
-}
-
-void dcd_int_disable(uint8_t rhport)
-{
- (void) rhport;
-
- NVIC_DisableIRQ(USB_IRQn);
-}
-
-static void receive_packet(xfer_ctl_t *xfer, uint16_t xfer_size)
-{
- uint16_t remaining = xfer->total_len - xfer->queued_len;
- uint16_t to_recv_size;
-
- if(remaining <= xfer->max_size)
- {
- /* Avoid buffer overflow. */
- to_recv_size = (xfer_size > remaining) ? remaining : xfer_size;
- }
- else
- {
- /* Room for full packet, choose recv_size based on what the microcontroller claims. */
- to_recv_size = (xfer_size > xfer->max_size) ? xfer->max_size : xfer_size;
- }
-
- uint8_t to_recv_rem = to_recv_size % 4;
- uint16_t to_recv_size_aligned = to_recv_size - to_recv_rem;
-
- /* Do not assume xfer buffer is aligned. */
- uint8_t *base = (xfer->buffer + xfer->queued_len);
-
- /* This for loop always runs at least once- skip if less than 4 bytes to collect. */
- if(to_recv_size >= 4)
- {
- for(uint16_t i = 0; i < to_recv_size_aligned; i += 4)
- {
- uint32_t tmp = (*USB->FIFO0D);
- base[i] = tmp & 0x000000FF;
- base[i + 1] = (tmp & 0x0000FF00) >> 8;
- base[i + 2] = (tmp & 0x00FF0000) >> 16;
- base[i + 3] = (tmp & 0xFF000000) >> 24;
- }
- }
-
- /* Do not read invalid bytes from RX FIFO. */
- if(to_recv_rem != 0)
- {
- uint32_t tmp = (*USB->FIFO0D);
- uint8_t *last_32b_bound = base + to_recv_size_aligned;
-
- last_32b_bound[0] = tmp & 0x000000FF;
- if(to_recv_rem > 1)
- {
- last_32b_bound[1] = (tmp & 0x0000FF00) >> 8;
- }
- if(to_recv_rem > 2)
- {
- last_32b_bound[2] = (tmp & 0x00FF0000) >> 16;
- }
- }
-
- xfer->queued_len += xfer_size;
-
- /* Per USB spec, a short OUT packet (including length 0) is always */
- /* indicative of the end of a transfer (at least for ctl, bulk, int). */
- xfer->short_packet = (xfer_size < xfer->max_size);
-}
-
-static void transmit_packet(xfer_ctl_t *xfer, uint8_t fifo_num)
-{
- uint16_t remaining;
- if(fifo_num == 0)
- {
- remaining = (USB->DIEP0TSIZ & 0x7FFFFU) >> _USB_DIEP0TSIZ_XFERSIZE_SHIFT;
- }
- else
- {
- remaining = (USB->DIEP[fifo_num - 1].TSIZ & 0x7FFFFU) >> _USB_DIEP_TSIZ_XFERSIZE_SHIFT;
- }
- xfer->queued_len = xfer->total_len - remaining;
-
- uint16_t to_xfer_size = (remaining > xfer->max_size) ? xfer->max_size : remaining;
- uint8_t to_xfer_rem = to_xfer_size % 4;
- uint16_t to_xfer_size_aligned = to_xfer_size - to_xfer_rem;
-
- /* Buffer might not be aligned to 32b, so we need to force alignment by copying to a temp var. */
- uint8_t *base = (xfer->buffer + xfer->queued_len);
-
- /* This for loop always runs at least once- skip if less than 4 bytes to send off. */
- if(to_xfer_size >= 4)
- {
- for(uint16_t i = 0; i < to_xfer_size_aligned; i += 4)
- {
- uint32_t tmp = base[i] | (base[i + 1] << 8) | (base[i + 2] << 16) | (base[i + 3] << 24);
- *tx_fifo[fifo_num] = tmp;
- }
- }
-
- /* Do not read beyond end of buffer if not divisible by 4. */
- if(to_xfer_rem != 0)
- {
- uint32_t tmp = 0;
- uint8_t *last_32b_bound = base + to_xfer_size_aligned;
-
- tmp |= last_32b_bound[0];
- if(to_xfer_rem > 1)
- {
- tmp |= (last_32b_bound[1] << 8);
- }
- if(to_xfer_rem > 2)
- {
- tmp |= (last_32b_bound[2] << 16);
- }
-
- *tx_fifo[fifo_num] = tmp;
- }
-}
-
-static void read_rx_fifo(void)
-{
- /*
- * Pop control word off FIFO (completed xfers will have 2 control words,
- * we only pop one ctl word each interrupt).
- */
- uint32_t const ctl_word = USB->GRXSTSP;
- uint8_t const pktsts = (ctl_word & _USB_GRXSTSP_PKTSTS_MASK) >> _USB_GRXSTSP_PKTSTS_SHIFT;
- uint8_t const epnum = (ctl_word & _USB_GRXSTSP_CHNUM_MASK ) >> _USB_GRXSTSP_CHNUM_SHIFT;
- uint16_t const bcnt = (ctl_word & _USB_GRXSTSP_BCNT_MASK ) >> _USB_GRXSTSP_BCNT_SHIFT;
-
- switch(pktsts)
- {
- case 0x01: /* Global OUT NAK (Interrupt) */
- break;
-
- case 0x02:
- {
- /* Out packet recvd */
- xfer_ctl_t *xfer = XFER_CTL_BASE(epnum, TUSB_DIR_OUT);
- receive_packet(xfer, bcnt);
- }
- break;
-
- case 0x03:
- /* Out packet done (Interrupt) */
- break;
-
- case 0x04:
- /* Step 2: Setup transaction completed (Interrupt) */
- /* After this event, OEPINT interrupt will occur with SETUP bit set */
- if(epnum == 0)
- {
- USB->DOEP0TSIZ |= (1 << _USB_DOEP0TSIZ_SUPCNT_SHIFT);
- }
-
- break;
-
- case 0x06:
- {
- /* Step1: Setup data packet received */
-
- /*
- * We can receive up to three setup packets in succession, but
- * only the last one is valid. Therefore we just overwrite it
- */
- _setup_packet[0] = (*USB->FIFO0D);
- _setup_packet[1] = (*USB->FIFO0D);
- }
- break;
-
- default:
- /* Invalid, breakpoint. */
- TU_BREAKPOINT();
- break;
- }
-}
-
-static void handle_epout_ints(void)
-{
- // GINTSTS will be cleared with DAINT == 0
- // DAINT for a given EP clears when DOEPINTx is cleared.
- // DOEPINT will be cleared when DAINT's out bits are cleared.
-
- for(uint8_t n = 0; n < EP_COUNT; n++)
- {
- xfer_ctl_t *xfer = XFER_CTL_BASE(n, TUSB_DIR_OUT);
-
- if(n == 0)
- {
- if(USB->DAINT & (1 << (_USB_DAINT_OUTEPINT0_SHIFT + n)))
- {
- // SETUP packet Setup Phase done.
- if((USB->DOEP0INT & USB_DOEP0INT_SETUP))
- {
- USB->DOEP0INT = USB_DOEP0INT_STUPPKTRCVD | USB_DOEP0INT_SETUP; // clear
- dcd_event_setup_received(0, (uint8_t *)&_setup_packet[0], true);
- }
-
- // OUT XFER complete (single packet).q
- if(USB->DOEP0INT & USB_DOEP0INT_XFERCOMPL)
- {
- USB->DOEP0INT = USB_DOEP0INT_XFERCOMPL;
-
- // Transfer complete if short packet or total len is transferred
- if(xfer->short_packet || (xfer->queued_len == xfer->total_len))
- {
- xfer->short_packet = false;
- dcd_event_xfer_complete(0, n, xfer->queued_len, XFER_RESULT_SUCCESS, true);
- }
- else
- {
- // Schedule another packet to be received.
- USB->DOEP0TSIZ |= (1 << _USB_DOEP0TSIZ_PKTCNT_SHIFT) | ((xfer->max_size & _USB_DOEP0TSIZ_XFERSIZE_MASK) << _USB_DOEP0TSIZ_XFERSIZE_SHIFT);
- USB->DOEP0CTL |= USB_DOEP0CTL_EPENA | USB_DOEP0CTL_CNAK;
- }
- }
- }
- }
- else
- {
- if(USB->DAINT & (1 << (_USB_DAINT_OUTEPINT0_SHIFT + n)))
- {
- // SETUP packet Setup Phase done.
- if((USB->DOEP[n - 1].INT & USB_DOEP_INT_SETUP))
- {
- USB->DOEP[n - 1].INT = USB_DOEP_INT_STUPPKTRCVD | USB_DOEP_INT_SETUP; // clear
- dcd_event_setup_received(0, (uint8_t *)&_setup_packet[0], true);
- }
-
- // OUT XFER complete (single packet).q
- if(USB->DOEP[n - 1].INT & USB_DOEP_INT_XFERCOMPL)
- {
- USB->DOEP[n - 1].INT = USB_DOEP_INT_XFERCOMPL;
-
- // Transfer complete if short packet or total len is transferred
- if(xfer->short_packet || (xfer->queued_len == xfer->total_len))
- {
- xfer->short_packet = false;
- dcd_event_xfer_complete(0, n, xfer->queued_len, XFER_RESULT_SUCCESS, true);
- }
- else
- {
- // Schedule another packet to be received.
- USB->DOEP[n - 1].TSIZ |= (1 << _USB_DOEP_TSIZ_PKTCNT_SHIFT) | ((xfer->max_size & _USB_DOEP_TSIZ_XFERSIZE_MASK) << _USB_DOEP_TSIZ_XFERSIZE_SHIFT);
- USB->DOEP[n - 1].CTL |= USB_DOEP_CTL_EPENA | USB_DOEP_CTL_CNAK;
- }
- }
- }
- }
- }
-}
-
-static void handle_epin_ints(void)
-{
-
- for(uint32_t n = 0; n < EP_COUNT; n++)
- {
- xfer_ctl_t *xfer = &xfer_status[n][TUSB_DIR_IN];
-
- if(n == 0)
- {
- if(USB->DAINT & (1 << n))
- {
- /* IN XFER complete (entire xfer). */
- if(USB->DIEP0INT & USB_DIEP0INT_XFERCOMPL)
- {
- USB->DIEP0INT = USB_DIEP0INT_XFERCOMPL;
- dcd_event_xfer_complete(0, n | TUSB_DIR_IN_MASK, xfer->total_len, XFER_RESULT_SUCCESS, true);
- }
-
- /* XFER FIFO empty */
- if(USB->DIEP0INT & USB_DIEP0INT_TXFEMP)
- {
- USB->DIEP0INT = USB_DIEP0INT_TXFEMP;
- transmit_packet(xfer, n);
-
- /* Turn off TXFE if all bytes are written. */
- if(xfer->queued_len == xfer->total_len)
- {
- USB->DIEPEMPMSK &= ~(1 << n);
- }
- }
-
- /* XFER Timeout */
- if(USB->DIEP0INT & USB_DIEP0INT_TIMEOUT)
- {
- /* Clear interrupt or enpoint will hang. */
- USB->DIEP0INT = USB_DIEP0INT_TIMEOUT;
- }
- }
- }
- else
- {
- if(USB->DAINT & (1 << n))
- {
- /* IN XFER complete (entire xfer). */
- if(USB->DIEP[n - 1].INT & USB_DIEP_INT_XFERCOMPL)
- {
- USB->DIEP[n - 1].INT = USB_DIEP_INT_XFERCOMPL;
- dcd_event_xfer_complete(0, n | TUSB_DIR_IN_MASK, xfer->total_len, XFER_RESULT_SUCCESS, true);
- }
-
- /* XFER FIFO empty */
- if(USB->DIEP[n - 1].INT & USB_DIEP_INT_TXFEMP)
- {
- USB->DIEP[n - 1].INT = USB_DIEP_INT_TXFEMP;
- transmit_packet(xfer, n);
-
- /* Turn off TXFE if all bytes are written. */
- if(xfer->queued_len == xfer->total_len)
- {
- USB->DIEPEMPMSK &= ~(1 << n);
- }
- }
-
- /* XFER Timeout */
- if(USB->DIEP[n - 1].INT & USB_DIEP_INT_TIMEOUT)
- {
- /* Clear interrupt or enpoint will hang. */
- USB->DIEP[n - 1].INT = USB_DIEP_INT_TIMEOUT;
- }
- }
- }
- }
-}
-
-void dcd_int_handler(uint8_t rhport)
-{
- (void) rhport;
-
- const uint32_t int_status = USB->GINTSTS;
-
- /* USB Reset */
- if(int_status & USB_GINTSTS_USBRST)
- {
- /* start of reset */
- USB->GINTSTS = USB_GINTSTS_USBRST;
- /* FIFOs will be reassigned when the endpoints are reopen */
- _allocated_fifos = 1;
- bus_reset();
- }
-
- /* Reset detected Interrupt */
- if(int_status & USB_GINTSTS_RESETDET)
- {
- USB->GINTSTS = USB_GINTSTS_RESETDET;
- bus_reset();
- }
-
- /* Enumeration Done */
- if(int_status & USB_GINTSTS_ENUMDONE)
- {
- /* This interrupt is considered the end of reset. */
- USB->GINTSTS = USB_GINTSTS_ENUMDONE;
- enum_done_processing();
- dcd_event_bus_signal(0, DCD_EVENT_BUS_RESET, true);
- }
-
- /* OTG Interrupt */
- if(int_status & USB_GINTSTS_OTGINT)
- {
- /* OTG INT bit is read-only */
-
- uint32_t const otg_int = USB->GOTGINT;
-
- if(otg_int & USB_GOTGINT_SESENDDET)
- {
- dcd_event_bus_signal(0, DCD_EVENT_UNPLUGGED, true);
- }
-
- USB->GOTGINT = otg_int;
- }
-
- #if USE_SOF
- if(int_status & USB_GINTSTS_SOF)
- {
- USB->GINTSTS = USB_GINTSTS_SOF;
- dcd_event_bus_signal(0, DCD_EVENT_SOF, true);
- }
- #endif
-
- /* RxFIFO Non-Empty */
- if(int_status & USB_GINTSTS_RXFLVL)
- {
- /* RXFLVL bit is read-only */
-
- /* Mask out RXFLVL while reading data from FIFO */
- USB->GINTMSK &= ~USB_GINTMSK_RXFLVLMSK;
- read_rx_fifo();
- USB->GINTMSK |= USB_GINTMSK_RXFLVLMSK;
- }
-
- /* OUT Endpoints Interrupt */
- if(int_status & USB_GINTMSK_OEPINTMSK)
- {
- /* OEPINT is read-only */
- handle_epout_ints();
- }
-
- /* IN Endpoints Interrupt */
- if(int_status & USB_GINTMSK_IEPINTMSK)
- {
- /* IEPINT bit read-only */
- handle_epin_ints();
- }
-
- /* unhandled */
- USB->GINTSTS |= USB_GINTSTS_CURMOD |
- USB_GINTSTS_MODEMIS |
- USB_GINTSTS_OTGINT |
- USB_GINTSTS_NPTXFEMP |
- USB_GINTSTS_GINNAKEFF |
- USB_GINTSTS_GOUTNAKEFF |
- USB_GINTSTS_ERLYSUSP |
- USB_GINTSTS_USBSUSP |
- USB_GINTSTS_ISOOUTDROP |
- USB_GINTSTS_EOPF |
- USB_GINTSTS_EPMIS |
- USB_GINTSTS_INCOMPISOIN |
- USB_GINTSTS_INCOMPLP |
- USB_GINTSTS_FETSUSP |
- USB_GINTSTS_PTXFEMP;
-}
-
-#endif
diff --git a/tinyusb/src/portable/sony/cxd56/dcd_cxd56.c b/tinyusb/src/portable/sony/cxd56/dcd_cxd56.c
deleted file mode 100755
index 83497646..00000000
--- a/tinyusb/src/portable/sony/cxd56/dcd_cxd56.c
+++ /dev/null
@@ -1,408 +0,0 @@
-/*
- * The MIT License (MIT)
- *
- * Copyright 2019 Sony Semiconductor Solutions Corporation
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- *
- * This file is part of the TinyUSB stack.
- */
-
-#include "tusb_option.h"
-
-#if TUSB_OPT_DEVICE_ENABLED && CFG_TUSB_MCU == OPT_MCU_CXD56
-
-#include <errno.h>
-#include <nuttx/usb/usbdev.h>
-#include <nuttx/arch.h>
-
-#include "device/dcd.h"
-
-#define CXD56_EPNUM (7)
-#define CXD56_SETUP_QUEUE_DEPTH (4)
-#define CXD56_MAX_DATA_OUT_SIZE (64)
-
-OSAL_QUEUE_DEF(OPT_MODE_DEVICE, _setup_queue_def, CXD56_SETUP_QUEUE_DEPTH, struct usb_ctrlreq_s);
-
-struct usbdcd_driver_s
-{
- struct usbdevclass_driver_s usbdevclass_driver;
- FAR struct usbdev_ep_s *ep[CXD56_EPNUM];
- FAR struct usbdev_req_s *req[CXD56_EPNUM];
- osal_queue_t setup_queue;
- bool setup_processed;
- FAR uint8_t dataout[CXD56_MAX_DATA_OUT_SIZE];
- size_t outlen;
-};
-
-static struct usbdcd_driver_s usbdcd_driver;
-static struct usbdev_s *usbdev;
-
-static int _dcd_bind (FAR struct usbdevclass_driver_s *driver, FAR struct usbdev_s *dev);
-static void _dcd_unbind (FAR struct usbdevclass_driver_s *driver, FAR struct usbdev_s *dev);
-static int _dcd_setup (FAR struct usbdevclass_driver_s *driver, FAR struct usbdev_s *dev,
- FAR const struct usb_ctrlreq_s *ctrl, FAR uint8_t *dataout, size_t outlen);
-static void _dcd_disconnect (FAR struct usbdevclass_driver_s *driver, FAR struct usbdev_s *dev);
-static void _dcd_suspend (FAR struct usbdevclass_driver_s *driver, FAR struct usbdev_s *dev);
-static void _dcd_resume (FAR struct usbdevclass_driver_s *driver, FAR struct usbdev_s *dev);
-
-static const struct usbdevclass_driverops_s g_driverops =
-{
- _dcd_bind, /* bind */
- _dcd_unbind, /* unbind */
- _dcd_setup, /* setup */
- _dcd_disconnect, /* disconnect */
- _dcd_suspend, /* suspend */
- _dcd_resume, /* resume */
-};
-
-static void usbdcd_ep0incomplete(FAR struct usbdev_ep_s *ep, FAR struct usbdev_req_s *req)
-{
- (void) ep;
-
- uint8_t ep_addr = (uint32_t)req->priv;
-
- if (req->result || req->xfrd != req->len)
- {
- if (req->len)
- {
- dcd_event_xfer_complete(0, ep_addr, req->xfrd, XFER_RESULT_SUCCESS, true);
- }
- }
- else
- {
- if (req->xfrd)
- {
- dcd_event_xfer_complete(0, ep_addr, req->xfrd, XFER_RESULT_SUCCESS, true);
- }
- }
-}
-
-static int _dcd_bind(FAR struct usbdevclass_driver_s *driver, FAR struct usbdev_s *dev)
-{
- (void) driver;
-
- usbdev = dev;
- usbdcd_driver.ep[0] = dev->ep0;
-
- usbdcd_driver.req[0] = EP_ALLOCREQ(usbdcd_driver.ep[0]);
- if (usbdcd_driver.req[0] != NULL)
- {
- usbdcd_driver.req[0]->len = 64;
- usbdcd_driver.req[0]->buf = EP_ALLOCBUFFER(usbdcd_driver.ep[0], 64);
- if (!usbdcd_driver.req[0]->buf)
- {
- EP_FREEREQ(usbdcd_driver.ep[0], usbdcd_driver.req[0]);
- usbdcd_driver.req[0] = NULL;
- }
- }
-
- usbdcd_driver.req[0]->callback = usbdcd_ep0incomplete;
-
- DEV_CONNECT(dev);
- return 0;
-}
-
-static void _dcd_unbind(FAR struct usbdevclass_driver_s *driver, FAR struct usbdev_s *dev)
-{
- (void) driver;
- (void) dev;
-}
-
-static int _dcd_setup(FAR struct usbdevclass_driver_s *driver, FAR struct usbdev_s *dev,
- FAR const struct usb_ctrlreq_s *ctrl, FAR uint8_t *dataout, size_t outlen)
-{
- (void) driver;
- (void) dev;
-
- if (usbdcd_driver.setup_processed)
- {
- usbdcd_driver.setup_processed = false;
- dcd_event_setup_received(0, (uint8_t *) ctrl, true);
- }
- else
- {
- osal_queue_send(usbdcd_driver.setup_queue, ctrl, true);
- }
-
- if (outlen > 0 && outlen <= CXD56_MAX_DATA_OUT_SIZE)
- {
- memcpy(usbdcd_driver.dataout, dataout, outlen);
- usbdcd_driver.outlen = outlen;
- }
-
- return 0;
-}
-
-static void _dcd_disconnect(FAR struct usbdevclass_driver_s *driver, FAR struct usbdev_s *dev)
-{
- (void) driver;
-
- tusb_speed_t speed;
-
- switch (dev->speed)
- {
- case USB_SPEED_LOW:
- speed = TUSB_SPEED_LOW;
- break;
- case USB_SPEED_FULL:
- speed = TUSB_SPEED_FULL;
- break;
- case USB_SPEED_HIGH:
- speed = TUSB_SPEED_HIGH;
- break;
- default:
- speed = TUSB_SPEED_HIGH;
- break;
- }
-
- dcd_event_bus_reset(0, speed, true);
- DEV_CONNECT(dev);
-}
-
-static void _dcd_suspend(FAR struct usbdevclass_driver_s *driver, FAR struct usbdev_s *dev)
-{
- (void) driver;
- (void) dev;
-
- dcd_event_bus_signal(0, DCD_EVENT_SUSPEND, true);
-}
-
-static void _dcd_resume(FAR struct usbdevclass_driver_s *driver, FAR struct usbdev_s *dev)
-{
- (void) driver;
- (void) dev;
-
- dcd_event_bus_signal(0, DCD_EVENT_RESUME, true);
-}
-
-void dcd_init(uint8_t rhport)
-{
- (void) rhport;
-
- usbdcd_driver.usbdevclass_driver.speed = USB_SPEED_HIGH;
- usbdcd_driver.usbdevclass_driver.ops = &g_driverops;
- usbdcd_driver.setup_processed = true;
- usbdcd_driver.setup_queue = osal_queue_create(&_setup_queue_def);
-
- usbdev_register(&usbdcd_driver.usbdevclass_driver);
-}
-
-// Enable device interrupt
-void dcd_int_enable(uint8_t rhport)
-{
- (void) rhport;
-
- up_enable_irq(CXD56_IRQ_USB_INT);
-}
-
-// Disable device interrupt
-void dcd_int_disable(uint8_t rhport)
-{
- (void) rhport;
-
- up_disable_irq(CXD56_IRQ_USB_INT);
-}
-
-// Receive Set Address request, mcu port must also include status IN response
-void dcd_set_address(uint8_t rhport, uint8_t dev_addr)
-{
- (void) rhport;
- (void) dev_addr;
-}
-
-void dcd_remote_wakeup(uint8_t rhport)
-{
- (void) rhport;
-
- DEV_WAKEUP(usbdev);
-}
-
-void dcd_connect(uint8_t rhport)
-{
- (void) rhport;
- DEV_CONNECT(usbdev);
-}
-
-void dcd_disconnect(uint8_t rhport)
-{
- (void) rhport;
- DEV_DISCONNECT(usbdev);
-}
-
-//--------------------------------------------------------------------+
-// Endpoint API
-//--------------------------------------------------------------------+
-
-bool dcd_edpt_open(uint8_t rhport, tusb_desc_endpoint_t const *p_endpoint_desc)
-{
- (void) rhport;
-
- uint8_t epnum = tu_edpt_number(p_endpoint_desc->bEndpointAddress);
- uint8_t const dir = tu_edpt_dir(p_endpoint_desc->bEndpointAddress);
- uint8_t xfrtype = 0;
- struct usb_epdesc_s epdesc;
-
- if (epnum >= CXD56_EPNUM)
- {
- return false;
- }
-
- switch (p_endpoint_desc->bmAttributes.xfer)
- {
- case 1:
- xfrtype = USB_EP_ATTR_XFER_ISOC;
- break;
- case 2:
- xfrtype = USB_EP_ATTR_XFER_BULK;
- break;
- case 3:
- xfrtype = USB_EP_ATTR_XFER_INT;
- break;
- }
-
- usbdcd_driver.ep[epnum] = DEV_ALLOCEP(usbdev, epnum, dir == TUSB_DIR_IN, xfrtype);
- if (usbdcd_driver.ep[epnum] == NULL)
- {
- return false;
- }
-
- usbdcd_driver.req[epnum] = NULL;
- usbdcd_driver.req[epnum] = EP_ALLOCREQ(usbdcd_driver.ep[epnum]);
- if (usbdcd_driver.req[epnum] != NULL)
- {
- usbdcd_driver.req[epnum]->len = p_endpoint_desc->wMaxPacketSize.size;
- }
- else
- {
- return false;
- }
-
- usbdcd_driver.req[epnum]->callback = usbdcd_ep0incomplete;
-
- epdesc.len = p_endpoint_desc->bLength;
- epdesc.type = p_endpoint_desc->bDescriptorType;
- epdesc.addr = p_endpoint_desc->bEndpointAddress;
- epdesc.attr = xfrtype;
- epdesc.mxpacketsize[0] = LSBYTE(p_endpoint_desc->wMaxPacketSize.size);
- epdesc.mxpacketsize[1] = MSBYTE(p_endpoint_desc->wMaxPacketSize.size);
- epdesc.interval = p_endpoint_desc->bInterval;
-
- if (EP_CONFIGURE(usbdcd_driver.ep[epnum], &epdesc, false) < 0)
- {
- return false;
- }
-
- return true;
-}
-
-bool dcd_edpt_xfer(uint8_t rhport, uint8_t ep_addr, uint8_t *buffer, uint16_t total_bytes)
-{
- (void) rhport;
-
- bool ret = true;
- uint8_t epnum = tu_edpt_number(ep_addr);
-
- if (epnum >= CXD56_EPNUM)
- {
- return false;
- }
-
- if (epnum == 0)
- {
- if (total_bytes == 0)
- {
- usbdcd_driver.setup_processed = true;
- dcd_event_xfer_complete(0, ep_addr, 0, XFER_RESULT_SUCCESS, false);
- }
- else if (ep_addr == 0x00 && total_bytes == usbdcd_driver.outlen)
- {
- memcpy(buffer, usbdcd_driver.dataout, usbdcd_driver.outlen);
- dcd_event_xfer_complete(0, ep_addr, total_bytes, XFER_RESULT_SUCCESS, false);
- usbdcd_driver.outlen = 0;
- }
- else
- {
- usbdcd_driver.req[epnum]->len = total_bytes;
- usbdcd_driver.req[epnum]->priv = (void *)((uint32_t)ep_addr);
- usbdcd_driver.req[epnum]->flags = total_bytes < usbdcd_driver.ep[epnum]->maxpacket ? USBDEV_REQFLAGS_NULLPKT : 0;
- usbdcd_driver.req[epnum]->buf = buffer;
-
- if (EP_SUBMIT(usbdcd_driver.ep[epnum], usbdcd_driver.req[epnum]) < 0)
- {
- ret = false;
- }
- }
-
- struct usb_ctrlreq_s ctrl;
-
- if (usbdcd_driver.setup_processed)
- {
- if (osal_queue_receive(usbdcd_driver.setup_queue, &ctrl))
- {
- usbdcd_driver.setup_processed = false;
- dcd_event_setup_received(0, (uint8_t *)&ctrl, false);
- }
- }
- }
- else
- {
- usbdcd_driver.req[epnum]->len = total_bytes;
- usbdcd_driver.req[epnum]->priv = (void *)((uint32_t)ep_addr);
- usbdcd_driver.req[epnum]->flags = total_bytes < usbdcd_driver.ep[epnum]->maxpacket ? USBDEV_REQFLAGS_NULLPKT : 0;
- usbdcd_driver.req[epnum]->buf = buffer;
-
- if (EP_SUBMIT(usbdcd_driver.ep[epnum], usbdcd_driver.req[epnum]) < 0)
- {
- ret = false;
- }
- }
-
- return ret;
-}
-
-void dcd_edpt_stall(uint8_t rhport, uint8_t ep_addr)
-{
- (void) rhport;
-
- uint8_t epnum = tu_edpt_number(ep_addr);
-
- if (epnum >= CXD56_EPNUM)
- {
- return;
- }
-
- EP_STALL(usbdcd_driver.ep[epnum]);
-}
-
-void dcd_edpt_clear_stall(uint8_t rhport, uint8_t ep_addr)
-{
- (void) rhport;
-
- uint8_t epnum = tu_edpt_number(ep_addr);
-
- if (epnum >= CXD56_EPNUM)
- {
- return;
- }
-
- EP_RESUME(usbdcd_driver.ep[epnum]);
-}
-
-#endif
diff --git a/tinyusb/src/portable/st/stm32_fsdev/dcd_stm32_fsdev.c b/tinyusb/src/portable/st/stm32_fsdev/dcd_stm32_fsdev.c
deleted file mode 100755
index eeba7204..00000000
--- a/tinyusb/src/portable/st/stm32_fsdev/dcd_stm32_fsdev.c
+++ /dev/null
@@ -1,1129 +0,0 @@
-/*
- * The MIT License (MIT)
- *
- * Copyright (c) 2019 Nathan Conrad
- *
- * Portions:
- * Copyright (c) 2016 STMicroelectronics
- * Copyright (c) 2019 Ha Thach (tinyusb.org)
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- *
- * This file is part of the TinyUSB stack.
- */
-
-/**********************************************
- * This driver has been tested with the following MCUs:
- * - F070, F072, L053, F042F6
- *
- * It also should work with minimal changes for any ST MCU with an "USB A"/"PCD"/"HCD" peripheral. This
- * covers:
- *
- * F04x, F072, F078, 070x6/B 1024 byte buffer
- * F102, F103 512 byte buffer; no internal D+ pull-up (maybe many more changes?)
- * F302xB/C, F303xB/C, F373 512 byte buffer; no internal D+ pull-up
- * F302x6/8, F302xD/E2, F303xD/E 1024 byte buffer; no internal D+ pull-up
- * L0x2, L0x3 1024 byte buffer
- * L1 512 byte buffer
- * L4x2, L4x3 1024 byte buffer
- *
- * To use this driver, you must:
- * - If you are using a device with crystal-less USB, set up the clock recovery system (CRS)
- * - Remap pins to be D+/D- on devices that they are shared (for example: F042Fx)
- * - This is different to the normal "alternate function" GPIO interface, needs to go through SYSCFG->CFGRx register
- * - Enable USB clock; Perhaps use __HAL_RCC_USB_CLK_ENABLE();
- * - (Optionally configure GPIO HAL to tell it the USB driver is using the USB pins)
- * - call tusb_init();
- * - periodically call tusb_task();
- *
- * Assumptions of the driver:
- * - You are not using CAN (it must share the packet buffer)
- * - APB clock is >= 10 MHz
- * - On some boards, series resistors are required, but not on others.
- * - On some boards, D+ pull up resistor (1.5kohm) is required, but not on others.
- * - You don't have long-running interrupts; some USB packets must be quickly responded to.
- * - You have the ST CMSIS library linked into the project. HAL is not used.
- *
- * Current driver limitations (i.e., a list of features for you to add):
- * - STALL handled, but not tested.
- * - Does it work? No clue.
- * - All EP BTABLE buffers are created based on max packet size of first EP opened with that address.
- * - No isochronous endpoints
- * - Endpoint index is the ID of the endpoint
- * - This means that priority is given to endpoints with lower ID numbers
- * - Code is mixing up EP IX with EP ID. Everywhere.
- * - Packet buffer memory is copied in the interrupt.
- * - This is better for performance, but means interrupts are disabled for longer
- * - DMA may be the best choice, but it could also be pushed to the USBD task.
- * - No double-buffering
- * - No DMA
- * - Minimal error handling
- * - Perhaps error interrupts should be reported to the stack, or cause a device reset?
- * - Assumes a single USB peripheral; I think that no hardware has multiple so this is fine.
- * - Add a callback for enabling/disabling the D+ PU on devices without an internal PU.
- * - F3 models use three separate interrupts. I think we could only use the LP interrupt for
- * everything? However, the interrupts are configurable so the DisableInt and EnableInt
- * below functions could be adjusting the wrong interrupts (if they had been reconfigured)
- * - LPM is not used correctly, or at all?
- *
- * USB documentation and Reference implementations
- * - STM32 Reference manuals
- * - STM32 USB Hardware Guidelines AN4879
- *
- * - STM32 HAL (much of this driver is based on this)
- * - libopencm3/lib/stm32/common/st_usbfs_core.c
- * - Keil USB Device http://www.keil.com/pack/doc/mw/USB/html/group__usbd.html
- *
- * - YouTube OpenTechLab 011; https://www.youtube.com/watch?v=4FOkJLp_PUw
- *
- * Advantages over HAL driver:
- * - Tiny (saves RAM, assumes a single USB peripheral)
- *
- * Notes:
- * - The buffer table is allocated as endpoints are opened. The allocation is only
- * cleared when the device is reset. This may be bad if the USB device needs
- * to be reconfigured.
- */
-
-#include "tusb_option.h"
-
-#if defined(STM32F102x6) || defined(STM32F102xB) || \
- defined(STM32F103x6) || defined(STM32F103xB) || \
- defined(STM32F103xE) || defined(STM32F103xG)
-#define STM32F1_FSDEV
-#endif
-
-#if (TUSB_OPT_DEVICE_ENABLED) && ( \
- (CFG_TUSB_MCU == OPT_MCU_STM32F0 ) || \
- (CFG_TUSB_MCU == OPT_MCU_STM32F1 && defined(STM32F1_FSDEV)) || \
- (CFG_TUSB_MCU == OPT_MCU_STM32F3 ) || \
- (CFG_TUSB_MCU == OPT_MCU_STM32L0 ) || \
- (CFG_TUSB_MCU == OPT_MCU_STM32L1 ) \
- )
-
-// In order to reduce the dependance on HAL, we undefine this.
-// Some definitions are copied to our private include file.
-#undef USE_HAL_DRIVER
-
-#include "device/dcd.h"
-#include "portable/st/stm32_fsdev/dcd_stm32_fsdev_pvt_st.h"
-
-
-/*****************************************************
- * Configuration
- *****************************************************/
-
-// HW supports max of 8 bidirectional endpoints, but this can be reduced to save RAM
-// (8u here would mean 8 IN and 8 OUT)
-#ifndef MAX_EP_COUNT
-# define MAX_EP_COUNT 8U
-#endif
-
-// If sharing with CAN, one can set this to be non-zero to give CAN space where it wants it
-// Both of these MUST be a multiple of 2, and are in byte units.
-#ifndef DCD_STM32_BTABLE_BASE
-# define DCD_STM32_BTABLE_BASE 0U
-#endif
-
-#ifndef DCD_STM32_BTABLE_LENGTH
-# define DCD_STM32_BTABLE_LENGTH (PMA_LENGTH - DCD_STM32_BTABLE_BASE)
-#endif
-
-// Since TinyUSB doesn't use SOF for now, and this interrupt too often (1ms interval)
-// We disable SOF for now until needed later on
-#ifndef USE_SOF
-# define USE_SOF 0
-#endif
-
-/***************************************************
- * Checks, structs, defines, function definitions, etc.
- */
-
-TU_VERIFY_STATIC((MAX_EP_COUNT) <= STFSDEV_EP_COUNT, "Only 8 endpoints supported on the hardware");
-
-TU_VERIFY_STATIC(((DCD_STM32_BTABLE_BASE) + (DCD_STM32_BTABLE_LENGTH))<=(PMA_LENGTH),
- "BTABLE does not fit in PMA RAM");
-
-TU_VERIFY_STATIC(((DCD_STM32_BTABLE_BASE) % 8) == 0, "BTABLE base must be aligned to 8 bytes");
-
-// One of these for every EP IN & OUT, uses a bit of RAM....
-typedef struct
-{
- uint8_t * buffer;
- // tu_fifo_t * ff; // TODO support dcd_edpt_xfer_fifo API
- uint16_t total_len;
- uint16_t queued_len;
- uint16_t pma_ptr;
- uint8_t max_packet_size;
- uint8_t pma_alloc_size;
-} xfer_ctl_t;
-
-static xfer_ctl_t xfer_status[MAX_EP_COUNT][2];
-
-static inline xfer_ctl_t* xfer_ctl_ptr(uint32_t epnum, uint32_t dir)
-{
- return &xfer_status[epnum][dir];
-}
-
-static TU_ATTR_ALIGNED(4) uint32_t _setup_packet[6];
-
-static uint8_t remoteWakeCountdown; // When wake is requested
-
-// into the stack.
-static void dcd_handle_bus_reset(void);
-static void dcd_transmit_packet(xfer_ctl_t * xfer, uint16_t ep_ix);
-static void dcd_ep_ctr_handler(void);
-
-// PMA allocation/access
-static uint8_t open_ep_count;
-static uint16_t ep_buf_ptr; ///< Points to first free memory location
-static void dcd_pma_alloc_reset(void);
-static uint16_t dcd_pma_alloc(uint8_t ep_addr, size_t length);
-static void dcd_pma_free(uint8_t ep_addr);
-static bool dcd_write_packet_memory(uint16_t dst, const void *__restrict src, size_t wNBytes);
-static bool dcd_read_packet_memory(void *__restrict dst, uint16_t src, size_t wNBytes);
-
-//static bool dcd_write_packet_memory_ff(tu_fifo_t * ff, uint16_t dst, uint16_t wNBytes);
-//static bool dcd_read_packet_memory_ff(tu_fifo_t * ff, uint16_t src, uint16_t wNBytes);
-
-// Using a function due to better type checks
-// This seems better than having to do type casts everywhere else
-static inline void reg16_clear_bits(__IO uint16_t *reg, uint16_t mask) {
- *reg = (uint16_t)(*reg & ~mask);
-}
-
-// Bits in ISTR are cleared upon writing 0
-static inline void clear_istr_bits(uint16_t mask) {
- USB->ISTR = ~mask;
-}
-
-void dcd_init (uint8_t rhport)
-{
- /* Clocks should already be enabled */
- /* Use __HAL_RCC_USB_CLK_ENABLE(); to enable the clocks before calling this function */
-
- /* The RM mentions to use a special ordering of PDWN and FRES, but this isn't done in HAL.
- * Here, the RM is followed. */
-
- for(uint32_t i = 0; i<200; i++) // should be a few us
- {
- asm("NOP");
- }
- // Perform USB peripheral reset
- USB->CNTR = USB_CNTR_FRES | USB_CNTR_PDWN;
- for(uint32_t i = 0; i<200; i++) // should be a few us
- {
- asm("NOP");
- }
- reg16_clear_bits(&USB->CNTR, USB_CNTR_PDWN);// Remove powerdown
- // Wait startup time, for F042 and F070, this is <= 1 us.
- for(uint32_t i = 0; i<200; i++) // should be a few us
- {
- asm("NOP");
- }
- USB->CNTR = 0; // Enable USB
-
- USB->BTABLE = DCD_STM32_BTABLE_BASE;
-
- USB->ISTR = 0; // Clear pending interrupts
-
- // Reset endpoints to disabled
- for(uint32_t i=0; i<STFSDEV_EP_COUNT; i++)
- {
- // This doesn't clear all bits since some bits are "toggle", but does set the type to DISABLED.
- pcd_set_endpoint(USB,i,0u);
- }
-
- USB->CNTR |= USB_CNTR_RESETM | (USE_SOF ? USB_CNTR_SOFM : 0) | USB_CNTR_ESOFM | USB_CNTR_CTRM | USB_CNTR_SUSPM | USB_CNTR_WKUPM;
- dcd_handle_bus_reset();
-
- // Enable pull-up if supported
- if ( dcd_connect ) dcd_connect(rhport);
-}
-
-// Define only on MCU with internal pull-up. BSP can define on MCU without internal PU.
-#if defined(USB_BCDR_DPPU)
-
-// Disable internal D+ PU
-void dcd_disconnect(uint8_t rhport)
-{
- (void) rhport;
- USB->BCDR &= ~(USB_BCDR_DPPU);
-}
-
-// Enable internal D+ PU
-void dcd_connect(uint8_t rhport)
-{
- (void) rhport;
- USB->BCDR |= USB_BCDR_DPPU;
-}
-
-#elif defined(SYSCFG_PMC_USB_PU) // works e.g. on STM32L151
-// Disable internal D+ PU
-void dcd_disconnect(uint8_t rhport)
-{
- (void) rhport;
- SYSCFG->PMC &= ~(SYSCFG_PMC_USB_PU);
-}
-
-// Enable internal D+ PU
-void dcd_connect(uint8_t rhport)
-{
- (void) rhport;
- SYSCFG->PMC |= SYSCFG_PMC_USB_PU;
-}
-#endif
-
-// Enable device interrupt
-void dcd_int_enable (uint8_t rhport)
-{
- (void)rhport;
- // Member here forces write to RAM before allowing ISR to execute
- __DSB();
- __ISB();
-#if CFG_TUSB_MCU == OPT_MCU_STM32F0 || CFG_TUSB_MCU == OPT_MCU_STM32L0
- NVIC_EnableIRQ(USB_IRQn);
-#elif CFG_TUSB_MCU == OPT_MCU_STM32L1
- NVIC_EnableIRQ(USB_LP_IRQn);
-#elif CFG_TUSB_MCU == OPT_MCU_STM32F3
- // Some STM32F302/F303 devices allow to remap the USB interrupt vectors from
- // shared USB/CAN IRQs to separate CAN and USB IRQs.
- // This dynamically checks if this remap is active to enable the right IRQs.
- #ifdef SYSCFG_CFGR1_USB_IT_RMP
- if (SYSCFG->CFGR1 & SYSCFG_CFGR1_USB_IT_RMP)
- {
- NVIC_EnableIRQ(USB_HP_IRQn);
- NVIC_EnableIRQ(USB_LP_IRQn);
- NVIC_EnableIRQ(USBWakeUp_RMP_IRQn);
- }
- else
- #endif
- {
- NVIC_EnableIRQ(USB_HP_CAN_TX_IRQn);
- NVIC_EnableIRQ(USB_LP_CAN_RX0_IRQn);
- NVIC_EnableIRQ(USBWakeUp_IRQn);
- }
-#elif CFG_TUSB_MCU == OPT_MCU_STM32F1
- NVIC_EnableIRQ(USB_HP_CAN1_TX_IRQn);
- NVIC_EnableIRQ(USB_LP_CAN1_RX0_IRQn);
- NVIC_EnableIRQ(USBWakeUp_IRQn);
-#else
- #error Unknown arch in USB driver
-#endif
-}
-
-// Disable device interrupt
-void dcd_int_disable(uint8_t rhport)
-{
- (void)rhport;
-
-#if CFG_TUSB_MCU == OPT_MCU_STM32F0 || CFG_TUSB_MCU == OPT_MCU_STM32L0
- NVIC_DisableIRQ(USB_IRQn);
-#elif CFG_TUSB_MCU == OPT_MCU_STM32L1
- NVIC_DisableIRQ(USB_LP_IRQn);
-#elif CFG_TUSB_MCU == OPT_MCU_STM32F3
- // Some STM32F302/F303 devices allow to remap the USB interrupt vectors from
- // shared USB/CAN IRQs to separate CAN and USB IRQs.
- // This dynamically checks if this remap is active to disable the right IRQs.
- #ifdef SYSCFG_CFGR1_USB_IT_RMP
- if (SYSCFG->CFGR1 & SYSCFG_CFGR1_USB_IT_RMP)
- {
- NVIC_DisableIRQ(USB_HP_IRQn);
- NVIC_DisableIRQ(USB_LP_IRQn);
- NVIC_DisableIRQ(USBWakeUp_RMP_IRQn);
- }
- else
- #endif
- {
- NVIC_DisableIRQ(USB_HP_CAN_TX_IRQn);
- NVIC_DisableIRQ(USB_LP_CAN_RX0_IRQn);
- NVIC_DisableIRQ(USBWakeUp_IRQn);
- }
-#elif CFG_TUSB_MCU == OPT_MCU_STM32F1
- NVIC_DisableIRQ(USB_HP_CAN1_TX_IRQn);
- NVIC_DisableIRQ(USB_LP_CAN1_RX0_IRQn);
- NVIC_DisableIRQ(USBWakeUp_IRQn);
-#else
- #error Unknown arch in USB driver
-#endif
-
- // CMSIS has a membar after disabling interrupts
-}
-
-// Receive Set Address request, mcu port must also include status IN response
-void dcd_set_address(uint8_t rhport, uint8_t dev_addr)
-{
- (void) rhport;
- (void) dev_addr;
-
- // Respond with status
- dcd_edpt_xfer(rhport, tu_edpt_addr(0, TUSB_DIR_IN), NULL, 0);
-
- // DCD can only set address after status for this request is complete.
- // do it at dcd_edpt0_status_complete()
-}
-
-void dcd_remote_wakeup(uint8_t rhport)
-{
- (void) rhport;
-
- USB->CNTR |= (uint16_t) USB_CNTR_RESUME;
- remoteWakeCountdown = 4u; // required to be 1 to 15 ms, ESOF should trigger every 1ms.
-}
-
-static const tusb_desc_endpoint_t ep0OUT_desc =
-{
- .bLength = sizeof(tusb_desc_endpoint_t),
- .bDescriptorType = TUSB_DESC_ENDPOINT,
-
- .bEndpointAddress = 0x00,
- .bmAttributes = { .xfer = TUSB_XFER_CONTROL },
- .wMaxPacketSize = { .size = CFG_TUD_ENDPOINT0_SIZE },
- .bInterval = 0
-};
-
-static const tusb_desc_endpoint_t ep0IN_desc =
-{
- .bLength = sizeof(tusb_desc_endpoint_t),
- .bDescriptorType = TUSB_DESC_ENDPOINT,
-
- .bEndpointAddress = 0x80,
- .bmAttributes = { .xfer = TUSB_XFER_CONTROL },
- .wMaxPacketSize = { .size = CFG_TUD_ENDPOINT0_SIZE },
- .bInterval = 0
-};
-
-static void dcd_handle_bus_reset(void)
-{
- //__IO uint16_t * const epreg = &(EPREG(0));
- USB->DADDR = 0u; // disable USB peripheral by clearing the EF flag
-
- // Clear all EPREG (or maybe this is automatic? I'm not sure)
- for(uint32_t i=0; i<STFSDEV_EP_COUNT; i++)
- {
- pcd_set_endpoint(USB,i,0u);
- }
-
- dcd_pma_alloc_reset();
- dcd_edpt_open (0, &ep0OUT_desc);
- dcd_edpt_open (0, &ep0IN_desc);
-
- USB->DADDR = USB_DADDR_EF; // Set enable flag, and leaving the device address as zero.
-}
-
-// Handle CTR interrupt for the TX/IN direction
-//
-// Upon call, (wIstr & USB_ISTR_DIR) == 0U
-static void dcd_ep_ctr_tx_handler(uint32_t wIstr)
-{
- uint32_t EPindex = wIstr & USB_ISTR_EP_ID;
- uint32_t wEPRegVal = pcd_get_endpoint(USB, EPindex);
-
- // Verify the CTR_TX bit is set. This was in the ST Micro code,
- // but I'm not sure it's actually necessary?
- if((wEPRegVal & USB_EP_CTR_TX) == 0U)
- {
- return;
- }
-
- /* clear int flag */
- pcd_clear_tx_ep_ctr(USB, EPindex);
-
- xfer_ctl_t * xfer = xfer_ctl_ptr(EPindex,TUSB_DIR_IN);
- if((xfer->total_len != xfer->queued_len)) /* TX not complete */
- {
- dcd_transmit_packet(xfer, EPindex);
- }
- else /* TX Complete */
- {
- dcd_event_xfer_complete(0, (uint8_t)(0x80 + EPindex), xfer->total_len, XFER_RESULT_SUCCESS, true);
- }
-}
-
-// Handle CTR interrupt for the RX/OUT direction
-//
-// Upon call, (wIstr & USB_ISTR_DIR) == 0U
-static void dcd_ep_ctr_rx_handler(uint32_t wIstr)
-{
- uint32_t EPindex = wIstr & USB_ISTR_EP_ID;
- uint32_t wEPRegVal = pcd_get_endpoint(USB, EPindex);
- uint32_t count = pcd_get_ep_rx_cnt(USB,EPindex);
-
- xfer_ctl_t *xfer = xfer_ctl_ptr(EPindex,TUSB_DIR_OUT);
-
- // Verify the CTR_RX bit is set. This was in the ST Micro code,
- // but I'm not sure it's actually necessary?
- if((wEPRegVal & USB_EP_CTR_RX) == 0U)
- {
- return;
- }
-
- if((EPindex == 0U) && ((wEPRegVal & USB_EP_SETUP) != 0U)) /* Setup packet */
- {
- // The setup_received function uses memcpy, so this must first copy the setup data into
- // user memory, to allow for the 32-bit access that memcpy performs.
- uint8_t userMemBuf[8];
- /* Get SETUP Packet*/
- if(count == 8) // Setup packet should always be 8 bytes. If not, ignore it, and try again.
- {
- // Must reset EP to NAK (in case it had been stalling) (though, maybe too late here)
- pcd_set_ep_rx_status(USB,0u,USB_EP_RX_NAK);
- pcd_set_ep_tx_status(USB,0u,USB_EP_TX_NAK);
- dcd_read_packet_memory(userMemBuf, *pcd_ep_rx_address_ptr(USB,EPindex), 8);
- dcd_event_setup_received(0, (uint8_t*)userMemBuf, true);
- }
- }
- else
- {
- // Clear RX CTR interrupt flag
- if(EPindex != 0u)
- {
- pcd_clear_rx_ep_ctr(USB, EPindex);
- }
-
- if (count != 0U)
- {
-#if 0 // TODO support dcd_edpt_xfer_fifo API
- if (xfer->ff)
- {
- dcd_read_packet_memory_ff(xfer->ff, *pcd_ep_rx_address_ptr(USB,EPindex), count);
- }
- else
-#endif
- {
- dcd_read_packet_memory(&(xfer->buffer[xfer->queued_len]), *pcd_ep_rx_address_ptr(USB,EPindex), count);
- }
-
- xfer->queued_len = (uint16_t)(xfer->queued_len + count);
- }
-
- if ((count < xfer->max_packet_size) || (xfer->queued_len == xfer->total_len))
- {
- /* RX COMPLETE */
- dcd_event_xfer_complete(0, EPindex, xfer->queued_len, XFER_RESULT_SUCCESS, true);
- // Though the host could still send, we don't know.
- // Does the bulk pipe need to be reset to valid to allow for a ZLP?
- }
- else
- {
- uint32_t remaining = (uint32_t)xfer->total_len - (uint32_t)xfer->queued_len;
- if(remaining >= xfer->max_packet_size) {
- pcd_set_ep_rx_cnt(USB, EPindex,xfer->max_packet_size);
- } else {
- pcd_set_ep_rx_cnt(USB, EPindex,remaining);
- }
- pcd_set_ep_rx_status(USB, EPindex, USB_EP_RX_VALID);
- }
- }
-
- // For EP0, prepare to receive another SETUP packet.
- // Clear CTR last so that a new packet does not overwrite the packing being read.
- // (Based on the docs, it seems SETUP will always be accepted after CTR is cleared)
- if(EPindex == 0u)
- {
- // Always be prepared for a status packet...
- pcd_set_ep_rx_cnt(USB, EPindex, CFG_TUD_ENDPOINT0_SIZE);
- pcd_clear_rx_ep_ctr(USB, EPindex);
- }
-}
-
-static void dcd_ep_ctr_handler(void)
-{
- uint32_t wIstr;
-
- /* stay in loop while pending interrupts */
- while (((wIstr = USB->ISTR) & USB_ISTR_CTR) != 0U)
- {
-
- if ((wIstr & USB_ISTR_DIR) == 0U) /* TX/IN */
- {
- dcd_ep_ctr_tx_handler(wIstr);
- }
- else /* RX/OUT*/
- {
- dcd_ep_ctr_rx_handler(wIstr);
- }
- }
-}
-
-void dcd_int_handler(uint8_t rhport) {
-
- (void) rhport;
-
- uint32_t int_status = USB->ISTR;
- //const uint32_t handled_ints = USB_ISTR_CTR | USB_ISTR_RESET | USB_ISTR_WKUP
- // | USB_ISTR_SUSP | USB_ISTR_SOF | USB_ISTR_ESOF;
- // unused IRQs: (USB_ISTR_PMAOVR | USB_ISTR_ERR | USB_ISTR_L1REQ )
-
- // The ST driver loops here on the CTR bit, but that loop has been moved into the
- // dcd_ep_ctr_handler(), so less need to loop here. The other interrupts shouldn't
- // be triggered repeatedly.
-
- if(int_status & USB_ISTR_RESET) {
- // USBRST is start of reset.
- clear_istr_bits(USB_ISTR_RESET);
- dcd_handle_bus_reset();
- dcd_event_bus_reset(0, TUSB_SPEED_FULL, true);
- return; // Don't do the rest of the things here; perhaps they've been cleared?
- }
-
- if (int_status & USB_ISTR_CTR)
- {
- /* servicing of the endpoint correct transfer interrupt */
- /* clear of the CTR flag into the sub */
- dcd_ep_ctr_handler();
- }
-
- if (int_status & USB_ISTR_WKUP)
- {
- reg16_clear_bits(&USB->CNTR, USB_CNTR_LPMODE);
- reg16_clear_bits(&USB->CNTR, USB_CNTR_FSUSP);
- clear_istr_bits(USB_ISTR_WKUP);
- dcd_event_bus_signal(0, DCD_EVENT_RESUME, true);
- }
-
- if (int_status & USB_ISTR_SUSP)
- {
- /* Suspend is asserted for both suspend and unplug events. without Vbus monitoring,
- * these events cannot be differentiated, so we only trigger suspend. */
-
- /* Force low-power mode in the macrocell */
- USB->CNTR |= USB_CNTR_FSUSP;
- USB->CNTR |= USB_CNTR_LPMODE;
-
- /* clear of the ISTR bit must be done after setting of CNTR_FSUSP */
- clear_istr_bits(USB_ISTR_SUSP);
- dcd_event_bus_signal(0, DCD_EVENT_SUSPEND, true);
- }
-
-#if USE_SOF
- if(int_status & USB_ISTR_SOF) {
- clear_istr_bits(USB_ISTR_SOF);
- dcd_event_bus_signal(0, DCD_EVENT_SOF, true);
- }
-#endif
-
- if(int_status & USB_ISTR_ESOF) {
- if(remoteWakeCountdown == 1u)
- {
- USB->CNTR &= (uint16_t)(~USB_CNTR_RESUME);
- }
- if(remoteWakeCountdown > 0u)
- {
- remoteWakeCountdown--;
- }
- clear_istr_bits(USB_ISTR_ESOF);
- }
-}
-
-//--------------------------------------------------------------------+
-// Endpoint API
-//--------------------------------------------------------------------+
-
-// Invoked when a control transfer's status stage is complete.
-// May help DCD to prepare for next control transfer, this API is optional.
-void dcd_edpt0_status_complete(uint8_t rhport, tusb_control_request_t const * request)
-{
- (void) rhport;
-
- if (request->bmRequestType_bit.recipient == TUSB_REQ_RCPT_DEVICE &&
- request->bmRequestType_bit.type == TUSB_REQ_TYPE_STANDARD &&
- request->bRequest == TUSB_REQ_SET_ADDRESS )
- {
- uint8_t const dev_addr = (uint8_t) request->wValue;
-
- // Setting new address after the whole request is complete
- reg16_clear_bits(&USB->DADDR, USB_DADDR_ADD);
- USB->DADDR = (uint16_t)(USB->DADDR | dev_addr); // leave the enable bit set
- }
-}
-
-static void dcd_pma_alloc_reset(void)
-{
- ep_buf_ptr = DCD_STM32_BTABLE_BASE + 8*MAX_EP_COUNT; // 8 bytes per endpoint (two TX and two RX words, each)
- //TU_LOG2("dcd_pma_alloc_reset()\r\n");
- for(uint32_t i=0; i<MAX_EP_COUNT; i++)
- {
- xfer_ctl_ptr(i,TUSB_DIR_OUT)->pma_alloc_size = 0U;
- xfer_ctl_ptr(i,TUSB_DIR_IN)->pma_alloc_size = 0U;
- xfer_ctl_ptr(i,TUSB_DIR_OUT)->pma_ptr = 0U;
- xfer_ctl_ptr(i,TUSB_DIR_IN)->pma_ptr = 0U;
- }
-}
-
-/***
- * Allocate a section of PMA
- *
- * If the EP number has already been allocated, and the new allocation
- * is larger than the old allocation, then this will fail with a TU_ASSERT.
- * (This is done to simplify the code. More complicated algorithms could be used)
- *
- * During failure, TU_ASSERT is used. If this happens, rework/reallocate memory manually.
- */
-static uint16_t dcd_pma_alloc(uint8_t ep_addr, size_t length)
-{
- uint8_t const epnum = tu_edpt_number(ep_addr);
- uint8_t const dir = tu_edpt_dir(ep_addr);
- xfer_ctl_t* epXferCtl = xfer_ctl_ptr(epnum,dir);
-
- if(epXferCtl->pma_alloc_size != 0U)
- {
- //TU_LOG2("dcd_pma_alloc(%x,%x)=%x (cached)\r\n",ep_addr,length,epXferCtl->pma_ptr);
- // Previously allocated
- TU_ASSERT(length <= epXferCtl->pma_alloc_size, 0xFFFF); // Verify no larger than previous alloc
- return epXferCtl->pma_ptr;
- }
-
- uint16_t addr = ep_buf_ptr;
- ep_buf_ptr = (uint16_t)(ep_buf_ptr + length); // increment buffer pointer
-
- // Verify no overflow
- TU_ASSERT(ep_buf_ptr <= PMA_LENGTH, 0xFFFF);
-
- epXferCtl->pma_ptr = addr;
- epXferCtl->pma_alloc_size = length;
- //TU_LOG2("dcd_pma_alloc(%x,%x)=%x\r\n",ep_addr,length,addr);
-
- return addr;
-}
-
-/***
- * Free a block of PMA space
- */
-static void dcd_pma_free(uint8_t ep_addr)
-{
- uint8_t const epnum = tu_edpt_number(ep_addr);
- uint8_t const dir = tu_edpt_dir(ep_addr);
-
- // Presently, this should never be called for EP0 IN/OUT
- TU_ASSERT(open_ep_count > 2, /**/);
- TU_ASSERT(xfer_ctl_ptr(epnum,dir)->max_packet_size != 0, /**/);
- open_ep_count--;
-
- // If count is 2, only EP0 should be open, so allocations can be mostly reset.
-
- if(open_ep_count == 2)
- {
- ep_buf_ptr = DCD_STM32_BTABLE_BASE + 8*MAX_EP_COUNT + 2*CFG_TUD_ENDPOINT0_SIZE; // 8 bytes per endpoint (two TX and two RX words, each), and EP0
-
- // Skip EP0
- for(uint32_t i=1; i<MAX_EP_COUNT; i++)
- {
- xfer_ctl_ptr(i,TUSB_DIR_OUT)->pma_alloc_size = 0U;
- xfer_ctl_ptr(i,TUSB_DIR_IN)->pma_alloc_size = 0U;
- xfer_ctl_ptr(i,TUSB_DIR_OUT)->pma_ptr = 0U;
- xfer_ctl_ptr(i,TUSB_DIR_IN)->pma_ptr = 0U;
- }
- }
-}
-
-// The STM32F0 doesn't seem to like |= or &= to manipulate the EP#R registers,
-// so I'm using the #define from HAL here, instead.
-
-bool dcd_edpt_open (uint8_t rhport, tusb_desc_endpoint_t const * p_endpoint_desc)
-{
- (void)rhport;
- uint8_t const epnum = tu_edpt_number(p_endpoint_desc->bEndpointAddress);
- uint8_t const dir = tu_edpt_dir(p_endpoint_desc->bEndpointAddress);
- const uint16_t epMaxPktSize = p_endpoint_desc->wMaxPacketSize.size;
- uint16_t pma_addr;
- uint32_t wType;
-
- // Isochronous not supported (yet), and some other driver assumptions.
- TU_ASSERT(p_endpoint_desc->bmAttributes.xfer != TUSB_XFER_ISOCHRONOUS);
- TU_ASSERT(epnum < MAX_EP_COUNT);
-
- // Set type
- switch(p_endpoint_desc->bmAttributes.xfer) {
- case TUSB_XFER_CONTROL:
- wType = USB_EP_CONTROL;
- break;
-#if (0)
- case TUSB_XFER_ISOCHRONOUS: // FIXME: Not yet supported
- wType = USB_EP_ISOCHRONOUS;
- break;
-#endif
-
- case TUSB_XFER_BULK:
- wType = USB_EP_CONTROL;
- break;
-
- case TUSB_XFER_INTERRUPT:
- wType = USB_EP_INTERRUPT;
- break;
-
- default:
- TU_ASSERT(false);
- }
-
- pcd_set_eptype(USB, epnum, wType);
- pcd_set_ep_address(USB, epnum, epnum);
- // Be normal, for now, instead of only accepting zero-byte packets (on control endpoint)
- // or being double-buffered (bulk endpoints)
- pcd_clear_ep_kind(USB,0);
-
- pma_addr = dcd_pma_alloc(p_endpoint_desc->bEndpointAddress, p_endpoint_desc->wMaxPacketSize.size);
-
- if(dir == TUSB_DIR_IN)
- {
- *pcd_ep_tx_address_ptr(USB, epnum) = pma_addr;
- pcd_set_ep_tx_cnt(USB, epnum, p_endpoint_desc->wMaxPacketSize.size);
- pcd_clear_tx_dtog(USB, epnum);
- pcd_set_ep_tx_status(USB,epnum,USB_EP_TX_NAK);
- }
- else
- {
- *pcd_ep_rx_address_ptr(USB, epnum) = pma_addr;
- pcd_set_ep_rx_cnt(USB, epnum, p_endpoint_desc->wMaxPacketSize.size);
- pcd_clear_rx_dtog(USB, epnum);
- pcd_set_ep_rx_status(USB, epnum, USB_EP_RX_NAK);
- }
-
- xfer_ctl_ptr(epnum, dir)->max_packet_size = epMaxPktSize;
-
- return true;
-}
-
-/**
- * Close an endpoint.
- *
- * This function may be called with interrupts enabled or disabled.
- *
- * This also clears transfers in progress, should there be any.
- */
-void dcd_edpt_close (uint8_t rhport, uint8_t ep_addr)
-{
- (void)rhport;
- uint32_t const epnum = tu_edpt_number(ep_addr);
- uint32_t const dir = tu_edpt_dir(ep_addr);
-
- if(dir == TUSB_DIR_IN)
- {
- pcd_set_ep_tx_status(USB,epnum,USB_EP_TX_DIS);
- }
- else
- {
- pcd_set_ep_rx_status(USB, epnum, USB_EP_RX_DIS);
- }
-
- dcd_pma_free(ep_addr);
-}
-
-// Currently, single-buffered, and only 64 bytes at a time (max)
-
-static void dcd_transmit_packet(xfer_ctl_t * xfer, uint16_t ep_ix)
-{
- uint16_t len = (uint16_t)(xfer->total_len - xfer->queued_len);
-
- if(len > xfer->max_packet_size) // max packet size for FS transfer
- {
- len = xfer->max_packet_size;
- }
- uint16_t oldAddr = *pcd_ep_tx_address_ptr(USB,ep_ix);
-
-#if 0 // TODO support dcd_edpt_xfer_fifo API
- if (xfer->ff)
- {
- dcd_write_packet_memory_ff(xfer->ff, oldAddr, len);
- }
- else
-#endif
- {
- dcd_write_packet_memory(oldAddr, &(xfer->buffer[xfer->queued_len]), len);
- }
- xfer->queued_len = (uint16_t)(xfer->queued_len + len);
-
- pcd_set_ep_tx_cnt(USB,ep_ix,len);
- pcd_set_ep_tx_status(USB, ep_ix, USB_EP_TX_VALID);
-}
-
-bool dcd_edpt_xfer (uint8_t rhport, uint8_t ep_addr, uint8_t * buffer, uint16_t total_bytes)
-{
- (void) rhport;
-
- uint8_t const epnum = tu_edpt_number(ep_addr);
- uint8_t const dir = tu_edpt_dir(ep_addr);
-
- xfer_ctl_t * xfer = xfer_ctl_ptr(epnum,dir);
-
- xfer->buffer = buffer;
- // xfer->ff = NULL; // TODO support dcd_edpt_xfer_fifo API
- xfer->total_len = total_bytes;
- xfer->queued_len = 0;
-
- if ( dir == TUSB_DIR_OUT )
- {
- // A setup token can occur immediately after an OUT STATUS packet so make sure we have a valid
- // buffer for the control endpoint.
- if (epnum == 0 && buffer == NULL)
- {
- xfer->buffer = (uint8_t*)_setup_packet;
- }
- if(total_bytes > xfer->max_packet_size)
- {
- pcd_set_ep_rx_cnt(USB,epnum,xfer->max_packet_size);
- } else {
- pcd_set_ep_rx_cnt(USB,epnum,total_bytes);
- }
- pcd_set_ep_rx_status(USB, epnum, USB_EP_RX_VALID);
- }
- else // IN
- {
- dcd_transmit_packet(xfer,epnum);
- }
- return true;
-}
-
-#if 0 // TODO support dcd_edpt_xfer_fifo API
-bool dcd_edpt_xfer_fifo (uint8_t rhport, uint8_t ep_addr, tu_fifo_t * ff, uint16_t total_bytes)
-{
- (void) rhport;
-
- uint8_t const epnum = tu_edpt_number(ep_addr);
- uint8_t const dir = tu_edpt_dir(ep_addr);
-
- xfer_ctl_t * xfer = xfer_ctl_ptr(epnum,dir);
-
- xfer->buffer = NULL;
- // xfer->ff = ff; // TODO support dcd_edpt_xfer_fifo API
- xfer->total_len = total_bytes;
- xfer->queued_len = 0;
-
- if ( dir == TUSB_DIR_OUT )
- {
- if(total_bytes > xfer->max_packet_size)
- {
- pcd_set_ep_rx_cnt(USB,epnum,xfer->max_packet_size);
- } else {
- pcd_set_ep_rx_cnt(USB,epnum,total_bytes);
- }
- pcd_set_ep_rx_status(USB, epnum, USB_EP_RX_VALID);
- }
- else // IN
- {
- dcd_transmit_packet(xfer,epnum);
- }
- return true;
-}
-#endif
-
-void dcd_edpt_stall (uint8_t rhport, uint8_t ep_addr)
-{
- (void)rhport;
-
- if (ep_addr & 0x80)
- { // IN
- pcd_set_ep_tx_status(USB, ep_addr & 0x7F, USB_EP_TX_STALL);
- }
- else
- { // OUT
- pcd_set_ep_rx_status(USB, ep_addr, USB_EP_RX_STALL);
- }
-}
-
-void dcd_edpt_clear_stall (uint8_t rhport, uint8_t ep_addr)
-{
- (void)rhport;
-
- if (ep_addr & 0x80)
- { // IN
- ep_addr &= 0x7F;
-
- pcd_set_ep_tx_status(USB,ep_addr, USB_EP_TX_NAK);
-
- /* Reset to DATA0 if clearing stall condition. */
- pcd_clear_tx_dtog(USB,ep_addr);
- }
- else
- { // OUT
- /* Reset to DATA0 if clearing stall condition. */
- pcd_clear_rx_dtog(USB,ep_addr);
-
- pcd_set_ep_rx_status(USB,ep_addr, USB_EP_RX_NAK);
- }
-}
-
-// Packet buffer access can only be 8- or 16-bit.
-/**
- * @brief Copy a buffer from user memory area to packet memory area (PMA).
- * This uses byte-access for user memory (so support non-aligned buffers)
- * and 16-bit access for packet memory.
- * @param dst, byte address in PMA; must be 16-bit aligned
- * @param src pointer to user memory area.
- * @param wPMABufAddr address into PMA.
- * @param wNBytes no. of bytes to be copied.
- * @retval None
- */
-static bool dcd_write_packet_memory(uint16_t dst, const void *__restrict src, size_t wNBytes)
-{
- uint32_t n = ((uint32_t)wNBytes + 1U) >> 1U;
- uint32_t i;
- uint16_t temp1, temp2;
- const uint8_t * srcVal;
-
- // The GCC optimizer will combine access to 32-bit sizes if we let it. Force
- // it volatile so that it won't do that.
- __IO uint16_t *pdwVal;
-
- srcVal = src;
- pdwVal = &pma[PMA_STRIDE*(dst>>1)];
-
- for (i = n; i != 0; i--)
- {
- temp1 = (uint16_t) *srcVal;
- srcVal++;
- temp2 = temp1 | ((uint16_t)((uint16_t) ((*srcVal) << 8U))) ;
- *pdwVal = temp2;
- pdwVal += PMA_STRIDE;
- srcVal++;
- }
- return true;
-}
-
-#if 0 // TODO support dcd_edpt_xfer_fifo API
-/**
- * @brief Copy from FIFO to packet memory area (PMA).
- * Uses byte-access of system memory and 16-bit access of packet memory
- * @param wNBytes no. of bytes to be copied.
- * @retval None
- */
-
-// THIS FUNCTION IS UNTESTED
-
-static bool dcd_write_packet_memory_ff(tu_fifo_t * ff, uint16_t dst, uint16_t wNBytes)
-{
- // Since we copy from a ring buffer FIFO, a wrap might occur making it necessary to conduct two copies
- // Check for first linear part
- void * src;
- uint16_t len = tu_fifo_get_linear_read_info(ff, 0, &src, wNBytes); // We want to read from the FIFO - THIS FUNCTION CHANGED!!!
- TU_VERIFY(len && dcd_write_packet_memory(dst, src, len)); // and write it into the PMA
- tu_fifo_advance_read_pointer(ff, len);
-
- // Check for wrapped part
- if (len < wNBytes)
- {
- // Get remaining wrapped length
- uint16_t len2 = tu_fifo_get_linear_read_info(ff, 0, &src, wNBytes - len);
- TU_VERIFY(len2);
-
- // Update destination pointer
- dst += len;
-
- // Since PMA is accessed 16-bit wise we need to handle the case when a 16 bit value was split
- if (len % 2) // If len is uneven there is a byte left to copy
- {
- // Since PMA can accessed only 16 bit-wise we copy the last byte again
- tu_fifo_backward_read_pointer(ff, 1); // Move one byte back and copy two bytes for the PMA
- tu_fifo_read_n(ff, (void *) &pma[PMA_STRIDE*(dst>>1)], 2); // Since EP FIFOs must be of item size 1 this is safe to do
- dst++;
- len2--;
- }
-
- TU_VERIFY(dcd_write_packet_memory(dst, src, len2));
- tu_fifo_advance_write_pointer(ff, len2);
- }
-
- return true;
-}
-#endif
-
-/**
- * @brief Copy a buffer from packet memory area (PMA) to user memory area.
- * Uses byte-access of system memory and 16-bit access of packet memory
- * @param wNBytes no. of bytes to be copied.
- * @retval None
- */
-static bool dcd_read_packet_memory(void *__restrict dst, uint16_t src, size_t wNBytes)
-{
- uint32_t n = (uint32_t)wNBytes >> 1U;
- uint32_t i;
- // The GCC optimizer will combine access to 32-bit sizes if we let it. Force
- // it volatile so that it won't do that.
- __IO const uint16_t *pdwVal;
- uint32_t temp;
-
- pdwVal = &pma[PMA_STRIDE*(src>>1)];
- uint8_t *dstVal = (uint8_t*)dst;
-
- for (i = n; i != 0U; i--)
- {
- temp = *pdwVal;
- pdwVal += PMA_STRIDE;
- *dstVal++ = ((temp >> 0) & 0xFF);
- *dstVal++ = ((temp >> 8) & 0xFF);
- }
-
- if (wNBytes % 2)
- {
- temp = *pdwVal;
- pdwVal += PMA_STRIDE;
- *dstVal++ = ((temp >> 0) & 0xFF);
- }
- return true;
-}
-
-#if 0 // TODO support dcd_edpt_xfer_fifo API
-/**
- * @brief Copy a buffer from user packet memory area (PMA) to FIFO.
- * Uses byte-access of system memory and 16-bit access of packet memory
- * @param wNBytes no. of bytes to be copied.
- * @retval None
- */
-
-// THIS FUNCTION IS UNTESTED
-
-static bool dcd_read_packet_memory_ff(tu_fifo_t * ff, uint16_t src, uint16_t wNBytes)
-{
- // Since we copy into a ring buffer FIFO, a wrap might occur making it necessary to conduct two copies
- // Check for first linear part
- void * dst;
- uint16_t len = tu_fifo_get_linear_write_info(ff, 0, &dst, wNBytes); // THIS FUNCTION CHANGED!!!!
- TU_VERIFY(len && dcd_read_packet_memory(dst, src, len));
- tu_fifo_advance_write_pointer(ff, len);
-
- // Check for wrapped part
- if (len < wNBytes)
- {
- // Get remaining wrapped length
- uint16_t len2 = tu_fifo_get_linear_write_info(ff, 0, &dst, wNBytes - len);
- TU_VERIFY(len2);
-
- // Update source pointer
- src += len;
-
- // Since PMA is accessed 16-bit wise we need to handle the case when a 16 bit value was split
- if (len % 2) // If len is uneven there is a byte left to copy
- {
- uint32_t temp = pma[PMA_STRIDE*(src>>1)];
- *((uint8_t *)dst++) = ((temp >> 8) & 0xFF);
- src++;
- len2--;
- }
-
- TU_VERIFY(dcd_read_packet_memory(dst, src, len2));
- tu_fifo_advance_write_pointer(ff, len2);
- }
-
- return true;
-}
-
-#endif
-
-#endif
-
diff --git a/tinyusb/src/portable/st/stm32_fsdev/dcd_stm32_fsdev_pvt_st.h b/tinyusb/src/portable/st/stm32_fsdev/dcd_stm32_fsdev_pvt_st.h
deleted file mode 100755
index eca8bf57..00000000
--- a/tinyusb/src/portable/st/stm32_fsdev/dcd_stm32_fsdev_pvt_st.h
+++ /dev/null
@@ -1,411 +0,0 @@
-/**
- ******************************************************************************
- * @file dcd_stm32f0_pvt_st.h
- * @brief DCD utilities from ST code
- ******************************************************************************
- * @attention
- *
- * <h2><center>&copy; COPYRIGHT(c) 2016 STMicroelectronics</center></h2>
- * <h2><center>&copy; parts COPYRIGHT(c) N Conrad</center></h2>
- *
- * Redistribution and use in source and binary forms, with or without modification,
- * are permitted provided that the following conditions are met:
- * 1. Redistributions of source code must retain the above copyright notice,
- * this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright notice,
- * this list of conditions and the following disclaimer in the documentation
- * and/or other materials provided with the distribution.
- * 3. Neither the name of STMicroelectronics nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
- * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
- * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
- * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- **********/
-
-// This file contains source copied from ST's HAL, and thus should have their copyright statement.
-
-// PMA_LENGTH is PMA buffer size in bytes.
-// On 512-byte devices, access with a stride of two words (use every other 16-bit address)
-// On 1024-byte devices, access with a stride of one word (use every 16-bit address)
-
-#ifndef PORTABLE_ST_STM32F0_DCD_STM32F0_FSDEV_PVT_ST_H_
-#define PORTABLE_ST_STM32F0_DCD_STM32F0_FSDEV_PVT_ST_H_
-
-#if defined(STM32F042x6) || \
- defined(STM32F070x6) || defined(STM32F070xB) || \
- defined(STM32F072xB) || \
- defined(STM32F078xx)
- #include "stm32f0xx.h"
- #define PMA_LENGTH (1024u)
- // F0x2 models are crystal-less
- // All have internal D+ pull-up
- // 070RB: 2 x 16 bits/word memory LPM Support, BCD Support
- // PMA dedicated to USB (no sharing with CAN)
-
-#elif defined(STM32F1_FSDEV)
- #include "stm32f1xx.h"
- #define PMA_LENGTH (512u)
- // NO internal Pull-ups
- // *B, and *C: 2 x 16 bits/word
-
- // F1 names this differently from the rest
- #define USB_CNTR_LPMODE USB_CNTR_LP_MODE
-
-#elif defined(STM32F302xB) || defined(STM32F302xC) || \
- defined(STM32F303xB) || defined(STM32F303xC) || \
- defined(STM32F373xC)
- #include "stm32f3xx.h"
- #define PMA_LENGTH (512u)
- // NO internal Pull-ups
- // *B, and *C: 1 x 16 bits/word
- // PMA dedicated to USB (no sharing with CAN)
-
-#elif defined(STM32F302x6) || defined(STM32F302x8) || \
- defined(STM32F302xD) || defined(STM32F302xE) || \
- defined(STM32F303xD) || defined(STM32F303xE)
- #include "stm32f3xx.h"
- #define PMA_LENGTH (1024u)
- // NO internal Pull-ups
- // *6, *8, *D, and *E: 2 x 16 bits/word LPM Support
- // When CAN clock is enabled, USB can use first 768 bytes ONLY.
-
-#elif CFG_TUSB_MCU == OPT_MCU_STM32L0
- #include "stm32l0xx.h"
- #define PMA_LENGTH (1024u)
-
-#elif CFG_TUSB_MCU == OPT_MCU_STM32L1
- #include "stm32l1xx.h"
- #define PMA_LENGTH (512u)
-
-#else
- #error You are using an untested or unimplemented STM32 variant. Please update the driver.
- // This includes L1x0, L1x1, L1x2, L4x2 and L4x3, G1x1, G1x3, and G1x4
-#endif
-
-// For purposes of accessing the packet
-#if ((PMA_LENGTH) == 512u)
- #define PMA_STRIDE (2u)
-#elif ((PMA_LENGTH) == 1024u)
- #define PMA_STRIDE (1u)
-#endif
-
-// And for type-safety create a new macro for the volatile address of PMAADDR
-// The compiler should warn us if we cast it to a non-volatile type?
-// Volatile is also needed to prevent the optimizer from changing access to 32-bit (as 32-bit access is forbidden)
-static __IO uint16_t * const pma = (__IO uint16_t*)USB_PMAADDR;
-
-// prototypes
-static inline __IO uint16_t* pcd_ep_rx_cnt_ptr(USB_TypeDef * USBx, uint32_t bEpNum);
-static inline __IO uint16_t* pcd_ep_tx_cnt_ptr(USB_TypeDef * USBx, uint32_t bEpNum);
-static inline void pcd_set_endpoint(USB_TypeDef * USBx, uint32_t bEpNum, uint32_t wRegValue);
-
-
-/* SetENDPOINT */
-static inline void pcd_set_endpoint(USB_TypeDef * USBx, uint32_t bEpNum, uint32_t wRegValue)
-{
- __O uint16_t *reg = (__O uint16_t *)((&USBx->EP0R) + bEpNum*2u);
- *reg = (uint16_t)wRegValue;
-}
-
-/* GetENDPOINT */
-static inline uint16_t pcd_get_endpoint(USB_TypeDef * USBx, uint32_t bEpNum) {
- __I uint16_t *reg = (__I uint16_t *)((&USBx->EP0R) + bEpNum*2u);
- return *reg;
-}
-
-static inline void pcd_set_eptype(USB_TypeDef * USBx, uint32_t bEpNum, uint32_t wType)
-{
- uint32_t regVal = pcd_get_endpoint(USBx, bEpNum);
- regVal &= (uint32_t)USB_EP_T_MASK;
- regVal |= wType;
- regVal |= USB_EP_CTR_RX | USB_EP_CTR_TX; // These clear on write0, so must set high
- pcd_set_endpoint(USBx, bEpNum, regVal);
-}
-
-static inline uint32_t pcd_get_eptype(USB_TypeDef * USBx, uint32_t bEpNum)
-{
- uint32_t regVal = pcd_get_endpoint(USBx, bEpNum);
- regVal &= USB_EP_T_FIELD;
- return regVal;
-}
-/**
- * @brief Clears bit CTR_RX / CTR_TX in the endpoint register.
- * @param USBx USB peripheral instance register address.
- * @param bEpNum Endpoint Number.
- * @retval None
- */
-static inline void pcd_clear_rx_ep_ctr(USB_TypeDef * USBx, uint32_t bEpNum)
-{
- uint32_t regVal = pcd_get_endpoint(USBx, bEpNum);
- regVal &= USB_EPREG_MASK;
- regVal &= ~USB_EP_CTR_RX;
- regVal |= USB_EP_CTR_TX; // preserve CTR_TX (clears on writing 0)
- pcd_set_endpoint(USBx, bEpNum, regVal);
-}
-static inline void pcd_clear_tx_ep_ctr(USB_TypeDef * USBx, uint32_t bEpNum)
-{
- uint32_t regVal = pcd_get_endpoint(USBx, bEpNum);
- regVal &= USB_EPREG_MASK;
- regVal &= ~USB_EP_CTR_TX;
- regVal |= USB_EP_CTR_RX; // preserve CTR_RX (clears on writing 0)
- pcd_set_endpoint(USBx, bEpNum,regVal);
-}
-/**
- * @brief gets counter of the tx buffer.
- * @param USBx USB peripheral instance register address.
- * @param bEpNum Endpoint Number.
- * @retval Counter value
- */
-static inline uint32_t pcd_get_ep_tx_cnt(USB_TypeDef * USBx, uint32_t bEpNum)
-{
- __I uint16_t *regPtr = pcd_ep_tx_cnt_ptr(USBx, bEpNum);
- return *regPtr & 0x3ffU;
-}
-
-static inline uint32_t pcd_get_ep_rx_cnt(USB_TypeDef * USBx, uint32_t bEpNum)
-{
- __I uint16_t *regPtr = pcd_ep_rx_cnt_ptr(USBx, bEpNum);
- return *regPtr & 0x3ffU;
-}
-
-/**
- * @brief Sets counter of rx buffer with no. of blocks.
- * @param dwReg Register
- * @param wCount Counter.
- * @param wNBlocks no. of Blocks.
- * @retval None
- */
-
-static inline void pcd_set_ep_cnt_rx_reg(__O uint16_t * pdwReg, size_t wCount) {
- uint32_t wNBlocks;
- if(wCount > 62u)
- {
- wNBlocks = wCount >> 5u;
- if((wCount & 0x1fU) == 0u)
- {
- wNBlocks--;
- }
- wNBlocks = wNBlocks << 10u;
- wNBlocks |= 0x8000u; // Mark block size as 32byte
- *pdwReg = (uint16_t)wNBlocks;
- }
- else
- {
- wNBlocks = wCount >> 1u;
- if((wCount & 0x1U) != 0u)
- {
- wNBlocks++;
- }
- *pdwReg = (uint16_t)((wNBlocks) << 10u);
- }
-}
-
-
-/**
- * @brief Sets address in an endpoint register.
- * @param USBx USB peripheral instance register address.
- * @param bEpNum Endpoint Number.
- * @param bAddr Address.
- * @retval None
- */
-static inline void pcd_set_ep_address(USB_TypeDef * USBx, uint32_t bEpNum, uint32_t bAddr)
-{
- uint32_t regVal = pcd_get_endpoint(USBx, bEpNum);
- regVal &= USB_EPREG_MASK;
- regVal |= bAddr;
- regVal |= USB_EP_CTR_RX|USB_EP_CTR_TX;
- pcd_set_endpoint(USBx, bEpNum,regVal);
-}
-
-static inline __IO uint16_t * pcd_btable_word_ptr(USB_TypeDef * USBx, size_t x)
-{
- size_t total_word_offset = (((USBx)->BTABLE)>>1) + x;
- total_word_offset *= PMA_STRIDE;
- return &(pma[total_word_offset]);
-}
-
-// Pointers to the PMA table entries (using the ARM address space)
-static inline __IO uint16_t* pcd_ep_tx_address_ptr(USB_TypeDef * USBx, uint32_t bEpNum)
-{
- return pcd_btable_word_ptr(USBx,(bEpNum)*4u + 0u);
-}
-static inline __IO uint16_t* pcd_ep_tx_cnt_ptr(USB_TypeDef * USBx, uint32_t bEpNum)
-{
- return pcd_btable_word_ptr(USBx,(bEpNum)*4u + 1u);
-}
-
-static inline __IO uint16_t* pcd_ep_rx_address_ptr(USB_TypeDef * USBx, uint32_t bEpNum)
-{
- return pcd_btable_word_ptr(USBx,(bEpNum)*4u + 2u);
-}
-
-static inline __IO uint16_t* pcd_ep_rx_cnt_ptr(USB_TypeDef * USBx, uint32_t bEpNum)
-{
- return pcd_btable_word_ptr(USBx,(bEpNum)*4u + 3u);
-}
-
-static inline void pcd_set_ep_tx_cnt(USB_TypeDef * USBx, uint32_t bEpNum, uint32_t wCount)
-{
- *pcd_ep_tx_cnt_ptr(USBx, bEpNum) = (uint16_t)wCount;
-}
-
-static inline void pcd_set_ep_rx_cnt(USB_TypeDef * USBx, uint32_t bEpNum, uint32_t wCount)
-{
- __IO uint16_t *pdwReg = pcd_ep_rx_cnt_ptr((USBx),(bEpNum));
- pcd_set_ep_cnt_rx_reg(pdwReg, wCount);
-}
-
-/**
- * @brief sets the status for tx transfer (bits STAT_TX[1:0]).
- * @param USBx USB peripheral instance register address.
- * @param bEpNum Endpoint Number.
- * @param wState new state
- * @retval None
- */
-static inline void pcd_set_ep_tx_status(USB_TypeDef * USBx, uint32_t bEpNum, uint32_t wState)
-{
- uint32_t regVal = pcd_get_endpoint(USBx, bEpNum);
- regVal &= USB_EPTX_DTOGMASK;
-
- /* toggle first bit ? */
- if((USB_EPTX_DTOG1 & (wState))!= 0U)
- {
- regVal ^= USB_EPTX_DTOG1;
- }
- /* toggle second bit ? */
- if((USB_EPTX_DTOG2 & ((uint32_t)(wState)))!= 0U)
- {
- regVal ^= USB_EPTX_DTOG2;
- }
- regVal |= USB_EP_CTR_RX|USB_EP_CTR_TX;
- pcd_set_endpoint(USBx, bEpNum, regVal);
-} /* pcd_set_ep_tx_status */
-
-/**
- * @brief sets the status for rx transfer (bits STAT_TX[1:0])
- * @param USBx USB peripheral instance register address.
- * @param bEpNum Endpoint Number.
- * @param wState new state
- * @retval None
- */
-
-static inline void pcd_set_ep_rx_status(USB_TypeDef * USBx, uint32_t bEpNum, uint32_t wState)
-{
- uint32_t regVal = pcd_get_endpoint(USBx, bEpNum);
- regVal &= USB_EPRX_DTOGMASK;
-
- /* toggle first bit ? */
- if((USB_EPRX_DTOG1 & wState)!= 0U)
- {
- regVal ^= USB_EPRX_DTOG1;
- }
- /* toggle second bit ? */
- if((USB_EPRX_DTOG2 & wState)!= 0U)
- {
- regVal ^= USB_EPRX_DTOG2;
- }
- regVal |= USB_EP_CTR_RX|USB_EP_CTR_TX;
- pcd_set_endpoint(USBx, bEpNum, regVal);
-} /* pcd_set_ep_rx_status */
-
-static inline uint32_t pcd_get_ep_rx_status(USB_TypeDef * USBx, uint32_t bEpNum)
-{
- uint32_t regVal = pcd_get_endpoint(USBx, bEpNum);
- return (regVal & USB_EPRX_STAT) >> (12u);
-} /* pcd_get_ep_rx_status */
-
-
-/**
- * @brief Toggles DTOG_RX / DTOG_TX bit in the endpoint register.
- * @param USBx USB peripheral instance register address.
- * @param bEpNum Endpoint Number.
- * @retval None
- */
-static inline void pcd_rx_dtog(USB_TypeDef * USBx, uint32_t bEpNum)
-{
- uint32_t regVal = pcd_get_endpoint(USBx, bEpNum);
- regVal &= USB_EPREG_MASK;
- regVal |= USB_EP_CTR_RX|USB_EP_CTR_TX|USB_EP_DTOG_RX;
- pcd_set_endpoint(USBx, bEpNum, regVal);
-}
-
-static inline void pcd_tx_dtog(USB_TypeDef * USBx, uint32_t bEpNum)
-{
- uint32_t regVal = pcd_get_endpoint(USBx, bEpNum);
- regVal &= USB_EPREG_MASK;
- regVal |= USB_EP_CTR_RX|USB_EP_CTR_TX|USB_EP_DTOG_TX;
- pcd_set_endpoint(USBx, bEpNum, regVal);
-}
-
-/**
- * @brief Clears DTOG_RX / DTOG_TX bit in the endpoint register.
- * @param USBx USB peripheral instance register address.
- * @param bEpNum Endpoint Number.
- * @retval None
- */
-
-static inline void pcd_clear_rx_dtog(USB_TypeDef * USBx, uint32_t bEpNum)
-{
- uint32_t regVal = pcd_get_endpoint(USBx, bEpNum);
- if((regVal & USB_EP_DTOG_RX) != 0)
- {
- pcd_rx_dtog(USBx,bEpNum);
- }
-}
-
-static inline void pcd_clear_tx_dtog(USB_TypeDef * USBx, uint32_t bEpNum)
-{
- uint32_t regVal = pcd_get_endpoint(USBx, bEpNum);
- if((regVal & USB_EP_DTOG_TX) != 0)
- {
- pcd_tx_dtog(USBx,bEpNum);
- }
-}
-
-/**
- * @brief set & clear EP_KIND bit.
- * @param USBx USB peripheral instance register address.
- * @param bEpNum Endpoint Number.
- * @retval None
- */
-
-static inline void pcd_set_ep_kind(USB_TypeDef * USBx, uint32_t bEpNum)
-{
- uint32_t regVal = pcd_get_endpoint(USBx, bEpNum);
- regVal |= USB_EP_KIND;
- regVal &= USB_EPREG_MASK;
- regVal |= USB_EP_CTR_RX|USB_EP_CTR_TX;
- pcd_set_endpoint(USBx, bEpNum, regVal);
-}
-static inline void pcd_clear_ep_kind(USB_TypeDef * USBx, uint32_t bEpNum)
-{
- uint32_t regVal = pcd_get_endpoint(USBx, bEpNum);
- regVal &= USB_EPKIND_MASK;
- regVal |= USB_EP_CTR_RX|USB_EP_CTR_TX;
- pcd_set_endpoint(USBx, bEpNum, regVal);
-}
-
-// This checks if the device has "LPM"
-#if defined(USB_ISTR_L1REQ)
-#define USB_ISTR_L1REQ_FORCED (USB_ISTR_L1REQ)
-#else
-#define USB_ISTR_L1REQ_FORCED ((uint16_t)0x0000U)
-#endif
-
-#define USB_ISTR_ALL_EVENTS (USB_ISTR_PMAOVR | USB_ISTR_ERR | USB_ISTR_WKUP | USB_ISTR_SUSP | \
- USB_ISTR_RESET | USB_ISTR_SOF | USB_ISTR_ESOF | USB_ISTR_L1REQ_FORCED )
-
-// Number of endpoints in hardware
-#define STFSDEV_EP_COUNT (8u)
-
-#endif /* PORTABLE_ST_STM32F0_DCD_STM32F0_FSDEV_PVT_ST_H_ */
diff --git a/tinyusb/src/portable/st/synopsys/dcd_synopsys.c b/tinyusb/src/portable/st/synopsys/dcd_synopsys.c
deleted file mode 100755
index 8a998aa3..00000000
--- a/tinyusb/src/portable/st/synopsys/dcd_synopsys.c
+++ /dev/null
@@ -1,1186 +0,0 @@
-/*
- * The MIT License (MIT)
- *
- * Copyright (c) 2018 Scott Shawcroft, 2019 William D. Jones for Adafruit Industries
- * Copyright (c) 2019 Ha Thach (tinyusb.org)
- * Copyright (c) 2020 Jan Duempelmann
- * Copyright (c) 2020 Reinhard Panhuber
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- *
- * This file is part of the TinyUSB stack.
- */
-
-#include "tusb_option.h"
-
-// Since TinyUSB doesn't use SOF for now, and this interrupt too often (1ms interval)
-// We disable SOF for now until needed later on
-#define USE_SOF 0
-
-#if defined (STM32F105x8) || defined (STM32F105xB) || defined (STM32F105xC) || \
- defined (STM32F107xB) || defined (STM32F107xC)
-#define STM32F1_SYNOPSYS
-#endif
-
-#if defined (STM32L475xx) || defined (STM32L476xx) || \
- defined (STM32L485xx) || defined (STM32L486xx) || defined (STM32L496xx) || \
- defined (STM32L4R5xx) || defined (STM32L4R7xx) || defined (STM32L4R9xx) || \
- defined (STM32L4S5xx) || defined (STM32L4S7xx) || defined (STM32L4S9xx)
-#define STM32L4_SYNOPSYS
-#endif
-
-#if TUSB_OPT_DEVICE_ENABLED && \
- ( (CFG_TUSB_MCU == OPT_MCU_STM32F1 && defined(STM32F1_SYNOPSYS)) || \
- CFG_TUSB_MCU == OPT_MCU_STM32F2 || \
- CFG_TUSB_MCU == OPT_MCU_STM32F4 || \
- CFG_TUSB_MCU == OPT_MCU_STM32F7 || \
- CFG_TUSB_MCU == OPT_MCU_STM32H7 || \
- (CFG_TUSB_MCU == OPT_MCU_STM32L4 && defined(STM32L4_SYNOPSYS) || \
- CFG_TUSB_MCU == OPT_MCU_GD32VF103 ) \
- )
-
-// EP_MAX : Max number of bi-directional endpoints including EP0
-// EP_FIFO_SIZE : Size of dedicated USB SRAM
-#if CFG_TUSB_MCU == OPT_MCU_STM32F1
-#include "stm32f1xx.h"
-#define EP_MAX_FS 4
-#define EP_FIFO_SIZE_FS 1280
-
-#elif CFG_TUSB_MCU == OPT_MCU_STM32F2
-#include "stm32f2xx.h"
-#define EP_MAX_FS USB_OTG_FS_MAX_IN_ENDPOINTS
-#define EP_FIFO_SIZE_FS USB_OTG_FS_TOTAL_FIFO_SIZE
-
-#elif CFG_TUSB_MCU == OPT_MCU_STM32F4
-#include "stm32f4xx.h"
-#define EP_MAX_FS USB_OTG_FS_MAX_IN_ENDPOINTS
-#define EP_FIFO_SIZE_FS USB_OTG_FS_TOTAL_FIFO_SIZE
-#define EP_MAX_HS USB_OTG_HS_MAX_IN_ENDPOINTS
-#define EP_FIFO_SIZE_HS USB_OTG_HS_TOTAL_FIFO_SIZE
-
-#elif CFG_TUSB_MCU == OPT_MCU_STM32H7
-#include "stm32h7xx.h"
-#define EP_MAX_FS 9
-#define EP_FIFO_SIZE_FS 4096
-#define EP_MAX_HS 9
-#define EP_FIFO_SIZE_HS 4096
-
-#elif CFG_TUSB_MCU == OPT_MCU_STM32F7
-#include "stm32f7xx.h"
-#define EP_MAX_FS 6
-#define EP_FIFO_SIZE_FS 1280
-#define EP_MAX_HS 9
-#define EP_FIFO_SIZE_HS 4096
-
-#elif CFG_TUSB_MCU == OPT_MCU_STM32L4
-#include "stm32l4xx.h"
-#define EP_MAX_FS 6
-#define EP_FIFO_SIZE_FS 1280
-
-#elif CFG_TUSB_MCU == OPT_MCU_GD32VF103
-#include "synopsys_common.h"
-
-// These numbers are the same for the whole GD32VF103 family.
-#define OTG_FS_IRQn 86
-#define EP_MAX_FS 4
-#define EP_FIFO_SIZE_FS 1280
-
-// The GD32VF103 is a RISC-V MCU, which implements the ECLIC Core-Local
-// Interrupt Controller by Nuclei. It is nearly API compatible to the
-// NVIC used by ARM MCUs.
-#define ECLIC_INTERRUPT_ENABLE_BASE 0xD2001001UL
-
-#define NVIC_EnableIRQ __eclic_enable_interrupt
-#define NVIC_DisableIRQ __eclic_disable_interrupt
-
-static inline void __eclic_enable_interrupt (uint32_t irq) {
- *(volatile uint8_t*)(ECLIC_INTERRUPT_ENABLE_BASE + (irq * 4)) = 1;
-}
-
-static inline void __eclic_disable_interrupt (uint32_t irq){
- *(volatile uint8_t*)(ECLIC_INTERRUPT_ENABLE_BASE + (irq * 4)) = 0;
-}
-
-#else
-#error "Unsupported MCUs"
-#endif
-
-#include "device/dcd.h"
-
-//--------------------------------------------------------------------+
-// MACRO TYPEDEF CONSTANT ENUM
-//--------------------------------------------------------------------+
-
-// On STM32 we associate Port0 to OTG_FS, and Port1 to OTG_HS
-#if TUD_OPT_RHPORT == 0
-#define EP_MAX EP_MAX_FS
-#define EP_FIFO_SIZE EP_FIFO_SIZE_FS
-#define RHPORT_REGS_BASE USB_OTG_FS_PERIPH_BASE
-#define RHPORT_IRQn OTG_FS_IRQn
-
-#else
-#define EP_MAX EP_MAX_HS
-#define EP_FIFO_SIZE EP_FIFO_SIZE_HS
-#define RHPORT_REGS_BASE USB_OTG_HS_PERIPH_BASE
-#define RHPORT_IRQn OTG_HS_IRQn
-
-#endif
-
-#define GLOBAL_BASE(_port) ((USB_OTG_GlobalTypeDef*) RHPORT_REGS_BASE)
-#define DEVICE_BASE(_port) (USB_OTG_DeviceTypeDef *) (RHPORT_REGS_BASE + USB_OTG_DEVICE_BASE)
-#define OUT_EP_BASE(_port) (USB_OTG_OUTEndpointTypeDef *) (RHPORT_REGS_BASE + USB_OTG_OUT_ENDPOINT_BASE)
-#define IN_EP_BASE(_port) (USB_OTG_INEndpointTypeDef *) (RHPORT_REGS_BASE + USB_OTG_IN_ENDPOINT_BASE)
-#define FIFO_BASE(_port, _x) ((volatile uint32_t *) (RHPORT_REGS_BASE + USB_OTG_FIFO_BASE + (_x) * USB_OTG_FIFO_SIZE))
-
-enum
-{
- DCD_HIGH_SPEED = 0, // Highspeed mode
- DCD_FULL_SPEED_USE_HS = 1, // Full speed in Highspeed port (probably with internal PHY)
- DCD_FULL_SPEED = 3, // Full speed with internal PHY
-};
-
-static TU_ATTR_ALIGNED(4) uint32_t _setup_packet[2];
-
-typedef struct {
- uint8_t * buffer;
- tu_fifo_t * ff;
- uint16_t total_len;
- uint16_t max_size;
- uint8_t interval;
-} xfer_ctl_t;
-
-typedef volatile uint32_t * usb_fifo_t;
-
-xfer_ctl_t xfer_status[EP_MAX][2];
-#define XFER_CTL_BASE(_ep, _dir) &xfer_status[_ep][_dir]
-
-// EP0 transfers are limited to 1 packet - larger sizes has to be split
-static uint16_t ep0_pending[2]; // Index determines direction as tusb_dir_t type
-
-// TX FIFO RAM allocation so far in words - RX FIFO size is readily available from usb_otg->GRXFSIZ
-static uint16_t _allocated_fifo_words_tx; // TX FIFO size in words (IN EPs)
-static bool _out_ep_closed; // Flag to check if RX FIFO size needs an update (reduce its size)
-
-// Calculate the RX FIFO size according to recommendations from reference manual
-static inline uint16_t calc_rx_ff_size(uint16_t ep_size)
-{
- return 15 + 2*(ep_size/4) + 2*EP_MAX;
-}
-
-static void update_grxfsiz(uint8_t rhport)
-{
- (void) rhport;
-
- USB_OTG_GlobalTypeDef * usb_otg = GLOBAL_BASE(rhport);
-
- // Determine largest EP size for RX FIFO
- uint16_t max_epsize = 0;
- for (uint8_t epnum = 0; epnum < EP_MAX; epnum++)
- {
- max_epsize = tu_max16(max_epsize, xfer_status[epnum][TUSB_DIR_OUT].max_size);
- }
-
- // Update size of RX FIFO
- usb_otg->GRXFSIZ = calc_rx_ff_size(max_epsize);
-}
-
-// Setup the control endpoint 0.
-static void bus_reset(uint8_t rhport)
-{
- (void) rhport;
-
- USB_OTG_GlobalTypeDef * usb_otg = GLOBAL_BASE(rhport);
- USB_OTG_DeviceTypeDef * dev = DEVICE_BASE(rhport);
- USB_OTG_OUTEndpointTypeDef * out_ep = OUT_EP_BASE(rhport);
- USB_OTG_INEndpointTypeDef * in_ep = IN_EP_BASE(rhport);
-
- tu_memclr(xfer_status, sizeof(xfer_status));
- _out_ep_closed = false;
-
- for(uint8_t n = 0; n < EP_MAX; n++) {
- out_ep[n].DOEPCTL |= USB_OTG_DOEPCTL_SNAK;
- }
-
- // clear device address
- dev->DCFG &= ~USB_OTG_DCFG_DAD_Msk;
-
- // TODO should probably assign value when reset rather than OR
- dev->DAINTMSK |= (1 << USB_OTG_DAINTMSK_OEPM_Pos) | (1 << USB_OTG_DAINTMSK_IEPM_Pos);
- dev->DOEPMSK |= USB_OTG_DOEPMSK_STUPM | USB_OTG_DOEPMSK_XFRCM;
- dev->DIEPMSK |= USB_OTG_DIEPMSK_TOM | USB_OTG_DIEPMSK_XFRCM;
-
- // "USB Data FIFOs" section in reference manual
- // Peripheral FIFO architecture
- //
- // The FIFO is split up in a lower part where the RX FIFO is located and an upper part where the TX FIFOs start.
- // We do this to allow the RX FIFO to grow dynamically which is possible since the free space is located
- // between the RX and TX FIFOs. This is required by ISO OUT EPs which need a bigger FIFO than the standard
- // configuration done below.
- //
- // Dynamically FIFO sizes are of interest only for ISO EPs since all others are usually not opened and closed.
- // All EPs other than ISO are opened as soon as the driver starts up i.e. when the host sends a
- // configure interface command. Hence, all IN EPs other the ISO will be located at the top. IN ISO EPs are usually
- // opened when the host sends an additional command: setInterface. At this point in time
- // the ISO EP will be located next to the free space and can change its size. In case more IN EPs change its size
- // an additional memory
- //
- // --------------- 320 or 1024 ( 1280 or 4096 bytes )
- // | IN FIFO 0 |
- // --------------- (320 or 1024) - 16
- // | IN FIFO 1 |
- // --------------- (320 or 1024) - 16 - x
- // | . . . . |
- // --------------- (320 or 1024) - 16 - x - y - ... - z
- // | IN FIFO MAX |
- // ---------------
- // | FREE |
- // --------------- GRXFSIZ
- // | OUT FIFO |
- // | ( Shared ) |
- // --------------- 0
- //
- // According to "FIFO RAM allocation" section in RM, FIFO RAM are allocated as follows (each word 32-bits):
- // - Each EP IN needs at least max packet size, 16 words is sufficient for EP0 IN
- //
- // - All EP OUT shared a unique OUT FIFO which uses
- // - 13 for setup packets + control words (up to 3 setup packets).
- // - 1 for global NAK (not required/used here).
- // - Largest-EPsize / 4 + 1. ( FS: 64 bytes, HS: 512 bytes). Recommended is "2 x (Largest-EPsize/4) + 1"
- // - 2 for each used OUT endpoint
- //
- // Therefore GRXFSIZ = 13 + 1 + 1 + 2 x (Largest-EPsize/4) + 2 x EPOUTnum
- // - FullSpeed (64 Bytes ): GRXFSIZ = 15 + 2 x 16 + 2 x EP_MAX = 47 + 2 x EP_MAX
- // - Highspeed (512 bytes): GRXFSIZ = 15 + 2 x 128 + 2 x EP_MAX = 271 + 2 x EP_MAX
- //
- // NOTE: Largest-EPsize & EPOUTnum is actual used endpoints in configuration. Since DCD has no knowledge
- // of the overall picture yet. We will use the worst scenario: largest possible + EP_MAX
- //
- // For Isochronous, largest EP size can be 1023/1024 for FS/HS respectively. In addition if multiple ISO
- // are enabled at least "2 x (Largest-EPsize/4) + 1" are recommended. Maybe provide a macro for application to
- // overwrite this.
-
- usb_otg->GRXFSIZ = calc_rx_ff_size(TUD_OPT_HIGH_SPEED ? 512 : 64);
-
- _allocated_fifo_words_tx = 16;
-
- // Control IN uses FIFO 0 with 64 bytes ( 16 32-bit word )
- usb_otg->DIEPTXF0_HNPTXFSIZ = (16 << USB_OTG_TX0FD_Pos) | (EP_FIFO_SIZE/4 - _allocated_fifo_words_tx);
-
- // Fixed control EP0 size to 64 bytes
- in_ep[0].DIEPCTL &= ~(0x03 << USB_OTG_DIEPCTL_MPSIZ_Pos);
- xfer_status[0][TUSB_DIR_OUT].max_size = xfer_status[0][TUSB_DIR_IN].max_size = 64;
-
- out_ep[0].DOEPTSIZ |= (3 << USB_OTG_DOEPTSIZ_STUPCNT_Pos);
-
- usb_otg->GINTMSK |= USB_OTG_GINTMSK_OEPINT | USB_OTG_GINTMSK_IEPINT;
-}
-
-// Set turn-around timeout according to link speed
-extern uint32_t SystemCoreClock;
-static void set_turnaround(USB_OTG_GlobalTypeDef * usb_otg, tusb_speed_t speed)
-{
- usb_otg->GUSBCFG &= ~USB_OTG_GUSBCFG_TRDT;
-
- if ( speed == TUSB_SPEED_HIGH )
- {
- // Use fixed 0x09 for Highspeed
- usb_otg->GUSBCFG |= (0x09 << USB_OTG_GUSBCFG_TRDT_Pos);
- }
- else
- {
- // Turnaround timeout depends on the MCU clock
- uint32_t turnaround;
-
- TU_LOG_INT(2, SystemCoreClock);
-
- if ( SystemCoreClock >= 32000000U )
- turnaround = 0x6U;
- else if ( SystemCoreClock >= 27500000U )
- turnaround = 0x7U;
- else if ( SystemCoreClock >= 24000000U )
- turnaround = 0x8U;
- else if ( SystemCoreClock >= 21800000U )
- turnaround = 0x9U;
- else if ( SystemCoreClock >= 20000000U )
- turnaround = 0xAU;
- else if ( SystemCoreClock >= 18500000U )
- turnaround = 0xBU;
- else if ( SystemCoreClock >= 17200000U )
- turnaround = 0xCU;
- else if ( SystemCoreClock >= 16000000U )
- turnaround = 0xDU;
- else if ( SystemCoreClock >= 15000000U )
- turnaround = 0xEU;
- else
- turnaround = 0xFU;
-
- // Fullspeed depends on MCU clocks, but we will use 0x06 for 32+ Mhz
- usb_otg->GUSBCFG |= (turnaround << USB_OTG_GUSBCFG_TRDT_Pos);
- }
-}
-
-static tusb_speed_t get_speed(uint8_t rhport)
-{
- (void) rhport;
- USB_OTG_DeviceTypeDef * dev = DEVICE_BASE(rhport);
- uint32_t const enum_spd = (dev->DSTS & USB_OTG_DSTS_ENUMSPD_Msk) >> USB_OTG_DSTS_ENUMSPD_Pos;
- return (enum_spd == DCD_HIGH_SPEED) ? TUSB_SPEED_HIGH : TUSB_SPEED_FULL;
-}
-
-static void set_speed(uint8_t rhport, tusb_speed_t speed)
-{
- uint32_t bitvalue;
-
- if ( rhport == 1 )
- {
- bitvalue = ((TUSB_SPEED_HIGH == speed) ? DCD_HIGH_SPEED : DCD_FULL_SPEED_USE_HS);
- }
- else
- {
- bitvalue = DCD_FULL_SPEED;
- }
-
- USB_OTG_DeviceTypeDef * dev = DEVICE_BASE(rhport);
-
- // Clear and set speed bits
- dev->DCFG &= ~(3 << USB_OTG_DCFG_DSPD_Pos);
- dev->DCFG |= (bitvalue << USB_OTG_DCFG_DSPD_Pos);
-}
-
-#if defined(USB_HS_PHYC)
-static bool USB_HS_PHYCInit(void)
-{
- USB_HS_PHYC_GlobalTypeDef *usb_hs_phyc = (USB_HS_PHYC_GlobalTypeDef*) USB_HS_PHYC_CONTROLLER_BASE;
-
- // Enable LDO
- usb_hs_phyc->USB_HS_PHYC_LDO |= USB_HS_PHYC_LDO_ENABLE;
-
- // Wait until LDO ready
- while ( 0 == (usb_hs_phyc->USB_HS_PHYC_LDO & USB_HS_PHYC_LDO_STATUS) ) {}
-
- uint32_t phyc_pll = 0;
-
- // TODO Try to get HSE_VALUE from registers instead of depending CFLAGS
- switch ( HSE_VALUE )
- {
- case 12000000: phyc_pll = USB_HS_PHYC_PLL1_PLLSEL_12MHZ ; break;
- case 12500000: phyc_pll = USB_HS_PHYC_PLL1_PLLSEL_12_5MHZ ; break;
- case 16000000: phyc_pll = USB_HS_PHYC_PLL1_PLLSEL_16MHZ ; break;
- case 24000000: phyc_pll = USB_HS_PHYC_PLL1_PLLSEL_24MHZ ; break;
- case 25000000: phyc_pll = USB_HS_PHYC_PLL1_PLLSEL_25MHZ ; break;
- case 32000000: phyc_pll = USB_HS_PHYC_PLL1_PLLSEL_Msk ; break; // Value not defined in header
- default:
- TU_ASSERT(0);
- }
- usb_hs_phyc->USB_HS_PHYC_PLL = phyc_pll;
-
- // Control the tuning interface of the High Speed PHY
- // Use magic value (USB_HS_PHYC_TUNE_VALUE) from ST driver
- usb_hs_phyc->USB_HS_PHYC_TUNE |= 0x00000F13U;
-
- // Enable PLL internal PHY
- usb_hs_phyc->USB_HS_PHYC_PLL |= USB_HS_PHYC_PLL_PLLEN;
-
- // Original ST code has 2 ms delay for PLL stabilization.
- // Primitive test shows that more than 10 USB un/replug cycle showed no error with enumeration
-
- return true;
-}
-#endif
-
-static void edpt_schedule_packets(uint8_t rhport, uint8_t const epnum, uint8_t const dir, uint16_t const num_packets, uint16_t total_bytes)
-{
- (void) rhport;
-
- USB_OTG_DeviceTypeDef * dev = DEVICE_BASE(rhport);
- USB_OTG_OUTEndpointTypeDef * out_ep = OUT_EP_BASE(rhport);
- USB_OTG_INEndpointTypeDef * in_ep = IN_EP_BASE(rhport);
-
- // EP0 is limited to one packet each xfer
- // We use multiple transaction of xfer->max_size length to get a whole transfer done
- if(epnum == 0) {
- xfer_ctl_t * const xfer = XFER_CTL_BASE(epnum, dir);
- total_bytes = tu_min16(ep0_pending[dir], xfer->max_size);
- ep0_pending[dir] -= total_bytes;
- }
-
- // IN and OUT endpoint xfers are interrupt-driven, we just schedule them here.
- if(dir == TUSB_DIR_IN) {
- // A full IN transfer (multiple packets, possibly) triggers XFRC.
- in_ep[epnum].DIEPTSIZ = (num_packets << USB_OTG_DIEPTSIZ_PKTCNT_Pos) |
- ((total_bytes << USB_OTG_DIEPTSIZ_XFRSIZ_Pos) & USB_OTG_DIEPTSIZ_XFRSIZ_Msk);
-
- in_ep[epnum].DIEPCTL |= USB_OTG_DIEPCTL_EPENA | USB_OTG_DIEPCTL_CNAK;
- // For ISO endpoint set correct odd/even bit for next frame.
- if ((in_ep[epnum].DIEPCTL & USB_OTG_DIEPCTL_EPTYP) == USB_OTG_DIEPCTL_EPTYP_0 && (XFER_CTL_BASE(epnum, dir))->interval == 1)
- {
- // Take odd/even bit from frame counter.
- uint32_t const odd_frame_now = (dev->DSTS & (1u << USB_OTG_DSTS_FNSOF_Pos));
- in_ep[epnum].DIEPCTL |= (odd_frame_now ? USB_OTG_DIEPCTL_SD0PID_SEVNFRM_Msk : USB_OTG_DIEPCTL_SODDFRM_Msk);
- }
- // Enable fifo empty interrupt only if there are something to put in the fifo.
- if(total_bytes != 0) {
- dev->DIEPEMPMSK |= (1 << epnum);
- }
- } else {
- // A full OUT transfer (multiple packets, possibly) triggers XFRC.
- out_ep[epnum].DOEPTSIZ &= ~(USB_OTG_DOEPTSIZ_PKTCNT_Msk | USB_OTG_DOEPTSIZ_XFRSIZ);
- out_ep[epnum].DOEPTSIZ |= (num_packets << USB_OTG_DOEPTSIZ_PKTCNT_Pos) |
- ((total_bytes << USB_OTG_DOEPTSIZ_XFRSIZ_Pos) & USB_OTG_DOEPTSIZ_XFRSIZ_Msk);
-
- out_ep[epnum].DOEPCTL |= USB_OTG_DOEPCTL_EPENA | USB_OTG_DOEPCTL_CNAK;
- if ((out_ep[epnum].DOEPCTL & USB_OTG_DOEPCTL_EPTYP) == USB_OTG_DOEPCTL_EPTYP_0 && (XFER_CTL_BASE(epnum, dir))->interval == 1)
- {
- // Take odd/even bit from frame counter.
- uint32_t const odd_frame_now = (dev->DSTS & (1u << USB_OTG_DSTS_FNSOF_Pos));
- out_ep[epnum].DOEPCTL |= (odd_frame_now ? USB_OTG_DOEPCTL_SD0PID_SEVNFRM_Msk : USB_OTG_DOEPCTL_SODDFRM_Msk);
- }
- }
-}
-
-/*------------------------------------------------------------------*/
-/* Controller API
- *------------------------------------------------------------------*/
-void dcd_init (uint8_t rhport)
-{
- // Programming model begins in the last section of the chapter on the USB
- // peripheral in each Reference Manual.
-
- USB_OTG_GlobalTypeDef * usb_otg = GLOBAL_BASE(rhport);
-
- // No HNP/SRP (no OTG support), program timeout later.
- if ( rhport == 1 )
- {
- // On selected MCUs HS port1 can be used with external PHY via ULPI interface
-#if CFG_TUSB_RHPORT1_MODE & OPT_MODE_HIGH_SPEED
- // deactivate internal PHY
- usb_otg->GCCFG &= ~USB_OTG_GCCFG_PWRDWN;
-
- // Init The UTMI Interface
- usb_otg->GUSBCFG &= ~(USB_OTG_GUSBCFG_TSDPS | USB_OTG_GUSBCFG_ULPIFSLS | USB_OTG_GUSBCFG_PHYSEL);
-
- // Select default internal VBUS Indicator and Drive for ULPI
- usb_otg->GUSBCFG &= ~(USB_OTG_GUSBCFG_ULPIEVBUSD | USB_OTG_GUSBCFG_ULPIEVBUSI);
-#else
- usb_otg->GUSBCFG |= USB_OTG_GUSBCFG_PHYSEL;
-#endif
-
-#if defined(USB_HS_PHYC)
- // Highspeed with embedded UTMI PHYC
-
- // Select UTMI Interface
- usb_otg->GUSBCFG &= ~USB_OTG_GUSBCFG_ULPI_UTMI_SEL;
- usb_otg->GCCFG |= USB_OTG_GCCFG_PHYHSEN;
-
- // Enables control of a High Speed USB PHY
- USB_HS_PHYCInit();
-#endif
- } else
- {
- // Enable internal PHY
- usb_otg->GUSBCFG |= USB_OTG_GUSBCFG_PHYSEL;
- }
-
- // Reset core after selecting PHY
- // Wait AHB IDLE, reset then wait until it is cleared
- while ((usb_otg->GRSTCTL & USB_OTG_GRSTCTL_AHBIDL) == 0U) {}
- usb_otg->GRSTCTL |= USB_OTG_GRSTCTL_CSRST;
- while ((usb_otg->GRSTCTL & USB_OTG_GRSTCTL_CSRST) == USB_OTG_GRSTCTL_CSRST) {}
-
- // Restart PHY clock
- *((volatile uint32_t *)(RHPORT_REGS_BASE + USB_OTG_PCGCCTL_BASE)) = 0;
-
- // Clear all interrupts
- usb_otg->GINTSTS |= usb_otg->GINTSTS;
-
- // Required as part of core initialization.
- // TODO: How should mode mismatch be handled? It will cause
- // the core to stop working/require reset.
- usb_otg->GINTMSK |= USB_OTG_GINTMSK_OTGINT | USB_OTG_GINTMSK_MMISM;
-
- USB_OTG_DeviceTypeDef * dev = DEVICE_BASE(rhport);
-
- // If USB host misbehaves during status portion of control xfer
- // (non zero-length packet), send STALL back and discard.
- dev->DCFG |= USB_OTG_DCFG_NZLSOHSK;
-
- set_speed(rhport, TUD_OPT_HIGH_SPEED ? TUSB_SPEED_HIGH : TUSB_SPEED_FULL);
-
- // Enable internal USB transceiver, unless using HS core (port 1) with external PHY.
- if (!(rhport == 1 && (CFG_TUSB_RHPORT1_MODE & OPT_MODE_HIGH_SPEED))) usb_otg->GCCFG |= USB_OTG_GCCFG_PWRDWN;
-
- usb_otg->GINTMSK |= USB_OTG_GINTMSK_USBRST | USB_OTG_GINTMSK_ENUMDNEM |
- USB_OTG_GINTMSK_USBSUSPM | USB_OTG_GINTMSK_WUIM |
- USB_OTG_GINTMSK_RXFLVLM | (USE_SOF ? USB_OTG_GINTMSK_SOFM : 0);
-
- // Enable global interrupt
- usb_otg->GAHBCFG |= USB_OTG_GAHBCFG_GINT;
-
- dcd_connect(rhport);
-}
-
-void dcd_int_enable (uint8_t rhport)
-{
- (void) rhport;
- NVIC_EnableIRQ(RHPORT_IRQn);
-}
-
-void dcd_int_disable (uint8_t rhport)
-{
- (void) rhport;
- NVIC_DisableIRQ(RHPORT_IRQn);
-}
-
-void dcd_set_address (uint8_t rhport, uint8_t dev_addr)
-{
- USB_OTG_DeviceTypeDef * dev = DEVICE_BASE(rhport);
- dev->DCFG = (dev->DCFG & ~USB_OTG_DCFG_DAD_Msk) | (dev_addr << USB_OTG_DCFG_DAD_Pos);
-
- // Response with status after changing device address
- dcd_edpt_xfer(rhport, tu_edpt_addr(0, TUSB_DIR_IN), NULL, 0);
-}
-
-void dcd_remote_wakeup(uint8_t rhport)
-{
- (void) rhport;
-
- // TODO must manually clear this bit after 1-15 ms
- // USB_OTG_DeviceTypeDef * dev = DEVICE_BASE(rhport);
- // dev->DCTL |= USB_OTG_DCTL_RWUSIG;
-}
-
-void dcd_connect(uint8_t rhport)
-{
- (void) rhport;
- USB_OTG_DeviceTypeDef * dev = DEVICE_BASE(rhport);
- dev->DCTL &= ~USB_OTG_DCTL_SDIS;
-}
-
-void dcd_disconnect(uint8_t rhport)
-{
- (void) rhport;
- USB_OTG_DeviceTypeDef * dev = DEVICE_BASE(rhport);
- dev->DCTL |= USB_OTG_DCTL_SDIS;
-}
-
-
-/*------------------------------------------------------------------*/
-/* DCD Endpoint port
- *------------------------------------------------------------------*/
-
-bool dcd_edpt_open (uint8_t rhport, tusb_desc_endpoint_t const * desc_edpt)
-{
- (void) rhport;
-
- USB_OTG_GlobalTypeDef * usb_otg = GLOBAL_BASE(rhport);
- USB_OTG_DeviceTypeDef * dev = DEVICE_BASE(rhport);
- USB_OTG_OUTEndpointTypeDef * out_ep = OUT_EP_BASE(rhport);
- USB_OTG_INEndpointTypeDef * in_ep = IN_EP_BASE(rhport);
-
- uint8_t const epnum = tu_edpt_number(desc_edpt->bEndpointAddress);
- uint8_t const dir = tu_edpt_dir(desc_edpt->bEndpointAddress);
-
- TU_ASSERT(epnum < EP_MAX);
-
- xfer_ctl_t * xfer = XFER_CTL_BASE(epnum, dir);
- xfer->max_size = desc_edpt->wMaxPacketSize.size;
- xfer->interval = desc_edpt->bInterval;
-
- uint16_t const fifo_size = (desc_edpt->wMaxPacketSize.size + 3) / 4; // Round up to next full word
-
- if(dir == TUSB_DIR_OUT)
- {
- // Calculate required size of RX FIFO
- uint16_t const sz = calc_rx_ff_size(4*fifo_size);
-
- // If size_rx needs to be extended check if possible and if so enlarge it
- if (usb_otg->GRXFSIZ < sz)
- {
- TU_ASSERT(sz + _allocated_fifo_words_tx <= EP_FIFO_SIZE/4);
-
- // Enlarge RX FIFO
- usb_otg->GRXFSIZ = sz;
- }
-
- out_ep[epnum].DOEPCTL |= (1 << USB_OTG_DOEPCTL_USBAEP_Pos) |
- (desc_edpt->bmAttributes.xfer << USB_OTG_DOEPCTL_EPTYP_Pos) |
- (desc_edpt->wMaxPacketSize.size << USB_OTG_DOEPCTL_MPSIZ_Pos);
-
- dev->DAINTMSK |= (1 << (USB_OTG_DAINTMSK_OEPM_Pos + epnum));
- }
- else
- {
- // "USB Data FIFOs" section in reference manual
- // Peripheral FIFO architecture
- //
- // --------------- 320 or 1024 ( 1280 or 4096 bytes )
- // | IN FIFO 0 |
- // --------------- (320 or 1024) - 16
- // | IN FIFO 1 |
- // --------------- (320 or 1024) - 16 - x
- // | . . . . |
- // --------------- (320 or 1024) - 16 - x - y - ... - z
- // | IN FIFO MAX |
- // ---------------
- // | FREE |
- // --------------- GRXFSIZ
- // | OUT FIFO |
- // | ( Shared ) |
- // --------------- 0
- //
- // In FIFO is allocated by following rules:
- // - IN EP 1 gets FIFO 1, IN EP "n" gets FIFO "n".
-
- // Check if free space is available
- TU_ASSERT(_allocated_fifo_words_tx + fifo_size + usb_otg->GRXFSIZ <= EP_FIFO_SIZE/4);
-
- _allocated_fifo_words_tx += fifo_size;
-
- TU_LOG(2, " Allocated %u bytes at offset %u", fifo_size*4, EP_FIFO_SIZE-_allocated_fifo_words_tx*4);
-
- // DIEPTXF starts at FIFO #1.
- // Both TXFD and TXSA are in unit of 32-bit words.
- usb_otg->DIEPTXF[epnum - 1] = (fifo_size << USB_OTG_DIEPTXF_INEPTXFD_Pos) | (EP_FIFO_SIZE/4 - _allocated_fifo_words_tx);
-
- in_ep[epnum].DIEPCTL |= (1 << USB_OTG_DIEPCTL_USBAEP_Pos) |
- (epnum << USB_OTG_DIEPCTL_TXFNUM_Pos) |
- (desc_edpt->bmAttributes.xfer << USB_OTG_DIEPCTL_EPTYP_Pos) |
- (desc_edpt->bmAttributes.xfer != TUSB_XFER_ISOCHRONOUS ? USB_OTG_DOEPCTL_SD0PID_SEVNFRM : 0) |
- (desc_edpt->wMaxPacketSize.size << USB_OTG_DIEPCTL_MPSIZ_Pos);
-
- dev->DAINTMSK |= (1 << (USB_OTG_DAINTMSK_IEPM_Pos + epnum));
- }
-
- return true;
-}
-
-bool dcd_edpt_xfer (uint8_t rhport, uint8_t ep_addr, uint8_t * buffer, uint16_t total_bytes)
-{
- uint8_t const epnum = tu_edpt_number(ep_addr);
- uint8_t const dir = tu_edpt_dir(ep_addr);
-
- xfer_ctl_t * xfer = XFER_CTL_BASE(epnum, dir);
- xfer->buffer = buffer;
- xfer->ff = NULL;
- xfer->total_len = total_bytes;
-
- // EP0 can only handle one packet
- if(epnum == 0) {
- ep0_pending[dir] = total_bytes;
- // Schedule the first transaction for EP0 transfer
- edpt_schedule_packets(rhport, epnum, dir, 1, ep0_pending[dir]);
- return true;
- }
-
- uint16_t num_packets = (total_bytes / xfer->max_size);
- uint16_t const short_packet_size = total_bytes % xfer->max_size;
-
- // Zero-size packet is special case.
- if(short_packet_size > 0 || (total_bytes == 0)) {
- num_packets++;
- }
-
- // Schedule packets to be sent within interrupt
- edpt_schedule_packets(rhport, epnum, dir, num_packets, total_bytes);
-
- return true;
-}
-
-// The number of bytes has to be given explicitly to allow more flexible control of how many
-// bytes should be written and second to keep the return value free to give back a boolean
-// success message. If total_bytes is too big, the FIFO will copy only what is available
-// into the USB buffer!
-bool dcd_edpt_xfer_fifo (uint8_t rhport, uint8_t ep_addr, tu_fifo_t * ff, uint16_t total_bytes)
-{
- // USB buffers always work in bytes so to avoid unnecessary divisions we demand item_size = 1
- TU_ASSERT(ff->item_size == 1);
-
- uint8_t const epnum = tu_edpt_number(ep_addr);
- uint8_t const dir = tu_edpt_dir(ep_addr);
-
- xfer_ctl_t * xfer = XFER_CTL_BASE(epnum, dir);
- xfer->buffer = NULL;
- xfer->ff = ff;
- xfer->total_len = total_bytes;
-
- uint16_t num_packets = (total_bytes / xfer->max_size);
- uint16_t const short_packet_size = total_bytes % xfer->max_size;
-
- // Zero-size packet is special case.
- if(short_packet_size > 0 || (total_bytes == 0)) num_packets++;
-
- // Schedule packets to be sent within interrupt
- edpt_schedule_packets(rhport, epnum, dir, num_packets, total_bytes);
-
- return true;
-}
-
-static void dcd_edpt_disable (uint8_t rhport, uint8_t ep_addr, bool stall)
-{
- (void) rhport;
-
- USB_OTG_GlobalTypeDef * usb_otg = GLOBAL_BASE(rhport);
- USB_OTG_DeviceTypeDef * dev = DEVICE_BASE(rhport);
- USB_OTG_OUTEndpointTypeDef * out_ep = OUT_EP_BASE(rhport);
- USB_OTG_INEndpointTypeDef * in_ep = IN_EP_BASE(rhport);
-
- uint8_t const epnum = tu_edpt_number(ep_addr);
- uint8_t const dir = tu_edpt_dir(ep_addr);
-
- if(dir == TUSB_DIR_IN) {
- // Only disable currently enabled non-control endpoint
- if ( (epnum == 0) || !(in_ep[epnum].DIEPCTL & USB_OTG_DIEPCTL_EPENA) ){
- in_ep[epnum].DIEPCTL |= USB_OTG_DIEPCTL_SNAK | (stall ? USB_OTG_DIEPCTL_STALL : 0);
- } else {
- // Stop transmitting packets and NAK IN xfers.
- in_ep[epnum].DIEPCTL |= USB_OTG_DIEPCTL_SNAK;
- while((in_ep[epnum].DIEPINT & USB_OTG_DIEPINT_INEPNE) == 0);
-
- // Disable the endpoint.
- in_ep[epnum].DIEPCTL |= USB_OTG_DIEPCTL_EPDIS | (stall ? USB_OTG_DIEPCTL_STALL : 0);
- while((in_ep[epnum].DIEPINT & USB_OTG_DIEPINT_EPDISD_Msk) == 0);
- in_ep[epnum].DIEPINT = USB_OTG_DIEPINT_EPDISD;
- }
-
- // Flush the FIFO, and wait until we have confirmed it cleared.
- usb_otg->GRSTCTL |= (epnum << USB_OTG_GRSTCTL_TXFNUM_Pos);
- usb_otg->GRSTCTL |= USB_OTG_GRSTCTL_TXFFLSH;
- while((usb_otg->GRSTCTL & USB_OTG_GRSTCTL_TXFFLSH_Msk) != 0);
- } else {
- // Only disable currently enabled non-control endpoint
- if ( (epnum == 0) || !(out_ep[epnum].DOEPCTL & USB_OTG_DOEPCTL_EPENA) ){
- out_ep[epnum].DOEPCTL |= stall ? USB_OTG_DOEPCTL_STALL : 0;
- } else {
- // Asserting GONAK is required to STALL an OUT endpoint.
- // Simpler to use polling here, we don't use the "B"OUTNAKEFF interrupt
- // anyway, and it can't be cleared by user code. If this while loop never
- // finishes, we have bigger problems than just the stack.
- dev->DCTL |= USB_OTG_DCTL_SGONAK;
- while((usb_otg->GINTSTS & USB_OTG_GINTSTS_BOUTNAKEFF_Msk) == 0);
-
- // Ditto here- disable the endpoint.
- out_ep[epnum].DOEPCTL |= USB_OTG_DOEPCTL_EPDIS | (stall ? USB_OTG_DOEPCTL_STALL : 0);
- while((out_ep[epnum].DOEPINT & USB_OTG_DOEPINT_EPDISD_Msk) == 0);
- out_ep[epnum].DOEPINT = USB_OTG_DOEPINT_EPDISD;
-
- // Allow other OUT endpoints to keep receiving.
- dev->DCTL |= USB_OTG_DCTL_CGONAK;
- }
- }
-}
-
-/**
- * Close an endpoint.
- */
-void dcd_edpt_close (uint8_t rhport, uint8_t ep_addr)
-{
- USB_OTG_GlobalTypeDef * usb_otg = GLOBAL_BASE(rhport);
-
- uint8_t const epnum = tu_edpt_number(ep_addr);
- uint8_t const dir = tu_edpt_dir(ep_addr);
-
- dcd_edpt_disable(rhport, ep_addr, false);
-
- // Update max_size
- xfer_status[epnum][dir].max_size = 0; // max_size = 0 marks a disabled EP - required for changing FIFO allocation
-
- if (dir == TUSB_DIR_IN)
- {
- uint16_t const fifo_size = (usb_otg->DIEPTXF[epnum - 1] & USB_OTG_DIEPTXF_INEPTXFD_Msk) >> USB_OTG_DIEPTXF_INEPTXFD_Pos;
- uint16_t const fifo_start = (usb_otg->DIEPTXF[epnum - 1] & USB_OTG_DIEPTXF_INEPTXSA_Msk) >> USB_OTG_DIEPTXF_INEPTXSA_Pos;
- // For now only the last opened endpoint can be closed without fuss.
- TU_ASSERT(fifo_start == EP_FIFO_SIZE/4 - _allocated_fifo_words_tx,);
- _allocated_fifo_words_tx -= fifo_size;
- }
- else
- {
- _out_ep_closed = true; // Set flag such that RX FIFO gets reduced in size once RX FIFO is empty
- }
-}
-
-void dcd_edpt_stall (uint8_t rhport, uint8_t ep_addr)
-{
- dcd_edpt_disable(rhport, ep_addr, true);
-}
-
-void dcd_edpt_clear_stall (uint8_t rhport, uint8_t ep_addr)
-{
- (void) rhport;
-
- USB_OTG_OUTEndpointTypeDef * out_ep = OUT_EP_BASE(rhport);
- USB_OTG_INEndpointTypeDef * in_ep = IN_EP_BASE(rhport);
-
- uint8_t const epnum = tu_edpt_number(ep_addr);
- uint8_t const dir = tu_edpt_dir(ep_addr);
-
- if(dir == TUSB_DIR_IN) {
- in_ep[epnum].DIEPCTL &= ~USB_OTG_DIEPCTL_STALL;
-
- uint8_t eptype = (in_ep[epnum].DIEPCTL & USB_OTG_DIEPCTL_EPTYP_Msk) >> USB_OTG_DIEPCTL_EPTYP_Pos;
- // Required by USB spec to reset DATA toggle bit to DATA0 on interrupt and bulk endpoints.
- if(eptype == 2 || eptype == 3) {
- in_ep[epnum].DIEPCTL |= USB_OTG_DIEPCTL_SD0PID_SEVNFRM;
- }
- } else {
- out_ep[epnum].DOEPCTL &= ~USB_OTG_DOEPCTL_STALL;
-
- uint8_t eptype = (out_ep[epnum].DOEPCTL & USB_OTG_DOEPCTL_EPTYP_Msk) >> USB_OTG_DOEPCTL_EPTYP_Pos;
- // Required by USB spec to reset DATA toggle bit to DATA0 on interrupt and bulk endpoints.
- if(eptype == 2 || eptype == 3) {
- out_ep[epnum].DOEPCTL |= USB_OTG_DOEPCTL_SD0PID_SEVNFRM;
- }
- }
-}
-
-/*------------------------------------------------------------------*/
-
-// Read a single data packet from receive FIFO
-static void read_fifo_packet(uint8_t rhport, uint8_t * dst, uint16_t len)
-{
- (void) rhport;
-
- usb_fifo_t rx_fifo = FIFO_BASE(rhport, 0);
-
- // Reading full available 32 bit words from fifo
- uint16_t full_words = len >> 2;
- for(uint16_t i = 0; i < full_words; i++) {
- uint32_t tmp = *rx_fifo;
- dst[0] = tmp & 0x000000FF;
- dst[1] = (tmp & 0x0000FF00) >> 8;
- dst[2] = (tmp & 0x00FF0000) >> 16;
- dst[3] = (tmp & 0xFF000000) >> 24;
- dst += 4;
- }
-
- // Read the remaining 1-3 bytes from fifo
- uint8_t bytes_rem = len & 0x03;
- if(bytes_rem != 0) {
- uint32_t tmp = *rx_fifo;
- dst[0] = tmp & 0x000000FF;
- if(bytes_rem > 1) {
- dst[1] = (tmp & 0x0000FF00) >> 8;
- }
- if(bytes_rem > 2) {
- dst[2] = (tmp & 0x00FF0000) >> 16;
- }
- }
-}
-
-// Write a single data packet to EPIN FIFO
-static void write_fifo_packet(uint8_t rhport, uint8_t fifo_num, uint8_t * src, uint16_t len)
-{
- (void) rhport;
-
- usb_fifo_t tx_fifo = FIFO_BASE(rhport, fifo_num);
-
- // Pushing full available 32 bit words to fifo
- uint16_t full_words = len >> 2;
- for(uint16_t i = 0; i < full_words; i++){
- *tx_fifo = (src[3] << 24) | (src[2] << 16) | (src[1] << 8) | src[0];
- src += 4;
- }
-
- // Write the remaining 1-3 bytes into fifo
- uint8_t bytes_rem = len & 0x03;
- if(bytes_rem){
- uint32_t tmp_word = 0;
- tmp_word |= src[0];
- if(bytes_rem > 1){
- tmp_word |= src[1] << 8;
- }
- if(bytes_rem > 2){
- tmp_word |= src[2] << 16;
- }
- *tx_fifo = tmp_word;
- }
-}
-
-static void handle_rxflvl_ints(uint8_t rhport, USB_OTG_OUTEndpointTypeDef * out_ep) {
- USB_OTG_GlobalTypeDef * usb_otg = GLOBAL_BASE(rhport);
- usb_fifo_t rx_fifo = FIFO_BASE(rhport, 0);
-
- // Pop control word off FIFO
- uint32_t ctl_word = usb_otg->GRXSTSP;
- uint8_t pktsts = (ctl_word & USB_OTG_GRXSTSP_PKTSTS_Msk) >> USB_OTG_GRXSTSP_PKTSTS_Pos;
- uint8_t epnum = (ctl_word & USB_OTG_GRXSTSP_EPNUM_Msk) >> USB_OTG_GRXSTSP_EPNUM_Pos;
- uint16_t bcnt = (ctl_word & USB_OTG_GRXSTSP_BCNT_Msk) >> USB_OTG_GRXSTSP_BCNT_Pos;
-
- switch(pktsts) {
- case 0x01: // Global OUT NAK (Interrupt)
- break;
-
- case 0x02: // Out packet recvd
- {
- xfer_ctl_t * xfer = XFER_CTL_BASE(epnum, TUSB_DIR_OUT);
-
- // Read packet off RxFIFO
- if (xfer->ff)
- {
- // Ring buffer
- tu_fifo_write_n_const_addr_full_words(xfer->ff, (const void *) rx_fifo, bcnt);
- }
- else
- {
- // Linear buffer
- read_fifo_packet(rhport, xfer->buffer, bcnt);
-
- // Increment pointer to xfer data
- xfer->buffer += bcnt;
- }
-
- // Truncate transfer length in case of short packet
- if(bcnt < xfer->max_size) {
- xfer->total_len -= (out_ep[epnum].DOEPTSIZ & USB_OTG_DOEPTSIZ_XFRSIZ_Msk) >> USB_OTG_DOEPTSIZ_XFRSIZ_Pos;
- if(epnum == 0) {
- xfer->total_len -= ep0_pending[TUSB_DIR_OUT];
- ep0_pending[TUSB_DIR_OUT] = 0;
- }
- }
- }
- break;
-
- case 0x03: // Out packet done (Interrupt)
- break;
-
- case 0x04: // Setup packet done (Interrupt)
- out_ep[epnum].DOEPTSIZ |= (3 << USB_OTG_DOEPTSIZ_STUPCNT_Pos);
- break;
-
- case 0x06: // Setup packet recvd
- // We can receive up to three setup packets in succession, but
- // only the last one is valid.
- _setup_packet[0] = (* rx_fifo);
- _setup_packet[1] = (* rx_fifo);
- break;
-
- default: // Invalid
- TU_BREAKPOINT();
- break;
- }
-}
-
-static void handle_epout_ints(uint8_t rhport, USB_OTG_DeviceTypeDef * dev, USB_OTG_OUTEndpointTypeDef * out_ep) {
- // DAINT for a given EP clears when DOEPINTx is cleared.
- // OEPINT will be cleared when DAINT's out bits are cleared.
- for(uint8_t n = 0; n < EP_MAX; n++) {
- xfer_ctl_t * xfer = XFER_CTL_BASE(n, TUSB_DIR_OUT);
-
- if(dev->DAINT & (1 << (USB_OTG_DAINT_OEPINT_Pos + n))) {
- // SETUP packet Setup Phase done.
- if(out_ep[n].DOEPINT & USB_OTG_DOEPINT_STUP) {
- out_ep[n].DOEPINT = USB_OTG_DOEPINT_STUP;
- dcd_event_setup_received(rhport, (uint8_t*) &_setup_packet[0], true);
- }
-
- // OUT XFER complete
- if(out_ep[n].DOEPINT & USB_OTG_DOEPINT_XFRC) {
- out_ep[n].DOEPINT = USB_OTG_DOEPINT_XFRC;
-
- // EP0 can only handle one packet
- if((n == 0) && ep0_pending[TUSB_DIR_OUT]) {
- // Schedule another packet to be received.
- edpt_schedule_packets(rhport, n, TUSB_DIR_OUT, 1, ep0_pending[TUSB_DIR_OUT]);
- } else {
- dcd_event_xfer_complete(rhport, n, xfer->total_len, XFER_RESULT_SUCCESS, true);
- }
- }
- }
- }
-}
-
-static void handle_epin_ints(uint8_t rhport, USB_OTG_DeviceTypeDef * dev, USB_OTG_INEndpointTypeDef * in_ep) {
- // DAINT for a given EP clears when DIEPINTx is cleared.
- // IEPINT will be cleared when DAINT's out bits are cleared.
- for ( uint8_t n = 0; n < EP_MAX; n++ )
- {
- xfer_ctl_t *xfer = XFER_CTL_BASE(n, TUSB_DIR_IN);
-
- if ( dev->DAINT & (1 << (USB_OTG_DAINT_IEPINT_Pos + n)) )
- {
- // IN XFER complete (entire xfer).
- if ( in_ep[n].DIEPINT & USB_OTG_DIEPINT_XFRC )
- {
- in_ep[n].DIEPINT = USB_OTG_DIEPINT_XFRC;
-
- // EP0 can only handle one packet
- if((n == 0) && ep0_pending[TUSB_DIR_IN]) {
- // Schedule another packet to be transmitted.
- edpt_schedule_packets(rhport, n, TUSB_DIR_IN, 1, ep0_pending[TUSB_DIR_IN]);
- } else {
- dcd_event_xfer_complete(rhport, n | TUSB_DIR_IN_MASK, xfer->total_len, XFER_RESULT_SUCCESS, true);
- }
- }
-
- // XFER FIFO empty
- if ( (in_ep[n].DIEPINT & USB_OTG_DIEPINT_TXFE) && (dev->DIEPEMPMSK & (1 << n)) )
- {
- // DIEPINT's TXFE bit is read-only, software cannot clear it.
- // It will only be cleared by hardware when written bytes is more than
- // - 64 bytes or
- // - Half of TX FIFO size (configured by DIEPTXF)
-
- uint16_t remaining_packets = (in_ep[n].DIEPTSIZ & USB_OTG_DIEPTSIZ_PKTCNT_Msk) >> USB_OTG_DIEPTSIZ_PKTCNT_Pos;
-
- // Process every single packet (only whole packets can be written to fifo)
- for(uint16_t i = 0; i < remaining_packets; i++)
- {
- uint16_t const remaining_bytes = (in_ep[n].DIEPTSIZ & USB_OTG_DIEPTSIZ_XFRSIZ_Msk) >> USB_OTG_DIEPTSIZ_XFRSIZ_Pos;
-
- // Packet can not be larger than ep max size
- uint16_t const packet_size = tu_min16(remaining_bytes, xfer->max_size);
-
- // It's only possible to write full packets into FIFO. Therefore DTXFSTS register of current
- // EP has to be checked if the buffer can take another WHOLE packet
- if(packet_size > ((in_ep[n].DTXFSTS & USB_OTG_DTXFSTS_INEPTFSAV_Msk) << 2)) break;
-
- // Push packet to Tx-FIFO
- if (xfer->ff)
- {
- usb_fifo_t tx_fifo = FIFO_BASE(rhport, n);
- tu_fifo_read_n_const_addr_full_words(xfer->ff, (void *) tx_fifo, packet_size);
- }
- else
- {
- write_fifo_packet(rhport, n, xfer->buffer, packet_size);
-
- // Increment pointer to xfer data
- xfer->buffer += packet_size;
- }
- }
-
- // Turn off TXFE if all bytes are written.
- if (((in_ep[n].DIEPTSIZ & USB_OTG_DIEPTSIZ_XFRSIZ_Msk) >> USB_OTG_DIEPTSIZ_XFRSIZ_Pos) == 0)
- {
- dev->DIEPEMPMSK &= ~(1 << n);
- }
- }
- }
- }
-}
-
-void dcd_int_handler(uint8_t rhport)
-{
- USB_OTG_GlobalTypeDef * usb_otg = GLOBAL_BASE(rhport);
- USB_OTG_DeviceTypeDef * dev = DEVICE_BASE(rhport);
- USB_OTG_OUTEndpointTypeDef * out_ep = OUT_EP_BASE(rhport);
- USB_OTG_INEndpointTypeDef * in_ep = IN_EP_BASE(rhport);
-
- uint32_t int_status = usb_otg->GINTSTS;
-
- if(int_status & USB_OTG_GINTSTS_USBRST)
- {
- // USBRST is start of reset.
- usb_otg->GINTSTS = USB_OTG_GINTSTS_USBRST;
- bus_reset(rhport);
- }
-
- if(int_status & USB_OTG_GINTSTS_ENUMDNE)
- {
- // ENUMDNE is the end of reset where speed of the link is detected
-
- usb_otg->GINTSTS = USB_OTG_GINTSTS_ENUMDNE;
-
- tusb_speed_t const speed = get_speed(rhport);
-
- set_turnaround(usb_otg, speed);
- dcd_event_bus_reset(rhport, speed, true);
- }
-
- if(int_status & USB_OTG_GINTSTS_USBSUSP)
- {
- usb_otg->GINTSTS = USB_OTG_GINTSTS_USBSUSP;
- dcd_event_bus_signal(rhport, DCD_EVENT_SUSPEND, true);
- }
-
- if(int_status & USB_OTG_GINTSTS_WKUINT)
- {
- usb_otg->GINTSTS = USB_OTG_GINTSTS_WKUINT;
- dcd_event_bus_signal(rhport, DCD_EVENT_RESUME, true);
- }
-
- if(int_status & USB_OTG_GINTSTS_OTGINT)
- {
- // OTG INT bit is read-only
- uint32_t const otg_int = usb_otg->GOTGINT;
-
- if (otg_int & USB_OTG_GOTGINT_SEDET)
- {
- dcd_event_bus_signal(rhport, DCD_EVENT_UNPLUGGED, true);
- }
-
- usb_otg->GOTGINT = otg_int;
- }
-
-#if USE_SOF
- if(int_status & USB_OTG_GINTSTS_SOF)
- {
- usb_otg->GINTSTS = USB_OTG_GINTSTS_SOF;
- dcd_event_bus_signal(rhport, DCD_EVENT_SOF, true);
- }
-#endif
-
- // RxFIFO non-empty interrupt handling.
- if(int_status & USB_OTG_GINTSTS_RXFLVL)
- {
- // RXFLVL bit is read-only
-
- // Mask out RXFLVL while reading data from FIFO
- usb_otg->GINTMSK &= ~USB_OTG_GINTMSK_RXFLVLM;
-
- // Loop until all available packets were handled
- do
- {
- handle_rxflvl_ints(rhport, out_ep);
- int_status = usb_otg->GINTSTS;
- } while(int_status & USB_OTG_GINTSTS_RXFLVL);
-
- // Manage RX FIFO size
- if (_out_ep_closed)
- {
- update_grxfsiz(rhport);
-
- // Disable flag
- _out_ep_closed = false;
- }
-
- usb_otg->GINTMSK |= USB_OTG_GINTMSK_RXFLVLM;
- }
-
- // OUT endpoint interrupt handling.
- if(int_status & USB_OTG_GINTSTS_OEPINT)
- {
- // OEPINT is read-only
- handle_epout_ints(rhport, dev, out_ep);
- }
-
- // IN endpoint interrupt handling.
- if(int_status & USB_OTG_GINTSTS_IEPINT)
- {
- // IEPINT bit read-only
- handle_epin_ints(rhport, dev, in_ep);
- }
-
- // // Check for Incomplete isochronous IN transfer
- // if(int_status & USB_OTG_GINTSTS_IISOIXFR) {
- // printf(" IISOIXFR!\r\n");
- //// TU_LOG2(" IISOIXFR!\r\n");
- // }
-}
-
-#endif
diff --git a/tinyusb/src/portable/st/synopsys/synopsys_common.h b/tinyusb/src/portable/st/synopsys/synopsys_common.h
deleted file mode 100755
index 6f0602fe..00000000
--- a/tinyusb/src/portable/st/synopsys/synopsys_common.h
+++ /dev/null
@@ -1,1465 +0,0 @@
-/**
- ******************************************************************************
- * @file synopsys_common.h
- * @author MCD Application Team
- * @brief CMSIS Cortex-M3 Device USB OTG peripheral Header File.
- * This file contains the USB OTG peripheral register's definitions, bits
- * definitions and memory mapping for STM32F1xx devices.
- *
- * This file contains:
- * - Data structures and the address mapping for the USB OTG peripheral
- * - The Peripheral's registers declarations and bits definition
- * - Macros to access the peripheral's registers hardware
- *
- ******************************************************************************
- * @attention
- *
- * <h2><center>&copy; Copyright (c) 2017 STMicroelectronics.
- * All rights reserved.</center></h2>
- *
- * This software component is licensed by ST under BSD 3-Clause license,
- * the "License"; You may not use this file except in compliance with the
- * License. You may obtain a copy of the License at:
- * opensource.org/licenses/BSD-3-Clause
- *
- ******************************************************************************
- */
-
-#include "stdint.h"
-
-#pragma once
-
-#ifdef __cplusplus
- #define __I volatile
-#else
- #define __I volatile const
-#endif
-#define __O volatile
-#define __IO volatile
-#define __IM volatile const
-#define __OM volatile
-#define __IOM volatile
-
-/**
- * @brief __USB_OTG_Core_register
- */
-
-typedef struct
-{
- __IO uint32_t GOTGCTL; /*!< USB_OTG Control and Status Register Address offset: 000h */
- __IO uint32_t GOTGINT; /*!< USB_OTG Interrupt Register Address offset: 004h */
- __IO uint32_t GAHBCFG; /*!< Core AHB Configuration Register Address offset: 008h */
- __IO uint32_t GUSBCFG; /*!< Core USB Configuration Register Address offset: 00Ch */
- __IO uint32_t GRSTCTL; /*!< Core Reset Register Address offset: 010h */
- __IO uint32_t GINTSTS; /*!< Core Interrupt Register Address offset: 014h */
- __IO uint32_t GINTMSK; /*!< Core Interrupt Mask Register Address offset: 018h */
- __IO uint32_t GRXSTSR; /*!< Receive Sts Q Read Register Address offset: 01Ch */
- __IO uint32_t GRXSTSP; /*!< Receive Sts Q Read & POP Register Address offset: 020h */
- __IO uint32_t GRXFSIZ; /*!< Receive FIFO Size Register Address offset: 024h */
- __IO uint32_t DIEPTXF0_HNPTXFSIZ; /*!< EP0 / Non Periodic Tx FIFO Size Register Address offset: 028h */
- __IO uint32_t HNPTXSTS; /*!< Non Periodic Tx FIFO/Queue Sts reg Address offset: 02Ch */
- uint32_t Reserved30[2]; /*!< Reserved 030h*/
- __IO uint32_t GCCFG; /*!< General Purpose IO Register Address offset: 038h */
- __IO uint32_t CID; /*!< User ID Register Address offset: 03Ch */
- uint32_t Reserved40[48]; /*!< Reserved 040h-0FFh */
- __IO uint32_t HPTXFSIZ; /*!< Host Periodic Tx FIFO Size Reg Address offset: 100h */
- __IO uint32_t DIEPTXF[0x0F]; /*!< dev Periodic Transmit FIFO Address offset: 0x104 */
-} USB_OTG_GlobalTypeDef;
-
-/**
- * @brief __device_Registers
- */
-
-typedef struct
-{
- __IO uint32_t DCFG; /*!< dev Configuration Register Address offset: 800h*/
- __IO uint32_t DCTL; /*!< dev Control Register Address offset: 804h*/
- __IO uint32_t DSTS; /*!< dev Status Register (RO) Address offset: 808h*/
- uint32_t Reserved0C; /*!< Reserved 80Ch*/
- __IO uint32_t DIEPMSK; /*!< dev IN Endpoint Mask Address offset: 810h*/
- __IO uint32_t DOEPMSK; /*!< dev OUT Endpoint Mask Address offset: 814h*/
- __IO uint32_t DAINT; /*!< dev All Endpoints Itr Reg Address offset: 818h*/
- __IO uint32_t DAINTMSK; /*!< dev All Endpoints Itr Mask Address offset: 81Ch*/
- uint32_t Reserved20; /*!< Reserved 820h*/
- uint32_t Reserved9; /*!< Reserved 824h*/
- __IO uint32_t DVBUSDIS; /*!< dev VBUS discharge Register Address offset: 828h*/
- __IO uint32_t DVBUSPULSE; /*!< dev VBUS Pulse Register Address offset: 82Ch*/
- __IO uint32_t DTHRCTL; /*!< dev thr Address offset: 830h*/
- __IO uint32_t DIEPEMPMSK; /*!< dev empty msk Address offset: 834h*/
- __IO uint32_t DEACHINT; /*!< dedicated EP interrupt Address offset: 838h*/
- __IO uint32_t DEACHMSK; /*!< dedicated EP msk Address offset: 83Ch*/
- uint32_t Reserved40; /*!< dedicated EP mask Address offset: 840h*/
- __IO uint32_t DINEP1MSK; /*!< dedicated EP mask Address offset: 844h*/
- uint32_t Reserved44[15]; /*!< Reserved 844-87Ch*/
- __IO uint32_t DOUTEP1MSK; /*!< dedicated EP msk Address offset: 884h*/
-} USB_OTG_DeviceTypeDef;
-
-/**
- * @brief __IN_Endpoint-Specific_Register
- */
-
-typedef struct
-{
- __IO uint32_t DIEPCTL; /*!< dev IN Endpoint Control Reg 900h + (ep_num * 20h) + 00h*/
- uint32_t Reserved04; /*!< Reserved 900h + (ep_num * 20h) + 04h*/
- __IO uint32_t DIEPINT; /*!< dev IN Endpoint Itr Reg 900h + (ep_num * 20h) + 08h*/
- uint32_t Reserved0C; /*!< Reserved 900h + (ep_num * 20h) + 0Ch*/
- __IO uint32_t DIEPTSIZ; /*!< IN Endpoint Txfer Size 900h + (ep_num * 20h) + 10h*/
- __IO uint32_t DIEPDMA; /*!< IN Endpoint DMA Address Reg 900h + (ep_num * 20h) + 14h*/
- __IO uint32_t DTXFSTS; /*!< IN Endpoint Tx FIFO Status Reg 900h + (ep_num * 20h) + 18h*/
- uint32_t Reserved18; /*!< Reserved 900h+(ep_num*20h)+1Ch-900h+ (ep_num * 20h) + 1Ch*/
-} USB_OTG_INEndpointTypeDef;
-
-/**
- * @brief __OUT_Endpoint-Specific_Registers
- */
-
-typedef struct
-{
- __IO uint32_t DOEPCTL; /*!< dev OUT Endpoint Control Reg B00h + (ep_num * 20h) + 00h*/
- uint32_t Reserved04; /*!< Reserved B00h + (ep_num * 20h) + 04h*/
- __IO uint32_t DOEPINT; /*!< dev OUT Endpoint Itr Reg B00h + (ep_num * 20h) + 08h*/
- uint32_t Reserved0C; /*!< Reserved B00h + (ep_num * 20h) + 0Ch*/
- __IO uint32_t DOEPTSIZ; /*!< dev OUT Endpoint Txfer Size B00h + (ep_num * 20h) + 10h*/
- __IO uint32_t DOEPDMA; /*!< dev OUT Endpoint DMA Address B00h + (ep_num * 20h) + 14h*/
- uint32_t Reserved18[2]; /*!< Reserved B00h + (ep_num * 20h) + 18h - B00h + (ep_num * 20h) + 1Ch*/
-} USB_OTG_OUTEndpointTypeDef;
-
-/**
- * @brief __Host_Mode_Register_Structures
- */
-
-typedef struct
-{
- __IO uint32_t HCFG; /*!< Host Configuration Register 400h*/
- __IO uint32_t HFIR; /*!< Host Frame Interval Register 404h*/
- __IO uint32_t HFNUM; /*!< Host Frame Nbr/Frame Remaining 408h*/
- uint32_t Reserved40C; /*!< Reserved 40Ch*/
- __IO uint32_t HPTXSTS; /*!< Host Periodic Tx FIFO/ Queue Status 410h*/
- __IO uint32_t HAINT; /*!< Host All Channels Interrupt Register 414h*/
- __IO uint32_t HAINTMSK; /*!< Host All Channels Interrupt Mask 418h*/
-} USB_OTG_HostTypeDef;
-
-/**
- * @brief __Host_Channel_Specific_Registers
- */
-
-typedef struct
-{
- __IO uint32_t HCCHAR;
- __IO uint32_t HCSPLT;
- __IO uint32_t HCINT;
- __IO uint32_t HCINTMSK;
- __IO uint32_t HCTSIZ;
- __IO uint32_t HCDMA;
- uint32_t Reserved[2];
-} USB_OTG_HostChannelTypeDef;
-
-/*!< USB registers base address */
-#define USB_OTG_FS_PERIPH_BASE 0x50000000UL
-
-#define USB_OTG_GLOBAL_BASE 0x00000000UL
-#define USB_OTG_DEVICE_BASE 0x00000800UL
-#define USB_OTG_IN_ENDPOINT_BASE 0x00000900UL
-#define USB_OTG_OUT_ENDPOINT_BASE 0x00000B00UL
-#define USB_OTG_EP_REG_SIZE 0x00000020UL
-#define USB_OTG_HOST_BASE 0x00000400UL
-#define USB_OTG_HOST_PORT_BASE 0x00000440UL
-#define USB_OTG_HOST_CHANNEL_BASE 0x00000500UL
-#define USB_OTG_HOST_CHANNEL_SIZE 0x00000020UL
-#define USB_OTG_PCGCCTL_BASE 0x00000E00UL
-#define USB_OTG_FIFO_BASE 0x00001000UL
-#define USB_OTG_FIFO_SIZE 0x00001000UL
-
-/******************************************************************************/
-/* */
-/* USB_OTG */
-/* */
-/******************************************************************************/
-/******************** Bit definition for USB_OTG_GOTGCTL register ***********/
-#define USB_OTG_GOTGCTL_SRQSCS_Pos (0U)
-#define USB_OTG_GOTGCTL_SRQSCS_Msk (0x1UL << USB_OTG_GOTGCTL_SRQSCS_Pos) /*!< 0x00000001 */
-#define USB_OTG_GOTGCTL_SRQSCS USB_OTG_GOTGCTL_SRQSCS_Msk /*!< Session request success */
-#define USB_OTG_GOTGCTL_SRQ_Pos (1U)
-#define USB_OTG_GOTGCTL_SRQ_Msk (0x1UL << USB_OTG_GOTGCTL_SRQ_Pos) /*!< 0x00000002 */
-#define USB_OTG_GOTGCTL_SRQ USB_OTG_GOTGCTL_SRQ_Msk /*!< Session request */
-#define USB_OTG_GOTGCTL_HNGSCS_Pos (8U)
-#define USB_OTG_GOTGCTL_HNGSCS_Msk (0x1UL << USB_OTG_GOTGCTL_HNGSCS_Pos) /*!< 0x00000100 */
-#define USB_OTG_GOTGCTL_HNGSCS USB_OTG_GOTGCTL_HNGSCS_Msk /*!< Host set HNP enable */
-#define USB_OTG_GOTGCTL_HNPRQ_Pos (9U)
-#define USB_OTG_GOTGCTL_HNPRQ_Msk (0x1UL << USB_OTG_GOTGCTL_HNPRQ_Pos) /*!< 0x00000200 */
-#define USB_OTG_GOTGCTL_HNPRQ USB_OTG_GOTGCTL_HNPRQ_Msk /*!< HNP request */
-#define USB_OTG_GOTGCTL_HSHNPEN_Pos (10U)
-#define USB_OTG_GOTGCTL_HSHNPEN_Msk (0x1UL << USB_OTG_GOTGCTL_HSHNPEN_Pos) /*!< 0x00000400 */
-#define USB_OTG_GOTGCTL_HSHNPEN USB_OTG_GOTGCTL_HSHNPEN_Msk /*!< Host set HNP enable */
-#define USB_OTG_GOTGCTL_DHNPEN_Pos (11U)
-#define USB_OTG_GOTGCTL_DHNPEN_Msk (0x1UL << USB_OTG_GOTGCTL_DHNPEN_Pos) /*!< 0x00000800 */
-#define USB_OTG_GOTGCTL_DHNPEN USB_OTG_GOTGCTL_DHNPEN_Msk /*!< Device HNP enabled */
-#define USB_OTG_GOTGCTL_CIDSTS_Pos (16U)
-#define USB_OTG_GOTGCTL_CIDSTS_Msk (0x1UL << USB_OTG_GOTGCTL_CIDSTS_Pos) /*!< 0x00010000 */
-#define USB_OTG_GOTGCTL_CIDSTS USB_OTG_GOTGCTL_CIDSTS_Msk /*!< Connector ID status */
-#define USB_OTG_GOTGCTL_DBCT_Pos (17U)
-#define USB_OTG_GOTGCTL_DBCT_Msk (0x1UL << USB_OTG_GOTGCTL_DBCT_Pos) /*!< 0x00020000 */
-#define USB_OTG_GOTGCTL_DBCT USB_OTG_GOTGCTL_DBCT_Msk /*!< Long/short debounce time */
-#define USB_OTG_GOTGCTL_ASVLD_Pos (18U)
-#define USB_OTG_GOTGCTL_ASVLD_Msk (0x1UL << USB_OTG_GOTGCTL_ASVLD_Pos) /*!< 0x00040000 */
-#define USB_OTG_GOTGCTL_ASVLD USB_OTG_GOTGCTL_ASVLD_Msk /*!< A-session valid */
-#define USB_OTG_GOTGCTL_BSVLD_Pos (19U)
-#define USB_OTG_GOTGCTL_BSVLD_Msk (0x1UL << USB_OTG_GOTGCTL_BSVLD_Pos) /*!< 0x00080000 */
-#define USB_OTG_GOTGCTL_BSVLD USB_OTG_GOTGCTL_BSVLD_Msk /*!< B-session valid */
-
-/******************** Bit definition for USB_OTG_HCFG register ********************/
-
-#define USB_OTG_HCFG_FSLSPCS_Pos (0U)
-#define USB_OTG_HCFG_FSLSPCS_Msk (0x3UL << USB_OTG_HCFG_FSLSPCS_Pos) /*!< 0x00000003 */
-#define USB_OTG_HCFG_FSLSPCS USB_OTG_HCFG_FSLSPCS_Msk /*!< FS/LS PHY clock select */
-#define USB_OTG_HCFG_FSLSPCS_0 (0x1UL << USB_OTG_HCFG_FSLSPCS_Pos) /*!< 0x00000001 */
-#define USB_OTG_HCFG_FSLSPCS_1 (0x2UL << USB_OTG_HCFG_FSLSPCS_Pos) /*!< 0x00000002 */
-#define USB_OTG_HCFG_FSLSS_Pos (2U)
-#define USB_OTG_HCFG_FSLSS_Msk (0x1UL << USB_OTG_HCFG_FSLSS_Pos) /*!< 0x00000004 */
-#define USB_OTG_HCFG_FSLSS USB_OTG_HCFG_FSLSS_Msk /*!< FS- and LS-only support */
-
-/******************** Bit definition for USB_OTG_DCFG register ********************/
-
-#define USB_OTG_DCFG_DSPD_Pos (0U)
-#define USB_OTG_DCFG_DSPD_Msk (0x3UL << USB_OTG_DCFG_DSPD_Pos) /*!< 0x00000003 */
-#define USB_OTG_DCFG_DSPD USB_OTG_DCFG_DSPD_Msk /*!< Device speed */
-#define USB_OTG_DCFG_DSPD_0 (0x1UL << USB_OTG_DCFG_DSPD_Pos) /*!< 0x00000001 */
-#define USB_OTG_DCFG_DSPD_1 (0x2UL << USB_OTG_DCFG_DSPD_Pos) /*!< 0x00000002 */
-#define USB_OTG_DCFG_NZLSOHSK_Pos (2U)
-#define USB_OTG_DCFG_NZLSOHSK_Msk (0x1UL << USB_OTG_DCFG_NZLSOHSK_Pos) /*!< 0x00000004 */
-#define USB_OTG_DCFG_NZLSOHSK USB_OTG_DCFG_NZLSOHSK_Msk /*!< Nonzero-length status OUT handshake */
-
-#define USB_OTG_DCFG_DAD_Pos (4U)
-#define USB_OTG_DCFG_DAD_Msk (0x7FUL << USB_OTG_DCFG_DAD_Pos) /*!< 0x000007F0 */
-#define USB_OTG_DCFG_DAD USB_OTG_DCFG_DAD_Msk /*!< Device address */
-#define USB_OTG_DCFG_DAD_0 (0x01UL << USB_OTG_DCFG_DAD_Pos) /*!< 0x00000010 */
-#define USB_OTG_DCFG_DAD_1 (0x02UL << USB_OTG_DCFG_DAD_Pos) /*!< 0x00000020 */
-#define USB_OTG_DCFG_DAD_2 (0x04UL << USB_OTG_DCFG_DAD_Pos) /*!< 0x00000040 */
-#define USB_OTG_DCFG_DAD_3 (0x08UL << USB_OTG_DCFG_DAD_Pos) /*!< 0x00000080 */
-#define USB_OTG_DCFG_DAD_4 (0x10UL << USB_OTG_DCFG_DAD_Pos) /*!< 0x00000100 */
-#define USB_OTG_DCFG_DAD_5 (0x20UL << USB_OTG_DCFG_DAD_Pos) /*!< 0x00000200 */
-#define USB_OTG_DCFG_DAD_6 (0x40UL << USB_OTG_DCFG_DAD_Pos) /*!< 0x00000400 */
-
-#define USB_OTG_DCFG_PFIVL_Pos (11U)
-#define USB_OTG_DCFG_PFIVL_Msk (0x3UL << USB_OTG_DCFG_PFIVL_Pos) /*!< 0x00001800 */
-#define USB_OTG_DCFG_PFIVL USB_OTG_DCFG_PFIVL_Msk /*!< Periodic (micro)frame interval */
-#define USB_OTG_DCFG_PFIVL_0 (0x1UL << USB_OTG_DCFG_PFIVL_Pos) /*!< 0x00000800 */
-#define USB_OTG_DCFG_PFIVL_1 (0x2UL << USB_OTG_DCFG_PFIVL_Pos) /*!< 0x00001000 */
-
-#define USB_OTG_DCFG_PERSCHIVL_Pos (24U)
-#define USB_OTG_DCFG_PERSCHIVL_Msk (0x3UL << USB_OTG_DCFG_PERSCHIVL_Pos) /*!< 0x03000000 */
-#define USB_OTG_DCFG_PERSCHIVL USB_OTG_DCFG_PERSCHIVL_Msk /*!< Periodic scheduling interval */
-#define USB_OTG_DCFG_PERSCHIVL_0 (0x1UL << USB_OTG_DCFG_PERSCHIVL_Pos) /*!< 0x01000000 */
-#define USB_OTG_DCFG_PERSCHIVL_1 (0x2UL << USB_OTG_DCFG_PERSCHIVL_Pos) /*!< 0x02000000 */
-
-/******************** Bit definition for USB_OTG_PCGCR register ********************/
-#define USB_OTG_PCGCR_STPPCLK_Pos (0U)
-#define USB_OTG_PCGCR_STPPCLK_Msk (0x1UL << USB_OTG_PCGCR_STPPCLK_Pos) /*!< 0x00000001 */
-#define USB_OTG_PCGCR_STPPCLK USB_OTG_PCGCR_STPPCLK_Msk /*!< Stop PHY clock */
-#define USB_OTG_PCGCR_GATEHCLK_Pos (1U)
-#define USB_OTG_PCGCR_GATEHCLK_Msk (0x1UL << USB_OTG_PCGCR_GATEHCLK_Pos) /*!< 0x00000002 */
-#define USB_OTG_PCGCR_GATEHCLK USB_OTG_PCGCR_GATEHCLK_Msk /*!< Gate HCLK */
-#define USB_OTG_PCGCR_PHYSUSP_Pos (4U)
-#define USB_OTG_PCGCR_PHYSUSP_Msk (0x1UL << USB_OTG_PCGCR_PHYSUSP_Pos) /*!< 0x00000010 */
-#define USB_OTG_PCGCR_PHYSUSP USB_OTG_PCGCR_PHYSUSP_Msk /*!< PHY suspended */
-
-/******************** Bit definition for USB_OTG_GOTGINT register ********************/
-#define USB_OTG_GOTGINT_SEDET_Pos (2U)
-#define USB_OTG_GOTGINT_SEDET_Msk (0x1UL << USB_OTG_GOTGINT_SEDET_Pos) /*!< 0x00000004 */
-#define USB_OTG_GOTGINT_SEDET USB_OTG_GOTGINT_SEDET_Msk /*!< Session end detected */
-#define USB_OTG_GOTGINT_SRSSCHG_Pos (8U)
-#define USB_OTG_GOTGINT_SRSSCHG_Msk (0x1UL << USB_OTG_GOTGINT_SRSSCHG_Pos) /*!< 0x00000100 */
-#define USB_OTG_GOTGINT_SRSSCHG USB_OTG_GOTGINT_SRSSCHG_Msk /*!< Session request success status change */
-#define USB_OTG_GOTGINT_HNSSCHG_Pos (9U)
-#define USB_OTG_GOTGINT_HNSSCHG_Msk (0x1UL << USB_OTG_GOTGINT_HNSSCHG_Pos) /*!< 0x00000200 */
-#define USB_OTG_GOTGINT_HNSSCHG USB_OTG_GOTGINT_HNSSCHG_Msk /*!< Host negotiation success status change */
-#define USB_OTG_GOTGINT_HNGDET_Pos (17U)
-#define USB_OTG_GOTGINT_HNGDET_Msk (0x1UL << USB_OTG_GOTGINT_HNGDET_Pos) /*!< 0x00020000 */
-#define USB_OTG_GOTGINT_HNGDET USB_OTG_GOTGINT_HNGDET_Msk /*!< Host negotiation detected */
-#define USB_OTG_GOTGINT_ADTOCHG_Pos (18U)
-#define USB_OTG_GOTGINT_ADTOCHG_Msk (0x1UL << USB_OTG_GOTGINT_ADTOCHG_Pos) /*!< 0x00040000 */
-#define USB_OTG_GOTGINT_ADTOCHG USB_OTG_GOTGINT_ADTOCHG_Msk /*!< A-device timeout change */
-#define USB_OTG_GOTGINT_DBCDNE_Pos (19U)
-#define USB_OTG_GOTGINT_DBCDNE_Msk (0x1UL << USB_OTG_GOTGINT_DBCDNE_Pos) /*!< 0x00080000 */
-#define USB_OTG_GOTGINT_DBCDNE USB_OTG_GOTGINT_DBCDNE_Msk /*!< Debounce done */
-
-/******************** Bit definition for USB_OTG_DCTL register ********************/
-#define USB_OTG_DCTL_RWUSIG_Pos (0U)
-#define USB_OTG_DCTL_RWUSIG_Msk (0x1UL << USB_OTG_DCTL_RWUSIG_Pos) /*!< 0x00000001 */
-#define USB_OTG_DCTL_RWUSIG USB_OTG_DCTL_RWUSIG_Msk /*!< Remote wakeup signaling */
-#define USB_OTG_DCTL_SDIS_Pos (1U)
-#define USB_OTG_DCTL_SDIS_Msk (0x1UL << USB_OTG_DCTL_SDIS_Pos) /*!< 0x00000002 */
-#define USB_OTG_DCTL_SDIS USB_OTG_DCTL_SDIS_Msk /*!< Soft disconnect */
-#define USB_OTG_DCTL_GINSTS_Pos (2U)
-#define USB_OTG_DCTL_GINSTS_Msk (0x1UL << USB_OTG_DCTL_GINSTS_Pos) /*!< 0x00000004 */
-#define USB_OTG_DCTL_GINSTS USB_OTG_DCTL_GINSTS_Msk /*!< Global IN NAK status */
-#define USB_OTG_DCTL_GONSTS_Pos (3U)
-#define USB_OTG_DCTL_GONSTS_Msk (0x1UL << USB_OTG_DCTL_GONSTS_Pos) /*!< 0x00000008 */
-#define USB_OTG_DCTL_GONSTS USB_OTG_DCTL_GONSTS_Msk /*!< Global OUT NAK status */
-
-#define USB_OTG_DCTL_TCTL_Pos (4U)
-#define USB_OTG_DCTL_TCTL_Msk (0x7UL << USB_OTG_DCTL_TCTL_Pos) /*!< 0x00000070 */
-#define USB_OTG_DCTL_TCTL USB_OTG_DCTL_TCTL_Msk /*!< Test control */
-#define USB_OTG_DCTL_TCTL_0 (0x1UL << USB_OTG_DCTL_TCTL_Pos) /*!< 0x00000010 */
-#define USB_OTG_DCTL_TCTL_1 (0x2UL << USB_OTG_DCTL_TCTL_Pos) /*!< 0x00000020 */
-#define USB_OTG_DCTL_TCTL_2 (0x4UL << USB_OTG_DCTL_TCTL_Pos) /*!< 0x00000040 */
-#define USB_OTG_DCTL_SGINAK_Pos (7U)
-#define USB_OTG_DCTL_SGINAK_Msk (0x1UL << USB_OTG_DCTL_SGINAK_Pos) /*!< 0x00000080 */
-#define USB_OTG_DCTL_SGINAK USB_OTG_DCTL_SGINAK_Msk /*!< Set global IN NAK */
-#define USB_OTG_DCTL_CGINAK_Pos (8U)
-#define USB_OTG_DCTL_CGINAK_Msk (0x1UL << USB_OTG_DCTL_CGINAK_Pos) /*!< 0x00000100 */
-#define USB_OTG_DCTL_CGINAK USB_OTG_DCTL_CGINAK_Msk /*!< Clear global IN NAK */
-#define USB_OTG_DCTL_SGONAK_Pos (9U)
-#define USB_OTG_DCTL_SGONAK_Msk (0x1UL << USB_OTG_DCTL_SGONAK_Pos) /*!< 0x00000200 */
-#define USB_OTG_DCTL_SGONAK USB_OTG_DCTL_SGONAK_Msk /*!< Set global OUT NAK */
-#define USB_OTG_DCTL_CGONAK_Pos (10U)
-#define USB_OTG_DCTL_CGONAK_Msk (0x1UL << USB_OTG_DCTL_CGONAK_Pos) /*!< 0x00000400 */
-#define USB_OTG_DCTL_CGONAK USB_OTG_DCTL_CGONAK_Msk /*!< Clear global OUT NAK */
-#define USB_OTG_DCTL_POPRGDNE_Pos (11U)
-#define USB_OTG_DCTL_POPRGDNE_Msk (0x1UL << USB_OTG_DCTL_POPRGDNE_Pos) /*!< 0x00000800 */
-#define USB_OTG_DCTL_POPRGDNE USB_OTG_DCTL_POPRGDNE_Msk /*!< Power-on programming done */
-
-/******************** Bit definition for USB_OTG_HFIR register ********************/
-#define USB_OTG_HFIR_FRIVL_Pos (0U)
-#define USB_OTG_HFIR_FRIVL_Msk (0xFFFFUL << USB_OTG_HFIR_FRIVL_Pos) /*!< 0x0000FFFF */
-#define USB_OTG_HFIR_FRIVL USB_OTG_HFIR_FRIVL_Msk /*!< Frame interval */
-
-/******************** Bit definition for USB_OTG_HFNUM register ********************/
-#define USB_OTG_HFNUM_FRNUM_Pos (0U)
-#define USB_OTG_HFNUM_FRNUM_Msk (0xFFFFUL << USB_OTG_HFNUM_FRNUM_Pos) /*!< 0x0000FFFF */
-#define USB_OTG_HFNUM_FRNUM USB_OTG_HFNUM_FRNUM_Msk /*!< Frame number */
-#define USB_OTG_HFNUM_FTREM_Pos (16U)
-#define USB_OTG_HFNUM_FTREM_Msk (0xFFFFUL << USB_OTG_HFNUM_FTREM_Pos) /*!< 0xFFFF0000 */
-#define USB_OTG_HFNUM_FTREM USB_OTG_HFNUM_FTREM_Msk /*!< Frame time remaining */
-
-/******************** Bit definition for USB_OTG_DSTS register ********************/
-#define USB_OTG_DSTS_SUSPSTS_Pos (0U)
-#define USB_OTG_DSTS_SUSPSTS_Msk (0x1UL << USB_OTG_DSTS_SUSPSTS_Pos) /*!< 0x00000001 */
-#define USB_OTG_DSTS_SUSPSTS USB_OTG_DSTS_SUSPSTS_Msk /*!< Suspend status */
-
-#define USB_OTG_DSTS_ENUMSPD_Pos (1U)
-#define USB_OTG_DSTS_ENUMSPD_Msk (0x3UL << USB_OTG_DSTS_ENUMSPD_Pos) /*!< 0x00000006 */
-#define USB_OTG_DSTS_ENUMSPD USB_OTG_DSTS_ENUMSPD_Msk /*!< Enumerated speed */
-#define USB_OTG_DSTS_ENUMSPD_0 (0x1UL << USB_OTG_DSTS_ENUMSPD_Pos) /*!< 0x00000002 */
-#define USB_OTG_DSTS_ENUMSPD_1 (0x2UL << USB_OTG_DSTS_ENUMSPD_Pos) /*!< 0x00000004 */
-#define USB_OTG_DSTS_EERR_Pos (3U)
-#define USB_OTG_DSTS_EERR_Msk (0x1UL << USB_OTG_DSTS_EERR_Pos) /*!< 0x00000008 */
-#define USB_OTG_DSTS_EERR USB_OTG_DSTS_EERR_Msk /*!< Erratic error */
-#define USB_OTG_DSTS_FNSOF_Pos (8U)
-#define USB_OTG_DSTS_FNSOF_Msk (0x3FFFUL << USB_OTG_DSTS_FNSOF_Pos) /*!< 0x003FFF00 */
-#define USB_OTG_DSTS_FNSOF USB_OTG_DSTS_FNSOF_Msk /*!< Frame number of the received SOF */
-
-/******************** Bit definition for USB_OTG_GAHBCFG register ********************/
-#define USB_OTG_GAHBCFG_GINT_Pos (0U)
-#define USB_OTG_GAHBCFG_GINT_Msk (0x1UL << USB_OTG_GAHBCFG_GINT_Pos) /*!< 0x00000001 */
-#define USB_OTG_GAHBCFG_GINT USB_OTG_GAHBCFG_GINT_Msk /*!< Global interrupt mask */
-#define USB_OTG_GAHBCFG_HBSTLEN_Pos (1U)
-#define USB_OTG_GAHBCFG_HBSTLEN_Msk (0xFUL << USB_OTG_GAHBCFG_HBSTLEN_Pos) /*!< 0x0000001E */
-#define USB_OTG_GAHBCFG_HBSTLEN USB_OTG_GAHBCFG_HBSTLEN_Msk /*!< Burst length/type */
-#define USB_OTG_GAHBCFG_HBSTLEN_0 (0x0UL << USB_OTG_GAHBCFG_HBSTLEN_Pos) /*!< Single */
-#define USB_OTG_GAHBCFG_HBSTLEN_1 (0x1UL << USB_OTG_GAHBCFG_HBSTLEN_Pos) /*!< INCR */
-#define USB_OTG_GAHBCFG_HBSTLEN_2 (0x3UL << USB_OTG_GAHBCFG_HBSTLEN_Pos) /*!< INCR4 */
-#define USB_OTG_GAHBCFG_HBSTLEN_3 (0x5UL << USB_OTG_GAHBCFG_HBSTLEN_Pos) /*!< INCR8 */
-#define USB_OTG_GAHBCFG_HBSTLEN_4 (0x7UL << USB_OTG_GAHBCFG_HBSTLEN_Pos) /*!< INCR16 */
-#define USB_OTG_GAHBCFG_DMAEN_Pos (5U)
-#define USB_OTG_GAHBCFG_DMAEN_Msk (0x1UL << USB_OTG_GAHBCFG_DMAEN_Pos) /*!< 0x00000020 */
-#define USB_OTG_GAHBCFG_DMAEN USB_OTG_GAHBCFG_DMAEN_Msk /*!< DMA enable */
-#define USB_OTG_GAHBCFG_TXFELVL_Pos (7U)
-#define USB_OTG_GAHBCFG_TXFELVL_Msk (0x1UL << USB_OTG_GAHBCFG_TXFELVL_Pos) /*!< 0x00000080 */
-#define USB_OTG_GAHBCFG_TXFELVL USB_OTG_GAHBCFG_TXFELVL_Msk /*!< TxFIFO empty level */
-#define USB_OTG_GAHBCFG_PTXFELVL_Pos (8U)
-#define USB_OTG_GAHBCFG_PTXFELVL_Msk (0x1UL << USB_OTG_GAHBCFG_PTXFELVL_Pos) /*!< 0x00000100 */
-#define USB_OTG_GAHBCFG_PTXFELVL USB_OTG_GAHBCFG_PTXFELVL_Msk /*!< Periodic TxFIFO empty level */
-
-/******************** Bit definition for USB_OTG_GUSBCFG register ********************/
-
-#define USB_OTG_GUSBCFG_TOCAL_Pos (0U)
-#define USB_OTG_GUSBCFG_TOCAL_Msk (0x7UL << USB_OTG_GUSBCFG_TOCAL_Pos) /*!< 0x00000007 */
-#define USB_OTG_GUSBCFG_TOCAL USB_OTG_GUSBCFG_TOCAL_Msk /*!< FS timeout calibration */
-#define USB_OTG_GUSBCFG_TOCAL_0 (0x1UL << USB_OTG_GUSBCFG_TOCAL_Pos) /*!< 0x00000001 */
-#define USB_OTG_GUSBCFG_TOCAL_1 (0x2UL << USB_OTG_GUSBCFG_TOCAL_Pos) /*!< 0x00000002 */
-#define USB_OTG_GUSBCFG_TOCAL_2 (0x4UL << USB_OTG_GUSBCFG_TOCAL_Pos) /*!< 0x00000004 */
-#define USB_OTG_GUSBCFG_PHYSEL_Pos (6U)
-#define USB_OTG_GUSBCFG_PHYSEL_Msk (0x1UL << USB_OTG_GUSBCFG_PHYSEL_Pos) /*!< 0x00000040 */
-#define USB_OTG_GUSBCFG_PHYSEL USB_OTG_GUSBCFG_PHYSEL_Msk /*!< USB 2.0 high-speed ULPI PHY or USB 1.1 full-speed serial transceiver select */
-#define USB_OTG_GUSBCFG_SRPCAP_Pos (8U)
-#define USB_OTG_GUSBCFG_SRPCAP_Msk (0x1UL << USB_OTG_GUSBCFG_SRPCAP_Pos) /*!< 0x00000100 */
-#define USB_OTG_GUSBCFG_SRPCAP USB_OTG_GUSBCFG_SRPCAP_Msk /*!< SRP-capable */
-#define USB_OTG_GUSBCFG_HNPCAP_Pos (9U)
-#define USB_OTG_GUSBCFG_HNPCAP_Msk (0x1UL << USB_OTG_GUSBCFG_HNPCAP_Pos) /*!< 0x00000200 */
-#define USB_OTG_GUSBCFG_HNPCAP USB_OTG_GUSBCFG_HNPCAP_Msk /*!< HNP-capable */
-#define USB_OTG_GUSBCFG_TRDT_Pos (10U)
-#define USB_OTG_GUSBCFG_TRDT_Msk (0xFUL << USB_OTG_GUSBCFG_TRDT_Pos) /*!< 0x00003C00 */
-#define USB_OTG_GUSBCFG_TRDT USB_OTG_GUSBCFG_TRDT_Msk /*!< USB turnaround time */
-#define USB_OTG_GUSBCFG_TRDT_0 (0x1UL << USB_OTG_GUSBCFG_TRDT_Pos) /*!< 0x00000400 */
-#define USB_OTG_GUSBCFG_TRDT_1 (0x2UL << USB_OTG_GUSBCFG_TRDT_Pos) /*!< 0x00000800 */
-#define USB_OTG_GUSBCFG_TRDT_2 (0x4UL << USB_OTG_GUSBCFG_TRDT_Pos) /*!< 0x00001000 */
-#define USB_OTG_GUSBCFG_TRDT_3 (0x8UL << USB_OTG_GUSBCFG_TRDT_Pos) /*!< 0x00002000 */
-#define USB_OTG_GUSBCFG_PHYLPCS_Pos (15U)
-#define USB_OTG_GUSBCFG_PHYLPCS_Msk (0x1UL << USB_OTG_GUSBCFG_PHYLPCS_Pos) /*!< 0x00008000 */
-#define USB_OTG_GUSBCFG_PHYLPCS USB_OTG_GUSBCFG_PHYLPCS_Msk /*!< PHY Low-power clock select */
-#define USB_OTG_GUSBCFG_ULPIFSLS_Pos (17U)
-#define USB_OTG_GUSBCFG_ULPIFSLS_Msk (0x1UL << USB_OTG_GUSBCFG_ULPIFSLS_Pos) /*!< 0x00020000 */
-#define USB_OTG_GUSBCFG_ULPIFSLS USB_OTG_GUSBCFG_ULPIFSLS_Msk /*!< ULPI FS/LS select */
-#define USB_OTG_GUSBCFG_ULPIAR_Pos (18U)
-#define USB_OTG_GUSBCFG_ULPIAR_Msk (0x1UL << USB_OTG_GUSBCFG_ULPIAR_Pos) /*!< 0x00040000 */
-#define USB_OTG_GUSBCFG_ULPIAR USB_OTG_GUSBCFG_ULPIAR_Msk /*!< ULPI Auto-resume */
-#define USB_OTG_GUSBCFG_ULPICSM_Pos (19U)
-#define USB_OTG_GUSBCFG_ULPICSM_Msk (0x1UL << USB_OTG_GUSBCFG_ULPICSM_Pos) /*!< 0x00080000 */
-#define USB_OTG_GUSBCFG_ULPICSM USB_OTG_GUSBCFG_ULPICSM_Msk /*!< ULPI Clock SuspendM */
-#define USB_OTG_GUSBCFG_ULPIEVBUSD_Pos (20U)
-#define USB_OTG_GUSBCFG_ULPIEVBUSD_Msk (0x1UL << USB_OTG_GUSBCFG_ULPIEVBUSD_Pos) /*!< 0x00100000 */
-#define USB_OTG_GUSBCFG_ULPIEVBUSD USB_OTG_GUSBCFG_ULPIEVBUSD_Msk /*!< ULPI External VBUS Drive */
-#define USB_OTG_GUSBCFG_ULPIEVBUSI_Pos (21U)
-#define USB_OTG_GUSBCFG_ULPIEVBUSI_Msk (0x1UL << USB_OTG_GUSBCFG_ULPIEVBUSI_Pos) /*!< 0x00200000 */
-#define USB_OTG_GUSBCFG_ULPIEVBUSI USB_OTG_GUSBCFG_ULPIEVBUSI_Msk /*!< ULPI external VBUS indicator */
-#define USB_OTG_GUSBCFG_TSDPS_Pos (22U)
-#define USB_OTG_GUSBCFG_TSDPS_Msk (0x1UL << USB_OTG_GUSBCFG_TSDPS_Pos) /*!< 0x00400000 */
-#define USB_OTG_GUSBCFG_TSDPS USB_OTG_GUSBCFG_TSDPS_Msk /*!< TermSel DLine pulsing selection */
-#define USB_OTG_GUSBCFG_PCCI_Pos (23U)
-#define USB_OTG_GUSBCFG_PCCI_Msk (0x1UL << USB_OTG_GUSBCFG_PCCI_Pos) /*!< 0x00800000 */
-#define USB_OTG_GUSBCFG_PCCI USB_OTG_GUSBCFG_PCCI_Msk /*!< Indicator complement */
-#define USB_OTG_GUSBCFG_PTCI_Pos (24U)
-#define USB_OTG_GUSBCFG_PTCI_Msk (0x1UL << USB_OTG_GUSBCFG_PTCI_Pos) /*!< 0x01000000 */
-#define USB_OTG_GUSBCFG_PTCI USB_OTG_GUSBCFG_PTCI_Msk /*!< Indicator pass through */
-#define USB_OTG_GUSBCFG_ULPIIPD_Pos (25U)
-#define USB_OTG_GUSBCFG_ULPIIPD_Msk (0x1UL << USB_OTG_GUSBCFG_ULPIIPD_Pos) /*!< 0x02000000 */
-#define USB_OTG_GUSBCFG_ULPIIPD USB_OTG_GUSBCFG_ULPIIPD_Msk /*!< ULPI interface protect disable */
-#define USB_OTG_GUSBCFG_FHMOD_Pos (29U)
-#define USB_OTG_GUSBCFG_FHMOD_Msk (0x1UL << USB_OTG_GUSBCFG_FHMOD_Pos) /*!< 0x20000000 */
-#define USB_OTG_GUSBCFG_FHMOD USB_OTG_GUSBCFG_FHMOD_Msk /*!< Forced host mode */
-#define USB_OTG_GUSBCFG_FDMOD_Pos (30U)
-#define USB_OTG_GUSBCFG_FDMOD_Msk (0x1UL << USB_OTG_GUSBCFG_FDMOD_Pos) /*!< 0x40000000 */
-#define USB_OTG_GUSBCFG_FDMOD USB_OTG_GUSBCFG_FDMOD_Msk /*!< Forced peripheral mode */
-#define USB_OTG_GUSBCFG_CTXPKT_Pos (31U)
-#define USB_OTG_GUSBCFG_CTXPKT_Msk (0x1UL << USB_OTG_GUSBCFG_CTXPKT_Pos) /*!< 0x80000000 */
-#define USB_OTG_GUSBCFG_CTXPKT USB_OTG_GUSBCFG_CTXPKT_Msk /*!< Corrupt Tx packet */
-
-/******************** Bit definition for USB_OTG_GRSTCTL register ********************/
-#define USB_OTG_GRSTCTL_CSRST_Pos (0U)
-#define USB_OTG_GRSTCTL_CSRST_Msk (0x1UL << USB_OTG_GRSTCTL_CSRST_Pos) /*!< 0x00000001 */
-#define USB_OTG_GRSTCTL_CSRST USB_OTG_GRSTCTL_CSRST_Msk /*!< Core soft reset */
-#define USB_OTG_GRSTCTL_HSRST_Pos (1U)
-#define USB_OTG_GRSTCTL_HSRST_Msk (0x1UL << USB_OTG_GRSTCTL_HSRST_Pos) /*!< 0x00000002 */
-#define USB_OTG_GRSTCTL_HSRST USB_OTG_GRSTCTL_HSRST_Msk /*!< HCLK soft reset */
-#define USB_OTG_GRSTCTL_FCRST_Pos (2U)
-#define USB_OTG_GRSTCTL_FCRST_Msk (0x1UL << USB_OTG_GRSTCTL_FCRST_Pos) /*!< 0x00000004 */
-#define USB_OTG_GRSTCTL_FCRST USB_OTG_GRSTCTL_FCRST_Msk /*!< Host frame counter reset */
-#define USB_OTG_GRSTCTL_RXFFLSH_Pos (4U)
-#define USB_OTG_GRSTCTL_RXFFLSH_Msk (0x1UL << USB_OTG_GRSTCTL_RXFFLSH_Pos) /*!< 0x00000010 */
-#define USB_OTG_GRSTCTL_RXFFLSH USB_OTG_GRSTCTL_RXFFLSH_Msk /*!< RxFIFO flush */
-#define USB_OTG_GRSTCTL_TXFFLSH_Pos (5U)
-#define USB_OTG_GRSTCTL_TXFFLSH_Msk (0x1UL << USB_OTG_GRSTCTL_TXFFLSH_Pos) /*!< 0x00000020 */
-#define USB_OTG_GRSTCTL_TXFFLSH USB_OTG_GRSTCTL_TXFFLSH_Msk /*!< TxFIFO flush */
-
-
-#define USB_OTG_GRSTCTL_TXFNUM_Pos (6U)
-#define USB_OTG_GRSTCTL_TXFNUM_Msk (0x1FUL << USB_OTG_GRSTCTL_TXFNUM_Pos) /*!< 0x000007C0 */
-#define USB_OTG_GRSTCTL_TXFNUM USB_OTG_GRSTCTL_TXFNUM_Msk /*!< TxFIFO number */
-#define USB_OTG_GRSTCTL_TXFNUM_0 (0x01UL << USB_OTG_GRSTCTL_TXFNUM_Pos) /*!< 0x00000040 */
-#define USB_OTG_GRSTCTL_TXFNUM_1 (0x02UL << USB_OTG_GRSTCTL_TXFNUM_Pos) /*!< 0x00000080 */
-#define USB_OTG_GRSTCTL_TXFNUM_2 (0x04UL << USB_OTG_GRSTCTL_TXFNUM_Pos) /*!< 0x00000100 */
-#define USB_OTG_GRSTCTL_TXFNUM_3 (0x08UL << USB_OTG_GRSTCTL_TXFNUM_Pos) /*!< 0x00000200 */
-#define USB_OTG_GRSTCTL_TXFNUM_4 (0x10UL << USB_OTG_GRSTCTL_TXFNUM_Pos) /*!< 0x00000400 */
-#define USB_OTG_GRSTCTL_DMAREQ_Pos (30U)
-#define USB_OTG_GRSTCTL_DMAREQ_Msk (0x1UL << USB_OTG_GRSTCTL_DMAREQ_Pos) /*!< 0x40000000 */
-#define USB_OTG_GRSTCTL_DMAREQ USB_OTG_GRSTCTL_DMAREQ_Msk /*!< DMA request signal */
-#define USB_OTG_GRSTCTL_AHBIDL_Pos (31U)
-#define USB_OTG_GRSTCTL_AHBIDL_Msk (0x1UL << USB_OTG_GRSTCTL_AHBIDL_Pos) /*!< 0x80000000 */
-#define USB_OTG_GRSTCTL_AHBIDL USB_OTG_GRSTCTL_AHBIDL_Msk /*!< AHB master idle */
-
-/******************** Bit definition for USB_OTG_DIEPMSK register ********************/
-#define USB_OTG_DIEPMSK_XFRCM_Pos (0U)
-#define USB_OTG_DIEPMSK_XFRCM_Msk (0x1UL << USB_OTG_DIEPMSK_XFRCM_Pos) /*!< 0x00000001 */
-#define USB_OTG_DIEPMSK_XFRCM USB_OTG_DIEPMSK_XFRCM_Msk /*!< Transfer completed interrupt mask */
-#define USB_OTG_DIEPMSK_EPDM_Pos (1U)
-#define USB_OTG_DIEPMSK_EPDM_Msk (0x1UL << USB_OTG_DIEPMSK_EPDM_Pos) /*!< 0x00000002 */
-#define USB_OTG_DIEPMSK_EPDM USB_OTG_DIEPMSK_EPDM_Msk /*!< Endpoint disabled interrupt mask */
-#define USB_OTG_DIEPMSK_TOM_Pos (3U)
-#define USB_OTG_DIEPMSK_TOM_Msk (0x1UL << USB_OTG_DIEPMSK_TOM_Pos) /*!< 0x00000008 */
-#define USB_OTG_DIEPMSK_TOM USB_OTG_DIEPMSK_TOM_Msk /*!< Timeout condition mask (nonisochronous endpoints) */
-#define USB_OTG_DIEPMSK_ITTXFEMSK_Pos (4U)
-#define USB_OTG_DIEPMSK_ITTXFEMSK_Msk (0x1UL << USB_OTG_DIEPMSK_ITTXFEMSK_Pos) /*!< 0x00000010 */
-#define USB_OTG_DIEPMSK_ITTXFEMSK USB_OTG_DIEPMSK_ITTXFEMSK_Msk /*!< IN token received when TxFIFO empty mask */
-#define USB_OTG_DIEPMSK_INEPNMM_Pos (5U)
-#define USB_OTG_DIEPMSK_INEPNMM_Msk (0x1UL << USB_OTG_DIEPMSK_INEPNMM_Pos) /*!< 0x00000020 */
-#define USB_OTG_DIEPMSK_INEPNMM USB_OTG_DIEPMSK_INEPNMM_Msk /*!< IN token received with EP mismatch mask */
-#define USB_OTG_DIEPMSK_INEPNEM_Pos (6U)
-#define USB_OTG_DIEPMSK_INEPNEM_Msk (0x1UL << USB_OTG_DIEPMSK_INEPNEM_Pos) /*!< 0x00000040 */
-#define USB_OTG_DIEPMSK_INEPNEM USB_OTG_DIEPMSK_INEPNEM_Msk /*!< IN endpoint NAK effective mask */
-#define USB_OTG_DIEPMSK_TXFURM_Pos (8U)
-#define USB_OTG_DIEPMSK_TXFURM_Msk (0x1UL << USB_OTG_DIEPMSK_TXFURM_Pos) /*!< 0x00000100 */
-#define USB_OTG_DIEPMSK_TXFURM USB_OTG_DIEPMSK_TXFURM_Msk /*!< FIFO underrun mask */
-#define USB_OTG_DIEPMSK_BIM_Pos (9U)
-#define USB_OTG_DIEPMSK_BIM_Msk (0x1UL << USB_OTG_DIEPMSK_BIM_Pos) /*!< 0x00000200 */
-#define USB_OTG_DIEPMSK_BIM USB_OTG_DIEPMSK_BIM_Msk /*!< BNA interrupt mask */
-
-/******************** Bit definition for USB_OTG_HPTXSTS register ********************/
-#define USB_OTG_HPTXSTS_PTXFSAVL_Pos (0U)
-#define USB_OTG_HPTXSTS_PTXFSAVL_Msk (0xFFFFUL << USB_OTG_HPTXSTS_PTXFSAVL_Pos) /*!< 0x0000FFFF */
-#define USB_OTG_HPTXSTS_PTXFSAVL USB_OTG_HPTXSTS_PTXFSAVL_Msk /*!< Periodic transmit data FIFO space available */
-#define USB_OTG_HPTXSTS_PTXQSAV_Pos (16U)
-#define USB_OTG_HPTXSTS_PTXQSAV_Msk (0xFFUL << USB_OTG_HPTXSTS_PTXQSAV_Pos) /*!< 0x00FF0000 */
-#define USB_OTG_HPTXSTS_PTXQSAV USB_OTG_HPTXSTS_PTXQSAV_Msk /*!< Periodic transmit request queue space available */
-#define USB_OTG_HPTXSTS_PTXQSAV_0 (0x01UL << USB_OTG_HPTXSTS_PTXQSAV_Pos) /*!< 0x00010000 */
-#define USB_OTG_HPTXSTS_PTXQSAV_1 (0x02UL << USB_OTG_HPTXSTS_PTXQSAV_Pos) /*!< 0x00020000 */
-#define USB_OTG_HPTXSTS_PTXQSAV_2 (0x04UL << USB_OTG_HPTXSTS_PTXQSAV_Pos) /*!< 0x00040000 */
-#define USB_OTG_HPTXSTS_PTXQSAV_3 (0x08UL << USB_OTG_HPTXSTS_PTXQSAV_Pos) /*!< 0x00080000 */
-#define USB_OTG_HPTXSTS_PTXQSAV_4 (0x10UL << USB_OTG_HPTXSTS_PTXQSAV_Pos) /*!< 0x00100000 */
-#define USB_OTG_HPTXSTS_PTXQSAV_5 (0x20UL << USB_OTG_HPTXSTS_PTXQSAV_Pos) /*!< 0x00200000 */
-#define USB_OTG_HPTXSTS_PTXQSAV_6 (0x40UL << USB_OTG_HPTXSTS_PTXQSAV_Pos) /*!< 0x00400000 */
-#define USB_OTG_HPTXSTS_PTXQSAV_7 (0x80UL << USB_OTG_HPTXSTS_PTXQSAV_Pos) /*!< 0x00800000 */
-
-#define USB_OTG_HPTXSTS_PTXQTOP_Pos (24U)
-#define USB_OTG_HPTXSTS_PTXQTOP_Msk (0xFFUL << USB_OTG_HPTXSTS_PTXQTOP_Pos) /*!< 0xFF000000 */
-#define USB_OTG_HPTXSTS_PTXQTOP USB_OTG_HPTXSTS_PTXQTOP_Msk /*!< Top of the periodic transmit request queue */
-#define USB_OTG_HPTXSTS_PTXQTOP_0 (0x01UL << USB_OTG_HPTXSTS_PTXQTOP_Pos) /*!< 0x01000000 */
-#define USB_OTG_HPTXSTS_PTXQTOP_1 (0x02UL << USB_OTG_HPTXSTS_PTXQTOP_Pos) /*!< 0x02000000 */
-#define USB_OTG_HPTXSTS_PTXQTOP_2 (0x04UL << USB_OTG_HPTXSTS_PTXQTOP_Pos) /*!< 0x04000000 */
-#define USB_OTG_HPTXSTS_PTXQTOP_3 (0x08UL << USB_OTG_HPTXSTS_PTXQTOP_Pos) /*!< 0x08000000 */
-#define USB_OTG_HPTXSTS_PTXQTOP_4 (0x10UL << USB_OTG_HPTXSTS_PTXQTOP_Pos) /*!< 0x10000000 */
-#define USB_OTG_HPTXSTS_PTXQTOP_5 (0x20UL << USB_OTG_HPTXSTS_PTXQTOP_Pos) /*!< 0x20000000 */
-#define USB_OTG_HPTXSTS_PTXQTOP_6 (0x40UL << USB_OTG_HPTXSTS_PTXQTOP_Pos) /*!< 0x40000000 */
-#define USB_OTG_HPTXSTS_PTXQTOP_7 (0x80UL << USB_OTG_HPTXSTS_PTXQTOP_Pos) /*!< 0x80000000 */
-
-/******************** Bit definition for USB_OTG_HAINT register ********************/
-#define USB_OTG_HAINT_HAINT_Pos (0U)
-#define USB_OTG_HAINT_HAINT_Msk (0xFFFFUL << USB_OTG_HAINT_HAINT_Pos) /*!< 0x0000FFFF */
-#define USB_OTG_HAINT_HAINT USB_OTG_HAINT_HAINT_Msk /*!< Channel interrupts */
-
-/******************** Bit definition for USB_OTG_DOEPMSK register ********************/
-#define USB_OTG_DOEPMSK_XFRCM_Pos (0U)
-#define USB_OTG_DOEPMSK_XFRCM_Msk (0x1UL << USB_OTG_DOEPMSK_XFRCM_Pos) /*!< 0x00000001 */
-#define USB_OTG_DOEPMSK_XFRCM USB_OTG_DOEPMSK_XFRCM_Msk /*!< Transfer completed interrupt mask */
-#define USB_OTG_DOEPMSK_EPDM_Pos (1U)
-#define USB_OTG_DOEPMSK_EPDM_Msk (0x1UL << USB_OTG_DOEPMSK_EPDM_Pos) /*!< 0x00000002 */
-#define USB_OTG_DOEPMSK_EPDM USB_OTG_DOEPMSK_EPDM_Msk /*!< Endpoint disabled interrupt mask */
-#define USB_OTG_DOEPMSK_AHBERRM_Pos (2U)
-#define USB_OTG_DOEPMSK_AHBERRM_Msk (0x1UL << USB_OTG_DOEPMSK_AHBERRM_Pos) /*!< 0x00000004 */
-#define USB_OTG_DOEPMSK_AHBERRM USB_OTG_DOEPMSK_AHBERRM_Msk /*!< OUT transaction AHB Error interrupt mask */
-#define USB_OTG_DOEPMSK_STUPM_Pos (3U)
-#define USB_OTG_DOEPMSK_STUPM_Msk (0x1UL << USB_OTG_DOEPMSK_STUPM_Pos) /*!< 0x00000008 */
-#define USB_OTG_DOEPMSK_STUPM USB_OTG_DOEPMSK_STUPM_Msk /*!< SETUP phase done mask */
-#define USB_OTG_DOEPMSK_OTEPDM_Pos (4U)
-#define USB_OTG_DOEPMSK_OTEPDM_Msk (0x1UL << USB_OTG_DOEPMSK_OTEPDM_Pos) /*!< 0x00000010 */
-#define USB_OTG_DOEPMSK_OTEPDM USB_OTG_DOEPMSK_OTEPDM_Msk /*!< OUT token received when endpoint disabled mask */
-#define USB_OTG_DOEPMSK_OTEPSPRM_Pos (5U)
-#define USB_OTG_DOEPMSK_OTEPSPRM_Msk (0x1UL << USB_OTG_DOEPMSK_OTEPSPRM_Pos) /*!< 0x00000020 */
-#define USB_OTG_DOEPMSK_OTEPSPRM USB_OTG_DOEPMSK_OTEPSPRM_Msk /*!< Status Phase Received mask */
-#define USB_OTG_DOEPMSK_B2BSTUP_Pos (6U)
-#define USB_OTG_DOEPMSK_B2BSTUP_Msk (0x1UL << USB_OTG_DOEPMSK_B2BSTUP_Pos) /*!< 0x00000040 */
-#define USB_OTG_DOEPMSK_B2BSTUP USB_OTG_DOEPMSK_B2BSTUP_Msk /*!< Back-to-back SETUP packets received mask */
-#define USB_OTG_DOEPMSK_OPEM_Pos (8U)
-#define USB_OTG_DOEPMSK_OPEM_Msk (0x1UL << USB_OTG_DOEPMSK_OPEM_Pos) /*!< 0x00000100 */
-#define USB_OTG_DOEPMSK_OPEM USB_OTG_DOEPMSK_OPEM_Msk /*!< OUT packet error mask */
-#define USB_OTG_DOEPMSK_BOIM_Pos (9U)
-#define USB_OTG_DOEPMSK_BOIM_Msk (0x1UL << USB_OTG_DOEPMSK_BOIM_Pos) /*!< 0x00000200 */
-#define USB_OTG_DOEPMSK_BOIM USB_OTG_DOEPMSK_BOIM_Msk /*!< BNA interrupt mask */
-#define USB_OTG_DOEPMSK_BERRM_Pos (12U)
-#define USB_OTG_DOEPMSK_BERRM_Msk (0x1UL << USB_OTG_DOEPMSK_BERRM_Pos) /*!< 0x00001000 */
-#define USB_OTG_DOEPMSK_BERRM USB_OTG_DOEPMSK_BERRM_Msk /*!< Babble error interrupt mask */
-#define USB_OTG_DOEPMSK_NAKM_Pos (13U)
-#define USB_OTG_DOEPMSK_NAKM_Msk (0x1UL << USB_OTG_DOEPMSK_NAKM_Pos) /*!< 0x00002000 */
-#define USB_OTG_DOEPMSK_NAKM USB_OTG_DOEPMSK_NAKM_Msk /*!< OUT Packet NAK interrupt mask */
-#define USB_OTG_DOEPMSK_NYETM_Pos (14U)
-#define USB_OTG_DOEPMSK_NYETM_Msk (0x1UL << USB_OTG_DOEPMSK_NYETM_Pos) /*!< 0x00004000 */
-#define USB_OTG_DOEPMSK_NYETM USB_OTG_DOEPMSK_NYETM_Msk /*!< NYET interrupt mask */
-/******************** Bit definition for USB_OTG_GINTSTS register ********************/
-#define USB_OTG_GINTSTS_CMOD_Pos (0U)
-#define USB_OTG_GINTSTS_CMOD_Msk (0x1UL << USB_OTG_GINTSTS_CMOD_Pos) /*!< 0x00000001 */
-#define USB_OTG_GINTSTS_CMOD USB_OTG_GINTSTS_CMOD_Msk /*!< Current mode of operation */
-#define USB_OTG_GINTSTS_MMIS_Pos (1U)
-#define USB_OTG_GINTSTS_MMIS_Msk (0x1UL << USB_OTG_GINTSTS_MMIS_Pos) /*!< 0x00000002 */
-#define USB_OTG_GINTSTS_MMIS USB_OTG_GINTSTS_MMIS_Msk /*!< Mode mismatch interrupt */
-#define USB_OTG_GINTSTS_OTGINT_Pos (2U)
-#define USB_OTG_GINTSTS_OTGINT_Msk (0x1UL << USB_OTG_GINTSTS_OTGINT_Pos) /*!< 0x00000004 */
-#define USB_OTG_GINTSTS_OTGINT USB_OTG_GINTSTS_OTGINT_Msk /*!< OTG interrupt */
-#define USB_OTG_GINTSTS_SOF_Pos (3U)
-#define USB_OTG_GINTSTS_SOF_Msk (0x1UL << USB_OTG_GINTSTS_SOF_Pos) /*!< 0x00000008 */
-#define USB_OTG_GINTSTS_SOF USB_OTG_GINTSTS_SOF_Msk /*!< Start of frame */
-#define USB_OTG_GINTSTS_RXFLVL_Pos (4U)
-#define USB_OTG_GINTSTS_RXFLVL_Msk (0x1UL << USB_OTG_GINTSTS_RXFLVL_Pos) /*!< 0x00000010 */
-#define USB_OTG_GINTSTS_RXFLVL USB_OTG_GINTSTS_RXFLVL_Msk /*!< RxFIFO nonempty */
-#define USB_OTG_GINTSTS_NPTXFE_Pos (5U)
-#define USB_OTG_GINTSTS_NPTXFE_Msk (0x1UL << USB_OTG_GINTSTS_NPTXFE_Pos) /*!< 0x00000020 */
-#define USB_OTG_GINTSTS_NPTXFE USB_OTG_GINTSTS_NPTXFE_Msk /*!< Nonperiodic TxFIFO empty */
-#define USB_OTG_GINTSTS_GINAKEFF_Pos (6U)
-#define USB_OTG_GINTSTS_GINAKEFF_Msk (0x1UL << USB_OTG_GINTSTS_GINAKEFF_Pos) /*!< 0x00000040 */
-#define USB_OTG_GINTSTS_GINAKEFF USB_OTG_GINTSTS_GINAKEFF_Msk /*!< Global IN nonperiodic NAK effective */
-#define USB_OTG_GINTSTS_BOUTNAKEFF_Pos (7U)
-#define USB_OTG_GINTSTS_BOUTNAKEFF_Msk (0x1UL << USB_OTG_GINTSTS_BOUTNAKEFF_Pos) /*!< 0x00000080 */
-#define USB_OTG_GINTSTS_BOUTNAKEFF USB_OTG_GINTSTS_BOUTNAKEFF_Msk /*!< Global OUT NAK effective */
-#define USB_OTG_GINTSTS_ESUSP_Pos (10U)
-#define USB_OTG_GINTSTS_ESUSP_Msk (0x1UL << USB_OTG_GINTSTS_ESUSP_Pos) /*!< 0x00000400 */
-#define USB_OTG_GINTSTS_ESUSP USB_OTG_GINTSTS_ESUSP_Msk /*!< Early suspend */
-#define USB_OTG_GINTSTS_USBSUSP_Pos (11U)
-#define USB_OTG_GINTSTS_USBSUSP_Msk (0x1UL << USB_OTG_GINTSTS_USBSUSP_Pos) /*!< 0x00000800 */
-#define USB_OTG_GINTSTS_USBSUSP USB_OTG_GINTSTS_USBSUSP_Msk /*!< USB suspend */
-#define USB_OTG_GINTSTS_USBRST_Pos (12U)
-#define USB_OTG_GINTSTS_USBRST_Msk (0x1UL << USB_OTG_GINTSTS_USBRST_Pos) /*!< 0x00001000 */
-#define USB_OTG_GINTSTS_USBRST USB_OTG_GINTSTS_USBRST_Msk /*!< USB reset */
-#define USB_OTG_GINTSTS_ENUMDNE_Pos (13U)
-#define USB_OTG_GINTSTS_ENUMDNE_Msk (0x1UL << USB_OTG_GINTSTS_ENUMDNE_Pos) /*!< 0x00002000 */
-#define USB_OTG_GINTSTS_ENUMDNE USB_OTG_GINTSTS_ENUMDNE_Msk /*!< Enumeration done */
-#define USB_OTG_GINTSTS_ISOODRP_Pos (14U)
-#define USB_OTG_GINTSTS_ISOODRP_Msk (0x1UL << USB_OTG_GINTSTS_ISOODRP_Pos) /*!< 0x00004000 */
-#define USB_OTG_GINTSTS_ISOODRP USB_OTG_GINTSTS_ISOODRP_Msk /*!< Isochronous OUT packet dropped interrupt */
-#define USB_OTG_GINTSTS_EOPF_Pos (15U)
-#define USB_OTG_GINTSTS_EOPF_Msk (0x1UL << USB_OTG_GINTSTS_EOPF_Pos) /*!< 0x00008000 */
-#define USB_OTG_GINTSTS_EOPF USB_OTG_GINTSTS_EOPF_Msk /*!< End of periodic frame interrupt */
-#define USB_OTG_GINTSTS_IEPINT_Pos (18U)
-#define USB_OTG_GINTSTS_IEPINT_Msk (0x1UL << USB_OTG_GINTSTS_IEPINT_Pos) /*!< 0x00040000 */
-#define USB_OTG_GINTSTS_IEPINT USB_OTG_GINTSTS_IEPINT_Msk /*!< IN endpoint interrupt */
-#define USB_OTG_GINTSTS_OEPINT_Pos (19U)
-#define USB_OTG_GINTSTS_OEPINT_Msk (0x1UL << USB_OTG_GINTSTS_OEPINT_Pos) /*!< 0x00080000 */
-#define USB_OTG_GINTSTS_OEPINT USB_OTG_GINTSTS_OEPINT_Msk /*!< OUT endpoint interrupt */
-#define USB_OTG_GINTSTS_IISOIXFR_Pos (20U)
-#define USB_OTG_GINTSTS_IISOIXFR_Msk (0x1UL << USB_OTG_GINTSTS_IISOIXFR_Pos) /*!< 0x00100000 */
-#define USB_OTG_GINTSTS_IISOIXFR USB_OTG_GINTSTS_IISOIXFR_Msk /*!< Incomplete isochronous IN transfer */
-#define USB_OTG_GINTSTS_PXFR_INCOMPISOOUT_Pos (21U)
-#define USB_OTG_GINTSTS_PXFR_INCOMPISOOUT_Msk (0x1UL << USB_OTG_GINTSTS_PXFR_INCOMPISOOUT_Pos) /*!< 0x00200000 */
-#define USB_OTG_GINTSTS_PXFR_INCOMPISOOUT USB_OTG_GINTSTS_PXFR_INCOMPISOOUT_Msk /*!< Incomplete periodic transfer */
-#define USB_OTG_GINTSTS_DATAFSUSP_Pos (22U)
-#define USB_OTG_GINTSTS_DATAFSUSP_Msk (0x1UL << USB_OTG_GINTSTS_DATAFSUSP_Pos) /*!< 0x00400000 */
-#define USB_OTG_GINTSTS_DATAFSUSP USB_OTG_GINTSTS_DATAFSUSP_Msk /*!< Data fetch suspended */
-#define USB_OTG_GINTSTS_HPRTINT_Pos (24U)
-#define USB_OTG_GINTSTS_HPRTINT_Msk (0x1UL << USB_OTG_GINTSTS_HPRTINT_Pos) /*!< 0x01000000 */
-#define USB_OTG_GINTSTS_HPRTINT USB_OTG_GINTSTS_HPRTINT_Msk /*!< Host port interrupt */
-#define USB_OTG_GINTSTS_HCINT_Pos (25U)
-#define USB_OTG_GINTSTS_HCINT_Msk (0x1UL << USB_OTG_GINTSTS_HCINT_Pos) /*!< 0x02000000 */
-#define USB_OTG_GINTSTS_HCINT USB_OTG_GINTSTS_HCINT_Msk /*!< Host channels interrupt */
-#define USB_OTG_GINTSTS_PTXFE_Pos (26U)
-#define USB_OTG_GINTSTS_PTXFE_Msk (0x1UL << USB_OTG_GINTSTS_PTXFE_Pos) /*!< 0x04000000 */
-#define USB_OTG_GINTSTS_PTXFE USB_OTG_GINTSTS_PTXFE_Msk /*!< Periodic TxFIFO empty */
-#define USB_OTG_GINTSTS_CIDSCHG_Pos (28U)
-#define USB_OTG_GINTSTS_CIDSCHG_Msk (0x1UL << USB_OTG_GINTSTS_CIDSCHG_Pos) /*!< 0x10000000 */
-#define USB_OTG_GINTSTS_CIDSCHG USB_OTG_GINTSTS_CIDSCHG_Msk /*!< Connector ID status change */
-#define USB_OTG_GINTSTS_DISCINT_Pos (29U)
-#define USB_OTG_GINTSTS_DISCINT_Msk (0x1UL << USB_OTG_GINTSTS_DISCINT_Pos) /*!< 0x20000000 */
-#define USB_OTG_GINTSTS_DISCINT USB_OTG_GINTSTS_DISCINT_Msk /*!< Disconnect detected interrupt */
-#define USB_OTG_GINTSTS_SRQINT_Pos (30U)
-#define USB_OTG_GINTSTS_SRQINT_Msk (0x1UL << USB_OTG_GINTSTS_SRQINT_Pos) /*!< 0x40000000 */
-#define USB_OTG_GINTSTS_SRQINT USB_OTG_GINTSTS_SRQINT_Msk /*!< Session request/new session detected interrupt */
-#define USB_OTG_GINTSTS_WKUINT_Pos (31U)
-#define USB_OTG_GINTSTS_WKUINT_Msk (0x1UL << USB_OTG_GINTSTS_WKUINT_Pos) /*!< 0x80000000 */
-#define USB_OTG_GINTSTS_WKUINT USB_OTG_GINTSTS_WKUINT_Msk /*!< Resume/remote wakeup detected interrupt */
-
-/******************** Bit definition for USB_OTG_GINTMSK register ********************/
-#define USB_OTG_GINTMSK_MMISM_Pos (1U)
-#define USB_OTG_GINTMSK_MMISM_Msk (0x1UL << USB_OTG_GINTMSK_MMISM_Pos) /*!< 0x00000002 */
-#define USB_OTG_GINTMSK_MMISM USB_OTG_GINTMSK_MMISM_Msk /*!< Mode mismatch interrupt mask */
-#define USB_OTG_GINTMSK_OTGINT_Pos (2U)
-#define USB_OTG_GINTMSK_OTGINT_Msk (0x1UL << USB_OTG_GINTMSK_OTGINT_Pos) /*!< 0x00000004 */
-#define USB_OTG_GINTMSK_OTGINT USB_OTG_GINTMSK_OTGINT_Msk /*!< OTG interrupt mask */
-#define USB_OTG_GINTMSK_SOFM_Pos (3U)
-#define USB_OTG_GINTMSK_SOFM_Msk (0x1UL << USB_OTG_GINTMSK_SOFM_Pos) /*!< 0x00000008 */
-#define USB_OTG_GINTMSK_SOFM USB_OTG_GINTMSK_SOFM_Msk /*!< Start of frame mask */
-#define USB_OTG_GINTMSK_RXFLVLM_Pos (4U)
-#define USB_OTG_GINTMSK_RXFLVLM_Msk (0x1UL << USB_OTG_GINTMSK_RXFLVLM_Pos) /*!< 0x00000010 */
-#define USB_OTG_GINTMSK_RXFLVLM USB_OTG_GINTMSK_RXFLVLM_Msk /*!< Receive FIFO nonempty mask */
-#define USB_OTG_GINTMSK_NPTXFEM_Pos (5U)
-#define USB_OTG_GINTMSK_NPTXFEM_Msk (0x1UL << USB_OTG_GINTMSK_NPTXFEM_Pos) /*!< 0x00000020 */
-#define USB_OTG_GINTMSK_NPTXFEM USB_OTG_GINTMSK_NPTXFEM_Msk /*!< Nonperiodic TxFIFO empty mask */
-#define USB_OTG_GINTMSK_GINAKEFFM_Pos (6U)
-#define USB_OTG_GINTMSK_GINAKEFFM_Msk (0x1UL << USB_OTG_GINTMSK_GINAKEFFM_Pos) /*!< 0x00000040 */
-#define USB_OTG_GINTMSK_GINAKEFFM USB_OTG_GINTMSK_GINAKEFFM_Msk /*!< Global nonperiodic IN NAK effective mask */
-#define USB_OTG_GINTMSK_GONAKEFFM_Pos (7U)
-#define USB_OTG_GINTMSK_GONAKEFFM_Msk (0x1UL << USB_OTG_GINTMSK_GONAKEFFM_Pos) /*!< 0x00000080 */
-#define USB_OTG_GINTMSK_GONAKEFFM USB_OTG_GINTMSK_GONAKEFFM_Msk /*!< Global OUT NAK effective mask */
-#define USB_OTG_GINTMSK_ESUSPM_Pos (10U)
-#define USB_OTG_GINTMSK_ESUSPM_Msk (0x1UL << USB_OTG_GINTMSK_ESUSPM_Pos) /*!< 0x00000400 */
-#define USB_OTG_GINTMSK_ESUSPM USB_OTG_GINTMSK_ESUSPM_Msk /*!< Early suspend mask */
-#define USB_OTG_GINTMSK_USBSUSPM_Pos (11U)
-#define USB_OTG_GINTMSK_USBSUSPM_Msk (0x1UL << USB_OTG_GINTMSK_USBSUSPM_Pos) /*!< 0x00000800 */
-#define USB_OTG_GINTMSK_USBSUSPM USB_OTG_GINTMSK_USBSUSPM_Msk /*!< USB suspend mask */
-#define USB_OTG_GINTMSK_USBRST_Pos (12U)
-#define USB_OTG_GINTMSK_USBRST_Msk (0x1UL << USB_OTG_GINTMSK_USBRST_Pos) /*!< 0x00001000 */
-#define USB_OTG_GINTMSK_USBRST USB_OTG_GINTMSK_USBRST_Msk /*!< USB reset mask */
-#define USB_OTG_GINTMSK_ENUMDNEM_Pos (13U)
-#define USB_OTG_GINTMSK_ENUMDNEM_Msk (0x1UL << USB_OTG_GINTMSK_ENUMDNEM_Pos) /*!< 0x00002000 */
-#define USB_OTG_GINTMSK_ENUMDNEM USB_OTG_GINTMSK_ENUMDNEM_Msk /*!< Enumeration done mask */
-#define USB_OTG_GINTMSK_ISOODRPM_Pos (14U)
-#define USB_OTG_GINTMSK_ISOODRPM_Msk (0x1UL << USB_OTG_GINTMSK_ISOODRPM_Pos) /*!< 0x00004000 */
-#define USB_OTG_GINTMSK_ISOODRPM USB_OTG_GINTMSK_ISOODRPM_Msk /*!< Isochronous OUT packet dropped interrupt mask */
-#define USB_OTG_GINTMSK_EOPFM_Pos (15U)
-#define USB_OTG_GINTMSK_EOPFM_Msk (0x1UL << USB_OTG_GINTMSK_EOPFM_Pos) /*!< 0x00008000 */
-#define USB_OTG_GINTMSK_EOPFM USB_OTG_GINTMSK_EOPFM_Msk /*!< End of periodic frame interrupt mask */
-#define USB_OTG_GINTMSK_EPMISM_Pos (17U)
-#define USB_OTG_GINTMSK_EPMISM_Msk (0x1UL << USB_OTG_GINTMSK_EPMISM_Pos) /*!< 0x00020000 */
-#define USB_OTG_GINTMSK_EPMISM USB_OTG_GINTMSK_EPMISM_Msk /*!< Endpoint mismatch interrupt mask */
-#define USB_OTG_GINTMSK_IEPINT_Pos (18U)
-#define USB_OTG_GINTMSK_IEPINT_Msk (0x1UL << USB_OTG_GINTMSK_IEPINT_Pos) /*!< 0x00040000 */
-#define USB_OTG_GINTMSK_IEPINT USB_OTG_GINTMSK_IEPINT_Msk /*!< IN endpoints interrupt mask */
-#define USB_OTG_GINTMSK_OEPINT_Pos (19U)
-#define USB_OTG_GINTMSK_OEPINT_Msk (0x1UL << USB_OTG_GINTMSK_OEPINT_Pos) /*!< 0x00080000 */
-#define USB_OTG_GINTMSK_OEPINT USB_OTG_GINTMSK_OEPINT_Msk /*!< OUT endpoints interrupt mask */
-#define USB_OTG_GINTMSK_IISOIXFRM_Pos (20U)
-#define USB_OTG_GINTMSK_IISOIXFRM_Msk (0x1UL << USB_OTG_GINTMSK_IISOIXFRM_Pos) /*!< 0x00100000 */
-#define USB_OTG_GINTMSK_IISOIXFRM USB_OTG_GINTMSK_IISOIXFRM_Msk /*!< Incomplete isochronous IN transfer mask */
-#define USB_OTG_GINTMSK_PXFRM_IISOOXFRM_Pos (21U)
-#define USB_OTG_GINTMSK_PXFRM_IISOOXFRM_Msk (0x1UL << USB_OTG_GINTMSK_PXFRM_IISOOXFRM_Pos) /*!< 0x00200000 */
-#define USB_OTG_GINTMSK_PXFRM_IISOOXFRM USB_OTG_GINTMSK_PXFRM_IISOOXFRM_Msk /*!< Incomplete periodic transfer mask */
-#define USB_OTG_GINTMSK_FSUSPM_Pos (22U)
-#define USB_OTG_GINTMSK_FSUSPM_Msk (0x1UL << USB_OTG_GINTMSK_FSUSPM_Pos) /*!< 0x00400000 */
-#define USB_OTG_GINTMSK_FSUSPM USB_OTG_GINTMSK_FSUSPM_Msk /*!< Data fetch suspended mask */
-#define USB_OTG_GINTMSK_PRTIM_Pos (24U)
-#define USB_OTG_GINTMSK_PRTIM_Msk (0x1UL << USB_OTG_GINTMSK_PRTIM_Pos) /*!< 0x01000000 */
-#define USB_OTG_GINTMSK_PRTIM USB_OTG_GINTMSK_PRTIM_Msk /*!< Host port interrupt mask */
-#define USB_OTG_GINTMSK_HCIM_Pos (25U)
-#define USB_OTG_GINTMSK_HCIM_Msk (0x1UL << USB_OTG_GINTMSK_HCIM_Pos) /*!< 0x02000000 */
-#define USB_OTG_GINTMSK_HCIM USB_OTG_GINTMSK_HCIM_Msk /*!< Host channels interrupt mask */
-#define USB_OTG_GINTMSK_PTXFEM_Pos (26U)
-#define USB_OTG_GINTMSK_PTXFEM_Msk (0x1UL << USB_OTG_GINTMSK_PTXFEM_Pos) /*!< 0x04000000 */
-#define USB_OTG_GINTMSK_PTXFEM USB_OTG_GINTMSK_PTXFEM_Msk /*!< Periodic TxFIFO empty mask */
-#define USB_OTG_GINTMSK_CIDSCHGM_Pos (28U)
-#define USB_OTG_GINTMSK_CIDSCHGM_Msk (0x1UL << USB_OTG_GINTMSK_CIDSCHGM_Pos) /*!< 0x10000000 */
-#define USB_OTG_GINTMSK_CIDSCHGM USB_OTG_GINTMSK_CIDSCHGM_Msk /*!< Connector ID status change mask */
-#define USB_OTG_GINTMSK_DISCINT_Pos (29U)
-#define USB_OTG_GINTMSK_DISCINT_Msk (0x1UL << USB_OTG_GINTMSK_DISCINT_Pos) /*!< 0x20000000 */
-#define USB_OTG_GINTMSK_DISCINT USB_OTG_GINTMSK_DISCINT_Msk /*!< Disconnect detected interrupt mask */
-#define USB_OTG_GINTMSK_SRQIM_Pos (30U)
-#define USB_OTG_GINTMSK_SRQIM_Msk (0x1UL << USB_OTG_GINTMSK_SRQIM_Pos) /*!< 0x40000000 */
-#define USB_OTG_GINTMSK_SRQIM USB_OTG_GINTMSK_SRQIM_Msk /*!< Session request/new session detected interrupt mask */
-#define USB_OTG_GINTMSK_WUIM_Pos (31U)
-#define USB_OTG_GINTMSK_WUIM_Msk (0x1UL << USB_OTG_GINTMSK_WUIM_Pos) /*!< 0x80000000 */
-#define USB_OTG_GINTMSK_WUIM USB_OTG_GINTMSK_WUIM_Msk /*!< Resume/remote wakeup detected interrupt mask */
-
-/******************** Bit definition for USB_OTG_DAINT register ********************/
-#define USB_OTG_DAINT_IEPINT_Pos (0U)
-#define USB_OTG_DAINT_IEPINT_Msk (0xFFFFUL << USB_OTG_DAINT_IEPINT_Pos) /*!< 0x0000FFFF */
-#define USB_OTG_DAINT_IEPINT USB_OTG_DAINT_IEPINT_Msk /*!< IN endpoint interrupt bits */
-#define USB_OTG_DAINT_OEPINT_Pos (16U)
-#define USB_OTG_DAINT_OEPINT_Msk (0xFFFFUL << USB_OTG_DAINT_OEPINT_Pos) /*!< 0xFFFF0000 */
-#define USB_OTG_DAINT_OEPINT USB_OTG_DAINT_OEPINT_Msk /*!< OUT endpoint interrupt bits */
-
-/******************** Bit definition for USB_OTG_HAINTMSK register ********************/
-#define USB_OTG_HAINTMSK_HAINTM_Pos (0U)
-#define USB_OTG_HAINTMSK_HAINTM_Msk (0xFFFFUL << USB_OTG_HAINTMSK_HAINTM_Pos) /*!< 0x0000FFFF */
-#define USB_OTG_HAINTMSK_HAINTM USB_OTG_HAINTMSK_HAINTM_Msk /*!< Channel interrupt mask */
-
-/******************** Bit definition for USB_OTG_GRXSTSP register ********************/
-#define USB_OTG_GRXSTSP_EPNUM_Pos (0U)
-#define USB_OTG_GRXSTSP_EPNUM_Msk (0xFUL << USB_OTG_GRXSTSP_EPNUM_Pos) /*!< 0x0000000F */
-#define USB_OTG_GRXSTSP_EPNUM USB_OTG_GRXSTSP_EPNUM_Msk /*!< IN EP interrupt mask bits */
-#define USB_OTG_GRXSTSP_BCNT_Pos (4U)
-#define USB_OTG_GRXSTSP_BCNT_Msk (0x7FFUL << USB_OTG_GRXSTSP_BCNT_Pos) /*!< 0x00007FF0 */
-#define USB_OTG_GRXSTSP_BCNT USB_OTG_GRXSTSP_BCNT_Msk /*!< OUT EP interrupt mask bits */
-#define USB_OTG_GRXSTSP_DPID_Pos (15U)
-#define USB_OTG_GRXSTSP_DPID_Msk (0x3UL << USB_OTG_GRXSTSP_DPID_Pos) /*!< 0x00018000 */
-#define USB_OTG_GRXSTSP_DPID USB_OTG_GRXSTSP_DPID_Msk /*!< OUT EP interrupt mask bits */
-#define USB_OTG_GRXSTSP_PKTSTS_Pos (17U)
-#define USB_OTG_GRXSTSP_PKTSTS_Msk (0xFUL << USB_OTG_GRXSTSP_PKTSTS_Pos) /*!< 0x001E0000 */
-#define USB_OTG_GRXSTSP_PKTSTS USB_OTG_GRXSTSP_PKTSTS_Msk /*!< OUT EP interrupt mask bits */
-
-/******************** Bit definition for USB_OTG_DAINTMSK register ********************/
-#define USB_OTG_DAINTMSK_IEPM_Pos (0U)
-#define USB_OTG_DAINTMSK_IEPM_Msk (0xFFFFUL << USB_OTG_DAINTMSK_IEPM_Pos) /*!< 0x0000FFFF */
-#define USB_OTG_DAINTMSK_IEPM USB_OTG_DAINTMSK_IEPM_Msk /*!< IN EP interrupt mask bits */
-#define USB_OTG_DAINTMSK_OEPM_Pos (16U)
-#define USB_OTG_DAINTMSK_OEPM_Msk (0xFFFFUL << USB_OTG_DAINTMSK_OEPM_Pos) /*!< 0xFFFF0000 */
-#define USB_OTG_DAINTMSK_OEPM USB_OTG_DAINTMSK_OEPM_Msk /*!< OUT EP interrupt mask bits */
-
-/******************** Bit definition for USB_OTG_GRXFSIZ register ********************/
-#define USB_OTG_GRXFSIZ_RXFD_Pos (0U)
-#define USB_OTG_GRXFSIZ_RXFD_Msk (0xFFFFUL << USB_OTG_GRXFSIZ_RXFD_Pos) /*!< 0x0000FFFF */
-#define USB_OTG_GRXFSIZ_RXFD USB_OTG_GRXFSIZ_RXFD_Msk /*!< RxFIFO depth */
-
-/******************** Bit definition for USB_OTG_DVBUSDIS register ********************/
-#define USB_OTG_DVBUSDIS_VBUSDT_Pos (0U)
-#define USB_OTG_DVBUSDIS_VBUSDT_Msk (0xFFFFUL << USB_OTG_DVBUSDIS_VBUSDT_Pos) /*!< 0x0000FFFF */
-#define USB_OTG_DVBUSDIS_VBUSDT USB_OTG_DVBUSDIS_VBUSDT_Msk /*!< Device VBUS discharge time */
-
-/******************** Bit definition for OTG register ********************/
-#define USB_OTG_NPTXFSA_Pos (0U)
-#define USB_OTG_NPTXFSA_Msk (0xFFFFUL << USB_OTG_NPTXFSA_Pos) /*!< 0x0000FFFF */
-#define USB_OTG_NPTXFSA USB_OTG_NPTXFSA_Msk /*!< Nonperiodic transmit RAM start address */
-#define USB_OTG_NPTXFD_Pos (16U)
-#define USB_OTG_NPTXFD_Msk (0xFFFFUL << USB_OTG_NPTXFD_Pos) /*!< 0xFFFF0000 */
-#define USB_OTG_NPTXFD USB_OTG_NPTXFD_Msk /*!< Nonperiodic TxFIFO depth */
-#define USB_OTG_TX0FSA_Pos (0U)
-#define USB_OTG_TX0FSA_Msk (0xFFFFUL << USB_OTG_TX0FSA_Pos) /*!< 0x0000FFFF */
-#define USB_OTG_TX0FSA USB_OTG_TX0FSA_Msk /*!< Endpoint 0 transmit RAM start address */
-#define USB_OTG_TX0FD_Pos (16U)
-#define USB_OTG_TX0FD_Msk (0xFFFFUL << USB_OTG_TX0FD_Pos) /*!< 0xFFFF0000 */
-#define USB_OTG_TX0FD USB_OTG_TX0FD_Msk /*!< Endpoint 0 TxFIFO depth */
-
-/******************** Bit definition for USB_OTG_DVBUSPULSE register ********************/
-#define USB_OTG_DVBUSPULSE_DVBUSP_Pos (0U)
-#define USB_OTG_DVBUSPULSE_DVBUSP_Msk (0xFFFUL << USB_OTG_DVBUSPULSE_DVBUSP_Pos) /*!< 0x00000FFF */
-#define USB_OTG_DVBUSPULSE_DVBUSP USB_OTG_DVBUSPULSE_DVBUSP_Msk /*!< Device VBUS pulsing time */
-
-/******************** Bit definition for USB_OTG_GNPTXSTS register ********************/
-#define USB_OTG_GNPTXSTS_NPTXFSAV_Pos (0U)
-#define USB_OTG_GNPTXSTS_NPTXFSAV_Msk (0xFFFFUL << USB_OTG_GNPTXSTS_NPTXFSAV_Pos) /*!< 0x0000FFFF */
-#define USB_OTG_GNPTXSTS_NPTXFSAV USB_OTG_GNPTXSTS_NPTXFSAV_Msk /*!< Nonperiodic TxFIFO space available */
-
-#define USB_OTG_GNPTXSTS_NPTQXSAV_Pos (16U)
-#define USB_OTG_GNPTXSTS_NPTQXSAV_Msk (0xFFUL << USB_OTG_GNPTXSTS_NPTQXSAV_Pos) /*!< 0x00FF0000 */
-#define USB_OTG_GNPTXSTS_NPTQXSAV USB_OTG_GNPTXSTS_NPTQXSAV_Msk /*!< Nonperiodic transmit request queue space available */
-#define USB_OTG_GNPTXSTS_NPTQXSAV_0 (0x01UL << USB_OTG_GNPTXSTS_NPTQXSAV_Pos) /*!< 0x00010000 */
-#define USB_OTG_GNPTXSTS_NPTQXSAV_1 (0x02UL << USB_OTG_GNPTXSTS_NPTQXSAV_Pos) /*!< 0x00020000 */
-#define USB_OTG_GNPTXSTS_NPTQXSAV_2 (0x04UL << USB_OTG_GNPTXSTS_NPTQXSAV_Pos) /*!< 0x00040000 */
-#define USB_OTG_GNPTXSTS_NPTQXSAV_3 (0x08UL << USB_OTG_GNPTXSTS_NPTQXSAV_Pos) /*!< 0x00080000 */
-#define USB_OTG_GNPTXSTS_NPTQXSAV_4 (0x10UL << USB_OTG_GNPTXSTS_NPTQXSAV_Pos) /*!< 0x00100000 */
-#define USB_OTG_GNPTXSTS_NPTQXSAV_5 (0x20UL << USB_OTG_GNPTXSTS_NPTQXSAV_Pos) /*!< 0x00200000 */
-#define USB_OTG_GNPTXSTS_NPTQXSAV_6 (0x40UL << USB_OTG_GNPTXSTS_NPTQXSAV_Pos) /*!< 0x00400000 */
-#define USB_OTG_GNPTXSTS_NPTQXSAV_7 (0x80UL << USB_OTG_GNPTXSTS_NPTQXSAV_Pos) /*!< 0x00800000 */
-
-#define USB_OTG_GNPTXSTS_NPTXQTOP_Pos (24U)
-#define USB_OTG_GNPTXSTS_NPTXQTOP_Msk (0x7FUL << USB_OTG_GNPTXSTS_NPTXQTOP_Pos) /*!< 0x7F000000 */
-#define USB_OTG_GNPTXSTS_NPTXQTOP USB_OTG_GNPTXSTS_NPTXQTOP_Msk /*!< Top of the nonperiodic transmit request queue */
-#define USB_OTG_GNPTXSTS_NPTXQTOP_0 (0x01UL << USB_OTG_GNPTXSTS_NPTXQTOP_Pos) /*!< 0x01000000 */
-#define USB_OTG_GNPTXSTS_NPTXQTOP_1 (0x02UL << USB_OTG_GNPTXSTS_NPTXQTOP_Pos) /*!< 0x02000000 */
-#define USB_OTG_GNPTXSTS_NPTXQTOP_2 (0x04UL << USB_OTG_GNPTXSTS_NPTXQTOP_Pos) /*!< 0x04000000 */
-#define USB_OTG_GNPTXSTS_NPTXQTOP_3 (0x08UL << USB_OTG_GNPTXSTS_NPTXQTOP_Pos) /*!< 0x08000000 */
-#define USB_OTG_GNPTXSTS_NPTXQTOP_4 (0x10UL << USB_OTG_GNPTXSTS_NPTXQTOP_Pos) /*!< 0x10000000 */
-#define USB_OTG_GNPTXSTS_NPTXQTOP_5 (0x20UL << USB_OTG_GNPTXSTS_NPTXQTOP_Pos) /*!< 0x20000000 */
-#define USB_OTG_GNPTXSTS_NPTXQTOP_6 (0x40UL << USB_OTG_GNPTXSTS_NPTXQTOP_Pos) /*!< 0x40000000 */
-
-/******************** Bit definition for USB_OTG_DTHRCTL register ********************/
-#define USB_OTG_DTHRCTL_NONISOTHREN_Pos (0U)
-#define USB_OTG_DTHRCTL_NONISOTHREN_Msk (0x1UL << USB_OTG_DTHRCTL_NONISOTHREN_Pos) /*!< 0x00000001 */
-#define USB_OTG_DTHRCTL_NONISOTHREN USB_OTG_DTHRCTL_NONISOTHREN_Msk /*!< Nonisochronous IN endpoints threshold enable */
-#define USB_OTG_DTHRCTL_ISOTHREN_Pos (1U)
-#define USB_OTG_DTHRCTL_ISOTHREN_Msk (0x1UL << USB_OTG_DTHRCTL_ISOTHREN_Pos) /*!< 0x00000002 */
-#define USB_OTG_DTHRCTL_ISOTHREN USB_OTG_DTHRCTL_ISOTHREN_Msk /*!< ISO IN endpoint threshold enable */
-
-#define USB_OTG_DTHRCTL_TXTHRLEN_Pos (2U)
-#define USB_OTG_DTHRCTL_TXTHRLEN_Msk (0x1FFUL << USB_OTG_DTHRCTL_TXTHRLEN_Pos) /*!< 0x000007FC */
-#define USB_OTG_DTHRCTL_TXTHRLEN USB_OTG_DTHRCTL_TXTHRLEN_Msk /*!< Transmit threshold length */
-#define USB_OTG_DTHRCTL_TXTHRLEN_0 (0x001UL << USB_OTG_DTHRCTL_TXTHRLEN_Pos) /*!< 0x00000004 */
-#define USB_OTG_DTHRCTL_TXTHRLEN_1 (0x002UL << USB_OTG_DTHRCTL_TXTHRLEN_Pos) /*!< 0x00000008 */
-#define USB_OTG_DTHRCTL_TXTHRLEN_2 (0x004UL << USB_OTG_DTHRCTL_TXTHRLEN_Pos) /*!< 0x00000010 */
-#define USB_OTG_DTHRCTL_TXTHRLEN_3 (0x008UL << USB_OTG_DTHRCTL_TXTHRLEN_Pos) /*!< 0x00000020 */
-#define USB_OTG_DTHRCTL_TXTHRLEN_4 (0x010UL << USB_OTG_DTHRCTL_TXTHRLEN_Pos) /*!< 0x00000040 */
-#define USB_OTG_DTHRCTL_TXTHRLEN_5 (0x020UL << USB_OTG_DTHRCTL_TXTHRLEN_Pos) /*!< 0x00000080 */
-#define USB_OTG_DTHRCTL_TXTHRLEN_6 (0x040UL << USB_OTG_DTHRCTL_TXTHRLEN_Pos) /*!< 0x00000100 */
-#define USB_OTG_DTHRCTL_TXTHRLEN_7 (0x080UL << USB_OTG_DTHRCTL_TXTHRLEN_Pos) /*!< 0x00000200 */
-#define USB_OTG_DTHRCTL_TXTHRLEN_8 (0x100UL << USB_OTG_DTHRCTL_TXTHRLEN_Pos) /*!< 0x00000400 */
-#define USB_OTG_DTHRCTL_RXTHREN_Pos (16U)
-#define USB_OTG_DTHRCTL_RXTHREN_Msk (0x1UL << USB_OTG_DTHRCTL_RXTHREN_Pos) /*!< 0x00010000 */
-#define USB_OTG_DTHRCTL_RXTHREN USB_OTG_DTHRCTL_RXTHREN_Msk /*!< Receive threshold enable */
-
-#define USB_OTG_DTHRCTL_RXTHRLEN_Pos (17U)
-#define USB_OTG_DTHRCTL_RXTHRLEN_Msk (0x1FFUL << USB_OTG_DTHRCTL_RXTHRLEN_Pos) /*!< 0x03FE0000 */
-#define USB_OTG_DTHRCTL_RXTHRLEN USB_OTG_DTHRCTL_RXTHRLEN_Msk /*!< Receive threshold length */
-#define USB_OTG_DTHRCTL_RXTHRLEN_0 (0x001UL << USB_OTG_DTHRCTL_RXTHRLEN_Pos) /*!< 0x00020000 */
-#define USB_OTG_DTHRCTL_RXTHRLEN_1 (0x002UL << USB_OTG_DTHRCTL_RXTHRLEN_Pos) /*!< 0x00040000 */
-#define USB_OTG_DTHRCTL_RXTHRLEN_2 (0x004UL << USB_OTG_DTHRCTL_RXTHRLEN_Pos) /*!< 0x00080000 */
-#define USB_OTG_DTHRCTL_RXTHRLEN_3 (0x008UL << USB_OTG_DTHRCTL_RXTHRLEN_Pos) /*!< 0x00100000 */
-#define USB_OTG_DTHRCTL_RXTHRLEN_4 (0x010UL << USB_OTG_DTHRCTL_RXTHRLEN_Pos) /*!< 0x00200000 */
-#define USB_OTG_DTHRCTL_RXTHRLEN_5 (0x020UL << USB_OTG_DTHRCTL_RXTHRLEN_Pos) /*!< 0x00400000 */
-#define USB_OTG_DTHRCTL_RXTHRLEN_6 (0x040UL << USB_OTG_DTHRCTL_RXTHRLEN_Pos) /*!< 0x00800000 */
-#define USB_OTG_DTHRCTL_RXTHRLEN_7 (0x080UL << USB_OTG_DTHRCTL_RXTHRLEN_Pos) /*!< 0x01000000 */
-#define USB_OTG_DTHRCTL_RXTHRLEN_8 (0x100UL << USB_OTG_DTHRCTL_RXTHRLEN_Pos) /*!< 0x02000000 */
-#define USB_OTG_DTHRCTL_ARPEN_Pos (27U)
-#define USB_OTG_DTHRCTL_ARPEN_Msk (0x1UL << USB_OTG_DTHRCTL_ARPEN_Pos) /*!< 0x08000000 */
-#define USB_OTG_DTHRCTL_ARPEN USB_OTG_DTHRCTL_ARPEN_Msk /*!< Arbiter parking enable */
-
-/******************** Bit definition for USB_OTG_DIEPEMPMSK register ********************/
-#define USB_OTG_DIEPEMPMSK_INEPTXFEM_Pos (0U)
-#define USB_OTG_DIEPEMPMSK_INEPTXFEM_Msk (0xFFFFUL << USB_OTG_DIEPEMPMSK_INEPTXFEM_Pos) /*!< 0x0000FFFF */
-#define USB_OTG_DIEPEMPMSK_INEPTXFEM USB_OTG_DIEPEMPMSK_INEPTXFEM_Msk /*!< IN EP Tx FIFO empty interrupt mask bits */
-
-/******************** Bit definition for USB_OTG_DEACHINT register ********************/
-#define USB_OTG_DEACHINT_IEP1INT_Pos (1U)
-#define USB_OTG_DEACHINT_IEP1INT_Msk (0x1UL << USB_OTG_DEACHINT_IEP1INT_Pos) /*!< 0x00000002 */
-#define USB_OTG_DEACHINT_IEP1INT USB_OTG_DEACHINT_IEP1INT_Msk /*!< IN endpoint 1interrupt bit */
-#define USB_OTG_DEACHINT_OEP1INT_Pos (17U)
-#define USB_OTG_DEACHINT_OEP1INT_Msk (0x1UL << USB_OTG_DEACHINT_OEP1INT_Pos) /*!< 0x00020000 */
-#define USB_OTG_DEACHINT_OEP1INT USB_OTG_DEACHINT_OEP1INT_Msk /*!< OUT endpoint 1 interrupt bit */
-
-/******************** Bit definition for USB_OTG_GCCFG register ********************/
-#define USB_OTG_GCCFG_PWRDWN_Pos (16U)
-#define USB_OTG_GCCFG_PWRDWN_Msk (0x1UL << USB_OTG_GCCFG_PWRDWN_Pos) /*!< 0x00010000 */
-#define USB_OTG_GCCFG_PWRDWN USB_OTG_GCCFG_PWRDWN_Msk /*!< Power down */
-#define USB_OTG_GCCFG_VBUSASEN_Pos (18U)
-#define USB_OTG_GCCFG_VBUSASEN_Msk (0x1UL << USB_OTG_GCCFG_VBUSASEN_Pos) /*!< 0x00040000 */
-#define USB_OTG_GCCFG_VBUSASEN USB_OTG_GCCFG_VBUSASEN_Msk /*!< Enable the VBUS sensing device */
-#define USB_OTG_GCCFG_VBUSBSEN_Pos (19U)
-#define USB_OTG_GCCFG_VBUSBSEN_Msk (0x1UL << USB_OTG_GCCFG_VBUSBSEN_Pos) /*!< 0x00080000 */
-#define USB_OTG_GCCFG_VBUSBSEN USB_OTG_GCCFG_VBUSBSEN_Msk /*!< Enable the VBUS sensing device */
-#define USB_OTG_GCCFG_SOFOUTEN_Pos (20U)
-#define USB_OTG_GCCFG_SOFOUTEN_Msk (0x1UL << USB_OTG_GCCFG_SOFOUTEN_Pos) /*!< 0x00100000 */
-#define USB_OTG_GCCFG_SOFOUTEN USB_OTG_GCCFG_SOFOUTEN_Msk /*!< SOF output enable */
-
-/******************** Bit definition for USB_OTG_DEACHINTMSK register ********************/
-#define USB_OTG_DEACHINTMSK_IEP1INTM_Pos (1U)
-#define USB_OTG_DEACHINTMSK_IEP1INTM_Msk (0x1UL << USB_OTG_DEACHINTMSK_IEP1INTM_Pos) /*!< 0x00000002 */
-#define USB_OTG_DEACHINTMSK_IEP1INTM USB_OTG_DEACHINTMSK_IEP1INTM_Msk /*!< IN Endpoint 1 interrupt mask bit */
-#define USB_OTG_DEACHINTMSK_OEP1INTM_Pos (17U)
-#define USB_OTG_DEACHINTMSK_OEP1INTM_Msk (0x1UL << USB_OTG_DEACHINTMSK_OEP1INTM_Pos) /*!< 0x00020000 */
-#define USB_OTG_DEACHINTMSK_OEP1INTM USB_OTG_DEACHINTMSK_OEP1INTM_Msk /*!< OUT Endpoint 1 interrupt mask bit */
-
-/******************** Bit definition for USB_OTG_CID register ********************/
-#define USB_OTG_CID_PRODUCT_ID_Pos (0U)
-#define USB_OTG_CID_PRODUCT_ID_Msk (0xFFFFFFFFUL << USB_OTG_CID_PRODUCT_ID_Pos) /*!< 0xFFFFFFFF */
-#define USB_OTG_CID_PRODUCT_ID USB_OTG_CID_PRODUCT_ID_Msk /*!< Product ID field */
-
-/******************** Bit definition for USB_OTG_DIEPEACHMSK1 register ********************/
-#define USB_OTG_DIEPEACHMSK1_XFRCM_Pos (0U)
-#define USB_OTG_DIEPEACHMSK1_XFRCM_Msk (0x1UL << USB_OTG_DIEPEACHMSK1_XFRCM_Pos) /*!< 0x00000001 */
-#define USB_OTG_DIEPEACHMSK1_XFRCM USB_OTG_DIEPEACHMSK1_XFRCM_Msk /*!< Transfer completed interrupt mask */
-#define USB_OTG_DIEPEACHMSK1_EPDM_Pos (1U)
-#define USB_OTG_DIEPEACHMSK1_EPDM_Msk (0x1UL << USB_OTG_DIEPEACHMSK1_EPDM_Pos) /*!< 0x00000002 */
-#define USB_OTG_DIEPEACHMSK1_EPDM USB_OTG_DIEPEACHMSK1_EPDM_Msk /*!< Endpoint disabled interrupt mask */
-#define USB_OTG_DIEPEACHMSK1_TOM_Pos (3U)
-#define USB_OTG_DIEPEACHMSK1_TOM_Msk (0x1UL << USB_OTG_DIEPEACHMSK1_TOM_Pos) /*!< 0x00000008 */
-#define USB_OTG_DIEPEACHMSK1_TOM USB_OTG_DIEPEACHMSK1_TOM_Msk /*!< Timeout condition mask (nonisochronous endpoints) */
-#define USB_OTG_DIEPEACHMSK1_ITTXFEMSK_Pos (4U)
-#define USB_OTG_DIEPEACHMSK1_ITTXFEMSK_Msk (0x1UL << USB_OTG_DIEPEACHMSK1_ITTXFEMSK_Pos) /*!< 0x00000010 */
-#define USB_OTG_DIEPEACHMSK1_ITTXFEMSK USB_OTG_DIEPEACHMSK1_ITTXFEMSK_Msk /*!< IN token received when TxFIFO empty mask */
-#define USB_OTG_DIEPEACHMSK1_INEPNMM_Pos (5U)
-#define USB_OTG_DIEPEACHMSK1_INEPNMM_Msk (0x1UL << USB_OTG_DIEPEACHMSK1_INEPNMM_Pos) /*!< 0x00000020 */
-#define USB_OTG_DIEPEACHMSK1_INEPNMM USB_OTG_DIEPEACHMSK1_INEPNMM_Msk /*!< IN token received with EP mismatch mask */
-#define USB_OTG_DIEPEACHMSK1_INEPNEM_Pos (6U)
-#define USB_OTG_DIEPEACHMSK1_INEPNEM_Msk (0x1UL << USB_OTG_DIEPEACHMSK1_INEPNEM_Pos) /*!< 0x00000040 */
-#define USB_OTG_DIEPEACHMSK1_INEPNEM USB_OTG_DIEPEACHMSK1_INEPNEM_Msk /*!< IN endpoint NAK effective mask */
-#define USB_OTG_DIEPEACHMSK1_TXFURM_Pos (8U)
-#define USB_OTG_DIEPEACHMSK1_TXFURM_Msk (0x1UL << USB_OTG_DIEPEACHMSK1_TXFURM_Pos) /*!< 0x00000100 */
-#define USB_OTG_DIEPEACHMSK1_TXFURM USB_OTG_DIEPEACHMSK1_TXFURM_Msk /*!< FIFO underrun mask */
-#define USB_OTG_DIEPEACHMSK1_BIM_Pos (9U)
-#define USB_OTG_DIEPEACHMSK1_BIM_Msk (0x1UL << USB_OTG_DIEPEACHMSK1_BIM_Pos) /*!< 0x00000200 */
-#define USB_OTG_DIEPEACHMSK1_BIM USB_OTG_DIEPEACHMSK1_BIM_Msk /*!< BNA interrupt mask */
-#define USB_OTG_DIEPEACHMSK1_NAKM_Pos (13U)
-#define USB_OTG_DIEPEACHMSK1_NAKM_Msk (0x1UL << USB_OTG_DIEPEACHMSK1_NAKM_Pos) /*!< 0x00002000 */
-#define USB_OTG_DIEPEACHMSK1_NAKM USB_OTG_DIEPEACHMSK1_NAKM_Msk /*!< NAK interrupt mask */
-
-/******************** Bit definition for USB_OTG_HPRT register ********************/
-#define USB_OTG_HPRT_PCSTS_Pos (0U)
-#define USB_OTG_HPRT_PCSTS_Msk (0x1UL << USB_OTG_HPRT_PCSTS_Pos) /*!< 0x00000001 */
-#define USB_OTG_HPRT_PCSTS USB_OTG_HPRT_PCSTS_Msk /*!< Port connect status */
-#define USB_OTG_HPRT_PCDET_Pos (1U)
-#define USB_OTG_HPRT_PCDET_Msk (0x1UL << USB_OTG_HPRT_PCDET_Pos) /*!< 0x00000002 */
-#define USB_OTG_HPRT_PCDET USB_OTG_HPRT_PCDET_Msk /*!< Port connect detected */
-#define USB_OTG_HPRT_PENA_Pos (2U)
-#define USB_OTG_HPRT_PENA_Msk (0x1UL << USB_OTG_HPRT_PENA_Pos) /*!< 0x00000004 */
-#define USB_OTG_HPRT_PENA USB_OTG_HPRT_PENA_Msk /*!< Port enable */
-#define USB_OTG_HPRT_PENCHNG_Pos (3U)
-#define USB_OTG_HPRT_PENCHNG_Msk (0x1UL << USB_OTG_HPRT_PENCHNG_Pos) /*!< 0x00000008 */
-#define USB_OTG_HPRT_PENCHNG USB_OTG_HPRT_PENCHNG_Msk /*!< Port enable/disable change */
-#define USB_OTG_HPRT_POCA_Pos (4U)
-#define USB_OTG_HPRT_POCA_Msk (0x1UL << USB_OTG_HPRT_POCA_Pos) /*!< 0x00000010 */
-#define USB_OTG_HPRT_POCA USB_OTG_HPRT_POCA_Msk /*!< Port overcurrent active */
-#define USB_OTG_HPRT_POCCHNG_Pos (5U)
-#define USB_OTG_HPRT_POCCHNG_Msk (0x1UL << USB_OTG_HPRT_POCCHNG_Pos) /*!< 0x00000020 */
-#define USB_OTG_HPRT_POCCHNG USB_OTG_HPRT_POCCHNG_Msk /*!< Port overcurrent change */
-#define USB_OTG_HPRT_PRES_Pos (6U)
-#define USB_OTG_HPRT_PRES_Msk (0x1UL << USB_OTG_HPRT_PRES_Pos) /*!< 0x00000040 */
-#define USB_OTG_HPRT_PRES USB_OTG_HPRT_PRES_Msk /*!< Port resume */
-#define USB_OTG_HPRT_PSUSP_Pos (7U)
-#define USB_OTG_HPRT_PSUSP_Msk (0x1UL << USB_OTG_HPRT_PSUSP_Pos) /*!< 0x00000080 */
-#define USB_OTG_HPRT_PSUSP USB_OTG_HPRT_PSUSP_Msk /*!< Port suspend */
-#define USB_OTG_HPRT_PRST_Pos (8U)
-#define USB_OTG_HPRT_PRST_Msk (0x1UL << USB_OTG_HPRT_PRST_Pos) /*!< 0x00000100 */
-#define USB_OTG_HPRT_PRST USB_OTG_HPRT_PRST_Msk /*!< Port reset */
-
-#define USB_OTG_HPRT_PLSTS_Pos (10U)
-#define USB_OTG_HPRT_PLSTS_Msk (0x3UL << USB_OTG_HPRT_PLSTS_Pos) /*!< 0x00000C00 */
-#define USB_OTG_HPRT_PLSTS USB_OTG_HPRT_PLSTS_Msk /*!< Port line status */
-#define USB_OTG_HPRT_PLSTS_0 (0x1UL << USB_OTG_HPRT_PLSTS_Pos) /*!< 0x00000400 */
-#define USB_OTG_HPRT_PLSTS_1 (0x2UL << USB_OTG_HPRT_PLSTS_Pos) /*!< 0x00000800 */
-#define USB_OTG_HPRT_PPWR_Pos (12U)
-#define USB_OTG_HPRT_PPWR_Msk (0x1UL << USB_OTG_HPRT_PPWR_Pos) /*!< 0x00001000 */
-#define USB_OTG_HPRT_PPWR USB_OTG_HPRT_PPWR_Msk /*!< Port power */
-
-#define USB_OTG_HPRT_PTCTL_Pos (13U)
-#define USB_OTG_HPRT_PTCTL_Msk (0xFUL << USB_OTG_HPRT_PTCTL_Pos) /*!< 0x0001E000 */
-#define USB_OTG_HPRT_PTCTL USB_OTG_HPRT_PTCTL_Msk /*!< Port test control */
-#define USB_OTG_HPRT_PTCTL_0 (0x1UL << USB_OTG_HPRT_PTCTL_Pos) /*!< 0x00002000 */
-#define USB_OTG_HPRT_PTCTL_1 (0x2UL << USB_OTG_HPRT_PTCTL_Pos) /*!< 0x00004000 */
-#define USB_OTG_HPRT_PTCTL_2 (0x4UL << USB_OTG_HPRT_PTCTL_Pos) /*!< 0x00008000 */
-#define USB_OTG_HPRT_PTCTL_3 (0x8UL << USB_OTG_HPRT_PTCTL_Pos) /*!< 0x00010000 */
-
-#define USB_OTG_HPRT_PSPD_Pos (17U)
-#define USB_OTG_HPRT_PSPD_Msk (0x3UL << USB_OTG_HPRT_PSPD_Pos) /*!< 0x00060000 */
-#define USB_OTG_HPRT_PSPD USB_OTG_HPRT_PSPD_Msk /*!< Port speed */
-#define USB_OTG_HPRT_PSPD_0 (0x1UL << USB_OTG_HPRT_PSPD_Pos) /*!< 0x00020000 */
-#define USB_OTG_HPRT_PSPD_1 (0x2UL << USB_OTG_HPRT_PSPD_Pos) /*!< 0x00040000 */
-
-/******************** Bit definition for USB_OTG_DOEPEACHMSK1 register ********************/
-#define USB_OTG_DOEPEACHMSK1_XFRCM_Pos (0U)
-#define USB_OTG_DOEPEACHMSK1_XFRCM_Msk (0x1UL << USB_OTG_DOEPEACHMSK1_XFRCM_Pos) /*!< 0x00000001 */
-#define USB_OTG_DOEPEACHMSK1_XFRCM USB_OTG_DOEPEACHMSK1_XFRCM_Msk /*!< Transfer completed interrupt mask */
-#define USB_OTG_DOEPEACHMSK1_EPDM_Pos (1U)
-#define USB_OTG_DOEPEACHMSK1_EPDM_Msk (0x1UL << USB_OTG_DOEPEACHMSK1_EPDM_Pos) /*!< 0x00000002 */
-#define USB_OTG_DOEPEACHMSK1_EPDM USB_OTG_DOEPEACHMSK1_EPDM_Msk /*!< Endpoint disabled interrupt mask */
-#define USB_OTG_DOEPEACHMSK1_TOM_Pos (3U)
-#define USB_OTG_DOEPEACHMSK1_TOM_Msk (0x1UL << USB_OTG_DOEPEACHMSK1_TOM_Pos) /*!< 0x00000008 */
-#define USB_OTG_DOEPEACHMSK1_TOM USB_OTG_DOEPEACHMSK1_TOM_Msk /*!< Timeout condition mask */
-#define USB_OTG_DOEPEACHMSK1_ITTXFEMSK_Pos (4U)
-#define USB_OTG_DOEPEACHMSK1_ITTXFEMSK_Msk (0x1UL << USB_OTG_DOEPEACHMSK1_ITTXFEMSK_Pos) /*!< 0x00000010 */
-#define USB_OTG_DOEPEACHMSK1_ITTXFEMSK USB_OTG_DOEPEACHMSK1_ITTXFEMSK_Msk /*!< IN token received when TxFIFO empty mask */
-#define USB_OTG_DOEPEACHMSK1_INEPNMM_Pos (5U)
-#define USB_OTG_DOEPEACHMSK1_INEPNMM_Msk (0x1UL << USB_OTG_DOEPEACHMSK1_INEPNMM_Pos) /*!< 0x00000020 */
-#define USB_OTG_DOEPEACHMSK1_INEPNMM USB_OTG_DOEPEACHMSK1_INEPNMM_Msk /*!< IN token received with EP mismatch mask */
-#define USB_OTG_DOEPEACHMSK1_INEPNEM_Pos (6U)
-#define USB_OTG_DOEPEACHMSK1_INEPNEM_Msk (0x1UL << USB_OTG_DOEPEACHMSK1_INEPNEM_Pos) /*!< 0x00000040 */
-#define USB_OTG_DOEPEACHMSK1_INEPNEM USB_OTG_DOEPEACHMSK1_INEPNEM_Msk /*!< IN endpoint NAK effective mask */
-#define USB_OTG_DOEPEACHMSK1_TXFURM_Pos (8U)
-#define USB_OTG_DOEPEACHMSK1_TXFURM_Msk (0x1UL << USB_OTG_DOEPEACHMSK1_TXFURM_Pos) /*!< 0x00000100 */
-#define USB_OTG_DOEPEACHMSK1_TXFURM USB_OTG_DOEPEACHMSK1_TXFURM_Msk /*!< OUT packet error mask */
-#define USB_OTG_DOEPEACHMSK1_BIM_Pos (9U)
-#define USB_OTG_DOEPEACHMSK1_BIM_Msk (0x1UL << USB_OTG_DOEPEACHMSK1_BIM_Pos) /*!< 0x00000200 */
-#define USB_OTG_DOEPEACHMSK1_BIM USB_OTG_DOEPEACHMSK1_BIM_Msk /*!< BNA interrupt mask */
-#define USB_OTG_DOEPEACHMSK1_BERRM_Pos (12U)
-#define USB_OTG_DOEPEACHMSK1_BERRM_Msk (0x1UL << USB_OTG_DOEPEACHMSK1_BERRM_Pos) /*!< 0x00001000 */
-#define USB_OTG_DOEPEACHMSK1_BERRM USB_OTG_DOEPEACHMSK1_BERRM_Msk /*!< Bubble error interrupt mask */
-#define USB_OTG_DOEPEACHMSK1_NAKM_Pos (13U)
-#define USB_OTG_DOEPEACHMSK1_NAKM_Msk (0x1UL << USB_OTG_DOEPEACHMSK1_NAKM_Pos) /*!< 0x00002000 */
-#define USB_OTG_DOEPEACHMSK1_NAKM USB_OTG_DOEPEACHMSK1_NAKM_Msk /*!< NAK interrupt mask */
-#define USB_OTG_DOEPEACHMSK1_NYETM_Pos (14U)
-#define USB_OTG_DOEPEACHMSK1_NYETM_Msk (0x1UL << USB_OTG_DOEPEACHMSK1_NYETM_Pos) /*!< 0x00004000 */
-#define USB_OTG_DOEPEACHMSK1_NYETM USB_OTG_DOEPEACHMSK1_NYETM_Msk /*!< NYET interrupt mask */
-
-/******************** Bit definition for USB_OTG_HPTXFSIZ register ********************/
-#define USB_OTG_HPTXFSIZ_PTXSA_Pos (0U)
-#define USB_OTG_HPTXFSIZ_PTXSA_Msk (0xFFFFUL << USB_OTG_HPTXFSIZ_PTXSA_Pos) /*!< 0x0000FFFF */
-#define USB_OTG_HPTXFSIZ_PTXSA USB_OTG_HPTXFSIZ_PTXSA_Msk /*!< Host periodic TxFIFO start address */
-#define USB_OTG_HPTXFSIZ_PTXFD_Pos (16U)
-#define USB_OTG_HPTXFSIZ_PTXFD_Msk (0xFFFFUL << USB_OTG_HPTXFSIZ_PTXFD_Pos) /*!< 0xFFFF0000 */
-#define USB_OTG_HPTXFSIZ_PTXFD USB_OTG_HPTXFSIZ_PTXFD_Msk /*!< Host periodic TxFIFO depth */
-
-/******************** Bit definition for USB_OTG_DIEPCTL register ********************/
-#define USB_OTG_DIEPCTL_MPSIZ_Pos (0U)
-#define USB_OTG_DIEPCTL_MPSIZ_Msk (0x7FFUL << USB_OTG_DIEPCTL_MPSIZ_Pos) /*!< 0x000007FF */
-#define USB_OTG_DIEPCTL_MPSIZ USB_OTG_DIEPCTL_MPSIZ_Msk /*!< Maximum packet size */
-#define USB_OTG_DIEPCTL_USBAEP_Pos (15U)
-#define USB_OTG_DIEPCTL_USBAEP_Msk (0x1UL << USB_OTG_DIEPCTL_USBAEP_Pos) /*!< 0x00008000 */
-#define USB_OTG_DIEPCTL_USBAEP USB_OTG_DIEPCTL_USBAEP_Msk /*!< USB active endpoint */
-#define USB_OTG_DIEPCTL_EONUM_DPID_Pos (16U)
-#define USB_OTG_DIEPCTL_EONUM_DPID_Msk (0x1UL << USB_OTG_DIEPCTL_EONUM_DPID_Pos) /*!< 0x00010000 */
-#define USB_OTG_DIEPCTL_EONUM_DPID USB_OTG_DIEPCTL_EONUM_DPID_Msk /*!< Even/odd frame */
-#define USB_OTG_DIEPCTL_NAKSTS_Pos (17U)
-#define USB_OTG_DIEPCTL_NAKSTS_Msk (0x1UL << USB_OTG_DIEPCTL_NAKSTS_Pos) /*!< 0x00020000 */
-#define USB_OTG_DIEPCTL_NAKSTS USB_OTG_DIEPCTL_NAKSTS_Msk /*!< NAK status */
-
-#define USB_OTG_DIEPCTL_EPTYP_Pos (18U)
-#define USB_OTG_DIEPCTL_EPTYP_Msk (0x3UL << USB_OTG_DIEPCTL_EPTYP_Pos) /*!< 0x000C0000 */
-#define USB_OTG_DIEPCTL_EPTYP USB_OTG_DIEPCTL_EPTYP_Msk /*!< Endpoint type */
-#define USB_OTG_DIEPCTL_EPTYP_0 (0x1UL << USB_OTG_DIEPCTL_EPTYP_Pos) /*!< 0x00040000 */
-#define USB_OTG_DIEPCTL_EPTYP_1 (0x2UL << USB_OTG_DIEPCTL_EPTYP_Pos) /*!< 0x00080000 */
-#define USB_OTG_DIEPCTL_STALL_Pos (21U)
-#define USB_OTG_DIEPCTL_STALL_Msk (0x1UL << USB_OTG_DIEPCTL_STALL_Pos) /*!< 0x00200000 */
-#define USB_OTG_DIEPCTL_STALL USB_OTG_DIEPCTL_STALL_Msk /*!< STALL handshake */
-
-#define USB_OTG_DIEPCTL_TXFNUM_Pos (22U)
-#define USB_OTG_DIEPCTL_TXFNUM_Msk (0xFUL << USB_OTG_DIEPCTL_TXFNUM_Pos) /*!< 0x03C00000 */
-#define USB_OTG_DIEPCTL_TXFNUM USB_OTG_DIEPCTL_TXFNUM_Msk /*!< TxFIFO number */
-#define USB_OTG_DIEPCTL_TXFNUM_0 (0x1UL << USB_OTG_DIEPCTL_TXFNUM_Pos) /*!< 0x00400000 */
-#define USB_OTG_DIEPCTL_TXFNUM_1 (0x2UL << USB_OTG_DIEPCTL_TXFNUM_Pos) /*!< 0x00800000 */
-#define USB_OTG_DIEPCTL_TXFNUM_2 (0x4UL << USB_OTG_DIEPCTL_TXFNUM_Pos) /*!< 0x01000000 */
-#define USB_OTG_DIEPCTL_TXFNUM_3 (0x8UL << USB_OTG_DIEPCTL_TXFNUM_Pos) /*!< 0x02000000 */
-#define USB_OTG_DIEPCTL_CNAK_Pos (26U)
-#define USB_OTG_DIEPCTL_CNAK_Msk (0x1UL << USB_OTG_DIEPCTL_CNAK_Pos) /*!< 0x04000000 */
-#define USB_OTG_DIEPCTL_CNAK USB_OTG_DIEPCTL_CNAK_Msk /*!< Clear NAK */
-#define USB_OTG_DIEPCTL_SNAK_Pos (27U)
-#define USB_OTG_DIEPCTL_SNAK_Msk (0x1UL << USB_OTG_DIEPCTL_SNAK_Pos) /*!< 0x08000000 */
-#define USB_OTG_DIEPCTL_SNAK USB_OTG_DIEPCTL_SNAK_Msk /*!< Set NAK */
-#define USB_OTG_DIEPCTL_SD0PID_SEVNFRM_Pos (28U)
-#define USB_OTG_DIEPCTL_SD0PID_SEVNFRM_Msk (0x1UL << USB_OTG_DIEPCTL_SD0PID_SEVNFRM_Pos) /*!< 0x10000000 */
-#define USB_OTG_DIEPCTL_SD0PID_SEVNFRM USB_OTG_DIEPCTL_SD0PID_SEVNFRM_Msk /*!< Set DATA0 PID */
-#define USB_OTG_DIEPCTL_SODDFRM_Pos (29U)
-#define USB_OTG_DIEPCTL_SODDFRM_Msk (0x1UL << USB_OTG_DIEPCTL_SODDFRM_Pos) /*!< 0x20000000 */
-#define USB_OTG_DIEPCTL_SODDFRM USB_OTG_DIEPCTL_SODDFRM_Msk /*!< Set odd frame */
-#define USB_OTG_DIEPCTL_EPDIS_Pos (30U)
-#define USB_OTG_DIEPCTL_EPDIS_Msk (0x1UL << USB_OTG_DIEPCTL_EPDIS_Pos) /*!< 0x40000000 */
-#define USB_OTG_DIEPCTL_EPDIS USB_OTG_DIEPCTL_EPDIS_Msk /*!< Endpoint disable */
-#define USB_OTG_DIEPCTL_EPENA_Pos (31U)
-#define USB_OTG_DIEPCTL_EPENA_Msk (0x1UL << USB_OTG_DIEPCTL_EPENA_Pos) /*!< 0x80000000 */
-#define USB_OTG_DIEPCTL_EPENA USB_OTG_DIEPCTL_EPENA_Msk /*!< Endpoint enable */
-
-/******************** Bit definition for USB_OTG_HCCHAR register ********************/
-#define USB_OTG_HCCHAR_MPSIZ_Pos (0U)
-#define USB_OTG_HCCHAR_MPSIZ_Msk (0x7FFUL << USB_OTG_HCCHAR_MPSIZ_Pos) /*!< 0x000007FF */
-#define USB_OTG_HCCHAR_MPSIZ USB_OTG_HCCHAR_MPSIZ_Msk /*!< Maximum packet size */
-
-#define USB_OTG_HCCHAR_EPNUM_Pos (11U)
-#define USB_OTG_HCCHAR_EPNUM_Msk (0xFUL << USB_OTG_HCCHAR_EPNUM_Pos) /*!< 0x00007800 */
-#define USB_OTG_HCCHAR_EPNUM USB_OTG_HCCHAR_EPNUM_Msk /*!< Endpoint number */
-#define USB_OTG_HCCHAR_EPNUM_0 (0x1UL << USB_OTG_HCCHAR_EPNUM_Pos) /*!< 0x00000800 */
-#define USB_OTG_HCCHAR_EPNUM_1 (0x2UL << USB_OTG_HCCHAR_EPNUM_Pos) /*!< 0x00001000 */
-#define USB_OTG_HCCHAR_EPNUM_2 (0x4UL << USB_OTG_HCCHAR_EPNUM_Pos) /*!< 0x00002000 */
-#define USB_OTG_HCCHAR_EPNUM_3 (0x8UL << USB_OTG_HCCHAR_EPNUM_Pos) /*!< 0x00004000 */
-#define USB_OTG_HCCHAR_EPDIR_Pos (15U)
-#define USB_OTG_HCCHAR_EPDIR_Msk (0x1UL << USB_OTG_HCCHAR_EPDIR_Pos) /*!< 0x00008000 */
-#define USB_OTG_HCCHAR_EPDIR USB_OTG_HCCHAR_EPDIR_Msk /*!< Endpoint direction */
-#define USB_OTG_HCCHAR_LSDEV_Pos (17U)
-#define USB_OTG_HCCHAR_LSDEV_Msk (0x1UL << USB_OTG_HCCHAR_LSDEV_Pos) /*!< 0x00020000 */
-#define USB_OTG_HCCHAR_LSDEV USB_OTG_HCCHAR_LSDEV_Msk /*!< Low-speed device */
-
-#define USB_OTG_HCCHAR_EPTYP_Pos (18U)
-#define USB_OTG_HCCHAR_EPTYP_Msk (0x3UL << USB_OTG_HCCHAR_EPTYP_Pos) /*!< 0x000C0000 */
-#define USB_OTG_HCCHAR_EPTYP USB_OTG_HCCHAR_EPTYP_Msk /*!< Endpoint type */
-#define USB_OTG_HCCHAR_EPTYP_0 (0x1UL << USB_OTG_HCCHAR_EPTYP_Pos) /*!< 0x00040000 */
-#define USB_OTG_HCCHAR_EPTYP_1 (0x2UL << USB_OTG_HCCHAR_EPTYP_Pos) /*!< 0x00080000 */
-
-#define USB_OTG_HCCHAR_MC_Pos (20U)
-#define USB_OTG_HCCHAR_MC_Msk (0x3UL << USB_OTG_HCCHAR_MC_Pos) /*!< 0x00300000 */
-#define USB_OTG_HCCHAR_MC USB_OTG_HCCHAR_MC_Msk /*!< Multi Count (MC) / Error Count (EC) */
-#define USB_OTG_HCCHAR_MC_0 (0x1UL << USB_OTG_HCCHAR_MC_Pos) /*!< 0x00100000 */
-#define USB_OTG_HCCHAR_MC_1 (0x2UL << USB_OTG_HCCHAR_MC_Pos) /*!< 0x00200000 */
-
-#define USB_OTG_HCCHAR_DAD_Pos (22U)
-#define USB_OTG_HCCHAR_DAD_Msk (0x7FUL << USB_OTG_HCCHAR_DAD_Pos) /*!< 0x1FC00000 */
-#define USB_OTG_HCCHAR_DAD USB_OTG_HCCHAR_DAD_Msk /*!< Device address */
-#define USB_OTG_HCCHAR_DAD_0 (0x01UL << USB_OTG_HCCHAR_DAD_Pos) /*!< 0x00400000 */
-#define USB_OTG_HCCHAR_DAD_1 (0x02UL << USB_OTG_HCCHAR_DAD_Pos) /*!< 0x00800000 */
-#define USB_OTG_HCCHAR_DAD_2 (0x04UL << USB_OTG_HCCHAR_DAD_Pos) /*!< 0x01000000 */
-#define USB_OTG_HCCHAR_DAD_3 (0x08UL << USB_OTG_HCCHAR_DAD_Pos) /*!< 0x02000000 */
-#define USB_OTG_HCCHAR_DAD_4 (0x10UL << USB_OTG_HCCHAR_DAD_Pos) /*!< 0x04000000 */
-#define USB_OTG_HCCHAR_DAD_5 (0x20UL << USB_OTG_HCCHAR_DAD_Pos) /*!< 0x08000000 */
-#define USB_OTG_HCCHAR_DAD_6 (0x40UL << USB_OTG_HCCHAR_DAD_Pos) /*!< 0x10000000 */
-#define USB_OTG_HCCHAR_ODDFRM_Pos (29U)
-#define USB_OTG_HCCHAR_ODDFRM_Msk (0x1UL << USB_OTG_HCCHAR_ODDFRM_Pos) /*!< 0x20000000 */
-#define USB_OTG_HCCHAR_ODDFRM USB_OTG_HCCHAR_ODDFRM_Msk /*!< Odd frame */
-#define USB_OTG_HCCHAR_CHDIS_Pos (30U)
-#define USB_OTG_HCCHAR_CHDIS_Msk (0x1UL << USB_OTG_HCCHAR_CHDIS_Pos) /*!< 0x40000000 */
-#define USB_OTG_HCCHAR_CHDIS USB_OTG_HCCHAR_CHDIS_Msk /*!< Channel disable */
-#define USB_OTG_HCCHAR_CHENA_Pos (31U)
-#define USB_OTG_HCCHAR_CHENA_Msk (0x1UL << USB_OTG_HCCHAR_CHENA_Pos) /*!< 0x80000000 */
-#define USB_OTG_HCCHAR_CHENA USB_OTG_HCCHAR_CHENA_Msk /*!< Channel enable */
-
-/******************** Bit definition for USB_OTG_HCSPLT register ********************/
-
-#define USB_OTG_HCSPLT_PRTADDR_Pos (0U)
-#define USB_OTG_HCSPLT_PRTADDR_Msk (0x7FUL << USB_OTG_HCSPLT_PRTADDR_Pos) /*!< 0x0000007F */
-#define USB_OTG_HCSPLT_PRTADDR USB_OTG_HCSPLT_PRTADDR_Msk /*!< Port address */
-#define USB_OTG_HCSPLT_PRTADDR_0 (0x01UL << USB_OTG_HCSPLT_PRTADDR_Pos) /*!< 0x00000001 */
-#define USB_OTG_HCSPLT_PRTADDR_1 (0x02UL << USB_OTG_HCSPLT_PRTADDR_Pos) /*!< 0x00000002 */
-#define USB_OTG_HCSPLT_PRTADDR_2 (0x04UL << USB_OTG_HCSPLT_PRTADDR_Pos) /*!< 0x00000004 */
-#define USB_OTG_HCSPLT_PRTADDR_3 (0x08UL << USB_OTG_HCSPLT_PRTADDR_Pos) /*!< 0x00000008 */
-#define USB_OTG_HCSPLT_PRTADDR_4 (0x10UL << USB_OTG_HCSPLT_PRTADDR_Pos) /*!< 0x00000010 */
-#define USB_OTG_HCSPLT_PRTADDR_5 (0x20UL << USB_OTG_HCSPLT_PRTADDR_Pos) /*!< 0x00000020 */
-#define USB_OTG_HCSPLT_PRTADDR_6 (0x40UL << USB_OTG_HCSPLT_PRTADDR_Pos) /*!< 0x00000040 */
-
-#define USB_OTG_HCSPLT_HUBADDR_Pos (7U)
-#define USB_OTG_HCSPLT_HUBADDR_Msk (0x7FUL << USB_OTG_HCSPLT_HUBADDR_Pos) /*!< 0x00003F80 */
-#define USB_OTG_HCSPLT_HUBADDR USB_OTG_HCSPLT_HUBADDR_Msk /*!< Hub address */
-#define USB_OTG_HCSPLT_HUBADDR_0 (0x01UL << USB_OTG_HCSPLT_HUBADDR_Pos) /*!< 0x00000080 */
-#define USB_OTG_HCSPLT_HUBADDR_1 (0x02UL << USB_OTG_HCSPLT_HUBADDR_Pos) /*!< 0x00000100 */
-#define USB_OTG_HCSPLT_HUBADDR_2 (0x04UL << USB_OTG_HCSPLT_HUBADDR_Pos) /*!< 0x00000200 */
-#define USB_OTG_HCSPLT_HUBADDR_3 (0x08UL << USB_OTG_HCSPLT_HUBADDR_Pos) /*!< 0x00000400 */
-#define USB_OTG_HCSPLT_HUBADDR_4 (0x10UL << USB_OTG_HCSPLT_HUBADDR_Pos) /*!< 0x00000800 */
-#define USB_OTG_HCSPLT_HUBADDR_5 (0x20UL << USB_OTG_HCSPLT_HUBADDR_Pos) /*!< 0x00001000 */
-#define USB_OTG_HCSPLT_HUBADDR_6 (0x40UL << USB_OTG_HCSPLT_HUBADDR_Pos) /*!< 0x00002000 */
-
-#define USB_OTG_HCSPLT_XACTPOS_Pos (14U)
-#define USB_OTG_HCSPLT_XACTPOS_Msk (0x3UL << USB_OTG_HCSPLT_XACTPOS_Pos) /*!< 0x0000C000 */
-#define USB_OTG_HCSPLT_XACTPOS USB_OTG_HCSPLT_XACTPOS_Msk /*!< XACTPOS */
-#define USB_OTG_HCSPLT_XACTPOS_0 (0x1UL << USB_OTG_HCSPLT_XACTPOS_Pos) /*!< 0x00004000 */
-#define USB_OTG_HCSPLT_XACTPOS_1 (0x2UL << USB_OTG_HCSPLT_XACTPOS_Pos) /*!< 0x00008000 */
-#define USB_OTG_HCSPLT_COMPLSPLT_Pos (16U)
-#define USB_OTG_HCSPLT_COMPLSPLT_Msk (0x1UL << USB_OTG_HCSPLT_COMPLSPLT_Pos) /*!< 0x00010000 */
-#define USB_OTG_HCSPLT_COMPLSPLT USB_OTG_HCSPLT_COMPLSPLT_Msk /*!< Do complete split */
-#define USB_OTG_HCSPLT_SPLITEN_Pos (31U)
-#define USB_OTG_HCSPLT_SPLITEN_Msk (0x1UL << USB_OTG_HCSPLT_SPLITEN_Pos) /*!< 0x80000000 */
-#define USB_OTG_HCSPLT_SPLITEN USB_OTG_HCSPLT_SPLITEN_Msk /*!< Split enable */
-
-/******************** Bit definition for USB_OTG_HCINT register ********************/
-#define USB_OTG_HCINT_XFRC_Pos (0U)
-#define USB_OTG_HCINT_XFRC_Msk (0x1UL << USB_OTG_HCINT_XFRC_Pos) /*!< 0x00000001 */
-#define USB_OTG_HCINT_XFRC USB_OTG_HCINT_XFRC_Msk /*!< Transfer completed */
-#define USB_OTG_HCINT_CHH_Pos (1U)
-#define USB_OTG_HCINT_CHH_Msk (0x1UL << USB_OTG_HCINT_CHH_Pos) /*!< 0x00000002 */
-#define USB_OTG_HCINT_CHH USB_OTG_HCINT_CHH_Msk /*!< Channel halted */
-#define USB_OTG_HCINT_AHBERR_Pos (2U)
-#define USB_OTG_HCINT_AHBERR_Msk (0x1UL << USB_OTG_HCINT_AHBERR_Pos) /*!< 0x00000004 */
-#define USB_OTG_HCINT_AHBERR USB_OTG_HCINT_AHBERR_Msk /*!< AHB error */
-#define USB_OTG_HCINT_STALL_Pos (3U)
-#define USB_OTG_HCINT_STALL_Msk (0x1UL << USB_OTG_HCINT_STALL_Pos) /*!< 0x00000008 */
-#define USB_OTG_HCINT_STALL USB_OTG_HCINT_STALL_Msk /*!< STALL response received interrupt */
-#define USB_OTG_HCINT_NAK_Pos (4U)
-#define USB_OTG_HCINT_NAK_Msk (0x1UL << USB_OTG_HCINT_NAK_Pos) /*!< 0x00000010 */
-#define USB_OTG_HCINT_NAK USB_OTG_HCINT_NAK_Msk /*!< NAK response received interrupt */
-#define USB_OTG_HCINT_ACK_Pos (5U)
-#define USB_OTG_HCINT_ACK_Msk (0x1UL << USB_OTG_HCINT_ACK_Pos) /*!< 0x00000020 */
-#define USB_OTG_HCINT_ACK USB_OTG_HCINT_ACK_Msk /*!< ACK response received/transmitted interrupt */
-#define USB_OTG_HCINT_NYET_Pos (6U)
-#define USB_OTG_HCINT_NYET_Msk (0x1UL << USB_OTG_HCINT_NYET_Pos) /*!< 0x00000040 */
-#define USB_OTG_HCINT_NYET USB_OTG_HCINT_NYET_Msk /*!< Response received interrupt */
-#define USB_OTG_HCINT_TXERR_Pos (7U)
-#define USB_OTG_HCINT_TXERR_Msk (0x1UL << USB_OTG_HCINT_TXERR_Pos) /*!< 0x00000080 */
-#define USB_OTG_HCINT_TXERR USB_OTG_HCINT_TXERR_Msk /*!< Transaction error */
-#define USB_OTG_HCINT_BBERR_Pos (8U)
-#define USB_OTG_HCINT_BBERR_Msk (0x1UL << USB_OTG_HCINT_BBERR_Pos) /*!< 0x00000100 */
-#define USB_OTG_HCINT_BBERR USB_OTG_HCINT_BBERR_Msk /*!< Babble error */
-#define USB_OTG_HCINT_FRMOR_Pos (9U)
-#define USB_OTG_HCINT_FRMOR_Msk (0x1UL << USB_OTG_HCINT_FRMOR_Pos) /*!< 0x00000200 */
-#define USB_OTG_HCINT_FRMOR USB_OTG_HCINT_FRMOR_Msk /*!< Frame overrun */
-#define USB_OTG_HCINT_DTERR_Pos (10U)
-#define USB_OTG_HCINT_DTERR_Msk (0x1UL << USB_OTG_HCINT_DTERR_Pos) /*!< 0x00000400 */
-#define USB_OTG_HCINT_DTERR USB_OTG_HCINT_DTERR_Msk /*!< Data toggle error */
-
-/******************** Bit definition for USB_OTG_DIEPINT register ********************/
-#define USB_OTG_DIEPINT_XFRC_Pos (0U)
-#define USB_OTG_DIEPINT_XFRC_Msk (0x1UL << USB_OTG_DIEPINT_XFRC_Pos) /*!< 0x00000001 */
-#define USB_OTG_DIEPINT_XFRC USB_OTG_DIEPINT_XFRC_Msk /*!< Transfer completed interrupt */
-#define USB_OTG_DIEPINT_EPDISD_Pos (1U)
-#define USB_OTG_DIEPINT_EPDISD_Msk (0x1UL << USB_OTG_DIEPINT_EPDISD_Pos) /*!< 0x00000002 */
-#define USB_OTG_DIEPINT_EPDISD USB_OTG_DIEPINT_EPDISD_Msk /*!< Endpoint disabled interrupt */
-#define USB_OTG_DIEPINT_AHBERR_Pos (2U)
-#define USB_OTG_DIEPINT_AHBERR_Msk (0x1UL << USB_OTG_DIEPINT_AHBERR_Pos) /*!< 0x00000004 */
-#define USB_OTG_DIEPINT_AHBERR USB_OTG_DIEPINT_AHBERR_Msk /*!< AHB Error (AHBErr) during an IN transaction */
-#define USB_OTG_DIEPINT_TOC_Pos (3U)
-#define USB_OTG_DIEPINT_TOC_Msk (0x1UL << USB_OTG_DIEPINT_TOC_Pos) /*!< 0x00000008 */
-#define USB_OTG_DIEPINT_TOC USB_OTG_DIEPINT_TOC_Msk /*!< Timeout condition */
-#define USB_OTG_DIEPINT_ITTXFE_Pos (4U)
-#define USB_OTG_DIEPINT_ITTXFE_Msk (0x1UL << USB_OTG_DIEPINT_ITTXFE_Pos) /*!< 0x00000010 */
-#define USB_OTG_DIEPINT_ITTXFE USB_OTG_DIEPINT_ITTXFE_Msk /*!< IN token received when TxFIFO is empty */
-#define USB_OTG_DIEPINT_INEPNM_Pos (5U)
-#define USB_OTG_DIEPINT_INEPNM_Msk (0x1UL << USB_OTG_DIEPINT_INEPNM_Pos) /*!< 0x00000004 */
-#define USB_OTG_DIEPINT_INEPNM USB_OTG_DIEPINT_INEPNM_Msk /*!< IN token received with EP mismatch */
-#define USB_OTG_DIEPINT_INEPNE_Pos (6U)
-#define USB_OTG_DIEPINT_INEPNE_Msk (0x1UL << USB_OTG_DIEPINT_INEPNE_Pos) /*!< 0x00000040 */
-#define USB_OTG_DIEPINT_INEPNE USB_OTG_DIEPINT_INEPNE_Msk /*!< IN endpoint NAK effective */
-#define USB_OTG_DIEPINT_TXFE_Pos (7U)
-#define USB_OTG_DIEPINT_TXFE_Msk (0x1UL << USB_OTG_DIEPINT_TXFE_Pos) /*!< 0x00000080 */
-#define USB_OTG_DIEPINT_TXFE USB_OTG_DIEPINT_TXFE_Msk /*!< Transmit FIFO empty */
-#define USB_OTG_DIEPINT_TXFIFOUDRN_Pos (8U)
-#define USB_OTG_DIEPINT_TXFIFOUDRN_Msk (0x1UL << USB_OTG_DIEPINT_TXFIFOUDRN_Pos) /*!< 0x00000100 */
-#define USB_OTG_DIEPINT_TXFIFOUDRN USB_OTG_DIEPINT_TXFIFOUDRN_Msk /*!< Transmit Fifo Underrun */
-#define USB_OTG_DIEPINT_BNA_Pos (9U)
-#define USB_OTG_DIEPINT_BNA_Msk (0x1UL << USB_OTG_DIEPINT_BNA_Pos) /*!< 0x00000200 */
-#define USB_OTG_DIEPINT_BNA USB_OTG_DIEPINT_BNA_Msk /*!< Buffer not available interrupt */
-#define USB_OTG_DIEPINT_PKTDRPSTS_Pos (11U)
-#define USB_OTG_DIEPINT_PKTDRPSTS_Msk (0x1UL << USB_OTG_DIEPINT_PKTDRPSTS_Pos) /*!< 0x00000800 */
-#define USB_OTG_DIEPINT_PKTDRPSTS USB_OTG_DIEPINT_PKTDRPSTS_Msk /*!< Packet dropped status */
-#define USB_OTG_DIEPINT_BERR_Pos (12U)
-#define USB_OTG_DIEPINT_BERR_Msk (0x1UL << USB_OTG_DIEPINT_BERR_Pos) /*!< 0x00001000 */
-#define USB_OTG_DIEPINT_BERR USB_OTG_DIEPINT_BERR_Msk /*!< Babble error interrupt */
-#define USB_OTG_DIEPINT_NAK_Pos (13U)
-#define USB_OTG_DIEPINT_NAK_Msk (0x1UL << USB_OTG_DIEPINT_NAK_Pos) /*!< 0x00002000 */
-#define USB_OTG_DIEPINT_NAK USB_OTG_DIEPINT_NAK_Msk /*!< NAK interrupt */
-
-/******************** Bit definition for USB_OTG_HCINTMSK register ********************/
-#define USB_OTG_HCINTMSK_XFRCM_Pos (0U)
-#define USB_OTG_HCINTMSK_XFRCM_Msk (0x1UL << USB_OTG_HCINTMSK_XFRCM_Pos) /*!< 0x00000001 */
-#define USB_OTG_HCINTMSK_XFRCM USB_OTG_HCINTMSK_XFRCM_Msk /*!< Transfer completed mask */
-#define USB_OTG_HCINTMSK_CHHM_Pos (1U)
-#define USB_OTG_HCINTMSK_CHHM_Msk (0x1UL << USB_OTG_HCINTMSK_CHHM_Pos) /*!< 0x00000002 */
-#define USB_OTG_HCINTMSK_CHHM USB_OTG_HCINTMSK_CHHM_Msk /*!< Channel halted mask */
-#define USB_OTG_HCINTMSK_AHBERR_Pos (2U)
-#define USB_OTG_HCINTMSK_AHBERR_Msk (0x1UL << USB_OTG_HCINTMSK_AHBERR_Pos) /*!< 0x00000004 */
-#define USB_OTG_HCINTMSK_AHBERR USB_OTG_HCINTMSK_AHBERR_Msk /*!< AHB error */
-#define USB_OTG_HCINTMSK_STALLM_Pos (3U)
-#define USB_OTG_HCINTMSK_STALLM_Msk (0x1UL << USB_OTG_HCINTMSK_STALLM_Pos) /*!< 0x00000008 */
-#define USB_OTG_HCINTMSK_STALLM USB_OTG_HCINTMSK_STALLM_Msk /*!< STALL response received interrupt mask */
-#define USB_OTG_HCINTMSK_NAKM_Pos (4U)
-#define USB_OTG_HCINTMSK_NAKM_Msk (0x1UL << USB_OTG_HCINTMSK_NAKM_Pos) /*!< 0x00000010 */
-#define USB_OTG_HCINTMSK_NAKM USB_OTG_HCINTMSK_NAKM_Msk /*!< NAK response received interrupt mask */
-#define USB_OTG_HCINTMSK_ACKM_Pos (5U)
-#define USB_OTG_HCINTMSK_ACKM_Msk (0x1UL << USB_OTG_HCINTMSK_ACKM_Pos) /*!< 0x00000020 */
-#define USB_OTG_HCINTMSK_ACKM USB_OTG_HCINTMSK_ACKM_Msk /*!< ACK response received/transmitted interrupt mask */
-#define USB_OTG_HCINTMSK_NYET_Pos (6U)
-#define USB_OTG_HCINTMSK_NYET_Msk (0x1UL << USB_OTG_HCINTMSK_NYET_Pos) /*!< 0x00000040 */
-#define USB_OTG_HCINTMSK_NYET USB_OTG_HCINTMSK_NYET_Msk /*!< response received interrupt mask */
-#define USB_OTG_HCINTMSK_TXERRM_Pos (7U)
-#define USB_OTG_HCINTMSK_TXERRM_Msk (0x1UL << USB_OTG_HCINTMSK_TXERRM_Pos) /*!< 0x00000080 */
-#define USB_OTG_HCINTMSK_TXERRM USB_OTG_HCINTMSK_TXERRM_Msk /*!< Transaction error mask */
-#define USB_OTG_HCINTMSK_BBERRM_Pos (8U)
-#define USB_OTG_HCINTMSK_BBERRM_Msk (0x1UL << USB_OTG_HCINTMSK_BBERRM_Pos) /*!< 0x00000100 */
-#define USB_OTG_HCINTMSK_BBERRM USB_OTG_HCINTMSK_BBERRM_Msk /*!< Babble error mask */
-#define USB_OTG_HCINTMSK_FRMORM_Pos (9U)
-#define USB_OTG_HCINTMSK_FRMORM_Msk (0x1UL << USB_OTG_HCINTMSK_FRMORM_Pos) /*!< 0x00000200 */
-#define USB_OTG_HCINTMSK_FRMORM USB_OTG_HCINTMSK_FRMORM_Msk /*!< Frame overrun mask */
-#define USB_OTG_HCINTMSK_DTERRM_Pos (10U)
-#define USB_OTG_HCINTMSK_DTERRM_Msk (0x1UL << USB_OTG_HCINTMSK_DTERRM_Pos) /*!< 0x00000400 */
-#define USB_OTG_HCINTMSK_DTERRM USB_OTG_HCINTMSK_DTERRM_Msk /*!< Data toggle error mask */
-
-/******************** Bit definition for USB_OTG_DIEPTSIZ register ********************/
-
-#define USB_OTG_DIEPTSIZ_XFRSIZ_Pos (0U)
-#define USB_OTG_DIEPTSIZ_XFRSIZ_Msk (0x7FFFFUL << USB_OTG_DIEPTSIZ_XFRSIZ_Pos) /*!< 0x0007FFFF */
-#define USB_OTG_DIEPTSIZ_XFRSIZ USB_OTG_DIEPTSIZ_XFRSIZ_Msk /*!< Transfer size */
-#define USB_OTG_DIEPTSIZ_PKTCNT_Pos (19U)
-#define USB_OTG_DIEPTSIZ_PKTCNT_Msk (0x3FFUL << USB_OTG_DIEPTSIZ_PKTCNT_Pos) /*!< 0x1FF80000 */
-#define USB_OTG_DIEPTSIZ_PKTCNT USB_OTG_DIEPTSIZ_PKTCNT_Msk /*!< Packet count */
-#define USB_OTG_DIEPTSIZ_MULCNT_Pos (29U)
-#define USB_OTG_DIEPTSIZ_MULCNT_Msk (0x3UL << USB_OTG_DIEPTSIZ_MULCNT_Pos) /*!< 0x60000000 */
-#define USB_OTG_DIEPTSIZ_MULCNT USB_OTG_DIEPTSIZ_MULCNT_Msk /*!< Packet count */
-/******************** Bit definition for USB_OTG_HCTSIZ register ********************/
-#define USB_OTG_HCTSIZ_XFRSIZ_Pos (0U)
-#define USB_OTG_HCTSIZ_XFRSIZ_Msk (0x7FFFFUL << USB_OTG_HCTSIZ_XFRSIZ_Pos) /*!< 0x0007FFFF */
-#define USB_OTG_HCTSIZ_XFRSIZ USB_OTG_HCTSIZ_XFRSIZ_Msk /*!< Transfer size */
-#define USB_OTG_HCTSIZ_PKTCNT_Pos (19U)
-#define USB_OTG_HCTSIZ_PKTCNT_Msk (0x3FFUL << USB_OTG_HCTSIZ_PKTCNT_Pos) /*!< 0x1FF80000 */
-#define USB_OTG_HCTSIZ_PKTCNT USB_OTG_HCTSIZ_PKTCNT_Msk /*!< Packet count */
-#define USB_OTG_HCTSIZ_DOPING_Pos (31U)
-#define USB_OTG_HCTSIZ_DOPING_Msk (0x1UL << USB_OTG_HCTSIZ_DOPING_Pos) /*!< 0x80000000 */
-#define USB_OTG_HCTSIZ_DOPING USB_OTG_HCTSIZ_DOPING_Msk /*!< Do PING */
-#define USB_OTG_HCTSIZ_DPID_Pos (29U)
-#define USB_OTG_HCTSIZ_DPID_Msk (0x3UL << USB_OTG_HCTSIZ_DPID_Pos) /*!< 0x60000000 */
-#define USB_OTG_HCTSIZ_DPID USB_OTG_HCTSIZ_DPID_Msk /*!< Data PID */
-#define USB_OTG_HCTSIZ_DPID_0 (0x1UL << USB_OTG_HCTSIZ_DPID_Pos) /*!< 0x20000000 */
-#define USB_OTG_HCTSIZ_DPID_1 (0x2UL << USB_OTG_HCTSIZ_DPID_Pos) /*!< 0x40000000 */
-
-/******************** Bit definition for USB_OTG_DIEPDMA register ********************/
-#define USB_OTG_DIEPDMA_DMAADDR_Pos (0U)
-#define USB_OTG_DIEPDMA_DMAADDR_Msk (0xFFFFFFFFUL << USB_OTG_DIEPDMA_DMAADDR_Pos) /*!< 0xFFFFFFFF */
-#define USB_OTG_DIEPDMA_DMAADDR USB_OTG_DIEPDMA_DMAADDR_Msk /*!< DMA address */
-
-/******************** Bit definition for USB_OTG_HCDMA register ********************/
-#define USB_OTG_HCDMA_DMAADDR_Pos (0U)
-#define USB_OTG_HCDMA_DMAADDR_Msk (0xFFFFFFFFUL << USB_OTG_HCDMA_DMAADDR_Pos) /*!< 0xFFFFFFFF */
-#define USB_OTG_HCDMA_DMAADDR USB_OTG_HCDMA_DMAADDR_Msk /*!< DMA address */
-
-/******************** Bit definition for USB_OTG_DTXFSTS register ********************/
-#define USB_OTG_DTXFSTS_INEPTFSAV_Pos (0U)
-#define USB_OTG_DTXFSTS_INEPTFSAV_Msk (0xFFFFUL << USB_OTG_DTXFSTS_INEPTFSAV_Pos) /*!< 0x0000FFFF */
-#define USB_OTG_DTXFSTS_INEPTFSAV USB_OTG_DTXFSTS_INEPTFSAV_Msk /*!< IN endpoint TxFIFO space available */
-
-/******************** Bit definition for USB_OTG_DIEPTXF register ********************/
-#define USB_OTG_DIEPTXF_INEPTXSA_Pos (0U)
-#define USB_OTG_DIEPTXF_INEPTXSA_Msk (0xFFFFUL << USB_OTG_DIEPTXF_INEPTXSA_Pos) /*!< 0x0000FFFF */
-#define USB_OTG_DIEPTXF_INEPTXSA USB_OTG_DIEPTXF_INEPTXSA_Msk /*!< IN endpoint FIFOx transmit RAM start address */
-#define USB_OTG_DIEPTXF_INEPTXFD_Pos (16U)
-#define USB_OTG_DIEPTXF_INEPTXFD_Msk (0xFFFFUL << USB_OTG_DIEPTXF_INEPTXFD_Pos) /*!< 0xFFFF0000 */
-#define USB_OTG_DIEPTXF_INEPTXFD USB_OTG_DIEPTXF_INEPTXFD_Msk /*!< IN endpoint TxFIFO depth */
-
-/******************** Bit definition for USB_OTG_DOEPCTL register ********************/
-
-#define USB_OTG_DOEPCTL_MPSIZ_Pos (0U)
-#define USB_OTG_DOEPCTL_MPSIZ_Msk (0x7FFUL << USB_OTG_DOEPCTL_MPSIZ_Pos) /*!< 0x000007FF */
-#define USB_OTG_DOEPCTL_MPSIZ USB_OTG_DOEPCTL_MPSIZ_Msk /*!< Maximum packet size */ /*!<Bit 1 */
-#define USB_OTG_DOEPCTL_USBAEP_Pos (15U)
-#define USB_OTG_DOEPCTL_USBAEP_Msk (0x1UL << USB_OTG_DOEPCTL_USBAEP_Pos) /*!< 0x00008000 */
-#define USB_OTG_DOEPCTL_USBAEP USB_OTG_DOEPCTL_USBAEP_Msk /*!< USB active endpoint */
-#define USB_OTG_DOEPCTL_NAKSTS_Pos (17U)
-#define USB_OTG_DOEPCTL_NAKSTS_Msk (0x1UL << USB_OTG_DOEPCTL_NAKSTS_Pos) /*!< 0x00020000 */
-#define USB_OTG_DOEPCTL_NAKSTS USB_OTG_DOEPCTL_NAKSTS_Msk /*!< NAK status */
-#define USB_OTG_DOEPCTL_SD0PID_SEVNFRM_Pos (28U)
-#define USB_OTG_DOEPCTL_SD0PID_SEVNFRM_Msk (0x1UL << USB_OTG_DOEPCTL_SD0PID_SEVNFRM_Pos) /*!< 0x10000000 */
-#define USB_OTG_DOEPCTL_SD0PID_SEVNFRM USB_OTG_DOEPCTL_SD0PID_SEVNFRM_Msk /*!< Set DATA0 PID */
-#define USB_OTG_DOEPCTL_SODDFRM_Pos (29U)
-#define USB_OTG_DOEPCTL_SODDFRM_Msk (0x1UL << USB_OTG_DOEPCTL_SODDFRM_Pos) /*!< 0x20000000 */
-#define USB_OTG_DOEPCTL_SODDFRM USB_OTG_DOEPCTL_SODDFRM_Msk /*!< Set odd frame */
-#define USB_OTG_DOEPCTL_EPTYP_Pos (18U)
-#define USB_OTG_DOEPCTL_EPTYP_Msk (0x3UL << USB_OTG_DOEPCTL_EPTYP_Pos) /*!< 0x000C0000 */
-#define USB_OTG_DOEPCTL_EPTYP USB_OTG_DOEPCTL_EPTYP_Msk /*!< Endpoint type */
-#define USB_OTG_DOEPCTL_EPTYP_0 (0x1UL << USB_OTG_DOEPCTL_EPTYP_Pos) /*!< 0x00040000 */
-#define USB_OTG_DOEPCTL_EPTYP_1 (0x2UL << USB_OTG_DOEPCTL_EPTYP_Pos) /*!< 0x00080000 */
-#define USB_OTG_DOEPCTL_SNPM_Pos (20U)
-#define USB_OTG_DOEPCTL_SNPM_Msk (0x1UL << USB_OTG_DOEPCTL_SNPM_Pos) /*!< 0x00100000 */
-#define USB_OTG_DOEPCTL_SNPM USB_OTG_DOEPCTL_SNPM_Msk /*!< Snoop mode */
-#define USB_OTG_DOEPCTL_STALL_Pos (21U)
-#define USB_OTG_DOEPCTL_STALL_Msk (0x1UL << USB_OTG_DOEPCTL_STALL_Pos) /*!< 0x00200000 */
-#define USB_OTG_DOEPCTL_STALL USB_OTG_DOEPCTL_STALL_Msk /*!< STALL handshake */
-#define USB_OTG_DOEPCTL_CNAK_Pos (26U)
-#define USB_OTG_DOEPCTL_CNAK_Msk (0x1UL << USB_OTG_DOEPCTL_CNAK_Pos) /*!< 0x04000000 */
-#define USB_OTG_DOEPCTL_CNAK USB_OTG_DOEPCTL_CNAK_Msk /*!< Clear NAK */
-#define USB_OTG_DOEPCTL_SNAK_Pos (27U)
-#define USB_OTG_DOEPCTL_SNAK_Msk (0x1UL << USB_OTG_DOEPCTL_SNAK_Pos) /*!< 0x08000000 */
-#define USB_OTG_DOEPCTL_SNAK USB_OTG_DOEPCTL_SNAK_Msk /*!< Set NAK */
-#define USB_OTG_DOEPCTL_EPDIS_Pos (30U)
-#define USB_OTG_DOEPCTL_EPDIS_Msk (0x1UL << USB_OTG_DOEPCTL_EPDIS_Pos) /*!< 0x40000000 */
-#define USB_OTG_DOEPCTL_EPDIS USB_OTG_DOEPCTL_EPDIS_Msk /*!< Endpoint disable */
-#define USB_OTG_DOEPCTL_EPENA_Pos (31U)
-#define USB_OTG_DOEPCTL_EPENA_Msk (0x1UL << USB_OTG_DOEPCTL_EPENA_Pos) /*!< 0x80000000 */
-#define USB_OTG_DOEPCTL_EPENA USB_OTG_DOEPCTL_EPENA_Msk /*!< Endpoint enable */
-
-/******************** Bit definition for USB_OTG_DOEPINT register ********************/
-#define USB_OTG_DOEPINT_XFRC_Pos (0U)
-#define USB_OTG_DOEPINT_XFRC_Msk (0x1UL << USB_OTG_DOEPINT_XFRC_Pos) /*!< 0x00000001 */
-#define USB_OTG_DOEPINT_XFRC USB_OTG_DOEPINT_XFRC_Msk /*!< Transfer completed interrupt */
-#define USB_OTG_DOEPINT_EPDISD_Pos (1U)
-#define USB_OTG_DOEPINT_EPDISD_Msk (0x1UL << USB_OTG_DOEPINT_EPDISD_Pos) /*!< 0x00000002 */
-#define USB_OTG_DOEPINT_EPDISD USB_OTG_DOEPINT_EPDISD_Msk /*!< Endpoint disabled interrupt */
-#define USB_OTG_DOEPINT_AHBERR_Pos (2U)
-#define USB_OTG_DOEPINT_AHBERR_Msk (0x1UL << USB_OTG_DOEPINT_AHBERR_Pos) /*!< 0x00000004 */
-#define USB_OTG_DOEPINT_AHBERR USB_OTG_DOEPINT_AHBERR_Msk /*!< AHB Error (AHBErr) during an OUT transaction */
-#define USB_OTG_DOEPINT_STUP_Pos (3U)
-#define USB_OTG_DOEPINT_STUP_Msk (0x1UL << USB_OTG_DOEPINT_STUP_Pos) /*!< 0x00000008 */
-#define USB_OTG_DOEPINT_STUP USB_OTG_DOEPINT_STUP_Msk /*!< SETUP phase done */
-#define USB_OTG_DOEPINT_OTEPDIS_Pos (4U)
-#define USB_OTG_DOEPINT_OTEPDIS_Msk (0x1UL << USB_OTG_DOEPINT_OTEPDIS_Pos) /*!< 0x00000010 */
-#define USB_OTG_DOEPINT_OTEPDIS USB_OTG_DOEPINT_OTEPDIS_Msk /*!< OUT token received when endpoint disabled */
-#define USB_OTG_DOEPINT_OTEPSPR_Pos (5U)
-#define USB_OTG_DOEPINT_OTEPSPR_Msk (0x1UL << USB_OTG_DOEPINT_OTEPSPR_Pos) /*!< 0x00000020 */
-#define USB_OTG_DOEPINT_OTEPSPR USB_OTG_DOEPINT_OTEPSPR_Msk /*!< Status Phase Received For Control Write */
-#define USB_OTG_DOEPINT_B2BSTUP_Pos (6U)
-#define USB_OTG_DOEPINT_B2BSTUP_Msk (0x1UL << USB_OTG_DOEPINT_B2BSTUP_Pos) /*!< 0x00000040 */
-#define USB_OTG_DOEPINT_B2BSTUP USB_OTG_DOEPINT_B2BSTUP_Msk /*!< Back-to-back SETUP packets received */
-#define USB_OTG_DOEPINT_OUTPKTERR_Pos (8U)
-#define USB_OTG_DOEPINT_OUTPKTERR_Msk (0x1UL << USB_OTG_DOEPINT_OUTPKTERR_Pos) /*!< 0x00000100 */
-#define USB_OTG_DOEPINT_OUTPKTERR USB_OTG_DOEPINT_OUTPKTERR_Msk /*!< OUT packet error */
-#define USB_OTG_DOEPINT_NAK_Pos (13U)
-#define USB_OTG_DOEPINT_NAK_Msk (0x1UL << USB_OTG_DOEPINT_NAK_Pos) /*!< 0x00002000 */
-#define USB_OTG_DOEPINT_NAK USB_OTG_DOEPINT_NAK_Msk /*!< NAK Packet is transmitted by the device */
-#define USB_OTG_DOEPINT_NYET_Pos (14U)
-#define USB_OTG_DOEPINT_NYET_Msk (0x1UL << USB_OTG_DOEPINT_NYET_Pos) /*!< 0x00004000 */
-#define USB_OTG_DOEPINT_NYET USB_OTG_DOEPINT_NYET_Msk /*!< NYET interrupt */
-#define USB_OTG_DOEPINT_STPKTRX_Pos (15U)
-#define USB_OTG_DOEPINT_STPKTRX_Msk (0x1UL << USB_OTG_DOEPINT_STPKTRX_Pos) /*!< 0x00008000 */
-#define USB_OTG_DOEPINT_STPKTRX USB_OTG_DOEPINT_STPKTRX_Msk /*!< Setup Packet Received */
-/******************** Bit definition for USB_OTG_DOEPTSIZ register ********************/
-
-#define USB_OTG_DOEPTSIZ_XFRSIZ_Pos (0U)
-#define USB_OTG_DOEPTSIZ_XFRSIZ_Msk (0x7FFFFUL << USB_OTG_DOEPTSIZ_XFRSIZ_Pos) /*!< 0x0007FFFF */
-#define USB_OTG_DOEPTSIZ_XFRSIZ USB_OTG_DOEPTSIZ_XFRSIZ_Msk /*!< Transfer size */
-#define USB_OTG_DOEPTSIZ_PKTCNT_Pos (19U)
-#define USB_OTG_DOEPTSIZ_PKTCNT_Msk (0x3FFUL << USB_OTG_DOEPTSIZ_PKTCNT_Pos) /*!< 0x1FF80000 */
-#define USB_OTG_DOEPTSIZ_PKTCNT USB_OTG_DOEPTSIZ_PKTCNT_Msk /*!< Packet count */
-
-#define USB_OTG_DOEPTSIZ_STUPCNT_Pos (29U)
-#define USB_OTG_DOEPTSIZ_STUPCNT_Msk (0x3UL << USB_OTG_DOEPTSIZ_STUPCNT_Pos) /*!< 0x60000000 */
-#define USB_OTG_DOEPTSIZ_STUPCNT USB_OTG_DOEPTSIZ_STUPCNT_Msk /*!< SETUP packet count */
-#define USB_OTG_DOEPTSIZ_STUPCNT_0 (0x1UL << USB_OTG_DOEPTSIZ_STUPCNT_Pos) /*!< 0x20000000 */
-#define USB_OTG_DOEPTSIZ_STUPCNT_1 (0x2UL << USB_OTG_DOEPTSIZ_STUPCNT_Pos) /*!< 0x40000000 */
-
-/******************** Bit definition for PCGCCTL register ********************/
-#define USB_OTG_PCGCCTL_STOPCLK_Pos (0U)
-#define USB_OTG_PCGCCTL_STOPCLK_Msk (0x1UL << USB_OTG_PCGCCTL_STOPCLK_Pos) /*!< 0x00000001 */
-#define USB_OTG_PCGCCTL_STOPCLK USB_OTG_PCGCCTL_STOPCLK_Msk /*!< SETUP packet count */
-#define USB_OTG_PCGCCTL_GATECLK_Pos (1U)
-#define USB_OTG_PCGCCTL_GATECLK_Msk (0x1UL << USB_OTG_PCGCCTL_GATECLK_Pos) /*!< 0x00000002 */
-#define USB_OTG_PCGCCTL_GATECLK USB_OTG_PCGCCTL_GATECLK_Msk /*!<Bit 0 */
-#define USB_OTG_PCGCCTL_PHYSUSP_Pos (4U)
-#define USB_OTG_PCGCCTL_PHYSUSP_Msk (0x1UL << USB_OTG_PCGCCTL_PHYSUSP_Pos) /*!< 0x00000010 */
-#define USB_OTG_PCGCCTL_PHYSUSP USB_OTG_PCGCCTL_PHYSUSP_Msk /*!<Bit 1 */
-
-/* Legacy define */
-/******************** Bit definition for OTG register ********************/
-#define USB_OTG_CHNUM_Pos (0U)
-#define USB_OTG_CHNUM_Msk (0xFUL << USB_OTG_CHNUM_Pos) /*!< 0x0000000F */
-#define USB_OTG_CHNUM USB_OTG_CHNUM_Msk /*!< Channel number */
-#define USB_OTG_CHNUM_0 (0x1UL << USB_OTG_CHNUM_Pos) /*!< 0x00000001 */
-#define USB_OTG_CHNUM_1 (0x2UL << USB_OTG_CHNUM_Pos) /*!< 0x00000002 */
-#define USB_OTG_CHNUM_2 (0x4UL << USB_OTG_CHNUM_Pos) /*!< 0x00000004 */
-#define USB_OTG_CHNUM_3 (0x8UL << USB_OTG_CHNUM_Pos) /*!< 0x00000008 */
-#define USB_OTG_BCNT_Pos (4U)
-#define USB_OTG_BCNT_Msk (0x7FFUL << USB_OTG_BCNT_Pos) /*!< 0x00007FF0 */
-#define USB_OTG_BCNT USB_OTG_BCNT_Msk /*!< Byte count */
-
-#define USB_OTG_DPID_Pos (15U)
-#define USB_OTG_DPID_Msk (0x3UL << USB_OTG_DPID_Pos) /*!< 0x00018000 */
-#define USB_OTG_DPID USB_OTG_DPID_Msk /*!< Data PID */
-#define USB_OTG_DPID_0 (0x1UL << USB_OTG_DPID_Pos) /*!< 0x00008000 */
-#define USB_OTG_DPID_1 (0x2UL << USB_OTG_DPID_Pos) /*!< 0x00010000 */
-
-#define USB_OTG_PKTSTS_Pos (17U)
-#define USB_OTG_PKTSTS_Msk (0xFUL << USB_OTG_PKTSTS_Pos) /*!< 0x001E0000 */
-#define USB_OTG_PKTSTS USB_OTG_PKTSTS_Msk /*!< Packet status */
-#define USB_OTG_PKTSTS_0 (0x1UL << USB_OTG_PKTSTS_Pos) /*!< 0x00020000 */
-#define USB_OTG_PKTSTS_1 (0x2UL << USB_OTG_PKTSTS_Pos) /*!< 0x00040000 */
-#define USB_OTG_PKTSTS_2 (0x4UL << USB_OTG_PKTSTS_Pos) /*!< 0x00080000 */
-#define USB_OTG_PKTSTS_3 (0x8UL << USB_OTG_PKTSTS_Pos) /*!< 0x00100000 */
-
-#define USB_OTG_EPNUM_Pos (0U)
-#define USB_OTG_EPNUM_Msk (0xFUL << USB_OTG_EPNUM_Pos) /*!< 0x0000000F */
-#define USB_OTG_EPNUM USB_OTG_EPNUM_Msk /*!< Endpoint number */
-#define USB_OTG_EPNUM_0 (0x1UL << USB_OTG_EPNUM_Pos) /*!< 0x00000001 */
-#define USB_OTG_EPNUM_1 (0x2UL << USB_OTG_EPNUM_Pos) /*!< 0x00000002 */
-#define USB_OTG_EPNUM_2 (0x4UL << USB_OTG_EPNUM_Pos) /*!< 0x00000004 */
-#define USB_OTG_EPNUM_3 (0x8UL << USB_OTG_EPNUM_Pos) /*!< 0x00000008 */
-
-#define USB_OTG_FRMNUM_Pos (21U)
-#define USB_OTG_FRMNUM_Msk (0xFUL << USB_OTG_FRMNUM_Pos) /*!< 0x01E00000 */
-#define USB_OTG_FRMNUM USB_OTG_FRMNUM_Msk /*!< Frame number */
-#define USB_OTG_FRMNUM_0 (0x1UL << USB_OTG_FRMNUM_Pos) /*!< 0x00200000 */
-#define USB_OTG_FRMNUM_1 (0x2UL << USB_OTG_FRMNUM_Pos) /*!< 0x00400000 */
-#define USB_OTG_FRMNUM_2 (0x4UL << USB_OTG_FRMNUM_Pos) /*!< 0x00800000 */
-#define USB_OTG_FRMNUM_3 (0x8UL << USB_OTG_FRMNUM_Pos) /*!< 0x01000000 */
-
-/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
diff --git a/tinyusb/src/portable/template/dcd_template.c b/tinyusb/src/portable/template/dcd_template.c
deleted file mode 100755
index 12b9144b..00000000
--- a/tinyusb/src/portable/template/dcd_template.c
+++ /dev/null
@@ -1,131 +0,0 @@
-/*
- * The MIT License (MIT)
- *
- * Copyright (c) 2018, hathach (tinyusb.org)
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- *
- * This file is part of the TinyUSB stack.
- */
-
-#include "tusb_option.h"
-
-#if CFG_TUSB_MCU == OPT_MCU_NONE
-
-#include "device/dcd.h"
-
-//--------------------------------------------------------------------+
-// MACRO TYPEDEF CONSTANT ENUM DECLARATION
-//--------------------------------------------------------------------+
-
-
-/*------------------------------------------------------------------*/
-/* Device API
- *------------------------------------------------------------------*/
-
-// Initialize controller to device mode
-void dcd_init (uint8_t rhport)
-{
- (void) rhport;
-}
-
-// Enable device interrupt
-void dcd_int_enable (uint8_t rhport)
-{
- (void) rhport;
-}
-
-// Disable device interrupt
-void dcd_int_disable (uint8_t rhport)
-{
- (void) rhport;
-}
-
-// Receive Set Address request, mcu port must also include status IN response
-void dcd_set_address (uint8_t rhport, uint8_t dev_addr)
-{
- (void) rhport;
- (void) dev_addr;
-}
-
-// Wake up host
-void dcd_remote_wakeup (uint8_t rhport)
-{
- (void) rhport;
-}
-
-// Connect by enabling internal pull-up resistor on D+/D-
-void dcd_connect(uint8_t rhport)
-{
- (void) rhport;
-}
-
-// Disconnect by disabling internal pull-up resistor on D+/D-
-void dcd_disconnect(uint8_t rhport)
-{
- (void) rhport;
-}
-
-//--------------------------------------------------------------------+
-// Endpoint API
-//--------------------------------------------------------------------+
-
-// Configure endpoint's registers according to descriptor
-bool dcd_edpt_open (uint8_t rhport, tusb_desc_endpoint_t const * ep_desc)
-{
- (void) rhport;
- (void) ep_desc;
- return false;
-}
-
-// Submit a transfer, When complete dcd_event_xfer_complete() is invoked to notify the stack
-bool dcd_edpt_xfer (uint8_t rhport, uint8_t ep_addr, uint8_t * buffer, uint16_t total_bytes)
-{
- (void) rhport;
- (void) ep_addr;
- (void) buffer;
- (void) total_bytes;
- return false;
-}
-
-// Submit a transfer where is managed by FIFO, When complete dcd_event_xfer_complete() is invoked to notify the stack - optional, however, must be listed in usbd.c
-bool dcd_edpt_xfer_fifo (uint8_t rhport, uint8_t ep_addr, tu_fifo_t * ff, uint16_t total_bytes)
-{
- (void) rhport;
- (void) ep_addr;
- (void) ff;
- (void) total_bytes;
- return false;
-}
-
-// Stall endpoint
-void dcd_edpt_stall (uint8_t rhport, uint8_t ep_addr)
-{
- (void) rhport;
- (void) ep_addr;
-}
-
-// clear stall, data toggle is also reset to DATA0
-void dcd_edpt_clear_stall (uint8_t rhport, uint8_t ep_addr)
-{
- (void) rhport;
- (void) ep_addr;
-}
-
-#endif
diff --git a/tinyusb/src/portable/ti/msp430x5xx/dcd_msp430x5xx.c b/tinyusb/src/portable/ti/msp430x5xx/dcd_msp430x5xx.c
deleted file mode 100755
index 027ed26c..00000000
--- a/tinyusb/src/portable/ti/msp430x5xx/dcd_msp430x5xx.c
+++ /dev/null
@@ -1,694 +0,0 @@
-/*
- * The MIT License (MIT)
- *
- * Copyright (c) 2019-2020 William D. Jones
- * Copyright (c) 2019-2020 Ha Thach (tinyusb.org)
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- *
- * This file is part of the TinyUSB stack.
- */
-
-#include "tusb_option.h"
-
-#if TUSB_OPT_DEVICE_ENABLED && ( CFG_TUSB_MCU == OPT_MCU_MSP430x5xx )
-
-#include "msp430.h"
-#include "device/dcd.h"
-
-/*------------------------------------------------------------------*/
-/* MACRO TYPEDEF CONSTANT ENUM
- *------------------------------------------------------------------*/
-// usbpllir_mirror and usbmaintl_mirror can be added later if needed.
-static volatile uint16_t usbiepie_mirror = 0;
-static volatile uint16_t usboepie_mirror = 0;
-static volatile uint8_t usbie_mirror = 0;
-static volatile uint16_t usbpwrctl_mirror = 0;
-static bool in_isr = false;
-
-uint8_t _setup_packet[8];
-
-// Xfer control
-typedef struct
-{
- uint8_t * buffer;
- // tu_fifo_t * ff; // TODO support dcd_edpt_xfer_fifo API
- uint16_t total_len;
- uint16_t queued_len;
- uint16_t max_size;
- bool short_packet;
-} xfer_ctl_t;
-
-xfer_ctl_t xfer_status[8][2];
-#define XFER_CTL_BASE(_ep, _dir) &xfer_status[_ep][_dir]
-
-// Accessing endpoint regs
-typedef volatile uint8_t * ep_regs_t;
-
-typedef enum
-{
- CNF = 0,
- BBAX = 1,
- BCTX = 2,
- BBAY = 5,
- BCTY = 6,
- SIZXY = 7
-} ep_regs_index_t;
-
-#define EP_REGS(epnum, dir) ((ep_regs_t) ((uintptr_t)&USBOEPCNF_1 + 64*dir + 8*(epnum - 1)))
-
-static void bus_reset(void)
-{
- // Hardcoded into the USB core.
- xfer_status[0][TUSB_DIR_OUT].max_size = 8;
- xfer_status[0][TUSB_DIR_IN].max_size = 8;
-
- USBKEYPID = USBKEY;
-
- // Enable the control EP 0. Also enable Indication Enable- a guard flag
- // separate from the Interrupt Enable mask.
- USBOEPCNF_0 |= (UBME | USBIIE);
- USBIEPCNF_0 |= (UBME | USBIIE);
-
- // Enable interrupts for this endpoint.
- USBOEPIE |= BIT0;
- USBIEPIE |= BIT0;
-
- // Clear NAK until a setup packet is received.
- USBOEPCNT_0 &= ~NAK;
- USBIEPCNT_0 &= ~NAK;
-
- USBCTL |= FEN; // Enable responding to packets.
-
- // Dedicated buffers in hardware for SETUP and EP0, no setup needed.
- // Now safe to respond to SETUP packets.
- USBIE |= SETUPIE;
-
- USBKEYPID = 0;
-}
-
-
-/*------------------------------------------------------------------*/
-/* Controller API
- *------------------------------------------------------------------*/
-void dcd_init (uint8_t rhport)
-{
- (void) rhport;
-
- USBKEYPID = USBKEY;
-
- // Enable the module (required to write config regs)!
- USBCNF |= USB_EN;
-
- // Reset used interrupts
- USBOEPIE = 0;
- USBIEPIE = 0;
- USBIE = 0;
- USBOEPIFG = 0;
- USBIEPIFG = 0;
- USBIFG = 0;
- USBPWRCTL &= ~(VUOVLIE | VBONIE | VBOFFIE | VUOVLIFG | VBONIFG | VBOFFIFG);
- usboepie_mirror = 0;
- usbiepie_mirror = 0;
- usbie_mirror = 0;
- usbpwrctl_mirror = 0;
-
- USBVECINT = 0;
-
- // Enable reset and wait for it before continuing.
- USBIE |= RSTRIE;
-
- // Enable pullup.
- USBCNF |= PUR_EN;
-
- USBKEYPID = 0;
-}
-
-// There is no "USB peripheral interrupt disable" bit on MSP430, so we have
-// to save the relevant registers individually.
-// WARNING: Unlike the ARM/NVIC routines, these functions are _not_ idempotent
-// if you modified the registers saved in between calls so they don't match
-// the mirrors; mirrors will be updated to reflect most recent register
-// contents.
-void dcd_int_enable (uint8_t rhport)
-{
- (void) rhport;
-
- __bic_SR_register(GIE); // Unlikely to be called in ISR, but let's be safe.
- // Also, this cleanly disables all USB interrupts
- // atomically from application's POV.
-
- // This guard is required because tinyusb can enable interrupts without
- // having disabled them first.
- if(in_isr)
- {
- USBOEPIE = usboepie_mirror;
- USBIEPIE = usbiepie_mirror;
- USBIE = usbie_mirror;
- USBPWRCTL |= usbpwrctl_mirror;
- }
-
- in_isr = false;
- __bis_SR_register(GIE);
-}
-
-void dcd_int_disable (uint8_t rhport)
-{
- (void) rhport;
-
- __bic_SR_register(GIE);
- usboepie_mirror = USBOEPIE;
- usbiepie_mirror = USBIEPIE;
- usbie_mirror = USBIE;
- usbpwrctl_mirror = (USBPWRCTL & (VUOVLIE | VBONIE | VBOFFIE));
- USBOEPIE = 0;
- USBIEPIE = 0;
- USBIE = 0;
- USBPWRCTL &= ~(VUOVLIE | VBONIE | VBOFFIE);
- in_isr = true;
- __bis_SR_register(GIE);
-}
-
-void dcd_set_address (uint8_t rhport, uint8_t dev_addr)
-{
- (void) rhport;
-
- USBFUNADR = dev_addr;
-
- // Response with status after changing device address
- dcd_edpt_xfer(rhport, tu_edpt_addr(0, TUSB_DIR_IN), NULL, 0);
-}
-
-void dcd_remote_wakeup(uint8_t rhport)
-{
- (void) rhport;
-}
-
-void dcd_connect(uint8_t rhport)
-{
- dcd_int_disable(rhport);
-
- USBKEYPID = USBKEY;
- USBCNF |= PUR_EN; // Enable pullup.
- USBKEYPID = 0;
-
- dcd_int_enable(rhport);
-}
-
-void dcd_disconnect(uint8_t rhport)
-{
- dcd_int_disable(rhport);
-
- USBKEYPID = USBKEY;
- USBCNF &= ~PUR_EN; // Disable pullup.
- USBKEYPID = 0;
-
- dcd_int_enable(rhport);
-}
-
-/*------------------------------------------------------------------*/
-/* DCD Endpoint port
- *------------------------------------------------------------------*/
-
-bool dcd_edpt_open (uint8_t rhport, tusb_desc_endpoint_t const * desc_edpt)
-{
- (void) rhport;
-
- uint8_t const epnum = tu_edpt_number(desc_edpt->bEndpointAddress);
- uint8_t const dir = tu_edpt_dir(desc_edpt->bEndpointAddress);
-
- // Unsupported endpoint numbers or type (Iso not supported. Control
- // not supported on nonzero endpoints).
- if( (epnum > 7) || \
- (desc_edpt->bmAttributes.xfer == 0) || \
- (desc_edpt->bmAttributes.xfer == 1)) {
- return false;
- }
-
- xfer_ctl_t * xfer = XFER_CTL_BASE(epnum, dir);
- xfer->max_size = desc_edpt->wMaxPacketSize.size;
-
- // Buffer allocation scheme:
- // For simplicity, only single buffer for now, since tinyusb currently waits
- // for an xfer to complete before scheduling another one. This means only
- // the X buffer is used.
- //
- // 1904 bytes are available, the max endpoint size supported on msp430 is
- // 64 bytes. This is enough RAM for all 14 endpoints enabled _with_ double
- // bufferring (64*14*2 = 1792 bytes). Extra RAM exists for triple and higher
- // order bufferring, which must be maintained in software.
- //
- // For simplicity, each endpoint gets a hardcoded 64 byte chunk (regardless
- // of actual wMaxPacketSize) whose start address is the following:
- // addr = 128 * (epnum - 1) + 64 * dir.
- //
- // Double buffering equation:
- // x_addr = 256 * (epnum - 1) + 128 * dir
- // y_addr = x_addr + 64
- // Address is right-shifted by 3 to fit into 8 bits.
-
- uint8_t buf_base = (128 * (epnum - 1) + 64 * dir) >> 3;
-
- // IN and OUT EP registers have the same structure.
- ep_regs_t ep_regs = EP_REGS(epnum, dir);
-
- // FIXME: I was able to get into a situation where OUT EP 3 would stall
- // while debugging, despite stall code never being called. It appears
- // these registers don't get cleared on reset, being part of RAM.
- // Investigate and see if I can duplicate.
- // Also, DBUF got set on OUT EP 2 while debugging. Only OUT EPs seem to be
- // affected at this time. USB RAM directly precedes main RAM; perhaps I'm
- // overwriting registers via buffer overflow w/ my debugging code?
- ep_regs[SIZXY] = desc_edpt->wMaxPacketSize.size;
- ep_regs[BCTX] |= NAK;
- ep_regs[BBAX] = buf_base;
- ep_regs[CNF] &= ~(TOGGLE | STALL | DBUF); // ISO xfers not supported on
- // MSP430, so no need to gate DATA0/1 and frame
- // behavior. Clear stall and double buffer bit as
- // well- see above comment.
- ep_regs[CNF] |= (UBME | USBIIE);
-
- USBKEYPID = USBKEY;
- if(dir == TUSB_DIR_OUT)
- {
- USBOEPIE |= (1 << epnum);
- }
- else
- {
- USBIEPIE |= (1 << epnum);
- }
- USBKEYPID = 0;
-
- return true;
-}
-
-bool dcd_edpt_xfer (uint8_t rhport, uint8_t ep_addr, uint8_t * buffer, uint16_t total_bytes)
-{
- (void) rhport;
-
- uint8_t const epnum = tu_edpt_number(ep_addr);
- uint8_t const dir = tu_edpt_dir(ep_addr);
-
- xfer_ctl_t * xfer = XFER_CTL_BASE(epnum, dir);
- xfer->buffer = buffer;
- // xfer->ff = NULL; // TODO support dcd_edpt_xfer_fifo API
- xfer->total_len = total_bytes;
- xfer->queued_len = 0;
- xfer->short_packet = false;
-
- if(epnum == 0)
- {
- if(dir == TUSB_DIR_OUT)
- {
- // Interrupt will notify us when data was received.
- USBCTL &= ~DIR;
- USBOEPCNT_0 &= ~NAK;
- }
- else
- {
- // Kickstart the IN packet handler by queuing initial data and calling
- // the ISR to transmit the first packet.
- // Interrupt only fires on completed xfer.
- USBCTL |= DIR;
- USBIEPIFG |= BIT0;
- }
- }
- else
- {
- ep_regs_t ep_regs = EP_REGS(epnum, dir);
-
- if(dir == TUSB_DIR_OUT)
- {
- ep_regs[BCTX] &= ~NAK;
- }
- else
- {
- USBIEPIFG |= (1 << epnum);
- }
- }
-
- return true;
-}
-
-#if 0 // TODO support dcd_edpt_xfer_fifo API
-bool dcd_edpt_xfer_fifo (uint8_t rhport, uint8_t ep_addr, tu_fifo_t * ff, uint16_t total_bytes)
-{
- (void) rhport;
-
- uint8_t const epnum = tu_edpt_number(ep_addr);
- uint8_t const dir = tu_edpt_dir(ep_addr);
-
- xfer_ctl_t * xfer = XFER_CTL_BASE(epnum, dir);
- xfer->buffer = NULL;
- xfer->ff = ff;
- xfer->total_len = total_bytes;
- xfer->queued_len = 0;
- xfer->short_packet = false;
-
- ep_regs_t ep_regs = EP_REGS(epnum, dir);
-
- if(dir == TUSB_DIR_OUT)
- {
- ep_regs[BCTX] &= ~NAK;
- }
- else
- {
- USBIEPIFG |= (1 << epnum);
- }
-
- return true;
-}
-#endif
-
-void dcd_edpt_stall (uint8_t rhport, uint8_t ep_addr)
-{
- (void) rhport;
-
- uint8_t const epnum = tu_edpt_number(ep_addr);
- uint8_t const dir = tu_edpt_dir(ep_addr);
-
- if(epnum == 0)
- {
- if(dir == TUSB_DIR_OUT)
- {
- USBOEPCNT_0 |= NAK;
- USBOEPCNF_0 |= STALL;
- }
- else
- {
- USBIEPCNT_0 |= NAK;
- USBIEPCNF_0 |= STALL;
- }
- }
- else
- {
- ep_regs_t ep_regs = EP_REGS(epnum, dir);
- ep_regs[CNF] |= STALL;
- }
-}
-
-void dcd_edpt_clear_stall (uint8_t rhport, uint8_t ep_addr)
-{
- (void) rhport;
-
- uint8_t const epnum = tu_edpt_number(ep_addr);
- uint8_t const dir = tu_edpt_dir(ep_addr);
-
- if(epnum == 0)
- {
- if(dir == TUSB_DIR_OUT)
- {
- USBOEPCNF_0 &= ~STALL;
- }
- else
- {
- USBIEPCNF_0 &= ~STALL;
- }
- }
- else
- {
- ep_regs_t ep_regs = EP_REGS(epnum, dir);
- // Required by USB spec to reset DATA toggle bit to DATA0 on interrupt
- // and bulk endpoints.
- ep_regs[CNF] &= ~(STALL + TOGGLE);
- }
-}
-
-void dcd_edpt0_status_complete(uint8_t rhport, tusb_control_request_t const * request)
-{
- (void) rhport;
- (void) request;
-
- // FIXME: Per manual, we should be clearing the NAK bits of EP0 after the
- // Status Phase of a control xfer is done, in preparation of another possible
- // SETUP packet. However, from my own testing, SETUP packets _are_ correctly
- // handled by the USB core without clearing the NAKs.
- //
- // Right now, clearing NAKs in this callbacks causes a direction mismatch
- // between host and device on EP0. Figure out why and come back to this.
- // USBOEPCNT_0 &= ~NAK;
- // USBIEPCNT_0 &= ~NAK;
-}
-
-/*------------------------------------------------------------------*/
-
-static void receive_packet(uint8_t ep_num)
-{
- xfer_ctl_t * xfer = XFER_CTL_BASE(ep_num, TUSB_DIR_OUT);
- ep_regs_t ep_regs = EP_REGS(ep_num, TUSB_DIR_OUT);
- uint8_t xfer_size;
-
- if(ep_num == 0)
- {
- xfer_size = USBOEPCNT_0 & 0x0F;
- }
- else
- {
- xfer_size = ep_regs[BCTX] & 0x7F;
- }
-
- uint16_t remaining = xfer->total_len - xfer->queued_len;
- uint16_t to_recv_size;
-
- if(remaining <= xfer->max_size) {
- // Avoid buffer overflow.
- to_recv_size = (xfer_size > remaining) ? remaining : xfer_size;
- } else {
- // Room for full packet, choose recv_size based on what the microcontroller
- // claims.
- to_recv_size = (xfer_size > xfer->max_size) ? xfer->max_size : xfer_size;
- }
-
-#if 0 // TODO support dcd_edpt_xfer_fifo API
- if (xfer->ff)
- {
- volatile uint8_t * ep_buf = (ep_num == 0) ? &USBOEP0BUF : (&USBSTABUFF + (ep_regs[BBAX] << 3));
- tu_fifo_write_n(xfer->ff, (const void *) ep_buf, to_recv_size);
- }
- else
-#endif
- {
- uint8_t * base = (xfer->buffer + xfer->queued_len);
-
- if(ep_num == 0)
- {
- volatile uint8_t * ep0out_buf = &USBOEP0BUF;
- for(uint16_t i = 0; i < to_recv_size; i++)
- {
- base[i] = ep0out_buf[i];
- }
- }
- else
- {
- volatile uint8_t * ep_buf = &USBSTABUFF + (ep_regs[BBAX] << 3);
- for(uint16_t i = 0; i < to_recv_size ; i++)
- {
- base[i] = ep_buf[i];
- }
- }
- }
-
- xfer->queued_len += xfer_size;
-
- xfer->short_packet = (xfer_size < xfer->max_size);
- if((xfer->total_len == xfer->queued_len) || xfer->short_packet)
- {
- dcd_event_xfer_complete(0, ep_num, xfer->queued_len, XFER_RESULT_SUCCESS, true);
- }
- else
- {
- // Schedule to receive another packet.
- if(ep_num == 0)
- {
- USBOEPCNT_0 &= ~NAK;
- }
- else
- {
- ep_regs[BCTX] &= ~NAK;
- }
- }
-}
-
-static void transmit_packet(uint8_t ep_num)
-{
- xfer_ctl_t * xfer = XFER_CTL_BASE(ep_num, TUSB_DIR_IN);
-
- // First, determine whether we should even send a packet or finish
- // up the xfer.
- bool zlp = (xfer->total_len == 0); // By necessity, xfer->total_len will
- // equal xfer->queued_len for ZLPs.
- // Of course a ZLP is a short packet.
- if((!zlp && (xfer->total_len == xfer->queued_len)) || xfer->short_packet)
- {
- dcd_event_xfer_complete(0, ep_num | TUSB_DIR_IN_MASK, xfer->queued_len, XFER_RESULT_SUCCESS, true);
- return;
- }
-
- // Then actually commit to transmit a packet.
- uint16_t remaining = xfer->total_len - xfer->queued_len;
- uint8_t xfer_size = (xfer->max_size < xfer->total_len) ? xfer->max_size : remaining;
-
- xfer->queued_len += xfer_size;
- if(xfer_size < xfer->max_size)
- {
- // Next "xfer complete interrupt", the transfer will end.
- xfer->short_packet = true;
- }
-
- if(ep_num == 0)
- {
- volatile uint8_t * ep0in_buf = &USBIEP0BUF;
- uint8_t * base = (xfer->buffer + xfer->queued_len);
- for(uint16_t i = 0; i < xfer_size; i++)
- {
- ep0in_buf[i] = base[i];
- }
-
- USBIEPCNT_0 = (USBIEPCNT_0 & 0xF0) + xfer_size;
- USBIEPCNT_0 &= ~NAK;
- }
- else
- {
- ep_regs_t ep_regs = EP_REGS(ep_num, TUSB_DIR_IN);
- volatile uint8_t * ep_buf = &USBSTABUFF + (ep_regs[BBAX] << 3);
-
-#if 0 // TODO support dcd_edpt_xfer_fifo API
- if (xfer->ff)
- {
- tu_fifo_read_n(xfer->ff, (void *) ep_buf, xfer_size);
- }
- else
-#endif
- {
- uint8_t * base = (xfer->buffer + xfer->queued_len);
- for(int i = 0; i < xfer_size; i++)
- {
- ep_buf[i] = base[i];
- }
- }
-
- ep_regs[BCTX] = (ep_regs[BCTX] & 0x80) + (xfer_size & 0x7F);
- ep_regs[BCTX] &= ~NAK;
- }
-}
-
-static void handle_setup_packet(void)
-{
- volatile uint8_t * setup_buf = &USBSUBLK;
-
- for(int i = 0; i < 8; i++)
- {
- _setup_packet[i] = setup_buf[i];
- }
-
- // Clearing SETUPIFG by reading USBVECINT does not set NAK, so now that we
- // have a SETUP packet, force NAKs until tinyusb can handle the SETUP
- // packet and prepare for a new xfer.
- USBIEPCNT_0 |= NAK;
- USBOEPCNT_0 |= NAK;
- dcd_event_setup_received(0, (uint8_t*) &_setup_packet[0], true);
-}
-
-void dcd_int_handler(uint8_t rhport)
-{
- (void) rhport;
-
- // Setup is special- reading USBVECINT to handle setup packets is done to
- // stop hardware-generated NAKs on EP0.
- uint8_t setup_status = USBIFG & SETUPIFG;
-
- if(setup_status)
- {
- handle_setup_packet();
- }
-
- uint16_t curr_vector = USBVECINT;
-
- switch(curr_vector)
- {
- case USBVECINT_RSTR:
- bus_reset();
- dcd_event_bus_reset(0, TUSB_SPEED_FULL, true);
- break;
-
- // Clear the (hardware-enforced) NAK on EP 0 after a SETUP packet
- // is received. At this point, even though the hardware is no longer
- // forcing NAKs, the EP0 NAK bits should still be set to avoid
- // sending/receiving data before tinyusb is ready.
- //
- // Furthermore, it's possible for the hardware to STALL in the middle of
- // a control xfer if the EP0 NAK bits aren't set properly.
- // See: https://e2e.ti.com/support/microcontrollers/msp430/f/166/t/845259
- // From my testing, if all of the following hold:
- // * OUT EP0 NAK is cleared.
- // * IN EP0 NAK is set.
- // * DIR bit in USBCTL is clear.
- // and an IN packet is received on EP0, the USB core will STALL. Setting
- // both EP0 NAKs manually when a SETUP packet is received, as is done
- // in handle_setup_packet(), avoids meeting STALL conditions.
- //
- // TODO: Figure out/explain why the STALL condition can be reached in the
- // first place. When I first noticed the STALL, the only two places I
- // touched the NAK bits were in dcd_edpt_xfer() and to _set_ (sic) them in
- // bus_reset(). SETUP packet handling should've been unaffected.
- case USBVECINT_SETUP_PACKET_RECEIVED:
- break;
-
- case USBVECINT_INPUT_ENDPOINT0:
- transmit_packet(0);
- break;
-
- case USBVECINT_OUTPUT_ENDPOINT0:
- receive_packet(0);
- break;
-
- case USBVECINT_INPUT_ENDPOINT1:
- case USBVECINT_INPUT_ENDPOINT2:
- case USBVECINT_INPUT_ENDPOINT3:
- case USBVECINT_INPUT_ENDPOINT4:
- case USBVECINT_INPUT_ENDPOINT5:
- case USBVECINT_INPUT_ENDPOINT6:
- case USBVECINT_INPUT_ENDPOINT7:
- {
- uint8_t ep = ((curr_vector - USBVECINT_INPUT_ENDPOINT1) >> 1) + 1;
- transmit_packet(ep);
- }
- break;
-
- case USBVECINT_OUTPUT_ENDPOINT1:
- case USBVECINT_OUTPUT_ENDPOINT2:
- case USBVECINT_OUTPUT_ENDPOINT3:
- case USBVECINT_OUTPUT_ENDPOINT4:
- case USBVECINT_OUTPUT_ENDPOINT5:
- case USBVECINT_OUTPUT_ENDPOINT6:
- case USBVECINT_OUTPUT_ENDPOINT7:
- {
- uint8_t ep = ((curr_vector - USBVECINT_OUTPUT_ENDPOINT1) >> 1) + 1;
- receive_packet(ep);
- }
- break;
-
- default:
- while(true);
- break;
- }
-
-}
-
-#endif
diff --git a/tinyusb/src/portable/valentyusb/eptri/dcd_eptri.c b/tinyusb/src/portable/valentyusb/eptri/dcd_eptri.c
deleted file mode 100755
index b68f04fa..00000000
--- a/tinyusb/src/portable/valentyusb/eptri/dcd_eptri.c
+++ /dev/null
@@ -1,643 +0,0 @@
-/*
- * The MIT License (MIT)
- *
- * Copyright (c) 2019 Ha Thach (tinyusb.org)
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- *
- * This file is part of the TinyUSB stack.
- */
-
-#ifndef DEBUG
-#define DEBUG 0
-#endif
-
-#ifndef LOG_USB
-#define LOG_USB 0
-#endif
-
-#include "tusb_option.h"
-
-#if TUSB_OPT_DEVICE_ENABLED && (CFG_TUSB_MCU == OPT_MCU_VALENTYUSB_EPTRI)
-
-#include "device/dcd.h"
-#include "dcd_eptri.h"
-#include "csr.h"
-#include "irq.h"
-void fomu_error(uint32_t line);
-
-#if LOG_USB
-struct usb_log {
- uint8_t ep_num;
- uint8_t size;
- uint8_t data[66];
-};
-__attribute__((used))
-struct usb_log usb_log[128];
-__attribute__((used))
-uint8_t usb_log_offset;
-
-struct xfer_log {
- uint8_t ep_num;
- uint16_t size;
-};
-__attribute__((used))
-struct xfer_log xfer_log[64];
-__attribute__((used))
-uint8_t xfer_log_offset;
-
-__attribute__((used))
-struct xfer_log queue_log[64];
-__attribute__((used))
-uint8_t queue_log_offset;
-#endif
-
-//--------------------------------------------------------------------+
-// SIE Command
-//--------------------------------------------------------------------+
-
-#define EP_SIZE 64
-
-uint16_t volatile rx_buffer_offset[16];
-uint8_t* volatile rx_buffer[16];
-uint16_t volatile rx_buffer_max[16];
-
-volatile uint8_t tx_ep;
-volatile bool tx_active;
-volatile uint16_t tx_buffer_offset[16];
-uint8_t* volatile tx_buffer[16];
-volatile uint16_t tx_buffer_max[16];
-volatile uint8_t reset_count;
-
-#if DEBUG
-__attribute__((used)) uint8_t volatile * last_tx_buffer;
-__attribute__((used)) volatile uint8_t last_tx_ep;
-uint8_t setup_packet_bfr[10];
-#endif
-
-//--------------------------------------------------------------------+
-// PIPE HELPER
-//--------------------------------------------------------------------+
-
-static bool advance_tx_ep(void) {
- // Move on to the next transmit buffer in a round-robin manner
- uint8_t prev_tx_ep = tx_ep;
- for (tx_ep = (tx_ep + 1) & 0xf; tx_ep != prev_tx_ep; tx_ep = ((tx_ep + 1) & 0xf)) {
- if (tx_buffer[tx_ep])
- return true;
- }
- if (!tx_buffer[tx_ep])
- return false;
- return true;
-}
-
-#if LOG_USB
-void xfer_log_append(uint8_t ep_num, uint16_t sz) {
- xfer_log[xfer_log_offset].ep_num = ep_num;
- xfer_log[xfer_log_offset].size = sz;
- xfer_log_offset++;
- if (xfer_log_offset >= sizeof(xfer_log)/sizeof(*xfer_log))
- xfer_log_offset = 0;
-}
-
-void queue_log_append(uint8_t ep_num, uint16_t sz) {
- queue_log[queue_log_offset].ep_num = ep_num;
- queue_log[queue_log_offset].size = sz;
- queue_log_offset++;
- if (queue_log_offset >= sizeof(queue_log)/sizeof(*queue_log))
- queue_log_offset = 0;
-}
-#endif
-
-static void tx_more_data(void) {
- // Send more data
- uint8_t added_bytes;
- for (added_bytes = 0; (added_bytes < EP_SIZE) && (tx_buffer_offset[tx_ep] < tx_buffer_max[tx_ep]); added_bytes++) {
-#if LOG_USB
- usb_log[usb_log_offset].data[added_bytes] = tx_buffer[tx_ep][tx_buffer_offset[tx_ep]];
-#endif
- usb_in_data_write(tx_buffer[tx_ep][tx_buffer_offset[tx_ep]++]);
- }
-
-#if LOG_USB
- usb_log[usb_log_offset].ep_num = tu_edpt_addr(tx_ep, TUSB_DIR_IN);
- usb_log[usb_log_offset].size = added_bytes;
- usb_log_offset++;
- if (usb_log_offset >= sizeof(usb_log)/sizeof(*usb_log))
- usb_log_offset = 0;
-#endif
-
- // Updating the epno queues the data
- usb_in_ctrl_write(tx_ep & 0xf);
-}
-
-static void process_tx(void) {
-#if DEBUG
- // If the system isn't idle, then something is very wrong.
- uint8_t in_status = usb_in_status_read();
- if (!(in_status & (1 << CSR_USB_IN_STATUS_IDLE_OFFSET)))
- fomu_error(__LINE__);
-#endif
-
- // If the buffer is now empty, search for the next buffer to fill.
- if (!tx_buffer[tx_ep]) {
- if (advance_tx_ep())
- tx_more_data();
- else
- tx_active = false;
- return;
- }
-
- if (tx_buffer_offset[tx_ep] >= tx_buffer_max[tx_ep]) {
-#if DEBUG
- last_tx_buffer = tx_buffer[tx_ep];
- last_tx_ep = tx_ep;
-#endif
- tx_buffer[tx_ep] = NULL;
- uint16_t xferred_bytes = tx_buffer_max[tx_ep];
- uint8_t xferred_ep = tx_ep;
-
- if (!advance_tx_ep())
- tx_active = false;
-#if LOG_USB
- xfer_log_append(tu_edpt_addr(xferred_ep, TUSB_DIR_IN), xferred_bytes);
-#endif
- dcd_event_xfer_complete(0, tu_edpt_addr(xferred_ep, TUSB_DIR_IN), xferred_bytes, XFER_RESULT_SUCCESS, true);
- if (!tx_active)
- return;
- }
-
- tx_more_data();
- return;
-}
-
-static void process_rx(void) {
- uint8_t out_status = usb_out_status_read();
-#if DEBUG
- // If the OUT handler is still waiting to send, don't do anything.
- if (!(out_status & (1 << CSR_USB_OUT_STATUS_HAVE_OFFSET)))
- fomu_error(__LINE__);
- // return;
-#endif
- uint8_t rx_ep = (out_status >> CSR_USB_OUT_STATUS_EPNO_OFFSET) & 0xf;
-
- // If the destination buffer doesn't exist, don't drain the hardware
- // fifo. Note that this can cause deadlocks if the host is waiting
- // on some other endpoint's data!
-#if DEBUG
- if (rx_buffer[rx_ep] == NULL) {
- fomu_error(__LINE__);
- return;
- }
-#endif
-
- // Drain the FIFO into the destination buffer
- uint32_t total_read = 0;
- uint32_t current_offset = rx_buffer_offset[rx_ep];
-#if DEBUG
- uint8_t test_buffer[256];
- memset(test_buffer, 0, sizeof(test_buffer));
- if (current_offset > rx_buffer_max[rx_ep])
- fomu_error(__LINE__);
-#endif
-#if LOG_USB
- usb_log[usb_log_offset].ep_num = tu_edpt_addr(rx_ep, TUSB_DIR_OUT);
- usb_log[usb_log_offset].size = 0;
-#endif
- while (usb_out_status_read() & (1 << CSR_USB_OUT_STATUS_HAVE_OFFSET)) {
- uint8_t c = usb_out_data_read();
-#if DEBUG
- test_buffer[total_read] = c;
-#endif
- total_read++;
- if (current_offset < rx_buffer_max[rx_ep]) {
-#if LOG_USB
- usb_log[usb_log_offset].data[usb_log[usb_log_offset].size++] = c;
-#endif
- if (rx_buffer[rx_ep] != (volatile uint8_t *)0xffffffff)
- rx_buffer[rx_ep][current_offset++] = c;
- }
- }
-#if LOG_USB
- usb_log_offset++;
- if (usb_log_offset >= sizeof(usb_log)/sizeof(*usb_log))
- usb_log_offset = 0;
-#endif
-#if DEBUG
- if (total_read > 66)
- fomu_error(__LINE__);
- if (total_read < 2)
- total_read = 2;
- // fomu_error(__LINE__);
-#endif
-
- // Strip off the CRC16
- rx_buffer_offset[rx_ep] += (total_read - 2);
- if (rx_buffer_offset[rx_ep] > rx_buffer_max[rx_ep])
- rx_buffer_offset[rx_ep] = rx_buffer_max[rx_ep];
-
- // If there's no more data, complete the transfer to tinyusb
- if ((rx_buffer_max[rx_ep] == rx_buffer_offset[rx_ep])
- // ZLP with less than the total amount of data
- || ((total_read == 2) && ((rx_buffer_offset[rx_ep] & 63) == 0))
- // Short read, but not a full packet
- || (((rx_buffer_offset[rx_ep] & 63) != 0) && (total_read < 66))) {
-#if DEBUG
- if (rx_buffer[rx_ep] == NULL)
- fomu_error(__LINE__);
-#endif
-
- // Free up this buffer.
- rx_buffer[rx_ep] = NULL;
- uint16_t len = rx_buffer_offset[rx_ep];
-
-#if DEBUG
- // Validate that all enabled endpoints have buffers,
- // and no disabled endpoints have buffers.
- uint16_t ep_en_mask = usb_out_enable_status_read();
- int i;
- for (i = 0; i < 16; i++) {
- if ((!!(ep_en_mask & (1 << i))) ^ (!!(rx_buffer[i]))) {
- uint8_t new_status = usb_out_status_read();
- // Another IRQ came in while we were processing, so ignore this endpoint.
- if ((new_status & 0x20) && ((new_status & 0xf) == i))
- continue;
- fomu_error(__LINE__);
- }
- }
-#endif
-#if LOG_USB
- xfer_log_append(tu_edpt_addr(rx_ep, TUSB_DIR_OUT), len);
-#endif
- dcd_event_xfer_complete(0, tu_edpt_addr(rx_ep, TUSB_DIR_OUT), len, XFER_RESULT_SUCCESS, true);
- }
- else {
- // If there's more data, re-enable data reception on this endpoint
- usb_out_ctrl_write((1 << CSR_USB_OUT_CTRL_ENABLE_OFFSET) | rx_ep);
- }
-
- // Now that the buffer is drained, clear the pending IRQ.
- usb_out_ev_pending_write(usb_out_ev_pending_read());
-}
-
-//--------------------------------------------------------------------+
-// CONTROLLER API
-//--------------------------------------------------------------------+
-
-static void dcd_reset(void)
-{
- reset_count++;
- usb_setup_ev_enable_write(0);
- usb_in_ev_enable_write(0);
- usb_out_ev_enable_write(0);
-
- usb_address_write(0);
-
- // Reset all three FIFO handlers
- usb_setup_ctrl_write(1 << CSR_USB_SETUP_CTRL_RESET_OFFSET);
- usb_in_ctrl_write(1 << CSR_USB_IN_CTRL_RESET_OFFSET);
- usb_out_ctrl_write(1 << CSR_USB_OUT_CTRL_RESET_OFFSET);
-
- memset((void *)rx_buffer, 0, sizeof(rx_buffer));
- memset((void *)rx_buffer_max, 0, sizeof(rx_buffer_max));
- memset((void *)rx_buffer_offset, 0, sizeof(rx_buffer_offset));
-
- memset((void *)tx_buffer, 0, sizeof(tx_buffer));
- memset((void *)tx_buffer_max, 0, sizeof(tx_buffer_max));
- memset((void *)tx_buffer_offset, 0, sizeof(tx_buffer_offset));
- tx_ep = 0;
- tx_active = false;
-
- // Enable all event handlers and clear their contents
- usb_setup_ev_pending_write(0xff);
- usb_in_ev_pending_write(0xff);
- usb_out_ev_pending_write(0xff);
- usb_in_ev_enable_write(1);
- usb_out_ev_enable_write(1);
- usb_setup_ev_enable_write(3);
-
- dcd_event_bus_reset(0, TUSB_SPEED_FULL, true);
-}
-
-// Initializes the USB peripheral for device mode and enables it.
-void dcd_init(uint8_t rhport)
-{
- (void) rhport;
-
- usb_pullup_out_write(0);
-
- // Enable all event handlers and clear their contents
- usb_setup_ev_pending_write(usb_setup_ev_pending_read());
- usb_in_ev_pending_write(usb_in_ev_pending_read());
- usb_out_ev_pending_write(usb_out_ev_pending_read());
- usb_in_ev_enable_write(1);
- usb_out_ev_enable_write(1);
- usb_setup_ev_enable_write(3);
-
- // Turn on the external pullup
- usb_pullup_out_write(1);
-}
-
-// Enables or disables the USB device interrupt(s). May be used to
-// prevent concurrency issues when mutating data structures shared
-// between main code and the interrupt handler.
-void dcd_int_enable(uint8_t rhport)
-{
- (void) rhport;
- irq_setmask(irq_getmask() | (1 << USB_INTERRUPT));
-}
-
-void dcd_int_disable(uint8_t rhport)
-{
- (void) rhport;
- irq_setmask(irq_getmask() & ~(1 << USB_INTERRUPT));
-}
-
-// Called when the device is given a new bus address.
-void dcd_set_address(uint8_t rhport, uint8_t dev_addr)
-{
- // Respond with ACK status first before changing device address
- dcd_edpt_xfer(rhport, tu_edpt_addr(0, TUSB_DIR_IN), NULL, 0);
-
- // Wait for the response packet to get sent
- while (tx_active)
- ;
-
- // Activate the new address
- usb_address_write(dev_addr);
-}
-
-// Called to remote wake up host when suspended (e.g hid keyboard)
-void dcd_remote_wakeup(uint8_t rhport)
-{
- (void) rhport;
-}
-
-void dcd_connect(uint8_t rhport)
-{
- (void) rhport;
- usb_pullup_out_write(1);
-}
-
-void dcd_disconnect(uint8_t rhport)
-{
- (void) rhport;
- usb_pullup_out_write(0);
-}
-
-
-//--------------------------------------------------------------------+
-// DCD Endpoint Port
-//--------------------------------------------------------------------+
-bool dcd_edpt_open(uint8_t rhport, tusb_desc_endpoint_t const * p_endpoint_desc)
-{
- (void) rhport;
- uint8_t ep_num = tu_edpt_number(p_endpoint_desc->bEndpointAddress);
- uint8_t ep_dir = tu_edpt_dir(p_endpoint_desc->bEndpointAddress);
-
- if (p_endpoint_desc->bmAttributes.xfer == TUSB_XFER_ISOCHRONOUS)
- return false; // Not supported
-
- if (ep_dir == TUSB_DIR_OUT) {
- rx_buffer_offset[ep_num] = 0;
- rx_buffer_max[ep_num] = 0;
- rx_buffer[ep_num] = NULL;
- }
-
- else if (ep_dir == TUSB_DIR_IN) {
- tx_buffer_offset[ep_num] = 0;
- tx_buffer_max[ep_num] = 0;
- tx_buffer[ep_num] = NULL;
- }
-
- return true;
-}
-
-void dcd_edpt_stall(uint8_t rhport, uint8_t ep_addr)
-{
- (void) rhport;
-
- if (tu_edpt_dir(ep_addr) == TUSB_DIR_OUT) {
- uint8_t enable = 0;
- if (rx_buffer[ep_addr])
- enable = 1;
- usb_out_ctrl_write((1 << CSR_USB_OUT_CTRL_STALL_OFFSET) | (enable << CSR_USB_OUT_CTRL_ENABLE_OFFSET) | tu_edpt_number(ep_addr));
- }
- else
- usb_in_ctrl_write((1 << CSR_USB_IN_CTRL_STALL_OFFSET) | tu_edpt_number(ep_addr));
-}
-
-void dcd_edpt_clear_stall(uint8_t rhport, uint8_t ep_addr)
-{
- (void) rhport;
- if (tu_edpt_dir(ep_addr) == TUSB_DIR_OUT) {
- uint8_t enable = 0;
- if (rx_buffer[ep_addr])
- enable = 1;
- usb_out_ctrl_write((0 << CSR_USB_OUT_CTRL_STALL_OFFSET) | (enable << CSR_USB_OUT_CTRL_ENABLE_OFFSET) | tu_edpt_number(ep_addr));
- }
- // IN endpoints will get unstalled when more data is written.
-}
-
-bool dcd_edpt_xfer (uint8_t rhport, uint8_t ep_addr, uint8_t* buffer, uint16_t total_bytes)
-{
- (void)rhport;
- uint8_t ep_num = tu_edpt_number(ep_addr);
- uint8_t ep_dir = tu_edpt_dir(ep_addr);
- TU_ASSERT(ep_num < 16);
-
- // Give a nonzero buffer when we transmit 0 bytes, so that the
- // system doesn't think the endpoint is idle.
- if ((buffer == NULL) && (total_bytes == 0)) {
- buffer = (uint8_t *)0xffffffff;
- }
-
- TU_ASSERT(buffer != NULL);
-
- if (ep_dir == TUSB_DIR_IN) {
- // Wait for the tx pipe to free up
- uint8_t previous_reset_count = reset_count;
- // Continue until the buffer is empty, the system is idle, and the fifo is empty.
- while (tx_buffer[ep_num] != NULL)
- ;
-
- dcd_int_disable(0);
-#if LOG_USB
- queue_log_append(ep_addr, total_bytes);
-#endif
- // If a reset happens while we're waiting, abort the transfer
- if (previous_reset_count != reset_count)
- return true;
-
- TU_ASSERT(tx_buffer[ep_num] == NULL);
- tx_buffer_offset[ep_num] = 0;
- tx_buffer_max[ep_num] = total_bytes;
- tx_buffer[ep_num] = buffer;
-
- // If the current buffer is NULL, then that means the tx logic is idle.
- // Update the tx_ep to point to our endpoint number and queue the data.
- // Otherwise, let it be and it'll get picked up after the next transfer
- // finishes.
- if (!tx_active) {
- tx_ep = ep_num;
- tx_active = true;
- tx_more_data();
- }
- dcd_int_enable(0);
- }
-
- else if (ep_dir == TUSB_DIR_OUT) {
- while (rx_buffer[ep_num] != NULL)
- ;
-
- TU_ASSERT(rx_buffer[ep_num] == NULL);
- dcd_int_disable(0);
-#if LOG_USB
- queue_log_append(ep_addr, total_bytes);
-#endif
- rx_buffer[ep_num] = buffer;
- rx_buffer_offset[ep_num] = 0;
- rx_buffer_max[ep_num] = total_bytes;
-
- // Enable receiving on this particular endpoint
- usb_out_ctrl_write((1 << CSR_USB_OUT_CTRL_ENABLE_OFFSET) | ep_num);
-#if DEBUG
- uint16_t ep_en_mask = usb_out_enable_status_read();
- int i;
- for (i = 0; i < 16; i++) {
- if ((!!(ep_en_mask & (1 << i))) ^ (!!(rx_buffer[i]))) {
- if (rx_buffer[i] && usb_out_ev_pending_read() && (usb_out_status_read() & 0xf) == i)
- continue;
- fomu_error(__LINE__);
- }
- }
-#endif
- dcd_int_enable(0);
- }
- return true;
-}
-
-//--------------------------------------------------------------------+
-// ISR
-//--------------------------------------------------------------------+
-
-static void handle_out(void)
-{
- // An "OUT" transaction just completed so we have new data.
- // (But only if we can accept the data)
-#if DEBUG
- if (!usb_out_ev_pending_read())
- fomu_error(__LINE__);
- if (!usb_out_ev_enable_read())
- fomu_error(__LINE__);
-#endif
- process_rx();
-}
-
-static void handle_in(void)
-{
-#if DEBUG
- if (!usb_in_ev_pending_read())
- fomu_error(__LINE__);
- if (!usb_in_ev_enable_read())
- fomu_error(__LINE__);
-#endif
- usb_in_ev_pending_write(usb_in_ev_pending_read());
- process_tx();
-}
-
-static void handle_reset(void)
-{
-#if DEBUG
- uint8_t setup_pending = usb_setup_ev_pending_read() & usb_setup_ev_enable_read();
- if (!(setup_pending & 2))
- fomu_error(__LINE__);
-#endif
- usb_setup_ev_pending_write(2);
-
- // This event means a bus reset occurred. Reset everything, and
- // abandon any further processing.
- dcd_reset();
-}
-
-static void handle_setup(void)
-{
-#if !DEBUG
- uint8_t setup_packet_bfr[10];
-#endif
-
-#if DEBUG
- uint8_t setup_pending = usb_setup_ev_pending_read() & usb_setup_ev_enable_read();
- if (!(setup_pending & 1))
- fomu_error(__LINE__);
-#endif
-
- // We got a SETUP packet. Copy it to the setup buffer and clear
- // the "pending" bit.
- // Setup packets are always 8 bytes, plus two bytes of crc16.
- uint32_t setup_length = 0;
-
-#if DEBUG
- if (!(usb_setup_status_read() & (1 << CSR_USB_SETUP_STATUS_HAVE_OFFSET)))
- fomu_error(__LINE__);
-#endif
-
- while (usb_setup_status_read() & (1 << CSR_USB_SETUP_STATUS_HAVE_OFFSET)) {
- uint8_t c = usb_setup_data_read();
- if (setup_length < sizeof(setup_packet_bfr))
- setup_packet_bfr[setup_length] = c;
- setup_length++;
- }
-
- // If we have 10 bytes, that's a full SETUP packet plus CRC16.
- // Otherwise, it was an RX error.
- if (setup_length == 10) {
- dcd_event_setup_received(0, setup_packet_bfr, true);
- }
-#if DEBUG
- else {
- fomu_error(__LINE__);
- }
-#endif
-
- usb_setup_ev_pending_write(1);
-}
-void dcd_int_handler(uint8_t rhport)
-{
- (void)rhport;
- uint8_t next_ev;
- while ((next_ev = usb_next_ev_read())) {
- switch (next_ev) {
- case 1 << CSR_USB_NEXT_EV_IN_OFFSET:
- handle_in();
- break;
- case 1 << CSR_USB_NEXT_EV_OUT_OFFSET:
- handle_out();
- break;
- case 1 << CSR_USB_NEXT_EV_SETUP_OFFSET:
- handle_setup();
- break;
- case 1 << CSR_USB_NEXT_EV_RESET_OFFSET:
- handle_reset();
- break;
- }
- }
-}
-
-#endif
diff --git a/tinyusb/src/portable/valentyusb/eptri/dcd_eptri.h b/tinyusb/src/portable/valentyusb/eptri/dcd_eptri.h
deleted file mode 100755
index 0fa6ecc6..00000000
--- a/tinyusb/src/portable/valentyusb/eptri/dcd_eptri.h
+++ /dev/null
@@ -1,39 +0,0 @@
-/*
- * The MIT License (MIT)
- *
- * Copyright (c) 2019 Ha Thach (tinyusb.org)
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- *
- * This file is part of the TinyUSB stack.
- */
-
-#ifndef _TUSB_DCD_VALENTYUSB_EPTRI_H_
-#define _TUSB_DCD_VALENTYUSB_EPTRI_H_
-
-#include "common/tusb_common.h"
-#ifdef __cplusplus
- extern "C" {
-#endif
-
-#ifdef __cplusplus
- }
-#endif
-
-#endif /* _TUSB_DCD_VALENTYUSB_EPTRI_H_ */