diff options
| author | hathach <[email protected]> | 2018-11-16 22:17:11 +0700 |
|---|---|---|
| committer | hathach <[email protected]> | 2018-11-16 22:17:11 +0700 |
| commit | 00694b56c58956bfd5c5cf33c8ba76defb849210 (patch) | |
| tree | b4e5068f6a22d2661decaef610c85a1ed6bebe6d /src | |
| parent | 7219ef8ed62f668a5313aba1a14fd342ce262750 (diff) | |
nrf5x: clean up dcd, add comment
Diffstat (limited to 'src')
| -rw-r--r-- | src/device/usbd.c | 2 | ||||
| -rw-r--r-- | src/portable/nordic/nrf5x/dcd_nrf5x.c | 151 |
2 files changed, 73 insertions, 80 deletions
diff --git a/src/device/usbd.c b/src/device/usbd.c index bf6aa665f..eac1a6a20 100644 --- a/src/device/usbd.c +++ b/src/device/usbd.c @@ -70,12 +70,10 @@ typedef struct { uint8_t itf2drv[16]; // map interface number to driver (0xff is invalid)
uint8_t ep2drv[2][8]; // map endpoint to driver ( 0xff is invalid )
-
}usbd_device_t;
static usbd_device_t _usbd_dev;
-
// Auto descriptor is enabled, descriptor set point to auto generated one
#if CFG_TUD_DESC_AUTO
extern tud_desc_set_t const _usbd_auto_desc_set;
diff --git a/src/portable/nordic/nrf5x/dcd_nrf5x.c b/src/portable/nordic/nrf5x/dcd_nrf5x.c index fad96acf3..816ff62ae 100644 --- a/src/portable/nordic/nrf5x/dcd_nrf5x.c +++ b/src/portable/nordic/nrf5x/dcd_nrf5x.c @@ -64,9 +64,7 @@ enum USBD_INTENCLR_ENDISOIN_Msk | USBD_INTEN_ENDISOOUT_Msk }; -/*------------------------------------------------------------------*/ -/* VARIABLE DECLARATION - *------------------------------------------------------------------*/ +// Transfer descriptor typedef struct { uint8_t* buffer; @@ -78,66 +76,23 @@ typedef struct // indicate packet is already ACK volatile bool data_received; -} nom_xfer_t; +} xfer_td_t; -/*static*/ struct +// Data for managing dcd +static struct { // All 8 endpoints including control IN & OUT (offset 1) - nom_xfer_t xfer[8][2]; + xfer_td_t xfer[8][2]; + // Only one DMA can run at a time volatile bool dma_running; }_dcd; -void bus_reset(void) -{ - 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; - - tu_varclr(&_dcd); - _dcd.xfer[0][TUSB_DIR_IN].mps = MAX_PACKET_SIZE; - _dcd.xfer[0][TUSB_DIR_OUT].mps = MAX_PACKET_SIZE; -} - /*------------------------------------------------------------------*/ -/* Controller API +/* Control / Bulk / Interrupt (CBI) Transfer *------------------------------------------------------------------*/ -bool dcd_init (uint8_t rhport) -{ - (void) rhport; - return true; -} - -void dcd_connect (uint8_t rhport) -{ - -} -void dcd_disconnect (uint8_t rhport) -{ - -} - -void dcd_set_address (uint8_t rhport, uint8_t dev_addr) -{ - (void) rhport; - // Set Address is automatically update by hw controller -} - -void dcd_set_config (uint8_t rhport, uint8_t config_num) -{ - (void) rhport; - (void) config_num; - // Nothing to do -} -/*------------------------------------------------------------------*/ -/* Control - *------------------------------------------------------------------*/ +// helper to start DMA static void edpt_dma_start(volatile uint32_t* reg_startep) { // Only one dma can be active @@ -162,28 +117,23 @@ static void edpt_dma_start(volatile uint32_t* reg_startep) __ISB(); __DSB(); } +// DMA is complete static void edpt_dma_end(void) { TU_ASSERT(_dcd.dma_running, ); - _dcd.dma_running = false; } -/*------------------------------------------------------------------*/ -/* - *------------------------------------------------------------------*/ - -static inline nom_xfer_t* get_td(uint8_t epnum, uint8_t dir) +// helper getting td +static inline xfer_td_t* get_td(uint8_t epnum, uint8_t dir) { return &_dcd.xfer[epnum][dir]; } -/*------------- Bulk/Int OUT transfer -------------*/ +/*------------- CBI OUT Transfer -------------*/ -/** - * Prepare Bulk/Int out transaction, Endpoint start to accept/ACK Data - * @param epnum - */ +// Prepare for a CBI transaction OUT, call at the start +// Allow ACK incoming data static void xact_out_prepare(uint8_t epnum) { if ( epnum == 0 ) @@ -200,9 +150,10 @@ static void xact_out_prepare(uint8_t epnum) __ISB(); __DSB(); } +// Start DMA to move data from Endpoint -> RAM static void xact_out_dma(uint8_t epnum) { - nom_xfer_t* xfer = get_td(epnum, TUSB_DIR_OUT); + xfer_td_t* xfer = get_td(epnum, TUSB_DIR_OUT); uint8_t const xact_len = NRF_USBD->SIZE.EPOUT[epnum]; @@ -216,16 +167,13 @@ static void xact_out_dma(uint8_t epnum) xfer->actual_len += xact_len; } +/*------------- CBI IN Transfer -------------*/ -/*------------- Bulk/Int IN transfer -------------*/ - -/** - * Prepare Bulk/Int in transaction, use DMA to transfer data from Memory -> Endpoint - * @param epnum - */ +// Prepare for a CBI transaction IN, call at the start +// it start DMA to transfer data from RAM -> Endpoint static void xact_in_prepare(uint8_t epnum) { - nom_xfer_t* xfer = get_td(epnum, TUSB_DIR_IN); + xfer_td_t* xfer = get_td(epnum, TUSB_DIR_IN); // Each transaction is up to Max Packet Size uint8_t const xact_len = tu_min16(xfer->total_len - xfer->actual_len, xfer->mps); @@ -238,6 +186,37 @@ static void xact_in_prepare(uint8_t epnum) edpt_dma_start(&NRF_USBD->TASKS_STARTEPIN[epnum]); } +//--------------------------------------------------------------------+ +// Tinyusb DCD API +//--------------------------------------------------------------------+ +bool dcd_init (uint8_t rhport) +{ + (void) rhport; + return true; +} + +void dcd_connect (uint8_t rhport) +{ + +} +void dcd_disconnect (uint8_t rhport) +{ + +} + +void dcd_set_address (uint8_t rhport, uint8_t dev_addr) +{ + (void) rhport; + // Set Address is automatically update by hw controller +} + +void dcd_set_config (uint8_t rhport, uint8_t config_num) +{ + (void) rhport; + (void) config_num; + // Nothing to do +} + bool dcd_edpt_open (uint8_t rhport, tusb_desc_endpoint_t const * desc_edpt) { (void) rhport; @@ -268,7 +247,7 @@ bool dcd_edpt_xfer (uint8_t rhport, uint8_t ep_addr, uint8_t * buffer, uint16_t uint8_t const epnum = edpt_number(ep_addr); uint8_t const dir = edpt_dir(ep_addr); - nom_xfer_t* xfer = get_td(epnum, dir); + xfer_td_t* xfer = get_td(epnum, dir); xfer->buffer = buffer; xfer->total_len = total_bytes; @@ -352,14 +331,30 @@ bool dcd_edpt_busy (uint8_t rhport, uint8_t ep_addr) uint8_t const epnum = edpt_number(ep_addr); uint8_t const dir = edpt_dir(ep_addr); - nom_xfer_t* xfer = get_td(epnum, dir); + xfer_td_t* xfer = get_td(epnum, dir); return xfer->actual_len < xfer->total_len; } /*------------------------------------------------------------------*/ -/* +/* Interrupt Handler *------------------------------------------------------------------*/ +void bus_reset(void) +{ + 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; + + tu_varclr(&_dcd); + _dcd.xfer[0][TUSB_DIR_IN].mps = MAX_PACKET_SIZE; + _dcd.xfer[0][TUSB_DIR_OUT].mps = MAX_PACKET_SIZE; +} + void USBD_IRQHandler(void) { uint32_t const inten = NRF_USBD->INTEN; @@ -448,7 +443,7 @@ void USBD_IRQHandler(void) { if ( BIT_TEST_(int_status, USBD_INTEN_ENDEPOUT0_Pos+epnum)) { - nom_xfer_t* xfer = get_td(epnum, TUSB_DIR_OUT); + xfer_td_t* xfer = get_td(epnum, TUSB_DIR_OUT); uint8_t const xact_len = NRF_USBD->EPOUT[epnum].AMOUNT; // Data in endpoint has been consumed @@ -488,7 +483,7 @@ void USBD_IRQHandler(void) { if ( BIT_TEST_(data_status, epnum ) || ( epnum == 0 && is_control_in) ) { - nom_xfer_t* xfer = get_td(epnum, TUSB_DIR_IN); + xfer_td_t* xfer = get_td(epnum, TUSB_DIR_IN); xfer->actual_len += NRF_USBD->EPIN[epnum].MAXCNT; @@ -509,7 +504,7 @@ void USBD_IRQHandler(void) { if ( BIT_TEST_(data_status, 16+epnum ) || ( epnum == 0 && is_control_out) ) { - nom_xfer_t* xfer = get_td(epnum, TUSB_DIR_OUT); + xfer_td_t* xfer = get_td(epnum, TUSB_DIR_OUT); if (xfer->actual_len < xfer->total_len) { |
