heartbeat.c File Reference

A simple file for periodic function calls either based on a timestamp or on a count. More...

Go to the source code of this file.

Defines

#define DEFAULT_HEARTBEAT_PERIOD   (9)

Functions

void hb_beat (void)
 Use this function in every row of the scheduler.
int hb_get_count (void)
 Use this function as a parameter to the get_timestamp function in hb_init to make the heartbeat act according to the internal clock as opposed to an external clock.
void hb_init (int period, VOID_VOID_F func, INT_VOID_F get_time)
 Initializes the heartbeat.
static void hb_update (int count)
 This function checks the given value and heartbeat state to call the heartbeat function at a transition.

Variables

static VOID_VOID_F hb_function = voidvoid
 The function called once at the beginning of a heartbeat.
static INT_VOID_F hb_get_timestamp = intvoid
 The function called to get the timestamp.
static int hb_period = DEFAULT_HEARTBEAT_PERIOD
 The period between function calls.
static int hb_state = 0
 Whether we are in a heartbeat or not.

Detailed Description

A simple file for periodic function calls either based on a timestamp or on a count.

Author:
Nicolas Champagne-Williamson
Date:
2009

Definition in file heartbeat.c.


Function Documentation

int hb_get_count ( void   ) 

Use this function as a parameter to the get_timestamp function in hb_init to make the heartbeat act according to the internal clock as opposed to an external clock.

Returns:
The current internal clock of the heartbeat module.

Definition at line 60 of file heartbeat.c.

00060                       {
00061   static int hb_prescale = -1;
00062   static unsigned int hb_count = 0;
00063   hb_prescale++;
00064   if (hb_prescale >= SCHED_SPEED){
00065     hb_count++;
00066     hb_prescale = 0;
00067   }
00068   return hb_count;
00069 }

void hb_init ( int  period,
VOID_VOID_F  func,
INT_VOID_F  get_time 
)

Initializes the heartbeat.

Note:
SCHED_SPEED should be defined in hardware_setup.h and is the schedule speed in kHz. If it is not, hb_get_count will not work properly.
Parameters:
period The time between heartbeats is given as 2^(period-1) milliseconds.
func The function to call once at the beginning of a heartbeat.
get_time A function which returns the current timestamp.

Definition at line 28 of file heartbeat.c.

References hb_function, hb_get_timestamp, and hb_period.

00028                                                                {
00029   hb_period = period;
00030   hb_function = func;
00031   hb_get_timestamp = get_time;
00032 }

static void hb_update ( int  count  )  [static]

This function checks the given value and heartbeat state to call the heartbeat function at a transition.

Parameters:
count The value to check against the period for a heartbeat.

Definition at line 39 of file heartbeat.c.

References hb_function, hb_period, and hb_state.

Referenced by hb_beat().

00039                                 {
00040   int new_state = count & (1 << (hb_period - 1));
00041   if (!hb_state && new_state){
00042     hb_function();
00043   } 
00044   hb_state = new_state;
00045 }


Variable Documentation

VOID_VOID_F hb_function = voidvoid [static]

The function called once at the beginning of a heartbeat.

Definition at line 17 of file heartbeat.c.

Referenced by hb_init(), and hb_update().

INT_VOID_F hb_get_timestamp = intvoid [static]

The function called to get the timestamp.

Definition at line 18 of file heartbeat.c.

Referenced by hb_beat(), and hb_init().

int hb_period = DEFAULT_HEARTBEAT_PERIOD [static]

The period between function calls.

Definition at line 16 of file heartbeat.c.

Referenced by hb_init(), and hb_update().

int hb_state = 0 [static]

Whether we are in a heartbeat or not.

Used for transition checking. 1 = hb, 0 = not hb.

Definition at line 15 of file heartbeat.c.

Referenced by hb_update().

Generated on Tue Jun 29 16:36:15 2010 by  doxygen 1.6.3