Updated application to code to accomodate changes to TDF format (new pad elements and changes to variant elements)

This commit is contained in:
Nav
2024-08-16 22:50:06 +01:00
parent 129e54dd2d
commit c662e946ca
35 changed files with 534 additions and 311 deletions

View File

@@ -18,8 +18,8 @@
#include "src/TargetController/Commands/RemoveBreakpoint.hpp" #include "src/TargetController/Commands/RemoveBreakpoint.hpp"
#include "src/TargetController/Commands/SetTargetProgramCounter.hpp" #include "src/TargetController/Commands/SetTargetProgramCounter.hpp"
#include "src/TargetController/Commands/SetTargetStackPointer.hpp" #include "src/TargetController/Commands/SetTargetStackPointer.hpp"
#include "src/TargetController/Commands/GetTargetGpioPinStates.hpp" #include "src/TargetController/Commands/GetTargetGpioPadStates.hpp"
#include "src/TargetController/Commands/SetTargetGpioPinState.hpp" #include "src/TargetController/Commands/SetTargetGpioPadState.hpp"
#include "src/TargetController/Commands/GetTargetStackPointer.hpp" #include "src/TargetController/Commands/GetTargetStackPointer.hpp"
#include "src/TargetController/Commands/GetTargetProgramCounter.hpp" #include "src/TargetController/Commands/GetTargetProgramCounter.hpp"
#include "src/TargetController/Commands/EnableProgrammingMode.hpp" #include "src/TargetController/Commands/EnableProgrammingMode.hpp"
@@ -47,8 +47,8 @@ namespace Services
using TargetController::Commands::RemoveBreakpoint; using TargetController::Commands::RemoveBreakpoint;
using TargetController::Commands::SetTargetProgramCounter; using TargetController::Commands::SetTargetProgramCounter;
using TargetController::Commands::SetTargetStackPointer; using TargetController::Commands::SetTargetStackPointer;
using TargetController::Commands::GetTargetGpioPinStates; using TargetController::Commands::GetTargetGpioPadStates;
using TargetController::Commands::SetTargetGpioPinState; using TargetController::Commands::SetTargetGpioPadState;
using TargetController::Commands::GetTargetStackPointer; using TargetController::Commands::GetTargetStackPointer;
using TargetController::Commands::GetTargetProgramCounter; using TargetController::Commands::GetTargetProgramCounter;
using TargetController::Commands::EnableProgrammingMode; using TargetController::Commands::EnableProgrammingMode;
@@ -74,8 +74,8 @@ namespace Services
using Targets::TargetPinoutDescriptor; using Targets::TargetPinoutDescriptor;
using Targets::TargetPinDescriptor; using Targets::TargetPinDescriptor;
using Targets::TargetGpioPinState; using Targets::TargetGpioPadState;
using Targets::TargetGpioPinDescriptorAndStatePairs; using Targets::TargetGpioPadDescriptorAndStatePairs;
TargetControllerService::AtomicSession::AtomicSession(TargetControllerService& targetControllerService) TargetControllerService::AtomicSession::AtomicSession(TargetControllerService& targetControllerService)
: targetControllerService(targetControllerService) : targetControllerService(targetControllerService)
@@ -270,22 +270,22 @@ namespace Services
); );
} }
TargetGpioPinDescriptorAndStatePairs TargetControllerService::getGpioPinStates( TargetGpioPadDescriptorAndStatePairs TargetControllerService::getGpioPadStates(
const TargetPinoutDescriptor& pinoutDescriptor const Targets::TargetPadDescriptors& padDescriptors
) const { ) const {
return this->commandManager.sendCommandAndWaitForResponse( return this->commandManager.sendCommandAndWaitForResponse(
std::make_unique<GetTargetGpioPinStates>(pinoutDescriptor), std::make_unique<GetTargetGpioPadStates>(padDescriptors),
this->defaultTimeout, this->defaultTimeout,
this->activeAtomicSessionId this->activeAtomicSessionId
)->gpioPinStates; )->gpioPadStates;
} }
void TargetControllerService::setGpioPinState( void TargetControllerService::setGpioPadState(
const TargetPinDescriptor& pinDescriptor, const Targets::TargetPadDescriptor& padDescriptor,
const TargetGpioPinState& state const TargetGpioPadState& state
) const { ) const {
this->commandManager.sendCommandAndWaitForResponse( this->commandManager.sendCommandAndWaitForResponse(
std::make_unique<SetTargetGpioPinState>(pinDescriptor, state), std::make_unique<SetTargetGpioPadState>(padDescriptor, state),
this->defaultTimeout, this->defaultTimeout,
this->activeAtomicSessionId this->activeAtomicSessionId
); );

View File

@@ -16,8 +16,8 @@
#include "src/Targets/TargetRegisterGroupDescriptor.hpp" #include "src/Targets/TargetRegisterGroupDescriptor.hpp"
#include "src/Targets/TargetRegisterDescriptor.hpp" #include "src/Targets/TargetRegisterDescriptor.hpp"
#include "src/Targets/TargetPinoutDescriptor.hpp" #include "src/Targets/TargetPinoutDescriptor.hpp"
#include "src/Targets/TargetPinDescriptor.hpp" #include "src/Targets/TargetPadDescriptor.hpp"
#include "src/Targets/TargetGpioPinState.hpp" #include "src/Targets/TargetGpioPadState.hpp"
#include "src/Targets/TargetMemory.hpp" #include "src/Targets/TargetMemory.hpp"
#include "src/Targets/TargetBreakpoint.hpp" #include "src/Targets/TargetBreakpoint.hpp"
@@ -205,23 +205,23 @@ namespace Services
void setProgramCounter(Targets::TargetMemoryAddress address) const; void setProgramCounter(Targets::TargetMemoryAddress address) const;
/** /**
* Retrieves the pin states for a particular target variant. * Retrieves the GPIO states for the given GPIO pads.
* *
* @param pinoutDescriptor * @param padDescriptors
*/ */
Targets::TargetGpioPinDescriptorAndStatePairs getGpioPinStates( Targets::TargetGpioPadDescriptorAndStatePairs getGpioPadStates(
const Targets::TargetPinoutDescriptor& pinoutDescriptor const Targets::TargetPadDescriptors& padDescriptors
) const; ) const;
/** /**
* Updates the pin state on the target, for a specific pin. * Updates the pin state on the target, for a specific pin.
* *
* @param pinDescriptor * @param padDescriptor
* @param state * @param state
*/ */
void setGpioPinState( void setGpioPadState(
const Targets::TargetPinDescriptor& pinDescriptor, const Targets::TargetPadDescriptor& padDescriptor,
const Targets::TargetGpioPinState& state const Targets::TargetGpioPadState& state
) const; ) const;
/** /**

View File

@@ -25,8 +25,8 @@ namespace TargetController::Commands
REMOVE_BREAKPOINT, REMOVE_BREAKPOINT,
SET_TARGET_PROGRAM_COUNTER, SET_TARGET_PROGRAM_COUNTER,
SET_TARGET_STACK_POINTER, SET_TARGET_STACK_POINTER,
GET_TARGET_GPIO_PIN_STATES, GET_TARGET_GPIO_PAD_STATES,
SET_TARGET_GPIO_PIN_STATE, SET_TARGET_GPIO_PAD_STATE,
GET_TARGET_STACK_POINTER, GET_TARGET_STACK_POINTER,
GET_TARGET_PROGRAM_COUNTER, GET_TARGET_PROGRAM_COUNTER,
ENABLE_PROGRAMMING_MODE, ENABLE_PROGRAMMING_MODE,

View File

@@ -0,0 +1,32 @@
#pragma once
#include "Command.hpp"
#include "src/TargetController/Responses/TargetGpioPadStates.hpp"
#include "src/Targets/TargetPadDescriptor.hpp"
namespace TargetController::Commands
{
class GetTargetGpioPadStates: public Command
{
public:
using SuccessResponseType = Responses::TargetGpioPadStates;
static constexpr CommandType type = CommandType::GET_TARGET_GPIO_PAD_STATES;
static const inline std::string name = "GetTargetGpioPadStates";
const Targets::TargetPadDescriptors padDescriptors;
explicit GetTargetGpioPadStates(const Targets::TargetPadDescriptors& padDescriptors)
: padDescriptors(padDescriptors)
{};
[[nodiscard]] CommandType getType() const override {
return GetTargetGpioPadStates::type;
}
[[nodiscard]] bool requiresStoppedTargetState() const override {
return true;
}
};
}

View File

@@ -1,31 +0,0 @@
#pragma once
#include "Command.hpp"
#include "src/TargetController/Responses/TargetGpioPinStates.hpp"
namespace TargetController::Commands
{
class GetTargetGpioPinStates: public Command
{
public:
using SuccessResponseType = Responses::TargetGpioPinStates;
static constexpr CommandType type = CommandType::GET_TARGET_GPIO_PIN_STATES;
static const inline std::string name = "GetTargetGpioPinStates";
const Targets::TargetPinoutDescriptor& pinoutDescriptor;
explicit GetTargetGpioPinStates(const Targets::TargetPinoutDescriptor& pinoutDescriptor)
: pinoutDescriptor(pinoutDescriptor)
{};
[[nodiscard]] CommandType getType() const override {
return GetTargetGpioPinStates::type;
}
[[nodiscard]] bool requiresStoppedTargetState() const override {
return true;
}
};
}

View File

@@ -0,0 +1,35 @@
#pragma once
#include "Command.hpp"
#include "src/Targets/TargetPadDescriptor.hpp"
#include "src/Targets/TargetGpioPadState.hpp"
namespace TargetController::Commands
{
class SetTargetGpioPadState: public Command
{
public:
static constexpr CommandType type = CommandType::SET_TARGET_GPIO_PAD_STATE;
static const inline std::string name = "SetTargetGpioPadState";
const Targets::TargetPadDescriptor& padDescriptor;
Targets::TargetGpioPadState state;
SetTargetGpioPadState(
const Targets::TargetPadDescriptor& padDescriptor,
const Targets::TargetGpioPadState& state
)
: padDescriptor(padDescriptor)
, state(state)
{};
[[nodiscard]] CommandType getType() const override {
return SetTargetGpioPadState::type;
}
[[nodiscard]] bool requiresStoppedTargetState() const override {
return true;
}
};
}

View File

@@ -1,35 +0,0 @@
#pragma once
#include "Command.hpp"
#include "src/Targets/TargetPinDescriptor.hpp"
#include "src/Targets/TargetGpioPinState.hpp"
namespace TargetController::Commands
{
class SetTargetGpioPinState: public Command
{
public:
static constexpr CommandType type = CommandType::SET_TARGET_GPIO_PIN_STATE;
static const inline std::string name = "SetTargetGpioPinState";
const Targets::TargetPinDescriptor& pinDescriptor;
Targets::TargetGpioPinState state;
SetTargetGpioPinState(
const Targets::TargetPinDescriptor& pinDescriptor,
const Targets::TargetGpioPinState& state
)
: pinDescriptor(pinDescriptor)
, state(state)
{};
[[nodiscard]] CommandType getType() const override {
return SetTargetGpioPinState::type;
}
[[nodiscard]] bool requiresStoppedTargetState() const override {
return true;
}
};
}

View File

@@ -13,7 +13,7 @@ namespace TargetController::Responses
TARGET_REGISTERS_READ, TARGET_REGISTERS_READ,
TARGET_MEMORY_READ, TARGET_MEMORY_READ,
TARGET_STATE, TARGET_STATE,
TARGET_GPIO_PIN_STATES, TARGET_GPIO_PAD_STATES,
TARGET_STACK_POINTER, TARGET_STACK_POINTER,
TARGET_PROGRAM_COUNTER, TARGET_PROGRAM_COUNTER,
BREAKPOINT, BREAKPOINT,

View File

@@ -0,0 +1,29 @@
#pragma once
#include <vector>
#include "Response.hpp"
#include "src/Targets/TargetPinDescriptor.hpp"
#include "src/Targets/TargetGpioPadState.hpp"
#include "src/Helpers/Pair.hpp"
namespace TargetController::Responses
{
class TargetGpioPadStates: public Response
{
public:
static constexpr ResponseType type = ResponseType::TARGET_GPIO_PAD_STATES;
Targets::TargetGpioPadDescriptorAndStatePairs gpioPadStates;
explicit TargetGpioPadStates(const Targets::TargetGpioPadDescriptorAndStatePairs& gpioPadStates)
: gpioPadStates(gpioPadStates)
{}
[[nodiscard]] ResponseType getType() const override {
return TargetGpioPadStates::type;
}
};
}

View File

@@ -1,29 +0,0 @@
#pragma once
#include <vector>
#include "Response.hpp"
#include "src/Targets/TargetPinDescriptor.hpp"
#include "src/Targets/TargetGpioPinState.hpp"
#include "src/Helpers/Pair.hpp"
namespace TargetController::Responses
{
class TargetGpioPinStates: public Response
{
public:
static constexpr ResponseType type = ResponseType::TARGET_GPIO_PIN_STATES;
Targets::TargetGpioPinDescriptorAndStatePairs gpioPinStates;
explicit TargetGpioPinStates(const Targets::TargetGpioPinDescriptorAndStatePairs& gpioPinStates)
: gpioPinStates(gpioPinStates)
{}
[[nodiscard]] ResponseType getType() const override {
return TargetGpioPinStates::type;
}
};
}

View File

@@ -44,8 +44,8 @@ namespace TargetController
using Commands::RemoveBreakpoint; using Commands::RemoveBreakpoint;
using Commands::SetTargetProgramCounter; using Commands::SetTargetProgramCounter;
using Commands::SetTargetStackPointer; using Commands::SetTargetStackPointer;
using Commands::GetTargetGpioPinStates; using Commands::GetTargetGpioPadStates;
using Commands::SetTargetGpioPinState; using Commands::SetTargetGpioPadState;
using Commands::GetTargetStackPointer; using Commands::GetTargetStackPointer;
using Commands::GetTargetProgramCounter; using Commands::GetTargetProgramCounter;
using Commands::EnableProgrammingMode; using Commands::EnableProgrammingMode;
@@ -55,7 +55,7 @@ namespace TargetController
using Responses::AtomicSessionId; using Responses::AtomicSessionId;
using Responses::TargetRegistersRead; using Responses::TargetRegistersRead;
using Responses::TargetMemoryRead; using Responses::TargetMemoryRead;
using Responses::TargetGpioPinStates; using Responses::TargetGpioPadStates;
using Responses::TargetStackPointer; using Responses::TargetStackPointer;
using Responses::TargetProgramCounter; using Responses::TargetProgramCounter;
using Responses::Breakpoint; using Responses::Breakpoint;
@@ -233,12 +233,12 @@ namespace TargetController
std::bind(&TargetControllerComponent::handleSetProgramCounter, this, std::placeholders::_1) std::bind(&TargetControllerComponent::handleSetProgramCounter, this, std::placeholders::_1)
); );
this->registerCommandHandler<GetTargetGpioPinStates>( this->registerCommandHandler<GetTargetGpioPadStates>(
std::bind(&TargetControllerComponent::handleGetTargetGpioPinStates, this, std::placeholders::_1) std::bind(&TargetControllerComponent::handleGetTargetGpioPadStates, this, std::placeholders::_1)
); );
this->registerCommandHandler<SetTargetGpioPinState>( this->registerCommandHandler<SetTargetGpioPadState>(
std::bind(&TargetControllerComponent::handleSetTargetGpioPinState, this, std::placeholders::_1) std::bind(&TargetControllerComponent::handleSetTargetGpioPadState, this, std::placeholders::_1)
); );
this->registerCommandHandler<GetTargetStackPointer>( this->registerCommandHandler<GetTargetStackPointer>(
@@ -1007,7 +1007,7 @@ namespace TargetController
return std::make_unique<Response>(); return std::make_unique<Response>();
} }
std::unique_ptr<Response> TargetControllerComponent::handleStepTargetExecution(StepTargetExecution& command) { std::unique_ptr<Response> TargetControllerComponent::handleStepTargetExecution(StepTargetExecution&) {
this->stepTarget(); this->stepTarget();
return std::make_unique<Response>(); return std::make_unique<Response>();
} }
@@ -1053,14 +1053,14 @@ namespace TargetController
return std::make_unique<Response>(); return std::make_unique<Response>();
} }
std::unique_ptr<TargetGpioPinStates> TargetControllerComponent::handleGetTargetGpioPinStates( std::unique_ptr<TargetGpioPadStates> TargetControllerComponent::handleGetTargetGpioPadStates(
GetTargetGpioPinStates& command GetTargetGpioPadStates& command
) { ) {
return std::make_unique<TargetGpioPinStates>(this->target->getGpioPinStates(command.pinoutDescriptor)); return std::make_unique<TargetGpioPadStates>(this->target->getGpioPadStates(command.padDescriptors));
} }
std::unique_ptr<Response> TargetControllerComponent::handleSetTargetGpioPinState(SetTargetGpioPinState& command) { std::unique_ptr<Response> TargetControllerComponent::handleSetTargetGpioPadState(SetTargetGpioPadState& command) {
this->target->setGpioPinState(command.pinDescriptor, command.state); this->target->setGpioPadState(command.padDescriptor, command.state);
return std::make_unique<Response>(); return std::make_unique<Response>();
} }
@@ -1076,7 +1076,7 @@ namespace TargetController
return std::make_unique<TargetProgramCounter>(this->target->getProgramCounter()); return std::make_unique<TargetProgramCounter>(this->target->getProgramCounter());
} }
std::unique_ptr<Response> TargetControllerComponent::handleEnableProgrammingMode(EnableProgrammingMode& command) { std::unique_ptr<Response> TargetControllerComponent::handleEnableProgrammingMode(EnableProgrammingMode&) {
if (!this->target->programmingModeEnabled()) { if (!this->target->programmingModeEnabled()) {
this->enableProgrammingMode(); this->enableProgrammingMode();
} }
@@ -1084,7 +1084,7 @@ namespace TargetController
return std::make_unique<Response>(); return std::make_unique<Response>();
} }
std::unique_ptr<Response> TargetControllerComponent::handleDisableProgrammingMode(DisableProgrammingMode& command) { std::unique_ptr<Response> TargetControllerComponent::handleDisableProgrammingMode(DisableProgrammingMode&) {
if (this->target->programmingModeEnabled()) { if (this->target->programmingModeEnabled()) {
this->disableProgrammingMode(); this->disableProgrammingMode();
} }

View File

@@ -39,8 +39,8 @@
#include "Commands/RemoveBreakpoint.hpp" #include "Commands/RemoveBreakpoint.hpp"
#include "Commands/SetTargetProgramCounter.hpp" #include "Commands/SetTargetProgramCounter.hpp"
#include "Commands/SetTargetStackPointer.hpp" #include "Commands/SetTargetStackPointer.hpp"
#include "Commands/GetTargetGpioPinStates.hpp" #include "Commands/GetTargetGpioPadStates.hpp"
#include "Commands/SetTargetGpioPinState.hpp" #include "Commands/SetTargetGpioPadState.hpp"
#include "Commands/GetTargetStackPointer.hpp" #include "Commands/GetTargetStackPointer.hpp"
#include "Commands/GetTargetProgramCounter.hpp" #include "Commands/GetTargetProgramCounter.hpp"
#include "Commands/EnableProgrammingMode.hpp" #include "Commands/EnableProgrammingMode.hpp"
@@ -53,7 +53,7 @@
#include "Responses/TargetState.hpp" #include "Responses/TargetState.hpp"
#include "Responses/TargetRegistersRead.hpp" #include "Responses/TargetRegistersRead.hpp"
#include "Responses/TargetMemoryRead.hpp" #include "Responses/TargetMemoryRead.hpp"
#include "Responses/TargetGpioPinStates.hpp" #include "Responses/TargetGpioPadStates.hpp"
#include "Responses/TargetStackPointer.hpp" #include "Responses/TargetStackPointer.hpp"
#include "Responses/TargetProgramCounter.hpp" #include "Responses/TargetProgramCounter.hpp"
#include "Responses/Breakpoint.hpp" #include "Responses/Breakpoint.hpp"
@@ -369,10 +369,10 @@ namespace TargetController
std::unique_ptr<Responses::Response> handleRemoveBreakpoint(Commands::RemoveBreakpoint& command); std::unique_ptr<Responses::Response> handleRemoveBreakpoint(Commands::RemoveBreakpoint& command);
std::unique_ptr<Responses::Response> handleSetProgramCounter(Commands::SetTargetProgramCounter& command); std::unique_ptr<Responses::Response> handleSetProgramCounter(Commands::SetTargetProgramCounter& command);
std::unique_ptr<Responses::Response> handleSetStackPointer(Commands::SetTargetStackPointer& command); std::unique_ptr<Responses::Response> handleSetStackPointer(Commands::SetTargetStackPointer& command);
std::unique_ptr<Responses::TargetGpioPinStates> handleGetTargetGpioPinStates( std::unique_ptr<Responses::TargetGpioPadStates> handleGetTargetGpioPadStates(
Commands::GetTargetGpioPinStates& command Commands::GetTargetGpioPadStates& command
); );
std::unique_ptr<Responses::Response> handleSetTargetGpioPinState(Commands::SetTargetGpioPinState& command); std::unique_ptr<Responses::Response> handleSetTargetGpioPadState(Commands::SetTargetGpioPadState& command);
std::unique_ptr<Responses::TargetStackPointer> handleGetTargetStackPointer( std::unique_ptr<Responses::TargetStackPointer> handleGetTargetStackPointer(
Commands::GetTargetStackPointer& command Commands::GetTargetStackPointer& command
); );

View File

@@ -9,6 +9,7 @@ target_sources(
${CMAKE_CURRENT_SOURCE_DIR}/TargetRegisterGroupDescriptor.cpp ${CMAKE_CURRENT_SOURCE_DIR}/TargetRegisterGroupDescriptor.cpp
${CMAKE_CURRENT_SOURCE_DIR}/TargetRegisterDescriptor.cpp ${CMAKE_CURRENT_SOURCE_DIR}/TargetRegisterDescriptor.cpp
${CMAKE_CURRENT_SOURCE_DIR}/TargetBitFieldDescriptor.cpp ${CMAKE_CURRENT_SOURCE_DIR}/TargetBitFieldDescriptor.cpp
${CMAKE_CURRENT_SOURCE_DIR}/TargetPadDescriptor.cpp
${CMAKE_CURRENT_SOURCE_DIR}/TargetPinoutDescriptor.cpp ${CMAKE_CURRENT_SOURCE_DIR}/TargetPinoutDescriptor.cpp
${CMAKE_CURRENT_SOURCE_DIR}/TargetPinDescriptor.cpp ${CMAKE_CURRENT_SOURCE_DIR}/TargetPinDescriptor.cpp
${CMAKE_CURRENT_SOURCE_DIR}/TargetVariantDescriptor.cpp ${CMAKE_CURRENT_SOURCE_DIR}/TargetVariantDescriptor.cpp

View File

@@ -7,6 +7,7 @@
#include <algorithm> #include <algorithm>
#include <optional> #include <optional>
#include <functional> #include <functional>
#include <unordered_map>
#include "IspParameters.hpp" #include "IspParameters.hpp"
@@ -33,7 +34,7 @@ namespace Targets::Microchip::Avr8
, family(this->targetDescriptionFile.getAvrFamily()) , family(this->targetDescriptionFile.getAvrFamily())
, physicalInterfaces(this->targetDescriptionFile.getPhysicalInterfaces()) , physicalInterfaces(this->targetDescriptionFile.getPhysicalInterfaces())
, gpioPortPeripheralDescriptors(this->targetDescriptionFile.gpioPortPeripheralDescriptors()) , gpioPortPeripheralDescriptors(this->targetDescriptionFile.gpioPortPeripheralDescriptors())
, gpioPadDescriptorsByPadName(Avr8::generateGpioPadDescriptorMapping(this->gpioPortPeripheralDescriptors)) , gpioPadDescriptorsByPadId(Avr8::generateGpioPadDescriptorMapping(this->gpioPortPeripheralDescriptors))
, fuseEnableStrategy(this->targetDescriptionFile.getFuseEnableStrategy().value_or(FuseEnableStrategy::CLEAR)) , fuseEnableStrategy(this->targetDescriptionFile.getFuseEnableStrategy().value_or(FuseEnableStrategy::CLEAR))
{ {
const auto cpuPeripheralDescriptor = this->targetDescriptionFile.getTargetPeripheralDescriptor("cpu"); const auto cpuPeripheralDescriptor = this->targetDescriptionFile.getTargetPeripheralDescriptor("cpu");
@@ -265,6 +266,7 @@ namespace Targets::Microchip::Avr8
this->targetDescriptionFile.tryGetVendorName().value_or("Microchip"), this->targetDescriptionFile.tryGetVendorName().value_or("Microchip"),
this->targetDescriptionFile.targetAddressSpaceDescriptorsByKey(), this->targetDescriptionFile.targetAddressSpaceDescriptorsByKey(),
this->targetDescriptionFile.targetPeripheralDescriptorsByKey(), this->targetDescriptionFile.targetPeripheralDescriptorsByKey(),
this->targetDescriptionFile.targetPadDescriptorsByKey(),
this->targetDescriptionFile.targetPinoutDescriptorsByKey(), this->targetDescriptionFile.targetPinoutDescriptorsByKey(),
this->targetDescriptionFile.targetVariantDescriptors(), this->targetDescriptionFile.targetVariantDescriptors(),
this->getBreakpointResources() this->getBreakpointResources()
@@ -558,11 +560,11 @@ namespace Targets::Microchip::Avr8
} }
} }
TargetGpioPinDescriptorAndStatePairs Avr8::getGpioPinStates(const TargetPinoutDescriptor& pinoutDescriptor) { TargetGpioPadDescriptorAndStatePairs Avr8::getGpioPadStates(const TargetPadDescriptors& padDescriptors) {
auto output = TargetGpioPinDescriptorAndStatePairs{}; auto output = TargetGpioPadDescriptorAndStatePairs{};
// To reduce the number of memory reads we perform here, we cache the data and map it by start address. // To reduce the number of memory reads we perform here, we cache the data and map it by start address.
auto cachedRegsByStartAddress = std::map<TargetMemoryAddress, unsigned char>{}; auto cachedRegsByStartAddress = std::unordered_map<TargetMemoryAddress, unsigned char>{};
const auto readGpioReg = [this, &cachedRegsByStartAddress] (const TargetRegisterDescriptor& descriptor) { const auto readGpioReg = [this, &cachedRegsByStartAddress] (const TargetRegisterDescriptor& descriptor) {
assert(descriptor.size == 1); assert(descriptor.size == 1);
@@ -577,33 +579,32 @@ namespace Targets::Microchip::Avr8
return cachedRegIt->second; return cachedRegIt->second;
}; };
for (const auto& pinDescriptor : pinoutDescriptor.pinDescriptors) { for (const auto* padDescriptor : padDescriptors) {
if (pinDescriptor.type != TargetPinType::GPIO) { if (padDescriptor->type != TargetPadType::GPIO) {
continue; continue;
} }
const auto padDescriptorIt = this->gpioPadDescriptorsByPadName.find(pinDescriptor.padName); const auto gpioPadDescriptorIt = this->gpioPadDescriptorsByPadId.find(padDescriptor->id);
if (padDescriptorIt == this->gpioPadDescriptorsByPadName.end()) { if (gpioPadDescriptorIt == this->gpioPadDescriptorsByPadId.end()) {
continue; continue;
} }
const auto& padDescriptor = padDescriptorIt->second; const auto& gpioPadDescriptor = gpioPadDescriptorIt->second;
const auto ddrValue = ( const auto ddrValue = (
readGpioReg(padDescriptor.dataDirectionRegisterDescriptor) & padDescriptor.registerMask readGpioReg(gpioPadDescriptor.dataDirectionRegisterDescriptor) & gpioPadDescriptor.registerMask
) != 0 ? TargetGpioPinState::DataDirection::OUTPUT : TargetGpioPinState::DataDirection::INPUT; ) != 0 ? TargetGpioPadState::DataDirection::OUTPUT : TargetGpioPadState::DataDirection::INPUT;
const auto& stateRegisterDescriptor = ddrValue == TargetGpioPinState::DataDirection::OUTPUT const auto& stateRegisterDescriptor = ddrValue == TargetGpioPadState::DataDirection::OUTPUT
? padDescriptor.outputRegisterDescriptor ? gpioPadDescriptor.outputRegisterDescriptor
: padDescriptor.inputRegisterDescriptor; : gpioPadDescriptor.inputRegisterDescriptor;
output.emplace_back( output.emplace_back(
TargetGpioPinDescriptorAndStatePair{ TargetGpioPadDescriptorAndStatePair{
pinDescriptor, *padDescriptor,
TargetGpioPinState{ TargetGpioPadState{
(readGpioReg(stateRegisterDescriptor) & padDescriptor.registerMask) != 0 (readGpioReg(stateRegisterDescriptor) & gpioPadDescriptor.registerMask) != 0
? TargetGpioPinState::State::HIGH ? TargetGpioPadState::State::HIGH
: TargetGpioPinState::State::LOW, : TargetGpioPadState::State::LOW,
ddrValue ddrValue
} }
} }
@@ -613,39 +614,38 @@ namespace Targets::Microchip::Avr8
return output; return output;
} }
void Avr8::setGpioPinState(const TargetPinDescriptor& pinDescriptor, const TargetGpioPinState& state) { void Avr8::setGpioPadState(const TargetPadDescriptor& padDescriptor, const TargetGpioPadState& state) {
using DataDirection = TargetGpioPinState::DataDirection; using DataDirection = TargetGpioPadState::DataDirection;
using GpioState = TargetGpioPinState::State; using GpioState = TargetGpioPadState::State;
const auto padDescriptorIt = this->gpioPadDescriptorsByPadName.find(pinDescriptor.padName); const auto gpioPadDescriptorIt = this->gpioPadDescriptorsByPadId.find(padDescriptor.id);
if (gpioPadDescriptorIt == this->gpioPadDescriptorsByPadId.end()) {
if (padDescriptorIt == this->gpioPadDescriptorsByPadName.end()) {
throw Exception{"Unknown pad"}; throw Exception{"Unknown pad"};
} }
const auto& padDescriptor = padDescriptorIt->second; const auto& gpioPadDescriptor = gpioPadDescriptorIt->second;
const auto currentDdrValue = this->readRegister(padDescriptor.dataDirectionRegisterDescriptor).at(0); const auto currentDdrValue = this->readRegister(gpioPadDescriptor.dataDirectionRegisterDescriptor).at(0);
this->writeRegister( this->writeRegister(
padDescriptor.dataDirectionRegisterDescriptor, gpioPadDescriptor.dataDirectionRegisterDescriptor,
{ {
static_cast<unsigned char>( static_cast<unsigned char>(
state.direction == DataDirection::OUTPUT state.direction == DataDirection::OUTPUT
? (currentDdrValue | padDescriptor.registerMask) ? (currentDdrValue | gpioPadDescriptor.registerMask)
: (currentDdrValue & ~(padDescriptor.registerMask)) : (currentDdrValue & ~(gpioPadDescriptor.registerMask))
) )
} }
); );
if (state.direction == DataDirection::OUTPUT) { if (state.direction == DataDirection::OUTPUT) {
const auto currentOutputValue = this->readRegister(padDescriptor.outputRegisterDescriptor).at(0); const auto currentOutputValue = this->readRegister(gpioPadDescriptor.outputRegisterDescriptor).at(0);
this->writeRegister( this->writeRegister(
padDescriptor.outputRegisterDescriptor, gpioPadDescriptor.outputRegisterDescriptor,
{ {
static_cast<unsigned char>( static_cast<unsigned char>(
state.value == GpioState::HIGH state.value == GpioState::HIGH
? (currentOutputValue | padDescriptor.registerMask) ? (currentOutputValue | gpioPadDescriptor.registerMask)
: (currentOutputValue & ~(padDescriptor.registerMask)) : (currentOutputValue & ~(gpioPadDescriptor.registerMask))
) )
} }
); );
@@ -679,22 +679,22 @@ namespace Targets::Microchip::Avr8
return this->activeProgrammingSession.has_value(); return this->activeProgrammingSession.has_value();
} }
std::map<std::string, GpioPadDescriptor> Avr8::generateGpioPadDescriptorMapping( std::map<TargetPadId, GpioPadDescriptor> Avr8::generateGpioPadDescriptorMapping(
const std::vector<TargetPeripheralDescriptor>& portPeripheralDescriptors const std::vector<TargetPeripheralDescriptor>& portPeripheralDescriptors
) { ) {
auto output = std::map<std::string, GpioPadDescriptor>{}; auto output = std::map<TargetPadId, GpioPadDescriptor>{};
for (const auto& peripheralDescriptor : portPeripheralDescriptors) { for (const auto& peripheralDescriptor : portPeripheralDescriptors) {
if (peripheralDescriptor.registerGroupDescriptorsByKey.empty()) {
continue;
}
for (const auto& signalDescriptor : peripheralDescriptor.signalDescriptors) { for (const auto& signalDescriptor : peripheralDescriptor.signalDescriptors) {
if (!signalDescriptor.index.has_value()) { if (!signalDescriptor.index.has_value()) {
continue; continue;
} }
if (output.contains(signalDescriptor.padName)) { if (output.contains(signalDescriptor.padId)) {
continue;
}
if (peripheralDescriptor.registerGroupDescriptorsByKey.empty()) {
continue; continue;
} }
@@ -712,8 +712,9 @@ namespace Targets::Microchip::Avr8
// From a register layout perspective, there are two types of GPIO port modules on AVR8 targets. // From a register layout perspective, there are two types of GPIO port modules on AVR8 targets.
if (portRegisterGroup.registerDescriptorsByKey.contains("outset")) { if (portRegisterGroup.registerDescriptorsByKey.contains("outset")) {
output.emplace( output.emplace(
signalDescriptor.padName, signalDescriptor.padId,
GpioPadDescriptor{ GpioPadDescriptor{
signalDescriptor.padKey,
registerMask, registerMask,
portRegisterGroup.getRegisterDescriptor("dir"), portRegisterGroup.getRegisterDescriptor("dir"),
portRegisterGroup.getRegisterDescriptor("in"), portRegisterGroup.getRegisterDescriptor("in"),
@@ -752,8 +753,9 @@ namespace Targets::Microchip::Avr8
if (ddrDescriptor.has_value() && inputDescriptor.has_value() && outputDescriptor.has_value()) { if (ddrDescriptor.has_value() && inputDescriptor.has_value() && outputDescriptor.has_value()) {
output.emplace( output.emplace(
signalDescriptor.padName, signalDescriptor.padId,
GpioPadDescriptor{ GpioPadDescriptor{
signalDescriptor.padKey,
registerMask, registerMask,
ddrDescriptor->get(), ddrDescriptor->get(),
inputDescriptor->get(), inputDescriptor->get(),

View File

@@ -20,6 +20,7 @@
#include "src/Targets/TargetPhysicalInterface.hpp" #include "src/Targets/TargetPhysicalInterface.hpp"
#include "src/Targets/TargetRegisterDescriptor.hpp" #include "src/Targets/TargetRegisterDescriptor.hpp"
#include "src/Targets/TargetBitFieldDescriptor.hpp" #include "src/Targets/TargetBitFieldDescriptor.hpp"
#include "src/Targets/TargetPadDescriptor.hpp"
#include "src/Targets/TargetBreakpoint.hpp" #include "src/Targets/TargetBreakpoint.hpp"
#include "TargetDescriptionFile.hpp" #include "TargetDescriptionFile.hpp"
@@ -104,8 +105,8 @@ namespace Targets::Microchip::Avr8
TargetStackPointer getStackPointer() override; TargetStackPointer getStackPointer() override;
void setStackPointer(TargetStackPointer stackPointer) override; void setStackPointer(TargetStackPointer stackPointer) override;
TargetGpioPinDescriptorAndStatePairs getGpioPinStates(const TargetPinoutDescriptor& pinoutDescriptor) override; TargetGpioPadDescriptorAndStatePairs getGpioPadStates(const TargetPadDescriptors& padDescriptors) override;
void setGpioPinState(const TargetPinDescriptor& pinDescriptor, const TargetGpioPinState& state) override; void setGpioPadState(const TargetPadDescriptor& padDescriptor, const TargetGpioPadState& state) override;
void enableProgrammingMode() override; void enableProgrammingMode() override;
@@ -136,7 +137,7 @@ namespace Targets::Microchip::Avr8
std::set<TargetPhysicalInterface> physicalInterfaces; std::set<TargetPhysicalInterface> physicalInterfaces;
std::vector<TargetPeripheralDescriptor> gpioPortPeripheralDescriptors; std::vector<TargetPeripheralDescriptor> gpioPortPeripheralDescriptors;
std::map<std::string, GpioPadDescriptor> gpioPadDescriptorsByPadName; std::map<TargetPadId, GpioPadDescriptor> gpioPadDescriptorsByPadId;
/** /**
* The stack pointer register on AVR8 targets can take several forms: * The stack pointer register on AVR8 targets can take several forms:
@@ -163,7 +164,7 @@ namespace Targets::Microchip::Avr8
std::optional<ProgrammingSession> activeProgrammingSession = std::nullopt; std::optional<ProgrammingSession> activeProgrammingSession = std::nullopt;
static std::map<std::string, GpioPadDescriptor> generateGpioPadDescriptorMapping( static std::map<TargetPadId, GpioPadDescriptor> generateGpioPadDescriptorMapping(
const std::vector<TargetPeripheralDescriptor>& portPeripheralDescriptors const std::vector<TargetPeripheralDescriptor>& portPeripheralDescriptors
); );

View File

@@ -2,6 +2,7 @@
#include <cstdint> #include <cstdint>
#include "src/Targets/TargetPadDescriptor.hpp"
#include "src/Targets/TargetRegisterDescriptor.hpp" #include "src/Targets/TargetRegisterDescriptor.hpp"
namespace Targets::Microchip::Avr8 namespace Targets::Microchip::Avr8
@@ -13,6 +14,8 @@ namespace Targets::Microchip::Avr8
*/ */
struct GpioPadDescriptor struct GpioPadDescriptor
{ {
const TargetPadId padId;
const std::string padKey;
std::uint8_t registerMask; std::uint8_t registerMask;
const TargetRegisterDescriptor& dataDirectionRegisterDescriptor; const TargetRegisterDescriptor& dataDirectionRegisterDescriptor;
@@ -20,12 +23,15 @@ namespace Targets::Microchip::Avr8
const TargetRegisterDescriptor& outputRegisterDescriptor; const TargetRegisterDescriptor& outputRegisterDescriptor;
GpioPadDescriptor( GpioPadDescriptor(
const std::string& padKey,
std::uint8_t registerMask, std::uint8_t registerMask,
const TargetRegisterDescriptor& dataDirectionRegisterDescriptor, const TargetRegisterDescriptor& dataDirectionRegisterDescriptor,
const TargetRegisterDescriptor& inputRegisterDescriptor, const TargetRegisterDescriptor& inputRegisterDescriptor,
const TargetRegisterDescriptor& outputRegisterDescriptor const TargetRegisterDescriptor& outputRegisterDescriptor
) )
: registerMask(registerMask) : padId(TargetPadDescriptor::generateId(padKey))
, padKey(padKey)
, registerMask(registerMask)
, dataDirectionRegisterDescriptor(dataDirectionRegisterDescriptor) , dataDirectionRegisterDescriptor(dataDirectionRegisterDescriptor)
, inputRegisterDescriptor(inputRegisterDescriptor) , inputRegisterDescriptor(inputRegisterDescriptor)
, outputRegisterDescriptor(outputRegisterDescriptor) , outputRegisterDescriptor(outputRegisterDescriptor)

View File

@@ -89,6 +89,7 @@ namespace Targets::RiscV
this->targetDescriptionFile.getVendorName(), this->targetDescriptionFile.getVendorName(),
this->targetDescriptionFile.targetAddressSpaceDescriptorsByKey(), this->targetDescriptionFile.targetAddressSpaceDescriptorsByKey(),
this->targetDescriptionFile.targetPeripheralDescriptorsByKey(), this->targetDescriptionFile.targetPeripheralDescriptorsByKey(),
this->targetDescriptionFile.targetPadDescriptorsByKey(),
this->targetDescriptionFile.targetPinoutDescriptorsByKey(), this->targetDescriptionFile.targetPinoutDescriptorsByKey(),
this->targetDescriptionFile.targetVariantDescriptors(), this->targetDescriptionFile.targetVariantDescriptors(),
{} // TODO: populate this {} // TODO: populate this
@@ -356,11 +357,11 @@ namespace Targets::RiscV
}); });
} }
TargetGpioPinDescriptorAndStatePairs RiscV::getGpioPinStates(const TargetPinoutDescriptor& pinoutDescriptor) { TargetGpioPadDescriptorAndStatePairs RiscV::getGpioPadStates(const TargetPadDescriptors& padDescriptors) {
return {}; return {};
} }
void RiscV::setGpioPinState(const TargetPinDescriptor& pinDescriptor, const TargetGpioPinState& state) { void RiscV::setGpioPadState(const TargetPadDescriptor& padDescriptor, const TargetGpioPadState& state) {
} }

