Tidying
This commit is contained in:
@@ -100,10 +100,10 @@ namespace Usb
|
|||||||
}
|
}
|
||||||
|
|
||||||
std::string HidInterface::getHidDevicePath() {
|
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_enumerate(this->vendorId, this->productId),
|
||||||
::hid_free_enumeration
|
::hid_free_enumeration
|
||||||
);
|
};
|
||||||
|
|
||||||
auto matchedDevice = std::optional<::hid_device_info*>{};
|
auto matchedDevice = std::optional<::hid_device_info*>{};
|
||||||
|
|
||||||
|
|||||||
@@ -435,16 +435,14 @@ namespace DebugToolDrivers::Wch
|
|||||||
* anything below 2.11.
|
* anything below 2.11.
|
||||||
*/
|
*/
|
||||||
static constexpr auto MIN_FW_VERSION = WchFirmwareVersion{.major = 2, .minor = 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
|
this->toolInfo.firmwareVersion < MIN_FW_VERSION ? 64 : 2
|
||||||
);
|
);
|
||||||
const auto alignedAddressRange = AlignmentService::alignAddressRange(addressRange, alignmentSize);
|
|
||||||
|
|
||||||
if (alignedAddressRange != addressRange) {
|
if (alignedAddressRange != addressRange) {
|
||||||
const auto alignedBufferSize = alignedAddressRange.size();
|
const auto alignedBufferSize = alignedAddressRange.size();
|
||||||
const auto addressAlignmentBytes = static_cast<TargetMemorySize>(
|
const auto addressAlignmentBytes = addressRange.startAddress - alignedAddressRange.startAddress;
|
||||||
addressRange.startAddress - alignedAddressRange.startAddress
|
|
||||||
);
|
|
||||||
const auto sizeAlignmentBytes = alignedBufferSize - bufferSize - addressAlignmentBytes;
|
const auto sizeAlignmentBytes = alignedBufferSize - bufferSize - addressAlignmentBytes;
|
||||||
|
|
||||||
auto alignedBuffer = addressAlignmentBytes > 0
|
auto alignedBuffer = addressAlignmentBytes > 0
|
||||||
@@ -591,9 +589,7 @@ namespace DebugToolDrivers::Wch
|
|||||||
}
|
}
|
||||||
|
|
||||||
const auto alignedBufferSize = alignedAddressRange.size();
|
const auto alignedBufferSize = alignedAddressRange.size();
|
||||||
const auto addressAlignmentBytes = static_cast<TargetMemorySize>(
|
const auto addressAlignmentBytes = startAddress - alignedAddressRange.startAddress;
|
||||||
startAddress - alignedAddressRange.startAddress
|
|
||||||
);
|
|
||||||
const auto sizeAlignmentBytes = (alignedAddressRange.endAddress > addressRange.endAddress)
|
const auto sizeAlignmentBytes = (alignedAddressRange.endAddress > addressRange.endAddress)
|
||||||
? alignedAddressRange.endAddress - addressRange.endAddress
|
? alignedAddressRange.endAddress - addressRange.endAddress
|
||||||
: 0;
|
: 0;
|
||||||
@@ -696,14 +692,17 @@ namespace DebugToolDrivers::Wch
|
|||||||
*
|
*
|
||||||
* See the WchLinkDebugInterface::writeProgramMemoryFullBlock() member function for more.
|
* See the WchLinkDebugInterface::writeProgramMemoryFullBlock() member function for more.
|
||||||
*/
|
*/
|
||||||
const auto finalBlockEnd = (
|
const auto finalBlockEndAddress = (
|
||||||
(memorySegmentDescriptor.addressRange.endAddress / this->programmingBlockSize) * this->programmingBlockSize
|
(memorySegmentDescriptor.addressRange.endAddress / this->programmingBlockSize) * this->programmingBlockSize
|
||||||
);
|
);
|
||||||
return addressSpaceDescriptor == this->sysAddressSpaceDescriptor
|
return addressSpaceDescriptor == this->sysAddressSpaceDescriptor
|
||||||
&& memorySegmentDescriptor.type == TargetMemorySegmentType::FLASH
|
&& memorySegmentDescriptor.type == TargetMemorySegmentType::FLASH
|
||||||
&& memorySegmentDescriptor.size() >= this->programmingBlockSize
|
&& memorySegmentDescriptor.size() >= this->programmingBlockSize
|
||||||
&& (memorySegmentDescriptor.addressRange.startAddress % this->programmingBlockSize) == 0
|
&& (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)
|
, memorySegmentDescriptor(memorySegmentDescriptor)
|
||||||
, startAddress(startAddress)
|
, startAddress(startAddress)
|
||||||
, size(size)
|
, size(size)
|
||||||
{};
|
{}
|
||||||
|
|
||||||
[[nodiscard]] EventType getType() const override {
|
[[nodiscard]] EventType getType() const override {
|
||||||
return MemoryWrittenToTarget::type;
|
return MemoryWrittenToTarget::type;
|
||||||
|
|||||||
@@ -48,7 +48,7 @@ public:
|
|||||||
{}
|
{}
|
||||||
|
|
||||||
Accessor accessor() {
|
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
|
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
|
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"
|
#### Thread-safe access of the target descriptor - the "managed target descriptor object"
|
||||||
|
|
||||||
|
|||||||
@@ -123,7 +123,7 @@ namespace TargetController
|
|||||||
CommandIdType commandId,
|
CommandIdType commandId,
|
||||||
std::optional<std::chrono::milliseconds> timeout
|
std::optional<std::chrono::milliseconds> timeout
|
||||||
) {
|
) {
|
||||||
auto response = std::unique_ptr<Response>(nullptr);
|
auto response = std::unique_ptr<Response>{};
|
||||||
|
|
||||||
const auto predicate = [commandId, &response] {
|
const auto predicate = [commandId, &response] {
|
||||||
// We will already hold the lock here, so we can use Synchronised::unsafeReference() here.
|
// We will already hold the lock here, so we can use Synchronised::unsafeReference() here.
|
||||||
@@ -372,7 +372,7 @@ namespace TargetController
|
|||||||
using namespace DebugToolDrivers::Wch;
|
using namespace DebugToolDrivers::Wch;
|
||||||
|
|
||||||
// The debug tool names in this mapping should always be lower-case.
|
// 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",
|
"atmel_ice",
|
||||||
[this] {
|
[this] {
|
||||||
@@ -476,59 +476,57 @@ namespace TargetController
|
|||||||
);
|
);
|
||||||
|
|
||||||
while (!commands.empty()) {
|
while (!commands.empty()) {
|
||||||
const auto command = std::move(commands.front());
|
const auto& command = commands.front();
|
||||||
commands.pop();
|
|
||||||
|
|
||||||
const auto commandId = command->id;
|
|
||||||
const auto commandType = command->getType();
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const auto commandHandlerIt = this->commandHandlersByCommandType.find(commandType);
|
const auto commandHandlerIt = this->commandHandlersByCommandType.find(command->getType());
|
||||||
|
|
||||||
if (commandHandlerIt == this->commandHandlersByCommandType.end()) {
|
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) {
|
if (this->state != TargetControllerState::ACTIVE) {
|
||||||
throw Exception{"Command rejected - TargetController not in active state."};
|
throw Exception{"Command rejected - TargetController not in active state"};
|
||||||
}
|
}
|
||||||
|
|
||||||
if (
|
if (
|
||||||
command->requiresStoppedTargetState()
|
command->requiresStoppedTargetState()
|
||||||
&& this->targetState->executionState != TargetExecutionState::STOPPED
|
&& 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()) {
|
if (this->target->programmingModeEnabled() && command->requiresDebugMode()) {
|
||||||
throw Exception{
|
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) {
|
} catch (const FatalErrorException& exception) {
|
||||||
this->registerCommandResponse(
|
this->registerCommandResponse(
|
||||||
commandId,
|
command->id,
|
||||||
std::make_unique<Responses::Error>(exception.getMessage())
|
std::make_unique<Responses::Error>(exception.getMessage())
|
||||||
);
|
);
|
||||||
|
|
||||||
throw exception;
|
throw;
|
||||||
|
|
||||||
} catch (const Exception& exception) {
|
} catch (const Exception& exception) {
|
||||||
try {
|
try {
|
||||||
this->refreshExecutionState(true);
|
this->refreshExecutionState(true);
|
||||||
|
|
||||||
} catch (const Exception& refreshException) {
|
} 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(
|
this->registerCommandResponse(
|
||||||
commandId,
|
command->id,
|
||||||
std::make_unique<Responses::Error>(exception.getMessage())
|
std::make_unique<Responses::Error>(exception.getMessage())
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
commands.pop();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user