halx
読み取り中…
検索中…
一致する文字列を見つけられません
common.hpp
[詳解]
1#pragma once
2
3#include <cstdint>
4
5#include <stm32cubemx_helper/device.hpp>
6
7#if __has_include(<cmsis_os2.h>)
8#include <cmsis_os2.h>
9#endif
10
11namespace halx::core {
12
13#if __has_include(<cmsis_os2.h>)
14inline constexpr uint32_t MAX_DELAY = osWaitForever;
15#else
16inline constexpr uint32_t MAX_DELAY = HAL_MAX_DELAY;
17#endif
18
19inline uint32_t get_tick() {
20#if __has_include(<cmsis_os2.h>)
21 return osKernelGetTickCount();
22#else
23 return HAL_GetTick();
24#endif
25}
26
27inline void delay(uint32_t tick) {
28#if __has_include(<cmsis_os2.h>)
29 osDelay(tick);
30#else
31 HAL_Delay(tick);
32#endif
33}
34
35inline void delay_until(uint32_t tick) {
36#if __has_include(<cmsis_os2.h>)
37 osDelayUntil(tick);
38#else
39 int32_t diff = static_cast<int32_t>(tick - HAL_GetTick());
40 if (diff > 0) {
41 HAL_Delay(diff);
42 }
43#endif
44}
45
46inline void yield() {
47#if __has_include(<cmsis_os2.h>)
48 osThreadYield();
49#else
50 __NOP();
51#endif
52}
53
54} // namespace halx::core
Definition common.hpp:11
uint32_t get_tick()
Definition common.hpp:19
void delay_until(uint32_t tick)
Definition common.hpp:35
constexpr uint32_t MAX_DELAY
Definition common.hpp:16
void yield()
Definition common.hpp:46
void delay(uint32_t tick)
Definition common.hpp:27