iLLD_TC27xC  1.0
IfxGtm_Atom_Timer.c
Go to the documentation of this file.
1 /**
2  * \file IfxGtm_Atom_Timer.c
3  * \brief _ATOM 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 /*----------------------------------Includes----------------------------------*/
27 /******************************************************************************/
28 
29 #include "IfxGtm_Atom_Timer.h"
30 #include "_Utilities/Ifx_Assert.h"
31 #include "IfxGtm_bf.h"
32 #include "stddef.h"
33 
34 /******************************************************************************/
35 /*-------------------------Function Implementations---------------------------*/
36 /******************************************************************************/
37 
39 {
40  boolean event;
41  event = IfxGtm_Atom_Ch_isZeroNotification(driver->atom, driver->timerChannel);
42 
43  if (event)
44  {
46  }
47  else
48  {}
49 
50  return event;
51 }
52 
53 
55 {
56  boolean event;
57  event = IfxGtm_Atom_Ch_isOneNotification(driver->atom, driver->triggerChannel);
58 
59  if (event)
60  {
62  }
63  else
64  {}
65 
66  return event;
67 }
68 
69 
71 {
72  driver->channelsMask |= mask;
73 }
74 
75 
77 {
79 }
80 
81 
83 {
85 }
86 
87 
89 {
90  return 1.0 / IfxStdIf_Timer_tickToS(driver->base.clockFreq, driver->base.period);
91 }
92 
93 
95 {
96  return driver->base.clockFreq;
97 }
98 
99 
101 {
102  return driver->base.period;
103 }
104 
105 
107 {
108  return IfxGtm_Atom_Ch_getTimerPointer(driver->atom, driver->timerChannel);
109 }
110 
111 
113 {
114  return 1.0 / driver->base.clockFreq;
115 }
116 
117 
119 {
120  /* FIXME Add the case when no trigger is defiend config->triggerOut = NULL
121  * FIXME Check if pwm is configured (IfxGtm_Atom_Ch_configurePwmMode) if if (triggerChannel == driver->timerChannel)
122  * Check similar issue on TOM */
123  boolean result = TRUE;
124  IfxGtm_Atom_Timer_Base *base = &driver->base;
125 
126  IFX_ASSERT(IFX_VERBOSE_LEVEL_ERROR, config->base.countDir == IfxStdIf_Timer_CountDir_up); /* only this mode is supported */
127 
128  driver->gtm = config->gtm;
129  driver->atomIndex = config->atom;
130  driver->atom = &config->gtm->ATOM[config->atom];
131  driver->timerChannel = config->timerChannel;
132  base->triggerEnabled = config->base.trigger.enabled;
133 
134  if (base->triggerEnabled)
135  {
136  driver->triggerChannel = config->triggerOut->channel;
137  }
138  else
139  {
140  driver->triggerChannel = driver->timerChannel; // Set to timer channel to disable its use
141  }
142 
143  driver->agc = (Ifx_GTM_ATOM_AGC *)&driver->atom->AGC.GLB_CTRL;
144 
145  /* Initialize the timer part */
146  IfxGtm_Atom_Ch_configurePwmMode(driver->atom, driver->timerChannel, config->clock,
149 
151 
152  if ((config->base.minResolution > 0) && ((1.0 / base->clockFreq) > config->base.minResolution))
153  {
154  result = FALSE;
156  }
157  else
158  {}
159 
161 
162  /* Initialize the trigger part */
163  driver->channelsMask = 1 << driver->timerChannel;
164 
165  if (base->triggerEnabled)
166  {
167  IfxGtm_Atom_Ch triggerChannel = driver->triggerChannel;
168  uint16 triggerChannelMask = 1 << triggerChannel;
169 
170  if (triggerChannel != driver->timerChannel)
171  {
172  IfxGtm_Atom_Ch_configurePwmMode(driver->atom, triggerChannel, config->clock,
175  IfxGtm_Atom_Agc_enableChannels(driver->agc, triggerChannelMask, 0, FALSE);
176  driver->channelsMask |= triggerChannelMask;
177  }
178  else
179  {}
180 
181  if (config->base.trigger.outputEnabled)
182  {
183  IfxGtm_Atom_Agc_enableChannelsOutput(driver->agc, triggerChannelMask, 0, FALSE);
184 
185  /* Initialize the port */
187  }
188  else
189  {
190  IfxGtm_Atom_Agc_enableChannelsOutput(driver->agc, 0, triggerChannelMask, FALSE);
191  }
192 
194  }
195  else
196  {}
197 
198  /* Interrupt configuration */
199  {
200  volatile Ifx_SRC_SRCR *src;
201  boolean timerHasIrq = config->base.isrPriority > 0;
202  boolean triggerHasIrq = (config->base.trigger.isrPriority > 0) && base->triggerEnabled;
203 
204  if (driver->triggerChannel == driver->timerChannel)
205  {
206  IfxGtm_Atom_Ch_setNotification(driver->atom, driver->timerChannel, IfxGtm_IrqMode_level, timerHasIrq, triggerHasIrq);
207  src = IfxGtm_Atom_Ch_getSrcPointer(driver->gtm, config->atom, driver->timerChannel);
208  IfxSrc_init(src, config->base.isrProvider, config->base.isrPriority);
209  IfxSrc_enable(src);
210  }
211  else
212  {
214 
215  if (timerHasIrq)
216  {
217  IfxGtm_Atom_Ch_setNotification(driver->atom, driver->timerChannel, irqMode, TRUE, FALSE);
218  src = IfxGtm_Atom_Ch_getSrcPointer(driver->gtm, config->atom, driver->timerChannel);
219  IfxSrc_init(src, config->base.isrProvider, config->base.isrPriority);
220  IfxSrc_enable(src);
221  }
222 
223  if (triggerHasIrq)
224  {
225  IfxGtm_Atom_Ch_setNotification(driver->atom, driver->triggerChannel, irqMode, FALSE, TRUE);
226  src = IfxGtm_Atom_Ch_getSrcPointer(driver->gtm, config->atom, driver->triggerChannel);
227  IfxSrc_init(src, config->base.trigger.isrProvider, config->base.trigger.isrPriority);
228  IfxSrc_enable(src);
229  }
230  }
231  }
232 
233  /* Transfer the shadow registers */
234  IfxGtm_Atom_Agc_setChannelsForceUpdate(driver->agc, driver->channelsMask, 0, 0, 0);
235  IfxGtm_Atom_Agc_trigger(driver->agc);
236  IfxGtm_Atom_Agc_setChannelsForceUpdate(driver->agc, 0, driver->channelsMask, 0, 0);
237  return result;
238 }
239 
240 
242 {
244  config->gtm = gtm;
245  config->atom = IfxGtm_Atom_0;
246  config->timerChannel = IfxGtm_Atom_Ch_0;
247  config->triggerOut = NULL_PTR;
248  config->clock = IfxGtm_Cmu_Clk_0;
250 }
251 
252 
254 {
255  IfxGtm_Atom_Agc_enableChannels(driver->agc, driver->channelsMask, 0, TRUE);
256 }
257 
258 
260 {
261  Ifx_TimerValue period = IfxStdIf_Timer_sToTick(driver->base.clockFreq, 1.0 / frequency);
262 
263  return IfxGtm_Atom_Timer_setPeriod(driver, period);
264 }
265 
266 
268 {
269  driver->base.period = period;
270  IfxGtm_Atom_Ch_setCompareZeroShadow(driver->atom, driver->timerChannel, period);
271 
272  if (driver->triggerChannel != driver->timerChannel)
273  {
274  IfxGtm_Atom_Ch_setCompareZeroShadow(driver->atom, driver->triggerChannel, period);
275  }
276 
277  return TRUE;
278 }
279 
280 
282 {
283  IfxGtm_Atom_Ch_setOneShotMode(driver->atom, driver->timerChannel, enabled);
284 }
285 
286 
288 {
289  IfxGtm_Atom_Ch_setCompareOneShadow(driver->atom, driver->triggerChannel, triggerPoint + 1);
290 }
291 
292 
294 {
295  /* *INDENT-OFF* Note: this file was indented manually by the author. */
296  /* Set the API link */
297  stdif->driver = driver;
313  /* *INDENT-ON* */
314 
315  return TRUE;
316 }
317 
318 
320 {
321  IfxGtm_Atom_Agc_enableChannels(driver->agc, 0, driver->channelsMask, TRUE);
322 }
323 
324 
326 {
327  driver->base.clockFreq = IfxGtm_Atom_Ch_getClockFrequency(driver->gtm, driver->atom, driver->timerChannel);
328 }