1 /***************************************************************************//**
2 * \file cy_tcpwm.h
3 * \version 1.70
4 *
5 * The header file of the TCPWM driver.
6 *
7 ********************************************************************************
8 * \copyright
9 * Copyright 2016-2022 Cypress Semiconductor Corporation
10 * SPDX-License-Identifier: Apache-2.0
11 *
12 * Licensed under the Apache License, Version 2.0 (the "License");
13 * you may not use this file except in compliance with the License.
14 * You may obtain a copy of the License at
15 *
16 * http://www.apache.org/licenses/LICENSE-2.0
17 *
18 * Unless required by applicable law or agreed to in writing, software
19 * distributed under the License is distributed on an "AS IS" BASIS,
20 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
21 * See the License for the specific language governing permissions and
22 * limitations under the License.
23 *******************************************************************************/
24
25 /**
26 * \addtogroup group_tcpwm
27 * \{
28 * \defgroup group_tcpwm_common Common
29 * \defgroup group_tcpwm_counter Timer/Counter (TCPWM)
30 * \defgroup group_tcpwm_pwm PWM (TCPWM)
31 * \defgroup group_tcpwm_quaddec Quadrature Decoder (TCPWM)
32 * \defgroup group_tcpwm_shiftreg Shift Register (TCPWM)
33 * \} */
34
35 /**
36 * \addtogroup group_tcpwm
37 * \{
38 *
39 * The TCPWM driver is a multifunction driver that implements Timer Counter,
40 * PWM, Quadrature Decoder and Shift Register functionality using the TCPWM block.
41 *
42 * The functions and other declarations used in this driver are in cy_tcpwm_counter.h,
43 * cy_tcpwm_pwm.h, cy_tcpwm_quaddec.h, cy_tcpwm_shiftreg.h respectively. Include cy_pdl.h
44 * to get access to all functions and declarations in the PDL.
45 *
46 * Each TCPWM block is a collection of counters that can all be triggered
47 * simultaneously. For each function call, the base register address of
48 * the TCPWM being used must be passed first, followed by the index of
49 * the counter you want to touch next.
50 *
51 * The TCPWM supports seven function modes:
52 * * Timer
53 * * Capture
54 * * Quadrature Decoder
55 * * Pulse Width Modulation (PWM)
56 * * PWM with dead time insertion (PWMDT)
57 * * Pseudo random PWM (PWMPR)
58 * * Shift Register
59 *
60 * The TCPWM driver is structured to map these seven functional modes to four
61 * high level operating modes:
62 * * Timer/Counter (includes Timer, Capture modes)
63 * * PWM (PWM, PWMDT, PWMPR)
64 * * Quadrature Decoder
65 * * Shift Register
66 *
67 * A brief description on each of the operating modes:
68 *
69 * \b Timer/Counter
70 *
71 * Use this mode whenever a specific timing interval or measurement is
72 * needed. Examples include:
73 * * Creating a periodic interrupt for running other system tasks
74 * * Measuring frequency of an input signal
75 * * Measuring pulse width of an input signal
76 * * Measuring time between two external events
77 * * Counting events
78 * * Triggering other system resources after x number events
79 * * Capturing time stamps when events occur
80 *
81 * \n
82 * \b PWM
83 *
84 * Use this mode when an output square wave is needed with a specific
85 * period and duty cycle, such as:
86 * * Creating arbitrary square wave outputs
87 * * Driving an LED (changing the brightness)
88 * * Driving Motors (dead time assertion available)
89 *
90 * \n
91 * \b Quadrature \b Decoder
92 *
93 * A quadrature decoder is used to decode the output of a quadrature encoder.
94 * A quadrature encoder senses the position, velocity, and direction of
95 * an object (for example a rotating axle, or a spinning mouse ball).
96 * A quadrature decoder can also be used for precision measurement of speed,
97 * acceleration, and position of a motor's rotor, or with a rotary switch to
98 * determine user input. \n
99 *
100 * \n
101 * \b Shift \b Register
102 *
103 * Shift Register functionality shifts the counter value to the right.
104 * A shift register is used to apply a signal delay function which can be used
105 * eg: in detecting frequency shift keying (FSK) signals.
106 * A shift register is also used in parallel-in to serial-out data conversion
107 * and serial-in to parallel-out data conversion.
108 *
109 * \section group_tcpwm_version_information TCPWM Versions
110 *
111 * There are three versions of TCPWM driver
112 *
113 * \b TCPWM \b Version \b 3
114 *
115 * - The mxtcpwm.3.0 consists of up to 2048, 16-bit or 32-bit counters
116 * - Counter groups up to 8*256
117 * - Counter compare, period, line_sel and dead time registers are double buffered.
118 * - Parallel data path support for CC0/CC1 register through dedicated data interface (only applicable to mxtcpwm 3.1, PSoC C3 (CAT1B) do not support this)
119 * - Glitch Filter with configurable depth supported on General-purpose triggers used by all counters and specific one-to-one triggers for each counter
120 * - Shadow registers available for duty, period, dead time, signal and polarity
121 * - Enhanced shadow update mechanism
122 * - Independent control of clock pre-scalar and dead time
123 * - Configurable PWM dithering on period as well as duty cycle
124 * - Configurable option to continue / pause with the ability to enter passive state through kill polarity in debug mode
125 * - Output state control for PWM signal during stop or kill operation synchronous to period match
126 * - Independent line polarity setting for PWM signal during kill operation
127 * - Support up to 4 Motion Interface (MOTIF)
128 * - Support interrupt output for each MOTIF
129 * - Hall interface for direct connection to Hall sensors
130 * - HW look-up table for advance motor control feedback loop operation
131 * - Synchronous modulation support for multiple counters
132 * - Support HRPWM (High resolution PWM generation) feature in both 16-bit and 32-bit TCPWM counters (Only applicable to mxtcpwm 3.1, PSoC C3 (CAT1B) only has 4 HRPWM blocks on the 32 bit PWMs.)
133 * - HRPWM enhancements are limited to PWM and PWM_DT mode only
134 * - HRPWM consists of an analog interpolator (also referred as delay element)
135 * - Analog interpolator consists of delay elements which uses the input clock to generate a set of delayed phases. These delayed phases are then used to delay the edges of the incoming PWM from tcpwm.
136 * - Analog interpolator is used to shift the edges of line_out and line_compl_out coming as output from the TCPWM to the analog interpolator.
137 * - The LSBs are used for fractional or micro ticks for delaying the line_out and line_compl_out outputs for PERIOD/PERIOD_BUFF, CC0/CC0_BUFF, and CC1/CC1_BUFF and DT/DT_BUFF.
138 * - Number of LSB bits used for fractional control is control by the design time parameter, GRP_HRPWM_WIDTH.
139 * - The remaining bits given by [GRP_CNT_WIDTH-1:GRP_HRPWM_WIDTH] are used by the mxtcpwm counter.
140 *
141 * \b TCPWM \b Version \b 2
142 *
143 * - Devices CY8C61x4 and CY8C62x4 use this version.
144 * - Supports up to four counter groups (check TRM for actual number of groups supported)
145 * - Each counter group consists of up to 256 counters (check TRM for actual number of counters supported)
146 * - Each counter
147 * - Can run in one of seven function modes
148 * - Supports various counting modes:
149 * - One-shot mode, Continuous mode (Up/Down/Up-down)
150 * - Selects input signals
151 * - Start, Reload, Stop, Count, and two Capture event signals
152 * - Generates output signals:
153 * - Two output triggers, PWM output, and Interrupt
154 * - Trigger Outputs (TR_OUT0/1) and an Interrupt on an event
155 * - Overflow (OV)
156 * - Underflow (UN)
157 * - Terminal Count (TC)
158 * - CC0/1_MATCH
159 * - LINE_OUT
160 * - Supports debug mode
161 * - Each counter can produce two output signals
162 *
163 * \image html tcpwm_v2_block_diagram.png
164 *
165 * - \b Input \b Trigger \b Selection \b and \b Event \b Detection
166 * - The counter control signals are generated as follows:
167 * - Selects input signals from two types of trigger multiplexer signals
168 * - Group trigger and one-to-one trigger
169 * - The constant '1' and '0' are also used as input triggers
170 * - Detects the selected edge from four types
171 * - Rising edge/falling edge/any edge/no edge
172 * - Supports software (SW) command
173 * - SW command of Trigger Multiplexer/SW command of TCPWM
174 *
175 * \image html tcpwm_v2_input_trigger_sel.png
176 *
177 * - \b Simultaneous \b Activation:
178 * - When a Trigger Multiplexer block SW command is used, the TCPWM counters can be activated at the same time
179 *
180 * \image html tcpwm_v2_trigger_simultaneously.png
181 *
182 * \b TCPWM \b Version \b 1
183 *
184 * - Devices CY8C61x6, CY8C61x7, CY8C62x5, CY8C62x6, CY8C62x7, CY8C62x8, CY8C62xA, CY8C63x6, CY8C63x7, CYS0644xxZI-S2D44,
185 * CYB0644xxZI-S4D44, CYB06447BZI-BLDX, CYB06447BZI-D54 and CYB06445LQI-S3D42 use this version.
186 * - Supports up to 32 counters (check TRM for actual number of counters supported)
187 * - Synchronized operation of multiple counters.
188 * - 16 or 32 bit counter, compare/capture (CC) and period registers.
189 * - CC and period registers are double buffered.
190 * - Up, down and up/down counting modes.
191 * - 14 trigger input signals and 2 constant input signals: '0' and '1', for a total of 16 hardware (HW) input signals
192 * - Rising edge, falling edge, combined rising/falling edge detection or pass-through on all HW input signals to derive counter events.
193 * - The start, reload, stop and capture events can be generated by software.
194 * - Clock pre-scaling (1x, 2x, 4x ... 128x).
195 * - Support Pseudo Random PWM
196 * - 3 output trigger signals for each counter to indicate underflow, overflow and cc_match events.
197 * - 2 PWM complementary output lines for each counter. Dead time insertion ([0, 255] counter cycles).
198 * - Support one interrupt output for each counter.
199 *
200 * \image html tcpwm_v1_block_diagram.png
201 *
202 * - Many functions work with an individual counter. You can also manage multiple counters simultaneously for certain functions.
203 * - These are listed in the \ref group_tcpwm_functions_common section of the TCPWM.
204 * - You can enable, disable, or trigger (in various ways) multiple counters simultaneously.
205 * - For these functions you provide a bit field representing each counter in the TCPWM you want to control.
206 * - You can represent the bit field as an ORed mask of each counter, like ((1U << cntNumX) | (1U << cntNumX) | (1U << cntNumX)), where X is the counter number from 0 to 31.
207 *
208 * \note
209 * * If none of the input terminals (start, reload(index)) are used, the
210 * software event \ref Cy_TCPWM_TriggerStart or
211 * \ref Cy_TCPWM_TriggerReloadOrIndex must be called to start the counting.
212 * * If count input terminal is not used, the \ref CY_TCPWM_INPUT_LEVEL macro
213 * should be set for the countInputMode parameter and the \ref CY_TCPWM_INPUT_1
214 * macro should be set for the countInput parameter in the configuration
215 * structure of the appropriate mode(Counter
216 * \ref group_tcpwm_data_structures_counter, PWM
217 * \ref group_tcpwm_data_structures_pwm, QuadDec
218 * \ref group_tcpwm_data_structures_quaddec, or Shift Register
219 * \ref group_tcpwm_data_structures_shiftreg).
220
221 * \section group_tcpwm_more_information More Information
222 *
223 * For more information on the TCPWM peripheral, refer to the technical
224 * reference manual (TRM).
225 *
226 * \section group_tcpwm_changelog Changelog
227 * <table class="doxtable">
228 * <tr><th>Version</th><th>Changes</th><th>Reason for Change</th></tr>
229 * <tr>
230 * <td rowspan="2">1.70</td>
231 * <td> Newly added enum \ref cy_en_copy_swap_config_t.
232 * - Newly added API \ref Cy_TCPWM_Counter_SetDirection_Change_Mode and updated API \ref Cy_TCPWM_Block_EnableSwap.
233 * </td>
234 * <td> Supported Glitch filter with configurable depth, HW look-up table for advance motor control, bug fixes and enhancement in reload and swap functionality.</td>
235 * </tr>
236 * <tr>
237 * <td>Newly added APIs :
238 * - \ref Cy_TCPWM_PWM_SetDT, \ref Cy_TCPWM_PWM_Configure_LineSelect, \ref Cy_TCPWM_PWM_Configure_LineSelectBuff,
239 * - \ref Cy_TCPWM_PWM_EnableLineSelectSwap, \ref Cy_TCPWM_PWM_Set_KillLinePolarity, \ref Cy_TCPWM_PWM_PWMDeadTimeBuff
240 * - \ref Cy_TCPWM_PWM_PWMDeadTimeBuffN, \ref Cy_TCPWM_PWM_SetDTBuff. </td>
241 *
242 * Updated the following APIs:
243 * - \ref Cy_TCPWM_PWM_Init
244 * - \ref Cy_TCPWM_PWM_Configure_Dithering
245 *
246 * Newly added and updated enums:
247 * - \ref cy_en_hrpwm_operating_frequency_t
248 * - \ref cy_en_kill_line_polarity_t
249 * - \ref cy_en_line_select_config_t
250 * - \ref cy_stc_tcpwm_pwm_config_t
251 * <td>Support for line select, HRPWM enhancements, enhancement in DT BUFF and SWAP ENABLE handling. </td>
252 * </tr>
253 * <tr>
254 * <td>1.60</td>
255 * <td>Newly Added \ref Cy_TCPWM_OutputTriggerSetup API and code enhancement. </td>
256 * <td>Glitch filter support added for TCPWM version 3 and above.</td>
257 * </tr>
258 * <tr>
259 * <td>1.50</td>
260 * <td>
261 * <ul>
262 * <li>Newly Added \ref cy_en_gf_depth_value_t, \ref cy_en_counter_direction_t , \ref cy_en_tcpwm_dithering_t and \ref cy_en_dithering_limiter_t enums.<br>
263 * <li> Newly Added \ref Cy_TCPWM_Block_EnableSwap , \ref Cy_TCPWM_InputTriggerSetupWithGF , \ref Cy_TCPWM_Counter_EnableSwap , \ref Cy_TCPWM_QuadDec_EnableSwap and \ref Cy_TCPWM_Shiftreg_EnableSwap APIs.<br>
264 * </ul>
265 * <td>
266 * <ul>
267 * <li>Support for IP version 3.0.<br>
268 * <li>Bug fixes.<br>
269 * <li>Documentation update.</td>
270 * </ul>
271 * <tr>
272 * <td>1.40</td>
273 * <td>Support for CAT1B and CAT1D devices is added. No changes in public APIs interface and behavior. </td>
274 * <td>New devices support added.</td>
275 * </tr>
276 * <tr>
277 * <td>1.30.1</td>
278 * <td>Updated documentation of PWM mode. </td>
279 * <td>Documentation enhancement. </td>
280 * </tr>
281 * <tr>
282 * <td>1.30</td>
283 * <td>Added new option to Swap Overflow/Underflow behavior in PWM Centre/Asymmetric Alignment modes.</td>
284 * <td>New feature.</td>
285 * </tr>
286 * <tr>
287 * <td>1.20</td>
288 * <td>Added new features: Shift Register, New QuadDec modes, Additional Compare/Capture Buffer.</td>
289 * <td>New silicon family support.</td>
290 * </tr>
291 * <tr>
292 * <td>1.10.2</td>
293 * <td>Minor documentation updates.</td>
294 * <td>Documentation enhancement.</td>
295 * </tr>
296 * <tr>
297 * <td>1.10.1</td>
298 * <td>Added header guards CY_IP_MXTCPWM.</td>
299 * <td>To enable the PDL compilation with wounded out IP blocks.</td>
300 * </tr>
301 * <tr>
302 * <td rowspan="2">1.10</td>
303 * <td>Flattened the organization of the driver source code into the single
304 * source directory and the single include directory.
305 * </td>
306 * <td>Driver library directory-structure simplification.</td>
307 * </tr>
308 * <tr>
309 * <td>Added register access layer. Use register access macros instead
310 * of direct register access using dereferenced pointers.</td>
311 * <td>Makes register access device-independent, so that the PDL does
312 * not need to be recompiled for each supported part number.</td>
313 * </tr>
314 * <tr>
315 * <td>1.0.1</td>
316 * <td>Added a deviation to the MISRA Compliance section.
317 * Added function-level code snippets.</td>
318 * <td>Documentation update and clarification</td>
319 * </tr>
320 * <tr>
321 * <td>1.0</td>
322 * <td>Initial version</td>
323 * <td></td>
324 * </tr>
325 * </table>
326 */
327
328 /** \} group_tcpwm */
329
330 /**
331 * \addtogroup group_tcpwm_common
332 * Common API for the Timer Counter PWM Block.
333 *
334 * This is the common API that provides an interface to the TCPWM hardware.
335 * The Timer Counter, PWM, and Quadrature Decoder drivers use this common API.
336 * Most users will use individual drivers and do not need to use the common
337 * API for the TCPWM.
338 *
339 * The functions and other declarations used in this part of the driver are in cy_tcpwm.h.
340 * Include either of cy_tcpwm_counter.h, cy_tcpwm_pwm.h, cy_tcpwm_quaddec.h
341 * depending on the desired functionality. You can also include cy_pdl.h
342 * to get access to all functions and declarations in the PDL.
343 *
344 * \{
345 * \defgroup group_tcpwm_macros_common Macros
346 * \defgroup group_tcpwm_functions_common Functions
347 * \defgroup group_tcpwm_data_structures_common Data Structures
348 * \defgroup group_tcpwm_enums Enumerated Types
349 */
350
351
352 #if !defined(CY_TCPWM_H)
353 #define CY_TCPWM_H
354
355 #include <stdint.h>
356 #include <stdbool.h>
357 #include <stddef.h>
358 #include "cy_syslib.h"
359 #include "cy_device_headers.h"
360 #include "cy_device.h"
361
362 #ifdef CY_IP_MXTCPWM
363
364 #if defined(__cplusplus)
365 extern "C" {
366 #endif
367
368 /**
369 * \addtogroup group_tcpwm_macros_common
370 * \{
371 */
372
373 /** Driver major version */
374 #define CY_TCPWM_DRV_VERSION_MAJOR 1
375
376 /** Driver minor version */
377 #define CY_TCPWM_DRV_VERSION_MINOR 70
378
379
380 /******************************************************************************
381 * API Constants
382 ******************************************************************************/
383
384 /** TCPWM driver identifier */
385 #define CY_TCPWM_ID (CY_PDL_DRV_ID(0x2DU))
386
387 /** \defgroup group_tcpwm_input_selection TCPWM Input Selection
388 * \{
389 * Selects which input to use
390 */
391 #define CY_TCPWM_INPUT_0 (0U) /**< Input is tied to logic 0 */
392 #define CY_TCPWM_INPUT_1 (1U) /**< Input is tied to logic 1 */
393 #define CY_TCPWM_INPUT_TRIG_0 (2U) /**< Input is connected to the trigger input 0 */
394 #define CY_TCPWM_INPUT_TRIG_1 (3U) /**< Input is connected to the trigger input 1 */
395 #define CY_TCPWM_INPUT_TRIG_2 (4U) /**< Input is connected to the trigger input 2 */
396 #define CY_TCPWM_INPUT_TRIG_3 (5U) /**< Input is connected to the trigger input 3 */
397 #define CY_TCPWM_INPUT_TRIG_4 (6U) /**< Input is connected to the trigger input 4 */
398 #define CY_TCPWM_INPUT_TRIG_5 (7U) /**< Input is connected to the trigger input 5 */
399 #define CY_TCPWM_INPUT_TRIG_6 (8U) /**< Input is connected to the trigger input 6 */
400 #define CY_TCPWM_INPUT_TRIG_7 (9U) /**< Input is connected to the trigger input 7 */
401 #define CY_TCPWM_INPUT_TRIG_8 (10U) /**< Input is connected to the trigger input 8 */
402 #define CY_TCPWM_INPUT_TRIG_9 (11U) /**< Input is connected to the trigger input 9 */
403 #define CY_TCPWM_INPUT_TRIG_10 (12U) /**< Input is connected to the trigger input 10 */
404 #define CY_TCPWM_INPUT_TRIG_11 (13U) /**< Input is connected to the trigger input 11 */
405 #define CY_TCPWM_INPUT_TRIG_12 (14U) /**< Input is connected to the trigger input 12 */
406 #define CY_TCPWM_INPUT_TRIG_13 (15U) /**< Input is connected to the trigger input 13 */
407
408 #if (CY_IP_MXTCPWM_VERSION >= 2U) || defined(CY_DOXYGEN)
409
410 #ifndef TCPWM_TR_ONE_CNT_NR
411 #define CY_TCPWM_INPUT_TRIG_WITH_INST(n,m) (n + TCPWM ##m## _TR_ONE_CNT_NR + 2U) /**< Input is connected to the trigger input n - all purpose trigger,
412 * m is the TCPWM instance number.*/
413 #else
414 #define CY_TCPWM_INPUT_TRIG(n) (n + TCPWM_TR_ONE_CNT_NR + 2U) /**< Input is connected to the trigger input n - all purpose trigger */
415
416 #endif /* TCPWM_TR_ONE_CNT_NR */
417 #endif /* (CY_IP_MXTCPWM_VERSION >= 2U) || defined(CY_DOXYGEN) */
418
419 /** Input is defined by Creator, and Init() function does not need to configure input */
420 #define CY_TCPWM_INPUT_CREATOR (0xFFFFFFFFU)
421 /** \} group_tcpwm_input_selection */
422
423 /**
424 * \defgroup group_tcpwm_input_modes Input Modes
425 * \{
426 * Configures how TCPWM inputs behave
427 */
428 /** A rising edge triggers the event (Capture, Start, Reload, etc..) */
429 #define CY_TCPWM_INPUT_RISINGEDGE (0U)
430 /** A falling edge triggers the event (Capture, Start, Reload, etc..) */
431 #define CY_TCPWM_INPUT_FALLINGEDGE (1U)
432 /** A rising edge or falling edge triggers the event (Capture, Start, Reload, etc..) */
433 #define CY_TCPWM_INPUT_EITHEREDGE (2U)
434 /** The event is triggered on each edge of the TCPWM clock if the input is high */
435 #define CY_TCPWM_INPUT_LEVEL (3U)
436 /** \} group_tcpwm_input_modes */
437
438 /**
439 * \defgroup group_tcpwm_output_trigger_modes Output Trigger Modes
440 * \{
441 * Configures how TCPWM output triggers behave (TCPWM_v2 only)
442 */
443 /** Output trigger generates signal on overflow event */
444 #define CY_TCPWM_CNT_TRIGGER_ON_OVERFLOW (0U)
445 /** Output trigger generates signal on underflow event */
446 #define CY_TCPWM_CNT_TRIGGER_ON_UNDEFLOW (1U)
447 /** Output trigger generates signal on terminal count event */
448 #define CY_TCPWM_CNT_TRIGGER_ON_TC (2U)
449 /** Output trigger generates signal on compare/capture 0 event */
450 #define CY_TCPWM_CNT_TRIGGER_ON_CC0_MATCH (3U)
451 /** Output trigger generates signal on compare/capture 1 event */
452 #define CY_TCPWM_CNT_TRIGGER_ON_CC1_MATCH (4U)
453 /** Output trigger generates the same signal as line_out */
454 #define CY_TCPWM_CNT_TRIGGER_ON_LINE_OUT (5U)
455 #if defined (CY_IP_MXS40TCPWM) || defined (CY_DOXYGEN)
456 /** Output trigger generates signal on compare/capture 0 or event */
457 #define CY_TCPWM_CNT_TRIGGER_ON_CC0_OR_CC1_MATCH (6U)
458 #endif /* defined (CY_IP_MXS40TCPWM) || defined (CY_DOXYGEN) */
459 /** Output trigger disabled */
460 #define CY_TCPWM_CNT_TRIGGER_ON_DISABLED (7U)
461 /** \} group_tcpwm_output_trigger_modes */
462
463 /**
464 * \defgroup group_tcpwm_interrupt_sources Interrupt Sources
465 * \{
466 * Interrupt Sources
467 */
468 #define CY_TCPWM_INT_NONE (0U) /**< No Interrupt */
469 #define CY_TCPWM_INT_ON_TC (1U) /**< Interrupt on Terminal count(TC) */
470 #define CY_TCPWM_INT_ON_CC0 (2U) /**< Interrupt on Compare 0/Capture 0(CC0) */
471 #define CY_TCPWM_INT_ON_CC0_OR_TC (3U) /**< Interrupt on TC or CC0 */
472 #define CY_TCPWM_INT_ON_CC1 (4U) /**< Interrupt on Compare 1/Capture 1(CC1)*/
473 /** \} group_tcpwm_interrupt_sources */
474
475 /***************************************
476 * Registers Constants
477 ***************************************/
478
479 /**
480 * \defgroup group_tcpwm_reg_const Default registers constants
481 * \{
482 * Default constants for CNT Registers
483 */
484 #define CY_TCPWM_CNT_CTRL_DEFAULT (0x0U) /**< Default value for CTRL register */
485 #define CY_TCPWM_CNT_COUNTER_DEFAULT (0x0U) /**< Default value for COUNTER register */
486 #define CY_TCPWM_CNT_CC_DEFAULT (0xFFFFFFFFU) /**< Default value for CC register */
487 #define CY_TCPWM_CNT_CC_BUFF_DEFAULT (0xFFFFFFFFU) /**< Default value for CC_BUFF register */
488 #define CY_TCPWM_CNT_PERIOD_DEFAULT (0xFFFFFFFFU) /**< Default value for PERIOD register */
489 #define CY_TCPWM_CNT_PERIOD_BUFF_DEFAULT (0xFFFFFFFFU) /**< Default value for PERIOD_BUFF register */
490 #define CY_TCPWM_CNT_TR_CTRL0_DEFAULT (0x10U) /**< Default value for TR_CTRL0 register */
491 #define CY_TCPWM_CNT_TR_CTRL1_DEFAULT (0x3FFU) /**< Default value for TR_CTRL1 register */
492 #define CY_TCPWM_CNT_TR_CTRL2_DEFAULT (0x3FU) /**< Default value for TR_CTRL2 register */
493 #define CY_TCPWM_CNT_INTR_DEFAULT (0x3U) /**< Default value for INTR register */
494 #define CY_TCPWM_CNT_INTR_SET_DEFAULT (0x0U) /**< Default value for INTR_SET register */
495 #define CY_TCPWM_CNT_INTR_MASK_DEFAULT (0x0U) /**< Default value for INTR_MASK register */
496
497 #define CY_TCPWM_GRP_CNT_CTRL_DEFAULT (0xF0U) /**< Default value for CTRL register */
498 #define CY_TCPWM_GRP_CNT_DT_DEFAULT (0x0U) /**< Default value for DT register */
499 #define CY_TCPWM_GRP_CNT_COUNTER_DEFAULT (0x0U) /**< Default value for COUNTER register */
500 #define CY_TCPWM_GRP_CNT_CC0_DEFAULT (0xFFFFFFFFU) /**< Default value for CC0 register */
501 #define CY_TCPWM_GRP_CNT_CC0_BUFF_DEFAULT (0xFFFFFFFFU) /**< Default value for CC0_BUFF register */
502 #define CY_TCPWM_GRP_CNT_CC1_DEFAULT (0xFFFFFFFFU) /**< Default value for CC0 register */
503 #define CY_TCPWM_GRP_CNT_CC1_BUFF_DEFAULT (0xFFFFFFFFU) /**< Default value for CC0_BUFF register */
504 #define CY_TCPWM_GRP_CNT_PERIOD_DEFAULT (0xFFFFFFFFU) /**< Default value for PERIOD register */
505 #define CY_TCPWM_GRP_CNT_PERIOD_BUFF_DEFAULT (0xFFFFFFFFU) /**< Default value for PERIOD_BUFF register */
506 #define CY_TCPWM_GRP_CNT_TR_PWM_CTRL_DEFAULT (0xFFFU) /**< Default value for TR_PWM_CTRL register */
507 #define CY_TCPWM_GRP_CNT_TR_IN_SEL0_DEFAULT (0x100U) /**< Default value for TR_IN_SEL0 register */
508 #define CY_TCPWM_GRP_CNT_TR_IN_SEL1_DEFAULT (0x0U) /**< Default value for TR_IN_SEL1 register */
509 #define CY_TCPWM_GRP_CNT_TR_IN_EDGE_SEL_DEFAULT (0xFFFU) /**< Default value for TR_IN_EDGE_SEL register */
510 #define CY_TCPWM_GRP_CNT_INTR_MASK_DEFAULT (0x0U) /**< Default value for INTR_MASK register */
511
512 /** \} group_tcpwm_reg_const */
513
514 /** Position of Up counting counter status */
515 #define CY_TCPWM_CNT_STATUS_UP_POS (0x1U)
516 /** Initial value for the counter in the Up counting mode */
517 #define CY_TCPWM_CNT_UP_INIT_VAL (0x0U)
518 /** Initial value for the counter in the Up/Down counting modes */
519 #define CY_TCPWM_CNT_UP_DOWN_INIT_VAL (0x1U)
520 /** \} group_tcpwm_macros_common */
521
522
523 /*******************************************************************************
524 * Enumerations
525 ******************************************************************************/
526
527 /**
528 * \addtogroup group_tcpwm_enums
529 * \{
530 */
531
532 /** TCPWM Input Triggers */
533 typedef enum
534 {
535 CY_TCPWM_INPUT_TR_START = 0x00U, /**< Start */
536 CY_TCPWM_INPUT_TR_RELOAD_OR_INDEX = 0x01U, /**< Reload/Index */
537 CY_TCPWM_INPUT_TR_STOP_OR_KILL = 0x02U, /**< Stop/Kill */
538 CY_TCPWM_INPUT_TR_COUNT = 0x03U, /**< Count */
539 CY_TCPWM_INPUT_TR_INDEX_OR_SWAP = 0x04U, /**< Index/Swap */
540 CY_TCPWM_INPUT_TR_CAPTURE0 = 0x04U, /**< Capture 0 */
541 CY_TCPWM_INPUT_TR_CAPTURE1 = 0x05U /**< Capture 1 */
542 } cy_en_tcpwm_trigselect_t;
543
544 /** TCPWM output Triggers */
545 typedef enum
546 {
547 CY_TCPWM_OUTPUT_TR_OVERFLOW = 0x00U, /**< Overflow Event */
548 CY_TCPWM_OUTPUT_TR_UNDERFLOW = 0x01U, /**< Underflow Event */
549 CY_TCPWM_OUTPUT_TR_TC_EVENT = 0x02U, /**< Terminal Count Event */
550 CY_TCPWM_OUTPUT_TR_CC0_MATCH = 0x03U, /**< Compare Match 0 Event */
551 CY_TCPWM_OUTPUT_TR_CC1_MATCH = 0x04U, /**< Compare Match 1 Event */
552 CY_TCPWM_OUTPUT_TR_LINE_OUT = 0x05U, /**< PWM Output Signal Line Out */
553 #if defined (CY_IP_MXS40TCPWM) || defined (CY_DOXYGEN)
554 CY_TCPWM_OUTPUT_TR_CC0ORCC1_MATCH = 0x06U, /**< Compare Match 0 Event or Compare Match 1 Event */
555 #endif /* defined (CY_IP_MXS40TCPWM) || defined (CY_DOXYGEN) */
556 CY_TCPWM_OUTPUT_TR_DISABLED = 0x07U /**< Trigger Out Disabled */
557 } cy_en_tcpwm_output_trigselect_t;
558
559 /** TCPWM status definitions */
560 typedef enum
561 {
562 CY_TCPWM_SUCCESS = 0x00U, /**< Successful */
563 CY_TCPWM_BAD_PARAM = CY_TCPWM_ID | CY_PDL_STATUS_ERROR | 0x01U, /**< One or more invalid parameters */
564 CY_TCPWM_UNSUPPORTED_FEATURE = CY_TCPWM_ID | CY_PDL_STATUS_ERROR | 0x02U, /**< Feature Unsupported */
565 } cy_en_tcpwm_status_t;
566
567 #if defined (CY_IP_MXS40TCPWM) || defined (CY_DOXYGEN)
568
569 /** Glitch filter depth support values */
570 typedef enum
571 {
572 CY_GLITCH_FILTER_DEPTH_SUPPORT_VALUE_0 = 0UL, /**< GLitch filter depth value 0. */
573 CY_GLITCH_FILTER_DEPTH_SUPPORT_VALUE_1 = 1UL, /**< GLitch filter depth value 1. */
574 CY_GLITCH_FILTER_DEPTH_SUPPORT_VALUE_2 = 2UL, /**< GLitch filter depth value 2. */
575 CY_GLITCH_FILTER_DEPTH_SUPPORT_VALUE_4 = 3UL, /**< GLitch filter depth value 4. */
576 CY_GLITCH_FILTER_DEPTH_SUPPORT_VALUE_8 = 4UL, /**< GLitch filter depth value 8. */
577 CY_GLITCH_FILTER_DEPTH_SUPPORT_VALUE_16 = 5UL, /**< GLitch filter depth value 16 */
578 CY_GLITCH_FILTER_DEPTH_SUPPORT_VALUE_32 = 6UL, /**< GLitch filter depth value 32 */
579 CY_GLITCH_FILTER_DEPTH_SUPPORT_VALUE_64 = 7UL, /**< GLitch filter depth value 64 */
580 CY_GLITCH_FILTER_DEPTH_SUPPORT_VALUE_128 = 8UL, /**< GLitch filter depth value 128 */
581 CY_GLITCH_FILTER_DEPTH_SUPPORT_VALUE_256 = 9UL, /**< GLitch filter depth value 256 */
582 CY_GLITCH_FILTER_DEPTH_SUPPORT_VALUE_512 = 10UL, /**< GLitch filter depth value 512 */
583 } cy_en_gf_depth_value_t;
584
585 /** Copy or Swap values for CC0, CC1, Period and DT
586 * 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
587 * When only reload is enabled then CC_BUFF/CC1_BUFF/PERIOD_BUFF/DT_BUFF values are copied to CC0/CC1/PERIOD/DT respectively.
588 * There is no action when reload is disabled.
589 * Reload is enabled/disabled with the API's Cy_TCPWM_Block_EnableCompare0Swap, Cy_TCPWM_Block_EnableCompare1Swap, Cy_TCPWM_PWM_EnablePeriodSwap */
590 typedef enum
591 {
592 CY_TCPWM_DISBALE_COPY_OR_SWAP = 0UL, /**< Reload is disabled. There is no copy or swap enabled. */
593 CY_TCPWM_COPY_CAPTUREBUFFER_VALUE_TO_CAPTURE = 1UL, /**< Copies the capture buffer value to the capture. */
594 CY_TCPWM_SWAP_CAPTUREBUFFER_AND_CAPTURE_VALUE = 2UL, /**< Values of capture buffer and capture are exchanged. */
595 } cy_en_copy_swap_config_t;
596
597 #endif /* defined (CY_IP_MXS40TCPWM) || defined (CY_DOXYGEN) */
598 /** \} group_tcpwm_enums */
599
600 /*******************************************************************************
601 * Function Prototypes
602 *******************************************************************************/
603
604 /**
605 * \addtogroup group_tcpwm_functions_common
606 * \{
607 */
608
609 #if (CY_IP_MXTCPWM_VERSION == 1U) || defined(CY_DOXYGEN)
610 __STATIC_INLINE void Cy_TCPWM_Enable_Multiple(TCPWM_Type *base, uint32_t counters);
611 __STATIC_INLINE void Cy_TCPWM_Disable_Multiple(TCPWM_Type *base, uint32_t counters);
612 __STATIC_INLINE void Cy_TCPWM_TriggerStart(TCPWM_Type *base, uint32_t counters);
613 __STATIC_INLINE void Cy_TCPWM_TriggerReloadOrIndex(TCPWM_Type *base, uint32_t counters);
614 __STATIC_INLINE void Cy_TCPWM_TriggerStopOrKill(TCPWM_Type *base, uint32_t counters);
615 __STATIC_INLINE void Cy_TCPWM_TriggerCaptureOrSwap(TCPWM_Type *base, uint32_t counters);
616 #endif
617 __STATIC_INLINE void Cy_TCPWM_Enable_Single(TCPWM_Type *base, uint32_t cntNum);
618 __STATIC_INLINE void Cy_TCPWM_Disable_Single(TCPWM_Type *base, uint32_t cntNum);
619 __STATIC_INLINE uint32_t Cy_TCPWM_GetInterruptStatus(TCPWM_Type const *base, uint32_t cntNum);
620 __STATIC_INLINE void Cy_TCPWM_ClearInterrupt(TCPWM_Type *base, uint32_t cntNum, uint32_t source);
621 __STATIC_INLINE void Cy_TCPWM_SetInterrupt(TCPWM_Type *base, uint32_t cntNum, uint32_t source);
622 __STATIC_INLINE void Cy_TCPWM_SetInterruptMask(TCPWM_Type *base, uint32_t cntNum, uint32_t mask);
623 __STATIC_INLINE uint32_t Cy_TCPWM_GetInterruptMask(TCPWM_Type const *base, uint32_t cntNum);
624 __STATIC_INLINE uint32_t Cy_TCPWM_GetInterruptStatusMasked(TCPWM_Type const *base, uint32_t cntNum);
625 __STATIC_INLINE void Cy_TCPWM_TriggerStart_Single(TCPWM_Type *base, uint32_t cntNum);
626 __STATIC_INLINE void Cy_TCPWM_TriggerReloadOrIndex_Single(TCPWM_Type *base, uint32_t cntNum);
627 __STATIC_INLINE void Cy_TCPWM_TriggerStopOrKill_Single(TCPWM_Type *base, uint32_t cntNum);
628 __STATIC_INLINE void Cy_TCPWM_TriggerCaptureOrSwap_Single(TCPWM_Type *base, uint32_t cntNum);
629 __STATIC_INLINE void Cy_TCPWM_TriggerCapture0(TCPWM_Type *base, uint32_t cntNum);
630 #if (CY_IP_MXTCPWM_VERSION >= 2U) || defined(CY_DOXYGEN)
631 __STATIC_INLINE void Cy_TCPWM_TriggerCapture1(TCPWM_Type *base, uint32_t cntNum);
632 __STATIC_INLINE bool Cy_TCPWM_GetTrigPinLevel (TCPWM_Type const *base, uint32_t cntNum, cy_en_tcpwm_trigselect_t triggerSelect);
633 __STATIC_INLINE void Cy_TCPWM_InputTriggerSetup (TCPWM_Type *base, uint32 cntNum, cy_en_tcpwm_trigselect_t triggerSelect, uint32_t edgeSelect, uint32_t triggerSignal);
634 __STATIC_INLINE void Cy_TCPWM_OutputTriggerSetup (TCPWM_Type *base, uint32 cntNum, cy_en_tcpwm_output_trigselect_t trigger0event, cy_en_tcpwm_output_trigselect_t trigger1event);
635 __STATIC_INLINE cy_en_tcpwm_status_t Cy_TCPWM_SetDebugFreeze (TCPWM_Type *base, uint32 cntNum, bool enable);
636 #endif
637 /** \cond INTERNAL */
638 __STATIC_INLINE uint32_t Cy_TCPWM_Block_GetCC0Val(TCPWM_Type const *base, uint32_t cntNum);
639 __STATIC_INLINE uint32_t Cy_TCPWM_Block_GetCC0BufVal(TCPWM_Type const *base, uint32_t cntNum);
640 __STATIC_INLINE uint32_t Cy_TCPWM_Block_GetCounter(TCPWM_Type const *base, uint32_t cntNum);
641 __STATIC_INLINE void Cy_TCPWM_Block_SetCounter(TCPWM_Type *base, uint32_t cntNum, uint32_t count);
642 __STATIC_INLINE void Cy_TCPWM_Block_SetPeriod(TCPWM_Type *base, uint32_t cntNum, uint32_t period);
643 __STATIC_INLINE uint32_t Cy_TCPWM_Block_GetPeriod(TCPWM_Type const *base, uint32_t cntNum);
644 __STATIC_INLINE void Cy_TCPWM_Block_SetCC0BufVal(TCPWM_Type *base, uint32_t cntNum, uint32_t compare1);
645 __STATIC_INLINE void Cy_TCPWM_Block_SetCC0Val(TCPWM_Type *base, uint32_t cntNum, uint32_t compare0);
646 __STATIC_INLINE void Cy_TCPWM_Block_EnableCompare0Swap(TCPWM_Type *base, uint32_t cntNum, bool enable);
647 #if (CY_IP_MXTCPWM_VERSION >= 2U) || defined (CY_DOXYGEN)
648 __STATIC_INLINE void Cy_TCPWM_Block_EnableCompare1Swap(TCPWM_Type *base, uint32_t cntNum, bool enable);
649 __STATIC_INLINE uint32_t Cy_TCPWM_Block_GetCC1Val(TCPWM_Type const *base, uint32_t cntNum);
650 __STATIC_INLINE uint32_t Cy_TCPWM_Block_GetCC1BufVal(TCPWM_Type const *base, uint32_t cntNum);
651 __STATIC_INLINE void Cy_TCPWM_Block_SetCC1BufVal(TCPWM_Type *base, uint32_t cntNum, uint32_t compareBuf1);
652 __STATIC_INLINE void Cy_TCPWM_Block_SetCC1Val(TCPWM_Type *base, uint32_t cntNum, uint32_t compare1);
653 #endif
654 #if defined (CY_IP_MXS40TCPWM) || defined (CY_DOXYGEN)
655 __STATIC_INLINE void Cy_TCPWM_Block_EnableSwap(TCPWM_Type *base, uint32_t cntNum, bool enable);
656 __STATIC_INLINE void Cy_TCPWM_InputTriggerSetupWithGF (TCPWM_Type *base, uint32 cntNum, cy_en_tcpwm_trigselect_t triggerSelect, uint32_t edgeSelect, uint32_t triggerSignal, cy_en_gf_depth_value_t dsvalue);
657 #endif /* defined (CY_IP_MXS40TCPWM) || defined (CY_DOXYGEN) */
658
659 /** \endcond */
660
661 /** \cond INTERNAL */
Cy_TCPWM_Block_GetCC0Val(TCPWM_Type const * base,uint32_t cntNum)662 __STATIC_INLINE uint32_t Cy_TCPWM_Block_GetCC0Val(TCPWM_Type const *base, uint32_t cntNum)
663 {
664 uint32_t result;
665
666 #if (CY_IP_MXTCPWM_VERSION == 1U)
667 result = (TCPWM_CNT_CC(base, cntNum));
668 #else
669 result = (TCPWM_GRP_CNT_CC0(base, TCPWM_GRP_CNT_GET_GRP(cntNum), cntNum));
670 #endif
671 return result;
672 }
Cy_TCPWM_Block_GetCC0BufVal(TCPWM_Type const * base,uint32_t cntNum)673 __STATIC_INLINE uint32_t Cy_TCPWM_Block_GetCC0BufVal(TCPWM_Type const *base, uint32_t cntNum)
674 {
675 uint32_t result;
676
677 #if (CY_IP_MXTCPWM_VERSION == 1U)
678 result = (TCPWM_CNT_CC_BUFF(base, cntNum));
679 #else
680 result = (TCPWM_GRP_CNT_CC0_BUFF(base, TCPWM_GRP_CNT_GET_GRP(cntNum), cntNum));
681 #endif
682
683 return result;
684 }
Cy_TCPWM_Block_GetCounter(TCPWM_Type const * base,uint32_t cntNum)685 __STATIC_INLINE uint32_t Cy_TCPWM_Block_GetCounter(TCPWM_Type const *base, uint32_t cntNum)
686 {
687 uint32_t result;
688
689 #if (CY_IP_MXTCPWM_VERSION == 1U)
690 result = TCPWM_CNT_COUNTER(base, cntNum);
691 #else
692 result = TCPWM_GRP_CNT_COUNTER(base, TCPWM_GRP_CNT_GET_GRP(cntNum), cntNum);
693 #endif
694
695 return result;
696 }
Cy_TCPWM_Block_SetCounter(TCPWM_Type * base,uint32_t cntNum,uint32_t count)697 __STATIC_INLINE void Cy_TCPWM_Block_SetCounter(TCPWM_Type *base, uint32_t cntNum, uint32_t count)
698 {
699 #if (CY_IP_MXTCPWM_VERSION == 1U)
700
701 TCPWM_CNT_COUNTER(base, cntNum) = count;
702 #else
703 TCPWM_GRP_CNT_COUNTER(base, TCPWM_GRP_CNT_GET_GRP(cntNum), cntNum) = count;
704 #endif
705 }
Cy_TCPWM_Block_SetPeriod(TCPWM_Type * base,uint32_t cntNum,uint32_t period)706 __STATIC_INLINE void Cy_TCPWM_Block_SetPeriod(TCPWM_Type *base, uint32_t cntNum, uint32_t period)
707 {
708 #if (CY_IP_MXTCPWM_VERSION == 1U)
709
710 TCPWM_CNT_PERIOD(base, cntNum) = period;
711 #else
712 TCPWM_GRP_CNT_PERIOD(base, TCPWM_GRP_CNT_GET_GRP(cntNum), cntNum) = period;
713 #endif
714 }
Cy_TCPWM_Block_GetPeriod(TCPWM_Type const * base,uint32_t cntNum)715 __STATIC_INLINE uint32_t Cy_TCPWM_Block_GetPeriod(TCPWM_Type const *base, uint32_t cntNum)
716 {
717 uint32_t result;
718
719 #if (CY_IP_MXTCPWM_VERSION == 1U)
720
721 result = TCPWM_CNT_PERIOD(base, cntNum);
722 #else
723 result = TCPWM_GRP_CNT_PERIOD(base, TCPWM_GRP_CNT_GET_GRP(cntNum), cntNum);
724 #endif
725 return result;
726 }
Cy_TCPWM_Block_SetCC0BufVal(TCPWM_Type * base,uint32_t cntNum,uint32_t compare1)727 __STATIC_INLINE void Cy_TCPWM_Block_SetCC0BufVal(TCPWM_Type *base, uint32_t cntNum, uint32_t compare1)
728 {
729 #if (CY_IP_MXTCPWM_VERSION == 1U)
730 TCPWM_CNT_CC_BUFF(base, cntNum) = compare1;
731 #else
732 TCPWM_GRP_CNT_CC0_BUFF(base, TCPWM_GRP_CNT_GET_GRP(cntNum), cntNum) = compare1;
733 #endif
734 }
Cy_TCPWM_Block_SetCC0Val(TCPWM_Type * base,uint32_t cntNum,uint32_t compare0)735 __STATIC_INLINE void Cy_TCPWM_Block_SetCC0Val(TCPWM_Type *base, uint32_t cntNum, uint32_t compare0)
736 {
737 #if (CY_IP_MXTCPWM_VERSION == 1U)
738 TCPWM_CNT_CC(base, cntNum) = compare0;
739 #else
740 TCPWM_GRP_CNT_CC0(base, TCPWM_GRP_CNT_GET_GRP(cntNum), cntNum) = compare0;
741 #endif
742 }
Cy_TCPWM_Block_EnableCompare0Swap(TCPWM_Type * base,uint32_t cntNum,bool enable)743 __STATIC_INLINE void Cy_TCPWM_Block_EnableCompare0Swap(TCPWM_Type *base, uint32_t cntNum, bool enable)
744 {
745 #if (CY_IP_MXTCPWM_VERSION == 1U)
746
747 if (enable)
748 {
749 TCPWM_CNT_CTRL(base, cntNum) |= TCPWM_CNT_CTRL_AUTO_RELOAD_CC_Msk;
750 }
751 else
752 {
753 TCPWM_CNT_CTRL(base, cntNum) &= ~TCPWM_CNT_CTRL_AUTO_RELOAD_CC_Msk;
754 }
755 #else
756 if (enable)
757 {
758 TCPWM_GRP_CNT_CTRL(base, TCPWM_GRP_CNT_GET_GRP(cntNum), cntNum) |=
759 TCPWM_GRP_CNT_V2_CTRL_AUTO_RELOAD_CC0_Msk;
760 }
761 else
762 {
763 TCPWM_GRP_CNT_CTRL(base, TCPWM_GRP_CNT_GET_GRP(cntNum), cntNum) &=
764 ~TCPWM_GRP_CNT_V2_CTRL_AUTO_RELOAD_CC0_Msk;
765 }
766 #endif
767 }
768 #if (CY_IP_MXTCPWM_VERSION >= 2U) || defined (CY_DOXYGEN)
Cy_TCPWM_Block_EnableCompare1Swap(TCPWM_Type * base,uint32_t cntNum,bool enable)769 __STATIC_INLINE void Cy_TCPWM_Block_EnableCompare1Swap(TCPWM_Type *base, uint32_t cntNum, bool enable)
770 {
771 if (TCPWM_GRP_CC1(base, TCPWM_GRP_CNT_GET_GRP(cntNum)))
772 {
773 if (enable)
774 {
775 TCPWM_GRP_CNT_CTRL(base, TCPWM_GRP_CNT_GET_GRP(cntNum), cntNum) |=
776 TCPWM_GRP_CNT_V2_CTRL_AUTO_RELOAD_CC1_Msk;
777 }
778 else
779 {
780 TCPWM_GRP_CNT_CTRL(base, TCPWM_GRP_CNT_GET_GRP(cntNum), cntNum) &=
781 ~TCPWM_GRP_CNT_V2_CTRL_AUTO_RELOAD_CC1_Msk;
782 }
783 }
784 }
Cy_TCPWM_Block_GetCC1Val(TCPWM_Type const * base,uint32_t cntNum)785 __STATIC_INLINE uint32_t Cy_TCPWM_Block_GetCC1Val(TCPWM_Type const *base, uint32_t cntNum)
786 {
787 uint32_t result = 0UL;
788
789 if (TCPWM_GRP_CC1(base, TCPWM_GRP_CNT_GET_GRP(cntNum)))
790 {
791 result = TCPWM_GRP_CNT_CC1(base, TCPWM_GRP_CNT_GET_GRP(cntNum), cntNum);
792 }
793
794 return result;
795 }
Cy_TCPWM_Block_GetCC1BufVal(TCPWM_Type const * base,uint32_t cntNum)796 __STATIC_INLINE uint32_t Cy_TCPWM_Block_GetCC1BufVal(TCPWM_Type const *base, uint32_t cntNum)
797 {
798 uint32_t result = 0UL;
799
800 if (TCPWM_GRP_CC1(base, TCPWM_GRP_CNT_GET_GRP(cntNum)))
801 {
802 result = TCPWM_GRP_CNT_CC1_BUFF(base, TCPWM_GRP_CNT_GET_GRP(cntNum), cntNum);
803 }
804
805 return result;
806 }
Cy_TCPWM_Block_SetCC1BufVal(TCPWM_Type * base,uint32_t cntNum,uint32_t compareBuf1)807 __STATIC_INLINE void Cy_TCPWM_Block_SetCC1BufVal(TCPWM_Type *base, uint32_t cntNum, uint32_t compareBuf1)
808 {
809 if (TCPWM_GRP_CC1(base, TCPWM_GRP_CNT_GET_GRP(cntNum)))
810 {
811 TCPWM_GRP_CNT_CC1_BUFF(base, TCPWM_GRP_CNT_GET_GRP(cntNum), cntNum) = compareBuf1;
812 }
813 }
Cy_TCPWM_Block_SetCC1Val(TCPWM_Type * base,uint32_t cntNum,uint32_t compare1)814 __STATIC_INLINE void Cy_TCPWM_Block_SetCC1Val(TCPWM_Type *base, uint32_t cntNum, uint32_t compare1)
815 {
816 if (TCPWM_GRP_CC1(base, TCPWM_GRP_CNT_GET_GRP(cntNum)))
817 {
818 TCPWM_GRP_CNT_CC1(base, TCPWM_GRP_CNT_GET_GRP(cntNum), cntNum) = compare1;
819 }
820 }
821 #endif
822 /** \endcond */
823 #if (CY_IP_MXTCPWM_VERSION == 1U) || defined(CY_DOXYGEN)
824 /*******************************************************************************
825 * Function Name: Cy_TCPWM_Enable_Multiple
826 ****************************************************************************//**
827 *
828 * Enables the counter(s) in the TCPWM block. Multiple blocks can be started
829 * simultaneously.
830 *
831 * \param base
832 * The pointer to a TCPWM instance.
833 *
834 * \param counters
835 * A bit field representing each counter in the TCPWM block.
836 *
837 * \funcusage
838 * \snippet tcpwm/pwm/snippet/main.c snippet_Cy_TCPWM_Enable_Multiple
839 *
840 * \note supported only in TCPWM_ver1
841 *
842 *******************************************************************************/
Cy_TCPWM_Enable_Multiple(TCPWM_Type * base,uint32_t counters)843 __STATIC_INLINE void Cy_TCPWM_Enable_Multiple(TCPWM_Type *base, uint32_t counters)
844 {
845 TCPWM_CTRL_SET(base) = counters;
846 }
847
848
849 /*******************************************************************************
850 * Function Name: Cy_TCPWM_Disable_Multiple
851 ****************************************************************************//**
852 *
853 * Disables the counter(s) in the TCPWM block. Multiple TCPWM can be disabled
854 * simultaneously.
855 *
856 * \param base
857 * The pointer to a TCPWM instance.
858 *
859 * \param counters
860 * A bit field representing each counter in the TCPWM block.
861 *
862 * \funcusage
863 * \snippet tcpwm/pwm/snippet/main.c snippet_Cy_TCPWM_Disable_Multiple
864 *
865 * \note supported only in TCPWM_ver1
866 *
867 *******************************************************************************/
Cy_TCPWM_Disable_Multiple(TCPWM_Type * base,uint32_t counters)868 __STATIC_INLINE void Cy_TCPWM_Disable_Multiple(TCPWM_Type *base, uint32_t counters)
869 {
870 TCPWM_CTRL_CLR(base) = counters;
871 }
872
873
874 /*******************************************************************************
875 * Function Name: Cy_TCPWM_TriggerStart
876 ****************************************************************************//**
877 *
878 * Triggers a software start on the selected TCPWMs.
879 *
880 * \param base
881 * The pointer to a TCPWM instance.
882 *
883 * \param counters
884 * A bit field representing each counter in the TCPWM block.
885 *
886 * \funcusage
887 * \snippet tcpwm/pwm/snippet/main.c snippet_Cy_TCPWM_Enable_Multiple
888 *
889 * \note supported only in TCPWM_ver1
890 *
891 *******************************************************************************/
Cy_TCPWM_TriggerStart(TCPWM_Type * base,uint32_t counters)892 __STATIC_INLINE void Cy_TCPWM_TriggerStart(TCPWM_Type *base, uint32_t counters)
893 {
894 TCPWM_CMD_START(base) = counters;
895 }
896
897
898 /*******************************************************************************
899 * Function Name: Cy_TCPWM_TriggerReloadOrIndex
900 ****************************************************************************//**
901 *
902 * Triggers a software reload event (or index in QuadDec mode).
903 *
904 * \param base
905 * The pointer to a TCPWM instance
906 *
907 * \param counters
908 * A bit field representing each counter in the TCPWM block.
909 *
910 * \funcusage
911 * \snippet tcpwm/pwm/snippet/main.c snippet_Cy_TCPWM_TriggerReloadOrIndex
912 *
913 * \note supported only in TCPWM_ver1
914 *
915 *******************************************************************************/
Cy_TCPWM_TriggerReloadOrIndex(TCPWM_Type * base,uint32_t counters)916 __STATIC_INLINE void Cy_TCPWM_TriggerReloadOrIndex(TCPWM_Type *base, uint32_t counters)
917 {
918 TCPWM_CMD_RELOAD(base) = counters;
919 }
920
921
922 /*******************************************************************************
923 * Function Name: Cy_TCPWM_TriggerStopOrKill
924 ****************************************************************************//**
925 *
926 * Triggers a stop in the Timer Counter mode, or a kill in the PWM mode.
927 *
928 * \note The kill trigger behavior for PWM is defined by the
929 * \ref cy_stc_tcpwm_pwm_config_t::killMode field. The pins states after a kill
930 * trigger are defined by \ref cy_stc_tcpwm_pwm_config_t::invertPWMOut and
931 * \ref cy_stc_tcpwm_pwm_config_t::invertPWMOutN fields.
932 *
933 * \param base
934 * The pointer to a TCPWM instance.
935 *
936 * \param counters
937 * A bit field representing each counter in the TCPWM block.
938 *
939 * \funcusage
940 * \snippet tcpwm/pwm/snippet/main.c snippet_Cy_TCPWM_TriggerStopOrKill
941 *
942 * \note supported only in TCPWM_ver1
943 *
944 *******************************************************************************/
Cy_TCPWM_TriggerStopOrKill(TCPWM_Type * base,uint32_t counters)945 __STATIC_INLINE void Cy_TCPWM_TriggerStopOrKill(TCPWM_Type *base, uint32_t counters)
946 {
947 TCPWM_CMD_STOP(base) = counters;
948 }
949
950
951 /*******************************************************************************
952 * Function Name: Cy_TCPWM_TriggerCaptureOrSwap
953 ****************************************************************************//**
954 *
955 * Triggers a Capture in the Timer Counter mode, and a Swap in the PWM mode.
956 *
957 * \param base
958 * The pointer to a TCPWM instance.
959 *
960 * \param counters
961 * A bit field representing each counter in the TCPWM block.
962 *
963 * \funcusage
964 * \snippet tcpwm/counter/snippet/main.c snippet_Cy_TCPWM_Counter_Capture
965 *
966 * \note supported only in TCPWM_ver1
967 *
968 *******************************************************************************/
Cy_TCPWM_TriggerCaptureOrSwap(TCPWM_Type * base,uint32_t counters)969 __STATIC_INLINE void Cy_TCPWM_TriggerCaptureOrSwap(TCPWM_Type *base, uint32_t counters)
970 {
971 TCPWM_CMD_CAPTURE(base) = counters;
972 }
973 #endif
974 /*******************************************************************************
975 * Function Name: Cy_TCPWM_Enable_Single
976 ****************************************************************************//**
977 *
978 * Enables specified counter
979 *
980 * \param base
981 * The pointer to a TCPWM instance.
982 *
983 * \param cntNum
984 * The Counter instance number in the selected TCPWM.
985 *
986 *******************************************************************************/
987
Cy_TCPWM_Enable_Single(TCPWM_Type * base,uint32_t cntNum)988 __STATIC_INLINE void Cy_TCPWM_Enable_Single(TCPWM_Type *base, uint32_t cntNum)
989 {
990 #if (CY_IP_MXTCPWM_VERSION == 1U)
991
992 TCPWM_CTRL_SET(base) = (1UL << cntNum);
993 #else
994
995 TCPWM_GRP_CNT_CTRL(base, TCPWM_GRP_CNT_GET_GRP(cntNum), cntNum) |=
996 _VAL2FLD(TCPWM_GRP_CNT_V2_CTRL_ENABLED, 1U);
997 #endif
998 }
999
1000 /*******************************************************************************
1001 * Function Name: Cy_TCPWM_Disable_Single
1002 ****************************************************************************//**
1003 *
1004 * Disable specified counter
1005 *
1006 * \param base
1007 * The pointer to a TCPWM instance.
1008 *
1009 * \param cntNum
1010 * The Counter instance number in the selected TCPWM.
1011 *
1012 *******************************************************************************/
Cy_TCPWM_Disable_Single(TCPWM_Type * base,uint32_t cntNum)1013 __STATIC_INLINE void Cy_TCPWM_Disable_Single(TCPWM_Type *base, uint32_t cntNum)
1014 {
1015 #if (CY_IP_MXTCPWM_VERSION == 1U)
1016 TCPWM_CTRL_CLR(base) = (1UL << cntNum);
1017 #else
1018 TCPWM_GRP_CNT_CTRL(base, TCPWM_GRP_CNT_GET_GRP(cntNum), cntNum) &=
1019 ~TCPWM_GRP_CNT_V2_CTRL_ENABLED_Msk;
1020 #endif
1021 }
1022
1023 /*******************************************************************************
1024 * Function Name: Cy_TCPWM_GetInterruptStatus
1025 ****************************************************************************//**
1026 *
1027 * Returns which event triggered the interrupt.
1028 *
1029 * \param base
1030 * The pointer to a TCPWM instance.
1031 *
1032 * \param cntNum
1033 * The Counter instance number in the selected TCPWM.
1034 *
1035 * \return
1036 * See \ref group_tcpwm_interrupt_sources
1037 *
1038 * \funcusage
1039 * \snippet tcpwm/pwm/snippet/main.c snippet_Cy_TCPWM_GetInterruptStatus
1040 *
1041 *******************************************************************************/
Cy_TCPWM_GetInterruptStatus(TCPWM_Type const * base,uint32_t cntNum)1042 __STATIC_INLINE uint32_t Cy_TCPWM_GetInterruptStatus(TCPWM_Type const *base, uint32_t cntNum)
1043 {
1044 uint32_t result;
1045
1046 #if (CY_IP_MXTCPWM_VERSION == 1U)
1047
1048 result = TCPWM_CNT_INTR(base, cntNum);
1049 #else
1050 result = TCPWM_GRP_CNT_INTR(base, TCPWM_GRP_CNT_GET_GRP(cntNum), cntNum);
1051 #endif
1052
1053 return result;
1054 }
1055
1056
1057 /*******************************************************************************
1058 * Function Name: Cy_TCPWM_ClearInterrupt
1059 ****************************************************************************//**
1060 *
1061 * Clears Active Interrupt Source
1062 *
1063 * \param base
1064 * The pointer to a TCPWM instance.
1065 *
1066 * \param cntNum
1067 * The Counter instance number in the selected TCPWM.
1068 *
1069 * \param source
1070 * source to clear. See \ref group_tcpwm_interrupt_sources
1071 *
1072 * \funcusage
1073 * \snippet tcpwm/pwm/snippet/main.c snippet_Cy_TCPWM_GetInterruptStatusMasked
1074 *
1075 *******************************************************************************/
Cy_TCPWM_ClearInterrupt(TCPWM_Type * base,uint32_t cntNum,uint32_t source)1076 __STATIC_INLINE void Cy_TCPWM_ClearInterrupt(TCPWM_Type *base, uint32_t cntNum, uint32_t source)
1077 {
1078 #if (CY_IP_MXTCPWM_VERSION == 1U)
1079
1080 TCPWM_CNT_INTR(base, cntNum) = source;
1081 (void)TCPWM_CNT_INTR(base, cntNum);
1082 #else
1083 TCPWM_GRP_CNT_INTR(base, TCPWM_GRP_CNT_GET_GRP(cntNum), cntNum) = source;
1084 (void)TCPWM_GRP_CNT_INTR(base, TCPWM_GRP_CNT_GET_GRP(cntNum), cntNum);
1085 #endif
1086 }
1087
1088
1089 /*******************************************************************************
1090 * Function Name: Cy_TCPWM_SetInterrupt
1091 ****************************************************************************//**
1092 *
1093 * Triggers an interrupt via a software write.
1094 *
1095 * \param base
1096 * The pointer to a TCPWM instance.
1097 *
1098 * \param cntNum
1099 * The Counter instance number in the selected TCPWM.
1100 *
1101 * \param source
1102 * The source to set an interrupt. See \ref group_tcpwm_interrupt_sources.
1103 *
1104 * \funcusage
1105 * \snippet tcpwm/pwm/snippet/main.c snippet_Cy_TCPWM_SetInterrupt
1106 *
1107 *******************************************************************************/
Cy_TCPWM_SetInterrupt(TCPWM_Type * base,uint32_t cntNum,uint32_t source)1108 __STATIC_INLINE void Cy_TCPWM_SetInterrupt(TCPWM_Type *base, uint32_t cntNum, uint32_t source)
1109 {
1110 #if (CY_IP_MXTCPWM_VERSION == 1U)
1111
1112 TCPWM_CNT_INTR_SET(base, cntNum) = source;
1113 #else
1114 TCPWM_GRP_CNT_INTR_SET(base, TCPWM_GRP_CNT_GET_GRP(cntNum), cntNum) = source;
1115 #endif
1116 }
1117
1118
1119 /*******************************************************************************
1120 * Function Name: Cy_TCPWM_SetInterruptMask
1121 ****************************************************************************//**
1122 *
1123 * Sets an interrupt mask. A 1 means that when the event occurs, it will cause an
1124 * interrupt; a 0 means no interrupt will be triggered.
1125 *
1126 * \param base
1127 * The pointer to a TCPWM instance.
1128 *
1129 * \param cntNum
1130 * The Counter instance number in the selected TCPWM.
1131 *
1132 * \param mask
1133 *. See \ref group_tcpwm_interrupt_sources
1134 *
1135 * \funcusage
1136 * \snippet tcpwm/pwm/snippet/main.c snippet_Cy_TCPWM_SetInterruptMask
1137 *
1138 *******************************************************************************/
Cy_TCPWM_SetInterruptMask(TCPWM_Type * base,uint32_t cntNum,uint32_t mask)1139 __STATIC_INLINE void Cy_TCPWM_SetInterruptMask(TCPWM_Type *base, uint32_t cntNum, uint32_t mask)
1140 {
1141 #if (CY_IP_MXTCPWM_VERSION == 1U)
1142
1143 TCPWM_CNT_INTR_MASK(base, cntNum) = mask;
1144 #else
1145 TCPWM_GRP_CNT_INTR_MASK(base, TCPWM_GRP_CNT_GET_GRP(cntNum), cntNum) = mask;
1146 #endif
1147 }
1148
1149
1150 /*******************************************************************************
1151 * Function Name: Cy_TCPWM_GetInterruptMask
1152 ****************************************************************************//**
1153 *
1154 * Returns the interrupt mask.
1155 *
1156 * \param base
1157 * The pointer to a TCPWM instance.
1158 *
1159 * \param cntNum
1160 * The Counter instance number in the selected TCPWM.
1161 *
1162 * \return
1163 * Interrupt Mask. See \ref group_tcpwm_interrupt_sources
1164 *
1165 * \funcusage
1166 * \snippet tcpwm/pwm/snippet/main.c snippet_Cy_TCPWM_SetInterruptMask
1167 *
1168 *******************************************************************************/
Cy_TCPWM_GetInterruptMask(TCPWM_Type const * base,uint32_t cntNum)1169 __STATIC_INLINE uint32_t Cy_TCPWM_GetInterruptMask(TCPWM_Type const *base, uint32_t cntNum)
1170 {
1171 uint32_t mask;
1172
1173 #if (CY_IP_MXTCPWM_VERSION == 1U)
1174
1175 mask = TCPWM_CNT_INTR_MASK(base, cntNum);
1176 #else
1177 mask = TCPWM_GRP_CNT_INTR_MASK(base, TCPWM_GRP_CNT_GET_GRP(cntNum), cntNum);
1178 #endif
1179
1180 return mask;
1181 }
1182
1183
1184 /*******************************************************************************
1185 * Function Name: Cy_TCPWM_GetInterruptStatusMasked
1186 ****************************************************************************//**
1187 *
1188 * Returns which masked interrupt triggered the interrupt.
1189 *
1190 * \param base
1191 * The pointer to a TCPWM instance.
1192 *
1193 * \param cntNum
1194 * The Counter instance number in the selected TCPWM.
1195 *
1196 * \return
1197 * Interrupt Mask. See \ref group_tcpwm_interrupt_sources
1198 *
1199 * \funcusage
1200 * \snippet tcpwm/pwm/snippet/main.c snippet_Cy_TCPWM_GetInterruptStatusMasked
1201 *
1202 *******************************************************************************/
Cy_TCPWM_GetInterruptStatusMasked(TCPWM_Type const * base,uint32_t cntNum)1203 __STATIC_INLINE uint32_t Cy_TCPWM_GetInterruptStatusMasked(TCPWM_Type const *base, uint32_t cntNum)
1204 {
1205 uint32_t status;
1206
1207 #if (CY_IP_MXTCPWM_VERSION == 1U)
1208
1209 status = TCPWM_CNT_INTR_MASKED(base, cntNum);
1210 #else
1211 status = TCPWM_GRP_CNT_INTR_MASKED(base, TCPWM_GRP_CNT_GET_GRP(cntNum), cntNum);
1212 #endif
1213
1214 return status;
1215 }
1216
1217
1218 /*******************************************************************************
1219 * Function Name: Cy_TCPWM_TriggerStart_Single
1220 ****************************************************************************//**
1221 *
1222 * Triggers a software start on the selected TCPWM.
1223 *
1224 * \param base
1225 * The pointer to a TCPWM instance.
1226 *
1227 * \param cntNum
1228 * The Counter instance number in the selected TCPWM.
1229 *
1230 * \funcusage
1231 * \snippet tcpwm/shiftreg/snippet/main.c snippet_Cy_TCPWM_ShiftReg_Start
1232 *
1233 *******************************************************************************/
Cy_TCPWM_TriggerStart_Single(TCPWM_Type * base,uint32_t cntNum)1234 __STATIC_INLINE void Cy_TCPWM_TriggerStart_Single(TCPWM_Type *base, uint32_t cntNum)
1235 {
1236 #if (CY_IP_MXTCPWM_VERSION == 1U)
1237
1238 TCPWM_CMD_START(base) = (1UL << cntNum);
1239 #else
1240 TCPWM_GRP_CNT_TR_CMD(base, TCPWM_GRP_CNT_GET_GRP(cntNum), cntNum) =
1241 TCPWM_GRP_CNT_V2_TR_CMD_START_Msk;
1242 #endif
1243 }
1244
1245
1246 /*******************************************************************************
1247 * Function Name: Cy_TCPWM_TriggerReloadOrIndex_Single
1248 ****************************************************************************//**
1249 *
1250 * Triggers a software reload event (or index 0 in QuadDec mode) on selected TCPWM.
1251 *
1252 * \param base
1253 * The pointer to a TCPWM instance.
1254 *
1255 * \param cntNum
1256 * The Counter instance number in the selected TCPWM.
1257 *
1258 *******************************************************************************/
Cy_TCPWM_TriggerReloadOrIndex_Single(TCPWM_Type * base,uint32_t cntNum)1259 __STATIC_INLINE void Cy_TCPWM_TriggerReloadOrIndex_Single(TCPWM_Type *base, uint32_t cntNum)
1260 {
1261 #if (CY_IP_MXTCPWM_VERSION == 1U)
1262
1263 TCPWM_CMD_RELOAD(base) = (1UL << cntNum);
1264 #else
1265 TCPWM_GRP_CNT_TR_CMD(base, TCPWM_GRP_CNT_GET_GRP(cntNum), cntNum) =
1266 TCPWM_GRP_CNT_V2_TR_CMD_RELOAD_Msk;
1267 #endif
1268 }
1269
1270
1271 /*******************************************************************************
1272 * Function Name: Cy_TCPWM_TriggerStopOrKill_Single
1273 ****************************************************************************//**
1274 *
1275 * Triggers a stop in the Timer Counter mode, or a kill in the PWM mode on
1276 * selected TCPWM.
1277 *
1278 * \note The kill trigger behavior for PWM is defined by the
1279 * \ref cy_stc_tcpwm_pwm_config_t::killMode field. The pins states after a kill
1280 * trigger are defined by \ref cy_stc_tcpwm_pwm_config_t::invertPWMOut and
1281 * \ref cy_stc_tcpwm_pwm_config_t::invertPWMOutN fields.
1282 *
1283 * \param base
1284 * The pointer to a TCPWM instance.
1285 *
1286 * \param cntNum
1287 * The Counter instance number in the selected TCPWM.
1288 *
1289 *******************************************************************************/
Cy_TCPWM_TriggerStopOrKill_Single(TCPWM_Type * base,uint32_t cntNum)1290 __STATIC_INLINE void Cy_TCPWM_TriggerStopOrKill_Single(TCPWM_Type *base, uint32_t cntNum)
1291 {
1292 #if (CY_IP_MXTCPWM_VERSION == 1U)
1293
1294 TCPWM_CMD_STOP(base) = (1UL << cntNum);
1295 #else
1296 TCPWM_GRP_CNT_TR_CMD(base, TCPWM_GRP_CNT_GET_GRP(cntNum), cntNum) =
1297 TCPWM_GRP_CNT_V2_TR_CMD_STOP_Msk;
1298 #endif
1299 }
1300
1301
1302 /*******************************************************************************
1303 * Function Name: Cy_TCPWM_TriggerCaptureOrSwap_Single
1304 ****************************************************************************//**
1305 *
1306 * Triggers a Capture 0 in the Timer Counter mode, and a Swap in the PWM mode on
1307 * selected TCPWM.
1308 *
1309 * \param base
1310 * The pointer to a TCPWM instance.
1311 *
1312 * \param cntNum
1313 * The Counter instance number in the selected TCPWM.
1314 *
1315 *******************************************************************************/
Cy_TCPWM_TriggerCaptureOrSwap_Single(TCPWM_Type * base,uint32_t cntNum)1316 __STATIC_INLINE void Cy_TCPWM_TriggerCaptureOrSwap_Single(TCPWM_Type *base, uint32_t cntNum)
1317 {
1318 #if (CY_IP_MXTCPWM_VERSION == 1U)
1319
1320 TCPWM_CMD_CAPTURE(base) = (1UL << cntNum);
1321 #else
1322 TCPWM_GRP_CNT_TR_CMD(base, TCPWM_GRP_CNT_GET_GRP(cntNum), cntNum) =
1323 TCPWM_GRP_CNT_V2_TR_CMD_CAPTURE0_Msk;
1324 #endif
1325 }
1326
1327 /*******************************************************************************
1328 * Function Name: Cy_TCPWM_TriggerCapture0
1329 ****************************************************************************//**
1330 *
1331 * Triggers a Capture 0 on the selected counter.
1332 *
1333 * \param base
1334 * The pointer to a TCPWM instance.
1335 *
1336 * \param cntNum
1337 * The Counter instance number in the selected TCPWM.
1338 *
1339 * \note For TCPWM version 3 and above in compare mode, when external direction control is enabled and Capture0 input is disabled,
1340 * user can use software capture0 trigger. While using this, User has to make sure that the
1341 * external direction control is set to CY_TCPWM_COUNTER_DIRECTION_RISING
1342 *******************************************************************************/
Cy_TCPWM_TriggerCapture0(TCPWM_Type * base,uint32_t cntNum)1343 __STATIC_INLINE void Cy_TCPWM_TriggerCapture0(TCPWM_Type *base, uint32_t cntNum)
1344 {
1345 Cy_TCPWM_TriggerCaptureOrSwap_Single(base, cntNum);
1346 }
1347
1348 #if (CY_IP_MXTCPWM_VERSION >= 2U) || defined (CY_DOXYGEN)
1349 /*******************************************************************************
1350 * Function Name: Cy_TCPWM_TriggerCapture1
1351 ****************************************************************************//**
1352 *
1353 * Triggers a Capture 1 in Timer Counter and QuadDec Mode. In PWM mode this acts
1354 * as a second kill input.
1355 *
1356 * \param base
1357 * The pointer to a TCPWM instance.
1358 *
1359 * \param cntNum
1360 * The Counter instance number in the selected TCPWM.
1361 *
1362 *******************************************************************************/
Cy_TCPWM_TriggerCapture1(TCPWM_Type * base,uint32_t cntNum)1363 __STATIC_INLINE void Cy_TCPWM_TriggerCapture1(TCPWM_Type *base, uint32_t cntNum)
1364 {
1365 if (TCPWM_GRP_CC1(base, TCPWM_GRP_CNT_GET_GRP(cntNum)))
1366 {
1367 TCPWM_GRP_CNT_TR_CMD(base, TCPWM_GRP_CNT_GET_GRP(cntNum), cntNum) =
1368 TCPWM_GRP_CNT_V2_TR_CMD_CAPTURE1_Msk;
1369 }
1370 else
1371 {
1372 /* Function is not supported for TCPWM_ver1 block */
1373 CY_ASSERT_L1(false);
1374 }
1375 }
1376
1377
1378 /*******************************************************************************
1379 * Function Name: Cy_TCPWM_GetTrigPinLevel
1380 ****************************************************************************//**
1381 *
1382 * Returns the current level of the selected input trigger.
1383 *
1384 * \param base
1385 * The pointer to a TCPWM instance.
1386 *
1387 * \param cntNum
1388 * The Counter instance number in the selected TCPWM.
1389 *
1390 * \param triggerSelect
1391 * Defines which trigger status is being checked, Start, Reload, Stop/Kill, Count, Capture 0 or Capture 1
1392 *
1393 * \return
1394 * The trigger level
1395 *
1396 * \funcusage
1397 * \snippet tcpwm/pwm/snippet/main.c snippet_Cy_TCPWM_GetTrigPinLevel
1398 *
1399 *******************************************************************************/
Cy_TCPWM_GetTrigPinLevel(TCPWM_Type const * base,uint32_t cntNum,cy_en_tcpwm_trigselect_t triggerSelect)1400 __STATIC_INLINE bool Cy_TCPWM_GetTrigPinLevel (TCPWM_Type const *base, uint32_t cntNum, cy_en_tcpwm_trigselect_t triggerSelect)
1401
1402 {
1403 uint32_t status = 0UL;
1404
1405 status = TCPWM_GRP_CNT_STATUS(base, TCPWM_GRP_CNT_GET_GRP(cntNum), cntNum);
1406
1407 switch(triggerSelect)
1408 {
1409 case CY_TCPWM_INPUT_TR_START:
1410 status = _FLD2VAL(TCPWM_GRP_CNT_V2_STATUS_TR_START, status);
1411 break;
1412 case CY_TCPWM_INPUT_TR_RELOAD_OR_INDEX:
1413 status = _FLD2VAL(TCPWM_GRP_CNT_V2_STATUS_TR_RELOAD, status);
1414 break;
1415 case CY_TCPWM_INPUT_TR_STOP_OR_KILL:
1416 status = _FLD2VAL(TCPWM_GRP_CNT_V2_STATUS_TR_RELOAD, status);
1417 break;
1418 case CY_TCPWM_INPUT_TR_COUNT:
1419 status = _FLD2VAL(TCPWM_GRP_CNT_V2_STATUS_TR_STOP, status);
1420 break;
1421 case CY_TCPWM_INPUT_TR_CAPTURE0:
1422 status = _FLD2VAL(TCPWM_GRP_CNT_V2_STATUS_TR_CAPTURE0, status);
1423 break;
1424 case CY_TCPWM_INPUT_TR_CAPTURE1:
1425 status = _FLD2VAL(TCPWM_GRP_CNT_V2_STATUS_TR_CAPTURE1, status);
1426 break;
1427 default:
1428 /* Not a valid input trigger */
1429 CY_ASSERT_L3(false);
1430 break;
1431 }
1432
1433
1434 return (status != 0UL);
1435 }
1436
1437 /*******************************************************************************
1438 * Function Name: Cy_TCPWM_InputTriggerSetup
1439 ****************************************************************************//**
1440 *
1441 * Sets up a trigger input signal for a specific TCPWM counter. This API is used to
1442 * handle software triggering of multiple counters synchronously.
1443 *
1444 * \param base
1445 * The pointer to a TCPWM instance.
1446 *
1447 * \param cntNum
1448 * The Counter instance number in the selected TCPWM.
1449 *
1450 * \param triggerSelect
1451 * Defines which trigger is being setup, Start, Reload, Stop/Kill, Count, Capture 0 or Capture 1
1452 * see cy_en_tcpwm_trigselect_t
1453 *
1454 * \param edgeSelect
1455 * Sets the trigger edge detection, Rising, Falling, Both, No edge detect. see \ref group_tcpwm_input_modes
1456 *
1457 * \param triggerSignal
1458 * Selects what trigger signal is connected to the selected input trigger.
1459 *
1460 * \note
1461 * Trigger signal for general purpose trigger is calculated as below.
1462 * CY_TCPWM_INPUT_TRIG(n) = (n + TCPWM_TR_ONE_CNT_NR + 2U)
1463 * For devices with more than one instance of TCPWM
1464 * CY_TCPWM_INPUT_TRIG_WITH_INST(n, m) is used where m is the TCPWM instance number.
1465 *
1466 * \funcusage
1467 * \snippet tcpwm/pwm/snippet/main.c snippet_Cy_TCPWM_InputTriggerSetup
1468 *
1469 *******************************************************************************/
Cy_TCPWM_InputTriggerSetup(TCPWM_Type * base,uint32 cntNum,cy_en_tcpwm_trigselect_t triggerSelect,uint32_t edgeSelect,uint32_t triggerSignal)1470 __STATIC_INLINE void Cy_TCPWM_InputTriggerSetup (TCPWM_Type *base, uint32 cntNum, cy_en_tcpwm_trigselect_t triggerSelect, uint32_t edgeSelect, uint32_t triggerSignal)
1471 {
1472 uint32_t grp = TCPWM_GRP_CNT_GET_GRP(cntNum);
1473
1474 switch(triggerSelect)
1475 {
1476 case CY_TCPWM_INPUT_TR_START:
1477 /* Clear input trigger settings first */
1478 TCPWM_GRP_CNT_TR_IN_SEL1(base, grp, cntNum) &= ~TCPWM_GRP_CNT_V2_TR_IN_SEL1_START_SEL_Msk;
1479 TCPWM_GRP_CNT_TR_IN_EDGE_SEL(base, grp, cntNum) &= ~TCPWM_GRP_CNT_V2_TR_IN_EDGE_SEL_START_EDGE_Msk;
1480
1481 /* Write new settings */
1482 TCPWM_GRP_CNT_TR_IN_SEL1(base, grp, cntNum) |= _VAL2FLD(TCPWM_GRP_CNT_V2_TR_IN_SEL1_START_SEL, triggerSignal);
1483 TCPWM_GRP_CNT_TR_IN_EDGE_SEL(base, grp, cntNum) |= _VAL2FLD(TCPWM_GRP_CNT_V2_TR_IN_EDGE_SEL_START_EDGE, edgeSelect);
1484 break;
1485 case CY_TCPWM_INPUT_TR_RELOAD_OR_INDEX:
1486 TCPWM_GRP_CNT_TR_IN_SEL0(base, grp, cntNum) &= ~TCPWM_GRP_CNT_V2_TR_IN_SEL0_RELOAD_SEL_Msk;
1487 TCPWM_GRP_CNT_TR_IN_EDGE_SEL(base, grp, cntNum) &= ~TCPWM_GRP_CNT_V2_TR_IN_EDGE_SEL_RELOAD_EDGE_Msk;
1488
1489 TCPWM_GRP_CNT_TR_IN_SEL0(base, grp, cntNum) |= _VAL2FLD(TCPWM_GRP_CNT_V2_TR_IN_SEL0_RELOAD_SEL, triggerSignal);
1490 TCPWM_GRP_CNT_TR_IN_EDGE_SEL(base, grp, cntNum) |= _VAL2FLD(TCPWM_GRP_CNT_V2_TR_IN_EDGE_SEL_RELOAD_EDGE, edgeSelect);
1491 break;
1492 case CY_TCPWM_INPUT_TR_STOP_OR_KILL:
1493 TCPWM_GRP_CNT_TR_IN_SEL0(base, grp, cntNum) &= ~TCPWM_GRP_CNT_V2_TR_IN_SEL0_STOP_SEL_Msk;
1494 TCPWM_GRP_CNT_TR_IN_EDGE_SEL(base, grp, cntNum) &= ~TCPWM_GRP_CNT_V2_TR_IN_EDGE_SEL_STOP_EDGE_Msk;
1495
1496 TCPWM_GRP_CNT_TR_IN_SEL0(base, grp, cntNum) |= _VAL2FLD(TCPWM_GRP_CNT_V2_TR_IN_SEL0_STOP_SEL, triggerSignal);
1497 TCPWM_GRP_CNT_TR_IN_EDGE_SEL(base, grp, cntNum) |= _VAL2FLD(TCPWM_GRP_CNT_V2_TR_IN_EDGE_SEL_STOP_EDGE, edgeSelect);
1498 break;
1499 case CY_TCPWM_INPUT_TR_COUNT:
1500 TCPWM_GRP_CNT_TR_IN_SEL0(base, grp, cntNum) &= ~TCPWM_GRP_CNT_V2_TR_IN_SEL0_COUNT_SEL_Msk;
1501 TCPWM_GRP_CNT_TR_IN_EDGE_SEL(base, grp, cntNum) &= ~TCPWM_GRP_CNT_V2_TR_IN_EDGE_SEL_COUNT_EDGE_Msk;
1502
1503 TCPWM_GRP_CNT_TR_IN_SEL0(base, grp, cntNum) |= _VAL2FLD(TCPWM_GRP_CNT_V2_TR_IN_SEL0_COUNT_SEL, triggerSignal);
1504 TCPWM_GRP_CNT_TR_IN_EDGE_SEL(base, grp, cntNum) |= _VAL2FLD(TCPWM_GRP_CNT_V2_TR_IN_EDGE_SEL_COUNT_EDGE, edgeSelect);
1505 break;
1506 case CY_TCPWM_INPUT_TR_CAPTURE0:
1507 TCPWM_GRP_CNT_TR_IN_SEL0(base, grp, cntNum) &= ~TCPWM_GRP_CNT_V2_TR_IN_SEL0_CAPTURE0_SEL_Msk;
1508 TCPWM_GRP_CNT_TR_IN_EDGE_SEL(base, grp, cntNum) &= ~TCPWM_GRP_CNT_V2_TR_IN_EDGE_SEL_CAPTURE0_EDGE_Msk;
1509
1510 TCPWM_GRP_CNT_TR_IN_SEL0(base, grp, cntNum) |= _VAL2FLD(TCPWM_GRP_CNT_V2_TR_IN_SEL0_CAPTURE0_SEL, triggerSignal);
1511 TCPWM_GRP_CNT_TR_IN_EDGE_SEL(base, grp, cntNum) |= _VAL2FLD(TCPWM_GRP_CNT_V2_TR_IN_EDGE_SEL_CAPTURE0_EDGE, edgeSelect);
1512 break;
1513 case CY_TCPWM_INPUT_TR_CAPTURE1:
1514 if (TCPWM_GRP_CC1(base, grp))
1515 {
1516 TCPWM_GRP_CNT_TR_IN_SEL1(base, grp, cntNum) &= ~TCPWM_GRP_CNT_V2_TR_IN_SEL1_CAPTURE1_SEL_Msk;
1517 TCPWM_GRP_CNT_TR_IN_EDGE_SEL(base, grp, cntNum) &= ~TCPWM_GRP_CNT_V2_TR_IN_EDGE_SEL_CAPTURE1_EDGE_Msk;
1518
1519 TCPWM_GRP_CNT_TR_IN_SEL1(base, grp, cntNum) |= _VAL2FLD(TCPWM_GRP_CNT_V2_TR_IN_SEL1_CAPTURE1_SEL, triggerSignal);
1520 TCPWM_GRP_CNT_TR_IN_EDGE_SEL(base, grp, cntNum) |= _VAL2FLD(TCPWM_GRP_CNT_V2_TR_IN_EDGE_SEL_CAPTURE1_EDGE, edgeSelect);
1521 }
1522 else
1523 {
1524 /* Capture 1 - Not supported for the group */
1525 CY_ASSERT_L3(false);
1526 }
1527 break;
1528 default:
1529 /* Not a valid input trigger */
1530 CY_ASSERT_L3(false);
1531 break;
1532 }
1533
1534 }
1535
1536
1537 /*******************************************************************************
1538 * Function Name: Cy_TCPWM_OutputTriggerSetup
1539 ****************************************************************************//**
1540 *
1541 * Sets up a trigger output signal for a specific TCPWM counter event.
1542 *
1543 * \param base
1544 * The pointer to a TCPWM instance.
1545 *
1546 * \param cntNum
1547 * The Counter instance number in the selected TCPWM.
1548 *
1549 * \param trigger0event
1550 * Selects internal events for output trigger out0 generation. see \ref cy_en_tcpwm_output_trigselect_t
1551 *
1552 * \param trigger1event
1553 * Selects internal events for output trigger out1 generation. see \ref cy_en_tcpwm_output_trigselect_t
1554 *
1555 *
1556 *******************************************************************************/
Cy_TCPWM_OutputTriggerSetup(TCPWM_Type * base,uint32 cntNum,cy_en_tcpwm_output_trigselect_t trigger0event,cy_en_tcpwm_output_trigselect_t trigger1event)1557 __STATIC_INLINE void Cy_TCPWM_OutputTriggerSetup (TCPWM_Type *base, uint32 cntNum, cy_en_tcpwm_output_trigselect_t trigger0event, cy_en_tcpwm_output_trigselect_t trigger1event)
1558 {
1559 uint32_t grp = TCPWM_GRP_CNT_GET_GRP(cntNum);
1560
1561 TCPWM_GRP_CNT_TR_OUT_SEL(base, grp, cntNum) =
1562 (_VAL2FLD(TCPWM_GRP_CNT_V2_TR_OUT_SEL_OUT0, trigger0event) |
1563 _VAL2FLD(TCPWM_GRP_CNT_V2_TR_OUT_SEL_OUT1, trigger1event));
1564
1565 }
1566
1567 /*******************************************************************************
1568 * Function Name: Cy_TCPWM_SetDebugFreeze
1569 ****************************************************************************//**
1570 *
1571 * Enables/disables the Debug Freeze feature for the specified counter.
1572 *
1573 * \param base
1574 * The pointer to a TCPWM instance.
1575 *
1576 * \param cntNum
1577 * The Counter instance number in the selected TCPWM.
1578 *
1579 * \param enable
1580 * true: The Debug Free feature is enabled
1581 * false: The Debug Freeze feature is disabled
1582 *
1583 * \return
1584 * Error / Status code. See cy_en_tcpwm_status_t.
1585 *
1586 * \funcusage
1587 * \snippet tcpwm/counter/snippet/main.c snippet_Cy_TCPWM_SetDebugFreeze
1588 *
1589 *******************************************************************************/
Cy_TCPWM_SetDebugFreeze(TCPWM_Type * base,uint32 cntNum,bool enable)1590 __STATIC_INLINE cy_en_tcpwm_status_t Cy_TCPWM_SetDebugFreeze (TCPWM_Type *base, uint32 cntNum, bool enable)
1591 {
1592
1593 TCPWM_GRP_CNT_CTRL(base, TCPWM_GRP_CNT_GET_GRP(cntNum), cntNum) |= (enable ? TCPWM_GRP_CNT_V2_CTRL_DBG_FREEZE_EN_Msk : 0UL);
1594
1595 return CY_TCPWM_SUCCESS;
1596 }
1597 #endif
1598
1599 #if defined (CY_IP_MXS40TCPWM) || defined (CY_DOXYGEN)
1600 /*******************************************************************************
1601 * Function Name: Cy_TCPWM_Block_EnableSwap
1602 ****************************************************************************//**
1603 *
1604 * Enables/disables swapping mechanism between CC0 and buffered CC0, CC1 and buffered CC1, PERIOD and buffered PERIOD, DT and buffered DT.
1605 *
1606 * \param base
1607 * The pointer to a TCPWM instance.
1608 *
1609 * \param cntNum
1610 * The Counter instance number in the selected TCPWM.
1611 *
1612 * \param enable
1613 * true: Swapping mechanism is enabled
1614 * false: Swapping mechanism is disabled
1615 *
1616 * \note This feature is coupled with the reload feature.
1617 * 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
1618 * When only reload is enabled then CC_BUFF/CC1_BUFF/PERIOD_BUFF/DT_BUFF values are copied to CC0/CC1/PERIOD/DT respectively.
1619 * There is no action when reload is disabled.
1620 * Reload is enabled/disabled with the API's Cy_TCPWM_Block_EnableCompare0Swap, Cy_TCPWM_Block_EnableCompare1Swap, Cy_TCPWM_PWM_EnablePeriodSwap
1621 *
1622 * \note Applicable for devices with TCPWM version 3 and above and for MXTCPWM version 1 and above.
1623 *
1624 *******************************************************************************/
Cy_TCPWM_Block_EnableSwap(TCPWM_Type * base,uint32_t cntNum,bool enable)1625 __STATIC_INLINE void Cy_TCPWM_Block_EnableSwap(TCPWM_Type *base, uint32_t cntNum, bool enable)
1626 {
1627 if (enable)
1628 {
1629 TCPWM_GRP_CNT_CTRL(base, TCPWM_GRP_CNT_GET_GRP(cntNum), cntNum) |=
1630 TCPWM_GRP_CNT_V3_CTRL_SWAP_ENABLED_Msk;
1631 }
1632 else
1633 {
1634 TCPWM_GRP_CNT_CTRL(base, TCPWM_GRP_CNT_GET_GRP(cntNum), cntNum) &=
1635 ~TCPWM_GRP_CNT_V3_CTRL_SWAP_ENABLED_Msk;
1636 }
1637 }
1638
1639 /*******************************************************************************
1640 * Function Name: Cy_TCPWM_InputTriggerSetupWithGF
1641 ****************************************************************************//**
1642 *
1643 * Sets up a trigger input signal for a specific TCPWM counter and
1644 * Glitch filter configuration for that trigger. This API is used to
1645 * handle software triggering of multiple counters synchronously.
1646 *
1647 * \param base
1648 * The pointer to a TCPWM instance.
1649 *
1650 * \param cntNum
1651 * The Counter instance number in the selected TCPWM.
1652 *
1653 * \param triggerSelect
1654 * Defines which trigger is being setup, Start, Reload, Stop/Kill, Count, Capture 0 or Capture 1
1655 * see cy_en_tcpwm_trigselect_t
1656 *
1657 * \param edgeSelect
1658 * Sets the trigger edge detection, Rising, Falling, Both, No edge detect. see \ref group_tcpwm_input_modes
1659 *
1660 * \param triggerSignal
1661 * Selects what trigger signal is connected to the selected input trigger.
1662 *
1663 * \param dsvalue
1664 * Glitch filter depth. \ref cy_en_gf_depth_value_t
1665 *
1666 * \note GF depth set for one to one triggers will be applied to specific trigger and GF depth set for general purpose trigger will be applicable for all general purpose triggers.
1667 *
1668 *******************************************************************************/
1669
Cy_TCPWM_InputTriggerSetupWithGF(TCPWM_Type * base,uint32 cntNum,cy_en_tcpwm_trigselect_t triggerSelect,uint32_t edgeSelect,uint32_t triggerSignal,cy_en_gf_depth_value_t dsvalue)1670 __STATIC_INLINE void Cy_TCPWM_InputTriggerSetupWithGF (TCPWM_Type *base, uint32 cntNum, cy_en_tcpwm_trigselect_t triggerSelect, uint32_t edgeSelect, uint32_t triggerSignal, cy_en_gf_depth_value_t dsvalue)
1671 {
1672 uint32_t grp = TCPWM_GRP_CNT_GET_GRP(cntNum);
1673 uint32_t prescalar = 0U;
1674 uint32_t depth = 7U;
1675 if (dsvalue <= CY_GLITCH_FILTER_DEPTH_SUPPORT_VALUE_64)
1676 {
1677 depth = (uint32_t)dsvalue;
1678 }
1679 else
1680 {
1681 prescalar = (uint32_t)dsvalue - depth;
1682 }
1683 /* Trigger signal for general purpose trigger is calculated as below.
1684 CY_TCPWM_INPUT_TRIG(n) = (n + TCPWM_TR_ONE_CNT_NR + 2U)
1685 TCPWM_TR_ONE_CNT_NR is the max one to one triggers.
1686 */
1687 if((triggerSignal - 2U) <= TCPWM_TR_ONE_CNT_NR)
1688 {
1689 uint32_t onetoone_gf = triggerSignal - 2U;
1690 /* Based on the number of one to one glitch filters available,
1691 only those corresponding one to one triggers can be connected to the one to one glitch filters */
1692 if(onetoone_gf <= TCPWM_GRP_NR0_CNT_TR_ONE_GF_NR)
1693 {
1694 TCPWM_GRP_CNT_ONE_GF(base, grp, cntNum, onetoone_gf) = (_VAL2FLD(TCPWM_GRP_CNT_V3_ONE_GF_GF_DEPTH, depth) |
1695 _VAL2FLD(TCPWM_GRP_CNT_V3_ONE_GF_GFPS_DIV, prescalar));
1696 }
1697 }
1698 else
1699 {
1700 uint32_t gfNum = triggerSignal - 2U - TCPWM_TR_ONE_CNT_NR;
1701 /* Based on the number of general purpose glitch filters available,
1702 only those corresponding general purpose triggers can be connected to the general purpose glitch filters */
1703 if(gfNum <= TCPWM_TR_ALL_GF_TR_ALL_GF_NR)
1704 {
1705 TCPWM_GF_FOR_GROUP_TRIGGER(base, gfNum) = (_VAL2FLD(TCPWM_TR_ALL_GF_ALL_GF_GF_DEPTH, depth) |
1706 _VAL2FLD(TCPWM_TR_ALL_GF_ALL_GF_GFPS_DIV, prescalar));
1707 }
1708 }
1709
1710 Cy_TCPWM_InputTriggerSetup (base,cntNum,triggerSelect,edgeSelect,triggerSignal);
1711
1712 }
1713
1714 #endif /* defined (CY_IP_MXS40TCPWM) || defined (CY_DOXYGEN) */
1715
1716 /** \} group_tcpwm_functions_common */
1717
1718 /** \} group_tcpwm_common */
1719
1720 /*******************************************************************************
1721 * Backward compatibility macro. The following code is DEPRECATED and must
1722 * not be used in new projects
1723 *******************************************************************************/
1724 #define CY_TCPWM_INT_ON_CC CY_TCPWM_INT_ON_CC0
1725 #define CY_TCPWM_INT_ON_CC_OR_TC CY_TCPWM_INT_ON_CC0_OR_TC
1726
1727 #if defined(__cplusplus)
1728 }
1729 #endif
1730
1731 #endif /* CY_IP_MXTCPWM */
1732
1733 #endif /* CY_TCPWM_H */
1734
1735 /* [] END OF FILE */
1736