fsl_llwu.h 11 KB

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