~cosmos-door/ubuntu/quantal/avarice/fix-ftbfs-1058667

« back to all changes in this revision

Viewing changes to src/jtag2run.cc

  • Committer: Bazaar Package Importer
  • Author(s): Shaun Jackman
  • Date: 2008-01-21 12:42:25 UTC
  • mfrom: (3.1.2 hardy)
  • Revision ID: james.westby@ubuntu.com-20080121124225-jpgg64fki5b2clqs
Tags: 2.7-2
* Add the AVR Dragon to the udev rules. Closes: #461986.
* Update the Debian policy to version 3.7.3.

Show diffs side-by-side

added added

removed removed

Lines of Context:
2
2
 *      avarice - The "avarice" program.
3
3
 *      Copyright (C) 2001 Scott Finneran
4
4
 *      Copyright (C) 2002 Intel Corporation
5
 
 *      Copyright (C) 2005 Joerg Wunsch
 
5
 *      Copyright (C) 2005, 2007 Joerg Wunsch
6
6
 *
7
7
 *      This program is free software; you can redistribute it and/or modify
8
8
 *      it under the terms of the GNU General Public License Version 2
19
19
 *
20
20
 * This file implements target execution handling for the mkII protocol.
21
21
 *
22
 
 * $Id: jtag2run.cc,v 1.4 2005/11/17 18:34:25 idgay Exp $
 
22
 * $Id: jtag2run.cc,v 1.9 2007/10/29 23:31:05 joerg_wunsch Exp $
23
23
 */
24
24
 
25
25
 
 
26
#include <ctype.h>
26
27
#include <stdarg.h>
27
28
#include <stdio.h>
28
29
#include <stdlib.h>
74
75
 
75
76
bool jtag2::resetProgram(void)
76
77
{
77
 
    uchar cmd[2] = { CMND_RESET, 0x01 };
78
 
    uchar *resp;
79
 
    int respSize;
80
 
 
81
 
    bool rv = doJtagCommand(cmd, 2, resp, respSize);
82
 
    delete [] resp;
83
 
 
84
 
    return rv;
 
78
    if (useDebugWire) {
 
79
        /* The JTAG ICE mkII and Dragon do not respond correctly to
 
80
         * the CMND_RESET command while in debugWire mode. */
 
81
        return interruptProgram()
 
82
            && setProgramCounter(0);
 
83
    } else {
 
84
        uchar cmd[2] = { CMND_RESET, 0x01 };
 
85
        uchar *resp;
 
86
        int respSize;
 
87
 
 
88
        bool rv = doJtagCommand(cmd, 2, resp, respSize);
 
89
        delete [] resp;
 
90
 
 
91
        return rv;
 
92
    }
85
93
}
86
94
 
87
95
bool jtag2::interruptProgram(void)
129
137
    return rv;
130
138
}
131
139
 
 
140
void jtag2::parseEvents(const char *evtlist)
 
