Added barrier pattern, thread yield and updated event API

This commit is contained in:
dario
2024-03-19 14:11:10 +01:00
parent 4ce4653f71
commit 1a8f8c5dff
6 changed files with 141 additions and 8 deletions

View File

@@ -9,6 +9,10 @@
#include <cmsis_os2.h>
#include <sta/event.hpp>
#define STA_EVENT_FLAGS_ALL 0xFFFFFFFFU
namespace sta
{
/**
@@ -25,12 +29,12 @@ namespace sta
/**
* @brief Set given flags for the event.
*/
void set(uint32_t flags) override;
void set(uint32_t flags = STA_EVENT_FLAGS_ALL) override;
/**
* @brief Clear given flags for the event.
*/
void clear(uint32_t flags) override;
void clear(uint32_t flags = STA_EVENT_FLAGS_ALL) override;
/**
* @brief Get current flags for the event.
@@ -46,11 +50,11 @@ namespace sta
* @param timeout Timeout in milliseconds.
* @return Event flags before clearing or error code if highest bit set.
*/
uint32_t wait(uint32_t flags, uint32_t timeout = osWaitForever) override;
uint32_t wait(uint32_t flags = STA_EVENT_FLAGS_ALL, uint32_t timeout = osWaitForever) override;
private:
osEventFlagsId_t event_id; /**< CMSIS RTOS2 Event Flag */
};
} // namespace sta
#endif // STA_RTOS_EVENT_HPP
#endif // STA_RTOS_EVENT_HPP

View File

@@ -0,0 +1,31 @@
/*
* barrier.hpp
*
* Created on: Mar 16, 2024
* Author: Dario
*/
#ifndef RTOS2_UTILS_STA_PATTERNS_BARRIER_HPP
#define RTOS2_UTILS_STA_PATTERNS_BARRIER_HPP
#include <sta/rtos/mutex.hpp>
#include <sta/rtos/event.hpp>
namespace sta
{
class Barrier {
public:
Barrier(const char* name, uint8_t n_threads);
void wait();
private:
RtosMutex mutex_;
RtosEvent flag_;
const uint8_t n_threads_;
uint8_t n_entered_;
uint8_t n_left_;
};
} // namespace sta
#endif /* RTOS2_UTILS_STA_PATTERNS_BARRIER_HPP_ */

View File

@@ -107,6 +107,12 @@ namespace sta
*/
void sleep(uint32_t ticks);
/**
* @brief Makes the currently running thread pass control to the next thread.
*
*/
void yield();
/**
* @brief Send user notification flags to thread.
*