This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

RTOS/LAUNCHXL-CC2650: Ti-RTOS abruptly stops

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(&params);
    //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, &params);

        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.
    }
}

  • Hi,

    Here are a couple things to try:

    1. Modify period of clk1Fxn.
    2. Check statuses returned by UART_write. If status is UART_ERROR, then that could be part of the problem.


    Regards,
    Toby
  • Perhaps halt your target and look at your task's call stack in ROV to see at what function you're blocked on.
  • Hi,
    Apologies for late reply.
    Modifying the period to 1miliSec (clkParams.period = 1000/Clock_tickPeriod; )  made it run smoothly (Ran it for more than 10 minutes and it was still working)
    Can you help me understand what is the case here.

  • When i halt the targeti get the following messege.

    "Can't find a source file at "/db/vtree/ademars/git_trees/avala-v/src/ti/sysbios/family/arm/m3/Hwi.c"

    Locate the file or edit the source lookup path to include its location."

    I have also attached the ROV snapshot.

    Above snap is when it works normally and the image below is when it halts.

  • Hi,

    I'm not sure where the bug could be, but...

    Taking another look at the Clock module documentation [1], the clock functions are called in context of SWI. The default UART write mode is UART_MODE_BLOCKING, so UART_write should be called in context of a Task.

    You may want to try modifying your code so that you have a task that does the ADC sampling and UART write. The task should pend on a semaphore. All the clock function should do is post to this semaphore at your desired period.

    [1] <sdk>\products\bios_6_46_01_37\docs\Bios_APIs.html ( click ti.sysbios.knl to access module docs )


    Regards,
    Toby