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: How to get sensor controller task running w/CCS like it is in Sensor Controller Studio?

Other Parts Discussed in Thread: CC1310, SYSBIOS

Tool/software: TI-RTOS

An I2C sensor is running well and looping in Sensor Controller Studio as shown below: initialization code, and task looping logic. SCS code is exported and compiles in CCS. The CCS program load triggers the same initialization logic as does the SCS initialization logic. However, I cannot start the task loop in CCS. I2C remains quiet, and no active logic is occuring with I2C. The 'sensor controller studio project from scratch' ADC task is working fine. (FYIO there is a typo in the lab manual - screen shot below)

Sensor Controller Studio Initialization Code

Code Composer Studio program load

Sensor Controller Studio - running task

 

 (there is a typo in the tutorial.... main_tirtos.c file should be 'empty.c' instead. )


  • The I2C sensor controller initializes and the sensor returns the initialization 'OK' code 0x26. The execution task will not start nor loop.

    /*
     *  ======== main_tirtos.c ========
     */
    
    /* Example/Board Header files */
    #include "Board.h"
    
    #include <stdint.h>
    
    /* POSIX Header files */
    #include <pthread.h>
    
    /* RTOS header files */
    #include <ti/sysbios/BIOS.h>
    
    /* Stack size in bytes */
    #define THREADSTACKSIZE    1024
    
    /* Sensor Controller thread */
    extern void *tirtosScThread(void *arg0);
    
    /*
     *  ======== main ========
     */
    int main(void)
    {
        pthread_t           thread;
        pthread_attr_t      attrs;
        struct sched_param  priParam;
        int                 retc;
    
        /* Call driver init functions */
        Board_init();
    
        /* Initialize the attributes structure with default values */
        pthread_attr_init(&attrs);
    
        /* Set priority, detach state, and stack size attributes */
        priParam.sched_priority = 1;
        retc = pthread_attr_setschedparam(&attrs, &priParam);
        retc |= pthread_attr_setdetachstate(&attrs, PTHREAD_CREATE_DETACHED);
        retc |= pthread_attr_setstacksize(&attrs, THREADSTACKSIZE);
        if (retc != 0) {
            /* failed to set attributes */
            while (1) {}
        }
    
        retc = pthread_create(&thread, &attrs, tirtosScThread, NULL);
        if (retc != 0) {
            /* pthread_create() failed */
            while (1) {}
        }
    
        BIOS_start();
        // train left station!
    }

    /*
     *  ======== Sensor Controller ========
     */
    
    //  SCIF Driver Header File
    #include "scif.h"
    
    // SCIF Driver Callback Functions
    void scCtrlReadyCallback(void)
    { }
    void scTaskAlertCallback(void)
    { }
    
    // Initialize and Configure SCIF Driver
    void *tirtosScThread(void *arg0)
    {
        // Initialize the Sensor Controller
            scifOsalInit();
            scifOsalRegisterCtrlReadyCallback(scCtrlReadyCallback);
            scifOsalRegisterTaskAlertCallback(scTaskAlertCallback);
            scifInit(&scifDriverSetup);
    
            // Set the Sensor Controller task tick interval to 1 second
            uint32_t rtc_Hz = 1;  // 1Hz RTC
            scifStartRtcTicksNow(0x00010000 / rtc_Hz);
    
            
            // when SCIF_i2c_TASK_ID task is 0 and ADC is 1
            //Do one of the following:
            //•To start all tasks in the Sensor Controller project in one operation:
            // Start all Sensor Controller tasks
            //scifStartTasksNbl((1 << SCIF_i2c_TASK_ID) | (1 << SCIF_ADCLEVEL_TASK_ID));
            //•To start only the "SCIF_i2c_TASK_ID" task:
            // Start the "SCIF_i2c_TASK_ID" Sensor Controller task
            scifStartTasksNbl(1 << SCIF_i2c_TASK_ID);
            //To start only the "ADClevel" task:
            // Start the "ADClevel" Sensor Controller task
            //scifStartTasksNbl(1 << SCIF_ADCLEVEL_TASK_ID);
    
    
            // Configure Sensor Controller tasks
            //scifTaskData.adcLevelTrigger.cfg.threshold = 600;
    
            return (0);
    }

  • I'm not able to see any obvious mistakes. Are you able to post a minimum example (SCS + CCS code) which runs on a launchpad and show the issue?
  • ... when scifStartTasksNbl(foo) is called, why is only the initialization code in the scs task completed, and not the excecution code nor the termination code? Since the sensor is initiated and waiting for the excecution code in the task, how is the excecution code run, and then how is the termination code run?

    so perhaps the better question is:
    1. How is the SCS initialization code called? ANS : scifStartTasksNbl(1 << SCIF_i2c_TASK_ID);

    2. How is the SCS execution code called? ANS : ???

    3. How is the SCS termination code called? ANS : ???

    At this time the entire project resides in the sensor controller, from input to i2c sensor control to sensor control IO.




        // when SCIF_i2c_TASK_ID task is 0 and ADC is 1
            //Do one of the following:
            //•To start all tasks in the Sensor Controller project in one operation:
            // Start all Sensor Controller tasks
            //scifStartTasksNbl((1 << SCIF_i2c_TASK_ID) | (1 << SCIF_ADCLEVEL_TASK_ID));
            //•To start only the "SCIF_i2c_TASK_ID" task:
            // Start the "SCIF_i2c_TASK_ID" Sensor Controller task
            scifStartTasksNbl(1 << SCIF_i2c_TASK_ID);
            //To start only the "ADClevel" task:
            // Start the "ADClevel" Sensor Controller task
            //scifStartTasksNbl(1 << SCIF_ADCLEVEL_TASK_ID);

  • ... working w/ semaphore for tasking ???

  • The scif_how_to_use.html file that is generated by Sensor Controller Studio for your project describe in detail how you should include the Sensor Controller code with the rest of your project. If you follow this the code should be run correctly.

    Are you able to post a minimum example (SCS + CCS code) which runs on a launchpad and show the issue?
  • TER,

    the scif how to is helpful, and following the guide did not work.

    Is there a possibility the posix thread is interfering?

  • I still haven't gotten an answer if you are able to send a full example to us that shows the issue.
  • Unfortunately the only method to start a new CCS RTOS project for the CC1310 is to begin a hack on the empty.c sdk project, or open a new RTOS but with a different SOC. Starting with the empty.c places a posix thread in the code which is now obsolete. The empty.c project and the 'starting from scratch with sensor controller' lab was disorienting to me personally for some reason. Nomenclature for dsp/bios, sysbios, tirtos, rtos was confusing too! The tutorials and scif_how_to are great and wonderful (compared to years past) but are also fraught with inconsistent nomenclature: 'start' a task meant to me 'initialize, run and loop'. start could also mean execute. Going back to the scif_how-to like TER suggested and looking for the key nomenclature: initialization code, execution code, termination code was helpful. Then, porting all code from the empty.c file and finally deleting the empty.c file altogether and having all code reside in main_tirtos.c created a successful CCS project using the i2c sensor code fully debugged with Sensor Controller Studio.

    Perhaps changing nomenclature would help clarify scif porting to CCS. For example below I've crossed out and replaced nomenclature to better clarify the difference between Initialize, execute, terminate, and stop, start, reset.

    Start Initialize or Restart Reinitialize Sensor Controller Tasks

    Starting Initializing a Sensor Controller task triggers the Initialization code. The task is then active.

    After a Sensor Controller task has been stopped terminated (see below), you must reset clear the task's data structures before it can be restarted re-initialized. The scifResetTaskStructs() function will always reset the state data structure. You can optionally also reset the cfg, input and output data structures.

    Do the following to (re)start initialize a Sensor Controller task:

      • To start initialize or restart reinitialize the "adc Level Trigger" task:
    // Reset all data structures except configuration
    scifResetTaskStructs scifInitializeTaskStructs(1 << SCIF_ADC_LEVEL_TRIGGER_TASK_ID, (1 << SCIF_STRUCT_INPUT) | (1 << SCIF_STRUCT_OUTPUT));
    
    // (Re)start initialze the "adc Level Trigger" Sensor Controller task
    if (scifWaitOnNbl(20000) != SCIF_SUCCESS) {
        ... Handle timeout or usage error ...
    } else if (scifStartTasksNbl(1 << SCIF_ADC_LEVEL_TRIGGER_TASK_ID) != SCIF_SUCCESS) {
        ... Handle usage error ...
    }

    Stop Sensor Controller Tasks

    Stopping a Sensor Controller task triggers the Termination code. The task is then inactive.

    Do the following to stop terminate a Sensor Controller task:

      • To stop terminate the "adc Level Trigger" task:
    // Stop Run termination code for the "adc Level Trigger" Sensor Controller task
    if (scifWaitOnNbl(20000) != SCIF_SUCCESS) {
        ... Handle timeout or usage error ...
    } else if (scifStopTasksNblscifTerminateTasksNbl(1 << SCIF_ADC_LEVEL_TRIGGER_TASK_ID) != SCIF_SUCCESS) { ... Handle usage error ... }
    Run Sensor Controller Tasks Once

    Running a Sensor Controller task once triggers the Initialization Code, the Execution Code (one time), and the Termination Code.

    Do the following to run initialize, execute and terminate a Sensor Controller task once:

      • To run initialize, execute and terminate the "adc Level Trigger" task:
    // Run initialize, execute and terminate the "adc Level Trigger" Sensor Controller task
    if (scifWaitOnNbl(20000) != SCIF_SUCCESS) {
        ... Handle timeout or usage error ...
    } else if (scifExecuteInitExTermTasksOnceNbl(1 << SCIF_ADC_LEVEL_TRIGGER_TASK_ID) != SCIF_SUCCESS) {
        ... Handle usage error ...
    }

    One final observation, Osal is a HWI, not a thread. For me, the tutorials appeared to imply Osal is a thread.