-
-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathintr_utils.hpp
85 lines (71 loc) · 2.18 KB
/
intr_utils.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#pragma once
//=====================================================================//
/*! @file
@brief 割り込み・ユーティリティー
@author 平松邦仁 ([email protected])
@copyright Copyright (C) 2017, 2021 Kunihito Hiramatsu @n
Released under the MIT license @n
https://github.com/hirakuni45/R8C/blob/master/LICENSE
*/
//=====================================================================//
#include <cstdint>
namespace utils {
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++//
/*!
@brief null タスク
*/
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++//
class null_task {
public:
//-----------------------------------------------------------------//
/*!
@brief ファンクタ
*/
//-----------------------------------------------------------------//
void operator () () {
}
};
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++//
/*!
@brief カウント・タスク
*/
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++//
class count_task {
volatile uint32_t count_;
public:
count_task() noexcept : count_(0) { }
//-----------------------------------------------------------------//
/*!
@brief ファンクタ
*/
//-----------------------------------------------------------------//
void operator () () {
++count_;
}
//-----------------------------------------------------------------//
/*!
@brief 同期
*/
//-----------------------------------------------------------------//
void sync() const noexcept
{
auto tmp = count_;
while(tmp == count_) {
}
}
//-----------------------------------------------------------------//
/*!
@brief カウンタの取得
@return カウンタ
*/
//-----------------------------------------------------------------//
auto get_count() const noexcept { return count_; }
//-----------------------------------------------------------------//
/*!
@brief カウンタの設定
@param[in] count カウント値
*/
//-----------------------------------------------------------------//
void set_count(uint32_t count) noexcept { count_ = count; }
};
}