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