+/*
+ * File: tmr32.h
+ *
+ * A very simple module that triggers an ISR once every 2 seconds. tmr32 relies
+ * on Timer 1 and a watch crystal.
+ *
+ * Later tmr and tmr32 modules can merge into a generic solution. To that end,
+ * one should note that Timer 1 must be in sync to use a compare moudule when
+ * the CPU is running, and it must not be synced to run while the CPU is in
+ * sleep. When in sleep, the comparator can't work, but Timer 1 overflow events
+ * will trigger and wake the CPU.
+ */
+
+#ifndef _TMR32_H
+#define _TMR32_H
+
+/* Initialize the tmr subsystem */
+void tmr32_init();
+
+/* Set the number of seconds, which is decremented by 2 every 2 seconds. When
+ * zero is reached, TASK_TMR32 is posted.
+ */
+void tmr32_set(unsigned twosecs);
+
+/* The tmr32 isr */
+void tmr32_isr();
+
+/* Wait for c clocks, 0 <= c < 32768. */
+#define tmr32_cwait(c) \
+ do { \
+ unsigned t0 = TMR1; \
+ while (TMR0 - t0 <= c); \
+ } while (0)
+
+#endif