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