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

This is an example about how to use the MSAL board, using 2 digital I/O.

/* @file msal_digital.c
* @author TST
* @version 0.1
* @date 18/06/2012
* @brief This is an example about how to use the MSAL board, using digital I/O
* input.
*
* @note To run this application it's necessary to connect the board with
* a 2 digital sources that simulates a sensor.
*
*/
/* Platform headers */
#include "tsmart.h"
/* Select with or without Interrupt */
#define USE_INTERRUPT 1
//#define USE_INTERRUPT 0
#define UART_BAUD_RATE 19200 /* typical Baud Rate */
#define UART_BUF_SZ 96 /* UART buffer size */
#define DEBUG_UART tsmart_uart2 /* UART2 for debugging selected */
/* @brief vMSAL_DIGITAL task
*
* This task turns on the digital module of the MSAL board, reads the value
* and set digital output.
*
* @param pvParameters
*/
void vMSAL_DIGITAL(void *pvParameters){
uint16_t value;
int8_t interrup;
uint8_t buffer[255];
sprintf(buffer,"\r\n\r\nStarting measures\r\n");
TSMART_UART_Send(&DEBUG_UART, buffer, strlen(buffer), 1000/portTICK_RATE_MS);
/* Activate the board */
while(1){
/* Read the analogical value on the 0-10Vdc input #1*/
if (USE_INTERRUPT == 0){
/* Sleep 1 second */
vTaskDelay(1000/portTICK_RATE_MS);
}else{
}
if (value == 1){
}else{
}
/* Print read value */
sprintf(buffer,"\r\nMeasured value: %d\r\n", value);
TSMART_UART_Send(&DEBUG_UART, buffer, strlen(buffer), 1000/portTICK_RATE_MS);
}
}
/* @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, MSAL...)
* 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 */
/* MSAL configuration */
tsmart_msal_config_t msal_config;
/* Debugging UART configuration */
tsmart_uart_config_t tsmart_uart_config;
/* UART buffer */
static uint8_t uart_buf[UART_BUF_SZ];
/* Return */
portBASE_TYPE xReturn;
/* ************************************************************************* */
/* Debug Mode */
/* ************************************************************************* */
/* ************************************************************************* */
/* Initialize resources */
/* ************************************************************************* */
/* The specific hardware for this application: MSAL
*/
/* Initialize MSAL with defect parameters */
msal_config.adc_mode = ADC_Mode_Independent;
msal_config.adc_external_trig_conv = ADC_ExternalTrigConv_None;
msal_config.adc_data_align = ADC_DataAlign_Right;
/* Digital inputs configuration: interrupts disabled */
msal_config.input_p4_mode = GPIO_Mode_IN_FLOATING;
msal_config.input_p5_mode = GPIO_Mode_Out_OD;
if (USE_INTERRUPT == 1){
}else{
}
/* Initialize MSAL board */
if (TSMART_MSAL_Init(&tsmart_msal, &msal_config)!= TSMART_PASS){
return TSMART_FAIL;
}
/* UART2 configuration: used for debugging */
tsmart_uart_config.baud_rate = UART_BAUD_RATE;
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 = UART_BUF_SZ;
tsmart_uart_config.rx_buf = uart_buf;
tsmart_uart_config.use_dma = TSMART_UART_DMA_RX_TX;
tsmart_uart_config.use_tim = TSMART_UART_TIM_SW;
TSMART_UART_Init(&DEBUG_UART, &tsmart_uart_config);
/* ************************************************************************* */
/* Application task */
/* ************************************************************************* */
/* This example will need one task:
*
* - MSAL_VOLTAGE task: This task turns on the digital module of the MSAL
* board, reads the value and prints it into the UART2.
*
*/
/* Create MSAL_VOLTAGE Task */
xReturn = xTaskCreate(vMSAL_DIGITAL, "MSAL_DIGITAL", 512, NULL, 7, NULL);
if (xReturn != pdPASS) {
return TSMART_FAIL;
}
/* Everything OK */
return TSMART_PASS;
}