mbed code for Farrari board

Dependencies:   DDRO_Farrari mbed

Fork of DDRO_Farrari by Liangzhen Lai

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers jtag.h Source File

jtag.h

00001 /*
00002 This is the JTAG driver file for mbed master
00003 Refer to buspriate + openOCD
00004 */
00005 
00006 // Addresses
00007 #define DHCSR_ADDR 0xE000EDF0
00008 #define DCRSR_ADDR 0xE000EDF4
00009 #define DCRDR_ADDR 0xE000EDF8
00010 #define DEMCR_ADDR 0xE000EDFC
00011 
00012 #define DHCSR_DBGKEY 0xA05F0000
00013 #define DHCSR_S_RESET_ST 0x2000000
00014 #define DHCSR_S_RETIRE_ST 0x1000000
00015 #define DHCSR_S_LOCKUP 0x80000
00016 #define DHCSR_S_SLEEP 0x40000
00017 #define DHCSR_S_HALT 0x20000
00018 #define DHCSR_S_REGRDY 0x10000
00019 #define DHCSR_C_SNAPSTALL 0x20
00020 #define DHCSR_C_MASKINTS 0x8
00021 #define DHCSR_C_STEP 0x4
00022 #define DHCSR_C_HALT 0x2
00023 #define DHCSR_C_DEBUGEN 0x1
00024 
00025 #define DCRSR_REGWnR 0x10000
00026 #define DCRSR_xPSR 0x10
00027 #define DCRSR_MSP  0x11
00028 #define DCRSR_PSP  0x12
00029 #define DCRSR_CONTROL  0x14
00030 
00031 #define DEMCR_TRCENA 0x1000000
00032 #define DEMCR_MON_REQ 0x80000
00033 #define DEMCR_MON_STEP 0x40000
00034 #define DEMCR_MON_PEND 0x20000
00035 #define DEMCR_MON_EN 0x10000
00036 #define DEMCR_VC_HARDERR 0x400
00037 #define DEMCR_VC_INTERR 0x200
00038 #define DEMCR_VC_BUSERR 0x100
00039 #define DEMCR_VC_STATERR 0x80
00040 #define DEMCR_VC_CHKERR 0x40
00041 #define DEMCR_VC_NOCPERR 0x20
00042 #define DEMCR_VC_MMERR 0x10
00043 #define DEMCR_VC_CORERESET 0x1
00044 
00045 
00046 
00047 #define AP 1
00048 #define DP 0
00049 
00050 #define READ 1
00051 #define WRITE 0
00052 
00053 #define DP_CTRLSTAT 0x4
00054 #define DP_SELECT 0x8
00055 #define DP_RDBUFF 0xC
00056 
00057 #define AP_CSW 0x0
00058 #define AP_TAR 0x4
00059 #define AP_SELECT 0x8
00060 #define AP_DRW 0xC
00061 #define AP_BD0 0x10
00062 #define AP_BD1 0x14
00063 #define AP_BD2 0x18
00064 #define AP_BD3 0x1C
00065 #define AP_CFG 0xF4
00066 #define AP_BASE 0xF8
00067 #define AP_IDR 0xFC
00068 
00069 #define JTAG_ABORT 0x8
00070 #define JTAG_DPACC 0xA
00071 #define JTAG_APACC 0xB
00072 #define JTAG_IDCODE 0xE
00073 #define JTAG_BYPASS 0xF
00074 
00075 
00076 #define SW_DP_ACK_OK 1
00077 #define SW_DP_ACK_WAIT 2
00078 #define SW_DP_ACK_FAULT 4
00079 
00080 #ifndef JTAG_H
00081 #define JTAG_H
00082 
00083 class JTAG
00084 {
00085 public:
00086 
00087 // Memory
00088     unsigned int memRead(unsigned int baseaddr, unsigned int readdata[], int size, bool check=false, bool print=false);
00089     void memWrite(unsigned int baseaddr, unsigned int writedata[], int size, bool zero=false);
00090     unsigned int readMemory(unsigned int address);
00091     void writeMemory(unsigned int address, unsigned int value);
00092     int loadProgram();
00093 
00094 // ------------------------------------------------
00095 // DP/AP Config
00096     unsigned int rdBuff(bool set_ir);
00097     unsigned int readDPACC(unsigned char addr, bool set_ir=true, bool rdthis=true);
00098     unsigned int readAPACC(unsigned char addr, bool set_ir=true, bool rdthis=true);
00099     void writeAPACC(unsigned int data, unsigned char addr, bool set_ir=true);
00100     void writeDPACC(unsigned int data, unsigned char addr, bool set_ir=true);
00101     void writeBanksel(unsigned int banksel, bool set_ir=true);
00102     void DAP_enable(void);
00103     void PowerupDAP();
00104 
00105 // --------------------------------
00106 // State Manipulation
00107     void setIR(unsigned char A);
00108     void setState(unsigned char c);
00109     void leaveState(void);
00110     void reset(void);
00111     unsigned int readID(void);
00112 
00113 // --------------------------------------------
00114 // Data Shifting
00115     unsigned int shiftBits(unsigned int data, int n);
00116     unsigned int shiftData(unsigned int data, char addr, bool rw);
00117 
00118 // ----------------------------------
00119 // Toggle Functions
00120     void DataLow(void);
00121     void DataHigh(void);
00122     void clockLow(void);
00123     void clockHigh(void);
00124     void clockTicks(unsigned char c);
00125     void TMSHigh(void);
00126     void TMSLow(void);
00127 
00128 // --------------------------------
00129 // Initializing and Config
00130     JTAG();
00131     void setJTAGspeed(int speed);
00132 
00133 
00134 
00135     char state; // n=null, r=reset, d=data, i=instruction
00136     int delay; // wait time for each signal switching, in us
00137 };
00138 
00139 #endif