104 lines
3.2 KiB
C
104 lines
3.2 KiB
C
/*!
|
|
* \file uart_dma_test.c
|
|
*
|
|
* \brief Target uart test implementation
|
|
*
|
|
* \copyright Revised BSD License, see section \ref LICENSE.
|
|
*
|
|
* \code
|
|
*
|
|
* _ __ _ ________ _
|
|
* | |/ /(_)___ / ____/ /_ (_)___
|
|
* | // / __ \/ / / __ \/ / __ \
|
|
* / |/ / / / / /___/ / / / / /_/ /
|
|
* /_/|_/_/_/ /_/\____/_/ /_/_/ .___/
|
|
* /_/
|
|
* (C) 2022-2025 XinChip
|
|
*
|
|
* \endcode
|
|
*
|
|
* \author ( XinChip ) Alex-J
|
|
*
|
|
* \author ( XinChip )
|
|
*/
|
|
|
|
/*-----------------------------------------------------------------------------------
|
|
INCLUDE HEADE FILES
|
|
------------------------------------------------------------------------------------*/
|
|
#include "uart_dma.h"
|
|
#include "xc60xx_uart.h"
|
|
|
|
/*------------------------------------------------------------------------------------
|
|
Macros
|
|
-------------------------------------------------------------------------------------*/
|
|
|
|
/*------------------------------------------------------------------------------------
|
|
Global Variables
|
|
-------------------------------------------------------------------------------------*/
|
|
|
|
/*------------------------------------------------------------------------------------
|
|
Functions
|
|
-------------------------------------------------------------------------------------*/
|
|
/**
|
|
* @brief uart_dma_demo
|
|
* @details
|
|
* @param void
|
|
* @retval void
|
|
*/
|
|
void uart_dma_demo(void) {
|
|
DEBUG("__UART_DMA_DEMO__\n");
|
|
|
|
uint8_t __attribute__((aligned(4))) rxbuff[26];
|
|
UART_TypeDef *uart_handle = XC_UART0;
|
|
|
|
UART_InitTypeDef UART_InitStruct = {0};
|
|
GPIO_InitTypeDef GPIO_InitStruct = {0};
|
|
|
|
GPIO_InitStruct.Mux = GPIO_Mux0;
|
|
GPIO_InitStruct.Pull = GPIO_PULLUP;
|
|
GPIO_InitStruct.Int = NOT_INT;
|
|
|
|
GPIO_InitStruct.Pin = GPIO_3;
|
|
GPIO_InitStruct.Dir = GPIO_DIR_OUTPUT;
|
|
GPIO_InitStruct.FunSel = UART0_TX;
|
|
GPIO_Init(&GPIO_InitStruct);
|
|
|
|
GPIO_InitStruct.Pin = GPIO_2;
|
|
GPIO_InitStruct.Dir = GPIO_DIR_INPUT;
|
|
GPIO_InitStruct.FunSel = UART0_RX;
|
|
GPIO_Init(&GPIO_InitStruct);
|
|
|
|
UART_InitStruct.Parity = UART_PARITY_DISABLE;
|
|
UART_InitStruct.StopBits = UART_STOP_1_BITS;
|
|
UART_InitStruct.WordLength = UART_UARTx_TCR_CLS_8BITS;
|
|
UART_InitStruct.BaudRate = UART_BAUDRATE_115200;
|
|
UART_InitStruct.HardwareFlowControl = UART_UARTx_MCR_AFCE_DISABLE;
|
|
|
|
UART_Init(uart_handle, &UART_InitStruct);
|
|
|
|
UART_DMA_IT_Register_TxCallback(uart_handle);
|
|
UART_DMA_IT_Register_RxCallback(uart_handle);
|
|
|
|
if (uart_handle == XC_UART0) {
|
|
UART_DMA_IT_Enable(XC_UART0,
|
|
1 << (DMA_CH_RCV_UART0 + 16) | 1 << DMA_CH_SEND_UART0);
|
|
} else if (uart_handle == XC_UART1) {
|
|
UART_DMA_IT_Enable(XC_UART1,
|
|
1 << (DMA_CH_RCV_UART1 + 16) | 1 << DMA_CH_SEND_UART1);
|
|
}
|
|
|
|
NVIC_EnableIRQ(DMAS_IRQn);
|
|
|
|
UARTx_DMA_Receive_Config(uart_handle);
|
|
|
|
for (int i = 0; i < 26; i++) {
|
|
uart_txdmabuff[i] = i + 'A';
|
|
}
|
|
|
|
while (1) {
|
|
if (UART_DMA_ReceiveData(uart_handle, rxbuff)) {
|
|
UART_DMA_SendData(uart_handle, rxbuff, 1);
|
|
}
|
|
}
|
|
}
|