Speeduino
Loading...
Searching...
No Matches
Macros | Functions | Variables
decoders.cpp File Reference
#include <limits.h>
#include "globals.h"
#include "decoders.h"
#include "elapsed_time.h"
#include "scheduler.h"
#include "crankMaths.h"
#include "timers.h"
#include "unit_testing.h"
#include "atomic.h"
#include "decoder_init.h"
#include "decoder_builder.h"
#include "scheduledIO_ign.h"
#include "src/pins/boardInputPin.h"
#include "scheduler_ignition_controller.h"

Macros

#define CRANK_ANGLE_MAX   ((std::max)(CRANK_ANGLE_MAX_IGN, CRANK_ANGLE_MAX_INJ))
 
#define TOOTH_CRANK   0
 
#define TOOTH_CAM_SECONDARY   1
 
#define TOOTH_CAM_TERTIARY   2
 
#define ID_TOOTH_PATTERN   0
 
#define SKIP_TOOTH1   1
 
#define SKIP_TOOTH2   2
 
#define SKIP_TOOTH3   3
 
#define SKIP_TOOTH4   4
 
#define TRIGGER_FILTER_OFF   0
 
#define TRIGGER_FILTER_LITE   1
 
#define TRIGGER_FILTER_MEDIUM   2
 
#define TRIGGER_FILTER_AGGRESSIVE   3
 
#define secondaryToothLastCount   checkSyncToothCount
 
#define renixSystemLastToothTime   toothLastToothRisingTime
 
#define renixSystemLastMinusOneToothTime   toothLastSecToothRisingTime
 

Functions

static void triggerRecordVVT1Angle (void)
 
static void addToothLogEntry (unsigned long toothTime, byte whichTooth)
 
void loggerPrimaryISR (void)
 
void loggerSecondaryISR (void)
 
void loggerTertiaryISR (void)
 
static decoder_status_t sharedGetStatus (void) noexcept
 
TESTABLE_STATIC uint16_t timeToAngleIntervalTooth (uint32_t time)
 
static bool IsCranking (const statuses &status)
 
TESTABLE_STATIC bool sharedEngineIsRunning (uint32_t curTime)
 
static decoder_features_t sharedGetDecoderFeatures (void)
 
static void sharedDecoderReset (void)
 
TESTABLE_STATIC bool SetRevolutionTime (uint32_t revTime)
 
static bool UpdateRevolutionTimeFromTeeth (bool isCamTeeth)
 
static uint16_t RpmFromRevolutionTimeUs (uint32_t revTime)
 
static uint16_t stdGetRPM (bool isCamTeeth)
 
static void setFilter (unsigned long curGap)
 
static int crankingGetRPM (byte totalTeeth, bool isCamTeeth)
 
static void checkPerToothTiming (int16_t crankAngle, uint16_t currentTooth)
 
static uint8_t getConfigPriTriggerEdge (const config4 &page4)
 
static uint8_t getConfigSecTriggerEdge (const config4 &page4)
 
static uint8_t getConfigTerTriggerEdge (const config10 &page10)
 
static void triggerPri_missingTooth (void)
 
static void triggerSec_missingTooth (void)
 
static void triggerThird_missingTooth (void)
 
static uint16_t getRPM_missingTooth (void)
 
static int16_t getCrankAngle_missingTooth (uint32_t currMicros)
 
static uint16_t clampToToothCount (int16_t toothNum, uint8_t toothAdder)
 
static uint16_t clampToActualTeeth (uint16_t toothNum, uint8_t toothAdder)
 
static uint16_t calcEndTeeth_missingTooth (const IgnitionSchedule &schedule, uint8_t toothAdder)
 
static void triggerSetEndTeeth_missingTooth (void)
 
decoder_t triggerSetup_missingTooth (void)
 Setup function for each decoder type.
 
static void triggerPri_DualWheel (void)
 
static void triggerSec_DualWheel (void)
 
static uint16_t getRPM_DualWheel (void)
 
static int16_t getCrankAngle_DualWheel (uint32_t currMicros)
 
static uint16_t calcEndTeeth_DualWheel (const IgnitionSchedule &schedule, uint8_t toothAdder)
 
