45
45
46
46
#include "soc/gdma_periph.h"
47
47
#include "hal/gdma_hal.h"
48
+ #include "hal/gdma_hal_ahb.h"
48
49
#include "hal/gdma_types.h"
49
50
#include "hal/gdma_ll.h"
50
51
#include "periph_ctrl.h"
58
59
59
60
#define ESPRESSIF_DMA_CHAN_MAX (SOC_GDMA_PAIRS_PER_GROUP_MAX)
60
61
62
+ #if !SOC_RCC_IS_INDEPENDENT
63
+ #define GDMA_RCC_ATOMIC () PERIPH_RCC_ATOMIC()
64
+ #else
65
+ #define GDMA_RCC_ATOMIC ()
66
+ #endif
67
+
61
68
/****************************************************************************
62
69
* Private Data
63
70
****************************************************************************/
64
71
65
72
static bool g_dma_chan_used [ESPRESSIF_DMA_CHAN_MAX ];
66
73
static mutex_t g_dma_lock = NXMUTEX_INITIALIZER ;
67
74
static gdma_hal_context_t ctx ;
75
+ static gdma_hal_config_t cfg =
76
+ {
77
+ .group_id = 0
78
+ };
68
79
69
80
/****************************************************************************
70
81
* Public Functions
@@ -123,26 +134,27 @@ int32_t esp_dma_request(enum esp_dma_periph_e periph,
123
134
124
135
dmainfo ("Allocated channel=%d\n" , chan );
125
136
126
- gdma_ll_rx_connect_to_periph (ctx .dev , chan , periph , periph );
127
- gdma_ll_tx_connect_to_periph (ctx .dev , chan , periph , periph );
137
+ gdma_hal_connect_peri (& ctx , chan , GDMA_CHANNEL_DIRECTION_TX ,
138
+ periph , periph );
139
+ gdma_hal_connect_peri (& ctx , chan , GDMA_CHANNEL_DIRECTION_RX ,
140
+ periph , periph );
128
141
129
142
if (burst_en )
130
143
{
131
144
/* Enable DMA TX/RX channels burst sending data */
132
145
133
- gdma_ll_tx_enable_data_burst (ctx .dev , chan , true);
134
- gdma_ll_rx_enable_data_burst (ctx .dev , chan , true);
135
-
136
146
/* Enable DMA TX/RX channels burst reading descriptor link */
137
147
138
- gdma_ll_tx_enable_descriptor_burst (ctx .dev , chan , true);
139
- gdma_ll_rx_enable_descriptor_burst (ctx .dev , chan , true);
148
+ gdma_hal_enable_burst (& ctx , chan , GDMA_CHANNEL_DIRECTION_TX ,
149
+ true, true);
150
+ gdma_hal_enable_burst (& ctx , chan , GDMA_CHANNEL_DIRECTION_RX ,
151
+ true, true);
140
152
}
141
153
142
154
/* Set priority for DMA TX/RX channels */
143
155
144
- gdma_ll_tx_set_priority ( ctx . dev , chan , tx_prio );
145
- gdma_ll_rx_set_priority ( ctx . dev , chan , rx_prio );
156
+ gdma_hal_set_priority ( & ctx , chan , GDMA_CHANNEL_DIRECTION_TX , tx_prio );
157
+ gdma_hal_set_priority ( & ctx , chan , GDMA_CHANNEL_DIRECTION_RX , rx_prio );
146
158
147
159
nxmutex_unlock (& g_dma_lock );
148
160
return chan ;
@@ -177,6 +189,8 @@ uint32_t esp_dma_setup(int chan, bool tx,
177
189
uint8_t * pdata = pbuf ;
178
190
uint32_t data_len ;
179
191
uint32_t buf_len ;
192
+ gdma_channel_direction_t dir = tx == true ? GDMA_CHANNEL_DIRECTION_TX : \
193
+ GDMA_CHANNEL_DIRECTION_RX ;
180
194
dma_descriptor_t * dma_desc = (dma_descriptor_t * )dmadesc ;
181
195
182
196
DEBUGASSERT (chan >= 0 );
@@ -212,22 +226,16 @@ uint32_t esp_dma_setup(int chan, bool tx,
212
226
dma_desc [i ].dw0 .suc_eof = 1 ;
213
227
dmadesc [i ].next = NULL ;
214
228
229
+ gdma_hal_reset (& ctx , chan , dir );
230
+
215
231
if (tx )
216
232
{
217
- /* Reset DMA TX channel FSM and FIFO pointer */
218
-
219
- gdma_ll_tx_reset_channel (ctx .dev , chan );
220
-
221
233
/* Set the descriptor link base address for TX channel */
222
234
223
235
gdma_ll_tx_set_desc_addr (ctx .dev , chan , (uint32_t )dmadesc );
224
236
}
225
237
else
226
238
{
227
- /* Reset DMA RX channel FSM and FIFO pointer */
228
-
229
- gdma_ll_rx_reset_channel (ctx .dev , chan );
230
-
231
239
/* Set the descriptor link base address for RX channel */
232
240
233
241
gdma_ll_rx_set_desc_addr (ctx .dev , chan , (uint32_t )dmadesc );
@@ -256,30 +264,14 @@ uint32_t esp_dma_setup(int chan, bool tx,
256
264
void esp_dma_load (struct esp_dmadesc_s * dmadesc , int chan , bool tx )
257
265
{
258
266
uint32_t regval ;
267
+ gdma_channel_direction_t dir = tx == true ? GDMA_CHANNEL_DIRECTION_TX : \
268
+ GDMA_CHANNEL_DIRECTION_RX ;
259
269
260
270
DEBUGASSERT (chan >= 0 );
261
271
DEBUGASSERT (dmadesc != NULL );
262
272
263
- if (tx )
264
- {
265
- /* Reset DMA TX channel FSM and FIFO pointer */
266
-
267
- gdma_ll_rx_reset_channel (ctx .dev , chan );
268
-
269
- /* Set the descriptor link base address for TX channel */
270
-
271
- gdma_ll_tx_set_desc_addr (ctx .dev , chan , (uint32_t )dmadesc );
272
- }
273
- else
274
- {
275
- /* Reset DMA RX channel FSM and FIFO pointer */
276
-
277
- gdma_ll_rx_reset_channel (ctx .dev , chan );
278
-
279
- /* Set the descriptor link base address for RX channel */
280
-
281
- gdma_ll_rx_set_desc_addr (ctx .dev , chan , (uint32_t )dmadesc );
282
- }
273
+ gdma_hal_reset (& ctx , chan , dir );
274
+ gdma_hal_start_with_desc (& ctx , chan , dir , (uint32_t )dmadesc );
283
275
}
284
276
285
277
/****************************************************************************
@@ -301,14 +293,9 @@ void esp_dma_load(struct esp_dmadesc_s *dmadesc, int chan, bool tx)
301
293
302
294
void esp_dma_enable_interrupt (int chan , bool tx , uint32_t mask , bool en )
303
295
{
304
- if (tx )
305
- {
306
- gdma_ll_tx_enable_interrupt (ctx .dev , chan , mask , en );
307
- }
308
- else
309
- {
310
- gdma_ll_rx_enable_interrupt (ctx .dev , chan , mask , en );
311
- }
296
+ gdma_channel_direction_t dir = tx == true ? GDMA_CHANNEL_DIRECTION_TX : \
297
+ GDMA_CHANNEL_DIRECTION_RX ;
298
+ gdma_hal_enable_intr (& ctx , chan , dir , mask , en );
312
299
}
313
300
314
301
/****************************************************************************
@@ -329,17 +316,9 @@ void esp_dma_enable_interrupt(int chan, bool tx, uint32_t mask, bool en)
329
316
int esp_dma_get_interrupt (int chan , bool tx )
330
317
{
331
318
uint32_t intr_status = 0 ;
332
-
333
- if (tx )
334
- {
335
- intr_status = gdma_ll_tx_get_interrupt_status (ctx .dev , chan , false);
336
- }
337
- else
338
- {
339
- intr_status = gdma_ll_rx_get_interrupt_status (ctx .dev , chan , false);
340
- }
341
-
342
- return intr_status ;
319
+ gdma_channel_direction_t dir = tx == true ? GDMA_CHANNEL_DIRECTION_TX : \
320
+ GDMA_CHANNEL_DIRECTION_RX ;
321
+ return gdma_hal_read_intr_status (& ctx , chan , dir , false);
343
322
}
344
323
345
324
/****************************************************************************
@@ -360,14 +339,9 @@ int esp_dma_get_interrupt(int chan, bool tx)
360
339
361
340
void esp_dma_clear_interrupt (int chan , bool tx , uint32_t mask )
362
341
{
363
- if (tx )
364
- {
365
- gdma_ll_tx_clear_interrupt_status (ctx .dev , chan , mask );
366
- }
367
- else
368
- {
369
- gdma_ll_rx_clear_interrupt_status (ctx .dev , chan , mask );
370
- }
342
+ gdma_channel_direction_t dir = tx == true ? GDMA_CHANNEL_DIRECTION_TX : \
343
+ GDMA_CHANNEL_DIRECTION_RX ;
344
+ gdma_hal_clear_intr (& ctx , chan , dir , mask );
371
345
}
372
346
373
347
/****************************************************************************
@@ -387,18 +361,9 @@ void esp_dma_clear_interrupt(int chan, bool tx, uint32_t mask)
387
361
388
362
int esp_dma_get_desc_addr (int chan , bool tx )
389
363
{
390
- uint32_t desc_addr = 0 ;
391
-
392
- if (tx )
393
- {
394
- desc_addr = gdma_ll_tx_get_eof_desc_addr (ctx .dev , chan );
395
- }
396
- else
397
- {
398
- desc_addr = gdma_ll_rx_get_success_eof_desc_addr (ctx .dev , chan );
399
- }
400
-
401
- return desc_addr ;
364
+ gdma_channel_direction_t dir = tx == true ? GDMA_CHANNEL_DIRECTION_TX : \
365
+ GDMA_CHANNEL_DIRECTION_RX ;
366
+ return gdma_hal_get_eof_desc_addr (& ctx , chan , dir , true);
402
367
}
403
368
404
369
/****************************************************************************
@@ -445,14 +410,9 @@ void esp_dma_enable(int chan, bool tx)
445
410
446
411
void esp_dma_disable (int chan , bool tx )
447
412
{
448
- if (tx )
449
- {
450
- gdma_ll_tx_stop (ctx .dev , chan );
451
- }
452
- else
453
- {
454
- gdma_ll_rx_stop (ctx .dev , chan );
455
- }
413
+ gdma_channel_direction_t dir = tx == true ? GDMA_CHANNEL_DIRECTION_TX : \
414
+ GDMA_CHANNEL_DIRECTION_RX ;
415
+ gdma_hal_stop (& ctx , chan , dir );
456
416
}
457
417
458
418
/****************************************************************************
@@ -499,14 +459,9 @@ void esp_dma_wait_idle(int chan, bool tx)
499
459
500
460
void esp_dma_reset_channel (int chan , bool tx )
501
461
{
502
- if (tx )
503
- {
504
- gdma_ll_tx_reset_channel (ctx .dev , chan );
505
- }
506
- else
507
- {
508
- gdma_ll_rx_reset_channel (ctx .dev , chan );
509
- }
462
+ gdma_channel_direction_t dir = tx == true ? GDMA_CHANNEL_DIRECTION_TX : \
463
+ GDMA_CHANNEL_DIRECTION_RX ;
464
+ gdma_hal_reset (& ctx , chan , dir );
510
465
}
511
466
512
467
/****************************************************************************
@@ -526,7 +481,12 @@ void esp_dma_reset_channel(int chan, bool tx)
526
481
void esp_dma_init (void )
527
482
{
528
483
periph_module_enable (PERIPH_GDMA_MODULE );
529
- ctx .dev = GDMA_LL_GET_HW (0 );
484
+ GDMA_RCC_ATOMIC ()
485
+ {
486
+ gdma_ll_enable_bus_clock (0 , true);
487
+ }
488
+
489
+ gdma_ahb_hal_init (& ctx , & cfg );
530
490
gdma_ll_force_enable_reg_clock (ctx .dev , true);
531
491
}
532
492
@@ -551,12 +511,17 @@ void esp_dma_deinit(void)
551
511
/* Disable DMA clock gating */
552
512
553
513
gdma_ll_force_enable_reg_clock (ctx .dev , false);
514
+ GDMA_RCC_ATOMIC ()
515
+ {
516
+ gdma_ll_enable_bus_clock (0 , false);
517
+ }
554
518
555
519
/* Disable DMA module by gating the clock and asserting the reset
556
520
* signal.
557
521
*/
558
522
559
523
periph_module_disable (PERIPH_GDMA_MODULE );
524
+ gdma_hal_deinit (& ctx );
560
525
561
526
nxmutex_unlock (& g_dma_lock );
562
527
}
0 commit comments