Hello,
so we use FreeRTOS with an self-written C+±abstraction layer.
Today I made some thoughts about a Watchdog-handling. Since the abstraction is mainly based on a single-responsibility about all OS-entities for every OS-using entity, we won’t pass any handles of mutexes, eventgroups, tasks and so on to other tasks. our components are decoupled via own-written communication interfaces and mechanisms. Tasks shall not do any unneccessary extra-handling, which can differ from task to task but should in general behave unified to prevent any confusion for the developer.
So to get this work, every C+±Object-Task has it’s own run-loop, which is called by a static defined C+±member-function of a task class, this is passed as a private parameter when the task get’s created, looking like this:
xTaskCreate(run, name, static_cast<uint16_t>(stackSize_), reinterpret_cast<void*>(owner), prio, &handle_);
So the owner is the c+±object. this works fine, later one, like this:
static void run(void* taskHandle)
{
reinterpret_cast<Task*>(taskHandle)->runTask();
}
So if a task now calls a mutex, which is also abstracted, everything will work because of FreeRTOS knowing which task is currently active.
A Watchdog-implementation-design at our side would now be to back-point to the C+±Task-Object and set it “ASLEEP”, so a checking watchdog-task can tell what state the task is in.
I thought that I may use the function xTaskGetCurrentTaskHandle() and with the task-handle get the previous passed private parameter when creating the task, which is in fact the c+±Task-object.
But the private parameter is not part of the TCB in FreeRTOS, it is port-defined where the private parameter is passed, as I noticed.
We can also generate a map to map the freeRTOS task-handles to our handles but that seems a bit bloated and unneccessaray runtime-intensive since the handle is already directly known to the FreeRTOS-task at creation-time.
Is there a “general” way to receive back the private parameter without fiddling it out of the port-implementation?
Use case would simply be like that:
C++ Mutex-object:
/**
* @brief gets the mutex
*/
void get()
{
// use like this:
reinterpret_cast<Task*>(xTaskGetCurrentTaskHandle()->prvParam)->setState(ASLEEP);
if (xSemaphoreTake(handle_, portMAX_DELAY) != pdTRUE)
{
// error happened
}
}
I hope you get the intention. With the current FreeRTOS-implementation there won’t seem to be an “easy” approach as I understand.
Or am I missing something?
regards
Felix