fome-fw/firmware/controllers/system/timer/scheduler.h

71 lines
1.9 KiB
C
Raw Normal View History

2015-07-10 06:01:56 -07:00
/**
* @file scheduler.h
*
* @date May 18, 2014
2020-01-07 21:02:40 -08:00
* @author Andrey Belomutskiy, (c) 2012-2020
2015-07-10 06:01:56 -07:00
*/
2019-10-07 22:49:42 -07:00
#pragma once
2015-07-10 06:01:56 -07:00
2018-09-16 19:26:57 -07:00
#include "global.h"
2015-07-10 06:01:56 -07:00
typedef void (*schfunc_t)(void *);
2019-11-23 15:38:16 -08:00
class action_s {
public:
// Default constructor constructs null action (ie, implicit bool conversion returns false)
action_s() = default;
// Allow implicit conversion from schfunc_t to action_s
action_s(schfunc_t callback) : action_s(callback, nullptr) { }
action_s(schfunc_t callback, void *param) : callback(callback), param(param) { }
// Allow any function that takes a single pointer parameter, so long as param is also of the same pointer type.
// This constructor means you shouldn't ever have to cast to schfunc_t on your own.
template <typename TArg>
action_s(void (*callback)(TArg*), TArg* param) : callback((schfunc_t)callback), param(param) { }
2019-11-23 15:38:16 -08:00
void execute();
schfunc_t getCallback() const;
void * getArgument() const;
2019-11-23 15:38:16 -08:00
operator bool() const {
return callback != nullptr;
}
2019-11-23 15:38:16 -08:00
private:
schfunc_t callback = nullptr;
void *param = nullptr;
};
2019-10-07 22:49:42 -07:00
/**
* This structure holds information about an event scheduled in the future: when to execute what callback with what parameters
*/
#pragma pack(push, 4)
struct scheduling_s {
2019-04-12 19:07:03 -07:00
#if EFI_SIGNAL_EXECUTOR_SLEEP
2016-04-01 18:01:44 -07:00
virtual_timer_t timer;
2015-07-10 06:01:56 -07:00
#endif /* EFI_SIGNAL_EXECUTOR_SLEEP */
2019-10-07 22:49:42 -07:00
/**
* timestamp represented as 64-bit value of ticks since MCU start
*/
2019-10-07 22:36:35 -07:00
volatile efitime_t momentX = 0;
2019-10-07 22:49:42 -07:00
/**
2019-11-23 11:14:17 -08:00
* Scheduler implementation uses a sorted linked list of these scheduling records.
2019-10-07 22:49:42 -07:00
*/
scheduling_s *nextScheduling_s = nullptr;
2019-10-07 22:36:35 -07:00
2019-11-23 15:38:16 -08:00
action_s action;
2015-07-10 06:01:56 -07:00
};
#pragma pack(pop)
2015-07-10 06:01:56 -07:00
struct ExecutorInterface {
/**
* see also scheduleByAngle
*/
virtual void scheduleByTimestamp(scheduling_s *scheduling, efitimeus_t timeUs, action_s action) = 0;
virtual void scheduleByTimestampNt(scheduling_s *scheduling, efitime_t timeUs, action_s action) = 0;
virtual void scheduleForLater(scheduling_s *scheduling, int delayUs, action_s action) = 0;
};