From d90dd1ceace4621a50b0f9961bac411bfba1c11f Mon Sep 17 00:00:00 2001 From: Brad Nelson Date: Fri, 5 Mar 2021 21:50:57 -0800 Subject: [PATCH] Adding posix clocks, optionally ms yields. --- ueforth/common/tasking_tester.fs | 11 +++++++++++ ueforth/common/tasks.fs | 4 ++++ ueforth/posix/posix.fs | 17 +++++++++++++++++ 3 files changed, 32 insertions(+) create mode 100644 ueforth/common/tasking_tester.fs diff --git a/ueforth/common/tasking_tester.fs b/ueforth/common/tasking_tester.fs new file mode 100644 index 0000000..f78ce15 --- /dev/null +++ b/ueforth/common/tasking_tester.fs @@ -0,0 +1,11 @@ +( Trying some things with tasks ) + +: printer1 begin 42 emit 1000 ms again ; +: printer2 begin 43 emit 500 ms again ; +: runner begin pause again ; + +' printer1 1000 1000 task print1 +' printer2 1000 1000 task print2 +print1 start-task +print2 start-task +runner diff --git a/ueforth/common/tasks.fs b/ueforth/common/tasks.fs index 78410ae..27520e2 100644 --- a/ueforth/common/tasks.fs +++ b/ueforth/common/tasks.fs @@ -30,6 +30,10 @@ forth definitions tasks task-list @ 2 cells + @ rp! ; +DEFINED? ms-ticks [IF] + : ms ( n -- ) ms-ticks >r begin pause ms-ticks r@ - over >= until rdrop drop ; +[THEN] + tasks definitions 0 0 0 task main-task main-task start-task forth definitions diff --git a/ueforth/posix/posix.fs b/ueforth/posix/posix.fs index 2e5befd..2cc16bd 100644 --- a/ueforth/posix/posix.fs +++ b/ueforth/posix/posix.fs @@ -139,6 +139,23 @@ O_RDWR constant r/w dup 0 SEEK_END lseek r> swap >r SEEK_SET lseek drop r> d0r 0 >r CLOCK_MONOTONIC_RAW rp@ cell - clock_gettime throw + r> 1000000 / r> 1000 * + ; + ( Other Utils ) : ms ( n -- ) 1000 * usleep drop ;