@@ -82,9 +82,8 @@ static struct
8282 // +1 for ISO endpoints
8383 xfer_td_t xfer [EP_CBI_COUNT + 1 ][2 ];
8484
85- // Number of pending DMA that is started but not handled yet by dcd_int_handler().
86- // Since nRF can only carry one DMA can run at a time, this value is normally be either 0 or 1.
87- volatile uint8_t dma_pending ;
85+ // nRF can only carry one DMA at a time, this is used to guard the access to EasyDMA
86+ volatile bool dma_running ;
8887}_dcd ;
8988
9089/*------------------------------------------------------------------*/
@@ -115,7 +114,7 @@ TU_ATTR_ALWAYS_INLINE static inline bool is_in_isr(void)
115114// helper to start DMA
116115static void start_dma (volatile uint32_t * reg_startep )
117116{
118- _dcd .dma_pending = true;
117+ _dcd .dma_running = true;
119118
120119 (* reg_startep ) = 1 ;
121120 __ISB (); __DSB ();
@@ -125,7 +124,7 @@ static void start_dma(volatile uint32_t* reg_startep)
125124 // Therefore dma_pending is corrected right away
126125 if ( (reg_startep == & NRF_USBD -> TASKS_EP0STATUS ) || (reg_startep == & NRF_USBD -> TASKS_EP0RCVOUT ) )
127126 {
128- _dcd .dma_pending = false;
127+ _dcd .dma_running = false;
129128 }
130129}
131130
@@ -137,7 +136,7 @@ static void edpt_dma_start(volatile uint32_t* reg_startep)
137136 // Called in critical section i.e within USB ISR, or USB/Global interrupt disabled
138137 if ( is_in_isr () || __get_PRIMASK () || !NVIC_GetEnableIRQ (USBD_IRQn ) )
139138 {
140- if (_dcd .dma_pending )
139+ if (_dcd .dma_running )
141140 {
142141 //use usbd task to defer later
143142 usbd_defer_func ((osal_task_func_t ) edpt_dma_start , (void * ) (uintptr_t ) reg_startep , true);
@@ -157,7 +156,7 @@ static void edpt_dma_start(volatile uint32_t* reg_startep)
157156 // use osal mutex to guard against multiple core MCUs such as nRF53
158157 dcd_int_disable (rhport );
159158
160- if ( !_dcd .dma_pending )
159+ if ( !_dcd .dma_running )
161160 {
162161 start_dma (reg_startep );
163162 started = true;
@@ -173,8 +172,8 @@ static void edpt_dma_start(volatile uint32_t* reg_startep)
173172// DMA is complete
174173static void edpt_dma_end (void )
175174{
176- TU_ASSERT (_dcd .dma_pending , );
177- _dcd .dma_pending = false;
175+ TU_ASSERT (_dcd .dma_running , );
176+ _dcd .dma_running = false;
178177}
179178
180179// helper getting td
@@ -217,9 +216,6 @@ static void xact_out_dma(uint8_t epnum)
217216
218217 edpt_dma_start (& NRF_USBD -> TASKS_STARTEPOUT [epnum ]);
219218 }
220-
221- // xfer->buffer += xact_len;
222- // xfer->actual_len += xact_len;
223219}
224220
225221// Prepare for a CBI transaction IN, call at the start
@@ -234,8 +230,6 @@ static void xact_in_dma(uint8_t epnum)
234230 NRF_USBD -> EPIN [epnum ].PTR = (uint32_t ) xfer -> buffer ;
235231 NRF_USBD -> EPIN [epnum ].MAXCNT = xact_len ;
236232
237- //xfer->buffer += xact_len;
238-
239233 edpt_dma_start (& NRF_USBD -> TASKS_STARTEPIN [epnum ]);
240234}
241235
@@ -813,7 +807,7 @@ void dcd_int_handler(uint8_t rhport)
813807 if ( tu_bit_test (data_status , epnum ) || (epnum == 0 && is_control_in ) )
814808 {
815809 xfer_td_t * xfer = get_td (epnum , TUSB_DIR_IN );
816- uint8_t const xact_len = NRF_USBD -> EPIN [epnum ].AMOUNT ; // MAXCNT
810+ uint8_t const xact_len = NRF_USBD -> EPIN [epnum ].AMOUNT ;
817811
818812 xfer -> buffer += xact_len ;
819813 xfer -> actual_len += xact_len ;
@@ -843,7 +837,6 @@ void dcd_int_handler(uint8_t rhport)
843837 }else
844838 {
845839 // Data overflow !!! Nah, nRF will auto accept next Bulk/Interrupt OUT packet
846- // If USBD is already queued this
847840 // Mark this endpoint with data received
848841 xfer -> data_received = true;
849842 }
0 commit comments