Skip to content

Commit

Permalink
Initial skeleton of SWD support classes.
Browse files Browse the repository at this point in the history
  • Loading branch information
azonenberg committed Aug 27, 2018
1 parent 6d0da0d commit dbcfeb1
Show file tree
Hide file tree
Showing 4 changed files with 268 additions and 0 deletions.
3 changes: 3 additions & 0 deletions ARMDebugPort.h
Expand Up @@ -36,6 +36,8 @@
#ifndef ARMDebugPort_h
#define ARMDebugPort_h

#include "DebuggerInterface.h"

/**
@brief Base class for ARM debug ports (JTAG-DP, SWJ-DP, etc)
Expand Down Expand Up @@ -66,6 +68,7 @@ class ARMDebugPort : public DebuggerInterface
{
REG_MEM_CSW = 0x00, //Control/status word
REG_MEM_TAR = 0x04, //Transfer address register

REG_MEM_DRW = 0x0C, //Data read/write
REG_MEM_BASE = 0xF8, //Location of debug ROM

Expand Down
132 changes: 132 additions & 0 deletions SWDDevice.h
@@ -0,0 +1,132 @@
/***********************************************************************************************************************
* *
* ANTIKERNEL v0.1 *
* *
* Copyright (c) 2012-2018 Andrew D. Zonenberg *
* All rights reserved. *
* *
* Redistribution and use in source and binary forms, with or without modification, are permitted provided that the *
* following conditions are met: *
* *
* * Redistributions of source code must retain the above copyright notice, this list of conditions, and the *
* following disclaimer. *
* *
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the *
* following disclaimer in the documentation and/or other materials provided with the distribution. *
* *
* * Neither the name of the author nor the names of any contributors may be used to endorse or promote products *
* derived from this software without specific prior written permission. *
* *
* THIS SOFTWARE IS PROVIDED BY THE AUTHORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED *
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL *
* THE AUTHORS BE HELD LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES *
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR *
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT *
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE *
* POSSIBILITY OF SUCH DAMAGE. *
* *
***********************************************************************************************************************/

/**
@file
@author Andrew D. Zonenberg
@brief Declaration of SWDDevice
*/

#ifndef SWDDevice_h
#define SWDDevice_h

/**
@brief A single SWD-connected device
\ingroup features
*/
class SWDDevice
{
public:
/*
SWDDevice(uint32_t idcode, SWDInterface* iface, size_t pos, size_t irlength);
virtual ~SWDDevice();
*/

/**
@brief Gets a human-readable description of this device.
Example: "Xilinx XC6SLX45 stepping 3"
@return Device description
*/
/*
virtual std::string GetDescription()=0;
unsigned int GetIDCode();
static SWDDevice* CreateDevice(uint32_t idcode, JtagInterface* iface, size_t pos);
virtual void PrintInfo();
*/

/**
@brief Does a post-initialization probe of the device to read debug ROMs etc.
@param quiet Do less noisy probing to reduce chance of triggering security lockdowns.
*/
//virtual void PostInitProbes(bool quiet) =0;

/**
@brief Looks up the value for a named constant
This is mostly used by jtagsh for allowing registers to be poked in a more human-friendly fashion.
@param name Name of the constant
@param value Value (if found)
@return True if found, false if not found
TODO: consider refactoring this to a separate base class?
*/
/*
bool LookupConstant(std::string name, uint32_t& value)
{
if(m_constantMap.find(name) != m_constantMap.end())
{
value = m_constantMap[name];
return true;
}
else
return false;
}*/

public:

/**
@brief Returns the JEDEC ID code of this device
*/
/*uint32_t GetIdcode()
{ return m_idcode; }
void EnterShiftDR();
void ShiftData(const unsigned char* send_data, unsigned char* rcv_data, int count);
protected:
///Length of this device's instruction register, in bits
size_t m_irlength;
///32-bit JEDEC ID code of this device
uint32_t m_idcode;
///The JTAGInterface associated with this device
JtagInterface* m_iface;
///Position of this device in the interface's scan chain
size_t m_pos;
///Cached IR
unsigned char m_cachedIR[4];
///Map of constant names to values, used by jtagsh and other scripting support
std::map<std::string, uint32_t> m_constantMap;
*/
};

