2021-04-24 20:23:17 +01:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
|
|
#include <cstdint>
|
2022-05-01 19:02:04 +01:00
|
|
|
#include <chrono>
|
2021-04-24 20:23:17 +01:00
|
|
|
#include <optional>
|
|
|
|
|
|
2022-12-26 21:27:19 +00:00
|
|
|
#include "src/TargetController/CommandManager.hpp"
|
|
|
|
|
#include "src/TargetController/TargetControllerState.hpp"
|
2021-05-30 16:52:32 +01:00
|
|
|
|
2022-04-28 21:02:45 +01:00
|
|
|
#include "src/Targets/TargetState.hpp"
|
2021-04-24 20:23:17 +01:00
|
|
|
#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"
|
|
|
|
|
|
2022-12-26 21:27:19 +00:00
|
|
|
namespace Bloom::Services
|
2021-04-24 20:23:17 +01:00
|
|
|
{
|
|
|
|
|
/**
|
2022-12-26 21:27:19 +00:00
|
|
|
* The TargetControllerService provides an interface to the TargetController.
|
2021-04-24 20:23:17 +01:00
|
|
|
*/
|
2022-12-26 21:27:19 +00:00
|
|
|
class TargetControllerService
|
2021-04-24 20:23:17 +01:00
|
|
|
{
|
|
|
|
|
public:
|
2022-12-26 21:27:19 +00:00
|
|
|
TargetControllerService() = default;
|
2021-04-24 20:23:17 +01:00
|
|
|
|
2021-05-01 13:48:18 +01:00
|
|
|
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
|
|
|
|
|
*/
|
2022-12-26 22:25:35 +00:00
|
|
|
TargetController::TargetControllerState getTargetControllerState() const;
|
2021-05-30 16:52:32 +01:00
|
|
|
|
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.
|
|
|
|
|
*/
|
2022-12-26 22:25:35 +00:00
|
|
|
bool isTargetControllerInService() const noexcept;
|
2021-05-30 16:52:32 +01:00
|
|
|
|
2022-09-14 22:05:50 +01:00
|
|
|
/**
|
|
|
|
|
* Resumes the TargetController if it's suspended. Otherwise, this function does nothing.
|
|
|
|
|
*/
|
2022-12-26 22:25:35 +00:00
|
|
|
void resumeTargetController() const;
|
2022-09-14 22:05:50 +01:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Suspends the TargetController if it's active. Otherwise, this function does nothing.
|
|
|
|
|
*/
|
2022-12-26 22:25:35 +00:00
|
|
|
void suspendTargetController() const;
|
2022-09-14 22:05:50 +01:00
|
|
|
|
2021-04-24 20:23:17 +01:00
|
|
|
/**
|
|
|
|
|
* Requests the TargetDescriptor from the TargetController
|
|
|
|
|
*
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
2022-12-26 22:25:35 +00:00
|
|
|
const Targets::TargetDescriptor& getTargetDescriptor() const;
|
2021-04-24 20:23:17 +01:00
|
|
|
|
2022-04-28 21:02:45 +01:00
|
|
|
/**
|
|
|
|
|
* Fetches the current target state.
|
|
|
|
|
*
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
2022-12-26 22:25:35 +00:00
|
|
|
Targets::TargetState getTargetState() const;
|
2022-04-28 21:02:45 +01:00
|
|
|
|
2021-04-24 20:23:17 +01:00
|
|
|
/**
|
|
|
|
|
* Requests the TargetController to halt execution on the target.
|
|
|
|
|
*/
|
2022-12-26 22:25:35 +00:00
|
|
|
void stopTargetExecution() const;
|
2021-04-24 20:23:17 +01:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Requests the TargetController to continue execution on the target.
|
|
|
|
|
*
|
|
|
|
|
* @param fromAddress
|
|
|
|
|
*/
|
2023-04-01 12:37:59 +01:00
|
|
|
void continueTargetExecution(
|
|
|
|
|
std::optional<Targets::TargetMemoryAddress> fromAddress,
|
|
|
|
|
std::optional<Targets::TargetMemoryAddress> toAddress
|
|
|
|
|
) const;
|
2021-04-24 20:23:17 +01:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Requests the TargetController to step execution on the target.
|
|
|
|
|
*
|
|
|
|
|
* @param fromAddress
|
|
|
|
|
*/
|
2023-04-01 12:40:12 +01:00
|
|
|
void stepTargetExecution(std::optional<Targets::TargetMemoryAddress> fromAddress) const;
|
2021-04-24 20:23:17 +01:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Requests the TargetController to read register values from the target.
|
|
|
|
|
*
|
|
|
|
|
* @param descriptors
|
|
|
|
|
* Descriptors of the registers to read.
|
|
|
|
|
*
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
2022-12-26 22:25:35 +00:00
|
|
|
Targets::TargetRegisters readRegisters(const Targets::TargetRegisterDescriptors& descriptors) const;
|
2021-04-24 20:23:17 +01:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Requests the TargetController to write register values to the target.
|
|
|
|
|
*
|
|
|
|
|
* @param registers
|
|
|
|
|
*/
|
2022-12-26 22:25:35 +00:00
|
|
|
void writeRegisters(const Targets::TargetRegisters& registers) const;
|
2021-04-24 20:23:17 +01:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Requests the TargetController to read memory from the target.
|
|
|
|
|
*
|
|
|
|
|
* @param memoryType
|
|
|
|
|
* @param startAddress
|
|
|
|
|
* @param bytes
|
2021-12-25 20:57:03 +00:00
|
|
|
* @param excludedAddressRanges
|
2021-04-24 20:23:17 +01:00
|
|
|
* @return
|
|
|
|
|
*/
|
2021-05-24 20:58:49 +01:00
|
|
|
Targets::TargetMemoryBuffer readMemory(
|
|
|
|
|
Targets::TargetMemoryType memoryType,
|
2022-09-06 17:16:49 +01:00
|
|
|
Targets::TargetMemoryAddress startAddress,
|
|
|
|
|
Targets::TargetMemorySize bytes,
|
2021-12-25 20:57:03 +00:00
|
|
|
const std::set<Targets::TargetMemoryAddressRange>& excludedAddressRanges = {}
|
2022-12-26 22:25:35 +00:00
|
|
|
) const;
|
2021-04-24 20:23:17 +01:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Requests the TargetController to write memory to the target.
|
|
|
|
|
*
|
|
|
|
|
* @param memoryType
|
|
|
|
|
* @param startAddress
|
|
|
|
|
* @param buffer
|
|
|
|
|
*/
|
2021-05-24 20:58:49 +01:00
|
|
|
void writeMemory(
|
|
|
|
|
Targets::TargetMemoryType memoryType,
|
2022-09-06 17:16:49 +01:00
|
|
|
Targets::TargetMemoryAddress startAddress,
|
2021-05-24 20:58:49 +01:00
|
|
|
const Targets::TargetMemoryBuffer& buffer
|
2022-12-26 22:25:35 +00:00
|
|
|
) const;
|
2021-04-24 20:23:17 +01:00
|
|
|
|
2022-12-11 23:25:15 +00:00
|
|
|
/**
|
|
|
|
|
* Requests the TargetController to erase the given target memory type.
|
|
|
|
|
*
|
|
|
|
|
* @param memoryType
|
|
|
|
|
*/
|
2022-12-26 22:25:35 +00:00
|
|
|
void eraseMemory(Targets::TargetMemoryType memoryType) const;
|
2022-12-11 23:25:15 +00:00
|
|
|
|
2021-04-24 20:23:17 +01:00
|
|
|
/**
|
|
|
|
|
* Requests the TargetController to set a breakpoint on the target.
|
|
|
|
|
*
|
|
|
|
|
* @param breakpoint
|
|
|
|
|
*/
|
2022-12-26 22:25:35 +00:00
|
|
|
void setBreakpoint(Targets::TargetBreakpoint breakpoint) const;
|
2021-04-24 20:23:17 +01:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Requests the TargetController to remove a breakpoint from the target.
|
|
|
|
|
*
|
|
|
|
|
* @param breakpoint
|
|
|
|
|
*/
|
2022-12-26 22:25:35 +00:00
|
|
|
void removeBreakpoint(Targets::TargetBreakpoint breakpoint) const;
|
2021-04-24 20:23:17 +01:00
|
|
|
|
2022-05-01 18:44:04 +01:00
|
|
|
/**
|
|
|
|
|
* Retrieves the current program counter value from the target.
|
|
|
|
|
*
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
2022-12-26 22:25:35 +00:00
|
|
|
Targets::TargetProgramCounter getProgramCounter() const;
|
2022-05-01 18:44:04 +01:00
|
|
|
|
2022-04-30 23:10:07 +01:00
|
|
|
/**
|
|
|
|
|
* Sets the target's program counter to the given address.
|
|
|
|
|
*
|
|
|
|
|
* @param address
|
|
|
|
|
*/
|
2022-12-26 22:25:35 +00:00
|
|
|
void setProgramCounter(Targets::TargetProgramCounter address) const;
|
2022-04-30 23:10:07 +01:00
|
|
|
|
2021-04-24 20:23:17 +01:00
|
|
|
/**
|
2021-09-02 21:19:46 +01:00
|
|
|
* Retrieves the pin states for a particular target variant.
|
2021-04-24 20:23:17 +01:00
|
|
|
*
|
|
|
|
|
* @param variantId
|
|
|
|
|
*/
|
2022-12-26 22:25:35 +00:00
|
|
|
Targets::TargetPinStateMapping getPinStates(int variantId) const;
|
2021-09-02 21:19:46 +01:00
|
|
|
|
|
|
|
|
/**
|
2021-09-04 17:58:05 +01:00
|
|
|
* Updates the pin state on the target, for a specific pin.
|
2021-09-02 21:19:46 +01:00
|
|
|
*
|
|
|
|
|
* @param pinDescriptor
|
|
|
|
|
* @param pinState
|
|
|
|
|
*/
|
2022-12-26 22:25:35 +00:00
|
|
|
void setPinState(Targets::TargetPinDescriptor pinDescriptor, Targets::TargetPinState pinState) const;
|
2021-10-06 21:12:31 +01:00
|
|
|
|
2021-11-11 19:05:59 +00:00
|
|
|
/**
|
|
|
|
|
* Retrieves the current stack pointer value from the target.
|
|
|
|
|
*
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
2022-12-26 22:25:35 +00:00
|
|
|
Targets::TargetStackPointer getStackPointer() const;
|
2021-11-11 19:05:59 +00:00
|
|
|
|
2022-04-08 22:14:01 +01:00
|
|
|
/**
|
|
|
|
|
* Triggers a reset on the target. The target will be held in a stopped state.
|
|
|
|
|
*/
|
2022-12-26 22:25:35 +00:00
|
|
|
void resetTarget() const;
|
2022-04-08 22:14:01 +01:00
|
|
|
|
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.
|
|
|
|
|
*/
|
2022-12-26 22:25:35 +00:00
|
|
|
void enableProgrammingMode() const;
|
2022-06-05 16:13:43 +01:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Disables programming mode on the target.
|
|
|
|
|
*/
|
2022-12-26 22:25:35 +00:00
|
|
|
void disableProgrammingMode() const;
|
2022-06-05 16:13:43 +01:00
|
|
|
|
2021-10-06 21:12:31 +01:00
|
|
|
private:
|
2022-12-26 21:27:19 +00:00
|
|
|
TargetController::CommandManager commandManager = TargetController::CommandManager();
|
2021-10-06 21:12:31 +01:00
|
|
|
|
2022-06-05 21:04:28 +01:00
|
|
|
std::chrono::milliseconds defaultTimeout = std::chrono::milliseconds(60000);
|
2021-04-24 20:23:17 +01:00
|
|
|
};
|
|
|
|
|
}
|