From 3ce9c60448a2e413d928deffb74e0536267f58ec Mon Sep 17 00:00:00 2001 From: BlackMark Date: Sat, 11 Apr 2020 22:25:30 +0200 Subject: [PATCH] Refactor address variable --- stk500v2/main.cpp | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/stk500v2/main.cpp b/stk500v2/main.cpp index 499b4ab..a5fa85a 100644 --- a/stk500v2/main.cpp +++ b/stk500v2/main.cpp @@ -450,10 +450,8 @@ constexpr ChipEraseState &operator|=(ChipEraseState &self, const ChipEraseState return self; } -static inline void handleMessage(Message &msg, ChipEraseState &chipEraseFlag) +static inline void handleMessage(Message &msg, uint32_t &addr, ChipEraseState &chipEraseFlag) { - static uint32_t s_address; - if (isSignOn(msg)) formatSignOnAnswer(msg); else if (isGetParameter(msg)) @@ -469,20 +467,20 @@ static inline void handleMessage(Message &msg, ChipEraseState &chipEraseFlag) else if (isReadLockIsp(msg)) formatReadLockIspAnswer(msg); else if (isLoadAddress(msg)) { - s_address = msg.body[1]; - s_address = (s_address << 8) | msg.body[2]; - s_address = (s_address << 8) | msg.body[3]; - s_address = (s_address << 8) | msg.body[4]; + addr = msg.body[1]; + addr = (addr << 8) | msg.body[2]; + addr = (addr << 8) | msg.body[3]; + addr = (addr << 8) | msg.body[4]; formatLoadAddressAnswer(msg); } else if (isReadFlashIsp(msg)) - formatReadFlashIspAnswer(msg, s_address); + formatReadFlashIspAnswer(msg, addr); else if (isReadEepromIsp(msg)) - formatReadEepromIspAnswer(msg, s_address); + formatReadEepromIspAnswer(msg, addr); else if (isChipEraseIsp(msg)) { chipEraseFlag = ChipEraseState::REQUEST; formatChipEraseIspAnswer(msg); } else if (isProgramEepromIsp(msg)) - formatProgramEepromIspAnswer(msg, s_address); + formatProgramEepromIspAnswer(msg, addr); else if (isLeaveProgmodeIsp(msg)) { chipEraseFlag |= ChipEraseState::RESPONSE; formatLeaveProgmodeIspAnswer(msg); @@ -502,11 +500,12 @@ int main() serial.init(); Message msg; + uint32_t addr = 0x0000; ChipEraseState chipEraseFlag = ChipEraseState::NONE; while (true) { if (receiveMessage(msg)) { - handleMessage(msg, chipEraseFlag); + handleMessage(msg, addr, chipEraseFlag); } }