Skip to content

Commit

Permalink
ARM cores call moveToNextState directly
Browse files Browse the repository at this point in the history
  • Loading branch information
adbancroft committed Oct 3, 2024
1 parent 0919ccb commit c6bb423
Show file tree
Hide file tree
Showing 5 changed files with 102 additions and 146 deletions.
52 changes: 32 additions & 20 deletions speeduino/board_stm32_official.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,45 +84,57 @@ STM32RTC& rtc = STM32RTC::getInstance();
***********************************************************************************************************
* Interrupt callback functions
*/
#define IGNITION_INTERRUPT_NAME(index) CONCAT(CONCAT(ignitionSchedule, index), Interrupt)
#define FUEL_INTERRUPT_NAME(index) CONCAT(CONCAT(fuelSchedule, index), Interrupt)


#if ((STM32_CORE_VERSION_MINOR<=8) & (STM32_CORE_VERSION_MAJOR==1))
void oneMSInterval(HardwareTimer*){oneMSInterval();}
void boostInterrupt(HardwareTimer*){boostInterrupt();}
void fuelSchedule1Interrupt(HardwareTimer*){FUEL_INTERRUPT_NAME(1)();}
void fuelSchedule2Interrupt(HardwareTimer*){FUEL_INTERRUPT_NAME(2)();}
void fuelSchedule3Interrupt(HardwareTimer*){FUEL_INTERRUPT_NAME(3)();}
void fuelSchedule4Interrupt(HardwareTimer*){FUEL_INTERRUPT_NAME(4)();}
void idleInterrupt(HardwareTimer*){idleInterrupt();}
void vvtInterrupt(HardwareTimer*){vvtInterrupt();}
void fanInterrupt(HardwareTimer*){fanInterrupt();}
#define STM_FUEL_INTERRUPT(index) void FUEL_INTERRUPT_NAME(index)(HardwareTimer*) {moveToNextState(fuelSchedule ## index);}
#define STM_IGNITION_INTERRUPT(index) void IGNITION_INTERRUPT_NAME(index)(HardwareTimer*) {moveToNextState(ignitionSchedule ## index);}
#else //End core<=1.8
#define STM_FUEL_INTERRUPT(index) void FUEL_INTERRUPT_NAME(index)(void) {moveToNextState(fuelSchedule ## index);}
#define STM_IGNITION_INTERRUPT(index) void IGNITION_INTERRUPT_NAME(index)(void) {moveToNextState(ignitionSchedule ## index);}
#endif

STM_FUEL_INTERRUPT(1)
STM_FUEL_INTERRUPT(2)
STM_FUEL_INTERRUPT(3)
STM_FUEL_INTERRUPT(4)
#if (INJ_CHANNELS >= 5)
void fuelSchedule5Interrupt(HardwareTimer*){FUEL_INTERRUPT_NAME(5)();}
STM_FUEL_INTERRUPT(5)
#endif
#if (INJ_CHANNELS >= 6)
void fuelSchedule6Interrupt(HardwareTimer*){FUEL_INTERRUPT_NAME(6)();}
STM_FUEL_INTERRUPT(6)
#endif
#if (INJ_CHANNELS >= 7)
void fuelSchedule7Interrupt(HardwareTimer*){FUEL_INTERRUPT_NAME(7)();}
STM_FUEL_INTERRUPT(7)
#endif
#if (INJ_CHANNELS >= 8)
void fuelSchedule8Interrupt(HardwareTimer*){FUEL_INTERRUPT_NAME(8)();}
STM_FUEL_INTERRUPT(8)
#endif
void idleInterrupt(HardwareTimer*){idleInterrupt();}
void vvtInterrupt(HardwareTimer*){vvtInterrupt();}
void fanInterrupt(HardwareTimer*){fanInterrupt();}
void ignitionSchedule1Interrupt(HardwareTimer*){IGNITION_INTERRUPT_NAME(1)();}
void ignitionSchedule2Interrupt(HardwareTimer*){IGNITION_INTERRUPT_NAME(2)();}
void ignitionSchedule3Interrupt(HardwareTimer*){IGNITION_INTERRUPT_NAME(3)();}
void ignitionSchedule4Interrupt(HardwareTimer*){IGNITION_INTERRUPT_NAME(4)();}

