From 16e20b89b63b9cde92731b28be132167a67c0b12 Mon Sep 17 00:00:00 2001 From: Nav Date: Sun, 27 Feb 2022 20:29:26 +0000 Subject: [PATCH] Switched to automatic storage for EDBG AVR command frame payloads that are fixed in size, in the EDBG driver. This means we don't have to keep allocating space (using std::vector) for each command payload, when the payload is fixed in size. Also, some general tidying of the EDBG AVR command frames. --- CMakeLists.txt | 1 - .../VendorSpecific/EDBG/AVR/AvrCommand.hpp | 22 ++-- .../AVR8Generic/ActivatePhysical.hpp | 25 ++-- .../AVR/CommandFrames/AVR8Generic/Attach.hpp | 26 ++-- .../AVR8Generic/Avr8GenericCommandFrame.hpp | 3 +- .../ClearAllSoftwareBreakpoints.hpp | 15 +-- .../AVR8Generic/ClearSoftwareBreakpoints.hpp | 34 ++--- .../AVR8Generic/DeactivatePhysical.hpp | 15 +-- .../AVR/CommandFrames/AVR8Generic/Detach.hpp | 17 +-- .../AVR8Generic/DisableDebugWire.hpp | 15 +-- .../CommandFrames/AVR8Generic/GetDeviceId.hpp | 15 +-- .../AVR8Generic/GetParameter.hpp | 41 ++---- .../AVR8Generic/GetProgramCounter.hpp | 15 +-- .../CommandFrames/AVR8Generic/ReadMemory.cpp | 47 +++---- .../CommandFrames/AVR8Generic/ReadMemory.hpp | 33 ++--- .../AVR/CommandFrames/AVR8Generic/Reset.hpp | 25 ++-- .../AVR/CommandFrames/AVR8Generic/Run.hpp | 15 +-- .../AVR/CommandFrames/AVR8Generic/RunTo.hpp | 33 ++--- .../AVR8Generic/SetParameter.hpp | 50 ++------ .../AVR8Generic/SetProgramCounter.hpp | 28 ++--- .../AVR8Generic/SetSoftwareBreakpoints.hpp | 34 ++--- .../SetXmegaSoftwareBreakpoint.hpp | 50 +++----- .../AVR/CommandFrames/AVR8Generic/Step.hpp | 19 ++- .../AVR/CommandFrames/AVR8Generic/Stop.hpp | 25 ++-- .../CommandFrames/AVR8Generic/WriteMemory.hpp | 55 +++----- .../AVR/CommandFrames/AvrCommandFrame.cpp | 64 ---------- .../AVR/CommandFrames/AvrCommandFrame.hpp | 119 +++++++++++++++--- .../Discovery/DiscoveryCommandFrame.hpp | 3 +- .../AVR/CommandFrames/Discovery/Query.hpp | 26 ++-- .../CommandFrames/HouseKeeping/EndSession.hpp | 19 ++- .../HouseKeeping/GetParameter.hpp | 37 ++---- .../HouseKeeping/HouseKeepingCommandFrame.hpp | 3 +- .../HouseKeeping/StartSession.hpp | 19 ++- .../EDBG/AVR/EdbgAvr8Interface.cpp | 20 +-- .../VendorSpecific/EDBG/EdbgInterface.cpp | 14 +-- .../VendorSpecific/EDBG/EdbgInterface.hpp | 25 ++-- 36 files changed, 379 insertions(+), 628 deletions(-) delete mode 100644 src/DebugToolDrivers/Protocols/CMSIS-DAP/VendorSpecific/EDBG/AVR/CommandFrames/AvrCommandFrame.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 16475164..2138566b 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -97,7 +97,6 @@ add_executable(Bloom src/DebugToolDrivers/Protocols/CMSIS-DAP/Command.cpp src/DebugToolDrivers/Protocols/CMSIS-DAP/Response.cpp src/DebugToolDrivers/Protocols/CMSIS-DAP/VendorSpecific/EDBG/AVR/AvrCommand.cpp - src/DebugToolDrivers/Protocols/CMSIS-DAP/VendorSpecific/EDBG/AVR/CommandFrames/AvrCommandFrame.cpp src/DebugToolDrivers/Protocols/CMSIS-DAP/VendorSpecific/EDBG/AVR/CommandFrames/AVR8Generic/ReadMemory.cpp src/DebugToolDrivers/Protocols/CMSIS-DAP/VendorSpecific/EDBG/AVR/AvrResponse.cpp src/DebugToolDrivers/Protocols/CMSIS-DAP/VendorSpecific/EDBG/AVR/ResponseFrames/AvrResponseFrame.cpp diff --git a/src/DebugToolDrivers/Protocols/CMSIS-DAP/VendorSpecific/EDBG/AVR/AvrCommand.hpp b/src/DebugToolDrivers/Protocols/CMSIS-DAP/VendorSpecific/EDBG/AVR/AvrCommand.hpp index 3deae24f..1d818477 100644 --- a/src/DebugToolDrivers/Protocols/CMSIS-DAP/VendorSpecific/EDBG/AVR/AvrCommand.hpp +++ b/src/DebugToolDrivers/Protocols/CMSIS-DAP/VendorSpecific/EDBG/AVR/AvrCommand.hpp @@ -10,7 +10,15 @@ namespace Bloom::DebugToolDrivers::Protocols::CmsisDap::Edbg::Avr class AvrCommand: public Command { public: - AvrCommand() { + AvrCommand( + std::size_t fragmentCount, + std::size_t fragmentNumber, + std::vector commandPacket + ) + : fragmentCount(fragmentCount) + , fragmentNumber(fragmentNumber) + , commandPacket(std::move(commandPacket)) + { this->setCommandId(0x80); } @@ -25,26 +33,14 @@ namespace Bloom::DebugToolDrivers::Protocols::CmsisDap::Edbg::Avr return this->fragmentNumber; } - void setFragmentNumber(std::size_t fragmentNumber) { - this->fragmentNumber = fragmentNumber; - } - [[nodiscard]] std::size_t getFragmentCount() const { return this->fragmentCount; } - void setFragmentCount(std::size_t fragmentCount) { - this->fragmentCount = fragmentCount; - } - [[nodiscard]] const std::vector& getCommandPacket() const { return this->commandPacket; } - void setCommandPacket(const std::vector& commandPacket) { - this->commandPacket = commandPacket; - } - private: std::size_t fragmentNumber = 1; std::size_t fragmentCount = 1; diff --git a/src/DebugToolDrivers/Protocols/CMSIS-DAP/VendorSpecific/EDBG/AVR/CommandFrames/AVR8Generic/ActivatePhysical.hpp b/src/DebugToolDrivers/Protocols/CMSIS-DAP/VendorSpecific/EDBG/AVR/CommandFrames/AVR8Generic/ActivatePhysical.hpp index 6b627edc..26085bfc 100644 --- a/src/DebugToolDrivers/Protocols/CMSIS-DAP/VendorSpecific/EDBG/AVR/CommandFrames/AVR8Generic/ActivatePhysical.hpp +++ b/src/DebugToolDrivers/Protocols/CMSIS-DAP/VendorSpecific/EDBG/AVR/CommandFrames/AVR8Generic/ActivatePhysical.hpp @@ -4,33 +4,22 @@ namespace Bloom::DebugToolDrivers::Protocols::CmsisDap::Edbg::Avr::CommandFrames::Avr8Generic { - class ActivatePhysical: public Avr8GenericCommandFrame + class ActivatePhysical: public Avr8GenericCommandFrame> { public: - ActivatePhysical() = default; - explicit ActivatePhysical(bool reset): reset(reset) {}; - - void setReset(bool reset) { - this->reset = reset; - } - - [[nodiscard]] std::vector getPayload() const override { + explicit ActivatePhysical(bool reset) { /* * The activate physical command consists of 3 bytes: * 1. Command ID (0x10) * 2. Version (0x00) * 3. Reset flag (to apply external reset) */ - auto output = std::vector(3, 0x00); - output[0] = 0x10; - output[1] = 0x00; - output[2] = static_cast(this->reset); - - return output; + this->payload = { + 0x10, + 0x00, + static_cast(reset) + }; } - - private: - bool reset = false; }; } diff --git a/src/DebugToolDrivers/Protocols/CMSIS-DAP/VendorSpecific/EDBG/AVR/CommandFrames/AVR8Generic/Attach.hpp b/src/DebugToolDrivers/Protocols/CMSIS-DAP/VendorSpecific/EDBG/AVR/CommandFrames/AVR8Generic/Attach.hpp index dfa355f0..b3fb0c11 100644 --- a/src/DebugToolDrivers/Protocols/CMSIS-DAP/VendorSpecific/EDBG/AVR/CommandFrames/AVR8Generic/Attach.hpp +++ b/src/DebugToolDrivers/Protocols/CMSIS-DAP/VendorSpecific/EDBG/AVR/CommandFrames/AVR8Generic/Attach.hpp @@ -4,33 +4,21 @@ namespace Bloom::DebugToolDrivers::Protocols::CmsisDap::Edbg::Avr::CommandFrames::Avr8Generic { - class Attach: public Avr8GenericCommandFrame + class Attach: public Avr8GenericCommandFrame> { public: - Attach() = default; - explicit Attach(bool breakAfterAttach): breakAfterAttach(breakAfterAttach) {}; - - void setBreadAfterAttach(bool breakAfterAttach) { - this->breakAfterAttach = breakAfterAttach; - } - - [[nodiscard]] std::vector getPayload() const override { + explicit Attach(bool breakAfterAttach) { /* * The attach command consists of 3 bytes: * 1. Command ID (0x13) * 2. Version (0x00) * 3. Break (stop) after attach flag */ - auto output = std::vector(3, 0x00); - output[0] = 0x13; - output[1] = 0x00; - output[2] = static_cast(this->breakAfterAttach); - - return output; + this->payload = { + 0x13, + 0x00, + static_cast(breakAfterAttach) + }; } - - private: - bool breakAfterAttach = false; }; - } diff --git a/src/DebugToolDrivers/Protocols/CMSIS-DAP/VendorSpecific/EDBG/AVR/CommandFrames/AVR8Generic/Avr8GenericCommandFrame.hpp b/src/DebugToolDrivers/Protocols/CMSIS-DAP/VendorSpecific/EDBG/AVR/CommandFrames/AVR8Generic/Avr8GenericCommandFrame.hpp index 58a0cf1c..84f5dbb9 100644 --- a/src/DebugToolDrivers/Protocols/CMSIS-DAP/VendorSpecific/EDBG/AVR/CommandFrames/AVR8Generic/Avr8GenericCommandFrame.hpp +++ b/src/DebugToolDrivers/Protocols/CMSIS-DAP/VendorSpecific/EDBG/AVR/CommandFrames/AVR8Generic/Avr8GenericCommandFrame.hpp @@ -7,7 +7,8 @@ namespace Bloom::DebugToolDrivers::Protocols::CmsisDap::Edbg::Avr::CommandFrames::Avr8Generic { - class Avr8GenericCommandFrame: public AvrCommandFrame + template + class Avr8GenericCommandFrame: public AvrCommandFrame { public: using ResponseFrameType = ResponseFrames::Avr8Generic::Avr8GenericResponseFrame; diff --git a/src/DebugToolDrivers/Protocols/CMSIS-DAP/VendorSpecific/EDBG/AVR/CommandFrames/AVR8Generic/ClearAllSoftwareBreakpoints.hpp b/src/DebugToolDrivers/Protocols/CMSIS-DAP/VendorSpecific/EDBG/AVR/CommandFrames/AVR8Generic/ClearAllSoftwareBreakpoints.hpp index fba99ead..b2b0c064 100644 --- a/src/DebugToolDrivers/Protocols/CMSIS-DAP/VendorSpecific/EDBG/AVR/CommandFrames/AVR8Generic/ClearAllSoftwareBreakpoints.hpp +++ b/src/DebugToolDrivers/Protocols/CMSIS-DAP/VendorSpecific/EDBG/AVR/CommandFrames/AVR8Generic/ClearAllSoftwareBreakpoints.hpp @@ -4,24 +4,19 @@ namespace Bloom::DebugToolDrivers::Protocols::CmsisDap::Edbg::Avr::CommandFrames::Avr8Generic { - class ClearAllSoftwareBreakpoints: public Avr8GenericCommandFrame + class ClearAllSoftwareBreakpoints: public Avr8GenericCommandFrame> { public: ClearAllSoftwareBreakpoints() { - init(); - }; - - private: - void init() { /* * The clear all software breakpoints command consists of 2 bytes: * 1. Command ID (0x45) * 2. Version (0x00) */ - auto payload = std::vector(2); - payload[0] = 0x45; - payload[1] = 0x00; - this->setPayload(payload); + this->payload = { + 0x45, + 0x00, + }; } }; } diff --git a/src/DebugToolDrivers/Protocols/CMSIS-DAP/VendorSpecific/EDBG/AVR/CommandFrames/AVR8Generic/ClearSoftwareBreakpoints.hpp b/src/DebugToolDrivers/Protocols/CMSIS-DAP/VendorSpecific/EDBG/AVR/CommandFrames/AVR8Generic/ClearSoftwareBreakpoints.hpp index cb8566af..25efbdcc 100644 --- a/src/DebugToolDrivers/Protocols/CMSIS-DAP/VendorSpecific/EDBG/AVR/CommandFrames/AVR8Generic/ClearSoftwareBreakpoints.hpp +++ b/src/DebugToolDrivers/Protocols/CMSIS-DAP/VendorSpecific/EDBG/AVR/CommandFrames/AVR8Generic/ClearSoftwareBreakpoints.hpp @@ -7,18 +7,10 @@ namespace Bloom::DebugToolDrivers::Protocols::CmsisDap::Edbg::Avr::CommandFrames::Avr8Generic { - class ClearSoftwareBreakpoints: public Avr8GenericCommandFrame + class ClearSoftwareBreakpoints: public Avr8GenericCommandFrame> { public: - ClearSoftwareBreakpoints() = default; - - explicit ClearSoftwareBreakpoints(std::vector addresses): addresses(std::move(addresses)) {} - - void setAddresses(const std::vector& addresses) { - this->addresses = addresses; - } - - [[nodiscard]] std::vector getPayload() const override { + explicit ClearSoftwareBreakpoints(const std::vector& addresses) { /* * The clear software breakpoints command consists of 2 bytes + 4*n bytes, where n is the number * of breakpoints to clear: @@ -27,21 +19,17 @@ namespace Bloom::DebugToolDrivers::Protocols::CmsisDap::Edbg::Avr::CommandFrames * 2. Version (0x00) * ... addresses */ - auto output = std::vector(2, 0x00); - output[0] = 0x44; - output[1] = 0x00; + this->payload = { + 0x44, + 0x00, + }; - for (const auto& address : this->addresses) { - output.push_back(static_cast(address)); - output.push_back(static_cast(address >> 8)); - output.push_back(static_cast(address >> 16)); - output.push_back(static_cast(address >> 24)); + for (const auto& address : addresses) { + this->payload.emplace_back(static_cast(address)); + this->payload.emplace_back(static_cast(address >> 8)); + this->payload.emplace_back(static_cast(address >> 16)); + this->payload.emplace_back(static_cast(address >> 24)); } - - return output; } - - private: - std::vector addresses; }; } diff --git a/src/DebugToolDrivers/Protocols/CMSIS-DAP/VendorSpecific/EDBG/AVR/CommandFrames/AVR8Generic/DeactivatePhysical.hpp b/src/DebugToolDrivers/Protocols/CMSIS-DAP/VendorSpecific/EDBG/AVR/CommandFrames/AVR8Generic/DeactivatePhysical.hpp index 78bb5c3a..eef68539 100644 --- a/src/DebugToolDrivers/Protocols/CMSIS-DAP/VendorSpecific/EDBG/AVR/CommandFrames/AVR8Generic/DeactivatePhysical.hpp +++ b/src/DebugToolDrivers/Protocols/CMSIS-DAP/VendorSpecific/EDBG/AVR/CommandFrames/AVR8Generic/DeactivatePhysical.hpp @@ -4,24 +4,19 @@ namespace Bloom::DebugToolDrivers::Protocols::CmsisDap::Edbg::Avr::CommandFrames::Avr8Generic { - class DeactivatePhysical: public Avr8GenericCommandFrame + class DeactivatePhysical: public Avr8GenericCommandFrame> { public: DeactivatePhysical() { - init(); - }; - - private: - void init() { /* * The deactivate physical command consists of 2 bytes: * 1. Command ID (0x11) * 2. Version (0x00) */ - auto payload = std::vector(2); - payload[0] = 0x11; - payload[1] = 0x00; - this->setPayload(payload); + this->payload = { + 0x11, + 0x00 + }; } }; } diff --git a/src/DebugToolDrivers/Protocols/CMSIS-DAP/VendorSpecific/EDBG/AVR/CommandFrames/AVR8Generic/Detach.hpp b/src/DebugToolDrivers/Protocols/CMSIS-DAP/VendorSpecific/EDBG/AVR/CommandFrames/AVR8Generic/Detach.hpp index 9a639f38..2fddd7fc 100644 --- a/src/DebugToolDrivers/Protocols/CMSIS-DAP/VendorSpecific/EDBG/AVR/CommandFrames/AVR8Generic/Detach.hpp +++ b/src/DebugToolDrivers/Protocols/CMSIS-DAP/VendorSpecific/EDBG/AVR/CommandFrames/AVR8Generic/Detach.hpp @@ -4,24 +4,19 @@ namespace Bloom::DebugToolDrivers::Protocols::CmsisDap::Edbg::Avr::CommandFrames::Avr8Generic { - class Detach: public Avr8GenericCommandFrame + class Detach: public Avr8GenericCommandFrame> { public: Detach() { - init(); - }; - - private: - void init() { /* * The detach command consists of 2 bytes: - * 1. Command ID (0x11) + * 1. Command ID (0x14) * 2. Version (0x00) */ - auto payload = std::vector(2); - payload[0] = 0x11; - payload[1] = 0x00; - this->setPayload(payload); + this->payload = { + 0x14, + 0x00 + }; } }; } diff --git a/src/DebugToolDrivers/Protocols/CMSIS-DAP/VendorSpecific/EDBG/AVR/CommandFrames/AVR8Generic/DisableDebugWire.hpp b/src/DebugToolDrivers/Protocols/CMSIS-DAP/VendorSpecific/EDBG/AVR/CommandFrames/AVR8Generic/DisableDebugWire.hpp index 25f7d944..a728c8cb 100644 --- a/src/DebugToolDrivers/Protocols/CMSIS-DAP/VendorSpecific/EDBG/AVR/CommandFrames/AVR8Generic/DisableDebugWire.hpp +++ b/src/DebugToolDrivers/Protocols/CMSIS-DAP/VendorSpecific/EDBG/AVR/CommandFrames/AVR8Generic/DisableDebugWire.hpp @@ -4,24 +4,19 @@ namespace Bloom::DebugToolDrivers::Protocols::CmsisDap::Edbg::Avr::CommandFrames::Avr8Generic { - class DisableDebugWire: public Avr8GenericCommandFrame + class DisableDebugWire: public Avr8GenericCommandFrame> { public: DisableDebugWire() { - init(); - }; - - private: - void init() { /* * The disable debugWire command consists of 2 bytes: * 1. Command ID (0x17) * 2. Version (0x00) */ - auto payload = std::vector(2); - payload[0] = 0x17; - payload[1] = 0x00; - this->setPayload(payload); + this->payload = { + 0x17, + 0x00 + }; } }; } diff --git a/src/DebugToolDrivers/Protocols/CMSIS-DAP/VendorSpecific/EDBG/AVR/CommandFrames/AVR8Generic/GetDeviceId.hpp b/src/DebugToolDrivers/Protocols/CMSIS-DAP/VendorSpecific/EDBG/AVR/CommandFrames/AVR8Generic/GetDeviceId.hpp index 9924351b..b426ee3e 100644 --- a/src/DebugToolDrivers/Protocols/CMSIS-DAP/VendorSpecific/EDBG/AVR/CommandFrames/AVR8Generic/GetDeviceId.hpp +++ b/src/DebugToolDrivers/Protocols/CMSIS-DAP/VendorSpecific/EDBG/AVR/CommandFrames/AVR8Generic/GetDeviceId.hpp @@ -5,26 +5,21 @@ namespace Bloom::DebugToolDrivers::Protocols::CmsisDap::Edbg::Avr::CommandFrames::Avr8Generic { - class GetDeviceId: public Avr8GenericCommandFrame + class GetDeviceId: public Avr8GenericCommandFrame> { public: using ResponseFrameType = ResponseFrames::Avr8Generic::GetDeviceId; GetDeviceId() { - init(); - }; - - private: - void init() { /* * The get device ID command consists of 2 bytes: * 1. Command ID (0x12) * 2. Version (0x00) */ - auto payload = std::vector(2); - payload[0] = 0x12; - payload[1] = 0x00; - this->setPayload(payload); + this->payload = { + 0x12, + 0x00 + }; } }; } diff --git a/src/DebugToolDrivers/Protocols/CMSIS-DAP/VendorSpecific/EDBG/AVR/CommandFrames/AVR8Generic/GetParameter.hpp b/src/DebugToolDrivers/Protocols/CMSIS-DAP/VendorSpecific/EDBG/AVR/CommandFrames/AVR8Generic/GetParameter.hpp index 93efa935..47b7653b 100644 --- a/src/DebugToolDrivers/Protocols/CMSIS-DAP/VendorSpecific/EDBG/AVR/CommandFrames/AVR8Generic/GetParameter.hpp +++ b/src/DebugToolDrivers/Protocols/CMSIS-DAP/VendorSpecific/EDBG/AVR/CommandFrames/AVR8Generic/GetParameter.hpp @@ -6,28 +6,10 @@ namespace Bloom::DebugToolDrivers::Protocols::CmsisDap::Edbg::Avr::CommandFrames::Avr8Generic { - class GetParameter: public Avr8GenericCommandFrame + class GetParameter: public Avr8GenericCommandFrame> { public: - GetParameter() = default; - - explicit GetParameter(const Avr8EdbgParameter& parameter) { - this->setParameter(parameter); - } - - GetParameter(const Avr8EdbgParameter& parameter, std::uint8_t size): GetParameter(parameter) { - this->setSize(size); - } - - void setParameter(const Avr8EdbgParameter& parameter) { - this->parameter = parameter; - } - - void setSize(std::uint8_t size) { - this->size = size; - } - - [[nodiscard]] std::vector getPayload() const override { + GetParameter(const Avr8EdbgParameter& parameter, std::uint8_t size) { /* * The get param command consists of 5 bytes: * 1. Command ID (0x02) @@ -36,18 +18,13 @@ namespace Bloom::DebugToolDrivers::Protocols::CmsisDap::Edbg::Avr::CommandFrames * 4. Param ID (Avr8Parameter::id) * 5. Param value length (this->size) */ - auto output = std::vector(5, 0x00); - output[0] = 0x02; - output[1] = 0x00; - output[2] = static_cast(this->parameter.context); - output[3] = static_cast(this->parameter.id); - output[4] = static_cast(this->size); - - return output; + this->payload = { + 0x02, + 0x00, + static_cast(parameter.context), + static_cast(parameter.id), + static_cast(size) + }; } - - private: - Avr8EdbgParameter parameter; - std::uint8_t size = 0; }; } diff --git a/src/DebugToolDrivers/Protocols/CMSIS-DAP/VendorSpecific/EDBG/AVR/CommandFrames/AVR8Generic/GetProgramCounter.hpp b/src/DebugToolDrivers/Protocols/CMSIS-DAP/VendorSpecific/EDBG/AVR/CommandFrames/AVR8Generic/GetProgramCounter.hpp index a0ea98fa..b4f9574f 100644 --- a/src/DebugToolDrivers/Protocols/CMSIS-DAP/VendorSpecific/EDBG/AVR/CommandFrames/AVR8Generic/GetProgramCounter.hpp +++ b/src/DebugToolDrivers/Protocols/CMSIS-DAP/VendorSpecific/EDBG/AVR/CommandFrames/AVR8Generic/GetProgramCounter.hpp @@ -5,26 +5,21 @@ namespace Bloom::DebugToolDrivers::Protocols::CmsisDap::Edbg::Avr::CommandFrames::Avr8Generic { - class GetProgramCounter: public Avr8GenericCommandFrame + class GetProgramCounter: public Avr8GenericCommandFrame> { public: using ResponseFrameType = ResponseFrames::Avr8Generic::GetProgramCounter; GetProgramCounter() { - init(); - }; - - private: - void init() { /* * The PC Read command consists of 2 bytes: * 1. Command ID (0x35) * 2. Version (0x00) */ - auto payload = std::vector(2); - payload[0] = 0x35; - payload[1] = 0x00; - this->setPayload(payload); + this->payload = { + 0x35, + 0x00, + }; } }; } diff --git a/src/DebugToolDrivers/Protocols/CMSIS-DAP/VendorSpecific/EDBG/AVR/CommandFrames/AVR8Generic/ReadMemory.cpp b/src/DebugToolDrivers/Protocols/CMSIS-DAP/VendorSpecific/EDBG/AVR/CommandFrames/AVR8Generic/ReadMemory.cpp index 26f3546b..f86540fd 100644 --- a/src/DebugToolDrivers/Protocols/CMSIS-DAP/VendorSpecific/EDBG/AVR/CommandFrames/AVR8Generic/ReadMemory.cpp +++ b/src/DebugToolDrivers/Protocols/CMSIS-DAP/VendorSpecific/EDBG/AVR/CommandFrames/AVR8Generic/ReadMemory.cpp @@ -5,7 +5,12 @@ namespace Bloom::DebugToolDrivers::Protocols::CmsisDap::Edbg::Avr::CommandFrames::Avr8Generic { - std::vector ReadMemory::getPayload() const { + ReadMemory::ReadMemory( + const Avr8MemoryType& type, + std::uint32_t address, + std::uint32_t bytes, + const std::set& excludedAddresses + ) { /* * The read memory command consists of 11/11 + (this->bytes / 8) bytes: * 1. Command ID (0x21 for the general read memory command, 0x22 for reading with a mask) @@ -15,43 +20,41 @@ namespace Bloom::DebugToolDrivers::Protocols::CmsisDap::Edbg::Avr::CommandFrames * 5. Number of bytes to read (4 bytes) * 6. Mask to apply (this->bytes / 8) - only required if we're using the masked read command (command ID 0x22). */ - auto output = std::vector(11, 0x00); - output[0] = this->excludedAddresses.empty() ? 0x21 : 0x22; - output[1] = 0x00; - output[2] = static_cast(this->type); - output[3] = static_cast(this->address); - output[4] = static_cast(this->address >> 8); - output[5] = static_cast(this->address >> 16); - output[6] = static_cast(this->address >> 24); - output[7] = static_cast(this->bytes); - output[8] = static_cast(this->bytes >> 8); - output[9] = static_cast(this->bytes >> 16); - output[10] = static_cast(this->bytes >> 24); + this->payload = std::vector(11, 0x00); + this->payload[0] = excludedAddresses.empty() ? 0x21 : 0x22; + this->payload[1] = 0x00; + this->payload[2] = static_cast(type); + this->payload[3] = static_cast(address); + this->payload[4] = static_cast(address >> 8); + this->payload[5] = static_cast(address >> 16); + this->payload[6] = static_cast(address >> 24); + this->payload[7] = static_cast(bytes); + this->payload[8] = static_cast(bytes >> 8); + this->payload[9] = static_cast(bytes >> 16); + this->payload[10] = static_cast(bytes >> 24); - if (!this->excludedAddresses.empty()) { - const auto endAddress = this->address + (this->bytes - 1); + if (!excludedAddresses.empty()) { + const auto endAddress = address + (bytes - 1); constexpr auto byteBitSize = std::numeric_limits::digits; auto byteBitset = std::bitset(); byteBitset.reset(); - for (std::uint32_t address = this->address; address <= endAddress; address++) { - auto addressIndex = address - this->address; + for (std::uint32_t address = address; address <= endAddress; address++) { + auto addressIndex = address - address; auto bitIndex = static_cast( addressIndex - (std::floor(addressIndex / byteBitSize) * byteBitSize) ); - if (!this->excludedAddresses.contains(address)) { - byteBitset[bitIndex] = 1; + if (!excludedAddresses.contains(address)) { + byteBitset[bitIndex] = true; } if (address > 0 && (bitIndex == 7 || address == endAddress)) { - output.emplace_back(byteBitset.to_ulong()); + this->payload.emplace_back(byteBitset.to_ulong()); byteBitset.reset(); } } } - - return output; } } diff --git a/src/DebugToolDrivers/Protocols/CMSIS-DAP/VendorSpecific/EDBG/AVR/CommandFrames/AVR8Generic/ReadMemory.hpp b/src/DebugToolDrivers/Protocols/CMSIS-DAP/VendorSpecific/EDBG/AVR/CommandFrames/AVR8Generic/ReadMemory.hpp index 65f8060f..2217a8a9 100644 --- a/src/DebugToolDrivers/Protocols/CMSIS-DAP/VendorSpecific/EDBG/AVR/CommandFrames/AVR8Generic/ReadMemory.hpp +++ b/src/DebugToolDrivers/Protocols/CMSIS-DAP/VendorSpecific/EDBG/AVR/CommandFrames/AVR8Generic/ReadMemory.hpp @@ -8,35 +8,16 @@ namespace Bloom::DebugToolDrivers::Protocols::CmsisDap::Edbg::Avr::CommandFrames::Avr8Generic { - class ReadMemory: public Avr8GenericCommandFrame + class ReadMemory: public Avr8GenericCommandFrame> { public: using ResponseFrameType = ResponseFrames::Avr8Generic::ReadMemory; - ReadMemory() = default; - - void setType(const Avr8MemoryType& type) { - this->type = type; - } - - void setAddress(std::uint32_t address) { - this->address = address; - } - - void setBytes(std::uint32_t bytes) { - this->bytes = bytes; - } - - void setExcludedAddresses(const std::set& excludedAddresses) { - this->excludedAddresses = excludedAddresses; - } - - [[nodiscard]] std::vector getPayload() const override; - - private: - Avr8MemoryType type = Avr8MemoryType::SRAM; - std::uint32_t address = 0; - std::uint32_t bytes = 0; - std::set excludedAddresses; + ReadMemory( + const Avr8MemoryType& type, + std::uint32_t address, + std::uint32_t bytes, + const std::set& excludedAddresses = {} + ); }; } diff --git a/src/DebugToolDrivers/Protocols/CMSIS-DAP/VendorSpecific/EDBG/AVR/CommandFrames/AVR8Generic/Reset.hpp b/src/DebugToolDrivers/Protocols/CMSIS-DAP/VendorSpecific/EDBG/AVR/CommandFrames/AVR8Generic/Reset.hpp index e92384c5..da76c153 100644 --- a/src/DebugToolDrivers/Protocols/CMSIS-DAP/VendorSpecific/EDBG/AVR/CommandFrames/AVR8Generic/Reset.hpp +++ b/src/DebugToolDrivers/Protocols/CMSIS-DAP/VendorSpecific/EDBG/AVR/CommandFrames/AVR8Generic/Reset.hpp @@ -4,32 +4,21 @@ namespace Bloom::DebugToolDrivers::Protocols::CmsisDap::Edbg::Avr::CommandFrames::Avr8Generic { - class Reset: public Avr8GenericCommandFrame + class Reset: public Avr8GenericCommandFrame> { public: - Reset() = default; - explicit Reset(bool stopAtMainAddress): stopAtMainAddress(stopAtMainAddress) {}; - - void setStopAtMainAddress(bool stopAtMainAddress) { - this->stopAtMainAddress = stopAtMainAddress; - } - - [[nodiscard]] std::vector getPayload() const override { + explicit Reset(bool stopAtMainAddress = false) { /* * The reset command consists of 3 bytes: * 1. Command ID (0x30) * 2. Version (0x00) * 3. "Level" (0x01 to stop at boot reset vector or 0x02 to stop at main address) */ - auto output = std::vector(3, 0x00); - output[0] = 0x30; - output[1] = 0x00; - output[2] = this->stopAtMainAddress ? 0x02 : 0x01; - - return output; + this->payload = { + 0x30, + 0x00, + static_cast(stopAtMainAddress ? 0x02 : 0x01), + }; } - - private: - bool stopAtMainAddress = false; }; } diff --git a/src/DebugToolDrivers/Protocols/CMSIS-DAP/VendorSpecific/EDBG/AVR/CommandFrames/AVR8Generic/Run.hpp b/src/DebugToolDrivers/Protocols/CMSIS-DAP/VendorSpecific/EDBG/AVR/CommandFrames/AVR8Generic/Run.hpp index 842cbd43..b07f121e 100644 --- a/src/DebugToolDrivers/Protocols/CMSIS-DAP/VendorSpecific/EDBG/AVR/CommandFrames/AVR8Generic/Run.hpp +++ b/src/DebugToolDrivers/Protocols/CMSIS-DAP/VendorSpecific/EDBG/AVR/CommandFrames/AVR8Generic/Run.hpp @@ -4,24 +4,19 @@ namespace Bloom::DebugToolDrivers::Protocols::CmsisDap::Edbg::Avr::CommandFrames::Avr8Generic { - class Run: public Avr8GenericCommandFrame + class Run: public Avr8GenericCommandFrame> { public: Run() { - init(); - }; - - private: - void init() { /* * The run command consists of 2 bytes: * 1. Command ID (0x32) * 2. Version (0x00) */ - auto payload = std::vector(2); - payload[0] = 0x32; - payload[1] = 0x00; - this->setPayload(payload); + this->payload = { + 0x32, + 0x00, + }; } }; } diff --git a/src/DebugToolDrivers/Protocols/CMSIS-DAP/VendorSpecific/EDBG/AVR/CommandFrames/AVR8Generic/RunTo.hpp b/src/DebugToolDrivers/Protocols/CMSIS-DAP/VendorSpecific/EDBG/AVR/CommandFrames/AVR8Generic/RunTo.hpp index 5c22f15d..0a1a4abb 100644 --- a/src/DebugToolDrivers/Protocols/CMSIS-DAP/VendorSpecific/EDBG/AVR/CommandFrames/AVR8Generic/RunTo.hpp +++ b/src/DebugToolDrivers/Protocols/CMSIS-DAP/VendorSpecific/EDBG/AVR/CommandFrames/AVR8Generic/RunTo.hpp @@ -6,18 +6,10 @@ namespace Bloom::DebugToolDrivers::Protocols::CmsisDap::Edbg::Avr::CommandFrames::Avr8Generic { - class RunTo: public Avr8GenericCommandFrame + class RunTo: public Avr8GenericCommandFrame> { public: - RunTo() = default; - - explicit RunTo(const std::uint32_t& address): address(address) {} - - void setAddress(const std::uint32_t& address) { - this->address = address; - } - - [[nodiscard]] std::vector getPayload() const override { + explicit RunTo(const std::uint32_t& address) { /* * The run-to command consists of 6 bytes: * @@ -25,21 +17,18 @@ namespace Bloom::DebugToolDrivers::Protocols::CmsisDap::Edbg::Avr::CommandFrames * 2. Version (0x00) * 3. Address to run to (4 bytes) */ - auto output = std::vector(6, 0x00); - output[0] = 0x33; - output[1] = 0x00; // The address to run to needs to be the 16-bit word address, not the byte address. - auto wordAddress = this->address / 2; - output[2] = (static_cast(wordAddress)); - output[3] = (static_cast(wordAddress >> 8)); - output[4] = (static_cast(wordAddress >> 16)); - output[5] = (static_cast(wordAddress >> 24)); + const auto wordAddress = address / 2; - return output; + this->payload = { + 0x33, + 0x00, + static_cast(wordAddress), + static_cast(wordAddress >> 8), + static_cast(wordAddress >> 16), + static_cast(wordAddress >> 24), + }; } - - private: - std::uint32_t address = 0; }; } diff --git a/src/DebugToolDrivers/Protocols/CMSIS-DAP/VendorSpecific/EDBG/AVR/CommandFrames/AVR8Generic/SetParameter.hpp b/src/DebugToolDrivers/Protocols/CMSIS-DAP/VendorSpecific/EDBG/AVR/CommandFrames/AVR8Generic/SetParameter.hpp index 75b9383e..34cbcdb8 100644 --- a/src/DebugToolDrivers/Protocols/CMSIS-DAP/VendorSpecific/EDBG/AVR/CommandFrames/AVR8Generic/SetParameter.hpp +++ b/src/DebugToolDrivers/Protocols/CMSIS-DAP/VendorSpecific/EDBG/AVR/CommandFrames/AVR8Generic/SetParameter.hpp @@ -4,36 +4,10 @@ namespace Bloom::DebugToolDrivers::Protocols::CmsisDap::Edbg::Avr::CommandFrames::Avr8Generic { - class SetParameter: public Avr8GenericCommandFrame + class SetParameter: public Avr8GenericCommandFrame> { public: - SetParameter() = default; - - explicit SetParameter(const Avr8EdbgParameter& parameter) { - this->setParameter(parameter); - } - - SetParameter(const Avr8EdbgParameter& parameter, const std::vector& value): SetParameter(parameter) { - this->setValue(value); - } - - SetParameter(const Avr8EdbgParameter& parameter, unsigned char value): SetParameter(parameter) { - this->setValue(value); - } - - void setParameter(const Avr8EdbgParameter& parameter) { - this->parameter = parameter; - } - - void setValue(const std::vector& value) { - this->value = value; - } - - void setValue(unsigned char value) { - this->value.resize(1, value); - } - - [[nodiscard]] std::vector getPayload() const override { + SetParameter(const Avr8EdbgParameter& parameter, const std::vector& value) { /* * The set param command consists of this->value.size() + 5 bytes. The first five bytes consist of: * 1. Command ID (0x01) @@ -43,19 +17,13 @@ namespace Bloom::DebugToolDrivers::Protocols::CmsisDap::Edbg::Avr::CommandFrames * 5. Param value length (this->value.size()) - this is only one byte in size, so its value should * never exceed 255. */ - auto output = std::vector(this->value.size() + 5, 0x00); - output[0] = 0x01; - output[1] = 0x00; - output[2] = static_cast(this->parameter.context); - output[3] = static_cast(this->parameter.id); - output[4] = static_cast(this->value.size()); - output.insert(output.begin() + 5, this->value.begin(), this->value.end()); - - return output; + this->payload = std::vector(value.size() + 5, 0x00); + this->payload[0] = 0x01; + this->payload[1] = 0x00; + this->payload[2] = static_cast(parameter.context); + this->payload[3] = static_cast(parameter.id); + this->payload[4] = static_cast(value.size()); + this->payload.insert(this->payload.begin() + 5, value.begin(), value.end()); } - - private: - Avr8EdbgParameter parameter; - std::vector value; }; } diff --git a/src/DebugToolDrivers/Protocols/CMSIS-DAP/VendorSpecific/EDBG/AVR/CommandFrames/AVR8Generic/SetProgramCounter.hpp b/src/DebugToolDrivers/Protocols/CMSIS-DAP/VendorSpecific/EDBG/AVR/CommandFrames/AVR8Generic/SetProgramCounter.hpp index c9c3f081..3623e06a 100644 --- a/src/DebugToolDrivers/Protocols/CMSIS-DAP/VendorSpecific/EDBG/AVR/CommandFrames/AVR8Generic/SetProgramCounter.hpp +++ b/src/DebugToolDrivers/Protocols/CMSIS-DAP/VendorSpecific/EDBG/AVR/CommandFrames/AVR8Generic/SetProgramCounter.hpp @@ -6,30 +6,24 @@ namespace Bloom::DebugToolDrivers::Protocols::CmsisDap::Edbg::Avr::CommandFrames::Avr8Generic { - class SetProgramCounter: public Avr8GenericCommandFrame + class SetProgramCounter: public Avr8GenericCommandFrame> { public: - explicit SetProgramCounter(std::uint32_t programCounter): programCounter(programCounter) {} - - [[nodiscard]] std::vector getPayload() const override { + explicit SetProgramCounter(std::uint32_t programCounter) { /* * The PC write command consists of 6 bytes: - * 1. Command ID (0x01) + * 1. Command ID (0x36) * 2. Version (0x00) * 3. PC (4 bytes, LSB) */ - auto output = std::vector(6, 0x00); - output[0] = 0x36; - output[1] = 0x00; - output[2] = static_cast(this->programCounter); - output[3] = static_cast(this->programCounter >> 8); - output[4] = static_cast(this->programCounter >> 16); - output[5] = static_cast(this->programCounter >> 24); - - return output; + this->payload = { + 0x36, + 0x00, + static_cast(programCounter), + static_cast(programCounter >> 8), + static_cast(programCounter >> 16), + static_cast(programCounter >> 24), + }; } - - private: - std::uint32_t programCounter = 0; }; } diff --git a/src/DebugToolDrivers/Protocols/CMSIS-DAP/VendorSpecific/EDBG/AVR/CommandFrames/AVR8Generic/SetSoftwareBreakpoints.hpp b/src/DebugToolDrivers/Protocols/CMSIS-DAP/VendorSpecific/EDBG/AVR/CommandFrames/AVR8Generic/SetSoftwareBreakpoints.hpp index 53138786..1460d7ea 100644 --- a/src/DebugToolDrivers/Protocols/CMSIS-DAP/VendorSpecific/EDBG/AVR/CommandFrames/AVR8Generic/SetSoftwareBreakpoints.hpp +++ b/src/DebugToolDrivers/Protocols/CMSIS-DAP/VendorSpecific/EDBG/AVR/CommandFrames/AVR8Generic/SetSoftwareBreakpoints.hpp @@ -7,18 +7,10 @@ namespace Bloom::DebugToolDrivers::Protocols::CmsisDap::Edbg::Avr::CommandFrames::Avr8Generic { - class SetSoftwareBreakpoints: public Avr8GenericCommandFrame + class SetSoftwareBreakpoints: public Avr8GenericCommandFrame> { public: - SetSoftwareBreakpoints() = default; - - explicit SetSoftwareBreakpoints(std::vector addresses): addresses(std::move(addresses)) {} - - void setAddresses(const std::vector& addresses) { - this->addresses = addresses; - } - - [[nodiscard]] std::vector getPayload() const override { + explicit SetSoftwareBreakpoints(const std::vector& addresses) { /* * The set software breakpoint command consists of 2 bytes + 4*n bytes, where n is the number * of breakpoints to set: @@ -27,21 +19,17 @@ namespace Bloom::DebugToolDrivers::Protocols::CmsisDap::Edbg::Avr::CommandFrames * 2. Version (0x00) * ... addresses */ - auto output = std::vector(2, 0x00); - output[0] = 0x43; - output[1] = 0x00; + this->payload = { + 0x43, + 0x00, + }; - for (const auto& address : this->addresses) { - output.push_back(static_cast(address)); - output.push_back(static_cast(address >> 8)); - output.push_back(static_cast(address >> 16)); - output.push_back(static_cast(address >> 24)); + for (const auto& address : addresses) { + this->payload.emplace_back(static_cast(address)); + this->payload.emplace_back(static_cast(address >> 8)); + this->payload.emplace_back(static_cast(address >> 16)); + this->payload.emplace_back(static_cast(address >> 24)); } - - return output; } - - private: - std::vector addresses; }; } diff --git a/src/DebugToolDrivers/Protocols/CMSIS-DAP/VendorSpecific/EDBG/AVR/CommandFrames/AVR8Generic/SetXmegaSoftwareBreakpoint.hpp b/src/DebugToolDrivers/Protocols/CMSIS-DAP/VendorSpecific/EDBG/AVR/CommandFrames/AVR8Generic/SetXmegaSoftwareBreakpoint.hpp index e09decee..e9e7233b 100644 --- a/src/DebugToolDrivers/Protocols/CMSIS-DAP/VendorSpecific/EDBG/AVR/CommandFrames/AVR8Generic/SetXmegaSoftwareBreakpoint.hpp +++ b/src/DebugToolDrivers/Protocols/CMSIS-DAP/VendorSpecific/EDBG/AVR/CommandFrames/AVR8Generic/SetXmegaSoftwareBreakpoint.hpp @@ -6,39 +6,27 @@ namespace Bloom::DebugToolDrivers::Protocols::CmsisDap::Edbg::Avr::CommandFrames::Avr8Generic { - class SetXmegaSoftwareBreakpoint: public Avr8GenericCommandFrame + class SetXmegaSoftwareBreakpoint: public Avr8GenericCommandFrame> { public: - SetXmegaSoftwareBreakpoint() = default; - - explicit SetXmegaSoftwareBreakpoint(std::uint32_t address): address(address) {} - - void setAddress(std::uint32_t address) { - this->address = address; + explicit SetXmegaSoftwareBreakpoint(std::uint32_t address) { + this->payload = { + 0x42, + 0x00, + static_cast(address), + static_cast(address >> 8), + static_cast(address >> 16), + static_cast(address >> 24), + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x01, + 0x00, + }; } - - [[nodiscard]] std::vector getPayload() const override { - /* - * The set software breakpoint command consists of 6 bytes bytes - * - * 1. Command ID (0x42) - * 2. Version (0x00) - * 3. Address (4 bytes) - */ - auto output = std::vector(15, 0x00); - output[0] = 0x42; - output[1] = 0x00; - output[2] = static_cast(address); - output[3] = static_cast(address >> 8); - output[4] = static_cast(address >> 16); - output[5] = static_cast(address >> 24); - output[13] = 0x01; // One breakpoint - output[14] = 0x00; - - return output; - } - - private: - std::uint32_t address = 0; }; } diff --git a/src/DebugToolDrivers/Protocols/CMSIS-DAP/VendorSpecific/EDBG/AVR/CommandFrames/AVR8Generic/Step.hpp b/src/DebugToolDrivers/Protocols/CMSIS-DAP/VendorSpecific/EDBG/AVR/CommandFrames/AVR8Generic/Step.hpp index cf80c0ca..e0d10d44 100644 --- a/src/DebugToolDrivers/Protocols/CMSIS-DAP/VendorSpecific/EDBG/AVR/CommandFrames/AVR8Generic/Step.hpp +++ b/src/DebugToolDrivers/Protocols/CMSIS-DAP/VendorSpecific/EDBG/AVR/CommandFrames/AVR8Generic/Step.hpp @@ -4,12 +4,10 @@ namespace Bloom::DebugToolDrivers::Protocols::CmsisDap::Edbg::Avr::CommandFrames::Avr8Generic { - class Step: public Avr8GenericCommandFrame + class Step: public Avr8GenericCommandFrame> { public: - Step() = default; - - [[nodiscard]] std::vector getPayload() const override { + Step() { /* * The step command consists of 4 bytes: * 1. Command ID (0x34) @@ -17,13 +15,12 @@ namespace Bloom::DebugToolDrivers::Protocols::CmsisDap::Edbg::Avr::CommandFrames * 3. Level (0x01 for instruction level step, 0x02 for statement level step) * 4. Mode (0x00 for step over, 0x01 for step into, 0x02 for step out) */ - auto output = std::vector(4, 0x00); - output[0] = 0x34; - output[1] = 0x00; - output[2] = 0x01; - output[3] = 0x01; - - return output; + this->payload = { + 0x34, + 0x00, + 0x01, + 0x01, + }; } }; } diff --git a/src/DebugToolDrivers/Protocols/CMSIS-DAP/VendorSpecific/EDBG/AVR/CommandFrames/AVR8Generic/Stop.hpp b/src/DebugToolDrivers/Protocols/CMSIS-DAP/VendorSpecific/EDBG/AVR/CommandFrames/AVR8Generic/Stop.hpp index 199a0c79..fe530f8a 100644 --- a/src/DebugToolDrivers/Protocols/CMSIS-DAP/VendorSpecific/EDBG/AVR/CommandFrames/AVR8Generic/Stop.hpp +++ b/src/DebugToolDrivers/Protocols/CMSIS-DAP/VendorSpecific/EDBG/AVR/CommandFrames/AVR8Generic/Stop.hpp @@ -4,32 +4,21 @@ namespace Bloom::DebugToolDrivers::Protocols::CmsisDap::Edbg::Avr::CommandFrames::Avr8Generic { - class Stop: public Avr8GenericCommandFrame + class Stop: public Avr8GenericCommandFrame> { public: - Stop() = default; - explicit Stop(bool stopImmediately): stopImmediately(stopImmediately) {}; - - void setStopImmediately(bool stopImmediately) { - this->stopImmediately = stopImmediately; - } - - [[nodiscard]] std::vector getPayload() const override { + explicit Stop(bool stopImmediately = true) { /* * The stop command consists of 3 bytes: * 1. Command ID (0x31) * 2. Version (0x00) * 3. Stop immediately (0x01 to stop immediately or 0x02 to stop at the next symbol) */ - auto output = std::vector(3, 0x00); - output[0] = 0x31; - output[1] = 0x00; - output[2] = this->stopImmediately ? 0x01 : 0x02; - - return output; + this->payload = { + 0x31, + 0x00, + static_cast(stopImmediately ? 0x01 : 0x02), + }; } - - private: - bool stopImmediately = true; }; } diff --git a/src/DebugToolDrivers/Protocols/CMSIS-DAP/VendorSpecific/EDBG/AVR/CommandFrames/AVR8Generic/WriteMemory.hpp b/src/DebugToolDrivers/Protocols/CMSIS-DAP/VendorSpecific/EDBG/AVR/CommandFrames/AVR8Generic/WriteMemory.hpp index e5126072..ca174a2c 100644 --- a/src/DebugToolDrivers/Protocols/CMSIS-DAP/VendorSpecific/EDBG/AVR/CommandFrames/AVR8Generic/WriteMemory.hpp +++ b/src/DebugToolDrivers/Protocols/CMSIS-DAP/VendorSpecific/EDBG/AVR/CommandFrames/AVR8Generic/WriteMemory.hpp @@ -7,24 +7,10 @@ namespace Bloom::DebugToolDrivers::Protocols::CmsisDap::Edbg::Avr::CommandFrames::Avr8Generic { - class WriteMemory: public Avr8GenericCommandFrame + class WriteMemory: public Avr8GenericCommandFrame> { public: - WriteMemory() = default; - - void setType(const Avr8MemoryType& type) { - this->type = type; - } - - void setAddress(std::uint32_t address) { - this->address = address; - } - - void setBuffer(const Targets::TargetMemoryBuffer& buffer) { - this->buffer = buffer; - } - - [[nodiscard]] std::vector getPayload() const override { + WriteMemory(const Avr8MemoryType& type, std::uint32_t address, const Targets::TargetMemoryBuffer& buffer) { /* * The write memory command consists of 12 bytes + the buffer size: * 1. Command ID (0x23) @@ -35,32 +21,25 @@ namespace Bloom::DebugToolDrivers::Protocols::CmsisDap::Edbg::Avr::CommandFrames * 6. Asynchronous flag (0x00 for "write first, then reply" and 0x01 for "reply first, then write") * 7. Buffer */ - auto output = std::vector(12, 0x00); - output[0] = 0x23; - output[1] = 0x00; - output[2] = static_cast(this->type); - output[3] = static_cast(this->address); - output[4] = static_cast(this->address >> 8); - output[5] = static_cast(this->address >> 16); - output[6] = static_cast(this->address >> 24); + this->payload = std::vector(12 + buffer.size(), 0x00); + this->payload[0] = 0x23; + this->payload[1] = 0x00; + this->payload[2] = static_cast(type); + this->payload[3] = static_cast(address); + this->payload[4] = static_cast(address >> 8); + this->payload[5] = static_cast(address >> 16); + this->payload[6] = static_cast(address >> 24); - auto bytesToWrite = static_cast(this->buffer.size()); - output[7] = static_cast(bytesToWrite); - output[8] = static_cast(bytesToWrite >> 8); - output[9] = static_cast(bytesToWrite >> 16); - output[10] = static_cast(bytesToWrite >> 24); + auto bytesToWrite = static_cast(buffer.size()); + this->payload[7] = static_cast(bytesToWrite); + this->payload[8] = static_cast(bytesToWrite >> 8); + this->payload[9] = static_cast(bytesToWrite >> 16); + this->payload[10] = static_cast(bytesToWrite >> 24); // We always set the async flag to 0x00 ("write first, then reply") - output[11] = 0x00; + this->payload[11] = 0x00; - output.insert(output.end(), this->buffer.begin(), this->buffer.end()); - - return output; + this->payload.insert(this->payload.begin() + 12, buffer.begin(), buffer.end()); } - - private: - Avr8MemoryType type = Avr8MemoryType::SRAM; - std::uint32_t address = 0; - Targets::TargetMemoryBuffer buffer; }; } diff --git a/src/DebugToolDrivers/Protocols/CMSIS-DAP/VendorSpecific/EDBG/AVR/CommandFrames/AvrCommandFrame.cpp b/src/DebugToolDrivers/Protocols/CMSIS-DAP/VendorSpecific/EDBG/AVR/CommandFrames/AvrCommandFrame.cpp deleted file mode 100644 index c937c934..00000000 --- a/src/DebugToolDrivers/Protocols/CMSIS-DAP/VendorSpecific/EDBG/AVR/CommandFrames/AvrCommandFrame.cpp +++ /dev/null @@ -1,64 +0,0 @@ -#include "AvrCommandFrame.hpp" - -#include - -namespace Bloom::DebugToolDrivers::Protocols::CmsisDap::Edbg::Avr -{ - std::vector AvrCommandFrame::generateAvrCommands(std::size_t maximumCommandPacketSize) const { - auto rawCommandFrame = static_cast>(*this); - std::size_t commandFrameSize = rawCommandFrame.size(); - auto commandsRequired = static_cast( - ceil(static_cast(commandFrameSize) / static_cast(maximumCommandPacketSize)) - ); - - std::vector avrCommands; - std::size_t copiedPacketSize = 0; - for (std::size_t i = 0; i < commandsRequired; i++) { - AvrCommand avrCommand; - avrCommand.setFragmentCount(commandsRequired); - avrCommand.setFragmentNumber(i + 1); - auto commandPacket = avrCommand.getCommandPacket(); - - // If we're on the last packet, the packet size will be what ever is left of the AvrCommandFrame - std::size_t commandPacketSize = ((i + 1) != commandsRequired) ? maximumCommandPacketSize - : (commandFrameSize - (maximumCommandPacketSize * i)); - - commandPacket.insert( - commandPacket.end(), - rawCommandFrame.begin() + static_cast(copiedPacketSize), - rawCommandFrame.begin() + static_cast(copiedPacketSize + commandPacketSize) - ); - - avrCommand.setCommandPacket(commandPacket); - avrCommands.push_back(avrCommand); - copiedPacketSize += commandPacketSize; - } - - return avrCommands; - } - - AvrCommandFrame::operator std::vector() const { - auto data = this->getPayload(); - auto dataSize = data.size(); - - auto rawCommand = std::vector(5); - - rawCommand[0] = this->SOF; - rawCommand[1] = this->getProtocolVersion(); - - rawCommand[2] = static_cast(this->getSequenceId()); - rawCommand[3] = static_cast(this->getSequenceId() >> 8); - - rawCommand[4] = static_cast(this->getProtocolHandlerId()); - - if (dataSize > 0) { - rawCommand.insert( - rawCommand.end(), - data.begin(), - data.end() - ); - } - - return rawCommand; - } -} diff --git a/src/DebugToolDrivers/Protocols/CMSIS-DAP/VendorSpecific/EDBG/AVR/CommandFrames/AvrCommandFrame.hpp b/src/DebugToolDrivers/Protocols/CMSIS-DAP/VendorSpecific/EDBG/AVR/CommandFrames/AvrCommandFrame.hpp index 46dc76cc..07c3668e 100644 --- a/src/DebugToolDrivers/Protocols/CMSIS-DAP/VendorSpecific/EDBG/AVR/CommandFrames/AvrCommandFrame.hpp +++ b/src/DebugToolDrivers/Protocols/CMSIS-DAP/VendorSpecific/EDBG/AVR/CommandFrames/AvrCommandFrame.hpp @@ -4,6 +4,9 @@ #include #include #include +#include +#include +#include #include "src/DebugToolDrivers/Protocols/CMSIS-DAP/Command.hpp" #include "src/DebugToolDrivers/Protocols/CMSIS-DAP/VendorSpecific/EDBG/Edbg.hpp" @@ -12,27 +15,59 @@ namespace Bloom::DebugToolDrivers::Protocols::CmsisDap::Edbg::Avr { + static inline std::atomic LAST_SEQUENCE_ID = 0; + + template > class AvrCommandFrame { + /* + * Every AVR command frame contains a payload. For many commands, the payload size is fixed, meaning we can + * use automatic storage. In other cases, the size of the payload is determined at runtime, requiring the use + * of dynamic storage. + * + * For example, consider the Get Device ID command from the AVR8 Generic Protocol. The size of the payload + * for this command is fixed at 2 bytes. So there is no need to use dynamic storage duration for the payload. + * + * Now consider the Write Memory command from the same protocol. The payload size for that command depends + * on the size of memory we wish to write, which is not known at compile time. For this command, the payload + * would have dynamic storage. + * + * For the above reason, the AvrCommandFrame class is a template class in which the payload container type can + * be specified for individual commands. + * + * For now, we only permit two payload container types: + * - std::array for payloads with automatic storage duration. + * - std::vector for payloads with dynamic storage duration. + */ + static_assert( + ( + std::is_same_v> + || std::is_same_v + ), + "Invalid payload container type - must be an std::array or an std::vector" + ); + + public: using ResponseFrameType = AvrResponseFrame; AvrCommandFrame() { - if (AvrCommandFrame::lastSequenceId < std::numeric_limits::max()) { - this->sequenceId = ++(AvrCommandFrame::lastSequenceId); + if (LAST_SEQUENCE_ID < std::numeric_limits::max()) { + this->sequenceId = ++(LAST_SEQUENCE_ID); } else { this->sequenceId = 0; - AvrCommandFrame::lastSequenceId = 0; + LAST_SEQUENCE_ID = 0; } }; + virtual ~AvrCommandFrame() = default; AvrCommandFrame(const AvrCommandFrame& other) = default; - AvrCommandFrame(AvrCommandFrame&& other) = default; + AvrCommandFrame(AvrCommandFrame&& other) noexcept = default; AvrCommandFrame& operator = (const AvrCommandFrame& other) = default; - AvrCommandFrame& operator = (AvrCommandFrame&& other) = default; + AvrCommandFrame& operator = (AvrCommandFrame&& other) noexcept = default; [[nodiscard]] unsigned char getProtocolVersion() const { return this->protocolVersion; @@ -58,12 +93,38 @@ namespace Bloom::DebugToolDrivers::Protocols::CmsisDap::Edbg::Avr this->protocolHandlerID = static_cast(protocolHandlerId); } - [[nodiscard]] virtual std::vector getPayload() const { + [[nodiscard]] virtual const PayloadContainerType& getPayload() const { return this->payload; - } + }; - void setPayload(const std::vector& payload) { - this->payload = payload; + /** + * Converts the command frame into a container of unsigned char - a raw buffer to send to the EDBG device. + * + * @return + */ + [[nodiscard]] auto getRawCommandFrame() const { + auto data = this->getPayload(); + const auto dataSize = data.size(); + + auto rawCommand = std::vector(5); + + rawCommand[0] = this->SOF; + rawCommand[1] = this->getProtocolVersion(); + + rawCommand[2] = static_cast(this->getSequenceId()); + rawCommand[3] = static_cast(this->getSequenceId() >> 8); + + rawCommand[4] = static_cast(this->getProtocolHandlerId()); + + if (dataSize > 0) { + rawCommand.insert( + rawCommand.end(), + data.begin(), + data.end() + ); + } + + return rawCommand; } /** @@ -83,14 +144,37 @@ namespace Bloom::DebugToolDrivers::Protocols::CmsisDap::Edbg::Avr * @return * A vector of sequenced AVRCommands, each containing a segment of the AvrCommandFrame. */ - [[nodiscard]] std::vector generateAvrCommands(std::size_t maximumCommandPacketSize) const; + [[nodiscard]] std::vector generateAvrCommands(std::size_t maximumCommandPacketSize) const { + auto rawCommandFrame = this->getRawCommandFrame(); - /** - * Converts instance of a CMSIS Command to an unsigned char, for sending to the Atmel ICE device. - * - * @return - */ - explicit virtual operator std::vector () const; + std::size_t commandFrameSize = rawCommandFrame.size(); + auto commandsRequired = static_cast( + std::ceil(static_cast(commandFrameSize) / static_cast(maximumCommandPacketSize)) + ); + + std::vector avrCommands; + std::size_t copiedPacketSize = 0; + for (std::size_t i = 0; i < commandsRequired; i++) { + // If we're on the last packet, the packet size will be what ever is left of the AvrCommandFrame + std::size_t commandPacketSize = ((i + 1) != commandsRequired) ? maximumCommandPacketSize + : (commandFrameSize - (maximumCommandPacketSize * i)); + + avrCommands.emplace_back(AvrCommand( + commandsRequired, + i + 1, + std::vector( + rawCommandFrame.begin() + static_cast(copiedPacketSize), + rawCommandFrame.begin() + static_cast(copiedPacketSize + commandPacketSize) + ) + )); + copiedPacketSize += commandPacketSize; + } + + return avrCommands; + } + + protected: + PayloadContainerType payload; private: unsigned char SOF = 0x0E; @@ -101,14 +185,11 @@ namespace Bloom::DebugToolDrivers::Protocols::CmsisDap::Edbg::Avr * Incrementing from 0x00 */ std::uint16_t sequenceId = 0; - inline static std::uint16_t lastSequenceId = 0; /** * Destination sub-protocol handler ID */ ProtocolHandlerId protocolHandlerID = ProtocolHandlerId::DISCOVERY; - - std::vector payload; }; } diff --git a/src/DebugToolDrivers/Protocols/CMSIS-DAP/VendorSpecific/EDBG/AVR/CommandFrames/Discovery/DiscoveryCommandFrame.hpp b/src/DebugToolDrivers/Protocols/CMSIS-DAP/VendorSpecific/EDBG/AVR/CommandFrames/Discovery/DiscoveryCommandFrame.hpp index fb2acbde..2aa44b76 100644 --- a/src/DebugToolDrivers/Protocols/CMSIS-DAP/VendorSpecific/EDBG/AVR/CommandFrames/Discovery/DiscoveryCommandFrame.hpp +++ b/src/DebugToolDrivers/Protocols/CMSIS-DAP/VendorSpecific/EDBG/AVR/CommandFrames/Discovery/DiscoveryCommandFrame.hpp @@ -34,7 +34,8 @@ namespace Bloom::DebugToolDrivers::Protocols::CmsisDap::Edbg::Avr::CommandFrames return static_cast(id) != rawId; } - class DiscoveryCommandFrame: public AvrCommandFrame + template + class DiscoveryCommandFrame: public AvrCommandFrame { public: using ResponseFrameType = ResponseFrames::DiscoveryResponseFrame; diff --git a/src/DebugToolDrivers/Protocols/CMSIS-DAP/VendorSpecific/EDBG/AVR/CommandFrames/Discovery/Query.hpp b/src/DebugToolDrivers/Protocols/CMSIS-DAP/VendorSpecific/EDBG/AVR/CommandFrames/Discovery/Query.hpp index 5326ca89..f86b6c2f 100644 --- a/src/DebugToolDrivers/Protocols/CMSIS-DAP/VendorSpecific/EDBG/AVR/CommandFrames/Discovery/Query.hpp +++ b/src/DebugToolDrivers/Protocols/CMSIS-DAP/VendorSpecific/EDBG/AVR/CommandFrames/Discovery/Query.hpp @@ -19,31 +19,19 @@ namespace Bloom::DebugToolDrivers::Protocols::CmsisDap::Edbg::Avr::CommandFrames * The Discovery protocol handler only supports one command; the Query command. This command is used to * query information from the device, such as device capabilities, manufacture date, serial number, etc. */ - class Query: public DiscoveryCommandFrame + class Query: public DiscoveryCommandFrame> { public: - Query(): DiscoveryCommandFrame() {} - - explicit Query(QueryContext context): DiscoveryCommandFrame() { - this->setContext(context); - } - - void setContext(QueryContext context) { - this->context = context; - } - - [[nodiscard]] std::vector getPayload() const override { + explicit Query(QueryContext context) { /* * The payload for the Query command consists of three bytes. A command ID (0x00), version (0x00) and a * query context. */ - auto output = std::vector(3, 0x00); - output[2] = static_cast(this->context); - - return output; + this->payload = { + 0x00, + 0x00, + static_cast(context) + }; } - - private: - QueryContext context = QueryContext::COMMAND_HANDLERS; }; } diff --git a/src/DebugToolDrivers/Protocols/CMSIS-DAP/VendorSpecific/EDBG/AVR/CommandFrames/HouseKeeping/EndSession.hpp b/src/DebugToolDrivers/Protocols/CMSIS-DAP/VendorSpecific/EDBG/AVR/CommandFrames/HouseKeeping/EndSession.hpp index 0ecd1f03..68b2ac08 100644 --- a/src/DebugToolDrivers/Protocols/CMSIS-DAP/VendorSpecific/EDBG/AVR/CommandFrames/HouseKeeping/EndSession.hpp +++ b/src/DebugToolDrivers/Protocols/CMSIS-DAP/VendorSpecific/EDBG/AVR/CommandFrames/HouseKeeping/EndSession.hpp @@ -7,24 +7,19 @@ namespace Bloom::DebugToolDrivers::Protocols::CmsisDap::Edbg::Avr::CommandFrames /** * The End Session command ends the active session with the tool. */ - class EndSession: public HouseKeepingCommandFrame + class EndSession: public HouseKeepingCommandFrame> { public: - EndSession(): HouseKeepingCommandFrame() { - this->init(); - } - - private: - void init() { + EndSession() { /* * The payload for the End Session command consists of three bytes. A command ID byte (0x11), a * version byte (0x00) and a reset flag (0x00 for no reset, 0x01 for tool reset). */ - auto payload = std::vector(3); - payload[0] = 0x11; - payload[1] = 0x00; - payload[2] = 0x00; - this->setPayload(payload); + this->payload = { + 0x11, + 0x00, + 0x00 + }; } }; } diff --git a/src/DebugToolDrivers/Protocols/CMSIS-DAP/VendorSpecific/EDBG/AVR/CommandFrames/HouseKeeping/GetParameter.hpp b/src/DebugToolDrivers/Protocols/CMSIS-DAP/VendorSpecific/EDBG/AVR/CommandFrames/HouseKeeping/GetParameter.hpp index 3d02a4ce..faa569ba 100644 --- a/src/DebugToolDrivers/Protocols/CMSIS-DAP/VendorSpecific/EDBG/AVR/CommandFrames/HouseKeeping/GetParameter.hpp +++ b/src/DebugToolDrivers/Protocols/CMSIS-DAP/VendorSpecific/EDBG/AVR/CommandFrames/HouseKeeping/GetParameter.hpp @@ -7,24 +7,10 @@ namespace Bloom::DebugToolDrivers::Protocols::CmsisDap::Edbg::Avr::CommandFrames::HouseKeeping { - class GetParameter: public HouseKeepingCommandFrame + class GetParameter: public HouseKeepingCommandFrame> { public: - explicit GetParameter(const Parameter& parameter): parameter(parameter) {} - - GetParameter(const Parameter& parameter, std::uint8_t size): GetParameter(parameter) { - this->setSize(size); - } - - void setParameter(const Parameter& parameter) { - this->parameter = parameter; - } - - void setSize(std::uint8_t size) { - this->size = size; - } - - [[nodiscard]] std::vector getPayload() const override { + explicit GetParameter(const Parameter& parameter, std::uint8_t size) { /* * The get param command consists of 5 bytes: * 1. Command ID (0x02) @@ -33,18 +19,13 @@ namespace Bloom::DebugToolDrivers::Protocols::CmsisDap::Edbg::Avr::CommandFrames * 4. Param ID (Parameter::id) * 5. Param value length (this->size) */ - auto output = std::vector(5, 0x00); - output[0] = 0x02; - output[1] = 0x00; - output[2] = static_cast(this->parameter.context); - output[3] = static_cast(this->parameter.id); - output[4] = static_cast(this->size); - - return output; + this->payload = { + 0x02, + 0x00, + static_cast(parameter.context), + static_cast(parameter.id), + static_cast(size) + }; } - - private: - Parameter parameter; - std::uint8_t size = 0; }; } diff --git a/src/DebugToolDrivers/Protocols/CMSIS-DAP/VendorSpecific/EDBG/AVR/CommandFrames/HouseKeeping/HouseKeepingCommandFrame.hpp b/src/DebugToolDrivers/Protocols/CMSIS-DAP/VendorSpecific/EDBG/AVR/CommandFrames/HouseKeeping/HouseKeepingCommandFrame.hpp index 662f7130..7eb24107 100644 --- a/src/DebugToolDrivers/Protocols/CMSIS-DAP/VendorSpecific/EDBG/AVR/CommandFrames/HouseKeeping/HouseKeepingCommandFrame.hpp +++ b/src/DebugToolDrivers/Protocols/CMSIS-DAP/VendorSpecific/EDBG/AVR/CommandFrames/HouseKeeping/HouseKeepingCommandFrame.hpp @@ -21,7 +21,8 @@ namespace Bloom::DebugToolDrivers::Protocols::CmsisDap::Edbg::Avr::CommandFrames return rawId == id; } - class HouseKeepingCommandFrame: public AvrCommandFrame + template + class HouseKeepingCommandFrame: public AvrCommandFrame { public: HouseKeepingCommandFrame() { diff --git a/src/DebugToolDrivers/Protocols/CMSIS-DAP/VendorSpecific/EDBG/AVR/CommandFrames/HouseKeeping/StartSession.hpp b/src/DebugToolDrivers/Protocols/CMSIS-DAP/VendorSpecific/EDBG/AVR/CommandFrames/HouseKeeping/StartSession.hpp index 53c797e6..3c4387e0 100644 --- a/src/DebugToolDrivers/Protocols/CMSIS-DAP/VendorSpecific/EDBG/AVR/CommandFrames/HouseKeeping/StartSession.hpp +++ b/src/DebugToolDrivers/Protocols/CMSIS-DAP/VendorSpecific/EDBG/AVR/CommandFrames/HouseKeeping/StartSession.hpp @@ -1,5 +1,7 @@ #pragma once +#include + #include "HouseKeepingCommandFrame.hpp" namespace Bloom::DebugToolDrivers::Protocols::CmsisDap::Edbg::Avr::CommandFrames::HouseKeeping @@ -7,23 +9,18 @@ namespace Bloom::DebugToolDrivers::Protocols::CmsisDap::Edbg::Avr::CommandFrames /** * The Start Session command begins a session with the tool. */ - class StartSession: public HouseKeepingCommandFrame + class StartSession: public HouseKeepingCommandFrame> { public: - StartSession(): HouseKeepingCommandFrame() { - this->init(); - } - - private: - void init() { + StartSession() { /* * The payload for the Start Session command consists of two bytes. A command ID byte (0x10) and a * version byte (0x00). */ - auto payload = std::vector(2); - payload[0] = 0x10; - payload[1] = 0x00; - this->setPayload(payload); + this->payload = { + 0x10, + 0x00 + }; } }; } diff --git a/src/DebugToolDrivers/Protocols/CMSIS-DAP/VendorSpecific/EDBG/AVR/EdbgAvr8Interface.cpp b/src/DebugToolDrivers/Protocols/CMSIS-DAP/VendorSpecific/EDBG/AVR/EdbgAvr8Interface.cpp index 34994b82..6dc07a5d 100644 --- a/src/DebugToolDrivers/Protocols/CMSIS-DAP/VendorSpecific/EDBG/AVR/EdbgAvr8Interface.cpp +++ b/src/DebugToolDrivers/Protocols/CMSIS-DAP/VendorSpecific/EDBG/AVR/EdbgAvr8Interface.cpp @@ -1459,11 +1459,12 @@ namespace Bloom::DebugToolDrivers::Protocols::CmsisDap::Edbg::Avr } } - auto commandFrame = CommandFrames::Avr8Generic::ReadMemory(); - commandFrame.setType(type); - commandFrame.setAddress(startAddress); - commandFrame.setBytes(bytes); - commandFrame.setExcludedAddresses(excludedAddresses); + auto commandFrame = CommandFrames::Avr8Generic::ReadMemory( + type, + startAddress, + bytes, + excludedAddresses + ); auto response = this->edbgInterface.sendAvrCommandFrameAndWaitForResponseFrame(commandFrame); if (response.getResponseId() == Avr8ResponseId::FAILED) { @@ -1479,10 +1480,11 @@ namespace Bloom::DebugToolDrivers::Protocols::CmsisDap::Edbg::Avr throw Exception("Writing to flash memory is not supported."); } - auto commandFrame = CommandFrames::Avr8Generic::WriteMemory(); - commandFrame.setType(type); - commandFrame.setAddress(address); - commandFrame.setBuffer(buffer); + auto commandFrame = CommandFrames::Avr8Generic::WriteMemory( + type, + address, + buffer + ); auto response = this->edbgInterface.sendAvrCommandFrameAndWaitForResponseFrame(commandFrame); if (response.getResponseId() == Avr8ResponseId::FAILED) { diff --git a/src/DebugToolDrivers/Protocols/CMSIS-DAP/VendorSpecific/EDBG/EdbgInterface.cpp b/src/DebugToolDrivers/Protocols/CMSIS-DAP/VendorSpecific/EDBG/EdbgInterface.cpp index 13fe4583..b99b0cfd 100644 --- a/src/DebugToolDrivers/Protocols/CMSIS-DAP/VendorSpecific/EDBG/EdbgInterface.cpp +++ b/src/DebugToolDrivers/Protocols/CMSIS-DAP/VendorSpecific/EDBG/EdbgInterface.cpp @@ -8,18 +8,10 @@ namespace Bloom::DebugToolDrivers::Protocols::CmsisDap::Edbg { using namespace Bloom::Exceptions; - Protocols::CmsisDap::Response EdbgInterface::sendAvrCommandFrameAndWaitForResponse( - const Protocols::CmsisDap::Edbg::Avr::AvrCommandFrame& avrCommandFrame + Protocols::CmsisDap::Response EdbgInterface::sendAvrCommandsAndWaitForResponse( + const std::vector& avrCommands ) { - // An AVR command frame can be split into multiple CMSIS-DAP commands. Each command - // containing a fragment of the AvrCommandFrame. - - // Minus 3 to accommodate AVR command meta data - std::size_t maximumCommandPacketSize = (this->getUsbHidInputReportSize() - 3); - - auto avrCommands = avrCommandFrame.generateAvrCommands(maximumCommandPacketSize); - - for (auto& avrCommand : avrCommands) { + for (const auto& avrCommand : avrCommands) { // Send command to device auto response = this->sendCommandAndWaitForResponse(avrCommand); diff --git a/src/DebugToolDrivers/Protocols/CMSIS-DAP/VendorSpecific/EDBG/EdbgInterface.hpp b/src/DebugToolDrivers/Protocols/CMSIS-DAP/VendorSpecific/EDBG/EdbgInterface.hpp index 68352caf..0bd5bdaa 100644 --- a/src/DebugToolDrivers/Protocols/CMSIS-DAP/VendorSpecific/EDBG/EdbgInterface.hpp +++ b/src/DebugToolDrivers/Protocols/CMSIS-DAP/VendorSpecific/EDBG/EdbgInterface.hpp @@ -33,8 +33,19 @@ namespace Bloom::DebugToolDrivers::Protocols::CmsisDap::Edbg * @param avrCommandFrame * @return */ - virtual Protocols::CmsisDap::Response sendAvrCommandFrameAndWaitForResponse( - const Protocols::CmsisDap::Edbg::Avr::AvrCommandFrame& avrCommandFrame + template + Protocols::CmsisDap::Response sendAvrCommandFrameAndWaitForResponse( + const Protocols::CmsisDap::Edbg::Avr::AvrCommandFrame& avrCommandFrame + ) { + // An AVR command frame can be split into multiple CMSIS-DAP commands. Each command + // containing a fragment of the AvrCommandFrame. + return this->sendAvrCommandsAndWaitForResponse(avrCommandFrame.generateAvrCommands( + this->getUsbHidInputReportSize() - 3 // Minus 3 to accommodate AVR command bytes + )); + } + + virtual Protocols::CmsisDap::Response sendAvrCommandsAndWaitForResponse( + const std::vector& avrCommands ); Protocols::CmsisDap::Edbg::Avr::AvrResponse getAvrResponse(); @@ -44,12 +55,10 @@ namespace Bloom::DebugToolDrivers::Protocols::CmsisDap::Edbg const CommandFrameType& avrCommandFrame ) { static_assert( - std::is_base_of::value, - "AVR Command must be base of AvrCommandFrame." - ); - - static_assert( - std::is_base_of::value, + std::is_base_of< + Protocols::CmsisDap::Edbg::Avr::AvrResponseFrame, + typename CommandFrameType::ResponseFrameType + >::value, "AVR Command must specify a valid response frame type, derived from AvrResponseFrame." );