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