rusEFI
The most advanced open source ECU
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 BOARD_WEAK getAnalogInputDividerCoefficient (adc_channel_e)
 
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 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 uint32_t slowAdcErrorsCount = 0
 
static float mcuTemperature
 
static AdcChannelMode adcHwChannelMode [EFI_ADC_TOTAL_CHANNELS]
 
static int adcDebugReporting = false
 
static SlowAdcController slowAdcController
 
 adc_channel_e
 

Function Documentation

◆ __attribute__()

__attribute__ ( (weak)  )

Definition at line 173 of file adc_inputs.cpp.

173 { }

◆ addFastAdcChannel()

void addFastAdcChannel ( const char *  name,
adc_channel_e  hwChannel 
)

Definition at line 145 of file adc_inputs.cpp.

145  {
146  if (!isAdcChannelValid(hwChannel)) {
147  return;
148  }
149 
150 #if EFI_USE_FAST_ADC
151  fastAdc.enableChannel(hwChannel);
152 #endif
153 
155  // Nothing to do for slow channels, input is mapped to analog in init_sensors.cpp
156 }
static AdcChannelMode adcHwChannelMode[EFI_ADC_TOTAL_CHANNELS]
Definition: adc_inputs.cpp:32
AdcDevice fastAdc
bool isAdcChannelValid(adc_channel_e hwChannel)
Definition: adc_inputs.h:20
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:

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

175  {
177 
178  /**
179  * order of analog channels here is totally random and has no meaning
180  * we also have some weird implementation with internal indices - that all has no meaning, it's just a random implementation
181  * which does not mean anything.
182  */
183 
185 
187 
188  // not currently used addFastAdcChannel("Vref", engineConfiguration->vRefAdcChannel, ADC_SLOW);
189 
191 
193 }
void addFastAdcChannel(const char *, adc_channel_e hwChannel)
Definition: adc_inputs.cpp:145
void setAdcChannelOverrides()
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 37 of file adc_inputs.cpp.

37  {
38  return adcHwChannelMode[hwChannel];
39 }

Referenced by AdcSubscription::PrintInfo().

Here is the caller graph for this function:

◆ getAnalogInputDividerCoefficient()

float BOARD_WEAK getAnalogInputDividerCoefficient ( adc_channel_e  hwChannel)

◆ getInternalAdcValue()

int getInternalAdcValue ( const char *  msg,
adc_channel_e  hwChannel 
)

Definition at line 45 of file adc_inputs.cpp.

45  {
46  if (!isAdcChannelValid(hwChannel)) {
47  warning(ObdCode::CUSTOM_OBD_ANALOG_INPUT_NOT_CONFIGURED, "ADC: %s input is not configured", msg);
48  return -1;
49  }
50 
51 #if EFI_USE_FAST_ADC
52  if (adcHwChannelMode[hwChannel] == AdcChannelMode::Fast) {
53  return fastAdc.getAvgAdcValue(hwChannel);
54  }
55 #endif // EFI_USE_FAST_ADC
56 
57  return slowAdcSamples[hwChannel - EFI_ADC_0];
58 }
static volatile NO_CACHE adcsample_t slowAdcSamples[SLOW_ADC_CHANNEL_COUNT]
Definition: adc_inputs.cpp:25
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 41 of file adc_inputs.cpp.

41  {
42  return mcuTemperature;
43 }
static float mcuTemperature
Definition: adc_inputs.cpp:30

Referenced by populateFrame(), and updateMiscSensors().

Here is the caller graph for this function:

◆ initAdcInputs()

void initAdcInputs ( )

Definition at line 205 of file adc_inputs.cpp.

205  {
206  efiPrintf("initAdcInputs()");
207 
208  configureInputs();
209 
210  // migrate to 'enable adcdebug'
212 
213 #if EFI_INTERNAL_ADC
214  portInitAdc();
215 
216  // Start the slow ADC thread
217  slowAdcController.start();
218 
219 #if EFI_USE_FAST_ADC
220  // After this point fastAdc is not allowed to add channels
221  fastAdc.init();
222 #endif // EFI_USE_FAST_ADC
223 
225 #else // ! EFI_INTERNAL_ADC
226  efiPrintf("ADC disabled");
227 #endif // EFI_INTERNAL_ADC
228 }
static void setAdcDebugReporting(int value)
Definition: adc_inputs.cpp:107
static void printAdcValue(int channel)
Definition: adc_inputs.cpp:60
static void configureInputs()
Definition: adc_inputs.cpp:175
static SlowAdcController slowAdcController
Definition: adc_inputs.cpp:203
void init(void)
void addConsoleActionI(const char *token, VoidInt callback)
Register a console command with one Integer parameter.
void(* VoidInt)(int)
Definition: cli_registry.h:54
void portInitAdc()
Definition: mpu_util.cpp:244

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

