Speeduino
Loading...
Searching...
No Matches
Macros | Functions | Variables
scheduler_fuel_controller.cpp File Reference
#include "scheduler_fuel_controller.h"
#include "scheduledIO_inj.h"
#include "units.h"
#include "table2d.h"
#include "globals.h"

Macros

#define SET_CALLBACKS(index)   setCallbacks(fuelSchedule ## index, openInjector ## index, closeInjector ## index);\
 
#define SET_FUEL_CHANNEL(channel)    setFuelChannelSchedule(fuelSchedule ##channel, UINT8_C(channel), crankAngle, injChannelMask, injAngle, &angleCalcCache);
 
#define ASSIGN_PRIMARY_PW(index)   fuelSchedule ## index .pw = applyFuelTrim(trimTables[index-1U], pulse_widths.primary, page6, current);
 
#define ASSIGN_SECONDARY_PW(index)
 
#define ASSIGN_ZERO_PW(index)   fuelSchedule ## index .pw = 0U;
 
#define ASSIGN_PRIMARY_ANGLE(index)    fuelSchedule ## index .channelDegrees = calcScheduleAngle(current, page2, index);
 

Functions

static void setupSequentialCallbacks (void)
 
static void setupPairedCallbacks (void)
 
static void setupSemiSequentialCallbacks (uint8_t nCylinders, uint8_t inj4cylPairing)
 
static void setupCallbacks (uint8_t injLayout, uint8_t nCylinders, uint8_t inj4cylPairing)
 
TESTABLE_INLINE_STATIC bool isAnyFuelScheduleRunning (void)
 
TESTABLE_INLINE_STATIC uint16_t lookupInjectorAngle (const statuses &current)
 
TESTABLE_INLINE_STATIC uint16_t updatePwAngleCache (uint16_t pw, injectorAngleCalcCache *pCache)
 
TESTABLE_INLINE_STATIC uint16_t _calculateOpenAngle (const FuelSchedule &schedule, uint16_t pwDegrees, uint16_t injAngle)
 Compute the injector open angle for an injection channel.
 
TESTABLE_INLINE_STATIC uint32_t calculateInjectorTimeout (const FuelSchedule &schedule, int16_t crankAngle, uint16_t openAngle)
 Calculate the time in uS from now to when the injector should be opened.
 
TESTABLE_INLINE_STATIC void setFuelChannelSchedule (FuelSchedule &schedule, uint8_t channel, uint16_t crankAngle, byte injChannelMask, uint16_t injAngle, injectorAngleCalcCache *pCache) noexcept
 
TESTABLE_INLINE_STATIC uint16_t setFuelChannelSchedules (uint16_t crankAngle, byte injChannelMask, uint16_t injAngle)
 
TESTABLE_INLINE_STATIC uint16_t injectorLimits (uint16_t angle)
 Clamp the angle to within [0,CRANK_ANGLE_MAX_INJ)
 
 BEGIN_LTO_ALWAYS_INLINE (uint16_t) setFuelChannelSchedules(const statuses &current)
 
static uint16_t applyFuelTrim (const table3d6RpmLoad &trimTable, uint16_t pw, const config6 &page6, const statuses &current)
 
static void assignPrimaryPws (const pulseWidths &pulse_widths, const config6 &page6, const statuses &current)
 
static void assignSecondaryPws (const pulseWidths &pulse_widths, const statuses &current)
 
static void zeroAllChannels (void)
 
static void resetFuelSchedules (void)
 
void startFuelSchedulers (void)
 Start the timers that drive schedulers.
 
void stopFuelSchedulers (void)
 Stop the timers that drive schedulers.
 
void beginInjectorPriming (const statuses &current, const config4 &page4)
 Start priming the fuel system.
 
void closeAllInjectors (void)
 Utility function to close all injectors.
 
TESTABLE_INLINE_STATIC uint16_t calcAngularCylinderSeparation (const statuses &current, const config2 &page2)
 
TESTABLE_INLINE_STATIC uint16_t getOddfireAngle (const config2 &page2, uint8_t channel)
 
TESTABLE_INLINE_STATIC bool useEvenFire (const config2 &page2)
 
TESTABLE_INLINE_STATIC uint16_t getEvenFireAngle (const statuses &current, const config2 &page2, uint8_t channel)
 
TESTABLE_INLINE_STATIC uint16_t calcScheduleAngle (const statuses &current, const config2 &page2, uint8_t channel)
 Calculate the schedule channel angle. I.e. FuelSchedule::channelDegrees.
 