View File

@@ -85,10 +85,8 @@ namespace Targets::RiscV
TargetStackPointer getStackPointer() override; TargetStackPointer getStackPointer() override;
void setStackPointer(TargetStackPointer stackPointer) override; void setStackPointer(TargetStackPointer stackPointer) override;
TargetGpioPinDescriptorAndStatePairs getGpioPinStates( TargetGpioPadDescriptorAndStatePairs getGpioPadStates(const TargetPadDescriptors& padDescriptors) override;
const TargetPinoutDescriptor& pinoutDescriptor void setGpioPadState(const TargetPadDescriptor& padDescriptor, const TargetGpioPadState& state) override;
) override;
void setGpioPinState(const TargetPinDescriptor& pinDescriptor, const TargetGpioPinState& state) override;
void enableProgrammingMode() override; void enableProgrammingMode() override;

View File

@@ -16,9 +16,8 @@
#include "TargetRegisterDescriptor.hpp" #include "TargetRegisterDescriptor.hpp"
#include "TargetMemory.hpp" #include "TargetMemory.hpp"
#include "TargetBreakpoint.hpp" #include "TargetBreakpoint.hpp"
#include "TargetPinoutDescriptor.hpp" #include "TargetPadDescriptor.hpp"
#include "TargetPinDescriptor.hpp" #include "TargetGpioPadState.hpp"
#include "TargetGpioPinState.hpp"
#include "src/DebugToolDrivers/DebugTool.hpp" #include "src/DebugToolDrivers/DebugTool.hpp"
@@ -266,23 +265,19 @@ namespace Targets
virtual void setStackPointer(TargetStackPointer stackPointer) = 0; virtual void setStackPointer(TargetStackPointer stackPointer) = 0;
/** /**
* Should get the current state of each GPIO pin on the target * Should get the current state of the given GPIO pads.
*
* @param pinoutDescriptor
* *
* @return * @return
*/ */
virtual TargetGpioPinDescriptorAndStatePairs getGpioPinStates( virtual TargetGpioPadDescriptorAndStatePairs getGpioPadStates(const TargetPadDescriptors& padDescriptors) = 0;
const TargetPinoutDescriptor& pinoutDescriptor
) = 0;
/** /**
* Should update the pin state for the given GPIO pin, with the given state. * Should update the state for the given GPIO pad, with the given state.
* *
* @param pinDescriptor * @param padDescriptor
* @param state * @param state
*/ */
virtual void setGpioPinState(const TargetPinDescriptor& pinDescriptor, const TargetGpioPinState& state) = 0; virtual void setGpioPadState(const TargetPadDescriptor& padDescriptor, const TargetGpioPadState& state) = 0;
/** /**
* Should prepare the target for programming. * Should prepare the target for programming.

View File

@@ -0,0 +1,20 @@
#pragma once
#include <string>
namespace Targets::TargetDescription
{
struct Pad
{
std::string key;
std::string name;
Pad(
const std::string& key,
const std::string& name
)
: key(key)
, name(name)
{}
};
}

View File

@@ -1,20 +1,21 @@
#pragma once #pragma once
#include <string> #include <string>
#include <optional>
namespace Targets::TargetDescription namespace Targets::TargetDescription
{ {
struct Pin struct Pin
{ {
std::string position; std::string position;
std::string pad; std::optional<std::string> padKey;
Pin( Pin(
const std::string& position, const std::string& position,
const std::string& pad const std::optional<std::string>& padKey
) )
: position(position) : position(position)
, pad(pad) , padKey(padKey)
{} {}
}; };
} }

View File

@@ -8,20 +8,20 @@ namespace Targets::TargetDescription
{ {
struct Signal struct Signal
{ {
std::string padId; std::string padKey;
std::optional<std::uint16_t> index; std::optional<std::uint16_t> index;
std::optional<std::string> function; std::optional<std::string> function;
std::optional<std::string> group; std::optional<std::string> group;
std::optional<std::string> field; std::optional<std::string> field;
Signal( Signal(
const std::string& padId, const std::string& padKey,
const std::optional<std::uint16_t>& index, const std::optional<std::uint16_t>& index,
const std::optional<std::string>& function, const std::optional<std::string>& function,
const std::optional<std::string>& group, const std::optional<std::string>& group,
const std::optional<std::string>& field const std::optional<std::string>& field
) )
: padId(padId) : padKey(padKey)
, index(index) , index(index)
, function(function) , function(function)
, group(group) , group(group)

View File

@@ -219,6 +219,22 @@ namespace Targets::TargetDescription
return peripheral->get(); return peripheral->get();
} }
std::set<const Peripheral*> TargetDescriptionFile::getModulePeripherals(const std::string& moduleKey) const {
auto output = std::set<const Peripheral*>{};
for (const auto& [peripheralKey, peripheral] : this->peripheralsByKey) {
if (peripheral.moduleKey == moduleKey) {
output.insert(&peripheral);
}
}
return output;
}
std::set<const Peripheral*> TargetDescriptionFile::getGpioPeripherals() const {
return this->getModulePeripherals("gpio_port");
}
std::optional<TargetMemorySegmentDescriptor> TargetDescriptionFile::tryGetTargetMemorySegmentDescriptor( std::optional<TargetMemorySegmentDescriptor> TargetDescriptionFile::tryGetTargetMemorySegmentDescriptor(
std::string_view addressSpaceKey, std::string_view addressSpaceKey,
std::string_view segmentKey std::string_view segmentKey
@@ -305,6 +321,20 @@ namespace Targets::TargetDescription
return output; return output;
} }
std::map<std::string, TargetPadDescriptor> TargetDescriptionFile::targetPadDescriptorsByKey() const {
auto output = std::map<std::string, TargetPadDescriptor>{};
const auto gpioPadKeys = this->getGpioPadKeys();
for (const auto& [key, pad] : this->padsByKey) {
output.emplace(
key,
TargetDescriptionFile::targetPadDescriptorFromPad(pad, gpioPadKeys)
);
}
return output;
}
std::map<std::string, TargetPinoutDescriptor> TargetDescriptionFile::targetPinoutDescriptorsByKey() const { std::map<std::string, TargetPinoutDescriptor> TargetDescriptionFile::targetPinoutDescriptorsByKey() const {
auto output = std::map<std::string, TargetPinoutDescriptor>{}; auto output = std::map<std::string, TargetPinoutDescriptor>{};
@@ -421,6 +451,15 @@ namespace Targets::TargetDescription
this->peripheralsByKey.emplace(peripheral.key, std::move(peripheral)); this->peripheralsByKey.emplace(peripheral.key, std::move(peripheral));
} }
for (
auto element = deviceElement.firstChildElement("pads").firstChildElement("pad");
!element.isNull();
element = element.nextSiblingElement("pad")
) {
auto pad = TargetDescriptionFile::padFromXml(element);
this->padsByKey.emplace(pad.key, std::move(pad));
}
for ( for (
auto element = deviceElement.firstChildElement("pinouts").firstChildElement("pinout"); auto element = deviceElement.firstChildElement("pinouts").firstChildElement("pinout");
!element.isNull(); !element.isNull();
@@ -461,6 +500,17 @@ namespace Targets::TargetDescription
return attribute->get(); return attribute->get();
} }
std::set<std::string> TargetDescriptionFile::getGpioPadKeys() const {
auto output = std::set<std::string>{};
for (const auto* peripheral : this->getGpioPeripherals()) {
for (const auto& signal : peripheral->sigs) {
output.insert(signal.padKey);
}
}
return output;
}
std::optional<std::string> TargetDescriptionFile::tryGetAttribute( std::optional<std::string> TargetDescriptionFile::tryGetAttribute(
const QDomElement& element, const QDomElement& element,
const QString& attributeName const QString& attributeName
@@ -806,7 +856,7 @@ namespace Targets::TargetDescription
const auto index = TargetDescriptionFile::tryGetAttribute(xmlElement, "index"); const auto index = TargetDescriptionFile::tryGetAttribute(xmlElement, "index");
return { return {
TargetDescriptionFile::getAttribute(xmlElement, "pad-id"), TargetDescriptionFile::getAttribute(xmlElement, "pad-key"),
index.has_value() ? std::optional{StringService::toUint64(*index)} : std::nullopt, index.has_value() ? std::optional{StringService::toUint64(*index)} : std::nullopt,
TargetDescriptionFile::tryGetAttribute(xmlElement, "function"), TargetDescriptionFile::tryGetAttribute(xmlElement, "function"),
TargetDescriptionFile::tryGetAttribute(xmlElement, "group"), TargetDescriptionFile::tryGetAttribute(xmlElement, "group"),
@@ -814,6 +864,13 @@ namespace Targets::TargetDescription
}; };
} }
Pad TargetDescriptionFile::padFromXml(const QDomElement& xmlElement) {
return {
TargetDescriptionFile::getAttribute(xmlElement, "key"),
TargetDescriptionFile::getAttribute(xmlElement, "name")
};
}
Pinout TargetDescriptionFile::pinoutFromXml(const QDomElement& xmlElement) { Pinout TargetDescriptionFile::pinoutFromXml(const QDomElement& xmlElement) {
static const auto typesByName = BiMap<std::string, TargetPinoutType>{ static const auto typesByName = BiMap<std::string, TargetPinoutType>{
{"soic", TargetPinoutType::SOIC}, {"soic", TargetPinoutType::SOIC},
@@ -857,15 +914,14 @@ namespace Targets::TargetDescription
Pin TargetDescriptionFile::pinFromXml(const QDomElement& xmlElement) { Pin TargetDescriptionFile::pinFromXml(const QDomElement& xmlElement) {
return { return {
TargetDescriptionFile::getAttribute(xmlElement, "position"), TargetDescriptionFile::getAttribute(xmlElement, "position"),
TargetDescriptionFile::getAttribute(xmlElement, "pad") TargetDescriptionFile::tryGetAttribute(xmlElement, "pad-key")
}; };
} }
Variant TargetDescriptionFile::variantFromXml(const QDomElement& xmlElement) { Variant TargetDescriptionFile::variantFromXml(const QDomElement& xmlElement) {
return { return {
TargetDescriptionFile::getAttribute(xmlElement, "name"), TargetDescriptionFile::getAttribute(xmlElement, "name"),
TargetDescriptionFile::getAttribute(xmlElement, "pinout-key"), TargetDescriptionFile::getAttribute(xmlElement, "pinout-key")
TargetDescriptionFile::getAttribute(xmlElement, "package")
}; };
} }
@@ -954,7 +1010,7 @@ namespace Targets::TargetDescription
const Signal& signal const Signal& signal
) { ) {
return { return {
signal.padId, signal.padKey,
signal.index signal.index
}; };
} }
@@ -1075,6 +1131,41 @@ namespace Targets::TargetDescription
}; };
} }
TargetPadDescriptor TargetDescriptionFile::targetPadDescriptorFromPad(
const Pad& pad,
const std::set<std::string>& gpioPadKeys
) {
static const auto resolvePadType = [&gpioPadKeys] (const Pad& pad) -> TargetPadType {
if (gpioPadKeys.contains(pad.key)) {
return TargetPadType::GPIO;
}
const auto padNameLower = StringService::asciiToLower(pad.name);
if (
padNameLower.find("vcc") == 0
|| padNameLower.find("avcc") == 0
|| padNameLower.find("aref") == 0
|| padNameLower.find("avdd") == 0
|| padNameLower.find("vdd") == 0
) {
return TargetPadType::VCC;
}
if (padNameLower.find("gnd") == 0 || padNameLower.find("agnd") == 0) {
return TargetPadType::GND;
}
return TargetPadType::OTHER;
};
return {
pad.key,
pad.name,
resolvePadType(pad)
};
}
TargetPinoutDescriptor TargetDescriptionFile::targetPinoutDescriptorFromPinout(const Pinout& pinout) { TargetPinoutDescriptor TargetDescriptionFile::targetPinoutDescriptorFromPinout(const Pinout& pinout) {
auto output = TargetPinoutDescriptor{ auto output = TargetPinoutDescriptor{
pinout.key, pinout.key,
@@ -1091,30 +1182,9 @@ namespace Targets::TargetDescription
} }
TargetPinDescriptor TargetDescriptionFile::targetPinDescriptorFromPin(const Pin& pin) { TargetPinDescriptor TargetDescriptionFile::targetPinDescriptorFromPin(const Pin& pin) {
static const auto resolvePinType = [] (const std::string& pad) -> TargetPinType {
const auto padLower = StringService::asciiToLower(pad);
if (
padLower.find("vcc") == 0
|| padLower.find("avcc") == 0
|| padLower.find("aref") == 0
|| padLower.find("avdd") == 0
|| padLower.find("vdd") == 0
) {
return TargetPinType::VCC;
}
if (padLower.find("gnd") == 0) {
return TargetPinType::GND;
}
return TargetPinType::OTHER;
};
return { return {
pin.pad,
pin.position, pin.position,
resolvePinType(pin.pad) pin.padKey
}; };
} }

View File

@@ -7,6 +7,7 @@
#include <functional> #include <functional>
#include <map> #include <map>
#include <vector> #include <vector>
#include <set>
#include "PropertyGroup.hpp" #include "PropertyGroup.hpp"
#include "AddressSpace.hpp" #include "AddressSpace.hpp"
@@ -19,6 +20,7 @@
#include "RegisterGroupReference.hpp" #include "RegisterGroupReference.hpp"
#include "Peripheral.hpp" #include "Peripheral.hpp"
#include "RegisterGroupInstance.hpp" #include "RegisterGroupInstance.hpp"
#include "Pad.hpp"
#include "Signal.hpp" #include "Signal.hpp"
#include "Pinout.hpp" #include "Pinout.hpp"
#include "Pin.hpp" #include "Pin.hpp"
@@ -129,6 +131,9 @@ namespace Targets::TargetDescription
std::string_view key std::string_view key
) const; ) const;
[[nodiscard]] const Peripheral& getPeripheral(std::string_view key) const; [[nodiscard]] const Peripheral& getPeripheral(std::string_view key) const;
[[nodiscard]] std::set<const Peripheral*> getModulePeripherals(const std::string& moduleKey) const;
[[nodiscard]] std::set<const Peripheral*> getGpioPeripherals() const;
[[nodiscard]] std::optional<TargetMemorySegmentDescriptor> tryGetTargetMemorySegmentDescriptor( [[nodiscard]] std::optional<TargetMemorySegmentDescriptor> tryGetTargetMemorySegmentDescriptor(
std::string_view addressSpaceKey, std::string_view addressSpaceKey,
@@ -146,6 +151,7 @@ namespace Targets::TargetDescription
[[nodiscard]] std::map<std::string, TargetAddressSpaceDescriptor> targetAddressSpaceDescriptorsByKey() const; [[nodiscard]] std::map<std::string, TargetAddressSpaceDescriptor> targetAddressSpaceDescriptorsByKey() const;
[[nodiscard]] std::map<std::string, TargetPeripheralDescriptor> targetPeripheralDescriptorsByKey() const; [[nodiscard]] std::map<std::string, TargetPeripheralDescriptor> targetPeripheralDescriptorsByKey() const;
[[nodiscard]] std::map<std::string, TargetPadDescriptor> targetPadDescriptorsByKey() const;
[[nodiscard]] std::map<std::string, TargetPinoutDescriptor> targetPinoutDescriptorsByKey() const; [[nodiscard]] std::map<std::string, TargetPinoutDescriptor> targetPinoutDescriptorsByKey() const;
[[nodiscard]] std::vector<TargetVariantDescriptor> targetVariantDescriptors() const; [[nodiscard]] std::vector<TargetVariantDescriptor> targetVariantDescriptors() const;
[[nodiscard]] std::vector<TargetPeripheralDescriptor> gpioPortPeripheralDescriptors() const; [[nodiscard]] std::vector<TargetPeripheralDescriptor> gpioPortPeripheralDescriptors() const;
@@ -157,6 +163,7 @@ namespace Targets::TargetDescription
std::vector<PhysicalInterface> physicalInterfaces; std::vector<PhysicalInterface> physicalInterfaces;
std::map<std::string, Module, std::less<void>> modulesByKey; std::map<std::string, Module, std::less<void>> modulesByKey;
std::map<std::string, Peripheral, std::less<void>> peripheralsByKey; std::map<std::string, Peripheral, std::less<void>> peripheralsByKey;
std::map<std::string, Pad, std::less<void>> padsByKey;
std::map<std::string, Pinout, std::less<void>> pinoutsByKey; std::map<std::string, Pinout, std::less<void>> pinoutsByKey;
std::vector<Variant> variants; std::vector<Variant> variants;
@@ -177,6 +184,8 @@ namespace Targets::TargetDescription
) const; ) const;
const std::string& getDeviceAttribute(const std::string& attributeName) const; const std::string& getDeviceAttribute(const std::string& attributeName) const;
[[nodiscard]] std::set<std::string> getGpioPadKeys() const;
static std::optional<std::string> tryGetAttribute(const QDomElement& element, const QString& attributeName); static std::optional<std::string> tryGetAttribute(const QDomElement& element, const QString& attributeName);
static std::string getAttribute(const QDomElement& element, const QString& attributeName); static std::string getAttribute(const QDomElement& element, const QString& attributeName);
@@ -194,6 +203,7 @@ namespace Targets::TargetDescription
static Peripheral peripheralFromXml(const QDomElement& xmlElement); static Peripheral peripheralFromXml(const QDomElement& xmlElement);
static RegisterGroupInstance registerGroupInstanceFromXml(const QDomElement& xmlElement); static RegisterGroupInstance registerGroupInstanceFromXml(const QDomElement& xmlElement);
static Signal signalFromXml(const QDomElement& xmlElement); static Signal signalFromXml(const QDomElement& xmlElement);
static Pad padFromXml(const QDomElement& xmlElement);
static Pinout pinoutFromXml(const QDomElement& xmlElement); static Pinout pinoutFromXml(const QDomElement& xmlElement);
static Pin pinFromXml(const QDomElement& xmlElement); static Pin pinFromXml(const QDomElement& xmlElement);
static Variant variantFromXml(const QDomElement& xmlElement); static Variant variantFromXml(const QDomElement& xmlElement);
@@ -236,6 +246,11 @@ namespace Targets::TargetDescription
static TargetBitFieldDescriptor targetBitFieldDescriptorFromBitField(const BitField& bitField); static TargetBitFieldDescriptor targetBitFieldDescriptorFromBitField(const BitField& bitField);
static TargetPadDescriptor targetPadDescriptorFromPad(
const Pad& pad,
const std::set<std::string>& gpioPadKeys
);
static TargetPinoutDescriptor targetPinoutDescriptorFromPinout(const Pinout& pinout); static TargetPinoutDescriptor targetPinoutDescriptorFromPinout(const Pinout& pinout);
static TargetPinDescriptor targetPinDescriptorFromPin(const Pin& pin); static TargetPinDescriptor targetPinDescriptorFromPin(const Pin& pin);

View File

@@ -8,16 +8,13 @@ namespace Targets::TargetDescription
{ {
std::string name; std::string name;
std::string pinoutKey; std::string pinoutKey;
std::string package;
Variant( Variant(
const std::string& name, const std::string& name,
const std::string& pinoutKey, const std::string& pinoutKey
const std::string& package
) )
: name(name) : name(name)
, pinoutKey(pinoutKey) , pinoutKey(pinoutKey)
, package(package)
{} {}
}; };
} }

View File

@@ -13,6 +13,7 @@ namespace Targets
const std::string& vendorName, const std::string& vendorName,
std::map<std::string, TargetAddressSpaceDescriptor>&& addressSpaceDescriptorsByKey, std::map<std::string, TargetAddressSpaceDescriptor>&& addressSpaceDescriptorsByKey,
std::map<std::string, TargetPeripheralDescriptor>&& peripheralDescriptorsByKey, std::map<std::string, TargetPeripheralDescriptor>&& peripheralDescriptorsByKey,
std::map<std::string, TargetPadDescriptor>&& padDescriptorsByKey,
std::map<std::string, TargetPinoutDescriptor>&& pinoutDescriptorsByKey, std::map<std::string, TargetPinoutDescriptor>&& pinoutDescriptorsByKey,
std::vector<TargetVariantDescriptor>&& variantDescriptors, std::vector<TargetVariantDescriptor>&& variantDescriptors,
const BreakpointResources& breakpointResources const BreakpointResources& breakpointResources
@@ -23,6 +24,7 @@ namespace Targets
, vendorName(vendorName) , vendorName(vendorName)
, addressSpaceDescriptorsByKey(std::move(addressSpaceDescriptorsByKey)) , addressSpaceDescriptorsByKey(std::move(addressSpaceDescriptorsByKey))
, peripheralDescriptorsByKey(std::move(peripheralDescriptorsByKey)) , peripheralDescriptorsByKey(std::move(peripheralDescriptorsByKey))
, padDescriptorsByKey(std::move(padDescriptorsByKey))
, pinoutDescriptorsByKey(std::move(pinoutDescriptorsByKey)) , pinoutDescriptorsByKey(std::move(pinoutDescriptorsByKey))
, variantDescriptors(std::move(variantDescriptors)) , variantDescriptors(std::move(variantDescriptors))
, breakpointResources(breakpointResources) , breakpointResources(breakpointResources)
@@ -92,6 +94,30 @@ namespace Targets
return descriptor->get(); return descriptor->get();
} }
std::optional<
std::reference_wrapper<const TargetPadDescriptor>
> TargetDescriptor::tryGetPadDescriptor(const std::string& key) const {
const auto descriptorIt = this->padDescriptorsByKey.find(key);
if (descriptorIt == this->padDescriptorsByKey.end()) {
return std::nullopt;
}
return std::cref(descriptorIt->second);
}
const TargetPadDescriptor& TargetDescriptor::getPadDescriptor(const std::string& key) const {
const auto descriptor = this->tryGetPadDescriptor(key);
if (!descriptor.has_value()) {
throw Exceptions::InternalFatalErrorException{
"Failed to get pad descriptor \"" + std::string{key}
+ "\" from target descriptor - descriptor not found"
};
}
return descriptor->get();
}
std::optional< std::optional<
std::reference_wrapper<const TargetPinoutDescriptor> std::reference_wrapper<const TargetPinoutDescriptor>
> TargetDescriptor::tryGetPinoutDescriptor(const std::string& key) const { > TargetDescriptor::tryGetPinoutDescriptor(const std::string& key) const {

View File

@@ -11,6 +11,7 @@
#include "TargetMemory.hpp" #include "TargetMemory.hpp"
#include "TargetAddressSpaceDescriptor.hpp" #include "TargetAddressSpaceDescriptor.hpp"
#include "TargetPeripheralDescriptor.hpp" #include "TargetPeripheralDescriptor.hpp"
#include "TargetPadDescriptor.hpp"
#include "TargetPinoutDescriptor.hpp" #include "TargetPinoutDescriptor.hpp"
#include "TargetVariantDescriptor.hpp" #include "TargetVariantDescriptor.hpp"
#include "TargetBreakpoint.hpp" #include "TargetBreakpoint.hpp"
@@ -25,6 +26,7 @@ namespace Targets
std::string vendorName; std::string vendorName;
std::map<std::string, TargetAddressSpaceDescriptor> addressSpaceDescriptorsByKey; std::map<std::string, TargetAddressSpaceDescriptor> addressSpaceDescriptorsByKey;
std::map<std::string, TargetPeripheralDescriptor> peripheralDescriptorsByKey; std::map<std::string, TargetPeripheralDescriptor> peripheralDescriptorsByKey;
std::map<std::string, TargetPadDescriptor> padDescriptorsByKey;
std::map<std::string, TargetPinoutDescriptor> pinoutDescriptorsByKey; std::map<std::string, TargetPinoutDescriptor> pinoutDescriptorsByKey;
std::vector<TargetVariantDescriptor> variantDescriptors; std::vector<TargetVariantDescriptor> variantDescriptors;
BreakpointResources breakpointResources; BreakpointResources breakpointResources;
@@ -36,6 +38,7 @@ namespace Targets
const std::string& vendorName, const std::string& vendorName,
std::map<std::string, TargetAddressSpaceDescriptor>&& addressSpaceDescriptorsByKey, std::map<std::string, TargetAddressSpaceDescriptor>&& addressSpaceDescriptorsByKey,
std::map<std::string, TargetPeripheralDescriptor>&& peripheralDescriptorsByKey, std::map<std::string, TargetPeripheralDescriptor>&& peripheralDescriptorsByKey,
std::map<std::string, TargetPadDescriptor>&& padDescriptorsByKey,
std::map<std::string, TargetPinoutDescriptor>&& pinoutDescriptorsByKey, std::map<std::string, TargetPinoutDescriptor>&& pinoutDescriptorsByKey,
std::vector<TargetVariantDescriptor>&& variantDescriptors, std::vector<TargetVariantDescriptor>&& variantDescriptors,
const BreakpointResources& breakpointResources const BreakpointResources& breakpointResources
@@ -71,6 +74,12 @@ namespace Targets
const TargetPeripheralDescriptor& getPeripheralDescriptor(const std::string& key) const; const TargetPeripheralDescriptor& getPeripheralDescriptor(const std::string& key) const;
std::optional<std::reference_wrapper<const TargetPadDescriptor>> tryGetPadDescriptor(
const std::string& key
) const;
const TargetPadDescriptor& getPadDescriptor(const std::string& key) const;
std::optional<std::reference_wrapper<const TargetPinoutDescriptor>> tryGetPinoutDescriptor( std::optional<std::reference_wrapper<const TargetPinoutDescriptor>> tryGetPinoutDescriptor(
const std::string& key const std::string& key
) const; ) const;

View File

@@ -0,0 +1,50 @@
#pragma once
#include <cstdint>
#include <QMetaType>
#include "TargetPadDescriptor.hpp"
#include "src/Helpers/Pair.hpp"
namespace Targets
{
struct TargetGpioPadState
{
enum class State: std::uint8_t
{
HIGH,
LOW,
};
enum class DataDirection: std::uint8_t
{
INPUT,
OUTPUT,
};
State value;
DataDirection direction;
TargetGpioPadState(
State value,
DataDirection direction
)
: value(value)
, direction(direction)
{}
bool operator == (const TargetGpioPadState& other) const {
return this->value == other.value && this->direction == other.direction;
}
bool operator != (const TargetGpioPadState& other) const {
return !(*this == other);
}
};
using TargetGpioPadDescriptorAndStatePair = Pair<const TargetPadDescriptor&, TargetGpioPadState>;
using TargetGpioPadDescriptorAndStatePairs = std::vector<TargetGpioPadDescriptorAndStatePair>;
}
Q_DECLARE_METATYPE(Targets::TargetGpioPadState)

View File

@@ -1,40 +0,0 @@
#pragma once
#include <cstdint>
#include <QMetaType>
#include "TargetPinDescriptor.hpp"
namespace Targets
{
struct TargetGpioPinState
{
enum class State: std::uint8_t
{
HIGH,
LOW,
};
enum class DataDirection: std::uint8_t
{
INPUT,
OUTPUT,
};
State value;
DataDirection direction;
TargetGpioPinState(
State value,
DataDirection direction
)
: value(value)
, direction(direction)
{}
};
using TargetGpioPinDescriptorAndStatePair = Pair<const TargetPinDescriptor&, TargetGpioPinState>;
using TargetGpioPinDescriptorAndStatePairs = std::vector<TargetGpioPinDescriptorAndStatePair>;
}
Q_DECLARE_METATYPE(Targets::TargetGpioPinState)

View File

@@ -0,0 +1,29 @@
#include "TargetPadDescriptor.hpp"
#include "src/Services/StringService.hpp"
namespace Targets
{
TargetPadDescriptor::TargetPadDescriptor(
const std::string& key,
const std::string& name,
TargetPadType type
)
: id(TargetPadDescriptor::generateId(key))
, key(key)
, name(name)
, type(type)
{}
bool TargetPadDescriptor::operator == (const TargetPadDescriptor& other) const {
return this->id == other.id;
}
bool TargetPadDescriptor::operator != (const TargetPadDescriptor& other) const {
return !(*this == other);
}
TargetPadId TargetPadDescriptor::generateId(const std::string& padKey) {
return Services::StringService::generateUniqueInteger(padKey);
}
}

View File

@@ -0,0 +1,45 @@
#pragma once
#include <cstdint>
#include <string>
#include <vector>
namespace Targets
{
enum class TargetPadType: std::uint8_t
{
GPIO,
GND,
VCC,
OTHER,
};
using TargetPadId = std::size_t;
struct TargetPadDescriptor
{
public:
const TargetPadId id;
const std::string key;
std::string name;
TargetPadType type = TargetPadType::OTHER;
TargetPadDescriptor(
const std::string& key,
const std::string& name,
TargetPadType type
);
TargetPadDescriptor(const TargetPadDescriptor& other) = delete;
TargetPadDescriptor& operator = (const TargetPadDescriptor& other) = delete;
TargetPadDescriptor(TargetPadDescriptor&& other) noexcept = default;
bool operator == (const TargetPadDescriptor& other) const;
bool operator != (const TargetPadDescriptor& other) const;
static TargetPadId generateId(const std::string& padKey);
};
using TargetPadDescriptors = std::vector<TargetPadDescriptor*>;
}

View File

@@ -3,16 +3,17 @@
namespace Targets namespace Targets
{ {
TargetPeripheralSignalDescriptor::TargetPeripheralSignalDescriptor( TargetPeripheralSignalDescriptor::TargetPeripheralSignalDescriptor(
const std::string& padName, const std::string& padKey,
const std::optional<std::uint16_t>& index const std::optional<std::uint16_t>& index
) )
: padName(padName) : padId(TargetPadDescriptor::generateId(padKey))
, padKey(padKey)
, index(index) , index(index)
{} {}
TargetPeripheralSignalDescriptor TargetPeripheralSignalDescriptor::clone() const { TargetPeripheralSignalDescriptor TargetPeripheralSignalDescriptor::clone() const {
return { return {
this->padName, this->padKey,
this->index this->index
}; };
} }

View File

@@ -4,16 +4,19 @@
#include <string> #include <string>
#include <optional> #include <optional>
#include "TargetPadDescriptor.hpp"
namespace Targets namespace Targets
{ {
struct TargetPeripheralSignalDescriptor struct TargetPeripheralSignalDescriptor
{ {
public: public:
std::string padName; const TargetPadId padId;
const std::string padKey;
std::optional<std::uint16_t> index; std::optional<std::uint16_t> index;
TargetPeripheralSignalDescriptor( TargetPeripheralSignalDescriptor(
const std::string& padName, const std::string& padKey,
const std::optional<std::uint16_t>& index const std::optional<std::uint16_t>& index
); );
@@ -21,7 +24,6 @@ namespace Targets
TargetPeripheralSignalDescriptor& operator = (const TargetPeripheralSignalDescriptor& other) = delete; TargetPeripheralSignalDescriptor& operator = (const TargetPeripheralSignalDescriptor& other) = delete;
TargetPeripheralSignalDescriptor(TargetPeripheralSignalDescriptor&& other) noexcept = default; TargetPeripheralSignalDescriptor(TargetPeripheralSignalDescriptor&& other) noexcept = default;
TargetPeripheralSignalDescriptor& operator = (TargetPeripheralSignalDescriptor&& other) = default;
[[nodiscard]] TargetPeripheralSignalDescriptor clone() const; [[nodiscard]] TargetPeripheralSignalDescriptor clone() const;
}; };

View File

@@ -1,14 +1,15 @@
#include "TargetPinDescriptor.hpp" #include "TargetPinDescriptor.hpp"
#include "src/Services/StringService.hpp"
namespace Targets namespace Targets
{ {
TargetPinDescriptor::TargetPinDescriptor( TargetPinDescriptor::TargetPinDescriptor(
const std::string& padName,
const std::string& position, const std::string& position,
TargetPinType type const std::optional<std::string>& padKey
) )
: padName(padName) : position(position)
, position(position) , numericPosition(Services::StringService::toUint16(this->position, 10))
, type(type) , padKey(padKey)
{} {}
} }

View File

@@ -2,28 +2,20 @@
#include <cstdint> #include <cstdint>
#include <string> #include <string>
#include <optional>
namespace Targets namespace Targets
{ {
enum class TargetPinType: std::uint8_t
{
GPIO,
GND,
VCC,
OTHER,
};
struct TargetPinDescriptor struct TargetPinDescriptor
{ {
public: public:
std::string padName;
std::string position; std::string position;
TargetPinType type = TargetPinType::OTHER; std::uint16_t numericPosition;
std::optional<std::string> padKey;
TargetPinDescriptor( TargetPinDescriptor(
const std::string& padName,
const std::string& position, const std::string& position,
TargetPinType type const std::optional<std::string>& padKey
); );
TargetPinDescriptor(const TargetPinDescriptor& other) = delete; TargetPinDescriptor(const TargetPinDescriptor& other) = delete;