-
-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathpower_mgr.hpp
366 lines (318 loc) · 10.1 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
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
#pragma once
//=========================================================================//
/*! @file
@brief Low Power Consumption / 消費電力低減機能 (RX72M)
@author 平松邦仁 (hira@rvf-rc45.net)
@copyright Copyright (C) 2019, 2024 Kunihito Hiramatsu @n
Released under the MIT license @n
https://github.com/hirakuni45/RX/blob/master/LICENSE
*/
//=========================================================================//
#include "RX72M/peripheral.hpp"
#include "RX600/system.hpp"
#include "RX600/bus.hpp"
#include "common/static_holder.hpp"
namespace device {
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++//
/*!
@brief 電力制御クラス
*/
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++//
class power_mgr {
struct pad_t {
uint8_t cmt_;
uint8_t tpu_;
uint8_t tmr_;
uint8_t gptw_;
uint16_t mtu_;
uint16_t dmac_;
uint8_t exdmac_;
uint8_t dsmif_;
pad_t() :
cmt_(0),
tpu_(0),
tmr_(0),
gptw_(0),
mtu_(0),
dmac_(0),
exdmac_(0),
dsmif_(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」
*/
//-----------------------------------------------------------------//
static void turn(peripheral t, bool ena = true)
{
device::SYSTEM::PRCR = 0xA500 | device::SYSTEM::PRCR.PRC1.b();
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::POE3:
case peripheral::GPTW0:
case peripheral::GPTW1:
case peripheral::GPTW2:
case peripheral::GPTW3:
sr_(ena, pad_.gptw_, peripheral::POE3, t);
SYSTEM::MSTPCRA.MSTPA7 = (pad_.gptw_ == 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::PPG1:
SYSTEM::MSTPCRA.MSTPA10 = f;
break;
case peripheral::PPG0:
SYSTEM::MSTPCRA.MSTPA11 = f;
break;
// TPU0 to TPU5 のストップ状態設定
case peripheral::TPU0:
case peripheral::TPU1:
case peripheral::TPU2:
case peripheral::TPU3:
case peripheral::TPU4:
case peripheral::TPU5:
sr_(ena, pad_.tpu_, peripheral::TPU0, t);
SYSTEM::MSTPCRA.MSTPA13 = (pad_.tpu_ == 0);
break;
// CMT2, CMT3 のストップ状態設定
case peripheral::CMT2:
case peripheral::CMT3:
sr_(ena, pad_.cmt_, peripheral::CMT0, t);
SYSTEM::MSTPCRA.MSTPA14 = ((pad_.cmt_ & 0b1100) == 0);
break;
// CMT0, CMT1 のストップ状態設定
case peripheral::CMT0:
case peripheral::CMT1:
sr_(ena, pad_.cmt_, peripheral::CMT0, t);
SYSTEM::MSTPCRA.MSTPA15 = ((pad_.cmt_ & 0b0011) == 0);
break;
case peripheral::S12AD1:
SYSTEM::MSTPCRA.MSTPA16 = f; // S12AD1 のストップ状態解除
break;
case peripheral::S12AD:
SYSTEM::MSTPCRA.MSTPA17 = f; // S12AD のストップ状態解除
break;
case peripheral::R12DA:
SYSTEM::MSTPCRA.MSTPA19 = f; // R12DA のストップ状態解除
break;
// DMAC/DTC のストップ状態解除
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::EXDMAC0:
case peripheral::EXDMAC1:
sr_(ena, pad_.exdmac_, peripheral::EXDMAC0, t);
SYSTEM::MSTPCRA.MSTPA29 = (pad_.exdmac_ == 0);
break;
// CAN モジュール
case peripheral::CAN0:
SYSTEM::MSTPCRB.MSTPB0 = f;
break;
case peripheral::CAN1:
SYSTEM::MSTPCRB.MSTPB1 = f;
break;
case peripheral::CAN2:
SYSTEM::MSTPCRB.MSTPB2 = f;
break;
case peripheral::SCI12:
SYSTEM::MSTPCRB.MSTPB4 = f; // B-B4 (SCI12)のストップ状態解除
break;
case peripheral::DOC: // データ演算回路
SYSTEM::MSTPCRB.MSTPB6 = f;
break;
case peripheral::TEMPS: // 温度センサ
SYSTEM::MSTPCRB.MSTPB8 = f;
break;
case peripheral::ELC: // イベントリンク
SYSTEM::MSTPCRB.MSTPB9 = f;
break;
case peripheral::DSMIF0:
case peripheral::DSMIF1:
sr_(ena, pad_.dsmif_, peripheral::DSMIF0, t);
SYSTEM::MSTPCRB.MSTPB11 = (pad_.dsmif_ == 0);
break;
case peripheral::EPTPC:
case peripheral::PTPEDMAC:
SYSTEM::MSTPCRB.MSTPB13 = f;
break;
case peripheral::ETHERC1:
case peripheral::EDMAC1:
case peripheral::PMGI1:
SYSTEM::MSTPCRB.MSTPB14 = f; // ETHER1, EDMAC1 のストップ状態解除
BUS::BEREN.TOEN = 1;
break;
case peripheral::ETHERC0:
case peripheral::ETHERCA:
case peripheral::EDMAC0:
case peripheral::PMGI0:
SYSTEM::MSTPCRB.MSTPB15 = f; // ETHER0, EDMAC0 のストップ状態解除
BUS::BEREN.TOEN = 1;
break;
case peripheral::RSPI1:
SYSTEM::MSTPCRB.MSTPB16 = f; // RSPI1 のストップ状態解除
break;
case peripheral::RSPI0:
SYSTEM::MSTPCRB.MSTPB17 = f; // RSPI0 のストップ状態解除
break;
case peripheral::USB0:
SYSTEM::MSTPCRB.MSTPB19 = f; // USB のストップ状態解除
break;
case peripheral::RIIC1:
SYSTEM::MSTPCRB.MSTPB20 = f; // RIIC1 のストップ状態解除
break;
case peripheral::RIIC0:
SYSTEM::MSTPCRB.MSTPB21 = f; // RIIC0 のストップ状態解除
break;
case peripheral::PDC:
SYSTEM::MSTPCRB.MSTPB22 = f;
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::RAM:
SYSTEM::MSTPCRC.MSTPC0 = f; // RAM のストップ状態解除
break;
case peripheral::EXTRAM:
SYSTEM::MSTPCRC.MSTPC2 = f; // RAM2 のストップ状態解除
break;
case peripheral::ECCRAM:
SYSTEM::MSTPCRC.MSTPC6 = f; // ECC RAM のストップ状態解除
break;
case peripheral::STBRAM:
SYSTEM::MSTPCRC.MSTPC7 = f; // STANDBY RAM のストップ状態解除
break;
case peripheral::RIIC2:
SYSTEM::MSTPCRC.MSTPC17 = f; // RIIC2 のストップ状態解除
break;
case peripheral::CAC:
SYSTEM::MSTPCRC.MSTPC19 = f; // CAC のストップ状態解除
break;
case peripheral::RSPI2:
SYSTEM::MSTPCRC.MSTPC22 = f; // RSPI2 のストップ状態解除
break;
case peripheral::QSPI:
SYSTEM::MSTPCRC.MSTPC23 = f; // QSPI のストップ状態解除
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; // SCI9 のストップ状態解除
break;
case peripheral::SCI8:
SYSTEM::MSTPCRC.MSTPC27 = f; // SCI8 のストップ状態解除
break;
case peripheral::DRW2D:
SYSTEM::MSTPCRC.MSTPC28 = f; // DRW2D のストップ状態解除
break;
case peripheral::GLCDC:
SYSTEM::MSTPCRC.MSTPC29 = f; // GLCDC のストップ状態解除
break;
case peripheral::ESC:
SYSTEM::MSTPCRD.MSTPD11 = f; // EtherCAT のストップ状態解除
break;
case peripheral::SSIE1:
SYSTEM::MSTPCRD.MSTPD14 = f; // SSIE1 のストップ状態解除
break;
case peripheral::SSIE0:
SYSTEM::MSTPCRD.MSTPD15 = f; // SSIE0 のストップ状態解除
break;
case peripheral::SDHI:
SYSTEM::MSTPCRD.MSTPD19 = f; // SDHI のストップ状態解除
break;
case peripheral::MMCIF:
SYSTEM::MSTPCRD.MSTPD21 = f;
break;
case peripheral::TSIP:
SYSTEM::MSTPCRD.MSTPD27 = f;
break;
default:
break;
}
device::SYSTEM::PRCR = 0xA500;
}
};
}