iLLD_TC27xC  1.0
IfxCcu6_Timer.c
Go to the documentation of this file.
1 /**
2  * \file IfxCcu6_Timer.c
3  * \brief CCU6 TIMER details
4  *
5  * \version iLLD_0_1_0_10
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_Timer.h"
31 
32 /******************************************************************************/
33 /*-------------------------Function Implementations---------------------------*/
34 /******************************************************************************/
35 
37 {
38  if (timer->timer == IfxCcu6_TimerId_t13)
39  {
40  // enable shadow transfer
42 
43  // enable manual counting mode
46  }
47  else if (timer->timer == IfxCcu6_TimerId_t12)
48  {
49  // enable shadow transfer
51 
52  // enable manual counting mode
55  }
56 }
57 
58 
60 {
61  Ifx_CCU6 *ccu6SFR = config->ccu6; // pointer to CCU6 registers
62  timer->ccu6 = ccu6SFR; // adding register pointer to module handler
63 
64  /* -- hardware module initialisation -- */
65 
66  // enable module if it hasn't been enabled by any other interface //
67  if (IfxCcu6_isModuleEnabled(ccu6SFR) == FALSE)
68  {
69  IfxCcu6_enableModule(ccu6SFR);
70  }
71 
72  /* -- timer initialisation -- */
73 
74  // Timer 13 initialisation //
75 
76  if ((config->timer == IfxCcu6_TimerId_t13) || (config->synchronousOperation))
77  {
78  // enable Timer13 if it hasn't been enabled by any other interface //
80  {
82  }
83 
84  // clock initialisation //
85 
86  if (config->clock.t13ExtClockEnabled) // if external source is selected as reference
87  {
88  // input signal selection
89  if (config->clock.t13ExtClockInput != NULL_PTR)
90  {
92  }
93 
94  // counting input mode selection
96 
97  // period setting
98  IfxCcu6_setT13PeriodValue(ccu6SFR, config->base.t13Period);
99  }
100  else // if internal clock is selected as reference
101  {
102  IfxCcu6_setT13Frequency(ccu6SFR, config->base.t13Frequency, config->base.t13Period);
103  }
104 
105  // counter initialisation //
106 
108 
109  // if Timer 13 start is in sync with Timer 12 //
110  if ((config->trigger.t13InSyncWithT12) && (!(config->synchronousOperation)))
111  {
114  }
115  }
116  else
117  {}
118 
119  // Timer 12 initialisation //
120 
121  if ((config->timer == IfxCcu6_TimerId_t12) || (config->trigger.t13InSyncWithT12) || (config->synchronousOperation))
122  {
123  Ifx_TimerValue period = config->base.t12Period;
124 
125  // enable Timer12 if it hasn't been enabled by any other interface //
127  {
129  }
130 
131  // if Timer 13 start is in sync with Timer 12 //
132  if ((config->trigger.t13InSyncWithT12) && (!(config->synchronousOperation)) && (config->base.waitingTime != 0))
133  {
134  // if in sync with T12 period match (only period match is allowed in this interface because T12 is only in counter mode)
136  {
137  period = config->base.waitingTime; // waiting time as period
138  }
139  }
140  else
141  {
142  // configuration error
143  }
144 
145  // clock initialisation //
146 
147  if (config->clock.t12ExtClockEnabled) // if external source is selected as reference
148  {
149  // input signal selection
150  if (config->clock.t12ExtClockInput != NULL_PTR)
151  {
153  }
154 
155  // counting input mode selection
157 
158  // countining mode selection
159  IfxCcu6_setT12CountMode(ccu6SFR, config->timer12.countMode);
160 
161  // period selection for center aligned mode
163  {
164  period = (period / 2) - 1;
165  }
166 
167  // period setting
168  IfxCcu6_setT12PeriodValue(ccu6SFR, period);
169  }
170  else // if internal clock is selected as reference
171  {
172  // in case of in sync with T13, T12 runs at same frequency as T13
173  IfxCcu6_setT12Frequency(ccu6SFR, config->base.t12Frequency, period, config->timer12.countMode);
174  }
175 
176  // counter initialisation //
177 
179  }
180 
181  /* -- Pin mapping -- */
182 
183  const IfxCcu6_Timer_Pins *pins = config->pins;
184 
185  if (pins != NULL_PTR)
186  {
187  IfxCcu6_T12hr_In *t12hr = pins->t12hr;
188 
189  if (t12hr != NULL_PTR)
190  {
191  IfxCcu6_initT12hrPin(t12hr, pins->t1xhrInputMode);
192  }
193 
194  IfxCcu6_T13hr_In *t13hr = pins->t13hr;
195 
196  if (t13hr != NULL_PTR)
197  {
198  IfxCcu6_initT13hrPin(t13hr, pins->t1xhrInputMode);
199  }
200  }
201 
202  /* -- interrupt initialisation -- */
203 
206 
207  if (config->interrupt.priority > 0)
208  {
209  volatile Ifx_SRC_SRCR *src;
210  src = IfxCcu6_getSrcAddress(ccu6SFR, config->interrupt.serviceRequest);
211  IfxSrc_init(src, config->interrupt.typeOfService, config->interrupt.priority);
212  IfxSrc_enable(src);
213  }
214 
215  timer->timer = config->timer;
216  timer->trigger = config->trigger;
217 
218 #if IFX_CFG_USE_STANDARD_INTERFACE
219  IFX_ASSERT(IFX_VERBOSE_LEVEL_ERROR, (uint32)timer == ((uint32)&timer->base));
220  timer->base.functions.start = (Timer_Start) & IfxCcu6_Timer_start;
221  timer->base.functions.stop = (Timer_Stop) & IfxCcu6_Timer_stop;
222  timer->base.functions.synchronousStart = (Timer_SynchronousStart) & IfxCcu6_Timer_synchronousStart;
223  timer->base.functions.synchronousStop = (Timer_SynchronousStop) & IfxCcu6_Timer_synchronousStop;
224  timer->base.functions.countOneStep = (Timer_CountOneStep) & IfxCcu6_Timer_countOneStep;
225  timer->base.functions.startSingleShotMode = (Timer_StartSingleShotMode) & IfxCcu6_Timer_startSingleShotMode;
226 #endif
227 }
228 
229 
231 {
232  const IfxCcu6_Timer_Config defaultConfig = {
233  .ccu6 = NULL_PTR, // will be initialized below
234 
235  .base.t12Frequency = 400000,
236  .base.t13Frequency = 400000,
237  .base.t12Period = 100,
238  .base.t13Period = 100,
239  .base.waitingTime = 20,
240 
241  .timer = IfxCcu6_TimerId_t13,
242  .synchronousOperation = FALSE,
243 
244  .pins = NULL_PTR,
245 
246  .clock = {
247  .t12ExtClockEnabled = FALSE,
248  .t12ExtClockInput = NULL_PTR,
249  .t12countingInputMode = IfxCcu6_CountingInputMode_internal,
250 
251  .t13ExtClockEnabled = FALSE,
252  .t13ExtClockInput = NULL_PTR,
253  .t13countingInputMode = IfxCcu6_CountingInputMode_internal,
254  },
255 
256  .timer12 = {
258  .counterValue = 0,
259  },
260 
261  .timer13 = {
262  .counterValue = 0,
265  },
266 
267  .interrupt = {
268  .interruptSource = IfxCcu6_InterruptSource_t12PeriodMatch,
269  .serviceRequest = IfxCcu6_ServiceRequest_sR2,
270  .priority = 0, // interrupt priority 0
271  .typeOfService = IfxSrc_Tos_cpu0, // type of service CPU0
272  },
273 
274  .trigger = {
275  .t12ExtInputTrigger = NULL_PTR,
276  .t13ExtInputTrigger = NULL_PTR,
277  .extInputTriggerMode = IfxCcu6_ExternalTriggerMode_risingEdge,
278  .t13InSyncWithT12 = TRUE,
279  },
280  };
281 
282  /* Default Configuration */
283  *config = defaultConfig;
284 
285  /* take over module pointer */
286  config->ccu6 = ccu6;
287 }
288 
289 
291 {
292  // Timer 13 start //
293 
294  if (timer->timer == IfxCcu6_TimerId_t13)
295  {
296  // enable shadow transfer
298 
299  // start Timer 13 when not in sync with timer12
300  if (!(timer->trigger.t13InSyncWithT12))
301  {
302  if (timer->trigger.t13ExtInputTrigger != NULL_PTR)
303  {
304  // external start
307  }
308  else
309  {
310  // internal start
311  IfxCcu6_startTimer(timer->ccu6, FALSE, TRUE);
312  }
313  }
314  else
315  {}
316  }
317  else
318  {}
319 
320  // Timer 12 start alone or when in sync with Timer 13 //
321 
322  if ((timer->timer == IfxCcu6_TimerId_t12) || (timer->trigger.t13InSyncWithT12))
323  {
324  // enable shadow transfer
326 
327  //start Timer 12
328  if (timer->trigger.t12ExtInputTrigger != NULL_PTR)
329  {
330  // external start
333  }
334  else
335  {
336  // internal start
337  IfxCcu6_startTimer(timer->ccu6, TRUE, FALSE);
338  }
339  }
340  else
341  {}
342 }
343 
344 
346 {
347  // Timer 13 start //
348 
349  if (timer->timer == IfxCcu6_TimerId_t13)
350  {
351  // enable shadow transfer
353 
354  //enable single shot mode
356 
357  // start Timer 13 when not in sync with timer12
358  if (!(timer->trigger.t13InSyncWithT12))
359  {
360  if (timer->trigger.t13ExtInputTrigger != NULL_PTR)
361  {
362  // external start
365  }
366  else
367  {
368  // internal start
369  IfxCcu6_startTimer(timer->ccu6, FALSE, TRUE);
370  }
371  }
372  else
373  {}
374  }
375  else
376  {}
377 
378  // Timer 12 start alone or when in sync with Timer 13 //
379 
380  if ((timer->timer == IfxCcu6_TimerId_t12) || (timer->trigger.t13InSyncWithT12))
381  {
382  // enable shadow transfer
384 
385  //enable single shot mode
387 
388  if (timer->trigger.t12ExtInputTrigger != NULL_PTR)
389  {
390  // external start
393  }
394  else
395  {
396  // internal start
397  IfxCcu6_startTimer(timer->ccu6, TRUE, FALSE);
398  }
399  }
400  else
401  {}
402 }
403 
404 
406 {
407  // Timer 13 stop //
408 
409  if ((timer->timer == IfxCcu6_TimerId_t13) || (timer->trigger.t13InSyncWithT12))
410  {
411  // disable shadow transfer
413 
414  // remove external input trigger if any
415  if (timer->trigger.t13ExtInputTrigger != NULL_PTR)
416  {
418  }
419 
420  // remove the sync with Timer 12
421  if (timer->trigger.t13InSyncWithT12)
422  {
425  }
426 
427  // stop Timer 13
428  IfxCcu6_stopTimer(timer->ccu6, FALSE, TRUE);
429  }
430 
431  // Timer 12 stop //
432 
433  else
434  {
435  // disable shadow transfer
437 
438  // remove external input trigger if any
439  if (timer->trigger.t12ExtInputTrigger != NULL_PTR)
440  {
442  }
443 
444  // stop Timer 12
445  IfxCcu6_stopTimer(timer->ccu6, TRUE, FALSE);
446  }
447 }
448 
449 
451 {
452  // enable shadow transfer
454 
455  // only internal synchronous start is possible
456  IfxCcu6_startTimer(timer->ccu6, TRUE, TRUE);
457 }
458 
459 
461 {
462  // disable shadow transfer
464 
465  // only internal synchronous stop is possible
466  IfxCcu6_stopTimer(timer->ccu6, TRUE, TRUE);
467 }