1 /***************************************************************************//**
2 * \file cy_tcpwm_quaddec.h
3 * \version 1.70
4 *
5 * \brief
6 * The header file of the TCPWM Quadrature Decoder 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_QUADDEC_H)
26 #define CY_TCPWM_QUADDEC_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_quaddec
38 * Driver API for Quadrature Decoder.
39 *
40 * The functions and other declarations used in this part of the driver are in cy_tcpwm_quaddec.h.
41 * You can also include cy_pdl.h to get access to all functions and declarations in the PDL.
42 *
43 * A quadrature decoder is used to decode the output of a quadrature encoder.
44 * A quadrature encoder senses the position, velocity, and direction of
45 * an object (for example a rotating axle, or a spinning mouse ball).
46 * A quadrature decoder can also be used for precision measurement of speed,
47 * acceleration, and position of a motor's rotor, or with a rotary switch to
48 * determine user input.
49 *
50 * The Quadrature Decoder has the following features:
51 * * 16- or 32-bit Counter.
52 * * Period Register. This is only available in TCPWM Version 2.
53 * * Range 0, Range 0 Compare, Range 1 capture, Range 1 Compare Quadrature modes. This is only available in TCPWM Version 2.
54 * * Counter Resolution of x1, x2, x4, and up/down rotary the frequency of the phiA (Count) and
55 * phiB (Start) inputs. Up/Down rotary resolution is only available in TCPWM Version 2
56 * * Interrupt on Terminal Count and Compare or Capture 0. Interrupt on Compare or Capture 1 is only available in TCPWM Version 2.
57 * * Index Input to determine absolute position
58 * * A positive edge on phiA increments the counter when phiB is 0 and decrements
59 * the counter when phiB is 1
60 * * Two programmable trigger outputs, trig_out0 and trig_out1 that generate a
61 * trigger on one of the following events Overflow, Underflow, Terminal Count,
62 * and Compare Match 0/1. The available triggers are dependent on the QuadDec mode.
63 * All these features are only available in TCPWM Version 2.
64 * * TC (cc_match) trigger output is only available in TCPWM Version 1.
65 * * Second Compare Match (CC_MATCH1) event is only available in TCPWM Version 2.
66 *
67 * \section group_tcpwm_quaddec_configuration Configuration Considerations
68 *
69 * The QuadDec configuration can be divided to number of sequential
70 * steps listed below:
71 * * \ref group_tcpwm_quaddec_config
72 * * \ref group_tcpwm_quaddec_clock
73 * * \ref group_tcpwm_quaddec_enable
74 * * \ref group_tcpwm_quaddec_start
75 *
76 * \subsection group_tcpwm_quaddec_config Configure Quadrature
77 * To configure Quadrature, provide the configuration parameters in the
78 * \ref cy_stc_tcpwm_quaddec_config_t structure. The Configuration structure
79 * can be modified through software, but if the configurator in ModusToolbox is used
80 * then the configuration structure will be updated with the users input. To initialize
81 * the driver, call \ref Cy_TCPWM_QuadDec_Init function providing a pointer to the populated
82 * \ref cy_stc_tcpwm_quaddec_config_t structure.
83 *
84 * For TCPWM V1 Configuration
85 * \snippet tcpwm/quaddec/snippet/main.c snippet_Cy_TCPWM_V1_QuadDec_Init
86 *
87 * For TCPWM V2 Configuration
88 * \snippet tcpwm/quaddec/snippet/main.c snippet_Cy_TCPWM_V2_QuadDec_Init
89 *
90 * \subsection group_tcpwm_quaddec_clock Assign Clock Divider
91 * The clock source must be connected to proper working.
92 * Any of the peripheral clock dividers could be used. Use the
93 * \ref group_sysclk driver API to do that.
94 *
95 * \subsection group_tcpwm_quaddec_enable Enable Quadrature Decoder
96 * Quadrature has to be enabled before starting
97 *
98 * \snippet tcpwm/quaddec/snippet/main.c snippet_Cy_TCPWM_QuadDec_Enable
99 *
100 * \subsection group_tcpwm_quaddec_start Start Quadrature Decoder
101 * Quadrature has to be started
102 *
103 * \snippet tcpwm/quaddec/snippet/main.c snippet_Cy_TCPWM_QuadDec_Start
104 * \{
105 */
106 
107 /**
108 * \defgroup group_tcpwm_macros_quaddec          Macros
109 * \defgroup group_tcpwm_functions_quaddec       Functions
110 * \defgroup group_tcpwm_data_structures_quaddec Data Structures
111 * \} */
112 
113 /**
114 * \addtogroup group_tcpwm_data_structures_quaddec
115 * \{
116 */
117 
118 /** Quadrature Decoder configuration structure */
119 typedef struct cy_stc_tcpwm_quaddec_config
120 {
121     /** Selects the quadrature encoding mode. See \ref group_tcpwm_quaddec_resolution */
122     uint32_t    resolution;
123     /** Enables an interrupt on the terminal count, capture or compare. See \ref group_tcpwm_interrupt_sources */
124     uint32_t    interruptSources;
125     /** Configures how the index input behaves. See \ref group_tcpwm_input_modes */
126     uint32_t    indexInputMode;
127     /** Selects which input the index uses. The inputs are device-specific. See \ref group_tcpwm_input_selection */
128     uint32_t    indexInput;
129     /** Configures how the stop input behaves. See \ref group_tcpwm_input_modes */
130     uint32_t    stopInputMode;
131     /** Selects which input the stop uses. The inputs are device-specific. See \ref group_tcpwm_input_selection */
132     uint32_t    stopInput;
133     /** Selects which input the phiA uses. The inputs are device specific. See \ref group_tcpwm_input_selection */
134     uint32_t    phiAInput;
135     /** Selects which input the phiB uses. The inputs are device specific. See \ref group_tcpwm_input_selection */
136     uint32_t    phiBInput;
137 #if (CY_IP_MXTCPWM_VERSION >= 2U)
138     /** Configures how the phiA input behaves. See \ref group_tcpwm_input_modes */
139     uint32_t    phiAInputMode;
140     /** Configures how the phiB input behaves. See \ref group_tcpwm_input_modes */
141     uint32_t    phiBInputMode;
142     /**  Sets the QuadDec mode */
143     uint32_t    quadMode;
144     /**  Sets the period0 of the pwm */
145     uint32_t    period0;
146     /** Specifies index or wrap-around capture function*/
147     bool        captureOnIndex;
148     /** Sets the value for Compare 0 */
149     uint32_t    compare0;
150     /** Sets the value for the buffered Compare 0 */
151     uint32_t    compareBuf0;
152     /**  If enabled, the compare 0 values are swapped on the terminal count */
153     bool        enableCompare0Swap;
154     /** Sets the value for Compare 1 */
155     uint32_t    compare1;
156     /** Sets the value for the buffered Compare 1 */
157     uint32_t    compareBuf1;
158     /** If enabled, the compare1 values are swapped on the terminal count */
159     bool        enableCompare1Swap;
160     /** Configures how the capture 0/index 1 input behaves.*/
161     uint32_t    capture0OrIndex1InputMode;
162     /** Selects which input the capture 0/index 1 uses. The inputs are device-specific. */
163     uint32_t    capture0OrIndex1Input;
164     /** Configures how the capture1 input behaves. */
165     uint32_t    capture1InputMode;
166     /** Selects which input the capture 1 uses. The inputs are device-specific. */
167     uint32_t    capture1Input;
168     /** Configures which internal event generates on output trigger 0. */
169     uint32_t    trigger0Event;
170     /** Configures which internal event generates on output trigger 1. */
171     uint32_t    trigger1Event;
172 #endif /* (CY_IP_MXTCPWM_VERSION >= 2U) || defined (CY_DOXYGEN) */
173 #if defined (CY_IP_MXS40TCPWM) || 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 #endif /* defined (CY_IP_MXS40TCPWM) || defined (CY_DOXYGEN) */
176 }cy_stc_tcpwm_quaddec_config_t;
177 /** \} group_tcpwm_data_structures_quaddec */
178 
179 /**
180 * \addtogroup group_tcpwm_macros_quaddec
181 * \{
182 * \defgroup group_tcpwm_quaddec_mode QuadDec Mode
183 * \{
184 * The quadrature decoder mode.
185 */
186 /** Counter Range between 0x0000 and 0xFFFF / 0xFFFFFFFF (for GRP_CNT_WIDTH = 16 / 32) */
187 #define CY_TCPWM_QUADDEC_MODE_RANGE0                (0U)
188 /** Counter Range0 with a compare function */
189 #define CY_TCPWM_QUADDEC_MODE_RANGE0_CMP            (1U)
190 /** COUNTER range is between 0x0000 and PERIOD with 1 or 2 Capture functions */
191 #define CY_TCPWM_QUADDEC_MODE_RANGE1_CAPT           (2U)
192 /** Same as QUAD_RANGE1_CAPT with 1 or 2 Compare functions */
193 #define CY_TCPWM_QUADDEC_MODE_RANGE1_CMP            (3U)
194 /** \} group_tcpwm_quaddec_mode */
195 
196 /**
197 * \defgroup group_tcpwm_quaddec_resolution QuadDec Resolution
198 * \{
199 * The quadrature decoder resolution.
200 */
201 #define CY_TCPWM_QUADDEC_X1                         (0U)    /**< X1 mode */
202 #define CY_TCPWM_QUADDEC_X2                         (1U)    /**< X2 mode */
203 #define CY_TCPWM_QUADDEC_X4                         (2U)    /**< X4 mode */
204 #define CY_TCPWM_QUADDEC_UP_DOWN_ROTARY_COUNT       (3U)    /**< Up/Down Rotary mode */
205 /** \} group_tcpwm_quaddec_resolution */
206 
207 /**
208 * \defgroup group_tcpwm_quaddec_capture_mode QuadDec CaptureMode
209 * \{
210 * The quadrature capture modes.
211 */
212 #define CY_TCPWM_QUADDEC_CAPTURE_ON_INDEX            (0U)   /**< Capture on Index */
213 #define CY_TCPWM_QUADDEC_CAPTURE_ON_WRAP_AROUND      (1U)   /**< Capture on Wrap Around */
214 /** \} group_tcpwm_quaddec_capture_mode */
215 
216 /** \defgroup group_tcpwm_quaddec_status QuadDec Status
217 * \{
218 * The quaddec status.
219 */
220 #define CY_TCPWM_QUADDEC_STATUS_DOWN_COUNTING       (0x1UL)        /**< QuadDec is down counting */
221 #define CY_TCPWM_QUADDEC_STATUS_UP_COUNTING         (0x2UL)        /**< QuadDec is up counting */
222 /** QuadDec the counter is running */
223 #define CY_TCPWM_QUADDEC_STATUS_COUNTER_RUNNING     (0x80000000UL)
224 /** \} group_tcpwm_quaddec_status */
225 
226 
227 /***************************************
228 *        Registers Constants
229 ***************************************/
230 /** \cond INTERNAL */
231 #define CY_TCPWM_QUADDEC_CTRL_QUADDEC_MODE          (0x3UL)     /**< Quadrature encoding mode for CTRL register */
232 /** \endcond */
233 /** \} group_tcpwm_macros_quaddec */
234 
235 /*******************************************************************************
236 * Backward compatibility macro. The following code is DEPRECATED and must
237 * not be used in new projects
238 *******************************************************************************/
239 #define Cy_TCPWM_QuadDec_GetCapture         Cy_TCPWM_QuadDec_GetCapture0Val
240 #define Cy_TCPWM_QuadDec_GetCaptureBuf      Cy_TCPWM_QuadDec_GetCapture0BufVal
241 
242 /*******************************************************************************
243 *        Function Prototypes
244 *******************************************************************************/
245 
246 /**
247 * \addtogroup group_tcpwm_functions_quaddec
248 * \{
249 */
250 
251 cy_en_tcpwm_status_t Cy_TCPWM_QuadDec_Init(TCPWM_Type *base, uint32_t cntNum,
252                                            cy_stc_tcpwm_quaddec_config_t const *config);
253 void Cy_TCPWM_QuadDec_DeInit(TCPWM_Type *base, uint32_t cntNum, cy_stc_tcpwm_quaddec_config_t const *config);
254 __STATIC_INLINE void Cy_TCPWM_QuadDec_Enable(TCPWM_Type *base, uint32_t cntNum);
255 __STATIC_INLINE void Cy_TCPWM_QuadDec_Disable(TCPWM_Type *base, uint32_t cntNum);
256 __STATIC_INLINE uint32_t Cy_TCPWM_QuadDec_GetStatus(TCPWM_Type const *base, uint32_t cntNum);
257 __STATIC_INLINE uint32_t Cy_TCPWM_QuadDec_GetCapture0Val(TCPWM_Type const *base, uint32_t cntNum);
258 __STATIC_INLINE uint32_t Cy_TCPWM_QuadDec_GetCapture0BufVal(TCPWM_Type const *base, uint32_t cntNum);
259 __STATIC_INLINE void Cy_TCPWM_QuadDec_SetCompare0Val(TCPWM_Type *base, uint32_t cntNum, uint32_t compare0);
260 __STATIC_INLINE uint32_t Cy_TCPWM_QuadDec_GetCompare0Val(TCPWM_Type const *base, uint32_t cntNum);
261 __STATIC_INLINE void Cy_TCPWM_QuadDec_SetCompare0BufVal(TCPWM_Type *base, uint32_t cntNum, uint32_t compareBuf0);
262 __STATIC_INLINE uint32_t Cy_TCPWM_QuadDec_GetCompare0BufVal(TCPWM_Type const *base, uint32_t cntNum);
263 __STATIC_INLINE void Cy_TCPWM_QuadDec_EnableCompare0Swap(TCPWM_Type *base, uint32_t cntNum, bool enable);
264 __STATIC_INLINE void Cy_TCPWM_QuadDec_SetCounter(TCPWM_Type *base, uint32_t cntNum, uint32_t count);
265 __STATIC_INLINE uint32_t Cy_TCPWM_QuadDec_GetCounter(TCPWM_Type const *base, uint32_t cntNum);
266 #if (CY_IP_MXTCPWM_VERSION >= 2U) || defined (CY_DOXYGEN)
267 __STATIC_INLINE uint32_t Cy_TCPWM_QuadDec_GetCapture1Val (TCPWM_Type const *base, uint32_t cntNum);
268 __STATIC_INLINE uint32_t Cy_TCPWM_QuadDec_GetCapture1BufVal (TCPWM_Type const *base, uint32_t cntNum);
269 __STATIC_INLINE uint32_t Cy_TCPWM_QuadDec_GetCompare1Val (TCPWM_Type const *base, uint32_t cntNum);
270 __STATIC_INLINE uint32_t Cy_TCPWM_QuadDec_GetCompare1BufVal (TCPWM_Type const *base, uint32_t cntNum);
271 __STATIC_INLINE void Cy_TCPWM_QuadDec_SetCompare1Val (TCPWM_Type *base, uint32_t cntNum, uint32_t compare1);
272 __STATIC_INLINE void Cy_TCPWM_QuadDec_SetCompare1BufVal (TCPWM_Type *base, uint32_t cntNum, uint32_t compareBuf1);
273 __STATIC_INLINE void Cy_TCPWM_QuadDec_EnableCompare1Swap(TCPWM_Type *base, uint32_t cntNum,  bool enable);
274 __STATIC_INLINE void Cy_TCPWM_QuadDec_SetPeriod0(TCPWM_Type *base, uint32_t cntNum, uint32_t period0);
275 __STATIC_INLINE uint32_t Cy_TCPWM_QuadDec_GetPeriod0(TCPWM_Type const *base, uint32_t cntNum);
276 __STATIC_INLINE void Cy_TCPWM_QuadDec_SetPeriod1(TCPWM_Type *base, uint32_t cntNum, uint32_t period1);
277 __STATIC_INLINE uint32_t Cy_TCPWM_QuadDec_GetPeriod1(TCPWM_Type const *base, uint32_t cntNum);
278 __STATIC_INLINE void Cy_TCPWM_QuadDec_TriggerIndex1 (TCPWM_Type *base, uint32_t cntNum);
279 #endif
280 #if defined (CY_IP_MXS40TCPWM) || defined (CY_DOXYGEN)
281 __STATIC_INLINE void Cy_TCPWM_QuadDec_EnableSwap(TCPWM_Type *base, uint32_t cntNum,  bool enable);
282 #endif /* defined (CY_IP_MXS40TCPWM) || defined (CY_DOXYGEN) */
283 
284 /*******************************************************************************
285 * Function Name: Cy_TCPWM_QuadDec_Enable
286 ****************************************************************************//**
287 *
288 * Enables the counter in the TCPWM block for the QuadDec operation.
289 *
290 * \param base
291 * The pointer to a TCPWM instance.
292 *
293 * \param cntNum
294 * The Counter instance number in the selected TCPWM.
295 *
296 * \funcusage
297 * \snippet tcpwm/quaddec/snippet/main.c snippet_Cy_TCPWM_V1_QuadDec_Init
298 * \snippet tcpwm/quaddec/snippet/main.c snippet_Cy_TCPWM_V2_QuadDec_Init
299 *
300 *******************************************************************************/
Cy_TCPWM_QuadDec_Enable(TCPWM_Type * base,uint32_t cntNum)301 __STATIC_INLINE void Cy_TCPWM_QuadDec_Enable(TCPWM_Type *base, uint32_t cntNum)
302 {
303     Cy_TCPWM_Enable_Single(base, cntNum);
304 }
305 
306 /*******************************************************************************
307 * Function Name: Cy_TCPWM_QuadDec_Disable
308 ****************************************************************************//**
309 *
310 * Disables the counter in the TCPWM block.
311 *
312 * \param base
313 * The pointer to a TCPWM instance.
314 *
315 * \param cntNum
316 * The Counter instance number in the selected TCPWM.
317 *
318 * \funcusage
319 * \snippet tcpwm/quaddec/snippet/main.c snippet_Cy_TCPWM_QuadDec_DeInit
320 *
321 *******************************************************************************/
Cy_TCPWM_QuadDec_Disable(TCPWM_Type * base,uint32_t cntNum)322 __STATIC_INLINE void Cy_TCPWM_QuadDec_Disable(TCPWM_Type *base, uint32_t cntNum)
323 {
324     Cy_TCPWM_Disable_Single(base, cntNum);
325 }
326 
327 
328 /*******************************************************************************
329 * Function Name: Cy_TCPWM_QuadDec_GetStatus
330 ****************************************************************************//**
331 *
332 * Returns the status of the QuadDec whether it is running or not. In case the
333 * QuadDec is running, status will also provide information on counting up/down.
334 *
335 * \param base
336 * The pointer to a TCPWM instance.
337 *
338 * \param cntNum
339 * The Counter instance number in the selected TCPWM.
340 *
341 * \return
342 * The status. See \ref group_tcpwm_quaddec_status
343 *
344 * \funcusage
345 * \snippet tcpwm/quaddec/snippet/main.c snippet_Cy_TCPWM_QuadDec_GetStatus
346 *
347 *******************************************************************************/
Cy_TCPWM_QuadDec_GetStatus(TCPWM_Type const * base,uint32_t cntNum)348 __STATIC_INLINE uint32_t Cy_TCPWM_QuadDec_GetStatus(TCPWM_Type const *base, uint32_t cntNum)
349 {
350     uint32_t status;
351 
352 #if (CY_IP_MXTCPWM_VERSION == 1U)
353 
354         status = TCPWM_CNT_STATUS(base, cntNum);
355 
356         /* Generates proper up counting status. Is not generated by HW */
357         status &= ~CY_TCPWM_QUADDEC_STATUS_UP_COUNTING;
358         status |= ((~status & CY_TCPWM_QUADDEC_STATUS_DOWN_COUNTING & (status >> TCPWM_CNT_STATUS_RUNNING_Pos)) <<
359                    CY_TCPWM_CNT_STATUS_UP_POS);
360 #else
361         status = TCPWM_GRP_CNT_STATUS(base, TCPWM_GRP_CNT_GET_GRP(cntNum), cntNum);
362 
363         /* Generates proper up counting status. Is not generated by HW */
364         status &= ~CY_TCPWM_QUADDEC_STATUS_UP_COUNTING;
365         status |= ((~status & CY_TCPWM_QUADDEC_STATUS_DOWN_COUNTING & (status >> TCPWM_GRP_CNT_V2_STATUS_RUNNING_Pos)) <<
366                CY_TCPWM_CNT_STATUS_UP_POS);
367 
368         /* For backward compatibility, we set TCPWM_CNT_STATUS_RUNNING_Pos with TCPWM_GRP_CNT_V2_STATUS_RUNNING */
369         status |= (_FLD2VAL(TCPWM_GRP_CNT_V2_STATUS_RUNNING, status) << TCPWM_CNT_STATUS_RUNNING_Pos);
370 #endif
371 
372     return(status);
373 }
374 
375 
376 /*******************************************************************************
377 * Function Name: Cy_TCPWM_QuadDec_GetCapture0Val
378 ****************************************************************************//**
379 *
380 * Returns the capture value.
381 *
382 * \param base
383 * The pointer to a TCPWM instance.
384 *
385 * \param cntNum
386 * The Counter instance number in the selected TCPWM.
387 *
388 * \return
389 * The capture value.
390 *
391 * \funcusage
392 * \snippet tcpwm/quaddec/snippet/main.c snippet_Cy_TCPWM_QuadDec_Capture
393 *
394 *******************************************************************************/
Cy_TCPWM_QuadDec_GetCapture0Val(TCPWM_Type const * base,uint32_t cntNum)395 __STATIC_INLINE uint32_t Cy_TCPWM_QuadDec_GetCapture0Val(TCPWM_Type const *base, uint32_t cntNum)
396 {
397     return Cy_TCPWM_Block_GetCC0Val(base, cntNum);
398 }
399 
400 
401 /*******************************************************************************
402 * Function Name: Cy_TCPWM_QuadDec_GetCapture0BufVal
403 ****************************************************************************//**
404 *
405 * Returns the buffered capture value.
406 *
407 * \param base
408 * The pointer to a TCPWM instance.
409 *
410 * \param cntNum
411 * The Counter instance number in the selected TCPWM.
412 *
413 * \return
414 * The buffered capture value.
415 *
416 * \funcusage
417 * \snippet tcpwm/quaddec/snippet/main.c snippet_Cy_TCPWM_QuadDec_Capture
418 *
419 *******************************************************************************/
Cy_TCPWM_QuadDec_GetCapture0BufVal(TCPWM_Type const * base,uint32_t cntNum)420 __STATIC_INLINE uint32_t Cy_TCPWM_QuadDec_GetCapture0BufVal(TCPWM_Type const *base, uint32_t cntNum)
421 {
422     return Cy_TCPWM_Block_GetCC0BufVal(base, cntNum);
423 }
424 
425 
426 /*******************************************************************************
427 * Function Name: Cy_TCPWM_QuadDec_SetCompare0Val
428 ****************************************************************************//**
429 *
430 * Sets the compare value for Compare0 when the compare mode is enabled.
431 *
432 * \param base
433 * The pointer to a TCPWM instance.
434 *
435 * \param cntNum
436 * The Counter instance number in the selected TCPWM.
437 *
438 * \param compare0
439 * The Compare 0 value.
440 *
441 * \funcusage
442 * \snippet tcpwm/quaddec/snippet/main.c snippet_Cy_TCPWM_QuadDec_SetCompare0Val
443 *
444 *******************************************************************************/
Cy_TCPWM_QuadDec_SetCompare0Val(TCPWM_Type * base,uint32_t cntNum,uint32_t compare0)445 __STATIC_INLINE void Cy_TCPWM_QuadDec_SetCompare0Val(TCPWM_Type *base, uint32_t cntNum,  uint32_t compare0)
446 {
447     Cy_TCPWM_Block_SetCC0Val(base, cntNum, compare0);
448 }
449 
450 
451 /*******************************************************************************
452 * Function Name: Cy_TCPWM_QuadDec_GetCompare0Val
453 ****************************************************************************//**
454 *
455 * Returns compare 0 value.
456 *
457 * \param base
458 * The pointer to a TCPWM instance.
459 *
460 * \param cntNum
461 * The Counter instance number in the selected TCPWM.
462 *
463 * \return
464 * Compare 0 value.
465 *
466 * \funcusage
467 * \snippet tcpwm/quaddec/snippet/main.c snippet_Cy_TCPWM_QuadDec_SetCompare0Val
468 *
469 *******************************************************************************/
Cy_TCPWM_QuadDec_GetCompare0Val(TCPWM_Type const * base,uint32_t cntNum)470 __STATIC_INLINE uint32_t Cy_TCPWM_QuadDec_GetCompare0Val(TCPWM_Type const  *base, uint32_t cntNum)
471 {
472     return Cy_TCPWM_Block_GetCC0Val(base, cntNum);
473 }
474 
475 
476 /*******************************************************************************
477 * Function Name: Cy_TCPWM_QuadDec_SetCompare0BufVal
478 ****************************************************************************//**
479 *
480 * Sets the Buffered Compare 0 value when the compare mode is enabled.
481 *
482 * \param base
483 * The pointer to a TCPWM instance.
484 *
485 * \param cntNum
486 * The Counter instance number in the selected TCPWM.
487 *
488 * \param compareBuf0
489 * The Buffered Compare 0 value.
490 *
491 * \funcusage
492 * \snippet tcpwm/quaddec/snippet/main.c snippet_Cy_TCPWM_QuadDec_SetCompare0BufVal
493 *
494 *******************************************************************************/
Cy_TCPWM_QuadDec_SetCompare0BufVal(TCPWM_Type * base,uint32_t cntNum,uint32_t compareBuf0)495 __STATIC_INLINE void Cy_TCPWM_QuadDec_SetCompare0BufVal(TCPWM_Type *base, uint32_t cntNum,  uint32_t compareBuf0)
496 {
497     Cy_TCPWM_Block_SetCC0BufVal(base, cntNum, compareBuf0);
498 }
499 
500 
501 /*******************************************************************************
502 * Function Name: Cy_TCPWM_QuadDec_GetCompare0BufVal
503 ****************************************************************************//**
504 *
505 * Returns Buffered Compare 0 Value.
506 *
507 * \param base
508 * The pointer to a TCPWM instance.
509 *
510 * \param cntNum
511 * The Counter instance number in the selected TCPWM.
512 *
513 * \return
514 * Buffered Compare 0 Value.
515 *
516 * \funcusage
517 * \snippet tcpwm/quaddec/snippet/main.c snippet_Cy_TCPWM_QuadDec_SetCompare0BufVal
518 *
519 *******************************************************************************/
Cy_TCPWM_QuadDec_GetCompare0BufVal(TCPWM_Type const * base,uint32_t cntNum)520 __STATIC_INLINE uint32_t Cy_TCPWM_QuadDec_GetCompare0BufVal(TCPWM_Type const  *base, uint32_t cntNum)
521 {
522     return Cy_TCPWM_Block_GetCC0BufVal(base, cntNum);
523 }
524 
525 
526 /*******************************************************************************
527 * Function Name: Cy_TCPWM_QuadDec_EnableCompare0Swap
528 ****************************************************************************//**
529 *
530 * Enables the comparison swap of compare 0 and compareBuf 0 when the comparison
531 * value is true
532 *
533 * \param base
534 * The pointer to a TCPWM instance.
535 *
536 * \param cntNum
537 * The Counter instance number in the selected TCPWM.
538 *
539 * \param enable
540 * true = swap enabled, false = swap disabled
541 *
542 * \funcusage
543 * \snippet tcpwm/quaddec/snippet/main.c snippet_Cy_TCPWM_QuadDec_EnableCompare0Swap
544 *
545 *******************************************************************************/
Cy_TCPWM_QuadDec_EnableCompare0Swap(TCPWM_Type * base,uint32_t cntNum,bool enable)546 __STATIC_INLINE void Cy_TCPWM_QuadDec_EnableCompare0Swap(TCPWM_Type *base, uint32_t cntNum,  bool enable)
547 {
548     Cy_TCPWM_Block_EnableCompare0Swap(base, cntNum, enable);
549 }
550 
551 
552 /*******************************************************************************
553 * Function Name: Cy_TCPWM_QuadDec_SetCounter
554 ****************************************************************************//**
555 *
556 * Sets the value of the counter.
557 *
558 * \param base
559 * The pointer to a TCPWM instance.
560 *
561 * \param cntNum
562 * The Counter instance number in the selected TCPWM.
563 *
564 * \param count
565 * The value to write into the counter.
566 *
567 * \funcusage
568 * \snippet tcpwm/quaddec/snippet/main.c snippet_Cy_TCPWM_QuadDec_SetCounter
569 *
570 *******************************************************************************/
Cy_TCPWM_QuadDec_SetCounter(TCPWM_Type * base,uint32_t cntNum,uint32_t count)571 __STATIC_INLINE void Cy_TCPWM_QuadDec_SetCounter(TCPWM_Type *base, uint32_t cntNum, uint32_t count)
572 {
573     Cy_TCPWM_Block_SetCounter(base, cntNum, count);
574 }
575 
576 
577 /*******************************************************************************
578 * Function Name: Cy_TCPWM_QuadDec_GetCounter
579 ****************************************************************************//**
580 *
581 * Returns the value in the counter.
582 *
583 * \param base
584 * The pointer to a TCPWM instance.
585 *
586 * \param cntNum
587 * The Counter instance number in the selected TCPWM.
588 *
589 * \return
590 * The current counter value.
591 *
592 * \funcusage
593 * \snippet tcpwm/quaddec/snippet/main.c snippet_Cy_TCPWM_QuadDec_GetCounter
594 *
595 *******************************************************************************/
Cy_TCPWM_QuadDec_GetCounter(TCPWM_Type const * base,uint32_t cntNum)596 __STATIC_INLINE uint32_t Cy_TCPWM_QuadDec_GetCounter(TCPWM_Type const *base, uint32_t cntNum)
597 {
598     return Cy_TCPWM_Block_GetCounter(base, cntNum);
599 }
600 #if (CY_IP_MXTCPWM_VERSION >= 2U) || defined (CY_DOXYGEN)
601 /*******************************************************************************
602 * Function Name: Cy_TCPWM_QuadDec_SetCompare1Val
603 ****************************************************************************//**
604 *
605 * Sets the compare value for Compare 1 when the compare mode enabled.
606 *
607 * \param base
608 * The pointer to a TCPWM instance.
609 *
610 * \param cntNum
611 * The Counter instance number in the selected TCPWM.
612 *
613 * \param compare1
614 * The Compare 1 value.
615 *
616 * \funcusage
617 * \snippet tcpwm/quaddec/snippet/main.c snippet_Cy_TCPWM_QuadDec_SetCompare1Val
618 *
619 *******************************************************************************/
Cy_TCPWM_QuadDec_SetCompare1Val(TCPWM_Type * base,uint32_t cntNum,uint32_t compare1)620 __STATIC_INLINE void Cy_TCPWM_QuadDec_SetCompare1Val(TCPWM_Type *base, uint32_t cntNum,  uint32_t compare1)
621 {
622     Cy_TCPWM_Block_SetCC1Val(base, cntNum, compare1);
623 }
624 
625 
626 /*******************************************************************************
627 * Function Name: Cy_TCPWM_QuadDec_GetCompare1Val
628 ****************************************************************************//**
629 *
630 * Returns compare 1 value.
631 *
632 * \param base
633 * The pointer to a TCPWM instance.
634 *
635 * \param cntNum
636 * The Counter instance number in the selected TCPWM.
637 *
638 * \return
639 * Compare 1 value.
640 *
641 * \funcusage
642 * \snippet tcpwm/quaddec/snippet/main.c snippet_Cy_TCPWM_QuadDec_SetCompare1Val
643 *
644 *******************************************************************************/
Cy_TCPWM_QuadDec_GetCompare1Val(TCPWM_Type const * base,uint32_t cntNum)645 __STATIC_INLINE uint32_t Cy_TCPWM_QuadDec_GetCompare1Val(TCPWM_Type const *base, uint32_t cntNum)
646 {
647     return Cy_TCPWM_Block_GetCC1Val(base, cntNum);
648 }
649 
650 
651 /*******************************************************************************
652 * Function Name: Cy_TCPWM_QuadDec_SetCompare1BufVal
653 ****************************************************************************//**
654 *
655 * Sets the buffered compare value for Compare 1 when the compare mode enabled.
656 *
657 * \param base
658 * The pointer to a TCPWM instance.
659 *
660 * \param cntNum
661 * The Counter instance number in the selected TCPWM.
662 *
663 * \param compareBuf1
664 * The buffered Compare 1 value.
665 *
666 * \funcusage
667 * \snippet tcpwm/quaddec/snippet/main.c snippet_Cy_TCPWM_QuadDec_SetCompare1BufVal
668 *
669 *******************************************************************************/
Cy_TCPWM_QuadDec_SetCompare1BufVal(TCPWM_Type * base,uint32_t cntNum,uint32_t compareBuf1)670 __STATIC_INLINE void Cy_TCPWM_QuadDec_SetCompare1BufVal(TCPWM_Type *base, uint32_t cntNum,  uint32_t compareBuf1)
671 {
672     Cy_TCPWM_Block_SetCC1BufVal(base, cntNum, compareBuf1);
673 }
674 
675 
676 /*******************************************************************************
677 * Function Name: Cy_TCPWM_QuadDec_GetCompare1BufVal
678 ****************************************************************************//**
679 *
680 * Returns the buffered compare 1 value.
681 *
682 * \param base
683 * The pointer to a TCPWM instance.
684 *
685 * \param cntNum
686 * The Counter instance number in the selected TCPWM.
687 *
688 * \return
689 * Buffered compare 1 value.
690 *
691 * \funcusage
692 * \snippet tcpwm/quaddec/snippet/main.c snippet_Cy_TCPWM_QuadDec_SetCompare1BufVal
693 *
694 *******************************************************************************/
Cy_TCPWM_QuadDec_GetCompare1BufVal(TCPWM_Type const * base,uint32_t cntNum)695 __STATIC_INLINE uint32_t Cy_TCPWM_QuadDec_GetCompare1BufVal(TCPWM_Type const *base, uint32_t cntNum)
696 {
697     return Cy_TCPWM_Block_GetCC1BufVal(base, cntNum);
698 }
699 
700 /*******************************************************************************
701 * Function Name: Cy_TCPWM_QuadDec_GetCapture1Val
702 ****************************************************************************//**
703 *
704 * Returns capture 1 value when capture mode is enabled
705 *
706 * \param base
707 * The pointer to a TCPWM instance.
708 *
709 * \param cntNum
710 * The Counter instance number in the selected TCPWM.
711 *
712 * \return
713 * Capture 1 value.
714 *
715 *******************************************************************************/
Cy_TCPWM_QuadDec_GetCapture1Val(TCPWM_Type const * base,uint32_t cntNum)716 __STATIC_INLINE uint32_t Cy_TCPWM_QuadDec_GetCapture1Val (TCPWM_Type const *base, uint32_t cntNum)
717 {
718     return Cy_TCPWM_Block_GetCC1Val(base, cntNum);
719 }
720 
721 /*******************************************************************************
722 * Function Name: Cy_TCPWM_QuadDec_GetCapture1BufVal
723 ****************************************************************************//**
724 *
725 * Returns the buffered capture 1 value when capture mode is enabled.
726 *
727 * \param base
728 * The pointer to a TCPWM instance.
729 *
730 * \param cntNum
731 * The Counter instance number in the selected TCPWM.
732 *
733 * \return
734 * Buffered capture 1 value.
735 *
736 *******************************************************************************/
Cy_TCPWM_QuadDec_GetCapture1BufVal(TCPWM_Type const * base,uint32_t cntNum)737 __STATIC_INLINE uint32_t Cy_TCPWM_QuadDec_GetCapture1BufVal (TCPWM_Type const *base, uint32_t cntNum)
738 {
739     return Cy_TCPWM_Block_GetCC1BufVal(base, cntNum);
740 }
741 
742 /*******************************************************************************
743 * Function Name: Cy_TCPWM_QuadDec_EnableCompare1Swap
744 ****************************************************************************//**
745 *
746 * Enables the comparison swap of compare 1 and compareBuf 1 when the comparison
747 * value is true
748 *
749 * \param base
750 * The pointer to a TCPWM instance.
751 *
752 * \param cntNum
753 * The Counter instance number in the selected TCPWM.
754 *
755 * \param enable
756 * true = swap enabled; false = swap disabled
757 *
758 * \funcusage
759 * \snippet tcpwm/quaddec/snippet/main.c snippet_Cy_TCPWM_QuadDec_EnableCompare1Swap
760 *
761 *******************************************************************************/
Cy_TCPWM_QuadDec_EnableCompare1Swap(TCPWM_Type * base,uint32_t cntNum,bool enable)762 __STATIC_INLINE void Cy_TCPWM_QuadDec_EnableCompare1Swap(TCPWM_Type *base, uint32_t cntNum,  bool enable)
763 {
764     Cy_TCPWM_Block_EnableCompare1Swap(base, cntNum, enable);
765 }
766 /*******************************************************************************
767 * Function Name: Cy_TCPWM_QuadDec_SetPeriod0
768 ****************************************************************************//**
769 *
770 * Sets the value of the period register.
771 *
772 * \param base
773 * The pointer to a TCPWM instance.
774 *
775 * \param cntNum
776 * The Counter instance number in the selected TCPWM.
777 *
778 * \param period0
779 * The value to write into a period.
780 *
781 * \funcusage
782 * \snippet tcpwm/quaddec/snippet/main.c snippet_Cy_TCPWM_QuadDec_SetPeriod0
783 *
784 *******************************************************************************/
Cy_TCPWM_QuadDec_SetPeriod0(TCPWM_Type * base,uint32_t cntNum,uint32_t period0)785 __STATIC_INLINE void Cy_TCPWM_QuadDec_SetPeriod0(TCPWM_Type *base, uint32_t cntNum,  uint32_t period0)
786 {
787     Cy_TCPWM_Block_SetPeriod(base, cntNum, period0);
788 }
789 
790 
791 /*******************************************************************************
792 * Function Name: Cy_TCPWM_QuadDec_GetPeriod0
793 ****************************************************************************//**
794 *
795 * Returns the value in the period 0 register.
796 *
797 * \param base
798 * The pointer to a TCPWM instance.
799 *
800 * \param cntNum
801 * The Counter instance number in the selected TCPWM.
802 *
803 * \return
804 * The current period value.
805 *
806 * \funcusage
807 * \snippet tcpwm/quaddec/snippet/main.c snippet_Cy_TCPWM_QuadDec_SetPeriod0
808 *
809 *******************************************************************************/
Cy_TCPWM_QuadDec_GetPeriod0(TCPWM_Type const * base,uint32_t cntNum)810 __STATIC_INLINE uint32_t Cy_TCPWM_QuadDec_GetPeriod0(TCPWM_Type const *base, uint32_t cntNum)
811 {
812     return Cy_TCPWM_Block_GetPeriod(base, cntNum);
813 }
814 
815 
816 /*******************************************************************************
817 * Function Name: Cy_TCPWM_QuadDec_SetPeriod1
818 ****************************************************************************//**
819 *
820 * Sets the value of the period register.
821 *
822 * \param base
823 * The pointer to a TCPWM instance.
824 *
825 * \param cntNum
826 * The Counter instance number in the selected TCPWM.
827 *
828 * \param period1
829 * The value to write into a period 1.
830 *
831 * \funcusage
832 * \snippet tcpwm/quaddec/snippet/main.c snippet_Cy_TCPWM_QuadDec_SetPeriod1
833 *
834 * * \note supported only in TCPWM_ver2
835 *
836 *******************************************************************************/
Cy_TCPWM_QuadDec_SetPeriod1(TCPWM_Type * base,uint32_t cntNum,uint32_t period1)837 __STATIC_INLINE void Cy_TCPWM_QuadDec_SetPeriod1(TCPWM_Type *base, uint32_t cntNum,  uint32_t period1)
838 {
839     TCPWM_GRP_CNT_PERIOD_BUFF(base, TCPWM_GRP_CNT_GET_GRP(cntNum), cntNum) = period1;
840 }
841 
842 
843 /*******************************************************************************
844 * Function Name: Cy_TCPWM_QuadDec_GetPeriod1
845 ****************************************************************************//**
846 *
847 * Returns the value in the period 1 register.
848 *
849 * \param base
850 * The pointer to a TCPWM instance.
851 *
852 * \param cntNum
853 * The Counter instance number in the selected TCPWM.
854 *
855 * \return
856 * The current period 1 value.
857 *
858 * \funcusage
859 * \snippet tcpwm/quaddec/snippet/main.c snippet_Cy_TCPWM_QuadDec_SetPeriod1
860 *
861 * \note supported only in TCPWM_ver2
862 *
863 *******************************************************************************/
Cy_TCPWM_QuadDec_GetPeriod1(TCPWM_Type const * base,uint32_t cntNum)864 __STATIC_INLINE uint32_t Cy_TCPWM_QuadDec_GetPeriod1(TCPWM_Type const *base, uint32_t cntNum)
865 {
866     uint32_t period1 = 0UL;
867 
868     period1 = TCPWM_GRP_CNT_PERIOD_BUFF(base, TCPWM_GRP_CNT_GET_GRP(cntNum), cntNum);
869     return period1;
870 }
871 
872 /*******************************************************************************
873 * Function Name: Cy_TCPWM_QuadDec_TriggerIndex1
874 ****************************************************************************//**
875 *
876 * Triggers a software index 1.
877 *
878 * \param base
879 * The pointer to a TCPWM instance.
880 *
881 * \param cntNum
882 * The Counter instance number in the selected TCPWM.
883 *
884 * \funcusage
885 * \snippet tcpwm/quaddec/snippet/main.c snippet_Cy_TCPWM_QuadDec_TriggerIndex1
886 *
887 *******************************************************************************/
Cy_TCPWM_QuadDec_TriggerIndex1(TCPWM_Type * base,uint32_t cntNum)888 __STATIC_INLINE void Cy_TCPWM_QuadDec_TriggerIndex1 (TCPWM_Type *base, uint32_t cntNum)
889 {
890     Cy_TCPWM_TriggerCapture0(base, cntNum);
891 }
892 #endif
893 
894 #if defined (CY_IP_MXS40TCPWM) || defined (CY_DOXYGEN)
895 /*******************************************************************************
896 * Function Name: Cy_TCPWM_QuadDec_EnableSwap
897 ****************************************************************************//**
898 *
899 * Enables/disables swapping mechanism between CC0 and buffered CC0, CC1 and buffered CC1, PERIOD and buffered PERIOD, DT and buffered DT.
900 *
901 * \param base
902 * The pointer to a TCPWM instance.
903 *
904 * \param cntNum
905 * The Counter instance number in the selected TCPWM.
906 *
907 * \param enable
908 * true = swap enabled; false = swap disabled
909 *
910 *
911 *******************************************************************************/
Cy_TCPWM_QuadDec_EnableSwap(TCPWM_Type * base,uint32_t cntNum,bool enable)912 __STATIC_INLINE void Cy_TCPWM_QuadDec_EnableSwap(TCPWM_Type *base, uint32_t cntNum,  bool enable)
913 {
914     Cy_TCPWM_Block_EnableSwap(base, cntNum, enable);
915 }
916 #endif /* defined (CY_IP_MXS40TCPWM) */
917 
918 /** \} group_tcpwm_functions_quaddec */
919 
920 /** \} group_tcpwm_quaddec */
921 
922 #if defined(__cplusplus)
923 }
924 #endif
925 
926 #endif /* CY_IP_MXTCPWM */
927 
928 #endif /* CY_TCPWM_QUADDEC_H */
929 
930 /* [] END OF FILE */
931