Kernel Scheduler

group OS_87x3e_Schedule

Manage the kernel scheduler functions.

Functions

uint32_t os_hp_time_get(void)

Get the time in microseconds since os_sched_start() API function was called.

os_sched.h

Added Since 2.13.0.0:

Example usage

// Task routine implementation.
void task_routine(void *p_param)
{
    uint32_t last_time;

    // Get the last timestamp.
    last_time = os_hp_time_get();

    for (;;)
    {
         // Wait for the next cycle.
         platform_delay_us(100);

         // Do something here per 100us.
    }
}

Parameters:

None.

Returns:

The time in microseconds. Note the time represented by a 32-bit integer may be overflowed.

Variables

void (*os_delay)(uint32_t ms)

Delay current task for a given period in milliseconds.

os_sched.h

Example usage

// Task routine implementation.
void task_routine(void *p_param)
{
    for (;;)
    {
         // Task code goes here.
         os_delay(100);

         // Do something here per 100ms.
    }
}

Param ms:

The amout of timer in milliseconds that the current task should block.

Return:

None..

uint32_t (*os_sys_time_get)(void)

Get the time in milliseconds since os_sched_start() API function was called.

os_sched.h

Example usage

// Task routine implementation.
void task_routine(void *p_param)
{
    uint32_t last_time;

    // Get the last timestamp.
    last_time = os_sys_time_get();

    for (;;)
    {
         // Wait for the next cycle.
         os_delay(100);

         // Do something here per 100ms.
    }
}

Param None.:

Return:

The time in milliseconds. Note the time represented by a 32-bit integer may be overflowed.

bool (*os_sched_start)(void)

Start the RTOS kernel scheduler.

os_sched.h

Example usage

int test(void)
{
    // Create at least one task before starting kernel scheduler.
    if (os_task_create(&p_handle, "task", task_routine,
                       NULL, STACK_SIZE, TASK_PRIORITY) == true)
    {
        // Task created successfully.
    }
    else
    {
        // Task failed to create.
        return -1;
    }

    // Start the kernel scheduler.
    os_sched_start();

    // Will not get here unless a task calls os_sched_stop().
}

Param None.:

Retval true:

Scheduler was started successfully.

Retval false:

Scheduler was failed to start.

Return:

The status of starting kernel scheduler.

bool (*os_sched_stop)(void)

Stop the RTOS kernel scheduler. All created tasks will be automatically deleted and multitasking (either preemptive or cooperative) stops.

os_sched.h

Example usage

// Task routine implementation.
void task_routine(void *p_param)
{
    for (;;)
    {
         // Task code goes here.

         // At some point we want to end the real time kernel processing.
         os_sched_stop();
    }
}

int test(void)
{
    // Create at least one task before starting kernel scheduler.
    if (os_task_create(&p_handle, "task", task_routine,
                       NULL, STACK_SIZE, TASK_PRIORITY) == true)
    {
        // Task created successfully.
    }
    else
    {
        // Task failed to create.
        return -1;
    }

    // Start the kernel scheduler.
    os_sched_start();

    // Will not get here unless a task calls os_sched_stop().
}

Param None.:

Retval true:

Scheduler was stopped successfully.

Retval false:

Scheduler was failed to stop.

Return:

The status of stopping kernel scheduler.

bool (*os_sched_suspend)(void)

Suspends the kernel scheduler without disabling interrupts. Context switches will not occur while the scheduler is suspended. After calling os_sched_suspend(), the calling task will continue to execute without risk of being swapped out until a call to os_sched_resume() has been made.

os_sched.h

Example usage

// Task routine implementation.
void task_routine(void *p_param)
{
    for (;;)
    {
         // Task code goes here.

         // At some point the task wants to perform a long operation, and do not
         // want to get swapped out.
         os_sched_suspend();

         // The long operation.

         // The operation is completed, and resume the scheduler.
         os_sched_resume();
    }
}

Param None.:

Retval true:

Scheduler was suspended successfully.

Retval false:

Scheduler was failed to suspend.

Return:

The status of suspending kernel scheduler.

bool (*os_sched_resume)(void)

Resume the kernel scheduler after it was suspended by a call to os_sched_suspend().

os_sched.h

Example usage

// Task routine implementation.
void task_routine(void *p_param)
{
    for (;;)
    {
         // Task code goes here.

         // At some point the task wants to perform a long operation, and do not
         // want to get swapped out.
         os_sched_suspend();

         // The long operation.

         // The operation is completed, and resume the scheduler.
         os_sched_resume();
    }
}

Param None.:

Retval true:

Scheduler was resumed successfully.

Retval false:

Scheduler was failed to resume.

Return:

The status of resuming kernel scheduler.