having fun with async - reducing threads

This commit is contained in:
rusefi 2019-07-13 11:06:03 -04:00
parent 636970c0e5
commit 8b0929a9ac
2 changed files with 21 additions and 22 deletions

View File

@ -561,7 +561,7 @@ static bool isTriggerErrorNow() {
extern bool consoleByteArrived; extern bool consoleByteArrived;
class BlinkingTask : public PeriodicTimerController { class CommunicationBlinkingTask : public PeriodicTimerController {
int getPeriodMs() override { int getPeriodMs() override {
return counter % 2 == 0 ? onTimeMs : offTimeMs; return counter % 2 == 0 ? onTimeMs : offTimeMs;
@ -619,7 +619,7 @@ private:
int offTimeMs = 100; int offTimeMs = 100;
}; };
static BlinkingTask blinkingTask; static CommunicationBlinkingTask communicationsBlinkingTask;
#endif /* EFI_PROD_CODE */ #endif /* EFI_PROD_CODE */
@ -964,7 +964,7 @@ void startStatusThreads(void) {
// todo: refactoring needed, this file should probably be split into pieces // todo: refactoring needed, this file should probably be split into pieces
#if EFI_PROD_CODE #if EFI_PROD_CODE
initStatusLeds(); initStatusLeds();
blinkingTask.Start(); communicationsBlinkingTask.Start();
#endif /* EFI_PROD_CODE */ #endif /* EFI_PROD_CODE */
#if EFI_LCD #if EFI_LCD

View File

@ -142,27 +142,28 @@ Engine ___engine CCM_OPTIONAL;
Engine * engine = &___engine; Engine * engine = &___engine;
#endif /* EFI_PROD_CODE || EFI_SIMULATOR */ #endif /* EFI_PROD_CODE || EFI_SIMULATOR */
static msg_t csThread(void) { class EngineStateBlinkingTask : public PeriodicTimerController {
chRegSetThreadName("status"); int getPeriodMs() override {
#if EFI_SHAFT_POSITION_INPUT return 50;
while (true) { }
int is_cranking = ENGINE(rpmCalculator).isCranking(PASS_ENGINE_PARAMETER_SIGNATURE);
void PeriodicTask() override {
counter++;
bool is_running = ENGINE(rpmCalculator).isRunning(PASS_ENGINE_PARAMETER_SIGNATURE); bool is_running = ENGINE(rpmCalculator).isRunning(PASS_ENGINE_PARAMETER_SIGNATURE);
if (is_running) { if (is_running) {
// blinking while running // blink in running mode
enginePins.runningLedPin.setValue(0); enginePins.runningLedPin.setValue(counter % 2);
chThdSleepMilliseconds(50);
enginePins.runningLedPin.setValue(1);
chThdSleepMilliseconds(50);
} else { } else {
// constant on while cranking and off if engine is stopped int is_cranking = ENGINE(rpmCalculator).isCranking(PASS_ENGINE_PARAMETER_SIGNATURE);
enginePins.runningLedPin.setValue(is_cranking); enginePins.runningLedPin.setValue(is_cranking);
chThdSleepMilliseconds(100);
} }
} }
#endif /* EFI_SHAFT_POSITION_INPUT */ private:
return -1; int counter = 0;
} };
static EngineStateBlinkingTask engineStateBlinkingTask;
#if EFI_PROD_CODE #if EFI_PROD_CODE
static Overflow64Counter halTime; static Overflow64Counter halTime;
@ -427,8 +428,6 @@ static void printAnalogInfo(void) {
engineConfiguration->vbattDividerCoeff); engineConfiguration->vbattDividerCoeff);
} }
static THD_WORKING_AREA(csThreadStack, UTILITY_THREAD_STACK_SIZE); // declare thread stack
#define isOutOfBounds(offset) ((offset<0) || (offset) >= (int) sizeof(engine_configuration_s)) #define isOutOfBounds(offset) ((offset<0) || (offset) >= (int) sizeof(engine_configuration_s))
static void getShort(int offset) { static void getShort(int offset) {
@ -719,7 +718,7 @@ void initEngineContoller(Logging *sharedLogger DECLARE_ENGINE_PARAMETER_SUFFIX)
return; return;
} }
chThdCreateStatic(csThreadStack, sizeof(csThreadStack), LOWPRIO, (tfunc_t)(void*) csThread, NULL); engineStateBlinkingTask.Start();
#if EFI_PROD_CODE && EFI_ENGINE_CONTROL #if EFI_PROD_CODE && EFI_ENGINE_CONTROL
/** /**
@ -793,7 +792,7 @@ void initEngineContoller(Logging *sharedLogger DECLARE_ENGINE_PARAMETER_SUFFIX)
// help to notice when RAM usage goes up - if a code change adds to RAM usage these variables would fail // help to notice when RAM usage goes up - if a code change adds to RAM usage these variables would fail
// linking process which is the way to raise the alarm // linking process which is the way to raise the alarm
#ifndef RAM_UNUSED_SIZE #ifndef RAM_UNUSED_SIZE
#define RAM_UNUSED_SIZE 16000 #define RAM_UNUSED_SIZE 17500
#endif #endif
#ifndef CCM_UNUSED_SIZE #ifndef CCM_UNUSED_SIZE
#define CCM_UNUSED_SIZE 4600 #define CCM_UNUSED_SIZE 4600