static void triggerSetEndTeeth_DualWheel (void)
 
decoder_t triggerSetup_DualWheel (void)
 
static void triggerPri_BasicDistributor (void)
 
static uint16_t getRPM_BasicDistributor (void)
 
static int16_t getCrankAngle_BasicDistributor (uint32_t currMicros)
 
static void triggerSetEndTeeth_BasicDistributor (void)
 
decoder_t triggerSetup_BasicDistributor (void)
 
static void triggerPri_GM7X (void)
 
static uint16_t getRPM_GM7X (void)
 
static int16_t getCrankAngle_GM7X (uint32_t currMicros)
 
static void triggerSetEndTeeth_GM7X (void)
 
decoder_t triggerSetup_GM7X (void)
 
static void triggerPri_4G63 (void)
 
static void triggerSec_4G63 (void)
 
static uint16_t getRPM_4G63 (void)
 
static int16_t getCrankAngle_4G63 (uint32_t currMicros)
 
static void triggerSetEndTeeth_4G63 (void)
 
decoder_t triggerSetup_4G63 (void)
 
static void triggerPri_24X (void)
 
static void triggerSec_24X (void)
 
static uint16_t getRPM_24X (void)
 
static int16_t getCrankAngle_24X (uint32_t currMicros)
 
decoder_t triggerSetup_24X (void)
 
static void triggerPri_Jeep2000 (void)
 
static void triggerSec_Jeep2000 (void)
 
static uint16_t getRPM_Jeep2000 (void)
 
static int16_t getCrankAngle_Jeep2000 (uint32_t currMicros)
 
decoder_t triggerSetup_Jeep2000 (void)
 
static void triggerPri_Audi135 (void)
 
static void triggerSec_Audi135 (void)
 
static uint16_t getRPM_Audi135 (void)
 
static int16_t getCrankAngle_Audi135 (uint32_t currMicros)
 
decoder_t triggerSetup_Audi135 (void)
 
static void triggerPri_HondaD17 (void)
 
static uint16_t getRPM_HondaD17 (void)
 
static int16_t getCrankAngle_HondaD17 (uint32_t currMicros)
 
decoder_t triggerSetup_HondaD17 (void)
 
static void triggerPri_HondaJ32 (void)
 
static uint16_t getRPM_HondaJ32 (void)
 
static int16_t getCrankAngle_HondaJ32 (uint32_t currMicros)
 
decoder_t triggerSetup_HondaJ32 (void)
 
static void triggerPri_Miata9905 (void)
 
static void triggerSec_Miata9905 (void)
 
static uint16_t getRPM_Miata9905 (void)
 
static int16_t getCrankAngle_Miata9905 (uint32_t currMicros)
 
int getCamAngle_Miata9905 (void)
 
static void triggerSetEndTeeth_Miata9905 (void)
 
decoder_t triggerSetup_Miata9905 (void)
 
static void triggerPri_MazdaAU (void)
 
static void triggerSec_MazdaAU (void)
 
static uint16_t getRPM_MazdaAU (void)
 
static int16_t getCrankAngle_MazdaAU (uint32_t currMicros)
 
decoder_t triggerSetup_MazdaAU (void)
 
static uint16_t getRPM_non360 (void)
 
static int16_t getCrankAngle_non360 (uint32_t currMicros)
 
decoder_t triggerSetup_non360 (void)
 
static void triggerPri_Nissan360 (void)
 
static void triggerSec_Nissan360 (void)
 
static uint16_t getRPM_Nissan360 (void)
 
static int16_t getCrankAngle_Nissan360 (uint32_t currMicros)
 
static uint16_t calcEndTooth_Nissan360 (const IgnitionSchedule &schedule)
 
void triggerSetEndTeeth_Nissan360 (void)
 
decoder_t triggerSetup_Nissan360 (void)
 
static void triggerPri_Subaru67 (void)
 
static void triggerSec_Subaru67 (void)
 
static uint16_t getRPM_Subaru67 (void)
 
static int16_t getCrankAngle_Subaru67 (uint32_t currMicros)
 
static void triggerSetEndTeeth_Subaru67 (void)
 
decoder_t triggerSetup_Subaru67 (void)
 
