iLLD_TC27xD  1.0
IfxCcu6_TPwm.c
Go to the documentation of this file.
1 /**
2  * \file IfxCcu6_TPwm.c
3  * \brief CCU6 TPWM details
4  *
5  * \version iLLD_1_0_0_11_0
6  * \copyright Copyright (c) 2013 Infineon Technologies AG. All rights reserved.
7  *
8  *
9  * IMPORTANT NOTICE
10  *
11  *
12  * Infineon Technologies AG (Infineon) is supplying this file for use
13  * exclusively with Infineon's microcontroller products. This file can be freely
14  * distributed within development tools that are supporting such microcontroller
15  * products.
16  *
17  * THIS SOFTWARE IS PROVIDED "AS IS". NO WARRANTIES, WHETHER EXPRESS, IMPLIED
18  * OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF
19  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE.
20  * INFINEON SHALL NOT, IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL,
21  * OR CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER.
22  *
23  *
24  */
25 
26 /******************************************************************************/
27 /*----------------------------------Includes----------------------------------*/
28 /******************************************************************************/
29 
30 #include "IfxCcu6_TPwm.h"
31 
32 /******************************************************************************/
33 /*-------------------------Function Implementations---------------------------*/
34 /******************************************************************************/
35 
37 {
38  Ifx_CCU6 *ccu6SFR = config->ccu6; // pointer to CCU6 registers
39  tPwm->ccu6 = ccu6SFR; // adding register pointer to module handler
40 
41  /* -- hardware module initialisation -- */
42 
43  // enable module if it hasn't been enabled by any other interface //
44  if (IfxCcu6_isModuleEnabled(ccu6SFR) == FALSE)
45  {
46  IfxCcu6_enableModule(ccu6SFR);
47  }
48 
49  /* -- timer initialisation -- */
50 
51  // Timer 13 initialisation //
52 
53  if (config->timer == IfxCcu6_TimerId_t13)
54  {
55  // enable Timer13 if it hasn't been enabled by any other interface //
57  {
59  }
60 
61  // clock initialisation //
62 
63  if (config->clock.t13ExtClockEnabled) // if external source is selected as reference
64  {
65  // input signal selection
66  if (config->clock.t13ExtClockInput != NULL_PTR)
67  {
69  }
70 
71  // counting input mode selection
73 
74  // period setting
75  IfxCcu6_setT13PeriodValue(ccu6SFR, (uint16)config->base.period);
76  }
77  else // if internal clock is selected as reference
78  {
79  IfxCcu6_setT13Frequency(ccu6SFR, config->base.frequency, config->base.period);
80  }
81 
82  // duty cycle initialisation //
83 
85 
87 
88  // if Timer 13 start is in sync with Timer 12 //
89  if (config->trigger.t13InSyncWithT12)
90  {
93  }
94  }
95  else
96  {}
97 
98  // Timer 12 initialisation //
99 
100  if ((config->timer == IfxCcu6_TimerId_t12) || (config->trigger.t13InSyncWithT12))
101  {
102  Ifx_TimerValue period = config->base.period;
103  Ifx_TimerValue compareValue = config->timer12.compareValue;
104 
105  // enable Timer12 if it hasn't been enabled by any other interface //
107  {
109  }
110 
111  // if Timer 13 start is in sync with Timer 12 //
112  if ((config->trigger.t13InSyncWithT12) && (config->base.waitingTime != 0))
113  {
114  // if in sync with T12 period match
116  {
117  period = config->base.waitingTime; // waiting time as period
118  }
120  {
121  compareValue = config->base.waitingTime; // waiting time as compare value
122  period = config->base.activeCount;
123  }
124  }
125  else
126  {
127  // configuration error
128  }
129 
130  // clock initialisation //
131 
132  if (config->clock.t12ExtClockEnabled) // if external source is selected as reference
133  {
134  // input signal selection
135  if (config->clock.t12ExtClockInput != NULL_PTR)
136  {
138  }
139 
140  // counting input mode selection
142 
143  // countining mode selection
144  IfxCcu6_setT12CountMode(ccu6SFR, config->timer12.countMode);
145 
146  // period selection for center aligned mode
148  {
149  period = (period / 2) - 1;
150  }
151 
152  // period setting
153  IfxCcu6_setT12PeriodValue(ccu6SFR, (uint16)period);
154  }
155  else // if internal clock is selected as reference
156  {
157  // in case of in sync with T13 T12 runs at same frequency as T13
158  IfxCcu6_setT12Frequency(ccu6SFR, config->base.frequency, period, config->timer12.countMode);
159  }
160 
161  // duty cycle initialisation //
162 
164 
166 
167  IfxCcu6_setT12CompareValue(ccu6SFR, config->timer12.channelId, (uint16)compareValue);
168 
169  // dead time injection if selected
170  if (config->timer12.deadTimeValue)
171  {
173  IfxCcu6_enableDeadTime(ccu6SFR, config->timer12.channelId);
174  }
175  }
176  else
177  {}
178 
179  /* -- output path initialisation -- */
180 
181  //enable modulation output path //
182  IfxCcu6_enableModulationOutput(ccu6SFR, config->timer, config->channelOut);
183 
184  // output passive logic configuration //
185  //TODO check correct polarity:
186  IfxCcu6_setOutputPassiveState(ccu6SFR, config->channelOut, config->base.activeState);
187 
188  /* -- Pin mapping -- */
189 
190  const IfxCcu6_TPwm_Pins *pins = config->pins;
191 
192  if (pins != NULL_PTR)
193  {
194  IfxCcu6_Cc60_Out *cc60Out = pins->cc60Out;
195 
196  if (cc60Out != NULL_PTR)
197  {
198  IfxCcu6_initCc60OutPin(cc60Out, pins->outputMode, pins->pinDriver);
199  }
200 
201  IfxCcu6_Cc61_Out *cc61Out = pins->cc61Out;
202 
203  if (cc61Out != NULL_PTR)
204  {
205  IfxCcu6_initCc61OutPin(cc61Out, pins->outputMode, pins->pinDriver);
206  }
207 
208  IfxCcu6_Cc62_Out *cc62Out = pins->cc62Out;
209 
210  if (cc62Out != NULL_PTR)
211  {
212  IfxCcu6_initCc62OutPin(cc62Out, pins->outputMode, pins->pinDriver);
213  }
214 
215  IfxCcu6_Cout60_Out *cout60 = pins->cout60;
216 
217  if (cout60 != NULL_PTR)
218  {
219  IfxCcu6_initCout60Pin(cout60, pins->outputMode, pins->pinDriver);
220  }
221 
222  IfxCcu6_Cout61_Out *cout61 = pins->cout61;
223 
224  if (cout61 != NULL_PTR)
225  {
226  IfxCcu6_initCout61Pin(cout61, pins->outputMode, pins->pinDriver);
227  }
228 
229  IfxCcu6_Cout62_Out *cout62 = pins->cout62;
230 
231  if (cout62 != NULL_PTR)
232  {
233  IfxCcu6_initCout62Pin(cout62, pins->outputMode, pins->pinDriver);
234  }
235 
236  IfxCcu6_Cout63_Out *cout63 = pins->cout63;
237 
238  if (cout63 != NULL_PTR)
239  {
240  IfxCcu6_initCout63Pin(cout63, pins->outputMode, pins->pinDriver);
241  }
242 
243  IfxCcu6_T12hr_In *t12hr = pins->t12hr;
244 
245  if (t12hr != NULL_PTR)
246  {
247  IfxCcu6_initT12hrPin(t12hr, pins->t1xhrInputMode);
248  }
249 
250  IfxCcu6_T13hr_In *t13hr = pins->t13hr;
251 
252  if (t13hr != NULL_PTR)
253  {
254  IfxCcu6_initT13hrPin(t13hr, pins->t1xhrInputMode);
255  }
256  }
257 
258  /* -- interrupt initialisation -- */
259 
260  if (config->interrupt1.priority > 0)
261  {
262  IfxCcu6_enableInterrupt(config->ccu6, config->interrupt1.source);
264 
265  volatile Ifx_SRC_SRCR *src;
266  src = IfxCcu6_getSrcAddress(config->ccu6, config->interrupt1.serviceRequest);
267  IfxSrc_init(src, config->interrupt1.typeOfService, config->interrupt1.priority);
268  IfxSrc_enable(src);
269  }
270 
271  if (config->interrupt2.priority > 0)
272  {
273  IfxCcu6_enableInterrupt(config->ccu6, config->interrupt2.source);
275 
276  volatile Ifx_SRC_SRCR *src;
277  src = IfxCcu6_getSrcAddress(config->ccu6, config->interrupt2.serviceRequest);
278  IfxSrc_init(src, config->interrupt2.typeOfService, config->interrupt2.priority);
279  IfxSrc_enable(src);
280  }
281 
282  if (config->interrupt3.priority > 0)
283  {
284  IfxCcu6_enableInterrupt(config->ccu6, config->interrupt3.source);
286 
287  volatile Ifx_SRC_SRCR *src;
288  src = IfxCcu6_getSrcAddress(config->ccu6, config->interrupt3.serviceRequest);
289  IfxSrc_init(src, config->interrupt3.typeOfService, config->interrupt3.priority);
290  IfxSrc_enable(src);
291  }
292 
293  if (config->interrupt4.priority > 0)
294  {
295  IfxCcu6_enableInterrupt(config->ccu6, config->interrupt4.source);
297 
298  volatile Ifx_SRC_SRCR *src;
299  src = IfxCcu6_getSrcAddress(config->ccu6, config->interrupt4.serviceRequest);
300  IfxSrc_init(src, config->interrupt4.typeOfService, config->interrupt4.priority);
301  IfxSrc_enable(src);
302  }
303 
304  /* -- output trigger initialisation --*/
305 
306  if (config->trigger.outputTriggerEnabled)
307  {
309  }
310 
311  tPwm->timer = config->timer;
312  tPwm->channelOut = config->channelOut;
313  tPwm->trigger = config->trigger;
314 
315 #if IFX_CFG_USE_STANDARD_INTERFACE
316  IFX_ASSERT(IFX_VERBOSE_LEVEL_ERROR, (uint32)tPwm == ((uint32)&tPwm->base));
317  tPwm->base.functions.start = (TPwm_Start) & IfxCcu6_TPwm_start;
318  tPwm->base.functions.pause = (TPwm_Pause) & IfxCcu6_TPwm_pause;
319  tPwm->base.functions.resume = (TPwm_Resume) & IfxCcu6_TPwm_resume;
320  tPwm->base.functions.stop = (TPwm_Stop) & IfxCcu6_TPwm_stop;
321 #endif
322 }
323 
324 
326 {
327  const IfxCcu6_TPwm_Config defaultConfig = {
328  .ccu6 = NULL_PTR, // will be initialized below
329 
330  .base.frequency = 400000,
331  .base.period = 100,
332  .base.waitingTime = 20,
333  .base.activeState = Ifx_ActiveState_high,
334 
335  .timer = IfxCcu6_TimerId_t13,
336 
337  .clock = {
338  .t12ExtClockEnabled = FALSE,
339  .t12ExtClockInput = NULL_PTR,
340  .t12countingInputMode = IfxCcu6_CountingInputMode_internal,
341 
342  .t13ExtClockEnabled = FALSE,
343  .t13ExtClockInput = NULL_PTR,
344  .t13countingInputMode = IfxCcu6_CountingInputMode_internal,
345  },
346 
347  .timer12 = {
348  .channelId = IfxCcu6_T12Channel_0,
349  .channelMode = IfxCcu6_T12ChannelMode_compareMode,
351  .counterValue = 0,
352  .deadTimeValue = 0,
353  .compareValue = 0,
354  },
355 
356  .timer13 = {
357  .counterValue = 0,
358  .compareValue = 0,
361  },
362 
363  .channelOut = IfxCcu6_ChannelOut_cout3,
364 
365  .pins = NULL_PTR,
366 
367  .interrupt1 = {
369  .serviceRequest = IfxCcu6_ServiceRequest_0,
370  .priority = 0, // interrupt priority 0
371  .typeOfService = IfxSrc_Tos_cpu0, // type of service CPU0
372  },
373 
374  .interrupt2 = {
376  .serviceRequest = IfxCcu6_ServiceRequest_1,
377  .priority = 0, // interrupt priority 0
378  .typeOfService = IfxSrc_Tos_cpu0, // type of service CPU0
379  },
380 
381  .interrupt3 = {
383  .serviceRequest = IfxCcu6_ServiceRequest_2,
384  .priority = 0, // interrupt priority 0
385  .typeOfService = IfxSrc_Tos_cpu0, // type of service CPU0
386  },
387 
388  .interrupt4 = {
390  .serviceRequest = IfxCcu6_ServiceRequest_3,
391  .priority = 0, // interrupt priority 0
392  .typeOfService = IfxSrc_Tos_cpu0, // type of service CPU0
393  },
394 
395  .trigger = {
396  .t12ExtInputTrigger = NULL_PTR,
397  .t13ExtInputTrigger = NULL_PTR,
398  .extInputTriggerMode = IfxCcu6_ExternalTriggerMode_risingEdge,
399  .t13InSyncWithT12 = TRUE,
400 
401  .outputTriggerEnabled = TRUE,
402  .outputLine = IfxCcu6_TrigOut_0,
403  .outputTrigger = IfxCcu6_TrigSel_cout63,
404  },
405  };
406 
407  /* Default Configuration */
408  *config = defaultConfig;
409 
410  /* take over module pointer */
411  config->ccu6 = ccu6;
412 }
413 
414 
416 {
418 }
419 
420 
422 {
424 }
425 
426 
428 {
429  // Timer 13 modulation //
430 
431  if (tPwm->timer == IfxCcu6_TimerId_t13)
432  {
433  // enable shadow transfer
435 
436  // start Timer 13 when not in sync with Timer 12
437  if (!(tPwm->trigger.t13InSyncWithT12))
438  {
439  if (tPwm->trigger.t13ExtInputTrigger != NULL_PTR)
440  {
441  // external start
444  }
445  else
446  {
447  // internal start
449  }
450  }
451  else
452  {}
453  }
454  else
455  {}
456 
457  // Timer 12 alone for modulation or when in sync with Timer 13 //
458 
459  if ((tPwm->timer == IfxCcu6_TimerId_t12) || (tPwm->trigger.t13InSyncWithT12))
460  {
461  // enable shadow transfer
463 
464  //start Timer 12
465  if (tPwm->trigger.t12ExtInputTrigger != NULL_PTR)
466  {
467  // external start
470  }
471  else
472  {
473  // internal start
475  }
476  }
477  else
478  {}
479 }
480 
481 
483 {
484  // Timer 13 modulation //
485 
486  if ((tPwm->timer == IfxCcu6_TimerId_t13) || (tPwm->trigger.t13InSyncWithT12))
487  {
488  // disable shadow transfer
490 
491  // remove external input trigger if any
492  if (tPwm->trigger.t13ExtInputTrigger != NULL_PTR)
493  {
495  }
496 
497  // remove the sync with Timer 12
498  if (tPwm->trigger.t13InSyncWithT12)
499  {
502  }
503 
504  // stop Timer 13
505  IfxCcu6_stopTimer(tPwm->ccu6, FALSE, TRUE);
506  }
507 
508  // Timer 12 modulation //
509 
510  else
511  {
512  // disable shadow transfer
514 
515  // remove external input trigger if any
516  if (tPwm->trigger.t12ExtInputTrigger != NULL_PTR)
517  {
519  }
520 
521  // stop Timer 12
522  IfxCcu6_stopTimer(tPwm->ccu6, TRUE, FALSE);
523  }
524 
525  // disable the modulation
527 }