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