timer.c File Reference

Hardware independent timer driver (implementation). More...

#include "timer.h"
#include "hw/hw_timer.h"
#include "cfg/cfg_timer.h"
#include "cfg/cfg_wdt.h"
#include "cfg/cfg_proc.h"
#include "cfg/cfg_signal.h"
#include <cfg/os.h>
#include <cfg/debug.h>
#include <cfg/module.h>
#include <cpu/attr.h>
#include <cpu/types.h>
#include <cpu/irq.h>
#include <cpu/power.h>
#include <kern/preempt.h>
#include <emul/timer_posix.c>
#include <kern/signal.h>
#include <kern/proc.h>
#include <cfg/macros.h>

Go to the source code of this file.

Functions

void timer_addToList (Timer *timer, List *queue)
 This function really does the job.
void timer_add (Timer *timer)
 Add the specified timer to the software timer service queue.
Timertimer_abort (Timer *timer)
 Remove a timer from the timers queue before it has expired.
void synctimer_add (Timer *timer, List *queue)
 Add timer to queue.
void synctimer_poll (List *queue)
 Simple synchronous timer based scheduler polling routine.
void timer_delayTicks (ticks_t delay)
 Wait for the specified amount of timer ticks.
void timer_busyWait (hptime_t delay)
 Busy wait until the specified amount of high-precision ticks have elapsed.
void timer_delayHp (hptime_t delay)
 Wait for the specified amount of time (expressed in microseconds).

Variables

volatile ticks_t _clock
 Master system clock (1 tick accuracy).
static REGISTER List timers_queue
 List of active asynchronous timers.

Detailed Description

Hardware independent timer driver (implementation).

Author:
Bernie Innocenti <bernie@codewiz.org>
Francesco Sacchi <batt@develer.com>

Definition in file timer.c.


Function Documentation

void synctimer_add ( Timer timer,
List queue 
)

Add timer to queue.

See also:
synctimer_poll() for details.

Definition at line 213 of file timer.c.

void synctimer_poll ( List queue  ) 

Simple synchronous timer based scheduler polling routine.

Sometimes you would like to have a proper scheduler, but you can't afford it due to memory constraints.

This is a simple replacement: you can create events and call them periodically at specific time intervals. All you have to do is to set up normal timers, and call synctimer_add() instead of timer_add() to add the events to your specific queue. Then, in the main loop or wherever you want, you can call synctimer_poll() to process expired events. The associated callbacks will be executed. As this is done synchronously you don't have to worry about race conditions. You can kill an event by simply calling synctimer_abort().

Definition at line 235 of file timer.c.

Timer* timer_abort ( Timer timer  ) 

Remove a timer from the timers queue before it has expired.

Note:
Attempting to remove a timer already expired cause undefined behaviour.

Definition at line 174 of file timer.c.

void timer_add ( Timer timer  ) 

Add the specified timer to the software timer service queue.

When the delay indicated by the timer expires, the timer device will execute the event associated with it.

Note:
Interrupt safe

Definition at line 163 of file timer.c.

void timer_addToList ( Timer timer,
List queue 
) [inline]

This function really does the job.

It adds timer to queue.

See also:
timer_add for details.

Definition at line 124 of file timer.c.

void timer_busyWait ( hptime_t  delay  ) 

Busy wait until the specified amount of high-precision ticks have elapsed.

Note:
This function is interrupt safe, the only requirement is a running hardware timer.

Definition at line 284 of file timer.c.

void timer_delayHp ( hptime_t  delay  ) 

Wait for the specified amount of time (expressed in microseconds).

Definition at line 312 of file timer.c.

void timer_delayTicks ( ticks_t  delay  ) 

Wait for the specified amount of timer ticks.

Note:
Sleeping while preemption is disabled fallbacks to a busy wait sleep.

Definition at line 248 of file timer.c.