]> begriffs open source - cmsis/blob - CMSIS/Core/Template/Device_A/Source/system_Device.c
Reworked CMSIS-Core(M) and Core(A) docs for CMSIS 6. (#47)
[cmsis] / CMSIS / Core / Template / Device_A / Source / system_Device.c
1 /******************************************************************************
2  * @file     system_<Device>.c
3  * @brief    CMSIS Cortex-A Device Peripheral Access Layer 
4  * @version  V1.00
5  * @date     10. January 2018
6  ******************************************************************************/
7 /*
8  * Copyright (c) 2009-2018 Arm Limited. All rights reserved.
9  *
10  * SPDX-License-Identifier: Apache-2.0
11  *
12  * Licensed under the Apache License, Version 2.0 (the License); you may
13  * not use this file except in compliance with the License.
14  * You may obtain a copy of the License at
15  *
16  * www.apache.org/licenses/LICENSE-2.0
17  *
18  * Unless required by applicable law or agreed to in writing, software
19  * distributed under the License is distributed on an AS IS BASIS, WITHOUT
20  * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
21  * See the License for the specific language governing permissions and
22  * limitations under the License.
23  */
24
25 #include <stdint.h>
26 #include "<Device>.h" /* ToDo: replace '<Device>' with your device name */
27 #include "irq_ctrl.h"
28
29 /*----------------------------------------------------------------------------
30   Define clocks
31  *----------------------------------------------------------------------------*/
32 /* ToDo: add here your necessary defines for device initialization
33          following is an example for different system frequencies */
34 #define XTAL            (12000000U)       /* Oscillator frequency             */
35
36 #define SYSTEM_CLOCK    (5 * XTAL)
37
38
39 /*----------------------------------------------------------------------------
40   System Core Clock Variable
41  *----------------------------------------------------------------------------*/
42 /* ToDo: initialize SystemCoreClock with the system core clock frequency value
43          achieved after system intitialization.
44          This means system core clock frequency after call to SystemInit() */
45 uint32_t SystemCoreClock = SYSTEM_CLOCK;  /* System Clock Frequency (Core Clock)*/
46
47
48
49 /*----------------------------------------------------------------------------
50   Clock functions
51  *----------------------------------------------------------------------------*/
52
53 void SystemCoreClockUpdate (void)            /* Get Core Clock Frequency      */
54 {
55 /* ToDo: add code to calculate the system frequency based upon the current
56          register settings.
57          This function can be used to retrieve the system core clock frequeny
58          after user changed register sittings. */
59   SystemCoreClock = SYSTEM_CLOCK;
60 }
61
62
63 /*----------------------------------------------------------------------------
64   System Initialization
65  *----------------------------------------------------------------------------*/
66 void SystemInit (void)
67 {
68 /* ToDo: add code to initialize the system
69    Do not use global variables because this function is called before
70    reaching pre-main. RW section may be overwritten afterwards.          */
71   SystemCoreClock = SYSTEM_CLOCK;
72
73   // Invalidate entire Unified TLB
74   __set_TLBIALL(0);
75
76   // Invalidate entire branch predictor array
77   __set_BPIALL(0);
78   __DSB();
79   __ISB();
80
81   //  Invalidate instruction cache and flush branch target cache
82   __set_ICIALLU(0);
83   __DSB();
84   __ISB();
85
86   //  Invalidate data cache
87   L1C_InvalidateDCacheAll();
88   
89   // Create Translation Table
90   MMU_CreateTranslationTable();
91
92   // Enable MMU
93   MMU_Enable();
94
95   // Enable Caches
96   L1C_EnableCaches();
97   L1C_EnableBTAC();
98
99 #if (__L2C_PRESENT == 1) 
100   // Enable GIC
101   L2C_Enable();
102 #endif
103
104 #if ((__FPU_PRESENT == 1) && (__FPU_USED == 1))
105   // Enable FPU
106   __FPU_Enable();
107 #endif
108
109   // IRQ Initialize
110   IRQ_Initialize();
111 }