mirror of https://github.com/rusefi/rusefi-1.git
wider usage of PeriodicController
This commit is contained in:
parent
00e7bfa1f5
commit
24b1b34fef
|
@ -57,6 +57,7 @@
|
||||||
#include "lcd_controller.h"
|
#include "lcd_controller.h"
|
||||||
#include "settings.h"
|
#include "settings.h"
|
||||||
#include "can_hw.h"
|
#include "can_hw.h"
|
||||||
|
#include "PeriodicController.h"
|
||||||
#include "cdm_ion_sense.h"
|
#include "cdm_ion_sense.h"
|
||||||
|
|
||||||
extern afr_Map3D_t afrMap;
|
extern afr_Map3D_t afrMap;
|
||||||
|
@ -539,8 +540,6 @@ static void showFuelInfo(void) {
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static THD_WORKING_AREA(lcdThreadStack, UTILITY_THREAD_STACK_SIZE);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* blinking thread to show that we are alive
|
* blinking thread to show that we are alive
|
||||||
* that's a trivial task - a smaller stack should work
|
* that's a trivial task - a smaller stack should work
|
||||||
|
@ -651,18 +650,21 @@ static void blinkingThread(void *arg) {
|
||||||
|
|
||||||
#endif /* EFI_PROD_CODE */
|
#endif /* EFI_PROD_CODE */
|
||||||
|
|
||||||
static void lcdThread(void *arg) {
|
class LcdController : public PeriodicController<UTILITY_THREAD_STACK_SIZE> {
|
||||||
(void)arg;
|
public:
|
||||||
chRegSetThreadName("lcd");
|
LcdController() : PeriodicController("BenchThread") { }
|
||||||
while (true) {
|
private:
|
||||||
|
void PeriodicTask(efitime_t nowNt) override {
|
||||||
|
setPeriod(NOT_TOO_OFTEN(10 /* ms */, engineConfiguration->bc.lcdThreadPeriodMs));
|
||||||
if (engineConfiguration->bc.useLcdScreen) {
|
if (engineConfiguration->bc.useLcdScreen) {
|
||||||
#if EFI_HD44780_LCD
|
#if EFI_HD44780_LCD
|
||||||
updateHD44780lcd();
|
updateHD44780lcd();
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
chThdSleepMilliseconds(engineConfiguration->bc.lcdThreadPeriodMs);
|
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
|
|
||||||
|
static LcdController lcdInstance;
|
||||||
|
|
||||||
#if EFI_HIP_9011 || defined(__DOXYGEN__)
|
#if EFI_HIP_9011 || defined(__DOXYGEN__)
|
||||||
extern HIP9011 instance;
|
extern HIP9011 instance;
|
||||||
|
@ -977,11 +979,11 @@ void initStatusLoop(void) {
|
||||||
|
|
||||||
void startStatusThreads(void) {
|
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
|
||||||
chThdCreateStatic(lcdThreadStack, sizeof(lcdThreadStack), NORMALPRIO, (tfunc_t) lcdThread, NULL);
|
|
||||||
#if EFI_PROD_CODE || defined(__DOXYGEN__)
|
#if EFI_PROD_CODE || defined(__DOXYGEN__)
|
||||||
initStatusLeds();
|
initStatusLeds();
|
||||||
chThdCreateStatic(blinkingStack, sizeof(blinkingStack), NORMALPRIO, (tfunc_t) blinkingThread, NULL);
|
chThdCreateStatic(blinkingStack, sizeof(blinkingStack), NORMALPRIO, (tfunc_t) blinkingThread, NULL);
|
||||||
#endif /* EFI_PROD_CODE */
|
#endif /* EFI_PROD_CODE */
|
||||||
|
lcdInstance.Start();
|
||||||
}
|
}
|
||||||
|
|
||||||
void setFullLog(int value) {
|
void setFullLog(int value) {
|
||||||
|
|
|
@ -31,13 +31,12 @@
|
||||||
#include "idle_thread.h"
|
#include "idle_thread.h"
|
||||||
#include "pin_repository.h"
|
#include "pin_repository.h"
|
||||||
#include "engine.h"
|
#include "engine.h"
|
||||||
|
#include "PeriodicController.h"
|
||||||
#include "stepper.h"
|
#include "stepper.h"
|
||||||
|
|
||||||
#if EFI_IDLE_CONTROL || defined(__DOXYGEN__)
|
#if EFI_IDLE_CONTROL || defined(__DOXYGEN__)
|
||||||
#include "allsensors.h"
|
#include "allsensors.h"
|
||||||
|
|
||||||
static THD_WORKING_AREA(ivThreadStack, UTILITY_THREAD_STACK_SIZE);
|
|
||||||
|
|
||||||
static Logging *logger;
|
static Logging *logger;
|
||||||
#if EFI_TUNER_STUDIO || defined(__DOXYGEN__)
|
#if EFI_TUNER_STUDIO || defined(__DOXYGEN__)
|
||||||
extern TunerStudioOutputChannels tsOutputChannels;
|
extern TunerStudioOutputChannels tsOutputChannels;
|
||||||
|
@ -76,7 +75,6 @@ typedef enum {
|
||||||
|
|
||||||
idle_state_e idleState = INIT;
|
idle_state_e idleState = INIT;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* that's current position with CLT and IAT corrections
|
* that's current position with CLT and IAT corrections
|
||||||
*/
|
*/
|
||||||
|
@ -266,9 +264,12 @@ static percent_t automaticIdleController() {
|
||||||
return newValue;
|
return newValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
static msg_t ivThread(int param) {
|
class IdleController : public PeriodicController<UTILITY_THREAD_STACK_SIZE> {
|
||||||
(void) param;
|
public:
|
||||||
chRegSetThreadName("IdleValve");
|
IdleController() : PeriodicController("IdleValve") { }
|
||||||
|
private:
|
||||||
|
void PeriodicTask(efitime_t nowNt) override {
|
||||||
|
setPeriod(NOT_TOO_OFTEN(10 /* ms */, engineConfiguration->idleRpmPid.periodMs));
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Here we have idle logic thread - actual stepper movement is implemented in a separate
|
* Here we have idle logic thread - actual stepper movement is implemented in a separate
|
||||||
|
@ -276,9 +277,6 @@ static msg_t ivThread(int param) {
|
||||||
* @see stepper.cpp
|
* @see stepper.cpp
|
||||||
*/
|
*/
|
||||||
|
|
||||||
while (true) {
|
|
||||||
idlePid.sleep(); // in both manual and auto mode same period is used
|
|
||||||
|
|
||||||
if (engineConfiguration->isVerboseIAC && engineConfiguration->idleMode == IM_AUTO) {
|
if (engineConfiguration->isVerboseIAC && engineConfiguration->idleMode == IM_AUTO) {
|
||||||
scheduleMsg(logger, "state %d", idleState);
|
scheduleMsg(logger, "state %d", idleState);
|
||||||
idlePid.showPidStatus(logger, "idle");
|
idlePid.showPidStatus(logger, "idle");
|
||||||
|
@ -374,17 +372,16 @@ static msg_t ivThread(int param) {
|
||||||
// The threshold is dependent on IAC type (see initIdleHardware())
|
// The threshold is dependent on IAC type (see initIdleHardware())
|
||||||
if (absF(iacPosition - currentIdlePosition) < idlePositionSensitivityThreshold) {
|
if (absF(iacPosition - currentIdlePosition) < idlePositionSensitivityThreshold) {
|
||||||
idleState = PWM_PRETTY_CLOSE;
|
idleState = PWM_PRETTY_CLOSE;
|
||||||
continue; // value is pretty close, let's leave the poor valve alone
|
return; // value is pretty close, let's leave the poor valve alone
|
||||||
}
|
}
|
||||||
|
|
||||||
currentIdlePosition = iacPosition;
|
currentIdlePosition = iacPosition;
|
||||||
idleState = ADJUSTING;
|
idleState = ADJUSTING;
|
||||||
applyIACposition(currentIdlePosition);
|
applyIACposition(currentIdlePosition);
|
||||||
}
|
}
|
||||||
#if defined __GNUC__
|
};
|
||||||
return -1;
|
|
||||||
#endif
|
static IdleController instance;
|
||||||
}
|
|
||||||
|
|
||||||
void setTargetIdleRpm(int value) {
|
void setTargetIdleRpm(int value) {
|
||||||
setTargetRpmCurve(value PASS_ENGINE_PARAMETER_SUFFIX);
|
setTargetRpmCurve(value PASS_ENGINE_PARAMETER_SUFFIX);
|
||||||
|
@ -486,7 +483,7 @@ void startIdleThread(Logging*sharedLogger) {
|
||||||
|
|
||||||
//scheduleMsg(logger, "initial idle %d", idlePositionController.value);
|
//scheduleMsg(logger, "initial idle %d", idlePositionController.value);
|
||||||
|
|
||||||
chThdCreateStatic(ivThreadStack, sizeof(ivThreadStack), NORMALPRIO, (tfunc_t)(void*) ivThread, NULL);
|
instance.Start();
|
||||||
|
|
||||||
// this is neutral/no gear switch input. on Miata it's wired both to clutch pedal and neutral in gearbox
|
// this is neutral/no gear switch input. on Miata it's wired both to clutch pedal and neutral in gearbox
|
||||||
// this switch is not used yet
|
// this switch is not used yet
|
||||||
|
|
|
@ -217,7 +217,7 @@ void dizzyBench(void) {
|
||||||
|
|
||||||
class BenchController : public PeriodicController<UTILITY_THREAD_STACK_SIZE> {
|
class BenchController : public PeriodicController<UTILITY_THREAD_STACK_SIZE> {
|
||||||
public:
|
public:
|
||||||
BenchController() : PeriodicController("BenchThread") { }
|
BenchController() : PeriodicController("BenchThread") { }
|
||||||
private:
|
private:
|
||||||
void PeriodicTask(efitime_t nowNt) override {
|
void PeriodicTask(efitime_t nowNt) override {
|
||||||
setPeriod(NOT_TOO_OFTEN(10 /* ms */, engineConfiguration->auxPid[0].periodMs));
|
setPeriod(NOT_TOO_OFTEN(10 /* ms */, engineConfiguration->auxPid[0].periodMs));
|
||||||
|
|
|
@ -24,6 +24,7 @@ EXTERN_ENGINE;
|
||||||
#if EFI_MEMS || defined(__DOXYGEN__)
|
#if EFI_MEMS || defined(__DOXYGEN__)
|
||||||
#include "mpu_util.h"
|
#include "mpu_util.h"
|
||||||
#include "lis302dl.h"
|
#include "lis302dl.h"
|
||||||
|
#include "PeriodicController.h"
|
||||||
|
|
||||||
static SPIDriver *driver;
|
static SPIDriver *driver;
|
||||||
|
|
||||||
|
@ -56,21 +57,20 @@ void configureAccelerometerPins(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
|
||||||
|
|
||||||
static THD_WORKING_AREA(ivThreadStack, UTILITY_THREAD_STACK_SIZE);
|
static THD_WORKING_AREA(ivThreadStack, UTILITY_THREAD_STACK_SIZE);
|
||||||
|
|
||||||
static msg_t ivThread(int param) {
|
class AccelController : public PeriodicController<UTILITY_THREAD_STACK_SIZE> {
|
||||||
(void) param;
|
public:
|
||||||
chRegSetThreadName("Acc SPI");
|
AccelController() : PeriodicController("Acc SPI") { }
|
||||||
while (true) {
|
private:
|
||||||
|
void PeriodicTask(efitime_t nowNt) override {
|
||||||
// has to be a thread since we want to use blocking method - blocking method only available in threads, not in interrupt handler
|
// has to be a thread since we want to use blocking method - blocking method only available in threads, not in interrupt handler
|
||||||
// todo: migrate to async SPI API?
|
// todo: migrate to async SPI API?
|
||||||
engine->sensors.accelerometer.x = (int8_t)lis302dlReadRegister(driver, LIS302DL_OUTX);
|
engine->sensors.accelerometer.x = (int8_t)lis302dlReadRegister(driver, LIS302DL_OUTX);
|
||||||
engine->sensors.accelerometer.y = (int8_t)lis302dlReadRegister(driver, LIS302DL_OUTY);
|
engine->sensors.accelerometer.y = (int8_t)lis302dlReadRegister(driver, LIS302DL_OUTY);
|
||||||
chThdSleepMilliseconds(20);
|
chThdSleepMilliseconds(20);
|
||||||
}
|
}
|
||||||
|
};
|
||||||
|
|
||||||
#if defined __GNUC__
|
static BenchController instance;
|
||||||
return -1;
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
void initAccelerometer(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
|
void initAccelerometer(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
|
||||||
if (engineConfiguration->LIS302DLCsPin == GPIO_UNASSIGNED)
|
if (engineConfiguration->LIS302DLCsPin == GPIO_UNASSIGNED)
|
||||||
|
|
Loading…
Reference in New Issue