-
-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathport_map_tmr.hpp
415 lines (400 loc) · 8.35 KB
/
port_map_tmr.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
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
#pragma once
//=========================================================================//
/*! @file
@brief RX660/RX671 グループ・ポート・マッピング (TMR)
@author 平松邦仁 ([email protected])
@copyright Copyright (C) 2024 Kunihito Hiramatsu @n
Released under the MIT license @n
https://github.com/hirakuni45/RX/blob/master/LICENSE
*/
//=========================================================================//
#if defined(SIG_RX660)
#include "RX660/peripheral.hpp"
#include "RX660/port.hpp"
#include "RX660/mpc.hpp"
#elif defined(SIG_RX671)
#include "RX671/peripheral.hpp"
#include "RX671/port.hpp"
#include "RX671/mpc.hpp"
#endif
#include "RX600/port_map_order.hpp"
namespace device {
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++//
/*!
@brief RX671 TMR ポート・マッピング・ユーティリティー
*/
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++//
class port_map_tmr : public port_map_order {
static bool tmr0_(CHANNEL ch, bool ena, ORDER odr) noexcept
{
bool ret = true;
uint8_t sel = ena ? 0b0'0101 : 0; // ok
switch(ch) {
case CHANNEL::TMO: // TMO0
// P22
// PB3
// PH1
switch(odr) {
case ORDER::FIRST:
PORT2::PMR.B2 = 0;
MPC::P22PFS.PSEL = sel;
PORT2::PMR.B2 = ena;
break;
case ORDER::SECOND:
PORTB::PMR.B3 = 0;
MPC::PB3PFS.PSEL = sel;
PORTB::PMR.B3 = ena;
break;
case ORDER::THIRD:
PORTH::PMR.B1 = 0;
MPC::PH1PFS.PSEL = sel;
PORTH::PMR.B1 = ena;
break;
default:
ret = false;
break;
}
break;
case CHANNEL::TMCI: // TMCI0
// P01
// P21
// PB1
// PH3 (RX660)
switch(odr) {
case ORDER::FIRST:
PORT0::PMR.B1 = 0;
MPC::P01PFS.PSEL = sel;
PORT0::PMR.B1 = ena;
break;
case ORDER::SECOND:
PORT2::PMR.B1 = 0;
MPC::P21PFS.PSEL = sel;
PORT2::PMR.B1 = ena;
break;
case ORDER::THIRD:
PORTB::PMR.B1 = 0;
MPC::PB1PFS.PSEL = sel;
PORTB::PMR.B1 = ena;
break;
#if defined(SIG_RX660)
case ORDER::FOURTH:
PORTH::PMR.B3 = 0;
MPC::PH3PFS.PSEL = sel;
PORTH::PMR.B3 = ena;
break;
#endif
default:
ret = false;
break;
}
break;
case CHANNEL::TMRI: // TMRI0
// P00
// P20
// PA4
// PH2
switch(odr) {
case ORDER::FIRST:
PORT0::PMR.B0 = 0;
MPC::P00PFS.PSEL = sel;
PORT0::PMR.B0 = ena;
break;
case ORDER::SECOND:
PORT2::PMR.B0 = 0;
MPC::P20PFS.PSEL = sel;
PORT2::PMR.B0 = ena;
break;
case ORDER::THIRD:
PORTA::PMR.B4 = 0;
MPC::PA4PFS.PSEL = sel;
PORTA::PMR.B4 = ena;
break;
case ORDER::FOURTH:
PORTH::PMR.B2 = 0;
MPC::PH2PFS.PSEL = sel;
PORTH::PMR.B2 = ena;
break;
default:
ret = false;
break;
}
break;
default:
ret = false;
break;
}
return ret;
}
static bool tmr1_(CHANNEL ch, bool ena, ORDER odr) noexcept
{
bool ret = true;
uint8_t sel = ena ? 0b0'0101 : 0; // ok
switch(ch) {
case CHANNEL::TMO: // TMO1
// P17
// P26
switch(odr) {
case ORDER::FIRST:
PORT1::PMR.B7 = 0;
MPC::P17PFS.PSEL = sel;
PORT1::PMR.B7 = ena;
break;
case ORDER::SECOND:
PORT2::PMR.B6 = 0;
MPC::P26PFS.PSEL = sel;
PORT2::PMR.B6 = ena;
break;
default:
ret = false;
break;
}
break;
case CHANNEL::TMCI: // TMCI1
// P02
// P12
// P54
// PC4
switch(odr) {
case ORDER::FIRST:
PORT0::PMR.B2 = 0;
MPC::P02PFS.PSEL = sel;
PORT0::PMR.B2 = ena;
break;
case ORDER::SECOND:
PORT1::PMR.B2 = 0;
MPC::P12PFS.PSEL = sel;
PORT1::PMR.B2 = ena;
break;
case ORDER::THIRD:
PORT5::PMR.B4 = 0;
MPC::P54PFS.PSEL = sel;
PORT5::PMR.B4 = ena;
break;
case ORDER::FOURTH:
PORTC::PMR.B4 = 0;
MPC::PC4PFS.PSEL = sel;
PORTC::PMR.B4 = ena;
break;
default:
ret = false;
break;
}
break;
case CHANNEL::TMRI: // TMRI1
// P24
// PB5
switch(odr) {
case ORDER::FIRST:
PORT2::PMR.B4 = 0;
MPC::P24PFS.PSEL = sel;
PORT2::PMR.B4 = ena;
break;
case ORDER::SECOND:
PORTB::PMR.B5 = 0;
MPC::PB5PFS.PSEL = sel;
PORTB::PMR.B5 = ena;
break;
default:
ret = false;
break;
}
break;
default:
ret = false;
break;
}
return ret;
}
static bool tmr2_(CHANNEL ch, bool ena, ORDER odr) noexcept
{
bool ret = true;
uint8_t sel = ena ? 0b0'0101 : 0; // ok
switch(ch) {
case CHANNEL::TMO: // TMO2
// P16
// PC7
switch(odr) {
case ORDER::FIRST:
PORT1::PMR.B6 = 0;
MPC::P16PFS.PSEL = sel;
PORT1::PMR.B6 = ena;
break;
case ORDER::SECOND:
PORTC::PMR.B7 = 0;
MPC::PC7PFS.PSEL = sel;
PORTC::PMR.B7 = ena;
break;
default:
ret = false;
break;
}
break;
case CHANNEL::TMCI: // TMCI2
// P15
// P31
// PC6
switch(odr) {
case ORDER::FIRST:
PORT1::PMR.B5 = 0;
MPC::P15PFS.PSEL = sel;
PORT1::PMR.B5 = ena;
break;
case ORDER::SECOND:
PORT3::PMR.B1 = 0;
MPC::P31PFS.PSEL = sel;
PORT3::PMR.B1 = ena;
break;
case ORDER::THIRD:
PORTC::PMR.B6 = 0;
MPC::PC6PFS.PSEL = sel;
PORTC::PMR.B6 = ena;
break;
default:
ret = false;
break;
}
break;
case CHANNEL::TMRI: // TMRI2
// P14
// PC5
switch(odr) {
case ORDER::FIRST:
PORT1::PMR.B4 = 0;
MPC::P14PFS.PSEL = sel;
PORT1::PMR.B4 = ena;
break;
case ORDER::SECOND:
PORTC::PMR.B5 = 0;
MPC::PC5PFS.PSEL = sel;
PORTC::PMR.B5 = ena;
break;
default:
ret = false;
break;
}
break;
default:
ret = false;
break;
}
return ret;
}
static bool tmr3_(CHANNEL ch, bool ena, ORDER odr) noexcept
{
bool ret = true;
uint8_t sel = ena ? 0b0'0101 : 0; // ok
switch(ch) {
case CHANNEL::TMO: // TMO3
// P13
// P32
// P55
switch(odr) {
case ORDER::FIRST:
PORT1::PMR.B3 = 0;
MPC::P13PFS.PSEL = sel;
PORT1::PMR.B3 = ena;
break;
case ORDER::SECOND:
PORT3::PMR.B2 = 0;
MPC::P32PFS.PSEL = sel;
PORT3::PMR.B2 = ena;
break;
case ORDER::THIRD:
PORT5::PMR.B5 = 0;
MPC::P55PFS.PSEL = sel;
PORT5::PMR.B5 = ena;
break;
default:
ret = false;
break;
}
break;
case CHANNEL::TMCI: // TMCI3
// P27
// P34
// PA6
switch(odr) {
case ORDER::FIRST:
PORT2::PMR.B7 = 0;
MPC::P27PFS.PSEL = sel;
PORT2::PMR.B7 = ena;
break;
case ORDER::SECOND:
PORT3::PMR.B4 = 0;
MPC::P34PFS.PSEL = sel;
PORT3::PMR.B4 = ena;
break;
case ORDER::THIRD:
PORTA::PMR.B6 = 0;
MPC::PA6PFS.PSEL = sel;
PORTA::PMR.B6 = ena;
break;
default:
ret = false;
break;
}
break;
case CHANNEL::TMRI: // TMRI3
// P30
// P33
switch(odr) {
case ORDER::FIRST:
PORT3::PMR.B0 = 0;
MPC::P30PFS.PSEL = sel;
PORT3::PMR.B0 = ena;
break;
case ORDER::SECOND:
PORT3::PMR.B3 = 0;
MPC::P33PFS.PSEL = sel;
PORT3::PMR.B3 = ena;
break;
default:
ret = false;
break;
}
break;
default:
ret = false;
break;
}
return ret;
}
public:
//-----------------------------------------------------------------//
/*!
@brief TMR 関係、チャネル別ポート切り替え
@param[in] per 周辺機器タイプ
@param[in] ch チャネル
@param[in] ena 無効にする場合「false」
@param[in] odr 候補選択
@return 無効な周辺機器の場合「false」
*/
//-----------------------------------------------------------------//
static bool turn(peripheral per, CHANNEL ch, bool ena = true, ORDER odr = ORDER::FIRST) noexcept
{
if(odr == ORDER::BYPASS) return true;
MPC::PWPR.B0WI = 0; // PWPR 書き込み許可
MPC::PWPR.PFSWE = 1; // PxxPFS 書き込み許可
bool ret = true;
switch(per) {
case peripheral::TMR0:
ret = tmr0_(ch, ena, odr);
break;
case peripheral::TMR1:
ret = tmr1_(ch, ena, odr);
break;
case peripheral::TMR2:
ret = tmr2_(ch, ena, odr);
break;
case peripheral::TMR3:
ret = tmr3_(ch, ena, odr);
break;
default:
ret = false;
break;
}
MPC::PWPR = device::MPC::PWPR.B0WI.b();
return ret;
}
};
}