Skip to content

Commit

Permalink
Refactoring: Added JtagDevice::PostInitProbes()
Browse files Browse the repository at this point in the history
  • Loading branch information
azonenberg committed Jul 23, 2018
1 parent 8f4858c commit c012b8e
Show file tree
Hide file tree
Showing 18 changed files with 80 additions and 137 deletions.
9 changes: 6 additions & 3 deletions ARM7TDMISProcessor.cpp
Expand Up @@ -56,16 +56,19 @@ ARM7TDMISProcessor::ARM7TDMISProcessor(
, m_rev(rev)
{
m_selectedChain = 255;

//WriteIceRegister(DEBUG_CTRL, 0x3f);
//uint32_t ret = ReadIceRegister(DEBUG_CTRL);
}

ARM7TDMISProcessor::~ARM7TDMISProcessor()
{

}

void ARM7TDMISProcessor::PostInitProbes()
{
//WriteIceRegister(DEBUG_CTRL, 0x3f);
//uint32_t ret = ReadIceRegister(DEBUG_CTRL);
}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Scan chain selection

Expand Down
2 changes: 2 additions & 0 deletions ARM7TDMISProcessor.h
Expand Up @@ -67,6 +67,8 @@ class ARM7TDMISProcessor : public DebuggableDevice
BYPASS = 0xf
};

virtual void PostInitProbes();

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Internal debug stuff

Expand Down
3 changes: 3 additions & 0 deletions ARMDebugPort.cpp
Expand Up @@ -56,7 +56,10 @@ ARMDebugPort::ARMDebugPort(
//No Mem-AP for now
m_defaultMemAP = NULL;
m_defaultRegisterAP = NULL;
}

void ARMDebugPort::PostInitProbes()
{
//Turn on the debug stuff
EnableDebugging();

Expand Down
2 changes: 2 additions & 0 deletions ARMDebugPort.h
Expand Up @@ -141,6 +141,8 @@ class ARMDebugPort : public ARMDevice
INST_APACC = 0x0b,
};

virtual void PostInitProbes();

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// General device info

Expand Down
25 changes: 18 additions & 7 deletions FreescaleIMXDevice.cpp
Expand Up @@ -39,10 +39,25 @@

using namespace std;

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Construction / destruction

FreescaleIMXDevice::FreescaleIMXDevice(
unsigned int devid, unsigned int stepping,
unsigned int idcode, JtagInterface* iface, size_t pos)
: FreescaleMicrocontroller(idcode, iface, pos, 5)
{

}

/**
@brief Destructor
*/
FreescaleIMXDevice::~FreescaleIMXDevice()
{
}

void FreescaleIMXDevice::PostInitProbes()
{
/*
m_devid = devid;
Expand Down Expand Up @@ -73,20 +88,16 @@ FreescaleIMXDevice::FreescaleIMXDevice(
GetImpCode();*/
}

/**
@brief Destructor
*/
FreescaleIMXDevice::~FreescaleIMXDevice()
{
}

JtagDevice* FreescaleIMXDevice::CreateDevice(
unsigned int devid, unsigned int stepping, unsigned int idcode, JtagInterface* iface, size_t pos)
{
//TODO: Sanity checks
return new FreescaleIMXDevice(devid, stepping, idcode, iface, pos);
}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// General device info

