+/* -------- INTERNAL FUNCTIONS -------- */
+
+static void gpioHandler(uint8_t id) {
+ uint8_t i;
+ uint16_t now, left;
+
+ if (timerActive[id])
+ return;
+ timerActive[id] = true;
+ now = TA1R;
+ timerPoint[id] = now + ACLK_TICKS_PER_SECOND; // One second ahead
+ left = ACLK_TICKS_PER_SECOND;
+ for (i = 0; i < 3; i++)
+ if (timerActive[i] && (timerPoint[i] - now) < left) {
+ left = timerPoint[i] - now;
+ }
+ TA1CCR0 = now + left;
+ TA1CCTL0 = CCIE;
+}
+
+static void tickHandler(uint16_t clock) {
+ uint8_t i;
+
+ for (i = 0; i < 3; i++)
+ if (timerActive[i] && timerPoint[i] == clock) {
+ uint32_t count = Hal_gpioCount(i);
+
+ if (count) {
+ ; // update timer; call jitter handler
+ } else {
+ ; // clear timer; call app gpio handler
+ }
+ }
+ // if all timers are unset, disable ticker.
+}
+
+static void postEvent(uint8_t handlerId) {
+ uint8_t key = Em_Hal_lock();
+ handlerEvents |= 1 << handlerId;
+ Em_Hal_unlock(key);
+}