]>
Commit | Line | Data |
---|---|---|
a1bb33af UH |
1 | /* |
2 | * This file is part of the sigrok project. | |
3 | * | |
4 | * Copyright (C) 2010 Bert Vermeulen <bert@biot.com> | |
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 | ||
22b02383 | 20 | #include "config.h" |
a1bb33af UH |
21 | #include <stdio.h> |
22 | #include <stdlib.h> | |
23 | #include <sys/time.h> | |
24 | #include <inttypes.h> | |
25 | #include <glib.h> | |
26 | #include <libusb.h> | |
fed16f06 | 27 | #include <sigrok.h> |
4cea9eb2 | 28 | #include <sigrok-internal.h> |
a1bb33af UH |
29 | #include "analyzer.h" |
30 | ||
fed16f06 UH |
31 | #define USB_VENDOR 0x0c12 |
32 | #define USB_VENDOR_NAME "Zeroplus" | |
a1bb33af UH |
33 | #define USB_MODEL_NAME "Logic Cube" |
34 | #define USB_MODEL_VERSION "" | |
35 | ||
36 | #define USB_INTERFACE 0 | |
37 | #define USB_CONFIGURATION 1 | |
38 | #define NUM_TRIGGER_STAGES 4 | |
39 | #define TRIGGER_TYPES "01" | |
40 | ||
fed16f06 | 41 | #define PACKET_SIZE 2048 /* ?? */ |
a1bb33af UH |
42 | |
43 | typedef struct { | |
44 | unsigned short pid; | |
45 | char model_name[64]; | |
46 | unsigned int channels; | |
fed16f06 | 47 | unsigned int sample_depth; /* In Ksamples/channel */ |
a1bb33af UH |
48 | unsigned int max_sampling_freq; |
49 | } model_t; | |
50 | ||
fed16f06 UH |
51 | /* |
52 | * Note -- 16032, 16064 and 16128 *usually* -- but not always -- have the | |
53 | * same 128K sample depth. | |
54 | */ | |
29cbfeaf | 55 | static model_t zeroplus_models[] = { |
a1bb33af UH |
56 | {0x7009, "LAP-C(16064)", 16, 64, 100}, |
57 | {0x700A, "LAP-C(16128)", 16, 128, 200}, | |
58 | {0x700B, "LAP-C(32128)", 32, 128, 200}, | |
59 | {0x700C, "LAP-C(321000)", 32, 1024, 200}, | |
60 | {0x700D, "LAP-C(322000)", 32, 2048, 200}, | |
61 | {0x700E, "LAP-C(16032)", 16, 32, 100}, | |
62 | {0x7016, "LAP-C(162000)", 16, 2048, 200}, | |
63 | }; | |
64 | ||
65 | static int capabilities[] = { | |
5a2326a7 UH |
66 | SR_HWCAP_LOGIC_ANALYZER, |
67 | SR_HWCAP_SAMPLERATE, | |
68 | SR_HWCAP_PROBECONFIG, | |
69 | SR_HWCAP_CAPTURE_RATIO, | |
a1bb33af | 70 | |
fed16f06 | 71 | /* These are really implemented in the driver, not the hardware. */ |
5a2326a7 | 72 | SR_HWCAP_LIMIT_SAMPLES, |
fed16f06 | 73 | 0, |
a1bb33af UH |
74 | }; |
75 | ||
a00ba012 | 76 | /* List of struct sr_device_instance, maintained by opendev()/closedev(). */ |
a1bb33af UH |
77 | static GSList *device_instances = NULL; |
78 | ||
79 | static libusb_context *usb_context = NULL; | |
80 | ||
fed16f06 UH |
81 | /* |
82 | * The hardware supports more samplerates than these, but these are the | |
83 | * options hardcoded into the vendor's Windows GUI. | |
84 | */ | |
a1bb33af | 85 | |
fed16f06 UH |
86 | /* |
87 | * TODO: We shouldn't support 150MHz and 200MHz on devices that don't go up | |
88 | * that high. | |
89 | */ | |
a1bb33af | 90 | static uint64_t supported_samplerates[] = { |
c9140419 UH |
91 | SR_HZ(100), |
92 | SR_HZ(500), | |
59df0c77 UH |
93 | SR_KHZ(1), |
94 | SR_KHZ(5), | |
95 | SR_KHZ(25), | |
96 | SR_KHZ(50), | |
97 | SR_KHZ(100), | |
98 | SR_KHZ(200), | |
99 | SR_KHZ(400), | |
100 | SR_KHZ(800), | |
101 | SR_MHZ(1), | |
102 | SR_MHZ(10), | |
103 | SR_MHZ(25), | |
104 | SR_MHZ(50), | |
105 | SR_MHZ(80), | |
106 | SR_MHZ(100), | |
107 | SR_MHZ(150), | |
108 | SR_MHZ(200), | |
fed16f06 | 109 | 0, |
a1bb33af UH |
110 | }; |
111 | ||
60679b18 | 112 | static struct sr_samplerates samplerates = { |
c9140419 UH |
113 | SR_HZ(0), |
114 | SR_HZ(0), | |
115 | SR_HZ(0), | |
fed16f06 | 116 | supported_samplerates, |
a1bb33af UH |
117 | }; |
118 | ||
fed16f06 | 119 | /* TODO: All of these should go in a device-specific struct. */ |
a1bb33af UH |
120 | static uint64_t cur_samplerate = 0; |
121 | static uint64_t limit_samples = 0; | |
29cbfeaf UH |
122 | static int num_channels = 32; /* TODO: This isn't initialized before it's needed :( */ |
123 | static uint64_t memory_size = 0; | |
86c5e279 | 124 | static uint8_t probe_mask = 0; |
fed16f06 UH |
125 | static uint8_t trigger_mask[NUM_TRIGGER_STAGES] = { 0 }; |
126 | static uint8_t trigger_value[NUM_TRIGGER_STAGES] = { 0 }; | |
a1bb33af | 127 | |
fed16f06 | 128 | // static uint8_t trigger_buffer[NUM_TRIGGER_STAGES] = { 0 }; |
a1bb33af UH |
129 | |
130 | static int hw_set_configuration(int device_index, int capability, void *value); | |
131 | ||
132 | static unsigned int get_memory_size(int type) | |
133 | { | |
fed16f06 UH |
134 | if (type == MEMORY_SIZE_8K) |
135 | return 8 * 1024; | |
136 | else if (type == MEMORY_SIZE_64K) | |
137 | return 64 * 1024; | |
138 | else if (type == MEMORY_SIZE_128K) | |
139 | return 128 * 1024; | |
140 | else if (type == MEMORY_SIZE_512K) | |
141 | return 512 * 1024; | |
142 | else | |
143 | return 0; | |
a1bb33af UH |
144 | } |
145 | ||
a00ba012 | 146 | static int opendev4(struct sr_device_instance **sdi, libusb_device *dev, |
408e7199 UH |
147 | struct libusb_device_descriptor *des) |
148 | { | |
9a498834 UH |
149 | unsigned int i; |
150 | int err; | |
408e7199 UH |
151 | |
152 | if ((err = libusb_get_device_descriptor(dev, des))) { | |
153 | g_warning("failed to get device descriptor: %d", err); | |
154 | return -1; | |
155 | } | |
156 | ||
9a498834 | 157 | if (des->idVendor != USB_VENDOR) |
408e7199 UH |
158 | return 0; |
159 | ||
160 | if (libusb_get_bus_number(dev) == (*sdi)->usb->bus | |
161 | && libusb_get_device_address(dev) == (*sdi)->usb->address) { | |
162 | ||
9a498834 UH |
163 | for (i = 0; i < ARRAY_SIZE(zeroplus_models); i++) { |
164 | if (!(des->idProduct == zeroplus_models[i].pid)) | |
408e7199 UH |
165 | continue; |
166 | ||
9a498834 UH |
167 | g_message("Found PID=%04X (%s)", des->idProduct, |
168 | zeroplus_models[i].model_name); | |
169 | num_channels = zeroplus_models[i].channels; | |
170 | memory_size = zeroplus_models[i].sample_depth * 1024; | |
408e7199 UH |
171 | break; |
172 | } | |
173 | ||
174 | if (num_channels == 0) { | |
175 | g_warning("Unknown ZeroPlus device %04X", | |
9a498834 | 176 | des->idProduct); |
408e7199 UH |
177 | return -2; |
178 | } | |
179 | ||
180 | /* Found it. */ | |
181 | if (!(err = libusb_open(dev, &((*sdi)->usb->devhdl)))) { | |
5a2326a7 | 182 | (*sdi)->status = SR_ST_ACTIVE; |
408e7199 UH |
183 | g_message("opened device %d on %d.%d interface %d", |
184 | (*sdi)->index, (*sdi)->usb->bus, | |
185 | (*sdi)->usb->address, USB_INTERFACE); | |
186 | } else { | |
187 | g_warning("failed to open device: %d", err); | |
188 | *sdi = NULL; | |
189 | } | |
190 | } | |
191 | ||
192 | return 0; | |
193 | } | |
194 | ||
29cbfeaf | 195 | static struct sr_device_instance *zp_open_device(int device_index) |
a1bb33af | 196 | { |
a00ba012 | 197 | struct sr_device_instance *sdi; |
a1bb33af UH |
198 | libusb_device **devlist; |
199 | struct libusb_device_descriptor des; | |
afc8e4de | 200 | int err, i; |
a1bb33af | 201 | |
d32d961d | 202 | if (!(sdi = sr_get_device_instance(device_instances, device_index))) |
a1bb33af UH |
203 | return NULL; |
204 | ||
205 | libusb_get_device_list(usb_context, &devlist); | |
5a2326a7 | 206 | if (sdi->status == SR_ST_INACTIVE) { |
fed16f06 | 207 | /* Find the device by vendor, product, bus and address. */ |
a1bb33af | 208 | libusb_get_device_list(usb_context, &devlist); |
fed16f06 | 209 | for (i = 0; devlist[i]; i++) { |
408e7199 | 210 | /* TODO: Error handling. */ |
9a5c6dcf | 211 | err = opendev4(&sdi, devlist[i], &des); |
a1bb33af | 212 | } |
fed16f06 | 213 | } else { |
5a2326a7 | 214 | /* Status must be SR_ST_ACTIVE, i.e. already in use... */ |
a1bb33af UH |
215 | sdi = NULL; |
216 | } | |
217 | libusb_free_device_list(devlist, 1); | |
218 | ||
5a2326a7 | 219 | if (sdi && sdi->status != SR_ST_ACTIVE) |
a1bb33af UH |
220 | sdi = NULL; |
221 | ||
222 | return sdi; | |
223 | } | |
224 | ||
a00ba012 | 225 | static void close_device(struct sr_device_instance *sdi) |
a1bb33af | 226 | { |
408e7199 UH |
227 | if (!sdi->usb->devhdl) |
228 | return; | |
229 | ||
230 | g_message("closing device %d on %d.%d interface %d", sdi->index, | |
231 | sdi->usb->bus, sdi->usb->address, USB_INTERFACE); | |
232 | libusb_release_interface(sdi->usb->devhdl, USB_INTERFACE); | |
233 | libusb_close(sdi->usb->devhdl); | |
234 | sdi->usb->devhdl = NULL; | |
5a2326a7 | 235 | sdi->status = SR_ST_INACTIVE; |
a1bb33af UH |
236 | } |
237 | ||
a1bb33af UH |
238 | static int configure_probes(GSList *probes) |
239 | { | |
1afe8989 | 240 | struct sr_probe *probe; |
a1bb33af UH |
241 | GSList *l; |
242 | int probe_bit, stage, i; | |
243 | char *tc; | |
244 | ||
245 | probe_mask = 0; | |
fed16f06 | 246 | for (i = 0; i < NUM_TRIGGER_STAGES; i++) { |
a1bb33af UH |
247 | trigger_mask[i] = 0; |
248 | trigger_value[i] = 0; | |
249 | } | |
250 | ||
251 | stage = -1; | |
fed16f06 | 252 | for (l = probes; l; l = l->next) { |
1afe8989 | 253 | probe = (struct sr_probe *)l->data; |
fed16f06 | 254 | if (probe->enabled == FALSE) |
a1bb33af UH |
255 | continue; |
256 | probe_bit = 1 << (probe->index - 1); | |
257 | probe_mask |= probe_bit; | |
fed16f06 UH |
258 | |
259 | if (probe->trigger) { | |
a1bb33af | 260 | stage = 0; |
fed16f06 | 261 | for (tc = probe->trigger; *tc; tc++) { |
a1bb33af | 262 | trigger_mask[stage] |= probe_bit; |
fed16f06 | 263 | if (*tc == '1') |
a1bb33af UH |
264 | trigger_value[stage] |= probe_bit; |
265 | stage++; | |
fed16f06 | 266 | if (stage > NUM_TRIGGER_STAGES) |
e46b8fb1 | 267 | return SR_ERR; |
a1bb33af UH |
268 | } |
269 | } | |
270 | } | |
271 | ||
e46b8fb1 | 272 | return SR_OK; |
a1bb33af UH |
273 | } |
274 | ||
a1bb33af UH |
275 | /* |
276 | * API callbacks | |
277 | */ | |
278 | ||
54ac5277 | 279 | static int hw_init(const char *deviceinfo) |
a1bb33af | 280 | { |
a00ba012 | 281 | struct sr_device_instance *sdi; |
a1bb33af UH |
282 | struct libusb_device_descriptor des; |
283 | libusb_device **devlist; | |
284 | int err, devcnt, i; | |
285 | ||
17e1afcb | 286 | /* Avoid compiler warnings. */ |
afc8e4de UH |
287 | deviceinfo = deviceinfo; |
288 | ||
fed16f06 | 289 | if (libusb_init(&usb_context) != 0) { |
a1bb33af UH |
290 | g_warning("Failed to initialize USB."); |
291 | return 0; | |
292 | } | |
293 | ||
fed16f06 | 294 | /* Find all ZeroPlus analyzers and add them to device list. */ |
a1bb33af UH |
295 | devcnt = 0; |
296 | libusb_get_device_list(usb_context, &devlist); | |
fed16f06 UH |
297 | |
298 | for (i = 0; devlist[i]; i++) { | |
a1bb33af | 299 | err = libusb_get_device_descriptor(devlist[i], &des); |
fed16f06 | 300 | if (err != 0) { |
a1bb33af UH |
301 | g_warning("failed to get device descriptor: %d", err); |
302 | continue; | |
303 | } | |
304 | ||
fed16f06 UH |
305 | if (des.idVendor == USB_VENDOR) { |
306 | /* | |
307 | * Definitely a Zeroplus. | |
308 | * TODO: Any way to detect specific model/version in | |
309 | * the zeroplus range? | |
310 | */ | |
a00ba012 | 311 | sdi = sr_device_instance_new(devcnt, |
5a2326a7 | 312 | SR_ST_INACTIVE, USB_VENDOR_NAME, |
fed16f06 UH |
313 | USB_MODEL_NAME, USB_MODEL_VERSION); |
314 | if (!sdi) | |
a1bb33af | 315 | return 0; |
fed16f06 UH |
316 | device_instances = |
317 | g_slist_append(device_instances, sdi); | |
6c290072 | 318 | sdi->usb = sr_usb_device_instance_new( |
fed16f06 UH |
319 | libusb_get_bus_number(devlist[i]), |
320 | libusb_get_device_address(devlist[i]), NULL); | |
a1bb33af UH |
321 | devcnt++; |
322 | } | |
323 | } | |
324 | libusb_free_device_list(devlist, 1); | |
325 | ||
326 | return devcnt; | |
327 | } | |
328 | ||
a1bb33af UH |
329 | static int hw_opendev(int device_index) |
330 | { | |
a00ba012 | 331 | struct sr_device_instance *sdi; |
a1bb33af UH |
332 | int err; |
333 | ||
fed16f06 | 334 | if (!(sdi = zp_open_device(device_index))) { |
a1bb33af | 335 | g_warning("unable to open device"); |
e46b8fb1 | 336 | return SR_ERR; |
a1bb33af UH |
337 | } |
338 | ||
339 | err = libusb_claim_interface(sdi->usb->devhdl, USB_INTERFACE); | |
fed16f06 | 340 | if (err != 0) { |
a1bb33af | 341 | g_warning("Unable to claim interface: %d", err); |
e46b8fb1 | 342 | return SR_ERR; |
a1bb33af UH |
343 | } |
344 | analyzer_reset(sdi->usb->devhdl); | |
345 | analyzer_initialize(sdi->usb->devhdl); | |
a1bb33af UH |
346 | |
347 | analyzer_set_memory_size(MEMORY_SIZE_512K); | |
fed16f06 | 348 | // analyzer_set_freq(g_freq, g_freq_scale); |
a1bb33af | 349 | analyzer_set_trigger_count(1); |
408e7199 UH |
350 | // analyzer_set_ramsize_trigger_address((((100 - g_pre_trigger) |
351 | // * get_memory_size(g_memory_size)) / 100) >> 2); | |
fed16f06 UH |
352 | analyzer_set_ramsize_trigger_address( |
353 | (100 * get_memory_size(MEMORY_SIZE_512K) / 100) >> 2); | |
a1bb33af | 354 | |
fed16f06 UH |
355 | #if 0 |
356 | if (g_double_mode == 1) | |
a1bb33af UH |
357 | analyzer_set_compression(COMPRESSION_DOUBLE); |
358 | else if (g_compression == 1) | |
359 | analyzer_set_compression(COMPRESSION_ENABLE); | |
fed16f06 UH |
360 | else |
361 | #endif | |
362 | analyzer_set_compression(COMPRESSION_NONE); | |
a1bb33af | 363 | |
fed16f06 | 364 | if (cur_samplerate == 0) { |
408e7199 | 365 | /* Samplerate hasn't been set. Default to the slowest one. */ |
5a2326a7 | 366 | if (hw_set_configuration(device_index, SR_HWCAP_SAMPLERATE, |
e46b8fb1 UH |
367 | &samplerates.low) == SR_ERR) |
368 | return SR_ERR; | |
a1bb33af UH |
369 | } |
370 | ||
e46b8fb1 | 371 | return SR_OK; |
a1bb33af UH |
372 | } |
373 | ||
a1bb33af UH |
374 | static void hw_closedev(int device_index) |
375 | { | |
a00ba012 | 376 | struct sr_device_instance *sdi; |
a1bb33af | 377 | |
d32d961d | 378 | if ((sdi = sr_get_device_instance(device_instances, device_index))) |
a1bb33af | 379 | close_device(sdi); |
a1bb33af UH |
380 | } |
381 | ||
a1bb33af UH |
382 | static void hw_cleanup(void) |
383 | { | |
384 | GSList *l; | |
385 | ||
408e7199 | 386 | /* Properly close all devices... */ |
fed16f06 | 387 | for (l = device_instances; l; l = l->next) |
a00ba012 | 388 | close_device((struct sr_device_instance *)l->data); |
a1bb33af | 389 | |
408e7199 | 390 | /* ...and free all their memory. */ |
fed16f06 | 391 | for (l = device_instances; l; l = l->next) |
a1bb33af UH |
392 | g_free(l->data); |
393 | g_slist_free(device_instances); | |
394 | device_instances = NULL; | |
395 | ||
fed16f06 | 396 | if (usb_context) |
a1bb33af UH |
397 | libusb_exit(usb_context); |
398 | usb_context = NULL; | |
a1bb33af UH |
399 | } |
400 | ||
a1bb33af UH |
401 | static void *hw_get_device_info(int device_index, int device_info_id) |
402 | { | |
a00ba012 | 403 | struct sr_device_instance *sdi; |
408e7199 | 404 | void *info = NULL; |
a1bb33af | 405 | |
d32d961d | 406 | if (!(sdi = sr_get_device_instance(device_instances, device_index))) |
a1bb33af UH |
407 | return NULL; |
408 | ||
fed16f06 | 409 | switch (device_info_id) { |
5a2326a7 | 410 | case SR_DI_INSTANCE: |
a1bb33af UH |
411 | info = sdi; |
412 | break; | |
5a2326a7 | 413 | case SR_DI_NUM_PROBES: |
a1bb33af UH |
414 | info = GINT_TO_POINTER(num_channels); |
415 | break; | |
5a2326a7 | 416 | case SR_DI_SAMPLERATES: |
a1bb33af UH |
417 | info = &samplerates; |
418 | break; | |
5a2326a7 | 419 | case SR_DI_TRIGGER_TYPES: |
a1bb33af UH |
420 | info = TRIGGER_TYPES; |
421 | break; | |
5a2326a7 | 422 | case SR_DI_CUR_SAMPLERATE: |
a1bb33af UH |
423 | info = &cur_samplerate; |
424 | break; | |
425 | } | |
426 | ||
427 | return info; | |
428 | } | |
429 | ||
a1bb33af UH |
430 | static int hw_get_status(int device_index) |
431 | { | |
a00ba012 | 432 | struct sr_device_instance *sdi; |
a1bb33af | 433 | |
d32d961d | 434 | sdi = sr_get_device_instance(device_instances, device_index); |
fed16f06 | 435 | if (sdi) |
a1bb33af UH |
436 | return sdi->status; |
437 | else | |
5a2326a7 | 438 | return SR_ST_NOT_FOUND; |
a1bb33af UH |
439 | } |
440 | ||
a1bb33af UH |
441 | static int *hw_get_capabilities(void) |
442 | { | |
a1bb33af UH |
443 | return capabilities; |
444 | } | |
445 | ||
fed16f06 | 446 | /* TODO: This will set the same samplerate for all devices. */ |
afc8e4de | 447 | static int set_configuration_samplerate(uint64_t samplerate) |
a1bb33af | 448 | { |
5e2ddeb0 | 449 | g_message("%s(%" PRIu64 ")", __FUNCTION__, samplerate); |
59df0c77 UH |
450 | if (samplerate > SR_MHZ(1)) |
451 | analyzer_set_freq(samplerate / SR_MHZ(1), FREQ_SCALE_MHZ); | |
452 | else if (samplerate > SR_KHZ(1)) | |
453 | analyzer_set_freq(samplerate / SR_KHZ(1), FREQ_SCALE_KHZ); | |
a1bb33af | 454 | else |
fed16f06 | 455 | analyzer_set_freq(samplerate, FREQ_SCALE_HZ); |
a1bb33af UH |
456 | |
457 | cur_samplerate = samplerate; | |
458 | ||
e46b8fb1 | 459 | return SR_OK; |
a1bb33af UH |
460 | } |
461 | ||
462 | static int hw_set_configuration(int device_index, int capability, void *value) | |
463 | { | |
a00ba012 | 464 | struct sr_device_instance *sdi; |
a1bb33af UH |
465 | uint64_t *tmp_u64; |
466 | ||
d32d961d | 467 | if (!(sdi = sr_get_device_instance(device_instances, device_index))) |
e46b8fb1 | 468 | return SR_ERR; |
a1bb33af UH |
469 | |
470 | switch (capability) { | |
5a2326a7 | 471 | case SR_HWCAP_SAMPLERATE: |
fed16f06 UH |
472 | tmp_u64 = value; |
473 | return set_configuration_samplerate(*tmp_u64); | |
5a2326a7 | 474 | case SR_HWCAP_PROBECONFIG: |
fed16f06 | 475 | return configure_probes((GSList *) value); |
5a2326a7 | 476 | case SR_HWCAP_LIMIT_SAMPLES: |
2458ea65 BV |
477 | tmp_u64 = value; |
478 | limit_samples = *tmp_u64; | |
e46b8fb1 | 479 | return SR_OK; |
fed16f06 | 480 | default: |
e46b8fb1 | 481 | return SR_ERR; |
a1bb33af UH |
482 | } |
483 | } | |
484 | ||
485 | static int hw_start_acquisition(int device_index, gpointer session_device_id) | |
486 | { | |
a00ba012 | 487 | struct sr_device_instance *sdi; |
b9c735a2 UH |
488 | struct sr_datafeed_packet packet; |
489 | struct sr_datafeed_header header; | |
a1bb33af | 490 | int res; |
afc8e4de | 491 | unsigned int packet_num; |
a1bb33af UH |
492 | unsigned char *buf; |
493 | ||
d32d961d | 494 | if (!(sdi = sr_get_device_instance(device_instances, device_index))) |
e46b8fb1 | 495 | return SR_ERR; |
a1bb33af | 496 | |
a143e4e5 BV |
497 | /* push configured settings to device */ |
498 | analyzer_configure(sdi->usb->devhdl); | |
499 | ||
a1bb33af UH |
500 | analyzer_start(sdi->usb->devhdl); |
501 | g_message("Waiting for data"); | |
502 | analyzer_wait_data(sdi->usb->devhdl); | |
503 | ||
fed16f06 UH |
504 | g_message("Stop address = 0x%x", |
505 | analyzer_get_stop_address(sdi->usb->devhdl)); | |
506 | g_message("Now address = 0x%x", | |
507 | analyzer_get_now_address(sdi->usb->devhdl)); | |
508 | g_message("Trigger address = 0x%x", | |
509 | analyzer_get_trigger_address(sdi->usb->devhdl)); | |
a1bb33af | 510 | |
5a2326a7 | 511 | packet.type = SR_DF_HEADER; |
b9c735a2 | 512 | packet.length = sizeof(struct sr_datafeed_header); |
fed16f06 | 513 | packet.payload = (unsigned char *)&header; |
a1bb33af UH |
514 | header.feed_version = 1; |
515 | gettimeofday(&header.starttime, NULL); | |
4c100f32 | 516 | header.samplerate = cur_samplerate; |
5a2326a7 | 517 | header.protocol_id = SR_PROTO_RAW; |
c2616fb9 DR |
518 | header.num_logic_probes = num_channels; |
519 | header.num_analog_probes = 0; | |
8a2efef2 | 520 | sr_session_bus(session_device_id, &packet); |
a1bb33af UH |
521 | |
522 | buf = g_malloc(PACKET_SIZE); | |
523 | if (!buf) | |
e46b8fb1 | 524 | return SR_ERR; |
a1bb33af | 525 | analyzer_read_start(sdi->usb->devhdl); |
fed16f06 UH |
526 | /* Send the incoming transfer to the session bus. */ |
527 | for (packet_num = 0; packet_num < (memory_size * 4 / PACKET_SIZE); | |
528 | packet_num++) { | |
a1bb33af | 529 | res = analyzer_read_data(sdi->usb->devhdl, buf, PACKET_SIZE); |
408e7199 UH |
530 | #if 0 |
531 | g_message("Tried to read %llx bytes, actually read %x bytes", | |
532 | PACKET_SIZE, res); | |
533 | #endif | |
a1bb33af | 534 | |
5a2326a7 | 535 | packet.type = SR_DF_LOGIC; |
a1bb33af | 536 | packet.length = PACKET_SIZE; |
4c046c6b | 537 | packet.unitsize = 4; |
a1bb33af | 538 | packet.payload = buf; |
8a2efef2 | 539 | sr_session_bus(session_device_id, &packet); |
a1bb33af UH |
540 | } |
541 | analyzer_read_stop(sdi->usb->devhdl); | |
542 | g_free(buf); | |
543 | ||
5a2326a7 | 544 | packet.type = SR_DF_END; |
8a2efef2 | 545 | sr_session_bus(session_device_id, &packet); |
a1bb33af | 546 | |
e46b8fb1 | 547 | return SR_OK; |
a1bb33af UH |
548 | } |
549 | ||
fed16f06 | 550 | /* This stops acquisition on ALL devices, ignoring device_index. */ |
a1bb33af UH |
551 | static void hw_stop_acquisition(int device_index, gpointer session_device_id) |
552 | { | |
b9c735a2 | 553 | struct sr_datafeed_packet packet; |
a00ba012 | 554 | struct sr_device_instance *sdi; |
a1bb33af | 555 | |
5a2326a7 | 556 | packet.type = SR_DF_END; |
8a2efef2 | 557 | sr_session_bus(session_device_id, &packet); |
a1bb33af | 558 | |
d32d961d | 559 | if (!(sdi = sr_get_device_instance(device_instances, device_index))) |
fed16f06 | 560 | return; /* TODO: Cry? */ |
a1bb33af UH |
561 | |
562 | analyzer_reset(sdi->usb->devhdl); | |
fed16f06 | 563 | /* TODO: Need to cancel and free any queued up transfers. */ |
a1bb33af UH |
564 | } |
565 | ||
5c2d46d1 | 566 | struct sr_device_plugin zeroplus_logic_cube_plugin_info = { |
a1bb33af | 567 | "zeroplus-logic-cube", |
9f8274a5 | 568 | "Zeroplus Logic Cube LAP-C series", |
a1bb33af UH |
569 | 1, |
570 | hw_init, | |
571 | hw_cleanup, | |
a1bb33af UH |
572 | hw_opendev, |
573 | hw_closedev, | |
574 | hw_get_device_info, | |
575 | hw_get_status, | |
576 | hw_get_capabilities, | |
577 | hw_set_configuration, | |
578 | hw_start_acquisition, | |
fed16f06 | 579 | hw_stop_acquisition, |
a1bb33af | 580 | }; |