Renamed TargetControllerConsole to TargetControllerService

This commit is contained in:
Nav
2022-12-26 21:27:19 +00:00
parent de97e8d4e0
commit d353b55f9b
85 changed files with 261 additions and 257 deletions

View File

@@ -2,5 +2,4 @@ target_sources(
Bloom
PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/TargetControllerComponent.cpp
${CMAKE_CURRENT_SOURCE_DIR}/TargetControllerConsole.cpp
)

View File

@@ -18,9 +18,9 @@ All TargetController commands can be found in [src/TargetController/Commands](./
[`Bloom::TargetController::Responses::Response`](./Responses/Response.hpp) base class.
**NOTE:** Components within Bloom do not typically concern themselves with the TargetController command-response
mechanism. Instead, they use the `TargetControllerConsole` class, which encapsulates the command-response mechanism and
mechanism. Instead, they use the `TargetControllerService` class, which encapsulates the command-response mechanism and
provides a simplified means for interaction with the connected hardware. For more, see
[The TargetControllerConsole class](#the-targetcontrollerconsole-class) section below.
[The TargetControllerService class](#the-TargetControllerService-class) section below.
Commands can be sent to the TargetController via the [`Bloom::TargetController::CommandManager`](./CommandManager.hpp)
class.
@@ -53,26 +53,26 @@ until a timeout has been reached. Because it is a template function, it is able
type at compile-time (see the `SuccessResponseType` alias in some command classes). If the TargetController responds
with an error, or the timeout is reached, `CommandManager::sendCommandAndWaitForResponse()` will throw an exception.
#### The TargetControllerConsole class
#### The TargetControllerService class
The `TargetControllerConsole` class encapsulates the TargetController's command-response mechanism and provides a
The `TargetControllerService` class encapsulates the TargetController's command-response mechanism and provides a
simplified means for other components to interact with the connected hardware. Iterating on the example above, to read
memory from the target:
```c++
auto tcConsole = TargetController::TargetControllerConsole();
auto tcService = Services::TargetControllerService();
const auto data = tcConsole.readMemory(
const auto data = tcService.readMemory(
someMemoryType, // Flash, RAM, EEPROM, etc
someStartAddress,
someNumberOfBytes
);
```
The `TargetControllerConsole` class does not require any dependencies at construction. It can be constructed in
The `TargetControllerService` class does not require any dependencies at construction. It can be constructed in
different threads and used freely to gain access to the connected hardware, from any component within Bloom.
All components within Bloom should use the `TargetControllerConsole` class to interact with the connected hardware. They
All components within Bloom should use the `TargetControllerService` class to interact with the connected hardware. They
**should not** directly issue commands via the `Bloom::TargetController::CommandManager`, unless there is a very good
reason to do so.
@@ -114,7 +114,7 @@ For more on TargetController suspension, see `TargetControllerComponent::suspend
When a component needs to write to the target's program memory, it must enable programming mode on the target. This can
be done by issuing the `EnableProgrammingMode` command to the TargetController (see
`TargetControllerConsole::enableProgrammingMode()`). Once programming mode has been enabled, the TargetController will
`TargetControllerService::enableProgrammingMode()`). Once programming mode has been enabled, the TargetController will
reject any subsequent commands that involve debug operations (such as `ResumeTargetExecution`, `ReadTargetRegisters`,
etc), until programming mode has been disabled.

View File

@@ -1,271 +0,0 @@
#include "TargetControllerConsole.hpp"
// Commands
#include "Commands/GetState.hpp"
#include "Commands/Suspend.hpp"
#include "Commands/Resume.hpp"
#include "Commands/GetTargetDescriptor.hpp"
#include "Commands/GetTargetState.hpp"
#include "Commands/StopTargetExecution.hpp"
#include "Commands/ResumeTargetExecution.hpp"
#include "Commands/ResetTarget.hpp"
#include "Commands/ReadTargetRegisters.hpp"
#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"
#include "Commands/SetTargetProgramCounter.hpp"
#include "Commands/GetTargetPinStates.hpp"
#include "Commands/SetTargetPinState.hpp"
#include "Commands/GetTargetStackPointer.hpp"
#include "Commands/GetTargetProgramCounter.hpp"
#include "Commands/EnableProgrammingMode.hpp"
#include "Commands/DisableProgrammingMode.hpp"
namespace Bloom::TargetController
{
using Commands::GetState;
using Commands::Suspend;
using Commands::Resume;
using Commands::GetTargetDescriptor;
using Commands::GetTargetState;
using Commands::StopTargetExecution;
using Commands::ResumeTargetExecution;
using Commands::ResetTarget;
using Commands::ReadTargetRegisters;
using Commands::WriteTargetRegisters;
using Commands::ReadTargetMemory;
using Commands::WriteTargetMemory;
using Commands::EraseTargetMemory;
using Commands::StepTargetExecution;
using Commands::SetBreakpoint;
using Commands::RemoveBreakpoint;
using Commands::SetTargetProgramCounter;
using Commands::GetTargetPinStates;
using Commands::SetTargetPinState;
using Commands::GetTargetStackPointer;
using Commands::GetTargetProgramCounter;
using Commands::EnableProgrammingMode;
using Commands::DisableProgrammingMode;
using Targets::TargetDescriptor;
using Targets::TargetState;
using Targets::TargetRegisters;
using Targets::TargetRegisterDescriptors;
using Targets::TargetMemoryType;
using Targets::TargetMemoryAddress;
using Targets::TargetMemorySize;
using Targets::TargetMemoryAddressRange;
using Targets::TargetMemoryBuffer;
using Targets::TargetProgramCounter;
using Targets::TargetStackPointer;
using Targets::TargetBreakpoint;
using Targets::TargetPinDescriptor;
using Targets::TargetPinState;
using Targets::TargetPinStateMapping;
TargetControllerState TargetControllerConsole::getTargetControllerState() {
return this->commandManager.sendCommandAndWaitForResponse(
std::make_unique<GetState>(),
this->defaultTimeout
)->state;
}
bool TargetControllerConsole::isTargetControllerInService() noexcept {
try {
return this->getTargetControllerState() == TargetControllerState::ACTIVE;
} catch (...) {
return false;
}
}
void TargetControllerConsole::resumeTargetController() {
this->commandManager.sendCommandAndWaitForResponse(
std::make_unique<Resume>(),
this->defaultTimeout
);
return;
}
void TargetControllerConsole::suspendTargetController() {
this->commandManager.sendCommandAndWaitForResponse(
std::make_unique<Suspend>(),
this->defaultTimeout
);
return;
}
const TargetDescriptor& TargetControllerConsole::getTargetDescriptor() {
return this->commandManager.sendCommandAndWaitForResponse(
std::make_unique<GetTargetDescriptor>(),
this->defaultTimeout
)->targetDescriptor;
}
TargetState TargetControllerConsole::getTargetState() {
return this->commandManager.sendCommandAndWaitForResponse(
std::make_unique<GetTargetState>(),
this->defaultTimeout
)->targetState;
}
void TargetControllerConsole::stopTargetExecution() {
this->commandManager.sendCommandAndWaitForResponse(
std::make_unique<StopTargetExecution>(),
this->defaultTimeout
);
}
void TargetControllerConsole::continueTargetExecution(std::optional<TargetProgramCounter> fromAddress) {
auto resumeExecutionCommand = std::make_unique<ResumeTargetExecution>();
if (fromAddress.has_value()) {
resumeExecutionCommand->fromProgramCounter = fromAddress.value();
}
this->commandManager.sendCommandAndWaitForResponse(
std::move(resumeExecutionCommand),
this->defaultTimeout
);
}
void TargetControllerConsole::stepTargetExecution(std::optional<TargetProgramCounter> fromAddress) {
auto stepExecutionCommand = std::make_unique<StepTargetExecution>();
if (fromAddress.has_value()) {
stepExecutionCommand->fromProgramCounter = fromAddress.value();
}
this->commandManager.sendCommandAndWaitForResponse(
std::move(stepExecutionCommand),
this->defaultTimeout
);
}
TargetRegisters TargetControllerConsole::readRegisters(const TargetRegisterDescriptors& descriptors) {
return this->commandManager.sendCommandAndWaitForResponse(
std::make_unique<ReadTargetRegisters>(descriptors),
this->defaultTimeout
)->registers;
}
void TargetControllerConsole::writeRegisters(const TargetRegisters& registers) {
this->commandManager.sendCommandAndWaitForResponse(
std::make_unique<WriteTargetRegisters>(registers),
this->defaultTimeout
);
}
TargetMemoryBuffer TargetControllerConsole::readMemory(
TargetMemoryType memoryType,
TargetMemoryAddress startAddress,
TargetMemorySize bytes,
const std::set<TargetMemoryAddressRange>& excludedAddressRanges
) {
return this->commandManager.sendCommandAndWaitForResponse(
std::make_unique<ReadTargetMemory>(
memoryType,
startAddress,
bytes,
excludedAddressRanges
),
this->defaultTimeout
)->data;
}
void TargetControllerConsole::writeMemory(
TargetMemoryType memoryType,
TargetMemoryAddress startAddress,
const TargetMemoryBuffer& buffer
) {
this->commandManager.sendCommandAndWaitForResponse(
std::make_unique<WriteTargetMemory>(memoryType, startAddress, buffer),
this->defaultTimeout
);
}
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),
this->defaultTimeout
);
}
void TargetControllerConsole::removeBreakpoint(TargetBreakpoint breakpoint) {
this->commandManager.sendCommandAndWaitForResponse(
std::make_unique<RemoveBreakpoint>(breakpoint),
this->defaultTimeout
);
}
TargetProgramCounter TargetControllerConsole::getProgramCounter() {
return this->commandManager.sendCommandAndWaitForResponse(
std::make_unique<GetTargetProgramCounter>(),
this->defaultTimeout
)->programCounter;
}
void TargetControllerConsole::setProgramCounter(TargetProgramCounter address) {
this->commandManager.sendCommandAndWaitForResponse(
std::make_unique<SetTargetProgramCounter>(address),
this->defaultTimeout
);
}
TargetPinStateMapping TargetControllerConsole::getPinStates(int variantId) {
return this->commandManager.sendCommandAndWaitForResponse(
std::make_unique<GetTargetPinStates>(variantId),
this->defaultTimeout
)->pinStatesByNumber;
}
void TargetControllerConsole::setPinState(TargetPinDescriptor pinDescriptor, TargetPinState pinState) {
this->commandManager.sendCommandAndWaitForResponse(
std::make_unique<SetTargetPinState>(pinDescriptor, pinState),
this->defaultTimeout
);
}
TargetStackPointer TargetControllerConsole::getStackPointer() {
return this->commandManager.sendCommandAndWaitForResponse(
std::make_unique<GetTargetStackPointer>(),
this->defaultTimeout
)->stackPointer;
}
void TargetControllerConsole::resetTarget() {
this->commandManager.sendCommandAndWaitForResponse(
std::make_unique<ResetTarget>(),
this->defaultTimeout
);
}
void TargetControllerConsole::enableProgrammingMode() {
this->commandManager.sendCommandAndWaitForResponse(
std::make_unique<EnableProgrammingMode>(),
this->defaultTimeout
);
}
void TargetControllerConsole::disableProgrammingMode() {
this->commandManager.sendCommandAndWaitForResponse(
std::make_unique<DisableProgrammingMode>(),
this->defaultTimeout
);
}
}

View File

@@ -1,222 +0,0 @@
#pragma once
#include <cstdint>
#include <chrono>
#include <optional>
#include "CommandManager.hpp"
#include "TargetControllerState.hpp"
#include "src/Targets/TargetState.hpp"
#include "src/Targets/TargetRegister.hpp"
#include "src/Targets/TargetMemory.hpp"
#include "src/Targets/TargetBreakpoint.hpp"
#include "src/Targets/TargetVariant.hpp"
#include "src/Targets/TargetPinDescriptor.hpp"
#include "src/Exceptions/Exception.hpp"
namespace Bloom::TargetController
{
/**
* The TargetControllerConsole provides an interface to the TargetController.
*/
class TargetControllerConsole
{
public:
TargetControllerConsole() = default;
void setDefaultTimeout(std::chrono::milliseconds timeout) {
this->defaultTimeout = timeout;
}
/**
* Requests the current TargetController state from the TargetController. The TargetController should always
* respond to such a request, even when it's in a suspended state.
*
* To check if the TargetController is in an active state, isTargetControllerInService() can be used for
* convenience.
*
* @return
*/
TargetControllerState getTargetControllerState();
/**
* Retrieves the TargetController state and checks if it's currently active.
*
* @return
* True if the TargetController is currently in an active state, otherwise false.
*/
bool isTargetControllerInService() noexcept;
/**
* Resumes the TargetController if it's suspended. Otherwise, this function does nothing.
*/
void resumeTargetController();
/**
* Suspends the TargetController if it's active. Otherwise, this function does nothing.
*/
void suspendTargetController();
/**
* Requests the TargetDescriptor from the TargetController
*
* @return
*/
const Targets::TargetDescriptor& getTargetDescriptor();
/**
* Fetches the current target state.
*
* @return
*/
Targets::TargetState getTargetState();
/**
* Requests the TargetController to halt execution on the target.
*/
void stopTargetExecution();
/**
* Requests the TargetController to continue execution on the target.
*
* @param fromAddress
*/
void continueTargetExecution(std::optional<Targets::TargetProgramCounter> fromAddress);
/**
* Requests the TargetController to step execution on the target.
*
* @param fromAddress
*/
void stepTargetExecution(std::optional<Targets::TargetProgramCounter> fromAddress);
/**
* Requests the TargetController to read register values from the target.
*
* @param descriptors
* Descriptors of the registers to read.
*
* @return
*/
Targets::TargetRegisters readRegisters(const Targets::TargetRegisterDescriptors& descriptors);
/**
* Requests the TargetController to write register values to the target.
*
* @param registers
*/
void writeRegisters(const Targets::TargetRegisters& registers);
/**
* Requests the TargetController to read memory from the target.
*
* @param memoryType
* @param startAddress
* @param bytes
* @param excludedAddressRanges
* @return
*/
Targets::TargetMemoryBuffer readMemory(
Targets::TargetMemoryType memoryType,
Targets::TargetMemoryAddress startAddress,
Targets::TargetMemorySize bytes,
const std::set<Targets::TargetMemoryAddressRange>& excludedAddressRanges = {}
);
/**
* Requests the TargetController to write memory to the target.
*
* @param memoryType
* @param startAddress
* @param buffer
*/
void writeMemory(
Targets::TargetMemoryType memoryType,
Targets::TargetMemoryAddress startAddress,
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.
*
* @param breakpoint
*/
void setBreakpoint(Targets::TargetBreakpoint breakpoint);
/**
* Requests the TargetController to remove a breakpoint from the target.
*
* @param breakpoint
*/
void removeBreakpoint(Targets::TargetBreakpoint breakpoint);
/**
* Retrieves the current program counter value from the target.
*
* @return
*/
Targets::TargetProgramCounter getProgramCounter();
/**
* Sets the target's program counter to the given address.
*
* @param address
*/
void setProgramCounter(Targets::TargetProgramCounter address);
/**
* Retrieves the pin states for a particular target variant.
*
* @param variantId
*/
Targets::TargetPinStateMapping getPinStates(int variantId);
/**
* Updates the pin state on the target, for a specific pin.
*
* @param pinDescriptor
* @param pinState
*/
void setPinState(Targets::TargetPinDescriptor pinDescriptor, Targets::TargetPinState pinState);
/**
* Retrieves the current stack pointer value from the target.
*
* @return
*/
Targets::TargetStackPointer getStackPointer();
/**
* Triggers a reset on the target. The target will be held in a stopped state.
*/
void resetTarget();
/**
* Enables programming mode on the target.
*
* From the point of invoking this function, the TargetController will reject any subsequent commands for
* debug operations (such as ResumeTargetExecution, ReadTargetRegisters, etc), until programming mode has
* been disabled.
*/
void enableProgrammingMode();
/**
* Disables programming mode on the target.
*/
void disableProgrammingMode();
private:
CommandManager commandManager = CommandManager();
std::chrono::milliseconds defaultTimeout = std::chrono::milliseconds(60000);
};
}