2021-04-04 21:04:12 +01:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
|
|
#include <cstdint>
|
|
|
|
|
#include <queue>
|
2021-06-22 23:52:31 +01:00
|
|
|
#include <utility>
|
2022-10-09 13:10:17 +01:00
|
|
|
#include <optional>
|
2021-04-04 21:04:12 +01:00
|
|
|
|
|
|
|
|
#include "src/Targets/Microchip/AVR/Target.hpp"
|
|
|
|
|
#include "src/DebugToolDrivers/DebugTool.hpp"
|
|
|
|
|
|
2022-03-05 18:00:34 +00:00
|
|
|
#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"
|
2022-03-05 18:00:34 +00:00
|
|
|
#include "TargetParameters.hpp"
|
2021-04-04 21:04:12 +01:00
|
|
|
#include "PadDescriptor.hpp"
|
2022-06-03 15:49:12 +01:00
|
|
|
#include "ProgramMemorySection.hpp"
|
2022-03-05 18:00:34 +00:00
|
|
|
#include "src/Targets/TargetRegister.hpp"
|
2021-04-04 21:04:12 +01:00
|
|
|
|
2021-05-31 01:01:14 +01:00
|
|
|
#include "TargetDescription/TargetDescriptionFile.hpp"
|
2021-04-04 21:04:12 +01:00
|
|
|
|
2022-03-19 13:27:36 +00:00
|
|
|
#include "Avr8TargetConfig.hpp"
|
2022-03-05 18:00:34 +00:00
|
|
|
|
2021-04-04 21:04:12 +01:00
|
|
|
namespace Bloom::Targets::Microchip::Avr::Avr8Bit
|
|
|
|
|
{
|
|
|
|
|
class Avr8: public Target
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
explicit Avr8() = default;
|
2022-12-03 22:16:21 +00:00
|
|
|
Avr8(std::string name, const TargetSignature& signature)
|
|
|
|
|
: name(std::move(name))
|
|
|
|
|
, Target(signature)
|
|
|
|
|
{
|
2021-06-27 20:09:15 +01:00
|
|
|
this->initFromTargetDescriptionFile();
|
2021-05-02 15:50:07 +01:00
|
|
|
};
|
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;
|
2021-06-22 23:52:31 +01:00
|
|
|
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 {
|
2022-02-15 13:14:03 +00:00
|
|
|
return debugTool->getAvr8DebugInterface() != nullptr;
|
2021-04-04 21:04:12 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void setDebugTool(DebugTool* debugTool) override {
|
2022-03-16 17:13:40 +00:00
|
|
|
this->targetPowerManagementInterface = debugTool->getTargetPowerManagementInterface();
|
2022-02-15 13:14:03 +00:00
|
|
|
this->avr8DebugInterface = debugTool->getAvr8DebugInterface();
|
2022-03-05 18:00:34 +00:00
|
|
|
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
|
|
|
|
|
*/
|
2021-06-22 23:52:31 +01:00
|
|
|
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-06-22 23:52:31 +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;
|
|
|
|
|
|
2022-09-06 17:16:49 +01:00
|
|
|
void setBreakpoint(TargetProgramCounter address) override;
|
|
|
|
|
void removeBreakpoint(TargetProgramCounter address) override;
|
2021-04-04 21:04:12 +01:00
|
|
|
void clearAllBreakpoints() override;
|
|
|
|
|
|
2021-08-07 17:28:54 +01:00
|
|
|
void writeRegisters(TargetRegisters registers) override;
|
|
|
|
|
TargetRegisters readRegisters(TargetRegisterDescriptors descriptors) override;
|
2021-04-08 20:39:53 +01:00
|
|
|
|
2021-06-22 23:52:31 +01:00
|
|
|
TargetMemoryBuffer readMemory(
|
2021-04-08 20:39:53 +01:00
|
|
|
TargetMemoryType memoryType,
|
2022-09-06 17:16:49 +01:00
|
|
|
TargetMemoryAddress startAddress,
|
|
|
|
|
TargetMemorySize bytes,
|
2021-12-25 20:57:03 +00:00
|
|
|
const std::set<Targets::TargetMemoryAddressRange>& excludedAddressRanges = {}
|
2021-04-08 20:39:53 +01:00
|
|
|
) override;
|
2021-06-22 23:52:31 +01:00
|
|
|
void writeMemory(
|
2021-04-08 20:39:53 +01:00
|
|
|
TargetMemoryType memoryType,
|
2022-09-06 17:16:49 +01:00
|
|
|
TargetMemoryAddress startAddress,
|
2021-04-08 20:39:53 +01:00
|
|
|
const TargetMemoryBuffer& buffer
|
|
|
|
|
) override;
|
2022-12-11 18:18:39 +00:00
|
|
|
void eraseMemory(TargetMemoryType memoryType) override;
|
2021-04-04 21:04:12 +01:00
|
|
|
|
2021-06-22 23:52:31 +01:00
|
|
|
TargetState getState() override;
|
2021-04-04 21:04:12 +01:00
|
|
|
|
2022-09-06 17:16:49 +01:00
|
|
|
TargetProgramCounter getProgramCounter() override;
|
2021-08-07 17:28:54 +01:00
|
|
|
TargetRegister getProgramCounterRegister();
|
2022-09-06 17:16:49 +01:00
|
|
|
void setProgramCounter(TargetProgramCounter programCounter) override;
|
2021-04-08 20:39:53 +01:00
|
|
|
|
2022-09-06 17:16:49 +01:00
|
|
|
TargetStackPointer getStackPointer() override;
|
2021-11-11 19:03:23 +00:00
|
|
|
|
2021-06-22 23:52:31 +01:00
|
|
|
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;
|
2021-10-06 21:12:31 +01:00
|
|
|
|
2022-05-15 17:42:02 +01:00
|
|
|
void enableProgrammingMode() override;
|
|
|
|
|
|
|
|
|
|
void disableProgrammingMode() override;
|
|
|
|
|
|
|
|
|
|
bool programmingModeEnabled() override;
|
|
|
|
|
|
2021-10-06 21:12:31 +01:00
|
|
|
protected:
|
2022-03-16 17:13:40 +00:00
|
|
|
DebugToolDrivers::TargetInterfaces::TargetPowerManagementInterface* targetPowerManagementInterface = nullptr;
|
2022-02-15 13:14:03 +00:00
|
|
|
DebugToolDrivers::TargetInterfaces::Microchip::Avr::Avr8::Avr8DebugInterface* avr8DebugInterface = nullptr;
|
2022-03-05 18:00:34 +00:00
|
|
|
DebugToolDrivers::TargetInterfaces::Microchip::Avr::AvrIspInterface* avrIspInterface = nullptr;
|
|
|
|
|
|
2022-03-19 13:27:36 +00:00
|
|
|
std::optional<Avr8TargetConfig> targetConfig;
|
|
|
|
|
|
2021-10-06 21:12:31 +01:00
|
|
|
std::string name;
|
|
|
|
|
std::optional<Family> family;
|
|
|
|
|
std::optional<TargetDescription::TargetDescriptionFile> targetDescriptionFile;
|
2022-03-01 22:40:00 +00:00
|
|
|
|
2022-08-04 21:06:13 +01:00
|
|
|
std::set<PhysicalInterface> supportedPhysicalInterfaces;
|
|
|
|
|
|
2021-10-06 21:12:31 +01:00
|
|
|
std::optional<TargetParameters> targetParameters;
|
|
|
|
|
std::map<std::string, PadDescriptor> padDescriptorsByName;
|
|
|
|
|
std::map<int, TargetVariant> targetVariantsById;
|
|
|
|
|
std::map<TargetRegisterType, TargetRegisterDescriptors> targetRegisterDescriptorsByType;
|
2021-10-09 19:18:27 +01:00
|
|
|
std::map<TargetMemoryType, TargetMemoryDescriptor> targetMemoryDescriptorsByType;
|
2021-10-06 21:12:31 +01:00
|
|
|
|
2022-12-11 23:27:08 +00:00
|
|
|
bool progModeEnabled = false;
|
2022-05-15 17:42:02 +01:00
|
|
|
|
2021-10-06 21:12:31 +01:00
|
|
|
/**
|
|
|
|
|
* 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();
|
|
|
|
|
|
2021-10-09 19:18:27 +01:00
|
|
|
void loadTargetMemoryDescriptors();
|
|
|
|
|
|
2021-10-06 21:12:31 +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;
|
2022-03-05 18:03:00 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Updates the debugWire enable (DWEN) fuse bit on the AVR target.
|
|
|
|
|
*
|
2022-10-09 13:10:30 +01:00
|
|
|
* @param enable
|
|
|
|
|
* True to enable the fuse, false to disable it.
|
2022-03-05 18:03:00 +00:00
|
|
|
*/
|
2022-10-09 13:10:30 +01:00
|
|
|
void updateDwenFuseBit(bool enable);
|
2022-06-03 15:49:12 +01:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Resolves the program memory section from a program memory address.
|
|
|
|
|
*
|
2022-12-13 21:12:16 +00:00
|
|
|
* Currently unused, but will be needed soon.
|
|
|
|
|
*
|
2022-06-03 15:49:12 +01:00
|
|
|
* @param address
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
2022-09-06 17:16:49 +01:00
|
|
|
ProgramMemorySection getProgramMemorySectionFromAddress(TargetMemoryAddress address);
|
2021-04-04 21:04:12 +01:00
|
|
|
};
|
|
|
|
|
}
|