Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
OS_SEM_CTR  OSTaskSemPost (OS_TCB    *p_tcb,
                           OS_OPT     opt,
                           OS_ERR    *p_err)

File

Called from

Code enabled by

os_task.c

Task or ISR

Always enabled

...

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 if opt is  is set to to OS_OPT_POST_NONE, because the the OS_OPT_POST_NO_SCHED option  option does not cause the scheduler to be called.

Files

os.h/os_task.c

Prototype

Code Block
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.

...

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 1to DEF_ENABLED.

Required Configuration

Always enabled.

Callers

Application and ISRs.

Notes/Warnings

None.

Example Usage

Code Block
titleOSTaskSemPost() 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" */
                  :
                  :
              }
          }