Initial memory allocation for 2nd fuel map

This commit is contained in:
Josh Stewart 2019-04-10 15:58:38 +10:00
parent b3b0517a66
commit 8df2c46833
8 changed files with 105 additions and 9 deletions

View File

@ -989,7 +989,21 @@ page = 10
knock_recoveryStepTime = scalar, U08, 120, "Sec", 0.1, 0.0, 0.0, 2.5, 1
knock_recoveryStep = scalar, U08, 121, "Deg", 1.0, 0.0, 0.0, 50, 0
unused11_122_191 = array, U08, 122,[70],"RPM", 100.0, 0.0, 100, 25500, 0
;Things for the 2nd fuel table
fuel2Algorithm = bits, U08, 122, [0:2], $loadSourceNames
fuel2Mode = bits, U08, 122, [3:4], "Off", "Multiplied", "Added", "Switched"
unused10_212 = bits, U08, 122, [5:7], "INVALID","1","2","3","4","5","6","INVALID","8","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID"
unused11_122_191 = array, U08, 123,[71],"RPM", 100.0, 0.0, 100, 25500, 0
;Page 11 is the fuel map and axis bins only
page = 11
; name = bits, type, offset, bits
; name = array, type, offset, shape, units, scale, translate, lo, hi, digits
; name = scalar, type, offset, units, scale, translate, lo, hi, digits
veTable2 = array, U08, 0, [16x16],"%", 1.0, 0.0, 0.0, 255.0, 0
fuelRPM2Bins = array, U08, 256, [ 16], "RPM", 100.0, 0.0, 100.0, 25500.0, 0
fuelLoad2Bins = array, U08, 272, [ 16], { bitStringValue(algorithmUnits , fuel2Algorithm) }, 2.0, 0.0, 0.0, {fuelLoadMax}, 0
;-------------------------------------------------------------------------------

View File

@ -20,6 +20,7 @@
#define seqFuelPage 8
#define canbusPage 9//Config Page 9
#define warmupPage 10 //Config Page 10
#define fuelMap2Page 11
#define SERIAL_PACKET_SIZE 91 /**< The size of the live data packet. This MUST match ochBlockSize setting in the ini file */

View File

@ -1473,6 +1473,12 @@ byte getPageValue(byte page, uint16_t valueAddress)
returnValue = *((byte *)pnt_configPage + valueAddress);
break;
case fuelMap2Page:
if( valueAddress < 256) { returnValue = fuelTable2.values[15 - (valueAddress / 16)][valueAddress % 16]; } //This is slightly non-intuitive, but essentially just flips the table vertically (IE top line becomes the bottom line etc). Columns are unchanged. Every 16 loops, manually call loop() to avoid potential misses
else if(valueAddress < 272) { returnValue = byte(fuelTable2.axisX[(valueAddress - 256)] / TABLE_RPM_MULTIPLIER); } //RPM Bins for VE table (Need to be dvidied by 100)
else if (valueAddress < 288) { returnValue = byte(fuelTable2.axisY[15 - (valueAddress - 272)] / TABLE_LOAD_MULTIPLIER); } //MAP or TPS bins for VE table
break;
default:
#ifndef SMALL_FLASH_MODE
Serial.println(F("\nPage has not been implemented yet"));

View File

