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.

Sensor Controller in CCS Project

I have generated the code for the SCE with Sensor Controller Studio that implements SPI communication and toggles led's to indicate that the code is executing. I have run the code in SCS and it works. I added the files to my TI-RTOS CCS project that is already functioning correctly. I added the following functions to my initialisation:

	scifOsalInit();
	scifOsalRegisterTaskAlertCallback(sciCallback);
	scifInit(&scifDriverSetup);
	scifStartRtcTicksNow(0x100);

The application runs but my task alert callback routine never executes. No flashing led's or SPI coms on the scope either so the SCE is definitely not running. What am I missing?

Cameron

  • Hi Cameron,

    Can you share more details around the code snippet + your Sensor Controller Studio project file? It is hard to say what is wrong based on your code snippet. Are you starting the task itself somewhere else?

    Regards,
    Svend
  • Hi Svend,

    I left off the line where I start the task, sorry. I have tried this with my altered SimpleBLEPeripheral project but when it didn't work I tried a more simple project. It has one task that executes a while loop and simply increments a counter.  My main function is as follows:

      int main(void) 
    {
    	/* Call board init functions */
    	Board_initGeneral();
    
    	scifOsalInit();
    	scifOsalRegisterTaskAlertCallback(sciCallback);
    	scifInit(&scifDriverSetup);
    	scifStartRtcTicksNow(0x100);
    	scifStartTasksNbl(SCIF_SPICOMS_TASK_ID);
    
    	System_printf("Start BIOS.\n");
    	/* SysMin will only print to the console when you call flush or exit */
    	System_flush();
    
    	/* Start BIOS */
    	BIOS_start();
    
    	return (0);
    }

    The project I used had the task "created statically":

    /*
    * ======== echoFxn ========
    * Task for this function is created statically. See the project's .cfg file.
    */

    My sensor controller code is simple. The initilization code sets up an interrupt:

    evhSetupGpioTrigger(0, AUXIO_I_INT2, 1, EVH_GPIO_TRIG_ON_MATCH);

    It then communicates with an accelerometer and flashes an led whether initialization was successful or not. The event handler code retrieves samples from the accelerometer. Execution code does the same as the event handler, my application does not require any execution code, I used it to see if RTC scheduling would fix the problem. I have no termination code.

    The idea is that even if the event handler code is never called and the RTC scheduling doesn't work, an led will blink during initialization.

    My project file as .txt:

    <?xml version="1.0"?>
    <project name="AcellSPI" version="1.1.0.38192">
        <desc><![CDATA[]]></desc>
        <pattr name="Board">None</pattr>
        <pattr name="Chip name">CC2640</pattr>
        <pattr name="Chip package">QFN48 7x7 RGZ</pattr>
        <pattr name="Chip revision">-</pattr>
        <pattr name="Code prefix"></pattr>
        <pattr name="Operating system">TI-RTOS</pattr>
        <pattr name="Output directory">.</pattr>
        <task name="SPIComs">
            <desc><![CDATA[]]></desc>
            <tattr name="AREAD" type="hex" content="const" scope="task" min="0000" max="ffff">000b</tattr>
            <tattr name="ASTATUS" type="hex" content="const" scope="task" min="0000" max="ffff">000b</tattr>
            <tattr name="AWRITE" type="hex" content="const" scope="task" min="0000" max="ffff">000a</tattr>
            <tattr name="BUFFER_SIZE" type="dec" content="const" scope="task" min="0" max="65535">512</tattr>
            <tattr name="FIFO" type="hex" content="const" scope="task" min="0000" max="ffff">000d</tattr>
            <tattr name="FIFO_CTL" type="hex" content="const" scope="task" min="0000" max="ffff">0028</tattr>
            <tattr name="FIFO_SAM" type="hex" content="const" scope="task" min="0000" max="ffff">0029</tattr>
            <tattr name="FILTER_CTL" type="hex" content="const" scope="task" min="0000" max="ffff">002c</tattr>
            <tattr name="FSTATUS" type="hex" content="const" scope="task" min="0000" max="ffff">00d7</tattr>
            <tattr name="INTMAP2" type="hex" content="const" scope="task" min="0000" max="ffff">002b</tattr>
            <tattr name="POWER_CTL" type="hex" content="const" scope="task" min="0000" max="ffff">002d</tattr>
            <tattr name="RBUF1" type="hex" content="const" scope="task" min="0000" max="ffff">00d1</tattr>
            <tattr name="WBUF1" type="hex" content="const" scope="task" min="0000" max="ffff">0084</tattr>
            <tattr name="X8" type="hex" content="const" scope="task" min="0000" max="ffff">0008</tattr>
            <tattr name="Y8" type="hex" content="const" scope="task" min="0000" max="ffff">0009</tattr>
            <tattr name="Z8" type="hex" content="const" scope="task" min="0000" max="ffff">000a</tattr>
            <tattr name="output.fstatus" type="hex" content="struct" scope="task" min="0000" max="ffff">0000</tattr>
            <tattr name="output.status" type="hex" content="struct" scope="task" min="0000" max="ffff">0000</tattr>
            <tattr name="output.x" type="dec" content="struct" scope="task" min="-32768" max="32767">0</tattr>
            <tattr name="output.y" type="dec" content="struct" scope="task" min="-32768" max="32767">0</tattr>
            <tattr name="output.z" type="dec" content="struct" scope="task" min="-32768" max="32767">0</tattr>
            <resource_ref name="ADC" enabled="0"/>
            <resource_ref name="Analog Open-Drain Pins" enabled="0"/>
            <resource_ref name="Analog Open-Source Pins" enabled="0"/>
            <resource_ref name="Analog Pins" enabled="0"/>
            <resource_ref name="COMPA" enabled="0"/>
            <resource_ref name="Delay Insertion" enabled="0"/>
            <resource_ref name="Differential Output Pins" enabled="0"/>
            <resource_ref name="Digital Input Pins" enabled="1">
                <io_usage name="INT2" label="Acceleromter Interrupt">
                    <uattr name="Configuration on initialization">-1</uattr>
                    <uattr name="Configuration on uninitialization">-1</uattr>
                    <uattr name="Pin count">0</uattr>
                    <uattr name="Pin/0000">DIO7</uattr>
                    <uattr name="Pin/0001"></uattr>
                    <uattr name="Pin/0002"></uattr>
                    <uattr name="Pin/0003"></uattr>
                    <uattr name="Pin/0004"></uattr>
                    <uattr name="Pin/0005"></uattr>
                    <uattr name="Pin/0006"></uattr>
                    <uattr name="Pin/0007"></uattr>
                    <uattr name="Pin/0008"></uattr>
                    <uattr name="Pin/0009"></uattr>
                    <uattr name="Pin/0010"></uattr>
                    <uattr name="Pin/0011"></uattr>
                    <uattr name="Pin/0012"></uattr>
                    <uattr name="Pin/0013"></uattr>
                    <uattr name="Pin/0014"></uattr>
                    <uattr name="Pin/0015"></uattr>
                </io_usage>
            </resource_ref>
            <resource_ref name="Digital Open-Drain Pins" enabled="0"/>
            <resource_ref name="Digital Open-Source Pins" enabled="0"/>
            <resource_ref name="Digital Output Pins" enabled="1">
                <io_usage name="LED1" label="LED1">
                    <uattr name="Configuration on uninitialization">0</uattr>
                    <uattr name="Output value on initialization">0</uattr>
                    <uattr name="Pin count">0</uattr>
                    <uattr name="Pin/0000">DIO25</uattr>
                    <uattr name="Pin/0001"></uattr>
                    <uattr name="Pin/0002"></uattr>
                    <uattr name="Pin/0003"></uattr>
                    <uattr name="Pin/0004"></uattr>
                    <uattr name="Pin/0005"></uattr>
                    <uattr name="Pin/0006"></uattr>
                    <uattr name="Pin/0007"></uattr>
                    <uattr name="Pin/0008"></uattr>
                    <uattr name="Pin/0009"></uattr>
                    <uattr name="Pin/0010"></uattr>
                    <uattr name="Pin/0011"></uattr>
                    <uattr name="Pin/0012"></uattr>
                    <uattr name="Pin/0013"></uattr>
                    <uattr name="Pin/0014"></uattr>
                    <uattr name="Pin/0015"></uattr>
                </io_usage>
                <io_usage name="LED2" label="LED2">
                    <uattr name="Configuration on uninitialization">0</uattr>
                    <uattr name="Output value on initialization">0</uattr>
                    <uattr name="Pin count">0</uattr>
                    <uattr name="Pin/0000">DIO26</uattr>
                    <uattr name="Pin/0001"></uattr>
                    <uattr name="Pin/0002"></uattr>
                    <uattr name="Pin/0003"></uattr>
                    <uattr name="Pin/0004"></uattr>
                    <uattr name="Pin/0005"></uattr>
                    <uattr name="Pin/0006"></uattr>
                    <uattr name="Pin/0007"></uattr>
                    <uattr name="Pin/0008"></uattr>
                    <uattr name="Pin/0009"></uattr>
                    <uattr name="Pin/0010"></uattr>
                    <uattr name="Pin/0011"></uattr>
                    <uattr name="Pin/0012"></uattr>
                    <uattr name="Pin/0013"></uattr>
                    <uattr name="Pin/0014"></uattr>
                    <uattr name="Pin/0015"></uattr>
                </io_usage>
            </resource_ref>
            <resource_ref name="GPIO Event Trigger" enabled="1"/>
            <resource_ref name="I2C Master" enabled="0">
                <rattr name="SCL frequency">0</rattr>
                <rattr name="SCL stretch timeout">1</rattr>
                <io_usage>
                    <uattr name="SCL pin/0000"></uattr>
                    <uattr name="SDA pin/0000"></uattr>
                </io_usage>
            </resource_ref>
            <resource_ref name="ISRC" enabled="0"/>
            <resource_ref name="Math and Logic" enabled="0"/>
            <resource_ref name="Multi-Buffered Output Data Exchange" enabled="0">
                <rattr name="Buffer count">2</rattr>
            </resource_ref>
            <resource_ref name="Peripheral Sharing" enabled="0"/>
            <resource_ref name="RTC Multi-Event Capture" enabled="0"/>
            <resource_ref name="RTC-Based Execution Scheduling" enabled="1"/>
            <resource_ref name="SPI Chip Select" enabled="1">
                <io_usage name="CS1" label="Accelerometer Chip Select">
                    <uattr name="CSN pin/0000">DIO6</uattr>
                </io_usage>
                <io_usage name="CS2" label="Flash Chip Select">
                    <uattr name="CSN pin/0000">DIO3</uattr>
                </io_usage>
            </resource_ref>
            <resource_ref name="SPI Data Transfer" enabled="1">
                <rattr name="MISO configuration when inactive">0</rattr>
                <rattr name="MOSI configuration on initialization">0</rattr>
                <rattr name="MOSI configuration on uninitialization">-1</rattr>
                <rattr name="SCLK configuration on initialization">0</rattr>
                <rattr name="SCLK configuration on uninitialization">0</rattr>
                <io_usage>
                    <uattr name="MISO pin/0000">DIO1</uattr>
                    <uattr name="MOSI pin/0000">DIO2</uattr>
                    <uattr name="SCLK pin/0000">DIO5</uattr>
                </io_usage>
            </resource_ref>
            <resource_ref name="System CPU Alert" enabled="0"/>
            <resource_ref name="TDC" enabled="0"/>
            <resource_ref name="Timer Event Trigger" enabled="0"/>
            <resource_ref name="UART Emulator" enabled="0">
                <rattr name="RX buffer size">64</rattr>
                <rattr name="Required idle period before enabling RX">11</rattr>
                <rattr name="TX buffer size">64</rattr>
                <io_usage>
                    <uattr name="RX pin/0000"></uattr>
                    <uattr name="TX pin/0000"></uattr>
                </io_usage>
            </resource_ref>
            <sccode name="event0"><![CDATA[//U16 n = 0;
    spiBegin(SPI_POL0_PHA0, AUXIO_SPI_CSN_CS1);
    spiTx8bit(SPI_POL0_PHA0, AREAD);
    spiTx8bit(SPI_POL0_PHA0, X8);
    
    spiRx8bit(SPI_POL0_PHA0; output.x);
    spiRx8bit(SPI_POL0_PHA0; output.y);
    spiRx8bit(SPI_POL0_PHA0; output.z);
    
    spiEnd(SPI_POL0_PHA0, AUXIO_SPI_CSN_CS1);
    
    spiBegin(SPI_POL0_PHA0, AUXIO_SPI_CSN_CS1);
    spiTx8bit(SPI_POL0_PHA0, AREAD);
    spiTx8bit(SPI_POL0_PHA0, ASTATUS);
    spiRx8bit(SPI_POL0_PHA0; output.status);
    spiEnd(SPI_POL0_PHA0, AUXIO_SPI_CSN_CS1);
    
    
    //for (U16 n = 0; n < CONSTANT; n++)
    //n += 1;]]></sccode>
            <sccode name="execute"><![CDATA[spiBegin(SPI_POL0_PHA0, AUXIO_SPI_CSN_CS1);
    spiTx8bit(SPI_POL0_PHA0, AREAD);
    spiTx8bit(SPI_POL0_PHA0, X8);
    
    spiRx8bit(SPI_POL0_PHA0; output.x);
    spiRx8bit(SPI_POL0_PHA0; output.y);
    spiRx8bit(SPI_POL0_PHA0; output.z);
    
    spiEnd(SPI_POL0_PHA0, AUXIO_SPI_CSN_CS1);
    
    spiBegin(SPI_POL0_PHA0, AUXIO_SPI_CSN_CS1);
    spiTx8bit(SPI_POL0_PHA0, AREAD);
    spiTx8bit(SPI_POL0_PHA0, ASTATUS);
    spiRx8bit(SPI_POL0_PHA0; output.status);
    spiEnd(SPI_POL0_PHA0, AUXIO_SPI_CSN_CS1);
    
    fwScheduleTask(1);]]></sccode>
            <sccode name="initialize"><![CDATA[U16 n = 0;
    
    evhSetupGpioTrigger(0, AUXIO_I_INT2, 1, EVH_GPIO_TRIG_ON_MATCH);
    
    spiBegin(SPI_POL0_PHA0, AUXIO_SPI_CSN_CS1);
    spiTx8bit(SPI_POL0_PHA0, AWRITE);
    spiTx8bit(SPI_POL0_PHA0, INTMAP2);
    spiTx8bit(SPI_POL0_PHA0, 0x1);
    spiEnd(SPI_POL0_PHA0, AUXIO_SPI_CSN_CS1);
    
    spiBegin(SPI_POL0_PHA0, AUXIO_SPI_CSN_CS1);
    spiTx8bit(SPI_POL0_PHA0, AWRITE);
    spiTx8bit(SPI_POL0_PHA0, POWER_CTL);
    spiTx8bit(SPI_POL0_PHA0, 2);
    spiEnd(SPI_POL0_PHA0, AUXIO_SPI_CSN_CS1);
    
    spiBegin(SPI_POL0_PHA0, AUXIO_SPI_CSN_CS1);
    spiTx8bit(SPI_POL0_PHA0, AREAD);
    spiTx8bit(SPI_POL0_PHA0, POWER_CTL);
    spiRx8bit(SPI_POL0_PHA0; output.status);
    spiEnd(SPI_POL0_PHA0, AUXIO_SPI_CSN_CS1);
    
    if (output.status == 2) {
        gpioGenPulseTrain(AUXIO_O_LED2, 1, 100, 10, 30000);
    }
    
    spiBegin(SPI_POL0_PHA0, AUXIO_SPI_CSN_CS2);
    spiTx8bit(SPI_POL0_PHA0, FSTATUS);
    spiRx8bit(SPI_POL0_PHA0; output.fstatus);
    spiEnd(SPI_POL0_PHA0, AUXIO_SPI_CSN_CS2);
    
    if (output.fstatus != 0) {
        gpioGenPulseTrain(AUXIO_O_LED1, 1, 100, 10, 30000);
    }
    
    spiBegin(SPI_POL0_PHA0, AUXIO_SPI_CSN_CS1);
    spiTx8bit(SPI_POL0_PHA0, AREAD);
    spiTx8bit(SPI_POL0_PHA0, ASTATUS);
    spiRx8bit(SPI_POL0_PHA0; output.status);
    spiEnd(SPI_POL0_PHA0, AUXIO_SPI_CSN_CS1);
    
    fwScheduleTask(1);]]></sccode>
            <sccode name="terminate"><![CDATA[if (output.status == 2) {
        gpioGenPulseTrain(AUXIO_O_LED1, 1, 100, 10, 30000);
    }]]></sccode>
            <tt_iter>run_execute,if_event0trigen_start,if_event0trigen_end,run_event0</tt_iter>
            <tt_struct>output.x,output.y,output.z</tt_struct>
        </task>
    </project>
    

  • The project file is not included in the post.

    You might need to run the initialization in a TI RTOS context as it sets up semaphores and such.

    Also note that:
    - scifStartRTC* is not needed if you don't have any RTC based execution code in SCS (you should remove RTC-based scheduling as a resource)
    - Interrupts to the M3 are not set until after the SC task finishes executing (it will be set by the framework after progam is done running.

  • Looking through the code it seems you run the execution code (fwScheduleTask) periodically and you do have some RTC-based execution code in there as well as having some termination code.
    Anyway, to generate an alert to the system CPU you should also include the "System CPU Alert" or "Multi-buffered output data exchange" resource and use the API from one of those to generate the alert.

    Regards,
    Svend
  • Okay... I am not really sure how to do that. I thought that this function sorted that out:

    /** \brief OSAL "TI-RTOS": Initializes the OSAL
      *
      * This creates a binary semaphore used to wait on the task control interface.
      *
      * This function must be called once at startup before using the task control functions:
      * - \ref scifStartTasksNbl()
      * - \ref scifStopTasksNbl()
      * - \ref scifWaitOnNbl()
      */
    void scifOsalInit(void) {
        // Create a binary semaphore, initially blocked.
        Semaphore_Params semParams;
        Semaphore_Params_init(&semParams);
        semParams.mode = Semaphore_Mode_BINARY;
        Semaphore_construct(&semCtrlReady, 0, &semParams);
    } // scifOsalInit

    I have now added a  task control ready callback:

    scifOsalRegisterCtrlReadyCallback(sciReadyCallback);

    After it gets called it starts the task:

    scifStartTasksNbl(SCIF_SPICOMS_TASK_ID);

    After the above function is called I can see that the task control ready callback is called once again. Still the task does not actually execute.

    Just to respond to your notes:

    - Although I ultimately do not need RTC scheduling, I have used it in my Sensor controller project for now.

    - I don't actually have any CPU interrupts, the sensor controller is supposed to collect data and save it to external flash memory. The interrupt I mentioned is actually just a GPIO event that calls the event handler to retrieve data from the acceleromter.

  • So you're saying the task alert callback won't execute because I am not using "System CPU Alert" or "Multi-buffered output data exchange" resourses. That's okay but I still can't work out why the task isn't executing (no leds flashing).

    It is telling me that task control is ready and it seems to register that I am starting the task since the task control ready callback is called again after scifStartTasksNbl(SCIF_SPICOMS_TASK_ID) is called.

    Is it possible that the Sensor Controller is unable to drive pins that I have initialized in my BoardGpioInitTable?