72 {
73  if (isAdcChannelValid(hwChannel)) {
74  ioportid_t port = getAdcChannelPort("print", hwChannel);
75  int pin = getAdcChannelPin(hwChannel);
76  int adcValue = getAdcValue("print", hwChannel);
77  float volts = getVoltage("print", hwChannel);
78  float voltsDivided = getVoltageDivided("print", hwChannel);
79  /* Human index starts from 1 */
80  efiPrintf(" %s ch[%2d] @ %s%d ADC%d 12bit=%4d %.3fV (input %.3fV)",
81  prefix, internalIndex, portname(port), pin,
82  /* TODO: */ hwChannel - EFI_ADC_0 + 1,
83  adcValue, volts, voltsDivided);
84  }
85 }
float getVoltageDivided(const char *msg, adc_channel_e hwChannel)
float getVoltage(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.
Definition: hal_pal_lld.h:102
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 60 of file adc_inputs.cpp.

60  {
61  /* Do this check before conversion to adc_channel_e that is uint8_t based */
62  if ((channel < EFI_ADC_NONE) || (channel >= EFI_ADC_TOTAL_CHANNELS)) {
63  efiPrintf("Invalid ADC channel %d", channel);
64  return;
65  }
66  int value = getAdcValue("print", (adc_channel_e)channel);
67  float volts = adcToVoltsDivided(value, (adc_channel_e)channel);
68  efiPrintf("adc %d voltage : %.3f", channel, volts);
69 }
adc_channel_e
Definition: adc_inputs.cpp:238
uint16_t channel
Definition: adc_inputs.h:105

Referenced by initAdcInputs().

Here is the caller graph for this function:

◆ printFullAdcReport()

void printFullAdcReport ( void  )

Definition at line 87 of file adc_inputs.cpp.

87  {
88 #if EFI_USE_FAST_ADC
89  efiPrintf("fast %lu samples", fastAdc.conversionCount);
90 
91  for (int internalIndex = 0; internalIndex < fastAdc.size(); internalIndex++) {
92  adc_channel_e hwChannel = fastAdc.getAdcChannelByInternalIndex(internalIndex);
93 
94  printAdcChannedReport("F", internalIndex, hwChannel);
95  }
96 #endif // EFI_USE_FAST_ADC
97  efiPrintf("slow %lu samples", slowAdcConversionCount);
98 
99  /* we assume that all slow ADC channels are enabled */
100  for (int internalIndex = 0; internalIndex < ADC_MAX_CHANNELS_COUNT; internalIndex++) {
101  adc_channel_e hwChannel = static_cast<adc_channel_e>(internalIndex + EFI_ADC_0);
102 
103  printAdcChannedReport("S", internalIndex, hwChannel);
104  }
105 }
static uint32_t slowAdcConversionCount
Definition: adc_inputs.cpp:27
static void printAdcChannedReport(const char *prefix, int internalIndex, adc_channel_e hwChannel)
Definition: adc_inputs.cpp:71
int size() const
adc_channel_e getAdcChannelByInternalIndex(int index) const
uint32_t conversionCount
Definition: AdcDevice.h:42

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

230  {
231  if (!adcDebugReporting)
232  return;
234 }
static int adcDebugReporting
Definition: adc_inputs.cpp:35
void printFullAdcReport(void)
Definition: adc_inputs.cpp:87

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

158  {
159  if (!isAdcChannelValid(hwChannel)) {
160  return;
161  }
162 #if EFI_USE_FAST_ADC
163  if (adcHwChannelMode[hwChannel] == AdcChannelMode::Fast) {
164  /* TODO: */
165  //fastAdc.disableChannel(hwChannel);
166  }
167 #endif
168 
170 }

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

107  {
108  adcDebugReporting = value;
109  efiPrintf("adcDebug=%d", adcDebugReporting);
110 }

Referenced by initAdcInputs().

Here is the caller graph for this function:

◆ waitForSlowAdc()

void waitForSlowAdc ( uint32_t  lastAdcCounter)

Definition at line 195 of file adc_inputs.cpp.

195  {
196  // note that having ADC reading is one thing while having new sensor API is a totally different thing!
197  // todo: use sync.objects?
198  while (slowAdcConversionCount <= lastAdcCounter) {
199  chThdSleepMilliseconds(1);
200  }
201 }

Referenced by initHardware(), and 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 238 of file adc_inputs.cpp.

Referenced by printAdcValue(), and printFullAdcReport().

◆ adcDebugReporting

int adcDebugReporting = false
static

Definition at line 35 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 30 of file adc_inputs.cpp.

Referenced by getMCUInternalTemperature().

◆ slowAdcController

SlowAdcController slowAdcController
static

Definition at line 203 of file adc_inputs.cpp.

Referenced by initAdcInputs().

◆ slowAdcConversionCount

uint32_t slowAdcConversionCount = 0
static

Definition at line 27 of file adc_inputs.cpp.

Referenced by printFullAdcReport(), and waitForSlowAdc().

◆ slowAdcErrorsCount

uint32_t slowAdcErrorsCount = 0
static

Definition at line 28 of file adc_inputs.cpp.

◆ slowAdcSamples

volatile NO_CACHE adcsample_t slowAdcSamples[SLOW_ADC_CHANNEL_COUNT]
static

Definition at line 25 of file adc_inputs.cpp.

Referenced by getInternalAdcValue().

Go to the source code of this file.