|
@@ -1,53 +1,39 @@
|
|
#include "all-headers.h"
|
|
#include "all-headers.h"
|
|
|
|
|
|
-
|
|
+
|
|
-
|
|
|
|
-
|
|
|
|
|
|
|
|
static uint32_t gMicrocontrollerSerialNumber ;
|
|
static uint32_t gMicrocontrollerSerialNumber ;
|
|
static uint32_t readMicrocontrollerSerialNumber (void) ;
|
|
static uint32_t readMicrocontrollerSerialNumber (void) ;
|
|
|
|
|
|
-
|
|
|
|
|
|
|
|
-
|
|
|
|
|
|
|
|
|
|
|
|
-
|
|
+
|
|
-
|
|
|
|
|
|
|
|
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
-
|
|
+
|
|
-
|
|
|
|
|
|
|
|
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
-
|
|
+
|
|
-
|
|
|
|
|
|
|
|
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
-
|
|
+
|
|
-
|
|
|
|
|
|
|
|
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
-
|
|
+
|
|
-
|
|
|
|
|
|
|
|
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@@ -61,9 +47,8 @@ static uint32_t readMicrocontrollerSerialNumber (void) ;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
-
|
|
+
|
|
|
|
|
|
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@@ -77,211 +62,198 @@ static uint32_t readMicrocontrollerSerialNumber (void) ;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|
|
|
|
|
|
|
|
+
|
|
#ifndef CPU_MHZ
|
|
#ifndef CPU_MHZ
|
|
- #error "CPU_MHZ is not defined"
|
|
+#error "CPU_MHZ is not defined"
|
|
- static const uint32_t K_MCG_C5_PRDIV = 0 ;
|
|
+static const uint32_t K_MCG_C5_PRDIV = 0 ;
|
|
#elif CPU_MHZ == 240
|
|
#elif CPU_MHZ == 240
|
|
- static const uint32_t K_MCG_C5_PRDIV = 0 ;
|
|
+static const uint32_t K_MCG_C5_PRDIV = 0 ;
|
|
#elif CPU_MHZ == 216
|
|
#elif CPU_MHZ == 216
|
|
- static const uint32_t K_MCG_C5_PRDIV = 0 ;
|
|
+static const uint32_t K_MCG_C5_PRDIV = 0 ;
|
|
#elif CPU_MHZ == 192
|
|
#elif CPU_MHZ == 192
|
|
- static const uint32_t K_MCG_C5_PRDIV = 0 ;
|
|
+static const uint32_t K_MCG_C5_PRDIV = 0 ;
|
|
#elif CPU_MHZ == 180
|
|
#elif CPU_MHZ == 180
|
|
- static const uint32_t K_MCG_C5_PRDIV = 1 ;
|
|
+static const uint32_t K_MCG_C5_PRDIV = 1 ;
|
|
#elif CPU_MHZ == 168
|
|
#elif CPU_MHZ == 168
|
|
- static const uint32_t K_MCG_C5_PRDIV = 0 ;
|
|
+static const uint32_t K_MCG_C5_PRDIV = 0 ;
|
|
#elif CPU_MHZ == 144
|
|
#elif CPU_MHZ == 144
|
|
- static const uint32_t K_MCG_C5_PRDIV = 0 ;
|
|
+static const uint32_t K_MCG_C5_PRDIV = 0 ;
|
|
#elif CPU_MHZ == 120
|
|
#elif CPU_MHZ == 120
|
|
- static const uint32_t K_MCG_C5_PRDIV = 1 ;
|
|
+static const uint32_t K_MCG_C5_PRDIV = 1 ;
|
|
#elif CPU_MHZ == 96
|
|
#elif CPU_MHZ == 96
|
|
- static const uint32_t K_MCG_C5_PRDIV = 1 ;
|
|
+static const uint32_t K_MCG_C5_PRDIV = 1 ;
|
|
#elif CPU_MHZ == 72
|
|
#elif CPU_MHZ == 72
|
|
- static const uint32_t K_MCG_C5_PRDIV = 1 ;
|
|
+static const uint32_t K_MCG_C5_PRDIV = 1 ;
|
|
#elif CPU_MHZ == 48
|
|
#elif CPU_MHZ == 48
|
|
- static const uint32_t K_MCG_C5_PRDIV = 1 ;
|
|
+static const uint32_t K_MCG_C5_PRDIV = 1 ;
|
|
#elif CPU_MHZ == 24
|
|
#elif CPU_MHZ == 24
|
|
- static const uint32_t K_MCG_C5_PRDIV = 1 ;
|
|
+static const uint32_t K_MCG_C5_PRDIV = 1 ;
|
|
#else
|
|
#else
|
|
- #error "CPU_MHZ has an invalid value"
|
|
+#error "CPU_MHZ has an invalid value"
|
|
- static const uint32_t K_MCG_C5_PRDIV = 0 ;
|
|
+static const uint32_t K_MCG_C5_PRDIV = 0 ;
|
|
#endif
|
|
#endif
|
|
|
|
|
|
-
|
|
|
|
|
|
|
|
-
|
|
|
|
-
|
|
|
|
#ifndef CPU_MHZ
|
|
#ifndef CPU_MHZ
|
|
- #error "CPU_MHZ is not defined"
|
|
+#error "CPU_MHZ is not defined"
|
|
- static const uint32_t K_MCG_C6_VDIV = 0 ;
|
|
+static const uint32_t K_MCG_C6_VDIV = 0 ;
|
|
#elif CPU_MHZ == 240
|
|
#elif CPU_MHZ == 240
|
|
- static const uint32_t K_MCG_C6_VDIV = 14 ;
|
|
+static const uint32_t K_MCG_C6_VDIV = 14 ;
|
|
#elif CPU_MHZ == 216
|
|
#elif CPU_MHZ == 216
|
|
- static const uint32_t K_MCG_C6_VDIV = 11 ;
|
|
+static const uint32_t K_MCG_C6_VDIV = 11 ;
|
|
#elif CPU_MHZ == 192
|
|
#elif CPU_MHZ == 192
|
|
- static const uint32_t K_MCG_C6_VDIV = 8 ;
|
|
+static const uint32_t K_MCG_C6_VDIV = 8 ;
|
|
#elif CPU_MHZ == 180
|
|
#elif CPU_MHZ == 180
|
|
- static const uint32_t K_MCG_C6_VDIV = 29 ;
|
|
+static const uint32_t K_MCG_C6_VDIV = 29 ;
|
|
#elif CPU_MHZ == 168
|
|
#elif CPU_MHZ == 168
|
|
- static const uint32_t K_MCG_C6_VDIV = 5 ;
|
|
+static const uint32_t K_MCG_C6_VDIV = 5 ;
|
|
#elif CPU_MHZ == 144
|
|
#elif CPU_MHZ == 144
|
|
- static const uint32_t K_MCG_C6_VDIV = 2 ;
|
|
+static const uint32_t K_MCG_C6_VDIV = 2 ;
|
|
#elif CPU_MHZ == 120
|
|
#elif CPU_MHZ == 120
|
|
- static const uint32_t K_MCG_C6_VDIV = 14 ;
|
|
+static const uint32_t K_MCG_C6_VDIV = 14 ;
|
|
#elif CPU_MHZ == 96
|
|
#elif CPU_MHZ == 96
|
|
- static const uint32_t K_MCG_C6_VDIV = 8 ;
|
|
+static const uint32_t K_MCG_C6_VDIV = 8 ;
|
|
#elif CPU_MHZ == 72
|
|
#elif CPU_MHZ == 72
|
|
- static const uint32_t K_MCG_C6_VDIV = 2 ;
|
|
+static const uint32_t K_MCG_C6_VDIV = 2 ;
|
|
#elif CPU_MHZ == 48
|
|
#elif CPU_MHZ == 48
|
|
- static const uint32_t K_MCG_C6_VDIV = 8 ;
|
|
+static const uint32_t K_MCG_C6_VDIV = 8 ;
|
|
#elif CPU_MHZ == 24
|
|
#elif CPU_MHZ == 24
|
|
- static const uint32_t K_MCG_C6_VDIV = 8 ;
|
|
+static const uint32_t K_MCG_C6_VDIV = 8 ;
|
|
#else
|
|
#else
|
|
- #error "CPU_MHZ has an invalid value"
|
|
+#error "CPU_MHZ has an invalid value"
|
|
- static const uint32_t K_MCG_C6_VDIV = 0 ;
|
|
+static const uint32_t K_MCG_C6_VDIV = 0 ;
|
|
#endif
|
|
#endif
|
|
|
|
|
|
-
|
|
|
|
|
|
|
|
-
|
|
|
|
-
|
|
|
|
#ifndef CPU_MHZ
|
|
#ifndef CPU_MHZ
|
|
- #error "CPU_MHZ is not defined"
|
|
+#error "CPU_MHZ is not defined"
|
|
- static const uint32_t K_SIM_CLKDIV1_OUTDIV1 = 0 ;
|
|
+static const uint32_t K_SIM_CLKDIV1_OUTDIV1 = 0 ;
|
|
#elif CPU_MHZ == 48
|
|
#elif CPU_MHZ == 48
|
|
- static const uint32_t K_SIM_CLKDIV1_OUTDIV1 = 1 ;
|
|
+static const uint32_t K_SIM_CLKDIV1_OUTDIV1 = 1 ;
|
|
#elif CPU_MHZ == 24
|
|
#elif CPU_MHZ == 24
|
|
- static const uint32_t K_SIM_CLKDIV1_OUTDIV1 = 3 ;
|
|
+static const uint32_t K_SIM_CLKDIV1_OUTDIV1 = 3 ;
|
|
#else
|
|
#else
|
|
- static const uint32_t K_SIM_CLKDIV1_OUTDIV1 = 0 ;
|
|
+static const uint32_t K_SIM_CLKDIV1_OUTDIV1 = 0 ;
|
|
#endif
|
|
#endif
|
|
|
|
|
|
-
|
|
+
|
|
|
|
|
|
-
|
|
|
|
|
|
|
|
#ifndef CPU_MHZ
|
|
#ifndef CPU_MHZ
|
|
- #error "CPU_MHZ is not defined"
|
|
+#error "CPU_MHZ is not defined"
|
|
- static const uint32_t K_SIM_CLKDIV1_OUTDIV2 = 0 ;
|
|
+static const uint32_t K_SIM_CLKDIV1_OUTDIV2 = 0 ;
|
|
#elif CPU_MHZ == 240
|
|
#elif CPU_MHZ == 240
|
|
- static const uint32_t K_SIM_CLKDIV1_OUTDIV2 = 3 ;
|
|
+static const uint32_t K_SIM_CLKDIV1_OUTDIV2 = 3 ;
|
|
#elif CPU_MHZ == 216
|
|
#elif CPU_MHZ == 216
|
|
- static const uint32_t K_SIM_CLKDIV1_OUTDIV2 = 3 ;
|
|
+static const uint32_t K_SIM_CLKDIV1_OUTDIV2 = 3 ;
|
|
#elif CPU_MHZ == 192
|
|
#elif CPU_MHZ == 192
|
|
- static const uint32_t K_SIM_CLKDIV1_OUTDIV2 = 3 ;
|
|
+static const uint32_t K_SIM_CLKDIV1_OUTDIV2 = 3 ;
|
|
#elif CPU_MHZ == 180
|
|
#elif CPU_MHZ == 180
|
|
- static const uint32_t K_SIM_CLKDIV1_OUTDIV2 = 2 ;
|
|
+static const uint32_t K_SIM_CLKDIV1_OUTDIV2 = 2 ;
|
|
#elif CPU_MHZ == 168
|
|
#elif CPU_MHZ == 168
|
|
- static const uint32_t K_SIM_CLKDIV1_OUTDIV2 = 2 ;
|
|
+static const uint32_t K_SIM_CLKDIV1_OUTDIV2 = 2 ;
|
|
#elif CPU_MHZ == 144
|
|
#elif CPU_MHZ == 144
|
|
- static const uint32_t K_SIM_CLKDIV1_OUTDIV2 = 2 ;
|
|
+static const uint32_t K_SIM_CLKDIV1_OUTDIV2 = 2 ;
|
|
#elif CPU_MHZ == 120
|
|
#elif CPU_MHZ == 120
|
|
- static const uint32_t K_SIM_CLKDIV1_OUTDIV2 = 1 ;
|
|
+static const uint32_t K_SIM_CLKDIV1_OUTDIV2 = 1 ;
|
|
#elif CPU_MHZ == 96
|
|
#elif CPU_MHZ == 96
|
|
- static const uint32_t K_SIM_CLKDIV1_OUTDIV2 = 1 ;
|
|
+static const uint32_t K_SIM_CLKDIV1_OUTDIV2 = 1 ;
|
|
#elif CPU_MHZ == 72
|
|
#elif CPU_MHZ == 72
|
|
- static const uint32_t K_SIM_CLKDIV1_OUTDIV2 = 1 ;
|
|
+static const uint32_t K_SIM_CLKDIV1_OUTDIV2 = 1 ;
|
|
#elif CPU_MHZ == 48
|
|
#elif CPU_MHZ == 48
|
|
- static const uint32_t K_SIM_CLKDIV1_OUTDIV2 = 1 ;
|
|
+static const uint32_t K_SIM_CLKDIV1_OUTDIV2 = 1 ;
|
|
#elif CPU_MHZ == 24
|
|
#elif CPU_MHZ == 24
|
|
- static const uint32_t K_SIM_CLKDIV1_OUTDIV2 = 3 ;
|
|
+static const uint32_t K_SIM_CLKDIV1_OUTDIV2 = 3 ;
|
|
#else
|
|
#else
|
|
- #error "CPU_MHZ has an invalid value"
|
|
+#error "CPU_MHZ has an invalid value"
|
|
- static const uint32_t K_SIM_CLKDIV1_OUTDIV2 = 0 ;
|
|
+static const uint32_t K_SIM_CLKDIV1_OUTDIV2 = 0 ;
|
|
#endif
|
|
#endif
|
|
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|
|
|
|
|
|
|
|
+
|
|
static const uint32_t BUS_MHZ = (16 / 2) * (K_MCG_C6_VDIV + 16) /(K_MCG_C5_PRDIV + 1) / (K_SIM_CLKDIV1_OUTDIV2 + 1) ;
|
|
static const uint32_t BUS_MHZ = (16 / 2) * (K_MCG_C6_VDIV + 16) /(K_MCG_C5_PRDIV + 1) / (K_SIM_CLKDIV1_OUTDIV2 + 1) ;
|
|
|
|
|
|
-
|
|
|
|
-
|
|
|
|
uint32_t busMHZ (void) {
|
|
uint32_t busMHZ (void) {
|
|
- return BUS_MHZ ;
|
|
+ return BUS_MHZ ;
|
|
}
|
|
}
|
|
|
|
|
|
-
|
|
+
|
|
|
|
|
|
-
|
|
+
|
|
|
|
|
|
#ifndef CPU_MHZ
|
|
#ifndef CPU_MHZ
|
|
- #error "CPU_MHZ is not defined"
|
|
+#error "CPU_MHZ is not defined"
|
|
- static const uint32_t K_SIM_CLKDIV1_OUTDIV3 = 0 ;
|
|
+static const uint32_t K_SIM_CLKDIV1_OUTDIV3 = 0 ;
|
|
#elif CPU_MHZ == 48
|
|
#elif CPU_MHZ == 48
|
|
- static const uint32_t K_SIM_CLKDIV1_OUTDIV3 = 1 ;
|
|
+static const uint32_t K_SIM_CLKDIV1_OUTDIV3 = 1 ;
|
|
#elif CPU_MHZ == 24
|
|
#elif CPU_MHZ == 24
|
|
- static const uint32_t K_SIM_CLKDIV1_OUTDIV3 = 3 ;
|
|
+static const uint32_t K_SIM_CLKDIV1_OUTDIV3 = 3 ;
|
|
#else
|
|
#else
|
|
- static const uint32_t K_SIM_CLKDIV1_OUTDIV3 = 0 ;
|
|
+static const uint32_t K_SIM_CLKDIV1_OUTDIV3 = 0 ;
|
|
#endif
|
|
#endif
|
|
|
|
|
|
-
|
|
+
|
|
|
|
|
|
-
|
|
+
|
|
|
|
|
|
static const uint32_t FLEXBUS_MHZ = (16 / 2) * (K_MCG_C6_VDIV + 16) /(K_MCG_C5_PRDIV + 1) / (K_SIM_CLKDIV1_OUTDIV3 + 1) ;
|
|
static const uint32_t FLEXBUS_MHZ = (16 / 2) * (K_MCG_C6_VDIV + 16) /(K_MCG_C5_PRDIV + 1) / (K_SIM_CLKDIV1_OUTDIV3 + 1) ;
|
|
|
|
|
|
-
|
|
+
|
|
|
|
|
|
uint32_t FlexBusMHZ (void) {
|
|
uint32_t FlexBusMHZ (void) {
|
|
- return FLEXBUS_MHZ ;
|
|
+ return FLEXBUS_MHZ ;
|
|
}
|
|
}
|
|
|
|
|
|
-
|
|
+
|
|
|
|
|
|
-
|
|
+
|
|
|
|
|
|
#ifndef CPU_MHZ
|
|
#ifndef CPU_MHZ
|
|
- #error "CPU_MHZ is not defined"
|
|
+#error "CPU_MHZ is not defined"
|
|
- static const uint32_t K_SIM_CLKDIV1_OUTDIV4 = 0 ;
|
|
+static const uint32_t K_SIM_CLKDIV1_OUTDIV4 = 0 ;
|
|
#elif CPU_MHZ == 240
|
|
#elif CPU_MHZ == 240
|
|
- static const uint32_t K_SIM_CLKDIV1_OUTDIV4 = 7 ;
|
|
+static const uint32_t K_SIM_CLKDIV1_OUTDIV4 = 7 ;
|
|
#elif CPU_MHZ == 216
|
|
#elif CPU_MHZ == 216
|
|
- static const uint32_t K_SIM_CLKDIV1_OUTDIV4 = 7 ;
|
|
+static const uint32_t K_SIM_CLKDIV1_OUTDIV4 = 7 ;
|
|
#elif CPU_MHZ == 192
|
|
#elif CPU_MHZ == 192
|
|
- static const uint32_t K_SIM_CLKDIV1_OUTDIV4 = 6 ;
|
|
+static const uint32_t K_SIM_CLKDIV1_OUTDIV4 = 6 ;
|
|
#elif CPU_MHZ == 180
|
|
#elif CPU_MHZ == 180
|
|
- static const uint32_t K_SIM_CLKDIV1_OUTDIV4 = 6 ;
|
|
+static const uint32_t K_SIM_CLKDIV1_OUTDIV4 = 6 ;
|
|
#elif CPU_MHZ == 168
|
|
#elif CPU_MHZ == 168
|
|
- static const uint32_t K_SIM_CLKDIV1_OUTDIV4 = 5 ;
|
|
+static const uint32_t K_SIM_CLKDIV1_OUTDIV4 = 5 ;
|
|
#elif CPU_MHZ == 144
|
|
#elif CPU_MHZ == 144
|
|
- static const uint32_t K_SIM_CLKDIV1_OUTDIV4 = 4 ;
|
|
+static const uint32_t K_SIM_CLKDIV1_OUTDIV4 = 4 ;
|
|
#elif CPU_MHZ == 120
|
|
#elif CPU_MHZ == 120
|
|
- static const uint32_t K_SIM_CLKDIV1_OUTDIV4 = 4 ;
|
|
+static const uint32_t K_SIM_CLKDIV1_OUTDIV4 = 4 ;
|
|
#elif CPU_MHZ == 96
|
|
#elif CPU_MHZ == 96
|
|
- static const uint32_t K_SIM_CLKDIV1_OUTDIV4 = 3 ;
|
|
+static const uint32_t K_SIM_CLKDIV1_OUTDIV4 = 3 ;
|
|
#elif CPU_MHZ == 72
|
|
#elif CPU_MHZ == 72
|
|
- static const uint32_t K_SIM_CLKDIV1_OUTDIV4 = 2 ;
|
|
+static const uint32_t K_SIM_CLKDIV1_OUTDIV4 = 2 ;
|
|
#elif CPU_MHZ == 48
|
|
#elif CPU_MHZ == 48
|
|
- static const uint32_t K_SIM_CLKDIV1_OUTDIV4 = 3 ;
|
|
+static const uint32_t K_SIM_CLKDIV1_OUTDIV4 = 3 ;
|
|
#elif CPU_MHZ == 24
|
|
#elif CPU_MHZ == 24
|
|
- static const uint32_t K_SIM_CLKDIV1_OUTDIV4 = 3 ;
|
|
+static const uint32_t K_SIM_CLKDIV1_OUTDIV4 = 3 ;
|
|
#else
|
|
#else
|
|
- #error "CPU_MHZ has an invalid value"
|
|
+#error "CPU_MHZ has an invalid value"
|
|
- static const uint32_t K_SIM_CLKDIV1_OUTDIV4 = 0 ;
|
|
+static const uint32_t K_SIM_CLKDIV1_OUTDIV4 = 0 ;
|
|
#endif
|
|
#endif
|
|
|
|
|
|
-
|
|
+
|
|
|
|
|
|
-
|
|
+
|
|
|
|
|
|
static const uint32_t FLASH_KHZ = (16000 / 2) * (K_MCG_C6_VDIV + 16) / (K_MCG_C5_PRDIV + 1) / (K_SIM_CLKDIV1_OUTDIV4 + 1) ;
|
|
static const uint32_t FLASH_KHZ = (16000 / 2) * (K_MCG_C6_VDIV + 16) / (K_MCG_C5_PRDIV + 1) / (K_SIM_CLKDIV1_OUTDIV4 + 1) ;
|
|
|
|
|
|
-
|
|
+
|
|
|
|
|
|
uint32_t FlashKHz (void) {
|
|
uint32_t FlashKHz (void) {
|
|
- return FLASH_KHZ ;
|
|
+ return FLASH_KHZ ;
|
|
}
|
|
}
|
|
|
|
|
|
-
|
|
+
|
|
|
|
|
|
-
|
|
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@@ -294,9 +266,9 @@ uint32_t FlashKHz (void) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
-
|
|
+
|
|
|
|
|
|
-
|
|
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@@ -310,222 +282,220 @@ uint32_t FlashKHz (void) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
-
|
|
+
|
|
|
|
|
|
-
|
|
+
|
|
|
|
|
|
#ifndef CPU_MHZ
|
|
#ifndef CPU_MHZ
|
|
- #error "CPU_MHZ is not defined"
|
|
+#error "CPU_MHZ is not defined"
|
|
- static const uint32_t K_SIM_SOPT2_PLLFLLSEL = 0 ;
|
|
+static const uint32_t K_SIM_SOPT2_PLLFLLSEL = 0 ;
|
|
#elif CPU_MHZ == 216
|
|
#elif CPU_MHZ == 216
|
|
- static const uint32_t K_SIM_SOPT2_PLLFLLSEL = 3 ;
|
|
+static const uint32_t K_SIM_SOPT2_PLLFLLSEL = 3 ;
|
|
#elif CPU_MHZ == 180
|
|
#elif CPU_MHZ == 180
|
|
- static const uint32_t K_SIM_SOPT2_PLLFLLSEL = 3 ;
|
|
+static const uint32_t K_SIM_SOPT2_PLLFLLSEL = 3 ;
|
|
#else
|
|
#else
|
|
- static const uint32_t K_SIM_SOPT2_PLLFLLSEL = 1 ;
|
|
+static const uint32_t K_SIM_SOPT2_PLLFLLSEL = 1 ;
|
|
#endif
|
|
#endif
|
|
|
|
|
|
-
|
|
+
|
|
|
|
|
|
-
|
|
+
|
|
|
|
|
|
#ifndef CPU_MHZ
|
|
#ifndef CPU_MHZ
|
|
- #error "CPU_MHZ is not defined"
|
|
+#error "CPU_MHZ is not defined"
|
|
- static const uint32_t K_SIM_CLKDIV2_USBFRAC = 0 ;
|
|
+static const uint32_t K_SIM_CLKDIV2_USBFRAC = 0 ;
|
|
#elif CPU_MHZ == 168
|
|
#elif CPU_MHZ == 168
|
|
- static const uint32_t K_SIM_CLKDIV2_USBFRAC = 1 ;
|
|
+static const uint32_t K_SIM_CLKDIV2_USBFRAC = 1 ;
|
|
#elif CPU_MHZ == 120
|
|
#elif CPU_MHZ == 120
|
|
- static const uint32_t K_SIM_CLKDIV2_USBFRAC = 1 ;
|
|
+static const uint32_t K_SIM_CLKDIV2_USBFRAC = 1 ;
|
|
#elif CPU_MHZ == 72
|
|
#elif CPU_MHZ == 72
|
|
- static const uint32_t K_SIM_CLKDIV2_USBFRAC = 1 ;
|
|
+static const uint32_t K_SIM_CLKDIV2_USBFRAC = 1 ;
|
|
#else
|
|
#else
|
|
- static const uint32_t K_SIM_CLKDIV2_USBFRAC = 0 ;
|
|
+static const uint32_t K_SIM_CLKDIV2_USBFRAC = 0 ;
|
|
#endif
|
|
#endif
|
|
|
|
|
|
-
|
|
+
|
|
|
|
|
|
-
|
|
+
|
|
|
|
|
|
#ifndef CPU_MHZ
|
|
#ifndef CPU_MHZ
|
|
- #error "CPU_MHZ is not defined"
|
|
+#error "CPU_MHZ is not defined"
|
|
- static const uint32_t K_SIM_CLKDIV2_USBDIV = 0 ;
|
|
+static const uint32_t K_SIM_CLKDIV2_USBDIV = 0 ;
|
|
#elif CPU_MHZ == 240
|
|
#elif CPU_MHZ == 240
|
|
- static const uint32_t K_SIM_CLKDIV2_USBDIV = 4 ;
|
|
+static const uint32_t K_SIM_CLKDIV2_USBDIV = 4 ;
|
|
#elif CPU_MHZ == 216
|
|
#elif CPU_MHZ == 216
|
|
- static const uint32_t K_SIM_CLKDIV2_USBDIV = 0 ;
|
|
+static const uint32_t K_SIM_CLKDIV2_USBDIV = 0 ;
|
|
#elif CPU_MHZ == 192
|
|
#elif CPU_MHZ == 192
|
|
- static const uint32_t K_SIM_CLKDIV2_USBDIV = 3 ;
|
|
+static const uint32_t K_SIM_CLKDIV2_USBDIV = 3 ;
|
|
#elif CPU_MHZ == 180
|
|
#elif CPU_MHZ == 180
|
|
- static const uint32_t K_SIM_CLKDIV2_USBDIV = 0 ;
|
|
+static const uint32_t K_SIM_CLKDIV2_USBDIV = 0 ;
|
|
#elif CPU_MHZ == 168
|
|
#elif CPU_MHZ == 168
|
|
- static const uint32_t K_SIM_CLKDIV2_USBDIV = 6 ;
|
|
+static const uint32_t K_SIM_CLKDIV2_USBDIV = 6 ;
|
|
#elif CPU_MHZ == 144
|
|
#elif CPU_MHZ == 144
|
|
- static const uint32_t K_SIM_CLKDIV2_USBDIV = 2 ;
|
|
+static const uint32_t K_SIM_CLKDIV2_USBDIV = 2 ;
|
|
#elif CPU_MHZ == 120
|
|
#elif CPU_MHZ == 120
|
|
- static const uint32_t K_SIM_CLKDIV2_USBDIV = 4 ;
|
|
+static const uint32_t K_SIM_CLKDIV2_USBDIV = 4 ;
|
|
#elif CPU_MHZ == 96
|
|
#elif CPU_MHZ == 96
|
|
- static const uint32_t K_SIM_CLKDIV2_USBDIV = 1 ;
|
|
+static const uint32_t K_SIM_CLKDIV2_USBDIV = 1 ;
|
|
#elif CPU_MHZ == 72
|
|
#elif CPU_MHZ == 72
|
|
- static const uint32_t K_SIM_CLKDIV2_USBDIV = 2 ;
|
|
+static const uint32_t K_SIM_CLKDIV2_USBDIV = 2 ;
|
|
#elif CPU_MHZ == 48
|
|
#elif CPU_MHZ == 48
|
|
- static const uint32_t K_SIM_CLKDIV2_USBDIV = 1 ;
|
|
+static const uint32_t K_SIM_CLKDIV2_USBDIV = 1 ;
|
|
#elif CPU_MHZ == 24
|
|
#elif CPU_MHZ == 24
|
|
- static const uint32_t K_SIM_CLKDIV2_USBDIV = 1 ;
|
|
+static const uint32_t K_SIM_CLKDIV2_USBDIV = 1 ;
|
|
#else
|
|
#else
|
|
- #error "CPU_MHZ has an invalid value"
|
|
+#error "CPU_MHZ has an invalid value"
|
|
- static const uint32_t K_SIM_CLKDIV2_USBDIV = 0 ;
|
|
+static const uint32_t K_SIM_CLKDIV2_USBDIV = 0 ;
|
|
#endif
|
|
#endif
|
|
|
|
|
|
-
|
|
+
|
|
|
|
|
|
-
|
|
|
|
|
|
|
|
void startPhase1 (void) {
|
|
void startPhase1 (void) {
|
|
-
|
|
+
|
|
-
|
|
+
|
|
- WDOG_UNLOCK = 0xC520 ;
|
|
+ WDOG_UNLOCK = 0xC520 ;
|
|
- WDOG_UNLOCK = 0xD928 ;
|
|
+ WDOG_UNLOCK = 0xD928 ;
|
|
-
|
|
+
|
|
- WDOG_STCTRLH = 0 ;
|
|
+ WDOG_STCTRLH = 0 ;
|
|
-
|
|
+
|
|
- SIM_SCGC3 = SIM_SCGC3_ADC1 | SIM_SCGC3_FTM2 | SIM_SCGC3_FTM3 ;
|
|
+ SIM_SCGC3 = SIM_SCGC3_ADC1 | SIM_SCGC3_FTM2 | SIM_SCGC3_FTM3 ;
|
|
- SIM_SCGC5 = SIM_SCGC5_PORTA | SIM_SCGC5_PORTB | SIM_SCGC5_PORTC | SIM_SCGC5_PORTD | SIM_SCGC5_PORTE ;
|
|
+ SIM_SCGC5 = SIM_SCGC5_PORTA | SIM_SCGC5_PORTB | SIM_SCGC5_PORTC | SIM_SCGC5_PORTD | SIM_SCGC5_PORTE ;
|
|
- SIM_SCGC6 = SIM_SCGC6_RTC | SIM_SCGC6_FTM0 | SIM_SCGC6_FTM1 | SIM_SCGC6_ADC0 | SIM_SCGC6_FTF ;
|
|
+ SIM_SCGC6 = SIM_SCGC6_RTC | SIM_SCGC6_FTM0 | SIM_SCGC6_FTM1 | SIM_SCGC6_ADC0 | SIM_SCGC6_FTF ;
|
|
-
|
|
+
|
|
- LMEM_PCCCR = LMEM_PCCCR_GO | LMEM_PCCCR_INVW1 | LMEM_PCCCR_INVW0 | LMEM_PCCCR_ENWRBUF | LMEM_PCCCR_ENCACHE ;
|
|
+ LMEM_PCCCR = LMEM_PCCCR_GO | LMEM_PCCCR_INVW1 | LMEM_PCCCR_INVW0 | LMEM_PCCCR_ENWRBUF | LMEM_PCCCR_ENCACHE ;
|
|
-
|
|
+
|
|
if ((RTC_CR & RTC_CR_OSCE) != 0) {
|
|
if ((RTC_CR & RTC_CR_OSCE) != 0) {
|
|
RTC_SR = 0;
|
|
RTC_SR = 0;
|
|
RTC_CR = RTC_CR_SC16P | RTC_CR_SC4P | RTC_CR_OSCE;
|
|
RTC_CR = RTC_CR_SC16P | RTC_CR_SC4P | RTC_CR_OSCE;
|
|
}
|
|
}
|
|
-
|
|
+
|
|
if (PMC_REGSC & PMC_REGSC_ACKISO) {
|
|
if (PMC_REGSC & PMC_REGSC_ACKISO) {
|
|
- PMC_REGSC |= PMC_REGSC_ACKISO;
|
|
+ PMC_REGSC |= PMC_REGSC_ACKISO;
|
|
- }
|
|
+ }
|
|
-
|
|
+
|
|
-
|
|
+
|
|
-
|
|
+
|
|
SMC_PMPROT = SMC_PMPROT_AHSRUN | SMC_PMPROT_AVLP | SMC_PMPROT_ALLS | SMC_PMPROT_AVLLS;
|
|
SMC_PMPROT = SMC_PMPROT_AHSRUN | SMC_PMPROT_AVLP | SMC_PMPROT_ALLS | SMC_PMPROT_AVLLS;
|
|
-
|
|
+
|
|
-
|
|
+
|
|
- OSC_CR = OSC_CR_SC8P | OSC_CR_SC2P | OSC_CR_ERCLKEN;
|
|
+ OSC_CR = OSC_CR_SC8P | OSC_CR_SC2P | OSC_CR_ERCLKEN;
|
|
-
|
|
+
|
|
MCG_C2 = MCG_C2_RANGE (2) | MCG_C2_EREFS;
|
|
MCG_C2 = MCG_C2_RANGE (2) | MCG_C2_EREFS;
|
|
-
|
|
+
|
|
MCG_C1 = MCG_C1_CLKS(2) | MCG_C1_FRDIV(4);
|
|
MCG_C1 = MCG_C1_CLKS(2) | MCG_C1_FRDIV(4);
|
|
-
|
|
+
|
|
while ((MCG_S & MCG_S_OSCINIT0) == 0) {}
|
|
while ((MCG_S & MCG_S_OSCINIT0) == 0) {}
|
|
-
|
|
+
|
|
while ((MCG_S & MCG_S_IREFST) != 0) {}
|
|
while ((MCG_S & MCG_S_IREFST) != 0) {}
|
|
-
|
|
+
|
|
while ((MCG_S & MCG_S_CLKST (3)) != MCG_S_CLKST(2)) {}
|
|
while ((MCG_S & MCG_S_CLKST (3)) != MCG_S_CLKST(2)) {}
|
|
-
|
|
+
|
|
-
|
|
+
|
|
-
|
|
+
|
|
-
|
|
+
|
|
- const uint32_t serialNumber = readMicrocontrollerSerialNumber () ;
|
|
+ const uint32_t serialNumber = readMicrocontrollerSerialNumber () ;
|
|
-
|
|
+
|
|
- SMC_PMCTRL = SMC_PMCTRL_RUNM (3);
|
|
+ SMC_PMCTRL = SMC_PMCTRL_RUNM (3);
|
|
while (SMC_PMSTAT != SMC_PMPROT_AHSRUN) {}
|
|
while (SMC_PMSTAT != SMC_PMPROT_AHSRUN) {}
|
|
-
|
|
+
|
|
- MCG_C5 = K_MCG_C5_PRDIV ;
|
|
+ MCG_C5 = K_MCG_C5_PRDIV ;
|
|
- MCG_C6 = MCG_C6_PLLS | K_MCG_C6_VDIV ;
|
|
+ MCG_C6 = MCG_C6_PLLS | K_MCG_C6_VDIV ;
|
|
-
|
|
+
|
|
while (!(MCG_S & MCG_S_PLLST)) {}
|
|
while (!(MCG_S & MCG_S_PLLST)) {}
|
|
-
|
|
+
|
|
while (!(MCG_S & MCG_S_LOCK0)) {}
|
|
while (!(MCG_S & MCG_S_LOCK0)) {}
|
|
-
|
|
+
|
|
- SIM_CLKDIV1 =
|
|
+ SIM_CLKDIV1 =
|
|
- SIM_CLKDIV1_OUTDIV1(K_SIM_CLKDIV1_OUTDIV1)
|
|
+ SIM_CLKDIV1_OUTDIV1(K_SIM_CLKDIV1_OUTDIV1)
|
|
- | SIM_CLKDIV1_OUTDIV2(K_SIM_CLKDIV1_OUTDIV2)
|
|
+ | SIM_CLKDIV1_OUTDIV2(K_SIM_CLKDIV1_OUTDIV2)
|
|
- | SIM_CLKDIV1_OUTDIV3(K_SIM_CLKDIV1_OUTDIV3)
|
|
+ | SIM_CLKDIV1_OUTDIV3(K_SIM_CLKDIV1_OUTDIV3)
|
|
- | SIM_CLKDIV1_OUTDIV4(K_SIM_CLKDIV1_OUTDIV4)
|
|
+ | SIM_CLKDIV1_OUTDIV4(K_SIM_CLKDIV1_OUTDIV4)
|
|
- ;
|
|
+ ;
|
|
- SIM_CLKDIV2 =
|
|
+ SIM_CLKDIV2 =
|
|
- SIM_CLKDIV2_USBDIV (K_SIM_CLKDIV2_USBDIV)
|
|
+ SIM_CLKDIV2_USBDIV (K_SIM_CLKDIV2_USBDIV)
|
|
- | K_SIM_CLKDIV2_USBFRAC
|
|
+ | K_SIM_CLKDIV2_USBFRAC
|
|
- ;
|
|
+ ;
|
|
-
|
|
+
|
|
- MCG_C1 = MCG_C1_CLKS(0) | MCG_C1_FRDIV(4);
|
|
+ MCG_C1 = MCG_C1_CLKS(0) | MCG_C1_FRDIV(4);
|
|
-
|
|
+
|
|
- while ((MCG_S & MCG_S_CLKST (3)) != MCG_S_CLKST(3)) {}
|
|
+ while ((MCG_S & MCG_S_CLKST (3)) != MCG_S_CLKST(3)) {}
|
|
-
|
|
+
|
|
- SIM_SOPT2 =
|
|
+ SIM_SOPT2 =
|
|
- SIM_SOPT2_USBSRC
|
|
+ SIM_SOPT2_USBSRC
|
|
- | (K_SIM_SOPT2_PLLFLLSEL << 16)
|
|
+ | (K_SIM_SOPT2_PLLFLLSEL << 16)
|
|
- | SIM_SOPT2_TRACECLKSEL
|
|
+ | SIM_SOPT2_TRACECLKSEL
|
|
- ;
|
|
+ ;
|
|
-
|
|
+
|
|
- extern uint32_t __bss_start ;
|
|
+ extern uint32_t __bss_start ;
|
|
- extern const uint32_t __bss_end ;
|
|
+ extern const uint32_t __bss_end ;
|
|
- uint32_t * p = & __bss_start ;
|
|
+ uint32_t * p = & __bss_start ;
|
|
- while (p != & __bss_end) {
|
|
+ while (p != & __bss_end) {
|
|
- * p = 0 ;
|
|
+ * p = 0 ;
|
|
- p ++ ;
|
|
+ p ++ ;
|
|
- }
|
|
+ }
|
|
-
|
|
+
|
|
- extern uint32_t __data_start ;
|
|
+ extern uint32_t __data_start ;
|
|
- extern const uint32_t __data_end ;
|
|
+ extern const uint32_t __data_end ;
|
|
- extern uint32_t __data_load_start ;
|
|
+ extern uint32_t __data_load_start ;
|
|
- uint32_t * pSrc = & __data_load_start ;
|
|
+ uint32_t * pSrc = & __data_load_start ;
|
|
- uint32_t * pDest = & __data_start ;
|
|
+ uint32_t * pDest = & __data_start ;
|
|
- while (pDest != & __data_end) {
|
|
+ while (pDest != & __data_end) {
|
|
- * pDest = * pSrc ;
|
|
+ * pDest = * pSrc ;
|
|
- pDest ++ ;
|
|
+ pDest ++ ;
|
|
- pSrc ++ ;
|
|
+ pSrc ++ ;
|
|
- }
|
|
+ }
|
|
-
|
|
+
|
|
- gMicrocontrollerSerialNumber = serialNumber ;
|
|
+ gMicrocontrollerSerialNumber = serialNumber ;
|
|
}
|
|
}
|
|
|
|
|
|
-
|
|
+
|
|
|
|
|
|
-
|
|
+
|
|
|
|
|
|
static uint32_t readMicrocontrollerSerialNumber (void) {
|
|
static uint32_t readMicrocontrollerSerialNumber (void) {
|
|
- while ((FTFE_FSTAT & FTFE_FSTAT_CCIF) == 0) {}
|
|
+ while ((FTFE_FSTAT & FTFE_FSTAT_CCIF) == 0) {}
|
|
- FTFE_FSTAT = FTFE_FSTAT_RDCOLERR | FTFE_FSTAT_ACCERR | FTFE_FSTAT_FPVIOL;
|
|
+ FTFE_FSTAT = FTFE_FSTAT_RDCOLERR | FTFE_FSTAT_ACCERR | FTFE_FSTAT_FPVIOL;
|
|
-
|
|
+
|
|
- FTFE_FCCOB_0_3 = 0x41070000 ;
|
|
+ FTFE_FCCOB_0_3 = 0x41070000 ;
|
|
- FTFE_FSTAT = FTFE_FSTAT_CCIF ;
|
|
+ FTFE_FSTAT = FTFE_FSTAT_CCIF ;
|
|
- while ((FTFE_FSTAT & FTFE_FSTAT_CCIF) == 0) {}
|
|
+ while ((FTFE_FSTAT & FTFE_FSTAT_CCIF) == 0) {}
|
|
-
|
|
+
|
|
- return FTFE_FCCOB_8_11 ;
|
|
+ return FTFE_FCCOB_8_11 ;
|
|
}
|
|
}
|
|
|
|
|
|
-
|
|
+
|
|
|
|
|
|
uint32_t microcontrollerSerialNumber (void) {
|
|
uint32_t microcontrollerSerialNumber (void) {
|
|
- return gMicrocontrollerSerialNumber ;
|
|
+ return gMicrocontrollerSerialNumber ;
|
|
}
|
|
}
|
|
|
|
|
|
-
|
|
+
|
|
|
|
|
|
void startPhase2 (void) {
|
|
void startPhase2 (void) {
|
|
-
|
|
+
|
|
- extern void (* __boot_routine_array_start) (void) ;
|
|
+ extern void (* __boot_routine_array_start) (void) ;
|
|
- extern void (* __boot_routine_array_end) (void) ;
|
|
+ extern void (* __boot_routine_array_end) (void) ;
|
|
- void (* * ptr) (void) = & __boot_routine_array_start ;
|
|
+ void (* * ptr) (void) = & __boot_routine_array_start ;
|
|
- while (ptr != & __boot_routine_array_end) {
|
|
+ while (ptr != & __boot_routine_array_end) {
|
|
- (* ptr) () ;
|
|
+ (* ptr) () ;
|
|
- ptr ++ ;
|
|
+ ptr ++ ;
|
|
- }
|
|
+ }
|
|
-
|
|
+
|
|
- extern void (* __constructor_array_start) (void) ;
|
|
+ extern void (* __constructor_array_start) (void) ;
|
|
- extern void (* __constructor_array_end) (void) ;
|
|
+ extern void (* __constructor_array_end) (void) ;
|
|
- ptr = & __constructor_array_start ;
|
|
+ ptr = & __constructor_array_start ;
|
|
- while (ptr != & __constructor_array_end) {
|
|
+ while (ptr != & __constructor_array_end) {
|
|
- (* ptr) () ;
|
|
+ (* ptr) () ;
|
|
- ptr ++ ;
|
|
+ ptr ++ ;
|
|
- }
|
|
+ }
|
|
-
|
|
+
|
|
- extern void (* __init_routine_array_start) (void) ;
|
|
+ extern void (* __init_routine_array_start) (void) ;
|
|
- extern void (* __init_routine_array_end) (void) ;
|
|
+ extern void (* __init_routine_array_end) (void) ;
|
|
- ptr = & __init_routine_array_start ;
|
|
+ ptr = & __init_routine_array_start ;
|
|
- while (ptr != & __init_routine_array_end) {
|
|
+ while (ptr != & __init_routine_array_end) {
|
|
- (* ptr) () ;
|
|
+ (* ptr) () ;
|
|
- ptr ++ ;
|
|
+ ptr ++ ;
|
|
- }
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
-
|
|
|