static void triggerPri_Daihatsu (void)
 
static uint16_t getRPM_Daihatsu (void)
 
static int16_t getCrankAngle_Daihatsu (uint32_t currMicros)
 
decoder_t triggerSetup_Daihatsu (void)
 
static void triggerPri_Harley (void)
 
static uint16_t getRPM_Harley (void)
 
static int16_t getCrankAngle_Harley (uint32_t currMicros)
 
decoder_t triggerSetup_Harley (void)
 
static void triggerPri_ThirtySixMinus222 (void)
 
static uint16_t getRPM_ThirtySixMinus222 (void)
 
static void triggerSetEndTeeth_ThirtySixMinus222 (void)
 
decoder_t triggerSetup_ThirtySixMinus222 (void)
 
static void triggerPri_ThirtySixMinus21 (void)
 
static uint16_t getRPM_ThirtySixMinus21 (void)
 
static void triggerSetEndTeeth_ThirtySixMinus21 (void)
 
decoder_t triggerSetup_ThirtySixMinus21 (void)
 
static void triggerPri_420a (void)
 
static void triggerSec_420a (void)
 
static uint16_t getRPM_420a (void)
 
static int16_t getCrankAngle_420a (uint32_t currMicros)
 
static void triggerSetEndTeeth_420a (void)
 
decoder_t triggerSetup_420a (void)
 
static void triggerPri_Webber (void)
 
static void triggerSec_Webber (void)
 
decoder_t triggerSetup_Webber (void)
 
static void triggerSec_FordST170 (void)
 
static uint16_t getRPM_FordST170 (void)
 
static int16_t getCrankAngle_FordST170 (uint32_t currMicros)
 
static uint16_t calcSetEndTeeth_FordST170 (const IgnitionSchedule &schedule, uint8_t toothAdder)
 
static void triggerSetEndTeeth_FordST170 (void)
 
decoder_t triggerSetup_FordST170 (void)
 
static void triggerSec_DRZ400 (void)
 
decoder_t triggerSetup_DRZ400 (void)
 
static void triggerPri_NGC (void)
 
static void triggerSec_NGC4 (void)
 
static void triggerSec_NGC68 (void)
 
static uint16_t getRPM_NGC (void)
 
static uint16_t calcSetEndTeeth_NGC_SkipMissing (uint16_t toothNum)
 
static uint16_t calcSetEndTeeth_NGC (IgnitionSchedule &schedule, uint8_t toothAdder)
 
static void triggerSetEndTeeth_NGC (void)
 
decoder_t triggerSetup_NGC (void)
 
static void triggerPri_Vmax (void)
 
static uint16_t getRPM_Vmax (void)
 
static int16_t getCrankAngle_Vmax (uint32_t currMicros)
 
decoder_t triggerSetup_Vmax (void)
 
static void triggerPri_Renix (void)
 
static uint16_t calcEndTeeth_Renix (const IgnitionSchedule &schedule, uint8_t toothAdder)
 
static void triggerSetEndTeeth_Renix (void)
 
decoder_t triggerSetup_Renix (void)
 
static void triggerRoverMEMSCommon (uint32_t curTime)
 
static void triggerPri_RoverMEMS (void)
 
static void triggerSec_RoverMEMS (void)
 
static uint16_t getRPM_RoverMEMS (void)
 
static int16_t calcEndTooth_RoverMEMS (const IgnitionSchedule &schedule, uint8_t toothAdder)
 
static void triggerSetEndTeeth_RoverMEMS (void)
 
decoder_t triggerSetup_RoverMEMS (void)
 
static void triggerPri_SuzukiK6A (void)
 
static uint16_t getRPM_SuzukiK6A (void)
 
static int16_t getCrankAngle_SuzukiK6A (uint32_t currMicros)
 
static uint16_t calcEndTeeth_SuzukiK6A (const IgnitionSchedule &schedule)
 
static void triggerSetEndTeeth_SuzukiK6A (void)
 
decoder_t triggerSetup_SuzukiK6A (void)
 
static void triggerPri_FordTFI (void)
 
static void triggerSec_FordTFI (void)
 
static uint16_t getRPM_FordTFI (void)
 
