steps towards #975

This commit is contained in:
rusefi 2019-10-18 19:39:06 -04:00
parent 0e01355c15
commit d9401fbdbc
4 changed files with 21 additions and 7 deletions

View File

@ -2,11 +2,10 @@
* @file electronic_throttle.h
*
* @date Dec 7, 2013
* @author Andrey Belomutskiy, (c) 2012-2017
* @author Andrey Belomutskiy, (c) 2012-2019
*/
#ifndef ELECTRONIC_THROTTLE_H_
#define ELECTRONIC_THROTTLE_H_
#pragma once
// https://en.wikipedia.org/wiki/Nyquist%E2%80%93Shannon_sampling_theorem
#define DEFAULT_ETB_LOOP_FREQUENCY 200
@ -37,5 +36,3 @@ void stopETBPins(void);
void startETBPins(DECLARE_ENGINE_PARAMETER_SIGNATURE);
void onConfigurationChangeElectronicThrottleCallback(engine_configuration_s *previousConfiguration);
void unregisterEtbPins();
#endif /* ELECTRONIC_THROTTLE_H_ */

View File

@ -62,6 +62,10 @@ void PwmConfig::init(float *st, SingleWave *waves) {
* See also setFrequency
*/
void SimplePwm::setSimplePwmDutyCycle(float dutyCycle) {
if (isStopRequested) {
// we are here in order to not change pin once PWM stop was requested
return;
}
if (cisnan(dutyCycle)) {
warning(CUSTOM_DUTY_INVALID, "spwd:dutyCycle %.2f", dutyCycle);
return;
@ -128,6 +132,10 @@ void PwmConfig::setFrequency(float frequency) {
periodNt = US2NT(frequency2periodUs(frequency));
}
void PwmConfig::stop() {
isStopRequested = true;
}
void PwmConfig::handleCycleStart() {
efiAssertVoid(CUSTOM_ERR_6697, safe.phaseIndex == 0, "handleCycleStart");
if (pwmCycleCallback != NULL) {
@ -151,6 +159,9 @@ void PwmConfig::handleCycleStart() {
* @return Next time for signal toggle
*/
efitimeus_t PwmConfig::togglePwmState() {
if (isStopRequested) {
return 0;
}
#if DEBUG_PWM
scheduleMsg(&logger, "togglePwmState phaseIndex=%d iteration=%d", safe.phaseIndex, safe.iteration);
scheduleMsg(&logger, "period=%.2f safe.period=%.2f", period, safe.periodNt);
@ -229,6 +240,10 @@ static void timerCallback(PwmConfig *state) {
efiAssertVoid(CUSTOM_ERR_6581, state->dbgNestingLevel < 25, "PWM nesting issue");
efitimeus_t switchTimeUs = state->togglePwmState();
if (switchTimeUs == 0) {
// we are here when PWM gets stopped
return;
}
if (state->executor == NULL) {
firmwareError(CUSTOM_ERR_6695, "exec on %s", state->name);
return;
@ -271,6 +286,7 @@ void PwmConfig::weComplexInit(const char *msg, ExecutorInterface *executor,
pin_state_t *const*pinStates, pwm_cycle_callback *pwmCycleCallback, pwm_gen_callback *stateChangeCallback) {
UNUSED(msg);
this->executor = executor;
isStopRequested = false;
efiAssertVoid(CUSTOM_ERR_6582, periodNt != 0, "period is not initialized");
if (phaseCount == 0) {

View File

@ -70,6 +70,7 @@ public:
* We need to handle zero duty cycle and 100% duty cycle in a special way
*/
pwm_mode_e mode;
bool isStopRequested = false;
/**
* @param use NAN frequency to pause PWM
@ -83,6 +84,7 @@ public:
OutputPin *outputPins[PWM_PHASE_MAX_WAVE_PER_PWM];
MultiWave multiWave;
efitimeus_t togglePwmState();
void stop();
int dbgNestingLevel;

View File

@ -255,8 +255,7 @@ void turnOnTriggerInputPins(Logging *sharedLogger) {
void stopTriggerInputPins(void) {
#if EFI_PROD_CODE
for (int i = 0; i < TRIGGER_SUPPORTED_CHANNELS; i++) {
if (CONFIGB(triggerInputPins)[i]
!= activeConfiguration.bc.triggerInputPins[i]) {
if (isConfigurationChanged(bc.triggerInputPins[i])) {
turnOffTriggerInputPin(activeConfiguration.bc.triggerInputPins[i]);
}
}