auto-sync

This commit is contained in:
rusEfi 2014-11-25 15:03:16 -06:00
parent 344374457a
commit 92dc1cc061
6 changed files with 26 additions and 30 deletions

View File

@ -54,7 +54,7 @@ char hexChar(int v) {
return 'A' - 10 + v;
}
// todo: why does it not compile if I make this function 'inline'?
// todo: make this a macro?
int isIsrContext(void) {
/**
* Unfortunately ChibiOS has two versions of methods for different
@ -63,6 +63,7 @@ int isIsrContext(void) {
return dbg_isr_cnt > 0;
}
// todo: make this a macro?
int isLocked(void) {
return dbg_lock_cnt > 0;
}

View File

@ -48,17 +48,12 @@ static void executorCallback(void *arg) {
}
Executor::Executor() {
reentrantLock = false;
reentrantFlag = false;
queue.setLateDelay(US2NT(100));
}
void Executor::lock(void) {
lockAnyContext();
}
void Executor::unlock(void) {
unlockAnyContext();
}
#define lock() lockAnyContext()
#define unlock() unlockAnyContext()
void Executor::schedule2(scheduling_s *scheduling, uint64_t timeUs, schfunc_t callback,
void *param) {
@ -70,12 +65,12 @@ void Executor::schedule2(scheduling_s *scheduling, uint64_t timeUs, schfunc_t ca
// callback(param);
// return;
// }
if (!reentrantLock) {
if (!reentrantFlag) {
// this would guard the queue and disable interrupts
lock();
}
queue.insertTask(scheduling, US2NT(timeUs), callback, param);
if (!reentrantLock) {
if (!reentrantFlag) {
doExecute();
unlock();
}
@ -98,10 +93,10 @@ void Executor::onTimerCallback() {
void Executor::doExecute() {
/**
* Let's execute actions we should execute at this point.
* reentrantLock takes care of the use case where the actions we are executing are scheduling
* reentrantFlag takes care of the use case where the actions we are executing are scheduling
* further invocations
*/
reentrantLock = TRUE;
reentrantFlag = true;
bool shouldExecute = true;
/**
* in real life it could be that while we executing listeners time passes and it's already time to execute
@ -120,7 +115,7 @@ void Executor::doExecute() {
return;
}
uint64_t nowNt = getTimeNowNt();
reentrantLock = false;
reentrantFlag = false;
/**
* 'executeAll' is potentially invoking heavy callbacks, let's grab fresh time value?
*/

View File

@ -19,10 +19,8 @@ public:
void onTimerCallback();
private:
EventQueue queue;
bool reentrantLock;
bool reentrantFlag;
void doExecute();
void lock(void);
void unlock(void);
};
#ifdef __cplusplus

View File

@ -14,6 +14,7 @@
#include "main.h"
#include "event_queue.h"
#include "efitime.h"
#include "efilib2.h"
EventQueue::EventQueue() {
head = NULL;
@ -76,7 +77,8 @@ uint64_t EventQueue::getNextEventTime(uint64_t nowX) {
}
// static scheduling_s * longScheduling;
// static uint32_t cost;
uint32_t maxEventQueueTime = 0;
uint32_t lastEventQueueTime;
/**
* Invoke all pending actions prior to specified timestamp
@ -109,10 +111,12 @@ bool EventQueue::executeAll(uint64_t now) {
bool result = (executionList != NULL);
LL_FOREACH_SAFE(executionList, current, tmp)
{
// uint32_t before = hal_lld_get_counter_value();
uint32_t before = GET_TIMESTAMP();
current->callback(current->param);
// even with overflow it's safe to substract here
// cost = hal_lld_get_counter_value() - before;
lastEventQueueTime = GET_TIMESTAMP() - before;
if (lastEventQueueTime > maxEventQueueTime)
maxEventQueueTime = lastEventQueueTime;
// if (cost > 2000) {
// longScheduling = current;
// cost++;

View File

@ -212,6 +212,7 @@ extern PwmConfig triggerSignal;
#endif /* #if EFI_PROD_CODE */
extern uint32_t maxLockTime;
extern uint32_t maxEventQueueTime;
static void triggerInfo(Engine *engine) {
#if (EFI_PROD_CODE || EFI_SIMULATOR) || defined(__DOXYGEN__)
@ -221,11 +222,6 @@ static void triggerInfo(Engine *engine) {
scheduleMsg(&logger, "Template %s/%d trigger %d", getConfigurationName(engineConfiguration->engineType),
engineConfiguration->engineType, engineConfiguration->triggerConfig.triggerType);
scheduleMsg(&logger, "sn=%d ignitionMathTime=%d schTime=%d",
ts->isSynchronizationNeeded,
engine->ignitionMathTime,
engine->ignitionSchTime);
scheduleMsg(&logger, "trigger event counters %d/%d/%d/%d", triggerCentral.getHwEventCounter(0),
triggerCentral.getHwEventCounter(1), triggerCentral.getHwEventCounter(2),
triggerCentral.getHwEventCounter(3));
@ -245,7 +241,13 @@ static void triggerInfo(Engine *engine) {
#endif
#if EFI_PROD_CODE
scheduleMsg(&logger, "sn=%s ignitionMathTime=%d schTime=%d",
boolToString(ts->isSynchronizationNeeded),
engine->ignitionMathTime,
engine->ignitionSchTime);
scheduleMsg(&logger, "maxLockTime=%d / maxTriggerReentraint=%d", maxLockTime, maxTriggerReentraint);
scheduleMsg(&logger, "maxEventQueueTime=%d", maxEventQueueTime);
scheduleMsg(&logger, "primary trigger simulator: %s %s freq=%d",
hwPortname(boardConfiguration->triggerSimulatorPins[0]),
pinModeToString(boardConfiguration->triggerSimulatorPinModes[0]),

View File

@ -31,11 +31,7 @@ class Engine;
class trigger_shape_s {
public:
trigger_shape_s();
/**
* todo: something really weird - unit test fail on Linux build server
* if I change this type to bool_t? WAT?
*/
int isSynchronizationNeeded;
bool_t isSynchronizationNeeded;
int totalToothCount;
int skippedToothCount;