OpenMPTL - ARM Cortex (common)
C++ Microprocessor Template Library
scb.hpp
Go to the documentation of this file.
1 /*
2  * OpenMPTL - C++ Microprocessor Template Library
3  *
4  * Copyright (C) 2012-2017 Axel Burri <axel@tty0.ch>
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program. If not, see <http://www.gnu.org/licenses/>.
18  *
19  */
20 
21 #ifndef ARM_CORTEX_COMMON_REG_SCB_HPP_INCLUDED
22 #define ARM_CORTEX_COMMON_REG_SCB_HPP_INCLUDED
23 
24 #include <register.hpp>
25 
26 namespace mptl {
27 
28 /**
29  * System Control Register
30  *
31  * For details, see "Cortex-M3 Technical Reference Manual":
32  * <http://infocenter.arm.com/help/topic/com.arm.doc.subset.cortexm.m3/index.html>
33  */
34 struct SCB
35 {
36  /** Auxiliary Control Register, ACTLR */
38 
39  /**
40  * SysTick Control and Status Register
41  */
42  struct STCSR
43  : public reg< uint32_t, 0xE000E010, rw >
44  {
45  using ENABLE = regbits< type, 0, 1 >; /**< [ 0: 0] Counter enable */
46  using TICKINT = regbits< type, 1, 1 >; /**< [ 1: 1] Counting down to 0 pends the SysTick handler */
47  using CLKSOURCE = regbits< type, 2, 1 >; /**< [ 2: 2] Clock source */
48  using COUNTFLAG = regbits< type, 16, 1 >; /**< [16:16] Count Flag */
49  };
50 
51  /**
52  * SysTick Reload Value Register
53  */
54  struct STRVR
55  : public reg< uint32_t, 0xE000E014, rw >
56  {
58  };
59 
60  /**
61  * SysTick Current Value Register
62  */
63  struct STCVR
64  : public reg< uint32_t, 0xE000E018, rw >
65  {
67  };
68 
69  /**
70  * SysTick Calilbration Value Register
71  */
72  struct STCR
73  : public reg< uint32_t, 0xE000E01C, ro >
74  {
75  using SKEW = regbits< type, 30, 1 >; /**< [30:30] Calibration value is not exactly 10 ms */
76  using NOREF = regbits< type, 31, 1 >; /**< [31:31] The reference clock is not provided */
77  };
78 
79  /**
80  * CPUID Base Register, CPUID
81  */
82  struct CPUID
83  : public reg< uint32_t, 0xE000ED00, ro >
84  {
85  using REVISION = regbits< type, 0, 4 >; /**< [ 3: 0] Implementation defined revision number */
86  using PARTNO = regbits< type, 4, 12 >; /**< [15: 4] Number of processor within family */
87  using Constant = regbits< type, 16, 4 >; /**< [19:16] Reads as 0x0F */
88  using VARIANT = regbits< type, 20, 4 >; /**< [23:20] Implementation defined variant number */
89  using IMPLEMENTER = regbits< type, 24, 8 >; /**< [31:24] Implementer code. ARM is 0x41 */
90  };
91 
92  /**
93  * Interrupt Control and State Register
94  */
95  struct ICSR
96  : public reg< uint32_t, 0xE000ED04, rw >
97  {
98  using VECTACTIVE = regbits< type, 0, 9 >; /**< [ 8: 0] Active ISR number field */
99  using RETTOBASE = regbits< type, 11, 1 >; /**< [11:11] All active exceptions minus the IPSR_current_exception yields the empty set */
100  using VECTPENDING = regbits< type, 12, 10 >; /**< [21:12] Pending ISR number field */
101  using ISRPENDING = regbits< type, 22, 1 >; /**< [22:22] Interrupt pending flag */
102  using ISRPREEMPT = regbits< type, 23, 1 >; /**< [23:23] It indicates that a pending interrupt becomes active in the next running cycle */
103  using PENDSTCLR = regbits< type, 25, 1 >; /**< [25:25] Clear pending SysTick bit */
104  using PENDSTSET = regbits< type, 26, 1 >; /**< [26:26] Set pending SysTick bit */
105  using PENDSVCLR = regbits< type, 27, 1 >; /**< [27:27] Clear pending pendSV bit */
106  using PENDSVSET = regbits< type, 28, 1 >; /**< [28:28] Set pending pendSV bit */
107  using NMIPENDSET = regbits< type, 31, 1 >; /**< [31:31] Set pending NMI bit */
108  };
109 
110  /**
111  * Vector Table Offset Register
112  */
113  struct VTOR
114  : public reg< uint32_t, 0xE000ED08, rw >
115  {
116  using TBLOFF = regbits< type, 7, 22 >; /**< [28: 7] Vector table base offset field */
117  using TBLBASE = regbits< type, 29, 1 >; /**< [29:29] Table base in code(0) or RAM(1) */
118  };
119 
120  /**
121  * Application Interrupt and Reset Control Register
122  */
123  struct AIRCR
124  : public reg< uint32_t, 0xE000ED0C, rw >
125  {
126  using VECTRESET = regbits< type, 0, 1 >; /**< [ 0: 0] System Reset bit */
127  using VECTCLRACTIVE = regbits< type, 1, 1 >; /**< [ 1: 1] Clear active vector bit */
128  using SYSRESETREQ = regbits< type, 2, 1 >; /**< [ 2: 2] Requests chip control logic to generate a reset */
129  using PRIGROUP = regbits< type, 8, 3 >; /**< [10: 8] Priority group */
130  using ENDIANESS = regbits< type, 15, 1 >; /**< [15:15] Data endianness bit */
131  using VECTKEY = regbits< type, 16, 16 >; /**< [31:16] Register key (VECTKEY) - Reads as 0xFA05 (VECTKEYSTAT) */
132  };
133 
134  /**
135  * System Control Register
136  */
137  struct SCR
138  : public reg< uint32_t, 0xE000ED10, rw >
139  {
140  using SLEEPONEXIT = regbits< type, 1, 1 >; /**< [ 1: 1] Sleep on exit bit */
141  using SLEEPDEEP = regbits< type, 2, 1 >; /**< [ 2: 2] Sleep deep bit */
142  using SEVONPEND = regbits< type, 4, 1 >; /**< [ 4: 4] Wake up from WFE */
143  };
144 
145  /**
146  * Configuration and Control Register
147  */
148  struct CCR
149  : public reg< uint32_t, 0xE000ED14, rw, 0x00000200 >
150  {
151  using NONBASETHRDENA = regbits< type, 0, 1 >; /**< [ 0: 0] Thread mode can be entered from any level in Handler mode by controlled return value */
152  using USERSETMPEND = regbits< type, 1, 1 >; /**< [ 1: 1] Enables user code to write the Software Trigger Interrupt register to trigger (pend) a Main exception */
153  using UNALIGN_TRP = regbits< type, 3, 1 >; /**< [ 3: 3] Trap for unaligned access */
154  using DIV_0_TRP = regbits< type, 4, 1 >; /**< [ 4: 4] Trap on Divide by 0 */
155  using BFHFNMIGN = regbits< type, 8, 1 >; /**< [ 8: 8] Handlers running at priority -1 and -2 */
156  using STKALIGN = regbits< type, 9, 1 >; /**< [ 9: 9] On exception entry, the SP used prior to the exception is adjusted to be 8-byte aligned */
157  };
158 
159  /**
160  * System Handler Priority Register
161  */
162  template<unsigned reg_index>
163  struct SHPR
164  : public reg< uint32_t, 0xE000ED18 + 4 * reg_index, rw >
165  {
166  static_assert(reg_index < 3, "invalid index for register");
167 
169 
170  // TODO: template PRIx
171  using PRI_N = regbits< type, 0, 8 >; /**< [ 7: 0] Priority of system handler 4,8, and 12. Mem Manage, reserved and Debug Monitor */
172  using PRI_N1 = regbits< type, 8, 8 >; /**< [15: 8] Priority of system handler 5,9, and 13. Bus Fault, reserved and reserved */
173  using PRI_N2 = regbits< type, 16, 8 >; /**< [23:16] Priority of system handler 6,10, and 14. Usage Fault, reserved and PendSV */
174  using PRI_N3 = regbits< type, 24, 8 >; /**< [31:24] Priority of system handler 7,11, and 15. Reserved, SVCall and SysTick */
175  };
176 
177  /**
178  * System Handler Control and State Register
179  */
180  struct SHCSR
181  : public reg< uint32_t, 0xE000ED24, rw >
182  {
183  using MEMFAULTACT = regbits< type, 0, 1 >; /**< [ 0: 0] MemManage is active */
184  using BUSFAULTACT = regbits< type, 1, 1 >; /**< [ 1: 1] BusFault is active */
185  using USGFAULTACT = regbits< type, 3, 1 >; /**< [ 3: 3] UsageFault is active */
186  using SVCALLACT = regbits< type, 7, 1 >; /**< [ 7: 7] SVCall is active */
187  using MONITORACT = regbits< type, 8, 1 >; /**< [ 8: 8] Monitor is active */
188  using PENDSVACT = regbits< type, 10, 1 >; /**< [10:10] PendSV is active */
189  using SYSTICKACT = regbits< type, 11, 1 >; /**< [11:11] SysTick is active */
190  using USGFAULTPENDED = regbits< type, 12, 1 >; /**< [12:12] Usage Fault is pended */
191  using MEMFAULTPENDED = regbits< type, 13, 1 >; /**< [13:13] MemManage is pended */
192  using BUSFAULTPENDED = regbits< type, 14, 1 >; /**< [14:14] Bus Fault is pended */
193  using SVCALLPENDED = regbits< type, 15, 1 >; /**< [15:15] SVCall is pended */
194  using MEMFAULTENA = regbits< type, 16, 1 >; /**< [16:16] MemManage enable */
195  using BUSFAULTENA = regbits< type, 17, 1 >; /**< [17:17] Bus Fault enable */
196  using USGFAULTENA = regbits< type, 18, 1 >; /**< [18:18] UsageFault enable */
197  };
198 
199  /**
200  * Configurable Fault Status Registers
201  */
202  struct CFSR
203  : public reg< uint32_t, 0xE000ED28, rw >
204  {
205  /* MFSR */
206  // TODO: byte-accessible registers
207  // regbits< type, 0, 8 > MFSR;
208  // regbits< type, 8, 16 > BFSR;
209  // regbits< type, 16, 16 > UFSR;
210  using IACCVIOL = regbits< type, 0, 1 >; /**< [ 0: 0] Instruction access violation */
211  using DACCVIOL = regbits< type, 1, 1 >; /**< [ 1: 1] Data access violation */
212  using MUNSTKERR = regbits< type, 3, 1 >; /**< [ 3: 3] Unstacking error */
213  using MSTKERR = regbits< type, 4, 1 >; /**< [ 4: 4] Stacking error */
214  /* BFSR */
215  using IBUSERR = regbits< type, 8, 1 >; /**< [ 8: 8] Instruction bus error flag */
216  using PRECISERR = regbits< type, 9, 1 >; /**< [ 9: 9] Precise data bus error */
217  using IMPRECISERR = regbits< type, 10, 1 >; /**< [10:10] Imprecise data bus error */
218  using UNSTKERR = regbits< type, 11, 1 >; /**< [11:11] Unstacking error */
219  using STKERR = regbits< type, 12, 1 >; /**< [12:12] Stacking error */
220  using BFARVALID = regbits< type, 15, 1 >; /**< [15:15] Bus Fault Address Register address valid flag */
221  /* UFSR */
222  using UNDEFINSTR = regbits< type, 16, 1 >; /**< [16:16] The processor attempt to excecute an undefined instruction */
223  using INVSTATE = regbits< type, 17, 1 >; /**< [17:17] Invalid combination of EPSR and instruction */
224  using INVPC = regbits< type, 18, 1 >; /**< [18:18] Attempt to load EXC_RETURN into pc illegally */
225  using NOCP = regbits< type, 19, 1 >; /**< [19:19] Attempt to use a coprocessor instruction */
226  using UNALIGNED = regbits< type, 24, 1 >; /**< [24:24] Fault occurs when there is an attempt to make an unaligned memory access */
227  using DIVBYZERO = regbits< type, 25, 1 >; /**< [25:25] Fault occurs when SDIV or DIV instruction is used with a divisor of 0 */
228  };
229 
230  /**
231  * HardFault Status Register
232  */
233  struct HFSR
234  : public reg< uint32_t, 0xE000ED2C, rw >
235  {
236  using VECTTBL = regbits< type, 1, 1 >; /**< [ 1: 1] Fault occures because of vector table read on exception processing */
237  using FORCED = regbits< type, 30, 1 >; /**< [30:30] Hard Fault activated when a configurable Fault was received and cannot activate */
238  using DEBUGEVT = regbits< type, 31, 1 >; /**< [31:31] Fault related to debug */
239  };
240 
241  /**
242  * Debug Fault Status Register
243  */
244  struct DFSR
245  : public reg< uint32_t, 0xE000ED30, rw >
246  {
247  using HALTED = regbits< type, 0, 1 >; /**< [ 0: 0] Halt request flag */
248  using BKPT = regbits< type, 1, 1 >; /**< [ 1: 1] BKPT flag */
249  using DWTTRAP = regbits< type, 2, 1 >; /**< [ 2: 2] Data Watchpoint and Trace (DWT) flag */
250  using VCATCH = regbits< type, 3, 1 >; /**< [ 3: 3] Vector catch flag */
251  using EXTERNAL = regbits< type, 4, 1 >; /**< [ 4: 4] External debug request flag */
252  };
253 
254 
255  using MMFAR = reg< uint32_t, 0xE000ED34, rw >; /**< MemManage Fault Address Register[b] */
256  using BFAR = reg< uint32_t, 0xE000ED38, rw >; /**< BusFault Address Register[b] */
257  using AFSR = reg< uint32_t, 0xE000ED3C, rw >; /**< Auxiliary Fault Status Register, AFSR */
258  using ID_PFR0 = reg< uint32_t, 0xE000ED40, ro, 0x00000030 >; /**< Processor Feature Register 0 */
259  using ID_PFR1 = reg< uint32_t, 0xE000ED44, ro, 0x00000200 >; /**< Processor Feature Register 1 */
260  using ID_DFR0 = reg< uint32_t, 0xE000ED48, ro, 0x00100000 >; /**< Debug Features Register 0[c] */
261  using ID_AFR0 = reg< uint32_t, 0xE000ED4C, ro >; /**< Auxiliary Features Register 0 */
262  using ID_MMFR0 = reg< uint32_t, 0xE000ED50, ro, 0x00100030 >; /**< Memory Model Feature Register 0 */
263  using ID_MMFR1 = reg< uint32_t, 0xE000ED54, ro >; /**< Memory Model Feature Register 1 */
264  using ID_MMFR2 = reg< uint32_t, 0xE000ED58, ro, 0x01000000 >; /**< Memory Model Feature Register 2 */
265  using ID_MMFR3 = reg< uint32_t, 0xE000ED5C, ro >; /**< Memory Model Feature Register 3 */
266  using ID_ISAR0 = reg< uint32_t, 0xE000ED60, ro, 0x01100110 >; /**< Instruction Set Attributes Register 0 */
267  using ID_ISAR1 = reg< uint32_t, 0xE000ED64, ro, 0x02111000 >; /**< Instruction Set Attributes Register 1 */
268  using ID_ISAR2 = reg< uint32_t, 0xE000ED68, ro, 0x21112231 >; /**< Instruction Set Attributes Register 2 */
269  using ID_ISAR3 = reg< uint32_t, 0xE000ED6C, ro, 0x01111110 >; /**< Instruction Set Attributes Register 3 */
270  using ID_ISAR4 = reg< uint32_t, 0xE000ED70, ro, 0x01310132 >; /**< Instruction Set Attributes Register 4 */
271  using CPACR = reg< uint32_t, 0xE000ED88, rw >; /**< Coprocessor Access Control Register */
272  using STIR = reg< uint32_t, 0xE000EF00, wo >; /**< Software Triggered Interrupt Register */
273 };
274 
275 } // namespace mptl
276 
277 #endif // ARM_CORTEX_COMMON_REG_SCB_HPP_INCLUDED
Vector Table Offset Register.
Definition: scb.hpp:113
Application Interrupt and Reset Control Register.
Definition: scb.hpp:123
Configuration and Control Register.
Definition: scb.hpp:148
Debug Fault Status Register.
Definition: scb.hpp:244
System Handler Control and State Register.
Definition: scb.hpp:180
HardFault Status Register.
Definition: scb.hpp:233
System Handler Priority Register.
Definition: scb.hpp:163
Configurable Fault Status Registers.
Definition: scb.hpp:202
System Control Register.
Definition: scb.hpp:34
SysTick Reload Value Register.
Definition: scb.hpp:54
SysTick Calilbration Value Register.
Definition: scb.hpp:72
System Control Register.
Definition: scb.hpp:137
CPUID Base Register, CPUID.
Definition: scb.hpp:82
SysTick Control and Status Register.
Definition: scb.hpp:42
SysTick Current Value Register.
Definition: scb.hpp:63
Interrupt Control and State Register.
Definition: scb.hpp:95