diff --git a/src/Insight/InsightWorker/Tasks/ReadTargetMemory.cpp b/src/Insight/InsightWorker/Tasks/ReadTargetMemory.cpp index 875098f8..33f7f516 100644 --- a/src/Insight/InsightWorker/Tasks/ReadTargetMemory.cpp +++ b/src/Insight/InsightWorker/Tasks/ReadTargetMemory.cpp @@ -1,21 +1,37 @@ #include "ReadTargetMemory.hpp" #include +#include #include "src/Targets/TargetMemory.hpp" +#include "src/Exceptions/Exception.hpp" namespace Bloom { using TargetController::TargetControllerConsole; void ReadTargetMemory::run(TargetControllerConsole& targetControllerConsole) { + using Targets::TargetMemorySize; + + const auto& targetDescriptor = targetControllerConsole.getTargetDescriptor(); + const auto memoryDescriptorIt = targetDescriptor.memoryDescriptorsByType.find(this->memoryType); + + if (memoryDescriptorIt == targetDescriptor.memoryDescriptorsByType.end()) { + throw Exceptions::Exception("Invalid memory type"); + } + + const auto& memoryDescriptor = memoryDescriptorIt->second; + /* * To prevent locking up the TargetController for too long, we split the read into numerous reads. * * This allows the TargetController to service other commands in-between reads, reducing the likelihood of * command timeouts when we're reading lots of data. */ - constexpr auto readSize = 256; + const auto readSize = std::max( + TargetMemorySize(256), + memoryDescriptor.pageSize.value_or(TargetMemorySize(0)) + ); const auto readsRequired = static_cast( std::ceil(static_cast(this->size) / static_cast(readSize)) ); diff --git a/src/Targets/TargetMemory.hpp b/src/Targets/TargetMemory.hpp index 80405328..0425b302 100644 --- a/src/Targets/TargetMemory.hpp +++ b/src/Targets/TargetMemory.hpp @@ -65,12 +65,12 @@ namespace Bloom::Targets { TargetMemoryType type; TargetMemoryAddressRange addressRange; - std::optional pageSize; + std::optional pageSize; TargetMemoryDescriptor( TargetMemoryType type, TargetMemoryAddressRange addressRange, - std::optional pageSize = std::nullopt + std::optional pageSize = std::nullopt ) : type(type) , addressRange(addressRange)