Files
BloomPatched/src/TargetController/TargetControllerConsole.hpp

216 lines
6.4 KiB
C++
Raw Normal View History

#pragma once
#include <cstdint>
2022-05-01 19:02:04 +01:00
#include <chrono>
#include <optional>
#include "CommandManager.hpp"
2021-05-30 16:52:32 +01:00
#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"
2022-04-05 22:37:00 +01:00
#include "src/Exceptions/Exception.hpp"
namespace Bloom::TargetController
{
/**
2021-10-10 23:18:06 +01:00
* The TargetControllerConsole provides an interface to the TargetController.
*/
class TargetControllerConsole
{
public:
TargetControllerConsole() = default;
void setDefaultTimeout(std::chrono::milliseconds timeout) {
this->defaultTimeout = timeout;
}
2021-10-10 23:18:06 +01:00
/**
* 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
*/
2021-05-30 16:52:32 +01:00
TargetControllerState getTargetControllerState();
2021-10-10 23:18:06 +01:00
/**
* Retrieves the TargetController state and checks if it's currently active.
*
* @return
* True if the TargetController is currently in an active state, otherwise false.
*/
2021-05-30 16:52:32 +01:00
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
*/
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 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);
2022-05-01 18:44:04 +01:00
/**
* Retrieves the current program counter value from the target.
*
* @return
*/
Targets::TargetProgramCounter getProgramCounter();
2022-05-01 18:44:04 +01:00
/**
* 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
*/
2022-10-01 21:01:37 +01:00
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();
2022-06-05 16:13:43 +01:00
/**
* 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);
};
}