]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/CORTEX_EFM32_Gecko_Starter_Kit_Simplicity_Studio/Source/SilLabs_Code/emlib/em_system.c
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 / em_system.c
1 /***************************************************************************//**\r
2  * @file em_system.c\r
3  * @brief System Peripheral 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 #include "em_system.h"\r
35 #include "em_assert.h"\r
36 \r
37 /***************************************************************************//**\r
38  * @addtogroup EM_Library\r
39  * @{\r
40  ******************************************************************************/\r
41 \r
42 /***************************************************************************//**\r
43  * @addtogroup SYSTEM\r
44  * @brief System Peripheral API\r
45  * @{\r
46  ******************************************************************************/\r
47 \r
48 /*******************************************************************************\r
49  **************************   GLOBAL FUNCTIONS   *******************************\r
50  ******************************************************************************/\r
51 \r
52 /***************************************************************************//**\r
53  * @brief\r
54  *   Get chip major/minor revision.\r
55  *\r
56  * @param[out] rev\r
57  *   Location to place chip revision info.\r
58  ******************************************************************************/\r
59 void SYSTEM_ChipRevisionGet(SYSTEM_ChipRevision_TypeDef *rev)\r
60 {\r
61   uint8_t tmp;\r
62 \r
63   EFM_ASSERT(rev);  \r
64   \r
65   /* CHIP FAMILY bit [5:2] */\r
66   tmp  = (((ROMTABLE->PID1 & _ROMTABLE_PID1_FAMILYMSB_MASK) >> _ROMTABLE_PID1_FAMILYMSB_SHIFT) << 2);           \r
67   /* CHIP FAMILY bit [1:0] */\r
68   tmp |=  ((ROMTABLE->PID0 & _ROMTABLE_PID0_FAMILYLSB_MASK) >> _ROMTABLE_PID0_FAMILYLSB_SHIFT);                 \r
69   rev->family = tmp;\r
70 \r
71   /* CHIP MAJOR bit [3:0] */\r
72   rev->major = (ROMTABLE->PID0 & _ROMTABLE_PID0_REVMAJOR_MASK) >> _ROMTABLE_PID0_REVMAJOR_SHIFT;                \r
73 \r
74   /* CHIP MINOR bit [7:4] */\r
75   tmp  = (((ROMTABLE->PID2 & _ROMTABLE_PID2_REVMINORMSB_MASK) >> _ROMTABLE_PID2_REVMINORMSB_SHIFT) << 4);  \r
76   /* CHIP MINOR bit [3:0] */\r
77   tmp |=  ((ROMTABLE->PID3 & _ROMTABLE_PID3_REVMINORLSB_MASK) >> _ROMTABLE_PID3_REVMINORLSB_SHIFT);             \r
78   rev->minor = tmp;\r
79 }\r
80 \r
81 /***************************************************************************//**\r
82  * @brief\r
83  *    Get factory calibration value for a given peripheral register.\r
84  *\r
85  * @param[in] regAddress\r
86  *    Address of register to get a calibration value for.\r
87  *\r
88  * @return\r
89  *    Calibration value for the requested register.\r
90  ******************************************************************************/\r
91 uint32_t SYSTEM_GetCalibrationValue(volatile uint32_t *regAddress)\r
92 {\r
93   int               regCount;\r
94   CALIBRATE_TypeDef *p;\r
95 \r
96   regCount = 1;\r
97   p        = CALIBRATE;\r
98 \r
99   for (;; )\r
100   {\r
101     if ((regCount > CALIBRATE_MAX_REGISTERS) ||\r
102         (p->VALUE == 0xFFFFFFFF))\r
103     {\r
104       EFM_ASSERT(false);\r
105       return 0;                 /* End of device calibration table reached. */\r
106     }\r
107 \r
108     if (p->ADDRESS == (uint32_t)regAddress)\r
109     {\r
110       return p->VALUE;          /* Calibration value found ! */\r
111     }\r
112 \r
113     p++;\r
114     regCount++;\r
115   }\r
116 }\r
117 \r
118 /** @} (end addtogroup SYSTEM) */\r
119 /** @} (end addtogroup EM_Library) */\r