iLLD_TC27xC
1.0
IfxCcu6_TPwm.c
Go to the documentation of this file.
1
/**
2
* \file IfxCcu6_TPwm.c
3
* \brief CCU6 TPWM 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_TPwm.h
"
31
32
/******************************************************************************/
33
/*-------------------------Function Implementations---------------------------*/
34
/******************************************************************************/
35
36
void
IfxCcu6_TPwm_initModule
(
IfxCcu6_TPwm
*tPwm,
const
IfxCcu6_TPwm_Config
*config)
37
{
38
Ifx_CCU6 *ccu6SFR = config->
ccu6
;
// pointer to CCU6 registers
39
tPwm->
ccu6
= ccu6SFR;
// adding register pointer to module handler
40
41
/* -- hardware module initialisation -- */
42
43
// enable module if it hasn't been enabled by any other interface //
44
if
(
IfxCcu6_isModuleEnabled
(ccu6SFR) ==
FALSE
)
45
{
46
IfxCcu6_enableModule
(ccu6SFR);
47
}
48
49
/* -- timer initialisation -- */
50
51
// Timer 13 initialisation //
52
53
if
(config->
timer
==
IfxCcu6_TimerId_t13
)
54
{
55
// enable Timer13 if it hasn't been enabled by any other interface //
56
if
(
IfxCcu6_getTimerAvailabilityStatus
(ccu6SFR,
IfxCcu6_TimerId_t13
) ==
FALSE
)
57
{
58
IfxCcu6_enableTimer
(ccu6SFR,
IfxCcu6_TimerId_t13
);
59
}
60
61
// clock initialisation //
62
63
if
(config->
clock
.
t13ExtClockEnabled
)
// if external source is selected as reference
64
{
65
// input signal selection
66
if
(config->
clock
.
t13ExtClockInput
!=
NULL_PTR
)
67
{
68
IfxCcu6_setT13InputSignal
(config->
ccu6
, config->
clock
.
t13ExtClockInput
);
69
}
70
71
// counting input mode selection
72
IfxCcu6_setCountingInputMode
(ccu6SFR,
IfxCcu6_TimerId_t13
, config->
clock
.
t13countingInputMode
);
73
74
// period setting
75
IfxCcu6_setT13PeriodValue
(ccu6SFR, config->
base
.
period
);
76
}
77
else
// if internal clock is selected as reference
78
{
79
IfxCcu6_setT13Frequency
(ccu6SFR, config->
base
.
frequency
, config->
base
.
period
);
80
}
81
82
// duty cycle initialisation //
83
84
IfxCcu6_setT13CounterValue
(ccu6SFR, config->
timer13
.
counterValue
);
85
86
IfxCcu6_setT13CompareValue
(ccu6SFR, config->
timer13
.
compareValue
);
87
88
// if Timer 13 start is in sync with Timer 12 //
89
if
(config->
trigger
.
t13InSyncWithT12
)
90
{
91
IfxCcu6_setT13TriggerEventMode
(ccu6SFR, config->
timer13
.
t12SyncEvent
);
92
IfxCcu6_setT13TriggerEventDirection
(ccu6SFR, config->
timer13
.
t12SyncDirection
);
93
}
94
}
95
else
96
{}
97
98
// Timer 12 initialisation //
99
100
if
((config->
timer
==
IfxCcu6_TimerId_t12
) || (config->
trigger
.
t13InSyncWithT12
))
101
{
102
Ifx_TimerValue
period = config->
base
.
period
;
103
Ifx_TimerValue
compareValue = config->
timer12
.
compareValue
;
104
105
// enable Timer12 if it hasn't been enabled by any other interface //
106
if
(
IfxCcu6_getTimerAvailabilityStatus
(ccu6SFR,
IfxCcu6_TimerId_t12
) ==
FALSE
)
107
{
108
IfxCcu6_enableTimer
(ccu6SFR,
IfxCcu6_TimerId_t12
);
109
}
110
111
// if Timer 13 start is in sync with Timer 12 //
112
if
((config->
trigger
.
t13InSyncWithT12
) && (config->
base
.
waitingTime
!= 0))
113
{
114
// if in sync with T12 period match
115
if
(config->
timer13
.
t12SyncEvent
==
IfxCcu6_T13TriggerEvent_onT12Period
)
116
{
117
period = config->
base
.
waitingTime
;
// waiting time as period
118
}
119
else
if
(config->
timer13
.
t12SyncEvent
!=
IfxCcu6_T13TriggerEvent_noAction
)
120
{
121
compareValue = config->
base
.
waitingTime
;
// waiting time as compare value
122
period = config->
base
.
activeCount
;
123
}
124
}
125
else
126
{
127
// configuration error
128
}
129
130
// clock initialisation //
131
132
if
(config->
clock
.
t12ExtClockEnabled
)
// if external source is selected as reference
133
{
134
// input signal selection
135
if
(config->
clock
.
t12ExtClockInput
!=
NULL_PTR
)
136
{
137
IfxCcu6_setT12InputSignal
(config->
ccu6
, config->
clock
.
t12ExtClockInput
);
138
}
139
140
// counting input mode selection
141
IfxCcu6_setCountingInputMode
(ccu6SFR,
IfxCcu6_TimerId_t12
, config->
clock
.
t12countingInputMode
);
142
143
// countining mode selection
144
IfxCcu6_setT12CountMode
(ccu6SFR, config->
timer12
.
countMode
);
145
146
// period selection for center aligned mode
147
if
(config->
timer12
.
countMode
==
IfxCcu6_T12CountMode_centerAligned
)
148
{
149
period = (period / 2) - 1;
150
}
151
152
// period setting
153
IfxCcu6_setT12PeriodValue
(ccu6SFR, period);
154
}
155
else
// if internal clock is selected as reference
156
{
157
// in case of in sync with T13 T12 runs at same frequency as T13
158
IfxCcu6_setT12Frequency
(ccu6SFR, config->
base
.
frequency
, period, config->
timer12
.
countMode
);
159
}
160
161
// duty cycle initialisation //
162
163
IfxCcu6_setT12CounterValue
(ccu6SFR, config->
timer12
.
counterValue
);
164
165
IfxCcu6_setT12ChannelMode
(ccu6SFR, config->
timer12
.
channelId
, config->
timer12
.
channelMode
);
166
167
IfxCcu6_setT12CompareValue
(ccu6SFR, config->
timer12
.
channelId
, compareValue);
168
169
// dead time injection if selected
170
if
(config->
timer12
.
deadTimeValue
)
171
{
172
IfxCcu6_setDeadTimeValue
(ccu6SFR, config->
timer12
.
deadTimeValue
);
173
IfxCcu6_enableDeadTime
(ccu6SFR, config->
timer12
.
channelId
);
174
}
175
}
176
else
177
{}
178
179
/* -- output path initialisation -- */
180
181
//enable modulation output path //
182
IfxCcu6_enableModulationOutput
(ccu6SFR, config->
timer
, config->
channelOut
);
183
184
// output passive logic configuration //
185
//TODO check correct polarity:
186
IfxCcu6_setOutputPassiveState
(ccu6SFR, config->
channelOut
, config->
base
.
activeState
);
187
188
/* -- Pin mapping -- */
189
190
const
IfxCcu6_TPwm_Pins
*pins = config->
pins
;
191
192
if
(pins !=
NULL_PTR
)
193
{
194
IfxCcu6_Cc60_Out
*cc60Out = pins->
cc60Out
;
195
196
if
(cc60Out !=
NULL_PTR
)
197
{
198
IfxCcu6_initCc60OutPin
(cc60Out, pins->
outputMode
, pins->
pinDriver
);
199
}
200
201
IfxCcu6_Cc61_Out
*cc61Out = pins->
cc61Out
;
202
203
if
(cc61Out !=
NULL_PTR
)
204
{
205
IfxCcu6_initCc61OutPin
(cc61Out, pins->
outputMode
, pins->
pinDriver
);
206
}
207
208
IfxCcu6_Cc62_Out
*cc62Out = pins->
cc62Out
;
209
210
if
(cc62Out !=
NULL_PTR
)
211
{
212
IfxCcu6_initCc62OutPin
(cc62Out, pins->
outputMode
, pins->
pinDriver
);
213
}
214
215
IfxCcu6_Cout60_Out
*cout60 = pins->
cout60
;
216
217
if
(cout60 !=
NULL_PTR
)
218
{
219
IfxCcu6_initCout60Pin
(cout60, pins->
outputMode
, pins->
pinDriver
);
220
}
221
222
IfxCcu6_Cout61_Out
*cout61 = pins->
cout61
;
223
224
if
(cout61 !=
NULL_PTR
)
225
{
226
IfxCcu6_initCout61Pin
(cout61, pins->
outputMode
, pins->
pinDriver
);
227
}
228
229
IfxCcu6_Cout62_Out
*cout62 = pins->
cout62
;
230
231
if
(cout62 !=
NULL_PTR
)
232
{
233
IfxCcu6_initCout62Pin
(cout62, pins->
outputMode
, pins->
pinDriver
);
234
}
235
236
IfxCcu6_Cout63_Out
*cout63 = pins->
cout63
;
237
238
if
(cout63 !=
NULL_PTR
)
239
{
240
IfxCcu6_initCout63Pin
(cout63, pins->
outputMode
, pins->
pinDriver
);
241
}
242
243
IfxCcu6_T12hr_In
*t12hr = pins->
t12hr
;
244
245
if
(t12hr !=
NULL_PTR
)
246
{
247
IfxCcu6_initT12hrPin
(t12hr, pins->
t1xhrInputMode
);
248
}
249
250
IfxCcu6_T13hr_In
*t13hr = pins->
t13hr
;
251
252
if
(t13hr !=
NULL_PTR
)
253
{
254
IfxCcu6_initT13hrPin
(t13hr, pins->
t1xhrInputMode
);
255
}
256
}
257
258
/* -- interrupt initialisation -- */
259
260
IfxCcu6_enableInterrupt
(ccu6SFR, config->
interrupt
.
interruptSource
);
261
IfxCcu6_routeInterruptNode
(ccu6SFR, config->
interrupt
.
interruptSource
, config->
interrupt
.
serviceRequest
);
262
263
if
(config->
interrupt
.
priority
> 0)
264
{
265
volatile
Ifx_SRC_SRCR *src;
266
src =
IfxCcu6_getSrcAddress
(ccu6SFR, config->
interrupt
.
serviceRequest
);
267
IfxSrc_init
(src, config->
interrupt
.
typeOfService
, config->
interrupt
.
priority
);
268
IfxSrc_enable
(src);
269
}
270
271
/* -- output trigger initialisation --*/
272
273
if
(config->
trigger
.
outputTriggerEnabled
)
274
{
275
IfxCcu6_connectTrigger
(ccu6SFR, config->
trigger
.
outputLine
, config->
trigger
.
outputTrigger
);
276
}
277
278
tPwm->
timer
= config->
timer
;
279
tPwm->
channelOut
= config->
channelOut
;
280
tPwm->
trigger
= config->
trigger
;
281
282
#if IFX_CFG_USE_STANDARD_INTERFACE
283
IFX_ASSERT
(
IFX_VERBOSE_LEVEL_ERROR
, (
uint32
)tPwm == ((
uint32
)&tPwm->
base
));
284
tPwm->
base
.functions.start = (
TPwm_Start
) &
IfxCcu6_TPwm_start
;
285
tPwm->
base
.functions.pause = (
TPwm_Pause
) &
IfxCcu6_TPwm_pause
;
286
tPwm->
base
.functions.resume = (
TPwm_Resume
) &
IfxCcu6_TPwm_resume
;
287
tPwm->
base
.functions.stop = (
TPwm_Stop
) &
IfxCcu6_TPwm_stop
;
288
#endif
289
}
290
291
292
void
IfxCcu6_TPwm_initModuleConfig
(
IfxCcu6_TPwm_Config
*config, Ifx_CCU6 *ccu6)
293
{
294
const
IfxCcu6_TPwm_Config
defaultConfig = {
295
.
ccu6
=
NULL_PTR
,
// will be initialized below
296
297
.base.frequency = 400000,
298
.base.period = 100,
299
.base.waitingTime = 20,
300
.base.activeState =
Ifx_ActiveState_high
,
301
302
.timer =
IfxCcu6_TimerId_t13
,
303
304
.clock = {
305
.t12ExtClockEnabled =
FALSE
,
306
.t12ExtClockInput =
NULL_PTR
,
307
.t12countingInputMode =
IfxCcu6_CountingInputMode_internal
,
308
309
.t13ExtClockEnabled =
FALSE
,
310
.t13ExtClockInput =
NULL_PTR
,
311
.t13countingInputMode =
IfxCcu6_CountingInputMode_internal
,
312
},
313
314
.timer12 = {
315
.channelId =
IfxCcu6_T12Channel_0
,
316
.channelMode =
IfxCcu6_T12ChannelMode_compareMode
,
317
.countMode =
IfxCcu6_T12CountMode_edgeAligned
,
318
.counterValue = 0,
319
.deadTimeValue = 0,
320
.compareValue = 0,
321
},
322
323
.timer13 = {
324
.counterValue = 0,
325
.compareValue = 0,
326
.t12SyncEvent =
IfxCcu6_T13TriggerEvent_onCC60RCompare
,
327
.t12SyncDirection =
IfxCcu6_T13TriggerDirection_onT12CountingUp
,
328
},
329
330
.channelOut =
IfxCcu6_ChannelOut_cout3
,
331
332
.pins =
NULL_PTR
,
333
334
.interrupt = {
335
.interruptSource =
IfxCcu6_InterruptSource_t13CompareMatch
,
336
.serviceRequest =
IfxCcu6_ServiceRequest_sR2
,
337
.priority = 0,
// interrupt priority 0
338
.typeOfService =
IfxSrc_Tos_cpu0
,
// type of service CPU0
339
},
340
341
.trigger = {
342
.t12ExtInputTrigger =
NULL_PTR
,
343
.t13ExtInputTrigger =
NULL_PTR
,
344
.extInputTriggerMode =
IfxCcu6_ExternalTriggerMode_risingEdge
,
345
.t13InSyncWithT12 =
TRUE
,
346
347
.outputTriggerEnabled =
TRUE
,
348
.outputLine =
IfxCcu6_TrigOut_0
,
349
.outputTrigger =
IfxCcu6_TrigSel_cout63
,
350
},
351
};
352
353
/* Default Configuration */
354
*config = defaultConfig;
355
356
/* take over module pointer */
357
config->
ccu6
= ccu6;
358
}
359
360
361
void
IfxCcu6_TPwm_pause
(
IfxCcu6_TPwm
*tPwm)
362
{
363
IfxCcu6_disableModulationOutput
(tPwm->
ccu6
, tPwm->
timer
, tPwm->
channelOut
);
364
}
365
366
367
void
IfxCcu6_TPwm_resume
(
IfxCcu6_TPwm
*tPwm)
368
{
369
IfxCcu6_enableModulationOutput
(tPwm->
ccu6
, tPwm->
timer
, tPwm->
channelOut
);
370
}
371
372
373
void
IfxCcu6_TPwm_start
(
IfxCcu6_TPwm
*tPwm)
374
{
375
// Timer 13 modulation //
376
377
if
(tPwm->
timer
==
IfxCcu6_TimerId_t13
)
378
{
379
// enable shadow transfer
380
IfxCcu6_enableShadowTransfer
(tPwm->
ccu6
,
FALSE
,
TRUE
);
381
382
// start Timer 13 when not in sync with Timer 12
383
if
(!(tPwm->
trigger
.
t13InSyncWithT12
))
384
{
385
if
(tPwm->
trigger
.
t13ExtInputTrigger
!=
NULL_PTR
)
386
{
387
// external start
388
IfxCcu6_setExternalRunMode
(tPwm->
ccu6
,
IfxCcu6_TimerId_t13
, tPwm->
trigger
.
extInputTriggerMode
);
389
IfxCcu6_setT13InputSignal
(tPwm->
ccu6
, tPwm->
trigger
.
t13ExtInputTrigger
);
390
}
391
else
392
{
393
// internal start
394
IfxCcu6_startTimer
(tPwm->
ccu6
,
FALSE
,
TRUE
);
395
}
396
}
397
else
398
{}
399
}
400
else
401
{}
402
403
// Timer 12 alone for modulation or when in sync with Timer 13 //
404
405
if
((tPwm->
timer
==
IfxCcu6_TimerId_t12
) || (tPwm->
trigger
.
t13InSyncWithT12
))
406
{
407
// enable shadow transfer
408
IfxCcu6_enableShadowTransfer
(tPwm->
ccu6
,
TRUE
,
FALSE
);
409
410
//start Timer 12
411
if
(tPwm->
trigger
.
t12ExtInputTrigger
!=
NULL_PTR
)
412
{
413
// external start
414
IfxCcu6_setExternalRunMode
(tPwm->
ccu6
,
IfxCcu6_TimerId_t12
, tPwm->
trigger
.
extInputTriggerMode
);
415
IfxCcu6_setT12InputSignal
(tPwm->
ccu6
, tPwm->
trigger
.
t12ExtInputTrigger
);
416
}
417
else
418
{
419
// internal start
420
IfxCcu6_startTimer
(tPwm->
ccu6
,
TRUE
,
FALSE
);
421
}
422
}
423
else
424
{}
425
}
426
427
428
void
IfxCcu6_TPwm_stop
(
IfxCcu6_TPwm
*tPwm)
429
{
430
// Timer 13 modulation //
431
432
if
((tPwm->
timer
==
IfxCcu6_TimerId_t13
) || (tPwm->
trigger
.
t13InSyncWithT12
))
433
{
434
// disable shadow transfer
435
IfxCcu6_disableShadowTransfer
(tPwm->
ccu6
,
FALSE
,
TRUE
);
436
437
// remove external input trigger if any
438
if
(tPwm->
trigger
.
t13ExtInputTrigger
!=
NULL_PTR
)
439
{
440
IfxCcu6_setExternalRunMode
(tPwm->
ccu6
,
IfxCcu6_TimerId_t13
,
IfxCcu6_ExternalTriggerMode_disable
);
441
}
442
443
// remove the sync with Timer 12
444
if
(tPwm->
trigger
.
t13InSyncWithT12
)
445
{
446
IfxCcu6_setT13TriggerEventMode
(tPwm->
ccu6
,
IfxCcu6_T13TriggerEvent_noAction
);
447
IfxCcu6_setT13TriggerEventDirection
(tPwm->
ccu6
,
IfxCcu6_T13TriggerDirection_noAction
);
448
}
449
450
// stop Timer 13
451
IfxCcu6_stopTimer
(tPwm->
ccu6
,
FALSE
,
TRUE
);
452
}
453
454
// Timer 12 modulation //
455
456
else
457
{
458
// disable shadow transfer
459
IfxCcu6_disableShadowTransfer
(tPwm->
ccu6
,
TRUE
,
FALSE
);
460
461
// remove external input trigger if any
462
if
(tPwm->
trigger
.
t12ExtInputTrigger
!=
NULL_PTR
)
463
{
464
IfxCcu6_setExternalRunMode
(tPwm->
ccu6
,
IfxCcu6_TimerId_t12
,
IfxCcu6_ExternalTriggerMode_disable
);
465
}
466
467
// stop Timer 12
468
IfxCcu6_stopTimer
(tPwm->
ccu6
,
TRUE
,
FALSE
);
469
}
470
471
// disable the modulation
472
IfxCcu6_disableModulationOutput
(tPwm->
ccu6
, tPwm->
timer
, tPwm->
channelOut
);
473
}
home
mclld
Libraries
release
iLLD_0_1_0_10
src
ifx
TC27xC
Ccu6
TPwm
IfxCcu6_TPwm.c
Generated by
1.8.4