diff options
Diffstat (limited to 'lib/chibios-contrib/ext/mcux-sdk/devices/MKE02Z4/system_MKE02Z4.c')
-rw-r--r-- | lib/chibios-contrib/ext/mcux-sdk/devices/MKE02Z4/system_MKE02Z4.c | 140 |
1 files changed, 140 insertions, 0 deletions
diff --git a/lib/chibios-contrib/ext/mcux-sdk/devices/MKE02Z4/system_MKE02Z4.c b/lib/chibios-contrib/ext/mcux-sdk/devices/MKE02Z4/system_MKE02Z4.c new file mode 100644 index 000000000..1bbb56505 --- /dev/null +++ b/lib/chibios-contrib/ext/mcux-sdk/devices/MKE02Z4/system_MKE02Z4.c | |||
@@ -0,0 +1,140 @@ | |||
1 | /* | ||
2 | ** ################################################################### | ||
3 | ** Processors: MKE02Z16VFM4 | ||
4 | ** MKE02Z16VLC4 | ||
5 | ** MKE02Z16VLD4 | ||
6 | ** MKE02Z32VFM4 | ||
7 | ** MKE02Z32VLC4 | ||
8 | ** MKE02Z32VLD4 | ||
9 | ** MKE02Z32VLH4 | ||
10 | ** MKE02Z32VQH4 | ||
11 | ** MKE02Z64VFM4 | ||
12 | ** MKE02Z64VLC4 | ||
13 | ** MKE02Z64VLD4 | ||
14 | ** MKE02Z64VLH4 | ||
15 | ** MKE02Z64VQH4 | ||
16 | ** | ||
17 | ** Compilers: Freescale C/C++ for Embedded ARM | ||
18 | ** GNU C Compiler | ||
19 | ** IAR ANSI C/C++ Compiler for ARM | ||
20 | ** Keil ARM C/C++ Compiler | ||
21 | ** MCUXpresso Compiler | ||
22 | ** | ||
23 | ** Reference manual: MKE02P64M40SF0RM Rev 4 | ||
24 | ** Version: rev. 1.0, 2017-05-19 | ||
25 | ** Build: b201123 | ||
26 | ** | ||
27 | ** Abstract: | ||
28 | ** Provides a system configuration function and a global variable that | ||
29 | ** contains the system frequency. It configures the device and initializes | ||
30 | ** the oscillator (PLL) that is part of the microcontroller device. | ||
31 | ** | ||
32 | ** Copyright 2016 Freescale Semiconductor, Inc. | ||
33 | ** Copyright 2016-2020 NXP | ||
34 | ** All rights reserved. | ||
35 | ** | ||
36 | ** SPDX-License-Identifier: BSD-3-Clause | ||
37 | ** | ||
38 | ** http: www.nxp.com | ||
39 | ** mail: [email protected] | ||
40 | ** | ||
41 | ** Revisions: | ||
42 | ** - rev. 1.0 (2017-05-19) | ||
43 | ** Initial version. | ||
44 | ** | ||
45 | ** ################################################################### | ||
46 | */ | ||
47 | |||
48 | /*! | ||
49 | * @file MKE02Z4 | ||
50 | * @version 1.0 | ||
51 | * @date 2017-05-19 | ||
52 | * @brief Device specific configuration file for MKE02Z4 (implementation file) | ||
53 | * | ||
54 | * Provides a system configuration function and a global variable that contains | ||
55 | * the system frequency. It configures the device and initializes the oscillator | ||
56 | * (PLL) that is part of the microcontroller device. | ||
57 | */ | ||
58 | |||
59 | #include <stdint.h> | ||
60 | #include "fsl_device_registers.h" | ||
61 | |||
62 | |||
63 | |||
64 | /* ---------------------------------------------------------------------------- | ||
65 | -- Core clock | ||
66 | ---------------------------------------------------------------------------- */ | ||
67 | |||
68 | uint32_t SystemCoreClock = DEFAULT_SYSTEM_CLOCK; | ||
69 | |||
70 | /* ---------------------------------------------------------------------------- | ||
71 | -- SystemInit() | ||
72 | ---------------------------------------------------------------------------- */ | ||
73 | |||
74 | void SystemInit (void) { | ||
75 | |||
76 | #if (DISABLE_WDOG) | ||
77 | WDOG->CNT = WDOG_UPDATE_KEY1; | ||
78 | WDOG->CNT = WDOG_UPDATE_KEY2; | ||
79 | WDOG->TOVAL = 0xFFFFU; | ||
80 | WDOG->CS1 = (uint8_t) ((WDOG->CS1) & ~WDOG_CS1_EN_MASK) | WDOG_CS1_UPDATE_MASK; | ||
81 | WDOG->CS2 |= 0U; | ||
82 | #endif /* (DISABLE_WDOG) */ | ||
83 | |||
84 | SystemInitHook(); | ||
85 | } | ||
86 | |||
87 | /* ---------------------------------------------------------------------------- | ||
88 | -- SystemCoreClockUpdate() | ||
89 | ---------------------------------------------------------------------------- */ | ||
90 | |||
91 | void SystemCoreClockUpdate (void) { | ||
92 | |||
93 | uint32_t ICSOUTClock; /* Variable to store output clock frequency of the ICS module */ | ||
94 | uint16_t Divider; | ||
95 | uint16_t Temp; | ||
96 | |||
97 | Divider = (uint16_t)(0x01U) << (((uint16_t)ICS->C2 & ICS_C2_BDIV_MASK) >> ICS_C2_BDIV_SHIFT); | ||
98 | |||
99 | switch ((ICS->C1 & ICS_C1_CLKS_MASK) >> ICS_C1_CLKS_SHIFT) { | ||
100 | case 0x0: | ||
101 | /* FLL */ | ||
102 | if((ICS->C1 & ICS_C1_IREFS_MASK) != 0x0U) | ||
103 | { | ||
104 | ICSOUTClock = CPU_INT_IRC_CLK_HZ * 1024UL; | ||
105 | } | ||
106 | else | ||
107 | { | ||
108 | /* Reference Divider */ | ||
109 | Temp = ((uint16_t)ICS->C1 & ICS_C1_RDIV_MASK) >> ICS_C1_RDIV_SHIFT; | ||
110 | Temp = (Temp + 1U) * (((OSC->CR & OSC_CR_RANGE_MASK) != 0x0U) ? 32U : 1U); | ||
111 | |||
112 | ICSOUTClock = CPU_XTAL_CLK_HZ / Temp * 1024UL; | ||
113 | } | ||
114 | break; | ||
115 | |||
116 | case 0x1: | ||
117 | /* Internal IRC */ | ||
118 | ICSOUTClock = CPU_INT_IRC_CLK_HZ; | ||
119 | break; | ||
120 | |||
121 | case 0x2: | ||
122 | /* External OSC */ | ||
123 | ICSOUTClock = CPU_XTAL_CLK_HZ; | ||
124 | break; | ||
125 | |||
126 | default: | ||
127 | ICSOUTClock = 0U; | ||
128 | break; | ||
129 | } | ||
130 | SystemCoreClock = (ICSOUTClock / Divider); | ||
131 | |||
132 | } | ||
133 | |||
134 | /* ---------------------------------------------------------------------------- | ||
135 | -- SystemInitHook() | ||
136 | ---------------------------------------------------------------------------- */ | ||
137 | |||
138 | __attribute__ ((weak)) void SystemInitHook (void) { | ||
139 | /* Void implementation of the weak function. */ | ||
140 | } | ||