2024-03-28 21:10:08 +00:00
|
|
|
#include "EdbgAvr8Session.hpp"
|
|
|
|
|
|
|
|
|
|
#include "src/Services/StringService.hpp"
|
|
|
|
|
|
|
|
|
|
#include "src/Exceptions/Exception.hpp"
|
|
|
|
|
|
|
|
|
|
namespace DebugToolDrivers::Microchip::Protocols::Edbg::Avr
|
|
|
|
|
{
|
|
|
|
|
EdbgAvr8Session::EdbgAvr8Session(
|
2024-07-23 21:14:22 +01:00
|
|
|
const Targets::Microchip::Avr8::TargetDescriptionFile& targetDescriptionFile,
|
|
|
|
|
const Targets::Microchip::Avr8::Avr8TargetConfig& targetConfig
|
2024-03-28 21:10:08 +00:00
|
|
|
)
|
|
|
|
|
: targetDescriptionFile(targetDescriptionFile)
|
|
|
|
|
, targetConfig(targetConfig)
|
|
|
|
|
, programAddressSpace(this->targetDescriptionFile.getProgramAddressSpace())
|
2024-07-23 21:14:22 +01:00
|
|
|
, registerFileAddressSpace(this->targetDescriptionFile.getRegisterFileAddressSpace())
|
|
|
|
|
, dataAddressSpace(this->targetDescriptionFile.getDataAddressSpace())
|
2024-03-28 21:10:08 +00:00
|
|
|
, eepromAddressSpace(this->targetDescriptionFile.getEepromAddressSpace())
|
|
|
|
|
, ioAddressSpace(this->targetDescriptionFile.getIoAddressSpace())
|
|
|
|
|
, signatureAddressSpace(this->targetDescriptionFile.getSignatureAddressSpace())
|
|
|
|
|
, programMemorySegment(this->targetDescriptionFile.getProgramMemorySegment())
|
|
|
|
|
, ramMemorySegment(this->targetDescriptionFile.getRamMemorySegment())
|
|
|
|
|
, eepromMemorySegment(this->targetDescriptionFile.getEepromMemorySegment())
|
|
|
|
|
, ioMemorySegment(this->targetDescriptionFile.getIoMemorySegment())
|
2024-11-06 19:46:27 +00:00
|
|
|
, fuseMemorySegment(this->targetDescriptionFile.getFuseMemorySegment())
|
2024-03-28 21:10:08 +00:00
|
|
|
, signatureMemorySegment(this->targetDescriptionFile.getSignatureMemorySegment())
|
|
|
|
|
, programAppSection(this->programMemorySegment.tryGetSection("app_section"))
|
|
|
|
|
, programBootSection(this->programMemorySegment.tryGetSection("boot_section"))
|
|
|
|
|
{
|
|
|
|
|
using Services::StringService;
|
|
|
|
|
|
|
|
|
|
const auto ocdDataRegisterProperty = this->targetDescriptionFile.tryGetProperty("ocd", "ocd_datareg");
|
|
|
|
|
if (ocdDataRegisterProperty.has_value()) {
|
|
|
|
|
this->ocdDataRegister = StringService::toUint8(ocdDataRegisterProperty->get().value);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const auto resolvedConfigVariant = EdbgAvr8Session::tryResolveConfigVariant(
|
|
|
|
|
this->targetDescriptionFile.getAvrFamily(),
|
|
|
|
|
this->targetConfig.physicalInterface
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
if (!resolvedConfigVariant.has_value()) {
|
2024-07-23 21:14:22 +01:00
|
|
|
throw Exceptions::Exception{
|
2024-03-28 21:10:08 +00:00
|
|
|
"Failed to resolve EDBG config variant from the selected physical interface and the AVR target family"
|
|
|
|
|
" - please review the selected physical interface"
|
2024-07-23 21:14:22 +01:00
|
|
|
};
|
2024-03-28 21:10:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
this->configVariant = *resolvedConfigVariant;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::optional<Avr8ConfigVariant> EdbgAvr8Session::tryResolveConfigVariant(
|
2024-07-23 21:14:22 +01:00
|
|
|
Targets::Microchip::Avr8::Family avrFamily,
|
2024-03-28 21:10:08 +00:00
|
|
|
Targets::TargetPhysicalInterface physicalInterface
|
|
|
|
|
) {
|
2024-07-23 21:14:22 +01:00
|
|
|
using Targets::Microchip::Avr8::Family;
|
2024-03-28 21:10:08 +00:00
|
|
|
using Targets::TargetPhysicalInterface;
|
|
|
|
|
|
|
|
|
|
if (avrFamily == Family::MEGA || avrFamily == Family::TINY) {
|
|
|
|
|
switch (physicalInterface) {
|
|
|
|
|
case TargetPhysicalInterface::JTAG: {
|
|
|
|
|
return Avr8ConfigVariant::MEGAJTAG;
|
|
|
|
|
}
|
|
|
|
|
case TargetPhysicalInterface::DEBUG_WIRE: {
|
|
|
|
|
return Avr8ConfigVariant::DEBUG_WIRE;
|
|
|
|
|
}
|
|
|
|
|
case TargetPhysicalInterface::UPDI: {
|
|
|
|
|
return Avr8ConfigVariant::UPDI;
|
|
|
|
|
}
|
|
|
|
|
default: {
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (avrFamily == Family::XMEGA) {
|
|
|
|
|
switch (physicalInterface) {
|
|
|
|
|
case TargetPhysicalInterface::JTAG:
|
|
|
|
|
case TargetPhysicalInterface::PDI: {
|
|
|
|
|
return Avr8ConfigVariant::XMEGA;
|
|
|
|
|
}
|
|
|
|
|
default: {
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (avrFamily == Family::DA || avrFamily == Family::DB || avrFamily == Family::DD || avrFamily == Family::EA) {
|
|
|
|
|
switch (physicalInterface) {
|
|
|
|
|
case TargetPhysicalInterface::UPDI: {
|
|
|
|
|
return Avr8ConfigVariant::UPDI;
|
|
|
|
|
}
|
|
|
|
|
default: {
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return std::nullopt;
|
|
|
|
|
}
|
|
|
|
|
}
|