]> git.sur5r.net Git - freertos/blob - Demo/CORTEX_EFMG890F128_IAR/CMSIS/CM3/DeviceSupport/EnergyMicro/EFM32/system_efm32.c
Start to re-arrange files to include FreeRTOS+ in main download.
[freertos] / Demo / CORTEX_EFMG890F128_IAR / CMSIS / CM3 / DeviceSupport / EnergyMicro / EFM32 / system_efm32.c
1 /**************************************************************************//**\r
2  * @file\r
3  * @brief CMSIS Cortex-M3 Peripheral Access Layer for EFM32 devices\r
4  *\r
5  * @author Energy Micro AS\r
6  * @version 1.0.2\r
7  ******************************************************************************\r
8  * @section License\r
9  * <b>(C) Copyright 2009 Energy Micro AS, http://www.energymicro.com</b>\r
10  ******************************************************************************\r
11  *\r
12  * This source code is the property of Energy Micro AS. The source and compiled\r
13  * code may only be used on Energy Micro "EFM32" microcontrollers.\r
14  *\r
15  * This copyright notice may not be removed from the source code nor changed.\r
16  *\r
17  * DISCLAIMER OF WARRANTY/LIMITATION OF REMEDIES: Energy Micro AS has no\r
18  * obligation to support this Software. Energy Micro AS is providing the\r
19  * Software "AS IS", with no express or implied warranties of any kind,\r
20  * including, but not limited to, any implied warranties of merchantability\r
21  * or fitness for any particular purpose or warranties against infringement\r
22  * of any proprietary rights of a third party.\r
23  *\r
24  * Energy Micro AS will not be liable for any consequential, incidental, or\r
25  * special damages, or any other relief, or for any claim by any third party,\r
26  * arising from your use of this Software.\r
27  *\r
28  *****************************************************************************/\r
29 \r
30 #include <stdint.h>\r
31 #include "efm32.h"\r
32 \r
33 uint32_t SystemCoreClock;     /**< System Clock Frequency (Core Clock)  */\r
34 \r
35 #ifndef EFM32_HFXO_FREQ\r
36 #define EFM32_HFXO_FREQ 32000000\r
37 #endif\r
38 #ifndef EFM32_LFXO_FREQ \r
39 #define EFM32_LFXO_FREQ 32768\r
40 #endif\r
41 #ifndef EFM32_LFRCO_FREQ\r
42 #define EFM32_LFRCO_FREQ 32768\r
43 #endif\r
44 \r
45 /**************************************************************************//**\r
46  * @brief Initialize the system\r
47  *\r
48  * @param  none\r
49  * @return none\r
50  *\r
51  * @brief  Setup the microcontroller system.\r
52  *         Initialize the System and update the SystemCoreClock variable.\r
53  *****************************************************************************/\r
54 void SystemInit(void)\r
55 {\r
56 #if EFM32_AUXHFROCO_ENABLE\r
57   CMU_TypeDef *cmu = CMU;\r
58 \r
59   /* Enable clocks to debug modules in Cortex */\r
60   /* This will enable Debug Trace and MSC Flash programming clocks */\r
61   cmu->OSCENCMD = CMU_OSCENCMD_AUXHFRCOEN;\r
62 #endif\r
63 }\r
64 \r
65 /**************************************************************************//**\r
66  * @brief Update SystemCoreClock variable\r
67  *\r
68  * @param  none\r
69  * @return none\r
70  *\r
71  * @brief  Updates the SystemCoreClock with current core Clock\r
72  *         retrieved from cpu registers.\r
73  *****************************************************************************/\r
74 void SystemCoreClockUpdate(void)\r
75 {\r
76   CMU_TypeDef *cmu = CMU;\r
77   uint32_t inputClock;\r
78 \r
79   /* Check source for core clock */\r
80   switch (cmu->STATUS &\r
81           (CMU_STATUS_HFRCOSEL |\r
82            CMU_STATUS_HFXOSEL |\r
83            CMU_STATUS_LFRCOSEL |\r
84            CMU_STATUS_LFXOSEL))\r
85   {\r
86   case CMU_STATUS_HFXOSEL:\r
87     inputClock = EFM32_HFXO_FREQ;\r
88     break;\r
89   case CMU_STATUS_LFRCOSEL:\r
90     inputClock = EFM32_LFRCO_FREQ;\r
91     break;\r
92   case CMU_STATUS_LFXOSEL:\r
93     inputClock = EFM32_LFXO_FREQ;\r
94     break;\r
95   case CMU_STATUS_HFRCOSEL:\r
96   default:\r
97     switch ((cmu->HFRCOCTRL & _CMU_HFRCOCTRL_BAND_MASK) >> _CMU_HFRCOCTRL_BAND_SHIFT)\r
98     {\r
99     case _CMU_HFRCOCTRL_BAND_28MHZ:\r
100       inputClock = 28000000;\r
101       break;\r
102     case _CMU_HFRCOCTRL_BAND_21MHZ:\r
103       inputClock = 21000000;\r
104       break;\r
105     case _CMU_HFRCOCTRL_BAND_14MHZ:\r
106       inputClock = 14000000;\r
107       break;\r
108     case _CMU_HFRCOCTRL_BAND_11MHZ:\r
109       inputClock = 11000000;\r
110       break;\r
111     case _CMU_HFRCOCTRL_BAND_7MHZ:\r
112       inputClock = 7000000;\r
113       break;\r
114     case _CMU_HFRCOCTRL_BAND_1MHZ:\r
115       inputClock = 1500000;\r
116       break;\r
117     default:\r
118       inputClock = 0;\r
119       break;\r
120     }\r
121     break;\r
122   }\r
123   /* Adjust according to clock divisor */\r
124   SystemCoreClock = inputClock / (1<<((cmu->HFCORECLKDIV & _CMU_HFCORECLKDIV_MASK)>>_CMU_HFCORECLKDIV_HFCORECLKDIV_SHIFT));\r
125 }\r
126 \r