static int16_t getCrankAngle_FordTFI (uint32_t currMicros)
 
static void triggerSetEndTeeth_FordTFI (void)
 
decoder_t triggerSetup_FordTFI (void)
 

Variables

static volatile unsigned long curGap
 
static volatile unsigned long curGap2
 
static volatile unsigned long curGap3
 
static volatile unsigned long lastGap
 
static volatile unsigned long targetGap
 
TESTABLE_STATIC unsigned long MAX_STALL_TIME = MICROS_PER_SEC/2U
 
TESTABLE_STATIC uint16_t toothCurrentCount = 0
 
TESTABLE_STATIC volatile byte toothSystemCount = 0
 
TESTABLE_STATIC volatile unsigned long toothSystemLastToothTime = 0
 
TESTABLE_STATIC volatile unsigned long toothLastToothTime = 0
 
TESTABLE_STATIC volatile unsigned long toothLastSecToothTime = 0
 
TESTABLE_STATIC volatile unsigned long toothLastThirdToothTime = 0
 
TESTABLE_STATIC volatile unsigned long toothLastMinusOneToothTime = 0
 
TESTABLE_STATIC volatile unsigned long toothLastMinusOneSecToothTime = 0
 
TESTABLE_STATIC volatile unsigned long toothLastToothRisingTime = 0
 
TESTABLE_STATIC volatile unsigned long toothLastSecToothRisingTime = 0
 
static volatile unsigned long targetGap2
 
static volatile unsigned long targetGap3
 
TESTABLE_STATIC volatile unsigned long toothOneTime = 0
 
TESTABLE_STATIC volatile unsigned long toothOneMinusOneTime = 0
 
static volatile unsigned long lastSyncRevolution = 0
 
TESTABLE_STATIC volatile bool revolutionOne = 0
 
TESTABLE_STATIC volatile unsigned int secondaryToothCount
 
static uint16_t triggerActualTeeth
 
TESTABLE_STATIC volatile unsigned long triggerFilterTime
 
static volatile unsigned long triggerSecFilterTime
 
static volatile unsigned long triggerThirdFilterTime
 
TESTABLE_STATIC volatile uint16_t triggerToothAngle
 
static byte checkSyncToothCount
 
static unsigned long lastVVTtime
 
TESTABLE_STATIC uint16_t ignitionEndTeeth [IGN_CHANNELS]
 
static int16_t toothAngles [24]
 
TESTABLE_STATIC decoder_status_t decoderStatus
 
constexpr uint8_t COMPOSITE_LOG_PRI = 0
 
constexpr uint8_t COMPOSITE_LOG_SEC = 1
 
constexpr uint8_t COMPOSITE_LOG_THIRD = 2
 
constexpr uint8_t COMPOSITE_LOG_TRIG = 3
 
constexpr uint8_t COMPOSITE_LOG_SYNC = 4
 
constexpr uint8_t COMPOSITE_ENGINE_CYCLE = 5
 
static decoder_features_t decoderFeatures
 
volatile unsigned long roverMEMSTeethSeen = 0
 

Detailed Description

Crank and Cam decoders

This file contains the various crank and cam wheel decoder functions. Each decoder must have the following 4 functions (Where xxxx is the decoder name):

Each decoder must utilise at least the following variables:

Macro Definition Documentation

◆ CRANK_ANGLE_MAX

#define CRANK_ANGLE_MAX   ((std::max)(CRANK_ANGLE_MAX_IGN, CRANK_ANGLE_MAX_INJ))

◆ ID_TOOTH_PATTERN

#define ID_TOOTH_PATTERN   0

◆ SKIP_TOOTH1

#define SKIP_TOOTH1   1

◆ SKIP_TOOTH2

#define SKIP_TOOTH2   2

◆ SKIP_TOOTH3

#define SKIP_TOOTH3   3

◆ SKIP_TOOTH4

#define SKIP_TOOTH4   4

◆ TOOTH_CAM_SECONDARY

#define TOOTH_CAM_SECONDARY   1

◆ TOOTH_CAM_TERTIARY

#define TOOTH_CAM_TERTIARY   2

◆ TOOTH_CRANK

