iLLD_TC27xD  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_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_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
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, (uint16)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 
204  if (config->interrupt1.priority > 0)
205  {
206  IfxCcu6_enableInterrupt(config->ccu6, config->interrupt1.source);
208 
209  volatile Ifx_SRC_SRCR *src;
210  src = IfxCcu6_getSrcAddress(config->ccu6, config->interrupt1.serviceRequest);
211  IfxSrc_init(src, config->interrupt1.typeOfService, config->interrupt1.priority);
212  IfxSrc_enable(src);
213  }
214 
215  if (config->interrupt2.priority > 0)
216  {
217  IfxCcu6_enableInterrupt(config->ccu6, config->interrupt2.source);
219 
220  volatile Ifx_SRC_SRCR *src;
221  src = IfxCcu6_getSrcAddress(config->ccu6, config->interrupt2.serviceRequest);
222  IfxSrc_init(src, config->interrupt2.typeOfService, config->interrupt2.priority);
223  IfxSrc_enable(src);
224  }
225 
226  if (config->interrupt3.priority > 0)
227  {
228  IfxCcu6_enableInterrupt(config->ccu6, config->interrupt3.source);
230 
231  volatile Ifx_SRC_SRCR *src;
232  src = IfxCcu6_getSrcAddress(config->ccu6, config->interrupt3.serviceRequest);
233  IfxSrc_init(src, config->interrupt3.typeOfService, config->interrupt3.priority);
234  IfxSrc_enable(src);
235  }
236 
237  if (config->interrupt4.priority > 0)
238  {
239  IfxCcu6_enableInterrupt(config->ccu6, config->interrupt4.source);
241 
242  volatile Ifx_SRC_SRCR *src;
243  src = IfxCcu6_getSrcAddress(config->ccu6, config->interrupt4.serviceRequest);
244  IfxSrc_init(src, config->interrupt4.typeOfService, config->interrupt4.priority);
245  IfxSrc_enable(src);
246  }
247 
248  timer->timer = config->timer;
249  timer->trigger = config->trigger;
250 
251 #if IFX_CFG_USE_STANDARD_INTERFACE
252  IFX_ASSERT(IFX_VERBOSE_LEVEL_ERROR, (uint32)timer == ((uint32)&timer->base));
253  timer->base.functions.start = (Timer_Start) & IfxCcu6_Timer_start;
254  timer->base.functions.stop = (Timer_Stop) & IfxCcu6_Timer_stop;
255  timer->base.functions.synchronousStart = (Timer_SynchronousStart) & IfxCcu6_Timer_synchronousStart;
256  timer->base.functions.synchronousStop = (Timer_SynchronousStop) & IfxCcu6_Timer_synchronousStop;
257  timer->base.functions.countOneStep = (Timer_CountOneStep) & IfxCcu6_Timer_countOneStep;
258  timer->base.functions.startSingleShotMode = (Timer_StartSingleShotMode) & IfxCcu6_Timer_startSingleShotMode;
259 #endif
260 }
261 
262 
264 {
265  const IfxCcu6_Timer_Config defaultConfig = {
266  .ccu6 = NULL_PTR, // will be initialized below
267 
268  .base.t12Frequency = 400000,
269  .base.t13Frequency = 400000,
270  .base.t12Period = 100,
271  .base.t13Period = 100,
272  .base.waitingTime = 20,
273 
274  .timer = IfxCcu6_TimerId_t13,
275  .synchronousOperation = FALSE,
276 
277  .pins = NULL_PTR,
278 
279  .clock = {
280  .t12ExtClockEnabled = FALSE,
281  .t12ExtClockInput = NULL_PTR,
282  .t12countingInputMode = IfxCcu6_CountingInputMode_internal,
283 
284  .t13ExtClockEnabled = FALSE,
285  .t13ExtClockInput = NULL_PTR,
286  .t13countingInputMode = IfxCcu6_CountingInputMode_internal,
287  },
288 
289  .timer12 = {
291  .counterValue = 0,
292  },
293 
294  .timer13 = {
295  .counterValue = 0,
298  },
299 
300  .interrupt1 = {
302  .serviceRequest = IfxCcu6_ServiceRequest_0,
303  .priority = 0, // interrupt priority 0
304  .typeOfService = IfxSrc_Tos_cpu0, // type of service CPU0
305  },
306 
307  .interrupt2 = {
309  .serviceRequest = IfxCcu6_ServiceRequest_1,
310  .priority = 0, // interrupt priority 0
311  .typeOfService = IfxSrc_Tos_cpu0, // type of service CPU0
312  },
313 
314  .interrupt3 = {
316  .serviceRequest = IfxCcu6_ServiceRequest_2,
317  .priority = 0, // interrupt priority 0
318  .typeOfService = IfxSrc_Tos_cpu0, // type of service CPU0
319  },
320 
321  .interrupt4 = {
323  .serviceRequest = IfxCcu6_ServiceRequest_3,
324  .priority = 0, // interrupt priority 0
325  .typeOfService = IfxSrc_Tos_cpu0, // type of service CPU0
326  },
327 
328  .trigger = {
329  .t12ExtInputTrigger = NULL_PTR,
330  .t13ExtInputTrigger = NULL_PTR,
331  .extInputTriggerMode = IfxCcu6_ExternalTriggerMode_risingEdge,
332  .t13InSyncWithT12 = TRUE,
333  },
334  };
335 
336  /* Default Configuration */
337  *config = defaultConfig;
338 
339  /* take over module pointer */
340  config->ccu6 = ccu6;
341 }
342 
343 
345 {
346  // Timer 13 start //
347 
348  if (timer->timer == IfxCcu6_TimerId_t13)
349  {
350  // enable shadow transfer
352 
353  // start Timer 13 when not in sync with timer12
354  if (!(timer->trigger.t13InSyncWithT12))
355  {
356  if (timer->trigger.t13ExtInputTrigger != NULL_PTR)
357  {
358  // external start
361  }
362  else
363  {
364  // internal start
365  IfxCcu6_startTimer(timer->ccu6, FALSE, TRUE);
366  }
367  }
368  else
369  {}
370  }
371  else
372  {}
373 
374  // Timer 12 start alone or when in sync with Timer 13 //
375 
376  if ((timer->timer == IfxCcu6_TimerId_t12) || (timer->trigger.t13InSyncWithT12))
377  {
378  // enable shadow transfer
380 
381  //start Timer 12
382  if (timer->trigger.t12ExtInputTrigger != NULL_PTR)
383  {
384  // external start
387  }
388  else
389  {
390  // internal start
391  IfxCcu6_startTimer(timer->ccu6, TRUE, FALSE);
392  }
393  }
394  else
395  {}
396 }
397 
398 
400 {
401  // Timer 13 start //
402 
403  if (timer->timer == IfxCcu6_TimerId_t13)
404  {
405  // enable shadow transfer
407 
408  //enable single shot mode
410 
411  // start Timer 13 when not in sync with timer12
412  if (!(timer->trigger.t13InSyncWithT12))
413  {
414  if (timer->trigger.t13ExtInputTrigger != NULL_PTR)
415  {
416  // external start
419  }
420  else
421  {
422  // internal start
423  IfxCcu6_startTimer(timer->ccu6, FALSE, TRUE);
424  }
425  }
426  else
427  {}
428  }
429  else
430  {}
431 
432  // Timer 12 start alone or when in sync with Timer 13 //
433 
434  if ((timer->timer == IfxCcu6_TimerId_t12) || (timer->trigger.t13InSyncWithT12))
435  {
436  // enable shadow transfer
438 
439  //enable single shot mode
441 
442  if (timer->trigger.t12ExtInputTrigger != NULL_PTR)
443  {
444  // external start
447  }
448  else
449  {
450  // internal start
451  IfxCcu6_startTimer(timer->ccu6, TRUE, FALSE);
452  }
453  }
454  else
455  {}
456 }
457 
458 
460 {
461  // Timer 13 stop //
462 
463  if ((timer->timer == IfxCcu6_TimerId_t13) || (timer->trigger.t13InSyncWithT12))
464  {
465  // disable shadow transfer
467 
468  // remove external input trigger if any
469  if (timer->trigger.t13ExtInputTrigger != NULL_PTR)
470  {
472  }
473 
474  // remove the sync with Timer 12
475  if (timer->trigger.t13InSyncWithT12)
476  {
479  }
480 
481  // stop Timer 13
482  IfxCcu6_stopTimer(timer->ccu6, FALSE, TRUE);
483  }
484 
485  // Timer 12 stop //
486 
487  else
488  {
489  // disable shadow transfer
491 
492  // remove external input trigger if any
493  if (timer->trigger.t12ExtInputTrigger != NULL_PTR)
494  {
496  }
497 
498  // stop Timer 12
499  IfxCcu6_stopTimer(timer->ccu6, TRUE, FALSE);
500  }
501 }
502 
503 
505 {
506  // enable shadow transfer
508 
509  // only internal synchronous start is possible
510  IfxCcu6_startTimer(timer->ccu6, TRUE, TRUE);
511 }
512 
513 
515 {
516  // disable shadow transfer
518 
519  // only internal synchronous stop is possible
520  IfxCcu6_stopTimer(timer->ccu6, TRUE, TRUE);
521 }