iLLD_TC27xD  1.0
IfxCcu6_TimerWithTrigger.c
Go to the documentation of this file.
1 /**
2  * \file IfxCcu6_TimerWithTrigger.c
3  * \brief CCU6 TIMERWITHTRIGGER 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 /*----------------------------------Includes----------------------------------*/
27 /******************************************************************************/
28 
30 #include "_Utilities/Ifx_Assert.h"
31 #include "stddef.h"
32 #include "string.h"
33 
34 /******************************************************************************/
35 /*-------------------------Function Implementations---------------------------*/
36 /******************************************************************************/
37 
39 {
40  boolean event;
41  event = IfxCcu6_isT12OneNotification(driver->ccu6);
42 
43  if (event)
44  {
46  }
47  else
48  {}
49 
50  return event;
51 }
52 
53 
55 {
56  boolean event;
57  event = IfxCcu6_isT13CompareNotification(driver->ccu6);
58 
59  if (event)
60  {
62  }
63  else
64  {}
65 
66  return event;
67 }
68 
69 
71 {
73 }
74 
75 
77 {}
78 
80 {
81  return 1.0 / IfxStdIf_Timer_tickToS(driver->base.clockFreq, driver->base.period);
82 }
83 
84 
86 {
87  return driver->base.clockFreq;
88 }
89 
90 
92 {
93  return driver->base.period;
94 }
95 
96 
98 {
99  return IfxCcu6_getT12TimerPointer(driver->ccu6);
100 }
101 
102 
104 {
105  return 1.0 / driver->base.clockFreq;
106 }
107 
108 
110 {
111  boolean result = TRUE;
112  IfxCcu6_TimerWithTrigger_Base *base = &driver->base;
113  Ifx_CCU6 *module;
114 
115  driver->ccu6 = config->ccu6;
116  module = driver->ccu6;
117 
118  base->triggerEnabled = config->base.trigger.enabled;
119 
120  /** - Enable/initialise the CCU6 if it has not been enabled. See IfxCcu6_isModuleEnabled() */
121  if (IfxCcu6_isModuleEnabled(module) == FALSE)
122  {
123  IfxCcu6_enableModule(module);
124  }
125 
126  /* Initialize the timer part */
128 
129  driver->base.countDir = config->base.countDir;
130 
131  uint16 prescaler;
132  float32 freqT12 = 0, periodT12;
134 
135  for (prescaler = 0; prescaler < 16; prescaler++)
136  {
137  freqT12 = freqCC6 / (1U << prescaler);
138  periodT12 = freqT12 / config->base.frequency;
139 
140  if ((periodT12 <= 16386.0) && (periodT12 > config->base.minResolution))
141  {
142  break;
143  }
144  }
145 
146  if (prescaler < 16)
147  {
148  Ifx_CCU6_TCTR0 tctr0;
149  tctr0.U = module->TCTR0.U;
150  tctr0.B.T12CLK = (prescaler & 0x7U);
151  tctr0.B.T12PRE = ((prescaler & 0x8U) != 0);
152  module->TCTR0.U = tctr0.U;
153  }
154  else
155  {
156  /** \retval IfxCcu6_Stat_wrongPwmFreq if the T12 prescaler can't fulfill the
157  * required frequency */
158  result = FALSE;
159  }
160 
162 
163  if ((config->base.minResolution > 0) && ((1.0 / base->clockFreq) > config->base.minResolution))
164  {
165  result = FALSE;
167  }
168  else
169  {}
170 
172  /* Initialize the trigger part */
173 
174  /** - The T13 is used to generate additional PWM for internal trigger purpose (e.g.
175  * ADC) or external trigger purpose (e.g. sensor synchronisation). */
176 
177  if (base->triggerEnabled)
178  {
179  Ifx_CCU6_TCTR0 tctr0 = module->TCTR0;
180  module->TCTR0.B.T13CLK = tctr0.B.T12CLK;
181  module->TCTR0.B.T13PRE = tctr0.B.T12PRE;
182  IfxCcu6_setT13PeriodValue(module, (uint16)(base->period - 1));
183 
184  module->MODCTR.B.T13MODEN = 0;
186 
188 
190 
193 
194  if (config->base.trigger.outputEnabled)
195  {
196  if (config->triggerOut != NULL_PTR)
197  {
198  /*Initialize the port */
200  }
201  else
202  {
203  result = FALSE;
204  }
205  }
206  else
207  {}
208 
210  }
211  else
212  {}
213 
214  /* Interrupt configuration */
215  {
216  boolean timerHasIrq = config->base.isrPriority > 0;
217  boolean triggerHasIrq = (config->base.trigger.isrPriority > 0) && base->triggerEnabled;
218 
219  if (timerHasIrq || triggerHasIrq)
220  {
221  volatile Ifx_SRC_SRCR *src;
222 
226 
227  if (timerHasIrq)
228  {
230  {
232  }
233  else
234  {
236  }
237 
238  module->INP.B.INPT12 = config->serviceReqNrPeriod;
239  src = IfxCcu6_getSrcAddress(module, config->serviceReqNrPeriod);
240  IfxSrc_init(src, config->base.isrProvider, config->base.isrPriority);
241  IfxSrc_enable(src);
242  }
243 
244  if (triggerHasIrq)
245  {
247  module->INP.B.INPT13 = config->serviceReqNrTrigger;
248 
249  src = IfxCcu6_getSrcAddress(module, config->serviceReqNrTrigger);
250  IfxSrc_init(src, config->base.trigger.isrProvider, config->base.trigger.isrPriority);
251  IfxSrc_enable(src);
252  }
253  }
254  }
255 
256  /* Transfer the shadow registers */
258  return result;
259 }
260 
261 
263 {
265  config->ccu6 = ccu6;
268  config->triggerOut = NULL_PTR;
269 }
270 
271 
273 {
274  IfxCcu6_startTimer(driver->ccu6, TRUE, FALSE);
275 }
276 
277 
279 {
280  Ifx_TimerValue period = IfxStdIf_Timer_sToTick(driver->base.clockFreq, 1.0 / frequency);
281 
282  return IfxCcu6_TimerWithTrigger_setPeriod(driver, period);
283 }
284 
285 
287 {
288  driver->base.period = period;
289  IfxCcu6_setT12PeriodValue(driver->ccu6, (uint16)((driver->ccu6->TCTR0.B.CTM == 1) ?
290  ((period / 2) - 1) : (period - 1)));
291 
292  return TRUE;
293 }
294 
295 
297 {
298  if (enabled)
299  {
301  }
302  else
303  {
305  }
306 }
307 
308 
310 {
311  driver->ccu6->CC63SR.U = triggerPoint; /* FIXME does it require -1?*/
312 }
313 
314 
316 {
317  /* Ensure the stdif is reset to zeros */
318  memset(stdif, 0, sizeof(IfxStdIf_Timer));
319 
320  /* *INDENT-OFF* Note: this file was indented manually by the author. */
321  /* Set the API link */
322  stdif->driver = driver;
338  /* *INDENT-ON* */
339 
340  return TRUE;
341 }
342 
343 
345 {
346  IfxCcu6_stopTimer(driver->ccu6, TRUE, TRUE);
347 }
348 
349 
351 {
352  /* FIXME ADD iLLD new feature getClockFrequency() */
353  uint16 prescaler;
354  prescaler = driver->ccu6->TCTR0.B.T12CLK;
355 
356  driver->base.clockFreq = IfxScuCcu_getSpbFrequency() / (1U << prescaler);
357 }