STM_IGNITION_INTERRUPT(1)
STM_IGNITION_INTERRUPT(2)
STM_IGNITION_INTERRUPT(3)
STM_IGNITION_INTERRUPT(4)
#if (IGN_CHANNELS >= 5)
void ignitionSchedule5Interrupt(HardwareTimer*){IGNITION_INTERRUPT_NAME(5)();}
STM_IGNITION_INTERRUPT(5)
#endif
#if (IGN_CHANNELS >= 6)
void ignitionSchedule6Interrupt(HardwareTimer*){IGNITION_INTERRUPT_NAME(6)();}
STM_IGNITION_INTERRUPT(6)
#endif
#if (IGN_CHANNELS >= 7)
void ignitionSchedule7Interrupt(HardwareTimer*){IGNITION_INTERRUPT_NAME(7)();}
STM_IGNITION_INTERRUPT(7)
#endif
#if (IGN_CHANNELS >= 8)
void ignitionSchedule8Interrupt(HardwareTimer*){IGNITION_INTERRUPT_NAME(8)();}
STM_IGNITION_INTERRUPT(8)
#endif
#endif //End core<=1.8


void initBoard()
{
Expand Down
32 changes: 16 additions & 16 deletions speeduino/board_teensy35.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -315,50 +315,50 @@ void ftm0_isr(void)
bool interrupt7 = (FTM0_C6SC & FTM_CSC_CHF);
bool interrupt8 = (FTM0_C7SC & FTM_CSC_CHF);

if(interrupt1) { FTM0_C0SC &= ~FTM_CSC_CHF; FUEL_INTERRUPT_NAME(1)(); }
else if(interrupt2) { FTM0_C1SC &= ~FTM_CSC_CHF; FUEL_INTERRUPT_NAME(2)(); }
else if(interrupt3) { FTM0_C2SC &= ~FTM_CSC_CHF; FUEL_INTERRUPT_NAME(3)(); }
else if(interrupt4) { FTM0_C3SC &= ~FTM_CSC_CHF; FUEL_INTERRUPT_NAME(4)(); }
else if(interrupt5) { FTM0_C4SC &= ~FTM_CSC_CHF; IGNITION_INTERRUPT_NAME(1)(); }
else if(interrupt6) { FTM0_C5SC &= ~FTM_CSC_CHF; IGNITION_INTERRUPT_NAME(2)(); }
else if(interrupt7) { FTM0_C6SC &= ~FTM_CSC_CHF; IGNITION_INTERRUPT_NAME(3)(); }
else if(interrupt8) { FTM0_C7SC &= ~FTM_CSC_CHF; IGNITION_INTERRUPT_NAME(4)(); }
if(interrupt1) { FTM0_C0SC &= ~FTM_CSC_CHF; moveToNextState(fuelSchedule1); }
else if(interrupt2) { FTM0_C1SC &= ~FTM_CSC_CHF; moveToNextState(fuelSchedule2); }
else if(interrupt3) { FTM0_C2SC &= ~FTM_CSC_CHF; moveToNextState(fuelSchedule3); }
else if(interrupt4) { FTM0_C3SC &= ~FTM_CSC_CHF; moveToNextState(fuelSchedule4); }
else if(interrupt5) { FTM0_C4SC &= ~FTM_CSC_CHF; moveToNextState(ignitionSchedule1); }
else if(interrupt6) { FTM0_C5SC &= ~FTM_CSC_CHF; moveToNextState(ignitionSchedule2); }
else if(interrupt7) { FTM0_C6SC &= ~FTM_CSC_CHF; moveToNextState(ignitionSchedule3); }
else if(interrupt8) { FTM0_C7SC &= ~FTM_CSC_CHF; moveToNextState(ignitionSchedule4); }

}
void ftm3_isr(void)
{

#if (INJ_CHANNELS >= 5)
bool interrupt1 = (FTM3_C0SC & FTM_CSC_CHF);
if(interrupt1) { FTM3_C0SC &= ~FTM_CSC_CHF; FUEL_INTERRUPT_NAME(5)(); }
if(interrupt1) { FTM3_C0SC &= ~FTM_CSC_CHF; moveToNextState(fuelSchedule5); }
#endif
#if (INJ_CHANNELS >= 6)
bool interrupt2 = (FTM3_C1SC & FTM_CSC_CHF);
if(interrupt2) { FTM3_C1SC &= ~FTM_CSC_CHF; FUEL_INTERRUPT_NAME(6)(); }
if(interrupt2) { FTM3_C1SC &= ~FTM_CSC_CHF; moveToNextState(fuelSchedule6); }
#endif
#if (INJ_CHANNELS >= 7)
bool interrupt3 = (FTM3_C2SC & FTM_CSC_CHF);
if(interrupt3) { FTM3_C2SC &= ~FTM_CSC_CHF; FUEL_INTERRUPT_NAME(7)(); }
if(interrupt3) { FTM3_C2SC &= ~FTM_CSC_CHF; moveToNextState(fuelSchedule7); }
#endif
#if (INJ_CHANNELS >= 8)
bool interrupt4 = (FTM3_C3SC & FTM_CSC_CHF);
if(interrupt4) { FTM3_C3SC &= ~FTM_CSC_CHF; FUEL_INTERRUPT_NAME(8)(); }
if(interrupt4) { FTM3_C3SC &= ~FTM_CSC_CHF; moveToNextState(fuelSchedule8); }
#endif
#if (IGN_CHANNELS >= 5)
bool interrupt5 = (FTM3_C4SC & FTM_CSC_CHF);
if(interrupt5) { FTM3_C4SC &= ~FTM_CSC_CHF; IGNITION_INTERRUPT_NAME(5)(); }
if(interrupt5) { FTM3_C4SC &= ~FTM_CSC_CHF; moveToNextState(ignitionSchedule5); }
#endif
#if (IGN_CHANNELS >= 6)
bool interrupt6 = (FTM3_C5SC & FTM_CSC_CHF);
if(interrupt6) { FTM3_C5SC &= ~FTM_CSC_CHF; IGNITION_INTERRUPT_NAME(6)(); }
if(interrupt6) { FTM3_C5SC &= ~FTM_CSC_CHF; moveToNextState(ignitionSchedule6); }
#endif
#if (IGN_CHANNELS >= 7)
bool interrupt7 = (FTM3_C6SC & FTM_CSC_CHF);
if(interrupt7) { FTM3_C6SC &= ~FTM_CSC_CHF; IGNITION_INTERRUPT_NAME(7)(); }
if(interrupt7) { FTM3_C6SC &= ~FTM_CSC_CHF; moveToNextState(ignitionSchedule7); }
#endif
#if (IGN_CHANNELS >= 8)
bool interrupt8 = (FTM3_C7SC & FTM_CSC_CHF);
if(interrupt8) { FTM3_C7SC &= ~FTM_CSC_CHF; IGNITION_INTERRUPT_NAME(8)(); }
if(interrupt8) { FTM3_C7SC &= ~FTM_CSC_CHF; moveToNextState(ignitionSchedule8); }
#endif

}
Expand Down
32 changes: 16 additions & 16 deletions speeduino/board_teensy41.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -235,10 +235,10 @@ void TMR1_isr(void)
bool interrupt3 = (TMR1_CSCTRL2 & TMR_CSCTRL_TCF1);
bool interrupt4 = (TMR1_CSCTRL3 & TMR_CSCTRL_TCF1);

