22
22
#define DMA_CH_PRIORITY_HIGH 1
23
23
#define DMA_CH_PRIORITY_LOW 0
24
24
#define VALID_BURST_LENGTH 0
25
- #define UDMA_ADDR_INC_NONE 0X03
25
+ #define UDMA_ADDR_INC_NONE 0x03
26
26
27
27
LOG_MODULE_REGISTER (si91x_dma , CONFIG_DMA_LOG_LEVEL );
28
28
@@ -40,18 +40,21 @@ struct dma_siwx91x_data {
40
40
UDMA_Channel_Info * chan_info ;
41
41
dma_callback_t dma_callback ; /* User callback */
42
42
void * cb_data ; /* User callback data */
43
- RSI_UDMA_DATACONTEXT_T dma_rom_buff ; /* Buffer to store UDMA handle */
44
- /* related information */
43
+ RSI_UDMA_DATACONTEXT_T dma_rom_buff ; /* Buffer to store UDMA handle
44
+ * related information
45
+ */
45
46
};
46
47
47
48
static inline int siwx91x_dma_is_peripheral_request (uint32_t dir )
48
49
{
49
50
if (dir == MEMORY_TO_MEMORY ) {
50
51
return 0 ;
51
52
}
53
+
52
54
if (dir == MEMORY_TO_PERIPHERAL || dir == PERIPHERAL_TO_MEMORY ) {
53
55
return 1 ;
54
56
}
57
+
55
58
return -1 ;
56
59
}
57
60
@@ -108,19 +111,22 @@ static int dma_channel_config(const struct device *dev, RSI_UDMA_HANDLE_T udma_h
108
111
RSI_UDMA_CHA_CFG_T channel_config = {};
109
112
int status ;
110
113
111
- channel_config .channelPrioHigh = config -> channel_priority ;
112
114
if (siwx91x_dma_is_peripheral_request (config -> channel_direction ) < 0 ) {
113
115
return - EINVAL ;
114
116
}
117
+
118
+ channel_config .channelPrioHigh = config -> channel_priority ;
115
119
channel_config .periphReq = siwx91x_dma_is_peripheral_request (config -> channel_direction );
116
120
channel_config .dmaCh = channel ;
121
+
117
122
if (channel_config .periphReq ) {
118
123
/* Arbitration power for peripheral<->memory transfers */
119
124
channel_control .rPower = ARBSIZE_1 ;
120
125
} else {
121
126
/* Arbitration power for mem-mem transfers */
122
127
channel_control .rPower = ARBSIZE_1024 ;
123
128
}
129
+
124
130
/* Obtain the number of transfers */
125
131
config -> head_block -> block_size /= config -> source_data_size ;
126
132
if (config -> head_block -> block_size >= DMA_MAX_TRANSFER_COUNT ) {
@@ -129,6 +135,7 @@ static int dma_channel_config(const struct device *dev, RSI_UDMA_HANDLE_T udma_h
129
135
} else {
130
136
channel_control .totalNumOfDMATrans = config -> head_block -> block_size ;
131
137
}
138
+
132
139
if (siwx91x_dma_data_width (config -> source_data_size ) < 0 ||
133
140
siwx91x_dma_data_width (config -> dest_data_size ) < 0 ) {
134
141
return - EINVAL ;
@@ -137,22 +144,26 @@ static int dma_channel_config(const struct device *dev, RSI_UDMA_HANDLE_T udma_h
137
144
siwx91x_dma_burst_length (config -> dest_burst_length ) < 0 ) {
138
145
return - EINVAL ;
139
146
}
147
+
140
148
channel_control .srcSize = siwx91x_dma_data_width (config -> source_data_size );
141
149
channel_control .dstSize = siwx91x_dma_data_width (config -> dest_data_size );
142
150
if (siwx91x_dma_addr_adjustment (config -> head_block -> source_addr_adj ) < 0 ||
143
151
siwx91x_dma_addr_adjustment (config -> head_block -> dest_addr_adj ) < 0 ) {
144
152
return - EINVAL ;
145
153
}
154
+
146
155
if (siwx91x_dma_addr_adjustment (config -> head_block -> source_addr_adj ) == 0 ) {
147
156
channel_control .srcInc = channel_control .srcSize ;
148
157
} else {
149
158
channel_control .srcInc = UDMA_SRC_INC_NONE ;
150
159
}
160
+
151
161
if (siwx91x_dma_addr_adjustment (config -> head_block -> dest_addr_adj ) == 0 ) {
152
162
channel_control .dstInc = channel_control .dstSize ;
153
163
} else {
154
164
channel_control .dstInc = UDMA_DST_INC_NONE ;
155
165
}
166
+
156
167
status = UDMAx_ChannelConfigure (& udma_resources , (uint8_t )channel ,
157
168
config -> head_block -> source_address ,
158
169
config -> head_block -> dest_address ,
@@ -161,6 +172,7 @@ static int dma_channel_config(const struct device *dev, RSI_UDMA_HANDLE_T udma_h
161
172
if (status ) {
162
173
return - EIO ;
163
174
}
175
+
164
176
return 0 ;
165
177
}
166
178
@@ -193,8 +205,10 @@ static int dma_siwx91x_configure(const struct device *dev, uint32_t channel,
193
205
if (status ) {
194
206
return status ;
195
207
}
208
+
196
209
data -> dma_callback = config -> dma_callback ;
197
210
data -> cb_data = config -> user_data ;
211
+
198
212
return 0 ;
199
213
}
200
214
@@ -231,19 +245,22 @@ static int dma_siwx91x_reload(const struct device *dev, uint32_t channel, uint32
231
245
} else {
232
246
data -> chan_info [channel ].Cnt = size ;
233
247
}
248
+
234
249
/* Program the DMA descriptors with new transfer data information. */
235
250
if (udma_table [channel ].vsUDMAChaConfigData1 .srcInc != UDMA_SRC_INC_NONE ) {
236
251
length = data -> chan_info [channel ].Cnt
237
252
<< udma_table [channel ].vsUDMAChaConfigData1 .srcInc ;
238
253
desc_src_addr = src + (length - 1 );
239
254
udma_table [channel ].pSrcEndAddr = (void * )desc_src_addr ;
240
255
}
256
+
241
257
if (udma_table [channel ].vsUDMAChaConfigData1 .dstInc != UDMA_SRC_INC_NONE ) {
242
258
length = data -> chan_info [channel ].Cnt
243
259
<< udma_table [channel ].vsUDMAChaConfigData1 .dstInc ;
244
260
desc_dst_addr = dst + (length - 1 );
245
261
udma_table [channel ].pDstEndAddr = (void * )desc_dst_addr ;
246
262
}
263
+
247
264
udma_table [channel ].vsUDMAChaConfigData1 .totalNumOfDMATrans = data -> chan_info [channel ].Cnt ;
248
265
udma_table [channel ].vsUDMAChaConfigData1 .transferType = UDMA_MODE_BASIC ;
249
266
@@ -262,6 +279,7 @@ static int dma_siwx91x_start(const struct device *dev, uint32_t channel)
262
279
if (channel >= cfg -> channels ) {
263
280
return - EINVAL ;
264
281
}
282
+
265
283
if (RSI_UDMA_ChannelEnable (udma_handle , channel ) != 0 ) {
266
284
return - EINVAL ;
267
285
}
@@ -272,6 +290,7 @@ static int dma_siwx91x_start(const struct device *dev, uint32_t channel)
272
290
/* Apply software trigger to start transfer */
273
291
sys_set_bit ((mem_addr_t )& cfg -> reg -> CHNL_SW_REQUEST , channel );
274
292
}
293
+
275
294
return 0 ;
276
295
}
277
296
@@ -286,9 +305,11 @@ static int dma_siwx91x_stop(const struct device *dev, uint32_t channel)
286
305
if (channel >= cfg -> channels ) {
287
306
return - EINVAL ;
288
307
}
308
+
289
309
if (RSI_UDMA_ChannelDisable (udma_handle , channel ) != 0 ) {
290
310
return - EIO ;
291
311
}
312
+
292
313
return 0 ;
293
314
}
294
315
@@ -303,6 +324,7 @@ static int dma_siwx91x_get_status(const struct device *dev, uint32_t channel,
303
324
if (channel >= cfg -> channels ) {
304
325
return - EINVAL ;
305
326
}
327
+
306
328
/* Read the channel status register */
307
329
stat -> busy = sys_test_bit ((mem_addr_t )& cfg -> reg -> CHANNEL_STATUS_REG , channel );
308
330
@@ -314,6 +336,7 @@ static int dma_siwx91x_get_status(const struct device *dev, uint32_t channel,
314
336
} else {
315
337
stat -> dir = MEMORY_TO_MEMORY ;
316
338
}
339
+
317
340
return 0 ;
318
341
}
319
342
@@ -347,6 +370,7 @@ static int dma_siwx91x_init(const struct device *dev)
347
370
if (UDMAx_DMAEnable (& udma_resources , udma_handle ) != 0 ) {
348
371
return - EBUSY ;
349
372
}
373
+
350
374
return 0 ;
351
375
}
352
376
@@ -361,16 +385,19 @@ static void dma_siwx91x_isr(const struct device *dev)
361
385
};
362
386
uint8_t channel ;
363
387
364
- /* Disable the IRQ to prevent the ISR from being triggered by */
365
- /* interrupts from other DMA channels */
388
+ /* Disable the IRQ to prevent the ISR from being triggered by
389
+ * interrupts from other DMA channels.
390
+ */
366
391
irq_disable (cfg -> irq_number );
392
+
367
393
channel = find_lsb_set (cfg -> reg -> UDMA_DONE_STATUS_REG );
368
394
/* Identify the interrupt channel */
369
395
if (!channel || channel > cfg -> channels ) {
370
396
goto out ;
371
397
}
372
398
/* find_lsb_set() returns 1 indexed value */
373
399
channel -= 1 ;
400
+
374
401
if (data -> chan_info [channel ].Cnt == data -> chan_info [channel ].Size ) {
375
402
if (data -> dma_callback ) {
376
403
/* Transfer complete, call user callback */
@@ -388,6 +415,7 @@ static void dma_siwx91x_isr(const struct device *dev)
388
415
sys_set_bit ((mem_addr_t )& cfg -> reg -> CHNL_SW_REQUEST , channel );
389
416
}
390
417
}
418
+
391
419
out :
392
420
/* Enable the IRQ to restore interrupt functionality for other DMA channels */
393
421
irq_enable (cfg -> irq_number );
0 commit comments