Removed using namespace directive for class member function definitions in source files

This commit is contained in:
Nav
2022-02-05 15:32:08 +00:00
parent 9bbc534973
commit 53a3c815d7
116 changed files with 13113 additions and 12664 deletions

View File

@@ -3,90 +3,98 @@
#include "src/TargetController/Exceptions/DeviceFailure.hpp"
#include "src/TargetController/Exceptions/DeviceInitializationFailure.hpp"
using namespace Bloom::DebugToolDrivers;
using namespace Bloom::DebugToolDrivers::Protocols::CmsisDap::Edbg::Avr;
using namespace Bloom::Exceptions;
namespace Bloom::DebugToolDrivers
{
using namespace Protocols::CmsisDap::Edbg::Avr;
using namespace Bloom::Exceptions;
void AtmelIce::init() {
UsbDevice::init();
void AtmelIce::init() {
UsbDevice::init();
// TODO: Move away from hard-coding the CMSIS-DAP/EDBG interface number
auto& usbHidInterface = this->getEdbgInterface().getUsbHidInterface();
usbHidInterface.setNumber(0);
usbHidInterface.setLibUsbDevice(this->libUsbDevice);
usbHidInterface.setLibUsbDeviceHandle(this->libUsbDeviceHandle);
usbHidInterface.setVendorId(this->vendorId);
usbHidInterface.setProductId(this->productId);
// TODO: Move away from hard-coding the CMSIS-DAP/EDBG interface number
auto& usbHidInterface = this->getEdbgInterface().getUsbHidInterface();
usbHidInterface.setNumber(0);
usbHidInterface.setLibUsbDevice(this->libUsbDevice);
usbHidInterface.setLibUsbDeviceHandle(this->libUsbDeviceHandle);
usbHidInterface.setVendorId(this->vendorId);
usbHidInterface.setProductId(this->productId);
if (!usbHidInterface.isInitialised()) {
usbHidInterface.detachKernelDriver();
this->setConfiguration(0);
usbHidInterface.init();
if (!usbHidInterface.isInitialised()) {
usbHidInterface.detachKernelDriver();
this->setConfiguration(0);
usbHidInterface.init();
}
/*
* The Atmel-ICE EDBG/CMSIS-DAP interface doesn't operate properly when sending commands too quickly.
*
* Because of this, we have to enforce a minimum time gap between commands. See comment
* in CmsisDapInterface class declaration for more info.
*/
this->getEdbgInterface().setMinimumCommandTimeGap(std::chrono::milliseconds(35));
// We don't need to claim the CMSISDAP interface here as the HIDAPI will have already done so.
if (!this->sessionStarted) {
this->startSession();
}
this->edbgAvr8Interface = std::make_unique<EdbgAvr8Interface>(this->edbgInterface);
this->setInitialised(true);
}
/*
* The Atmel-ICE EDBG/CMSIS-DAP interface doesn't operate properly when sending commands too quickly.
*
* Because of this, we have to enforce a minimum time gap between commands. See comment
* in CmsisDapInterface class declaration for more info.
*/
this->getEdbgInterface().setMinimumCommandTimeGap(std::chrono::milliseconds(35));
void AtmelIce::close() {
if (this->sessionStarted) {
this->endSession();
}
// We don't need to claim the CMSISDAP interface here as the HIDAPI will have already done so.
if (!this->sessionStarted) {
this->startSession();
this->getEdbgInterface().getUsbHidInterface().close();
UsbDevice::close();
}
this->edbgAvr8Interface = std::make_unique<EdbgAvr8Interface>(this->edbgInterface);
this->setInitialised(true);
}
std::string AtmelIce::getSerialNumber() {
using namespace CommandFrames::Discovery;
void AtmelIce::close() {
if (this->sessionStarted) {
this->endSession();
}
this->getEdbgInterface().getUsbHidInterface().close();
UsbDevice::close();
}
std::string AtmelIce::getSerialNumber() {
auto response = this->getEdbgInterface().sendAvrCommandFrameAndWaitForResponseFrame(
CommandFrames::Discovery::Query(CommandFrames::Discovery::QueryContext::SERIAL_NUMBER)
);
if (response.getResponseId() != CommandFrames::Discovery::ResponseId::OK) {
throw DeviceInitializationFailure(
"Failed to fetch serial number from device - invalid Discovery Protocol response ID."
auto response = this->getEdbgInterface().sendAvrCommandFrameAndWaitForResponseFrame(
Query(QueryContext::SERIAL_NUMBER)
);
if (response.getResponseId() != ResponseId::OK) {
throw DeviceInitializationFailure(
"Failed to fetch serial number from device - invalid Discovery Protocol response ID."
);
}
auto data = response.getPayloadData();
return std::string(data.begin(), data.end());
}
auto data = response.getPayloadData();
return std::string(data.begin(), data.end());
}
void AtmelIce::startSession() {
using namespace CommandFrames::HouseKeeping;
void AtmelIce::startSession() {
auto response = this->getEdbgInterface().sendAvrCommandFrameAndWaitForResponseFrame(
CommandFrames::HouseKeeping::StartSession()
);
auto response = this->getEdbgInterface().sendAvrCommandFrameAndWaitForResponseFrame(
StartSession()
);
if (response.getResponseId() == CommandFrames::HouseKeeping::ResponseId::FAILED) {
// Failed response returned!
throw DeviceInitializationFailure("Failed to start session with Atmel-ICE!");
if (response.getResponseId() == ResponseId::FAILED) {
// Failed response returned!
throw DeviceInitializationFailure("Failed to start session with Atmel-ICE!");
}
this->sessionStarted = true;
}
this->sessionStarted = true;
}
void AtmelIce::endSession() {
using namespace CommandFrames::HouseKeeping;
void AtmelIce::endSession() {
auto response = this->getEdbgInterface().sendAvrCommandFrameAndWaitForResponseFrame(
CommandFrames::HouseKeeping::EndSession()
);
auto response = this->getEdbgInterface().sendAvrCommandFrameAndWaitForResponseFrame(
EndSession()
);
if (response.getResponseId() == CommandFrames::HouseKeeping::ResponseId::FAILED) {
// Failed response returned!
throw DeviceFailure("Failed to end session with Atmel-ICE!");
if (response.getResponseId() == ResponseId::FAILED) {
// Failed response returned!
throw DeviceFailure("Failed to end session with Atmel-ICE!");
}
this->sessionStarted = false;
}
this->sessionStarted = false;
}

View File

@@ -3,82 +3,90 @@
#include "src/TargetController/Exceptions/DeviceFailure.hpp"
#include "src/TargetController/Exceptions/DeviceInitializationFailure.hpp"
using namespace Bloom::DebugToolDrivers;
using namespace Bloom::DebugToolDrivers::Protocols::CmsisDap::Edbg::Avr;
using namespace Bloom::Exceptions;
namespace Bloom::DebugToolDrivers
{
using namespace Protocols::CmsisDap::Edbg::Avr;
using namespace Bloom::Exceptions;
void CuriosityNano::init() {
UsbDevice::init();
void CuriosityNano::init() {
UsbDevice::init();
// TODO: Move away from hard-coding the CMSIS-DAP/EDBG interface number
auto& usbHidInterface = this->getEdbgInterface().getUsbHidInterface();
usbHidInterface.setNumber(0);
usbHidInterface.setLibUsbDevice(this->libUsbDevice);
usbHidInterface.setLibUsbDeviceHandle(this->libUsbDeviceHandle);
usbHidInterface.setVendorId(this->vendorId);
usbHidInterface.setProductId(this->productId);
// TODO: Move away from hard-coding the CMSIS-DAP/EDBG interface number
auto& usbHidInterface = this->getEdbgInterface().getUsbHidInterface();
usbHidInterface.setNumber(0);
usbHidInterface.setLibUsbDevice(this->libUsbDevice);
usbHidInterface.setLibUsbDeviceHandle(this->libUsbDeviceHandle);
usbHidInterface.setVendorId(this->vendorId);
usbHidInterface.setProductId(this->productId);
if (!usbHidInterface.isInitialised()) {
usbHidInterface.detachKernelDriver();
usbHidInterface.init();
if (!usbHidInterface.isInitialised()) {
usbHidInterface.detachKernelDriver();
usbHidInterface.init();
}
this->getEdbgInterface().setMinimumCommandTimeGap(std::chrono::milliseconds(35));
if (!this->sessionStarted) {
this->startSession();
}
this->edbgAvr8Interface = std::make_unique<EdbgAvr8Interface>(this->edbgInterface);
this->setInitialised(true);
}
this->getEdbgInterface().setMinimumCommandTimeGap(std::chrono::milliseconds(35));
void CuriosityNano::close() {
if (this->sessionStarted) {
this->endSession();
}
if (!this->sessionStarted) {
this->startSession();
this->getEdbgInterface().getUsbHidInterface().close();
UsbDevice::close();
}
this->edbgAvr8Interface = std::make_unique<EdbgAvr8Interface>(this->edbgInterface);
this->setInitialised(true);
}
std::string CuriosityNano::getSerialNumber() {
using namespace CommandFrames::Discovery;
void CuriosityNano::close() {
if (this->sessionStarted) {
this->endSession();
}
this->getEdbgInterface().getUsbHidInterface().close();
UsbDevice::close();
}
std::string CuriosityNano::getSerialNumber() {
auto response = this->getEdbgInterface().sendAvrCommandFrameAndWaitForResponseFrame(
CommandFrames::Discovery::Query(CommandFrames::Discovery::QueryContext::SERIAL_NUMBER)
);
if (response.getResponseId() != CommandFrames::Discovery::ResponseId::OK) {
throw DeviceInitializationFailure(
"Failed to fetch serial number from device - invalid Discovery Protocol response ID."
auto response = this->getEdbgInterface().sendAvrCommandFrameAndWaitForResponseFrame(
Query(QueryContext::SERIAL_NUMBER)
);
if (response.getResponseId() != ResponseId::OK) {
throw DeviceInitializationFailure(
"Failed to fetch serial number from device - invalid Discovery Protocol response ID."
);
}
auto data = response.getPayloadData();
return std::string(data.begin(), data.end());
}
auto data = response.getPayloadData();
return std::string(data.begin(), data.end());
}
void CuriosityNano::startSession() {
using namespace CommandFrames::HouseKeeping;
void CuriosityNano::startSession() {
auto response = this->getEdbgInterface().sendAvrCommandFrameAndWaitForResponseFrame(
CommandFrames::HouseKeeping::StartSession()
);
auto response = this->getEdbgInterface().sendAvrCommandFrameAndWaitForResponseFrame(
StartSession()
);
if (response.getResponseId() == CommandFrames::HouseKeeping::ResponseId::FAILED) {
// Failed response returned!
throw DeviceInitializationFailure("Failed to start session with Curiosity Nano!");
if (response.getResponseId() == ResponseId::FAILED) {
// Failed response returned!
throw DeviceInitializationFailure("Failed to start session with Curiosity Nano!");
}
this->sessionStarted = true;
}
this->sessionStarted = true;
}
void CuriosityNano::endSession() {
using namespace CommandFrames::HouseKeeping;
void CuriosityNano::endSession() {
auto response = this->getEdbgInterface().sendAvrCommandFrameAndWaitForResponseFrame(
CommandFrames::HouseKeeping::EndSession()
);
auto response = this->getEdbgInterface().sendAvrCommandFrameAndWaitForResponseFrame(
EndSession()
);
if (response.getResponseId() == CommandFrames::HouseKeeping::ResponseId::FAILED) {
// Failed response returned!
throw DeviceFailure("Failed to end session with Curiosity Nano!");
if (response.getResponseId() == ResponseId::FAILED) {
// Failed response returned!
throw DeviceFailure("Failed to end session with Curiosity Nano!");
}
this->sessionStarted = false;
}
this->sessionStarted = false;
}

View File

@@ -3,83 +3,91 @@
#include "src/TargetController/Exceptions/DeviceFailure.hpp"
#include "src/TargetController/Exceptions/DeviceInitializationFailure.hpp"
using namespace Bloom::DebugToolDrivers;
using namespace Bloom::DebugToolDrivers::Protocols::CmsisDap::Edbg::Avr;
using namespace Bloom::Exceptions;
namespace Bloom::DebugToolDrivers
{
using namespace Protocols::CmsisDap::Edbg::Avr;
using namespace Bloom::Exceptions;
void MplabPickit4::init() {
UsbDevice::init();
void MplabPickit4::init() {
UsbDevice::init();
// TODO: Move away from hard-coding the CMSIS-DAP/EDBG interface number
auto& usbHidInterface = this->getEdbgInterface().getUsbHidInterface();
usbHidInterface.setNumber(0);
usbHidInterface.setLibUsbDevice(this->libUsbDevice);
usbHidInterface.setLibUsbDeviceHandle(this->libUsbDeviceHandle);
usbHidInterface.setVendorId(this->vendorId);
usbHidInterface.setProductId(this->productId);
// TODO: Move away from hard-coding the CMSIS-DAP/EDBG interface number
auto& usbHidInterface = this->getEdbgInterface().getUsbHidInterface();
usbHidInterface.setNumber(0);
usbHidInterface.setLibUsbDevice(this->libUsbDevice);
usbHidInterface.setLibUsbDeviceHandle(this->libUsbDeviceHandle);
usbHidInterface.setVendorId(this->vendorId);
usbHidInterface.setProductId(this->productId);
if (!usbHidInterface.isInitialised()) {
usbHidInterface.init();
if (!usbHidInterface.isInitialised()) {
usbHidInterface.init();
}
this->getEdbgInterface().setMinimumCommandTimeGap(std::chrono::milliseconds(35));
// We don't need to claim the CMSISDAP interface here as the HIDAPI will have already done so.
if (!this->sessionStarted) {
this->startSession();
}
this->edbgAvr8Interface = std::make_unique<EdbgAvr8Interface>(this->edbgInterface);
this->setInitialised(true);
}
this->getEdbgInterface().setMinimumCommandTimeGap(std::chrono::milliseconds(35));
void MplabPickit4::close() {
if (this->sessionStarted) {
this->endSession();
}
// We don't need to claim the CMSISDAP interface here as the HIDAPI will have already done so.
if (!this->sessionStarted) {
this->startSession();
this->getEdbgInterface().getUsbHidInterface().close();
UsbDevice::close();
}
this->edbgAvr8Interface = std::make_unique<EdbgAvr8Interface>(this->edbgInterface);
std::string MplabPickit4::getSerialNumber() {
using namespace CommandFrames::Discovery;
this->setInitialised(true);
}
void MplabPickit4::close() {
if (this->sessionStarted) {
this->endSession();
}
this->getEdbgInterface().getUsbHidInterface().close();
UsbDevice::close();
}
std::string MplabPickit4::getSerialNumber() {
auto response = this->getEdbgInterface().sendAvrCommandFrameAndWaitForResponseFrame(
CommandFrames::Discovery::Query(CommandFrames::Discovery::QueryContext::SERIAL_NUMBER)
);
if (response.getResponseId() != CommandFrames::Discovery::ResponseId::OK) {
throw DeviceInitializationFailure(
"Failed to fetch serial number from device - invalid Discovery Protocol response ID."
auto response = this->getEdbgInterface().sendAvrCommandFrameAndWaitForResponseFrame(
Query(QueryContext::SERIAL_NUMBER)
);
if (response.getResponseId() != ResponseId::OK) {
throw DeviceInitializationFailure(
"Failed to fetch serial number from device - invalid Discovery Protocol response ID."
);
}
auto data = response.getPayloadData();
return std::string(data.begin(), data.end());
}
auto data = response.getPayloadData();
return std::string(data.begin(), data.end());
}
void MplabPickit4::startSession() {
using namespace CommandFrames::HouseKeeping;
void MplabPickit4::startSession() {
auto response = this->getEdbgInterface().sendAvrCommandFrameAndWaitForResponseFrame(
CommandFrames::HouseKeeping::StartSession()
);
auto response = this->getEdbgInterface().sendAvrCommandFrameAndWaitForResponseFrame(
StartSession()
);
if (response.getResponseId() == CommandFrames::HouseKeeping::ResponseId::FAILED) {
// Failed response returned!
throw DeviceInitializationFailure("Failed to start session with MPLAB PICkit 4!");
if (response.getResponseId() == ResponseId::FAILED) {
// Failed response returned!
throw DeviceInitializationFailure("Failed to start session with MPLAB PICkit 4!");
}
this->sessionStarted = true;
}
this->sessionStarted = true;
}
void MplabPickit4::endSession() {
using namespace CommandFrames::HouseKeeping;
void MplabPickit4::endSession() {
auto response = this->getEdbgInterface().sendAvrCommandFrameAndWaitForResponseFrame(
CommandFrames::HouseKeeping::EndSession()
);
auto response = this->getEdbgInterface().sendAvrCommandFrameAndWaitForResponseFrame(
EndSession()
);
if (response.getResponseId() == CommandFrames::HouseKeeping::ResponseId::FAILED) {
// Failed response returned!
throw DeviceFailure("Failed to end session with MPLAB PICkit 4!");
if (response.getResponseId() == ResponseId::FAILED) {
// Failed response returned!
throw DeviceFailure("Failed to end session with MPLAB PICkit 4!");
}
this->sessionStarted = false;
}
this->sessionStarted = false;
}

View File

@@ -3,82 +3,90 @@
#include "src/TargetController/Exceptions/DeviceFailure.hpp"
#include "src/TargetController/Exceptions/DeviceInitializationFailure.hpp"
using namespace Bloom::DebugToolDrivers;
using namespace Bloom::DebugToolDrivers::Protocols::CmsisDap::Edbg::Avr;
using namespace Bloom::Exceptions;
namespace Bloom::DebugToolDrivers
{
using namespace Protocols::CmsisDap::Edbg::Avr;
using namespace Bloom::Exceptions;
void MplabSnap::init() {
UsbDevice::init();
void MplabSnap::init() {
UsbDevice::init();
// TODO: Move away from hard-coding the CMSIS-DAP/EDBG interface number
auto& usbHidInterface = this->getEdbgInterface().getUsbHidInterface();
usbHidInterface.setNumber(0);
usbHidInterface.setLibUsbDevice(this->libUsbDevice);
usbHidInterface.setLibUsbDeviceHandle(this->libUsbDeviceHandle);
usbHidInterface.setVendorId(this->vendorId);
usbHidInterface.setProductId(this->productId);
// TODO: Move away from hard-coding the CMSIS-DAP/EDBG interface number
auto& usbHidInterface = this->getEdbgInterface().getUsbHidInterface();
usbHidInterface.setNumber(0);
usbHidInterface.setLibUsbDevice(this->libUsbDevice);
usbHidInterface.setLibUsbDeviceHandle(this->libUsbDeviceHandle);
usbHidInterface.setVendorId(this->vendorId);
usbHidInterface.setProductId(this->productId);
if (!usbHidInterface.isInitialised()) {
usbHidInterface.init();
if (!usbHidInterface.isInitialised()) {
usbHidInterface.init();
}
this->getEdbgInterface().setMinimumCommandTimeGap(std::chrono::milliseconds(35));
// We don't need to claim the CMSISDAP interface here as the HIDAPI will have already done so.
if (!this->sessionStarted) {
this->startSession();
}
this->edbgAvr8Interface = std::make_unique<EdbgAvr8Interface>(this->edbgInterface);
this->setInitialised(true);
}
this->getEdbgInterface().setMinimumCommandTimeGap(std::chrono::milliseconds(35));
void MplabSnap::close() {
if (this->sessionStarted) {
this->endSession();
}
// We don't need to claim the CMSISDAP interface here as the HIDAPI will have already done so.
if (!this->sessionStarted) {
this->startSession();
this->getEdbgInterface().getUsbHidInterface().close();
UsbDevice::close();
}
this->edbgAvr8Interface = std::make_unique<EdbgAvr8Interface>(this->edbgInterface);
this->setInitialised(true);
}
std::string MplabSnap::getSerialNumber() {
using namespace CommandFrames::Discovery;
void MplabSnap::close() {
if (this->sessionStarted) {
this->endSession();
}
this->getEdbgInterface().getUsbHidInterface().close();
UsbDevice::close();
}
std::string MplabSnap::getSerialNumber() {
auto response = this->getEdbgInterface().sendAvrCommandFrameAndWaitForResponseFrame(
CommandFrames::Discovery::Query(CommandFrames::Discovery::QueryContext::SERIAL_NUMBER)
);
if (response.getResponseId() != CommandFrames::Discovery::ResponseId::OK) {
throw DeviceInitializationFailure(
"Failed to fetch serial number from device - invalid Discovery Protocol response ID."
auto response = this->getEdbgInterface().sendAvrCommandFrameAndWaitForResponseFrame(
Query(QueryContext::SERIAL_NUMBER)
);
if (response.getResponseId() != ResponseId::OK) {
throw DeviceInitializationFailure(
"Failed to fetch serial number from device - invalid Discovery Protocol response ID."
);
}
auto data = response.getPayloadData();
return std::string(data.begin(), data.end());
}
auto data = response.getPayloadData();
return std::string(data.begin(), data.end());
}
void MplabSnap::startSession() {
using namespace CommandFrames::HouseKeeping;
void MplabSnap::startSession() {
auto response = this->getEdbgInterface().sendAvrCommandFrameAndWaitForResponseFrame(
CommandFrames::HouseKeeping::StartSession()
);
auto response = this->getEdbgInterface().sendAvrCommandFrameAndWaitForResponseFrame(
StartSession()
);
if (response.getResponseId() == CommandFrames::HouseKeeping::ResponseId::FAILED) {
// Failed response returned!
throw DeviceInitializationFailure("Failed to start session with MPLAB Snap!");
if (response.getResponseId() == ResponseId::FAILED) {
// Failed response returned!
throw DeviceInitializationFailure("Failed to start session with MPLAB Snap!");
}
this->sessionStarted = true;
}
this->sessionStarted = true;
}
void MplabSnap::endSession() {
using namespace CommandFrames::HouseKeeping;
void MplabSnap::endSession() {
auto response = this->getEdbgInterface().sendAvrCommandFrameAndWaitForResponseFrame(
CommandFrames::HouseKeeping::EndSession()
);
auto response = this->getEdbgInterface().sendAvrCommandFrameAndWaitForResponseFrame(
EndSession()
);
if (response.getResponseId() == CommandFrames::HouseKeeping::ResponseId::FAILED) {
// Failed response returned!
throw DeviceFailure("Failed to end session with MPLAB Snap!");
if (response.getResponseId() == ResponseId::FAILED) {
// Failed response returned!
throw DeviceFailure("Failed to end session with MPLAB Snap!");
}
this->sessionStarted = false;
}
this->sessionStarted = false;
}

View File

@@ -3,92 +3,100 @@
#include "src/TargetController/Exceptions/DeviceFailure.hpp"
#include "src/TargetController/Exceptions/DeviceInitializationFailure.hpp"
using namespace Bloom::DebugToolDrivers;
using namespace Bloom::DebugToolDrivers::Protocols::CmsisDap::Edbg::Avr;
using namespace Bloom::Exceptions;
namespace Bloom::DebugToolDrivers
{
using namespace Protocols::CmsisDap::Edbg::Avr;
using namespace Bloom::Exceptions;
using Bloom::DebugToolDrivers::Protocols::CmsisDap::Edbg::Avr::EdbgAvr8Interface;
void PowerDebugger::init() {
UsbDevice::init();
void PowerDebugger::init() {
UsbDevice::init();
// TODO: Move away from hard-coding the CMSIS-DAP/EDBG interface number
auto& usbHidInterface = this->getEdbgInterface().getUsbHidInterface();
usbHidInterface.setNumber(0);
usbHidInterface.setLibUsbDevice(this->libUsbDevice);
usbHidInterface.setLibUsbDeviceHandle(this->libUsbDeviceHandle);
usbHidInterface.setVendorId(this->vendorId);
usbHidInterface.setProductId(this->productId);
// TODO: Move away from hard-coding the CMSIS-DAP/EDBG interface number
auto& usbHidInterface = this->getEdbgInterface().getUsbHidInterface();
usbHidInterface.setNumber(0);
usbHidInterface.setLibUsbDevice(this->libUsbDevice);
usbHidInterface.setLibUsbDeviceHandle(this->libUsbDeviceHandle);
usbHidInterface.setVendorId(this->vendorId);
usbHidInterface.setProductId(this->productId);
if (!usbHidInterface.isInitialised()) {
usbHidInterface.init();
}
if (!usbHidInterface.isInitialised()) {
usbHidInterface.init();
/*
* The Power Debugger EDBG/CMSIS-DAP interface doesn't operate properly when sending commands too quickly.
*
* Because of this, we have to enforce a minimum time gap between commands. See comment in
* CmsisDapInterface class declaration for more info.
*/
this->getEdbgInterface().setMinimumCommandTimeGap(std::chrono::milliseconds(35));
// We don't need to claim the CMSISDAP interface here as the HIDAPI will have already done so.
if (!this->sessionStarted) {
this->startSession();
}
this->edbgAvr8Interface = std::make_unique<EdbgAvr8Interface>(this->edbgInterface);
this->setInitialised(true);
}
/*
* The Power Debugger EDBG/CMSIS-DAP interface doesn't operate properly when sending commands too quickly.
*
* Because of this, we have to enforce a minimum time gap between commands. See comment in
* CmsisDapInterface class declaration for more info.
*/
this->getEdbgInterface().setMinimumCommandTimeGap(std::chrono::milliseconds(35));
void PowerDebugger::close() {
if (this->sessionStarted) {
this->endSession();
}
// We don't need to claim the CMSISDAP interface here as the HIDAPI will have already done so.
if (!this->sessionStarted) {
this->startSession();
this->getEdbgInterface().getUsbHidInterface().close();
UsbDevice::close();
}
this->edbgAvr8Interface = std::make_unique<EdbgAvr8Interface>(this->edbgInterface);
this->setInitialised(true);
}
std::string PowerDebugger::getSerialNumber() {
using namespace CommandFrames::Discovery;
void PowerDebugger::close() {
if (this->sessionStarted) {
this->endSession();
}
this->getEdbgInterface().getUsbHidInterface().close();
UsbDevice::close();
}
std::string PowerDebugger::getSerialNumber() {
auto response = this->getEdbgInterface().sendAvrCommandFrameAndWaitForResponseFrame(
CommandFrames::Discovery::Query(CommandFrames::Discovery::QueryContext::SERIAL_NUMBER)
);
if (response.getResponseId() != CommandFrames::Discovery::ResponseId::OK) {
throw DeviceInitializationFailure(
"Failed to fetch serial number from device - invalid Discovery Protocol response ID."
auto response = this->getEdbgInterface().sendAvrCommandFrameAndWaitForResponseFrame(
Query(QueryContext::SERIAL_NUMBER)
);
if (response.getResponseId() != ResponseId::OK) {
throw DeviceInitializationFailure(
"Failed to fetch serial number from device - invalid Discovery Protocol response ID."
);
}
auto data = response.getPayloadData();
return std::string(data.begin(), data.end());
}
auto data = response.getPayloadData();
return std::string(data.begin(), data.end());
}
void PowerDebugger::startSession() {
using namespace CommandFrames::HouseKeeping;
void PowerDebugger::startSession() {
auto response = this->getEdbgInterface().sendAvrCommandFrameAndWaitForResponseFrame(
CommandFrames::HouseKeeping::StartSession()
);
if (response.getResponseId() == CommandFrames::HouseKeeping::ResponseId::FAILED) {
// Failed response returned!
throw DeviceInitializationFailure(
"Failed to start session with the Power Debugger - device returned failed response ID"
auto response = this->getEdbgInterface().sendAvrCommandFrameAndWaitForResponseFrame(
StartSession()
);
if (response.getResponseId() == ResponseId::FAILED) {
// Failed response returned!
throw DeviceInitializationFailure(
"Failed to start session with the Power Debugger - device returned failed response ID"
);
}
this->sessionStarted = true;
}
this->sessionStarted = true;
}
void PowerDebugger::endSession() {
using namespace CommandFrames::HouseKeeping;
void PowerDebugger::endSession() {
auto response = this->getEdbgInterface().sendAvrCommandFrameAndWaitForResponseFrame(
CommandFrames::HouseKeeping::EndSession()
);
auto response = this->getEdbgInterface().sendAvrCommandFrameAndWaitForResponseFrame(
EndSession()
);
if (response.getResponseId() == CommandFrames::HouseKeeping::ResponseId::FAILED) {
// Failed response returned!
throw DeviceFailure("Failed to end session with the Power Debugger - device returned failed response ID");
if (response.getResponseId() == ResponseId::FAILED) {
// Failed response returned!
throw DeviceFailure(
"Failed to end session with the Power Debugger - device returned failed response ID"
);
}
this->sessionStarted = false;
}
this->sessionStarted = false;
}

View File

@@ -3,82 +3,90 @@
#include "src/TargetController/Exceptions/DeviceFailure.hpp"
#include "src/TargetController/Exceptions/DeviceInitializationFailure.hpp"
using namespace Bloom::DebugToolDrivers;
using namespace Bloom::DebugToolDrivers::Protocols::CmsisDap::Edbg::Avr;
using namespace Bloom::Exceptions;
namespace Bloom::DebugToolDrivers
{
using namespace Protocols::CmsisDap::Edbg::Avr;
using namespace Bloom::Exceptions;
void XplainedMini::init() {
UsbDevice::init();
void XplainedMini::init() {
UsbDevice::init();
// TODO: Move away from hard-coding the CMSIS-DAP/EDBG interface number
auto& usbHidInterface = this->getEdbgInterface().getUsbHidInterface();
usbHidInterface.setNumber(0);
usbHidInterface.setLibUsbDevice(this->libUsbDevice);
usbHidInterface.setLibUsbDeviceHandle(this->libUsbDeviceHandle);
usbHidInterface.setVendorId(this->vendorId);
usbHidInterface.setProductId(this->productId);
// TODO: Move away from hard-coding the CMSIS-DAP/EDBG interface number
auto& usbHidInterface = this->getEdbgInterface().getUsbHidInterface();
usbHidInterface.setNumber(0);
usbHidInterface.setLibUsbDevice(this->libUsbDevice);
usbHidInterface.setLibUsbDeviceHandle(this->libUsbDeviceHandle);
usbHidInterface.setVendorId(this->vendorId);
usbHidInterface.setProductId(this->productId);
if (!usbHidInterface.isInitialised()) {
usbHidInterface.detachKernelDriver();
usbHidInterface.init();
if (!usbHidInterface.isInitialised()) {
usbHidInterface.detachKernelDriver();
usbHidInterface.init();
}
this->getEdbgInterface().setMinimumCommandTimeGap(std::chrono::milliseconds(35));
if (!this->sessionStarted) {
this->startSession();
}
this->edbgAvr8Interface = std::make_unique<EdbgAvr8Interface>(this->edbgInterface);
this->setInitialised(true);
}
this->getEdbgInterface().setMinimumCommandTimeGap(std::chrono::milliseconds(35));
void XplainedMini::close() {
if (this->sessionStarted) {
this->endSession();
}
if (!this->sessionStarted) {
this->startSession();
this->getEdbgInterface().getUsbHidInterface().close();
UsbDevice::close();
}
this->edbgAvr8Interface = std::make_unique<EdbgAvr8Interface>(this->edbgInterface);
this->setInitialised(true);
}
std::string XplainedMini::getSerialNumber() {
using namespace CommandFrames::Discovery;
void XplainedMini::close() {
if (this->sessionStarted) {
this->endSession();
}
this->getEdbgInterface().getUsbHidInterface().close();
UsbDevice::close();
}
std::string XplainedMini::getSerialNumber() {
auto response = this->getEdbgInterface().sendAvrCommandFrameAndWaitForResponseFrame(
CommandFrames::Discovery::Query(CommandFrames::Discovery::QueryContext::SERIAL_NUMBER)
);
if (response.getResponseId() != CommandFrames::Discovery::ResponseId::OK) {
throw DeviceInitializationFailure(
"Failed to fetch serial number from device - invalid Discovery Protocol response ID."
auto response = this->getEdbgInterface().sendAvrCommandFrameAndWaitForResponseFrame(
Query(QueryContext::SERIAL_NUMBER)
);
if (response.getResponseId() != ResponseId::OK) {
throw DeviceInitializationFailure(
"Failed to fetch serial number from device - invalid Discovery Protocol response ID."
);
}
auto data = response.getPayloadData();
return std::string(data.begin(), data.end());
}
auto data = response.getPayloadData();
return std::string(data.begin(), data.end());
}
void XplainedMini::startSession() {
using namespace CommandFrames::HouseKeeping;
void XplainedMini::startSession() {
auto response = this->getEdbgInterface().sendAvrCommandFrameAndWaitForResponseFrame(
CommandFrames::HouseKeeping::StartSession()
);
auto response = this->getEdbgInterface().sendAvrCommandFrameAndWaitForResponseFrame(
StartSession()
);
if (response.getResponseId() == CommandFrames::HouseKeeping::ResponseId::FAILED) {
// Failed response returned!
throw DeviceInitializationFailure("Failed to start session with Xplained Mini!");
if (response.getResponseId() == ResponseId::FAILED) {
// Failed response returned!
throw DeviceInitializationFailure("Failed to start session with Xplained Mini!");
}
this->sessionStarted = true;
}
this->sessionStarted = true;
}
void XplainedMini::endSession() {
using namespace CommandFrames::HouseKeeping;
void XplainedMini::endSession() {
auto response = this->getEdbgInterface().sendAvrCommandFrameAndWaitForResponseFrame(
CommandFrames::HouseKeeping::EndSession()
);
auto response = this->getEdbgInterface().sendAvrCommandFrameAndWaitForResponseFrame(
EndSession()
);
if (response.getResponseId() == CommandFrames::HouseKeeping::ResponseId::FAILED) {
// Failed response returned!
throw DeviceFailure("Failed to end session with Xplained Mini!");
if (response.getResponseId() == ResponseId::FAILED) {
// Failed response returned!
throw DeviceFailure("Failed to end session with Xplained Mini!");
}
this->sessionStarted = false;
}
this->sessionStarted = false;
}

View File

@@ -3,82 +3,90 @@
#include "src/TargetController/Exceptions/DeviceFailure.hpp"
#include "src/TargetController/Exceptions/DeviceInitializationFailure.hpp"
using namespace Bloom::DebugToolDrivers;
using namespace Bloom::DebugToolDrivers::Protocols::CmsisDap::Edbg::Avr;
using namespace Bloom::Exceptions;
namespace Bloom::DebugToolDrivers
{
using namespace Protocols::CmsisDap::Edbg::Avr;
using namespace Bloom::Exceptions;
void XplainedNano::init() {
UsbDevice::init();
void XplainedNano::init() {
UsbDevice::init();
// TODO: Move away from hard-coding the CMSIS-DAP/EDBG interface number
auto& usbHidInterface = this->getEdbgInterface().getUsbHidInterface();
usbHidInterface.setNumber(0);
usbHidInterface.setLibUsbDevice(this->libUsbDevice);
usbHidInterface.setLibUsbDeviceHandle(this->libUsbDeviceHandle);
usbHidInterface.setVendorId(this->vendorId);
usbHidInterface.setProductId(this->productId);
// TODO: Move away from hard-coding the CMSIS-DAP/EDBG interface number
auto& usbHidInterface = this->getEdbgInterface().getUsbHidInterface();
usbHidInterface.setNumber(0);
usbHidInterface.setLibUsbDevice(this->libUsbDevice);
usbHidInterface.setLibUsbDeviceHandle(this->libUsbDeviceHandle);
usbHidInterface.setVendorId(this->vendorId);
usbHidInterface.setProductId(this->productId);
if (!usbHidInterface.isInitialised()) {
usbHidInterface.detachKernelDriver();
usbHidInterface.init();
if (!usbHidInterface.isInitialised()) {
usbHidInterface.detachKernelDriver();
usbHidInterface.init();
}
this->getEdbgInterface().setMinimumCommandTimeGap(std::chrono::milliseconds(35));
if (!this->sessionStarted) {
this->startSession();
}
this->edbgAvr8Interface = std::make_unique<EdbgAvr8Interface>(this->edbgInterface);
this->setInitialised(true);
}
this->getEdbgInterface().setMinimumCommandTimeGap(std::chrono::milliseconds(35));
void XplainedNano::close() {
if (this->sessionStarted) {
this->endSession();
}
if (!this->sessionStarted) {
this->startSession();
this->getEdbgInterface().getUsbHidInterface().close();
UsbDevice::close();
}
this->edbgAvr8Interface = std::make_unique<EdbgAvr8Interface>(this->edbgInterface);
this->setInitialised(true);
}
std::string XplainedNano::getSerialNumber() {
using namespace CommandFrames::Discovery;
void XplainedNano::close() {
if (this->sessionStarted) {
this->endSession();
}
this->getEdbgInterface().getUsbHidInterface().close();
UsbDevice::close();
}
std::string XplainedNano::getSerialNumber() {
auto response = this->getEdbgInterface().sendAvrCommandFrameAndWaitForResponseFrame(
CommandFrames::Discovery::Query(CommandFrames::Discovery::QueryContext::SERIAL_NUMBER)
);
if (response.getResponseId() != CommandFrames::Discovery::ResponseId::OK) {
throw DeviceInitializationFailure(
"Failed to fetch serial number from device - invalid Discovery Protocol response ID."
auto response = this->getEdbgInterface().sendAvrCommandFrameAndWaitForResponseFrame(
Query(QueryContext::SERIAL_NUMBER)
);
if (response.getResponseId() != ResponseId::OK) {
throw DeviceInitializationFailure(
"Failed to fetch serial number from device - invalid Discovery Protocol response ID."
);
}
auto data = response.getPayloadData();
return std::string(data.begin(), data.end());
}
auto data = response.getPayloadData();
return std::string(data.begin(), data.end());
}
void XplainedNano::startSession() {
using namespace CommandFrames::HouseKeeping;
void XplainedNano::startSession() {
auto response = this->getEdbgInterface().sendAvrCommandFrameAndWaitForResponseFrame(
CommandFrames::HouseKeeping::StartSession()
);
auto response = this->getEdbgInterface().sendAvrCommandFrameAndWaitForResponseFrame(
StartSession()
);
if (response.getResponseId() == CommandFrames::HouseKeeping::ResponseId::FAILED) {
// Failed response returned!
throw DeviceInitializationFailure("Failed to start session with Xplained Nano!");
if (response.getResponseId() == ResponseId::FAILED) {
// Failed response returned!
throw DeviceInitializationFailure("Failed to start session with Xplained Nano!");
}
this->sessionStarted = true;
}
this->sessionStarted = true;
}
void XplainedNano::endSession() {
using namespace CommandFrames::HouseKeeping;
void XplainedNano::endSession() {
auto response = this->getEdbgInterface().sendAvrCommandFrameAndWaitForResponseFrame(
CommandFrames::HouseKeeping::EndSession()
);
auto response = this->getEdbgInterface().sendAvrCommandFrameAndWaitForResponseFrame(
EndSession()
);
if (response.getResponseId() == CommandFrames::HouseKeeping::ResponseId::FAILED) {
// Failed response returned!
throw DeviceFailure("Failed to end session with Xplained Nano!");
if (response.getResponseId() == ResponseId::FAILED) {
// Failed response returned!
throw DeviceFailure("Failed to end session with Xplained Nano!");
}
this->sessionStarted = false;
}
this->sessionStarted = false;
}

View File

@@ -3,91 +3,99 @@
#include "src/TargetController/Exceptions/DeviceFailure.hpp"
#include "src/TargetController/Exceptions/DeviceInitializationFailure.hpp"
using namespace Bloom::DebugToolDrivers;
using namespace Bloom::DebugToolDrivers::Protocols::CmsisDap::Edbg::Avr;
using namespace Bloom::Exceptions;
namespace Bloom::DebugToolDrivers
{
using namespace Protocols::CmsisDap::Edbg::Avr;
using namespace Bloom::Exceptions;
void XplainedPro::init() {
UsbDevice::init();
void XplainedPro::init() {
UsbDevice::init();
// TODO: Move away from hard-coding the CMSIS-DAP/EDBG interface number
auto& usbHidInterface = this->getEdbgInterface().getUsbHidInterface();
usbHidInterface.setNumber(0);
usbHidInterface.setLibUsbDevice(this->libUsbDevice);
usbHidInterface.setLibUsbDeviceHandle(this->libUsbDeviceHandle);
usbHidInterface.setVendorId(this->vendorId);
usbHidInterface.setProductId(this->productId);
// TODO: Move away from hard-coding the CMSIS-DAP/EDBG interface number
auto& usbHidInterface = this->getEdbgInterface().getUsbHidInterface();
usbHidInterface.setNumber(0);
usbHidInterface.setLibUsbDevice(this->libUsbDevice);
usbHidInterface.setLibUsbDeviceHandle(this->libUsbDeviceHandle);
usbHidInterface.setVendorId(this->vendorId);
usbHidInterface.setProductId(this->productId);
if (!usbHidInterface.isInitialised()) {
usbHidInterface.detachKernelDriver();
usbHidInterface.init();
if (!usbHidInterface.isInitialised()) {
usbHidInterface.detachKernelDriver();
usbHidInterface.init();
}
this->getEdbgInterface().setMinimumCommandTimeGap(std::chrono::milliseconds(35));
if (!this->sessionStarted) {
this->startSession();
}
this->edbgAvr8Interface = std::make_unique<EdbgAvr8Interface>(this->edbgInterface);
/*
* The Xplained Pro debug tool returns incorrect data for any read memory command that exceeds 256 bytes in the
* size of the read request, despite the fact that the HID report size is 512 bytes. The debug tool doesn't
* report any error, it just returns incorrect data.
*
* This means we must enforce a hard limit on the number of bytes we attempt to access, per request.
*/
this->edbgAvr8Interface->setMaximumMemoryAccessSizePerRequest(256);
this->setInitialised(true);
}
this->getEdbgInterface().setMinimumCommandTimeGap(std::chrono::milliseconds(35));
void XplainedPro::close() {
if (this->sessionStarted) {
this->endSession();
}
if (!this->sessionStarted) {
this->startSession();
this->getEdbgInterface().getUsbHidInterface().close();
UsbDevice::close();
}
this->edbgAvr8Interface = std::make_unique<EdbgAvr8Interface>(this->edbgInterface);
std::string XplainedPro::getSerialNumber() {
using namespace CommandFrames::Discovery;
/*
* The Xplained Pro debug tool returns incorrect data for any read memory command that exceeds 256 bytes in the
* size of the read request, despite the fact that the HID report size is 512 bytes. The debug tool doesn't
* report any error, it just returns incorrect data.
*
* This means we must enforce a hard limit on the number of bytes we attempt to access, per request.
*/
this->edbgAvr8Interface->setMaximumMemoryAccessSizePerRequest(256);
this->setInitialised(true);
}
void XplainedPro::close() {
if (this->sessionStarted) {
this->endSession();
}
this->getEdbgInterface().getUsbHidInterface().close();
UsbDevice::close();
}
std::string XplainedPro::getSerialNumber() {
auto response = this->getEdbgInterface().sendAvrCommandFrameAndWaitForResponseFrame(
CommandFrames::Discovery::Query(CommandFrames::Discovery::QueryContext::SERIAL_NUMBER)
);
if (response.getResponseId() != CommandFrames::Discovery::ResponseId::OK) {
throw DeviceInitializationFailure(
"Failed to fetch serial number from device - invalid Discovery Protocol response ID."
auto response = this->getEdbgInterface().sendAvrCommandFrameAndWaitForResponseFrame(
Query(QueryContext::SERIAL_NUMBER)
);
if (response.getResponseId() != ResponseId::OK) {
throw DeviceInitializationFailure(
"Failed to fetch serial number from device - invalid Discovery Protocol response ID."
);
}
auto data = response.getPayloadData();
return std::string(data.begin(), data.end());
}
auto data = response.getPayloadData();
return std::string(data.begin(), data.end());
}
void XplainedPro::startSession() {
using namespace CommandFrames::HouseKeeping;
void XplainedPro::startSession() {
auto response = this->getEdbgInterface().sendAvrCommandFrameAndWaitForResponseFrame(
CommandFrames::HouseKeeping::StartSession()
);
auto response = this->getEdbgInterface().sendAvrCommandFrameAndWaitForResponseFrame(
StartSession()
);
if (response.getResponseId() == CommandFrames::HouseKeeping::ResponseId::FAILED) {
// Failed response returned!
throw DeviceInitializationFailure("Failed to start session with Xplained Pro!");
if (response.getResponseId() == ResponseId::FAILED) {
// Failed response returned!
throw DeviceInitializationFailure("Failed to start session with Xplained Pro!");
}
this->sessionStarted = true;
}
this->sessionStarted = true;
}
void XplainedPro::endSession() {
using namespace CommandFrames::HouseKeeping;
void XplainedPro::endSession() {
auto response = this->getEdbgInterface().sendAvrCommandFrameAndWaitForResponseFrame(
CommandFrames::HouseKeeping::EndSession()
);
auto response = this->getEdbgInterface().sendAvrCommandFrameAndWaitForResponseFrame(
EndSession()
);
if (response.getResponseId() == CommandFrames::HouseKeeping::ResponseId::FAILED) {
// Failed response returned!
throw DeviceFailure("Failed to end session with Xplained Pro!");
if (response.getResponseId() == ResponseId::FAILED) {
// Failed response returned!
throw DeviceFailure("Failed to end session with Xplained Pro!");
}
this->sessionStarted = false;
}
this->sessionStarted = false;
}