iLLD_TC27xC  1.0
IfxGtm_Tom_Timer.c
Go to the documentation of this file.
1 /**
2  * \file IfxGtm_Tom_Timer.c
3  * \brief _TOM 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_Tom_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 
42  event = IfxGtm_Tom_Ch_isZeroNotification(driver->tom, driver->timerChannel);
43 
44  if (event)
45  {
47  }
48  else
49  {}
50 
51  return event;
52 }
53 
54 
56 {
57  boolean event;
58 
59  event = IfxGtm_Tom_Ch_isOneNotification(driver->tom, driver->triggerChannel);
60 
61  if (event)
62  {
64  }
65  else
66  {}
67 
68  return event;
69 }
70 
71 
73 {
74  driver->channelsMask |= mask;
75 }
76 
77 
79 {
81 }
82 
83 
85 {
87 }
88 
89 
91 {
92  return 1.0 / IfxStdIf_Timer_tickToS(driver->base.clockFreq, driver->base.period);
93 }
94 
95 
97 {
98  return driver->base.clockFreq;
99 }
100 
101 
103 {
104  return driver->base.period;
105 }
106 
107 
109 {
110  return IfxGtm_Tom_Ch_getTimerPointer(driver->tom, driver->timerChannel);
111 }
112 
113 
115 {
116  return 1.0 / driver->base.clockFreq;
117 }
118 
119 
121 {
122  boolean result = TRUE;
123  IfxGtm_Tom_Timer_Base *base = &driver->base;
124  uint16 maskShift;
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->tomIndex = config->tom;
130  driver->tom = &config->gtm->TOM[config->tom];
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  if (config->timerChannel <= 7)
144  {
145  driver->tgc = IfxGtm_Tom_Ch_getTgcPointer(driver->tom, 0);
146  }
147  else
148  {
149  driver->tgc = IfxGtm_Tom_Ch_getTgcPointer(driver->tom, 1);
150  }
151 
152  /* Initialize the timer part */
153  /* FIXME add IfxGtm_Tom_Ch_configurePwmMode() and use it */
154  IfxGtm_Tom_Ch_setClockSource(driver->tom, driver->timerChannel, config->clock);
156 
158 
159  if ((config->base.minResolution > 0) && ((1.0 / base->clockFreq) > config->base.minResolution))
160  {
161  result = FALSE;
163  }
164  else
165  {}
166 
168 
169  /* Initialize the trigger part */
170  maskShift = (config->timerChannel <= 7) ? 0 : 8;
171  driver->channelsMask = 1 << (driver->timerChannel - maskShift);
172 
173  if (base->triggerEnabled)
174  {
175  IfxGtm_Tom_Ch triggerChannel = driver->triggerChannel;
176  uint16 triggerChannelMask = 1 << (triggerChannel - maskShift);
177 
178  if (triggerChannel != driver->timerChannel)
179  {
180  /* FIXME add IfxGtm_Tom_Ch_configurePwmMode() and use it */
181  IfxGtm_Tom_Ch_setSignalLevel(driver->tom, triggerChannel, config->base.trigger.risingEdgeAtPeriod);
183  IfxGtm_Tom_Ch_setClockSource(driver->tom, triggerChannel, config->clock);
185  IfxGtm_Tom_Tgc_enableChannels(driver->tgc, triggerChannelMask, 0, FALSE);
186  driver->channelsMask |= triggerChannelMask;
187  }
188  else
189  {}
190 
191  if (config->base.trigger.outputEnabled)
192  {
193  IfxGtm_Tom_Tgc_enableChannelsOutput(driver->tgc, triggerChannelMask, 0, FALSE);
194 
195  /* Initialize the port */
197  }
198  else
199  {
200  IfxGtm_Tom_Tgc_enableChannelsOutput(driver->tgc, 0, triggerChannelMask, FALSE);
201  }
202 
204  }
205  else
206  {}
207 
208  /* Interrupt configuration */
209  {
210  volatile Ifx_SRC_SRCR *src;
211  boolean timerHasIrq = config->base.isrPriority > 0;
212  boolean triggerHasIrq = (config->base.trigger.isrPriority > 0) && base->triggerEnabled;
213 
214  if (driver->triggerChannel == driver->timerChannel)
215  {
216  IfxGtm_Tom_Ch_setNotification(driver->tom, driver->timerChannel, IfxGtm_IrqMode_level, timerHasIrq, triggerHasIrq);
217  src = IfxGtm_Tom_Ch_getSrcPointer(driver->gtm, config->tom, driver->timerChannel);
218  IfxSrc_init(src, config->base.isrProvider, config->base.isrPriority);
219  IfxSrc_enable(src);
220  }
221  else
222  {
224 
225  if (timerHasIrq)
226  {
227  IfxGtm_Tom_Ch_setNotification(driver->tom, driver->timerChannel, irqMode, TRUE, FALSE);
228  src = IfxGtm_Tom_Ch_getSrcPointer(driver->gtm, config->tom, driver->timerChannel);
229  IfxSrc_init(src, config->base.isrProvider, config->base.isrPriority);
230  IfxSrc_enable(src);
231  }
232 
233  if (triggerHasIrq)
234  {
235  IfxGtm_Tom_Ch_setNotification(driver->tom, driver->triggerChannel, irqMode, FALSE, TRUE);
236  src = IfxGtm_Tom_Ch_getSrcPointer(driver->gtm, config->tom, driver->triggerChannel);
237  IfxSrc_init(src, config->base.trigger.isrProvider, config->base.trigger.isrPriority);
238  IfxSrc_enable(src);
239  }
240  }
241  }
242 
243  /* Transfer the shadow registers */
244  IfxGtm_Tom_Tgc_setChannelsForceUpdate(driver->tgc, driver->channelsMask, 0, 0, 0);
245  IfxGtm_Tom_Tgc_trigger(driver->tgc);
246  IfxGtm_Tom_Tgc_setChannelsForceUpdate(driver->tgc, 0, driver->channelsMask, 0, 0);
247  return result;
248 }
249 
250 
252 {
254  config->gtm = gtm;
255  config->tom = IfxGtm_Tom_0;
256  config->timerChannel = IfxGtm_Tom_Ch_0;
257  config->triggerOut = NULL_PTR;
260 }
261 
262 
264 {
265  IfxGtm_Tom_Tgc_enableChannels(driver->tgc, driver->channelsMask, 0, TRUE);
266 }
267 
268 
270 {
271  Ifx_TimerValue period = IfxStdIf_Timer_sToTick(driver->base.clockFreq, 1.0 / frequency);
272 
273  return IfxGtm_Tom_Timer_setPeriod(driver, period);
274 }
275 
276 
278 {
279  driver->base.period = period;
280  IfxGtm_Tom_Ch_setCompareZeroShadow(driver->tom, driver->timerChannel, period);
281 
282  if (driver->triggerChannel != driver->timerChannel)
283  {
284  IfxGtm_Tom_Ch_setCompareZeroShadow(driver->tom, driver->triggerChannel, period);
285  }
286 
287  return TRUE;
288 }
289 
290 
291 void IfxGtm_Tom_Timer_setSingleMode(IfxGtm_Tom_Timer *driver, boolean enabled)
292 {
293  IfxGtm_Tom_Ch_setOneShotMode(driver->tom, driver->timerChannel, enabled);
294 }
295 
296 
298 {
299  IfxGtm_Tom_Ch_setCompareOneShadow(driver->tom, driver->triggerChannel, triggerPoint + 1);
300 }
301 
302 
304 {
305  /* *INDENT-OFF* Note: this file was indented manually by the author. */
306  /* Set the API link */
307  stdif->driver = driver;
323  /* *INDENT-ON* */
324 
325  return TRUE;
326 }
327 
328 
330 {
331  IfxGtm_Tom_Tgc_enableChannels(driver->tgc, 0, driver->channelsMask, TRUE);
332 }
333 
334 
336 {
337  driver->base.clockFreq = IfxGtm_Tom_Ch_getClockFrequency(driver->gtm, driver->tom, driver->timerChannel);
338 }