iLLD_TC27xD  1.0
IfxMsc_Msc.c
Go to the documentation of this file.
1 /**
2  * \file IfxMsc_Msc.c
3  * \brief MSC MSC 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 "IfxMsc_Msc.h"
30 
31 /******************************************************************************/
32 /*-------------------------Function Implementations---------------------------*/
33 /******************************************************************************/
34 
36 {
37  IfxMsc_resetModule(msc->msc);
38 }
39 
40 
42 {
43  Ifx_MSC *mscSfr = msc->msc;
45 
46  if (target == IfxMsc_Msc_Target_low)
47  {
48  enX = IfxMsc_getDataLowTarget(mscSfr);
49  }
50  else if (target == IfxMsc_Msc_Target_high)
51  {
52  enX = IfxMsc_getDataHighTarget(mscSfr);
53  }
54 
55  return enX;
56 }
57 
58 
60 {
61  Ifx_MSC *mscSfr = config->msc;
62 
63  msc->msc = mscSfr;
64 
67 
68  /* Enable the MSCx Clock */
69  IfxMsc_enableModule(mscSfr);
70 
71  /* Configure MSC hadrware enable and set the divider mode */
72  {
73  Ifx_MSC_FDR fdr;
74 
75  /* Read the FDR register content */
76  fdr.U = mscSfr->FDR.U;
77  /* Select the divider mode */
78  fdr.B.DM = config->clockConfig.dividerMode;
79  /* Enable Hardware Clock Control */
80  fdr.B.ENHW = IfxMsc_HardwareClock_enabled;
81 
82  mscSfr->FDR.U = fdr.U;
83  }
84 
85  /* Configure Upstream Channel Data Format */
86  {
87  Ifx_MSC_USR usr;
88 
89  /* Read the USR register content */
90  usr.U = mscSfr->USR.U;
91  /* Service Request Delay Control */
92  usr.B.SRDC = config->upstreamConfig.serviceRequestDelay;
93  /* Select parity control Even - 0, Odd - 1 */
94  usr.B.PCTR = config->upstreamConfig.parity;
95  /* Select upstream baud rate fMSC/xx */
96  usr.B.URR = config->upstreamConfig.upstreamChannelReceivingRate;
97  /* Select 12 bit or 16 bit frame */
98  usr.B.UFT = config->upstreamConfig.upstreamChannelFrameType;
99 
100  mscSfr->USR.U = usr.U;
101  }
102 
103  /* Normal divider */
104  if (config->clockConfig.dividerMode == 1)
105  {
106  /* Initialize MSC BaudRate at 6.25MHz, Fsys = 100MHz */
107  mscSfr->FDR.B.STEP =
109  }
110  /* Fractional divider */
111  else
112  {
113  /* Initialize MSC BaudRate at 6.25MHz, Fsys = 100MHz */
114  mscSfr->FDR.B.STEP =
116  }
117 
118  IfxScuWdt_setCpuEndinit(passwd);
119 
120  /* Configure IOs */
121  {
122  IfxMsc_Msc_Io *io = (IfxMsc_Msc_Io *)&config->io;
123 
124  IfxMsc_Fclp_Out *fclp = io->fclp.pin;
125 
126  if (fclp != NULL_PTR)
127  {
128  IfxMsc_initFclpPin(fclp, io->fclp.mode, io->pinDriver);
129  }
130 
131  IfxMsc_Fcln_Out *fcln = io->fcln.pin;
132 
133  if (fcln != NULL_PTR)
134  {
135  IfxMsc_initFclnPin(fcln, io->fcln.mode, io->pinDriver);
136  }
137 
138  IfxMsc_Sop_Out *sop = io->sop.pin;
139 
140  if (sop != NULL_PTR)
141  {
142  IfxMsc_initSopPin(sop, io->sop.mode, io->pinDriver);
143  }
144 
145  IfxMsc_Son_Out *son = io->son.pin;
146 
147  if (son != NULL_PTR)
148  {
149  IfxMsc_initSonPin(son, io->son.mode, io->pinDriver);
150  }
151 
152  IfxMsc_En_Out *en0 = io->en0.pin;
153 
154  if (en0 != NULL_PTR)
155  {
156  IfxMsc_initEnPin(en0, io->en0.mode, io->pinDriver);
157  }
158 
159  IfxMsc_En_Out *en1 = io->en1.pin;
160 
161  if (en1 != NULL_PTR)
162  {
163  IfxMsc_initEnPin(en1, io->en1.mode, io->pinDriver);
164  }
165 
166  IfxMsc_En_Out *en2 = io->en2.pin;
167 
168  if (en2 != NULL_PTR)
169  {
170  IfxMsc_initEnPin(en2, io->en2.mode, io->pinDriver);
171  }
172 
173  IfxMsc_En_Out *en3 = io->en3.pin;
174 
175  if (en3 != NULL_PTR)
176  {
177  IfxMsc_initEnPin(en3, io->en3.mode, io->pinDriver);
178  }
179 
180  IfxMsc_Sdi_In *sdi = io->sdi.pin;
181 
182  if (sdi != NULL_PTR)
183  {
184  IfxMsc_initSdiPin(sdi, io->sdi.mode);
185  }
186 
187  IfxMsc_Inj_In *inj0 = io->inj0.pin;
188 
189  if (inj0 != NULL_PTR)
190  {
191  IfxMsc_initInjPin(inj0, io->inj0.mode);
192  }
193 
194  IfxMsc_Inj_In *inj1 = io->inj1.pin;
195 
196  if (inj1 != NULL_PTR)
197  {
198  IfxMsc_initInjPin(inj1, io->inj1.mode);
199  }
200  }
201 
202  /* Configure the control of upstream channel timeout feature */
203  {
204  Ifx_MSC_USCE usce;
205 
206  /* Read the USCE register content */
207  usce.U = mscSfr->USCE.U;
208  /* Upstream Timeout Value */
209  usce.B.USTOVAL = config->upstreamConfig.upstreamTimeoutValue;
210  /* Upstream Timeout Prescaler */
211  usce.B.USTOPRE = config->upstreamConfig.upstreamTimeoutPrescaler;
212  /* Upstream Timeout Interrupt */
213  usce.B.USTOIP = config->interruptConfig.upstreamTimeoutInterruptNode,
214  usce.B.USTOEN = config->interruptConfig.upstreamTimeoutInterrupt,
215 
216  mscSfr->USCE.U = usce.U;
217  }
218 
219  /* Control the operation mode and frame layout of the downstream channel transmission */
220  {
221  Ifx_MSC_DSC dsc;
222 
223  /* Read the DSC register content */
224  dsc.U = mscSfr->DSC.U;
225 
226  /* Passive Phase Length */
227  dsc.B.PPD = config->downstreamConfig.dataFramePassivePhaseLength;
228  /* Number of command bits transmitted */
229  dsc.B.NBC = config->downstreamConfig.commandFrameLength;
230  /* SRH Selection Bit */
231  dsc.B.ENSELH = config->downstreamConfig.srhActivePhaseSelection;
232  /* SRL Selection Bit */
233  dsc.B.ENSELL = config->downstreamConfig.srlActivePhaseSelection;
234  /* Number of SRH Bits transmitted */
235  dsc.B.NDBH = config->downstreamConfig.srhDataFrameLength;
236  /* Number of SRL Bits transmitted */
237  dsc.B.NDBL = config->downstreamConfig.srlDataFrameLength;
238  /* Transmission Mode - Triggered or data repetition */
239  dsc.B.TM = config->downstreamConfig.transmissionMode;
240 
241  mscSfr->DSC.U = dsc.U;
242  }
243 
244  /* Number Of Passive Time Frames */
245  mscSfr->DSS.B.NPTF = config->downstreamConfig.passiveTimeFrameCount;
246 
247  /* Select Source for SRL */
248  mscSfr->DSDSL.U = config->downstreamConfig.downstreamDataSourcesLow;
249  /* Select Source for SRH */
250  mscSfr->DSDSH.U = config->downstreamConfig.downstreamDataSourcesHigh;
251 
252  /* Emergency Stop Enable for Bits */
253  mscSfr->ESR.U = config->downstreamConfig.emergencyStopEnableBits;
254 
255  /* Interrupt configuration */
256  {
257  Ifx_MSC_ICR icr;
258 
259  icr.U = mscSfr->ICR.U;
260 
261  icr.B.EDIP = config->interruptConfig.dataFrameInterruptNode;
262  icr.B.EDIE = config->interruptConfig.dataFrameInterrupt;
263  icr.B.ECIP = config->interruptConfig.commandFrameInterruptNode;
264  icr.B.ECIE = config->interruptConfig.commandFrameInterrupt;
265  icr.B.TFIP = config->interruptConfig.timeFrameInterruptNode;
266  icr.B.TFIE = config->interruptConfig.timeFrameInterrupt;
267  icr.B.RDIP = config->interruptConfig.receiveDataInterruptNode;
268  icr.B.RDIE = config->interruptConfig.receiveDataInterrupt;
269 
270  /* additional interrupt configured in USCE */
271 
272  mscSfr->ICR.U = icr.U;
273 
274  /* ABRA */
275  Ifx_MSC_ABC abc;
276  abc.U = mscSfr->ABC.U;
277 
279  {
280  abc.B.OIP = 0;
281  abc.B.OASR = 1;
282  }
283  else
284  {
285  abc.B.OIP = config->interruptConfig.overflowInterruptNode;
286  abc.B.OASR = 0;
287  }
288 
289  abc.B.OIE = config->interruptConfig.overflowInterrupt;
290 
292  {
293  abc.B.UIP = 0;
294  abc.B.UASR = 1;
295  }
296  else
297  {
298  abc.B.UIP = config->interruptConfig.underflowInterruptNode;
299  abc.B.UASR = 0;
300  }
301 
302  abc.B.UIE = config->interruptConfig.underflowInterrupt;
303 
304  mscSfr->ABC.U = abc.U;
305  }
306 
307  /* MSC inputs/outputs signal polarities */
308  {
309  Ifx_MSC_OCR ocr;
310 
311  /* Read the OCR register content */
312  ocr.U = mscSfr->OCR.U;
313  /* FCL is activated during active phases or always */
314  ocr.B.CLKCTRL = config->outputControlConfig.fclClockControl;
315  /* SDI Line Polarity - SDI and SI */
316  ocr.B.ILP = config->outputControlConfig.sdiLinePolarity;
317  /* Chip Selection Lines Polarity - EN[0:3, ENL, ENH and ENC */
318  ocr.B.CSLP = config->outputControlConfig.cslpPolarity;
319  /* SOP Line Polarity - SOP, SON, SO */
320  ocr.B.SLP = config->outputControlConfig.sopPolarity;
321  /* FCLP Line Polarity - FCLP, FCLN and FCL */
322  ocr.B.CLP = config->outputControlConfig.fclpPolarity;
323 
324  mscSfr->OCR.U = ocr.U;
325  }
326  /* Chip Enable Selection for ENL */
327  IfxMsc_setDataLowTarget(mscSfr, config->target[0]);
328 
329  /* Chip Enable Selection for ENH */
330  IfxMsc_setDataHighTarget(mscSfr, config->target[0]);
331 
332  /* Chip Enable Selection for ENC */
334 
335  /* Configure the Injection Enable and number of SRHE, SRLE Bits transmitted and Extension Enable */
336  {
337  Ifx_MSC_DSCE dsce;
338 
339  /* Read the DSCE register content */
340  dsce.U = mscSfr->DSCE.U;
341  /* Command-Data-Command in Data Repetition Mode */
343  /* Injection Position of the Pin 1 Signal */
344  dsce.B.INJPOSP1 = config->downstreamConfig.injectionPositionPin1;
345  /* Injection Enable of the Pin 1 Signal */
346  dsce.B.INJENP1 = config->downstreamConfig.externalSignalInjectionPin1;
347  /* Injection Position of the Pin 0 Signal */
348  dsce.B.INJPOSP0 = config->downstreamConfig.injectionPositionPin0;
349  /* Injection Enable of the Pin 0 Signal */
350  dsce.B.INJENP0 = config->downstreamConfig.externalSignalInjectionPin0;
351 
352  mscSfr->DSCE.U = dsce.U;
353  }
354 
355  /* If enabled configure extension registers */
357  {
359  }
360 
361  /* If enabled, configure ABRA block */
363  {
364  IfxMsc_Msc_initializeAbra(msc, config);
365  }
366 }
367 
368 
370 {
371  const IfxMsc_Msc_Config defaultConfig = {
372  .msc = NULL_PTR,
373  .clockConfig = {
374  .baudrate = 3125000,
375  .dividerMode = IfxMsc_DividerMode_normal,
376  .step = 0
377  },
378  .upstreamConfig = {
379  .upstreamChannelFrameType = IfxMsc_UpstreamChannelFrameType_12bit,
380  .upstreamChannelReceivingRate = IfxMsc_UpstreamChannelReceivingRate_16,
381  .parity = IfxMsc_Parity_even,
382  .serviceRequestDelay = IfxMsc_ServiceRequestDelay_noDelay,
383  .upstreamTimeoutPrescaler = IfxMsc_UpstreamTimeoutPrescaler_32768,
384  .upstreamTimeoutValue = IfxMsc_UpstreamTimeoutValue_16
385  },
386  .interruptConfig = {
387  .dataFrameInterruptNode = IfxMsc_DataFrameInterruptNode_SR0,
388  .dataFrameInterrupt = IfxMsc_DataFrameInterrupt_disabled,
389  .commandFrameInterruptNode = IfxMsc_CommandFrameInterruptNode_SR0,
390  .commandFrameInterrupt = IfxMsc_CommandFrameInterrupt_disabled,
391  .timeFrameInterruptNode = IfxMsc_TimeFrameInterruptNode_SR0,
392  .timeFrameInterrupt = IfxMsc_TimeFrameInterrupt_disabled,
393  .receiveDataInterruptNode = IfxMsc_ReceiveDataInterruptNode_SR0,
394  .receiveDataInterrupt = IfxMsc_ReceiveDataInterrupt_disabled,
395  .upstreamTimeoutInterruptNode = IfxMsc_UpstreamTimeoutInterruptNode_SR0,
396  .upstreamTimeoutInterrupt = IfxMsc_UpstreamTimeoutInterrupt_disabled,
397  .overflowInterruptNode = IfxMsc_OverflowInterruptNode_SR0,
398  .overflowInterrupt = IfxMsc_OverflowInterrupt_disabled,
399  .underflowInterruptNode = IfxMsc_UnderflowInterruptNode_SR0,
400  .underflowInterrupt = IfxMsc_UnderflowInterrupt_disabled
401  },
402  .outputControlConfig = {
403  .fclpPolarity = IfxMsc_FclLinePolarity_nonInverted,
404  .sopPolarity = IfxMsc_SoLinePolarity_nonInverted,
405  .cslpPolarity = IfxMsc_ChipSelectActiveState_low,
406  .sdiLinePolarity = IfxMsc_SdiLinePolarity_likeSi,
408  },
409  .downstreamConfig = {
410  .transmissionMode = IfxMsc_TransmissionMode_triggered,
411  .srlDataFrameLength = IfxMsc_DataFrameLength_16,
412  .srhDataFrameLength = IfxMsc_DataFrameLength_16,
413  .srlActivePhaseSelection = IfxMsc_ActivePhaseSelection_none,
414  .srhActivePhaseSelection = IfxMsc_ActivePhaseSelection_none,
415  .commandFrameLength = IfxMsc_CommandFrameLength_32,
416  .dataFramePassivePhaseLength = IfxMsc_DataFramePassivePhaseLength_2,
417  .passiveTimeFrameCount = IfxMsc_PassiveTimeFrameCount_0,
418  .externalSignalInjectionPin0 = IfxMsc_ExternalSignalInjection_disabled,
419  .injectionPositionPin0 = IfxMsc_ExternalBitInjectionPosition_0,
420  .externalSignalInjectionPin1 = IfxMsc_ExternalSignalInjection_disabled,
421  .injectionPositionPin1 = IfxMsc_ExternalBitInjectionPosition_0,
422  .commandDataCommandReceptionMode = IfxMsc_CommandDataCommandRepetitionMode_disabled,
423  .downstreamDataSourcesLow = 0,
424  .downstreamDataSourcesHigh = 0,
425  .emergencyStopEnableBits = 0
426  },
427  .downstreamExtensionConfig = {
428  .extension = IfxMsc_Extension_disabled,
429  .srlBitsShiftedAtDataFramesExtension = IfxMsc_MsbBitDataExtension_notPresent,
430  .srhBitsShiftedAtDataFramesExtension = IfxMsc_MsbBitDataExtension_notPresent,
431  .downstreamExtensionDataSourcesLow = 0,
432  .downstreamExtensionDataSourcesHigh = 0,
433  .emergencyStopExtensionEnableBits = 0,
434  .dataFrameExtensionPassivePhaseLength = IfxMsc_DataFrameExtensionPassivePhaseLength_0,
435  .controlFrameExtensionPassivePhaseLength = IfxMsc_ControlFrameExtensionPassivePhaseLength_0,
436  .nDividerDownstream = IfxMsc_NDividerDownstream_1
437  },
438  .abraConfig = {
439  .abraDownstreamBlockBaudrate = 500000,
440  .lowPhaseOfShiftClock = IfxMsc_ShiftClockPhaseDuration_1,
441  .highPhaseOfShiftClock = IfxMsc_ShiftClockPhaseDuration_1,
442  .nDividerAbra = IfxMsc_NDividerAbra_1,
443  .abraBlockBypass = IfxMsc_AsynchronousBlock_bypassed,
444  .clockSelectAbra = IfxMsc_ClockSelect_fspb
445  },
446  .io = {
447  .fclp = {
448  .pin = NULL_PTR,
450  },
451  .fcln = {
452  .pin = NULL_PTR,
454  },
455  .sop = {
456  .pin = NULL_PTR,
458  },
459  .son = {
460  .pin = NULL_PTR,
462  },
463  .en0 = {
464  .pin = NULL_PTR,
466  },
467  .en1 = {
468  .pin = NULL_PTR,
470  },
471  .en2 = {
472  .pin = NULL_PTR,
474  },
475  .en3 = {
476  .pin = NULL_PTR,
478  },
479  .sdi = {
480  .pin = NULL_PTR,
482  },
483  .inj0 = {
484  .pin = NULL_PTR,
486  },
487  .inj1 = {
488  .pin = NULL_PTR,
490  },
492  }
493  };
494 
495  /* Default Configuration */
496  *config = defaultConfig;
497 
498  /* take over module pointer */
499  config->msc = msc;
500 }
501 
502 
504 {
505  Ifx_MSC *mscSfr = msc->msc;
506 
507  /* N Divider Downstream */
508  mscSfr->DSTE.B.NDD =
510 
511  /* Configure Asynchronous block */
512  {
513  Ifx_MSC_ABC abc;
514 
515  /* Read the ABC register content */
516  abc.U = mscSfr->ABC.U;
517  /* Asynchronous Block Bypass */
518  abc.B.ABB = config->abraConfig.abraBlockBypass;
519  /* Clock Select */
520  abc.B.CLKSEL = config->abraConfig.clockSelectAbra;
521  /* N Divider ABRA */
522  abc.B.NDA = config->abraConfig.nDividerAbra;
523  /* Duration of the High Phase of the Shift Clock */
524  abc.B.HIGH = config->abraConfig.highPhaseOfShiftClock;
525  /* Duration of the Low Phase of the Shift Clock */
526  abc.B.LOW = config->abraConfig.lowPhaseOfShiftClock;
527 
528  mscSfr->ABC.U = abc.U;
529  }
530 }
531 
532 
534 {
535  Ifx_MSC *mscSfr = msc->msc;
536 
537  /* Configure the number of SRHE, SRLE Bits transmitted and Extension Enable */
538  {
539  Ifx_MSC_DSCE dsce;
540 
541  /* Read the DSCE register content */
542  dsce.U = mscSfr->DSCE.U;
543  /* Extension Enable */
544  dsce.B.EXEN = config->downstreamExtensionConfig.extension;
545  /* Configure the number of SRLE Bits transmitted */
547  /* Configure the number of SRHE Bits transmitted */
549 
550  mscSfr->DSCE.U = dsce.U;
551  }
552 
553  /* Select Source for SRLE */
555 
556  /* Select Source for SRHE */
558 
559  /* Emergency Stop Enable for Bit */
561 
562  /* Passive Phase Length at Data and Control Frames Extension */
563  {
564  Ifx_MSC_DSTE dste;
565 
566  /* Read the DSTE register content */
567  dste.U = mscSfr->DSTE.U;
568  /* Passive Phase Length at Control Frames Extension */
570  /* Passive Phase Length at Data Frames Extension */
572  /* N Divider for Downstream */
573  dste.B.NDD = config->downstreamExtensionConfig.nDividerDownstream;
574 
575  mscSfr->DSTE.U = dste.U;
576  }
577 }
578 
579 
581 {
582  Ifx_MSC *mscSfr = msc->msc;
583  uint16 data = 0;
584 
585  /* Check for valid flag */
586  if (!IfxMsc_getUpstreamValidFlag(mscSfr, upstreamIdx))
587  {
588  return -1;
589  }
590 
591  /* Clear the flag */
592  IfxMsc_clearUpstreamValidFlag(mscSfr, upstreamIdx);
593 
594  /* Read the data */
595  data = IfxMsc_getData(mscSfr, upstreamIdx);
596 
597  return data;
598 }
599 
600 
602 {
603  Ifx_MSC *mscSfr = msc->msc;
604 
605  /* Downstream command */
606  mscSfr->DC.U = command;
607 }
608 
609 
610 void IfxMsc_Msc_sendData(IfxMsc_Msc *msc, uint16 dataLow, uint16 dataHigh)
611 {
612  Ifx_MSC *mscSfr = msc->msc;
613 
614  {
615  Ifx_MSC_DD dd;
616  dd.B.DDL = dataLow;
617  dd.B.DDH = dataHigh;
618 
619  /* Downstream Data */
620  mscSfr->DD.U = dd.U;
621  }
622 
623  /* Send data */
624  mscSfr->ISC.B.SDP = 1;
625 }
626 
627 
628 void IfxMsc_Msc_sendDataExtension(IfxMsc_Msc *msc, uint32 data, uint32 dataExtension)
629 {
630  Ifx_MSC *mscSfr = msc->msc;
631 
632  /* Downstream Data (mirror) + extension */
633  mscSfr->DDE.U = dataExtension;
634  mscSfr->DDM.U = data;
635 
636  /* Send data */
637  mscSfr->ISC.B.SDP = 1;
638 }
639 
640 
642 {
643  Ifx_MSC *mscSfr = msc->msc;
644 
645  /* Downstream Data High only */
646  mscSfr->DD.B.DDH = data;
647 
648  /* Send data */
649  mscSfr->ISC.B.SDP = 1;
650 }
651 
652 
654 {
655  Ifx_MSC *mscSfr = msc->msc;
656 
657  /* Downstream Data Low only */
658  mscSfr->DD.B.DDL = data;
659 
660  /* Send data */
661  mscSfr->ISC.B.SDP = 1;
662 }
663 
664 
666 {
667  Ifx_MSC *mscSfr = msc->msc;
668 
669  IfxMsc_setCommandTarget(mscSfr, enX);
670 }
671 
672 
674 {
675  Ifx_MSC *mscSfr = msc->msc;
676 
677  /* Set data low target */
678  IfxMsc_setDataLowTarget(mscSfr, enXLow);
679  /* Set data high target */
680  IfxMsc_setDataHighTarget(mscSfr, enXHigh);
681 }