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/CC2640R2F: Task_Entry always works

Part Number: CC2640R2F

Tool/software: TI-RTOS

Hello, could you help with the solution of the next problem. The project is based on project_zero_cc2640r2lp_app. After adding personal tasks, the following situation occurs: all tasks are created without errors, but when the project is started, they are always in the READY state (checked by points), and only the ICall_taskEntry task is in the RUNNING state: 

In addition, the picture of memory allocation:

What are the causes of this situation?

  • Hi Egor,

    Can you post some code on how you initialize your tasks?

    Regards,

    Klas
  • Hello, Klas:

    Task_Struct SCUartTask;
    Char SCUartTaskStack[512];
    
    #define NUMMSGS         5
    
    typedef struct MsgObj {
        char str[64];
    } MsgObj;
    
    typedef struct MailboxMsgObj {
        Mailbox_MbxElem  elem;      /* Mailbox header        */
        MsgObj           obj;       /* Application's mailbox */
    } MailboxMsgObj;
    
    MailboxMsgObj mailboxBuffer[NUMMSGS];
    
    Mailbox_Struct mbxStruct;
    Mailbox_Handle mbxUart;
    
    Event_Handle uartEmuEvent;
    
    void scUart_createTask(void)
    {
        Task_Params taskParams;
        Mailbox_Params mbxParams;
        Error_Block eb;
    
        /*
         *      Configure the OS task
         */
        Task_Params_init(&taskParams);
        taskParams.stack = SCUartTaskStack;
        taskParams.stackSize = sizeof(SCUartTaskStack);
        taskParams.priority = 3;//3
        Task_construct(&SCUartTask, SC_uartTaskFxn, &taskParams, NULL);
    
        /*
         *      Create the semaphore used to wait for Sensor Controller
         *      ALERT events
         */
        Semaphore_Params semParams;
        Semaphore_Params_init(&semParams);
        semParams.mode = Semaphore_Mode_BINARY;
        Semaphore_construct(&semScTaskAlert, 0, &semParams);
    
        /* Construct a Mailbox instance */
        Mailbox_Params_init(&mbxParams);
        mbxParams.buf = (Ptr)mailboxBuffer;
        mbxParams.bufSize = sizeof(mailboxBuffer);
        Mailbox_construct(&mbxStruct, sizeof(MsgObj), NUMMSGS, &mbxParams, NULL);
        mbxUart = Mailbox_handle(&mbxStruct);
        /*
         *      Configure event receive a UART data
         */
        uartEmuEvent = Event_create(NULL, &eb);
        if (uartEmuEvent == NULL) {
            Log_error0("Event create failed");
        }
    
    }

    Task_Struct UartTask;
    Char UartTaskStack[1024];
    
    void Uart_createTask(void)
    {
        Task_Params taskParams;
    
        // Configure the OS task
        Task_Params_init(&taskParams);
        taskParams.stack = UartTaskStack;
        taskParams.stackSize = sizeof(UartTaskStack);
        taskParams.priority = 3;//3
        Task_construct(&UartTask, uartTaskFxn, &taskParams, NULL);
    }
    #define LOCK_TASK_PRIORITY                          1
    
    #ifndef LOCK_TASK_STACK_SIZE
    #define LOCK_TASK_STACK_SIZE                        1250
    #endif
    
    Task_Struct lockTask;
    Char lockTaskStack[LOCK_TASK_STACK_SIZE];
    
    void LockTask_createTask(void)
    {
      Task_Params taskParams;
    
      // Configure task
      Task_Params_init(&taskParams);
      taskParams.stack = lockTaskStack;
      taskParams.stackSize = LOCK_TASK_STACK_SIZE;
      taskParams.priority = LOCK_TASK_PRIORITY;
    
      Task_construct(&lockTask, LockSensorTaskFunction, &taskParams, NULL);
    }
    #define SENSOR_TASK_PRIORITY                     1
    
    #ifndef SENSOR_TASK_STACK_SIZE
    #define SENSOR_TASK_STACK_SIZE                   512
    #endif
    
    Task_Struct snsrTask;
    Char snsrTaskStack[SENSOR_TASK_STACK_SIZE];
    
    void SensorTask_createTask(void)
    {
      Task_Params taskParams;
    
      // Configure task
      Task_Params_init(&taskParams);
      taskParams.stack = snsrTaskStack;
      taskParams.stackSize = SENSOR_TASK_STACK_SIZE;
      taskParams.priority = SENSOR_TASK_PRIORITY;
    
      Task_construct(&snsrTask, SensorsTaskFunction, &taskParams, NULL);
    }
    #define PRZ_TASK_PRIORITY                     1
    
    #ifndef PRZ_TASK_STACK_SIZE
    #define PRZ_TASK_STACK_SIZE                   1024
    #endif
    
    Task_Struct przTask;
    Char przTaskStack[PRZ_TASK_STACK_SIZE];
    
    void ProjectZero_createTask(void)
    
    {
      Task_Params taskParams;
    
      // Configure task
      Task_Params_init(&taskParams);
      taskParams.stack = przTaskStack;
      taskParams.stackSize = PRZ_TASK_STACK_SIZE;
      taskParams.priority = PRZ_TASK_PRIORITY;
    
      Task_construct(&przTask, WirelessConnectionTaskFunction, &taskParams, NULL);
    }

    and main. c function:

    int main()
    {
      /* Register Application callback to trap asserts raised in the Stack */
      RegisterAssertCback(AssertHandler);
    
      PIN_init(BoardGpioInitTable);
    
    #if !defined( POWER_SAVING )
      /* Set constraints for Standby, powerdown and idle mode */
      // PowerCC26XX_SB_DISALLOW may be redundant
      Power_setConstraint(PowerCC26XX_SB_DISALLOW);
      Power_setConstraint(PowerCC26XX_IDLE_PD_DISALLOW);
    #endif // POWER_SAVING | USE_FPGA
    
    #ifdef ICALL_JT
      /* Update User Configuration of the stack */
      user0Cfg.appServiceInfo->timerTickPeriod = Clock_tickPeriod;
      user0Cfg.appServiceInfo->timerMaxMillisecond  = ICall_getMaxMSecs();
    #endif  /* ICALL_JT */
    
      /* Initialize the RTOS Log formatting and output to UART in Idle thread.
       * Note: Define xdc_runtime_Log_DISABLE_ALL to remove all impact of Log.
       * Note: NULL as Params gives 115200,8,N,1 and Blocking mode */
      UART_init();
      UartLog_init(UART_open(Board_UART0, NULL));
    
      /* Initialize ICall module */
      ICall_init();
    
      /* Start tasks of external images - Priority 5 */
      ICall_createRemoteTasks();
    
      /* Kick off profile - Priority 3 */
      GAPRole_createTask();
    
      /* Processing reset source */
      Eseal_GetResetSource();
    
      ProjectZero_createTask();
    
      LockTask_createTask();
    
      SensorTask_createTask();
      
      scUart_createTask();
    
      Uart_createTask();
    
      /* enable interrupts and start SYS/BIOS */
      BIOS_start();
    
      return 0;
    }
  • Hi Egor,

    First thing i would try is to lower the priority of your own custom tasks from 3 to 1. I would also try to comment out all tasks except one at the time and see if they change status from "Running" independently of each other.

    Please get back with your results.

    Regards,

    Klas

  • Hi, Klas.

    After setting the priority of my tasks to 1, nothing has changed much:

    But after deleting and adding tasks, the following results were obtained:

    LockTask_createTask or ProjectZero_createTask,  or scUart_createTask() were commented out, the program began to work


    When I commented Uart_createTask(), SensorTask_createTask() i got Hwi Exceptions:

    
    
  • Hi Egor,

    The fact that it says MEMFAULT gives me reason to believe you are out of RAM. Can you take a look under the "Memory allocation" tab? Does it work as expected if you run the project_zero default tasks with only one of your customized tasks at the time? Is there a special task that doesn't work? You have to break down the problem piece to piece in order to find the real issue here.

    Regards,

    Klas

  • Hello, Klas.

    Initially ProjectZero_createTask (), SensorTask_createTask (), LockTask_createTask (), were in the same ProjectZero project, and scUart_createTask (), Uart_createTask (), in another ProjectZero project. And in that case they worked without problems. But it was necessary to unite them into one project.

    Thanks for the help with MEMFAULT, I tried to reduce the size of my tasks as much as possible, and in particular the size of the task stack. As a result, the program worked, but there were problems with the connection. 

    In addition, I started the UART task once, to write data to the flash, after that I restart the device and already start only the tasks: ProjectZero, SensorTask, LockTask.

    Also, I recreated all the tasks with Task_create () instead of Task_construct(), which freed up some memory.

    And the stack for scUart_createTask (), Uart_createTask () I selected using ICall_malloc.

    This is the picture of memory allocation:

    At the moment the device works, but in what particular place was the problem with the memory I have not yet been able to figure out

  • Hi Egor,

    I'm not sure I understand if you still have a problem. What kind of connection problem do you have? If you like you said were able to free up some memory i think that was the solution.

    Regards,

    Klas


  • Hello Klas,

    Sorry that was not very clear. At the moment the problem does not arise and everything works. Thank you very much for your help.