ELEC-C7222
Libraries for ELEC C7222 Course Work
Loading...
Searching...
No Matches
freertos_semaphore.hpp
Go to the documentation of this file.
1
5#ifndef ELEC_C7222_UTILS_FREERTOS_SEMAPHORE_HPP
6#define ELEC_C7222_UTILS_FREERTOS_SEMAPHORE_HPP
7
8#include <cstdint>
9
10#include "non_copyable.hpp"
11
12namespace c7222 {
13
36 public:
43 explicit FreeRtosBinarySemaphore(bool initially_given);
49 bool Initialize(bool initially_given = false);
52
58 bool Take(std::uint32_t ticks_to_wait = 0);
63 bool Give();
70 bool IsValid() const;
71
72 private:
73 void* handle_{nullptr};
74};
75
95 public:
103 FreeRtosCountingSemaphore(std::uint32_t max_count, std::uint32_t initial_count);
110 bool Initialize(std::uint32_t max_count, std::uint32_t initial_count);
113
119 bool Take(std::uint32_t ticks_to_wait = 0);
124 bool Give();
131 std::uint32_t GetCount() const;
133 bool IsValid() const;
134
135 private:
136 void* handle_{nullptr};
137};
138
139} // namespace c7222
140
141#endif // ELEC_C7222_UTILS_FREERTOS_SEMAPHORE_HPP
Ownership-based wrapper for a FreeRTOS-style binary semaphore.
Definition freertos_semaphore.hpp:35
bool Initialize(bool initially_given=false)
Initialize (or re-initialize) the semaphore.
bool Take(std::uint32_t ticks_to_wait=0)
Take the semaphore.
bool Give()
Give the semaphore from task context.
FreeRtosBinarySemaphore(bool initially_given)
Construct and initialize a binary semaphore.
bool GiveFromISR()
Give the semaphore from ISR context.
~FreeRtosBinarySemaphore()
Destroy semaphore resources if initialized.
FreeRtosBinarySemaphore()=default
Construct an uninitialized semaphore wrapper.
Ownership-based wrapper for a FreeRTOS-style counting semaphore.
Definition freertos_semaphore.hpp:94
bool Give()
Return one token to the semaphore from task context.
~FreeRtosCountingSemaphore()
Destroy semaphore resources if initialized.
std::uint32_t GetCount() const
FreeRtosCountingSemaphore(std::uint32_t max_count, std::uint32_t initial_count)
Construct and initialize a counting semaphore.
bool Initialize(std::uint32_t max_count, std::uint32_t initial_count)
Initialize (or re-initialize) a counting semaphore.
bool GiveFromISR()
Return one token to the semaphore from ISR context.
FreeRtosCountingSemaphore()=default
Construct an uninitialized counting semaphore wrapper.
bool Take(std::uint32_t ticks_to_wait=0)
Take one token from the semaphore.
Disable both copy and move operations.
Definition non_copyable.hpp:75
C7222 course abstractions namespace.
Definition ble.hpp:20
Base classes to control copy/move semantics.