iLLD_TC27xC  1.0
IfxPort.c
Go to the documentation of this file.
1 /**
2  * \file IfxPort.c
3  * \brief PORT basic functionality
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 /*----------------------------------Includes----------------------------------*/
27 /******************************************************************************/
28 
29 #include "IfxPort.h"
30 #include "Cpu/Std/IfxCpu.h"
31 #include "Scu/Std/IfxScuWdt.h"
32 
33 /******************************************************************************/
34 /*-------------------------Function Implementations---------------------------*/
35 /******************************************************************************/
36 
37 boolean IfxPort_disableEmergencyStop(Ifx_P *port, uint8 pinIndex)
38 {
39  sint32 portIndex;
40  boolean result = FALSE;
41 
42  for (portIndex = 0; portIndex < IFXPORT_COUNT; portIndex++)
43  {
44  if (port == IfxPort_cfg_esrMasks[portIndex].port)
45  {
46  if ((1U << pinIndex) & IfxPort_cfg_esrMasks[portIndex].masks)
47  {
48  IfxPort_resetESR(port, pinIndex);
49  result = TRUE;
50  }
51 
52  break;
53  }
54  }
55 
56  return result;
57 }
58 
59 
60 boolean IfxPort_enableEmergencyStop(Ifx_P *port, uint8 pinIndex)
61 {
62  sint32 portIndex;
63  boolean result = FALSE;
64 
65  for (portIndex = 0; portIndex < IFXPORT_COUNT; portIndex++)
66  {
67  if (port == IfxPort_cfg_esrMasks[portIndex].port)
68  {
69  if ((1U << pinIndex) & IfxPort_cfg_esrMasks[portIndex].masks)
70  {
71  IfxPort_setESR(port, pinIndex);
72  result = TRUE;
73  }
74  }
75  }
76 
77  return result;
78 }
79 
80 
82 {
83  sint32 result = -1, index;
84 
85  for (index = 0; index < IFXPORT_COUNT; index++)
86  {
87  if (IfxPort_cfg_indexMap[index].module == port)
88  {
89  result = IfxPort_cfg_indexMap[index].index;
90  break;
91  }
92  }
93 
94  return result;
95 }
96 
97 
98 void IfxPort_resetESR(Ifx_P *port, uint8 pinIndex)
99 {
101 
103  __ldmst(&port->ESR.U, 1U << pinIndex, 0);
104  IfxScuWdt_setCpuEndinit(passwd);
105 }
106 
107 
108 void IfxPort_setESR(Ifx_P *port, uint8 pinIndex)
109 {
111 
113  __ldmst(&port->ESR.U, 1U << pinIndex, 1U << pinIndex);
114  IfxScuWdt_setCpuEndinit(passwd);
115 }
116 
117 
118 void IfxPort_setGroupModeInput(Ifx_P *port, uint8 pinIndex, uint16 mask, IfxPort_InputMode mode)
119 {
120  uint32 i;
121  uint32 iocrVal[4];
122  uint32 iocrMask[4];
123 
124  /* initialise */
125  for (i = 0; i < 4; i++)
126  {
127  iocrVal[i] = 0;
128  iocrMask[i] = 0;
129  }
130 
131  /* calculate IOCRx values and masks */
132  uint32 imask = (uint32)mask << pinIndex;
133 
134  for (i = pinIndex; i < 16; i++)
135  {
136  if ((imask & (1U << i)) != 0)
137  {
138  uint32 index = i / 4;
139  uint32 shift = (i & 0x3U) * 8;
140  iocrMask[index] |= (0x1FU << 3) << shift;
141  iocrVal[index] |= (mode) << shift;
142  }
143  }
144 
145  /* write IOCRx */
146  for (i = 0; i < 4; i++)
147  {
148  if (iocrMask[i] != 0)
149  {
150  __ldmst(&((&(port->IOCR0.U))[i]), iocrMask[i], iocrVal[i]);
151  }
152  }
153 }
154 
155 
156 void IfxPort_setGroupModeOutput(Ifx_P *port, uint8 pinIndex, uint16 mask, IfxPort_OutputMode mode, IfxPort_OutputIdx index)
157 {
158  uint32 i;
159  uint32 iocrVal[4];
160  uint32 iocrMask[4];
161 
162  /* initialise */
163  for (i = 0; i < 4; i++)
164  {
165  iocrVal[i] = 0;
166  iocrMask[i] = 0;
167  }
168 
169  /* calculate IOCRx values and masks */
170  uint32 imask = (uint32)mask << pinIndex;
171 
172  for (i = pinIndex; i < 16; i++)
173  {
174  if ((imask & (1U << i)) != 0)
175  {
176  uint32 index = i / 4;
177  uint32 shift = (i & 0x3U) * 8;
178  iocrMask[index] |= (0x1FU << 3) << shift;
179  iocrVal[index] |= (mode | index) << shift;
180  }
181  }
182 
183  /* write IOCRx */
184  for (i = 0; i < 4; i++)
185  {
186  if (iocrMask[i] != 0)
187  {
188  __ldmst(&((&(port->IOCR0.U))[i]), iocrMask[i], iocrVal[i]);
189  }
190  }
191 }
192 
193 
194 void IfxPort_setGroupPadDriver(Ifx_P *port, uint8 pinIndex, uint16 mask, IfxPort_PadDriver padDriver)
195 {
197 
199  {
200  uint32 i;
201  uint32 pdrVal[2];
202  uint32 pdrMask[2];
203 
204  /* initialise */
205  for (i = 0; i < 2; i++)
206  {
207  pdrVal[i] = 0;
208  pdrMask[i] = 0;
209  }
210 
211  /* calculate PDRx values and masks */
212  uint32 imask = (uint32)mask << pinIndex;
213 
214  for (i = pinIndex; i < 16; i++)
215  {
216  if ((imask & (1U << i)) != 0)
217  {
218  uint32 index = i / 8;
219  uint32 shift = (i & 0x7U) * 4;
220  pdrMask[index] |= (0xFUL << shift);
221  pdrVal[index] |= (padDriver << shift);
222  }
223  }
224 
225  /* write PDRx */
226  for (i = 0; i < 2; i++)
227  {
228  if (pdrMask[i] != 0)
229  {
230  __ldmst(&((&(port->PDR0.U))[i]), pdrMask[i], pdrVal[i]);
231  }
232  }
233  }
234  IfxScuWdt_setCpuEndinit(passwd);
235 }
236 
237 
238 void IfxPort_setPinMode(Ifx_P *port, uint8 pinIndex, IfxPort_Mode mode)
239 {
240  volatile Ifx_P_IOCR0 *iocr = &(port->IOCR0);
241  uint8 iocrIndex = (pinIndex / 4);
242  uint8 shift = (pinIndex & 0x3U) * 8;
243 
244  __ldmst(&iocr[iocrIndex].U, (0xFFUL << shift), (mode << shift));
245 }
246 
247 
248 void IfxPort_setPinPadDriver(Ifx_P *port, uint8 pinIndex, IfxPort_PadDriver padDriver)
249 {
251 
253  {
254  volatile uint32 *pdr = (volatile uint32 *)&(port->PDR0.U);
255  uint8 pdrIndex = (pinIndex / 8);
256  uint8 shift = (pinIndex & 0x7U) * 4;
257  __ldmst(&(pdr[pdrIndex]), (0xFUL << shift), (padDriver << shift));
258  }
259  IfxScuWdt_setCpuEndinit(passwd);
260 }