Used more specific exception classes to allow the TC to handle device failure errors better

This commit is contained in:
Nav
2021-08-15 01:47:48 +01:00
parent 89b5875132
commit 85fbf1ada4
16 changed files with 228 additions and 115 deletions

View File

@@ -1,11 +1,12 @@
#include "CmsisDapInterface.hpp"
#include <memory>
#include <chrono>
#include <thread>
#include "CmsisDapInterface.hpp"
#include "src/DebugToolDrivers/Protocols/CMSIS-DAP/Command.hpp"
#include "src/DebugToolDrivers/Protocols/CMSIS-DAP/Response.hpp"
#include "src/Exceptions/Exception.hpp"
#include "src/TargetController/Exceptions/DeviceCommunicationFailure.hpp"
using namespace Bloom::DebugToolDrivers::Protocols::CmsisDap;
using namespace Bloom::Exceptions;
@@ -30,7 +31,7 @@ std::unique_ptr<Response> CmsisDapInterface::getResponse() {
auto rawResponse = this->getUsbHidInterface().read(10000);
if (rawResponse.size() == 0) {
throw Exception("Empty CMSIS-DAP response received");
throw DeviceCommunicationFailure("Empty CMSIS-DAP response received");
}
auto response = std::make_unique<Response>(Response());
@@ -44,7 +45,7 @@ std::unique_ptr<Response> CmsisDapInterface::sendCommandAndWaitForResponse(const
if (response->getResponseId() != cmsisDapCommand.getCommandId()) {
// This response is not what we were expecting
throw Exception("Unexpected response to CMSIS-DAP command.");
throw DeviceCommunicationFailure("Unexpected response to CMSIS-DAP command.");
}
return response;

View File

@@ -1,9 +1,11 @@
#include "EdbgAvr8Interface.hpp"
#include <cstdint>
#include <thread>
#include <math.h>
#include "EdbgAvr8Interface.hpp"
#include "src/Exceptions/InvalidConfig.hpp"
#include "src/TargetController/Exceptions/DeviceInitializationFailure.hpp"
#include "src/DebugToolDrivers/Protocols/CMSIS-DAP/VendorSpecific/EDBG/AVR/Exceptions/Avr8CommandFailure.hpp"
#include "src/Logger/Logger.hpp"
@@ -218,59 +220,59 @@ void EdbgAvr8Interface::setDebugWireAndJtagParameters() {
void EdbgAvr8Interface::setPdiParameters() {
if (!this->targetParameters.appSectionPdiOffset.has_value()) {
throw Exception("Missing required parameter: APPL_BASE_ADDR");
throw DeviceInitializationFailure("Missing required parameter: APPL_BASE_ADDR");
}
if (!this->targetParameters.bootSectionPdiOffset.has_value()) {
throw Exception("Missing required parameter: BOOT_BASE_ADDR");
throw DeviceInitializationFailure("Missing required parameter: BOOT_BASE_ADDR");
}
if (!this->targetParameters.bootSectionSize.has_value()) {
throw Exception("Missing required parameter: BOOT_BYTES");
throw DeviceInitializationFailure("Missing required parameter: BOOT_BYTES");
}
if (!this->targetParameters.flashSize.has_value()) {
throw Exception("Missing required parameter: APPLICATION_BYTES");
throw DeviceInitializationFailure("Missing required parameter: APPLICATION_BYTES");
}
if (!this->targetParameters.eepromPdiOffset.has_value()) {
throw Exception("Missing required parameter: EEPROM_BASE_ADDR");
throw DeviceInitializationFailure("Missing required parameter: EEPROM_BASE_ADDR");
}
if (!this->targetParameters.fuseRegistersPdiOffset.has_value()) {
throw Exception("Missing required parameter: FUSE_BASE_ADDR");
throw DeviceInitializationFailure("Missing required parameter: FUSE_BASE_ADDR");
}
if (!this->targetParameters.lockRegistersPdiOffset.has_value()) {
throw Exception("Missing required parameter: LOCKBIT_BASE_ADDR");
throw DeviceInitializationFailure("Missing required parameter: LOCKBIT_BASE_ADDR");
}
if (!this->targetParameters.userSignaturesPdiOffset.has_value()) {
throw Exception("Missing required parameter: USER_SIGN_BASE_ADDR");
throw DeviceInitializationFailure("Missing required parameter: USER_SIGN_BASE_ADDR");
}
if (!this->targetParameters.productSignaturesPdiOffset.has_value()) {
throw Exception("Missing required parameter: PROD_SIGN_BASE_ADDR");
throw DeviceInitializationFailure("Missing required parameter: PROD_SIGN_BASE_ADDR");
}
if (!this->targetParameters.ramPdiOffset.has_value()) {
throw Exception("Missing required parameter: DATA_BASE_ADDR");
throw DeviceInitializationFailure("Missing required parameter: DATA_BASE_ADDR");
}
if (!this->targetParameters.flashPageSize.has_value()) {
throw Exception("Missing required parameter: FLASH_PAGE_BYTES");
throw DeviceInitializationFailure("Missing required parameter: FLASH_PAGE_BYTES");
}
if (!this->targetParameters.eepromSize.has_value()) {
throw Exception("Missing required parameter: EEPROM_SIZE");
throw DeviceInitializationFailure("Missing required parameter: EEPROM_SIZE");
}
if (!this->targetParameters.eepromPageSize.has_value()) {
throw Exception("Missing required parameter: EEPROM_PAGE_SIZE");
throw DeviceInitializationFailure("Missing required parameter: EEPROM_PAGE_SIZE");
}
if (!this->targetParameters.nvmBaseAddress.has_value()) {
throw Exception("Missing required parameter: NVM_BASE");
throw DeviceInitializationFailure("Missing required parameter: NVM_BASE");
}
Logger::debug("Setting APPL_BASE_ADDR AVR8 parameter");
@@ -360,7 +362,7 @@ void EdbgAvr8Interface::setPdiParameters() {
void EdbgAvr8Interface::setUpdiParameters() {
if (!this->targetParameters.signatureSegmentStartAddress.has_value()) {
throw Exception("Missing required parameter: SIGNATURE BASE ADDRESS");
throw DeviceInitializationFailure("Missing required parameter: SIGNATURE BASE ADDRESS");
}
if (this->targetParameters.programMemoryUpdiStartAddress.has_value()) {
@@ -537,28 +539,29 @@ void EdbgAvr8Interface::setTargetParameters(const Avr8Bit::TargetParameters& con
this->targetParameters = config;
if (!config.stackPointerRegisterLowAddress.has_value()) {
throw Exception("Failed to find stack pointer register start address");
throw DeviceInitializationFailure("Failed to find stack pointer register start address");
}
if (!config.stackPointerRegisterSize.has_value()) {
throw Exception("Failed to find stack pointer register size");
throw DeviceInitializationFailure("Failed to find stack pointer register size");
}
if (!config.statusRegisterStartAddress.has_value()) {
throw Exception("Failed to find status register start address");
throw DeviceInitializationFailure("Failed to find status register start address");
}
if (!config.statusRegisterSize.has_value()) {
throw Exception("Failed to find status register size");
throw DeviceInitializationFailure("Failed to find status register size");
}
if (this->configVariant == Avr8ConfigVariant::NONE) {
auto configVariant = this->resolveConfigVariant();
if (!configVariant.has_value()) {
throw Exception("Failed to resolve config variant for the selected "
throw DeviceInitializationFailure("Failed to resolve config variant for the selected "
"physical interface and AVR8 family. The selected physical interface is not known to be supported "
"by the AVR8 family.");
"by the AVR8 family."
);
}
this->configVariant = configVariant.value();

View File

@@ -1,11 +1,11 @@
#pragma once
#include "src/Exceptions/Exception.hpp"
#include "src/TargetController/Exceptions/TargetOperationFailure.hpp"
#include "src/DebugToolDrivers/Protocols/CMSIS-DAP/VendorSpecific/EDBG/AVR/ResponseFrames/AVR8Generic/Avr8GenericResponseFrame.hpp"
namespace Bloom::Exceptions
{
class Avr8CommandFailure: public Exception
class Avr8CommandFailure: public TargetOperationFailure
{
private:
static inline auto failureCodeToDescription = std::map<unsigned char, std::string>({
@@ -59,18 +59,18 @@ namespace Bloom::Exceptions
});
public:
explicit Avr8CommandFailure(const std::string& message): Exception(message) {
explicit Avr8CommandFailure(const std::string& message): TargetOperationFailure(message) {
this->message = message;
}
explicit Avr8CommandFailure(const char* message): Exception(message) {
explicit Avr8CommandFailure(const char* message): TargetOperationFailure(message) {
this->message = std::string(message);
}
explicit Avr8CommandFailure(
const std::string& message,
DebugToolDrivers::Protocols::CmsisDap::Edbg::Avr::ResponseFrames::Avr8Generic::Avr8GenericResponseFrame& responseFrame
): Exception(message) {
): TargetOperationFailure(message) {
this->message = message;
auto responsePayload = responseFrame.getPayload();

View File

@@ -1,13 +1,16 @@
#include "EdbgInterface.hpp"
#include <cstdint>
#include <cstring>
#include <memory>
#include "EdbgInterface.hpp"
#include "src/TargetController/Exceptions/DeviceCommunicationFailure.hpp"
using namespace Bloom::DebugToolDrivers;
using namespace Bloom::DebugToolDrivers::Protocols::CmsisDap::Edbg;
using namespace Bloom::DebugToolDrivers::Protocols::CmsisDap::Edbg::Avr;
using namespace Bloom::Exceptions;
using namespace Bloom::Exceptions;
Protocols::CmsisDap::Response EdbgInterface::sendAvrCommandFrameAndWaitForResponse(
const Protocols::CmsisDap::Edbg::Avr::AvrCommandFrame& avrCommandFrame
@@ -30,7 +33,9 @@ Protocols::CmsisDap::Response EdbgInterface::sendAvrCommandFrameAndWaitForRespon
}
// This should never happen
throw Exception("Cannot send AVR command frame - failed to generate CMSIS-DAP Vendor (AVR) commands");
throw DeviceCommunicationFailure(
"Cannot send AVR command frame - failed to generate CMSIS-DAP Vendor (AVR) commands"
);
}
Protocols::CmsisDap::Edbg::Avr::AvrResponse EdbgInterface::getAvrResponse() {
@@ -42,7 +47,7 @@ Protocols::CmsisDap::Edbg::Avr::AvrResponse EdbgInterface::getAvrResponse() {
avrResponse.init(*cmsisResponse);
return avrResponse;
} else {
throw Exception("Unexpected response to AvrResponseCommand from device");
throw DeviceCommunicationFailure("Unexpected response to AvrResponseCommand from device");
}
}
@@ -56,7 +61,7 @@ std::optional<Protocols::CmsisDap::Edbg::Avr::AvrEvent> EdbgInterface::requestAv
avrEvent.init(*cmsisResponse);
return avrEvent.getEventDataSize() > 0 ? std::optional(avrEvent): std::nullopt;
} else {
throw Exception("Unexpected response to AvrEventCommand from device");
throw DeviceCommunicationFailure("Unexpected response to AvrEventCommand from device");
}
}
@@ -75,11 +80,14 @@ std::vector<Protocols::CmsisDap::Edbg::Avr::AvrResponse> EdbgInterface::requestA
response = this->getAvrResponse();
if (response.getFragmentCount() != fragmentCount) {
throw Exception("Failed to fetch AVRResponse objects - invalid fragment count returned.");
throw DeviceCommunicationFailure(
"Failed to fetch AVRResponse objects - invalid fragment count returned."
);
}
if (response.getFragmentCount() == 0 && response.getFragmentNumber() == 0) {
throw Exception("Failed to fetch AVRResponse objects - unexpected empty response");
throw DeviceCommunicationFailure("Failed to fetch AVRResponse objects - unexpected empty response");
} else if (response.getFragmentNumber() == 0) {
// End of response data ( &this packet can be ignored)
break;

View File

@@ -2,7 +2,6 @@
#include <memory>
#include "src/Exceptions/Exception.hpp"
#include "src/DebugToolDrivers/Protocols/CMSIS-DAP/CmsisDapInterface.hpp"
#include "src/DebugToolDrivers/Protocols/CMSIS-DAP/VendorSpecific/EDBG/AVR/AvrCommand.hpp"
#include "src/DebugToolDrivers/Protocols/CMSIS-DAP/VendorSpecific/EDBG/AVR/AvrEventCommand.hpp"
@@ -11,6 +10,7 @@
#include "src/DebugToolDrivers/Protocols/CMSIS-DAP/VendorSpecific/EDBG/AVR/AvrResponseCommand.hpp"
#include "src/DebugToolDrivers/Protocols/CMSIS-DAP/VendorSpecific/EDBG/AVR/ResponseFrames/AvrResponseFrame.hpp"
#include "src/DebugToolDrivers/Protocols/CMSIS-DAP/VendorSpecific/EDBG/AVR/CommandFrames/AvrCommandFrame.hpp"
#include "src/TargetController/Exceptions/DeviceCommunicationFailure.hpp"
namespace Bloom::DebugToolDrivers::Protocols::CmsisDap::Edbg
{
@@ -62,8 +62,9 @@ namespace Bloom::DebugToolDrivers::Protocols::CmsisDap::Edbg
if (response.getData()[0] != 0x01) {
// The last response packet should always acknowledge receipt of the AvrCommandFrame
throw Exceptions::Exception("Failed to send AvrCommandFrame to device "
"- device did not acknowledge receipt.");
throw Exceptions::DeviceCommunicationFailure(
"Failed to send AvrCommandFrame to device - device did not acknowledge receipt."
);
}
auto responses = this->requestAvrResponses();