Extracting interfaces from TDFs
This commit is contained in:
13
src/Targets/TargetDescription/Interface.hpp
Normal file
13
src/Targets/TargetDescription/Interface.hpp
Normal file
@@ -0,0 +1,13 @@
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include <optional>
|
||||
|
||||
namespace Bloom::Targets::TargetDescription
|
||||
{
|
||||
struct Interface
|
||||
{
|
||||
std::string name;
|
||||
std::optional<std::string> type;
|
||||
};
|
||||
}
|
||||
@@ -41,6 +41,7 @@ void TargetDescriptionFile::init(const QDomDocument& xml) {
|
||||
this->loadPeripheralModules();
|
||||
this->loadVariants();
|
||||
this->loadPinouts();
|
||||
this->loadInterfaces();
|
||||
}
|
||||
|
||||
std::string TargetDescriptionFile::getTargetName() const {
|
||||
@@ -62,13 +63,13 @@ AddressSpace TargetDescriptionFile::generateAddressSpaceFromXml(const QDomElemen
|
||||
addressSpace.id = xmlElement.attribute("id").toStdString();
|
||||
|
||||
bool conversionStatus;
|
||||
addressSpace.startAddress = xmlElement.attribute("start").toUShort(&conversionStatus, 16);
|
||||
addressSpace.startAddress = xmlElement.attribute("start").toUInt(&conversionStatus, 16);
|
||||
|
||||
if (!conversionStatus) {
|
||||
throw Exception("Failed to convert start address hex value to integer.");
|
||||
}
|
||||
|
||||
addressSpace.size = xmlElement.attribute("size").toUShort(&conversionStatus, 16);
|
||||
addressSpace.size = xmlElement.attribute("size").toUInt(&conversionStatus, 16);
|
||||
|
||||
if (!conversionStatus) {
|
||||
throw Exception("Failed to convert size hex value to integer.");
|
||||
@@ -439,3 +440,31 @@ void TargetDescriptionFile::loadPinouts() {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void TargetDescriptionFile::loadInterfaces() {
|
||||
auto interfaceNodes = this->deviceElement.elementsByTagName("interfaces").item(0).toElement()
|
||||
.elementsByTagName("interface");
|
||||
|
||||
for (int interfaceIndex = 0; interfaceIndex < interfaceNodes.count(); interfaceIndex++) {
|
||||
try {
|
||||
auto interfaceXml = interfaceNodes.item(interfaceIndex).toElement();
|
||||
|
||||
if (!interfaceXml.hasAttribute("name")) {
|
||||
throw Exception("Missing name attribute");
|
||||
}
|
||||
|
||||
auto interface = Interface();
|
||||
interface.name = interfaceXml.attribute("name").toLower().toStdString();
|
||||
|
||||
if (interfaceXml.hasAttribute("type")) {
|
||||
interface.type = interfaceXml.attribute("type").toStdString();
|
||||
}
|
||||
|
||||
this->interfacesByName.insert(std::pair(interface.name, interface));
|
||||
|
||||
} catch (const Exception& exception) {
|
||||
Logger::debug("Failed to extract interface from target description element - " + exception.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
#include "Module.hpp"
|
||||
#include "Variant.hpp"
|
||||
#include "Pinout.hpp"
|
||||
#include "Interface.hpp"
|
||||
|
||||
namespace Bloom::Targets::TargetDescription
|
||||
{
|
||||
@@ -44,9 +45,10 @@ namespace Bloom::Targets::TargetDescription
|
||||
std::map<std::string, Module> peripheralModulesMappedByName;
|
||||
std::vector<Variant> variants;
|
||||
std::map<std::string, Pinout> pinoutsMappedByName;
|
||||
std::map<std::string, Interface> interfacesByName;
|
||||
|
||||
|
||||
void init(const QDomDocument& xml);
|
||||
virtual void init(const QDomDocument& xml);
|
||||
void init(const QString& xmlFilePath);
|
||||
|
||||
private:
|
||||
@@ -112,6 +114,11 @@ namespace Bloom::Targets::TargetDescription
|
||||
*/
|
||||
void loadPinouts();
|
||||
|
||||
/**
|
||||
* Extracts all interfaces and loads them into this->interfacesByName
|
||||
*/
|
||||
void loadInterfaces();
|
||||
|
||||
public:
|
||||
TargetDescriptionFile() = default;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user