Updated TDF physical interface extraction to align with new TDF format
This commit is contained in:
@@ -1,13 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include <optional>
|
||||
|
||||
namespace Targets::TargetDescription
|
||||
{
|
||||
struct Interface
|
||||
{
|
||||
std::string name;
|
||||
std::optional<std::string> type;
|
||||
};
|
||||
}
|
||||
21
src/Targets/TargetDescription/PhysicalInterface.hpp
Normal file
21
src/Targets/TargetDescription/PhysicalInterface.hpp
Normal file
@@ -0,0 +1,21 @@
|
||||
#pragma once
|
||||
|
||||
#include <cstdint>
|
||||
#include <string>
|
||||
|
||||
namespace Targets::TargetDescription
|
||||
{
|
||||
struct PhysicalInterface
|
||||
{
|
||||
std::string name;
|
||||
std::string type;
|
||||
|
||||
PhysicalInterface(
|
||||
const std::string& name,
|
||||
const std::string& type
|
||||
)
|
||||
: name(name)
|
||||
, type(type)
|
||||
{}
|
||||
};
|
||||
}
|
||||
@@ -153,11 +153,21 @@ namespace Targets::TargetDescription
|
||||
);
|
||||
}
|
||||
|
||||
for (
|
||||
auto element = deviceElement.firstChildElement("physical-interfaces")
|
||||
.firstChildElement("physical-interface");
|
||||
!element.isNull();
|
||||
element = element.nextSiblingElement("physical-interface")
|
||||
) {
|
||||
this->physicalInterfaces.emplace_back(
|
||||
TargetDescriptionFile::physicalInterfaceFromXml(element)
|
||||
);
|
||||
}
|
||||
|
||||
this->loadModules(document);
|
||||
this->loadPeripheralModules(document);
|
||||
this->loadVariants(document);
|
||||
this->loadPinouts(document);
|
||||
this->loadInterfaces(document);
|
||||
}
|
||||
|
||||
std::optional<std::string> TargetDescriptionFile::tryGetAttribute(
|
||||
@@ -324,6 +334,13 @@ namespace Targets::TargetDescription
|
||||
return output;
|
||||
}
|
||||
|
||||
PhysicalInterface TargetDescriptionFile::physicalInterfaceFromXml(const QDomElement& xmlElement) {
|
||||
return PhysicalInterface(
|
||||
TargetDescriptionFile::getAttribute(xmlElement, "name"),
|
||||
TargetDescriptionFile::getAttribute(xmlElement, "type")
|
||||
);
|
||||
}
|
||||
|
||||
RegisterGroup TargetDescriptionFile::registerGroupFromXml(const QDomElement& xmlElement) {
|
||||
if (!xmlElement.hasAttribute("name")) {
|
||||
throw Exception("Missing register group name attribute");
|
||||
@@ -650,35 +667,4 @@ namespace Targets::TargetDescription
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void TargetDescriptionFile::loadInterfaces(const QDomDocument& document) {
|
||||
const auto deviceElement = document.elementsByTagName("device").item(0).toElement();
|
||||
|
||||
auto interfaceNodes = 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()
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,11 +13,11 @@
|
||||
#include "AddressSpace.hpp"
|
||||
#include "MemorySegment.hpp"
|
||||
#include "MemorySegmentSection.hpp"
|
||||
#include "PhysicalInterface.hpp"
|
||||
#include "RegisterGroup.hpp"
|
||||
#include "Module.hpp"
|
||||
#include "Variant.hpp"
|
||||
#include "Pinout.hpp"
|
||||
#include "Interface.hpp"
|
||||
|
||||
#include "src/Targets/TargetFamily.hpp"
|
||||
|
||||
@@ -103,12 +103,12 @@ namespace Targets::TargetDescription
|
||||
std::map<std::string, std::string> deviceAttributesByName;
|
||||
std::map<std::string, AddressSpace, std::less<void>> addressSpacesByKey;
|
||||
std::map<std::string, PropertyGroup, std::less<void>> propertyGroupsByKey;
|
||||
std::vector<PhysicalInterface> physicalInterfaces;
|
||||
std::map<std::string, Module> modulesMappedByName;
|
||||
std::map<std::string, Module> peripheralModulesMappedByName;
|
||||
std::map<std::string, std::vector<RegisterGroup>> peripheralRegisterGroupsMappedByModuleRegisterGroupName;
|
||||
std::vector<Variant> variants;
|
||||
std::map<std::string, Pinout> pinoutsMappedByName;
|
||||
std::map<std::string, Interface> interfacesByName;
|
||||
|
||||
TargetDescriptionFile() = default;
|
||||
virtual ~TargetDescriptionFile() = default;
|
||||
@@ -152,6 +152,14 @@ namespace Targets::TargetDescription
|
||||
*/
|
||||
static MemorySegmentSection memorySegmentSectionFromXml(const QDomElement& xmlElement);
|
||||
|
||||
/**
|
||||
* Constructs a PhysicalInterface from al XML element.
|
||||
*
|
||||
* @param xmlElement
|
||||
* @return
|
||||
*/
|
||||
static PhysicalInterface physicalInterfaceFromXml(const QDomElement& xmlElement);
|
||||
|
||||
/**
|
||||
* Constructs a RegisterGroup object from an XML element.
|
||||
*
|
||||
@@ -203,10 +211,5 @@ namespace Targets::TargetDescription
|
||||
* Extracts all pinouts and loads them into this->pinoutsMappedByName.
|
||||
*/
|
||||
void loadPinouts(const QDomDocument& document);
|
||||
|
||||
/**
|
||||
* Extracts all interfaces and loads them into this->interfacesByName
|
||||
*/
|
||||
void loadInterfaces(const QDomDocument& document);
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user