ELEC-C7222
Libraries for ELEC C7222 Course Work
Loading...
Searching...
No Matches
freertos_timer.hpp
Go to the documentation of this file.
1
5#ifndef ELEC_C7222_UTILS_FREE_RTOS_TIMER_HPP
6#define ELEC_C7222_UTILS_FREE_RTOS_TIMER_HPP
7
8#include <cstdint>
9#include <functional>
10
11#include "non_copyable.hpp"
12
13namespace c7222 {
14
25void FreeRtosTimerCallback(void* timer);
26
72 public:
73 enum class Type : uint8_t {
78 };
79
86 FreeRtosTimer() = default;
94 FreeRtosTimer(const char* name,
95 std::uint32_t period_ticks,
96 Type type,
97 std::function<void(void*)> callback = nullptr);
98
112 bool Initialize(const char* name,
113 std::uint32_t period_ticks,
114 Type type,
115 std::function<void(void*)> callback);
116
123
134 bool Start(std::uint32_t ticks_to_wait = 0, void* callback_arg = nullptr);
144 bool StartFromISR(void* callback_arg = nullptr);
154 bool Stop(std::uint32_t ticks_to_wait = 0);
155
174 bool Reset(std::uint32_t ticks_to_wait = 0);
175
195 bool ChangePeriod(std::uint32_t period_ticks, std::uint32_t ticks_to_wait = 0);
196
204 bool ChangePeriodFromISR(std::uint32_t period_ticks);
205
213 void SetCallback(std::function<void(void*)> callback);
214
219 bool IsValid() const;
220
225 bool IsActive() const;
226
227 private:
228 friend void FreeRtosTimerCallback(void* timer);
229
235 void* handle_{nullptr};
241 std::function<void(void*)> callback_{nullptr};
245 void* callback_arg_{nullptr};
246};
247
248} // namespace c7222
249
250#endif // ELEC_C7222_UTILS_FREE_RTOS_TIMER_HPP
Ownership-based C++ wrapper for FreeRTOS software timers.
Definition freertos_timer.hpp:71
bool IsValid() const
Check if the timer handle is valid.
bool Reset(std::uint32_t ticks_to_wait=0)
Reset the timer to start counting from zero.
bool IsActive() const
Check whether the timer is active.
friend void FreeRtosTimerCallback(void *timer)
Internal use only. This function is invoked as a callback when the FreeRTOS timer expires.
bool Stop(std::uint32_t ticks_to_wait=0)
Stop the timer.
bool ChangePeriod(std::uint32_t period_ticks, std::uint32_t ticks_to_wait=0)
Change the timer period.
FreeRtosTimer(const char *name, std::uint32_t period_ticks, Type type, std::function< void(void *)> callback=nullptr)
Create a FreeRTOS software timer.
bool ResetFromISR()
Reset the timer from ISR context (no immediate yield).
bool Start(std::uint32_t ticks_to_wait=0, void *callback_arg=nullptr)
Start the timer.
bool StartFromISR(void *callback_arg=nullptr)
Start the timer from ISR context (no immediate yield).
bool ChangePeriodFromISR(std::uint32_t period_ticks)
Change the timer period from ISR context (no immediate yield).
bool StopFromISR()
Stop the timer from ISR context (no immediate yield).
Type
Definition freertos_timer.hpp:73
@ kOneShot
One-shot timer: fires once then stops.
@ kPeriodic
Periodic timer: fires repeatedly at the configured period.
bool Initialize(const char *name, std::uint32_t period_ticks, Type type, std::function< void(void *)> callback)
Initialize (or re-initialize) the timer wrapper.
void SetCallback(std::function< void(void *)> callback)
Register or replace the timer callback.
FreeRtosTimer()=default
Create an uninitialized timer wrapper.
~FreeRtosTimer()
Delete the timer if it was created.
Disable both copy and move operations.
Definition non_copyable.hpp:75
C7222 course abstractions namespace.
Definition ble.hpp:20
void FreeRtosTimerCallback(void *timer)
Internal use only. This function is invoked as a callback when the FreeRTOS timer expires.
Base classes to control copy/move semantics.