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:
@@ -44,9 +44,11 @@ target_sources(
|
||||
|
||||
# RISC-V debug tools
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/WCH/Protocols/WchLink/WchLinkInterface.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/WCH/WchLinkToolConfig.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/WCH/WchLinkBase.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/WCH/WchLinkE/WchLinkE.cpp
|
||||
|
||||
# RISC-V Debug Translator implementation
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/Protocols/RiscVDebugSpec/DebugTranslatorConfig.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/Protocols/RiscVDebugSpec/DebugTranslator.cpp
|
||||
)
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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())
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
};
|
||||
}
|
||||
@@ -11,12 +11,14 @@ namespace DebugToolDrivers::Wch
|
||||
using Exceptions::DeviceInitializationFailure;
|
||||
|
||||
WchLinkBase::WchLinkBase(
|
||||
const DebugToolConfig& toolConfig,
|
||||
WchLinkVariant variant,
|
||||
std::uint16_t vendorId,
|
||||
std::uint16_t productId,
|
||||
std::uint8_t wchLinkUsbInterfaceNumber
|
||||
)
|
||||
: UsbDevice(vendorId, productId)
|
||||
, toolConfig(WchLinkToolConfig{toolConfig})
|
||||
, variant(variant)
|
||||
, wchLinkUsbInterfaceNumber(wchLinkUsbInterfaceNumber)
|
||||
{}
|
||||
@@ -77,6 +79,7 @@ namespace DebugToolDrivers::Wch
|
||||
if (!this->wchRiscVTranslator) {
|
||||
this->wchRiscVTranslator = std::make_unique<DebugTranslator>(
|
||||
*(this->wchLinkInterface.get()),
|
||||
this->toolConfig.riscVDebugTranslatorConfig,
|
||||
targetDescriptionFile,
|
||||
targetConfig
|
||||
);
|
||||
|
||||
@@ -8,6 +8,9 @@
|
||||
#include "src/DebugToolDrivers/USB/UsbDevice.hpp"
|
||||
#include "src/DebugToolDrivers/USB/UsbInterface.hpp"
|
||||
|
||||
#include "WchLinkToolConfig.hpp"
|
||||
#include "src/ProjectConfig.hpp"
|
||||
|
||||
#include "Protocols/WchLink/WchLinkInterface.hpp"
|
||||
#include "src/DebugToolDrivers/Protocols/RiscVDebugSpec/DebugTranslator.hpp"
|
||||
|
||||
@@ -20,6 +23,7 @@ namespace DebugToolDrivers::Wch
|
||||
{
|
||||
public:
|
||||
WchLinkBase(
|
||||
const DebugToolConfig& toolConfig,
|
||||
WchLinkVariant variant,
|
||||
std::uint16_t vendorId,
|
||||
std::uint16_t productId,
|
||||
@@ -64,6 +68,7 @@ namespace DebugToolDrivers::Wch
|
||||
) override;
|
||||
|
||||
protected:
|
||||
WchLinkToolConfig toolConfig;
|
||||
bool initialised = false;
|
||||
|
||||
WchLinkVariant variant;
|
||||
|
||||
@@ -2,8 +2,9 @@
|
||||
|
||||
namespace DebugToolDrivers::Wch
|
||||
{
|
||||
WchLinkE::WchLinkE()
|
||||
WchLinkE::WchLinkE(const DebugToolConfig& toolConfig)
|
||||
: WchLinkBase(
|
||||
toolConfig,
|
||||
WchLinkVariant::LINK_E_CH32V307,
|
||||
WchLinkE::USB_VENDOR_ID,
|
||||
WchLinkE::USB_PRODUCT_ID,
|
||||
|
||||
@@ -5,6 +5,8 @@
|
||||
|
||||
#include "src/DebugToolDrivers/WCH/WchLinkBase.hpp"
|
||||
|
||||
#include "src/ProjectConfig.hpp"
|
||||
|
||||
namespace DebugToolDrivers::Wch
|
||||
{
|
||||
/**
|
||||
@@ -21,7 +23,7 @@ namespace DebugToolDrivers::Wch
|
||||
static const inline std::uint16_t USB_PRODUCT_ID = 0x8010;
|
||||
static const inline std::uint8_t WCH_LINK_INTERFACE_NUMBER = 0;
|
||||
|
||||
WchLinkE();
|
||||
WchLinkE(const DebugToolConfig& toolConfig);
|
||||
|
||||
std::string getName() override {
|
||||
return "WCH-LinkE";
|
||||
|
||||
16
src/DebugToolDrivers/WCH/WchLinkToolConfig.cpp
Normal file
16
src/DebugToolDrivers/WCH/WchLinkToolConfig.cpp
Normal file
@@ -0,0 +1,16 @@
|
||||
#include "WchLinkToolConfig.hpp"
|
||||
|
||||
namespace DebugToolDrivers::Wch
|
||||
{
|
||||
WchLinkToolConfig::WchLinkToolConfig(const DebugToolConfig& toolConfig)
|
||||
: DebugToolConfig(toolConfig)
|
||||
{
|
||||
const auto& toolNode = toolConfig.toolNode;
|
||||
|
||||
if (toolNode["riscVDebugTranslator"]) {
|
||||
this->riscVDebugTranslatorConfig = Protocols::RiscVDebugSpec::DebugTranslatorConfig{
|
||||
toolNode["riscVDebugTranslator"]
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
20
src/DebugToolDrivers/WCH/WchLinkToolConfig.hpp
Normal file
20
src/DebugToolDrivers/WCH/WchLinkToolConfig.hpp
Normal file
@@ -0,0 +1,20 @@
|
||||
#pragma once
|
||||
|
||||
#include <yaml-cpp/yaml.h>
|
||||
|
||||
#include "src/ProjectConfig.hpp"
|
||||
#include "src/DebugToolDrivers/Protocols/RiscVDebugSpec/DebugTranslatorConfig.hpp"
|
||||
|
||||
namespace DebugToolDrivers::Wch
|
||||
{
|
||||
/**
|
||||
* Extending the generic DebugToolConfig struct to accommodate WCH-Link configuration parameters.
|
||||
*/
|
||||
struct WchLinkToolConfig: public DebugToolConfig
|
||||
{
|
||||
public:
|
||||
Protocols::RiscVDebugSpec::DebugTranslatorConfig riscVDebugTranslatorConfig = {};
|
||||
|
||||
explicit WchLinkToolConfig(const DebugToolConfig& toolConfig);
|
||||
};
|
||||
}
|
||||
@@ -212,19 +212,19 @@ TargetConfig::TargetConfig(const YAML::Node& targetNode) {
|
||||
this->targetNode = targetNode;
|
||||
}
|
||||
|
||||
DebugToolConfig::DebugToolConfig(const YAML::Node& debugToolNode) {
|
||||
if (!debugToolNode.IsMap()) {
|
||||
DebugToolConfig::DebugToolConfig(const YAML::Node& toolNode) {
|
||||
if (!toolNode.IsMap()) {
|
||||
throw Exceptions::InvalidConfig{
|
||||
"Invalid debug tool configuration provided - node must take the form of a YAML mapping."
|
||||
};
|
||||
}
|
||||
|
||||
if (!debugToolNode["name"]) {
|
||||
if (!toolNode["name"]) {
|
||||
throw Exceptions::InvalidConfig{"No debug tool name found."};
|
||||
}
|
||||
|
||||
this->name = StringService::asciiToLower(debugToolNode["name"].as<std::string>());
|
||||
this->debugToolNode = debugToolNode;
|
||||
this->name = StringService::asciiToLower(toolNode["name"].as<std::string>());
|
||||
this->toolNode = toolNode;
|
||||
}
|
||||
|
||||
DebugServerConfig::DebugServerConfig(const YAML::Node& debugServerNode) {
|
||||
|
||||
@@ -107,16 +107,16 @@ struct DebugToolConfig
|
||||
/**
|
||||
* For extracting any debug tool specific configuration.
|
||||
*/
|
||||
YAML::Node debugToolNode;
|
||||
YAML::Node toolNode;
|
||||
|
||||
DebugToolConfig() = default;
|
||||
|
||||
/**
|
||||
* Obtains config parameters from YAML node.
|
||||
*
|
||||
* @param debugToolNode
|
||||
* @param toolNode
|
||||
*/
|
||||
explicit DebugToolConfig(const YAML::Node& debugToolNode);
|
||||
explicit DebugToolConfig(const YAML::Node& toolNode);
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
@@ -373,8 +373,8 @@ namespace TargetController
|
||||
},
|
||||
{
|
||||
"wch-link-e",
|
||||
[] {
|
||||
return std::make_unique<DebugToolDrivers::Wch::WchLinkE>();
|
||||
[this] {
|
||||
return std::make_unique<DebugToolDrivers::Wch::WchLinkE>(this->environmentConfig.debugToolConfig);
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user