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

This is an example about how to manage the operating system FreeRTOS.

/* @file freertos_timer.c
* @author TST
* @version 0.1
* @date 13/06/2012
* @brief This is an example of how to manage the operating system FreeRTOS.
*
* FreeRTOS is a real-time operating system for embedded devices,
* being ported to 31 micro-controllers. This example shows the user how to create
* timers.
*
* User can learn more about FreeRTOS in http://www.freertos.org/
*
* API reference for FreeRTOS:
* - http://www.freertos.org/a00106.html
*
*/
/* Platform headers */
#include "tsmart.h"
/* Debug UART parameters */
#define APP_RX_BUFFER_SZ 20
#define TSMART_UART tsmart_uart3
static uint8_t app_rx_buf[APP_RX_BUFFER_SZ];
static uint8_t debug_buf[20];
/* Timer handler */
static xTimerHandle timer;
/* Timer handler function */
void callback_timer(xTimerHandle xTimer){
/* Debug message */
TSMART_UART_Send(&TSMART_UART, "timer expired\r\n", strlen("timer expired\r\n"), 1000/portTICK_RATE_MS);
/* Reset timer */
xTimerReset(timer, portMAX_DELAY);
}
/* @brief vTimer task
*
* This task configures and starts a timer.
*
* @param pvParameters
*/
void vTimer(void *pvParameters) {
portBASE_TYPE ret;
void * pvTimerID;
/* Debug message */
TSMART_UART_Send(&TSMART_UART, "FreeRTOS Timer test\r\n", strlen("FreeRTOS Timer test\r\n"), 1000/portTICK_RATE_MS);
/* Create timer */
timer = xTimerCreate( "timer", 5000/portTICK_RATE_MS, pdTRUE, pvTimerID, callback_timer);
/* Debug message */
TSMART_UART_Send(&TSMART_UART, "Start timer\r\n", strlen("Start timer\r\n"), 1000/portTICK_RATE_MS);
/* Start */
ret = xTimerStart(timer, portMAX_DELAY);
/* Wait for ever */
vTaskDelay(portMAX_DELAY);
}
/* @brief "Init()" function.
*
* This is the first thing that the user must do for using TSmarT.
* It initializes 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 */
portBASE_TYPE xReturn;
tsmart_uart_config_t tsmart_uart_config;
/* ************************************************************************* */
/* Debug Mode */
/* ************************************************************************* */
/* ************************************************************************* */
/* Initialize hardware resources */
/* ************************************************************************* */
/* The specific hardware for this application: Debug UART
*/
/* Initialize Debug UART3 */
tsmart_uart_config.baud_rate = 19200;
tsmart_uart_config.flow_control = TSMART_UART_FC_NONE;
tsmart_uart_config.parity_bit = TSMART_UART_PARITY_NONE;
tsmart_uart_config.word_length = TSMART_UART_WORDLENGTH_8B;
tsmart_uart_config.stop_bit = TSMART_UART_STOPBITS_1;
tsmart_uart_config.rx_buf_sz = APP_RX_BUFFER_SZ;
tsmart_uart_config.rx_buf = app_rx_buf;
tsmart_uart_config.use_dma = TSMART_UART_DMA_RX_TX;
tsmart_uart_config.use_tim = TSMART_UART_TIM_SW;
TSMART_UART_Init(&TSMART_UART, &tsmart_uart_config);
/* ************************************************************************* */
/* Application task */
/* ************************************************************************* */
/* This examples will need two tasks:
*
* - vtimer task: This task configures and uses a timer from FreeRTOS
*
*/
xReturn = xTaskCreate(vTimer, "Timer", 256, NULL, 7, NULL);
if (xReturn != pdPASS) {
return TSMART_FAIL;
}
/* Everything OK */
return TSMART_PASS;
}