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