The Big Refactoring of 2019: scheduler should not be global #655
This commit is contained in:
parent
5ffcc396eb
commit
970d120a41
|
@ -41,7 +41,7 @@ static void toggleTestAndScheduleNext() {
|
|||
testPin.toggle();
|
||||
periodIndex = (periodIndex + 1) % TEST_LEN;
|
||||
testTime += test557[periodIndex];
|
||||
scheduleByTimestamp(&scheduling, testTime, (schfunc_t) &toggleTestAndScheduleNext, NULL);
|
||||
engine->executor.scheduleByTimestamp(&scheduling, testTime, (schfunc_t) &toggleTestAndScheduleNext, NULL);
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -115,7 +115,9 @@ static void turnAuxPidOn(int index) {
|
|||
return;
|
||||
}
|
||||
|
||||
startSimplePwmExt(&auxPidPwm[index], "Aux PID", engineConfiguration->auxPidPins[index],
|
||||
startSimplePwmExt(&auxPidPwm[index], "Aux PID",
|
||||
&engine->executor,
|
||||
engineConfiguration->auxPidPins[index],
|
||||
&auxPidPin[0],
|
||||
engineConfiguration->auxPidFrequency[index], 0.1, applyPinState);
|
||||
}
|
||||
|
|
|
@ -24,7 +24,7 @@ EXTERN_ENGINE
|
|||
|
||||
static Logging *logger;
|
||||
|
||||
static SimplePwm alternatorControl;
|
||||
static SimplePwm alternatorControl("alt");
|
||||
static pid_s *altPidS = &persistentState.persistentConfiguration.engineConfiguration.alternatorControl;
|
||||
static Pid altPid(altPidS);
|
||||
|
||||
|
@ -162,7 +162,10 @@ void initAlternatorCtrl(Logging *sharedLogger) {
|
|||
enginePins.alternatorPin.initPin("on/off alternator", boardConfiguration->alternatorControlPin);
|
||||
|
||||
} else {
|
||||
startSimplePwmExt(&alternatorControl, "Alternator control", boardConfiguration->alternatorControlPin,
|
||||
startSimplePwmExt(&alternatorControl,
|
||||
"Alternator control",
|
||||
&engine->executor,
|
||||
boardConfiguration->alternatorControlPin,
|
||||
&enginePins.alternatorPin,
|
||||
engineConfiguration->alternatorPwmFrequency, 0.1, applyAlternatorPinState);
|
||||
}
|
||||
|
|
|
@ -659,7 +659,9 @@ void initFsioImpl(Logging *sharedLogger DECLARE_ENGINE_PARAMETER_SUFFIX) {
|
|||
if (frequency == 0) {
|
||||
enginePins.fsioOutputs[i].initPin(getGpioPinName(i), boardConfiguration->fsioOutputPins[i], &DEFAULT_OUTPUT);
|
||||
} else {
|
||||
startSimplePwmExt(&fsioPwm[i], "FSIOpwm", brainPin, &enginePins.fsioOutputs[i], frequency, 0.5f, applyPinState);
|
||||
startSimplePwmExt(&fsioPwm[i], "FSIOpwm",
|
||||
&engine->executor,
|
||||
brainPin, &enginePins.fsioOutputs[i], frequency, 0.5f, applyPinState);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -82,10 +82,10 @@ static THD_WORKING_AREA(etbTreadStack, UTILITY_THREAD_STACK_SIZE);
|
|||
/**
|
||||
* @brief Pulse-Width Modulation state
|
||||
*/
|
||||
static SimplePwm etbPwmUp CCM_OPTIONAL;
|
||||
static SimplePwm etbPwmUp("etbUp") CCM_OPTIONAL;
|
||||
static float valueOverride = NAN;
|
||||
/*
|
||||
static SimplePwm etbPwmDown CCM_OPTIONAL;
|
||||
static SimplePwm etbPwmDown("etbDown") CCM_OPTIONAL;
|
||||
static OutputPin outputDirectionOpen CCM_OPTIONAL;
|
||||
*/
|
||||
static OutputPin outputDirectionClose CCM_OPTIONAL;
|
||||
|
@ -282,6 +282,7 @@ void startETBPins(void) {
|
|||
|
||||
// this line used for PWM
|
||||
startSimplePwmExt(&etbPwmUp, "etb1",
|
||||
&engine->executor,
|
||||
boardConfiguration->etbControlPin1,
|
||||
&enginePins.etbOutput1,
|
||||
freq,
|
||||
|
|
|
@ -764,7 +764,7 @@ void initEngineContoller(Logging *sharedLogger DECLARE_ENGINE_PARAMETER_SUFFIX)
|
|||
#endif /* EFI_PROD_CODE */
|
||||
}
|
||||
|
||||
static char UNUSED_RAM_SIZE[10500];
|
||||
static char UNUSED_RAM_SIZE[10400];
|
||||
|
||||
static char UNUSED_CCM_SIZE[7100] CCM_OPTIONAL;
|
||||
|
||||
|
@ -781,5 +781,5 @@ int getRusEfiVersion(void) {
|
|||
if (initBootloader() != 0)
|
||||
return 123;
|
||||
#endif /* EFI_BOOTLOADER_INCLUDE_CODE */
|
||||
return 20190105;
|
||||
return 20190109;
|
||||
}
|
||||
|
|
|
@ -57,7 +57,7 @@ static Pid idlePid(&engineConfiguration->idleRpmPid);
|
|||
#endif /* EFI_IDLE_INCREMENTAL_PID_CIC */
|
||||
|
||||
// todo: extract interface for idle valve hardware, with solenoid and stepper implementations?
|
||||
static SimplePwm idleSolenoid;
|
||||
static SimplePwm idleSolenoid("idle");
|
||||
|
||||
static StepperMotor iacMotor;
|
||||
|
||||
|
@ -465,7 +465,9 @@ static void initIdleHardware() {
|
|||
/**
|
||||
* Start PWM for idleValvePin
|
||||
*/
|
||||
startSimplePwmExt(&idleSolenoid, "Idle Valve", boardConfiguration->idle.solenoidPin, &enginePins.idleSolenoidPin,
|
||||
startSimplePwmExt(&idleSolenoid, "Idle Valve",
|
||||
&engine->executor,
|
||||
boardConfiguration->idle.solenoidPin, &enginePins.idleSolenoidPin,
|
||||
boardConfiguration->idle.solenoidFrequency, boardConfiguration->manIdlePosition / 100,
|
||||
applyIdleSolenoidPinState);
|
||||
idlePositionSensitivityThreshold = 0.0f;
|
||||
|
|
|
@ -10,6 +10,7 @@
|
|||
|
||||
#include "global.h"
|
||||
#include "pwm_generator_logic.h"
|
||||
#include "error_handling.h"
|
||||
|
||||
/**
|
||||
* We need to limit the number of iterations in order to avoid precision loss while calculating
|
||||
|
@ -29,6 +30,10 @@ SimplePwm::SimplePwm() {
|
|||
init(_switchTimes, sr);
|
||||
}
|
||||
|
||||
SimplePwm::SimplePwm(const char *name) : SimplePwm() {
|
||||
this->name = name;
|
||||
}
|
||||
|
||||
void PwmConfig::baseConstructor() {
|
||||
memset((void*)&scheduling, 0, sizeof(scheduling));
|
||||
memset((void*)&safe, 0, sizeof(safe));
|
||||
|
@ -39,6 +44,8 @@ void PwmConfig::baseConstructor() {
|
|||
phaseCount = 0;
|
||||
pwmCycleCallback = NULL;
|
||||
stateChangeCallback = NULL;
|
||||
executor = NULL;
|
||||
name = "[noname]";
|
||||
}
|
||||
|
||||
PwmConfig::PwmConfig() {
|
||||
|
@ -216,6 +223,11 @@ static void timerCallback(PwmConfig *state) {
|
|||
efiAssertVoid(CUSTOM_ERR_6581, state->dbgNestingLevel < 25, "PWM nesting issue");
|
||||
|
||||
efitimeus_t switchTimeUs = state->togglePwmState();
|
||||
// if (state->executor == NULL) {
|
||||
// firmwareError(CUSTOM_ERR_6695, "exec on %s", state->name);
|
||||
// return;
|
||||
// }
|
||||
|
||||
scheduleByTimestamp(&state->scheduling, switchTimeUs, (schfunc_t) timerCallback, state);
|
||||
state->dbgNestingLevel--;
|
||||
}
|
||||
|
@ -246,8 +258,9 @@ void copyPwmParameters(PwmConfig *state, int phaseCount, float *switchTimes, int
|
|||
* this method also starts the timer cycle
|
||||
* See also startSimplePwm
|
||||
*/
|
||||
void PwmConfig::weComplexInit(const char *msg, int phaseCount, float *switchTimes, int waveCount,
|
||||
void PwmConfig::weComplexInit(const char *msg, ExecutorInterface *executor, int phaseCount, float *switchTimes, int waveCount,
|
||||
pin_state_t **pinStates, pwm_cycle_callback *pwmCycleCallback, pwm_gen_callback *stateChangeCallback) {
|
||||
this->executor = executor;
|
||||
|
||||
efiAssertVoid(CUSTOM_ERR_6582, periodNt != 0, "period is not initialized");
|
||||
if (phaseCount == 0) {
|
||||
|
@ -275,7 +288,8 @@ void PwmConfig::weComplexInit(const char *msg, int phaseCount, float *switchTime
|
|||
timerCallback(this);
|
||||
}
|
||||
|
||||
void startSimplePwm(SimplePwm *state, const char *msg, OutputPin *output, float frequency, float dutyCycle, pwm_gen_callback *stateChangeCallback) {
|
||||
void startSimplePwm(SimplePwm *state, const char *msg, ExecutorInterface *executor,
|
||||
OutputPin *output, float frequency, float dutyCycle, pwm_gen_callback *stateChangeCallback) {
|
||||
efiAssertVoid(CUSTOM_ERR_6692, state != NULL, "state");
|
||||
efiAssertVoid(CUSTOM_ERR_6665, dutyCycle >= 0 && dutyCycle <= 1, "dutyCycle");
|
||||
if (frequency < 1) {
|
||||
|
@ -292,15 +306,17 @@ void startSimplePwm(SimplePwm *state, const char *msg, OutputPin *output, float
|
|||
state->outputPins[0] = output;
|
||||
|
||||
state->setFrequency(frequency);
|
||||
state->weComplexInit(msg, 2, switchTimes, 1, pinStates, NULL, stateChangeCallback);
|
||||
state->weComplexInit(msg, executor, 2, switchTimes, 1, pinStates, NULL, stateChangeCallback);
|
||||
}
|
||||
|
||||
void startSimplePwmExt(SimplePwm *state, const char *msg, brain_pin_e brainPin, OutputPin *output, float frequency,
|
||||
void startSimplePwmExt(SimplePwm *state, const char *msg,
|
||||
ExecutorInterface *executor,
|
||||
brain_pin_e brainPin, OutputPin *output, float frequency,
|
||||
float dutyCycle, pwm_gen_callback *stateChangeCallback) {
|
||||
|
||||
output->initPin(msg, brainPin);
|
||||
|
||||
startSimplePwm(state, msg, output, frequency, dutyCycle, stateChangeCallback);
|
||||
startSimplePwm(state, msg, executor, output, frequency, dutyCycle, stateChangeCallback);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -54,10 +54,13 @@ public:
|
|||
void init(float *switchTimes, SingleWave *waves);
|
||||
|
||||
void weComplexInit(const char *msg,
|
||||
ExecutorInterface *executor,
|
||||
int phaseCount, float *swithcTimes, int waveCount, pin_state_t **pinStates,
|
||||
pwm_cycle_callback *pwmCycleCallback,
|
||||
pwm_gen_callback *callback);
|
||||
|
||||
ExecutorInterface *executor;
|
||||
|
||||
/**
|
||||
* We need to handle zero duty cycle and 100% duty cycle in a special way
|
||||
*/
|
||||
|
@ -69,7 +72,7 @@ public:
|
|||
void setFrequency(float frequency);
|
||||
|
||||
void handleCycleStart();
|
||||
|
||||
const char *name;
|
||||
|
||||
OutputPin *outputPins[PWM_PHASE_MAX_WAVE_PER_PWM];
|
||||
MultiWave multiWave;
|
||||
|
@ -106,6 +109,7 @@ private:
|
|||
class SimplePwm : public PwmConfig {
|
||||
public:
|
||||
SimplePwm();
|
||||
SimplePwm(const char *name);
|
||||
void setSimplePwmDutyCycle(float dutyCycle);
|
||||
pin_state_t pinStates[2];
|
||||
SingleWave sr[1];
|
||||
|
@ -119,7 +123,9 @@ private:
|
|||
*
|
||||
* This method should be called after scheduling layer is started by initSignalExecutor()
|
||||
*/
|
||||
void startSimplePwm(SimplePwm *state, const char *msg, OutputPin *output,
|
||||
void startSimplePwm(SimplePwm *state, const char *msg,
|
||||
ExecutorInterface *executor,
|
||||
OutputPin *output,
|
||||
float dutyCycle, float frequency, pwm_gen_callback *stateChangeCallback);
|
||||
|
||||
/**
|
||||
|
@ -127,7 +133,10 @@ void startSimplePwm(SimplePwm *state, const char *msg, OutputPin *output,
|
|||
*
|
||||
* This method should be called after scheduling layer is started by initSignalExecutor()
|
||||
*/
|
||||
void startSimplePwmExt(SimplePwm *state, const char *msg, brain_pin_e brainPin, OutputPin *output,
|
||||
void startSimplePwmExt(SimplePwm *state,
|
||||
const char *msg,
|
||||
ExecutorInterface *executor,
|
||||
brain_pin_e brainPin, OutputPin *output,
|
||||
float frequency, float dutyCycle, pwm_gen_callback *stateChangeCallback);
|
||||
|
||||
void copyPwmParameters(PwmConfig *state, int phaseCount, float *switchTimes,
|
||||
|
|
|
@ -160,7 +160,7 @@ static void resumeStimulator() {
|
|||
stopEmulationAtIndex = DO_NOT_STOP;
|
||||
}
|
||||
|
||||
void initTriggerEmulatorLogic(Logging *sharedLogger) {
|
||||
void initTriggerEmulatorLogic(Logging *sharedLogger DECLARE_ENGINE_PARAMETER_SUFFIX) {
|
||||
logger = sharedLogger;
|
||||
|
||||
TriggerShape *s = &engine->triggerCentral.triggerShape;
|
||||
|
@ -169,7 +169,9 @@ void initTriggerEmulatorLogic(Logging *sharedLogger) {
|
|||
s->wave.channels[0].pinStates,
|
||||
s->wave.channels[1].pinStates,
|
||||
s->wave.channels[2].pinStates };
|
||||
triggerSignal.weComplexInit("position sensor", s->getSize(), s->wave.switchTimes, PWM_PHASE_MAX_WAVE_PER_PWM,
|
||||
triggerSignal.weComplexInit("position sensor",
|
||||
&engine->executor,
|
||||
s->getSize(), s->wave.switchTimes, PWM_PHASE_MAX_WAVE_PER_PWM,
|
||||
pinStates, updateTriggerShapeIfNeeded, emulatorApplyPinState);
|
||||
|
||||
addConsoleActionI("rpm", setTriggerEmulatorRPM);
|
||||
|
|
|
@ -21,6 +21,6 @@ public:
|
|||
void handleEmulatorCallback(PwmConfig *state, int stateIndex);
|
||||
};
|
||||
|
||||
void initTriggerEmulatorLogic(Logging *sharedLogger);
|
||||
void initTriggerEmulatorLogic(Logging *sharedLogger DECLARE_ENGINE_PARAMETER_SUFFIX);
|
||||
|
||||
#endif /* TRIGGER_EMULATOR_ALGO_H_ */
|
||||
|
|
|
@ -36,7 +36,7 @@ struct CJ125_state {
|
|||
efitick_t prevNt;
|
||||
};
|
||||
|
||||
static SimplePwm wboHeaterControl;
|
||||
static SimplePwm wboHeaterControl("wbo");
|
||||
static OutputPin wboHeaterPin;
|
||||
static OutputPin cj125Cs;
|
||||
static Logging *logger;
|
||||
|
@ -398,7 +398,9 @@ static void cjStartHeaterControl(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
|
|||
if (boardConfiguration->wboHeaterPin != GPIO_UNASSIGNED) {
|
||||
scheduleMsg(logger, "cj125: Starting heater control");
|
||||
// todo: use custom pin state method, turn pin off while not running
|
||||
startSimplePwmExt(&wboHeaterControl, "wboHeaterPin", boardConfiguration->wboHeaterPin,
|
||||
startSimplePwmExt(&wboHeaterControl, "wboHeaterPin",
|
||||
&engine->executor,
|
||||
boardConfiguration->wboHeaterPin,
|
||||
&wboHeaterPin, CJ125_HEATER_PWM_FREQ, 0.0f, applyPinState);
|
||||
cjSetIdleHeater(PASS_ENGINE_PARAMETER_SIGNATURE);
|
||||
}
|
||||
|
|
|
@ -45,11 +45,13 @@ static void test100dutyCycle() {
|
|||
print("*************************************** test100dutyCycle\r\n");
|
||||
|
||||
expectedTimeOfNextEvent = timeNowUs = 0;
|
||||
SimplePwm pwm;
|
||||
TestExecutor executor;
|
||||
SimplePwm pwm("test PWM1");
|
||||
OutputPin pin;
|
||||
schedulingQueue.clear();
|
||||
|
||||
startSimplePwm(&pwm, "unit_test",
|
||||
&executor,
|
||||
&pin,
|
||||
1000 /* frequency */,
|
||||
1.0 /* duty cycle */,
|
||||
|
@ -71,11 +73,13 @@ static void testSwitchToNanPeriod() {
|
|||
print("*************************************** testSwitchToNanPeriod\r\n");
|
||||
|
||||
expectedTimeOfNextEvent = timeNowUs = 0;
|
||||
SimplePwm pwm;
|
||||
TestExecutor executor;
|
||||
SimplePwm pwm("test PWM1");
|
||||
OutputPin pin;
|
||||
schedulingQueue.clear();
|
||||
|
||||
startSimplePwm(&pwm, "unit_test",
|
||||
&executor,
|
||||
&pin,
|
||||
1000 /* frequency */,
|
||||
0.60 /* duty cycle */,
|
||||
|
@ -108,11 +112,14 @@ void testPwmGenerator() {
|
|||
print("*************************************** testPwmGenerator\r\n");
|
||||
|
||||
expectedTimeOfNextEvent = timeNowUs = 0;
|
||||
SimplePwm pwm;
|
||||
TestExecutor executor;
|
||||
SimplePwm pwm("test PWM3");
|
||||
OutputPin pin;
|
||||
schedulingQueue.clear();
|
||||
|
||||
startSimplePwm(&pwm, "unit_test",
|
||||
startSimplePwm(&pwm,
|
||||
"unit_test",
|
||||
&executor,
|
||||
&pin,
|
||||
1000 /* frequency */,
|
||||
0.80 /* duty cycle */,
|
||||
|
|
Loading…
Reference in New Issue