How do I find which TCD was active on the eDMA callback?

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

How do I find which TCD was active on the eDMA callback?

1,135 Views
marcohess
Contributor II

I used the EDMA_DRV_ConfigLoopTransfer function in the KSDK to setup a DMA transfer from the ADC to a ping-pong buffer like so:

 

    status = EDMA_DRV_ConfigLoopTransfer( &edma_chan_state0,

                                          edma_transfer_descriptors1,

                                          kEDMAPeripheralToMemory,

                                          (uint32_t)&ADC0->R[0],

                                          (uint32_t)&edma_buffer0,

                                          2, /* size to be transferred on every DMA write/read */

                                          2, /* bytesOnEachRequest */

                                          sizeof( edma_buffer0 ), /* Total length of Memory in bytes */

                                          2 /* Num Descriptors */ );

 

I also have a callback interrupt that signals that a transfer was completed.

 

    status = EDMA_DRV_InstallCallback( &edma_chan_state0,

                                       edma0_callback,

                                       &edma_chan_state0 );

 

It all seems to work (PDB triggering the ADC) and I am collecting samples in my buffers, but how do I know which buffer is the last filled one?

Labels (1)
Tags (2)
0 Kudos
Reply
2 Replies

766 Views
marcohess
Contributor II

Found a solution that appears to work. Not sure if is the most elegant solution:

            if( (uint32_t)DMA_TCD0_DADDR >= (uint32_t)&edma_buffer0[1] )

            {

                edma_buffer0_index = 0;

            }

            else

            {

                edma_buffer0_index = 1;

            }

With edma_buffer0_index now being the index to the buffer that is ready to be processed.

0 Kudos
Reply

766 Views
bosleymusic_com
Contributor IV

Is this code in an interrupt or in the main body of a regular loop?

I'm trying to work out something similar, but you should be able to configure major loop for half interrupt, and full interrupt according to the documentation. The thing is I think even if you use half interrupt, the installer

EDMA_HAL_STCDSetHalfCompleteIntCmd drops in to the same interrupt based on what I see in the TCD structure, so you would still need some form of logic like you've outlined to decide which portion of the buffer to process.


The other thing is this - are you  truly ping-ponging? It's hard to tell because I can't see how you've declared your buffer - is it one continuous array? If it's one continous array, you should set half interrupt, use the logic you set up (seems fine to me) and onward ho. BUT, If you have two descriptors in loop,  aren't they each being written to every flag/request? Have you set a breakpoint inside the interrupt and looked at how the data is being written? I'm curious to know what your buffer(s) look like at half interrupt point.  Is one filled with values, while the other is empty, or are the writes being split between them because you have two separate descriptors declared and using round robin arbitration for EDMA?

I'm working through something very similar for mono audio in SAI so I'd love to put our heads together and see what works best.

0 Kudos
Reply