em_system.c 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  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. * @addtogroup EM_Library
  38. * @{
  39. ******************************************************************************/
  40. /***************************************************************************//**
  41. * @addtogroup SYSTEM
  42. * @brief System Peripheral API
  43. * @{
  44. ******************************************************************************/
  45. /*******************************************************************************
  46. ************************** GLOBAL FUNCTIONS *******************************
  47. ******************************************************************************/
  48. /***************************************************************************//**
  49. * @brief
  50. * Get chip major/minor revision.
  51. *
  52. * @param[out] rev
  53. * Location to place chip revision info.
  54. ******************************************************************************/
  55. void SYSTEM_ChipRevisionGet(SYSTEM_ChipRevision_TypeDef *rev)
  56. {
  57. uint8_t tmp;
  58. EFM_ASSERT(rev);
  59. rev->major = (ROMTABLE->PID0 & _ROMTABLE_PID0_REVMAJOR_MASK) >> _ROMTABLE_PID0_REVMAJOR_SHIFT;
  60. tmp = (ROMTABLE->PID2 & _ROMTABLE_PID2_REVMINORMSB_MASK);
  61. tmp |= ((ROMTABLE->PID3 & _ROMTABLE_PID3_REVMINORLSB_MASK) >> _ROMTABLE_PID3_REVMINORLSB_SHIFT);
  62. rev->minor = tmp;
  63. }
  64. /***************************************************************************//**
  65. * @brief
  66. * Get factory calibration value for a given peripheral register.
  67. *
  68. * @param[in] regAddress
  69. * Address of register to get a calibration value for.
  70. *
  71. * @return
  72. * Calibration value for the requested register.
  73. ******************************************************************************/
  74. uint32_t SYSTEM_GetCalibrationValue(volatile uint32_t *regAddress)
  75. {
  76. int regCount;
  77. CALIBRATE_TypeDef *p;
  78. regCount = 1;
  79. p = CALIBRATE;
  80. for (;; )
  81. {
  82. if ((regCount > CALIBRATE_MAX_REGISTERS) ||
  83. (p->VALUE == 0xFFFFFFFF))
  84. {
  85. EFM_ASSERT(false);
  86. return 0; /* End of device calibration table reached. */
  87. }
  88. if (p->ADDRESS == (uint32_t)regAddress)
  89. {
  90. return p->VALUE; /* Calibration value found ! */
  91. }
  92. p++;
  93. regCount++;
  94. }
  95. }
  96. /** @} (end addtogroup SYSTEM) */
  97. /** @} (end addtogroup EM_Library) */