iLLD_TC29x  1.0
IfxSent.c
Go to the documentation of this file.
1 /**
2  * \file IfxSent.c
3  * \brief SENT 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 /******************************************************************************/
27 /*----------------------------------Includes----------------------------------*/
28 /******************************************************************************/
29 
30 #include "IfxSent.h"
31 
32 /******************************************************************************/
33 /*-------------------------Function Implementations---------------------------*/
34 /******************************************************************************/
35 
37 {
38  float32 fFracDiv = IfxSent_getModuleClock(sent);
39  float32 fPdiv = fFracDiv / (float32)(sent->CH[channelId].CPDR.B.PDIV + 1);
40 
41  uint32 div = sent->CH[channelId].CFDR.B.DIV;
42 
43  if (div > 0)
44  {
45  float32 fTick = (fPdiv * 56) / div;
46  return 1 / fTick;
47  }
48  else
49  {
50  return 0.0;
51  }
52 }
53 
54 
56 {
58 
59  uint32 rmc = sent->CLC.B.RMC;
60 
61  if (rmc < 1)
62  {
63  rmc = 1;
64  }
65 
66  float32 fclc = fsys / rmc;
67 
68  Ifx_SENT_FDR fdr;
69  fdr.U = sent->FDR.U;
70 
71  float32 kernelFreq = 0.0;
72 
73  if (fdr.B.DM == 1)
74  {
75  kernelFreq = fclc / (1024 - fdr.B.STEP);
76  }
77  else if (fdr.B.DM == 2)
78  {
79  kernelFreq = (fclc * fdr.B.STEP) / 1024;
80  }
81 
82  return kernelFreq;
83 }
84 
85 
86 void IfxSent_initializeChannelUnitTime(Ifx_SENT *sent, IfxSent_ChannelId channelId, float32 tUnit)
87 {
88  float32 fFracDiv = IfxSent_getModuleClock(sent);
89 
90  /* const uint32 divMin = 560; */
91  const uint32 divMax = 3276;
92 
93  uint32 pDiv;
94  uint32 fDiv;
95 
96  float32 tResult;
97  tResult = fFracDiv * 56 * tUnit;
98  pDiv = tResult / divMax;
99  fDiv = tResult / pDiv;
100 
101  if (fDiv > divMax)
102  {
103  pDiv = pDiv + 1;
104  fDiv = tResult / pDiv;
105  }
106 
107  if ((pDiv > 1024) || (pDiv < 1))
108  {
109  pDiv = 1025;
110  fDiv = tResult / 1024;
111  }
112 
113  IfxSent_setChannelPreDivider(sent, channelId, (uint16)pDiv - 1);
114  IfxSent_setChannelFractionalDivider(sent, channelId, (uint16)fDiv);
115 }
116 
117 
118 void IfxSent_initializeModuleClock(Ifx_SENT *sent, IfxSent_ClockDividerMode dividerMode, uint16 stepValue)
119 {
120  Ifx_SENT_FDR tempFDR;
121  tempFDR.U = 0;
122  tempFDR.B.STEP = stepValue;
123  tempFDR.B.DM = dividerMode;
124  sent->FDR.U = tempFDR.U;
125 }
126 
127 
128 void IfxSent_resetModule(Ifx_SENT *sent)
129 {
131 
133  sent->KRST1.B.RST = 1; /* Only if both Kernel reset bits are set a reset is executed */
134  sent->KRST0.B.RST = 1;
135  IfxScuWdt_setCpuEndinit(passwd);
136 
137  while (0 == sent->KRST0.B.RSTSTAT) /* Wait until reset is executed */
138 
139  {}
140 
142  sent->KRSTCLR.B.CLR = 1; /* Clear Kernel reset status bit */
143  IfxScuWdt_setCpuEndinit(passwd);
144 }