aboutsummaryrefslogtreecommitdiff
path: root/tmk_core/common/chibios/timer.c
diff options
context:
space:
mode:
authorskullY <skullydazed@gmail.com>2019-08-30 11:19:03 -0700
committerskullydazed <skullydazed@users.noreply.github.com>2019-08-30 15:01:52 -0700
commitb624f32f944acdc59dcb130674c09090c5c404cb (patch)
treebc13adbba137d122d9a2c2fb2fafcbb08ac10e25 /tmk_core/common/chibios/timer.c
parent61af76a10d00aba185b8338604171de490a13e3b (diff)
downloadqmk_firmware-b624f32f944acdc59dcb130674c09090c5c404cb.tar.gz
qmk_firmware-b624f32f944acdc59dcb130674c09090c5c404cb.zip
clang-format changes
Diffstat (limited to 'tmk_core/common/chibios/timer.c')
-rw-r--r--tmk_core/common/chibios/timer.c46
1 files changed, 19 insertions, 27 deletions
diff --git a/tmk_core/common/chibios/timer.c b/tmk_core/common/chibios/timer.c
index 473e533ca..1ce9d1d17 100644
--- a/tmk_core/common/chibios/timer.c
+++ b/tmk_core/common/chibios/timer.c
@@ -2,40 +2,32 @@
2 2
3#include "timer.h" 3#include "timer.h"
4 4
5static systime_t last_systime = 0; 5static systime_t last_systime = 0;
6static systime_t overflow = 0; 6static systime_t overflow = 0;
7static uint32_t current_time_ms = 0; 7static uint32_t current_time_ms = 0;
8 8
9void timer_init(void) { 9void timer_init(void) { timer_clear(); }
10 timer_clear();
11}
12 10
13void timer_clear(void) { 11void timer_clear(void) {
14 last_systime = chVTGetSystemTime(); 12 last_systime = chVTGetSystemTime();
15 overflow = 0; 13 overflow = 0;
16 current_time_ms = 0; 14 current_time_ms = 0;
17} 15}
18 16
19uint16_t timer_read(void) { 17uint16_t timer_read(void) { return (uint16_t)timer_read32(); }
20 return (uint16_t)timer_read32();
21}
22 18
23uint32_t timer_read32(void) { 19uint32_t timer_read32(void) {
24 // Note: We assume that the timer update is called at least once betweeen every wrap around of the system time 20 // Note: We assume that the timer update is called at least once betweeen every wrap around of the system time
25 systime_t current_systime = chVTGetSystemTime(); 21 systime_t current_systime = chVTGetSystemTime();
26 systime_t elapsed = current_systime - last_systime + overflow; 22 systime_t elapsed = current_systime - last_systime + overflow;
27 uint32_t elapsed_ms = ST2MS(elapsed); 23 uint32_t elapsed_ms = ST2MS(elapsed);
28 current_time_ms += elapsed_ms; 24 current_time_ms += elapsed_ms;
29 overflow = elapsed - MS2ST(elapsed_ms); 25 overflow = elapsed - MS2ST(elapsed_ms);
30 last_systime = current_systime; 26 last_systime = current_systime;
31 27
32 return current_time_ms; 28 return current_time_ms;
33} 29}
34 30
35uint16_t timer_elapsed(uint16_t last) { 31uint16_t timer_elapsed(uint16_t last) { return timer_read() - last; }
36 return timer_read() - last;
37}
38 32
39uint32_t timer_elapsed32(uint32_t last) { 33uint32_t timer_elapsed32(uint32_t last) { return timer_read32() - last; }
40 return timer_read32() - last;
41}