]>
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))) { | |
b08024a8 | 153 | sr_warn("failed to get device descriptor: %d", err); |
408e7199 UH |
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 | ||
b08024a8 UH |
167 | sr_info("Found PID=%04X (%s)", des->idProduct, |
168 | zeroplus_models[i].model_name); | |
9a498834 UH |
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) { | |
b08024a8 | 175 | sr_warn("Unknown ZeroPlus device %04X", des->idProduct); |
408e7199 UH |
176 | return -2; |
177 | } | |
178 | ||
179 | /* Found it. */ | |
180 | if (!(err = libusb_open(dev, &((*sdi)->usb->devhdl)))) { | |
5a2326a7 | 181 | (*sdi)->status = SR_ST_ACTIVE; |
b08024a8 UH |
182 | sr_info("opened device %d on %d.%d interface %d", |
183 | (*sdi)->index, (*sdi)->usb->bus, | |
184 | (*sdi)->usb->address, USB_INTERFACE); | |
408e7199 | 185 | } else { |
b08024a8 | 186 | sr_warn("failed to open device: %d", err); |
408e7199 UH |
187 | *sdi = NULL; |
188 | } | |
189 | } | |
190 | ||
191 | return 0; | |
192 | } | |
193 | ||
29cbfeaf | 194 | static struct sr_device_instance *zp_open_device(int device_index) |
a1bb33af | 195 | { |
a00ba012 | 196 | struct sr_device_instance *sdi; |
a1bb33af UH |
197 | libusb_device **devlist; |
198 | struct libusb_device_descriptor des; | |
afc8e4de | 199 | int err, i; |
a1bb33af | 200 | |
d32d961d | 201 | if (!(sdi = sr_get_device_instance(device_instances, device_index))) |
a1bb33af UH |
202 | return NULL; |
203 | ||
204 | libusb_get_device_list(usb_context, &devlist); | |
5a2326a7 | 205 | if (sdi->status == SR_ST_INACTIVE) { |
fed16f06 | 206 | /* Find the device by vendor, product, bus and address. */ |
a1bb33af | 207 | libusb_get_device_list(usb_context, &devlist); |
fed16f06 | 208 | for (i = 0; devlist[i]; i++) { |
408e7199 | 209 | /* TODO: Error handling. */ |
9a5c6dcf | 210 | err = opendev4(&sdi, devlist[i], &des); |
a1bb33af | 211 | } |
fed16f06 | 212 | } else { |
5a2326a7 | 213 | /* Status must be SR_ST_ACTIVE, i.e. already in use... */ |
a1bb33af UH |
214 | sdi = NULL; |
215 | } | |
216 | libusb_free_device_list(devlist, 1); | |
217 | ||
5a2326a7 | 218 | if (sdi && sdi->status != SR_ST_ACTIVE) |
a1bb33af UH |
219 | sdi = NULL; |
220 | ||
221 | return sdi; | |
222 | } | |
223 | ||
a00ba012 | 224 | static void close_device(struct sr_device_instance *sdi) |
a1bb33af | 225 | { |
408e7199 UH |
226 | if (!sdi->usb->devhdl) |
227 | return; | |
228 | ||
b08024a8 UH |
229 | sr_info("closing device %d on %d.%d interface %d", sdi->index, |
230 | sdi->usb->bus, sdi->usb->address, USB_INTERFACE); | |
408e7199 UH |
231 | libusb_release_interface(sdi->usb->devhdl, USB_INTERFACE); |
232 | libusb_close(sdi->usb->devhdl); | |
233 | sdi->usb->devhdl = NULL; | |
5a2326a7 | 234 | sdi->status = SR_ST_INACTIVE; |
a1bb33af UH |
235 | } |
236 | ||
a1bb33af UH |
237 | static int configure_probes(GSList *probes) |
238 | { | |
1afe8989 | 239 | struct sr_probe *probe; |
a1bb33af UH |
240 | GSList *l; |
241 | int probe_bit, stage, i; | |
242 | char *tc; | |
243 | ||
244 | probe_mask = 0; | |
fed16f06 | 245 | for (i = 0; i < NUM_TRIGGER_STAGES; i++) { |
a1bb33af UH |
246 | trigger_mask[i] = 0; |
247 | trigger_value[i] = 0; | |
248 | } | |
249 | ||
250 | stage = -1; | |
fed16f06 | 251 | for (l = probes; l; l = l->next) { |
1afe8989 | 252 | probe = (struct sr_probe *)l->data; |
fed16f06 | 253 | if (probe->enabled == FALSE) |
a1bb33af UH |
254 | continue; |
255 | probe_bit = 1 << (probe->index - 1); | |
256 | probe_mask |= probe_bit; | |
fed16f06 UH |
257 | |
258 | if (probe->trigger) { | |
a1bb33af | 259 | stage = 0; |
fed16f06 | 260 | for (tc = probe->trigger; *tc; tc++) { |
a1bb33af | 261 | trigger_mask[stage] |= probe_bit; |
fed16f06 | 262 | if (*tc == '1') |
a1bb33af UH |
263 | trigger_value[stage] |= probe_bit; |
264 | stage++; | |
fed16f06 | 265 | if (stage > NUM_TRIGGER_STAGES) |
e46b8fb1 | 266 | return SR_ERR; |
a1bb33af UH |
267 | } |
268 | } | |
269 | } | |
270 | ||
e46b8fb1 | 271 | return SR_OK; |
a1bb33af UH |
272 | } |
273 | ||
a1bb33af UH |
274 | /* |
275 | * API callbacks | |
276 | */ | |
277 | ||
54ac5277 | 278 | static int hw_init(const char *deviceinfo) |
a1bb33af | 279 | { |
a00ba012 | 280 | struct sr_device_instance *sdi; |
a1bb33af UH |
281 | struct libusb_device_descriptor des; |
282 | libusb_device **devlist; | |
283 | int err, devcnt, i; | |
284 | ||
17e1afcb | 285 | /* Avoid compiler warnings. */ |
afc8e4de UH |
286 | deviceinfo = deviceinfo; |
287 | ||
fed16f06 | 288 | if (libusb_init(&usb_context) != 0) { |
b08024a8 | 289 | sr_warn("Failed to initialize USB."); |
a1bb33af UH |
290 | return 0; |
291 | } | |
292 | ||
fed16f06 | 293 | /* Find all ZeroPlus analyzers and add them to device list. */ |
a1bb33af UH |
294 | devcnt = 0; |
295 | libusb_get_device_list(usb_context, &devlist); | |
fed16f06 UH |
296 | |
297 | for (i = 0; devlist[i]; i++) { | |
a1bb33af | 298 | err = libusb_get_device_descriptor(devlist[i], &des); |
fed16f06 | 299 | if (err != 0) { |
b08024a8 | 300 | sr_warn("failed to get device descriptor: %d", err); |
a1bb33af UH |
301 | continue; |
302 | } | |
303 | ||
fed16f06 UH |
304 | if (des.idVendor == USB_VENDOR) { |
305 | /* | |
306 | * Definitely a Zeroplus. | |
307 | * TODO: Any way to detect specific model/version in | |
308 | * the zeroplus range? | |
309 | */ | |
a00ba012 | 310 | sdi = sr_device_instance_new(devcnt, |
5a2326a7 | 311 | SR_ST_INACTIVE, USB_VENDOR_NAME, |
fed16f06 UH |
312 | USB_MODEL_NAME, USB_MODEL_VERSION); |
313 | if (!sdi) | |
a1bb33af | 314 | return 0; |
fed16f06 UH |
315 | device_instances = |
316 | g_slist_append(device_instances, sdi); | |
6c290072 | 317 | sdi->usb = sr_usb_device_instance_new( |
fed16f06 UH |
318 | libusb_get_bus_number(devlist[i]), |
319 | libusb_get_device_address(devlist[i]), NULL); | |
a1bb33af UH |
320 | devcnt++; |
321 | } | |
322 | } | |
323 | libusb_free_device_list(devlist, 1); | |
324 | ||
325 | return devcnt; | |
326 | } | |
327 | ||
a1bb33af UH |
328 | static int hw_opendev(int device_index) |
329 | { | |
a00ba012 | 330 | struct sr_device_instance *sdi; |
a1bb33af UH |
331 | int err; |
332 | ||
fed16f06 | 333 | if (!(sdi = zp_open_device(device_index))) { |
b08024a8 | 334 | sr_warn("unable to open device"); |
e46b8fb1 | 335 | return SR_ERR; |
a1bb33af UH |
336 | } |
337 | ||
338 | err = libusb_claim_interface(sdi->usb->devhdl, USB_INTERFACE); | |
fed16f06 | 339 | if (err != 0) { |
b08024a8 | 340 | sr_warn("Unable to claim interface: %d", err); |
e46b8fb1 | 341 | return SR_ERR; |
a1bb33af UH |
342 | } |
343 | analyzer_reset(sdi->usb->devhdl); | |
344 | analyzer_initialize(sdi->usb->devhdl); | |
a1bb33af UH |
345 | |
346 | analyzer_set_memory_size(MEMORY_SIZE_512K); | |
fed16f06 | 347 | // analyzer_set_freq(g_freq, g_freq_scale); |
a1bb33af | 348 | analyzer_set_trigger_count(1); |
408e7199 UH |
349 | // analyzer_set_ramsize_trigger_address((((100 - g_pre_trigger) |
350 | // * get_memory_size(g_memory_size)) / 100) >> 2); | |
fed16f06 UH |
351 | analyzer_set_ramsize_trigger_address( |
352 | (100 * get_memory_size(MEMORY_SIZE_512K) / 100) >> 2); | |
a1bb33af | 353 | |
fed16f06 UH |
354 | #if 0 |
355 | if (g_double_mode == 1) | |
a1bb33af UH |
356 | analyzer_set_compression(COMPRESSION_DOUBLE); |
357 | else if (g_compression == 1) | |
358 | analyzer_set_compression(COMPRESSION_ENABLE); | |
fed16f06 UH |
359 | else |
360 | #endif | |
361 | analyzer_set_compression(COMPRESSION_NONE); | |
a1bb33af | 362 | |
fed16f06 | 363 | if (cur_samplerate == 0) { |
408e7199 | 364 | /* Samplerate hasn't been set. Default to the slowest one. */ |
5a2326a7 | 365 | if (hw_set_configuration(device_index, SR_HWCAP_SAMPLERATE, |
e46b8fb1 UH |
366 | &samplerates.low) == SR_ERR) |
367 | return SR_ERR; | |
a1bb33af UH |
368 | } |
369 | ||
e46b8fb1 | 370 | return SR_OK; |
a1bb33af UH |
371 | } |
372 | ||
a1bb33af UH |
373 | static void hw_closedev(int device_index) |
374 | { | |
a00ba012 | 375 | struct sr_device_instance *sdi; |
a1bb33af | 376 | |
d32d961d | 377 | if ((sdi = sr_get_device_instance(device_instances, device_index))) |
a1bb33af | 378 | close_device(sdi); |
a1bb33af UH |
379 | } |
380 | ||
a1bb33af UH |
381 | static void hw_cleanup(void) |
382 | { | |
383 | GSList *l; | |
384 | ||
408e7199 | 385 | /* Properly close all devices... */ |
fed16f06 | 386 | for (l = device_instances; l; l = l->next) |
a00ba012 | 387 | close_device((struct sr_device_instance *)l->data); |
a1bb33af | 388 | |
408e7199 | 389 | /* ...and free all their memory. */ |
fed16f06 | 390 | for (l = device_instances; l; l = l->next) |
a1bb33af UH |
391 | g_free(l->data); |
392 | g_slist_free(device_instances); | |
393 | device_instances = NULL; | |
394 | ||
fed16f06 | 395 | if (usb_context) |
a1bb33af UH |
396 | libusb_exit(usb_context); |
397 | usb_context = NULL; | |
a1bb33af UH |
398 | } |
399 | ||
a1bb33af UH |
400 | static void *hw_get_device_info(int device_index, int device_info_id) |
401 | { | |
a00ba012 | 402 | struct sr_device_instance *sdi; |
408e7199 | 403 | void *info = NULL; |
a1bb33af | 404 | |
d32d961d | 405 | if (!(sdi = sr_get_device_instance(device_instances, device_index))) |
a1bb33af UH |
406 | return NULL; |
407 | ||
fed16f06 | 408 | switch (device_info_id) { |
5a2326a7 | 409 | case SR_DI_INSTANCE: |
a1bb33af UH |
410 | info = sdi; |
411 | break; | |
5a2326a7 | 412 | case SR_DI_NUM_PROBES: |
a1bb33af UH |
413 | info = GINT_TO_POINTER(num_channels); |
414 | break; | |
5a2326a7 | 415 | case SR_DI_SAMPLERATES: |
a1bb33af UH |
416 | info = &samplerates; |
417 | break; | |
5a2326a7 | 418 | case SR_DI_TRIGGER_TYPES: |
a1bb33af UH |
419 | info = TRIGGER_TYPES; |
420 | break; | |
5a2326a7 | 421 | case SR_DI_CUR_SAMPLERATE: |
a1bb33af UH |
422 | info = &cur_samplerate; |
423 | break; | |
424 | } | |
425 | ||
426 | return info; | |
427 | } | |
428 | ||
a1bb33af UH |
429 | static int hw_get_status(int device_index) |
430 | { | |
a00ba012 | 431 | struct sr_device_instance *sdi; |
a1bb33af | 432 | |
d32d961d | 433 | sdi = sr_get_device_instance(device_instances, device_index); |
fed16f06 | 434 | if (sdi) |
a1bb33af UH |
435 | return sdi->status; |
436 | else | |
5a2326a7 | 437 | return SR_ST_NOT_FOUND; |
a1bb33af UH |
438 | } |
439 | ||
a1bb33af UH |
440 | static int *hw_get_capabilities(void) |
441 | { | |
a1bb33af UH |
442 | return capabilities; |
443 | } | |
444 | ||
fed16f06 | 445 | /* TODO: This will set the same samplerate for all devices. */ |
afc8e4de | 446 | static int set_configuration_samplerate(uint64_t samplerate) |
a1bb33af | 447 | { |
b08024a8 | 448 | sr_info("%s(%" PRIu64 ")", __FUNCTION__, samplerate); |
59df0c77 UH |
449 | if (samplerate > SR_MHZ(1)) |
450 | analyzer_set_freq(samplerate / SR_MHZ(1), FREQ_SCALE_MHZ); | |
451 | else if (samplerate > SR_KHZ(1)) | |
452 | analyzer_set_freq(samplerate / SR_KHZ(1), FREQ_SCALE_KHZ); | |
a1bb33af | 453 | else |
fed16f06 | 454 | analyzer_set_freq(samplerate, FREQ_SCALE_HZ); |
a1bb33af UH |
455 | |
456 | cur_samplerate = samplerate; | |
457 | ||
e46b8fb1 | 458 | return SR_OK; |
a1bb33af UH |
459 | } |
460 | ||
461 | static int hw_set_configuration(int device_index, int capability, void *value) | |
462 | { | |
a00ba012 | 463 | struct sr_device_instance *sdi; |
a1bb33af UH |
464 | uint64_t *tmp_u64; |
465 | ||
d32d961d | 466 | if (!(sdi = sr_get_device_instance(device_instances, device_index))) |
e46b8fb1 | 467 | return SR_ERR; |
a1bb33af UH |
468 | |
469 | switch (capability) { | |
5a2326a7 | 470 | case SR_HWCAP_SAMPLERATE: |
fed16f06 UH |
471 | tmp_u64 = value; |
472 | return set_configuration_samplerate(*tmp_u64); | |
5a2326a7 | 473 | case SR_HWCAP_PROBECONFIG: |
fed16f06 | 474 | return configure_probes((GSList *) value); |
5a2326a7 | 475 | case SR_HWCAP_LIMIT_SAMPLES: |
2458ea65 BV |
476 | tmp_u64 = value; |
477 | limit_samples = *tmp_u64; | |
e46b8fb1 | 478 | return SR_OK; |
fed16f06 | 479 | default: |
e46b8fb1 | 480 | return SR_ERR; |
a1bb33af UH |
481 | } |
482 | } | |
483 | ||
484 | static int hw_start_acquisition(int device_index, gpointer session_device_id) | |
485 | { | |
a00ba012 | 486 | struct sr_device_instance *sdi; |
b9c735a2 UH |
487 | struct sr_datafeed_packet packet; |
488 | struct sr_datafeed_header header; | |
a1bb33af | 489 | int res; |
afc8e4de | 490 | unsigned int packet_num; |
a1bb33af UH |
491 | unsigned char *buf; |
492 | ||
d32d961d | 493 | if (!(sdi = sr_get_device_instance(device_instances, device_index))) |
e46b8fb1 | 494 | return SR_ERR; |
a1bb33af | 495 | |
a143e4e5 BV |
496 | /* push configured settings to device */ |
497 | analyzer_configure(sdi->usb->devhdl); | |
498 | ||
a1bb33af | 499 | analyzer_start(sdi->usb->devhdl); |
b08024a8 | 500 | sr_info("Waiting for data"); |
a1bb33af UH |
501 | analyzer_wait_data(sdi->usb->devhdl); |
502 | ||
b08024a8 UH |
503 | sr_info("Stop address = 0x%x", |
504 | analyzer_get_stop_address(sdi->usb->devhdl)); | |
505 | sr_info("Now address = 0x%x", | |
506 | analyzer_get_now_address(sdi->usb->devhdl)); | |
507 | sr_info("Trigger address = 0x%x", | |
508 | analyzer_get_trigger_address(sdi->usb->devhdl)); | |
a1bb33af | 509 | |
5a2326a7 | 510 | packet.type = SR_DF_HEADER; |
b9c735a2 | 511 | packet.length = sizeof(struct sr_datafeed_header); |
fed16f06 | 512 | packet.payload = (unsigned char *)&header; |
a1bb33af UH |
513 | header.feed_version = 1; |
514 | gettimeofday(&header.starttime, NULL); | |
4c100f32 | 515 | header.samplerate = cur_samplerate; |
5a2326a7 | 516 | header.protocol_id = SR_PROTO_RAW; |
c2616fb9 DR |
517 | header.num_logic_probes = num_channels; |
518 | header.num_analog_probes = 0; | |
8a2efef2 | 519 | sr_session_bus(session_device_id, &packet); |
a1bb33af | 520 | |
b53738ba UH |
521 | if (!(buf = g_try_malloc(PACKET_SIZE))) { |
522 | sr_err("zeroplus: %s: buf malloc failed", __func__); | |
523 | return SR_ERR_MALLOC; | |
524 | } | |
525 | ||
a1bb33af | 526 | analyzer_read_start(sdi->usb->devhdl); |
fed16f06 UH |
527 | /* Send the incoming transfer to the session bus. */ |
528 | for (packet_num = 0; packet_num < (memory_size * 4 / PACKET_SIZE); | |
529 | packet_num++) { | |
a1bb33af | 530 | res = analyzer_read_data(sdi->usb->devhdl, buf, PACKET_SIZE); |
408e7199 | 531 | #if 0 |
b08024a8 UH |
532 | sr_info("Tried to read %llx bytes, actually read %x bytes", |
533 | PACKET_SIZE, res); | |
408e7199 | 534 | #endif |
a1bb33af | 535 | |
5a2326a7 | 536 | packet.type = SR_DF_LOGIC; |
a1bb33af | 537 | packet.length = PACKET_SIZE; |
4c046c6b | 538 | packet.unitsize = 4; |
a1bb33af | 539 | packet.payload = buf; |
8a2efef2 | 540 | sr_session_bus(session_device_id, &packet); |
a1bb33af UH |
541 | } |
542 | analyzer_read_stop(sdi->usb->devhdl); | |
543 | g_free(buf); | |
544 | ||
5a2326a7 | 545 | packet.type = SR_DF_END; |
8a2efef2 | 546 | sr_session_bus(session_device_id, &packet); |
a1bb33af | 547 | |
e46b8fb1 | 548 | return SR_OK; |
a1bb33af UH |
549 | } |
550 | ||
fed16f06 | 551 | /* This stops acquisition on ALL devices, ignoring device_index. */ |
a1bb33af UH |
552 | static void hw_stop_acquisition(int device_index, gpointer session_device_id) |
553 | { | |
b9c735a2 | 554 | struct sr_datafeed_packet packet; |
a00ba012 | 555 | struct sr_device_instance *sdi; |
a1bb33af | 556 | |
5a2326a7 | 557 | packet.type = SR_DF_END; |
8a2efef2 | 558 | sr_session_bus(session_device_id, &packet); |
a1bb33af | 559 | |
d32d961d | 560 | if (!(sdi = sr_get_device_instance(device_instances, device_index))) |
fed16f06 | 561 | return; /* TODO: Cry? */ |
a1bb33af UH |
562 | |
563 | analyzer_reset(sdi->usb->devhdl); | |
fed16f06 | 564 | /* TODO: Need to cancel and free any queued up transfers. */ |
a1bb33af UH |
565 | } |
566 | ||
5c2d46d1 | 567 | struct sr_device_plugin zeroplus_logic_cube_plugin_info = { |
a1bb33af | 568 | "zeroplus-logic-cube", |
9f8274a5 | 569 | "Zeroplus Logic Cube LAP-C series", |
a1bb33af UH |
570 | 1, |
571 | hw_init, | |
572 | hw_cleanup, | |
a1bb33af UH |
573 | hw_opendev, |
574 | hw_closedev, | |
575 | hw_get_device_info, | |
576 | hw_get_status, | |
577 | hw_get_capabilities, | |
578 | hw_set_configuration, | |
579 | hw_start_acquisition, | |
fed16f06 | 580 | hw_stop_acquisition, |
a1bb33af | 581 | }; |