Golem  v0.1.1
Generic Operating system Libraries for Embedded Multitasking
 All Data Structures Files Functions Variables Pages
/home/ruud/Engineering/software/projects/golem-project-code/trunk/glm_signal.h File Reference

Simple signaling system. More...

#include <stdbool.h>
#include "glm_heap.h"

Go to the source code of this file.

Functions

bool signal_init ()
 Initializes the signaling system. More...
 
void signal_reset ()
 Resets the signaling system. More...
 
char * signal_name ()
 Obtain the name of the signaling system. More...
 
bool signal_create (signal_t *signal)
 Create a new signal. More...
 
bool signal_create_flag (flag_t *flag)
 Create a new flag. More...
 
bool signal_connect (signal_t signal, flag_t flag)
 Connect a signal to a flag. More...
 
void signal_reset_connections (signal_t signal)
 Reset connections between a signal and its flags. More...
 
void signal_emit (signal_t signal)
 Emit a signal (immediately) More...
 
void signal_emit_delayed (signal_t signal, uint_base_t delay)
 Emit a signal after a delay. More...
 
bool signal_flag_isset (flag_t flag)
 Check if a flag is set. More...
 
void signal_flag_clear (flag_t flag)
 Clear a flag. More...
 
void signal_flag_reset (flag_t flag)
 Reset a flag. More...
 

Detailed Description

Simple signaling system.

It is designed to be used in a cooperative multi-tasking system where task A needs to send messages (signals) to task B. In order to prevent task B from having a signal-handler function that takes too long to finish executing, hence screwing up the scheduling, the signal is passed to task B by setting a flag which can then be read by task B when it is running. Furthermore task A's signal can be tied to more than one other task's flag.

Author
Ruud Beukema

This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/.

Definition in file glm_signal.h.

Function Documentation

bool signal_connect ( signal_t  signal,
flag_t  flag 
)

Connect a signal to a flag.

The signal and flag to be interconnected may belong to two different software components. However, they may belong to one and the same software component as well.

Parameters
signalThe signal to connect to the flag.
flagThe flag to which a_signal must be connected.
Returns
TRUE if signal is successfully connected to the flag or FALSE if not.

Definition at line 188 of file glm_signal.c.

bool signal_create ( signal_t *  signal)

Create a new signal.

After a successful creation the signal can be emitted by its owner at any point in time by calling signal_emit(). All flags connected to this signal will be set upon emission.

Parameters
signalPointer to variable in which to store the new signal's ID.
Returns
TRUE if a_signal holds a valid signal-ID, FALSE if the creation of a new signal failed (a_signal is invalid).

Definition at line 100 of file glm_signal.c.

bool signal_create_flag ( flag_t *  flag)

Create a new flag.

After successful creation the flag can be connected to one or more signals using signal_connect(). The flag will then be set every time one of the connected signals emit.

During use a single flag may be set multiple times (by the same or different signals. The number of times a flag can be set is limited by the upper limit of the tick type (uint_base_t). The upper limit of the type uint_base_t is always 2^N-1, where N is equal to the bit-with of the integer-registers on your system - as selected with the CORE_*BIT-parameter in glm_conf.h.

Parameters
flagPointer to variable in which to store the new flag's ID.
Returns
TRUE if a_flag holds a valid flag-ID, FALSE if the creation of a new flag failed (and a_flag is invalid).

Definition at line 146 of file glm_signal.c.

void signal_emit ( signal_t  signal)

Emit a signal (immediately)

All flags connected to the signal are set.

Parameters
signalThe signal to emit

Definition at line 250 of file glm_signal.c.

void signal_emit_delayed ( signal_t  signal,
uint_base_t  delay 
)

Emit a signal after a delay.

All flags connected to the signal are set after the given delay. The delay is given in ticks, where one tick equals 1/CORE_TICK_FREQ_HZ seconds.

Parameters
signalSignal to emit.
delayDelay in ticks after which to the emit signal.

Definition at line 270 of file glm_signal.c.

void signal_flag_clear ( flag_t  flag)

Clear a flag.

The number of times the flag is set is decreased by one.

Parameters
flagFlag to clear.

Definition at line 291 of file glm_signal.c.

bool signal_flag_isset ( flag_t  flag)

Check if a flag is set.

Parameters
flagThe flag to check.
Returns
TRUE if flag is set, FALSE if not.

Definition at line 277 of file glm_signal.c.

void signal_flag_reset ( flag_t  flag)

Reset a flag.

The number of times a flag is set is decreased to 0, such that signal_flag_isset() would return FALSE afterwards.

Parameters
flagFlag to reset.

Definition at line 301 of file glm_signal.c.

bool signal_init ( )

Initializes the signaling system.

This function has to be called before using the signaling system and after calling signal_reset(). The initialization consists merely of obtaining the heap-ID, which is needed for its successful operation.

Returns
TRUE if initialisation succeeds, FALSE if signaling system could not obtain a heap-ID.

Definition at line 60 of file glm_signal.c.

char* signal_name ( )

Obtain the name of the signaling system.

Returns
Pointer to the start of the name of the signaling system component. This name is a '\0'-terminated string.

Definition at line 93 of file glm_signal.c.

void signal_reset ( )

Resets the signaling system.

Clears all registered signals and flags and their inter- connections.

Definition at line 67 of file glm_signal.c.

void signal_reset_connections ( signal_t  signal)

Reset connections between a signal and its flags.

All flags previously connected to the signal will not become set anymore when the signal is emitted.

Parameters
signalThe signal to be reset.

Definition at line 236 of file glm_signal.c.