]>
Commit | Line | Data |
---|---|---|
10763937 SA |
1 | /* |
2 | * This file is part of the libsigrok project. | |
3 | * | |
4 | * Copyright (C) 2014 abraxa (Soeren Apel) <soeren@apelpie.net> | |
5 | * Based on the Hameg HMO driver by poljar (Damir Jelić) <poljarinho@gmail.com> | |
6 | * | |
7 | * This program is free software: you can redistribute it and/or modify | |
8 | * it under the terms of the GNU General Public License as published by | |
9 | * the Free Software Foundation, either version 3 of the License, or | |
10 | * (at your option) any later version. | |
11 | * | |
12 | * This program is distributed in the hope that it will be useful, | |
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 | * GNU General Public License for more details. | |
16 | * | |
17 | * You should have received a copy of the GNU General Public License | |
18 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | |
19 | */ | |
20 | ||
6ec6c43b | 21 | #include <config.h> |
10763937 | 22 | #include <stdlib.h> |
5a1afc09 | 23 | #include "scpi.h" |
10763937 SA |
24 | #include "protocol.h" |
25 | ||
dd5c48a6 | 26 | static struct sr_dev_driver yokogawa_dlm_driver_info; |
8ab929d6 | 27 | |
329733d9 UH |
28 | static const char *MANUFACTURER_ID = "YOKOGAWA"; |
29 | static const char *MANUFACTURER_NAME = "Yokogawa"; | |
8ab929d6 | 30 | |
f3c60fb6 SA |
31 | static const uint32_t dlm_scanopts[] = { |
32 | SR_CONF_CONN, | |
33 | }; | |
34 | ||
35 | static const uint32_t dlm_drvopts[] = { | |
cf0280fa AJ |
36 | SR_CONF_LOGIC_ANALYZER, |
37 | SR_CONF_OSCILLOSCOPE, | |
38 | }; | |
39 | ||
f3c60fb6 SA |
40 | static const uint32_t dlm_devopts[] = { |
41 | SR_CONF_LIMIT_FRAMES | SR_CONF_GET | SR_CONF_SET, | |
42 | SR_CONF_SAMPLERATE | SR_CONF_GET, | |
43 | SR_CONF_TIMEBASE | SR_CONF_GET | SR_CONF_SET | SR_CONF_LIST, | |
44 | SR_CONF_NUM_HDIV | SR_CONF_GET, | |
45 | SR_CONF_HORIZ_TRIGGERPOS | SR_CONF_GET | SR_CONF_SET, | |
f3c60fb6 | 46 | SR_CONF_TRIGGER_SOURCE | SR_CONF_GET | SR_CONF_SET | SR_CONF_LIST, |
86621306 | 47 | SR_CONF_TRIGGER_SLOPE | SR_CONF_GET | SR_CONF_SET | SR_CONF_LIST, |
f3c60fb6 SA |
48 | }; |
49 | ||
50 | static const uint32_t dlm_analog_devopts[] = { | |
f3c60fb6 | 51 | SR_CONF_NUM_VDIV | SR_CONF_GET, |
86621306 UH |
52 | SR_CONF_VDIV | SR_CONF_GET | SR_CONF_SET | SR_CONF_LIST, |
53 | SR_CONF_COUPLING | SR_CONF_GET | SR_CONF_SET | SR_CONF_LIST, | |
f3c60fb6 SA |
54 | }; |
55 | ||
56 | static const uint32_t dlm_digital_devopts[] = { | |
57 | }; | |
58 | ||
8ab929d6 SA |
59 | enum { |
60 | CG_INVALID = -1, | |
61 | CG_NONE, | |
62 | CG_ANALOG, | |
63 | CG_DIGITAL, | |
64 | }; | |
65 | ||
8ab929d6 SA |
66 | static struct sr_dev_inst *probe_usbtmc_device(struct sr_scpi_dev_inst *scpi) |
67 | { | |
68 | struct sr_dev_inst *sdi; | |
69 | struct dev_context *devc; | |
70 | struct sr_scpi_hw_info *hw_info; | |
71 | char *model_name; | |
72 | int model_index; | |
73 | ||
74 | sdi = NULL; | |
75 | devc = NULL; | |
76 | hw_info = NULL; | |
77 | ||
78 | if (sr_scpi_get_hw_id(scpi, &hw_info) != SR_OK) { | |
79 | sr_info("Couldn't get IDN response."); | |
80 | goto fail; | |
81 | } | |
82 | ||
83 | if (strcmp(hw_info->manufacturer, MANUFACTURER_ID) != 0) | |
84 | goto fail; | |
85 | ||
86 | if (dlm_model_get(hw_info->model, &model_name, &model_index) != SR_OK) | |
87 | goto fail; | |
88 | ||
aac29cc1 | 89 | sdi = g_malloc0(sizeof(struct sr_dev_inst)); |
0af636be UH |
90 | sdi->vendor = g_strdup(MANUFACTURER_NAME); |
91 | sdi->model = g_strdup(model_name); | |
92 | sdi->version = g_strdup(hw_info->firmware_version); | |
8ab929d6 | 93 | |
d1314831 SA |
94 | sdi->serial_num = g_strdup(hw_info->serial_number); |
95 | ||
8ab929d6 SA |
96 | sr_scpi_hw_info_free(hw_info); |
97 | hw_info = NULL; | |
98 | ||
ac10a927 | 99 | devc = g_malloc0(sizeof(struct dev_context)); |
8ab929d6 | 100 | |
4f840ce9 | 101 | sdi->driver = &yokogawa_dlm_driver_info; |
8ab929d6 SA |
102 | sdi->priv = devc; |
103 | sdi->inst_type = SR_INST_SCPI; | |
104 | sdi->conn = scpi; | |
105 | ||
106 | if (dlm_device_init(sdi, model_index) != SR_OK) | |
107 | goto fail; | |
108 | ||
8ab929d6 SA |
109 | return sdi; |
110 | ||
111 | fail: | |
7b365c47 | 112 | sr_scpi_hw_info_free(hw_info); |
4bf93988 | 113 | sr_dev_inst_free(sdi); |
b1f83103 | 114 | g_free(devc); |
8ab929d6 SA |
115 | |
116 | return NULL; | |
117 | } | |
118 | ||
4f840ce9 | 119 | static GSList *scan(struct sr_dev_driver *di, GSList *options) |
8ab929d6 | 120 | { |
41812aca | 121 | return sr_scpi_scan(di->context, options, probe_usbtmc_device); |
8ab929d6 SA |
122 | } |
123 | ||
8ab929d6 SA |
124 | static void clear_helper(void *priv) |
125 | { | |
126 | struct dev_context *devc; | |
127 | ||
128 | devc = priv; | |
129 | ||
130 | dlm_scope_state_destroy(devc->model_state); | |
131 | ||
132 | g_free(devc->analog_groups); | |
133 | g_free(devc->digital_groups); | |
8ab929d6 SA |
134 | } |
135 | ||
4f840ce9 | 136 | static int dev_clear(const struct sr_dev_driver *di) |
8ab929d6 | 137 | { |
6e43c3d5 | 138 | return std_dev_clear_with_callback(di, clear_helper); |
8ab929d6 SA |
139 | } |
140 | ||
141 | static int dev_open(struct sr_dev_inst *sdi) | |
142 | { | |
6402c379 | 143 | if (sr_scpi_open(sdi->conn) != SR_OK) |
8ab929d6 SA |
144 | return SR_ERR; |
145 | ||
146 | if (dlm_scope_state_query(sdi) != SR_OK) | |
147 | return SR_ERR; | |
148 | ||
8ab929d6 SA |
149 | return SR_OK; |
150 | } | |
151 | ||
152 | static int dev_close(struct sr_dev_inst *sdi) | |
153 | { | |
f1ba6b4b | 154 | return sr_scpi_close(sdi->conn); |
8ab929d6 SA |
155 | } |
156 | ||
8ab929d6 SA |
157 | /** |
158 | * Check which category a given channel group belongs to. | |
159 | * | |
160 | * @param devc Our internal device context. | |
a9308652 | 161 | * @param cg The channel group to check. |
8ab929d6 | 162 | * |
a9308652 UH |
163 | * @retval CG_NONE cg is NULL |
164 | * @retval CG_ANALOG cg is an analog group | |
8ab929d6 SA |
165 | * @retval CG_DIGITAL cg is a digital group |
166 | * @retval CG_INVALID cg is something else | |
167 | */ | |
168 | static int check_channel_group(struct dev_context *devc, | |
ac10a927 | 169 | const struct sr_channel_group *cg) |
8ab929d6 SA |
170 | { |
171 | unsigned int i; | |
329733d9 | 172 | const struct scope_config *model; |
8ab929d6 SA |
173 | |
174 | model = devc->model_config; | |
175 | ||
176 | if (!cg) | |
177 | return CG_NONE; | |
178 | ||
a9308652 | 179 | for (i = 0; i < model->analog_channels; i++) |
8ab929d6 SA |
180 | if (cg == devc->analog_groups[i]) |
181 | return CG_ANALOG; | |
182 | ||
a9308652 | 183 | for (i = 0; i < model->pods; i++) |
8ab929d6 SA |
184 | if (cg == devc->digital_groups[i]) |
185 | return CG_DIGITAL; | |
186 | ||
187 | sr_err("Invalid channel group specified."); | |
188 | return CG_INVALID; | |
189 | } | |
190 | ||
584560f1 | 191 | static int config_get(uint32_t key, GVariant **data, const struct sr_dev_inst *sdi, |
ac10a927 | 192 | const struct sr_channel_group *cg) |
8ab929d6 SA |
193 | { |
194 | int ret, cg_type; | |
195 | unsigned int i; | |
196 | struct dev_context *devc; | |
329733d9 | 197 | const struct scope_config *model; |
8ab929d6 SA |
198 | struct scope_state *state; |
199 | ||
709468ba | 200 | if (!sdi) |
8ab929d6 SA |
201 | return SR_ERR_ARG; |
202 | ||
709468ba UH |
203 | devc = sdi->priv; |
204 | ||
8ab929d6 SA |
205 | if ((cg_type = check_channel_group(devc, cg)) == CG_INVALID) |
206 | return SR_ERR; | |
207 | ||
8ab929d6 SA |
208 | model = devc->model_config; |
209 | state = devc->model_state; | |
210 | ||
211 | switch (key) { | |
bf622e6d | 212 | case SR_CONF_NUM_HDIV: |
8ab929d6 SA |
213 | *data = g_variant_new_int32(model->num_xdivs); |
214 | ret = SR_OK; | |
215 | break; | |
216 | case SR_CONF_TIMEBASE: | |
217 | *data = g_variant_new("(tt)", | |
f3c60fb6 SA |
218 | dlm_timebases[state->timebase][0], |
219 | dlm_timebases[state->timebase][1]); | |
8ab929d6 SA |
220 | ret = SR_OK; |
221 | break; | |
222 | case SR_CONF_NUM_VDIV: | |
223 | if (cg_type == CG_NONE) { | |
224 | sr_err("No channel group specified."); | |
225 | return SR_ERR_CHANNEL_GROUP; | |
226 | } else if (cg_type == CG_ANALOG) { | |
227 | *data = g_variant_new_int32(model->num_ydivs); | |
228 | ret = SR_OK; | |
229 | break; | |
230 | } else { | |
231 | ret = SR_ERR_NA; | |
232 | } | |
233 | break; | |
234 | case SR_CONF_VDIV: | |
235 | ret = SR_ERR_NA; | |
236 | if (cg_type == CG_NONE) { | |
237 | sr_err("No channel group specified."); | |
238 | return SR_ERR_CHANNEL_GROUP; | |
239 | } else if (cg_type != CG_ANALOG) | |
240 | break; | |
241 | ||
a9308652 | 242 | for (i = 0; i < model->analog_channels; i++) { |
8ab929d6 SA |
243 | if (cg != devc->analog_groups[i]) |
244 | continue; | |
245 | *data = g_variant_new("(tt)", | |
f3c60fb6 SA |
246 | dlm_vdivs[state->analog_states[i].vdiv][0], |
247 | dlm_vdivs[state->analog_states[i].vdiv][1]); | |
8ab929d6 SA |
248 | ret = SR_OK; |
249 | break; | |
250 | } | |
251 | break; | |
252 | case SR_CONF_TRIGGER_SOURCE: | |
253 | *data = g_variant_new_string((*model->trigger_sources)[state->trigger_source]); | |
254 | ret = SR_OK; | |
255 | break; | |
256 | case SR_CONF_TRIGGER_SLOPE: | |
f3c60fb6 | 257 | *data = g_variant_new_string(dlm_trigger_slopes[state->trigger_slope]); |
8ab929d6 SA |
258 | ret = SR_OK; |
259 | break; | |
260 | case SR_CONF_HORIZ_TRIGGERPOS: | |
261 | *data = g_variant_new_double(state->horiz_triggerpos); | |
262 | ret = SR_OK; | |
263 | break; | |
264 | case SR_CONF_COUPLING: | |
265 | ret = SR_ERR_NA; | |
266 | if (cg_type == CG_NONE) { | |
267 | sr_err("No channel group specified."); | |
268 | return SR_ERR_CHANNEL_GROUP; | |
269 | } else if (cg_type != CG_ANALOG) | |
270 | break; | |
271 | ||
a9308652 | 272 | for (i = 0; i < model->analog_channels; i++) { |
8ab929d6 SA |
273 | if (cg != devc->analog_groups[i]) |
274 | continue; | |
275 | *data = g_variant_new_string((*model->coupling_options)[state->analog_states[i].coupling]); | |
276 | ret = SR_OK; | |
277 | break; | |
278 | } | |
279 | break; | |
280 | case SR_CONF_SAMPLERATE: | |
281 | *data = g_variant_new_uint64(state->sample_rate); | |
282 | ret = SR_OK; | |
283 | break; | |
284 | default: | |
285 | ret = SR_ERR_NA; | |
286 | } | |
287 | ||
288 | return ret; | |
289 | } | |
290 | ||
291 | static GVariant *build_tuples(const uint64_t (*array)[][2], unsigned int n) | |
292 | { | |
293 | unsigned int i; | |
294 | GVariant *rational[2]; | |
295 | GVariantBuilder gvb; | |
296 | ||
297 | g_variant_builder_init(&gvb, G_VARIANT_TYPE_ARRAY); | |
298 | ||
299 | for (i = 0; i < n; i++) { | |
300 | rational[0] = g_variant_new_uint64((*array)[i][0]); | |
301 | rational[1] = g_variant_new_uint64((*array)[i][1]); | |
302 | ||
303 | /* FIXME: Valgrind reports a memory leak here. */ | |
304 | g_variant_builder_add_value(&gvb, g_variant_new_tuple(rational, 2)); | |
305 | } | |
306 | ||
307 | return g_variant_builder_end(&gvb); | |
308 | } | |
309 | ||
584560f1 | 310 | static int config_set(uint32_t key, GVariant *data, const struct sr_dev_inst *sdi, |
ac10a927 | 311 | const struct sr_channel_group *cg) |
8ab929d6 SA |
312 | { |
313 | int ret, cg_type; | |
314 | unsigned int i, j; | |
315 | char float_str[30]; | |
316 | struct dev_context *devc; | |
329733d9 | 317 | const struct scope_config *model; |
8ab929d6 SA |
318 | struct scope_state *state; |
319 | const char *tmp; | |
320 | uint64_t p, q; | |
321 | double tmp_d; | |
322 | gboolean update_sample_rate; | |
323 | ||
324 | if (!sdi || !(devc = sdi->priv)) | |
325 | return SR_ERR_ARG; | |
326 | ||
327 | if ((cg_type = check_channel_group(devc, cg)) == CG_INVALID) | |
328 | return SR_ERR; | |
329 | ||
330 | model = devc->model_config; | |
331 | state = devc->model_state; | |
332 | update_sample_rate = FALSE; | |
333 | ||
334 | ret = SR_ERR_NA; | |
335 | ||
336 | switch (key) { | |
337 | case SR_CONF_LIMIT_FRAMES: | |
338 | devc->frame_limit = g_variant_get_uint64(data); | |
339 | ret = SR_OK; | |
340 | break; | |
341 | case SR_CONF_TRIGGER_SOURCE: | |
342 | tmp = g_variant_get_string(data, NULL); | |
343 | for (i = 0; (*model->trigger_sources)[i]; i++) { | |
344 | if (g_strcmp0(tmp, (*model->trigger_sources)[i]) != 0) | |
345 | continue; | |
346 | state->trigger_source = i; | |
347 | /* TODO: A and B trigger support possible? */ | |
348 | ret = dlm_trigger_source_set(sdi->conn, (*model->trigger_sources)[i]); | |
349 | break; | |
350 | } | |
351 | break; | |
352 | case SR_CONF_VDIV: | |
353 | if (cg_type == CG_NONE) { | |
354 | sr_err("No channel group specified."); | |
355 | return SR_ERR_CHANNEL_GROUP; | |
356 | } | |
357 | ||
358 | g_variant_get(data, "(tt)", &p, &q); | |
359 | ||
f3c60fb6 SA |
360 | for (i = 0; i < ARRAY_SIZE(dlm_vdivs); i++) { |
361 | if (p != dlm_vdivs[i][0] || | |
362 | q != dlm_vdivs[i][1]) | |
8ab929d6 | 363 | continue; |
a9308652 | 364 | for (j = 1; j <= model->analog_channels; j++) { |
8ab929d6 SA |
365 | if (cg != devc->analog_groups[j - 1]) |
366 | continue; | |
367 | state->analog_states[j - 1].vdiv = i; | |
368 | g_ascii_formatd(float_str, sizeof(float_str), | |
369 | "%E", (float) p / q); | |
370 | if (dlm_analog_chan_vdiv_set(sdi->conn, j, float_str) != SR_OK || | |
ac10a927 | 371 | sr_scpi_get_opc(sdi->conn) != SR_OK) |
8ab929d6 SA |
372 | return SR_ERR; |
373 | ||
374 | break; | |
375 | } | |
376 | ||
377 | ret = SR_OK; | |
378 | break; | |
379 | } | |
380 | break; | |
381 | case SR_CONF_TIMEBASE: | |
382 | g_variant_get(data, "(tt)", &p, &q); | |
383 | ||
f3c60fb6 SA |
384 | for (i = 0; i < ARRAY_SIZE(dlm_timebases); i++) { |
385 | if (p != dlm_timebases[i][0] || | |
386 | q != dlm_timebases[i][1]) | |
8ab929d6 SA |
387 | continue; |
388 | state->timebase = i; | |
389 | g_ascii_formatd(float_str, sizeof(float_str), | |
390 | "%E", (float) p / q); | |
391 | ret = dlm_timebase_set(sdi->conn, float_str); | |
392 | update_sample_rate = TRUE; | |
393 | break; | |
394 | } | |
395 | break; | |
396 | case SR_CONF_HORIZ_TRIGGERPOS: | |
397 | tmp_d = g_variant_get_double(data); | |
398 | ||
399 | /* TODO: Check if the calculation makes sense for the DLM. */ | |
400 | if (tmp_d < 0.0 || tmp_d > 1.0) | |
401 | return SR_ERR; | |
402 | ||
403 | state->horiz_triggerpos = tmp_d; | |
404 | tmp_d = -(tmp_d - 0.5) * | |
f3c60fb6 SA |
405 | ((double) dlm_timebases[state->timebase][0] / |
406 | dlm_timebases[state->timebase][1]) | |
ac10a927 | 407 | * model->num_xdivs; |
8ab929d6 SA |
408 | |
409 | g_ascii_formatd(float_str, sizeof(float_str), "%E", tmp_d); | |
410 | ret = dlm_horiz_trigger_pos_set(sdi->conn, float_str); | |
411 | break; | |
412 | case SR_CONF_TRIGGER_SLOPE: | |
413 | tmp = g_variant_get_string(data, NULL); | |
414 | ||
415 | if (!tmp || !(tmp[0] == 'f' || tmp[0] == 'r')) | |
416 | return SR_ERR_ARG; | |
417 | ||
418 | /* Note: See dlm_trigger_slopes[] in protocol.c. */ | |
419 | state->trigger_slope = (tmp[0] == 'r') ? | |
420 | SLOPE_POSITIVE : SLOPE_NEGATIVE; | |
421 | ||
422 | ret = dlm_trigger_slope_set(sdi->conn, state->trigger_slope); | |
423 | break; | |
424 | case SR_CONF_COUPLING: | |
425 | if (cg_type == CG_NONE) { | |
426 | sr_err("No channel group specified."); | |
427 | return SR_ERR_CHANNEL_GROUP; | |
428 | } | |
429 | ||
430 | tmp = g_variant_get_string(data, NULL); | |
431 | ||
432 | for (i = 0; (*model->coupling_options)[i]; i++) { | |
433 | if (strcmp(tmp, (*model->coupling_options)[i]) != 0) | |
434 | continue; | |
a9308652 | 435 | for (j = 1; j <= model->analog_channels; j++) { |
8ab929d6 SA |
436 | if (cg != devc->analog_groups[j - 1]) |
437 | continue; | |
438 | state->analog_states[j-1].coupling = i; | |
439 | ||
440 | if (dlm_analog_chan_coupl_set(sdi->conn, j, tmp) != SR_OK || | |
ac10a927 | 441 | sr_scpi_get_opc(sdi->conn) != SR_OK) |
8ab929d6 SA |
442 | return SR_ERR; |
443 | break; | |
444 | } | |
445 | ||
446 | ret = SR_OK; | |
447 | break; | |
448 | } | |
449 | break; | |
450 | default: | |
451 | ret = SR_ERR_NA; | |
452 | break; | |
453 | } | |
454 | ||
455 | if (ret == SR_OK) | |
456 | ret = sr_scpi_get_opc(sdi->conn); | |
457 | ||
458 | if (ret == SR_OK && update_sample_rate) | |
459 | ret = dlm_sample_rate_query(sdi); | |
460 | ||
461 | return ret; | |
462 | } | |
463 | ||
c65a021c SA |
464 | static int config_channel_set(const struct sr_dev_inst *sdi, |
465 | struct sr_channel *ch, unsigned int changes) | |
466 | { | |
a9308652 | 467 | /* Currently we only handle SR_CHANNEL_SET_ENABLED. */ |
c65a021c SA |
468 | if (changes != SR_CHANNEL_SET_ENABLED) |
469 | return SR_ERR_NA; | |
470 | ||
471 | return dlm_channel_state_set(sdi, ch->index, ch->enabled); | |
472 | } | |
473 | ||
584560f1 | 474 | static int config_list(uint32_t key, GVariant **data, const struct sr_dev_inst *sdi, |
ac10a927 | 475 | const struct sr_channel_group *cg) |
8ab929d6 | 476 | { |
cf0280fa AJ |
477 | int cg_type = CG_NONE; |
478 | struct dev_context *devc = NULL; | |
329733d9 | 479 | const struct scope_config *model = NULL; |
8ab929d6 | 480 | |
9a512113 | 481 | /* SR_CONF_SCAN_OPTIONS is always valid, regardless of sdi or channel group. */ |
f3c60fb6 SA |
482 | if (key == SR_CONF_SCAN_OPTIONS) { |
483 | *data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32, | |
484 | dlm_scanopts, ARRAY_SIZE(dlm_scanopts), sizeof(uint32_t)); | |
485 | return SR_OK; | |
486 | } | |
8ab929d6 | 487 | |
f3c60fb6 SA |
488 | /* If sdi is NULL, nothing except SR_CONF_DEVICE_OPTIONS can be provided. */ |
489 | if (key == SR_CONF_DEVICE_OPTIONS && !sdi) { | |
490 | *data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32, | |
491 | dlm_drvopts, ARRAY_SIZE(dlm_drvopts), sizeof(uint32_t)); | |
492 | return SR_OK; | |
cf0280fa | 493 | } |
8ab929d6 | 494 | |
f3c60fb6 SA |
495 | if (!sdi) |
496 | return SR_ERR_ARG; | |
497 | ||
498 | devc = sdi->priv; | |
499 | model = devc->model_config; | |
500 | ||
a9308652 UH |
501 | /* |
502 | * If cg is NULL, only the SR_CONF_DEVICE_OPTIONS that are not | |
9a512113 | 503 | * specific to a channel group must be returned. |
a9308652 | 504 | */ |
f3c60fb6 SA |
505 | if (!cg) { |
506 | switch (key) { | |
507 | case SR_CONF_DEVICE_OPTIONS: | |
508 | *data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32, | |
509 | dlm_devopts, ARRAY_SIZE(dlm_devopts), sizeof(uint32_t)); | |
510 | return SR_OK; | |
511 | case SR_CONF_TIMEBASE: | |
512 | *data = build_tuples(&dlm_timebases, ARRAY_SIZE(dlm_timebases)); | |
513 | return SR_OK; | |
514 | case SR_CONF_TRIGGER_SOURCE: | |
515 | if (!model) | |
516 | return SR_ERR_ARG; | |
517 | *data = g_variant_new_strv(*model->trigger_sources, | |
518 | g_strv_length((char **)*model->trigger_sources)); | |
519 | return SR_OK; | |
520 | case SR_CONF_TRIGGER_SLOPE: | |
521 | *data = g_variant_new_strv(dlm_trigger_slopes, | |
522 | g_strv_length((char **)dlm_trigger_slopes)); | |
523 | return SR_OK; | |
524 | case SR_CONF_NUM_HDIV: | |
49f49cb5 | 525 | *data = g_variant_new_uint32(model->num_xdivs); |
f3c60fb6 SA |
526 | return SR_OK; |
527 | default: | |
528 | return SR_ERR_NA; | |
529 | } | |
530 | } | |
531 | ||
532 | if ((cg_type = check_channel_group(devc, cg)) == CG_INVALID) | |
533 | return SR_ERR; | |
534 | ||
8ab929d6 | 535 | switch (key) { |
8ab929d6 | 536 | case SR_CONF_DEVICE_OPTIONS: |
f3c60fb6 | 537 | if (cg_type == CG_ANALOG) { |
584560f1 | 538 | *data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32, |
f3c60fb6 SA |
539 | dlm_analog_devopts, ARRAY_SIZE(dlm_analog_devopts), sizeof(uint32_t)); |
540 | } else if (cg_type == CG_DIGITAL) { | |
541 | *data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32, | |
542 | dlm_digital_devopts, ARRAY_SIZE(dlm_digital_devopts), sizeof(uint32_t)); | |
8ab929d6 | 543 | } else { |
584560f1 BV |
544 | *data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32, |
545 | NULL, 0, sizeof(uint32_t)); | |
8ab929d6 SA |
546 | } |
547 | break; | |
548 | case SR_CONF_COUPLING: | |
549 | if (cg_type == CG_NONE) | |
550 | return SR_ERR_CHANNEL_GROUP; | |
551 | *data = g_variant_new_strv(*model->coupling_options, | |
ac10a927 | 552 | g_strv_length((char **)*model->coupling_options)); |
8ab929d6 | 553 | break; |
8ab929d6 SA |
554 | case SR_CONF_VDIV: |
555 | if (cg_type == CG_NONE) | |
556 | return SR_ERR_CHANNEL_GROUP; | |
f3c60fb6 | 557 | *data = build_tuples(&dlm_vdivs, ARRAY_SIZE(dlm_vdivs)); |
8ab929d6 SA |
558 | break; |
559 | default: | |
560 | return SR_ERR_NA; | |
561 | } | |
562 | ||
563 | return SR_OK; | |
564 | } | |
565 | ||
566 | static int dlm_check_channels(GSList *channels) | |
567 | { | |
568 | GSList *l; | |
569 | struct sr_channel *ch; | |
570 | gboolean enabled_pod1, enabled_chan4; | |
571 | ||
572 | enabled_pod1 = enabled_chan4 = FALSE; | |
573 | ||
574 | /* Note: On the DLM2000, CH4 and Logic are shared. */ | |
575 | /* TODO Handle non-DLM2000 models. */ | |
576 | for (l = channels; l; l = l->next) { | |
577 | ch = l->data; | |
578 | switch (ch->type) { | |
579 | case SR_CHANNEL_ANALOG: | |
580 | if (ch->index == 3) | |
581 | enabled_chan4 = TRUE; | |
582 | break; | |
583 | case SR_CHANNEL_LOGIC: | |
584 | enabled_pod1 = TRUE; | |
585 | break; | |
586 | default: | |
587 | return SR_ERR; | |
588 | } | |
589 | } | |
590 | ||
591 | if (enabled_pod1 && enabled_chan4) | |
592 | return SR_ERR; | |
593 | ||
594 | return SR_OK; | |
595 | } | |
596 | ||
695dc859 | 597 | static int dev_acquisition_start(const struct sr_dev_inst *sdi) |
8ab929d6 SA |
598 | { |
599 | GSList *l; | |
600 | gboolean digital_added; | |
601 | struct sr_channel *ch; | |
602 | struct dev_context *devc; | |
603 | struct sr_scpi_dev_inst *scpi; | |
604 | ||
8ab929d6 SA |
605 | scpi = sdi->conn; |
606 | devc = sdi->priv; | |
607 | digital_added = FALSE; | |
608 | ||
609 | g_slist_free(devc->enabled_channels); | |
610 | devc->enabled_channels = NULL; | |
611 | ||
612 | for (l = sdi->channels; l; l = l->next) { | |
613 | ch = l->data; | |
614 | if (!ch->enabled) | |
615 | continue; | |
616 | /* Only add a single digital channel. */ | |
617 | if (ch->type != SR_CHANNEL_LOGIC || !digital_added) { | |
618 | devc->enabled_channels = g_slist_append( | |
ac10a927 SA |
619 | devc->enabled_channels, ch); |
620 | if (ch->type == SR_CHANNEL_LOGIC) | |
621 | digital_added = TRUE; | |
8ab929d6 SA |
622 | } |
623 | } | |
624 | ||
625 | if (!devc->enabled_channels) | |
626 | return SR_ERR; | |
627 | ||
628 | if (dlm_check_channels(devc->enabled_channels) != SR_OK) { | |
629 | sr_err("Invalid channel configuration specified!"); | |
630 | return SR_ERR_NA; | |
631 | } | |
632 | ||
af3487ec SA |
633 | /* Request data for the first enabled channel. */ |
634 | devc->current_channel = devc->enabled_channels; | |
635 | dlm_channel_data_request(sdi); | |
636 | ||
0028d5a1 SA |
637 | /* Call our callback when data comes in or after 5ms. */ |
638 | sr_scpi_source_add(sdi->session, scpi, G_IO_IN, 5, | |
8ab929d6 SA |
639 | dlm_data_receive, (void *)sdi); |
640 | ||
641 | return SR_OK; | |
642 | } | |
643 | ||
695dc859 | 644 | static int dev_acquisition_stop(struct sr_dev_inst *sdi) |
8ab929d6 SA |
645 | { |
646 | struct dev_context *devc; | |
8ab929d6 | 647 | |
bee2b016 | 648 | std_session_send_df_end(sdi); |
8ab929d6 | 649 | |
8ab929d6 SA |
650 | devc = sdi->priv; |
651 | ||
652 | devc->num_frames = 0; | |
653 | g_slist_free(devc->enabled_channels); | |
654 | devc->enabled_channels = NULL; | |
af3487ec SA |
655 | |
656 | sr_scpi_source_remove(sdi->session, sdi->conn); | |
8ab929d6 SA |
657 | |
658 | return SR_OK; | |
659 | } | |
10763937 | 660 | |
dd5c48a6 | 661 | static struct sr_dev_driver yokogawa_dlm_driver_info = { |
10763937 | 662 | .name = "yokogawa-dlm", |
ac10a927 | 663 | .longname = "Yokogawa DL/DLM", |
10763937 | 664 | .api_version = 1, |
c2fdcc25 | 665 | .init = std_init, |
700d6b64 | 666 | .cleanup = std_cleanup, |
8ab929d6 | 667 | .scan = scan, |
c01bf34c | 668 | .dev_list = std_dev_list, |
8ab929d6 SA |
669 | .dev_clear = dev_clear, |
670 | .config_get = config_get, | |
671 | .config_set = config_set, | |
c65a021c | 672 | .config_channel_set = config_channel_set, |
8ab929d6 SA |
673 | .config_list = config_list, |
674 | .dev_open = dev_open, | |
675 | .dev_close = dev_close, | |
676 | .dev_acquisition_start = dev_acquisition_start, | |
677 | .dev_acquisition_stop = dev_acquisition_stop, | |
41812aca | 678 | .context = NULL, |
10763937 | 679 | }; |
dd5c48a6 | 680 | SR_REGISTER_DEV_DRIVER(yokogawa_dlm_driver_info); |