Combined watchdog code with latest changes.

This commit is contained in:
dario
2024-01-03 14:55:16 +01:00
parent 1a80082a0b
commit 14142d5b62
7 changed files with 256 additions and 9 deletions

View File

@@ -22,6 +22,45 @@ namespace sta
{
namespace tacos
{
/**
* @brief A status flags for the watchdog.
*
*/
enum class ThreadStatus
{
/**
* @brief This thread wants to be ignored by the watchdog.
*
*/
IGNORED,
/**
* @brief The thread terminated regularly. The watchdog will not try to restart this thread.
*
*/
STOPPED,
/**
* @brief The thread's status is unknown. If the watchdog encounters this status, it will try to
* restart the affected thread.
*
*/
UNKNOWN,
/**
* @brief The thread is running as intended. The watchdog will set this flag back to UNKNOWN.
*
*/
RUNNING,
/**
* @brief The thread is waiting and might not send a heartbeat signal in a while. The watchdog will
* not do anything in this case.
*
*/
WAITING
};
/**
* @brief Abstract class for thread implementations in Tacos.
*
@@ -97,8 +136,37 @@ namespace sta
*/
virtual void cleanup();
private:
#ifdef STA_TACOS_WATCHDOG_ENABLED
#define BLOCKING(stmt) waiting(); stmt heartbeat()
protected:
/**
* @brief
*
*/
void heartbeat();
/**
* @brief Set the thread's status to waiting. Should be called before executing
*
*/
void waiting();
public:
/**
* @brief Get the current status of the thread.
*
* @return ThreadStatus
*/
ThreadStatus getStatus();
/**
* @brief Reset the thread's status to UNKNOWN. Should only be called by the Watchdog.
*
*/
void resetStatus();
#endif // STA_TACOS_WATCHDOG_ENABLED
private:
/**
* @brief Static function to pass to RTOS to run as a thread. Calls the loop function implemented here.
*/
@@ -108,6 +176,9 @@ namespace sta
osThreadId_t instance_;
osThreadAttr_t attribs_;
bool running_;
#ifdef STA_TACOS_WATCHDOG_ENABLED
ThreadStatus status_;
#endif // STA_TACOS_WATCHDOG_ENABLED
};
}
}