Chris O'Byrne - YAVRTOS

Semaphores


Functions

uint8_t wait_for_min_value (semaphore_t *s, int16_t value)
 Wait for a semaphore to reach at least a particular value.
uint8_t wait_for_increment_of (semaphore_t *p, uint16_t amount)
 Wait for a semaphore to increment its value by a certain amount.
int16_t get_semaphore_value (semaphore_t *s)
 Get the current value of a semaphore.
void increment_semaphore_by (semaphore_t *s, uint16_t amount)
 Increment the value of a semaphore by the given amount.

Detailed Description

A semaphore contains a number that tasks can suspend themselves against, waiting for the number to reach at least a certain value before the task is schedulable again.

To update a semaphore's value, use increment_semaphore_by()

To read a semaphore's value, use get_semaphore_value()

To lock on a semaphore, use wait_for_min_value() or wait_for_increment_of()

See using semaphores for information on how to use semaphores


Function Documentation

int16_t get_semaphore_value ( semaphore_t s  ) 

Get the current value of a semaphore.

This function may be called anywhere

void increment_semaphore_by ( semaphore_t s,
uint16_t  amount 
)

Increment the value of a semaphore by the given amount.

The arguments are

  • s - the semaphore to increment
  • amount - the amount by which the semaphore should be incremented. Note that semaphore values are actually signed 16-bit numbers, so the maximum value for this argument is about 32,000
This may be called by any task, by an ISR, or even before the task system is running.

When called from a task, this function may end up yielding control to a higher-priority task that is waiting on the semaphore.

uint8_t wait_for_increment_of ( semaphore_t p,
uint16_t  amount 
)

Wait for a semaphore to increment its value by a certain amount.

The arguments are

  • p - the semaphore to wait on
  • amount - the amount by which the semaphore should increment before returning. Note that semaphore values are actually signed 16-bit numbers, so the maximum value for this argument is about 32,000
Since the calling task could be suspended, this can only be called by a task with a non-zero priority

uint8_t wait_for_min_value ( semaphore_t s,
int16_t  value 
)

Wait for a semaphore to reach at least a particular value.

Since the calling task could be suspended, this can only be called by a task with a non-zero priority


YAVRTOS and YAVRTOS documentation Copyright © 2007-2008 Chris O'Byrne. Email - chris <at> obyrne <dot> com