void PDMA_Init(uint8_t *g_au8TxBuffer)
{
/* Open PDMA Channel */
PDMA_Open(PDMA, 1 << 1); // Channel 1 for UART1 RX
// Select basic mode
PDMA_SetTransferMode(PDMA, 1, PDMA_UART1_RX, 0, 0);
// Set data width and transfer count
PDMA_SetTransferCnt(PDMA, 1, PDMA_WIDTH_8, 32);
//Set PDMA Transfer Address
PDMA_SetTransferAddr(PDMA, 1, UART1_BASE, PDMA_SAR_FIX, ((uint32_t)(&g_au8RxBuffer[0])), PDMA_DAR_INC);
//Select Single Request
PDMA_SetBurstType(PDMA, 1, PDMA_REQ_SINGLE, 0);
#ifdef ENABLE_PDMA_INTERRUPT
//Set timeout
// PDMA_SetTimeOut(PDMA, 0, 1, PDMA_TIME);
PDMA_SetTimeOut(PDMA, 1, 1, PDMA_TIME);
// PDMA_EnableInt(PDMA, 0, PDMA_INT_TRANS_DONE);
PDMA_EnableInt(PDMA, 1, PDMA_INT_TRANS_DONE);
PDMA_EnableInt(PDMA, 1, PDMA_INT_TIMEOUT);
g_u32IsTestOver = 0;
#endif
}
MAIN函数:
while (1)
{
PDMA_Init(g_au8TxBuffer[0]);
// Enable UART PDMA Tx and Rx
UART_PDMA_ENABLE(UART1,UART_INTEN_RXPDMAEN_Msk);
while(g_u32IsTestOver==0);
if (g_u32IsTestOver == 1)
{
printf("test done...\n");
g_u32IsTestOver = 0;
//RX
for(int i=0;i<32;i++)
{
printf("%d:%x\n",i,g_au8RxBuffer[i]);
g_au8RxBuffer[i]=0;
}
}
//UART_PDMA_DISABLE(UART1,UART_INTEN_RXPDMAEN_Msk);
} |