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