AnsweredAssumed Answered

eDMA driver

Question asked by Pat on Nov 11, 2016
Latest reply on Nov 18, 2016 by David E Seymour

Hi All,

Looking for some guidance on porting my TCD-DMA configuration to the KSDK v2.0 using the eDMA driver API. My code transfer data from buffer to SPI over DMA.

 

static uint32_t SPI_data_patterns[] =
{
   DSPI_PUSHR_PCS0 | DSPI_PUSHR_CTAS(0) | DSPI_PUSHR_CONT | DSPI_PUSHR_TXDATA(0x0ec0),
   DSPI_PUSHR_PCS0 | DSPI_PUSHR_CTAS(0) | DSPI_PUSHR_EOQ  | DSPI_PUSHR_TXDATA(0x0000)
};

 

static uint32_t *p_SPI_data_patterns = SPI_data_patterns;
static uint32_t SPI_data_patterns_size = sizeof(SPI_data_patterns);

 

void test(void)
{
   ...
   /* Load address of source data */
   DMA_0.TCD[16].SADDR.R = p_SPI_data_patterns;
   /* Read 4 bytes per transfer */
   DMA_0.TCD[16].ATTR.B.SSIZE = kEDMA_TransferSize4Bytes;
   /* After transfer, add 4 to src addr */
   DMA_0.TCD[16].SOFF.B.SOFF = 4;
   /* After major loop, reset src addr */
   DMA_0.TCD[16].SLAST.B.SLAST = -SPI_data_patterns_size;
   /* Source modulo feature not used */
   DMA_0.TCD[16].ATTR.B.SMOD = 0;
 
   /* Load address of destination */
   DMA_0.TCD[16].DADDR.B.DADDR = &SPI0.PUSHR.R;
   /* Write 4 bytes per transfer */
   DMA_0.TCD[16].ATTR.B.DSIZE = kEDMA_TransferSize4Bytes;
   /* After transfer, add 0 to dest addr */
   DMA_0.TCD[16].DOFF.B.DOFF = 0;
   /* After major loop, reset dest addr */
   DMA_0.TCD[16].DLASTSGA.B.DLASTSGA = 0;
   /* Destination modulo feature not used */
   DMA_0.TCD[16].ATTR.B.DMOD = 0;
 
   /* Transfer 4 bytes per minor loop */
   DMA_0.TCD[16].NBYTES.MLNO.B.NBYTES = 4;
 
   /* Initialize the begining and current major loop iteration counts */
   DMA_0.TCD[16].BITER.ELINKNO.B.BITER = SPI_data_patterns_size / 4;
   DMA_0.TCD[16].CITER.ELINKNO.B.CITER = SPI_data_patterns_size / 4;
   DMA_0.TCD[16].BITER.ELINKNO.B.ELINK = 0;
   DMA_0.TCD[16].CITER.ELINKNO.B.ELINK = 0;
 
   DMA_0.TCD[16].CSR.B.DREQ         = 1;
   DMA_0.TCD[16].CSR.B.INTHALF      = 0;
   DMA_0.TCD[16].CSR.B.INTMAJOR     = 0;
   DMA_0.TCD[16].CSR.B.MAJORELINK   = 0;
   DMA_0.TCD[16].CSR.B.ESG          = 0
   DMA_0.TCD[16].CSR.B.BWC          = 0;
   DMA_0.TCD[16].CSR.B.START        = 0;
   DMA_0.TCD[16].CSR.B.DONE         = 0;
   DMA_0.TCD[16].CSR.B.ACTIVE       = 0;

 

   /*eDMA request signal for channel 16 is enabled, start DMA/SPI transfer*/
   DMA_0.ERQ.B.ERQ16 = 1U;

...
}   
void my10msISR(void)

{

...

      if (SPI_0.SR.B.EOQF){
         /*clear EOQF, so next frames are TXed by DMA*/
         SPI_0.SR.R = DSPI_SR_EOQF;
         DMA_0.ERQ.B.ERQ16 = 1U;
      }

...
 }

 

Best regards,

Pat

Outcomes