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.

Merging two example codes from CC1310

Other Parts Discussed in Thread: CC1310, SYSBIOS

Hi all,

I'm really new to microprocessors and, subsequently, to the TI-RTOS environment. I'm trying to merge two of the examples together, the adcbuffcontinuous and the PER, so I can send the values read in the ADC of my TX CC1310 and send the values to my RX CC1310. I've got two problems while trying that: first, how to properly merge the two examples (which I believe I can figure out). Second, and this is the most important thing to me, is how to make the tasks run in a loop. It appears the PER sends x packets and then completely stops (I'm using it as base). How do I "jump" from task to task without letting the program come to a halt? I hope I was clear.

cheers,

Pedro

  • Pedro Henrique Fonseca said:
    first, how to properly merge the two examples (which I believe I can figure out).

    You may need to copy the relevant code from one of the examples sources to the other. Along with c code, you would also need to copy the RTOS configuration from .cfg file to the other .cfg file.

    Pedro Henrique Fonseca said:
    Second, and this is the most important thing to me, is how to make the tasks run in a loop. It appears the PER sends x packets and then completely stops (I'm using it as base). How do I "jump" from task to task without letting the program come to a halt?

    Which version of TI-RTOS are you using? I can't find the PER example. From your description, it looks like the Task completed it's work and exited. Once the Task function exits, the task will move to a terminated state. If you are planning to repeat the steps in the Task, you probably will need some sort of loop in your Task function and make sure it does not exit the function.

    To switch from one Task to another,  the currently running task should either block (pend on a semaphore or call Task_sleep()) or be interrupted. You can find more information about kernel features in TI-RTOS Kernel (SYS/BIOS) user guide. I would also recommend looking through the various examples in TI-RTOS to familiarize yourself with TI-RTOS API usage.

    Hope this helps,

    Vikram 

  • Thank you for you prompt reply, Vikram. I'been researching a lot since yesterday and I believe you put me in the right way. I'll try that. Thank you!

  • Could you help me understand how to create a semaphore? The User guide is not thorough explaining it and I couldn't replicate the examples. I'm using the empty example to understand how these things work, so I just want to constantly print messages from the tasks. Here is the code. Thanks in advance!

    /*
    * Copyright (c) 2015-2016, Texas Instruments Incorporated
    * All rights reserved.
    *
    * Redistribution and use in source and binary forms, with or without
    * modification, are permitted provided that the following conditions
    * are met:
    *
    * * Redistributions of source code must retain the above copyright
    * notice, this list of conditions and the following disclaimer.
    *
    * * Redistributions in binary form must reproduce the above copyright
    * notice, this list of conditions and the following disclaimer in the
    * documentation and/or other materials provided with the distribution.
    *
    * * Neither the name of Texas Instruments Incorporated nor the names of
    * its contributors may be used to endorse or promote products derived
    * from this software without specific prior written permission.
    *
    * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
    * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
    * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
    * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
    * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
    * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
    * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
    * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
    * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
    * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
    * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    */

    /*
    * ======== empty.c ========
    */
    /* XDCtools Header files */
    #include <xdc/std.h>
    #include <xdc/runtime/System.h>
    #include <xdc/runtime/Assert.h>

    /* BIOS Header files */
    #include <ti/sysbios/BIOS.h>
    #include <ti/sysbios/knl/Clock.h>
    #include <ti/sysbios/knl/Task.h>

    /* TI-RTOS Header files */
    // #include <ti/drivers/I2C.h>
    #include <ti/drivers/PIN.h>
    // #include <ti/drivers/SPI.h>
    // #include <ti/drivers/UART.h>
    // #include <ti/drivers/Watchdog.h>

    /* Board Header files */
    #include "Board.h"

    /* C library */
    #include <stdio.h>

    #define TASKSTACKSIZE 512

    Task_Struct task0Struct;
    Char task0Stack[TASKSTACKSIZE];

    Task_Struct task1Struct;
    Char task1Stack[TASKSTACKSIZE];

    Task_Struct task2Struct;
    Char task2Stack[TASKSTACKSIZE];

    char mensagem[] = "you are in task: ";

    /* Pin driver handle */
    static PIN_Handle ledPinHandle;
    static PIN_State ledPinState;

    /* Declaration of semaphore */
    static Semaphore_Struct semaphore;
    static Semaphore_Handle semaphoreHandle;

    /*
    * ======== heartBeatFxn ========
    * Toggle the Board_LED0. The Task_sleep is determined by arg0 which
    * is configured for the heartBeat Task instance.
    */
    /*void heartBeatFxn(UArg arg0, UArg arg1)
    {
    while (1) {
    Task_sleep((UInt)arg0);
    PIN_setOutputValue(ledPinHandle, Board_LED0,
    !PIN_getOutputValue(Board_LED0));
    }
    }*/

    void taskPrint0(UArg arg0, UArg arg1)
    {
    int i=0;
    while(1) {
    Semaphore_pend(semaphore,BIOS_WAIT_FOREVER);
    printf("%s:%d\n",mensagem,i);
    Semaphore_post(semaphore);
    }
    }

    void taskPrint1(UArg arg0, UArg arg1)
    {
    int j=1;
    while(1) {
    Semaphore_pend(semaphore,BIOS_WAIT_FOREVER);
    printf("%s:%d\n",mensagem,j);
    Semaphore_post(semaphore);
    }
    }


    /*
    * ======== main ========
    */
    int main(void)
    {
    Task_Params taskParams;

    /* Call board init functions */
    Board_initGeneral();
    // Board_initI2C();
    // Board_initSPI();
    // Board_initUART();
    // Board_initWatchdog();

    /* Construct heartBeat Task thread
    Task_Params_init(&taskParams);
    taskParams.arg0 = 1000000 / Clock_tickPeriod;
    taskParams.stackSize = TASKSTACKSIZE;
    taskParams.stack = &task0Stack;
    Task_construct(&task0Struct, (Task_FuncPtr)heartBeatFxn, &taskParams, NULL);*/

    /* \Create Semaphore */
    Semaphore_construct(&semaphore, 0, NULL);
    semaphoreHandle = Semaphore_handle(&semaphore);

    /* Construct Printf0 task thread */
    Task_Params_init(&taskParams);
    taskParams.stackSize = TASKSTACKSIZE;
    taskParams.stack = &task1Stack;
    Task_construct(&task1Struct, (Task_FuncPtr)taskPrint0, &taskParams, NULL);

    /* Construct Printf0 task thread */
    Task_Params_init(&taskParams);
    taskParams.stackSize = TASKSTACKSIZE;
    taskParams.stack = &task2Stack;
    Task_construct(&task2Struct, (Task_FuncPtr)taskPrint1, &taskParams, NULL);

    /* Open LED pins
    ledPinHandle = PIN_open(&ledPinState, ledPinTable);
    if(!ledPinHandle) {
    System_abort("Error initializing board LED pins\n");
    }

    PIN_setOutputValue(ledPinHandle, Board_LED1, 1);*/

    System_printf("Starting the example\nSystem provider is set to SysMin. "
    "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();

    /* Start BIOS */
    BIOS_start();

    return (0);
    }


    I get the errors that Semaphore_Handle and Semaphore_Struct are not defined, but I thought they were defined in the Semaphore.h file.

    Pedro
  • Also hwne I say PER I mean the packet error rate example.
  • FORGET ABOUT THIS!

    I made it work. Was missing the include on Semaphore.h (what a dumb guy hahaha). Now it works fine =)