]>
Commit | Line | Data |
---|---|---|
3ba56876 | 1 | /* |
2 | * This file is part of the libsigrok project. | |
3 | * | |
4 | * Copyright (C) 2010-2012 Håvard Espeland <gus@ping.uio.no>, | |
5 | * Copyright (C) 2010 Martin Stensgård <mastensg@ping.uio.no> | |
6 | * Copyright (C) 2010 Carl Henrik Lunde <chlunde@ping.uio.no> | |
7 | * | |
8 | * This program is free software: you can redistribute it and/or modify | |
9 | * it under the terms of the GNU General Public License as published by | |
10 | * the Free Software Foundation, either version 3 of the License, or | |
11 | * (at your option) any later version. | |
12 | * | |
13 | * This program is distributed in the hope that it will be useful, | |
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
16 | * GNU General Public License for more details. | |
17 | * | |
18 | * You should have received a copy of the GNU General Public License | |
19 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | |
20 | */ | |
21 | ||
3ba56876 | 22 | #include <config.h> |
23 | #include "protocol.h" | |
24 | ||
3ba56876 | 25 | /* |
26 | * Channel numbers seem to go from 1-16, according to this image: | |
27 | * http://tools.asix.net/img/sigma_sigmacab_pins_720.jpg | |
28 | * (the cable has two additional GND pins, and a TI and TO pin) | |
29 | */ | |
30 | static const char *channel_names[] = { | |
31 | "1", "2", "3", "4", "5", "6", "7", "8", | |
32 | "9", "10", "11", "12", "13", "14", "15", "16", | |
33 | }; | |
34 | ||
53a939ab GS |
35 | static const uint32_t scanopts[] = { |
36 | SR_CONF_CONN, | |
37 | }; | |
38 | ||
3ba56876 | 39 | static const uint32_t drvopts[] = { |
40 | SR_CONF_LOGIC_ANALYZER, | |
41 | }; | |
42 | ||
43 | static const uint32_t devopts[] = { | |
44 | SR_CONF_LIMIT_MSEC | SR_CONF_GET | SR_CONF_SET, | |
2f7e529c | 45 | SR_CONF_LIMIT_SAMPLES | SR_CONF_GET | SR_CONF_SET, |
53a939ab | 46 | SR_CONF_CONN | SR_CONF_GET, |
3ba56876 | 47 | SR_CONF_SAMPLERATE | SR_CONF_GET | SR_CONF_SET | SR_CONF_LIST, |
de3f7acb | 48 | #if ASIX_SIGMA_WITH_TRIGGER |
3ba56876 | 49 | SR_CONF_TRIGGER_MATCH | SR_CONF_LIST, |
50 | SR_CONF_CAPTURE_RATIO | SR_CONF_GET | SR_CONF_SET, | |
de3f7acb | 51 | #endif |
3ba56876 | 52 | }; |
53 | ||
eac48b34 | 54 | #if ASIX_SIGMA_WITH_TRIGGER |
3ba56876 | 55 | static const int32_t trigger_matches[] = { |
56 | SR_TRIGGER_ZERO, | |
57 | SR_TRIGGER_ONE, | |
58 | SR_TRIGGER_RISING, | |
59 | SR_TRIGGER_FALLING, | |
60 | }; | |
eac48b34 | 61 | #endif |
3ba56876 | 62 | |
3553451f | 63 | static void clear_helper(struct dev_context *devc) |
53279f13 | 64 | { |
53279f13 UH |
65 | ftdi_deinit(&devc->ftdic); |
66 | } | |
67 | ||
3ba56876 | 68 | static int dev_clear(const struct sr_dev_driver *di) |
69 | { | |
9b4d261f GS |
70 | return std_dev_clear_with_callback(di, |
71 | (std_dev_clear_callback)clear_helper); | |
3ba56876 | 72 | } |
73 | ||
53a939ab | 74 | static gboolean bus_addr_in_devices(int bus, int addr, GSList *devs) |
3ba56876 | 75 | { |
53a939ab | 76 | struct sr_usb_dev_inst *usb; |
3ba56876 | 77 | |
53a939ab GS |
78 | for (/* EMPTY */; devs; devs = devs->next) { |
79 | usb = devs->data; | |
80 | if (usb->bus == bus && usb->address == addr) | |
81 | return TRUE; | |
82 | } | |
3ba56876 | 83 | |
53a939ab GS |
84 | return FALSE; |
85 | } | |
3ba56876 | 86 | |
53a939ab GS |
87 | static gboolean known_vid_pid(const struct libusb_device_descriptor *des) |
88 | { | |
9b4d261f GS |
89 | gboolean is_sigma, is_omega; |
90 | ||
53a939ab GS |
91 | if (des->idVendor != USB_VENDOR_ASIX) |
92 | return FALSE; | |
9b4d261f GS |
93 | is_sigma = des->idProduct == USB_PRODUCT_SIGMA; |
94 | is_omega = des->idProduct == USB_PRODUCT_OMEGA; | |
95 | if (!is_sigma && !is_omega) | |
53a939ab GS |
96 | return FALSE; |
97 | return TRUE; | |
98 | } | |
3ba56876 | 99 | |
53a939ab GS |
100 | static GSList *scan(struct sr_dev_driver *di, GSList *options) |
101 | { | |
102 | struct drv_context *drvc; | |
103 | libusb_context *usbctx; | |
104 | const char *conn; | |
105 | GSList *l, *conn_devices; | |
106 | struct sr_config *src; | |
107 | GSList *devices; | |
108 | libusb_device **devlist, *devitem; | |
109 | int bus, addr; | |
110 | struct libusb_device_descriptor des; | |
111 | struct libusb_device_handle *hdl; | |
112 | int ret; | |
113 | char conn_id[20]; | |
114 | char serno_txt[16]; | |
115 | char *end; | |
116 | long serno_num, serno_pre; | |
117 | enum asix_device_type dev_type; | |
118 | const char *dev_text; | |
119 | struct sr_dev_inst *sdi; | |
120 | struct dev_context *devc; | |
121 | size_t devidx, chidx; | |
122 | ||
123 | drvc = di->context; | |
124 | usbctx = drvc->sr_ctx->libusb_ctx; | |
125 | ||
126 | /* Find all devices which match an (optional) conn= spec. */ | |
127 | conn = NULL; | |
128 | for (l = options; l; l = l->next) { | |
129 | src = l->data; | |
130 | switch (src->key) { | |
131 | case SR_CONF_CONN: | |
132 | conn = g_variant_get_string(src->data, NULL); | |
133 | break; | |
134 | } | |
3ba56876 | 135 | } |
53a939ab GS |
136 | conn_devices = NULL; |
137 | if (conn) | |
138 | conn_devices = sr_usb_find(usbctx, conn); | |
139 | if (conn && !conn_devices) | |
140 | return NULL; | |
141 | ||
142 | /* Find all ASIX logic analyzers (which match the connection spec). */ | |
143 | devices = NULL; | |
144 | libusb_get_device_list(usbctx, &devlist); | |
145 | for (devidx = 0; devlist[devidx]; devidx++) { | |
146 | devitem = devlist[devidx]; | |
147 | ||
148 | /* Check for connection match if a user spec was given. */ | |
149 | bus = libusb_get_bus_number(devitem); | |
150 | addr = libusb_get_device_address(devitem); | |
151 | if (conn && !bus_addr_in_devices(bus, addr, conn_devices)) | |
152 | continue; | |
153 | snprintf(conn_id, sizeof(conn_id), "%d.%d", bus, addr); | |
154 | ||
155 | /* | |
156 | * Check for known VID:PID pairs. Get the serial number, | |
157 | * to then derive the device type from it. | |
158 | */ | |
159 | libusb_get_device_descriptor(devitem, &des); | |
160 | if (!known_vid_pid(&des)) | |
161 | continue; | |
162 | if (!des.iSerialNumber) { | |
163 | sr_warn("Cannot get serial number (index 0)."); | |
164 | continue; | |
165 | } | |
166 | ret = libusb_open(devitem, &hdl); | |
167 | if (ret < 0) { | |
168 | sr_warn("Cannot open USB device %04x.%04x: %s.", | |
169 | des.idVendor, des.idProduct, | |
170 | libusb_error_name(ret)); | |
171 | continue; | |
172 | } | |
173 | ret = libusb_get_string_descriptor_ascii(hdl, | |
174 | des.iSerialNumber, | |
175 | (unsigned char *)serno_txt, sizeof(serno_txt)); | |
176 | if (ret < 0) { | |
177 | sr_warn("Cannot get serial number (%s).", | |
178 | libusb_error_name(ret)); | |
179 | libusb_close(hdl); | |
180 | continue; | |
181 | } | |
182 | libusb_close(hdl); | |
183 | ||
184 | /* | |
185 | * All ASIX logic analyzers have a serial number, which | |
186 | * reads as a hex number, and tells the device type. | |
187 | */ | |
188 | ret = sr_atol_base(serno_txt, &serno_num, &end, 16); | |
189 | if (ret != SR_OK || !end || *end) { | |
190 | sr_warn("Cannot interpret serial number %s.", serno_txt); | |
191 | continue; | |
192 | } | |
193 | dev_type = ASIX_TYPE_NONE; | |
194 | dev_text = NULL; | |
195 | serno_pre = serno_num >> 16; | |
196 | switch (serno_pre) { | |
197 | case 0xa601: | |
198 | dev_type = ASIX_TYPE_SIGMA; | |
199 | dev_text = "SIGMA"; | |
200 | sr_info("Found SIGMA, serno %s.", serno_txt); | |
201 | break; | |
202 | case 0xa602: | |
203 | dev_type = ASIX_TYPE_SIGMA; | |
204 | dev_text = "SIGMA2"; | |
205 | sr_info("Found SIGMA2, serno %s.", serno_txt); | |
206 | break; | |
207 | case 0xa603: | |
208 | dev_type = ASIX_TYPE_OMEGA; | |
209 | dev_text = "OMEGA"; | |
210 | sr_info("Found OMEGA, serno %s.", serno_txt); | |
211 | if (!ASIX_WITH_OMEGA) { | |
212 | sr_warn("OMEGA support is not implemented yet."); | |
213 | continue; | |
214 | } | |
215 | break; | |
216 | default: | |
217 | sr_warn("Unknown serno %s, skipping.", serno_txt); | |
218 | continue; | |
219 | } | |
220 | ||
221 | /* Create a device instance, add it to the result set. */ | |
222 | ||
223 | sdi = g_malloc0(sizeof(*sdi)); | |
224 | devices = g_slist_append(devices, sdi); | |
225 | sdi->status = SR_ST_INITIALIZING; | |
226 | sdi->vendor = g_strdup("ASIX"); | |
227 | sdi->model = g_strdup(dev_text); | |
228 | sdi->serial_num = g_strdup(serno_txt); | |
229 | sdi->connection_id = g_strdup(conn_id); | |
230 | for (chidx = 0; chidx < ARRAY_SIZE(channel_names); chidx++) | |
231 | sr_channel_new(sdi, chidx, SR_CHANNEL_LOGIC, | |
232 | TRUE, channel_names[chidx]); | |
233 | ||
234 | devc = g_malloc0(sizeof(*devc)); | |
235 | sdi->priv = devc; | |
236 | devc->id.vid = des.idVendor; | |
237 | devc->id.pid = des.idProduct; | |
238 | devc->id.serno = serno_num; | |
239 | devc->id.prefix = serno_pre; | |
240 | devc->id.type = dev_type; | |
5e78a564 GS |
241 | devc->samplerate = samplerates[0]; |
242 | sr_sw_limits_init(&devc->cfg_limits); | |
80e717b3 | 243 | devc->firmware_idx = SIGMA_FW_NONE; |
53a939ab GS |
244 | devc->capture_ratio = 50; |
245 | devc->use_triggers = 0; | |
3ba56876 | 246 | } |
53a939ab GS |
247 | libusb_free_device_list(devlist, 1); |
248 | g_slist_free_full(conn_devices, (GDestroyNotify)sr_usb_dev_inst_free); | |
3ba56876 | 249 | |
53a939ab | 250 | return std_scan_complete(di, devices); |
3ba56876 | 251 | } |
252 | ||
3ba56876 | 253 | static int dev_open(struct sr_dev_inst *sdi) |
254 | { | |
255 | struct dev_context *devc; | |
53a939ab GS |
256 | long vid, pid; |
257 | const char *serno; | |
3ba56876 | 258 | int ret; |
259 | ||
260 | devc = sdi->priv; | |
261 | ||
53a939ab GS |
262 | if (devc->id.type == ASIX_TYPE_OMEGA && !ASIX_WITH_OMEGA) { |
263 | sr_err("OMEGA support is not implemented yet."); | |
264 | return SR_ERR_NA; | |
265 | } | |
266 | vid = devc->id.vid; | |
267 | pid = devc->id.pid; | |
268 | serno = sdi->serial_num; | |
269 | ||
270 | ret = ftdi_init(&devc->ftdic); | |
271 | if (ret < 0) { | |
272 | sr_err("Cannot initialize FTDI context (%d): %s.", | |
273 | ret, ftdi_get_error_string(&devc->ftdic)); | |
274 | return SR_ERR_IO; | |
275 | } | |
276 | ret = ftdi_usb_open_desc_index(&devc->ftdic, vid, pid, NULL, serno, 0); | |
277 | if (ret < 0) { | |
278 | sr_err("Cannot open device (%d): %s.", | |
279 | ret, ftdi_get_error_string(&devc->ftdic)); | |
280 | return SR_ERR_IO; | |
3ba56876 | 281 | } |
282 | ||
3ba56876 | 283 | return SR_OK; |
284 | } | |
285 | ||
286 | static int dev_close(struct sr_dev_inst *sdi) | |
287 | { | |
288 | struct dev_context *devc; | |
53a939ab | 289 | int ret; |
3ba56876 | 290 | |
291 | devc = sdi->priv; | |
292 | ||
53a939ab GS |
293 | ret = ftdi_usb_close(&devc->ftdic); |
294 | ftdi_deinit(&devc->ftdic); | |
295 | ||
296 | return (ret == 0) ? SR_OK : SR_ERR; | |
3ba56876 | 297 | } |
298 | ||
dd7a72ea UH |
299 | static int config_get(uint32_t key, GVariant **data, |
300 | const struct sr_dev_inst *sdi, const struct sr_channel_group *cg) | |
3ba56876 | 301 | { |
302 | struct dev_context *devc; | |
303 | ||
304 | (void)cg; | |
305 | ||
306 | if (!sdi) | |
307 | return SR_ERR; | |
308 | devc = sdi->priv; | |
309 | ||
310 | switch (key) { | |
53a939ab GS |
311 | case SR_CONF_CONN: |
312 | *data = g_variant_new_string(sdi->connection_id); | |
313 | break; | |
3ba56876 | 314 | case SR_CONF_SAMPLERATE: |
5e78a564 | 315 | *data = g_variant_new_uint64(devc->samplerate); |
3ba56876 | 316 | break; |
317 | case SR_CONF_LIMIT_MSEC: | |
2f7e529c | 318 | case SR_CONF_LIMIT_SAMPLES: |
5e78a564 | 319 | return sr_sw_limits_config_get(&devc->cfg_limits, key, data); |
de3f7acb | 320 | #if ASIX_SIGMA_WITH_TRIGGER |
3ba56876 | 321 | case SR_CONF_CAPTURE_RATIO: |
322 | *data = g_variant_new_uint64(devc->capture_ratio); | |
323 | break; | |
de3f7acb | 324 | #endif |
3ba56876 | 325 | default: |
326 | return SR_ERR_NA; | |
327 | } | |
328 | ||
329 | return SR_OK; | |
330 | } | |
331 | ||
dd7a72ea UH |
332 | static int config_set(uint32_t key, GVariant *data, |
333 | const struct sr_dev_inst *sdi, const struct sr_channel_group *cg) | |
3ba56876 | 334 | { |
335 | struct dev_context *devc; | |
5e78a564 GS |
336 | int ret; |
337 | uint64_t want_rate, have_rate; | |
3ba56876 | 338 | |
339 | (void)cg; | |
340 | ||
3ba56876 | 341 | devc = sdi->priv; |
342 | ||
3ba56876 | 343 | switch (key) { |
344 | case SR_CONF_SAMPLERATE: | |
5e78a564 GS |
345 | want_rate = g_variant_get_uint64(data); |
346 | ret = sigma_normalize_samplerate(want_rate, &have_rate); | |
347 | if (ret != SR_OK) | |
348 | return ret; | |
349 | if (have_rate != want_rate) { | |
350 | char *text_want, *text_have; | |
351 | text_want = sr_samplerate_string(want_rate); | |
352 | text_have = sr_samplerate_string(have_rate); | |
353 | sr_info("Adjusted samplerate %s to %s.", | |
354 | text_want, text_have); | |
355 | g_free(text_want); | |
356 | g_free(text_have); | |
357 | } | |
358 | devc->samplerate = have_rate; | |
3ba56876 | 359 | break; |
5e78a564 | 360 | case SR_CONF_LIMIT_MSEC: |
3ba56876 | 361 | case SR_CONF_LIMIT_SAMPLES: |
5e78a564 | 362 | return sr_sw_limits_config_set(&devc->cfg_limits, key, data); |
de3f7acb | 363 | #if ASIX_SIGMA_WITH_TRIGGER |
3ba56876 | 364 | case SR_CONF_CAPTURE_RATIO: |
efad7ccc | 365 | devc->capture_ratio = g_variant_get_uint64(data); |
3ba56876 | 366 | break; |
de3f7acb | 367 | #endif |
3ba56876 | 368 | default: |
758906aa | 369 | return SR_ERR_NA; |
3ba56876 | 370 | } |
371 | ||
758906aa | 372 | return SR_OK; |
3ba56876 | 373 | } |
374 | ||
dd7a72ea UH |
375 | static int config_list(uint32_t key, GVariant **data, |
376 | const struct sr_dev_inst *sdi, const struct sr_channel_group *cg) | |
3ba56876 | 377 | { |
3ba56876 | 378 | switch (key) { |
53a939ab | 379 | case SR_CONF_SCAN_OPTIONS: |
3ba56876 | 380 | case SR_CONF_DEVICE_OPTIONS: |
53a939ab GS |
381 | if (cg) |
382 | return SR_ERR_NA; | |
9b4d261f GS |
383 | return STD_CONFIG_LIST(key, data, sdi, cg, |
384 | scanopts, drvopts, devopts); | |
3ba56876 | 385 | case SR_CONF_SAMPLERATE: |
463160cb | 386 | *data = std_gvar_samplerates(samplerates, samplerates_count); |
3ba56876 | 387 | break; |
de3f7acb | 388 | #if ASIX_SIGMA_WITH_TRIGGER |
3ba56876 | 389 | case SR_CONF_TRIGGER_MATCH: |
53012da6 | 390 | *data = std_gvar_array_i32(ARRAY_AND_SIZE(trigger_matches)); |
3ba56876 | 391 | break; |
de3f7acb | 392 | #endif |
3ba56876 | 393 | default: |
394 | return SR_ERR_NA; | |
395 | } | |
396 | ||
397 | return SR_OK; | |
398 | } | |
399 | ||
695dc859 | 400 | static int dev_acquisition_start(const struct sr_dev_inst *sdi) |
3ba56876 | 401 | { |
402 | struct dev_context *devc; | |
403 | struct clockselect_50 clockselect; | |
8256ed15 | 404 | int triggerpin, ret; |
f06fb3e9 | 405 | uint8_t triggerselect; |
3ba56876 | 406 | struct triggerinout triggerinout_conf; |
407 | struct triggerlut lut; | |
22f64ed8 | 408 | uint8_t regval; |
8256ed15 GS |
409 | uint8_t clock_bytes[sizeof(clockselect)]; |
410 | size_t clock_idx; | |
3ba56876 | 411 | |
3ba56876 | 412 | devc = sdi->priv; |
413 | ||
5e78a564 GS |
414 | /* |
415 | * Setup the device's samplerate from the value which up to now | |
416 | * just got checked and stored. As a byproduct this can pick and | |
417 | * send firmware to the device, reduce the number of available | |
418 | * logic channels, etc. | |
419 | * | |
420 | * Determine an acquisition timeout from optionally configured | |
421 | * sample count or time limits. Which depends on the samplerate. | |
422 | */ | |
423 | ret = sigma_set_samplerate(sdi); | |
424 | if (ret != SR_OK) | |
425 | return ret; | |
426 | ret = sigma_set_acquire_timeout(devc); | |
427 | if (ret != SR_OK) | |
428 | return ret; | |
429 | ||
3ba56876 | 430 | if (sigma_convert_trigger(sdi) != SR_OK) { |
431 | sr_err("Failed to configure triggers."); | |
432 | return SR_ERR; | |
433 | } | |
434 | ||
3ba56876 | 435 | /* Enter trigger programming mode. */ |
9b4d261f | 436 | sigma_set_register(devc, WRITE_TRIGGER_SELECT2, 0x20); |
3ba56876 | 437 | |
f06fb3e9 | 438 | triggerselect = 0; |
5e78a564 | 439 | if (devc->samplerate >= SR_MHZ(100)) { |
f06fb3e9 | 440 | /* 100 and 200 MHz mode. */ |
9b4d261f | 441 | sigma_set_register(devc, WRITE_TRIGGER_SELECT2, 0x81); |
3ba56876 | 442 | |
443 | /* Find which pin to trigger on from mask. */ | |
9b4d261f GS |
444 | for (triggerpin = 0; triggerpin < 8; triggerpin++) { |
445 | if (devc->trigger.risingmask & (1 << triggerpin)) | |
446 | break; | |
447 | if (devc->trigger.fallingmask & (1 << triggerpin)) | |
3ba56876 | 448 | break; |
9b4d261f | 449 | } |
3ba56876 | 450 | |
451 | /* Set trigger pin and light LED on trigger. */ | |
452 | triggerselect = (1 << LEDSEL1) | (triggerpin & 0x7); | |
453 | ||
454 | /* Default rising edge. */ | |
455 | if (devc->trigger.fallingmask) | |
456 | triggerselect |= 1 << 3; | |
457 | ||
5e78a564 | 458 | } else if (devc->samplerate <= SR_MHZ(50)) { |
f06fb3e9 | 459 | /* All other modes. */ |
9b4d261f | 460 | sigma_build_basic_trigger(devc, &lut); |
3ba56876 | 461 | |
9b4d261f | 462 | sigma_write_trigger_lut(devc, &lut); |
3ba56876 | 463 | |
464 | triggerselect = (1 << LEDSEL1) | (1 << LEDSEL0); | |
465 | } | |
466 | ||
467 | /* Setup trigger in and out pins to default values. */ | |
468 | memset(&triggerinout_conf, 0, sizeof(struct triggerinout)); | |
469 | triggerinout_conf.trgout_bytrigger = 1; | |
470 | triggerinout_conf.trgout_enable = 1; | |
471 | ||
9b4d261f GS |
472 | sigma_write_register(devc, WRITE_TRIGGER_OPTION, |
473 | (uint8_t *)&triggerinout_conf, sizeof(struct triggerinout)); | |
3ba56876 | 474 | |
475 | /* Go back to normal mode. */ | |
9b4d261f | 476 | sigma_set_register(devc, WRITE_TRIGGER_SELECT2, triggerselect); |
3ba56876 | 477 | |
478 | /* Set clock select register. */ | |
8256ed15 GS |
479 | clockselect.async = 0; |
480 | clockselect.fraction = 1 - 1; /* Divider 1. */ | |
481 | clockselect.disabled_channels = 0x0000; /* All channels enabled. */ | |
5e78a564 | 482 | if (devc->samplerate == SR_MHZ(200)) { |
3ba56876 | 483 | /* Enable 4 channels. */ |
8256ed15 | 484 | clockselect.disabled_channels = 0xf0ff; |
5e78a564 | 485 | } else if (devc->samplerate == SR_MHZ(100)) { |
3ba56876 | 486 | /* Enable 8 channels. */ |
8256ed15 GS |
487 | clockselect.disabled_channels = 0x00ff; |
488 | } else { | |
3ba56876 | 489 | /* |
8256ed15 GS |
490 | * 50 MHz mode, or fraction thereof. The 50MHz reference |
491 | * can get divided by any integer in the range 1 to 256. | |
492 | * Divider minus 1 gets written to the hardware. | |
493 | * (The driver lists a discrete set of sample rates, but | |
494 | * all of them fit the above description.) | |
3ba56876 | 495 | */ |
5e78a564 | 496 | clockselect.fraction = SR_MHZ(50) / devc->samplerate - 1; |
3ba56876 | 497 | } |
8256ed15 GS |
498 | clock_idx = 0; |
499 | clock_bytes[clock_idx++] = clockselect.async; | |
500 | clock_bytes[clock_idx++] = clockselect.fraction; | |
501 | clock_bytes[clock_idx++] = clockselect.disabled_channels & 0xff; | |
502 | clock_bytes[clock_idx++] = clockselect.disabled_channels >> 8; | |
9b4d261f | 503 | sigma_write_register(devc, WRITE_CLOCK_SELECT, clock_bytes, clock_idx); |
3ba56876 | 504 | |
505 | /* Setup maximum post trigger time. */ | |
9b4d261f GS |
506 | sigma_set_register(devc, WRITE_POST_TRIGGER, |
507 | (devc->capture_ratio * 255) / 100); | |
3ba56876 | 508 | |
509 | /* Start acqusition. */ | |
9b4d261f | 510 | regval = WMR_TRGRES | WMR_SDRAMWRITEEN; |
22f64ed8 GS |
511 | #if ASIX_SIGMA_WITH_TRIGGER |
512 | regval |= WMR_TRGEN; | |
513 | #endif | |
9b4d261f | 514 | sigma_set_register(devc, WRITE_MODE, regval); |
3ba56876 | 515 | |
bee2b016 | 516 | std_session_send_df_header(sdi); |
3ba56876 | 517 | |
518 | /* Add capture source. */ | |
9b4d261f GS |
519 | sr_session_source_add(sdi->session, -1, 0, 10, |
520 | sigma_receive_data, (void *)sdi); | |
3ba56876 | 521 | |
522 | devc->state.state = SIGMA_CAPTURE; | |
523 | ||
524 | return SR_OK; | |
525 | } | |
526 | ||
695dc859 | 527 | static int dev_acquisition_stop(struct sr_dev_inst *sdi) |
3ba56876 | 528 | { |
529 | struct dev_context *devc; | |
530 | ||
3ba56876 | 531 | devc = sdi->priv; |
3ba56876 | 532 | |
dde0175d GS |
533 | /* |
534 | * When acquisition is currently running, keep the receive | |
535 | * routine registered and have it stop the acquisition upon the | |
536 | * next invocation. Else unregister the receive routine here | |
537 | * already. The detour is required to have sample data retrieved | |
538 | * for forced acquisition stops. | |
539 | */ | |
540 | if (devc->state.state == SIGMA_CAPTURE) { | |
541 | devc->state.state = SIGMA_STOPPING; | |
542 | } else { | |
543 | devc->state.state = SIGMA_IDLE; | |
544 | sr_session_source_remove(sdi->session, -1); | |
545 | } | |
3ba56876 | 546 | |
547 | return SR_OK; | |
548 | } | |
549 | ||
dd5c48a6 | 550 | static struct sr_dev_driver asix_sigma_driver_info = { |
3ba56876 | 551 | .name = "asix-sigma", |
552 | .longname = "ASIX SIGMA/SIGMA2", | |
553 | .api_version = 1, | |
c2fdcc25 | 554 | .init = std_init, |
700d6b64 | 555 | .cleanup = std_cleanup, |
3ba56876 | 556 | .scan = scan, |
c01bf34c | 557 | .dev_list = std_dev_list, |
3ba56876 | 558 | .dev_clear = dev_clear, |
559 | .config_get = config_get, | |
560 | .config_set = config_set, | |
561 | .config_list = config_list, | |
562 | .dev_open = dev_open, | |
563 | .dev_close = dev_close, | |
564 | .dev_acquisition_start = dev_acquisition_start, | |
565 | .dev_acquisition_stop = dev_acquisition_stop, | |
566 | .context = NULL, | |
567 | }; | |
dd5c48a6 | 568 | SR_REGISTER_DEV_DRIVER(asix_sigma_driver_info); |