From 4ef2a72930a8f56ddc5703b43b3b5432682b8716 Mon Sep 17 00:00:00 2001 From: rusefi Date: Tue, 9 Jul 2019 16:08:49 -0400 Subject: [PATCH] refactoring: wider usage of new periodic task --- .../actuators/alternator_controller.cpp | 14 ++++++-------- .../actuators/electronic_throttle.cpp | 16 +++++++--------- firmware/controllers/actuators/idle_thread.cpp | 14 ++++++-------- firmware/controllers/engine_controller.cpp | 8 ++++---- firmware/controllers/system/periodic_task.h | 2 +- 5 files changed, 24 insertions(+), 30 deletions(-) diff --git a/firmware/controllers/actuators/alternator_controller.cpp b/firmware/controllers/actuators/alternator_controller.cpp index 355539afd9..125b6e9e44 100644 --- a/firmware/controllers/actuators/alternator_controller.cpp +++ b/firmware/controllers/actuators/alternator_controller.cpp @@ -15,7 +15,7 @@ #include "voltage.h" #include "pid.h" #include "local_version_holder.h" -#include "periodic_thread_controller.h" +#include "periodic_task.h" #include "pwm_generator.h" #include "pin_repository.h" @@ -47,14 +47,12 @@ static void pidReset(void) { altPid.reset(); } -class AlternatorController : public PeriodicController { -public: - AlternatorController() : PeriodicController("AlternatorController") { } -private: - void PeriodicTask(efitime_t nowNt) override { - UNUSED(nowNt); - setPeriod(GET_PERIOD_LIMITED(&engineConfiguration->alternatorControl)); +class AlternatorController : public PeriodicTimerController { + int getPeriodMs() override { + return GET_PERIOD_LIMITED(&engineConfiguration->alternatorControl); + } + void PeriodicTask() override { #if ! EFI_UNIT_TEST if (shouldResetPid) { pidReset(); diff --git a/firmware/controllers/actuators/electronic_throttle.cpp b/firmware/controllers/actuators/electronic_throttle.cpp index f1f6741c78..8f434c3326 100644 --- a/firmware/controllers/actuators/electronic_throttle.cpp +++ b/firmware/controllers/actuators/electronic_throttle.cpp @@ -77,7 +77,7 @@ #include "pwm_generator_logic.h" #include "pid.h" #include "engine_controller.h" -#include "periodic_thread_controller.h" +#include "periodic_task.h" #include "pin_repository.h" #include "pwm_generator.h" #include "dc_motor.h" @@ -169,17 +169,15 @@ static percent_t currentEtbDuty; #define ETB_DUTY_LIMIT 0.9 #define PERCENT_TO_DUTY(X) (maxF(minF((X / 100.0), ETB_DUTY_LIMIT - 0.01), 0.01 - ETB_DUTY_LIMIT)) -class EtbController : public PeriodicController { -public: - EtbController() : PeriodicController("ETB") { } -private: +class EtbController : public PeriodicTimerController { + float feedForward = 0; - void PeriodicTask(efitime_t nowNt) override { - UNUSED(nowNt); - setPeriod(GET_PERIOD_LIMITED(&engineConfiguration->etb)); - + int getPeriodMs() override { + return GET_PERIOD_LIMITED(&engineConfiguration->etb); + } + void PeriodicTask() override { // set debug_mode 17 if (engineConfiguration->debugMode == DBG_ELECTRONIC_THROTTLE_PID) { #if EFI_TUNER_STUDIO diff --git a/firmware/controllers/actuators/idle_thread.cpp b/firmware/controllers/actuators/idle_thread.cpp index f4f1bd8ee5..61d312fa0f 100644 --- a/firmware/controllers/actuators/idle_thread.cpp +++ b/firmware/controllers/actuators/idle_thread.cpp @@ -33,7 +33,7 @@ #include "idle_thread.h" #include "pin_repository.h" #include "engine.h" -#include "periodic_thread_controller.h" +#include "periodic_task.h" #include "stepper.h" #include "allsensors.h" @@ -249,14 +249,12 @@ static percent_t automaticIdleController() { return newValue; } -class IdleController : public PeriodicController { -public: - IdleController() : PeriodicController("IdleValve") { } -private: - void PeriodicTask(efitime_t nowNt) override { - UNUSED(nowNt); - setPeriod(GET_PERIOD_LIMITED(&engineConfiguration->idleRpmPid)); +class IdleController : public PeriodicTimerController { + int getPeriodMs() override { + return GET_PERIOD_LIMITED(&engineConfiguration->idleRpmPid); + } + void PeriodicTask() override { /* * Here we have idle logic thread - actual stepper movement is implemented in a separate * working thread, diff --git a/firmware/controllers/engine_controller.cpp b/firmware/controllers/engine_controller.cpp index 905247dd6c..58768f8ffc 100644 --- a/firmware/controllers/engine_controller.cpp +++ b/firmware/controllers/engine_controller.cpp @@ -337,8 +337,8 @@ static void doPeriodicSlowCallback(DECLARE_ENGINE_PARAMETER_SIGNATURE) { } void initPeriodicEvents(DECLARE_ENGINE_PARAMETER_SIGNATURE) { - slowController.start(); - fastController.start(); + slowController.Start(); + fastController.Start(); } char * getPinNameByAdcChannel(const char *msg, adc_channel_e hwChannel, char *buffer) { @@ -793,7 +793,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 // linking process which is the way to raise the alarm #ifndef RAM_UNUSED_SIZE -#define RAM_UNUSED_SIZE 7400 +#define RAM_UNUSED_SIZE 11000 #endif #ifndef CCM_UNUSED_SIZE #define CCM_UNUSED_SIZE 4600 @@ -814,6 +814,6 @@ int getRusEfiVersion(void) { if (initBootloader() != 0) return 123; #endif /* EFI_BOOTLOADER_INCLUDE_CODE */ - return 20190706; + return 20190709; } #endif /* EFI_UNIT_TEST */ diff --git a/firmware/controllers/system/periodic_task.h b/firmware/controllers/system/periodic_task.h index f5fded8b9b..c73a9f0aeb 100644 --- a/firmware/controllers/system/periodic_task.h +++ b/firmware/controllers/system/periodic_task.h @@ -28,7 +28,7 @@ public: virtual void PeriodicTask() = 0; - void start() { + void Start() { runAndScheduleNext(this); } };