1 /*
2 * Copyright (c) 2015, Freescale Semiconductor, Inc.
3 * Copyright 2016-2021 NXP
4 * All rights reserved.
5 *
6 * SPDX-License-Identifier: BSD-3-Clause
7 */
8
9 #ifndef _FSL_SIM_H_
10 #define _FSL_SIM_H_
11
12 #include "fsl_common.h"
13
14 /*! @addtogroup sim */
15 /*! @{*/
16
17 /*******************************************************************************
18 * Definitions
19 *******************************************************************************/
20
21 /*! @name Driver version */
22 /*@{*/
23 #define FSL_SIM_DRIVER_VERSION (MAKE_VERSION(2, 1, 3))
24 /*@}*/
25
26 #if (defined(FSL_FEATURE_SIM_OPT_HAS_USB_VOLTAGE_REGULATOR) && FSL_FEATURE_SIM_OPT_HAS_USB_VOLTAGE_REGULATOR)
27 /*!@brief USB voltage regulator enable setting. */
28 enum _sim_usb_volt_reg_enable_mode
29 {
30 kSIM_UsbVoltRegEnable = (int)SIM_SOPT1_USBREGEN_MASK, /*!< Enable voltage regulator. */
31 kSIM_UsbVoltRegEnableInLowPower = SIM_SOPT1_USBVSTBY_MASK, /*!< Enable voltage regulator in VLPR/VLPW modes. */
32 kSIM_UsbVoltRegEnableInStop = SIM_SOPT1_USBSSTBY_MASK, /*!< Enable voltage regulator in STOP/VLPS/LLS/VLLS modes. */
33 kSIM_UsbVoltRegEnableInAllModes =
34 (int)(SIM_SOPT1_USBREGEN_MASK | SIM_SOPT1_USBSSTBY_MASK |
35 SIM_SOPT1_USBVSTBY_MASK) /*!< Enable voltage regulator in all power modes. */
36 };
37 #endif /* (defined(FSL_FEATURE_SIM_OPT_HAS_USB_VOLTAGE_REGULATOR) && FSL_FEATURE_SIM_OPT_HAS_USB_VOLTAGE_REGULATOR) */
38
39 /*!@brief Unique ID. */
40 typedef struct _sim_uid
41 {
42 #if (defined(FSL_FEATURE_SIM_HAS_UIDH) && FSL_FEATURE_SIM_HAS_UIDH)
43 uint32_t H; /*!< UIDH. */
44 #endif
45
46 #if (defined(FSL_FEATURE_SIM_HAS_UIDM) && FSL_FEATURE_SIM_HAS_UIDM)
47 uint32_t M; /*!< SIM_UIDM. */
48 #else
49 uint32_t MH; /*!< UIDMH. */
50 uint32_t ML; /*!< UIDML. */
51 #endif /* FSL_FEATURE_SIM_HAS_UIDM */
52 uint32_t L; /*!< UIDL. */
53 } sim_uid_t;
54
55 #if (defined(FSL_FEATURE_SIM_HAS_RF_MAC_ADDR) && FSL_FEATURE_SIM_HAS_RF_MAC_ADDR)
56 /*! @brief RF Mac Address.*/
57 typedef struct _sim_rf_addr
58 {
59 uint32_t rfAddrL; /*!< RFADDRL. */
60 uint32_t rfAddrH; /*!< RFADDRH. */
61 } sim_rf_addr_t;
62 #endif /* FSL_FEATURE_SIM_HAS_RF_MAC_ADDR */
63
64 /*!@brief Flash enable mode. */
65 enum _sim_flash_mode
66 {
67 kSIM_FlashDisableInWait = SIM_FCFG1_FLASHDOZE_MASK, /*!< Disable flash in wait mode. */
68 kSIM_FlashDisable = SIM_FCFG1_FLASHDIS_MASK /*!< Disable flash in normal mode. */
69 };
70
71 /*******************************************************************************
72 * API
73 ******************************************************************************/
74
75 #if defined(__cplusplus)
76 extern "C" {
77 #endif /* __cplusplus*/
78
79 #if (defined(FSL_FEATURE_SIM_OPT_HAS_USB_VOLTAGE_REGULATOR) && FSL_FEATURE_SIM_OPT_HAS_USB_VOLTAGE_REGULATOR)
80 /*!
81 * @brief Sets the USB voltage regulator setting.
82 *
83 * This function configures whether the USB voltage regulator is enabled in
84 * normal RUN mode, STOP/VLPS/LLS/VLLS modes, and VLPR/VLPW modes. The configurations
85 * are passed in as mask value of \ref _sim_usb_volt_reg_enable_mode. For example, to enable
86 * USB voltage regulator in RUN/VLPR/VLPW modes and disable in STOP/VLPS/LLS/VLLS mode,
87 * use:
88 *
89 * SIM_SetUsbVoltRegulatorEnableMode(kSIM_UsbVoltRegEnable | kSIM_UsbVoltRegEnableInLowPower);
90 *
91 * @param mask USB voltage regulator enable setting.
92 */
93 void SIM_SetUsbVoltRegulatorEnableMode(uint32_t mask);
94 #endif /* FSL_FEATURE_SIM_OPT_HAS_USB_VOLTAGE_REGULATOR */
95
96 /*!
97 * @brief Gets the unique identification register value.
98 *
99 * @param uid Pointer to the structure to save the UID value.
100 */
101 void SIM_GetUniqueId(sim_uid_t *uid);
102
103 /*!
104 * @brief Sets the flash enable mode.
105 *
106 * @param mode The mode to set; see \ref _sim_flash_mode for mode details.
107 */
SIM_SetFlashMode(uint8_t mode)108 static inline void SIM_SetFlashMode(uint8_t mode)
109 {
110 SIM->FCFG1 = mode;
111 }
112
113 #if (defined(FSL_FEATURE_SIM_HAS_RF_MAC_ADDR) && FSL_FEATURE_SIM_HAS_RF_MAC_ADDR)
114 /*!
115 * @brief Gets the RF address register value.
116 *
117 * @param info Pointer to the structure to save the RF address value.
118 */
119 void SIM_GetRfAddr(sim_rf_addr_t *info);
120 #endif /* FSL_FEATURE_SIM_HAS_RF_MAC_ADDR */
121
122 #if (defined(FSL_FEATURE_SIM_MISC2_HAS_SYSTICK_CLK_EN) && FSL_FEATURE_SIM_MISC2_HAS_SYSTICK_CLK_EN)
123
124 /*!
125 * @brief Enable the Systick clock or not.
126 *
127 * The Systick clock is enabled by default.
128 *
129 * @param enable The switcher for Systick clock.
130 */
SIM_EnableSystickClock(bool enable)131 static inline void SIM_EnableSystickClock(bool enable)
132 {
133 if (enable)
134 {
135 SIM->MISC2 &= ~SIM_MISC2_SYSTICK_CLK_EN_MASK; /* Clear to enable. */
136 }
137 else
138 {
139 SIM->MISC2 |= SIM_MISC2_SYSTICK_CLK_EN_MASK; /* Set to disable. */
140 }
141 }
142
143 #endif /* FSL_FEATURE_SIM_MISC2_HAS_SYSTICK_CLK_EN */
144
145 #if defined(__cplusplus)
146 }
147 #endif /* __cplusplus*/
148
149 /*! @}*/
150
151 #endif /* _FSL_SIM_H_ */
152