@@ -244,44 +244,46 @@ static void spi_mcux_dma_callback(const struct device *dev, void *arg, uint32_t
244
244
/* arg directly holds the spi device */
245
245
const struct device * spi_dev = arg ;
246
246
struct spi_mcux_data * data = (struct spi_mcux_data * )spi_dev -> data ;
247
+ char debug_char ;
247
248
248
249
if (status < 0 ) {
249
- LOG_ERR ("DMA callback error with channel %d." , channel );
250
- data -> status_flags |= LPSPI_DMA_ERROR_FLAG ;
250
+ goto error ;
251
+ }
252
+
253
+ /* identify the origin of this callback */
254
+ if (channel == data -> dma_tx .channel ) {
255
+ /* this part of the transfer ends */
256
+ data -> status_flags |= LPSPI_DMA_TX_DONE_FLAG ;
257
+ debug_char = 'T' ;
258
+ } else if (channel == data -> dma_rx .channel ) {
259
+ /* this part of the transfer ends */
260
+ data -> status_flags |= LPSPI_DMA_RX_DONE_FLAG ;
261
+ debug_char = 'R' ;
251
262
} else {
252
- /* identify the origin of this callback */
253
- if (channel == data -> dma_tx .channel ) {
254
- /* this part of the transfer ends */
255
- data -> status_flags |= LPSPI_DMA_TX_DONE_FLAG ;
256
- LOG_DBG ("DMA TX Block Complete" );
257
- } else if (channel == data -> dma_rx .channel ) {
258
- /* this part of the transfer ends */
259
- data -> status_flags |= LPSPI_DMA_RX_DONE_FLAG ;
260
- LOG_DBG ("DMA RX Block Complete" );
261
- } else {
262
- LOG_ERR ("DMA callback channel %d is not valid." , channel );
263
- data -> status_flags |= LPSPI_DMA_ERROR_FLAG ;
264
- }
263
+ goto error ;
265
264
}
265
+
266
+ LOG_DBG ("DMA %cX Block Complete" , debug_char );
267
+
266
268
#if CONFIG_SPI_ASYNC
267
- if (data -> ctx .asynchronous &&
268
- ((data -> status_flags & LPSPI_DMA_DONE_FLAG ) == LPSPI_DMA_DONE_FLAG )) {
269
+ if (data -> ctx .asynchronous && (data -> status_flags & LPSPI_DMA_DONE_FLAG )) {
269
270
/* Load dma blocks of equal length */
270
- size_t dma_size = MIN (data -> ctx . tx_len , data -> ctx . rx_len );
271
+ size_t dma_size = spi_context_max_continuous_chunk (data -> ctx );
271
272
272
- if (dma_size = = 0 ) {
273
- dma_size = MAX ( data -> ctx . tx_len , data -> ctx . rx_len ) ;
273
+ if (dma_size ! = 0 ) {
274
+ return ;
274
275
}
275
276
276
277
spi_context_update_tx (& data -> ctx , 1 , dma_size );
277
278
spi_context_update_rx (& data -> ctx , 1 , dma_size );
278
-
279
- if (data -> ctx .tx_len == 0 && data -> ctx .rx_len == 0 ) {
280
- spi_context_complete (& data -> ctx , spi_dev , 0 );
281
- }
282
- return ;
283
279
}
284
280
#endif
281
+
282
+ goto done ;
283
+ error :
284
+ LOG_ERR ("DMA callback error with channel %d." , channel );
285
+ data -> status_flags |= LPSPI_DMA_ERROR_FLAG ;
286
+ done :
285
287
spi_context_complete (& data -> ctx , spi_dev , 0 );
286
288
}
287
289
0 commit comments