From 2eb4705ae6026ee938560e83c5b41484e923f096 Mon Sep 17 00:00:00 2001 From: dario Date: Thu, 18 Jan 2024 13:24:31 +0100 Subject: [PATCH 1/5] Added return value to addThread --- include/sta/tacos.hpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/include/sta/tacos.hpp b/include/sta/tacos.hpp index 3ca9f85..b92f699 100644 --- a/include/sta/tacos.hpp +++ b/include/sta/tacos.hpp @@ -68,9 +68,13 @@ namespace sta * @ingroup tacos_api */ template - void addThread(std::list states, Args ... args) + std::shared_ptr addThread(std::list states, Args ... args) { - Manager::instance()->registerThread(std::make_shared(args...), states); + std::shared_ptr thread_ptr = std::make_shared(args...); + + Manager::instance()->registerThread(thread_ptr, states); + + return thread_ptr; } } // namespace tacos } From 5cb4f3a2af98c3f00cb63d419e855c2faaf9dae5 Mon Sep 17 00:00:00 2001 From: dario Date: Fri, 19 Jan 2024 12:42:05 +0100 Subject: [PATCH 2/5] Added customizable stack sizes for TacosThreads --- include/sta/tacos/thread.hpp | 13 ++++++++++--- src/thread.cpp | 11 ++--------- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/include/sta/tacos/thread.hpp b/include/sta/tacos/thread.hpp index ca01469..660dd64 100644 --- a/include/sta/tacos/thread.hpp +++ b/include/sta/tacos/thread.hpp @@ -31,11 +31,18 @@ namespace sta { public: /** - * @brief Create a new thread with the given name and priority. + * @brief */ - TacosThread(const char* name, osPriority_t prio); - TacosThread(); + /** + * @brief Create a new thread with the given name and priority. + * + * @param name The thread's name. This is used for debugging. + * @param prio The thread's priority. Generally, this should be lower than the manager and statemachine priority. + * @param stack_size The stack size for the task. The default is the stack size specified in the FreeRTOS settings. + * @param cb_size The control block size for the task. The default is the size specified in the FreeRTOS settings. + */ + TacosThread(const char* name, osPriority_t prio, uint32_t stack_size = NULL, uint32_t cb_size = NULL); virtual ~TacosThread(); diff --git a/src/thread.cpp b/src/thread.cpp index 49c6b14..37b6073 100644 --- a/src/thread.cpp +++ b/src/thread.cpp @@ -19,17 +19,10 @@ namespace sta { namespace tacos { - TacosThread::TacosThread(const char* name, osPriority_t prio) + TacosThread::TacosThread(const char* name, osPriority_t prio, uint32_t stack_size = NULL, uint32_t cb_size = NULL) : RtosThread(RtosHandle(Handle::Deferred(&instance_))), instance_{ NULL }, - attribs_{ .name = name, .priority = prio }, - running_{false} - {} - - TacosThread::TacosThread() - : RtosThread(RtosHandle(Handle::Deferred(&instance_))), - instance_{ NULL }, - attribs_{ }, + attribs_{ .name = name, .priority = prio, .stack_size=stack_size, .cb_size=cb_size }, running_{false} {} From 7f875a8f46a9ad98aa6f2f131ff0826eb4481e35 Mon Sep 17 00:00:00 2001 From: dario Date: Fri, 19 Jan 2024 13:52:39 +0100 Subject: [PATCH 3/5] Updated custom stack sizes for TacosThreads --- include/sta/tacos/thread.hpp | 6 +++--- src/thread.cpp | 9 ++++++--- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/include/sta/tacos/thread.hpp b/include/sta/tacos/thread.hpp index 660dd64..902b9b5 100644 --- a/include/sta/tacos/thread.hpp +++ b/include/sta/tacos/thread.hpp @@ -39,10 +39,10 @@ namespace sta * * @param name The thread's name. This is used for debugging. * @param prio The thread's priority. Generally, this should be lower than the manager and statemachine priority. - * @param stack_size The stack size for the task. The default is the stack size specified in the FreeRTOS settings. - * @param cb_size The control block size for the task. The default is the size specified in the FreeRTOS settings. + * @param stack_size The stack size for the task. The default is 0, i.e. the stack size specified in the FreeRTOS settings. + * @param cb_size The control block size for the task. The default is 0, i.e. the size specified in the FreeRTOS settings. */ - TacosThread(const char* name, osPriority_t prio, uint32_t stack_size = NULL, uint32_t cb_size = NULL); + TacosThread(const char* name, osPriority_t prio, uint32_t stack_size = 0, uint32_t cb_size = 0); virtual ~TacosThread(); diff --git a/src/thread.cpp b/src/thread.cpp index 37b6073..a6a2fb4 100644 --- a/src/thread.cpp +++ b/src/thread.cpp @@ -19,12 +19,15 @@ namespace sta { namespace tacos { - TacosThread::TacosThread(const char* name, osPriority_t prio, uint32_t stack_size = NULL, uint32_t cb_size = NULL) + TacosThread::TacosThread(const char* name, osPriority_t prio, uint32_t stack_size /* = 0 */, uint32_t cb_size /* = 0 */) : RtosThread(RtosHandle(Handle::Deferred(&instance_))), instance_{ NULL }, - attribs_{ .name = name, .priority = prio, .stack_size=stack_size, .cb_size=cb_size }, + attribs_{ .name=name, .cb_size=cb_size, .stack_size=stack_size, .priority=prio }, running_{false} - {} + { + STA_ASSERT(stack_size >= 0); + STA_ASSERT(stack_size >= 0); + } void TacosThread::entry_point(void* arg) { From c335ef637fb37928c33fc247362b0666604cecde Mon Sep 17 00:00:00 2001 From: dario Date: Sat, 20 Jan 2024 14:52:29 +0100 Subject: [PATCH 4/5] fixed duplicate assert --- src/thread.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/thread.cpp b/src/thread.cpp index a6a2fb4..a392422 100644 --- a/src/thread.cpp +++ b/src/thread.cpp @@ -26,7 +26,7 @@ namespace sta running_{false} { STA_ASSERT(stack_size >= 0); - STA_ASSERT(stack_size >= 0); + STA_ASSERT(cb_size >= 0); } void TacosThread::entry_point(void* arg) From 2947df3c7678d4621f6394c84d44edb122d645e8 Mon Sep 17 00:00:00 2001 From: dario Date: Sat, 20 Jan 2024 15:14:06 +0100 Subject: [PATCH 5/5] Removed obsolete @brief --- include/sta/tacos/thread.hpp | 4 ---- 1 file changed, 4 deletions(-) diff --git a/include/sta/tacos/thread.hpp b/include/sta/tacos/thread.hpp index 902b9b5..4cebf27 100644 --- a/include/sta/tacos/thread.hpp +++ b/include/sta/tacos/thread.hpp @@ -30,10 +30,6 @@ namespace sta class TacosThread : public RtosThread { public: - /** - * @brief - */ - /** * @brief Create a new thread with the given name and priority. *