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

Detailed Description

Low level internal ADC code.

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

Definition in file adc_inputs.h.

Typedefs

using AdcToken = uint32_t
 
using AdcTockenInternal = union { AdcToken token
 

Enumerations

enum class  AdcChannelMode : char { Off , Slow , Fast }
 

Functions

float getAnalogInputDividerCoefficient (adc_channel_e)
 
float boardAdjustVoltage (float voltage, adc_channel_e hwChannel)
 
int boardGetAnalogInputDiagnostic (adc_channel_e, float voltage)
 
bool isAdcChannelValid (adc_channel_e hwChannel)
 
bool isAdcChannelOnChip (adc_channel_e hwChannel)
 
bool isAdcChannelOffChip (adc_channel_e hwChannel)
 
ObdCode analogGetDiagnostic ()
 
void adcInputsUpdateSubscribers (efitick_t nowNt)
 
AdcChannelMode getAdcMode (adc_channel_e hwChannel)
 
void initAdcInputs ()
 
void printFullAdcReportIfNeeded (void)
 
int getInternalAdcValue (const char *msg, adc_channel_e index)
 
void addFastAdcChannel (const char *name, adc_channel_e hwChannel)
 
void removeChannel (const char *name, adc_channel_e hwChannel)
 
struct { 
 
   uint16_t   adc 
 
   uint16_t   channel 
 
__attribute__ ((packed)) 
 
AdcToken enableFastAdcChannel (const char *msg, adc_channel_e channel)
 
adcsample_t getFastAdc (AdcToken token)
 
const ADCConversionGroup * getKnockConversionGroup (uint8_t channelIdx)
 
void onKnockSamplingComplete ()
 
float getMCUInternalTemperature (void)
 
float getMCUVref (void)
 
void waitForSlowAdc (uint32_t lastAdcCounter=1)
 
void printFullAdcReport (void)
 

Variables

static constexpr AdcToken invalidAdcToken = (AdcToken)(-1)
 

Typedef Documentation

◆ AdcTockenInternal

using AdcTockenInternal = union { AdcToken token

Definition at line 100 of file adc_inputs.h.

◆ AdcToken

using AdcToken = uint32_t

Definition at line 98 of file adc_inputs.h.

Enumeration Type Documentation

◆ AdcChannelMode

enum class AdcChannelMode : char
strong
Enumerator
Off 
Slow 
Fast 

Definition at line 77 of file adc_inputs.h.

77 : char {
78 Off,
79 Slow,
80 Fast
81};

Function Documentation

◆ __attribute__()

struct @29 __attribute__ ( (packed)  )

Definition at line 38 of file tooth_logger.h.

40 {
41 // the whole order of all packet bytes is reversed, not just the 'endian-swap' integers
42 uint32_t timestamp;
43 // unfortunately all these fields are required by TS...
44 bool priLevel : 1;
45 bool secLevel : 1;
46 bool trigger : 1;
47 bool sync : 1;
48 bool coil : 1;
49 bool injector : 1;
static bool sync(void *instance)
composite_logger_s

◆ adcInputsUpdateSubscribers()

void adcInputsUpdateSubscribers ( efitick_t  nowNt)

Definition at line 181 of file adc_inputs.cpp.

181 {
182 adcOnchipSlowUpdate(nowNt);
183
184 {
186
188
189 protectedGpio_check(nowNt);
190 }
191}
void adcOnchipSlowUpdate(efitick_t nowNt)
static void UpdateSubscribers(efitick_t nowNt)
@ 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:

◆ addFastAdcChannel()

void addFastAdcChannel ( const char name,
adc_channel_e  hwChannel 
)

Definition at line 193 of file adc_inputs.cpp.

193 {
194 if (!isAdcChannelValid(hwChannel)) {
195 return;
196 }
197
198#if EFI_USE_FAST_ADC
199 fastAdc.enableChannel(hwChannel);
200#endif
201
203 // Nothing to do for slow channels, input is mapped to analog in init_sensors.cpp
204}
static AdcChannelMode adcHwChannelMode[EFI_ADC_TOTAL_CHANNELS]
AdcDevice fastAdc
bool isAdcChannelValid(adc_channel_e hwChannel)
Definition adc_inputs.h:23
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()

ObdCode analogGetDiagnostic ( )

Definition at line 59 of file adc_inputs.cpp.

60{
61 /* TODO: debounce? */
63 if (code != ObdCode::None) {
64 return code;
65 }
66
68}
static ObdCode analogGetVrefDiagnostic()
ObdCode PUBLIC_API_WEAK boardGetAnalogDiagnostic()
uint8_t code
Definition bluetooth.cpp:40

Referenced by SensorChecker::onSlowCallback().

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

◆ boardAdjustVoltage()

float 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:

◆ boardGetAnalogInputDiagnostic()

int boardGetAnalogInputDiagnostic ( adc_channel_e  hwChannel,
float  voltage 
)

Definition at line 262 of file board_configuration.cpp.

262 {
263 /* we do not check voltage for valid ragne yet */
264 (void)voltage;
265
266 switch (hwChannel) {
267 /* inputs that may be affected by incorrect reference voltage */
268 case MM176_IN_TPS_ANALOG:
269 case MM176_IN_TPS2_ANALOG:
270 case MM176_IN_PPS1_ANALOG:
271 case MM176_IN_PPS2_ANALOG:
272 case MM176_IN_IAT_ANALOG:
273 case MM176_IN_AT1_ANALOG:
274 case MM176_IN_CLT_ANALOG:
275 case MM176_IN_AT2_ANALOG:
276 //case MM176_IN_O2S_ANALOG:
277 //case MM176_IN_O2S2_ANALOG:
278 case MM176_IN_MAP1_ANALOG:
279 case MM176_IN_MAP2_ANALOG:
280 case MM176_IN_AUX1_ANALOG:
281 case MM176_IN_AUX2_ANALOG:
282 case MM176_IN_AUX3_ANALOG:
283 case MM176_IN_AUX4_ANALOG:
284 /* TODO: more? */
285 return (boardGetAnalogDiagnostic() == ObdCode::None) ? 0 : -1;
286 /* all other inputs should not rely on output 5V */
287 default:
288 return 0;
289 }
290
291 return 0;
292}
ObdCode boardGetAnalogDiagnostic()

Referenced by adcGetRawVoltage().

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

◆ enableFastAdcChannel()

AdcToken enableFastAdcChannel ( const char msg,
adc_channel_e  channel 
)

Definition at line 279 of file mpu_util.cpp.

279 {
281 return invalidAdcToken;
282 }
283
284 // TODO: implement me!
285 return invalidAdcToken;
286}
static constexpr AdcToken invalidAdcToken
Definition adc_inputs.h:110
uint16_t channel
Definition adc_inputs.h:104

Referenced by calcFastAdcIndexes().

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 110 of file adc_inputs.cpp.

110 {
111 return adcHwChannelMode[hwChannel];
112}

Referenced by AdcSubscription::PrintInfo().

Here is the caller graph for this function:

◆ getAnalogInputDividerCoefficient()

float getAnalogInputDividerCoefficient ( adc_channel_e  hwChannel)

Definition at line 242 of file hellen_common.cpp.

242 {
243#if (HELLEN_BOARD_MM64 == TRUE)
244 (void)hwChannel;
245 if (0)
246#endif
247#if (HELLEN_BOARD_MM100 == TRUE)
248 if (hwChannel == MM100_IN_CRANK_ANALOG) [[unlikely]]
249#endif
250#if (HELLEN_BOARD_MM144 == TRUE)
251 if (hwChannel == H144_IN_CRANK_ANALOG) [[unlikely]]
252#endif
253#if (HELLEN_BOARD_MM176 == TRUE)
254 if (hwChannel == MM176_IN_CRANK_ANALOG) [[unlikely]]
255#endif
256 {
257 // (4.7K || 5.1K) + 4.7K divider
258 // 4.7K || 5.1K == 2.445K
259 return (4.7f + 2.445f) / 4.7f;
260 }
261
263}
static constexpr engine_configuration_s * engineConfiguration

Referenced by adcGetScaledVoltage().

Here is the caller graph for this function:

◆ getFastAdc()

adcsample_t getFastAdc ( AdcToken  token)

Definition at line 288 of file mpu_util.cpp.

288 {
289 if (token == invalidAdcToken) {
290 return 0;
291 }
292
293 // TODO: implement me!
294 return 0;
295}

Referenced by onFastAdcComplete().

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

◆ getInternalAdcValue()

int getInternalAdcValue ( const char msg,
adc_channel_e  index 
)

Definition at line 116 of file adc_inputs.cpp.

116 {
117 if (!isAdcChannelValid(hwChannel)) {
118 warning(ObdCode::CUSTOM_OBD_ANALOG_INPUT_NOT_CONFIGURED, "ADC: %s input is not configured", msg);
119 return -1;
120 }
121
122#if EFI_USE_FAST_ADC
123 if (adcHwChannelMode[hwChannel] == AdcChannelMode::Fast) {
124 return fastAdc.getAvgAdcValue(hwChannel);
125 }
126#endif // EFI_USE_FAST_ADC
127
128 return adcOnchipSlowGetAvgRaw(hwChannel);
129}
adcsample_t adcOnchipSlowGetAvgRaw(adc_channel_e hwChannel)
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:

◆ getKnockConversionGroup()

const ADCConversionGroup * getKnockConversionGroup ( uint8_t  channelIdx)

Definition at line 409 of file stm32_adc_v2.cpp.

409 {
410#if KNOCK_HAS_CH2
411 if (channelIdx == 1) {
412 return &adcConvGroupCh2;
413 }
414#else
415 (void)channelIdx;
416#endif // KNOCK_HAS_CH2
417
418 return &adcConvGroupCh1;
419}
float uint8_t channelIdx
static const ADCConversionGroup adcConvGroupCh2
static const ADCConversionGroup adcConvGroupCh1

Referenced by onStartKnockSampling().

Here is the caller graph for this function:

◆ getMCUInternalTemperature()

float getMCUInternalTemperature ( void  )

Definition at line 78 of file adc_onchip_slow.cpp.

78 {
79 return mcuTemperature;
80}
static float mcuTemperature

Referenced by populateFrame(), and updateMiscSensors().

Here is the caller graph for this function:

◆ getMCUVref()

float getMCUVref ( void  )

Definition at line 82 of file adc_onchip_slow.cpp.

82 {
83 return mcuVrefVoltage;
84}
static float mcuVrefVoltage

Referenced by analogGetVrefDiagnostic(), and updateMiscSensors().

Here is the caller graph for this function:

◆ initAdcInputs()

void initAdcInputs ( )

Definition at line 241 of file adc_inputs.cpp.

241 {
242 efiPrintf("initAdcInputs()");
243
245
246 // migrate to 'enable adcdebug'
248
249#if EFI_INTERNAL_ADC
250 // This will start HW for all used ADCs
251 portInitAdc();
252
253#if EFI_USE_FAST_ADC
254 // After this point fastAdc is not allowed to add channels
255 fastAdc.init();
256#endif // EFI_USE_FAST_ADC
257
259#else // ! EFI_INTERNAL_ADC
260 efiPrintf("ADC disabled");
261#endif // EFI_INTERNAL_ADC
262
263 // Workaround to pre-feed all sensors with some data...
264 chThdSleepMilliseconds(1);
266}
void adcInputsUpdateSubscribers(efitick_t nowNt)
static void setAdcDebugReporting(int value)
static void printAdcValue(int channel)
static void configureInputs()
void init(void)
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:

◆ isAdcChannelOffChip()

bool isAdcChannelOffChip ( adc_channel_e  hwChannel)
inline

Definition at line 40 of file adc_inputs.h.

40 {
41 return (isAdcChannelValid(hwChannel) && (hwChannel > EFI_ADC_ONCHIP_LAST));
42}
Here is the call graph for this function:

◆ isAdcChannelOnChip()

bool isAdcChannelOnChip ( adc_channel_e  hwChannel)
inline

Definition at line 36 of file adc_inputs.h.

36 {
37 return (isAdcChannelValid(hwChannel) && (hwChannel <= EFI_ADC_ONCHIP_LAST));
38}

Referenced by boardGetAnalogInputDiagnostic().

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

◆ isAdcChannelValid()

bool isAdcChannelValid ( adc_channel_e  hwChannel)
inline

Definition at line 23 of file adc_inputs.h.

23 {
24 /* Compiler will optimize, keep following if as a reminder */
25 if (hwChannel >= EFI_ADC_TOTAL_CHANNELS) {
26 /* this should not happen!
27 * if we have enum out of range somewhere in settings
28 * that means something goes terribly wrong
29 * TODO: should we say something?
30 */
31 return false;
32 }
33 return ((hwChannel > EFI_ADC_NONE) && (hwChannel < EFI_ADC_TOTAL_CHANNELS));
34}

Referenced by adcPrintChannelReport(), addAdcChannelForTrigger(), addFastAdcChannel(), configTherm(), configureTempSensor(), deInitIfValid(), enableFastAdcChannel(), enableFastAdcChannel(), enableFastAdcChannel(), getAfr(), getInternalAdcValue(), getPinNameByAdcChannel(), hasAfrSensor(), initAuxSensors(), initFlexSensor(), initFluidPressure(), initFuelLevel(), initIfValid(), initLambda(), initMaf(), initMap(), initOldAnalogInputs(), initRangeSensors(), initTps(), initVbatt(), isAdcChannelOffChip(), isAdcChannelOnChip(), removeChannel(), slowAdcEnableDisableChannel(), GenericGearController::update(), and updateRawSensors().

Here is the caller graph for this function:

◆ onKnockSamplingComplete()

void onKnockSamplingComplete ( )

Definition at line 41 of file software_knock.cpp.

41 {
42 knockNeedsProcess = true;
43
44 // Notify the processing thread that it's time to process this sample
45 chSysLockFromISR();
46 knockSem.signalI();
47 chSysUnlockFromISR();
48}
chibios_rt::BinarySemaphore knockSem(true)
static volatile bool knockNeedsProcess

Referenced by knockCompletionCallback(), and knockCompletionCallback().

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

◆ printFullAdcReport()

void printFullAdcReport ( void  )

Definition at line 160 of file adc_inputs.cpp.

160 {
161#if EFI_USE_FAST_ADC
162 efiPrintf("fast %u samples", engine->outputChannels.fastAdcConversionCount);
163
164 for (int internalIndex = 0; internalIndex < fastAdc.size(); internalIndex++) {
165 adc_channel_e hwChannel = fastAdc.getAdcChannelByInternalIndex(internalIndex);
166
167 adcPrintChannelReport("F", internalIndex, hwChannel);
168 }
169#endif // EFI_USE_FAST_ADC
170
172}
adc_channel_e
void adcPrintChannelReport(const char *prefix, int internalIndex, adc_channel_e hwChannel)
void adcOnchipSlowShowReport()
int size() const
adc_channel_e getAdcChannelByInternalIndex(int index) const
TunerStudioOutputChannels outputChannels
Definition engine.h:109
static EngineAccessor engine
Definition engine.h:413

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 268 of file adc_inputs.cpp.

268 {
270 return;
272}
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 206 of file adc_inputs.cpp.

206 {
207 if (!isAdcChannelValid(hwChannel)) {
208 return;
209 }
210#if EFI_USE_FAST_ADC
211 if (adcHwChannelMode[hwChannel] == AdcChannelMode::Fast) {
212 /* TODO: */
213 //fastAdc.disableChannel(hwChannel);
214 }
215#endif
216
218}

Referenced by setAdcChannelOverrides().

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

◆ waitForSlowAdc()

void waitForSlowAdc ( uint32_t  lastAdcCounter = 1)

Definition at line 87 of file adc_onchip_slow.cpp.

87 {
88 // note that having ADC reading is one thing while having new sensor API is a totally different thing!
89 // todo: use sync.objects?
90 while (slowAdcConversionCount <= lastAdcCounter) {
91 chThdSleepMilliseconds(1);
92 }
93}
static uint32_t slowAdcConversionCount

Referenced by StepperMotorBase::setInitialPosition().

Here is the caller graph for this function:

Variable Documentation

◆ adc

beuint16_t adc

Definition at line 103 of file adc_inputs.h.

Referenced by getAdcInternalChannel(), and getHwChannelForAdcInput().

◆ channel

uint16_t channel

Definition at line 104 of file adc_inputs.h.

Referenced by addAdcChannelForTrigger(), boardGetAnalogInputDiagnostic(), CH_IRQ_HANDLER(), comp_lld_channel_enable(), configureRusefiLuaHooks(), configureTempSensor(), createRequest(), deInitIfValid(), disableTriggerStimulator(), DMAMUX_DisableChannel(), DMAMUX_DisablePeriodTrigger(), DMAMUX_EnableAlwaysOn(), DMAMUX_EnableChannel(), DMAMUX_EnablePeriodTrigger(), DMAMUX_SetSource(), EDMA_ClearChannelStatusFlags(), EDMA_CreateHandle(), EDMA_DisableChannelInterrupts(), EDMA_DisableChannelRequest(), EDMA_EnableAsyncRequest(), EDMA_EnableAutoStopRequest(), EDMA_EnableChannelInterrupts(), EDMA_EnableChannelRequest(), EDMA_GetChannelStatusFlags(), EDMA_GetRemainingMajorLoopCount(), EDMA_InstallTCD(), EDMA_ResetChannel(), EDMA_SetBandWidth(), EDMA_SetChannelLink(), EDMA_SetChannelPreemptionConfig(), EDMA_SetMinorOffsetConfig(), EDMA_SetModulo(), EDMA_SetTransferConfig(), EDMA_TriggerChannelStart(), efiExtiDisablePin(), efiExtiEnablePin(), emulatorApplyPinState(), enableFastAdcChannel(), enableFastAdcChannel(), Dac::GetLastVoltage(), getMcp3208adc(), getSentValue(), getSentValues(), getValue(), gpt_lld_polled_delay(), TriggerEmulatorHelper::handleEmulatorCallback(), initAuxSensors(), initFluidPressure(), initFuelLevel(), initIfValid(), initMaf(), initRangeSensors(), luaL_checkPwmIndex(), printAdcValue(), AdcSubscription::PrintInfo(), printSentInfo(), pwm_lld_disable_channel(), pwm_lld_disable_channel_notification(), pwm_lld_enable_channel(), pwm_lld_enable_channel_notification(), Ads1015::readChannel(), readGppwmChannel(), requestAdcValue(), requestAdcValueI(), sendToPot(), SENT_ISR_Handler(), SentDecoderThread(), setAnalogInputPin(), setDacVoltage(), setPotResistance(), setTriggerEmulatorRPM(), Dac::SetVoltage(), startKnockSampling(), startSimulatedTriggerSignal(), startTriggerEmulatorPins(), startTriggerInputPins(), stopTriggerEmulatorPins(), TunerstudioThread::ThreadTask(), updateRawSensors(), updateTriggerWaveformIfNeeded(), and validateCanChannelAndConvertFromHumanIntoZeroIndex().

◆ invalidAdcToken

constexpr AdcToken invalidAdcToken = (AdcToken)(-1)
staticconstexpr

Go to the source code of this file.