iLLD_TC27xC  1.0
IfxSent_Sent.c
Go to the documentation of this file.
1 /**
2  * \file IfxSent_Sent.c
3  * \brief SENT SENT details
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 /******************************************************************************/
27 /*----------------------------------Includes----------------------------------*/
28 /******************************************************************************/
29 
30 #include "IfxSent_Sent.h"
31 
32 /******************************************************************************/
33 /*-------------------------Function Implementations---------------------------*/
34 /******************************************************************************/
35 
37 {
38  Ifx_SENT *sentSFR = driver->sent;
41  IfxSent_resetModule(sentSFR);
43 }
44 
45 
47 {
48  boolean result = TRUE;
49 
50  channel->driver = config->driver;
51  Ifx_SENT *sentSFR = config->driver->sent;
52  Ifx_SENT_CH *sentCh = &sentSFR->CH[config->channelId];
53  channel->channel = sentCh;
54  channel->channelId = config->channelId;
55 
56  IfxSent_disableChannel(sentSFR, config->channelId);
57  IfxSent_initializeChannelUnitTime(sentSFR, config->channelId, config->tUnit);
58 
59 #if 0
60  Ifx_SENT_CH_WDT tempWDT;
61  tempWDT.U = 0;
62  tempWDT.B.WDLx = config->watchDogTimerLimit;
63  sentCh->WDT.U = tempWDT.U;
64 #endif
65  Ifx_SENT_CH_RCR tempRCR;
66  tempRCR.U = 0;
67  tempRCR.B.IEP = config->receiveControl.endPulseIgnored;
68  tempRCR.B.ACE = config->receiveControl.alternateCrcSelected;
69  tempRCR.B.SNI = config->receiveControl.statusNibbleEnabled;
70  tempRCR.B.SDP = config->receiveControl.serialDataProcessingEnabled;
71  tempRCR.B.SCDIS = config->receiveControl.serialDataDisabledCrcDisabled;
72  tempRCR.B.CDIS = config->receiveControl.crcModeDisabled;
73  tempRCR.B.CFC = config->receiveControl.frameCheckMode;
74  tempRCR.B.FRL = config->receiveControl.frameLength;
75  tempRCR.B.CRZ = config->receiveControl.crcMethodDisabled;
76  tempRCR.B.ESF = config->receiveControl.extendedSerialFrameMode;
77  tempRCR.B.IDE = config->receiveControl.driftErrorsDisabled;
78  tempRCR.B.SUSEN = config->receiveControl.suspendTriggered;
79  sentCh->RCR.U = tempRCR.U;
80 
81  IfxSent_enableChannel(sentSFR, config->channelId);
82 
83  Ifx_SENT_CH_VIEW tempVIEW;
84  tempVIEW.U = 0;
85  tempVIEW.B.RDNP0 = config->nibbleControl.nibblePointer0;
86  tempVIEW.B.RDNP1 = config->nibbleControl.nibblePointer1;
87  tempVIEW.B.RDNP2 = config->nibbleControl.nibblePointer2;
88  tempVIEW.B.RDNP3 = config->nibbleControl.nibblePointer3;
89  tempVIEW.B.RDNP4 = config->nibbleControl.nibblePointer4;
90  tempVIEW.B.RDNP5 = config->nibbleControl.nibblePointer5;
91  tempVIEW.B.RDNP6 = config->nibbleControl.nibblePointer6;
92  tempVIEW.B.RDNP7 = config->nibbleControl.nibblePointer7;
93  sentCh->VIEW.U = tempVIEW.U;
94 
95  Ifx_SENT_CH_IOCR tempIOCR;
96  tempIOCR.U = 0;
97  tempIOCR.B.DEPTH = config->inputOutputControl.digitalGlitchFilterDepth;
98  tempIOCR.B.OIE = config->inputOutputControl.outputPulsePolarityHigh;
99  tempIOCR.B.IIE = config->inputOutputControl.inputPulsePolarityHigh;
100  tempIOCR.B.CEC = config->inputOutputControl.edgeCounterCleared;
101  tempIOCR.B.CREG = config->inputOutputControl.glitchRisingCleared;
102  tempIOCR.B.CFEG = config->inputOutputControl.glitchFallingCleared;
103  tempIOCR.B.ETS = config->inputOutputControl.externalTrigger;
104  tempIOCR.B.CTR = config->inputOutputControl.triggerMonitorCleared;
105  sentCh->IOCR.U = tempIOCR.U;
106 
107  Ifx_SENT_CH_INP tempINP;
108  tempINP.U = 0;
109  tempINP.B.RSI = config->interuptNodeControl.receiveSuccessInterruptNode;
110  tempINP.B.RDI = config->interuptNodeControl.receiveDataInterruptNode;
112  tempINP.B.TDI = config->interuptNodeControl.transferDataInterruptNode;
114  tempINP.B.ERRI = config->interuptNodeControl.errorInterruptNode;
115  tempINP.B.SDI = config->interuptNodeControl.serialDataReceiveInterruptNode;
116  tempINP.B.WDI = config->interuptNodeControl.watchdogErrorInterruptNode;
117  sentCh->INP.U = tempINP.U;
118 
119  sentCh->INTEN.U = config->enabledInterrupts.ALL;
120 
121  if (config->receiveControl.frameLength > 8)
122  {
123  /* Clear RSI and enable only RDI interrupt */
124  sentCh->INTEN.B.RSI = 0;
125  sentCh->INTEN.B.RDI = 1;
126  }
127 
128  if (config->spcModeOn == TRUE)
129  {
131  uint8 error = 0;
132 
133  // check if Transaction is in progress, before proceeding !!!
134  while ((sentCh->SCR.B.TRQ == 1) && (timeOut > 0))
135  {
136  // Wait for Transaction to be completed
137  timeOut--;
138  }
139 
140  if (timeOut == 0U)
141  {
142  error = 1U;
143  }
144 
145  if (error == 0U)
146  {
147  Ifx_SENT_CH_SCR tempSCR;
148  tempSCR.U = 0;
149  tempSCR.B.PLEN = config->transmitControl.pulseLength;
150  tempSCR.B.TRIG = config->transmitControl.triggerSource;
151  tempSCR.B.DEL = config->transmitControl.pulseDelayLength;
152  tempSCR.B.BASE = config->transmitControl.timeBase;
153  sentCh->SCR.U = tempSCR.U;
154 
156  {
157  // Enable Buffer Underflow interrupt also
158  sentCh->INTEN.B.TBI = 1U;
159  }
160  }
161  }
162 
163  const IfxSent_Sent_Pins *pinsConfig = (const IfxSent_Sent_Pins *)config->pins;
164 
165  if (pinsConfig != NULL_PTR)
166  {
167  const IfxSent_Sent_In *sentIn = pinsConfig->in;
168 
169  if (sentIn != NULL_PTR)
170  {
171  IfxSent_initSentPin(sentIn, pinsConfig->inMode);
172  }
173 
174  const IfxSent_Spc_Out *spcOut = pinsConfig->out;
175 
176  if (spcOut != NULL_PTR)
177  {
178  IfxSent_initSpcPin(spcOut, pinsConfig->outMode, pinsConfig->pinDriver);
179  }
180  }
181 
182  {
183  IfxSrc_Tos tos = config->interrupt.isrProvider;
184 
185  //IfxSent_clearAllEventFlags(sentSFR);
186  if (config->interrupt.priority != 0)
187  {
188  volatile Ifx_SRC_SRCR *src = IfxSent_getChannelSrc(config->channelId);
189  IfxSrc_init(src, tos, config->interrupt.priority);
190  IfxSrc_enable(src);
191  }
192  }
193 
194  return result;
195 }
196 
197 
199 {
200  const IfxSent_Sent_ChannelConfig defaultChannelConfig = {
201  .driver = NULL_PTR,
202  .channelId = IfxSent_ChannelId_none,
203  .tUnit = 3E-6, // 3 uS
204  //.watchDogTimerLimit = 1000,
205 
206  .receiveControl.endPulseIgnored = FALSE,
207  .receiveControl.alternateCrcSelected = FALSE,
208  .receiveControl.statusNibbleEnabled = FALSE,
209  .receiveControl.serialDataProcessingEnabled = FALSE,
210  .receiveControl.serialDataDisabledCrcDisabled = FALSE,
211  .receiveControl.crcModeDisabled = FALSE,
212  .receiveControl.frameCheckMode = IfxSent_FrameCheckMode_pastSyncPulse,
213  .receiveControl.frameLength = 6,
214  .receiveControl.crcMethodDisabled = FALSE,
215  .receiveControl.extendedSerialFrameMode = IfxSent_ExtendedSerialFrameMode_standard,
216  .receiveControl.driftErrorsDisabled = FALSE,
217  .receiveControl.suspendTriggered = FALSE,
218 
219  .nibbleControl.nibblePointer0 = IfxSent_Nibble_0,
220  .nibbleControl.nibblePointer1 = IfxSent_Nibble_1,
221  .nibbleControl.nibblePointer2 = IfxSent_Nibble_2,
222  .nibbleControl.nibblePointer3 = IfxSent_Nibble_3,
223  .nibbleControl.nibblePointer4 = IfxSent_Nibble_4,
224  .nibbleControl.nibblePointer5 = IfxSent_Nibble_5,
225  .nibbleControl.nibblePointer6 = IfxSent_Nibble_6,
226  .nibbleControl.nibblePointer7 = IfxSent_Nibble_7,
227 
228  .inputOutputControl.digitalGlitchFilterDepth = IfxSent_DigitalGlitchesLength_2,
229  .inputOutputControl.outputPulsePolarityHigh = FALSE,
230  .inputOutputControl.inputPulsePolarityHigh = FALSE,
231  .inputOutputControl.edgeCounterCleared = TRUE,
232  .inputOutputControl.glitchRisingCleared = TRUE,
233  .inputOutputControl.glitchFallingCleared = TRUE,
234  .inputOutputControl.externalTrigger = IfxSent_ExternalTrigger_0,
235  .inputOutputControl.triggerMonitorCleared = FALSE,
236 
237  .enabledInterrupts.ALL = IFXSENT_CFG_CHANNEL_INTEN,
238 
239  .interuptNodeControl.receiveDataInterruptNode = IfxSent_InterruptNodePointer_0,
240  .interuptNodeControl.receiveSuccessInterruptNode = IfxSent_InterruptNodePointer_0,
241  .interuptNodeControl.receiveBufferOverflowInterruptNode = IfxSent_InterruptNodePointer_0,
242  .interuptNodeControl.transferDataInterruptNode = IfxSent_InterruptNodePointer_0,
243  .interuptNodeControl.transferBufferUnderflowInterruptNode = IfxSent_InterruptNodePointer_0,
244  .interuptNodeControl.errorInterruptNode = IfxSent_InterruptNodePointer_0,
245  .interuptNodeControl.serialDataReceiveInterruptNode = IfxSent_InterruptNodePointer_0,
246  .interuptNodeControl.watchdogErrorInterruptNode = IfxSent_InterruptNodePointer_0,
247 
248  .pins = NULL_PTR,
249 
250  /* SPC mode enable/disable */
251  .spcModeOn = FALSE,
252  };
253  *config = defaultChannelConfig;
254  config->driver = driver;
255 }
256 
257 
259 {
260  boolean result = TRUE;
261  Ifx_SENT *sentSFR = config->module;
262  driver->sent = sentSFR;
263 
266 
267  Ifx_SENT_CLC tempCLC;
268  tempCLC.U = 0;
269  tempCLC.B.EDIS = (config->sleepModeEnabled != FALSE) ? 0 : 1;
270  tempCLC.B.RMC = 1; // no divider required, pass clock 1:1
271  sentSFR->CLC.U = tempCLC.U;
272 
273  IfxSent_enableModule(sentSFR);
274  IfxSent_initializeModuleClock(sentSFR, IfxSent_ClockDividerMode_normal, 1023); // Fractional divider not required, pass 1:1
276 
277  IfxScuWdt_setCpuEndinit(passwd);
278 
279  return result;
280 }
281 
282 
284 {
285  /* Default module initialization */
286  const IfxSent_Sent_Config defaultModuleConfig = {
287  .module = NULL_PTR,
288  .sleepModeEnabled = TRUE,
289  .timeStampPreDivider = 0,
290  };
291  *config = defaultModuleConfig;
292  config->module = sent;
293 }
294 
295 
297 {
298  boolean result = TRUE;
299 
300  Ifx_SENT *sentSFR = channel->driver->sent;
301  IfxSent_ChannelId ChanIdx = channel->channelId;
302  frame->data = sentSFR->RDR[ChanIdx].U;
303  frame->timeStamp = sentSFR->RTS[ChanIdx].U;
304  frame->statusNibble = channel->channel->RSR.B.SCN;
305 
306  return result;
307 }
308 
309 
311 {
312  boolean result = TRUE;
313 
314  Ifx_SENT_CH *sentCh = channel->channel;
315  Ifx_SENT_CH_SDS sds;
316 
317  sds.U = sentCh->SDS.U;
318 
319  message->serialData = sds.B.SD;
320  message->messageId = sds.B.MID;
321  message->configBit = sds.B.CON;
322  message->crc = sds.B.SCRC;
323 
324  return result;
325 }