From aa5604d118bc89e85c8230562080c034bfc9df17 Mon Sep 17 00:00:00 2001 From: Michael Buesch Date: Sun, 3 May 2009 12:35:53 +0200 Subject: pressure-control: Implement idle-release of valves through timer. Signed-off-by: Michael Buesch --- pressure_control/firmware/main.h | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'pressure_control/firmware/main.h') diff --git a/pressure_control/firmware/main.h b/pressure_control/firmware/main.h index edb8694..d8cb6aa 100644 --- a/pressure_control/firmware/main.h +++ b/pressure_control/firmware/main.h @@ -6,6 +6,27 @@ #include +typedef uint16_t jiffies_t; +typedef int16_t s_jiffies_t; + +/* Jiffies timing helpers derived from the Linux Kernel sources. + * These inlines deal with timer wrapping correctly. + * + * time_after(a, b) returns true if the time a is after time b. + * + * Do this with "<0" and ">=0" to only test the sign of the result. A + * good compiler would generate better code (and a really good compiler + * wouldn't care). Gcc is currently neither. + */ +#define time_after(a, b) ((s_jiffies_t)(b) - (s_jiffies_t)(a) < 0) +#define time_before(a, b) time_after(b, a) + +#define JIFFIES_PER_SECOND 1000 +#define msec_to_jiffies(msec) ((jiffies_t)((uint32_t)JIFFIES_PER_SECOND * (uint32_t)(msec) / (uint32_t)1000)) + +jiffies_t get_jiffies(void); + + struct pressure_config { /* Desired pressure in mBar */ uint16_t desired; -- cgit v1.2.3