Available Languages?:

This is an old revision of the document!


OSA : Counting semaphores

Intro

Counting semaphore is a system variable of type unsigned char, unsigned int or unsigned long (it depends of OS_CSEM_SIZE constant). To use counting semaphores in your program you must define OS_ENABLE_CSEM in OSAcfg.h

General difference between counting and binary semaphores is that counting semaphore can take any value in range from 0 to maximum type's value (255, 65535, 4294967295).

Definition

Here is an example of definition counting semaphore variable:

OST_CSEM  mycsem;

For HT-PICC16 it is allowed to allocate counting semaphores only in bank0 and bank1.

Work

To work with counting semaphore variable it must be created by service OS_Csem_Create. After creation semaphore is zeroed. The value of counting semaphore can be changed with any service of set value group (see below). When task is waiting for cointing semaphore, it will be put in wait mode while semaphore is zero. Once it's value becames non-zero, task will be switched in ready mode. After task will get control, semaphore's value will be decremented by 1.

Attention should be paid that there are two groups of services to change semaphore's value:

  • to work within task
  • to work within interrupt service routine (these service have prefix Int)

In order to call the services from interrupt, constant OS_ENABLE_INT should be defined in OSAcfg.h.

Few words about service OS_Csem_Signal. This service increases semaphore's value by 1. If semaphore already set at maxiumm, then its value will remain unchanged and bEventError flag will be set.

Services

Service Arguments Description Properties
Creating
OS_Csem_Create (csem) Create and zero counting semaphore Not allowed in interrupt
Menagement
OS_Csem_Signal (csem) Increase counting semaphore's value by 1 (wait when overflow) Not allowed in interrupt
OS_Csem_Signal_Now (csem) Increase counting semaphore's value by 1 (don't wait when overflow) Have alternate service for work in ISR (suffix "_I")
OS_Csem_Set (csem) Set counting semaphore's value to 1. Have alternate service for work in ISR (suffix "_I")
OS_Csem_SetValue (csem, value) Set counting semaphore's value to given value. Have alternate service for work in ISR (suffix "_I")
OS_Csem_Reset (csem) Zero counting semaphore Have alternate service for work in ISR (suffix "_I")
Checking
bool
OS_Csem_Check
(csem) Check for counting semaphore is set (not eq. to 0) Have alternate service for work in ISR (suffix "_I")
OS_Csem_Accept (csem) Accept counting semaphore. Decrease it's value by 1. Have alternate service for work in ISR (suffix "_I")
Waiting
OS_Csem_Wait (csem) Wait for counting semaphore. Then decrease it's value by 1 Allowed only in taskSwitches contexts
OS_Csem_Wait_TO (csem, timeout) Wait for counting semaphore. Then decrease it's value by 1. Exit if timeout expired Allowed only in taskSwitches contextsService uses system timer
 
en/osa/ref/services/counting_semaphores.1260572439.txt.gz · Last modified: 12.12.2009 02:00 by osa_chief
 
Creative Commons License Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki