versaloon driver update
[openocd.git] / src / jtag / drivers / versaloon / usbtoxxx / usbtoswd.c
1 /***************************************************************************
2 * Copyright (C) 2009 - 2010 by Simon Qian <SimonQian@SimonQian.com> *
3 * *
4 * This program is free software; you can redistribute it and/or modify *
5 * it under the terms of the GNU General Public License as published by *
6 * the Free Software Foundation; either version 2 of the License, or *
7 * (at your option) any later version. *
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 *
16 * Free Software Foundation, Inc., *
17 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
18 ***************************************************************************/
19 #ifdef HAVE_CONFIG_H
20 #include "config.h"
21 #endif
22
23 #include <stdlib.h>
24 #include <string.h>
25
26 #include "../versaloon_include.h"
27 #include "../versaloon.h"
28 #include "../versaloon_internal.h"
29 #include "usbtoxxx.h"
30 #include "usbtoxxx_internal.h"
31
32 RESULT usbtoswd_callback(void *p, uint8_t *src, uint8_t *processed)
33 {
34 struct versaloon_pending_t *pending = (struct versaloon_pending_t *)p;
35
36 processed = processed;
37
38 if (pending->extra_data != NULL)
39 {
40 *((uint8_t *)pending->extra_data) = src[0];
41 }
42
43 return ERROR_OK;
44 }
45
46 RESULT usbtoswd_init(uint8_t interface_index)
47 {
48 return usbtoxxx_init_command(USB_TO_SWD, interface_index);
49 }
50
51 RESULT usbtoswd_fini(uint8_t interface_index)
52 {
53 return usbtoxxx_fini_command(USB_TO_SWD, interface_index);
54 }
55
56 RESULT usbtoswd_config(uint8_t interface_index, uint8_t trn, uint16_t retry,
57 uint16_t dly)
58 {
59 uint8_t cfg_buf[5];
60
61 #if PARAM_CHECK
62 if (interface_index > 7)
63 {
64 LOG_BUG(ERRMSG_INVALID_INTERFACE_NUM, interface_index);
65 return ERROR_FAIL;
66 }
67 #endif
68
69 cfg_buf[0] = trn;
70 SET_LE_U16(&cfg_buf[1], retry);
71 SET_LE_U16(&cfg_buf[3], dly);
72
73 return usbtoxxx_conf_command(USB_TO_SWD, interface_index, cfg_buf, 5);
74 }
75
76 RESULT usbtoswd_seqout(uint8_t interface_index, uint8_t *data, uint16_t bitlen)
77 {
78 uint16_t bytelen = (bitlen + 7) >> 3;
79
80 #if PARAM_CHECK
81 if (interface_index > 7)
82 {
83 LOG_BUG(ERRMSG_INVALID_INTERFACE_NUM, interface_index);
84 return ERROR_FAIL;
85 }
86 #endif
87
88 SET_LE_U16(&versaloon_cmd_buf[0], bitlen);
89 memcpy(versaloon_cmd_buf + 2, data, bytelen);
90
91 return usbtoxxx_out_command(USB_TO_SWD, interface_index,
92 versaloon_cmd_buf, bytelen + 2, 0);
93 }
94
95 RESULT usbtoswd_seqin(uint8_t interface_index, uint8_t *data, uint16_t bitlen)
96 {
97 uint16_t bytelen = (bitlen + 7) >> 3;
98 uint8_t buff[2];
99
100 #if PARAM_CHECK
101 if (interface_index > 7)
102 {
103 LOG_BUG(ERRMSG_INVALID_INTERFACE_NUM, interface_index);
104 return ERROR_FAIL;
105 }
106 #endif
107
108 SET_LE_U16(&buff[0], bitlen);
109
110 return usbtoxxx_in_command(USB_TO_SWD, interface_index, buff, 2, bytelen,
111 data, 0, bytelen, 0);
112 }
113
114 RESULT usbtoswd_transact(uint8_t interface_index, uint8_t request,
115 uint32_t *data, uint8_t *ack)
116 {
117 uint8_t parity;
118 uint8_t buff[5];
119
120 #if PARAM_CHECK
121 if (interface_index > 7)
122 {
123 LOG_BUG(ERRMSG_INVALID_INTERFACE_NUM, interface_index);
124 return ERROR_FAIL;
125 }
126 #endif
127
128 parity = (request >> 1) & 1;
129 parity += (request >> 2) & 1;
130 parity += (request >> 3) & 1;
131 parity += (request >> 4) & 1;
132 parity &= 1;
133 buff[0] = (request | 0x81 | (parity << 5)) & ~0x40;
134 if (data != NULL)
135 {
136 SET_LE_U32(&buff[1], *data);
137 }
138 else
139 {
140 memset(buff + 1, 0, 4);
141 }
142
143 versaloon_set_extra_data(ack);
144 versaloon_set_callback(usbtoswd_callback);
145 if (request & 0x04)
146 {
147 // read
148 return usbtoxxx_inout_command(USB_TO_SWD, interface_index, buff, 5, 5,
149 (uint8_t *)data, 1, 4, 0);
150 }
151 else
152 {
153 // write
154 return usbtoxxx_inout_command(USB_TO_SWD, interface_index, buff, 5, 5,
155 NULL, 0, 0, 0);
156 }
157 }
158

Linking to existing account procedure

If you already have an account and want to add another login method you MUST first sign in with your existing account and then change URL to read https://review.openocd.org/login/?link to get to this page again but this time it'll work for linking. Thank you.

SSH host keys fingerprints

1024 SHA256:YKx8b7u5ZWdcbp7/4AeXNaqElP49m6QrwfXaqQGJAOk gerrit-code-review@openocd.zylin.com (DSA)
384 SHA256:jHIbSQa4REvwCFG4cq5LBlBLxmxSqelQPem/EXIrxjk gerrit-code-review@openocd.org (ECDSA)
521 SHA256:UAOPYkU9Fjtcao0Ul/Rrlnj/OsQvt+pgdYSZ4jOYdgs gerrit-code-review@openocd.org (ECDSA)
256 SHA256:A13M5QlnozFOvTllybRZH6vm7iSt0XLxbA48yfc2yfY gerrit-code-review@openocd.org (ECDSA)
256 SHA256:spYMBqEYoAOtK7yZBrcwE8ZpYt6b68Cfh9yEVetvbXg gerrit-code-review@openocd.org (ED25519)
+--[ED25519 256]--+
|=..              |
|+o..   .         |
|*.o   . .        |
|+B . . .         |
|Bo. = o S        |
|Oo.+ + =         |
|oB=.* = . o      |
| =+=.+   + E     |
|. .=o   . o      |
+----[SHA256]-----+
2048 SHA256:0Onrb7/PHjpo6iVZ7xQX2riKN83FJ3KGU0TvI0TaFG4 gerrit-code-review@openocd.zylin.com (RSA)