Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.
 
 
 

219 řádky
6.1 KiB

  1. /*
  2. * Copyright (c) 2015, Freescale Semiconductor, Inc.
  3. * Copyright 2016-2017, 2020 NXP
  4. * All rights reserved.
  5. *
  6. * SPDX-License-Identifier: BSD-3-Clause
  7. */
  8. #ifndef _FSL_EWM_H_
  9. #define _FSL_EWM_H_
  10. #include "fsl_common.h"
  11. /*!
  12. * @addtogroup ewm
  13. * @{
  14. */
  15. /*******************************************************************************
  16. * Definitions
  17. *******************************************************************************/
  18. /*! @name Driver version */
  19. /*@{*/
  20. /*! @brief EWM driver version 2.0.2. */
  21. #define FSL_EWM_DRIVER_VERSION (MAKE_VERSION(2, 0, 2))
  22. /*@}*/
  23. /*! @brief Describes EWM clock source. */
  24. #if defined(FSL_FEATURE_EWM_HAS_CLOCK_SELECT) && FSL_FEATURE_EWM_HAS_CLOCK_SELECT
  25. typedef enum _ewm_lpo_clock_source
  26. {
  27. kEWM_LpoClockSource0 = 0U, /*!< EWM clock sourced from lpo_clk[0]*/
  28. kEWM_LpoClockSource1 = 1U, /*!< EWM clock sourced from lpo_clk[1]*/
  29. kEWM_LpoClockSource2 = 2U, /*!< EWM clock sourced from lpo_clk[2]*/
  30. kEWM_LpoClockSource3 = 3U, /*!< EWM clock sourced from lpo_clk[3]*/
  31. } ewm_lpo_clock_source_t;
  32. #endif /* FSL_FEATURE_EWM_HAS_CLOCK_SELECT */
  33. /*!
  34. * @brief Data structure for EWM configuration.
  35. *
  36. * This structure is used to configure the EWM.
  37. */
  38. typedef struct _ewm_config
  39. {
  40. bool enableEwm; /*!< Enable EWM module */
  41. bool enableEwmInput; /*!< Enable EWM_in input */
  42. bool setInputAssertLogic; /*!< EWM_in signal assertion state */
  43. bool enableInterrupt; /*!< Enable EWM interrupt */
  44. #if defined(FSL_FEATURE_EWM_HAS_CLOCK_SELECT) && FSL_FEATURE_EWM_HAS_CLOCK_SELECT
  45. ewm_lpo_clock_source_t clockSource; /*!< Clock source select */
  46. #endif /* FSL_FEATURE_EWM_HAS_CLOCK_SELECT */
  47. #if defined(FSL_FEATURE_EWM_HAS_PRESCALER) && FSL_FEATURE_EWM_HAS_PRESCALER
  48. uint8_t prescaler; /*!< Clock prescaler value */
  49. #endif /* FSL_FEATURE_EWM_HAS_PRESCALER */
  50. uint8_t compareLowValue; /*!< Compare low-register value */
  51. uint8_t compareHighValue; /*!< Compare high-register value */
  52. } ewm_config_t;
  53. /*!
  54. * @brief EWM interrupt configuration structure with default settings all disabled.
  55. *
  56. * This structure contains the settings for all of EWM interrupt configurations.
  57. */
  58. enum _ewm_interrupt_enable_t
  59. {
  60. kEWM_InterruptEnable = EWM_CTRL_INTEN_MASK, /*!< Enable the EWM to generate an interrupt*/
  61. };
  62. /*!
  63. * @brief EWM status flags.
  64. *
  65. * This structure contains the constants for the EWM status flags for use in the EWM functions.
  66. */
  67. enum _ewm_status_flags_t
  68. {
  69. kEWM_RunningFlag = EWM_CTRL_EWMEN_MASK, /*!< Running flag, set when EWM is enabled*/
  70. };
  71. /*******************************************************************************
  72. * API
  73. *******************************************************************************/
  74. #if defined(__cplusplus)
  75. extern "C" {
  76. #endif /* __cplusplus */
  77. /*!
  78. * @name EWM initialization and de-initialization
  79. * @{
  80. */
  81. /*!
  82. * @brief Initializes the EWM peripheral.
  83. *
  84. * This function is used to initialize the EWM. After calling, the EWM
  85. * runs immediately according to the configuration.
  86. * Note that, except for the interrupt enable control bit, other control bits and registers are write once after a
  87. * CPU reset. Modifying them more than once generates a bus transfer error.
  88. *
  89. * This is an example.
  90. * @code
  91. * ewm_config_t config;
  92. * EWM_GetDefaultConfig(&config);
  93. * config.compareHighValue = 0xAAU;
  94. * EWM_Init(ewm_base,&config);
  95. * @endcode
  96. *
  97. * @param base EWM peripheral base address
  98. * @param config The configuration of the EWM
  99. */
  100. void EWM_Init(EWM_Type *base, const ewm_config_t *config);
  101. /*!
  102. * @brief Deinitializes the EWM peripheral.
  103. *
  104. * This function is used to shut down the EWM.
  105. *
  106. * @param base EWM peripheral base address
  107. */
  108. void EWM_Deinit(EWM_Type *base);
  109. /*!
  110. * @brief Initializes the EWM configuration structure.
  111. *
  112. * This function initializes the EWM configuration structure to default values. The default
  113. * values are as follows.
  114. * @code
  115. * ewmConfig->enableEwm = true;
  116. * ewmConfig->enableEwmInput = false;
  117. * ewmConfig->setInputAssertLogic = false;
  118. * ewmConfig->enableInterrupt = false;
  119. * ewmConfig->ewm_lpo_clock_source_t = kEWM_LpoClockSource0;
  120. * ewmConfig->prescaler = 0;
  121. * ewmConfig->compareLowValue = 0;
  122. * ewmConfig->compareHighValue = 0xFEU;
  123. * @endcode
  124. *
  125. * @param config Pointer to the EWM configuration structure.
  126. * @see ewm_config_t
  127. */
  128. void EWM_GetDefaultConfig(ewm_config_t *config);
  129. /* @} */
  130. /*!
  131. * @name EWM functional Operation
  132. * @{
  133. */
  134. /*!
  135. * @brief Enables the EWM interrupt.
  136. *
  137. * This function enables the EWM interrupt.
  138. *
  139. * @param base EWM peripheral base address
  140. * @param mask The interrupts to enable
  141. * The parameter can be combination of the following source if defined
  142. * @arg kEWM_InterruptEnable
  143. */
  144. static inline void EWM_EnableInterrupts(EWM_Type *base, uint32_t mask)
  145. {
  146. base->CTRL |= (uint8_t)mask;
  147. }
  148. /*!
  149. * @brief Disables the EWM interrupt.
  150. *
  151. * This function enables the EWM interrupt.
  152. *
  153. * @param base EWM peripheral base address
  154. * @param mask The interrupts to disable
  155. * The parameter can be combination of the following source if defined
  156. * @arg kEWM_InterruptEnable
  157. */
  158. static inline void EWM_DisableInterrupts(EWM_Type *base, uint32_t mask)
  159. {
  160. base->CTRL &= (uint8_t)(~mask);
  161. }
  162. /*!
  163. * @brief Gets all status flags.
  164. *
  165. * This function gets all status flags.
  166. *
  167. * This is an example for getting the running flag.
  168. * @code
  169. * uint32_t status;
  170. * status = EWM_GetStatusFlags(ewm_base) & kEWM_RunningFlag;
  171. * @endcode
  172. * @param base EWM peripheral base address
  173. * @return State of the status flag: asserted (true) or not-asserted (false).@see _ewm_status_flags_t
  174. * - True: a related status flag has been set.
  175. * - False: a related status flag is not set.
  176. */
  177. static inline uint32_t EWM_GetStatusFlags(EWM_Type *base)
  178. {
  179. return ((uint32_t)base->CTRL & EWM_CTRL_EWMEN_MASK);
  180. }
  181. /*!
  182. * @brief Services the EWM.
  183. *
  184. * This function resets the EWM counter to zero.
  185. *
  186. * @param base EWM peripheral base address
  187. */
  188. void EWM_Refresh(EWM_Type *base);
  189. /*@}*/
  190. #if defined(__cplusplus)
  191. }
  192. #endif /* __cplusplus */
  193. /*! @}*/
  194. #endif /* _FSL_EWM_H_ */