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 };
|
|
|
|
|
2017-07-27 18:05:29 +02:00
|
|
|
// Task waking struct
|
|
|
|
struct task_wake {
|
|
|
|
uint8_t wake;
|
|
|
|
};
|
|
|
|
|
2016-05-25 17:37:40 +02:00
|
|
|
// sched.c
|
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);
|
2017-09-04 04:02:48 +02:00
|
|
|
void sched_timer_reset(void);
|
2017-08-07 17:33:31 +02:00
|
|
|
void sched_wake_tasks(void);
|
2017-08-07 18:33:08 +02:00
|
|
|
uint8_t sched_tasks_busy(void);
|
2017-07-27 18:05:29 +02:00
|
|
|
void sched_wake_task(struct task_wake *w);
|
|
|
|
uint8_t sched_check_wake(struct task_wake *w);
|
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
|