// Configure PDMA to Scatter Gather mode */
void PDMA_Init(void)
{
/* Tx description */
DMA_TXDESC[0].ctl = ((BUFF_LEN-1)<<PDMA_DSCT_CTL_TXCNT_Pos)|PDMA_WIDTH_32|PDMA_SAR_INC|PDMA_DAR_FIX|PDMA_REQ_SINGLE|PDMA_OP_SCATTER;
DMA_TXDESC[0].src = (uint32_t)&PcmTxBuff[0];
DMA_TXDESC[0].dest = (uint32_t)&I2S0->TXFIFO;
DMA_TXDESC[0].offset = (uint32_t)&DMA_TXDESC[1] - (PDMA->SCATBA);
DMA_TXDESC[1].ctl = ((BUFF_LEN-1)<<PDMA_DSCT_CTL_TXCNT_Pos)|PDMA_WIDTH_32|PDMA_SAR_INC|PDMA_DAR_FIX|PDMA_REQ_SINGLE|PDMA_OP_SCATTER;
DMA_TXDESC[1].src = (uint32_t)&PcmTxBuff[1];
DMA_TXDESC[1].dest = (uint32_t)&I2S0->TXFIFO;
DMA_TXDESC[1].offset = (uint32_t)&DMA_TXDESC[0] - (PDMA->SCATBA); //link to first description
/* Rx description */
DMA_RXDESC[0].ctl = ((BUFF_LEN-1)<<PDMA_DSCT_CTL_TXCNT_Pos)|PDMA_WIDTH_32|PDMA_SAR_FIX|PDMA_DAR_INC|PDMA_REQ_SINGLE|PDMA_OP_SCATTER;
DMA_RXDESC[0].src = (uint32_t)&I2S0->RXFIFO;
DMA_RXDESC[0].dest = (uint32_t)&PcmRxBuff[0];
DMA_RXDESC[0].offset = (uint32_t)&DMA_RXDESC[1] - (PDMA->SCATBA);
DMA_RXDESC[1].ctl = ((BUFF_LEN-1)<<PDMA_DSCT_CTL_TXCNT_Pos)|PDMA_WIDTH_32|PDMA_SAR_FIX|PDMA_DAR_INC|PDMA_REQ_SINGLE|PDMA_OP_SCATTER;
DMA_RXDESC[1].src = (uint32_t)&I2S0->RXFIFO;
DMA_RXDESC[1].dest = (uint32_t)&PcmRxBuff[1];
DMA_RXDESC[1].offset = (uint32_t)&DMA_RXDESC[0] - (PDMA->SCATBA); //link to first description
/* Open PDMA channel 1 for I2S TX and channel 2 for I2S RX */
PDMA_Open(PDMA,0x3 << 1);
/* Configure PDMA transfer mode */
PDMA_SetTransferMode(PDMA,1, PDMA_I2S0_TX, 1, (uint32_t)&DMA_TXDESC[0]);
PDMA_SetTransferMode(PDMA,2, PDMA_I2S0_RX, 1, (uint32_t)&DMA_RXDESC[0]);
/* Enable PDMA channel 1&2 interrupt */
PDMA_EnableInt(PDMA,1, 0);
PDMA_EnableInt(PDMA,2, 0);
NVIC_EnableIRQ(PDMA_IRQn);
}
|