1 /***************************************************************************//**
\r
5 *******************************************************************************
\r
7 * <b>(C) Copyright 2015 Silicon Labs, http://www.silabs.com</b>
\r
8 *******************************************************************************
\r
10 * Permission is granted to anyone to use this software for any purpose,
\r
11 * including commercial applications, and to alter it and redistribute it
\r
12 * freely, subject to the following restrictions:
\r
14 * 1. The origin of this software must not be misrepresented; you must not
\r
15 * claim that you wrote the original software.
\r
16 * 2. Altered source versions must be plainly marked as such, and must not be
\r
17 * misrepresented as being the original software.
\r
18 * 3. This notice may not be removed or altered from any source distribution.
\r
20 * DISCLAIMER OF WARRANTY/LIMITATION OF REMEDIES: Silicon Labs has no
\r
21 * obligation to support this Software. Silicon Labs is providing the
\r
22 * Software "AS IS", with no express or implied warranties of any kind,
\r
23 * including, but not limited to, any implied warranties of merchantability
\r
24 * or fitness for any particular purpose or warranties against infringement
\r
25 * of any proprietary rights of a third party.
\r
27 * Silicon Labs will not be liable for any consequential, incidental, or
\r
28 * special damages, or any other relief, or for any claim by any third party,
\r
29 * arising from your use of this Software.
\r
31 ******************************************************************************/
\r
33 #ifndef __SILICON_LABS_EM_SYSTEM_H__
\r
34 #define __SILICON_LABS_EM_SYSTEM_H__
\r
36 #include <stdbool.h>
\r
37 #include "em_device.h"
\r
43 /***************************************************************************//**
\r
44 * @addtogroup EM_Library
\r
46 ******************************************************************************/
\r
48 /***************************************************************************//**
\r
49 * @addtogroup SYSTEM
\r
51 ******************************************************************************/
\r
53 /*******************************************************************************
\r
54 ******************************** ENUMS ************************************
\r
55 ******************************************************************************/
\r
57 /** Family identifiers. */
\r
60 /* New style family #defines */
\r
61 #if defined(_DEVINFO_PART_DEVICE_FAMILY_EFM32G)
\r
62 systemPartFamilyEfm32Gecko = _DEVINFO_PART_DEVICE_FAMILY_EFM32G, /**< EFM32 Gecko Device Family */
\r
64 #if defined(_DEVINFO_PART_DEVICE_FAMILY_EFM32GG)
\r
65 systemPartFamilyEfm32Giant = _DEVINFO_PART_DEVICE_FAMILY_EFM32GG, /**< EFM32 Giant Gecko Device Family */
\r
67 #if defined(_DEVINFO_PART_DEVICE_FAMILY_EFM32TG)
\r
68 systemPartFamilyEfm32Tiny = _DEVINFO_PART_DEVICE_FAMILY_EFM32TG, /**< EFM32 Tiny Gecko Device Family */
\r
70 #if defined(_DEVINFO_PART_DEVICE_FAMILY_EFM32LG)
\r
71 systemPartFamilyEfm32Leopard = _DEVINFO_PART_DEVICE_FAMILY_EFM32LG, /**< EFM32 Leopard Gecko Device Family */
\r
73 #if defined(_DEVINFO_PART_DEVICE_FAMILY_EFM32WG)
\r
74 systemPartFamilyEfm32Wonder = _DEVINFO_PART_DEVICE_FAMILY_EFM32WG, /**< EFM32 Wonder Gecko Device Family */
\r
76 #if defined(_DEVINFO_PART_DEVICE_FAMILY_EFM32ZG)
\r
77 systemPartFamilyEfm32Zero = _DEVINFO_PART_DEVICE_FAMILY_EFM32ZG, /**< EFM32 Zero Gecko Device Family */
\r
79 #if defined(_DEVINFO_PART_DEVICE_FAMILY_EFM32HG)
\r
80 systemPartFamilyEfm32Happy = _DEVINFO_PART_DEVICE_FAMILY_EFM32HG, /**< EFM32 Happy Gecko Device Family */
\r
82 #if defined(_DEVINFO_PART_DEVICE_FAMILY_EFM32PG1B)
\r
83 systemPartFamilyEfm32Pearl1B = _DEVINFO_PART_DEVICE_FAMILY_EFM32PG1B, /**< EFM32 Pearl Gecko Gen1 Basic Device Family */
\r
85 #if defined(_DEVINFO_PART_DEVICE_FAMILY_EFM32JG1B)
\r
86 systemPartFamilyEfm32Jade1B = _DEVINFO_PART_DEVICE_FAMILY_EFM32JG1B, /**< EFM32 Jade Gecko Gen1 Basic Device Family */
\r
88 #if defined(_DEVINFO_PART_DEVICE_FAMILY_EZR32WG)
\r
89 systemPartFamilyEzr32Wonder = _DEVINFO_PART_DEVICE_FAMILY_EZR32WG, /**< EZR32 Wonder Device Family */
\r
91 #if defined(_DEVINFO_PART_DEVICE_FAMILY_EZR32LG)
\r
92 systemPartFamilyEzr32Leopard = _DEVINFO_PART_DEVICE_FAMILY_EZR32LG, /**< EZR32 Leopard Device Family */
\r
94 #if defined(_DEVINFO_PART_DEVICE_FAMILY_EZR32HG)
\r
95 systemPartFamilyEzr32Happy = _DEVINFO_PART_DEVICE_FAMILY_EZR32HG, /**< EZR32 Happy Device Family */
\r
97 #if defined(_DEVINFO_PART_DEVICE_FAMILY_EFR32MG1P)
\r
98 systemPartFamilyMighty1P = _DEVINFO_PART_DEVICE_FAMILY_EFR32MG1P, /**< EFR32 Mighty Gecko Gen1 Premium Device Family */
\r
100 #if defined(_DEVINFO_PART_DEVICE_FAMILY_EFR32MG1B)
\r
101 systemPartFamilyMighty1B = _DEVINFO_PART_DEVICE_FAMILY_EFR32MG1B, /**< EFR32 Mighty Gecko Gen1 Basic Device Family */
\r
103 #if defined(_DEVINFO_PART_DEVICE_FAMILY_EFR32MG1V)
\r
104 systemPartFamilyMighty1V = _DEVINFO_PART_DEVICE_FAMILY_EFR32MG1V, /**< EFR32 Mighty Gecko Gen1 Value Device Family */
\r
106 #if defined(_DEVINFO_PART_DEVICE_FAMILY_EFR32BG1P)
\r
107 systemPartFamilyBlue1P = _DEVINFO_PART_DEVICE_FAMILY_EFR32BG1P, /**< EFR32 Blue Gecko Gen1 Premium Device Family */
\r
109 #if defined(_DEVINFO_PART_DEVICE_FAMILY_EFR32BG1B)
\r
110 systemPartFamilyBlue1B = _DEVINFO_PART_DEVICE_FAMILY_EFR32BG1B, /**< EFR32 Blue Gecko Gen1 Basic Device Family */
\r
112 #if defined(_DEVINFO_PART_DEVICE_FAMILY_EFR32BG1V)
\r
113 systemPartFamilyBlue1V = _DEVINFO_PART_DEVICE_FAMILY_EFR32BG1V, /**< EFR32 Blue Gecko Gen1 Value Device Family */
\r
115 #if defined(_DEVINFO_PART_DEVICE_FAMILY_EFR32SG1P)
\r
116 systemPartFamilySnappy1P = _DEVINFO_PART_DEVICE_FAMILY_EFR32SG1P, /**< EFR32 Snappy Gecko Gen1 Premium Device Family */
\r
118 #if defined(_DEVINFO_PART_DEVICE_FAMILY_EFR32SG1B)
\r
119 systemPartFamilySnappy1B = _DEVINFO_PART_DEVICE_FAMILY_EFR32SG1B, /**< EFR32 Snappy Gecko Gen1 Basic Device Family */
\r
121 #if defined(_DEVINFO_PART_DEVICE_FAMILY_EFR32SG1V)
\r
122 systemPartFamilySnappy1V = _DEVINFO_PART_DEVICE_FAMILY_EFR32SG1V, /**< EFR32 Snappy Gecko Gen1 Value Device Family */
\r
124 #if defined(_DEVINFO_PART_DEVICE_FAMILY_EFR32FG1P)
\r
125 systemPartFamilyFlex1P = _DEVINFO_PART_DEVICE_FAMILY_EFR32FG1P, /**< EFR32 Flex Gecko Gen1 Premium Device Family */
\r
127 #if defined(_DEVINFO_PART_DEVICE_FAMILY_EFR32FG1B)
\r
128 systemPartFamilyFlex1B = _DEVINFO_PART_DEVICE_FAMILY_EFR32FG1B, /**< EFR32 Flex Gecko Gen1 Basic Device Family */
\r
130 #if defined(_DEVINFO_PART_DEVICE_FAMILY_EFR32FG1V)
\r
131 systemPartFamilyFlex1V = _DEVINFO_PART_DEVICE_FAMILY_EFR32FG1V, /**< EFR32 Flex Gecko Gen1 Value Device Family */
\r
133 /* Legacy family #defines */
\r
134 #if defined(_DEVINFO_PART_DEVICE_FAMILY_G)
\r
135 systemPartFamilyGecko = _DEVINFO_PART_DEVICE_FAMILY_G, /**< Gecko Device Family */
\r
137 #if defined(_DEVINFO_PART_DEVICE_FAMILY_GG)
\r
138 systemPartFamilyGiant = _DEVINFO_PART_DEVICE_FAMILY_GG, /**< Giant Gecko Device Family */
\r
140 #if defined(_DEVINFO_PART_DEVICE_FAMILY_TG)
\r
141 systemPartFamilyTiny = _DEVINFO_PART_DEVICE_FAMILY_TG, /**< Tiny Gecko Device Family */
\r
143 #if defined(_DEVINFO_PART_DEVICE_FAMILY_LG)
\r
144 systemPartFamilyLeopard = _DEVINFO_PART_DEVICE_FAMILY_LG, /**< Leopard Gecko Device Family */
\r
146 #if defined(_DEVINFO_PART_DEVICE_FAMILY_WG)
\r
147 systemPartFamilyWonder = _DEVINFO_PART_DEVICE_FAMILY_WG, /**< Wonder Gecko Device Family */
\r
149 #if defined(_DEVINFO_PART_DEVICE_FAMILY_ZG)
\r
150 systemPartFamilyZero = _DEVINFO_PART_DEVICE_FAMILY_ZG, /**< Zero Gecko Device Family */
\r
152 #if defined(_DEVINFO_PART_DEVICE_FAMILY_HG)
\r
153 systemPartFamilyHappy = _DEVINFO_PART_DEVICE_FAMILY_HG, /**< Happy Gecko Device Family */
\r
155 systemPartFamilyUnknown = 0xFF /**< Unknown Device Family.
\r
156 The family id is missing
\r
157 on unprogrammed parts. */
\r
158 } SYSTEM_PartFamily_TypeDef;
\r
161 /*******************************************************************************
\r
162 ******************************* STRUCTS ***********************************
\r
163 ******************************************************************************/
\r
165 /** Chip revision details */
\r
168 uint8_t minor; /**< Minor revision number */
\r
169 uint8_t major; /**< Major revision number */
\r
170 uint8_t family;/**< Device family number */
\r
171 } SYSTEM_ChipRevision_TypeDef;
\r
173 #if defined(__FPU_PRESENT) && (__FPU_PRESENT == 1)
\r
174 /** Floating point coprocessor access modes. */
\r
177 fpuAccessDenied = (0x0 << 20), /**< Access denied, any attempted access generates a NOCP UsageFault. */
\r
178 fpuAccessPrivilegedOnly = (0x5 << 20), /**< Privileged access only, an unprivileged access generates a NOCP UsageFault. */
\r
179 fpuAccessReserved = (0xA << 20), /**< Reserved. */
\r
180 fpuAccessFull = (0xF << 20) /**< Full access. */
\r
181 } SYSTEM_FpuAccess_TypeDef;
\r
184 /*******************************************************************************
\r
185 ***************************** PROTOTYPES **********************************
\r
186 ******************************************************************************/
\r
188 void SYSTEM_ChipRevisionGet(SYSTEM_ChipRevision_TypeDef *rev);
\r
189 uint32_t SYSTEM_GetCalibrationValue(volatile uint32_t *regAddress);
\r
191 #if defined(__FPU_PRESENT) && (__FPU_PRESENT == 1)
\r
192 /***************************************************************************//**
\r
194 * Set floating point coprocessor (FPU) access mode.
\r
196 * @param[in] accessMode
\r
197 * Floating point coprocessor access mode. See @ref SYSTEM_FpuAccess_TypeDef
\r
199 ******************************************************************************/
\r
200 __STATIC_INLINE void SYSTEM_FpuAccessModeSet(SYSTEM_FpuAccess_TypeDef accessMode)
\r
202 SCB->CPACR = (SCB->CPACR & ~(0xF << 20)) | accessMode;
\r
206 /***************************************************************************//**
\r
208 * Get the unique number for this part.
\r
211 * Unique number for this part.
\r
212 ******************************************************************************/
\r
213 __STATIC_INLINE uint64_t SYSTEM_GetUnique(void)
\r
215 return (uint64_t)((uint64_t)DEVINFO->UNIQUEH << 32) | (uint64_t)DEVINFO->UNIQUEL;
\r
218 /***************************************************************************//**
\r
220 * Get the production revision for this part.
\r
223 * Production revision for this part.
\r
224 ******************************************************************************/
\r
225 __STATIC_INLINE uint8_t SYSTEM_GetProdRev(void)
\r
227 return (DEVINFO->PART & _DEVINFO_PART_PROD_REV_MASK)
\r
228 >> _DEVINFO_PART_PROD_REV_SHIFT;
\r
231 /***************************************************************************//**
\r
233 * Get the SRAM size (in KB).
\r
236 * This function retrievs the correct value by reading the chip device
\r
237 * info structure. If your binary is made for one specific device only,
\r
238 * the \#define SRAM_SIZE can be used instead.
\r
241 * The size of the internal SRAM (in KB).
\r
242 ******************************************************************************/
\r
243 __STATIC_INLINE uint16_t SYSTEM_GetSRAMSize(void)
\r
245 #if defined(_EFM32_GECKO_FAMILY)
\r
246 /* Early Gecko devices had a bug where SRAM and Flash size were swapped. */
\r
247 if (SYSTEM_GetProdRev() < 5)
\r
249 return (DEVINFO->MSIZE & _DEVINFO_MSIZE_FLASH_MASK)
\r
250 >> _DEVINFO_MSIZE_FLASH_SHIFT;
\r
253 return (DEVINFO->MSIZE & _DEVINFO_MSIZE_SRAM_MASK)
\r
254 >> _DEVINFO_MSIZE_SRAM_SHIFT;
\r
257 /***************************************************************************//**
\r
259 * Get the flash size (in KB).
\r
262 * This function retrievs the correct value by reading the chip device
\r
263 * info structure. If your binary is made for one specific device only,
\r
264 * the \#define FLASH_SIZE can be used instead.
\r
267 * The size of the internal flash (in KB).
\r
268 ******************************************************************************/
\r
269 __STATIC_INLINE uint16_t SYSTEM_GetFlashSize(void)
\r
271 #if defined(_EFM32_GECKO_FAMILY)
\r
272 /* Early Gecko devices had a bug where SRAM and Flash size were swapped. */
\r
273 if (SYSTEM_GetProdRev() < 5)
\r
275 return (DEVINFO->MSIZE & _DEVINFO_MSIZE_SRAM_MASK)
\r
276 >> _DEVINFO_MSIZE_SRAM_SHIFT;
\r
279 return (DEVINFO->MSIZE & _DEVINFO_MSIZE_FLASH_MASK)
\r
280 >> _DEVINFO_MSIZE_FLASH_SHIFT;
\r
284 /***************************************************************************//**
\r
286 * Get the flash page size in bytes.
\r
289 * This function retrievs the correct value by reading the chip device
\r
290 * info structure. If your binary is made for one specific device only,
\r
291 * the \#define FLASH_PAGE_SIZE can be used instead.
\r
294 * The page size of the internal flash in bytes.
\r
295 ******************************************************************************/
\r
296 __STATIC_INLINE uint32_t SYSTEM_GetFlashPageSize(void)
\r
300 #if defined(_EFM32_GIANT_FAMILY)
\r
301 if (SYSTEM_GetProdRev() < 18)
\r
303 /* Early Giant/Leopard devices did not have MEMINFO in DEVINFO. */
\r
304 return FLASH_PAGE_SIZE;
\r
306 #elif defined(_EFM32_ZERO_FAMILY)
\r
307 if (SYSTEM_GetProdRev() < 24)
\r
309 /* Early Zero devices have an incorrect DEVINFO flash page size */
\r
310 return FLASH_PAGE_SIZE;
\r
314 tmp = (DEVINFO->MEMINFO & _DEVINFO_MEMINFO_FLASH_PAGE_SIZE_MASK)
\r
315 >> _DEVINFO_MEMINFO_FLASH_PAGE_SIZE_SHIFT;
\r
317 return 1 << ((tmp + 10) & 0xFF);
\r
321 #if defined( _DEVINFO_DEVINFOREV_DEVINFOREV_MASK )
\r
322 /***************************************************************************//**
\r
324 * Get DEVINFO revision.
\r
327 * Revision of the DEVINFO contents.
\r
328 ******************************************************************************/
\r
329 __STATIC_INLINE uint8_t SYSTEM_GetDevinfoRev(void)
\r
331 return (DEVINFO->DEVINFOREV & _DEVINFO_DEVINFOREV_DEVINFOREV_MASK)
\r
332 >> _DEVINFO_DEVINFOREV_DEVINFOREV_SHIFT;
\r
337 /***************************************************************************//**
\r
339 * Get part number of the MCU.
\r
342 * The part number of the MCU.
\r
343 ******************************************************************************/
\r
344 __STATIC_INLINE uint16_t SYSTEM_GetPartNumber(void)
\r
346 return (DEVINFO->PART & _DEVINFO_PART_DEVICE_NUMBER_MASK)
\r
347 >> _DEVINFO_PART_DEVICE_NUMBER_SHIFT;
\r
350 /***************************************************************************//**
\r
352 * Get family identifier of the MCU.
\r
355 * This function retrievs the family id by reading the chip's device info
\r
356 * structure in flash memory. The user can retrieve the family id directly
\r
357 * by reading the DEVINFO->PART item and decode with the mask and shift
\r
358 * \#defines defined in \<part_family\>_devinfo.h (please refer to code
\r
359 * below for details).
\r
362 * The family identifier of the MCU.
\r
363 ******************************************************************************/
\r
364 __STATIC_INLINE SYSTEM_PartFamily_TypeDef SYSTEM_GetFamily(void)
\r
366 return (SYSTEM_PartFamily_TypeDef)
\r
367 ((DEVINFO->PART & _DEVINFO_PART_DEVICE_FAMILY_MASK)
\r
368 >> _DEVINFO_PART_DEVICE_FAMILY_SHIFT);
\r
372 /***************************************************************************//**
\r
374 * Get the calibration temperature (in degrees Celsius).
\r
377 * The calibration temperature in Celsius.
\r
378 ******************************************************************************/
\r
379 __STATIC_INLINE uint8_t SYSTEM_GetCalibrationTemperature(void)
\r
381 return (DEVINFO->CAL & _DEVINFO_CAL_TEMP_MASK)
\r
382 >> _DEVINFO_CAL_TEMP_SHIFT;
\r
385 /** @} (end addtogroup SYSTEM) */
\r
386 /** @} (end addtogroup EM_Library) */
\r
392 #endif /* __SILICON_LABS_EM_SYSTEM_H__ */
\r