diff options
author | Keith Packard <keithp@keithp.com> | 2017-11-17 23:27:36 -0800 |
---|---|---|
committer | Keith Packard <keithp@keithp.com> | 2017-11-17 23:27:36 -0800 |
commit | 65fb0ad8693407cc9bd114424c1f51b6aa6befc3 (patch) | |
tree | 1ff9efb8f31a7a89e5171c0a1a9c4518226c0146 /src | |
parent | cf5729a0bae51172f12fc9ec4339d4e975a45fcc (diff) |
altos/test: Add jiffy funcs to lisp test
Signed-off-by: Keith Packard <keithp@keithp.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/test/ao_lisp_os.h | 19 |
1 files changed, 14 insertions, 5 deletions
diff --git a/src/test/ao_lisp_os.h b/src/test/ao_lisp_os.h index 9ff2e1fe..9b021900 100644 --- a/src/test/ao_lisp_os.h +++ b/src/test/ao_lisp_os.h @@ -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 |