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.

SYS/BIOS Preemptive or cooperative?

Hi, I have SYS/BIOS 6.41.00.26.

I have a simple main.c:

// TP_on set a GPIO pin
// TP_off clear GPIO pin

static Void task(UArg arg0, UArg arg1)
{
	while(1)
	{
		TP_on((TpIdx_t)arg0);
		TP_off((TpIdx_t)arg0);
	}
}

/*
 *  ======== main ========
 */
Void main()
{
    //
    // Enable lazy stacking for interrupt handlers.  This allows floating-point
    // instructions to be used within interrupt handlers, but at the expense of
    // extra stack usage.
    //
    ROM_FPULazyStackingEnable();

    TP_init();

    Task_Params taskParams;
    Task_Params_init(&taskParams);
    taskParams.priority = 1;
    taskParams.stackSize = 1024;
    taskParams.arg0 = TP32;
    Task_create (task, &taskParams, NULL);
    taskParams.arg0 = TP33;
    Task_create (task, &taskParams, NULL);

    BIOS_start();
}

Since I thought that the BIOS was preemptive I programmed the task as if it was the only thread running (as described in SYS/BIOS User Guide 3.5.6), the function task() is implemented as infinite loop without sleep, yield or other similar calls.

Running this example only one pin is toggled. It seems that the scheduler doesn't preempt the running task.

I try to add a Task_yield():

static Void task(UArg arg0, UArg arg1)
{
	while(1)
	{
		TP_on((TpIdx_t)arg0);
		TP_off((TpIdx_t)arg0);
		Task_yield();
	}
}

In this way both process runs. But this behaviour is typical of cooperative system.

Is there a way to configure BIOS to preempt task at same priority without need of Task_yield()?

best regards

Max

  • Hi Max,

    Unfortunately, we do not have an option to configure the BIOS to use time driven scheduling.

    If you need time driven scheduling, I would suggest using a Clock with the following Clock handler function:

    Void clockHandler1(UArg arg)
    {
        Task_yield();
    }
    

    This would periodically yield the current running task providing a time driven scheduling.

    More info about Clock Module can be found here.

    Hope this helps.

    Vikram