OSTaskSemPost

Description

OSTaskSemPost() sends a signal to a task through it’s local semaphore.

If the task receiving the signal is actually waiting for a signal to be received, it will be made ready-to-run and, if the receiving task has a higher priority than the task sending the signal, the higher-priority task resumes, and the task sending the signal is suspended; that is, a context switch occurs. Note that scheduling only occurs if opt is set to OS_OPT_POST_NONE, because the OS_OPT_POST_NO_SCHED option does not cause the scheduler to be called.

Files

os.h/os_task.c

Prototype

OS_SEM_CTR  OSTaskSemPost (OS_TCB    *p_tcb,
                           OS_OPT     opt,
                           OS_ERR    *p_err)

Arguments

p_tcb

is a pointer to the TCB of the task being signaled. A NULL pointer indicates that the user is sending a signal to itself.

opt

provides options to the call.

OS_OPT_POST_NONE

No option, by default the scheduler will be called.

OS_OPT_POST_NO_SCHED

Do not call the scheduler after the post, therefore the caller is resumed.

You would use this option if the task (or ISR) calling OSTaskSemPost() will be doing additional posts, reschedule waits until all is done, and multiple posts are to take effect simultaneously.

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 signal was sent.

OS_ERR_OPT_INVALID

If OS_CFG_ARG_CHK_EN is set to DEF_ENABLED in os_cfg.h: if a valid option is not specified.

OS_ERR_OS_NOT_RUNNING

If OS_CFG_INVALID_OS_CALLS_CHK_EN is set to DEF_ENABLED in os_cfg.h: if µC/OS-III is not running yet.

OS_ERR_SEM_OVF

the post would have caused the semaphore counter to overflow.

OS_ERR_STATE_INVALID

If the task is in an invalid state.

Returned Value

The current value of the task’s signal counter, or 0 if called from an ISR and OS_CFG_ISR_POST_DEFERRED_EN is set to DEF_ENABLED.

Required Configuration

Always enabled.

Callers

Application and ISRs.

Notes/Warnings

None.

Example Usage

OSTaskSemPost() example usage
          OS_TCB       CommRxTaskTCB;
           
           
          void CommTaskRx (void *p_arg)
          {
              OS_ERR      err;
              OS_SEM_CTR  ctr;
           
           
              (void)&p_arg;
              while (DEF_ON) {
                  :
                  ctr = OSTaskSemPost(&CommRxTaskTCB,
                                       OS_OPT_POST_NONE,
                                      &err);
                  /* Check "err" */
                  :
                  :
              }
          }