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)
 
bool isAdcChannelValid (adc_channel_e hwChannel)
 
bool isAdcChannelOnChip (adc_channel_e hwChannel)
 
bool isAdcChannelOffChip (adc_channel_e hwChannel)
 
int analogGetDiagnostic ()
 
void updateSlowAdc (efitick_t nowNt)
 
AdcChannelMode getAdcMode (adc_channel_e hwChannel)
 
void initAdcInputs ()
 
void waitForSlowAdc (uint32_t lastAdcCounter=1)
 
void printFullAdcReportIfNeeded (void)
 
int getInternalAdcValue (const char *msg, adc_channel_e index)
 
float getMCUInternalTemperature (void)
 
void addFastAdcChannel (const char *name, adc_channel_e hwChannel)
 
void removeChannel (const char *name, adc_channel_e hwChannel)
 
void onFastAdcComplete (adcsample_t *samples)
 
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 ()
 
void printFullAdcReport (void)
 

Variables

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

Typedef Documentation

◆ AdcTockenInternal

using AdcTockenInternal = union { AdcToken token

Definition at line 105 of file adc_inputs.h.

◆ AdcToken

using AdcToken = uint32_t

Definition at line 103 of file adc_inputs.h.

Enumeration Type Documentation

◆ AdcChannelMode

enum class AdcChannelMode : char
strong
Enumerator
Off 
Slow 
Fast 

Definition at line 75 of file adc_inputs.h.

75 : char {
76 Off,
77 Slow,
78 Fast
79};

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

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

◆ enableFastAdcChannel()

AdcToken enableFastAdcChannel ( const char msg,
adc_channel_e  channel 
)

Definition at line 274 of file mpu_util.cpp.

274 {
276 return invalidAdcToken;
277 }
278
279 // TODO: implement me!
280 return invalidAdcToken;
281}
static constexpr AdcToken invalidAdcToken
Definition adc_inputs.h:115
uint16_t channel
Definition adc_inputs.h:109

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 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 getAnalogInputDividerCoefficient ( adc_channel_e  hwChannel)

Definition at line 111 of file board_configuration.cpp.

111 {
112 switch (hwChannel) {
113 /* MAP, TPS, MAF (na), AC press (na) */
114 case EFI_ADC_0:
115 case EFI_ADC_1:
116 case EFI_ADC_11:
117 case EFI_ADC_6:
118 return (22.0 + 41.2) / 41.2;
119
120 /* IAT, CLT */
121 case EFI_ADC_3:
122 case EFI_ADC_14:
123 /* no divider, 1.5K pull-up to 3.3V, 22K pull-down */
124 /* TODO: handle both pull-up and pull-down */
125 return 1.0;
126
127 /* AFR 1, AFR 2 (na), knock (TBD) */
128 case EFI_ADC_7:
129 case EFI_ADC_5:
130 case EFI_ADC_2:
131 /* no divider */
132 return 1.0;
133
134 /* +12 sense, Ignition switch */
135 case EFI_ADC_9:
136 case EFI_ADC_8:
137 return (68.0 + 6.8) / 6.8;
138
139 /* 5V feedback */
140 case EFI_ADC_10:
141 return (10.0 + 10.0) / 10.0;
142
143 /* Ignition feedback */
144 case EFI_ADC_12:
145 case EFI_ADC_13:
146 /* TBD */
147 return 1.0;
148
149 default:
151 }
153}
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 283 of file mpu_util.cpp.

283 {
284 if (token == invalidAdcToken) {
285 return 0;
286 }
287
288 // TODO: implement me!
289 return 0;
290}

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

◆ getKnockConversionGroup()

const ADCConversionGroup * getKnockConversionGroup ( uint8_t  channelIdx)

Definition at line 369 of file stm32_adc_v2.cpp.

369 {
370#if KNOCK_HAS_CH2
371 if (channelIdx == 1) {
372 return &adcConvGroupCh2;
373 }
374#else
375 (void)channelIdx;
376#endif // KNOCK_HAS_CH2
377
378 return &adcConvGroupCh1;
379}
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 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:

◆ isAdcChannelOffChip()

bool isAdcChannelOffChip ( adc_channel_e  hwChannel)
inline

Definition at line 38 of file adc_inputs.h.

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

◆ isAdcChannelOnChip()

bool isAdcChannelOnChip ( adc_channel_e  hwChannel)
inline

Definition at line 34 of file adc_inputs.h.

34 {
35 return (isAdcChannelValid(hwChannel) && (hwChannel <= EFI_ADC_ONCHIP_LAST));
36}

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 21 of file adc_inputs.h.

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

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

Here is the caller graph for this function:

◆ onFastAdcComplete()

void onFastAdcComplete ( adcsample_t samples)

This method is not in the adc* lower-level file because it is more business logic then hardware.

this callback is executed 10 000 times a second, it needs to be as fast as possible

Definition at line 269 of file hardware.cpp.

269 {
271
272#if HAL_TRIGGER_USE_ADC
273 // we need to call this ASAP, because trigger processing is time-critical
275#endif /* HAL_TRIGGER_USE_ADC */
276
277 /**
278 * this callback is executed 10 000 times a second, it needs to be as fast as possible
279 */
280 efiAssertVoid(ObdCode::CUSTOM_STACK_ADC, hasLotsOfRemainingStack(), "lowstck#9b");
281
282#if EFI_MAP_AVERAGING && defined (MODULE_MAP_AVERAGING)
284#endif /* EFI_MAP_AVERAGING */
285}
adcsample_t getFastAdc(AdcToken token)
Definition mpu_util.cpp:283
static AdcToken triggerSampleIndex
Definition hardware.cpp:263
static AdcToken fastMapSampleIndex
Definition hardware.cpp:260
void mapAveragingAdcCallback(float instantVoltage)
@ CUSTOM_STACK_ADC
@ AdcCallbackFast
void triggerAdcCallback(triggerAdcSample_t value)

Referenced by adc_callback(), and fastAdcDoneCB().

Here is the call graph for this function:
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 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}
adc_channel_e
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:108
static EngineAccessor engine
Definition engine.h:410

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:

◆ 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 = 1)

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

beuint16_t adc

Definition at line 108 of file adc_inputs.h.

Referenced by getAdcInternalChannel().

◆ channel

uint16_t channel

Definition at line 109 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

Definition at line 115 of file adc_inputs.h.

Referenced by enableFastAdcChannel(), enableFastAdcChannel(), and getFastAdc().

Go to the source code of this file.