@@ -82,9 +82,8 @@ static struct
82
82
// +1 for ISO endpoints
83
83
xfer_td_t xfer [EP_CBI_COUNT + 1 ][2 ];
84
84
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 ;
88
87
}_dcd ;
89
88
90
89
/*------------------------------------------------------------------*/
@@ -115,7 +114,7 @@ TU_ATTR_ALWAYS_INLINE static inline bool is_in_isr(void)
115
114
// helper to start DMA
116
115
static void start_dma (volatile uint32_t * reg_startep )
117
116
{
118
- _dcd .dma_pending = true;
117
+ _dcd .dma_running = true;
119
118
120
119
(* reg_startep ) = 1 ;
121
120
__ISB (); __DSB ();
@@ -125,7 +124,7 @@ static void start_dma(volatile uint32_t* reg_startep)
125
124
// Therefore dma_pending is corrected right away
126
125
if ( (reg_startep == & NRF_USBD -> TASKS_EP0STATUS ) || (reg_startep == & NRF_USBD -> TASKS_EP0RCVOUT ) )
127
126
{
128
- _dcd .dma_pending = false;
127
+ _dcd .dma_running = false;
129
128
}
130
129
}
131
130
@@ -137,7 +136,7 @@ static void edpt_dma_start(volatile uint32_t* reg_startep)
137
136
// Called in critical section i.e within USB ISR, or USB/Global interrupt disabled
138
137
if ( is_in_isr () || __get_PRIMASK () || !NVIC_GetEnableIRQ (USBD_IRQn ) )
139
138
{
140
- if (_dcd .dma_pending )
139
+ if (_dcd .dma_running )
141
140
{
142
141
//use usbd task to defer later
143
142
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)
157
156
// use osal mutex to guard against multiple core MCUs such as nRF53
158
157
dcd_int_disable (rhport );
159
158
160
- if ( !_dcd .dma_pending )
159
+ if ( !_dcd .dma_running )
161
160
{
162
161
start_dma (reg_startep );
163
162
started = true;
@@ -173,8 +172,8 @@ static void edpt_dma_start(volatile uint32_t* reg_startep)
173
172
// DMA is complete
174
173
static void edpt_dma_end (void )
175
174
{
176
- TU_ASSERT (_dcd .dma_pending , );
177
- _dcd .dma_pending = false;
175
+ TU_ASSERT (_dcd .dma_running , );
176
+ _dcd .dma_running = false;
178
177
}
179
178
180
179
// helper getting td
@@ -217,9 +216,6 @@ static void xact_out_dma(uint8_t epnum)
217
216
218
217
edpt_dma_start (& NRF_USBD -> TASKS_STARTEPOUT [epnum ]);
219
218
}
220
-
221
- // xfer->buffer += xact_len;
222
- // xfer->actual_len += xact_len;
223
219
}
224
220
225
221
// Prepare for a CBI transaction IN, call at the start
@@ -234,8 +230,6 @@ static void xact_in_dma(uint8_t epnum)
234
230
NRF_USBD -> EPIN [epnum ].PTR = (uint32_t ) xfer -> buffer ;
235
231
NRF_USBD -> EPIN [epnum ].MAXCNT = xact_len ;
236
232
237
- //xfer->buffer += xact_len;
238
-
239
233
edpt_dma_start (& NRF_USBD -> TASKS_STARTEPIN [epnum ]);
240
234
}
241
235
@@ -813,7 +807,7 @@ void dcd_int_handler(uint8_t rhport)
813
807
if ( tu_bit_test (data_status , epnum ) || (epnum == 0 && is_control_in ) )
814
808
{
815
809
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 ;
817
811
818
812
xfer -> buffer += xact_len ;
819
813
xfer -> actual_len += xact_len ;
@@ -843,7 +837,6 @@ void dcd_int_handler(uint8_t rhport)
843
837
}else
844
838
{
845
839
// Data overflow !!! Nah, nRF will auto accept next Bulk/Interrupt OUT packet
846
- // If USBD is already queued this
847
840
// Mark this endpoint with data received
848
841
xfer -> data_received = true;
849
842
}
0 commit comments