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

190 lines
6.2 KiB
C++
Raw Normal View History

2021-04-04 21:04:12 +01:00
#pragma once
#include <cstdint>
#include <queue>
#include <utility>
2021-04-04 21:04:12 +01:00
#include "src/Targets/Microchip/AVR/Target.hpp"
#include "src/DebugToolDrivers/DebugTool.hpp"
#include "src/DebugToolDrivers/TargetInterfaces/Microchip/AVR/AVR8/Avr8DebugInterface.hpp"
#include "src/DebugToolDrivers/TargetInterfaces/Microchip/AVR/AvrIspInterface.hpp"
2021-04-04 21:04:12 +01:00
#include "Family.hpp"
#include "TargetParameters.hpp"
2021-04-04 21:04:12 +01:00
#include "PadDescriptor.hpp"
2022-06-03 15:46:28 +01:00
#include "ProgrammingSession.hpp"
#include "ProgramMemorySection.hpp"
#include "src/Targets/TargetRegister.hpp"
2021-04-04 21:04:12 +01:00
#include "TargetDescription/TargetDescriptionFile.hpp"
2021-04-04 21:04:12 +01:00
#include "Avr8TargetConfig.hpp"
2021-04-04 21:04:12 +01:00
namespace Bloom::Targets::Microchip::Avr::Avr8Bit
{
class Avr8: public Target
{
public:
explicit Avr8() = default;
Avr8(std::string name, const TargetSignature& signature): name(std::move(name)) {
this->id = signature;
this->initFromTargetDescriptionFile();
};
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;
void postPromotionConfigure() override;
2021-04-08 20:39:53 +01:00
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->getAvr8DebugInterface() != nullptr;
2021-04-04 21:04:12 +01:00
}
void setDebugTool(DebugTool* debugTool) override {
this->targetPowerManagementInterface = debugTool->getTargetPowerManagementInterface();
this->avr8DebugInterface = debugTool->getAvr8DebugInterface();
this->avrIspInterface = debugTool->getAvrIspInterface();
2022-02-27 20:44:01 +00:00
}
2021-04-04 21:04:12 +01:00
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
*/
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
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;
void writeRegisters(TargetRegisters registers) override;
TargetRegisters readRegisters(TargetRegisterDescriptors descriptors) override;
2021-04-08 20:39:53 +01:00
TargetMemoryBuffer readMemory(
2021-04-08 20:39:53 +01:00
TargetMemoryType memoryType,
std::uint32_t startAddress,
std::uint32_t bytes,
const std::set<Targets::TargetMemoryAddressRange>& excludedAddressRanges = {}
2021-04-08 20:39:53 +01:00
) override;
void writeMemory(
2021-04-08 20:39:53 +01:00
TargetMemoryType memoryType,
std::uint32_t startAddress,
const TargetMemoryBuffer& buffer
) override;
2021-04-04 21:04:12 +01:00
TargetState getState() override;
2021-04-04 21:04:12 +01:00
std::uint32_t getProgramCounter() override;
TargetRegister getProgramCounterRegister();
void setProgramCounter(std::uint32_t programCounter) override;
2021-04-08 20:39:53 +01:00
std::uint32_t getStackPointer() override;
std::map<int, TargetPinState> getPinStates(int variantId) override;
void setPinState(
2021-04-04 21:04:12 +01:00
const TargetPinDescriptor& pinDescriptor,
const TargetPinState& state
) override;
void enableProgrammingMode() override;
void disableProgrammingMode() override;
bool programmingModeEnabled() override;
protected:
DebugToolDrivers::TargetInterfaces::TargetPowerManagementInterface* targetPowerManagementInterface = nullptr;
DebugToolDrivers::TargetInterfaces::Microchip::Avr::Avr8::Avr8DebugInterface* avr8DebugInterface = nullptr;
DebugToolDrivers::TargetInterfaces::Microchip::Avr::AvrIspInterface* avrIspInterface = nullptr;
std::optional<Avr8TargetConfig> targetConfig;
std::string name;
std::optional<Family> family;
std::optional<TargetDescription::TargetDescriptionFile> targetDescriptionFile;
std::optional<TargetParameters> targetParameters;
std::map<std::string, PadDescriptor> padDescriptorsByName;
std::map<int, TargetVariant> targetVariantsById;
std::map<TargetRegisterType, TargetRegisterDescriptors> targetRegisterDescriptorsByType;
std::map<TargetMemoryType, TargetMemoryDescriptor> targetMemoryDescriptorsByType;
2022-06-03 15:46:28 +01:00
std::optional<ProgrammingSession> programmingSession;
/**
* Initiates the AVR8 instance from data extracted from the TDF.
*/
void initFromTargetDescriptionFile();
/**
* Populates this->targetRegisterDescriptorsByType with registers extracted from the TDF, as well as general
* purpose and other CPU registers.
*/
void loadTargetRegisterDescriptors();
void loadTargetMemoryDescriptors();
/**
* 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;
/**
* Updates the debugWire enable (DWEN) fuse bit on the AVR target.
*
* @param setFuse
* True to set the fuse, false to clear it.
*/
void writeDwenFuseBit(bool setFuse);
/**
* Resolves the program memory section from a program memory address.
*
* @param address
* @return
*/
ProgramMemorySection getProgramMemorySectionFromAddress(std::uint32_t address);
2021-04-04 21:04:12 +01:00
};
}