Files
BloomPatched/src/Targets/Microchip/AVR/AVR8/Avr8.hpp

165 lines
5.3 KiB
C++
Raw Normal View History

2021-04-04 21:04:12 +01:00
#pragma once
#include <cstdint>
#include <queue>
#include "src/DebugToolDrivers/TargetInterfaces/Microchip/AVR/AVR8/Avr8Interface.hpp"
#include "src/Targets/Microchip/AVR/Target.hpp"
#include "src/Targets/TargetRegister.hpp"
#include "src/DebugToolDrivers/DebugTool.hpp"
#include "src/ApplicationConfig.hpp"
#include "src/Exceptions/Exception.hpp"
#include "TargetParameters.hpp"
#include "Family.hpp"
#include "PadDescriptor.hpp"
#include "TargetDescription/TargetDescriptionFile.hpp"
2021-04-04 21:04:12 +01:00
namespace Bloom::Targets::Microchip::Avr::Avr8Bit
{
class Avr8: public Target
{
protected:
DebugToolDrivers::TargetInterfaces::Microchip::Avr::Avr8::Avr8Interface* avr8Interface;
2021-04-04 21:04:12 +01:00
std::string name = "";
std::optional<Family> family;
std::optional<TargetDescription::TargetDescriptionFile> targetDescriptionFile;
std::optional<TargetParameters> targetParameters;
2021-04-04 21:04:12 +01:00
std::map<std::string, PadDescriptor> padDescriptorsByName;
std::map<int, TargetVariant> targetVariantsById;
2021-04-08 20:39:53 +01:00
/**
* Extracts the ID from the target's memory.
*
* This function will cache the ID value and use the cached version for any subsequent calls.
*
* @return
*/
TargetSignature getId() override;
/**
* Extracts the AVR8 target parameters from the loaded target description file.
2021-04-08 20:39:53 +01:00
*
* @return
*/
2021-04-04 21:04:12 +01:00
virtual TargetParameters& getTargetParameters();
2021-04-08 20:39:53 +01:00
/**
* Generates a collection of PadDescriptor object from data in the loaded target description file and
2021-04-08 20:39:53 +01:00
* populates this->padDescriptorsByName.
*/
2021-04-04 21:04:12 +01:00
virtual void loadPadDescriptors();
2021-04-08 20:39:53 +01:00
/**
* Loads all variants for the AVR8 target, from the TDF.
2021-04-08 20:39:53 +01:00
*/
2021-04-04 21:04:12 +01:00
virtual void loadTargetVariants();
void loadTargetDescriptionFile();
2021-04-04 21:04:12 +01:00
public:
explicit Avr8() = default;
Avr8(const std::string& name, const TargetSignature& signature): name(name) {
this->id = signature;
};
2021-04-04 21:04:12 +01:00
2021-04-08 20:39:53 +01:00
/*
* The functions below implement the Target interface for AVR8 targets.
*
* See the Bloom::Targets::Target interface class for documentation on the expected behaviour of
* each function.
*/
void preActivationConfigure(const TargetConfig& targetConfig) override;
void postActivationConfigure() override;
virtual void postPromotionConfigure() override;
void activate() override;
void deactivate() override;
2021-04-04 21:04:12 +01:00
/**
2021-04-08 20:39:53 +01:00
* All AVR8 compatible debug tools must provide a valid Avr8Interface.
2021-04-04 21:04:12 +01:00
*
* @param debugTool
* @return
*/
bool isDebugToolSupported(DebugTool* debugTool) override {
return debugTool->getAvr8Interface() != nullptr;
}
void setDebugTool(DebugTool* debugTool) override {
this->avr8Interface = debugTool->getAvr8Interface();
};
2021-04-08 20:39:53 +01:00
/**
* Instances to this target class can be promoted. See Avr8::promote() method for more.
*
* @return
*/
bool supportsPromotion() override {
return true;
}
2021-04-04 21:04:12 +01:00
2021-04-08 20:39:53 +01:00
/**
* Instances of this generic Avr8 target class will be promoted to a family specific class (see the Mega, Xmega
* and Tiny classes for more).
*
* @return
*/
virtual std::unique_ptr<Targets::Target> promote() override;
2021-04-04 21:04:12 +01:00
2021-04-08 20:39:53 +01:00
std::string getName() const override {
return this->name;
}
2021-04-04 21:04:12 +01:00
2021-04-08 20:39:53 +01:00
virtual TargetDescriptor getDescriptor() override;
2021-04-04 21:04:12 +01:00
void run() override;
void stop() override;
void step() override;
void reset() override;
void setBreakpoint(std::uint32_t address) override;
void removeBreakpoint(std::uint32_t address) override;
void clearAllBreakpoints() override;
virtual TargetRegisters readGeneralPurposeRegisters(std::set<std::size_t> registerIds) override;
virtual void writeRegisters(const TargetRegisters& registers) override;
virtual TargetRegisters readRegisters(const TargetRegisterDescriptors& descriptors) override;
2021-04-08 20:39:53 +01:00
virtual TargetMemoryBuffer readMemory(
TargetMemoryType memoryType,
std::uint32_t startAddress,
std::uint32_t bytes
) override;
virtual void writeMemory(
TargetMemoryType memoryType,
std::uint32_t startAddress,
const TargetMemoryBuffer& buffer
) override;
2021-04-04 21:04:12 +01:00
virtual TargetState getState() override;
virtual std::uint32_t getProgramCounter() override;
virtual TargetRegister getProgramCounterRegister() override;
2021-04-08 20:39:53 +01:00
virtual void setProgramCounter(std::uint32_t programCounter) override;
2021-04-04 21:04:12 +01:00
virtual TargetRegister getStackPointerRegister() override;
virtual TargetRegister getStatusRegister() override;
virtual std::map<int, TargetPinState> getPinStates(int variantId) override;
virtual void setPinState(
int variantId,
const TargetPinDescriptor& pinDescriptor,
const TargetPinState& state
) override;
virtual bool memoryAddressRangeClashesWithIoPortRegisters(
2021-04-04 21:04:12 +01:00
TargetMemoryType memoryType,
std::uint32_t startAddress,
std::uint32_t endAddress
2021-04-04 21:04:12 +01:00
) override;
};
}