build: Use compile_time_request system for init, tasks, and shutdown

Avoid using linker magic to define the init, task, and shutdown
functions.  Instead, use the compile_time_request system.  This
simplifies the build and produces more efficient code.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
This commit is contained in:
Kevin O'Connor 2017-05-26 09:14:26 -04:00
parent ca9756413f
commit a82e949c00
26 changed files with 82 additions and 127 deletions

View file

@ -2,14 +2,14 @@
#define __SCHED_H
#include <stdint.h> // uint32_t
#include "compiler.h" // __section
#include "ctr.h" // DECL_CTR
// Declare an init function (called at firmware startup)
#define DECL_INIT(FUNC) _DECL_CALLBACK(initfuncs, FUNC)
#define DECL_INIT(FUNC) _DECL_CALLLIST(ctr_run_initfuncs, FUNC)
// Declare a task function (called periodically during normal runtime)
#define DECL_TASK(FUNC) _DECL_CALLBACK(taskfuncs, FUNC)
#define DECL_TASK(FUNC) _DECL_CALLLIST(ctr_run_taskfuncs, FUNC)
// Declare a shutdown function (called on an emergency stop)
#define DECL_SHUTDOWN(FUNC) _DECL_CALLBACK(shutdownfuncs, FUNC)
#define DECL_SHUTDOWN(FUNC) _DECL_CALLLIST(ctr_run_shutdownfuncs, FUNC)
// Timer structure for scheduling timed events (see sched_add_timer() )
struct timer {
@ -33,15 +33,7 @@ void sched_report_shutdown(void);
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(".rodata." __stringify(NAME) ) = { .func = FUNC }
#define foreachdecl(ITER, NAME) \
extern typeof(*ITER) NAME ## _start[], NAME ## _end[]; \
for (ITER = NAME ## _start ; ITER < NAME ## _end ; ITER ++)
#define _DECL_CALLLIST(NAME, FUNC) \
DECL_CTR("_DECL_CALLLIST " __stringify(NAME) " " __stringify(FUNC))
#endif // sched.h