1 /**************************************************************************//**
3 * @brief CMSIS Cortex-A Core Peripheral Access Layer Header File
6 ******************************************************************************/
8 * Copyright (c) 2009-2017 ARM Limited. All rights reserved.
10 * SPDX-License-Identifier: Apache-2.0
12 * Licensed under the Apache License, Version 2.0 (the License); you may
13 * not use this file except in compliance with the License.
14 * You may obtain a copy of the License at
16 * www.apache.org/licenses/LICENSE-2.0
18 * Unless required by applicable law or agreed to in writing, software
19 * distributed under the License is distributed on an AS IS BASIS, WITHOUT
20 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
21 * See the License for the specific language governing permissions and
22 * limitations under the License.
25 #if defined ( __ICCARM__ )
26 #pragma system_include /* treat file as system include file for MISRA check */
33 #ifndef __CORE_CA_H_GENERIC
34 #define __CORE_CA_H_GENERIC
37 /*******************************************************************************
39 ******************************************************************************/
41 /* CMSIS CA definitions */
42 #define __CA_CMSIS_VERSION_MAIN (1U) /*!< \brief [31:16] CMSIS HAL main version */
43 #define __CA_CMSIS_VERSION_SUB (0U) /*!< \brief [15:0] CMSIS HAL sub version */
44 #define __CA_CMSIS_VERSION ((__CA_CMSIS_VERSION_MAIN << 16U) | \
45 __CA_CMSIS_VERSION_SUB ) /*!< \brief CMSIS HAL version number */
47 #if defined ( __CC_ARM )
48 #if defined __TARGET_FPU_VFP
49 #if (__FPU_PRESENT == 1)
52 #warning "Compiler generates FPU instructions for a device without an FPU (check __FPU_PRESENT)"
59 #elif defined ( __ICCARM__ )
60 #if defined __ARMVFP__
61 #if (__FPU_PRESENT == 1)
64 #warning "Compiler generates FPU instructions for a device without an FPU (check __FPU_PRESENT)"
71 #elif defined ( __TMS470__ )
72 #if defined __TI_VFP_SUPPORT__
73 #if (__FPU_PRESENT == 1)
76 #warning "Compiler generates FPU instructions for a device without an FPU (check __FPU_PRESENT)"
83 #elif defined ( __GNUC__ )
84 #if defined (__VFP_FP__) && !defined(__SOFTFP__)
85 #if (__FPU_PRESENT == 1)
88 #warning "Compiler generates FPU instructions for a device without an FPU (check __FPU_PRESENT)"
95 #elif defined ( __TASKING__ )
96 #if defined __FPU_VFP__
97 #if (__FPU_PRESENT == 1)
100 #error "Compiler generates FPU instructions for a device without an FPU (check __FPU_PRESENT)"
101 #define __FPU_USED 0U
104 #define __FPU_USED 0U
108 #include "cmsis_compiler.h" /* CMSIS compiler specific defines */
114 #endif /* __CORE_CA_H_GENERIC */
116 #ifndef __CMSIS_GENERIC
118 #ifndef __CORE_CA_H_DEPENDANT
119 #define __CORE_CA_H_DEPENDANT
125 /* check device defines and use defaults */
126 #if defined __CHECK_DEVICE_DEFINES
128 #define __CA_REV 0x0000U
129 #warning "__CA_REV not defined in device header file; using default!"
132 #ifndef __FPU_PRESENT
133 #define __FPU_PRESENT 0U
134 #warning "__FPU_PRESENT not defined in device header file; using default!"
137 #ifndef __MPU_PRESENT
138 #define __MPU_PRESENT 0U
139 #warning "__MPU_PRESENT not defined in device header file; using default!"
142 #ifndef __GIC_PRESENT
143 #define __GIC_PRESENT 1U
144 #warning "__GIC_PRESENT not defined in device header file; using default!"
147 #ifndef __TIM_PRESENT
148 #define __TIM_PRESENT 1U
149 #warning "__TIM_PRESENT not defined in device header file; using default!"
152 #ifndef __L2C_PRESENT
153 #define __L2C_PRESENT 0U
154 #warning "__L2C_PRESENT not defined in device header file; using default!"
158 /* IO definitions (access restrictions to peripheral registers) */
160 #define __I volatile /*!< \brief Defines 'read only' permissions */
162 #define __I volatile const /*!< \brief Defines 'read only' permissions */
164 #define __O volatile /*!< \brief Defines 'write only' permissions */
165 #define __IO volatile /*!< \brief Defines 'read / write' permissions */
167 /* following defines should be used for structure members */
168 #define __IM volatile const /*!< \brief Defines 'read only' structure member permissions */
169 #define __OM volatile /*!< \brief Defines 'write only' structure member permissions */
170 #define __IOM volatile /*!< \brief Defines 'read / write' structure member permissions */
173 /*******************************************************************************
174 * Register Abstraction
175 Core Register contain:
178 - L2C-310 Cache Controller
179 - Generic Interrupt Controller Distributor
180 - Generic Interrupt Controller Interface
181 ******************************************************************************/
183 /* Core Register CPSR */
188 uint32_t M:5; /*!< \brief bit: 0.. 4 Mode field */
189 uint32_t T:1; /*!< \brief bit: 5 Thumb execution state bit */
190 uint32_t F:1; /*!< \brief bit: 6 FIQ mask bit */
191 uint32_t I:1; /*!< \brief bit: 7 IRQ mask bit */
192 uint32_t A:1; /*!< \brief bit: 8 Asynchronous abort mask bit */
193 uint32_t E:1; /*!< \brief bit: 9 Endianness execution state bit */
194 uint32_t IT1:6; /*!< \brief bit: 10..15 If-Then execution state bits 2-7 */
195 uint32_t GE:4; /*!< \brief bit: 16..19 Greater than or Equal flags */
196 uint32_t _reserved0:4; /*!< \brief bit: 20..23 Reserved */
197 uint32_t J:1; /*!< \brief bit: 24 Jazelle bit */
198 uint32_t IT0:2; /*!< \brief bit: 25..26 If-Then execution state bits 0-1 */
199 uint32_t Q:1; /*!< \brief bit: 27 Saturation condition flag */
200 uint32_t V:1; /*!< \brief bit: 28 Overflow condition code flag */
201 uint32_t C:1; /*!< \brief bit: 29 Carry condition code flag */
202 uint32_t Z:1; /*!< \brief bit: 30 Zero condition code flag */
203 uint32_t N:1; /*!< \brief bit: 31 Negative condition code flag */
204 } b; /*!< \brief Structure used for bit access */
205 uint32_t w; /*!< \brief Type used for word access */
208 /* CPSR Register Definitions */
209 #define CPSR_N_Pos 31U /*!< \brief CPSR: N Position */
210 #define CPSR_N_Msk (1UL << CPSR_N_Pos) /*!< \brief CPSR: N Mask */
212 #define CPSR_Z_Pos 30U /*!< \brief CPSR: Z Position */
213 #define CPSR_Z_Msk (1UL << CPSR_Z_Pos) /*!< \brief CPSR: Z Mask */
215 #define CPSR_C_Pos 29U /*!< \brief CPSR: C Position */
216 #define CPSR_C_Msk (1UL << CPSR_C_Pos) /*!< \brief CPSR: C Mask */
218 #define CPSR_V_Pos 28U /*!< \brief CPSR: V Position */
219 #define CPSR_V_Msk (1UL << CPSR_V_Pos) /*!< \brief CPSR: V Mask */
221 #define CPSR_Q_Pos 27U /*!< \brief CPSR: Q Position */
222 #define CPSR_Q_Msk (1UL << CPSR_Q_Pos) /*!< \brief CPSR: Q Mask */
224 #define CPSR_IT0_Pos 25U /*!< \brief CPSR: IT0 Position */
225 #define CPSR_IT0_Msk (3UL << CPSR_IT0_Pos) /*!< \brief CPSR: IT0 Mask */
227 #define CPSR_J_Pos 24U /*!< \brief CPSR: J Position */
228 #define CPSR_J_Msk (1UL << CPSR_J_Pos) /*!< \brief CPSR: J Mask */
230 #define CPSR_GE_Pos 16U /*!< \brief CPSR: GE Position */
231 #define CPSR_GE_Msk (0xFUL << CPSR_GE_Pos) /*!< \brief CPSR: GE Mask */
233 #define CPSR_IT1_Pos 10U /*!< \brief CPSR: IT1 Position */
234 #define CPSR_IT1_Msk (0x3FUL << CPSR_IT1_Pos) /*!< \brief CPSR: IT1 Mask */
236 #define CPSR_E_Pos 9U /*!< \brief CPSR: E Position */
237 #define CPSR_E_Msk (1UL << CPSR_E_Pos) /*!< \brief CPSR: E Mask */
239 #define CPSR_A_Pos 8U /*!< \brief CPSR: A Position */
240 #define CPSR_A_Msk (1UL << CPSR_A_Pos) /*!< \brief CPSR: A Mask */
242 #define CPSR_I_Pos 7U /*!< \brief CPSR: I Position */
243 #define CPSR_I_Msk (1UL << CPSR_I_Pos) /*!< \brief CPSR: I Mask */
245 #define CPSR_F_Pos 6U /*!< \brief CPSR: F Position */
246 #define CPSR_F_Msk (1UL << CPSR_F_Pos) /*!< \brief CPSR: F Mask */
248 #define CPSR_T_Pos 5U /*!< \brief CPSR: T Position */
249 #define CPSR_T_Msk (1UL << CPSR_T_Pos) /*!< \brief CPSR: T Mask */
251 #define CPSR_M_Pos 0U /*!< \brief CPSR: M Position */
252 #define CPSR_M_Msk (0x1FUL << CPSR_M_Pos) /*!< \brief CPSR: M Mask */
254 /* CP15 Register SCTLR */
259 uint32_t M:1; /*!< \brief bit: 0 MMU enable */
260 uint32_t A:1; /*!< \brief bit: 1 Alignment check enable */
261 uint32_t C:1; /*!< \brief bit: 2 Cache enable */
262 uint32_t _reserved0:2; /*!< \brief bit: 3.. 4 Reserved */
263 uint32_t CP15BEN:1; /*!< \brief bit: 5 CP15 barrier enable */
264 uint32_t _reserved1:1; /*!< \brief bit: 6 Reserved */
265 uint32_t B:1; /*!< \brief bit: 7 Endianness model */
266 uint32_t _reserved2:2; /*!< \brief bit: 8.. 9 Reserved */
267 uint32_t SW:1; /*!< \brief bit: 10 SWP and SWPB enable */
268 uint32_t Z:1; /*!< \brief bit: 11 Branch prediction enable */
269 uint32_t I:1; /*!< \brief bit: 12 Instruction cache enable */
270 uint32_t V:1; /*!< \brief bit: 13 Vectors bit */
271 uint32_t RR:1; /*!< \brief bit: 14 Round Robin select */
272 uint32_t _reserved3:2; /*!< \brief bit:15..16 Reserved */
273 uint32_t HA:1; /*!< \brief bit: 17 Hardware Access flag enable */
274 uint32_t _reserved4:1; /*!< \brief bit: 18 Reserved */
275 uint32_t WXN:1; /*!< \brief bit: 19 Write permission implies XN */
276 uint32_t UWXN:1; /*!< \brief bit: 20 Unprivileged write permission implies PL1 XN */
277 uint32_t FI:1; /*!< \brief bit: 21 Fast interrupts configuration enable */
278 uint32_t U:1; /*!< \brief bit: 22 Alignment model */
279 uint32_t _reserved5:1; /*!< \brief bit: 23 Reserved */
280 uint32_t VE:1; /*!< \brief bit: 24 Interrupt Vectors Enable */
281 uint32_t EE:1; /*!< \brief bit: 25 Exception Endianness */
282 uint32_t _reserved6:1; /*!< \brief bit: 26 Reserved */
283 uint32_t NMFI:1; /*!< \brief bit: 27 Non-maskable FIQ (NMFI) support */
284 uint32_t TRE:1; /*!< \brief bit: 28 TEX remap enable. */
285 uint32_t AFE:1; /*!< \brief bit: 29 Access flag enable */
286 uint32_t TE:1; /*!< \brief bit: 30 Thumb Exception enable */
287 uint32_t _reserved7:1; /*!< \brief bit: 31 Reserved */
288 } b; /*!< \brief Structure used for bit access */
289 uint32_t w; /*!< \brief Type used for word access */
292 #define SCTLR_TE_Pos 30U /*!< \brief SCTLR: TE Position */
293 #define SCTLR_TE_Msk (1UL << SCTLR_TE_Pos) /*!< \brief SCTLR: TE Mask */
295 #define SCTLR_AFE_Pos 29U /*!< \brief SCTLR: AFE Position */
296 #define SCTLR_AFE_Msk (1UL << SCTLR_AFE_Pos) /*!< \brief SCTLR: AFE Mask */
298 #define SCTLR_TRE_Pos 28U /*!< \brief SCTLR: TRE Position */
299 #define SCTLR_TRE_Msk (1UL << SCTLR_TRE_Pos) /*!< \brief SCTLR: TRE Mask */
301 #define SCTLR_NMFI_Pos 27U /*!< \brief SCTLR: NMFI Position */
302 #define SCTLR_NMFI_Msk (1UL << SCTLR_NMFI_Pos) /*!< \brief SCTLR: NMFI Mask */
304 #define SCTLR_EE_Pos 25U /*!< \brief SCTLR: EE Position */
305 #define SCTLR_EE_Msk (1UL << SCTLR_EE_Pos) /*!< \brief SCTLR: EE Mask */
307 #define SCTLR_VE_Pos 24U /*!< \brief SCTLR: VE Position */
308 #define SCTLR_VE_Msk (1UL << SCTLR_VE_Pos) /*!< \brief SCTLR: VE Mask */
310 #define SCTLR_U_Pos 22U /*!< \brief SCTLR: U Position */
311 #define SCTLR_U_Msk (1UL << SCTLR_U_Pos) /*!< \brief SCTLR: U Mask */
313 #define SCTLR_FI_Pos 21U /*!< \brief SCTLR: FI Position */
314 #define SCTLR_FI_Msk (1UL << SCTLR_FI_Pos) /*!< \brief SCTLR: FI Mask */
316 #define SCTLR_UWXN_Pos 20U /*!< \brief SCTLR: UWXN Position */
317 #define SCTLR_UWXN_Msk (1UL << SCTLR_UWXN_Pos) /*!< \brief SCTLR: UWXN Mask */
319 #define SCTLR_WXN_Pos 19U /*!< \brief SCTLR: WXN Position */
320 #define SCTLR_WXN_Msk (1UL << SCTLR_WXN_Pos) /*!< \brief SCTLR: WXN Mask */
322 #define SCTLR_HA_Pos 17U /*!< \brief SCTLR: HA Position */
323 #define SCTLR_HA_Msk (1UL << SCTLR_HA_Pos) /*!< \brief SCTLR: HA Mask */
325 #define SCTLR_RR_Pos 14U /*!< \brief SCTLR: RR Position */
326 #define SCTLR_RR_Msk (1UL << SCTLR_RR_Pos) /*!< \brief SCTLR: RR Mask */
328 #define SCTLR_V_Pos 13U /*!< \brief SCTLR: V Position */
329 #define SCTLR_V_Msk (1UL << SCTLR_V_Pos) /*!< \brief SCTLR: V Mask */
331 #define SCTLR_I_Pos 12U /*!< \brief SCTLR: I Position */
332 #define SCTLR_I_Msk (1UL << SCTLR_I_Pos) /*!< \brief SCTLR: I Mask */
334 #define SCTLR_Z_Pos 11U /*!< \brief SCTLR: Z Position */
335 #define SCTLR_Z_Msk (1UL << SCTLR_Z_Pos) /*!< \brief SCTLR: Z Mask */
337 #define SCTLR_SW_Pos 10U /*!< \brief SCTLR: SW Position */
338 #define SCTLR_SW_Msk (1UL << SCTLR_SW_Pos) /*!< \brief SCTLR: SW Mask */
340 #define SCTLR_B_Pos 7U /*!< \brief SCTLR: B Position */
341 #define SCTLR_B_Msk (1UL << SCTLR_B_Pos) /*!< \brief SCTLR: B Mask */
343 #define SCTLR_CP15BEN_Pos 5U /*!< \brief SCTLR: CP15BEN Position */
344 #define SCTLR_CP15BEN_Msk (1UL << SCTLR_CP15BEN_Pos) /*!< \brief SCTLR: CP15BEN Mask */
346 #define SCTLR_C_Pos 2U /*!< \brief SCTLR: C Position */
347 #define SCTLR_C_Msk (1UL << SCTLR_C_Pos) /*!< \brief SCTLR: C Mask */
349 #define SCTLR_A_Pos 1U /*!< \brief SCTLR: A Position */
350 #define SCTLR_A_Msk (1UL << SCTLR_A_Pos) /*!< \brief SCTLR: A Mask */
352 #define SCTLR_M_Pos 0U /*!< \brief SCTLR: M Position */
353 #define SCTLR_M_Msk (1UL << SCTLR_M_Pos) /*!< \brief SCTLR: M Mask */
355 /* CP15 Register ACTLR */
360 uint32_t _reserved0:6; /*!< bit: 0.. 5 Reserved */
361 uint32_t SMP:1; /*!< bit: 6 Enables coherent requests to the processor */
362 uint32_t _reserved1:3; /*!< bit: 7.. 9 Reserved */
363 uint32_t DODMBS:1; /*!< bit: 10 Disable optimized data memory barrier behavior */
364 uint32_t L2RADIS:1; /*!< bit: 11 L2 Data Cache read-allocate mode disable */
365 uint32_t L1RADIS:1; /*!< bit: 12 L1 Data Cache read-allocate mode disable */
366 uint32_t L1PCTL:2; /*!< bit:13..14 L1 Data prefetch control */
367 uint32_t DDVM:1; /*!< bit: 15 Disable Distributed Virtual Memory (DVM) transactions */
368 uint32_t _reserved3:12; /*!< bit:16..27 Reserved */
369 uint32_t DDI:1; /*!< bit: 28 Disable dual issue */
370 uint32_t _reserved7:3; /*!< bit:29..31 Reserved */
371 } b; /*!< Structure used for bit access */
372 uint32_t w; /*!< Type used for word access */
375 #define ACTLR_DDI_Pos 28U /*!< ACTLR: DDI Position */
376 #define ACTLR_DDI_Msk (1UL << ACTLR_DDI_Pos) /*!< ACTLR: DDI Mask */
378 #define ACTLR_DDVM_Pos 15U /*!< ACTLR: DDVM Position */
379 #define ACTLR_DDVM_Msk (1UL << ACTLR_DDVM_Pos) /*!< ACTLR: DDVM Mask */
381 #define ACTLR_L1PCTL_Pos 13U /*!< ACTLR: L1PCTL Position */
382 #define ACTLR_L1PCTL_Msk (3UL << ACTLR_L1PCTL_Pos) /*!< ACTLR: L1PCTL Mask */
384 #define ACTLR_L1RADIS_Pos 12U /*!< ACTLR: L1RADIS Position */
385 #define ACTLR_L1RADIS_Msk (1UL << ACTLR_L1RADIS_Pos) /*!< ACTLR: L1RADIS Mask */
387 #define ACTLR_L2RADIS_Pos 11U /*!< ACTLR: L2RADIS Position */
388 #define ACTLR_L2RADIS_Msk (1UL << ACTLR_L2RADIS_Pos) /*!< ACTLR: L2RADIS Mask */
390 #define ACTLR_DODMBS_Pos 10U /*!< ACTLR: DODMBS Position */
391 #define ACTLR_DODMBS_Msk (1UL << ACTLR_DODMBS_Pos) /*!< ACTLR: DODMBS Mask */
393 #define ACTLR_SMP_Pos 6U /*!< ACTLR: SMP Position */
394 #define ACTLR_SMP_Msk (1UL << ACTLR_SMP_Pos) /*!< ACTLR: SMP Mask */
396 /* CP15 Register CPACR */
401 uint32_t _reserved0:20; /*!< \brief bit: 0..19 Reserved */
402 uint32_t cp10:2; /*!< \brief bit:20..21 Access rights for coprocessor 10 */
403 uint32_t cp11:2; /*!< \brief bit:22..23 Access rights for coprocessor 11 */
404 uint32_t _reserved1:6; /*!< \brief bit:24..29 Reserved */
405 uint32_t D32DIS:1; /*!< \brief bit: 30 Disable use of registers D16-D31 of the VFP register file */
406 uint32_t ASEDIS:1; /*!< \brief bit: 31 Disable Advanced SIMD Functionality */
407 } b; /*!< \brief Structure used for bit access */
408 uint32_t w; /*!< \brief Type used for word access */
411 #define CPACR_ASEDIS_Pos 31U /*!< \brief CPACR: ASEDIS Position */
412 #define CPACR_ASEDIS_Msk (1UL << CPACR_ASEDIS_Pos) /*!< \brief CPACR: ASEDIS Mask */
414 #define CPACR_D32DIS_Pos 30U /*!< \brief CPACR: D32DIS Position */
415 #define CPACR_D32DIS_Msk (1UL << CPACR_D32DIS_Pos) /*!< \brief CPACR: D32DIS Mask */
417 #define CPACR_cp11_Pos 22U /*!< \brief CPACR: cp11 Position */
418 #define CPACR_cp11_Msk (3UL << CPACR_cp11_Pos) /*!< \brief CPACR: cp11 Mask */
420 #define CPACR_cp10_Pos 20U /*!< \brief CPACR: cp10 Position */
421 #define CPACR_cp10_Msk (3UL << CPACR_cp10_Pos) /*!< \brief CPACR: cp10 Mask */
423 /* CP15 Register DFSR */
428 uint32_t FS0:4; /*!< \brief bit: 0.. 3 Fault Status bits bit 0-3 */
429 uint32_t Domain:4; /*!< \brief bit: 4.. 7 Fault on which domain */
430 uint32_t _reserved0:2; /*!< \brief bit: 8.. 9 Reserved */
431 uint32_t FS1:1; /*!< \brief bit: 10 Fault Status bits bit 4 */
432 uint32_t WnR:1; /*!< \brief bit: 11 Write not Read bit */
433 uint32_t ExT:1; /*!< \brief bit: 12 External abort type */
434 uint32_t CM:1; /*!< \brief bit: 13 Cache maintenance fault */
435 uint32_t _reserved1:18; /*!< \brief bit:14..31 Reserved */
436 } b; /*!< \brief Structure used for bit access */
437 uint32_t w; /*!< \brief Type used for word access */
440 #define DFSR_CM_Pos 13U /*!< \brief DFSR: CM Position */
441 #define DFSR_CM_Msk (1UL << DFSR_CM_Pos) /*!< \brief DFSR: CM Mask */
443 #define DFSR_Ext_Pos 12U /*!< \brief DFSR: Ext Position */
444 #define DFSR_Ext_Msk (1UL << DFSR_Ext_Pos) /*!< \brief DFSR: Ext Mask */
446 #define DFSR_WnR_Pos 11U /*!< \brief DFSR: WnR Position */
447 #define DFSR_WnR_Msk (1UL << DFSR_WnR_Pos) /*!< \brief DFSR: WnR Mask */
449 #define DFSR_FS1_Pos 10U /*!< \brief DFSR: FS1 Position */
450 #define DFSR_FS1_Msk (1UL << DFSR_FS1_Pos) /*!< \brief DFSR: FS1 Mask */
452 #define DFSR_Domain_Pos 4U /*!< \brief DFSR: Domain Position */
453 #define DFSR_Domain_Msk (0xFUL << DFSR_Domain_Pos) /*!< \brief DFSR: Domain Mask */
455 #define DFSR_FS0_Pos 0U /*!< \brief DFSR: FS0 Position */
456 #define DFSR_FS0_Msk (0xFUL << DFSR_FS0_Pos) /*!< \brief DFSR: FS0 Mask */
458 /* CP15 Register IFSR */
463 uint32_t FS0:4; /*!< \brief bit: 0.. 3 Fault Status bits bit 0-3 */
464 uint32_t _reserved0:6; /*!< \brief bit: 4.. 9 Reserved */
465 uint32_t FS1:1; /*!< \brief bit: 10 Fault Status bits bit 4 */
466 uint32_t _reserved1:1; /*!< \brief bit: 11 Reserved */
467 uint32_t ExT:1; /*!< \brief bit: 12 External abort type */
468 uint32_t _reserved2:19; /*!< \brief bit:13..31 Reserved */
469 } b; /*!< \brief Structure used for bit access */
470 uint32_t w; /*!< \brief Type used for word access */
473 #define IFSR_ExT_Pos 12U /*!< \brief IFSR: ExT Position */
474 #define IFSR_ExT_Msk (1UL << IFSR_ExT_Pos) /*!< \brief IFSR: ExT Mask */
476 #define IFSR_FS1_Pos 10U /*!< \brief IFSR: FS1 Position */
477 #define IFSR_FS1_Msk (1UL << IFSR_FS1_Pos) /*!< \brief IFSR: FS1 Mask */
479 #define IFSR_FS0_Pos 0U /*!< \brief IFSR: FS0 Position */
480 #define IFSR_FS0_Msk (0xFUL << IFSR_FS0_Pos) /*!< \brief IFSR: FS0 Mask */
482 /* CP15 Register ISR */
487 uint32_t _reserved0:6; /*!< \brief bit: 0.. 5 Reserved */
488 uint32_t F:1; /*!< \brief bit: 6 FIQ pending bit */
489 uint32_t I:1; /*!< \brief bit: 7 IRQ pending bit */
490 uint32_t A:1; /*!< \brief bit: 8 External abort pending bit */
491 uint32_t _reserved1:23; /*!< \brief bit:14..31 Reserved */
492 } b; /*!< \brief Structure used for bit access */
493 uint32_t w; /*!< \brief Type used for word access */
496 #define ISR_A_Pos 13U /*!< \brief ISR: A Position */
497 #define ISR_A_Msk (1UL << ISR_A_Pos) /*!< \brief ISR: A Mask */
499 #define ISR_I_Pos 12U /*!< \brief ISR: I Position */
500 #define ISR_I_Msk (1UL << ISR_I_Pos) /*!< \brief ISR: I Mask */
502 #define ISR_F_Pos 11U /*!< \brief ISR: F Position */
503 #define ISR_F_Msk (1UL << ISR_F_Pos) /*!< \brief ISR: F Mask */
507 \brief Union type to access the L2C_310 Cache Controller.
509 #if (__L2C_PRESENT == 1U) || defined(DOXYGEN)
512 __IM uint32_t CACHE_ID; /*!< \brief Offset: 0x0000 (R/ ) Cache ID Register */
513 __IM uint32_t CACHE_TYPE; /*!< \brief Offset: 0x0004 (R/ ) Cache Type Register */
514 uint32_t RESERVED0[0x3e];
515 __IOM uint32_t CONTROL; /*!< \brief Offset: 0x0100 (R/W) Control Register */
516 __IOM uint32_t AUX_CNT; /*!< \brief Offset: 0x0104 (R/W) Auxiliary Control */
517 uint32_t RESERVED1[0x3e];
518 __IOM uint32_t EVENT_CONTROL; /*!< \brief Offset: 0x0200 (R/W) Event Counter Control */
519 __IOM uint32_t EVENT_COUNTER1_CONF; /*!< \brief Offset: 0x0204 (R/W) Event Counter 1 Configuration */
520 __IOM uint32_t EVENT_COUNTER0_CONF; /*!< \brief Offset: 0x0208 (R/W) Event Counter 1 Configuration */
521 uint32_t RESERVED2[0x2];
522 __IOM uint32_t INTERRUPT_MASK; /*!< \brief Offset: 0x0214 (R/W) Interrupt Mask */
523 __IM uint32_t MASKED_INT_STATUS; /*!< \brief Offset: 0x0218 (R/ ) Masked Interrupt Status */
524 __IM uint32_t RAW_INT_STATUS; /*!< \brief Offset: 0x021c (R/ ) Raw Interrupt Status */
525 __OM uint32_t INTERRUPT_CLEAR; /*!< \brief Offset: 0x0220 ( /W) Interrupt Clear */
526 uint32_t RESERVED3[0x143];
527 __IOM uint32_t CACHE_SYNC; /*!< \brief Offset: 0x0730 (R/W) Cache Sync */
528 uint32_t RESERVED4[0xf];
529 __IOM uint32_t INV_LINE_PA; /*!< \brief Offset: 0x0770 (R/W) Invalidate Line By PA */
530 uint32_t RESERVED6[2];
531 __IOM uint32_t INV_WAY; /*!< \brief Offset: 0x077c (R/W) Invalidate by Way */
532 uint32_t RESERVED5[0xc];
533 __IOM uint32_t CLEAN_LINE_PA; /*!< \brief Offset: 0x07b0 (R/W) Clean Line by PA */
534 uint32_t RESERVED7[1];
535 __IOM uint32_t CLEAN_LINE_INDEX_WAY; /*!< \brief Offset: 0x07b8 (R/W) Clean Line by Index/Way */
536 __IOM uint32_t CLEAN_WAY; /*!< \brief Offset: 0x07bc (R/W) Clean by Way */
537 uint32_t RESERVED8[0xc];
538 __IOM uint32_t CLEAN_INV_LINE_PA; /*!< \brief Offset: 0x07f0 (R/W) Clean and Invalidate Line by PA */
539 uint32_t RESERVED9[1];
540 __IOM uint32_t CLEAN_INV_LINE_INDEX_WAY; /*!< \brief Offset: 0x07f8 (R/W) Clean and Invalidate Line by Index/Way */
541 __IOM uint32_t CLEAN_INV_WAY; /*!< \brief Offset: 0x07fc (R/W) Clean and Invalidate by Way */
542 uint32_t RESERVED10[0x40];
543 __IOM uint32_t DATA_LOCK_0_WAY; /*!< \brief Offset: 0x0900 (R/W) Data Lockdown 0 by Way */
544 __IOM uint32_t INST_LOCK_0_WAY; /*!< \brief Offset: 0x0904 (R/W) Instruction Lockdown 0 by Way */
545 __IOM uint32_t DATA_LOCK_1_WAY; /*!< \brief Offset: 0x0908 (R/W) Data Lockdown 1 by Way */
546 __IOM uint32_t INST_LOCK_1_WAY; /*!< \brief Offset: 0x090c (R/W) Instruction Lockdown 1 by Way */
547 __IOM uint32_t DATA_LOCK_2_WAY; /*!< \brief Offset: 0x0910 (R/W) Data Lockdown 2 by Way */
548 __IOM uint32_t INST_LOCK_2_WAY; /*!< \brief Offset: 0x0914 (R/W) Instruction Lockdown 2 by Way */
549 __IOM uint32_t DATA_LOCK_3_WAY; /*!< \brief Offset: 0x0918 (R/W) Data Lockdown 3 by Way */
550 __IOM uint32_t INST_LOCK_3_WAY; /*!< \brief Offset: 0x091c (R/W) Instruction Lockdown 3 by Way */
551 __IOM uint32_t DATA_LOCK_4_WAY; /*!< \brief Offset: 0x0920 (R/W) Data Lockdown 4 by Way */
552 __IOM uint32_t INST_LOCK_4_WAY; /*!< \brief Offset: 0x0924 (R/W) Instruction Lockdown 4 by Way */
553 __IOM uint32_t DATA_LOCK_5_WAY; /*!< \brief Offset: 0x0928 (R/W) Data Lockdown 5 by Way */
554 __IOM uint32_t INST_LOCK_5_WAY; /*!< \brief Offset: 0x092c (R/W) Instruction Lockdown 5 by Way */
555 __IOM uint32_t DATA_LOCK_6_WAY; /*!< \brief Offset: 0x0930 (R/W) Data Lockdown 5 by Way */
556 __IOM uint32_t INST_LOCK_6_WAY; /*!< \brief Offset: 0x0934 (R/W) Instruction Lockdown 5 by Way */
557 __IOM uint32_t DATA_LOCK_7_WAY; /*!< \brief Offset: 0x0938 (R/W) Data Lockdown 6 by Way */
558 __IOM uint32_t INST_LOCK_7_WAY; /*!< \brief Offset: 0x093c (R/W) Instruction Lockdown 6 by Way */
559 uint32_t RESERVED11[0x4];
560 __IOM uint32_t LOCK_LINE_EN; /*!< \brief Offset: 0x0950 (R/W) Lockdown by Line Enable */
561 __IOM uint32_t UNLOCK_ALL_BY_WAY; /*!< \brief Offset: 0x0954 (R/W) Unlock All Lines by Way */
562 uint32_t RESERVED12[0xaa];
563 __IOM uint32_t ADDRESS_FILTER_START; /*!< \brief Offset: 0x0c00 (R/W) Address Filtering Start */
564 __IOM uint32_t ADDRESS_FILTER_END; /*!< \brief Offset: 0x0c04 (R/W) Address Filtering End */
565 uint32_t RESERVED13[0xce];
566 __IOM uint32_t DEBUG_CONTROL; /*!< \brief Offset: 0x0f40 (R/W) Debug Control Register */
569 #define L2C_310 ((L2C_310_TypeDef *)L2C_310_BASE) /*!< \brief L2C_310 Declaration */
572 #if (__GIC_PRESENT == 1U) || defined(DOXYGEN)
573 /** \brief Structure type to access the Generic Interrupt Controller Distributor (GICD)
577 __IOM uint32_t D_CTLR; /*!< \brief Offset: 0x000 (R/W) Distributor Control Register */
578 __IM uint32_t D_TYPER; /*!< \brief Offset: 0x004 (R/ ) Interrupt Controller Type Register */
579 __IM uint32_t D_IIDR; /*!< \brief Offset: 0x008 (R/ ) Distributor Implementer Identification Register */
581 __IOM uint32_t D_STATUSR; /*!< \brief Offset: 0x010 (R/W) Error Reporting Status Register, optional */
582 uint32_t RESERVED1[11];
583 __OM uint32_t D_SETSPI_NSR; /*!< \brief Offset: 0x040 ( /W) Set SPI Register */
585 __OM uint32_t D_CLRSPI_NSR; /*!< \brief Offset: 0x048 ( /W) Clear SPI Register */
587 __OM uint32_t D_SETSPI_SR; /*!< \brief Offset: 0x050 ( /W) Set SPI, Secure Register */
589 __OM uint32_t D_CLRSPI_SR; /*!< \brief Offset: 0x058 ( /W) Clear SPI, Secure Register */
590 uint32_t RESERVED5[9];
591 __IOM uint32_t D_IGROUPR[32]; /*!< \brief Offset: 0x080 (R/W) Interrupt Group Registers */
592 __IOM uint32_t D_ISENABLER[32]; /*!< \brief Offset: 0x100 (R/W) Interrupt Set-Enable Registers */
593 __IOM uint32_t D_ICENABLER[32]; /*!< \brief Offset: 0x180 (R/W) Interrupt Clear-Enable Registers */
594 __IOM uint32_t D_ISPENDR[32]; /*!< \brief Offset: 0x200 (R/W) Interrupt Set-Pending Registers */
595 __IOM uint32_t D_ICPENDR[32]; /*!< \brief Offset: 0x280 (R/W) Interrupt Clear-Pending Registers */
596 __IOM uint32_t D_ISACTIVER[32]; /*!< \brief Offset: 0x300 (R/W) Interrupt Set-Active Registers */
597 __IOM uint32_t D_ICACTIVER[32]; /*!< \brief Offset: 0x380 (R/W) Interrupt Clear-Active Registers */
598 __IOM uint8_t D_IPRIORITYR[1020]; /*!< \brief Offset: 0x400 (R/W) Interrupt Priority Registers */
599 uint32_t RESERVED9[1];
600 __IOM uint8_t D_ITARGETSR[1020]; /*!< \brief Offset: 0x800 (R/W) Interrupt Targets Registers */
601 uint32_t RESERVED10[1];
602 __IOM uint32_t D_ICFGR[64]; /*!< \brief Offset: 0xC00 (R/W) Interrupt Configuration Registers */
603 __IOM uint32_t D_IGRPMODR[32]; /*!< \brief Offset: 0xD00 (R/W) Interrupt Group Modifier Registers */
604 uint32_t RESERVED11[32];
605 __IOM uint32_t D_NSACR[64]; /*!< \brief Offset: 0xE00 (R/W) Non-secure Access Control Registers */
606 __OM uint32_t D_SGIR; /*!< \brief Offset: 0xF00 ( /W) Software Generated Interrupt Register */
607 uint32_t RESERVED13[3];
608 __IOM uint8_t D_CPENDSGIR[16]; /*!< \brief Offset: 0xF10 (R/W) SGI Clear-Pending Registers */
609 __IOM uint8_t D_SPENDSGIR[16]; /*!< \brief Offset: 0xF20 (R/W) SGI Set-Pending Registers */
610 uint32_t RESERVED14[5236];
611 __IOM uint64_t D_IROUTER[988]; /*!< \brief Offset: 0x6100(R/W) Interrupt Routing Registers */
612 } GICDistributor_Type;
614 #define GICDistributor ((GICDistributor_Type *) GIC_DISTRIBUTOR_BASE ) /*!< GIC Distributor configuration struct */
616 /** \brief Structure type to access the Generic Interrupt Controller Interface (GICC)
620 __IOM uint32_t C_CTLR; /*!< \brief Offset: 0x000 (R/W) CPU Interface Control Register */
621 __IOM uint32_t C_PMR; /*!< \brief Offset: 0x004 (R/W) Interrupt Priority Mask Register */
622 __IOM uint32_t C_BPR; /*!< \brief Offset: 0x008 (R/W) Binary Point Register */
623 __IM uint32_t C_IAR; /*!< \brief Offset: 0x00C (R/ ) Interrupt Acknowledge Register */
624 __OM uint32_t C_EOIR; /*!< \brief Offset: 0x010 ( /W) End Of Interrupt Register */
625 __IM uint32_t C_RPR; /*!< \brief Offset: 0x014 (R/ ) Running Priority Register */
626 __IM uint32_t C_HPPIR; /*!< \brief Offset: 0x018 (R/ ) Highest Priority Pending Interrupt Register */
627 __IOM uint32_t C_ABPR; /*!< \brief Offset: 0x01C (R/W) Aliased Binary Point Register */
628 __IM uint32_t C_AIAR; /*!< \brief Offset: 0x020 (R/ ) Aliased Interrupt Acknowledge Register */
629 __OM uint32_t C_AEOIR; /*!< \brief Offset: 0x024 ( /W) Aliased End Of Interrupt Register */
630 __IM uint32_t C_AHPPIR; /*!< \brief Offset: 0x028 (R/ ) Aliased Highest Priority Pending Interrupt Register */
631 __IOM uint32_t C_STATUSR; /*!< \brief Offset: 0x02C (R/W) Error Reporting Status Register, optional */
632 uint32_t RESERVED15[40];
633 __IOM uint32_t C_APR[4]; /*!< \brief Offset: 0x0D0 (R/W) Active Priority Register */
634 __IOM uint32_t C_NSAPR[4]; /*!< \brief Offset: 0x0E0 (R/W) Non-secure Active Priority Register */
635 uint32_t RESERVED17[3];
636 __IM uint32_t C_IIDR; /*!< \brief Offset: 0x0FC (R/ ) CPU Interface Identification Register */
637 uint32_t RESERVED18[960];
638 __OM uint32_t C_DIR; /*!< \brief Offset: 0x1000( /W) Deactivate Interrupt Register */
641 #define GICInterface ((GICInterface_Type *) GIC_INTERFACE_BASE ) /*!< GIC Interface configuration struct */
644 #if (__TIM_PRESENT == 1U) || defined(DOXYGEN)
645 #if ((__CORTEX_A == 5U) || (__CORTEX_A == 9U)) || defined(DOXYGEN)
646 /** \brief Structure type to access the Private Timer
650 __IOM uint32_t LOAD; //!< \brief Offset: 0x000 (R/W) Private Timer Load Register
651 __IOM uint32_t COUNTER; //!< \brief Offset: 0x004 (R/W) Private Timer Counter Register
652 __IOM uint32_t CONTROL; //!< \brief Offset: 0x008 (R/W) Private Timer Control Register
653 __IM uint32_t ISR; //!< \brief Offset: 0x00C (R/ ) Private Timer Interrupt Status Register
654 uint32_t RESERVED[4];
655 __IOM uint32_t WLOAD; //!< \brief Offset: 0x020 (R/W) Watchdog Load Register
656 __IOM uint32_t WCOUNTER; //!< \brief Offset: 0x024 (R/W) Watchdog Counter Register
657 __IOM uint32_t WCONTROL; //!< \brief Offset: 0x028 (R/W) Watchdog Control Register
658 __IOM uint32_t WISR; //!< \brief Offset: 0x02C (R/W) Watchdog Interrupt Status Register
659 __IOM uint32_t WRESET; //!< \brief Offset: 0x030 (R/W) Watchdog Reset Status Register
660 __IM uint32_t WDISABLE; //!< \brief Offset: 0x034 (R/ ) Watchdog Disable Register
662 #define PTIM ((Timer_Type *) TIMER_BASE ) /*!< \brief Timer configuration struct */
666 /*******************************************************************************
667 * Hardware Abstraction Layer
668 Core Function Interface contains:
670 - L2C-310 Cache Controller Functions
671 - PL1 Timer Functions
674 ******************************************************************************/
676 /* ########################## L1 Cache functions ################################# */
678 /** \brief Enable Caches by setting I and C bits in \ref CMSIS_SCTLR "SCTLR" register.
680 __STATIC_INLINE void L1C_EnableCaches(void) {
681 __set_SCTLR( __get_SCTLR() | (1u << SCTLR_I_Pos) | (1u << SCTLR_C_Pos));
685 /** \brief Disable Caches by clearing I and C bits in \ref CMSIS_SCTLR "SCTLR" register.
687 __STATIC_INLINE void L1C_DisableCaches(void) {
688 __set_SCTLR( __get_SCTLR() & ~(1u << SCTLR_I_Pos) & ~(1u << SCTLR_C_Pos));
692 /** \brief Enable Branch Prediction by setting Z bit in \ref CMSIS_SCTLR "SCTLR" register.
694 __STATIC_INLINE void L1C_EnableBTAC(void) {
695 __set_SCTLR( __get_SCTLR() | (1u << SCTLR_Z_Pos));
699 /** \brief Disable Branch Prediction by clearing Z bit in \ref CMSIS_SCTLR "SCTLR" register.
701 __STATIC_INLINE void L1C_DisableBTAC(void) {
702 __set_SCTLR( __get_SCTLR() & ~(1u << SCTLR_Z_Pos));
706 /** \brief Invalidate entire branch predictor array
708 __STATIC_INLINE void L1C_InvalidateBTAC(void) {
710 __DSB(); //ensure completion of the invalidation
711 __ISB(); //ensure instruction fetch path sees new state
714 /** \brief Invalidate the whole instruction cache
716 __STATIC_INLINE void L1C_InvalidateICacheAll(void) {
718 __DSB(); //ensure completion of the invalidation
719 __ISB(); //ensure instruction fetch path sees new I cache state
722 /** \brief Clean data cache line by address.
723 * \param va Pointer to data to clear the cache for.
725 __STATIC_INLINE void L1C_CleanDCacheMVA(void *va) {
726 __set_DCCMVAC((uint32_t)va);
727 __DMB(); //ensure the ordering of data cache maintenance operations and their effects
730 /** \brief Invalidate data cache line by address.
731 * \param va Pointer to data to invalidate the cache for.
733 __STATIC_INLINE void L1C_InvalidateDCacheMVA(void *va) {
734 __set_DCIMVAC((uint32_t)va);
735 __DMB(); //ensure the ordering of data cache maintenance operations and their effects
738 /** \brief Clean and Invalidate data cache by address.
739 * \param va Pointer to data to invalidate the cache for.
741 __STATIC_INLINE void L1C_CleanInvalidateDCacheMVA(void *va) {
742 __set_DCCIMVAC((uint32_t)va);
743 __DMB(); //ensure the ordering of data cache maintenance operations and their effects
746 /** \brief Clean and Invalidate the entire data or unified cache
747 * \param op 0 - invalidate, 1 - clean, otherwise - invalidate and clean
748 * \see __L1C_CleanInvalidateCache
750 __STATIC_INLINE void L1C_CleanInvalidateCache(uint32_t op) {
751 __L1C_CleanInvalidateCache(op);
754 /** \brief Invalidate the whole data cache.
756 __STATIC_INLINE void L1C_InvalidateDCacheAll(void) {
757 L1C_CleanInvalidateCache(0);
760 /** \brief Clean the whole data cache.
762 __STATIC_INLINE void L1C_CleanDCacheAll(void) {
763 L1C_CleanInvalidateCache(1);
766 /** \brief Clean and invalidate the whole data cache.
768 __STATIC_INLINE void L1C_CleanInvalidateDCacheAll(void) {
769 L1C_CleanInvalidateCache(2);
773 /* ########################## L2 Cache functions ################################# */
774 #if (__L2C_PRESENT == 1U) || defined(DOXYGEN)
775 /** \brief Cache Sync operation by writing \ref L2C_310_TypeDef::CACHE_SYNC "CACHE_SYNC" register.
777 __STATIC_INLINE void L2C_Sync(void)
779 L2C_310->CACHE_SYNC = 0x0;
782 /** \brief Read cache controller cache ID from \ref L2C_310_TypeDef::CACHE_ID "CACHE_ID" register.
783 * \return L2C_310_TypeDef::CACHE_ID
785 __STATIC_INLINE int L2C_GetID (void)
787 return L2C_310->CACHE_ID;
790 /** \brief Read cache controller cache type from \ref L2C_310_TypeDef::CACHE_TYPE "CACHE_TYPE" register.
791 * \return L2C_310_TypeDef::CACHE_TYPE
793 __STATIC_INLINE int L2C_GetType (void)
795 return L2C_310->CACHE_TYPE;
798 /** \brief Invalidate all cache by way
800 __STATIC_INLINE void L2C_InvAllByWay (void)
804 if (L2C_310->AUX_CNT & (1u << 16u)) {
810 L2C_310->INV_WAY = (1u << assoc) - 1u;
811 while(L2C_310->INV_WAY & ((1u << assoc) - 1u)); //poll invalidate
816 /** \brief Clean and Invalidate all cache by way
818 __STATIC_INLINE void L2C_CleanInvAllByWay (void)
822 if (L2C_310->AUX_CNT & (1u << 16u)) {
828 L2C_310->CLEAN_INV_WAY = (1u << assoc) - 1u;
829 while(L2C_310->CLEAN_INV_WAY & ((1u << assoc) - 1u)); //poll invalidate
834 /** \brief Enable Level 2 Cache
836 __STATIC_INLINE void L2C_Enable(void)
838 L2C_310->CONTROL = 0;
839 L2C_310->INTERRUPT_CLEAR = 0x000001FFuL;
840 L2C_310->DEBUG_CONTROL = 0;
841 L2C_310->DATA_LOCK_0_WAY = 0;
842 L2C_310->CACHE_SYNC = 0;
843 L2C_310->CONTROL = 0x01;
847 /** \brief Disable Level 2 Cache
849 __STATIC_INLINE void L2C_Disable(void)
851 L2C_310->CONTROL = 0x00;
855 /** \brief Invalidate cache by physical address
856 * \param pa Pointer to data to invalidate cache for.
858 __STATIC_INLINE void L2C_InvPa (void *pa)
860 L2C_310->INV_LINE_PA = (unsigned int)pa;
864 /** \brief Clean cache by physical address
865 * \param pa Pointer to data to invalidate cache for.
867 __STATIC_INLINE void L2C_CleanPa (void *pa)
869 L2C_310->CLEAN_LINE_PA = (unsigned int)pa;
873 /** \brief Clean and invalidate cache by physical address
874 * \param pa Pointer to data to invalidate cache for.
876 __STATIC_INLINE void L2C_CleanInvPa (void *pa)
878 L2C_310->CLEAN_INV_LINE_PA = (unsigned int)pa;
883 /* ########################## GIC functions ###################################### */
884 #if (__GIC_PRESENT == 1U) || defined(DOXYGEN)
886 /** Enable the interrupt distributor using the GIC's \ref GICDistributor_Type::D_CTLR "D_CTLR" register.
888 __STATIC_INLINE void GIC_EnableDistributor(void)
890 GICDistributor->D_CTLR |= 1;
893 /** Disable the interrupt distributor using the GIC's \ref GICDistributor_Type::D_CTLR "D_CTLR" register.
895 __STATIC_INLINE void GIC_DisableDistributor(void)
897 GICDistributor->D_CTLR &=~1;
900 /** Read the GIC's \ref GICDistributor_Type.D_TYPER "D_TYPER" register.
901 * \return GICDistributor_Type::D_TYPER
903 __STATIC_INLINE uint32_t GIC_DistributorInfo(void)
905 return (uint32_t)(GICDistributor->D_TYPER);
908 /** Reads the GIC's \ref GICDistributor_Type.D_IIDR "D_IIDR" register.
909 * \return GICDistributor_Type::D_IIDR
911 __STATIC_INLINE uint32_t GIC_DistributorImplementer(void)
913 return (uint32_t)(GICDistributor->D_IIDR);
916 /** Sets the GIC's \ref GICDistributor_Type.D_ITARGETSR "D_ITARGETSR" register for the given interrupt.
917 * \param IRQn Interrupt to be configured.
918 * \param cpu_target CPU interfaces to assign this interrupt to.
920 __STATIC_INLINE void GIC_SetTarget(IRQn_Type IRQn, uint32_t cpu_target)
922 GICDistributor->D_ITARGETSR[((uint32_t)(int32_t)IRQn)] = (uint8_t)(cpu_target & 0x0f);
925 /** Read the GIC's \ref GICDistributor_Type.D_ITARGETSR "D_ITARGETSR" register.
926 * \param IRQn Interrupt to acquire the configuration for.
927 * \return GICDistributor_Type::D_ITARGETSR
929 __STATIC_INLINE uint32_t GIC_GetTarget(IRQn_Type IRQn)
931 return ((uint32_t) GICDistributor->D_ITARGETSR[((uint32_t)(int32_t)IRQn)] & 0x0f);
934 /** Enable the CPUs interrupt interface.
936 __STATIC_INLINE void GIC_EnableInterface(void)
938 GICInterface->C_CTLR |= 1; //enable interface
941 /** Disable the CPUs interrupt interface.
943 __STATIC_INLINE void GIC_DisableInterface(void)
945 GICInterface->C_CTLR &=~1; //disable distributor
948 /** Read the CPU's \ref GICInterface_Type::C_IAR "C_IAR" register.
949 * \return GICInterface_Type::C_IAR
951 __STATIC_INLINE IRQn_Type GIC_AcknowledgePending(void)
953 return (IRQn_Type)(GICInterface->C_IAR);
956 /** Writes the given interrupt number to the CPU's \ref GICInterface_Type::C_EOIR "C_EOIR" register.
957 * \param IRQn The interrupt to be signaled as finished.
959 __STATIC_INLINE void GIC_EndInterrupt(IRQn_Type IRQn)
961 GICInterface->C_EOIR = IRQn;
964 /** Enables the given interrupt using GIC's \ref GICDistributor_Type::D_ISENABLER "D_ISENABLER" register.
965 * \param IRQn The interrupt to be enabled.
967 __STATIC_INLINE void GIC_EnableIRQ(IRQn_Type IRQn)
969 GICDistributor->D_ISENABLER[IRQn / 32] = 1 << (IRQn % 32);
972 /** Disables the given interrupt using GIC's \ref GICDistributor_Type::D_ICENABLER "D_ICENABLER" register.
973 * \param IRQn The interrupt to be disabled.
975 __STATIC_INLINE void GIC_DisableIRQ(IRQn_Type IRQn)
977 GICDistributor->D_ICENABLER[IRQn / 32] = 1 << (IRQn % 32);
980 /** Sets the given interrupt as pending using GIC's \ref GICDistributor_Type::D_ISPENDR "D_ISPENDR" register.
981 * \param IRQn The interrupt to be enabled.
983 __STATIC_INLINE void GIC_SetPendingIRQ(IRQn_Type IRQn)
986 GICDistributor->D_ISPENDR[IRQn / 32] = 1 << (IRQn % 32);
988 // INTID 0-15 Software Generated Interrupt
989 GICDistributor->D_SPENDSGIR[IRQn] = 1U;
990 // Forward the interrupt to the CPU interface that requested it
991 GICDistributor->D_SGIR = (IRQn | 0x02000000U);
995 /** Clears the given interrupt from beeing pending using GIC's \ref GICDistributor_Type::D_ICPENDR "D_ICPENDR" register.
996 * \param IRQn The interrupt to be enabled.
998 __STATIC_INLINE void GIC_ClearPendingIRQ(IRQn_Type IRQn)
1001 GICDistributor->D_ICPENDR[IRQn / 32] = 1 << (IRQn % 32);
1003 // INTID 0-15 Software Generated Interrupt
1004 GICDistributor->D_CPENDSGIR[IRQn] = 1U;
1008 /** Configures the interrupt egde and model using GIC's GICDistributor_Type::D_ICFGR "D_ICFGR" register.
1009 * \param IRQn The interrupt to be configured.
1010 * \param edge_level Signal sensitivity: 0 - level sensitive, 1 - edge triggered
1011 * \param model Handling mode: 0 - N-N model, 1 - 1-N model.
1013 __STATIC_INLINE void GIC_SetLevelModel(IRQn_Type IRQn, uint8_t edge_level, uint8_t model)
1015 // Word-size read/writes must be used to access this register
1016 volatile uint32_t * field = &(GICDistributor->D_ICFGR[IRQn / 16]);
1017 unsigned bit_shift = (IRQn % 16)<<1;
1018 unsigned int save_word;
1021 save_word &= (~(3 << bit_shift));
1023 *field = (save_word | ((((edge_level & 0x01u) << 1) | (model & 0x01u)) << bit_shift));
1026 /** Set the priority for the given interrupt in the GIC's \ref GICDistributor_Type::D_IPRIORITYR "D_IPRIORITYR" register.
1027 * \param IRQn The interrupt to be configured.
1028 * \param priority The priority for the interrupt, lower values denote higher priorities.
1030 __STATIC_INLINE void GIC_SetPriority(IRQn_Type IRQn, uint32_t priority)
1032 GICDistributor->D_IPRIORITYR[((uint32_t)(int32_t)IRQn)] = (uint8_t)(priority);
1035 /** Read the current interrupt priority from GIC's \ref GICDistributor_Type::D_IPRIORITYR "D_IPRIORITYR" register.
1036 * \param IRQn The interrupt to be queried.
1038 __STATIC_INLINE uint32_t GIC_GetPriority(IRQn_Type IRQn)
1040 return((uint32_t)GICDistributor->D_IPRIORITYR[((uint32_t)(int32_t)IRQn)]);
1043 /** Set the interrupt priority mask using CPU's \ref GICInterface_Type::C_PMR "C_PMR" register.
1044 * \param priority Priority mask to be set.
1046 __STATIC_INLINE void GIC_SetInterfacePriorityMask(uint32_t priority)
1048 GICInterface->C_PMR = priority & 0xff; //set priority mask
1051 /** Read the current interrupt priority mask from CPU's \ref GICInterface_Type::C_PMR "C_PMR" register.
1052 * \result GICInterface_Type::C_PMR
1054 __STATIC_INLINE uint32_t GIC_GetInterfacePriorityMask(void)
1056 return (uint32_t)GICInterface->C_PMR;
1059 /** Configures the group priority and subpriority split point using CPU's \ref GICInterface_Type::C_BPR "C_BPR" register.
1060 * \param binary_point Amount of bits used as subpriority.
1062 __STATIC_INLINE void GIC_SetBinaryPoint(uint32_t binary_point)
1064 GICInterface->C_BPR = binary_point & 0x07; //set binary point
1067 /** Read the current group priority and subpriority split point from CPU's \ref GICInterface_Type::C_BPR "C_BPR" register.
1068 * \return GICInterface_Type::C_BPR
1070 __STATIC_INLINE uint32_t GIC_GetBinaryPoint(void)
1072 return (uint32_t)GICInterface->C_BPR;
1075 /** Get the status for a given interrupt.
1076 * \param IRQn The interrupt to get status for.
1077 * \return 0 - not pending/active, 1 - pending, 2 - active, 3 - pending and active
1079 __STATIC_INLINE uint32_t GIC_GetIRQStatus(IRQn_Type IRQn)
1081 uint32_t pending, active;
1083 active = ((GICDistributor->D_ISACTIVER[IRQn / 32]) >> (IRQn % 32)) & 0x1;
1084 pending =((GICDistributor->D_ISPENDR[IRQn / 32]) >> (IRQn % 32)) & 0x1;
1086 return ((active<<1) | pending);
1089 /** Generate a software interrupt using GIC's \ref GICDistributor_Type::D_SGIR "D_SGIR" register.
1090 * \param IRQn Software interrupt to be generated.
1091 * \param target_list List of CPUs the software interrupt should be forwarded to.
1092 * \param filter_list Filter to be applied to determin interrupt receivers.
1094 __STATIC_INLINE void GIC_SendSGI(IRQn_Type IRQn, uint32_t target_list, uint32_t filter_list)
1096 GICDistributor->D_SGIR = ((filter_list & 0x3) << 24) | ((target_list & 0xff) << 16) | (IRQn & 0xf);
1099 /** Get the interrupt number of the highest interrupt pending from CPU's \ref GICInterface_Type::C_HPPIR "C_HPPIR" register.
1100 * \return GICInterface_Type::C_HPPIR
1102 __STATIC_INLINE uint32_t GIC_GetHighPendingIRQ(void)
1104 return GICInterface->C_HPPIR;
1107 /** Provides information about the implementer and revision of the CPU interface.
1108 * \return GICInterface_Type::C_IIDR
1110 __STATIC_INLINE uint32_t GIC_GetInterfaceId(void)
1112 return GICInterface->C_IIDR;
1115 /** Initialitze the interrupt distributor.
1117 __STATIC_INLINE void GIC_DistInit(void)
1120 uint32_t num_irq = 0;
1121 uint32_t priority_field;
1123 //A reset sets all bits in the D_IGROUPRs corresponding to the SPIs to 0,
1124 //configuring all of the interrupts as Secure.
1126 //Disable interrupt forwarding
1127 GIC_DisableDistributor();
1128 //Get the maximum number of interrupts that the GIC supports
1129 num_irq = 32 * ((GIC_DistributorInfo() & 0x1f) + 1);
1131 /* Priority level is implementation defined.
1132 To determine the number of priority bits implemented write 0xFF to an D_IPRIORITYR
1133 priority field and read back the value stored.*/
1134 GIC_SetPriority((IRQn_Type)0, 0xff);
1135 priority_field = GIC_GetPriority((IRQn_Type)0);
1137 for (i = (IRQn_Type)32; i < num_irq; i++)
1139 //Disable the SPI interrupt
1141 //Set level-sensitive and 1-N model
1142 GIC_SetLevelModel(i, 0, 1);
1144 GIC_SetPriority(i, priority_field/2);
1145 //Set target list to CPU0
1146 GIC_SetTarget(i, 1);
1148 //Enable distributor
1149 GIC_EnableDistributor();
1152 /** Initialize the CPU's interrupt interface
1154 __STATIC_INLINE void GIC_CPUInterfaceInit(void)
1157 uint32_t priority_field;
1159 //A reset sets all bits in the D_IGROUPRs corresponding to the SPIs to 0,
1160 //configuring all of the interrupts as Secure.
1162 //Disable interrupt forwarding
1163 GIC_DisableInterface();
1165 /* Priority level is implementation defined.
1166 To determine the number of priority bits implemented write 0xFF to an D_IPRIORITYR
1167 priority field and read back the value stored.*/
1168 GIC_SetPriority((IRQn_Type)0, 0xff);
1169 priority_field = GIC_GetPriority((IRQn_Type)0);
1172 for (i = (IRQn_Type)0; i < 32; i++)
1174 //Set level-sensitive and 1-N model for PPI
1176 GIC_SetLevelModel(i, 0, 1);
1177 //Disable SGI and PPI interrupts
1180 GIC_SetPriority(i, priority_field/2);
1183 GIC_EnableInterface();
1184 //Set binary point to 0
1185 GIC_SetBinaryPoint(0);
1187 GIC_SetInterfacePriorityMask(0xff);
1190 /** Initialize and enable the GIC
1192 __STATIC_INLINE void GIC_Enable(void)
1195 GIC_CPUInterfaceInit(); //per CPU
1199 /* ########################## Generic Timer functions ############################ */
1200 #if (__TIM_PRESENT == 1U) || defined(DOXYGEN)
1202 /* PL1 Physical Timer */
1203 #if (__CORTEX_A == 7U) || defined(DOXYGEN)
1205 /** \brief Physical Timer Control register */
1210 uint32_t ENABLE:1; /*!< \brief bit: 0 Enables the timer. */
1211 uint32_t IMASK:1; /*!< \brief bit: 1 Timer output signal mask bit. */
1212 uint32_t ISTATUS:1; /*!< \brief bit: 2 The status of the timer. */
1213 uint32_t _reserved0:29; /*!< \brief bit: 3..31 Reserved */
1214 } b; /*!< \brief Structure used for bit access */
1215 uint32_t w; /*!< \brief Type used for word access */
1218 /** Configures the frequency the timer shall run at.
1219 * \param value The timer frequency in Hz.
1221 __STATIC_INLINE void PL1_SetCounterFrequency(uint32_t value) {
1222 __set_CNTFRQ(value);
1226 /** Sets the reset value of the timer.
1227 * \param value The value the timer is loaded with.
1229 __STATIC_INLINE void PL1_SetLoadValue(uint32_t value) {
1230 __set_CNTP_TVAL(value);
1234 /** Get the current counter value.
1235 * \return Current counter value.
1237 __STATIC_INLINE uint32_t PL1_GetCurrentValue() {
1238 return(__get_CNTP_TVAL());
1241 /** Configure the timer by setting the control value.
1242 * \param value New timer control value.
1244 __STATIC_INLINE void PL1_SetControl(uint32_t value) {
1245 __set_CNTP_CTL(value);
1250 #elif ((__CORTEX_A == 5U) || (__CORTEX_A == 9U)) || defined(DOXYGEN)
1251 /** Set the load value to timers \ref Timer_Type::LOAD "LOAD" register.
1252 * \param value The load value to be set.
1254 __STATIC_INLINE void PTIM_SetLoadValue(uint32_t value) {
1258 /** Get the load value from timers \ref Timer_Type::LOAD "LOAD" register.
1259 * \return Timer_Type::LOAD
1261 __STATIC_INLINE uint32_t PTIM_GetLoadValue() {
1265 /** Get current counter value from timers \ref Timer_Type::COUNTER "COUNTER" register.
1266 * \result Timer_Type::COUNTER
1268 __STATIC_INLINE uint32_t PTIM_GetCurrentValue() {
1269 return(PTIM->COUNTER);
1272 /** Configure the timer using its \ref Timer_Type::CONTROL "CONTROL" register.
1273 * \param value The new configuration value to be set.
1275 __STATIC_INLINE void PTIM_SetControl(uint32_t value) {
1276 PTIM->CONTROL = value;
1279 /** Get the current timer configuration from its \ref Timer_Type::CONTROL "CONTROL" register.
1280 * \return Timer_Type::CONTROL
1282 __STATIC_INLINE uint32_t PTIM_GetControl(void) {
1283 return(PTIM->CONTROL);
1286 /** Clears the event flag in timers \ref Timer_Type::ISR "ISR" register.
1288 __STATIC_INLINE void PTIM_ClearEventFlag(void) {
1294 /* ########################## MMU functions ###################################### */
1296 #define SECTION_DESCRIPTOR (0x2)
1297 #define SECTION_MASK (0xFFFFFFFC)
1299 #define SECTION_TEXCB_MASK (0xFFFF8FF3)
1300 #define SECTION_B_SHIFT (2)
1301 #define SECTION_C_SHIFT (3)
1302 #define SECTION_TEX0_SHIFT (12)
1303 #define SECTION_TEX1_SHIFT (13)
1304 #define SECTION_TEX2_SHIFT (14)
1306 #define SECTION_XN_MASK (0xFFFFFFEF)
1307 #define SECTION_XN_SHIFT (4)
1309 #define SECTION_DOMAIN_MASK (0xFFFFFE1F)
1310 #define SECTION_DOMAIN_SHIFT (5)
1312 #define SECTION_P_MASK (0xFFFFFDFF)
1313 #define SECTION_P_SHIFT (9)
1315 #define SECTION_AP_MASK (0xFFFF73FF)
1316 #define SECTION_AP_SHIFT (10)
1317 #define SECTION_AP2_SHIFT (15)
1319 #define SECTION_S_MASK (0xFFFEFFFF)
1320 #define SECTION_S_SHIFT (16)
1322 #define SECTION_NG_MASK (0xFFFDFFFF)
1323 #define SECTION_NG_SHIFT (17)
1325 #define SECTION_NS_MASK (0xFFF7FFFF)
1326 #define SECTION_NS_SHIFT (19)
1328 #define PAGE_L1_DESCRIPTOR (0x1)
1329 #define PAGE_L1_MASK (0xFFFFFFFC)
1331 #define PAGE_L2_4K_DESC (0x2)
1332 #define PAGE_L2_4K_MASK (0xFFFFFFFD)
1334 #define PAGE_L2_64K_DESC (0x1)
1335 #define PAGE_L2_64K_MASK (0xFFFFFFFC)
1337 #define PAGE_4K_TEXCB_MASK (0xFFFFFE33)
1338 #define PAGE_4K_B_SHIFT (2)
1339 #define PAGE_4K_C_SHIFT (3)
1340 #define PAGE_4K_TEX0_SHIFT (6)
1341 #define PAGE_4K_TEX1_SHIFT (7)
1342 #define PAGE_4K_TEX2_SHIFT (8)
1344 #define PAGE_64K_TEXCB_MASK (0xFFFF8FF3)
1345 #define PAGE_64K_B_SHIFT (2)
1346 #define PAGE_64K_C_SHIFT (3)
1347 #define PAGE_64K_TEX0_SHIFT (12)
1348 #define PAGE_64K_TEX1_SHIFT (13)
1349 #define PAGE_64K_TEX2_SHIFT (14)
1351 #define PAGE_TEXCB_MASK (0xFFFF8FF3)
1352 #define PAGE_B_SHIFT (2)
1353 #define PAGE_C_SHIFT (3)
1354 #define PAGE_TEX_SHIFT (12)
1356 #define PAGE_XN_4K_MASK (0xFFFFFFFE)
1357 #define PAGE_XN_4K_SHIFT (0)
1358 #define PAGE_XN_64K_MASK (0xFFFF7FFF)
1359 #define PAGE_XN_64K_SHIFT (15)
1361 #define PAGE_DOMAIN_MASK (0xFFFFFE1F)
1362 #define PAGE_DOMAIN_SHIFT (5)
1364 #define PAGE_P_MASK (0xFFFFFDFF)
1365 #define PAGE_P_SHIFT (9)
1367 #define PAGE_AP_MASK (0xFFFFFDCF)
1368 #define PAGE_AP_SHIFT (4)
1369 #define PAGE_AP2_SHIFT (9)
1371 #define PAGE_S_MASK (0xFFFFFBFF)
1372 #define PAGE_S_SHIFT (10)
1374 #define PAGE_NG_MASK (0xFFFFF7FF)
1375 #define PAGE_NG_SHIFT (11)
1377 #define PAGE_NS_MASK (0xFFFFFFF7)
1378 #define PAGE_NS_SHIFT (3)
1380 #define OFFSET_1M (0x00100000)
1381 #define OFFSET_64K (0x00010000)
1382 #define OFFSET_4K (0x00001000)
1384 #define DESCRIPTOR_FAULT (0x00000000)
1386 /* Attributes enumerations */
1388 /* Region size attributes */
1394 } mmu_region_size_Type;
1396 /* Region type attributes */
1406 /* Region cacheability attributes */
1413 } mmu_cacheability_Type;
1415 /* Region parity check attributes */
1420 } mmu_ecc_check_Type;
1422 /* Region execution attributes */
1429 /* Region global attributes */
1436 /* Region shareability attributes */
1443 /* Region security attributes */
1450 /* Region access attributes */
1458 /* Memory Region definition */
1459 typedef struct RegionStruct {
1460 mmu_region_size_Type rg_t;
1461 mmu_memory_Type mem_t;
1463 mmu_cacheability_Type inner_norm_t;
1464 mmu_cacheability_Type outer_norm_t;
1465 mmu_ecc_check_Type e_t;
1466 mmu_execute_Type xn_t;
1467 mmu_global_Type g_t;
1468 mmu_secure_Type sec_t;
1469 mmu_access_Type priv_t;
1470 mmu_access_Type user_t;
1471 mmu_shared_Type sh_t;
1473 } mmu_region_attributes_Type;
1475 //Following macros define the descriptors and attributes
1476 //Sect_Normal. Outer & inner wb/wa, non-shareable, executable, rw, domain 0
1477 #define section_normal(descriptor_l1, region) region.rg_t = SECTION; \
1478 region.domain = 0x0; \
1479 region.e_t = ECC_DISABLED; \
1480 region.g_t = GLOBAL; \
1481 region.inner_norm_t = WB_WA; \
1482 region.outer_norm_t = WB_WA; \
1483 region.mem_t = NORMAL; \
1484 region.sec_t = SECURE; \
1485 region.xn_t = EXECUTE; \
1486 region.priv_t = RW; \
1487 region.user_t = RW; \
1488 region.sh_t = NON_SHARED; \
1489 MMU_GetSectionDescriptor(&descriptor_l1, region);
1491 //Sect_Normal_Cod. Outer & inner wb/wa, non-shareable, executable, ro, domain 0
1492 #define section_normal_cod(descriptor_l1, region) region.rg_t = SECTION; \
1493 region.domain = 0x0; \
1494 region.e_t = ECC_DISABLED; \
1495 region.g_t = GLOBAL; \
1496 region.inner_norm_t = WB_WA; \
1497 region.outer_norm_t = WB_WA; \
1498 region.mem_t = NORMAL; \
1499 region.sec_t = SECURE; \
1500 region.xn_t = EXECUTE; \
1501 region.priv_t = READ; \
1502 region.user_t = READ; \
1503 region.sh_t = NON_SHARED; \
1504 MMU_GetSectionDescriptor(&descriptor_l1, region);
1506 //Sect_Normal_RO. Sect_Normal_Cod, but not executable
1507 #define section_normal_ro(descriptor_l1, region) region.rg_t = SECTION; \
1508 region.domain = 0x0; \
1509 region.e_t = ECC_DISABLED; \
1510 region.g_t = GLOBAL; \
1511 region.inner_norm_t = WB_WA; \
1512 region.outer_norm_t = WB_WA; \
1513 region.mem_t = NORMAL; \
1514 region.sec_t = SECURE; \
1515 region.xn_t = NON_EXECUTE; \
1516 region.priv_t = READ; \
1517 region.user_t = READ; \
1518 region.sh_t = NON_SHARED; \
1519 MMU_GetSectionDescriptor(&descriptor_l1, region);
1521 //Sect_Normal_RW. Sect_Normal_Cod, but writeable and not executable
1522 #define section_normal_rw(descriptor_l1, region) region.rg_t = SECTION; \
1523 region.domain = 0x0; \
1524 region.e_t = ECC_DISABLED; \
1525 region.g_t = GLOBAL; \
1526 region.inner_norm_t = WB_WA; \
1527 region.outer_norm_t = WB_WA; \
1528 region.mem_t = NORMAL; \
1529 region.sec_t = SECURE; \
1530 region.xn_t = NON_EXECUTE; \
1531 region.priv_t = RW; \
1532 region.user_t = RW; \
1533 region.sh_t = NON_SHARED; \
1534 MMU_GetSectionDescriptor(&descriptor_l1, region);
1535 //Sect_SO. Strongly-ordered (therefore shareable), not executable, rw, domain 0, base addr 0
1536 #define section_so(descriptor_l1, region) region.rg_t = SECTION; \
1537 region.domain = 0x0; \
1538 region.e_t = ECC_DISABLED; \
1539 region.g_t = GLOBAL; \
1540 region.inner_norm_t = NON_CACHEABLE; \
1541 region.outer_norm_t = NON_CACHEABLE; \
1542 region.mem_t = STRONGLY_ORDERED; \
1543 region.sec_t = SECURE; \
1544 region.xn_t = NON_EXECUTE; \
1545 region.priv_t = RW; \
1546 region.user_t = RW; \
1547 region.sh_t = NON_SHARED; \
1548 MMU_GetSectionDescriptor(&descriptor_l1, region);
1550 //Sect_Device_RO. Device, non-shareable, non-executable, ro, domain 0, base addr 0
1551 #define section_device_ro(descriptor_l1, region) region.rg_t = SECTION; \
1552 region.domain = 0x0; \
1553 region.e_t = ECC_DISABLED; \
1554 region.g_t = GLOBAL; \
1555 region.inner_norm_t = NON_CACHEABLE; \
1556 region.outer_norm_t = NON_CACHEABLE; \
1557 region.mem_t = STRONGLY_ORDERED; \
1558 region.sec_t = SECURE; \
1559 region.xn_t = NON_EXECUTE; \
1560 region.priv_t = READ; \
1561 region.user_t = READ; \
1562 region.sh_t = NON_SHARED; \
1563 MMU_GetSectionDescriptor(&descriptor_l1, region);
1565 //Sect_Device_RW. Sect_Device_RO, but writeable
1566 #define section_device_rw(descriptor_l1, region) region.rg_t = SECTION; \
1567 region.domain = 0x0; \
1568 region.e_t = ECC_DISABLED; \
1569 region.g_t = GLOBAL; \
1570 region.inner_norm_t = NON_CACHEABLE; \
1571 region.outer_norm_t = NON_CACHEABLE; \
1572 region.mem_t = STRONGLY_ORDERED; \
1573 region.sec_t = SECURE; \
1574 region.xn_t = NON_EXECUTE; \
1575 region.priv_t = RW; \
1576 region.user_t = RW; \
1577 region.sh_t = NON_SHARED; \
1578 MMU_GetSectionDescriptor(&descriptor_l1, region);
1579 //Page_4k_Device_RW. Shared device, not executable, rw, domain 0
1580 #define page4k_device_rw(descriptor_l1, descriptor_l2, region) region.rg_t = PAGE_4k; \
1581 region.domain = 0x0; \
1582 region.e_t = ECC_DISABLED; \
1583 region.g_t = GLOBAL; \
1584 region.inner_norm_t = NON_CACHEABLE; \
1585 region.outer_norm_t = NON_CACHEABLE; \
1586 region.mem_t = SHARED_DEVICE; \
1587 region.sec_t = SECURE; \
1588 region.xn_t = NON_EXECUTE; \
1589 region.priv_t = RW; \
1590 region.user_t = RW; \
1591 region.sh_t = NON_SHARED; \
1592 MMU_GetPageDescriptor(&descriptor_l1, &descriptor_l2, region);
1594 //Page_64k_Device_RW. Shared device, not executable, rw, domain 0
1595 #define page64k_device_rw(descriptor_l1, descriptor_l2, region) region.rg_t = PAGE_64k; \
1596 region.domain = 0x0; \
1597 region.e_t = ECC_DISABLED; \
1598 region.g_t = GLOBAL; \
1599 region.inner_norm_t = NON_CACHEABLE; \
1600 region.outer_norm_t = NON_CACHEABLE; \
1601 region.mem_t = SHARED_DEVICE; \
1602 region.sec_t = SECURE; \
1603 region.xn_t = NON_EXECUTE; \
1604 region.priv_t = RW; \
1605 region.user_t = RW; \
1606 region.sh_t = NON_SHARED; \
1607 MMU_GetPageDescriptor(&descriptor_l1, &descriptor_l2, region);
1609 /** \brief Set section execution-never attribute
1611 \param [out] descriptor_l1 L1 descriptor.
1612 \param [in] xn Section execution-never attribute : EXECUTE , NON_EXECUTE.
1616 __STATIC_INLINE int MMU_XNSection(uint32_t *descriptor_l1, mmu_execute_Type xn)
1618 *descriptor_l1 &= SECTION_XN_MASK;
1619 *descriptor_l1 |= ((xn & 0x1) << SECTION_XN_SHIFT);
1623 /** \brief Set section domain
1625 \param [out] descriptor_l1 L1 descriptor.
1626 \param [in] domain Section domain
1630 __STATIC_INLINE int MMU_DomainSection(uint32_t *descriptor_l1, uint8_t domain)
1632 *descriptor_l1 &= SECTION_DOMAIN_MASK;
1633 *descriptor_l1 |= ((domain & 0xF) << SECTION_DOMAIN_SHIFT);
1637 /** \brief Set section parity check
1639 \param [out] descriptor_l1 L1 descriptor.
1640 \param [in] p_bit Parity check: ECC_DISABLED, ECC_ENABLED
1644 __STATIC_INLINE int MMU_PSection(uint32_t *descriptor_l1, mmu_ecc_check_Type p_bit)
1646 *descriptor_l1 &= SECTION_P_MASK;
1647 *descriptor_l1 |= ((p_bit & 0x1) << SECTION_P_SHIFT);
1651 /** \brief Set section access privileges
1653 \param [out] descriptor_l1 L1 descriptor.
1654 \param [in] user User Level Access: NO_ACCESS, RW, READ
1655 \param [in] priv Privilege Level Access: NO_ACCESS, RW, READ
1656 \param [in] afe Access flag enable
1660 __STATIC_INLINE int MMU_APSection(uint32_t *descriptor_l1, mmu_access_Type user, mmu_access_Type priv, uint32_t afe)
1664 if (afe == 0) { //full access
1665 if ((priv == NO_ACCESS) && (user == NO_ACCESS)) { ap = 0x0; }
1666 else if ((priv == RW) && (user == NO_ACCESS)) { ap = 0x1; }
1667 else if ((priv == RW) && (user == READ)) { ap = 0x2; }
1668 else if ((priv == RW) && (user == RW)) { ap = 0x3; }
1669 else if ((priv == READ) && (user == NO_ACCESS)) { ap = 0x5; }
1670 else if ((priv == READ) && (user == READ)) { ap = 0x7; }
1673 else { //Simplified access
1674 if ((priv == RW) && (user == NO_ACCESS)) { ap = 0x1; }
1675 else if ((priv == RW) && (user == RW)) { ap = 0x3; }
1676 else if ((priv == READ) && (user == NO_ACCESS)) { ap = 0x5; }
1677 else if ((priv == READ) && (user == READ)) { ap = 0x7; }
1680 *descriptor_l1 &= SECTION_AP_MASK;
1681 *descriptor_l1 |= (ap & 0x3) << SECTION_AP_SHIFT;
1682 *descriptor_l1 |= ((ap & 0x4)>>2) << SECTION_AP2_SHIFT;
1687 /** \brief Set section shareability
1689 \param [out] descriptor_l1 L1 descriptor.
1690 \param [in] s_bit Section shareability: NON_SHARED, SHARED
1694 __STATIC_INLINE int MMU_SharedSection(uint32_t *descriptor_l1, mmu_shared_Type s_bit)
1696 *descriptor_l1 &= SECTION_S_MASK;
1697 *descriptor_l1 |= ((s_bit & 0x1) << SECTION_S_SHIFT);
1701 /** \brief Set section Global attribute
1703 \param [out] descriptor_l1 L1 descriptor.
1704 \param [in] g_bit Section attribute: GLOBAL, NON_GLOBAL
1708 __STATIC_INLINE int MMU_GlobalSection(uint32_t *descriptor_l1, mmu_global_Type g_bit)
1710 *descriptor_l1 &= SECTION_NG_MASK;
1711 *descriptor_l1 |= ((g_bit & 0x1) << SECTION_NG_SHIFT);
1715 /** \brief Set section Security attribute
1717 \param [out] descriptor_l1 L1 descriptor.
1718 \param [in] s_bit Section Security attribute: SECURE, NON_SECURE
1722 __STATIC_INLINE int MMU_SecureSection(uint32_t *descriptor_l1, mmu_secure_Type s_bit)
1724 *descriptor_l1 &= SECTION_NS_MASK;
1725 *descriptor_l1 |= ((s_bit & 0x1) << SECTION_NS_SHIFT);
1729 /* Page 4k or 64k */
1730 /** \brief Set 4k/64k page execution-never attribute
1732 \param [out] descriptor_l2 L2 descriptor.
1733 \param [in] xn Page execution-never attribute : EXECUTE , NON_EXECUTE.
1734 \param [in] page Page size: PAGE_4k, PAGE_64k,
1738 __STATIC_INLINE int MMU_XNPage(uint32_t *descriptor_l2, mmu_execute_Type xn, mmu_region_size_Type page)
1740 if (page == PAGE_4k)
1742 *descriptor_l2 &= PAGE_XN_4K_MASK;
1743 *descriptor_l2 |= ((xn & 0x1) << PAGE_XN_4K_SHIFT);
1747 *descriptor_l2 &= PAGE_XN_64K_MASK;
1748 *descriptor_l2 |= ((xn & 0x1) << PAGE_XN_64K_SHIFT);
1753 /** \brief Set 4k/64k page domain
1755 \param [out] descriptor_l1 L1 descriptor.
1756 \param [in] domain Page domain
1760 __STATIC_INLINE int MMU_DomainPage(uint32_t *descriptor_l1, uint8_t domain)
1762 *descriptor_l1 &= PAGE_DOMAIN_MASK;
1763 *descriptor_l1 |= ((domain & 0xf) << PAGE_DOMAIN_SHIFT);
1767 /** \brief Set 4k/64k page parity check
1769 \param [out] descriptor_l1 L1 descriptor.
1770 \param [in] p_bit Parity check: ECC_DISABLED, ECC_ENABLED
1774 __STATIC_INLINE int MMU_PPage(uint32_t *descriptor_l1, mmu_ecc_check_Type p_bit)
1776 *descriptor_l1 &= SECTION_P_MASK;
1777 *descriptor_l1 |= ((p_bit & 0x1) << SECTION_P_SHIFT);
1781 /** \brief Set 4k/64k page access privileges
1783 \param [out] descriptor_l2 L2 descriptor.
1784 \param [in] user User Level Access: NO_ACCESS, RW, READ
1785 \param [in] priv Privilege Level Access: NO_ACCESS, RW, READ
1786 \param [in] afe Access flag enable
1790 __STATIC_INLINE int MMU_APPage(uint32_t *descriptor_l2, mmu_access_Type user, mmu_access_Type priv, uint32_t afe)
1794 if (afe == 0) { //full access
1795 if ((priv == NO_ACCESS) && (user == NO_ACCESS)) { ap = 0x0; }
1796 else if ((priv == RW) && (user == NO_ACCESS)) { ap = 0x1; }
1797 else if ((priv == RW) && (user == READ)) { ap = 0x2; }
1798 else if ((priv == RW) && (user == RW)) { ap = 0x3; }
1799 else if ((priv == READ) && (user == NO_ACCESS)) { ap = 0x5; }
1800 else if ((priv == READ) && (user == READ)) { ap = 0x6; }
1803 else { //Simplified access
1804 if ((priv == RW) && (user == NO_ACCESS)) { ap = 0x1; }
1805 else if ((priv == RW) && (user == RW)) { ap = 0x3; }
1806 else if ((priv == READ) && (user == NO_ACCESS)) { ap = 0x5; }
1807 else if ((priv == READ) && (user == READ)) { ap = 0x7; }
1810 *descriptor_l2 &= PAGE_AP_MASK;
1811 *descriptor_l2 |= (ap & 0x3) << PAGE_AP_SHIFT;
1812 *descriptor_l2 |= ((ap & 0x4)>>2) << PAGE_AP2_SHIFT;
1817 /** \brief Set 4k/64k page shareability
1819 \param [out] descriptor_l2 L2 descriptor.
1820 \param [in] s_bit 4k/64k page shareability: NON_SHARED, SHARED
1824 __STATIC_INLINE int MMU_SharedPage(uint32_t *descriptor_l2, mmu_shared_Type s_bit)
1826 *descriptor_l2 &= PAGE_S_MASK;
1827 *descriptor_l2 |= ((s_bit & 0x1) << PAGE_S_SHIFT);
1831 /** \brief Set 4k/64k page Global attribute
1833 \param [out] descriptor_l2 L2 descriptor.
1834 \param [in] g_bit 4k/64k page attribute: GLOBAL, NON_GLOBAL
1838 __STATIC_INLINE int MMU_GlobalPage(uint32_t *descriptor_l2, mmu_global_Type g_bit)
1840 *descriptor_l2 &= PAGE_NG_MASK;
1841 *descriptor_l2 |= ((g_bit & 0x1) << PAGE_NG_SHIFT);
1845 /** \brief Set 4k/64k page Security attribute
1847 \param [out] descriptor_l1 L1 descriptor.
1848 \param [in] s_bit 4k/64k page Security attribute: SECURE, NON_SECURE
1852 __STATIC_INLINE int MMU_SecurePage(uint32_t *descriptor_l1, mmu_secure_Type s_bit)
1854 *descriptor_l1 &= PAGE_NS_MASK;
1855 *descriptor_l1 |= ((s_bit & 0x1) << PAGE_NS_SHIFT);
1859 /** \brief Set Section memory attributes
1861 \param [out] descriptor_l1 L1 descriptor.
1862 \param [in] mem Section memory type: NORMAL, DEVICE, SHARED_DEVICE, NON_SHARED_DEVICE, STRONGLY_ORDERED
1863 \param [in] outer Outer cacheability: NON_CACHEABLE, WB_WA, WT, WB_NO_WA,
1864 \param [in] inner Inner cacheability: NON_CACHEABLE, WB_WA, WT, WB_NO_WA,
1868 __STATIC_INLINE int MMU_MemorySection(uint32_t *descriptor_l1, mmu_memory_Type mem, mmu_cacheability_Type outer, mmu_cacheability_Type inner)
1870 *descriptor_l1 &= SECTION_TEXCB_MASK;
1872 if (STRONGLY_ORDERED == mem)
1876 else if (SHARED_DEVICE == mem)
1878 *descriptor_l1 |= (1 << SECTION_B_SHIFT);
1880 else if (NON_SHARED_DEVICE == mem)
1882 *descriptor_l1 |= (1 << SECTION_TEX1_SHIFT);
1884 else if (NORMAL == mem)
1886 *descriptor_l1 |= 1 << SECTION_TEX2_SHIFT;
1892 *descriptor_l1 |= (1 << SECTION_B_SHIFT);
1895 *descriptor_l1 |= 1 << SECTION_C_SHIFT;
1898 *descriptor_l1 |= (1 << SECTION_B_SHIFT) | (1 << SECTION_C_SHIFT);
1906 *descriptor_l1 |= (1 << SECTION_TEX0_SHIFT);
1909 *descriptor_l1 |= 1 << SECTION_TEX1_SHIFT;
1912 *descriptor_l1 |= (1 << SECTION_TEX0_SHIFT) | (1 << SECTION_TEX0_SHIFT);
1919 /** \brief Set 4k/64k page memory attributes
1921 \param [out] descriptor_l2 L2 descriptor.
1922 \param [in] mem 4k/64k page memory type: NORMAL, DEVICE, SHARED_DEVICE, NON_SHARED_DEVICE, STRONGLY_ORDERED
1923 \param [in] outer Outer cacheability: NON_CACHEABLE, WB_WA, WT, WB_NO_WA,
1924 \param [in] inner Inner cacheability: NON_CACHEABLE, WB_WA, WT, WB_NO_WA,
1925 \param [in] page Page size
1929 __STATIC_INLINE int MMU_MemoryPage(uint32_t *descriptor_l2, mmu_memory_Type mem, mmu_cacheability_Type outer, mmu_cacheability_Type inner, mmu_region_size_Type page)
1931 *descriptor_l2 &= PAGE_4K_TEXCB_MASK;
1933 if (page == PAGE_64k)
1936 MMU_MemorySection(descriptor_l2, mem, outer, inner);
1940 if (STRONGLY_ORDERED == mem)
1944 else if (SHARED_DEVICE == mem)
1946 *descriptor_l2 |= (1 << PAGE_4K_B_SHIFT);
1948 else if (NON_SHARED_DEVICE == mem)
1950 *descriptor_l2 |= (1 << PAGE_4K_TEX1_SHIFT);
1952 else if (NORMAL == mem)
1954 *descriptor_l2 |= 1 << PAGE_4K_TEX2_SHIFT;
1960 *descriptor_l2 |= (1 << PAGE_4K_B_SHIFT);
1963 *descriptor_l2 |= 1 << PAGE_4K_C_SHIFT;
1966 *descriptor_l2 |= (1 << PAGE_4K_B_SHIFT) | (1 << PAGE_4K_C_SHIFT);
1974 *descriptor_l2 |= (1 << PAGE_4K_TEX0_SHIFT);
1977 *descriptor_l2 |= 1 << PAGE_4K_TEX1_SHIFT;
1980 *descriptor_l2 |= (1 << PAGE_4K_TEX0_SHIFT) | (1 << PAGE_4K_TEX0_SHIFT);
1989 /** \brief Create a L1 section descriptor
1991 \param [out] descriptor L1 descriptor
1992 \param [in] reg Section attributes
1996 __STATIC_INLINE int MMU_GetSectionDescriptor(uint32_t *descriptor, mmu_region_attributes_Type reg)
2000 MMU_MemorySection(descriptor, reg.mem_t, reg.outer_norm_t, reg.inner_norm_t);
2001 MMU_XNSection(descriptor,reg.xn_t);
2002 MMU_DomainSection(descriptor, reg.domain);
2003 MMU_PSection(descriptor, reg.e_t);
2004 MMU_APSection(descriptor, reg.priv_t, reg.user_t, 1);
2005 MMU_SharedSection(descriptor,reg.sh_t);
2006 MMU_GlobalSection(descriptor,reg.g_t);
2007 MMU_SecureSection(descriptor,reg.sec_t);
2008 *descriptor &= SECTION_MASK;
2009 *descriptor |= SECTION_DESCRIPTOR;
2015 /** \brief Create a L1 and L2 4k/64k page descriptor
2017 \param [out] descriptor L1 descriptor
2018 \param [out] descriptor2 L2 descriptor
2019 \param [in] reg 4k/64k page attributes
2023 __STATIC_INLINE int MMU_GetPageDescriptor(uint32_t *descriptor, uint32_t *descriptor2, mmu_region_attributes_Type reg)
2031 MMU_MemoryPage(descriptor2, reg.mem_t, reg.outer_norm_t, reg.inner_norm_t, PAGE_4k);
2032 MMU_XNPage(descriptor2, reg.xn_t, PAGE_4k);
2033 MMU_DomainPage(descriptor, reg.domain);
2034 MMU_PPage(descriptor, reg.e_t);
2035 MMU_APPage(descriptor2, reg.priv_t, reg.user_t, 1);
2036 MMU_SharedPage(descriptor2,reg.sh_t);
2037 MMU_GlobalPage(descriptor2,reg.g_t);
2038 MMU_SecurePage(descriptor,reg.sec_t);
2039 *descriptor &= PAGE_L1_MASK;
2040 *descriptor |= PAGE_L1_DESCRIPTOR;
2041 *descriptor2 &= PAGE_L2_4K_MASK;
2042 *descriptor2 |= PAGE_L2_4K_DESC;
2046 MMU_MemoryPage(descriptor2, reg.mem_t, reg.outer_norm_t, reg.inner_norm_t, PAGE_64k);
2047 MMU_XNPage(descriptor2, reg.xn_t, PAGE_64k);
2048 MMU_DomainPage(descriptor, reg.domain);
2049 MMU_PPage(descriptor, reg.e_t);
2050 MMU_APPage(descriptor2, reg.priv_t, reg.user_t, 1);
2051 MMU_SharedPage(descriptor2,reg.sh_t);
2052 MMU_GlobalPage(descriptor2,reg.g_t);
2053 MMU_SecurePage(descriptor,reg.sec_t);
2054 *descriptor &= PAGE_L1_MASK;
2055 *descriptor |= PAGE_L1_DESCRIPTOR;
2056 *descriptor2 &= PAGE_L2_64K_MASK;
2057 *descriptor2 |= PAGE_L2_64K_DESC;
2068 /** \brief Create a 1MB Section
2070 \param [in] ttb Translation table base address
2071 \param [in] base_address Section base address
2072 \param [in] count Number of sections to create
2073 \param [in] descriptor_l1 L1 descriptor (region attributes)
2076 __STATIC_INLINE void MMU_TTSection(uint32_t *ttb, uint32_t base_address, uint32_t count, uint32_t descriptor_l1)
2082 offset = base_address >> 20;
2083 entry = (base_address & 0xFFF00000) | descriptor_l1;
2088 for (i = 0; i < count; i++ )
2096 /** \brief Create a 4k page entry
2098 \param [in] ttb L1 table base address
2099 \param [in] base_address 4k base address
2100 \param [in] count Number of 4k pages to create
2101 \param [in] descriptor_l1 L1 descriptor (region attributes)
2102 \param [in] ttb_l2 L2 table base address
2103 \param [in] descriptor_l2 L2 descriptor (region attributes)
2106 __STATIC_INLINE void MMU_TTPage4k(uint32_t *ttb, uint32_t base_address, uint32_t count, uint32_t descriptor_l1, uint32_t *ttb_l2, uint32_t descriptor_l2 )
2109 uint32_t offset, offset2;
2110 uint32_t entry, entry2;
2113 offset = base_address >> 20;
2114 entry = ((int)ttb_l2 & 0xFFFFFC00) | descriptor_l1;
2121 offset2 = (base_address & 0xff000) >> 12;
2123 entry2 = (base_address & 0xFFFFF000) | descriptor_l2;
2124 for (i = 0; i < count; i++ )
2128 entry2 += OFFSET_4K;
2132 /** \brief Create a 64k page entry
2134 \param [in] ttb L1 table base address
2135 \param [in] base_address 64k base address
2136 \param [in] count Number of 64k pages to create
2137 \param [in] descriptor_l1 L1 descriptor (region attributes)
2138 \param [in] ttb_l2 L2 table base address
2139 \param [in] descriptor_l2 L2 descriptor (region attributes)
2142 __STATIC_INLINE void MMU_TTPage64k(uint32_t *ttb, uint32_t base_address, uint32_t count, uint32_t descriptor_l1, uint32_t *ttb_l2, uint32_t descriptor_l2 )
2144 uint32_t offset, offset2;
2145 uint32_t entry, entry2;
2149 offset = base_address >> 20;
2150 entry = ((int)ttb_l2 & 0xFFFFFC00) | descriptor_l1;
2157 offset2 = (base_address & 0xff000) >> 12;
2159 entry2 = (base_address & 0xFFFF0000) | descriptor_l2;
2160 for (i = 0; i < count; i++ )
2163 for (j = 0; j < 16; j++)
2168 entry2 += OFFSET_64K;
2172 /** \brief Enable MMU
2174 __STATIC_INLINE void MMU_Enable(void) {
2175 // Set M bit 0 to enable the MMU
2176 // Set AFE bit to enable simplified access permissions model
2177 // Clear TRE bit to disable TEX remap and A bit to disable strict alignment fault checking
2178 __set_SCTLR( (__get_SCTLR() & ~(1 << 28) & ~(1 << 1)) | 1 | (1 << 29));
2182 /** \brief Disable MMU
2184 __STATIC_INLINE void MMU_Disable(void) {
2185 // Clear M bit 0 to disable the MMU
2186 __set_SCTLR( __get_SCTLR() & ~1);
2190 /** \brief Invalidate entire unified TLB
2193 __STATIC_INLINE void MMU_InvalidateTLB(void) {
2195 __DSB(); //ensure completion of the invalidation
2196 __ISB(); //ensure instruction fetch path sees new state
2204 #endif /* __CORE_CA_H_DEPENDANT */
2206 #endif /* __CMSIS_GENERIC */