@ -226,14 +226,12 @@
const char TSfirmwareVersion[] PROGMEM = "Speeduino";
const byte data_structure_version = 2; //This identifies the data structure when reading / writing.
//const byte page_size = 64;
//const int16_t npage_size[11] PROGMEM = {0,288,128,288,128,288,128,240,192,192,192};
#define NUM_PAGES 11
const uint16_t npage_size[NUM_PAGES] PROGMEM = {0,128,288,288,128,288,128,240,192,192,192};
//const byte page11_size = 128;
#define NUM_PAGES 12
const uint16_t npage_size[NUM_PAGES] = {0,128,288,288,128,288,128,240,192,192,192,288};
#define MAP_PAGE_SIZE 288
struct table3D fuelTable; //16x16 fuel map
struct table3D fuelTable2; //16x16 fuel map
struct table3D ignitionTable; //16x16 ignition map
struct table3D afrTable; //16x16 afr target map
struct table3D stagingTable; //8x8 fuel staging table
@ -410,7 +408,8 @@ struct statuses {
unsigned int PW8; //In uS
volatile byte runSecs; //Counter of seconds since cranking commenced (overflows at 255 obviously)
volatile byte secl; //Continous
volatile unsigned int loopsPerSecond;
//volatile unsigned int loopsPerSecond;
volatile uint32_t loopsPerSecond;
bool launchingSoft; //True when in launch control soft limit mode
bool launchingHard; //True when in launch control hard limit mode
uint16_t freeRAM;
@ -884,7 +883,11 @@ struct config10 {
byte knock_recoveryStepTime;
byte knock_recoveryStep;
byte unused11_122_191[70];
byte fuel2Algorithm : 3;
byte fuel2Mode : 2;
byte unused10_122 : 3;
byte unused11_123_191[69];
#if defined(CORE_AVR)
};

View File

@ -143,6 +143,12 @@ Current layout of EEPROM data (Version 3) is as follows (All sizes are in bytes)
#define EEPROM_CONFIG9_END 1902
#define EEPROM_CONFIG10_START 1902
#define EEPROM_CONFIG10_END 2094
#define EEPROM_CONFIG11_XSIZE 2094
#define EEPROM_CONFIG11_YSIZE 2095
#define EEPROM_CONFIG11_MAP 2096
#define EEPROM_CONFIG11_XBINS 2352
#define EEPROM_CONFIG11_YBINS 2369
#define EEPROM_CONFIG11_END 2385
//Calibration data is stored at the end of the EEPROM (This is in case any further calibration tables are needed as they are large blocks)
#define EEPROM_PAGE_CRC32 2514 //Size of this is 4 * <number of pages> (CRC32 = 32 bits)

View File

@ -386,6 +386,39 @@ void writeConfig(byte tableNum)
break;
case fuelMap2Page:
/*---------------------------------------------------
| Fuel table (See storage.h for data layout) - Page 1
| 16x16 table itself + the 16 values along each of the axis
-----------------------------------------------------*/
EEPROM.update(EEPROM_CONFIG11_XSIZE, fuelTable2.xSize); writeCounter++; //Write the VE Tables RPM dimension size
EEPROM.update(EEPROM_CONFIG11_YSIZE, fuelTable2.ySize); writeCounter++; //Write the VE Tables MAP/TPS dimension size
for(int x=EEPROM_CONFIG11_MAP; x<EEPROM_CONFIG11_XBINS; x++)
{
if( (writeCounter > EEPROM_MAX_WRITE_BLOCK) ) { break; } //This is a safety check to make sure we don't attempt to write too much to the EEPROM at a time.
offset = x - EEPROM_CONFIG11_MAP;
EEPROM.update(x, fuelTable2.values[15-(offset/16)][offset%16]); writeCounter++; //Write the 16x16 map
}
//RPM bins
for(int x=EEPROM_CONFIG11_XBINS; x<EEPROM_CONFIG11_YBINS; x++)
{
if( (writeCounter > EEPROM_MAX_WRITE_BLOCK) ) { break; } //This is a safety check to make sure we don't attempt to write too much to the EEPROM at a time.
offset = x - EEPROM_CONFIG1_XBINS;
EEPROM.update(x, byte(fuelTable2.axisX[offset]/TABLE_RPM_MULTIPLIER)); writeCounter++; //RPM bins are divided by 100 and converted to a byte
}
//TPS/MAP bins
for(int x=EEPROM_CONFIG11_YBINS; x<EEPROM_CONFIG11_END; x++)
{
if( (writeCounter > EEPROM_MAX_WRITE_BLOCK) ) { break; } //This is a safety check to make sure we don't attempt to write too much to the EEPROM at a time.
offset = x - EEPROM_CONFIG11_YBINS;
EEPROM.update(x, fuelTable2.axisY[offset] / TABLE_LOAD_MULTIPLIER); //Table load is divided by 2 (Allows for MAP up to 511)
}
if(writeCounter > EEPROM_MAX_WRITE_BLOCK) { eepromWritesPending = true; }
else { eepromWritesPending = false; }
break;
//That concludes the writing of the 2nd fuel table
default:
break;
}
@ -601,6 +634,26 @@ void loadConfig()
*(pnt_configPage + byte(x - EEPROM_CONFIG10_START)) = EEPROM.read(x);
}
//*********************************************************************************************************************************************************************************
//Fuel table 2 (See storage.h for data layout)
for(int x=EEPROM_CONFIG11_MAP; x<EEPROM_CONFIG11_XBINS; x++)
{
offset = x - EEPROM_CONFIG11_MAP;
fuelTable2.values[15-(offset/16)][offset%16] = EEPROM.read(x); //Read the 8x8 map
}
//RPM bins
for(int x=EEPROM_CONFIG11_XBINS; x<EEPROM_CONFIG11_YBINS; x++)
{
offset = x - EEPROM_CONFIG11_XBINS;
fuelTable2.axisX[offset] = (EEPROM.read(x) * TABLE_RPM_MULTIPLIER); //RPM bins are divided by 100 when stored. Multiply them back now
}
//TPS/MAP bins
for(int x=EEPROM_CONFIG11_YBINS; x<EEPROM_CONFIG11_END; x++)
{
offset = x - EEPROM_CONFIG11_YBINS;
fuelTable2.axisY[offset] = EEPROM.read(x) * TABLE_LOAD_MULTIPLIER;
}
}
/*

View File

@ -223,7 +223,6 @@ void oneMSInterval() //Most ARM chips can simply call a function
#if defined(CORE_AVR) //AVR chips use the ISR for this
//Reset Timer2 to trigger in another ~1ms
TCNT2 = 131; //Preload timer2 with 100 cycles, leaving 156 till overflow.
//TIFR2 = 0x00; //Timer2 INT Flag Reg: Clear Timer Overflow Flag
#endif
}

View File

@ -164,6 +164,20 @@ uint32_t calculateCRC32(byte pageNo)
CRC32_val = CRC32.crc32((byte *)pnt_configPage, sizeof(configPage10) );
break;
case fuelMap2Page:
//Confirmed working
raw_value = getPageValue(fuelMap2Page, 0);
CRC32_val = CRC32.crc32(&raw_value, 1, false);
for(uint16_t x=1; x< npage_size[fuelMap2Page]; x++)
//for(uint16_t x=1; x< 288; x++)
{
raw_value = getPageValue(fuelMap2Page, x);
CRC32_val = CRC32.crc32_upd(&raw_value, 1, false);
}
//Do a manual reflection of the CRC32 value
CRC32_val = ~CRC32_val;
break;
default:
CRC32_val = 0;
break;