]> git.tdb.fi Git - model-railway-devices.git/blob - common/clock.c
Provide peak current since last read
[model-railway-devices.git] / common / clock.c
1 #include "clock.h"
2 #include "timer.h"
3
4 #ifndef CLOCK_TIMER
5 #error CLOCK_TIMER must be defined
6 #endif
7
8 static volatile uint32_t time = 0;
9
10 void clock_start()
11 {
12         timer_start_hz(CLOCK_TIMER, CLOCK_RATE, 1);
13 }
14
15 void clock_stop()
16 {
17         timer_stop(CLOCK_TIMER);
18 }
19
20 uint32_t clock_get()
21 {
22         cli();
23         uint32_t t = time;
24         sei();
25         return t;
26 }
27
28 void tick()
29 {
30         ++time;
31 }
32
33 #define SET_CLOCK_CALLBACK(n) TIMER_SET_CALLBACK(n, tick)
34 SET_CLOCK_CALLBACK(CLOCK_TIMER)