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