fsl_llwu.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329
  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_LLWU_H_
  35. #define _FSL_LLWU_H_
  36. #include "fsl_common.h"
  37. /*! @addtogroup llwu */
  38. /*! @{ */
  39. /*******************************************************************************
  40. * Definitions
  41. ******************************************************************************/
  42. /*! @name Driver version */
  43. /*@{*/
  44. /*! @brief LLWU driver version 2.0.1. */
  45. #define FSL_LLWU_DRIVER_VERSION (MAKE_VERSION(2, 0, 1))
  46. /*@}*/
  47. /*!
  48. * @brief External input pin control modes
  49. */
  50. typedef enum _llwu_external_pin_mode
  51. {
  52. kLLWU_ExternalPinDisable = 0U, /*!< Pin disabled as a wakeup input. */
  53. kLLWU_ExternalPinRisingEdge = 1U, /*!< Pin enabled with the rising edge detection. */
  54. kLLWU_ExternalPinFallingEdge = 2U, /*!< Pin enabled with the falling edge detection.*/
  55. kLLWU_ExternalPinAnyEdge = 3U /*!< Pin enabled with any change detection. */
  56. } llwu_external_pin_mode_t;
  57. /*!
  58. * @brief Digital filter control modes
  59. */
  60. typedef enum _llwu_pin_filter_mode
  61. {
  62. kLLWU_PinFilterDisable = 0U, /*!< Filter disabled. */
  63. kLLWU_PinFilterRisingEdge = 1U, /*!< Filter positive edge detection.*/
  64. kLLWU_PinFilterFallingEdge = 2U, /*!< Filter negative edge detection.*/
  65. kLLWU_PinFilterAnyEdge = 3U /*!< Filter any edge detection. */
  66. } llwu_pin_filter_mode_t;
  67. #if (defined(FSL_FEATURE_LLWU_HAS_VERID) && FSL_FEATURE_LLWU_HAS_VERID)
  68. /*!
  69. * @brief IP version ID definition.
  70. */
  71. typedef struct _llwu_version_id
  72. {
  73. uint16_t feature; /*!< A feature specification number. */
  74. uint8_t minor; /*!< The minor version number. */
  75. uint8_t major; /*!< The major version number. */
  76. } llwu_version_id_t;
  77. #endif /* FSL_FEATURE_LLWU_HAS_VERID */
  78. #if (defined(FSL_FEATURE_LLWU_HAS_PARAM) && FSL_FEATURE_LLWU_HAS_PARAM)
  79. /*!
  80. * @brief IP parameter definition.
  81. */
  82. typedef struct _llwu_param
  83. {
  84. uint8_t filters; /*!< A number of the pin filter. */
  85. uint8_t dmas; /*!< A number of the wakeup DMA. */
  86. uint8_t modules; /*!< A number of the wakeup module. */
  87. uint8_t pins; /*!< A number of the wake up pin. */
  88. } llwu_param_t;
  89. #endif /* FSL_FEATURE_LLWU_HAS_PARAM */
  90. #if (defined(FSL_FEATURE_LLWU_HAS_PIN_FILTER) && FSL_FEATURE_LLWU_HAS_PIN_FILTER)
  91. /*!
  92. * @brief An external input pin filter control structure
  93. */
  94. typedef struct _llwu_external_pin_filter_mode
  95. {
  96. uint32_t pinIndex; /*!< A pin number */
  97. llwu_pin_filter_mode_t filterMode; /*!< Filter mode */
  98. } llwu_external_pin_filter_mode_t;
  99. #endif /* FSL_FEATURE_LLWU_HAS_PIN_FILTER */
  100. /*******************************************************************************
  101. * API
  102. ******************************************************************************/
  103. #if defined(__cplusplus)
  104. extern "C" {
  105. #endif
  106. /*!
  107. * @name Low-Leakage Wakeup Unit Control APIs
  108. * @{
  109. */
  110. #if (defined(FSL_FEATURE_LLWU_HAS_VERID) && FSL_FEATURE_LLWU_HAS_VERID)
  111. /*!
  112. * @brief Gets the LLWU version ID.
  113. *
  114. * This function gets the LLWU version ID, including the major version number,
  115. * the minor version number, and the feature specification number.
  116. *
  117. * @param base LLWU peripheral base address.
  118. * @param versionId A pointer to the version ID structure.
  119. */
  120. static inline void LLWU_GetVersionId(LLWU_Type *base, llwu_version_id_t *versionId)
  121. {
  122. *((uint32_t *)versionId) = base->VERID;
  123. }
  124. #endif /* FSL_FEATURE_LLWU_HAS_VERID */
  125. #if (defined(FSL_FEATURE_LLWU_HAS_PARAM) && FSL_FEATURE_LLWU_HAS_PARAM)
  126. /*!
  127. * @brief Gets the LLWU parameter.
  128. *
  129. * This function gets the LLWU parameter, including a wakeup pin number, a module
  130. * number, a DMA number, and a pin filter number.
  131. *
  132. * @param base LLWU peripheral base address.
  133. * @param param A pointer to the LLWU parameter structure.
  134. */
  135. static inline void LLWU_GetParam(LLWU_Type *base, llwu_param_t *param)
  136. {
  137. *((uint32_t *)param) = base->PARAM;
  138. }
  139. #endif /* FSL_FEATURE_LLWU_HAS_PARAM */
  140. #if (defined(FSL_FEATURE_LLWU_HAS_EXTERNAL_PIN) && FSL_FEATURE_LLWU_HAS_EXTERNAL_PIN)
  141. /*!
  142. * @brief Sets the external input pin source mode.
  143. *
  144. * This function sets the external input pin source mode that is used
  145. * as a wake up source.
  146. *
  147. * @param base LLWU peripheral base address.
  148. * @param pinIndex A pin index to be enabled as an external wakeup source starting from 1.
  149. * @param pinMode A pin configuration mode defined in the llwu_external_pin_modes_t.
  150. */
  151. void LLWU_SetExternalWakeupPinMode(LLWU_Type *base, uint32_t pinIndex, llwu_external_pin_mode_t pinMode);
  152. /*!
  153. * @brief Gets the external wakeup source flag.
  154. *
  155. * This function checks the external pin flag to detect whether the MCU is
  156. * woken up by the specific pin.
  157. *
  158. * @param base LLWU peripheral base address.
  159. * @param pinIndex A pin index, which starts from 1.
  160. * @return True if the specific pin is a wakeup source.
  161. */
  162. bool LLWU_GetExternalWakeupPinFlag(LLWU_Type *base, uint32_t pinIndex);
  163. /*!
  164. * @brief Clears the external wakeup source flag.
  165. *
  166. * This function clears the external wakeup source flag for a specific pin.
  167. *
  168. * @param base LLWU peripheral base address.
  169. * @param pinIndex A pin index, which starts from 1.
  170. */
  171. void LLWU_ClearExternalWakeupPinFlag(LLWU_Type *base, uint32_t pinIndex);
  172. #endif /* FSL_FEATURE_LLWU_HAS_EXTERNAL_PIN */
  173. #if (defined(FSL_FEATURE_LLWU_HAS_INTERNAL_MODULE) && FSL_FEATURE_LLWU_HAS_INTERNAL_MODULE)
  174. /*!
  175. * @brief Enables/disables the internal module source.
  176. *
  177. * This function enables/disables the internal module source mode that is used
  178. * as a wake up source.
  179. *
  180. * @param base LLWU peripheral base address.
  181. * @param moduleIndex A module index to be enabled as an internal wakeup source starting from 1.
  182. * @param enable An enable or a disable setting
  183. */
  184. static inline void LLWU_EnableInternalModuleInterruptWakup(LLWU_Type *base, uint32_t moduleIndex, bool enable)
  185. {
  186. if (enable)
  187. {
  188. base->ME |= 1U << moduleIndex;
  189. }
  190. else
  191. {
  192. base->ME &= ~(1U << moduleIndex);
  193. }
  194. }
  195. #if (!(defined(FSL_FEATURE_LLWU_HAS_NO_INTERNAL_MODULE_WAKEUP_FLAG_REG) && \
  196. FSL_FEATURE_LLWU_HAS_NO_INTERNAL_MODULE_WAKEUP_FLAG_REG))
  197. /* Re-define the register which includes the internal wakeup module flag. */
  198. #if (defined(FSL_FEATURE_LLWU_REG_BITWIDTH) && (FSL_FEATURE_LLWU_REG_BITWIDTH == 32)) /* 32-bit LLWU. */
  199. #if (defined(FSL_FEATURE_LLWU_HAS_MF) && FSL_FEATURE_LLWU_HAS_MF)
  200. #define INTERNAL_WAKEUP_MODULE_FLAG_REG MF
  201. #else
  202. #error "Unsupported internal module flag register."
  203. #endif
  204. #else /* 8-bit LLUW. */
  205. #if (defined(FSL_FEATURE_LLWU_HAS_MF) && FSL_FEATURE_LLWU_HAS_MF)
  206. #define INTERNAL_WAKEUP_MODULE_FLAG_REG MF5
  207. #elif(defined(FSL_FEATURE_LLWU_HAS_PF) && FSL_FEATURE_LLWU_HAS_PF)
  208. #define INTERNAL_WAKEUP_MODULE_FLAG_REG PF3
  209. #elif(!(defined(FSL_FEATURE_LLWU_HAS_EXTERNAL_PIN) && (FSL_FEATURE_LLWU_HAS_EXTERNAL_PIN > 16)))
  210. #define INTERNAL_WAKEUP_MODULE_FLAG_REG F3
  211. #else
  212. #error "Unsupported internal module flag register."
  213. #endif
  214. #endif /* FSL_FEATURE_LLWU_REG_BITWIDTH */
  215. /*!
  216. * @brief Gets the external wakeup source flag.
  217. *
  218. * This function checks the external pin flag to detect whether the system is
  219. * woken up by the specific pin.
  220. *
  221. * @param base LLWU peripheral base address.
  222. * @param moduleIndex A module index, which starts from 1.
  223. * @return True if the specific pin is a wake up source.
  224. */
  225. static inline bool LLWU_GetInternalWakeupModuleFlag(LLWU_Type *base, uint32_t moduleIndex)
  226. {
  227. return ((1U << moduleIndex) == (base->INTERNAL_WAKEUP_MODULE_FLAG_REG & (1U << moduleIndex)));
  228. }
  229. #endif /* FSL_FEATURE_LLWU_HAS_NO_INTERNAL_MODULE_WAKEUP_FLAG_REG */
  230. #endif /* FSL_FEATURE_LLWU_HAS_INTERNAL_MODULE */
  231. #if (defined(FSL_FEATURE_LLWU_HAS_DMA_ENABLE_REG) && FSL_FEATURE_LLWU_HAS_DMA_ENABLE_REG)
  232. /*!
  233. * @brief Enables/disables the internal module DMA wakeup source.
  234. *
  235. * This function enables/disables the internal DMA that is used as a wake up source.
  236. *
  237. * @param base LLWU peripheral base address.
  238. * @param moduleIndex An internal module index which is used as a DMA request source, starting from 1.
  239. * @param enable Enable or disable the DMA request source
  240. */
  241. static inline void LLWU_EnableInternalModuleDmaRequestWakup(LLWU_Type *base, uint32_t moduleIndex, bool enable)
  242. {
  243. if (enable)
  244. {
  245. base->DE |= 1U << moduleIndex;
  246. }
  247. else
  248. {
  249. base->DE &= ~(1U << moduleIndex);
  250. }
  251. }
  252. #endif /* FSL_FEATURE_LLWU_HAS_DMA_ENABLE_REG */
  253. #if (defined(FSL_FEATURE_LLWU_HAS_PIN_FILTER) && FSL_FEATURE_LLWU_HAS_PIN_FILTER)
  254. /*!
  255. * @brief Sets the pin filter configuration.
  256. *
  257. * This function sets the pin filter configuration.
  258. *
  259. * @param base LLWU peripheral base address.
  260. * @param filterIndex A pin filter index used to enable/disable the digital filter, starting from 1.
  261. * @param filterMode A filter mode configuration
  262. */
  263. void LLWU_SetPinFilterMode(LLWU_Type *base, uint32_t filterIndex, llwu_external_pin_filter_mode_t filterMode);
  264. /*!
  265. * @brief Gets the pin filter configuration.
  266. *
  267. * This function gets the pin filter flag.
  268. *
  269. * @param base LLWU peripheral base address.
  270. * @param filterIndex A pin filter index, which starts from 1.
  271. * @return True if the flag is a source of the existing low-leakage power mode.
  272. */
  273. bool LLWU_GetPinFilterFlag(LLWU_Type *base, uint32_t filterIndex);
  274. /*!
  275. * @brief Clears the pin filter configuration.
  276. *
  277. * This function clears the pin filter flag.
  278. *
  279. * @param base LLWU peripheral base address.
  280. * @param filterIndex A pin filter index to clear the flag, starting from 1.
  281. */
  282. void LLWU_ClearPinFilterFlag(LLWU_Type *base, uint32_t filterIndex);
  283. #endif /* FSL_FEATURE_LLWU_HAS_PIN_FILTER */
  284. #if (defined(FSL_FEATURE_LLWU_HAS_RESET_ENABLE) && FSL_FEATURE_LLWU_HAS_RESET_ENABLE)
  285. /*!
  286. * @brief Sets the reset pin mode.
  287. *
  288. * This function determines how the reset pin is used as a low leakage mode exit source.
  289. *
  290. * @param pinEnable Enable reset the pin filter
  291. * @param pinFilterEnable Specify whether the pin filter is enabled in Low-Leakage power mode.
  292. */
  293. void LLWU_SetResetPinMode(LLWU_Type *base, bool pinEnable, bool enableInLowLeakageMode);
  294. #endif /* FSL_FEATURE_LLWU_HAS_RESET_ENABLE */
  295. /*@}*/
  296. #if defined(__cplusplus)
  297. }
  298. #endif
  299. /*! @}*/
  300. #endif /* _FSL_LLWU_H_*/