- Refactored AVR8 constructor, moving TDF construction to the TargetControllerComponent

- The `TargetControllerComponent` now resolves the target via the new generated mapping approach
- Added `TargetDescriptionFile` derived class
- Removed obsolete JSON map processing code
- Other bits of refactoring and tidying
This commit is contained in:
Nav
2023-12-17 18:12:53 +00:00
parent 866cdbdcc5
commit 66cbd89051
14 changed files with 161 additions and 119 deletions

View File

@@ -18,9 +18,9 @@ namespace Targets::Microchip::Avr::Avr8Bit
{
using namespace Exceptions;
Avr8::Avr8(const TargetConfig& targetConfig)
Avr8::Avr8(const TargetConfig& targetConfig, TargetDescription::TargetDescriptionFile&& targetDescriptionFile)
: targetConfig(Avr8TargetConfig(targetConfig))
, targetDescriptionFile(TargetDescription::TargetDescriptionFile(this->targetConfig.name))
, targetDescriptionFile(std::move(targetDescriptionFile))
, signature(this->targetDescriptionFile.getTargetSignature())
, name(this->targetDescriptionFile.getTargetName())
, family(this->targetDescriptionFile.getAvrFamily())

View File

@@ -30,7 +30,10 @@ namespace Targets::Microchip::Avr::Avr8Bit
class Avr8: public Target
{
public:
explicit Avr8(const TargetConfig& targetConfig);
explicit Avr8(
const TargetConfig& targetConfig,
TargetDescription::TargetDescriptionFile&& targetDescriptionFile
);
/*
* The functions below implement the Target interface for AVR8 targets.

View File

@@ -1,9 +1,5 @@
#include "TargetDescriptionFile.hpp"
#include <QJsonDocument>
#include <QJsonArray>
#include <QJsonObject>
#include "src/Services/PathService.hpp"
#include "src/Logger/Logger.hpp"
@@ -22,54 +18,15 @@ namespace Targets::Microchip::Avr::Avr8Bit::TargetDescription
using Targets::TargetVariant;
using Targets::TargetRegisterDescriptor;
TargetDescriptionFile::TargetDescriptionFile(const std::string& targetName) {
const auto mapping = TargetDescriptionFile::getTargetDescriptionMapping();
const auto descriptionFileObjectIt = mapping.find(QString::fromStdString(targetName).toLower());
if (descriptionFileObjectIt == mapping.end()) {
throw Exception(
"Failed to resolve target description file for target \"" + targetName + "\" - unknown target name."
);
}
const auto descriptionFileObject = descriptionFileObjectIt.value().toObject();
const auto descriptionFilePath = QString::fromStdString(
Services::PathService::resourcesDirPath()) + "/" + descriptionFileObject.find("tdfPath")->toString();
Logger::debug("Loading AVR8 target description file: " + descriptionFilePath.toStdString());
Targets::TargetDescription::TargetDescriptionFile::init(descriptionFilePath);
}
void TargetDescriptionFile::init(const QDomDocument& document) {
Targets::TargetDescription::TargetDescriptionFile::init(document);
const auto device = document.elementsByTagName("device").item(0).toElement();
if (!device.isElement()) {
throw TargetDescriptionParsingFailureException("Device element not found.");
}
this->avrFamilyName = device.attributes().namedItem("avr-family").nodeValue().toLower().toStdString();
TargetDescriptionFile::TargetDescriptionFile(const std::string& xmlFilePath)
: Targets::TargetDescription::TargetDescriptionFile(xmlFilePath)
{
this->loadSupportedPhysicalInterfaces();
this->loadPadDescriptors();
this->loadTargetVariants();
this->loadTargetRegisterDescriptors();
}
QJsonObject TargetDescriptionFile::getTargetDescriptionMapping() {
auto mappingFile = QFile(
QString::fromStdString(Services::PathService::resourcesDirPath() + "/TargetDescriptionFiles/AVR/Mapping.json")
);
if (!mappingFile.exists()) {
throw Exception("Failed to load AVR target description mapping - mapping file not found");
}
mappingFile.open(QIODevice::ReadOnly);
return QJsonDocument::fromJson(mappingFile.readAll()).object();
}
TargetSignature TargetDescriptionFile::getTargetSignature() const {
const auto& propertyGroups = this->propertyGroupsMappedByName;
@@ -110,11 +67,9 @@ namespace Targets::Microchip::Avr::Avr8Bit::TargetDescription
Family TargetDescriptionFile::getAvrFamily() const {
static const auto targetFamiliesByName = TargetDescriptionFile::getFamilyNameToEnumMapping();
if (this->avrFamilyName.empty()) {
throw Exception("Could not find target family name in target description file.");
}
const auto familyIt = targetFamiliesByName.find(this->avrFamilyName);
const auto familyIt = targetFamiliesByName.find(
QString::fromStdString(this->deviceAttribute("avr-family")).toLower().toStdString()
);
if (familyIt == targetFamiliesByName.end()) {
throw Exception("Unknown family name in target description file.");

View File

@@ -33,27 +33,13 @@ namespace Targets::Microchip::Avr::Avr8Bit::TargetDescription
class TargetDescriptionFile: public Targets::TargetDescription::TargetDescriptionFile
{
public:
/**
* Will resolve the target description file using the target description JSON mapping and a given target name.
*
* @param targetName
*/
TargetDescriptionFile(const std::string& targetName);
/**
* Extends TDF initialisation to include the loading of physical interfaces for debugging AVR8 targets, among
* other things.
*
* @param xml
*/
void init(const QDomDocument& document) override;
/**
* Loads the AVR8 target description JSON mapping file.
*
* @return
*/
static QJsonObject getTargetDescriptionMapping();
explicit TargetDescriptionFile(const std::string& xmlFilePath);
/**
* Extracts the AVR8 target signature from the TDF.