1 /***************************************************************************//**
2 * \file cy_tcpwm_counter.h
3 * \version 1.70
4 *
5 * \brief
6 * The header file of the TCPWM Timer Counter driver.
7 *
8 ********************************************************************************
9 * \copyright
10 * Copyright 2016-2021 Cypress Semiconductor Corporation
11 * SPDX-License-Identifier: Apache-2.0
12 *
13 * Licensed under the Apache License, Version 2.0 (the "License");
14 * you may not use this file except in compliance with the License.
15 * You may obtain a copy of the License at
16 *
17 *     http://www.apache.org/licenses/LICENSE-2.0
18 *
19 * Unless required by applicable law or agreed to in writing, software
20 * distributed under the License is distributed on an "AS IS" BASIS,
21 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
22 * See the License for the specific language governing permissions and
23 * limitations under the License.
24 *******************************************************************************/
25 #if !defined(CY_TCPWM_COUNTER_H)
26 #define CY_TCPWM_COUNTER_H
27 
28 #include "cy_tcpwm.h"
29 
30 #ifdef CY_IP_MXTCPWM
31 
32 #if defined(__cplusplus)
33 extern "C" {
34 #endif
35 
36 /**
37 * \addtogroup group_tcpwm_counter
38 * \{
39 * Driver API for Timer/Counter.
40 *
41 * The functions and other declarations used in this part of the driver are
42 * in cy_tcpwm_counter.h. You can also include cy_pdl.h
43 * to get access to all functions and declarations in the PDL.
44 *
45 * Use Timer/Counter mode whenever a specific timing interval or measurement is
46 * needed. Examples include:
47 * * Creating a periodic interrupt for running other system tasks
48 * * Measuring frequency of an input signal
49 * * Measuring pulse width of an input signal
50 * * Measuring time between two external events
51 * * Counting events
52 * * Triggering other system resources after x number events
53 * * Capturing time stamps when events occur
54 *
55 * The Timer/Counter has the following features:
56 * * 16- or 32-bit Timer/Counter.
57 * * Programmable Period Register.
58 * * Programmable Compare Register. Compare value can be swapped with a
59 * buffered compare value on comparison event.
60 * * Capture with buffer register.
61 * * Count Up, Count Down, or Count Up and Down Counting modes.
62 * * Continuous or One Shot Run modes.
63 * * Interrupt on Terminal Count and Compare or Capture 0. Interrupt on Compare or Capture 1 is only available in TCPWM Version 2.
64 * * Start, Reload, Stop, Capture, and Count Inputs.
65 * * 2 compare (CC0/CC1) registers with double buffer, Capture 1 event. Second compare
66 * register and Capture 1 event are available only in TCPWM Version 2.
67 * * Two programmable trigger outputs, trig_out0 and trig_out1 that generate a
68 * trigger on one of the following events Overflow, Underflow, Terminal Count,
69 * and Compare Match 0/1. The available triggers are dependent on the Timer/Counter mode.
70 * All these features are only available in TCPWM Version 2.
71 * * Overflow, Underflow, and Compare(cc_match) trigger outputs are only available in TCPWM Version 1.
72 * * Second Compare Match (CC_MATCH1) event is only available in TCPWM Version 2.
73 *
74 * \section group_tcpwm_counter_configuration Configuration Considerations
75 *
76 * The Counter configuration can be divided to number of sequential
77 * steps listed below:
78 * * \ref group_tcpwm_counter_config
79 * * \ref group_tcpwm_counter_clock
80 * * \ref group_tcpwm_counter_enable
81 * * \ref group_tcpwm_counter_start
82 *
83 * \subsection group_tcpwm_counter_config Configure Counter
84 * To configure Counter, provide the configuration parameters in the
85 * \ref cy_stc_tcpwm_counter_config_t structure. The Configuration structure
86 * can be modified through software, but if the configurator in ModusToolbox is used
87 * then the configuration structure will be updated with the users input. To initialize
88 * the driver, call \ref Cy_TCPWM_Counter_Init function providing a pointer to the populated
89 * \ref cy_stc_tcpwm_counter_config_t structure.
90 *
91 * For TCPWM V1 Configuration
92 * \snippet tcpwm/counter/snippet/main.c snippet_Cy_TCPWM_V1_Counter_Init
93 *
94 * TCPWM V2 Configuration
95 * \snippet tcpwm/counter/snippet/main.c snippet_Cy_TCPWM_V2_Counter_Init
96 *
97 * \subsection group_tcpwm_counter_clock Assign Clock Divider
98 * The clock source must be connected to proper working.
99 * Any of the peripheral clock dividers could be used. Use the
100 * \ref group_sysclk driver API to do that.
101 *
102 * \subsection group_tcpwm_counter_enable Enable Counter
103 * Counter has to be enabled before starting
104 *
105 * \snippet tcpwm/counter/snippet/main.c snippet_Cy_TCPWM_Counter_Enable
106 *
107 * \subsection group_tcpwm_counter_start Start Counter
108 * Counter has to be started
109 *
110 * \snippet tcpwm/counter/snippet/main.c snippet_Cy_TCPWM_Counter_Start
111 *
112 */
113 
114 /**
115 * \defgroup group_tcpwm_macros_counter          Macros
116 * \defgroup group_tcpwm_functions_counter       Functions
117 * \defgroup group_tcpwm_data_structures_counter Data Structures
118 * \} */
119 
120 /**
121 * \addtogroup group_tcpwm_data_structures_counter
122 * \{
123 */
124 #if (CY_IP_MXTCPWM_VERSION >= 3U) || defined (CY_DOXYGEN)
125 /** Counter Direction modes  */
126 typedef enum
127 {
128     CY_TCPWM_COUNTER_DIRECTION_DISABLE  = 0UL, /**< Counter changes current count direction is disabled */
129     CY_TCPWM_COUNTER_DIRECTION_FALLING  = 1UL, /**< Counter changes current count direction based on falling edge of capture0 input */
130     CY_TCPWM_COUNTER_DIRECTION_RISING   = 2UL, /**< Counter changes current count direction based on rising edge of capture0 input */
131     CY_TCPWM_COUNTER_DIRECTION_LEVEL    = 3UL, /**< Counter count increase when capture0 level equal to high, counter count decrease when capture0 level equals to low */
132 } cy_en_counter_direction_t;
133 #endif /* (CY_IP_MXTCPWM_VERSION >= 3U) || defined (CY_DOXYGEN) */
134 /** Counter Timer configuration structure */
135 typedef struct cy_stc_tcpwm_counter_config
136 {
137     uint32_t    period;             /**< Sets the period of the counter */
138     /** Sets the clock prescaler inside the TCWPM block. See \ref group_tcpwm_counter_clk_prescalers */
139     uint32_t    clockPrescaler;
140     uint32_t    runMode;            /**< Sets the run mode. See \ref group_tcpwm_counter_run_modes */
141     uint32_t    countDirection;     /**< Sets the counter direction. See \ref group_tcpwm_counter_direction */
142     /** The counter can either compare or capture a value. See \ref group_tcpwm_counter_compare_capture */
143     uint32_t    compareOrCapture;
144     uint32_t    compare0;           /**< Sets the value for Compare0*/
145     uint32_t    compare1;           /**< Sets the value for Compare1*/
146     bool        enableCompareSwap;  /**< If enabled, the compare values are swapped each time the comparison is true */
147     /** Enabled an interrupt on the terminal count, capture or compare. See \ref group_tcpwm_interrupt_sources */
148     uint32_t    interruptSources;
149     uint32_t    captureInputMode;   /**< Configures how the capture input behaves. See \ref group_tcpwm_input_modes */
150     /** Selects which input the capture uses, the inputs are device-specific. See \ref group_tcpwm_input_selection */
151     uint32_t    captureInput;
152     uint32_t    reloadInputMode;    /**< Configures how the reload input behaves. See \ref group_tcpwm_input_modes */
153     /** Selects which input the reload uses, the inputs are device-specific. See \ref group_tcpwm_input_selection */
154     uint32_t    reloadInput;
155     uint32_t    startInputMode;     /**< Configures how the start input behaves. See \ref group_tcpwm_input_modes */
156     /** Selects which input the start uses, the inputs are device-specific. See \ref group_tcpwm_input_selection */
157     uint32_t    startInput;
158     uint32_t    stopInputMode;      /**< Configures how the stop input behaves. See \ref group_tcpwm_input_modes */
159     /** Selects which input the stop uses, the inputs are device-specific. See \ref group_tcpwm_input_selection */
160     uint32_t    stopInput;
161     uint32_t    countInputMode;     /**< Configures how the count input behaves. See \ref group_tcpwm_input_modes */
162     uint32_t    countInput;         /**< Selects which input the count uses, the inputs are device-specific. See \ref group_tcpwm_input_selection */
163 #if (CY_IP_MXTCPWM_VERSION >= 2U) || defined (CY_DOXYGEN)
164     uint32_t    capture1InputMode;  /**< Configures how the capture1 input behaves. See \ref group_tcpwm_input_modes */
165     uint32_t    capture1Input;      /**< Selects which input the capture1 uses, the inputs are device-specific. */
166     /** See \ref group_tcpwm_input_selection */
167     bool        enableCompare1Swap; /**< If enabled, the compare1 values are swapped each time the comparison is true */
168     uint32_t    compare2;           /**< Sets the value for Compare1  */
169     uint32_t    compare3;           /**< Sets the value for the buffered Compare1 */
170     uint32_t    trigger0Event;      /**< Configures which internal event generates on output trigger 0*/
171     uint32_t    trigger1Event;      /**< Configures which internal event generates on output trigger 1*/
172 #endif /* (CY_IP_MXTCPWM_VERSION >= 2U) || defined (CY_DOXYGEN) */
173 #if (CY_IP_MXTCPWM_VERSION >= 3U) || defined (CY_DOXYGEN)
174     bool        buffer_swap_enable; /**< Configures swapping mechanism between CC0 and buffered CC0, CC1 and buffered CC1, PERIOD and buffered PERIOD, DT and buffered DT  */
175     cy_en_counter_direction_t direction_mode; /**< Counter direction mode */
176     bool        glitch_filter_enable;   /**< Enables Glitch filter for input triggers. */
177     cy_en_gf_depth_value_t gf_depth;    /**< Glitch filter depth value. */
178 #endif /* (CY_IP_MXTCPWM_VERSION >= 3U) || defined (CY_DOXYGEN) */
179 }cy_stc_tcpwm_counter_config_t;
180 /** \} group_tcpwm_data_structures_counter */
181 
182 /**
183 * \addtogroup group_tcpwm_macros_counter
184 * \{
185 * \defgroup group_tcpwm_counter_run_modes Counter Run Modes
186 * \{
187 * Run modes for the counter timer.
188 */
189 #define CY_TCPWM_COUNTER_ONESHOT                (1U)    /**< Counter runs once and then stops */
190 #define CY_TCPWM_COUNTER_CONTINUOUS             (0U)    /**< Counter runs forever */
191 /** \} group_tcpwm_counter_run_modes */
192 
193 /** \defgroup group_tcpwm_counter_direction Counter Direction
194 * The counter directions.
195 * \{
196 */
197 #define CY_TCPWM_COUNTER_COUNT_UP               (0U)    /**< Counter counts up */
198 #define CY_TCPWM_COUNTER_COUNT_DOWN             (1U)    /**< Counter counts down */
199 /** Counter counts up and down terminal count only occurs on underflow. */
200 #define CY_TCPWM_COUNTER_COUNT_UP_DOWN_1        (2U)
201 /** Counter counts up and down terminal count occurs on both overflow and underflow. */
202 #define CY_TCPWM_COUNTER_COUNT_UP_DOWN_2        (3U)
203 /** \} group_tcpwm_counter_direction */
204 
205 /** \defgroup group_tcpwm_counter_clk_prescalers Counter CLK Prescalers
206 * \{
207 * The clock prescaler values.
208 */
209 #define CY_TCPWM_COUNTER_PRESCALER_DIVBY_1      (0U) /**< Divide by 1 */
210 #define CY_TCPWM_COUNTER_PRESCALER_DIVBY_2      (1U) /**< Divide by 2 */
211 #define CY_TCPWM_COUNTER_PRESCALER_DIVBY_4      (2U) /**< Divide by 4 */
212 #define CY_TCPWM_COUNTER_PRESCALER_DIVBY_8      (3U) /**< Divide by 8 */
213 #define CY_TCPWM_COUNTER_PRESCALER_DIVBY_16     (4U) /**< Divide by 16 */
214 #define CY_TCPWM_COUNTER_PRESCALER_DIVBY_32     (5U) /**< Divide by 32 */
215 #define CY_TCPWM_COUNTER_PRESCALER_DIVBY_64     (6U) /**< Divide by 64 */
216 #define CY_TCPWM_COUNTER_PRESCALER_DIVBY_128    (7U) /**< Divide by 128 */
217 /** \} group_tcpwm_counter_clk_prescalers */
218 
219 /** \defgroup group_tcpwm_counter_compare_capture Counter Compare Capture
220 * \{
221 * A compare or capture mode.
222 */
223 #define CY_TCPWM_COUNTER_MODE_CAPTURE           (2U)  /**< Timer/Counter is in Capture Mode */
224 #define CY_TCPWM_COUNTER_MODE_COMPARE           (0U)  /**< Timer/Counter is in Compare Mode */
225 /** \} group_tcpwm_counter_compare_capture */
226 
227 /** \defgroup group_tcpwm_counter_status Counter Status
228 * \{
229 * The counter status.
230 */
231 #define CY_TCPWM_COUNTER_STATUS_DOWN_COUNTING   (0x1UL)        /**< Timer/Counter is down counting */
232 #define CY_TCPWM_COUNTER_STATUS_UP_COUNTING     (0x2UL)        /**< Timer/Counter is up counting */
233 
234 /** Timer/Counter is running */
235 #define CY_TCPWM_COUNTER_STATUS_COUNTER_RUNNING (0x80000000UL)
236 
237 /** \} group_tcpwm_counter_status */
238 /** \} group_tcpwm_macros_counter */
239 
240 
241 /*******************************************************************************
242 * Backward compatibility macro. The following code is DEPRECATED and must
243 * not be used in new projects
244 *******************************************************************************/
245 #define Cy_TCPWM_Counter_GetCapture         Cy_TCPWM_Counter_GetCapture0Val
246 #define Cy_TCPWM_Counter_GetCaptureBuf      Cy_TCPWM_Counter_GetCapture0BufVal
247 #define Cy_TCPWM_Counter_SetCompare0        Cy_TCPWM_Counter_SetCompare0Val
248 #define Cy_TCPWM_Counter_GetCompare0        Cy_TCPWM_Counter_GetCompare0Val
249 #define Cy_TCPWM_Counter_SetCompare1        Cy_TCPWM_Counter_SetCompare0BufVal
250 #define Cy_TCPWM_Counter_GetCompare1        Cy_TCPWM_Counter_GetCompare0BufVal
251 #define Cy_TCPWM_Counter_EnableCompareSwap  Cy_TCPWM_Counter_EnableCompare0Swap
252 
253 /*******************************************************************************
254 *        Function Prototypes
255 *******************************************************************************/
256 
257 /**
258 * \addtogroup group_tcpwm_functions_counter
259 * \{
260 */
261 cy_en_tcpwm_status_t Cy_TCPWM_Counter_Init(TCPWM_Type *base, uint32_t cntNum,
262                                            cy_stc_tcpwm_counter_config_t const *config);
263 void Cy_TCPWM_Counter_DeInit(TCPWM_Type *base, uint32_t cntNum, cy_stc_tcpwm_counter_config_t const *config);
264 __STATIC_INLINE void Cy_TCPWM_Counter_Enable(TCPWM_Type *base, uint32_t cntNum);
265 __STATIC_INLINE void Cy_TCPWM_Counter_Disable(TCPWM_Type *base, uint32_t cntNum);
266 __STATIC_INLINE uint32_t Cy_TCPWM_Counter_GetStatus(TCPWM_Type const *base, uint32_t cntNum);
267 __STATIC_INLINE uint32_t Cy_TCPWM_Counter_GetCapture0Val(TCPWM_Type const *base, uint32_t cntNum);
268 __STATIC_INLINE uint32_t Cy_TCPWM_Counter_GetCapture0BufVal(TCPWM_Type const *base, uint32_t cntNum);
269 __STATIC_INLINE void Cy_TCPWM_Counter_SetCompare0Val(TCPWM_Type *base, uint32_t cntNum, uint32_t compare0);
270 __STATIC_INLINE uint32_t Cy_TCPWM_Counter_GetCompare0Val(TCPWM_Type const *base, uint32_t cntNum);
271 __STATIC_INLINE void Cy_TCPWM_Counter_SetCompare0BufVal(TCPWM_Type *base, uint32_t cntNum, uint32_t compare1);
272 __STATIC_INLINE uint32_t Cy_TCPWM_Counter_GetCompare0BufVal(TCPWM_Type const *base, uint32_t cntNum);
273 __STATIC_INLINE void Cy_TCPWM_Counter_EnableCompare0Swap(TCPWM_Type *base, uint32_t cntNum, bool enable);
274 __STATIC_INLINE void Cy_TCPWM_Counter_SetCounter(TCPWM_Type *base, uint32_t cntNum, uint32_t count);
275 __STATIC_INLINE uint32_t Cy_TCPWM_Counter_GetCounter(TCPWM_Type const *base, uint32_t cntNum);
276 __STATIC_INLINE void Cy_TCPWM_Counter_SetPeriod(TCPWM_Type *base, uint32_t cntNum, uint32_t period);
277 __STATIC_INLINE uint32_t Cy_TCPWM_Counter_GetPeriod(TCPWM_Type const *base, uint32_t cntNum);
278 #if (CY_IP_MXTCPWM_VERSION >= 2U) || defined (CY_DOXYGEN)
279 __STATIC_INLINE uint32_t Cy_TCPWM_Counter_GetCapture1Val (TCPWM_Type const *base, uint32_t cntNum);
280 __STATIC_INLINE uint32_t Cy_TCPWM_Counter_GetCapture1BufVal (TCPWM_Type const *base, uint32_t cntNum);
281 __STATIC_INLINE uint32_t Cy_TCPWM_Counter_GetCompare1Val (TCPWM_Type const *base, uint32_t cntNum);
282 __STATIC_INLINE uint32_t Cy_TCPWM_Counter_GetCompare1BufVal (TCPWM_Type const *base, uint32_t cntNum);
283 __STATIC_INLINE void Cy_TCPWM_Counter_SetCompare1Val (TCPWM_Type *base, uint32_t cntNum, uint32_t compare1);
284 __STATIC_INLINE void Cy_TCPWM_Counter_SetCompare1BufVal (TCPWM_Type *base, uint32_t cntNum, uint32_t compareBuf1);
285 __STATIC_INLINE void Cy_TCPWM_Counter_EnableCompare1Swap(TCPWM_Type *base, uint32_t cntNum,  bool enable);
286 #endif
287 #if (CY_IP_MXTCPWM_VERSION >= 3U) || defined (CY_DOXYGEN)
288 __STATIC_INLINE void Cy_TCPWM_Counter_EnableSwap(TCPWM_Type *base, uint32_t cntNum,  bool enable);
289 __STATIC_INLINE void Cy_TCPWM_Counter_SetDirection_Change_Mode(TCPWM_Type *base, uint32_t cntNum,  cy_en_counter_direction_t direction_mode);
290 #endif /* (CY_IP_MXTCPWM_VERSION >= 3U) || defined (CY_DOXYGEN) */
291 
292 /*******************************************************************************
293 * Function Name: Cy_TCPWM_Counter_Enable
294 ****************************************************************************//**
295 *
296 * Enables the counter in the TCPWM block for the Counter operation.
297 *
298 * \param base
299 * The pointer to a TCPWM instance.
300 *
301 * \param cntNum
302 * The Counter instance number in the selected TCPWM.
303 *
304 * \funcusage
305 * \snippet tcpwm/counter/snippet/main.c snippet_Cy_TCPWM_V1_Counter_Init
306 * \snippet tcpwm/counter/snippet/main.c snippet_Cy_TCPWM_V2_Counter_Init
307 *
308 *******************************************************************************/
Cy_TCPWM_Counter_Enable(TCPWM_Type * base,uint32_t cntNum)309 __STATIC_INLINE void Cy_TCPWM_Counter_Enable(TCPWM_Type *base, uint32_t cntNum)
310 {
311     Cy_TCPWM_Enable_Single(base, cntNum);
312 }
313 
314 
315 /*******************************************************************************
316 * Function Name: Cy_TCPWM_Counter_Disable
317 ****************************************************************************//**
318 *
319 * Disables the counter in the TCPWM block.
320 *
321 * \param base
322 * The pointer to a TCPWM instance.
323 *
324 * \param cntNum
325 * The Counter instance number in the selected TCPWM.
326 *
327 * \funcusage
328 * \snippet tcpwm/counter/snippet/main.c snippet_Cy_TCPWM_Counter_DeInit
329 *
330 *******************************************************************************/
Cy_TCPWM_Counter_Disable(TCPWM_Type * base,uint32_t cntNum)331 __STATIC_INLINE void Cy_TCPWM_Counter_Disable(TCPWM_Type *base, uint32_t cntNum)
332 {
333     Cy_TCPWM_Disable_Single(base, cntNum);
334 }
335 
336 
337 /*******************************************************************************
338 * Function Name: Cy_TCPWM_Counter_GetStatus
339 ****************************************************************************//**
340 *
341 * Returns the status of the Counter Timer whether it is running or not. In case the
342 * Counter is running, status will also provide information on counting up/down. This
343 * is useful when the counter mode is set to UP_DOWN_1 or UP_DOWN_2.
344 *
345 * \param base
346 * The pointer to a TCPWM instance.
347 *
348 * \param cntNum
349 * The Counter instance number in the selected TCPWM.
350 *
351 * \return
352 * The status. See \ref group_tcpwm_counter_status
353 *
354 * \funcusage
355 * \snippet tcpwm/counter/snippet/main.c snippet_Cy_TCPWM_Counter_GetStatus
356 *
357 *******************************************************************************/
Cy_TCPWM_Counter_GetStatus(TCPWM_Type const * base,uint32_t cntNum)358 __STATIC_INLINE uint32_t Cy_TCPWM_Counter_GetStatus(TCPWM_Type const  *base, uint32_t cntNum)
359 {
360     uint32_t status;
361 
362 #if (CY_IP_MXTCPWM_VERSION == 1U)
363 
364         status = TCPWM_CNT_STATUS(base, cntNum);
365 
366         /* Generates proper up counting status. Is not generated by HW */
367         status &= ~CY_TCPWM_COUNTER_STATUS_UP_COUNTING;
368         status |= ((~status & CY_TCPWM_COUNTER_STATUS_DOWN_COUNTING & (status >> TCPWM_CNT_STATUS_RUNNING_Pos)) <<
369                CY_TCPWM_CNT_STATUS_UP_POS);
370 #else
371         status = TCPWM_GRP_CNT_STATUS(base, TCPWM_GRP_CNT_GET_GRP(cntNum), cntNum);
372 
373         /* Generates proper up counting status. Is not generated by HW */
374         status &= ~CY_TCPWM_COUNTER_STATUS_UP_COUNTING;
375         status |= ((~status & CY_TCPWM_COUNTER_STATUS_DOWN_COUNTING & (status >> TCPWM_GRP_CNT_V2_STATUS_RUNNING_Pos)) <<
376                CY_TCPWM_CNT_STATUS_UP_POS);
377 
378         /* For backward compatibility, we set TCPWM_CNT_STATUS_RUNNING_Pos with TCPWM_GRP_CNT_V2_STATUS_RUNNING */
379         status |= (_FLD2VAL(TCPWM_GRP_CNT_V2_STATUS_RUNNING, status) << TCPWM_CNT_STATUS_RUNNING_Pos);
380 #endif
381 
382     return(status);
383 }
384 
385 
386 /*******************************************************************************
387 * Function Name: Cy_TCPWM_Counter_GetCapture0Val
388 ****************************************************************************//**
389 *
390 * Returns the capture 0 value when the capture mode is enabled.
391 *
392 * \param base
393 * The pointer to a TCPWM instance.
394 *
395 * \param cntNum
396 * The Counter instance number in the selected TCPWM.
397 *
398 * \return
399 * The capture 0 value.
400 *
401 * \funcusage
402 * \snippet tcpwm/counter/snippet/main.c snippet_Cy_TCPWM_Counter_Capture
403 *
404 *******************************************************************************/
Cy_TCPWM_Counter_GetCapture0Val(TCPWM_Type const * base,uint32_t cntNum)405 __STATIC_INLINE uint32_t Cy_TCPWM_Counter_GetCapture0Val(TCPWM_Type const  *base, uint32_t cntNum)
406 {
407     return Cy_TCPWM_Block_GetCC0Val(base, cntNum);
408 }
409 
410 
411 /*******************************************************************************
412 * Function Name: Cy_TCPWM_Counter_GetCapture0BufVal
413 ****************************************************************************//**
414 *
415 * Returns the buffered capture 0 value when the capture mode is enabled.
416 *
417 * \param base
418 * The pointer to a TCPWM instance.
419 *
420 * \param cntNum
421 * The Counter instance number in the selected TCPWM.
422 *
423 * \return
424 * The buffered capture 0 value.
425 *
426 * \funcusage
427 * \snippet tcpwm/counter/snippet/main.c snippet_Cy_TCPWM_Counter_Capture
428 *
429 *******************************************************************************/
Cy_TCPWM_Counter_GetCapture0BufVal(TCPWM_Type const * base,uint32_t cntNum)430 __STATIC_INLINE uint32_t Cy_TCPWM_Counter_GetCapture0BufVal(TCPWM_Type const  *base, uint32_t cntNum)
431 {
432     return Cy_TCPWM_Block_GetCC0BufVal(base, cntNum);
433 }
434 
435 
436 /*******************************************************************************
437 * Function Name: Cy_TCPWM_Counter_SetCompare0Val
438 ****************************************************************************//**
439 *
440 * Sets the compare value for Compare0 when the compare mode is enabled.
441 *
442 * \param base
443 * The pointer to a TCPWM instance.
444 *
445 * \param cntNum
446 * The Counter instance number in the selected TCPWM.
447 *
448 * \param compare0
449 * The Compare0 value.
450 *
451 * \funcusage
452 * \snippet tcpwm/counter/snippet/main.c snippet_Cy_TCPWM_Counter_SetCompare0Val
453 *
454 *******************************************************************************/
Cy_TCPWM_Counter_SetCompare0Val(TCPWM_Type * base,uint32_t cntNum,uint32_t compare0)455 __STATIC_INLINE void Cy_TCPWM_Counter_SetCompare0Val(TCPWM_Type *base, uint32_t cntNum,  uint32_t compare0)
456 {
457     Cy_TCPWM_Block_SetCC0Val(base, cntNum, compare0);
458 }
459 
460 
461 /*******************************************************************************
462 * Function Name: Cy_TCPWM_Counter_GetCompare0Val
463 ****************************************************************************//**
464 *
465 * Returns compare 0 value.
466 *
467 * \param base
468 * The pointer to a TCPWM instance.
469 *
470 * \param cntNum
471 * The Counter instance number in the selected TCPWM.
472 *
473 * \return
474 * Compare 0 value.
475 *
476 * \funcusage
477 * \snippet tcpwm/counter/snippet/main.c snippet_Cy_TCPWM_Counter_SetCompare0Val
478 *
479 *******************************************************************************/
Cy_TCPWM_Counter_GetCompare0Val(TCPWM_Type const * base,uint32_t cntNum)480 __STATIC_INLINE uint32_t Cy_TCPWM_Counter_GetCompare0Val(TCPWM_Type const  *base, uint32_t cntNum)
481 {
482     return Cy_TCPWM_Block_GetCC0Val(base, cntNum);
483 }
484 
485 
486 /*******************************************************************************
487 * Function Name: Cy_TCPWM_Counter_SetCompare0BufVal
488 ****************************************************************************//**
489 *
490 * Sets the compare value for Compare1 when the compare mode is enabled.
491 *
492 * \param base
493 * The pointer to a TCPWM instance.
494 *
495 * \param cntNum
496 * The Counter instance number in the selected TCPWM.
497 *
498 * \param compare1
499 * The Compare1 value.
500 *
501 * \funcusage
502 * \snippet tcpwm/counter/snippet/main.c snippet_Cy_TCPWM_Counter_SetCompare0BufVal
503 *
504 *******************************************************************************/
Cy_TCPWM_Counter_SetCompare0BufVal(TCPWM_Type * base,uint32_t cntNum,uint32_t compare1)505 __STATIC_INLINE void Cy_TCPWM_Counter_SetCompare0BufVal(TCPWM_Type *base, uint32_t cntNum,  uint32_t compare1)
506 {
507     Cy_TCPWM_Block_SetCC0BufVal(base, cntNum, compare1);
508 }
509 
510 
511 /*******************************************************************************
512 * Function Name: Cy_TCPWM_Counter_GetCompare0BufVal
513 ****************************************************************************//**
514 *
515 * Returns the buffered compare 0 value.
516 *
517 * \param base
518 * The pointer to a TCPWM instance.
519 *
520 * \param cntNum
521 * The Counter instance number in the selected TCPWM.
522 *
523 * \return
524 * Buffered Compare 0 value.
525 *
526 * \funcusage
527 * \snippet tcpwm/counter/snippet/main.c snippet_Cy_TCPWM_Counter_SetCompare0BufVal
528 *
529 *******************************************************************************/
Cy_TCPWM_Counter_GetCompare0BufVal(TCPWM_Type const * base,uint32_t cntNum)530 __STATIC_INLINE uint32_t Cy_TCPWM_Counter_GetCompare0BufVal(TCPWM_Type const  *base, uint32_t cntNum)
531 {
532     return Cy_TCPWM_Block_GetCC0BufVal(base, cntNum);
533 }
534 
535 
536 /*******************************************************************************
537 * Function Name: Cy_TCPWM_Counter_EnableCompare0Swap
538 ****************************************************************************//**
539 *
540 * Enables the comparison swap when the comparison value is true.
541 *
542 * \param base
543 * The pointer to a TCPWM instance.
544 *
545 * \param cntNum
546 * The Counter instance number in the selected TCPWM.
547 *
548 * \param enable
549 * true = swap enabled, false = swap disabled
550 *
551 * \funcusage
552 * \snippet tcpwm/counter/snippet/main.c snippet_Cy_TCPWM_Counter_EnableCompare0Swap
553 *
554 * \note From Version 3 of TCPWM, this feature is coupled with the swap enable feature (Cy_TCPWM_Counter_EnableSwap()).
555 * when both reload and swap are enabled then CC0 value is swapped with CC0 buff value.
556 * When only reload is enabled then CC0 buff value is copied to CC0.
557 * There is no action when reload is disabled.
558 *
559 *******************************************************************************/
Cy_TCPWM_Counter_EnableCompare0Swap(TCPWM_Type * base,uint32_t cntNum,bool enable)560 __STATIC_INLINE void Cy_TCPWM_Counter_EnableCompare0Swap(TCPWM_Type *base, uint32_t cntNum,  bool enable)
561 {
562     Cy_TCPWM_Block_EnableCompare0Swap(base, cntNum, enable);
563 }
564 
565 
566 /*******************************************************************************
567 * Function Name: Cy_TCPWM_Counter_SetCounter
568 ****************************************************************************//**
569 *
570 * Sets the value of the counter.
571 *
572 * \param base
573 * The pointer to a TCPWM instance.
574 *
575 * \param cntNum
576 * The Counter instance number in the selected TCPWM.
577 *
578 * \param count
579 * The value to write into the counter.
580 *
581 * \funcusage
582 * \snippet tcpwm/counter/snippet/main.c snippet_Cy_TCPWM_Counter_SetCounter
583 *
584 *******************************************************************************/
Cy_TCPWM_Counter_SetCounter(TCPWM_Type * base,uint32_t cntNum,uint32_t count)585 __STATIC_INLINE void Cy_TCPWM_Counter_SetCounter(TCPWM_Type *base, uint32_t cntNum, uint32_t count)
586 {
587     Cy_TCPWM_Block_SetCounter(base, cntNum, count);
588 }
589 
590 
591 /*******************************************************************************
592 * Function Name: Cy_TCPWM_Counter_GetCounter
593 ****************************************************************************//**
594 *
595 * Returns the value in the counter.
596 *
597 * \param base
598 * The pointer to a TCPWM instance.
599 *
600 * \param cntNum
601 * The Counter instance number in the selected TCPWM.
602 *
603 * \return
604 * The current counter value.
605 *
606 * \funcusage
607 * \snippet tcpwm/counter/snippet/main.c snippet_Cy_TCPWM_Counter_GetCounter
608 *
609 *******************************************************************************/
Cy_TCPWM_Counter_GetCounter(TCPWM_Type const * base,uint32_t cntNum)610 __STATIC_INLINE uint32_t Cy_TCPWM_Counter_GetCounter(TCPWM_Type const  *base, uint32_t cntNum)
611 {
612     return Cy_TCPWM_Block_GetCounter(base, cntNum);
613 }
614 
615 
616 /*******************************************************************************
617 * Function Name: Cy_TCPWM_Counter_SetPeriod
618 ****************************************************************************//**
619 *
620 * Sets the value of the period register.
621 *
622 * \param base
623 * The pointer to a TCPWM instance.
624 *
625 * \param cntNum
626 * The Counter instance number in the selected TCPWM.
627 *
628 * \param period
629 * The value to write into a period.
630 *
631 * \funcusage
632 * \snippet tcpwm/counter/snippet/main.c snippet_Cy_TCPWM_Counter_SetPeriod
633 *
634 *******************************************************************************/
Cy_TCPWM_Counter_SetPeriod(TCPWM_Type * base,uint32_t cntNum,uint32_t period)635 __STATIC_INLINE void Cy_TCPWM_Counter_SetPeriod(TCPWM_Type *base, uint32_t cntNum,  uint32_t period)
636 {
637     Cy_TCPWM_Block_SetPeriod(base, cntNum, period);
638 }
639 
640 
641 /*******************************************************************************
642 * Function Name: Cy_TCPWM_Counter_GetPeriod
643 ****************************************************************************//**
644 *
645 * Returns the value in the period register.
646 *
647 * \param base
648 * The pointer to a TCPWM instance.
649 *
650 * \param cntNum
651 * The Counter instance number in the selected TCPWM.
652 *
653 * \return
654 * The current period value.
655 *
656 * \funcusage
657 * \snippet tcpwm/counter/snippet/main.c snippet_Cy_TCPWM_Counter_SetPeriod
658 *
659 *******************************************************************************/
Cy_TCPWM_Counter_GetPeriod(TCPWM_Type const * base,uint32_t cntNum)660 __STATIC_INLINE uint32_t Cy_TCPWM_Counter_GetPeriod(TCPWM_Type const *base, uint32_t cntNum)
661 {
662     return Cy_TCPWM_Block_GetPeriod(base, cntNum);
663 }
664 
665 #if (CY_IP_MXTCPWM_VERSION >= 2U) || defined (CY_DOXYGEN)
666 /*******************************************************************************
667 * Function Name: Cy_TCPWM_Counter_SetCompare1Val
668 ****************************************************************************//**
669 *
670 * Sets the compare value for Compare1 when the compare mode enabled.
671 *
672 * \param base
673 * The pointer to a TCPWM instance.
674 *
675 * \param cntNum
676 * The Counter instance number in the selected TCPWM.
677 *
678 * \param compare1
679 * The Compare1 value.
680 *
681 * \funcusage
682 * \snippet tcpwm/counter/snippet/main.c snippet_Cy_TCPWM_Counter_SetCompare1BufVal
683 *
684 *******************************************************************************/
Cy_TCPWM_Counter_SetCompare1Val(TCPWM_Type * base,uint32_t cntNum,uint32_t compare1)685 __STATIC_INLINE void Cy_TCPWM_Counter_SetCompare1Val(TCPWM_Type *base, uint32_t cntNum,  uint32_t compare1)
686 {
687     Cy_TCPWM_Block_SetCC1Val(base, cntNum, compare1);
688 }
689 
690 
691 /*******************************************************************************
692 * Function Name: Cy_TCPWM_Counter_GetCompare1Val
693 ****************************************************************************//**
694 *
695 * Returns compare 1 value.
696 *
697 * \param base
698 * The pointer to a TCPWM instance.
699 *
700 * \param cntNum
701 * The Counter instance number in the selected TCPWM.
702 *
703 * \return
704 * Compare 1 value.
705 *
706 * \funcusage
707 * \snippet tcpwm/counter/snippet/main.c snippet_Cy_TCPWM_Counter_SetCompare1BufVal
708 *
709 *******************************************************************************/
Cy_TCPWM_Counter_GetCompare1Val(TCPWM_Type const * base,uint32_t cntNum)710 __STATIC_INLINE uint32_t Cy_TCPWM_Counter_GetCompare1Val(TCPWM_Type const *base, uint32_t cntNum)
711 {
712     return Cy_TCPWM_Block_GetCC1Val(base, cntNum);
713 }
714 
715 
716 /*******************************************************************************
717 * Function Name: Cy_TCPWM_Counter_SetCompare1BufVal
718 ****************************************************************************//**
719 *
720 * Sets the buffered compare value for Compare1 when the compare mode enabled.
721 *
722 * \param base
723 * The pointer to a TCPWM instance.
724 *
725 * \param cntNum
726 * The Counter instance number in the selected TCPWM.
727 *
728 * \param compareBuf1
729 * The buffered Compare1 value.
730 *
731 * \funcusage
732 * \snippet tcpwm/counter/snippet/main.c snippet_Cy_TCPWM_Counter_SetCompare1BufVal
733 *
734 *******************************************************************************/
Cy_TCPWM_Counter_SetCompare1BufVal(TCPWM_Type * base,uint32_t cntNum,uint32_t compareBuf1)735 __STATIC_INLINE void Cy_TCPWM_Counter_SetCompare1BufVal(TCPWM_Type *base, uint32_t cntNum,  uint32_t compareBuf1)
736 {
737     Cy_TCPWM_Block_SetCC1BufVal(base, cntNum, compareBuf1);
738 }
739 
740 
741 /*******************************************************************************
742 * Function Name: Cy_TCPWM_Counter_GetCompare1BufVal
743 ****************************************************************************//**
744 *
745 * Returns the buffered compare1 value.
746 *
747 * \param base
748 * The pointer to a TCPWM instance.
749 *
750 * \param cntNum
751 * The Counter instance number in the selected TCPWM.
752 *
753 * \return
754 * Buffered compare1 value.
755 *
756 * \funcusage
757 * \snippet tcpwm/counter/snippet/main.c snippet_Cy_TCPWM_Counter_SetCompare1BufVal
758 *
759 *******************************************************************************/
Cy_TCPWM_Counter_GetCompare1BufVal(TCPWM_Type const * base,uint32_t cntNum)760 __STATIC_INLINE uint32_t Cy_TCPWM_Counter_GetCompare1BufVal(TCPWM_Type const *base, uint32_t cntNum)
761 {
762     return Cy_TCPWM_Block_GetCC1BufVal(base, cntNum);
763 }
764 
765 /*******************************************************************************
766 * Function Name: Cy_TCPWM_Counter_GetCapture1Val
767 ****************************************************************************//**
768 *
769 * Returns capture 1 value when capture mode is enabled
770 *
771 * \param base
772 * The pointer to a TCPWM instance.
773 *
774 * \param cntNum
775 * The Counter instance number in the selected TCPWM.
776 *
777 * \return
778 * Capture 1 value.
779 *
780 *******************************************************************************/
Cy_TCPWM_Counter_GetCapture1Val(TCPWM_Type const * base,uint32_t cntNum)781 __STATIC_INLINE uint32_t Cy_TCPWM_Counter_GetCapture1Val (TCPWM_Type const *base, uint32_t cntNum)
782 {
783     return Cy_TCPWM_Block_GetCC1Val(base, cntNum);
784 }
785 
786 /*******************************************************************************
787 * Function Name: Cy_TCPWM_Counter_GetCapture1BufVal
788 ****************************************************************************//**
789 *
790 * Returns the buffered capture1 value when capture mode is enabled.
791 *
792 * \param base
793 * The pointer to a TCPWM instance.
794 *
795 * \param cntNum
796 * The Counter instance number in the selected TCPWM.
797 *
798 * \return
799 * Buffered capture1 value.
800 *
801 *******************************************************************************/
Cy_TCPWM_Counter_GetCapture1BufVal(TCPWM_Type const * base,uint32_t cntNum)802 __STATIC_INLINE uint32_t Cy_TCPWM_Counter_GetCapture1BufVal (TCPWM_Type const *base, uint32_t cntNum)
803 {
804     return Cy_TCPWM_Block_GetCC1BufVal(base, cntNum);
805 }
806 
807 /*******************************************************************************
808 * Function Name: Cy_TCPWM_Counter_EnableCompare1Swap
809 ****************************************************************************//**
810 *
811 * Enables the comparison swap of compare1 and compareBuf1 when the comparison
812 * value is true
813 *
814 * \param base
815 * The pointer to a TCPWM instance.
816 *
817 * \param cntNum
818 * The Counter instance number in the selected TCPWM.
819 *
820 * \param enable
821 * true = swap enabled; false = swap disabled
822 *
823 * \funcusage
824 * \snippet tcpwm/counter/snippet/main.c snippet_Cy_TCPWM_Counter_EnableCompare1Swap
825 *
826 * \note From Version 3 of TCPWM, this feature is coupled with the swap enable feature (Cy_TCPWM_Counter_EnableSwap()).
827 * when both reload and swap are enabled then CC1 value is swapped with CC1 buff value.
828 * When only reload is enabled then CC1 buff value is copied to CC1.
829 * There is no action when reload is disabled.
830 *
831 *******************************************************************************/
Cy_TCPWM_Counter_EnableCompare1Swap(TCPWM_Type * base,uint32_t cntNum,bool enable)832 __STATIC_INLINE void Cy_TCPWM_Counter_EnableCompare1Swap(TCPWM_Type *base, uint32_t cntNum,  bool enable)
833 {
834     Cy_TCPWM_Block_EnableCompare1Swap(base, cntNum, enable);
835 }
836 #endif
837 #if (CY_IP_MXTCPWM_VERSION >= 3U) || defined (CY_DOXYGEN)
838 /*******************************************************************************
839 * Function Name: Cy_TCPWM_Counter_EnableSwap
840 ****************************************************************************//**
841 *
842 * Enables/disables swapping mechanism between CC0 and buffered CC0, CC1 and buffered CC1, PERIOD and buffered PERIOD, DT and buffered DT.
843 *
844 * \param base
845 * The pointer to a TCPWM instance.
846 *
847 * \param cntNum
848 * The Counter instance number in the selected TCPWM.
849 *
850 * \param enable
851 * true = swap enabled; false = swap disabled
852 *
853 * \note This feature is coupled with the reload feature.
854 * when both reload and swap are enabled then CC0/CC1/PERIOD/DT values are swapped with CC_BUFF/CC1_BUFF/PERIOD_BUFF/DT_BUFF values respectively
855 * When only reload is enabled then CC_BUFF/CC1_BUFF/PERIOD_BUFF/DT_BUFF values are copied to CC0/CC1/PERIOD/DT respectively.
856 * There is no action when reload is disabled.
857 *
858 *******************************************************************************/
Cy_TCPWM_Counter_EnableSwap(TCPWM_Type * base,uint32_t cntNum,bool enable)859 __STATIC_INLINE void Cy_TCPWM_Counter_EnableSwap(TCPWM_Type *base, uint32_t cntNum,  bool enable)
860 {
861     Cy_TCPWM_Block_EnableSwap(base, cntNum, enable);
862 }
863 
864 /*******************************************************************************
865 * Function Name: Cy_TCPWM_Counter_SetDirection_Change_Mode
866 ****************************************************************************//**
867 *
868 * Direction change mode Based on falling/rising edge of capture0 input.
869 *
870 * \param base
871 * The pointer to a TCPWM instance.
872 *
873 * \param cntNum
874 * The Counter instance number in the selected TCPWM.
875 *
876 * \param direction_mode
877 * Direction change mode Based on falling/rising edge of capture0 input \ref cy_en_counter_direction_t
878 *
879 * \note For TCPWM version 3 and above in compare mode, when external direction control is enabled and Capture0 input is disabled,
880 *       user can use software capture0 trigger. While using this, User has to make sure that the
881 *       external direction control is set to CY_TCPWM_COUNTER_DIRECTION_RISING
882 *
883 *******************************************************************************/
Cy_TCPWM_Counter_SetDirection_Change_Mode(TCPWM_Type * base,uint32_t cntNum,cy_en_counter_direction_t direction_mode)884 __STATIC_INLINE void Cy_TCPWM_Counter_SetDirection_Change_Mode(TCPWM_Type *base, uint32_t cntNum,  cy_en_counter_direction_t direction_mode)
885 {
886     uint32_t grp = TCPWM_GRP_CNT_GET_GRP(cntNum);
887 
888     TCPWM_GRP_CNT_CTRL(base, grp, cntNum) &= ~TCPWM_GRP_CNT_CTRL_QUAD_ENCODING_MODE_Msk;
889     TCPWM_GRP_CNT_CTRL(base, grp, cntNum) |= (_VAL2FLD(TCPWM_GRP_CNT_CTRL_QUAD_ENCODING_MODE, direction_mode));
890 }
891 #endif /* (CY_IP_MXTCPWM_VERSION >= 3U) */
892 /** \} group_tcpwm_functions_counter */
893 
894 /** \} group_tcpwm_counter */
895 
896 #if defined(__cplusplus)
897 }
898 #endif
899 
900 #endif /* CY_IP_MXTCPWM */
901 
902 #endif /* CY_TCPWM_COUNTER_H */
903 
904 /* [] END OF FILE */
905