I think it's OK to crash very visibly if no proper SPI response

This commit is contained in:
rusefi 2020-05-13 01:07:11 -04:00
parent 159789dc5b
commit 52ad619b15
1 changed files with 8 additions and 23 deletions

View File

@ -82,7 +82,8 @@ typedef enum {
#define FWDRespCmd(d) CMD_WR(0x16, d) #define FWDRespCmd(d) CMD_WR(0x16, d)
#define FWDRespSyncCmd(d) CMD_WR(0x17, d) #define FWDRespSyncCmd(d) CMD_WR(0x17, d)
#define CMD_SR CMD_WR(0x1a, 0x03) #define CMD_SR_CODE 0x1a
#define CMD_SR CMD_WR(CMD_SR_CODE, 0x03)
// 0x238 = 568 // 0x238 = 568
#define CMD_OE_SET CMD_WR(0x1c, 0x02) #define CMD_OE_SET CMD_WR(0x1c, 0x02)
/* not used /* not used
@ -191,10 +192,6 @@ float vBattForTle8888 = 0;
// set debug_mode 31 // set debug_mode 31
static int tle8888SpiCounter = 0; static int tle8888SpiCounter = 0;
// that's a strange variable for troubleshooting
int tle8888initResponsesAccumulator = 0;
static int initResponse0 = 0;
static int initResponse1 = 0;
static uint16_t spiRxb = 0, spiTxb = 0; static uint16_t spiRxb = 0, spiTxb = 0;
@ -253,10 +250,7 @@ void tle8888PostState(TsDebugChannels *debugChannels) {
//debugChannels->debugIntField1 = tle8888SpiCounter; //debugChannels->debugIntField1 = tle8888SpiCounter;
//debugChannels->debugIntField2 = spiTxb; //debugChannels->debugIntField2 = spiTxb;
//debugChannels->debugIntField3 = spiRxb; //debugChannels->debugIntField3 = spiRxb;
debugChannels->debugIntField4 = tle8888initResponsesAccumulator;
debugChannels->debugIntField5 = tle8888reinitializationCounter; debugChannels->debugIntField5 = tle8888reinitializationCounter;
debugChannels->debugFloatField1 = initResponse0;
debugChannels->debugFloatField2 = initResponse1;
debugChannels->debugFloatField3 = chips[0].OpStat[1]; debugChannels->debugFloatField3 = chips[0].OpStat[1];
debugChannels->debugFloatField4 = selfResetCounter * 1000000 + requestedResetCounter * 10000 + lowVoltageResetCounter; debugChannels->debugFloatField4 = selfResetCounter * 1000000 + requestedResetCounter * 10000 + lowVoltageResetCounter;
@ -503,16 +497,12 @@ static void handleFWDStat1(struct tle8888_priv *chip, int registerNum, int data)
tle8888_spi_rw(chip, CMD_WdDiag, &wdDiagResponse); tle8888_spi_rw(chip, CMD_WdDiag, &wdDiagResponse);
} }
int startupConfiguration(struct tle8888_priv *chip) { static int startupConfiguration(struct tle8888_priv *chip) {
const struct tle8888_config *cfg = chip->cfg; const struct tle8888_config *cfg = chip->cfg;
uint16_t response = 0; uint16_t response = 0;
/* Set LOCK bit to 0 */ /* Set LOCK bit to 0 */
// second 0x13D=317 => 0x35=53 // second 0x13D=317 => 0x35=53
tle8888_spi_rw(chip, CMD_UNLOCK, &response); tle8888_spi_rw(chip, CMD_UNLOCK, &response);
if (response == 53) {
tle8888initResponsesAccumulator += 8;
}
initResponse1 = response;
chip->o_direct_mask = 0; chip->o_direct_mask = 0;
chip->o_oe_mask = 0; chip->o_oe_mask = 0;
@ -826,7 +816,6 @@ int tle8888SpiStartupExchange(struct tle8888_priv *chip) {
const struct tle8888_config *cfg = chip->cfg; const struct tle8888_config *cfg = chip->cfg;
tle8888reinitializationCounter++; tle8888reinitializationCounter++;
tle8888initResponsesAccumulator = 0;
/** /**
* We need around 50ms to get reliable TLE8888 start if MCU is powered externally but +12 goes gown and then goes up * We need around 50ms to get reliable TLE8888 start if MCU is powered externally but +12 goes gown and then goes up
@ -837,17 +826,12 @@ int tle8888SpiStartupExchange(struct tle8888_priv *chip) {
watchdogLogic(chip); watchdogLogic(chip);
/* Software reset */ /* Software reset */
// first packet: 0x335=821 > 0xFD=253
uint16_t response = 0; uint16_t response = 0;
tle8888_spi_rw(chip, CMD_SR, &response); tle8888_spi_rw(chip, CMD_SR, NULL);
if (response == 253) { tle8888_spi_rw(chip, CMD_UNLOCK, &response);
// I've seen this response on red board if (response != (CMD_WRITE | CMD_REG_ADDR(CMD_SR_CODE))) {
tle8888initResponsesAccumulator += 4; firmwareError(CUSTOM_ERR_6724, "TLE8888 SR Unexpected response %x", response);
} else if (response == 2408) {
// and I've seen this response on red board
tle8888initResponsesAccumulator += 100;
} }
initResponse0 = response;
/** /**
* Table 8. Reset Times. All reset times not more than 20uS * Table 8. Reset Times. All reset times not more than 20uS
@ -902,6 +886,7 @@ static int tle8888_chip_init(void * data) {
} }
} }
if (ret) { if (ret) {
ret = -1; ret = -1;
goto err_gpios; goto err_gpios;