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