]> sigrok.org Git - libsigrok.git/blame - src/hardware/chronovu-la/api.c
dev_acquisition_{start,stop}(): Drop duplicate 'cb_data' parameter.
[libsigrok.git] / src / hardware / chronovu-la / api.c
CommitLineData
b908f067 1/*
50985c20 2 * This file is part of the libsigrok project.
b908f067 3 *
67f890d5 4 * Copyright (C) 2011-2015 Uwe Hermann <uwe@hermann-uwe.de>
b908f067
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 2 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, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20
6ec6c43b 21#include <config.h>
45e080b6 22#include "protocol.h"
b908f067 23
7b356712
UH
24SR_PRIV struct sr_dev_driver chronovu_la_driver_info;
25static struct sr_dev_driver *di = &chronovu_la_driver_info;
b908f067 26
67f890d5 27static const uint32_t drvopts[] = {
1bec72d2 28 SR_CONF_LOGIC_ANALYZER,
67f890d5
UH
29};
30
31static const uint32_t scanopts[] = {
32 SR_CONF_CONN,
33};
34
35static const uint32_t devopts[] = {
5827f61b
BV
36 SR_CONF_LIMIT_MSEC | SR_CONF_SET,
37 SR_CONF_LIMIT_SAMPLES | SR_CONF_SET | SR_CONF_LIST,
67f890d5 38 SR_CONF_CONN | SR_CONF_GET,
5827f61b
BV
39 SR_CONF_SAMPLERATE | SR_CONF_GET | SR_CONF_SET | SR_CONF_LIST,
40 SR_CONF_TRIGGER_MATCH | SR_CONF_LIST,
1bec72d2
BV
41};
42
aeff7fa2
BV
43static const int32_t trigger_matches[] = {
44 SR_TRIGGER_ZERO,
45 SR_TRIGGER_ONE,
46 SR_TRIGGER_RISING,
47 SR_TRIGGER_FALLING,
48};
49
695dc859 50static int dev_acquisition_stop(struct sr_dev_inst *sdi);
b908f067 51
97900799 52static void clear_helper(void *priv)
c4f3ed4b 53{
1644fb24 54 struct dev_context *devc;
b172c130 55
97900799 56 devc = priv;
1644fb24 57
97900799
UH
58 ftdi_free(devc->ftdic);
59 g_free(devc->final_buf);
60}
c4f3ed4b 61
4f840ce9 62static int dev_clear(const struct sr_dev_driver *di)
97900799
UH
63{
64 return std_dev_clear(di, clear_helper);
c4f3ed4b
BV
65}
66
4f840ce9 67static int init(struct sr_dev_driver *di, struct sr_context *sr_ctx)
61136ea6 68{
f6beaac5 69 return std_init(sr_ctx, di, LOG_PREFIX);
61136ea6
BV
70}
71
67f890d5
UH
72static int add_device(int model, struct libusb_device_descriptor *des,
73 const char *serial_num, const char *connection_id,
74 libusb_device *usbdev, GSList **devices)
b908f067 75{
00910580
UH
76 int ret;
77 unsigned int i;
b908f067 78 struct sr_dev_inst *sdi;
1644fb24
BV
79 struct drv_context *drvc;
80 struct dev_context *devc;
c4f3ed4b 81
00910580 82 ret = SR_OK;
f3a35908 83
41812aca 84 drvc = di->context;
4b97c74e 85
1644fb24 86 /* Allocate memory for our private device context. */
f57d8ffe 87 devc = g_malloc0(sizeof(struct dev_context));
b908f067
UH
88
89 /* Set some sane defaults. */
00910580
UH
90 devc->prof = &cv_profiles[model];
91 devc->ftdic = NULL; /* Will be set in the open() API call. */
92 devc->cur_samplerate = 0; /* Set later (different for LA8/LA16). */
1644fb24
BV
93 devc->limit_msec = 0;
94 devc->limit_samples = 0;
1644fb24
BV
95 memset(devc->mangled_buf, 0, BS);
96 devc->final_buf = NULL;
00910580
UH
97 devc->trigger_pattern = 0x0000; /* Irrelevant, see trigger_mask. */
98 devc->trigger_mask = 0x0000; /* All channels: "don't care". */
99 devc->trigger_edgemask = 0x0000; /* All channels: "state triggered". */
1644fb24
BV
100 devc->trigger_found = 0;
101 devc->done = 0;
102 devc->block_counter = 0;
00910580 103 devc->divcount = 0;
67f890d5
UH
104 devc->usb_vid = des->idVendor;
105 devc->usb_pid = des->idProduct;
00910580 106 memset(devc->samplerates, 0, sizeof(uint64_t) * 255);
b908f067
UH
107
108 /* Allocate memory where we'll store the de-mangled data. */
1644fb24 109 if (!(devc->final_buf = g_try_malloc(SDRAM_SIZE))) {
b172c130 110 sr_err("Failed to allocate memory for sample buffer.");
00910580 111 ret = SR_ERR_MALLOC;
1644fb24 112 goto err_free_devc;
b908f067
UH
113 }
114
00910580
UH
115 /* We now know the device, set its max. samplerate as default. */
116 devc->cur_samplerate = devc->prof->max_samplerate;
b908f067
UH
117
118 /* Register the device with libsigrok. */
aac29cc1 119 sdi = g_malloc0(sizeof(struct sr_dev_inst));
0af636be
UH
120 sdi->status = SR_ST_INITIALIZING;
121 sdi->vendor = g_strdup("ChronoVu");
122 sdi->model = g_strdup(devc->prof->modelname);
67f890d5
UH
123 sdi->serial_num = g_strdup(serial_num);
124 sdi->connection_id = g_strdup(connection_id);
125 sdi->conn = sr_usb_dev_inst_new(libusb_get_bus_number(usbdev),
126 libusb_get_device_address(usbdev), NULL);
f3a35908 127 sdi->driver = di;
1644fb24 128 sdi->priv = devc;
b908f067 129
5e23fcab
ML
130 for (i = 0; i < devc->prof->num_channels; i++)
131 sr_channel_new(sdi, i, SR_CHANNEL_LOGIC, TRUE,
0f34cb47 132 cv_channel_names[i]);
87ca93c5 133
00910580 134 *devices = g_slist_append(*devices, sdi);
1644fb24 135 drvc->instances = g_slist_append(drvc->instances, sdi);
b908f067 136
65c8d48f
BV
137 if (ret == SR_OK)
138 return SR_OK;
b908f067 139
1644fb24
BV
140err_free_devc:
141 g_free(devc);
b908f067 142
00910580
UH
143 return ret;
144}
145
4f840ce9 146static GSList *scan(struct sr_dev_driver *di, GSList *options)
00910580 147{
67f890d5
UH
148 int i, ret, model;
149 struct drv_context *drvc;
150 GSList *devices, *conn_devices, *l;
151 struct sr_usb_dev_inst *usb;
152 struct sr_config *src;
153 struct libusb_device_descriptor des;
154 libusb_device **devlist;
155 struct libusb_device_handle *hdl;
156 const char *conn;
157 char product[64], serial_num[64], connection_id[64];
00910580 158
67f890d5
UH
159 drvc = di->context;
160 drvc->instances = NULL;
161
162 conn = NULL;
163 for (l = options; l; l = l->next) {
164 src = l->data;
165 switch (src->key) {
166 case SR_CONF_CONN:
167 conn = g_variant_get_string(src->data, NULL);
168 break;
169 }
00910580 170 }
67f890d5
UH
171 if (conn)
172 conn_devices = sr_usb_find(drvc->sr_ctx->libusb_ctx, conn);
173 else
174 conn_devices = NULL;
00910580 175
67f890d5
UH
176 devices = NULL;
177 libusb_get_device_list(drvc->sr_ctx->libusb_ctx, &devlist);
178
179 for (i = 0; devlist[i]; i++) {
180 if (conn) {
181 for (l = conn_devices; l; l = l->next) {
182 usb = l->data;
183 if (usb->bus == libusb_get_bus_number(devlist[i])
184 && usb->address == libusb_get_device_address(devlist[i]))
185 break;
186 }
187 if (!l)
188 /* This device matched none of the ones that
189 * matched the conn specification. */
190 continue;
191 }
192
193 libusb_get_device_descriptor(devlist[i], &des);
194
195 if ((ret = libusb_open(devlist[i], &hdl)) < 0)
196 continue;
197
198 if (des.iProduct == 0) {
199 product[0] = '\0';
200 } else if ((ret = libusb_get_string_descriptor_ascii(hdl,
201 des.iProduct, (unsigned char *)product,
202 sizeof(product))) < 0) {
203 sr_warn("Failed to get product string descriptor: %s.",
204 libusb_error_name(ret));
205 continue;
206 }
207
208 if (des.iSerialNumber == 0) {
209 serial_num[0] = '\0';
210 } else if ((ret = libusb_get_string_descriptor_ascii(hdl,
211 des.iSerialNumber, (unsigned char *)serial_num,
212 sizeof(serial_num))) < 0) {
213 sr_warn("Failed to get serial number string descriptor: %s.",
214 libusb_error_name(ret));
215 continue;
216 }
217
218 usb_get_port_path(devlist[i], connection_id, sizeof(connection_id));
219
220 libusb_close(hdl);
221
222 if (!strcmp(product, "ChronoVu LA8")) {
223 model = 0;
224 } else if (!strcmp(product, "ChronoVu LA16")) {
225 model = 1;
226 } else {
227 sr_spew("Unknown iProduct string '%s'.", product);
228 continue;
229 }
230
231 sr_dbg("Found %s (%04x:%04x, %d.%d, %s).",
232 product, des.idVendor, des.idProduct,
233 libusb_get_bus_number(devlist[i]),
234 libusb_get_device_address(devlist[i]), connection_id);
235
236 if ((ret = add_device(model, &des, serial_num, connection_id,
237 devlist[i], &devices)) < 0) {
00910580 238 sr_dbg("Failed to add device: %d.", ret);
67f890d5 239 }
00910580
UH
240 }
241
67f890d5
UH
242 libusb_free_device_list(devlist, 1);
243 g_slist_free_full(conn_devices, (GDestroyNotify)sr_usb_dev_inst_free);
00910580
UH
244
245 return devices;
b908f067
UH
246}
247
4f840ce9 248static GSList *dev_list(const struct sr_dev_driver *di)
811deee4 249{
41812aca 250 return ((struct drv_context *)(di->context))->instances;
811deee4
BV
251}
252
6078d2c9 253static int dev_open(struct sr_dev_inst *sdi)
b908f067 254{
1644fb24 255 struct dev_context *devc;
25a0f108 256 int ret;
b908f067 257
b172c130 258 if (!(devc = sdi->priv))
b908f067 259 return SR_ERR_BUG;
b908f067 260
00910580
UH
261 /* Allocate memory for the FTDI context and initialize it. */
262 if (!(devc->ftdic = ftdi_new())) {
263 sr_err("Failed to initialize libftdi.");
264 return SR_ERR;
265 }
266
267 sr_dbg("Opening %s device (%04x:%04x).", devc->prof->modelname,
268 devc->usb_vid, devc->usb_pid);
b908f067
UH
269
270 /* Open the device. */
00910580
UH
271 if ((ret = ftdi_usb_open_desc(devc->ftdic, devc->usb_vid,
272 devc->usb_pid, devc->prof->iproduct, NULL)) < 0) {
b172c130
UH
273 sr_err("Failed to open FTDI device (%d): %s.",
274 ret, ftdi_get_error_string(devc->ftdic));
00910580 275 goto err_ftdi_free;
b908f067 276 }
f3a35908 277 sr_dbg("Device opened successfully.");
b908f067
UH
278
279 /* Purge RX/TX buffers in the FTDI chip. */
1644fb24 280 if ((ret = ftdi_usb_purge_buffers(devc->ftdic)) < 0) {
b172c130
UH
281 sr_err("Failed to purge FTDI buffers (%d): %s.",
282 ret, ftdi_get_error_string(devc->ftdic));
00910580 283 goto err_ftdi_free;
b908f067 284 }
f3a35908 285 sr_dbg("FTDI buffers purged successfully.");
b908f067
UH
286
287 /* Enable flow control in the FTDI chip. */
1644fb24 288 if ((ret = ftdi_setflowctrl(devc->ftdic, SIO_RTS_CTS_HS)) < 0) {
b172c130
UH
289 sr_err("Failed to enable FTDI flow control (%d): %s.",
290 ret, ftdi_get_error_string(devc->ftdic));
00910580 291 goto err_ftdi_free;
b908f067 292 }
f3a35908 293 sr_dbg("FTDI flow control enabled successfully.");
b908f067
UH
294
295 /* Wait 100ms. */
296 g_usleep(100 * 1000);
297
298 sdi->status = SR_ST_ACTIVE;
299
65c8d48f
BV
300 if (ret == SR_OK)
301 return SR_OK;
b908f067 302
00910580
UH
303err_ftdi_free:
304 ftdi_free(devc->ftdic); /* Close device (if open), free FTDI context. */
305 devc->ftdic = NULL;
306 return ret;
b908f067
UH
307}
308
6078d2c9 309static int dev_close(struct sr_dev_inst *sdi)
b908f067 310{
00910580 311 int ret;
1644fb24 312 struct dev_context *devc;
b908f067 313
00910580
UH
314 if (sdi->status != SR_ST_ACTIVE)
315 return SR_OK;
b908f067 316
00910580 317 devc = sdi->priv;
b908f067 318
00910580
UH
319 if (devc->ftdic && (ret = ftdi_usb_close(devc->ftdic)) < 0)
320 sr_err("Failed to close FTDI device (%d): %s.",
321 ret, ftdi_get_error_string(devc->ftdic));
b908f067
UH
322 sdi->status = SR_ST_INACTIVE;
323
b908f067
UH
324 return SR_OK;
325}
326
4f840ce9 327static int cleanup(const struct sr_dev_driver *di)
b908f067 328{
4f840ce9 329 return dev_clear(di);
b908f067
UH
330}
331
584560f1 332static int config_get(uint32_t key, GVariant **data, const struct sr_dev_inst *sdi,
53b4680f 333 const struct sr_channel_group *cg)
b908f067 334{
1644fb24 335 struct dev_context *devc;
67f890d5
UH
336 struct sr_usb_dev_inst *usb;
337 char str[128];
b908f067 338
53b4680f 339 (void)cg;
8f996b89 340
584560f1 341 switch (key) {
67f890d5
UH
342 case SR_CONF_CONN:
343 if (!sdi || !(usb = sdi->conn))
344 return SR_ERR_ARG;
345 snprintf(str, 128, "%d.%d", usb->bus, usb->address);
346 *data = g_variant_new_string(str);
347 break;
123e1313 348 case SR_CONF_SAMPLERATE:
b172c130
UH
349 if (!sdi || !(devc = sdi->priv))
350 return SR_ERR_BUG;
351 *data = g_variant_new_uint64(devc->cur_samplerate);
b908f067 352 break;
cfe8a84d 353 default:
bd6fbf62 354 return SR_ERR_NA;
b908f067
UH
355 }
356
6a2761fd 357 return SR_OK;
b908f067
UH
358}
359
584560f1 360static int config_set(uint32_t key, GVariant *data, const struct sr_dev_inst *sdi,
53b4680f 361 const struct sr_channel_group *cg)
b908f067 362{
1644fb24 363 struct dev_context *devc;
b908f067 364
53b4680f 365 (void)cg;
8f996b89 366
e73ffd42
BV
367 if (sdi->status != SR_ST_ACTIVE)
368 return SR_ERR_DEV_CLOSED;
369
b172c130 370 if (!(devc = sdi->priv))
b908f067 371 return SR_ERR_BUG;
b908f067 372
584560f1 373 switch (key) {
1953564a 374 case SR_CONF_SAMPLERATE:
00910580 375 if (cv_set_samplerate(sdi, g_variant_get_uint64(data)) < 0)
b908f067 376 return SR_ERR;
b908f067 377 break;
1953564a 378 case SR_CONF_LIMIT_MSEC:
b172c130
UH
379 if (g_variant_get_uint64(data) == 0)
380 return SR_ERR_ARG;
1bec72d2 381 devc->limit_msec = g_variant_get_uint64(data);
b908f067 382 break;
1953564a 383 case SR_CONF_LIMIT_SAMPLES:
b172c130
UH
384 if (g_variant_get_uint64(data) == 0)
385 return SR_ERR_ARG;
1bec72d2 386 devc->limit_samples = g_variant_get_uint64(data);
b908f067
UH
387 break;
388 default:
bd6fbf62 389 return SR_ERR_NA;
b908f067
UH
390 }
391
392 return SR_OK;
393}
394
584560f1 395static int config_list(uint32_t key, GVariant **data, const struct sr_dev_inst *sdi,
53b4680f 396 const struct sr_channel_group *cg)
a1c743fc 397{
f0de2dd0 398 GVariant *gvar, *grange[2];
1bec72d2 399 GVariantBuilder gvb;
00910580 400 struct dev_context *devc;
a1c743fc 401
53b4680f 402 (void)cg;
a1c743fc
BV
403
404 switch (key) {
67f890d5 405 case SR_CONF_SCAN_OPTIONS:
584560f1 406 *data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
67f890d5
UH
407 scanopts, ARRAY_SIZE(scanopts), sizeof(uint32_t));
408 break;
409 case SR_CONF_DEVICE_OPTIONS:
410 if (!sdi)
411 *data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
412 drvopts, ARRAY_SIZE(drvopts), sizeof(uint32_t));
413 else
414 *data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
415 devopts, ARRAY_SIZE(devopts), sizeof(uint32_t));
9a6517d1 416 break;
a1c743fc 417 case SR_CONF_SAMPLERATE:
00910580
UH
418 if (!sdi || !sdi->priv || !(devc = sdi->priv))
419 return SR_ERR_BUG;
420 cv_fill_samplerates_if_needed(sdi);
1bec72d2
BV
421 g_variant_builder_init(&gvb, G_VARIANT_TYPE("a{sv}"));
422 gvar = g_variant_new_fixed_array(G_VARIANT_TYPE("t"),
00910580
UH
423 devc->samplerates,
424 ARRAY_SIZE(devc->samplerates),
1bec72d2
BV
425 sizeof(uint64_t));
426 g_variant_builder_add(&gvb, "{sv}", "samplerates", gvar);
427 *data = g_variant_builder_end(&gvb);
a1c743fc 428 break;
f0de2dd0 429 case SR_CONF_LIMIT_SAMPLES:
69bdcd8b
UH
430 if (!sdi || !sdi->priv || !(devc = sdi->priv) || !devc->prof)
431 return SR_ERR_BUG;
f0de2dd0 432 grange[0] = g_variant_new_uint64(0);
69bdcd8b
UH
433 if (devc->prof->model == CHRONOVU_LA8)
434 grange[1] = g_variant_new_uint64(MAX_NUM_SAMPLES);
435 else
436 grange[1] = g_variant_new_uint64(MAX_NUM_SAMPLES / 2);
f0de2dd0
BV
437 *data = g_variant_new_tuple(grange, 2);
438 break;
aeff7fa2 439 case SR_CONF_TRIGGER_MATCH:
00910580 440 if (!sdi || !sdi->priv || !(devc = sdi->priv) || !devc->prof)
13dd25bd 441 return SR_ERR_BUG;
af945a66 442 *data = g_variant_new_fixed_array(G_VARIANT_TYPE_INT32,
aeff7fa2
BV
443 trigger_matches, devc->prof->num_trigger_matches,
444 sizeof(int32_t));
c50277a6 445 break;
a1c743fc 446 default:
bd6fbf62 447 return SR_ERR_NA;
a1c743fc
BV
448 }
449
450 return SR_OK;
451}
452
b908f067
UH
453static int receive_data(int fd, int revents, void *cb_data)
454{
455 int i, ret;
456 struct sr_dev_inst *sdi;
1644fb24 457 struct dev_context *devc;
b908f067 458
b908f067
UH
459 (void)fd;
460 (void)revents;
461
462 if (!(sdi = cb_data)) {
b172c130 463 sr_err("cb_data was NULL.");
b908f067
UH
464 return FALSE;
465 }
466
1644fb24 467 if (!(devc = sdi->priv)) {
b172c130 468 sr_err("sdi->priv was NULL.");
b908f067
UH
469 return FALSE;
470 }
471
1644fb24 472 if (!devc->ftdic) {
b172c130 473 sr_err("devc->ftdic was NULL.");
b908f067
UH
474 return FALSE;
475 }
476
477 /* Get one block of data. */
b172c130
UH
478 if ((ret = cv_read_block(devc)) < 0) {
479 sr_err("Failed to read data block: %d.", ret);
695dc859 480 dev_acquisition_stop(sdi);
b908f067
UH
481 return FALSE;
482 }
483
484 /* We need to get exactly NUM_BLOCKS blocks (i.e. 8MB) of data. */
1644fb24
BV
485 if (devc->block_counter != (NUM_BLOCKS - 1)) {
486 devc->block_counter++;
b908f067
UH
487 return TRUE;
488 }
489
f3a35908 490 sr_dbg("Sampling finished, sending data to session bus now.");
b908f067 491
b0efc84e
UH
492 /*
493 * All data was received and demangled, send it to the session bus.
494 *
495 * Note: Due to the method how data is spread across the 8MByte of
496 * SDRAM, we can _not_ send it to the session bus in a streaming
497 * manner while we receive it. We have to receive and de-mangle the
498 * full 8MByte first, only then the whole buffer contains valid data.
499 */
b908f067 500 for (i = 0; i < NUM_BLOCKS; i++)
695dc859 501 cv_send_block_to_session_bus(sdi, i);
b908f067 502
695dc859 503 dev_acquisition_stop(sdi);
b908f067 504
b908f067
UH
505 return TRUE;
506}
507
695dc859 508static int dev_acquisition_start(const struct sr_dev_inst *sdi)
b908f067 509{
1644fb24 510 struct dev_context *devc;
00910580
UH
511 uint8_t buf[8];
512 int bytes_to_write, bytes_written;
b908f067 513
e73ffd42
BV
514 if (sdi->status != SR_ST_ACTIVE)
515 return SR_ERR_DEV_CLOSED;
516
208c1d35 517 devc = sdi->priv;
b908f067 518
1644fb24 519 if (!devc->ftdic) {
b172c130 520 sr_err("devc->ftdic was NULL.");
b908f067
UH
521 return SR_ERR_BUG;
522 }
523
00910580 524 devc->divcount = cv_samplerate_to_divcount(sdi, devc->cur_samplerate);
1644fb24 525 if (devc->divcount == 0xff) {
b172c130 526 sr_err("Invalid divcount/samplerate.");
b908f067
UH
527 return SR_ERR;
528 }
529
aeff7fa2
BV
530 if (cv_convert_trigger(sdi) != SR_OK) {
531 sr_err("Failed to configure trigger.");
014359e3
BV
532 return SR_ERR;
533 }
534
b908f067 535 /* Fill acquisition parameters into buf[]. */
00910580
UH
536 if (devc->prof->model == CHRONOVU_LA8) {
537 buf[0] = devc->divcount;
538 buf[1] = 0xff; /* This byte must always be 0xff. */
539 buf[2] = devc->trigger_pattern & 0xff;
540 buf[3] = devc->trigger_mask & 0xff;
541 bytes_to_write = 4;
542 } else {
543 buf[0] = devc->divcount;
544 buf[1] = 0xff; /* This byte must always be 0xff. */
545 buf[2] = (devc->trigger_pattern & 0xff00) >> 8; /* LSB */
546 buf[3] = (devc->trigger_pattern & 0x00ff) >> 0; /* MSB */
547 buf[4] = (devc->trigger_mask & 0xff00) >> 8; /* LSB */
548 buf[5] = (devc->trigger_mask & 0x00ff) >> 0; /* MSB */
549 buf[6] = (devc->trigger_edgemask & 0xff00) >> 8; /* LSB */
550 buf[7] = (devc->trigger_edgemask & 0x00ff) >> 0; /* MSB */
551 bytes_to_write = 8;
552 }
b908f067
UH
553
554 /* Start acquisition. */
00910580 555 bytes_written = cv_write(devc, buf, bytes_to_write);
b908f067 556
00910580
UH
557 if (bytes_written < 0 || bytes_written != bytes_to_write) {
558 sr_err("Acquisition failed to start.");
afc88319 559 return SR_ERR;
b908f067
UH
560 }
561
4afdfd46 562 sr_dbg("Hardware acquisition started successfully.");
b908f067 563
102f1239 564 std_session_send_df_header(sdi, LOG_PREFIX);
b908f067 565
b908f067 566 /* Time when we should be done (for detecting trigger timeouts). */
00910580
UH
567 devc->done = (devc->divcount + 1) * devc->prof->trigger_constant +
568 g_get_monotonic_time() + (10 * G_TIME_SPAN_SECOND);
1644fb24
BV
569 devc->block_counter = 0;
570 devc->trigger_found = 0;
b908f067 571
b172c130 572 /* Hook up a dummy handler to receive data from the device. */
c650d3ec 573 sr_session_source_add(sdi->session, -1, 0, 0, receive_data, (void *)sdi);
b908f067
UH
574
575 return SR_OK;
576}
577
695dc859 578static int dev_acquisition_stop(struct sr_dev_inst *sdi)
b908f067 579{
f3a35908 580 sr_dbg("Stopping acquisition.");
102f1239 581 sr_session_source_remove(sdi->session, -1);
3be42bc2 582 std_session_send_df_end(sdi, LOG_PREFIX);
b908f067
UH
583
584 return SR_OK;
585}
586
7b356712
UH
587SR_PRIV struct sr_dev_driver chronovu_la_driver_info = {
588 .name = "chronovu-la",
589 .longname = "ChronoVu LA8/LA16",
b908f067 590 .api_version = 1,
6078d2c9
UH
591 .init = init,
592 .cleanup = cleanup,
593 .scan = scan,
594 .dev_list = dev_list,
3b412e3a 595 .dev_clear = dev_clear,
035a1078
BV
596 .config_get = config_get,
597 .config_set = config_set,
a1c743fc 598 .config_list = config_list,
6078d2c9
UH
599 .dev_open = dev_open,
600 .dev_close = dev_close,
601 .dev_acquisition_start = dev_acquisition_start,
602 .dev_acquisition_stop = dev_acquisition_stop,
41812aca 603 .context = NULL,
b908f067 604};