#endif
131 changes: 131 additions & 0 deletions SWDInterface.h
@@ -0,0 +1,131 @@
/***********************************************************************************************************************
* *
* ANTIKERNEL v0.1 *
* *
* Copyright (c) 2012-2018 Andrew D. Zonenberg *
* All rights reserved. *
* *
* Redistribution and use in source and binary forms, with or without modification, are permitted provided that the *
* following conditions are met: *
* *
* * Redistributions of source code must retain the above copyright notice, this list of conditions, and the *
* following disclaimer. *
* *
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the *
* following disclaimer in the documentation and/or other materials provided with the distribution. *
* *
* * Neither the name of the author nor the names of any contributors may be used to endorse or promote products *
* derived from this software without specific prior written permission. *
* *
* THIS SOFTWARE IS PROVIDED BY THE AUTHORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED *
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL *
* THE AUTHORS BE HELD LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES *
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR *
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT *
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE *
* POSSIBILITY OF SUCH DAMAGE. *
* *
***********************************************************************************************************************/

/**
@file
@author Andrew D. Zonenberg
@brief Declaration of SWDInterface
*/

#include "ARMDebugPort.h"

#ifndef SWDInterface_h
#define SWDInterface_h

/**
@brief Abstract representation of a SWD adapter.
A SWD adapter provides access to a single SW-DP (TODO: or SWJ-DP) on a single ARM SoC.
In order to support a new "dumb" SWD adapter without any higher level protocol offload, create a new derived class
and implement each of the following functions:
\li GetName()
\li GetSerial()
\li GetUserID()
\li GetFrequency()
*/
class SWDInterface : public ARMDebugPort
{
public:
SWDInterface();
virtual ~SWDInterface();

//GetInterfaceCount() is a strongly recommended static member function for each derived class

//Setup stuff
public:

/**
@brief Gets the manufacturer-assigned name for this programming adapter.
This is usually the model number but is sometimes something more generic like "Digilent Adept USB Device".
@return The device name
*/
virtual std::string GetName() =0;

/**
@brief Gets the manufacturer-assigned serial number for this programming adapter, if any.
Derived classes may choose to return the user ID, an empty string, or another default value if no serial number
has been assigned.
@return The serial number
*/
virtual std::string GetSerial() =0;

/**
@brief Gets the user-assigned name for this JTAG adapter, if any.
Derived classes may choose to return the serial number, an empty string, or another default value if no name
has been assigned.
@return The name for this adapter.
*/
virtual std::string GetUserID() =0;

/**
@brief Gets the clock frequency, in Hz, of the JTAG interface
@return The clock frequency
*/
virtual int GetFrequency() =0;

/**
@brief Performs a SW-DP write transaction
*/
virtual void WriteWord(uint8_t reg_addr, uint32_t wdata) =0;

/**
@brief Performs a SW-DP read transaction
*/
virtual uint32_t ReadWord(uint8_t reg_addr) =0;

public:

//Scanning stuff
public:

/**
@brief Connects to the interface and figures out what we have attached to us
*/
virtual void InitializeDevice();

//Device(s) found on the SWD interface
//For now: only support for one
protected:
SWDDevice* m_device;

public:
SWDDevice* GetDevice()
{ return m_device; }
};

#endif
2 changes: 2 additions & 0 deletions jtaghal.h
Expand Up @@ -101,6 +101,8 @@
#include "GPIOInterface.h"
#include "JtagDevice.h"
#include "JtagInterface.h"
#include "SWDDevice.h"
#include "SWDInterface.h"

//JTAG adapter drivers
#include "DigilentJtagInterface.h"
Expand Down

0 comments on commit dbcfeb1

Please sign in to comment.