Debian Codegraph @

src/jtag1.h

raw symbols SCIP
1 /*
2 * avarice - The "avarice" program.
3 * Copyright (C) 2001 Scott Finneran
4 * Copyright (C) 2002, 2003, 2004 Intel Corporation
5 * Copyright (C) 2005, 2007 Joerg Wunsch
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License Version 2
9 * as published by the Free Software Foundation.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA.
19 *
20 * This file extends the generic "jtag" class for the mkI protocol.
21 *
22 * $Id: jtag1.h 322 2013-01-07 09:47:52Z joerg_wunsch $
23 */
24
25 #ifndef JTAG1_H
26 #define JTAG1_H
27
28 #include "jtag.h"
29
30 enum SendResult { send_failed, send_ok, mcu_data };
31
32 /*
33 There are apparently a total of three hardware breakpoints
34 (the docs claim four, but documents 2 breakpoints accessible via
35 non-existent parameters).
36
37 In summary, there is one code-only breakpoint, and 2 breakpoints which
38 can be:
39 - 2 code breakpoints
40 - 2 1-byte data breakpoints
41 - 1 code and 1-byte data breakpoint
42 - 1 ranged code breakpoint
43 - 1 ranged data breakpoint
44
45 Currently we're ignoring ranges, so we allow up to 3 breakpoints,
46 of which a maximum of 2 are data breakpoints. This is easily handled
47 by keeping each kind of breakpoint separate.
48
49 In the future, we could support "software" breakpoints too (though it
50 seems mildly painful)
51
52 See avrIceProtocol.txt for full details.
53 */
54
55 enum {
56 // We distinguish the total possible breakpoints and those for each type
57 // (code or data) - see above
58 MAX_BREAKPOINTS_CODE = 4,
59 MAX_BREAKPOINTS_DATA = 2,
60 MAX_BREAKPOINTS = 4
61 };
62
63 struct breakpoint
64 {
65 unsigned int address;
66 bpType type;
67 };
68
69 class jtag1: public jtag
70 {
71 /** Decode 3-byte big-endian address **/
72 unsigned long decodeAddress(uchar *buf) {
73 return buf[0] << 16 | buf[1] << 8 | buf[2];
74 };
75
76 /** Encode 3-byte big-endian address **/
77 void encodeAddress(uchar *buffer, unsigned long x) {
78 buffer[0] = x >> 16;
79 buffer[1] = x >> 8;
80 buffer[2] = x;
81 };
82
83 breakpoint bpCode[MAX_BREAKPOINTS_CODE], bpData[MAX_BREAKPOINTS_DATA];
84 int numBreakpointsCode, numBreakpointsData;
85
86 public:
87 jtag1(const char *dev, char *name, bool nsrst = false):
88 jtag(dev, name) {
89 apply_nSRST = nsrst;
90 };
91
92 virtual void initJtagBox(void);
93 virtual void initJtagOnChipDebugging(unsigned long bitrate);
94
95 virtual void deleteAllBreakpoints(void);
96 virtual bool deleteBreakpoint(unsigned int address, bpType type, unsigned int length);
97 virtual bool addBreakpoint(unsigned int address, bpType type, unsigned int length);
98 virtual void updateBreakpoints(void);
99 virtual bool codeBreakpointAt(unsigned int address);
100 virtual void parseEvents(const char *);
101
102 virtual void enableProgramming(void);
103 virtual void disableProgramming(void);
104 virtual void eraseProgramMemory(void);
105 virtual void eraseProgramPage(unsigned long address);
106 virtual void downloadToTarget(const char* filename, bool program, bool verify);
107
108 virtual unsigned long getProgramCounter(void);
109 virtual void setProgramCounter(unsigned long pc);
110 virtual void resetProgram(bool possible_nSRST);
111 virtual void interruptProgram(void);
112 virtual void resumeProgram(void);
113 virtual void jtagSingleStep(void);
114 virtual bool jtagContinue(void);
115
116 virtual uchar *jtagRead(unsigned long addr, unsigned int numBytes);
117 virtual void jtagWrite(unsigned long addr, unsigned int numBytes, uchar buffer[]);
118 virtual unsigned int statusAreaAddress(void) const {
119 /* no Xmega handling in JTAG ICE mkI */
120 return 0x5D + DATA_SPACE_ADDR_OFFSET;
121 };
122 virtual unsigned int cpuRegisterAreaAddress(void) const {
123 /* no Xmega handling in JTAG ICE mkI */
124 return DATA_SPACE_ADDR_OFFSET;
125 }
126
127 private:
128 virtual void changeBitRate(int newBitRate);
129 virtual void setDeviceDescriptor(jtag_device_def_type *dev);
130 virtual bool synchroniseAt(int bitrate);
131 virtual void startJtagLink(void);
132 virtual void deviceAutoConfig(void);
133 virtual void configDaisyChain(void);
134
135 uchar *getJtagResponse(int responseSize);
136 SendResult sendJtagCommand(uchar *command, int commandSize, int *tries);
137 bool checkForEmulator(void);
138
139 /** Send a command to the jtag, with retries, and return the 'responseSize'
140 byte response. Aborts avarice in case of to many failed retries.
141
142 Returns a dynamically allocated buffer containing the reponse (caller
143 must free)
144 **/
145 uchar *doJtagCommand(uchar *command, int commandSize, int responseSize);
146
147 /** Simplified form of doJtagCommand:
148 Send 1-byte command 'cmd' to JTAG ICE, with retries, expecting a
149 'responseSize' byte reponse.
150
151 Return true if responseSize is 0 or if last response byte is
152 JTAG_R_OK
153 **/
154 bool doSimpleJtagCommand(uchar cmd, int responseSize);
155
156 // Miscellaneous
157 // -------------
158
159 /** Set JTAG ICE parameter 'item' to 'newValue' **/
160 void setJtagParameter(uchar item, uchar newValue);
161
162 /** Return value of JTAG ICE parameter 'item' **/
163 uchar getJtagParameter(uchar item);
164
165 };
166
167 #endif