-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathtimer.h
44 lines (32 loc) · 1.04 KB
/
timer.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#ifndef TIMER_H
#define TIMER_H
#include "dev_data.h"
#include "features.h"
#ifdef HAVE_TIMER
typedef struct {
int16_t last;
} timer_t;
/* return True every sec tenth seconds */
char timer_done(timer_t *t);
void timer_start(int16_t sec, timer_t *t);
int16_t timer_remaining(timer_t *t);
void timer_reset(timer_t *t);
int16_t timer_counter(void);
/**
* The point of 'reset_delta' is: assume every(20,&t) controls a 50% PWM output
* and is called half a second too late at the end of the 'off' phase. You have
* three choices:
* = do nothing: the 'on' phase will last 1.5 seconds, thus the next on>off
* transition isn't delayed.
* = call reset(): 'on' will be 2.0 seconds, thus keeping individual timing
* as accurately aspossible
* = call reset_delta(20,&t): 'on' will be 2.5 seconds, thereby making sure
* that the on/off ratio isn't disturbed too much.
*/
void timer_init(void);
void timer_poll(void);
#else // no timer
#define timer_init() do {} while(0)
#define timer_poll() do {} while(0)
#endif // !HAVE_TIMER
#endif // timer_h