timer.h File Reference

#include <compiler.h>

Go to the source code of this file.

Defines

#define INVALID_TIMER_ID   0xFFFFFFFF
#define TIMER_HZ   4

Enumerations

enum  { TIMEOUT_ONESHOT, TIMEOUT_PERIODIC }

Functions

void timer_cancel_timeout (U32 id)
void timer_delay (U32 ms)
U32 timer_get_ms (void)
void timer_init (void(*tick_isr)(void *ctx), void *ctx)
void timer_poll (void)
 Called from application main loop to invoke any scheduled timeout cbs.
U32 timer_sched_timeout_cb (U32 ms, U8 type, void(*cb)(void *ctx), void *ctx)


Define Documentation

#define INVALID_TIMER_ID   0xFFFFFFFF

Definition at line 38 of file timer.h.

#define TIMER_HZ   4

Definition at line 47 of file timer.h.


Enumeration Type Documentation

anonymous enum

Enumerator:
TIMEOUT_ONESHOT 
TIMEOUT_PERIODIC 

Definition at line 33 of file timer.h.

00033      {
00034         TIMEOUT_ONESHOT,
00035         TIMEOUT_PERIODIC
00036 };


Function Documentation

void timer_cancel_timeout ( U32  id  ) 

Definition at line 163 of file timer.c.

References timeout_t::expired, timer_t::timeout, TIMER, and TRUE.

00164 {
00165         struct timer_t* priv = &TIMER;
00166         struct timeout_t* tmo;
00167     
00168         tmo = &priv->timeout[id];
00169         tmo->expired = TRUE;
00170 }

void timer_delay ( U32  ms  ) 

Definition at line 88 of file timer.c.

References timer_t::MS_PER_TICK, timer_t::tick, and TIMER.

00089 {
00090         struct timer_t* priv = &TIMER;
00091         U32 expire_at_tick = priv->tick + ms / priv->MS_PER_TICK;
00092         while (priv->tick < expire_at_tick);
00093 }

U32 timer_get_ms ( void   ) 

Definition at line 82 of file timer.c.

References timer_t::MS_PER_TICK, timer_t::tick, and TIMER.

Referenced by cmd_ping(), init_ping_info(), ping_recv(), ping_send(), poll(), print_stats(), tcp_accept_cb(), tcp_connect_cb(), ttcp_print_stats(), udp_recv_cb(), and udp_send_data().

00083 {
00084         struct timer_t* priv = &TIMER;
00085         return priv->tick * priv->MS_PER_TICK;
00086 }

void timer_init ( void(*)(void *ctx tick_isr,
void *  ctx 
)

Definition at line 62 of file timer.c.

References ARRAY_SIZE, timer_t::ctx, timeout_t::expired, irq_handler(), timer_t::MS_PER_TICK, timer_t::tick_isr, timer_t::timeout, TIMER, and TRUE.

Referenced by main().

00063 {
00064         struct timer_t* priv = &TIMER;
00065         uint8_t id;
00066         
00067         INTC_register_interrupt(&irq_handler, AVR32_RTC_IRQ, AVR32_INTC_INT0);
00068         if (!rtc_init(&AVR32_RTC, RTC_OSC_RC, 0))
00069                 Assert(0);
00070 
00071     priv->tick_isr = tick_isr;
00072     priv->ctx = ctx;
00073         rtc_set_top_value(&AVR32_RTC, 115 * priv->MS_PER_TICK / 2);
00074         rtc_enable_interrupt(&AVR32_RTC);
00075         rtc_enable(&AVR32_RTC);
00076 
00077         for (id = 0; id < ARRAY_SIZE(priv->timeout); id++)
00078                 priv->timeout[id].expired = TRUE;
00079 }

void timer_poll ( void   ) 

Called from application main loop to invoke any scheduled timeout cbs.

This function might be called as often as possible rather than at each tick to support the timeout value '0', e.g a timeout within less than one tick.

Definition at line 101 of file timer.c.

References ARRAY_SIZE, timeout_t::cb, timeout_t::ctx, timeout_t::expire_at_tick, timeout_t::expired, timeout_t::tick, timer_t::tick, timer_t::timeout, TIMEOUT_PERIODIC, TIMER, TRUE, and timeout_t::type.

Referenced by poll().

00102 {
00103         struct timer_t* priv = &TIMER;
00104         U8 i;
00105 
00106         for (i = 0; i < ARRAY_SIZE(priv->timeout); i++) {
00107                 struct timeout_t* tmo = &priv->timeout[i];
00108                 if (tmo->expired)
00109                         continue;
00110         
00111                 if (tmo->expire_at_tick > priv->tick)
00112                         continue;
00113 
00114                 if (tmo->cb)
00115                         tmo->cb(tmo->ctx);
00116                 
00117                 if (tmo->type == TIMEOUT_PERIODIC)
00118                         tmo->expire_at_tick = priv->tick + tmo->tick;
00119                 else
00120                         tmo->expired = TRUE;
00121         }
00122 }

U32 timer_sched_timeout_cb ( U32  ms,
U8  type,
void(*)(void *ctx cb,
void *  ctx 
)

Definition at line 147 of file timer.c.

References timeout_t::cb, cb, timeout_t::ctx, timer_t::timeout, TIMER, and timer_sched_timeout().

Referenced by tcp_send_data(), tcp_timeout_cb(), udp_send_data(), and wl_init_complete_cb().

00148 {
00149         struct timer_t* priv = &TIMER;
00150         struct timeout_t* tmo;
00151         U8 id;
00152 
00153         Assert(cb);
00154         id = timer_sched_timeout(ms, type);
00155         tmo = &priv->timeout[id];
00156 
00157         tmo->cb = cb;
00158         tmo->ctx = ctx;
00159         return id;
00160 }


Generated on Fri Feb 19 02:24:08 2010 for AVR32 - H&D by  doxygen 1.5.5