diff --git a/platformio.ini b/platformio.ini index 3c5201c6..645243a7 100644 --- a/platformio.ini +++ b/platformio.ini @@ -38,6 +38,7 @@ framework=arduino lib_deps = EEPROM, FlexCAN_T4, Time test_build_src = yes test_ignore = test_table3d_native +extra_scripts = post:post_extra_script.py [env:teensy36] ;platform=teensy diff --git a/post_extra_script.py b/post_extra_script.py new file mode 100644 index 00000000..b587629b --- /dev/null +++ b/post_extra_script.py @@ -0,0 +1,31 @@ +Import("env") + +# see https://github.com/platformio/platformio-core/issues/3742#issuecomment-1003454439 +def wait_for_monitor_port(source, target, env): + # "pio test" has no delay between upload & monitoring. Unfortuneatly, the teensy + # is rebooting at that point and the port isn't available. This rasies an exception. + port = env.GetProjectOption("monitor_port") + if port is None: + from platformio.builder.tools.pioupload import AutodetectUploadPort + AutodetectUploadPort(env) + port = env.subst("$UPLOAD_PORT") + if port: + # We have a port specified, wait for it to + # activate + print(f"Waiting for port {port}...") + import serial + while True: + try: + serial.Serial(port) + print("...done!") + return + except: + pass + + # No port specified, try a generic delay + print("Delay while uploading...") + import time + time.sleep(2) + print("...done!") + +env.AddPostAction("upload", wait_for_monitor_port) \ No newline at end of file diff --git a/speeduino/board_avr2560.h b/speeduino/board_avr2560.h index 3ea67e7f..730bc125 100644 --- a/speeduino/board_avr2560.h +++ b/speeduino/board_avr2560.h @@ -90,42 +90,42 @@ #define IGN8_COMPARE OCR3B //Replaces injector 2 //Note that the interrupt flag is reset BEFORE the interrupt is enabled - #define FUEL1_TIMER_ENABLE() TIFR3 |= (1<> 2) //Converts a given number of uS into the required number of timer ticks until that time has passed diff --git a/speeduino/board_same51.h b/speeduino/board_same51.h index bd0f3ecd..a549ff08 100644 --- a/speeduino/board_same51.h +++ b/speeduino/board_same51.h @@ -111,45 +111,45 @@ #define IGN7_COMPARE TCC2->CC[0].bit.CC #define IGN8_COMPARE TCC2->CC[1].bit.CC - #define FUEL1_TIMER_ENABLE() TCC0->INTENSET.bit.MC0 = 0x1 - #define FUEL2_TIMER_ENABLE() TCC0->INTENSET.bit.MC1 = 0x1 - #define FUEL3_TIMER_ENABLE() TCC0->INTENSET.bit.MC2 = 0x1 - #define FUEL4_TIMER_ENABLE() TCC0->INTENSET.bit.MC3 = 0x1 +static inline void FUEL1_TIMER_ENABLE(void) { TCC0->INTENSET.bit.MC0 = 0x1; } +static inline void FUEL2_TIMER_ENABLE(void) { TCC0->INTENSET.bit.MC1 = 0x1; } +static inline void FUEL3_TIMER_ENABLE(void) { TCC0->INTENSET.bit.MC2 = 0x1; } +static inline void FUEL4_TIMER_ENABLE(void) { TCC0->INTENSET.bit.MC3 = 0x1; } //The below are NOT YET RIGHT! - #define FUEL5_TIMER_ENABLE() TCC0->INTENSET.bit.MC0 = 0x1 - #define FUEL6_TIMER_ENABLE() TCC0->INTENSET.bit.MC1 = 0x1 - #define FUEL7_TIMER_ENABLE() TCC0->INTENSET.bit.MC2 = 0x1 - #define FUEL8_TIMER_ENABLE() TCC0->INTENSET.bit.MC3 = 0x1 +static inline void FUEL5_TIMER_ENABLE(void) { TCC0->INTENSET.bit.MC0 = 0x1; } +static inline void FUEL6_TIMER_ENABLE(void) { TCC0->INTENSET.bit.MC1 = 0x1; } +static inline void FUEL7_TIMER_ENABLE(void) { TCC0->INTENSET.bit.MC2 = 0x1; } +static inline void FUEL8_TIMER_ENABLE(void) { TCC0->INTENSET.bit.MC3 = 0x1; } - #define FUEL1_TIMER_DISABLE() TCC0->INTENSET.bit.MC0 = 0x0 - #define FUEL2_TIMER_DISABLE() TCC0->INTENSET.bit.MC0 = 0x0 - #define FUEL3_TIMER_DISABLE() TCC0->INTENSET.bit.MC0 = 0x0 - #define FUEL4_TIMER_DISABLE() TCC0->INTENSET.bit.MC0 = 0x0 +static inline void FUEL1_TIMER_DISABLE(void) { TCC0->INTENSET.bit.MC0 = 0x0; } +static inline void FUEL2_TIMER_DISABLE(void) { TCC0->INTENSET.bit.MC0 = 0x0; } +static inline void FUEL3_TIMER_DISABLE(void) { TCC0->INTENSET.bit.MC0 = 0x0; } +static inline void FUEL4_TIMER_DISABLE(void) { TCC0->INTENSET.bit.MC0 = 0x0; } //The below are NOT YET RIGHT! - #define FUEL5_TIMER_DISABLE() TCC0->INTENSET.bit.MC0 = 0x0 - #define FUEL6_TIMER_DISABLE() TCC0->INTENSET.bit.MC0 = 0x0 - #define FUEL7_TIMER_DISABLE() TCC0->INTENSET.bit.MC0 = 0x0 - #define FUEL8_TIMER_DISABLE() TCC0->INTENSET.bit.MC0 = 0x0 +static inline void FUEL5_TIMER_DISABLE(void) { TCC0->INTENSET.bit.MC0 = 0x0; } +static inline void FUEL6_TIMER_DISABLE(void) { TCC0->INTENSET.bit.MC0 = 0x0; } +static inline void FUEL7_TIMER_DISABLE(void) { TCC0->INTENSET.bit.MC0 = 0x0; } +static inline void FUEL9_TIMER_DISABLE(void) { TCC0->INTENSET.bit.MC0 = 0x0; } - #define IGN1_TIMER_ENABLE() TCC1->INTENSET.bit.MC0 = 0x1 - #define IGN2_TIMER_ENABLE() TCC1->INTENSET.bit.MC1 = 0x1 - #define IGN3_TIMER_ENABLE() TCC2->INTENSET.bit.MC0 = 0x1 - #define IGN4_TIMER_ENABLE() TCC2->INTENSET.bit.MC1 = 0x1 - //The below are NOT YET RIGHT! - #define IGN5_TIMER_ENABLE() TCC1->INTENSET.bit.MC0 = 0x1 - #define IGN6_TIMER_ENABLE() TCC1->INTENSET.bit.MC1 = 0x1 - #define IGN7_TIMER_ENABLE() TCC2->INTENSET.bit.MC0 = 0x1 - #define IGN8_TIMER_ENABLE() TCC2->INTENSET.bit.MC1 = 0x1 +static inline void IGN1_TIMER_ENABLE(void) { TCC1->INTENSET.bit.MC0 = 0x1; } +static inline void IGN2_TIMER_ENABLE(void) { TCC1->INTENSET.bit.MC1 = 0x1; } +static inline void IGN3_TIMER_ENABLE(void) { TCC2->INTENSET.bit.MC0 = 0x1; } +static inline void IGN4_TIMER_ENABLE(void) { TCC2->INTENSET.bit.MC1 = 0x1; } +//The below are NOT YET RIGHT! +static inline void IGN5_TIMER_ENABLE(void) { TCC1->INTENSET.bit.MC0 = 0x1; } +static inline void IGN6_TIMER_ENABLE(void) { TCC1->INTENSET.bit.MC1 = 0x1; } +static inline void IGN7_TIMER_ENABLE(void) { TCC2->INTENSET.bit.MC0 = 0x1; } +static inline void IGN8_TIMER_ENABLE(void) { TCC2->INTENSET.bit.MC1 = 0x1; } - #define IGN1_TIMER_DISABLE() TCC1->INTENSET.bit.MC0 = 0x0 - #define IGN2_TIMER_DISABLE() TCC1->INTENSET.bit.MC1 = 0x0 - #define IGN3_TIMER_DISABLE() TCC2->INTENSET.bit.MC0 = 0x0 - #define IGN4_TIMER_DISABLE() TCC2->INTENSET.bit.MC1 = 0x0 - //The below are NOT YET RIGHT! - #define IGN5_TIMER_DISABLE() TCC1->INTENSET.bit.MC0 = 0x0 - #define IGN6_TIMER_DISABLE() TCC1->INTENSET.bit.MC1 = 0x0 - #define IGN7_TIMER_DISABLE() TCC2->INTENSET.bit.MC0 = 0x0 - #define IGN8_TIMER_DISABLE() TCC2->INTENSET.bit.MC1 = 0x0 +static inline void IGN1_TIMER_DISABLE(void) { TCC1->INTENSET.bit.MC0 = 0x0; } +static inline void IGN2_TIMER_DISABLE(void) { TCC1->INTENSET.bit.MC1 = 0x0; } +static inline void IGN3_TIMER_DISABLE(void) { TCC2->INTENSET.bit.MC0 = 0x0; } +static inline void IGN4_TIMER_DISABLE(void) { TCC2->INTENSET.bit.MC1 = 0x0; } +//The below are NOT YET RIGHT! +static inline void IGN5_TIMER_DISABLE(void) { TCC1->INTENSET.bit.MC0 = 0x0; } +static inline void IGN6_TIMER_DISABLE(void) { TCC1->INTENSET.bit.MC1 = 0x0; } +static inline void IGN7_TIMER_DISABLE(void) { TCC2->INTENSET.bit.MC0 = 0x0; } +static inline void IGN8_TIMER_DISABLE(void) { TCC2->INTENSET.bit.MC1 = 0x0; } #define MAX_TIMER_PERIOD 139808 // 2.13333333uS * 65535 #define MAX_TIMER_PERIOD_SLOW 139808 diff --git a/speeduino/board_stm32_generic.h b/speeduino/board_stm32_generic.h index 2bff993a..e1250c1d 100644 --- a/speeduino/board_stm32_generic.h +++ b/speeduino/board_stm32_generic.h @@ -137,46 +137,46 @@ #define IGN8_COMPARE (TIM4)->CCR4 #endif //github.com/rogerclarkmelbourne/Arduino_STM32/blob/754bc2969921f1ef262bd69e7faca80b19db7524/STM32F1/system/libmaple/include/libmaple/timer.h#L444 - #define FUEL1_TIMER_ENABLE() (TIM3)->SR = ~TIM_FLAG_CC1; (TIM3)->DIER |= TIM_DIER_CC1IE - #define FUEL2_TIMER_ENABLE() (TIM3)->SR = ~TIM_FLAG_CC2; (TIM3)->DIER |= TIM_DIER_CC2IE - #define FUEL3_TIMER_ENABLE() (TIM3)->SR = ~TIM_FLAG_CC3; (TIM3)->DIER |= TIM_DIER_CC3IE - #define FUEL4_TIMER_ENABLE() (TIM3)->SR = ~TIM_FLAG_CC4; (TIM3)->DIER |= TIM_DIER_CC4IE + static inline void FUEL1_TIMER_ENABLE(void) {(TIM3)->SR = ~TIM_FLAG_CC1; (TIM3)->DIER |= TIM_DIER_CC1IE;} + static inline void FUEL2_TIMER_ENABLE(void) {(TIM3)->SR = ~TIM_FLAG_CC2; (TIM3)->DIER |= TIM_DIER_CC2IE;} + static inline void FUEL3_TIMER_ENABLE(void) {(TIM3)->SR = ~TIM_FLAG_CC3; (TIM3)->DIER |= TIM_DIER_CC3IE;} + static inline void FUEL4_TIMER_ENABLE(void) {(TIM3)->SR = ~TIM_FLAG_CC4; (TIM3)->DIER |= TIM_DIER_CC4IE;} - #define FUEL1_TIMER_DISABLE() (TIM3)->DIER &= ~TIM_DIER_CC1IE - #define FUEL2_TIMER_DISABLE() (TIM3)->DIER &= ~TIM_DIER_CC2IE - #define FUEL3_TIMER_DISABLE() (TIM3)->DIER &= ~TIM_DIER_CC3IE - #define FUEL4_TIMER_DISABLE() (TIM3)->DIER &= ~TIM_DIER_CC4IE + static inline void FUEL1_TIMER_DISABLE(void) {(TIM3)->DIER &= ~TIM_DIER_CC1IE;} + static inline void FUEL2_TIMER_DISABLE(void) {(TIM3)->DIER &= ~TIM_DIER_CC2IE;} + static inline void FUEL3_TIMER_DISABLE(void) {(TIM3)->DIER &= ~TIM_DIER_CC3IE;} + static inline void FUEL4_TIMER_DISABLE(void) {(TIM3)->DIER &= ~TIM_DIER_CC4IE;} - #define IGN1_TIMER_ENABLE() (TIM2)->SR = ~TIM_FLAG_CC1; (TIM2)->DIER |= TIM_DIER_CC1IE - #define IGN2_TIMER_ENABLE() (TIM2)->SR = ~TIM_FLAG_CC2; (TIM2)->DIER |= TIM_DIER_CC2IE - #define IGN3_TIMER_ENABLE() (TIM2)->SR = ~TIM_FLAG_CC3; (TIM2)->DIER |= TIM_DIER_CC3IE - #define IGN4_TIMER_ENABLE() (TIM2)->SR = ~TIM_FLAG_CC4; (TIM2)->DIER |= TIM_DIER_CC4IE + static inline void IGN1_TIMER_ENABLE(void) {(TIM2)->SR = ~TIM_FLAG_CC1; (TIM2)->DIER |= TIM_DIER_CC1IE;} + static inline void IGN2_TIMER_ENABLE(void) {(TIM2)->SR = ~TIM_FLAG_CC2; (TIM2)->DIER |= TIM_DIER_CC2IE;} + static inline void IGN3_TIMER_ENABLE(void) {(TIM2)->SR = ~TIM_FLAG_CC3; (TIM2)->DIER |= TIM_DIER_CC3IE;} + static inline void IGN4_TIMER_ENABLE(void) {(TIM2)->SR = ~TIM_FLAG_CC4; (TIM2)->DIER |= TIM_DIER_CC4IE;} - #define IGN1_TIMER_DISABLE() (TIM2)->DIER &= ~TIM_DIER_CC1IE - #define IGN2_TIMER_DISABLE() (TIM2)->DIER &= ~TIM_DIER_CC2IE - #define IGN3_TIMER_DISABLE() (TIM2)->DIER &= ~TIM_DIER_CC3IE - #define IGN4_TIMER_DISABLE() (TIM2)->DIER &= ~TIM_DIER_CC4IE + static inline void IGN1_TIMER_DISABLE(void) {(TIM2)->DIER &= ~TIM_DIER_CC1IE;} + static inline void IGN2_TIMER_DISABLE(void) {(TIM2)->DIER &= ~TIM_DIER_CC2IE;} + static inline void IGN3_TIMER_DISABLE(void) {(TIM2)->DIER &= ~TIM_DIER_CC3IE;} + static inline void IGN4_TIMER_DISABLE(void) {(TIM2)->DIER &= ~TIM_DIER_CC4IE;} #ifndef SMALL_FLASH_MODE - #define FUEL5_TIMER_ENABLE() (TIM5)->SR = ~TIM_FLAG_CC1; (TIM5)->DIER |= TIM_DIER_CC1IE - #define FUEL6_TIMER_ENABLE() (TIM5)->SR = ~TIM_FLAG_CC2; (TIM5)->DIER |= TIM_DIER_CC2IE - #define FUEL7_TIMER_ENABLE() (TIM5)->SR = ~TIM_FLAG_CC3; (TIM5)->DIER |= TIM_DIER_CC3IE - #define FUEL8_TIMER_ENABLE() (TIM5)->SR = ~TIM_FLAG_CC4; (TIM5)->DIER |= TIM_DIER_CC4IE + static inline void FUEL5_TIMER_ENABLE(void) {(TIM5)->SR = ~TIM_FLAG_CC1; (TIM5)->DIER |= TIM_DIER_CC1IE;} + static inline void FUEL6_TIMER_ENABLE(void) {(TIM5)->SR = ~TIM_FLAG_CC2; (TIM5)->DIER |= TIM_DIER_CC2IE;} + static inline void FUEL7_TIMER_ENABLE(void) {(TIM5)->SR = ~TIM_FLAG_CC3; (TIM5)->DIER |= TIM_DIER_CC3IE;} + static inline void FUEL8_TIMER_ENABLE(void) {(TIM5)->SR = ~TIM_FLAG_CC4; (TIM5)->DIER |= TIM_DIER_CC4IE;} - #define FUEL5_TIMER_DISABLE() (TIM5)->DIER &= ~TIM_DIER_CC1IE - #define FUEL6_TIMER_DISABLE() (TIM5)->DIER &= ~TIM_DIER_CC2IE - #define FUEL7_TIMER_DISABLE() (TIM5)->DIER &= ~TIM_DIER_CC3IE - #define FUEL8_TIMER_DISABLE() (TIM5)->DIER &= ~TIM_DIER_CC4IE + static inline void FUEL5_TIMER_DISABLE(void) {(TIM5)->DIER &= ~TIM_DIER_CC1IE;} + static inline void FUEL6_TIMER_DISABLE(void) {(TIM5)->DIER &= ~TIM_DIER_CC2IE;} + static inline void FUEL7_TIMER_DISABLE(void) {(TIM5)->DIER &= ~TIM_DIER_CC3IE;} + static inline void FUEL8_TIMER_DISABLE(void) {(TIM5)->DIER &= ~TIM_DIER_CC4IE;} - #define IGN5_TIMER_ENABLE() (TIM4)->SR = ~TIM_FLAG_CC1; (TIM4)->DIER |= TIM_DIER_CC1IE - #define IGN6_TIMER_ENABLE() (TIM4)->SR = ~TIM_FLAG_CC2; (TIM4)->DIER |= TIM_DIER_CC2IE - #define IGN7_TIMER_ENABLE() (TIM4)->SR = ~TIM_FLAG_CC3; (TIM4)->DIER |= TIM_DIER_CC3IE - #define IGN8_TIMER_ENABLE() (TIM4)->SR = ~TIM_FLAG_CC4; (TIM4)->DIER |= TIM_DIER_CC4IE + static inline void IGN5_TIMER_ENABLE(void) {(TIM4)->SR = ~TIM_FLAG_CC1; (TIM4)->DIER |= TIM_DIER_CC1IE;} + static inline void IGN6_TIMER_ENABLE(void) {(TIM4)->SR = ~TIM_FLAG_CC2; (TIM4)->DIER |= TIM_DIER_CC2IE;} + static inline void IGN7_TIMER_ENABLE(void) {(TIM4)->SR = ~TIM_FLAG_CC3; (TIM4)->DIER |= TIM_DIER_CC3IE;} + static inline void IGN8_TIMER_ENABLE(void) {(TIM4)->SR = ~TIM_FLAG_CC4; (TIM4)->DIER |= TIM_DIER_CC4IE;} - #define IGN5_TIMER_DISABLE() (TIM4)->DIER &= ~TIM_DIER_CC1IE - #define IGN6_TIMER_DISABLE() (TIM4)->DIER &= ~TIM_DIER_CC2IE - #define IGN7_TIMER_DISABLE() (TIM4)->DIER &= ~TIM_DIER_CC3IE - #define IGN8_TIMER_DISABLE() (TIM4)->DIER &= ~TIM_DIER_CC4IE + static inline void IGN5_TIMER_DISABLE(void) {(TIM4)->DIER &= ~TIM_DIER_CC1IE;} + static inline void IGN6_TIMER_DISABLE(void) {(TIM4)->DIER &= ~TIM_DIER_CC2IE;} + static inline void IGN7_TIMER_DISABLE(void) {(TIM4)->DIER &= ~TIM_DIER_CC3IE;} + static inline void IGN8_TIMER_DISABLE(void) {(TIM4)->DIER &= ~TIM_DIER_CC4IE;} #endif /* diff --git a/speeduino/board_stm32_official.h b/speeduino/board_stm32_official.h index 5bccb3ee..a4c1bed9 100644 --- a/speeduino/board_stm32_official.h +++ b/speeduino/board_stm32_official.h @@ -196,46 +196,46 @@ extern "C" char* sbrk(int incr); #define IGN8_COMPARE (TIM4)->CCR4 -#define FUEL1_TIMER_ENABLE() (TIM3)->CR1 |= TIM_CR1_CEN; (TIM3)->SR = ~TIM_FLAG_CC1; (TIM3)->DIER |= TIM_DIER_CC1IE -#define FUEL2_TIMER_ENABLE() (TIM3)->CR1 |= TIM_CR1_CEN; (TIM3)->SR = ~TIM_FLAG_CC2; (TIM3)->DIER |= TIM_DIER_CC2IE -#define FUEL3_TIMER_ENABLE() (TIM3)->CR1 |= TIM_CR1_CEN; (TIM3)->SR = ~TIM_FLAG_CC3; (TIM3)->DIER |= TIM_DIER_CC3IE -#define FUEL4_TIMER_ENABLE() (TIM3)->CR1 |= TIM_CR1_CEN; (TIM3)->SR = ~TIM_FLAG_CC4; (TIM3)->DIER |= TIM_DIER_CC4IE +static inline void FUEL1_TIMER_ENABLE(void) {(TIM3)->CR1 |= TIM_CR1_CEN; (TIM3)->SR = ~TIM_FLAG_CC1; (TIM3)->DIER |= TIM_DIER_CC1IE;} +static inline void FUEL2_TIMER_ENABLE(void) {(TIM3)->CR1 |= TIM_CR1_CEN; (TIM3)->SR = ~TIM_FLAG_CC2; (TIM3)->DIER |= TIM_DIER_CC2IE;} +static inline void FUEL3_TIMER_ENABLE(void) {(TIM3)->CR1 |= TIM_CR1_CEN; (TIM3)->SR = ~TIM_FLAG_CC3; (TIM3)->DIER |= TIM_DIER_CC3IE;} +static inline void FUEL4_TIMER_ENABLE(void) {(TIM3)->CR1 |= TIM_CR1_CEN; (TIM3)->SR = ~TIM_FLAG_CC4; (TIM3)->DIER |= TIM_DIER_CC4IE;} -#define FUEL1_TIMER_DISABLE() (TIM3)->DIER &= ~TIM_DIER_CC1IE -#define FUEL2_TIMER_DISABLE() (TIM3)->DIER &= ~TIM_DIER_CC2IE -#define FUEL3_TIMER_DISABLE() (TIM3)->DIER &= ~TIM_DIER_CC3IE -#define FUEL4_TIMER_DISABLE() (TIM3)->DIER &= ~TIM_DIER_CC4IE +static inline void FUEL1_TIMER_DISABLE(void) {(TIM3)->DIER &= ~TIM_DIER_CC1IE;} +static inline void FUEL2_TIMER_DISABLE(void) {(TIM3)->DIER &= ~TIM_DIER_CC2IE;} +static inline void FUEL3_TIMER_DISABLE(void) {(TIM3)->DIER &= ~TIM_DIER_CC3IE;} +static inline void FUEL4_TIMER_DISABLE(void) {(TIM3)->DIER &= ~TIM_DIER_CC4IE;} -#define IGN1_TIMER_ENABLE() (TIM2)->CR1 |= TIM_CR1_CEN; (TIM2)->SR = ~TIM_FLAG_CC1; (TIM2)->DIER |= TIM_DIER_CC1IE -#define IGN2_TIMER_ENABLE() (TIM2)->CR1 |= TIM_CR1_CEN; (TIM2)->SR = ~TIM_FLAG_CC2; (TIM2)->DIER |= TIM_DIER_CC2IE -#define IGN3_TIMER_ENABLE() (TIM2)->CR1 |= TIM_CR1_CEN; (TIM2)->SR = ~TIM_FLAG_CC3; (TIM2)->DIER |= TIM_DIER_CC3IE -#define IGN4_TIMER_ENABLE() (TIM2)->CR1 |= TIM_CR1_CEN; (TIM2)->SR = ~TIM_FLAG_CC4; (TIM2)->DIER |= TIM_DIER_CC4IE + static inline void IGN1_TIMER_ENABLE(void) {(TIM2)->CR1 |= TIM_CR1_CEN; (TIM2)->SR = ~TIM_FLAG_CC1; (TIM2)->DIER |= TIM_DIER_CC1IE;} + static inline void IGN2_TIMER_ENABLE(void) {(TIM2)->CR1 |= TIM_CR1_CEN; (TIM2)->SR = ~TIM_FLAG_CC2; (TIM2)->DIER |= TIM_DIER_CC2IE;} + static inline void IGN3_TIMER_ENABLE(void) {(TIM2)->CR1 |= TIM_CR1_CEN; (TIM2)->SR = ~TIM_FLAG_CC3; (TIM2)->DIER |= TIM_DIER_CC3IE;} + static inline void IGN4_TIMER_ENABLE(void) {(TIM2)->CR1 |= TIM_CR1_CEN; (TIM2)->SR = ~TIM_FLAG_CC4; (TIM2)->DIER |= TIM_DIER_CC4IE;} -#define IGN1_TIMER_DISABLE() (TIM2)->DIER &= ~TIM_DIER_CC1IE -#define IGN2_TIMER_DISABLE() (TIM2)->DIER &= ~TIM_DIER_CC2IE -#define IGN3_TIMER_DISABLE() (TIM2)->DIER &= ~TIM_DIER_CC3IE -#define IGN4_TIMER_DISABLE() (TIM2)->DIER &= ~TIM_DIER_CC4IE + static inline void IGN1_TIMER_DISABLE(void) {(TIM2)->DIER &= ~TIM_DIER_CC1IE;} + static inline void IGN2_TIMER_DISABLE(void) {(TIM2)->DIER &= ~TIM_DIER_CC2IE;} + static inline void IGN3_TIMER_DISABLE(void) {(TIM2)->DIER &= ~TIM_DIER_CC3IE;} + static inline void IGN4_TIMER_DISABLE(void) {(TIM2)->DIER &= ~TIM_DIER_CC4IE;} -#define FUEL5_TIMER_ENABLE() (TIM5)->CR1 |= TIM_CR1_CEN; (TIM5)->CR1 |= TIM_CR1_CEN; (TIM5)->SR = ~TIM_FLAG_CC1; (TIM5)->DIER |= TIM_DIER_CC1IE -#define FUEL6_TIMER_ENABLE() (TIM5)->CR1 |= TIM_CR1_CEN; (TIM5)->CR1 |= TIM_CR1_CEN; (TIM5)->SR = ~TIM_FLAG_CC2; (TIM5)->DIER |= TIM_DIER_CC2IE -#define FUEL7_TIMER_ENABLE() (TIM5)->CR1 |= TIM_CR1_CEN; (TIM5)->CR1 |= TIM_CR1_CEN; (TIM5)->SR = ~TIM_FLAG_CC3; (TIM5)->DIER |= TIM_DIER_CC3IE -#define FUEL8_TIMER_ENABLE() (TIM5)->CR1 |= TIM_CR1_CEN; (TIM5)->CR1 |= TIM_CR1_CEN; (TIM5)->SR = ~TIM_FLAG_CC4; (TIM5)->DIER |= TIM_DIER_CC4IE +static inline void FUEL5_TIMER_ENABLE(void) {(TIM5)->CR1 |= TIM_CR1_CEN; (TIM5)->CR1 |= TIM_CR1_CEN; (TIM5)->SR = ~TIM_FLAG_CC1; (TIM5)->DIER |= TIM_DIER_CC1IE;} +static inline void FUEL6_TIMER_ENABLE(void) {(TIM5)->CR1 |= TIM_CR1_CEN; (TIM5)->CR1 |= TIM_CR1_CEN; (TIM5)->SR = ~TIM_FLAG_CC2; (TIM5)->DIER |= TIM_DIER_CC2IE;} +static inline void FUEL7_TIMER_ENABLE(void) {(TIM5)->CR1 |= TIM_CR1_CEN; (TIM5)->CR1 |= TIM_CR1_CEN; (TIM5)->SR = ~TIM_FLAG_CC3; (TIM5)->DIER |= TIM_DIER_CC3IE;} +static inline void FUEL8_TIMER_ENABLE(void) {(TIM5)->CR1 |= TIM_CR1_CEN; (TIM5)->CR1 |= TIM_CR1_CEN; (TIM5)->SR = ~TIM_FLAG_CC4; (TIM5)->DIER |= TIM_DIER_CC4IE;} -#define FUEL5_TIMER_DISABLE() (TIM5)->DIER &= ~TIM_DIER_CC1IE -#define FUEL6_TIMER_DISABLE() (TIM5)->DIER &= ~TIM_DIER_CC2IE -#define FUEL7_TIMER_DISABLE() (TIM5)->DIER &= ~TIM_DIER_CC3IE -#define FUEL8_TIMER_DISABLE() (TIM5)->DIER &= ~TIM_DIER_CC4IE +static inline void FUEL5_TIMER_DISABLE(void) {(TIM5)->DIER &= ~TIM_DIER_CC1IE;} +static inline void FUEL6_TIMER_DISABLE(void) {(TIM5)->DIER &= ~TIM_DIER_CC2IE;} +static inline void FUEL7_TIMER_DISABLE(void) {(TIM5)->DIER &= ~TIM_DIER_CC3IE;} +static inline void FUEL8_TIMER_DISABLE(void) {(TIM5)->DIER &= ~TIM_DIER_CC4IE;} -#define IGN5_TIMER_ENABLE() (TIM4)->CR1 |= TIM_CR1_CEN; (TIM4)->SR = ~TIM_FLAG_CC1; (TIM4)->DIER |= TIM_DIER_CC1IE -#define IGN6_TIMER_ENABLE() (TIM4)->CR1 |= TIM_CR1_CEN; (TIM4)->SR = ~TIM_FLAG_CC2; (TIM4)->DIER |= TIM_DIER_CC2IE -#define IGN7_TIMER_ENABLE() (TIM4)->CR1 |= TIM_CR1_CEN; (TIM4)->SR = ~TIM_FLAG_CC3; (TIM4)->DIER |= TIM_DIER_CC3IE -#define IGN8_TIMER_ENABLE() (TIM4)->CR1 |= TIM_CR1_CEN; (TIM4)->SR = ~TIM_FLAG_CC4; (TIM4)->DIER |= TIM_DIER_CC4IE + static inline void IGN5_TIMER_ENABLE(void) {(TIM4)->CR1 |= TIM_CR1_CEN; (TIM4)->SR = ~TIM_FLAG_CC1; (TIM4)->DIER |= TIM_DIER_CC1IE;} + static inline void IGN6_TIMER_ENABLE(void) {(TIM4)->CR1 |= TIM_CR1_CEN; (TIM4)->SR = ~TIM_FLAG_CC2; (TIM4)->DIER |= TIM_DIER_CC2IE;} + static inline void IGN7_TIMER_ENABLE(void) {(TIM4)->CR1 |= TIM_CR1_CEN; (TIM4)->SR = ~TIM_FLAG_CC3; (TIM4)->DIER |= TIM_DIER_CC3IE;} + static inline void IGN8_TIMER_ENABLE(void) {(TIM4)->CR1 |= TIM_CR1_CEN; (TIM4)->SR = ~TIM_FLAG_CC4; (TIM4)->DIER |= TIM_DIER_CC4IE;} -#define IGN5_TIMER_DISABLE() (TIM4)->DIER &= ~TIM_DIER_CC1IE -#define IGN6_TIMER_DISABLE() (TIM4)->DIER &= ~TIM_DIER_CC2IE -#define IGN7_TIMER_DISABLE() (TIM4)->DIER &= ~TIM_DIER_CC3IE -#define IGN8_TIMER_DISABLE() (TIM4)->DIER &= ~TIM_DIER_CC4IE + static inline void IGN5_TIMER_DISABLE(void) {(TIM4)->DIER &= ~TIM_DIER_CC1IE;} + static inline void IGN6_TIMER_DISABLE(void) {(TIM4)->DIER &= ~TIM_DIER_CC2IE;} + static inline void IGN7_TIMER_DISABLE(void) {(TIM4)->DIER &= ~TIM_DIER_CC3IE;} + static inline void IGN8_TIMER_DISABLE(void) {(TIM4)->DIER &= ~TIM_DIER_CC4IE;} diff --git a/speeduino/board_teensy35.h b/speeduino/board_teensy35.h index 45e0d789..787c52a8 100644 --- a/speeduino/board_teensy35.h +++ b/speeduino/board_teensy35.h @@ -76,41 +76,41 @@ #define IGN7_COMPARE FTM3_C6V #define IGN8_COMPARE FTM3_C7V - #define FUEL1_TIMER_ENABLE() FTM0_C0SC |= FTM_CSC_CHIE //Write 1 to the CHIE (Channel Interrupt Enable) bit of channel 0 Status/Control - #define FUEL2_TIMER_ENABLE() FTM0_C1SC |= FTM_CSC_CHIE - #define FUEL3_TIMER_ENABLE() FTM0_C2SC |= FTM_CSC_CHIE - #define FUEL4_TIMER_ENABLE() FTM0_C3SC |= FTM_CSC_CHIE - #define FUEL5_TIMER_ENABLE() FTM3_C0SC |= FTM_CSC_CHIE - #define FUEL6_TIMER_ENABLE() FTM3_C1SC |= FTM_CSC_CHIE - #define FUEL7_TIMER_ENABLE() FTM3_C2SC |= FTM_CSC_CHIE - #define FUEL8_TIMER_ENABLE() FTM3_C3SC |= FTM_CSC_CHIE + static inline void FUEL1_TIMER_ENABLE(void) {FTM0_C0SC |= FTM_CSC_CHIE;} //Write 1 to the CHIE (Channel Interrupt Enable) bit of channel 0 Status/Control + static inline void FUEL2_TIMER_ENABLE(void) {FTM0_C1SC |= FTM_CSC_CHIE;} + static inline void FUEL3_TIMER_ENABLE(void) {FTM0_C2SC |= FTM_CSC_CHIE;} + static inline void FUEL4_TIMER_ENABLE(void) {FTM0_C3SC |= FTM_CSC_CHIE;} + static inline void FUEL5_TIMER_ENABLE(void) {FTM3_C0SC |= FTM_CSC_CHIE;} + static inline void FUEL6_TIMER_ENABLE(void) {FTM3_C1SC |= FTM_CSC_CHIE;} + static inline void FUEL7_TIMER_ENABLE(void) {FTM3_C2SC |= FTM_CSC_CHIE;} + static inline void FUEL8_TIMER_ENABLE(void) {FTM3_C3SC |= FTM_CSC_CHIE;} - #define FUEL1_TIMER_DISABLE() FTM0_C0SC &= ~FTM_CSC_CHIE //Write 0 to the CHIE (Channel Interrupt Enable) bit of channel 0 Status/Control - #define FUEL2_TIMER_DISABLE() FTM0_C1SC &= ~FTM_CSC_CHIE - #define FUEL3_TIMER_DISABLE() FTM0_C2SC &= ~FTM_CSC_CHIE - #define FUEL4_TIMER_DISABLE() FTM0_C3SC &= ~FTM_CSC_CHIE - #define FUEL5_TIMER_DISABLE() FTM3_C0SC &= ~FTM_CSC_CHIE //Write 0 to the CHIE (Channel Interrupt Enable) bit of channel 0 Status/Control - #define FUEL6_TIMER_DISABLE() FTM3_C1SC &= ~FTM_CSC_CHIE - #define FUEL7_TIMER_DISABLE() FTM3_C2SC &= ~FTM_CSC_CHIE - #define FUEL8_TIMER_DISABLE() FTM3_C3SC &= ~FTM_CSC_CHIE + static inline void FUEL1_TIMER_DISABLE(void) {FTM0_C0SC &= ~FTM_CSC_CHIE;} //Write 0 to the CHIE (Channel Interrupt Enable) bit of channel 0 Status/Control + static inline void FUEL2_TIMER_DISABLE(void) {FTM0_C1SC &= ~FTM_CSC_CHIE;} + static inline void FUEL3_TIMER_DISABLE(void) {FTM0_C2SC &= ~FTM_CSC_CHIE;} + static inline void FUEL4_TIMER_DISABLE(void) {FTM0_C3SC &= ~FTM_CSC_CHIE;} + static inline void FUEL5_TIMER_DISABLE(void) {FTM3_C0SC &= ~FTM_CSC_CHIE;} //Write 0 to the CHIE (Channel Interrupt Enable) bit of channel 0 Status/Control + static inline void FUEL6_TIMER_DISABLE(void) {FTM3_C1SC &= ~FTM_CSC_CHIE;} + static inline void FUEL7_TIMER_DISABLE(void) {FTM3_C2SC &= ~FTM_CSC_CHIE;} + static inline void FUEL8_TIMER_DISABLE(void) {FTM3_C3SC &= ~FTM_CSC_CHIE;} - #define IGN1_TIMER_ENABLE() FTM0_C4SC |= FTM_CSC_CHIE - #define IGN2_TIMER_ENABLE() FTM0_C5SC |= FTM_CSC_CHIE - #define IGN3_TIMER_ENABLE() FTM0_C6SC |= FTM_CSC_CHIE - #define IGN4_TIMER_ENABLE() FTM0_C7SC |= FTM_CSC_CHIE - #define IGN5_TIMER_ENABLE() FTM3_C4SC |= FTM_CSC_CHIE - #define IGN6_TIMER_ENABLE() FTM3_C5SC |= FTM_CSC_CHIE - #define IGN7_TIMER_ENABLE() FTM3_C6SC |= FTM_CSC_CHIE - #define IGN8_TIMER_ENABLE() FTM3_C7SC |= FTM_CSC_CHIE + static inline void IGN1_TIMER_ENABLE(void) {FTM0_C4SC |= FTM_CSC_CHIE;} + static inline void IGN2_TIMER_ENABLE(void) {FTM0_C5SC |= FTM_CSC_CHIE;} + static inline void IGN3_TIMER_ENABLE(void) {FTM0_C6SC |= FTM_CSC_CHIE;} + static inline void IGN4_TIMER_ENABLE(void) {FTM0_C7SC |= FTM_CSC_CHIE;} + static inline void IGN5_TIMER_ENABLE(void) {FTM3_C4SC |= FTM_CSC_CHIE;} + static inline void IGN6_TIMER_ENABLE(void) {FTM3_C5SC |= FTM_CSC_CHIE;} + static inline void IGN7_TIMER_ENABLE(void) {FTM3_C6SC |= FTM_CSC_CHIE;} + static inline void IGN8_TIMER_ENABLE(void) {FTM3_C7SC |= FTM_CSC_CHIE;} - #define IGN1_TIMER_DISABLE() FTM0_C4SC &= ~FTM_CSC_CHIE - #define IGN2_TIMER_DISABLE() FTM0_C5SC &= ~FTM_CSC_CHIE - #define IGN3_TIMER_DISABLE() FTM0_C6SC &= ~FTM_CSC_CHIE - #define IGN4_TIMER_DISABLE() FTM0_C7SC &= ~FTM_CSC_CHIE - #define IGN5_TIMER_DISABLE() FTM3_C4SC &= ~FTM_CSC_CHIE - #define IGN6_TIMER_DISABLE() FTM3_C5SC &= ~FTM_CSC_CHIE - #define IGN7_TIMER_DISABLE() FTM3_C6SC &= ~FTM_CSC_CHIE - #define IGN8_TIMER_DISABLE() FTM3_C7SC &= ~FTM_CSC_CHIE + static inline void IGN1_TIMER_DISABLE(void) {FTM0_C4SC &= ~FTM_CSC_CHIE;} + static inline void IGN2_TIMER_DISABLE(void) {FTM0_C5SC &= ~FTM_CSC_CHIE;} + static inline void IGN3_TIMER_DISABLE(void) {FTM0_C6SC &= ~FTM_CSC_CHIE;} + static inline void IGN4_TIMER_DISABLE(void) {FTM0_C7SC &= ~FTM_CSC_CHIE;} + static inline void IGN5_TIMER_DISABLE(void) {FTM3_C4SC &= ~FTM_CSC_CHIE;} + static inline void IGN6_TIMER_DISABLE(void) {FTM3_C5SC &= ~FTM_CSC_CHIE;} + static inline void IGN7_TIMER_DISABLE(void) {FTM3_C6SC &= ~FTM_CSC_CHIE;} + static inline void IGN8_TIMER_DISABLE(void) {FTM3_C7SC &= ~FTM_CSC_CHIE;} #define MAX_TIMER_PERIOD 139808 // 2.13333333uS * 65535 #define uS_TO_TIMER_COMPARE(uS) ((uS * 15) >> 5) //Converts a given number of uS into the required number of timer ticks until that time has passed. diff --git a/speeduino/board_teensy41.h b/speeduino/board_teensy41.h index 0cc89fb8..422b5681 100644 --- a/speeduino/board_teensy41.h +++ b/speeduino/board_teensy41.h @@ -82,41 +82,41 @@ #define IGN7_COMPARE TMR4_COMP12 #define IGN8_COMPARE TMR4_COMP13 - #define FUEL1_TIMER_ENABLE() TMR1_CSCTRL0 |= TMR_CSCTRL_TCF1EN //Write 1 to the TCFIEN (Channel Interrupt Enable) bit of channel 0 Status/Control - #define FUEL2_TIMER_ENABLE() TMR1_CSCTRL1 |= TMR_CSCTRL_TCF1EN - #define FUEL3_TIMER_ENABLE() TMR1_CSCTRL2 |= TMR_CSCTRL_TCF1EN - #define FUEL4_TIMER_ENABLE() TMR1_CSCTRL3 |= TMR_CSCTRL_TCF1EN - #define FUEL5_TIMER_ENABLE() TMR3_CSCTRL0 |= TMR_CSCTRL_TCF1EN - #define FUEL6_TIMER_ENABLE() TMR3_CSCTRL1 |= TMR_CSCTRL_TCF1EN - #define FUEL7_TIMER_ENABLE() TMR3_CSCTRL2 |= TMR_CSCTRL_TCF1EN - #define FUEL8_TIMER_ENABLE() TMR3_CSCTRL3 |= TMR_CSCTRL_TCF1EN + static inline void FUEL1_TIMER_ENABLE(void) {TMR1_CSCTRL0 |= TMR_CSCTRL_TCF1EN;} //Write 1 to the TCFIEN (Channel Interrupt Enable) bit of channel 0 Status/Control + static inline void FUEL2_TIMER_ENABLE(void) {TMR1_CSCTRL1 |= TMR_CSCTRL_TCF1EN;} + static inline void FUEL3_TIMER_ENABLE(void) {TMR1_CSCTRL2 |= TMR_CSCTRL_TCF1EN;} + static inline void FUEL4_TIMER_ENABLE(void) {TMR1_CSCTRL3 |= TMR_CSCTRL_TCF1EN;} + static inline void FUEL5_TIMER_ENABLE(void) {TMR3_CSCTRL0 |= TMR_CSCTRL_TCF1EN;} + static inline void FUEL6_TIMER_ENABLE(void) {TMR3_CSCTRL1 |= TMR_CSCTRL_TCF1EN;} + static inline void FUEL7_TIMER_ENABLE(void) {TMR3_CSCTRL2 |= TMR_CSCTRL_TCF1EN;} + static inline void FUEL8_TIMER_ENABLE(void) {TMR3_CSCTRL3 |= TMR_CSCTRL_TCF1EN;} - #define FUEL1_TIMER_DISABLE() TMR1_CSCTRL0 &= ~TMR_CSCTRL_TCF1EN //Write 0 to the TCFIEN (Channel Interrupt Enable) bit of channel 0 Status/Control - #define FUEL2_TIMER_DISABLE() TMR1_CSCTRL1 &= ~TMR_CSCTRL_TCF1EN - #define FUEL3_TIMER_DISABLE() TMR1_CSCTRL2 &= ~TMR_CSCTRL_TCF1EN - #define FUEL4_TIMER_DISABLE() TMR1_CSCTRL3 &= ~TMR_CSCTRL_TCF1EN - #define FUEL5_TIMER_DISABLE() TMR3_CSCTRL0 &= ~TMR_CSCTRL_TCF1EN - #define FUEL6_TIMER_DISABLE() TMR3_CSCTRL1 &= ~TMR_CSCTRL_TCF1EN - #define FUEL7_TIMER_DISABLE() TMR3_CSCTRL2 &= ~TMR_CSCTRL_TCF1EN - #define FUEL8_TIMER_DISABLE() TMR3_CSCTRL3 &= ~TMR_CSCTRL_TCF1EN + static inline void FUEL1_TIMER_DISABLE(void) {TMR1_CSCTRL0 &= ~TMR_CSCTRL_TCF1EN;} //Write 0 to the TCFIEN (Channel Interrupt Enable) bit of channel 0 Status/Control + static inline void FUEL2_TIMER_DISABLE(void) {TMR1_CSCTRL1 &= ~TMR_CSCTRL_TCF1EN;} + static inline void FUEL3_TIMER_DISABLE(void) {TMR1_CSCTRL2 &= ~TMR_CSCTRL_TCF1EN;} + static inline void FUEL4_TIMER_DISABLE(void) {TMR1_CSCTRL3 &= ~TMR_CSCTRL_TCF1EN;} + static inline void FUEL5_TIMER_DISABLE(void) {TMR3_CSCTRL0 &= ~TMR_CSCTRL_TCF1EN;} + static inline void FUEL6_TIMER_DISABLE(void) {TMR3_CSCTRL1 &= ~TMR_CSCTRL_TCF1EN;} + static inline void FUEL7_TIMER_DISABLE(void) {TMR3_CSCTRL2 &= ~TMR_CSCTRL_TCF1EN;} + static inline void FUEL8_TIMER_DISABLE(void) {TMR3_CSCTRL3 &= ~TMR_CSCTRL_TCF1EN;} - #define IGN1_TIMER_ENABLE() TMR2_CSCTRL0 |= TMR_CSCTRL_TCF1EN - #define IGN2_TIMER_ENABLE() TMR2_CSCTRL1 |= TMR_CSCTRL_TCF1EN - #define IGN3_TIMER_ENABLE() TMR2_CSCTRL2 |= TMR_CSCTRL_TCF1EN - #define IGN4_TIMER_ENABLE() TMR2_CSCTRL3 |= TMR_CSCTRL_TCF1EN - #define IGN5_TIMER_ENABLE() TMR4_CSCTRL0 |= TMR_CSCTRL_TCF1EN - #define IGN6_TIMER_ENABLE() TMR4_CSCTRL1 |= TMR_CSCTRL_TCF1EN - #define IGN7_TIMER_ENABLE() TMR4_CSCTRL2 |= TMR_CSCTRL_TCF1EN - #define IGN8_TIMER_ENABLE() TMR4_CSCTRL3 |= TMR_CSCTRL_TCF1EN + static inline void IGN1_TIMER_ENABLE(void) {TMR2_CSCTRL0 |= TMR_CSCTRL_TCF1EN;} + static inline void IGN2_TIMER_ENABLE(void) {TMR2_CSCTRL1 |= TMR_CSCTRL_TCF1EN;} + static inline void IGN3_TIMER_ENABLE(void) {TMR2_CSCTRL2 |= TMR_CSCTRL_TCF1EN;} + static inline void IGN4_TIMER_ENABLE(void) {TMR2_CSCTRL3 |= TMR_CSCTRL_TCF1EN;} + static inline void IGN5_TIMER_ENABLE(void) {TMR4_CSCTRL0 |= TMR_CSCTRL_TCF1EN;} + static inline void IGN6_TIMER_ENABLE(void) {TMR4_CSCTRL1 |= TMR_CSCTRL_TCF1EN;} + static inline void IGN7_TIMER_ENABLE(void) {TMR4_CSCTRL2 |= TMR_CSCTRL_TCF1EN;} + static inline void IGN8_TIMER_ENABLE(void) {TMR4_CSCTRL3 |= TMR_CSCTRL_TCF1EN;} - #define IGN1_TIMER_DISABLE() TMR2_CSCTRL0 &= ~TMR_CSCTRL_TCF1EN - #define IGN2_TIMER_DISABLE() TMR2_CSCTRL1 &= ~TMR_CSCTRL_TCF1EN - #define IGN3_TIMER_DISABLE() TMR2_CSCTRL2 &= ~TMR_CSCTRL_TCF1EN - #define IGN4_TIMER_DISABLE() TMR2_CSCTRL3 &= ~TMR_CSCTRL_TCF1EN - #define IGN5_TIMER_DISABLE() TMR4_CSCTRL0 &= ~TMR_CSCTRL_TCF1EN - #define IGN6_TIMER_DISABLE() TMR4_CSCTRL1 &= ~TMR_CSCTRL_TCF1EN - #define IGN7_TIMER_DISABLE() TMR4_CSCTRL2 &= ~TMR_CSCTRL_TCF1EN - #define IGN8_TIMER_DISABLE() TMR4_CSCTRL3 &= ~TMR_CSCTRL_TCF1EN + static inline void IGN1_TIMER_DISABLE(void) {TMR2_CSCTRL0 &= ~TMR_CSCTRL_TCF1EN;} + static inline void IGN2_TIMER_DISABLE(void) {TMR2_CSCTRL1 &= ~TMR_CSCTRL_TCF1EN;} + static inline void IGN3_TIMER_DISABLE(void) {TMR2_CSCTRL2 &= ~TMR_CSCTRL_TCF1EN;} + static inline void IGN4_TIMER_DISABLE(void) {TMR2_CSCTRL3 &= ~TMR_CSCTRL_TCF1EN;} + static inline void IGN5_TIMER_DISABLE(void) {TMR4_CSCTRL0 &= ~TMR_CSCTRL_TCF1EN;} + static inline void IGN6_TIMER_DISABLE(void) {TMR4_CSCTRL1 &= ~TMR_CSCTRL_TCF1EN;} + static inline void IGN7_TIMER_DISABLE(void) {TMR4_CSCTRL2 &= ~TMR_CSCTRL_TCF1EN;} + static inline void IGN8_TIMER_DISABLE(void) {TMR4_CSCTRL3 &= ~TMR_CSCTRL_TCF1EN;} //Bus Clock is 150Mhz @ 600 Mhz CPU. Need to handle this dynamically in the future for other frequencies //#define TMR_PRESCALE 128 diff --git a/speeduino/board_template.h b/speeduino/board_template.h index cdaf6c5d..13cc6c1c 100644 --- a/speeduino/board_template.h +++ b/speeduino/board_template.h @@ -67,45 +67,45 @@ #define IGN7_COMPARE #define IGN8_COMPARE - #define FUEL1_TIMER_ENABLE() - #define FUEL2_TIMER_ENABLE() - #define FUEL3_TIMER_ENABLE() - #define FUEL4_TIMER_ENABLE() + static inline void FUEL1_TIMER_ENABLE(void) {;} + static inline void FUEL2_TIMER_ENABLE(void) {;} + static inline void FUEL3_TIMER_ENABLE(void) {;} + static inline void FUEL4_TIMER_ENABLE(void) {;} //The below are optional, but recommended if there are sufficient timers/compares - #define FUEL5_TIMER_ENABLE() - #define FUEL6_TIMER_ENABLE() - #define FUEL7_TIMER_ENABLE() - #define FUEL8_TIMER_ENABLE() + static inline void FUEL5_TIMER_ENABLE(void) {;} + static inline void FUEL6_TIMER_ENABLE(void) {;} + static inline void FUEL7_TIMER_ENABLE(void) {;} + static inline void FUEL8_TIMER_ENABLE(void) {;} - #define FUEL1_TIMER_DISABLE() - #define FUEL2_TIMER_DISABLE() - #define FUEL3_TIMER_DISABLE() - #define FUEL4_TIMER_DISABLE() + static inline void FUEL1_TIMER_DISABLE(void) { ;} + static inline void FUEL2_TIMER_DISABLE(void) { ;} + static inline void FUEL3_TIMER_DISABLE(void) { ;} + static inline void FUEL4_TIMER_DISABLE(void) { ;} //The below are optional, but recommended if there are sufficient timers/compares - #define FUEL5_TIMER_DISABLE() - #define FUEL6_TIMER_DISABLE() - #define FUEL7_TIMER_DISABLE() - #define FUEL8_TIMER_DISABLE() + static inline void FUEL5_TIMER_DISABLE(void) { ;} + static inline void FUEL6_TIMER_DISABLE(void) { ;} + static inline void FUEL7_TIMER_DISABLE(void) { ;} + static inline void FUEL8_TIMER_DISABLE(void) { ;} - #define IGN1_TIMER_ENABLE() - #define IGN2_TIMER_ENABLE() - #define IGN3_TIMER_ENABLE() - #define IGN4_TIMER_ENABLE() + static inline void IGN1_TIMER_ENABLE(void) {;} + static inline void IGN2_TIMER_ENABLE(void) {;} + static inline void IGN3_TIMER_ENABLE(void) {;} + static inline void IGN4_TIMER_ENABLE(void) {;} //The below are optional, but recommended if there are sufficient timers/compares - #define IGN5_TIMER_ENABLE() - #define IGN6_TIMER_ENABLE() - #define IGN7_TIMER_ENABLE() - #define IGN8_TIMER_ENABLE() + static inline void IGN5_TIMER_ENABLE(void) {;} + static inline void IGN6_TIMER_ENABLE(void) {;} + static inline void IGN7_TIMER_ENABLE(void) {;} + static inline void IGN8_TIMER_ENABLE(void) {;} - #define IGN1_TIMER_DISABLE() - #define IGN2_TIMER_DISABLE() - #define IGN3_TIMER_DISABLE() - #define IGN4_TIMER_DISABLE() - //The below are optional, but recommended if there are sufficient timers/compares - #define IGN5_TIMER_DISABLE() - #define IGN6_TIMER_DISABLE() - #define IGN7_TIMER_DISABLE() - #define IGN8_TIMER_DISABLE() + static inline void IGN1_TIMER_DISABLE(void) {;} + static inline void IGN2_TIMER_DISABLE(void) {;} + static inline void IGN3_TIMER_DISABLE(void) {;} + static inline void IGN4_TIMER_DISABLE(void) {;} + //The below are optional, but recommended if there are suffici;}ent timers/compares + static inline void IGN5_TIMER_DISABLE(void) {;} + static inline void IGN6_TIMER_DISABLE(void) {;} + static inline void IGN7_TIMER_DISABLE(void) {;} + static inline void IGN8_TIMER_DISABLE(void) {;} #define MAX_TIMER_PERIOD 139808 //This is the maximum time, in uS, that the compare channels can run before overflowing. It is typically 65535 * @@ -117,7 +117,7 @@ */ //macro functions for enabling and disabling timer interrupts for the boost and vvt functions #define ENABLE_BOOST_TIMER() - #define DISABLE_BOOST_TIMER() + #define DISABLE_BOOST_TIMER(void) { #define ENABLE_VVT_TIMER() #define DISABLE_VVT_TIMER() diff --git a/speeduino/init.cpp b/speeduino/init.cpp index b0672443..9bd3d616 100644 --- a/speeduino/init.cpp +++ b/speeduino/init.cpp @@ -984,17 +984,17 @@ void initialiseAll(void) { case INJ_PAIRED: //Paired injection - inj1StartFunction = openInjector1; - inj1EndFunction = closeInjector1; - inj2StartFunction = openInjector2; - inj2EndFunction = closeInjector2; - inj3StartFunction = openInjector3; - inj3EndFunction = closeInjector3; - inj4StartFunction = openInjector4; - inj4EndFunction = closeInjector4; -#if (INJ_CHANNELS >= 5) - inj5StartFunction = openInjector5; - inj5EndFunction = closeInjector5; + fuelSchedule1.pStartFunction = openInjector1; + fuelSchedule1.pEndFunction = closeInjector1; + fuelSchedule2.pStartFunction = openInjector2; + fuelSchedule2.pEndFunction = closeInjector2; + fuelSchedule3.pStartFunction = openInjector3; + fuelSchedule3.pEndFunction = closeInjector3; + fuelSchedule4.pStartFunction = openInjector4; + fuelSchedule4.pEndFunction = closeInjector4; +#if INJ_CHANNELS >= 5 + fuelSchedule5.pStartFunction = openInjector5; + fuelSchedule5.pEndFunction = closeInjector5; #endif break; @@ -1004,109 +1004,109 @@ void initialiseAll(void) { if(configPage4.inj4cylPairing == INJ_PAIR_13_24) { - inj1StartFunction = openInjector1and3; - inj1EndFunction = closeInjector1and3; - inj2StartFunction = openInjector2and4; - inj2EndFunction = closeInjector2and4; + fuelSchedule1.pStartFunction = openInjector1and3; + fuelSchedule1.pEndFunction = closeInjector1and3; + fuelSchedule2.pStartFunction = openInjector2and4; + fuelSchedule2.pEndFunction = closeInjector2and4; } else { - inj1StartFunction = openInjector1and4; - inj1EndFunction = closeInjector1and4; - inj2StartFunction = openInjector2and3; - inj2EndFunction = closeInjector2and3; + fuelSchedule1.pStartFunction = openInjector1and4; + fuelSchedule1.pEndFunction = closeInjector1and4; + fuelSchedule2.pStartFunction = openInjector2and3; + fuelSchedule2.pEndFunction = closeInjector2and3; } } else if( configPage2.nCylinders == 5 ) //This is similar to the paired injection but uses five injector outputs instead of four { - inj1StartFunction = openInjector1; - inj1EndFunction = closeInjector1; - inj2StartFunction = openInjector2; - inj2EndFunction = closeInjector2; - inj3StartFunction = openInjector3and5; - inj3EndFunction = closeInjector3and5; - inj4StartFunction = openInjector4; - inj4EndFunction = closeInjector4; + fuelSchedule1.pStartFunction = openInjector1; + fuelSchedule1.pEndFunction = closeInjector1; + fuelSchedule2.pStartFunction = openInjector2; + fuelSchedule2.pEndFunction = closeInjector2; + fuelSchedule3.pStartFunction = openInjector3and5; + fuelSchedule3.pEndFunction = closeInjector3and5; + fuelSchedule4.pStartFunction = openInjector4; + fuelSchedule4.pEndFunction = closeInjector4; } else if( configPage2.nCylinders == 6 ) { - inj1StartFunction = openInjector1and4; - inj1EndFunction = closeInjector1and4; - inj2StartFunction = openInjector2and5; - inj2EndFunction = closeInjector2and5; - inj3StartFunction = openInjector3and6; - inj3EndFunction = closeInjector3and6; + fuelSchedule1.pStartFunction = openInjector1and4; + fuelSchedule1.pEndFunction = closeInjector1and4; + fuelSchedule2.pStartFunction = openInjector2and5; + fuelSchedule2.pEndFunction = closeInjector2and5; + fuelSchedule3.pStartFunction = openInjector3and6; + fuelSchedule3.pEndFunction = closeInjector3and6; } else if( configPage2.nCylinders == 8 ) { - inj1StartFunction = openInjector1and5; - inj1EndFunction = closeInjector1and5; - inj2StartFunction = openInjector2and6; - inj2EndFunction = closeInjector2and6; - inj3StartFunction = openInjector3and7; - inj3EndFunction = closeInjector3and7; - inj4StartFunction = openInjector4and8; - inj4EndFunction = closeInjector4and8; + fuelSchedule1.pStartFunction = openInjector1and5; + fuelSchedule1.pEndFunction = closeInjector1and5; + fuelSchedule2.pStartFunction = openInjector2and6; + fuelSchedule2.pEndFunction = closeInjector2and6; + fuelSchedule3.pStartFunction = openInjector3and7; + fuelSchedule3.pEndFunction = closeInjector3and7; + fuelSchedule4.pStartFunction = openInjector4and8; + fuelSchedule4.pEndFunction = closeInjector4and8; } else { //Fall back to paired injection - inj1StartFunction = openInjector1; - inj1EndFunction = closeInjector1; - inj2StartFunction = openInjector2; - inj2EndFunction = closeInjector2; - inj3StartFunction = openInjector3; - inj3EndFunction = closeInjector3; - inj4StartFunction = openInjector4; - inj4EndFunction = closeInjector4; -#if (INJ_CHANNELS >= 5) - inj5StartFunction = openInjector5; - inj5EndFunction = closeInjector5; + fuelSchedule1.pStartFunction = openInjector1; + fuelSchedule1.pEndFunction = closeInjector1; + fuelSchedule2.pStartFunction = openInjector2; + fuelSchedule2.pEndFunction = closeInjector2; + fuelSchedule3.pStartFunction = openInjector3; + fuelSchedule3.pEndFunction = closeInjector3; + fuelSchedule4.pStartFunction = openInjector4; + fuelSchedule4.pEndFunction = closeInjector4; +#if INJ_CHANNELS >= 5 + fuelSchedule5.pStartFunction = openInjector5; + fuelSchedule5.pEndFunction = closeInjector5; #endif } break; case INJ_SEQUENTIAL: //Sequential injection - inj1StartFunction = openInjector1; - inj1EndFunction = closeInjector1; - inj2StartFunction = openInjector2; - inj2EndFunction = closeInjector2; - inj3StartFunction = openInjector3; - inj3EndFunction = closeInjector3; - inj4StartFunction = openInjector4; - inj4EndFunction = closeInjector4; -#if (INJ_CHANNELS >= 5) - inj5StartFunction = openInjector5; - inj5EndFunction = closeInjector5; + fuelSchedule1.pStartFunction = openInjector1; + fuelSchedule1.pEndFunction = closeInjector1; + fuelSchedule2.pStartFunction = openInjector2; + fuelSchedule2.pEndFunction = closeInjector2; + fuelSchedule3.pStartFunction = openInjector3; + fuelSchedule3.pEndFunction = closeInjector3; + fuelSchedule4.pStartFunction = openInjector4; + fuelSchedule4.pEndFunction = closeInjector4; +#if INJ_CHANNELS >= 5 + fuelSchedule5.pStartFunction = openInjector5; + fuelSchedule5.pEndFunction = closeInjector5; #endif -#if (INJ_CHANNELS >= 6) - inj6StartFunction = openInjector6; - inj6EndFunction = closeInjector6; +#if INJ_CHANNELS >= 6 + fuelSchedule6.pStartFunction = openInjector6; + fuelSchedule6.pEndFunction = closeInjector6; #endif -#if (INJ_CHANNELS >= 7) - inj7StartFunction = openInjector7; - inj7EndFunction = closeInjector7; +#if INJ_CHANNELS >= 7 + fuelSchedule7.pStartFunction = openInjector7; + fuelSchedule7.pEndFunction = closeInjector7; #endif -#if (INJ_CHANNELS >= 8) - inj8StartFunction = openInjector8; - inj8EndFunction = closeInjector8; +#if INJ_CHANNELS >= 8 + fuelSchedule8.pStartFunction = openInjector8; + fuelSchedule8.pEndFunction = closeInjector8; #endif break; default: //Paired injection - inj1StartFunction = openInjector1; - inj1EndFunction = closeInjector1; - inj2StartFunction = openInjector2; - inj2EndFunction = closeInjector2; - inj3StartFunction = openInjector3; - inj3EndFunction = closeInjector3; - inj4StartFunction = openInjector4; - inj4EndFunction = closeInjector4; -#if (INJ_CHANNELS >= 5) - inj5StartFunction = openInjector5; - inj5EndFunction = closeInjector5; + fuelSchedule1.pStartFunction = openInjector1; + fuelSchedule1.pEndFunction = closeInjector1; + fuelSchedule2.pStartFunction = openInjector2; + fuelSchedule2.pEndFunction = closeInjector2; + fuelSchedule3.pStartFunction = openInjector3; + fuelSchedule3.pEndFunction = closeInjector3; + fuelSchedule4.pStartFunction = openInjector4; + fuelSchedule4.pEndFunction = closeInjector4; +#if INJ_CHANNELS >= 5 + fuelSchedule5.pStartFunction = openInjector5; + fuelSchedule5.pEndFunction = closeInjector5; #endif break; } @@ -1115,43 +1115,43 @@ void initialiseAll(void) { case IGN_MODE_WASTED: //Wasted Spark (Normal mode) - ign1StartFunction = beginCoil1Charge; - ign1EndFunction = endCoil1Charge; - ign2StartFunction = beginCoil2Charge; - ign2EndFunction = endCoil2Charge; - ign3StartFunction = beginCoil3Charge; - ign3EndFunction = endCoil3Charge; - ign4StartFunction = beginCoil4Charge; - ign4EndFunction = endCoil4Charge; - ign5StartFunction = beginCoil5Charge; - ign5EndFunction = endCoil5Charge; + ignitionSchedule1.pStartCallback = beginCoil1Charge; + ignitionSchedule1.pEndCallback = endCoil1Charge; + ignitionSchedule2.pStartCallback = beginCoil2Charge; + ignitionSchedule2.pEndCallback = endCoil2Charge; + ignitionSchedule3.pStartCallback = beginCoil3Charge; + ignitionSchedule3.pEndCallback = endCoil3Charge; + ignitionSchedule4.pStartCallback = beginCoil4Charge; + ignitionSchedule4.pEndCallback = endCoil4Charge; + ignitionSchedule5.pStartCallback = beginCoil5Charge; + ignitionSchedule5.pEndCallback = endCoil5Charge; break; case IGN_MODE_SINGLE: //Single channel mode. All ignition pulses are on channel 1 - ign1StartFunction = beginCoil1Charge; - ign1EndFunction = endCoil1Charge; - ign2StartFunction = beginCoil1Charge; - ign2EndFunction = endCoil1Charge; - ign3StartFunction = beginCoil1Charge; - ign3EndFunction = endCoil1Charge; - ign4StartFunction = beginCoil1Charge; - ign4EndFunction = endCoil1Charge; -#if (INJ_CHANNELS >= 5) - ign5StartFunction = beginCoil1Charge; - ign5EndFunction = endCoil1Charge; + ignitionSchedule1.pStartCallback = beginCoil1Charge; + ignitionSchedule1.pEndCallback = endCoil1Charge; + ignitionSchedule2.pStartCallback = beginCoil1Charge; + ignitionSchedule2.pEndCallback = endCoil1Charge; + ignitionSchedule3.pStartCallback = beginCoil1Charge; + ignitionSchedule3.pEndCallback = endCoil1Charge; + ignitionSchedule4.pStartCallback = beginCoil1Charge; + ignitionSchedule4.pEndCallback = endCoil1Charge; +#if IGN_CHANNELS >= 5 + ignitionSchedule5.pStartCallback = beginCoil1Charge; + ignitionSchedule5.pEndCallback = endCoil1Charge; #endif -#if (INJ_CHANNELS >= 6) - ign6StartFunction = beginCoil1Charge; - ign6EndFunction = endCoil1Charge; +#if IGN_CHANNELS >= 6 + ignitionSchedule6.pStartCallback = beginCoil1Charge; + ignitionSchedule6.pEndCallback = endCoil1Charge; #endif -#if (INJ_CHANNELS >= 7) - ign7StartFunction = beginCoil1Charge; - ign7EndFunction = endCoil1Charge; +#if IGN_CHANNELS >= 7 + ignitionSchedule7.pStartCallback = beginCoil1Charge; + ignitionSchedule7.pEndCallback = endCoil1Charge; #endif -#if (INJ_CHANNELS >= 5) - ign8StartFunction = beginCoil1Charge; - ign8EndFunction = endCoil1Charge; +#if IGN_CHANNELS >= 8 + ignitionSchedule8.pStartCallback = beginCoil1Charge; + ignitionSchedule8.pEndCallback = endCoil1Charge; #endif break; @@ -1160,118 +1160,132 @@ void initialiseAll(void) //Wasted COP mode for 4 cylinders. Ignition channels 1&3 and 2&4 are paired together if( configPage2.nCylinders <= 4 ) { - ign1StartFunction = beginCoil1and3Charge; - ign1EndFunction = endCoil1and3Charge; - ign2StartFunction = beginCoil2and4Charge; - ign2EndFunction = endCoil2and4Charge; + ignitionSchedule1.pStartCallback = beginCoil1and3Charge; + ignitionSchedule1.pEndCallback = endCoil1and3Charge; + ignitionSchedule2.pStartCallback = beginCoil2and4Charge; + ignitionSchedule2.pEndCallback = endCoil2and4Charge; - ign3StartFunction = nullCallback; - ign3EndFunction = nullCallback; - ign4StartFunction = nullCallback; - ign4EndFunction = nullCallback; + ignitionSchedule3.pStartCallback = nullCallback; + ignitionSchedule3.pEndCallback = nullCallback; + ignitionSchedule4.pStartCallback = nullCallback; + ignitionSchedule4.pEndCallback = nullCallback; } //Wasted COP mode for 6 cylinders. Ignition channels 1&4, 2&5 and 3&6 are paired together else if( configPage2.nCylinders == 6 ) { - ign1StartFunction = beginCoil1and4Charge; - ign1EndFunction = endCoil1and4Charge; - ign2StartFunction = beginCoil2and5Charge; - ign2EndFunction = endCoil2and5Charge; - ign3StartFunction = beginCoil3and6Charge; - ign3EndFunction = endCoil3and6Charge; + ignitionSchedule1.pStartCallback = beginCoil1and4Charge; + ignitionSchedule1.pEndCallback = endCoil1and4Charge; + ignitionSchedule2.pStartCallback = beginCoil2and5Charge; + ignitionSchedule2.pEndCallback = endCoil2and5Charge; + ignitionSchedule3.pStartCallback = beginCoil3and6Charge; + ignitionSchedule3.pEndCallback = endCoil3and6Charge; - ign4StartFunction = nullCallback; - ign4EndFunction = nullCallback; - ign5StartFunction = nullCallback; - ign5EndFunction = nullCallback; - ign6StartFunction = nullCallback; - ign6EndFunction = nullCallback; + ignitionSchedule4.pStartCallback = nullCallback; + ignitionSchedule4.pEndCallback = nullCallback; + ignitionSchedule5.pStartCallback = nullCallback; + ignitionSchedule5.pEndCallback = nullCallback; +#if IGN_CHANNELS >= 6 + ignitionSchedule6.pStartCallback = nullCallback; + ignitionSchedule6.pEndCallback = nullCallback; +#endif } //Wasted COP mode for 8 cylinders. Ignition channels 1&5, 2&6, 3&7 and 4&8 are paired together else if( configPage2.nCylinders == 8 ) { - ign1StartFunction = beginCoil1and5Charge; - ign1EndFunction = endCoil1and5Charge; - ign2StartFunction = beginCoil2and6Charge; - ign2EndFunction = endCoil2and6Charge; - ign3StartFunction = beginCoil3and7Charge; - ign3EndFunction = endCoil3and7Charge; - ign4StartFunction = beginCoil4and8Charge; - ign4EndFunction = endCoil4and8Charge; + ignitionSchedule1.pStartCallback = beginCoil1and5Charge; + ignitionSchedule1.pEndCallback = endCoil1and5Charge; + ignitionSchedule2.pStartCallback = beginCoil2and6Charge; + ignitionSchedule2.pEndCallback = endCoil2and6Charge; + ignitionSchedule3.pStartCallback = beginCoil3and7Charge; + ignitionSchedule3.pEndCallback = endCoil3and7Charge; + ignitionSchedule4.pStartCallback = beginCoil4and8Charge; + ignitionSchedule4.pEndCallback = endCoil4and8Charge; - ign5StartFunction = nullCallback; - ign5EndFunction = nullCallback; - ign6StartFunction = nullCallback; - ign6EndFunction = nullCallback; - ign7StartFunction = nullCallback; - ign7EndFunction = nullCallback; - ign8StartFunction = nullCallback; - ign8EndFunction = nullCallback; + ignitionSchedule5.pStartCallback = nullCallback; + ignitionSchedule5.pEndCallback = nullCallback; +#if IGN_CHANNELS >= 6 + ignitionSchedule6.pStartCallback = nullCallback; + ignitionSchedule6.pEndCallback = nullCallback; +#endif +#if IGN_CHANNELS >= 7 + ignitionSchedule7.pStartCallback = nullCallback; + ignitionSchedule7.pEndCallback = nullCallback; +#endif +#if IGN_CHANNELS >= 8 + ignitionSchedule8.pStartCallback = nullCallback; + ignitionSchedule8.pEndCallback = nullCallback; +#endif } else { //If the person has inadvertently selected this when running more than 4 cylinders or other than 6 cylinders, just use standard Wasted spark mode - ign1StartFunction = beginCoil1Charge; - ign1EndFunction = endCoil1Charge; - ign2StartFunction = beginCoil2Charge; - ign2EndFunction = endCoil2Charge; - ign3StartFunction = beginCoil3Charge; - ign3EndFunction = endCoil3Charge; - ign4StartFunction = beginCoil4Charge; - ign4EndFunction = endCoil4Charge; - ign5StartFunction = beginCoil5Charge; - ign5EndFunction = endCoil5Charge; + ignitionSchedule1.pStartCallback = beginCoil1Charge; + ignitionSchedule1.pEndCallback = endCoil1Charge; + ignitionSchedule2.pStartCallback = beginCoil2Charge; + ignitionSchedule2.pEndCallback = endCoil2Charge; + ignitionSchedule3.pStartCallback = beginCoil3Charge; + ignitionSchedule3.pEndCallback = endCoil3Charge; + ignitionSchedule4.pStartCallback = beginCoil4Charge; + ignitionSchedule4.pEndCallback = endCoil4Charge; + ignitionSchedule5.pStartCallback = beginCoil5Charge; + ignitionSchedule5.pEndCallback = endCoil5Charge; } break; case IGN_MODE_SEQUENTIAL: - ign1StartFunction = beginCoil1Charge; - ign1EndFunction = endCoil1Charge; - ign2StartFunction = beginCoil2Charge; - ign2EndFunction = endCoil2Charge; - ign3StartFunction = beginCoil3Charge; - ign3EndFunction = endCoil3Charge; - ign4StartFunction = beginCoil4Charge; - ign4EndFunction = endCoil4Charge; - ign5StartFunction = beginCoil5Charge; - ign5EndFunction = endCoil5Charge; - ign6StartFunction = beginCoil6Charge; - ign6EndFunction = endCoil6Charge; - ign7StartFunction = beginCoil7Charge; - ign7EndFunction = endCoil7Charge; - ign8StartFunction = beginCoil8Charge; - ign8EndFunction = endCoil8Charge; + ignitionSchedule1.pStartCallback = beginCoil1Charge; + ignitionSchedule1.pEndCallback = endCoil1Charge; + ignitionSchedule2.pStartCallback = beginCoil2Charge; + ignitionSchedule2.pEndCallback = endCoil2Charge; + ignitionSchedule3.pStartCallback = beginCoil3Charge; + ignitionSchedule3.pEndCallback = endCoil3Charge; + ignitionSchedule4.pStartCallback = beginCoil4Charge; + ignitionSchedule4.pEndCallback = endCoil4Charge; + ignitionSchedule5.pStartCallback = beginCoil5Charge; + ignitionSchedule5.pEndCallback = endCoil5Charge; +#if IGN_CHANNELS >= 6 + ignitionSchedule6.pStartCallback = beginCoil6Charge; + ignitionSchedule6.pEndCallback = endCoil6Charge; +#endif +#if IGN_CHANNELS >= 7 + ignitionSchedule7.pStartCallback = beginCoil7Charge; + ignitionSchedule7.pEndCallback = endCoil7Charge; +#endif +#if IGN_CHANNELS >= 8 + ignitionSchedule8.pStartCallback = beginCoil8Charge; + ignitionSchedule8.pEndCallback = endCoil8Charge; +#endif break; case IGN_MODE_ROTARY: if(configPage10.rotaryType == ROTARY_IGN_FC) { //Ignition channel 1 is a wasted spark signal for leading signal on both rotors - ign1StartFunction = beginCoil1Charge; - ign1EndFunction = endCoil1Charge; - ign2StartFunction = beginCoil1Charge; - ign2EndFunction = endCoil1Charge; + ignitionSchedule1.pStartCallback = beginCoil1Charge; + ignitionSchedule1.pEndCallback = endCoil1Charge; + ignitionSchedule2.pStartCallback = beginCoil1Charge; + ignitionSchedule2.pEndCallback = endCoil1Charge; - ign3StartFunction = beginTrailingCoilCharge; - ign3EndFunction = endTrailingCoilCharge1; - ign4StartFunction = beginTrailingCoilCharge; - ign4EndFunction = endTrailingCoilCharge2; + ignitionSchedule3.pStartCallback = beginTrailingCoilCharge; + ignitionSchedule3.pEndCallback = endTrailingCoilCharge1; + ignitionSchedule4.pStartCallback = beginTrailingCoilCharge; + ignitionSchedule4.pEndCallback = endTrailingCoilCharge2; } else if(configPage10.rotaryType == ROTARY_IGN_FD) { //Ignition channel 1 is a wasted spark signal for leading signal on both rotors - ign1StartFunction = beginCoil1Charge; - ign1EndFunction = endCoil1Charge; - ign2StartFunction = beginCoil1Charge; - ign2EndFunction = endCoil1Charge; + ignitionSchedule1.pStartCallback = beginCoil1Charge; + ignitionSchedule1.pEndCallback = endCoil1Charge; + ignitionSchedule2.pStartCallback = beginCoil1Charge; + ignitionSchedule2.pEndCallback = endCoil1Charge; //Trailing coils have their own channel each //IGN2 = front rotor trailing spark - ign3StartFunction = beginCoil2Charge; - ign3EndFunction = endCoil2Charge; + ignitionSchedule3.pStartCallback = beginCoil2Charge; + ignitionSchedule3.pEndCallback = endCoil2Charge; //IGN3 = rear rotor trailing spark - ign4StartFunction = beginCoil3Charge; - ign4EndFunction = endCoil3Charge; + ignitionSchedule4.pStartCallback = beginCoil3Charge; + ignitionSchedule4.pEndCallback = endCoil3Charge; //IGN4 not used } @@ -1280,33 +1294,33 @@ void initialiseAll(void) //RX8 outputs are simply 1 coil and 1 output per plug //IGN1 is front rotor, leading spark - ign1StartFunction = beginCoil1Charge; - ign1EndFunction = endCoil1Charge; + ignitionSchedule1.pStartCallback = beginCoil1Charge; + ignitionSchedule1.pEndCallback = endCoil1Charge; //IGN2 is rear rotor, leading spark - ign2StartFunction = beginCoil2Charge; - ign2EndFunction = endCoil2Charge; + ignitionSchedule2.pStartCallback = beginCoil2Charge; + ignitionSchedule2.pEndCallback = endCoil2Charge; //IGN3 = front rotor trailing spark - ign3StartFunction = beginCoil3Charge; - ign3EndFunction = endCoil3Charge; + ignitionSchedule3.pStartCallback = beginCoil3Charge; + ignitionSchedule3.pEndCallback = endCoil3Charge; //IGN4 = rear rotor trailing spark - ign4StartFunction = beginCoil4Charge; - ign4EndFunction = endCoil4Charge; + ignitionSchedule4.pStartCallback = beginCoil4Charge; + ignitionSchedule4.pEndCallback = endCoil4Charge; } else { } //No action for other RX ignition modes (Future expansion / MISRA compliant). break; default: //Wasted spark (Shouldn't ever happen anyway) - ign1StartFunction = beginCoil1Charge; - ign1EndFunction = endCoil1Charge; - ign2StartFunction = beginCoil2Charge; - ign2EndFunction = endCoil2Charge; - ign3StartFunction = beginCoil3Charge; - ign3EndFunction = endCoil3Charge; - ign4StartFunction = beginCoil4Charge; - ign4EndFunction = endCoil4Charge; - ign5StartFunction = beginCoil5Charge; - ign5EndFunction = endCoil5Charge; + ignitionSchedule1.pStartCallback = beginCoil1Charge; + ignitionSchedule1.pEndCallback = endCoil1Charge; + ignitionSchedule2.pStartCallback = beginCoil2Charge; + ignitionSchedule2.pEndCallback = endCoil2Charge; + ignitionSchedule3.pStartCallback = beginCoil3Charge; + ignitionSchedule3.pEndCallback = endCoil3Charge; + ignitionSchedule4.pStartCallback = beginCoil4Charge; + ignitionSchedule4.pEndCallback = endCoil4Charge; + ignitionSchedule5.pStartCallback = beginCoil5Charge; + ignitionSchedule5.pEndCallback = endCoil5Charge; break; } @@ -3603,6 +3617,26 @@ void initialiseTriggers(void) } } +static inline bool isAnyFuelScheduleRunning(void) { + return fuelSchedule1.Status==RUNNING + || fuelSchedule2.Status==RUNNING + || fuelSchedule3.Status==RUNNING + || fuelSchedule4.Status==RUNNING +#if INJ_CHANNELS >= 5 + || fuelSchedule5.Status==RUNNING +#endif +#if INJ_CHANNELS >= 6 + || fuelSchedule6.Status==RUNNING +#endif +#if INJ_CHANNELS >= 7 + || fuelSchedule7.Status==RUNNING +#endif +#if INJ_CHANNELS >= 8 + || fuelSchedule8.Status==RUNNING +#endif + ; +} + /** Change injectors or/and ignition angles to 720deg. * Roll back req_fuel size and set number of outputs equal to cylinder count. * */ @@ -3610,35 +3644,34 @@ void changeHalfToFullSync(void) { //Need to do another check for injLayout as this function can be called from ignition noInterrupts(); - if( (configPage2.injLayout == INJ_SEQUENTIAL) && (CRANK_ANGLE_MAX_INJ != 720) && fuelSchedule1.Status!=RUNNING && fuelSchedule2.Status!=RUNNING && fuelSchedule3.Status!=RUNNING && fuelSchedule4.Status!=RUNNING && - fuelSchedule5.Status!=RUNNING && fuelSchedule6.Status!=RUNNING && fuelSchedule7.Status!=RUNNING && fuelSchedule8.Status!=RUNNING) + if( (configPage2.injLayout == INJ_SEQUENTIAL) && (CRANK_ANGLE_MAX_INJ != 720) && (!isAnyFuelScheduleRunning())) { CRANK_ANGLE_MAX_INJ = 720; req_fuel_uS *= 2; - - inj1StartFunction = openInjector1; - inj1EndFunction = closeInjector1; - inj2StartFunction = openInjector2; - inj2EndFunction = closeInjector2; - inj3StartFunction = openInjector3; - inj3EndFunction = closeInjector3; - inj4StartFunction = openInjector4; - inj4EndFunction = closeInjector4; -#if (INJ_CHANNELS >= 5) - inj5StartFunction = openInjector5; - inj5EndFunction = closeInjector5; + + fuelSchedule1.pStartFunction = openInjector1; + fuelSchedule1.pEndFunction = closeInjector1; + fuelSchedule2.pStartFunction = openInjector2; + fuelSchedule2.pEndFunction = closeInjector2; + fuelSchedule3.pStartFunction = openInjector3; + fuelSchedule3.pEndFunction = closeInjector3; + fuelSchedule4.pStartFunction = openInjector4; + fuelSchedule4.pEndFunction = closeInjector4; +#if INJ_CHANNELS >= 5 + fuelSchedule5.pStartFunction = openInjector5; + fuelSchedule5.pEndFunction = closeInjector5; #endif -#if (INJ_CHANNELS >= 6) - inj6StartFunction = openInjector6; - inj6EndFunction = closeInjector6; +#if INJ_CHANNELS >= 6 + fuelSchedule6.pStartFunction = openInjector6; + fuelSchedule6.pEndFunction = closeInjector6; #endif -#if (INJ_CHANNELS >= 7) - inj7StartFunction = openInjector7; - inj7EndFunction = closeInjector7; +#if INJ_CHANNELS >= 6 + fuelSchedule7.pStartFunction = openInjector7; + fuelSchedule7.pEndFunction = closeInjector7; #endif -#if (INJ_CHANNELS >= 8) - inj8StartFunction = openInjector8; - inj8EndFunction = closeInjector8; +#if INJ_CHANNELS >= 6 + fuelSchedule8.pStartFunction = openInjector8; + fuelSchedule8.pEndFunction = closeInjector8; #endif switch (configPage2.nCylinders) @@ -3670,30 +3703,30 @@ void changeHalfToFullSync(void) switch (configPage2.nCylinders) { case 4: - ign1StartFunction = beginCoil1Charge; - ign1EndFunction = endCoil1Charge; - ign2StartFunction = beginCoil2Charge; - ign2EndFunction = endCoil2Charge; + ignitionSchedule1.pStartCallback = beginCoil1Charge; + ignitionSchedule1.pEndCallback = endCoil1Charge; + ignitionSchedule2.pStartCallback = beginCoil2Charge; + ignitionSchedule2.pEndCallback = endCoil2Charge; break; case 6: - ign1StartFunction = beginCoil1Charge; - ign1EndFunction = endCoil1Charge; - ign2StartFunction = beginCoil2Charge; - ign2EndFunction = endCoil2Charge; - ign3StartFunction = beginCoil3Charge; - ign3EndFunction = endCoil3Charge; + ignitionSchedule1.pStartCallback = beginCoil1Charge; + ignitionSchedule1.pEndCallback = endCoil1Charge; + ignitionSchedule2.pStartCallback = beginCoil2Charge; + ignitionSchedule2.pEndCallback = endCoil2Charge; + ignitionSchedule3.pStartCallback = beginCoil3Charge; + ignitionSchedule3.pEndCallback = endCoil3Charge; break; case 8: - ign1StartFunction = beginCoil1Charge; - ign1EndFunction = endCoil1Charge; - ign2StartFunction = beginCoil2Charge; - ign2EndFunction = endCoil2Charge; - ign3StartFunction = beginCoil3Charge; - ign3EndFunction = endCoil3Charge; - ign4StartFunction = beginCoil4Charge; - ign4EndFunction = endCoil4Charge; + ignitionSchedule1.pStartCallback = beginCoil1Charge; + ignitionSchedule1.pEndCallback = endCoil1Charge; + ignitionSchedule2.pStartCallback = beginCoil2Charge; + ignitionSchedule2.pEndCallback = endCoil2Charge; + ignitionSchedule3.pStartCallback = beginCoil3Charge; + ignitionSchedule3.pEndCallback = endCoil3Charge; + ignitionSchedule4.pStartCallback = beginCoil4Charge; + ignitionSchedule4.pEndCallback = endCoil4Charge; break; default: @@ -3718,40 +3751,40 @@ void changeFullToHalfSync(void) case 4: if(configPage4.inj4cylPairing == INJ_PAIR_13_24) { - inj1StartFunction = openInjector1and3; - inj1EndFunction = closeInjector1and3; - inj2StartFunction = openInjector2and4; - inj2EndFunction = closeInjector2and4; + fuelSchedule1.pStartFunction = openInjector1and3; + fuelSchedule1.pEndFunction = closeInjector1and3; + fuelSchedule2.pStartFunction = openInjector2and4; + fuelSchedule2.pEndFunction = closeInjector2and4; } else { - inj1StartFunction = openInjector1and4; - inj1EndFunction = closeInjector1and4; - inj2StartFunction = openInjector2and3; - inj2EndFunction = closeInjector2and3; + fuelSchedule1.pStartFunction = openInjector1and4; + fuelSchedule1.pEndFunction = closeInjector1and4; + fuelSchedule2.pStartFunction = openInjector2and3; + fuelSchedule2.pEndFunction = closeInjector2and3; } maxInjOutputs = 2; break; case 6: - inj1StartFunction = openInjector1and4; - inj1EndFunction = closeInjector1and4; - inj2StartFunction = openInjector2and5; - inj2EndFunction = closeInjector2and5; - inj3StartFunction = openInjector3and6; - inj3EndFunction = closeInjector3and6; + fuelSchedule1.pStartFunction = openInjector1and4; + fuelSchedule1.pEndFunction = closeInjector1and4; + fuelSchedule2.pStartFunction = openInjector2and5; + fuelSchedule2.pEndFunction = closeInjector2and5; + fuelSchedule3.pStartFunction = openInjector3and6; + fuelSchedule3.pEndFunction = closeInjector3and6; maxInjOutputs = 3; break; case 8: - inj1StartFunction = openInjector1and5; - inj1EndFunction = closeInjector1and5; - inj2StartFunction = openInjector2and6; - inj2EndFunction = closeInjector2and6; - inj3StartFunction = openInjector3and7; - inj3EndFunction = closeInjector3and7; - inj4StartFunction = openInjector4and8; - inj4EndFunction = closeInjector4and8; + fuelSchedule1.pStartFunction = openInjector1and5; + fuelSchedule1.pEndFunction = closeInjector1and5; + fuelSchedule2.pStartFunction = openInjector2and6; + fuelSchedule2.pEndFunction = closeInjector2and6; + fuelSchedule3.pStartFunction = openInjector3and7; + fuelSchedule3.pEndFunction = closeInjector3and7; + fuelSchedule4.pStartFunction = openInjector4and8; + fuelSchedule4.pEndFunction = closeInjector4and8; maxInjOutputs = 4; break; } @@ -3764,30 +3797,30 @@ void changeFullToHalfSync(void) switch (configPage2.nCylinders) { case 4: - ign1StartFunction = beginCoil1and3Charge; - ign1EndFunction = endCoil1and3Charge; - ign2StartFunction = beginCoil2and4Charge; - ign2EndFunction = endCoil2and4Charge; + ignitionSchedule1.pStartCallback = beginCoil1and3Charge; + ignitionSchedule1.pEndCallback = endCoil1and3Charge; + ignitionSchedule2.pStartCallback = beginCoil2and4Charge; + ignitionSchedule2.pEndCallback = endCoil2and4Charge; break; case 6: - ign1StartFunction = beginCoil1and4Charge; - ign1EndFunction = endCoil1and4Charge; - ign2StartFunction = beginCoil2and5Charge; - ign2EndFunction = endCoil2and5Charge; - ign3StartFunction = beginCoil3and6Charge; - ign3EndFunction = endCoil3and6Charge; + ignitionSchedule1.pStartCallback = beginCoil1and4Charge; + ignitionSchedule1.pEndCallback = endCoil1and4Charge; + ignitionSchedule2.pStartCallback = beginCoil2and5Charge; + ignitionSchedule2.pEndCallback = endCoil2and5Charge; + ignitionSchedule3.pStartCallback = beginCoil3and6Charge; + ignitionSchedule3.pEndCallback = endCoil3and6Charge; break; case 8: - ign1StartFunction = beginCoil1and5Charge; - ign1EndFunction = endCoil1and5Charge; - ign2StartFunction = beginCoil2and6Charge; - ign2EndFunction = endCoil2and6Charge; - ign3StartFunction = beginCoil3and7Charge; - ign3EndFunction = endCoil3and7Charge; - ign4StartFunction = beginCoil4and8Charge; - ign4EndFunction = endCoil4and8Charge; + ignitionSchedule1.pStartCallback = beginCoil1and5Charge; + ignitionSchedule1.pEndCallback = endCoil1and5Charge; + ignitionSchedule2.pStartCallback = beginCoil2and6Charge; + ignitionSchedule2.pEndCallback = endCoil2and6Charge; + ignitionSchedule3.pStartCallback = beginCoil3and7Charge; + ignitionSchedule3.pEndCallback = endCoil3and7Charge; + ignitionSchedule4.pStartCallback = beginCoil4and8Charge; + ignitionSchedule4.pEndCallback = endCoil4and8Charge; break; } } diff --git a/speeduino/schedule_calcs.cpp b/speeduino/schedule_calcs.cpp index 8b79de1b..c7cb6b0f 100644 --- a/speeduino/schedule_calcs.cpp +++ b/speeduino/schedule_calcs.cpp @@ -1,7 +1,5 @@ #include "schedule_calcs.h" -byte channelInjEnabled = 0; - int ignition1StartAngle; int ignition1EndAngle; int channel1IgnDegrees; /**< The number of crank degrees until cylinder 1 is at TDC (This is obviously 0 for virtually ALL engines, but there's some weird ones) */ diff --git a/speeduino/schedule_calcs.h b/speeduino/schedule_calcs.h index eac5f09e..a60f6887 100644 --- a/speeduino/schedule_calcs.h +++ b/speeduino/schedule_calcs.h @@ -3,8 +3,6 @@ #include #include "scheduler.h" -extern byte channelInjEnabled; - extern int ignition1StartAngle; extern int ignition1EndAngle; extern int channel1IgnDegrees; /**< The number of crank degrees until cylinder 1 is at TDC (This is obviously 0 for virtually ALL engines, but there's some weird ones) */ @@ -68,6 +66,6 @@ inline void __attribute__((always_inline)) calculateIgnitionAngle(const int dwel // Ignition for rotary. inline void __attribute__((always_inline)) calculateIgnitionTrailingRotary(int dwellAngle, int rotarySplitDegrees, int leadIgnitionAngle, int *pEndAngle, int *pStartAngle); -inline uint32_t __attribute__((always_inline)) calculateIgnitionTimeout(const Schedule &schedule, int startAngle, int channelIgnDegrees, int crankAngle); +inline uint32_t __attribute__((always_inline)) calculateIgnitionTimeout(const IgnitionSchedule &schedule, int startAngle, int channelIgnDegrees, int crankAngle); -#include "schedule_calcs.hpp" \ No newline at end of file +#include "schedule_calcs.hpp" diff --git a/speeduino/schedule_calcs.hpp b/speeduino/schedule_calcs.hpp index 4f42b7ac..4b58134e 100644 --- a/speeduino/schedule_calcs.hpp +++ b/speeduino/schedule_calcs.hpp @@ -71,7 +71,7 @@ inline void calculateIgnitionTrailingRotary(int dwellAngle, int rotarySplitDegre if(*pStartAngle < 0) {*pStartAngle += CRANK_ANGLE_MAX_IGN;} } -inline uint32_t _calculateIgnitionTimeout(const Schedule &schedule, int16_t startAngle, int16_t crankAngle) { +inline uint32_t _calculateIgnitionTimeout(const IgnitionSchedule &schedule, int16_t startAngle, int16_t crankAngle) { int16_t delta = startAngle - crankAngle; if (delta<0) { @@ -94,7 +94,7 @@ static inline uint16_t _adjustToIgnChannel(int angle, int channelInjDegrees) { return angle; } -inline uint32_t calculateIgnitionTimeout(const Schedule &schedule, int startAngle, int channelIgnDegrees, int crankAngle) +inline uint32_t calculateIgnitionTimeout(const IgnitionSchedule &schedule, int startAngle, int channelIgnDegrees, int crankAngle) { if (channelIgnDegrees==0) { return _calculateIgnitionTimeout(schedule, startAngle, crankAngle); diff --git a/speeduino/scheduler.cpp b/speeduino/scheduler.cpp index 84526272..47d8f524 100644 --- a/speeduino/scheduler.cpp +++ b/speeduino/scheduler.cpp @@ -30,105 +30,81 @@ A full copy of the license may be found in the projects root directory #include "timers.h" #include "schedule_calcs.h" -FuelSchedule fuelSchedule1; -FuelSchedule fuelSchedule2; -FuelSchedule fuelSchedule3; -FuelSchedule fuelSchedule4; -FuelSchedule fuelSchedule5; -FuelSchedule fuelSchedule6; -FuelSchedule fuelSchedule7; -FuelSchedule fuelSchedule8; +FuelSchedule fuelSchedule1(FUEL1_COUNTER, FUEL1_COMPARE, FUEL1_TIMER_DISABLE, FUEL1_TIMER_ENABLE); +FuelSchedule fuelSchedule2(FUEL2_COUNTER, FUEL2_COMPARE, FUEL2_TIMER_DISABLE, FUEL2_TIMER_ENABLE); +FuelSchedule fuelSchedule3(FUEL3_COUNTER, FUEL3_COMPARE, FUEL3_TIMER_DISABLE, FUEL3_TIMER_ENABLE); +FuelSchedule fuelSchedule4(FUEL4_COUNTER, FUEL4_COMPARE, FUEL4_TIMER_DISABLE, FUEL4_TIMER_ENABLE); -Schedule ignitionSchedule1; -Schedule ignitionSchedule2; -Schedule ignitionSchedule3; -Schedule ignitionSchedule4; -Schedule ignitionSchedule5; -Schedule ignitionSchedule6; -Schedule ignitionSchedule7; -Schedule ignitionSchedule8; - -void (*inj1StartFunction)(void); -void (*inj1EndFunction)(void); -void (*inj2StartFunction)(void); -void (*inj2EndFunction)(void); -void (*inj3StartFunction)(void); -void (*inj3EndFunction)(void); -void (*inj4StartFunction)(void); -void (*inj4EndFunction)(void); #if (INJ_CHANNELS >= 5) -void (*inj5StartFunction)(void); -void (*inj5EndFunction)(void); +FuelSchedule fuelSchedule5(FUEL5_COUNTER, FUEL5_COMPARE, FUEL5_TIMER_DISABLE, FUEL5_TIMER_ENABLE); #endif #if (INJ_CHANNELS >= 6) -void (*inj6StartFunction)(void); -void (*inj6EndFunction)(void); +FuelSchedule fuelSchedule6(FUEL6_COUNTER, FUEL6_COMPARE, FUEL6_TIMER_DISABLE, FUEL6_TIMER_ENABLE); #endif #if (INJ_CHANNELS >= 7) -void (*inj7StartFunction)(void); -void (*inj7EndFunction)(void); +FuelSchedule fuelSchedule7(FUEL7_COUNTER, FUEL7_COMPARE, FUEL7_TIMER_DISABLE, FUEL7_TIMER_ENABLE); #endif #if (INJ_CHANNELS >= 8) -void (*inj8StartFunction)(void); -void (*inj8EndFunction)(void); +FuelSchedule fuelSchedule8(FUEL8_COUNTER, FUEL8_COMPARE, FUEL8_TIMER_DISABLE, FUEL8_TIMER_ENABLE); #endif -void (*ign1StartFunction)(void); -void (*ign1EndFunction)(void); -void (*ign2StartFunction)(void); -void (*ign2EndFunction)(void); -void (*ign3StartFunction)(void); -void (*ign3EndFunction)(void); -void (*ign4StartFunction)(void); -void (*ign4EndFunction)(void); -void (*ign5StartFunction)(void); -void (*ign5EndFunction)(void); -void (*ign6StartFunction)(void); -void (*ign6EndFunction)(void); -void (*ign7StartFunction)(void); -void (*ign7EndFunction)(void); -void (*ign8StartFunction)(void); -void (*ign8EndFunction)(void); +IgnitionSchedule ignitionSchedule1(IGN1_COUNTER, IGN1_COMPARE, IGN1_TIMER_DISABLE, IGN1_TIMER_ENABLE); +IgnitionSchedule ignitionSchedule2(IGN2_COUNTER, IGN2_COMPARE, IGN2_TIMER_DISABLE, IGN2_TIMER_ENABLE); +IgnitionSchedule ignitionSchedule3(IGN3_COUNTER, IGN3_COMPARE, IGN3_TIMER_DISABLE, IGN3_TIMER_ENABLE); +IgnitionSchedule ignitionSchedule4(IGN4_COUNTER, IGN4_COMPARE, IGN4_TIMER_DISABLE, IGN4_TIMER_ENABLE); +IgnitionSchedule ignitionSchedule5(IGN5_COUNTER, IGN5_COMPARE, IGN5_TIMER_DISABLE, IGN5_TIMER_ENABLE); -void initialiseSchedulers(void) +#if IGN_CHANNELS >= 6 +IgnitionSchedule ignitionSchedule6(IGN6_COUNTER, IGN6_COMPARE, IGN6_TIMER_DISABLE, IGN6_TIMER_ENABLE); +#endif +#if IGN_CHANNELS >= 7 +IgnitionSchedule ignitionSchedule7(IGN7_COUNTER, IGN7_COMPARE, IGN7_TIMER_DISABLE, IGN7_TIMER_ENABLE); +#endif +#if IGN_CHANNELS >= 8 +IgnitionSchedule ignitionSchedule8(IGN8_COUNTER, IGN8_COMPARE, IGN8_TIMER_DISABLE, IGN8_TIMER_ENABLE); +#endif + +void initialiseSchedulers() { - //nullSchedule.Status = OFF; - fuelSchedule1.Status = OFF; fuelSchedule2.Status = OFF; fuelSchedule3.Status = OFF; fuelSchedule4.Status = OFF; +#if INJ_CHANNELS >= 5 fuelSchedule5.Status = OFF; +#endif +#if INJ_CHANNELS >= 6 fuelSchedule6.Status = OFF; +#endif +#if INJ_CHANNELS >= 7 fuelSchedule7.Status = OFF; +#endif +#if INJ_CHANNELS >= 8 fuelSchedule8.Status = OFF; - - fuelSchedule1.schedulesSet = 0; - fuelSchedule2.schedulesSet = 0; - fuelSchedule3.schedulesSet = 0; - fuelSchedule4.schedulesSet = 0; - fuelSchedule5.schedulesSet = 0; - fuelSchedule6.schedulesSet = 0; - fuelSchedule7.schedulesSet = 0; - fuelSchedule8.schedulesSet = 0; +#endif ignitionSchedule1.Status = OFF; - ignitionSchedule2.Status = OFF; - ignitionSchedule3.Status = OFF; - ignitionSchedule4.Status = OFF; - ignitionSchedule5.Status = OFF; - ignitionSchedule6.Status = OFF; - ignitionSchedule7.Status = OFF; - ignitionSchedule8.Status = OFF; - IGN1_TIMER_ENABLE(); + ignitionSchedule2.Status = OFF; IGN2_TIMER_ENABLE(); + ignitionSchedule3.Status = OFF; IGN3_TIMER_ENABLE(); + ignitionSchedule4.Status = OFF; IGN4_TIMER_ENABLE(); #if (IGN_CHANNELS >= 5) + ignitionSchedule5.Status = OFF; IGN5_TIMER_ENABLE(); +#endif +#if IGN_CHANNELS >= 6 + ignitionSchedule6.Status = OFF; IGN6_TIMER_ENABLE(); +#endif +#if IGN_CHANNELS >= 7 + ignitionSchedule7.Status = OFF; IGN7_TIMER_ENABLE(); +#endif +#if IGN_CHANNELS >= 8 + ignitionSchedule8.Status = OFF; IGN8_TIMER_ENABLE(); #endif @@ -143,88 +119,79 @@ void initialiseSchedulers(void) FUEL8_TIMER_ENABLE(); #endif - ignitionSchedule1.schedulesSet = 0; - ignitionSchedule2.schedulesSet = 0; - ignitionSchedule3.schedulesSet = 0; - ignitionSchedule4.schedulesSet = 0; - ignitionSchedule5.schedulesSet = 0; - ignitionSchedule6.schedulesSet = 0; - ignitionSchedule7.schedulesSet = 0; - ignitionSchedule8.schedulesSet = 0; - - inj1StartFunction = nullCallback; - inj1EndFunction = nullCallback; - inj2StartFunction = nullCallback; - inj2EndFunction = nullCallback; - inj3StartFunction = nullCallback; - inj3EndFunction = nullCallback; - inj4StartFunction = nullCallback; - inj4EndFunction = nullCallback; -#if INJ_CHANNELS>=5 - inj5StartFunction = nullCallback; - inj5EndFunction = nullCallback; + fuelSchedule1.pStartFunction = nullCallback; + fuelSchedule1.pEndFunction = nullCallback; + fuelSchedule2.pStartFunction = nullCallback; + fuelSchedule2.pEndFunction = nullCallback; + fuelSchedule3.pStartFunction = nullCallback; + fuelSchedule3.pEndFunction = nullCallback; + fuelSchedule4.pStartFunction = nullCallback; + fuelSchedule4.pEndFunction = nullCallback; +#if (INJ_CHANNELS >= 5) + fuelSchedule5.pStartFunction = nullCallback; + fuelSchedule5.pEndFunction = nullCallback; #endif -#if INJ_CHANNELS>=6 - inj6StartFunction = nullCallback; - inj6EndFunction = nullCallback; +#if (INJ_CHANNELS >= 6) + fuelSchedule6.pStartFunction = nullCallback; + fuelSchedule6.pEndFunction = nullCallback; #endif -#if INJ_CHANNELS>=7 - inj7StartFunction = nullCallback; - inj7EndFunction = nullCallback; +#if (INJ_CHANNELS >= 7) + fuelSchedule7.pStartFunction = nullCallback; + fuelSchedule7.pEndFunction = nullCallback; #endif -#if INJ_CHANNELS>=8 - inj8StartFunction = nullCallback; - inj8EndFunction = nullCallback; +#if (INJ_CHANNELS >= 8) + fuelSchedule8.pStartFunction = nullCallback; + fuelSchedule8.pEndFunction = nullCallback; #endif - ign1StartFunction = nullCallback; - ign1EndFunction = nullCallback; + ignitionSchedule1.pStartCallback = nullCallback; + ignitionSchedule1.pEndCallback = nullCallback; ignition1StartAngle=0; ignition1EndAngle=0; channel1IgnDegrees=0; /**< The number of crank degrees until cylinder 1 is at TDC (This is obviously 0 for virtually ALL engines, but there's some weird ones) */ - ign2StartFunction = nullCallback; - ign2EndFunction = nullCallback; + ignitionSchedule2.pStartCallback = nullCallback; + ignitionSchedule2.pEndCallback = nullCallback; ignition2StartAngle=0; ignition2EndAngle=0; channel2IgnDegrees=0; /**< The number of crank degrees until cylinder 2 (and 5/6/7/8) is at TDC */ - ign3StartFunction = nullCallback; - ign3EndFunction = nullCallback; + ignitionSchedule3.pStartCallback = nullCallback; + ignitionSchedule3.pEndCallback = nullCallback; ignition3StartAngle=0; ignition3EndAngle=0; channel3IgnDegrees=0; /**< The number of crank degrees until cylinder 2 (and 5/6/7/8) is at TDC */ - ign4StartFunction = nullCallback; - ign4EndFunction = nullCallback; + ignitionSchedule4.pStartCallback = nullCallback; + ignitionSchedule4.pEndCallback = nullCallback; ignition4StartAngle=0; ignition4EndAngle=0; channel4IgnDegrees=0; /**< The number of crank degrees until cylinder 2 (and 5/6/7/8) is at TDC */ #if (IGN_CHANNELS >= 5) - ign5StartFunction = nullCallback; - ign5EndFunction = nullCallback; + ignitionSchedule5.pStartCallback = nullCallback; + ignitionSchedule5.pEndCallback = nullCallback; ignition5StartAngle=0; ignition5EndAngle=0; channel5IgnDegrees=0; /**< The number of crank degrees until cylinder 2 (and 5/6/7/8) is at TDC */ #endif #if (IGN_CHANNELS >= 6) - ign6StartFunction = nullCallback; - ign6EndFunction = nullCallback; + ignitionSchedule6.pStartCallback = nullCallback; + ignitionSchedule6.pEndCallback = nullCallback; ignition6StartAngle=0; ignition6EndAngle=0; channel6IgnDegrees=0; /**< The number of crank degrees until cylinder 2 (and 5/6/7/8) is at TDC */ #endif #if (IGN_CHANNELS >= 7) - ign7StartFunction = nullCallback; - ign7EndFunction = nullCallback; + ignitionSchedule7.pStartCallback = nullCallback; + ignitionSchedule7.pEndCallback = nullCallback; ignition7StartAngle=0; ignition7EndAngle=0; channel7IgnDegrees=0; /**< The number of crank degrees until cylinder 2 (and 5/6/7/8) is at TDC */ #endif #if (IGN_CHANNELS >= 8) - ign8StartFunction = nullCallback; - ign8EndFunction = nullCallback; + ignitionSchedule8.pStartCallback = nullCallback; + ignitionSchedule8.pEndCallback = nullCallback; ignition8StartAngle=0; ignition8EndAngle=0; channel8IgnDegrees=0; /**< The number of crank degrees until cylinder 2 (and 5/6/7/8) is at TDC */ @@ -259,43 +226,6 @@ duration: The number of uS after startCallback is called before endCallback is c endCallback: This function is called once the duration time has been reached */ -//Experimental new generic function. This is NOT yet ready and functional -void setFuelSchedule(struct Schedule *targetSchedule, unsigned long timeout, unsigned long duration) -{ - if(targetSchedule->Status != RUNNING) //Check that we're not already part way through a schedule - { - targetSchedule->duration = duration; - - //Need to check that the timeout doesn't exceed the overflow - COMPARE_TYPE timeout_timer_compare; - if (timeout > MAX_TIMER_PERIOD) { timeout_timer_compare = uS_TO_TIMER_COMPARE( (MAX_TIMER_PERIOD - 1) ); } // If the timeout is >16x (Each tick represents 16uS) the maximum allowed value of unsigned int (65535), the timer compare value will overflow when appliedcausing erratic behaviour such as erroneous sparking. - else { timeout_timer_compare = uS_TO_TIMER_COMPARE(timeout); } //Normal case - - //The following must be enclosed in the noInterupts block to avoid contention caused if the relevant interrupt fires before the state is fully set - noInterrupts(); - //targetSchedule->startCompare = *targetSchedule->counter + timeout_timer_compare; - targetSchedule->startCompare = FUEL1_COUNTER + timeout_timer_compare; //Insert correct counter HERE! - targetSchedule->endCompare = targetSchedule->startCompare + uS_TO_TIMER_COMPARE(duration); - targetSchedule->Status = PENDING; //Turn this schedule on - targetSchedule->schedulesSet++; //Increment the number of times this schedule has been set - - //*targetSchedule->compare = targetSchedule->startCompare; - SET_COMPARE(FUEL1_COMPARE, targetSchedule->startCompare); //Insert corrector compare HERE! - interrupts(); - FUEL1_TIMER_ENABLE(); - } - else - { - //If the schedule is already running, we can set the next schedule so it is ready to go - //This is required in cases of high rpm and high DC where there otherwise would not be enough time to set the schedule - //targetSchedule->nextStartCompare = *targetSchedule->counter + uS_TO_TIMER_COMPARE(timeout); - targetSchedule->nextEndCompare = targetSchedule->nextStartCompare + uS_TO_TIMER_COMPARE(duration); - targetSchedule->hasNextSchedule = true; - } -} - - -//void setFuelSchedule1(void (*startCallback)(), unsigned long timeout, unsigned long duration, void(*endCallback)()) void setFuelSchedule1(unsigned long timeout, unsigned long duration) //Uses timer 3 compare A { //Check whether timeout exceeds the maximum future time. This can potentially occur on sequential setups when below ~115rpm @@ -312,11 +242,6 @@ void setFuelSchedule1(unsigned long timeout, unsigned long duration) //Uses time fuelSchedule1.startCompare = FUEL1_COUNTER + uS_TO_TIMER_COMPARE(timeout); fuelSchedule1.endCompare = fuelSchedule1.startCompare + uS_TO_TIMER_COMPARE(duration); fuelSchedule1.Status = PENDING; //Turn this schedule on - fuelSchedule1.schedulesSet++; //Increment the number of times this schedule has been set - //Schedule 1 shares a timer with schedule 5 - //if(channel5InjEnabled) { SET_COMPARE(FUEL1_COMPARE, setQueue(timer3Aqueue, &fuelSchedule1, &fuelSchedule5, FUEL1_COUNTER) ); } - //else { timer3Aqueue[0] = &fuelSchedule1; timer3Aqueue[1] = &fuelSchedule1; timer3Aqueue[2] = &fuelSchedule1; timer3Aqueue[3] = &fuelSchedule1; SET_COMPARE(FUEL1_COMPARE, fuelSchedule1.startCompare); } - //timer3Aqueue[0] = &fuelSchedule1; timer3Aqueue[1] = &fuelSchedule1; timer3Aqueue[2] = &fuelSchedule1; timer3Aqueue[3] = &fuelSchedule1; SET_COMPARE(FUEL1_COMPARE, fuelSchedule1.startCompare); interrupts(); FUEL1_TIMER_ENABLE(); @@ -346,9 +271,6 @@ void setFuelSchedule2(unsigned long timeout, unsigned long duration) //Uses time { if(fuelSchedule2.Status != RUNNING) //Check that we're not already part way through a schedule { - //Callbacks no longer used, but retained for now: - //fuelSchedule2.StartCallback = startCallback; - //fuelSchedule2.EndCallback = endCallback; fuelSchedule2.duration = duration; //Need to check that the timeout doesn't exceed the overflow @@ -362,7 +284,6 @@ void setFuelSchedule2(unsigned long timeout, unsigned long duration) //Uses time fuelSchedule2.endCompare = fuelSchedule2.startCompare + uS_TO_TIMER_COMPARE(duration); SET_COMPARE(FUEL2_COMPARE, fuelSchedule2.startCompare); //Use the B compare unit of timer 3 fuelSchedule2.Status = PENDING; //Turn this schedule on - fuelSchedule2.schedulesSet++; //Increment the number of times this schedule has been set interrupts(); FUEL2_TIMER_ENABLE(); } @@ -376,7 +297,7 @@ void setFuelSchedule2(unsigned long timeout, unsigned long duration) //Uses time } } } -//void setFuelSchedule3(void (*startCallback)(), unsigned long timeout, unsigned long duration, void(*endCallback)()) + void setFuelSchedule3(unsigned long timeout, unsigned long duration) //Uses timer 3 compare C { //Check whether timeout exceeds the maximum future time. This can potentially occur on sequential setups when below ~115rpm @@ -384,9 +305,6 @@ void setFuelSchedule3(unsigned long timeout, unsigned long duration) //Uses time { if(fuelSchedule3.Status != RUNNING) //Check that we're not already part way through a schedule { - //Callbacks no longer used, but retained for now: - //fuelSchedule3.StartCallback = startCallback; - //fuelSchedule3.EndCallback = endCallback; fuelSchedule3.duration = duration; //Need to check that the timeout doesn't exceed the overflow @@ -400,7 +318,6 @@ void setFuelSchedule3(unsigned long timeout, unsigned long duration) //Uses time fuelSchedule3.endCompare = fuelSchedule3.startCompare + uS_TO_TIMER_COMPARE(duration); SET_COMPARE(FUEL3_COMPARE, fuelSchedule3.startCompare); //Use the C compare unit of timer 3 fuelSchedule3.Status = PENDING; //Turn this schedule on - fuelSchedule3.schedulesSet++; //Increment the number of times this schedule has been set interrupts(); FUEL3_TIMER_ENABLE(); } @@ -414,7 +331,7 @@ void setFuelSchedule3(unsigned long timeout, unsigned long duration) //Uses time } } } -//void setFuelSchedule4(void (*startCallback)(), unsigned long timeout, unsigned long duration, void(*endCallback)()) + void setFuelSchedule4(unsigned long timeout, unsigned long duration) //Uses timer 4 compare B { //Check whether timeout exceeds the maximum future time. This can potentially occur on sequential setups when below ~115rpm @@ -422,9 +339,6 @@ void setFuelSchedule4(unsigned long timeout, unsigned long duration) //Uses time { if(fuelSchedule4.Status != RUNNING) //Check that we're not already part way through a schedule { - //Callbacks no longer used, but retained for now: - //fuelSchedule4.StartCallback = startCallback; - //fuelSchedule4.EndCallback = endCallback; fuelSchedule4.duration = duration; //Need to check that the timeout doesn't exceed the overflow @@ -438,7 +352,6 @@ void setFuelSchedule4(unsigned long timeout, unsigned long duration) //Uses time fuelSchedule4.endCompare = fuelSchedule4.startCompare + uS_TO_TIMER_COMPARE(duration); SET_COMPARE(FUEL4_COMPARE, fuelSchedule4.startCompare); //Use the B compare unit of timer 4 fuelSchedule4.Status = PENDING; //Turn this schedule on - fuelSchedule4.schedulesSet++; //Increment the number of times this schedule has been set interrupts(); FUEL4_TIMER_ENABLE(); } @@ -474,7 +387,6 @@ void setFuelSchedule5(unsigned long timeout, unsigned long duration) //Uses time fuelSchedule5.endCompare = fuelSchedule5.startCompare + uS_TO_TIMER_COMPARE(duration); SET_COMPARE(FUEL5_COMPARE, fuelSchedule5.startCompare); //Use the C compare unit of timer 4 fuelSchedule5.Status = PENDING; //Turn this schedule on - fuelSchedule5.schedulesSet++; //Increment the number of times this schedule has been set interrupts(); FUEL5_TIMER_ENABLE(); } @@ -511,7 +423,6 @@ void setFuelSchedule6(unsigned long timeout, unsigned long duration) //Uses time fuelSchedule6.endCompare = fuelSchedule6.startCompare + uS_TO_TIMER_COMPARE(duration); SET_COMPARE(FUEL6_COMPARE, fuelSchedule6.startCompare); //Use the A compare unit of timer 4 fuelSchedule6.Status = PENDING; //Turn this schedule on - fuelSchedule6.schedulesSet++; //Increment the number of times this schedule has been set interrupts(); FUEL6_TIMER_ENABLE(); } @@ -548,7 +459,6 @@ void setFuelSchedule7(unsigned long timeout, unsigned long duration) //Uses time fuelSchedule7.endCompare = fuelSchedule7.startCompare + uS_TO_TIMER_COMPARE(duration); SET_COMPARE(FUEL7_COMPARE, fuelSchedule7.startCompare); //Use the C compare unit of timer 5 fuelSchedule7.Status = PENDING; //Turn this schedule on - fuelSchedule7.schedulesSet++; //Increment the number of times this schedule has been set interrupts(); FUEL7_TIMER_ENABLE(); } @@ -585,7 +495,6 @@ void setFuelSchedule8(unsigned long timeout, unsigned long duration) //Uses time fuelSchedule8.endCompare = fuelSchedule8.startCompare + uS_TO_TIMER_COMPARE(duration); SET_COMPARE(FUEL8_COMPARE, fuelSchedule8.startCompare); //Use the B compare unit of timer 5 fuelSchedule8.Status = PENDING; //Turn this schedule on - fuelSchedule8.schedulesSet++; //Increment the number of times this schedule has been set interrupts(); FUEL8_TIMER_ENABLE(); } @@ -602,17 +511,14 @@ void setFuelSchedule8(unsigned long timeout, unsigned long duration) //Uses time #endif //Ignition schedulers use Timer 5 -void setIgnitionSchedule1(void (*startCallback)(), unsigned long timeout, unsigned long duration, void(*endCallback)()) +void setIgnitionSchedule1(unsigned long timeout, unsigned long duration) { if(ignitionSchedule1.Status != RUNNING) //Check that we're not already part way through a schedule { - ignitionSchedule1.StartCallback = startCallback; //Name the start callback function - ignitionSchedule1.EndCallback = endCallback; //Name the start callback function ignitionSchedule1.duration = duration; //Need to check that the timeout doesn't exceed the overflow COMPARE_TYPE timeout_timer_compare; - //timeout -= (micros() - lastCrankAngleCalc); if (timeout > MAX_TIMER_PERIOD) { timeout_timer_compare = uS_TO_TIMER_COMPARE( (MAX_TIMER_PERIOD - 1) ); } // If the timeout is >4x (Each tick represents 4uS) the maximum allowed value of unsigned int (65535), the timer compare value will overflow when applied causing erratic behaviour such as erroneous sparking. else { timeout_timer_compare = uS_TO_TIMER_COMPARE(timeout); } //Normal case @@ -621,7 +527,6 @@ void setIgnitionSchedule1(void (*startCallback)(), unsigned long timeout, unsign if(ignitionSchedule1.endScheduleSetByDecoder == false) { ignitionSchedule1.endCompare = ignitionSchedule1.startCompare + uS_TO_TIMER_COMPARE(duration); } //The .endCompare value is also set by the per tooth timing in decoders.ino. The check here is so that it's not getting overridden. SET_COMPARE(IGN1_COMPARE, ignitionSchedule1.startCompare); ignitionSchedule1.Status = PENDING; //Turn this schedule on - ignitionSchedule1.schedulesSet++; interrupts(); IGN1_TIMER_ENABLE(); } @@ -652,12 +557,10 @@ void refreshIgnitionSchedule1(unsigned long timeToEnd) } } -void setIgnitionSchedule2(void (*startCallback)(), unsigned long timeout, unsigned long duration, void(*endCallback)()) +void setIgnitionSchedule2(unsigned long timeout, unsigned long duration) { if(ignitionSchedule2.Status != RUNNING) //Check that we're not already part way through a schedule { - ignitionSchedule2.StartCallback = startCallback; //Name the start callback function - ignitionSchedule2.EndCallback = endCallback; //Name the start callback function ignitionSchedule2.duration = duration; //Need to check that the timeout doesn't exceed the overflow @@ -670,7 +573,6 @@ void setIgnitionSchedule2(void (*startCallback)(), unsigned long timeout, unsign if(ignitionSchedule2.endScheduleSetByDecoder == false) { ignitionSchedule2.endCompare = ignitionSchedule2.startCompare + uS_TO_TIMER_COMPARE(duration); } //The .endCompare value is also set by the per tooth timing in decoders.ino. The check here is so that it's not getting overridden. SET_COMPARE(IGN2_COMPARE, ignitionSchedule2.startCompare); ignitionSchedule2.Status = PENDING; //Turn this schedule on - ignitionSchedule2.schedulesSet++; interrupts(); IGN2_TIMER_ENABLE(); } @@ -686,13 +588,10 @@ void setIgnitionSchedule2(void (*startCallback)(), unsigned long timeout, unsign } } } -void setIgnitionSchedule3(void (*startCallback)(), unsigned long timeout, unsigned long duration, void(*endCallback)()) +void setIgnitionSchedule3(unsigned long timeout, unsigned long duration) { if(ignitionSchedule3.Status != RUNNING) //Check that we're not already part way through a schedule { - - ignitionSchedule3.StartCallback = startCallback; //Name the start callback function - ignitionSchedule3.EndCallback = endCallback; //Name the start callback function ignitionSchedule3.duration = duration; //Need to check that the timeout doesn't exceed the overflow @@ -705,7 +604,6 @@ void setIgnitionSchedule3(void (*startCallback)(), unsigned long timeout, unsign if(ignitionSchedule3.endScheduleSetByDecoder == false) { ignitionSchedule3.endCompare = ignitionSchedule3.startCompare + uS_TO_TIMER_COMPARE(duration); } //The .endCompare value is also set by the per tooth timing in decoders.ino. The check here is so that it's not getting overridden. SET_COMPARE(IGN3_COMPARE, ignitionSchedule3.startCompare); ignitionSchedule3.Status = PENDING; //Turn this schedule on - ignitionSchedule3.schedulesSet++; interrupts(); IGN3_TIMER_ENABLE(); } @@ -721,13 +619,10 @@ void setIgnitionSchedule3(void (*startCallback)(), unsigned long timeout, unsign } } } -void setIgnitionSchedule4(void (*startCallback)(), unsigned long timeout, unsigned long duration, void(*endCallback)()) +void setIgnitionSchedule4(unsigned long timeout, unsigned long duration) { if(ignitionSchedule4.Status != RUNNING) //Check that we're not already part way through a schedule { - - ignitionSchedule4.StartCallback = startCallback; //Name the start callback function - ignitionSchedule4.EndCallback = endCallback; //Name the start callback function ignitionSchedule4.duration = duration; //Need to check that the timeout doesn't exceed the overflow @@ -740,7 +635,6 @@ void setIgnitionSchedule4(void (*startCallback)(), unsigned long timeout, unsign if(ignitionSchedule4.endScheduleSetByDecoder == false) { ignitionSchedule4.endCompare = ignitionSchedule4.startCompare + uS_TO_TIMER_COMPARE(duration); } //The .endCompare value is also set by the per tooth timing in decoders.ino. The check here is so that it's not getting overridden. SET_COMPARE(IGN4_COMPARE, ignitionSchedule4.startCompare); ignitionSchedule4.Status = PENDING; //Turn this schedule on - ignitionSchedule4.schedulesSet++; interrupts(); IGN4_TIMER_ENABLE(); } @@ -756,13 +650,10 @@ void setIgnitionSchedule4(void (*startCallback)(), unsigned long timeout, unsign } } } -void setIgnitionSchedule5(void (*startCallback)(), unsigned long timeout, unsigned long duration, void(*endCallback)()) +void setIgnitionSchedule5(unsigned long timeout, unsigned long duration) { if(ignitionSchedule5.Status != RUNNING) //Check that we're not already part way through a schedule { - - ignitionSchedule5.StartCallback = startCallback; //Name the start callback function - ignitionSchedule5.EndCallback = endCallback; //Name the start callback function ignitionSchedule5.duration = duration; //Need to check that the timeout doesn't exceed the overflow @@ -775,7 +666,6 @@ void setIgnitionSchedule5(void (*startCallback)(), unsigned long timeout, unsign if(ignitionSchedule5.endScheduleSetByDecoder == false) { ignitionSchedule5.endCompare = ignitionSchedule5.startCompare + uS_TO_TIMER_COMPARE(duration); } //The .endCompare value is also set by the per tooth timing in decoders.ino. The check here is so that it's not getting overridden. SET_COMPARE(IGN5_COMPARE, ignitionSchedule5.startCompare); ignitionSchedule5.Status = PENDING; //Turn this schedule on - ignitionSchedule5.schedulesSet++; interrupts(); IGN5_TIMER_ENABLE(); } @@ -791,13 +681,12 @@ void setIgnitionSchedule5(void (*startCallback)(), unsigned long timeout, unsign } } } -void setIgnitionSchedule6(void (*startCallback)(), unsigned long timeout, unsigned long duration, void(*endCallback)()) + +#if IGN_CHANNELS >= 6 +void setIgnitionSchedule6(unsigned long timeout, unsigned long duration) { if(ignitionSchedule6.Status != RUNNING) //Check that we're not already part way through a schedule { - - ignitionSchedule6.StartCallback = startCallback; //Name the start callback function - ignitionSchedule6.EndCallback = endCallback; //Name the start callback function ignitionSchedule6.duration = duration; //Need to check that the timeout doesn't exceed the overflow @@ -810,7 +699,6 @@ void setIgnitionSchedule6(void (*startCallback)(), unsigned long timeout, unsign if(ignitionSchedule6.endScheduleSetByDecoder == false) { ignitionSchedule6.endCompare = ignitionSchedule6.startCompare + uS_TO_TIMER_COMPARE(duration); } //The .endCompare value is also set by the per tooth timing in decoders.ino. The check here is so that it's not getting overridden. SET_COMPARE(IGN6_COMPARE, ignitionSchedule6.startCompare); ignitionSchedule6.Status = PENDING; //Turn this schedule on - ignitionSchedule6.schedulesSet++; interrupts(); IGN6_TIMER_ENABLE(); } @@ -826,13 +714,13 @@ void setIgnitionSchedule6(void (*startCallback)(), unsigned long timeout, unsign } } } -void setIgnitionSchedule7(void (*startCallback)(), unsigned long timeout, unsigned long duration, void(*endCallback)()) +#endif + +#if IGN_CHANNELS >= 7 +void setIgnitionSchedule7(unsigned long timeout, unsigned long duration) { if(ignitionSchedule7.Status != RUNNING) //Check that we're not already part way through a schedule { - - ignitionSchedule7.StartCallback = startCallback; //Name the start callback function - ignitionSchedule7.EndCallback = endCallback; //Name the start callback function ignitionSchedule7.duration = duration; //Need to check that the timeout doesn't exceed the overflow @@ -845,7 +733,6 @@ void setIgnitionSchedule7(void (*startCallback)(), unsigned long timeout, unsign if(ignitionSchedule7.endScheduleSetByDecoder == false) { ignitionSchedule7.endCompare = ignitionSchedule7.startCompare + uS_TO_TIMER_COMPARE(duration); } //The .endCompare value is also set by the per tooth timing in decoders.ino. The check here is so that it's not getting overridden. SET_COMPARE(IGN7_COMPARE, ignitionSchedule7.startCompare); ignitionSchedule7.Status = PENDING; //Turn this schedule on - ignitionSchedule7.schedulesSet++; interrupts(); IGN7_TIMER_ENABLE(); } @@ -861,13 +748,13 @@ void setIgnitionSchedule7(void (*startCallback)(), unsigned long timeout, unsign } } } -void setIgnitionSchedule8(void (*startCallback)(), unsigned long timeout, unsigned long duration, void(*endCallback)()) +#endif + +#if IGN_CHANNELS >= 8 +void setIgnitionSchedule8(unsigned long timeout, unsigned long duration) { if(ignitionSchedule8.Status != RUNNING) //Check that we're not already part way through a schedule { - - ignitionSchedule8.StartCallback = startCallback; //Name the start callback function - ignitionSchedule8.EndCallback = endCallback; //Name the start callback function ignitionSchedule8.duration = duration; //Need to check that the timeout doesn't exceed the overflow @@ -880,7 +767,6 @@ void setIgnitionSchedule8(void (*startCallback)(), unsigned long timeout, unsign if(ignitionSchedule8.endScheduleSetByDecoder == false) { ignitionSchedule8.endCompare = ignitionSchedule8.startCompare + uS_TO_TIMER_COMPARE(duration); } //The .endCompare value is also set by the per tooth timing in decoders.ino. The check here is so that it's not getting overridden. SET_COMPARE(IGN8_COMPARE, ignitionSchedule8.startCompare); ignitionSchedule8.Status = PENDING; //Turn this schedule on - ignitionSchedule8.schedulesSet++; interrupts(); IGN8_TIMER_ENABLE(); } @@ -896,6 +782,8 @@ void setIgnitionSchedule8(void (*startCallback)(), unsigned long timeout, unsign } } } +#endif + /** Perform the injector priming pulses. * Set these to run at an arbitrary time in the future (100us). * The prime pulse value is in ms*10, so need to multiple by 100 to get to uS @@ -931,6 +819,41 @@ extern void beginInjectorPriming(void) } } +// Shared ISR function for all fuel timers. +// This is completely inlined into the ISR - there is no function call +// overhead. +static inline __attribute__((always_inline)) void fuelScheduleISR(FuelSchedule &schedule) +{ + if (schedule.Status == PENDING) //Check to see if this schedule is turn on + { + schedule.pStartFunction(); + schedule.Status = RUNNING; //Set the status to be in progress (ie The start callback has been called, but not the end callback) + SET_COMPARE(schedule.compare, schedule.counter + uS_TO_TIMER_COMPARE(schedule.duration) ); //Doing this here prevents a potential overflow on restarts + } + else if (schedule.Status == RUNNING) + { + schedule.pEndFunction(); + schedule.Status = OFF; //Turn off the schedule + + //If there is a next schedule queued up, activate it + if(schedule.hasNextSchedule == true) + { + SET_COMPARE(schedule.compare, schedule.nextStartCompare); + SET_COMPARE(schedule.endCompare, schedule.nextEndCompare); + schedule.Status = PENDING; + schedule.hasNextSchedule = false; + } + else + { + schedule.pTimerDisable(); + } + } + else if (schedule.Status == OFF) + { + schedule.pTimerDisable(); //Safety check. Turn off this output compare unit and return without performing any action + } +} + /*******************************************************************************************************************************************************************************************************/ /** fuelSchedule*Interrupt (All 8 ISR functions below) get called (as timed interrupts) when either the start time or the duration time are reached. * This calls the relevant callback function (startCallback or endCallback) depending on the status (PENDING => Needs to run, RUNNING => Needs to stop) of the schedule. @@ -939,536 +862,183 @@ extern void beginInjectorPriming(void) * - endCallback - change scheduler into OFF state (or PENDING if schedule.hasNextSchedule is set) */ //Timer3A (fuel schedule 1) Compare Vector -#if (INJ_CHANNELS >= 1) #if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__) || defined(__AVR_ATmega2561__) //AVR chips use the ISR for this //fuelSchedules 1 and 5 ISR(TIMER3_COMPA_vect) //cppcheck-suppress misra-c2012-8.2 #else -void fuelSchedule1Interrupt(void) +void fuelSchedule1Interrupt() //Most ARM chips can simply call a function #endif { - if (fuelSchedule1.Status == PENDING) //Check to see if this schedule is turn on - { - //To use timer queue, change fuelShedule1 to timer3Aqueue[0]; - inj1StartFunction(); - fuelSchedule1.Status = RUNNING; //Set the status to be in progress (ie The start callback has been called, but not the end callback) - SET_COMPARE(FUEL1_COMPARE, FUEL1_COUNTER + uS_TO_TIMER_COMPARE(fuelSchedule1.duration) ); //Doing this here prevents a potential overflow on restarts - } - else if (fuelSchedule1.Status == RUNNING) - { - //timer3Aqueue[0]->EndCallback(); - inj1EndFunction(); - fuelSchedule1.Status = OFF; //Turn off the schedule - fuelSchedule1.schedulesSet = 0; - //SET_COMPARE(FUEL1_COMPARE, fuelSchedule1.endCompare); - - //If there is a next schedule queued up, activate it - if(fuelSchedule1.hasNextSchedule == true) - { - SET_COMPARE(FUEL1_COMPARE, fuelSchedule1.nextStartCompare); - fuelSchedule1.endCompare = fuelSchedule1.nextEndCompare; - fuelSchedule1.Status = PENDING; - fuelSchedule1.schedulesSet = 1; - fuelSchedule1.hasNextSchedule = false; - } - else { FUEL1_TIMER_DISABLE(); } - } - else if (fuelSchedule1.Status == OFF) { FUEL1_TIMER_DISABLE(); } //Safety check. Turn off this output compare unit and return without performing any action + fuelScheduleISR(fuelSchedule1); } -#endif -#if (INJ_CHANNELS >= 2) + #if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__) || defined(__AVR_ATmega2561__) //AVR chips use the ISR for this ISR(TIMER3_COMPB_vect) //cppcheck-suppress misra-c2012-8.2 #else -void fuelSchedule2Interrupt(void) +void fuelSchedule2Interrupt() //Most ARM chips can simply call a function #endif { - if (fuelSchedule2.Status == PENDING) //Check to see if this schedule is turn on - { - //fuelSchedule2.StartCallback(); - inj2StartFunction(); - fuelSchedule2.Status = RUNNING; //Set the status to be in progress (ie The start callback has been called, but not the end callback) - SET_COMPARE(FUEL2_COMPARE, FUEL2_COUNTER + uS_TO_TIMER_COMPARE(fuelSchedule2.duration) ); //Doing this here prevents a potential overflow on restarts - } - else if (fuelSchedule2.Status == RUNNING) - { - //fuelSchedule2.EndCallback(); - inj2EndFunction(); - fuelSchedule2.Status = OFF; //Turn off the schedule - fuelSchedule2.schedulesSet = 0; - - //If there is a next schedule queued up, activate it - if(fuelSchedule2.hasNextSchedule == true) - { - SET_COMPARE(FUEL2_COMPARE, fuelSchedule2.nextStartCompare); - fuelSchedule2.endCompare = fuelSchedule2.nextEndCompare; - fuelSchedule2.Status = PENDING; - fuelSchedule2.schedulesSet = 1; - fuelSchedule2.hasNextSchedule = false; - } - else { FUEL2_TIMER_DISABLE(); } - } + fuelScheduleISR(fuelSchedule2); } -#endif -#if (INJ_CHANNELS >= 3) + #if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__) || defined(__AVR_ATmega2561__) //AVR chips use the ISR for this ISR(TIMER3_COMPC_vect) //cppcheck-suppress misra-c2012-8.2 #else -void fuelSchedule3Interrupt(void) +void fuelSchedule3Interrupt() //Most ARM chips can simply call a function #endif { - if (fuelSchedule3.Status == PENDING) //Check to see if this schedule is turn on - { - //fuelSchedule3.StartCallback(); - inj3StartFunction(); - fuelSchedule3.Status = RUNNING; //Set the status to be in progress (ie The start callback has been called, but not the end callback) - SET_COMPARE(FUEL3_COMPARE, FUEL3_COUNTER + uS_TO_TIMER_COMPARE(fuelSchedule3.duration) ); //Doing this here prevents a potential overflow on restarts - } - else if (fuelSchedule3.Status == RUNNING) - { - //fuelSchedule3.EndCallback(); - inj3EndFunction(); - fuelSchedule3.Status = OFF; //Turn off the schedule - fuelSchedule3.schedulesSet = 0; - - //If there is a next schedule queued up, activate it - if(fuelSchedule3.hasNextSchedule == true) - { - SET_COMPARE(FUEL3_COMPARE, fuelSchedule3.nextStartCompare); - fuelSchedule3.endCompare = fuelSchedule3.nextEndCompare; - fuelSchedule3.Status = PENDING; - fuelSchedule3.schedulesSet = 1; - fuelSchedule3.hasNextSchedule = false; - } - else { FUEL3_TIMER_DISABLE(); } - } + fuelScheduleISR(fuelSchedule3); } -#endif -#if (INJ_CHANNELS >= 4) + #if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__) || defined(__AVR_ATmega2561__) //AVR chips use the ISR for this ISR(TIMER4_COMPB_vect) //cppcheck-suppress misra-c2012-8.2 #else -void fuelSchedule4Interrupt(void) +void fuelSchedule4Interrupt() //Most ARM chips can simply call a function #endif { - if (fuelSchedule4.Status == PENDING) //Check to see if this schedule is turn on - { - //fuelSchedule4.StartCallback(); - inj4StartFunction(); - fuelSchedule4.Status = RUNNING; //Set the status to be in progress (ie The start callback has been called, but not the end callback) - SET_COMPARE(FUEL4_COMPARE, FUEL4_COUNTER + uS_TO_TIMER_COMPARE(fuelSchedule4.duration) ); //Doing this here prevents a potential overflow on restarts - } - else if (fuelSchedule4.Status == RUNNING) - { - //fuelSchedule4.EndCallback(); - inj4EndFunction(); - fuelSchedule4.Status = OFF; //Turn off the schedule - fuelSchedule4.schedulesSet = 0; - - //If there is a next schedule queued up, activate it - if(fuelSchedule4.hasNextSchedule == true) - { - SET_COMPARE(FUEL4_COMPARE, fuelSchedule4.nextStartCompare); - fuelSchedule4.endCompare = fuelSchedule4.nextEndCompare; - fuelSchedule4.Status = PENDING; - fuelSchedule4.schedulesSet = 1; - fuelSchedule4.hasNextSchedule = false; - } - else { FUEL4_TIMER_DISABLE(); } - } + fuelScheduleISR(fuelSchedule4); } -#endif -#if (INJ_CHANNELS >= 5) +#if INJ_CHANNELS >= 5 #if defined(CORE_AVR) //AVR chips use the ISR for this ISR(TIMER4_COMPC_vect) //cppcheck-suppress misra-c2012-8.2 #else -void fuelSchedule5Interrupt(void) +void fuelSchedule5Interrupt() //Most ARM chips can simply call a function #endif -{ - if (fuelSchedule5.Status == PENDING) //Check to see if this schedule is turn on { - inj5StartFunction(); - fuelSchedule5.Status = RUNNING; //Set the status to be in progress (ie The start callback has been called, but not the end callback) - SET_COMPARE(FUEL5_COMPARE, FUEL5_COUNTER + uS_TO_TIMER_COMPARE(fuelSchedule5.duration) ); //Doing this here prevents a potential overflow on restarts + fuelScheduleISR(fuelSchedule5); } - else if (fuelSchedule5.Status == RUNNING) - { - inj5EndFunction(); - fuelSchedule5.Status = OFF; //Turn off the schedule - fuelSchedule5.schedulesSet = 0; - - //If there is a next schedule queued up, activate it - if(fuelSchedule5.hasNextSchedule == true) - { - SET_COMPARE(FUEL5_COMPARE, fuelSchedule5.nextStartCompare); - fuelSchedule5.endCompare = fuelSchedule5.nextEndCompare; - fuelSchedule5.Status = PENDING; - fuelSchedule5.schedulesSet = 1; - fuelSchedule5.hasNextSchedule = false; - } - else { FUEL5_TIMER_DISABLE(); } - } -} #endif -#if (INJ_CHANNELS >= 6) +#if INJ_CHANNELS >= 6 #if defined(CORE_AVR) //AVR chips use the ISR for this ISR(TIMER4_COMPA_vect) //cppcheck-suppress misra-c2012-8.2 #else -void fuelSchedule6Interrupt(void) +void fuelSchedule6Interrupt() //Most ARM chips can simply call a function #endif -{ - if (fuelSchedule6.Status == PENDING) //Check to see if this schedule is turn on { - //fuelSchedule6.StartCallback(); - inj6StartFunction(); - fuelSchedule6.Status = RUNNING; //Set the status to be in progress (ie The start callback has been called, but not the end callback) - SET_COMPARE(FUEL6_COMPARE, FUEL6_COUNTER + uS_TO_TIMER_COMPARE(fuelSchedule6.duration) ); //Doing this here prevents a potential overflow on restarts + fuelScheduleISR(fuelSchedule6); } - else if (fuelSchedule6.Status == RUNNING) - { - //fuelSchedule6.EndCallback(); - inj6EndFunction(); - fuelSchedule6.Status = OFF; //Turn off the schedule - fuelSchedule6.schedulesSet = 0; - - //If there is a next schedule queued up, activate it - if(fuelSchedule6.hasNextSchedule == true) - { - SET_COMPARE(FUEL6_COMPARE, fuelSchedule6.nextStartCompare); - fuelSchedule6.endCompare = fuelSchedule6.nextEndCompare; - fuelSchedule6.Status = PENDING; - fuelSchedule6.schedulesSet = 1; - fuelSchedule6.hasNextSchedule = false; - } - else { FUEL6_TIMER_DISABLE(); } - } -} #endif -#if (INJ_CHANNELS >= 7) +#if INJ_CHANNELS >= 7 #if defined(CORE_AVR) //AVR chips use the ISR for this ISR(TIMER5_COMPC_vect) //cppcheck-suppress misra-c2012-8.2 #else -void fuelSchedule7Interrupt(void) +void fuelSchedule7Interrupt() //Most ARM chips can simply call a function #endif -{ - if (fuelSchedule7.Status == PENDING) //Check to see if this schedule is turn on { - //fuelSchedule7.StartCallback(); - inj7StartFunction(); - fuelSchedule7.Status = RUNNING; //Set the status to be in progress (ie The start callback has been called, but not the end callback) - SET_COMPARE(FUEL7_COMPARE, FUEL7_COUNTER + uS_TO_TIMER_COMPARE(fuelSchedule7.duration) ); //Doing this here prevents a potential overflow on restarts + fuelScheduleISR(fuelSchedule7); } - else if (fuelSchedule7.Status == RUNNING) - { - //fuelSchedule7.EndCallback(); - inj7EndFunction(); - fuelSchedule7.Status = OFF; //Turn off the schedule - fuelSchedule7.schedulesSet = 0; - - //If there is a next schedule queued up, activate it - if(fuelSchedule7.hasNextSchedule == true) - { - SET_COMPARE(FUEL7_COMPARE, fuelSchedule7.nextStartCompare); - fuelSchedule7.endCompare = fuelSchedule7.nextEndCompare; - fuelSchedule7.Status = PENDING; - fuelSchedule7.schedulesSet = 1; - fuelSchedule7.hasNextSchedule = false; - } - else { FUEL7_TIMER_DISABLE(); } - } -} #endif -#if (INJ_CHANNELS >= 8) +#if INJ_CHANNELS >= 8 #if defined(CORE_AVR) //AVR chips use the ISR for this ISR(TIMER5_COMPB_vect) //cppcheck-suppress misra-c2012-8.2 #else -void fuelSchedule8Interrupt(void) +void fuelSchedule8Interrupt() //Most ARM chips can simply call a function #endif -{ - if (fuelSchedule8.Status == PENDING) //Check to see if this schedule is turn on { - //fuelSchedule8.StartCallback(); - inj8StartFunction(); - fuelSchedule8.Status = RUNNING; //Set the status to be in progress (ie The start callback has been called, but not the end callback) - SET_COMPARE(FUEL8_COMPARE, FUEL8_COUNTER + uS_TO_TIMER_COMPARE(fuelSchedule8.duration) ); //Doing this here prevents a potential overflow on restarts + fuelScheduleISR(fuelSchedule8); } - else if (fuelSchedule8.Status == RUNNING) - { - //fuelSchedule8.EndCallback(); - inj8EndFunction(); - fuelSchedule8.Status = OFF; //Turn off the schedule - fuelSchedule8.schedulesSet = 0; +#endif - //If there is a next schedule queued up, activate it - if(fuelSchedule8.hasNextSchedule == true) - { - SET_COMPARE(FUEL8_COMPARE, fuelSchedule8.nextStartCompare); - fuelSchedule8.endCompare = fuelSchedule8.nextEndCompare; - fuelSchedule8.Status = PENDING; - fuelSchedule8.schedulesSet = 1; - fuelSchedule8.hasNextSchedule = false; - } - else { FUEL8_TIMER_DISABLE(); } +// Shared ISR function for all ignition timers. +// This is completely inlined into the ISR - there is no function call +// overhead. +static inline __attribute__((always_inline)) void ignitionScheduleISR(IgnitionSchedule &schedule) +{ + if (schedule.Status == PENDING) //Check to see if this schedule is turn on + { + schedule.pStartCallback(); + schedule.Status = RUNNING; //Set the status to be in progress (ie The start callback has been called, but not the end callback) + schedule.startTime = micros(); + if(schedule.endScheduleSetByDecoder == true) { SET_COMPARE(schedule.compare, schedule.endCompare); } + else { SET_COMPARE(schedule.compare, schedule.counter + uS_TO_TIMER_COMPARE(schedule.duration) ); } //Doing this here prevents a potential overflow on restarts + } + else if (schedule.Status == RUNNING) + { + schedule.pEndCallback(); + schedule.Status = OFF; //Turn off the schedule + schedule.endScheduleSetByDecoder = false; + ignitionCount = ignitionCount + 1; //Increment the ignition counter + currentStatus.actualDwell = DWELL_AVERAGE( (micros() - schedule.startTime) ); + + //If there is a next schedule queued up, activate it + if(schedule.hasNextSchedule == true) + { + SET_COMPARE(schedule.compare, schedule.nextStartCompare); + schedule.Status = PENDING; + schedule.hasNextSchedule = false; + } + else + { + schedule.pTimerDisable(); + } + } + else if (schedule.Status == OFF) + { + //Catch any spurious interrupts. This really shouldn't ever be called, but there as a safety + schedule.pTimerDisable(); } } -#endif -#if IGN_CHANNELS >= 1 #if defined(CORE_AVR) //AVR chips use the ISR for this ISR(TIMER5_COMPA_vect) //cppcheck-suppress misra-c2012-8.2 #else -void ignitionSchedule1Interrupt(void) +void ignitionSchedule1Interrupt(void) //Most ARM chips can simply call a function #endif { - if (ignitionSchedule1.Status == PENDING) //Check to see if this schedule is turn on - { - ignitionSchedule1.StartCallback(); - ignitionSchedule1.Status = RUNNING; //Set the status to be in progress (ie The start callback has been called, but not the end callback) - ignitionSchedule1.startTime = micros(); - if(ignitionSchedule1.endScheduleSetByDecoder == true) { SET_COMPARE(IGN1_COMPARE, ignitionSchedule1.endCompare); } - else { SET_COMPARE(IGN1_COMPARE, IGN1_COUNTER + uS_TO_TIMER_COMPARE(ignitionSchedule1.duration) ); } //Doing this here prevents a potential overflow on restarts - } - else if (ignitionSchedule1.Status == RUNNING) - { - ignitionSchedule1.EndCallback(); - ignitionSchedule1.Status = OFF; //Turn off the schedule - ignitionSchedule1.schedulesSet = 0; - ignitionSchedule1.endScheduleSetByDecoder = false; - ignitionCount += 1; //Increment the ignition counter - currentStatus.actualDwell = DWELL_AVERAGE( (micros() - ignitionSchedule1.startTime) ); - - //If there is a next schedule queued up, activate it - if(ignitionSchedule1.hasNextSchedule == true) - { - SET_COMPARE(IGN1_COMPARE, ignitionSchedule1.nextStartCompare); - ignitionSchedule1.Status = PENDING; - ignitionSchedule1.schedulesSet = 1; - ignitionSchedule1.hasNextSchedule = false; - } - else{ IGN1_TIMER_DISABLE(); } - } - else if (ignitionSchedule1.Status == OFF) - { - //Catch any spurious interrupts. This really shouldn't ever be called, but there as a safety - IGN1_TIMER_DISABLE(); - } + ignitionScheduleISR(ignitionSchedule1); } -#endif -#if IGN_CHANNELS >= 2 #if defined(CORE_AVR) //AVR chips use the ISR for this ISR(TIMER5_COMPB_vect) //cppcheck-suppress misra-c2012-8.2 #else -void ignitionSchedule2Interrupt(void) +void ignitionSchedule2Interrupt(void) //Most ARM chips can simply call a function #endif { - if (ignitionSchedule2.Status == PENDING) //Check to see if this schedule is turn on - { - ignitionSchedule2.StartCallback(); - ignitionSchedule2.Status = RUNNING; //Set the status to be in progress (ie The start callback has been called, but not the end callback) - ignitionSchedule2.startTime = micros(); - if(ignitionSchedule2.endScheduleSetByDecoder == true) { SET_COMPARE(IGN2_COMPARE, ignitionSchedule2.endCompare); } //If the decoder has set the end compare value, assign it to the next compare - else { SET_COMPARE(IGN2_COMPARE, IGN2_COUNTER + uS_TO_TIMER_COMPARE(ignitionSchedule2.duration) ); } //If the decoder based timing isn't set, doing this here prevents a potential overflow that can occur at low RPMs - } - else if (ignitionSchedule2.Status == RUNNING) - { - ignitionSchedule2.Status = OFF; //Turn off the schedule - ignitionSchedule2.EndCallback(); - ignitionSchedule2.schedulesSet = 0; - ignitionSchedule2.endScheduleSetByDecoder = false; - ignitionCount += 1; //Increment the ignition counter - currentStatus.actualDwell = DWELL_AVERAGE( (micros() - ignitionSchedule2.startTime) ); - - //If there is a next schedule queued up, activate it - if(ignitionSchedule2.hasNextSchedule == true) - { - SET_COMPARE(IGN2_COMPARE, ignitionSchedule2.nextStartCompare); - ignitionSchedule2.Status = PENDING; - ignitionSchedule2.schedulesSet = 1; - ignitionSchedule2.hasNextSchedule = false; - } - else{ IGN2_TIMER_DISABLE(); } - } - else if (ignitionSchedule2.Status == OFF) - { - //Catch any spurious interrupts. This really shouldn't ever be called, but there as a safety - IGN2_TIMER_DISABLE(); - } + ignitionScheduleISR(ignitionSchedule2); } -#endif -#if IGN_CHANNELS >= 3 #if defined(CORE_AVR) //AVR chips use the ISR for this ISR(TIMER5_COMPC_vect) //cppcheck-suppress misra-c2012-8.2 #else -void ignitionSchedule3Interrupt(void) +void ignitionSchedule3Interrupt(void) //Most ARM chips can simply call a function #endif { - if (ignitionSchedule3.Status == PENDING) //Check to see if this schedule is turn on - { - ignitionSchedule3.StartCallback(); - ignitionSchedule3.Status = RUNNING; //Set the status to be in progress (ie The start callback has been called, but not the end callback) - ignitionSchedule3.startTime = micros(); - if(ignitionSchedule3.endScheduleSetByDecoder == true) { SET_COMPARE(IGN3_COMPARE, ignitionSchedule3.endCompare ); } //If the decoder has set the end compare value, assign it to the next compare - else { SET_COMPARE(IGN3_COMPARE, IGN3_COUNTER + uS_TO_TIMER_COMPARE(ignitionSchedule3.duration)); } //If the decoder based timing isn't set, doing this here prevents a potential overflow that can occur at low RPMs - } - else if (ignitionSchedule3.Status == RUNNING) - { - ignitionSchedule3.Status = OFF; //Turn off the schedule - ignitionSchedule3.EndCallback(); - ignitionSchedule3.schedulesSet = 0; - ignitionSchedule3.endScheduleSetByDecoder = false; - ignitionCount += 1; //Increment the ignition counter - currentStatus.actualDwell = DWELL_AVERAGE( (micros() - ignitionSchedule3.startTime) ); - - //If there is a next schedule queued up, activate it - if(ignitionSchedule3.hasNextSchedule == true) - { - SET_COMPARE(IGN3_COMPARE, ignitionSchedule3.nextStartCompare); - ignitionSchedule3.Status = PENDING; - ignitionSchedule3.schedulesSet = 1; - ignitionSchedule3.hasNextSchedule = false; - } - else { IGN3_TIMER_DISABLE(); } - } - else if (ignitionSchedule3.Status == OFF) - { - //Catch any spurious interrupts. This really shouldn't ever be called, but there as a safety - IGN3_TIMER_DISABLE(); - } + ignitionScheduleISR(ignitionSchedule3); } -#endif -#if IGN_CHANNELS >= 4 #if defined(CORE_AVR) //AVR chips use the ISR for this ISR(TIMER4_COMPA_vect) //cppcheck-suppress misra-c2012-8.2 #else -void ignitionSchedule4Interrupt(void) +void ignitionSchedule4Interrupt(void) //Most ARM chips can simply call a function #endif { - if (ignitionSchedule4.Status == PENDING) //Check to see if this schedule is turn on - { - ignitionSchedule4.StartCallback(); - ignitionSchedule4.Status = RUNNING; //Set the status to be in progress (ie The start callback has been called, but not the end callback) - ignitionSchedule4.startTime = micros(); - if(ignitionSchedule4.endScheduleSetByDecoder == true) { SET_COMPARE(IGN4_COMPARE, ignitionSchedule4.endCompare); } //If the decoder has set the end compare value, assign it to the next compare - else { SET_COMPARE(IGN4_COMPARE, IGN4_COUNTER + uS_TO_TIMER_COMPARE(ignitionSchedule4.duration) ); } //If the decoder based timing isn't set, doing this here prevents a potential overflow that can occur at low RPMs - } - else if (ignitionSchedule4.Status == RUNNING) - { - ignitionSchedule4.Status = OFF; //Turn off the schedule - ignitionSchedule4.EndCallback(); - ignitionSchedule4.schedulesSet = 0; - ignitionSchedule4.endScheduleSetByDecoder = false; - ignitionCount += 1; //Increment the ignition counter - currentStatus.actualDwell = DWELL_AVERAGE( (micros() - ignitionSchedule4.startTime) ); - - //If there is a next schedule queued up, activate it - if(ignitionSchedule4.hasNextSchedule == true) - { - SET_COMPARE(IGN4_COMPARE, ignitionSchedule4.nextStartCompare); - ignitionSchedule4.Status = PENDING; - ignitionSchedule4.schedulesSet = 1; - ignitionSchedule4.hasNextSchedule = false; - } - else { IGN4_TIMER_DISABLE(); } - } - else if (ignitionSchedule4.Status == OFF) - { - //Catch any spurious interrupts. This really shouldn't ever be called, but there as a safety - IGN4_TIMER_DISABLE(); - } + ignitionScheduleISR(ignitionSchedule4); } -#endif -#if IGN_CHANNELS >= 5 #if defined(CORE_AVR) //AVR chips use the ISR for this ISR(TIMER4_COMPC_vect) //cppcheck-suppress misra-c2012-8.2 #else -void ignitionSchedule5Interrupt(void) +void ignitionSchedule5Interrupt(void) //Most ARM chips can simply call a function #endif { - if (ignitionSchedule5.Status == PENDING) //Check to see if this schedule is turn on - { - ignitionSchedule5.StartCallback(); - ignitionSchedule5.Status = RUNNING; //Set the status to be in progress (ie The start callback has been called, but not the end callback) - ignitionSchedule5.startTime = micros(); - if(ignitionSchedule5.endScheduleSetByDecoder == true) { SET_COMPARE(IGN5_COMPARE, ignitionSchedule5.endCompare); } //If the decoder has set the end compare value, assign it to the next compare - else { SET_COMPARE(IGN5_COMPARE, IGN5_COUNTER + uS_TO_TIMER_COMPARE(ignitionSchedule5.duration) ); } //If the decoder based timing isn't set, doing this here prevents a potential overflow that can occur at low RPMs - } - else if (ignitionSchedule5.Status == RUNNING) - { - ignitionSchedule5.Status = OFF; //Turn off the schedule - ignitionSchedule5.EndCallback(); - ignitionSchedule5.schedulesSet = 0; - ignitionSchedule5.endScheduleSetByDecoder = false; - ignitionCount += 1; //Increment the ignition counter - currentStatus.actualDwell = DWELL_AVERAGE( (micros() - ignitionSchedule5.startTime) ); - - //If there is a next schedule queued up, activate it - if(ignitionSchedule5.hasNextSchedule == true) - { - SET_COMPARE(IGN5_COMPARE, ignitionSchedule5.nextStartCompare); - ignitionSchedule5.Status = PENDING; - ignitionSchedule5.schedulesSet = 1; - ignitionSchedule5.hasNextSchedule = false; - } - else{ IGN5_TIMER_DISABLE(); } - } - else if (ignitionSchedule5.Status == OFF) - { - //Catch any spurious interrupts. This really shouldn't ever be called, but there as a safety - IGN5_TIMER_DISABLE(); - } + ignitionScheduleISR(ignitionSchedule5); } -#endif #if IGN_CHANNELS >= 6 #if defined(CORE_AVR) //AVR chips use the ISR for this ISR(TIMER4_COMPB_vect) //cppcheck-suppress misra-c2012-8.2 #else -void ignitionSchedule6Interrupt(void) +void ignitionSchedule6Interrupt(void) //Most ARM chips can simply call a function #endif { - if (ignitionSchedule6.Status == PENDING) //Check to see if this schedule is turn on - { - ignitionSchedule6.StartCallback(); - ignitionSchedule6.Status = RUNNING; //Set the status to be in progress (ie The start callback has been called, but not the end callback) - ignitionSchedule6.startTime = micros(); - if(ignitionSchedule6.endScheduleSetByDecoder == true) { SET_COMPARE(IGN6_COMPARE, ignitionSchedule6.endCompare); } //If the decoder has set the end compare value, assign it to the next compare - else { SET_COMPARE(IGN6_COMPARE, IGN6_COUNTER + uS_TO_TIMER_COMPARE(ignitionSchedule6.duration) ); } //If the decoder based timing isn't set, doing this here prevents a potential overflow that can occur at low RPMs - } - else if (ignitionSchedule6.Status == RUNNING) - { - ignitionSchedule6.Status = OFF; //Turn off the schedule - ignitionSchedule6.EndCallback(); - ignitionSchedule6.schedulesSet = 0; - ignitionSchedule6.endScheduleSetByDecoder = false; - ignitionCount += 1; //Increment the ignition counter - currentStatus.actualDwell = DWELL_AVERAGE( (micros() - ignitionSchedule6.startTime) ); - - //If there is a next schedule queued up, activate it - if(ignitionSchedule6.hasNextSchedule == true) - { - SET_COMPARE(IGN6_COMPARE, ignitionSchedule6.nextStartCompare); - ignitionSchedule6.Status = PENDING; - ignitionSchedule6.schedulesSet = 1; - ignitionSchedule6.hasNextSchedule = false; - } - else{ IGN6_TIMER_DISABLE(); } - } - else if (ignitionSchedule6.Status == OFF) - { - //Catch any spurious interrupts. This really shouldn't ever be called, but there as a safety - IGN6_TIMER_DISABLE(); - } + ignitionScheduleISR(ignitionSchedule6); } #endif @@ -1476,41 +1046,10 @@ void ignitionSchedule6Interrupt(void) #if defined(CORE_AVR) //AVR chips use the ISR for this ISR(TIMER3_COMPC_vect) //cppcheck-suppress misra-c2012-8.2 #else -void ignitionSchedule7Interrupt(void) +void ignitionSchedule7Interrupt(void) //Most ARM chips can simply call a function #endif { - if (ignitionSchedule7.Status == PENDING) //Check to see if this schedule is turn on - { - ignitionSchedule7.StartCallback(); - ignitionSchedule7.Status = RUNNING; //Set the status to be in progress (ie The start callback has been called, but not the end callback) - ignitionSchedule7.startTime = micros(); - if(ignitionSchedule7.endScheduleSetByDecoder == true) { SET_COMPARE(IGN7_COMPARE, ignitionSchedule7.endCompare); } //If the decoder has set the end compare value, assign it to the next compare - else { SET_COMPARE(IGN7_COMPARE, IGN7_COUNTER + uS_TO_TIMER_COMPARE(ignitionSchedule7.duration) ); } //If the decoder based timing isn't set, doing this here prevents a potential overflow that can occur at low RPMs - } - else if (ignitionSchedule7.Status == RUNNING) - { - ignitionSchedule7.Status = OFF; //Turn off the schedule - ignitionSchedule7.EndCallback(); - ignitionSchedule7.schedulesSet = 0; - ignitionSchedule7.endScheduleSetByDecoder = false; - ignitionCount += 1; //Increment the ignition counter - currentStatus.actualDwell = DWELL_AVERAGE( (micros() - ignitionSchedule7.startTime) ); - - //If there is a next schedule queued up, activate it - if(ignitionSchedule7.hasNextSchedule == true) - { - SET_COMPARE(IGN7_COMPARE, ignitionSchedule7.nextStartCompare); - ignitionSchedule7.Status = PENDING; - ignitionSchedule7.schedulesSet = 1; - ignitionSchedule7.hasNextSchedule = false; - } - else{ IGN7_TIMER_DISABLE(); } - } - else if (ignitionSchedule7.Status == OFF) - { - //Catch any spurious interrupts. This really shouldn't ever be called, but there as a safety - IGN7_TIMER_DISABLE(); - } + ignitionScheduleISR(ignitionSchedule7); } #endif @@ -1518,41 +1057,10 @@ void ignitionSchedule7Interrupt(void) #if defined(CORE_AVR) //AVR chips use the ISR for this ISR(TIMER3_COMPB_vect) //cppcheck-suppress misra-c2012-8.2 #else -void ignitionSchedule8Interrupt(void) +void ignitionSchedule8Interrupt(void) //Most ARM chips can simply call a function #endif { - if (ignitionSchedule8.Status == PENDING) //Check to see if this schedule is turn on - { - ignitionSchedule8.StartCallback(); - ignitionSchedule8.Status = RUNNING; //Set the status to be in progress (ie The start callback has been called, but not the end callback) - ignitionSchedule8.startTime = micros(); - if(ignitionSchedule8.endScheduleSetByDecoder == true) { SET_COMPARE(IGN8_COMPARE, ignitionSchedule8.endCompare); } //If the decoder has set the end compare value, assign it to the next compare - else { SET_COMPARE(IGN8_COMPARE, IGN8_COUNTER + uS_TO_TIMER_COMPARE(ignitionSchedule8.duration) ); } //If the decoder based timing isn't set, doing this here prevents a potential overflow that can occur at low RPMs - } - else if (ignitionSchedule8.Status == RUNNING) - { - ignitionSchedule8.Status = OFF; //Turn off the schedule - ignitionSchedule8.EndCallback(); - ignitionSchedule8.schedulesSet = 0; - ignitionSchedule8.endScheduleSetByDecoder = false; - ignitionCount += 1; //Increment the ignition counter - currentStatus.actualDwell = DWELL_AVERAGE( (micros() - ignitionSchedule8.startTime) ); - - //If there is a next schedule queued up, activate it - if(ignitionSchedule8.hasNextSchedule == true) - { - SET_COMPARE(IGN8_COMPARE, ignitionSchedule8.nextStartCompare); - ignitionSchedule8.Status = PENDING; - ignitionSchedule8.schedulesSet = 1; - ignitionSchedule8.hasNextSchedule = false; - } - else{ IGN8_TIMER_DISABLE(); } - } - else if (ignitionSchedule8.Status == OFF) - { - //Catch any spurious interrupts. This really shouldn't ever be called, but there as a safety - IGN8_TIMER_DISABLE(); - } + ignitionScheduleISR(ignitionSchedule8); } #endif @@ -1574,16 +1082,24 @@ void disablePendingFuelSchedule(byte channel) if(fuelSchedule4.Status == PENDING) { fuelSchedule4.Status = OFF; } break; case 4: +#if (INJ_CHANNELS >= 5) if(fuelSchedule5.Status == PENDING) { fuelSchedule5.Status = OFF; } +#endif break; case 5: +#if (INJ_CHANNELS >= 6) if(fuelSchedule6.Status == PENDING) { fuelSchedule6.Status = OFF; } +#endif break; case 6: +#if (INJ_CHANNELS >= 7) if(fuelSchedule7.Status == PENDING) { fuelSchedule7.Status = OFF; } +#endif break; case 7: +#if (INJ_CHANNELS >= 8) if(fuelSchedule8.Status == PENDING) { fuelSchedule8.Status = OFF; } +#endif break; } interrupts(); @@ -1608,15 +1124,21 @@ void disablePendingIgnSchedule(byte channel) case 4: if(ignitionSchedule5.Status == PENDING) { ignitionSchedule5.Status = OFF; } break; - case 5: +#if IGN_CHANNELS >= 6 + case 6: if(ignitionSchedule6.Status == PENDING) { ignitionSchedule6.Status = OFF; } break; - case 6: +#endif +#if IGN_CHANNELS >= 7 + case 7: if(ignitionSchedule7.Status == PENDING) { ignitionSchedule7.Status = OFF; } break; - case 7: +#endif +#if IGN_CHANNELS >= 8 + case 8: if(ignitionSchedule8.Status == PENDING) { ignitionSchedule8.Status = OFF; } break; +#endif } interrupts(); } diff --git a/speeduino/scheduler.h b/speeduino/scheduler.h index fde90916..e1c01cbf 100644 --- a/speeduino/scheduler.h +++ b/speeduino/scheduler.h @@ -50,73 +50,40 @@ See page 136 of the processors datasheet: http://www.atmel.com/Images/doc2549.pd #define DWELL_AVERAGE(input) (((long)input * (256 - DWELL_AVERAGE_ALPHA) + ((long)currentStatus.actualDwell * DWELL_AVERAGE_ALPHA))) >> 8 //#define DWELL_AVERAGE(input) (currentStatus.dwell) //Can be use to disable the above for testing -extern void (*inj1StartFunction)(void); -extern void (*inj1EndFunction)(void); -extern void (*inj2StartFunction)(void); -extern void (*inj2EndFunction)(void); -extern void (*inj3StartFunction)(void); -extern void (*inj3EndFunction)(void); -extern void (*inj4StartFunction)(void); -extern void (*inj4EndFunction)(void); -#if (INJ_CHANNELS >= 5) -extern void (*inj5StartFunction)(void); -extern void (*inj5EndFunction)(void); -#endif -#if (INJ_CHANNELS >= 6) -extern void (*inj6StartFunction)(void); -extern void (*inj6EndFunction)(void); -#endif -#if (INJ_CHANNELS >= 7) -extern void (*inj7StartFunction)(void); -extern void (*inj7EndFunction)(void); -#endif -#if (INJ_CHANNELS >= 8) -extern void (*inj8StartFunction)(void); -extern void (*inj8EndFunction)(void); -#endif - -/** @name IgnitionCallbacks - * These are the (global) function pointers that get called to begin and end the ignition coil charging. - * They are required for the various spark output modes. - * @{ -*/ -extern void (*ign1StartFunction)(void); -extern void (*ign1EndFunction)(void); -extern void (*ign2StartFunction)(void); -extern void (*ign2EndFunction)(void); -extern void (*ign3StartFunction)(void); -extern void (*ign3EndFunction)(void); -extern void (*ign4StartFunction)(void); -extern void (*ign4EndFunction)(void); -extern void (*ign5StartFunction)(void); -extern void (*ign5EndFunction)(void); -extern void (*ign6StartFunction)(void); -extern void (*ign6EndFunction)(void); -extern void (*ign7StartFunction)(void); -extern void (*ign7EndFunction)(void); -extern void (*ign8StartFunction)(void); -extern void (*ign8EndFunction)(void); -/** @} */ - void initialiseSchedulers(void); void beginInjectorPriming(void); + void setFuelSchedule1(unsigned long timeout, unsigned long duration); void setFuelSchedule2(unsigned long timeout, unsigned long duration); void setFuelSchedule3(unsigned long timeout, unsigned long duration); void setFuelSchedule4(unsigned long timeout, unsigned long duration); -//void setFuelSchedule5(void (*startCallback)(), unsigned long timeout, unsigned long duration, void(*endCallback)()); //Schedule 5 remains a special case for now due to the way it's implemented +#if INJ_CHANNELS >= 5 void setFuelSchedule5(unsigned long timeout, unsigned long duration); +#endif +#if INJ_CHANNELS >= 6 void setFuelSchedule6(unsigned long timeout, unsigned long duration); +#endif +#if INJ_CHANNELS >= 7 void setFuelSchedule7(unsigned long timeout, unsigned long duration); +#endif +#if INJ_CHANNELS >= 8 void setFuelSchedule8(unsigned long timeout, unsigned long duration); -void setIgnitionSchedule1(void (*startCallback)(), unsigned long timeout, unsigned long duration, void(*endCallback)()); -void setIgnitionSchedule2(void (*startCallback)(), unsigned long timeout, unsigned long duration, void(*endCallback)()); -void setIgnitionSchedule3(void (*startCallback)(), unsigned long timeout, unsigned long duration, void(*endCallback)()); -void setIgnitionSchedule4(void (*startCallback)(), unsigned long timeout, unsigned long duration, void(*endCallback)()); -void setIgnitionSchedule5(void (*startCallback)(), unsigned long timeout, unsigned long duration, void(*endCallback)()); -void setIgnitionSchedule6(void (*startCallback)(), unsigned long timeout, unsigned long duration, void(*endCallback)()); -void setIgnitionSchedule7(void (*startCallback)(), unsigned long timeout, unsigned long duration, void(*endCallback)()); -void setIgnitionSchedule8(void (*startCallback)(), unsigned long timeout, unsigned long duration, void(*endCallback)()); +#endif + +void setIgnitionSchedule1(unsigned long timeout, unsigned long duration); +void setIgnitionSchedule2(unsigned long timeout, unsigned long duration); +void setIgnitionSchedule3(unsigned long timeout, unsigned long duration); +void setIgnitionSchedule4(unsigned long timeout, unsigned long duration); +void setIgnitionSchedule5(unsigned long timeout, unsigned long duration); +#if IGN_CHANNELS >= 6 +void setIgnitionSchedule6(unsigned long timeout, unsigned long duration); +#endif +#if IGN_CHANNELS >= 7 +void setIgnitionSchedule7(unsigned long timeout, unsigned long duration); +#endif +#if IGN_CHANNELS >= 8 +void setIgnitionSchedule8(unsigned long timeout, unsigned long duration); +#endif void disablePendingFuelSchedule(byte channel); void disablePendingIgnSchedule(byte channel); @@ -176,12 +143,27 @@ enum ScheduleStatus {OFF, PENDING, STAGED, RUNNING}; //The statuses that a sched /** Ignition schedule. */ -struct Schedule { +struct IgnitionSchedule { + + // Deduce the real types of the counter and compare registers. + // COMPARE_TYPE is NOT the same - it's just an integer type wide enough to + // store 16-bit counter/compare calculation results. + using counter_t = decltype(IGN1_COUNTER); + using compare_t = decltype(IGN1_COMPARE); + + IgnitionSchedule( counter_t &counter, compare_t &compare, + void (&_pTimerDisable)(), void (&_pTimerEnable)()) + : counter(counter) + , compare(compare) + , pTimerDisable(_pTimerDisable) + , pTimerEnable(_pTimerEnable) + { + } + volatile unsigned long duration;///< Scheduled duration (uS ?) volatile ScheduleStatus Status; ///< Schedule status: OFF, PENDING, STAGED, RUNNING - volatile byte schedulesSet; ///< A counter of how many times the schedule has been set - void (*StartCallback)(); ///< Start Callback function for schedule - void (*EndCallback)(); ///< End Callback function for schedule + void (*pStartCallback)(void); ///< Start Callback function for schedule + void (*pEndCallback)(void); ///< End Callback function for schedule volatile unsigned long startTime; /**< The system time (in uS) that the schedule started, used by the overdwell protection in timers.ino */ volatile COMPARE_TYPE startCompare; ///< The counter value of the timer when this will start volatile COMPARE_TYPE endCompare; ///< The counter value of the timer when this will end @@ -190,116 +172,81 @@ struct Schedule { COMPARE_TYPE nextEndCompare; ///< Planned end of next schedule (when current schedule is RUNNING) volatile bool hasNextSchedule = false; ///< Enable flag for planned next schedule (when current schedule is RUNNING) volatile bool endScheduleSetByDecoder = false; + + counter_t &counter; // Reference to the counter register. E.g. TCNT3 + compare_t &compare; // Reference to the compare register. E.g. OCR3A + void (&pTimerDisable)(); // Reference to the timer disable function + void (&pTimerEnable)(); // Reference to the timer enable function }; + + /** Fuel injection schedule. * Fuel schedules don't use the callback pointers, or the startTime/endScheduleSetByDecoder variables. * They are removed in this struct to save RAM. */ struct FuelSchedule { + + // Deduce the real types of the counter and compare registers. + // COMPARE_TYPE is NOT the same - it's just an integer type wide enough to + // store 16-bit counter/compare calculation results. + using counter_t = decltype(FUEL1_COUNTER); + using compare_t = decltype(FUEL1_COMPARE); + + FuelSchedule( counter_t &counter, compare_t &compare, + void (&_pTimerDisable)(), void (&_pTimerEnable)()) + : counter(counter) + , compare(compare) + , pTimerDisable(_pTimerDisable) + , pTimerEnable(_pTimerEnable) + { + } + volatile unsigned long duration;///< Scheduled duration (uS ?) volatile ScheduleStatus Status; ///< Schedule status: OFF, PENDING, STAGED, RUNNING - volatile byte schedulesSet; ///< A counter of how many times the schedule has been set volatile COMPARE_TYPE startCompare; ///< The counter value of the timer when this will start volatile COMPARE_TYPE endCompare; ///< The counter value of the timer when this will end - + void (*pStartFunction)(void); + void (*pEndFunction)(void); COMPARE_TYPE nextStartCompare; COMPARE_TYPE nextEndCompare; volatile bool hasNextSchedule = false; -}; -//volatile Schedule *timer3Aqueue[4]; -//Schedule *timer3Bqueue[4]; -//Schedule *timer3Cqueue[4]; + counter_t &counter; // Reference to the counter register. E.g. TCNT3 + compare_t &compare; // Reference to the compare register. E.g. OCR3A + void (&pTimerDisable)(); // Reference to the timer disable function + void (&pTimerEnable)(); // Reference to the timer enable function +}; extern FuelSchedule fuelSchedule1; extern FuelSchedule fuelSchedule2; extern FuelSchedule fuelSchedule3; extern FuelSchedule fuelSchedule4; +#if INJ_CHANNELS >= 5 extern FuelSchedule fuelSchedule5; +#endif +#if INJ_CHANNELS >= 6 extern FuelSchedule fuelSchedule6; +#endif +#if INJ_CHANNELS >= 7 extern FuelSchedule fuelSchedule7; +#endif +#if INJ_CHANNELS >= 8 extern FuelSchedule fuelSchedule8; +#endif -extern Schedule ignitionSchedule1; -extern Schedule ignitionSchedule2; -extern Schedule ignitionSchedule3; -extern Schedule ignitionSchedule4; -extern Schedule ignitionSchedule5; -extern Schedule ignitionSchedule6; -extern Schedule ignitionSchedule7; -extern Schedule ignitionSchedule8; - -//IgnitionSchedule nullSchedule; //This is placed at the end of the queue. It's status will always be set to OFF and hence will never perform any action within an ISR - -static inline COMPARE_TYPE setQueue(volatile Schedule *queue[], Schedule *schedule1, Schedule *schedule2, unsigned int CNT) -{ - //Create an array of all the upcoming targets, relative to the current count on the timer - unsigned int tmpQueue[4]; - - //Set the initial queue state. This order matches the tmpQueue order - if(schedule1->Status == OFF) - { - queue[0] = schedule2; - queue[1] = schedule2; - tmpQueue[0] = schedule2->startCompare - CNT; - tmpQueue[1] = schedule2->endCompare - CNT; - } - else - { - queue[0] = schedule1; - queue[1] = schedule1; - tmpQueue[0] = schedule1->startCompare - CNT; - tmpQueue[1] = schedule1->endCompare - CNT; - } - - if(schedule2->Status == OFF) - { - queue[2] = schedule1; - queue[3] = schedule1; - tmpQueue[2] = schedule1->startCompare - CNT; - tmpQueue[3] = schedule1->endCompare - CNT; - } - else - { - queue[2] = schedule2; - queue[3] = schedule2; - tmpQueue[2] = schedule2->startCompare - CNT; - tmpQueue[3] = schedule2->endCompare - CNT; - } - - - //Sort the queues. Both queues are kept in sync. - //This implements a sorting networking based on the Bose-Nelson sorting network - //See: pages.ripco.net/~jgamble/nw.html - #define SWAP(x,y) if(tmpQueue[y] < tmpQueue[x]) { unsigned int tmp = tmpQueue[x]; tmpQueue[x] = tmpQueue[y]; tmpQueue[y] = tmp; volatile Schedule *tmpS = queue[x]; queue[x] = queue[y]; queue[y] = tmpS; } - /*SWAP(0, 1); */ //Likely not needed - /*SWAP(2, 3); */ //Likely not needed - SWAP(0, 2); - SWAP(1, 3); - SWAP(1, 2); - - //Return the next compare time in the queue - return tmpQueue[0] + CNT; //Return the -} - -/* - * Moves all the Schedules in a queue forward one position. - * The current item (0) is discarded - * The final queue slot is set to nullSchedule to indicate that no action should be taken - */ -static inline unsigned int popQueue(volatile Schedule *queue[]) -{ - queue[0] = queue[1]; - queue[1] = queue[2]; - queue[2] = queue[3]; - //queue[3] = &nullSchedule; - - unsigned int returnCompare; - if( queue[0]->Status == PENDING ) { returnCompare = queue[0]->startCompare; } - else { returnCompare = queue[0]->endCompare; } - - return returnCompare; -} - +extern IgnitionSchedule ignitionSchedule1; +extern IgnitionSchedule ignitionSchedule2; +extern IgnitionSchedule ignitionSchedule3; +extern IgnitionSchedule ignitionSchedule4; +extern IgnitionSchedule ignitionSchedule5; +#if IGN_CHANNELS >= 6 +extern IgnitionSchedule ignitionSchedule6; +#endif +#if IGN_CHANNELS >= 7 +extern IgnitionSchedule ignitionSchedule7; +#endif +#if IGN_CHANNELS >= 8 +extern IgnitionSchedule ignitionSchedule8; +#endif #endif // SCHEDULER_H diff --git a/speeduino/speeduino.ino b/speeduino/speeduino.ino index 70ff07a1..9f9fb273 100644 --- a/speeduino/speeduino.ino +++ b/speeduino/speeduino.ino @@ -1050,13 +1050,8 @@ void loop(void) uint32_t timeOut = calculateIgnitionTimeout(ignitionSchedule1, ignition1StartAngle, channel1IgnDegrees, crankAngle); if ( (timeOut > 0U) && (BIT_CHECK(ignitionChannelsOn, IGN1_CMD_BIT)) ) { - - setIgnitionSchedule1(ign1StartFunction, - //((unsigned long)(ignition1StartAngle - crankAngle) * (unsigned long)timePerDegree), - timeOut, - currentStatus.dwell + fixedCrankingOverride, //((unsigned long)((unsigned long)currentStatus.dwell* currentStatus.RPM) / newRPM) + fixedCrankingOverride, - ign1EndFunction - ); + setIgnitionSchedule1(timeOut, + currentStatus.dwell + fixedCrankingOverride); } #endif @@ -1087,11 +1082,8 @@ void loop(void) if ( (ignition2StartTime > 0) && (BIT_CHECK(ignitionChannelsOn, IGN2_CMD_BIT)) ) { - setIgnitionSchedule2(ign2StartFunction, - ignition2StartTime, - currentStatus.dwell + fixedCrankingOverride, - ign2EndFunction - ); + setIgnitionSchedule2(ignition2StartTime, + currentStatus.dwell + fixedCrankingOverride); } } #endif @@ -1103,11 +1095,8 @@ void loop(void) if ( (ignition3StartTime > 0) && (BIT_CHECK(ignitionChannelsOn, IGN3_CMD_BIT)) ) { - setIgnitionSchedule3(ign3StartFunction, - ignition3StartTime, - currentStatus.dwell + fixedCrankingOverride, - ign3EndFunction - ); + setIgnitionSchedule3(ignition3StartTime, + currentStatus.dwell + fixedCrankingOverride); } } #endif @@ -1119,11 +1108,8 @@ void loop(void) if ( (ignition4StartTime > 0) && (BIT_CHECK(ignitionChannelsOn, IGN4_CMD_BIT)) ) { - setIgnitionSchedule4(ign4StartFunction, - ignition4StartTime, - currentStatus.dwell + fixedCrankingOverride, - ign4EndFunction - ); + setIgnitionSchedule4(ignition4StartTime, + currentStatus.dwell + fixedCrankingOverride); } } #endif @@ -1135,11 +1121,8 @@ void loop(void) if ( (ignition5StartTime > 0) && (BIT_CHECK(ignitionChannelsOn, IGN5_CMD_BIT)) ) { - setIgnitionSchedule5(ign5StartFunction, - ignition5StartTime, - currentStatus.dwell + fixedCrankingOverride, - ign5EndFunction - ); + setIgnitionSchedule5(ignition5StartTime, + currentStatus.dwell + fixedCrankingOverride); } } #endif @@ -1151,11 +1134,8 @@ void loop(void) if ( (ignition6StartTime > 0) && (BIT_CHECK(ignitionChannelsOn, IGN6_CMD_BIT)) ) { - setIgnitionSchedule6(ign6StartFunction, - ignition6StartTime, - currentStatus.dwell + fixedCrankingOverride, - ign6EndFunction - ); + setIgnitionSchedule6(ignition6StartTime, + currentStatus.dwell + fixedCrankingOverride); } } #endif @@ -1167,11 +1147,8 @@ void loop(void) if ( (ignition7StartTime > 0) && (BIT_CHECK(ignitionChannelsOn, IGN7_CMD_BIT)) ) { - setIgnitionSchedule7(ign7StartFunction, - ignition7StartTime, - currentStatus.dwell + fixedCrankingOverride, - ign7EndFunction - ); + setIgnitionSchedule7(ignition7StartTime, + currentStatus.dwell + fixedCrankingOverride); } } #endif @@ -1183,11 +1160,8 @@ void loop(void) if ( (ignition8StartTime > 0) && (BIT_CHECK(ignitionChannelsOn, IGN8_CMD_BIT)) ) { - setIgnitionSchedule8(ign8StartFunction, - ignition8StartTime, - currentStatus.dwell + fixedCrankingOverride, - ign8EndFunction - ); + setIgnitionSchedule8(ignition8StartTime, + currentStatus.dwell + fixedCrankingOverride); } } #endif diff --git a/speeduino/timers.cpp b/speeduino/timers.cpp index 6040c4bd..4794cb4c 100644 --- a/speeduino/timers.cpp +++ b/speeduino/timers.cpp @@ -56,6 +56,12 @@ void initialiseTimers(void) tachoOutputFlag = TACHO_INACTIVE; } +static inline void applyOverDwellCheck(IgnitionSchedule &schedule, uint32_t targetOverdwellTime) { + //Check first whether each spark output is currently on. Only check it's dwell time if it is + if ((schedule.Status == RUNNING) && (schedule.startTime < targetOverdwellTime)) { + schedule.pEndCallback(); schedule.Status = OFF; + } +} //Timer2 Overflow Interrupt Vector, called when the timer overflows. //Executes every ~1ms. @@ -76,21 +82,25 @@ void oneMSInterval(void) //Most ARM chips can simply call a function loop250ms++; loopSec++; - unsigned long targetOverdwellTime; - //Overdwell check - targetOverdwellTime = micros() - dwellLimit_uS; //Set a target time in the past that all coil charging must have begun after. If the coil charge began before this time, it's been running too long + uint32_t targetOverdwellTime = micros() - dwellLimit_uS; //Set a target time in the past that all coil charging must have begun after. If the coil charge began before this time, it's been running too long bool isCrankLocked = configPage4.ignCranklock && (currentStatus.RPM < currentStatus.crankRPM); //Dwell limiter is disabled during cranking on setups using the locked cranking timing. WE HAVE to do the RPM check here as relying on the engine cranking bit can be potentially too slow in updating - //Check first whether each spark output is currently on. Only check it's dwell time if it is - - if(ignitionSchedule1.Status == RUNNING) { if( (ignitionSchedule1.startTime < targetOverdwellTime) && (configPage4.useDwellLim) && (isCrankLocked != true) ) { ign1EndFunction(); ignitionSchedule1.Status = OFF; } } - if(ignitionSchedule2.Status == RUNNING) { if( (ignitionSchedule2.startTime < targetOverdwellTime) && (configPage4.useDwellLim) && (isCrankLocked != true) ) { ign2EndFunction(); ignitionSchedule2.Status = OFF; } } - if(ignitionSchedule3.Status == RUNNING) { if( (ignitionSchedule3.startTime < targetOverdwellTime) && (configPage4.useDwellLim) && (isCrankLocked != true) ) { ign3EndFunction(); ignitionSchedule3.Status = OFF; } } - if(ignitionSchedule4.Status == RUNNING) { if( (ignitionSchedule4.startTime < targetOverdwellTime) && (configPage4.useDwellLim) && (isCrankLocked != true) ) { ign4EndFunction(); ignitionSchedule4.Status = OFF; } } - if(ignitionSchedule5.Status == RUNNING) { if( (ignitionSchedule5.startTime < targetOverdwellTime) && (configPage4.useDwellLim) && (isCrankLocked != true) ) { ign5EndFunction(); ignitionSchedule5.Status = OFF; } } - if(ignitionSchedule6.Status == RUNNING) { if( (ignitionSchedule6.startTime < targetOverdwellTime) && (configPage4.useDwellLim) && (isCrankLocked != true) ) { ign6EndFunction(); ignitionSchedule6.Status = OFF; } } - if(ignitionSchedule7.Status == RUNNING) { if( (ignitionSchedule7.startTime < targetOverdwellTime) && (configPage4.useDwellLim) && (isCrankLocked != true) ) { ign7EndFunction(); ignitionSchedule7.Status = OFF; } } - if(ignitionSchedule8.Status == RUNNING) { if( (ignitionSchedule8.startTime < targetOverdwellTime) && (configPage4.useDwellLim) && (isCrankLocked != true) ) { ign8EndFunction(); ignitionSchedule8.Status = OFF; } } + if ((configPage4.useDwellLim == 1) && (isCrankLocked != true)) { + applyOverDwellCheck(ignitionSchedule1, targetOverdwellTime); + applyOverDwellCheck(ignitionSchedule2, targetOverdwellTime); + applyOverDwellCheck(ignitionSchedule3, targetOverdwellTime); + applyOverDwellCheck(ignitionSchedule4, targetOverdwellTime); + applyOverDwellCheck(ignitionSchedule5, targetOverdwellTime); +#if IGN_CHANNELS >= 6 + applyOverDwellCheck(ignitionSchedule6, targetOverdwellTime); +#endif +#if IGN_CHANNELS >= 7 + applyOverDwellCheck(ignitionSchedule7, targetOverdwellTime); +#endif +#if IGN_CHANNELS >= 8 + applyOverDwellCheck(ignitionSchedule8, targetOverdwellTime); +#endif + } //Tacho is flagged as being ready for a pulse by the ignition outputs, or the sweep interval upon startup @@ -179,7 +189,6 @@ void oneMSInterval(void) //Most ARM chips can simply call a function #if defined(CORE_STM32) //debug purpose, only visual for running code digitalWrite(LED_BUILTIN, !digitalRead(LED_BUILTIN)); #endif - } //1Hz loop diff --git a/speeduino/timers.h b/speeduino/timers.h index 16216972..e1cf6c27 100644 --- a/speeduino/timers.h +++ b/speeduino/timers.h @@ -30,6 +30,7 @@ enum TachoOutputStatus {TACHO_INACTIVE, READY, ACTIVE}; //The 3 statuses that th extern volatile TachoOutputStatus tachoOutputFlag; extern volatile bool tachoSweepEnabled; extern volatile uint16_t tachoSweepIncr; + #define TACHO_SWEEP_TIME_MS 1500 #define TACHO_SWEEP_RAMP_MS (TACHO_SWEEP_TIME_MS * 2 / 3) #define MS_PER_SEC 1000 diff --git a/test/test_init/test_fuel_schedule_init.cpp b/test/test_init/test_fuel_schedule_init.cpp index 07dea23d..37b4a50e 100644 --- a/test/test_init/test_fuel_schedule_init.cpp +++ b/test/test_init/test_fuel_schedule_init.cpp @@ -34,25 +34,25 @@ static void __attribute__((noinline)) assert_fuel_schedules(uint16_t crankAngle, strcpy_P(msg, PSTR("req_fuel_uS")); TEST_ASSERT_EQUAL_UINT16_MESSAGE(reqFuel, req_fuel_uS, msg); - assert_fuel_channel(enabled[0], angle[0], INJ1_CMD_BIT, channel1InjDegrees, inj1StartFunction, inj1EndFunction); - assert_fuel_channel(enabled[1], angle[1], INJ2_CMD_BIT, channel2InjDegrees, inj2StartFunction, inj2EndFunction); - assert_fuel_channel(enabled[2], angle[2], INJ3_CMD_BIT, channel3InjDegrees, inj3StartFunction, inj3EndFunction); - assert_fuel_channel(enabled[3], angle[3], INJ4_CMD_BIT, channel4InjDegrees, inj4StartFunction, inj4EndFunction); + assert_fuel_channel(enabled[0], angle[0], INJ1_CMD_BIT, channel1InjDegrees, fuelSchedule1.pStartFunction, fuelSchedule1.pEndFunction); + assert_fuel_channel(enabled[1], angle[1], INJ2_CMD_BIT, channel2InjDegrees, fuelSchedule2.pStartFunction, fuelSchedule2.pEndFunction); + assert_fuel_channel(enabled[2], angle[2], INJ3_CMD_BIT, channel3InjDegrees, fuelSchedule3.pStartFunction, fuelSchedule3.pEndFunction); + assert_fuel_channel(enabled[3], angle[3], INJ4_CMD_BIT, channel4InjDegrees, fuelSchedule4.pStartFunction, fuelSchedule4.pEndFunction); #if INJ_CHANNELS>=5 - assert_fuel_channel(enabled[4], angle[4], INJ5_CMD_BIT, channel5InjDegrees, inj5StartFunction, inj5EndFunction); + assert_fuel_channel(enabled[4], angle[4], INJ5_CMD_BIT, channel5InjDegrees, fuelSchedule5.pStartFunction, fuelSchedule5.pEndFunction); #endif #if INJ_CHANNELS>=6 - assert_fuel_channel(enabled[5], angle[5], INJ6_CMD_BIT, channel6InjDegrees, inj6StartFunction, inj6EndFunction); + assert_fuel_channel(enabled[5], angle[5], INJ6_CMD_BIT, channel6InjDegrees, fuelSchedule6.pStartFunction, fuelSchedule6.pEndFunction); #endif #if INJ_CHANNELS>=7 - assert_fuel_channel(enabled[6], angle[6], INJ7_CMD_BIT, channel7InjDegrees, inj7StartFunction, inj7EndFunction); + assert_fuel_channel(enabled[6], angle[6], INJ7_CMD_BIT, channel7InjDegrees, fuelSchedule7.pStartFunction, fuelSchedule7.pEndFunction); #endif #if INJ_CHANNELS>=8 - assert_fuel_channel(enabled[7], angle[7], INJ8_CMD_BIT, channel8InjDegrees, inj8StartFunction, inj8EndFunction); + assert_fuel_channel(enabled[7], angle[7], INJ8_CMD_BIT, channel8InjDegrees, fuelSchedule8.pStartFunction, fuelSchedule8.pEndFunction); #endif } @@ -335,15 +335,12 @@ static void cylinder3_stroke4_semiseq_staged(void) configPage10.stagingEnabled = true; initialiseAll(); //Run the main initialise function #if INJ_CHANNELS>=6 - const bool enabled[] = {true, true, true, true, true, true, false, false}; const uint16_t angle[] = {0,80,160,0,80,160,0,0}; - assert_fuel_schedules(240U, reqFuel * 50U, enabled, angle); #else - const bool enabled[] = {true, true, true, true, false, false, false, false}; const uint16_t angle[] = {0,80,160,0,0,0,0,0}; - //assert_fuel_schedules(240U, reqFuel * 50U, enabled, angle); - assert_fuel_schedules(720U, reqFuel * 50U, enabled, angle); //Special case as 3 squirts per cycle MUST be over 720 degrees #endif + const bool enabled[] = {true, true, true, true, false, false, false, false}; + assert_fuel_schedules(720U, reqFuel * 50U, enabled, angle); //Special case as 3 squirts per cycle MUST be over 720 degrees } static void run_3_cylinder_4stroke_tests(void) @@ -402,14 +399,12 @@ static void cylinder3_stroke2_semiseq_staged(void) configPage10.stagingEnabled = true; initialiseAll(); //Run the main initialise function #if INJ_CHANNELS>=6 - const bool enabled[] = {true, true, true, true, true, true, false, false}; const uint16_t angle[] = {0,80,160,0,80,160,0,0}; - assert_fuel_schedules(120U, reqFuel * 100U, enabled, angle); #else - const bool enabled[] = {true, true, true, true, false, false, false, false}; const uint16_t angle[] = {0,80,160,0,0,0,0,0}; - assert_fuel_schedules(120U, reqFuel * 100U, enabled, angle); #endif + const bool enabled[] = {true, true, true, true, false, false, false, false}; + assert_fuel_schedules(120U, reqFuel * 100U, enabled, angle); } static void run_3_cylinder_2stroke_tests(void) @@ -427,15 +422,20 @@ static void run_3_cylinder_2stroke_tests(void) RUN_TEST_P(cylinder3_stroke2_semiseq_staged); } +static void assert_4cylinder_4stroke_seq_nostage(void) +{ + const bool enabled[] = {true, true, true, true, false, false, false, false}; + const uint16_t angle[] = {0,180,360,540,0,0,0,0}; + assert_fuel_schedules(720U, reqFuel * 100U, enabled, angle); +} + static void cylinder4_stroke4_seq_nostage(void) { configPage2.injLayout = INJ_SEQUENTIAL; configPage10.stagingEnabled = false; initialiseAll(); //Run the main initialise function - const bool enabled[] = {true, true, true, true, false, false, false, false}; - const uint16_t angle[] = {0,180,360,540,0,0,0,0}; - assert_fuel_schedules(720U, reqFuel * 100U, enabled, angle); - } + assert_4cylinder_4stroke_seq_nostage(); +} static void cylinder4_stroke4_semiseq_nostage(void) { @@ -447,6 +447,7 @@ static void cylinder4_stroke4_semiseq_nostage(void) assert_fuel_schedules(360U, reqFuel * 50U, enabled, angle); } + static void cylinder4_stroke4_seq_staged(void) { configPage2.injLayout = INJ_SEQUENTIAL; @@ -454,18 +455,16 @@ static void cylinder4_stroke4_seq_staged(void) initialiseAll(); //Run the main initialise function #if INJ_CHANNELS>=8 const bool enabled[] = {true, true, true, true, true, true, true, true}; - const uint16_t angle[] = {0,180,360,540,0,180,36}; + const uint16_t angle[] = {0,180,360,540,0,180,360,540}; assert_fuel_schedules(720U, reqFuel * 100U, enabled, angle); #elif INJ_CHANNELS >= 5 const bool enabled[] = {true, true, true, true, true, false, false, false}; const uint16_t angle[] = {0,180,360,540,0,0,0,0}; assert_fuel_schedules(720U, reqFuel * 100U, enabled, angle); #else - const bool enabled[] = {true, true, true, true, false, false, false, false}; - const uint16_t angle[] = {0,180,360,540,0,0,0,0}; - assert_fuel_schedules(720U, reqFuel * 100U, enabled, angle); + assert_4cylinder_4stroke_seq_nostage(); #endif - } +} static void cylinder4_stroke4_semiseq_staged(void) { @@ -638,7 +637,7 @@ static void cylinder6_stroke4_seq_nostage(void) initialiseAll(); //Run the main initialise function #if INJ_CHANNELS >= 6 const bool enabled[] = {true, true, true, true, true, true, false, false}; - const uint16_t angle[] = {0,120,240,360,480,600,0}; + const uint16_t angle[] = {0,120,240,360,480,600,0,0}; assert_fuel_schedules(720U, reqFuel * 100U, enabled, angle); #else const bool enabled[] = {true, true, true, false, false, false, false, false}; @@ -680,14 +679,12 @@ static void cylinder6_stroke4_semiseq_staged(void) configPage10.stagingEnabled = true; initialiseAll(); //Run the main initialise function #if INJ_CHANNELS >= 8 - const bool enabled[] = {true, true, true, true, true, true, true, true}; const uint16_t angle[] = {0,120,240,0,0,120,240,0}; - assert_fuel_schedules(720U, reqFuel * 50U, enabled, angle); #else - const bool enabled[] = {true, true, true, false, false, false, false, false}; const uint16_t angle[] = {0,120,240,0,0,0,0,0}; - assert_fuel_schedules(720U, reqFuel * 50U, enabled, angle); #endif + const bool enabled[] = {true, true, true, false, false, false, false, false}; + assert_fuel_schedules(720U, reqFuel * 50U, enabled, angle); } void run_6_cylinder_4stroke_tests(void) @@ -712,7 +709,7 @@ static void cylinder8_stroke4_seq_nostage(void) initialiseAll(); //Run the main initialise function #if INJ_CHANNELS >= 8 const bool enabled[] = {true, true, true, true, true, true, true, true}; - const uint16_t angle[] = {0,90,180,270,360,450,5}; + const uint16_t angle[] = {0,90,180,270,360,450,540,630}; assert_fuel_schedules(720U, reqFuel * 100U, enabled, angle); #else const bool enabled[] = {true, true, true, true, false, false, false, false}; @@ -788,11 +785,7 @@ static void cylinder_5_NoinjTiming_paired(void) { initialiseAll(); //Run the main initialise function -#if INJ_CHANNELS>=5 - const bool enabled[] = {true, true, true, true, true, false, false, false}; -#else const bool enabled[] = {true, true, true, true, false, false, false, false}; -#endif assert_fuel_schedules(720U, reqFuel * 50U, enabled, zeroAngles); } @@ -814,11 +807,7 @@ static void cylinder_8_NoinjTiming_paired(void) { initialiseAll(); //Run the main initialise function -#if INJ_CHANNELS>=8 - const bool enabled[] = {true, true, true, true, true, true, true, true}; -#else const bool enabled[] = {true, true, true, true, false, false, false, false}; -#endif assert_fuel_schedules(720U, reqFuel * 50U, enabled, zeroAngles); } @@ -849,7 +838,6 @@ static void cylinder_2_oddfire(void) const bool enabled[] = {true, true, false, false, false, false, false, false}; const uint16_t angle[] = {0,13,0,0,0,0,0,0}; - Serial.println(configPage2.engineType); assert_fuel_schedules(720U, reqFuel * 50U, enabled, angle); } @@ -888,6 +876,32 @@ static void run_oddfire_tests() RUN_TEST_P(cylinder8_stroke4_seq_nostage); } +static void test_partial_sync(void) +{ + configPage2.nCylinders = 4; + configPage2.strokes = FOUR_STROKE; + configPage2.engineType = EVEN_FIRE; + configPage2.injTiming = true; + configPage2.reqFuel = reqFuel; + configPage2.injLayout = INJ_SEQUENTIAL; + configPage10.stagingEnabled = false; + initialiseAll(); //Run the main initialise function + + // Confirm initial state + assert_4cylinder_4stroke_seq_nostage(); + + changeFullToHalfSync(); + { + const bool enabled[] = {true, true, false, false, false, false, false, false}; + const uint16_t angle[] = {0,180,360,540,0,0,0,0}; + assert_fuel_schedules(360U, reqFuel * 50U, enabled, angle); + } + + changeHalfToFullSync(); + assert_4cylinder_4stroke_seq_nostage(); +} + + void testFuelScheduleInit() { run_1_cylinder_4stroke_tests(); @@ -905,4 +919,6 @@ void testFuelScheduleInit() run_no_inj_timing_tests(); run_oddfire_tests(); + + RUN_TEST_P(test_partial_sync); } \ No newline at end of file diff --git a/test/test_init/test_ignition_schedule_init.cpp b/test/test_init/test_ignition_schedule_init.cpp index d73cf9f1..55545e1c 100644 --- a/test/test_init/test_ignition_schedule_init.cpp +++ b/test/test_init/test_ignition_schedule_init.cpp @@ -27,21 +27,21 @@ static void assert_ignition_schedules(uint16_t crankAngle, uint16_t expectedOutp strcpy_P(msg, PSTR("maxIgnOutputs")); TEST_ASSERT_EQUAL_UINT16_MESSAGE(expectedOutputs, maxIgnOutputs, msg); - assert_ignition_channel(angle[0], 0, channel1IgnDegrees, ign1StartFunction, ign1EndFunction); - assert_ignition_channel(angle[1], 1, channel2IgnDegrees, ign2StartFunction, ign2EndFunction); - assert_ignition_channel(angle[2], 2, channel3IgnDegrees, ign3StartFunction, ign3EndFunction); - assert_ignition_channel(angle[3], 3, channel4IgnDegrees, ign4StartFunction, ign4EndFunction); + assert_ignition_channel(angle[0], 0, channel1IgnDegrees, ignitionSchedule1.pStartCallback, ignitionSchedule1.pEndCallback); + assert_ignition_channel(angle[1], 1, channel2IgnDegrees, ignitionSchedule2.pStartCallback, ignitionSchedule2.pEndCallback); + assert_ignition_channel(angle[2], 2, channel3IgnDegrees, ignitionSchedule3.pStartCallback, ignitionSchedule3.pEndCallback); + assert_ignition_channel(angle[3], 3, channel4IgnDegrees, ignitionSchedule4.pStartCallback, ignitionSchedule4.pEndCallback); #if IGN_CHANNELS>=5 - assert_ignition_channel(angle[4], 4, channel5IgnDegrees, ign5StartFunction, ign5EndFunction); + assert_ignition_channel(angle[4], 4, channel5IgnDegrees, ignitionSchedule5.pStartCallback, ignitionSchedule5.pEndCallback); #endif #if IGN_CHANNELS>=6 - assert_ignition_channel(angle[5], 5, channel6IgnDegrees, ign6StartFunction, ign6EndFunction); + assert_ignition_channel(angle[5], 5, channel6IgnDegrees, ignitionSchedule6.pStartCallback, ignitionSchedule6.pEndCallback); #endif #if IGN_CHANNELS>=7 - assert_ignition_channel(angle[6], 6, channel7IgnDegrees, ign7StartFunction, ign7EndFunction); + assert_ignition_channel(angle[6], 6, channel7IgnDegrees, ignitionSchedule7.pStartCallback, ignitionSchedule7.pEndCallback); #endif #if IGN_CHANNELS>=8 - assert_ignition_channel(angle[7], 7, channel8IgnDegrees, ign8StartFunction, ign8EndFunction); + assert_ignition_channel(angle[7], 7, channel8IgnDegrees, ignitionSchedule8.pStartCallback, ignitionSchedule8.pEndCallback); #endif } @@ -163,13 +163,18 @@ static void run_3_cylinder_4stroke_tests(void) RUN_TEST_P(cylinder3_stroke4_wasted_odd); } +static void assert_cylinder4_stroke4_seq_even(void) +{ + const uint16_t angle[] = {0,180,360,540,0,0,0,0}; + assert_ignition_schedules(720U, 4U, angle); +} + static void cylinder4_stroke4_seq_even(void) { configPage4.sparkMode = IGN_MODE_SEQUENTIAL; configPage2.engineType = EVEN_FIRE; initialiseAll(); //Run the main initialise function - const uint16_t angle[] = {0,180,360,540,0,0,0,0}; - assert_ignition_schedules(720U, 4U, angle); + assert_cylinder4_stroke4_seq_even(); } static void cylinder4_stroke4_wasted_even(void) @@ -237,7 +242,7 @@ static void cylinder6_stroke4_seq_even(void) configPage2.engineType = EVEN_FIRE; initialiseAll(); //Run the main initialise function #if IGN_CHANNELS >= 6 - const uint16_t angle[] = {0,120,240,360,480,540,0,0}; + const uint16_t angle[] = {0,120,240,360,480,600,0,0}; assert_ignition_schedules(720U, 6U, angle); #else const uint16_t angle[] = {0,120,240,0,0,0,0,0}; @@ -296,6 +301,28 @@ static void run_8_cylinder_4stroke_tests(void) RUN_TEST_P(cylinder8_stroke4_wasted_even); } +static void test_partial_sync(void) +{ + configPage2.nCylinders = 4; + configPage2.strokes = FOUR_STROKE; + configPage4.sparkMode = IGN_MODE_SEQUENTIAL; + configPage2.engineType = EVEN_FIRE; + + initialiseAll(); //Run the main initialise function + + // Initial state + assert_cylinder4_stroke4_seq_even(); + + changeFullToHalfSync(); + { + const uint16_t angle[] = {0,180,360,540,0,0,0,0}; + assert_ignition_schedules(360U, 2U, angle); + } + + changeHalfToFullSync(); + assert_cylinder4_stroke4_seq_even(); +} + void testIgnitionScheduleInit() { run_1_cylinder_4stroke_tests(); @@ -305,4 +332,6 @@ void testIgnitionScheduleInit() run_5_cylinder_4stroke_tests(); run_6_cylinder_4stroke_tests(); run_8_cylinder_4stroke_tests(); + + RUN_TEST_P(test_partial_sync); } \ No newline at end of file diff --git a/test/test_schedule_calcs/test_ign_calcs.cpp b/test/test_schedule_calcs/test_ign_calcs.cpp index bc3bd518..7ba3bebe 100644 --- a/test/test_schedule_calcs/test_ign_calcs.cpp +++ b/test/test_schedule_calcs/test_ign_calcs.cpp @@ -33,12 +33,12 @@ struct ign_test_parameters int16_t expectedEndAngle; // Expected end angle }; +static void nullIgnCallback(void) { } void test_calc_ign_timeout(const ign_test_parameters &test_params) { char msg[150]; - Schedule schedule; - memset(&schedule, 0, sizeof(schedule)); + IgnitionSchedule schedule(IGN4_COUNTER, IGN4_COMPARE, nullIgnCallback, nullIgnCallback); int startAngle; int endAngle; @@ -47,11 +47,11 @@ void test_calc_ign_timeout(const ign_test_parameters &test_params) TEST_ASSERT_EQUAL_MESSAGE(test_params.expectedStartAngle, startAngle, "startAngle"); TEST_ASSERT_EQUAL_MESSAGE(test_params.expectedEndAngle, endAngle, "endAngle"); - sprintf_P(msg, PSTR("PENDING advanceAngle: %" PRIi8 ", channelAngle: % " PRIu16 ", crankAngle: %" PRIu16 ", endAngle: %" PRIi16), test_params.advanceAngle, test_params.channelAngle, test_params.crankAngle, endAngle); + sprintf_P(msg, PSTR("PENDING advanceAngle: %" PRIi8 ", channelAngle: %" PRIu16 ", crankAngle: %" PRIu16 ", endAngle: %" PRIi16), test_params.advanceAngle, test_params.channelAngle, test_params.crankAngle, endAngle); schedule.Status = PENDING; TEST_ASSERT_EQUAL_MESSAGE(test_params.pending, calculateIgnitionTimeout(schedule, startAngle, test_params.channelAngle, test_params.crankAngle), msg); - sprintf_P(msg, PSTR("RUNNING advanceAngle: %" PRIi8 ", channelAngle: % " PRIu16 ", crankAngle: %" PRIu16 ", endAngle: %" PRIi16), test_params.advanceAngle, test_params.channelAngle, test_params.crankAngle, endAngle); + sprintf_P(msg, PSTR("RUNNING advanceAngle: %" PRIi8 ", channelAngle: %" PRIu16 ", crankAngle: %" PRIu16 ", endAngle: %" PRIi16), test_params.advanceAngle, test_params.channelAngle, test_params.crankAngle, endAngle); schedule.Status = RUNNING; TEST_ASSERT_EQUAL_MESSAGE(test_params.running, calculateIgnitionTimeout(schedule, startAngle, test_params.channelAngle, test_params.crankAngle), msg); } @@ -554,7 +554,7 @@ void test_rotary_channel_calcs(void) { setEngineSpeed(4000, 360); - static const int16_t test_data[][5] PROGMEM = { + static const int test_data[][5] PROGMEM = { // End Angle (deg), Dwell Angle, rotary split degrees, expected start angle, expected end angle { -40, 5, 0, -40, 315 }, { -40, 95, 0, -40, 225 }, @@ -588,18 +588,18 @@ void test_rotary_channel_calcs(void) { 40, 355, 40, 80, 85 }, }; - const int16_t (*pStart)[5] = &test_data[0]; - const int16_t (*pEnd)[5] = &test_data[0]+_countof(test_data); + const int (*pStart)[5] = &test_data[0]; + const int (*pEnd)[5] = &test_data[0]+_countof(test_data); - int16_t endAngle, startAngle; - int16_t local[5]; + int endAngle, startAngle; + int local[5]; while (pStart!=pEnd) { memcpy_P(local, pStart, sizeof(local)); ignition2EndAngle = local[0]; calculateIgnitionTrailingRotary(local[1], local[2], local[0], &endAngle, &startAngle); - TEST_ASSERT_EQUAL(local[3], endAngle); - TEST_ASSERT_EQUAL(local[4], startAngle); + TEST_ASSERT_EQUAL_MESSAGE(local[3], endAngle, "endAngle"); + TEST_ASSERT_EQUAL_MESSAGE(local[4], startAngle, "startAngle"); ++pStart; } diff --git a/test/test_schedule_calcs/test_inj_calcs.cpp b/test/test_schedule_calcs/test_inj_calcs.cpp index aaede6f5..f32f7386 100644 --- a/test/test_schedule_calcs/test_inj_calcs.cpp +++ b/test/test_schedule_calcs/test_inj_calcs.cpp @@ -22,23 +22,25 @@ struct inj_test_parameters uint32_t running; // Expected delay when channel status is RUNNING }; +static void nullInjCallback(void) { } + static void test_calc_inj_timeout(const inj_test_parameters ¶meters) { static constexpr uint16_t injAngle = 355; char msg[150]; uint16_t PWdivTimerPerDegree = div(parameters.pw, timePerDegree).quot; - memset(&fuelSchedule2, 0, sizeof(fuelSchedule2)); + FuelSchedule schedule(FUEL2_COUNTER, FUEL2_COMPARE, nullInjCallback, nullInjCallback); - fuelSchedule2.Status = PENDING; + schedule.Status = PENDING; uint16_t startAngle = calculateInjectorStartAngle(PWdivTimerPerDegree, parameters.channelAngle, injAngle); - sprintf_P(msg, PSTR("PENDING channelAngle: % " PRIu16 ", pw: % " PRIu16 ", crankAngle: % " PRIu16 ", startAngle: % " PRIu16 ""), parameters.channelAngle, parameters.pw, parameters.crankAngle, startAngle); - TEST_ASSERT_EQUAL_MESSAGE(parameters.pending, calculateInjectorTimeout(fuelSchedule2, parameters.channelAngle, startAngle, parameters.crankAngle), msg); + sprintf_P(msg, PSTR("PENDING channelAngle: %" PRIu16 ", pw: %" PRIu16 ", crankAngle: %" PRIu16 ", startAngle: %" PRIu16), parameters.channelAngle, parameters.pw, parameters.crankAngle, startAngle); + TEST_ASSERT_EQUAL_MESSAGE(parameters.pending, calculateInjectorTimeout(schedule, parameters.channelAngle, startAngle, parameters.crankAngle), msg); - fuelSchedule2.Status = RUNNING; + schedule.Status = RUNNING; startAngle = calculateInjectorStartAngle( PWdivTimerPerDegree, parameters.channelAngle, injAngle); - sprintf_P(msg, PSTR("RUNNING channelAngle: % " PRIu16 ", pw: % " PRIu16 ", crankAngle: % " PRIu16 ", startAngle: % " PRIu16 ""), parameters.channelAngle, parameters.pw, parameters.crankAngle, startAngle); - TEST_ASSERT_EQUAL_MESSAGE(parameters.running, calculateInjectorTimeout(fuelSchedule2, parameters.channelAngle, startAngle, parameters.crankAngle), msg); + sprintf_P(msg, PSTR("RUNNING channelAngle: %" PRIu16 ", pw: %" PRIu16 ", crankAngle: %" PRIu16 ", startAngle: %" PRIu16), parameters.channelAngle, parameters.pw, parameters.crankAngle, startAngle); + TEST_ASSERT_EQUAL_MESSAGE(parameters.running, calculateInjectorTimeout(schedule, parameters.channelAngle, startAngle, parameters.crankAngle), msg); } diff --git a/test/test_schedules/test_accuracy_duration.cpp b/test/test_schedules/test_accuracy_duration.cpp index 3d5ab7b2..868fbf63 100644 --- a/test/test_schedules/test_accuracy_duration.cpp +++ b/test/test_schedules/test_accuracy_duration.cpp @@ -112,7 +112,9 @@ void test_accuracy_duration_inj8(void) void test_accuracy_duration_ign1(void) { initialiseSchedulers(); - setIgnitionSchedule1(startCallback, TIMEOUT, DURATION, endCallback); + ignitionSchedule1.pStartCallback = startCallback; + ignitionSchedule1.pEndCallback = endCallback; + setIgnitionSchedule1(TIMEOUT, DURATION); while( (ignitionSchedule1.Status == PENDING) || (ignitionSchedule1.Status == RUNNING) ) /*Wait*/ ; TEST_ASSERT_UINT32_WITHIN(DELTA, DURATION, end_time - start_time); } @@ -120,7 +122,9 @@ void test_accuracy_duration_ign1(void) void test_accuracy_duration_ign2(void) { initialiseSchedulers(); - setIgnitionSchedule2(startCallback, TIMEOUT, DURATION, endCallback); + ignitionSchedule2.pStartCallback = startCallback; + ignitionSchedule2.pEndCallback = endCallback; + setIgnitionSchedule2(TIMEOUT, DURATION); while( (ignitionSchedule2.Status == PENDING) || (ignitionSchedule2.Status == RUNNING) ) /*Wait*/ ; TEST_ASSERT_UINT32_WITHIN(DELTA, TIMEOUT, end_time - start_time); } @@ -128,7 +132,9 @@ void test_accuracy_duration_ign2(void) void test_accuracy_duration_ign3(void) { initialiseSchedulers(); - setIgnitionSchedule3(startCallback, TIMEOUT, DURATION, endCallback); + ignitionSchedule3.pStartCallback = startCallback; + ignitionSchedule3.pEndCallback = endCallback; + setIgnitionSchedule3(TIMEOUT, DURATION); while( (ignitionSchedule3.Status == PENDING) || (ignitionSchedule3.Status == RUNNING) ) /*Wait*/ ; TEST_ASSERT_UINT32_WITHIN(DELTA, TIMEOUT, end_time - start_time); } @@ -136,7 +142,9 @@ void test_accuracy_duration_ign3(void) void test_accuracy_duration_ign4(void) { initialiseSchedulers(); - setIgnitionSchedule4(startCallback, TIMEOUT, DURATION, endCallback); + ignitionSchedule4.pStartCallback = startCallback; + ignitionSchedule4.pEndCallback = endCallback; + setIgnitionSchedule4(TIMEOUT, DURATION); while( (ignitionSchedule4.Status == PENDING) || (ignitionSchedule4.Status == RUNNING) ) /*Wait*/ ; TEST_ASSERT_UINT32_WITHIN(DELTA, TIMEOUT, end_time - start_time); } @@ -145,7 +153,9 @@ void test_accuracy_duration_ign5(void) { #if IGN_CHANNELS >= 5 initialiseSchedulers(); - setIgnitionSchedule5(startCallback, TIMEOUT, DURATION, endCallback); + ignitionSchedule5.pStartCallback = startCallback; + ignitionSchedule5.pEndCallback = endCallback; + setIgnitionSchedule5(TIMEOUT, DURATION); while( (ignitionSchedule5.Status == PENDING) || (ignitionSchedule5.Status == RUNNING) ) /*Wait*/ ; TEST_ASSERT_UINT32_WITHIN(DELTA, TIMEOUT, end_time - start_time); #endif @@ -155,7 +165,9 @@ void test_accuracy_duration_ign5(void) void test_accuracy_duration_ign6(void) { initialiseSchedulers(); - setIgnitionSchedule6(startCallback, TIMEOUT, DURATION, endCallback); + ignitionSchedule6.pStartCallback = startCallback; + ignitionSchedule6.pEndCallback = endCallback; + setIgnitionSchedule6(TIMEOUT, DURATION); while( (ignitionSchedule6.Status == PENDING) || (ignitionSchedule6.Status == RUNNING) ) /*Wait*/ ; TEST_ASSERT_UINT32_WITHIN(DELTA, TIMEOUT, end_time - start_time); } @@ -165,7 +177,9 @@ void test_accuracy_duration_ign6(void) void test_accuracy_duration_ign7(void) { initialiseSchedulers(); - setIgnitionSchedule7(startCallback, TIMEOUT, DURATION, endCallback); + ignitionSchedule7.pStartCallback = startCallback; + ignitionSchedule7.pEndCallback = endCallback; + setIgnitionSchedule7(TIMEOUT, DURATION); while( (ignitionSchedule7.Status == PENDING) || (ignitionSchedule7.Status == RUNNING) ) /*Wait*/ ; TEST_ASSERT_UINT32_WITHIN(DELTA, TIMEOUT, end_time - start_time); } @@ -175,7 +189,9 @@ void test_accuracy_duration_ign7(void) void test_accuracy_duration_ign8(void) { initialiseSchedulers(); - setIgnitionSchedule8(startCallback, TIMEOUT, DURATION, endCallback); + ignitionSchedule8.pStartCallback = startCallback; + ignitionSchedule8.pEndCallback = endCallback; + setIgnitionSchedule8(TIMEOUT, DURATION); while( (ignitionSchedule8.Status == PENDING) || (ignitionSchedule8.Status == RUNNING) ) /*Wait*/ ; TEST_ASSERT_UINT32_WITHIN(DELTA, TIMEOUT, end_time - start_time); } diff --git a/test/test_schedules/test_accuracy_timeout.cpp b/test/test_schedules/test_accuracy_timeout.cpp index 89b0fac2..c46b6e9b 100644 --- a/test/test_schedules/test_accuracy_timeout.cpp +++ b/test/test_schedules/test_accuracy_timeout.cpp @@ -106,7 +106,9 @@ void test_accuracy_timeout_ign1(void) { initialiseSchedulers(); start_time = micros(); - setIgnitionSchedule1(startCallback, TIMEOUT, DURATION, endCallback); + ignitionSchedule1.pStartCallback = startCallback; + ignitionSchedule1.pEndCallback = endCallback; + setIgnitionSchedule1(TIMEOUT, DURATION); while(ignitionSchedule1.Status == PENDING) /*Wait*/ ; TEST_ASSERT_UINT32_WITHIN(DELTA, TIMEOUT, end_time - start_time); } @@ -115,7 +117,9 @@ void test_accuracy_timeout_ign2(void) { initialiseSchedulers(); start_time = micros(); - setIgnitionSchedule2(startCallback, TIMEOUT, DURATION, endCallback); + ignitionSchedule2.pStartCallback = startCallback; + ignitionSchedule2.pEndCallback = endCallback; + setIgnitionSchedule2(TIMEOUT, DURATION); while(ignitionSchedule2.Status == PENDING) /*Wait*/ ; TEST_ASSERT_UINT32_WITHIN(DELTA, TIMEOUT, end_time - start_time); } @@ -124,7 +128,9 @@ void test_accuracy_timeout_ign3(void) { initialiseSchedulers(); start_time = micros(); - setIgnitionSchedule3(startCallback, TIMEOUT, DURATION, endCallback); + ignitionSchedule3.pStartCallback = startCallback; + ignitionSchedule3.pEndCallback = endCallback; + setIgnitionSchedule3(TIMEOUT, DURATION); while(ignitionSchedule3.Status == PENDING) /*Wait*/ ; TEST_ASSERT_UINT32_WITHIN(DELTA, TIMEOUT, end_time - start_time); } @@ -133,7 +139,9 @@ void test_accuracy_timeout_ign4(void) { initialiseSchedulers(); start_time = micros(); - setIgnitionSchedule4(startCallback, TIMEOUT, DURATION, endCallback); + ignitionSchedule4.pStartCallback = startCallback; + ignitionSchedule4.pEndCallback = endCallback; + setIgnitionSchedule4(TIMEOUT, DURATION); while(ignitionSchedule4.Status == PENDING) /*Wait*/ ; TEST_ASSERT_UINT32_WITHIN(DELTA, TIMEOUT, end_time - start_time); } @@ -142,8 +150,10 @@ void test_accuracy_timeout_ign4(void) void test_accuracy_timeout_ign5(void) { initialiseSchedulers(); + ignitionSchedule5.pStartCallback = startCallback; + ignitionSchedule5.pEndCallback = endCallback; start_time = micros(); - setIgnitionSchedule5(startCallback, TIMEOUT, DURATION, endCallback); + setIgnitionSchedule5(TIMEOUT, DURATION); while(ignitionSchedule5.Status == PENDING) /*Wait*/ ; TEST_ASSERT_UINT32_WITHIN(DELTA, TIMEOUT, end_time - start_time); } @@ -154,7 +164,9 @@ void test_accuracy_timeout_ign6(void) { initialiseSchedulers(); start_time = micros(); - setIgnitionSchedule6(startCallback, TIMEOUT, DURATION, endCallback); + ignitionSchedule6.pStartCallback = startCallback; + ignitionSchedule6.pEndCallback = endCallback; + setIgnitionSchedule6(TIMEOUT, DURATION); while(ignitionSchedule6.Status == PENDING) /*Wait*/ ; TEST_ASSERT_UINT32_WITHIN(DELTA, TIMEOUT, end_time - start_time); } @@ -165,7 +177,9 @@ void test_accuracy_timeout_ign7(void) { initialiseSchedulers(); start_time = micros(); - setIgnitionSchedule7(startCallback, TIMEOUT, DURATION, endCallback); + ignitionSchedule7.pStartCallback = startCallback; + ignitionSchedule7.pEndCallback = endCallback; + setIgnitionSchedule7(TIMEOUT, DURATION); while(ignitionSchedule7.Status == PENDING) /*Wait*/ ; TEST_ASSERT_UINT32_WITHIN(DELTA, TIMEOUT, end_time - start_time); } @@ -176,7 +190,9 @@ void test_accuracy_timeout_ign8(void) { initialiseSchedulers(); start_time = micros(); - setIgnitionSchedule8(startCallback, TIMEOUT, DURATION, endCallback); + ignitionSchedule8.pStartCallback = startCallback; + ignitionSchedule8.pEndCallback = endCallback; + setIgnitionSchedule8(TIMEOUT, DURATION); while(ignitionSchedule8.Status == PENDING) /*Wait*/ ; TEST_ASSERT_UINT32_WITHIN(DELTA, TIMEOUT, end_time - start_time); } diff --git a/test/test_schedules/test_status_initial_off.cpp b/test/test_schedules/test_status_initial_off.cpp index 0e6dee87..908a09fa 100644 --- a/test/test_schedules/test_status_initial_off.cpp +++ b/test/test_schedules/test_status_initial_off.cpp @@ -1,4 +1,3 @@ - #include #include diff --git a/test/test_schedules/test_status_off_to_pending.cpp b/test/test_schedules/test_status_off_to_pending.cpp index fab570a9..da1095c6 100644 --- a/test/test_schedules/test_status_off_to_pending.cpp +++ b/test/test_schedules/test_status_off_to_pending.cpp @@ -77,28 +77,36 @@ void test_status_off_to_pending_inj8(void) void test_status_off_to_pending_ign1(void) { initialiseSchedulers(); - setIgnitionSchedule1(emptyCallback, TIMEOUT, DURATION, emptyCallback); + ignitionSchedule1.pStartCallback = emptyCallback; + ignitionSchedule1.pEndCallback = emptyCallback; + setIgnitionSchedule1(TIMEOUT, DURATION); TEST_ASSERT_EQUAL(PENDING, ignitionSchedule1.Status); } void test_status_off_to_pending_ign2(void) { initialiseSchedulers(); - setIgnitionSchedule2(emptyCallback, TIMEOUT, DURATION, emptyCallback); + ignitionSchedule2.pStartCallback = emptyCallback; + ignitionSchedule2.pEndCallback = emptyCallback; + setIgnitionSchedule2(TIMEOUT, DURATION); TEST_ASSERT_EQUAL(PENDING, ignitionSchedule2.Status); } void test_status_off_to_pending_ign3(void) { initialiseSchedulers(); - setIgnitionSchedule3(emptyCallback, TIMEOUT, DURATION, emptyCallback); + ignitionSchedule3.pStartCallback = emptyCallback; + ignitionSchedule3.pEndCallback = emptyCallback; + setIgnitionSchedule3(TIMEOUT, DURATION); TEST_ASSERT_EQUAL(PENDING, ignitionSchedule3.Status); } void test_status_off_to_pending_ign4(void) { initialiseSchedulers(); - setIgnitionSchedule4(emptyCallback, TIMEOUT, DURATION, emptyCallback); + ignitionSchedule4.pStartCallback = emptyCallback; + ignitionSchedule4.pEndCallback = emptyCallback; + setIgnitionSchedule4(TIMEOUT, DURATION); TEST_ASSERT_EQUAL(PENDING, ignitionSchedule4.Status); } @@ -106,7 +114,9 @@ void test_status_off_to_pending_ign4(void) void test_status_off_to_pending_ign5(void) { initialiseSchedulers(); - setIgnitionSchedule5(emptyCallback, TIMEOUT, DURATION, emptyCallback); + ignitionSchedule5.pStartCallback = emptyCallback; + ignitionSchedule5.pEndCallback = emptyCallback; + setIgnitionSchedule5(TIMEOUT, DURATION); TEST_ASSERT_EQUAL(PENDING, ignitionSchedule5.Status); } #endif @@ -115,7 +125,9 @@ void test_status_off_to_pending_ign5(void) void test_status_off_to_pending_ign6(void) { initialiseSchedulers(); - setIgnitionSchedule6(emptyCallback, TIMEOUT, DURATION, emptyCallback); + ignitionSchedule6.pStartCallback = emptyCallback; + ignitionSchedule6.pEndCallback = emptyCallback; + setIgnitionSchedule6(TIMEOUT, DURATION); TEST_ASSERT_EQUAL(PENDING, ignitionSchedule6.Status); } #endif @@ -124,7 +136,9 @@ void test_status_off_to_pending_ign6(void) void test_status_off_to_pending_ign7(void) { initialiseSchedulers(); - setIgnitionSchedule7(emptyCallback, TIMEOUT, DURATION, emptyCallback); + ignitionSchedule7.pStartCallback = emptyCallback; + ignitionSchedule7.pEndCallback = emptyCallback; + setIgnitionSchedule7(TIMEOUT, DURATION); TEST_ASSERT_EQUAL(PENDING, ignitionSchedule7.Status); } #endif @@ -133,7 +147,9 @@ void test_status_off_to_pending_ign7(void) void test_status_off_to_pending_ign8(void) { initialiseSchedulers(); - setIgnitionSchedule8(emptyCallback, TIMEOUT, DURATION, emptyCallback); + ignitionSchedule8.pStartCallback = emptyCallback; + ignitionSchedule8.pEndCallback = emptyCallback; + setIgnitionSchedule8(TIMEOUT, DURATION); TEST_ASSERT_EQUAL(PENDING, ignitionSchedule8.Status); } #endif diff --git a/test/test_schedules/test_status_pending_to_running.cpp b/test/test_schedules/test_status_pending_to_running.cpp index 6dedb78e..2598585b 100644 --- a/test/test_schedules/test_status_pending_to_running.cpp +++ b/test/test_schedules/test_status_pending_to_running.cpp @@ -85,7 +85,9 @@ void test_status_pending_to_running_inj8(void) void test_status_pending_to_running_ign1(void) { initialiseSchedulers(); - setIgnitionSchedule1(emptyCallback, TIMEOUT, DURATION, emptyCallback); + ignitionSchedule1.pStartCallback = emptyCallback; + ignitionSchedule1.pEndCallback = emptyCallback; + setIgnitionSchedule1(TIMEOUT, DURATION); while(ignitionSchedule1.Status == PENDING) /*Wait*/ ; TEST_ASSERT_EQUAL(RUNNING, ignitionSchedule1.Status); } @@ -93,7 +95,9 @@ void test_status_pending_to_running_ign1(void) void test_status_pending_to_running_ign2(void) { initialiseSchedulers(); - setIgnitionSchedule2(emptyCallback, TIMEOUT, DURATION, emptyCallback); + ignitionSchedule2.pStartCallback = emptyCallback; + ignitionSchedule2.pEndCallback = emptyCallback; + setIgnitionSchedule2(TIMEOUT, DURATION); while(ignitionSchedule2.Status == PENDING) /*Wait*/ ; TEST_ASSERT_EQUAL(RUNNING, ignitionSchedule2.Status); } @@ -101,7 +105,9 @@ void test_status_pending_to_running_ign2(void) void test_status_pending_to_running_ign3(void) { initialiseSchedulers(); - setIgnitionSchedule3(emptyCallback, TIMEOUT, DURATION, emptyCallback); + ignitionSchedule3.pStartCallback = emptyCallback; + ignitionSchedule3.pEndCallback = emptyCallback; + setIgnitionSchedule3(TIMEOUT, DURATION); while(ignitionSchedule3.Status == PENDING) /*Wait*/ ; TEST_ASSERT_EQUAL(RUNNING, ignitionSchedule3.Status); } @@ -109,7 +115,9 @@ void test_status_pending_to_running_ign3(void) void test_status_pending_to_running_ign4(void) { initialiseSchedulers(); - setIgnitionSchedule4(emptyCallback, TIMEOUT, DURATION, emptyCallback); + ignitionSchedule4.pStartCallback = emptyCallback; + ignitionSchedule4.pEndCallback = emptyCallback; + setIgnitionSchedule4(TIMEOUT, DURATION); while(ignitionSchedule4.Status == PENDING) /*Wait*/ ; TEST_ASSERT_EQUAL(RUNNING, ignitionSchedule4.Status); } @@ -118,7 +126,9 @@ void test_status_pending_to_running_ign5(void) { #if IGN_CHANNELS >= 5 initialiseSchedulers(); - setIgnitionSchedule5(emptyCallback, TIMEOUT, DURATION, emptyCallback); + ignitionSchedule5.pStartCallback = emptyCallback; + ignitionSchedule5.pEndCallback = emptyCallback; + setIgnitionSchedule5(TIMEOUT, DURATION); while(ignitionSchedule5.Status == PENDING) /*Wait*/ ; TEST_ASSERT_EQUAL(RUNNING, ignitionSchedule5.Status); #endif @@ -128,7 +138,9 @@ void test_status_pending_to_running_ign6(void) { #if INJ_CHANNELS >= 6 initialiseSchedulers(); - setIgnitionSchedule6(emptyCallback, TIMEOUT, DURATION, emptyCallback); + ignitionSchedule6.pStartCallback = emptyCallback; + ignitionSchedule6.pEndCallback = emptyCallback; + setIgnitionSchedule6(TIMEOUT, DURATION); while(ignitionSchedule6.Status == PENDING) /*Wait*/ ; TEST_ASSERT_EQUAL(RUNNING, ignitionSchedule6.Status); #endif @@ -138,7 +150,9 @@ void test_status_pending_to_running_ign7(void) { #if INJ_CHANNELS >= 7 initialiseSchedulers(); - setIgnitionSchedule7(emptyCallback, TIMEOUT, DURATION, emptyCallback); + ignitionSchedule7.pStartCallback = emptyCallback; + ignitionSchedule7.pEndCallback = emptyCallback; + setIgnitionSchedule7(TIMEOUT, DURATION); while(ignitionSchedule7.Status == PENDING) /*Wait*/ ; TEST_ASSERT_EQUAL(RUNNING, ignitionSchedule7.Status); #endif @@ -148,7 +162,9 @@ void test_status_pending_to_running_ign8(void) { #if INJ_CHANNELS >= 8 initialiseSchedulers(); - setIgnitionSchedule8(emptyCallback, TIMEOUT, DURATION, emptyCallback); + ignitionSchedule8.pStartCallback = emptyCallback; + ignitionSchedule8.pEndCallback = emptyCallback; + setIgnitionSchedule8(TIMEOUT, DURATION); while(ignitionSchedule8.Status == PENDING) /*Wait*/ ; TEST_ASSERT_EQUAL(RUNNING, ignitionSchedule8.Status); #endif diff --git a/test/test_schedules/test_status_running_to_off.cpp b/test/test_schedules/test_status_running_to_off.cpp index 9013f5dc..19965b9e 100644 --- a/test/test_schedules/test_status_running_to_off.cpp +++ b/test/test_schedules/test_status_running_to_off.cpp @@ -85,7 +85,9 @@ void test_status_running_to_off_inj8(void) void test_status_running_to_off_ign1(void) { initialiseSchedulers(); - setIgnitionSchedule1(emptyCallback, TIMEOUT, DURATION, emptyCallback); + ignitionSchedule1.pStartCallback = emptyCallback; + ignitionSchedule1.pEndCallback = emptyCallback; + setIgnitionSchedule1(TIMEOUT, DURATION); while( (ignitionSchedule1.Status == PENDING) || (ignitionSchedule1.Status == RUNNING) ) /*Wait*/ ; TEST_ASSERT_EQUAL(OFF, ignitionSchedule1.Status); } @@ -93,7 +95,9 @@ void test_status_running_to_off_ign1(void) void test_status_running_to_off_ign2(void) { initialiseSchedulers(); - setIgnitionSchedule2(emptyCallback, TIMEOUT, DURATION, emptyCallback); + ignitionSchedule2.pStartCallback = emptyCallback; + ignitionSchedule2.pEndCallback = emptyCallback; + setIgnitionSchedule2(TIMEOUT, DURATION); while( (ignitionSchedule2.Status == PENDING) || (ignitionSchedule2.Status == RUNNING) ) /*Wait*/ ; TEST_ASSERT_EQUAL(OFF, ignitionSchedule2.Status); } @@ -101,7 +105,9 @@ void test_status_running_to_off_ign2(void) void test_status_running_to_off_ign3(void) { initialiseSchedulers(); - setIgnitionSchedule3(emptyCallback, TIMEOUT, DURATION, emptyCallback); + ignitionSchedule3.pStartCallback = emptyCallback; + ignitionSchedule3.pEndCallback = emptyCallback; + setIgnitionSchedule3(TIMEOUT, DURATION); while( (ignitionSchedule3.Status == PENDING) || (ignitionSchedule3.Status == RUNNING) ) /*Wait*/ ; TEST_ASSERT_EQUAL(OFF, ignitionSchedule3.Status); } @@ -109,7 +115,9 @@ void test_status_running_to_off_ign3(void) void test_status_running_to_off_ign4(void) { initialiseSchedulers(); - setIgnitionSchedule4(emptyCallback, TIMEOUT, DURATION, emptyCallback); + ignitionSchedule4.pStartCallback = emptyCallback; + ignitionSchedule4.pEndCallback = emptyCallback; + setIgnitionSchedule4(TIMEOUT, DURATION); while( (ignitionSchedule4.Status == PENDING) || (ignitionSchedule4.Status == RUNNING) ) /*Wait*/ ; TEST_ASSERT_EQUAL(OFF, ignitionSchedule4.Status); } @@ -118,7 +126,9 @@ void test_status_running_to_off_ign5(void) { #if IGN_CHANNELS >= 5 initialiseSchedulers(); - setIgnitionSchedule5(emptyCallback, TIMEOUT, DURATION, emptyCallback); + ignitionSchedule5.pStartCallback = emptyCallback; + ignitionSchedule5.pEndCallback = emptyCallback; + setIgnitionSchedule5(TIMEOUT, DURATION); while( (ignitionSchedule5.Status == PENDING) || (ignitionSchedule5.Status == RUNNING) ) /*Wait*/ ; TEST_ASSERT_EQUAL(OFF, ignitionSchedule5.Status); #endif @@ -128,7 +138,9 @@ void test_status_running_to_off_ign6(void) { #if IGN_CHANNELS >= 6 initialiseSchedulers(); - setIgnitionSchedule6(emptyCallback, TIMEOUT, DURATION, emptyCallback); + ignitionSchedule6.pStartCallback = emptyCallback; + ignitionSchedule6.pEndCallback = emptyCallback; + setIgnitionSchedule6(TIMEOUT, DURATION); while( (ignitionSchedule6.Status == PENDING) || (ignitionSchedule6.Status == RUNNING) ) /*Wait*/ ; TEST_ASSERT_EQUAL(OFF, ignitionSchedule6.Status); #endif @@ -138,7 +150,9 @@ void test_status_running_to_off_ign7(void) { #if IGN_CHANNELS >= 7 initialiseSchedulers(); - setIgnitionSchedule7(emptyCallback, TIMEOUT, DURATION, emptyCallback); + ignitionSchedule7.pStartCallback = emptyCallback; + ignitionSchedule7.pEndCallback = emptyCallback; + setIgnitionSchedule7(TIMEOUT, DURATION); while( (ignitionSchedule7.Status == PENDING) || (ignitionSchedule7.Status == RUNNING) ) /*Wait*/ ; TEST_ASSERT_EQUAL(OFF, ignitionSchedule7.Status); #endif @@ -148,7 +162,9 @@ void test_status_running_to_off_ign8(void) { #if IGN_CHANNELS >= 8 initialiseSchedulers(); - setIgnitionSchedule8(emptyCallback, TIMEOUT, DURATION, emptyCallback); + ignitionSchedule8.pStartCallback = emptyCallback; + ignitionSchedule8.pEndCallback = emptyCallback; + setIgnitionSchedule8(TIMEOUT, DURATION); while( (ignitionSchedule8.Status == PENDING) || (ignitionSchedule8.Status == RUNNING) ) /*Wait*/ ; TEST_ASSERT_EQUAL(OFF, ignitionSchedule8.Status); #endif diff --git a/test/test_schedules/test_status_running_to_pending.cpp b/test/test_schedules/test_status_running_to_pending.cpp index b712fed5..98915f47 100644 --- a/test/test_schedules/test_status_running_to_pending.cpp +++ b/test/test_schedules/test_status_running_to_pending.cpp @@ -101,9 +101,11 @@ void test_status_running_to_pending_inj8(void) void test_status_running_to_pending_ign1(void) { initialiseSchedulers(); - setIgnitionSchedule1(emptyCallback, TIMEOUT, DURATION, emptyCallback); + ignitionSchedule1.pStartCallback = emptyCallback; + ignitionSchedule1.pEndCallback = emptyCallback; + setIgnitionSchedule1(TIMEOUT, DURATION); while(ignitionSchedule1.Status == PENDING) /*Wait*/ ; - setIgnitionSchedule1(emptyCallback, 2*TIMEOUT, DURATION, emptyCallback); + setIgnitionSchedule1(2*TIMEOUT, DURATION); while(ignitionSchedule1.Status == RUNNING) /*Wait*/ ; TEST_ASSERT_EQUAL(PENDING, ignitionSchedule1.Status); } @@ -111,9 +113,11 @@ void test_status_running_to_pending_ign1(void) void test_status_running_to_pending_ign2(void) { initialiseSchedulers(); - setIgnitionSchedule2(emptyCallback, TIMEOUT, DURATION, emptyCallback); + ignitionSchedule2.pStartCallback = emptyCallback; + ignitionSchedule2.pEndCallback = emptyCallback; + setIgnitionSchedule2(TIMEOUT, DURATION); while(ignitionSchedule2.Status == PENDING) /*Wait*/ ; - setIgnitionSchedule2(emptyCallback, 2*TIMEOUT, DURATION, emptyCallback); + setIgnitionSchedule2(2*TIMEOUT, DURATION); while(ignitionSchedule2.Status == RUNNING) /*Wait*/ ; TEST_ASSERT_EQUAL(PENDING, ignitionSchedule2.Status); } @@ -121,9 +125,11 @@ void test_status_running_to_pending_ign2(void) void test_status_running_to_pending_ign3(void) { initialiseSchedulers(); - setIgnitionSchedule3(emptyCallback, TIMEOUT, DURATION, emptyCallback); + ignitionSchedule3.pStartCallback = emptyCallback; + ignitionSchedule3.pEndCallback = emptyCallback; + setIgnitionSchedule3(TIMEOUT, DURATION); while(ignitionSchedule3.Status == PENDING) /*Wait*/ ; - setIgnitionSchedule3(emptyCallback, 2*TIMEOUT, DURATION, emptyCallback); + setIgnitionSchedule3(2*TIMEOUT, DURATION); while(ignitionSchedule3.Status == RUNNING) /*Wait*/ ; TEST_ASSERT_EQUAL(PENDING, ignitionSchedule3.Status); } @@ -131,9 +137,11 @@ void test_status_running_to_pending_ign3(void) void test_status_running_to_pending_ign4(void) { initialiseSchedulers(); - setIgnitionSchedule4(emptyCallback, TIMEOUT, DURATION, emptyCallback); + ignitionSchedule4.pStartCallback = emptyCallback; + ignitionSchedule4.pEndCallback = emptyCallback; + setIgnitionSchedule4(TIMEOUT, DURATION); while(ignitionSchedule4.Status == PENDING) /*Wait*/ ; - setIgnitionSchedule4(emptyCallback, 2*TIMEOUT, DURATION, emptyCallback); + setIgnitionSchedule4(2*TIMEOUT, DURATION); while(ignitionSchedule4.Status == RUNNING) /*Wait*/ ; TEST_ASSERT_EQUAL(PENDING, ignitionSchedule4.Status); } @@ -142,9 +150,11 @@ void test_status_running_to_pending_ign5(void) { #if IGN_CHANNELS >= 5 initialiseSchedulers(); - setIgnitionSchedule5(emptyCallback, TIMEOUT, DURATION, emptyCallback); + ignitionSchedule5.pStartCallback = emptyCallback; + ignitionSchedule5.pEndCallback = emptyCallback; + setIgnitionSchedule5(TIMEOUT, DURATION); while(ignitionSchedule5.Status == PENDING) /*Wait*/ ; - setIgnitionSchedule5(emptyCallback, 2*TIMEOUT, DURATION, emptyCallback); + setIgnitionSchedule5(2*TIMEOUT, DURATION); while(ignitionSchedule5.Status == RUNNING) /*Wait*/ ; TEST_ASSERT_EQUAL(PENDING, ignitionSchedule5.Status); #endif @@ -154,9 +164,11 @@ void test_status_running_to_pending_ign6(void) { #if INJ_CHANNELS >= 6 initialiseSchedulers(); - setIgnitionSchedule6(emptyCallback, TIMEOUT, DURATION, emptyCallback); + ignitionSchedule6.pStartCallback = emptyCallback; + ignitionSchedule6.pEndCallback = emptyCallback; + setIgnitionSchedule6(TIMEOUT, DURATION); while(ignitionSchedule6.Status == PENDING) /*Wait*/ ; - setIgnitionSchedule6(emptyCallback, 2*TIMEOUT, DURATION, emptyCallback); + setIgnitionSchedule6(2*TIMEOUT, DURATION); while(ignitionSchedule6.Status == RUNNING) /*Wait*/ ; TEST_ASSERT_EQUAL(PENDING, ignitionSchedule6.Status); #endif @@ -166,9 +178,11 @@ void test_status_running_to_pending_ign7(void) { #if INJ_CHANNELS >= 7 initialiseSchedulers(); - setIgnitionSchedule7(emptyCallback, TIMEOUT, DURATION, emptyCallback); + ignitionSchedule7.pStartCallback = emptyCallback; + ignitionSchedule7.pEndCallback = emptyCallback; + setIgnitionSchedule7(TIMEOUT, DURATION); while(ignitionSchedule7.Status == PENDING) /*Wait*/ ; - setIgnitionSchedule7(emptyCallback, 2*TIMEOUT, DURATION, emptyCallback); + setIgnitionSchedule7(2*TIMEOUT, DURATION); while(ignitionSchedule7.Status == RUNNING) /*Wait*/ ; TEST_ASSERT_EQUAL(PENDING, ignitionSchedule7.Status); #endif @@ -178,9 +192,11 @@ void test_status_running_to_pending_ign8(void) { #if INJ_CHANNELS >= 8 initialiseSchedulers(); - setIgnitionSchedule8(emptyCallback, TIMEOUT, DURATION, emptyCallback); + ignitionSchedule8.pStartCallback = emptyCallback; + ignitionSchedule8.pEndCallback = emptyCallback; + setIgnitionSchedule8(TIMEOUT, DURATION); while(ignitionSchedule8.Status == PENDING) /*Wait*/ ; - setIgnitionSchedule8(emptyCallback, 2*TIMEOUT, DURATION, emptyCallback); + setIgnitionSchedule8(2*TIMEOUT, DURATION); while(ignitionSchedule8.Status == RUNNING) /*Wait*/ ; TEST_ASSERT_EQUAL(PENDING, ignitionSchedule8.Status); #endif