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.

TDA4VMXEVM: R5F;MCU2_0;multitask;printf log;task API

Part Number: TDA4VMXEVM

I am writing a multi-tasking program running on R5F--mcu2_0. I have a few questions that are not very clear. Come and ask everyone:


1. When outputting log, why the log in main () function cannot be output, but the log in task function can be output and viewed;

2. How to use Task_sleep () in sys / bios, for example, I want to sleep for 10 milliseconds, Task_sleep (10 * 1000 / Clock_tickPeriod)?

3. I created three tasks, the priority of the tasks is the same, but when executing, one task is always outputting log, other tasks have no log output, but I call Task_yield () in the task, three tasks will Normal switch execution will output log.

Thanks.

  • Hello,

    First of all, which SDK version are you using?

    Below are my answers to your questions as well as a few clarifying questions on each of your points:

    1. Could you please provide a code snippet to see why this could be the case?

    2. Yes, that is the correct way to use the Task_sleep API.  There is also a similar API in the PDK OSAL called TaskP_sleepInMsecs that takes care of this calculation for you.

    3. On this question, are saying that you only see the log from the first task until you call Task_yield?  If not, could you please clarify the behavior of what is occurring?  With three tasks at the same priority, the first task will run until yielding in some way, either from a Task_yield or from pending on a semaphore.  Only at this point will the other tasks resume.

    Regards,

    Lucas

  • my sdk full name is:psdk_rtos_auto_j7_06_01_00_15
    extern "C" {
    #include <app.h>
    #include <utils/console_io/include/app_log.h>
    #include <xdc/runtime/Error.h>
    #include <ti/sysbios/BIOS.h>
    #include <ti/sysbios/knl/Task.h>
    #include <ti/sysbios/knl/Clock.h>
    #include <app_ipc_rsctable.h>
    }
    static uint8_t TskStack0[4*1024]
    __attribute__ ((section(".bss:taskStackSection")))
    __attribute__ ((aligned(4096)))
    ;

    static uint8_t TskStack1[4*1024]
    __attribute__ ((section(".bss:taskStackSection")))
    __attribute__ ((aligned(4096)))
    ;
    static uint8_t TskStack2[4*1024]
    __attribute__ ((section(".bss:taskStackSection")))
    __attribute__ ((aligned(4096)))
    ;
    void fun1(){
    while(true){
    printf("11111111111111111111111111111111111111111111111111\n");
    }
    }
    void fun2(){
    while(true){
    printf("22222222222222222222222222222222222222222222222222221\n");
    }
    }
    void fun3(){
    printf("33333333333333333333333333333333333333333333333333333\n")
    }
    int main(void)
    {
    printf("This is my main function\n");
    Task_Params tskParams;
    Error_Block eb;
    Task_Handle task0,task1,task2;
    Error_init(&eb);
    Task_Params_init(&tskParams);

    tskParams.arg0 = (UArg) NULL;
    tskParams.arg1 = (UArg) NULL;
    tskParams.priority = 10u;
    tskParams.stack = TskStack0;
    tskParams.stackSize = 4096;
    task0 = Task_create((ti_sysbios_knl_Task_FuncPtr)Srr3FrontReader, &tskParams, &eb);
    if(NULL == task0){
    BIOS_exit(0);
    }
    tskParams.stack = TskStack1;
    tskParams.stackSize = 4096;
    task1 = Task_create((ti_sysbios_knl_Task_FuncPtr)fun1, &tskParams, &eb);
    if(NULL == task1){
    BIOS_exit(0);
    }
    tskParams.stack = TskStack2;
    tskParams.stackSize = 4096;
    task2 = Task_create((ti_sysbios_knl_Task_FuncPtr)fun1, &tskParams, &eb);
    if(NULL == task2){
    BIOS_exit(0);
    }
    tskParams.stack = TskStack3;
    tskParams.stackSize = 4096;
    task3 = Task_create((ti_sysbios_knl_Task_FuncPtr)fun1, &tskParams, &eb);
    if(NULL == task3){
    BIOS_exit(0);
    }
    BIOS_start();
    return 0;
    }
    Regarding question 3: The task will only switch if I actively call Task_yield () in the loop.
    Thanks
  • Hi,

    As we discussed on https://e2e.ti.com/support/processors/f/791/t/890353 thread, unless one thread blocks, it will not switch to next same priority thread. 

    Can you try adding some Task_sleep (x), with x different in each thread, in the loop?

    For the Task_skeep, x is always in terms of ms. so lets if you want sleep for 10ms, then use 10..

    For this to work, we need to provide timer frequency in the cfg file. This is already taken care in vision apps. So you could directly use Task_sleep API. 

    Rgds,

    Brijesh

  • But if I actively call an interface such as Task_sleep () to switch threads, instead of the scheduler scheduling the thread to switch automatically, this will affect the logic, efficiency and correctness of my program.

    Thanks.

  • Please refer to BIOS user guide. I think there is no round robin scheduling policy.

    Rgds,

    Brijesh 

  • Yes, I haven't seen the description of the circular scheduling strategy in the user guide,

    but I mentioned that it is a deprivable kernel, so as you said, it will always run a task,

    The operating system will not call other tasks of the same priority until the current task is blocked, suspended, or sleeping, or the CPU is actively given up.

    Thanks.