rusEFI
The most advanced open source ECU
Loading...
Searching...
No Matches
Functions | Variables
adc_inputs.cpp File Reference

Detailed Description

Low level ADC code.

Date
Jan 14, 2013
Author
Andrey Belomutskiy, (c) 2012-2020

Definition in file adc_inputs.cpp.

Functions

float PUBLIC_API_WEAK getAnalogInputDividerCoefficient (adc_channel_e)
 
float PUBLIC_API_WEAK boardAdjustVoltage (float voltage, adc_channel_e)
 
int PUBLIC_API_WEAK boardGetAnalogDiagnostic ()
 
int PUBLIC_API_WEAK boardGetAnalogInputDiagnostic (adc_channel_e channel, float)
 
int analogGetDiagnostic ()
 
AdcChannelMode getAdcMode (adc_channel_e hwChannel)
 
float getMCUInternalTemperature ()
 
int getInternalAdcValue (const char *msg, adc_channel_e hwChannel)
 
static void printAdcValue (int channel)
 
static void printAdcChannedReport (const char *prefix, int internalIndex, adc_channel_e hwChannel)
 
void printFullAdcReport (void)
 
static void setAdcDebugReporting (int value)
 
void updateSlowAdc (efitick_t nowNt)
 
void addFastAdcChannel (const char *, adc_channel_e hwChannel)
 
void removeChannel (const char *, adc_channel_e hwChannel)
 
 __attribute__ ((weak)) void setAdcChannelOverrides()
 
static void configureInputs ()
 
void waitForSlowAdc (uint32_t lastAdcCounter)
 
void initAdcInputs ()
 
void printFullAdcReportIfNeeded (void)
 

Variables

AdcDevice fastAdc
 
static volatile NO_CACHE adcsample_t slowAdcSamples [SLOW_ADC_CHANNEL_COUNT]
 
static uint32_t slowAdcConversionCount = 0
 
static float mcuTemperature
 
static AdcChannelMode adcHwChannelMode [EFI_ADC_TOTAL_CHANNELS]
 
static int adcDebugReporting = false
 
 adc_channel_e
 

Function Documentation

◆ __attribute__()

__attribute__ ( (weak)  )

Definition at line 203 of file adc_inputs.cpp.

203{ }

◆ addFastAdcChannel()

void addFastAdcChannel ( const char name,
adc_channel_e  hwChannel 
)

Definition at line 175 of file adc_inputs.cpp.

175 {
176 if (!isAdcChannelValid(hwChannel)) {
177 return;
178 }
179
180#if EFI_USE_FAST_ADC
181 fastAdc.enableChannel(hwChannel);
182#endif
183
185 // Nothing to do for slow channels, input is mapped to analog in init_sensors.cpp
186}
static AdcChannelMode adcHwChannelMode[EFI_ADC_TOTAL_CHANNELS]
AdcDevice fastAdc
bool isAdcChannelValid(adc_channel_e hwChannel)
Definition adc_inputs.h:21
int enableChannel(adc_channel_e hwChannel)

Referenced by addAdcChannelForTrigger(), configureInputs(), and setAdcChannelOverrides().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ analogGetDiagnostic()

int analogGetDiagnostic ( )

Definition at line 41 of file adc_inputs.cpp.

42{
43 /* TODO: debounce? */
45}
int PUBLIC_API_WEAK boardGetAnalogDiagnostic()

Referenced by SensorChecker::onSlowCallback().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ boardAdjustVoltage()

float PUBLIC_API_WEAK boardAdjustVoltage ( float  voltage,
adc_channel_e  hwChannel 
)

Definition at line 15 of file adc_inputs.cpp.

15 {
16 // a hack useful when we do not trust voltage just after board EN was turned on. is this just hiding electrical design flaws?
17 return voltage;
18}

Referenced by adcGetScaledVoltage().

Here is the caller graph for this function:

◆ boardGetAnalogDiagnostic()

int PUBLIC_API_WEAK boardGetAnalogDiagnostic ( )

Definition at line 23 of file adc_inputs.cpp.

23 {
24 return 0;
25}

Referenced by analogGetDiagnostic(), and boardGetAnalogInputDiagnostic().

