Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.
 
 
 

327 rindas
11 KiB

  1. /*
  2. * Copyright (c) 2015, Freescale Semiconductor, Inc.
  3. * Copyright 2016-2020 NXP
  4. * All rights reserved.
  5. *
  6. * SPDX-License-Identifier: BSD-3-Clause
  7. */
  8. #ifndef _FSL_LLWU_H_
  9. #define _FSL_LLWU_H_
  10. #include "fsl_common.h"
  11. /*! @addtogroup llwu */
  12. /*! @{ */
  13. /*******************************************************************************
  14. * Definitions
  15. ******************************************************************************/
  16. /*! @name Driver version */
  17. /*@{*/
  18. /*! @brief LLWU driver version. */
  19. #define FSL_LLWU_DRIVER_VERSION (MAKE_VERSION(2, 0, 5))
  20. /*@}*/
  21. #if (defined(FSL_FEATURE_LLWU_REG_BITWIDTH) && (FSL_FEATURE_LLWU_REG_BITWIDTH == 32))
  22. #define LLWU_REG_VAL(x) ((uint32_t)(x))
  23. #else
  24. #define LLWU_REG_VAL(x) ((uint8_t)(x))
  25. #endif
  26. /*!
  27. * @brief External input pin control modes
  28. */
  29. typedef enum _llwu_external_pin_mode
  30. {
  31. kLLWU_ExternalPinDisable = 0U, /*!< Pin disabled as a wakeup input. */
  32. kLLWU_ExternalPinRisingEdge = 1U, /*!< Pin enabled with the rising edge detection. */
  33. kLLWU_ExternalPinFallingEdge = 2U, /*!< Pin enabled with the falling edge detection.*/
  34. kLLWU_ExternalPinAnyEdge = 3U /*!< Pin enabled with any change detection. */
  35. } llwu_external_pin_mode_t;
  36. /*!
  37. * @brief Digital filter control modes
  38. */
  39. typedef enum _llwu_pin_filter_mode
  40. {
  41. kLLWU_PinFilterDisable = 0U, /*!< Filter disabled. */
  42. kLLWU_PinFilterRisingEdge = 1U, /*!< Filter positive edge detection.*/
  43. kLLWU_PinFilterFallingEdge = 2U, /*!< Filter negative edge detection.*/
  44. kLLWU_PinFilterAnyEdge = 3U /*!< Filter any edge detection. */
  45. } llwu_pin_filter_mode_t;
  46. #if (defined(FSL_FEATURE_LLWU_HAS_VERID) && FSL_FEATURE_LLWU_HAS_VERID)
  47. /*!
  48. * @brief IP version ID definition.
  49. */
  50. typedef struct _llwu_version_id
  51. {
  52. uint16_t feature; /*!< A feature specification number. */
  53. uint8_t minor; /*!< The minor version number. */
  54. uint8_t major; /*!< The major version number. */
  55. } llwu_version_id_t;
  56. #endif /* FSL_FEATURE_LLWU_HAS_VERID */
  57. #if (defined(FSL_FEATURE_LLWU_HAS_PARAM) && FSL_FEATURE_LLWU_HAS_PARAM)
  58. /*!
  59. * @brief IP parameter definition.
  60. */
  61. typedef struct _llwu_param
  62. {
  63. uint8_t filters; /*!< A number of the pin filter. */
  64. uint8_t dmas; /*!< A number of the wakeup DMA. */
  65. uint8_t modules; /*!< A number of the wakeup module. */
  66. uint8_t pins; /*!< A number of the wake up pin. */
  67. } llwu_param_t;
  68. #endif /* FSL_FEATURE_LLWU_HAS_PARAM */
  69. #if (defined(FSL_FEATURE_LLWU_HAS_PIN_FILTER) && FSL_FEATURE_LLWU_HAS_PIN_FILTER)
  70. /*!
  71. * @brief An external input pin filter control structure
  72. */
  73. typedef struct _llwu_external_pin_filter_mode
  74. {
  75. uint32_t pinIndex; /*!< A pin number */
  76. llwu_pin_filter_mode_t filterMode; /*!< Filter mode */
  77. } llwu_external_pin_filter_mode_t;
  78. #endif /* FSL_FEATURE_LLWU_HAS_PIN_FILTER */
  79. /*******************************************************************************
  80. * API
  81. ******************************************************************************/
  82. #if defined(__cplusplus)
  83. extern "C" {
  84. #endif
  85. /*!
  86. * @name Low-Leakage Wakeup Unit Control APIs
  87. * @{
  88. */
  89. #if (defined(FSL_FEATURE_LLWU_HAS_VERID) && FSL_FEATURE_LLWU_HAS_VERID)
  90. /*!
  91. * @brief Gets the LLWU version ID.
  92. *
  93. * This function gets the LLWU version ID, including the major version number,
  94. * the minor version number, and the feature specification number.
  95. *
  96. * @param base LLWU peripheral base address.
  97. * @param versionId A pointer to the version ID structure.
  98. */
  99. static inline void LLWU_GetVersionId(LLWU_Type *base, llwu_version_id_t *versionId)
  100. {
  101. union
  102. {
  103. llwu_version_id_t vid;
  104. uint32_t u32;
  105. } llwuVID;
  106. llwuVID.u32 = base->VERID;
  107. *versionId = llwuVID.vid;
  108. }
  109. #endif /* FSL_FEATURE_LLWU_HAS_VERID */
  110. #if (defined(FSL_FEATURE_LLWU_HAS_PARAM) && FSL_FEATURE_LLWU_HAS_PARAM)
  111. /*!
  112. * @brief Gets the LLWU parameter.
  113. *
  114. * This function gets the LLWU parameter, including a wakeup pin number, a module
  115. * number, a DMA number, and a pin filter number.
  116. *
  117. * @param base LLWU peripheral base address.
  118. * @param param A pointer to the LLWU parameter structure.
  119. */
  120. static inline void LLWU_GetParam(LLWU_Type *base, llwu_param_t *param)
  121. {
  122. union
  123. {
  124. llwu_param_t param;
  125. uint32_t u32;
  126. } llwuParam;
  127. llwuParam.u32 = base->PARAM;
  128. *param = llwuParam.param;
  129. }
  130. #endif /* FSL_FEATURE_LLWU_HAS_PARAM */
  131. #if (defined(FSL_FEATURE_LLWU_HAS_EXTERNAL_PIN) && FSL_FEATURE_LLWU_HAS_EXTERNAL_PIN)
  132. /*!
  133. * @brief Sets the external input pin source mode.
  134. *
  135. * This function sets the external input pin source mode that is used
  136. * as a wake up source.
  137. *
  138. * @param base LLWU peripheral base address.
  139. * @param pinIndex A pin index to be enabled as an external wakeup source starting from 1.
  140. * @param pinMode A pin configuration mode defined in the llwu_external_pin_modes_t.
  141. */
  142. void LLWU_SetExternalWakeupPinMode(LLWU_Type *base, uint32_t pinIndex, llwu_external_pin_mode_t pinMode);
  143. /*!
  144. * @brief Gets the external wakeup source flag.
  145. *
  146. * This function checks the external pin flag to detect whether the MCU is
  147. * woken up by the specific pin.
  148. *
  149. * @param base LLWU peripheral base address.
  150. * @param pinIndex A pin index, which starts from 1.
  151. * @return True if the specific pin is a wakeup source.
  152. */
  153. bool LLWU_GetExternalWakeupPinFlag(LLWU_Type *base, uint32_t pinIndex);
  154. /*!
  155. * @brief Clears the external wakeup source flag.
  156. *
  157. * This function clears the external wakeup source flag for a specific pin.
  158. *
  159. * @param base LLWU peripheral base address.
  160. * @param pinIndex A pin index, which starts from 1.
  161. */
  162. void LLWU_ClearExternalWakeupPinFlag(LLWU_Type *base, uint32_t pinIndex);
  163. #endif /* FSL_FEATURE_LLWU_HAS_EXTERNAL_PIN */
  164. #if (defined(FSL_FEATURE_LLWU_HAS_INTERNAL_MODULE) && FSL_FEATURE_LLWU_HAS_INTERNAL_MODULE)
  165. /*!
  166. * @brief Enables/disables the internal module source.
  167. *
  168. * This function enables/disables the internal module source mode that is used
  169. * as a wake up source.
  170. *
  171. * @param base LLWU peripheral base address.
  172. * @param moduleIndex A module index to be enabled as an internal wakeup source starting from 1.
  173. * @param enable An enable or a disable setting
  174. */
  175. static inline void LLWU_EnableInternalModuleInterruptWakup(LLWU_Type *base, uint32_t moduleIndex, bool enable)
  176. {
  177. if (enable)
  178. {
  179. base->ME |= LLWU_REG_VAL(1UL << moduleIndex);
  180. }
  181. else
  182. {
  183. base->ME &= LLWU_REG_VAL(~(1UL << moduleIndex));
  184. }
  185. }
  186. #if (!(defined(FSL_FEATURE_LLWU_HAS_NO_INTERNAL_MODULE_WAKEUP_FLAG_REG) && \
  187. FSL_FEATURE_LLWU_HAS_NO_INTERNAL_MODULE_WAKEUP_FLAG_REG))
  188. /* Re-define the register which includes the internal wakeup module flag. */
  189. #if (defined(FSL_FEATURE_LLWU_REG_BITWIDTH) && (FSL_FEATURE_LLWU_REG_BITWIDTH == 32)) /* 32-bit LLWU. */
  190. #if (defined(FSL_FEATURE_LLWU_HAS_MF) && FSL_FEATURE_LLWU_HAS_MF)
  191. #define INTERNAL_WAKEUP_MODULE_FLAG_REG MF
  192. #else
  193. #error "Unsupported internal module flag register."
  194. #endif
  195. #else /* 8-bit LLUW. */
  196. #if (defined(FSL_FEATURE_LLWU_HAS_MF) && FSL_FEATURE_LLWU_HAS_MF)
  197. #define INTERNAL_WAKEUP_MODULE_FLAG_REG MF5
  198. #elif (defined(FSL_FEATURE_LLWU_HAS_PF) && FSL_FEATURE_LLWU_HAS_PF)
  199. #define INTERNAL_WAKEUP_MODULE_FLAG_REG PF3
  200. #elif (!(defined(FSL_FEATURE_LLWU_HAS_EXTERNAL_PIN) && (FSL_FEATURE_LLWU_HAS_EXTERNAL_PIN > 16)))
  201. #define INTERNAL_WAKEUP_MODULE_FLAG_REG F3
  202. #else
  203. #error "Unsupported internal module flag register."
  204. #endif
  205. #endif /* FSL_FEATURE_LLWU_REG_BITWIDTH */
  206. /*!
  207. * @brief Gets the external wakeup source flag.
  208. *
  209. * This function checks the external pin flag to detect whether the system is
  210. * woken up by the specific pin.
  211. *
  212. * @param base LLWU peripheral base address.
  213. * @param moduleIndex A module index, which starts from 1.
  214. * @return True if the specific pin is a wake up source.
  215. */
  216. static inline bool LLWU_GetInternalWakeupModuleFlag(LLWU_Type *base, uint32_t moduleIndex)
  217. {
  218. return ((1UL << moduleIndex) == ((uint32_t)base->INTERNAL_WAKEUP_MODULE_FLAG_REG & (1UL << moduleIndex)));
  219. }
  220. #endif /* FSL_FEATURE_LLWU_HAS_NO_INTERNAL_MODULE_WAKEUP_FLAG_REG */
  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 |= LLWU_REG_VAL(1UL << moduleIndex);
  237. }
  238. else
  239. {
  240. base->DE &= LLWU_REG_VAL(~(1UL << 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 base LLWU peripheral base address.
  282. * @param pinEnable Enable reset the pin filter
  283. * @param pinFilterEnable Specify whether the pin filter is enabled in Low-Leakage power mode.
  284. */
  285. void LLWU_SetResetPinMode(LLWU_Type *base, bool pinEnable, bool pinFilterEnable);
  286. #endif /* FSL_FEATURE_LLWU_HAS_RESET_ENABLE */
  287. /*@}*/
  288. #if defined(__cplusplus)
  289. }
  290. #endif
  291. /*! @}*/
  292. #endif /* _FSL_LLWU_H_*/