141
{
 
142
    memset(nonbreaking_events, 0, sizeof nonbreaking_events);
 
143
 
 
144
    const struct
 
145
    {
 
146
        uchar num;
 
147
        const char *name;
 
148
    } evttable[] =
 
149
        {
 
150
            { EVT_BREAK,                                "break" },
 
151
            { EVT_DEBUG,                                "debug" },
 
152
            { EVT_ERROR_PHY_FORCE_BREAK_TIMEOUT,        "error_phy_force_break_timeout" },
 
153
            { EVT_ERROR_PHY_MAX_BIT_LENGTH_DIFF,        "error_phy_max_bit_length_diff" },
 
154
            { EVT_ERROR_PHY_OPT_RECEIVE_TIMEOUT,        "error_phy_opt_receive_timeout" },
 
155
            { EVT_ERROR_PHY_OPT_RECEIVED_BREAK,         "error_phy_opt_received_break" },
 
156
            { EVT_ERROR_PHY_RECEIVED_BREAK,             "error_phy_received_break" },
 
157
            { EVT_ERROR_PHY_RECEIVE_TIMEOUT,            "error_phy_receive_timeout" },
 
158
            { EVT_ERROR_PHY_RELEASE_BREAK_TIMEOUT,      "error_phy_release_break_timeout" },
 
159
            { EVT_ERROR_PHY_SYNC_OUT_OF_RANGE,          "error_phy_sync_out_of_range" },
 
160
            { EVT_ERROR_PHY_SYNC_TIMEOUT,               "error_phy_sync_timeout" },
 
161
            { EVT_ERROR_PHY_SYNC_TIMEOUT_BAUD,          "error_phy_sync_timeout_baud" },
 
162
            { EVT_ERROR_PHY_SYNC_WAIT_TIMEOUT,          "error_phy_sync_wait_timeout" },
 
163
            { EVT_RESULT_PHY_NO_ACTIVITY,               "result_phy_no_activity" },
 
164
            { EVT_EXT_RESET,                            "ext_reset" },
 
165
            { EVT_ICE_POWER_ERROR_STATE,                "ice_power_error_state" },
 
166
            { EVT_ICE_POWER_OK,                         "ice_power_ok" },
 
167
            { EVT_IDR_DIRTY,                            "idr_dirty" },
 
168
            { EVT_NONE,                                 "none" },
 
169
            { EVT_PDSB_BREAK,                           "pdsb_break" },
 
170
            { EVT_PDSMB_BREAK,                          "pdsmb_break" },
 
171
            { EVT_PROGRAM_BREAK,                        "program_break" },
 
172
            { EVT_RUN,                                  "run" },
 
173
            { EVT_TARGET_POWER_OFF,                     "target_power_off" },
 
174
            { EVT_TARGET_POWER_ON,                      "target_power_on" },
 
175
            { EVT_TARGET_SLEEP,                         "target_sleep" },
 
176
            { EVT_TARGET_WAKEUP,                        "target_wakeup" },
 
177
        };
 
178
 
 
179
    // parse the given comma-separated string
 
180
    const char *cp1, *cp2;
 
181
    cp1 = evtlist;
 
182
    while (*cp1 != '\0')
 
183
    {
 
184
        while (isspace(*cp1) || *cp1 == ',')
 
185
            cp1++;
 
186
        cp2 = cp1;
 
187
        while (*cp2 != '\0' && *cp2 != ',')
 
188
            cp2++;
 
189
        size_t l = cp2 - cp1;
 
190
        uchar evtval = 0;
 
191
 
 
192
        // Now, cp1 points to the name to parse, of length l
 
193
        for (int i = 0; i < sizeof evttable / sizeof evttable[0]; i++)
 
194
        {
 
195
            if (strncmp(evttable[i].name, cp1, l) == 0)
 
196
            {
 
197
                evtval = evttable[i].num;
 
198
                break;
 
199
            }
 
200
        }
 
201
        if (evtval == 0)
 
202
        {
 
203
            fprintf(stderr, "Warning: event name %.*s not matched\n",
 
204
                    (int)l, cp1);
 
205
        }
 
206
        else
 
207
        {
 
208
            nonbreaking_events[evtval - EVT_BREAK] = true;
 
209
        }
 
210
 
 
211
        cp1 = cp2;
 
212
    }
 
213
}
 
214
 
132
215
bool jtag2::jtagContinue(void)
133
216
{
134
217
    updateBreakpoints(); // download new bp configuration
151
234
        // box or a nudge from GDB.
152
235
        debugOut("Waiting for input.\n");
153
236
 
 
237
        if (ctrlPipe != -1)
 
238
          {
 
239
            /* signal the USB daemon to start polling. */
 
240
            char cmd[1] = { 'p' };
 
241
            (void)write(ctrlPipe, cmd, 1);
 
242
          }
 
243
 
154
244
        // Check for input from JTAG ICE (breakpoint, sleep, info, power)
155
245
        // or gdb (user break)
156
246
        FD_ZERO (&readfds);
184
274
                // We really need a queue of received frames.
185
275
                if (seqno != 0xffff)
186
276
                    debugOut("Expected event packet, got other response");
187
 
                else if (evtbuf[8] == EVT_BREAK)
188
 
                    breakpoint = true;
189
 
                // Ignore other events.
 
277
                else if (!nonbreaking_events[evtbuf[8] - EVT_BREAK])
 
278
                {
 
279
                    if (evtbuf[8] == EVT_IDR_DIRTY)
 
280
                    {
 
281
                        // The program is still running at IDR dirty, so
 
282
                        // pretend a user break;
 
283
                        gdbInterrupt = true;
 
284
                        printf("\nIDR dirty: 0x%02x\n", evtbuf[9]);
 
285
                    }
 
286
                    else
 
287
                    {
 
288
                        breakpoint = true;
 
289
                    }
 
290
                }
190
291
                delete [] evtbuf;
191
292
            }
192
293
        }