jtag: linuxgpiod: drop extra parenthesis
[openocd.git] / src / target / ls1_sap.c
1 /***************************************************************************
2 * Copyright (C) 2015 by Esben Haabendal *
3 * eha@deif.com *
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 as published by *
7 * the Free Software Foundation; either version 2 of the License, or *
8 * (at your option) any later version. *
9 * *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
14 ***************************************************************************/
15
16 #ifdef HAVE_CONFIG_H
17 #include "config.h"
18 #endif
19
20 #include "target.h"
21 #include "target_type.h"
22
23 #include <jtag/jtag.h>
24
25 struct ls1_sap {
26 struct jtag_tap *tap;
27 };
28
29 static int ls1_sap_target_create(struct target *target, Jim_Interp *interp)
30 {
31 struct ls1_sap *ls1_sap = calloc(1, sizeof(struct ls1_sap));
32
33 ls1_sap->tap = target->tap;
34 target->arch_info = ls1_sap;
35
36 return ERROR_OK;
37 }
38
39 static int ls1_sap_init_target(struct command_context *cmd_ctx, struct target *target)
40 {
41 LOG_DEBUG("%s", __func__);
42 return ERROR_OK;
43 }
44
45 static int ls1_sap_arch_state(struct target *target)
46 {
47 LOG_DEBUG("%s", __func__);
48 return ERROR_OK;
49 }
50
51 static int ls1_sap_poll(struct target *target)
52 {
53 if ((target->state == TARGET_UNKNOWN) ||
54 (target->state == TARGET_RUNNING) ||
55 (target->state == TARGET_DEBUG_RUNNING))
56 target->state = TARGET_HALTED;
57
58 return ERROR_OK;
59 }
60
61 static int ls1_sap_halt(struct target *target)
62 {
63 LOG_DEBUG("%s", __func__);
64 return ERROR_OK;
65 }
66
67 static int ls1_sap_resume(struct target *target, int current, target_addr_t address,
68 int handle_breakpoints, int debug_execution)
69 {
70 LOG_DEBUG("%s", __func__);
71 return ERROR_OK;
72 }
73
74 static int ls1_sap_step(struct target *target, int current, target_addr_t address,
75 int handle_breakpoints)
76 {
77 LOG_DEBUG("%s", __func__);
78 return ERROR_OK;
79 }
80
81 static int ls1_sap_assert_reset(struct target *target)
82 {
83 target->state = TARGET_RESET;
84
85 LOG_DEBUG("%s", __func__);
86 return ERROR_OK;
87 }
88
89 static int ls1_sap_deassert_reset(struct target *target)
90 {
91 target->state = TARGET_RUNNING;
92
93 LOG_DEBUG("%s", __func__);
94 return ERROR_OK;
95 }
96
97 static void ls1_sap_set_instr(struct jtag_tap *tap, uint32_t new_instr)
98 {
99 struct scan_field field;
100
101 if (buf_get_u32(tap->cur_instr, 0, tap->ir_length) == new_instr)
102 return;
103
104 field.num_bits = tap->ir_length;
105 uint8_t *t = calloc(DIV_ROUND_UP(field.num_bits, 8), 1);
106 field.out_value = t;
107 buf_set_u32(t, 0, field.num_bits, new_instr);
108 field.in_value = NULL;
109 jtag_add_ir_scan(tap, &field, TAP_IDLE);
110 free(t);
111 }
112
113 static void ls1_sap_set_addr_high(struct jtag_tap *tap, uint16_t addr_high)
114 {
115 struct scan_field field;
116 uint8_t buf[2] = { 0 };
117
118 ls1_sap_set_instr(tap, 0x21);
119
120 field.num_bits = 16;
121 field.out_value = buf;
122 buf_set_u32(buf, 0, 16, addr_high);
123 field.in_value = NULL;
124 field.check_value = NULL;
125 field.check_mask = NULL;
126 jtag_add_dr_scan(tap, 1, &field, TAP_IDLE);
127 }
128
129 static void ls1_sap_memory_cmd(struct jtag_tap *tap, uint32_t address,
130 int32_t size, bool rnw)
131 {
132 struct scan_field field;
133 uint8_t cmd[8] = { 0 };
134
135 ls1_sap_set_instr(tap, 0x24);
136
137 field.num_bits = 64;
138 field.out_value = cmd;
139 buf_set_u64(cmd, 0, 9, 0);
140 buf_set_u64(cmd, 9, 3, size);
141 buf_set_u64(cmd, 12, 1, rnw);
142 buf_set_u64(cmd, 13, 3, 0);
143 buf_set_u64(cmd, 16, 32, address);
144 buf_set_u64(cmd, 48, 16, 0);
145 field.in_value = NULL;
146 field.check_value = NULL;
147 field.check_mask = NULL;
148 jtag_add_dr_scan(tap, 1, &field, TAP_IDLE);
149 }
150
151 static void ls1_sap_memory_read(struct jtag_tap *tap, uint32_t size,
152 uint8_t *value)
153 {
154 struct scan_field field;
155
156 ls1_sap_set_instr(tap, 0x25);
157
158 field.num_bits = 8 * size;
159 field.out_value = NULL;
160 field.in_value = value;
161 field.check_value = NULL;
162 field.check_mask = NULL;
163 jtag_add_dr_scan(tap, 1, &field, TAP_IDLE);
164 }
165
166 static void ls1_sap_memory_write(struct jtag_tap *tap, uint32_t size,
167 const uint8_t *value)
168 {
169 struct scan_field field;
170
171 ls1_sap_set_instr(tap, 0x25);
172
173 field.num_bits = 8 * size;
174 field.out_value = value;
175 field.in_value = NULL;
176 field.check_value = NULL;
177 field.check_mask = NULL;
178 jtag_add_dr_scan(tap, 1, &field, TAP_IDLE);
179 }
180
181 static int ls1_sap_read_memory(struct target *target, target_addr_t address,
182 uint32_t size, uint32_t count, uint8_t *buffer)
183 {
184 LOG_DEBUG("Reading memory at physical address 0x%" TARGET_PRIxADDR
185 "; size %" PRIu32 "; count %" PRIu32, address, size, count);
186
187 if (count == 0 || buffer == NULL)
188 return ERROR_COMMAND_SYNTAX_ERROR;
189
190 ls1_sap_set_addr_high(target->tap, 0);
191
192 while (count--) {
193 ls1_sap_memory_cmd(target->tap, address, size, true);
194 ls1_sap_memory_read(target->tap, size, buffer);
195 address += size;
196 buffer += size;
197 }
198
199 return jtag_execute_queue();
200 }
201
202 static int ls1_sap_write_memory(struct target *target, target_addr_t address,
203 uint32_t size, uint32_t count,
204 const uint8_t *buffer)
205 {
206 LOG_DEBUG("Writing memory at physical address 0x%" TARGET_PRIxADDR
207 "; size %" PRIu32 "; count %" PRIu32, address, size, count);
208
209
210 if (count == 0 || buffer == NULL)
211 return ERROR_COMMAND_SYNTAX_ERROR;
212
213 ls1_sap_set_addr_high(target->tap, 0);
214
215 while (count--) {
216 ls1_sap_memory_cmd(target->tap, address, size, false);
217 ls1_sap_memory_write(target->tap, size, buffer);
218 address += size;
219 buffer += size;
220 }
221
222 return jtag_execute_queue();
223 }
224
225 struct target_type ls1_sap_target = {
226 .name = "ls1_sap",
227
228 .target_create = ls1_sap_target_create,
229 .init_target = ls1_sap_init_target,
230
231 .poll = ls1_sap_poll,
232 .arch_state = ls1_sap_arch_state,
233
234 .halt = ls1_sap_halt,
235 .resume = ls1_sap_resume,
236 .step = ls1_sap_step,
237
238 .assert_reset = ls1_sap_assert_reset,
239 .deassert_reset = ls1_sap_deassert_reset,
240
241 .read_memory = ls1_sap_read_memory,
242 .write_memory = ls1_sap_write_memory,
243 };

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)