From 3d95a983b6c85283935c517524e0f0d24bbf5af2 Mon Sep 17 00:00:00 2001 From: Nav Date: Wed, 16 Mar 2022 17:12:52 +0000 Subject: [PATCH] EDBG implementation of the TargetPowerManagementInterface --- .../EdbgTargetPowerManagementInterface.cpp | 34 +++++++++++++++++++ .../EdbgTargetPowerManagementInterface.hpp | 29 ++++++++++++++++ 2 files changed, 63 insertions(+) create mode 100644 src/DebugToolDrivers/Protocols/CMSIS-DAP/VendorSpecific/EDBG/EdbgTargetPowerManagementInterface.cpp create mode 100644 src/DebugToolDrivers/Protocols/CMSIS-DAP/VendorSpecific/EDBG/EdbgTargetPowerManagementInterface.hpp diff --git a/src/DebugToolDrivers/Protocols/CMSIS-DAP/VendorSpecific/EDBG/EdbgTargetPowerManagementInterface.cpp b/src/DebugToolDrivers/Protocols/CMSIS-DAP/VendorSpecific/EDBG/EdbgTargetPowerManagementInterface.cpp new file mode 100644 index 00000000..b30847ce --- /dev/null +++ b/src/DebugToolDrivers/Protocols/CMSIS-DAP/VendorSpecific/EDBG/EdbgTargetPowerManagementInterface.cpp @@ -0,0 +1,34 @@ +#include "EdbgTargetPowerManagementInterface.hpp" + +#include "src/DebugToolDrivers/Protocols/CMSIS-DAP/VendorSpecific/EDBG/AVR/CommandFrames/EDBGControl/GetParameter.hpp" +#include "src/DebugToolDrivers/Protocols/CMSIS-DAP/VendorSpecific/EDBG/AVR/CommandFrames/EDBGControl/SetParameter.hpp" + +namespace Bloom::DebugToolDrivers::Protocols::CmsisDap::Edbg +{ + using namespace Bloom::Exceptions; + + using Protocols::CmsisDap::Edbg::Avr::ResponseFrames::EdbgControl::EdbgControlResponseId; + + using Protocols::CmsisDap::Edbg::Avr::CommandFrames::EdbgControl::GetParameter; + using Protocols::CmsisDap::Edbg::Avr::CommandFrames::EdbgControl::SetParameter; + + void EdbgTargetPowerManagementInterface::enableTargetPower() { + auto response = this->edbgInterface.sendAvrCommandFrameAndWaitForResponseFrame( + SetParameter(EdbgParameters::CONTROL_TARGET_POWER, 0x01) + ); + + if (response.getResponseId() == EdbgControlResponseId::FAILED) { + throw Exception("Failed to enable target power via EDBG Control protocol"); + } + } + + void EdbgTargetPowerManagementInterface::disableTargetPower() { + auto response = this->edbgInterface.sendAvrCommandFrameAndWaitForResponseFrame( + SetParameter(EdbgParameters::CONTROL_TARGET_POWER, 0x00) + ); + + if (response.getResponseId() == EdbgControlResponseId::FAILED) { + throw Exception("Failed to disable target power via EDBG Control protocol"); + } + } +} diff --git a/src/DebugToolDrivers/Protocols/CMSIS-DAP/VendorSpecific/EDBG/EdbgTargetPowerManagementInterface.hpp b/src/DebugToolDrivers/Protocols/CMSIS-DAP/VendorSpecific/EDBG/EdbgTargetPowerManagementInterface.hpp new file mode 100644 index 00000000..7e2e65f8 --- /dev/null +++ b/src/DebugToolDrivers/Protocols/CMSIS-DAP/VendorSpecific/EDBG/EdbgTargetPowerManagementInterface.hpp @@ -0,0 +1,29 @@ +#pragma once + +#include + +#include "src/DebugToolDrivers/TargetInterfaces/TargetPowerManagementInterface.hpp" +#include "src/DebugToolDrivers/Protocols/CMSIS-DAP/VendorSpecific/EDBG/EdbgInterface.hpp" + +namespace Bloom::DebugToolDrivers::Protocols::CmsisDap::Edbg +{ + class EdbgTargetPowerManagementInterface: public TargetInterfaces::TargetPowerManagementInterface + { + public: + explicit EdbgTargetPowerManagementInterface(EdbgInterface& edbgInterface) + : edbgInterface(edbgInterface) {}; + + /** + * Issues a Set Parameter command to the EDBG tool, to enable the target power. + */ + void enableTargetPower() override; + + /** + * Issues a Set Parameter command to the EDBG tool, to disable the target power. + */ + void disableTargetPower() override; + + private: + EdbgInterface& edbgInterface; + }; +}