KSDK-1.1.0 eDMA Ping-Pong

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

KSDK-1.1.0 eDMA Ping-Pong

746 Views
oaf
Contributor IV

I'm programming the FRDM-K64 and are trying to get input from SAI using DMA.

The idea is to get the DMA read to one buffer while I'm processing the other, and then we could switch buffers (ping - pong).

The DMA is configured as this:

uint32_t *fifo_addr = SAI_DRV_RxGetFifoAddr(0, chan);

uint8_t saiBuff[1000];

EDMA_DRV_InstallCallback(&dmaCh0, RxDmaCallback, (void *)0);

EDMA_DRV_ConfigLoopTransfer(&dmaCh0, i2s0Tcd, kEDMAPeripheralToMemory,

    (uint32_t)fifo_addr, (uint32_t)saiBuff,

      4,            // Transfer size pr DMA read/write in bytes

     32,            // bytes on each DMA work cycle

     64,           // totalLength (buffer size)

       2);            // number of TCDs

As I understand it from the doc/debugger:

     Each DMA cycle will transfer 4 bytes (using SPI in 32-bit mode, this is correct?)

    I get a Rx IRQ callback after 32 bytes has been transfered by the DMA

    My buffer is 64 bytes long.

    The DMA and I have split the buffer in 2.

The question is: In the RxDmaCallback(), how do I find out which buffer (ping or pong) is ready for processing?

Tags (3)
3 Replies

451 Views
DavidS
NXP Employee
NXP Employee

Hi Ole,

Just white boarding a couple of options.

1) initialize the Rx buffer to all "F's" (or a pattern you do not expect to ever see).  In the ISR receive the data from the buffer with data, then clear and set to all "F's".

2) Chain eDMA to another channel that DMA's one source global value to one destination global variable.  In the ISR read that destination variable to determine which half is the new data, and then update the source global value to indicate the other buffer should be used next time.

Regards,

David

451 Views
oaf
Contributor IV

To fill with known pattern and search, or chain DMA channels seems a little bit crazy to me.

I've found out that you could use DMA_TCD0_DADDR to find last written buffer address but when all the project is using ProcessorExpert it feels a little bit wrong to access the DMA registers directly.

0 Kudos

451 Views
DavidS
NXP Employee
NXP Employee

Hi Ole,

I will continue to think of ideas or maybe someone else will answer too.

With respect to my ideas, I intended that you would only look at the first longword of each buffer to determine which was the correct buffer to access. 

Using a chained eDMA channel is "excessive" but just another idea.

Your idea valid too.

Or just using a global variable that you exclusive OR in the ISR to determine which buffer to read.

Sorry PE doesn't have the exact implementation you are looking for.

Regards,

David

0 Kudos