Merge pull request #1236 from dalathegreat/bugfix/nvrol-WDT-reset

Bugfix: Zoe PH2, Make NVROL reset survive WDT trigger
This commit is contained in:
Daniel Öster 2025-06-16 20:44:17 +03:00 committed by GitHub
commit 2e317d9d1c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 51 additions and 37 deletions

View file

@ -661,8 +661,6 @@ void RenaultZoeGen2Battery::transmit_can(unsigned long currentMillis) {
if (datalayer_extended.zoePH2.UserRequestNVROLReset) { if (datalayer_extended.zoePH2.UserRequestNVROLReset) {
// Send NVROL reset frames // Send NVROL reset frames
transmit_reset_nvrol_frames(); transmit_reset_nvrol_frames();
// after transmitting the NVROL reset frames, set the nvrol reset flag to false, to continue normal operation
datalayer_extended.zoePH2.UserRequestNVROLReset = false;
} else { } else {
// Send 100ms CAN Message // Send 100ms CAN Message
if (currentMillis - previousMillis100 >= INTERVAL_100_MS) { if (currentMillis - previousMillis100 >= INTERVAL_100_MS) {
@ -697,7 +695,6 @@ void RenaultZoeGen2Battery::transmit_can(unsigned long currentMillis) {
transmit_can_frame(&ZOE_POLL_18DADBF1, can_config.battery); transmit_can_frame(&ZOE_POLL_18DADBF1, can_config.battery);
} }
// 1000mss
if (currentMillis - previousMillis1000 >= INTERVAL_1_S) { if (currentMillis - previousMillis1000 >= INTERVAL_1_S) {
previousMillis1000 = currentMillis; previousMillis1000 = currentMillis;
@ -741,39 +738,54 @@ void RenaultZoeGen2Battery::transmit_can_frame_376(void) {
} }
void RenaultZoeGen2Battery::transmit_reset_nvrol_frames(void) { void RenaultZoeGen2Battery::transmit_reset_nvrol_frames(void) {
// NVROL reset, part 1: send 0x021003AAAAAAAAAA switch (NVROLstateMachine) {
ZOE_POLL_18DADBF1.data = {0x02, 0x10, 0x03, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA}; case 0:
transmit_can_frame(&ZOE_POLL_18DADBF1, can_config.battery); startTimeNVROL = millis();
// wait 100 ms // NVROL reset, part 1: send 0x021003AAAAAAAAAA
wait_ms(100); ZOE_POLL_18DADBF1.data = {0x02, 0x10, 0x03, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA};
// NVROL reset, part 2: send 0x043101B00900AAAA transmit_can_frame(&ZOE_POLL_18DADBF1, can_config.battery);
ZOE_POLL_18DADBF1.data = {0x04, 0x31, 0x01, 0xB0, 0x09, 0x00, 0xAA, 0xAA}; NVROLstateMachine = 1;
transmit_can_frame(&ZOE_POLL_18DADBF1, can_config.battery); break;
case 1: // wait 100 ms
// wait 1 s if ((millis() - startTimeNVROL) > INTERVAL_100_MS) {
wait_ms(1000); // NVROL reset, part 2: send 0x043101B00900AAAA
ZOE_POLL_18DADBF1.data = {0x04, 0x31, 0x01, 0xB0, 0x09, 0x00, 0xAA, 0xAA};
// Enable temporisation before sleep, part 1: send 0x021003AAAAAAAAAA transmit_can_frame(&ZOE_POLL_18DADBF1, can_config.battery);
ZOE_POLL_18DADBF1.data = {0x02, 0x10, 0x03, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA}; startTimeNVROL = millis(); //Reset time start, so we can check time for next step
transmit_can_frame(&ZOE_POLL_18DADBF1, can_config.battery); NVROLstateMachine = 2;
// wait 100 ms }
wait_ms(100); break;
// Enable temporisation before sleep, part 2: send 0x042E928101AAAAAA case 2: // wait 1 s
ZOE_POLL_18DADBF1.data = {0x04, 0x2E, 0x92, 0x81, 0x01, 0xAA, 0xAA, 0xAA}; if ((millis() - startTimeNVROL) > INTERVAL_1_S) {
transmit_can_frame(&ZOE_POLL_18DADBF1, can_config.battery); // Enable temporisation before sleep, part 1: send 0x021003AAAAAAAAAA
ZOE_POLL_18DADBF1.data = {0x02, 0x10, 0x03, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA};
// Set data back to init values transmit_can_frame(&ZOE_POLL_18DADBF1, can_config.battery);
ZOE_POLL_18DADBF1.data = {0x03, 0x22, 0x90, 0x00, 0x00, 0x00, 0x00, 0x00}; startTimeNVROL = millis(); //Reset time start, so we can check time for next step
poll_index = 0; NVROLstateMachine = 3;
}
// after transmitting these frames, wait 30 s break;
wait_ms(30000); case 3: //Wait 100ms
} if ((millis() - startTimeNVROL) > INTERVAL_100_MS) {
// Enable temporisation before sleep, part 2: send 0x042E928101AAAAAA
void RenaultZoeGen2Battery::wait_ms(int duration_ms) { ZOE_POLL_18DADBF1.data = {0x04, 0x2E, 0x92, 0x81, 0x01, 0xAA, 0xAA, 0xAA};
unsigned long freezeMillis = millis(); transmit_can_frame(&ZOE_POLL_18DADBF1, can_config.battery);
while (millis() - freezeMillis < duration_ms) { // Set data back to init values, we are done with the ZOE_POLL_18DADBF1 frame
// Do nothing - just wait ZOE_POLL_18DADBF1.data = {0x03, 0x22, 0x90, 0x00, 0x00, 0x00, 0x00, 0x00};
poll_index = 0;
NVROLstateMachine = 4;
}
break;
case 4: //Wait 30s
if ((millis() - startTimeNVROL) > INTERVAL_30_S) {
// after sleeping, set the nvrol reset flag to false, to continue normal operation of sending CAN messages
datalayer_extended.zoePH2.UserRequestNVROLReset = false;
// reset state machine, we are done!
NVROLstateMachine = 0;
}
break;
default: //Something went catastrophically wrong. Reset state machine
NVROLstateMachine = 0;
break;
} }
} }

View file

@ -167,7 +167,8 @@ class RenaultZoeGen2Battery : public CanBattery {
static const int POLL_CELL_93 = 0x9081; static const int POLL_CELL_93 = 0x9081;
static const int POLL_CELL_94 = 0x9082; static const int POLL_CELL_94 = 0x9082;
static const int POLL_CELL_95 = 0x9083; static const int POLL_CELL_95 = 0x9083;
volatile unsigned long startTimeNVROL = 0;
uint8_t NVROLstateMachine = 0;
uint16_t battery_soc = 0; uint16_t battery_soc = 0;
uint16_t battery_usable_soc = 5000; uint16_t battery_usable_soc = 5000;
uint16_t battery_soh = 10000; uint16_t battery_soh = 10000;

View file

@ -34,6 +34,7 @@ enum PrechargeState {
#define INTERVAL_2_S 2000 #define INTERVAL_2_S 2000
#define INTERVAL_5_S 5000 #define INTERVAL_5_S 5000
#define INTERVAL_10_S 10000 #define INTERVAL_10_S 10000
#define INTERVAL_30_S 30000
#define INTERVAL_60_S 60000 #define INTERVAL_60_S 60000
#define INTERVAL_10_MS_DELAYED 15 #define INTERVAL_10_MS_DELAYED 15