1 /***************************************************************************//**
\r
5 *******************************************************************************
\r
7 * <b>(C) Copyright 2014 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
34 #ifndef __SILICON_LABS_EM_SYSTEM_H_
\r
35 #define __SILICON_LABS_EM_SYSTEM_H_
\r
37 #include <stdbool.h>
\r
38 #include "em_device.h"
\r
44 /***************************************************************************//**
\r
45 * @addtogroup EM_Library
\r
47 ******************************************************************************/
\r
49 /***************************************************************************//**
\r
50 * @addtogroup SYSTEM
\r
52 ******************************************************************************/
\r
54 /*******************************************************************************
\r
55 ******************************** ENUMS ************************************
\r
56 ******************************************************************************/
\r
58 /** EFM32 part family identifiers. */
\r
61 /* New style family #defines */
\r
62 #if defined ( _DEVINFO_PART_DEVICE_FAMILY_EFM32G )
\r
63 systemPartFamilyEfm32Gecko = _DEVINFO_PART_DEVICE_FAMILY_EFM32G, /**< EFM32 Gecko Device Family */
\r
65 #if defined ( _DEVINFO_PART_DEVICE_FAMILY_EFM32GG )
\r
66 systemPartFamilyEfm32Giant = _DEVINFO_PART_DEVICE_FAMILY_EFM32GG, /**< EFM32 Giant Gecko Device Family */
\r
68 #if defined( _DEVINFO_PART_DEVICE_FAMILY_EFM32TG )
\r
69 systemPartFamilyEfm32Tiny = _DEVINFO_PART_DEVICE_FAMILY_EFM32TG, /**< EFM32 Tiny Gecko Device Family */
\r
71 #if defined( _DEVINFO_PART_DEVICE_FAMILY_EFM32LG )
\r
72 systemPartFamilyEfm32Leopard = _DEVINFO_PART_DEVICE_FAMILY_EFM32LG, /**< EFM32 Leopard Gecko Device Family */
\r
74 #if defined( _DEVINFO_PART_DEVICE_FAMILY_EFM32WG )
\r
75 systemPartFamilyEfm32Wonder = _DEVINFO_PART_DEVICE_FAMILY_EFM32WG, /**< EFM32 Wonder Gecko Device Family */
\r
77 #if defined( _DEVINFO_PART_DEVICE_FAMILY_EFM32ZG )
\r
78 systemPartFamilyEfm32Zero = _DEVINFO_PART_DEVICE_FAMILY_EFM32ZG, /**< EFM32 Zero Gecko Device Family */
\r
80 #if defined( _DEVINFO_PART_DEVICE_FAMILY_EFM32HG )
\r
81 systemPartFamilyEfm32Happy = _DEVINFO_PART_DEVICE_FAMILY_EFM32HG, /**< EFM32 Happy Gecko Device Family */
\r
83 #if defined( _DEVINFO_PART_DEVICE_FAMILY_EZR32WG )
\r
84 systemPartFamilyEzr32Wonder = _DEVINFO_PART_DEVICE_FAMILY_EZR32WG, /**< EZR32 Wonder Device Family */
\r
86 #if defined( _DEVINFO_PART_DEVICE_FAMILY_EZR32LG )
\r
87 systemPartFamilyEzr32Leopard = _DEVINFO_PART_DEVICE_FAMILY_EZR32LG, /**< EZR32 Leopard Device Family */
\r
89 #if defined( _DEVINFO_PART_DEVICE_FAMILY_EZR32HG )
\r
90 systemPartFamilyEzr32Happy = _DEVINFO_PART_DEVICE_FAMILY_EZR32HG, /**< EZR32 Happy Device Family */
\r
92 /* Legacy family #defines */
\r
93 #if defined( _DEVINFO_PART_DEVICE_FAMILY_G )
\r
94 systemPartFamilyGecko = _DEVINFO_PART_DEVICE_FAMILY_G, /**< Gecko Device Family */
\r
96 #if defined( _DEVINFO_PART_DEVICE_FAMILY_GG )
\r
97 systemPartFamilyGiant = _DEVINFO_PART_DEVICE_FAMILY_GG, /**< Giant Gecko Device Family */
\r
99 #if defined( _DEVINFO_PART_DEVICE_FAMILY_TG )
\r
100 systemPartFamilyTiny = _DEVINFO_PART_DEVICE_FAMILY_TG, /**< Tiny Gecko Device Family */
\r
102 #if defined( _DEVINFO_PART_DEVICE_FAMILY_LG )
\r
103 systemPartFamilyLeopard = _DEVINFO_PART_DEVICE_FAMILY_LG, /**< Leopard Gecko Device Family */
\r
105 #if defined( _DEVINFO_PART_DEVICE_FAMILY_WG )
\r
106 systemPartFamilyWonder = _DEVINFO_PART_DEVICE_FAMILY_WG, /**< Wonder Gecko Device Family */
\r
108 #if defined( _DEVINFO_PART_DEVICE_FAMILY_ZG )
\r
109 systemPartFamilyZero = _DEVINFO_PART_DEVICE_FAMILY_ZG, /**< Zero Gecko Device Family */
\r
111 #if defined( _DEVINFO_PART_DEVICE_FAMILY_HG )
\r
112 systemPartFamilyHappy = _DEVINFO_PART_DEVICE_FAMILY_HG, /**< Happy Gecko Device Family */
\r
114 systemPartFamilyUnknown = 0xFF /**< Unknown Device Family.
\r
115 The family id is missing
\r
116 on unprogrammed parts. */
\r
117 } SYSTEM_PartFamily_TypeDef;
\r
120 /*******************************************************************************
\r
121 ******************************* STRUCTS ***********************************
\r
122 ******************************************************************************/
\r
124 /** Chip revision details */
\r
127 uint8_t minor; /**< Minor revision number */
\r
128 uint8_t major; /**< Major revision number */
\r
129 uint8_t family;/**< Device family number */
\r
130 } SYSTEM_ChipRevision_TypeDef;
\r
132 #if defined( __FPU_PRESENT ) && ( __FPU_PRESENT == 1 )
\r
133 /** Floating point coprocessor access modes. */
\r
136 fpuAccessDenied = (0x0 << 20), /**< Access denied, any attempted access generates a NOCP UsageFault. */
\r
137 fpuAccessPrivilegedOnly = (0x5 << 20), /**< Privileged access only, an unprivileged access generates a NOCP UsageFault. */
\r
138 fpuAccessReserved = (0xA << 20), /**< Reserved. */
\r
139 fpuAccessFull = (0xF << 20) /**< Full access. */
\r
140 } SYSTEM_FpuAccess_TypeDef;
\r
143 /*******************************************************************************
\r
144 ***************************** PROTOTYPES **********************************
\r
145 ******************************************************************************/
\r
147 void SYSTEM_ChipRevisionGet(SYSTEM_ChipRevision_TypeDef *rev);
\r
148 uint32_t SYSTEM_GetCalibrationValue(volatile uint32_t *regAddress);
\r
150 #if defined( __FPU_PRESENT ) && ( __FPU_PRESENT == 1 )
\r
151 /***************************************************************************//**
\r
153 * Set floating point coprocessor (FPU) access mode.
\r
155 * @param[in] accessMode
\r
156 * Floating point coprocessor access mode. See @ref SYSTEM_FpuAccess_TypeDef
\r
158 ******************************************************************************/
\r
159 __STATIC_INLINE void SYSTEM_FpuAccessModeSet(SYSTEM_FpuAccess_TypeDef accessMode)
\r
161 SCB->CPACR = (SCB->CPACR & ~(0xF << 20)) | accessMode;
\r
165 /***************************************************************************//**
\r
167 * Get the unique number for this part.
\r
170 * Unique number for this part.
\r
171 ******************************************************************************/
\r
172 __STATIC_INLINE uint64_t SYSTEM_GetUnique(void)
\r
174 return ((uint64_t) ((uint64_t) DEVINFO->UNIQUEH << 32) | (uint64_t) DEVINFO->UNIQUEL);
\r
177 /***************************************************************************//**
\r
179 * Get the production revision for this part.
\r
182 * Production revision for this part.
\r
183 ******************************************************************************/
\r
184 __STATIC_INLINE uint8_t SYSTEM_GetProdRev(void)
\r
186 return ((DEVINFO->PART & _DEVINFO_PART_PROD_REV_MASK)
\r
187 >> _DEVINFO_PART_PROD_REV_SHIFT);
\r
190 /***************************************************************************//**
\r
192 * Get the SRAM size (in KB).
\r
195 * This function retrievs the correct value by reading the chip device
\r
196 * info structure. If your binary is made for one specific device only,
\r
197 * the \#define SRAM_SIZE can be used instead.
\r
200 * The size of the internal SRAM (in KB).
\r
201 ******************************************************************************/
\r
202 __STATIC_INLINE uint16_t SYSTEM_GetSRAMSize(void)
\r
204 #if defined(_EFM32_GECKO_FAMILY)
\r
205 /* Early Gecko devices had a bug where SRAM and Flash size were swapped. */
\r
206 if (SYSTEM_GetProdRev() < 5)
\r
208 return (DEVINFO->MSIZE & _DEVINFO_MSIZE_FLASH_MASK)
\r
209 >> _DEVINFO_MSIZE_FLASH_SHIFT;
\r
212 return (DEVINFO->MSIZE & _DEVINFO_MSIZE_SRAM_MASK)
\r
213 >> _DEVINFO_MSIZE_SRAM_SHIFT;
\r
216 /***************************************************************************//**
\r
218 * Get the flash size (in KB).
\r
221 * This function retrievs the correct value by reading the chip device
\r
222 * info structure. If your binary is made for one specific device only,
\r
223 * the \#define FLASH_SIZE can be used instead.
\r
226 * The size of the internal flash (in KB).
\r
227 ******************************************************************************/
\r
228 __STATIC_INLINE uint16_t SYSTEM_GetFlashSize(void)
\r
230 #if defined(_EFM32_GECKO_FAMILY)
\r
231 /* Early Gecko devices had a bug where SRAM and Flash size were swapped. */
\r
232 if (SYSTEM_GetProdRev() < 5)
\r
234 return (DEVINFO->MSIZE & _DEVINFO_MSIZE_SRAM_MASK)
\r
235 >> _DEVINFO_MSIZE_SRAM_SHIFT;
\r
238 return (DEVINFO->MSIZE & _DEVINFO_MSIZE_FLASH_MASK)
\r
239 >> _DEVINFO_MSIZE_FLASH_SHIFT;
\r
243 /***************************************************************************//**
\r
245 * Get the flash page size in bytes.
\r
248 * This function retrievs the correct value by reading the chip device
\r
249 * info structure. If your binary is made for one specific device only,
\r
250 * the \#define FLASH_PAGE_SIZE can be used instead.
\r
253 * The page size of the internal flash in bytes.
\r
254 ******************************************************************************/
\r
255 __STATIC_INLINE uint32_t SYSTEM_GetFlashPageSize(void)
\r
259 #if defined( _EFM32_GIANT_FAMILY )
\r
260 tmp = SYSTEM_GetProdRev();
\r
263 /* Early Giant/Leopard devices did not have MEMINFO in DEVINFO. */
\r
264 return FLASH_PAGE_SIZE;
\r
266 #elif defined( _EFM32_ZERO_FAMILY )
\r
267 tmp = SYSTEM_GetProdRev();
\r
270 /* Early Zero devices have an incorrect DEVINFO flash page size */
\r
271 return FLASH_PAGE_SIZE;
\r
274 tmp = (DEVINFO->MEMINFO & _DEVINFO_MEMINFO_FLASH_PAGE_SIZE_MASK)
\r
275 >> _DEVINFO_MEMINFO_FLASH_PAGE_SIZE_SHIFT;
\r
277 return 1 << ((tmp + 10) & 0xFF);
\r
281 /***************************************************************************//**
\r
283 * Get part number of the MCU.
\r
286 * The part number of the MCU.
\r
287 ******************************************************************************/
\r
288 __STATIC_INLINE uint16_t SYSTEM_GetPartNumber(void)
\r
290 return (DEVINFO->PART & _DEVINFO_PART_DEVICE_NUMBER_MASK)
\r
291 >> _DEVINFO_PART_DEVICE_NUMBER_SHIFT;
\r
294 /***************************************************************************//**
\r
296 * Get family identifier of the MCU.
\r
299 * This function retrievs the family id by reading the chip's device info
\r
300 * structure in flash memory. The user can retrieve the family id directly
\r
301 * by reading the DEVINFO->PART item and decode with the mask and shift
\r
302 * \#defines defined in \<part_family\>_devinfo.h (please refer to code
\r
303 * below for details).
\r
306 * The family identifier of the MCU.
\r
307 ******************************************************************************/
\r
308 __STATIC_INLINE SYSTEM_PartFamily_TypeDef SYSTEM_GetFamily(void)
\r
310 return (SYSTEM_PartFamily_TypeDef)
\r
311 ((DEVINFO->PART & _DEVINFO_PART_DEVICE_FAMILY_MASK)
\r
312 >> _DEVINFO_PART_DEVICE_FAMILY_SHIFT);
\r
316 /***************************************************************************//**
\r
318 * Get the calibration temperature (in degrees Celsius).
\r
321 * The calibration temperature in Celsius.
\r
322 ******************************************************************************/
\r
323 __STATIC_INLINE uint8_t SYSTEM_GetCalibrationTemperature(void)
\r
325 return (DEVINFO->CAL & _DEVINFO_CAL_TEMP_MASK)
\r
326 >> _DEVINFO_CAL_TEMP_SHIFT;
\r
329 /** @} (end addtogroup SYSTEM) */
\r
330 /** @} (end addtogroup EM_Library) */
\r
336 #endif /* __SILICON_LABS_EM_SYSTEM_H_ */
\r