You are on page 1of 8

10/19/22, 4:34 PM AURIX_code_examples/IfxCcu6_Icu.

c at master · Infineon/AURIX_code_examples · GitHub

Infineon / AURIX_code_examples Public

Code Pull requests Actions Projects Security Insights


master

AURIX_code_examples / code_examples / Blinky_LED_1_KIT_TC375_SB / Libraries / iLLD /


TC37A / Tricore / Ccu6 / Icu / IfxCcu6_Icu.c

MatteoVitturi
December 2020 release - total of 174 code examples


1
contributor

346 lines (269 sloc)



13.2 KB

1 /**
2 * \file IfxCcu6_Icu.c
3 * \brief CCU6 ICU details
4 *
5 * \version iLLD_1_0_1_12_0
6 * \copyright Copyright (c) 2018 Infineon Technologies AG. All rights reserved.
7 *
8 *
9 * IMPORTANT NOTICE
10 *
11 * Use of this file is subject to the terms of use agreed between (i) you or
12 * the company in which ordinary course of business you are acting and (ii)
13 * Infineon Technologies AG or its licensees. If and as long as no such terms
14 * of use are agreed, use of this file is subject to following:
15 *
16 * Boost Software License - Version 1.0 - August 17th, 2003
17 *
18 * Permission is hereby granted, free of charge, to any person or organization
19 * obtaining a copy of the software and accompanying documentation covered by
20 * this license (the "Software") to use, reproduce, display, distribute,
21 * execute, and transmit the Software, and to prepare derivative works of the
22 * Software, and to permit third-parties to whom the Software is furnished to
23 * do so, all subject to the following:
24 *
25 * The copyright notices in the Software and this entire statement, including
26 * the above license grant, this restriction and the following disclaimer, must
27 * be included in all copies of the Software, in whole or in part, and all
28 * derivative works of the Software, unless such copies or derivative works are
29 * solely in the form of machine-executable object code generated by a source

30 * language processor.
31 *

https://github.com/Infineon/AURIX_code_examples/blob/master/code_examples/Blinky_LED_1_KIT_TC375_SB/Libraries/iLLD/TC37A/Tricore/Cc… 1/8
10/19/22, 4:34 PM AURIX_code_examples/IfxCcu6_Icu.c at master · Infineon/AURIX_code_examples · GitHub
32 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
33 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
34 * FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
35 * SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
36 * FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
37 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
38 * DEALINGS IN THE SOFTWARE.
39 *
40 *
41 */
42
43 /******************************************************************************/
44 /*----------------------------------Includes----------------------------------*/
45 /******************************************************************************/
46
47 #include "IfxCcu6_Icu.h"
48
49 /******************************************************************************/
50 /*-------------------------Function Implementations---------------------------*/
51 /******************************************************************************/
52
53 uint32 IfxCcu6_Icu_getTimeStamp(IfxCcu6_Icu_Channel *channel)
54 {
55 uint32 timeStamp = 0;
56
57 timeStamp = IfxCcu6_getCaptureShadowRegisterValue(channel->ccu6, channel->channelId);
58
59 return timeStamp;
60 }
61
62
63 void IfxCcu6_Icu_initChannel(IfxCcu6_Icu_Channel *channel, const IfxCcu6_Icu_ChannelConfig *cha
64 {
65 channel->ccu6 = channelConfig->ccu6;
66
67 /* -- capture input initialisation -- */
68
69 const IfxCcu6_Icu_Pins *pins = channelConfig->pins;
70
71 if (pins != NULL_PTR)
72 {
73 IfxCcu6_Cc60in_In *cc60In = pins->cc60In;
74
75 if (cc60In != NULL_PTR)
76 {
77 IfxCcu6_initCc60InPinWithPadLevel(cc60In, pins->cc6xInputMode, pins->pinDriver);
78 }
79
80 IfxCcu6_Cc61in_In *cc61In = pins->cc61In;
81

82 if (cc61In != NULL_PTR)
83 {

https://github.com/Infineon/AURIX_code_examples/blob/master/code_examples/Blinky_LED_1_KIT_TC375_SB/Libraries/iLLD/TC37A/Tricore/Cc… 2/8
10/19/22, 4:34 PM AURIX_code_examples/IfxCcu6_Icu.c at master · Infineon/AURIX_code_examples · GitHub
84 IfxCcu6_initCc61InPinWithPadLevel(cc61In, pins->cc6xInputMode, pins->pinDriver);
85 }
86
87 IfxCcu6_Cc62in_In *cc62In = pins->cc62In;
88
89 if (cc62In != NULL_PTR)
90 {
91 IfxCcu6_initCc62InPinWithPadLevel(cc62In, pins->cc6xInputMode, pins->pinDriver);
92 }
93
94 if (channelConfig->multiInputCaptureEnabled)
95 {
96 IfxCcu6_Ccpos0_In *ccpos0 = pins->ccpos0;
97
98 if (ccpos0 != NULL_PTR)
99 {
100 IfxCcu6_initCcpos0PinWithPadLevel(ccpos0, pins->ccposxInputMode, pins->pinDrive
101 }
102
103 IfxCcu6_Ccpos1_In *ccpos1 = pins->ccpos1;
104
105 if (ccpos1 != NULL_PTR)
106 {
107 IfxCcu6_initCcpos1PinWithPadLevel(ccpos1, pins->ccposxInputMode, pins->pinDrive
108 }
109
110 IfxCcu6_Ccpos2_In *ccpos2 = pins->ccpos2;
111
112 if (ccpos2 != NULL_PTR)
113 {
114 IfxCcu6_initCcpos2PinWithPadLevel(ccpos2, pins->ccposxInputMode, pins->pinDrive
115 }
116 }
117
118 IfxCcu6_T12hr_In *t12hr = pins->t12hr;
119
120 if (t12hr != NULL_PTR)
121 {
122 IfxCcu6_initT12hrPinWithPadLevel(t12hr, pins->t1xhrInputMode, pins->pinDriver);
123 }
124
125 IfxCcu6_T13hr_In *t13hr = pins->t13hr;
126
127 if (t13hr != NULL_PTR)
128 {
129 IfxCcu6_initT13hrPinWithPadLevel(t13hr, pins->t1xhrInputMode, pins->pinDriver);
130 }
131 }
132
133 /* -- interrupt initialisation -- */

134
135 if (channelConfig->interrupt1.priority > 0)

https://github.com/Infineon/AURIX_code_examples/blob/master/code_examples/Blinky_LED_1_KIT_TC375_SB/Libraries/iLLD/TC37A/Tricore/Cc… 3/8
10/19/22, 4:34 PM AURIX_code_examples/IfxCcu6_Icu.c at master · Infineon/AURIX_code_examples · GitHub
136 {
137 IfxCcu6_enableInterrupt(channelConfig->ccu6, channelConfig->interrupt1.source);
138 IfxCcu6_routeInterruptNode(channelConfig->ccu6, channelConfig->interrupt1.source, chann
139
140 volatile Ifx_SRC_SRCR *src;
141 src = IfxCcu6_getSrcAddress(channelConfig->ccu6, channelConfig->interrupt1.serviceReque
142 IfxSrc_init(src, channelConfig->interrupt1.typeOfService, channelConfig->interrupt1.pri
143 IfxSrc_enable(src);
144 }
145
146 if (channelConfig->interrupt2.priority > 0)
147 {
148 IfxCcu6_enableInterrupt(channelConfig->ccu6, channelConfig->interrupt2.source);
149 IfxCcu6_routeInterruptNode(channelConfig->ccu6, channelConfig->interrupt2.source, chann
150
151 volatile Ifx_SRC_SRCR *src;
152 src = IfxCcu6_getSrcAddress(channelConfig->ccu6, channelConfig->interrupt2.serviceReque
153 IfxSrc_init(src, channelConfig->interrupt2.typeOfService, channelConfig->interrupt2.pri
154 IfxSrc_enable(src);
155 }
156
157 if (channelConfig->interrupt3.priority > 0)
158 {
159 IfxCcu6_enableInterrupt(channelConfig->ccu6, channelConfig->interrupt3.source);
160 IfxCcu6_routeInterruptNode(channelConfig->ccu6, channelConfig->interrupt3.source, chann
161
162 volatile Ifx_SRC_SRCR *src;
163 src = IfxCcu6_getSrcAddress(channelConfig->ccu6, channelConfig->interrupt3.serviceReque
164 IfxSrc_init(src, channelConfig->interrupt3.typeOfService, channelConfig->interrupt3.pri
165 IfxSrc_enable(src);
166 }
167
168 if (channelConfig->interrupt4.priority > 0)
169 {
170 IfxCcu6_enableInterrupt(channelConfig->ccu6, channelConfig->interrupt4.source);
171 IfxCcu6_routeInterruptNode(channelConfig->ccu6, channelConfig->interrupt4.source, chann
172
173 volatile Ifx_SRC_SRCR *src;
174 src = IfxCcu6_getSrcAddress(channelConfig->ccu6, channelConfig->interrupt4.serviceReque
175 IfxSrc_init(src, channelConfig->interrupt4.typeOfService, channelConfig->interrupt4.pri
176 IfxSrc_enable(src);
177 }
178
179 channel->trigger = channelConfig->trigger;
180 channel->channelId = channelConfig->channelId;
181 channel->channelMode = channelConfig->channelMode;
182
183 #if IFX_CFG_USE_STANDARD_INTERFACE
184 IFX_ASSERT(IFX_VERBOSE_LEVEL_ERROR, (uint32)icu == ((uint32)&icu->base));
185 icu->base.functions.startCapture = (Icu_StartCapture) & IfxCcu6_Icu_startCapture;

186 icu->base.functions.stopCapture = (Icu_StopCapture) & IfxCcu6_Icu_stopCapture;


187 icu->base.functions.getTimeStamp = (Icu_GetTimeStamp) & IfxCcu6_Icu_getTimeStamp;

https://github.com/Infineon/AURIX_code_examples/blob/master/code_examples/Blinky_LED_1_KIT_TC375_SB/Libraries/iLLD/TC37A/Tricore/Cc… 4/8
10/19/22, 4:34 PM AURIX_code_examples/IfxCcu6_Icu.c at master · Infineon/AURIX_code_examples · GitHub
188 #endif
189 }
190
191
192 void IfxCcu6_Icu_initChannelConfig(IfxCcu6_Icu_ChannelConfig *channelConfig, Ifx_CCU6 *ccu6)
193 {
194 channelConfig->ccu6 = ccu6;
195
196 channelConfig->channelId = IfxCcu6_T12Channel_0;
197 channelConfig->channelMode = IfxCcu6_T12ChannelMode_doubleRegisterCaptureRi
198
199 channelConfig->interrupt1.source = IfxCcu6_InterruptSource_cc60RisingEdge;
200 channelConfig->interrupt1.serviceRequest = IfxCcu6_ServiceRequest_0;
201 channelConfig->interrupt1.priority = 0; // interrupt priority 0
202 channelConfig->interrupt1.typeOfService = IfxSrc_Tos_cpu0; // type of service CPU0
203
204 channelConfig->interrupt2.source = IfxCcu6_InterruptSource_cc60FallingEdge;
205 channelConfig->interrupt2.serviceRequest = IfxCcu6_ServiceRequest_1;
206 channelConfig->interrupt2.priority = 0; // interrupt priority 0
207 channelConfig->interrupt2.typeOfService = IfxSrc_Tos_cpu0; // type of service CPU0
208
209 channelConfig->interrupt3.source = IfxCcu6_InterruptSource_cc61RisingEdge;
210 channelConfig->interrupt3.serviceRequest = IfxCcu6_ServiceRequest_2;
211 channelConfig->interrupt3.priority = 0; // interrupt priority 0
212 channelConfig->interrupt3.typeOfService = IfxSrc_Tos_cpu0; // type of service CPU0
213
214 channelConfig->interrupt4.source = IfxCcu6_InterruptSource_trap;
215 channelConfig->interrupt4.serviceRequest = IfxCcu6_ServiceRequest_3;
216 channelConfig->interrupt4.priority = 0; // interrupt priority 0
217 channelConfig->interrupt4.typeOfService = IfxSrc_Tos_cpu0; // type of service CPU0
218
219 channelConfig->trigger.extInputTrigger = channelConfig->timer.trigger.t12ExtInputTrigge
220 channelConfig->trigger.extInputTriggerMode = channelConfig->timer.trigger.extInputTriggerMo
221
222 channelConfig->pins = NULL_PTR;
223
224 channelConfig->multiInputCaptureEnabled = FALSE;
225 }
226
227
228 void IfxCcu6_Icu_initModule(IfxCcu6_Icu *icu, const IfxCcu6_Icu_Config *config)
229 {
230 Ifx_CCU6 *ccu6SFR = config->ccu6; // pointer to CCU6 registers
231 icu->ccu6 = ccu6SFR; // adding register pointer to module handler
232
233 /* -- hardware module initialisation -- */
234
235 // enable module if it hasn't been enabled by any other interface //
236 if (IfxCcu6_isModuleEnabled(ccu6SFR) == FALSE)
237 {

238 IfxCcu6_enableModule(ccu6SFR);
239 }

https://github.com/Infineon/AURIX_code_examples/blob/master/code_examples/Blinky_LED_1_KIT_TC375_SB/Libraries/iLLD/TC37A/Tricore/Cc… 5/8
10/19/22, 4:34 PM AURIX_code_examples/IfxCcu6_Icu.c at master · Infineon/AURIX_code_examples · GitHub
240
241 /* -- timer initialisation -- */
242
243 // enable Timer12 if it hasn't been enabled by any other interface //
244 if (IfxCcu6_getTimerAvailabilityStatus(ccu6SFR, IfxCcu6_TimerId_t12) == FALSE)
245 {
246 IfxCcu6_enableTimer(ccu6SFR, IfxCcu6_TimerId_t12);
247 }
248
249 // clock initialization //
250
251 Ifx_TimerValue period = config->period;
252
253 if (config->clock.extClockEnabled) // if external source is selected as reference
254 {
255 // input signal selection
256 if (config->clock.extClockInput != NULL_PTR)
257 {
258 IfxCcu6_setT12InputSignal(config->ccu6, config->clock.extClockInput);
259 }
260
261 // counting input mode selection
262 IfxCcu6_setCountingInputMode(ccu6SFR, IfxCcu6_TimerId_t12, config->clock.countingInputM
263
264 // countining mode selection
265 IfxCcu6_setT12CountMode(ccu6SFR, config->countMode);
266
267 // period selection for center aligned mode
268 if (config->countMode == IfxCcu6_T12CountMode_centerAligned)
269 {
270 period = (period / 2) - 1;
271 }
272
273 // period setting
274 IfxCcu6_setT12PeriodValue(ccu6SFR, (uint16)period);
275
276 // frequency is meaningless here : set to 0
277 icu->captureFrequency = 0;
278 }
279 else // if internal clock is selected as reference
280 {
281 // in case of in sync with T13, T12 runs at same frequency as T13
282 icu->captureFrequency = IfxCcu6_setT12Frequency(ccu6SFR, config->frequency, period, con
283 }
284
285 // counter initialisation //
286
287 IfxCcu6_setT12CounterValue(ccu6SFR, config->counterValue);
288 }
289

290
291 void IfxCcu6_Icu_initModuleConfig(IfxCcu6_Icu_Config *config, Ifx_CCU6 *ccu6)

https://github.com/Infineon/AURIX_code_examples/blob/master/code_examples/Blinky_LED_1_KIT_TC375_SB/Libraries/iLLD/TC37A/Tricore/Cc… 6/8
10/19/22, 4:34 PM AURIX_code_examples/IfxCcu6_Icu.c at master · Infineon/AURIX_code_examples · GitHub
292 {
293 config->ccu6 = ccu6;
294
295 config->frequency = 400000;
296 config->period = 0xFFFE; /* max(uint16) - 1 */
297
298 config->clock.extClockEnabled = FALSE;
299 config->clock.extClockInput = NULL_PTR;
300 config->clock.countingInputMode = IfxCcu6_CountingInputMode_internal;
301
302 config->countMode = IfxCcu6_T12CountMode_edgeAligned;
303 config->counterValue = 0;
304 }
305
306
307 void IfxCcu6_Icu_startCapture(IfxCcu6_Icu_Channel *channel)
308 {
309 if (IfxCcu6_getTimerRunStatus(channel->ccu6, IfxCcu6_TimerId_t12) != IfxCcu6_TimerRunStatus
310 {
311 // enable shadow transfer
312 IfxCcu6_enableShadowTransfer(channel->ccu6, TRUE, FALSE);
313
314 // start the timer
315 if (channel->trigger.extInputTrigger != NULL_PTR)
316 {
317 // external input setting
318 IfxCcu6_setExternalRunMode(channel->ccu6, IfxCcu6_TimerId_t12, channel->trigger.ext
319 IfxCcu6_setT12InputSignal(channel->ccu6, channel->trigger.extInputTrigger);
320 }
321 else
322 {
323 // internal start
324 IfxCcu6_startTimer(channel->ccu6, TRUE, FALSE);
325 }
326 }
327
328 // enable capture mode
329 IfxCcu6_setT12ChannelMode(channel->ccu6, channel->channelId, channel->channelMode);
330 }
331
332
333 void IfxCcu6_Icu_stopCapture(IfxCcu6_Icu_Channel *channel)
334 {
335 // disable shadow transfer
336 IfxCcu6_disableShadowTransfer(channel->ccu6, TRUE, FALSE);
337
338 // disable capture mode
339 IfxCcu6_setT12ChannelMode(channel->ccu6, channel->channelId, IfxCcu6_T12ChannelMode_off);
340
341 // remove the external input

342 IfxCcu6_setExternalRunMode(channel->ccu6, IfxCcu6_TimerId_t12, IfxCcu6_ExternalTriggerMode_


343

https://github.com/Infineon/AURIX_code_examples/blob/master/code_examples/Blinky_LED_1_KIT_TC375_SB/Libraries/iLLD/TC37A/Tricore/Cc… 7/8
10/19/22, 4:34 PM AURIX_code_examples/IfxCcu6_Icu.c at master · Infineon/AURIX_code_examples · GitHub
344 // stop the timer
345 IfxCcu6_stopTimer(channel->ccu6, TRUE, FALSE);
346 }

https://github.com/Infineon/AURIX_code_examples/blob/master/code_examples/Blinky_LED_1_KIT_TC375_SB/Libraries/iLLD/TC37A/Tricore/Cc… 8/8

You might also like