#define TOOTH_CRANK   0

Function Documentation

◆ triggerSec_DRZ400()

static void triggerSec_DRZ400 ( void  )
static

◆ triggerSetup_DRZ400()

decoder_t triggerSetup_DRZ400 ( void  )

Variable Documentation

◆ checkSyncToothCount

byte checkSyncToothCount
static

◆ COMPOSITE_ENGINE_CYCLE

constexpr uint8_t COMPOSITE_ENGINE_CYCLE = 5
constexpr

◆ COMPOSITE_LOG_PRI

constexpr uint8_t COMPOSITE_LOG_PRI = 0
constexpr

◆ COMPOSITE_LOG_SEC

constexpr uint8_t COMPOSITE_LOG_SEC = 1
constexpr

◆ COMPOSITE_LOG_SYNC

constexpr uint8_t COMPOSITE_LOG_SYNC = 4
constexpr

◆ COMPOSITE_LOG_THIRD

constexpr uint8_t COMPOSITE_LOG_THIRD = 2
constexpr

◆ COMPOSITE_LOG_TRIG

constexpr uint8_t COMPOSITE_LOG_TRIG = 3
constexpr

◆ curGap

volatile unsigned long curGap
static

◆ curGap2

volatile unsigned long curGap2
static

◆ curGap3

volatile unsigned long curGap3
static

◆ decoderStatus

◆ ignitionEndTeeth

TESTABLE_STATIC uint16_t ignitionEndTeeth[IGN_CHANNELS]

◆ lastGap

volatile unsigned long lastGap
static

◆ lastSyncRevolution

volatile unsigned long lastSyncRevolution = 0
static

◆ lastVVTtime

unsigned long lastVVTtime
static

◆ MAX_STALL_TIME

TESTABLE_STATIC unsigned long MAX_STALL_TIME = MICROS_PER_SEC/2U

◆ revolutionOne

TESTABLE_STATIC volatile bool revolutionOne = 0

◆ secondaryToothCount

TESTABLE_STATIC volatile unsigned int secondaryToothCount

◆ targetGap

volatile unsigned long targetGap
static

◆ targetGap2

volatile unsigned long targetGap2
static

◆ targetGap3

volatile unsigned long targetGap3
static

◆ toothAngles

int16_t toothAngles[24]
static

◆ toothCurrentCount

TESTABLE_STATIC uint16_t toothCurrentCount = 0

◆ toothLastMinusOneSecToothTime

TESTABLE_STATIC volatile unsigned long toothLastMinusOneSecToothTime = 0

◆ toothLastMinusOneToothTime

TESTABLE_STATIC volatile unsigned long toothLastMinusOneToothTime = 0

◆ toothLastSecToothRisingTime

TESTABLE_STATIC volatile unsigned long toothLastSecToothRisingTime = 0

◆ toothLastSecToothTime

TESTABLE_STATIC volatile unsigned long toothLastSecToothTime = 0

◆ toothLastThirdToothTime

TESTABLE_STATIC volatile unsigned long toothLastThirdToothTime = 0

◆ toothLastToothRisingTime

TESTABLE_STATIC volatile unsigned long toothLastToothRisingTime = 0

◆ toothLastToothTime

TESTABLE_STATIC volatile unsigned long toothLastToothTime = 0

◆ toothOneMinusOneTime

TESTABLE_STATIC volatile unsigned long toothOneMinusOneTime = 0

◆ toothOneTime

TESTABLE_STATIC volatile unsigned long toothOneTime = 0

◆ toothSystemCount

TESTABLE_STATIC volatile byte toothSystemCount = 0

◆ toothSystemLastToothTime

TESTABLE_STATIC volatile unsigned long toothSystemLastToothTime = 0

◆ triggerActualTeeth

uint16_t triggerActualTeeth
static

◆ triggerFilterTime

TESTABLE_STATIC volatile unsigned long triggerFilterTime

◆ triggerSecFilterTime

volatile unsigned long triggerSecFilterTime
static

◆ triggerThirdFilterTime

volatile unsigned long triggerThirdFilterTime
static

◆ triggerToothAngle

TESTABLE_STATIC volatile uint16_t triggerToothAngle