-
-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathicu.hpp
474 lines (429 loc) · 12.2 KB
/
icu.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
#pragma once
//=========================================================================//
/*! @file
@brief Interrupt Controller / 割り込みコントローラ (RX24T)
@author 平松邦仁 ([email protected])
@copyright Copyright (C) 2016, 2024 Kunihito Hiramatsu @n
Released under the MIT license @n
https://github.com/hirakuni45/RX/blob/master/LICENSE
*/
//=========================================================================//
#include "common/io_utils.hpp"
#include "RX600/icu_base.hpp"
namespace device {
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++//
/*!
@brief ICU class (ICUb)
*/
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++//
struct icu_t : public ICU_BASE, ICU_IRQ8 {
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++//
/*!
@brief 通常割り込みベクター型
*/
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++//
enum class VECTOR : uint8_t {
NONE = 0, ///< none
BUSERR = 16, ///< BSC
FRDYI = 23, ///< FCU
SWINT = 27, ///< ICU
CMI0 = 28, ///< CMT0
CMI1 = 29, ///< CMT1
CMI2 = 30, ///< CMT2
CMI3 = 31, ///< CMT3
FERRF = 32, ///< CAC
MENDF = 33, ///< CAC
OVFF = 34, ///< CAC
ETGIN = 40, ///< GPT
ETGIP = 41, ///< GPT
SPEI0 = 44, ///< RSPI0
SPRI0 = 45, ///< RSPI0
SPTI0 = 46, ///< RSPI0
SPII0 = 47, ///< RSPI0
GTCIA0 = 48, ///< GPT0
GTCIB0 = 49,
GTCIC0 = 50,
GTCID0 = 51,
GDTE0 = 52,
GTCIE0 = 53,
GTCIF0 = 54,
GTCIV0 = 55,
GTCIU0 = 56,
DOPCF = 57, ///< DOC
COMFRXINT = 59, ///< RSCAN
RXFINT = 60,
TXINT = 61,
CHERRINT = 62,
GLERRINT = 63,
IRQ0 = 64, ///< ICU
IRQ1 = 65,
IRQ2 = 66,
IRQ3 = 67,
IRQ4 = 68,
IRQ5 = 69,
IRQ6 = 70,
IRQ7 = 71,
LVD1 = 88, ///< LVD
LVD2 = 89, ///< LVD
GTCIA1 = 98, ///< GPT1
GTCIB1 = 99,
GTCIC1 = 100,
GTCID1 = 101,
S12ADI = 102, ///< S12AD
GBADI = 103,
GCADI = 104,
S12ADI1 = 105, ///< S12ADI1
GBADI1 = 106,
GCADI1 = 107,
CMPC0 = 108, ///< CMPC0
CMPC1 = 109, ///< CMPC1
CMPC2 = 110, ///< CMPC2
S12ADI2 = 111, ///< S12AD2
GBADI2 = 112,
GCADI2 = 113,
TGIA0 = 114, ///< MTU0
TGIB0 = 115, ///< MTU0
TGIC0 = 116, ///< MTU0
TGID0 = 117, ///< MTU0
TCIV0 = 118, ///< MTU0
TGIE0 = 119, ///< MTU0
TGIF0 = 120, ///< MTU0
TGIA1 = 121, ///< MTU1
TGIB1 = 122, ///< MTU1
TCIV1 = 123, ///< MTU1
TCIU1 = 124, ///< MTU1
TGIA2 = 125, ///< MTU2
TGIB2 = 126, ///< MTU2
TCIV2 = 127, ///< MTU2
TCIU2 = 128, ///< MTU2
TGIA3 = 129, ///< MTU3
TGIB3 = 130, ///< MTU3
TGIC3 = 131, ///< MTU3
TGID3 = 132, ///< MTU3
TCIV3 = 133, ///< MTU3
TGIA4 = 134, ///< MTU4
TGIB4 = 135, ///< MTU4
TGIC4 = 136, ///< MTU4
TGID4 = 137, ///< MTU4
TCIV4 = 138, ///< MTU4
TGIU5 = 139, ///< MTU5
TGIV5 = 140, ///< MTU5
TGIW5 = 141, ///< MTU5
TGIA6 = 142, ///< MTU6
TGIB6 = 143, ///< MTU6
TGIC6 = 144, ///< MTU6
TGID6 = 145, ///< MTU6
TCIV6 = 146, ///< MTU6
TGIA7 = 149, ///< MTU7
TGIB7 = 150, ///< MTU7
TGIC7 = 151, ///< MTU7
TGID7 = 152, ///< MTU7
TCIV7 = 153, ///< MTU7
TGIA9 = 159, ///< MTU9
TGIB9 = 160, ///< MTU9
TGIC9 = 161, ///< MTU9
TGID9 = 162, ///< MTU9
TCIV9 = 163, ///< MTU9
TGIE9 = 164, ///< MTU9
TGIF9 = 165, ///< MTU9
OEI1 = 168, ///< POE
OEI2 = 169, ///< POE
OEI3 = 170, ///< POE
OEI4 = 171, ///< POE
OEI5 = 172, ///< POE
CMPC3 = 173, ///< CMPC3
CMIA0 = 174, ///< TMR0: CMIA0
CMIB0 = 175, ///< TMR0: CMIB0
OVI0 = 176, ///< TMR0: OVI0
CMIA1 = 177, ///< TMR1: CMIA1
CMIB1 = 178, ///< TMR1: CMIB1
OVI1 = 179, ///< TMR1: OVI1
CMIA2 = 180, ///< TMR2: CMIA2
CMIB2 = 181, ///< TMR2: CMIB2
OVI2 = 182, ///< TMR2: OVI2
CMIA3 = 183, ///< TMR3: CMIA3
CMIB3 = 184, ///< TMR3: CMIB3
OVI3 = 185, ///< TMR3: OVI3
CMIA4 = 186, ///< TMR4: CMIA4
CMIB4 = 187, ///< TMR4: CMIB4
OVI4 = 188, ///< TMR4: OVI4
CMIA5 = 189, ///< TMR5: CMIA5
CMIB5 = 190, ///< TMR5: CMIB5
OVI5 = 191, ///< TMR5: OVI5
CMIA6 = 192, ///< TMR6: CMIA6
CMIB6 = 193, ///< TMR6: CMIB6
OVI6 = 194, ///< TMR6: OVI6
CMIA7 = 195, ///< TMR7: CMIA7
CMIB7 = 196, ///< TMR7: CMIB7
OVI7 = 197, ///< TMR7: OVI7
GDTE1 = 202, ///< GPT1
GTCIE1 = 203,
GTCIF1 = 204,
GTCIV1 = 205,
GTCIU1 = 206,
GTCIA2 = 207, ///< GPT2
GTCIB2 = 208,
GTCIC2 = 209,
GTCID2 = 210,
GDTE2 = 211,
GTCIE2 = 212,
GTCIF2 = 213,
GTCIV2 = 214,
GTCIU2 = 215,
GTCIA3 = 216, ///< GPT3
GTCIB3 = 217,
ERI1 = 218, ///< SCI1
RXI1 = 219, ///< SCI1
TXI1 = 220, ///< SCI1
TEI1 = 221, ///< SCI1
ERI5 = 222, ///< SCI5
RXI5 = 223, ///< SCI5
TXI5 = 224, ///< SCI5
TEI5 = 225, ///< SCI5
ERI6 = 226, ///< SCI6
RXI6 = 227, ///< SCI6
TXI6 = 228, ///< SCI6
TEI6 = 229, ///< SCI6
GTCIC3 = 238, ///< GPT3
GTCID3 = 239,
GDTE3 = 240,
GTCIE3 = 241,
GTCIF3 = 242,
GTCIV3 = 243,
GTCIU3 = 244,
ICEEI0 = 246, ///< RIIC0
ICRXI0 = 247, ///< RIIC0
ICTXI0 = 248, ///< RIIC0
ICTEI0 = 249, ///< RIIC0
};
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++//
/*!
@brief IR レジスタ・クラス
@param[in] base ベースアドレス
*/
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++//
template <uint32_t base>
struct ir_t {
//-----------------------------------------------------------------//
/*!
@brief []オペレータ
@param[in] vec 割り込みベクター型
@return IR レジスターの参照
*/
//-----------------------------------------------------------------//
volatile uint8_t& operator [] (VECTOR vec) noexcept {
return *reinterpret_cast<volatile uint8_t*>(base + static_cast<uint8_t>(vec));
}
};
static inline ir_t<0x0008'7000> IR;
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++//
/*!
@brief IER レジスタ・クラス
@param[in] base ベースアドレス
*/
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++//
template <uint32_t base>
struct ier_t {
//-----------------------------------------------------------------//
/*!
@brief 許可、不許可
@param[in] vec 割り込みベクター型
@param[in] ena 不許可の場合「false」
*/
//-----------------------------------------------------------------//
void enable(VECTOR vec, bool ena = true) noexcept
{
auto idx = static_cast<uint8_t>(vec);
auto tmp = rd8_(base + (idx >> 3));
if(ena) {
tmp |= 1 << (idx & 7);
} else {
tmp &= ~(1 << (idx & 7));
}
wr8_(base + (idx >> 3), tmp);
}
//-----------------------------------------------------------------//
/*!
@brief 許可状態を取得
@param[in] vec 割り込みベクター型
@return 許可状態(許可の場合「true」)
*/
//-----------------------------------------------------------------//
bool get(VECTOR vec) const noexcept
{
auto idx = static_cast<uint8_t>(vec);
auto tmp = rd8_(base + (idx >> 3));
return tmp & (1 << (idx & 7));
}
};
static inline ier_t<0x0008'7200> IER;
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++//
/*!
@brief IPR レジスタ・クラス @n
全て、下位4ビットが有効
@param[in] base ベースアドレス
*/
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++//
template <uint32_t base>
struct ipr_t {
//-----------------------------------------------------------------//
/*!
@brief []オペレータ
@param[in] vec 標準割り込みベクター型
@return IPR レジスターの参照
*/
//-----------------------------------------------------------------//
volatile uint8_t& operator [] (VECTOR vec) {
uint32_t idx = 0;
switch(vec) {
case VECTOR::BUSERR: idx = 0; break;
case VECTOR::FRDYI: idx = 2; break;
case VECTOR::SWINT: idx = 3; break;
case VECTOR::CMI0: idx = 4; break;
case VECTOR::CMI1: idx = 5; break;
case VECTOR::CMI2: idx = 6; break;
case VECTOR::CMI3: idx = 7; break;
case VECTOR::SPEI0:
case VECTOR::SPRI0:
case VECTOR::SPTI0:
case VECTOR::SPII0:
idx = static_cast<uint32_t>(VECTOR::SPEI0);
break;
case VECTOR::TGIA0:
case VECTOR::TGIB0:
case VECTOR::TGIC0:
case VECTOR::TGID0:
idx = static_cast<uint32_t>(VECTOR::TGIA0);
break;
case VECTOR::TCIV0:
case VECTOR::TGIE0:
case VECTOR::TGIF0:
idx = static_cast<uint32_t>(VECTOR::TCIV0);
break;
case VECTOR::TGIA1:
case VECTOR::TGIB1:
idx = static_cast<uint32_t>(VECTOR::TGIA1);
break;
case VECTOR::TCIV1:
case VECTOR::TCIU1:
idx = static_cast<uint32_t>(VECTOR::TCIV1);
break;
case VECTOR::TGIA2:
case VECTOR::TGIB2:
idx = static_cast<uint32_t>(VECTOR::TGIA2);
break;
case VECTOR::TCIV2:
case VECTOR::TCIU2:
idx = static_cast<uint32_t>(VECTOR::TCIV2);
break;
case VECTOR::TGIA3:
case VECTOR::TGIB3:
case VECTOR::TGIC3:
case VECTOR::TGID3:
idx = static_cast<uint32_t>(VECTOR::TGIA3);
break;
case VECTOR::TGIA4:
case VECTOR::TGIB4:
case VECTOR::TGIC4:
case VECTOR::TGID4:
idx = static_cast<uint32_t>(VECTOR::TGIA4);
break;
case VECTOR::TGIU5:
case VECTOR::TGIV5:
case VECTOR::TGIW5:
idx = static_cast<uint32_t>(VECTOR::TGIU5);
break;
case VECTOR::TGIA6:
case VECTOR::TGIB6:
case VECTOR::TGIC6:
case VECTOR::TGID6:
idx = static_cast<uint32_t>(VECTOR::TGIA6);
break;
case VECTOR::TGIA7:
case VECTOR::TGIB7:
idx = static_cast<uint32_t>(VECTOR::TGIA7);
break;
case VECTOR::TGIC7:
case VECTOR::TGID7:
idx = static_cast<uint32_t>(VECTOR::TGIC7);
break;
case VECTOR::TGIA9:
case VECTOR::TGIB9:
case VECTOR::TGIC9:
case VECTOR::TGID9:
idx = static_cast<uint32_t>(VECTOR::TGIA9);
break;
case VECTOR::TCIV9:
case VECTOR::TGIE9:
case VECTOR::TGIF9:
idx = static_cast<uint32_t>(VECTOR::TCIV9);
break;
case VECTOR::CMIA0:
case VECTOR::CMIB0:
case VECTOR::OVI0:
idx = static_cast<uint32_t>(VECTOR::CMIA0);
break;
case VECTOR::CMIA1:
case VECTOR::CMIB1:
case VECTOR::OVI1:
idx = static_cast<uint32_t>(VECTOR::CMIA1);
break;
case VECTOR::CMIA2:
case VECTOR::CMIB2:
case VECTOR::OVI2:
idx = static_cast<uint32_t>(VECTOR::CMIA2);
break;
case VECTOR::CMIA3:
case VECTOR::CMIB3:
case VECTOR::OVI3:
idx = static_cast<uint32_t>(VECTOR::CMIA3);
break;
case VECTOR::CMIA4:
case VECTOR::CMIB4:
case VECTOR::OVI4:
idx = static_cast<uint32_t>(VECTOR::CMIA4);
break;
case VECTOR::CMIA5:
case VECTOR::CMIB5:
case VECTOR::OVI5:
idx = static_cast<uint32_t>(VECTOR::CMIA5);
break;
case VECTOR::CMIA6:
case VECTOR::CMIB6:
case VECTOR::OVI6:
idx = static_cast<uint32_t>(VECTOR::CMIA6);
break;
case VECTOR::CMIA7:
case VECTOR::CMIB7:
case VECTOR::OVI7:
idx = static_cast<uint32_t>(VECTOR::CMIA7);
break;
case VECTOR::ERI1:
case VECTOR::RXI1:
case VECTOR::TXI1:
case VECTOR::TEI1:
idx = static_cast<uint32_t>(VECTOR::ERI1);
break;
case VECTOR::ERI5:
case VECTOR::RXI5:
case VECTOR::TXI5:
case VECTOR::TEI5:
idx = static_cast<uint32_t>(VECTOR::ERI5);
break;
case VECTOR::ERI6:
case VECTOR::RXI6:
case VECTOR::TXI6:
case VECTOR::TEI6:
idx = static_cast<uint32_t>(VECTOR::ERI6);
break;
default: idx = static_cast<uint32_t>(vec); break;
}
return *reinterpret_cast<volatile uint8_t*>(base + idx);
}
};
static inline ipr_t<0x0008'7300> IPR;
/// @brief DTC 転送要求許可レジスタ (DTCER)
static inline dtcer_t<0x0008'7100, VECTOR> DTCER;
};
typedef icu_t ICU;
}