]>
Commit | Line | Data |
---|---|---|
a4210e18 EK |
1 | /* |
2 | * This file is part of the libsigrok project. | |
3 | * | |
4 | * Copyright (C) 2016 danselmi <da@da> | |
5 | * | |
6 | * This program is free software: you can redistribute it and/or modify | |
7 | * it under the terms of the GNU General Public License as published by | |
8 | * the Free Software Foundation, either version 3 of the License, or | |
9 | * (at your option) any later version. | |
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, see <http://www.gnu.org/licenses/>. | |
18 | */ | |
19 | ||
20 | #include <config.h> | |
21 | #ifdef _WIN32 | |
22 | #define _WIN32_WINNT 0x0501 | |
23 | #include <winsock2.h> | |
24 | #include <ws2tcpip.h> | |
25 | #endif | |
26 | //#include <glib.h> | |
27 | #include <string.h> | |
28 | #include <unistd.h> | |
29 | #ifndef _WIN32 | |
30 | #include <sys/socket.h> | |
31 | #include <netinet/in.h> | |
32 | #include <arpa/inet.h> | |
33 | #include <netdb.h> | |
34 | #endif | |
35 | #include <errno.h> | |
36 | #include "protocol.h" | |
37 | ||
38 | #define BUFFER_SIZE 4 | |
39 | ||
40 | ||
41 | #define Start 0xFE | |
2f15f5bf | 42 | #define reset 0xEE |
a4210e18 EK |
43 | #define IPDBG_LA_ID 0xBB |
44 | #define Escape 0x55 | |
45 | ||
46 | ||
47 | /* Command opcodes */ | |
48 | #define set_trigger 0x00 | |
2f15f5bf | 49 | |
a4210e18 EK |
50 | #define Trigger 0xF0 |
51 | #define LA 0x0F | |
2f15f5bf | 52 | |
a4210e18 EK |
53 | #define Masks 0xF1 |
54 | #define Mask 0xF3 | |
2f15f5bf | 55 | |
a4210e18 | 56 | #define Value 0xF7 |
2f15f5bf | 57 | |
a4210e18 EK |
58 | #define Last_Masks 0xF9 |
59 | #define Mask_last 0xFB | |
2f15f5bf | 60 | |
a4210e18 | 61 | #define Value_last 0xFF |
2f15f5bf | 62 | |
a66099c6 EK |
63 | #define Select_Edge_Mask 0xF5 |
64 | #define Set_Edge_Mask 0xF6 | |
65 | ||
a4210e18 EK |
66 | #define delay 0x1F |
67 | #define K_Mauslesen 0xAA | |
68 | ||
69 | ||
70 | SR_PRIV int sendEscaping(struct ipdbg_org_la_tcp *tcp, char *dataToSend, int length); | |
71 | ||
72 | SR_PRIV struct ipdbg_org_la_tcp *ipdbg_org_la_new_tcp(void) | |
73 | { | |
74 | struct ipdbg_org_la_tcp *tcp; | |
75 | ||
76 | tcp = g_malloc0(sizeof(struct ipdbg_org_la_tcp)); | |
77 | ||
78 | tcp->address = NULL; | |
79 | tcp->port = NULL; | |
80 | tcp->socket = -1; | |
81 | ||
82 | return tcp; | |
83 | } | |
84 | ||
85 | SR_PRIV int ipdbg_org_la_tcp_open(struct ipdbg_org_la_tcp *tcp) | |
86 | { | |
2f15f5bf EK |
87 | struct addrinfo hints; |
88 | struct addrinfo *results, *res; | |
89 | int err; | |
90 | ||
91 | memset(&hints, 0, sizeof(hints)); | |
92 | hints.ai_family = AF_UNSPEC; | |
93 | hints.ai_socktype = SOCK_STREAM; | |
94 | hints.ai_protocol = IPPROTO_TCP; | |
95 | ||
96 | err = getaddrinfo(tcp->address, tcp->port, &hints, &results); | |
97 | ||
98 | if (err) { | |
99 | sr_err("Address lookup failed: %s:%s: %s", tcp->address, tcp->port, | |
100 | gai_strerror(err)); | |
101 | return SR_ERR; | |
102 | } | |
103 | ||
104 | for (res = results; res; res = res->ai_next) { | |
105 | if ((tcp->socket = socket(res->ai_family, res->ai_socktype, | |
106 | res->ai_protocol)) < 0) | |
107 | continue; | |
108 | if (connect(tcp->socket, res->ai_addr, res->ai_addrlen) != 0) { | |
109 | close(tcp->socket); | |
110 | tcp->socket = -1; | |
111 | continue; | |
112 | } | |
113 | break; | |
114 | } | |
115 | ||
116 | freeaddrinfo(results); | |
117 | ||
118 | if (tcp->socket < 0) { | |
119 | sr_err("Failed to connect to %s:%s: %s", tcp->address, tcp->port, | |
120 | g_strerror(errno)); | |
121 | return SR_ERR; | |
122 | } | |
123 | ||
124 | return SR_OK; | |
a4210e18 EK |
125 | } |
126 | ||
127 | SR_PRIV int ipdbg_org_la_tcp_send(struct ipdbg_org_la_tcp *tcp, const uint8_t *buf, size_t len) | |
128 | { | |
2f15f5bf EK |
129 | int out; |
130 | out = send(tcp->socket, (char*)buf, len, 0); | |
a4210e18 | 131 | |
2f15f5bf EK |
132 | if (out < 0) { |
133 | sr_err("Send error: %s", g_strerror(errno)); | |
134 | return SR_ERR; | |
135 | } | |
a4210e18 | 136 | |
2f15f5bf EK |
137 | if ((unsigned int)out < len) { |
138 | sr_dbg("Only sent %d/%d bytes of data.", out, (int)len); | |
139 | } | |
a4210e18 | 140 | |
2f15f5bf | 141 | return SR_OK; |
a4210e18 EK |
142 | } |
143 | ||
144 | SR_PRIV int ipdbg_org_la_tcp_receive(struct ipdbg_org_la_tcp *tcp, uint8_t *buf, int bufsize) | |
145 | { | |
146 | int received = 0; | |
147 | ||
148 | while(received < bufsize) | |
149 | { | |
a4210e18 EK |
150 | int len; |
151 | ||
d37c6daa | 152 | len = recv(tcp->socket, (char*)(buf+received), bufsize-received, 0); |
a4210e18 EK |
153 | |
154 | if (len < 0) { | |
155 | sr_err("Receive error: %s", g_strerror(errno)); | |
156 | return SR_ERR; | |
157 | } | |
158 | else | |
159 | { | |
160 | received += len; | |
161 | } | |
162 | } | |
163 | ||
2f15f5bf | 164 | return received; |
a4210e18 EK |
165 | } |
166 | ||
167 | SR_PRIV int ipdbg_org_la_tcp_close(struct ipdbg_org_la_tcp *tcp) | |
168 | { | |
169 | int ret = SR_ERR; | |
2f15f5bf | 170 | if (close(tcp->socket) >= 0) |
a4210e18 EK |
171 | ret = SR_OK; |
172 | ||
173 | tcp->socket = -1; | |
174 | ||
175 | return ret; | |
176 | } | |
177 | ||
178 | SR_PRIV void ipdbg_org_la_tcp_free(struct ipdbg_org_la_tcp *tcp) | |
179 | { | |
2f15f5bf EK |
180 | g_free(tcp->address); |
181 | g_free(tcp->port); | |
a4210e18 EK |
182 | } |
183 | ||
184 | SR_PRIV int ipdbg_org_la_convert_trigger(const struct sr_dev_inst *sdi) | |
185 | { | |
186 | struct ipdbg_org_la_dev_context *devc; | |
187 | struct sr_trigger *trigger; | |
188 | struct sr_trigger_stage *stage; | |
189 | struct sr_trigger_match *match; | |
190 | const GSList *l, *m; | |
191 | ||
192 | devc = sdi->priv; | |
193 | ||
194 | devc->num_stages = 0; | |
195 | devc->num_transfers = 0; | |
196 | devc->raw_sample_buf = NULL; /// name convert_trigger to init acquisition... | |
b8fa29a1 | 197 | for (unsigned int i = 0; i < devc->DATA_WIDTH_BYTES; i++) |
a4210e18 EK |
198 | { |
199 | devc->trigger_mask[i] = 0; | |
200 | devc->trigger_value[i] = 0; | |
201 | devc->trigger_mask_last[i] = 0; | |
202 | devc->trigger_value_last[i] = 0; | |
a66099c6 | 203 | devc->trigger_edge_mask[i] = 0; |
a4210e18 | 204 | } |
a4210e18 | 205 | |
b8fa29a1 | 206 | if (!(trigger = sr_session_trigger_get(sdi->session))) |
a4210e18 EK |
207 | { |
208 | return SR_OK; | |
209 | } | |
210 | ||
a4210e18 EK |
211 | for (l = trigger->stages; l; l = l->next) |
212 | { | |
213 | stage = l->data; | |
214 | for (m = stage->matches; m; m = m->next) | |
215 | { | |
216 | match = m->data; | |
217 | unsigned int byteIndex = (match->channel->index) /8; | |
218 | unsigned char matchPattern = 1 << (match->channel->index - 8* byteIndex); | |
a4210e18 EK |
219 | |
220 | if (!match->channel->enabled) | |
221 | /* Ignore disabled channels with a trigger. */ | |
222 | continue; | |
223 | if (match->match == SR_TRIGGER_ONE ) | |
224 | { | |
225 | devc->trigger_value[byteIndex] |= matchPattern; | |
226 | devc->trigger_mask[byteIndex] |= matchPattern; | |
227 | devc->trigger_mask_last[byteIndex] &= ~matchPattern; | |
a66099c6 | 228 | devc->trigger_edge_mask[byteIndex] &= ~matchPattern; |
a4210e18 EK |
229 | //sr_err("\n========ONE MASK==========="); |
230 | ||
231 | } | |
232 | else if (match->match == SR_TRIGGER_ZERO) | |
233 | { | |
234 | devc->trigger_value[byteIndex] &= ~matchPattern; | |
235 | devc->trigger_mask[byteIndex] |= matchPattern; | |
236 | devc->trigger_mask_last[byteIndex] &= ~matchPattern; | |
a66099c6 | 237 | devc->trigger_edge_mask[byteIndex] &= ~matchPattern; |
a4210e18 EK |
238 | //sr_err("\n========ZERO MASK==========="); |
239 | } | |
240 | else if ( match->match == SR_TRIGGER_RISING) | |
241 | { | |
242 | devc->trigger_value[byteIndex] |= matchPattern; | |
243 | devc->trigger_value_last[byteIndex] &= ~matchPattern; | |
244 | devc->trigger_mask[byteIndex] |= matchPattern; | |
245 | devc->trigger_mask_last[byteIndex] |= matchPattern; | |
a66099c6 | 246 | devc->trigger_edge_mask[byteIndex] &= ~matchPattern; |
a4210e18 EK |
247 | //sr_err("\n==========RISING==========="); |
248 | ||
249 | } | |
250 | else if (match->match == SR_TRIGGER_FALLING ) | |
251 | { | |
252 | devc->trigger_value[byteIndex] &= ~matchPattern; | |
253 | devc->trigger_value_last[byteIndex] |= matchPattern; | |
254 | devc->trigger_mask[byteIndex] |= matchPattern; | |
255 | devc->trigger_mask_last[byteIndex] |= matchPattern; | |
a66099c6 | 256 | devc->trigger_edge_mask[byteIndex] &= ~matchPattern; |
a4210e18 EK |
257 | //sr_err("\n========FALlING==========="); |
258 | } | |
a66099c6 EK |
259 | else if (match->match == SR_TRIGGER_EDGE) |
260 | { | |
261 | devc->trigger_mask[byteIndex] &= ~matchPattern; | |
262 | devc->trigger_mask_last[byteIndex] &= ~matchPattern; | |
263 | devc->trigger_edge_mask[byteIndex] |= matchPattern; | |
264 | } | |
a4210e18 EK |
265 | |
266 | } | |
267 | ||
268 | } | |
269 | ||
a4210e18 EK |
270 | return SR_OK; |
271 | } | |
272 | ||
273 | SR_PRIV int ipdbg_org_la_receive_data(int fd, int revents, void *cb_data) | |
274 | { | |
a4210e18 EK |
275 | |
276 | ||
277 | const struct sr_dev_inst *sdi; | |
278 | struct ipdbg_org_la_dev_context *devc; | |
279 | ||
280 | ||
281 | ||
282 | (void)fd; | |
2f15f5bf | 283 | (void)revents; |
a4210e18 EK |
284 | |
285 | sdi = (const struct sr_dev_inst *)cb_data; | |
286 | if (!sdi) | |
287 | { | |
288 | return FALSE; | |
289 | } | |
a4210e18 EK |
290 | |
291 | if (!(devc = sdi->priv)) | |
292 | { | |
293 | return FALSE; | |
294 | ||
295 | } | |
a4210e18 EK |
296 | |
297 | ||
298 | struct ipdbg_org_la_tcp *tcp = sdi->conn; | |
299 | struct sr_datafeed_packet packet; | |
300 | struct sr_datafeed_logic logic; | |
301 | ||
302 | ||
a4210e18 EK |
303 | if (!devc->raw_sample_buf) |
304 | { | |
a4210e18 | 305 | devc->raw_sample_buf = g_try_malloc(devc->limit_samples*devc->DATA_WIDTH_BYTES); |
a4210e18 EK |
306 | if (!devc->raw_sample_buf) { |
307 | sr_warn("Sample buffer malloc failed."); | |
308 | return FALSE; | |
309 | } | |
310 | ||
311 | } | |
312 | ||
313 | ||
314 | if (devc->num_transfers < devc->limit_samples_max*devc->DATA_WIDTH_BYTES) | |
315 | { | |
a4210e18 EK |
316 | unsigned char byte; |
317 | ||
a4210e18 EK |
318 | if (ipdbg_org_la_tcp_receive(tcp, &byte, 1) == 1) |
319 | { | |
320 | if(devc->num_transfers < devc->limit_samples*devc->DATA_WIDTH_BYTES) | |
321 | devc->raw_sample_buf[devc->num_transfers] = byte; | |
b8fa29a1 | 322 | |
a4210e18 EK |
323 | devc->num_transfers++; |
324 | } | |
325 | ||
326 | } | |
327 | else | |
328 | { | |
a4210e18 EK |
329 | |
330 | if (devc->delay_value > 0) { | |
331 | /* There are pre-trigger samples, send those first. */ | |
332 | packet.type = SR_DF_LOGIC; | |
333 | packet.payload = &logic; | |
334 | //logic.length = devc->delay_value-1; | |
335 | logic.length = devc->delay_value*devc->DATA_WIDTH_BYTES; | |
336 | logic.unitsize = devc->DATA_WIDTH_BYTES; | |
337 | logic.data = devc->raw_sample_buf; | |
338 | sr_session_send(cb_data, &packet); | |
339 | } | |
340 | ||
341 | /* Send the trigger. */ | |
342 | packet.type = SR_DF_TRIGGER; | |
343 | sr_session_send(cb_data, &packet); | |
344 | ||
345 | /* Send post-trigger samples. */ | |
346 | packet.type = SR_DF_LOGIC; | |
347 | packet.payload = &logic; | |
348 | //logic.length = devc->limit_samples - devc->delay_value+1; | |
349 | logic.length = (devc->limit_samples - devc->delay_value)*devc->DATA_WIDTH_BYTES; | |
350 | logic.unitsize = devc->DATA_WIDTH_BYTES; | |
351 | logic.data = devc->raw_sample_buf + devc->delay_value*devc->DATA_WIDTH_BYTES; | |
352 | //logic.data = devc->raw_sample_buf + devc->delay_value-1; | |
353 | sr_session_send(cb_data, &packet); | |
354 | ||
355 | g_free(devc->raw_sample_buf); | |
356 | devc->raw_sample_buf = NULL; | |
357 | ||
358 | //serial_flush(serial); | |
b8fa29a1 | 359 | ipdbg_org_la_abort_acquisition(sdi); |
a4210e18 EK |
360 | } |
361 | ||
362 | return TRUE; | |
363 | } | |
364 | ||
365 | SR_PRIV int ipdbg_org_la_sendDelay(struct ipdbg_org_la_dev_context *devc, struct ipdbg_org_la_tcp *tcp) | |
366 | { | |
a4210e18 EK |
367 | |
368 | int maxSample; | |
369 | ||
2f15f5bf | 370 | maxSample = devc->limit_samples; |
a4210e18 EK |
371 | |
372 | devc->delay_value = (maxSample/100.0) * devc->capture_ratio; | |
373 | uint8_t Befehl[1]; | |
374 | Befehl[0] = LA; | |
375 | ipdbg_org_la_tcp_send(tcp, Befehl, 1); | |
376 | Befehl[0] = delay; | |
377 | ipdbg_org_la_tcp_send(tcp, Befehl, 1); | |
378 | ||
379 | //sr_warn("delay 2"); | |
380 | ||
381 | ||
382 | char buf[4] = { devc->delay_value & 0x000000ff, | |
383 | (devc->delay_value >> 8) & 0x000000ff, | |
384 | (devc->delay_value >> 16) & 0x000000ff, | |
385 | (devc->delay_value >> 24) & 0x000000ff}; | |
386 | ||
2f15f5bf EK |
387 | for(size_t i = 0 ; i < devc->ADDR_WIDTH_BYTES ; ++i) |
388 | sendEscaping(tcp, &(buf[devc->ADDR_WIDTH_BYTES-1-i]), 1); | |
a4210e18 EK |
389 | |
390 | return SR_OK; | |
391 | } | |
392 | ||
393 | SR_PRIV int ipdbg_org_la_sendTrigger(struct ipdbg_org_la_dev_context *devc, struct ipdbg_org_la_tcp *tcp) | |
394 | { | |
395 | /////////////////////////////////////////////Mask//////////////////////////////////////////////////////////// | |
396 | uint8_t buf[1]; | |
397 | buf[0] = Trigger; | |
398 | ipdbg_org_la_tcp_send(tcp, buf, 1); | |
399 | buf[0] = Masks; | |
400 | ipdbg_org_la_tcp_send(tcp, buf, 1); | |
401 | buf[0] = Mask; | |
402 | ipdbg_org_la_tcp_send(tcp, buf, 1); | |
403 | ||
2f15f5bf EK |
404 | for(size_t k = 0 ; k < devc->DATA_WIDTH_BYTES ; ++k) |
405 | sendEscaping(tcp, devc->trigger_mask + devc->DATA_WIDTH_BYTES -1-k, 1); | |
a4210e18 EK |
406 | |
407 | ||
408 | /////////////////////////////////////////////Value//////////////////////////////////////////////////////////// | |
409 | buf[0]= Trigger; | |
410 | ipdbg_org_la_tcp_send(tcp, buf, 1); | |
411 | buf[0] = Masks; | |
412 | ipdbg_org_la_tcp_send(tcp, buf, 1); | |
413 | buf[0] = Value; | |
414 | ipdbg_org_la_tcp_send(tcp, buf, 1); | |
415 | ||
416 | ||
2f15f5bf EK |
417 | for(size_t k = 0 ; k < devc->DATA_WIDTH_BYTES ; ++k) |
418 | sendEscaping(tcp, devc->trigger_value + devc->DATA_WIDTH_BYTES -1-k, 1); | |
a4210e18 | 419 | |
b8fa29a1 | 420 | |
a4210e18 EK |
421 | /////////////////////////////////////////////Mask_last//////////////////////////////////////////////////////////// |
422 | buf[0] = Trigger; | |
423 | ipdbg_org_la_tcp_send(tcp, buf, 1); | |
424 | buf[0] = Last_Masks; | |
425 | ipdbg_org_la_tcp_send(tcp, buf, 1); | |
426 | buf[0] = Mask_last; | |
427 | ipdbg_org_la_tcp_send(tcp, buf, 1); | |
428 | ||
429 | ||
2f15f5bf EK |
430 | for(size_t k = 0 ; k < devc->DATA_WIDTH_BYTES ; ++k) |
431 | sendEscaping(tcp, devc->trigger_mask_last + devc->DATA_WIDTH_BYTES -1-k, 1); | |
a4210e18 EK |
432 | |
433 | ||
434 | /////////////////////////////////////////////Value_last//////////////////////////////////////////////////////////// | |
435 | buf[0] = Trigger; | |
436 | ipdbg_org_la_tcp_send(tcp, buf, 1); | |
437 | buf[0]= Last_Masks; | |
438 | ipdbg_org_la_tcp_send(tcp, buf, 1); | |
439 | buf[0]= Value_last; | |
440 | ipdbg_org_la_tcp_send(tcp, buf, 1); | |
441 | ||
442 | ||
2f15f5bf EK |
443 | for(size_t k = 0 ; k < devc->DATA_WIDTH_BYTES ; ++k) |
444 | sendEscaping(tcp, devc->trigger_value_last + devc->DATA_WIDTH_BYTES -1-k, 1); | |
a4210e18 | 445 | |
a66099c6 EK |
446 | /////////////////////////////////////////////edge_mask//////////////////////////////////////////////////////////// |
447 | buf[0] = Trigger; | |
448 | ipdbg_org_la_tcp_send(tcp, buf, 1); | |
449 | buf[0] = Select_Edge_Mask; | |
450 | ipdbg_org_la_tcp_send(tcp, buf, 1); | |
451 | buf[0] = Set_Edge_Mask; | |
452 | ipdbg_org_la_tcp_send(tcp, buf, 1); | |
453 | ||
454 | for(size_t k = 0 ; k < devc->DATA_WIDTH_BYTES ; ++k) | |
455 | sendEscaping(tcp, devc->trigger_edge_mask + devc->DATA_WIDTH_BYTES -1-k, 1); | |
456 | ||
457 | ||
b8fa29a1 | 458 | |
a4210e18 EK |
459 | return SR_OK; |
460 | } | |
461 | ||
462 | SR_PRIV int sendEscaping(struct ipdbg_org_la_tcp *tcp, char *dataToSend, int length) | |
463 | { | |
a4210e18 EK |
464 | while(length--) |
465 | { | |
466 | uint8_t payload = *dataToSend++; | |
a4210e18 EK |
467 | |
468 | if ( payload == (uint8_t)reset ) | |
469 | { | |
470 | uint8_t escapeSymbol = Escape; | |
471 | sr_warn("Escape"); | |
472 | ||
473 | if(ipdbg_org_la_tcp_send(tcp, &escapeSymbol, 1) != SR_OK) | |
474 | sr_warn("can't send escape"); | |
475 | ||
476 | ||
477 | } | |
478 | ||
479 | if ( payload == (char)Escape ) | |
480 | { | |
481 | uint8_t escapeSymbol = Escape; | |
482 | sr_warn("Escape"); | |
483 | ||
484 | if(ipdbg_org_la_tcp_send(tcp, &escapeSymbol, 1) != SR_OK) | |
485 | sr_warn("can't send escape"); | |
486 | } | |
487 | ||
488 | if (ipdbg_org_la_tcp_send(tcp, &payload, 1) != SR_OK) | |
489 | { | |
490 | sr_warn("Can't send data"); | |
491 | } | |
a4210e18 EK |
492 | |
493 | } | |
494 | return SR_OK; | |
495 | } | |
496 | ||
497 | SR_PRIV void ipdbg_org_la_get_addrwidth_and_datawidth(struct ipdbg_org_la_tcp *tcp, struct ipdbg_org_la_dev_context *devc) | |
498 | { | |
a4210e18 EK |
499 | uint8_t buf[8]; |
500 | uint8_t auslesen[1]; | |
501 | auslesen[0]= K_Mauslesen; | |
502 | ||
503 | if(ipdbg_org_la_tcp_send(tcp, auslesen, 1) != SR_OK) | |
504 | sr_warn("Can't send K_Mauslesen"); | |
a4210e18 EK |
505 | |
506 | ||
507 | /// delay | |
508 | if(ipdbg_org_la_tcp_receive(tcp, buf, 8) != 8) | |
509 | sr_warn("getAddrAndDataWidth failed"); | |
510 | ||
a4210e18 EK |
511 | devc->DATA_WIDTH = buf[0] & 0x000000FF; |
512 | devc->DATA_WIDTH |= (buf[1] << 8) & 0x0000FF00; | |
513 | devc->DATA_WIDTH |= (buf[2] << 16) & 0x00FF0000; | |
514 | devc->DATA_WIDTH |= (buf[3] << 24) & 0xFF000000; | |
515 | ||
516 | devc->ADDR_WIDTH = buf[4] & 0x000000FF; | |
517 | devc->ADDR_WIDTH |= (buf[5] << 8) & 0x0000FF00; | |
518 | devc->ADDR_WIDTH |= (buf[6] << 16) & 0x00FF0000; | |
519 | devc->ADDR_WIDTH |= (buf[7] << 24) & 0xFF000000; | |
520 | ||
521 | ||
a4210e18 EK |
522 | int HOST_WORD_SIZE = 8; // bits/ word |
523 | ||
524 | devc->DATA_WIDTH_BYTES = (devc->DATA_WIDTH+HOST_WORD_SIZE -1)/HOST_WORD_SIZE; | |
525 | devc->ADDR_WIDTH_BYTES = (devc->ADDR_WIDTH+HOST_WORD_SIZE -1)/HOST_WORD_SIZE; | |
526 | devc->limit_samples_max = (0x01 << devc->ADDR_WIDTH); | |
b8fa29a1 | 527 | devc->limit_samples = devc->limit_samples_max; |
a4210e18 EK |
528 | |
529 | ||
530 | ||
531 | devc->trigger_mask = g_malloc0(devc->DATA_WIDTH_BYTES); | |
532 | devc->trigger_value = g_malloc0(devc->DATA_WIDTH_BYTES); | |
533 | devc->trigger_mask_last = g_malloc0(devc->DATA_WIDTH_BYTES); | |
534 | devc->trigger_value_last = g_malloc0(devc->DATA_WIDTH_BYTES); | |
a66099c6 | 535 | devc->trigger_edge_mask = g_malloc0(devc->DATA_WIDTH_BYTES); |
a4210e18 EK |
536 | |
537 | ||
538 | } | |
539 | ||
540 | SR_PRIV struct ipdbg_org_la_dev_context *ipdbg_org_la_dev_new(void) | |
541 | { | |
542 | struct ipdbg_org_la_dev_context *devc; | |
543 | ||
544 | devc = g_malloc0(sizeof(struct ipdbg_org_la_dev_context)); | |
545 | ||
546 | ||
547 | devc->capture_ratio = 50; | |
548 | ///devc->num_bytes = 0; | |
549 | ||
550 | return devc; | |
551 | } | |
552 | ||
553 | SR_PRIV int ipdbg_org_la_sendReset(struct ipdbg_org_la_tcp *tcp) | |
554 | { | |
555 | uint8_t buf[1]; | |
556 | buf[0]= reset; | |
557 | if(ipdbg_org_la_tcp_send(tcp, buf, 1) != SR_OK) | |
558 | sr_warn("Reset can't send"); | |
559 | return SR_OK; | |
560 | } | |
561 | ||
562 | SR_PRIV int ipdbg_org_la_requestID(struct ipdbg_org_la_tcp *tcp) | |
563 | { | |
564 | uint8_t buf[1]; | |
565 | buf[0]= IPDBG_LA_ID; | |
566 | if(ipdbg_org_la_tcp_send(tcp, buf, 1) != SR_OK) | |
567 | sr_warn("IDBG can't send"); | |
568 | ||
569 | char ID[4]; | |
570 | if(ipdbg_org_la_tcp_receive(tcp, (uint8_t*)ID, 4) != 4) | |
571 | { | |
572 | sr_warn("IDBG can't read"); | |
573 | } | |
574 | ||
575 | ||
576 | if (strncmp(ID, "IDBG", 4)) { | |
577 | sr_err("Invalid reply (expected 'IDBG' '%c%c%c%c').", ID[0], ID[1], ID[2], ID[3]); | |
578 | return SR_ERR; | |
579 | } | |
580 | ||
581 | return SR_OK; | |
582 | } | |
583 | ||
584 | SR_PRIV void ipdbg_org_la_abort_acquisition(const struct sr_dev_inst *sdi) | |
585 | { | |
a4210e18 EK |
586 | |
587 | struct ipdbg_org_la_tcp *tcp = sdi->conn; | |
588 | ||
2f15f5bf | 589 | sr_session_source_remove(sdi->session, tcp->socket); |
a4210e18 | 590 | |
b8fa29a1 | 591 | std_session_send_df_end(sdi); |
a4210e18 EK |
592 | } |
593 | ||
594 | SR_PRIV int ipdbg_org_la_sendStart(struct ipdbg_org_la_tcp *tcp) | |
595 | { | |
596 | uint8_t buf[1]; | |
597 | buf[0] = Start; | |
598 | ||
599 | if(ipdbg_org_la_tcp_send(tcp, buf, 1) != SR_OK) | |
600 | sr_warn("Reset can't send"); | |
601 | return SR_OK; | |
602 | } | |
603 |