]> sigrok.org Git - libsigrok.git/blame - hardware/zeroplus-logic-cube/zeroplus.c
sr/drivers: remove driver API call dev_status_get()
[libsigrok.git] / hardware / zeroplus-logic-cube / zeroplus.c
CommitLineData
a1bb33af
UH
1/*
2 * This file is part of the sigrok project.
3 *
c73d2ea4 4 * Copyright (C) 2010-2012 Bert Vermeulen <bert@biot.com>
a1bb33af
UH
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 <stdio.h>
21#include <stdlib.h>
c31e9ef4 22#include <string.h>
a1bb33af
UH
23#include <sys/time.h>
24#include <inttypes.h>
25#include <glib.h>
26#include <libusb.h>
c31e9ef4 27#include "config.h"
45c59c8b
BV
28#include "libsigrok.h"
29#include "libsigrok-internal.h"
a1bb33af
UH
30#include "analyzer.h"
31
fed16f06 32#define USB_VENDOR 0x0c12
8fdecced
UH
33
34#define VENDOR_NAME "ZEROPLUS"
35#define MODEL_NAME "Logic Cube LAP-C"
36#define MODEL_VERSION NULL
a1bb33af 37
6752905e 38#define NUM_PROBES 16
a1bb33af
UH
39#define USB_INTERFACE 0
40#define USB_CONFIGURATION 1
41#define NUM_TRIGGER_STAGES 4
42#define TRIGGER_TYPES "01"
43
fed16f06 44#define PACKET_SIZE 2048 /* ?? */
a1bb33af
UH
45
46typedef struct {
428edbe1 47 unsigned short vid;
a1bb33af 48 unsigned short pid;
428edbe1 49 char *model_name;
a1bb33af 50 unsigned int channels;
fed16f06 51 unsigned int sample_depth; /* In Ksamples/channel */
a1bb33af
UH
52 unsigned int max_sampling_freq;
53} model_t;
54
fed16f06
UH
55/*
56 * Note -- 16032, 16064 and 16128 *usually* -- but not always -- have the
57 * same 128K sample depth.
58 */
29cbfeaf 59static model_t zeroplus_models[] = {
428edbe1
BV
60 {0x0c12, 0x7009, "LAP-C(16064)", 16, 64, 100},
61 {0x0c12, 0x700A, "LAP-C(16128)", 16, 128, 200},
3f848bb7 62 /* TODO: we don't know anything about these
428edbe1
BV
63 {0x0c12, 0x700B, "LAP-C(32128)", 32, 128, 200},
64 {0x0c12, 0x700C, "LAP-C(321000)", 32, 1024, 200},
65 {0x0c12, 0x700D, "LAP-C(322000)", 32, 2048, 200},
3f848bb7 66 */
428edbe1
BV
67 {0x0c12, 0x700E, "LAP-C(16032)", 16, 32, 100},
68 {0x0c12, 0x7016, "LAP-C(162000)", 16, 2048, 200},
69 { 0, 0, 0, 0, 0, 0 }
a1bb33af
UH
70};
71
915f7cc8 72static const int hwcaps[] = {
5a2326a7
UH
73 SR_HWCAP_LOGIC_ANALYZER,
74 SR_HWCAP_SAMPLERATE,
75 SR_HWCAP_PROBECONFIG,
76 SR_HWCAP_CAPTURE_RATIO,
a1bb33af 77
fed16f06 78 /* These are really implemented in the driver, not the hardware. */
5a2326a7 79 SR_HWCAP_LIMIT_SAMPLES,
fed16f06 80 0,
a1bb33af
UH
81};
82
d261dbbf
UH
83/*
84 * ZEROPLUS LAP-C (16032) numbers the 16 probes A0-A7 and B0-B7.
85 * We currently ignore other untested/unsupported devices here.
86 */
6752905e 87static const char *probe_names[NUM_PROBES + 1] = {
d261dbbf
UH
88 "A0",
89 "A1",
90 "A2",
91 "A3",
92 "A4",
93 "A5",
94 "A6",
95 "A7",
96 "B0",
97 "B1",
98 "B2",
99 "B3",
100 "B4",
101 "B5",
102 "B6",
103 "B7",
464d12c7
KS
104 NULL,
105};
106
e7eb703f 107/* List of struct sr_dev_inst, maintained by dev_open()/dev_close(). */
32756547
BV
108SR_PRIV struct sr_dev_driver zeroplus_logic_cube_driver_info;
109static struct sr_dev_driver *zdi = &zeroplus_logic_cube_driver_info;
a1bb33af
UH
110
111static libusb_context *usb_context = NULL;
112
fed16f06
UH
113/*
114 * The hardware supports more samplerates than these, but these are the
115 * options hardcoded into the vendor's Windows GUI.
116 */
a1bb33af 117
fed16f06
UH
118/*
119 * TODO: We shouldn't support 150MHz and 200MHz on devices that don't go up
120 * that high.
121 */
a533743d 122static const uint64_t supported_samplerates[] = {
c9140419
UH
123 SR_HZ(100),
124 SR_HZ(500),
59df0c77
UH
125 SR_KHZ(1),
126 SR_KHZ(5),
127 SR_KHZ(25),
128 SR_KHZ(50),
129 SR_KHZ(100),
130 SR_KHZ(200),
131 SR_KHZ(400),
132 SR_KHZ(800),
133 SR_MHZ(1),
134 SR_MHZ(10),
135 SR_MHZ(25),
136 SR_MHZ(50),
137 SR_MHZ(80),
138 SR_MHZ(100),
139 SR_MHZ(150),
140 SR_MHZ(200),
fed16f06 141 0,
a1bb33af
UH
142};
143
a533743d 144static const struct sr_samplerates samplerates = {
590b9f9a
UH
145 0,
146 0,
147 0,
fed16f06 148 supported_samplerates,
a1bb33af
UH
149};
150
ea9cfed7
UH
151/* Private, per-device-instance driver context. */
152struct context {
bf43ea23 153 uint64_t cur_samplerate;
bf43ea23
UH
154 uint64_t limit_samples;
155 int num_channels; /* TODO: This isn't initialized before it's needed :( */
156 uint64_t memory_size;
157 uint8_t probe_mask;
158 uint8_t trigger_mask[NUM_TRIGGER_STAGES];
159 uint8_t trigger_value[NUM_TRIGGER_STAGES];
160 // uint8_t trigger_buffer[NUM_TRIGGER_STAGES];
69890f73 161
7da6f9d5 162 /* TODO: this belongs in the device instance */
d68e2d1a 163 struct sr_usb_dev_inst *usb;
bf43ea23 164};
a1bb33af 165
6f4b1868
BV
166static int hw_dev_config_set(const struct sr_dev_inst *sdi, int hwcap,
167 const void *value);
25a0f108 168static int hw_dev_close(struct sr_dev_inst *sdi);
a1bb33af
UH
169
170static unsigned int get_memory_size(int type)
171{
fed16f06
UH
172 if (type == MEMORY_SIZE_8K)
173 return 8 * 1024;
174 else if (type == MEMORY_SIZE_64K)
175 return 64 * 1024;
176 else if (type == MEMORY_SIZE_128K)
177 return 128 * 1024;
178 else if (type == MEMORY_SIZE_512K)
179 return 512 * 1024;
180 else
181 return 0;
a1bb33af
UH
182}
183
6f4b1868 184static int configure_probes(const struct sr_dev_inst *sdi, const GSList *probes)
a1bb33af 185{
ea9cfed7 186 struct context *ctx;
1b79df2f
JH
187 const struct sr_probe *probe;
188 const GSList *l;
a1bb33af
UH
189 int probe_bit, stage, i;
190 char *tc;
191
bf43ea23 192 /* Note: sdi and sdi->priv are non-NULL, the caller checked this. */
ea9cfed7 193 ctx = sdi->priv;
bf43ea23 194
ea9cfed7 195 ctx->probe_mask = 0;
fed16f06 196 for (i = 0; i < NUM_TRIGGER_STAGES; i++) {
ea9cfed7
UH
197 ctx->trigger_mask[i] = 0;
198 ctx->trigger_value[i] = 0;
a1bb33af
UH
199 }
200
201 stage = -1;
fed16f06 202 for (l = probes; l; l = l->next) {
1afe8989 203 probe = (struct sr_probe *)l->data;
fed16f06 204 if (probe->enabled == FALSE)
a1bb33af
UH
205 continue;
206 probe_bit = 1 << (probe->index - 1);
ea9cfed7 207 ctx->probe_mask |= probe_bit;
fed16f06
UH
208
209 if (probe->trigger) {
a1bb33af 210 stage = 0;
fed16f06 211 for (tc = probe->trigger; *tc; tc++) {
ea9cfed7 212 ctx->trigger_mask[stage] |= probe_bit;
fed16f06 213 if (*tc == '1')
ea9cfed7 214 ctx->trigger_value[stage] |= probe_bit;
a1bb33af 215 stage++;
fed16f06 216 if (stage > NUM_TRIGGER_STAGES)
e46b8fb1 217 return SR_ERR;
a1bb33af
UH
218 }
219 }
220 }
221
e46b8fb1 222 return SR_OK;
a1bb33af
UH
223}
224
7da6f9d5
BV
225static void clear_instances(void)
226{
227 GSList *l;
228 struct sr_dev_inst *sdi;
229
230 for (l = zdi->instances; l; l = l->next) {
231 sdi = l->data;
232 /* Properly close all devices... */
25a0f108 233 hw_dev_close(sdi);
7da6f9d5
BV
234 /* ...and free all their memory. */
235 sr_dev_inst_free(sdi);
236 }
237 g_slist_free(zdi->instances);
238 zdi->instances = NULL;
239
240}
241
a1bb33af
UH
242/*
243 * API callbacks
244 */
245
40dda2c3 246static int hw_init(void)
61136ea6
BV
247{
248
7da6f9d5
BV
249 if (libusb_init(&usb_context) != 0) {
250 sr_err("zp: Failed to initialize USB.");
251 return 0;
252 }
61136ea6
BV
253
254 return SR_OK;
255}
256
4ca38984 257static GSList *hw_scan(GSList *options)
a1bb33af 258{
d68e2d1a 259 struct sr_dev_inst *sdi;
428edbe1
BV
260 struct sr_probe *probe;
261 struct context *ctx;
262 model_t *prof;
a1bb33af
UH
263 struct libusb_device_descriptor des;
264 libusb_device **devlist;
428edbe1
BV
265 GSList *devices;
266 int ret, devcnt, i, j;
a1bb33af 267
4ca38984
BV
268 (void)options;
269 devices = NULL;
270
7da6f9d5
BV
271 clear_instances();
272
8fdecced 273 /* Find all ZEROPLUS analyzers and add them to device list. */
a1bb33af 274 devcnt = 0;
185ae2c5 275 libusb_get_device_list(usb_context, &devlist); /* TODO: Errors. */
fed16f06
UH
276
277 for (i = 0; devlist[i]; i++) {
ebc34738
UH
278 ret = libusb_get_device_descriptor(devlist[i], &des);
279 if (ret != 0) {
280 sr_err("zp: failed to get device descriptor: %d", ret);
a1bb33af
UH
281 continue;
282 }
283
428edbe1
BV
284 prof = NULL;
285 for (j = 0; j < zeroplus_models[j].vid; j++) {
286 if (des.idVendor == zeroplus_models[j].vid &&
287 des.idProduct == zeroplus_models[j].pid) {
288 prof = &zeroplus_models[j];
bf43ea23 289 }
a1bb33af 290 }
428edbe1
BV
291 /* Skip if the device was not found */
292 if (!prof)
293 continue;
294 sr_info("zp: Found ZEROPLUS model %s", prof->model_name);
295
296 /* Register the device with libsigrok. */
297 if (!(sdi = sr_dev_inst_new(devcnt, SR_ST_INACTIVE,
298 VENDOR_NAME, prof->model_name, NULL))) {
299 sr_err("zp: %s: sr_dev_inst_new failed", __func__);
300 return NULL;
301 }
302 sdi->driver = zdi;
303
304 /* Allocate memory for our private driver context. */
305 if (!(ctx = g_try_malloc0(sizeof(struct context)))) {
306 sr_err("zp: %s: ctx malloc failed", __func__);
307 return 0;
308 }
309 sdi->priv = ctx;
310 ctx->num_channels = prof->channels;
311 ctx->memory_size = prof->sample_depth * 1024;
312 // memset(ctx->trigger_buffer, 0, NUM_TRIGGER_STAGES);
313
314 /* Fill in probelist according to this device's profile. */
315 for (j = 0; j < ctx->num_channels; j++) {
316 if (!(probe = sr_probe_new(j, SR_PROBE_LOGIC, TRUE,
317 probe_names[j])))
318 return NULL;
319 sdi->probes = g_slist_append(sdi->probes, probe);
320 }
321
322 devices = g_slist_append(devices, sdi);
323 zdi->instances = g_slist_append(zdi->instances, sdi);
324 ctx->usb = sr_usb_dev_inst_new(
325 libusb_get_bus_number(devlist[i]),
326 libusb_get_device_address(devlist[i]), NULL);
327 devcnt++;
328
a1bb33af
UH
329 }
330 libusb_free_device_list(devlist, 1);
331
4ca38984 332 return devices;
a1bb33af
UH
333}
334
25a0f108 335static int hw_dev_open(struct sr_dev_inst *sdi)
a1bb33af 336{
ea9cfed7 337 struct context *ctx;
428edbe1
BV
338 libusb_device **devlist, *dev;
339 struct libusb_device_descriptor des;
340 int device_count, ret, i;
a1bb33af 341
ea9cfed7 342 if (!(ctx = sdi->priv)) {
bf43ea23
UH
343 sr_err("zp: %s: sdi->priv was NULL", __func__);
344 return SR_ERR_ARG;
345 }
346
428edbe1
BV
347 device_count = libusb_get_device_list(usb_context, &devlist);
348 if (device_count < 0) {
349 sr_err("zp: Failed to retrieve device list");
350 return SR_ERR;
351 }
352
353 dev = NULL;
354 for (i = 0; i < device_count; i++) {
355 if ((ret = libusb_get_device_descriptor(devlist[i], &des))) {
356 sr_err("fx2lafw: Failed to get device descriptor: %d.",
357 ret);
358 continue;
359 }
360 if (libusb_get_bus_number(devlist[i]) == ctx->usb->bus
361 && libusb_get_device_address(devlist[i]) == ctx->usb->address) {
362 dev = devlist[i];
363 break;
364 }
365 }
366 if (!dev) {
367 sr_err("device on bus %d address %d disappeared!",
368 ctx->usb->bus, ctx->usb->address);
369 return SR_ERR;
370 }
371
372 if (!(ret = libusb_open(dev, &(ctx->usb->devhdl)))) {
373 sdi->status = SR_ST_ACTIVE;
374 sr_info("zp: opened device %d on %d.%d interface %d",
375 sdi->index, ctx->usb->bus,
376 ctx->usb->address, USB_INTERFACE);
377 } else {
378 sr_err("zp: failed to open device: %d", ret);
379 return SR_ERR;
380 }
381
ebc34738
UH
382 ret = libusb_set_configuration(ctx->usb->devhdl, USB_CONFIGURATION);
383 if (ret < 0) {
133a37bf 384 sr_err("zp: Unable to set USB configuration %d: %d",
ebc34738 385 USB_CONFIGURATION, ret);
185ae2c5
UH
386 return SR_ERR;
387 }
388
ebc34738
UH
389 ret = libusb_claim_interface(ctx->usb->devhdl, USB_INTERFACE);
390 if (ret != 0) {
391 sr_err("zp: Unable to claim interface: %d", ret);
e46b8fb1 392 return SR_ERR;
a1bb33af 393 }
185ae2c5 394
ea9cfed7
UH
395 analyzer_reset(ctx->usb->devhdl);
396 analyzer_initialize(ctx->usb->devhdl);
a1bb33af
UH
397
398 analyzer_set_memory_size(MEMORY_SIZE_512K);
fed16f06 399 // analyzer_set_freq(g_freq, g_freq_scale);
a1bb33af 400 analyzer_set_trigger_count(1);
408e7199
UH
401 // analyzer_set_ramsize_trigger_address((((100 - g_pre_trigger)
402 // * get_memory_size(g_memory_size)) / 100) >> 2);
fed16f06
UH
403 analyzer_set_ramsize_trigger_address(
404 (100 * get_memory_size(MEMORY_SIZE_512K) / 100) >> 2);
a1bb33af 405
fed16f06
UH
406#if 0
407 if (g_double_mode == 1)
a1bb33af
UH
408 analyzer_set_compression(COMPRESSION_DOUBLE);
409 else if (g_compression == 1)
410 analyzer_set_compression(COMPRESSION_ENABLE);
fed16f06
UH
411 else
412#endif
413 analyzer_set_compression(COMPRESSION_NONE);
a1bb33af 414
ea9cfed7 415 if (ctx->cur_samplerate == 0) {
408e7199 416 /* Samplerate hasn't been set. Default to the slowest one. */
6f4b1868 417 if (hw_dev_config_set(sdi, SR_HWCAP_SAMPLERATE,
73017cf9 418 &samplerates.list[0]) == SR_ERR)
e46b8fb1 419 return SR_ERR;
a1bb33af
UH
420 }
421
e46b8fb1 422 return SR_OK;
a1bb33af
UH
423}
424
25a0f108 425static int hw_dev_close(struct sr_dev_inst *sdi)
a1bb33af 426{
25a0f108 427 struct context *ctx;
a1bb33af 428
25a0f108
BV
429 if (!(ctx = sdi->priv)) {
430 sr_err("zp: %s: sdi->priv was NULL", __func__);
431 return SR_ERR;
697785d1
UH
432 }
433
25a0f108
BV
434 if (!ctx->usb->devhdl)
435 return SR_ERR;
436
437 sr_info("zp: closing device %d on %d.%d interface %d", sdi->index,
438 ctx->usb->bus, ctx->usb->address, USB_INTERFACE);
439 libusb_release_interface(ctx->usb->devhdl, USB_INTERFACE);
440 libusb_reset_device(ctx->usb->devhdl);
441 libusb_close(ctx->usb->devhdl);
442 ctx->usb->devhdl = NULL;
443 sdi->status = SR_ST_INACTIVE;
697785d1
UH
444
445 return SR_OK;
a1bb33af
UH
446}
447
57ab7d9f 448static int hw_cleanup(void)
a1bb33af 449{
a1bb33af 450
7da6f9d5 451 clear_instances();
a1bb33af 452
fed16f06 453 if (usb_context)
a1bb33af
UH
454 libusb_exit(usb_context);
455 usb_context = NULL;
57ab7d9f
UH
456
457 return SR_OK;
a1bb33af
UH
458}
459
626409ab
BV
460static int hw_info_get(int info_id, const void **data,
461 const struct sr_dev_inst *sdi)
a1bb33af 462{
ea9cfed7 463 struct context *ctx;
a1bb33af 464
626409ab 465 switch (info_id) {
1d9a8a5f 466 case SR_DI_INST:
626409ab 467 *data = sdi;
6752905e 468 sr_spew("zp: %s: Returning sdi.", __func__);
a1bb33af 469 break;
444adea2
BV
470 case SR_DI_HWCAPS:
471 *data = hwcaps;
472 break;
5a2326a7 473 case SR_DI_NUM_PROBES:
626409ab
BV
474 if (sdi) {
475 ctx = sdi->priv;
476 *data = GINT_TO_POINTER(ctx->num_channels);
477 sr_spew("zp: %s: Returning number of channels: %d.",
478 __func__, ctx->num_channels);
479 } else
480 return SR_ERR;
a1bb33af 481 break;
464d12c7 482 case SR_DI_PROBE_NAMES:
626409ab 483 *data = probe_names;
6752905e 484 sr_spew("zp: %s: Returning probenames.", __func__);
464d12c7 485 break;
5a2326a7 486 case SR_DI_SAMPLERATES:
626409ab 487 *data = &samplerates;
6752905e 488 sr_spew("zp: %s: Returning samplerates.", __func__);
a1bb33af 489 break;
5a2326a7 490 case SR_DI_TRIGGER_TYPES:
626409ab
BV
491 *data = TRIGGER_TYPES;
492 sr_spew("zp: %s: Returning triggertypes: %s.", __func__, TRIGGER_TYPES);
a1bb33af 493 break;
5a2326a7 494 case SR_DI_CUR_SAMPLERATE:
626409ab
BV
495 if (sdi) {
496 ctx = sdi->priv;
497 *data = &ctx->cur_samplerate;
498 sr_spew("zp: %s: Returning samplerate: %" PRIu64 "Hz.",
499 __func__, ctx->cur_samplerate);
500 } else
501 return SR_ERR;
bf43ea23
UH
502 break;
503 default:
626409ab 504 return SR_ERR_ARG;
a1bb33af
UH
505 }
506
626409ab 507 return SR_OK;
a1bb33af
UH
508}
509
6f4b1868 510static int set_samplerate(const struct sr_dev_inst *sdi, uint64_t samplerate)
a1bb33af 511{
ea9cfed7 512 struct context *ctx;
bf43ea23
UH
513
514 if (!sdi) {
515 sr_err("zp: %s: sdi was NULL", __func__);
516 return SR_ERR_ARG;
517 }
518
ea9cfed7 519 if (!(ctx = sdi->priv)) {
bf43ea23
UH
520 sr_err("zp: %s: sdi->priv was NULL", __func__);
521 return SR_ERR_ARG;
522 }
523
73017cf9
UH
524 sr_info("zp: Setting samplerate to %" PRIu64 "Hz.", samplerate);
525
59df0c77
UH
526 if (samplerate > SR_MHZ(1))
527 analyzer_set_freq(samplerate / SR_MHZ(1), FREQ_SCALE_MHZ);
528 else if (samplerate > SR_KHZ(1))
529 analyzer_set_freq(samplerate / SR_KHZ(1), FREQ_SCALE_KHZ);
a1bb33af 530 else
fed16f06 531 analyzer_set_freq(samplerate, FREQ_SCALE_HZ);
a1bb33af 532
ea9cfed7 533 ctx->cur_samplerate = samplerate;
a1bb33af 534
e46b8fb1 535 return SR_OK;
a1bb33af
UH
536}
537
6f4b1868
BV
538static int hw_dev_config_set(const struct sr_dev_inst *sdi, int hwcap,
539 const void *value)
a1bb33af 540{
ea9cfed7 541 struct context *ctx;
a1bb33af 542
ea9cfed7 543 if (!(ctx = sdi->priv)) {
bf43ea23
UH
544 sr_err("zp: %s: sdi->priv was NULL", __func__);
545 return SR_ERR_ARG;
546 }
a1bb33af 547
ffedd0bf 548 switch (hwcap) {
5a2326a7 549 case SR_HWCAP_SAMPLERATE:
1b79df2f 550 return set_samplerate(sdi, *(const uint64_t *)value);
5a2326a7 551 case SR_HWCAP_PROBECONFIG:
1b79df2f 552 return configure_probes(sdi, (const GSList *)value);
5a2326a7 553 case SR_HWCAP_LIMIT_SAMPLES:
1b79df2f 554 ctx->limit_samples = *(const uint64_t *)value;
e46b8fb1 555 return SR_OK;
fed16f06 556 default:
e46b8fb1 557 return SR_ERR;
a1bb33af
UH
558 }
559}
560
3ffb6964
BV
561static int hw_dev_acquisition_start(const struct sr_dev_inst *sdi,
562 void *cb_data)
a1bb33af 563{
b9c735a2 564 struct sr_datafeed_packet packet;
9c939c51 565 struct sr_datafeed_logic logic;
b9c735a2 566 struct sr_datafeed_header header;
f366e86c 567 struct sr_datafeed_meta_logic meta;
9c939c51 568 uint64_t samples_read;
a1bb33af 569 int res;
afc8e4de 570 unsigned int packet_num;
a1bb33af 571 unsigned char *buf;
ea9cfed7 572 struct context *ctx;
a1bb33af 573
ea9cfed7 574 if (!(ctx = sdi->priv)) {
bf43ea23
UH
575 sr_err("zp: %s: sdi->priv was NULL", __func__);
576 return SR_ERR_ARG;
577 }
a1bb33af 578
a143e4e5 579 /* push configured settings to device */
ea9cfed7 580 analyzer_configure(ctx->usb->devhdl);
a143e4e5 581
ea9cfed7 582 analyzer_start(ctx->usb->devhdl);
7b48d6e1 583 sr_info("zp: Waiting for data");
ea9cfed7 584 analyzer_wait_data(ctx->usb->devhdl);
a1bb33af 585
7b48d6e1 586 sr_info("zp: Stop address = 0x%x",
ea9cfed7 587 analyzer_get_stop_address(ctx->usb->devhdl));
7b48d6e1 588 sr_info("zp: Now address = 0x%x",
ea9cfed7 589 analyzer_get_now_address(ctx->usb->devhdl));
7b48d6e1 590 sr_info("zp: Trigger address = 0x%x",
ea9cfed7 591 analyzer_get_trigger_address(ctx->usb->devhdl));
a1bb33af 592
5a2326a7 593 packet.type = SR_DF_HEADER;
9c939c51 594 packet.payload = &header;
a1bb33af
UH
595 header.feed_version = 1;
596 gettimeofday(&header.starttime, NULL);
f366e86c
BV
597 sr_session_send(cb_data, &packet);
598
599 /* Send metadata about the SR_DF_LOGIC packets to come. */
600 packet.type = SR_DF_META_LOGIC;
601 packet.payload = &meta;
602 meta.samplerate = ctx->cur_samplerate;
603 meta.num_probes = ctx->num_channels;
3cd3a20b 604 sr_session_send(cb_data, &packet);
a1bb33af 605
b53738ba 606 if (!(buf = g_try_malloc(PACKET_SIZE))) {
bf43ea23 607 sr_err("zp: %s: buf malloc failed", __func__);
b53738ba
UH
608 return SR_ERR_MALLOC;
609 }
610
9c939c51 611 samples_read = 0;
ea9cfed7 612 analyzer_read_start(ctx->usb->devhdl);
fed16f06 613 /* Send the incoming transfer to the session bus. */
ea9cfed7 614 for (packet_num = 0; packet_num < (ctx->memory_size * 4 / PACKET_SIZE);
fed16f06 615 packet_num++) {
ea9cfed7 616 res = analyzer_read_data(ctx->usb->devhdl, buf, PACKET_SIZE);
7b48d6e1 617 sr_info("zp: Tried to read %llx bytes, actually read %x bytes",
b08024a8 618 PACKET_SIZE, res);
a1bb33af 619
5a2326a7 620 packet.type = SR_DF_LOGIC;
9c939c51
BV
621 packet.payload = &logic;
622 logic.length = PACKET_SIZE;
623 logic.unitsize = 4;
624 logic.data = buf;
3cd3a20b 625 sr_session_send(cb_data, &packet);
9c939c51 626 samples_read += res / 4;
a1bb33af 627 }
ea9cfed7 628 analyzer_read_stop(ctx->usb->devhdl);
a1bb33af
UH
629 g_free(buf);
630
5a2326a7 631 packet.type = SR_DF_END;
3cd3a20b 632 sr_session_send(cb_data, &packet);
a1bb33af 633
e46b8fb1 634 return SR_OK;
a1bb33af
UH
635}
636
3cd3a20b 637/* TODO: This stops acquisition on ALL devices, ignoring dev_index. */
3ffb6964
BV
638static int hw_dev_acquisition_stop(const struct sr_dev_inst *sdi,
639 void *cb_data)
a1bb33af 640{
b9c735a2 641 struct sr_datafeed_packet packet;
ea9cfed7 642 struct context *ctx;
a1bb33af 643
5a2326a7 644 packet.type = SR_DF_END;
3cd3a20b 645 sr_session_send(cb_data, &packet);
a1bb33af 646
ea9cfed7 647 if (!(ctx = sdi->priv)) {
69890f73 648 sr_err("zp: %s: sdi->priv was NULL", __func__);
3010f21c 649 return SR_ERR_BUG;
69890f73 650 }
a1bb33af 651
ea9cfed7 652 analyzer_reset(ctx->usb->devhdl);
fed16f06 653 /* TODO: Need to cancel and free any queued up transfers. */
3010f21c
UH
654
655 return SR_OK;
a1bb33af
UH
656}
657
c09f0b57 658SR_PRIV struct sr_dev_driver zeroplus_logic_cube_driver_info = {
e519ba86 659 .name = "zeroplus-logic-cube",
8fdecced 660 .longname = "ZEROPLUS Logic Cube LAP-C series",
e519ba86
UH
661 .api_version = 1,
662 .init = hw_init,
663 .cleanup = hw_cleanup,
61136ea6 664 .scan = hw_scan,
e7eb703f
UH
665 .dev_open = hw_dev_open,
666 .dev_close = hw_dev_close,
626409ab 667 .info_get = hw_info_get,
a9a245b4 668 .dev_config_set = hw_dev_config_set,
69040b7c
UH
669 .dev_acquisition_start = hw_dev_acquisition_start,
670 .dev_acquisition_stop = hw_dev_acquisition_stop,
32756547 671 .instances = NULL,
a1bb33af 672};