|
|
@@ -197,6 +197,9 @@ class StatusRequest {
|
|
|
};
|
|
|
#endif // _TASK_STATUS_REQUEST
|
|
|
|
|
|
+typedef void (*callback_t)();
|
|
|
+typedef void (*onDisable_cb_t)();
|
|
|
+typedef bool (*onEnable_cb_t)();
|
|
|
|
|
|
typedef struct {
|
|
|
bool enabled : 1; // indicates that task is enabled or not.
|
|
|
@@ -216,9 +219,9 @@ class Scheduler;
|
|
|
class Task {
|
|
|
friend class Scheduler;
|
|
|
public:
|
|
|
- inline Task(unsigned long aInterval=0, long aIterations=0, void (*aCallback)()=NULL, Scheduler* aScheduler=NULL, bool aEnable=false, bool (*aOnEnable)()=NULL, void (*aOnDisable)()=NULL);
|
|
|
+ inline Task(unsigned long aInterval=0, long aIterations=0, callback_t aCallback=NULL, Scheduler* aScheduler=NULL, bool aEnable=false, onEnable_cb_t aOnEnable=NULL, onDisable_cb_t aOnDisable=NULL);
|
|
|
#ifdef _TASK_STATUS_REQUEST
|
|
|
- inline Task(void (*aCallback)()=NULL, Scheduler* aScheduler=NULL, bool (*aOnEnable)()=NULL, void (*aOnDisable)()=NULL);
|
|
|
+ inline Task(callback_t aCallback=NULL, Scheduler* aScheduler=NULL, onEnable_cb_t aOnEnable=NULL, onDisable_cb_t aOnDisable=NULL);
|
|
|
#endif // _TASK_STATUS_REQUEST
|
|
|
|
|
|
inline void enable();
|
|
|
@@ -230,17 +233,17 @@ class Task {
|
|
|
inline void restartDelayed(unsigned long aDelay=0);
|
|
|
inline bool disable();
|
|
|
inline bool isEnabled() { return iStatus.enabled; }
|
|
|
- inline void set(unsigned long aInterval, long aIterations, void (*aCallback)(),bool (*aOnEnable)()=NULL, void (*aOnDisable)()=NULL);
|
|
|
+ inline void set(unsigned long aInterval, long aIterations, callback_t aCallback,onEnable_cb_t aOnEnable=NULL, onDisable_cb_t aOnDisable=NULL);
|
|
|
inline void setInterval(unsigned long aInterval);
|
|
|
inline unsigned long getInterval() { return iInterval; }
|
|
|
inline void setIterations(long aIterations);
|
|
|
inline long getIterations() { return iIterations; }
|
|
|
inline unsigned long getRunCounter() { return iRunCounter; }
|
|
|
- inline void setCallback(void (*aCallback)()) { iCallback = aCallback; }
|
|
|
- inline void setOnEnable(bool (*aCallback)()) { iOnEnable = aCallback; }
|
|
|
- inline void setOnDisable(void (*aCallback)()) { iOnDisable = aCallback; }
|
|
|
- inline void yield(void (*aCallback)());
|
|
|
- inline void yieldOnce(void (*aCallback)());
|
|
|
+ inline void setCallback(callback_t aCallback) { iCallback = aCallback; }
|
|
|
+ inline void setOnEnable(onEnable_cb_t aCallback) { iOnEnable = aCallback; }
|
|
|
+ inline void setOnDisable(callback_t aCallback) { iOnDisable = aCallback; }
|
|
|
+ inline void yield(callback_t aCallback);
|
|
|
+ inline void yieldOnce(callback_t aCallback);
|
|
|
#ifdef _TASK_TIMECRITICAL
|
|
|
inline long getOverrun() { return iOverrun; }
|
|
|
inline long getStartDelay() { return iStartDelay; }
|
|
|
@@ -278,9 +281,9 @@ class Task {
|
|
|
volatile long iIterations; // number of iterations left. 0 - last iteration. -1 - infinite iterations
|
|
|
long iSetIterations; // number of iterations originally requested (for restarts)
|
|
|
unsigned long iRunCounter; // current number of iteration (starting with 1). Resets on enable.
|
|
|
- void (*iCallback)(); // pointer to the void callback method
|
|
|
- bool (*iOnEnable)(); // pointer to the bolol OnEnable callback method
|
|
|
- void (*iOnDisable)(); // pointer to the void OnDisable method
|
|
|
+ callback_t iCallback; // pointer to the void callback method
|
|
|
+ onEnable_cb_t iOnEnable; // pointer to the bolol OnEnable callback method
|
|
|
+ onDisable_cb_t iOnDisable; // pointer to the void OnDisable method
|
|
|
Task *iPrev, *iNext; // pointers to the previous and next tasks in the chain
|
|
|
Scheduler *iScheduler; // pointer to the current scheduler
|
|
|
#ifdef _TASK_STATUS_REQUEST
|
|
|
@@ -344,7 +347,7 @@ class Scheduler {
|
|
|
/** Constructor, uses default values for the parameters
|
|
|
* so could be called with no parameters.
|
|
|
*/
|
|
|
-Task::Task( unsigned long aInterval, long aIterations, void (*aCallback)(), Scheduler* aScheduler, bool aEnable, bool (*aOnEnable)(), void (*aOnDisable)() ) {
|
|
|
+Task::Task( unsigned long aInterval, long aIterations, callback_t aCallback, Scheduler* aScheduler, bool aEnable, onEnable_cb_t aOnEnable, onDisable_cb_t aOnDisable ) {
|
|
|
reset();
|
|
|
set(aInterval, aIterations, aCallback, aOnEnable, aOnDisable);
|
|
|
if (aScheduler) aScheduler->addTask(*this);
|
|
|
@@ -363,7 +366,7 @@ Task::Task( unsigned long aInterval, long aIterations, void (*aCallback)(), Sche
|
|
|
/** Constructor with reduced parameter list for tasks created for
|
|
|
* StatusRequest only triggering (always immediate and only 1 iteration)
|
|
|
*/
|
|
|
-Task::Task( void (*aCallback)(), Scheduler* aScheduler, bool (*aOnEnable)(), void (*aOnDisable)() ) {
|
|
|
+Task::Task( callback_t aCallback, Scheduler* aScheduler, onEnable_cb_t aOnEnable, onDisable_cb_t aOnDisable ) {
|
|
|
reset();
|
|
|
set(TASK_IMMEDIATE, TASK_ONCE, aCallback, aOnEnable, aOnDisable);
|
|
|
if (aScheduler) aScheduler->addTask(*this);
|
|
|
@@ -452,7 +455,7 @@ void Task::reset() {
|
|
|
* @param aOnEnable - pointer to the callback method which is called on enable()
|
|
|
* @param aOnDisable - pointer to the callback method which is called on disable()
|
|
|
*/
|
|
|
-void Task::set(unsigned long aInterval, long aIterations, void (*aCallback)(),bool (*aOnEnable)(), void (*aOnDisable)()) {
|
|
|
+void Task::set(unsigned long aInterval, long aIterations, callback_t aCallback, onEnable_cb_t aOnEnable, onDisable_cb_t aOnDisable) {
|
|
|
setInterval(aInterval);
|
|
|
iSetIterations = iIterations = aIterations;
|
|
|
iCallback = aCallback;
|
|
|
@@ -471,7 +474,7 @@ void Task::setIterations(long aIterations) {
|
|
|
/** Prepare task for next step iteration following yielding of control to the scheduler
|
|
|
* @param aCallback - pointer to the callback method for the next step
|
|
|
*/
|
|
|
-void Task::yield (void (*aCallback)()) {
|
|
|
+void Task::yield (callback_t aCallback) {
|
|
|
iCallback = aCallback;
|
|
|
forceNextIteration();
|
|
|
|
|
|
@@ -485,7 +488,7 @@ void Task::yield (void (*aCallback)()) {
|
|
|
/** Prepare task for next step iteration following yielding of control to the scheduler
|
|
|
* @param aCallback - pointer to the callback method for the next step
|
|
|
*/
|
|
|
-void Task::yieldOnce (void (*aCallback)()) {
|
|
|
+void Task::yieldOnce (callback_t aCallback) {
|
|
|
yield(aCallback);
|
|
|
iIterations = 1;
|
|
|
}
|
|
|
@@ -501,7 +504,7 @@ void Task::enable() {
|
|
|
Task *current = iScheduler->iCurrent;
|
|
|
iScheduler->iCurrent = this;
|
|
|
iStatus.inonenable = true; // Protection against potential infinite loop
|
|
|
- iStatus.enabled = (*iOnEnable)();
|
|
|
+ iStatus.enabled = iOnEnable();
|
|
|
iStatus.inonenable = false; // Protection against potential infinite loop
|
|
|
iScheduler->iCurrent = current;
|
|
|
}
|
|
|
@@ -573,7 +576,7 @@ bool Task::disable() {
|
|
|
if (previousEnabled && iOnDisable) {
|
|
|
Task *current = iScheduler->iCurrent;
|
|
|
iScheduler->iCurrent = this;
|
|
|
- (*iOnDisable)();
|
|
|
+ iOnDisable();
|
|
|
iScheduler->iCurrent = current;
|
|
|
}
|
|
|
#ifdef _TASK_STATUS_REQUEST
|
|
|
@@ -842,7 +845,7 @@ bool Scheduler::execute() {
|
|
|
|
|
|
iCurrent->iDelay = i;
|
|
|
if ( iCurrent->iCallback ) {
|
|
|
- ( *(iCurrent->iCallback) )();
|
|
|
+ iCurrent->iCallback();
|
|
|
idleRun = false;
|
|
|
}
|
|
|
}
|