blob: b84a8a9cbfe41c65f7c7bfffcf2a2f687503f187 (
plain)
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
|
#pragma once
#include "interrupt_enums.h"
#include <mmio/mmio.h>
struct NVIC_reg_t {
volatile uint32_t ISER[32];
volatile uint32_t ICER[32];
volatile uint32_t ISPR[32];
volatile uint32_t ICPR[32];
volatile uint32_t IABR[64];
volatile uint8_t IPR[2816];
volatile uint32_t STIR;
};
struct SCB_reg_t {
volatile uint32_t CPUID;
volatile uint32_t ICSR;
volatile uint32_t VTOR;
volatile uint32_t AIRCR;
volatile uint32_t SCR;
volatile uint32_t CCR;
volatile uint8_t SHPR[12];
volatile uint32_t SHCSR;
volatile uint32_t CFSR;
volatile uint32_t HFSR;
volatile uint32_t DFSR;
volatile uint32_t MMAR;
volatile uint32_t BFAR;
};
class NVIC_t : public mmio_ptr<NVIC_reg_t> {
public:
mmio_ptr<SCB_reg_t> SCB;
constexpr NVIC_t(uintptr_t offset) :
mmio_ptr(offset),
SCB(offset + 0xc00) {}
void enable(interrupt::irq n) const {
ptr()->ISER[int(n) >> 5] = 1 << (int(n) & 0x1f);
}
void set_priority(interrupt::exception n, uint8_t priority) const {
SCB->SHPR[int(n) - 4] = priority;
}
void set_priority(interrupt::irq n, uint8_t priority) const {
ptr()->IPR[int(n)] = priority;
}
};
|