1 /***************************************************************************//**
2 * @file
3 * @brief System Peripheral API
4 * @author Energy Micro AS
5 * @version 3.0.0
6 *******************************************************************************
7 * @section License
8 * <b>(C) Copyright 2012 Energy Micro AS, http://www.energymicro.com</b>
9 *******************************************************************************
10 *
11 * Permission is granted to anyone to use this software for any purpose,
12 * including commercial applications, and to alter it and redistribute it
13 * freely, subject to the following restrictions:
14 *
15 * 1. The origin of this software must not be misrepresented; you must not
16 * claim that you wrote the original software.
17 * 2. Altered source versions must be plainly marked as such, and must not be
18 * misrepresented as being the original software.
19 * 3. This notice may not be removed or altered from any source distribution.
20 *
21 * DISCLAIMER OF WARRANTY/LIMITATION OF REMEDIES: Energy Micro AS has no
22 * obligation to support this Software. Energy Micro AS is providing the
23 * Software "AS IS", with no express or implied warranties of any kind,
24 * including, but not limited to, any implied warranties of merchantability
25 * or fitness for any particular purpose or warranties against infringement
26 * of any proprietary rights of a third party.
27 *
28 * Energy Micro AS will not be liable for any consequential, incidental, or
29 * special damages, or any other relief, or for any claim by any third party,
30 * arising from your use of this Software.
31 *
32 ******************************************************************************/
33 #include "em_part.h"
34 #include "em_system.h"
35 #include "em_assert.h"
36
37 /***************************************************************************//**
38 * @addtogroup EM_Library
39 * @{
40 ******************************************************************************/
41
42 /***************************************************************************//**
43 * @addtogroup SYSTEM
44 * @brief System Peripheral API
45 * @{
46 ******************************************************************************/
47
48 /*******************************************************************************
49 ************************** GLOBAL FUNCTIONS *******************************
50 ******************************************************************************/
51
52 /***************************************************************************//**
53 * @brief
54 * Get chip major/minor revision.
55 *
56 * @param[out] rev
57 * Location to place chip revision info.
58 ******************************************************************************/
SYSTEM_ChipRevisionGet(SYSTEM_ChipRevision_TypeDef * rev)59 void SYSTEM_ChipRevisionGet(SYSTEM_ChipRevision_TypeDef *rev)
60 {
61 uint8_t tmp;
62
63 EFM_ASSERT(rev);
64
65 rev->major = (ROMTABLE->PID0 & _ROMTABLE_PID0_REVMAJOR_MASK) >> _ROMTABLE_PID0_REVMAJOR_SHIFT;
66
67 tmp = (ROMTABLE->PID2 & _ROMTABLE_PID2_REVMINORMSB_MASK);
68 tmp |= ((ROMTABLE->PID3 & _ROMTABLE_PID3_REVMINORLSB_MASK) >> _ROMTABLE_PID3_REVMINORLSB_SHIFT);
69 rev->minor = tmp;
70 }
71
72 /***************************************************************************//**
73 * @brief
74 * Get factory calibration value for a given peripheral register.
75 *
76 * @param[in] regAddress
77 * Address of register to get a calibration value for.
78 *
79 * @return
80 * Calibration value for the requested register.
81 ******************************************************************************/
SYSTEM_GetCalibrationValue(volatile uint32_t * regAddress)82 uint32_t SYSTEM_GetCalibrationValue(volatile uint32_t *regAddress)
83 {
84 int regCount;
85 CALIBRATE_TypeDef *p;
86
87 regCount = 1;
88 p = CALIBRATE;
89
90 for (;; )
91 {
92 if ((regCount > CALIBRATE_MAX_REGISTERS) ||
93 (p->VALUE == 0xFFFFFFFF))
94 {
95 EFM_ASSERT(false);
96 return 0; /* End of device calibration table reached. */
97 }
98
99 if (p->ADDRESS == (uint32_t)regAddress)
100 {
101 return p->VALUE; /* Calibration value found ! */
102 }
103
104 p++;
105 regCount++;
106 }
107 }
108
109 /** @} (end addtogroup SYSTEM) */
110 /** @} (end addtogroup EM_Library) */
111