]> sigrok.org Git - libsigrok.git/blob - src/hardware/scpi-pps/protocol.h
scpi-pps: Add SR_CONF_REGULATION for HP 66xxB power supplies.
[libsigrok.git] / src / hardware / scpi-pps / protocol.h
1 /*
2  * This file is part of the libsigrok project.
3  *
4  * Copyright (C) 2014 Bert Vermeulen <bert@biot.com>
5  * Copyright (C) 2017 Frank Stettner <frank-stettner@gmx.net>
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
21 #ifndef LIBSIGROK_HARDWARE_SCPI_PPS_PROTOCOL_H
22 #define LIBSIGROK_HARDWARE_SCPI_PPS_PROTOCOL_H
23
24 #include <stdint.h>
25 #include <glib.h>
26 #include <libsigrok/libsigrok.h>
27 #include "libsigrok-internal.h"
28 #include "scpi.h"
29
30 #define LOG_PREFIX "scpi-pps"
31
32 enum pps_scpi_cmds {
33         SCPI_CMD_REMOTE = 1,
34         SCPI_CMD_LOCAL,
35         SCPI_CMD_BEEPER,
36         SCPI_CMD_BEEPER_ENABLE,
37         SCPI_CMD_BEEPER_DISABLE,
38         SCPI_CMD_SELECT_CHANNEL,
39         SCPI_CMD_GET_MEAS_VOLTAGE,
40         SCPI_CMD_GET_MEAS_CURRENT,
41         SCPI_CMD_GET_MEAS_POWER,
42         SCPI_CMD_GET_MEAS_FREQUENCY,
43         SCPI_CMD_GET_VOLTAGE_TARGET,
44         SCPI_CMD_SET_VOLTAGE_TARGET,
45         SCPI_CMD_GET_FREQUENCY_TARGET,
46         SCPI_CMD_SET_FREQUENCY_TARGET,
47         SCPI_CMD_GET_CURRENT_LIMIT,
48         SCPI_CMD_SET_CURRENT_LIMIT,
49         SCPI_CMD_GET_OUTPUT_ENABLED,
50         SCPI_CMD_SET_OUTPUT_ENABLE,
51         SCPI_CMD_SET_OUTPUT_DISABLE,
52         SCPI_CMD_GET_OUTPUT_REGULATION,
53         SCPI_CMD_GET_OVER_TEMPERATURE_PROTECTION,
54         SCPI_CMD_SET_OVER_TEMPERATURE_PROTECTION_ENABLE,
55         SCPI_CMD_SET_OVER_TEMPERATURE_PROTECTION_DISABLE,
56         SCPI_CMD_GET_OVER_VOLTAGE_PROTECTION_ENABLED,
57         SCPI_CMD_SET_OVER_VOLTAGE_PROTECTION_ENABLE,
58         SCPI_CMD_SET_OVER_VOLTAGE_PROTECTION_DISABLE,
59         SCPI_CMD_GET_OVER_VOLTAGE_PROTECTION_ACTIVE,
60         SCPI_CMD_GET_OVER_VOLTAGE_PROTECTION_THRESHOLD,
61         SCPI_CMD_SET_OVER_VOLTAGE_PROTECTION_THRESHOLD,
62         SCPI_CMD_GET_OVER_CURRENT_PROTECTION_ENABLED,
63         SCPI_CMD_SET_OVER_CURRENT_PROTECTION_ENABLE,
64         SCPI_CMD_SET_OVER_CURRENT_PROTECTION_DISABLE,
65         SCPI_CMD_GET_OVER_CURRENT_PROTECTION_ACTIVE,
66         SCPI_CMD_GET_OVER_CURRENT_PROTECTION_THRESHOLD,
67         SCPI_CMD_SET_OVER_CURRENT_PROTECTION_THRESHOLD,
68 };
69
70 /* Defines the SCPI dialect */
71 enum pps_scpi_dialect {
72         SCPI_DIALECT_UNKNOWN = 1,
73         SCPI_DIALECT_HP_COMP,
74         SCPI_DIALECT_HP_66XXB,
75         SCPI_DIALECT_PHILIPS,
76 };
77
78 /*
79  * These are bit values denoting features a device can have either globally,
80  * in scpi_pps.features, or on a per-channel-group basis in
81  * channel_group_spec.features.
82  */
83 enum pps_features {
84         PPS_OTP           = (1 << 0),
85         PPS_OVP           = (1 << 1),
86         PPS_OCP           = (1 << 2),
87         PPS_INDEPENDENT   = (1 << 3),
88         PPS_SERIES        = (1 << 4),
89         PPS_PARALLEL      = (1 << 5),
90 };
91
92 struct scpi_pps {
93         const char *vendor;
94         const char *model;
95         const enum pps_scpi_dialect dialect;
96         uint64_t features;
97         const uint32_t *devopts;
98         unsigned int num_devopts;
99         const uint32_t *devopts_cg;
100         unsigned int num_devopts_cg;
101         const struct channel_spec *channels;
102         unsigned int num_channels;
103         const struct channel_group_spec *channel_groups;
104         unsigned int num_channel_groups;
105         const struct scpi_command *commands;
106         int (*probe_channels) (struct sr_dev_inst *sdi, struct sr_scpi_hw_info *hwinfo,
107                 struct channel_spec **channels, unsigned int *num_channels,
108                 struct channel_group_spec **channel_groups, unsigned int *num_channel_groups);
109 };
110
111 struct channel_spec {
112         const char *name;
113         /* Min, max, programming resolution, spec digits, encoding digits. */
114         double voltage[5];
115         double current[5];
116         double power[5];
117         double frequency[5];
118         double ovp[5];
119         double ocp[5];
120 };
121
122 struct channel_group_spec {
123         const char *name;
124         uint64_t channel_index_mask;
125         uint64_t features;
126 };
127
128 struct pps_channel {
129         enum sr_mq mq;
130         unsigned int hw_output_idx;
131         const char *hwname;
132         int digits;
133 };
134
135 struct pps_channel_instance {
136         enum sr_mq mq;
137         int command;
138         const char *prefix;
139 };
140
141 struct pps_channel_group {
142         uint64_t features;
143 };
144
145 enum acq_states {
146         STATE_VOLTAGE,
147         STATE_CURRENT,
148         STATE_STOP,
149 };
150
151 struct dev_context {
152         const struct scpi_pps *device;
153
154         gboolean beeper_was_set;
155         struct channel_spec *channels;
156         struct channel_group_spec *channel_groups;
157
158         struct sr_channel *cur_acquisition_channel;
159         struct sr_sw_limits limits;
160 };
161
162 SR_PRIV extern unsigned int num_pps_profiles;
163 SR_PRIV extern const struct scpi_pps pps_profiles[];
164
165 SR_PRIV int select_channel(const struct sr_dev_inst *sdi, struct sr_channel *ch);
166 SR_PRIV int scpi_pps_receive_data(int fd, int revents, void *cb_data);
167
168 #endif