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