ucos任务信号量

任务信号量

实现多对一(发向特定任务)的信号量的传输

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_INT_Q_FULL

If OS_CFG_ISR_POST_DEFERRED_EN is to DEF_ENABLED in os_cfg.h: If the deferred

interrupt post queue is full.

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.

OSTaskSemPend

Description

OSTaskSemPend() allows a task to wait for a signal to be sent by another task or ISR without

going through an intermediate object such as a semaphore. If the task was previously signaled

when OSTaskSemPend() is called then, the caller resumes.

If no signal was received by the task and OS_OPT_PEND_BLOCKING is specified for the opt

argument, OSTaskSemPend() suspends the current task until either a signal is received, or a

user-specified timeout expires. A pended task suspended with OSTaskSuspend() can receive

signals. However, the task remains suspended until it is resumed by calling OSTaskResume().

If no signals were sent to the task and OS_OPT_PEND_NON_BLOCKING was specified for the opt

argument, OSTaskSemPend() returns to the caller with an appropriate error code and returns a

signal count of 0.

Files

os.h/os_task.c

Prototype

OS_SEM_CTR OSTaskSemPend (OS_TICK timeout,
 OS_OPT opt,
 CPU_TS *p_ts,
 OS_ERR *p_err)

Arguments

timeout

allows the task to resume execution if a signal is not received from a task or an ISR

within the specified number of clock ticks. A timeout value of 0 indicates that the task

wants to wait forever for a signal. The timeout value is not synchronized with the clock

tick. The timeout count starts decrementing on the next clock tick, which could

potentially occur immediately.

opt

determines whether the user wants to block or not, if a signal was not sent to the task. Set

this argument to either:

OS_OPT_PEND_BLOCKING, or

OS_OPT_PEND_NON_BLOCKING

Note that the timeout argument should be set to 0 when specifying

OS_OPT_PEND_NON_BLOCKING, since the timeout value is irrelevant using this option.

p_ts

is a pointer to a timestamp indicating when the task’s semaphore was posted, or the pend

was aborted. Passing a NULL pointer is valid and indicates that the timestamp is not

necessary.

A timestamp is useful when the task is to know when the semaphore was posted, or how

long it took for the task to resume after the semaphore was posted. In the latter case, call

OS_TS_GET() and compute the difference between the current value of the timestamp and

*p_ts. In other words:

delta = OS_TS_GET() - *p_ts;

p_err

is a pointer to a variable used to hold an error code.

OS_ERR_NONE

If a signal is received.

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.

  • 13
    点赞
  • 20
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值