]>
Commit | Line | Data |
---|---|---|
a1bb33af | 1 | /* |
50985c20 | 2 | * This file is part of the libsigrok project. |
a1bb33af | 3 | * |
c73d2ea4 | 4 | * Copyright (C) 2010-2012 Bert Vermeulen <bert@biot.com> |
a1bb33af 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 3 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, see <http://www.gnu.org/licenses/>. | |
18 | */ | |
19 | ||
6d116114 | 20 | #include "protocol.h" |
a1bb33af | 21 | |
8fdecced | 22 | #define VENDOR_NAME "ZEROPLUS" |
a1bb33af UH |
23 | #define USB_INTERFACE 0 |
24 | #define USB_CONFIGURATION 1 | |
25 | #define NUM_TRIGGER_STAGES 4 | |
c50277a6 | 26 | #define TRIGGER_TYPE "01" |
fed16f06 | 27 | #define PACKET_SIZE 2048 /* ?? */ |
a1bb33af | 28 | |
0ab0cb94 TY |
29 | //#define ZP_EXPERIMENTAL |
30 | ||
e495a676 UH |
31 | struct zp_model { |
32 | uint16_t vid; | |
33 | uint16_t pid; | |
428edbe1 | 34 | char *model_name; |
a1bb33af | 35 | unsigned int channels; |
fed16f06 | 36 | unsigned int sample_depth; /* In Ksamples/channel */ |
a1bb33af | 37 | unsigned int max_sampling_freq; |
e495a676 | 38 | }; |
a1bb33af | 39 | |
fed16f06 UH |
40 | /* |
41 | * Note -- 16032, 16064 and 16128 *usually* -- but not always -- have the | |
42 | * same 128K sample depth. | |
43 | */ | |
e495a676 | 44 | static const struct zp_model zeroplus_models[] = { |
9e5670d0 | 45 | {0x0c12, 0x7002, "LAP-16128U", 16, 128, 200}, |
428edbe1 | 46 | {0x0c12, 0x7009, "LAP-C(16064)", 16, 64, 100}, |
e495a676 UH |
47 | {0x0c12, 0x700a, "LAP-C(16128)", 16, 128, 200}, |
48 | /* TODO: We don't know anything about these. | |
49 | {0x0c12, 0x700b, "LAP-C(32128)", 32, 128, 200}, | |
50 | {0x0c12, 0x700c, "LAP-C(321000)", 32, 1024, 200}, | |
51 | {0x0c12, 0x700d, "LAP-C(322000)", 32, 2048, 200}, | |
3f848bb7 | 52 | */ |
e495a676 | 53 | {0x0c12, 0x700e, "LAP-C(16032)", 16, 32, 100}, |
428edbe1 BV |
54 | {0x0c12, 0x7016, "LAP-C(162000)", 16, 2048, 200}, |
55 | { 0, 0, 0, 0, 0, 0 } | |
a1bb33af UH |
56 | }; |
57 | ||
8386096f | 58 | static const int32_t hwcaps[] = { |
1953564a BV |
59 | SR_CONF_LOGIC_ANALYZER, |
60 | SR_CONF_SAMPLERATE, | |
61 | SR_CONF_CAPTURE_RATIO, | |
1953564a | 62 | SR_CONF_LIMIT_SAMPLES, |
a1bb33af UH |
63 | }; |
64 | ||
d261dbbf UH |
65 | /* |
66 | * ZEROPLUS LAP-C (16032) numbers the 16 probes A0-A7 and B0-B7. | |
67 | * We currently ignore other untested/unsupported devices here. | |
68 | */ | |
e495a676 | 69 | static const char *probe_names[] = { |
78693401 UH |
70 | "A0", "A1", "A2", "A3", "A4", "A5", "A6", "A7", |
71 | "B0", "B1", "B2", "B3", "B4", "B5", "B6", "B7", | |
464d12c7 KS |
72 | NULL, |
73 | }; | |
74 | ||
32756547 | 75 | SR_PRIV struct sr_dev_driver zeroplus_logic_cube_driver_info; |
a873c594 | 76 | static struct sr_dev_driver *di = &zeroplus_logic_cube_driver_info; |
a1bb33af | 77 | |
fed16f06 UH |
78 | /* |
79 | * The hardware supports more samplerates than these, but these are the | |
80 | * options hardcoded into the vendor's Windows GUI. | |
81 | */ | |
a1bb33af | 82 | |
8386096f | 83 | static const uint64_t samplerates_100[] = { |
17548571 UH |
84 | SR_HZ(100), |
85 | SR_HZ(500), | |
86 | SR_KHZ(1), | |
87 | SR_KHZ(5), | |
88 | SR_KHZ(25), | |
89 | SR_KHZ(50), | |
90 | SR_KHZ(100), | |
91 | SR_KHZ(200), | |
92 | SR_KHZ(400), | |
93 | SR_KHZ(800), | |
94 | SR_MHZ(1), | |
95 | SR_MHZ(10), | |
96 | SR_MHZ(25), | |
97 | SR_MHZ(50), | |
98 | SR_MHZ(80), | |
99 | SR_MHZ(100), | |
17548571 UH |
100 | }; |
101 | ||
8386096f | 102 | const uint64_t samplerates_200[] = { |
c9140419 UH |
103 | SR_HZ(100), |
104 | SR_HZ(500), | |
59df0c77 UH |
105 | SR_KHZ(1), |
106 | SR_KHZ(5), | |
107 | SR_KHZ(25), | |
108 | SR_KHZ(50), | |
109 | SR_KHZ(100), | |
110 | SR_KHZ(200), | |
111 | SR_KHZ(400), | |
112 | SR_KHZ(800), | |
113 | SR_MHZ(1), | |
114 | SR_MHZ(10), | |
115 | SR_MHZ(25), | |
116 | SR_MHZ(50), | |
117 | SR_MHZ(80), | |
118 | SR_MHZ(100), | |
119 | SR_MHZ(150), | |
120 | SR_MHZ(200), | |
bf43ea23 | 121 | }; |
a1bb33af | 122 | |
25a0f108 | 123 | static int hw_dev_close(struct sr_dev_inst *sdi); |
a1bb33af | 124 | |
0ab0cb94 | 125 | #if 0 |
014359e3 | 126 | static int configure_probes(const struct sr_dev_inst *sdi) |
a1bb33af | 127 | { |
310e9e9b | 128 | struct dev_context *devc; |
1b79df2f JH |
129 | const struct sr_probe *probe; |
130 | const GSList *l; | |
a1bb33af UH |
131 | int probe_bit, stage, i; |
132 | char *tc; | |
133 | ||
bf43ea23 | 134 | /* Note: sdi and sdi->priv are non-NULL, the caller checked this. */ |
310e9e9b | 135 | devc = sdi->priv; |
bf43ea23 | 136 | |
310e9e9b | 137 | devc->probe_mask = 0; |
fed16f06 | 138 | for (i = 0; i < NUM_TRIGGER_STAGES; i++) { |
310e9e9b BV |
139 | devc->trigger_mask[i] = 0; |
140 | devc->trigger_value[i] = 0; | |
a1bb33af UH |
141 | } |
142 | ||
143 | stage = -1; | |
014359e3 | 144 | for (l = sdi->probes; l; l = l->next) { |
1afe8989 | 145 | probe = (struct sr_probe *)l->data; |
fed16f06 | 146 | if (probe->enabled == FALSE) |
a1bb33af | 147 | continue; |
b35c8293 | 148 | probe_bit = 1 << (probe->index); |
310e9e9b | 149 | devc->probe_mask |= probe_bit; |
fed16f06 UH |
150 | |
151 | if (probe->trigger) { | |
a1bb33af | 152 | stage = 0; |
fed16f06 | 153 | for (tc = probe->trigger; *tc; tc++) { |
310e9e9b | 154 | devc->trigger_mask[stage] |= probe_bit; |
fed16f06 | 155 | if (*tc == '1') |
310e9e9b | 156 | devc->trigger_value[stage] |= probe_bit; |
a1bb33af | 157 | stage++; |
fed16f06 | 158 | if (stage > NUM_TRIGGER_STAGES) |
e46b8fb1 | 159 | return SR_ERR; |
a1bb33af UH |
160 | } |
161 | } | |
162 | } | |
163 | ||
e46b8fb1 | 164 | return SR_OK; |
a1bb33af | 165 | } |
0ab0cb94 TY |
166 | #endif |
167 | ||
168 | static int configure_probes(const struct sr_dev_inst *sdi) | |
169 | { | |
170 | struct dev_context *devc; | |
171 | const GSList *l; | |
172 | const struct sr_probe *probe; | |
173 | char *tc; | |
174 | int type; | |
175 | ||
176 | /* Note: sdi and sdi->priv are non-NULL, the caller checked this. */ | |
177 | devc = sdi->priv; | |
178 | ||
179 | for (l = sdi->probes; l; l = l->next) { | |
180 | probe = (struct sr_probe *)l->data; | |
181 | if (probe->enabled == FALSE) | |
182 | continue; | |
183 | ||
184 | if ((tc = probe->trigger)) { | |
185 | switch (*tc) { | |
186 | case '1': | |
187 | type = TRIGGER_HIGH; | |
188 | break; | |
189 | case '0': | |
190 | type = TRIGGER_LOW; | |
191 | break; | |
192 | #if 0 | |
193 | case 'r': | |
194 | type = TRIGGER_POSEDGE; | |
195 | break; | |
196 | case 'f': | |
197 | type = TRIGGER_NEGEDGE; | |
198 | break; | |
199 | case 'c': | |
200 | type = TRIGGER_ANYEDGE; | |
201 | break; | |
202 | #endif | |
203 | default: | |
204 | return SR_ERR; | |
205 | } | |
206 | analyzer_add_trigger(probe->index, type); | |
207 | devc->trigger = 1; | |
208 | } | |
209 | } | |
210 | ||
211 | return SR_OK; | |
212 | } | |
a1bb33af | 213 | |
3316e149 BV |
214 | SR_PRIV int zp_set_samplerate(struct dev_context *devc, uint64_t samplerate) |
215 | { | |
216 | int i; | |
217 | ||
218 | for (i = 0; ARRAY_SIZE(samplerates_200); i++) | |
219 | if (samplerate == samplerates_200[i]) | |
220 | break; | |
221 | ||
222 | if (i == ARRAY_SIZE(samplerates_200) || samplerate > devc->max_samplerate) { | |
223 | sr_err("Unsupported samplerate: %" PRIu64 "Hz.", samplerate); | |
224 | return SR_ERR_ARG; | |
225 | } | |
226 | ||
227 | sr_info("Setting samplerate to %" PRIu64 "Hz.", samplerate); | |
228 | ||
229 | if (samplerate >= SR_MHZ(1)) | |
230 | analyzer_set_freq(samplerate / SR_MHZ(1), FREQ_SCALE_MHZ); | |
231 | else if (samplerate >= SR_KHZ(1)) | |
232 | analyzer_set_freq(samplerate / SR_KHZ(1), FREQ_SCALE_KHZ); | |
233 | else | |
234 | analyzer_set_freq(samplerate, FREQ_SCALE_HZ); | |
235 | ||
236 | devc->cur_samplerate = samplerate; | |
237 | ||
238 | return SR_OK; | |
239 | } | |
240 | ||
811deee4 | 241 | static int clear_instances(void) |
7da6f9d5 BV |
242 | { |
243 | GSList *l; | |
244 | struct sr_dev_inst *sdi; | |
310e9e9b | 245 | struct drv_context *drvc; |
fabe59b3 | 246 | struct dev_context *devc; |
609bfd75 | 247 | struct sr_usb_dev_inst *usb; |
7da6f9d5 | 248 | |
a873c594 | 249 | drvc = di->priv; |
310e9e9b | 250 | for (l = drvc->instances; l; l = l->next) { |
7da6f9d5 | 251 | sdi = l->data; |
fabe59b3 BV |
252 | if (!(devc = sdi->priv)) { |
253 | /* Log error, but continue cleaning up the rest. */ | |
6d116114 | 254 | sr_err("%s: sdi->priv was NULL, continuing", __func__); |
fabe59b3 BV |
255 | continue; |
256 | } | |
609bfd75 BV |
257 | usb = sdi->conn; |
258 | sr_usb_dev_inst_free(usb); | |
7da6f9d5 | 259 | /* Properly close all devices... */ |
25a0f108 | 260 | hw_dev_close(sdi); |
7da6f9d5 BV |
261 | /* ...and free all their memory. */ |
262 | sr_dev_inst_free(sdi); | |
263 | } | |
310e9e9b BV |
264 | g_slist_free(drvc->instances); |
265 | drvc->instances = NULL; | |
7da6f9d5 | 266 | |
811deee4 | 267 | return SR_OK; |
7da6f9d5 BV |
268 | } |
269 | ||
34f06b90 | 270 | static int hw_init(struct sr_context *sr_ctx) |
61136ea6 | 271 | { |
063e7aef | 272 | return std_hw_init(sr_ctx, di, "zeroplus: "); |
61136ea6 BV |
273 | } |
274 | ||
4ca38984 | 275 | static GSList *hw_scan(GSList *options) |
a1bb33af | 276 | { |
d68e2d1a | 277 | struct sr_dev_inst *sdi; |
428edbe1 | 278 | struct sr_probe *probe; |
310e9e9b BV |
279 | struct drv_context *drvc; |
280 | struct dev_context *devc; | |
e495a676 | 281 | const struct zp_model *prof; |
a1bb33af UH |
282 | struct libusb_device_descriptor des; |
283 | libusb_device **devlist; | |
428edbe1 BV |
284 | GSList *devices; |
285 | int ret, devcnt, i, j; | |
a1bb33af | 286 | |
4ca38984 | 287 | (void)options; |
64d33dc2 | 288 | |
a873c594 | 289 | drvc = di->priv; |
4b97c74e | 290 | |
4ca38984 BV |
291 | devices = NULL; |
292 | ||
8fdecced | 293 | /* Find all ZEROPLUS analyzers and add them to device list. */ |
a1bb33af | 294 | devcnt = 0; |
d4abb463 | 295 | libusb_get_device_list(drvc->sr_ctx->libusb_ctx, &devlist); /* TODO: Errors. */ |
fed16f06 UH |
296 | |
297 | for (i = 0; devlist[i]; i++) { | |
ebc34738 UH |
298 | ret = libusb_get_device_descriptor(devlist[i], &des); |
299 | if (ret != 0) { | |
6d116114 | 300 | sr_err("Failed to get device descriptor: %s.", |
d4928d71 | 301 | libusb_error_name(ret)); |
a1bb33af UH |
302 | continue; |
303 | } | |
304 | ||
428edbe1 BV |
305 | prof = NULL; |
306 | for (j = 0; j < zeroplus_models[j].vid; j++) { | |
307 | if (des.idVendor == zeroplus_models[j].vid && | |
308 | des.idProduct == zeroplus_models[j].pid) { | |
309 | prof = &zeroplus_models[j]; | |
bf43ea23 | 310 | } |
a1bb33af | 311 | } |
e495a676 | 312 | /* Skip if the device was not found. */ |
428edbe1 BV |
313 | if (!prof) |
314 | continue; | |
e495a676 | 315 | sr_info("Found ZEROPLUS %s.", prof->model_name); |
428edbe1 BV |
316 | |
317 | /* Register the device with libsigrok. */ | |
318 | if (!(sdi = sr_dev_inst_new(devcnt, SR_ST_INACTIVE, | |
319 | VENDOR_NAME, prof->model_name, NULL))) { | |
6d116114 | 320 | sr_err("%s: sr_dev_inst_new failed", __func__); |
428edbe1 BV |
321 | return NULL; |
322 | } | |
a873c594 | 323 | sdi->driver = di; |
428edbe1 BV |
324 | |
325 | /* Allocate memory for our private driver context. */ | |
310e9e9b | 326 | if (!(devc = g_try_malloc0(sizeof(struct dev_context)))) { |
6d116114 | 327 | sr_err("Device context malloc failed."); |
886a52b6 | 328 | return NULL; |
428edbe1 | 329 | } |
e495a676 | 330 | |
310e9e9b | 331 | sdi->priv = devc; |
17548571 | 332 | devc->prof = prof; |
310e9e9b | 333 | devc->num_channels = prof->channels; |
0ab0cb94 TY |
334 | #ifdef ZP_EXPERIMENTAL |
335 | devc->max_memory_size = 128 * 1024; | |
336 | devc->max_samplerate = 200; | |
337 | #else | |
338 | devc->max_memory_size = prof->sample_depth * 1024; | |
339 | devc->max_samplerate = prof->max_sampling_freq; | |
340 | #endif | |
341 | devc->max_samplerate *= SR_MHZ(1); | |
342 | devc->memory_size = MEMORY_SIZE_8K; | |
310e9e9b | 343 | // memset(devc->trigger_buffer, 0, NUM_TRIGGER_STAGES); |
428edbe1 BV |
344 | |
345 | /* Fill in probelist according to this device's profile. */ | |
310e9e9b | 346 | for (j = 0; j < devc->num_channels; j++) { |
428edbe1 BV |
347 | if (!(probe = sr_probe_new(j, SR_PROBE_LOGIC, TRUE, |
348 | probe_names[j]))) | |
349 | return NULL; | |
350 | sdi->probes = g_slist_append(sdi->probes, probe); | |
351 | } | |
352 | ||
353 | devices = g_slist_append(devices, sdi); | |
310e9e9b | 354 | drvc->instances = g_slist_append(drvc->instances, sdi); |
609bfd75 | 355 | sdi->conn = sr_usb_dev_inst_new( |
428edbe1 BV |
356 | libusb_get_bus_number(devlist[i]), |
357 | libusb_get_device_address(devlist[i]), NULL); | |
358 | devcnt++; | |
359 | ||
a1bb33af UH |
360 | } |
361 | libusb_free_device_list(devlist, 1); | |
362 | ||
4ca38984 | 363 | return devices; |
a1bb33af UH |
364 | } |
365 | ||
811deee4 BV |
366 | static GSList *hw_dev_list(void) |
367 | { | |
0e94d524 | 368 | return ((struct drv_context *)(di->priv))->instances; |
811deee4 BV |
369 | } |
370 | ||
25a0f108 | 371 | static int hw_dev_open(struct sr_dev_inst *sdi) |
a1bb33af | 372 | { |
310e9e9b | 373 | struct dev_context *devc; |
e495a676 | 374 | struct drv_context *drvc; |
609bfd75 | 375 | struct sr_usb_dev_inst *usb; |
428edbe1 BV |
376 | libusb_device **devlist, *dev; |
377 | struct libusb_device_descriptor des; | |
378 | int device_count, ret, i; | |
a1bb33af | 379 | |
e495a676 | 380 | drvc = di->priv; |
609bfd75 | 381 | usb = sdi->conn; |
e495a676 | 382 | |
310e9e9b | 383 | if (!(devc = sdi->priv)) { |
6d116114 | 384 | sr_err("%s: sdi->priv was NULL", __func__); |
bf43ea23 UH |
385 | return SR_ERR_ARG; |
386 | } | |
387 | ||
d4abb463 PS |
388 | device_count = libusb_get_device_list(drvc->sr_ctx->libusb_ctx, |
389 | &devlist); | |
428edbe1 | 390 | if (device_count < 0) { |
6d116114 | 391 | sr_err("Failed to retrieve device list."); |
428edbe1 BV |
392 | return SR_ERR; |
393 | } | |
394 | ||
395 | dev = NULL; | |
396 | for (i = 0; i < device_count; i++) { | |
397 | if ((ret = libusb_get_device_descriptor(devlist[i], &des))) { | |
6d116114 | 398 | sr_err("Failed to get device descriptor: %s.", |
d4928d71 | 399 | libusb_error_name(ret)); |
428edbe1 BV |
400 | continue; |
401 | } | |
609bfd75 BV |
402 | if (libusb_get_bus_number(devlist[i]) == usb->bus |
403 | && libusb_get_device_address(devlist[i]) == usb->address) { | |
428edbe1 BV |
404 | dev = devlist[i]; |
405 | break; | |
406 | } | |
407 | } | |
408 | if (!dev) { | |
6d116114 | 409 | sr_err("Device on bus %d address %d disappeared!", |
609bfd75 | 410 | usb->bus, usb->address); |
428edbe1 BV |
411 | return SR_ERR; |
412 | } | |
413 | ||
609bfd75 | 414 | if (!(ret = libusb_open(dev, &(usb->devhdl)))) { |
428edbe1 | 415 | sdi->status = SR_ST_ACTIVE; |
6d116114 | 416 | sr_info("Opened device %d on %d.%d interface %d.", |
609bfd75 | 417 | sdi->index, usb->bus, usb->address, USB_INTERFACE); |
428edbe1 | 418 | } else { |
6d116114 | 419 | sr_err("Failed to open device: %s.", libusb_error_name(ret)); |
428edbe1 BV |
420 | return SR_ERR; |
421 | } | |
422 | ||
609bfd75 | 423 | ret = libusb_set_configuration(usb->devhdl, USB_CONFIGURATION); |
ebc34738 | 424 | if (ret < 0) { |
6d116114 | 425 | sr_err("Unable to set USB configuration %d: %s.", |
d4928d71 | 426 | USB_CONFIGURATION, libusb_error_name(ret)); |
185ae2c5 UH |
427 | return SR_ERR; |
428 | } | |
429 | ||
609bfd75 | 430 | ret = libusb_claim_interface(usb->devhdl, USB_INTERFACE); |
ebc34738 | 431 | if (ret != 0) { |
6d116114 | 432 | sr_err("Unable to claim interface: %s.", |
d4928d71 | 433 | libusb_error_name(ret)); |
e46b8fb1 | 434 | return SR_ERR; |
a1bb33af | 435 | } |
185ae2c5 | 436 | |
e495a676 | 437 | /* Set default configuration after power on. */ |
609bfd75 BV |
438 | if (analyzer_read_status(usb->devhdl) == 0) |
439 | analyzer_configure(usb->devhdl); | |
0ab0cb94 | 440 | |
609bfd75 BV |
441 | analyzer_reset(usb->devhdl); |
442 | analyzer_initialize(usb->devhdl); | |
a1bb33af | 443 | |
0ab0cb94 | 444 | //analyzer_set_memory_size(MEMORY_SIZE_512K); |
fed16f06 | 445 | // analyzer_set_freq(g_freq, g_freq_scale); |
a1bb33af | 446 | analyzer_set_trigger_count(1); |
408e7199 UH |
447 | // analyzer_set_ramsize_trigger_address((((100 - g_pre_trigger) |
448 | // * get_memory_size(g_memory_size)) / 100) >> 2); | |
a1bb33af | 449 | |
fed16f06 UH |
450 | #if 0 |
451 | if (g_double_mode == 1) | |
a1bb33af UH |
452 | analyzer_set_compression(COMPRESSION_DOUBLE); |
453 | else if (g_compression == 1) | |
454 | analyzer_set_compression(COMPRESSION_ENABLE); | |
fed16f06 UH |
455 | else |
456 | #endif | |
457 | analyzer_set_compression(COMPRESSION_NONE); | |
a1bb33af | 458 | |
310e9e9b | 459 | if (devc->cur_samplerate == 0) { |
0ab0cb94 TY |
460 | /* Samplerate hasn't been set. Default to 1MHz. */ |
461 | analyzer_set_freq(1, FREQ_SCALE_MHZ); | |
462 | devc->cur_samplerate = SR_MHZ(1); | |
a1bb33af UH |
463 | } |
464 | ||
e46b8fb1 | 465 | return SR_OK; |
a1bb33af UH |
466 | } |
467 | ||
25a0f108 | 468 | static int hw_dev_close(struct sr_dev_inst *sdi) |
a1bb33af | 469 | { |
609bfd75 | 470 | struct sr_usb_dev_inst *usb; |
a1bb33af | 471 | |
609bfd75 | 472 | usb = sdi->conn; |
697785d1 | 473 | |
609bfd75 | 474 | if (!usb->devhdl) |
25a0f108 BV |
475 | return SR_ERR; |
476 | ||
6d116114 | 477 | sr_info("Closing device %d on %d.%d interface %d.", sdi->index, |
609bfd75 BV |
478 | usb->bus, usb->address, USB_INTERFACE); |
479 | libusb_release_interface(usb->devhdl, USB_INTERFACE); | |
480 | libusb_reset_device(usb->devhdl); | |
481 | libusb_close(usb->devhdl); | |
482 | usb->devhdl = NULL; | |
25a0f108 | 483 | sdi->status = SR_ST_INACTIVE; |
697785d1 UH |
484 | |
485 | return SR_OK; | |
a1bb33af UH |
486 | } |
487 | ||
57ab7d9f | 488 | static int hw_cleanup(void) |
a1bb33af | 489 | { |
310e9e9b BV |
490 | struct drv_context *drvc; |
491 | ||
a873c594 | 492 | if (!(drvc = di->priv)) |
310e9e9b | 493 | return SR_OK; |
a1bb33af | 494 | |
7da6f9d5 | 495 | clear_instances(); |
a1bb33af | 496 | |
57ab7d9f | 497 | return SR_OK; |
a1bb33af UH |
498 | } |
499 | ||
8386096f | 500 | static int config_get(int id, GVariant **data, const struct sr_dev_inst *sdi) |
a1bb33af | 501 | { |
310e9e9b | 502 | struct dev_context *devc; |
a1bb33af | 503 | |
035a1078 | 504 | switch (id) { |
123e1313 | 505 | case SR_CONF_SAMPLERATE: |
626409ab | 506 | if (sdi) { |
310e9e9b | 507 | devc = sdi->priv; |
8386096f | 508 | *data = g_variant_new_uint64(devc->cur_samplerate); |
6d116114 UH |
509 | sr_spew("Returning samplerate: %" PRIu64 "Hz.", |
510 | devc->cur_samplerate); | |
626409ab BV |
511 | } else |
512 | return SR_ERR; | |
bf43ea23 UH |
513 | break; |
514 | default: | |
bd6fbf62 | 515 | return SR_ERR_NA; |
a1bb33af UH |
516 | } |
517 | ||
626409ab | 518 | return SR_OK; |
a1bb33af UH |
519 | } |
520 | ||
8386096f | 521 | static int config_set(int id, GVariant *data, const struct sr_dev_inst *sdi) |
a1bb33af | 522 | { |
310e9e9b | 523 | struct dev_context *devc; |
a1bb33af | 524 | |
e73ffd42 BV |
525 | if (sdi->status != SR_ST_ACTIVE) |
526 | return SR_ERR_DEV_CLOSED; | |
0ab0cb94 | 527 | |
310e9e9b | 528 | if (!(devc = sdi->priv)) { |
6d116114 | 529 | sr_err("%s: sdi->priv was NULL", __func__); |
bf43ea23 UH |
530 | return SR_ERR_ARG; |
531 | } | |
a1bb33af | 532 | |
035a1078 | 533 | switch (id) { |
1953564a | 534 | case SR_CONF_SAMPLERATE: |
8386096f | 535 | return zp_set_samplerate(devc, g_variant_get_uint64(data)); |
1953564a | 536 | case SR_CONF_LIMIT_SAMPLES: |
8386096f | 537 | return set_limit_samples(devc, g_variant_get_uint64(data)); |
1953564a | 538 | case SR_CONF_CAPTURE_RATIO: |
8386096f | 539 | return set_capture_ratio(devc, g_variant_get_uint64(data)); |
fed16f06 | 540 | default: |
bd6fbf62 | 541 | return SR_ERR_NA; |
a1bb33af | 542 | } |
e495a676 UH |
543 | |
544 | return SR_OK; | |
a1bb33af UH |
545 | } |
546 | ||
8386096f | 547 | static int config_list(int key, GVariant **data, const struct sr_dev_inst *sdi) |
a1c743fc | 548 | { |
17548571 | 549 | struct dev_context *devc; |
8386096f BV |
550 | GVariant *gvar; |
551 | GVariantBuilder gvb; | |
a1c743fc BV |
552 | |
553 | switch (key) { | |
9a6517d1 | 554 | case SR_CONF_DEVICE_OPTIONS: |
8386096f BV |
555 | *data = g_variant_new_fixed_array(G_VARIANT_TYPE_INT32, |
556 | hwcaps, ARRAY_SIZE(hwcaps), sizeof(int32_t)); | |
9a6517d1 | 557 | break; |
a1c743fc | 558 | case SR_CONF_SAMPLERATE: |
17548571 | 559 | devc = sdi->priv; |
8386096f | 560 | g_variant_builder_init(&gvb, G_VARIANT_TYPE("a{sv}")); |
17548571 | 561 | if (devc->prof->max_sampling_freq == 100) { |
8386096f BV |
562 | gvar = g_variant_new_fixed_array(G_VARIANT_TYPE("t"), |
563 | samplerates_100, ARRAY_SIZE(samplerates_100), | |
564 | sizeof(uint64_t)); | |
17548571 | 565 | } else if (devc->prof->max_sampling_freq == 200) { |
8386096f BV |
566 | gvar = g_variant_new_fixed_array(G_VARIANT_TYPE("t"), |
567 | samplerates_200, ARRAY_SIZE(samplerates_200), | |
568 | sizeof(uint64_t)); | |
17548571 UH |
569 | } else { |
570 | sr_err("Internal error: Unknown max. samplerate: %d.", | |
571 | devc->prof->max_sampling_freq); | |
572 | return SR_ERR_ARG; | |
573 | } | |
8386096f BV |
574 | g_variant_builder_add(&gvb, "{sv}", "samplerates", gvar); |
575 | *data = g_variant_builder_end(&gvb); | |
a1c743fc | 576 | break; |
c50277a6 | 577 | case SR_CONF_TRIGGER_TYPE: |
8386096f | 578 | *data = g_variant_new_string(TRIGGER_TYPE); |
c50277a6 | 579 | break; |
a1c743fc | 580 | default: |
bd6fbf62 | 581 | return SR_ERR_NA; |
a1c743fc BV |
582 | } |
583 | ||
584 | return SR_OK; | |
585 | } | |
586 | ||
3ffb6964 BV |
587 | static int hw_dev_acquisition_start(const struct sr_dev_inst *sdi, |
588 | void *cb_data) | |
a1bb33af | 589 | { |
609bfd75 BV |
590 | struct dev_context *devc; |
591 | struct sr_usb_dev_inst *usb; | |
b9c735a2 | 592 | struct sr_datafeed_packet packet; |
9c939c51 | 593 | struct sr_datafeed_logic logic; |
0ab0cb94 | 594 | //uint64_t samples_read; |
a1bb33af | 595 | int res; |
e495a676 | 596 | unsigned int packet_num, n; |
a1bb33af UH |
597 | unsigned char *buf; |
598 | ||
e73ffd42 BV |
599 | if (sdi->status != SR_ST_ACTIVE) |
600 | return SR_ERR_DEV_CLOSED; | |
601 | ||
310e9e9b | 602 | if (!(devc = sdi->priv)) { |
6d116114 | 603 | sr_err("%s: sdi->priv was NULL", __func__); |
bf43ea23 UH |
604 | return SR_ERR_ARG; |
605 | } | |
a1bb33af | 606 | |
014359e3 | 607 | if (configure_probes(sdi) != SR_OK) { |
6d116114 | 608 | sr_err("Failed to configure probes."); |
014359e3 BV |
609 | return SR_ERR; |
610 | } | |
611 | ||
609bfd75 BV |
612 | usb = sdi->conn; |
613 | ||
0ab0cb94 TY |
614 | set_triggerbar(devc); |
615 | ||
e495a676 | 616 | /* Push configured settings to device. */ |
609bfd75 | 617 | analyzer_configure(usb->devhdl); |
a143e4e5 | 618 | |
609bfd75 | 619 | analyzer_start(usb->devhdl); |
6d116114 | 620 | sr_info("Waiting for data."); |
609bfd75 | 621 | analyzer_wait_data(usb->devhdl); |
a1bb33af | 622 | |
6d116114 | 623 | sr_info("Stop address = 0x%x.", |
609bfd75 | 624 | analyzer_get_stop_address(usb->devhdl)); |
6d116114 | 625 | sr_info("Now address = 0x%x.", |
609bfd75 | 626 | analyzer_get_now_address(usb->devhdl)); |
6d116114 | 627 | sr_info("Trigger address = 0x%x.", |
609bfd75 | 628 | analyzer_get_trigger_address(usb->devhdl)); |
a1bb33af | 629 | |
4afdfd46 | 630 | /* Send header packet to the session bus. */ |
29a27196 | 631 | std_session_send_df_header(cb_data, LOG_PREFIX); |
f366e86c | 632 | |
b53738ba | 633 | if (!(buf = g_try_malloc(PACKET_SIZE))) { |
6d116114 | 634 | sr_err("Packet buffer malloc failed."); |
b53738ba UH |
635 | return SR_ERR_MALLOC; |
636 | } | |
637 | ||
0ab0cb94 | 638 | //samples_read = 0; |
609bfd75 | 639 | analyzer_read_start(usb->devhdl); |
fed16f06 | 640 | /* Send the incoming transfer to the session bus. */ |
0ab0cb94 TY |
641 | n = get_memory_size(devc->memory_size); |
642 | if (devc->max_memory_size * 4 < n) | |
643 | n = devc->max_memory_size * 4; | |
644 | for (packet_num = 0; packet_num < n / PACKET_SIZE; packet_num++) { | |
609bfd75 | 645 | res = analyzer_read_data(usb->devhdl, buf, PACKET_SIZE); |
6d116114 | 646 | sr_info("Tried to read %d bytes, actually read %d bytes.", |
b08024a8 | 647 | PACKET_SIZE, res); |
a1bb33af | 648 | |
5a2326a7 | 649 | packet.type = SR_DF_LOGIC; |
9c939c51 BV |
650 | packet.payload = &logic; |
651 | logic.length = PACKET_SIZE; | |
652 | logic.unitsize = 4; | |
653 | logic.data = buf; | |
3cd3a20b | 654 | sr_session_send(cb_data, &packet); |
0ab0cb94 | 655 | //samples_read += res / 4; |
a1bb33af | 656 | } |
609bfd75 | 657 | analyzer_read_stop(usb->devhdl); |
a1bb33af UH |
658 | g_free(buf); |
659 | ||
5a2326a7 | 660 | packet.type = SR_DF_END; |
3cd3a20b | 661 | sr_session_send(cb_data, &packet); |
a1bb33af | 662 | |
e46b8fb1 | 663 | return SR_OK; |
a1bb33af UH |
664 | } |
665 | ||
3cd3a20b | 666 | /* TODO: This stops acquisition on ALL devices, ignoring dev_index. */ |
69b07d14 | 667 | static int hw_dev_acquisition_stop(struct sr_dev_inst *sdi, void *cb_data) |
a1bb33af | 668 | { |
310e9e9b | 669 | struct dev_context *devc; |
609bfd75 BV |
670 | struct sr_usb_dev_inst *usb; |
671 | struct sr_datafeed_packet packet; | |
a1bb33af | 672 | |
5a2326a7 | 673 | packet.type = SR_DF_END; |
3cd3a20b | 674 | sr_session_send(cb_data, &packet); |
a1bb33af | 675 | |
310e9e9b | 676 | if (!(devc = sdi->priv)) { |
6d116114 | 677 | sr_err("%s: sdi->priv was NULL", __func__); |
3010f21c | 678 | return SR_ERR_BUG; |
69890f73 | 679 | } |
a1bb33af | 680 | |
609bfd75 BV |
681 | usb = sdi->conn; |
682 | analyzer_reset(usb->devhdl); | |
fed16f06 | 683 | /* TODO: Need to cancel and free any queued up transfers. */ |
3010f21c UH |
684 | |
685 | return SR_OK; | |
a1bb33af UH |
686 | } |
687 | ||
c09f0b57 | 688 | SR_PRIV struct sr_dev_driver zeroplus_logic_cube_driver_info = { |
e519ba86 | 689 | .name = "zeroplus-logic-cube", |
8fdecced | 690 | .longname = "ZEROPLUS Logic Cube LAP-C series", |
e519ba86 UH |
691 | .api_version = 1, |
692 | .init = hw_init, | |
693 | .cleanup = hw_cleanup, | |
61136ea6 | 694 | .scan = hw_scan, |
811deee4 BV |
695 | .dev_list = hw_dev_list, |
696 | .dev_clear = hw_cleanup, | |
035a1078 BV |
697 | .config_get = config_get, |
698 | .config_set = config_set, | |
a1c743fc | 699 | .config_list = config_list, |
e7eb703f UH |
700 | .dev_open = hw_dev_open, |
701 | .dev_close = hw_dev_close, | |
69040b7c UH |
702 | .dev_acquisition_start = hw_dev_acquisition_start, |
703 | .dev_acquisition_stop = hw_dev_acquisition_stop, | |
310e9e9b | 704 | .priv = NULL, |
a1bb33af | 705 | }; |