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"
|
|
|
|
|
|
2021-05-31 01:01:14 +01:00
|
|
|
#include "TargetDescription/TargetDescriptionFile.hpp"
|
2021-04-04 21:04:12 +01:00
|
|
|
|
|
|
|
|
namespace Bloom::Targets::Microchip::Avr::Avr8Bit
|
|
|
|
|
{
|
|
|
|
|
class Avr8: public Target
|
|
|
|
|
{
|
|
|
|
|
protected:
|
2021-05-24 20:58:49 +01:00
|
|
|
DebugToolDrivers::TargetInterfaces::Microchip::Avr::Avr8::Avr8Interface* avr8Interface;
|
2021-04-04 21:04:12 +01:00
|
|
|
std::string name = "";
|
|
|
|
|
std::optional<Family> family;
|
2021-06-03 00:49:08 +01:00
|
|
|
std::optional<TargetDescription::TargetDescriptionFile> targetDescriptionFile;
|
2021-04-07 20:34:12 +01:00
|
|
|
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;
|
|
|
|
|
|
|
|
|
|
/**
|
2021-05-31 01:01:14 +01:00
|
|
|
* 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
|
|
|
/**
|
2021-05-31 01:01:14 +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
|
|
|
|
|
|
|
|
/**
|
2021-05-31 01:01:14 +01:00
|
|
|
* Extracts target variant information from the loaded target description file and generates a collection
|
2021-04-08 20:39:53 +01:00
|
|
|
* of TargetVariant objects.
|
|
|
|
|
*
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
2021-06-03 00:49:08 +01:00
|
|
|
virtual std::vector<TargetVariant> generateVariantsFromTdf();
|
2021-04-08 20:39:53 +01:00
|
|
|
|
|
|
|
|
/**
|
2021-06-03 00:49:08 +01:00
|
|
|
* Populates this->targetVariantsById using this->generateVariantsFromTdf() and data from
|
2021-04-08 20:39:53 +01:00
|
|
|
* this->padDescriptorsByName.
|
|
|
|
|
*/
|
2021-04-04 21:04:12 +01:00
|
|
|
virtual void loadTargetVariants();
|
|
|
|
|
|
2021-06-03 00:49:08 +01:00
|
|
|
void loadTargetDescriptionFile();
|
2021-05-02 15:50:07 +01:00
|
|
|
|
2021-04-04 21:04:12 +01:00
|
|
|
public:
|
|
|
|
|
explicit Avr8() = default;
|
2021-05-02 15:50:07 +01:00
|
|
|
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;
|
|
|
|
|
|
2021-04-07 20:34:12 +01:00
|
|
|
virtual bool memoryAddressRangeClashesWithIoPortRegisters(
|
2021-04-04 21:04:12 +01:00
|
|
|
TargetMemoryType memoryType,
|
|
|
|
|
std::uint32_t startAddress,
|
2021-04-07 20:34:12 +01:00
|
|
|
std::uint32_t endAddress
|
2021-04-04 21:04:12 +01:00
|
|
|
) override;
|
|
|
|
|
};
|
|
|
|
|
}
|