Here is the caller graph for this function:

◆ boardGetAnalogInputDiagnostic()

int PUBLIC_API_WEAK boardGetAnalogInputDiagnostic ( adc_channel_e  channel,
float   
)

Definition at line 28 of file adc_inputs.cpp.

28 {
29#if EFI_PROD_CODE
30 /* for on-chip ADC inputs we check common analog health */
33 }
34#endif // EFI_PROD_CODE
35
36 /* input is outside chip/ECU */
37 return 0;
38}
uint16_t channel
Definition adc_inputs.h:109
bool isAdcChannelOnChip(adc_channel_e hwChannel)
Definition adc_inputs.h:34
Here is the call graph for this function:

◆ configureInputs()

static void configureInputs ( )
static

order of analog channels here is totally random and has no meaning we also have some weird implementation with internal indices - that all has no meaning, it's just a random implementation which does not mean anything.

Definition at line 205 of file adc_inputs.cpp.

205 {
207
208 /**
209 * order of analog channels here is totally random and has no meaning
210 * we also have some weird implementation with internal indices - that all has no meaning, it's just a random implementation
211 * which does not mean anything.
212 */
213
215
216 // not currently used addFastAdcChannel("Vref", engineConfiguration->vRefAdcChannel, ADC_SLOW);
217
219
221}
void addFastAdcChannel(const char *, adc_channel_e hwChannel)
void setAdcChannelOverrides()
static constexpr engine_configuration_s * engineConfiguration

Referenced by initAdcInputs().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ getAdcMode()

AdcChannelMode getAdcMode ( adc_channel_e  hwChannel)

Definition at line 69 of file adc_inputs.cpp.

69 {
70 return adcHwChannelMode[hwChannel];
71}

Referenced by AdcSubscription::PrintInfo().

Here is the caller graph for this function:

◆ getAnalogInputDividerCoefficient()

float PUBLIC_API_WEAK getAnalogInputDividerCoefficient ( adc_channel_e  hwChannel)

◆ getInternalAdcValue()

int getInternalAdcValue ( const char msg,
adc_channel_e  hwChannel 
)

Definition at line 77 of file adc_inputs.cpp.

77 {
78 if (!isAdcChannelValid(hwChannel)) {
79 warning(ObdCode::CUSTOM_OBD_ANALOG_INPUT_NOT_CONFIGURED, "ADC: %s input is not configured", msg);
80 return -1;
81 }
82
83#if EFI_USE_FAST_ADC
84 if (adcHwChannelMode[hwChannel] == AdcChannelMode::Fast) {
85 return fastAdc.getAvgAdcValue(hwChannel);
86 }
87#endif // EFI_USE_FAST_ADC
88
89 return slowAdcSamples[hwChannel - EFI_ADC_0];
90}
static volatile NO_CACHE adcsample_t slowAdcSamples[SLOW_ADC_CHANNEL_COUNT]
adcsample_t getAvgAdcValue(adc_channel_e hwChannel)
bool warning(ObdCode code, const char *fmt,...)
@ CUSTOM_OBD_ANALOG_INPUT_NOT_CONFIGURED
Here is the call graph for this function:

◆ getMCUInternalTemperature()

float getMCUInternalTemperature ( void  )

Definition at line 73 of file adc_inputs.cpp.

73 {
74 return mcuTemperature;
75}
static float mcuTemperature

Referenced by populateFrame(), and updateMiscSensors().

Here is the caller graph for this function:

◆ initAdcInputs()

void initAdcInputs ( )

Definition at line 231 of file adc_inputs.cpp.

231 {
232 efiPrintf("initAdcInputs()");
233
235
236 // migrate to 'enable adcdebug'
238
239#if EFI_INTERNAL_ADC
240 portInitAdc();
241
242#if EFI_USE_FAST_ADC
243 // After this point fastAdc is not allowed to add channels
244 fastAdc.init();
245#endif // EFI_USE_FAST_ADC
246
248#else // ! EFI_INTERNAL_ADC
249 efiPrintf("ADC disabled");
250#endif // EFI_INTERNAL_ADC
251
252 // Workaround to pre-feed all sensors with some data...
253 chThdSleepMilliseconds(1);
255}
void updateSlowAdc(efitick_t nowNt)
static void setAdcDebugReporting(int value)
static void printAdcValue(int channel)
static void configureInputs()
void addConsoleActionI(const char *token, VoidInt callback)
Register a console command with one Integer parameter.
void(* VoidInt)(int)
void portInitAdc()
Definition mpu_util.cpp:256
efitick_t getTimeNowNt()
Definition efitime.cpp:19

