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