void PDMA_INIT(void) { uint32_t u32SrcAddr, u32DstAddr; /* Configure PDMA channel 1 to trigger ADC */ PDMA_Open(1 << PDMA_CH); PDMA_SetTransferCnt(PDMA_CH, PDMA_WIDTH_32, ADC_TEST_COUNT); u32SrcAddr = (uint32_t)&ADC->PDMA; u32DstAddr = (uint32_t)g_au32RxPDMADestination; PDMA_SetTransferAddr(PDMA_CH, u32SrcAddr, PDMA_SAR_FIX, u32DstAddr, PDMA_DAR_INC); PDMA_SetTimeOut(PDMA_CH, 0, 0x5555); PDMA_EnableInt(PDMA_CH, PDMA_IER_TD_IE_Msk); NVIC_EnableIRQ(PDMA_IRQn); /* Set PDMA Channel 1 for ADC, and start timeout counting */ PDMA_SetTransferMode(PDMA_CH, PDMA_ADC, 0, 0); PDMA_Trigger(PDMA_CH); }
/*---------------------------------------------------------------------------------------------------------*/ int PDMA_Example(void) { uint32_t u32EndSrc, u32EndDst; /* Init System, IP clock and multi-function I/O */ SYS_Init(); //In the end of SYS_Init() will issue SYS_LockReg() to lock protected register. If user want to write protected register, please issue SYS_UnlockReg() to unlock protected register. /* Init UART for printf */ UART0_Init(); printf("\n\nCPU @ %dHz\n", SystemCoreClock); printf("+------------------------------------------------------+ \n"); printf("| NUC400 PDMA Memory to Memory Driver Sample Code | \n"); printf("+------------------------------------------------------+ \n"); /* Open Channel 2 */ PDMA_Open(1 << 2); PDMA_SetTransferCnt(2, PDMA_WIDTH_32, PDMA_TEST_LENGTH); u32EndSrc = (uint32_t)SrcArray + PDMA_TEST_LENGTH * 4; u32EndDst = (uint32_t)DestArray + PDMA_TEST_LENGTH * 4; PDMA_SetTransferAddr(2, u32EndSrc, PDMA_SAR_INC, u32EndDst, PDMA_DAR_INC); PDMA_SetTransferMode(2, PDMA_MEM, 0, 0); PDMA_SetBurstType(2, PDMA_REQ_BURST, PDMA_BURST_4); PDMA_SetTimeOut(2, 0, 0x5); PDMA_EnableInt(2, 0); NVIC_EnableIRQ(PDMA_IRQn); u32IsTestOver = 0; PDMA_Trigger(2); while(u32IsTestOver == 0); if (u32IsTestOver == 1) printf("test done...\n"); else if (u32IsTestOver == 2) printf("target abort...\n"); else if (u32IsTestOver == 3) printf("timeout...\n"); PDMA_Close(); }
int32_t main (void) { /* Init System, IP clock and multi-function I/O In the end of SYS_Init() will issue SYS_LockReg() to lock protected register. If user want to write protected register, please issue SYS_UnlockReg() to unlock protected register if necessary */ SYS_Init(); /* Init UART0 for printf */ UART_Open(UART0, 115200); printf("\nThis sample code demonstrate PDMA channel 1 trigger DAC channel 0 function.\n"); // Enable DAC channel 0, trigger by PDMA. DAC_Open(DAC, 0, DAC_PDMA_TRIGGER); // DAC clock is 42MHz, update DAC output every 5 us, the stable time is 42 * 5 clocks DAC_SetDelayTime(DAC, 42 * 5); // Wait 'til both channels are ready while(DAC_IS_BUSY(DAC, 0) == 1); /* Configure PDMA channel 1 to trigger DAC */ PDMA_Open(1 << 1); PDMA_SetTransferCnt(1, PDMA_WIDTH_16, SINE_ARRAY_SIZE); // Set source to wrap around mode to generate sine wave continuously // Set destination to DAC DATA0 address. PDMA_SetTransferAddr(1, (uint32_t)a16Sine, PDMA_SAR_WRA, (uint32_t)&DAC->DATA0, PDMA_DAR_FIX); // Set channel 1 transfer mode to DAC channel 0 TX PDMA_SetTransferMode(1, PDMA_DAC0_TX, 0, 0); PDMA_Trigger(1); while(1); }
/*---------------------------------------------------------------------------------------------------------*/ void UART_PDMATest() { uint32_t i; uint32_t TEST_SIZE = 100; printf("+-----------------------------------------------------------+\n"); printf("| UART PDMA Test |\n"); printf("+-----------------------------------------------------------+\n"); printf("| Description : |\n"); printf("| The sample code will demo uart PDMA function. |\n"); printf("| Please connect UART1 Tx, Rx pin. |\n"); printf("+-----------------------------------------------------------+\n"); /* connect UART1 Tx, Rx pin. UART1 will transfer data from Tx PDMA buffer. And will receive data to Rx PDMA buffer. This test function will compare Tx and Rx buffer data. */ for(i = 0; i < TEST_SIZE; i++) { TX_Buffer[i] = (i & 0xff); RX_Buffer[i] = 0; } /* Enable Interrupt and install the call back function */ UART_ENABLE_INT(UART1, (UART_IER_RLS_IE_Msk | UART_IER_BUF_ERR_IE_Msk) ); NVIC_EnableIRQ(UART1_IRQn); // Rx PDMA Setting PDMA_Open(1 << RX_CH); PDMA_SetTransferCnt(RX_CH, PDMA_WIDTH_8, TEST_SIZE); PDMA_SetTransferAddr(RX_CH, UART1_BASE, PDMA_SAR_FIX, (uint32_t)RX_Buffer, PDMA_DAR_INC); PDMA_SetTransferMode(RX_CH, PDMA_UART1_RX, 0, 0); PDMA_SetTimeOut(RX_CH, 0, 0x5555); PDMA_EnableInt(RX_CH, PDMA_IER_TD_IE_Msk); NVIC_EnableIRQ(PDMA_IRQn); u32IsTestOver = 0; // Tx PDMA Setting PDMA_Open(1 << TX_CH); PDMA_SetTransferCnt(TX_CH, PDMA_WIDTH_8, TEST_SIZE); PDMA_SetTransferAddr(TX_CH, (uint32_t)TX_Buffer, PDMA_SAR_INC, UART1_BASE, PDMA_DAR_FIX); PDMA_SetTransferMode(TX_CH, PDMA_UART1_TX, 0, 0); PDMA_SetTimeOut(TX_CH, 0, 0x5555); PDMA_EnableInt(TX_CH, PDMA_IER_TD_IE_Msk); NVIC_EnableIRQ(PDMA_IRQn); u32IsTestOver = 0; PDMA_Trigger(RX_CH); PDMA_Trigger(TX_CH); UART1->CTL |= UART_CTL_DMA_RX_EN_Msk; UART1->CTL |= UART_CTL_DMA_TX_EN_Msk; while(u32IsTestOver == 0); for(i = 0; i < TEST_SIZE; i++) { if(TX_Buffer[i] != RX_Buffer[i]) { printf("\n Test fail!!"); while(1); } } printf("\n Tx/Rx data compare pass!!"); /* Disable Interrupt */ UART_DISABLE_INT(UART1, (UART_IER_RLS_IE_Msk | UART_IER_BUF_ERR_IE_Msk)); NVIC_DisableIRQ(UART1_IRQn); printf("\n UART PDMASample Demo End.\n"); }