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