iLLD_TC27xD  1.0
IfxEray_Eray.c
Go to the documentation of this file.
1 /**
2  * \file IfxEray_Eray.c
3  * \brief ERAY ERAY details
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_Eray.h"
30 #include "Mtu/Std/IfxMtu.h"
31 
32 /** \addtogroup IfxLld_Eray_Eray_Node
33  * \{ */
34 
35 /******************************************************************************/
36 /*-----------------------Private Function Prototypes--------------------------*/
37 /******************************************************************************/
38 
39 /** \brief Inialises the communication controller.
40  * \param eray pointer to ERAY Module handle.
41  * \param config pointer to communication controller config structure.
42  * \return None
43  */
44 static void IfxEray_Eray_Node_initCommunicationController(IfxEray_Eray *eray, const IfxEray_Eray_ControllerConfig *config);
45 
46 /** \brief Initialises the Global Timing Unit.
47  * \param eray pointer to ERAY Module handle.
48  * \param config global timing unit Configuration structure.
49  * \return None
50  */
51 static void IfxEray_Eray_Node_initGTU(IfxEray_Eray *eray, const IfxEray_Eray_GTUConfig *config);
52 
53 /** \brief Inialises the message RAM.
54  * \param eray pointer to ERAY Module handle.
55  * \param config pointer to message RAM config structure.
56  * \return None
57  */
58 static void IfxEray_Eray_Node_initMessageRAM(IfxEray_Eray *eray, const IfxEray_Eray_MessageRAMConfig *config);
59 
60 /** \} */
61 
62 /******************************************************************************/
63 /*-------------------------Function Implementations---------------------------*/
64 /******************************************************************************/
65 
67 {
68  Ifx_ERAY *eraySFR = eray->eray;
69  // clear all the flags
70  IfxEray_clearAllFlags(eraySFR);
71 
72  // set Communication Controller to config state
74  {
81  }
82 
83  // enable interrupt lines
86  //configure message RAM ( slots and slot buffers )
87  IfxEray_Eray_Node_initMessageRAM(eray, &config->messageRAMConfig);
88  //configure communication controller for clock corrections
89  IfxEray_Eray_Node_initCommunicationController(eray, &config->controllerConfig);
90  // initialise the Node pins.
91  const IfxEray_Eray_Pins *pins = config->pins;
92 
93  if (pins != NULL_PTR)
94  {
95  const IfxEray_Eray_NodeA *nodeAPins = pins->nodeAPins;
96 
97  if (nodeAPins != NULL_PTR)
98  {
99  const IfxEray_Rxd_In *rx = nodeAPins->rxIn;
100 
101  if (rx != NULL_PTR)
102  {
103  IfxEray_initRxPin(rx, nodeAPins->rxInMode);
104  }
105 
106  const IfxEray_Txd_Out *tx = nodeAPins->txOut;
107 
108  if (tx != NULL_PTR)
109  {
110  IfxEray_initTxPin(tx, nodeAPins->txOutMode, nodeAPins->pinDriver);
111  }
112 
113  const IfxEray_Txen_Out *txEn = nodeAPins->txEnOut;
114 
115  if (txEn != NULL_PTR)
116  {
117  IfxEray_initTxEnPin(txEn, nodeAPins->txEnOutMode, nodeAPins->pinDriver);
118  }
119  }
120 
121  const IfxEray_Eray_NodeB *nodeBPins = pins->nodeBPins;
122 
123  if (nodeBPins != NULL_PTR)
124  {
125  const IfxEray_Rxd_In *rx = nodeBPins->rxIn;
126 
127  if (rx != NULL_PTR)
128  {
129  IfxEray_initRxPin(rx, nodeBPins->rxInMode);
130  }
131 
132  const IfxEray_Txd_Out *tx = nodeBPins->txOut;
133 
134  if (tx != NULL_PTR)
135  {
136  IfxEray_initTxPin(tx, nodeBPins->txOutMode, nodeBPins->pinDriver);
137  }
138 
139  const IfxEray_Txen_Out *txEn = nodeBPins->txEnOut;
140 
141  if (txEn != NULL_PTR)
142  {
143  IfxEray_initTxEnPin(txEn, nodeBPins->txEnOutMode, nodeBPins->pinDriver);
144  }
145  }
146  }
147 
148  // set the Communication Controller to ready state
149  IfxEray_setPocReady(eraySFR);
150 }
151 
152 
153 static void IfxEray_Eray_Node_initCommunicationController(IfxEray_Eray *eray, const IfxEray_Eray_ControllerConfig *config)
154 {
155  Ifx_ERAY *eraySFR = eray->eray;
156  //SUCC1
165  //SUCC2
167  //SUCC3
169  //NEMC
171  //PRTC1, PRTC2
175  IfxEray_setBaudrate(eraySFR, config->prtc1Control.baudrate);
177  );
179  //MHDC
181  // GTU
182  IfxEray_Eray_Node_initGTU(eray, &config->gtuConfig);
183 }
184 
185 
187 {
188  // Default node configurations buffer
189  const IfxEray_Eray_NodeConfig nodeConfig = {
190  .messageRAMConfig = {
191  .firstDynamicBuffer = 0,
192  .numberOfMessageBuffers = 0,
193  .fifoBufferStartIndex = 0x80,
194  .fifoDepth = 30,
195  .frameIdFilter = 0x7FD,
196  .receiveChannel = IfxEray_ReceiveChannel_a,
197  .rejectedFrameId = 2,
198  .filteredCycleNumber = 0,
199  .staticFifoDisabled = FALSE,
200  .fifoNullFramesRejected = FALSE,
201  .bufferReconfigEnabled = TRUE,
202  .fifoConfigured = FALSE
203  },
204 
205  .controllerConfig = {
206  .networkVectorLength = 0x2,
207  .staticFramepayload = 0x4,
208  .latestTransmissionStart = 0x3F,
209 
210  .prtc1Control = {
211  .transmissionStartTime = 0xA,
212  .collisionAvoidanceDuration = 0x61,
213  .strobePosition = IfxEray_StrobePosition_5,
214  .baudrate = IfxEray_Baudrate_10,
215  .receiveWakeupTestDuration = 0x8C,
216  .transmitWakeupRepetitions = 0x2
217  },
218 
219  .prtc2Control = {
220  .receiveWakeupIdleTime = 0x2D,
221  .receiveWakeupLowTime = 0x12,
222  .transmitWakeupIdleTime = 0x2D,
223  .transmitWakeupLowTime = 0x12
224  },
225 
226  .succ1Config = {
227  .channelAConnectedNode = TRUE,
228  .channelBConnectedNode = TRUE,
229  .channelASymbolTransmitted = FALSE,
230  .channelBSymbolTransmitted = FALSE,
231  .clockSyncErrorHalt = TRUE,
232  .transmissionSlotMode = IfxEray_TransmissionSlotMode_single,
233  .wakeupPatternChannel = IfxEray_WakeupChannel_a,
234  .numberOfCyclePairsForActive = 0x7,
235  .maxColdStartAttempts = 0x1F,
236  .syncFrameTransmitted = TRUE,
237  .startupFrameTransmitted = TRUE
238  },
239 
240  .succ2Config = {
241  .listenTimeOut = 0x13972,
242  .listenTimeOutNoise = IfxEray_ListenTimeOutNoise_16
243  },
244 
245  .succ3Config = {
246  .clockCorrectionCyclesPassive = 0x1,
247  .clockCorrectionCyclesHalt = 0x1
248  },
249 
250  .gtuConfig = {
251  .gtu01Config.microticksPerCycle = 0x9C40,
252 
253  .gtu02Config = {
254  .macroticksPerCycle = 0x3E8,
255  .maxSyncFrames = 0x4
256  },
257 
258  .gtu03Config = {
259  .channelAMicrotickInitialOffset = 0x19,
260  .channelBMicrotickInitialOffset = 0x19,
261  .channelAMacrotickInitialOffset = 0xA,
262  .channelBMacrotickInitialOffset = 0x2
263  },
264 
265  .gtu04Config = {
266  .networkStartIdleTime = 0x38E,
267  .correctionOffset = 0x394
268  },
269 
270  .gtu05Config = {
271  .channelAReceptionDelay = 0x4,
272  .channelBReceptionDelay = 0x4,
273  .clusterDrift = 1,
274  .decodingCorrection = 0x34
275  },
276 
277  .gtu06Config = {
278  .acceptedStartupDeviation = 0x81,
279  .maxDriftOffset = 0xD2
280  },
281 
282  .gtu07Config = {
283  .staticSlotLength = 0x32,
284  .staticSlotsCount = 0xC
285  },
286 
287  .gtu08Config = {
288  .dynamicSlotLength = 4,
289  .dynamicSlotCount = 0x4B,
290  },
291 
292  .gtu09Config = {
293  .idleDynamicSlots = IfxEray_IdleDynamicSlots_1,
294  .staticActionPoint = 8,
295  .dynamicActionPoint = 3
296  },
297 
298  .gtu10Config = {
299  .maxOffsetCorrection = 0x32,
300  .maxRateCorrection = 0xD2
301  },
302 
303  .gtu11Config = {
304  .externalOffsetCorrection = IfxEray_ExternalOffsetCorrection_0,
305  .externalRateCorrection = IfxEray_ExternalRateCorrection_0,
306  .externalOffset = IfxEray_ExternalOffset_noCorrection,
307  .externalRate = IfxEray_ExternalRate_noCorrection
308  },
309  },
310  },
311  .pins = NULL_PTR
312  };
313 
314  *config = nodeConfig;
315 }
316 
317 
318 static void IfxEray_Eray_Node_initGTU(IfxEray_Eray *eray, const IfxEray_Eray_GTUConfig *config)
319 {
320  Ifx_ERAY *eraySFR = eray->eray;
321 
339 }
340 
341 
342 static void IfxEray_Eray_Node_initMessageRAM(IfxEray_Eray *eray, const IfxEray_Eray_MessageRAMConfig *config)
343 {
344  Ifx_ERAY *eraySFR = eray->eray;
345  uint32 bufferCount;
346  //group of Message Buffers exclusively for the static segment configured
348  /* Last Configured Buffer
349  * 01H..7FH: Number of Message Buffers is LCB + 1
350  * 80H..FFH: No Message Buffer configured
351  */
353 
354  // receive FIFO buffers configuration
355  if (config->fifoConfigured == TRUE)
356  {
360  }
361  else
362  {
363  // FIFO is not supported. No message buffers assigned to the FIFO, if FFB >= 128
365  }
366 
367  if (config->bufferReconfigEnabled == TRUE)
368  {
369  //buffers reconfigured
371  }
372  else
373  {
374  //buffer reconfiguration locked
376  }
377 
378  for (bufferCount = 0; bufferCount < config->numberOfMessageBuffers; bufferCount++)
379  {
380  IfxEray_setSlot(eraySFR, config->header[bufferCount], config->data[bufferCount], config->slotControl[bufferCount]);
381  }
382 }
383 
384 
386 {
387  eray->eray = config->module;
388  Ifx_ERAY *eraySFR = config->module;
389  // Enable MTU clock
390  {
392  IfxScuWdt_clearCpuEndinit(password);
394  IfxScuWdt_setCpuEndinit(password);
395  }
396  // clear RAMS
397  {
403 
404  IfxScuWdt_setSafetyEndinit(password);
405  }
406 
407  {
410  //enable the module
411  IfxEray_enableModule(eraySFR);
412  IfxScuWdt_setCpuEndinit(passwd);
413  }
414 
415  /** NOTE: If not DMA, the interrupt service provider is assigned to the CPU ID where
416  * this function is called from */
417  {
418  if (config->interrupt.int0Priority != 0)
419  {
420  volatile Ifx_SRC_SRCR *src = IfxEray_getInterruptLine0SrcPtr(eraySFR);
422  IfxSrc_enable(src);
423  }
424 
425  if (config->interrupt.int1Priority != 0)
426  {
427  volatile Ifx_SRC_SRCR *src = IfxEray_getInterruptLine1SrcPtr(eraySFR);
429  IfxSrc_enable(src);
430  }
431 
432  if (config->interrupt.tint0Priority != 0)
433  {
434  volatile Ifx_SRC_SRCR *src = IfxEray_getTimerInterrupt0SrcPtr(eraySFR);
436  IfxSrc_enable(src);
437  }
438 
439  if (config->interrupt.tint1Priority != 0)
440  {
441  volatile Ifx_SRC_SRCR *src = IfxEray_getTimerInterrupt1SrcPtr(eraySFR);
443  IfxSrc_enable(src);
444  }
445 
446  if (config->interrupt.mbsc0Priority != 0)
447  {
448  volatile Ifx_SRC_SRCR *src = IfxEray_getMessageBufferStatus0SrcPtr(eraySFR);
450  IfxSrc_enable(src);
451  }
452 
453  if (config->interrupt.mbsc1Priority != 0)
454  {
455  volatile Ifx_SRC_SRCR *src = IfxEray_getMessageBufferStatus1SrcPtr(eraySFR);
457  IfxSrc_enable(src);
458  }
459 
460  if (config->interrupt.ibusyPriority != 0)
461  {
462  volatile Ifx_SRC_SRCR *src = IfxEray_getInputBufferBusySrcPtr(eraySFR);
464  IfxSrc_enable(src);
465  }
466 
467  if (config->interrupt.obusyPriority != 0)
468  {
469  volatile Ifx_SRC_SRCR *src = IfxEray_getOutputBufferBusySrcPtr(eraySFR);
471  IfxSrc_enable(src);
472  }
473 
474  if (config->interrupt.ndat0Priority != 0)
475  {
476  volatile Ifx_SRC_SRCR *src = IfxEray_getNewDataInterrupt0SrcPtr(eraySFR);
478  IfxSrc_enable(src);
479  }
480 
481  if (config->interrupt.ndat1Priority != 0)
482  {
483  volatile Ifx_SRC_SRCR *src = IfxEray_getNewDataInterrupt1SrcPtr(eraySFR);
485  IfxSrc_enable(src);
486  }
487  }
488 }
489 
490 
492 {
493  config->module = eray;
504 
505  config->interrupt.int0Priority = 0;
506  config->interrupt.int1Priority = 0;
507  config->interrupt.tint0Priority = 0;
508  config->interrupt.tint1Priority = 0;
509  config->interrupt.ndat0Priority = 0;
510  config->interrupt.ndat1Priority = 0;
511  config->interrupt.mbsc0Priority = 0;
512  config->interrupt.mbsc1Priority = 0;
513  config->interrupt.ibusyPriority = 0;
514  config->interrupt.obusyPriority = 0;
515 }
516 
517 
519 {
520  Ifx_ERAY *eraySFR = eray->eray;
521 
522  Ifx_ERAY_FSR fifoStatus = IfxEray_getFifoStatus(eraySFR);
523 
524  // Check if FIFO is not empty
525  if (fifoStatus.B.RFNE == 1)
526  {
527  if (fifoStatus.B.RFO == 1)
528  {
529  //FIX ME: FIFO overrun error
530  }
531  else
532  {
534  {}
535 
536  IfxEray_receiveHeader(eraySFR, config->headerReceived);
537  IfxEray_receiveData(eraySFR, config->dataReceived);
538  //Transfer the first message buffer ID of FIFO
541 
543  {}
544 
545  if (config->swapRequested && (IfxEray_getOutputBuffer(eraySFR) != config->bufferIndex))
546  {
547  IfxEray_setViewData(eraySFR, config->swapRequested);
548  }
549  }
550  }
551 }
552 
553 
555 {
556  Ifx_ERAY *eraySFR = eray->eray;
557 
559  {}
560 
561  IfxEray_receiveHeader(eraySFR, config->headerReceived);
562  IfxEray_receiveData(eraySFR, config->dataReceived);
563  IfxEray_setRxBufferNumber(eraySFR, config->bufferIndex);
565 
567  {}
568 
569  if (config->swapRequested && (IfxEray_getOutputBuffer(eraySFR) != config->bufferIndex))
570  {
571  IfxEray_setViewData(eraySFR, config->swapRequested);
572  }
573 }
574 
575 
577 {
578  Ifx_ERAY *eraySFR = eray->eray;
579 
580  while (IfxEray_getInputBufferBusyHostStatus(eraySFR) == TRUE)
581  {}
582 
583  IfxEray_sendHeader(eraySFR, transmitControl->headerTransfered);
584  IfxEray_sendData(eraySFR, transmitControl->dataTransfered);
585  IfxEray_setTransmitRequest(eraySFR, transmitControl->transferRequested);
586  IfxEray_setTxBufferNumber(eraySFR, transmitControl->bufferIndex);
587 
588  while (IfxEray_getInputBufferBusyShadowStatus(eraySFR) == TRUE)
589  {}
590 
591  while (IfxEray_getInputBufferBusyHostStatus(eraySFR) == TRUE)
592  {}
593 }