iLLD_TC27xD
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_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
/******************************************************************************/
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, (
uint16
)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, (
uint16
)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
if
(config->
interrupt1
.
priority
> 0)
205
{
206
IfxCcu6_enableInterrupt
(config->
ccu6
, config->
interrupt1
.
source
);
207
IfxCcu6_routeInterruptNode
(config->
ccu6
, config->
interrupt1
.
source
, config->
interrupt1
.
serviceRequest
);
208
209
volatile
Ifx_SRC_SRCR *src;
210
src =
IfxCcu6_getSrcAddress
(config->
ccu6
, config->
interrupt1
.
serviceRequest
);
211
IfxSrc_init
(src, config->
interrupt1
.
typeOfService
, config->
interrupt1
.
priority
);
212
IfxSrc_enable
(src);
213
}
214
215
if
(config->
interrupt2
.
priority
> 0)
216
{
217
IfxCcu6_enableInterrupt
(config->
ccu6
, config->
interrupt2
.
source
);
218
IfxCcu6_routeInterruptNode
(config->
ccu6
, config->
interrupt2
.
source
, config->
interrupt2
.
serviceRequest
);
219
220
volatile
Ifx_SRC_SRCR *src;
221
src =
IfxCcu6_getSrcAddress
(config->
ccu6
, config->
interrupt2
.
serviceRequest
);
222
IfxSrc_init
(src, config->
interrupt2
.
typeOfService
, config->
interrupt2
.
priority
);
223
IfxSrc_enable
(src);
224
}
225
226
if
(config->
interrupt3
.
priority
> 0)
227
{
228
IfxCcu6_enableInterrupt
(config->
ccu6
, config->
interrupt3
.
source
);
229
IfxCcu6_routeInterruptNode
(config->
ccu6
, config->
interrupt3
.
source
, config->
interrupt3
.
serviceRequest
);
230
231
volatile
Ifx_SRC_SRCR *src;
232
src =
IfxCcu6_getSrcAddress
(config->
ccu6
, config->
interrupt3
.
serviceRequest
);
233
IfxSrc_init
(src, config->
interrupt3
.
typeOfService
, config->
interrupt3
.
priority
);
234
IfxSrc_enable
(src);
235
}
236
237
if
(config->
interrupt4
.
priority
> 0)
238
{
239
IfxCcu6_enableInterrupt
(config->
ccu6
, config->
interrupt4
.
source
);
240
IfxCcu6_routeInterruptNode
(config->
ccu6
, config->
interrupt4
.
source
, config->
interrupt4
.
serviceRequest
);
241
242
volatile
Ifx_SRC_SRCR *src;
243
src =
IfxCcu6_getSrcAddress
(config->
ccu6
, config->
interrupt4
.
serviceRequest
);
244
IfxSrc_init
(src, config->
interrupt4
.
typeOfService
, config->
interrupt4
.
priority
);
245
IfxSrc_enable
(src);
246
}
247
248
timer->
timer
= config->
timer
;
249
timer->
trigger
= config->
trigger
;
250
251
#if IFX_CFG_USE_STANDARD_INTERFACE
252
IFX_ASSERT
(
IFX_VERBOSE_LEVEL_ERROR
, (
uint32
)timer == ((
uint32
)&timer->
base
));
253
timer->
base
.functions.start = (
Timer_Start
) &
IfxCcu6_Timer_start
;
254
timer->
base
.functions.stop = (
Timer_Stop
) &
IfxCcu6_Timer_stop
;
255
timer->
base
.functions.synchronousStart = (
Timer_SynchronousStart
) &
IfxCcu6_Timer_synchronousStart
;
256
timer->
base
.functions.synchronousStop = (
Timer_SynchronousStop
) &
IfxCcu6_Timer_synchronousStop
;
257
timer->
base
.functions.countOneStep = (
Timer_CountOneStep
) &
IfxCcu6_Timer_countOneStep
;
258
timer->
base
.functions.startSingleShotMode = (
Timer_StartSingleShotMode
) &
IfxCcu6_Timer_startSingleShotMode
;
259
#endif
260
}
261
262
263
void
IfxCcu6_Timer_initModuleConfig
(
IfxCcu6_Timer_Config
*config, Ifx_CCU6 *ccu6)
264
{
265
const
IfxCcu6_Timer_Config
defaultConfig = {
266
.
ccu6
=
NULL_PTR
,
// will be initialized below
267
268
.base.t12Frequency = 400000,
269
.base.t13Frequency = 400000,
270
.base.t12Period = 100,
271
.base.t13Period = 100,
272
.base.waitingTime = 20,
273
274
.timer =
IfxCcu6_TimerId_t13
,
275
.synchronousOperation =
FALSE
,
276
277
.pins =
NULL_PTR
,
278
279
.clock = {
280
.t12ExtClockEnabled =
FALSE
,
281
.t12ExtClockInput =
NULL_PTR
,
282
.t12countingInputMode =
IfxCcu6_CountingInputMode_internal
,
283
284
.t13ExtClockEnabled =
FALSE
,
285
.t13ExtClockInput =
NULL_PTR
,
286
.t13countingInputMode =
IfxCcu6_CountingInputMode_internal
,
287
},
288
289
.timer12 = {
290
.countMode =
IfxCcu6_T12CountMode_edgeAligned
,
291
.counterValue = 0,
292
},
293
294
.timer13 = {
295
.counterValue = 0,
296
.t12SyncEvent =
IfxCcu6_T13TriggerEvent_onCC60RCompare
,
297
.t12SyncDirection =
IfxCcu6_T13TriggerDirection_onT12CountingUp
,
298
},
299
300
.interrupt1 = {
301
.source =
IfxCcu6_InterruptSource_t12PeriodMatch
,
302
.serviceRequest =
IfxCcu6_ServiceRequest_0
,
303
.priority = 0,
// interrupt priority 0
304
.typeOfService =
IfxSrc_Tos_cpu0
,
// type of service CPU0
305
},
306
307
.interrupt2 = {
308
.source =
IfxCcu6_InterruptSource_t13PeriodMatch
,
309
.serviceRequest =
IfxCcu6_ServiceRequest_1
,
310
.priority = 0,
// interrupt priority 0
311
.typeOfService =
IfxSrc_Tos_cpu0
,
// type of service CPU0
312
},
313
314
.interrupt3 = {
315
.source =
IfxCcu6_InterruptSource_t12OneMatch
,
316
.serviceRequest =
IfxCcu6_ServiceRequest_2
,
317
.priority = 0,
// interrupt priority 0
318
.typeOfService =
IfxSrc_Tos_cpu0
,
// type of service CPU0
319
},
320
321
.interrupt4 = {
322
.source =
IfxCcu6_InterruptSource_trap
,
323
.serviceRequest =
IfxCcu6_ServiceRequest_3
,
324
.priority = 0,
// interrupt priority 0
325
.typeOfService =
IfxSrc_Tos_cpu0
,
// type of service CPU0
326
},
327
328
.trigger = {
329
.t12ExtInputTrigger =
NULL_PTR
,
330
.t13ExtInputTrigger =
NULL_PTR
,
331
.extInputTriggerMode =
IfxCcu6_ExternalTriggerMode_risingEdge
,
332
.t13InSyncWithT12 =
TRUE
,
333
},
334
};
335
336
/* Default Configuration */
337
*config = defaultConfig;
338
339
/* take over module pointer */
340
config->
ccu6
= ccu6;
341
}
342
343
344
void
IfxCcu6_Timer_start
(
IfxCcu6_Timer
*timer)
345
{
346
// Timer 13 start //
347
348
if
(timer->
timer
==
IfxCcu6_TimerId_t13
)
349
{
350
// enable shadow transfer
351
IfxCcu6_enableShadowTransfer
(timer->
ccu6
,
FALSE
,
TRUE
);
352
353
// start Timer 13 when not in sync with timer12
354
if
(!(timer->
trigger
.
t13InSyncWithT12
))
355
{
356
if
(timer->
trigger
.
t13ExtInputTrigger
!=
NULL_PTR
)
357
{
358
// external start
359
IfxCcu6_setExternalRunMode
(timer->
ccu6
,
IfxCcu6_TimerId_t13
, timer->
trigger
.
extInputTriggerMode
);
360
IfxCcu6_setT13InputSignal
(timer->
ccu6
, timer->
trigger
.
t13ExtInputTrigger
);
361
}
362
else
363
{
364
// internal start
365
IfxCcu6_startTimer
(timer->
ccu6
,
FALSE
,
TRUE
);
366
}
367
}
368
else
369
{}
370
}
371
else
372
{}
373
374
// Timer 12 start alone or when in sync with Timer 13 //
375
376
if
((timer->
timer
==
IfxCcu6_TimerId_t12
) || (timer->
trigger
.
t13InSyncWithT12
))
377
{
378
// enable shadow transfer
379
IfxCcu6_enableShadowTransfer
(timer->
ccu6
,
TRUE
,
FALSE
);
380
381
//start Timer 12
382
if
(timer->
trigger
.
t12ExtInputTrigger
!=
NULL_PTR
)
383
{
384
// external start
385
IfxCcu6_setExternalRunMode
(timer->
ccu6
,
IfxCcu6_TimerId_t12
, timer->
trigger
.
extInputTriggerMode
);
386
IfxCcu6_setT12InputSignal
(timer->
ccu6
, timer->
trigger
.
t12ExtInputTrigger
);
387
}
388
else
389
{
390
// internal start
391
IfxCcu6_startTimer
(timer->
ccu6
,
TRUE
,
FALSE
);
392
}
393
}
394
else
395
{}
396
}
397
398
399
void
IfxCcu6_Timer_startSingleShotMode
(
IfxCcu6_Timer
*timer)
400
{
401
// Timer 13 start //
402
403
if
(timer->
timer
==
IfxCcu6_TimerId_t13
)
404
{
405
// enable shadow transfer
406
IfxCcu6_enableShadowTransfer
(timer->
ccu6
,
FALSE
,
TRUE
);
407
408
//enable single shot mode
409
IfxCcu6_enableSingleShotMode
(timer->
ccu6
,
IfxCcu6_TimerId_t13
);
410
411
// start Timer 13 when not in sync with timer12
412
if
(!(timer->
trigger
.
t13InSyncWithT12
))
413
{
414
if
(timer->
trigger
.
t13ExtInputTrigger
!=
NULL_PTR
)
415
{
416
// external start
417
IfxCcu6_setExternalRunMode
(timer->
ccu6
,
IfxCcu6_TimerId_t13
, timer->
trigger
.
extInputTriggerMode
);
418
IfxCcu6_setT13InputSignal
(timer->
ccu6
, timer->
trigger
.
t13ExtInputTrigger
);
419
}
420
else
421
{
422
// internal start
423
IfxCcu6_startTimer
(timer->
ccu6
,
FALSE
,
TRUE
);
424
}
425
}
426
else
427
{}
428
}
429
else
430
{}
431
432
// Timer 12 start alone or when in sync with Timer 13 //
433
434
if
((timer->
timer
==
IfxCcu6_TimerId_t12
) || (timer->
trigger
.
t13InSyncWithT12
))
435
{
436
// enable shadow transfer
437
IfxCcu6_enableShadowTransfer
(timer->
ccu6
,
TRUE
,
FALSE
);
438
439
//enable single shot mode
440
IfxCcu6_enableSingleShotMode
(timer->
ccu6
,
IfxCcu6_TimerId_t12
);
441
442
if
(timer->
trigger
.
t12ExtInputTrigger
!=
NULL_PTR
)
443
{
444
// external start
445
IfxCcu6_setExternalRunMode
(timer->
ccu6
,
IfxCcu6_TimerId_t12
, timer->
trigger
.
extInputTriggerMode
);
446
IfxCcu6_setT12InputSignal
(timer->
ccu6
, timer->
trigger
.
t12ExtInputTrigger
);
447
}
448
else
449
{
450
// internal start
451
IfxCcu6_startTimer
(timer->
ccu6
,
TRUE
,
FALSE
);
452
}
453
}
454
else
455
{}
456
}
457
458
459
void
IfxCcu6_Timer_stop
(
IfxCcu6_Timer
*timer)
460
{
461
// Timer 13 stop //
462
463
if
((timer->
timer
==
IfxCcu6_TimerId_t13
) || (timer->
trigger
.
t13InSyncWithT12
))
464
{
465
// disable shadow transfer
466
IfxCcu6_disableShadowTransfer
(timer->
ccu6
,
FALSE
,
TRUE
);
467
468
// remove external input trigger if any
469
if
(timer->
trigger
.
t13ExtInputTrigger
!=
NULL_PTR
)
470
{
471
IfxCcu6_setExternalRunMode
(timer->
ccu6
,
IfxCcu6_TimerId_t13
,
IfxCcu6_ExternalTriggerMode_disable
);
472
}
473
474
// remove the sync with Timer 12
475
if
(timer->
trigger
.
t13InSyncWithT12
)
476
{
477
IfxCcu6_setT13TriggerEventMode
(timer->
ccu6
,
IfxCcu6_T13TriggerEvent_noAction
);
478
IfxCcu6_setT13TriggerEventDirection
(timer->
ccu6
,
IfxCcu6_T13TriggerDirection_noAction
);
479
}
480
481
// stop Timer 13
482
IfxCcu6_stopTimer
(timer->
ccu6
,
FALSE
,
TRUE
);
483
}
484
485
// Timer 12 stop //
486
487
else
488
{
489
// disable shadow transfer
490
IfxCcu6_disableShadowTransfer
(timer->
ccu6
,
TRUE
,
FALSE
);
491
492
// remove external input trigger if any
493
if
(timer->
trigger
.
t12ExtInputTrigger
!=
NULL_PTR
)
494
{
495
IfxCcu6_setExternalRunMode
(timer->
ccu6
,
IfxCcu6_TimerId_t12
,
IfxCcu6_ExternalTriggerMode_disable
);
496
}
497
498
// stop Timer 12
499
IfxCcu6_stopTimer
(timer->
ccu6
,
TRUE
,
FALSE
);
500
}
501
}
502
503
504
void
IfxCcu6_Timer_synchronousStart
(
IfxCcu6_Timer
*timer)
505
{
506
// enable shadow transfer
507
IfxCcu6_enableShadowTransfer
(timer->
ccu6
,
TRUE
,
TRUE
);
508
509
// only internal synchronous start is possible
510
IfxCcu6_startTimer
(timer->
ccu6
,
TRUE
,
TRUE
);
511
}
512
513
514
void
IfxCcu6_Timer_synchronousStop
(
IfxCcu6_Timer
*timer)
515
{
516
// disable shadow transfer
517
IfxCcu6_disableShadowTransfer
(timer->
ccu6
,
TRUE
,
TRUE
);
518
519
// only internal synchronous stop is possible
520
IfxCcu6_stopTimer
(timer->
ccu6
,
TRUE
,
TRUE
);
521
}
home
mclld
Libraries
release
iLLD_1_0_0_11_0
src
ifx
TC27xD
Ccu6
Timer
IfxCcu6_Timer.c
Generated by
1.8.4