auto-sync

This commit is contained in:
rusEfi 2014-09-20 20:02:53 -05:00
parent 5463dfdcad
commit fd27f6c855
7 changed files with 89 additions and 33 deletions

View File

@ -64,6 +64,7 @@
#include "rusefi.h"
#include "pin_repository.h"
#include "flash_main.h"
#include "max31855.h"
#endif
extern Engine engine;
@ -374,6 +375,8 @@ void updateTunerStudioState(TunerStudioOutputChannels *tsOutputChannels) {
tsOutputChannels->manifold_air_pressure = getMap();
tsOutputChannels->checkEngine = hasErrorCodes();
#if EFI_PROD_CODE
tsOutputChannels->egtValues.values[0] = getEgtValue(boardConfiguration, 0);
tsOutputChannels->needBurn = getNeedToWriteConfiguration();
tsOutputChannels->hasSdCard = isSdCardAlive();
tsOutputChannels->isFuelPumpOn = getOutputPinValue(FUEL_PUMP_RELAY);

View File

@ -14,7 +14,13 @@
/**
* this is used to confirm that firmware and TunerStudio are using the same rusefi.ini version
*/
#define TS_FILE_VERSION 20140917
#define TS_FILE_VERSION 20140920
#define EGT_CHANNEL_COUNT 8
typedef struct {
uint16_t values[EGT_CHANNEL_COUNT];
} egt_values_s;
/**
* please be aware that 'float' (F32) type requires TunerStudio version 2.6 and later
@ -61,7 +67,8 @@ typedef struct {
unsigned int isMapError : 1; // bit 2
unsigned int isIatError : 1; // bit 3
int tsConfigVersion;
int unused[7];
egt_values_s egtValues;
int unused[3];
} TunerStudioOutputChannels;
#endif /* TUNERSTUDIO_CONFIGURATION_H_ */

View File

@ -439,6 +439,11 @@ static void setWholeFuelMapCmd(float value) {
}
#if EFI_PROD_CODE
static void setEgtSpi(int spi) {
boardConfiguration->max31855spiDevice = (spi_device_e) spi;
}
static void setPotSpi(int spi) {
boardConfiguration->digitalPotentiometerSpiDevice = (spi_device_e) spi;
}
@ -798,7 +803,10 @@ void initSettings(engine_configuration_s *engineConfiguration) {
addConsoleActionSS("set_ignition_pin", setIgnitionPin);
addConsoleActionSS("set_trigger_input_pin", setTriggerInputPin);
addConsoleActionSS("set_trigger_simulator_pin", setTriggerSimulatorPin);
addConsoleActionSSP("set_egt_cs_pin", (VoidCharPtrCharPtrVoidPtr)setEgtCSPin, boardConfiguration);
addConsoleActionI("set_egt_spi", setEgtSpi);
addConsoleActionSS("set_trigger_simulator_mode", setTriggerSimulatorMode);
addConsoleActionS("set_fuel_pump_pin", setFuelPumpPin);
addConsoleActionS("set_idle_pin", setIdlePin);

View File

@ -270,20 +270,23 @@ void initHardware(Logging *logger, Engine *engine) {
}
SPIDriver * getSpiDevice(spi_device_e spiDevice) {
if (spiDevice == SPI_NONE) {
return NULL;
}
#if STM32_SPI_USE_SPI1 || defined(__DOXYGEN__)
if (spiDevice == SPI_DEVICE_1) {
if (spiDevice == SPI_DEVICE_1) {
return &SPID1;
}
}
#endif
#if STM32_SPI_USE_SPI2 || defined(__DOXYGEN__)
if (spiDevic e== SPI_DEVICE_2) {
return &SPID2;
}
if (spiDevic e== SPI_DEVICE_2) {
return &SPID2;
}
#endif
#if STM32_SPI_USE_SPI3 || defined(__DOXYGEN__)
if (spiDevice == SPI_DEVICE_3) {
if (spiDevice == SPI_DEVICE_3) {
return &SPID3;
}
}
#endif
firmwareError("Unexpected SPI device: %d", spiDevice);
return NULL;

View File

@ -21,6 +21,8 @@
#if EFI_MAX_31855
#define EGT_ERROR_VALUE -1000
static Logging logger;
static SPIConfig spiConfig[MAX31855_CS_COUNT];
@ -28,6 +30,8 @@ static SPIConfig spiConfig[MAX31855_CS_COUNT];
static void showEgtInfo(board_configuration_s *boardConfiguration) {
printSpiState(&logger, boardConfiguration);
scheduleMsg(&logger, "EGT spi: %d", boardConfiguration->max31855spiDevice);
for (int i = 0; i < MAX31855_CS_COUNT; i++) {
if (boardConfiguration->max31855_cs[i] != GPIO_NONE) {
scheduleMsg(&logger, "%d ETG @ %s", i, hwPortname(boardConfiguration->max31855_cs[i]));
@ -37,8 +41,6 @@ static void showEgtInfo(board_configuration_s *boardConfiguration) {
}
}
static uint32_t rx_buff;
// bits D17 and D3 are always expected to be zero
#define MC_RESERVED_BITS 0x20008
#define MC_OPEN_BIT 1
@ -64,44 +66,72 @@ static const char * getMcCode(max_32855_code code) {
}
}
static void egtRead(board_configuration_s *boardConfiguration) {
static max_32855_code getResultCode(uint32_t egtPacket) {
if ((egtPacket & MC_RESERVED_BITS) != 0) {
return MC_INVALID;
} else if ((egtPacket & MC_OPEN_BIT) != 0) {
return MC_OPEN;
} else if ((egtPacket & MC_GND_BIT) != 0) {
return MC_SHORT_GND;
} else if ((egtPacket & MC_VCC_BIT) != 0) {
return MC_SHORT_VCC;
} else {
return MC_OK;
}
}
scheduleMsg(&logger, "Reading egt");
uint32_t readEgtPacket(board_configuration_s *boardConfiguration, int egtChannel) {
uint32_t egtPacket;
SPIDriver *driver = getSpiDevice(boardConfiguration->max31855spiDevice);
if (driver == NULL) {
return 0xFFFFFFFF;
}
SPIDriver *driver = getSpiDevice(SPI_DEVICE_3);
spiStart(driver, &spiConfig[0]);
spiStart(driver, &spiConfig[egtChannel]);
spiSelect(driver);
spiReceive(driver, 4, &rx_buff);
spiReceive(driver, 4, &egtPacket);
spiUnselect(driver);
spiStop(driver);
egtPacket = SWAP_UINT32(egtPacket);
return egtPacket;
}
rx_buff = SWAP_UINT32(rx_buff);
#define GET_TEMPERATURE_C(x) (((x) >> 18) / 4)
max_32855_code code;
if ((rx_buff & MC_RESERVED_BITS) != 0) {
code = MC_INVALID;
} else if ((rx_buff & MC_OPEN_BIT) != 0) {
code = MC_OPEN;
} else if ((rx_buff & MC_GND_BIT) != 0) {
code = MC_SHORT_GND;
} else if ((rx_buff & MC_VCC_BIT) != 0) {
code = MC_SHORT_VCC;
uint16_t getEgtValue(board_configuration_s *boardConfiguration, int egtChannel) {
uint32_t packet = readEgtPacket(boardConfiguration, egtChannel);
max_32855_code code = getResultCode(packet);
if (code != MC_OK) {
return EGT_ERROR_VALUE + code;
} else {
code = MC_OK;
return GET_TEMPERATURE_C(packet);
}
}
static void egtRead(board_configuration_s *boardConfiguration) {
if (boardConfiguration->max31855spiDevice == SPI_NONE) {
scheduleMsg(&logger, "No SPI selected for EGT");
return;
}
scheduleMsg(&logger, "egt %x code=%d %s", rx_buff, code, getMcCode(code));
scheduleMsg(&logger, "Reading egt");
uint32_t egtPacket = readEgtPacket(boardConfiguration, 0);
max_32855_code code = getResultCode(egtPacket);
scheduleMsg(&logger, "egt %x code=%d %s", egtPacket, code, getMcCode(code));
if (code != MC_INVALID) {
int refBits = ((rx_buff & 0xFFFF) / 16); // bits 15:4
int refBits = ((egtPacket & 0xFFFF) / 16); // bits 15:4
float refTemp = refBits / 16.0;
scheduleMsg(&logger, "reference temperature %f", refTemp);
}
scheduleMsg(&logger, "EGT temperature %d", GET_TEMPERATURE_C(egtPacket));
}
}
void initMax31855(board_configuration_s *boardConfiguration) {

View File

@ -17,6 +17,7 @@ extern "C"
#endif /* __cplusplus */
void initMax31855(board_configuration_s *boardConfiguration);
uint16_t getEgtValue(board_configuration_s *boardConfiguration, int egtChannel);
#ifdef __cplusplus
}

View File

@ -317,7 +317,8 @@ enable2ndByteCanID = false
[OutputChannels]
fileVersion = { 20140917 }
; see TS_FILE_VERSION in firmware code
fileVersion = { 20140920 }
ochGetCommand = "O"
@ -370,6 +371,8 @@ fileVersion = { 20140917 }
ind_map_error = bits, U32, 80, [2:2], "true", "false";
ind_iat_error = bits, U32, 80, [3:3], "true", "false";
firmwareTsVersion = scalar,U32, 84, "version", 1, 0
egt0 = scalar, S16, 88, "°C", 1, 0
egt1 = scalar, S16, 90, "°C", 1, 0
time = { timeNow }
engineLoad = { fuelAlgorithm == 0 ? MAF : TPS }
@ -481,6 +484,7 @@ fileVersion = { 20140917 }
; warmupEnrichGauge = warmupEnrich, "Warmup Enrichment", "%", 100, 150, -1, -1, 101, 105, 0, 0
; accelEnrichGauge = accDecEnrich, "Accel Enrich", "%", 50, 150, -1, -1, 999, 999, 0, 0
dwellGauge = sparkDwell, "Dwell", "mSec", 0, 10, 0.5, 1.0, 6.0, 8.0, 1, 1
egt0Gauge = egt0, "EGT#0", "C", 0, 2000
[FrontPage]
; Gauges are numbered left to right, top to bottom.