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.

Create_task stuck

Hi there.. I'm new to the ti-rtos development, so be gentle with me..

Im trying to create 2 tasks.. and on the second time I call create_task the whole program gets stuck..

It doesnt move on to the next line. Here's  the code:

int main(void)
{
/* Call board init functions */
Board_initGeneral();

Task_Handle myTsk2;
Task_Params taskParams2;
Error_Block eb4;
Error_init(&eb4);
/* Create 1 task with priority 15 */
Task_Params_init(&taskParams2);
taskParams2.stackSize = 512;
taskParams2.priority = -1;
taskParams2.instance -> name = "Task2";
myTsk2 = Task_create(myTskFunc2, &taskParams2, &eb4);
if (myTsk2 == NULL) {
System_abort("Task create failed");
}

Task_Handle myTsk;
Task_Params taskParams;
Error_Block eb2;
Error_init(&eb2);
/* Create 1 task with priority 15 */
Task_Params_init(&taskParams);
taskParams.stackSize = 512;
taskParams.priority = -1;
taskParams.instance -> name = "Task1";
myTsk = Task_create(myTskFunc, &taskParams, &eb2);
if (myTsk == NULL) {
System_abort("Task create failed");
}

}

I guess that it is something silly but I cant figure out what it is.

  • Hi,

    My guess is that you don't have enough heap memory to create the second task.

    The heap is used for dynamic memory allocation and one solution would be to increase the heap size in the .cfg file of your project.

    However, these is probably another method which will be easier to understand: assign a stack without using the heap. You can create an array of bytes and use it for your stack. The space will be allocated during compilation and your linker will tell you if you run out of memory.

    1. Declare your array of bytes (make sure it is global)
    2. Assign it to your stack with the Task_params

    Here is your modified code:

    // Create your stack array and make it global
    Char taskStack1[512];
    Char taskStack2[512];
    
    int main(void)
    {
      /* Call board init functions */
      Board_initGeneral();
    
      Task_Handle myTsk2;
      Task_Params taskParams2;
      Error_Block eb4;
      Error_init(&eb4);
      /* Create 1 task with priority 15 */
      Task_Params_init(&taskParams2);
      //////////
      // Specify which stack to use
      taskParam2.stack = taskStack2;
    
      taskParams2.stackSize = 512; //this size needs to match your array size, so you could use sizeof(taskStack2)
      taskParams2.priority = -1; //you don't need to do this if you want to use the default priority
      taskParams2.instance -> name = "Task2";
      myTsk2 = Task_create(myTskFunc2, &taskParams2, &eb4);
      if (myTsk2 == NULL) {
        System_abort("Task create failed");
      }
    
      Task_Handle myTsk;
      Task_Params taskParams;
      Error_Block eb2;
      Error_init(&eb2);
      /* Create 1 task with priority 15 */
      Task_Params_init(&taskParams);
      //////////
      // Specify which stack to use
      taskParam.stack = taskStack;
    
      taskParams.stackSize = 512;
      taskParams.priority = -1;
      taskParams.instance -> name = "Task1";
      myTsk = Task_create(myTskFunc, &taskParams, &eb2);
      if (myTsk == NULL) {
        System_abort("Task create failed");
      }
    
    }

    Regards,

    Michel

  • There was a suggested answer and since there has been no active on this thread for more than a week, the suggested answer was marked as verify. Please feel free to select the "Reject Answer" button and reply with more details.