Mouse code for the MacroRat
mbed-dev/targets/TARGET_Silicon_Labs/TARGET_EFM32/TARGET_EFR32MG1/device/system_efr32mg1p.c@46:b156ef445742, 2017-06-03 (annotated)
- Committer:
- sahilmgandhi
- Date:
- Sat Jun 03 00:22:44 2017 +0000
- Revision:
- 46:b156ef445742
- Parent:
- 18:6a4db94011d3
Final code for internal battlebot competition.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
sahilmgandhi | 18:6a4db94011d3 | 1 | /***************************************************************************//** |
sahilmgandhi | 18:6a4db94011d3 | 2 | * @file system_efr32mg1p.c |
sahilmgandhi | 18:6a4db94011d3 | 3 | * @brief CMSIS Cortex-M3/M4 System Layer for EFR32 devices. |
sahilmgandhi | 18:6a4db94011d3 | 4 | * @version 5.1.2 |
sahilmgandhi | 18:6a4db94011d3 | 5 | ****************************************************************************** |
sahilmgandhi | 18:6a4db94011d3 | 6 | * @section License |
sahilmgandhi | 18:6a4db94011d3 | 7 | * <b>Copyright 2017 Silicon Laboratories, Inc. http://www.silabs.com</b> |
sahilmgandhi | 18:6a4db94011d3 | 8 | ****************************************************************************** |
sahilmgandhi | 18:6a4db94011d3 | 9 | * |
sahilmgandhi | 18:6a4db94011d3 | 10 | * Permission is granted to anyone to use this software for any purpose, |
sahilmgandhi | 18:6a4db94011d3 | 11 | * including commercial applications, and to alter it and redistribute it |
sahilmgandhi | 18:6a4db94011d3 | 12 | * freely, subject to the following restrictions: |
sahilmgandhi | 18:6a4db94011d3 | 13 | * |
sahilmgandhi | 18:6a4db94011d3 | 14 | * 1. The origin of this software must not be misrepresented; you must not |
sahilmgandhi | 18:6a4db94011d3 | 15 | * claim that you wrote the original software.@n |
sahilmgandhi | 18:6a4db94011d3 | 16 | * 2. Altered source versions must be plainly marked as such, and must not be |
sahilmgandhi | 18:6a4db94011d3 | 17 | * misrepresented as being the original software.@n |
sahilmgandhi | 18:6a4db94011d3 | 18 | * 3. This notice may not be removed or altered from any source distribution. |
sahilmgandhi | 18:6a4db94011d3 | 19 | * |
sahilmgandhi | 18:6a4db94011d3 | 20 | * DISCLAIMER OF WARRANTY/LIMITATION OF REMEDIES: Silicon Laboratories, Inc. |
sahilmgandhi | 18:6a4db94011d3 | 21 | * has no obligation to support this Software. Silicon Laboratories, Inc. is |
sahilmgandhi | 18:6a4db94011d3 | 22 | * providing the Software "AS IS", with no express or implied warranties of any |
sahilmgandhi | 18:6a4db94011d3 | 23 | * kind, including, but not limited to, any implied warranties of |
sahilmgandhi | 18:6a4db94011d3 | 24 | * merchantability or fitness for any particular purpose or warranties against |
sahilmgandhi | 18:6a4db94011d3 | 25 | * infringement of any proprietary rights of a third party. |
sahilmgandhi | 18:6a4db94011d3 | 26 | * |
sahilmgandhi | 18:6a4db94011d3 | 27 | * Silicon Laboratories, Inc. will not be liable for any consequential, |
sahilmgandhi | 18:6a4db94011d3 | 28 | * incidental, or special damages, or any other relief, or for any claim by |
sahilmgandhi | 18:6a4db94011d3 | 29 | * any third party, arising from your use of this Software. |
sahilmgandhi | 18:6a4db94011d3 | 30 | * |
sahilmgandhi | 18:6a4db94011d3 | 31 | *****************************************************************************/ |
sahilmgandhi | 18:6a4db94011d3 | 32 | |
sahilmgandhi | 18:6a4db94011d3 | 33 | #include <stdint.h> |
sahilmgandhi | 18:6a4db94011d3 | 34 | #include "em_device.h" |
sahilmgandhi | 18:6a4db94011d3 | 35 | |
sahilmgandhi | 18:6a4db94011d3 | 36 | /******************************************************************************* |
sahilmgandhi | 18:6a4db94011d3 | 37 | ****************************** DEFINES ************************************ |
sahilmgandhi | 18:6a4db94011d3 | 38 | ******************************************************************************/ |
sahilmgandhi | 18:6a4db94011d3 | 39 | |
sahilmgandhi | 18:6a4db94011d3 | 40 | /** LFRCO frequency, tuned to below frequency during manufacturing. */ |
sahilmgandhi | 18:6a4db94011d3 | 41 | #define EFR32_LFRCO_FREQ (32768UL) |
sahilmgandhi | 18:6a4db94011d3 | 42 | #define EFR32_ULFRCO_FREQ (1000UL) |
sahilmgandhi | 18:6a4db94011d3 | 43 | |
sahilmgandhi | 18:6a4db94011d3 | 44 | /******************************************************************************* |
sahilmgandhi | 18:6a4db94011d3 | 45 | ************************** LOCAL VARIABLES ******************************** |
sahilmgandhi | 18:6a4db94011d3 | 46 | ******************************************************************************/ |
sahilmgandhi | 18:6a4db94011d3 | 47 | |
sahilmgandhi | 18:6a4db94011d3 | 48 | /* System oscillator frequencies. These frequencies are normally constant */ |
sahilmgandhi | 18:6a4db94011d3 | 49 | /* for a target, but they are made configurable in order to allow run-time */ |
sahilmgandhi | 18:6a4db94011d3 | 50 | /* handling of different boards. The crystal oscillator clocks can be set */ |
sahilmgandhi | 18:6a4db94011d3 | 51 | /* compile time to a non-default value by defining respective EFR_nFXO_FREQ */ |
sahilmgandhi | 18:6a4db94011d3 | 52 | /* values according to board design. By defining the EFR_nFXO_FREQ to 0, */ |
sahilmgandhi | 18:6a4db94011d3 | 53 | /* one indicates that the oscillator is not present, in order to save some */ |
sahilmgandhi | 18:6a4db94011d3 | 54 | /* SW footprint. */ |
sahilmgandhi | 18:6a4db94011d3 | 55 | |
sahilmgandhi | 18:6a4db94011d3 | 56 | #ifndef EFR32_HFRCO_MAX_FREQ |
sahilmgandhi | 18:6a4db94011d3 | 57 | #define EFR32_HFRCO_MAX_FREQ (38000000UL) |
sahilmgandhi | 18:6a4db94011d3 | 58 | #endif |
sahilmgandhi | 18:6a4db94011d3 | 59 | |
sahilmgandhi | 18:6a4db94011d3 | 60 | #ifndef EFR32_HFXO_FREQ |
sahilmgandhi | 18:6a4db94011d3 | 61 | #define EFR32_HFXO_FREQ (38400000UL) |
sahilmgandhi | 18:6a4db94011d3 | 62 | #endif |
sahilmgandhi | 18:6a4db94011d3 | 63 | |
sahilmgandhi | 18:6a4db94011d3 | 64 | #ifndef EFR32_HFRCO_STARTUP_FREQ |
sahilmgandhi | 18:6a4db94011d3 | 65 | #define EFR32_HFRCO_STARTUP_FREQ (19000000UL) |
sahilmgandhi | 18:6a4db94011d3 | 66 | #endif |
sahilmgandhi | 18:6a4db94011d3 | 67 | |
sahilmgandhi | 18:6a4db94011d3 | 68 | |
sahilmgandhi | 18:6a4db94011d3 | 69 | /* Do not define variable if HF crystal oscillator not present */ |
sahilmgandhi | 18:6a4db94011d3 | 70 | #if (EFR32_HFXO_FREQ > 0UL) |
sahilmgandhi | 18:6a4db94011d3 | 71 | /** @cond DO_NOT_INCLUDE_WITH_DOXYGEN */ |
sahilmgandhi | 18:6a4db94011d3 | 72 | /** System HFXO clock. */ |
sahilmgandhi | 18:6a4db94011d3 | 73 | static uint32_t SystemHFXOClock = EFR32_HFXO_FREQ; |
sahilmgandhi | 18:6a4db94011d3 | 74 | /** @endcond (DO_NOT_INCLUDE_WITH_DOXYGEN) */ |
sahilmgandhi | 18:6a4db94011d3 | 75 | #endif |
sahilmgandhi | 18:6a4db94011d3 | 76 | |
sahilmgandhi | 18:6a4db94011d3 | 77 | #ifndef EFR32_LFXO_FREQ |
sahilmgandhi | 18:6a4db94011d3 | 78 | #define EFR32_LFXO_FREQ (EFR32_LFRCO_FREQ) |
sahilmgandhi | 18:6a4db94011d3 | 79 | #endif |
sahilmgandhi | 18:6a4db94011d3 | 80 | /* Do not define variable if LF crystal oscillator not present */ |
sahilmgandhi | 18:6a4db94011d3 | 81 | #if (EFR32_LFXO_FREQ > 0UL) |
sahilmgandhi | 18:6a4db94011d3 | 82 | /** @cond DO_NOT_INCLUDE_WITH_DOXYGEN */ |
sahilmgandhi | 18:6a4db94011d3 | 83 | /** System LFXO clock. */ |
sahilmgandhi | 18:6a4db94011d3 | 84 | static uint32_t SystemLFXOClock = 32768UL; |
sahilmgandhi | 18:6a4db94011d3 | 85 | /** @endcond (DO_NOT_INCLUDE_WITH_DOXYGEN) */ |
sahilmgandhi | 18:6a4db94011d3 | 86 | #endif |
sahilmgandhi | 18:6a4db94011d3 | 87 | |
sahilmgandhi | 18:6a4db94011d3 | 88 | |
sahilmgandhi | 18:6a4db94011d3 | 89 | /******************************************************************************* |
sahilmgandhi | 18:6a4db94011d3 | 90 | ************************** GLOBAL VARIABLES ******************************* |
sahilmgandhi | 18:6a4db94011d3 | 91 | ******************************************************************************/ |
sahilmgandhi | 18:6a4db94011d3 | 92 | |
sahilmgandhi | 18:6a4db94011d3 | 93 | /** |
sahilmgandhi | 18:6a4db94011d3 | 94 | * @brief |
sahilmgandhi | 18:6a4db94011d3 | 95 | * System System Clock Frequency (Core Clock). |
sahilmgandhi | 18:6a4db94011d3 | 96 | * |
sahilmgandhi | 18:6a4db94011d3 | 97 | * @details |
sahilmgandhi | 18:6a4db94011d3 | 98 | * Required CMSIS global variable that must be kept up-to-date. |
sahilmgandhi | 18:6a4db94011d3 | 99 | */ |
sahilmgandhi | 18:6a4db94011d3 | 100 | uint32_t SystemCoreClock; |
sahilmgandhi | 18:6a4db94011d3 | 101 | |
sahilmgandhi | 18:6a4db94011d3 | 102 | |
sahilmgandhi | 18:6a4db94011d3 | 103 | /** |
sahilmgandhi | 18:6a4db94011d3 | 104 | * @brief |
sahilmgandhi | 18:6a4db94011d3 | 105 | * System HFRCO frequency |
sahilmgandhi | 18:6a4db94011d3 | 106 | * |
sahilmgandhi | 18:6a4db94011d3 | 107 | * @note |
sahilmgandhi | 18:6a4db94011d3 | 108 | * This is an EFR32 proprietary variable, not part of the CMSIS definition. |
sahilmgandhi | 18:6a4db94011d3 | 109 | * |
sahilmgandhi | 18:6a4db94011d3 | 110 | * @details |
sahilmgandhi | 18:6a4db94011d3 | 111 | * Frequency of the system HFRCO oscillator |
sahilmgandhi | 18:6a4db94011d3 | 112 | */ |
sahilmgandhi | 18:6a4db94011d3 | 113 | uint32_t SystemHfrcoFreq = EFR32_HFRCO_STARTUP_FREQ; |
sahilmgandhi | 18:6a4db94011d3 | 114 | |
sahilmgandhi | 18:6a4db94011d3 | 115 | |
sahilmgandhi | 18:6a4db94011d3 | 116 | /******************************************************************************* |
sahilmgandhi | 18:6a4db94011d3 | 117 | ************************** GLOBAL FUNCTIONS ******************************* |
sahilmgandhi | 18:6a4db94011d3 | 118 | ******************************************************************************/ |
sahilmgandhi | 18:6a4db94011d3 | 119 | |
sahilmgandhi | 18:6a4db94011d3 | 120 | /***************************************************************************//** |
sahilmgandhi | 18:6a4db94011d3 | 121 | * @brief |
sahilmgandhi | 18:6a4db94011d3 | 122 | * Get the current core clock frequency. |
sahilmgandhi | 18:6a4db94011d3 | 123 | * |
sahilmgandhi | 18:6a4db94011d3 | 124 | * @details |
sahilmgandhi | 18:6a4db94011d3 | 125 | * Calculate and get the current core clock frequency based on the current |
sahilmgandhi | 18:6a4db94011d3 | 126 | * configuration. Assuming that the SystemCoreClock global variable is |
sahilmgandhi | 18:6a4db94011d3 | 127 | * maintained, the core clock frequency is stored in that variable as well. |
sahilmgandhi | 18:6a4db94011d3 | 128 | * This function will however calculate the core clock based on actual HW |
sahilmgandhi | 18:6a4db94011d3 | 129 | * configuration. It will also update the SystemCoreClock global variable. |
sahilmgandhi | 18:6a4db94011d3 | 130 | * |
sahilmgandhi | 18:6a4db94011d3 | 131 | * @note |
sahilmgandhi | 18:6a4db94011d3 | 132 | * This is an EFR32 proprietary function, not part of the CMSIS definition. |
sahilmgandhi | 18:6a4db94011d3 | 133 | * |
sahilmgandhi | 18:6a4db94011d3 | 134 | * @return |
sahilmgandhi | 18:6a4db94011d3 | 135 | * The current core clock frequency in Hz. |
sahilmgandhi | 18:6a4db94011d3 | 136 | ******************************************************************************/ |
sahilmgandhi | 18:6a4db94011d3 | 137 | uint32_t SystemCoreClockGet(void) |
sahilmgandhi | 18:6a4db94011d3 | 138 | { |
sahilmgandhi | 18:6a4db94011d3 | 139 | uint32_t ret; |
sahilmgandhi | 18:6a4db94011d3 | 140 | uint32_t presc; |
sahilmgandhi | 18:6a4db94011d3 | 141 | |
sahilmgandhi | 18:6a4db94011d3 | 142 | ret = SystemHFClockGet(); |
sahilmgandhi | 18:6a4db94011d3 | 143 | presc = (CMU->HFCOREPRESC & _CMU_HFCOREPRESC_PRESC_MASK) >> |
sahilmgandhi | 18:6a4db94011d3 | 144 | _CMU_HFCOREPRESC_PRESC_SHIFT; |
sahilmgandhi | 18:6a4db94011d3 | 145 | ret /= (presc + 1); |
sahilmgandhi | 18:6a4db94011d3 | 146 | |
sahilmgandhi | 18:6a4db94011d3 | 147 | /* Keep CMSIS system clock variable up-to-date */ |
sahilmgandhi | 18:6a4db94011d3 | 148 | SystemCoreClock = ret; |
sahilmgandhi | 18:6a4db94011d3 | 149 | |
sahilmgandhi | 18:6a4db94011d3 | 150 | return ret; |
sahilmgandhi | 18:6a4db94011d3 | 151 | } |
sahilmgandhi | 18:6a4db94011d3 | 152 | |
sahilmgandhi | 18:6a4db94011d3 | 153 | |
sahilmgandhi | 18:6a4db94011d3 | 154 | /***************************************************************************//** |
sahilmgandhi | 18:6a4db94011d3 | 155 | * @brief |
sahilmgandhi | 18:6a4db94011d3 | 156 | * Get the maximum core clock frequency. |
sahilmgandhi | 18:6a4db94011d3 | 157 | * |
sahilmgandhi | 18:6a4db94011d3 | 158 | * @note |
sahilmgandhi | 18:6a4db94011d3 | 159 | * This is an EFR32 proprietary function, not part of the CMSIS definition. |
sahilmgandhi | 18:6a4db94011d3 | 160 | * |
sahilmgandhi | 18:6a4db94011d3 | 161 | * @return |
sahilmgandhi | 18:6a4db94011d3 | 162 | * The maximum core clock frequency in Hz. |
sahilmgandhi | 18:6a4db94011d3 | 163 | ******************************************************************************/ |
sahilmgandhi | 18:6a4db94011d3 | 164 | uint32_t SystemMaxCoreClockGet(void) |
sahilmgandhi | 18:6a4db94011d3 | 165 | { |
sahilmgandhi | 18:6a4db94011d3 | 166 | return (EFR32_HFRCO_MAX_FREQ > EFR32_HFXO_FREQ ? \ |
sahilmgandhi | 18:6a4db94011d3 | 167 | EFR32_HFRCO_MAX_FREQ : EFR32_HFXO_FREQ); |
sahilmgandhi | 18:6a4db94011d3 | 168 | } |
sahilmgandhi | 18:6a4db94011d3 | 169 | |
sahilmgandhi | 18:6a4db94011d3 | 170 | |
sahilmgandhi | 18:6a4db94011d3 | 171 | /***************************************************************************//** |
sahilmgandhi | 18:6a4db94011d3 | 172 | * @brief |
sahilmgandhi | 18:6a4db94011d3 | 173 | * Get the current HFCLK frequency. |
sahilmgandhi | 18:6a4db94011d3 | 174 | * |
sahilmgandhi | 18:6a4db94011d3 | 175 | * @note |
sahilmgandhi | 18:6a4db94011d3 | 176 | * This is an EFR32 proprietary function, not part of the CMSIS definition. |
sahilmgandhi | 18:6a4db94011d3 | 177 | * |
sahilmgandhi | 18:6a4db94011d3 | 178 | * @return |
sahilmgandhi | 18:6a4db94011d3 | 179 | * The current HFCLK frequency in Hz. |
sahilmgandhi | 18:6a4db94011d3 | 180 | ******************************************************************************/ |
sahilmgandhi | 18:6a4db94011d3 | 181 | uint32_t SystemHFClockGet(void) |
sahilmgandhi | 18:6a4db94011d3 | 182 | { |
sahilmgandhi | 18:6a4db94011d3 | 183 | uint32_t ret; |
sahilmgandhi | 18:6a4db94011d3 | 184 | |
sahilmgandhi | 18:6a4db94011d3 | 185 | switch (CMU->HFCLKSTATUS & _CMU_HFCLKSTATUS_SELECTED_MASK) |
sahilmgandhi | 18:6a4db94011d3 | 186 | { |
sahilmgandhi | 18:6a4db94011d3 | 187 | case CMU_HFCLKSTATUS_SELECTED_LFXO: |
sahilmgandhi | 18:6a4db94011d3 | 188 | #if (EFR32_LFXO_FREQ > 0) |
sahilmgandhi | 18:6a4db94011d3 | 189 | ret = SystemLFXOClock; |
sahilmgandhi | 18:6a4db94011d3 | 190 | #else |
sahilmgandhi | 18:6a4db94011d3 | 191 | /* We should not get here, since core should not be clocked. May */ |
sahilmgandhi | 18:6a4db94011d3 | 192 | /* be caused by a misconfiguration though. */ |
sahilmgandhi | 18:6a4db94011d3 | 193 | ret = 0; |
sahilmgandhi | 18:6a4db94011d3 | 194 | #endif |
sahilmgandhi | 18:6a4db94011d3 | 195 | break; |
sahilmgandhi | 18:6a4db94011d3 | 196 | |
sahilmgandhi | 18:6a4db94011d3 | 197 | case CMU_HFCLKSTATUS_SELECTED_LFRCO: |
sahilmgandhi | 18:6a4db94011d3 | 198 | ret = EFR32_LFRCO_FREQ; |
sahilmgandhi | 18:6a4db94011d3 | 199 | break; |
sahilmgandhi | 18:6a4db94011d3 | 200 | |
sahilmgandhi | 18:6a4db94011d3 | 201 | case CMU_HFCLKSTATUS_SELECTED_HFXO: |
sahilmgandhi | 18:6a4db94011d3 | 202 | #if (EFR32_HFXO_FREQ > 0) |
sahilmgandhi | 18:6a4db94011d3 | 203 | ret = SystemHFXOClock; |
sahilmgandhi | 18:6a4db94011d3 | 204 | #else |
sahilmgandhi | 18:6a4db94011d3 | 205 | /* We should not get here, since core should not be clocked. May */ |
sahilmgandhi | 18:6a4db94011d3 | 206 | /* be caused by a misconfiguration though. */ |
sahilmgandhi | 18:6a4db94011d3 | 207 | ret = 0; |
sahilmgandhi | 18:6a4db94011d3 | 208 | #endif |
sahilmgandhi | 18:6a4db94011d3 | 209 | break; |
sahilmgandhi | 18:6a4db94011d3 | 210 | |
sahilmgandhi | 18:6a4db94011d3 | 211 | default: /* CMU_HFCLKSTATUS_SELECTED_HFRCO */ |
sahilmgandhi | 18:6a4db94011d3 | 212 | ret = SystemHfrcoFreq; |
sahilmgandhi | 18:6a4db94011d3 | 213 | break; |
sahilmgandhi | 18:6a4db94011d3 | 214 | } |
sahilmgandhi | 18:6a4db94011d3 | 215 | |
sahilmgandhi | 18:6a4db94011d3 | 216 | return ret / (1U + ((CMU->HFPRESC & _CMU_HFPRESC_PRESC_MASK) |
sahilmgandhi | 18:6a4db94011d3 | 217 | >> _CMU_HFPRESC_PRESC_SHIFT)); |
sahilmgandhi | 18:6a4db94011d3 | 218 | } |
sahilmgandhi | 18:6a4db94011d3 | 219 | |
sahilmgandhi | 18:6a4db94011d3 | 220 | |
sahilmgandhi | 18:6a4db94011d3 | 221 | /**************************************************************************//** |
sahilmgandhi | 18:6a4db94011d3 | 222 | * @brief |
sahilmgandhi | 18:6a4db94011d3 | 223 | * Get high frequency crystal oscillator clock frequency for target system. |
sahilmgandhi | 18:6a4db94011d3 | 224 | * |
sahilmgandhi | 18:6a4db94011d3 | 225 | * @note |
sahilmgandhi | 18:6a4db94011d3 | 226 | * This is an EFR32 proprietary function, not part of the CMSIS definition. |
sahilmgandhi | 18:6a4db94011d3 | 227 | * |
sahilmgandhi | 18:6a4db94011d3 | 228 | * @return |
sahilmgandhi | 18:6a4db94011d3 | 229 | * HFXO frequency in Hz. |
sahilmgandhi | 18:6a4db94011d3 | 230 | *****************************************************************************/ |
sahilmgandhi | 18:6a4db94011d3 | 231 | uint32_t SystemHFXOClockGet(void) |
sahilmgandhi | 18:6a4db94011d3 | 232 | { |
sahilmgandhi | 18:6a4db94011d3 | 233 | /* External crystal oscillator present? */ |
sahilmgandhi | 18:6a4db94011d3 | 234 | #if (EFR32_HFXO_FREQ > 0) |
sahilmgandhi | 18:6a4db94011d3 | 235 | return SystemHFXOClock; |
sahilmgandhi | 18:6a4db94011d3 | 236 | #else |
sahilmgandhi | 18:6a4db94011d3 | 237 | return 0; |
sahilmgandhi | 18:6a4db94011d3 | 238 | #endif |
sahilmgandhi | 18:6a4db94011d3 | 239 | } |
sahilmgandhi | 18:6a4db94011d3 | 240 | |
sahilmgandhi | 18:6a4db94011d3 | 241 | |
sahilmgandhi | 18:6a4db94011d3 | 242 | /**************************************************************************//** |
sahilmgandhi | 18:6a4db94011d3 | 243 | * @brief |
sahilmgandhi | 18:6a4db94011d3 | 244 | * Set high frequency crystal oscillator clock frequency for target system. |
sahilmgandhi | 18:6a4db94011d3 | 245 | * |
sahilmgandhi | 18:6a4db94011d3 | 246 | * @note |
sahilmgandhi | 18:6a4db94011d3 | 247 | * This function is mainly provided for being able to handle target systems |
sahilmgandhi | 18:6a4db94011d3 | 248 | * with different HF crystal oscillator frequencies run-time. If used, it |
sahilmgandhi | 18:6a4db94011d3 | 249 | * should probably only be used once during system startup. |
sahilmgandhi | 18:6a4db94011d3 | 250 | * |
sahilmgandhi | 18:6a4db94011d3 | 251 | * @note |
sahilmgandhi | 18:6a4db94011d3 | 252 | * This is an EFR32 proprietary function, not part of the CMSIS definition. |
sahilmgandhi | 18:6a4db94011d3 | 253 | * |
sahilmgandhi | 18:6a4db94011d3 | 254 | * @param[in] freq |
sahilmgandhi | 18:6a4db94011d3 | 255 | * HFXO frequency in Hz used for target. |
sahilmgandhi | 18:6a4db94011d3 | 256 | *****************************************************************************/ |
sahilmgandhi | 18:6a4db94011d3 | 257 | void SystemHFXOClockSet(uint32_t freq) |
sahilmgandhi | 18:6a4db94011d3 | 258 | { |
sahilmgandhi | 18:6a4db94011d3 | 259 | /* External crystal oscillator present? */ |
sahilmgandhi | 18:6a4db94011d3 | 260 | #if (EFR32_HFXO_FREQ > 0) |
sahilmgandhi | 18:6a4db94011d3 | 261 | SystemHFXOClock = freq; |
sahilmgandhi | 18:6a4db94011d3 | 262 | |
sahilmgandhi | 18:6a4db94011d3 | 263 | /* Update core clock frequency if HFXO is used to clock core */ |
sahilmgandhi | 18:6a4db94011d3 | 264 | if ((CMU->HFCLKSTATUS & _CMU_HFCLKSTATUS_SELECTED_MASK) == CMU_HFCLKSTATUS_SELECTED_HFXO) |
sahilmgandhi | 18:6a4db94011d3 | 265 | { |
sahilmgandhi | 18:6a4db94011d3 | 266 | /* The function will update the global variable */ |
sahilmgandhi | 18:6a4db94011d3 | 267 | SystemCoreClockGet(); |
sahilmgandhi | 18:6a4db94011d3 | 268 | } |
sahilmgandhi | 18:6a4db94011d3 | 269 | #else |
sahilmgandhi | 18:6a4db94011d3 | 270 | (void)freq; /* Unused parameter */ |
sahilmgandhi | 18:6a4db94011d3 | 271 | #endif |
sahilmgandhi | 18:6a4db94011d3 | 272 | } |
sahilmgandhi | 18:6a4db94011d3 | 273 | |
sahilmgandhi | 18:6a4db94011d3 | 274 | |
sahilmgandhi | 18:6a4db94011d3 | 275 | /**************************************************************************//** |
sahilmgandhi | 18:6a4db94011d3 | 276 | * @brief |
sahilmgandhi | 18:6a4db94011d3 | 277 | * Initialize the system. |
sahilmgandhi | 18:6a4db94011d3 | 278 | * |
sahilmgandhi | 18:6a4db94011d3 | 279 | * @details |
sahilmgandhi | 18:6a4db94011d3 | 280 | * Do required generic HW system init. |
sahilmgandhi | 18:6a4db94011d3 | 281 | * |
sahilmgandhi | 18:6a4db94011d3 | 282 | * @note |
sahilmgandhi | 18:6a4db94011d3 | 283 | * This function is invoked during system init, before the main() routine |
sahilmgandhi | 18:6a4db94011d3 | 284 | * and any data has been initialized. For this reason, it cannot do any |
sahilmgandhi | 18:6a4db94011d3 | 285 | * initialization of variables etc. |
sahilmgandhi | 18:6a4db94011d3 | 286 | *****************************************************************************/ |
sahilmgandhi | 18:6a4db94011d3 | 287 | void SystemInit(void) |
sahilmgandhi | 18:6a4db94011d3 | 288 | { |
sahilmgandhi | 18:6a4db94011d3 | 289 | #if (__FPU_PRESENT == 1) && (__FPU_USED == 1) |
sahilmgandhi | 18:6a4db94011d3 | 290 | /* Set floating point coprosessor access mode. */ |
sahilmgandhi | 18:6a4db94011d3 | 291 | SCB->CPACR |= ((3UL << 10*2) | /* set CP10 Full Access */ |
sahilmgandhi | 18:6a4db94011d3 | 292 | (3UL << 11*2) ); /* set CP11 Full Access */ |
sahilmgandhi | 18:6a4db94011d3 | 293 | #endif |
sahilmgandhi | 18:6a4db94011d3 | 294 | } |
sahilmgandhi | 18:6a4db94011d3 | 295 | |
sahilmgandhi | 18:6a4db94011d3 | 296 | |
sahilmgandhi | 18:6a4db94011d3 | 297 | /**************************************************************************//** |
sahilmgandhi | 18:6a4db94011d3 | 298 | * @brief |
sahilmgandhi | 18:6a4db94011d3 | 299 | * Get low frequency RC oscillator clock frequency for target system. |
sahilmgandhi | 18:6a4db94011d3 | 300 | * |
sahilmgandhi | 18:6a4db94011d3 | 301 | * @note |
sahilmgandhi | 18:6a4db94011d3 | 302 | * This is an EFR32 proprietary function, not part of the CMSIS definition. |
sahilmgandhi | 18:6a4db94011d3 | 303 | * |
sahilmgandhi | 18:6a4db94011d3 | 304 | * @return |
sahilmgandhi | 18:6a4db94011d3 | 305 | * LFRCO frequency in Hz. |
sahilmgandhi | 18:6a4db94011d3 | 306 | *****************************************************************************/ |
sahilmgandhi | 18:6a4db94011d3 | 307 | uint32_t SystemLFRCOClockGet(void) |
sahilmgandhi | 18:6a4db94011d3 | 308 | { |
sahilmgandhi | 18:6a4db94011d3 | 309 | /* Currently we assume that this frequency is properly tuned during */ |
sahilmgandhi | 18:6a4db94011d3 | 310 | /* manufacturing and is not changed after reset. If future requirements */ |
sahilmgandhi | 18:6a4db94011d3 | 311 | /* for re-tuning by user, we can add support for that. */ |
sahilmgandhi | 18:6a4db94011d3 | 312 | return EFR32_LFRCO_FREQ; |
sahilmgandhi | 18:6a4db94011d3 | 313 | } |
sahilmgandhi | 18:6a4db94011d3 | 314 | |
sahilmgandhi | 18:6a4db94011d3 | 315 | |
sahilmgandhi | 18:6a4db94011d3 | 316 | /**************************************************************************//** |
sahilmgandhi | 18:6a4db94011d3 | 317 | * @brief |
sahilmgandhi | 18:6a4db94011d3 | 318 | * Get ultra low frequency RC oscillator clock frequency for target system. |
sahilmgandhi | 18:6a4db94011d3 | 319 | * |
sahilmgandhi | 18:6a4db94011d3 | 320 | * @note |
sahilmgandhi | 18:6a4db94011d3 | 321 | * This is an EFR32 proprietary function, not part of the CMSIS definition. |
sahilmgandhi | 18:6a4db94011d3 | 322 | * |
sahilmgandhi | 18:6a4db94011d3 | 323 | * @return |
sahilmgandhi | 18:6a4db94011d3 | 324 | * ULFRCO frequency in Hz. |
sahilmgandhi | 18:6a4db94011d3 | 325 | *****************************************************************************/ |
sahilmgandhi | 18:6a4db94011d3 | 326 | uint32_t SystemULFRCOClockGet(void) |
sahilmgandhi | 18:6a4db94011d3 | 327 | { |
sahilmgandhi | 18:6a4db94011d3 | 328 | /* The ULFRCO frequency is not tuned, and can be very inaccurate */ |
sahilmgandhi | 18:6a4db94011d3 | 329 | return EFR32_ULFRCO_FREQ; |
sahilmgandhi | 18:6a4db94011d3 | 330 | } |
sahilmgandhi | 18:6a4db94011d3 | 331 | |
sahilmgandhi | 18:6a4db94011d3 | 332 | |
sahilmgandhi | 18:6a4db94011d3 | 333 | /**************************************************************************//** |
sahilmgandhi | 18:6a4db94011d3 | 334 | * @brief |
sahilmgandhi | 18:6a4db94011d3 | 335 | * Get low frequency crystal oscillator clock frequency for target system. |
sahilmgandhi | 18:6a4db94011d3 | 336 | * |
sahilmgandhi | 18:6a4db94011d3 | 337 | * @note |
sahilmgandhi | 18:6a4db94011d3 | 338 | * This is an EFR32 proprietary function, not part of the CMSIS definition. |
sahilmgandhi | 18:6a4db94011d3 | 339 | * |
sahilmgandhi | 18:6a4db94011d3 | 340 | * @return |
sahilmgandhi | 18:6a4db94011d3 | 341 | * LFXO frequency in Hz. |
sahilmgandhi | 18:6a4db94011d3 | 342 | *****************************************************************************/ |
sahilmgandhi | 18:6a4db94011d3 | 343 | uint32_t SystemLFXOClockGet(void) |
sahilmgandhi | 18:6a4db94011d3 | 344 | { |
sahilmgandhi | 18:6a4db94011d3 | 345 | /* External crystal oscillator present? */ |
sahilmgandhi | 18:6a4db94011d3 | 346 | #if (EFR32_LFXO_FREQ > 0) |
sahilmgandhi | 18:6a4db94011d3 | 347 | return SystemLFXOClock; |
sahilmgandhi | 18:6a4db94011d3 | 348 | #else |
sahilmgandhi | 18:6a4db94011d3 | 349 | return 0; |
sahilmgandhi | 18:6a4db94011d3 | 350 | #endif |
sahilmgandhi | 18:6a4db94011d3 | 351 | } |
sahilmgandhi | 18:6a4db94011d3 | 352 | |
sahilmgandhi | 18:6a4db94011d3 | 353 | |
sahilmgandhi | 18:6a4db94011d3 | 354 | /**************************************************************************//** |
sahilmgandhi | 18:6a4db94011d3 | 355 | * @brief |
sahilmgandhi | 18:6a4db94011d3 | 356 | * Set low frequency crystal oscillator clock frequency for target system. |
sahilmgandhi | 18:6a4db94011d3 | 357 | * |
sahilmgandhi | 18:6a4db94011d3 | 358 | * @note |
sahilmgandhi | 18:6a4db94011d3 | 359 | * This function is mainly provided for being able to handle target systems |
sahilmgandhi | 18:6a4db94011d3 | 360 | * with different HF crystal oscillator frequencies run-time. If used, it |
sahilmgandhi | 18:6a4db94011d3 | 361 | * should probably only be used once during system startup. |
sahilmgandhi | 18:6a4db94011d3 | 362 | * |
sahilmgandhi | 18:6a4db94011d3 | 363 | * @note |
sahilmgandhi | 18:6a4db94011d3 | 364 | * This is an EFR32 proprietary function, not part of the CMSIS definition. |
sahilmgandhi | 18:6a4db94011d3 | 365 | * |
sahilmgandhi | 18:6a4db94011d3 | 366 | * @param[in] freq |
sahilmgandhi | 18:6a4db94011d3 | 367 | * LFXO frequency in Hz used for target. |
sahilmgandhi | 18:6a4db94011d3 | 368 | *****************************************************************************/ |
sahilmgandhi | 18:6a4db94011d3 | 369 | void SystemLFXOClockSet(uint32_t freq) |
sahilmgandhi | 18:6a4db94011d3 | 370 | { |
sahilmgandhi | 18:6a4db94011d3 | 371 | /* External crystal oscillator present? */ |
sahilmgandhi | 18:6a4db94011d3 | 372 | #if (EFR32_LFXO_FREQ > 0) |
sahilmgandhi | 18:6a4db94011d3 | 373 | SystemLFXOClock = freq; |
sahilmgandhi | 18:6a4db94011d3 | 374 | |
sahilmgandhi | 18:6a4db94011d3 | 375 | /* Update core clock frequency if LFXO is used to clock core */ |
sahilmgandhi | 18:6a4db94011d3 | 376 | if ((CMU->HFCLKSTATUS & _CMU_HFCLKSTATUS_SELECTED_MASK) == CMU_HFCLKSTATUS_SELECTED_LFXO) |
sahilmgandhi | 18:6a4db94011d3 | 377 | { |
sahilmgandhi | 18:6a4db94011d3 | 378 | /* The function will update the global variable */ |
sahilmgandhi | 18:6a4db94011d3 | 379 | SystemCoreClockGet(); |
sahilmgandhi | 18:6a4db94011d3 | 380 | } |
sahilmgandhi | 18:6a4db94011d3 | 381 | #else |
sahilmgandhi | 18:6a4db94011d3 | 382 | (void)freq; /* Unused parameter */ |
sahilmgandhi | 18:6a4db94011d3 | 383 | #endif |
sahilmgandhi | 18:6a4db94011d3 | 384 | } |