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