-
-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathport_map_tpu.hpp
592 lines (568 loc) · 12.2 KB
/
port_map_tpu.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
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
#pragma once
//=========================================================================//
/*! @file
@brief RX671 グループ・ポート・マッピング (TPU) @n
・TPU 型に従って、タイマー用ポートを設定 @n
TPU0, TPU1, TPU2, TPU3, TPU4, TPU5
@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 "RX671/peripheral.hpp"
#include "RX671/port.hpp"
#include "RX671/mpc.hpp"
#include "RX600/port_map_order.hpp"
namespace device {
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++//
/*!
@brief TPU ポート・マッピング・ユーティリティー
*/
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++//
class port_map_tpu : public port_map_order {
static bool tpu0_(CHANNEL ch, bool ena, ORDER odr) noexcept
{
bool ret = true;
uint8_t sel = ena ? 0b00'0011 : 0;
switch(ch) {
case CHANNEL::A:
// TIOCA0:
switch(odr) {
// P86
// PA0
case ORDER::FIRST:
PORT8::PMR.B6 = 0;
MPC::P86PFS.PSEL = sel;
PORT8::PMR.B6 = ena;
break;
case ORDER::SECOND:
PORTA::PMR.B0 = 0;
MPC::PA0PFS.PSEL = sel;
PORTA::PMR.B0 = ena;
break;
default:
ret = false;
break;
}
break;
case CHANNEL::B:
// TIOCB0:
switch(odr) {
// P17
// PA1
case ORDER::FIRST:
PORT1::PMR.B7 = 0;
MPC::P17PFS.PSEL = sel;
PORT1::PMR.B7 = ena;
break;
case ORDER::SECOND:
PORTA::PMR.B1 = 0;
MPC::PA1PFS.PSEL = sel;
PORTA::PMR.B1 = ena;
break;
default:
ret = false;
break;
}
break;
case CHANNEL::C:
// TIOCC0:
switch(odr) {
// P32
case ORDER::FIRST:
PORT3::PMR.B2 = 0;
MPC::P32PFS.PSEL = sel;
PORT3::PMR.B2 = ena;
break;
default:
ret = false;
break;
}
break;
case CHANNEL::D:
// TIOCD0:
switch(odr) {
// P33
// PA3
case ORDER::FIRST:
PORT3::PMR.B3 = 0;
MPC::P33PFS.PSEL = sel;
PORT3::PMR.B3 = ena;
break;
case ORDER::SECOND:
PORTA::PMR.B3 = 0;
MPC::PA3PFS.PSEL = sel;
PORTA::PMR.B3 = ena;
break;
default:
ret = false;
break;
}
break;
default:
ret = false;
break;
}
return ret;
}
static bool tpu1_(CHANNEL ch, bool ena, ORDER odr) noexcept
{
bool ret = true;
uint8_t sel = ena ? 0b00'0011 : 0;
switch(ch) {
case CHANNEL::A:
// TIOCA1:
switch(odr) {
// P56
// PA4
case ORDER::FIRST:
PORT5::PMR.B6 = 0;
MPC::P56PFS.PSEL = sel;
PORT5::PMR.B6 = ena;
break;
case ORDER::SECOND:
PORTA::PMR.B4 = 0;
MPC::PA4PFS.PSEL = sel;
PORTA::PMR.B4 = ena;
break;
default:
ret = false;
break;
}
break;
case CHANNEL::B:
// TIOCB1:
switch(odr) {
// P16
// PA5
case ORDER::FIRST:
PORT1::PMR.B6 = 0;
MPC::P16PFS.PSEL = sel;
PORT1::PMR.B6 = ena;
break;
case ORDER::SECOND:
PORTA::PMR.B5 = 0;
MPC::PA5PFS.PSEL = sel;
PORTA::PMR.B5 = ena;
break;
default:
ret = false;
break;
}
break;
default:
ret = false;
break;
}
return ret;
}
static bool tpu2_(CHANNEL ch, bool ena, ORDER odr) noexcept
{
bool ret = true;
uint8_t sel = ena ? 0b00'0011 : 0;
switch(ch) {
case CHANNEL::A:
// TIOCA2:
switch(odr) {
// P87
// PA6
case ORDER::FIRST:
PORT8::PMR.B7 = 0;
MPC::P87PFS.PSEL = sel;
PORT8::PMR.B7 = ena;
break;
case ORDER::SECOND:
PORTA::PMR.B6 = 0;
MPC::PA6PFS.PSEL = sel;
PORTA::PMR.B6 = ena;
break;
default:
ret = false;
break;
}
break;
case CHANNEL::B:
// TIOCB2:
switch(odr) {
// P15
// PA7
case ORDER::FIRST:
PORT1::PMR.B5 = 0;
MPC::P15PFS.PSEL = sel;
PORT1::PMR.B5 = ena;
break;
case ORDER::SECOND:
PORTA::PMR.B7 = 0;
MPC::PA7PFS.PSEL = sel;
PORTA::PMR.B7 = ena;
break;
default:
ret = false;
break;
}
break;
default:
ret = false;
break;
}
return ret;
}
static bool tpu3_(CHANNEL ch, bool ena, ORDER odr) noexcept
{
bool ret = true;
uint8_t sel = ena ? 0b00'0011 : 0;
switch(ch) {
case CHANNEL::A:
// TIOCA3:
switch(odr) {
// P21
// PB0
case ORDER::FIRST:
PORT2::PMR.B1 = 0;
MPC::P21PFS.PSEL = sel;
PORT2::PMR.B1 = ena;
break;
case ORDER::SECOND:
PORTB::PMR.B0 = 0;
MPC::PB0PFS.PSEL = sel;
PORTB::PMR.B0 = ena;
break;
default:
ret = false;
break;
}
break;
case CHANNEL::B:
// TIOCB3:
switch(odr) {
// P20
// PB1
case ORDER::FIRST:
PORT2::PMR.B0 = 0;
MPC::P20PFS.PSEL = sel;
PORT2::PMR.B0 = ena;
break;
case ORDER::SECOND:
PORTB::PMR.B1 = 0;
MPC::PB1PFS.PSEL = sel;
PORTB::PMR.B1 = ena;
break;
default:
ret = false;
break;
}
break;
case CHANNEL::C:
// TIOCC3:
switch(odr) {
// P22
// PB2
case ORDER::FIRST:
PORT2::PMR.B2 = 0;
MPC::P22PFS.PSEL = sel;
PORT2::PMR.B2 = ena;
break;
case ORDER::SECOND:
PORTB::PMR.B2 = 0;
MPC::PB2PFS.PSEL = sel;
PORTB::PMR.B2 = ena;
break;
default:
ret = false;
break;
}
break;
case CHANNEL::D:
// TIOCD3:
switch(odr) {
// P23
// PB3
case ORDER::FIRST:
PORT2::PMR.B3 = 0;
MPC::P23PFS.PSEL = sel;
PORT2::PMR.B3 = ena;
break;
case ORDER::SECOND:
PORTB::PMR.B3 = 0;
MPC::PB3PFS.PSEL = sel;
PORTB::PMR.B3 = ena;
break;
default:
ret = false;
break;
}
break;
default:
ret = false;
break;
}
return ret;
}
static bool tpu4_(CHANNEL ch, bool ena, ORDER odr) noexcept
{
bool ret = true;
uint8_t sel = ena ? 0b00'0011 : 0;
switch(ch) {
case CHANNEL::A:
// TIOCA4:
switch(odr) {
// P25
// PB4
case ORDER::FIRST:
PORT2::PMR.B5 = 0;
MPC::P25PFS.PSEL = sel;
PORT2::PMR.B5 = ena;
break;
case ORDER::SECOND:
PORTB::PMR.B4 = 0;
MPC::PB4PFS.PSEL = sel;
PORTB::PMR.B4 = ena;
break;
default:
ret = false;
break;
}
break;
case CHANNEL::B:
// TIOCB4:
switch(odr) {
// P24
// PB5
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 tpu5_(CHANNEL ch, bool ena, ORDER odr) noexcept
{
bool ret = true;
uint8_t sel = ena ? 0b00'0011 : 0;
switch(ch) {
case CHANNEL::A:
// TIOCA5:
switch(odr) {
// P13
// PB6
case ORDER::FIRST:
PORT1::PMR.B3 = 0;
MPC::P13PFS.PSEL = sel;
PORT1::PMR.B3 = ena;
break;
case ORDER::SECOND:
PORTB::PMR.B6 = 0;
MPC::PB6PFS.PSEL = sel;
PORTB::PMR.B6 = ena;
break;
default:
ret = false;
break;
}
break;
case CHANNEL::B:
// TIOCB5:
switch(odr) {
// P14
// PB7
case ORDER::FIRST:
PORT1::PMR.B4 = 0;
MPC::P14PFS.PSEL = sel;
PORT1::PMR.B4 = ena;
break;
case ORDER::SECOND:
PORTB::PMR.B7 = 0;
MPC::PB7PFS.PSEL = sel;
PORTB::PMR.B7 = ena;
break;
default:
ret = false;
break;
}
break;
default:
ret = false;
break;
}
return ret;
}
public:
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++//
/*!
@brief タイマー系、チャネル別ポート切り替え
@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::TPU0:
ret = tpu0_(ch, ena, odr);
break;
case peripheral::TPU1:
ret = tpu1_(ch, ena, odr);
break;
case peripheral::TPU2:
ret = tpu2_(ch, ena, odr);
break;
case peripheral::TPU3:
ret = tpu3_(ch, ena, odr);
break;
case peripheral::TPU4:
ret = tpu4_(ch, ena, odr);
break;
case peripheral::TPU5:
ret = tpu5_(ch, ena, odr);
break;
default:
ret = false;
break;
}
MPC::PWPR = MPC::PWPR.B0WI.b();
return ret;
}
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++//
/*!
@brief TPU クロック入力切り替え
@param[in] clk クロック型
@param[in] ena 無効にする場合場合「false」
@param[in] odr 候補を選択する場合
@return 無効な周辺機器の場合「false」
*/
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++//
static bool turn_clock(CHANNEL clk, bool ena = true, ORDER odr = ORDER::FIRST) noexcept
{
MPC::PWPR.B0WI = 0; // PWPR 書き込み許可
MPC::PWPR.PFSWE = 1; // PxxPFS 書き込み許可
bool ret = true;
switch(clk) {
case CHANNEL::CLK_A:
// TCLKA:
switch(odr) {
// P14
// PC2
case ORDER::FIRST:
PORT1::PMR.B4 = 0;
MPC::P14PFS.PSEL = ena ? 0b000100 : 0;
PORT1::PMR.B4 = ena;
break;
case ORDER::SECOND:
PORTC::PMR.B2 = 0;
MPC::PC2PFS.PSEL = ena ? 0b000011 : 0;
PORTC::PMR.B2 = ena;
break;
default:
ret = false;
break;
}
break;
case CHANNEL::CLK_B:
// TCLKB:
switch(odr) {
// P15
// PA3
// PC3
case ORDER::FIRST:
PORT1::PMR.B5 = 0;
MPC::P15PFS.PSEL = ena ? 0b000100 : 0;
PORT1::PMR.B5 = ena;
break;
case ORDER::SECOND:
PORTA::PMR.B3 = 0;
MPC::PA3PFS.PSEL = ena ? 0b000100 : 0;
PORTA::PMR.B3 = ena;
break;
case ORDER::THIRD:
PORTC::PMR.B3 = 0;
MPC::PC3PFS.PSEL = ena ? 0b000011 : 0;
PORTC::PMR.B3 = ena;
break;
default:
ret = false;
break;
}
break;
case CHANNEL::CLK_C:
// TCLKC:
switch(odr) {
// P16
// PB2
// PC0
case ORDER::FIRST:
PORT1::PMR.B6 = 0;
MPC::P16PFS.PSEL = ena ? 0b000100 : 0;
PORT1::PMR.B6 = ena;
break;
case ORDER::SECOND:
PORTB::PMR.B2 = 0;
MPC::PB2PFS.PSEL = ena ? 0b000100 : 0;
PORTB::PMR.B2 = ena;
break;
case ORDER::THIRD:
PORTC::PMR.B0 = 0;
MPC::PC0PFS.PSEL = ena ? 0b000011 : 0;
PORTC::PMR.B0 = ena;
break;
default:
ret = false;
break;
}
break;
case CHANNEL::CLK_D:
// TCLKD:
switch(odr) {
// P17
// PB3
// PC1
case ORDER::FIRST:
PORT1::PMR.B7 = 0;
MPC::P17PFS.PSEL = ena ? 0b000100 : 0;
PORT1::PMR.B7 = ena;
break;
case ORDER::SECOND:
PORTB::PMR.B3 = 0;
MPC::PB3PFS.PSEL = ena ? 0b000100 : 0;
PORTB::PMR.B3 = ena;
break;
case ORDER::THIRD:
PORTC::PMR.B1 = 0;
MPC::PC1PFS.PSEL = ena ? 0b000011 : 0;
PORTC::PMR.B1 = ena;
break;
default:
ret = false;
break;
}
break;
default:
ret = false;
break;
}
MPC::PWPR = MPC::PWPR.B0WI.b();
return ret;
}
};
}