altos/test: Add jiffy funcs to lisp test
[fw/altos] / src / test / ao_lisp_os.h
index 9ff2e1feb71cafb65ce1a8445b3dc49d8be731f8..9b021900d818a17358c816cae7e4e4f905054bed 100644 (file)
@@ -45,15 +45,24 @@ ao_lisp_os_led(int led)
        printf("leds set to 0x%x\n", led);
 }
 
+#define AO_LISP_JIFFIES_PER_SECOND     100
+
 static inline void
-ao_lisp_os_delay(int delay)
+ao_lisp_os_delay(int jiffies)
 {
-       if (!delay)
-               return;
        struct timespec ts = {
-               .tv_sec = delay / 1000,
-               .tv_nsec = (delay % 1000) * 1000000,
+               .tv_sec = jiffies / AO_LISP_JIFFIES_PER_SECOND,
+               .tv_nsec = (jiffies % AO_LISP_JIFFIES_PER_SECOND) * (1000000000L / AO_LISP_JIFFIES_PER_SECOND)
        };
        nanosleep(&ts, NULL);
 }
+
+static inline int
+ao_lisp_os_jiffy(void)
+{
+       struct timespec tp;
+       clock_gettime(CLOCK_MONOTONIC, &tp);
+       return tp.tv_sec * AO_LISP_JIFFIES_PER_SECOND + (tp.tv_nsec / (1000000000L / AO_LISP_JIFFIES_PER_SECOND));
+}
+
 #endif