-
-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathpower_mgr.hpp
177 lines (148 loc) · 4.25 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
#pragma once
//=========================================================================//
/*! @file
@brief Low Power Consumption / 消費電力低減機能 (RX140)
@author 平松邦仁 ([email protected])
@copyright Copyright (C) 2024 Kunihito Hiramatsu @n
Released under the MIT license @n
https://github.com/hirakuni45/RX/blob/master/LICENSE
*/
//=========================================================================//
#include "RX140/system.hpp"
#include "RX140/peripheral.hpp"
namespace device {
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++//
/*!
@brief 電力制御クラス
*/
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++//
struct power_mgr {
struct pad_t {
uint8_t tmr_;
uint8_t mtu_;
uint8_t cmt_;
pad_t() :
tmr_(0),
mtu_(0),
cmt_(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)));
}
}
//-----------------------------------------------------------------//
/*!
@brief モジュール・ストップ機能を設定
@param[in] per 周辺機器タイプ
@param[in] ena オフにする場合「false」
@return ペリフェラルが見つからない場合「false」
*/
//-----------------------------------------------------------------//
static bool turn(peripheral per, bool ena = true)
{
device::SYSTEM::PRCR = 0xA500 | device::SYSTEM::PRCR.PRC1.b();
bool ret = true;
bool f = !ena;
switch(per) {
case peripheral::TMR3:
case peripheral::TMR2:
sr_(ena, pad_.tmr_, peripheral::TMR0, per);
SYSTEM::MSTPCRA.MSTPA4 = ((pad_.tmr_ & 0b00'00'11'00) == 0);
break;
case peripheral::TMR1:
case peripheral::TMR0:
sr_(ena, pad_.tmr_, peripheral::TMR0, per);
SYSTEM::MSTPCRA.MSTPA5 = ((pad_.tmr_ & 0b00'00'00'11) == 0);
break;
case peripheral::MTU0:
case peripheral::MTU1:
case peripheral::MTU2:
case peripheral::MTU3:
case peripheral::MTU4:
case peripheral::MTU5:
sr_(ena, pad_.mtu_, peripheral::MTU0, per);
SYSTEM::MSTPCRA.MSTPA9 = (pad_.mtu_ == 0);
break;
case peripheral::CMT0:
case peripheral::CMT1:
// CMT0, CMT1 のストップ状態設定
sr_(ena, pad_.cmt_, peripheral::CMT0, per);
SYSTEM::MSTPCRA.MSTPA15 = ((pad_.cmt_ & 0b0011) == 0);
break;
case peripheral::S12AD:
SYSTEM::MSTPCRA.MSTPA17 = f;
break;
case peripheral::DA:
SYSTEM::MSTPCRA.MSTPA19 = f;
break;
case peripheral::DTC:
SYSTEM::MSTPCRA.MSTPA28 = f;
break;
case peripheral::RSCAN:
SYSTEM::MSTPCRB.MSTPB0 = f;
break;
case peripheral::SCI12:
SYSTEM::MSTPCRB.MSTPB4 = f;
break;
case peripheral::DOC:
SYSTEM::MSTPCRB.MSTPB6 = f;
break;
case peripheral::ELC:
SYSTEM::MSTPCRB.MSTPB9 = f;
break;
case peripheral::CMPB:
SYSTEM::MSTPCRB.MSTPB10 = f;
break;
case peripheral::RSPI0:
SYSTEM::MSTPCRB.MSTPB17 = f;
break;
case peripheral::RIIC0:
SYSTEM::MSTPCRB.MSTPB21 = f;
break;
case peripheral::CRC:
SYSTEM::MSTPCRB.MSTPB23 = f;
break;
case peripheral::SCI6:
SYSTEM::MSTPCRB.MSTPB25 = f;
break;
case peripheral::SCI5:
SYSTEM::MSTPCRB.MSTPB26 = f;
break;
case peripheral::SCI1:
SYSTEM::MSTPCRB.MSTPB30 = f;
break;
case peripheral::CAC:
SYSTEM::MSTPCRC.MSTPC19 = f;
break;
case peripheral::SCI9:
SYSTEM::MSTPCRC.MSTPC26 = f;
break;
case peripheral::SCI8:
SYSTEM::MSTPCRC.MSTPC27 = f;
break;
case peripheral::CTSU:
SYSTEM::MSTPCRD.MSTPD10 = f;
break;
default:
ret = false;
break;
}
device::SYSTEM::PRCR = 0xA500;
return ret;
}
};
}