auto-sync

This commit is contained in:
rusEfi 2015-04-28 21:11:49 -04:00
parent e82e4d10d4
commit 9176d0be3e
4 changed files with 35 additions and 14 deletions

View File

@ -83,6 +83,9 @@ public:
*/ */
float iat; float iat;
float clt; float clt;
angle_t mapAveragingStart;
angle_t mapAveragingDuration;
}; };
class RpmCalculator; class RpmCalculator;

View File

@ -81,7 +81,8 @@ board_configuration_s *boardConfiguration = &persistentState.persistentConfigura
* CH_FREQUENCY is the number of system ticks in a second * CH_FREQUENCY is the number of system ticks in a second
*/ */
static VirtualTimer periodicTimer; static VirtualTimer periodicSlowTimer;
static VirtualTimer periodicFastTimer;
static LoggingWithStorage logger("Engine Controller"); static LoggingWithStorage logger("Engine Controller");
@ -203,18 +204,34 @@ static void cylinderCleanupControl(Engine *engine) {
static LocalVersionHolder versionForConfigurationListeners; static LocalVersionHolder versionForConfigurationListeners;
static void periodicCallback(Engine *engine); static void periodicSlowCallback(Engine *engine);
static void scheduleNextInvocation(void) { static void scheduleNextSlowInvocation(void) {
// schedule next invocation // schedule next invocation
int period = boardConfiguration->generalPeriodicThreadPeriod; int period = boardConfiguration->generalPeriodicThreadPeriod;
if (period == 0) if (period == 0)
period = 50; // this might happen while resetting config period = 50; // this might happen while resetting config
chVTSetAny(&periodicTimer, period * TICKS_IN_MS, (vtfunc_t) &periodicCallback, engine); chVTSetAny(&periodicSlowTimer, period * TICKS_IN_MS, (vtfunc_t) &periodicSlowCallback, engine);
} }
static void periodicCallback(Engine *engine) { static void periodicFastCallback(DECLARE_ENGINE_PARAMETER_F) {
int rpm = engine->rpmCalculator.rpmValue;
if (isValidRpm(rpm)) {
MAP_sensor_config_s * c = &engineConfiguration->map;
engine->engineState.mapAveragingStart = interpolate2d(rpm, c->samplingAngleBins, c->samplingAngle, MAP_ANGLE_SIZE);
engine->engineState.mapAveragingDuration = interpolate2d(rpm, c->samplingWindowBins, c->samplingWindow, MAP_WINDOW_SIZE);
} else {
engine->engineState.mapAveragingStart = NAN;
engine->engineState.mapAveragingDuration = NAN;
}
chVTSetAny(&periodicFastTimer, 20 * TICKS_IN_MS, (vtfunc_t) &periodicFastCallback, engine);
}
static void periodicSlowCallback(Engine *engine) {
efiAssertVoid(getRemainingStack(chThdSelf()) > 64, "lowStckOnEv"); efiAssertVoid(getRemainingStack(chThdSelf()) > 64, "lowStckOnEv");
#if EFI_PROD_CODE #if EFI_PROD_CODE
/** /**
@ -253,11 +270,12 @@ static void periodicCallback(Engine *engine) {
cylinderCleanupControl(engine); cylinderCleanupControl(engine);
scheduleNextInvocation(); scheduleNextSlowInvocation();
} }
void initPeriodicEvents(Engine *engine) { void initPeriodicEvents(DECLARE_ENGINE_PARAMETER_F) {
scheduleNextInvocation(); scheduleNextSlowInvocation();
periodicFastCallback(PASS_ENGINE_PARAMETER_F);
} }
char * getPinNameByAdcChannel(adc_channel_e hwChannel, char *buffer) { char * getPinNameByAdcChannel(adc_channel_e hwChannel, char *buffer) {
@ -457,7 +475,7 @@ static void getKnockInfo(void) {
scheduleMsg(&logger, "knock now=%s/ever=%s", boolToString(engine->knockNow), boolToString(engine->knockEver)); scheduleMsg(&logger, "knock now=%s/ever=%s", boolToString(engine->knockNow), boolToString(engine->knockEver));
} }
void initEngineContoller(Logging *sharedLogger, Engine *engine) { void initEngineContoller(Logging *sharedLogger DECLARE_ENGINE_PARAMETER_S) {
if (hasFirmwareError()) { if (hasFirmwareError()) {
return; return;
} }
@ -496,7 +514,7 @@ void initEngineContoller(Logging *sharedLogger, Engine *engine) {
#endif #endif
// multiple issues with this initMapAdjusterThread(); // multiple issues with this initMapAdjusterThread();
initPeriodicEvents(engine); initPeriodicEvents(PASS_ENGINE_PARAMETER_F);
chThdCreateStatic(csThreadStack, sizeof(csThreadStack), LOWPRIO, (tfunc_t) csThread, NULL); chThdCreateStatic(csThreadStack, sizeof(csThreadStack), LOWPRIO, (tfunc_t) csThread, NULL);

View File

@ -16,7 +16,7 @@
char * getPinNameByAdcChannel(adc_channel_e hwChannel, char *buffer); char * getPinNameByAdcChannel(adc_channel_e hwChannel, char *buffer);
void initConfigActions(void); void initConfigActions(void);
void initPeriodicEvents(Engine *engine); void initPeriodicEvents(DECLARE_ENGINE_PARAMETER_F);
void initEngineContoller(Logging *sharedLogger, Engine *engine); void initEngineContoller(Logging *sharedLogger DECLARE_ENGINE_PARAMETER_S);
#endif /* ENGINE_STATUS_H_ */ #endif /* ENGINE_STATUS_H_ */

View File

@ -215,7 +215,7 @@ void runRusEfi(void) {
* Now let's initialize actual engine control logic * Now let's initialize actual engine control logic
* todo: should we initialize some? most? controllers before hardware? * todo: should we initialize some? most? controllers before hardware?
*/ */
initEngineContoller(&sharedLogger, engine); initEngineContoller(&sharedLogger PASS_ENGINE_PARAMETER_F);
#if EFI_PERF_METRICS || defined(__DOXYGEN__) #if EFI_PERF_METRICS || defined(__DOXYGEN__)
initTimePerfActions(&sharedLogger); initTimePerfActions(&sharedLogger);