Tidying
This commit is contained in:
@@ -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*>{};
|
||||
|
||||
|
||||
@@ -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<TargetMemorySize>(
|
||||
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<TargetMemorySize>(
|
||||
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<TargetMemorySize>(
|
||||
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
|
||||
)
|
||||
;
|
||||
}
|
||||
|
||||
|
||||
@@ -31,7 +31,7 @@ namespace Events
|
||||
, memorySegmentDescriptor(memorySegmentDescriptor)
|
||||
, startAddress(startAddress)
|
||||
, size(size)
|
||||
{};
|
||||
{}
|
||||
|
||||
[[nodiscard]] EventType getType() const override {
|
||||
return MemoryWrittenToTarget::type;
|
||||
|
||||
@@ -48,7 +48,7 @@ public:
|
||||
{}
|
||||
|
||||
Accessor accessor() {
|
||||
return Accessor(this->mutex, this->value);
|
||||
return Accessor{this->mutex, this->value};
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -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"
|
||||
|
||||
|
||||
@@ -123,7 +123,7 @@ namespace TargetController
|
||||
CommandIdType commandId,
|
||||
std::optional<std::chrono::milliseconds> timeout
|
||||
) {
|
||||
auto response = std::unique_ptr<Response>(nullptr);
|
||||
auto response = std::unique_ptr<Response>{};
|
||||
|
||||
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<std::string, std::function<std::unique_ptr<DebugTool>()>> {
|
||||
return std::map<std::string, std::function<std::unique_ptr<DebugTool>()>>{
|
||||
{
|
||||
"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<Responses::Error>(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<Responses::Error>(exception.getMessage())
|
||||
);
|
||||
}
|
||||
|
||||
commands.pop();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user