diff --git a/speeduino/globals.cpp b/speeduino/globals.cpp index 5b4e1d60e6..34837048a6 100644 --- a/speeduino/globals.cpp +++ b/speeduino/globals.cpp @@ -201,11 +201,11 @@ bool pinIsOutput(byte pin) bool isIdlePWM = (configPage6.iacAlgorithm > 0) && ((configPage6.iacAlgorithm <= 3) || (configPage6.iacAlgorithm == 6)); bool isIdleSteper = (configPage6.iacAlgorithm > 3) && (configPage6.iacAlgorithm != 6); //Injector? - for (uint8_t index=0U; index<_countof(injectorPins); ++index) { + for (uint8_t index=0U; index<_countof(pinInjectors); ++index) { used = used || (pin == pinInjectors[index]); } //Ignition? - for (uint8_t index=0U; index<_countof(ignitionPins); ++index) { + for (uint8_t index=0U; index<_countof(pinCoils); ++index) { used = used || (pin == pinCoils[index]); } diff --git a/speeduino/init.cpp b/speeduino/init.cpp index acd1b54211..d744b6bcd0 100644 --- a/speeduino/init.cpp +++ b/speeduino/init.cpp @@ -292,8 +292,8 @@ void initialiseAll(void) currentLoopTime = micros_safe(); mainLoopCount = 0; - initialiseFuelSchedulers(pinInjectors); - initialiseIgnitionSchedulers(pinCoils); + initialiseFuelSchedulers(); + initialiseIgnitionSchedulers(); //Begin priming the fuel pump. This is turned off in the low resolution, 1s interrupt in timers.ino //First check that the priming time is not 0 @@ -318,9 +318,11 @@ void initialiseAll(void) } // This saves a couple of bytes of RAM versus using static constexpr statements -static inline void useDirectChannelControl(void) { +static inline void useDirectChannelControl(const uint8_t injPins[], const uint8_t ignPins[]) { setInjectorControlActions({ openInjector_DIRECT, closeInjector_DIRECT, toggleInjector_DIRECT }); setIgnitionControlActions({ coilStartCharging_DIRECT, coilStopCharging_DIRECT }); + initialiseInjectorPins_DIRECT(injPins); + initialiseIgnitionPins_DIRECT(ignPins); } #ifndef SMALL_FLASH_MODE //No support for bluepill here anyway @@ -354,7 +356,7 @@ static void setPinMappingsV2_0Shield(void) { pinFlex = 2; // Flex sensor (Must be external interrupt enabled) pinResetControl = 43; //Reset control output - useDirectChannelControl(); + useDirectChannelControl(pinInjectors, pinCoils); } static void setPinMappingsV3_0Shield(void) { @@ -407,7 +409,7 @@ static void setPinMappingsV3_0Shield(void) { pinO2 = A22; #endif - useDirectChannelControl(); + useDirectChannelControl(pinInjectors, pinCoils); } static void setPinMappingsMx5Nb2Shield(void) { @@ -462,7 +464,7 @@ static void setPinMappingsMx5Nb2Shield(void) { pinTachOut = 28; //Done #endif - useDirectChannelControl(); + useDirectChannelControl(pinInjectors, pinCoils); } static void setPinMappingsMx5Na18Shield(void) { @@ -514,7 +516,7 @@ static void setPinMappingsMx5Na18Shield(void) { pinTachOut = 28; //Done #endif - useDirectChannelControl(); + useDirectChannelControl(pinInjectors, pinCoils); } static void setPinMappingsMx5Na16Shield(void) { @@ -568,7 +570,7 @@ static void setPinMappingsMx5Na16Shield(void) { pinTachOut = 28; //Done #endif - useDirectChannelControl(); + useDirectChannelControl(pinInjectors, pinCoils); } static void setPinMappingsTurtanasPcb(void) { @@ -604,7 +606,7 @@ static void setPinMappingsTurtanasPcb(void) { pinFlex = 2; // Flex sensor (Must be external interrupt enabled) pinResetControl = 26; //Reset control - useDirectChannelControl(); + useDirectChannelControl(pinInjectors, pinCoils); } static void setPinMappingsDazV6Shield(void) { @@ -647,7 +649,7 @@ static void setPinMappingsDazV6Shield(void) { #endif pinFan = 47; //Pin for the fan output - useDirectChannelControl(); + useDirectChannelControl(pinInjectors, pinCoils); } static void setPinMappingsNO2CShield(void) { @@ -694,7 +696,7 @@ static void setPinMappingsNO2CShield(void) { #endif pinResetControl = 26; //Reset control output - useDirectChannelControl(); + useDirectChannelControl(pinInjectors, pinCoils); } static void setPinMappingsUA4CShield(void) { @@ -742,7 +744,7 @@ static void setPinMappingsUA4CShield(void) { pinFan = 24; //Pin for the fan output pinResetControl = 46; //Reset control output PLACEHOLDER value for now - useDirectChannelControl(); + useDirectChannelControl(pinInjectors, pinCoils); } static void setPinMappingsBlitzboxBL49sp(void) { @@ -782,7 +784,7 @@ static void setPinMappingsBlitzboxBL49sp(void) { pinFan = 12; //Pin for the fan output pinResetControl = 46; //Reset control output PLACEHOLDER value for now - useDirectChannelControl(); + useDirectChannelControl(pinInjectors, pinCoils); } static void setPinMappingsDiyEfiCore4Shield(void) { @@ -831,7 +833,7 @@ static void setPinMappingsDiyEfiCore4Shield(void) { pinResetControl = 46; //Reset control output PLACEHOLDER value for now #endif // CORE_AVR - useDirectChannelControl(); + useDirectChannelControl(pinInjectors, pinCoils); } static void setPinMappingsPlazomatV0_1Shield(void) { @@ -869,7 +871,7 @@ static void setPinMappingsPlazomatV0_1Shield(void) { pinResetControl = 26; //Reset control output #endif // CORE_AVR - useDirectChannelControl(); + useDirectChannelControl(pinInjectors, pinCoils); } #endif // SMALL_FLASH_MODE @@ -1091,7 +1093,7 @@ static void setPinMappingsV4_0Shield(void) { pinTrigger2 = PC15; //The Cam Sensor pin #endif - useDirectChannelControl(); + useDirectChannelControl(pinInjectors, pinCoils); } static void setPinMappingBmwPnP(void) { @@ -1177,7 +1179,7 @@ static void setPinMappingBmwPnP(void) { pinCTPS = PA6; //(placeholder) #endif - useDirectChannelControl(); + useDirectChannelControl(pinInjectors, pinCoils); } static void setPinMappingsTeensyRevA(void) { @@ -1215,7 +1217,7 @@ static void setPinMappingsTeensyRevA(void) { #endif #endif - useDirectChannelControl(); + useDirectChannelControl(pinInjectors, pinCoils); } static void setPinMappingsTeensyRevB(void) { @@ -1253,7 +1255,7 @@ static void setPinMappingsTeensyRevB(void) { #endif #endif - useDirectChannelControl(); + useDirectChannelControl(pinInjectors, pinCoils); } @@ -1292,7 +1294,7 @@ static void setPinMappingsJuiceBox(void) { #endif #endif - useDirectChannelControl(); + useDirectChannelControl(pinInjectors, pinCoils); } static void setPinMappingsDropBear(void) { @@ -1427,7 +1429,7 @@ static void setPinMappingBearCub(void) { pinResetControl = 46; //Reset control output PLACEHOLDER value for now #endif - useDirectChannelControl(); + useDirectChannelControl(pinInjectors, pinCoils); } static void setPinMappingsSTM32(void) { @@ -1609,7 +1611,7 @@ static void setPinMappingsSTM32(void) { pinTrigger2 = PA13; //The Cam Sensor pin #endif - useDirectChannelControl(); + useDirectChannelControl(pinInjectors, pinCoils); } /** Set board / microcontroller specific pin mappings / assignments. diff --git a/speeduino/scheduledIO.cpp b/speeduino/scheduledIO.cpp index 617746eaaf..725c6df61d 100644 --- a/speeduino/scheduledIO.cpp +++ b/speeduino/scheduledIO.cpp @@ -1,5 +1,5 @@ #include "scheduledIO.h" -#include "scheduledIO_direct.h" + /** @file * Injector and Coil (toggle/open/close) control (under various situations, eg with particular cylinder count, rotary engine type or wasted spark ign, etc.). * Also accounts for presence of MC33810 injector/ignition (dwell, etc.) control circuit. @@ -7,20 +7,6 @@ * form where they are called (by scheduler.ino). */ -static inline void registerPins(ioPort toRegister[], uint8_t toRegisterSize, const uint8_t pins[]) { - for (uint8_t index=0U; index -#include #include +#include "globals.h" +#include "speeduino.h" #include "test_staging.h" #include "../test_utils.h" #include "scheduler.h" @@ -21,8 +21,6 @@ void test_Staging_setCommon() { // initialiseAll(); - maxInjPrimaryOutputs = 2; - maxInjSecondaryOutputs = 2; configPage2.nCylinders = 4; currentStatus.RPM = 3000; currentStatus.fuelLoad = 50; @@ -48,7 +46,8 @@ void test_Staging_setCommon() staged_req_fuel_mult_sec = (100 * totalInjector) / configPage10.stagedInjSizeSec; } -extern void calculateStaging(uint16_t pwLimit, uint16_t pwPrimary); +extern pulseWidths computePulseWidths(uint16_t pwLimit, uint16_t pwPrimary); +extern void applyPWToSchedules(uint16_t primaryPW, uint16_t secondaryPW); void test_Staging_Off(void) { @@ -57,8 +56,8 @@ void test_Staging_Off(void) BIT_SET(currentStatus.status4, BIT_STATUS4_STAGING_ACTIVE); configPage10.stagingEnabled = false; - calculateStaging(9000U, 0U); //90% duty cycle at 6000rpm - TEST_ASSERT_BIT_LOW(BIT_STATUS4_STAGING_ACTIVE, currentStatus.status4); + auto pw = computePulseWidths(9000U, 0U); //90% duty cycle at 6000rpm + TEST_ASSERT_EQUAL(0U, pw.secondary); } void test_Staging_4cyl_Auto_Inactive(void) @@ -70,14 +69,15 @@ void test_Staging_4cyl_Auto_Inactive(void) configPage10.stagingEnabled = true; configPage10.stagingMode = STAGING_MODE_AUTO; - calculateStaging(9000U, 3000U); //90% duty cycle at 6000rpm + auto pw = computePulseWidths(9000U, 3000U); //90% duty cycle at 6000rpm + applyPWToSchedules(pw.primary, pw.secondary); //PW 1 and 2 should be normal, 3 and 4 should be 0 as that testPW is below the pwLimit //PW1/2 should be ((PW - openTime) * staged_req_fuel_mult_pri) + openTime = ((3000 - 1000) * 3.0) + 1000 = 7000 TEST_ASSERT_EQUAL(7000, fuelSchedules[0].pw); TEST_ASSERT_EQUAL(7000, fuelSchedules[1].pw); TEST_ASSERT_EQUAL(0, fuelSchedules[2].pw); TEST_ASSERT_EQUAL(0, fuelSchedules[3].pw); - TEST_ASSERT_BIT_LOW(BIT_STATUS4_STAGING_ACTIVE, currentStatus.status4); + TEST_ASSERT_EQUAL(0U, pw.secondary); } void test_Staging_4cyl_Table_Inactive(void) @@ -94,14 +94,15 @@ void test_Staging_4cyl_Table_Inactive(void) for(byte x=0; x<64; x++) { stagingTable.values.values[x] = 0; } - calculateStaging(9000U, 3000U); //90% duty cycle at 6000rpm + auto pw = computePulseWidths(9000U, 3000U); //90% duty cycle at 6000rpm + applyPWToSchedules(pw.primary, pw.secondary); //PW 1 and 2 should be normal, 3 and 4 should be 0 as that testPW is below the pwLimit //PW1/2 should be (PW - openTime) * staged_req_fuel_mult_pri = (3000 - 1000) * 3.0 = 6000 TEST_ASSERT_EQUAL(7000, fuelSchedules[0].pw); TEST_ASSERT_EQUAL(7000, fuelSchedules[1].pw); TEST_ASSERT_EQUAL(0, fuelSchedules[2].pw); TEST_ASSERT_EQUAL(0, fuelSchedules[3].pw); - TEST_ASSERT_BIT_LOW(BIT_STATUS4_STAGING_ACTIVE, currentStatus.status4); + TEST_ASSERT_EQUAL(0U, pw.secondary); } void test_Staging_4cyl_Auto_50pct(void) @@ -115,13 +116,14 @@ void test_Staging_4cyl_Auto_50pct(void) uint32_t pwLimit = 9000; //90% duty cycle at 6000rpm - calculateStaging(pwLimit, 9000U); //90% duty cycle at 6000rpm + auto pw = computePulseWidths(pwLimit, 9000U); //90% duty cycle at 6000rpm + applyPWToSchedules(pw.primary, pw.secondary); //PW 1 and 2 should be maxed out at the pwLimit, 3 and 4 should be based on their relative size TEST_ASSERT_EQUAL(pwLimit, fuelSchedules[0].pw); //PW1/2 run at maximum available limit TEST_ASSERT_EQUAL(pwLimit, fuelSchedules[1].pw); TEST_ASSERT_EQUAL(9000, fuelSchedules[2].pw); TEST_ASSERT_EQUAL(9000, fuelSchedules[3].pw); - TEST_ASSERT_BIT_HIGH(BIT_STATUS4_STAGING_ACTIVE, currentStatus.status4); + TEST_ASSERT_NOT_EQUAL(0U, pw.secondary); } void test_Staging_4cyl_Auto_33pct(void) @@ -134,13 +136,14 @@ void test_Staging_4cyl_Auto_33pct(void) configPage10.stagingMode = STAGING_MODE_AUTO; uint32_t pwLimit = 9000; //90% duty cycle at 6000rpm - calculateStaging(9000U, 7000U); //90% duty cycle at 6000rpm + auto pw = computePulseWidths(9000U, 7000U); //90% duty cycle at 6000rpm + applyPWToSchedules(pw.primary, pw.secondary); //PW 1 and 2 should be maxed out at the pwLimit, 3 and 4 should be based on their relative size TEST_ASSERT_EQUAL(pwLimit, fuelSchedules[0].pw); //PW1/2 run at maximum available limit TEST_ASSERT_EQUAL(pwLimit, fuelSchedules[1].pw); TEST_ASSERT_EQUAL(6000, fuelSchedules[2].pw); TEST_ASSERT_EQUAL(6000, fuelSchedules[3].pw); - TEST_ASSERT_BIT_HIGH(BIT_STATUS4_STAGING_ACTIVE, currentStatus.status4); + TEST_ASSERT_NOT_EQUAL(0U, pw.secondary); } void test_Staging_4cyl_Table_50pct(void) @@ -159,11 +162,12 @@ void test_Staging_4cyl_Table_50pct(void) currentStatus.RPM += 1; currentStatus.fuelLoad += 1; - calculateStaging(9000U, 3000U); //90% duty cycle at 6000rpm + auto pw = computePulseWidths(9000U, 3000U); //90% duty cycle at 6000rpm + applyPWToSchedules(pw.primary, pw.secondary); TEST_ASSERT_EQUAL(4000, fuelSchedules[0].pw); TEST_ASSERT_EQUAL(4000, fuelSchedules[1].pw); TEST_ASSERT_EQUAL(2500, fuelSchedules[2].pw); TEST_ASSERT_EQUAL(2500, fuelSchedules[3].pw); - TEST_ASSERT_BIT_HIGH(BIT_STATUS4_STAGING_ACTIVE, currentStatus.status4); + TEST_ASSERT_NOT_EQUAL(0U, pw.secondary); } \ No newline at end of file diff --git a/test/test_init/tests_init.cpp b/test/test_init/tests_init.cpp index 363a7f89fb..881a605bff 100644 --- a/test/test_init/tests_init.cpp +++ b/test/test_init/tests_init.cpp @@ -46,6 +46,9 @@ void test_initialisation_complete(void) TEST_ASSERT_EQUAL(true, currentStatus.initialisationComplete); } +extern ioPort injectorPins[INJ_CHANNELS]; +extern ioPort ignitionPins[INJ_CHANNELS]; + void test_initialisation_ports(void) { #if defined(CORE_AVR) || defined(ARDUINO_ARCH_AVR) diff --git a/test/test_schedules/test_status_initial_off.cpp b/test/test_schedules/test_status_initial_off.cpp index ff0105c387..72c13ae57e 100644 --- a/test/test_schedules/test_status_initial_off.cpp +++ b/test/test_schedules/test_status_initial_off.cpp @@ -6,7 +6,7 @@ void test_status_initial_off(FuelSchedule &schedule) { - initialiseFuelSchedulers(pinInjectors); + initialiseFuelSchedulers(); TEST_ASSERT_EQUAL(OFF, schedule._status); } @@ -20,7 +20,7 @@ void test_status_initial_off_inj(void) void test_status_initial_off(IgnitionSchedule &schedule) { - initialiseFuelSchedulers(pinInjectors); + initialiseFuelSchedulers(); TEST_ASSERT_EQUAL(OFF, schedule._status); } diff --git a/test/test_schedules/test_status_off_to_pending.cpp b/test/test_schedules/test_status_off_to_pending.cpp index 77cf20aaba..0a944ebd1c 100644 --- a/test/test_schedules/test_status_off_to_pending.cpp +++ b/test/test_schedules/test_status_off_to_pending.cpp @@ -12,7 +12,7 @@ static void emptyCallback(void) { } void test_status_off_to_pending(FuelSchedule &schedule) { - initialiseFuelSchedulers(pinInjectors); + initialiseFuelSchedulers(); _setSchedule(schedule, TIMEOUT, DURATION); TEST_ASSERT_EQUAL(PENDING, schedule._status); } @@ -29,7 +29,7 @@ extern void setCallbacks(Schedule &schedule, voidVoidCallback pStartCallback, vo void test_status_off_to_pending_ign(IgnitionSchedule &schedule) { - initialiseIgnitionSchedulers(pinCoils); + initialiseIgnitionSchedulers(); setCallbacks(schedule, emptyCallback, emptyCallback); _setSchedule(schedule, TIMEOUT, DURATION); TEST_ASSERT_EQUAL(PENDING, schedule._status);