fsl_sim.h 4.7 KB

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