static void setInjectorAngles (const statuses &current, const config2 &page2)
 
TESTABLE_STATIC uint8_t calulateNumSquirts (const statuses &current, const config2 &page2)
 
TESTABLE_STATIC uint16_t calculateMaxInjAngle (const statuses &current, const config2 &page2)
 
TESTABLE_INLINE_STATIC uint8_t calcNumPrimaryInjectors (const statuses &current, const config2 &page2)
 
TESTABLE_STATIC uint8_t calcNumSecondaryInjectors (uint16_t primary, const config2 &page2, const config10 &page10)
 
TESTABLE_STATIC num_injector_t calcNumInjectors (const statuses &current, const config2 &page2, const config10 &page10)
 
static uint8_t validateInjLayout (uint8_t layout, const config2 &page2)
 
TESTABLE_STATIC void validateInjectionSetup (config2 &page2, config6 &page6)
 
void configureFuelSchedules (statuses &current, const config2 &page2, const config4 &page4, const config10 &page10)
 
void initialiseFuelSchedules (statuses &current, config2 &page2, const config4 &page4, config6 &page6, config10 &page10, const pinNumbers_t &pins)
 Initialise this module.
 
static bool isSwitchableConfig (const config2 &page2)
 
TESTABLE_INLINE_STATIC bool changeToSemiSequentialInjection (const statuses &current, const config2 &page2)
 
TESTABLE_INLINE_STATIC bool changeToFullSequentialInjection (const statuses &current, const config2 &page2)
 
static void changeFuellingToFullSequential (const config2 &page2, const config4 &page4, const config10 &page10, statuses &current)
 
static void changeFuellingToSemiSequential (const config2 &page2, const config4 &page4, const config10 &page10, statuses &current)
 
