iLLD_TC27xC
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_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
/******************************************************************************/
27
/*----------------------------------Includes----------------------------------*/
28
/******************************************************************************/
29
30
#include "
IfxCcu6_Timer.h
"
31
32
/******************************************************************************/
33
/*-------------------------Function Implementations---------------------------*/
34
/******************************************************************************/
35
36
void
IfxCcu6_Timer_countOneStep
(
IfxCcu6_Timer
*timer)
37
{
38
if
(timer->
timer
==
IfxCcu6_TimerId_t13
)
39
{
40
// enable shadow transfer
41
IfxCcu6_enableShadowTransfer
(timer->
ccu6
,
FALSE
,
TRUE
);
42
43
// enable manual counting mode
44
IfxCcu6_setCountingInputMode
(timer->
ccu6
,
IfxCcu6_TimerId_t13
,
IfxCcu6_CountingInputMode_manual
);
45
IfxCcu6_enableCountEvent
(timer->
ccu6
,
FALSE
,
TRUE
);
46
}
47
else
if
(timer->
timer
==
IfxCcu6_TimerId_t12
)
48
{
49
// enable shadow transfer
50
IfxCcu6_enableShadowTransfer
(timer->
ccu6
,
TRUE
,
FALSE
);
51
52
// enable manual counting mode
53
IfxCcu6_setCountingInputMode
(timer->
ccu6
,
IfxCcu6_TimerId_t12
,
IfxCcu6_CountingInputMode_manual
);
54
IfxCcu6_enableCountEvent
(timer->
ccu6
,
TRUE
,
FALSE
);
55
}
56
}
57
58
59
void
IfxCcu6_Timer_initModule
(
IfxCcu6_Timer
*timer,
const
IfxCcu6_Timer_Config
*config)
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 //
79
if
(
IfxCcu6_getTimerAvailabilityStatus
(ccu6SFR,
IfxCcu6_TimerId_t13
) ==
FALSE
)
80
{
81
IfxCcu6_enableTimer
(ccu6SFR,
IfxCcu6_TimerId_t13
);
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
{
91
IfxCcu6_setT13InputSignal
(config->
ccu6
, config->
clock
.
t13ExtClockInput
);
92
}
93
94
// counting input mode selection
95
IfxCcu6_setCountingInputMode
(ccu6SFR,
IfxCcu6_TimerId_t13
, config->
clock
.
t13countingInputMode
);
96
97
// period setting
98
IfxCcu6_setT13PeriodValue
(ccu6SFR, config->
base
.
t13Period
);
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
107
IfxCcu6_setT13CounterValue
(ccu6SFR, config->
timer13
.
counterValue
);
108
109
// if Timer 13 start is in sync with Timer 12 //
110
if
((config->
trigger
.
t13InSyncWithT12
) && (!(config->
synchronousOperation
)))
111
{
112
IfxCcu6_setT13TriggerEventMode
(ccu6SFR, config->
timer13
.
t12SyncEvent
);
113
IfxCcu6_setT13TriggerEventDirection
(ccu6SFR, config->
timer13
.
t12SyncDirection
);
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 //
126
if
(
IfxCcu6_getTimerAvailabilityStatus
(ccu6SFR,
IfxCcu6_TimerId_t12
) ==
FALSE
)
127
{
128
IfxCcu6_enableTimer
(ccu6SFR,
IfxCcu6_TimerId_t12
);
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)
135
if
(config->
timer13
.
t12SyncEvent
==
IfxCcu6_T13TriggerEvent_onT12Period
)
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
{
152
IfxCcu6_setT12InputSignal
(config->
ccu6
, config->
clock
.
t12ExtClockInput
);
153
}
154
155
// counting input mode selection
156
IfxCcu6_setCountingInputMode
(ccu6SFR,
IfxCcu6_TimerId_t12
, config->
clock
.
t12countingInputMode
);
157
158
// countining mode selection
159
IfxCcu6_setT12CountMode
(ccu6SFR, config->
timer12
.
countMode
);
160
161
// period selection for center aligned mode
162
if
(config->
timer12
.
countMode
==
IfxCcu6_T12CountMode_centerAligned
)
163
{
164
period = (period / 2) - 1;
165
}
166
167
// period setting
168
IfxCcu6_setT12PeriodValue
(ccu6SFR, 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
178
IfxCcu6_setT12CounterValue
(ccu6SFR, config->
timer12
.
counterValue
);
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
IfxCcu6_enableInterrupt
(ccu6SFR, config->
interrupt
.
interruptSource
);
205
IfxCcu6_routeInterruptNode
(ccu6SFR, config->
interrupt
.
interruptSource
, config->
interrupt
.
serviceRequest
);
206
207
if
(config->
interrupt
.
priority
> 0)
208
{
209
volatile
Ifx_SRC_SRCR *src;
210
src =
IfxCcu6_getSrcAddress
(ccu6SFR, config->
interrupt
.
serviceRequest
);
211
IfxSrc_init
(src, config->
interrupt
.
typeOfService
, config->
interrupt
.
priority
);
212
IfxSrc_enable
(src);
213
}
214
215
timer->
timer
= config->
timer
;
216
timer->
trigger
= config->
trigger
;
217
218
#if IFX_CFG_USE_STANDARD_INTERFACE
219
IFX_ASSERT
(
IFX_VERBOSE_LEVEL_ERROR
, (
uint32
)timer == ((
uint32
)&timer->
base
));
220
timer->
base
.functions.start = (
Timer_Start
) &
IfxCcu6_Timer_start
;
221
timer->
base
.functions.stop = (
Timer_Stop
) &
IfxCcu6_Timer_stop
;
222
timer->
base
.functions.synchronousStart = (
Timer_SynchronousStart
) &
IfxCcu6_Timer_synchronousStart
;
223
timer->
base
.functions.synchronousStop = (
Timer_SynchronousStop
) &
IfxCcu6_Timer_synchronousStop
;
224
timer->
base
.functions.countOneStep = (
Timer_CountOneStep
) &
IfxCcu6_Timer_countOneStep
;
225
timer->
base
.functions.startSingleShotMode = (
Timer_StartSingleShotMode
) &
IfxCcu6_Timer_startSingleShotMode
;
226
#endif
227
}
228
229
230
void
IfxCcu6_Timer_initModuleConfig
(
IfxCcu6_Timer_Config
*config, Ifx_CCU6 *ccu6)
231
{
232
const
IfxCcu6_Timer_Config
defaultConfig = {
233
.
ccu6
=
NULL_PTR
,
// will be initialized below
234
235
.base.t12Frequency = 400000,
236
.base.t13Frequency = 400000,
237
.base.t12Period = 100,
238
.base.t13Period = 100,
239
.base.waitingTime = 20,
240
241
.timer =
IfxCcu6_TimerId_t13
,
242
.synchronousOperation =
FALSE
,
243
244
.pins =
NULL_PTR
,
245
246
.clock = {
247
.t12ExtClockEnabled =
FALSE
,
248
.t12ExtClockInput =
NULL_PTR
,
249
.t12countingInputMode =
IfxCcu6_CountingInputMode_internal
,
250
251
.t13ExtClockEnabled =
FALSE
,
252
.t13ExtClockInput =
NULL_PTR
,
253
.t13countingInputMode =
IfxCcu6_CountingInputMode_internal
,
254
},
255
256
.timer12 = {
257
.countMode =
IfxCcu6_T12CountMode_edgeAligned
,
258
.counterValue = 0,
259
},
260
261
.timer13 = {
262
.counterValue = 0,
263
.t12SyncEvent =
IfxCcu6_T13TriggerEvent_onCC60RCompare
,
264
.t12SyncDirection =
IfxCcu6_T13TriggerDirection_onT12CountingUp
,
265
},
266
267
.interrupt = {
268
.interruptSource =
IfxCcu6_InterruptSource_t12PeriodMatch
,
269
.serviceRequest =
IfxCcu6_ServiceRequest_sR2
,
270
.priority = 0,
// interrupt priority 0
271
.typeOfService =
IfxSrc_Tos_cpu0
,
// type of service CPU0
272
},
273
274
.trigger = {
275
.t12ExtInputTrigger =
NULL_PTR
,
276
.t13ExtInputTrigger =
NULL_PTR
,
277
.extInputTriggerMode =
IfxCcu6_ExternalTriggerMode_risingEdge
,
278
.t13InSyncWithT12 =
TRUE
,
279
},
280
};
281
282
/* Default Configuration */
283
*config = defaultConfig;
284
285
/* take over module pointer */
286
config->
ccu6
= ccu6;
287
}
288
289
290
void
IfxCcu6_Timer_start
(
IfxCcu6_Timer
*timer)
291
{
292
// Timer 13 start //
293
294
if
(timer->
timer
==
IfxCcu6_TimerId_t13
)
295
{
296
// enable shadow transfer
297
IfxCcu6_enableShadowTransfer
(timer->
ccu6
,
FALSE
,
TRUE
);
298
299
// start Timer 13 when not in sync with timer12
300
if
(!(timer->
trigger
.
t13InSyncWithT12
))
301
{
302
if
(timer->
trigger
.
t13ExtInputTrigger
!=
NULL_PTR
)
303
{
304
// external start
305
IfxCcu6_setExternalRunMode
(timer->
ccu6
,
IfxCcu6_TimerId_t13
, timer->
trigger
.
extInputTriggerMode
);
306
IfxCcu6_setT13InputSignal
(timer->
ccu6
, timer->
trigger
.
t13ExtInputTrigger
);
307
}
308
else
309
{
310
// internal start
311
IfxCcu6_startTimer
(timer->
ccu6
,
FALSE
,
TRUE
);
312
}
313
}
314
else
315
{}
316
}
317
else
318
{}
319
320
// Timer 12 start alone or when in sync with Timer 13 //
321
322
if
((timer->
timer
==
IfxCcu6_TimerId_t12
) || (timer->
trigger
.
t13InSyncWithT12
))
323
{
324
// enable shadow transfer
325
IfxCcu6_enableShadowTransfer
(timer->
ccu6
,
TRUE
,
FALSE
);
326
327
//start Timer 12
328
if
(timer->
trigger
.
t12ExtInputTrigger
!=
NULL_PTR
)
329
{
330
// external start
331
IfxCcu6_setExternalRunMode
(timer->
ccu6
,
IfxCcu6_TimerId_t12
, timer->
trigger
.
extInputTriggerMode
);
332
IfxCcu6_setT12InputSignal
(timer->
ccu6
, timer->
trigger
.
t12ExtInputTrigger
);
333
}
334
else
335
{
336
// internal start
337
IfxCcu6_startTimer
(timer->
ccu6
,
TRUE
,
FALSE
);
338
}
339
}
340
else
341
{}
342
}
343
344
345
void
IfxCcu6_Timer_startSingleShotMode
(
IfxCcu6_Timer
*timer)
346
{
347
// Timer 13 start //
348
349
if
(timer->
timer
==
IfxCcu6_TimerId_t13
)
350
{
351
// enable shadow transfer
352
IfxCcu6_enableShadowTransfer
(timer->
ccu6
,
FALSE
,
TRUE
);
353
354
//enable single shot mode
355
IfxCcu6_enableSingleShotMode
(timer->
ccu6
,
IfxCcu6_TimerId_t13
);
356
357
// start Timer 13 when not in sync with timer12
358
if
(!(timer->
trigger
.
t13InSyncWithT12
))
359
{
360
if
(timer->
trigger
.
t13ExtInputTrigger
!=
NULL_PTR
)
361
{
362
// external start
363
IfxCcu6_setExternalRunMode
(timer->
ccu6
,
IfxCcu6_TimerId_t13
, timer->
trigger
.
extInputTriggerMode
);
364
IfxCcu6_setT13InputSignal
(timer->
ccu6
, timer->
trigger
.
t13ExtInputTrigger
);
365
}
366
else
367
{
368
// internal start
369
IfxCcu6_startTimer
(timer->
ccu6
,
FALSE
,
TRUE
);
370
}
371
}
372
else
373
{}
374
}
375
else
376
{}
377
378
// Timer 12 start alone or when in sync with Timer 13 //
379
380
if
((timer->
timer
==
IfxCcu6_TimerId_t12
) || (timer->
trigger
.
t13InSyncWithT12
))
381
{
382
// enable shadow transfer
383
IfxCcu6_enableShadowTransfer
(timer->
ccu6
,
TRUE
,
FALSE
);
384
385
//enable single shot mode
386
IfxCcu6_enableSingleShotMode
(timer->
ccu6
,
IfxCcu6_TimerId_t12
);
387
388
if
(timer->
trigger
.
t12ExtInputTrigger
!=
NULL_PTR
)
389
{
390
// external start
391
IfxCcu6_setExternalRunMode
(timer->
ccu6
,
IfxCcu6_TimerId_t12
, timer->
trigger
.
extInputTriggerMode
);
392
IfxCcu6_setT12InputSignal
(timer->
ccu6
, timer->
trigger
.
t12ExtInputTrigger
);
393
}
394
else
395
{
396
// internal start
397
IfxCcu6_startTimer
(timer->
ccu6
,
TRUE
,
FALSE
);
398
}
399
}
400
else
401
{}
402
}
403
404
405
void
IfxCcu6_Timer_stop
(
IfxCcu6_Timer
*timer)
406
{
407
// Timer 13 stop //
408
409
if
((timer->
timer
==
IfxCcu6_TimerId_t13
) || (timer->
trigger
.
t13InSyncWithT12
))
410
{
411
// disable shadow transfer
412
IfxCcu6_disableShadowTransfer
(timer->
ccu6
,
FALSE
,
TRUE
);
413
414
// remove external input trigger if any
415
if
(timer->
trigger
.
t13ExtInputTrigger
!=
NULL_PTR
)
416
{
417
IfxCcu6_setExternalRunMode
(timer->
ccu6
,
IfxCcu6_TimerId_t13
,
IfxCcu6_ExternalTriggerMode_disable
);
418
}
419
420
// remove the sync with Timer 12
421
if
(timer->
trigger
.
t13InSyncWithT12
)
422
{
423
IfxCcu6_setT13TriggerEventMode
(timer->
ccu6
,
IfxCcu6_T13TriggerEvent_noAction
);
424
IfxCcu6_setT13TriggerEventDirection
(timer->
ccu6
,
IfxCcu6_T13TriggerDirection_noAction
);
425
}
426
427
// stop Timer 13
428
IfxCcu6_stopTimer
(timer->
ccu6
,
FALSE
,
TRUE
);
429
}
430
431
// Timer 12 stop //
432
433
else
434
{
435
// disable shadow transfer
436
IfxCcu6_disableShadowTransfer
(timer->
ccu6
,
TRUE
,
FALSE
);
437
438
// remove external input trigger if any
439
if
(timer->
trigger
.
t12ExtInputTrigger
!=
NULL_PTR
)
440
{
441
IfxCcu6_setExternalRunMode
(timer->
ccu6
,
IfxCcu6_TimerId_t12
,
IfxCcu6_ExternalTriggerMode_disable
);
442
}
443
444
// stop Timer 12
445
IfxCcu6_stopTimer
(timer->
ccu6
,
TRUE
,
FALSE
);
446
}
447
}
448
449
450
void
IfxCcu6_Timer_synchronousStart
(
IfxCcu6_Timer
*timer)
451
{
452
// enable shadow transfer
453
IfxCcu6_enableShadowTransfer
(timer->
ccu6
,
TRUE
,
TRUE
);
454
455
// only internal synchronous start is possible
456
IfxCcu6_startTimer
(timer->
ccu6
,
TRUE
,
TRUE
);
457
}
458
459
460
void
IfxCcu6_Timer_synchronousStop
(
IfxCcu6_Timer
*timer)
461
{
462
// disable shadow transfer
463
IfxCcu6_disableShadowTransfer
(timer->
ccu6
,
TRUE
,
TRUE
);
464
465
// only internal synchronous stop is possible
466
IfxCcu6_stopTimer
(timer->
ccu6
,
TRUE
,
TRUE
);
467
}
home
mclld
Libraries
release
iLLD_0_1_0_10
src
ifx
TC27xC
Ccu6
Timer
IfxCcu6_Timer.c
Generated by
1.8.4