From 0abbe9eb22e5e80baf907e0a42f7c50abbf498a0 Mon Sep 17 00:00:00 2001 From: Nav Date: Sat, 12 Apr 2025 03:59:32 +0100 Subject: [PATCH] Tidying --- src/DebugToolDrivers/Usb/Hid/HidInterface.cpp | 4 +-- .../Wch/WchLinkDebugInterface.cpp | 19 ++++++----- .../Events/MemoryWrittenToTarget.hpp | 2 +- src/Helpers/Synchronised.hpp | 2 +- src/TargetController/README.md | 2 +- .../TargetControllerComponent.cpp | 32 +++++++++---------- 6 files changed, 29 insertions(+), 32 deletions(-) diff --git a/src/DebugToolDrivers/Usb/Hid/HidInterface.cpp b/src/DebugToolDrivers/Usb/Hid/HidInterface.cpp index 0d671b6b..f1da268c 100644 --- a/src/DebugToolDrivers/Usb/Hid/HidInterface.cpp +++ b/src/DebugToolDrivers/Usb/Hid/HidInterface.cpp @@ -100,10 +100,10 @@ namespace Usb } std::string HidInterface::getHidDevicePath() { - const auto hidDeviceInfoList = std::unique_ptr<::hid_device_info, decltype(&::hid_free_enumeration)>( + const auto hidDeviceInfoList = std::unique_ptr<::hid_device_info, decltype(&::hid_free_enumeration)>{ ::hid_enumerate(this->vendorId, this->productId), ::hid_free_enumeration - ); + }; auto matchedDevice = std::optional<::hid_device_info*>{}; diff --git a/src/DebugToolDrivers/Wch/WchLinkDebugInterface.cpp b/src/DebugToolDrivers/Wch/WchLinkDebugInterface.cpp index 506c6283..c8bb8686 100644 --- a/src/DebugToolDrivers/Wch/WchLinkDebugInterface.cpp +++ b/src/DebugToolDrivers/Wch/WchLinkDebugInterface.cpp @@ -435,16 +435,14 @@ namespace DebugToolDrivers::Wch * anything below 2.11. */ static constexpr auto MIN_FW_VERSION = WchFirmwareVersion{.major = 2, .minor = 11}; - const auto alignmentSize = static_cast( + const auto alignedAddressRange = AlignmentService::alignAddressRange( + addressRange, this->toolInfo.firmwareVersion < MIN_FW_VERSION ? 64 : 2 ); - const auto alignedAddressRange = AlignmentService::alignAddressRange(addressRange, alignmentSize); if (alignedAddressRange != addressRange) { const auto alignedBufferSize = alignedAddressRange.size(); - const auto addressAlignmentBytes = static_cast( - addressRange.startAddress - alignedAddressRange.startAddress - ); + const auto addressAlignmentBytes = addressRange.startAddress - alignedAddressRange.startAddress; const auto sizeAlignmentBytes = alignedBufferSize - bufferSize - addressAlignmentBytes; auto alignedBuffer = addressAlignmentBytes > 0 @@ -591,9 +589,7 @@ namespace DebugToolDrivers::Wch } const auto alignedBufferSize = alignedAddressRange.size(); - const auto addressAlignmentBytes = static_cast( - startAddress - alignedAddressRange.startAddress - ); + const auto addressAlignmentBytes = startAddress - alignedAddressRange.startAddress; const auto sizeAlignmentBytes = (alignedAddressRange.endAddress > addressRange.endAddress) ? alignedAddressRange.endAddress - addressRange.endAddress : 0; @@ -696,14 +692,17 @@ namespace DebugToolDrivers::Wch * * See the WchLinkDebugInterface::writeProgramMemoryFullBlock() member function for more. */ - const auto finalBlockEnd = ( + const auto finalBlockEndAddress = ( (memorySegmentDescriptor.addressRange.endAddress / this->programmingBlockSize) * this->programmingBlockSize ); return addressSpaceDescriptor == this->sysAddressSpaceDescriptor && memorySegmentDescriptor.type == TargetMemorySegmentType::FLASH && memorySegmentDescriptor.size() >= this->programmingBlockSize && (memorySegmentDescriptor.addressRange.startAddress % this->programmingBlockSize) == 0 - && (memorySegmentDescriptor.size() % this->programmingBlockSize == 0 || startAddress <= finalBlockEnd) + && ( + memorySegmentDescriptor.size() % this->programmingBlockSize == 0 + || startAddress <= finalBlockEndAddress + ) ; } diff --git a/src/EventManager/Events/MemoryWrittenToTarget.hpp b/src/EventManager/Events/MemoryWrittenToTarget.hpp index 9ab5f9a3..89c56107 100644 --- a/src/EventManager/Events/MemoryWrittenToTarget.hpp +++ b/src/EventManager/Events/MemoryWrittenToTarget.hpp @@ -31,7 +31,7 @@ namespace Events , memorySegmentDescriptor(memorySegmentDescriptor) , startAddress(startAddress) , size(size) - {}; + {} [[nodiscard]] EventType getType() const override { return MemoryWrittenToTarget::type; diff --git a/src/Helpers/Synchronised.hpp b/src/Helpers/Synchronised.hpp index 503c29d4..6dd39b5c 100644 --- a/src/Helpers/Synchronised.hpp +++ b/src/Helpers/Synchronised.hpp @@ -48,7 +48,7 @@ public: {} Accessor accessor() { - return Accessor(this->mutex, this->value); + return Accessor{this->mutex, this->value}; } /** diff --git a/src/TargetController/README.md b/src/TargetController/README.md index 31196177..5526e202 100644 --- a/src/TargetController/README.md +++ b/src/TargetController/README.md @@ -215,7 +215,7 @@ objects. It is the invoker's responsibility to ensure that all const references to descriptor objects, passed to the TargetController, are still valid at the time the TargetController services the command. If the TargetController -encounters a dangling reference, undefined behaviour will occur. See the "master target descriptor" for more. +encounters a dangling reference, undefined behaviour will occur. See the "managed target descriptor" for more. #### Thread-safe access of the target descriptor - the "managed target descriptor object" diff --git a/src/TargetController/TargetControllerComponent.cpp b/src/TargetController/TargetControllerComponent.cpp index 6a40c859..3339e8ef 100644 --- a/src/TargetController/TargetControllerComponent.cpp +++ b/src/TargetController/TargetControllerComponent.cpp @@ -123,7 +123,7 @@ namespace TargetController CommandIdType commandId, std::optional timeout ) { - auto response = std::unique_ptr(nullptr); + auto response = std::unique_ptr{}; const auto predicate = [commandId, &response] { // We will already hold the lock here, so we can use Synchronised::unsafeReference() here. @@ -372,7 +372,7 @@ namespace TargetController using namespace DebugToolDrivers::Wch; // The debug tool names in this mapping should always be lower-case. - return std::map()>> { + return std::map()>>{ { "atmel_ice", [this] { @@ -476,59 +476,57 @@ namespace TargetController ); while (!commands.empty()) { - const auto command = std::move(commands.front()); - commands.pop(); - - const auto commandId = command->id; - const auto commandType = command->getType(); + const auto& command = commands.front(); try { - const auto commandHandlerIt = this->commandHandlersByCommandType.find(commandType); + const auto commandHandlerIt = this->commandHandlersByCommandType.find(command->getType()); if (commandHandlerIt == this->commandHandlersByCommandType.end()) { - throw Exception{"No handler registered for this command."}; + throw Exception{"No handler registered for this command"}; } if (this->state != TargetControllerState::ACTIVE) { - throw Exception{"Command rejected - TargetController not in active state."}; + throw Exception{"Command rejected - TargetController not in active state"}; } if ( command->requiresStoppedTargetState() && this->targetState->executionState != TargetExecutionState::STOPPED ) { - throw Exception{"Command rejected - command requires target execution to be stopped."}; + throw Exception{"Command rejected - command requires target execution to be stopped"}; } if (this->target->programmingModeEnabled() && command->requiresDebugMode()) { throw Exception{ - "Command rejected - command cannot be serviced whilst the target is in programming mode." + "Command rejected - command cannot be serviced whilst the target is in programming mode" }; } - this->registerCommandResponse(commandId, commandHandlerIt->second(*(command.get()))); + this->registerCommandResponse(command->id, commandHandlerIt->second(*(command.get()))); } catch (const FatalErrorException& exception) { this->registerCommandResponse( - commandId, + command->id, std::make_unique(exception.getMessage()) ); - throw exception; + throw; } catch (const Exception& exception) { try { this->refreshExecutionState(true); } catch (const Exception& refreshException) { - Logger::error("Post exception target state refresh failed: " + refreshException.getMessage()); + Logger::error("Post-exception target state refresh failed: " + refreshException.getMessage()); } this->registerCommandResponse( - commandId, + command->id, std::make_unique(exception.getMessage()) ); } + + commands.pop(); } }