More on magic constants (#223)

* More on magic constants

* More on magic constants

* More on magic constants #223
This commit is contained in:
rusefillc 2023-04-12 22:46:30 -04:00 committed by GitHub
parent a588f15808
commit 26564a0efc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 23 additions and 8 deletions

View File

@ -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

View File

@ -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