auto-sync

This commit is contained in:
rusEfi 2015-04-17 20:08:24 -04:00
parent 59e68964cd
commit 9b5a79680b
9 changed files with 30 additions and 30 deletions

View File

@ -34,7 +34,6 @@ extern schfunc_t globalTimerCallback;
* these fields are global in order to facilitate debugging
*/
static uint64_t nextEventTimeNt = 0;
static uint64_t hwAlarmTime = 0;
uint32_t beforeHwSetTimer;
uint32_t hwSetTimerTime;
@ -74,9 +73,12 @@ void Executor::scheduleByTime(scheduling_s *scheduling, efitimeus_t timeUs, schf
// this would guard the queue and disable interrupts
lockAnyContext();
}
queue.insertTask(scheduling, US2NT(timeUs), callback, param);
bool_t needToResetTimer = queue.insertTask(scheduling, US2NT(timeUs), callback, param);
if (!reentrantFlag) {
doExecute();
if (needToResetTimer) {
scheduleTimerCallback();
}
unlockAnyContext();
}
}
@ -89,6 +91,7 @@ void Executor::schedule(scheduling_s *scheduling, uint64_t nowUs, int delayUs, s
void Executor::onTimerCallback() {
lockAnyContext();
doExecute();
scheduleTimerCallback();
unlockAnyContext();
}
@ -122,19 +125,19 @@ void Executor::doExecute() {
firmwareError("Someone has stolen my lock");
return;
}
uint64_t nowNt = getTimeNowNt();
reentrantFlag = false;
}
void Executor::scheduleTimerCallback() {
/**
* 'executeAll' is potentially invoking heavy callbacks, let's grab fresh time value?
*/
/**
* Let's set up the timer for the next execution
* Let's grab fresh time value
*/
uint64_t nowNt = getTimeNowNt();
nextEventTimeNt = queue.getNextEventTime(nowNt);
efiAssertVoid(nextEventTimeNt > nowNt, "setTimer constraint");
if (nextEventTimeNt == EMPTY_QUEUE)
return; // no pending events in the queue
hwAlarmTime = NT2US(nextEventTimeNt - nowNt);
int32_t hwAlarmTime = NT2US((int32_t)nextEventTimeNt - (int32_t)nowNt);
beforeHwSetTimer = GET_TIMESTAMP();
setHardwareUsTimer(hwAlarmTime == 0 ? 1 : hwAlarmTime);
hwSetTimerTime = GET_TIMESTAMP() - beforeHwSetTimer;

View File

@ -21,6 +21,7 @@ private:
EventQueue queue;
bool reentrantFlag;
void doExecute();
void scheduleTimerCallback();
};
void initSignalExecutorImpl(void);

View File

