auto-sync
This commit is contained in:
parent
8e18c457c7
commit
459bf8ba0e
|
@ -23,15 +23,15 @@ static void startPwmTest(int freq) {
|
|||
scheduleMsg(&logger, "running pwm test @%d", freq);
|
||||
|
||||
// PD13, GPIO_UNASSIGNED because pin is initialized elsewhere already
|
||||
startSimplePwm(&pwmTest[0], "tester", LED_WARNING, 10, 0.5f);
|
||||
startSimplePwm(&pwmTest[0], "tester", LED_WARNING, 10, 0.5f, applyPinState);
|
||||
// currently this is PB9 by default - see boardConfiguration->injectionPins
|
||||
startSimplePwm(&pwmTest[1], "tester", INJECTOR_1_OUTPUT, freq / 1.3333333333, 0.5f);
|
||||
startSimplePwm(&pwmTest[1], "tester", INJECTOR_1_OUTPUT, freq / 1.3333333333, 0.5f, applyPinState);
|
||||
// currently this is PB8 by default
|
||||
startSimplePwm(&pwmTest[2], "tester", INJECTOR_2_OUTPUT, freq / 1000, 0.5f);
|
||||
startSimplePwm(&pwmTest[2], "tester", INJECTOR_2_OUTPUT, freq / 1000, 0.5f, applyPinState);
|
||||
// currently this is PE3 by default
|
||||
startSimplePwm(&pwmTest[3], "tester", INJECTOR_3_OUTPUT, freq, 0.5);
|
||||
startSimplePwm(&pwmTest[3], "tester", INJECTOR_3_OUTPUT, freq, 0.5, applyPinState);
|
||||
// currently this is PE5 by default
|
||||
startSimplePwm(&pwmTest[4], "tester", INJECTOR_4_OUTPUT, freq / 33.33333333333, 0.5);
|
||||
startSimplePwm(&pwmTest[4], "tester", INJECTOR_4_OUTPUT, freq / 33.33333333333, 0.5, applyPinState);
|
||||
}
|
||||
|
||||
void initPwmTester(void) {
|
||||
|
|
|
@ -34,16 +34,14 @@
|
|||
|
||||
static THD_WORKING_AREA(ivThreadStack, UTILITY_THREAD_STACK_SIZE);
|
||||
|
||||
extern board_configuration_s *boardConfiguration;
|
||||
extern engine_configuration_s *engineConfiguration;
|
||||
|
||||
/**
|
||||
* here we keep the value we got from IDLE SWITCH input
|
||||
*/
|
||||
static volatile int idleSwitchState;
|
||||
|
||||
static Logging logger;
|
||||
EXTERN_ENGINE;
|
||||
EXTERN_ENGINE
|
||||
;
|
||||
|
||||
static SimplePwm idleValvePwm;
|
||||
|
||||
|
@ -62,7 +60,7 @@ void idleDebug(const char *msg, int value) {
|
|||
}
|
||||
|
||||
static void showIdleInfo(void) {
|
||||
scheduleMsg(&logger, "idleMode=%s", getIdle_mode_e(engineConfiguration->idleMode));
|
||||
scheduleMsg(&logger, "idleMode=%s duty=%f", getIdle_mode_e(engineConfiguration->idleMode), boardConfiguration->idleSolenoidPwm);
|
||||
scheduleMsg(&logger, "idle valve freq=%d on %s", boardConfiguration->idleSolenoidFrequency,
|
||||
hwPortname(boardConfiguration->idleValvePin));
|
||||
}
|
||||
|
@ -77,16 +75,18 @@ static void setIdleValvePwm(int value) {
|
|||
if (value < 1 || value > 999)
|
||||
return;
|
||||
scheduleMsg(&logger, "setting idle valve PWM %d", value);
|
||||
float f = 0.001 * value;
|
||||
boardConfiguration->idleSolenoidPwm = f;
|
||||
showIdleInfo();
|
||||
/**
|
||||
* currently idle level is an integer per mil (0-1000 range), and PWM takes a float in the 0..1 range
|
||||
* todo: unify?
|
||||
*/
|
||||
idleValvePwm.setSimplePwmDutyCycle(0.001 * value);
|
||||
idleValvePwm.setSimplePwmDutyCycle(f);
|
||||
}
|
||||
|
||||
static msg_t ivThread(int param) {
|
||||
(void)param;
|
||||
(void) param;
|
||||
chRegSetThreadName("IdleValve");
|
||||
|
||||
int currentIdleValve = -1;
|
||||
|
@ -94,7 +94,8 @@ static msg_t ivThread(int param) {
|
|||
chThdSleepMilliseconds(boardConfiguration->idleThreadPeriod);
|
||||
|
||||
// this value is not used yet
|
||||
idleSwitchState = palReadPad(getHwPort(boardConfiguration->idleSwitchPin), getHwPin(boardConfiguration->idleSwitchPin));
|
||||
idleSwitchState = palReadPad(getHwPort(boardConfiguration->idleSwitchPin),
|
||||
getHwPin(boardConfiguration->idleSwitchPin));
|
||||
|
||||
if (engineConfiguration->idleMode != IM_AUTO)
|
||||
continue;
|
||||
|
@ -119,22 +120,28 @@ static void setIdleRpmAction(int value) {
|
|||
scheduleMsg(&logger, "target idle RPM %d", value);
|
||||
}
|
||||
|
||||
static void applyIdleSolenoidPinState(PwmConfig *state, int stateIndex) {
|
||||
efiAssertVoid(stateIndex < PWM_PHASE_MAX_COUNT, "invalid stateIndex");
|
||||
efiAssertVoid(state->multiWave.waveCount == 1, "invalid idle waveCount");
|
||||
io_pin_e ioPin = state->outputPins[0];
|
||||
int value = state->multiWave.waves[0].pinStates[stateIndex];
|
||||
if (!value || engine->rpmCalculator.rpmValue != 0)
|
||||
setOutputPinValue(ioPin, value);
|
||||
}
|
||||
|
||||
void startIdleThread(Engine *engine) {
|
||||
initLogging(&logger, "Idle Valve Control");
|
||||
|
||||
/**
|
||||
* Start PWM for IDLE_VALVE logical / idleValvePin physical
|
||||
*/
|
||||
startSimplePwmExt(&idleValvePwm, "Idle Valve",
|
||||
boardConfiguration->idleValvePin,
|
||||
IDLE_VALVE,
|
||||
boardConfiguration->idleSolenoidFrequency,
|
||||
boardConfiguration->idleSolenoidPwm);
|
||||
startSimplePwmExt(&idleValvePwm, "Idle Valve", boardConfiguration->idleValvePin, IDLE_VALVE,
|
||||
boardConfiguration->idleSolenoidFrequency, boardConfiguration->idleSolenoidPwm, applyIdleSolenoidPinState);
|
||||
|
||||
idleInit(&idle);
|
||||
scheduleMsg(&logger, "initial idle %d", idle.value);
|
||||
|
||||
chThdCreateStatic(ivThreadStack, sizeof(ivThreadStack), NORMALPRIO, (tfunc_t)ivThread, NULL);
|
||||
chThdCreateStatic(ivThreadStack, sizeof(ivThreadStack), NORMALPRIO, (tfunc_t) ivThread, NULL);
|
||||
|
||||
// this is idle switch INPUT - sometimes there is a switch on the throttle pedal
|
||||
// this switch is not used yet
|
||||
|
@ -143,5 +150,5 @@ void startIdleThread(Engine *engine) {
|
|||
addConsoleAction("idleinfo", showIdleInfo);
|
||||
addConsoleActionI("set_idle_rpm", setIdleRpmAction);
|
||||
addConsoleActionI("set_idle_pwm", setIdleValvePwm);
|
||||
addConsoleActionIP("set_idle_enabled", (VoidIntVoidPtr)setIdleControlEnabled, engine);
|
||||
addConsoleActionIP("set_idle_enabled", (VoidIntVoidPtr) setIdleControlEnabled, engine);
|
||||
}
|
||||
|
|
|
@ -34,7 +34,7 @@ void applyPinState(PwmConfig *state, int stateIndex) {
|
|||
}
|
||||
}
|
||||
|
||||
void startSimplePwm(PwmConfig *state, const char *msg, io_pin_e ioPin, float frequency, float dutyCycle) {
|
||||
void startSimplePwm(PwmConfig *state, const char *msg, io_pin_e ioPin, float frequency, float dutyCycle, pwm_gen_callback *stateChangeCallback) {
|
||||
efiAssertVoid(dutyCycle >= 0 && dutyCycle <= 1, "dutyCycle");
|
||||
|
||||
float switchTimes[] = { dutyCycle, 1 };
|
||||
|
@ -45,17 +45,17 @@ void startSimplePwm(PwmConfig *state, const char *msg, io_pin_e ioPin, float fre
|
|||
state->outputPins[0] = ioPin;
|
||||
|
||||
state->periodNt = US2NT(frequency2periodUs(frequency));
|
||||
weComplexInit(msg, state, 2, switchTimes, 1, pinStates, NULL, applyPinState);
|
||||
weComplexInit(msg, state, 2, switchTimes, 1, pinStates, NULL, stateChangeCallback);
|
||||
}
|
||||
|
||||
void startSimplePwmExt(PwmConfig *state, const char *msg, brain_pin_e brainPin, io_pin_e ioPin, float frequency,
|
||||
float dutyCycle) {
|
||||
float dutyCycle, pwm_gen_callback *stateChangeCallback) {
|
||||
|
||||
GPIO_TypeDef * port = getHwPort(brainPin);
|
||||
int pin = getHwPin(brainPin);
|
||||
outputPinRegister(msg, ioPin, port, pin);
|
||||
|
||||
startSimplePwm(state, msg, ioPin, frequency, dutyCycle);
|
||||
startSimplePwm(state, msg, ioPin, frequency, dutyCycle, stateChangeCallback);
|
||||
}
|
||||
|
||||
void initPwmGenerator(void) {
|
||||
|
|
|
@ -16,19 +16,20 @@
|
|||
#include "gpio_helper.h"
|
||||
|
||||
void startSimplePwm(PwmConfig *state, const char *msg, io_pin_e ioPin,
|
||||
float dutyCycle, float frequency);
|
||||
float dutyCycle, float frequency, pwm_gen_callback *stateChangeCallback);
|
||||
void applyPinState(PwmConfig *state, int stateIndex);
|
||||
|
||||
void initPwmGenerator(void);
|
||||
|
||||
void startSimplePwmExt(PwmConfig *state, const char *msg, brain_pin_e brainPin, io_pin_e ioPin,
|
||||
float frequency, float dutyCycle, pwm_gen_callback *stateChangeCallback);
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif /* __cplusplus */
|
||||
|
||||
void startSimplePwmExt(PwmConfig *state, const char *msg, brain_pin_e brainPin, io_pin_e ioPin,
|
||||
float frequency, float dutyCycle);
|
||||
|
||||
void initPwmGenerator(void);
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
|
|
Loading…
Reference in New Issue