fsl_ewm.h 7.7 KB

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