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