You are on page 1of 11

10/19/22, 4:30 PM AURIX_code_examples/IfxPort.

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 / Port / Std / IfxPort.c

MatteoVitturi
December 2020 release - total of 174 code examples


1
contributor

521 lines (405 sloc)



12.8 KB

1 /**
2 * \file IfxPort.c
3 * \brief PORT basic functionality
4 *
5 * \version iLLD_1_0_1_12_0
6 * \copyright Copyright (c) 2019 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/P… 1/11
10/19/22, 4:30 PM AURIX_code_examples/IfxPort.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 /*----------------------------------Includes----------------------------------*/
44 /******************************************************************************/
45
46 #include "IfxPort.h"
47
48 /******************************************************************************/
49 /*-------------------------Function Implementations---------------------------*/
50 /******************************************************************************/
51
52 boolean IfxPort_disableEmergencyStop(Ifx_P *port, uint8 pinIndex)
53 {
54 sint32 portIndex;
55 boolean result = FALSE;
56
57 for (portIndex = 0; portIndex < IFXPORT_NUM_MODULES; portIndex++)
58 {
59 if (port == IfxPort_cfg_esrMasks[portIndex].port)
60 {
61 if ((1U << pinIndex) & IfxPort_cfg_esrMasks[portIndex].masks)
62 {
63 IfxPort_resetESR(port, pinIndex);
64 result = TRUE;
65 }
66
67 break;
68 }
69 }
70
71 return result;
72 }
73
74
75 boolean IfxPort_enableEmergencyStop(Ifx_P *port, uint8 pinIndex)
76 {
77 sint32 portIndex;
78 boolean result = FALSE;
79
80 for (portIndex = 0; portIndex < IFXPORT_NUM_MODULES; portIndex++)
81 {

82 if (port == IfxPort_cfg_esrMasks[portIndex].port)
83 {

https://github.com/Infineon/AURIX_code_examples/blob/master/code_examples/Blinky_LED_1_KIT_TC375_SB/Libraries/iLLD/TC37A/Tricore/P… 2/11
10/19/22, 4:30 PM AURIX_code_examples/IfxPort.c at master · Infineon/AURIX_code_examples · GitHub
84 if ((1U << pinIndex) & IfxPort_cfg_esrMasks[portIndex].masks)
85 {
86 IfxPort_setESR(port, pinIndex);
87 result = TRUE;
88 }
89 }
90 }
91
92 return result;
93 }
94
95
96 Ifx_P *IfxPort_getAddress(IfxPort_Index port)
97 {
98 Ifx_P *module = NULL_PTR;
99 uint8 i = 0;
100
101 while ((i < IFXPORT_NUM_MODULES) && (module == NULL_PTR))
102 {
103 if (IfxPort_cfg_indexMap[i].index == port)
104 {
105 module = IfxPort_cfg_indexMap[i].module;
106 }
107
108 i++;
109 }
110
111 return module;
112 }
113
114
115 IfxPort_Index IfxPort_getIndex(Ifx_P *port)
116 {
117 uint32 index;
118 IfxPort_Index result;
119
120 result = IfxPort_Index_none;
121
122 for (index = 0; index < IFXPORT_NUM_MODULES; index++)
123 {
124 if (IfxPort_cfg_indexMap[index].module == port)
125 {
126 result = (IfxPort_Index)IfxPort_cfg_indexMap[index].index;
127 break;
128 }
129 }
130
131 return result;
132 }
133

134
135 void IfxPort_resetESR(Ifx_P *port, uint8 pinIndex)

