fsl_sim.h 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. /*
  2. * The Clear BSD License
  3. * Copyright (c) 2015, Freescale Semiconductor, Inc.
  4. * Copyright 2016-2017 NXP
  5. * All rights reserved.
  6. *
  7. * Redistribution and use in source and binary forms, with or without modification,
  8. * are permitted (subject to the limitations in the disclaimer below) provided
  9. * that the following conditions are met:
  10. *
  11. * o Redistributions of source code must retain the above copyright notice, this list
  12. * of conditions and the following disclaimer.
  13. *
  14. * o Redistributions in binary form must reproduce the above copyright notice, this
  15. * list of conditions and the following disclaimer in the documentation and/or
  16. * other materials provided with the distribution.
  17. *
  18. * o Neither the name of the copyright holder nor the names of its
  19. * contributors may be used to endorse or promote products derived from this
  20. * software without specific prior written permission.
  21. *
  22. * NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED BY THIS LICENSE.
  23. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
  24. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  25. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  26. * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
  27. * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  28. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  29. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
  30. * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  31. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  32. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  33. */
  34. #ifndef _FSL_SIM_H_
  35. #define _FSL_SIM_H_
  36. #include "fsl_common.h"
  37. /*! @addtogroup sim */
  38. /*! @{*/
  39. /*******************************************************************************
  40. * Definitions
  41. *******************************************************************************/
  42. /*! @name Driver version */
  43. /*@{*/
  44. #define FSL_SIM_DRIVER_VERSION (MAKE_VERSION(2, 1, 0)) /*!< Driver version 2.0.0 */
  45. /*@}*/
  46. #if (defined(FSL_FEATURE_SIM_OPT_HAS_USB_VOLTAGE_REGULATOR) && FSL_FEATURE_SIM_OPT_HAS_USB_VOLTAGE_REGULATOR)
  47. /*!@brief USB voltage regulator enable setting. */
  48. enum _sim_usb_volt_reg_enable_mode
  49. {
  50. kSIM_UsbVoltRegEnable = SIM_SOPT1_USBREGEN_MASK, /*!< Enable voltage regulator. */
  51. kSIM_UsbVoltRegEnableInLowPower = SIM_SOPT1_USBVSTBY_MASK, /*!< Enable voltage regulator in VLPR/VLPW modes. */
  52. kSIM_UsbVoltRegEnableInStop = SIM_SOPT1_USBSSTBY_MASK, /*!< Enable voltage regulator in STOP/VLPS/LLS/VLLS modes. */
  53. kSIM_UsbVoltRegEnableInAllModes = SIM_SOPT1_USBREGEN_MASK | SIM_SOPT1_USBSSTBY_MASK |
  54. SIM_SOPT1_USBVSTBY_MASK /*!< Enable voltage regulator in all power modes. */
  55. };
  56. #endif /* (defined(FSL_FEATURE_SIM_OPT_HAS_USB_VOLTAGE_REGULATOR) && FSL_FEATURE_SIM_OPT_HAS_USB_VOLTAGE_REGULATOR) */
  57. /*!@brief Unique ID. */
  58. typedef struct _sim_uid
  59. {
  60. #if defined(SIM_UIDH)
  61. uint32_t H; /*!< UIDH. */
  62. #endif
  63. #if (defined(FSL_FEATURE_SIM_HAS_UIDM) && FSL_FEATURE_SIM_HAS_UIDM)
  64. uint32_t M; /*!< SIM_UIDM. */
  65. #else
  66. uint32_t MH; /*!< UIDMH. */
  67. uint32_t ML; /*!< UIDML. */
  68. #endif /* FSL_FEATURE_SIM_HAS_UIDM */
  69. uint32_t L; /*!< UIDL. */
  70. } sim_uid_t;
  71. #if (defined(FSL_FEATURE_SIM_HAS_RF_MAC_ADDR) && FSL_FEATURE_SIM_HAS_RF_MAC_ADDR)
  72. /*! @brief RF Mac Address.*/
  73. typedef struct _sim_rf_addr
  74. {
  75. uint32_t rfAddrL; /*!< RFADDRL. */
  76. uint32_t rfAddrH; /*!< RFADDRH. */
  77. } sim_rf_addr_t;
  78. #endif /* FSL_FEATURE_SIM_HAS_RF_MAC_ADDR */
  79. /*!@brief Flash enable mode. */
  80. enum _sim_flash_mode
  81. {
  82. kSIM_FlashDisableInWait = SIM_FCFG1_FLASHDOZE_MASK, /*!< Disable flash in wait mode. */
  83. kSIM_FlashDisable = SIM_FCFG1_FLASHDIS_MASK /*!< Disable flash in normal mode. */
  84. };
  85. /*******************************************************************************
  86. * API
  87. ******************************************************************************/
  88. #if defined(__cplusplus)
  89. extern "C" {
  90. #endif /* __cplusplus*/
  91. #if (defined(FSL_FEATURE_SIM_OPT_HAS_USB_VOLTAGE_REGULATOR) && FSL_FEATURE_SIM_OPT_HAS_USB_VOLTAGE_REGULATOR)
  92. /*!
  93. * @brief Sets the USB voltage regulator setting.
  94. *
  95. * This function configures whether the USB voltage regulator is enabled in
  96. * normal RUN mode, STOP/VLPS/LLS/VLLS modes, and VLPR/VLPW modes. The configurations
  97. * are passed in as mask value of \ref _sim_usb_volt_reg_enable_mode. For example, to enable
  98. * USB voltage regulator in RUN/VLPR/VLPW modes and disable in STOP/VLPS/LLS/VLLS mode,
  99. * use:
  100. *
  101. * SIM_SetUsbVoltRegulatorEnableMode(kSIM_UsbVoltRegEnable | kSIM_UsbVoltRegEnableInLowPower);
  102. *
  103. * @param mask USB voltage regulator enable setting.
  104. */
  105. void SIM_SetUsbVoltRegulatorEnableMode(uint32_t mask);
  106. #endif /* FSL_FEATURE_SIM_OPT_HAS_USB_VOLTAGE_REGULATOR */
  107. /*!
  108. * @brief Gets the unique identification register value.
  109. *
  110. * @param uid Pointer to the structure to save the UID value.
  111. */
  112. void SIM_GetUniqueId(sim_uid_t *uid);
  113. /*!
  114. * @brief Sets the flash enable mode.
  115. *
  116. * @param mode The mode to set; see \ref _sim_flash_mode for mode details.
  117. */
  118. static inline void SIM_SetFlashMode(uint8_t mode)
  119. {
  120. SIM->FCFG1 = mode;
  121. }
  122. #if (defined(FSL_FEATURE_SIM_HAS_RF_MAC_ADDR) && FSL_FEATURE_SIM_HAS_RF_MAC_ADDR)
  123. /*!
  124. * @brief Gets the RF address register value.
  125. *
  126. * @param info Pointer to the structure to save the RF address value.
  127. */
  128. void SIM_GetRfAddr(sim_rf_addr_t *info);
  129. #endif /* FSL_FEATURE_SIM_HAS_RF_MAC_ADDR */
  130. #if (defined(FSL_FEATURE_SIM_MISC2_HAS_SYSTICK_CLK_EN) && FSL_FEATURE_SIM_MISC2_HAS_SYSTICK_CLK_EN)
  131. /*!
  132. * @brief Enable the Systick clock or not.
  133. *
  134. * The Systick clock is enabled by default.
  135. *
  136. * @param enable The switcher for Systick clock.
  137. */
  138. static inline void SIM_EnableSystickClock(bool enable)
  139. {
  140. if (enable)
  141. {
  142. SIM->MISC2 &= ~SIM_MISC2_SYSTICK_CLK_EN_MASK; /* Clear to enable. */
  143. }
  144. else
  145. {
  146. SIM->MISC2 |= SIM_MISC2_SYSTICK_CLK_EN_MASK; /* Set to disable. */
  147. }
  148. }
  149. #endif /* FSL_FEATURE_SIM_MISC2_HAS_SYSTICK_CLK_EN */
  150. #if defined(__cplusplus)
  151. }
  152. #endif /* __cplusplus*/
  153. /*! @}*/
  154. #endif /* _FSL_SIM_H_ */