Updated TDF module, register group, register group reference, register and bit field extraction to align with new TDF format
This commit is contained in:
70
src/Targets/TargetDescription/Register.hpp
Normal file
70
src/Targets/TargetDescription/Register.hpp
Normal file
@@ -0,0 +1,70 @@
|
||||
#pragma once
|
||||
|
||||
#include <cstdint>
|
||||
#include <string>
|
||||
#include <optional>
|
||||
#include <map>
|
||||
#include <functional>
|
||||
|
||||
#include "BitField.hpp"
|
||||
|
||||
#include "Exceptions/InvalidTargetDescriptionDataException.hpp"
|
||||
|
||||
namespace Targets::TargetDescription
|
||||
{
|
||||
struct Register
|
||||
{
|
||||
std::string key;
|
||||
std::string name;
|
||||
std::optional<std::string> description;
|
||||
std::uint32_t offset;
|
||||
std::uint16_t size;
|
||||
std::optional<std::uint64_t> initialValue;
|
||||
std::optional<std::string> access;
|
||||
std::optional<bool> alternative;
|
||||
std::map<std::string, BitField, std::less<void>> bitFieldsByKey;
|
||||
|
||||
Register(
|
||||
const std::string& key,
|
||||
const std::string& name,
|
||||
const std::optional<std::string>& description,
|
||||
std::uint32_t offset,
|
||||
std::uint16_t size,
|
||||
const std::optional<std::uint64_t>& initialValue,
|
||||
const std::optional<std::string>& access,
|
||||
const std::optional<bool>& alternative,
|
||||
const std::map<std::string, BitField, std::less<void>>& bitFieldsByKey
|
||||
)
|
||||
: key(key)
|
||||
, name(name)
|
||||
, description(description)
|
||||
, offset(offset)
|
||||
, size(size)
|
||||
, initialValue(initialValue)
|
||||
, access(access)
|
||||
, alternative(alternative)
|
||||
, bitFieldsByKey(bitFieldsByKey)
|
||||
{}
|
||||
|
||||
std::optional<std::reference_wrapper<const BitField>> tryGetBitField(std::string_view key) const {
|
||||
const auto bitFieldIt = this->bitFieldsByKey.find(key);
|
||||
|
||||
if (bitFieldIt == this->bitFieldsByKey.end()) {
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
return std::cref(bitFieldIt->second);
|
||||
}
|
||||
|
||||
const BitField& getBitField(std::string_view key) const {
|
||||
const auto bitField = this->tryGetBitField(key);
|
||||
if (!bitField.has_value()) {
|
||||
throw Exceptions::InvalidTargetDescriptionDataException(
|
||||
"Failed to get bit field \"" + std::string(key) + "\" from register in TDF - bit field not found"
|
||||
);
|
||||
}
|
||||
|
||||
return bitField->get();
|
||||
}
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user