From 6708da2661d693f855b6f56d69af1e2fb8502463 Mon Sep 17 00:00:00 2001 From: Lars-Dominik Braun Date: Tue, 23 Sep 2014 17:24:57 +0200 Subject: Add wakeup source mechanism Should reduce amount of cpu wakeups with expensive computations. --- common.h | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'common.h') diff --git a/common.h b/common.h index 5957da3..fb53d4d 100644 --- a/common.h +++ b/common.h @@ -23,5 +23,27 @@ } \ } +#include + +/* global wakeup flag, incremented by functions that interact with the main + * loop (i.e. not pwm) */ +extern volatile uint8_t wakeup; + +/* wakeup sources */ +enum { + WAKE_ACCEL = 0, + WAKE_GYRO = 1, + WAKE_I2C = 2, + WAKE_TIMER = 3, +}; + +#define shouldWakeup(x) (wakeup & (1 << x)) +#define enableWakeup(x) wakeup |= 1 << x; +#include +#define disableWakeup(x) \ + ATOMIC_BLOCK (ATOMIC_FORCEON) { \ + wakeup &= ~(1 << x); \ + } + #endif /* COMMON_H */ -- cgit v1.2.3