halx
読み取り中…
検索中…
一致する文字列を見つけられません
timer.hpp
[詳解]
1#pragma once
2
3#include <cstdint>
4#include <memory>
5#include <type_traits>
6
7#include <cmsis_os2.h>
8
9namespace halx::rtos {
10
11class Timer {
12private:
13 struct Deleter {
14 void operator()(osTimerId_t timer_id) { osTimerDelete(timer_id); }
15 };
16
17 using TimerId = std::unique_ptr<std::remove_pointer_t<osTimerId_t>, Deleter>;
18
19public:
20 Timer(void (*func)(void *), void *args, osTimerType_t type,
21 uint32_t attr_bits = 0) {
22 osTimerAttr_t attr{};
23 attr.attr_bits = attr_bits;
24 timer_id_ = TimerId{osTimerNew(func, type, args, &attr)};
25 }
26
27 bool start(uint32_t ticks) {
28 return osTimerStart(timer_id_.get(), ticks) == osOK;
29 }
30
31 bool stop() { return osTimerStop(timer_id_.get()) == osOK; }
32
33 bool is_running() { return osTimerIsRunning(timer_id_.get()) == 1; }
34
35private:
36 TimerId timer_id_;
37};
38
39} // namespace halx::rtos
Timer(void(*func)(void *), void *args, osTimerType_t type, uint32_t attr_bits=0)
Definition timer.hpp:20
bool is_running()
Definition timer.hpp:33
bool start(uint32_t ticks)
Definition timer.hpp:27
bool stop()
Definition timer.hpp:31
Definition mutex.hpp:9