diff --git a/src/Targets/Microchip/AVR/AVR8/TargetDescription/TargetDescriptionFile.cpp b/src/Targets/Microchip/AVR/AVR8/TargetDescription/TargetDescriptionFile.cpp index e61df91c..85dcde16 100644 --- a/src/Targets/Microchip/AVR/AVR8/TargetDescription/TargetDescriptionFile.cpp +++ b/src/Targets/Microchip/AVR/AVR8/TargetDescription/TargetDescriptionFile.cpp @@ -284,6 +284,98 @@ namespace Bloom::Targets::Microchip::Avr::Avr8Bit::TargetDescription return targetParameters; } + IspParameters TargetDescriptionFile::getIspParameters() const { + if (!this->propertyGroupsMappedByName.contains("isp_interface")) { + throw Exception("TDF missing ISP parameters"); + } + + const auto& ispParameterPropertiesByName = this->propertyGroupsMappedByName.at( + "isp_interface" + ).propertiesMappedByName; + + if (!ispParameterPropertiesByName.contains("ispenterprogmode_timeout")) { + throw Exception("TDF missing ISP programming mode timeout property"); + } + + if (!ispParameterPropertiesByName.contains("ispenterprogmode_stabdelay")) { + throw Exception("TDF missing ISP programming mode stabilization delay property"); + } + + if (!ispParameterPropertiesByName.contains("ispenterprogmode_cmdexedelay")) { + throw Exception("TDF missing ISP programming mode command execution delay property"); + } + + if (!ispParameterPropertiesByName.contains("ispenterprogmode_synchloops")) { + throw Exception("TDF missing ISP programming mode sync loops property"); + } + + if (!ispParameterPropertiesByName.contains("ispenterprogmode_bytedelay")) { + throw Exception("TDF missing ISP programming mode byte delay property"); + } + + if (!ispParameterPropertiesByName.contains("ispenterprogmode_pollindex")) { + throw Exception("TDF missing ISP programming mode poll index property"); + } + + if (!ispParameterPropertiesByName.contains("ispenterprogmode_pollvalue")) { + throw Exception("TDF missing ISP programming mode poll value property"); + } + + if (!ispParameterPropertiesByName.contains("ispleaveprogmode_predelay")) { + throw Exception("TDF missing ISP programming mode pre-delay property"); + } + + if (!ispParameterPropertiesByName.contains("ispleaveprogmode_postdelay")) { + throw Exception("TDF missing ISP programming mode post-delay property"); + } + + if (!ispParameterPropertiesByName.contains("ispreadsign_pollindex")) { + throw Exception("TDF missing ISP read signature poll index property"); + } + + if (!ispParameterPropertiesByName.contains("ispreadfuse_pollindex")) { + throw Exception("TDF missing ISP read fuse poll index property"); + } + + auto output = IspParameters(); + + output.programModeTimeout = static_cast( + ispParameterPropertiesByName.at("ispenterprogmode_timeout").value.toUShort() + ); + output.programModeStabilizationDelay = static_cast( + ispParameterPropertiesByName.at("ispenterprogmode_stabdelay").value.toUShort() + ); + output.programModeCommandExecutionDelay = static_cast( + ispParameterPropertiesByName.at("ispenterprogmode_cmdexedelay").value.toUShort() + ); + output.programModeSyncLoops = static_cast( + ispParameterPropertiesByName.at("ispenterprogmode_synchloops").value.toUShort() + ); + output.programModeByteDelay = static_cast( + ispParameterPropertiesByName.at("ispenterprogmode_bytedelay").value.toUShort() + ); + output.programModePollValue = static_cast( + ispParameterPropertiesByName.at("ispenterprogmode_pollvalue").value.toUShort(nullptr, 16) + ); + output.programModePollIndex = static_cast( + ispParameterPropertiesByName.at("ispenterprogmode_pollindex").value.toUShort() + ); + output.programModePreDelay = static_cast( + ispParameterPropertiesByName.at("ispleaveprogmode_predelay").value.toUShort() + ); + output.programModePostDelay = static_cast( + ispParameterPropertiesByName.at("ispleaveprogmode_postdelay").value.toUShort() + ); + output.readSignaturePollIndex = static_cast( + ispParameterPropertiesByName.at("ispreadsign_pollindex").value.toUShort() + ); + output.readFusePollIndex = static_cast( + ispParameterPropertiesByName.at("ispreadfuse_pollindex").value.toUShort() + ); + + return output; + } + void TargetDescriptionFile::loadDebugPhysicalInterfaces() { auto interfaceNamesToInterfaces = std::map({ {"updi", PhysicalInterface::UPDI}, diff --git a/src/Targets/Microchip/AVR/AVR8/TargetDescription/TargetDescriptionFile.hpp b/src/Targets/Microchip/AVR/AVR8/TargetDescription/TargetDescriptionFile.hpp index 95e374d8..b2f6f895 100644 --- a/src/Targets/Microchip/AVR/AVR8/TargetDescription/TargetDescriptionFile.hpp +++ b/src/Targets/Microchip/AVR/AVR8/TargetDescription/TargetDescriptionFile.hpp @@ -5,6 +5,7 @@ #include "src/Targets/TargetDescription/TargetDescriptionFile.hpp" #include "src/Targets/Microchip/AVR/TargetSignature.hpp" +#include "src/Targets/Microchip/AVR/IspParameters.hpp" #include "src/Targets/Microchip/AVR/AVR8/Family.hpp" #include "src/Targets/Microchip/AVR/AVR8/PhysicalInterface.hpp" #include "src/Targets/Microchip/AVR/AVR8/TargetParameters.hpp" @@ -72,6 +73,13 @@ namespace Bloom::Targets::Microchip::Avr::Avr8Bit::TargetDescription */ [[nodiscard]] TargetParameters getTargetParameters() const; + /** + * Extracts the target's ISP parameters from the TDF. + * + * @return + */ + [[nodiscard]] IspParameters getIspParameters() const; + /** * Returns a set of all supported physical interfaces for debugging. * diff --git a/src/Targets/Microchip/AVR/IspParameters.hpp b/src/Targets/Microchip/AVR/IspParameters.hpp new file mode 100644 index 00000000..06176c8d --- /dev/null +++ b/src/Targets/Microchip/AVR/IspParameters.hpp @@ -0,0 +1,26 @@ +#pragma once + +#include + +namespace Bloom::Targets::Microchip::Avr +{ + /** + * These parameters are required by the ISP interface. They can be extracted from the target's TDF. + */ + struct IspParameters + { + std::uint8_t programModeTimeout; + std::uint8_t programModeStabilizationDelay; + std::uint8_t programModeCommandExecutionDelay; + std::uint8_t programModeSyncLoops; + std::uint8_t programModeByteDelay; + std::uint8_t programModePollValue; + std::uint8_t programModePollIndex; + std::uint8_t programModePreDelay; + std::uint8_t programModePostDelay; + + std::uint8_t readSignaturePollIndex; + + std::uint8_t readFusePollIndex; + }; +}