-
-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathpower_mgr.hpp
241 lines (210 loc) · 6.73 KB
/
power_mgr.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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
#pragma once
//=========================================================================//
/*! @file
@brief Low Power Consumption / 消費電力低減機能 (RX660)
@author 平松邦仁 (hira@rvf-rc45.net)
@copyright Copyright (C) 2024 Kunihito Hiramatsu @n
Released under the MIT license @n
https://github.com/hirakuni45/RX/blob/master/LICENSE
*/
//=========================================================================//
#include "RX660/peripheral.hpp"
#include "RX600/system.hpp"
#include "RX600/bus.hpp"
namespace device {
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++//
/*!
@brief 省電力制御クラス
*/
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++//
class power_mgr {
struct pad_t {
uint8_t tmr_;
uint8_t cmt_;
uint8_t cmpc_;
uint16_t mtu_;
uint16_t dmac_;
pad_t() :
tmr_(0),
cmt_(0),
cmpc_(0),
mtu_(0),
dmac_(0)
{ }
};
static inline pad_t pad_;
static void sr_(bool f, uint8_t& pad, peripheral org, peripheral tgt)
{
if(f) {
pad |= 1 << (static_cast<uint16_t>(tgt) - static_cast<uint16_t>(org));
} else {
pad &= ~(1 << (static_cast<uint16_t>(tgt) - static_cast<uint16_t>(org)));
}
}
static void sr_(bool f, uint16_t& pad, peripheral org, peripheral tgt)
{
if(f) {
pad |= 1 << (static_cast<uint16_t>(tgt) - static_cast<uint16_t>(org));
} else {
pad &= ~(1 << (static_cast<uint16_t>(tgt) - static_cast<uint16_t>(org)));
}
}
public:
//-----------------------------------------------------------------//
/*!
@brief 周辺機器に切り替える
@param[in] t 周辺機器タイプ
@param[in] ena オフにする場合「false」
@return ペリフェラルが見つからない場合「false」
*/
//-----------------------------------------------------------------//
static bool turn(peripheral t, bool ena = true)
{
device::SYSTEM::PRCR = 0xA500 | device::SYSTEM::PRCR.PRC1.b();
bool ret = true;
bool f = !ena;
switch(t) {
case peripheral::CMTW1:
SYSTEM::MSTPCRA.MSTPA0 = f;
break;
case peripheral::CMTW0:
SYSTEM::MSTPCRA.MSTPA1 = f;
break;
case peripheral::TMR2:
case peripheral::TMR3:
sr_(ena, pad_.tmr_, peripheral::TMR0, t);
SYSTEM::MSTPCRA.MSTPA4 = ((pad_.tmr_ & 0b1100) == 0);
break;
case peripheral::TMR0:
case peripheral::TMR1:
sr_(ena, pad_.tmr_, peripheral::TMR0, t);
SYSTEM::MSTPCRA.MSTPA5 = ((pad_.tmr_ & 0b0011) == 0);
break;
case peripheral::MTU0:
case peripheral::MTU1:
case peripheral::MTU2:
case peripheral::MTU3:
case peripheral::MTU4:
case peripheral::MTU5:
case peripheral::MTU6:
case peripheral::MTU7:
case peripheral::MTU8:
sr_(ena, pad_.mtu_, peripheral::MTU0, t);
SYSTEM::MSTPCRA.MSTPA9 = (pad_.mtu_ == 0);
break;
case peripheral::CMT0:
case peripheral::CMT1:
sr_(ena, pad_.cmt_, peripheral::CMT0, t);
SYSTEM::MSTPCRA.MSTPA15 = ((pad_.cmt_ & 0b0011) == 0);
break;
case peripheral::CMT2:
case peripheral::CMT3:
sr_(ena, pad_.cmt_, peripheral::CMT0, t);
SYSTEM::MSTPCRA.MSTPA14 = ((pad_.cmt_ & 0b1100) == 0);
break;
case peripheral::S12AD:
SYSTEM::MSTPCRA.MSTPA17 = f; // S12AD のストップ状態解除
break;
case peripheral::R12DA:
SYSTEM::MSTPCRA.MSTPA19 = f; // R12DA のストップ状態解除
break;
case peripheral::DMAC0:
case peripheral::DMAC1:
case peripheral::DMAC2:
case peripheral::DMAC3:
case peripheral::DMAC4:
case peripheral::DMAC5:
case peripheral::DMAC6:
case peripheral::DMAC7:
case peripheral::DTC:
sr_(ena, pad_.dmac_, peripheral::DMAC0, t);
SYSTEM::MSTPCRA.MSTPA28 = (pad_.dmac_ == 0);
break;
case peripheral::SCI12:
SYSTEM::MSTPCRB.MSTPB4 = f; // B-B4 (SCI12)のストップ状態解除
break;
case peripheral::DOC:
SYSTEM::MSTPCRB.MSTPB6 = f;
break;
case peripheral::ELC:
SYSTEM::MSTPCRB.MSTPB9 = f; // ELC のストップ状態解除
break;
case peripheral::CMPC0:
case peripheral::CMPC1:
case peripheral::CMPC2:
case peripheral::CMPC3:
sr_(ena, pad_.cmpc_, peripheral::CMPC0, t);
SYSTEM::MSTPCRB.MSTPB10 = (pad_.cmpc_ == 0);
break;
case peripheral::RSPI0:
SYSTEM::MSTPCRB.MSTPB17 = f; // RSPI0 のストップ状態解除
break;
case peripheral::RIIC0:
SYSTEM::MSTPCRB.MSTPB21 = f; // RIIC0 のストップ状態解除
break;
case peripheral::CRC:
SYSTEM::MSTPCRB.MSTPB23 = f;
break;
case peripheral::SCI7:
SYSTEM::MSTPCRB.MSTPB24 = f; // B24 (SCI7)のストップ状態解除
break;
case peripheral::SCI6:
SYSTEM::MSTPCRB.MSTPB25 = f; // B25 (SCI6)のストップ状態解除
break;
case peripheral::SCI5:
SYSTEM::MSTPCRB.MSTPB26 = f; // B26 (SCI5)のストップ状態解除
break;
case peripheral::SCI4:
SYSTEM::MSTPCRB.MSTPB27 = f; // B27 (SCI4)のストップ状態解除
break;
case peripheral::SCI3:
SYSTEM::MSTPCRB.MSTPB28 = f; // B28 (SCI3)のストップ状態解除
break;
case peripheral::SCI2:
SYSTEM::MSTPCRB.MSTPB29 = f; // B29 (SCI2)のストップ状態解除
break;
case peripheral::SCI1:
SYSTEM::MSTPCRB.MSTPB30 = f; // B30 (SCI1)のストップ状態解除
break;
case peripheral::SCI0:
SYSTEM::MSTPCRB.MSTPB31 = f; // B31 (SCI0)のストップ状態解除
break;
case peripheral::RIIC2:
SYSTEM::MSTPCRC.MSTPC17 = f; // RIIC2 のストップ状態解除
break;
case peripheral::CAC:
SYSTEM::MSTPCRC.MSTPC19 = f; // CAC のストップ状態解除
break;
case peripheral::SCI11:
SYSTEM::MSTPCRC.MSTPC24 = f; // SCI11のストップ状態解除
break;
case peripheral::SCI10:
SYSTEM::MSTPCRC.MSTPC25 = f; // SCI10のストップ状態解除
break;
case peripheral::SCI9:
SYSTEM::MSTPCRC.MSTPC26 = f; // C-B26 (SCI9)のストップ状態解除
break;
case peripheral::SCI8:
SYSTEM::MSTPCRC.MSTPC27 = f; // C-B27 (SCI8)のストップ状態解除
break;
case peripheral::RSCI11:
SYSTEM::MSTPCRD.MSTPD2 = f; // RSCI11 のストップ状態解除
break;
case peripheral::RSCI10:
SYSTEM::MSTPCRD.MSTPD3 = f; // RSCI10 のストップ状態解除
break;
case peripheral::REMC0:
SYSTEM::MSTPCRD.MSTPD7 = f; // REMC のストップ状態解除
break;
case peripheral::CANFD0:
SYSTEM::MSTPCRD.MSTPD10 = f; // CANFD のストップ状態解除
break;
default:
ret = false;
break;
}
device::SYSTEM::PRCR = 0xA500;
return ret;
}
};
}