Speeduino initialisation and main loop.
| BEGIN_LTO_ALWAYS_INLINE |
( |
void |
| ) |
|
Speeduino main loop.
Main loop chores (roughly in the order that they are performed):
- Check if serial comms or tooth logging are in progress (send or receive, prioritise communication)
- Record loop timing vars
- Check tooth time, update statuses (currentStatus) variables
- Read sensors
- get VE for fuel calcs and spark advance for ignition
- Check crank/cam/tooth/timing sync (skip remaining ops if out-of-sync)
- execute doCrankSpeedCalcs()
single byte variable currentStatus.LOOP_TIMER plays a big part here as:
- it contains expire-bits for interval based frequency driven events (e.g. 15Hz, 4Hz, 1Hz)
- Can be tested for certain frequency interval being expired by (eg) BIT_CHECK(currentStatus.LOOP_TIMER, BIT_TIMER_15HZ)
Sometimes loop() is inlined by LTO & sometimes not When not inlined, there is a huge difference in stack usage: 60+ bytes That eats into available RAM. Adding attribute((always_inline)) forces the LTO process to inline.
Since the function is declared in an Arduino header, we can't change it to inline, so we need to suppress the resulting warning.