2016-05-25 18:37:40 +03:00
|
|
|
#ifndef __SCHED_H
|
|
|
|
#define __SCHED_H
|
|
|
|
|
2017-05-26 15:34:31 +03:00
|
|
|
#include <stdint.h> // uint32_t
|
2017-05-26 16:14:26 +03:00
|
|
|
#include "ctr.h" // DECL_CTR
|
2016-05-25 18:37:40 +03:00
|
|
|
|
|
|
|
// Declare an init function (called at firmware startup)
|
2017-05-26 16:14:26 +03:00
|
|
|
#define DECL_INIT(FUNC) _DECL_CALLLIST(ctr_run_initfuncs, FUNC)
|
2016-05-25 18:37:40 +03:00
|
|
|
// Declare a task function (called periodically during normal runtime)
|
2017-05-26 16:14:26 +03:00
|
|
|
#define DECL_TASK(FUNC) _DECL_CALLLIST(ctr_run_taskfuncs, FUNC)
|
2016-05-25 18:37:40 +03:00
|
|
|
// Declare a shutdown function (called on an emergency stop)
|
2017-05-26 16:14:26 +03:00
|
|
|
#define DECL_SHUTDOWN(FUNC) _DECL_CALLLIST(ctr_run_shutdownfuncs, FUNC)
|
2016-05-25 18:37:40 +03:00
|
|
|
|
2017-03-11 06:12:05 +03:00
|
|
|
// Timer structure for scheduling timed events (see sched_add_timer() )
|
2016-05-25 18:37:40 +03:00
|
|
|
struct timer {
|
|
|
|
struct timer *next;
|
2016-06-09 04:33:50 +03:00
|
|
|
uint_fast8_t (*func)(struct timer*);
|
2016-05-25 18:37:40 +03:00
|
|
|
uint32_t waketime;
|
|
|
|
};
|
|
|
|
|
|
|
|
enum { SF_DONE=0, SF_RESCHEDULE=1 };
|
|
|
|
|
2017-07-27 19:05:29 +03:00
|
|
|
// Task waking struct
|
|
|
|
struct task_wake {
|
|
|
|
uint8_t wake;
|
|
|
|
};
|
|
|
|
|
2016-05-25 18:37:40 +03:00
|
|
|
// sched.c
|
2017-03-11 06:12:05 +03:00
|
|
|
void sched_add_timer(struct timer*);
|
2016-05-25 18:37:40 +03:00
|
|
|
void sched_del_timer(struct timer *del);
|
2017-03-27 23:38:01 +03:00
|
|
|
unsigned int sched_timer_dispatch(void);
|
2017-09-04 05:02:48 +03:00
|
|
|
void sched_timer_reset(void);
|
2017-08-07 18:33:31 +03:00
|
|
|
void sched_wake_tasks(void);
|
2017-08-07 19:33:08 +03:00
|
|
|
uint8_t sched_tasks_busy(void);
|
2017-07-27 19:05:29 +03:00
|
|
|
void sched_wake_task(struct task_wake *w);
|
|
|
|
uint8_t sched_check_wake(struct task_wake *w);
|
2016-05-25 18:37:40 +03:00
|
|
|
uint8_t sched_is_shutdown(void);
|
|
|
|
void sched_clear_shutdown(void);
|
2017-05-26 15:34:31 +03: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 18:37:40 +03:00
|
|
|
void sched_main(void);
|
|
|
|
|
|
|
|
// Compiler glue for DECL_X macros above.
|
2017-05-26 16:14:26 +03:00
|
|
|
#define _DECL_CALLLIST(NAME, FUNC) \
|
|
|
|
DECL_CTR("_DECL_CALLLIST " __stringify(NAME) " " __stringify(FUNC))
|
2016-05-25 18:37:40 +03:00
|
|
|
|
|
|
|
#endif // sched.h
|