@ -11,8 +11,10 @@
typedef void (*schfunc_t)(void *);
typedef struct scheduling_struct scheduling_s;
struct scheduling_struct {
class scheduling_s {
public:
scheduling_s();
#if EFI_SIGNAL_EXECUTOR_SLEEP
VirtualTimer timer;
#endif /* EFI_SIGNAL_EXECUTOR_SLEEP */
@ -22,6 +24,7 @@ struct scheduling_struct {
void *param;
scheduling_s *next;
const char *name;
// bool_t isScheduled;
};
void scheduleTask(const char *prefix, scheduling_s *scheduling, int delayUs, schfunc_t callback, void *param);

View File

@ -200,12 +200,14 @@ static void onTdcCallback(void) {
static void tdcMarkCallback(trigger_event_e ckpSignalType, uint32_t index0 DECLARE_ENGINE_PARAMETER_S) {
(void) ckpSignalType;
bool isTriggerSynchronizationPoint = index0 == 0;
if (isTriggerSynchronizationPoint) {
if (isTriggerSynchronizationPoint && engineConfiguration->isDigitalChartEnabled) {
int revIndex2 = engine->rpmCalculator.getRevolutionCounter() % 2;
int rpm = getRpm();
// todo: use event-based scheduling, not just time-based scheduling
scheduleByAngle(rpm, &tdcScheduler[revIndex2], tdcPosition(),
(schfunc_t) onTdcCallback, NULL, &engine->rpmCalculator);
if (isValidRpm(rpm)) {
scheduleByAngle(rpm, &tdcScheduler[revIndex2], tdcPosition(),
(schfunc_t) onTdcCallback, NULL, &engine->rpmCalculator);
}
}
}
#endif
@ -249,18 +251,9 @@ void initRpmCalculator(Engine *engine) {
* it takes the crankshaft to rotate to the specified angle.
*/
void scheduleByAngle(int rpm, scheduling_s *timer, angle_t angle, schfunc_t callback, void *param, RpmCalculator *calc) {
if (!isValidRpm(rpm)) {
/**
* this might happen in case of a single trigger event after a pause - this is normal, so no
* warning here
*/
return;
}
float delayUs = getOneDegreeTimeUs(rpm) * angle;
if (cisnan(delayUs)) {
firmwareError("NaN delay?");
return;
}
efiAssertVoid(isValidRpm(rpm), "RPM check expected");
float delayUs = calc->oneDegreeUs * angle;
efiAssertVoid(!cisnan(delayUs), "NaN delay?");
scheduleTask("by angle", timer, (int) delayUs, callback, param);
}
#endif

View File

@ -6,12 +6,12 @@ HW_LAYER_EGT_CPP = $(PROJECT_DIR)/hw_layer/can_hw.cpp \
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
HW_LAYER_EMS_CPP = $(HW_LAYER_EGT_CPP) \
$(PROJECT_DIR)/hw_layer/pin_repository.cpp \
$(PROJECT_DIR)/hw_layer/microsecond_timer.cpp \
$(PROJECT_DIR)/hw_layer/wave_analyzer_hw.cpp \
$(PROJECT_DIR)/hw_layer/hardware.cpp \
$(PROJECT_DIR)/hw_layer/neo6m.cpp \

View File

@ -1,5 +1,5 @@
/**
* @file microsecond_timer.c
* @file microsecond_timer.cpp
*
* Here we have a 1MHz timer dedicated to event scheduling. We are using one of the 32-bit timers here,
* so this timer can schedule events up to 4B/100M ~ 4000 seconds ~ 1 hour from current time.

View File

@ -42,7 +42,7 @@ struct_no_prefix engine_configuration_s
! please note that 1024 here is 4 * FUEL_RPM_COUNT * FUEL_LOAD_COUNT
custom fuel_table_t 1024 array, F32, @OFFSET@, [16x16],"ms", 1, 0, 0.0, 300.0, 2
custom ve_table_t 1024 array, F32, @OFFSET@, [16x16],"%", 1, 0, 0, 200.0, 2
custom ve_table_t 1024 array, F32, @OFFSET@, [16x16],"%", 1, 0, 0, 999.0, 2
custom afr_table_t 1024 array, F32, @OFFSET@, [16x16],"deg", 1, 0, 0, 25.0, 2
! please note that 1024 here is 4 * IGN_LOAD_COUNT * IGN_RPM_COUNT

View File

@ -290,5 +290,5 @@ int getRusEfiVersion(void) {
return 123; // this is here to make the compiler happy about the unused array
if (UNUSED_CCM_SIZE[0] * 0 != 0)
return 3211; // this is here to make the compiler happy about the unused array
return 20150416;
return 20150417;
}

View File

@ -504,7 +504,7 @@ page = 1
ignitionTable = array, F32, 11832, [16x16],"deg", 1, 0, -360, 360, 2
ignitionLoadBins = array, F32, 12856, [16], "Load", 1, 0.0, 0, 300.0, 2
ignitionRpmBins = array, F32, 12920, [16], "RPM", 1, 0.0, 0, 18000.0, 2
veTable = array, F32, 12984, [16x16],"%", 1, 0, 0, 200.0, 2
veTable = array, F32, 12984, [16x16],"%", 1, 0, 0, 999.0, 2
veLoadBins = array, F32, 14008, [16], "%", 1, 0.0, 0, 300.0, 2
veRpmBins = array, F32, 14072, [16], "RPM", 1, 0.0, 0, 18000.0, 2
afrTable = array, F32, 14136, [16x16],"deg", 1, 0, 0, 25.0, 2