altos/lisp: Finish first pass through r7rs
[fw/altos] / src / lisp / ao_lisp_os.h
index b7bf7a2cd825385abdfb9478a5bed5e1293cd3c7..4285cb8c1d584f84892a1bb9a87362c0abb1a749 100644 (file)
 #include <stdlib.h>
 #include <time.h>
 
-static inline int
-ao_lisp_getc() {
-       return getchar();
-}
+extern int ao_lisp_getc(void);
 
 static inline void
-ao_lisp_os_flush() {
+ao_lisp_os_flush(void) {
        fflush(stdout);
 }
 
@@ -44,13 +41,23 @@ 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)
 {
        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