--- /dev/null
+Clunk might one day be a program for driving an impulse electric clock
+from a GPIO line.
+
+The general plan is to generate a pulse every 30 s (at 0 s and 30 s
+past each minute), with extra magic to adjust the clock at startup and
+at the start and end of summer time.
--- /dev/null
+#include <err.h>
+#include <stdbool.h>
+#include <stdio.h>
+#include <time.h>
+
+static void
+pulse()
+{
+ /* Dummy implementation */
+ printf("tick!\n");
+}
+
+static void
+run()
+{
+ struct timespec ts;
+ struct tm tm;
+
+ while (true) {
+ if (clock_gettime(CLOCK_REALTIME, &ts) != 0)
+ err(1, "clock_gettime");
+ if (localtime_r(&ts.tv_sec, &tm) == NULL)
+ err(1, "localtime_r");
+ /* Round down to the last 30 s. */
+ ts.tv_nsec = 0;
+ ts.tv_sec -= tm.tm_sec % 30;
+ /* Choose when next tick will be. */
+ ts.tv_sec += 30;
+ if (clock_nanosleep(CLOCK_REALTIME, TIMER_ABSTIME, &ts, NULL)
+ != 0)
+ err(1, "clock_nanosleep");
+ pulse();
+ }
+}
+
+int
+main(int argc, char **argv)
+{
+
+ run();
+ return 0;
+}