From 26564a0efc1c0a3804a0dcfbcc91e112feabc722 Mon Sep 17 00:00:00 2001 From: rusefillc <48498823+rusefillc@users.noreply.github.com> Date: Wed, 12 Apr 2023 22:46:30 -0400 Subject: [PATCH] More on magic constants (#223) * More on magic constants * More on magic constants * More on magic constants #223 --- .../boards/f0_module/bootloader/bootloader.cpp | 14 +++++++------- for_rusefi/wideband_can.h | 17 ++++++++++++++++- 2 files changed, 23 insertions(+), 8 deletions(-) diff --git a/firmware/boards/f0_module/bootloader/bootloader.cpp b/firmware/boards/f0_module/bootloader/bootloader.cpp index a507a42..8c63f70 100644 --- a/firmware/boards/f0_module/bootloader/bootloader.cpp +++ b/firmware/boards/f0_module/bootloader/bootloader.cpp @@ -97,7 +97,7 @@ void WaitForBootloaderCmd() } // if we got a bootloader-init message, here we go! - if (frame.DLC == 0 && frame.EID == 0xEF0'0000) + if (frame.DLC == 0 && frame.EID == WB_BL_ENTER) { return; } @@ -109,7 +109,7 @@ void sendAck() CANTxFrame frame; frame.IDE = CAN_IDE_EXT; - frame.EID = 0x727573; // ascii "rus" + frame.EID = WB_ACK; // ascii "rus" frame.RTR = CAN_RTR_DATA; frame.DLC = 0; @@ -154,7 +154,7 @@ void RunBootloaderLoop() uint16_t header = frame.EID >> 20; // All rusEfi bootloader packets start with 0x0EF, ignore other traffic on the bus - if (header != 0x0EF) + if (header != WB_BL_HEADER) { continue; } @@ -163,12 +163,12 @@ void RunBootloaderLoop() uint16_t embeddedData = frame.EID & 0xFFFF; switch (opcode) { - case 0x00: // opcode 0 is simply the "enter BL" command, but we're already here. Send an ack. + case WB_OPCODE_START: // opcode 0 is simply the "enter BL" command, but we're already here. Send an ack. sendAck(); break; - case 0x01: // opcode 1 is "erase app flash" + case WB_OPCODE_ERASE: // opcode 1 is "erase app flash" // embedded data must be 0x5A5A - if (embeddedData == 0x5A5A) + if (embeddedData == WB_ERASE_TAG) { EraseAppPages(); sendAck(); @@ -199,7 +199,7 @@ void RunBootloaderLoop() } break; - case 0x03: // opcode 3 is "boot app" + case WB_OPCODE_REBOOT: // opcode 3 is "boot app" sendAck(); // Let the message get out diff --git a/for_rusefi/wideband_can.h b/for_rusefi/wideband_can.h index 7d2043c..df75ba7 100644 --- a/for_rusefi/wideband_can.h +++ b/for_rusefi/wideband_can.h @@ -4,7 +4,22 @@ // ascii "rus" #define WB_ACK 0x727573 -#define WB_BL_ENTER 0xEF0'0000 + +#define WB_BL_HEADER 0x0EF +#define WB_OPCODE_START 0 +#define WB_OPCODE_ERASE 1 +#define WB_ERASE_TAG 0x5A5A +#define WB_OPCODE_DATA 2 +#define WB_OPCODE_REBOOT 3 + +// 0xEF0'0000 +#define WB_BL_ENTER ((WB_BL_HEADER << 4 + WB_OPCODE_START) << 16) +// 0xEF1'5A5A +#define WB_BL_ERASE ((WB_BL_HEADER << 4 + WB_OPCODE_ERASE) << 16 + WB_ERASE_TAG) +// 0xEF2'0000 +#define WB_BL_DATA_BASE ((WB_BL_HEADER << 4 + WB_OPCODE_DATA) << 16) +// 0xEF3'0000 +#define WB_BL_REBOOT ((WB_BL_HEADER << 4 + WB_OPCODE_REBOOT) << 16) #define WB_MSG_SET_INDEX 0xEF4'0000 #define WB_MGS_ECU_STATUS 0xEF5'0000 #define WB_DATA_BASE_ADDR 0x190