fsfw/src/fsfw/osal/freertos/FreeRTOSTaskIF.h

38 lines
1.3 KiB
C
Raw Normal View History

2020-12-14 23:56:44 +01:00
#ifndef FSFW_OSAL_FREERTOS_FREERTOSTASKIF_H_
#define FSFW_OSAL_FREERTOS_FREERTOSTASKIF_H_
2020-08-08 12:46:06 +02:00
#include "FreeRTOS.h"
#include "task.h"
2020-08-08 12:46:06 +02:00
class FreeRTOSTaskIF {
2022-02-02 10:29:30 +01:00
public:
2022-05-27 00:31:20 +02:00
virtual ~FreeRTOSTaskIF() = default;
2022-02-02 10:29:30 +01:00
virtual TaskHandle_t getTaskHandle() = 0;
2020-12-14 23:56:44 +01:00
2022-02-02 10:29:30 +01:00
protected:
2022-05-27 00:31:20 +02:00
static bool checkMissedDeadline(const TickType_t xLastWakeTime, const TickType_t interval) {
2022-02-02 10:29:30 +01:00
/* Check whether deadline was missed while also taking overflows
* into account. Drawing this on paper with a timeline helps to understand
* it. */
TickType_t currentTickCount = xTaskGetTickCount();
TickType_t timeToWake = xLastWakeTime + interval;
// Time to wake has not overflown.
if (timeToWake > xLastWakeTime) {
/* If the current time has overflown exclusively or the current
* tick count is simply larger than the time to wake, a deadline was
* missed */
if ((currentTickCount < xLastWakeTime) or (currentTickCount > timeToWake)) {
return true;
}
}
/* Time to wake has overflown. A deadline was missed if the current time
* is larger than the time to wake */
else if ((timeToWake < xLastWakeTime) and (currentTickCount > timeToWake)) {
return true;
2020-12-14 23:56:44 +01:00
}
2022-02-02 10:29:30 +01:00
return false;
}
2020-08-08 12:46:06 +02:00
};
2020-12-14 23:56:44 +01:00
#endif /* FSFW_OSAL_FREERTOS_FREERTOSTASKIF_H_ */