iLLD_TC27xD  1.0
IfxEray.c
Go to the documentation of this file.
1 /**
2  * \file IfxEray.c
3  * \brief ERAY basic functionality
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 /*----------------------------------Includes----------------------------------*/
27 /******************************************************************************/
28 
29 #include "IfxEray.h"
30 
31 /******************************************************************************/
32 /*-------------------------Function Implementations---------------------------*/
33 /******************************************************************************/
34 
35 uint16 IfxEray_calcHeaderCrc(uint8 payloadLength, uint16 frameId, boolean startupFrameIndicator, boolean syncFrameIndicator)
36 {
37  uint32 headerValue = ((syncFrameIndicator & 0x1) << 19) | ((startupFrameIndicator & 0x1) << 18) | ((frameId & 0x7FF) << 7) | (payloadLength &
38  0x7F);
39 
40  uint32 crcInit = 0x1A;
41  uint32 length = 20;
42  uint32 crcNext;
43  uint32 crcPoly = 0x385;
44  uint32 crcRegX = crcInit;
45  uint32 headerTemp, regTemp;
46 
47  headerValue <<= 11;
48  crcRegX <<= 21;
49  crcPoly <<= 21;
50 
51  while (length--)
52  {
53  headerValue <<= 1;
54  headerTemp = headerValue & 0x80000000;
55  regTemp = crcRegX & 0x80000000;
56 
57  if (headerTemp ^ regTemp) // Step 1
58  {
59  crcNext = 1;
60  }
61  else
62  {
63  crcNext = 0;
64  }
65 
66  crcRegX <<= 1; // Step 2
67 
68  if (crcNext)
69  {
70  crcRegX ^= crcPoly; // Step 3
71  }
72  }
73 
74  crcRegX >>= 21;
75 
76  return (uint16)crcRegX;
77 }
78 
79 
80 boolean IfxEray_changePocState(Ifx_ERAY *eray, IfxEray_PocCommand pocCommand)
81 {
82  boolean result;
83 
84  // wait if Communication controller is busy
85  while (eray->SUCC1.B.PBSY == 1)
86  {}
87 
88  eray->SUCC1.B.CMD = pocCommand;
89 
90  // if command not accepted, return FALSE
91  if (eray->SUCC1.B.CMD == 0)
92  {
93  result = FALSE;
94  }
95  else
96  {
97  result = TRUE;
98  }
99 
100  return result;
101 }
102 
103 
104 void IfxEray_clearAllFlags(Ifx_ERAY *eray)
105 {
106  eray->EIR.U = 0xFFFFFFFFU; /* Clear Error Int. */
107  eray->SIR.U = 0xFFFFFFFFU; /* Clear Status Int. */
108  eray->EIER.U = 0xFFFFFFFFU; /* Disable all Error Int. */
109  eray->SIER.U = 0xFFFFFFFFU; /* Disable all Status Int. */
110  eray->MHDS.U = 0x7F7F7FFFU; /* Clear Error Int. */
111 }
112 
113 
114 void IfxEray_enableInterruptLines(Ifx_ERAY *eray)
115 {
116  eray->ILE.U = 0x00000003U; //enable both the interrupt lines
117  eray->EILS.U = 0x00000000U; // all interrupt lines to INT0SRC
118  eray->SILS.U = 0x00000800U; // TOBC interrupt line to INT1SRC
119  eray->SIES.U = 0x0303FFFFU; // all status interrupts are enabled
120  eray->EIES.U = 0x07070FFFU; // all error interrupts are enabled
121  eray->NDIC1.U = 0x00000000U; // all interrupt lines to NADT0SRC
122  eray->NDIC2.U = 0x00000000U; // all interrupt lines to NADT0SRC
123  eray->NDIC3.U = 0x00000000U; // all interrupt lines to NADT0SRC
124  eray->NDIC4.U = 0x00000000U; // all interrupt lines to NADT0SRC
125  eray->MSIC1.U = 0x00000000U; // all interrupt lines to MBSC0SRC
126  eray->MSIC2.U = 0x00000000U; // all interrupt lines to MBSC0SRC
127  eray->MSIC3.U = 0x00000000U; // all interrupt lines to MBSC0SRC
128  eray->MSIC4.U = 0x00000000U; // all interrupt lines to MBSC0SRC
129 }
130 
131 
132 void IfxEray_readData(Ifx_ERAY *eray, uint32 *data, uint8 payloadLength)
133 {
134  if (data != NULL_PTR)
135  {
136  uint16 length = (payloadLength + 1) / 2;
137  uint8 index;
138 
139  for (index = 0; index < length; index++)
140  {
141  *data++ = eray->RDDS_1S[index].U;
142  }
143  }
144 }
145 
146 
147 void IfxEray_readFrame(Ifx_ERAY *eray, IfxEray_ReceivedHeader *header, uint32 *data, Ifx_SizeT maxPayloadLength)
148 {
149  {
150  Ifx_ERAY_RDHS1 rdhs1;
151  rdhs1.U = eray->RDHS1.U;
152  Ifx_ERAY_RDHS2 rdhs2;
153  rdhs2.U = eray->RDHS2.U;
154  Ifx_ERAY_RDHS3 rdhs3;
155  rdhs3.U = eray->RDHS3.U;
156 
157  header->frameId = rdhs1.B.FID;
158  header->payloadLength = rdhs2.B.PLR;
159  header->headerCrc = rdhs2.B.CRC;
160  header->reservedBit = rdhs3.B.RES;
161  header->payloadPreambleIndicator = rdhs3.B.PPI;
162  header->nullFrameIndicator = rdhs3.B.NFI;
163  header->syncFrame = rdhs3.B.SYN;
164  header->startupFrame = rdhs3.B.SFI;
165  header->cycleNumber = rdhs3.B.RCC;
166  }
167 
168  IfxEray_readData(eray, data, (header->payloadLength > maxPayloadLength) ? maxPayloadLength : header->payloadLength);
169 }
170 
171 
172 void IfxEray_resetModule(Ifx_ERAY *eray)
173 {
174  eray->KRST1.B.RST = 1; /* Only if both Kernel reset bits are set a reset is executed */
175  eray->KRST0.B.RST = 1;
176 
177  while (eray->KRST0.B.RSTSTAT == 0)
178  {
179  /* Wait until reset is executed */
180  }
181 
182  eray->KRSTCLR.B.CLR = 1; /* Clear Kernel reset status bit */
183 }
184 
185 
186 void IfxEray_setMessageBufferInterruptDestination(Ifx_ERAY *eray, uint8 messageBuffer, uint8 messageBufferDestination)
187 {
188  uint8 ix = messageBuffer / 32;
189  uint32 mask = 1 << (messageBuffer % 32);
190  Ifx_ERAY_MSIC1 *msicSFR = (Ifx_ERAY_MSIC1 *)((uint32)&eray->MSIC1 + 4 * ix);
191 
192  if (messageBufferDestination == FALSE)
193  {
194  msicSFR->U &= ~mask;
195  }
196  else
197  {
198  msicSFR->U |= mask;
199  }
200 }
201 
202 
203 void IfxEray_setNewDataInterruptDestination(Ifx_ERAY *eray, uint8 ndat, uint8 ndatDestination)
204 {
205  uint8 ix = ndatDestination / 32;
206  uint32 mask = 1 << (ndatDestination % 32);
207  Ifx_ERAY_NDIC1 *ndicSFR = (Ifx_ERAY_NDIC1 *)((uint32)&eray->NDIC1 + 4 * ix);
208 
209  if (ndatDestination == FALSE)
210  {
211  ndicSFR->U &= ~mask;
212  }
213  else
214  {
215  ndicSFR->U |= mask;
216  }
217 }
218 
219 
220 void IfxEray_setPocReady(Ifx_ERAY *eray)
221 {
222  // wait CC is busy
223  while (eray->SUCC1.B.PBSY == 1)
224  {}
225 
226  // Ready unlock sequence
227  eray->LCK.B.CLK = 0xCE;
228  eray->LCK.B.CLK = 0x31;
229  eray->SUCC1.B.CMD = IfxEray_PocCommand_ready;
230 }
231 
232 
233 void IfxEray_setSlot(Ifx_ERAY *eray, const IfxEray_Header *header, const uint32 *data, const IfxEray_SlotConfig *slotConfig)
234 {
235  // wait if Host is busy with another transfer
237  {}
238 
239  if (header != NULL_PTR)
240  {
241  {
242  Ifx_ERAY_WRHS1 wrhs1;
243  wrhs1.U = 0;
244  wrhs1.B.FID = header->frameId;
245  wrhs1.B.CYC = header->cycleCode;
246  wrhs1.B.CHA = header->channelAFiltered;
247  wrhs1.B.CHB = header->channelBFiltered;
248  wrhs1.B.CFG = header->bufferDirection;
249  wrhs1.B.PPIT = header->transmitPayloadIndicatior;
250  wrhs1.B.TXM = header->transmissionMode;
251  wrhs1.B.MBI = header->bufferServiceEnabled;
252  eray->WRHS1.U = wrhs1.U;
253  }
254  {
255  Ifx_ERAY_WRHS2 wrhs2;
256  wrhs2.U = 0;
257 
259  {
260  wrhs2.B.CRC = IfxEray_calcHeaderCrc(header->payloadLength, header->frameId, header->startupFrameIndicator, header->syncFrameIndicator);
261  }
262 
263  wrhs2.B.PLC = header->payloadLength;
264  eray->WRHS2.U = wrhs2.U;
265  }
266 
267  eray->WRHS3.U = header->dataPointer;
268  }
269 
270  IfxEray_writeData(eray, data, header->payloadLength);
271 
272  eray->IBCM.B.LHSH = slotConfig->headerTransfered;
273  eray->IBCM.B.LDSH = slotConfig->dataTransfered;
274  eray->IBCM.B.STXRH = slotConfig->transferRequested;
275  eray->IBCR.B.IBRH = slotConfig->bufferIndex;
276 
277  // wait if Shadow is busy with another transfer
279  {}
280 
282  {}
283 }
284 
285 
286 void IfxEray_writeData(Ifx_ERAY *eray, const uint32 *data, uint8 payloadLength)
287 {
288  if (data != NULL_PTR)
289  {
290  uint16 length = (payloadLength + 1) / 2;
291  uint8 index;
292 
293  for (index = 0; index < length; index++)
294  {
295  eray->WRDS_1S[index].U = *data++;
296  }
297  }
298 }