Added reworked manager / statemachine tasks, thread implementation and new directory layout

This commit is contained in:
dario
2023-09-22 15:07:15 +02:00
parent adeec2f3f9
commit 503d874a6e
13 changed files with 652 additions and 26 deletions

86
Tacos/src/thread.cpp Normal file
View File

@@ -0,0 +1,86 @@
/*
* thread.cpp
*
* Created on: Sep 14, 2023
* Author: Dario
*/
#include <sta/tacos/thread.hpp>
#include <sta/debug/assert.hpp>
#include <functional>
#include <cstring>
namespace sta
{
namespace tacos
{
TacosThread::TacosThread(const char* name, osPriority_t prio)
: RtosThread(RtosHandle<osThreadId_t>(Handle::Deferred(&instance_))),
attribs_{ .name = name, .priority = prio }
{
}
static void entry_point(void* arg)
{
STA_ASSERT(arg != nullptr);
TacosThread* instance = reinterpret_cast<TacosThread*>(arg) ;
instance->loop();
}
void TacosThread::start()
{
STA_ASSERT(!isRunning());
instance_ = osThreadNew(entry_point, this, &attribs_);
STA_ASSERT(instance_ != NULL);
}
bool TacosThread::isRunning()
{
return instance_ != NULL;
}
osThreadId_t TacosThread::getInstance()
{
STA_ASSERT(isRunning());
return instance_;
}
const char* TacosThread::getName() const
{
return attribs_.name;
}
void TacosThread::loop()
{
init();
while ((osEventFlagsGet(instance_) & STA_RTOS_THREAD_FLAG_TERMINATE) == 0)
{
func();
}
instance_ = NULL;
osThreadExit();
}
bool TacosThread::operator==(const TacosThread& other) const
{
return std::strcmp(this->getName(), other.getName()) == 0;
}
bool TacosThread::operator<(const TacosThread& other) const
{
return std::strcmp(this->getName(), other.getName()) < 0;
}
} // namespace tacos
} // namespace sta