diff options
author | Keith Packard <keithp@keithp.com> | 2017-11-17 23:23:50 -0800 |
---|---|---|
committer | Keith Packard <keithp@keithp.com> | 2017-11-17 23:26:59 -0800 |
commit | cf5729a0bae51172f12fc9ec4339d4e975a45fcc (patch) | |
tree | f67bef57d31f5f202718f7e8dbc6f41ac6b6c346 /src/lisp/ao_lisp_os.h | |
parent | e1acf5eb12aceda7aa838df031c1da1129d0fa5d (diff) |
altos/lisp: Finish first pass through r7rs
* print -> write, patom -> display
* Add read-char, write-char
* Add exit, current-jiffy, current-second, jiffies-per-second
* Add for-each and string-for-each
* Avoid duplicate builtins with different atoms
Signed-off-by: Keith Packard <keithp@keithp.com>
Diffstat (limited to 'src/lisp/ao_lisp_os.h')
-rw-r--r-- | src/lisp/ao_lisp_os.h | 16 |
1 files changed, 13 insertions, 3 deletions
diff --git a/src/lisp/ao_lisp_os.h b/src/lisp/ao_lisp_os.h index 5fa3686b..4285cb8c 100644 --- a/src/lisp/ao_lisp_os.h +++ b/src/lisp/ao_lisp_os.h @@ -41,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 |