auto-sync
This commit is contained in:
parent
e6fe729edb
commit
13c60095a8
|
@ -34,4 +34,6 @@ typedef float angle_t;
|
|||
*/
|
||||
typedef float percent_t;
|
||||
|
||||
typedef void (*Void)(void);
|
||||
|
||||
#endif /* CONTROLLERS_ALGO_RUSEFI_TYPES_H_ */
|
||||
|
|
|
@ -50,7 +50,7 @@ uint64_t getStartOfRevolutionIndex() {
|
|||
|
||||
void TriggerCentral::addEventListener(ShaftPositionListener listener, const char *name, Engine *engine) {
|
||||
print("registerCkpListener: %s\r\n", name);
|
||||
registerCallback(&triggerListeneres, (IntListener) listener, engine);
|
||||
triggerListeneres.registerCallback((IntListener) listener, engine);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -123,9 +123,9 @@ static void initWave(const char *name, int index) {
|
|||
|
||||
reader->name = name;
|
||||
|
||||
registerCallback(&hw->widthListeners, (IntListener) waAnaWidthCallback, (void*) reader);
|
||||
hw->widthListeners.registerCallback((IntListener) waAnaWidthCallback, (void*) reader);
|
||||
|
||||
registerCallback(&hw->periodListeners, (IntListener) waIcuPeriodCallback, (void*) reader);
|
||||
hw->periodListeners.registerCallback((IntListener) waIcuPeriodCallback, (void*) reader);
|
||||
|
||||
initWaveAnalyzerDriver(hw, brainPin);
|
||||
|
||||
|
|
|
@ -22,15 +22,17 @@ public:
|
|||
int errorsCount;
|
||||
int getAdcValueByIndex(int internalIndex);
|
||||
|
||||
adcsample_t samples[ADC_MAX_CHANNELS_COUNT * ADC_GRP1_BUF_DEPTH_SLOW];
|
||||
adcsample_t samples[ADC_MAX_CHANNELS_COUNT * MAX_ADC_GRP_BUF_DEPTH];
|
||||
|
||||
int getAdcValueByHwChannel(int hwChannel);
|
||||
|
||||
adc_state values;
|
||||
int channelCount;
|
||||
private:
|
||||
ADCConversionGroup* hwConfig;
|
||||
/**
|
||||
* Number of ADC channels in use
|
||||
*/
|
||||
int channelCount;
|
||||
|
||||
adc_channel_e hardwareIndexByIndernalAdcIndex[20];
|
||||
};
|
||||
|
|
|
@ -19,10 +19,6 @@
|
|||
#include "engine_math.h"
|
||||
#include "board_test.h"
|
||||
|
||||
#if EFI_SPEED_DENSITY
|
||||
#include "map_averaging.h"
|
||||
#endif /* EFI_SPEED_DENSITY */
|
||||
|
||||
AdcDevice::AdcDevice(ADCConversionGroup* hwConfig) {
|
||||
this->hwConfig = hwConfig;
|
||||
channelCount = 0;
|
||||
|
@ -34,8 +30,6 @@ AdcDevice::AdcDevice(ADCConversionGroup* hwConfig) {
|
|||
memset(internalAdcIndexByHardwareIndex, 0xFFFFFFFF, sizeof(internalAdcIndexByHardwareIndex));
|
||||
}
|
||||
|
||||
#define ADC_GRP1_BUF_DEPTH_FAST 1
|
||||
|
||||
#define ADC_NUMBER_CHANNELS_FAST 1
|
||||
|
||||
// todo: migrate from hardware timer to software ADC conversion triggering
|
||||
|
@ -65,15 +59,9 @@ static int adcCallbackCounter_slow = 0;
|
|||
|
||||
static int adcDebugReporting = FALSE;
|
||||
|
||||
static int fastAdcValue;
|
||||
extern engine_configuration_s *engineConfiguration;
|
||||
extern board_configuration_s *boardConfiguration;
|
||||
|
||||
/*
|
||||
* ADC samples buffer.
|
||||
*/
|
||||
static adcsample_t samples_fast[ADC_NUMBER_CHANNELS_FAST * ADC_GRP1_BUF_DEPTH_FAST];
|
||||
|
||||
static adcsample_t getAvgAdcValue(int index, adcsample_t *samples, int bufDepth, int numChannels) {
|
||||
adcsample_t result = 0;
|
||||
int i;
|
||||
|
@ -85,7 +73,6 @@ static adcsample_t getAvgAdcValue(int index, adcsample_t *samples, int bufDepth,
|
|||
}
|
||||
|
||||
static void adc_callback_slow(ADCDriver *adcp, adcsample_t *buffer, size_t n);
|
||||
static void adc_callback_fast(ADCDriver *adcp, adcsample_t *buffer, size_t n);
|
||||
|
||||
#define MY_SAMPLING_SLOW ADC_SAMPLE_480
|
||||
#define MY_SAMPLING_FAST ADC_SAMPLE_28
|
||||
|
@ -170,7 +157,7 @@ static void pwmpcb_slow(PWMDriver *pwmp) {
|
|||
;
|
||||
return;
|
||||
}
|
||||
adcStartConversionI(&ADC_SLOW_DEVICE, &adcgrpcfgSlow, slowAdc.samples, ADC_GRP1_BUF_DEPTH_SLOW);
|
||||
adcStartConversionI(&ADC_SLOW_DEVICE, &adcgrpcfgSlow, slowAdc.samples, ADC_BUF_DEPTH_SLOW);
|
||||
chSysUnlockFromIsr()
|
||||
;
|
||||
#endif
|
||||
|
@ -196,7 +183,7 @@ static void pwmpcb_fast(PWMDriver *pwmp) {
|
|||
;
|
||||
return;
|
||||
}
|
||||
adcStartConversionI(&ADC_FAST_DEVICE, &adcgrpcfg_fast, samples_fast, ADC_GRP1_BUF_DEPTH_FAST);
|
||||
adcStartConversionI(&ADC_FAST_DEVICE, &adcgrpcfg_fast, fastAdc.samples, ADC_BUF_DEPTH_FAST);
|
||||
chSysUnlockFromIsr()
|
||||
;
|
||||
fastAdc.conversionCount++;
|
||||
|
@ -204,14 +191,15 @@ static void pwmpcb_fast(PWMDriver *pwmp) {
|
|||
}
|
||||
|
||||
int getInternalAdcValue(adc_channel_e hwChannel) {
|
||||
if (boardConfiguration->adcHwChannelEnabled[hwChannel] == ADC_FAST)
|
||||
return fastAdcValue;
|
||||
if (boardConfiguration->adcHwChannelEnabled[hwChannel] == ADC_FAST) {
|
||||
int internalIndex = fastAdc.internalAdcIndexByHardwareIndex[hwChannel];
|
||||
return fastAdc.samples[internalIndex];
|
||||
}
|
||||
if (boardConfiguration->adcHwChannelEnabled[hwChannel] != ADC_SLOW) {
|
||||
warning(OBD_PCM_Processor_Fault, "ADC is off %d", hwChannel);
|
||||
}
|
||||
|
||||
int internalIndex = slowAdc.internalAdcIndexByHardwareIndex[hwChannel];
|
||||
return slowAdc.getAdcValueByIndex(internalIndex);
|
||||
return slowAdc.getAdcValueByHwChannel(hwChannel);
|
||||
}
|
||||
|
||||
static PWMConfig pwmcfg_slow = { PWM_FREQ_SLOW, PWM_PERIOD_SLOW, pwmpcb_slow, { {
|
||||
|
@ -373,6 +361,11 @@ int AdcDevice::size() {
|
|||
return channelCount;
|
||||
}
|
||||
|
||||
int AdcDevice::getAdcValueByHwChannel(int hwChannel) {
|
||||
int internalIndex = internalAdcIndexByHardwareIndex[hwChannel];
|
||||
return values.adc_data[internalIndex];
|
||||
}
|
||||
|
||||
int AdcDevice::getAdcValueByIndex(int internalIndex) {
|
||||
return values.adc_data[internalIndex];
|
||||
}
|
||||
|
@ -459,29 +452,15 @@ static void adc_callback_slow(ADCDriver *adcp, adcsample_t *buffer, size_t n) {
|
|||
|
||||
// newState.time = chimeNow();
|
||||
for (int i = 0; i < slowAdc.size(); i++) {
|
||||
int value = getAvgAdcValue(i, slowAdc.samples, ADC_GRP1_BUF_DEPTH_SLOW, slowAdc.size());
|
||||
/**
|
||||
* todo: No need to average since DEPTH is '1'
|
||||
*/
|
||||
int value = getAvgAdcValue(i, slowAdc.samples, ADC_BUF_DEPTH_SLOW, slowAdc.size());
|
||||
slowAdc.values.adc_data[i] = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void adc_callback_fast(ADCDriver *adcp, adcsample_t *buffer, size_t n) {
|
||||
(void) buffer;
|
||||
(void) n;
|
||||
// /* Note, only in the ADC_COMPLETE state because the ADC driver fires an
|
||||
// intermediate callback when the buffer is half full.*/
|
||||
efiAssertVoid(getRemainingStack(chThdSelf()) > 128, "lowstck#9b");
|
||||
if (adcp->state == ADC_COMPLETE) {
|
||||
fastAdcValue = getAvgAdcValue(0, samples_fast, ADC_GRP1_BUF_DEPTH_FAST, fastAdc.size());
|
||||
|
||||
fastAdc.values.adc_data[0] = fastAdcValue;
|
||||
|
||||
#if EFI_MAP_AVERAGING
|
||||
mapAveragingCallback(fastAdcValue);
|
||||
#endif /* EFI_MAP_AVERAGING */
|
||||
}
|
||||
}
|
||||
|
||||
void initAdcInputs(bool boardTestMode) {
|
||||
|
||||
initLoggingExt(&logger, "ADC", LOGGING_BUFFER, sizeof(LOGGING_BUFFER));
|
||||
|
|
|
@ -18,24 +18,22 @@
|
|||
const char * getAdcMode(adc_channel_e hwChannel);
|
||||
int getAdcChannelPin(adc_channel_e hwChannel);
|
||||
void initAdcInputs(bool boardTestMode);
|
||||
void adc_callback_fast(ADCDriver *adcp, adcsample_t *buffer, size_t n);
|
||||
GPIO_TypeDef* getAdcChannelPort(adc_channel_e hwChannel);
|
||||
adc_channel_e getAdcChannel(brain_pin_e pin);
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif /* __cplusplus */
|
||||
|
||||
int getAdcHardwareIndexByInternalIndex(int index);
|
||||
|
||||
void pokeAdcInputs(void);
|
||||
int getInternalAdcValue(adc_channel_e index);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
|
||||
/* Depth of the conversion buffer, channels are sampled X times each.*/
|
||||
#define ADC_GRP1_BUF_DEPTH_SLOW 1
|
||||
#define ADC_BUF_DEPTH_SLOW 1
|
||||
#define ADC_BUF_DEPTH_FAST 1
|
||||
|
||||
// max(ADC_BUF_DEPTH_SLOW, ADC_BUF_DEPTH_FAST)
|
||||
#define MAX_ADC_GRP_BUF_DEPTH 1
|
||||
|
||||
#define ADC_MAX_CHANNELS_COUNT 16
|
||||
|
||||
//typedef struct
|
||||
|
|
|
@ -24,6 +24,7 @@
|
|||
#include "can_hw.h"
|
||||
|
||||
#if EFI_PROD_CODE
|
||||
#include "AdcConfiguration.h"
|
||||
#include "board_test.h"
|
||||
#include "mcp3208.h"
|
||||
#include "HIP9011.h"
|
||||
|
@ -39,6 +40,10 @@
|
|||
#include "engine_configuration.h"
|
||||
#endif
|
||||
|
||||
#if EFI_SPEED_DENSITY
|
||||
#include "map_averaging.h"
|
||||
#endif /* EFI_SPEED_DENSITY */
|
||||
|
||||
#if EFI_INTERNAL_FLASH
|
||||
#include "flash_main.h"
|
||||
#endif /* EFI_INTERNAL_FLASH */
|
||||
|
@ -130,6 +135,30 @@ static Logging *sharedLogger;
|
|||
|
||||
#if EFI_PROD_CODE
|
||||
|
||||
extern AdcDevice fastAdc;
|
||||
|
||||
/**
|
||||
* This method is not in the adc* lower-level file because it is more business logic then hardware.
|
||||
*/
|
||||
void adc_callback_fast(ADCDriver *adcp, adcsample_t *buffer, size_t n) {
|
||||
(void) buffer;
|
||||
(void) n;
|
||||
/**
|
||||
* Note, only in the ADC_COMPLETE state because the ADC driver fires an
|
||||
* intermediate callback when the buffer is half full.
|
||||
* */
|
||||
if (adcp->state == ADC_COMPLETE) {
|
||||
/**
|
||||
* this callback is executed 10 000 times a second, it needs to be as fast as possible
|
||||
*/
|
||||
efiAssertVoid(getRemainingStack(chThdSelf()) > 128, "lowstck#9b");
|
||||
|
||||
#if EFI_MAP_AVERAGING
|
||||
mapAveragingCallback(fastAdc.samples[0]);
|
||||
#endif /* EFI_MAP_AVERAGING */
|
||||
}
|
||||
}
|
||||
|
||||
void initHardware(Logging *l, Engine *engine) {
|
||||
sharedLogger = l;
|
||||
engine_configuration_s *engineConfiguration = engine->engineConfiguration;
|
||||
|
|
|
@ -8,11 +8,11 @@ HW_LAYER_EMS = $(HW_LAYER_EGT) \
|
|||
$(PROJECT_DIR)/hw_layer/mcp3208.c \
|
||||
$(PROJECT_DIR)/hw_layer/microsecond_timer.c \
|
||||
$(PROJECT_DIR)/hw_layer/flash.c \
|
||||
$(PROJECT_DIR)/hw_layer/rtc_helper.c \
|
||||
$(PROJECT_DIR)/hw_layer/wave_analyzer_hw.c
|
||||
|
||||
$(PROJECT_DIR)/hw_layer/rtc_helper.c
|
||||
|
||||
HW_LAYER_EMS_CPP = $(HW_LAYER_EGT_CPP) \
|
||||
$(PROJECT_DIR)/hw_layer/pin_repository.cpp \
|
||||
$(PROJECT_DIR)/hw_layer/wave_analyzer_hw.cpp \
|
||||
$(PROJECT_DIR)/hw_layer/hardware.cpp \
|
||||
$(PROJECT_DIR)/hw_layer/neo6m.cpp \
|
||||
$(PROJECT_DIR)/hw_layer/mmc_card.cpp \
|
||||
|
|
|
@ -57,7 +57,7 @@ void initVehicleSpeed(Logging *l) {
|
|||
initWaveAnalyzerDriver(&vehicleSpeedInput, engineConfiguration->vehicleSpeedSensorInputPin);
|
||||
startInputDriver(&vehicleSpeedInput, true);
|
||||
|
||||
registerCallback(&vehicleSpeedInput.widthListeners, (IntListener) vsAnaWidthCallback, NULL);
|
||||
vehicleSpeedInput.widthListeners.registerCallback((IntListener) vsAnaWidthCallback, NULL);
|
||||
addConsoleAction("speedinfo", speedInfo);
|
||||
}
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* @file wave_analyzer_hw.c
|
||||
* @file wave_analyzer_hw.cpp
|
||||
* @brief Helper methods related to Input Capture Unit (ICU)
|
||||
*
|
||||
* @date Jun 23, 2013
|
||||
|
@ -44,7 +44,7 @@ static void icuWidthCallback(ICUDriver *driver) {
|
|||
int rowWidth = icuGetWidth(driver);
|
||||
*/
|
||||
WaveReaderHw * hw = findWaveReaderHw(driver);
|
||||
invokeJustArgCallbacks(&hw->widthListeners);
|
||||
hw->widthListeners.invokeJustArgCallbacks();
|
||||
}
|
||||
|
||||
static void icuPeriordCallBack(ICUDriver *driver) {
|
||||
|
@ -55,7 +55,7 @@ static void icuPeriordCallBack(ICUDriver *driver) {
|
|||
*/
|
||||
|
||||
WaveReaderHw * hw = findWaveReaderHw(driver);
|
||||
invokeJustArgCallbacks(&hw->periodListeners);
|
||||
hw->periodListeners.invokeJustArgCallbacks();
|
||||
}
|
||||
|
||||
static uint32_t getAlternateFunctions(ICUDriver *driver) {
|
|
@ -15,6 +15,7 @@ extern "C"
|
|||
#endif /* __cplusplus */
|
||||
|
||||
#include "efifeatures.h"
|
||||
#include "rusefi_types.h"
|
||||
|
||||
typedef enum {
|
||||
NO_PARAMETER,
|
||||
|
@ -46,7 +47,6 @@ int tokenLength(const char *msgp);
|
|||
|
||||
typedef void (*VoidPtr)(void*);
|
||||
|
||||
typedef void (*Void)(void);
|
||||
typedef void (*VoidInt)(int);
|
||||
typedef void (*VoidIntVoidPtr)(int, void*);
|
||||
typedef void (*VoidFloat)(float);
|
||||
|
|
|
@ -8,11 +8,15 @@
|
|||
#include "listener_array.h"
|
||||
#include "main.h"
|
||||
|
||||
void registerCallback(IntListenerArray *array, IntListener handler, void *arg) {
|
||||
efiAssertVoid(array->currentListenersCount < MAX_INT_LISTENER_COUNT, "Too many callbacks");
|
||||
int index = array->currentListenersCount++;
|
||||
array->callbacks[index] = handler;
|
||||
array->args[index] = arg;
|
||||
void IntListenerArray::registerCallback(IntListener handler, void *arg) {
|
||||
efiAssertVoid(currentListenersCount < MAX_INT_LISTENER_COUNT, "Too many callbacks");
|
||||
int index = currentListenersCount++;
|
||||
callbacks[index] = handler;
|
||||
args[index] = arg;
|
||||
}
|
||||
|
||||
void IntListenerArray::registerCallback(Void listener) {
|
||||
|
||||
}
|
||||
|
||||
void invokeCallbacks(IntListenerArray *array, int value) {
|
||||
|
@ -20,10 +24,10 @@ void invokeCallbacks(IntListenerArray *array, int value) {
|
|||
(array->callbacks[i])(value);
|
||||
}
|
||||
|
||||
void invokeJustArgCallbacks(IntListenerArray *array) {
|
||||
for (int i = 0; i < array->currentListenersCount; i++) {
|
||||
ArgListener listener = (ArgListener)array->callbacks[i];
|
||||
void *arg = array->args[i];
|
||||
void IntListenerArray::invokeJustArgCallbacks() {
|
||||
for (int i = 0; i < currentListenersCount; i++) {
|
||||
ArgListener listener = (ArgListener)callbacks[i];
|
||||
void *arg = args[i];
|
||||
(listener)(arg);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,10 +8,7 @@
|
|||
#ifndef LISTENER_ARRAY_H_
|
||||
#define LISTENER_ARRAY_H_
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif /* __cplusplus */
|
||||
#include "rusefi_types.h"
|
||||
|
||||
#define MAX_INT_LISTENER_COUNT 15
|
||||
|
||||
|
@ -24,13 +21,16 @@ typedef void (*IntIntVoidListener)(int value1, int value2, void *arg);
|
|||
typedef void (*ArgListener)(void *arg);
|
||||
typedef void (*ArgIntListener)(void *arg, int value);
|
||||
|
||||
typedef struct {
|
||||
class IntListenerArray {
|
||||
public:
|
||||
void registerCallback(IntListener handler, void *arg);
|
||||
void registerCallback(Void listener);
|
||||
void invokeJustArgCallbacks();
|
||||
int currentListenersCount;
|
||||
IntListener callbacks[MAX_INT_LISTENER_COUNT];
|
||||
void * args[MAX_INT_LISTENER_COUNT];
|
||||
} IntListenerArray;
|
||||
};
|
||||
|
||||
void registerCallback(IntListenerArray *array, IntListener handler, void *arg);
|
||||
void invokeCallbacks(IntListenerArray *array, int value);
|
||||
void invokeJustArgCallbacks(IntListenerArray *array);
|
||||
void invokeArgIntCallbacks(IntListenerArray *array, int value);
|
||||
|
@ -38,8 +38,4 @@ void invokeIntIntCallbacks(IntListenerArray *array, int value, int value2);
|
|||
void invokeIntIntVoidCallbacks(IntListenerArray *array, int value, int value2);
|
||||
void clearCallbacks(IntListenerArray *array);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#endif /* LISTENER_ARRAY_H_ */
|
||||
|
|
Loading…
Reference in New Issue