string FreescaleIMXDevice::GetDescription()
{
/*
Expand Down
125 changes: 3 additions & 122 deletions FreescaleIMXDevice.h
Expand Up @@ -67,103 +67,9 @@ class FreescaleIMXDevice : public FreescaleMicrocontroller
JtagInterface* iface,
size_t pos);

/*
///Device families
enum families
{
FAMILY_MX12, //PIC32MX 1xx/2xx
FAMILY_MX34, //PIC32MX 3xx/4xx
FAMILY_MX567, //PIC32MX 5xx/6xx/7xx
FAMILY_MM, //All PIC32MM devices
virtual void PostInitProbes();

FAMILY_MZ //All PIC32MZ devices
};
///CPU types
enum cpus
{
CPU_M4K,
CPU_MAPTIV
};
///JTAG device IDs (from BSDL files and/or flash programming spec)
enum deviceids
{
PIC32MX110F016B = 0x4a07,
PIC32MX110F016C = 0x4a09,
PIC32MX110F016D = 0x4a0b,
PIC32MX120F032B = 0x4a06,
PIC32MX120F032C = 0x4a08,
PIC32MX120F032D = 0x4a0a,
PIC32MX130F064B = 0x4d07,
PIC32MX130F064C = 0x4d09,
PIC32MX130F064D = 0x4d0b,
PIC32MX150F128B = 0x4d06,
PIC32MX150F128C = 0x4d08,
PIC32MX150F128D = 0x4d0a,
PIC32MX210F016B = 0x4a01,
PIC32MX210F016C = 0x4a03,
PIC32MX210F016D = 0x4a05,
PIC32MX220F032B = 0x4a00,
PIC32MX220F032C = 0x4a02,
PIC32MX220F032D = 0x4a04,
PIC32MX230F064B = 0x4d01,
PIC32MX230F064C = 0x4d03,
PIC32MX230F064D = 0x4d05,
PIC32MX250F128B = 0x4d00,
PIC32MX250F128C = 0x4d02,
PIC32MX250F128D = 0x4d04,
PIC32MX330F064H = 0x5600,
PIC32MX330F064L = 0x5601,
PIC32MX340F512H = 0x0916,
PIC32MX350F128H = 0x570c,
//PIC32MX350F128L = 0x570d, //350F128L and 350F256H have same IDCODE... BSDL error?
PIC32MX350F256H = 0x570d,
PIC32MX350F256L = 0x5705,
PIC32MX430F064H = 0x5602,
PIC32MX430F064L = 0x5603,
PIC32MX450F128H = 0x570e,
PIC32MX450F128L = 0x570f,
PIC32MX450F256H = 0x5706,
PIC32MX450F256L = 0x5707,
PIC32MX534F064H = 0x440c, //H and L have same IDCODE... BSDL error?
//PIC32MX534F064L = 0x440c,
PIC32MX564F064H = 0x4401,
PIC32MX564F064L = 0x440d,
PIC32MX564F128H = 0x4403,
PIC32MX564F128L = 0x440f,
PIC32MX664F064H = 0x4405,
PIC32MX664F064L = 0x4411,
PIC32MX664F128H = 0x4407,
PIC32MX664F128L = 0x4413,
PIC32MX695F512L = 0x4341,
PIC32MX764F128H = 0x440b,
PIC32MX764F128L = 0x4417,
PIC32MX795F512L = 0x4307,
PIC32MM0016GPL020 = 0x6b04,
PIC32MM0032GPL020 = 0x6b0c,
PIC32MM0064GPL020 = 0x6b14,
PIC32MM0016GPL028 = 0x6b02,
PIC32MM0032GPL028 = 0x6b0a,
PIC32MM0064GPL028 = 0x6b12,
PIC32MM0016GPL036 = 0x6b06,
PIC32MM0032GPL036 = 0x6b0b,
PIC32MM0064GPL036 = 0x6b16,
PIC32MM0064GPM028 = 0x7708,
PIC32MM0128GPM028 = 0x7710,
PIC32MM0256GPM028 = 0x7718,
PIC32MM0064GPM036 = 0x770a,
PIC32MM0128GPM036 = 0x7712,
PIC32MM0256GPM036 = 0x771a,
PIC32MM0064GPM048 = 0x772c,
PIC32MM0128GPM048 = 0x7734,
PIC32MM0256GPM048 = 0x773c,
PIC32MM0064GPM064 = 0x770e,
PIC32MM0128GPM064 = 0x7716,
PIC32MM0256GPM064 = 0x771e
};
/*
///5-bit-wide JTAG instructions (from BSDL file and datasheet)
enum instructions
Expand Down Expand Up @@ -210,31 +116,6 @@ class FreescaleIMXDevice : public FreescaleMicrocontroller
//Sample the program counter (used for profiling... not implemented?)
INST_PCSAMPLE = 0x14
};
///8-bit instructions for Microchip virtual TAP (write to INST_MTAP_COMMAND data register)
enum mtap_instructions
{
///Get status
MCHP_STATUS = 0x00,
///Begin chip reset
MCHP_ASSERT_RST = 0xD1,
///End chip reset
MCHP_DE_ASSERT_RST = 0xD0,
///Bulk-erase flash
MCHP_ERASE = 0xFC,
///Enable connecting the CPU to flash
MCHP_FLASH_ENABLE = 0xFE,
///Disconnect the CPU from flash
MCHP_FLASH_DISABLE = 0xFD,
///Force re-read of device config
MCHP_READ_CONFIG = 0xFF
};
*/
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// General device info
Expand All @@ -249,7 +130,6 @@ class FreescaleIMXDevice : public FreescaleMicrocontroller

virtual void Program(FirmwareImage* image);

/*
//FreescaleIMXDeviceStatusRegister GetStatusRegister();

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
Expand All @@ -258,6 +138,7 @@ class FreescaleIMXDevice : public FreescaleMicrocontroller
void SetIR(unsigned char irval)
{ JtagDevice::SetIR(&irval, m_irlength); }

/*
protected:
void EnterMtapMode();
uint8_t SendMchpCommand(uint8_t cmd);
Expand Down
8 changes: 4 additions & 4 deletions JtagDevice.cpp
Expand Up @@ -46,6 +46,10 @@ using namespace std;
/**
@brief Initializes this device
NOTE: Do not do probes/scans of the chain during the constructor, because we haven't initialized all TAPs yet.
Any initialization that involves querying the chain should be done in PostInitProbes().
@param idcode The ID code of this device
@param iface The JTAG adapter this device was discovered on
@param pos Position in the chain that this device was discovered
Expand All @@ -61,10 +65,6 @@ JtagDevice::JtagDevice(unsigned int idcode, JtagInterface* iface, size_t pos, si
m_irlength = 0;

memset(m_cachedIR, 0xFF, sizeof(m_cachedIR));

//If we are the last device in the chain, have the interface recalculate and add dummy devices as needed
if(pos == iface->GetDeviceCount()-1)
iface->CreateDummyDevices();
}

/**
Expand Down
5 changes: 5 additions & 0 deletions JtagDevice.h
Expand Up @@ -64,6 +64,11 @@ class JtagDevice

virtual void PrintInfo();

/**
@brief Does a post-initialization probe of the device to read debug ROMs etc.
*/
virtual void PostInitProbes() =0;

public:
//JTAG interface helpers
void SetIR(const unsigned char* data)
Expand Down
10 changes: 10 additions & 0 deletions JtagInterface.cpp
Expand Up @@ -305,6 +305,16 @@ void JtagInterface::InitializeChain()
else
m_devices.push_back(JtagDevice::CreateDevice(m_idcodes[i], this, i));
}

