Updated TDF peripheral, register group instance and signal extraction to align with new TDF format
This commit is contained in:
63
src/Targets/TargetDescription/Peripheral.hpp
Normal file
63
src/Targets/TargetDescription/Peripheral.hpp
Normal file
@@ -0,0 +1,63 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <cstdint>
|
||||||
|
#include <string>
|
||||||
|
#include <map>
|
||||||
|
#include <functional>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
#include "RegisterGroupInstance.hpp"
|
||||||
|
#include "Signal.hpp"
|
||||||
|
|
||||||
|
#include "Exceptions/InvalidTargetDescriptionDataException.hpp"
|
||||||
|
|
||||||
|
namespace Targets::TargetDescription
|
||||||
|
{
|
||||||
|
struct Peripheral
|
||||||
|
{
|
||||||
|
std::string key;
|
||||||
|
std::string name;
|
||||||
|
std::string moduleKey;
|
||||||
|
|
||||||
|
std::map<std::string, RegisterGroupInstance, std::less<void>> registerGroupInstancesByKey;
|
||||||
|
std::vector<Signal> sigs;
|
||||||
|
|
||||||
|
Peripheral(
|
||||||
|
const std::string& key,
|
||||||
|
const std::string& name,
|
||||||
|
const std::string& moduleKey,
|
||||||
|
const std::map<std::string, RegisterGroupInstance, std::less<void>>& registerGroupInstancesByKey,
|
||||||
|
const std::vector<Signal>& sigs
|
||||||
|
)
|
||||||
|
: key(key)
|
||||||
|
, name(name)
|
||||||
|
, moduleKey(moduleKey)
|
||||||
|
, registerGroupInstancesByKey(registerGroupInstancesByKey)
|
||||||
|
, sigs(sigs)
|
||||||
|
{}
|
||||||
|
|
||||||
|
std::optional<std::reference_wrapper<const RegisterGroupInstance>> tryGetRegisterGroupInstance(
|
||||||
|
std::string_view key
|
||||||
|
) const {
|
||||||
|
const auto instanceIt = this->registerGroupInstancesByKey.find(key);
|
||||||
|
|
||||||
|
if (instanceIt == this->registerGroupInstancesByKey.end()) {
|
||||||
|
return std::nullopt;
|
||||||
|
}
|
||||||
|
|
||||||
|
return std::cref(instanceIt->second);
|
||||||
|
}
|
||||||
|
|
||||||
|
const RegisterGroupInstance& getRegisterGroupInstance(std::string_view key) const {
|
||||||
|
const auto instance = this->tryGetRegisterGroupInstance(key);
|
||||||
|
if (!instance.has_value()) {
|
||||||
|
throw Exceptions::InvalidTargetDescriptionDataException(
|
||||||
|
"Failed to get register group instance \"" + std::string(key)
|
||||||
|
+ "\" from peripheral in TDF - register group instance not found"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return instance->get();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
34
src/Targets/TargetDescription/RegisterGroupInstance.hpp
Normal file
34
src/Targets/TargetDescription/RegisterGroupInstance.hpp
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <cstdint>
|
||||||
|
#include <string>
|
||||||
|
#include <optional>
|
||||||
|
|
||||||
|
namespace Targets::TargetDescription
|
||||||
|
{
|
||||||
|
struct RegisterGroupInstance
|
||||||
|
{
|
||||||
|
std::string key;
|
||||||
|
std::string name;
|
||||||
|
std::string registerGroupKey;
|
||||||
|
std::string addressSpaceKey;
|
||||||
|
std::uint32_t offset;
|
||||||
|
std::optional<std::string> description;
|
||||||
|
|
||||||
|
RegisterGroupInstance(
|
||||||
|
const std::string& key,
|
||||||
|
const std::string& name,
|
||||||
|
const std::string& registerGroupKey,
|
||||||
|
const std::string& addressSpaceKey,
|
||||||
|
std::uint32_t offset,
|
||||||
|
const std::optional<std::string>& description
|
||||||
|
)
|
||||||
|
: key(key)
|
||||||
|
, name(name)
|
||||||
|
, registerGroupKey(registerGroupKey)
|
||||||
|
, addressSpaceKey(addressSpaceKey)
|
||||||
|
, offset(offset)
|
||||||
|
, description(description)
|
||||||
|
{}
|
||||||
|
};
|
||||||
|
}
|
||||||
@@ -1,5 +1,6 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <cstdint>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <optional>
|
#include <optional>
|
||||||
|
|
||||||
@@ -7,9 +8,24 @@ namespace Targets::TargetDescription
|
|||||||
{
|
{
|
||||||
struct Signal
|
struct Signal
|
||||||
{
|
{
|
||||||
std::string padName;
|
std::string padId;
|
||||||
std::string function;
|
std::optional<std::uint16_t> index;
|
||||||
std::optional<int> index;
|
std::optional<std::string> function;
|
||||||
std::string group;
|
std::optional<std::string> group;
|
||||||
|
std::optional<std::string> field;
|
||||||
|
|
||||||
|
Signal(
|
||||||
|
const std::string& padId,
|
||||||
|
const std::optional<std::uint16_t>& index,
|
||||||
|
const std::optional<std::string>& function,
|
||||||
|
const std::optional<std::string>& group,
|
||||||
|
const std::optional<std::string>& field
|
||||||
|
)
|
||||||
|
: padId(padId)
|
||||||
|
, index(index)
|
||||||
|
, function(function)
|
||||||
|
, group(group)
|
||||||
|
, field(field)
|
||||||
|
{}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -141,6 +141,27 @@ namespace Targets::TargetDescription
|
|||||||
return module->get();
|
return module->get();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::optional<std::reference_wrapper<const Peripheral>> TargetDescriptionFile::tryGetPeripheral(
|
||||||
|
std::string_view key
|
||||||
|
) const {
|
||||||
|
const auto peripheralIt = this->peripheralsByKey.find(key);
|
||||||
|
return peripheralIt != this->peripheralsByKey.end()
|
||||||
|
? std::optional(std::cref(peripheralIt->second))
|
||||||
|
: std::nullopt;
|
||||||
|
}
|
||||||
|
|
||||||
|
const Peripheral& TargetDescriptionFile::getPeripheral(std::string_view key) const {
|
||||||
|
const auto peripheral = this->tryGetPeripheral(key);
|
||||||
|
|
||||||
|
if (!peripheral.has_value()) {
|
||||||
|
throw InvalidTargetDescriptionDataException(
|
||||||
|
"Failed to get peripheral \"" + std::string(key) + "\" from TDF - peripheral not found"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return peripheral->get();
|
||||||
|
}
|
||||||
|
|
||||||
void TargetDescriptionFile::init(const std::string& xmlFilePath) {
|
void TargetDescriptionFile::init(const std::string& xmlFilePath) {
|
||||||
auto file = QFile(QString::fromStdString(xmlFilePath));
|
auto file = QFile(QString::fromStdString(xmlFilePath));
|
||||||
if (!file.exists()) {
|
if (!file.exists()) {
|
||||||
@@ -219,7 +240,17 @@ namespace Targets::TargetDescription
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
this->loadPeripheralModules(document);
|
for (
|
||||||
|
auto element = deviceElement.firstChildElement("peripherals").firstChildElement("peripheral");
|
||||||
|
!element.isNull();
|
||||||
|
element = element.nextSiblingElement("peripheral")
|
||||||
|
) {
|
||||||
|
auto peripheral = TargetDescriptionFile::peripheralFromXml(element);
|
||||||
|
this->peripheralsByKey.insert(
|
||||||
|
std::pair(peripheral.key, std::move(peripheral))
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
this->loadVariants(document);
|
this->loadVariants(document);
|
||||||
this->loadPinouts(document);
|
this->loadPinouts(document);
|
||||||
}
|
}
|
||||||
@@ -507,6 +538,62 @@ namespace Targets::TargetDescription
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Peripheral TargetDescriptionFile::peripheralFromXml(const QDomElement& xmlElement) {
|
||||||
|
const auto offset = TargetDescriptionFile::tryGetAttribute(xmlElement, "offset");
|
||||||
|
|
||||||
|
auto output = Peripheral(
|
||||||
|
TargetDescriptionFile::getAttribute(xmlElement, "key"),
|
||||||
|
TargetDescriptionFile::getAttribute(xmlElement, "name"),
|
||||||
|
TargetDescriptionFile::getAttribute(xmlElement, "module-key"),
|
||||||
|
{},
|
||||||
|
{}
|
||||||
|
);
|
||||||
|
|
||||||
|
for (
|
||||||
|
auto element = xmlElement.firstChildElement("register-group-instance");
|
||||||
|
!element.isNull();
|
||||||
|
element = element.nextSiblingElement("register-group-instance")
|
||||||
|
) {
|
||||||
|
auto registerGroupInstance = TargetDescriptionFile::registerGroupInstanceFromXml(element);
|
||||||
|
output.registerGroupInstancesByKey.insert(
|
||||||
|
std::pair(registerGroupInstance.key, std::move(registerGroupInstance))
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (
|
||||||
|
auto element = xmlElement.firstChildElement("signals").firstChildElement("signal");
|
||||||
|
!element.isNull();
|
||||||
|
element = element.nextSiblingElement("signal")
|
||||||
|
) {
|
||||||
|
output.sigs.emplace_back(TargetDescriptionFile::signalFromXml(element));
|
||||||
|
}
|
||||||
|
|
||||||
|
return output;
|
||||||
|
}
|
||||||
|
|
||||||
|
RegisterGroupInstance TargetDescriptionFile::registerGroupInstanceFromXml(const QDomElement& xmlElement) {
|
||||||
|
return RegisterGroupInstance(
|
||||||
|
TargetDescriptionFile::getAttribute(xmlElement, "key"),
|
||||||
|
TargetDescriptionFile::getAttribute(xmlElement, "name"),
|
||||||
|
TargetDescriptionFile::getAttribute(xmlElement, "register-group-key"),
|
||||||
|
TargetDescriptionFile::getAttribute(xmlElement, "address-space-key"),
|
||||||
|
StringService::toUint32(TargetDescriptionFile::getAttribute(xmlElement, "offset")),
|
||||||
|
TargetDescriptionFile::tryGetAttribute(xmlElement, "description")
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
Signal TargetDescriptionFile::signalFromXml(const QDomElement& xmlElement) {
|
||||||
|
const auto index = TargetDescriptionFile::tryGetAttribute(xmlElement, "index");
|
||||||
|
|
||||||
|
return Signal(
|
||||||
|
TargetDescriptionFile::getAttribute(xmlElement, "pad-id"),
|
||||||
|
index.has_value() ? std::optional(StringService::toUint64(*index)) : std::nullopt,
|
||||||
|
TargetDescriptionFile::tryGetAttribute(xmlElement, "function"),
|
||||||
|
TargetDescriptionFile::tryGetAttribute(xmlElement, "group"),
|
||||||
|
TargetDescriptionFile::tryGetAttribute(xmlElement, "field")
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
const std::string& TargetDescriptionFile::deviceAttribute(const std::string& attributeName) const {
|
const std::string& TargetDescriptionFile::deviceAttribute(const std::string& attributeName) const {
|
||||||
const auto attributeIt = this->deviceAttributesByName.find(attributeName);
|
const auto attributeIt = this->deviceAttributesByName.find(attributeName);
|
||||||
|
|
||||||
@@ -517,13 +604,6 @@ namespace Targets::TargetDescription
|
|||||||
return attributeIt->second;
|
return attributeIt->second;
|
||||||
}
|
}
|
||||||
|
|
||||||
void TargetDescriptionFile::loadPeripheralModules(const QDomDocument& document) {
|
|
||||||
const auto deviceElement = document.elementsByTagName("device").item(0).toElement();
|
|
||||||
|
|
||||||
auto moduleNodes = deviceElement.elementsByTagName("peripherals").item(0).toElement()
|
|
||||||
.elementsByTagName("module");
|
|
||||||
}
|
|
||||||
|
|
||||||
void TargetDescriptionFile::loadVariants(const QDomDocument& document) {
|
void TargetDescriptionFile::loadVariants(const QDomDocument& document) {
|
||||||
const auto deviceElement = document.elementsByTagName("device").item(0).toElement();
|
const auto deviceElement = document.elementsByTagName("device").item(0).toElement();
|
||||||
|
|
||||||
|
|||||||
@@ -14,10 +14,15 @@
|
|||||||
#include "MemorySegment.hpp"
|
#include "MemorySegment.hpp"
|
||||||
#include "MemorySegmentSection.hpp"
|
#include "MemorySegmentSection.hpp"
|
||||||
#include "PhysicalInterface.hpp"
|
#include "PhysicalInterface.hpp"
|
||||||
#include "RegisterGroup.hpp"
|
|
||||||
#include "Module.hpp"
|
#include "Module.hpp"
|
||||||
#include "Variant.hpp"
|
#include "RegisterGroup.hpp"
|
||||||
|
#include "Register.hpp"
|
||||||
|
#include "RegisterGroupReference.hpp"
|
||||||
|
#include "Peripheral.hpp"
|
||||||
|
#include "RegisterGroupInstance.hpp"
|
||||||
|
#include "Signal.hpp"
|
||||||
#include "Pinout.hpp"
|
#include "Pinout.hpp"
|
||||||
|
#include "Variant.hpp"
|
||||||
|
|
||||||
#include "src/Targets/TargetFamily.hpp"
|
#include "src/Targets/TargetFamily.hpp"
|
||||||
#include "src/Targets/TargetPhysicalInterface.hpp"
|
#include "src/Targets/TargetPhysicalInterface.hpp"
|
||||||
@@ -107,13 +112,18 @@ namespace Targets::TargetDescription
|
|||||||
) const;
|
) const;
|
||||||
[[nodiscard]] const Module& getModule(std::string_view key) const;
|
[[nodiscard]] const Module& getModule(std::string_view key) const;
|
||||||
|
|
||||||
|
[[nodiscard]] std::optional<std::reference_wrapper<const Peripheral>> tryGetPeripheral(
|
||||||
|
std::string_view key
|
||||||
|
) const;
|
||||||
|
[[nodiscard]] const Peripheral& getPeripheral(std::string_view key) const;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
std::map<std::string, std::string> deviceAttributesByName;
|
std::map<std::string, std::string> deviceAttributesByName;
|
||||||
std::map<std::string, PropertyGroup, std::less<void>> propertyGroupsByKey;
|
std::map<std::string, PropertyGroup, std::less<void>> propertyGroupsByKey;
|
||||||
std::map<std::string, AddressSpace, std::less<void>> addressSpacesByKey;
|
std::map<std::string, AddressSpace, std::less<void>> addressSpacesByKey;
|
||||||
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, Module> peripheralModulesMappedByName;
|
std::map<std::string, Peripheral, std::less<void>> peripheralsByKey;
|
||||||
std::map<std::string, std::vector<RegisterGroup>> peripheralRegisterGroupsMappedByModuleRegisterGroupName;
|
std::map<std::string, std::vector<RegisterGroup>> peripheralRegisterGroupsMappedByModuleRegisterGroupName;
|
||||||
std::vector<Variant> variants;
|
std::vector<Variant> variants;
|
||||||
std::map<std::string, Pinout> pinoutsMappedByName;
|
std::map<std::string, Pinout> pinoutsMappedByName;
|
||||||
@@ -144,6 +154,9 @@ namespace Targets::TargetDescription
|
|||||||
static RegisterGroupReference registerGroupReferenceFromXml(const QDomElement& xmlElement);
|
static RegisterGroupReference registerGroupReferenceFromXml(const QDomElement& xmlElement);
|
||||||
static Register registerFromXml(const QDomElement& xmlElement);
|
static Register registerFromXml(const QDomElement& xmlElement);
|
||||||
static BitField bitFieldFromXml(const QDomElement& xmlElement);
|
static BitField bitFieldFromXml(const QDomElement& xmlElement);
|
||||||
|
static Peripheral peripheralFromXml(const QDomElement& xmlElement);
|
||||||
|
static RegisterGroupInstance registerGroupInstanceFromXml(const QDomElement& xmlElement);
|
||||||
|
static Signal signalFromXml(const QDomElement& xmlElement);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Fetches a device attribute value by name. Throws an exception if the attribute is not found.
|
* Fetches a device attribute value by name. Throws an exception if the attribute is not found.
|
||||||
@@ -153,11 +166,6 @@ namespace Targets::TargetDescription
|
|||||||
*/
|
*/
|
||||||
const std::string& deviceAttribute(const std::string& attributeName) const;
|
const std::string& deviceAttribute(const std::string& attributeName) const;
|
||||||
|
|
||||||
/**
|
|
||||||
* Extracts all peripheral modules and loads them into this->peripheralModulesMappedByName.
|
|
||||||
*/
|
|
||||||
void loadPeripheralModules(const QDomDocument& document);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Extracts all variants and loads them into this->variants.
|
* Extracts all variants and loads them into this->variants.
|
||||||
*/
|
*/
|
||||||
|
|||||||
Reference in New Issue
Block a user