This is the quickstart guide for SAM3A/3N/3S/3U/3X/4E/4N/4S/G Peripheral DMA Controller (PDC) Driver with step-by-step instructions on how to configure and use the driver.
voidFirst initialise the board:console_uart_irq_handler(
void)
{
/* Get UART status and check if PDC receive buffer is full */
if
((uart_get_status(CONSOLE_UART) & UART_SR_RXBUFF) == UART_SR_RXBUFF) {
/* Configure PDC for data transfer (RX and TX) */
pdc_rx_init(g_p_uart_pdc, &g_pdc_uart_packet, NULL);
pdc_tx_init(g_p_uart_pdc, &g_pdc_uart_packet, NULL);
}
}
Now setup the PDC registers:sysclk_init();
board_init();
Enable UART IRQ:/* Get pointer to UART PDC register base */
g_p_uart_pdc = uart_get_pdc_base(CONSOLE_UART);
/* Initialize PDC data packet for transfer */
g_pdc_uart_packet.ul_addr = (uint32_t) g_uc_pdc_buffer;
g_pdc_uart_packet.ul_size = BUFFER_SIZE;
/* Configure PDC for data receive */
pdc_rx_init(g_p_uart_pdc, &g_pdc_uart_packet, NULL);
/* Enable PDC transfers */
pdc_enable_transfer(g_p_uart_pdc, PERIPH_PTCR_RXTEN | PERIPH_PTCR_TXTEN);
uart_enable_interrupt(CONSOLE_UART, UART_IER_RXBUFF);
Enable UART interrupt NVIC_EnableIRQ(CONSOLE_UART_IRQn);
Once the required number of bytes have been transferred, an interrupt is triggered and the handler will run. The main program may execute other code or be busy-waiting:while
(1) {
}