iLLD_TC27xC  1.0
IfxCcu6_TPwm.h
Go to the documentation of this file.
1 /**
2  * \file IfxCcu6_TPwm.h
3  * \brief CCU6 TPWM details
4  * \ingroup IfxLld_Ccu6
5  *
6  * \version iLLD_0_1_0_10
7  * \copyright Copyright (c) 2013 Infineon Technologies AG. All rights reserved.
8  *
9  *
10  * IMPORTANT NOTICE
11  *
12  *
13  * Infineon Technologies AG (Infineon) is supplying this file for use
14  * exclusively with Infineon's microcontroller products. This file can be freely
15  * distributed within development tools that are supporting such microcontroller
16  * products.
17  *
18  * THIS SOFTWARE IS PROVIDED "AS IS". NO WARRANTIES, WHETHER EXPRESS, IMPLIED
19  * OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF
20  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE.
21  * INFINEON SHALL NOT, IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL,
22  * OR CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER.
23  *
24  *
25  * \defgroup IfxLld_Ccu6_TPwm_Usage How to use the CCU6 TPWM Interface driver?
26  * \ingroup IfxLld_Ccu6
27  *
28  * The TPWM interface driver provides a default CCU6 configuration for PWM modulation output through the selected timer block.
29  *
30  * User can select the various configuration options that hardware allows
31  *
32  * In the following sections it will be described, how to integrate the driver into the application framework.
33  *
34  *
35  * \section IfxLld_Ccu6_TPwm_Preparation Preparation
36  *
37  *
38  * \subsection IfxLld_Ccu6_TPwm_Include Include Files
39  *
40  * Include following header file into your C code:
41  * \code
42  * #include <Ccu6/TPwm/IfxCcu6_TPwm.h>
43  * \endcode
44  *
45  * \subsection IfxLld_Ccu6_TPwm_Variables Variables
46  *
47  * Declare the TPWM handle as global variable in your C code:
48  *
49  * \code
50  * // used globally
51  * static IfxCcu6_TPwm tPwm;
52  * \endcode
53  *
54  * \subsection IfxLld_Ccu6_TPwm_Interrupt Interrupt Handler Installation
55  *
56  * See also \ref IfxLld_Cpu_Irq_Usage
57  *
58  * Define priority for the Interrrupt handler. This is normally done in the Ifx_IntPrioDef.h file:
59  * \code
60  * // priorities are normally defined in Ifx_IntPrioDef.h
61  * #define IFX_INTPRIO_CCU6 1
62  * \endcode
63  *
64  * Add the interrupt service routine to your C code.
65  * \code
66  * IFX_INTERRUPT(ccu60ISR_TPwm, 0, IFX_INTPRIO_CCU6)
67  * {
68  * //user code
69  * }
70  * \endcode
71  *
72  * Finally install the interrupt handlers in your initialisation function:
73  * \code
74  * // install interrupt handlers
75  * IfxCpu_Irq_installInterruptHandler(&ccu60ISR_TPwm, IFX_INTPRIO_CCU6);
76  * IfxCpu_enableInterrupts();
77  * \endcode
78  *
79  * \subsection IfxLld_Ccu6_TPwm_Init Module Initialisation
80  *
81  * The module initialisation can be done in the same function. Here an example:
82  * \code
83  * // create configuration
84  * IfxCcu6_TPwm_Config tPwmConfig;
85  * IfxCcu6_TPwm_initModuleConfig(&tPwmConfig, &MODULE_CCU60);
86  *
87  * // configure the frequency of the timer in case of internal start
88  * // this frequency will be set for the timer block selected later
89  * tPwmConfig.base.frequency = 400000;
90  *
91  * // configure the period of the timer
92  * tPwmConfig.base.period = 100;
93  *
94  * // configure the waiting time in case of delayed T13 start in sync with T12
95  * tPwmConfig.base.waitingTime = 20;
96  *
97  * // select the active state of the output
98  * tPwmConfig.base.activeState = Ifx_ActiveState_high;
99  *
100  * // select the timer through which PWM is to be generated
101  * tPwmConfig.timer = IfxCcu6_TimerId_t13;
102  *
103  * // configure the clock for internal mode
104  * tPwmConfig.clock.t13ExtClockEnabled = FALSE;
105  * tPwmConfig.clock.t13ExtClockInput = NULL_PTR;
106  * tPwmConfig.clock.t13countingInputMode = IfxCcu6_CountingInputMode_internal;
107  *
108  * // configure the selcted timer block
109  * tPwmConfig.timer13.counterValue = 0;
110  * tPwmConfig.timer13.compareValue = 100;
111  * // configure the syncronisation, in case of sync start with T12
112  * tPwmConfig.timer13.t12SyncEvent = IfxCcu6_T13TriggerEvent_onCC60RCompare;
113  * tPwmConfig.timer13.t12SyncDirection = IfxCcu6_T13TriggerDirection_onT12CountingUp;
114  *
115  * //select the channel out for modulation
116  * tPwmConfig.channelOut = IfxCcu6_ChannelOut_cout3;
117  *
118  * // pin configuration
119  * const IfxCcu6_TPwm_Pins pins = {
120  * NULL, // CC60Out pin not used
121  * NULL, // CC61Out pin not used
122  * NULL, // CC62Out pin not used
123  * NULL, // COUT60 pin not used
124  * NULL, // COUT61 pin not used
125  * NULL, // COUT62 pin not used
126  * IfxCcu60_COUT63_P00_0_OUT, // COUT63 pin
127  * IfxPort_OutputMode_pushPull,
128  * IfxPort_PadDriver_cmosAutomotiveSpeed1
129  * };
130  * tPwmConfig.pins = &pins;
131  *
132  * // configure the interrupts
133  * tPwmConfig.interrupt.interruptSource = IfxCcu6_InterruptSource_t13CompareMatch;
134  * tPwmConfig.interrupt.serviceRequest = IfxCcu6_ServiceRequest_sR2;
135  * tPwmConfig.interrupt.priority = IFX_INTPRIO_CCU6;
136  * tPwmConfig.interrupt.typeOfService = IfxSrc_Tos_cpu0;
137  *
138  * // configure input and output triggers
139  * tPwmConfig.trigger.t12ExtInputTrigger = IfxCcu60_T12HRB_P00_7_IN;
140  * tPwmConfig.trigger.t13ExtInputTrigger = NULL_PTR;
141  * tPwmConfig.trigger.extInputTriggerMode = IfxCcu6_ExternalTriggerMode_risingEdge;
142  * tPwmConfig.trigger.t13InSyncWithT12 = TRUE;
143  *
144  * tPwmConfig.trigger.outputTriggerEnabled = TRUE;
145  * tPwmConfig.trigger.outputLine = IfxCcu6_TrigOut_0;
146  * tPwmConfig.trigger.outputTrigger = IfxCcu6_TrigSel_cout63;
147  *
148  *
149  * // initialize the module
150  * IfxCcu6_TPwm_initModule(&tPwm, &tPwmConfig);
151  * \endcode
152  *
153  *
154  * The TPWM is ready for use now!
155  *
156  *
157  * \section IfxLld_Ccu6_TPwm_ModulationControl Modulation Control
158  *
159  *
160  * The TPWM driver provides simple to use Modulation Control functions
161  *
162  * This means: you can start, stop, pause and resume the modulation once the module is initialised with the appropriate configuration
163  *
164  * Start the modulation
165  * \code
166  * IfxCcu6_TPwm_start(&tPwm);
167  * \endcode
168  *
169  * Stop the modulation
170  * \code
171  * IfxCcu6_TPwm_stop(&tPwm);
172  * \endcode
173  *
174  * Pause the modulation
175  * \code
176  * IfxCcu6_TPwm_pause(&tPwm);
177  * \endcode
178  *
179  * Resume the modulation
180  * \code
181  * IfxCcu6_TPwm_resume(&tPwm);
182  * \endcode
183  *
184  * \defgroup IfxLld_Ccu6_TPwm TPwm
185  * \ingroup IfxLld_Ccu6
186  * \defgroup IfxLld_Ccu6_TPwm_DataStructures Data Structures
187  * \ingroup IfxLld_Ccu6_TPwm
188  * \defgroup IfxLld_Ccu6_TPwm_Module_Initialize_Functions Module Initialize Functions
189  * \ingroup IfxLld_Ccu6_TPwm
190  * \defgroup IfxLld_Ccu6_TPwm_Modultion_Control_Functions Modultion Control Functions
191  * \ingroup IfxLld_Ccu6_TPwm
192  */
193 
194 #ifndef IFXCCU6_TPWM_H
195 #define IFXCCU6_TPWM_H 1
196 
197 /******************************************************************************/
198 /*----------------------------------Includes----------------------------------*/
199 /******************************************************************************/
200 
201 #include "Ccu6/Std/IfxCcu6.h"
202 #include "If/Ccu6If/TPwm.h"
203 
204 /******************************************************************************/
205 /*-----------------------------Data Structures--------------------------------*/
206 /******************************************************************************/
207 
208 /** \addtogroup IfxLld_Ccu6_TPwm_DataStructures
209  * \{ */
210 /** \brief Structure for clock configuration
211  */
212 typedef struct
213 {
214  boolean t12ExtClockEnabled; /**< \brief Timer 12 external clock enable / disable selection */
215  IfxCcu6_T12hr_In *t12ExtClockInput; /**< \brief External input signal selection for timer 12 */
216  IfxCcu6_CountingInputMode t12countingInputMode; /**< \brief Input event leading to a counting action of the timer T12 */
217  boolean t13ExtClockEnabled; /**< \brief Timer 13 external clock enable / disable selection */
218  IfxCcu6_T13hr_In *t13ExtClockInput; /**< \brief External input signal selection for timer 13 */
219  IfxCcu6_CountingInputMode t13countingInputMode; /**< \brief Input event leading to a counting action of the timer T13 */
221 
222 /** \brief Structure for interrupt configuration
223  */
224 typedef struct
225 {
226  IfxCcu6_InterruptSource interruptSource; /**< \brief Interrupt source selection */
227  IfxCcu6_ServiceRequest serviceRequest; /**< \brief Selection of service request outputs */
228  uint16 priority; /**< \brief Interrupt priority */
229  IfxSrc_Tos typeOfService; /**< \brief type of interrupt service */
231 
232 /** \brief Structure for CCU6 output pin configuration
233  */
234 typedef struct
235 {
236  const IfxCcu6_Cc60_Out *cc60Out; /**< \brief CC60 compare output CC0 */
237  const IfxCcu6_Cc61_Out *cc61Out; /**< \brief CC61 compare output CC1 */
238  const IfxCcu6_Cc62_Out *cc62Out; /**< \brief CC62 compare output CC2 */
239  const IfxCcu6_Cout60_Out *cout60; /**< \brief CC60 compare output COUT0 */
240  const IfxCcu6_Cout61_Out *cout61; /**< \brief CC61 compare output COUT1 */
241  const IfxCcu6_Cout62_Out *cout62; /**< \brief CC62 compare output COUT2 */
242  const IfxCcu6_Cout63_Out *cout63; /**< \brief CC63 compare output COUT3 */
243  IfxPort_OutputMode outputMode; /**< \brief The pin output mode which should be configured */
244  IfxPort_PadDriver pinDriver; /**< \brief pad driver */
245  const IfxCcu6_T12hr_In *t12hr; /**< \brief T12HR input signal */
246  const IfxCcu6_T13hr_In *t13hr; /**< \brief T13HR input signal */
247  IfxPort_InputMode t1xhrInputMode; /**< \brief The T1xHR pin input mode which should be configured */
249 
250 /** \brief Structure for Timer 12
251  */
252 typedef struct
253 {
254  IfxCcu6_TimerInputClock clockInput; /**< \brief Input clock selection (prescaler) */
255  IfxCcu6_T12Channel channelId; /**< \brief Capture compare channel of the Timer12 */
256  IfxCcu6_T12ChannelMode channelMode; /**< \brief The operating mode for the T12 channel */
257  IfxCcu6_T12CountMode countMode; /**< \brief Operating mode of Timer 12 */
258  uint16 counterValue; /**< \brief 16-bit counter value of Timer12 */
259  uint8 deadTimeValue; /**< \brief Value of the dead time to be induced */
260  uint16 compareValue; /**< \brief 16-bit comapre value of Timer12 */
262 
263 /** \brief Structure for Timer 13
264  */
265 typedef struct
266 {
267  IfxCcu6_TimerInputClock clockInput; /**< \brief Input clock selection (prescaler) */
268  uint16 counterValue; /**< \brief 16-bit counter value of Timer13 */
269  uint16 compareValue; /**< \brief 16-bit comapre value of Timer12 */
270  IfxCcu6_T13TriggerEvent t12SyncEvent; /**< \brief T12 sync trigger event to start T13 */
271  IfxCcu6_T13TriggerDirection t12SyncDirection; /**< \brief Additional information to control trigger event selection */
273 
274 /** \brief Configuration structure for external triggers
275  */
276 typedef struct
277 {
278  IfxCcu6_T12hr_In *t12ExtInputTrigger; /**< \brief External trigger input signal selection to start the timer 12 */
279  IfxCcu6_T13hr_In *t13ExtInputTrigger; /**< \brief External trigger input signal selection to start the timer 13 */
280  IfxCcu6_ExternalTriggerMode extInputTriggerMode; /**< \brief Event of signal T1xHR that can set the run bit T1xR by HW */
281  boolean t13InSyncWithT12; /**< \brief Selection of Timer 13 start in sync with T12 */
282  boolean outputTriggerEnabled; /**< \brief Output trigger connection to VADC enable / disable choice */
283  IfxCcu6_TrigOut outputLine; /**< \brief Trigger out selection */
284  IfxCcu6_TrigSel outputTrigger; /**< \brief Output Trigger selection */
286 
287 /** \} */
288 
289 /** \addtogroup IfxLld_Ccu6_TPwm_DataStructures
290  * \{ */
291 /** \brief Module handle
292  */
293 typedef struct
294 {
295  TPwm base; /**< \brief Base TPWM object */
296  Ifx_CCU6 *ccu6; /**< \brief Pointer to the base of CCU6 registers */
297  IfxCcu6_TimerId timer; /**< \brief Timer number (T12 / T13) */
298  IfxCcu6_ChannelOut channelOut; /**< \brief Capture compare output pin selection */
299  IfxCcu6_TPwm_TriggerConfig trigger; /**< \brief Structure for trigger configuration */
300 } IfxCcu6_TPwm;
301 
302 /** \brief Configuration structure of the module
303  */
304 typedef struct
305 {
306  TPwm_Config base; /**< \brief Base configuration */
307  Ifx_CCU6 *ccu6; /**< \brief Pointer to the base of CCU6 registers */
308  IfxCcu6_TimerId timer; /**< \brief Timer number (T12 / T13) */
309  IfxCcu6_TPwm_Clock clock; /**< \brief Structure for clock configuration */
310  IfxCcu6_TPwm_Timer12 timer12; /**< \brief Structure for Timer 12 */
311  IfxCcu6_TPwm_Timer13 timer13; /**< \brief Structure for Timer 13 */
312  IfxCcu6_ChannelOut channelOut; /**< \brief Capture compare output pin selection */
313  IfxCcu6_TPwm_Pins *pins; /**< \brief Structure for CCU6 output pin configuration */
314  IfxCcu6_TPwm_InterruptConfig interrupt; /**< \brief Structure for interrupt configuration */
315  IfxCcu6_TPwm_TriggerConfig trigger; /**< \brief Structure for trigger configuration */
317 
318 /** \} */
319 
320 /** \addtogroup IfxLld_Ccu6_TPwm_Module_Initialize_Functions
321  * \{ */
322 
323 /******************************************************************************/
324 /*-------------------------Global Function Prototypes-------------------------*/
325 /******************************************************************************/
326 
327 /** \brief Fills the config structure with default values
328  * \param config Configuration structure of the module
329  * \param ccu6 Pointer to the base of CCU6 registers
330  * \return None
331  *
332  * A coding example can be found in \ref IfxCcu6_TPwm_initModule
333  *
334  */
335 IFX_EXTERN void IfxCcu6_TPwm_initModuleConfig(IfxCcu6_TPwm_Config *config, Ifx_CCU6 *ccu6);
336 
337 /** \} */
338 
339 /** \addtogroup IfxLld_Ccu6_TPwm_Modultion_Control_Functions
340  * \{ */
341 
342 /******************************************************************************/
343 /*-------------------------Global Function Prototypes-------------------------*/
344 /******************************************************************************/
345 
346 /** \brief Initialises the module with default configuration
347  * \param tPwm Module handle
348  * \param config Configuration structure of the module
349  * \return None
350  *
351  * \code
352  * // create configuration
353  * IfxCcu6_TPwm_Config tPwmConfig;
354  * IfxCcu6_TPwm_initModuleConfig(&tPwmConfig, &MODULE_CCU60);
355  *
356  * // configure the frequency of the timer in case of internal start
357  * // this frequency will be set for the timer block selected later
358  * tPwmConfig.base.frequency = 400000;
359  *
360  * // configure the period of the timer
361  * tPwmConfig.base.period = 100;
362  *
363  * // configure the waiting time in case of delayed T13 start in sync with T12
364  * tPwmConfig.base.waitingTime = 20;
365  *
366  * // select the active state of the output
367  * tPwmConfig.base.activeState = Ifx_ActiveState_high;
368  *
369  * // select the timer through which PWM is to be generated
370  * tPwmConfig.timer = IfxCcu6_TimerId_t13;
371  *
372  * // configure the clock for internal mode
373  * tPwmConfig.clock.t13ExtClockEnabled = FALSE;
374  * tPwmConfig.clock.t13ExtClockInput = NULL_PTR;
375  * tPwmConfig.clock.t13countingInputMode = IfxCcu6_CountingInputMode_internal;
376  *
377  * // configure the selcted timer block
378  * tPwmConfig.timer13.counterValue = 0;
379  * tPwmConfig.timer13.compareValue = 100;
380  * // configure the syncronisation, in case of sync start with T12
381  * tPwmConfig.timer13.t12SyncEvent = IfxCcu6_T13TriggerEvent_onCC60RCompare;
382  * tPwmConfig.timer13.t12SyncDirection = IfxCcu6_T13TriggerDirection_onT12CountingUp;
383  *
384  * //select the channel out for modulation
385  * tPwmConfig.channelOut = IfxCcu6_ChannelOut_cout3;
386  *
387  * // pin configuration
388  * const IfxCcu6_TPwm_Pins pins = {
389  * NULL, // CC60Out pin not used
390  * NULL, // CC61Out pin not used
391  * NULL, // CC62Out pin not used
392  * NULL, // COUT60 pin not used
393  * NULL, // COUT61 pin not used
394  * NULL, // COUT62 pin not used
395  * IfxCcu60_COUT63_P00_0_OUT, // COUT63 pin
396  * IfxPort_OutputMode_pushPull,
397  * IfxPort_PadDriver_cmosAutomotiveSpeed1
398  * };
399  * tPwmConfig.pins = &pins;
400  *
401  * // configure the interrupts
402  * tPwmConfig.interrupt.interruptSource = IfxCcu6_InterruptSource_t13CompareMatch;
403  * tPwmConfig.interrupt.serviceRequest = IfxCcu6_ServiceRequest_sR2;
404  * tPwmConfig.interrupt.priority = IFX_INTRPRIO_CCU6;
405  * tPwmConfig.interrupt.typeOfService = IfxSrc_Tos_cpu0;
406  *
407  * // configure input and output triggers
408  * tPwmConfig.trigger.t12ExtInputTrigger = IfxCcu60_T12HRB_P00_7_IN;
409  * tPwmConfig.trigger.t13ExtInputTrigger = NULL_PTR;
410  * tPwmConfig.trigger.extInputTriggerMode = IfxCcu6_ExternalTriggerMode_risingEdge;
411  * tPwmConfig.trigger.t13InSyncWithT12 = TRUE;
412  *
413  * tPwmConfig.trigger.outputTriggerEnabled = TRUE;
414  * tPwmConfig.trigger.outputLine = IfxCcu6_TrigOut_0;
415  * tPwmConfig.trigger.outputTrigger = IfxCcu6_TrigSel_cout63;
416  *
417  *
418  * // initialize the module
419  * IfxCcu6_TPwm_initModule(&tPwm, &tPwmConfig);
420  * \endcode
421  *
422  */
424 
425 /** \brief Pauses the triggered PWM
426  * \param tPwm Module handle
427  * \return None
428  *
429  * \code
430  * IfxCcu6_TPwm_pause(&tPwm);
431  * \endcode
432  *
433  */
435 
436 /** \brief Resumes the triggered PWM
437  * \param tPwm Module handle
438  * \return None
439  *
440  * \code
441  * IfxCcu6_TPwm_resume(&tPwm);
442  * \endcode
443  *
444  */
446 
447 /** \brief Starts the triggered PWM
448  * \param tPwm Module handle
449  * \return None
450  *
451  * \code
452  * IfxCcu6_TPwm_start(&tPwm);
453  * \endcode
454  *
455  */
457 
458 /** \brief Stops the triggered PWM
459  * \param tPwm Module handle
460  * \return None
461  *
462  * \code
463  * IfxCcu6_TPwm_stop(&tPwm);
464  * \endcode
465  *
466  */
468 
469 /** \} */
470 
471 #endif /* IFXCCU6_TPWM_H */