]> begriffs open source - cmsis/blob - CMSIS/Core_A/Include/core_ca.h
CMSIS-Zone limited to Cortex-M as Cache support for complex Cortex-A/R systems is...
[cmsis] / CMSIS / Core_A / Include / core_ca.h
1 /**************************************************************************//**
2  * @file     core_ca.h
3  * @brief    CMSIS Cortex-A Core Peripheral Access Layer Header File
4  * @version  V1.0.2
5  * @date     12. November 2018
6  ******************************************************************************/
7 /*
8  * Copyright (c) 2009-2018 ARM Limited. All rights reserved.
9  *
10  * SPDX-License-Identifier: Apache-2.0
11  *
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
15  *
16  * www.apache.org/licenses/LICENSE-2.0
17  *
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.
23  */
24
25 #if   defined ( __ICCARM__ )
26   #pragma system_include         /* treat file as system include file for MISRA check */
27 #elif defined (__clang__)
28   #pragma clang system_header   /* treat file as system include file */
29 #endif
30
31 #ifndef __CORE_CA_H_GENERIC
32 #define __CORE_CA_H_GENERIC
33
34 #ifdef __cplusplus
35  extern "C" {
36 #endif
37
38 /*******************************************************************************
39  *                 CMSIS definitions
40  ******************************************************************************/
41
42 /*  CMSIS CA definitions */
43 #define __CA_CMSIS_VERSION_MAIN  (1U)                                      /*!< \brief [31:16] CMSIS-Core(A) main version   */
44 #define __CA_CMSIS_VERSION_SUB   (1U)                                      /*!< \brief [15:0]  CMSIS-Core(A) sub version    */
45 #define __CA_CMSIS_VERSION       ((__CA_CMSIS_VERSION_MAIN << 16U) | \
46                                    __CA_CMSIS_VERSION_SUB          )       /*!< \brief CMSIS-Core(A) version number         */
47
48 #if defined ( __CC_ARM )
49   #if defined __TARGET_FPU_VFP
50     #if (__FPU_PRESENT == 1)
51       #define __FPU_USED       1U
52     #else
53       #warning "Compiler generates FPU instructions for a device without an FPU (check __FPU_PRESENT)"
54       #define __FPU_USED       0U
55     #endif
56   #else
57     #define __FPU_USED         0U
58   #endif
59
60 #elif defined (__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050)
61   #if defined __ARM_FP
62     #if defined (__FPU_PRESENT) && (__FPU_PRESENT == 1U)
63       #define __FPU_USED       1U
64     #else
65       #warning "Compiler generates FPU instructions for a device without an FPU (check __FPU_PRESENT)"
66       #define __FPU_USED       0U
67     #endif
68   #else
69     #define __FPU_USED         0U
70   #endif
71
72 #elif defined ( __ICCARM__ )
73   #if defined __ARMVFP__
74     #if (__FPU_PRESENT == 1)
75       #define __FPU_USED       1U
76     #else
77       #warning "Compiler generates FPU instructions for a device without an FPU (check __FPU_PRESENT)"
78       #define __FPU_USED       0U
79     #endif
80   #else
81     #define __FPU_USED         0U
82   #endif
83
84 #elif defined ( __TMS470__ )
85   #if defined __TI_VFP_SUPPORT__
86     #if (__FPU_PRESENT == 1)
87       #define __FPU_USED       1U
88     #else
89       #warning "Compiler generates FPU instructions for a device without an FPU (check __FPU_PRESENT)"
90       #define __FPU_USED       0U
91     #endif
92   #else
93     #define __FPU_USED         0U
94   #endif
95
96 #elif defined ( __GNUC__ )
97   #if defined (__VFP_FP__) && !defined(__SOFTFP__)
98     #if (__FPU_PRESENT == 1)
99       #define __FPU_USED       1U
100     #else
101       #warning "Compiler generates FPU instructions for a device without an FPU (check __FPU_PRESENT)"
102       #define __FPU_USED       0U
103     #endif
104   #else
105     #define __FPU_USED         0U
106   #endif
107
108 #elif defined ( __TASKING__ )
109   #if defined __FPU_VFP__
110     #if (__FPU_PRESENT == 1)
111       #define __FPU_USED       1U
112     #else
113       #error "Compiler generates FPU instructions for a device without an FPU (check __FPU_PRESENT)"
114       #define __FPU_USED       0U
115     #endif
116   #else
117     #define __FPU_USED         0U
118   #endif
119 #endif
120
121 #include "cmsis_compiler.h"               /* CMSIS compiler specific defines */
122
123 #ifdef __cplusplus
124 }
125 #endif
126
127 #endif /* __CORE_CA_H_GENERIC */
128
129 #ifndef __CMSIS_GENERIC
130
131 #ifndef __CORE_CA_H_DEPENDANT
132 #define __CORE_CA_H_DEPENDANT
133
134 #ifdef __cplusplus
135  extern "C" {
136 #endif
137
138  /* check device defines and use defaults */
139 #if defined __CHECK_DEVICE_DEFINES
140   #ifndef __CA_REV
141     #define __CA_REV              0x0000U
142     #warning "__CA_REV not defined in device header file; using default!"
143   #endif
144   
145   #ifndef __FPU_PRESENT
146     #define __FPU_PRESENT             0U
147     #warning "__FPU_PRESENT not defined in device header file; using default!"
148   #endif
149     
150   #ifndef __GIC_PRESENT
151     #define __GIC_PRESENT             1U
152     #warning "__GIC_PRESENT not defined in device header file; using default!"
153   #endif
154   
155   #ifndef __TIM_PRESENT
156     #define __TIM_PRESENT             1U
157     #warning "__TIM_PRESENT not defined in device header file; using default!"
158   #endif
159   
160   #ifndef __L2C_PRESENT
161     #define __L2C_PRESENT             0U
162     #warning "__L2C_PRESENT not defined in device header file; using default!"
163   #endif
164 #endif
165
166 /* IO definitions (access restrictions to peripheral registers) */
167 #ifdef __cplusplus
168   #define   __I     volatile             /*!< \brief Defines 'read only' permissions */
169 #else
170   #define   __I     volatile const       /*!< \brief Defines 'read only' permissions */
171 #endif
172 #define     __O     volatile             /*!< \brief Defines 'write only' permissions */
173 #define     __IO    volatile             /*!< \brief Defines 'read / write' permissions */
174
175 /* following defines should be used for structure members */
176 #define     __IM     volatile const      /*!< \brief Defines 'read only' structure member permissions */
177 #define     __OM     volatile            /*!< \brief Defines 'write only' structure member permissions */
178 #define     __IOM    volatile            /*!< \brief Defines 'read / write' structure member permissions */
179 #define RESERVED(N, T) T RESERVED##N;    // placeholder struct members used for "reserved" areas
180
181  /*******************************************************************************
182   *                 Register Abstraction
183    Core Register contain:
184    - CPSR
185    - CP15 Registers
186    - L2C-310 Cache Controller
187    - Generic Interrupt Controller Distributor
188    - Generic Interrupt Controller Interface
189   ******************************************************************************/
190
191 /* Core Register CPSR */
192 typedef union
193 {
194   struct
195   {
196     uint32_t M:5;                        /*!< \brief bit:  0.. 4  Mode field */
197     uint32_t T:1;                        /*!< \brief bit:      5  Thumb execution state bit */
198     uint32_t F:1;                        /*!< \brief bit:      6  FIQ mask bit */
199     uint32_t I:1;                        /*!< \brief bit:      7  IRQ mask bit */
200     uint32_t A:1;                        /*!< \brief bit:      8  Asynchronous abort mask bit */
201     uint32_t E:1;                        /*!< \brief bit:      9  Endianness execution state bit */
202     uint32_t IT1:6;                      /*!< \brief bit: 10..15  If-Then execution state bits 2-7 */
203     uint32_t GE:4;                       /*!< \brief bit: 16..19  Greater than or Equal flags */
204     RESERVED(0:4, uint32_t)              
205     uint32_t J:1;                        /*!< \brief bit:     24  Jazelle bit */
206     uint32_t IT0:2;                      /*!< \brief bit: 25..26  If-Then execution state bits 0-1 */
207     uint32_t Q:1;                        /*!< \brief bit:     27  Saturation condition flag */
208     uint32_t V:1;                        /*!< \brief bit:     28  Overflow condition code flag */
209     uint32_t C:1;                        /*!< \brief bit:     29  Carry condition code flag */
210     uint32_t Z:1;                        /*!< \brief bit:     30  Zero condition code flag */
211     uint32_t N:1;                        /*!< \brief bit:     31  Negative condition code flag */
212   } b;                                   /*!< \brief Structure used for bit  access */
213   uint32_t w;                            /*!< \brief Type      used for word access */
214 } CPSR_Type;
215
216
217
218 /* CPSR Register Definitions */
219 #define CPSR_N_Pos                       31U                                    /*!< \brief CPSR: N Position */
220 #define CPSR_N_Msk                       (1UL << CPSR_N_Pos)                    /*!< \brief CPSR: N Mask */
221
222 #define CPSR_Z_Pos                       30U                                    /*!< \brief CPSR: Z Position */
223 #define CPSR_Z_Msk                       (1UL << CPSR_Z_Pos)                    /*!< \brief CPSR: Z Mask */
224
225 #define CPSR_C_Pos                       29U                                    /*!< \brief CPSR: C Position */
226 #define CPSR_C_Msk                       (1UL << CPSR_C_Pos)                    /*!< \brief CPSR: C Mask */
227
228 #define CPSR_V_Pos                       28U                                    /*!< \brief CPSR: V Position */
229 #define CPSR_V_Msk                       (1UL << CPSR_V_Pos)                    /*!< \brief CPSR: V Mask */
230
231 #define CPSR_Q_Pos                       27U                                    /*!< \brief CPSR: Q Position */
232 #define CPSR_Q_Msk                       (1UL << CPSR_Q_Pos)                    /*!< \brief CPSR: Q Mask */
233
234 #define CPSR_IT0_Pos                     25U                                    /*!< \brief CPSR: IT0 Position */
235 #define CPSR_IT0_Msk                     (3UL << CPSR_IT0_Pos)                  /*!< \brief CPSR: IT0 Mask */
236
237 #define CPSR_J_Pos                       24U                                    /*!< \brief CPSR: J Position */
238 #define CPSR_J_Msk                       (1UL << CPSR_J_Pos)                    /*!< \brief CPSR: J Mask */
239
240 #define CPSR_GE_Pos                      16U                                    /*!< \brief CPSR: GE Position */
241 #define CPSR_GE_Msk                      (0xFUL << CPSR_GE_Pos)                 /*!< \brief CPSR: GE Mask */
242
243 #define CPSR_IT1_Pos                     10U                                    /*!< \brief CPSR: IT1 Position */
244 #define CPSR_IT1_Msk                     (0x3FUL << CPSR_IT1_Pos)               /*!< \brief CPSR: IT1 Mask */
245
246 #define CPSR_E_Pos                       9U                                     /*!< \brief CPSR: E Position */
247 #define CPSR_E_Msk                       (1UL << CPSR_E_Pos)                    /*!< \brief CPSR: E Mask */
248
249 #define CPSR_A_Pos                       8U                                     /*!< \brief CPSR: A Position */
250 #define CPSR_A_Msk                       (1UL << CPSR_A_Pos)                    /*!< \brief CPSR: A Mask */
251
252 #define CPSR_I_Pos                       7U                                     /*!< \brief CPSR: I Position */
253 #define CPSR_I_Msk                       (1UL << CPSR_I_Pos)                    /*!< \brief CPSR: I Mask */
254
255 #define CPSR_F_Pos                       6U                                     /*!< \brief CPSR: F Position */
256 #define CPSR_F_Msk                       (1UL << CPSR_F_Pos)                    /*!< \brief CPSR: F Mask */
257
258 #define CPSR_T_Pos                       5U                                     /*!< \brief CPSR: T Position */
259 #define CPSR_T_Msk                       (1UL << CPSR_T_Pos)                    /*!< \brief CPSR: T Mask */
260
261 #define CPSR_M_Pos                       0U                                     /*!< \brief CPSR: M Position */
262 #define CPSR_M_Msk                       (0x1FUL << CPSR_M_Pos)                 /*!< \brief CPSR: M Mask */
263
264 #define CPSR_M_USR                       0x10U                                  /*!< \brief CPSR: M User mode (PL0) */
265 #define CPSR_M_FIQ                       0x11U                                  /*!< \brief CPSR: M Fast Interrupt mode (PL1) */
266 #define CPSR_M_IRQ                       0x12U                                  /*!< \brief CPSR: M Interrupt mode (PL1) */
267 #define CPSR_M_SVC                       0x13U                                  /*!< \brief CPSR: M Supervisor mode (PL1) */
268 #define CPSR_M_MON                       0x16U                                  /*!< \brief CPSR: M Monitor mode (PL1) */
269 #define CPSR_M_ABT                       0x17U                                  /*!< \brief CPSR: M Abort mode (PL1) */
270 #define CPSR_M_HYP                       0x1AU                                  /*!< \brief CPSR: M Hypervisor mode (PL2) */
271 #define CPSR_M_UND                       0x1BU                                  /*!< \brief CPSR: M Undefined mode (PL1) */
272 #define CPSR_M_SYS                       0x1FU                                  /*!< \brief CPSR: M System mode (PL1) */
273
274 /* CP15 Register SCTLR */
275 typedef union
276 {
277   struct
278   {
279     uint32_t M:1;                        /*!< \brief bit:     0  MMU enable */
280     uint32_t A:1;                        /*!< \brief bit:     1  Alignment check enable */
281     uint32_t C:1;                        /*!< \brief bit:     2  Cache enable */
282     RESERVED(0:2, uint32_t)              
283     uint32_t CP15BEN:1;                  /*!< \brief bit:     5  CP15 barrier enable */
284     RESERVED(1:1, uint32_t)              
285     uint32_t B:1;                        /*!< \brief bit:     7  Endianness model */
286     RESERVED(2:2, uint32_t)              
287     uint32_t SW:1;                       /*!< \brief bit:    10  SWP and SWPB enable */
288     uint32_t Z:1;                        /*!< \brief bit:    11  Branch prediction enable */
289     uint32_t I:1;                        /*!< \brief bit:    12  Instruction cache enable */
290     uint32_t V:1;                        /*!< \brief bit:    13  Vectors bit */
291     uint32_t RR:1;                       /*!< \brief bit:    14  Round Robin select */
292     RESERVED(3:2, uint32_t)              
293     uint32_t HA:1;                       /*!< \brief bit:    17  Hardware Access flag enable */
294     RESERVED(4:1, uint32_t)              
295     uint32_t WXN:1;                      /*!< \brief bit:    19  Write permission implies XN */
296     uint32_t UWXN:1;                     /*!< \brief bit:    20  Unprivileged write permission implies PL1 XN */
297     uint32_t FI:1;                       /*!< \brief bit:    21  Fast interrupts configuration enable */
298     uint32_t U:1;                        /*!< \brief bit:    22  Alignment model */
299     RESERVED(5:1, uint32_t)              
300     uint32_t VE:1;                       /*!< \brief bit:    24  Interrupt Vectors Enable */
301     uint32_t EE:1;                       /*!< \brief bit:    25  Exception Endianness */
302     RESERVED(6:1, uint32_t)              
303     uint32_t NMFI:1;                     /*!< \brief bit:    27  Non-maskable FIQ (NMFI) support */
304     uint32_t TRE:1;                      /*!< \brief bit:    28  TEX remap enable. */
305     uint32_t AFE:1;                      /*!< \brief bit:    29  Access flag enable */
306     uint32_t TE:1;                       /*!< \brief bit:    30  Thumb Exception enable */
307     RESERVED(7:1, uint32_t)              
308   } b;                                   /*!< \brief Structure used for bit  access */
309   uint32_t w;                            /*!< \brief Type      used for word access */
310 } SCTLR_Type;
311
312 #define SCTLR_TE_Pos                     30U                                    /*!< \brief SCTLR: TE Position */
313 #define SCTLR_TE_Msk                     (1UL << SCTLR_TE_Pos)                  /*!< \brief SCTLR: TE Mask */
314
315 #define SCTLR_AFE_Pos                    29U                                    /*!< \brief SCTLR: AFE Position */
316 #define SCTLR_AFE_Msk                    (1UL << SCTLR_AFE_Pos)                 /*!< \brief SCTLR: AFE Mask */
317
318 #define SCTLR_TRE_Pos                    28U                                    /*!< \brief SCTLR: TRE Position */
319 #define SCTLR_TRE_Msk                    (1UL << SCTLR_TRE_Pos)                 /*!< \brief SCTLR: TRE Mask */
320
321 #define SCTLR_NMFI_Pos                   27U                                    /*!< \brief SCTLR: NMFI Position */
322 #define SCTLR_NMFI_Msk                   (1UL << SCTLR_NMFI_Pos)                /*!< \brief SCTLR: NMFI Mask */
323
324 #define SCTLR_EE_Pos                     25U                                    /*!< \brief SCTLR: EE Position */
325 #define SCTLR_EE_Msk                     (1UL << SCTLR_EE_Pos)                  /*!< \brief SCTLR: EE Mask */
326
327 #define SCTLR_VE_Pos                     24U                                    /*!< \brief SCTLR: VE Position */
328 #define SCTLR_VE_Msk                     (1UL << SCTLR_VE_Pos)                  /*!< \brief SCTLR: VE Mask */
329
330 #define SCTLR_U_Pos                      22U                                    /*!< \brief SCTLR: U Position */
331 #define SCTLR_U_Msk                      (1UL << SCTLR_U_Pos)                   /*!< \brief SCTLR: U Mask */
332
333 #define SCTLR_FI_Pos                     21U                                    /*!< \brief SCTLR: FI Position */
334 #define SCTLR_FI_Msk                     (1UL << SCTLR_FI_Pos)                  /*!< \brief SCTLR: FI Mask */
335
336 #define SCTLR_UWXN_Pos                   20U                                    /*!< \brief SCTLR: UWXN Position */
337 #define SCTLR_UWXN_Msk                   (1UL << SCTLR_UWXN_Pos)                /*!< \brief SCTLR: UWXN Mask */
338
339 #define SCTLR_WXN_Pos                    19U                                    /*!< \brief SCTLR: WXN Position */
340 #define SCTLR_WXN_Msk                    (1UL << SCTLR_WXN_Pos)                 /*!< \brief SCTLR: WXN Mask */
341
342 #define SCTLR_HA_Pos                     17U                                    /*!< \brief SCTLR: HA Position */
343 #define SCTLR_HA_Msk                     (1UL << SCTLR_HA_Pos)                  /*!< \brief SCTLR: HA Mask */
344
345 #define SCTLR_RR_Pos                     14U                                    /*!< \brief SCTLR: RR Position */
346 #define SCTLR_RR_Msk                     (1UL << SCTLR_RR_Pos)                  /*!< \brief SCTLR: RR Mask */
347
348 #define SCTLR_V_Pos                      13U                                    /*!< \brief SCTLR: V Position */
349 #define SCTLR_V_Msk                      (1UL << SCTLR_V_Pos)                   /*!< \brief SCTLR: V Mask */
350
351 #define SCTLR_I_Pos                      12U                                    /*!< \brief SCTLR: I Position */
352 #define SCTLR_I_Msk                      (1UL << SCTLR_I_Pos)                   /*!< \brief SCTLR: I Mask */
353
354 #define SCTLR_Z_Pos                      11U                                    /*!< \brief SCTLR: Z Position */
355 #define SCTLR_Z_Msk                      (1UL << SCTLR_Z_Pos)                   /*!< \brief SCTLR: Z Mask */
356
357 #define SCTLR_SW_Pos                     10U                                    /*!< \brief SCTLR: SW Position */
358 #define SCTLR_SW_Msk                     (1UL << SCTLR_SW_Pos)                  /*!< \brief SCTLR: SW Mask */
359
360 #define SCTLR_B_Pos                      7U                                     /*!< \brief SCTLR: B Position */
361 #define SCTLR_B_Msk                      (1UL << SCTLR_B_Pos)                   /*!< \brief SCTLR: B Mask */
362
363 #define SCTLR_CP15BEN_Pos                5U                                     /*!< \brief SCTLR: CP15BEN Position */
364 #define SCTLR_CP15BEN_Msk                (1UL << SCTLR_CP15BEN_Pos)             /*!< \brief SCTLR: CP15BEN Mask */
365
366 #define SCTLR_C_Pos                      2U                                     /*!< \brief SCTLR: C Position */
367 #define SCTLR_C_Msk                      (1UL << SCTLR_C_Pos)                   /*!< \brief SCTLR: C Mask */
368
369 #define SCTLR_A_Pos                      1U                                     /*!< \brief SCTLR: A Position */
370 #define SCTLR_A_Msk                      (1UL << SCTLR_A_Pos)                   /*!< \brief SCTLR: A Mask */
371
372 #define SCTLR_M_Pos                      0U                                     /*!< \brief SCTLR: M Position */
373 #define SCTLR_M_Msk                      (1UL << SCTLR_M_Pos)                   /*!< \brief SCTLR: M Mask */
374
375 /* CP15 Register ACTLR */
376 typedef union
377 {
378 #if __CORTEX_A == 5 || defined(DOXYGEN)
379   /** \brief Structure used for bit access on Cortex-A5 */
380   struct
381   {
382     uint32_t FW:1;                      /*!< \brief bit:      0  Cache and TLB maintenance broadcast */
383     RESERVED(0:5, uint32_t)              
384     uint32_t SMP:1;                      /*!< \brief bit:     6  Enables coherent requests to the processor */
385     uint32_t EXCL:1;                     /*!< \brief bit:     7  Exclusive L1/L2 cache control */
386     RESERVED(1:2, uint32_t)
387     uint32_t DODMBS:1;                   /*!< \brief bit:    10  Disable optimized data memory barrier behavior */
388     uint32_t DWBST:1;                    /*!< \brief bit:    11  AXI data write bursts to Normal memory */
389     uint32_t RADIS:1;                    /*!< \brief bit:    12  L1 Data Cache read-allocate mode disable */
390     uint32_t L1PCTL:2;                   /*!< \brief bit:13..14  L1 Data prefetch control */    
391     uint32_t BP:2;                       /*!< \brief bit:16..15  Branch prediction policy */
392     uint32_t RSDIS:1;                    /*!< \brief bit:    17  Disable return stack operation */
393     uint32_t BTDIS:1;                    /*!< \brief bit:    18  Disable indirect Branch Target Address Cache (BTAC) */
394     RESERVED(3:9, uint32_t)             
395     uint32_t DBDI:1;                     /*!< \brief bit:    28  Disable branch dual issue */
396     RESERVED(7:3, uint32_t)              
397  } b;
398 #endif  
399 #if __CORTEX_A == 7 || defined(DOXYGEN)
400   /** \brief Structure used for bit access on Cortex-A7 */
401   struct
402   {
403     RESERVED(0:6, uint32_t)              
404     uint32_t SMP:1;                      /*!< \brief bit:     6  Enables coherent requests to the processor */
405     RESERVED(1:3, uint32_t)              
406     uint32_t DODMBS:1;                   /*!< \brief bit:    10  Disable optimized data memory barrier behavior */
407     uint32_t L2RADIS:1;                  /*!< \brief bit:    11  L2 Data Cache read-allocate mode disable */
408     uint32_t L1RADIS:1;                  /*!< \brief bit:    12  L1 Data Cache read-allocate mode disable */
409     uint32_t L1PCTL:2;                   /*!< \brief bit:13..14  L1 Data prefetch control */
410     uint32_t DDVM:1;                     /*!< \brief bit:    15  Disable Distributed Virtual Memory (DVM) transactions */
411     RESERVED(3:12, uint32_t)             
412     uint32_t DDI:1;                      /*!< \brief bit:    28  Disable dual issue */
413     RESERVED(7:3, uint32_t)              
414   } b;
415 #endif  
416 #if __CORTEX_A == 9 || defined(DOXYGEN)
417   /** \brief Structure used for bit access on Cortex-A9 */
418   struct
419   {
420     uint32_t FW:1;                       /*!< \brief bit:     0  Cache and TLB maintenance broadcast */
421     RESERVED(0:1, uint32_t)
422     uint32_t L1PE:1;                     /*!< \brief bit:     2  Dside prefetch */
423     uint32_t WFLZM:1;                    /*!< \brief bit:     3  Cache and TLB maintenance broadcast */
424     RESERVED(1:2, uint32_t)
425     uint32_t SMP:1;                      /*!< \brief bit:     6  Enables coherent requests to the processor */
426     uint32_t EXCL:1;                     /*!< \brief bit:     7  Exclusive L1/L2 cache control */
427     uint32_t AOW:1;                      /*!< \brief bit:     8  Enable allocation in one cache way only */
428     uint32_t PARITY:1;                   /*!< \brief bit:     9  Support for parity checking, if implemented */
429     RESERVED(7:22, uint32_t)              
430   } b;
431 #endif  
432   uint32_t w;                            /*!< \brief Type      used for word access */
433 } ACTLR_Type;
434
435 #define ACTLR_DDI_Pos                    28U                                     /*!< \brief ACTLR: DDI Position */
436 #define ACTLR_DDI_Msk                    (1UL << ACTLR_DDI_Pos)                  /*!< \brief ACTLR: DDI Mask */
437
438 #define ACTLR_DBDI_Pos                   28U                                     /*!< \brief ACTLR: DBDI Position */
439 #define ACTLR_DBDI_Msk                   (1UL << ACTLR_DBDI_Pos)                 /*!< \brief ACTLR: DBDI Mask */
440
441 #define ACTLR_BTDIS_Pos                  18U                                     /*!< \brief ACTLR: BTDIS Position */
442 #define ACTLR_BTDIS_Msk                  (1UL << ACTLR_BTDIS_Pos)                /*!< \brief ACTLR: BTDIS Mask */
443
444 #define ACTLR_RSDIS_Pos                  17U                                     /*!< \brief ACTLR: RSDIS Position */
445 #define ACTLR_RSDIS_Msk                  (1UL << ACTLR_RSDIS_Pos)                /*!< \brief ACTLR: RSDIS Mask */
446
447 #define ACTLR_BP_Pos                     15U                                     /*!< \brief ACTLR: BP Position */
448 #define ACTLR_BP_Msk                     (3UL << ACTLR_BP_Pos)                   /*!< \brief ACTLR: BP Mask */
449
450 #define ACTLR_DDVM_Pos                   15U                                     /*!< \brief ACTLR: DDVM Position */
451 #define ACTLR_DDVM_Msk                   (1UL << ACTLR_DDVM_Pos)                 /*!< \brief ACTLR: DDVM Mask */
452
453 #define ACTLR_L1PCTL_Pos                 13U                                     /*!< \brief ACTLR: L1PCTL Position */
454 #define ACTLR_L1PCTL_Msk                 (3UL << ACTLR_L1PCTL_Pos)               /*!< \brief ACTLR: L1PCTL Mask */
455
456 #define ACTLR_RADIS_Pos                  12U                                     /*!< \brief ACTLR: RADIS Position */
457 #define ACTLR_RADIS_Msk                  (1UL << ACTLR_RADIS_Pos)                /*!< \brief ACTLR: RADIS Mask */
458
459 #define ACTLR_L1RADIS_Pos                12U                                     /*!< \brief ACTLR: L1RADIS Position */
460 #define ACTLR_L1RADIS_Msk                (1UL << ACTLR_L1RADIS_Pos)              /*!< \brief ACTLR: L1RADIS Mask */
461
462 #define ACTLR_DWBST_Pos                  11U                                     /*!< \brief ACTLR: DWBST Position */
463 #define ACTLR_DWBST_Msk                  (1UL << ACTLR_DWBST_Pos)                /*!< \brief ACTLR: DWBST Mask */
464
465 #define ACTLR_L2RADIS_Pos                11U                                     /*!< \brief ACTLR: L2RADIS Position */
466 #define ACTLR_L2RADIS_Msk                (1UL << ACTLR_L2RADIS_Pos)              /*!< \brief ACTLR: L2RADIS Mask */
467
468 #define ACTLR_DODMBS_Pos                 10U                                     /*!< \brief ACTLR: DODMBS Position */
469 #define ACTLR_DODMBS_Msk                 (1UL << ACTLR_DODMBS_Pos)               /*!< \brief ACTLR: DODMBS Mask */
470
471 #define ACTLR_PARITY_Pos                 9U                                      /*!< \brief ACTLR: PARITY Position */
472 #define ACTLR_PARITY_Msk                 (1UL << ACTLR_PARITY_Pos)               /*!< \brief ACTLR: PARITY Mask */
473
474 #define ACTLR_AOW_Pos                    8U                                      /*!< \brief ACTLR: AOW Position */
475 #define ACTLR_AOW_Msk                    (1UL << ACTLR_AOW_Pos)                  /*!< \brief ACTLR: AOW Mask */
476
477 #define ACTLR_EXCL_Pos                   7U                                      /*!< \brief ACTLR: EXCL Position */
478 #define ACTLR_EXCL_Msk                   (1UL << ACTLR_EXCL_Pos)                 /*!< \brief ACTLR: EXCL Mask */
479
480 #define ACTLR_SMP_Pos                    6U                                      /*!< \brief ACTLR: SMP Position */
481 #define ACTLR_SMP_Msk                    (1UL << ACTLR_SMP_Pos)                  /*!< \brief ACTLR: SMP Mask */
482
483 #define ACTLR_WFLZM_Pos                  3U                                      /*!< \brief ACTLR: WFLZM Position */
484 #define ACTLR_WFLZM_Msk                  (1UL << ACTLR_WFLZM_Pos)                /*!< \brief ACTLR: WFLZM Mask */
485
486 #define ACTLR_L1PE_Pos                   2U                                      /*!< \brief ACTLR: L1PE Position */
487 #define ACTLR_L1PE_Msk                   (1UL << ACTLR_L1PE_Pos)                 /*!< \brief ACTLR: L1PE Mask */
488
489 #define ACTLR_FW_Pos                     0U                                      /*!< \brief ACTLR: FW Position */
490 #define ACTLR_FW_Msk                     (1UL << ACTLR_FW_Pos)                   /*!< \brief ACTLR: FW Mask */
491
492 /* CP15 Register CPACR */
493 typedef union
494 {
495   struct
496   {
497     uint32_t CP0:2;                      /*!< \brief bit:  0..1  Access rights for coprocessor 0 */
498     uint32_t CP1:2;                      /*!< \brief bit:  2..3  Access rights for coprocessor 1 */
499     uint32_t CP2:2;                      /*!< \brief bit:  4..5  Access rights for coprocessor 2 */
500     uint32_t CP3:2;                      /*!< \brief bit:  6..7  Access rights for coprocessor 3 */
501     uint32_t CP4:2;                      /*!< \brief bit:  8..9  Access rights for coprocessor 4 */
502     uint32_t CP5:2;                      /*!< \brief bit:10..11  Access rights for coprocessor 5 */
503     uint32_t CP6:2;                      /*!< \brief bit:12..13  Access rights for coprocessor 6 */
504     uint32_t CP7:2;                      /*!< \brief bit:14..15  Access rights for coprocessor 7 */
505     uint32_t CP8:2;                      /*!< \brief bit:16..17  Access rights for coprocessor 8 */
506     uint32_t CP9:2;                      /*!< \brief bit:18..19  Access rights for coprocessor 9 */
507     uint32_t CP10:2;                     /*!< \brief bit:20..21  Access rights for coprocessor 10 */
508     uint32_t CP11:2;                     /*!< \brief bit:22..23  Access rights for coprocessor 11 */
509     uint32_t CP12:2;                     /*!< \brief bit:24..25  Access rights for coprocessor 11 */
510     uint32_t CP13:2;                     /*!< \brief bit:26..27  Access rights for coprocessor 11 */
511     uint32_t TRCDIS:1;                   /*!< \brief bit:    28  Disable CP14 access to trace registers */
512     RESERVED(0:1, uint32_t)              
513     uint32_t D32DIS:1;                   /*!< \brief bit:    30  Disable use of registers D16-D31 of the VFP register file */
514     uint32_t ASEDIS:1;                   /*!< \brief bit:    31  Disable Advanced SIMD Functionality */
515   } b;                                   /*!< \brief Structure used for bit  access */
516   uint32_t w;                            /*!< \brief Type      used for word access */
517 } CPACR_Type;
518
519 #define CPACR_ASEDIS_Pos                 31U                                    /*!< \brief CPACR: ASEDIS Position */
520 #define CPACR_ASEDIS_Msk                 (1UL << CPACR_ASEDIS_Pos)              /*!< \brief CPACR: ASEDIS Mask */
521
522 #define CPACR_D32DIS_Pos                 30U                                    /*!< \brief CPACR: D32DIS Position */
523 #define CPACR_D32DIS_Msk                 (1UL << CPACR_D32DIS_Pos)              /*!< \brief CPACR: D32DIS Mask */
524
525 #define CPACR_TRCDIS_Pos                 28U                                    /*!< \brief CPACR: D32DIS Position */
526 #define CPACR_TRCDIS_Msk                 (1UL << CPACR_D32DIS_Pos)              /*!< \brief CPACR: D32DIS Mask */
527
528 #define CPACR_CP_Pos_(n)                 (n*2U)                                 /*!< \brief CPACR: CPn Position */
529 #define CPACR_CP_Msk_(n)                 (3UL << CPACR_CP_Pos_(n))              /*!< \brief CPACR: CPn Mask */
530
531 #define CPACR_CP_NA                      0U                                     /*!< \brief CPACR CPn field: Access denied. */
532 #define CPACR_CP_PL1                     1U                                     /*!< \brief CPACR CPn field: Accessible from PL1 only. */
533 #define CPACR_CP_FA                      3U                                     /*!< \brief CPACR CPn field: Full access. */
534
535 /* CP15 Register DFSR */
536 typedef union
537 {
538   struct
539   {
540     uint32_t FS0:4;                      /*!< \brief bit: 0.. 3  Fault Status bits bit 0-3 */
541     uint32_t Domain:4;                   /*!< \brief bit: 4.. 7  Fault on which domain */
542     RESERVED(0:1, uint32_t)              
543     uint32_t LPAE:1;                     /*!< \brief bit:     9  Large Physical Address Extension */
544     uint32_t FS1:1;                      /*!< \brief bit:    10  Fault Status bits bit 4 */
545     uint32_t WnR:1;                      /*!< \brief bit:    11  Write not Read bit */
546     uint32_t ExT:1;                      /*!< \brief bit:    12  External abort type */
547     uint32_t CM:1;                       /*!< \brief bit:    13  Cache maintenance fault */
548     RESERVED(1:18, uint32_t)             
549   } s;                                   /*!< \brief Structure used for bit  access in short format */
550   struct
551   {
552     uint32_t STATUS:5;                   /*!< \brief bit: 0.. 5  Fault Status bits */
553     RESERVED(0:3, uint32_t)              
554     uint32_t LPAE:1;                     /*!< \brief bit:     9  Large Physical Address Extension */
555     RESERVED(1:1, uint32_t)              
556     uint32_t WnR:1;                      /*!< \brief bit:    11  Write not Read bit */
557     uint32_t ExT:1;                      /*!< \brief bit:    12  External abort type */
558     uint32_t CM:1;                       /*!< \brief bit:    13  Cache maintenance fault */
559     RESERVED(2:18, uint32_t)             
560   } l;                                   /*!< \brief Structure used for bit  access in long format */
561   uint32_t w;                            /*!< \brief Type      used for word access */
562 } DFSR_Type;
563
564 #define DFSR_CM_Pos                      13U                                    /*!< \brief DFSR: CM Position */
565 #define DFSR_CM_Msk                      (1UL << DFSR_CM_Pos)                   /*!< \brief DFSR: CM Mask */
566
567 #define DFSR_Ext_Pos                     12U                                    /*!< \brief DFSR: Ext Position */
568 #define DFSR_Ext_Msk                     (1UL << DFSR_Ext_Pos)                  /*!< \brief DFSR: Ext Mask */
569
570 #define DFSR_WnR_Pos                     11U                                    /*!< \brief DFSR: WnR Position */
571 #define DFSR_WnR_Msk                     (1UL << DFSR_WnR_Pos)                  /*!< \brief DFSR: WnR Mask */
572
573 #define DFSR_FS1_Pos                     10U                                    /*!< \brief DFSR: FS1 Position */
574 #define DFSR_FS1_Msk                     (1UL << DFSR_FS1_Pos)                  /*!< \brief DFSR: FS1 Mask */
575
576 #define DFSR_LPAE_Pos                    9U                                    /*!< \brief DFSR: LPAE Position */
577 #define DFSR_LPAE_Msk                    (1UL << DFSR_LPAE_Pos)                /*!< \brief DFSR: LPAE Mask */
578
579 #define DFSR_Domain_Pos                  4U                                     /*!< \brief DFSR: Domain Position */
580 #define DFSR_Domain_Msk                  (0xFUL << DFSR_Domain_Pos)             /*!< \brief DFSR: Domain Mask */
581
582 #define DFSR_FS0_Pos                     0U                                     /*!< \brief DFSR: FS0 Position */
583 #define DFSR_FS0_Msk                     (0xFUL << DFSR_FS0_Pos)                /*!< \brief DFSR: FS0 Mask */
584
585 #define DFSR_STATUS_Pos                  0U                                     /*!< \brief DFSR: STATUS Position */
586 #define DFSR_STATUS_Msk                  (0x3FUL << DFSR_STATUS_Pos)            /*!< \brief DFSR: STATUS Mask */
587
588 /* CP15 Register IFSR */
589 typedef union
590 {
591   struct
592   {
593     uint32_t FS0:4;                      /*!< \brief bit: 0.. 3  Fault Status bits bit 0-3 */
594     RESERVED(0:5, uint32_t)              
595     uint32_t LPAE:1;                     /*!< \brief bit:     9  Large Physical Address Extension */
596     uint32_t FS1:1;                      /*!< \brief bit:    10  Fault Status bits bit 4 */
597     RESERVED(1:1, uint32_t)              
598     uint32_t ExT:1;                      /*!< \brief bit:    12  External abort type */
599     RESERVED(2:19, uint32_t)             
600   } s;                                   /*!< \brief Structure used for bit access in short format */
601   struct
602   {
603     uint32_t STATUS:6;                   /*!< \brief bit: 0.. 5  Fault Status bits */
604     RESERVED(0:3, uint32_t)              
605     uint32_t LPAE:1;                     /*!< \brief bit:     9  Large Physical Address Extension */
606     RESERVED(1:2, uint32_t)              
607     uint32_t ExT:1;                      /*!< \brief bit:    12  External abort type */
608     RESERVED(2:19, uint32_t)             
609   } l;                                   /*!< \brief Structure used for bit access in long format */
610   uint32_t w;                            /*!< \brief Type      used for word access */
611 } IFSR_Type;
612
613 #define IFSR_ExT_Pos                     12U                                    /*!< \brief IFSR: ExT Position */
614 #define IFSR_ExT_Msk                     (1UL << IFSR_ExT_Pos)                  /*!< \brief IFSR: ExT Mask */
615
616 #define IFSR_FS1_Pos                     10U                                    /*!< \brief IFSR: FS1 Position */
617 #define IFSR_FS1_Msk                     (1UL << IFSR_FS1_Pos)                  /*!< \brief IFSR: FS1 Mask */
618
619 #define IFSR_LPAE_Pos                    9U                                     /*!< \brief IFSR: LPAE Position */
620 #define IFSR_LPAE_Msk                    (0x1UL << IFSR_LPAE_Pos)               /*!< \brief IFSR: LPAE Mask */
621
622 #define IFSR_FS0_Pos                     0U                                     /*!< \brief IFSR: FS0 Position */
623 #define IFSR_FS0_Msk                     (0xFUL << IFSR_FS0_Pos)                /*!< \brief IFSR: FS0 Mask */
624
625 #define IFSR_STATUS_Pos                  0U                                     /*!< \brief IFSR: STATUS Position */
626 #define IFSR_STATUS_Msk                  (0x3FUL << IFSR_STATUS_Pos)            /*!< \brief IFSR: STATUS Mask */
627
628 /* CP15 Register ISR */
629 typedef union
630 {
631   struct
632   {
633     RESERVED(0:6, uint32_t)              
634     uint32_t F:1;                        /*!< \brief bit:     6  FIQ pending bit */
635     uint32_t I:1;                        /*!< \brief bit:     7  IRQ pending bit */
636     uint32_t A:1;                        /*!< \brief bit:     8  External abort pending bit */
637     RESERVED(1:23, uint32_t)             
638   } b;                                   /*!< \brief Structure used for bit  access */
639   uint32_t w;                            /*!< \brief Type      used for word access */
640 } ISR_Type;
641
642 #define ISR_A_Pos                        13U                                    /*!< \brief ISR: A Position */
643 #define ISR_A_Msk                        (1UL << ISR_A_Pos)                     /*!< \brief ISR: A Mask */
644
645 #define ISR_I_Pos                        12U                                    /*!< \brief ISR: I Position */
646 #define ISR_I_Msk                        (1UL << ISR_I_Pos)                     /*!< \brief ISR: I Mask */
647
648 #define ISR_F_Pos                        11U                                    /*!< \brief ISR: F Position */
649 #define ISR_F_Msk                        (1UL << ISR_F_Pos)                     /*!< \brief ISR: F Mask */
650
651 /* DACR Register */
652 #define DACR_D_Pos_(n)                   (2U*n)                                 /*!< \brief DACR: Dn Position */
653 #define DACR_D_Msk_(n)                   (3UL << DACR_D_Pos_(n))                /*!< \brief DACR: Dn Mask */
654 #define DACR_Dn_NOACCESS                 0U                                     /*!< \brief DACR Dn field: No access */
655 #define DACR_Dn_CLIENT                   1U                                     /*!< \brief DACR Dn field: Client */
656 #define DACR_Dn_MANAGER                  3U                                     /*!< \brief DACR Dn field: Manager */
657
658 /**
659   \brief     Mask and shift a bit field value for use in a register bit range.
660   \param [in] field  Name of the register bit field.
661   \param [in] value  Value of the bit field. This parameter is interpreted as an uint32_t type.
662   \return           Masked and shifted value.
663 */
664 #define _VAL2FLD(field, value)    (((uint32_t)(value) << field ## _Pos) & field ## _Msk)
665
666 /**
667   \brief     Mask and shift a register value to extract a bit filed value.
668   \param [in] field  Name of the register bit field.
669   \param [in] value  Value of register. This parameter is interpreted as an uint32_t type.
670   \return           Masked and shifted bit field value.
671 */
672 #define _FLD2VAL(field, value)    (((uint32_t)(value) & field ## _Msk) >> field ## _Pos)
673
674
675 /**
676  \brief  Union type to access the L2C_310 Cache Controller.
677 */
678 #if (__L2C_PRESENT == 1U) || defined(DOXYGEN)
679 typedef struct
680 {
681   __IM  uint32_t CACHE_ID;                   /*!< \brief Offset: 0x0000 (R/ ) Cache ID Register               */
682   __IM  uint32_t CACHE_TYPE;                 /*!< \brief Offset: 0x0004 (R/ ) Cache Type Register             */
683         RESERVED(0[0x3e], uint32_t)
684   __IOM uint32_t CONTROL;                    /*!< \brief Offset: 0x0100 (R/W) Control Register                */
685   __IOM uint32_t AUX_CNT;                    /*!< \brief Offset: 0x0104 (R/W) Auxiliary Control               */
686         RESERVED(1[0x3e], uint32_t)
687   __IOM uint32_t EVENT_CONTROL;              /*!< \brief Offset: 0x0200 (R/W) Event Counter Control           */
688   __IOM uint32_t EVENT_COUNTER1_CONF;        /*!< \brief Offset: 0x0204 (R/W) Event Counter 1 Configuration   */
689   __IOM uint32_t EVENT_COUNTER0_CONF;        /*!< \brief Offset: 0x0208 (R/W) Event Counter 1 Configuration   */
690         RESERVED(2[0x2], uint32_t)
691   __IOM uint32_t INTERRUPT_MASK;             /*!< \brief Offset: 0x0214 (R/W) Interrupt Mask                  */
692   __IM  uint32_t MASKED_INT_STATUS;          /*!< \brief Offset: 0x0218 (R/ ) Masked Interrupt Status         */
693   __IM  uint32_t RAW_INT_STATUS;             /*!< \brief Offset: 0x021c (R/ ) Raw Interrupt Status            */
694   __OM  uint32_t INTERRUPT_CLEAR;            /*!< \brief Offset: 0x0220 ( /W) Interrupt Clear                 */
695         RESERVED(3[0x143], uint32_t)
696   __IOM uint32_t CACHE_SYNC;                 /*!< \brief Offset: 0x0730 (R/W) Cache Sync                      */
697         RESERVED(4[0xf], uint32_t)
698   __IOM uint32_t INV_LINE_PA;                /*!< \brief Offset: 0x0770 (R/W) Invalidate Line By PA           */
699         RESERVED(6[2], uint32_t)
700   __IOM uint32_t INV_WAY;                    /*!< \brief Offset: 0x077c (R/W) Invalidate by Way               */
701         RESERVED(5[0xc], uint32_t)
702   __IOM uint32_t CLEAN_LINE_PA;              /*!< \brief Offset: 0x07b0 (R/W) Clean Line by PA                */
703         RESERVED(7[1], uint32_t)
704   __IOM uint32_t CLEAN_LINE_INDEX_WAY;       /*!< \brief Offset: 0x07b8 (R/W) Clean Line by Index/Way         */
705   __IOM uint32_t CLEAN_WAY;                  /*!< \brief Offset: 0x07bc (R/W) Clean by Way                    */
706         RESERVED(8[0xc], uint32_t)
707   __IOM uint32_t CLEAN_INV_LINE_PA;          /*!< \brief Offset: 0x07f0 (R/W) Clean and Invalidate Line by PA  */
708         RESERVED(9[1], uint32_t)
709   __IOM uint32_t CLEAN_INV_LINE_INDEX_WAY;   /*!< \brief Offset: 0x07f8 (R/W) Clean and Invalidate Line by Index/Way  */
710   __IOM uint32_t CLEAN_INV_WAY;              /*!< \brief Offset: 0x07fc (R/W) Clean and Invalidate by Way     */
711         RESERVED(10[0x40], uint32_t)
712   __IOM uint32_t DATA_LOCK_0_WAY;            /*!< \brief Offset: 0x0900 (R/W) Data Lockdown 0 by Way          */
713   __IOM uint32_t INST_LOCK_0_WAY;            /*!< \brief Offset: 0x0904 (R/W) Instruction Lockdown 0 by Way   */
714   __IOM uint32_t DATA_LOCK_1_WAY;            /*!< \brief Offset: 0x0908 (R/W) Data Lockdown 1 by Way          */
715   __IOM uint32_t INST_LOCK_1_WAY;            /*!< \brief Offset: 0x090c (R/W) Instruction Lockdown 1 by Way   */
716   __IOM uint32_t DATA_LOCK_2_WAY;            /*!< \brief Offset: 0x0910 (R/W) Data Lockdown 2 by Way          */
717   __IOM uint32_t INST_LOCK_2_WAY;            /*!< \brief Offset: 0x0914 (R/W) Instruction Lockdown 2 by Way   */
718   __IOM uint32_t DATA_LOCK_3_WAY;            /*!< \brief Offset: 0x0918 (R/W) Data Lockdown 3 by Way          */
719   __IOM uint32_t INST_LOCK_3_WAY;            /*!< \brief Offset: 0x091c (R/W) Instruction Lockdown 3 by Way   */
720   __IOM uint32_t DATA_LOCK_4_WAY;            /*!< \brief Offset: 0x0920 (R/W) Data Lockdown 4 by Way          */
721   __IOM uint32_t INST_LOCK_4_WAY;            /*!< \brief Offset: 0x0924 (R/W) Instruction Lockdown 4 by Way   */
722   __IOM uint32_t DATA_LOCK_5_WAY;            /*!< \brief Offset: 0x0928 (R/W) Data Lockdown 5 by Way          */
723   __IOM uint32_t INST_LOCK_5_WAY;            /*!< \brief Offset: 0x092c (R/W) Instruction Lockdown 5 by Way   */
724   __IOM uint32_t DATA_LOCK_6_WAY;            /*!< \brief Offset: 0x0930 (R/W) Data Lockdown 5 by Way          */
725   __IOM uint32_t INST_LOCK_6_WAY;            /*!< \brief Offset: 0x0934 (R/W) Instruction Lockdown 5 by Way   */
726   __IOM uint32_t DATA_LOCK_7_WAY;            /*!< \brief Offset: 0x0938 (R/W) Data Lockdown 6 by Way          */
727   __IOM uint32_t INST_LOCK_7_WAY;            /*!< \brief Offset: 0x093c (R/W) Instruction Lockdown 6 by Way   */
728         RESERVED(11[0x4], uint32_t)
729   __IOM uint32_t LOCK_LINE_EN;               /*!< \brief Offset: 0x0950 (R/W) Lockdown by Line Enable         */
730   __IOM uint32_t UNLOCK_ALL_BY_WAY;          /*!< \brief Offset: 0x0954 (R/W) Unlock All Lines by Way         */
731         RESERVED(12[0xaa], uint32_t)
732   __IOM uint32_t ADDRESS_FILTER_START;       /*!< \brief Offset: 0x0c00 (R/W) Address Filtering Start         */
733   __IOM uint32_t ADDRESS_FILTER_END;         /*!< \brief Offset: 0x0c04 (R/W) Address Filtering End           */
734         RESERVED(13[0xce], uint32_t)
735   __IOM uint32_t DEBUG_CONTROL;              /*!< \brief Offset: 0x0f40 (R/W) Debug Control Register          */
736 } L2C_310_TypeDef;
737
738 #define L2C_310           ((L2C_310_TypeDef *)L2C_310_BASE) /*!< \brief L2C_310 register set access pointer */
739 #endif
740
741 #if (__GIC_PRESENT == 1U) || defined(DOXYGEN)
742     
743 /** \brief  Structure type to access the Generic Interrupt Controller Distributor (GICD)
744 */
745 typedef struct
746 {
747   __IOM uint32_t CTLR;                 /*!< \brief  Offset: 0x000 (R/W) Distributor Control Register */
748   __IM  uint32_t TYPER;                /*!< \brief  Offset: 0x004 (R/ ) Interrupt Controller Type Register */
749   __IM  uint32_t IIDR;                 /*!< \brief  Offset: 0x008 (R/ ) Distributor Implementer Identification Register */
750         RESERVED(0, uint32_t)
751   __IOM uint32_t STATUSR;              /*!< \brief  Offset: 0x010 (R/W) Error Reporting Status Register, optional */
752         RESERVED(1[11], uint32_t)
753   __OM  uint32_t SETSPI_NSR;           /*!< \brief  Offset: 0x040 ( /W) Set SPI Register */
754         RESERVED(2, uint32_t)
755   __OM  uint32_t CLRSPI_NSR;           /*!< \brief  Offset: 0x048 ( /W) Clear SPI Register */
756         RESERVED(3, uint32_t)
757   __OM  uint32_t SETSPI_SR;            /*!< \brief  Offset: 0x050 ( /W) Set SPI, Secure Register */
758         RESERVED(4, uint32_t)
759   __OM  uint32_t CLRSPI_SR;            /*!< \brief  Offset: 0x058 ( /W) Clear SPI, Secure Register */
760         RESERVED(5[9], uint32_t)
761   __IOM uint32_t IGROUPR[32];          /*!< \brief  Offset: 0x080 (R/W) Interrupt Group Registers */
762   __IOM uint32_t ISENABLER[32];        /*!< \brief  Offset: 0x100 (R/W) Interrupt Set-Enable Registers */
763   __IOM uint32_t ICENABLER[32];        /*!< \brief  Offset: 0x180 (R/W) Interrupt Clear-Enable Registers */
764   __IOM uint32_t ISPENDR[32];          /*!< \brief  Offset: 0x200 (R/W) Interrupt Set-Pending Registers */
765   __IOM uint32_t ICPENDR[32];          /*!< \brief  Offset: 0x280 (R/W) Interrupt Clear-Pending Registers */
766   __IOM uint32_t ISACTIVER[32];        /*!< \brief  Offset: 0x300 (R/W) Interrupt Set-Active Registers */
767   __IOM uint32_t ICACTIVER[32];        /*!< \brief  Offset: 0x380 (R/W) Interrupt Clear-Active Registers */
768   __IOM uint32_t IPRIORITYR[255];      /*!< \brief  Offset: 0x400 (R/W) Interrupt Priority Registers */
769         RESERVED(6, uint32_t)
770   __IOM uint32_t  ITARGETSR[255];      /*!< \brief  Offset: 0x800 (R/W) Interrupt Targets Registers */
771         RESERVED(7, uint32_t)
772   __IOM uint32_t ICFGR[64];            /*!< \brief  Offset: 0xC00 (R/W) Interrupt Configuration Registers */
773   __IOM uint32_t IGRPMODR[32];         /*!< \brief  Offset: 0xD00 (R/W) Interrupt Group Modifier Registers */
774         RESERVED(8[32], uint32_t)
775   __IOM uint32_t NSACR[64];            /*!< \brief  Offset: 0xE00 (R/W) Non-secure Access Control Registers */
776   __OM  uint32_t SGIR;                 /*!< \brief  Offset: 0xF00 ( /W) Software Generated Interrupt Register */
777         RESERVED(9[3], uint32_t)
778   __IOM uint32_t CPENDSGIR[4];         /*!< \brief  Offset: 0xF10 (R/W) SGI Clear-Pending Registers */
779   __IOM uint32_t SPENDSGIR[4];         /*!< \brief  Offset: 0xF20 (R/W) SGI Set-Pending Registers */
780         RESERVED(10[5236], uint32_t)
781   __IOM uint64_t IROUTER[988];         /*!< \brief  Offset: 0x6100(R/W) Interrupt Routing Registers */
782 }  GICDistributor_Type;
783
784 #define GICDistributor      ((GICDistributor_Type      *)     GIC_DISTRIBUTOR_BASE ) /*!< \brief GIC Distributor register set access pointer */
785
786 /** \brief  Structure type to access the Generic Interrupt Controller Interface (GICC)
787 */
788 typedef struct
789 {
790   __IOM uint32_t CTLR;                 /*!< \brief  Offset: 0x000 (R/W) CPU Interface Control Register */
791   __IOM uint32_t PMR;                  /*!< \brief  Offset: 0x004 (R/W) Interrupt Priority Mask Register */
792   __IOM uint32_t BPR;                  /*!< \brief  Offset: 0x008 (R/W) Binary Point Register */
793   __IM  uint32_t IAR;                  /*!< \brief  Offset: 0x00C (R/ ) Interrupt Acknowledge Register */
794   __OM  uint32_t EOIR;                 /*!< \brief  Offset: 0x010 ( /W) End Of Interrupt Register */
795   __IM  uint32_t RPR;                  /*!< \brief  Offset: 0x014 (R/ ) Running Priority Register */
796   __IM  uint32_t HPPIR;                /*!< \brief  Offset: 0x018 (R/ ) Highest Priority Pending Interrupt Register */
797   __IOM uint32_t ABPR;                 /*!< \brief  Offset: 0x01C (R/W) Aliased Binary Point Register */
798   __IM  uint32_t AIAR;                 /*!< \brief  Offset: 0x020 (R/ ) Aliased Interrupt Acknowledge Register */
799   __OM  uint32_t AEOIR;                /*!< \brief  Offset: 0x024 ( /W) Aliased End Of Interrupt Register */
800   __IM  uint32_t AHPPIR;               /*!< \brief  Offset: 0x028 (R/ ) Aliased Highest Priority Pending Interrupt Register */
801   __IOM uint32_t STATUSR;              /*!< \brief  Offset: 0x02C (R/W) Error Reporting Status Register, optional */
802         RESERVED(1[40], uint32_t)
803   __IOM uint32_t APR[4];               /*!< \brief  Offset: 0x0D0 (R/W) Active Priority Register */
804   __IOM uint32_t NSAPR[4];             /*!< \brief  Offset: 0x0E0 (R/W) Non-secure Active Priority Register */
805         RESERVED(2[3], uint32_t)
806   __IM  uint32_t IIDR;                 /*!< \brief  Offset: 0x0FC (R/ ) CPU Interface Identification Register */
807         RESERVED(3[960], uint32_t)
808   __OM  uint32_t DIR;                  /*!< \brief  Offset: 0x1000( /W) Deactivate Interrupt Register */
809 }  GICInterface_Type;
810
811 #define GICInterface        ((GICInterface_Type        *)     GIC_INTERFACE_BASE )   /*!< \brief GIC Interface register set access pointer */
812 #endif
813
814 #if (__TIM_PRESENT == 1U) || defined(DOXYGEN)
815 #if ((__CORTEX_A == 5U) || (__CORTEX_A == 9U)) || defined(DOXYGEN)
816 /** \brief Structure type to access the Private Timer
817 */
818 typedef struct
819 {
820   __IOM uint32_t LOAD;            //!< \brief  Offset: 0x000 (R/W) Private Timer Load Register
821   __IOM uint32_t COUNTER;         //!< \brief  Offset: 0x004 (R/W) Private Timer Counter Register
822   __IOM uint32_t CONTROL;         //!< \brief  Offset: 0x008 (R/W) Private Timer Control Register
823   __IOM uint32_t ISR;             //!< \brief  Offset: 0x00C (R/W) Private Timer Interrupt Status Register
824         RESERVED(0[4], uint32_t)
825   __IOM uint32_t WLOAD;           //!< \brief  Offset: 0x020 (R/W) Watchdog Load Register
826   __IOM uint32_t WCOUNTER;        //!< \brief  Offset: 0x024 (R/W) Watchdog Counter Register
827   __IOM uint32_t WCONTROL;        //!< \brief  Offset: 0x028 (R/W) Watchdog Control Register
828   __IOM uint32_t WISR;            //!< \brief  Offset: 0x02C (R/W) Watchdog Interrupt Status Register
829   __IOM uint32_t WRESET;          //!< \brief  Offset: 0x030 (R/W) Watchdog Reset Status Register
830   __OM  uint32_t WDISABLE;        //!< \brief  Offset: 0x034 ( /W) Watchdog Disable Register
831 } Timer_Type;
832 #define PTIM ((Timer_Type *) TIMER_BASE )   /*!< \brief Timer register struct */
833 #endif
834 #endif
835
836  /*******************************************************************************
837   *                Hardware Abstraction Layer
838    Core Function Interface contains:
839    - L1 Cache Functions
840    - L2C-310 Cache Controller Functions 
841    - PL1 Timer Functions
842    - GIC Functions
843    - MMU Functions
844   ******************************************************************************/
845  
846 /* ##########################  L1 Cache functions  ################################# */
847
848 /** \brief Enable Caches by setting I and C bits in SCTLR register.
849 */
850 __STATIC_FORCEINLINE void L1C_EnableCaches(void) {
851   __set_SCTLR( __get_SCTLR() | SCTLR_I_Msk | SCTLR_C_Msk);
852   __ISB();
853 }
854
855 /** \brief Disable Caches by clearing I and C bits in SCTLR register.
856 */
857 __STATIC_FORCEINLINE void L1C_DisableCaches(void) {
858   __set_SCTLR( __get_SCTLR() & (~SCTLR_I_Msk) & (~SCTLR_C_Msk));
859   __ISB();
860 }
861
862 /** \brief  Enable Branch Prediction by setting Z bit in SCTLR register.
863 */
864 __STATIC_FORCEINLINE void L1C_EnableBTAC(void) {
865   __set_SCTLR( __get_SCTLR() | SCTLR_Z_Msk);
866   __ISB();
867 }
868
869 /** \brief  Disable Branch Prediction by clearing Z bit in SCTLR register.
870 */
871 __STATIC_FORCEINLINE void L1C_DisableBTAC(void) {
872   __set_SCTLR( __get_SCTLR() & (~SCTLR_Z_Msk));
873   __ISB();
874 }
875
876 /** \brief  Invalidate entire branch predictor array
877 */
878 __STATIC_FORCEINLINE void L1C_InvalidateBTAC(void) {
879   __set_BPIALL(0);
880   __DSB();     //ensure completion of the invalidation
881   __ISB();     //ensure instruction fetch path sees new state
882 }
883
884 /** \brief  Invalidate the whole instruction cache
885 */
886 __STATIC_FORCEINLINE void L1C_InvalidateICacheAll(void) {
887   __set_ICIALLU(0);
888   __DSB();     //ensure completion of the invalidation
889   __ISB();     //ensure instruction fetch path sees new I cache state
890 }
891
892 /** \brief  Clean data cache line by address.
893 * \param [in] va Pointer to data to clear the cache for.
894 */
895 __STATIC_FORCEINLINE void L1C_CleanDCacheMVA(void *va) {
896   __set_DCCMVAC((uint32_t)va);
897   __DMB();     //ensure the ordering of data cache maintenance operations and their effects
898 }
899
900 /** \brief  Invalidate data cache line by address.
901 * \param [in] va Pointer to data to invalidate the cache for.
902 */
903 __STATIC_FORCEINLINE void L1C_InvalidateDCacheMVA(void *va) {
904   __set_DCIMVAC((uint32_t)va);
905   __DMB();     //ensure the ordering of data cache maintenance operations and their effects
906 }
907
908 /** \brief  Clean and Invalidate data cache by address.
909 * \param [in] va Pointer to data to invalidate the cache for.
910 */
911 __STATIC_FORCEINLINE void L1C_CleanInvalidateDCacheMVA(void *va) {
912   __set_DCCIMVAC((uint32_t)va);
913   __DMB();     //ensure the ordering of data cache maintenance operations and their effects
914 }
915
916 /** \brief Calculate log2 rounded up
917 *  - log(0)  => 0
918 *  - log(1)  => 0
919 *  - log(2)  => 1
920 *  - log(3)  => 2
921 *  - log(4)  => 2
922 *  - log(5)  => 3
923 *        :      :
924 *  - log(16) => 4
925 *  - log(32) => 5
926 *        :      :
927 * \param [in] n input value parameter 
928 * \return log2(n)
929 */
930 __STATIC_FORCEINLINE uint8_t __log2_up(uint32_t n)
931 {
932   if (n < 2U) {
933     return 0U;
934   }
935   uint8_t log = 0U;
936   uint32_t t = n;
937   while(t > 1U)
938   {
939     log++;
940     t >>= 1U;
941   }
942   if (n & 1U) { log++; }
943   return log;
944 }
945
946 /** \brief  Apply cache maintenance to given cache level.
947 * \param [in] level cache level to be maintained
948 * \param [in] maint 0 - invalidate, 1 - clean, otherwise - invalidate and clean
949 */
950 __STATIC_FORCEINLINE void __L1C_MaintainDCacheSetWay(uint32_t level, uint32_t maint)
951 {
952   uint32_t Dummy;
953   uint32_t ccsidr;
954   uint32_t num_sets;
955   uint32_t num_ways;
956   uint32_t shift_way;
957   uint32_t log2_linesize;
958    int32_t log2_num_ways;
959
960   Dummy = level << 1U;
961   /* set csselr, select ccsidr register */
962   __set_CSSELR(Dummy);
963   /* get current ccsidr register */
964   ccsidr = __get_CCSIDR();
965   num_sets = ((ccsidr & 0x0FFFE000U) >> 13U) + 1U;
966   num_ways = ((ccsidr & 0x00001FF8U) >> 3U) + 1U;
967   log2_linesize = (ccsidr & 0x00000007U) + 2U + 2U;
968   log2_num_ways = __log2_up(num_ways);
969   if ((log2_num_ways < 0) || (log2_num_ways > 32)) {
970     return; // FATAL ERROR
971   }
972   shift_way = 32U - (uint32_t)log2_num_ways;
973   for(int32_t way = num_ways-1; way >= 0; way--)
974   {
975     for(int32_t set = num_sets-1; set >= 0; set--)
976     {
977       Dummy = (level << 1U) | (((uint32_t)set) << log2_linesize) | (((uint32_t)way) << shift_way);
978       switch (maint)
979       {
980         case 0U: __set_DCISW(Dummy);  break;
981         case 1U: __set_DCCSW(Dummy);  break;
982         default: __set_DCCISW(Dummy); break;
983       }
984     }
985   }
986   __DMB();
987 }
988
989 /** \brief  Clean and Invalidate the entire data or unified cache
990 * Generic mechanism for cleaning/invalidating the entire data or unified cache to the point of coherency
991 * \param [in] op 0 - invalidate, 1 - clean, otherwise - invalidate and clean
992 */
993 __STATIC_FORCEINLINE void L1C_CleanInvalidateCache(uint32_t op) {
994   uint32_t clidr;
995   uint32_t cache_type;
996   clidr =  __get_CLIDR();
997   for(uint32_t i = 0U; i<7U; i++)
998   {
999     cache_type = (clidr >> i*3U) & 0x7UL;
1000     if ((cache_type >= 2U) && (cache_type <= 4U))
1001     {
1002       __L1C_MaintainDCacheSetWay(i, op);
1003     }
1004   }
1005 }
1006
1007 /** \brief  Clean and Invalidate the entire data or unified cache
1008 * Generic mechanism for cleaning/invalidating the entire data or unified cache to the point of coherency
1009 * \param [in] op 0 - invalidate, 1 - clean, otherwise - invalidate and clean
1010 * \deprecated Use generic L1C_CleanInvalidateCache instead.
1011 */
1012 CMSIS_DEPRECATED
1013 __STATIC_FORCEINLINE void __L1C_CleanInvalidateCache(uint32_t op) {
1014   L1C_CleanInvalidateCache(op);
1015 }
1016
1017 /** \brief  Invalidate the whole data cache.
1018 */
1019 __STATIC_FORCEINLINE void L1C_InvalidateDCacheAll(void) {
1020   L1C_CleanInvalidateCache(0);
1021 }
1022
1023 /** \brief  Clean the whole data cache.
1024  */
1025 __STATIC_FORCEINLINE void L1C_CleanDCacheAll(void) {
1026   L1C_CleanInvalidateCache(1);
1027 }
1028
1029 /** \brief  Clean and invalidate the whole data cache.
1030  */
1031 __STATIC_FORCEINLINE void L1C_CleanInvalidateDCacheAll(void) {
1032   L1C_CleanInvalidateCache(2);
1033 }
1034
1035 /* ##########################  L2 Cache functions  ################################# */
1036 #if (__L2C_PRESENT == 1U) || defined(DOXYGEN)
1037 /** \brief Cache Sync operation by writing CACHE_SYNC register.
1038 */
1039 __STATIC_INLINE void L2C_Sync(void)
1040 {
1041   L2C_310->CACHE_SYNC = 0x0;
1042 }
1043
1044 /** \brief Read cache controller cache ID from CACHE_ID register.
1045  * \return L2C_310_TypeDef::CACHE_ID
1046  */
1047 __STATIC_INLINE int L2C_GetID (void)
1048 {
1049   return L2C_310->CACHE_ID;
1050 }
1051
1052 /** \brief Read cache controller cache type from CACHE_TYPE register.
1053 *  \return L2C_310_TypeDef::CACHE_TYPE
1054 */
1055 __STATIC_INLINE int L2C_GetType (void)
1056 {
1057   return L2C_310->CACHE_TYPE;
1058 }
1059
1060 /** \brief Invalidate all cache by way
1061 */
1062 __STATIC_INLINE void L2C_InvAllByWay (void)
1063 {
1064   unsigned int assoc;
1065
1066   if (L2C_310->AUX_CNT & (1U << 16U)) {
1067     assoc = 16U;
1068   } else {
1069     assoc =  8U;
1070   }
1071   
1072   L2C_310->INV_WAY = (1U << assoc) - 1U;
1073   while(L2C_310->INV_WAY & ((1U << assoc) - 1U)); //poll invalidate
1074
1075   L2C_Sync();
1076 }
1077
1078 /** \brief Clean and Invalidate all cache by way
1079 */
1080 __STATIC_INLINE void L2C_CleanInvAllByWay (void)
1081 {
1082   unsigned int assoc;
1083
1084   if (L2C_310->AUX_CNT & (1U << 16U)) {
1085     assoc = 16U;
1086   } else {
1087     assoc =  8U;
1088   }
1089
1090   L2C_310->CLEAN_INV_WAY = (1U << assoc) - 1U;
1091   while(L2C_310->CLEAN_INV_WAY & ((1U << assoc) - 1U)); //poll invalidate
1092
1093   L2C_Sync();
1094 }
1095
1096 /** \brief Enable Level 2 Cache
1097 */
1098 __STATIC_INLINE void L2C_Enable(void)
1099 {
1100   L2C_310->CONTROL = 0;
1101   L2C_310->INTERRUPT_CLEAR = 0x000001FFuL;
1102   L2C_310->DEBUG_CONTROL = 0;
1103   L2C_310->DATA_LOCK_0_WAY = 0;
1104   L2C_310->CACHE_SYNC = 0;
1105   L2C_310->CONTROL = 0x01;
1106   L2C_Sync();
1107 }
1108
1109 /** \brief Disable Level 2 Cache
1110 */
1111 __STATIC_INLINE void L2C_Disable(void)
1112 {
1113   L2C_310->CONTROL = 0x00;
1114   L2C_Sync();
1115 }
1116
1117 /** \brief Invalidate cache by physical address
1118 * \param [in] pa Pointer to data to invalidate cache for.
1119 */
1120 __STATIC_INLINE void L2C_InvPa (void *pa)
1121 {
1122   L2C_310->INV_LINE_PA = (unsigned int)pa;
1123   L2C_Sync();
1124 }
1125
1126 /** \brief Clean cache by physical address
1127 * \param [in] pa Pointer to data to invalidate cache for.
1128 */
1129 __STATIC_INLINE void L2C_CleanPa (void *pa)
1130 {
1131   L2C_310->CLEAN_LINE_PA = (unsigned int)pa;
1132   L2C_Sync();
1133 }
1134
1135 /** \brief Clean and invalidate cache by physical address
1136 * \param [in] pa Pointer to data to invalidate cache for.
1137 */
1138 __STATIC_INLINE void L2C_CleanInvPa (void *pa)
1139 {
1140   L2C_310->CLEAN_INV_LINE_PA = (unsigned int)pa;
1141   L2C_Sync();
1142 }
1143 #endif
1144
1145 /* ##########################  GIC functions  ###################################### */
1146 #if (__GIC_PRESENT == 1U) || defined(DOXYGEN)
1147   
1148 /** \brief  Enable the interrupt distributor using the GIC's CTLR register.
1149 */
1150 __STATIC_INLINE void GIC_EnableDistributor(void)
1151 {
1152   GICDistributor->CTLR |= 1U;
1153 }
1154
1155 /** \brief Disable the interrupt distributor using the GIC's CTLR register.
1156 */
1157 __STATIC_INLINE void GIC_DisableDistributor(void)
1158 {
1159   GICDistributor->CTLR &=~1U;
1160 }
1161
1162 /** \brief Read the GIC's TYPER register.
1163 * \return GICDistributor_Type::TYPER
1164 */
1165 __STATIC_INLINE uint32_t GIC_DistributorInfo(void)
1166 {
1167   return (GICDistributor->TYPER);
1168 }
1169
1170 /** \brief Reads the GIC's IIDR register.
1171 * \return GICDistributor_Type::IIDR
1172 */
1173 __STATIC_INLINE uint32_t GIC_DistributorImplementer(void)
1174 {
1175   return (GICDistributor->IIDR);
1176 }
1177
1178 /** \brief Sets the GIC's ITARGETSR register for the given interrupt.
1179 * \param [in] IRQn Interrupt to be configured.
1180 * \param [in] cpu_target CPU interfaces to assign this interrupt to.
1181 */
1182 __STATIC_INLINE void GIC_SetTarget(IRQn_Type IRQn, uint32_t cpu_target)
1183 {
1184   uint32_t mask = GICDistributor->ITARGETSR[IRQn / 4U] & ~(0xFFUL << ((IRQn % 4U) * 8U));
1185   GICDistributor->ITARGETSR[IRQn / 4U] = mask | ((cpu_target & 0xFFUL) << ((IRQn % 4U) * 8U));
1186 }
1187
1188 /** \brief Read the GIC's ITARGETSR register.
1189 * \param [in] IRQn Interrupt to acquire the configuration for.
1190 * \return GICDistributor_Type::ITARGETSR
1191 */
1192 __STATIC_INLINE uint32_t GIC_GetTarget(IRQn_Type IRQn)
1193 {
1194   return (GICDistributor->ITARGETSR[IRQn / 4U] >> ((IRQn % 4U) * 8U)) & 0xFFUL;
1195 }
1196
1197 /** \brief Enable the CPU's interrupt interface.
1198 */
1199 __STATIC_INLINE void GIC_EnableInterface(void)
1200 {
1201   GICInterface->CTLR |= 1U; //enable interface
1202 }
1203
1204 /** \brief Disable the CPU's interrupt interface.
1205 */
1206 __STATIC_INLINE void GIC_DisableInterface(void)
1207 {
1208   GICInterface->CTLR &=~1U; //disable distributor
1209 }
1210
1211 /** \brief Read the CPU's IAR register.
1212 * \return GICInterface_Type::IAR
1213 */
1214 __STATIC_INLINE IRQn_Type GIC_AcknowledgePending(void)
1215 {
1216   return (IRQn_Type)(GICInterface->IAR);
1217 }
1218
1219 /** \brief Writes the given interrupt number to the CPU's EOIR register.
1220 * \param [in] IRQn The interrupt to be signaled as finished.
1221 */
1222 __STATIC_INLINE void GIC_EndInterrupt(IRQn_Type IRQn)
1223 {
1224   GICInterface->EOIR = IRQn;
1225 }
1226
1227 /** \brief Enables the given interrupt using GIC's ISENABLER register.
1228 * \param [in] IRQn The interrupt to be enabled.
1229 */
1230 __STATIC_INLINE void GIC_EnableIRQ(IRQn_Type IRQn)
1231 {
1232   GICDistributor->ISENABLER[IRQn / 32U] = 1U << (IRQn % 32U);
1233 }
1234
1235 /** \brief Get interrupt enable status using GIC's ISENABLER register.
1236 * \param [in] IRQn The interrupt to be queried.
1237 * \return 0 - interrupt is not enabled, 1 - interrupt is enabled.
1238 */
1239 __STATIC_INLINE uint32_t GIC_GetEnableIRQ(IRQn_Type IRQn)
1240 {
1241   return (GICDistributor->ISENABLER[IRQn / 32U] >> (IRQn % 32U)) & 1UL;
1242 }
1243
1244 /** \brief Disables the given interrupt using GIC's ICENABLER register.
1245 * \param [in] IRQn The interrupt to be disabled.
1246 */
1247 __STATIC_INLINE void GIC_DisableIRQ(IRQn_Type IRQn)
1248 {
1249   GICDistributor->ICENABLER[IRQn / 32U] = 1U << (IRQn % 32U);
1250 }
1251
1252 /** \brief Get interrupt pending status from GIC's ISPENDR register.
1253 * \param [in] IRQn The interrupt to be queried.
1254 * \return 0 - interrupt is not pending, 1 - interrupt is pendig.
1255 */
1256 __STATIC_INLINE uint32_t GIC_GetPendingIRQ(IRQn_Type IRQn)
1257 {
1258   uint32_t pend;
1259
1260   if (IRQn >= 16U) {
1261     pend = (GICDistributor->ISPENDR[IRQn / 32U] >> (IRQn % 32U)) & 1UL;
1262   } else {
1263     // INTID 0-15 Software Generated Interrupt
1264     pend = (GICDistributor->SPENDSGIR[IRQn / 4U] >> ((IRQn % 4U) * 8U)) & 0xFFUL;
1265     // No CPU identification offered
1266     if (pend != 0U) {
1267       pend = 1U;
1268     } else {
1269       pend = 0U;
1270     }
1271   }
1272
1273   return (pend);
1274 }
1275
1276 /** \brief Sets the given interrupt as pending using GIC's ISPENDR register.
1277 * \param [in] IRQn The interrupt to be enabled.
1278 */
1279 __STATIC_INLINE void GIC_SetPendingIRQ(IRQn_Type IRQn)
1280 {
1281   if (IRQn >= 16U) {
1282     GICDistributor->ISPENDR[IRQn / 32U] = 1U << (IRQn % 32U);
1283   } else {
1284     // INTID 0-15 Software Generated Interrupt
1285     GICDistributor->SPENDSGIR[IRQn / 4U] = 1U << ((IRQn % 4U) * 8U);
1286   }
1287 }
1288
1289 /** \brief Clears the given interrupt from being pending using GIC's ICPENDR register.
1290 * \param [in] IRQn The interrupt to be enabled.
1291 */
1292 __STATIC_INLINE void GIC_ClearPendingIRQ(IRQn_Type IRQn)
1293 {
1294   if (IRQn >= 16U) {
1295     GICDistributor->ICPENDR[IRQn / 32U] = 1U << (IRQn % 32U);
1296   } else {
1297     // INTID 0-15 Software Generated Interrupt
1298     GICDistributor->CPENDSGIR[IRQn / 4U] = 1U << ((IRQn % 4U) * 8U);
1299   }
1300 }
1301
1302 /** \brief Sets the interrupt configuration using GIC's ICFGR register.
1303 * \param [in] IRQn The interrupt to be configured.
1304 * \param [in] int_config Int_config field value. Bit 0: Reserved (0 - N-N model, 1 - 1-N model for some GIC before v1)
1305 *                                           Bit 1: 0 - level sensitive, 1 - edge triggered
1306 */
1307 __STATIC_INLINE void GIC_SetConfiguration(IRQn_Type IRQn, uint32_t int_config)
1308 {
1309   uint32_t icfgr = GICDistributor->ICFGR[IRQn / 16U];
1310   uint32_t shift = (IRQn % 16U) << 1U;
1311
1312   icfgr &= (~(3U         << shift));
1313   icfgr |= (  int_config << shift);
1314
1315   GICDistributor->ICFGR[IRQn / 16U] = icfgr;
1316 }
1317
1318 /** \brief Get the interrupt configuration from the GIC's ICFGR register.
1319 * \param [in] IRQn Interrupt to acquire the configuration for.
1320 * \return Int_config field value. Bit 0: Reserved (0 - N-N model, 1 - 1-N model for some GIC before v1)
1321 *                                 Bit 1: 0 - level sensitive, 1 - edge triggered
1322 */
1323 __STATIC_INLINE uint32_t GIC_GetConfiguration(IRQn_Type IRQn)
1324 {
1325   return (GICDistributor->ICFGR[IRQn / 16U] >> ((IRQn % 16U) >> 1U));
1326 }
1327
1328 /** \brief Set the priority for the given interrupt in the GIC's IPRIORITYR register.
1329 * \param [in] IRQn The interrupt to be configured.
1330 * \param [in] priority The priority for the interrupt, lower values denote higher priorities.
1331 */
1332 __STATIC_INLINE void GIC_SetPriority(IRQn_Type IRQn, uint32_t priority)
1333 {
1334   uint32_t mask = GICDistributor->IPRIORITYR[IRQn / 4U] & ~(0xFFUL << ((IRQn % 4U) * 8U));
1335   GICDistributor->IPRIORITYR[IRQn / 4U] = mask | ((priority & 0xFFUL) << ((IRQn % 4U) * 8U));
1336 }
1337
1338 /** \brief Read the current interrupt priority from GIC's IPRIORITYR register.
1339 * \param [in] IRQn The interrupt to be queried.
1340 */
1341 __STATIC_INLINE uint32_t GIC_GetPriority(IRQn_Type IRQn)
1342 {
1343   return (GICDistributor->IPRIORITYR[IRQn / 4U] >> ((IRQn % 4U) * 8U)) & 0xFFUL;
1344 }
1345
1346 /** \brief Set the interrupt priority mask using CPU's PMR register.
1347 * \param [in] priority Priority mask to be set.
1348 */
1349 __STATIC_INLINE void GIC_SetInterfacePriorityMask(uint32_t priority)
1350 {
1351   GICInterface->PMR = priority & 0xFFUL; //set priority mask
1352 }
1353
1354 /** \brief Read the current interrupt priority mask from CPU's PMR register.
1355 * \result GICInterface_Type::PMR
1356 */
1357 __STATIC_INLINE uint32_t GIC_GetInterfacePriorityMask(void)
1358 {
1359   return GICInterface->PMR;
1360 }
1361
1362 /** \brief Configures the group priority and subpriority split point using CPU's BPR register.
1363 * \param [in] binary_point Amount of bits used as subpriority.
1364 */
1365 __STATIC_INLINE void GIC_SetBinaryPoint(uint32_t binary_point)
1366 {
1367   GICInterface->BPR = binary_point & 7U; //set binary point
1368 }
1369
1370 /** \brief Read the current group priority and subpriority split point from CPU's BPR register.
1371 * \return GICInterface_Type::BPR
1372 */
1373 __STATIC_INLINE uint32_t GIC_GetBinaryPoint(void)
1374 {
1375   return GICInterface->BPR;
1376 }
1377
1378 /** \brief Get the status for a given interrupt.
1379 * \param [in] IRQn The interrupt to get status for.
1380 * \return 0 - not pending/active, 1 - pending, 2 - active, 3 - pending and active
1381 */
1382 __STATIC_INLINE uint32_t GIC_GetIRQStatus(IRQn_Type IRQn)
1383 {
1384   uint32_t pending, active;
1385
1386   active = ((GICDistributor->ISACTIVER[IRQn / 32U])  >> (IRQn % 32U)) & 1UL;
1387   pending = ((GICDistributor->ISPENDR[IRQn / 32U]) >> (IRQn % 32U)) & 1UL;
1388
1389   return ((active<<1U) | pending);
1390 }
1391
1392 /** \brief Generate a software interrupt using GIC's SGIR register.
1393 * \param [in] IRQn Software interrupt to be generated.
1394 * \param [in] target_list List of CPUs the software interrupt should be forwarded to.
1395 * \param [in] filter_list Filter to be applied to determine interrupt receivers.
1396 */
1397 __STATIC_INLINE void GIC_SendSGI(IRQn_Type IRQn, uint32_t target_list, uint32_t filter_list)
1398 {
1399   GICDistributor->SGIR = ((filter_list & 3U) << 24U) | ((target_list & 0xFFUL) << 16U) | (IRQn & 0x0FUL);
1400 }
1401
1402 /** \brief Get the interrupt number of the highest interrupt pending from CPU's HPPIR register.
1403 * \return GICInterface_Type::HPPIR
1404 */
1405 __STATIC_INLINE uint32_t GIC_GetHighPendingIRQ(void) 
1406
1407   return GICInterface->HPPIR; 
1408 }
1409
1410 /** \brief Provides information about the implementer and revision of the CPU interface.
1411 * \return GICInterface_Type::IIDR
1412 */
1413 __STATIC_INLINE uint32_t GIC_GetInterfaceId(void)
1414
1415   return GICInterface->IIDR; 
1416 }
1417
1418 /** \brief Set the interrupt group from the GIC's IGROUPR register.
1419 * \param [in] IRQn The interrupt to be queried.
1420 * \param [in] group Interrupt group number: 0 - Group 0, 1 - Group 1
1421 */
1422 __STATIC_INLINE void GIC_SetGroup(IRQn_Type IRQn, uint32_t group)
1423 {
1424   uint32_t igroupr = GICDistributor->IGROUPR[IRQn / 32U];
1425   uint32_t shift   = (IRQn % 32U);
1426
1427   igroupr &= (~(1U          << shift));
1428   igroupr |= ( (group & 1U) << shift);
1429
1430   GICDistributor->IGROUPR[IRQn / 32U] = igroupr;
1431 }
1432 #define GIC_SetSecurity         GIC_SetGroup
1433
1434 /** \brief Get the interrupt group from the GIC's IGROUPR register.
1435 * \param [in] IRQn The interrupt to be queried.
1436 * \return 0 - Group 0, 1 - Group 1
1437 */
1438 __STATIC_INLINE uint32_t GIC_GetGroup(IRQn_Type IRQn)
1439 {
1440   return (GICDistributor->IGROUPR[IRQn / 32U] >> (IRQn % 32U)) & 1UL;
1441 }
1442 #define GIC_GetSecurity         GIC_GetGroup
1443
1444 /** \brief Initialize the interrupt distributor.
1445 */
1446 __STATIC_INLINE void GIC_DistInit(void)
1447 {
1448   uint32_t i;
1449   uint32_t num_irq = 0U;
1450   uint32_t priority_field;
1451
1452   //A reset sets all bits in the IGROUPRs corresponding to the SPIs to 0,
1453   //configuring all of the interrupts as Secure.
1454
1455   //Disable interrupt forwarding
1456   GIC_DisableDistributor();
1457   //Get the maximum number of interrupts that the GIC supports
1458   num_irq = 32U * ((GIC_DistributorInfo() & 0x1FU) + 1U);
1459
1460   /* Priority level is implementation defined.
1461    To determine the number of priority bits implemented write 0xFF to an IPRIORITYR
1462    priority field and read back the value stored.*/
1463   GIC_SetPriority((IRQn_Type)0U, 0xFFU);
1464   priority_field = GIC_GetPriority((IRQn_Type)0U);
1465
1466   for (i = 32U; i < num_irq; i++)
1467   {
1468       //Disable the SPI interrupt
1469       GIC_DisableIRQ((IRQn_Type)i);
1470       //Set level-sensitive (and N-N model)
1471       GIC_SetConfiguration((IRQn_Type)i, 0U);
1472       //Set priority
1473       GIC_SetPriority((IRQn_Type)i, priority_field/2U);
1474       //Set target list to CPU0
1475       GIC_SetTarget((IRQn_Type)i, 1U);
1476   }
1477   //Enable distributor
1478   GIC_EnableDistributor();
1479 }
1480
1481 /** \brief Initialize the CPU's interrupt interface
1482 */
1483 __STATIC_INLINE void GIC_CPUInterfaceInit(void)
1484 {
1485   uint32_t i;
1486   uint32_t priority_field;
1487
1488   //A reset sets all bits in the IGROUPRs corresponding to the SPIs to 0,
1489   //configuring all of the interrupts as Secure.
1490
1491   //Disable interrupt forwarding
1492   GIC_DisableInterface();
1493
1494   /* Priority level is implementation defined.
1495    To determine the number of priority bits implemented write 0xFF to an IPRIORITYR
1496    priority field and read back the value stored.*/
1497   GIC_SetPriority((IRQn_Type)0U, 0xFFU);
1498   priority_field = GIC_GetPriority((IRQn_Type)0U);
1499
1500   //SGI and PPI
1501   for (i = 0U; i < 32U; i++)
1502   {
1503     if(i > 15U) {
1504       //Set level-sensitive (and N-N model) for PPI
1505       GIC_SetConfiguration((IRQn_Type)i, 0U);
1506     }
1507     //Disable SGI and PPI interrupts
1508     GIC_DisableIRQ((IRQn_Type)i);
1509     //Set priority
1510     GIC_SetPriority((IRQn_Type)i, priority_field/2U);
1511   }
1512   //Enable interface
1513   GIC_EnableInterface();
1514   //Set binary point to 0
1515   GIC_SetBinaryPoint(0U);
1516   //Set priority mask
1517   GIC_SetInterfacePriorityMask(0xFFU);
1518 }
1519
1520 /** \brief Initialize and enable the GIC
1521 */
1522 __STATIC_INLINE void GIC_Enable(void)
1523 {
1524   GIC_DistInit();
1525   GIC_CPUInterfaceInit(); //per CPU
1526 }
1527 #endif
1528
1529 /* ##########################  Generic Timer functions  ############################ */
1530 #if (__TIM_PRESENT == 1U) || defined(DOXYGEN)
1531   
1532 /* PL1 Physical Timer */
1533 #if (__CORTEX_A == 7U) || defined(DOXYGEN)
1534   
1535 /** \brief Physical Timer Control register */
1536 typedef union
1537 {
1538   struct
1539   {
1540     uint32_t ENABLE:1;      /*!< \brief bit: 0      Enables the timer. */
1541     uint32_t IMASK:1;       /*!< \brief bit: 1      Timer output signal mask bit. */
1542     uint32_t ISTATUS:1;     /*!< \brief bit: 2      The status of the timer. */
1543     RESERVED(0:29, uint32_t)
1544   } b;                      /*!< \brief Structure used for bit  access */
1545   uint32_t w;               /*!< \brief Type      used for word access */
1546 } CNTP_CTL_Type;
1547
1548 /** \brief Configures the frequency the timer shall run at.
1549 * \param [in] value The timer frequency in Hz.
1550 */
1551 __STATIC_INLINE void PL1_SetCounterFrequency(uint32_t value)
1552 {
1553   __set_CNTFRQ(value);
1554   __ISB();
1555 }
1556
1557 /** \brief Sets the reset value of the timer.
1558 * \param [in] value The value the timer is loaded with.
1559 */
1560 __STATIC_INLINE void PL1_SetLoadValue(uint32_t value)
1561 {
1562   __set_CNTP_TVAL(value);
1563   __ISB();
1564 }
1565
1566 /** \brief Get the current counter value.
1567 * \return Current counter value.
1568 */
1569 __STATIC_INLINE uint32_t PL1_GetCurrentValue(void)
1570 {
1571   return(__get_CNTP_TVAL());
1572 }
1573
1574 /** \brief Get the current physical counter value.
1575 * \return Current physical counter value.
1576 */
1577 __STATIC_INLINE uint64_t PL1_GetCurrentPhysicalValue(void)
1578 {
1579   return(__get_CNTPCT());
1580 }
1581
1582 /** \brief Set the physical compare value.
1583 * \param [in] value New physical timer compare value.
1584 */
1585 __STATIC_INLINE void PL1_SetPhysicalCompareValue(uint64_t value)
1586 {
1587   __set_CNTP_CVAL(value);
1588   __ISB();
1589 }
1590
1591 /** \brief Get the physical compare value.
1592 * \return Physical compare value.
1593 */
1594 __STATIC_INLINE uint64_t PL1_GetPhysicalCompareValue(void)
1595 {
1596   return(__get_CNTP_CVAL());
1597 }
1598
1599 /** \brief Configure the timer by setting the control value.
1600 * \param [in] value New timer control value.
1601 */
1602 __STATIC_INLINE void PL1_SetControl(uint32_t value)
1603 {
1604   __set_CNTP_CTL(value);
1605   __ISB();
1606 }
1607
1608 /** \brief Get the control value.
1609 * \return Control value.
1610 */
1611 __STATIC_INLINE uint32_t PL1_GetControl(void)
1612 {
1613   return(__get_CNTP_CTL());
1614 }
1615 #endif
1616
1617 /* Private Timer */
1618 #if ((__CORTEX_A == 5U) || (__CORTEX_A == 9U)) || defined(DOXYGEN)
1619 /** \brief Set the load value to timers LOAD register.
1620 * \param [in] value The load value to be set.
1621 */
1622 __STATIC_INLINE void PTIM_SetLoadValue(uint32_t value)
1623 {
1624   PTIM->LOAD = value;
1625 }
1626
1627 /** \brief Get the load value from timers LOAD register.
1628 * \return Timer_Type::LOAD
1629 */
1630 __STATIC_INLINE uint32_t PTIM_GetLoadValue(void)
1631 {
1632   return(PTIM->LOAD);
1633 }
1634
1635 /** \brief Set current counter value from its COUNTER register.
1636 */
1637 __STATIC_INLINE void PTIM_SetCurrentValue(uint32_t value)
1638 {
1639   PTIM->COUNTER = value;
1640 }
1641
1642 /** \brief Get current counter value from timers COUNTER register.
1643 * \result Timer_Type::COUNTER
1644 */
1645 __STATIC_INLINE uint32_t PTIM_GetCurrentValue(void)
1646 {
1647   return(PTIM->COUNTER);
1648 }
1649
1650 /** \brief Configure the timer using its CONTROL register.
1651 * \param [in] value The new configuration value to be set.
1652 */
1653 __STATIC_INLINE void PTIM_SetControl(uint32_t value)
1654 {
1655   PTIM->CONTROL = value;
1656 }
1657
1658 /** ref Timer_Type::CONTROL Get the current timer configuration from its CONTROL register.
1659 * \return Timer_Type::CONTROL
1660 */
1661 __STATIC_INLINE uint32_t PTIM_GetControl(void)
1662 {
1663   return(PTIM->CONTROL);
1664 }
1665
1666 /** ref Timer_Type::CONTROL Get the event flag in timers ISR register.
1667 * \return 0 - flag is not set, 1- flag is set
1668 */
1669 __STATIC_INLINE uint32_t PTIM_GetEventFlag(void)
1670 {
1671   return (PTIM->ISR & 1UL);
1672 }
1673
1674 /** ref Timer_Type::CONTROL Clears the event flag in timers ISR register.
1675 */
1676 __STATIC_INLINE void PTIM_ClearEventFlag(void)
1677 {
1678   PTIM->ISR = 1;
1679 }
1680 #endif
1681 #endif
1682
1683 /* ##########################  MMU functions  ###################################### */
1684
1685 #define SECTION_DESCRIPTOR      (0x2)
1686 #define SECTION_MASK            (0xFFFFFFFC)
1687
1688 #define SECTION_TEXCB_MASK      (0xFFFF8FF3)
1689 #define SECTION_B_SHIFT         (2)
1690 #define SECTION_C_SHIFT         (3)
1691 #define SECTION_TEX0_SHIFT      (12)
1692 #define SECTION_TEX1_SHIFT      (13)
1693 #define SECTION_TEX2_SHIFT      (14)
1694
1695 #define SECTION_XN_MASK         (0xFFFFFFEF)
1696 #define SECTION_XN_SHIFT        (4)
1697
1698 #define SECTION_DOMAIN_MASK     (0xFFFFFE1F)
1699 #define SECTION_DOMAIN_SHIFT    (5)
1700
1701 #define SECTION_P_MASK          (0xFFFFFDFF)
1702 #define SECTION_P_SHIFT         (9)
1703
1704 #define SECTION_AP_MASK         (0xFFFF73FF)
1705 #define SECTION_AP_SHIFT        (10)
1706 #define SECTION_AP2_SHIFT       (15)
1707
1708 #define SECTION_S_MASK          (0xFFFEFFFF)
1709 #define SECTION_S_SHIFT         (16)
1710
1711 #define SECTION_NG_MASK         (0xFFFDFFFF)
1712 #define SECTION_NG_SHIFT        (17)
1713
1714 #define SECTION_NS_MASK         (0xFFF7FFFF)
1715 #define SECTION_NS_SHIFT        (19)
1716
1717 #define PAGE_L1_DESCRIPTOR      (0x1)
1718 #define PAGE_L1_MASK            (0xFFFFFFFC)
1719
1720 #define PAGE_L2_4K_DESC         (0x2)
1721 #define PAGE_L2_4K_MASK         (0xFFFFFFFD)
1722
1723 #define PAGE_L2_64K_DESC        (0x1)
1724 #define PAGE_L2_64K_MASK        (0xFFFFFFFC)
1725
1726 #define PAGE_4K_TEXCB_MASK      (0xFFFFFE33)
1727 #define PAGE_4K_B_SHIFT         (2)
1728 #define PAGE_4K_C_SHIFT         (3)
1729 #define PAGE_4K_TEX0_SHIFT      (6)
1730 #define PAGE_4K_TEX1_SHIFT      (7)
1731 #define PAGE_4K_TEX2_SHIFT      (8)
1732
1733 #define PAGE_64K_TEXCB_MASK     (0xFFFF8FF3)
1734 #define PAGE_64K_B_SHIFT        (2)
1735 #define PAGE_64K_C_SHIFT        (3)
1736 #define PAGE_64K_TEX0_SHIFT     (12)
1737 #define PAGE_64K_TEX1_SHIFT     (13)
1738 #define PAGE_64K_TEX2_SHIFT     (14)
1739
1740 #define PAGE_TEXCB_MASK         (0xFFFF8FF3)
1741 #define PAGE_B_SHIFT            (2)
1742 #define PAGE_C_SHIFT            (3)
1743 #define PAGE_TEX_SHIFT          (12)
1744
1745 #define PAGE_XN_4K_MASK         (0xFFFFFFFE)
1746 #define PAGE_XN_4K_SHIFT        (0)
1747 #define PAGE_XN_64K_MASK        (0xFFFF7FFF)
1748 #define PAGE_XN_64K_SHIFT       (15)
1749
1750 #define PAGE_DOMAIN_MASK        (0xFFFFFE1F)
1751 #define PAGE_DOMAIN_SHIFT       (5)
1752
1753 #define PAGE_P_MASK             (0xFFFFFDFF)
1754 #define PAGE_P_SHIFT            (9)
1755
1756 #define PAGE_AP_MASK            (0xFFFFFDCF)
1757 #define PAGE_AP_SHIFT           (4)
1758 #define PAGE_AP2_SHIFT          (9)
1759
1760 #define PAGE_S_MASK             (0xFFFFFBFF)
1761 #define PAGE_S_SHIFT            (10)
1762
1763 #define PAGE_NG_MASK            (0xFFFFF7FF)
1764 #define PAGE_NG_SHIFT           (11)
1765
1766 #define PAGE_NS_MASK            (0xFFFFFFF7)
1767 #define PAGE_NS_SHIFT           (3)
1768
1769 #define OFFSET_1M               (0x00100000)
1770 #define OFFSET_64K              (0x00010000)
1771 #define OFFSET_4K               (0x00001000)
1772
1773 #define DESCRIPTOR_FAULT        (0x00000000)
1774
1775 /* Attributes enumerations */
1776
1777 /* Region size attributes */
1778 typedef enum
1779 {
1780    SECTION,
1781    PAGE_4k,
1782    PAGE_64k,
1783 } mmu_region_size_Type;
1784
1785 /* Region type attributes */
1786 typedef enum
1787 {
1788    NORMAL,
1789    DEVICE,
1790    SHARED_DEVICE,
1791    NON_SHARED_DEVICE,
1792    STRONGLY_ORDERED
1793 } mmu_memory_Type;
1794
1795 /* Region cacheability attributes */
1796 typedef enum
1797 {
1798    NON_CACHEABLE,
1799    WB_WA,
1800    WT,
1801    WB_NO_WA,
1802 } mmu_cacheability_Type;
1803
1804 /* Region parity check attributes */
1805 typedef enum
1806 {
1807    ECC_DISABLED,
1808    ECC_ENABLED,
1809 } mmu_ecc_check_Type;
1810
1811 /* Region execution attributes */
1812 typedef enum
1813 {
1814    EXECUTE,
1815    NON_EXECUTE,
1816 } mmu_execute_Type;
1817
1818 /* Region global attributes */
1819 typedef enum
1820 {
1821    GLOBAL,
1822    NON_GLOBAL,
1823 } mmu_global_Type;
1824
1825 /* Region shareability attributes */
1826 typedef enum
1827 {
1828    NON_SHARED,
1829    SHARED,
1830 } mmu_shared_Type;
1831
1832 /* Region security attributes */
1833 typedef enum
1834 {
1835    SECURE,
1836    NON_SECURE,
1837 } mmu_secure_Type;
1838
1839 /* Region access attributes */
1840 typedef enum
1841 {
1842    NO_ACCESS,
1843    RW,
1844    READ,
1845 } mmu_access_Type;
1846
1847 /* Memory Region definition */
1848 typedef struct RegionStruct {
1849     mmu_region_size_Type rg_t;
1850     mmu_memory_Type mem_t;
1851     uint8_t domain;
1852     mmu_cacheability_Type inner_norm_t;
1853     mmu_cacheability_Type outer_norm_t;
1854     mmu_ecc_check_Type e_t;
1855     mmu_execute_Type xn_t;
1856     mmu_global_Type g_t;
1857     mmu_secure_Type sec_t;
1858     mmu_access_Type priv_t;
1859     mmu_access_Type user_t;
1860     mmu_shared_Type sh_t;
1861
1862 } mmu_region_attributes_Type;
1863
1864 //Following macros define the descriptors and attributes
1865 //Sect_Normal. Outer & inner wb/wa, non-shareable, executable, rw, domain 0
1866 #define section_normal(descriptor_l1, region)     region.rg_t = SECTION; \
1867                                    region.domain = 0x0; \
1868                                    region.e_t = ECC_DISABLED; \
1869                                    region.g_t = GLOBAL; \
1870                                    region.inner_norm_t = WB_WA; \
1871                                    region.outer_norm_t = WB_WA; \
1872                                    region.mem_t = NORMAL; \
1873                                    region.sec_t = SECURE; \
1874                                    region.xn_t = EXECUTE; \
1875                                    region.priv_t = RW; \
1876                                    region.user_t = RW; \
1877                                    region.sh_t = NON_SHARED; \
1878                                    MMU_GetSectionDescriptor(&descriptor_l1, region);
1879
1880 //Sect_Normal_NC. Outer & inner non-cacheable, non-shareable, executable, rw, domain 0
1881 #define section_normal_nc(descriptor_l1, region)     region.rg_t = SECTION; \
1882                                    region.domain = 0x0; \
1883                                    region.e_t = ECC_DISABLED; \
1884                                    region.g_t = GLOBAL; \
1885                                    region.inner_norm_t = NON_CACHEABLE; \
1886                                    region.outer_norm_t = NON_CACHEABLE; \
1887                                    region.mem_t = NORMAL; \
1888                                    region.sec_t = SECURE; \
1889                                    region.xn_t = EXECUTE; \
1890                                    region.priv_t = RW; \
1891                                    region.user_t = RW; \
1892                                    region.sh_t = NON_SHARED; \
1893                                    MMU_GetSectionDescriptor(&descriptor_l1, region);
1894
1895 //Sect_Normal_Cod. Outer & inner wb/wa, non-shareable, executable, ro, domain 0
1896 #define section_normal_cod(descriptor_l1, region) region.rg_t = SECTION; \
1897                                    region.domain = 0x0; \
1898                                    region.e_t = ECC_DISABLED; \
1899                                    region.g_t = GLOBAL; \
1900                                    region.inner_norm_t = WB_WA; \
1901                                    region.outer_norm_t = WB_WA; \
1902                                    region.mem_t = NORMAL; \
1903                                    region.sec_t = SECURE; \
1904                                    region.xn_t = EXECUTE; \
1905                                    region.priv_t = READ; \
1906                                    region.user_t = READ; \
1907                                    region.sh_t = NON_SHARED; \
1908                                    MMU_GetSectionDescriptor(&descriptor_l1, region);
1909
1910 //Sect_Normal_RO. Sect_Normal_Cod, but not executable
1911 #define section_normal_ro(descriptor_l1, region)  region.rg_t = SECTION; \
1912                                    region.domain = 0x0; \
1913                                    region.e_t = ECC_DISABLED; \
1914                                    region.g_t = GLOBAL; \
1915                                    region.inner_norm_t = WB_WA; \
1916                                    region.outer_norm_t = WB_WA; \
1917                                    region.mem_t = NORMAL; \
1918                                    region.sec_t = SECURE; \
1919                                    region.xn_t = NON_EXECUTE; \
1920                                    region.priv_t = READ; \
1921                                    region.user_t = READ; \
1922                                    region.sh_t = NON_SHARED; \
1923                                    MMU_GetSectionDescriptor(&descriptor_l1, region);
1924
1925 //Sect_Normal_RW. Sect_Normal_Cod, but writeable and not executable
1926 #define section_normal_rw(descriptor_l1, region) region.rg_t = SECTION; \
1927                                    region.domain = 0x0; \
1928                                    region.e_t = ECC_DISABLED; \
1929                                    region.g_t = GLOBAL; \
1930                                    region.inner_norm_t = WB_WA; \
1931                                    region.outer_norm_t = WB_WA; \
1932                                    region.mem_t = NORMAL; \
1933                                    region.sec_t = SECURE; \
1934                                    region.xn_t = NON_EXECUTE; \
1935                                    region.priv_t = RW; \
1936                                    region.user_t = RW; \
1937                                    region.sh_t = NON_SHARED; \
1938                                    MMU_GetSectionDescriptor(&descriptor_l1, region);
1939 //Sect_SO. Strongly-ordered (therefore shareable), not executable, rw, domain 0, base addr 0
1940 #define section_so(descriptor_l1, region) region.rg_t = SECTION; \
1941                                    region.domain = 0x0; \
1942                                    region.e_t = ECC_DISABLED; \
1943                                    region.g_t = GLOBAL; \
1944                                    region.inner_norm_t = NON_CACHEABLE; \
1945                                    region.outer_norm_t = NON_CACHEABLE; \
1946                                    region.mem_t = STRONGLY_ORDERED; \
1947                                    region.sec_t = SECURE; \
1948                                    region.xn_t = NON_EXECUTE; \
1949                                    region.priv_t = RW; \
1950                                    region.user_t = RW; \
1951                                    region.sh_t = NON_SHARED; \
1952                                    MMU_GetSectionDescriptor(&descriptor_l1, region);
1953
1954 //Sect_Device_RO. Device, non-shareable, non-executable, ro, domain 0, base addr 0
1955 #define section_device_ro(descriptor_l1, region) region.rg_t = SECTION; \
1956                                    region.domain = 0x0; \
1957                                    region.e_t = ECC_DISABLED; \
1958                                    region.g_t = GLOBAL; \
1959                                    region.inner_norm_t = NON_CACHEABLE; \
1960                                    region.outer_norm_t = NON_CACHEABLE; \
1961                                    region.mem_t = STRONGLY_ORDERED; \
1962                                    region.sec_t = SECURE; \
1963                                    region.xn_t = NON_EXECUTE; \
1964                                    region.priv_t = READ; \
1965                                    region.user_t = READ; \
1966                                    region.sh_t = NON_SHARED; \
1967                                    MMU_GetSectionDescriptor(&descriptor_l1, region);
1968
1969 //Sect_Device_RW. Sect_Device_RO, but writeable
1970 #define section_device_rw(descriptor_l1, region) region.rg_t = SECTION; \
1971                                    region.domain = 0x0; \
1972                                    region.e_t = ECC_DISABLED; \
1973                                    region.g_t = GLOBAL; \
1974                                    region.inner_norm_t = NON_CACHEABLE; \
1975                                    region.outer_norm_t = NON_CACHEABLE; \
1976                                    region.mem_t = STRONGLY_ORDERED; \
1977                                    region.sec_t = SECURE; \
1978                                    region.xn_t = NON_EXECUTE; \
1979                                    region.priv_t = RW; \
1980                                    region.user_t = RW; \
1981                                    region.sh_t = NON_SHARED; \
1982                                    MMU_GetSectionDescriptor(&descriptor_l1, region);
1983 //Page_4k_Device_RW.  Shared device, not executable, rw, domain 0
1984 #define page4k_device_rw(descriptor_l1, descriptor_l2, region) region.rg_t = PAGE_4k; \
1985                                    region.domain = 0x0; \
1986                                    region.e_t = ECC_DISABLED; \
1987                                    region.g_t = GLOBAL; \
1988                                    region.inner_norm_t = NON_CACHEABLE; \
1989                                    region.outer_norm_t = NON_CACHEABLE; \
1990                                    region.mem_t = SHARED_DEVICE; \
1991                                    region.sec_t = SECURE; \
1992                                    region.xn_t = NON_EXECUTE; \
1993                                    region.priv_t = RW; \
1994                                    region.user_t = RW; \
1995                                    region.sh_t = NON_SHARED; \
1996                                    MMU_GetPageDescriptor(&descriptor_l1, &descriptor_l2, region);
1997
1998 //Page_64k_Device_RW.  Shared device, not executable, rw, domain 0
1999 #define page64k_device_rw(descriptor_l1, descriptor_l2, region)  region.rg_t = PAGE_64k; \
2000                                    region.domain = 0x0; \
2001                                    region.e_t = ECC_DISABLED; \
2002                                    region.g_t = GLOBAL; \
2003                                    region.inner_norm_t = NON_CACHEABLE; \
2004                                    region.outer_norm_t = NON_CACHEABLE; \
2005                                    region.mem_t = SHARED_DEVICE; \
2006                                    region.sec_t = SECURE; \
2007                                    region.xn_t = NON_EXECUTE; \
2008                                    region.priv_t = RW; \
2009                                    region.user_t = RW; \
2010                                    region.sh_t = NON_SHARED; \
2011                                    MMU_GetPageDescriptor(&descriptor_l1, &descriptor_l2, region);
2012
2013 /** \brief  Set section execution-never attribute
2014
2015   \param [out]    descriptor_l1  L1 descriptor.
2016   \param [in]                xn  Section execution-never attribute : EXECUTE , NON_EXECUTE.
2017
2018   \return          0
2019 */
2020 __STATIC_INLINE int MMU_XNSection(uint32_t *descriptor_l1, mmu_execute_Type xn)
2021 {
2022   *descriptor_l1 &= SECTION_XN_MASK;
2023   *descriptor_l1 |= ((xn & 0x1) << SECTION_XN_SHIFT);
2024   return 0;
2025 }
2026
2027 /** \brief  Set section domain
2028
2029   \param [out]    descriptor_l1  L1 descriptor.
2030   \param [in]            domain  Section domain
2031
2032   \return          0
2033 */
2034 __STATIC_INLINE int MMU_DomainSection(uint32_t *descriptor_l1, uint8_t domain)
2035 {
2036   *descriptor_l1 &= SECTION_DOMAIN_MASK;
2037   *descriptor_l1 |= ((domain & 0xF) << SECTION_DOMAIN_SHIFT);
2038   return 0;
2039 }
2040
2041 /** \brief  Set section parity check
2042
2043   \param [out]    descriptor_l1  L1 descriptor.
2044   \param [in]              p_bit Parity check: ECC_DISABLED, ECC_ENABLED
2045
2046   \return          0
2047 */
2048 __STATIC_INLINE int MMU_PSection(uint32_t *descriptor_l1, mmu_ecc_check_Type p_bit)
2049 {
2050   *descriptor_l1 &= SECTION_P_MASK;
2051   *descriptor_l1 |= ((p_bit & 0x1) << SECTION_P_SHIFT);
2052   return 0;
2053 }
2054
2055 /** \brief  Set section access privileges
2056
2057   \param [out]    descriptor_l1  L1 descriptor.
2058   \param [in]              user  User Level Access: NO_ACCESS, RW, READ
2059   \param [in]              priv  Privilege Level Access: NO_ACCESS, RW, READ
2060   \param [in]               afe  Access flag enable
2061
2062   \return          0
2063 */
2064 __STATIC_INLINE int MMU_APSection(uint32_t *descriptor_l1, mmu_access_Type user, mmu_access_Type priv, uint32_t afe)
2065 {
2066   uint32_t ap = 0;
2067
2068   if (afe == 0) { //full access
2069     if ((priv == NO_ACCESS) && (user == NO_ACCESS)) { ap = 0x0; }
2070     else if ((priv == RW) && (user == NO_ACCESS))   { ap = 0x1; }
2071     else if ((priv == RW) && (user == READ))        { ap = 0x2; }
2072     else if ((priv == RW) && (user == RW))          { ap = 0x3; }
2073     else if ((priv == READ) && (user == NO_ACCESS)) { ap = 0x5; }
2074     else if ((priv == READ) && (user == READ))      { ap = 0x7; }
2075   }
2076
2077   else { //Simplified access
2078     if ((priv == RW) && (user == NO_ACCESS))        { ap = 0x1; }
2079     else if ((priv == RW) && (user == RW))          { ap = 0x3; }
2080     else if ((priv == READ) && (user == NO_ACCESS)) { ap = 0x5; }
2081     else if ((priv == READ) && (user == READ))      { ap = 0x7; }
2082   }
2083
2084   *descriptor_l1 &= SECTION_AP_MASK;
2085   *descriptor_l1 |= (ap & 0x3) << SECTION_AP_SHIFT;
2086   *descriptor_l1 |= ((ap & 0x4)>>2) << SECTION_AP2_SHIFT;
2087
2088   return 0;
2089 }
2090
2091 /** \brief  Set section shareability
2092
2093   \param [out]    descriptor_l1  L1 descriptor.
2094   \param [in]             s_bit  Section shareability: NON_SHARED, SHARED
2095
2096   \return          0
2097 */
2098 __STATIC_INLINE int MMU_SharedSection(uint32_t *descriptor_l1, mmu_shared_Type s_bit)
2099 {
2100   *descriptor_l1 &= SECTION_S_MASK;
2101   *descriptor_l1 |= ((s_bit & 0x1) << SECTION_S_SHIFT);
2102   return 0;
2103 }
2104
2105 /** \brief  Set section Global attribute
2106
2107   \param [out]    descriptor_l1  L1 descriptor.
2108   \param [in]             g_bit  Section attribute: GLOBAL, NON_GLOBAL
2109
2110   \return          0
2111 */
2112 __STATIC_INLINE int MMU_GlobalSection(uint32_t *descriptor_l1, mmu_global_Type g_bit)
2113 {
2114   *descriptor_l1 &= SECTION_NG_MASK;
2115   *descriptor_l1 |= ((g_bit & 0x1) << SECTION_NG_SHIFT);
2116   return 0;
2117 }
2118
2119 /** \brief  Set section Security attribute
2120
2121   \param [out]    descriptor_l1  L1 descriptor.
2122   \param [in]             s_bit  Section Security attribute: SECURE, NON_SECURE
2123
2124   \return          0
2125 */
2126 __STATIC_INLINE int MMU_SecureSection(uint32_t *descriptor_l1, mmu_secure_Type s_bit)
2127 {
2128   *descriptor_l1 &= SECTION_NS_MASK;
2129   *descriptor_l1 |= ((s_bit & 0x1) << SECTION_NS_SHIFT);
2130   return 0;
2131 }
2132
2133 /* Page 4k or 64k */
2134 /** \brief  Set 4k/64k page execution-never attribute
2135
2136   \param [out]    descriptor_l2  L2 descriptor.
2137   \param [in]                xn  Page execution-never attribute : EXECUTE , NON_EXECUTE.
2138   \param [in]              page  Page size: PAGE_4k, PAGE_64k,
2139
2140   \return          0
2141 */
2142 __STATIC_INLINE int MMU_XNPage(uint32_t *descriptor_l2, mmu_execute_Type xn, mmu_region_size_Type page)
2143 {
2144   if (page == PAGE_4k)
2145   {
2146       *descriptor_l2 &= PAGE_XN_4K_MASK;
2147       *descriptor_l2 |= ((xn & 0x1) << PAGE_XN_4K_SHIFT);
2148   }
2149   else
2150   {
2151       *descriptor_l2 &= PAGE_XN_64K_MASK;
2152       *descriptor_l2 |= ((xn & 0x1) << PAGE_XN_64K_SHIFT);
2153   }
2154   return 0;
2155 }
2156
2157 /** \brief  Set 4k/64k page domain
2158
2159   \param [out]    descriptor_l1  L1 descriptor.
2160   \param [in]            domain  Page domain
2161
2162   \return          0
2163 */
2164 __STATIC_INLINE int MMU_DomainPage(uint32_t *descriptor_l1, uint8_t domain)
2165 {
2166   *descriptor_l1 &= PAGE_DOMAIN_MASK;
2167   *descriptor_l1 |= ((domain & 0xf) << PAGE_DOMAIN_SHIFT);
2168   return 0;
2169 }
2170
2171 /** \brief  Set 4k/64k page parity check
2172
2173   \param [out]    descriptor_l1  L1 descriptor.
2174   \param [in]              p_bit Parity check: ECC_DISABLED, ECC_ENABLED
2175
2176   \return          0
2177 */
2178 __STATIC_INLINE int MMU_PPage(uint32_t *descriptor_l1, mmu_ecc_check_Type p_bit)
2179 {
2180   *descriptor_l1 &= SECTION_P_MASK;
2181   *descriptor_l1 |= ((p_bit & 0x1) << SECTION_P_SHIFT);
2182   return 0;
2183 }
2184
2185 /** \brief  Set 4k/64k page access privileges
2186
2187   \param [out]    descriptor_l2  L2 descriptor.
2188   \param [in]              user  User Level Access: NO_ACCESS, RW, READ
2189   \param [in]              priv  Privilege Level Access: NO_ACCESS, RW, READ
2190   \param [in]               afe  Access flag enable
2191
2192   \return          0
2193 */
2194 __STATIC_INLINE int MMU_APPage(uint32_t *descriptor_l2, mmu_access_Type user, mmu_access_Type priv, uint32_t afe)
2195 {
2196   uint32_t ap = 0;
2197
2198   if (afe == 0) { //full access
2199     if ((priv == NO_ACCESS) && (user == NO_ACCESS)) { ap = 0x0; }
2200     else if ((priv == RW) && (user == NO_ACCESS))   { ap = 0x1; }
2201     else if ((priv == RW) && (user == READ))        { ap = 0x2; }
2202     else if ((priv == RW) && (user == RW))          { ap = 0x3; }
2203     else if ((priv == READ) && (user == NO_ACCESS)) { ap = 0x5; }
2204     else if ((priv == READ) && (user == READ))      { ap = 0x6; }
2205   }
2206
2207   else { //Simplified access
2208     if ((priv == RW) && (user == NO_ACCESS))        { ap = 0x1; }
2209     else if ((priv == RW) && (user == RW))          { ap = 0x3; }
2210     else if ((priv == READ) && (user == NO_ACCESS)) { ap = 0x5; }
2211     else if ((priv == READ) && (user == READ))      { ap = 0x7; }
2212   }
2213
2214   *descriptor_l2 &= PAGE_AP_MASK;
2215   *descriptor_l2 |= (ap & 0x3) << PAGE_AP_SHIFT;
2216   *descriptor_l2 |= ((ap & 0x4)>>2) << PAGE_AP2_SHIFT;
2217
2218   return 0;
2219 }
2220
2221 /** \brief  Set 4k/64k page shareability
2222
2223   \param [out]    descriptor_l2  L2 descriptor.
2224   \param [in]             s_bit  4k/64k page shareability: NON_SHARED, SHARED
2225
2226   \return          0
2227 */
2228 __STATIC_INLINE int MMU_SharedPage(uint32_t *descriptor_l2, mmu_shared_Type s_bit)
2229 {
2230   *descriptor_l2 &= PAGE_S_MASK;
2231   *descriptor_l2 |= ((s_bit & 0x1) << PAGE_S_SHIFT);
2232   return 0;
2233 }
2234
2235 /** \brief  Set 4k/64k page Global attribute
2236
2237   \param [out]    descriptor_l2  L2 descriptor.
2238   \param [in]             g_bit  4k/64k page attribute: GLOBAL, NON_GLOBAL
2239
2240   \return          0
2241 */
2242 __STATIC_INLINE int MMU_GlobalPage(uint32_t *descriptor_l2, mmu_global_Type g_bit)
2243 {
2244   *descriptor_l2 &= PAGE_NG_MASK;
2245   *descriptor_l2 |= ((g_bit & 0x1) << PAGE_NG_SHIFT);
2246   return 0;
2247 }
2248
2249 /** \brief  Set 4k/64k page Security attribute
2250
2251   \param [out]    descriptor_l1  L1 descriptor.
2252   \param [in]             s_bit  4k/64k page Security attribute: SECURE, NON_SECURE
2253
2254   \return          0
2255 */
2256 __STATIC_INLINE int MMU_SecurePage(uint32_t *descriptor_l1, mmu_secure_Type s_bit)
2257 {
2258   *descriptor_l1 &= PAGE_NS_MASK;
2259   *descriptor_l1 |= ((s_bit & 0x1) << PAGE_NS_SHIFT);
2260   return 0;
2261 }
2262
2263 /** \brief  Set Section memory attributes
2264
2265   \param [out]    descriptor_l1  L1 descriptor.
2266   \param [in]               mem  Section memory type: NORMAL, DEVICE, SHARED_DEVICE, NON_SHARED_DEVICE, STRONGLY_ORDERED
2267   \param [in]             outer  Outer cacheability: NON_CACHEABLE, WB_WA, WT, WB_NO_WA,
2268   \param [in]             inner  Inner cacheability: NON_CACHEABLE, WB_WA, WT, WB_NO_WA,
2269
2270   \return          0
2271 */
2272 __STATIC_INLINE int MMU_MemorySection(uint32_t *descriptor_l1, mmu_memory_Type mem, mmu_cacheability_Type outer, mmu_cacheability_Type inner)
2273 {
2274   *descriptor_l1 &= SECTION_TEXCB_MASK;
2275
2276   if (STRONGLY_ORDERED == mem)
2277   {
2278     return 0;
2279   }
2280   else if (SHARED_DEVICE == mem)
2281   {
2282     *descriptor_l1 |= (1 << SECTION_B_SHIFT);
2283   }
2284   else if (NON_SHARED_DEVICE == mem)
2285   {
2286     *descriptor_l1 |= (1 << SECTION_TEX1_SHIFT);
2287   }
2288   else if (NORMAL == mem)
2289   {
2290    *descriptor_l1 |= 1 << SECTION_TEX2_SHIFT;
2291    switch(inner)
2292    {
2293       case NON_CACHEABLE:
2294         break;
2295       case WB_WA:
2296         *descriptor_l1 |= (1 << SECTION_B_SHIFT);
2297         break;
2298       case WT:
2299         *descriptor_l1 |= 1 << SECTION_C_SHIFT;
2300         break;
2301       case WB_NO_WA:
2302         *descriptor_l1 |= (1 << SECTION_B_SHIFT) | (1 << SECTION_C_SHIFT);
2303         break;
2304     }
2305     switch(outer)
2306     {
2307       case NON_CACHEABLE:
2308         break;
2309       case WB_WA:
2310         *descriptor_l1 |= (1 << SECTION_TEX0_SHIFT);
2311         break;
2312       case WT:
2313         *descriptor_l1 |= 1 << SECTION_TEX1_SHIFT;
2314         break;
2315       case WB_NO_WA:
2316         *descriptor_l1 |= (1 << SECTION_TEX0_SHIFT) | (1 << SECTION_TEX0_SHIFT);
2317         break;
2318     }
2319   }
2320   return 0;
2321 }
2322
2323 /** \brief  Set 4k/64k page memory attributes
2324
2325   \param [out]    descriptor_l2  L2 descriptor.
2326   \param [in]               mem  4k/64k page memory type: NORMAL, DEVICE, SHARED_DEVICE, NON_SHARED_DEVICE, STRONGLY_ORDERED
2327   \param [in]             outer  Outer cacheability: NON_CACHEABLE, WB_WA, WT, WB_NO_WA,
2328   \param [in]             inner  Inner cacheability: NON_CACHEABLE, WB_WA, WT, WB_NO_WA,
2329   \param [in]              page  Page size
2330
2331   \return          0
2332 */
2333 __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)
2334 {
2335   *descriptor_l2 &= PAGE_4K_TEXCB_MASK;
2336
2337   if (page == PAGE_64k)
2338   {
2339     //same as section
2340     MMU_MemorySection(descriptor_l2, mem, outer, inner);
2341   }
2342   else
2343   {
2344     if (STRONGLY_ORDERED == mem)
2345     {
2346       return 0;
2347     }
2348     else if (SHARED_DEVICE == mem)
2349     {
2350       *descriptor_l2 |= (1 << PAGE_4K_B_SHIFT);
2351     }
2352     else if (NON_SHARED_DEVICE == mem)
2353     {
2354       *descriptor_l2 |= (1 << PAGE_4K_TEX1_SHIFT);
2355     }
2356     else if (NORMAL == mem)
2357     {
2358       *descriptor_l2 |= 1 << PAGE_4K_TEX2_SHIFT;
2359       switch(inner)
2360       {
2361         case NON_CACHEABLE:
2362           break;
2363         case WB_WA:
2364           *descriptor_l2 |= (1 << PAGE_4K_B_SHIFT);
2365           break;
2366         case WT:
2367           *descriptor_l2 |= 1 << PAGE_4K_C_SHIFT;
2368           break;
2369         case WB_NO_WA:
2370           *descriptor_l2 |= (1 << PAGE_4K_B_SHIFT) | (1 << PAGE_4K_C_SHIFT);
2371           break;
2372       }
2373       switch(outer)
2374       {
2375         case NON_CACHEABLE:
2376           break;
2377         case WB_WA:
2378           *descriptor_l2 |= (1 << PAGE_4K_TEX0_SHIFT);
2379           break;
2380         case WT:
2381           *descriptor_l2 |= 1 << PAGE_4K_TEX1_SHIFT;
2382           break;
2383         case WB_NO_WA:
2384           *descriptor_l2 |= (1 << PAGE_4K_TEX0_SHIFT) | (1 << PAGE_4K_TEX0_SHIFT);
2385           break;
2386       }
2387     }
2388   }
2389
2390   return 0;
2391 }
2392
2393 /** \brief  Create a L1 section descriptor
2394
2395   \param [out]     descriptor  L1 descriptor
2396   \param [in]      reg  Section attributes
2397   
2398   \return          0
2399 */
2400 __STATIC_INLINE int MMU_GetSectionDescriptor(uint32_t *descriptor, mmu_region_attributes_Type reg)
2401 {
2402   *descriptor  = 0;
2403
2404   MMU_MemorySection(descriptor, reg.mem_t, reg.outer_norm_t, reg.inner_norm_t);
2405   MMU_XNSection(descriptor,reg.xn_t);
2406   MMU_DomainSection(descriptor, reg.domain);
2407   MMU_PSection(descriptor, reg.e_t);
2408   MMU_APSection(descriptor, reg.priv_t, reg.user_t, 1);
2409   MMU_SharedSection(descriptor,reg.sh_t);
2410   MMU_GlobalSection(descriptor,reg.g_t);
2411   MMU_SecureSection(descriptor,reg.sec_t);
2412   *descriptor &= SECTION_MASK;
2413   *descriptor |= SECTION_DESCRIPTOR;
2414  
2415   return 0;
2416 }
2417
2418
2419 /** \brief  Create a L1 and L2 4k/64k page descriptor
2420
2421   \param [out]       descriptor  L1 descriptor
2422   \param [out]      descriptor2  L2 descriptor
2423   \param [in]               reg  4k/64k page attributes
2424
2425   \return          0
2426 */
2427 __STATIC_INLINE int MMU_GetPageDescriptor(uint32_t *descriptor, uint32_t *descriptor2, mmu_region_attributes_Type reg)
2428 {
2429   *descriptor  = 0;
2430   *descriptor2 = 0;
2431
2432   switch (reg.rg_t)
2433   {
2434     case PAGE_4k:
2435       MMU_MemoryPage(descriptor2, reg.mem_t, reg.outer_norm_t, reg.inner_norm_t, PAGE_4k);
2436       MMU_XNPage(descriptor2, reg.xn_t, PAGE_4k);
2437       MMU_DomainPage(descriptor, reg.domain);
2438       MMU_PPage(descriptor, reg.e_t);
2439       MMU_APPage(descriptor2, reg.priv_t, reg.user_t, 1);
2440       MMU_SharedPage(descriptor2,reg.sh_t);
2441       MMU_GlobalPage(descriptor2,reg.g_t);
2442       MMU_SecurePage(descriptor,reg.sec_t);
2443       *descriptor &= PAGE_L1_MASK;
2444       *descriptor |= PAGE_L1_DESCRIPTOR;
2445       *descriptor2 &= PAGE_L2_4K_MASK;
2446       *descriptor2 |= PAGE_L2_4K_DESC;
2447       break;
2448
2449     case PAGE_64k:
2450       MMU_MemoryPage(descriptor2, reg.mem_t, reg.outer_norm_t, reg.inner_norm_t, PAGE_64k);
2451       MMU_XNPage(descriptor2, reg.xn_t, PAGE_64k);
2452       MMU_DomainPage(descriptor, reg.domain);
2453       MMU_PPage(descriptor, reg.e_t);
2454       MMU_APPage(descriptor2, reg.priv_t, reg.user_t, 1);
2455       MMU_SharedPage(descriptor2,reg.sh_t);
2456       MMU_GlobalPage(descriptor2,reg.g_t);
2457       MMU_SecurePage(descriptor,reg.sec_t);
2458       *descriptor &= PAGE_L1_MASK;
2459       *descriptor |= PAGE_L1_DESCRIPTOR;
2460       *descriptor2 &= PAGE_L2_64K_MASK;
2461       *descriptor2 |= PAGE_L2_64K_DESC;
2462       break;
2463
2464     case SECTION:
2465       //error
2466       break;
2467   }
2468   
2469   return 0;
2470 }
2471
2472 /** \brief  Create a 1MB Section
2473
2474   \param [in]               ttb  Translation table base address
2475   \param [in]      base_address  Section base address
2476   \param [in]             count  Number of sections to create
2477   \param [in]     descriptor_l1  L1 descriptor (region attributes)
2478
2479 */
2480 __STATIC_INLINE void MMU_TTSection(uint32_t *ttb, uint32_t base_address, uint32_t count, uint32_t descriptor_l1)
2481 {
2482   uint32_t offset;
2483   uint32_t entry;
2484   uint32_t i;
2485
2486   offset = base_address >> 20;
2487   entry  = (base_address & 0xFFF00000) | descriptor_l1;
2488
2489   //4 bytes aligned
2490   ttb = ttb + offset;
2491
2492   for (i = 0; i < count; i++ )
2493   {
2494     //4 bytes aligned
2495     *ttb++ = entry;
2496     entry += OFFSET_1M;
2497   }
2498 }
2499
2500 /** \brief  Create a 4k page entry
2501
2502   \param [in]               ttb  L1 table base address
2503   \param [in]      base_address  4k base address
2504   \param [in]             count  Number of 4k pages to create
2505   \param [in]     descriptor_l1  L1 descriptor (region attributes)
2506   \param [in]            ttb_l2  L2 table base address
2507   \param [in]     descriptor_l2  L2 descriptor (region attributes)
2508
2509 */
2510 __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 )
2511 {
2512
2513   uint32_t offset, offset2;
2514   uint32_t entry, entry2;
2515   uint32_t i;
2516
2517   offset = base_address >> 20;
2518   entry  = ((int)ttb_l2 & 0xFFFFFC00) | descriptor_l1;
2519
2520   //4 bytes aligned
2521   ttb += offset;
2522   //create l1_entry
2523   *ttb = entry;
2524
2525   offset2 = (base_address & 0xff000) >> 12;
2526   ttb_l2 += offset2;
2527   entry2 = (base_address & 0xFFFFF000) | descriptor_l2;
2528   for (i = 0; i < count; i++ )
2529   {
2530     //4 bytes aligned
2531     *ttb_l2++ = entry2;
2532     entry2 += OFFSET_4K;
2533   }
2534 }
2535
2536 /** \brief  Create a 64k page entry
2537
2538   \param [in]               ttb  L1 table base address
2539   \param [in]      base_address  64k base address
2540   \param [in]             count  Number of 64k pages to create
2541   \param [in]     descriptor_l1  L1 descriptor (region attributes)
2542   \param [in]            ttb_l2  L2 table base address
2543   \param [in]     descriptor_l2  L2 descriptor (region attributes)
2544
2545 */
2546 __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 )
2547 {
2548   uint32_t offset, offset2;
2549   uint32_t entry, entry2;
2550   uint32_t i,j;
2551
2552
2553   offset = base_address >> 20;
2554   entry  = ((int)ttb_l2 & 0xFFFFFC00) | descriptor_l1;
2555
2556   //4 bytes aligned
2557   ttb += offset;
2558   //create l1_entry
2559   *ttb = entry;
2560
2561   offset2 = (base_address & 0xff000) >> 12;
2562   ttb_l2 += offset2;
2563   entry2 = (base_address & 0xFFFF0000) | descriptor_l2;
2564   for (i = 0; i < count; i++ )
2565   {
2566     //create 16 entries
2567     for (j = 0; j < 16; j++)
2568     {
2569       //4 bytes aligned
2570       *ttb_l2++ = entry2;
2571     }
2572     entry2 += OFFSET_64K;
2573   }
2574 }
2575
2576 /** \brief  Enable MMU
2577 */
2578 __STATIC_INLINE void MMU_Enable(void)
2579 {
2580   // Set M bit 0 to enable the MMU
2581   // Set AFE bit to enable simplified access permissions model
2582   // Clear TRE bit to disable TEX remap and A bit to disable strict alignment fault checking
2583   __set_SCTLR( (__get_SCTLR() & ~(1 << 28) & ~(1 << 1)) | 1 | (1 << 29));
2584   __ISB();
2585 }
2586
2587 /** \brief  Disable MMU
2588 */
2589 __STATIC_INLINE void MMU_Disable(void)
2590 {
2591   // Clear M bit 0 to disable the MMU
2592   __set_SCTLR( __get_SCTLR() & ~1);
2593   __ISB();
2594 }
2595
2596 /** \brief  Invalidate entire unified TLB
2597 */
2598
2599 __STATIC_INLINE void MMU_InvalidateTLB(void)
2600 {
2601   __set_TLBIALL(0);
2602   __DSB();     //ensure completion of the invalidation
2603   __ISB();     //ensure instruction fetch path sees new state
2604 }
2605
2606
2607 #ifdef __cplusplus
2608 }
2609 #endif
2610
2611 #endif /* __CORE_CA_H_DEPENDANT */
2612
2613 #endif /* __CMSIS_GENERIC */