2021-04-04 21:04:12 +01:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
|
|
#include <cstdint>
|
2022-10-09 13:10:17 +01:00
|
|
|
#include <optional>
|
2021-04-04 21:04:12 +01:00
|
|
|
|
2024-02-13 20:22:18 +00:00
|
|
|
#include "MemorySegmentSection.hpp"
|
|
|
|
|
|
|
|
|
|
#include "src/Services/StringService.hpp"
|
2024-02-13 20:48:06 +00:00
|
|
|
#include "Exceptions/InvalidTargetDescriptionDataException.hpp"
|
2021-04-04 21:04:12 +01:00
|
|
|
|
2023-08-13 15:47:51 +01:00
|
|
|
namespace Targets::TargetDescription
|
2021-04-04 21:04:12 +01:00
|
|
|
{
|
2023-12-19 21:54:30 +00:00
|
|
|
enum class MemorySegmentType: std::uint8_t
|
2021-06-22 23:52:31 +01:00
|
|
|
{
|
2023-12-19 21:54:30 +00:00
|
|
|
ALIASED,
|
2021-04-04 21:04:12 +01:00
|
|
|
REGISTERS,
|
|
|
|
|
EEPROM,
|
|
|
|
|
FLASH,
|
|
|
|
|
FUSES,
|
2023-12-19 21:54:30 +00:00
|
|
|
IO,
|
|
|
|
|
RAM,
|
2021-04-04 21:04:12 +01:00
|
|
|
LOCKBITS,
|
|
|
|
|
OSCCAL,
|
2024-02-13 20:22:18 +00:00
|
|
|
PRODUCTION_SIGNATURES,
|
2023-12-19 21:54:30 +00:00
|
|
|
SIGNATURES,
|
|
|
|
|
USER_SIGNATURES,
|
2021-04-04 21:04:12 +01:00
|
|
|
};
|
|
|
|
|
|
2021-05-31 01:01:14 +01:00
|
|
|
struct MemorySegment
|
|
|
|
|
{
|
2024-02-13 20:22:18 +00:00
|
|
|
std::string key;
|
2021-04-04 21:04:12 +01:00
|
|
|
std::string name;
|
|
|
|
|
MemorySegmentType type;
|
|
|
|
|
std::uint32_t startAddress;
|
|
|
|
|
std::uint32_t size;
|
|
|
|
|
std::optional<std::uint16_t> pageSize;
|
2024-02-13 20:22:18 +00:00
|
|
|
std::map<std::string, MemorySegmentSection, std::less<void>> sectionsByKey;
|
|
|
|
|
|
|
|
|
|
MemorySegment(
|
|
|
|
|
const std::string& key,
|
|
|
|
|
const std::string& name,
|
|
|
|
|
MemorySegmentType type,
|
|
|
|
|
std::uint32_t startAddress,
|
|
|
|
|
std::uint32_t size,
|
|
|
|
|
const std::optional<std::uint16_t>& pageSize,
|
|
|
|
|
const std::map<std::string, MemorySegmentSection, std::less<void>>& sectionsByKey
|
|
|
|
|
)
|
|
|
|
|
: key(key)
|
|
|
|
|
, name(name)
|
|
|
|
|
, type(type)
|
|
|
|
|
, startAddress(startAddress)
|
|
|
|
|
, size(size)
|
|
|
|
|
, pageSize(pageSize)
|
|
|
|
|
, sectionsByKey(sectionsByKey)
|
|
|
|
|
{}
|
|
|
|
|
|
|
|
|
|
std::optional<std::reference_wrapper<const MemorySegmentSection>> tryGetSection(
|
|
|
|
|
std::string_view keyStr
|
|
|
|
|
) const {
|
|
|
|
|
const auto keys = Services::StringService::split(keyStr, '.');
|
|
|
|
|
|
|
|
|
|
const auto firstSubgroupIt = this->sectionsByKey.find(*keys.begin());
|
|
|
|
|
return firstSubgroupIt != this->sectionsByKey.end()
|
|
|
|
|
? keys.size() > 1
|
|
|
|
|
? firstSubgroupIt->second.tryGetSubSection(keys | std::ranges::views::drop(1))
|
|
|
|
|
: std::optional(std::cref(firstSubgroupIt->second))
|
|
|
|
|
: std::nullopt;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::optional<std::reference_wrapper<const MemorySegmentSection>> getSection(
|
|
|
|
|
std::string_view keyStr
|
|
|
|
|
) const {
|
|
|
|
|
const auto propertyGroup = this->tryGetSection(keyStr);
|
|
|
|
|
if (!propertyGroup.has_value()) {
|
2024-02-13 20:48:06 +00:00
|
|
|
throw Exceptions::InvalidTargetDescriptionDataException(
|
2024-02-13 20:22:18 +00:00
|
|
|
"Failed to get memory segment section \"" + std::string(keyStr)
|
2024-02-13 20:48:06 +00:00
|
|
|
+ "\" from memory segment in TDF - section not found"
|
2024-02-13 20:22:18 +00:00
|
|
|
);
|
|
|
|
|
}
|
2021-04-04 21:04:12 +01:00
|
|
|
|
2024-02-13 20:22:18 +00:00
|
|
|
return propertyGroup->get();
|
|
|
|
|
}
|
2021-04-04 21:04:12 +01:00
|
|
|
};
|
|
|
|
|
}
|