if(interrupt1) { TMR1_CSCTRL0 &= ~TMR_CSCTRL_TCF1; FUEL_INTERRUPT_NAME(1)(); }
else if(interrupt2) { TMR1_CSCTRL1 &= ~TMR_CSCTRL_TCF1; FUEL_INTERRUPT_NAME(2)(); }
else if(interrupt3) { TMR1_CSCTRL2 &= ~TMR_CSCTRL_TCF1; FUEL_INTERRUPT_NAME(3)(); }
else if(interrupt4) { TMR1_CSCTRL3 &= ~TMR_CSCTRL_TCF1; FUEL_INTERRUPT_NAME(4)(); }
if(interrupt1) { TMR1_CSCTRL0 &= ~TMR_CSCTRL_TCF1; moveToNextState(fuelSchedule1); }
else if(interrupt2) { TMR1_CSCTRL1 &= ~TMR_CSCTRL_TCF1; moveToNextState(fuelSchedule2); }
else if(interrupt3) { TMR1_CSCTRL2 &= ~TMR_CSCTRL_TCF1; moveToNextState(fuelSchedule3); }
else if(interrupt4) { TMR1_CSCTRL3 &= ~TMR_CSCTRL_TCF1; moveToNextState(fuelSchedule4); }
}
void TMR2_isr(void)
{
Expand All @@ -248,10 +248,10 @@ void TMR2_isr(void)
bool interrupt3 = (TMR2_CSCTRL2 & TMR_CSCTRL_TCF1);
bool interrupt4 = (TMR2_CSCTRL3 & TMR_CSCTRL_TCF1);

if(interrupt1) { TMR2_CSCTRL0 &= ~TMR_CSCTRL_TCF1; IGNITION_INTERRUPT_NAME(1)(); }
else if(interrupt2) { TMR2_CSCTRL1 &= ~TMR_CSCTRL_TCF1; IGNITION_INTERRUPT_NAME(2)(); }
else if(interrupt3) { TMR2_CSCTRL2 &= ~TMR_CSCTRL_TCF1; IGNITION_INTERRUPT_NAME(3)(); }
else if(interrupt4) { TMR2_CSCTRL3 &= ~TMR_CSCTRL_TCF1; IGNITION_INTERRUPT_NAME(4)(); }
if(interrupt1) { TMR2_CSCTRL0 &= ~TMR_CSCTRL_TCF1; moveToNextState(ignitionSchedule1); }
else if(interrupt2) { TMR2_CSCTRL1 &= ~TMR_CSCTRL_TCF1; moveToNextState(ignitionSchedule2); }
else if(interrupt3) { TMR2_CSCTRL2 &= ~TMR_CSCTRL_TCF1; moveToNextState(ignitionSchedule3); }
else if(interrupt4) { TMR2_CSCTRL3 &= ~TMR_CSCTRL_TCF1; moveToNextState(ignitionSchedule4); }
}
void TMR3_isr(void)
{
Expand All @@ -261,10 +261,10 @@ void TMR3_isr(void)
bool interrupt3 = (TMR3_CSCTRL2 & TMR_CSCTRL_TCF1);
bool interrupt4 = (TMR3_CSCTRL3 & TMR_CSCTRL_TCF1);

if(interrupt1) { TMR3_CSCTRL0 &= ~TMR_CSCTRL_TCF1; FUEL_INTERRUPT_NAME(5)(); }
else if(interrupt2) { TMR3_CSCTRL1 &= ~TMR_CSCTRL_TCF1; FUEL_INTERRUPT_NAME(6)(); }
else if(interrupt3) { TMR3_CSCTRL2 &= ~TMR_CSCTRL_TCF1; FUEL_INTERRUPT_NAME(7)(); }
else if(interrupt4) { TMR3_CSCTRL3 &= ~TMR_CSCTRL_TCF1; FUEL_INTERRUPT_NAME(8)(); }
if(interrupt1) { TMR3_CSCTRL0 &= ~TMR_CSCTRL_TCF1; moveToNextState(fuelSchedule5); }
else if(interrupt2) { TMR3_CSCTRL1 &= ~TMR_CSCTRL_TCF1; moveToNextState(fuelSchedule6); }
else if(interrupt3) { TMR3_CSCTRL2 &= ~TMR_CSCTRL_TCF1; moveToNextState(fuelSchedule7); }
else if(interrupt4) { TMR3_CSCTRL3 &= ~TMR_CSCTRL_TCF1; moveToNextState(fuelSchedule8); }
}
void TMR4_isr(void)
{
Expand All @@ -274,10 +274,10 @@ void TMR4_isr(void)
bool interrupt3 = (TMR4_CSCTRL2 & TMR_CSCTRL_TCF1);
bool interrupt4 = (TMR4_CSCTRL3 & TMR_CSCTRL_TCF1);

if(interrupt1) { TMR4_CSCTRL0 &= ~TMR_CSCTRL_TCF1; IGNITION_INTERRUPT_NAME(5)(); }
else if(interrupt2) { TMR4_CSCTRL1 &= ~TMR_CSCTRL_TCF1; IGNITION_INTERRUPT_NAME(6)(); }
else if(interrupt3) { TMR4_CSCTRL2 &= ~TMR_CSCTRL_TCF1; IGNITION_INTERRUPT_NAME(7)(); }
else if(interrupt4) { TMR4_CSCTRL3 &= ~TMR_CSCTRL_TCF1; IGNITION_INTERRUPT_NAME(8)(); }
if(interrupt1) { TMR4_CSCTRL0 &= ~TMR_CSCTRL_TCF1; moveToNextState(ignitionSchedule5); }
else if(interrupt2) { TMR4_CSCTRL1 &= ~TMR_CSCTRL_TCF1; moveToNextState(ignitionSchedule6); }
else if(interrupt3) { TMR4_CSCTRL2 &= ~TMR_CSCTRL_TCF1; moveToNextState(ignitionSchedule7); }
else if(interrupt4) { TMR4_CSCTRL3 &= ~TMR_CSCTRL_TCF1; moveToNextState(ignitionSchedule8); }
}

