diff --git a/firmware/config/engines/custom_engine.cpp b/firmware/config/engines/custom_engine.cpp index f59b2a72e8..10848e54ba 100644 --- a/firmware/config/engines/custom_engine.cpp +++ b/firmware/config/engines/custom_engine.cpp @@ -62,6 +62,8 @@ void setCustomEngineConfiguration(engine_configuration_s *engineConfiguration) { * We want to initialize all outputs for test */ engineConfiguration->cylindersCount = 10; + + engineConfiguration->displayMode = DM_NONE; #else boardConfiguration->injectionPins[4] = GPIO_UNASSIGNED; boardConfiguration->injectionPins[5] = GPIO_UNASSIGNED; diff --git a/firmware/config/stm32f4ems/efifeatures.h b/firmware/config/stm32f4ems/efifeatures.h index 2a52d04a4a..7d513df778 100644 --- a/firmware/config/stm32f4ems/efifeatures.h +++ b/firmware/config/stm32f4ems/efifeatures.h @@ -14,6 +14,8 @@ #define EFI_FSIO TRUE +#define EFI_PWM_TESTER FALSE + #define EFI_USE_CCM TRUE #ifndef EFI_ENABLE_ASSERTS diff --git a/firmware/controllers/PwmTester.cpp b/firmware/controllers/PwmTester.cpp index 0b09907c14..1ebb018e89 100644 --- a/firmware/controllers/PwmTester.cpp +++ b/firmware/controllers/PwmTester.cpp @@ -13,37 +13,76 @@ #include "PwmTester.h" #include "EfiWave.h" #include "pwm_generator_logic.h" -#include "engine_configuration.h" +#include "engine.h" #include "pwm_generator.h" -static Logging logger; +static LoggingWithStorage logger; static SimplePwm pwmTest[5]; -extern board_configuration_s *boardConfiguration; - extern OutputPin warningPin; -extern OutputPin outputs[IO_PIN_COUNT]; +extern engine_pins_s enginePins; + +EXTERN_ENGINE; static void startPwmTest(int freq) { scheduleMsg(&logger, "running pwm test @%d", freq); - // PD13, GPIO_UNASSIGNED because pin is initialized elsewhere already + engine->isRunningPwmTest = true; + + // PD13 pin is initialized elsewhere already startSimplePwm(&pwmTest[0], "tester", &warningPin, 10, 0.5f, applyPinState); + /** + * See custom_engine.cpp for pinout + */ // currently this is PB9 by default - see boardConfiguration->injectionPins - startSimplePwm(&pwmTest[1], "tester", &outputs[(int)INJECTOR_1_OUTPUT], freq / 1.3333333333, 0.5f, applyPinState); + startSimplePwm(&pwmTest[1], "tester", &enginePins.injectors[0], freq / 1.3333333333, 0.5f, applyPinState); + // currently this is PE2 by default + startSimplePwm(&pwmTest[2], "tester", &enginePins.injectors[1], freq / 1000, 0.5f, applyPinState); // currently this is PB8 by default - startSimplePwm(&pwmTest[2], "tester", &outputs[(int)INJECTOR_2_OUTPUT], freq / 1000, 0.5f, applyPinState); - // currently this is PE3 by default - startSimplePwm(&pwmTest[3], "tester", &outputs[(int)INJECTOR_3_OUTPUT], freq, 0.5, applyPinState); - // currently this is PE5 by default - startSimplePwm(&pwmTest[4], "tester", &outputs[(int)INJECTOR_4_OUTPUT], freq / 33.33333333333, 0.5, applyPinState); + startSimplePwm(&pwmTest[3], "tester", &enginePins.injectors[2], freq, 0.5, applyPinState); + // currently this is PB7 by default + startSimplePwm(&pwmTest[4], "tester", &enginePins.injectors[3], freq / 33.33333333333, 0.5, applyPinState); + +} + +static scheduling_s ioTest; + +static OutputSignal outSignals[4]; + +static void testCallback(void *arg) { + + /** + * 0.1ms from now please squirt for 1.6ms + */ + scheduleOutput(&outSignals[0], 0.1, 1.6); + scheduleOutput(&outSignals[1], 0.1, 1.6); + scheduleOutput(&outSignals[2], 0.1, 1.6); + scheduleOutput(&outSignals[3], 0.1, 1.6); + + /** + * this would re-schedule another callback in 2ms from now + */ + scheduleTask("test", &ioTest, MS2US(2), testCallback, NULL); } void initPwmTester(void) { initLogging(&logger, "pwm test"); addConsoleActionI("pwmtest", startPwmTest); -// un-comment this to start pwm test on start up startPwmTest(1000); + startPwmTest(1000); + + /** + * injector channels #4-#8 are used for individual squirt test + */ + outSignals[0].output = &enginePins.injectors[4]; + outSignals[1].output = &enginePins.injectors[5]; + outSignals[2].output = &enginePins.injectors[6]; + outSignals[3].output = &enginePins.injectors[7]; + + /** + * this would schedule a callback in 2ms from now + */ + scheduleTask("test", &ioTest, MS2US(2), testCallback, NULL); } #endif diff --git a/firmware/controllers/algo/engine.cpp b/firmware/controllers/algo/engine.cpp index ae312249c5..b9c5354070 100644 --- a/firmware/controllers/algo/engine.cpp +++ b/firmware/controllers/algo/engine.cpp @@ -46,6 +46,7 @@ Engine::Engine() { isCylinderCleanupMode = false; engineCycleEventCount = 0; stopEngineRequestTimeNt = 0; + isRunningPwmTest = false; } void Engine::precalc(engine_configuration_s *engineConfiguration) { @@ -76,6 +77,8 @@ bool Engine::stopPins() { } void Engine::watchdog() { + if (isRunningPwmTest) + return; if (!isSpinning) { if (!isRunningBenchTest() && stopPins()) { firmwareError("Some pins were turned off by 2nd pass watchdog"); diff --git a/firmware/controllers/algo/engine.h b/firmware/controllers/algo/engine.h index 12e01aebe1..1c29f1f4f9 100644 --- a/firmware/controllers/algo/engine.h +++ b/firmware/controllers/algo/engine.h @@ -103,6 +103,8 @@ public: bool_t clutchUpState; bool_t clutchDownState; + bool_t isRunningPwmTest; + TriggerShape triggerShape; float angleExtra[IGNITION_PIN_COUNT]; diff --git a/firmware/controllers/system/scheduler.h b/firmware/controllers/system/scheduler.h index 4619b99db9..f886210937 100644 --- a/firmware/controllers/system/scheduler.h +++ b/firmware/controllers/system/scheduler.h @@ -24,16 +24,7 @@ struct scheduling_struct { const char *name; }; -#ifdef __cplusplus -extern "C" -{ -#endif /* __cplusplus */ - void scheduleTask(const char *prefix, scheduling_s *scheduling, int delayUs, schfunc_t callback, void *param); void scheduleTask2(const char *prefix, scheduling_s *scheduling, uint64_t time, schfunc_t callback, void *param); -#ifdef __cplusplus -} -#endif /* __cplusplus */ - #endif /* SCHEDULER_H_ */