Thread rework to support watchdog restarting

This commit is contained in:
dario
2024-01-24 21:17:42 +01:00
parent ce2bb459cf
commit 3feedc948f
3 changed files with 90 additions and 68 deletions

View File

@@ -60,7 +60,7 @@ namespace sta
/**
* @brief Access handle value.
*
* If the deferred ctor was used the handle value is
* If the deferred constructor was used the handle value is
* evaluated on the first call to this method.
*
* @return Handle value

View File

@@ -2,7 +2,6 @@
#define STA_RTOS_THREAD_HPP
#include <sta/rtos/defs.hpp>
#include <sta/rtos/handle.hpp>
#include <cmsis_os2.h>
@@ -73,15 +72,30 @@ namespace sta
class RtosThread
{
public:
using Handle = RtosHandle<osThreadId_t>; /**< Thread handle type */
public:
RtosThread();
/**
* @brief Create an RtosThread.
*
* @param name The thread's name. Will be used for debugging.
* @param prio The thread's priority.
*/
RtosThread(const char* name, osPriority_t prio);
/**
* @param handle Thread handle
* @brief Get the currently running instance.
*
* @return The currently running instance id.
*/
RtosThread(const Handle & handle);
osThreadId_t getInstance();
/**
* @brief Get the name of this thread.
*/
const char* getName() const;
/**
* @brief Start the execution of this thread.
*/
void start();
/**
* @brief Sets the thread to BLOCKED for a given number of ticks.
@@ -117,23 +131,6 @@ namespace sta
*/
uint32_t clear(uint32_t flags);
/**
* @brief Send termination request to thread.
*/
void requestTermination();
/**
* @brief Clear the termination request flag for this thread.
*/
void deleteTerminationRequest();
/**
* @brief Resets the terminate bool to false.
*
* @return Returns the previous value of this variable.
*/
bool isTerminationRequested();
/**
* @brief Forcibly terminate thread.
*/
@@ -145,22 +142,22 @@ namespace sta
* @param flags System flags
*/
void sysNotify(uint32_t flags);
protected:
/**
* @brief A function that wraps this task's functionality.
*/
virtual void loop() = 0;
private:
Handle handle_;
bool terminate_;
/**
* @brief Static function to pass to RTOS to run as a thread. Calls the loop function implemented here.
*/
static void entry_point(void* arg);
private:
osThreadId_t instance_;
osThreadAttr_t attribs_;
};
} // namespace sta
/**
* @brief Create RtosThread wrapper object for thread handle.
*
* @param name Thread name
*/
#define STA_RTOS_THREAD_WRAPPER(name) \
extern osThreadId_t name ## Handle; \
sta::RtosThread name ## Thread = sta::RtosThread(sta::RtosThread::Handle::Deferred(&name ## Handle));
#endif // STA_RTOS_THREAD_HPP