]>
Commit | Line | Data |
---|---|---|
b908f067 UH |
1 | /* |
2 | * This file is part of the sigrok project. | |
3 | * | |
4 | * Copyright (C) 2011-2012 Uwe Hermann <uwe@hermann-uwe.de> | |
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 | ||
21 | #include <ftdi.h> | |
22 | #include <glib.h> | |
23 | #include <string.h> | |
45c59c8b BV |
24 | #include "libsigrok.h" |
25 | #include "libsigrok-internal.h" | |
45e080b6 | 26 | #include "protocol.h" |
b908f067 | 27 | |
765ef2f7 | 28 | SR_PRIV struct sr_dev_driver chronovu_la8_driver_info; |
f3a35908 | 29 | static struct sr_dev_driver *di = &chronovu_la8_driver_info; |
b908f067 | 30 | |
1bec72d2 BV |
31 | /* This will be initialized via config_list()/SR_CONF_SAMPLERATE. |
32 | * | |
33 | * Min: 1 sample per 0.01us -> sample time is 0.084s, samplerate 100MHz | |
34 | * Max: 1 sample per 2.55us -> sample time is 21.391s, samplerate 392.15kHz | |
35 | */ | |
36 | SR_PRIV uint64_t chronovu_la8_samplerates[255 + 1] = { 0 }; | |
37 | ||
38 | /* Note: Continuous sampling is not supported by the hardware. */ | |
39 | SR_PRIV const int32_t chronovu_la8_hwcaps[] = { | |
40 | SR_CONF_LOGIC_ANALYZER, | |
41 | SR_CONF_SAMPLERATE, | |
42 | SR_CONF_LIMIT_MSEC, /* TODO: Not yet implemented. */ | |
43 | SR_CONF_LIMIT_SAMPLES, /* TODO: Not yet implemented. */ | |
44 | }; | |
45 | ||
74e5f12d UH |
46 | /* |
47 | * The ChronoVu LA8 can have multiple PIDs. Older versions shipped with | |
48 | * a standard FTDI USB VID/PID of 0403:6001, newer ones have 0403:8867. | |
49 | */ | |
50 | static const uint16_t usb_pids[] = { | |
51 | 0x6001, | |
52 | 0x8867, | |
53 | }; | |
54 | ||
b908f067 | 55 | /* Function prototypes. */ |
69b07d14 | 56 | static int hw_dev_acquisition_stop(struct sr_dev_inst *sdi, void *cb_data); |
b908f067 | 57 | |
811deee4 | 58 | static int clear_instances(void) |
c4f3ed4b BV |
59 | { |
60 | GSList *l; | |
61 | struct sr_dev_inst *sdi; | |
1644fb24 BV |
62 | struct drv_context *drvc; |
63 | struct dev_context *devc; | |
64 | ||
f3a35908 | 65 | drvc = di->priv; |
c4f3ed4b BV |
66 | |
67 | /* Properly close all devices. */ | |
1644fb24 | 68 | for (l = drvc->instances; l; l = l->next) { |
c4f3ed4b BV |
69 | if (!(sdi = l->data)) { |
70 | /* Log error, but continue cleaning up the rest. */ | |
f3a35908 | 71 | sr_err("%s: sdi was NULL, continuing.", __func__); |
c4f3ed4b BV |
72 | continue; |
73 | } | |
74 | if (sdi->priv) { | |
1644fb24 BV |
75 | devc = sdi->priv; |
76 | ftdi_free(devc->ftdic); | |
c4f3ed4b BV |
77 | } |
78 | sr_dev_inst_free(sdi); | |
79 | } | |
1644fb24 BV |
80 | g_slist_free(drvc->instances); |
81 | drvc->instances = NULL; | |
c4f3ed4b | 82 | |
811deee4 | 83 | return SR_OK; |
c4f3ed4b BV |
84 | } |
85 | ||
34f06b90 | 86 | static int hw_init(struct sr_context *sr_ctx) |
61136ea6 | 87 | { |
063e7aef | 88 | return std_hw_init(sr_ctx, di, DRIVER_LOG_DOMAIN); |
61136ea6 BV |
89 | } |
90 | ||
c4f3ed4b | 91 | static GSList *hw_scan(GSList *options) |
b908f067 | 92 | { |
b908f067 | 93 | struct sr_dev_inst *sdi; |
87ca93c5 | 94 | struct sr_probe *probe; |
1644fb24 BV |
95 | struct drv_context *drvc; |
96 | struct dev_context *devc; | |
c4f3ed4b | 97 | GSList *devices; |
9c4311c5 BV |
98 | unsigned int i; |
99 | int ret; | |
c4f3ed4b BV |
100 | |
101 | (void)options; | |
f3a35908 UH |
102 | |
103 | drvc = di->priv; | |
4b97c74e | 104 | |
c4f3ed4b | 105 | devices = NULL; |
b908f067 | 106 | |
1644fb24 BV |
107 | /* Allocate memory for our private device context. */ |
108 | if (!(devc = g_try_malloc(sizeof(struct dev_context)))) { | |
f3a35908 | 109 | sr_err("Device context malloc failed."); |
b908f067 UH |
110 | goto err_free_nothing; |
111 | } | |
112 | ||
113 | /* Set some sane defaults. */ | |
1644fb24 BV |
114 | devc->ftdic = NULL; |
115 | devc->cur_samplerate = SR_MHZ(100); /* 100MHz == max. samplerate */ | |
116 | devc->limit_msec = 0; | |
117 | devc->limit_samples = 0; | |
3e9b7f9c | 118 | devc->cb_data = NULL; |
1644fb24 BV |
119 | memset(devc->mangled_buf, 0, BS); |
120 | devc->final_buf = NULL; | |
121 | devc->trigger_pattern = 0x00; /* Value irrelevant, see trigger_mask. */ | |
122 | devc->trigger_mask = 0x00; /* All probes are "don't care". */ | |
123 | devc->trigger_timeout = 10; /* Default to 10s trigger timeout. */ | |
124 | devc->trigger_found = 0; | |
125 | devc->done = 0; | |
126 | devc->block_counter = 0; | |
127 | devc->divcount = 0; /* 10ns sample period == 100MHz samplerate */ | |
128 | devc->usb_pid = 0; | |
b908f067 UH |
129 | |
130 | /* Allocate memory where we'll store the de-mangled data. */ | |
1644fb24 | 131 | if (!(devc->final_buf = g_try_malloc(SDRAM_SIZE))) { |
f3a35908 | 132 | sr_err("final_buf malloc failed."); |
1644fb24 | 133 | goto err_free_devc; |
b908f067 UH |
134 | } |
135 | ||
136 | /* Allocate memory for the FTDI context (ftdic) and initialize it. */ | |
1644fb24 | 137 | if (!(devc->ftdic = ftdi_new())) { |
f3a35908 | 138 | sr_err("%s: ftdi_new failed.", __func__); |
b908f067 UH |
139 | goto err_free_final_buf; |
140 | } | |
141 | ||
142 | /* Check for the device and temporarily open it. */ | |
74e5f12d | 143 | for (i = 0; i < ARRAY_SIZE(usb_pids); i++) { |
f3a35908 | 144 | sr_dbg("Probing for VID/PID %04x:%04x.", USB_VENDOR_ID, |
74e5f12d | 145 | usb_pids[i]); |
1644fb24 | 146 | ret = ftdi_usb_open_desc(devc->ftdic, USB_VENDOR_ID, |
74e5f12d UH |
147 | usb_pids[i], USB_DESCRIPTION, NULL); |
148 | if (ret == 0) { | |
f3a35908 | 149 | sr_dbg("Found LA8 device (%04x:%04x).", |
74e5f12d | 150 | USB_VENDOR_ID, usb_pids[i]); |
1644fb24 | 151 | devc->usb_pid = usb_pids[i]; |
74e5f12d | 152 | } |
b908f067 | 153 | } |
74e5f12d | 154 | |
1644fb24 | 155 | if (devc->usb_pid == 0) |
74e5f12d | 156 | goto err_free_ftdic; |
b908f067 UH |
157 | |
158 | /* Register the device with libsigrok. */ | |
159 | sdi = sr_dev_inst_new(0, SR_ST_INITIALIZING, | |
160 | USB_VENDOR_NAME, USB_MODEL_NAME, USB_MODEL_VERSION); | |
161 | if (!sdi) { | |
f3a35908 | 162 | sr_err("%s: sr_dev_inst_new failed.", __func__); |
b908f067 UH |
163 | goto err_close_ftdic; |
164 | } | |
f3a35908 | 165 | sdi->driver = di; |
1644fb24 | 166 | sdi->priv = devc; |
b908f067 | 167 | |
1bec72d2 | 168 | for (i = 0; chronovu_la8_probe_names[i]; i++) { |
de6e0eca | 169 | if (!(probe = sr_probe_new(i, SR_PROBE_LOGIC, TRUE, |
1bec72d2 | 170 | chronovu_la8_probe_names[i]))) |
87ca93c5 BV |
171 | return NULL; |
172 | sdi->probes = g_slist_append(sdi->probes, probe); | |
173 | } | |
174 | ||
c4f3ed4b | 175 | devices = g_slist_append(devices, sdi); |
1644fb24 | 176 | drvc->instances = g_slist_append(drvc->instances, sdi); |
b908f067 | 177 | |
b908f067 | 178 | /* Close device. We'll reopen it again when we need it. */ |
1644fb24 | 179 | (void) la8_close(devc); /* Log, but ignore errors. */ |
b908f067 | 180 | |
c4f3ed4b | 181 | return devices; |
b908f067 UH |
182 | |
183 | err_close_ftdic: | |
1644fb24 | 184 | (void) la8_close(devc); /* Log, but ignore errors. */ |
b908f067 | 185 | err_free_ftdic: |
4f9bf9a2 | 186 | ftdi_free(devc->ftdic); /* NOT free() or g_free()! */ |
b908f067 | 187 | err_free_final_buf: |
1644fb24 BV |
188 | g_free(devc->final_buf); |
189 | err_free_devc: | |
190 | g_free(devc); | |
b908f067 UH |
191 | err_free_nothing: |
192 | ||
c4f3ed4b | 193 | return NULL; |
b908f067 UH |
194 | } |
195 | ||
811deee4 BV |
196 | static GSList *hw_dev_list(void) |
197 | { | |
0e94d524 | 198 | return ((struct drv_context *)(di->priv))->instances; |
811deee4 BV |
199 | } |
200 | ||
25a0f108 | 201 | static int hw_dev_open(struct sr_dev_inst *sdi) |
b908f067 | 202 | { |
1644fb24 | 203 | struct dev_context *devc; |
25a0f108 | 204 | int ret; |
b908f067 | 205 | |
1644fb24 | 206 | if (!(devc = sdi->priv)) { |
f3a35908 | 207 | sr_err("%s: sdi->priv was NULL.", __func__); |
b908f067 UH |
208 | return SR_ERR_BUG; |
209 | } | |
210 | ||
f3a35908 | 211 | sr_dbg("Opening LA8 device (%04x:%04x).", USB_VENDOR_ID, |
1644fb24 | 212 | devc->usb_pid); |
b908f067 UH |
213 | |
214 | /* Open the device. */ | |
1644fb24 BV |
215 | if ((ret = ftdi_usb_open_desc(devc->ftdic, USB_VENDOR_ID, |
216 | devc->usb_pid, USB_DESCRIPTION, NULL)) < 0) { | |
f3a35908 | 217 | sr_err("%s: ftdi_usb_open_desc: (%d) %s", |
1644fb24 BV |
218 | __func__, ret, ftdi_get_error_string(devc->ftdic)); |
219 | (void) la8_close_usb_reset_sequencer(devc); /* Ignore errors. */ | |
b908f067 UH |
220 | return SR_ERR; |
221 | } | |
f3a35908 | 222 | sr_dbg("Device opened successfully."); |
b908f067 UH |
223 | |
224 | /* Purge RX/TX buffers in the FTDI chip. */ | |
1644fb24 | 225 | if ((ret = ftdi_usb_purge_buffers(devc->ftdic)) < 0) { |
f3a35908 | 226 | sr_err("%s: ftdi_usb_purge_buffers: (%d) %s", |
1644fb24 BV |
227 | __func__, ret, ftdi_get_error_string(devc->ftdic)); |
228 | (void) la8_close_usb_reset_sequencer(devc); /* Ignore errors. */ | |
b908f067 UH |
229 | goto err_dev_open_close_ftdic; |
230 | } | |
f3a35908 | 231 | sr_dbg("FTDI buffers purged successfully."); |
b908f067 UH |
232 | |
233 | /* Enable flow control in the FTDI chip. */ | |
1644fb24 | 234 | if ((ret = ftdi_setflowctrl(devc->ftdic, SIO_RTS_CTS_HS)) < 0) { |
f3a35908 | 235 | sr_err("%s: ftdi_setflowcontrol: (%d) %s", |
1644fb24 BV |
236 | __func__, ret, ftdi_get_error_string(devc->ftdic)); |
237 | (void) la8_close_usb_reset_sequencer(devc); /* Ignore errors. */ | |
b908f067 UH |
238 | goto err_dev_open_close_ftdic; |
239 | } | |
f3a35908 | 240 | sr_dbg("FTDI flow control enabled successfully."); |
b908f067 UH |
241 | |
242 | /* Wait 100ms. */ | |
243 | g_usleep(100 * 1000); | |
244 | ||
245 | sdi->status = SR_ST_ACTIVE; | |
246 | ||
247 | return SR_OK; | |
248 | ||
249 | err_dev_open_close_ftdic: | |
1644fb24 | 250 | (void) la8_close(devc); /* Log, but ignore errors. */ |
b908f067 UH |
251 | return SR_ERR; |
252 | } | |
253 | ||
25a0f108 | 254 | static int hw_dev_close(struct sr_dev_inst *sdi) |
b908f067 | 255 | { |
1644fb24 | 256 | struct dev_context *devc; |
b908f067 | 257 | |
961009b0 | 258 | devc = sdi->priv; |
b908f067 UH |
259 | |
260 | if (sdi->status == SR_ST_ACTIVE) { | |
f3a35908 | 261 | sr_dbg("Status ACTIVE, closing device."); |
1644fb24 | 262 | (void) la8_close_usb_reset_sequencer(devc); /* Ignore errors. */ |
b908f067 | 263 | } else { |
f3a35908 | 264 | sr_spew("Status not ACTIVE, nothing to do."); |
b908f067 UH |
265 | } |
266 | ||
267 | sdi->status = SR_ST_INACTIVE; | |
268 | ||
1644fb24 | 269 | g_free(devc->final_buf); |
b908f067 UH |
270 | |
271 | return SR_OK; | |
272 | } | |
273 | ||
274 | static int hw_cleanup(void) | |
275 | { | |
33e8a3c5 BV |
276 | if (!di->priv) |
277 | /* Can get called on an unused driver, doesn't matter. */ | |
278 | return SR_OK; | |
cf1ebd54 | 279 | |
c4f3ed4b | 280 | clear_instances(); |
b908f067 | 281 | |
c4f3ed4b | 282 | return SR_OK; |
b908f067 UH |
283 | } |
284 | ||
1bec72d2 | 285 | static int config_get(int id, GVariant **data, const struct sr_dev_inst *sdi) |
b908f067 | 286 | { |
1644fb24 | 287 | struct dev_context *devc; |
b908f067 | 288 | |
035a1078 | 289 | switch (id) { |
123e1313 | 290 | case SR_CONF_SAMPLERATE: |
6a2761fd | 291 | if (sdi) { |
1644fb24 | 292 | devc = sdi->priv; |
1bec72d2 | 293 | *data = g_variant_new_uint64(devc->cur_samplerate); |
f3a35908 | 294 | sr_spew("%s: Returning samplerate: %" PRIu64 "Hz.", |
1644fb24 | 295 | __func__, devc->cur_samplerate); |
6a2761fd BV |
296 | } else |
297 | return SR_ERR; | |
b908f067 | 298 | break; |
cfe8a84d | 299 | default: |
bd6fbf62 | 300 | return SR_ERR_NA; |
b908f067 UH |
301 | } |
302 | ||
6a2761fd | 303 | return SR_OK; |
b908f067 UH |
304 | } |
305 | ||
1bec72d2 | 306 | static int config_set(int id, GVariant *data, const struct sr_dev_inst *sdi) |
b908f067 | 307 | { |
1644fb24 | 308 | struct dev_context *devc; |
b908f067 | 309 | |
1644fb24 | 310 | if (!(devc = sdi->priv)) { |
f3a35908 | 311 | sr_err("%s: sdi->priv was NULL.", __func__); |
b908f067 UH |
312 | return SR_ERR_BUG; |
313 | } | |
314 | ||
035a1078 | 315 | switch (id) { |
1953564a | 316 | case SR_CONF_SAMPLERATE: |
1bec72d2 | 317 | if (set_samplerate(sdi, g_variant_get_uint64(data)) == SR_ERR) { |
f3a35908 | 318 | sr_err("%s: setting samplerate failed.", __func__); |
b908f067 UH |
319 | return SR_ERR; |
320 | } | |
f3a35908 | 321 | sr_dbg("SAMPLERATE = %" PRIu64, devc->cur_samplerate); |
b908f067 | 322 | break; |
1953564a | 323 | case SR_CONF_LIMIT_MSEC: |
1bec72d2 | 324 | if (g_variant_get_uint64(data) == 0) { |
f3a35908 | 325 | sr_err("%s: LIMIT_MSEC can't be 0.", __func__); |
b908f067 UH |
326 | return SR_ERR; |
327 | } | |
1bec72d2 | 328 | devc->limit_msec = g_variant_get_uint64(data); |
f3a35908 | 329 | sr_dbg("LIMIT_MSEC = %" PRIu64, devc->limit_msec); |
b908f067 | 330 | break; |
1953564a | 331 | case SR_CONF_LIMIT_SAMPLES: |
1bec72d2 | 332 | if (g_variant_get_uint64(data) < MIN_NUM_SAMPLES) { |
f3a35908 | 333 | sr_err("%s: LIMIT_SAMPLES too small.", __func__); |
b908f067 UH |
334 | return SR_ERR; |
335 | } | |
1bec72d2 | 336 | devc->limit_samples = g_variant_get_uint64(data); |
f3a35908 | 337 | sr_dbg("LIMIT_SAMPLES = %" PRIu64, devc->limit_samples); |
b908f067 UH |
338 | break; |
339 | default: | |
bd6fbf62 | 340 | return SR_ERR_NA; |
b908f067 UH |
341 | } |
342 | ||
343 | return SR_OK; | |
344 | } | |
345 | ||
1bec72d2 | 346 | static int config_list(int key, GVariant **data, const struct sr_dev_inst *sdi) |
a1c743fc | 347 | { |
1bec72d2 BV |
348 | GVariant *gvar; |
349 | GVariantBuilder gvb; | |
a1c743fc BV |
350 | |
351 | (void)sdi; | |
352 | ||
353 | switch (key) { | |
9a6517d1 | 354 | case SR_CONF_DEVICE_OPTIONS: |
1bec72d2 BV |
355 | *data = g_variant_new_fixed_array(G_VARIANT_TYPE_INT32, |
356 | chronovu_la8_hwcaps, ARRAY_SIZE(chronovu_la8_hwcaps), | |
357 | sizeof(int32_t)); | |
9a6517d1 | 358 | break; |
a1c743fc BV |
359 | case SR_CONF_SAMPLERATE: |
360 | fill_supported_samplerates_if_needed(); | |
1bec72d2 BV |
361 | g_variant_builder_init(&gvb, G_VARIANT_TYPE("a{sv}")); |
362 | gvar = g_variant_new_fixed_array(G_VARIANT_TYPE("t"), | |
363 | chronovu_la8_samplerates, ARRAY_SIZE(chronovu_la8_samplerates), | |
364 | sizeof(uint64_t)); | |
365 | g_variant_builder_add(&gvb, "{sv}", "samplerates", gvar); | |
366 | *data = g_variant_builder_end(&gvb); | |
a1c743fc | 367 | break; |
c50277a6 | 368 | case SR_CONF_TRIGGER_TYPE: |
1bec72d2 | 369 | *data = g_variant_new_string(TRIGGER_TYPE); |
c50277a6 | 370 | break; |
a1c743fc | 371 | default: |
bd6fbf62 | 372 | return SR_ERR_NA; |
a1c743fc BV |
373 | } |
374 | ||
375 | return SR_OK; | |
376 | } | |
377 | ||
b908f067 UH |
378 | static int receive_data(int fd, int revents, void *cb_data) |
379 | { | |
380 | int i, ret; | |
381 | struct sr_dev_inst *sdi; | |
1644fb24 | 382 | struct dev_context *devc; |
b908f067 | 383 | |
b908f067 UH |
384 | (void)fd; |
385 | (void)revents; | |
386 | ||
387 | if (!(sdi = cb_data)) { | |
f3a35908 | 388 | sr_err("%s: cb_data was NULL.", __func__); |
b908f067 UH |
389 | return FALSE; |
390 | } | |
391 | ||
1644fb24 | 392 | if (!(devc = sdi->priv)) { |
f3a35908 | 393 | sr_err("%s: sdi->priv was NULL.", __func__); |
b908f067 UH |
394 | return FALSE; |
395 | } | |
396 | ||
1644fb24 | 397 | if (!devc->ftdic) { |
f3a35908 | 398 | sr_err("%s: devc->ftdic was NULL.", __func__); |
b908f067 UH |
399 | return FALSE; |
400 | } | |
401 | ||
402 | /* Get one block of data. */ | |
1644fb24 | 403 | if ((ret = la8_read_block(devc)) < 0) { |
f3a35908 | 404 | sr_err("%s: la8_read_block error: %d.", __func__, ret); |
3ffb6964 | 405 | hw_dev_acquisition_stop(sdi, sdi); |
b908f067 UH |
406 | return FALSE; |
407 | } | |
408 | ||
409 | /* We need to get exactly NUM_BLOCKS blocks (i.e. 8MB) of data. */ | |
1644fb24 BV |
410 | if (devc->block_counter != (NUM_BLOCKS - 1)) { |
411 | devc->block_counter++; | |
b908f067 UH |
412 | return TRUE; |
413 | } | |
414 | ||
f3a35908 | 415 | sr_dbg("Sampling finished, sending data to session bus now."); |
b908f067 UH |
416 | |
417 | /* All data was received and demangled, send it to the session bus. */ | |
418 | for (i = 0; i < NUM_BLOCKS; i++) | |
1644fb24 | 419 | send_block_to_session_bus(devc, i); |
b908f067 | 420 | |
3ffb6964 | 421 | hw_dev_acquisition_stop(sdi, sdi); |
b908f067 | 422 | |
b908f067 UH |
423 | return TRUE; |
424 | } | |
425 | ||
3ffb6964 | 426 | static int hw_dev_acquisition_start(const struct sr_dev_inst *sdi, |
f3a35908 | 427 | void *cb_data) |
b908f067 | 428 | { |
1644fb24 | 429 | struct dev_context *devc; |
b908f067 UH |
430 | uint8_t buf[4]; |
431 | int bytes_written; | |
432 | ||
1644fb24 | 433 | if (!(devc = sdi->priv)) { |
f3a35908 | 434 | sr_err("%s: sdi->priv was NULL.", __func__); |
b908f067 UH |
435 | return SR_ERR_BUG; |
436 | } | |
437 | ||
1644fb24 | 438 | if (!devc->ftdic) { |
f3a35908 | 439 | sr_err("%s: devc->ftdic was NULL.", __func__); |
b908f067 UH |
440 | return SR_ERR_BUG; |
441 | } | |
442 | ||
1644fb24 BV |
443 | devc->divcount = samplerate_to_divcount(devc->cur_samplerate); |
444 | if (devc->divcount == 0xff) { | |
f3a35908 | 445 | sr_err("%s: Invalid divcount/samplerate.", __func__); |
b908f067 UH |
446 | return SR_ERR; |
447 | } | |
448 | ||
014359e3 | 449 | if (configure_probes(sdi) != SR_OK) { |
f3a35908 | 450 | sr_err("Failed to configure probes."); |
014359e3 BV |
451 | return SR_ERR; |
452 | } | |
453 | ||
b908f067 | 454 | /* Fill acquisition parameters into buf[]. */ |
1644fb24 | 455 | buf[0] = devc->divcount; |
b908f067 | 456 | buf[1] = 0xff; /* This byte must always be 0xff. */ |
1644fb24 BV |
457 | buf[2] = devc->trigger_pattern; |
458 | buf[3] = devc->trigger_mask; | |
b908f067 UH |
459 | |
460 | /* Start acquisition. */ | |
1644fb24 | 461 | bytes_written = la8_write(devc, buf, 4); |
b908f067 UH |
462 | |
463 | if (bytes_written < 0) { | |
f3a35908 | 464 | sr_err("Acquisition failed to start: %d.", bytes_written); |
b908f067 UH |
465 | return SR_ERR; |
466 | } else if (bytes_written != 4) { | |
f3a35908 | 467 | sr_err("Acquisition failed to start: %d.", bytes_written); |
afc88319 | 468 | return SR_ERR; |
b908f067 UH |
469 | } |
470 | ||
4afdfd46 | 471 | sr_dbg("Hardware acquisition started successfully."); |
b908f067 | 472 | |
3e9b7f9c | 473 | devc->cb_data = cb_data; |
b908f067 UH |
474 | |
475 | /* Send header packet to the session bus. */ | |
4afdfd46 | 476 | std_session_send_df_header(cb_data, DRIVER_LOG_DOMAIN); |
b908f067 | 477 | |
b908f067 | 478 | /* Time when we should be done (for detecting trigger timeouts). */ |
1644fb24 BV |
479 | devc->done = (devc->divcount + 1) * 0.08388608 + time(NULL) |
480 | + devc->trigger_timeout; | |
481 | devc->block_counter = 0; | |
482 | devc->trigger_found = 0; | |
b908f067 UH |
483 | |
484 | /* Hook up a dummy handler to receive data from the LA8. */ | |
3ffb6964 | 485 | sr_source_add(-1, G_IO_IN, 0, receive_data, (void *)sdi); |
b908f067 UH |
486 | |
487 | return SR_OK; | |
488 | } | |
489 | ||
69b07d14 | 490 | static int hw_dev_acquisition_stop(struct sr_dev_inst *sdi, void *cb_data) |
b908f067 | 491 | { |
b908f067 UH |
492 | struct sr_datafeed_packet packet; |
493 | ||
afc88319 | 494 | (void)sdi; |
b908f067 | 495 | |
f3a35908 | 496 | sr_dbg("Stopping acquisition."); |
7021f985 BV |
497 | sr_source_remove(-1); |
498 | ||
b908f067 | 499 | /* Send end packet to the session bus. */ |
f3a35908 | 500 | sr_dbg("Sending SR_DF_END."); |
b908f067 UH |
501 | packet.type = SR_DF_END; |
502 | sr_session_send(cb_data, &packet); | |
503 | ||
504 | return SR_OK; | |
505 | } | |
506 | ||
507 | SR_PRIV struct sr_dev_driver chronovu_la8_driver_info = { | |
508 | .name = "chronovu-la8", | |
509 | .longname = "ChronoVu LA8", | |
510 | .api_version = 1, | |
511 | .init = hw_init, | |
512 | .cleanup = hw_cleanup, | |
61136ea6 | 513 | .scan = hw_scan, |
811deee4 BV |
514 | .dev_list = hw_dev_list, |
515 | .dev_clear = clear_instances, | |
035a1078 BV |
516 | .config_get = config_get, |
517 | .config_set = config_set, | |
a1c743fc | 518 | .config_list = config_list, |
b908f067 UH |
519 | .dev_open = hw_dev_open, |
520 | .dev_close = hw_dev_close, | |
b908f067 UH |
521 | .dev_acquisition_start = hw_dev_acquisition_start, |
522 | .dev_acquisition_stop = hw_dev_acquisition_stop, | |
1644fb24 | 523 | .priv = NULL, |
b908f067 | 524 | }; |