Added EraseTargetMemory TC command

This commit is contained in:
Nav
2022-12-11 23:25:15 +00:00
parent 83c273a22b
commit 76a0207701
7 changed files with 77 additions and 17 deletions

View File

@@ -18,6 +18,7 @@ namespace Bloom::TargetController::Commands
WRITE_TARGET_REGISTERS,
READ_TARGET_MEMORY,
WRITE_TARGET_MEMORY,
ERASE_TARGET_MEMORY,
GET_TARGET_STATE,
STEP_TARGET_EXECUTION,
SET_BREAKPOINT,

View File

@@ -0,0 +1,33 @@
#pragma once
#include "Command.hpp"
#include "src/Targets/TargetMemory.hpp"
namespace Bloom::TargetController::Commands
{
class EraseTargetMemory: public Command
{
public:
static constexpr CommandType type = CommandType::ERASE_TARGET_MEMORY;
static const inline std::string name = "EraseTargetMemory";
Targets::TargetMemoryType memoryType;
EraseTargetMemory(Targets::TargetMemoryType memoryType)
: memoryType(memoryType)
{};
[[nodiscard]] CommandType getType() const override {
return EraseTargetMemory::type;
}
[[nodiscard]] bool requiresStoppedTargetState() const override {
return true;
}
[[nodiscard]] bool requiresDebugMode() const override {
return this->memoryType == Targets::TargetMemoryType::RAM;
}
};
}

View File

@@ -37,6 +37,7 @@ namespace Bloom::TargetController
using Commands::WriteTargetRegisters;
using Commands::ReadTargetMemory;
using Commands::WriteTargetMemory;
using Commands::EraseTargetMemory;
using Commands::StepTargetExecution;
using Commands::SetBreakpoint;
using Commands::RemoveBreakpoint;
@@ -220,6 +221,10 @@ namespace Bloom::TargetController
std::bind(&TargetControllerComponent::handleWriteTargetMemory, this, std::placeholders::_1)
);
this->registerCommandHandler<EraseTargetMemory>(
std::bind(&TargetControllerComponent::handleEraseTargetMemory, this, std::placeholders::_1)
);
this->registerCommandHandler<StepTargetExecution>(
std::bind(&TargetControllerComponent::handleStepTargetExecution, this, std::placeholders::_1)
);
@@ -930,6 +935,21 @@ namespace Bloom::TargetController
return std::make_unique<Response>();
}
std::unique_ptr<Response> TargetControllerComponent::handleEraseTargetMemory(EraseTargetMemory& command) {
const auto& targetDescriptor = this->getTargetDescriptor();
if (
command.memoryType == this->getTargetDescriptor().programMemoryType
&& !this->target->programmingModeEnabled()
) {
throw Exception("Cannot erase program memory - programming mode not enabled.");
}
this->target->eraseMemory(command.memoryType);
return std::make_unique<Response>();
}
std::unique_ptr<Response> TargetControllerComponent::handleStepTargetExecution(StepTargetExecution& command) {
if (command.fromProgramCounter.has_value()) {
this->target->setProgramCounter(command.fromProgramCounter.value());

View File

@@ -32,6 +32,7 @@
#include "Commands/WriteTargetRegisters.hpp"
#include "Commands/ReadTargetMemory.hpp"
#include "Commands/WriteTargetMemory.hpp"
#include "Commands/EraseTargetMemory.hpp"
#include "Commands/StepTargetExecution.hpp"
#include "Commands/SetBreakpoint.hpp"
#include "Commands/RemoveBreakpoint.hpp"
@@ -350,6 +351,7 @@ namespace Bloom::TargetController
std::unique_ptr<Responses::Response> handleWriteTargetRegisters(Commands::WriteTargetRegisters& command);
std::unique_ptr<Responses::TargetMemoryRead> handleReadTargetMemory(Commands::ReadTargetMemory& command);
std::unique_ptr<Responses::Response> handleWriteTargetMemory(Commands::WriteTargetMemory& command);
std::unique_ptr<Responses::Response> handleEraseTargetMemory(Commands::EraseTargetMemory& command);
std::unique_ptr<Responses::Response> handleStepTargetExecution(Commands::StepTargetExecution& command);
std::unique_ptr<Responses::Response> handleSetBreakpoint(Commands::SetBreakpoint& command);
std::unique_ptr<Responses::Response> handleRemoveBreakpoint(Commands::RemoveBreakpoint& command);

View File

@@ -13,6 +13,7 @@
#include "Commands/WriteTargetRegisters.hpp"
#include "Commands/ReadTargetMemory.hpp"
#include "Commands/WriteTargetMemory.hpp"
#include "Commands/EraseTargetMemory.hpp"
#include "Commands/StepTargetExecution.hpp"
#include "Commands/SetBreakpoint.hpp"
#include "Commands/RemoveBreakpoint.hpp"
@@ -38,6 +39,7 @@ namespace Bloom::TargetController
using Commands::WriteTargetRegisters;
using Commands::ReadTargetMemory;
using Commands::WriteTargetMemory;
using Commands::EraseTargetMemory;
using Commands::StepTargetExecution;
using Commands::SetBreakpoint;
using Commands::RemoveBreakpoint;
@@ -190,6 +192,13 @@ namespace Bloom::TargetController
);
}
void TargetControllerConsole::eraseMemory(Targets::TargetMemoryType memoryType) {
this->commandManager.sendCommandAndWaitForResponse(
std::make_unique<EraseTargetMemory>(memoryType),
this->defaultTimeout
);
}
void TargetControllerConsole::setBreakpoint(TargetBreakpoint breakpoint) {
this->commandManager.sendCommandAndWaitForResponse(
std::make_unique<SetBreakpoint>(breakpoint),

View File

@@ -138,6 +138,13 @@ namespace Bloom::TargetController
const Targets::TargetMemoryBuffer& buffer
);
/**
* Requests the TargetController to erase the given target memory type.
*
* @param memoryType
*/
void eraseMemory(Targets::TargetMemoryType memoryType);
/**
* Requests the TargetController to set a breakpoint on the target.
*