diff --git a/build/scripts/TargetDescriptionFiles/AVR8/Avr8TargetDescriptionFile.php b/build/scripts/TargetDescriptionFiles/AVR8/Avr8TargetDescriptionFile.php index 449b6399..aa1985ce 100644 --- a/build/scripts/TargetDescriptionFiles/AVR8/Avr8TargetDescriptionFile.php +++ b/build/scripts/TargetDescriptionFiles/AVR8/Avr8TargetDescriptionFile.php @@ -51,28 +51,28 @@ class Avr8TargetDescriptionFile extends TargetDescriptionFile return null; } - public function getFamily(): ?string + public function getAvrFamily(): ?string { - if (!empty($this->deviceAttributesByName['family'])) { - if (stristr($this->deviceAttributesByName['family'], 'xmega') !== false) { + if (!empty($this->deviceAttributesByName['avr-family'])) { + if (stristr($this->deviceAttributesByName['avr-family'], 'xmega') !== false) { return self::AVR8_FAMILY_XMEGA; - } else if (stristr($this->deviceAttributesByName['family'], 'tiny') !== false) { + } else if (stristr($this->deviceAttributesByName['avr-family'], 'tiny') !== false) { return self::AVR8_FAMILY_TINY; - } else if (stristr($this->deviceAttributesByName['family'], 'mega') !== false) { + } else if (stristr($this->deviceAttributesByName['avr-family'], 'mega') !== false) { return self::AVR8_FAMILY_MEGA; - } else if (strtolower(trim($this->deviceAttributesByName['family'])) == 'avr da') { + } else if (strtolower(trim($this->deviceAttributesByName['avr-family'])) == 'avr da') { return self::AVR8_FAMILY_DA; - } else if (strtolower(trim($this->deviceAttributesByName['family'])) == 'avr db') { + } else if (strtolower(trim($this->deviceAttributesByName['avr-family'])) == 'avr db') { return self::AVR8_FAMILY_DB; - } else if (strtolower(trim($this->deviceAttributesByName['family'])) == 'avr dd') { + } else if (strtolower(trim($this->deviceAttributesByName['avr-family'])) == 'avr dd') { return self::AVR8_FAMILY_DD; - } else if (strtolower(trim($this->deviceAttributesByName['family'])) == 'avr ea') { + } else if (strtolower(trim($this->deviceAttributesByName['avr-family'])) == 'avr ea') { return self::AVR8_FAMILY_EA; } } @@ -591,7 +591,7 @@ class Avr8TargetDescriptionFile extends TargetDescriptionFile return $failures; } - $family = $this->getFamily(); + $family = $this->getAvrFamily(); if (is_null($family) || $family == self::AVR8_FAMILY_OTHER) { $failures[] = 'Unknown AVR8 family'; } diff --git a/src/Targets/Microchip/AVR/AVR8/Avr8.cpp b/src/Targets/Microchip/AVR/AVR8/Avr8.cpp index b3f34273..fe3342c9 100644 --- a/src/Targets/Microchip/AVR/AVR8/Avr8.cpp +++ b/src/Targets/Microchip/AVR/AVR8/Avr8.cpp @@ -23,7 +23,7 @@ namespace Targets::Microchip::Avr::Avr8Bit , targetDescriptionFile(TargetDescription::TargetDescriptionFile(this->targetConfig.name)) , signature(this->targetDescriptionFile.getTargetSignature()) , name(this->targetDescriptionFile.getTargetName()) - , family(this->targetDescriptionFile.getFamily()) + , family(this->targetDescriptionFile.getAvrFamily()) , targetParameters(this->targetDescriptionFile.getTargetParameters()) , supportedPhysicalInterfaces(this->targetDescriptionFile.getSupportedPhysicalInterfaces()) , padDescriptorsByName(this->targetDescriptionFile.getPadDescriptorsMappedByName()) diff --git a/src/Targets/Microchip/AVR/AVR8/TargetDescription/TargetDescriptionFile.cpp b/src/Targets/Microchip/AVR/AVR8/TargetDescription/TargetDescriptionFile.cpp index 0d949e08..799f2fce 100644 --- a/src/Targets/Microchip/AVR/AVR8/TargetDescription/TargetDescriptionFile.cpp +++ b/src/Targets/Microchip/AVR/AVR8/TargetDescription/TargetDescriptionFile.cpp @@ -41,8 +41,15 @@ namespace Targets::Microchip::Avr::Avr8Bit::TargetDescription Targets::TargetDescription::TargetDescriptionFile::init(descriptionFilePath); } - void TargetDescriptionFile::init(const QDomDocument& xml) { - Targets::TargetDescription::TargetDescriptionFile::init(xml); + 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(); this->loadSupportedPhysicalInterfaces(); this->loadPadDescriptors(); @@ -100,16 +107,14 @@ namespace Targets::Microchip::Avr::Avr8Bit::TargetDescription ); } - Family TargetDescriptionFile::getFamily() const { + Family TargetDescriptionFile::getAvrFamily() const { static const auto targetFamiliesByName = TargetDescriptionFile::getFamilyNameToEnumMapping(); - const auto& familyName = this->getFamilyName(); - - if (familyName.empty()) { + if (this->avrFamilyName.empty()) { throw Exception("Could not find target family name in target description file."); } - const auto familyIt = targetFamiliesByName.find(familyName); + const auto familyIt = targetFamiliesByName.find(this->avrFamilyName); if (familyIt == targetFamiliesByName.end()) { throw Exception("Unknown family name in target description file."); diff --git a/src/Targets/Microchip/AVR/AVR8/TargetDescription/TargetDescriptionFile.hpp b/src/Targets/Microchip/AVR/AVR8/TargetDescription/TargetDescriptionFile.hpp index 020db0f2..d27e15ca 100644 --- a/src/Targets/Microchip/AVR/AVR8/TargetDescription/TargetDescriptionFile.hpp +++ b/src/Targets/Microchip/AVR/AVR8/TargetDescription/TargetDescriptionFile.hpp @@ -46,7 +46,7 @@ namespace Targets::Microchip::Avr::Avr8Bit::TargetDescription * * @param xml */ - void init(const QDomDocument& xml) override; + void init(const QDomDocument& document) override; /** * Loads the AVR8 target description JSON mapping file. @@ -67,7 +67,7 @@ namespace Targets::Microchip::Avr::Avr8Bit::TargetDescription * * @return */ - [[nodiscard]] Family getFamily() const; + [[nodiscard]] Family getAvrFamily() const; /** * Constructs an instance of TargetParameters, for the AVR8 target, with data from the TDF. @@ -197,6 +197,7 @@ namespace Targets::Microchip::Avr::Avr8Bit::TargetDescription }; }; + std::string avrFamilyName; std::set supportedPhysicalInterfaces; std::map padDescriptorsByName; diff --git a/src/Targets/TargetDescription/TargetDescriptionFile.cpp b/src/Targets/TargetDescription/TargetDescriptionFile.cpp index de6b7b49..e7a79b73 100644 --- a/src/Targets/TargetDescription/TargetDescriptionFile.cpp +++ b/src/Targets/TargetDescription/TargetDescriptionFile.cpp @@ -27,8 +27,19 @@ namespace Targets::TargetDescription return this->targetName; } - const std::string& TargetDescriptionFile::getFamilyName() const { - return this->familyName; + TargetFamily TargetDescriptionFile::getFamily() const { + static const auto familiesByName = std::map { + {"AVR8", TargetFamily::AVR_8}, + {"RISCV", TargetFamily::RISC_V}, + }; + + const auto familyIt = familiesByName.find(this->familyName); + + if (familyIt == familiesByName.end()) { + throw Exception("Failed to resolve target family - invalid family name"); + } + + return familyIt->second; } void TargetDescriptionFile::init(const QString& xmlFilePath) { diff --git a/src/Targets/TargetDescription/TargetDescriptionFile.hpp b/src/Targets/TargetDescription/TargetDescriptionFile.hpp index e5c4b3d8..19eb1f8a 100644 --- a/src/Targets/TargetDescription/TargetDescriptionFile.hpp +++ b/src/Targets/TargetDescription/TargetDescriptionFile.hpp @@ -12,6 +12,8 @@ #include "Pinout.hpp" #include "Interface.hpp" +#include "src/Targets/TargetFamily.hpp" + #include GENERATED_TDF_MAPPING_PATH namespace Targets::TargetDescription @@ -74,11 +76,11 @@ namespace Targets::TargetDescription [[nodiscard]] const std::string& getTargetName() const; /** - * Returns the target family name extracted from the TDF. + * Returns the target family extracted from the TDF. * * @return */ - [[nodiscard]] const std::string& getFamilyName() const; + [[nodiscard]] TargetFamily getFamily() const; protected: std::string targetName; diff --git a/src/Targets/TargetDescriptionFiles/AVR8/D-SERIES/AVR128DA28.xml b/src/Targets/TargetDescriptionFiles/AVR8/D-SERIES/AVR128DA28.xml index e0ba75b5..95269faf 100644 --- a/src/Targets/TargetDescriptionFiles/AVR8/D-SERIES/AVR128DA28.xml +++ b/src/Targets/TargetDescriptionFiles/AVR8/D-SERIES/AVR128DA28.xml @@ -4,7 +4,7 @@ - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - +