iLLD_TC27xD
1.0
IfxCcu6_Icu.c
Go to the documentation of this file.
1
/**
2
* \file IfxCcu6_Icu.c
3
* \brief CCU6 ICU 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_Icu.h
"
31
32
/******************************************************************************/
33
/*-------------------------Function Implementations---------------------------*/
34
/******************************************************************************/
35
36
uint32
IfxCcu6_Icu_getTimeStamp
(
IfxCcu6_Icu_Channel
*channel)
37
{
38
uint32
timeStamp = 0;
39
40
timeStamp =
IfxCcu6_getCaptureShadowRegisterValue
(channel->
ccu6
, channel->
channelId
);
41
42
return
timeStamp;
43
}
44
45
46
void
IfxCcu6_Icu_initChannel
(
IfxCcu6_Icu_Channel
*channel,
const
IfxCcu6_Icu_ChannelConfig
*channelConfig)
47
{
48
channel->
ccu6
= channelConfig->
ccu6
;
49
50
/* -- capture input initialisation -- */
51
52
const
IfxCcu6_Icu_Pins
*pins = channelConfig->
pins
;
53
54
if
(pins !=
NULL_PTR
)
55
{
56
IfxCcu6_Cc60in_In
*cc60In = pins->
cc60In
;
57
58
if
(cc60In !=
NULL_PTR
)
59
{
60
IfxCcu6_initCc60InPin
(cc60In, pins->
cc6xInputMode
);
61
}
62
63
IfxCcu6_Cc61in_In
*cc61In = pins->
cc61In
;
64
65
if
(cc61In !=
NULL_PTR
)
66
{
67
IfxCcu6_initCc61InPin
(cc61In, pins->
cc6xInputMode
);
68
}
69
70
IfxCcu6_Cc62in_In
*cc62In = pins->
cc62In
;
71
72
if
(cc62In !=
NULL_PTR
)
73
{
74
IfxCcu6_initCc62InPin
(cc62In, pins->
cc6xInputMode
);
75
}
76
77
if
(channelConfig->
multiInputCaptureEnabled
)
78
{
79
IfxCcu6_Ccpos0_In
*ccpos0 = pins->
ccpos0
;
80
81
if
(ccpos0 !=
NULL_PTR
)
82
{
83
IfxCcu6_initCcpos0Pin
(ccpos0, pins->
ccposxInputMode
);
84
}
85
86
IfxCcu6_Ccpos1_In
*ccpos1 = pins->
ccpos1
;
87
88
if
(ccpos1 !=
NULL_PTR
)
89
{
90
IfxCcu6_initCcpos1Pin
(ccpos1, pins->
ccposxInputMode
);
91
}
92
93
IfxCcu6_Ccpos2_In
*ccpos2 = pins->
ccpos2
;
94
95
if
(ccpos2 !=
NULL_PTR
)
96
{
97
IfxCcu6_initCcpos2Pin
(ccpos2, pins->
ccposxInputMode
);
98
}
99
}
100
101
IfxCcu6_T12hr_In
*t12hr = pins->
t12hr
;
102
103
if
(t12hr !=
NULL_PTR
)
104
{
105
IfxCcu6_initT12hrPin
(t12hr, pins->
t1xhrInputMode
);
106
}
107
108
IfxCcu6_T13hr_In
*t13hr = pins->
t13hr
;
109
110
if
(t13hr !=
NULL_PTR
)
111
{
112
IfxCcu6_initT13hrPin
(t13hr, pins->
t1xhrInputMode
);
113
}
114
}
115
116
/* -- interrupt initialisation -- */
117
118
if
(channelConfig->
interrupt1
.
priority
> 0)
119
{
120
IfxCcu6_enableInterrupt
(channelConfig->
ccu6
, channelConfig->
interrupt1
.
source
);
121
IfxCcu6_routeInterruptNode
(channelConfig->
ccu6
, channelConfig->
interrupt1
.
source
, channelConfig->
interrupt1
.
serviceRequest
);
122
123
volatile
Ifx_SRC_SRCR *src;
124
src =
IfxCcu6_getSrcAddress
(channelConfig->
ccu6
, channelConfig->
interrupt1
.
serviceRequest
);
125
IfxSrc_init
(src, channelConfig->
interrupt1
.
typeOfService
, channelConfig->
interrupt1
.
priority
);
126
IfxSrc_enable
(src);
127
}
128
129
if
(channelConfig->
interrupt2
.
priority
> 0)
130
{
131
IfxCcu6_enableInterrupt
(channelConfig->
ccu6
, channelConfig->
interrupt2
.
source
);
132
IfxCcu6_routeInterruptNode
(channelConfig->
ccu6
, channelConfig->
interrupt2
.
source
, channelConfig->
interrupt2
.
serviceRequest
);
133
134
volatile
Ifx_SRC_SRCR *src;
135
src =
IfxCcu6_getSrcAddress
(channelConfig->
ccu6
, channelConfig->
interrupt2
.
serviceRequest
);
136
IfxSrc_init
(src, channelConfig->
interrupt2
.
typeOfService
, channelConfig->
interrupt2
.
priority
);
137
IfxSrc_enable
(src);
138
}
139
140
if
(channelConfig->
interrupt3
.
priority
> 0)
141
{
142
IfxCcu6_enableInterrupt
(channelConfig->
ccu6
, channelConfig->
interrupt3
.
source
);
143
IfxCcu6_routeInterruptNode
(channelConfig->
ccu6
, channelConfig->
interrupt3
.
source
, channelConfig->
interrupt3
.
serviceRequest
);
144
145
volatile
Ifx_SRC_SRCR *src;
146
src =
IfxCcu6_getSrcAddress
(channelConfig->
ccu6
, channelConfig->
interrupt3
.
serviceRequest
);
147
IfxSrc_init
(src, channelConfig->
interrupt3
.
typeOfService
, channelConfig->
interrupt3
.
priority
);
148
IfxSrc_enable
(src);
149
}
150
151
if
(channelConfig->
interrupt4
.
priority
> 0)
152
{
153
IfxCcu6_enableInterrupt
(channelConfig->
ccu6
, channelConfig->
interrupt4
.
source
);
154
IfxCcu6_routeInterruptNode
(channelConfig->
ccu6
, channelConfig->
interrupt4
.
source
, channelConfig->
interrupt4
.
serviceRequest
);
155
156
volatile
Ifx_SRC_SRCR *src;
157
src =
IfxCcu6_getSrcAddress
(channelConfig->
ccu6
, channelConfig->
interrupt4
.
serviceRequest
);
158
IfxSrc_init
(src, channelConfig->
interrupt4
.
typeOfService
, channelConfig->
interrupt4
.
priority
);
159
IfxSrc_enable
(src);
160
}
161
162
channel->
trigger
= channelConfig->
trigger
;
163
channel->
channelId
= channelConfig->
channelId
;
164
channel->
channelMode
= channelConfig->
channelMode
;
165
166
#if IFX_CFG_USE_STANDARD_INTERFACE
167
IFX_ASSERT
(
IFX_VERBOSE_LEVEL_ERROR
, (
uint32
)icu == ((
uint32
)&icu->base));
168
icu->base.functions.startCapture = (
Icu_StartCapture
) &
IfxCcu6_Icu_startCapture
;
169
icu->base.functions.stopCapture = (
Icu_StopCapture
) &
IfxCcu6_Icu_stopCapture
;
170
icu->base.functions.getTimeStamp = (
Icu_GetTimeStamp
) &
IfxCcu6_Icu_getTimeStamp
;
171
#endif
172
}
173
174
175
void
IfxCcu6_Icu_initChannelConfig
(
IfxCcu6_Icu_ChannelConfig
*channelConfig, Ifx_CCU6 *ccu6)
176
{
177
channelConfig->
ccu6
= ccu6;
178
179
channelConfig->
channelId
=
IfxCcu6_T12Channel_0
;
// default channel 0
180
channelConfig->
channelMode
=
IfxCcu6_T12ChannelMode_doubleRegisterCaptureRising
;
// default CC6xIN rising edge
181
182
channelConfig->
interrupt1
.
source
=
IfxCcu6_InterruptSource_cc60RisingEdge
;
183
channelConfig->
interrupt1
.
serviceRequest
=
IfxCcu6_ServiceRequest_0
;
184
channelConfig->
interrupt1
.
priority
= 0;
// interrupt priority 0
185
channelConfig->
interrupt1
.
typeOfService
=
IfxSrc_Tos_cpu0
;
// type of service CPU0
186
187
channelConfig->
interrupt2
.
source
=
IfxCcu6_InterruptSource_cc60FallingEdge
;
188
channelConfig->
interrupt2
.
serviceRequest
=
IfxCcu6_ServiceRequest_1
;
189
channelConfig->
interrupt2
.
priority
= 0;
// interrupt priority 0
190
channelConfig->
interrupt2
.
typeOfService
=
IfxSrc_Tos_cpu0
;
// type of service CPU0
191
192
channelConfig->
interrupt3
.
source
=
IfxCcu6_InterruptSource_cc61RisingEdge
;
193
channelConfig->
interrupt3
.
serviceRequest
=
IfxCcu6_ServiceRequest_2
;
194
channelConfig->
interrupt3
.
priority
= 0;
// interrupt priority 0
195
channelConfig->
interrupt3
.
typeOfService
=
IfxSrc_Tos_cpu0
;
// type of service CPU0
196
197
channelConfig->
interrupt4
.
source
=
IfxCcu6_InterruptSource_trap
;
198
channelConfig->
interrupt4
.
serviceRequest
=
IfxCcu6_ServiceRequest_3
;
199
channelConfig->
interrupt4
.
priority
= 0;
// interrupt priority 0
200
channelConfig->
interrupt4
.
typeOfService
=
IfxSrc_Tos_cpu0
;
// type of service CPU0
201
202
channelConfig->
trigger
.
extInputTrigger
= channelConfig->
timer
.
trigger
.
t12ExtInputTrigger
;
203
channelConfig->
trigger
.
extInputTriggerMode
= channelConfig->
timer
.
trigger
.
extInputTriggerMode
;
204
205
channelConfig->
pins
=
NULL_PTR
;
206
207
channelConfig->
multiInputCaptureEnabled
=
FALSE
;
208
}
209
210
211
void
IfxCcu6_Icu_initModule
(
IfxCcu6_Icu
*icu,
const
IfxCcu6_Icu_Config
*config)
212
{
213
Ifx_CCU6 *ccu6SFR = config->
ccu6
;
// pointer to CCU6 registers
214
icu->
ccu6
= ccu6SFR;
// adding register pointer to module handler
215
216
/* -- hardware module initialisation -- */
217
218
// enable module if it hasn't been enabled by any other interface //
219
if
(
IfxCcu6_isModuleEnabled
(ccu6SFR) ==
FALSE
)
220
{
221
IfxCcu6_enableModule
(ccu6SFR);
222
}
223
224
/* -- timer initialisation -- */
225
226
// enable Timer12 if it hasn't been enabled by any other interface //
227
if
(
IfxCcu6_getTimerAvailabilityStatus
(ccu6SFR,
IfxCcu6_TimerId_t12
) ==
FALSE
)
228
{
229
IfxCcu6_enableTimer
(ccu6SFR,
IfxCcu6_TimerId_t12
);
230
}
231
232
// clock initialisation //
233
234
Ifx_TimerValue
period = config->
period
;
235
236
if
(config->
clock
.
extClockEnabled
)
// if external source is selected as reference
237
{
238
// input signal selection
239
if
(config->
clock
.
extClockInput
!=
NULL_PTR
)
240
{
241
IfxCcu6_setT12InputSignal
(config->
ccu6
, config->
clock
.
extClockInput
);
242
}
243
244
// counting input mode selection
245
IfxCcu6_setCountingInputMode
(ccu6SFR,
IfxCcu6_TimerId_t12
, config->
clock
.
countingInputMode
);
246
247
// countining mode selection
248
IfxCcu6_setT12CountMode
(ccu6SFR, config->
countMode
);
249
250
// period selection for center aligned mode
251
if
(config->
countMode
==
IfxCcu6_T12CountMode_centerAligned
)
252
{
253
period = (period / 2) - 1;
254
}
255
256
// period setting
257
IfxCcu6_setT12PeriodValue
(ccu6SFR, (
uint16
)period);
258
}
259
else
// if internal clock is selected as reference
260
{
261
// in case of in sync with T13, T12 runs at same frequency as T13
262
IfxCcu6_setT12Frequency
(ccu6SFR, config->
frequency
, period, config->
countMode
);
263
}
264
265
// counter initialisation //
266
267
IfxCcu6_setT12CounterValue
(ccu6SFR, config->
counterValue
);
268
}
269
270
271
void
IfxCcu6_Icu_initModuleConfig
(
IfxCcu6_Icu_Config
*config, Ifx_CCU6 *ccu6)
272
{
273
config->
ccu6
= ccu6;
274
275
config->
frequency
= 400000;
276
config->
period
= 100;
277
278
config->
clock
.
extClockEnabled
=
FALSE
;
279
config->
clock
.
extClockInput
=
NULL_PTR
;
280
config->
clock
.
countingInputMode
=
IfxCcu6_CountingInputMode_internal
;
281
282
config->
countMode
=
IfxCcu6_T12CountMode_edgeAligned
;
283
config->
counterValue
= 0;
284
}
285
286
287
void
IfxCcu6_Icu_startCapture
(
IfxCcu6_Icu_Channel
*channel)
288
{
289
if
(
IfxCcu6_getTimerRunStatus
(channel->
ccu6
,
IfxCcu6_TimerId_t12
) !=
IfxCcu6_TimerRunStatus_running
)
290
{
291
// enable shadow transfer
292
IfxCcu6_enableShadowTransfer
(channel->
ccu6
,
TRUE
,
FALSE
);
293
294
// start the timer
295
if
(channel->
trigger
.
extInputTrigger
!=
NULL_PTR
)
296
{
297
// external input setting
298
IfxCcu6_setExternalRunMode
(channel->
ccu6
,
IfxCcu6_TimerId_t12
, channel->
trigger
.
extInputTriggerMode
);
299
IfxCcu6_setT12InputSignal
(channel->
ccu6
, channel->
trigger
.
extInputTrigger
);
300
}
301
else
302
{
303
// internal start
304
IfxCcu6_startTimer
(channel->
ccu6
,
TRUE
,
FALSE
);
305
}
306
}
307
308
// enable capture mode
309
IfxCcu6_setT12ChannelMode
(channel->
ccu6
, channel->
channelId
, channel->
channelMode
);
310
}
311
312
313
void
IfxCcu6_Icu_stopCapture
(
IfxCcu6_Icu_Channel
*channel)
314
{
315
// disable shadow transfer
316
IfxCcu6_disableShadowTransfer
(channel->
ccu6
,
TRUE
,
FALSE
);
317
318
// disable capture mode
319
IfxCcu6_setT12ChannelMode
(channel->
ccu6
, channel->
channelId
,
IfxCcu6_T12ChannelMode_off
);
320
321
// remove the external input
322
IfxCcu6_setExternalRunMode
(channel->
ccu6
,
IfxCcu6_TimerId_t12
,
IfxCcu6_ExternalTriggerMode_disable
);
323
324
// stop the timer
325
IfxCcu6_stopTimer
(channel->
ccu6
,
TRUE
,
FALSE
);
326
}
home
mclld
Libraries
release
iLLD_1_0_0_11_0
src
ifx
TC27xD
Ccu6
Icu
IfxCcu6_Icu.c
Generated by
1.8.4