Updated uart comunication for spatz

This commit is contained in:
dario 2024-08-03 22:47:01 +02:00
parent b0b775ffb0
commit ac1344747b
3 changed files with 19 additions and 23 deletions

View File

@ -2,6 +2,7 @@
#define STA_CORE_SPATZ_HPP #define STA_CORE_SPATZ_HPP
#include <sta/mutex.hpp> #include <sta/mutex.hpp>
#include <sta/signal.hpp>
#include <sta/config.hpp> #include <sta/config.hpp>
#ifdef STA_SPATZ_ENABLED #ifdef STA_SPATZ_ENABLED
@ -20,7 +21,7 @@ namespace sta
* *
* @param mutex A mutex used to make SPATZ thread-safe. * @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. * @brief Request bytes for a specific sensor id via the printable.

View File

@ -22,7 +22,7 @@ namespace sta
Profiler::~Profiler() 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 } // namespace sta

View File

@ -6,19 +6,20 @@
# error "The ID used to communicate SPATZ initialization was not defined." # error "The ID used to communicate SPATZ initialization was not defined."
#endif // STA_INIT_SPATZ_ID #endif // STA_INIT_SPATZ_ID
#include <cmsis_os2.h>
#include <FreeRTOS.h>
#include <usart.h> #include <usart.h>
namespace sta namespace sta
{ {
namespace spatz 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; mutex_ = mutex;
signal_ = signal;
uint8_t msg = 0xFF; uint8_t msg = 0xFF;
sta::lock_guard<sta::Mutex> lock(*mutex_); sta::lock_guard<sta::Mutex> lock(*mutex_);
@ -42,23 +43,9 @@ namespace sta
{ {
mutex_->acquire(); mutex_->acquire();
bool success = false; HAL_UART_Receive_IT(&huart1, reinterpret_cast<uint8_t*>(buffer), length * sizeof(float));
Debug->printf("%d", id);
while (!success) signal_->wait();
{
Debug->printf("%d", id);
HAL_StatusTypeDef state = HAL_UART_Receive(&huart1, reinterpret_cast<uint8_t*>(buffer), length * sizeof(float), 100);
if (state == HAL_TIMEOUT)
{
success = false;
Debug->println(">ERROR");
break;
}
success = true;
}
mutex_->release(); mutex_->release();
} }
@ -73,6 +60,14 @@ namespace sta
} // namespace spatz } // namespace spatz
} // namespace sta } // namespace sta
void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart)
{
if (sta::spatz::signal_ != nullptr)
sta::spatz::signal_->notify();
}
#else #else
namespace sta namespace sta