aboutsummaryrefslogtreecommitdiffstats
path: root/src/sched.h
diff options
context:
space:
mode:
authorKevin O'Connor <kevin@koconnor.net>2016-05-25 11:37:40 -0400
committerKevin O'Connor <kevin@koconnor.net>2016-05-25 11:37:40 -0400
commitf582a36e4df16d5709943f7df17a900c8bcc12ab (patch)
tree628d927c4f3e19e54618f7f47c7a44af66bf0c2f /src/sched.h
parent37a91e9c10648208de002c75df304e23ca89e256 (diff)
downloadkutter-f582a36e4df16d5709943f7df17a900c8bcc12ab.tar.gz
kutter-f582a36e4df16d5709943f7df17a900c8bcc12ab.tar.xz
kutter-f582a36e4df16d5709943f7df17a900c8bcc12ab.zip
Initial commit of source code.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Diffstat (limited to 'src/sched.h')
-rw-r--r--src/sched.h51
1 files changed, 51 insertions, 0 deletions
diff --git a/src/sched.h b/src/sched.h
new file mode 100644
index 00000000..047ac1ce
--- /dev/null
+++ b/src/sched.h
@@ -0,0 +1,51 @@
+#ifndef __SCHED_H
+#define __SCHED_H
+
+#include <stdint.h>
+#include "board/pgm.h" // PSTR
+#include "compiler.h" // __section
+
+// Declare an init function (called at firmware startup)
+#define DECL_INIT(FUNC) _DECL_CALLBACK(initfuncs, FUNC)
+// Declare a task function (called periodically during normal runtime)
+#define DECL_TASK(FUNC) _DECL_CALLBACK(taskfuncs, FUNC)
+// Declare a shutdown function (called on an emergency stop)
+#define DECL_SHUTDOWN(FUNC) _DECL_CALLBACK(shutdownfuncs, FUNC)
+
+// Timer structure for scheduling timed events (see sched_timer() )
+struct timer {
+ struct timer *next;
+ uint8_t (*func)(struct timer*);
+ uint32_t waketime;
+};
+
+enum { SF_DONE=0, SF_RESCHEDULE=1 };
+
+// sched.c
+uint8_t sched_check_periodic(uint16_t time, uint16_t *pnext);
+uint32_t sched_from_ms(uint32_t ms);
+uint32_t sched_read_time(void);
+uint8_t sched_is_before(uint32_t time1, uint32_t time2);
+void sched_timer(struct timer*);
+void sched_del_timer(struct timer *del);
+void sched_timer_kick(void);
+uint8_t sched_is_shutdown(void);
+uint16_t sched_shutdown_reason(void);
+void sched_clear_shutdown(void);
+void sched_try_shutdown(uint16_t reason);
+void sched_shutdown(uint16_t reason) __noreturn;
+void sched_main(void);
+
+// Compiler glue for DECL_X macros above.
+struct callback_handler {
+ void (*func)(void);
+};
+#define _DECL_CALLBACK(NAME, FUNC) \
+ const struct callback_handler _DECL_ ## NAME ## _ ## FUNC __visible \
+ __section(".progmem.data." __stringify(NAME) ) = { .func = FUNC }
+
+#define foreachdecl(ITER, NAME) \
+ extern typeof(*ITER) NAME ## _start[], NAME ## _end[]; \
+ for (ITER = NAME ## _start ; ITER < NAME ## _end ; ITER ++)
+
+#endif // sched.h