Added config struct for RISC-V debug translator implementation, and WCH debug tools.

Also some tidying in the `DebugToolConfig` struct
This commit is contained in:
Nav
2024-10-06 23:32:36 +01:00
parent a1dfa56913
commit 418db1df99
14 changed files with 142 additions and 35 deletions

View File

@@ -50,10 +50,12 @@ namespace DebugToolDrivers::Protocols::RiscVDebugSpec
DebugTranslator::DebugTranslator(
DebugTransportModuleInterface& dtmInterface,
const DebugTranslatorConfig& config,
const TargetDescriptionFile& targetDescriptionFile,
const RiscVTargetConfig& targetConfig
)
: dtmInterface(dtmInterface)
, config(config)
, targetDescriptionFile(targetDescriptionFile)
, targetConfig(targetConfig)
{}
@@ -130,12 +132,15 @@ namespace DebugToolDrivers::Protocols::RiscVDebugSpec
controlRegister.haltRequest = true;
this->writeDebugModuleControlRegister(controlRegister);
constexpr auto maxAttempts = 10;
auto statusRegister = this->readDebugModuleStatusRegister();
for (auto attempts = 1; !statusRegister.allHalted && attempts <= maxAttempts; ++attempts) {
std::this_thread::sleep_for(std::chrono::microseconds{10});
for (
auto attempts = 1;
!statusRegister.allHalted
&& (DebugTranslator::DEBUG_MODULE_RESPONSE_DELAY * attempts) < this->config.targetResponseTimeout;
++attempts
) {
std::this_thread::sleep_for(DebugTranslator::DEBUG_MODULE_RESPONSE_DELAY);
statusRegister = this->readDebugModuleStatusRegister();
}
@@ -154,12 +159,15 @@ namespace DebugToolDrivers::Protocols::RiscVDebugSpec
controlRegister.resumeRequest = true;
this->writeDebugModuleControlRegister(controlRegister);
constexpr auto maxAttempts = 10;
auto statusRegister = this->readDebugModuleStatusRegister();
for (auto attempts = 1; !statusRegister.allResumeAcknowledge && attempts <= maxAttempts; ++attempts) {
std::this_thread::sleep_for(std::chrono::microseconds{10});
for (
auto attempts = 1;
!statusRegister.allResumeAcknowledge
&& (DebugTranslator::DEBUG_MODULE_RESPONSE_DELAY * attempts) < this->config.targetResponseTimeout;
++attempts
) {
std::this_thread::sleep_for(DebugTranslator::DEBUG_MODULE_RESPONSE_DELAY);
statusRegister = this->readDebugModuleStatusRegister();
}
@@ -203,12 +211,15 @@ namespace DebugToolDrivers::Protocols::RiscVDebugSpec
controlRegister.ndmReset = false;
this->writeDebugModuleControlRegister(controlRegister);
constexpr auto maxAttempts = 10;
auto statusRegister = this->readDebugModuleStatusRegister();
for (auto attempts = 1; !statusRegister.allHaveReset && attempts <= maxAttempts; ++attempts) {
std::this_thread::sleep_for(std::chrono::microseconds{10});
for (
auto attempts = 1;
!statusRegister.allHaveReset
&& (DebugTranslator::DEBUG_MODULE_RESPONSE_DELAY * attempts) < this->config.targetResponseTimeout;
++attempts
) {
std::this_thread::sleep_for(DebugTranslator::DEBUG_MODULE_RESPONSE_DELAY);
statusRegister = this->readDebugModuleStatusRegister();
}
@@ -595,12 +606,15 @@ namespace DebugToolDrivers::Protocols::RiscVDebugSpec
controlRegister.selectedHartIndex = this->selectedHartIndex;
this->writeDebugModuleControlRegister(controlRegister);
constexpr auto maxAttempts = 10;
controlRegister = this->readDebugModuleControlRegister();
for (auto attempts = 1; !controlRegister.debugModuleActive && attempts <= maxAttempts; ++attempts) {
std::this_thread::sleep_for(std::chrono::microseconds{10});
for (
auto attempts = 1;
!controlRegister.debugModuleActive
&& (DebugTranslator::DEBUG_MODULE_RESPONSE_DELAY * attempts) < this->config.targetResponseTimeout;
++attempts
) {
std::this_thread::sleep_for(DebugTranslator::DEBUG_MODULE_RESPONSE_DELAY);
controlRegister = this->readDebugModuleControlRegister();
}
@@ -615,12 +629,15 @@ namespace DebugToolDrivers::Protocols::RiscVDebugSpec
controlRegister.selectedHartIndex = this->selectedHartIndex;
this->writeDebugModuleControlRegister(controlRegister);
constexpr auto maxAttempts = 10;
controlRegister = this->readDebugModuleControlRegister();
for (auto attempts = 1; controlRegister.debugModuleActive && attempts <= maxAttempts; ++attempts) {
std::this_thread::sleep_for(std::chrono::microseconds{10});
for (
auto attempts = 1;
controlRegister.debugModuleActive
&& (DebugTranslator::DEBUG_MODULE_RESPONSE_DELAY * attempts) < this->config.targetResponseTimeout;
++attempts
) {
std::this_thread::sleep_for(DebugTranslator::DEBUG_MODULE_RESPONSE_DELAY);
controlRegister = this->readDebugModuleControlRegister();
}
@@ -741,9 +758,13 @@ namespace DebugToolDrivers::Protocols::RiscVDebugSpec
return abstractStatusRegister.commandError;
}
constexpr auto maxAttempts = 10;
for (auto attempts = 1; abstractStatusRegister.busy && attempts <= maxAttempts; ++attempts) {
std::this_thread::sleep_for(std::chrono::microseconds{10});
for (
auto attempts = 1;
abstractStatusRegister.busy
&& (DebugTranslator::DEBUG_MODULE_RESPONSE_DELAY * attempts) < this->config.targetResponseTimeout;
++attempts
) {
std::this_thread::sleep_for(DebugTranslator::DEBUG_MODULE_RESPONSE_DELAY);
abstractStatusRegister = this->readDebugModuleAbstractControlStatusRegister();
}

View File

@@ -3,6 +3,7 @@
#include <cstdint>
#include <string>
#include <vector>
#include <chrono>
#include <unordered_map>
#include <unordered_set>
#include <optional>
@@ -11,6 +12,7 @@
#include "src/DebugToolDrivers/TargetInterfaces/RiscV/RiscVDebugInterface.hpp"
#include "DebugTransportModuleInterface.hpp"
#include "DebugTranslatorConfig.hpp"
#include "src/Targets/RiscV/TargetDescriptionFile.hpp"
#include "src/Targets/RiscV/RiscVTargetConfig.hpp"
@@ -40,6 +42,7 @@ namespace DebugToolDrivers::Protocols::RiscVDebugSpec
public:
DebugTranslator(
DebugTransportModuleInterface& dtmInterface,
const DebugTranslatorConfig& config,
const ::Targets::RiscV::TargetDescriptionFile& targetDescriptionFile,
const ::Targets::RiscV::RiscVTargetConfig& targetConfig
);
@@ -85,7 +88,10 @@ namespace DebugToolDrivers::Protocols::RiscVDebugSpec
) override;
private:
static constexpr auto DEBUG_MODULE_RESPONSE_DELAY = std::chrono::microseconds{10};
DebugTransportModuleInterface& dtmInterface;
const DebugTranslatorConfig& config;
const ::Targets::RiscV::TargetDescriptionFile& targetDescriptionFile;
const ::Targets::RiscV::RiscVTargetConfig& targetConfig;

View File

@@ -0,0 +1,12 @@
#include "DebugTranslatorConfig.hpp"
namespace DebugToolDrivers::Protocols::RiscVDebugSpec
{
DebugTranslatorConfig::DebugTranslatorConfig(const YAML::Node& configNode) {
if (configNode["targetResponseTimeout"]) {
this->targetResponseTimeout = std::chrono::microseconds{
configNode["targetResponseTimeout"].as<int>(this->targetResponseTimeout.count())
};
}
}
}

View File

@@ -0,0 +1,19 @@
#pragma once
#include <chrono>
#include <yaml-cpp/yaml.h>
namespace DebugToolDrivers::Protocols::RiscVDebugSpec
{
struct DebugTranslatorConfig
{
public:
/**
* Microsecond timeout for the RISC-V target to action or respond to a command.
*/
std::chrono::microseconds targetResponseTimeout = std::chrono::microseconds{100};
DebugTranslatorConfig() = default;
explicit DebugTranslatorConfig(const YAML::Node& configNode);
};
}