Speeduino
Loading...
Searching...
No Matches
Macros | Functions | Variables
decoders.cpp File Reference
#include <limits.h>
#include "globals.h"
#include "decoders.h"
#include "scheduledIO.h"
#include "scheduler.h"
#include "crankMaths.h"
#include "timers.h"
#include "schedule_calcs.h"
#include "unit_testing.h"
#include "atomic.h"
#include "decoder_init.h"
#include "decoder_builder.h"

Macros

#define READ_PRI_TRIGGER()   digitalRead(pinTrigger)
 
#define READ_SEC_TRIGGER()   digitalRead(pinTrigger2)
 
#define READ_THIRD_TRIGGER()   digitalRead(pinTrigger3)
 
#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 triggerRoverMEMSCommon (void)
 
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)
 
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 (void)
 
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 (int endAngle, 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 (void)
 
static uint16_t calcEndTeeth_DualWheel (int ignitionAngle, 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 (void)
 
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 (void)
 
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 (void)
 
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 (void)
 
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 (void)
 
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 (void)
 
decoder_t triggerSetup_Audi135 (void)
 
static void triggerPri_HondaD17 (void)
 
static uint16_t getRPM_HondaD17 (void)
 
static int16_t getCrankAngle_HondaD17 (void)
 
decoder_t triggerSetup_HondaD17 (void)
 
static void triggerPri_HondaJ32 (void)
 
static uint16_t getRPM_HondaJ32 (void)
 
static int16_t getCrankAngle_HondaJ32 (void)
 
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 (void)
 
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 (void)
 
decoder_t triggerSetup_MazdaAU (void)
 
static uint16_t getRPM_non360 (void)
 
static int16_t getCrankAngle_non360 (void)
 
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 (void)
 
static 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 (void)
 
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 (void)
 
decoder_t triggerSetup_Daihatsu (void)
 
static void triggerPri_Harley (void)
 
static uint16_t getRPM_Harley (void)
 
static int16_t getCrankAngle_Harley (void)
 
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 (void)
 
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 (void)
 
static uint16_t calcSetEndTeeth_FordST170 (int ignitionAngle, 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 (int ignitionAngle, 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 (void)
 
decoder_t triggerSetup_Vmax (void)
 
static void triggerPri_Renix (void)
 
static uint16_t calcEndTeeth_Renix (int ignitionAngle, uint8_t toothAdder)
 
static void triggerSetEndTeeth_Renix (void)
 
decoder_t triggerSetup_Renix (void)
 
static void triggerPri_RoverMEMS (void)
 
static void triggerSec_RoverMEMS (void)
 
static uint16_t getRPM_RoverMEMS (void)
 
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 (void)
 
static uint16_t calcEndTeeth_SuzukiK6A (int ignitionAngle)
 
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 (void)
 
static void triggerSetEndTeeth_FordTFI (void)
 
decoder_t triggerSetup_FordTFI (void)
 
static void initTriggerPin (uint8_t pin, port_register_t &pinPort, pin_mask_t &pinMask)
 
void initDecoderPins (uint8_t primaryPin, uint8_t secondaryPin, uint8_t tertiaryPin)
 Set the input pins for the decoders. Pin numbers are pulled from the tune.
 

Variables

static volatile unsigned long curTime
 
static volatile unsigned long curGap
 
static volatile unsigned long curTime2
 
static volatile unsigned long curGap2
 
static volatile unsigned long curTime3
 
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
 
static volatile unsigned long toothLastSecToothTime = 0
 
static volatile unsigned long toothLastThirdToothTime = 0
 
TESTABLE_STATIC volatile unsigned long toothLastMinusOneToothTime = 0
 
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
 
static volatile unsigned long toothOneTime = 0
 
static volatile unsigned long toothOneMinusOneTime = 0
 
static volatile unsigned long lastSyncRevolution = 0
 
static volatile bool revolutionOne = 0
 
static volatile unsigned int secondaryToothCount
 
static volatile unsigned long secondaryLastToothTime1 = 0
 
static uint16_t triggerActualTeeth
 
TESTABLE_STATIC volatile unsigned long triggerFilterTime
 
static volatile unsigned long triggerSecFilterTime
 
static volatile unsigned long triggerThirdFilterTime
 
static unsigned int triggerSecFilterTime_duration
 
TESTABLE_STATIC volatile uint16_t triggerToothAngle
 
static byte checkSyncToothCount
 
static unsigned long elapsedTime
 
static unsigned long lastCrankAngleCalc
 
static unsigned long lastVVTtime
 
TESTABLE_STATIC uint16_t ignition1EndTooth = 0
 
TESTABLE_STATIC uint16_t ignition2EndTooth = 0
 
TESTABLE_STATIC uint16_t ignition3EndTooth = 0
 
TESTABLE_STATIC uint16_t ignition4EndTooth = 0
 
static int16_t toothAngles [24]
 
TESTABLE_STATIC decoder_status_t decoderStatus
 
static port_register_t triggerPri_pin_port
 
static pin_mask_t triggerPri_pin_mask
 
static port_register_t triggerSec_pin_port
 
static pin_mask_t triggerSec_pin_mask
 
static port_register_t triggerThird_pin_port
 
static pin_mask_t triggerThird_pin_mask
 
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

◆ ID_TOOTH_PATTERN

#define ID_TOOTH_PATTERN   0

◆ READ_PRI_TRIGGER

#define READ_PRI_TRIGGER ( )    digitalRead(pinTrigger)

◆ READ_SEC_TRIGGER

#define READ_SEC_TRIGGER ( )    digitalRead(pinTrigger2)

◆ READ_THIRD_TRIGGER

#define READ_THIRD_TRIGGER ( )    digitalRead(pinTrigger3)

◆ 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

◆ initDecoderPins()

void initDecoderPins ( uint8_t  primaryPin,
uint8_t  secondaryPin,
uint8_t  tertiaryPin 
)

Set the input pins for the decoders. Pin numbers are pulled from the tune.

Parameters
primaryPinPrimary pin - usually the crank trigger
secondaryPinSecondary pin - optional, usually the cam trigger
tertiaryPinTertiary pin - optional, for decoders that use a 3rd input. E.g. VVT
Here is the call graph for this function:
Here is the caller graph for this function:

◆ initTriggerPin()

static void initTriggerPin ( uint8_t  pin,
port_register_t pinPort,
pin_mask_t pinMask 
)
static
Here is the call graph for this function:
Here is the caller graph for this function:

◆ triggerSec_DRZ400()

static void triggerSec_DRZ400 ( void  )
static
Here is the call graph for this function:
Here is the caller graph for this function:

◆ triggerSetup_DRZ400()

decoder_t triggerSetup_DRZ400 ( void  )
Here is the call graph for this function:
Here is the caller graph for this function:

Variable Documentation

◆ checkSyncToothCount

byte checkSyncToothCount
static

◆ curGap

volatile unsigned long curGap
static

◆ curGap2

volatile unsigned long curGap2
static

◆ curGap3

volatile unsigned long curGap3
static

◆ curTime

volatile unsigned long curTime
static

◆ curTime2

volatile unsigned long curTime2
static

◆ curTime3

volatile unsigned long curTime3
static

◆ decoderStatus

◆ elapsedTime

unsigned long elapsedTime
static

◆ ignition1EndTooth

TESTABLE_STATIC uint16_t ignition1EndTooth = 0

◆ ignition2EndTooth

TESTABLE_STATIC uint16_t ignition2EndTooth = 0

◆ ignition3EndTooth

TESTABLE_STATIC uint16_t ignition3EndTooth = 0

◆ ignition4EndTooth

TESTABLE_STATIC uint16_t ignition4EndTooth = 0

◆ lastCrankAngleCalc

unsigned long lastCrankAngleCalc
static

◆ lastGap

volatile unsigned long lastGap
static

◆ lastSyncRevolution

volatile unsigned long lastSyncRevolution = 0
static

◆ lastVVTtime

unsigned long lastVVTtime
static

◆ MAX_STALL_TIME

◆ revolutionOne

volatile bool revolutionOne = 0
static

◆ secondaryLastToothTime1

volatile unsigned long secondaryLastToothTime1 = 0
static

◆ secondaryToothCount

volatile unsigned int secondaryToothCount
static

◆ 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

volatile unsigned long toothLastMinusOneSecToothTime = 0
static

◆ toothLastMinusOneToothTime

TESTABLE_STATIC volatile unsigned long toothLastMinusOneToothTime = 0

◆ toothLastSecToothRisingTime

TESTABLE_STATIC volatile unsigned long toothLastSecToothRisingTime = 0

◆ toothLastSecToothTime

volatile unsigned long toothLastSecToothTime = 0
static

◆ toothLastThirdToothTime

volatile unsigned long toothLastThirdToothTime = 0
static

◆ toothLastToothRisingTime

TESTABLE_STATIC volatile unsigned long toothLastToothRisingTime = 0

◆ toothLastToothTime

TESTABLE_STATIC volatile unsigned long toothLastToothTime = 0

◆ toothOneMinusOneTime

volatile unsigned long toothOneMinusOneTime = 0
static

◆ toothOneTime

volatile unsigned long toothOneTime = 0
static

◆ toothSystemCount

TESTABLE_STATIC volatile byte toothSystemCount = 0

◆ toothSystemLastToothTime

TESTABLE_STATIC volatile unsigned long toothSystemLastToothTime = 0

◆ triggerActualTeeth

uint16_t triggerActualTeeth
static

◆ triggerFilterTime

◆ triggerPri_pin_mask

pin_mask_t triggerPri_pin_mask
static

◆ triggerPri_pin_port

port_register_t triggerPri_pin_port
static

◆ triggerSec_pin_mask

pin_mask_t triggerSec_pin_mask
static

◆ triggerSec_pin_port

port_register_t triggerSec_pin_port
static

◆ triggerSecFilterTime

volatile unsigned long triggerSecFilterTime
static

◆ triggerSecFilterTime_duration

unsigned int triggerSecFilterTime_duration
static

◆ triggerThird_pin_mask

pin_mask_t triggerThird_pin_mask
static

◆ triggerThird_pin_port

port_register_t triggerThird_pin_port
static

◆ triggerThirdFilterTime

volatile unsigned long triggerThirdFilterTime
static

◆ triggerToothAngle

TESTABLE_STATIC volatile uint16_t triggerToothAngle