https://github.com/Infineon/AURIX_code_examples/blob/master/code_examples/Blinky_LED_1_KIT_TC375_SB/Libraries/iLLD/TC37A/Tricore/P… 3/11
10/19/22, 4:30 PM AURIX_code_examples/IfxPort.c at master · Infineon/AURIX_code_examples · GitHub
136 {
137 uint16 passwd = IfxScuWdt_getCpuWatchdogPassword();
138
139 IfxScuWdt_clearCpuEndinit(passwd);
140 __ldmst(&port->ESR.U, 1U << pinIndex, 0);
141 IfxScuWdt_setCpuEndinit(passwd);
142 }
143
144
145 void IfxPort_setESR(Ifx_P *port, uint8 pinIndex)
146 {
147 uint16 passwd = IfxScuWdt_getCpuWatchdogPassword();
148
149 IfxScuWdt_clearCpuEndinit(passwd);
150 __ldmst(&port->ESR.U, 1U << pinIndex, 1U << pinIndex);
151 IfxScuWdt_setCpuEndinit(passwd);
152 }
153
154
155 void IfxPort_setGroupModeInput(Ifx_P *port, uint8 pinIndex, uint16 mask, IfxPort_InputMode mode
156 {
157 uint32 i;
158 uint32 iocrVal[4];
159 uint32 iocrMask[4];
160
161 /* initialise */
162 for (i = 0; i < 4; i++)
163 {
164 iocrVal[i] = 0;
165 iocrMask[i] = 0;
166 }
167
168 /* calculate IOCRx values and masks */
169 uint32 imask = (uint32)mask << pinIndex;
170
171 for (i = pinIndex; i < 16; i++)
172 {
173 if ((imask & (1U << i)) != 0)
174 {
175 uint32 index = i / 4;
176 uint32 shift = (i & 0x3U) * 8;
177 iocrMask[index] |= (0x1FU << 3) << shift;
178 iocrVal[index] |= (mode) << shift;
179 }
180 }
181
182 /* write IOCRx */
183 for (i = 0; i < 4; i++)
184 {
185 if (iocrMask[i] != 0)

186 {
187 __ldmst(&((&(port->IOCR0.U))[i]), iocrMask[i], iocrVal[i]);

https://github.com/Infineon/AURIX_code_examples/blob/master/code_examples/Blinky_LED_1_KIT_TC375_SB/Libraries/iLLD/TC37A/Tricore/P… 4/11
10/19/22, 4:30 PM AURIX_code_examples/IfxPort.c at master · Infineon/AURIX_code_examples · GitHub
188 }
189 }
190 }
191
192
193 void IfxPort_setGroupModeOutput(Ifx_P *port, uint8 pinIndex, uint16 mask, IfxPort_OutputMode mo
194 {
195 uint32 i;
196 uint32 iocrVal[4];
197 uint32 iocrMask[4];
198
199 IFX_UNUSED_PARAMETER(index == IfxPort_OutputIdx_general);
200
201 /* initialise */
202 for (i = 0; i < 4; i++)
203 {
204 iocrVal[i] = 0;
205 iocrMask[i] = 0;
206 }
207
208 /* calculate IOCRx values and masks */
209 uint32 imask = (uint32)mask << pinIndex;
210
211 for (i = pinIndex; i < 16; i++)
212 {
213 if ((imask & (1U << i)) != 0)
214 {
215 uint32 index = i / 4;
216 uint32 shift = (i & 0x3U) * 8;
217 iocrMask[index] |= (0x1FU << 3) << shift;
218 iocrVal[index] |= (mode | index) << shift;
219 }
220 }
221
222 /* write IOCRx */
223 for (i = 0; i < 4; i++)
224 {
225 if (iocrMask[i] != 0)
226 {
227 __ldmst(&((&(port->IOCR0.U))[i]), iocrMask[i], iocrVal[i]);
228 }
229 }
230 }
231
232
233 void IfxPort_setGroupPadDriver(Ifx_P *port, uint8 pinIndex, uint16 mask, IfxPort_PadDriver padD
234 {
235 uint16 passwd = IfxScuWdt_getCpuWatchdogPassword();
236
237 IfxScuWdt_clearCpuEndinit(passwd);

238 {
239 uint32 i;

https://github.com/Infineon/AURIX_code_examples/blob/master/code_examples/Blinky_LED_1_KIT_TC375_SB/Libraries/iLLD/TC37A/Tricore/P… 5/11
10/19/22, 4:30 PM AURIX_code_examples/IfxPort.c at master · Infineon/AURIX_code_examples · GitHub
240 uint32 pdrVal[2];
241 uint32 pdrMask[2];
242
243 /* initialise */
244 for (i = 0; i < 2; i++)
245 {
246 pdrVal[i] = 0;
247 pdrMask[i] = 0;
248 }
249
250 /* calculate PDRx values and masks */
251 uint32 imask = (uint32)mask << pinIndex;
252
253 for (i = pinIndex; i < 16; i++)
254 {
255 if ((imask & (1U << i)) != 0)
256 {
257 uint32 index = i / 8;
258 uint32 shift = (i & 0x7U) * 4;
259 pdrMask[index] |= (0xFUL << shift);
260 pdrVal[index] |= (padDriver << shift);
261 }
262 }
263
264 /* write PDRx */
265 for (i = 0; i < 2; i++)
266 {
267 if (pdrMask[i] != 0)
268 {
269 __ldmst(&((&(port->PDR0.U))[i]), pdrMask[i], pdrVal[i]);
270 }
271 }
272 }
273 IfxScuWdt_setCpuEndinit(passwd);
274 }
275
276
277 void IfxPort_setPinMode(Ifx_P *port, uint8 pinIndex, IfxPort_Mode mode)
278 {
279 volatile Ifx_P_IOCR0 *iocr = &(port->IOCR0);
280 uint8 iocrIndex = (pinIndex / 4);
281 uint8 shift = (pinIndex & 0x3U) * 8;
282
283 if (port == &MODULE_P40)
284 {
285 uint16 passwd = IfxScuWdt_getCpuWatchdogPassword();
286 IfxScuWdt_clearCpuEndinit(passwd);
287 port->PDISC.U &= ~(1 << pinIndex);
288 IfxScuWdt_setCpuEndinit(passwd);
289 }

290
291 __ldmst(&iocr[iocrIndex].U, (0xFFUL << shift), (mode << shift));

https://github.com/Infineon/AURIX_code_examples/blob/master/code_examples/Blinky_LED_1_KIT_TC375_SB/Libraries/iLLD/TC37A/Tricore/P… 6/11
10/19/22, 4:30 PM AURIX_code_examples/IfxPort.c at master · Infineon/AURIX_code_examples · GitHub
292 }
293
294
295 void IfxPort_setPinModeLVDS(Ifx_P *port, uint8 pinIndex, IfxPort_Mode pinMode, IfxPort_LvdsConf
296 {
297 uint32 lpcrOffset = (pinIndex / 2);
298
299 volatile Ifx_P_LPCR *lpcr = &(port->LPCR[0]);
300 uint16 passwd = IfxScuWdt_getCpuWatchdogPassword();
301
302 IfxScuWdt_clearCpuEndinit(passwd);
303 lpcr[lpcrOffset].B.LVDSM = lvds->lvdsMode;
304 lpcr[lpcrOffset].B.PS = lvds->padSupply;
305
306 if (pinMode < IfxPort_Mode_outputPushPullGeneral)
307 {
308 lpcr[lpcrOffset].B.REN_CTRL = lvds->enablePortControlled;
309 lpcr[lpcrOffset].B.RX_EN = 1;
310 }
311 else
312 {
313 lpcr[lpcrOffset].B.TEN_CTRL = lvds->enablePortControlled;
314 lpcr[lpcrOffset].B.TX_EN = 1;
315 lpcr[lpcrOffset].B.TX_PD = 0;
316 }
317
318 IfxScuWdt_setCpuEndinit(passwd);
319 }
320
321
322 void IfxPort_setPinPadDriver(Ifx_P *port, uint8 pinIndex, IfxPort_PadDriver padDriver)
323 {
324 uint16 passwd = IfxScuWdt_getCpuWatchdogPassword();
325
326 IfxScuWdt_clearCpuEndinit(passwd);
327 {
328 volatile uint32 *pdr = (volatile uint32 *)&(port->PDR0.U);
329 uint8 pdrIndex = (pinIndex / 8);
330 uint8 shift = (pinIndex & 0x7U) * 4;
331 __ldmst(&(pdr[pdrIndex]), (0xFUL << shift), (padDriver << shift));
332 }
333 IfxScuWdt_setCpuEndinit(passwd);
334 }
335
336
337 void IfxPort_setPinControllerSelection(Ifx_P *port, uint8 pinIndex)
338 {
339 boolean select = 0, lock = 0;
340 IfxPort_Index portIndex = IfxPort_getIndex(port);
341

342 switch (portIndex)


343 {

https://github.com/Infineon/AURIX_code_examples/blob/master/code_examples/Blinky_LED_1_KIT_TC375_SB/Libraries/iLLD/TC37A/Tricore/P… 7/11
10/19/22, 4:30 PM AURIX_code_examples/IfxPort.c at master · Infineon/AURIX_code_examples · GitHub
344 case IfxPort_Index_00:
345
346 if ((pinIndex == 10) || (pinIndex == 11))
347
348 {
349 select = 1;
350 }
351
352 break;
353
354 case IfxPort_Index_11:
355
356 if ((pinIndex == 0) || (pinIndex == 1) || (pinIndex == 2) || (pinIndex == 3) || (pinInd
357 {
358 select = 1;
359 }
360
361 break;
362
363 case IfxPort_Index_22:
364
365 if ((pinIndex == 10) || (pinIndex == 11))
366 {
367 select = 1;
368 }
369
370 break;
371
372 case IfxPort_Index_23:
373
374 if ((pinIndex == 2) || (pinIndex == 3) || (pinIndex == 4))
375
376 {
377 select = 1;
378 }
379
380 break;
381
382 case IfxPort_Index_33:
383
384 select = 1;
385 lock = 1;
386 break;
387 case IfxPort_Index_34:
388
389 if (pinIndex == 1)
390 {
391 select = 1;
392 lock = 1;
393 }

394
395 break;

https://github.com/Infineon/AURIX_code_examples/blob/master/code_examples/Blinky_LED_1_KIT_TC375_SB/Libraries/iLLD/TC37A/Tricore/P… 8/11
10/19/22, 4:30 PM AURIX_code_examples/IfxPort.c at master · Infineon/AURIX_code_examples · GitHub
396
397 case IfxPort_Index_40:
398
399 if ((pinIndex == 1) || (pinIndex == 2) || (pinIndex == 3) || (pinIndex == 5) || (pinInd
400 {
401 select = 1;
402 }
403
404 break;
405
406 default:
407 break;
408 }
409
410 if (select == 1)
411 {
412 uint16 passwd = IfxScuWdt_getSafetyWatchdogPassword();
413
414 IfxScuWdt_clearSafetyEndinit(passwd);
415
416 if ((lock == 1) && (port->PCSR.B.LCK == 1))
417 {
418 IFX_ASSERT(IFX_VERBOSE_LEVEL_WARNING, FALSE);
419 }
420
421 __ldmst(&port->PCSR.U, 1U << pinIndex, 1U << pinIndex);
422
423 IfxScuWdt_setSafetyEndinit(passwd);
424 }
425 }
426
427
428 void IfxPort_resetPinControllerSelection(Ifx_P *port, uint8 pinIndex)
429 {
430 uint16 passwd = IfxScuWdt_getSafetyWatchdogPassword();
431
432 IfxScuWdt_clearSafetyEndinit(passwd);
433 __ldmst(&port->PCSR.U, 1U << pinIndex, 0);
434 IfxScuWdt_setSafetyEndinit(passwd);
435 }
436
437
438 void IfxPort_modifyPinControllerSelection(Ifx_P *port, uint8 pinIndex, boolean mode)
439 {
440 boolean select = 0, lock = 0;
441 IfxPort_Index portIndex = IfxPort_getIndex(port);
442
443 switch (portIndex)
444 {
445 case IfxPort_Index_00:

446
447 if ((pinIndex == 10) || (pinIndex == 11))

https://github.com/Infineon/AURIX_code_examples/blob/master/code_examples/Blinky_LED_1_KIT_TC375_SB/Libraries/iLLD/TC37A/Tricore/P… 9/11
10/19/22, 4:30 PM AURIX_code_examples/IfxPort.c at master · Infineon/AURIX_code_examples · GitHub
448 {
449 select = 1;
450 }
451
452 break;
453
454 case IfxPort_Index_11:
455
456 if ((pinIndex == 0) || (pinIndex == 1) || (pinIndex == 2) || (pinIndex == 3) || (pinInd
457 {
458 select = 1;
459 }
460
461 break;
462
463 case IfxPort_Index_22:
464
465 if ((pinIndex == 10) || (pinIndex == 11) || (pinIndex == 12))
466 {
467 select = 1;
468 }
469
470 break;
471 case IfxPort_Index_23:
472
473 if ((pinIndex == 2) || (pinIndex == 3) || (pinIndex == 4))
474 {
475 select = 1;
476 }
477
478 break;
479
480 case IfxPort_Index_33:
481
482 select = 1;
483 lock = 1;
484 break;
485 case IfxPort_Index_34:
486
487 if (pinIndex == 1)
488 {
489 select = 1;
490 lock = 1;
491 }
492
493 break;
494 case IfxPort_Index_40:
495
496 if ((pinIndex == 1) || (pinIndex == 2) || (pinIndex == 3) || (pinIndex == 5) || (pinInd
497 {

498 select = 1;
499 }

https://github.com/Infineon/AURIX_code_examples/blob/master/code_examples/Blinky_LED_1_KIT_TC375_SB/Libraries/iLLD/TC37A/Tricore/… 10/11
10/19/22, 4:30 PM AURIX_code_examples/IfxPort.c at master · Infineon/AURIX_code_examples · GitHub
500
501 break;
502 default:
503 break;
504 }
505
506 if (select == 1)
507 {
508 uint16 passwd = IfxScuWdt_getSafetyWatchdogPassword();
509
510 IfxScuWdt_clearSafetyEndinit(passwd);
511
512 if ((lock == 1) && (port->PCSR.B.LCK == 1))
513 {
514 IFX_ASSERT(IFX_VERBOSE_LEVEL_WARNING, FALSE);
515 }
516
517 __ldmst(&port->PCSR.U, 1U << pinIndex, mode << pinIndex);
518
519 IfxScuWdt_setSafetyEndinit(passwd);
520 }
521 }

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

You might also like