Semaphore


Detailed Description

Semaphores are a mechanism for inter-task communication and interrupt-task communication. Each semaphore has it own semaphore control block which is used by system calls to handle the caller request associated with the semaphore. Tasks and interrupts can post a semaphore, but only tasks are allowed to pend for a semaphore. A timeout value can be passed to the pend function. Multiple posts increment the semaphore count, but only up to the semaphore maximum count. This value is specified when the sempahore is created. If the count is 0 the semaphore isn't avaible.


Defines

#define SEM_CREATE(name, cnt, max_cnt)
 Create a semaphore.

Functions

STATUS SEM_Pend (HANDLE *ph, uint16 tout)
 Semaphore pend function.
void SEM_Post (HANDLE *ph)
 Semaphore post function.
void SEM_Reset (HANDLE *ph, uint8 cnt)
 Semaphore reset function.
uint8 SEM_Querry (HANDLE *ph)
 Semaphore querry function.


Define Documentation

#define SEM_CREATE name,
cnt,
max_cnt   ) 
 

Create a semaphore.

This macro creates a semaphore and initilises its initail count and its maximum value. The semaphore maximum value can be up to 255.

Parameters:
name name of the semaphore
cnt number of resources at cration time
max_cnt maximun value of semaphore


Function Documentation

STATUS SEM_Pend HANDLE *  ph,
uint16  tout
 

Semaphore pend function.

A task can pend for a semaphore. If the semaphore count is greater than 0 the count is decremented and the function returns with SYS_OK. If the count is zero the function returns with SYS_ERROR. When a timeout value is specified, a timer is started and the task is delayed from execution for the timeout period. If in the mean time the semaphore is posted the SYS_SEM value is passed to the task, otherwise the task receives a SYS_SEM_TOUT entry value.

Parameters:
ph handle to semaphore
tout timeout value
Return values:
SYS_OK semaphore count was > 0
SYS_ERR semaphore count was 0
Attention:
Only tasks can pend on a semaphore.

void SEM_Post HANDLE *  ph  ) 
 

Semaphore post function.

A task or interrupt ISR can post a semaphore. If there was no other task waitnig for the semaphore the semaphore count is incremented by one, otherwise the first waiting task is unblocked. Also any timer associated with the pending task is removed. The value SYS_SEM is passed to the newly dequeued task.

Parameters:
ph handle to semaphore

uint8 SEM_Querry HANDLE *  ph  ) 
 

Semaphore querry function.

This function returns the acctual semaphore count.

Parameters:
ph handle to semaphore

void SEM_Reset HANDLE *  ph,
uint8  cnt
 

Semaphore reset function.

This function resets the semaphore count to the specified value. All pending tasks are dequeud and SYS_ERROR is passed to them.

Parameters:
ph handle to semaphore
cnt initial semaphore count


Generated on Sun Oct 16 22:23:55 2005 for uSmartX by  doxygen 1.4.3