Referenced by initHardware().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ printAdcChannedReport()

static void printAdcChannedReport ( const char prefix,
int  internalIndex,
adc_channel_e  hwChannel 
)
static

Definition at line 103 of file adc_inputs.cpp.

104{
105 if (isAdcChannelValid(hwChannel)) {
106 ioportid_t port = getAdcChannelPort("print", hwChannel);
107 int pin = getAdcChannelPin(hwChannel);
108 int adcValue = adcGetRawValue("print", hwChannel);
109 float volts = adcGetRawVoltage("print", hwChannel);
110 float voltsInput = adcGetScaledVoltage("print", hwChannel);
111 /* Human index starts from 1 */
112 efiPrintf(" %s ch[%2d] @ %s%d ADC%d 12bit=%4d %.3fV input %.3fV",
113 prefix, internalIndex, portname(port), pin,
114 /* TODO: */ hwChannel - EFI_ADC_0 + 1,
115 adcValue, volts, voltsInput);
116 }
117}
float adcGetScaledVoltage(const char *msg, adc_channel_e hwChannel)
float adcGetRawVoltage(const char *msg, adc_channel_e hwChannel)
int getAdcChannelPin(adc_channel_e hwChannel)
ioportid_t getAdcChannelPort(const char *msg, adc_channel_e hwChannel)
const char * portname(ioportid_t GPIOx)
GPIO_TypeDef * ioportid_t
Port Identifier.
brain_pin_e pin
Definition stm32_adc.cpp:15

Referenced by printFullAdcReport().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ printAdcValue()

static void printAdcValue ( int  channel)
static

Definition at line 92 of file adc_inputs.cpp.

92 {
93 /* Do this check before conversion to adc_channel_e that is uint8_t based */
94 if ((channel < EFI_ADC_NONE) || (channel >= EFI_ADC_TOTAL_CHANNELS)) {
95 efiPrintf("Invalid ADC channel %d", channel);
96 return;
97 }
98 int adcValue = adcGetRawValue("print", (adc_channel_e)channel);
99 float voltsInput = adcRawValueToScaledVoltage(adcValue, (adc_channel_e)channel);
100 efiPrintf("adc %d input %.3fV", channel, voltsInput);
101}
adc_channel_e

Referenced by initAdcInputs().

Here is the caller graph for this function:

◆ printFullAdcReport()

void printFullAdcReport ( void  )

Definition at line 119 of file adc_inputs.cpp.

119 {
120#if EFI_USE_FAST_ADC
121 efiPrintf("fast %u samples", engine->outputChannels.fastAdcConversionCount);
122
123 for (int internalIndex = 0; internalIndex < fastAdc.size(); internalIndex++) {
124 adc_channel_e hwChannel = fastAdc.getAdcChannelByInternalIndex(internalIndex);
125
126 printAdcChannedReport("F", internalIndex, hwChannel);
127 }
128#endif // EFI_USE_FAST_ADC
129 efiPrintf("slow %lu samples", slowAdcConversionCount);
130
131 /* we assume that all slow ADC channels are enabled */
132 for (int internalIndex = 0; internalIndex < ADC_MAX_CHANNELS_COUNT; internalIndex++) {
133 adc_channel_e hwChannel = static_cast<adc_channel_e>(internalIndex + EFI_ADC_0);
134
135 printAdcChannedReport("S", internalIndex, hwChannel);
136 }
137}
static uint32_t slowAdcConversionCount
static void printAdcChannedReport(const char *prefix, int internalIndex, adc_channel_e hwChannel)
int size() const
adc_channel_e getAdcChannelByInternalIndex(int index) const
TunerStudioOutputChannels outputChannels
Definition engine.h:105
static Engine *const engine
Definition engine.h:388

