From ac1344747bf834d9b90e76e49cc0ec712aeb2e35 Mon Sep 17 00:00:00 2001 From: dario Date: Sat, 3 Aug 2024 22:47:01 +0200 Subject: [PATCH] Updated uart comunication for spatz --- include/sta/debug/spatz.hpp | 3 ++- src/debug/profile.cpp | 2 +- src/debug/spatz.cpp | 37 ++++++++++++++++--------------------- 3 files changed, 19 insertions(+), 23 deletions(-) diff --git a/include/sta/debug/spatz.hpp b/include/sta/debug/spatz.hpp index 7b69f4c..eb3ec98 100644 --- a/include/sta/debug/spatz.hpp +++ b/include/sta/debug/spatz.hpp @@ -2,6 +2,7 @@ #define STA_CORE_SPATZ_HPP #include +#include #include #ifdef STA_SPATZ_ENABLED @@ -20,7 +21,7 @@ namespace sta * * @param mutex A mutex used to make SPATZ thread-safe. */ - void init(Mutex * mutex); + void init(Mutex * mutex, Signal * signal); /** * @brief Request bytes for a specific sensor id via the printable. diff --git a/src/debug/profile.cpp b/src/debug/profile.cpp index 4e7eec6..e1e541a 100644 --- a/src/debug/profile.cpp +++ b/src/debug/profile.cpp @@ -22,7 +22,7 @@ namespace sta Profiler::~Profiler() { - STA_DEBUG_PRINTF("[PROFILER] %s took %d us", name_, timeUs() - start_); + STA_DEBUG_PRINTF(">[PROFILER] %s took %d us", name_, timeUs() - start_); } } // namespace sta diff --git a/src/debug/spatz.cpp b/src/debug/spatz.cpp index a665b3d..6bf5880 100644 --- a/src/debug/spatz.cpp +++ b/src/debug/spatz.cpp @@ -6,19 +6,20 @@ # error "The ID used to communicate SPATZ initialization was not defined." #endif // STA_INIT_SPATZ_ID -#include -#include #include namespace sta { namespace spatz { - sta::Mutex * mutex_; + sta::Mutex * mutex_ = nullptr; + sta::Signal * signal_ = nullptr; - void init(sta::Mutex * mutex) + void init(sta::Mutex * mutex, Signal * signal) { mutex_ = mutex; + signal_ = signal; + uint8_t msg = 0xFF; sta::lock_guard lock(*mutex_); @@ -42,23 +43,9 @@ namespace sta { mutex_->acquire(); - bool success = false; - - while (!success) - { - Debug->printf("%d", id); - - HAL_StatusTypeDef state = HAL_UART_Receive(&huart1, reinterpret_cast(buffer), length * sizeof(float), 100); - - if (state == HAL_TIMEOUT) - { - success = false; - Debug->println(">ERROR"); - break; - } - - success = true; - } + HAL_UART_Receive_IT(&huart1, reinterpret_cast(buffer), length * sizeof(float)); + Debug->printf("%d", id); + signal_->wait(); mutex_->release(); } @@ -73,6 +60,14 @@ namespace sta } // namespace spatz } // namespace sta + +void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart) +{ + if (sta::spatz::signal_ != nullptr) + sta::spatz::signal_->notify(); +} + + #else namespace sta