auto-sync
This commit is contained in:
parent
59e68964cd
commit
9b5a79680b
|
@ -34,7 +34,6 @@ extern schfunc_t globalTimerCallback;
|
||||||
* these fields are global in order to facilitate debugging
|
* these fields are global in order to facilitate debugging
|
||||||
*/
|
*/
|
||||||
static uint64_t nextEventTimeNt = 0;
|
static uint64_t nextEventTimeNt = 0;
|
||||||
static uint64_t hwAlarmTime = 0;
|
|
||||||
|
|
||||||
uint32_t beforeHwSetTimer;
|
uint32_t beforeHwSetTimer;
|
||||||
uint32_t hwSetTimerTime;
|
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
|
// this would guard the queue and disable interrupts
|
||||||
lockAnyContext();
|
lockAnyContext();
|
||||||
}
|
}
|
||||||
queue.insertTask(scheduling, US2NT(timeUs), callback, param);
|
bool_t needToResetTimer = queue.insertTask(scheduling, US2NT(timeUs), callback, param);
|
||||||
if (!reentrantFlag) {
|
if (!reentrantFlag) {
|
||||||
doExecute();
|
doExecute();
|
||||||
|
if (needToResetTimer) {
|
||||||
|
scheduleTimerCallback();
|
||||||
|
}
|
||||||
unlockAnyContext();
|
unlockAnyContext();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -89,6 +91,7 @@ void Executor::schedule(scheduling_s *scheduling, uint64_t nowUs, int delayUs, s
|
||||||
void Executor::onTimerCallback() {
|
void Executor::onTimerCallback() {
|
||||||
lockAnyContext();
|
lockAnyContext();
|
||||||
doExecute();
|
doExecute();
|
||||||
|
scheduleTimerCallback();
|
||||||
unlockAnyContext();
|
unlockAnyContext();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -122,19 +125,19 @@ void Executor::doExecute() {
|
||||||
firmwareError("Someone has stolen my lock");
|
firmwareError("Someone has stolen my lock");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
uint64_t nowNt = getTimeNowNt();
|
|
||||||
reentrantFlag = false;
|
reentrantFlag = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Executor::scheduleTimerCallback() {
|
||||||
/**
|
/**
|
||||||
* 'executeAll' is potentially invoking heavy callbacks, let's grab fresh time value?
|
* Let's grab fresh time value
|
||||||
*/
|
|
||||||
/**
|
|
||||||
* Let's set up the timer for the next execution
|
|
||||||
*/
|
*/
|
||||||
|
uint64_t nowNt = getTimeNowNt();
|
||||||
nextEventTimeNt = queue.getNextEventTime(nowNt);
|
nextEventTimeNt = queue.getNextEventTime(nowNt);
|
||||||
efiAssertVoid(nextEventTimeNt > nowNt, "setTimer constraint");
|
efiAssertVoid(nextEventTimeNt > nowNt, "setTimer constraint");
|
||||||
if (nextEventTimeNt == EMPTY_QUEUE)
|
if (nextEventTimeNt == EMPTY_QUEUE)
|
||||||
return; // no pending events in the 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();
|
beforeHwSetTimer = GET_TIMESTAMP();
|
||||||
setHardwareUsTimer(hwAlarmTime == 0 ? 1 : hwAlarmTime);
|
setHardwareUsTimer(hwAlarmTime == 0 ? 1 : hwAlarmTime);
|
||||||
hwSetTimerTime = GET_TIMESTAMP() - beforeHwSetTimer;
|
hwSetTimerTime = GET_TIMESTAMP() - beforeHwSetTimer;
|
||||||
|
|
|
@ -21,6 +21,7 @@ private:
|
||||||
EventQueue queue;
|
EventQueue queue;
|
||||||
bool reentrantFlag;
|
bool reentrantFlag;
|
||||||
void doExecute();
|
void doExecute();
|
||||||
|
void scheduleTimerCallback();
|
||||||
};
|
};
|
||||||
|
|
||||||
void initSignalExecutorImpl(void);
|
void initSignalExecutorImpl(void);
|
||||||
|
|
|
@ -11,8 +11,10 @@
|
||||||
|
|
||||||
typedef void (*schfunc_t)(void *);
|
typedef void (*schfunc_t)(void *);
|
||||||
|
|
||||||
typedef struct scheduling_struct scheduling_s;
|
class scheduling_s {
|
||||||
struct scheduling_struct {
|
public:
|
||||||
|
scheduling_s();
|
||||||
|
|
||||||
#if EFI_SIGNAL_EXECUTOR_SLEEP
|
#if EFI_SIGNAL_EXECUTOR_SLEEP
|
||||||
VirtualTimer timer;
|
VirtualTimer timer;
|
||||||
#endif /* EFI_SIGNAL_EXECUTOR_SLEEP */
|
#endif /* EFI_SIGNAL_EXECUTOR_SLEEP */
|
||||||
|
@ -22,6 +24,7 @@ struct scheduling_struct {
|
||||||
void *param;
|
void *param;
|
||||||
scheduling_s *next;
|
scheduling_s *next;
|
||||||
const char *name;
|
const char *name;
|
||||||
|
// bool_t isScheduled;
|
||||||
};
|
};
|
||||||
|
|
||||||
void scheduleTask(const char *prefix, scheduling_s *scheduling, int delayUs, schfunc_t callback, void *param);
|
void scheduleTask(const char *prefix, scheduling_s *scheduling, int delayUs, schfunc_t callback, void *param);
|
||||||
|
|
|
@ -200,14 +200,16 @@ static void onTdcCallback(void) {
|
||||||
static void tdcMarkCallback(trigger_event_e ckpSignalType, uint32_t index0 DECLARE_ENGINE_PARAMETER_S) {
|
static void tdcMarkCallback(trigger_event_e ckpSignalType, uint32_t index0 DECLARE_ENGINE_PARAMETER_S) {
|
||||||
(void) ckpSignalType;
|
(void) ckpSignalType;
|
||||||
bool isTriggerSynchronizationPoint = index0 == 0;
|
bool isTriggerSynchronizationPoint = index0 == 0;
|
||||||
if (isTriggerSynchronizationPoint) {
|
if (isTriggerSynchronizationPoint && engineConfiguration->isDigitalChartEnabled) {
|
||||||
int revIndex2 = engine->rpmCalculator.getRevolutionCounter() % 2;
|
int revIndex2 = engine->rpmCalculator.getRevolutionCounter() % 2;
|
||||||
int rpm = getRpm();
|
int rpm = getRpm();
|
||||||
// todo: use event-based scheduling, not just time-based scheduling
|
// todo: use event-based scheduling, not just time-based scheduling
|
||||||
|
if (isValidRpm(rpm)) {
|
||||||
scheduleByAngle(rpm, &tdcScheduler[revIndex2], tdcPosition(),
|
scheduleByAngle(rpm, &tdcScheduler[revIndex2], tdcPosition(),
|
||||||
(schfunc_t) onTdcCallback, NULL, &engine->rpmCalculator);
|
(schfunc_t) onTdcCallback, NULL, &engine->rpmCalculator);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if EFI_PROD_CODE || EFI_SIMULATOR
|
#if EFI_PROD_CODE || EFI_SIMULATOR
|
||||||
|
@ -249,18 +251,9 @@ void initRpmCalculator(Engine *engine) {
|
||||||
* it takes the crankshaft to rotate to the specified angle.
|
* 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) {
|
void scheduleByAngle(int rpm, scheduling_s *timer, angle_t angle, schfunc_t callback, void *param, RpmCalculator *calc) {
|
||||||
if (!isValidRpm(rpm)) {
|
efiAssertVoid(isValidRpm(rpm), "RPM check expected");
|
||||||
/**
|
float delayUs = calc->oneDegreeUs * angle;
|
||||||
* this might happen in case of a single trigger event after a pause - this is normal, so no
|
efiAssertVoid(!cisnan(delayUs), "NaN delay?");
|
||||||
* warning here
|
|
||||||
*/
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
float delayUs = getOneDegreeTimeUs(rpm) * angle;
|
|
||||||
if (cisnan(delayUs)) {
|
|
||||||
firmwareError("NaN delay?");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
scheduleTask("by angle", timer, (int) delayUs, callback, param);
|
scheduleTask("by angle", timer, (int) delayUs, callback, param);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -6,12 +6,12 @@ HW_LAYER_EGT_CPP = $(PROJECT_DIR)/hw_layer/can_hw.cpp \
|
||||||
|
|
||||||
HW_LAYER_EMS = $(HW_LAYER_EGT) \
|
HW_LAYER_EMS = $(HW_LAYER_EGT) \
|
||||||
$(PROJECT_DIR)/hw_layer/mcp3208.c \
|
$(PROJECT_DIR)/hw_layer/mcp3208.c \
|
||||||
$(PROJECT_DIR)/hw_layer/microsecond_timer.c \
|
|
||||||
$(PROJECT_DIR)/hw_layer/flash.c \
|
$(PROJECT_DIR)/hw_layer/flash.c \
|
||||||
$(PROJECT_DIR)/hw_layer/rtc_helper.c
|
$(PROJECT_DIR)/hw_layer/rtc_helper.c
|
||||||
|
|
||||||
HW_LAYER_EMS_CPP = $(HW_LAYER_EGT_CPP) \
|
HW_LAYER_EMS_CPP = $(HW_LAYER_EGT_CPP) \
|
||||||
$(PROJECT_DIR)/hw_layer/pin_repository.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/wave_analyzer_hw.cpp \
|
||||||
$(PROJECT_DIR)/hw_layer/hardware.cpp \
|
$(PROJECT_DIR)/hw_layer/hardware.cpp \
|
||||||
$(PROJECT_DIR)/hw_layer/neo6m.cpp \
|
$(PROJECT_DIR)/hw_layer/neo6m.cpp \
|
||||||
|
|
|
@ -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,
|
* 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.
|
* so this timer can schedule events up to 4B/100M ~ 4000 seconds ~ 1 hour from current time.
|
|
@ -42,7 +42,7 @@ struct_no_prefix engine_configuration_s
|
||||||
|
|
||||||
! please note that 1024 here is 4 * FUEL_RPM_COUNT * FUEL_LOAD_COUNT
|
! 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 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
|
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
|
! please note that 1024 here is 4 * IGN_LOAD_COUNT * IGN_RPM_COUNT
|
||||||
|
|
|
@ -290,5 +290,5 @@ int getRusEfiVersion(void) {
|
||||||
return 123; // this is here to make the compiler happy about the unused array
|
return 123; // this is here to make the compiler happy about the unused array
|
||||||
if (UNUSED_CCM_SIZE[0] * 0 != 0)
|
if (UNUSED_CCM_SIZE[0] * 0 != 0)
|
||||||
return 3211; // this is here to make the compiler happy about the unused array
|
return 3211; // this is here to make the compiler happy about the unused array
|
||||||
return 20150416;
|
return 20150417;
|
||||||
}
|
}
|
||||||
|
|
|
@ -504,7 +504,7 @@ page = 1
|
||||||
ignitionTable = array, F32, 11832, [16x16],"deg", 1, 0, -360, 360, 2
|
ignitionTable = array, F32, 11832, [16x16],"deg", 1, 0, -360, 360, 2
|
||||||
ignitionLoadBins = array, F32, 12856, [16], "Load", 1, 0.0, 0, 300.0, 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
|
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
|
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
|
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
|
afrTable = array, F32, 14136, [16x16],"deg", 1, 0, 0, 25.0, 2
|
||||||
|
|
Loading…
Reference in New Issue