auto-sync

This commit is contained in:
rusEfi 2015-01-14 21:04:08 -06:00
parent 93d4e5c5c6
commit 95e172586f
14 changed files with 57 additions and 46 deletions

View File

@ -16,6 +16,7 @@
#include "event_registry.h"
#include "trigger_structure.h"
#include "table_helper.h"
#include "listener_array.h"
/**
* This class knows about when to inject fuel
@ -142,6 +143,9 @@ public:
void updateSlowSensors();
void watchdog();
IntListenerArray configurationListeners;
private:
/**
* By the way:

View File

@ -361,7 +361,7 @@ void setDefaultConfiguration(engine_configuration_s *engineConfiguration, board_
engineConfiguration->knockDetectionWindowStart = 35;
engineConfiguration->knockDetectionWindowEnd = 135;
engineConfiguration->hipOutputChannel = EFI_ADC_NONE;
/**
* this is RPM. 10000 rpm is only 166Hz, 800 rpm is 13Hz

View File

@ -536,7 +536,11 @@ typedef struct {
bool_t hasMafSensor : 1; // bit 12
bool_t hasTpsSensor : 1; // bit 13
int unused6284;
/**
* see also
* offset 6284
*/
adc_channel_e hipOutputChannel;
idle_mode_e idleMode;

View File

