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