OpenWSN Firmware
opentimers.h
Go to the documentation of this file.
1 
7 #ifndef __OPENTIMERS_H
8 #define __OPENTIMERS_H
9 
10 #include "openwsn.h"
11 
19 //=========================== define ==========================================
20 
22 #define MAX_NUM_TIMERS 10
23 
24 #define MAX_TICKS_IN_SINGLE_CLOCK ((PORT_TIMER_WIDTH)0xFFFFFFFF)
25 
26 #define TOO_MANY_TIMERS_ERROR 255
27 
28 #define opentimer_id_t uint8_t
29 
30 typedef void (*opentimers_cbt)(void);
31 
32 //=========================== typedef =========================================
33 
34 typedef enum {
37 } timer_type_t;
38 
39 /*the time can be in tics or in ms*/
40 typedef enum {
43 } time_type_t;
44 
45 typedef struct {
46  uint32_t period_ticks; // total number of clock ticks
47  PORT_TIMER_WIDTH ticks_remaining; // ticks remaining before elapses
48  uint16_t wraps_remaining; // the clock register is 16 bit, and can't count beyond 32k...
49  // so period_ticks = wraps_remaining*(32k or uint16_t)
50  timer_type_t type; // periodic or one-shot
51  bool isrunning; // is running?
52  opentimers_cbt callback; // function to call when elapses
53  bool hasExpired; // whether the callback has to be called
54 } opentimers_t;
55 
56 //=========================== module variables ================================
57 
58 typedef struct {
60  bool running;
61  PORT_TIMER_WIDTH currentTimeout; // current timeout, in ticks
63 
64 //=========================== prototypes ======================================
65 
66 void opentimers_init(void);
67 opentimer_id_t opentimers_start(uint32_t duration,
68  timer_type_t type,
69  time_type_t timetype,
70  opentimers_cbt callback);
71 void opentimers_setPeriod(opentimer_id_t id,time_type_t timetype, uint32_t newPeriod);
74 
75 void opentimers_sleepTimeCompesation(uint16_t sleepTime);
76 
82 #endif
timer_type_t type
Definition: opentimers.h:50
void opentimers_stop(opentimer_id_t id)
Stop a running timer.
Definition: opentimers.c:174
uint16_t wraps_remaining
Definition: opentimers.h:48
Definition: opentimers.h:58
Definition: opentimers.h:42
void opentimers_sleepTimeCompesation(uint16_t sleepTime)
Definition: opentimers.c:284
timer_type_t
Definition: opentimers.h:34
Definition: opentimers.h:45
void opentimers_setPeriod(opentimer_id_t id, time_type_t timetype, uint32_t newDuration)
Replace the period of a running timer.
Definition: opentimers.c:141
bool isrunning
Definition: opentimers.h:51
bool hasExpired
Definition: opentimers.h:53
uint32_t period_ticks
Definition: opentimers.h:46
Definition: opentimers.h:36
bool running
Definition: opentimers.h:60
void(* opentimers_cbt)(void)
Definition: opentimers.h:30
PORT_TIMER_WIDTH ticks_remaining
Definition: opentimers.h:47
#define opentimer_id_t
Definition: opentimers.h:28
Definition: opentimers.h:35
PORT_TIMER_WIDTH currentTimeout
Definition: opentimers.h:61
void opentimers_restart(opentimer_id_t id)
Restart a stop timer.
Definition: opentimers.c:183
opentimers_cbt callback
Definition: opentimers.h:52
void opentimers_init()
Initialize this module.
Definition: opentimers.c:33
time_type_t
Definition: opentimers.h:40
opentimer_id_t opentimers_start(uint32_t duration, timer_type_t type, time_type_t timetype, opentimers_cbt callback)
Start a timer.
Definition: opentimers.c:73
#define MAX_NUM_TIMERS
Maximum number of timers that can run concurrently.
Definition: opentimers.h:22
Definition: opentimers.h:41