Referenced by initSettings(), and printFullAdcReportIfNeeded().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ printFullAdcReportIfNeeded()

void printFullAdcReportIfNeeded ( void  )

Definition at line 257 of file adc_inputs.cpp.

257 {
259 return;
261}
static int adcDebugReporting
void printFullAdcReport(void)

Referenced by updateDevConsoleState().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ removeChannel()

void removeChannel ( const char name,
adc_channel_e  hwChannel 
)

Definition at line 188 of file adc_inputs.cpp.

188 {
189 if (!isAdcChannelValid(hwChannel)) {
190 return;
191 }
192#if EFI_USE_FAST_ADC
193 if (adcHwChannelMode[hwChannel] == AdcChannelMode::Fast) {
194 /* TODO: */
195 //fastAdc.disableChannel(hwChannel);
196 }
197#endif
198
200}

Referenced by setAdcChannelOverrides().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ setAdcDebugReporting()

static void setAdcDebugReporting ( int  value)
static

Definition at line 139 of file adc_inputs.cpp.

139 {
140 adcDebugReporting = value;
141 efiPrintf("adcDebug=%d", adcDebugReporting);
142}

Referenced by initAdcInputs().

Here is the caller graph for this function:

◆ updateSlowAdc()

void updateSlowAdc ( efitick_t  nowNt)

Definition at line 144 of file adc_inputs.cpp.

144 {
145 {
147
148 /* drop volatile type qualifier - this is safe */
151 return;
152 }
153
154 // Ask the port to sample the MCU temperature
156 if (mcuTemperature > 150.0f || mcuTemperature < -50.0f) {
157 /*
158 * we have a sporadic issue with this check todo https://github.com/rusefi/rusefi/issues/2552
159 */
160 //criticalError("Invalid CPU temperature measured %f", degrees);
161 }
162 }
163
164 {
166
168
170
171 protectedGpio_check(nowNt);
172 }
173}
static void UpdateSubscribers(efitick_t nowNt)
bool readSlowAnalogInputs(adcsample_t *convertedSamples)
Definition mpu_util.cpp:269
float getMcuTemperature()
Definition mpu_util.cpp:264
uint16_t adcsample_t
ADC sample data type.
@ AdcConversionSlow
@ AdcProcessSlow
void protectedGpio_check(efitick_t nowNt)

Referenced by initAdcInputs(), and MainLoop::PeriodicTask().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ waitForSlowAdc()

void waitForSlowAdc ( uint32_t  lastAdcCounter)

Definition at line 223 of file adc_inputs.cpp.

223 {
224 // note that having ADC reading is one thing while having new sensor API is a totally different thing!
225 // todo: use sync.objects?
226 while (slowAdcConversionCount <= lastAdcCounter) {
227 chThdSleepMilliseconds(1);
228 }
229}

Referenced by StepperMotorBase::setInitialPosition().

Here is the caller graph for this function:

Variable Documentation

◆ adc_channel_e

adc_channel_e
Initial value:
{
return 0

Definition at line 266 of file adc_inputs.cpp.

Referenced by printAdcValue(), and printFullAdcReport().

◆ adcDebugReporting

int adcDebugReporting = false
static

Definition at line 67 of file adc_inputs.cpp.

Referenced by printFullAdcReportIfNeeded(), and setAdcDebugReporting().

◆ adcHwChannelMode

AdcChannelMode adcHwChannelMode[EFI_ADC_TOTAL_CHANNELS]
static

◆ fastAdc

AdcDevice fastAdc
extern

◆ mcuTemperature

float mcuTemperature
static

Definition at line 62 of file adc_inputs.cpp.

Referenced by getMCUInternalTemperature(), and updateSlowAdc().

◆ slowAdcConversionCount

uint32_t slowAdcConversionCount = 0
static

Definition at line 60 of file adc_inputs.cpp.

Referenced by printFullAdcReport(), updateSlowAdc(), and waitForSlowAdc().

◆ slowAdcSamples

volatile NO_CACHE adcsample_t slowAdcSamples[SLOW_ADC_CHANNEL_COUNT]
static

Definition at line 58 of file adc_inputs.cpp.

Referenced by getInternalAdcValue(), and updateSlowAdc().

Go to the source code of this file.