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.

SIMPLELINK-CC13X2-26X2-SDK: Restart a terminated task with TI-RTOS

Part Number: SIMPLELINK-CC13X2-26X2-SDK

If a task is terminated with returning from the task-function, how to run the task again?

  • Hi,

    Please review this page. If a task is terminated, then you should recreate it.

    Maybe a different option could be to not terminate the task and rather let it pend on a semaphore / message queue.

    I hope this will help,

    Best regards,

  • I have thought about the option to stop it with a semaphore, but it would make the things much more complicated. As far as i understand your answer, i always have to destruct a task after termination, and then construct it again if i want it to run again. 

    With this approach the code will have the following structure:

    Task_Struct task;
    Task_Handle hTask = NULL;
    bool taskStopFlag = false;

    void taskFxn(UArg arg0, UArg arg1) {
      // do some init
      while (!taskStopFlag) {
        // do some work
      }
      // do some cleanup
    }

    bool startTask() {
      taskStopFlag = false;
      Task_Param taskParam;
      Task_Params_init(&taskParams);
      taskParams.stackSize = 
      ...
      Task_construct( &task, &taskFxn, &taskParam, NULL);
      hTask = Task_handle(&task);
      return true;
    }

    bool stopTask() {
      taskStopFlag = false;
      if (hTask ==NULL) return true;  // fast return if task does not exist 
      int cnt = 0;
      Task_Mode taskMode = Task_getMode(hTask);
      while ((cnt <maxWait) && (taskMode != Task_Mode_TERMINATED)) {
        Task_sleep(100000);
        taskMode = Task_getMode(hTask);

      }
      if (taskMode == Task_Mode_TERMINATED) {
        Task_destruct(&task);
        hTask = NULL;
        return true;
      } else
        return false;
    }

    Do you see any problems with this approach?

    PS: The function to insert source code into a message does not work. i got the following error:

    Access Denied

    You don't have permission to access "">e2e.ti.com/.../configure on this server.

    Reference #18.c7d6dd58.1618944356.1eb9033b

  • Hi,

    Seems great. I think you have a typo in the function stopTask() an you meant to set taskStopFlag to true.

    Best regards,