1 /***************************************************************************//**
2 * \file cy_tcpwm_pwm.h
3 * \version 1.70
4 *
5 * \brief
6 * The header file of the TCPWM PWM 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 
26 #if !defined(CY_TCPWM_PWM_H)
27 #define CY_TCPWM_PWM_H
28 
29 #include "cy_tcpwm.h"
30 
31 #ifdef CY_IP_MXTCPWM
32 
33 #if defined(__cplusplus)
34 extern "C" {
35 #endif
36 
37 /**
38 * \addtogroup group_tcpwm_pwm
39 * Driver API for PWM.
40 *
41 * The functions and other declarations used in this part of the driver are in cy_tcpwm_pwm.h.
42 * You can also include cy_pdl.h to get access to all
43 * functions and declarations in the PDL.
44 *
45 * Use PWM mode when an output square wave is needed with a specific
46 * period and duty cycle, such as:
47 * * Creating arbitrary square wave outputs
48 * * Driving an LED (changing the brightness)
49 * * Driving Motors (dead time assertion available)
50 *
51 * The PWM has the following features:
52 * * 16- or 32-bit Counter.
53 * * Two Programmable Period registers that can be swapped.
54 * * Two Output Compare registers that can be swapped on overflow and/or
55 * underflow.
56 * * Left Aligned, Right Aligned, Center Aligned, and Asymmetric Aligned modes
57 * * Continuous or One Shot run modes.
58 * * Pseudo Random mode.
59 * * Two PWM outputs with Dead Time insertion, and programmable polarity.
60 * * Interrupt on Terminal Count and Compare or Capture 0. Interrupt on Compare or Capture 1 is only available in TCPWM Version 2.
61 * * Start, Reload, Stop, Swap (Capture), and Count Inputs.
62 * * Immediate Kill, Kill 0 Input, Kill 1 Input, PWM output on Disable, PWM outputs, PWM Dead Time Clocks,
63 * Taps Enabled. All these features are only available in TCPWM Version 2.
64 * * Multiple Components can be synchronized together for applications.
65 * such as three phase motor control.
66 * * Two programmable trigger outputs, trig_out0 and trig_out1 that generate a
67 * trigger on one of the following events Overflow, Underflow, Terminal Count,
68 * Compare Match 0/1, and PWM output. The available triggers are dependent on the PWM mode.
69 * All these features are only available in TCPWM Version 2.
70 * * Overflow, Underflow, and Compare(cc_match) trigger outputs are only available in TCPWM Version 1.
71 * * Second Compare Match (CC_MATCH1) event is only available in TCPWM Version 2.
72 *
73 * \section group_tcpwm_pwm_configuration Configuration Considerations
74 *
75 * The PWM configuration can be divided to number of sequential
76 * steps listed below:
77 * * \ref group_tcpwm_pwm_config
78 * * \ref group_tcpwm_pwm_clock
79 * * \ref group_tcpwm_pwm_enable
80 * * \ref group_tcpwm_pwm_start
81 *
82 * \subsection group_tcpwm_pwm_config Configure PWM
83 * To configure PWM, provide the configuration parameters in the
84 * \ref cy_stc_tcpwm_pwm_config_t structure. The Configuration structure
85 * can be modified through software, but if the configurator in ModusToolbox is used
86 * then the configuration structure will be updated with the users input. To initialize
87 * the driver, call \ref Cy_TCPWM_PWM_Init function providing a pointer to the populated
88 * \ref cy_stc_tcpwm_pwm_config_t structure.
89 *
90 * For TCPWM V1 Configuration
91 * \snippet tcpwm/pwm/snippet/main.c snippet_Cy_TCPWM_V1_PWM_Init
92 *
93 * For TCPWM V2 Configuration
94 * \snippet tcpwm/pwm/snippet/main.c snippet_Cy_TCPWM_V2_PWM_Init
95 *
96 * \subsection group_tcpwm_pwm_clock Assign Clock Divider
97 * The clock source must be connected to proper working.
98 * Any of the peripheral clock dividers could be used. Use the
99 * \ref group_sysclk driver API to do that.
100 *
101 * \subsection group_tcpwm_pwm_enable Enable PWM
102 * PWM has to be enabled before starting
103 *
104 * \snippet tcpwm/pwm/snippet/main.c snippet_Cy_TCPWM_PWM_Enable
105 *
106 * \subsection group_tcpwm_pwm_start Start PWM
107 * PWM has to be started
108 *
109 * \snippet tcpwm/pwm/snippet/main.c snippet_Cy_TCPWM_PWM_Start
110 * \{
111 */
112 
113 /**
114 * \defgroup group_tcpwm_macros_pwm          Macros
115 * \defgroup group_tcpwm_functions_pwm       Functions
116 * \defgroup group_tcpwm_data_structures_pwm Data Structures
117 * \} */
118 
119 /**
120 * \addtogroup group_tcpwm_data_structures_pwm
121 * \{
122 */
123 #if defined (CY_IP_MXS40TCPWM) || defined (CY_DOXYGEN)
124 /** TCPWM Dithering  */
125 typedef enum
126 {
127     CY_TCPWM_DITHERING_DISABLE        = 0UL,   /**< TCPWM dithering is disabled */
128     CY_TCPWM_DITHERING_PERIOD         = 1UL,   /**< TCPWM dithering is set to period */
129     CY_TCPWM_DITHERING_DUTY           = 2UL,   /**< TCPWM dithering is set to duty */
130     CY_TCPWM_DITHERING_PERIOD_DUTY    = 3UL,   /**< TCPWM dithering is set to period and duty */
131 } cy_en_tcpwm_dithering_t ;
132 
133 /** TCPWM dithering limiter values */
134 typedef enum
135 {
136     CY_TCPWM_DITHERING_LIMITER_1           = 1UL,   /**< TCPWM dithering limiter value 1. */
137     CY_TCPWM_DITHERING_LIMITER_2           = 2UL,   /**< TCPWM dithering limiter value 2. */
138     CY_TCPWM_DITHERING_LIMITER_3           = 3UL,   /**< TCPWM dithering limiter value 3. */
139     CY_TCPWM_DITHERING_LIMITER_4           = 4UL,   /**< TCPWM dithering limiter value 4. */
140     CY_TCPWM_DITHERING_LIMITER_5           = 5UL,   /**< TCPWM dithering limiter value 5. */
141     CY_TCPWM_DITHERING_LIMITER_6           = 6UL,   /**< TCPWM dithering limiter value 6. */
142     CY_TCPWM_DITHERING_LIMITER_7           = 7UL,   /**< TCPWM dithering limiter value 7. */
143 } cy_en_dithering_limiter_t;
144 
145 /** HRPWM Operation Frequency
146     Selects the frequency of operation of HRPWM feature. Micro tick is adjusted based on this information. These bits specifies the frequency of CLK_OUT from TCPWM counter. CLK_OUT = CLK_PERI = CLK_HF */
147 typedef enum
148 {
149     CY_TCPWM_HRPWM_FREQ_80MHZ_OR_100MHZ                    = 0UL,   /**< HRPWM Iput Frequency is 80MHz or 100 MHz  */
150     CY_TCPWM_HRPWM_FREQ_150MHZ_OR_160MHZ_OR_180MHZ         = 1UL,   /**< HRPWM Iput Frequency is 150MHz or 160 MHz or 180 MHz */
151     CY_TCPWM_HRPWM_FREQ_200MHZ                             = 2UL,   /**< HRPWM Iput Frequency is 200 MHz  */
152     CY_TCPWM_HRPWM_FREQ_240MHZ                             = 3UL,   /**< HRPWM Iput Frequency is 240 MHz  */
153 } cy_en_hrpwm_operating_frequency_t;
154 
155 /**  Specifies the behavior of the PWM outputs line_out and line_out_compl_out while the TCPWM counter is disabled or stopped. */
156 typedef enum
157 {
158     CY_TCPWM_LINEOUT_AND_LINECMPOUT_IS_LOW           = 0UL,   /**< Line Out and Line Compl Out is Low during the kill and counter is disabled. */
159     CY_TCPWM_LINEOUT_IS_HIGH_AND_LINECMPOUT_IS_LOW   = 1UL,   /**< Line Out is High during the kill and counter is disabled. */
160     CY_TCPWM_LINECMPOUT_IS_HIGH_LINEOUT_IS_LOW       = 2UL,   /**< Line Compl Out is High during the kill and counter is disabled. */
161     CY_TCPWM_LINEOUT_AND_LINECMPOUT_IS_HIGH          = 3UL,   /**< Line Out and Line Compl Out is Hig during the kill and counter is disabled. */
162 } cy_en_kill_line_polarity_t;
163 #endif /* defined (CY_IP_MXS40TCPWM) || defined (CY_DOXYGEN) */
164 
165 #if (CY_IP_MXTCPWM_VERSION >= 2U) || defined (CY_DOXYGEN)
166 
167 /**  Source for the output signal "line_out" and  "line_compl_out" */
168 typedef enum
169 {
170     CY_TCPWM_OUTPUT_CONSTANT_0           = 0UL,   /**< Output signal is 0. */
171     CY_TCPWM_OUTPUT_CONSTANT_1           = 1UL,   /**< Output signal is 1. */
172     CY_TCPWM_OUTPUT_PWM_SIGNAL           = 2UL,   /**< Output signal is PWM Signal. */
173     CY_TCPWM_OUTPUT_INVERTED_PWM_SIGNAL  = 3UL,   /**< Output signal is inverted PWM Signal. */
174     CY_TCPWM_OUTPUT_PORT_DEFAULT         = 4UL,   /**< Output is not driven by the TCPWM. Instead the port default level configuration applies, e.g. "Z" (high impedance). */
175     CY_TCPWM_OUTPUT_SOURCE_MOTIF         = 5UL,   /**< Source for PWM signal conditioning comes from MOTIF modulation output control signals. It can be set to '0' , '1' or PWM. */
176 } cy_en_line_select_config_t;
177 #endif /* (CY_IP_MXTCPWM_VERSION >= 2U) || defined (CY_DOXYGEN) */
178 
179 /** PWM configuration structure */
180 typedef struct cy_stc_tcpwm_pwm_config
181 {
182     uint32_t    pwmMode;            /**< Sets the PWM mode. See \ref group_tcpwm_pwm_modes */
183     /** Sets the clock prescaler inside the TCWPM block. See \ref group_tcpwm_pwm_clk_prescalers */
184     uint32_t    clockPrescaler;
185     uint32_t    pwmAlignment;       /**< Sets the PWM alignment. See \ref group_tcpwm_pwm_alignment */
186     uint32_t    deadTimeClocks;     /**< The number of dead time-clocks if PWM with dead time is chosen */
187     uint32_t    runMode;            /**< Sets the PWM run mode. See \ref group_tcpwm_pwm_run_modes */
188     uint32_t    period0;            /**< Sets the period0 of the pwm */
189     uint32_t    period1;            /**< Sets the period1 of the pwm */
190     bool        enablePeriodSwap;   /**< Enables swapping of period 0 and period 1 on terminal count */
191     uint32_t    compare0;           /**< Sets the value for Compare 0 */
192     uint32_t    compare1;           /**< Sets the value for the buffered Compare 0 */
193     bool        enableCompareSwap;  /**< If enabled, the compare values are swapped on the terminal count */
194     /** Enables an interrupt on the terminal count, capture or compare. See \ref group_tcpwm_interrupt_sources */
195     uint32_t    interruptSources;
196     /** Inverts the PWM output. This field also defines the state of the PWM output while PWM is enabled, but not running. */
197     uint32_t    invertPWMOut;
198     /** Inverts the PWM_n output. This field also defines the state of the PWM_n output while PWM is enabled, but not running. */
199     uint32_t    invertPWMOutN;
200     uint32_t    killMode;           /**< Configures the PWM kill modes. See \ref group_tcpwm_pwm_kill_modes */
201     uint32_t    swapInputMode;      /**< Configures how the swap input behaves. See \ref group_tcpwm_input_modes */
202     /** Selects which input the swap uses. Inputs are device-specific. See \ref group_tcpwm_input_selection */
203     uint32_t    swapInput;
204     uint32_t    reloadInputMode;    /**< Configures how the reload input behaves. See \ref group_tcpwm_input_modes */
205     /** Selects which input the reload uses. The inputs are device-specific. See \ref group_tcpwm_input_selection */
206     uint32_t    reloadInput;
207     uint32_t    startInputMode;     /**< Configures how the start input behaves. See \ref group_tcpwm_input_modes */
208     /** Selects which input the start uses. The inputs are device-specific. See \ref group_tcpwm_input_selection */
209     uint32_t    startInput;
210     uint32_t    killInputMode;      /**< Configures how the kill input behaves. See \ref group_tcpwm_input_modes */
211     /** Selects which input the kill uses. The inputs are device-specific. See \ref group_tcpwm_input_selection */
212     uint32_t    killInput;
213     uint32_t    countInputMode;     /**< Configures how the count input behaves. See \ref group_tcpwm_input_modes */
214     /** Selects which input the count uses. The inputs are device-specific. See \ref group_tcpwm_input_selection */
215     uint32_t    countInput;
216     /** If enabled, line output is set on underflow and cleared on overflow. This configuration is available only in center and asymmetric alignment modes. */
217     bool        swapOverflowUnderflow;
218 #if (CY_IP_MXTCPWM_VERSION >= 2U)
219     bool        immediateKill;      /**< Specifies whether the kill event immediately deactivates the dt_line_out and dt_line_compl_out or with the next module clock */
220     uint32_t    tapsEnabled;        /**< In pseudo random mode sets the enabled taps */
221     uint32_t    compare2;           /**< Sets the value for Compare1  */
222     uint32_t    compare3;           /**< Sets the value for the buffered Compare1 */
223     bool        enableCompare1Swap; /**< If enabled, the compare1 values are swapped on the terminal count */
224     bool        compare0MatchUp;    /**< Enables/Disables the compare match 0 event generation when counting up in CNT_UPDN1/2 mode */
225     bool        compare0MatchDown;  /**< Enables/Disables the compare match 0 event generation when counting down in CNT_UPDN1/2 mode */
226     bool        compare1MatchUp;    /**< Enables/Disables the compare match 1 event generation when counting up in CNT_UPDN1/2 mode */
227     bool        compare1MatchDown;  /**< Enables/Disables the compare match 1 event generation when counting down in CNT_UPDN1/2 mode */
228     uint32_t    kill1InputMode;     /**< Configures how the kill 1 input behaves. See \ref group_tcpwm_input_modes */
229     uint32_t    kill1Input;         /**< Selects which input the kill 1 uses. The inputs are device-specific. See \ref group_tcpwm_input_selection */
230     uint32_t    pwmOnDisable;       /**< Specifies the behavior of the PWM outputs line_out and line_compl_out while the TCPWM counter is disabled */
231     uint32_t    trigger0Event;      /**< Configures which internal event generates on output trigger 0*/
232     uint32_t    trigger1Event;      /**< Configures which internal event generates on output trigger 1*/
233     bool        reloadLineSelect;   /**< Configures how the reload line select behaves. */
234     cy_en_line_select_config_t line_out_sel;          /**< Output signal source for PWM line out. */
235     cy_en_line_select_config_t linecompl_out_sel;     /**< Output signal source for PWM line compl out. */
236     cy_en_line_select_config_t line_out_sel_buff;      /**< Buffer Value Output signal source for PWM line out. Can be swapped with Line out on a terminal count event. */
237     cy_en_line_select_config_t linecompl_out_sel_buff; /**< Buffer Value Output signal source for PWM line compl out. Can be swapped with Linecompl out on a terminal count event. */
238     uint16_t    deadTimeClocks_linecompl_out;     /**< The number of dead time-clocks for line compl out if PWM with dead time is chosen */
239 #endif /* (CY_IP_MXTCPWM_VERSION >= 2U) || defined (CY_DOXYGEN) */
240 #if defined (CY_IP_MXS40TCPWM) || defined (CY_DOXYGEN)
241     bool        buffer_swap_enable; /**< Configures swapping mechanism between CC0 and buffered CC0, CC1 and buffered CC1, PERIOD and buffered PERIOD, DT and buffered DT  */
242     cy_en_tcpwm_dithering_t  dithering_mode; /**< Dithering mode is group specific configuration and will be applicable if the group supports dithering */
243     uint8_t period_dithering_value;      /**< Dithering value for period LFSR. Should be non zero value. */
244     uint8_t duty_dithering_value;        /**< Dithering value for duty LFSR. Should be non zero value. */
245     cy_en_dithering_limiter_t limiter;  /**< Magnitude of the pseudo-random value to be added to period/CC0/CC1 \ref cy_en_dithering_limiter_t */
246     bool        hrpwm_enable;            /**< If enabled, high resolution PWM path is enabled */
247     cy_en_hrpwm_operating_frequency_t hrpwm_input_freq; /**< Frequency of operation for HRPWM */
248     cy_en_kill_line_polarity_t kill_line_polarity; /**< Outputs line_out and line_out_compl_out while the TCPWM counter is disabled or stopped. */
249     uint32_t    deadTimeClocksBuff;     /**< Buffer value for the number of dead time-clocks if PWM with dead time is chosen. Can be swapped with Line out on a terminal count event. */
250     uint16_t    deadTimeClocksBuff_linecompl_out;     /**< The number of dead time-clocks for line compl out if PWM with dead time is chosen */
251     bool        glitch_filter_enable;   /**< Enables Glitch filter for input triggers. */
252     cy_en_gf_depth_value_t gf_depth;    /**< Glitch filter depth value. */
253 #endif /* defined (CY_IP_MXS40TCPWM) || defined (CY_DOXYGEN) */
254 }cy_stc_tcpwm_pwm_config_t;
255 /** \} group_tcpwm_data_structures_pwm */
256 
257 /**
258 * \addtogroup group_tcpwm_macros_pwm
259 * \{
260 * \defgroup group_tcpwm_pwm_run_modes PWM run modes
261 * \{
262 * Run modes for the pwm timer.
263 */
264 #define CY_TCPWM_PWM_ONESHOT            (1U)    /**< Counter runs once and then stops */
265 #define CY_TCPWM_PWM_CONTINUOUS         (0U)    /**< Counter runs forever */
266 /** \} group_tcpwm_pwm_run_modes */
267 
268 /** \defgroup group_tcpwm_pwm_modes PWM modes
269 * \{
270 * Sets the PWM modes.
271 */
272 #define CY_TCPWM_PWM_MODE_PWM           (4U) /**< Standard PWM Mode*/
273 #define CY_TCPWM_PWM_MODE_DEADTIME      (5U)    /**< PWM with deadtime mode*/
274 #define CY_TCPWM_PWM_MODE_PSEUDORANDOM  (6U)    /**< Pseudo Random PWM */
275 /** \} group_tcpwm_pwm_modes */
276 
277 /** \defgroup group_tcpwm_pwm_alignment PWM Alignment
278 * Sets the alignment of the PWM.
279 * \{
280 */
281 #define CY_TCPWM_PWM_LEFT_ALIGN                         (0U)     /**< PWM is left aligned, meaning it starts high */
282 #define CY_TCPWM_PWM_RIGHT_ALIGN                        (1U)        /**< PWM is right aligned, meaning it starts low */
283 /** PWM is centered aligned, terminal count only occurs on underflow */
284 #define CY_TCPWM_PWM_CENTER_ALIGN                       (2U)
285 /** PWM is asymmetrically aligned, terminal count occurs on overflow and underflow */
286 #define CY_TCPWM_PWM_ASYMMETRIC_ALIGN                   (3U)
287 #define CY_TCPWM_PWM_ASYMMETRIC_CC0_CC1_ALIGN           (4U) /**< PWM is asymmetrically aligned, line pulse period is equal to CC1-CC0 */
288 #define CY_TCPWM_PWM_CENTER_ASYMMETRIC_CC0_CC1_ALIGN    (5U) /**< PWM is asymmetrically aligned, TBD */
289 /** \} group_tcpwm_pwm_alignment */
290 
291 /** \defgroup group_tcpwm_pwm_kill_modes PWM kill modes
292 * Sets the kill mode for the PWM.
293 * \{
294 */
295 #define CY_TCPWM_PWM_STOP_ON_KILL       (2U)    /**< PWM stops counting on kill */
296 #define CY_TCPWM_PWM_SYNCH_KILL         (1U)    /**< PWM output is killed after next TC*/
297 #define CY_TCPWM_PWM_ASYNC_KILL         (0U)    /**< PWM output is killed instantly */
298 /** \} group_tcpwm_pwm_kill_modes */
299 
300 /** \defgroup group_tcpwm_pwm_output_on_disable PWM Disabled Output
301 * Specifies the behavior of the PWM outputs while PWM is disabled.
302 * \{
303 */
304 #define    CY_TCPWM_PWM_OUTPUT_HIGHZ    (0U)    /**< PWM output (default) high impedance */
305 #define    CY_TCPWM_PWM_OUTPUT_RETAIN   (1U)    /**< PWM outputs are retained */
306 #define    CY_TCPWM_PWM_OUTPUT_LOW      (2U)    /**< PWM output LOW */
307 #define    CY_TCPWM_PWM_OUTPUT_HIGH     (3U)    /**< PWM output HIGH */
308 /** \} group_tcpwm_pwm_output_on_disable */
309 
310 /** \defgroup group_tcpwm_pwm_output_line PWM Output Lines
311 * Specifies the PWM output line.
312 * \{
313 */
314 #define    CY_TCPWM_PWM_LINE_PWM        (0U)    /**< PWM Line output */
315 #define    CY_TCPWM_PWM_LINE_PWM_INV    (1U)    /**< PWM Line output compliment */
316 /** \} group_tcpwm_pwm_output_line */
317 
318 /** \defgroup group_tcpwm_pwm_clk_prescalers PWM CLK Prescaler values
319 * \{
320 * Clock prescaler values.
321 */
322 #define CY_TCPWM_PWM_PRESCALER_DIVBY_1      (0U) /**< Divide by 1 */
323 #define CY_TCPWM_PWM_PRESCALER_DIVBY_2      (1U) /**< Divide by 2 */
324 #define CY_TCPWM_PWM_PRESCALER_DIVBY_4      (2U) /**< Divide by 4 */
325 #define CY_TCPWM_PWM_PRESCALER_DIVBY_8      (3U) /**< Divide by 8 */
326 #define CY_TCPWM_PWM_PRESCALER_DIVBY_16     (4U) /**< Divide by 16 */
327 #define CY_TCPWM_PWM_PRESCALER_DIVBY_32     (5U) /**< Divide by 32 */
328 #define CY_TCPWM_PWM_PRESCALER_DIVBY_64     (6U) /**< Divide by 64 */
329 #define CY_TCPWM_PWM_PRESCALER_DIVBY_128    (7U) /**< Divide by 128 */
330 /** \} group_tcpwm_pwm_clk_prescalers */
331 
332 /** \defgroup group_tcpwm_pwm_output_invert PWM output invert
333 * \{
334 * Output invert modes.
335 */
336 #define CY_TCPWM_PWM_INVERT_ENABLE          (1U)  /**< Invert the output mode */
337 #define CY_TCPWM_PWM_INVERT_DISABLE         (0U)  /**< Do not invert the output mode */
338 /** \} group_tcpwm_pwm_output_invert */
339 
340 /** \defgroup group_tcpwm_pwm_status PWM Status
341 * \{
342 * The counter status.
343 */
344 #define CY_TCPWM_PWM_STATUS_DOWN_COUNTING   (0x1UL)        /**< PWM is down counting */
345 #define CY_TCPWM_PWM_STATUS_UP_COUNTING     (0x2UL)        /**< PWM is up counting */
346 #define CY_TCPWM_PWM_STATUS_COUNTER_RUNNING (0x80000000UL) /**< PWM counter is running */
347 /** \} group_tcpwm_pwm_status */
348 /** \} group_tcpwm_macros_pwm */
349 
350 
351 /*******************************************************************************
352 * Backward compatibility macro. The following code is DEPRECATED and must
353 * not be used in new projects
354 *******************************************************************************/
355 
356 #define Cy_TCPWM_PWM_SetCompare0        Cy_TCPWM_PWM_SetCompare0Val
357 #define Cy_TCPWM_PWM_GetCompare0        Cy_TCPWM_PWM_GetCompare0Val
358 #define Cy_TCPWM_PWM_SetCompare1        Cy_TCPWM_PWM_SetCompare0BufVal
359 #define Cy_TCPWM_PWM_GetCompare1        Cy_TCPWM_PWM_GetCompare0BufVal
360 #define Cy_TCPWM_PWM_EnableCompareSwap  Cy_TCPWM_PWM_EnableCompare0Swap
361 
362 
363 /***************************************
364 *        Registers Constants
365 ***************************************/
366 
367 /** \cond INTERNAL */
368 #define CY_TCPWM_PWM_CTRL_SYNC_KILL_OR_STOP_ON_KILL_POS  (2U)
369 #define CY_TCPWM_PWM_CTRL_SYNC_KILL_OR_STOP_ON_KILL_MASK (0x3UL << CY_TCPWM_PWM_CTRL_SYNC_KILL_OR_STOP_ON_KILL_POS)
370 
371 #define CY_TCPWM_PWM_TR_CTRL2_SET           (0UL) /**< Set define for PWM output signal configuration */
372 #define CY_TCPWM_PWM_TR_CTRL2_CLEAR         (1UL) /**< Clear define for PWM output signal configuration */
373 #define CY_TCPWM_PWM_TR_CTRL2_INVERT        (2UL) /**< Invert define for PWM output signal configuration */
374 #define CY_TCPWM_PWM_TR_CTRL2_NO_CHANGE     (3UL) /**< No change define for PWM output signal configuration */
375 
376 #if (CY_IP_MXTCPWM_VERSION == 1U)
377 /** The configuration of PWM output signal in Pseudo Random Mode */
378 #define CY_TCPWM_PWM_MODE_PR         (_VAL2FLD(TCPWM_CNT_TR_CTRL2_CC_MATCH_MODE, CY_TCPWM_PWM_TR_CTRL2_NO_CHANGE) | \
379                                       _VAL2FLD(TCPWM_CNT_TR_CTRL2_OVERFLOW_MODE, CY_TCPWM_PWM_TR_CTRL2_NO_CHANGE) | \
380                                       _VAL2FLD(TCPWM_CNT_TR_CTRL2_UNDERFLOW_MODE, CY_TCPWM_PWM_TR_CTRL2_NO_CHANGE))
381 
382 /** The configuration of PWM output signal for Left alignment */
383 #define CY_TCPWM_PWM_MODE_LEFT       (_VAL2FLD(TCPWM_CNT_TR_CTRL2_CC_MATCH_MODE, CY_TCPWM_PWM_TR_CTRL2_CLEAR) | \
384                                       _VAL2FLD(TCPWM_CNT_TR_CTRL2_OVERFLOW_MODE, CY_TCPWM_PWM_TR_CTRL2_SET) | \
385                                       _VAL2FLD(TCPWM_CNT_TR_CTRL2_UNDERFLOW_MODE, CY_TCPWM_PWM_TR_CTRL2_NO_CHANGE))
386 
387 /** The configuration of PWM output signal for Right alignment */
388 #define CY_TCPWM_PWM_MODE_RIGHT      (_VAL2FLD(TCPWM_CNT_TR_CTRL2_CC_MATCH_MODE, CY_TCPWM_PWM_TR_CTRL2_SET) | \
389                                       _VAL2FLD(TCPWM_CNT_TR_CTRL2_OVERFLOW_MODE, CY_TCPWM_PWM_TR_CTRL2_NO_CHANGE) | \
390                                       _VAL2FLD(TCPWM_CNT_TR_CTRL2_UNDERFLOW_MODE, CY_TCPWM_PWM_TR_CTRL2_CLEAR))
391 
392 /** The configuration of PWM output signal for Center and Asymmetric alignment */
393 #define CY_TCPWM_PWM_MODE_CNTR_OR_ASYMM (_VAL2FLD(TCPWM_CNT_TR_CTRL2_CC_MATCH_MODE, CY_TCPWM_PWM_TR_CTRL2_INVERT) | \
394                                          _VAL2FLD(TCPWM_CNT_TR_CTRL2_OVERFLOW_MODE, CY_TCPWM_PWM_TR_CTRL2_SET) | \
395                                          _VAL2FLD(TCPWM_CNT_TR_CTRL2_UNDERFLOW_MODE, CY_TCPWM_PWM_TR_CTRL2_CLEAR))
396 
397 /** The configuration of PWM output signal for Center and Asymmetric alignment with swapped underflow and overflow setting */
398 #define CY_TCPWM_PWM_MODE_CNTR_OR_ASYMM_SWAPPED (_VAL2FLD(TCPWM_CNT_TR_CTRL2_CC_MATCH_MODE, CY_TCPWM_PWM_TR_CTRL2_INVERT) | \
399                                          _VAL2FLD(TCPWM_CNT_TR_CTRL2_OVERFLOW_MODE, CY_TCPWM_PWM_TR_CTRL2_CLEAR) | \
400                                          _VAL2FLD(TCPWM_CNT_TR_CTRL2_UNDERFLOW_MODE, CY_TCPWM_PWM_TR_CTRL2_SET))
401 
402 #else
403 
404 /** The configuration of PWM output signal in Pseudo Random Mode */
405 #define CY_TCPWM_PWM_MODE_PR         (_VAL2FLD(TCPWM_GRP_CNT_V2_TR_PWM_CTRL_CC0_MATCH_MODE, CY_TCPWM_PWM_TR_CTRL2_NO_CHANGE) | \
406                                       _VAL2FLD(TCPWM_GRP_CNT_V2_TR_PWM_CTRL_OVERFLOW_MODE, CY_TCPWM_PWM_TR_CTRL2_NO_CHANGE) | \
407                                       _VAL2FLD(TCPWM_GRP_CNT_V2_TR_PWM_CTRL_UNDERFLOW_MODE, CY_TCPWM_PWM_TR_CTRL2_NO_CHANGE))
408 
409 /** The configuration of PWM output signal for Left alignment */
410 #define CY_TCPWM_PWM_MODE_LEFT       (_VAL2FLD(TCPWM_GRP_CNT_V2_TR_PWM_CTRL_CC0_MATCH_MODE, CY_TCPWM_PWM_TR_CTRL2_CLEAR) | \
411                                       _VAL2FLD(TCPWM_GRP_CNT_V2_TR_PWM_CTRL_OVERFLOW_MODE, CY_TCPWM_PWM_TR_CTRL2_SET) | \
412                                       _VAL2FLD(TCPWM_GRP_CNT_V2_TR_PWM_CTRL_UNDERFLOW_MODE, CY_TCPWM_PWM_TR_CTRL2_NO_CHANGE))
413 
414 /** The configuration of PWM output signal for Right alignment */
415 #define CY_TCPWM_PWM_MODE_RIGHT      (_VAL2FLD(TCPWM_GRP_CNT_V2_TR_PWM_CTRL_CC0_MATCH_MODE, CY_TCPWM_PWM_TR_CTRL2_SET) | \
416                                       _VAL2FLD(TCPWM_GRP_CNT_V2_TR_PWM_CTRL_OVERFLOW_MODE, CY_TCPWM_PWM_TR_CTRL2_NO_CHANGE) | \
417                                       _VAL2FLD(TCPWM_GRP_CNT_V2_TR_PWM_CTRL_UNDERFLOW_MODE, CY_TCPWM_PWM_TR_CTRL2_CLEAR))
418 
419 /** The configuration of PWM output signal for Center and Asymmetric alignment */
420 #define CY_TCPWM_PWM_MODE_CNTR_OR_ASYMM (_VAL2FLD(TCPWM_GRP_CNT_V2_TR_PWM_CTRL_CC0_MATCH_MODE, CY_TCPWM_PWM_TR_CTRL2_INVERT) | \
421                                          _VAL2FLD(TCPWM_GRP_CNT_V2_TR_PWM_CTRL_OVERFLOW_MODE, CY_TCPWM_PWM_TR_CTRL2_SET) | \
422                                          _VAL2FLD(TCPWM_GRP_CNT_V2_TR_PWM_CTRL_UNDERFLOW_MODE, CY_TCPWM_PWM_TR_CTRL2_CLEAR))
423 
424 /** The configuration of PWM output signal for Center and Asymmetric alignment with swapped underflow and overflow setting */
425 #define CY_TCPWM_PWM_MODE_CNTR_OR_ASYMM_SWAPPED (_VAL2FLD(TCPWM_GRP_CNT_V2_TR_PWM_CTRL_CC0_MATCH_MODE, CY_TCPWM_PWM_TR_CTRL2_INVERT) | \
426                                          _VAL2FLD(TCPWM_GRP_CNT_V2_TR_PWM_CTRL_OVERFLOW_MODE, CY_TCPWM_PWM_TR_CTRL2_CLEAR) | \
427                                          _VAL2FLD(TCPWM_GRP_CNT_V2_TR_PWM_CTRL_UNDERFLOW_MODE, CY_TCPWM_PWM_TR_CTRL2_SET))
428 
429 /** The configuration of PWM output signal to ignore CC1 match event */
430 #define CY_TCPWM_PWM_MODE_CC1_IGNORE   (_VAL2FLD(TCPWM_GRP_CNT_V2_TR_PWM_CTRL_CC1_MATCH_MODE, CY_TCPWM_PWM_TR_CTRL2_NO_CHANGE))
431 
432 /** The configuration of PWM output signal for Asymmetric with cc0 and cc1 mode (tcpwm_ver2 only)*/
433 #define CY_TCPWM_PWM_MODE_ASYMM_CC0_CC1    (_VAL2FLD(TCPWM_GRP_CNT_V2_TR_PWM_CTRL_CC0_MATCH_MODE, CY_TCPWM_PWM_TR_CTRL2_SET) | \
434                                             _VAL2FLD(TCPWM_GRP_CNT_V2_TR_PWM_CTRL_OVERFLOW_MODE, CY_TCPWM_PWM_TR_CTRL2_CLEAR) | \
435                                             _VAL2FLD(TCPWM_GRP_CNT_V2_TR_PWM_CTRL_UNDERFLOW_MODE, CY_TCPWM_PWM_TR_CTRL2_CLEAR) | \
436                                             _VAL2FLD(TCPWM_GRP_CNT_V2_TR_PWM_CTRL_CC1_MATCH_MODE, CY_TCPWM_PWM_TR_CTRL2_CLEAR))
437 
438 /** The configuration of PWM output signal for Center Align Asymmetric with cc0 and cc1 mode (tcpwm_ver2 only)*/
439 #define CY_TCPWM_PWM_MODE_CNTR_ASYMM_CC0_CC1   (_VAL2FLD(TCPWM_GRP_CNT_V2_TR_PWM_CTRL_CC0_MATCH_MODE, CY_TCPWM_PWM_TR_CTRL2_SET) | \
440                                                 _VAL2FLD(TCPWM_GRP_CNT_V2_TR_PWM_CTRL_OVERFLOW_MODE, CY_TCPWM_PWM_TR_CTRL2_SET) | \
441                                                 _VAL2FLD(TCPWM_GRP_CNT_V2_TR_PWM_CTRL_UNDERFLOW_MODE, CY_TCPWM_PWM_TR_CTRL2_CLEAR) | \
442                                                 _VAL2FLD(TCPWM_GRP_CNT_V2_TR_PWM_CTRL_CC1_MATCH_MODE, CY_TCPWM_PWM_TR_CTRL2_CLEAR))
443 
444 #define CY_TCPWM_PWM_MODE_CNTR_ASYMM_CC0_CC1_MATCH    ((TCPWM_GRP_CNT_V2_CTRL_CC0_MATCH_UP_EN_Msk) | \
445                                                        (TCPWM_GRP_CNT_V2_CTRL_CC1_MATCH_DOWN_EN_Msk))
446 #endif
447 /** \endcond */
448 
449 
450 /*******************************************************************************
451 *        Function Prototypes
452 *******************************************************************************/
453 
454 /**
455 * \addtogroup group_tcpwm_functions_pwm
456 * \{
457 */
458 
459 cy_en_tcpwm_status_t Cy_TCPWM_PWM_Init(TCPWM_Type *base, uint32_t cntNum, cy_stc_tcpwm_pwm_config_t const *config);
460 void Cy_TCPWM_PWM_DeInit(TCPWM_Type *base, uint32_t cntNum, cy_stc_tcpwm_pwm_config_t const *config);
461 __STATIC_INLINE void Cy_TCPWM_PWM_Enable(TCPWM_Type *base, uint32_t cntNum);
462 __STATIC_INLINE void Cy_TCPWM_PWM_Disable(TCPWM_Type *base, uint32_t cntNum);
463 __STATIC_INLINE uint32_t Cy_TCPWM_PWM_GetStatus(TCPWM_Type const *base, uint32_t cntNum);
464 __STATIC_INLINE void Cy_TCPWM_PWM_SetCompare0Val(TCPWM_Type *base, uint32_t cntNum, uint32_t compare0);
465 __STATIC_INLINE uint32_t Cy_TCPWM_PWM_GetCompare0Val(TCPWM_Type const *base, uint32_t cntNum);
466 __STATIC_INLINE void Cy_TCPWM_PWM_SetCompare0BufVal(TCPWM_Type *base, uint32_t cntNum, uint32_t compareBuf0);
467 __STATIC_INLINE uint32_t Cy_TCPWM_PWM_GetCompare0BufVal(TCPWM_Type const *base, uint32_t cntNum);
468 __STATIC_INLINE void Cy_TCPWM_PWM_EnableCompare0Swap(TCPWM_Type *base, uint32_t cntNum, bool enable);
469 __STATIC_INLINE void Cy_TCPWM_PWM_SetCounter(TCPWM_Type *base, uint32_t cntNum, uint32_t count);
470 __STATIC_INLINE uint32_t Cy_TCPWM_PWM_GetCounter(TCPWM_Type const *base, uint32_t cntNum);
471 __STATIC_INLINE void Cy_TCPWM_PWM_SetPeriod0(TCPWM_Type *base, uint32_t cntNum, uint32_t period0);
472 __STATIC_INLINE uint32_t Cy_TCPWM_PWM_GetPeriod0(TCPWM_Type const *base, uint32_t cntNum);
473 __STATIC_INLINE void Cy_TCPWM_PWM_SetPeriod1(TCPWM_Type *base, uint32_t cntNum, uint32_t period1);
474 __STATIC_INLINE uint32_t Cy_TCPWM_PWM_GetPeriod1(TCPWM_Type const *base, uint32_t cntNum);
475 __STATIC_INLINE void Cy_TCPWM_PWM_EnablePeriodSwap(TCPWM_Type *base, uint32_t cntNum, bool enable);
476 #if (CY_IP_MXTCPWM_VERSION >= 2U) || defined (CY_DOXYGEN)
477 __STATIC_INLINE uint32_t Cy_TCPWM_PWM_GetDtCounter (TCPWM_Type const *base, uint32_t cntNum);
478 __STATIC_INLINE uint32_t Cy_TCPWM_PWM_LineOutStatus (TCPWM_Type const *base, uint32_t cntNum, uint32_t pwmOutSelect);
479 #endif
480 __STATIC_INLINE void Cy_TCPWM_PWM_PWMDeadTime (TCPWM_Type const *base, uint32_t cntNum, uint32_t deadTime);
481 #if (CY_IP_MXTCPWM_VERSION >= 2U) || defined (CY_DOXYGEN)
482 __STATIC_INLINE void Cy_TCPWM_PWM_PWMDeadTimeN (TCPWM_Type const *base, uint32_t cntNum, uint32_t deadTime);
483 __STATIC_INLINE void Cy_TCPWM_PWM_Configure_LineSelect(TCPWM_Type *base, uint32_t cntNum,  cy_en_line_select_config_t line_out_val, cy_en_line_select_config_t line_compl_value);
484 __STATIC_INLINE void Cy_TCPWM_PWM_Configure_LineSelectBuff(TCPWM_Type *base, uint32_t cntNum,  cy_en_line_select_config_t line_out_val, cy_en_line_select_config_t line_compl_value);
485 __STATIC_INLINE void Cy_TCPWM_PWM_EnableLineSelectSwap(TCPWM_Type *base, uint32_t cntNum,  bool enable);
486 __STATIC_INLINE void Cy_TCPWM_PWM_SetDT (TCPWM_Type const *base, uint32_t cntNum, uint32_t deadTime);
487 #endif
488 #if defined (CY_IP_MXS40TCPWM) || defined (CY_DOXYGEN)
489 __STATIC_INLINE void Cy_TCPWM_PWM_EnableSwap(TCPWM_Type *base, uint32_t cntNum,  bool enable);
490 cy_en_tcpwm_status_t Cy_TCPWM_PWM_Configure_Dithering(TCPWM_Type *base, uint32_t cntNum, cy_en_tcpwm_dithering_t  mode, uint8_t period, uint8_t duty, cy_en_dithering_limiter_t limiter);
491 __STATIC_INLINE void Cy_TCPWM_PWM_PWMDeadTimeBuff (TCPWM_Type const *base, uint32_t cntNum, uint32_t deadTime);
492 __STATIC_INLINE void Cy_TCPWM_PWM_PWMDeadTimeBuffN (TCPWM_Type const *base, uint32_t cntNum, uint32_t deadTime);
493 __STATIC_INLINE void Cy_TCPWM_PWM_SetDTBuff (TCPWM_Type const *base, uint32_t cntNum, uint32_t deadTime);
494 #endif /* defined (CY_IP_MXS40TCPWM) || defined (CY_DOXYGEN) */
495 /*******************************************************************************
496 * Function Name: Cy_TCPWM_PWM_Enable
497 ****************************************************************************//**
498 *
499 * Enables the counter in the TCPWM block for the PWM operation.
500 *
501 * \param base
502 * The pointer to a TCPWM instance.
503 *
504 * \param cntNum
505 * The Counter instance number in the selected TCPWM.
506 *
507 * \funcusage
508 * \snippet tcpwm/pwm/snippet/main.c snippet_Cy_TCPWM_V1_PWM_Init
509 * \snippet tcpwm/pwm/snippet/main.c snippet_Cy_TCPWM_V2_PWM_Init
510 *
511 *******************************************************************************/
Cy_TCPWM_PWM_Enable(TCPWM_Type * base,uint32_t cntNum)512 __STATIC_INLINE void Cy_TCPWM_PWM_Enable(TCPWM_Type *base, uint32_t cntNum)
513 {
514     Cy_TCPWM_Enable_Single(base, cntNum);
515 }
516 
517 /*******************************************************************************
518 * Function Name: Cy_TCPWM_PWM_Disable
519 ****************************************************************************//**
520 *
521 * Disables the counter in the TCPWM block.
522 *
523 * \note This function sets connected PWM output pins Drive modes to High-Z state.
524 * To disable PWM without changing pins drive modes, use the
525 * \ref Cy_TCPWM_TriggerStopOrKill or \ref Cy_TCPWM_TriggerStopOrKill_Single
526 * function.
527 *
528 * \param base
529 * The pointer to a TCPWM instance.
530 *
531 * \param cntNum
532 * The Counter instance number in the selected TCPWM.
533 *
534 * \funcusage
535 * \snippet tcpwm/pwm/snippet/main.c snippet_Cy_TCPWM_PWM_DeInit
536 *
537 *******************************************************************************/
Cy_TCPWM_PWM_Disable(TCPWM_Type * base,uint32_t cntNum)538 __STATIC_INLINE void Cy_TCPWM_PWM_Disable(TCPWM_Type *base, uint32_t cntNum)
539 {
540     Cy_TCPWM_Disable_Single(base, cntNum);
541 }
542 
543 
544 /*******************************************************************************
545 * Function Name: Cy_TCPWM_PWM_GetStatus
546 ****************************************************************************//**
547 *
548 * Returns the status of the PWM whether it is running or not. In case the
549 * PWM is running, status will also provide information on counting up/down. This
550 * is useful when the PWM Alignment mode set to Center/Asymmetric Alignments.
551 *
552 * \param base
553 * The pointer to a TCPWM instance.
554 *
555 * \param cntNum
556 * The Counter instance number in the selected TCPWM.
557 *
558 * \return
559 * The status. See \ref group_tcpwm_pwm_status
560 *
561 * \funcusage
562 * \snippet tcpwm/pwm/snippet/main.c snippet_Cy_TCPWM_PWM_GetStatus
563 *
564 *******************************************************************************/
Cy_TCPWM_PWM_GetStatus(TCPWM_Type const * base,uint32_t cntNum)565 __STATIC_INLINE uint32_t Cy_TCPWM_PWM_GetStatus(TCPWM_Type const *base, uint32_t cntNum)
566 {
567     uint32_t status;
568 
569 #if (CY_IP_MXTCPWM_VERSION == 1U)
570 
571         status = TCPWM_CNT_STATUS(base, cntNum);
572 
573         /* Generates proper up counting status, does not generated by HW */
574         status &= ~CY_TCPWM_PWM_STATUS_UP_COUNTING;
575         status |= ((~status & CY_TCPWM_PWM_STATUS_DOWN_COUNTING & (status >> TCPWM_CNT_STATUS_RUNNING_Pos)) <<
576                    CY_TCPWM_CNT_STATUS_UP_POS);
577 #else
578         status = TCPWM_GRP_CNT_STATUS(base, TCPWM_GRP_CNT_GET_GRP(cntNum), cntNum);
579 
580         /* Generates proper up counting status, does not generated by HW */
581         status &= ~CY_TCPWM_PWM_STATUS_UP_COUNTING;
582         status |= ((~status & CY_TCPWM_PWM_STATUS_DOWN_COUNTING & (status >> TCPWM_GRP_CNT_V2_STATUS_RUNNING_Pos)) <<
583                    CY_TCPWM_CNT_STATUS_UP_POS);
584 
585         /* Set TCPWM_CNT_STATUS_RUNNING_Pos with TCPWM_GRP_CNT_V2_STATUS_RUNNING for BWC */
586         status |= (_FLD2VAL(TCPWM_GRP_CNT_V2_STATUS_RUNNING, status) << TCPWM_CNT_STATUS_RUNNING_Pos);
587 #endif
588 
589     return(status);
590 }
591 
592 
593 /*******************************************************************************
594 * Function Name: Cy_TCPWM_PWM_SetCompare0Val
595 ****************************************************************************//**
596 *
597 * Sets the compare value for Compare 0 when the compare mode enabled.
598 *
599 * \param base
600 * The pointer to a TCPWM instance.
601 *
602 * \param cntNum
603 * The Counter instance number in the selected TCPWM.
604 *
605 * \param compare0
606 * The Compare 0 value.
607 *
608 * \funcusage
609 * \snippet tcpwm/pwm/snippet/main.c snippet_Cy_TCPWM_PWM_SetCompare0Val
610 *
611 *******************************************************************************/
Cy_TCPWM_PWM_SetCompare0Val(TCPWM_Type * base,uint32_t cntNum,uint32_t compare0)612 __STATIC_INLINE void Cy_TCPWM_PWM_SetCompare0Val(TCPWM_Type *base, uint32_t cntNum,  uint32_t compare0)
613 {
614     Cy_TCPWM_Block_SetCC0Val(base, cntNum, compare0);
615 }
616 
617 
618 /*******************************************************************************
619 * Function Name: Cy_TCPWM_PWM_GetCompare0Val
620 ****************************************************************************//**
621 *
622 * Returns compare 0 value.
623 *
624 * \param base
625 * The pointer to a TCPWM instance.
626 *
627 * \param cntNum
628 * The Counter instance number in the selected TCPWM.
629 *
630 * \return
631 * Compare 0 value.
632 *
633 * \funcusage
634 * \snippet tcpwm/pwm/snippet/main.c snippet_Cy_TCPWM_PWM_SetCompare0Val
635 *
636 *******************************************************************************/
Cy_TCPWM_PWM_GetCompare0Val(TCPWM_Type const * base,uint32_t cntNum)637 __STATIC_INLINE uint32_t Cy_TCPWM_PWM_GetCompare0Val(TCPWM_Type const *base, uint32_t cntNum)
638 {
639     return Cy_TCPWM_Block_GetCC0Val(base, cntNum);
640 }
641 
642 
643 /*******************************************************************************
644 * Function Name: Cy_TCPWM_PWM_SetCompare0BufVal
645 ****************************************************************************//**
646 *
647 * Sets the buffered compare value for Compare 0 when the compare mode enabled.
648 *
649 * \param base
650 * The pointer to a TCPWM instance.
651 *
652 * \param cntNum
653 * The Counter instance number in the selected TCPWM.
654 *
655 * \param compareBuf0
656 * The buffered Compare 0 value.
657 *
658 * \funcusage
659 * \snippet tcpwm/pwm/snippet/main.c snippet_Cy_TCPWM_PWM_SetCompare0BufVal
660 *
661 *******************************************************************************/
Cy_TCPWM_PWM_SetCompare0BufVal(TCPWM_Type * base,uint32_t cntNum,uint32_t compareBuf0)662 __STATIC_INLINE void Cy_TCPWM_PWM_SetCompare0BufVal(TCPWM_Type *base, uint32_t cntNum,  uint32_t compareBuf0)
663 {
664     Cy_TCPWM_Block_SetCC0BufVal(base, cntNum, compareBuf0);
665 }
666 
667 
668 /*******************************************************************************
669 * Function Name: Cy_TCPWM_PWM_GetCompare0BufVal
670 ****************************************************************************//**
671 *
672 * Returns the buffered compare 0 value.
673 *
674 * \param base
675 * The pointer to a TCPWM instance.
676 *
677 * \param cntNum
678 * The Counter instance number in the selected TCPWM.
679 *
680 * \return
681 * Buffered compare 0 value.
682 *
683 * \funcusage
684 * \snippet tcpwm/pwm/snippet/main.c snippet_Cy_TCPWM_PWM_SetCompare0BufVal
685 *
686 *******************************************************************************/
Cy_TCPWM_PWM_GetCompare0BufVal(TCPWM_Type const * base,uint32_t cntNum)687 __STATIC_INLINE uint32_t Cy_TCPWM_PWM_GetCompare0BufVal(TCPWM_Type const *base, uint32_t cntNum)
688 {
689     return Cy_TCPWM_Block_GetCC0BufVal(base, cntNum);
690 }
691 
692 #if (CY_IP_MXTCPWM_VERSION >= 2U) || defined (CY_DOXYGEN)
693 /*******************************************************************************
694 * Function Name: Cy_TCPWM_PWM_SetCompare1Val
695 ****************************************************************************//**
696 *
697 * Sets the compare value for Compare 1 when the compare mode enabled.
698 *
699 * \param base
700 * The pointer to a TCPWM instance.
701 *
702 * \param cntNum
703 * The Counter instance number in the selected TCPWM.
704 *
705 * \param compare1
706 * The Compare1 value.
707 *
708 *******************************************************************************/
Cy_TCPWM_PWM_SetCompare1Val(TCPWM_Type * base,uint32_t cntNum,uint32_t compare1)709 __STATIC_INLINE void Cy_TCPWM_PWM_SetCompare1Val(TCPWM_Type *base, uint32_t cntNum,  uint32_t compare1)
710 {
711     Cy_TCPWM_Block_SetCC1Val(base, cntNum, compare1);
712 }
713 
714 
715 /*******************************************************************************
716 * Function Name: Cy_TCPWM_PWM_GetCompare1Val
717 ****************************************************************************//**
718 *
719 * Returns compare 1 value.
720 *
721 * \param base
722 * The pointer to a TCPWM instance.
723 *
724 * \param cntNum
725 * The Counter instance number in the selected TCPWM.
726 *
727 * \return
728 * Compare 1 value.
729 *
730 *******************************************************************************/
Cy_TCPWM_PWM_GetCompare1Val(TCPWM_Type const * base,uint32_t cntNum)731 __STATIC_INLINE uint32_t Cy_TCPWM_PWM_GetCompare1Val(TCPWM_Type const *base, uint32_t cntNum)
732 {
733     return Cy_TCPWM_Block_GetCC1Val(base, cntNum);
734 }
735 
736 
737 /*******************************************************************************
738 * Function Name: Cy_TCPWM_PWM_SetCompare1BufVal
739 ****************************************************************************//**
740 *
741 * Sets the buffered compare value for Compare1 when the compare mode enabled.
742 *
743 * \param base
744 * The pointer to a TCPWM instance.
745 *
746 * \param cntNum
747 * The Counter instance number in the selected TCPWM.
748 *
749 * \param compareBuf1
750 * The buffered Compare 1 value.
751 *
752 *
753 *******************************************************************************/
Cy_TCPWM_PWM_SetCompare1BufVal(TCPWM_Type * base,uint32_t cntNum,uint32_t compareBuf1)754 __STATIC_INLINE void Cy_TCPWM_PWM_SetCompare1BufVal(TCPWM_Type *base, uint32_t cntNum,  uint32_t compareBuf1)
755 {
756     Cy_TCPWM_Block_SetCC1BufVal(base, cntNum, compareBuf1);
757 }
758 
759 
760 /*******************************************************************************
761 * Function Name: Cy_TCPWM_PWM_GetCompare1BufVal
762 ****************************************************************************//**
763 *
764 * Returns the buffered compare 1 value.
765 *
766 * \param base
767 * The pointer to a TCPWM instance.
768 *
769 * \param cntNum
770 * The Counter instance number in the selected TCPWM.
771 *
772 * \return
773 * Buffered compare 1 value.
774 *
775 *******************************************************************************/
Cy_TCPWM_PWM_GetCompare1BufVal(TCPWM_Type const * base,uint32_t cntNum)776 __STATIC_INLINE uint32_t Cy_TCPWM_PWM_GetCompare1BufVal(TCPWM_Type const *base, uint32_t cntNum)
777 {
778     return Cy_TCPWM_Block_GetCC1BufVal(base, cntNum);
779 }
780 #endif
781 /*******************************************************************************
782 * Function Name: Cy_TCPWM_PWM_EnableCompare0Swap
783 ****************************************************************************//**
784 *
785 * Enables the comparison swap of compare 0 and compareBuf 0 on OV and/or UN,
786 * depending on the PWM alignment.
787 *
788 * \param base
789 * The pointer to a TCPWM instance.
790 *
791 * \param cntNum
792 * The Counter instance number in the selected TCPWM.
793 *
794 * \param enable
795 * true = swap enabled; false = swap disabled
796 *
797 * \funcusage
798 * \snippet tcpwm/pwm/snippet/main.c snippet_Cy_TCPWM_PWM_EnableCompare0Swap
799 *
800 * \note From Version 3 of TCPWM, this feature is coupled with the swap enable feature (Cy_TCPWM_PWM_EnableSwap()).
801 * when both reload and swap are enabled then CC0 value is swapped with CC0 buff value.
802 * When only reload is enabled then CC0 buff value is copied to CC0.
803 * There is no action when reload is disabled.
804 *
805 *******************************************************************************/
Cy_TCPWM_PWM_EnableCompare0Swap(TCPWM_Type * base,uint32_t cntNum,bool enable)806 __STATIC_INLINE void Cy_TCPWM_PWM_EnableCompare0Swap(TCPWM_Type *base, uint32_t cntNum,  bool enable)
807 {
808      Cy_TCPWM_Block_EnableCompare0Swap(base, cntNum, enable);
809 }
810 
811 #if (CY_IP_MXTCPWM_VERSION >= 2U) || defined (CY_DOXYGEN)
812 /*******************************************************************************
813 * Function Name: Cy_TCPWM_PWM_EnableCompare1Swap
814 ****************************************************************************//**
815 *
816 * Enables the comparison swap of compare1 and compareBuf1 on OV and/or UN,
817 * depending on the PWM alignment.
818 *
819 * \param base
820 * The pointer to a TCPWM instance.
821 *
822 * \param cntNum
823 * The Counter instance number in the selected TCPWM.
824 *
825 * \param enable
826 * true = swap enabled; false = swap disabled
827 *
828 * \note From Version 3 of TCPWM, this feature is coupled with the swap enable feature (Cy_TCPWM_PWM_EnableSwap()).
829 * when both reload and swap are enabled then CC1 value is swapped with CC1 buff value.
830 * When only reload is enabled then CC1 buff value is copied to CC1.
831 * There is no action when reload is disabled.
832 *
833 *******************************************************************************/
Cy_TCPWM_PWM_EnableCompare1Swap(TCPWM_Type * base,uint32_t cntNum,bool enable)834 __STATIC_INLINE void Cy_TCPWM_PWM_EnableCompare1Swap(TCPWM_Type *base, uint32_t cntNum,  bool enable)
835 {
836     Cy_TCPWM_Block_EnableCompare1Swap(base, cntNum, enable);
837 }
838 #endif
839 
840 /*******************************************************************************
841 * Function Name: Cy_TCPWM_PWM_SetCounter
842 ****************************************************************************//**
843 *
844 * Sets the value of the counter.
845 *
846 * \param base
847 * The pointer to a TCPWM instance.
848 *
849 * \param cntNum
850 * The Counter instance number in the selected TCPWM.
851 *
852 * \param count
853 * The value to write into the counter.
854 *
855 * \funcusage
856 * \snippet tcpwm/pwm/snippet/main.c snippet_Cy_TCPWM_PWM_SetCounter
857 *
858 *******************************************************************************/
Cy_TCPWM_PWM_SetCounter(TCPWM_Type * base,uint32_t cntNum,uint32_t count)859 __STATIC_INLINE void Cy_TCPWM_PWM_SetCounter(TCPWM_Type *base, uint32_t cntNum,  uint32_t count)
860 {
861     Cy_TCPWM_Block_SetCounter(base, cntNum, count);
862 }
863 
864 
865 /*******************************************************************************
866 * Function Name: Cy_TCPWM_PWM_GetCounter
867 ****************************************************************************//**
868 *
869 * Returns the value in the counter.
870 *
871 * \param base
872 * The pointer to a TCPWM instance.
873 *
874 * \param cntNum
875 * The Counter instance number in the selected TCPWM.
876 *
877 * \return
878 * The current counter value.
879 *
880 * \funcusage
881 * \snippet tcpwm/pwm/snippet/main.c snippet_Cy_TCPWM_PWM_GetCounter
882 *
883 *******************************************************************************/
Cy_TCPWM_PWM_GetCounter(TCPWM_Type const * base,uint32_t cntNum)884 __STATIC_INLINE uint32_t Cy_TCPWM_PWM_GetCounter(TCPWM_Type const *base, uint32_t cntNum)
885 {
886     return Cy_TCPWM_Block_GetCounter(base, cntNum);
887 }
888 
889 
890 /*******************************************************************************
891 * Function Name: Cy_TCPWM_PWM_SetPeriod0
892 ****************************************************************************//**
893 *
894 * Sets the value of the period register.
895 *
896 * \param base
897 * The pointer to a TCPWM instance.
898 *
899 * \param cntNum
900 * The Counter instance number in the selected TCPWM.
901 *
902 * \param period0
903 * The value to write into a period.
904 *
905 * \funcusage
906 * \snippet tcpwm/pwm/snippet/main.c snippet_Cy_TCPWM_PWM_SetPeriod0
907 *
908 *******************************************************************************/
Cy_TCPWM_PWM_SetPeriod0(TCPWM_Type * base,uint32_t cntNum,uint32_t period0)909 __STATIC_INLINE void Cy_TCPWM_PWM_SetPeriod0(TCPWM_Type *base, uint32_t cntNum,  uint32_t period0)
910 {
911     Cy_TCPWM_Block_SetPeriod(base, cntNum, period0);
912 }
913 
914 
915 /*******************************************************************************
916 * Function Name: Cy_TCPWM_PWM_GetPeriod0
917 ****************************************************************************//**
918 *
919 * Returns the value in the period register.
920 *
921 * \param base
922 * The pointer to a TCPWM instance.
923 *
924 * \param cntNum
925 * The Counter instance number in the selected TCPWM.
926 *
927 * \return
928 * The current period value.
929 *
930 * \funcusage
931 * \snippet tcpwm/pwm/snippet/main.c snippet_Cy_TCPWM_PWM_SetPeriod0
932 *
933 *******************************************************************************/
Cy_TCPWM_PWM_GetPeriod0(TCPWM_Type const * base,uint32_t cntNum)934 __STATIC_INLINE uint32_t Cy_TCPWM_PWM_GetPeriod0(TCPWM_Type const *base, uint32_t cntNum)
935 {
936     return Cy_TCPWM_Block_GetPeriod(base, cntNum);
937 }
938 
939 
940 /*******************************************************************************
941 * Function Name: Cy_TCPWM_PWM_SetPeriod1
942 ****************************************************************************//**
943 *
944 * Sets the value of the period register. In pseudo random mode period 1 sets
945 * which taps are enabled.
946 *
947 * \param base
948 * The pointer to a TCPWM instance.
949 *
950 * \param cntNum
951 * The Counter instance number in the selected TCPWM.
952 *
953 * \param period1
954 * The value to write into a period 1.
955 *
956 * \funcusage
957 * \snippet tcpwm/pwm/snippet/main.c snippet_Cy_TCPWM_PWM_SetPeriod1
958 *
959 *******************************************************************************/
Cy_TCPWM_PWM_SetPeriod1(TCPWM_Type * base,uint32_t cntNum,uint32_t period1)960 __STATIC_INLINE void Cy_TCPWM_PWM_SetPeriod1(TCPWM_Type *base, uint32_t cntNum,  uint32_t period1)
961 {
962 #if (CY_IP_MXTCPWM_VERSION == 1U)
963 
964         TCPWM_CNT_PERIOD_BUFF(base, cntNum) = period1;
965 #else
966         TCPWM_GRP_CNT_PERIOD_BUFF(base, TCPWM_GRP_CNT_GET_GRP(cntNum), cntNum) = period1;
967 #endif
968 }
969 
970 
971 /*******************************************************************************
972 * Function Name: Cy_TCPWM_PWM_GetPeriod1
973 ****************************************************************************//**
974 *
975 * Returns the value in the period register.
976 *
977 * \param base
978 * The pointer to a COUNTER PWM instance.
979 *
980 * \param cntNum
981 * The Counter instance number in the selected TCPWM.
982 *
983 * \return
984 * The current period value.
985 *
986 * \funcusage
987 * \snippet tcpwm/pwm/snippet/main.c snippet_Cy_TCPWM_PWM_SetPeriod1
988 *
989 *******************************************************************************/
Cy_TCPWM_PWM_GetPeriod1(TCPWM_Type const * base,uint32_t cntNum)990 __STATIC_INLINE uint32_t Cy_TCPWM_PWM_GetPeriod1(TCPWM_Type const *base, uint32_t cntNum)
991 {
992     uint32_t result;
993 
994 #if (CY_IP_MXTCPWM_VERSION == 1U)
995 
996         result = TCPWM_CNT_PERIOD_BUFF(base, cntNum);
997 #else
998         result = TCPWM_GRP_CNT_PERIOD_BUFF(base, TCPWM_GRP_CNT_GET_GRP(cntNum), cntNum);
999 #endif
1000 
1001     return result;
1002 }
1003 
1004 
1005 /*******************************************************************************
1006 * Function Name: Cy_TCPWM_PWM_EnablePeriodSwap
1007 ****************************************************************************//**
1008 *
1009 * Enables a period swap on OV and/or UN, depending on the PWM alignment
1010 *
1011 * \param base
1012 * The pointer to a TCPWM instance.
1013 *
1014 * \param cntNum
1015 * The Counter instance number in the selected TCPWM.
1016 *
1017 * \param enable
1018 * true = swap enabled; false = swap disabled
1019 *
1020 * \funcusage
1021 * \snippet tcpwm/pwm/snippet/main.c snippet_Cy_TCPWM_PWM_EnablePeriodSwap
1022 *
1023 * \note From Version 3 of TCPWM, this feature is coupled with the swap enable feature (Cy_TCPWM_PWM_EnableSwap()).
1024 * when both reload and swap are enabled then period value is swapped with period buff value.
1025 * When only reload is enabled then period buff value is copied to period.
1026 * There is no action when reload is disabled.
1027 *
1028 *******************************************************************************/
Cy_TCPWM_PWM_EnablePeriodSwap(TCPWM_Type * base,uint32_t cntNum,bool enable)1029 __STATIC_INLINE void Cy_TCPWM_PWM_EnablePeriodSwap(TCPWM_Type *base, uint32_t cntNum,  bool enable)
1030 {
1031 #if (CY_IP_MXTCPWM_VERSION == 1U)
1032 
1033         if (enable)
1034         {
1035             TCPWM_CNT_CTRL(base, cntNum) |=  TCPWM_CNT_CTRL_AUTO_RELOAD_PERIOD_Msk;
1036         }
1037         else
1038         {
1039             TCPWM_CNT_CTRL(base, cntNum) &= ~TCPWM_CNT_CTRL_AUTO_RELOAD_PERIOD_Msk;
1040         }
1041 #else
1042         if (enable)
1043         {
1044             TCPWM_GRP_CNT_CTRL(base, TCPWM_GRP_CNT_GET_GRP(cntNum), cntNum) |=
1045                                      TCPWM_GRP_CNT_V2_CTRL_AUTO_RELOAD_PERIOD_Msk;
1046         }
1047         else
1048         {
1049             TCPWM_GRP_CNT_CTRL(base, TCPWM_GRP_CNT_GET_GRP(cntNum), cntNum) &=
1050                                     ~TCPWM_GRP_CNT_V2_CTRL_AUTO_RELOAD_PERIOD_Msk;
1051         }
1052 #endif
1053 }
1054 
1055 #if (CY_IP_MXTCPWM_VERSION >= 2U) || defined (CY_DOXYGEN)
1056 /*******************************************************************************
1057 * Function Name: Cy_TCPWM_PWM_GetDtCounter
1058 ****************************************************************************//**
1059 *
1060 * Returns the dead time count when the PWM is configured in dead time mode
1061 *
1062 * \param base
1063 * The pointer to a TCPWM instance.
1064 *
1065 * \param cntNum
1066 * The Counter instance number in the selected TCPWM.
1067 *
1068 * \return
1069 * The dead time counter.
1070 *
1071 * \funcusage
1072 * \snippet tcpwm/pwm/snippet/main.c snippet_Cy_TCPWM_PWM_GetDtCounter
1073 *
1074 * \note supported only in TCPWM_ver2
1075 *
1076 *******************************************************************************/
Cy_TCPWM_PWM_GetDtCounter(TCPWM_Type const * base,uint32_t cntNum)1077 __STATIC_INLINE uint32_t Cy_TCPWM_PWM_GetDtCounter (TCPWM_Type const *base, uint32_t cntNum)
1078 {
1079     uint32_t result = 0UL;
1080 
1081     result = TCPWM_GRP_CNT_STATUS(base, TCPWM_GRP_CNT_GET_GRP(cntNum), cntNum);
1082     result = (result & (TCPWM_GRP_CNT_V2_STATUS_DT_CNT_L_Msk | TCPWM_GRP_CNT_V2_STATUS_DT_CNT_H_Msk)) >> TCPWM_GRP_CNT_V2_STATUS_DT_CNT_L_Pos;
1083 
1084     return result;
1085 }
1086 
1087 /*******************************************************************************
1088 * Function Name: Cy_TCPWM_PWM_LineOutStatus
1089 ****************************************************************************//**
1090 *
1091 * Returns the current level of the selected pwm output line.
1092 *
1093 * \param base
1094 * The pointer to a TCPWM instance.
1095 *
1096 * \param cntNum
1097 * The Counter instance number in the selected TCPWM.
1098 *
1099 * \param pwmOutSelect
1100 * Defines which pwm output line is being checked pwm or pwm_n.
1101 *
1102 * \return
1103 * The current pwm output line level.
1104 *
1105 * \funcusage
1106 * \snippet tcpwm/pwm/snippet/main.c snippet_Cy_TCPWM_PWM_LineOutStatus
1107 *
1108 * \note supported only in TCPWM_ver2
1109 *
1110 *******************************************************************************/
Cy_TCPWM_PWM_LineOutStatus(TCPWM_Type const * base,uint32_t cntNum,uint32_t pwmOutSelect)1111 __STATIC_INLINE uint32_t Cy_TCPWM_PWM_LineOutStatus (TCPWM_Type const *base, uint32_t cntNum, uint32_t pwmOutSelect)
1112 {
1113     uint32_t status = 0UL;
1114 
1115 
1116     status = TCPWM_GRP_CNT_STATUS(base, TCPWM_GRP_CNT_GET_GRP(cntNum), cntNum);
1117 
1118      switch(pwmOutSelect)
1119      {
1120          case CY_TCPWM_PWM_LINE_PWM:
1121              status = _FLD2VAL(TCPWM_GRP_CNT_V2_STATUS_LINE_OUT, status);
1122              break;
1123          case CY_TCPWM_PWM_LINE_PWM_INV:
1124              status = _FLD2VAL(TCPWM_GRP_CNT_V2_STATUS_LINE_COMPL_OUT, status);
1125              break;
1126          default:
1127              /* Not a Valid Line output */
1128              CY_ASSERT_L3(false);
1129              break;
1130     }
1131 
1132     return status;
1133 }
1134 #endif
1135 
1136 /*******************************************************************************
1137 * Function Name: Cy_TCPWM_PWM_PWMDeadTime
1138 ****************************************************************************//**
1139 *
1140 * Writes the dead time value for PWM. This is the number of clock cycles of dead time to activate Line Out
1141 *
1142 * \param base
1143 * The pointer to a TCPWM instance.
1144 *
1145 * \param cntNum
1146 * The Counter instance number in the selected TCPWM.
1147 *
1148 * \param deadTime
1149 * The dead time value.
1150 *
1151 * \funcusage
1152 * \snippet tcpwm/pwm/snippet/main.c snippet_Cy_TCPWM_PWM_PWMDeadTime
1153 *
1154 *******************************************************************************/
Cy_TCPWM_PWM_PWMDeadTime(TCPWM_Type const * base,uint32_t cntNum,uint32_t deadTime)1155 __STATIC_INLINE void Cy_TCPWM_PWM_PWMDeadTime (TCPWM_Type const *base, uint32_t cntNum, uint32_t deadTime)
1156 {
1157     uint32_t result;
1158 
1159 #if (CY_IP_MXTCPWM_VERSION == 1U)
1160 
1161         result = TCPWM_CNT_CTRL(base, cntNum);
1162         result &= ~(TCPWM_CNT_CTRL_GENERIC_Msk);
1163 
1164         TCPWM_CNT_CTRL(base, cntNum) = result | _VAL2FLD(TCPWM_CNT_CTRL_GENERIC, deadTime);
1165 #else
1166         uint32_t grp = TCPWM_GRP_CNT_GET_GRP(cntNum);
1167 
1168         result = TCPWM_GRP_CNT_DT(base, grp, cntNum);
1169         result &= ~(TCPWM_GRP_CNT_V2_DT_DT_LINE_OUT_L_Msk | TCPWM_GRP_CNT_V2_DT_DT_LINE_OUT_H_Msk);
1170 
1171         TCPWM_GRP_CNT_DT(base, grp, cntNum) = result |
1172                     _VAL2FLD(TCPWM_GRP_CNT_V2_DT_DT_LINE_OUT_L, (uint8_t)(deadTime)) |
1173                     _VAL2FLD(TCPWM_GRP_CNT_V2_DT_DT_LINE_OUT_H, (uint8_t)(deadTime >> 8U));
1174 #endif
1175 
1176 }
1177 
1178 #if (CY_IP_MXTCPWM_VERSION >= 2U) || defined (CY_DOXYGEN)
1179 /*******************************************************************************
1180 * Function Name: Cy_TCPWM_PWM_PWMDeadTimeN
1181 ****************************************************************************//**
1182 *
1183 * Writes the dead time value for PWM. This is the number of clock cycles of dead time to activate Line Compliment Out
1184 *
1185 * \param base
1186 * The pointer to a TCPWM instance.
1187 *
1188 * \param cntNum
1189 * The Counter instance number in the selected TCPWM.
1190 *
1191 * \param deadTime
1192 * The dead time value.
1193 *
1194 * \funcusage
1195 * \snippet tcpwm/pwm/snippet/main.c snippet_Cy_TCPWM_PWM_PWMDeadTime
1196 *
1197 *******************************************************************************/
Cy_TCPWM_PWM_PWMDeadTimeN(TCPWM_Type const * base,uint32_t cntNum,uint32_t deadTime)1198 __STATIC_INLINE void Cy_TCPWM_PWM_PWMDeadTimeN (TCPWM_Type const *base, uint32_t cntNum, uint32_t deadTime)
1199 {
1200     uint32_t result;
1201     uint32_t grp = TCPWM_GRP_CNT_GET_GRP(cntNum);
1202 
1203     result = TCPWM_GRP_CNT_DT(base, grp, cntNum);
1204     result &= ~(TCPWM_GRP_CNT_V2_DT_DT_LINE_COMPL_OUT_Msk);
1205 
1206     TCPWM_GRP_CNT_DT(base, grp, cntNum) = result |
1207             _VAL2FLD(TCPWM_GRP_CNT_V2_DT_DT_LINE_COMPL_OUT, (uint16_t)(deadTime));
1208 
1209 }
1210 
1211 /*******************************************************************************
1212 * Function Name: Cy_TCPWM_PWM_SetDT
1213 ****************************************************************************//**
1214 *
1215 * Writes the dead time value for PWM. This is the number of clock cycles of dead time to activate Line Out and  Line Compliment Out
1216 *
1217 * \param base
1218 * The pointer to a TCPWM instance.
1219 *
1220 * \param cntNum
1221 * The Counter instance number in the selected TCPWM.
1222 *
1223 * \param deadTime
1224 * The dead time value for both Line Out and Line Compliment Out.
1225 *
1226 * \note 32 bit value with 0-15 bits to set Line out Dead Time value and 16-31 bits to set Line Compliment Out Deat Time Value.
1227 *******************************************************************************/
Cy_TCPWM_PWM_SetDT(TCPWM_Type const * base,uint32_t cntNum,uint32_t deadTime)1228 __STATIC_INLINE void Cy_TCPWM_PWM_SetDT (TCPWM_Type const *base, uint32_t cntNum, uint32_t deadTime)
1229 {
1230     uint32_t grp = TCPWM_GRP_CNT_GET_GRP(cntNum);
1231     TCPWM_GRP_CNT_DT(base, grp, cntNum) = deadTime;
1232 }
1233 
1234 /*******************************************************************************
1235 * Function Name: Cy_TCPWM_PWM_Configure_LineSelect
1236 ****************************************************************************//**
1237 *
1238 * Configures the source for the output signal "line_out"  and "line_compl_out"
1239 *
1240 * \param base
1241 * The pointer to a TCPWM instance.
1242 *
1243 * \param cntNum
1244 * The Counter instance number in the selected TCPWM.
1245 *
1246 * \param line_out_val
1247 * Source for the lie out signal \ref cy_en_line_select_config_t
1248 *
1249 * \param line_compl_value
1250 * Source for the lie compl out signal \ref cy_en_line_select_config_t
1251 *
1252 *******************************************************************************/
Cy_TCPWM_PWM_Configure_LineSelect(TCPWM_Type * base,uint32_t cntNum,cy_en_line_select_config_t line_out_val,cy_en_line_select_config_t line_compl_value)1253 __STATIC_INLINE void Cy_TCPWM_PWM_Configure_LineSelect(TCPWM_Type *base, uint32_t cntNum,  cy_en_line_select_config_t line_out_val, cy_en_line_select_config_t line_compl_value)
1254 {
1255     uint32_t grp = TCPWM_GRP_CNT_GET_GRP(cntNum);
1256     TCPWM_GRP_CNT_LINE_SEL(base, grp, cntNum) = (_VAL2FLD(TCPWM_GRP_CNT_V2_LINE_SEL_OUT_SEL, line_out_val) |
1257                                                  _VAL2FLD(TCPWM_GRP_CNT_V2_LINE_SEL_COMPL_OUT_SEL, line_compl_value));
1258 }
1259 
1260 /*******************************************************************************
1261 * Function Name: Cy_TCPWM_PWM_Configure_LineSelectBuff
1262 ****************************************************************************//**
1263 *
1264 * Buffer for LINE SELCT. Can be exchanged with Line Select values on a terminal count event with an actively pending switch event.
1265 *
1266 * \param base
1267 * The pointer to a TCPWM instance.
1268 *
1269 * \param cntNum
1270 * The Counter instance number in the selected TCPWM.
1271 *
1272 * \param line_out_val
1273 * Source for the lie out signal \ref cy_en_line_select_config_t
1274 *
1275 * \param line_compl_value
1276 * Source for the lie compl out signal \ref cy_en_line_select_config_t
1277 *
1278 *******************************************************************************/
Cy_TCPWM_PWM_Configure_LineSelectBuff(TCPWM_Type * base,uint32_t cntNum,cy_en_line_select_config_t line_out_val,cy_en_line_select_config_t line_compl_value)1279 __STATIC_INLINE void Cy_TCPWM_PWM_Configure_LineSelectBuff(TCPWM_Type *base, uint32_t cntNum,  cy_en_line_select_config_t line_out_val, cy_en_line_select_config_t line_compl_value)
1280 {
1281     uint32_t grp = TCPWM_GRP_CNT_GET_GRP(cntNum);
1282     TCPWM_GRP_CNT_LINE_SEL_BUFF(base, grp, cntNum) = (_VAL2FLD(TCPWM_GRP_CNT_V2_LINE_SEL_BUFF_OUT_SEL, line_out_val) |
1283                                                  _VAL2FLD(TCPWM_GRP_CNT_V2_LINE_SEL_BUFF_COMPL_OUT_SEL, line_compl_value));
1284 }
1285 
1286 /*******************************************************************************
1287 * Function Name: Cy_TCPWM_PWM_EnableLineSelectSwap
1288 ****************************************************************************//**
1289 *
1290 * Enables a Line Select swap on OV and/or UN, depending on the PWM alignment
1291 *
1292 * \param base
1293 * The pointer to a TCPWM instance.
1294 *
1295 * \param cntNum
1296 * The Counter instance number in the selected TCPWM.
1297 *
1298 * \param enable
1299 * true = swap enabled; false = swap disabled
1300 *
1301 * \note From Version 3 of TCPWM, this feature is coupled with the swap enable feature (Cy_TCPWM_PWM_EnableSwap()).
1302 * when both reload and swap are enabled then line select value is swapped with line select buff value.
1303 * When only reload is enabled then line select buff value is copied to line select.
1304 * There is no action when reload is disabled.
1305 *******************************************************************************/
Cy_TCPWM_PWM_EnableLineSelectSwap(TCPWM_Type * base,uint32_t cntNum,bool enable)1306 __STATIC_INLINE void Cy_TCPWM_PWM_EnableLineSelectSwap(TCPWM_Type *base, uint32_t cntNum,  bool enable)
1307 {
1308     if (enable)
1309     {
1310         TCPWM_GRP_CNT_CTRL(base, TCPWM_GRP_CNT_GET_GRP(cntNum), cntNum) |=
1311                                  TCPWM_GRP_CNT_V2_CTRL_AUTO_RELOAD_LINE_SEL_Msk;
1312     }
1313     else
1314     {
1315         TCPWM_GRP_CNT_CTRL(base, TCPWM_GRP_CNT_GET_GRP(cntNum), cntNum) &=
1316                                 ~TCPWM_GRP_CNT_V2_CTRL_AUTO_RELOAD_LINE_SEL_Msk;
1317     }
1318 }
1319 #endif
1320 
1321 #if defined (CY_IP_MXS40TCPWM) || defined (CY_DOXYGEN)
1322 /*******************************************************************************
1323 * Function Name: Cy_TCPWM_PWM_EnableSwap
1324 ****************************************************************************//**
1325 *
1326 * Enables/disables swapping mechanism between CC0 and buffered CC0, CC1 and buffered CC1, PERIOD and buffered PERIOD, DT and buffered DT.
1327 *
1328 * \param base
1329 * The pointer to a TCPWM instance.
1330 *
1331 * \param cntNum
1332 * The Counter instance number in the selected TCPWM.
1333 *
1334 * \param enable
1335 * true = swap enabled; false = swap disabled
1336 *
1337 * \note This feature is coupled with the reload feature.
1338 * 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
1339 * When only reload is enabled then CC_BUFF/CC1_BUFF/PERIOD_BUFF/DT_BUFF values are copied to CC0/CC1/PERIOD/DT respectively.
1340 * There is no action when reload is disabled.
1341 *
1342 *******************************************************************************/
Cy_TCPWM_PWM_EnableSwap(TCPWM_Type * base,uint32_t cntNum,bool enable)1343 __STATIC_INLINE void Cy_TCPWM_PWM_EnableSwap(TCPWM_Type *base, uint32_t cntNum,  bool enable)
1344 {
1345     Cy_TCPWM_Block_EnableSwap(base, cntNum, enable);
1346 }
1347 
1348 /*******************************************************************************
1349 * Function Name: Cy_TCPWM_PWM_Set_KillLinePolarity
1350 ****************************************************************************//**
1351 *
1352 * Configures the source for the output signal "line_out"  and "line_compl_out"
1353 *
1354 * \param base
1355 * The pointer to a TCPWM instance.
1356 *
1357 * \param cntNum
1358 * The Counter instance number in the selected TCPWM.
1359 *
1360 * \param kill_line_polarity
1361 * Kill Line polarity value \ref cy_en_kill_line_polarity_t
1362 *
1363 *
1364 *******************************************************************************/
Cy_TCPWM_PWM_Set_KillLinePolarity(TCPWM_Type * base,uint32_t cntNum,cy_en_kill_line_polarity_t kill_line_polarity)1365 __STATIC_INLINE void Cy_TCPWM_PWM_Set_KillLinePolarity(TCPWM_Type *base, uint32_t cntNum,  cy_en_kill_line_polarity_t kill_line_polarity)
1366 {
1367     uint32_t grp = TCPWM_GRP_CNT_GET_GRP(cntNum);
1368 
1369     TCPWM_GRP_CNT_CTRL(base, grp, cntNum) &= ~TCPWM_GRP_CNT_CTRL_KILL_LINE_POLARITY_Msk;
1370     TCPWM_GRP_CNT_CTRL(base, grp, cntNum) |= (_VAL2FLD(TCPWM_GRP_CNT_CTRL_KILL_LINE_POLARITY, kill_line_polarity));
1371 }
1372 
1373 /*******************************************************************************
1374 * Function Name: Cy_TCPWM_PWM_PWMDeadTimeBuff
1375 ****************************************************************************//**
1376 *
1377 * Writes the dead time buffered value for PWM. This is the number of clock cycles of dead time to activate Line Out
1378 * Data from DT_BUFF will be shallow transferred to DT (when swap enable is disabled) on a terminal count event with an actively pending switch event.
1379 *
1380 * \param base
1381 * The pointer to a TCPWM instance.
1382 *
1383 * \param cntNum
1384 * The Counter instance number in the selected TCPWM.
1385 *
1386 * \param deadTime
1387 * The dead time value.
1388 *
1389 * \funcusage
1390 * \snippet tcpwm/pwm/snippet/main.c snippet_Cy_TCPWM_PWM_PWMDeadTime
1391 *
1392 *******************************************************************************/
Cy_TCPWM_PWM_PWMDeadTimeBuff(TCPWM_Type const * base,uint32_t cntNum,uint32_t deadTime)1393 __STATIC_INLINE void Cy_TCPWM_PWM_PWMDeadTimeBuff (TCPWM_Type const *base, uint32_t cntNum, uint32_t deadTime)
1394 {
1395     uint32_t grp = TCPWM_GRP_CNT_GET_GRP(cntNum);
1396     uint32_t result = TCPWM_GRP_CNT_DT_BUFF(base, grp, cntNum);
1397     result &= ~(TCPWM_GRP_CNT_DT_BUFF_DT_LINE_OUT_L_Msk | TCPWM_GRP_CNT_DT_BUFF_DT_LINE_OUT_H_Msk);
1398 
1399     TCPWM_GRP_CNT_DT_BUFF(base, grp, cntNum) = result |
1400                         (_VAL2FLD(TCPWM_GRP_CNT_DT_BUFF_DT_LINE_OUT_L, (uint8_t)(deadTime)) |
1401                         _VAL2FLD(TCPWM_GRP_CNT_DT_BUFF_DT_LINE_OUT_H, (uint8_t)(deadTime >> 8)));
1402 
1403 }
1404 
1405 /*******************************************************************************
1406 * Function Name: Cy_TCPWM_PWM_PWMDeadTimeBuffN
1407 ****************************************************************************//**
1408 *
1409 * Writes the dead time buffered value for PWM. This is the number of clock cycles of dead time to activate Line Compliment Out
1410 * Data from DT_BUFF will be shallow transferred to DT (when swap enable is disabled) on a terminal count event with an actively pending switch event.
1411 *
1412 * \param base
1413 * The pointer to a TCPWM instance.
1414 *
1415 * \param cntNum
1416 * The Counter instance number in the selected TCPWM.
1417 *
1418 * \param deadTime
1419 * The dead time value.
1420 *
1421 * \funcusage
1422 * \snippet tcpwm/pwm/snippet/main.c snippet_Cy_TCPWM_PWM_PWMDeadTime
1423 *
1424 *******************************************************************************/
Cy_TCPWM_PWM_PWMDeadTimeBuffN(TCPWM_Type const * base,uint32_t cntNum,uint32_t deadTime)1425 __STATIC_INLINE void Cy_TCPWM_PWM_PWMDeadTimeBuffN (TCPWM_Type const *base, uint32_t cntNum, uint32_t deadTime)
1426 {
1427     uint32_t result;
1428     uint32_t grp = TCPWM_GRP_CNT_GET_GRP(cntNum);
1429 
1430     result = TCPWM_GRP_CNT_DT_BUFF(base, grp, cntNum);
1431     result &= ~(TCPWM_GRP_CNT_V2_DT_DT_LINE_COMPL_OUT_Msk);
1432 
1433     TCPWM_GRP_CNT_DT_BUFF(base, grp, cntNum) = result |
1434             _VAL2FLD(TCPWM_GRP_CNT_V2_DT_DT_LINE_COMPL_OUT, (uint16_t)(deadTime));
1435 
1436 }
1437 
1438 
1439 /*******************************************************************************
1440 * Function Name: Cy_TCPWM_PWM_SetDTBuff
1441 ****************************************************************************//**
1442 *
1443 * Writes the dead time buffered value for PWM. This is the number of clock cycles of dead time to activate Line Out and  Line Compliment Out
1444 * Data from DT_BUFF will be shallow transferred to DT (when swap enable is disabled) on a terminal count event with an actively pending switch event.
1445 *
1446 * \param base
1447 * The pointer to a TCPWM instance.
1448 *
1449 * \param cntNum
1450 * The Counter instance number in the selected TCPWM.
1451 *
1452 * \param deadTime
1453 * The dead time value for both Line Out and Line Compliment Out.
1454 *
1455 * \note 32 bit value with 0-15 bits to set Line out Dead Time value and 16-31 bits to set Line Compliment Out Deat Time Value.
1456 *******************************************************************************/
Cy_TCPWM_PWM_SetDTBuff(TCPWM_Type const * base,uint32_t cntNum,uint32_t deadTime)1457 __STATIC_INLINE void Cy_TCPWM_PWM_SetDTBuff (TCPWM_Type const *base, uint32_t cntNum, uint32_t deadTime)
1458 {
1459     uint32_t grp = TCPWM_GRP_CNT_GET_GRP(cntNum);
1460     TCPWM_GRP_CNT_DT_BUFF(base, grp, cntNum) = deadTime;
1461 }
1462 
1463 #endif /* defined (CY_IP_MXS40TCPWM) */
1464 
1465 /** \} group_tcpwm_functions_pwm */
1466 
1467 /** \} group_tcpwm_pwm */
1468 
1469 #if defined(__cplusplus)
1470 }
1471 #endif
1472 
1473 #endif /* CY_IP_MXTCPWM */
1474 
1475 #endif /* CY_TCPWM_PWM_H */
1476 
1477 /* [] END OF FILE */
1478