00001 00011 #include <includes.h> 00012 00013 #define DEFAULT_HEARTBEAT_PERIOD (9) //in units of schedule periods (usually 1 ms) 00014 00015 static int hb_state = 0; 00016 static int hb_period = DEFAULT_HEARTBEAT_PERIOD; 00017 static VOID_VOID_F hb_function = voidvoid; 00018 static INT_VOID_F hb_get_timestamp = intvoid; 00028 void hb_init(int period, VOID_VOID_F func, INT_VOID_F get_time){ 00029 hb_period = period; 00030 hb_function = func; 00031 hb_get_timestamp = get_time; 00032 } 00033 00039 static void hb_update(int count){ 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 } 00046 00050 void hb_beat(void){ 00051 hb_update(hb_get_timestamp()); 00052 } 00053 00060 int hb_get_count(void){ 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 }
1.6.3