From 7513b8ea5a8946160769a9dc5f9d0d11ea195468 Mon Sep 17 00:00:00 2001 From: NOx-z <50815960+NOx-z@users.noreply.github.com> Date: Sun, 10 May 2020 22:52:20 -0700 Subject: [PATCH] Mc33 undervolt (#1421) * mc33 flash check * DI sanity checks for setting HV config * mc33 under voltage check * mc33 under voltage check Co-authored-by: Christopher W. Anderson --- firmware/hw_layer/mc33816.cpp | 45 +++++++++++++++++++++++++++++++++-- 1 file changed, 43 insertions(+), 2 deletions(-) diff --git a/firmware/hw_layer/mc33816.cpp b/firmware/hw_layer/mc33816.cpp index 24e49e82a7..096bb9a6cd 100644 --- a/firmware/hw_layer/mc33816.cpp +++ b/firmware/hw_layer/mc33816.cpp @@ -33,6 +33,7 @@ static bool flag0before = false; static bool flag0after = false; static unsigned short mcChipId; +static unsigned short mcDriverStatus; static Logging* logger; static SPIConfig spiCfg = { .circular = false, @@ -54,7 +55,7 @@ static bool validateChipId() { static void showStats() { // x9D is product code or something, and 43 is the revision? - scheduleMsg(logger, "MC %x %s", mcChipId, validateChipId() ? "hooray!" : "not hooray :("); + scheduleMsg(logger, "MC 0x%x %s", mcChipId, validateChipId() ? "hooray!" : "not hooray :("); if (CONFIG(mc33816_flag0) != GPIO_UNASSIGNED) { scheduleMsg(logger, "flag0 before %d after %d", flag0before, flag0after); @@ -65,6 +66,7 @@ static void showStats() { scheduleMsg(logger, "No flag0 pin selected"); } scheduleMsg(logger, "MC voltage %d", CONFIG(mc33_hvolt)); + scheduleMsg(logger, "MC driver status 0x%x", mcDriverStatus); } static void mcRestart(); @@ -189,6 +191,32 @@ static bool check_flash() { return true; } +static unsigned short readDriverStatus(){ + // Note: There is a config at 0x1CE & 1 that can reset this status reg on read + // otherwise the reload/recheck occurs with a write + // resetting it is necessary to reload - if the interrupt condition has been resolved + + unsigned short driverStatus; + setup_spi(); // ensure on common page? + spiSelect(driver); + spi_writew((0x8000 | 0x1D2 << 5) + 1); + driverStatus = recv_16bit_spi(); + spiUnselect(driver); + return driverStatus; +} + +static bool checkUndervoltV5(unsigned short driverStatus){ + return (driverStatus & (1<<1)); +} + +static bool checkOverTemp(unsigned short driverStatus){ + return (driverStatus & (1<<3)); +} + +static bool checkDrivenEnabled(unsigned short driverStatus){ + return (driverStatus & (1<<4)); +} + static void enable_flash() { spiSelect(driver); spi_writew(0x2001); //ch1 @@ -422,8 +450,14 @@ static void mcRestart() { setup_spi(); - mcChipId = readId(); + mcDriverStatus = readDriverStatus(); + if(checkUndervoltV5(mcDriverStatus)){ + firmwareError(OBD_PCM_Processor_Fault, "MC33 5V Under-Voltage!"); + return; + } + + mcChipId = readId(); if (!validateChipId()) { firmwareError(OBD_PCM_Processor_Fault, "No comm with MC33"); return; @@ -458,6 +492,13 @@ static void mcRestart() { } setBoostVoltage(CONFIG(mc33_hvolt)); driven.setValue(1); // driven = HV + + mcDriverStatus = readDriverStatus(); + if(!checkDrivenEnabled(mcDriverStatus)){ + firmwareError(OBD_PCM_Processor_Fault, "MC33 Driven did not stick!"); + return; + } + } #endif /* EFI_MC33816 */