timers.c File Reference

Include functions for initialization, starting and destroing timers. More...

#include "timers.h"
#include "sys.h"
#include "errnums.h"
#include "debug.h"
#include "io.h"
#include "malloc.h"

Functions

int timer_init (struct timer *tmr, const unsigned int usec, void(*handler)(struct timer *, void *), void *data)
 Function inicialized structure of timer.
void timer_start (struct timer *tmr)
 Function activate timer.
void timer_destroy (struct timer *tmr)
 Function deactivate timer.
void timer_debug (void)
 Debug walk trough.
int timer_pending (struct timer *tmr)
 Function return that the timer is pending.
void timer_check ()
 Function is searching for timers with runned out delay.
unsigned get_sysutime ()
 Function returns count of microseconds from cpu start.
int init_timers ()
 Function initialized list of timers.

Variables

timer_listtimer_ll
 A global list of timers in the system.


Detailed Description

Include functions for initialization, starting and destroing timers.

Timers are system structures, that allows threads raise asynchronous event. There is no need to allocate memory for this event, like threads must when creating new thread. The timer handling function is called after delay, that thread can specified. Timers handling functions runs in context of thread, that was interuppted. Timers are storage in list, where timer structure has pointer to next timer.


Function Documentation

unsigned get_sysutime (  ) 

Function returns count of microseconds from cpu start.

Returns:
Number of microseconds from cpu start

int init_timers (  ) 

Function initialized list of timers.

Returns:
EOK on success or ENOMEM on system memory lack

void timer_check (  ) 

Function is searching for timers with runned out delay.

Function walk trough the list of timers. If the delay is runned out (count of cpu cycles is less than stop_cycle) the timer is destroyed and handle function is called with parametres, that point to timer and inserted data.

void timer_debug ( void   ) 

Debug walk trough.

Walk trough list of timers and print timers pointer and next pointer.

void timer_destroy ( struct timer tmr  ) 

Function deactivate timer.

Parameters:
tmr - pointer to timer structure
Function walk trough list of timers and find out the timer in parametr. This timer is stopped, stop cycle is set to 0, and is remove from list of timers.

int timer_init ( struct timer tmr,
const unsigned int  usec,
void(*)(struct timer *, void *)  handler,
void *  data 
)

Function inicialized structure of timer.

Parameters:
tmr - pointer to timer structure
usec - count of microseconds, that determine delay of timer
handler - pointer to function, that is called after delay is runned out
data - pointer to data, that are passed to handler
Returns:
- EINVAL - if the handler is NULL, otherwise EOK
Function inicialized structure of timer for time usec microseconds. Parameters are stored into timer structure and stop_cycle value is set to 0, which means, that timer is not pending. Timer structure is not inserted into list of timers!!

int timer_pending ( struct timer tmr  ) 

Function return that the timer is pending.

Parameters:
tmr - pointer to timer structure
Returns:
- 1 if the timer is pending, otherwise 0
Function return 1 if the timer is pending, it means that stop cycle is great than actual count of cpu cycles from cpu start. Otherwise function return 0.

void timer_start ( struct timer tmr  ) 

Function activate timer.

Parameters:
tmr - pointer to timer structure
Function activate timer and insert it to the tail of list of active timers. Activation mean that the stop_cycle value is set to count of cpu cycles + timer microseconds multiply by cpu cycles per microseconds. If the timer in argument is pending, than it is restarted - it stay in list of active timers and stop_cycle value is again computed to the new value


Generated on Wed Nov 15 17:25:44 2006 for Kalisto by  doxygen 1.4.7