Part Number: LAUNCHXL-CC2650
Other Parts Discussed in Thread: SYSBIOS
Tool/software: TI-RTOS
Hi,
I am trying my hands on RTOS and playing around with examples.
The code works for random time (ranging from 1 to 10 seconds) and abruptly stops.
Looking forward to guidance.
/*
* ======== clock.c ========
*/
/* XDC module Headers */
#include <xdc/std.h>
#include <xdc/runtime/System.h>
/* BIOS module Headers */
#include <ti/sysbios/BIOS.h>
#include <ti/sysbios/knl/Clock.h>
//#include <ti/sysbios/knl/Task.h>
#include <ti/drivers/ADC.h>
#include <ti/drivers/PIN.h>
#include <ti/drivers/UART.h>
/* Example/Board Header files */
#include "Board.h"
#include <stdint.h>
#include <stdio.h>
Void clk0Fxn(UArg arg0);
Void clk1Fxn(UArg arg0);
Void echoFxn();
/* ADC sample count */
#define ADC_SAMPLE_COUNT (3)
#define HIGH 1
#define LOW 0
/* ADC conversion result variables */
uint16_t adcValue0;
uint16_t adcValue1[ADC_SAMPLE_COUNT];
Clock_Struct clk0Struct, clk1Struct;
Clock_Handle clk2Handle;
/* Pin driver handle */
static PIN_Handle ledPinHandle;
static PIN_State ledPinState;
UART_Handle uart;
UART_Params uartParams;
ADC_Handle adc;
ADC_Params params;
int_fast16_t res;
PIN_Config ledPinTable[] = {
Board_LED0 | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL | PIN_DRVSTR_MAX,
Board_LED1 | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL | PIN_DRVSTR_MAX,
PIN_TERMINATE
};
//Different states of TSL1401 sensor
enum sensorState{
DATA_PROCUREMENT,
INTEGRATION_WAIT
};
enum sensorState sensorDataState = DATA_PROCUREMENT ;
/*
* ======== main ========
*/
Int main()
{
/* Construct BIOS Objects */
Clock_Params clkParams;
/* Call board init functions */
Board_initGeneral();
Board_initADC();
Board_initUART();
/* Open LED pins */
ledPinHandle = PIN_open(&ledPinState, ledPinTable);
if(!ledPinHandle) {
System_abort("Error initializing board LED pins\n");
}
PIN_setOutputValue(ledPinHandle, Board_LED0, 1);
PIN_setOutputValue(ledPinHandle, Board_LED1, 1);
System_printf("Starting the HWI example.\n"
"Halt the target to view any SysMin contents in ROV.\n");
/* SysMin will only print to the console when you call flush or exit */
System_flush();
Clock_Params_init(&clkParams);
clkParams.period = 0;
clkParams.startFlag = TRUE;
/* Construct a one-shot Clock Instance */
Clock_construct(&clk0Struct, (Clock_FuncPtr)clk0Fxn,
5000/Clock_tickPeriod, &clkParams);
clkParams.period = 300/Clock_tickPeriod;;
clkParams.startFlag = FALSE;
/* Construct a periodic Clock Instance */
Clock_construct(&clk1Struct, (Clock_FuncPtr)clk1Fxn,
11000/Clock_tickPeriod, &clkParams);
clk2Handle = Clock_handle(&clk1Struct);
Clock_start(clk2Handle);
BIOS_start(); /* does not return */
return(0);
}
/*
* ======== echoFxn ========
* Task for this function is created statically. See the project's .cfg file.
*/
Void echoFxn()
{
const char echoPrompt[] = "\fData procurement\r\n";
/* Create a UART with data processing off. */
UART_Params_init(&uartParams);
uartParams.writeDataMode = UART_DATA_BINARY;
uartParams.readDataMode = UART_DATA_BINARY;
uartParams.readReturnMode = UART_RETURN_FULL;
uartParams.readEcho = UART_ECHO_OFF;
uartParams.baudRate = 115200;
uart = UART_open(Board_UART0, &uartParams);
if (uart == NULL) {
System_abort("Error opening the UART");
}
UART_write(uart, echoPrompt, sizeof(echoPrompt));
}
/*
* ======== clk0Fxn =======
*/
Void clk0Fxn(UArg arg0)
{
//One shot function to display information
echoFxn();
ADC_Params_init(¶ms);
//Integration_time(); //Getting Integration time from POT at start of program.
}
/*
* ======== clk1Fxn =======
*/
Void clk1Fxn(UArg arg0)
{
static uint16_t clockCount=0;
static char data[7];
const char integrationTime[] = ">1500\r\n";
if(sensorDataState == DATA_PROCUREMENT){
if(clockCount == 0){
PIN_setOutputValue(ledPinHandle, Board_LED0,HIGH); //SI of TSL1401
//sprintf(data,">%d\n\r",1500); //1500 is value taken from Processing program.
//UART_write(uart,data,sizeof(data));
UART_write(uart, integrationTime, sizeof(integrationTime));
}
else if(clockCount >= 1){
PIN_setOutputValue(ledPinHandle, Board_LED0,LOW); //SI of TSL1401
}
PIN_setOutputValue(ledPinHandle, Board_LED1,HIGH); //Clock of TSL1401
adc = ADC_open(Board_ADC1, ¶ms);
if (adc == NULL) {
System_abort("Error initializing ADC channel 0\n");
System_flush();
}
/* Blocking mode conversion */
res = ADC_convert(adc, &adcValue0);
if (res != ADC_STATUS_SUCCESS) {
System_printf("ADC channel 0 convert failed\n");
}
ADC_close(adc);
PIN_setOutputValue(ledPinHandle, Board_LED1,LOW); //Clock of TSL1401
sprintf(data,"%d\n\r",adcValue0);
UART_write(uart,data,sizeof(data));
if(clockCount > 128){
sensorDataState = INTEGRATION_WAIT;
}
}
clockCount++;
if(sensorDataState == INTEGRATION_WAIT){
if(clockCount >= 133){
sensorDataState = DATA_PROCUREMENT;
clockCount=0;
}
else
{
;
}
//Task_sleep(10/Clock_tickPeriod); //10 usec delay.
}
}