Metrologic Optimus S Programming Manual page 235

"c" programming guide
Table of Contents

Advertisement

Note that semaphores must be created before they are used. This function
cannot be called from an ISR.
Return
A pointer to the event control block allocated to the semaphore.
If no event control blocks are available, a NULL pointer will be returned.
See Also
OSSemPend, OSSemPost
OSSemPend
Purpose
To list a task on the pending list for the semaphore.
Syntax
Void OSSemPend (OS_Event *pevent, unsigned long timeout, unsigned char
*err);
where, pevent is a pointer to the semaphore. This pointer is returned to your
application when the semaphore is created.
timeout is used to allow the task to resume execution if the semaphore is not
acquired within the specified number of clock ticks. A timeout value of 0
indicates that the task desires to wait forever for the semaphore. The maximum
timeout can be 65535 clock ticks.
err is a pointer to a variable which will be sued to hold an error code.
OSSemPend sets *err to either:
(1) OS_NO_ERR, if the semaphore is available.
(2) OS_TIMEOUT, if a timeout occurred.
OSSemPend (DispSem, 0, &err);
Example
Description
This function is used when a task desires to gain exclusive access to a resource,
to synchronize its activities with an Interrupt Service Routine (ISR), or to wait
until an event occurs.
If a task calls OSSemPend and the value of the semaphore is greater than zero,
then OSSemPend will decrement the semaphore count and return to its caller.
However, if the value of the semaphore is less than or equal to zero,
OSSemPend decrements the semaphore count and places the calling task in the
pending list for the semaphore. The task will thus wait until a task or an ISR
releases the semaphore or signals the occurrence of the event. In this case,
rescheduling occurs and the next highest priority task ready to run is given
control of the CPU. An optional timeout may be specified when pending for a
semaphore.
Note that semaphores must be created before they are used. This function
cannot be called from an ISR.
None
Return
See Also
OSSemCreate, OSSemPost
Allow a task to synchronize with either an ISR or a task
Gain exclusive access to a resource
Signal the occurrence of an event
Chapter 5 Real-Time Kernel
229

Advertisement

Table of Contents
loading

This manual is also suitable for:

Optimus r

Table of Contents