2016-05-25 17:37:40 +02:00
|
|
|
#ifndef __SCHED_H
|
|
|
|
#define __SCHED_H
|
|
|
|
|
2017-05-26 14:34:31 +02:00
|
|
|
#include <stdint.h> // uint32_t
|
2017-05-26 15:14:26 +02:00
|
|
|
#include "ctr.h" // DECL_CTR
|
2016-05-25 17:37:40 +02:00
|
|
|
|
|
|
|
// Declare an init function (called at firmware startup)
|
2017-05-26 15:14:26 +02:00
|
|
|
#define DECL_INIT(FUNC) _DECL_CALLLIST(ctr_run_initfuncs, FUNC)
|
2016-05-25 17:37:40 +02:00
|
|
|
// Declare a task function (called periodically during normal runtime)
|
2017-05-26 15:14:26 +02:00
|
|
|
#define DECL_TASK(FUNC) _DECL_CALLLIST(ctr_run_taskfuncs, FUNC)
|
2016-05-25 17:37:40 +02:00
|
|
|
// Declare a shutdown function (called on an emergency stop)
|
2017-05-26 15:14:26 +02:00
|
|
|
#define DECL_SHUTDOWN(FUNC) _DECL_CALLLIST(ctr_run_shutdownfuncs, FUNC)
|
2016-05-25 17:37:40 +02:00
|
|
|
|
2017-03-11 04:12:05 +01:00
|
|
|
// Timer structure for scheduling timed events (see sched_add_timer() )
|
2016-05-25 17:37:40 +02:00
|
|
|
struct timer {
|
|
|
|
struct timer *next;
|
2016-06-09 03:33:50 +02:00
|
|
|
uint_fast8_t (*func)(struct timer*);
|
2016-05-25 17:37:40 +02:00
|
|
|
uint32_t waketime;
|
|
|
|
};
|
|
|
|
|
|
|
|
enum { SF_DONE=0, SF_RESCHEDULE=1 };
|
|
|
|
|
|
|
|
// sched.c
|
|
|
|
uint8_t sched_check_periodic(uint16_t time, uint16_t *pnext);
|
2017-03-11 04:12:05 +01:00
|
|
|
void sched_add_timer(struct timer*);
|
2016-05-25 17:37:40 +02:00
|
|
|
void sched_del_timer(struct timer *del);
|
2017-03-27 22:38:01 +02:00
|
|
|
unsigned int sched_timer_dispatch(void);
|
2016-05-25 17:37:40 +02:00
|
|
|
uint8_t sched_is_shutdown(void);
|
|
|
|
void sched_clear_shutdown(void);
|
2017-05-26 14:34:31 +02:00
|
|
|
void sched_try_shutdown(uint_fast8_t reason);
|
|
|
|
void sched_shutdown(uint_fast8_t reason) __noreturn;
|
|
|
|
void sched_report_shutdown(void);
|
2016-05-25 17:37:40 +02:00
|
|
|
void sched_main(void);
|
|
|
|
|
|
|
|
// Compiler glue for DECL_X macros above.
|
2017-05-26 15:14:26 +02:00
|
|
|
#define _DECL_CALLLIST(NAME, FUNC) \
|
|
|
|
DECL_CTR("_DECL_CALLLIST " __stringify(NAME) " " __stringify(FUNC))
|
2016-05-25 17:37:40 +02:00
|
|
|
|
|
|
|
#endif // sched.h
|