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/CC3220SF-LAUNCHXL: Starting Simplelink with Task_create , pthreads

Part Number: CC3220SF-LAUNCHXL
Other Parts Discussed in Thread: CC3200

Tool/software: TI-RTOS

Background is I am converting a project from cc3200 that receives messages from pc that are encrypted aes, decrypts them, does something with the message, encrypts it, and sends it back to pc with sockets and ports. I have converted to versions for pthreads and tasks, but neither works. One question is whether Simplelink is started ? In the old version, Simplelink was started with

// Start the SimpleLink Host
//
lRetVal = VStartSimpleLinkSpawnTask(SPAWN_TASK_PRIORITY);
if(lRetVal < 0)
{
ERR_PRINT(lRetVal);
LOOP_FOREVER();
}

What is the new way to do in Task_create without using osi_compat.h?

  • Is this the way for pthreads?
    * * ======== main_tirtos.c ======== */ #include <stdint.h> /* POSIX Header files */ #include <pthread.h> /* RTOS header files */ #include <ti/sysbios/BIOS.h> /* Example/Board Header files */ #include "Board.h" // extern void *mainThread(void *arg0); /* Stack size in bytes */ #define THREADSTACKSIZE 2048 #define SPAWN_TASK_PRIORITY 9 //#include #include "aest.h" /* * ======== main ======== */ int main(void) { aest a0; pthread_t spawn_thread, thread_Srvr, thread_Msgr, thread_Sndr; pthread_attr_t pAttrs_spawn, pAttrs_Srvr, pAttrs_Msgr, pAttrs_Sndr; struct sched_param priParam, priParam_Srvr, priParam_Msgr, priParam_Sndr; int retc; int detachState; /* Call driver init functions */ Board_initGeneral(); /* Create the sl_Task */ pthread_attr_init(&pAttrs_spawn); priParam.sched_priority = SPAWN_TASK_PRIORITY ; retc = pthread_attr_setschedparam(&pAttrs_spawn, &priParam); retc |= pthread_attr_setstacksize(&pAttrs_spawn, THREADSTACKSIZE); retc |= pthread_attr_setdetachstate(&pAttrs_spawn, PTHREAD_CREATE_DETACHED); retc = pthread_create(&spawn_thread, &pAttrs_spawn, sl_Task, NULL); int iT_aes=10; /* Set priority and stack size attributes */ //pthread_attr_init(&pAttrs); //priParam.sched_priority = 1; pthread_attr_init(&pAttrs_Srvr); priParam_Srvr.sched_priority = iT_aes; pthread_attr_init(&pAttrs_Msgr); priParam_Msgr.sched_priority = iT_aes; pthread_attr_init(&pAttrs_Sndr); priParam_Sndr.sched_priority = iT_aes; detachState = PTHREAD_CREATE_DETACHED; // retc = pthread_attr_setdetachstate(&pAttrs, detachState); // if (retc != 0) { /* pthread_attr_setdetachstate() failed */ while (1);} // pthread_attr_setschedparam(&pAttrs, &priParam); // retc |= pthread_attr_setstacksize(&pAttrs, THREADSTACKSIZE); // if (retc != 0) { /* pthread_attr_setstacksize() failed */ while (1);} // retc = pthread_create(&thread, &pAttrs, mainThread, NULL); // if (retc != 0) { /* pthread_create() failed */ while (1);} retc = pthread_attr_setdetachstate(&pAttrs_Srvr, detachState); if (retc != 0) { /* pthread_attr_setdetachstate() failed */ while (1);} pthread_attr_setschedparam(&pAttrs_Srvr, &priParam_Srvr); retc |= pthread_attr_setstacksize(&pAttrs_Srvr, THREADSTACKSIZE); if (retc != 0) { /* pthread_attr_setstacksize() failed */ while (1);} retc = pthread_create(&thread_Srvr, &pAttrs_Srvr, aest::aesSrvr, NULL); if (retc != 0) { /* pthread_create() failed */ while (1);} retc = pthread_attr_setdetachstate(&pAttrs_Msgr, detachState); if (retc != 0) { /* pthread_attr_setdetachstate() failed */ while (1);} pthread_attr_setschedparam(&pAttrs_Msgr, &priParam_Msgr); retc |= pthread_attr_setstacksize(&pAttrs_Msgr, THREADSTACKSIZE); if (retc != 0) { /* pthread_attr_setstacksize() failed */ while (1);} retc = pthread_create(&thread_Msgr, &pAttrs_Msgr, aest::aesMsgr, NULL); if (retc != 0) { /* pthread_create() failed */ while (1);} retc = pthread_attr_setdetachstate(&pAttrs_Sndr, detachState); if (retc != 0) { /* pthread_attr_setdetachstate() failed */ while (1);} pthread_attr_setschedparam(&pAttrs_Sndr, &priParam_Sndr); retc |= pthread_attr_setstacksize(&pAttrs_Sndr, THREADSTACKSIZE); if (retc != 0) { /* pthread_attr_setstacksize() failed */ while (1);} retc = pthread_create(&thread_Sndr, &pAttrs_Sndr, aest::aesSndr, NULL); if (retc != 0) { /* pthread_create() failed */ while (1);} BIOS_start(); return (0);

  • Hi,

    Looks like you created the thread but never turned on the NWP. You have to call sl_start() at some point.
    You can go through any of the examples in the SDK to see how this is done.

    Regards,
    Charles O
  • So if I add sl_start(0,0,0) right after the BIOS start it should start Simplelink and be available to my other threads?

    One would think there would be a simple mapping from the old way:

    void main()
    {
    
    	long lRetVal = -1;
        BoardInit();
        PinMuxConfig();
    #ifndef NOTERM
        InitTerm();
    #endif
        DisplayBanner(APPLICATION_NAME);
        GPIO_IF_LedConfigure(LED1|LED2|LED3);
        GPIO_IF_LedOff(MCU_ALL_LED_IND);
        //
         // Start the SimpleLink Host
         //
         lRetVal = VStartSimpleLinkSpawnTask(SPAWN_TASK_PRIORITY);
         if(lRetVal < 0)
         {
             ERR_PRINT(lRetVal);
             LOOP_FOREVER();
         }
         msgini(MSGSN);
         lRetVal = osi_TaskCreate( aest::aesSrvr, (const signed char*)"aest aesSrvr", OSI_STACK_SIZE, NULL, 1, NULL );
         if(lRetVal < 0){
             ERR_PRINT(lRetVal);
             LOOP_FOREVER();
         }
         lRetVal = osi_TaskCreate( aest::aesMsgr, (const signed char*)"aest aesMsgr", OSI_STACK_SIZE, NULL, 1, NULL );
         if(lRetVal < 0){
                  ERR_PRINT(lRetVal);
                  LOOP_FOREVER();
         }
         lRetVal = osi_TaskCreate( aest::aesSndr, (const signed char*)"aest aesSndr", OSI_STACK_SIZE, NULL, 1, NULL );
              if(lRetVal < 0){
                       ERR_PRINT(lRetVal);
                       LOOP_FOREVER();
              }
         //
         // Start the task scheduler
         //
         osi_start();
    }

  •  *  ======== main_tirtos.c ========
     */
    #include <stdint.h>
    /* POSIX Header files */
    #include <pthread.h>
    /* RTOS header files */
    #include <ti/sysbios/BIOS.h>
    /* Example/Board Header files */
    #include "Board.h"
    /* Stack size in bytes */
    #define THREADSTACKSIZE    2048
    #define TASKSTACKSIZE    2048
    #define SPAWN_TASK_PRIORITY     9
    //align stacks?
    #include <aestx.hpp>
    aestx a0;
    //pthread_attr_t pAttrs_spawn;
    //void * (*PTFPs[4])(void *)= {aestx::netwid,aestx::srvr, aestx::msgr, aestx::sndr};
    //pthread_attr_t pAttrs[4];
    //struct sched_param priParams[4];
    pthread_attr_t pAttrs[5];
    void * (*PTFPs[5])(void *)= {sl_Task, aestx::netwid,aestx::srvr, aestx::msgr, aestx::sndr};
    struct sched_param priParams[5];
    /*
     *  ======== main ========
     */
    int main(void)
    {
    
        //pthread_attr_t pAttrs_spawn;
        int32_t retc = 0;
        UART_Handle tUartHndl;
        Board_initSPI();
        /* Configure the UART                                                     */
        tUartHndl = InitTerm();
        /* remove uart receive from LPDS dependency                               */
        UART_control(tUartHndl, UART_CMD_RXDISABLE, NULL);
        /* Call driver init functions */
        Board_initGeneral();
        /*
        // sl_Task, array 4
        // Create the sl_Task
                pthread_t spawn_thread = (pthread_t) NULL;
                struct sched_param priParam;
                pthread_attr_init(&pAttrs_spawn);
                priParam.sched_priority = SPAWN_TASK_PRIORITY;
                retc = pthread_attr_setschedparam(&pAttrs_spawn, &priParam);
                retc |= pthread_attr_setstacksize(&pAttrs_spawn, TASKSTACKSIZE);
                retc |= pthread_attr_setdetachstate(&pAttrs_spawn, PTHREAD_CREATE_DETACHED);
                retc = pthread_create(&spawn_thread, &pAttrs_spawn, sl_Task, NULL);
                if (retc != 0){
                    UART_PRINT("could not create simplelink task\n\r");
                    while (1);
                }
        //array4
        pthread_t PTs[4]={(pthread_t)NULL,(pthread_t)NULL,(pthread_t)NULL,(pthread_t)NULL};
        for (int i=0;i<4;i++){
            pthread_attr_init(&(pAttrs[i]));
            priParams[i].sched_priority = SPAWN_TASK_PRIORITY;
            retc = pthread_attr_setschedparam(&(pAttrs[i]), &(priParams[i]));
            retc |= pthread_attr_setstacksize(&(pAttrs[i]), TASKSTACKSIZE);
            retc |= pthread_attr_setdetachstate(&(pAttrs[i]), PTHREAD_CREATE_DETACHED);
            retc |= pthread_create(&(PTs[i]), &(pAttrs[i]),PTFPs[i], NULL);
           }
           */
        pthread_t PTs[5]={(pthread_t)NULL,(pthread_t)NULL,(pthread_t)NULL,(pthread_t)NULL,(pthread_t)NULL};
        for (int i=0;i<5;i++){
            pthread_attr_init(&(pAttrs[i]));
            priParams[i].sched_priority = SPAWN_TASK_PRIORITY ;
            retc = pthread_attr_setschedparam(&(pAttrs[i]), &(priParams[i]));
            retc |= pthread_attr_setstacksize(&(pAttrs[i]), TASKSTACKSIZE);
            retc |= pthread_attr_setdetachstate(&(pAttrs[i]), PTHREAD_CREATE_DETACHED);
            retc |= pthread_create(&(PTs[i]), &(pAttrs[i]),PTFPs[i], NULL);
       }
       // use class static volatile variable to prevent class threads from running until ip setup done
        //
        BIOS_start();
        return (0);
    }
    

    OK, here is what seems to work: