klipper-dgus/src/sched.h

40 lines
1.3 KiB
C
Raw Normal View History

#ifndef __SCHED_H
#define __SCHED_H
#include <stdint.h> // uint32_t
#include "ctr.h" // DECL_CTR
// Declare an init function (called at firmware startup)
#define DECL_INIT(FUNC) _DECL_CALLLIST(ctr_run_initfuncs, FUNC)
// Declare a task function (called periodically during normal runtime)
#define DECL_TASK(FUNC) _DECL_CALLLIST(ctr_run_taskfuncs, FUNC)
// Declare a shutdown function (called on an emergency stop)
#define DECL_SHUTDOWN(FUNC) _DECL_CALLLIST(ctr_run_shutdownfuncs, FUNC)
// Timer structure for scheduling timed events (see sched_add_timer() )
struct timer {
struct timer *next;
uint_fast8_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);
void sched_add_timer(struct timer*);
void sched_del_timer(struct timer *del);
unsigned int sched_timer_dispatch(void);
uint8_t sched_is_shutdown(void);
void sched_clear_shutdown(void);
void sched_try_shutdown(uint_fast8_t reason);
void sched_shutdown(uint_fast8_t reason) __noreturn;
void sched_report_shutdown(void);
void sched_main(void);
// Compiler glue for DECL_X macros above.
#define _DECL_CALLLIST(NAME, FUNC) \
DECL_CTR("_DECL_CALLLIST " __stringify(NAME) " " __stringify(FUNC))
#endif // sched.h