fsl_ewm.h 7.5 KB

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