Merge remote-tracking branch 'origin/master' into master

This commit is contained in:
rusefillc 2020-10-05 11:19:57 -04:00
commit bfeeef72a8
8 changed files with 55 additions and 70 deletions

View File

@ -54,6 +54,7 @@ static LENameOrdinalPair leMap(LE_METHOD_MAP, "map");
static LENameOrdinalPair leVBatt(LE_METHOD_VBATT, "vbatt"); static LENameOrdinalPair leVBatt(LE_METHOD_VBATT, "vbatt");
static LENameOrdinalPair leFan(LE_METHOD_FAN, "fan"); static LENameOrdinalPair leFan(LE_METHOD_FAN, "fan");
static LENameOrdinalPair leCoolant(LE_METHOD_COOLANT, "coolant"); static LENameOrdinalPair leCoolant(LE_METHOD_COOLANT, "coolant");
static LENameOrdinalPair leIntakeTemp(LE_METHOD_INTAKE_AIR, "iat");
static LENameOrdinalPair leIsCoolantBroken(LE_METHOD_IS_COOLANT_BROKEN, "is_clt_broken"); static LENameOrdinalPair leIsCoolantBroken(LE_METHOD_IS_COOLANT_BROKEN, "is_clt_broken");
// @returns boolean state of A/C toggle switch // @returns boolean state of A/C toggle switch
static LENameOrdinalPair leAcToggle(LE_METHOD_AC_TOGGLE, "ac_on_switch"); static LENameOrdinalPair leAcToggle(LE_METHOD_AC_TOGGLE, "ac_on_switch");

View File

@ -1,2 +1,2 @@
#pragma once #pragma once
#define VCS_DATE 20201004 #define VCS_DATE 20201005

View File

