Initial work on error management

This commit is contained in:
Josh Stewart 2016-07-15 17:23:30 +10:00
parent 9bc4ef3810
commit cb75452fc7
5 changed files with 113 additions and 15 deletions

40
errors.h Normal file
View File

@ -0,0 +1,40 @@
#ifndef ERRORS_H
#define ERRORS_H
/*
* Up to 64 different error codes may be defined (6 bits)
*/
#define ERR_NONE 0 //No error
#define ERR_UNKNOWN 1 //Unknown error
#define ERR_IAT_SHORT 2 //Inlet sensor shorted
#define ERR_IAT_GND 3 //Inlet sensor grounded
#define ERR_CLT_SHORT 4 //Coolant sensor shorted
#define ERR_CLT_GND 5 //Coolant Sensor grounded
#define ERR_O2_SHORT 6 //O2 sensor shorted
#define ERR_O2_GND 7 //O2 sensor grounded
#define ERR_TPS_SHORT 8 //TPS shorted (Is potentially valid)
#define ERR_TPS_GND 9 //TPS grounded (Is potentially valid)
#define ERR_BAT_HIGH 10 //Battery voltage is too high
#define ERR_BAT_LOW 11 //Battery voltage is too low
#define MAX_ERRORS 4 //The number of errors the system can hold simultaneously. Should be a power of 2
/*
* This struct is a single byte in length and is sent to TS
* The first 2 bits are used to define the current error (0-3)
* The remaining 6 bits are used to give the error number
*/
struct packedError
{
byte errorNum : 2;
byte errorID : 6;
};
byte getNextError();
byte setError(byte);
byte errorCount = 0;
byte errorCodes[4];
#endif

58
errors.ino Normal file
View File

@ -0,0 +1,58 @@
/*
Speeduino - Simple engine management for the Arduino Mega 2560 platform
Copyright (C) Josh Stewart
A full copy of the license may be found in the projects root directory
*/
/*
* Sets the next available error
* Returns the error number or 0 if there is no more room for errors
*/
byte setError(byte errorID)
{
if(errorCount < MAX_ERRORS)
{
errorCodes[errorCount] = errorID;
errorCount++;
if(errorCount == 1) { BIT_SET(currentStatus.engine, BIT_ENGINE_ERROR); } //Enable the error indicator
return errorCount;
}
return 0;
}
void clearError(byte errorID)
{
byte clearedError;
if (errorID == errorCodes[0]) { clearedError = 0; }
else if(errorID == errorCodes[1]) { clearedError = 1; }
else if(errorID == errorCodes[2]) { clearedError = 2; }
else if(errorID == errorCodes[3]) { clearedError = 3; }
else return; //Occurs when the error we're being asked to clear is not currently one of the active errors
errorCodes[clearedError] == ERR_NONE;
//Clear the required error and move any from above it 'down' in the error array
for (byte x=clearedError; x < (errorCount-1); x++)
{
errorCodes[x] == errorCodes[x+1];
errorCodes[x+1] == ERR_NONE;
}
errorCount--;
if(errorCount == 0) { BIT_CLEAR(currentStatus.engine, BIT_ENGINE_ERROR); } //Enable the error indicator
}
byte getNextError()
{
packedError currentError;
//We alternate through the errors once per second
byte currentErrorNum = currentStatus.secl % MAX_ERRORS; //Which error number will be returned. This changes once per second. Note that as long as MAX_ERRORS is a power of 2, this % operation is performed very quickly.
currentError.errorNum = currentErrorNum;
currentError.errorID = errorCodes[currentErrorNum];
return *(byte*)&currentError; //Ugly, but this forces the cast of the currentError struct to a byte.
}

View File

@ -19,14 +19,14 @@ const int map_page_size = 288;
#define BIT_CHECK(var,pos) ((var) & (1<<(pos)))
//Define bit positions within engine virable
#define BIT_ENGINE_RUN 0 // Engine running
#define BIT_ENGINE_RUN 0 // Engine running
#define BIT_ENGINE_CRANK 1 // Engine cranking
#define BIT_ENGINE_ASE 2 // after start enrichment (ASE)
#define BIT_ENGINE_WARMUP 3 // Engine in warmup
#define BIT_ENGINE_ACC 4 // in TPS acceleration model
#define BIT_ENGINE_DCC 5 // in deceleration mode
#define BIT_ENGINE_MAP 6 // in MAP acceleration mode
#define BIT_ENGINE_IDLE 7 // idle on
#define BIT_ENGINE_ASE 2 // after start enrichment (ASE)
#define BIT_ENGINE_WARMUP 3 // Engine in warmup
#define BIT_ENGINE_ACC 4 // in acceleration mode (TPS accel)
#define BIT_ENGINE_DCC 5 // in deceleration mode
#define BIT_ENGINE_ERROR 6 // Error is detected
#define BIT_ENGINE_IDLE 7 // idle on
//Define masks for Squirt
#define BIT_SQUIRT_INJ1 0 //inj1 Squirt

View File

@ -1148,10 +1148,9 @@ page = 8
indicator = { crank }, "Not Cranking", "Cranking", white, black, green, black
indicator = { startw }, "ASE OFF", "ASE", white, black, green, black
indicator = { warmup }, "WUE OFF", "WUE", white, black, green, black
indicator = { tpsaccaen }, "TPS Accel", "TPS Accel", white, black, green, black
indicator = { mapaccaen }, "MAP Accel", "MAP Accel", white, black, green, black
indicator = { tpsaccden }, "TPS Decel", "TPS Decel", white, black, green, black
indicator = { mapaccden }, "MAP Decel", "MAP Decel", white, black, green, black
indicator = { accaen }, "Accel", "Accel", white, black, green, black
indicator = { accden }, "Decel", "Decel", white, black, green, black
indicator = { isError }, "No Errors", "ERROR", white, black, green, black
indicator = { (tps > tpsflood) && (rpm < crankRPM) }, "FLOOD OFF", "FLOOD CLEAR", white, black, red, black
indicator = { DFCOOn }, "DFCO OFF", "DFCO On", white, black, red, black
indicator = { launchHard }, "Launch Hard", "Launch Hard", white, black, green, black
@ -1254,10 +1253,10 @@ page = 8
crank = bits, U08, 2, [1:1]
startw = bits, U08, 2, [2:2]
warmup = bits, U08, 2, [3:3]
tpsaccaen = bits, U08, 2, [4:4]
tpsaccden = bits, U08, 2, [5:5]
mapaccaen = bits, U08, 2, [6:6]
mapaccden = bits, U08, 2, [7:7]
accaen = bits, U08, 2, [4:4]
accden = bits, U08, 2, [5:5]
error = bits, U08, 2, [6:6]
idle = bits, U08, 2, [7:7]
dwell = scalar, U08, 3, "ms", 0.100, 0.000
map = scalar, U08, 4, "kpa", 2.000, 0.000
iatRaw = scalar, U08, 5, "°C", 1.000, 0.000

View File

@ -37,6 +37,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#include "fastAnalog.h"
#include "sensors.h"
#include "libs/PID_v1/PID_v1.h"
#include "errors.h"
#ifdef __SAM3X8E__
//Do stuff for ARM based CPUs