uint16_t freeRam()
Expand Down
35 changes: 7 additions & 28 deletions speeduino/scheduler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -307,13 +307,7 @@ extern void beginInjectorPriming(void)
* @{
*/

/**
* @brief Shared fuel schedule timer ISR implementation. Should be called by the actual timer ISRs
* (as timed interrupts) when either the start time or the duration time are reached. See @ref schedule-state-machine
*
* @param schedule The fuel schedule to move to the next state
*/
static inline __attribute__((always_inline)) void onFuelScheduleTimer(FuelSchedule &schedule)
void moveToNextState(FuelSchedule &schedule)
{
movetoNextState(schedule, defaultPendingToRunning, defaultRunningToOff, defaultRunningToPending);
}
Expand All @@ -322,14 +316,8 @@ static inline __attribute__((always_inline)) void onFuelScheduleTimer(FuelSchedu
#if defined(CORE_AVR) //AVR chips use the ISR for this
#define FUEL_INTERRUPT(index, avr_vector) \
ISR((avr_vector)) { \
onFuelScheduleTimer(fuelSchedule ## index); \
}
#else
#define FUEL_INTERRUPT(index, avr_vector) \
void FUEL_INTERRUPT_NAME(index) (void) { \
onFuelScheduleTimer(fuelSchedule ## index); \
moveToNextState(fuelSchedule ## index); \
}
#endif

/** @brief ISR for fuel channel 1 */
// cppcheck-suppress misra-c2012-8.2
Expand Down Expand Up @@ -369,6 +357,7 @@ FUEL_INTERRUPT(7, TIMER5_COMPC_vect)
// cppcheck-suppress misra-c2012-8.2
FUEL_INTERRUPT(8, TIMER5_COMPB_vect)
#endif
#endif

///@}

Expand Down Expand Up @@ -420,13 +409,7 @@ static inline void ignitionRunningToPending(Schedule *pSchedule) {
onEndIgnitionEvent((IgnitionSchedule *)pSchedule);
}

/**
* @brief Shared ignition schedule timer ISR *implementation*. Should be called by the actual ignition timer ISRs
* (as timed interrupts) when either the start time or the duration time are reached. See @ref schedule-state-machine
*
* @param schedule The ignition schedule to move to the next state
*/
static inline __attribute__((always_inline)) void onIgnitionScheduleTimer(IgnitionSchedule &schedule)
void moveToNextState(IgnitionSchedule &schedule)
{
movetoNextState(schedule, ignitionPendingToRunning, ignitionRunningToOff, ignitionRunningToPending);
}
Expand All @@ -435,14 +418,8 @@ static inline __attribute__((always_inline)) void onIgnitionScheduleTimer(Igniti
#if defined(CORE_AVR) //AVR chips use the ISR for this
#define IGNITION_INTERRUPT(index, avr_vector) \
ISR((avr_vector)) { \
onIgnitionScheduleTimer(ignitionSchedule ## index); \
}
#else
#define IGNITION_INTERRUPT(index, avr_vector) \
void IGNITION_INTERRUPT_NAME(index) (void) { \
onIgnitionScheduleTimer(ignitionSchedule ## index); \
moveToNextState(ignitionSchedule ## index); \
}
#endif

/** @brief ISR for ignition channel 1 */
// cppcheck-suppress misra-c2012-8.2
Expand Down Expand Up @@ -482,6 +459,8 @@ IGNITION_INTERRUPT(7, TIMER3_COMPC_vect)
IGNITION_INTERRUPT(8, TIMER3_COMPB_vect)
#endif

#endif

///@}

void disablePendingFuelSchedule(byte channel)
Expand Down
Loading

0 comments on commit c6bb423

Please sign in to comment.