Speeduino
Loading...
Searching...
No Matches
Functions | Variables
engineProtection.cpp File Reference
#include "globals.h"
#include "engineProtection.h"
#include "maths.h"
#include "units.h"
#include "unit_testing.h"
#include "preprocessor.h"
#include "decoder_init.h"

Functions

TESTABLE_INLINE_STATIC bool checkOilPressureLimit (const statuses &current, const config6 &page6, const config10 &page10, uint32_t currMillis)
 
TESTABLE_INLINE_STATIC bool checkBoostLimit (const statuses &current, const config6 &page6)
 
static bool canApplyAfrLimit (const config6 &page6, const config9 &page9)
 
static uint16_t getAfrO2Limit (const statuses &current, const config9 &page9)
 
static bool isAfrLimitCondtionActive (const statuses &current, const config9 &page9)
 
TESTABLE_INLINE_STATIC bool checkAFRLimit (const statuses &current, const config6 &page6, const config9 &page9, uint32_t currMillis)
 
TESTABLE_INLINE_STATIC bool checkRpmLimit (const statuses &current, const config4 &page4, const config6 &page6, const config9 &page9)
 
TESTABLE_INLINE_STATIC bool checkCoolantLimit (const statuses &current, const config6 &page6, const config9 &page9)
 
 BEGIN_LTO_ALWAYS_INLINE (statuses::engine_protect_flags_t) checkEngineProtection(const statuses &current
 
 if (page6.engineProtectType !=PROTECT_CUT_OFF)
 
TESTABLE_INLINE_STATIC uint8_t getHardRevLimit (const statuses &current, const config4 &page4, const config9 &page9)
 
TESTABLE_INLINE_STATIC uint8_t applyEngineProtectionRevLimit (uint8_t curLimit, const statuses &current, const config4 &page4)
 
TESTABLE_INLINE_STATIC uint8_t applyHardLaunchRevLimit (uint8_t curLimit, const statuses &current, const config6 &page6)
 
TESTABLE_INLINE_STATIC uint16_t applyFlatShiftRevLimit (uint16_t curLimit, const statuses &current)
 
TESTABLE_INLINE_STATIC uint16_t getMaxRpm (const statuses &current, const config4 &page4, const config6 &page6, const config9 &page9)
 
static statuses::scheduler_cut_t applyFullCut (const config6 &page6)
 
TESTABLE_INLINE_STATIC bool useRollingCut (const statuses &current, const config2 &page2, uint16_t maxAllowedRPM)
 
static bool isNonSequential (const config2 &page2, const config4 &page4)
 
static uint8_t calcBaseCutRevolutions (const config2 &page2)
 
TESTABLE_INLINE_STATIC uint8_t calcRollingCutRevolutions (const config2 &page2, const config4 &page4)
 
TESTABLE_INLINE_STATIC uint8_t calcRollingCutPercentage (const statuses &current, uint16_t maxAllowedRPM)
 
static statuses::scheduler_cut_t channelOff (statuses::scheduler_cut_t cutState, const config6 &page6, uint8_t channel)
 
TESTABLE_INLINE_STATIC statuses::scheduler_cut_t channelOn (statuses::scheduler_cut_t cutState, bool supportPendingIgnitionCut, uint8_t channel)
 
TESTABLE_STATIC bool supportPendingIgnitionCut (const config2 &page2, const config4 &page4, const config6 &page6)
 
TESTABLE_STATIC statuses::scheduler_cut_t applyRollingCutPercentage (const statuses &current, const config6 &page6, uint8_t cutPercent, bool supportPendingIgnitionCut)
 
TESTABLE_STATIC statuses::scheduler_cut_t applyPendingIgnitionCuts (statuses::scheduler_cut_t cutState, const statuses &current)
 
TESTABLE_STATIC statuses::scheduler_cut_t applyRollingCut (const statuses &current, const config2 &page2, const config4 &page4, const config6 &page6, uint16_t maxAllowedRPM)
 
 BEGIN_LTO_ALWAYS_INLINE (statuses::scheduler_cut_t) calculateFuelIgnitionChannelCut(const statuses &current
 
 if (current.RPM >=maxAllowedRPM)
 
else if (useRollingCut(current, page2, maxAllowedRPM))
 

Variables

TESTABLE_STATIC uint32_t oilProtEndTime
 
TESTABLE_CONSTEXPR table2D_u8_u8_4 oilPressureProtectTableconfigPage10
 
TESTABLE_CONSTEXPR table2D_u8_u8_6 coolantProtectTableconfigPage9
 
TESTABLE_STATIC bool checkAFRLimitActive = false
 
TESTABLE_STATIC unsigned long afrProtectedActivateTime = 0
 
const config4page4
 
const config4 const config6page6
 
const config4 const config6 const config9page9
 
const config4 const config6 const config9 const config10page10
 
return flags
 
TESTABLE_STATIC uint32_t rollingCutLastRev = 0
 
TESTABLE_STATIC uint8_t(* rollingCutRandFunc )(void) noexcept = random1to100
 
constexpr statuses::scheduler_cut_t CUT_FULL_BOTH
 
constexpr statuses::scheduler_cut_t CUT_FULL_FUEL
 
constexpr statuses::scheduler_cut_t CUT_FULL_IGN
 
constexpr statuses::scheduler_cut_t CUT_NONE
 
TESTABLE_CONSTEXPR table2D_i8_u8_4 rollingCutTableconfigPage15
 Immediately below max RPM, there is a range within which we can apply a rolling cut.
 
const config2page2
 
 else
 

Function Documentation

◆ applyEngineProtectionRevLimit()

TESTABLE_INLINE_STATIC uint8_t applyEngineProtectionRevLimit ( uint8_t  curLimit,
const statuses current,
const config4 page4 
)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ applyFlatShiftRevLimit()

TESTABLE_INLINE_STATIC uint16_t applyFlatShiftRevLimit ( uint16_t  curLimit,
const statuses current 
)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ applyFullCut()

static statuses::scheduler_cut_t applyFullCut ( const config6 page6)
inlinestatic
Here is the caller graph for this function:

◆ applyHardLaunchRevLimit()

TESTABLE_INLINE_STATIC uint8_t applyHardLaunchRevLimit ( uint8_t  curLimit,
const statuses current,
const config6 page6 
)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ applyPendingIgnitionCuts()

TESTABLE_STATIC statuses::scheduler_cut_t applyPendingIgnitionCuts ( statuses::scheduler_cut_t  cutState,
const statuses current 
)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ applyRollingCut()

TESTABLE_STATIC statuses::scheduler_cut_t applyRollingCut ( const statuses current,
const config2 page2,
const config4 page4,
const config6 page6,
uint16_t  maxAllowedRPM 
)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ applyRollingCutPercentage()

TESTABLE_STATIC statuses::scheduler_cut_t applyRollingCutPercentage ( const statuses current,
const config6 page6,
uint8_t  cutPercent,
bool  supportPendingIgnitionCut 
)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ BEGIN_LTO_ALWAYS_INLINE() [1/2]

BEGIN_LTO_ALWAYS_INLINE ( statuses::engine_protect_flags_t  ) const &

◆ BEGIN_LTO_ALWAYS_INLINE() [2/2]

BEGIN_LTO_ALWAYS_INLINE ( statuses::scheduler_cut_t  ) const &
Here is the call graph for this function:

◆ calcBaseCutRevolutions()

static uint8_t calcBaseCutRevolutions ( const config2 page2)
inlinestatic
Here is the caller graph for this function:

◆ calcRollingCutPercentage()

TESTABLE_INLINE_STATIC uint8_t calcRollingCutPercentage ( const statuses current,
uint16_t  maxAllowedRPM 
)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ calcRollingCutRevolutions()

TESTABLE_INLINE_STATIC uint8_t calcRollingCutRevolutions ( const config2 page2,
const config4 page4 
)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ canApplyAfrLimit()

static bool canApplyAfrLimit ( const config6 page6,
const config9 page9 
)
inlinestatic
Here is the caller graph for this function:

◆ channelOff()

static statuses::scheduler_cut_t channelOff ( statuses::scheduler_cut_t  cutState,
const config6 page6,
uint8_t  channel 
)
inlinestatic
Here is the call graph for this function:
Here is the caller graph for this function:

◆ channelOn()

TESTABLE_INLINE_STATIC statuses::scheduler_cut_t channelOn ( statuses::scheduler_cut_t  cutState,
bool  supportPendingIgnitionCut,
uint8_t  channel 
)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ checkAFRLimit()

TESTABLE_INLINE_STATIC bool checkAFRLimit ( const statuses current,
const config6 page6,
const config9 page9,
uint32_t  currMillis 
)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ checkBoostLimit()

TESTABLE_INLINE_STATIC bool checkBoostLimit ( const statuses current,
const config6 page6 
)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ checkCoolantLimit()

TESTABLE_INLINE_STATIC bool checkCoolantLimit ( const statuses current,
const config6 page6,
const config9 page9 
)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ checkOilPressureLimit()

TESTABLE_INLINE_STATIC bool checkOilPressureLimit ( const statuses current,
const config6 page6,
const config10 page10,
uint32_t  currMillis 
)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ checkRpmLimit()

TESTABLE_INLINE_STATIC bool checkRpmLimit ( const statuses current,
const config4 page4,
const config6 page6,
const config9 page9 
)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ getAfrO2Limit()

static uint16_t getAfrO2Limit ( const statuses current,
const config9 page9 
)
inlinestatic
Here is the call graph for this function:
Here is the caller graph for this function:

◆ getHardRevLimit()

TESTABLE_INLINE_STATIC uint8_t getHardRevLimit ( const statuses current,
const config4 page4,
const config9 page9 
)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ getMaxRpm()

TESTABLE_INLINE_STATIC uint16_t getMaxRpm ( const statuses current,
const config4 page4,
const config6 page6,
const config9 page9 
)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ if() [1/3]

if ( current.RPM >=  maxAllowedRPM)
Here is the call graph for this function:

◆ if() [2/3]

if ( page6.engineProtectType !  = PROTECT_CUT_OFF)
Here is the call graph for this function:

◆ if() [3/3]

Here is the call graph for this function:

◆ isAfrLimitCondtionActive()

static bool isAfrLimitCondtionActive ( const statuses current,
const config9 page9 
)
inlinestatic
Here is the call graph for this function:
Here is the caller graph for this function:

◆ isNonSequential()

static bool isNonSequential ( const config2 page2,
const config4 page4 
)
inlinestatic
Here is the caller graph for this function:

◆ supportPendingIgnitionCut()

TESTABLE_STATIC bool supportPendingIgnitionCut ( const config2 page2,
const config4 page4,
const config6 page6 
)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ useRollingCut()

TESTABLE_INLINE_STATIC bool useRollingCut ( const statuses current,
const config2 page2,
uint16_t  maxAllowedRPM 
)
Here is the call graph for this function:

Variable Documentation

◆ afrProtectedActivateTime

TESTABLE_STATIC unsigned long afrProtectedActivateTime = 0

◆ checkAFRLimitActive

TESTABLE_STATIC bool checkAFRLimitActive = false

◆ configPage10

◆ configPage15

Immediately below max RPM, there is a range within which we can apply a rolling cut.

The rolling cut table defines a series of relative negative RPM offsets that define the window and percent cut for each offset. I.e. RPM 0---------------------—|++++++++++++++++++++|<- max RPM | rolling cut window |

◆ configPage9

◆ CUT_FULL_BOTH

constexpr statuses::scheduler_cut_t CUT_FULL_BOTH
constexpr
Initial value:
= {
.ignitionChannelsPending = 0x00,
.ignitionChannels = 0x00,
.fuelChannels = 0x00,
}

◆ CUT_FULL_FUEL

constexpr statuses::scheduler_cut_t CUT_FULL_FUEL
constexpr
Initial value:
= {
.ignitionChannelsPending = 0x00,
.ignitionChannels = 0xFF,
.fuelChannels = 0x00,
}

◆ CUT_FULL_IGN

constexpr statuses::scheduler_cut_t CUT_FULL_IGN
constexpr
Initial value:
= {
.ignitionChannelsPending = 0x00,
.ignitionChannels = 0x00,
.fuelChannels = 0xFF,
}

◆ CUT_NONE

Initial value:
= {
.ignitionChannelsPending = 0x00,
.ignitionChannels = 0xFF,
.fuelChannels = 0xFF,
}

◆ else

else
Initial value:
{
return CUT_NONE
constexpr statuses::scheduler_cut_t CUT_NONE
Definition engineProtection.cpp:253

◆ flags

return flags

◆ oilProtEndTime

TESTABLE_STATIC uint32_t oilProtEndTime

◆ page10

Initial value:
{
statuses::engine_protect_flags_t flags = { false, false, false, false, false }
return flags
Definition engineProtection.cpp:170
Engine protection status fields.
Definition statuses.h:243

◆ page2

const config2& page2

◆ page4

◆ page6

◆ page9

Initial value:
{
if ((current.decoder.getStatus().syncStatus==SyncStatus::None) || (current.startRevolutions < page4.StgCycles))
{
return CUT_FULL_BOTH;
}
if (page6.engineProtectType==PROTECT_CUT_OFF)
{
return CUT_NONE;
}
constexpr uint8_t PROTECT_CUT_OFF
Definition config_pages.h:79
TESTABLE_INLINE_STATIC uint16_t getMaxRpm(const statuses &current, const config4 &page4, const config6 &page6, const config9 &page9)
Definition engineProtection.cpp:216
const config4 const config6 const config9 & page9
Definition engineProtection.cpp:155
const config4 const config6 & page6
Definition engineProtection.cpp:155
constexpr statuses::scheduler_cut_t CUT_FULL_BOTH
Definition engineProtection.cpp:235
const config4 & page4
Definition engineProtection.cpp:155
static TIntegral readSerialIntegralTimeout(void)
Reads an integral type, timing out if necessary.
Definition comms.cpp:175
byte StgCycles
Definition config_pages.h:386

◆ rollingCutLastRev

TESTABLE_STATIC uint32_t rollingCutLastRev = 0

Tracks whether we're on the same or a different rev for the rolling cut

◆ rollingCutRandFunc

TESTABLE_STATIC uint8_t(* rollingCutRandFunc) (void) noexcept ( void  ) = random1to100
noexcept