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
38
boolean
IfxGtm_Atom_Timer_acknowledgeTimerIrq
(
IfxGtm_Atom_Timer
*driver)
39
{
40
boolean
event;
41
event
=
IfxGtm_Atom_Ch_isZeroNotification
(driver->
atom
, driver->
timerChannel
);
42
43
if
(event)
44
{
45
IfxGtm_Atom_Ch_clearZeroNotification
(driver->
atom
, driver->
timerChannel
);
46
}
47
else
48
{}
49
50
return
event;
51
}
52
53
54
boolean
IfxGtm_Atom_Timer_acknowledgeTriggerIrq
(
IfxGtm_Atom_Timer
*driver)
55
{
56
boolean
event;
57
event
=
IfxGtm_Atom_Ch_isOneNotification
(driver->
atom
, driver->
triggerChannel
);
58
59
if
(event)
60
{
61
IfxGtm_Atom_Ch_clearOneNotification
(driver->
atom
, driver->
triggerChannel
);
62
}
63
else
64
{}
65
66
return
event;
67
}
68
69
70
void
IfxGtm_Atom_Timer_addToChannelMask
(
IfxGtm_Atom_Timer
*driver,
uint16
mask)
71
{
72
driver->
channelsMask
|= mask;
73
}
74
75
76
void
IfxGtm_Atom_Timer_applyUpdate
(
IfxGtm_Atom_Timer
*driver)
77
{
78
IfxGtm_Atom_Agc_enableChannelsUpdate
(driver->
agc
, driver->
channelsMask
, 0);
79
}
80
81
82
void
IfxGtm_Atom_Timer_disableUpdate
(
IfxGtm_Atom_Timer
*driver)
83
{
84
IfxGtm_Atom_Agc_enableChannelsUpdate
(driver->
agc
, 0, driver->
channelsMask
);
85
}
86
87
88
float32
IfxGtm_Atom_Timer_getFrequency
(
IfxGtm_Atom_Timer
*driver)
89
{
90
return
1.0 /
IfxStdIf_Timer_tickToS
(driver->
base
.
clockFreq
, driver->
base
.
period
);
91
}
92
93
94
float32
IfxGtm_Atom_Timer_getInputFrequency
(
IfxGtm_Atom_Timer
*driver)
95
{
96
return
driver->
base
.
clockFreq
;
97
}
98
99
100
Ifx_TimerValue
IfxGtm_Atom_Timer_getPeriod
(
IfxGtm_Atom_Timer
*driver)
101
{
102
return
driver->
base
.
period
;
103
}
104
105
106
volatile
uint32
*
IfxGtm_Atom_Timer_getPointer
(
IfxGtm_Atom_Timer
*driver)
107
{
108
return
IfxGtm_Atom_Ch_getTimerPointer
(driver->
atom
, driver->
timerChannel
);
109
}
110
111
112
float32
IfxGtm_Atom_Timer_getResolution
(
IfxGtm_Atom_Timer
*driver)
113
{
114
return
1.0 / driver->
base
.
clockFreq
;
115
}
116
117
118
boolean
IfxGtm_Atom_Timer_init
(
IfxGtm_Atom_Timer
*driver,
const
IfxGtm_Atom_Timer_Config
*config)
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
,
147
config->
base
.
trigger
.
risingEdgeAtPeriod
,
IfxGtm_Atom_Ch_ResetEvent_onCm0
,
148
IfxGtm_Atom_Ch_OutputTrigger_generate
);
149
150
IfxGtm_Atom_Timer_updateInputFrequency
(driver);
151
152
if
((config->
base
.
minResolution
> 0) && ((1.0 / base->
clockFreq
) > config->
base
.
minResolution
))
153
{
154
result =
FALSE
;
155
IFX_ASSERT
(
IFX_VERBOSE_LEVEL_ERROR
,
FALSE
);
156
}
157
else
158
{}
159
160
IfxGtm_Atom_Timer_setFrequency
(driver, config->
base
.
frequency
);
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
,
173
config->
base
.
trigger
.
risingEdgeAtPeriod
,
IfxGtm_Atom_Ch_ResetEvent_onTrigger
,
174
IfxGtm_Atom_Ch_OutputTrigger_forward
);
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 */
186
IfxGtm_PinMap_setAtomTout
(config->
triggerOut
, config->
base
.
trigger
.
outputMode
, config->
base
.
trigger
.
outputDriver
);
187
}
188
else
189
{
190
IfxGtm_Atom_Agc_enableChannelsOutput
(driver->
agc
, 0, triggerChannelMask,
FALSE
);
191
}
192
193
IfxGtm_Atom_Timer_setTrigger
(driver, config->
base
.
trigger
.
triggerPoint
);
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
{
213
IfxGtm_IrqMode
irqMode =
IfxGtm_IrqMode_pulseNotify
;
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
241
void
IfxGtm_Atom_Timer_initConfig
(
IfxGtm_Atom_Timer_Config
*config, Ifx_GTM *gtm)
242
{
243
IfxStdIf_Timer_initConfig
(&config->
base
);
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
;
249
config->
base
.
countDir
=
IfxStdIf_Timer_CountDir_up
;
250
}
251
252
253
void
IfxGtm_Atom_Timer_run
(
IfxGtm_Atom_Timer
*driver)
254
{
255
IfxGtm_Atom_Agc_enableChannels
(driver->
agc
, driver->
channelsMask
, 0,
TRUE
);
256
}
257
258
259
boolean
IfxGtm_Atom_Timer_setFrequency
(
IfxGtm_Atom_Timer
*driver,
float32
frequency)
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
267
boolean
IfxGtm_Atom_Timer_setPeriod
(
IfxGtm_Atom_Timer
*driver,
Ifx_TimerValue
period)
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
281
void
IfxGtm_Atom_Timer_setSingleMode
(
IfxGtm_Atom_Timer
*driver,
boolean
enabled)
282
{
283
IfxGtm_Atom_Ch_setOneShotMode
(driver->
atom
, driver->
timerChannel
, enabled);
284
}
285
286
287
void
IfxGtm_Atom_Timer_setTrigger
(
IfxGtm_Atom_Timer
*driver,
Ifx_TimerValue
triggerPoint)
288
{
289
IfxGtm_Atom_Ch_setCompareOneShadow
(driver->
atom
, driver->
triggerChannel
, triggerPoint + 1);
290
}
291
292
293
boolean
IfxGtm_Atom_Timer_stdIfTimerInit
(
IfxStdIf_Timer
*stdif,
IfxGtm_Atom_Timer
*driver)
294
{
295
/* *INDENT-OFF* Note: this file was indented manually by the author. */
296
/* Set the API link */
297
stdif->
driver
= driver;
298
stdif->
getFrequency
=(
IfxStdIf_Timer_GetFrequency
)&
IfxGtm_Atom_Timer_getFrequency
;
299
stdif->
getPeriod
=(
IfxStdIf_Timer_GetPeriod
)&
IfxGtm_Atom_Timer_getPeriod
;
300
stdif->
getResolution
=(
IfxStdIf_Timer_GetResolution
)&
IfxGtm_Atom_Timer_getResolution
;
301
stdif->
setFrequency
=(
IfxStdIf_Timer_SetFrequency
)&
IfxGtm_Atom_Timer_setFrequency
;
302
stdif->
updateInputFrequency
=(
IfxStdIf_Timer_UpdateInputFrequency
)&
IfxGtm_Atom_Timer_updateInputFrequency
;
303
stdif->
applyUpdate
=(
IfxStdIf_Timer_ApplyUpdate
)&
IfxGtm_Atom_Timer_applyUpdate
;
304
stdif->
disableUpdate
=(
IfxStdIf_Timer_DisableUpdate
)&
IfxGtm_Atom_Timer_disableUpdate
;
305
stdif->
getInputFrequency
=(
IfxStdIf_Timer_GetInputFrequency
)&
IfxGtm_Atom_Timer_getInputFrequency
;
306
stdif->
run
=(
IfxStdIf_Timer_Run
)&
IfxGtm_Atom_Timer_run
;
307
stdif->
setPeriod
=(
IfxStdIf_Timer_SetPeriod
)&
IfxGtm_Atom_Timer_setPeriod
;
308
stdif->
setSingleMode
=(
IfxStdIf_Timer_SetSingleMode
)&
IfxGtm_Atom_Timer_setSingleMode
;
309
stdif->
setTrigger
=(
IfxStdIf_Timer_SetTrigger
)&
IfxGtm_Atom_Timer_setTrigger
;
310
stdif->
stop
=(
IfxStdIf_Timer_Stop
)&
IfxGtm_Atom_Timer_stop
;
311
stdif->
ackTimerIrq
=(
IfxStdIf_Timer_AckTimerIrq
)&
IfxGtm_Atom_Timer_acknowledgeTimerIrq
;
312
stdif->
ackTriggerIrq
=(
IfxStdIf_Timer_AckTriggerIrq
)&
IfxGtm_Atom_Timer_acknowledgeTriggerIrq
;
313
/* *INDENT-ON* */
314
315
return
TRUE
;
316
}
317
318
319
void
IfxGtm_Atom_Timer_stop
(
IfxGtm_Atom_Timer
*driver)
320
{
321
IfxGtm_Atom_Agc_enableChannels
(driver->
agc
, 0, driver->
channelsMask
,
TRUE
);
322
}
323
324
325
void
IfxGtm_Atom_Timer_updateInputFrequency
(
IfxGtm_Atom_Timer
*driver)
326
{
327
driver->
base
.
clockFreq
=
IfxGtm_Atom_Ch_getClockFrequency
(driver->
gtm
, driver->
atom
, driver->
timerChannel
);
328
}
home
mclld
Libraries
release
iLLD_0_1_0_10
src
ifx
TC27xC
Gtm
Atom
Timer
IfxGtm_Atom_Timer.c
Generated by
1.8.4