API  2.2
TSmarT Software Library
 All Data Structures Functions Variables Typedefs Enumerations Enumerator Groups Pages
db_uart.c

Example showing how to type and read data using the UART device

/* @file db_uart.c
* @author TST
* @version V0.0
* @date 26/09/2012
* @brief Debug_Board UART example.
*
* This example show users how to manage the diffrerents UARTs in the Debug_Board
* board. The example works with:
* - UART-1
* - UART-3
*
* It sends a simply message for UART1 and the UART3 depend on the selected UART
* in the Debug_Board. In addition, when a character is received by the tx line of the
* selected UART (Check the jumpers of the Debug_Board) a simply UART identification
* message will be sent to Debug_Board (Debug_Board send this message to a serial program).
*
*
* @note To run this appplication, user shall set the next configuration in the serial communication program:
* - Baud rate: 19200
* - Word length: 8 bits
* - Parity: none
* - Stop bit: 1
* - Flow control: none
*/
#include "tsmart.h"
/* @brief Task function. This task sends a message using the UART1 each second.
*
* @param pvParameters
*
*/
void vUART1(void *pvParameters){
for(;;){
/* Send message */
TSMART_UART_Send(&tsmart_uart1, "UART-1 in use\r\n", strlen("UART-1 in use\r\n"), 1000/portTICK_RATE_MS);
/* Wait for a second */
vTaskDelay(500/portTICK_RATE_MS);
}
}
/* @brief Task function. This task sends a message using the UART3 each second.
*
* @param pvParameters
*
*/
void vUART3(void *pvParameters){
for(;;){
/* Send message */
TSMART_UART_Send(&tsmart_uart3, "UART-3 in use\r\n", strlen("UART-3 in use\r\n"), 1000/portTICK_RATE_MS);
/* Wait for a second */
vTaskDelay(500/portTICK_RATE_MS);
}
}
/* @brief Task function. This task is waitng for any value. When a value is received, it sends a message
* using the UART1.
*
* @param pvParameters
*
*/
void vUART1RX(void *pvParameters){
/* Variables */
uint8_t value;
for(;;){
/* Wait for new value */
TSMART_UART_Receive(&tsmart_uart1, &value, 1, portMAX_DELAY);
/* Send message */
TSMART_UART_Send(&tsmart_uart1, "Reception UART-1\r\n", strlen("Reception UART-1\r\n"), 1000/portTICK_RATE_MS);
}
}
/* @brief Task function. This task is waitng for any value. When a value is received, it sends a message
* using the UART3.
*
* @param pvParameters
*
*/
void vUART3RX(void *pvParameters){
/* Variables */
uint8_t value;
for(;;){
/* Wait for new value */
TSMART_UART_Receive(&tsmart_uart3, &value, 1, portMAX_DELAY);
/* Send message */
TSMART_UART_Send(&tsmart_uart3, "Reception UART-3\r\n", strlen("Reception UART-3\r\n"), 1000/portTICK_RATE_MS);
}
}
/*
* @brief init() function
*
* This is the first thing that the user must do for using TSmarT.
* It initializes the specific hardware resources (GPRS, GPS, AI, DIO, MODBUS, MSA...)
* and software resources (queues, mutex, tasks...) for the user application.
*
* The way to fill in this function properly is to initialize first
* hardware resources and after that software resources.
*
* This function must return: TSMART_PASS when every thing is OK or
* TSMART_FAIL when a failure happened.
*
* @return
* @arg TSMART_PASS
* @arg TSMART_FAIL
*/
int32_t init() {
/* Variables */
tsmart_uart_config_t tsmart_uart_config;
/* Reception buffer UART. Size must be the same as rx_buf_sz */
static uint8_t app_rx_buf1[50];
static uint8_t app_rx_buf3[50];
/* ************************************************************************* */
/* Debug Mode */
/* ************************************************************************* */
/* ************************************************************************* */
/* Initialize resources */
/* ************************************************************************* */
/* UART configuration. */
/* Baud rate */
tsmart_uart_config.baud_rate = 19200;
/* Flow control */
tsmart_uart_config.flow_control = TSMART_UART_FC_NONE;
/* Parity bit */
tsmart_uart_config.parity_bit = TSMART_UART_PARITY_NONE;
/* Word length */
tsmart_uart_config.word_length = TSMART_UART_WORDLENGTH_8B;
/* Stop bit */
tsmart_uart_config.stop_bit = TSMART_UART_STOPBITS_1;
/* Buffer size for our UART */
tsmart_uart_config.rx_buf_sz = 50;
/* Buffer for our UART */
tsmart_uart_config.rx_buf = app_rx_buf1;
/* UART DMA */
tsmart_uart_config.use_dma = TSMART_UART_DMA_RX_TX;
/* UART time out */
tsmart_uart_config.use_tim = TSMART_UART_TIM_SW;
/* Initialize UART. UART 1 is selected */
TSMART_UART_Init(&tsmart_uart1, &tsmart_uart_config);
/* UART configuration. */
/* Baud rate */
tsmart_uart_config.baud_rate = 19200;
/* Flow control */
tsmart_uart_config.flow_control = TSMART_UART_FC_NONE;
/* Parity bit */
tsmart_uart_config.parity_bit = TSMART_UART_PARITY_NONE;
/* Word length */
tsmart_uart_config.word_length = TSMART_UART_WORDLENGTH_8B;
/* Stop bit */
tsmart_uart_config.stop_bit = TSMART_UART_STOPBITS_1;
/* Buffer size for our UART */
tsmart_uart_config.rx_buf_sz = 50;
/* Buffer for our UART */
tsmart_uart_config.rx_buf = app_rx_buf3;
/* UART DMA */
tsmart_uart_config.use_dma = TSMART_UART_DMA_RX_TX;
/* UART time out */
tsmart_uart_config.use_tim = TSMART_UART_TIM_SW;
/* Initialize UART. UART 3 is selected */
TSMART_UART_Init(&tsmart_uart3, &tsmart_uart_config);
/* ************************************************************************* */
/* Application task */
/* ************************************************************************* */
/* Create the UART1 task */
if(xTaskCreate(vUART1, "UART1", 512, NULL, 7, NULL) != pdPASS){
return TSMART_FAIL;
}
/* Create the UART3 task */
if(xTaskCreate(vUART3, "UART3", 512, NULL, 7, NULL) != pdPASS){
return TSMART_FAIL;
}
/* Create the UART1 RX task */
if(xTaskCreate(vUART1RX, "UART1RX", 512, NULL, 7, NULL) != pdPASS){
return TSMART_FAIL;
}
/* Create the UART3 RX task */
if(xTaskCreate(vUART3RX, "TUART3RX", 512, NULL, 7, NULL) != pdPASS){
return TSMART_FAIL;
}
/* Everything OK */
return TSMART_PASS;
}