Welcome to the EyeBot  Version 7 - RPi1
A Controller For Various Hardware IO
Functions | Variables
timer.c File Reference

Sets up and runs functions at given times. More...

#include "timer.h"
#include <unistd.h>

Functions

void core_timer (int sig)
 The core timer. Determines whether or not it is time to run one of the functions that have timers attached to them. More...
 
void initialise_core_timer (void)
 Begins an alarm which calls the "core_timer" function every 1ms * rate producing a calling frequency of 1kHz / rate.
 
int OSWait (int n)
 Waits for 1 ms. More...
 
Timer OSAttachTimer (int scale, void(*fct)(void))
 adds a function to a 1kHz/scale timer, ie. executes every 1ms*scale usage: OSAttachTimer(<scale>, &<function>); More...
 
int OSDetachTimer (Timer handle)
 removes the Timer from the list More...
 
int OSSetTime (int hrs, int mins, int secs)
 sets the system time More...
 
int OSGetTime (int *hrs, int *mins, int *secs, int *ticks)
 Get system time (ticks in 1/100 sec) More...
 
int OSShowTime (void)
 prints the time on the command line More...
 
int OSGetCount (void)
 gives you the count in 1/100 sec since the system start More...
 

Variables

void(* _functions [16])(void) = {NULL}
 
int _function_timer_scales [16] = {0}
 
int _timers_active = 0
 
int _core_timedev = 1000
 
int _clock_ticks = 0
 

Detailed Description

Sets up and runs functions at given times.

Author
Rhys Kessey
Marcus Pham (cleaned up)

These timer functions were written by Rhys Kessey The functions deal with two global variables, functions[] and function_timer_scales[] Every time a timer is linked to a function, values will be added to these arrays Every clock tick (determined by the rate that core_timer is called) these functions will be checked if the current clock tick is a multiple of a function scale, then the function will be executed. eg. functions[] = {f1,f2,f3,f4,NULL,NULL,NULL....} function_timer_scales[] = {1 ,2 ,1 ,4 ,0 ,0 ,0 ....} then every clock tick, f1 and f3 will be executed (in that order) every 2 clock ticks, f2 will be executed every 4 clock ticks, f4 will be executed

Function Documentation

void core_timer ( int  sig)

The core timer. Determines whether or not it is time to run one of the functions that have timers attached to them.

Parameters
sigthe signal
Timer OSAttachTimer ( int  scale,
void(*)(void)  fct 
)

adds a function to a 1kHz/scale timer, ie. executes every 1ms*scale usage: OSAttachTimer(<scale>, &<function>);

Parameters
scalethe rate to run the function
fctthe function to run, note must return void and have no arguments
Returns
the Timer struct for the timer
int OSDetachTimer ( Timer  handle)

removes the Timer from the list

Parameters
handlethe timer to remove
Returns
0 always
int OSGetCount ( void  )

gives you the count in 1/100 sec since the system start

Returns
the count
int OSGetTime ( int *  hrs,
int *  mins,
int *  secs,
int *  ticks 
)

Get system time (ticks in 1/100 sec)

Parameters
hrsthe pointer to the hours integer
minsthe pointer to the mins integer
secsthe pointer to the secs integer
ticksthe pointer to the ticks integer
Returns
0 always
int OSSetTime ( int  hrs,
int  mins,
int  secs 
)

sets the system time

Parameters
hrsthe hours
minsthe mins
secsthe secs
Returns
0 always
int OSShowTime ( void  )

prints the time on the command line

Returns
0 always
int OSWait ( int  n)

Waits for 1 ms.

Parameters
nthe number of ms to wait for
Returns
0 always