From: Ben Harris Date: Sat, 3 Nov 2018 11:56:58 +0000 (+0000) Subject: Make the "pulse" have non-zero width. X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~bjharris/git?a=commitdiff_plain;h=886a85f030cdbadd2e4bc696b20695e128f37907;p=clunk.git Make the "pulse" have non-zero width. Since I think most impulse clocks advance on the trailing edge of the pulse, this requires subtracting the pulse width from the wake-up time. --- diff --git a/clunk.c b/clunk.c index bba7013..821391f 100644 --- a/clunk.c +++ b/clunk.c @@ -3,11 +3,17 @@ #include #include +long const pulsewidth = 250000000; /* nanoseconds */ + static void pulse() { + struct timespec const ts = { 0, pulsewidth }; /* Dummy implementation */ - printf("tick!\n"); + printf("ker..."); + fflush(stdout); + clock_nanosleep(CLOCK_MONOTONIC, 0, &ts, NULL); + printf("chunk!\n"); } static void @@ -25,7 +31,8 @@ run() ts.tv_nsec = 0; ts.tv_sec -= tm.tm_sec % 30; /* Choose when next tick will be. */ - ts.tv_sec += 30; + ts.tv_nsec = 1000000000 - pulsewidth; + ts.tv_sec += 29; if (clock_nanosleep(CLOCK_REALTIME, TIMER_ABSTIME, &ts, NULL) != 0) err(1, "clock_nanosleep");