@ -393,7 +393,7 @@ void initEngineContoller(Logging *sharedLogger, Engine *engine) {
#if EFI_IDLE_CONTROL || defined(__DOXYGEN__)
if (engineConfiguration->isIdleThreadEnabled) {
startIdleThread(engine);
startIdleThread(sharedLogger, engine);
}
#endif

View File

@ -12,7 +12,7 @@
#include "engine_configuration.h"
#include "engine.h"
#define FLASH_DATA_VERSION 6130
#define FLASH_DATA_VERSION 6385
void readFromFlash(void);
void initFlash(Logging *sharedLogger, Engine *engine);

View File

@ -36,7 +36,7 @@
static THD_WORKING_AREA(ivThreadStack, UTILITY_THREAD_STACK_SIZE);
static LoggingWithStorage logger;
static Logging *logger;
EXTERN_ENGINE
;
@ -49,14 +49,13 @@ static SimplePwm idleValvePwm;
static IdleValveState idle;
void idleDebug(const char *msg, percent_t value) {
printMsg(&logger, "%s%f", msg, value);
scheduleLogging(&logger);
scheduleMsg(logger, "%s%f", msg, value);
}
static void showIdleInfo(void) {
scheduleMsg(&logger, "idleMode=%s duty=%f", getIdle_mode_e(engineConfiguration->idleMode),
scheduleMsg(logger, "idleMode=%s duty=%f", getIdle_mode_e(engineConfiguration->idleMode),
boardConfiguration->idleSolenoidPwm);
scheduleMsg(&logger, "idle valve freq=%d on %s", boardConfiguration->idleSolenoidFrequency,
scheduleMsg(logger, "idle valve freq=%d on %s", boardConfiguration->idleSolenoidFrequency,
hwPortname(boardConfiguration->idleValvePin));
}
@ -68,7 +67,7 @@ static void setIdleControlEnabled(int value) {
static void setIdleValvePwm(percent_t value) {
if (value < 0.01 || value > 99.9)
return;
scheduleMsg(&logger, "setting idle valve PWM %f", value);
scheduleMsg(logger, "setting idle valve PWM %f", value);
float f = 0.01 * value;
boardConfiguration->idleSolenoidPwm = f;
showIdleInfo();
@ -117,7 +116,7 @@ static msg_t ivThread(int param) {
static void setIdleRpmAction(int value) {
setIdleRpm(&idle, value);
scheduleMsg(&logger, "target idle RPM %d", value);
scheduleMsg(logger, "target idle RPM %d", value);
}
static void applyIdleSolenoidPinState(PwmConfig *state, int stateIndex) {
@ -129,8 +128,8 @@ static void applyIdleSolenoidPinState(PwmConfig *state, int stateIndex) {
output->setValue(value);
}
void startIdleThread(Engine *engine) {
initLogging(&logger, "Idle Valve Control");
void startIdleThread(Logging*sharedLogger, Engine *engine) {
logger = sharedLogger;
/**
* Start PWM for IDLE_VALVE logical / idleValvePin physical
@ -139,7 +138,7 @@ void startIdleThread(Engine *engine) {
boardConfiguration->idleSolenoidFrequency, boardConfiguration->idleSolenoidPwm, applyIdleSolenoidPinState);
idle.init();
scheduleMsg(&logger, "initial idle %d", idle.value);
scheduleMsg(logger, "initial idle %d", idle.value);
chThdCreateStatic(ivThreadStack, sizeof(ivThreadStack), NORMALPRIO, (tfunc_t) ivThread, NULL);

View File

@ -11,6 +11,6 @@
#include "engine.h"
void startIdleThread(Engine *engine);
void startIdleThread(Logging*sharedLogger, Engine *engine);
#endif /* IDLE_THREAD_H_ */

View File

@ -189,6 +189,10 @@ static void endOfSpiCommunication(SPIDriver *spip) {
isSendingSpiCommand = false;
}
void hipAdcCallback(adcsample_t value) {
}
void initHip9011(Logging *sharedLogger) {
if (!boardConfiguration->isHip9011Enabled)
return;

View File

@ -31,5 +31,6 @@
void initHip9011(Logging *sharedLogger);
void setHip9011FrankensoPinout(void);
void hipAdcCallback(adcsample_t value);
#endif /* HIP9011_H_ */

View File

@ -137,6 +137,9 @@ static Logging *sharedLogger;
extern AdcDevice fastAdc;
static int fastMapSampleIndex;
static int hipSampleIndex;
/**
* This method is not in the adc* lower-level file because it is more business logic then hardware.
*/
@ -154,11 +157,25 @@ void adc_callback_fast(ADCDriver *adcp, adcsample_t *buffer, size_t n) {
efiAssertVoid(getRemainingStack(chThdSelf()) > 128, "lowstck#9b");
#if EFI_MAP_AVERAGING
mapAveragingCallback(fastAdc.samples[0]);
mapAveragingCallback(fastAdc.samples[fastMapSampleIndex]);
#endif /* EFI_MAP_AVERAGING */
if (boardConfiguration->isHip9011Enabled) {
hipAdcCallback(fastAdc.samples[hipSampleIndex]);
}
}
}
static void calcFastAdcIndexes(void) {
fastMapSampleIndex = fastAdc.internalAdcIndexByHardwareIndex[engineConfiguration->map.sensor.hwChannel];
hipSampleIndex =
engineConfiguration->hipOutputChannel == EFI_ADC_NONE ?
-1 : fastAdc.internalAdcIndexByHardwareIndex[engineConfiguration->hipOutputChannel];
}
static void adcConfigListener(void) {
calcFastAdcIndexes();
}
void initHardware(Logging *l, Engine *engine) {
sharedLogger = l;
engine_configuration_s *engineConfiguration = engine->engineConfiguration;
@ -199,8 +216,7 @@ void initHardware(Logging *l, Engine *engine) {
#if EFI_INTERNAL_FLASH
palSetPadMode(CONFIG_RESET_SWITCH_PORT, CONFIG_RESET_SWITCH_PIN,
PAL_MODE_INPUT_PULLUP);
palSetPadMode(CONFIG_RESET_SWITCH_PORT, CONFIG_RESET_SWITCH_PIN, PAL_MODE_INPUT_PULLUP);
initFlash(sharedLogger, engine);
/**
@ -209,8 +225,7 @@ void initHardware(Logging *l, Engine *engine) {
*/
if (SHOULD_INGORE_FLASH()) {
engineConfiguration->engineType = DEFAULT_ENGINE_TYPE;
resetConfigurationExt(sharedLogger, engineConfiguration->engineType,
engine);
resetConfigurationExt(sharedLogger, engineConfiguration->engineType, engine);
writeToFlash();
} else {
readFromFlash();
@ -244,8 +259,7 @@ void initHardware(Logging *l, Engine *engine) {
initOutputPins();
#if EFI_MAX_31855
initMax31855(sharedLogger, getSpiDevice(boardConfiguration->max31855spiDevice),
boardConfiguration->max31855_cs);
initMax31855(sharedLogger, getSpiDevice(boardConfiguration->max31855spiDevice), boardConfiguration->max31855_cs);
#endif /* EFI_MAX_31855 */
// iacMotor.initialize(GPIOD_11, GPIOD_10);
@ -317,6 +331,9 @@ void initHardware(Logging *l, Engine *engine) {
initJoystick(sharedLogger);
calcFastAdcIndexes();
engine->configurationListeners.registerCallback(adcConfigListener);
printMsg(sharedLogger, "initHardware() OK!");
}

View File

@ -253,7 +253,7 @@ void firmwareError(const char *fmt, ...) {
}
}
static char UNUSED_RAM_SIZE[6000];
static char UNUSED_RAM_SIZE[6500];
static char UNUSED_CCM_SIZE[8000] CCM_OPTIONAL;

View File

@ -14,27 +14,6 @@
#define DELIMETER ","
typedef enum {
LP_RPM = 0,
LP_ECT = 1,
LP_IAT = 2,
LP_THROTTLE = 3,
LP_THROTTLE_ADC = 4,
LP_MAP = 5,
LP_MAP_RAW = 6,
LP_MAF = 7,
LP_TRG_CH0_DUTY = 8,
LP_TRG_CH1_DUTY = 9,
// LP_SECONDS,
LP_COUNT = 9
} LoggingPoints;
// todo: migrate to external buffer so that different instances have different
// size of buffers?
class Logging {
@ -81,10 +60,8 @@ void initLogging(LoggingWithStorage *logging, const char *name);
void initLoggingExt(Logging *logging, const char *name, char *buffer, int bufferSize);
void debugInt(Logging *logging, const char *caption, int value);
void logInt(Logging *logging, LoggingPoints loggingPoint, int value);
void debugFloat(Logging *logging, const char *text, float value, int precision);
void logFloat(Logging *logging, LoggingPoints loggingPoint, float value);
void appendFloat(Logging *logging, float value, int precision);
void resetLogging(Logging *logging);

View File

@ -8,6 +8,10 @@
#include "listener_array.h"
#include "main.h"
IntListenerArray::IntListenerArray() {
currentListenersCount = 0;
}
void IntListenerArray::registerCallback(IntListener handler, void *arg) {
efiAssertVoid(currentListenersCount < MAX_INT_LISTENER_COUNT, "Too many callbacks");
int index = currentListenersCount++;

View File

@ -23,6 +23,7 @@ typedef void (*ArgIntListener)(void *arg, int value);
class IntListenerArray {
public:
IntListenerArray();
void registerCallback(IntListener handler, void *arg);
void registerCallback(Void listener);
void invokeJustArgCallbacks();