chiark / gitweb /
Make the "pulse" have non-zero width.
authorBen Harris <bjh21@bjh21.me.uk>
Sat, 3 Nov 2018 11:56:58 +0000 (11:56 +0000)
committerBen Harris <bjh21@bjh21.me.uk>
Sat, 3 Nov 2018 11:56:58 +0000 (11:56 +0000)
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.

clunk.c

diff --git a/clunk.c b/clunk.c
index bba7013209f28472d88ad5980789a089063392ad..821391f7ada2de42e181c7605695880220a9051e 100644 (file)
--- a/clunk.c
+++ b/clunk.c
@@ -3,11 +3,17 @@
 #include <stdio.h>
 #include <time.h>
 
+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");