//Once devices are created, add dummies if needed
CreateDummyDevices();

//Do init that requires probing the chain once we have all of our devices
for(auto p : m_devices)
{
if(p)
p->PostInitProbes();
}
}

/**
Expand Down
1 change: 1 addition & 0 deletions JtagInterface.h
Expand Up @@ -218,6 +218,7 @@ class JtagInterface
void ScanDRSplitWrite(unsigned int device, const unsigned char* send_data, unsigned char* rcv_data, size_t count);
void ScanDRSplitRead(unsigned int device, unsigned char* rcv_data, size_t count);

protected:
//Helpers for initialization
void CreateDummyDevices();

Expand Down
3 changes: 3 additions & 0 deletions MicrochipPIC32Device.cpp
Expand Up @@ -247,7 +247,10 @@ MicrochipPIC32Device::MicrochipPIC32Device(
"Invalid PIC32 JTAG IDCODE",
"");
}
}

void MicrochipPIC32Device::PostInitProbes()
{
//Reset both TAPS
EnterMtapMode();
ResetToIdle();
Expand Down
2 changes: 2 additions & 0 deletions MicrochipPIC32Device.h
Expand Up @@ -172,6 +172,8 @@ class MicrochipPIC32Device : public MicrochipMicrocontroller
JtagInterface* iface,
size_t pos);

virtual void PostInitProbes();

///Device families
enum families
{
Expand Down
7 changes: 6 additions & 1 deletion STM32Device.cpp
Expand Up @@ -98,8 +98,13 @@ STM32Device::STM32Device(
m_ramKB = 0;
}

//Check read lock status
m_locksProbed = false;

}

void STM32Device::PostInitProbes()
{
//Check read lock status
STM32Device::ProbeLocksNondestructive();

//Extract serial number fields
Expand Down
2 changes: 2 additions & 0 deletions STM32Device.h
Expand Up @@ -70,6 +70,8 @@ class STM32Device
JtagInterface* iface,
size_t pos);

virtual void PostInitProbes();

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// General device info

Expand Down
4 changes: 4 additions & 0 deletions XilinxCoolRunnerIIDevice.cpp
Expand Up @@ -50,6 +50,10 @@ XilinxCoolRunnerIIDevice::XilinxCoolRunnerIIDevice(
m_stepping = stepping;
}

void XilinxCoolRunnerIIDevice::PostInitProbes()
{
}

/**
@brief Destructor
*/
Expand Down
2 changes: 2 additions & 0 deletions XilinxCoolRunnerIIDevice.h
Expand Up @@ -99,6 +99,8 @@ class XilinxCoolRunnerIIDevice : public XilinxCPLD
JtagInterface* iface,
size_t pos);

virtual void PostInitProbes();

///JTAG device IDs
enum deviceids
{
Expand Down
5 changes: 5 additions & 0 deletions XilinxFPGA.cpp
Expand Up @@ -53,6 +53,11 @@ XilinxFPGA::XilinxFPGA(unsigned int idcode, JtagInterface* iface, size_t pos, si
{
}

void XilinxFPGA::PostInitProbes()
{

}

/**
@brief Default virtual destructor
*/
Expand Down
2 changes: 2 additions & 0 deletions XilinxFPGA.h
Expand Up @@ -49,6 +49,8 @@ class XilinxFPGA : public XilinxDevice
XilinxFPGA(unsigned int idcode, JtagInterface* iface, size_t pos, size_t irlength);
virtual ~XilinxFPGA();

virtual void PostInitProbes();

protected:
//Static function for parsing bitstream headers (common to all Xilinx devices)
void ParseBitstreamCore(XilinxFPGABitstream* bitstream, const unsigned char* data, size_t len);\
Expand Down

0 comments on commit c012b8e

Please sign in to comment.