Speeduino
Loading...
Searching...
No Matches
Macros | Functions | Variables
scheduler_ignition_controller.cpp File Reference
#include "scheduler_ignition_controller.h"
#include "scheduledIO_ign.h"
#include "elapsed_time.h"
#include "globals.h"
#include "unit_testing.h"

Macros

#define SET_CHANNEL_ANGLE(channel)   ignitionSchedule ##channel .channelDegrees = ((channel)-1)*interCylinderAngle;
 
#define SET_IGNITION_CHANNEL(channelIdx)   setIgnitionChannel(ignitionSchedule ##channelIdx, crankAngle, dwellTime, current.schedulerCutState.ignitionChannels, channelIdx);
 

Functions

static int8_t constrainAdvanceTrim (int16_t advance)
 
static int8_t getIgnitionTrimmedAdvance (const config13 &page13, int8_t baseAdvance, uint8_t channelIndex)
 
static void setSequentialCallbacks (uint8_t numChannels)
 
static void setWastedSparkCallbacks (void)
 
static void setSingleChannelCallbacks (void)
 
static void set4CylinderWastedCOPCallbacks (void)
 
static void set6CylinderWastedCOPCallbacks (void)
 
static void set8CylinderWastedCOPCallbacks (void)
 
static void setWastedCOPCallbacks (uint8_t numCylinders)
 
static void setRotaryFcCallbacks (void)
 
static void setRotaryFdCallbacks (void)
 
static void setRotaryCallbacks (uint8_t rotaryType)
 
TESTABLE_STATIC void setCallbacks (uint8_t sparkMode, uint8_t numCylinders, uint8_t rotaryMode)
 
TESTABLE_STATIC void resetIgnitionSchedulers (void)
 
void stopAllCoilsCharging (void)
 Utility function to stop charging all ignition coils.
 
static void setOddfireScheduleAngles (const config2 &page2)
 
static void setRotaryScheduleAngles (void)
 
static void setEvenfireScheduleAngles (const statuses &current)
 
static void initScheduleAngles (const statuses &current, const config2 &page2, const config4 &page4)
 
TESTABLE_STATIC uint8_t validateSparkMode (uint8_t mode, const config2 &page2)
 
TESTABLE_STATIC void validateIgnitionSetup (config2 &page2, config4 &page4, config13 &page13)
 
static bool isSequential720 (const config4 &page4)
 
static bool isSingle720 (const config2 &page2, const config4 &page4)
 
static bool is720 (const config2 &page2, const config4 &page4)
 
static uint16_t calculateMaxIgnCrankAngle (const config2 &page2, const config4 &page4)
 
static uint8_t calculateMaxIgnChannels (const config2 &page2, const config4 &page4)
 
void initialiseIgnitionSchedules (statuses &current, config2 &page2, config4 &page4, const config10 &page10, config13 &page13, const pinNumbers_t &pins)
 Initialise all ignition schedules.
 
TESTABLE_INLINE_STATIC bool isAnyIgnScheduleRunning (void)
 
static bool isSwitchableCylinderCount (const config2 &page2)
 
static bool isSemiSequentialIgnition (const config2 &page2, const config4 &page4, const decoder_status_t &decoderStatus)
 
static bool isFullSequentialIgnition (const config4 &page4, const decoder_status_t &decoderStatus)
 
TESTABLE_STATIC void changeIgnitionToHalfSync (const config2 &page2, statuses &current)
 
TESTABLE_STATIC void changeIgnitionToFullSequential (const config2 &page2, statuses &current)
 
TESTABLE_INLINE_STATIC void matchIgnitionSchedulersToSyncState (const config2 &page2, const config4 &page4, statuses &current)
 
static int16_t _calculateSparkAngle (const IgnitionSchedule &schedule, int8_t advance)
 
static int16_t _calculateCoilChargeAngle (uint16_t dwellAngle, int16_t dischargeAngle)
 
TESTABLE_INLINE_STATIC void calculateIgnitionAngles (IgnitionSchedule &schedule, uint16_t dwellAngle, int8_t advance)
 
TESTABLE_STATIC void calculateIgnitionTrailingRotary (IgnitionSchedule &leading, uint16_t dwellAngle, int16_t rotarySplitDegrees, IgnitionSchedule &trailing)
 
static void calculateRotaryIgnitionAngles (uint16_t dwellAngle, const statuses &current)
 
