]> sigrok.org Git - libsigrok.git/blame - src/hardware/scpi-pps/protocol.h
scpi-pps: Add channel probe facility to scan.
[libsigrok.git] / src / hardware / scpi-pps / protocol.h
CommitLineData
ca1a7cb5
BV
1/*
2 * This file is part of the libsigrok project.
3 *
4 * Copyright (C) 2014 Bert Vermeulen <bert@biot.com>
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
20#ifndef LIBSIGROK_HARDWARE_SCPI_PPS_PROTOCOL_H
21#define LIBSIGROK_HARDWARE_SCPI_PPS_PROTOCOL_H
22
23#include <stdint.h>
24#include <glib.h>
25#include "libsigrok.h"
26#include "libsigrok-internal.h"
27
28#define LOG_PREFIX "scpi-pps"
29
9e45cd41 30enum pps_scpi_cmds {
60475cd7
BV
31 SCPI_CMD_REMOTE,
32 SCPI_CMD_LOCAL,
ee2860ee
BV
33 SCPI_CMD_BEEPER,
34 SCPI_CMD_BEEPER_ENABLE,
35 SCPI_CMD_BEEPER_DISABLE,
60475cd7 36 SCPI_CMD_SELECT_CHANNEL,
9e45cd41
BV
37 SCPI_CMD_GET_MEAS_VOLTAGE,
38 SCPI_CMD_GET_MEAS_CURRENT,
39 SCPI_CMD_GET_MEAS_POWER,
ca95e90f
BV
40 SCPI_CMD_GET_VOLTAGE_TARGET,
41 SCPI_CMD_SET_VOLTAGE_TARGET,
42 SCPI_CMD_GET_CURRENT_LIMIT,
43 SCPI_CMD_SET_CURRENT_LIMIT,
9e45cd41 44 SCPI_CMD_GET_OUTPUT_ENABLED,
53a81803
BV
45 SCPI_CMD_SET_OUTPUT_ENABLE,
46 SCPI_CMD_SET_OUTPUT_DISABLE,
9e45cd41
BV
47 SCPI_CMD_GET_OUTPUT_REGULATION,
48 SCPI_CMD_GET_OVER_TEMPERATURE_PROTECTION,
53a81803
BV
49 SCPI_CMD_SET_OVER_TEMPERATURE_PROTECTION_ENABLE,
50 SCPI_CMD_SET_OVER_TEMPERATURE_PROTECTION_DISABLE,
9e45cd41 51 SCPI_CMD_GET_OVER_VOLTAGE_PROTECTION_ENABLED,
53a81803
BV
52 SCPI_CMD_SET_OVER_VOLTAGE_PROTECTION_ENABLE,
53 SCPI_CMD_SET_OVER_VOLTAGE_PROTECTION_DISABLE,
9e45cd41
BV
54 SCPI_CMD_GET_OVER_VOLTAGE_PROTECTION_ACTIVE,
55 SCPI_CMD_GET_OVER_VOLTAGE_PROTECTION_THRESHOLD,
56 SCPI_CMD_SET_OVER_VOLTAGE_PROTECTION_THRESHOLD,
57 SCPI_CMD_GET_OVER_CURRENT_PROTECTION_ENABLED,
53a81803
BV
58 SCPI_CMD_SET_OVER_CURRENT_PROTECTION_ENABLE,
59 SCPI_CMD_SET_OVER_CURRENT_PROTECTION_DISABLE,
9e45cd41
BV
60 SCPI_CMD_GET_OVER_CURRENT_PROTECTION_ACTIVE,
61 SCPI_CMD_GET_OVER_CURRENT_PROTECTION_THRESHOLD,
62 SCPI_CMD_SET_OVER_CURRENT_PROTECTION_THRESHOLD,
9e45cd41
BV
63};
64
65/*
66 * These are bit values denoting features a device can have either globally,
67 * in scpi_pps.features, or on a per-channel-group basis in
68 * channel_group_spec.features.
69 */
70enum pps_features {
71 PPS_OTP = (1 << 0),
72 PPS_OVP = (1 << 1),
73 PPS_OCP = (1 << 2),
74 PPS_INDEPENDENT = (1 << 3),
75 PPS_SERIES = (1 << 4),
76 PPS_PARALLEL = (1 << 5),
77};
78
79struct scpi_pps {
58b77c41
BV
80 char *vendor;
81 char *model;
9e45cd41 82 uint64_t features;
584560f1 83 const uint32_t *devopts;
9e45cd41 84 unsigned int num_devopts;
584560f1 85 const uint32_t *devopts_cg;
9e45cd41
BV
86 unsigned int num_devopts_cg;
87 struct channel_spec *channels;
88 unsigned int num_channels;
89 struct channel_group_spec *channel_groups;
90 unsigned int num_channel_groups;
91 struct scpi_command *commands;
92 unsigned int num_commands;
4a471029
BV
93 int (*probe_channels) (struct sr_dev_inst *sdi, struct sr_scpi_hw_info *hwinfo,
94 struct channel_spec **channels, unsigned int *num_channels,
95 struct channel_group_spec **channel_groups, unsigned int *num_channel_groups);
9e45cd41
BV
96};
97
98struct channel_spec {
99 char *name;
100 /* Min, max, programming resolution. */
101 float voltage[3];
102 float current[3];
103};
104
105struct scpi_command {
106 int command;
107 char *string;
108};
109
110struct channel_group_spec {
111 char *name;
112 uint64_t channel_index_mask;
113 uint64_t features;
114};
115
01b0257a
BV
116struct pps_channel {
117 int mq;
118 unsigned int hw_output_idx;
119 char *hwname;
120};
121
122struct pps_channel_instance {
123 int mq;
124 int command;
125 char *prefix;
126};
127
9e45cd41
BV
128struct pps_channel_group {
129 uint64_t features;
130};
131
132enum acq_states {
133 STATE_VOLTAGE,
134 STATE_CURRENT,
135 STATE_STOP,
136};
137
ca1a7cb5
BV
138/** Private, per-device-instance driver context. */
139struct dev_context {
140 /* Model-specific information */
9e45cd41 141 const struct scpi_pps *device;
ca1a7cb5
BV
142
143 /* Acquisition settings */
9e45cd41 144 void *cb_data;
ca1a7cb5
BV
145
146 /* Operational state */
ee2860ee 147 gboolean beeper_was_set;
4a471029
BV
148 struct channel_spec *channels;
149 struct channel_group_spec *channel_groups;
ca1a7cb5
BV
150
151 /* Temporary state across callbacks */
9e45cd41 152 struct sr_channel *cur_channel;
ca1a7cb5
BV
153};
154
22c18b03 155const char *get_vendor(const char *raw_vendor);
478c8d92 156SR_PRIV char *scpi_cmd_get(const struct sr_dev_inst *sdi, int command);
9e45cd41 157SR_PRIV int scpi_cmd(const struct sr_dev_inst *sdi, int command, ...);
478c8d92
BV
158SR_PRIV int scpi_cmd_resp(const struct sr_dev_inst *sdi, GVariant **gvar,
159 const GVariantType *gvtype, int command, ...);
60475cd7 160SR_PRIV int select_channel(const struct sr_dev_inst *sdi, struct sr_channel *ch);
624503ae
BV
161SR_PRIV struct sr_channel *next_enabled_channel(const struct sr_dev_inst *sdi,
162 struct sr_channel *cur_channel);
ca1a7cb5
BV
163SR_PRIV int scpi_pps_receive_data(int fd, int revents, void *cb_data);
164
165#endif