summaryrefslogtreecommitdiff
path: root/src/drivers/ao_event.c
diff options
context:
space:
mode:
authorKeith Packard <keithp@keithp.com>2016-04-05 23:45:52 -0700
committerKeith Packard <keithp@keithp.com>2016-04-19 23:21:30 -0400
commit70e46100acf597014ce54cf3b642254ce1cba59b (patch)
tree361824076b35ac39ae3d427a2a2b0127753a238f /src/drivers/ao_event.c
parentaef5049cf8311927fada922730f85f31c8ddf177 (diff)
altos/telelcotwo: Add idle timeout
Puts TeleLCOTwo in a low power state (drawing about 80µA) after a timeout (default two minutes) to keep from killing the battery if the device is left turned on. Signed-off-by: Keith Packard <keithp@keithp.com>
Diffstat (limited to 'src/drivers/ao_event.c')
-rw-r--r--src/drivers/ao_event.c16
1 files changed, 16 insertions, 0 deletions
diff --git a/src/drivers/ao_event.c b/src/drivers/ao_event.c
index 5c0d2863..8f88d778 100644
--- a/src/drivers/ao_event.c
+++ b/src/drivers/ao_event.c
@@ -41,6 +41,22 @@ ao_event_get(struct ao_event *ev)
);
}
+uint8_t
+ao_event_get_for(struct ao_event *ev, uint16_t timeout)
+{
+ uint8_t empty = 1;
+ ao_arch_critical(
+ while ((empty = ao_event_queue_empty()))
+ if (ao_sleep_for(&ao_event_queue, timeout))
+ break;
+ if (!empty) {
+ *ev = ao_event_queue[ao_event_queue_remove];
+ ao_event_queue_remove = ao_event_queue_next(ao_event_queue_remove);
+ }
+ );
+ return empty;
+}
+
/* called with interrupts disabled */
void
ao_event_put_isr(uint8_t type, uint8_t unit, int32_t value)