1 /***************************************************************************//**
2 * \file cy_tcpwm_counter.h
3 * \version 1.60
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
177 #endif /* (CY_IP_MXTCPWM_VERSION >= 3U) || defined (CY_DOXYGEN) */
178 }cy_stc_tcpwm_counter_config_t;
179 /** \} group_tcpwm_data_structures_counter */
180
181 /**
182 * \addtogroup group_tcpwm_macros_counter
183 * \{
184 * \defgroup group_tcpwm_counter_run_modes Counter Run Modes
185 * \{
186 * Run modes for the counter timer.
187 */
188 #define CY_TCPWM_COUNTER_ONESHOT (1U) /**< Counter runs once and then stops */
189 #define CY_TCPWM_COUNTER_CONTINUOUS (0U) /**< Counter runs forever */
190 /** \} group_tcpwm_counter_run_modes */
191
192 /** \defgroup group_tcpwm_counter_direction Counter Direction
193 * The counter directions.
194 * \{
195 */
196 #define CY_TCPWM_COUNTER_COUNT_UP (0U) /**< Counter counts up */
197 #define CY_TCPWM_COUNTER_COUNT_DOWN (1U) /**< Counter counts down */
198 /** Counter counts up and down terminal count only occurs on underflow. */
199 #define CY_TCPWM_COUNTER_COUNT_UP_DOWN_1 (2U)
200 /** Counter counts up and down terminal count occurs on both overflow and underflow. */
201 #define CY_TCPWM_COUNTER_COUNT_UP_DOWN_2 (3U)
202 /** \} group_tcpwm_counter_direction */
203
204 /** \defgroup group_tcpwm_counter_clk_prescalers Counter CLK Prescalers
205 * \{
206 * The clock prescaler values.
207 */
208 #define CY_TCPWM_COUNTER_PRESCALER_DIVBY_1 (0U) /**< Divide by 1 */
209 #define CY_TCPWM_COUNTER_PRESCALER_DIVBY_2 (1U) /**< Divide by 2 */
210 #define CY_TCPWM_COUNTER_PRESCALER_DIVBY_4 (2U) /**< Divide by 4 */
211 #define CY_TCPWM_COUNTER_PRESCALER_DIVBY_8 (3U) /**< Divide by 8 */
212 #define CY_TCPWM_COUNTER_PRESCALER_DIVBY_16 (4U) /**< Divide by 16 */
213 #define CY_TCPWM_COUNTER_PRESCALER_DIVBY_32 (5U) /**< Divide by 32 */
214 #define CY_TCPWM_COUNTER_PRESCALER_DIVBY_64 (6U) /**< Divide by 64 */
215 #define CY_TCPWM_COUNTER_PRESCALER_DIVBY_128 (7U) /**< Divide by 128 */
216 /** \} group_tcpwm_counter_clk_prescalers */
217
218 /** \defgroup group_tcpwm_counter_compare_capture Counter Compare Capture
219 * \{
220 * A compare or capture mode.
221 */
222 #define CY_TCPWM_COUNTER_MODE_CAPTURE (2U) /**< Timer/Counter is in Capture Mode */
223 #define CY_TCPWM_COUNTER_MODE_COMPARE (0U) /**< Timer/Counter is in Compare Mode */
224 /** \} group_tcpwm_counter_compare_capture */
225
226 /** \defgroup group_tcpwm_counter_status Counter Status
227 * \{
228 * The counter status.
229 */
230 #define CY_TCPWM_COUNTER_STATUS_DOWN_COUNTING (0x1UL) /**< Timer/Counter is down counting */
231 #define CY_TCPWM_COUNTER_STATUS_UP_COUNTING (0x2UL) /**< Timer/Counter is up counting */
232
233 /** Timer/Counter is running */
234 #define CY_TCPWM_COUNTER_STATUS_COUNTER_RUNNING (0x80000000UL)
235
236 /** \} group_tcpwm_counter_status */
237 /** \} group_tcpwm_macros_counter */
238
239
240 /*******************************************************************************
241 * Backward compatibility macro. The following code is DEPRECATED and must
242 * not be used in new projects
243 *******************************************************************************/
244 #define Cy_TCPWM_Counter_GetCapture Cy_TCPWM_Counter_GetCapture0Val
245 #define Cy_TCPWM_Counter_GetCaptureBuf Cy_TCPWM_Counter_GetCapture0BufVal
246 #define Cy_TCPWM_Counter_SetCompare0 Cy_TCPWM_Counter_SetCompare0Val
247 #define Cy_TCPWM_Counter_GetCompare0 Cy_TCPWM_Counter_GetCompare0Val
248 #define Cy_TCPWM_Counter_SetCompare1 Cy_TCPWM_Counter_SetCompare0BufVal
249 #define Cy_TCPWM_Counter_GetCompare1 Cy_TCPWM_Counter_GetCompare0BufVal
250 #define Cy_TCPWM_Counter_EnableCompareSwap Cy_TCPWM_Counter_EnableCompare0Swap
251
252 /*******************************************************************************
253 * Function Prototypes
254 *******************************************************************************/
255
256 /**
257 * \addtogroup group_tcpwm_functions_counter
258 * \{
259 */
260 cy_en_tcpwm_status_t Cy_TCPWM_Counter_Init(TCPWM_Type *base, uint32_t cntNum,
261 cy_stc_tcpwm_counter_config_t const *config);
262 void Cy_TCPWM_Counter_DeInit(TCPWM_Type *base, uint32_t cntNum, cy_stc_tcpwm_counter_config_t const *config);
263 __STATIC_INLINE void Cy_TCPWM_Counter_Enable(TCPWM_Type *base, uint32_t cntNum);
264 __STATIC_INLINE void Cy_TCPWM_Counter_Disable(TCPWM_Type *base, uint32_t cntNum);
265 __STATIC_INLINE uint32_t Cy_TCPWM_Counter_GetStatus(TCPWM_Type const *base, uint32_t cntNum);
266 __STATIC_INLINE uint32_t Cy_TCPWM_Counter_GetCapture0Val(TCPWM_Type const *base, uint32_t cntNum);
267 __STATIC_INLINE uint32_t Cy_TCPWM_Counter_GetCapture0BufVal(TCPWM_Type const *base, uint32_t cntNum);
268 __STATIC_INLINE void Cy_TCPWM_Counter_SetCompare0Val(TCPWM_Type *base, uint32_t cntNum, uint32_t compare0);
269 __STATIC_INLINE uint32_t Cy_TCPWM_Counter_GetCompare0Val(TCPWM_Type const *base, uint32_t cntNum);
270 __STATIC_INLINE void Cy_TCPWM_Counter_SetCompare0BufVal(TCPWM_Type *base, uint32_t cntNum, uint32_t compare1);
271 __STATIC_INLINE uint32_t Cy_TCPWM_Counter_GetCompare0BufVal(TCPWM_Type const *base, uint32_t cntNum);
272 __STATIC_INLINE void Cy_TCPWM_Counter_EnableCompare0Swap(TCPWM_Type *base, uint32_t cntNum, bool enable);
273 __STATIC_INLINE void Cy_TCPWM_Counter_SetCounter(TCPWM_Type *base, uint32_t cntNum, uint32_t count);
274 __STATIC_INLINE uint32_t Cy_TCPWM_Counter_GetCounter(TCPWM_Type const *base, uint32_t cntNum);
275 __STATIC_INLINE void Cy_TCPWM_Counter_SetPeriod(TCPWM_Type *base, uint32_t cntNum, uint32_t period);
276 __STATIC_INLINE uint32_t Cy_TCPWM_Counter_GetPeriod(TCPWM_Type const *base, uint32_t cntNum);
277 #if (CY_IP_MXTCPWM_VERSION >= 2U) || defined (CY_DOXYGEN)
278 __STATIC_INLINE uint32_t Cy_TCPWM_Counter_GetCapture1Val (TCPWM_Type const *base, uint32_t cntNum);
279 __STATIC_INLINE uint32_t Cy_TCPWM_Counter_GetCapture1BufVal (TCPWM_Type const *base, uint32_t cntNum);
280 __STATIC_INLINE uint32_t Cy_TCPWM_Counter_GetCompare1Val (TCPWM_Type const *base, uint32_t cntNum);
281 __STATIC_INLINE uint32_t Cy_TCPWM_Counter_GetCompare1BufVal (TCPWM_Type const *base, uint32_t cntNum);
282 __STATIC_INLINE void Cy_TCPWM_Counter_SetCompare1Val (TCPWM_Type *base, uint32_t cntNum, uint32_t compare1);
283 __STATIC_INLINE void Cy_TCPWM_Counter_SetCompare1BufVal (TCPWM_Type *base, uint32_t cntNum, uint32_t compareBuf1);
284 __STATIC_INLINE void Cy_TCPWM_Counter_EnableCompare1Swap(TCPWM_Type *base, uint32_t cntNum, bool enable);
285 #endif
286 #if (CY_IP_MXTCPWM_VERSION >= 3U) || defined (CY_DOXYGEN)
287 __STATIC_INLINE void Cy_TCPWM_Counter_EnableSwap(TCPWM_Type *base, uint32_t cntNum, bool enable);
288 #endif /* (CY_IP_MXTCPWM_VERSION >= 3U) || defined (CY_DOXYGEN) */
289
290 /*******************************************************************************
291 * Function Name: Cy_TCPWM_Counter_Enable
292 ****************************************************************************//**
293 *
294 * Enables the counter in the TCPWM block for the Counter operation.
295 *
296 * \param base
297 * The pointer to a TCPWM instance.
298 *
299 * \param cntNum
300 * The Counter instance number in the selected TCPWM.
301 *
302 * \funcusage
303 * \snippet tcpwm/counter/snippet/main.c snippet_Cy_TCPWM_V1_Counter_Init
304 * \snippet tcpwm/counter/snippet/main.c snippet_Cy_TCPWM_V2_Counter_Init
305 *
306 *******************************************************************************/
Cy_TCPWM_Counter_Enable(TCPWM_Type * base,uint32_t cntNum)307 __STATIC_INLINE void Cy_TCPWM_Counter_Enable(TCPWM_Type *base, uint32_t cntNum)
308 {
309 Cy_TCPWM_Enable_Single(base, cntNum);
310 }
311
312
313 /*******************************************************************************
314 * Function Name: Cy_TCPWM_Counter_Disable
315 ****************************************************************************//**
316 *
317 * Disables the counter in the TCPWM block.
318 *
319 * \param base
320 * The pointer to a TCPWM instance.
321 *
322 * \param cntNum
323 * The Counter instance number in the selected TCPWM.
324 *
325 * \funcusage
326 * \snippet tcpwm/counter/snippet/main.c snippet_Cy_TCPWM_Counter_DeInit
327 *
328 *******************************************************************************/
Cy_TCPWM_Counter_Disable(TCPWM_Type * base,uint32_t cntNum)329 __STATIC_INLINE void Cy_TCPWM_Counter_Disable(TCPWM_Type *base, uint32_t cntNum)
330 {
331 Cy_TCPWM_Disable_Single(base, cntNum);
332 }
333
334
335 /*******************************************************************************
336 * Function Name: Cy_TCPWM_Counter_GetStatus
337 ****************************************************************************//**
338 *
339 * Returns the status of the Counter Timer whether it is running or not. In case the
340 * Counter is running, status will also provide information on counting up/down. This
341 * is useful when the counter mode is set to UP_DOWN_1 or UP_DOWN_2.
342 *
343 * \param base
344 * The pointer to a TCPWM instance.
345 *
346 * \param cntNum
347 * The Counter instance number in the selected TCPWM.
348 *
349 * \return
350 * The status. See \ref group_tcpwm_counter_status
351 *
352 * \funcusage
353 * \snippet tcpwm/counter/snippet/main.c snippet_Cy_TCPWM_Counter_GetStatus
354 *
355 *******************************************************************************/
Cy_TCPWM_Counter_GetStatus(TCPWM_Type const * base,uint32_t cntNum)356 __STATIC_INLINE uint32_t Cy_TCPWM_Counter_GetStatus(TCPWM_Type const *base, uint32_t cntNum)
357 {
358 uint32_t status;
359
360 #if (CY_IP_MXTCPWM_VERSION == 1U)
361
362 status = TCPWM_CNT_STATUS(base, cntNum);
363
364 /* Generates proper up counting status. Is not generated by HW */
365 status &= ~CY_TCPWM_COUNTER_STATUS_UP_COUNTING;
366 status |= ((~status & CY_TCPWM_COUNTER_STATUS_DOWN_COUNTING & (status >> TCPWM_CNT_STATUS_RUNNING_Pos)) <<
367 CY_TCPWM_CNT_STATUS_UP_POS);
368 #else
369 status = TCPWM_GRP_CNT_STATUS(base, TCPWM_GRP_CNT_GET_GRP(cntNum), cntNum);
370
371 /* Generates proper up counting status. Is not generated by HW */
372 status &= ~CY_TCPWM_COUNTER_STATUS_UP_COUNTING;
373 status |= ((~status & CY_TCPWM_COUNTER_STATUS_DOWN_COUNTING & (status >> TCPWM_GRP_CNT_V2_STATUS_RUNNING_Pos)) <<
374 CY_TCPWM_CNT_STATUS_UP_POS);
375
376 /* For backward compatibility, we set TCPWM_CNT_STATUS_RUNNING_Pos with TCPWM_GRP_CNT_V2_STATUS_RUNNING */
377 status |= (_FLD2VAL(TCPWM_GRP_CNT_V2_STATUS_RUNNING, status) << TCPWM_CNT_STATUS_RUNNING_Pos);
378 #endif
379
380 return(status);
381 }
382
383
384 /*******************************************************************************
385 * Function Name: Cy_TCPWM_Counter_GetCapture0Val
386 ****************************************************************************//**
387 *
388 * Returns the capture 0 value when the capture mode is enabled.
389 *
390 * \param base
391 * The pointer to a TCPWM instance.
392 *
393 * \param cntNum
394 * The Counter instance number in the selected TCPWM.
395 *
396 * \return
397 * The capture 0 value.
398 *
399 * \funcusage
400 * \snippet tcpwm/counter/snippet/main.c snippet_Cy_TCPWM_Counter_Capture
401 *
402 *******************************************************************************/
Cy_TCPWM_Counter_GetCapture0Val(TCPWM_Type const * base,uint32_t cntNum)403 __STATIC_INLINE uint32_t Cy_TCPWM_Counter_GetCapture0Val(TCPWM_Type const *base, uint32_t cntNum)
404 {
405 return Cy_TCPWM_Block_GetCC0Val(base, cntNum);
406 }
407
408
409 /*******************************************************************************
410 * Function Name: Cy_TCPWM_Counter_GetCapture0BufVal
411 ****************************************************************************//**
412 *
413 * Returns the buffered capture 0 value when the capture mode is enabled.
414 *
415 * \param base
416 * The pointer to a TCPWM instance.
417 *
418 * \param cntNum
419 * The Counter instance number in the selected TCPWM.
420 *
421 * \return
422 * The buffered capture 0 value.
423 *
424 * \funcusage
425 * \snippet tcpwm/counter/snippet/main.c snippet_Cy_TCPWM_Counter_Capture
426 *
427 *******************************************************************************/
Cy_TCPWM_Counter_GetCapture0BufVal(TCPWM_Type const * base,uint32_t cntNum)428 __STATIC_INLINE uint32_t Cy_TCPWM_Counter_GetCapture0BufVal(TCPWM_Type const *base, uint32_t cntNum)
429 {
430 return Cy_TCPWM_Block_GetCC0BufVal(base, cntNum);
431 }
432
433
434 /*******************************************************************************
435 * Function Name: Cy_TCPWM_Counter_SetCompare0Val
436 ****************************************************************************//**
437 *
438 * Sets the compare value for Compare0 when the compare mode is enabled.
439 *
440 * \param base
441 * The pointer to a TCPWM instance.
442 *
443 * \param cntNum
444 * The Counter instance number in the selected TCPWM.
445 *
446 * \param compare0
447 * The Compare0 value.
448 *
449 * \funcusage
450 * \snippet tcpwm/counter/snippet/main.c snippet_Cy_TCPWM_Counter_SetCompare0Val
451 *
452 *******************************************************************************/
Cy_TCPWM_Counter_SetCompare0Val(TCPWM_Type * base,uint32_t cntNum,uint32_t compare0)453 __STATIC_INLINE void Cy_TCPWM_Counter_SetCompare0Val(TCPWM_Type *base, uint32_t cntNum, uint32_t compare0)
454 {
455 Cy_TCPWM_Block_SetCC0Val(base, cntNum, compare0);
456 }
457
458
459 /*******************************************************************************
460 * Function Name: Cy_TCPWM_Counter_GetCompare0Val
461 ****************************************************************************//**
462 *
463 * Returns compare 0 value.
464 *
465 * \param base
466 * The pointer to a TCPWM instance.
467 *
468 * \param cntNum
469 * The Counter instance number in the selected TCPWM.
470 *
471 * \return
472 * Compare 0 value.
473 *
474 * \funcusage
475 * \snippet tcpwm/counter/snippet/main.c snippet_Cy_TCPWM_Counter_SetCompare0Val
476 *
477 *******************************************************************************/
Cy_TCPWM_Counter_GetCompare0Val(TCPWM_Type const * base,uint32_t cntNum)478 __STATIC_INLINE uint32_t Cy_TCPWM_Counter_GetCompare0Val(TCPWM_Type const *base, uint32_t cntNum)
479 {
480 return Cy_TCPWM_Block_GetCC0Val(base, cntNum);
481 }
482
483
484 /*******************************************************************************
485 * Function Name: Cy_TCPWM_Counter_SetCompare0BufVal
486 ****************************************************************************//**
487 *
488 * Sets the compare value for Compare1 when the compare mode is enabled.
489 *
490 * \param base
491 * The pointer to a TCPWM instance.
492 *
493 * \param cntNum
494 * The Counter instance number in the selected TCPWM.
495 *
496 * \param compare1
497 * The Compare1 value.
498 *
499 * \funcusage
500 * \snippet tcpwm/counter/snippet/main.c snippet_Cy_TCPWM_Counter_SetCompare0BufVal
501 *
502 *******************************************************************************/
Cy_TCPWM_Counter_SetCompare0BufVal(TCPWM_Type * base,uint32_t cntNum,uint32_t compare1)503 __STATIC_INLINE void Cy_TCPWM_Counter_SetCompare0BufVal(TCPWM_Type *base, uint32_t cntNum, uint32_t compare1)
504 {
505 Cy_TCPWM_Block_SetCC0BufVal(base, cntNum, compare1);
506 }
507
508
509 /*******************************************************************************
510 * Function Name: Cy_TCPWM_Counter_GetCompare0BufVal
511 ****************************************************************************//**
512 *
513 * Returns the buffered compare 0 value.
514 *
515 * \param base
516 * The pointer to a TCPWM instance.
517 *
518 * \param cntNum
519 * The Counter instance number in the selected TCPWM.
520 *
521 * \return
522 * Buffered Compare 0 value.
523 *
524 * \funcusage
525 * \snippet tcpwm/counter/snippet/main.c snippet_Cy_TCPWM_Counter_SetCompare0BufVal
526 *
527 *******************************************************************************/
Cy_TCPWM_Counter_GetCompare0BufVal(TCPWM_Type const * base,uint32_t cntNum)528 __STATIC_INLINE uint32_t Cy_TCPWM_Counter_GetCompare0BufVal(TCPWM_Type const *base, uint32_t cntNum)
529 {
530 return Cy_TCPWM_Block_GetCC0BufVal(base, cntNum);
531 }
532
533
534 /*******************************************************************************
535 * Function Name: Cy_TCPWM_Counter_EnableCompare0Swap
536 ****************************************************************************//**
537 *
538 * Enables the comparison swap when the comparison value is true.
539 *
540 * \param base
541 * The pointer to a TCPWM instance.
542 *
543 * \param cntNum
544 * The Counter instance number in the selected TCPWM.
545 *
546 * \param enable
547 * true = swap enabled, false = swap disabled
548 *
549 * \funcusage
550 * \snippet tcpwm/counter/snippet/main.c snippet_Cy_TCPWM_Counter_EnableCompare0Swap
551 *
552 *******************************************************************************/
Cy_TCPWM_Counter_EnableCompare0Swap(TCPWM_Type * base,uint32_t cntNum,bool enable)553 __STATIC_INLINE void Cy_TCPWM_Counter_EnableCompare0Swap(TCPWM_Type *base, uint32_t cntNum, bool enable)
554 {
555 Cy_TCPWM_Block_EnableCompare0Swap(base, cntNum, enable);
556 }
557
558
559 /*******************************************************************************
560 * Function Name: Cy_TCPWM_Counter_SetCounter
561 ****************************************************************************//**
562 *
563 * Sets the value of the counter.
564 *
565 * \param base
566 * The pointer to a TCPWM instance.
567 *
568 * \param cntNum
569 * The Counter instance number in the selected TCPWM.
570 *
571 * \param count
572 * The value to write into the counter.
573 *
574 * \funcusage
575 * \snippet tcpwm/counter/snippet/main.c snippet_Cy_TCPWM_Counter_SetCounter
576 *
577 *******************************************************************************/
Cy_TCPWM_Counter_SetCounter(TCPWM_Type * base,uint32_t cntNum,uint32_t count)578 __STATIC_INLINE void Cy_TCPWM_Counter_SetCounter(TCPWM_Type *base, uint32_t cntNum, uint32_t count)
579 {
580 Cy_TCPWM_Block_SetCounter(base, cntNum, count);
581 }
582
583
584 /*******************************************************************************
585 * Function Name: Cy_TCPWM_Counter_GetCounter
586 ****************************************************************************//**
587 *
588 * Returns the value in the counter.
589 *
590 * \param base
591 * The pointer to a TCPWM instance.
592 *
593 * \param cntNum
594 * The Counter instance number in the selected TCPWM.
595 *
596 * \return
597 * The current counter value.
598 *
599 * \funcusage
600 * \snippet tcpwm/counter/snippet/main.c snippet_Cy_TCPWM_Counter_GetCounter
601 *
602 *******************************************************************************/
Cy_TCPWM_Counter_GetCounter(TCPWM_Type const * base,uint32_t cntNum)603 __STATIC_INLINE uint32_t Cy_TCPWM_Counter_GetCounter(TCPWM_Type const *base, uint32_t cntNum)
604 {
605 return Cy_TCPWM_Block_GetCounter(base, cntNum);
606 }
607
608
609 /*******************************************************************************
610 * Function Name: Cy_TCPWM_Counter_SetPeriod
611 ****************************************************************************//**
612 *
613 * Sets the value of the period register.
614 *
615 * \param base
616 * The pointer to a TCPWM instance.
617 *
618 * \param cntNum
619 * The Counter instance number in the selected TCPWM.
620 *
621 * \param period
622 * The value to write into a period.
623 *
624 * \funcusage
625 * \snippet tcpwm/counter/snippet/main.c snippet_Cy_TCPWM_Counter_SetPeriod
626 *
627 *******************************************************************************/
Cy_TCPWM_Counter_SetPeriod(TCPWM_Type * base,uint32_t cntNum,uint32_t period)628 __STATIC_INLINE void Cy_TCPWM_Counter_SetPeriod(TCPWM_Type *base, uint32_t cntNum, uint32_t period)
629 {
630 Cy_TCPWM_Block_SetPeriod(base, cntNum, period);
631 }
632
633
634 /*******************************************************************************
635 * Function Name: Cy_TCPWM_Counter_GetPeriod
636 ****************************************************************************//**
637 *
638 * Returns the value in the period register.
639 *
640 * \param base
641 * The pointer to a TCPWM instance.
642 *
643 * \param cntNum
644 * The Counter instance number in the selected TCPWM.
645 *
646 * \return
647 * The current period value.
648 *
649 * \funcusage
650 * \snippet tcpwm/counter/snippet/main.c snippet_Cy_TCPWM_Counter_SetPeriod
651 *
652 *******************************************************************************/
Cy_TCPWM_Counter_GetPeriod(TCPWM_Type const * base,uint32_t cntNum)653 __STATIC_INLINE uint32_t Cy_TCPWM_Counter_GetPeriod(TCPWM_Type const *base, uint32_t cntNum)
654 {
655 return Cy_TCPWM_Block_GetPeriod(base, cntNum);
656 }
657
658 #if (CY_IP_MXTCPWM_VERSION >= 2U) || defined (CY_DOXYGEN)
659 /*******************************************************************************
660 * Function Name: Cy_TCPWM_Counter_SetCompare1Val
661 ****************************************************************************//**
662 *
663 * Sets the compare value for Compare1 when the compare mode enabled.
664 *
665 * \param base
666 * The pointer to a TCPWM instance.
667 *
668 * \param cntNum
669 * The Counter instance number in the selected TCPWM.
670 *
671 * \param compare1
672 * The Compare1 value.
673 *
674 * \funcusage
675 * \snippet tcpwm/counter/snippet/main.c snippet_Cy_TCPWM_Counter_SetCompare1BufVal
676 *
677 *******************************************************************************/
Cy_TCPWM_Counter_SetCompare1Val(TCPWM_Type * base,uint32_t cntNum,uint32_t compare1)678 __STATIC_INLINE void Cy_TCPWM_Counter_SetCompare1Val(TCPWM_Type *base, uint32_t cntNum, uint32_t compare1)
679 {
680 Cy_TCPWM_Block_SetCC1Val(base, cntNum, compare1);
681 }
682
683
684 /*******************************************************************************
685 * Function Name: Cy_TCPWM_Counter_GetCompare1Val
686 ****************************************************************************//**
687 *
688 * Returns compare 1 value.
689 *
690 * \param base
691 * The pointer to a TCPWM instance.
692 *
693 * \param cntNum
694 * The Counter instance number in the selected TCPWM.
695 *
696 * \return
697 * Compare 1 value.
698 *
699 * \funcusage
700 * \snippet tcpwm/counter/snippet/main.c snippet_Cy_TCPWM_Counter_SetCompare1BufVal
701 *
702 *******************************************************************************/
Cy_TCPWM_Counter_GetCompare1Val(TCPWM_Type const * base,uint32_t cntNum)703 __STATIC_INLINE uint32_t Cy_TCPWM_Counter_GetCompare1Val(TCPWM_Type const *base, uint32_t cntNum)
704 {
705 return Cy_TCPWM_Block_GetCC1Val(base, cntNum);
706 }
707
708
709 /*******************************************************************************
710 * Function Name: Cy_TCPWM_Counter_SetCompare1BufVal
711 ****************************************************************************//**
712 *
713 * Sets the buffered compare value for Compare1 when the compare mode enabled.
714 *
715 * \param base
716 * The pointer to a TCPWM instance.
717 *
718 * \param cntNum
719 * The Counter instance number in the selected TCPWM.
720 *
721 * \param compareBuf1
722 * The buffered Compare1 value.
723 *
724 * \funcusage
725 * \snippet tcpwm/counter/snippet/main.c snippet_Cy_TCPWM_Counter_SetCompare1BufVal
726 *
727 *******************************************************************************/
Cy_TCPWM_Counter_SetCompare1BufVal(TCPWM_Type * base,uint32_t cntNum,uint32_t compareBuf1)728 __STATIC_INLINE void Cy_TCPWM_Counter_SetCompare1BufVal(TCPWM_Type *base, uint32_t cntNum, uint32_t compareBuf1)
729 {
730 Cy_TCPWM_Block_SetCC1BufVal(base, cntNum, compareBuf1);
731 }
732
733
734 /*******************************************************************************
735 * Function Name: Cy_TCPWM_Counter_GetCompare1BufVal
736 ****************************************************************************//**
737 *
738 * Returns the buffered compare1 value.
739 *
740 * \param base
741 * The pointer to a TCPWM instance.
742 *
743 * \param cntNum
744 * The Counter instance number in the selected TCPWM.
745 *
746 * \return
747 * Buffered compare1 value.
748 *
749 * \funcusage
750 * \snippet tcpwm/counter/snippet/main.c snippet_Cy_TCPWM_Counter_SetCompare1BufVal
751 *
752 *******************************************************************************/
Cy_TCPWM_Counter_GetCompare1BufVal(TCPWM_Type const * base,uint32_t cntNum)753 __STATIC_INLINE uint32_t Cy_TCPWM_Counter_GetCompare1BufVal(TCPWM_Type const *base, uint32_t cntNum)
754 {
755 return Cy_TCPWM_Block_GetCC1BufVal(base, cntNum);
756 }
757
758 /*******************************************************************************
759 * Function Name: Cy_TCPWM_Counter_GetCapture1Val
760 ****************************************************************************//**
761 *
762 * Returns capture 1 value when capture mode is enabled
763 *
764 * \param base
765 * The pointer to a TCPWM instance.
766 *
767 * \param cntNum
768 * The Counter instance number in the selected TCPWM.
769 *
770 * \return
771 * Capture 1 value.
772 *
773 *******************************************************************************/
Cy_TCPWM_Counter_GetCapture1Val(TCPWM_Type const * base,uint32_t cntNum)774 __STATIC_INLINE uint32_t Cy_TCPWM_Counter_GetCapture1Val (TCPWM_Type const *base, uint32_t cntNum)
775 {
776 return Cy_TCPWM_Block_GetCC1Val(base, cntNum);
777 }
778
779 /*******************************************************************************
780 * Function Name: Cy_TCPWM_Counter_GetCapture1BufVal
781 ****************************************************************************//**
782 *
783 * Returns the buffered capture1 value when capture mode is enabled.
784 *
785 * \param base
786 * The pointer to a TCPWM instance.
787 *
788 * \param cntNum
789 * The Counter instance number in the selected TCPWM.
790 *
791 * \return
792 * Buffered capture1 value.
793 *
794 *******************************************************************************/
Cy_TCPWM_Counter_GetCapture1BufVal(TCPWM_Type const * base,uint32_t cntNum)795 __STATIC_INLINE uint32_t Cy_TCPWM_Counter_GetCapture1BufVal (TCPWM_Type const *base, uint32_t cntNum)
796 {
797 return Cy_TCPWM_Block_GetCC1BufVal(base, cntNum);
798 }
799
800 /*******************************************************************************
801 * Function Name: Cy_TCPWM_Counter_EnableCompare1Swap
802 ****************************************************************************//**
803 *
804 * Enables the comparison swap of compare1 and compareBuf1 when the comparison
805 * value is true
806 *
807 * \param base
808 * The pointer to a TCPWM instance.
809 *
810 * \param cntNum
811 * The Counter instance number in the selected TCPWM.
812 *
813 * \param enable
814 * true = swap enabled; false = swap disabled
815 *
816 * \funcusage
817 * \snippet tcpwm/counter/snippet/main.c snippet_Cy_TCPWM_Counter_EnableCompare1Swap
818 *
819 *******************************************************************************/
Cy_TCPWM_Counter_EnableCompare1Swap(TCPWM_Type * base,uint32_t cntNum,bool enable)820 __STATIC_INLINE void Cy_TCPWM_Counter_EnableCompare1Swap(TCPWM_Type *base, uint32_t cntNum, bool enable)
821 {
822 Cy_TCPWM_Block_EnableCompare1Swap(base, cntNum, enable);
823 }
824 #endif
825 #if (CY_IP_MXTCPWM_VERSION >= 3U) || defined (CY_DOXYGEN)
826 /*******************************************************************************
827 * Function Name: Cy_TCPWM_Counter_EnableSwap
828 ****************************************************************************//**
829 *
830 * Enables/disables swapping mechanism between CC0 and buffered CC0, CC1 and buffered CC1, PERIOD and buffered PERIOD, DT and buffered DT.
831 *
832 * \param base
833 * The pointer to a TCPWM instance.
834 *
835 * \param cntNum
836 * The Counter instance number in the selected TCPWM.
837 *
838 * \param enable
839 * true = swap enabled; false = swap disabled
840 *
841 *
842 *******************************************************************************/
Cy_TCPWM_Counter_EnableSwap(TCPWM_Type * base,uint32_t cntNum,bool enable)843 __STATIC_INLINE void Cy_TCPWM_Counter_EnableSwap(TCPWM_Type *base, uint32_t cntNum, bool enable)
844 {
845 Cy_TCPWM_Block_EnableSwap(base, cntNum, enable);
846 }
847 #endif /* (CY_IP_MXTCPWM_VERSION >= 3U) */
848 /** \} group_tcpwm_functions_counter */
849
850 /** \} group_tcpwm_counter */
851
852 #if defined(__cplusplus)
853 }
854 #endif
855
856 #endif /* CY_IP_MXTCPWM */
857
858 #endif /* CY_TCPWM_COUNTER_H */
859
860 /* [] END OF FILE */
861