TESTABLE_STATIC void matchFuelSchedulersToSyncState (const config2 &page2, const config4 &page4, const config10 &page10, statuses &current)
 
 BEGIN_LTO_ALWAYS_INLINE (void) applyPwToInjectorChannels(const pulseWidths &pulse_widths
 
 assignPrimaryPws (pulse_widths, page6, current)
 
 assignSecondaryPws (pulse_widths, current)
 

Variables

FuelSchedule fuelSchedule1 (FUEL1_COUNTER, FUEL1_COMPARE)
 
TESTABLE_STATIC table2D_u8_u16_4 injectorAngleTable & configPage2
 
const config2 & page2
 
const config2 const config4 & page4
 
const config2 const config4 const config6 & page6
 
const config2 const config4 const config6 const config10 & page10
 
const config2 const config4 const config6 const config10 statuses & current
 

Macro Definition Documentation

◆ ASSIGN_PRIMARY_ANGLE

#define ASSIGN_PRIMARY_ANGLE (   index)     fuelSchedule ## index .channelDegrees = calcScheduleAngle(current, page2, index);

◆ ASSIGN_PRIMARY_PW

#define ASSIGN_PRIMARY_PW (   index)    fuelSchedule ## index .pw = applyFuelTrim(trimTables[index-1U], pulse_widths.primary, page6, current);

◆ ASSIGN_SECONDARY_PW

#define ASSIGN_SECONDARY_PW (   index)
Value:
if (current.injOutputs.isSecondaryInjector(index)) \
{ \
fuelSchedule ## index .pw = pulse_widths.secondary; \
}
const config2 const config4 const config6 const config10 statuses & current
Definition scheduler_fuel_controller.cpp:913

◆ ASSIGN_ZERO_PW

#define ASSIGN_ZERO_PW (   index)    fuelSchedule ## index .pw = 0U;

◆ SET_CALLBACKS

#define SET_CALLBACKS (   index)    setCallbacks(fuelSchedule ## index, openInjector ## index, closeInjector ## index);\

◆ SET_FUEL_CHANNEL

#define SET_FUEL_CHANNEL (   channel)     setFuelChannelSchedule(fuelSchedule ##channel, UINT8_C(channel), crankAngle, injChannelMask, injAngle, &angleCalcCache);

Function Documentation

◆ _calculateOpenAngle()

TESTABLE_INLINE_STATIC uint16_t _calculateOpenAngle ( const FuelSchedule &  schedule,
uint16_t  pwDegrees,
uint16_t  injAngle 
)

Compute the injector open angle for an injection channel.

Parameters
scheduleFuel schedule to calculate for
pwDegreesHow many crank degrees the calculated PW will take at the current speed
injAngleThe requested injection angle
Returns
uint16_t

◆ applyFuelTrim()

static uint16_t applyFuelTrim ( const table3d6RpmLoad &  trimTable,
uint16_t  pw,
const config6 &  page6,
const statuses &  current 
)
inlinestatic

◆ assignPrimaryPws() [1/2]

static void assignPrimaryPws ( const pulseWidths &  pulse_widths,
const config6 &  page6,
const statuses &  current 
)
inlinestatic

◆ assignPrimaryPws() [2/2]

assignPrimaryPws ( pulse_widths  ,
page6  ,
current   
)

◆ assignSecondaryPws() [1/2]

static void assignSecondaryPws ( const pulseWidths &  pulse_widths,
const statuses &  current 
)
inlinestatic

◆ assignSecondaryPws() [2/2]

assignSecondaryPws ( pulse_widths  ,
current   
)

◆ BEGIN_LTO_ALWAYS_INLINE() [1/2]

BEGIN_LTO_ALWAYS_INLINE ( uint16_t  ) const &

◆ BEGIN_LTO_ALWAYS_INLINE() [2/2]

BEGIN_LTO_ALWAYS_INLINE ( void  ) const &

◆ beginInjectorPriming()

void beginInjectorPriming ( const statuses &  current,
const config4 &  page4 
)

Start priming the fuel system.

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

◆ calcAngularCylinderSeparation()

TESTABLE_INLINE_STATIC uint16_t calcAngularCylinderSeparation ( const statuses &  current,
const config2 &  page2 
)

◆ calcNumInjectors()

TESTABLE_STATIC num_injector_t calcNumInjectors ( const statuses &  current,
const config2 &  page2,
const config10 &  page10 
)

◆ calcNumPrimaryInjectors()

TESTABLE_INLINE_STATIC uint8_t calcNumPrimaryInjectors ( const statuses &  current,
const config2 &  page2 
)

◆ calcNumSecondaryInjectors()

TESTABLE_STATIC uint8_t calcNumSecondaryInjectors ( uint16_t  primary,
const config2 &  page2,
const config10 &  page10 
)

◆ calcScheduleAngle()

TESTABLE_INLINE_STATIC uint16_t calcScheduleAngle ( const statuses &  current,
const config2 &  page2,
uint8_t  channel 
)

Calculate the schedule channel angle. I.e. FuelSchedule::channelDegrees.

Most cases are spaced evenly round the crank cycle, with cylinder 1 at 0deg. E.g. 2 cylinder non-sequential is over 360deg so cylinder 2 is at 180deg.

There are special cases to account for though.

◆ calculateInjectorTimeout()

TESTABLE_INLINE_STATIC uint32_t calculateInjectorTimeout ( const FuelSchedule &  schedule,
int16_t  crankAngle,
uint16_t  openAngle 
)

Calculate the time in uS from now to when the injector should be opened.

Parameters
scheduleThe ignition channel
openAngleThe angle at which to open the injector
crankAngleThe current crank angle
Returns
uint32_t

◆ calculateMaxInjAngle()

TESTABLE_STATIC uint16_t calculateMaxInjAngle ( const statuses &  current,
const config2 &  page2 
)

◆ calulateNumSquirts()

TESTABLE_STATIC uint8_t calulateNumSquirts ( const statuses &  current,
const config2 &  page2 
)

◆ changeFuellingToFullSequential()

static void changeFuellingToFullSequential ( const config2 &  page2,
const config4 &  page4,
const config10 &  page10,
statuses &  current 
)
inlinestatic

◆ changeFuellingToSemiSequential()

static void changeFuellingToSemiSequential ( const config2 &  page2,
const config4 &  page4,
const config10 &  page10,
statuses &  current 
)
inlinestatic

◆ changeToFullSequentialInjection()

TESTABLE_INLINE_STATIC bool changeToFullSequentialInjection ( const statuses &  current,
const config2 &  page2 
)

◆ changeToSemiSequentialInjection()

TESTABLE_INLINE_STATIC bool changeToSemiSequentialInjection ( const statuses &  current,
const config2 &  page2 
)

◆ closeAllInjectors()

void closeAllInjectors ( void  )

Utility function to close all injectors.

◆ configureFuelSchedules()

void configureFuelSchedules ( statuses &  current,
const config2 &  page2,
const config4 &  page4,
const config10 &  page10 
)

◆ getEvenFireAngle()

TESTABLE_INLINE_STATIC uint16_t getEvenFireAngle ( const statuses &  current,
const config2 &  page2,
uint8_t  channel 
)

◆ getOddfireAngle()

TESTABLE_INLINE_STATIC uint16_t getOddfireAngle ( const config2 &  page2,
uint8_t  channel 
)

◆ initialiseFuelSchedules()

void initialiseFuelSchedules ( statuses &  current,
config2 &  page2,
const config4 &  page4,
config6 &  page6,
config10 &  page10,
const pinNumbers_t &  pins 
)

Initialise this module.

◆ injectorLimits()

TESTABLE_INLINE_STATIC uint16_t injectorLimits ( uint16_t  angle)

Clamp the angle to within [0,CRANK_ANGLE_MAX_INJ)

◆ isAnyFuelScheduleRunning()

TESTABLE_INLINE_STATIC bool isAnyFuelScheduleRunning ( void  )

◆ isSwitchableConfig()

static bool isSwitchableConfig ( const config2 &  page2)
inlinestatic

◆ lookupInjectorAngle()

TESTABLE_INLINE_STATIC uint16_t lookupInjectorAngle ( const statuses &  current)

◆ matchFuelSchedulersToSyncState()

TESTABLE_STATIC void matchFuelSchedulersToSyncState ( const config2 &  page2,
const config4 &  page4,
const config10 &  page10,
statuses &  current 
)

◆ resetFuelSchedules()

static void resetFuelSchedules ( void  )
static

◆ setFuelChannelSchedule()

TESTABLE_INLINE_STATIC void setFuelChannelSchedule ( FuelSchedule &  schedule,
uint8_t  channel,
uint16_t  crankAngle,
byte  injChannelMask,
uint16_t  injAngle,
injectorAngleCalcCache *  pCache 
)
noexcept

◆ setFuelChannelSchedules()

TESTABLE_INLINE_STATIC uint16_t setFuelChannelSchedules ( uint16_t  crankAngle,
byte  injChannelMask,
uint16_t  injAngle 
)

◆ setInjectorAngles()

static void setInjectorAngles ( const statuses &  current,
const config2 &  page2 
)
inlinestatic

◆ setupCallbacks()

static void setupCallbacks ( uint8_t  injLayout,
uint8_t  nCylinders,
uint8_t  inj4cylPairing 
)
static

◆ setupPairedCallbacks()

static void setupPairedCallbacks ( void  )
static

◆ setupSemiSequentialCallbacks()

static void setupSemiSequentialCallbacks ( uint8_t  nCylinders,
uint8_t  inj4cylPairing 
)
static

◆ setupSequentialCallbacks()

static void setupSequentialCallbacks ( void  )
static

◆ startFuelSchedulers()

void startFuelSchedulers ( void  )

Start the timers that drive schedulers.

◆ stopFuelSchedulers()

void stopFuelSchedulers ( void  )

Stop the timers that drive schedulers.

◆ updatePwAngleCache()

TESTABLE_INLINE_STATIC uint16_t updatePwAngleCache ( uint16_t  pw,
injectorAngleCalcCache *  pCache 
)

◆ useEvenFire()

TESTABLE_INLINE_STATIC bool useEvenFire ( const config2 &  page2)

◆ validateInjectionSetup()

TESTABLE_STATIC void validateInjectionSetup ( config2 &  page2,
config6 &  page6 
)

◆ validateInjLayout()

static uint8_t validateInjLayout ( uint8_t  layout,
const config2 &  page2 
)
static

◆ zeroAllChannels()

zeroAllChannels ( void  )
inlinestatic

Variable Documentation

◆ configPage2

TESTABLE_CONSTEXPR table2D_u8_u8_4 PrimingPulseTable& configPage2

◆ current

const config2 const config4 const config6 const config10 statuses& current
Initial value:
{
const config2 & page2
Definition scheduler_fuel_controller.cpp:913
const config2 const config4 const config6 const config10 & page10
Definition scheduler_fuel_controller.cpp:913
TESTABLE_STATIC void matchFuelSchedulersToSyncState(const config2 &page2, const config4 &page4, const config10 &page10, statuses &current)
Definition scheduler_fuel_controller.cpp:900
const config2 const config4 & page4
Definition scheduler_fuel_controller.cpp:913

◆ fuelSchedule1

◆ page10

const config2 const config4 const config6 const config10& page10

◆ page2

const config2& page2

◆ page4

const config2 const config4& page4

◆ page6

const config2 const config4 const config6& page6