aboutsummaryrefslogtreecommitdiff
path: root/tmk_core/common/timer.h
diff options
context:
space:
mode:
Diffstat (limited to 'tmk_core/common/timer.h')
-rw-r--r--tmk_core/common/timer.h28
1 files changed, 10 insertions, 18 deletions
diff --git a/tmk_core/common/timer.h b/tmk_core/common/timer.h
index a8dd85663..853cb9839 100644
--- a/tmk_core/common/timer.h
+++ b/tmk_core/common/timer.h
@@ -22,16 +22,14 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
22#include <stdbool.h> 22#include <stdbool.h>
23 23
24#if defined(__AVR__) 24#if defined(__AVR__)
25#include "avr/timer_avr.h" 25# include "avr/timer_avr.h"
26#endif 26#endif
27 27
28 28#define TIMER_DIFF(a, b, max) ((a) >= (b) ? (a) - (b) : (max) - (b) + (a))
29#define TIMER_DIFF(a, b, max) ((a) >= (b) ? (a) - (b) : (max) - (b) + (a)) 29#define TIMER_DIFF_8(a, b) TIMER_DIFF(a, b, UINT8_MAX)
30#define TIMER_DIFF_8(a, b) TIMER_DIFF(a, b, UINT8_MAX) 30#define TIMER_DIFF_16(a, b) TIMER_DIFF(a, b, UINT16_MAX)
31#define TIMER_DIFF_16(a, b) TIMER_DIFF(a, b, UINT16_MAX) 31#define TIMER_DIFF_32(a, b) TIMER_DIFF(a, b, UINT32_MAX)
32#define TIMER_DIFF_32(a, b) TIMER_DIFF(a, b, UINT32_MAX) 32#define TIMER_DIFF_RAW(a, b) TIMER_DIFF_8(a, b)
33#define TIMER_DIFF_RAW(a, b) TIMER_DIFF_8(a, b)
34
35 33
36#ifdef __cplusplus 34#ifdef __cplusplus
37extern "C" { 35extern "C" {
@@ -39,23 +37,17 @@ extern "C" {
39 37
40extern volatile uint32_t timer_count; 38extern volatile uint32_t timer_count;
41 39
42 40void timer_init(void);
43void timer_init(void); 41void timer_clear(void);
44void timer_clear(void);
45uint16_t timer_read(void); 42uint16_t timer_read(void);
46uint32_t timer_read32(void); 43uint32_t timer_read32(void);
47uint16_t timer_elapsed(uint16_t last); 44uint16_t timer_elapsed(uint16_t last);
48uint32_t timer_elapsed32(uint32_t last); 45uint32_t timer_elapsed32(uint32_t last);
49 46
50// Utility functions to check if a future time has expired & autmatically handle time wrapping if checked / reset frequently (half of max value) 47// Utility functions to check if a future time has expired & autmatically handle time wrapping if checked / reset frequently (half of max value)
51inline bool timer_expired(uint16_t current, uint16_t last) 48inline bool timer_expired(uint16_t current, uint16_t last) { return current - last < 0x8000; }
52{
53 return current - last < 0x8000;
54}
55 49
56inline bool timer_expired32(uint32_t current, uint32_t future) { 50inline bool timer_expired32(uint32_t current, uint32_t future) { return current - future < 0x80000000; }
57 return current - future < 0x80000000;
58}
59 51
60#ifdef __cplusplus 52#ifdef __cplusplus
61} 53}