@ -120,14 +120,23 @@ int EventQueue::executeAll(efitime_t now) {
assertListIsSorted(); assertListIsSorted();
#endif #endif
while (true) { bool didExecute;
do {
didExecute = executeOne(now);
executionCounter += didExecute ? 1 : 0;
} while (didExecute);
return executionCounter;
}
bool EventQueue::executeOne(efitime_t now) {
// Read the head every time - a previously executed event could // Read the head every time - a previously executed event could
// have inserted something new at the head // have inserted something new at the head
scheduling_s* current = head; scheduling_s* current = head;
// Queue is empty - bail // Queue is empty - bail
if (!current) { if (!current) {
break; return false;
} }
// If the next event is far in the future, we'll reschedule // If the next event is far in the future, we'll reschedule
@ -137,7 +146,7 @@ int EventQueue::executeAll(efitime_t now) {
// waiting for the time to arrive. On current CPUs, this is reasonable to set // waiting for the time to arrive. On current CPUs, this is reasonable to set
// around 10 microseconds. // around 10 microseconds.
if (current->momentX > now + lateDelay) { if (current->momentX > now + lateDelay) {
break; return false;
} }
// near future - spin wait for the event to happen and avoid the // near future - spin wait for the event to happen and avoid the
@ -147,8 +156,6 @@ int EventQueue::executeAll(efitime_t now) {
UNIT_TEST_BUSY_WAIT_CALLBACK(); UNIT_TEST_BUSY_WAIT_CALLBACK();
} }
executionCounter++;
// step the head forward, unlink this element, clear scheduled flag // step the head forward, unlink this element, clear scheduled flag
head = current->nextScheduling_s; head = current->nextScheduling_s;
current->nextScheduling_s = nullptr; current->nextScheduling_s = nullptr;
@ -168,9 +175,8 @@ int EventQueue::executeAll(efitime_t now) {
// (tests only) Ensure we didn't break anything // (tests only) Ensure we didn't break anything
assertListIsSorted(); assertListIsSorted();
#endif #endif
}
return executionCounter; return true;
} }
int EventQueue::size(void) const { int EventQueue::size(void) const {

View File

@ -56,6 +56,7 @@ public:
bool insertTask(scheduling_s *scheduling, efitime_t timeX, action_s action); bool insertTask(scheduling_s *scheduling, efitime_t timeX, action_s action);
int executeAll(efitime_t now); int executeAll(efitime_t now);
bool executeOne(efitime_t now);
efitime_t getNextEventTime(efitime_t nowUs) const; efitime_t getNextEventTime(efitime_t nowUs) const;
void clear(void); void clear(void);

View File

@ -21,7 +21,7 @@
* We need to limit the number of iterations in order to avoid precision loss while calculating * We need to limit the number of iterations in order to avoid precision loss while calculating
* next toggle time * next toggle time
*/ */
#define ITERATION_LIMIT 1000 #define ITERATION_LIMIT 100
// 1% duty cycle // 1% duty cycle
#define ZERO_PWM_THRESHOLD 0.01 #define ZERO_PWM_THRESHOLD 0.01
@ -123,7 +123,7 @@ static efitick_t getNextSwitchTimeNt(PwmConfig *state) {
* Once 'iteration' gets relatively high, we might lose calculation precision here. * Once 'iteration' gets relatively high, we might lose calculation precision here.
* This is addressed by ITERATION_LIMIT * This is addressed by ITERATION_LIMIT
*/ */
efitick_t timeToSwitchNt = (efitick_t) ((iteration + switchTime) * periodNt); uint32_t timeToSwitchNt = (uint32_t)((iteration + switchTime) * periodNt);
#if DEBUG_PWM #if DEBUG_PWM
scheduleMsg(&logger, "start=%d timeToSwitch=%d", state->safe.start, timeToSwitch); scheduleMsg(&logger, "start=%d timeToSwitch=%d", state->safe.start, timeToSwitch);
@ -175,8 +175,6 @@ void PwmConfig::handleCycleStart() {
* @return Next time for signal toggle * @return Next time for signal toggle
*/ */
efitick_t PwmConfig::togglePwmState() { efitick_t PwmConfig::togglePwmState() {
ScopePerf perf(PE::PwmConfigTogglePwmState);
if (isStopRequested) { if (isStopRequested) {
return 0; return 0;
} }
@ -224,20 +222,6 @@ efitick_t PwmConfig::togglePwmState() {
#if DEBUG_PWM #if DEBUG_PWM
scheduleMsg(&logger, "%s: nextSwitchTime %d", state->name, nextSwitchTime); scheduleMsg(&logger, "%s: nextSwitchTime %d", state->name, nextSwitchTime);
#endif /* DEBUG_PWM */ #endif /* DEBUG_PWM */
// signed value is needed here
// int64_t timeToSwitch = nextSwitchTimeUs - getTimeNowUs();
// if (timeToSwitch < 1) {
// /**
// * We are here if we are late for a state transition.
// * At 12000RPM=200Hz with a 60 toothed wheel we need to change state every
// * 1000000 / 200 / 120 = ~41 uS. We are kind of OK.
// *
// * We are also here after a flash write. Flash write freezes the whole chip for a couple of seconds,
// * so PWM generation and trigger simulation generation would have to recover from this time lag.
// */
// //todo: introduce error and test this error handling warning(OBD_PCM_Processor_Fault, "PWM: negative switch time");
// timeToSwitch = 10;
// }
safe.phaseIndex++; safe.phaseIndex++;
if (safe.phaseIndex == phaseCount || mode != PM_NORMAL) { if (safe.phaseIndex == phaseCount || mode != PM_NORMAL) {

View File

@ -41,7 +41,6 @@ EXTERN_ENGINE;
static efitime_t nextEventTimeNt = 0; static efitime_t nextEventTimeNt = 0;
uint32_t hwSetTimerDuration; uint32_t hwSetTimerDuration;
uint32_t lastExecutionCount;
void globalTimerCallback() { void globalTimerCallback() {
efiAssertVoid(CUSTOM_ERR_6624, getCurrentRemainingStack() > EXPECTED_REMAINING_STACK, "lowstck#2y"); efiAssertVoid(CUSTOM_ERR_6624, getCurrentRemainingStack() > EXPECTED_REMAINING_STACK, "lowstck#2y");
@ -131,16 +130,13 @@ void SingleTimerExecutor::executeAllPendingActions() {
* next listeners. * next listeners.
* TODO: add a counter & figure out a limit of iterations? * TODO: add a counter & figure out a limit of iterations?
*/ */
int totalExecuted = 0;
while (shouldExecute > 0) { bool didExecute;
/** do {
* It's worth noting that that the actions might be adding new actions into the queue
*/
efitick_t nowNt = getTimeNowNt(); efitick_t nowNt = getTimeNowNt();
shouldExecute = queue.executeAll(nowNt); didExecute = queue.executeOne(nowNt);
totalExecuted += shouldExecute; } while (didExecute);
}
lastExecutionCount = totalExecuted;
if (!isLocked()) { if (!isLocked()) {
firmwareError(CUSTOM_ERR_LOCK_ISSUE, "Someone has stolen my lock"); firmwareError(CUSTOM_ERR_LOCK_ISSUE, "Someone has stolen my lock");
return; return;
@ -162,10 +158,9 @@ void SingleTimerExecutor::scheduleTimerCallback() {
efiAssertVoid(CUSTOM_ERR_6625, nextEventTimeNt > nowNt, "setTimer constraint"); efiAssertVoid(CUSTOM_ERR_6625, 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
int32_t hwAlarmTime = NT2US((int32_t)nextEventTimeNt - (int32_t)nowNt); int32_t hwAlarmTime = NT2US((int32_t)nextEventTimeNt - (int32_t)nowNt);
uint32_t beforeHwSetTimer = getTimeNowLowerNt();
setHardwareUsTimer(hwAlarmTime == 0 ? 1 : hwAlarmTime); setHardwareUsTimer(hwAlarmTime == 0 ? 1 : hwAlarmTime);
hwSetTimerDuration = getTimeNowLowerNt() - beforeHwSetTimer;
} }
void initSingleTimerExecutorHardware(void) { void initSingleTimerExecutorHardware(void) {

View File

@ -603,7 +603,6 @@ extern PwmConfig triggerSignal;
#endif /* #if EFI_PROD_CODE */ #endif /* #if EFI_PROD_CODE */
extern uint32_t hipLastExecutionCount; extern uint32_t hipLastExecutionCount;
extern uint32_t hwSetTimerDuration;
extern uint32_t maxLockedDuration; extern uint32_t maxLockedDuration;
extern uint32_t maxEventCallbackDuration; extern uint32_t maxEventCallbackDuration;
@ -737,7 +736,6 @@ void triggerInfo(void) {
#if EFI_HIP_9011 #if EFI_HIP_9011
scheduleMsg(logger, "hipLastExecutionCount=%d", hipLastExecutionCount); scheduleMsg(logger, "hipLastExecutionCount=%d", hipLastExecutionCount);
#endif /* EFI_HIP_9011 */ #endif /* EFI_HIP_9011 */
scheduleMsg(logger, "hwSetTimerDuration=%d", hwSetTimerDuration);
scheduleMsg(logger, "totalTriggerHandlerMaxTime=%d", triggerMaxDuration); scheduleMsg(logger, "totalTriggerHandlerMaxTime=%d", triggerMaxDuration);
scheduleMsg(logger, "maxPrecisionCallbackDuration=%d", maxPrecisionCallbackDuration); scheduleMsg(logger, "maxPrecisionCallbackDuration=%d", maxPrecisionCallbackDuration);

View File

@ -51,7 +51,7 @@ enum class PE : uint8_t {
EventQueueExecuteCallback, EventQueueExecuteCallback,
PwmGeneratorCallback, PwmGeneratorCallback,
TunerStudioHandleCrcCommand, TunerStudioHandleCrcCommand,
PwmConfigTogglePwmState, Unused,
PwmConfigStateChangeCallback, PwmConfigStateChangeCallback,
Temporary1, Temporary1,
Temporary2, Temporary2,