iLLD_TC27xC  1.0
IfxDsadc.c
Go to the documentation of this file.
1 /**
2  * \file IfxDsadc.c
3  * \brief DSADC basic functionality
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 /*----------------------------------Includes----------------------------------*/
27 /******************************************************************************/
28 
29 #include "IfxDsadc.h"
30 #include "Scu/Std/IfxScuCcu.h"
31 
32 /******************************************************************************/
33 /*-------------------------Function Implementations---------------------------*/
34 /******************************************************************************/
35 
36 volatile Ifx_SRC_SRCR *IfxDsadc_getAuxSrc(Ifx_DSADC *dsadc, IfxDsadc_ChannelId channel)
37 {
38  return &(MODULE_SRC.DSADC.DSADC[channel].SRA);
39 }
40 
41 
43 {
44  float32 frequency = IfxDsadc_getMainCombOutFreq(dsadc, channel);
45 
46  frequency = frequency / ((float32)1.0 + dsadc->CH[channel].IWCTR.B.NVALINT);
47  Ifx_DSADC_CH_FCFGM fcfgm = dsadc->CH[channel].FCFGM;
48 
49  if (fcfgm.B.FIR0EN != 0)
50  {
51  frequency = frequency / 2;
52  }
53 
54  if (fcfgm.B.FIR1EN != 0)
55  {
56  frequency = frequency / 2;
57  }
58 
59  return frequency;
60 }
61 
62 
64 {
65  float32 frequency = IfxDsadc_getModulatorClockFreq(dsadc, channel);
66 
67  return frequency / ((float32)1.0 + dsadc->CH[channel].FCFGC.B.CFMDF);
68 }
69 
70 
72 {
73  Ifx_DSADC_CH_FCFGC fcfgc = dsadc->CH[channel].FCFGC;
74  Ifx_DSADC_CH_FCFGM fcfgm = dsadc->CH[channel].FCFGM;
75  Ifx_DSADC_CH_DICFG dicfg = dsadc->CH[channel].DICFG;
76  Ifx_DSADC_CH_IWCTR iwctr = dsadc->CH[channel].IWCTR;
77  float32 tsMod = 1.0 / IfxDsadc_getModulatorClockFreq(dsadc, channel);
78  float32 tsComb = tsMod * (1 + fcfgc.B.CFMDF);
79  float32 tsFir0 = tsComb * (1 + fcfgm.B.FIR0EN);
80  float32 tsFir1 = tsFir0 * (1 + fcfgm.B.FIR1EN);
81 
82  float32 gdDsA = 7 * tsMod;
83  uint32 combN = (1 + fcfgc.B.CFMDF);
84  float32 gdComb = tsMod * ((fcfgc.B.CFMC < 3) ? (0.5 * (fcfgc.B.CFMC + 1) * combN) : (combN + 1));
85  float32 gdFir0 = (fcfgm.B.FIR0EN != 0) ? (0.5 * 8 * tsComb) : 0;
86  float32 gdFir1 = (fcfgm.B.FIR1EN != 0) ? (0.5 * 28 * tsFir0) : 0;
87  float32 gdInt = (dicfg.B.ITRMODE == IfxDsadc_IntegratorTrigger_bypassed) ? 0 : (0.5 * (iwctr.B.NVALINT + 1) * tsFir1);
88 
89  return gdDsA + gdComb + gdFir0 + gdFir1 + gdInt;
90 }
91 
92 
93 volatile Ifx_SRC_SRCR *IfxDsadc_getMainSrc(Ifx_DSADC *dsadc, IfxDsadc_ChannelId channel)
94 {
95  return &(MODULE_SRC.DSADC.DSADC[channel].SRM);
96 }
97 
98 
100 {
101  float32 sourceFreq = IfxDsadc_getModulatorInputClockFreq(dsadc);
102 
103  return sourceFreq / ((dsadc->CH[channel].MODCFG.B.DIVM + 1) * 2);
104 }
105 
106 
108 {
109  float32 result;
110 
111  switch (dsadc->GLOBCFG.B.MCSEL)
112  {
114  result = IfxScuCcu_getOsc0Frequency();
115  break;
118  break;
120  result = IfxScuCcu_getSpbFrequency();
121  break;
122  default:
123  result = 0;
124  break;
125  }
126 
127  return result;
128 }