Chris O'Byrne - YAVRTOS

Semaphores


Functions

yavrtos_result_t wait_for_min_value (semaphore_t *s, int16_t value, semaphore_t *timeout_semaphore, int16_t timeout)
 Wait for a semaphore to reach at least a particular value.
yavrtos_result_t wait_for_min_value_timeout (semaphore_t *p, int16_t value, semaphore_t *timeout_semaphore, int16_t timeout_value)
 Wait for a semaphore to reach at least a particular value, but with a set value for the timeout, as opposed to an increment to the timeout semaphore value.
yavrtos_result_t wait_for_increment_of (semaphore_t *p, uint16_t amount, semaphore_t *timeout_semaphore, int16_t timeout)
 Wait for a semaphore to increment its value by a certain amount.
yavrtos_result_t wait_for_increment_of_timeout (semaphore_t *p, uint16_t amount, semaphore_t *timeout_semaphore, int16_t timeout_value)
 Wait for a semaphore to increment its value by a certain amount, but with a set value for the timeout, as opposed to an increment to the timeout semaphore value.
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.

yavrtos_result_t wait_for_increment_of ( semaphore_t p,
uint16_t  amount,
semaphore_t timeout_semaphore,
int16_t  timeout 
)

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
  • timeout_semaphore - a semaphore to use for timing out while waiting on the other semaphore, or 0 if no timeout should be performed
  • timeout - the amount that the timeout semaphore should increment before timeout occurs. Note that there is a similar restriction on the value of this argument - it should not exceed about 32,000
Since the calling task could be suspended, this can only be called by a task with a non-zero priority

The possible return values are

yavrtos_result_t wait_for_increment_of_timeout ( semaphore_t p,
uint16_t  amount,
semaphore_t timeout_semaphore,
int16_t  timeout_value 
)

Wait for a semaphore to increment its value by a certain amount, but with a set value for the timeout, as opposed to an increment to the timeout semaphore value.

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
  • timeout_semaphore - a semaphore to use for timing out while waiting on the other semaphore, or 0 if no timeout should be performed
  • timeout_value - the minimum value the timeout semaphore should reach before triggering a timeout
Since the calling task could be suspended, this can only be called by a task with a non-zero priority

The possible return values are

yavrtos_result_t wait_for_min_value ( semaphore_t s,
int16_t  value,
semaphore_t timeout_semaphore,
int16_t  timeout 
)

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

The arguments are

  • p - the semaphore to wait on
  • value - the minimum value the semaphore should reach
  • timeout_semaphore - a semaphore to use for timing out while waiting on the other semaphore, or 0 if no timeout should be performed
  • timeout - the amount that the timeout semaphore should increment before timeout occurs. Note that the value of this argument should not exceed about 32,000, as semaphores use signed 16-bit numbers
Since the calling task could be suspended, this can only be called by a task with a non-zero priority

The possible return values are

yavrtos_result_t wait_for_min_value_timeout ( semaphore_t p,
int16_t  value,
semaphore_t timeout_semaphore,
int16_t  timeout_value 
)

Wait for a semaphore to reach at least a particular value, but with a set value for the timeout, as opposed to an increment to the timeout semaphore value.

The arguments are

  • p - the semaphore to wait on
  • value - the minimum value the semaphore should reach
  • timeout_semaphore - a semaphore to use for timing out while waiting on the other semaphore, or 0 if no timeout should be performed
  • timeout_value - the minimum value the timeout semaphore should reach before triggering a timeout
Since the calling task could be suspended, this can only be called by a task with a non-zero priority

The possible return values are


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