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
|
|
|
|
|
|
|
typedef void (*schfunc_t)(void *);
|
|
|
|
|
2019-11-23 15:38:16 -08:00
|
|
|
class action_s {
|
|
|
|
public:
|
2021-05-07 05:22:35 -07:00
|
|
|
// Default constructor constructs null action (ie, implicit bool conversion returns false)
|
2020-01-06 21:41:18 -08:00
|
|
|
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) { }
|
|
|
|
|
2020-01-07 15:10:31 -08:00
|
|
|
// 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();
|
2019-11-23 17:36:40 -08:00
|
|
|
schfunc_t getCallback() const;
|
|
|
|
void * getArgument() const;
|
2019-11-23 15:38:16 -08:00
|
|
|
|
2021-05-07 05:22:35 -07: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
|
|
|
|
*/
|
2021-05-07 05:22:35 -07:00
|
|
|
#pragma pack(push, 4)
|
2021-11-16 13:52:11 -08:00
|
|
|
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
|
|
|
*/
|
2019-11-23 14:04:51 -08: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
|
|
|
};
|
2021-05-07 05:22:35 -07:00
|
|
|
#pragma pack(pop)
|
2015-07-10 06:01:56 -07:00
|
|
|
|
2020-01-06 21:41:18 -08:00
|
|
|
struct ExecutorInterface {
|
2019-01-09 06:37:16 -08:00
|
|
|
/**
|
|
|
|
* see also scheduleByAngle
|
|
|
|
*/
|
2021-07-14 13:03:00 -07:00
|
|
|
virtual void scheduleByTimestamp(const char *msg, scheduling_s *scheduling, efitimeus_t timeUs, action_s action) = 0;
|
|
|
|
virtual void scheduleByTimestampNt(const char *msg, scheduling_s *scheduling, efitime_t timeUs, action_s action) = 0;
|
2022-05-14 18:24:19 -07:00
|
|
|
virtual void scheduleForLater(const char *msg, scheduling_s *scheduling, int delayUs, action_s action) = 0;
|
2021-08-27 01:30:06 -07:00
|
|
|
virtual void cancel(scheduling_s* scheduling) = 0;
|
2019-01-08 21:53:54 -08:00
|
|
|
};
|