static void calculateNonRotaryIgnitionAngles (const config4 &page4, const config13 &page13, uint16_t dwellAngle, const statuses &current)
 
 BEGIN_LTO_ALWAYS_INLINE (void) calculateIgnitionAngles(const config2 &page2
 
 if ((current.maxIgnOutputs==4U) &&(page4.sparkMode==IGN_MODE_ROTARY))
 
 if (page2.perToothIgn)
 
TESTABLE_INLINE_STATIC void setIgnitionScheduleDuration (IgnitionSchedule &schedule, uint32_t delay, uint16_t duration)
 
TESTABLE_INLINE_STATIC uint32_t _calculateIgnitionTimeout (const IgnitionSchedule &schedule, int16_t crankAngle)
 
static void setIgnitionChannel (IgnitionSchedule &schedule, uint16_t crankAngle, uint16_t dwellDuration, byte channelMask, uint8_t channelIdx)
 
static uint16_t applyFixedCrankingOverride (const statuses &current, const config4 &page4)
 
TESTABLE_INLINE_STATIC void applyChannelOverDwellProtection (IgnitionSchedule &schedule, uint32_t now, uint32_t dwellLimit_uS)
 
static void applyChannelOverDwellProtection (IgnitionSchedule &schedule, uint32_t dwellLimit_uS)
 
TESTABLE_INLINE_STATIC bool isOverDwellActive (const config4 &page4, const statuses &current)
 
void applyOverDwellProtection (const config4 &page4, const statuses &current)
 Check that no ignition channel has been charging the coil for too long.
 
void startIgnitionSchedulers (void)
 Start the timers that drive schedulers

 
void stopIgnitionSchedulers (void)
 Stop the timers that drive schedulers

 

Variables

IgnitionSchedule ignitionSchedule1 (IGN1_COUNTER, IGN1_COMPARE)
 
constexpr table2D_u8_u8_8 rotarySplitTable & configPage10
 
const config4 & page4
 
const config4 const config13 & page13
 
const config4 const config13 statuses & current
 
uint16_t dwellAngle = timeToAngle(current.dwell)
 
 else
 
const config4 uint16_t crankAngle
 
uint16_t dwellTime = current.dwell + applyFixedCrankingOverride(current, page4)
 

Macro Definition Documentation

◆ SET_CHANNEL_ANGLE

#define SET_CHANNEL_ANGLE (   channel)    ignitionSchedule ##channel .channelDegrees = ((channel)-1)*interCylinderAngle;

◆ SET_IGNITION_CHANNEL

#define SET_IGNITION_CHANNEL (   channelIdx)    setIgnitionChannel(ignitionSchedule ##channelIdx, crankAngle, dwellTime, current.schedulerCutState.ignitionChannels, channelIdx);

Function Documentation

◆ _calculateCoilChargeAngle()

static int16_t _calculateCoilChargeAngle ( uint16_t  dwellAngle,
int16_t  dischargeAngle 
)
inlinestatic

◆ _calculateIgnitionTimeout()

TESTABLE_INLINE_STATIC uint32_t _calculateIgnitionTimeout ( const IgnitionSchedule &  schedule,
int16_t  crankAngle 
)

◆ _calculateSparkAngle()

static int16_t _calculateSparkAngle ( const IgnitionSchedule &  schedule,
int8_t  advance 
)
inlinestatic

◆ applyChannelOverDwellProtection() [1/2]

static void applyChannelOverDwellProtection ( IgnitionSchedule &  schedule,
uint32_t  dwellLimit_uS 
)
static

◆ applyChannelOverDwellProtection() [2/2]

TESTABLE_INLINE_STATIC void applyChannelOverDwellProtection ( IgnitionSchedule &  schedule,
uint32_t  now,
uint32_t  dwellLimit_uS 
)

◆ applyFixedCrankingOverride()

static uint16_t applyFixedCrankingOverride ( const statuses &  current,
const config4 &  page4 
)
static

◆ applyOverDwellProtection()

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

Check that no ignition channel has been charging the coil for too long.

The over dwell protection system runs independently of the standard ignition schedules and monitors the time that each ignition output has been active. If the active time exceeds the tune defined amount, the output will be ended to prevent damage to coils.

Note
Must be called once per millisecond by an external timer.

◆ BEGIN_LTO_ALWAYS_INLINE()

BEGIN_LTO_ALWAYS_INLINE ( void  ) const &

Calculate the Ignition angles for all cylinders (based on config2::nCylinders). both start and end angles are calculated for each channel. Also the mode of ignition firing - wasted spark vs. dedicated spark per cyl. - is considered here.

◆ calculateIgnitionAngles()

TESTABLE_INLINE_STATIC void calculateIgnitionAngles ( IgnitionSchedule &  schedule,
uint16_t  dwellAngle,
int8_t  advance 
)

◆ calculateIgnitionTrailingRotary()

TESTABLE_STATIC void calculateIgnitionTrailingRotary ( IgnitionSchedule &  leading,
uint16_t  dwellAngle,
int16_t  rotarySplitDegrees,
IgnitionSchedule &  trailing 
)

◆ calculateMaxIgnChannels()

static uint8_t calculateMaxIgnChannels ( const config2 &  page2,
const config4 &  page4 
)
static

◆ calculateMaxIgnCrankAngle()

static uint16_t calculateMaxIgnCrankAngle ( const config2 &  page2,
const config4 &  page4 
)
static

◆ calculateNonRotaryIgnitionAngles()

static void calculateNonRotaryIgnitionAngles ( const config4 &  page4,
const config13 &  page13,
uint16_t  dwellAngle,
const statuses &  current 
)
inlinestatic

◆ calculateRotaryIgnitionAngles()

static void calculateRotaryIgnitionAngles ( uint16_t  dwellAngle,
const statuses &  current 
)
inlinestatic

◆ changeIgnitionToFullSequential()

TESTABLE_STATIC void changeIgnitionToFullSequential ( const config2 &  page2,
statuses &  current 
)

◆ changeIgnitionToHalfSync()

TESTABLE_STATIC void changeIgnitionToHalfSync ( const config2 &  page2,
statuses &  current 
)

◆ constrainAdvanceTrim()

static int8_t constrainAdvanceTrim ( int16_t  advance)
inlinestatic

◆ getIgnitionTrimmedAdvance()

static int8_t getIgnitionTrimmedAdvance ( const config13 &  page13,
int8_t  baseAdvance,
uint8_t  channelIndex 
)
inlinestatic

◆ if() [1/2]

if ( (current.maxIgnOutputs==4U) &&(page4.sparkMode==IGN_MODE_ROTARY)  )

◆ if() [2/2]

if ( page2.  perToothIgn)

◆ initialiseIgnitionSchedules()

void initialiseIgnitionSchedules ( statuses &  current,
config2 &  page2,
config4 &  page4,
const config10 &  page10,
config13 &  page13,
const pinNumbers_t &  pins 
)

Initialise all ignition schedules.

◆ initScheduleAngles()

static void initScheduleAngles ( const statuses &  current,
const config2 &  page2,
const config4 &  page4 
)
static

◆ is720()

static bool is720 ( const config2 &  page2,
const config4 &  page4 
)
inlinestatic

◆ isAnyIgnScheduleRunning()

TESTABLE_INLINE_STATIC bool isAnyIgnScheduleRunning ( void  )

◆ isFullSequentialIgnition()

static bool isFullSequentialIgnition ( const config4 &  page4,
const decoder_status_t &  decoderStatus 
)
inlinestatic

◆ isOverDwellActive()

TESTABLE_INLINE_STATIC bool isOverDwellActive ( const config4 &  page4,
const statuses &  current 
)

◆ isSemiSequentialIgnition()

static bool isSemiSequentialIgnition ( const config2 &  page2,
const config4 &  page4,
const decoder_status_t &  decoderStatus 
)
inlinestatic

◆ isSequential720()

static bool isSequential720 ( const config4 &  page4)
inlinestatic

◆ isSingle720()

static bool isSingle720 ( const config2 &  page2,
const config4 &  page4 
)
inlinestatic

◆ isSwitchableCylinderCount()

static bool isSwitchableCylinderCount ( const config2 &  page2)
inlinestatic

◆ matchIgnitionSchedulersToSyncState()

TESTABLE_INLINE_STATIC void matchIgnitionSchedulersToSyncState ( const config2 &  page2,
const config4 &  page4,
statuses &  current 
)

◆ resetIgnitionSchedulers()

TESTABLE_STATIC void resetIgnitionSchedulers ( void  )

◆ set4CylinderWastedCOPCallbacks()

static void set4CylinderWastedCOPCallbacks ( void  )
static

◆ set6CylinderWastedCOPCallbacks()

static void set6CylinderWastedCOPCallbacks ( void  )
static

◆ set8CylinderWastedCOPCallbacks()

static void set8CylinderWastedCOPCallbacks ( void  )
static

◆ setCallbacks()

TESTABLE_STATIC void setCallbacks ( uint8_t  sparkMode,
uint8_t  numCylinders,
uint8_t  rotaryMode 
)

◆ setEvenfireScheduleAngles()

static void setEvenfireScheduleAngles ( const statuses &  current)
static

◆ setIgnitionChannel()

static void setIgnitionChannel ( IgnitionSchedule &  schedule,
uint16_t  crankAngle,
uint16_t  dwellDuration,
byte  channelMask,
uint8_t  channelIdx 
)
inlinestatic

◆ setIgnitionScheduleDuration()

TESTABLE_INLINE_STATIC void setIgnitionScheduleDuration ( IgnitionSchedule &  schedule,
uint32_t  delay,
uint16_t  duration 
)

◆ setOddfireScheduleAngles()

static void setOddfireScheduleAngles ( const config2 &  page2)
static

◆ setRotaryCallbacks()

static void setRotaryCallbacks ( uint8_t  rotaryType)
static

◆ setRotaryFcCallbacks()

static void setRotaryFcCallbacks ( void  )
static

◆ setRotaryFdCallbacks()

static void setRotaryFdCallbacks ( void  )
static

◆ setRotaryScheduleAngles()

static void setRotaryScheduleAngles ( void  )
static

◆ setSequentialCallbacks()

static void setSequentialCallbacks ( uint8_t  numChannels)
static

◆ setSingleChannelCallbacks()

static void setSingleChannelCallbacks ( void  )
static

◆ setWastedCOPCallbacks()

static void setWastedCOPCallbacks ( uint8_t  numCylinders)
static

◆ setWastedSparkCallbacks()

static void setWastedSparkCallbacks ( void  )
static

◆ startIgnitionSchedulers()

void startIgnitionSchedulers ( void  )

Start the timers that drive schedulers

◆ stopAllCoilsCharging()

void stopAllCoilsCharging ( void  )

Utility function to stop charging all ignition coils.

◆ stopIgnitionSchedulers()

void stopIgnitionSchedulers ( void  )

Stop the timers that drive schedulers

◆ validateIgnitionSetup()

TESTABLE_STATIC void validateIgnitionSetup ( config2 &  page2,
config4 &  page4,
config13 &  page13 
)

◆ validateSparkMode()

TESTABLE_STATIC uint8_t validateSparkMode ( uint8_t  mode,
const config2 &  page2 
)

Variable Documentation

◆ configPage10

constexpr table2D_u8_u8_8 rotarySplitTable& configPage10
constexpr

◆ crankAngle

const config4 uint16_t crankAngle
Initial value:
{
static int16_t ignitionLimits(int16_t angle)
Makes one pass at nudging the angle to within [0,CRANK_ANGLE_MAX_IGN].
Definition crankMaths.h:65
const config4 uint16_t crankAngle
Definition scheduler_ignition_controller.cpp:724

◆ current

const config4 const config13 statuses& current
Initial value:
{
const config2 & page2
Definition engineProtection.cpp:455
const config4 const config13 statuses & current
Definition scheduler_ignition_controller.cpp:646
TESTABLE_INLINE_STATIC void matchIgnitionSchedulersToSyncState(const config2 &page2, const config4 &page4, statuses &current)
Definition scheduler_ignition_controller.cpp:538
const config4 & page4
Definition scheduler_ignition_controller.cpp:645

◆ dwellAngle

uint16_t dwellAngle = timeToAngle(current.dwell)

◆ dwellTime

uint16_t dwellTime = current.dwell + applyFixedCrankingOverride(current, page4)

◆ else

else
Initial value:
{
static void calculateNonRotaryIgnitionAngles(const config4 &page4, const config13 &page13, uint16_t dwellAngle, const statuses &current)
Definition scheduler_ignition_controller.cpp:587
const config4 const config13 & page13
Definition scheduler_ignition_controller.cpp:645
uint16_t dwellAngle
Definition scheduler_ignition_controller.cpp:649

◆ ignitionSchedule1

◆ page13

const config4 const config13& page13

◆ page4

const config4& page4