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