]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/CORTEX_EFM32_Gecko_Starter_Kit_Simplicity_Studio/Source/SilLabs_Code/emlib/inc/em_system.h
Add EFM32 Giant Gecko Starter Kit demo - still a work in progress as the low power...
[freertos] / FreeRTOS / Demo / CORTEX_EFM32_Gecko_Starter_Kit_Simplicity_Studio / Source / SilLabs_Code / emlib / inc / em_system.h
1 /***************************************************************************//**\r
2  * @file em_system.h\r
3  * @brief System API\r
4  * @version 4.0.0\r
5  *******************************************************************************\r
6  * @section License\r
7  * <b>(C) Copyright 2014 Silicon Labs, http://www.silabs.com</b>\r
8  *******************************************************************************\r
9  *\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
13  *\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
19  *\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
26  *\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
30  *\r
31  ******************************************************************************/\r
32 \r
33 \r
34 #ifndef __SILICON_LABS_EM_SYSTEM_H_\r
35 #define __SILICON_LABS_EM_SYSTEM_H_\r
36 \r
37 #include <stdbool.h>\r
38 #include "em_device.h"\r
39 \r
40 #ifdef __cplusplus\r
41 extern "C" {\r
42 #endif\r
43 \r
44 /***************************************************************************//**\r
45  * @addtogroup EM_Library\r
46  * @{\r
47  ******************************************************************************/\r
48 \r
49 /***************************************************************************//**\r
50  * @addtogroup SYSTEM\r
51  * @{\r
52  ******************************************************************************/\r
53 \r
54 /*******************************************************************************\r
55  ********************************   ENUMS   ************************************\r
56  ******************************************************************************/\r
57 \r
58 /** EFM32 part family identifiers. */\r
59 typedef enum\r
60 {\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
64 #endif\r
65 #if defined ( _DEVINFO_PART_DEVICE_FAMILY_EFM32GG )\r
66   systemPartFamilyEfm32Giant   = _DEVINFO_PART_DEVICE_FAMILY_EFM32GG,  /**< EFM32 Giant Gecko Device Family */\r
67 #endif\r
68 #if defined( _DEVINFO_PART_DEVICE_FAMILY_EFM32TG )\r
69   systemPartFamilyEfm32Tiny    = _DEVINFO_PART_DEVICE_FAMILY_EFM32TG,  /**< EFM32 Tiny Gecko Device Family */\r
70 #endif\r
71 #if defined( _DEVINFO_PART_DEVICE_FAMILY_EFM32LG )\r
72   systemPartFamilyEfm32Leopard = _DEVINFO_PART_DEVICE_FAMILY_EFM32LG,  /**< EFM32 Leopard Gecko Device Family */\r
73 #endif\r
74 #if defined( _DEVINFO_PART_DEVICE_FAMILY_EFM32WG )\r
75   systemPartFamilyEfm32Wonder  = _DEVINFO_PART_DEVICE_FAMILY_EFM32WG,  /**< EFM32 Wonder Gecko Device Family */\r
76 #endif\r
77 #if defined( _DEVINFO_PART_DEVICE_FAMILY_EFM32ZG )\r
78   systemPartFamilyEfm32Zero    = _DEVINFO_PART_DEVICE_FAMILY_EFM32ZG,  /**< EFM32 Zero Gecko Device Family */\r
79 #endif\r
80 #if defined( _DEVINFO_PART_DEVICE_FAMILY_EFM32HG )\r
81   systemPartFamilyEfm32Happy   = _DEVINFO_PART_DEVICE_FAMILY_EFM32HG,  /**< EFM32 Happy Gecko Device Family */\r
82 #endif\r
83 #if defined( _DEVINFO_PART_DEVICE_FAMILY_EZR32WG )\r
84   systemPartFamilyEzr32Wonder  = _DEVINFO_PART_DEVICE_FAMILY_EZR32WG,  /**< EZR32 Wonder Device Family */\r
85 #endif\r
86 #if defined( _DEVINFO_PART_DEVICE_FAMILY_EZR32LG )\r
87   systemPartFamilyEzr32Leopard = _DEVINFO_PART_DEVICE_FAMILY_EZR32LG,  /**< EZR32 Leopard Device Family */\r
88 #endif\r
89 #if defined( _DEVINFO_PART_DEVICE_FAMILY_EZR32HG )\r
90   systemPartFamilyEzr32Happy   = _DEVINFO_PART_DEVICE_FAMILY_EZR32HG,  /**< EZR32 Happy Device Family */\r
91 #endif\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
95 #endif\r
96 #if defined( _DEVINFO_PART_DEVICE_FAMILY_GG )\r
97   systemPartFamilyGiant   = _DEVINFO_PART_DEVICE_FAMILY_GG,  /**< Giant Gecko Device Family */\r
98 #endif\r
99 #if defined( _DEVINFO_PART_DEVICE_FAMILY_TG )\r
100   systemPartFamilyTiny    = _DEVINFO_PART_DEVICE_FAMILY_TG,  /**< Tiny Gecko Device Family */\r
101 #endif\r
102 #if defined( _DEVINFO_PART_DEVICE_FAMILY_LG )\r
103   systemPartFamilyLeopard = _DEVINFO_PART_DEVICE_FAMILY_LG,  /**< Leopard Gecko Device Family */\r
104 #endif\r
105 #if defined( _DEVINFO_PART_DEVICE_FAMILY_WG )\r
106   systemPartFamilyWonder  = _DEVINFO_PART_DEVICE_FAMILY_WG,  /**< Wonder Gecko Device Family */\r
107 #endif\r
108 #if defined( _DEVINFO_PART_DEVICE_FAMILY_ZG )\r
109   systemPartFamilyZero    = _DEVINFO_PART_DEVICE_FAMILY_ZG,  /**< Zero Gecko Device Family */\r
110 #endif\r
111 #if defined( _DEVINFO_PART_DEVICE_FAMILY_HG )\r
112   systemPartFamilyHappy   = _DEVINFO_PART_DEVICE_FAMILY_HG,  /**< Happy Gecko Device Family */\r
113 #endif\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
118 \r
119 \r
120 /*******************************************************************************\r
121  *******************************   STRUCTS   ***********************************\r
122  ******************************************************************************/\r
123 \r
124 /** Chip revision details */\r
125 typedef struct\r
126 {\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
131 \r
132 #if defined( __FPU_PRESENT ) && ( __FPU_PRESENT == 1 )\r
133 /** Floating point coprocessor access modes. */\r
134 typedef enum\r
135 {\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
141 #endif\r
142 \r
143 /*******************************************************************************\r
144  *****************************   PROTOTYPES   **********************************\r
145  ******************************************************************************/\r
146 \r
147 void     SYSTEM_ChipRevisionGet(SYSTEM_ChipRevision_TypeDef *rev);\r
148 uint32_t SYSTEM_GetCalibrationValue(volatile uint32_t *regAddress);\r
149 \r
150 #if defined( __FPU_PRESENT ) && ( __FPU_PRESENT == 1 )\r
151 /***************************************************************************//**\r
152  * @brief\r
153  *   Set floating point coprocessor (FPU) access mode.\r
154  *\r
155  * @param[in] accessMode\r
156  *   Floating point coprocessor access mode. See @ref SYSTEM_FpuAccess_TypeDef\r
157  *   for details.\r
158  ******************************************************************************/\r
159 __STATIC_INLINE void SYSTEM_FpuAccessModeSet(SYSTEM_FpuAccess_TypeDef accessMode)\r
160 {\r
161   SCB->CPACR = (SCB->CPACR & ~(0xF << 20)) | accessMode;\r
162 }\r
163 #endif\r
164 \r
165 /***************************************************************************//**\r
166  * @brief\r
167  *   Get the unique number for this part.\r
168  *\r
169  * @return\r
170  *   Unique number for this part.\r
171  ******************************************************************************/\r
172 __STATIC_INLINE uint64_t SYSTEM_GetUnique(void)\r
173 {\r
174   return ((uint64_t) ((uint64_t) DEVINFO->UNIQUEH << 32) | (uint64_t) DEVINFO->UNIQUEL);\r
175 }\r
176 \r
177 /***************************************************************************//**\r
178  * @brief\r
179  *   Get the production revision for this part.\r
180  *\r
181  * @return\r
182  *   Production revision for this part.\r
183  ******************************************************************************/\r
184 __STATIC_INLINE uint8_t SYSTEM_GetProdRev(void)\r
185 {\r
186   return ((DEVINFO->PART & _DEVINFO_PART_PROD_REV_MASK)\r
187                          >> _DEVINFO_PART_PROD_REV_SHIFT);\r
188 }\r
189 \r
190 /***************************************************************************//**\r
191  * @brief\r
192  *   Get the SRAM size (in KB).\r
193  *\r
194  * @note\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
198  *\r
199  * @return\r
200  *   The size of the internal SRAM (in KB).\r
201  ******************************************************************************/\r
202 __STATIC_INLINE uint16_t SYSTEM_GetSRAMSize(void)\r
203 {\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
207   {\r
208     return (DEVINFO->MSIZE & _DEVINFO_MSIZE_FLASH_MASK)\r
209                            >> _DEVINFO_MSIZE_FLASH_SHIFT;\r
210   }\r
211 #endif\r
212   return (DEVINFO->MSIZE & _DEVINFO_MSIZE_SRAM_MASK)\r
213                          >> _DEVINFO_MSIZE_SRAM_SHIFT;\r
214 }\r
215 \r
216 /***************************************************************************//**\r
217  * @brief\r
218  *   Get the flash size (in KB).\r
219  *\r
220  * @note\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
224  *\r
225  * @return\r
226  *   The size of the internal flash (in KB).\r
227  ******************************************************************************/\r
228 __STATIC_INLINE uint16_t SYSTEM_GetFlashSize(void)\r
229 {\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
233   {\r
234     return (DEVINFO->MSIZE & _DEVINFO_MSIZE_SRAM_MASK)\r
235                            >> _DEVINFO_MSIZE_SRAM_SHIFT;\r
236   }\r
237 #endif\r
238   return (DEVINFO->MSIZE & _DEVINFO_MSIZE_FLASH_MASK)\r
239                          >> _DEVINFO_MSIZE_FLASH_SHIFT;\r
240 }\r
241 \r
242 \r
243 /***************************************************************************//**\r
244  * @brief\r
245  *   Get the flash page size in bytes.\r
246  *\r
247  * @note\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
251  *\r
252  * @return\r
253  *   The page size of the internal flash in bytes.\r
254  ******************************************************************************/\r
255 __STATIC_INLINE uint32_t SYSTEM_GetFlashPageSize(void)\r
256 {\r
257   uint32_t tmp;\r
258 \r
259 #if defined( _EFM32_GIANT_FAMILY )\r
260   tmp = SYSTEM_GetProdRev();\r
261   if (tmp < 18)\r
262   {\r
263     /* Early Giant/Leopard devices did not have MEMINFO in DEVINFO. */\r
264     return FLASH_PAGE_SIZE;\r
265   }\r
266 #elif defined( _EFM32_ZERO_FAMILY )\r
267   tmp = SYSTEM_GetProdRev();\r
268   if (tmp < 24)\r
269   {\r
270     /* Early Zero devices have an incorrect DEVINFO flash page size */\r
271     return FLASH_PAGE_SIZE;\r
272   }\r
273 #endif\r
274   tmp = (DEVINFO->MEMINFO & _DEVINFO_MEMINFO_FLASH_PAGE_SIZE_MASK)\r
275                  >> _DEVINFO_MEMINFO_FLASH_PAGE_SIZE_SHIFT;\r
276 \r
277   return 1 << ((tmp + 10) & 0xFF);\r
278 }\r
279 \r
280 \r
281 /***************************************************************************//**\r
282  * @brief\r
283  *   Get part number of the MCU.\r
284  *\r
285  * @return\r
286  *   The part number of the MCU.\r
287  ******************************************************************************/\r
288 __STATIC_INLINE uint16_t SYSTEM_GetPartNumber(void)\r
289 {\r
290   return (DEVINFO->PART & _DEVINFO_PART_DEVICE_NUMBER_MASK)\r
291                         >> _DEVINFO_PART_DEVICE_NUMBER_SHIFT;\r
292 }\r
293 \r
294 /***************************************************************************//**\r
295  * @brief\r
296  *   Get family identifier of the MCU.\r
297  *\r
298  * @note\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
304  *\r
305  * @return\r
306  *   The family identifier of the MCU.\r
307  ******************************************************************************/\r
308 __STATIC_INLINE SYSTEM_PartFamily_TypeDef SYSTEM_GetFamily(void)\r
309 {\r
310   return (SYSTEM_PartFamily_TypeDef)\r
311     ((DEVINFO->PART & _DEVINFO_PART_DEVICE_FAMILY_MASK)\r
312      >> _DEVINFO_PART_DEVICE_FAMILY_SHIFT);\r
313 }\r
314 \r
315 \r
316 /***************************************************************************//**\r
317  * @brief\r
318  *   Get the calibration temperature (in degrees Celsius).\r
319  *\r
320  * @return\r
321  *   The calibration temperature in Celsius.\r
322  ******************************************************************************/\r
323 __STATIC_INLINE uint8_t SYSTEM_GetCalibrationTemperature(void)\r
324 {\r
325   return (DEVINFO->CAL & _DEVINFO_CAL_TEMP_MASK)\r
326                        >> _DEVINFO_CAL_TEMP_SHIFT;\r
327 }\r
328 \r
329 /** @} (end addtogroup SYSTEM) */\r
330 /** @} (end addtogroup EM_Library) */\r
331 \r
332 #ifdef __cplusplus\r
333 }\r
334 #endif\r
335 \r
336 #endif /* __SILICON_LABS_EM_SYSTEM_H_ */\r