Debian Codegraph @

src/jtag2misc.cc

raw symbols SCIP
1 /*
2 * avarice - The "avarice" program.
3 * Copyright (C) 2005 Joerg Wunsch
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License Version 2
7 * as published by the Free Software Foundation.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA.
17 *
18 * This file contains miscellaneous routines for the mkII protocol.
19 *
20 * $Id: jtag2misc.cc 380 2020-08-31 21:01:26Z joerg_wunsch $
21 */
22
23
24 #include <stdarg.h>
25 #include <stdio.h>
26 #include <stdlib.h>
27 #include <unistd.h>
28 #include <sys/stat.h>
29 #include <termios.h>
30 #include <fcntl.h>
31 #include <string.h>
32
33 #include "avarice.h"
34 #include "jtag.h"
35 #include "jtag2.h"
36
37 void jtag2::setJtagParameter(uchar item, uchar *newValue, int valSize)
38 {
39 int respsize;
40 /*
41 * As the maximal parameter length is 4 bytes, we use a fixed-length
42 * buffer, as opposed to malloc()ing it.
43 */
44 unsigned char buf[2 + 4], *resp;
45
46 if (valSize > 4)
47 throw jtag_exception("Parameter too large in setJtagParameter");
48
49 buf[0] = CMND_SET_PARAMETER;
50 buf[1] = item;
51 memcpy(buf + 2, newValue, valSize);
52
53 try
54 {
55 doJtagCommand(buf, valSize + 2, resp, respsize);
56 }
57 catch (jtag_exception& e)
58 {
59 fprintf(stderr, "set parameter command failed: %s\n",
60 e.what());
61 throw;
62 }
63
64 delete [] resp;
65 }
66
67 /*
68 * Get a JTAG ICE parameter. Caller must delete [] the response. Note
69 * that the response still includes the response code at index 0 (to be
70 * ignored).
71 */
72 void jtag2::getJtagParameter(uchar item, uchar *&resp, int &respSize)
73 {
74 /*
75 * As the maximal parameter length is 4 bytes, we use a fixed-length
76 * buffer, as opposed to malloc()ing it.
77 */
78 unsigned char buf[2];
79
80 buf[0] = CMND_GET_PARAMETER;
81 buf[1] = item;
82
83 try
84 {
85 doJtagCommand(buf, 2, resp, respSize);
86 }
87 catch (jtag_exception& e)
88 {
89 fprintf(stderr, "get parameter command failed: %s\n",
90 e.what());
91 throw;
92 }
93 if (resp[0] != RSP_PARAMETER || respSize <= 1)
94 throw jtag_exception("unexpected response to get paremater command");
95 }
96
97