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

199 lines
6.6 KiB
C++
Raw Normal View History

2021-04-04 21:04:12 +01:00
#pragma once
#include <cstdint>
#include <queue>
#include <utility>
2022-10-09 13:10:17 +01:00
#include <optional>
2021-04-04 21:04:12 +01:00
#include "src/Targets/Target.hpp"
2021-04-04 21:04:12 +01:00
#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"
#include "ProgramMemorySection.hpp"
2023-05-26 22:36:43 +01:00
#include "src/Targets/Microchip/AVR/Fuse.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(const TargetConfig& targetConfig);
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 abstract class for documentation on the expected behaviour of
2021-04-08 20:39:53 +01:00
* each function.
*/
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 supportsDebugTool(DebugTool* debugTool) override;
2021-04-04 21:04:12 +01:00
void setDebugTool(DebugTool* debugTool) override;
2021-04-04 21:04:12 +01:00
void activate() override;
void deactivate() override;
2021-04-04 21:04:12 +01:00
TargetDescriptor getDescriptor() override;
2021-04-04 21:04:12 +01:00
void run(std::optional<TargetMemoryAddress> toAddress = std::nullopt) override;
2021-04-04 21:04:12 +01:00
void stop() override;
void step() override;
void reset() override;
void setBreakpoint(TargetProgramCounter address) override;
void removeBreakpoint(TargetProgramCounter address) override;
2021-04-04 21:04:12 +01:00
void clearAllBreakpoints() override;
void writeRegisters(TargetRegisters registers) override;
TargetRegisters readRegisters(const Targets::TargetRegisterDescriptorIds& descriptorIds) override;
2021-04-08 20:39:53 +01:00
TargetMemoryBuffer readMemory(
2021-04-08 20:39:53 +01:00
TargetMemoryType memoryType,
TargetMemoryAddress startAddress,
TargetMemorySize 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,
TargetMemoryAddress startAddress,
2021-04-08 20:39:53 +01:00
const TargetMemoryBuffer& buffer
) override;
void eraseMemory(TargetMemoryType memoryType) override;
2021-04-04 21:04:12 +01:00
TargetState getState() override;
2021-04-04 21:04:12 +01:00
TargetProgramCounter getProgramCounter() override;
void setProgramCounter(TargetProgramCounter programCounter) override;
2021-04-08 20:39:53 +01:00
TargetStackPointer 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;
Avr8TargetConfig targetConfig;
TargetDescription::TargetDescriptionFile targetDescriptionFile;
TargetSignature signature;
std::string name;
Family family;
TargetParameters targetParameters;
std::set<PhysicalInterface> supportedPhysicalInterfaces;
std::map<std::string, PadDescriptor> padDescriptorsByName;
std::map<int, TargetVariant> targetVariantsById;
TargetRegisterDescriptor stackPointerRegisterDescriptor;
TargetRegisterDescriptor statusRegisterDescriptor;
2023-05-26 22:36:43 +01:00
/**
* On some AVR8 targets, like the ATmega328P, a cleared fuse bit means the fuse is "programmed" (enabled).
* And a set bit means the fuse is "un-programmed" (disabled). But on others, like the ATmega4809, it's the
* other way around (set bit == enabled, cleared bit == disabled).
*
* The FuseEnableStrategy specifies the strategy of enabling a fuse. It's extracted from the TDF.
* See TargetDescription::getFuseEnableStrategy() for more.
*/
FuseEnableStrategy fuseEnableStrategy;
std::map<TargetRegisterDescriptorId, TargetRegisterDescriptor> targetRegisterDescriptorsById;
std::map<TargetMemoryType, TargetMemoryDescriptor> targetMemoryDescriptorsByType;
bool progModeEnabled = false;
/**
* Populates this->targetRegisterDescriptorsById with registers extracted from the TDF, as well as general
* purpose and other CPU registers.
*/
void loadTargetRegisterDescriptors();
void loadTargetMemoryDescriptors();
2023-05-26 22:36:43 +01:00
/**
* Checks if a particular fuse is enabled in the given fuse byte value. Takes the target's fuse enable strategy
* into account.
*
* @param descriptor
* @param fuseByteValue
*
* @return
*/
bool isFuseEnabled(const FuseBitsDescriptor& descriptor, unsigned char fuseByteValue) const;
/**
* Enables/disables a fuse within the given fuse byte, using the target's fuse enable strategy.
*
* @param descriptor
* @param fuseByteValue
* @param enabled
*
* @return
* The updated fuse byte value.
*/
unsigned char setFuseEnabled(
const FuseBitsDescriptor& descriptor,
unsigned char fuseByteValue,
bool enabled
) const;
/**
* 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-10-09 13:10:30 +01:00
void updateDwenFuseBit(bool enable);
2023-05-07 16:49:45 +01:00
/**
* Updates the On-chip debug enable (OCDEN) fuse bit on the AVR target.
*
* @param enable
* True to enable the fuse, false to disable it.
*/
void updateOcdenFuseBit(bool enable);
/**
* 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.
*
* @param address
* @return
*/
ProgramMemorySection getProgramMemorySectionFromAddress(TargetMemoryAddress address);
2021-04-04 21:04:12 +01:00
};
}