CJ125: prepare ADC (#542)

This commit is contained in:
andreika-git 2018-01-23 00:45:10 +02:00 committed by rusefi
parent a5f432f6df
commit bebdbcc21a
2 changed files with 14 additions and 3 deletions

View File

@ -550,14 +550,18 @@ static void setAdcDebugReporting(int value) {
scheduleMsg(&logger, "adcDebug=%d", adcDebugReporting);
}
void waitForSlowAdc() {
void waitForSlowAdc(int lastAdcCounter) {
// we use slowAdcCounter instead of slowAdc.conversionCount because we need ADC_COMPLETE state
// todo: use sync.objects?
while (slowAdcCounter < 1) {
while (slowAdcCounter <= lastAdcCounter) {
chThdSleepMilliseconds(1);
}
}
int getSlowAdcCounter() {
return slowAdcCounter;
}
static void adc_callback_slow(ADCDriver *adcp, adcsample_t *buffer, size_t n) {
(void) buffer;
(void) n;
@ -618,6 +622,11 @@ static void configureInputs(void) {
addChannel("OilP", engineConfiguration->oilPressure.hwChannel, ADC_SLOW);
addChannel("AC", engineConfiguration->acSwitchAdc, ADC_SLOW);
if (boardConfiguration->isCJ125Enabled) {
addChannel("cj125ur", engineConfiguration->cj125ur, ADC_SLOW);
addChannel("cj125ua", engineConfiguration->cj125ua, ADC_SLOW);
}
for (int i = 0; i < FSIO_ANALOG_INPUT_COUNT ; i++) {
addChannel("FSIOadc", engineConfiguration->fsioAdc[i], ADC_SLOW);
}

View File

@ -28,7 +28,9 @@ adc_channel_e getAdcChannel(brain_pin_e pin);
brain_pin_e getAdcChannelBrainPin(const char *msg, adc_channel_e hwChannel);
// wait until at least 1 slowADC sampling is complete
void waitForSlowAdc();
void waitForSlowAdc(int lastAdcCounter = 0);
// get a number of completed slowADC samples
int getSlowAdcCounter();
int getAdcHardwareIndexByInternalIndex(int index);