]> sigrok.org Git - libsigrok.git/blame - src/hardware/scpi-pps/protocol.h
scpi-pps: Reimplemention of switching channel groups (PSU channels)
[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>
c1aae900 25#include <libsigrok/libsigrok.h>
ca1a7cb5 26#include "libsigrok-internal.h"
91ef511d 27#include "scpi.h"
ca1a7cb5
BV
28
29#define LOG_PREFIX "scpi-pps"
30
9e45cd41 31enum pps_scpi_cmds {
17a82e83 32 SCPI_CMD_REMOTE = 1,
60475cd7 33 SCPI_CMD_LOCAL,
ee2860ee
BV
34 SCPI_CMD_BEEPER,
35 SCPI_CMD_BEEPER_ENABLE,
36 SCPI_CMD_BEEPER_DISABLE,
60475cd7 37 SCPI_CMD_SELECT_CHANNEL,
9e45cd41
BV
38 SCPI_CMD_GET_MEAS_VOLTAGE,
39 SCPI_CMD_GET_MEAS_CURRENT,
40 SCPI_CMD_GET_MEAS_POWER,
4264f1c0 41 SCPI_CMD_GET_MEAS_FREQUENCY,
ca95e90f
BV
42 SCPI_CMD_GET_VOLTAGE_TARGET,
43 SCPI_CMD_SET_VOLTAGE_TARGET,
4264f1c0
AG
44 SCPI_CMD_GET_FREQUENCY_TARGET,
45 SCPI_CMD_SET_FREQUENCY_TARGET,
ca95e90f
BV
46 SCPI_CMD_GET_CURRENT_LIMIT,
47 SCPI_CMD_SET_CURRENT_LIMIT,
9e45cd41 48 SCPI_CMD_GET_OUTPUT_ENABLED,
53a81803
BV
49 SCPI_CMD_SET_OUTPUT_ENABLE,
50 SCPI_CMD_SET_OUTPUT_DISABLE,
9e45cd41
BV
51 SCPI_CMD_GET_OUTPUT_REGULATION,
52 SCPI_CMD_GET_OVER_TEMPERATURE_PROTECTION,
53a81803
BV
53 SCPI_CMD_SET_OVER_TEMPERATURE_PROTECTION_ENABLE,
54 SCPI_CMD_SET_OVER_TEMPERATURE_PROTECTION_DISABLE,
9e45cd41 55 SCPI_CMD_GET_OVER_VOLTAGE_PROTECTION_ENABLED,
53a81803
BV
56 SCPI_CMD_SET_OVER_VOLTAGE_PROTECTION_ENABLE,
57 SCPI_CMD_SET_OVER_VOLTAGE_PROTECTION_DISABLE,
9e45cd41
BV
58 SCPI_CMD_GET_OVER_VOLTAGE_PROTECTION_ACTIVE,
59 SCPI_CMD_GET_OVER_VOLTAGE_PROTECTION_THRESHOLD,
60 SCPI_CMD_SET_OVER_VOLTAGE_PROTECTION_THRESHOLD,
61 SCPI_CMD_GET_OVER_CURRENT_PROTECTION_ENABLED,
53a81803
BV
62 SCPI_CMD_SET_OVER_CURRENT_PROTECTION_ENABLE,
63 SCPI_CMD_SET_OVER_CURRENT_PROTECTION_DISABLE,
9e45cd41
BV
64 SCPI_CMD_GET_OVER_CURRENT_PROTECTION_ACTIVE,
65 SCPI_CMD_GET_OVER_CURRENT_PROTECTION_THRESHOLD,
66 SCPI_CMD_SET_OVER_CURRENT_PROTECTION_THRESHOLD,
9e45cd41
BV
67};
68
69/*
70 * These are bit values denoting features a device can have either globally,
71 * in scpi_pps.features, or on a per-channel-group basis in
72 * channel_group_spec.features.
73 */
74enum pps_features {
75 PPS_OTP = (1 << 0),
76 PPS_OVP = (1 << 1),
77 PPS_OCP = (1 << 2),
78 PPS_INDEPENDENT = (1 << 3),
79 PPS_SERIES = (1 << 4),
80 PPS_PARALLEL = (1 << 5),
81};
82
83struct scpi_pps {
329733d9
UH
84 const char *vendor;
85 const char *model;
9e45cd41 86 uint64_t features;
584560f1 87 const uint32_t *devopts;
9e45cd41 88 unsigned int num_devopts;
584560f1 89 const uint32_t *devopts_cg;
9e45cd41 90 unsigned int num_devopts_cg;
329733d9 91 const struct channel_spec *channels;
9e45cd41 92 unsigned int num_channels;
329733d9 93 const struct channel_group_spec *channel_groups;
9e45cd41 94 unsigned int num_channel_groups;
329733d9 95 const struct scpi_command *commands;
4a471029
BV
96 int (*probe_channels) (struct sr_dev_inst *sdi, struct sr_scpi_hw_info *hwinfo,
97 struct channel_spec **channels, unsigned int *num_channels,
98 struct channel_group_spec **channel_groups, unsigned int *num_channel_groups);
9e45cd41
BV
99};
100
101struct channel_spec {
329733d9 102 const char *name;
6ed709fe 103 /* Min, max, programming resolution, spec digits, encoding digits. */
bcee1299
UH
104 double voltage[5];
105 double current[5];
106 double power[5];
107 double frequency[5];
9e45cd41
BV
108};
109
9e45cd41 110struct channel_group_spec {
329733d9 111 const char *name;
9e45cd41
BV
112 uint64_t channel_index_mask;
113 uint64_t features;
114};
115
01b0257a 116struct pps_channel {
0de290a5 117 enum sr_mq mq;
01b0257a 118 unsigned int hw_output_idx;
329733d9 119 const char *hwname;
6ed709fe 120 int digits;
01b0257a
BV
121};
122
123struct pps_channel_instance {
0de290a5 124 enum sr_mq mq;
01b0257a 125 int command;
329733d9 126 const char *prefix;
01b0257a
BV
127};
128
9e45cd41
BV
129struct pps_channel_group {
130 uint64_t features;
131};
132
133enum acq_states {
134 STATE_VOLTAGE,
135 STATE_CURRENT,
136 STATE_STOP,
137};
138
ca1a7cb5 139struct dev_context {
9e45cd41 140 const struct scpi_pps *device;
ca1a7cb5 141
ee2860ee 142 gboolean beeper_was_set;
4a471029
BV
143 struct channel_spec *channels;
144 struct channel_group_spec *channel_groups;
ca1a7cb5 145
17a82e83 146 struct sr_channel *cur_acquisition_channel;
ca1a7cb5
BV
147};
148
562a3490
UH
149SR_PRIV extern unsigned int num_pps_profiles;
150SR_PRIV extern const struct scpi_pps pps_profiles[];
151
60475cd7 152SR_PRIV int select_channel(const struct sr_dev_inst *sdi, struct sr_channel *ch);
ca1a7cb5
BV
153SR_PRIV int scpi_pps_receive_data(int fd, int revents, void *cb_data);
154
155#endif