OSTaskTimeQuantaSet

Description

OSTaskTimeQuantaSet() is used to change the amount of time a task is given when time slicing multiple tasks running at the same priority.

Files

os.h/os_task.c

Prototype

void  OSTaskTimeQuantaSet (OS_TCB   *p_tcb,
                           OS_TICK   time_quanta,
                           OS_ERR   *p_err)

Arguments

p_tcb

is a pointer to the TCB of the task for which the time quanta is being set. A NULL pointer indicates that the user is changing the time quanta for the calling task.

time_quanta

specifies the amount of time (in ticks) that the task will run when µC/OS-III is time slicing between tasks at the same priority. Specifying 0 indicates that the default time as specified will be used when calling the function OSSchedRoundRobinCfg(), or OS_CFG_TICK_RATE_HZ / 10 if you never called OSSchedRoundRobinCfg().

You should not specify a “large” value for this argument as this means that the task will execute for that amount of time when multiple tasks are ready-to-run at the same priority. The concept of time slicing is to allow other equal-priority tasks a chance to run. Typical time quanta periods should be approximately 10 ms. A too small value results in more overhead because of the additional context switches.

p_err

is a pointer to a variable that will contain an error code returned by this function.

OS_ERR_NONE

If the call was successful and the time quanta for the task was changed.

OS_ERR_SET_ISR

If OS_CFG_CALLED_FROM_ISR_CHK_EN set to DEF_ENABLED in os_cfg.h: if calling this function from an ISR.

Returned Value

None

Required Configuration

OS_CFG_SCHED_ROUND_ROBIN_EN must be enabled in os_cfg.h. Refer to µC-OS-III Configuration Manual.

Callers

Application.

Notes/Warnings

  1. Do not specify a large value for time_quanta.

Example Usage

OSTaskTimeQuantaSet() example usage
          void TaskX (void *p_arg)
          {
              OS_ERR  err;
           
           
              while (DEF_ON) {
                  :
                  :
                  OSTaskTimeQuantaSet((OS_TCB *)0,
                                      OS_CFG_TICK_RATE_HZ / 4;
                                      &err);
                  /* Check "err" */
                  :
                  :
              }
          }