]> sigrok.org Git - libsigrok.git/blame - src/hardware/scpi-pps/protocol.h
output/csv: use intermediate time_t var, silence compiler warning
[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>
7e66bf05 5 * Copyright (C) 2017,2019 Frank Stettner <frank-stettner@gmx.net>
ca1a7cb5
BV
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>
c1aae900 26#include <libsigrok/libsigrok.h>
ca1a7cb5 27#include "libsigrok-internal.h"
91ef511d 28#include "scpi.h"
ca1a7cb5
BV
29
30#define LOG_PREFIX "scpi-pps"
31
9e45cd41 32enum pps_scpi_cmds {
17a82e83 33 SCPI_CMD_REMOTE = 1,
60475cd7 34 SCPI_CMD_LOCAL,
ee2860ee
BV
35 SCPI_CMD_BEEPER,
36 SCPI_CMD_BEEPER_ENABLE,
37 SCPI_CMD_BEEPER_DISABLE,
60475cd7 38 SCPI_CMD_SELECT_CHANNEL,
9e45cd41
BV
39 SCPI_CMD_GET_MEAS_VOLTAGE,
40 SCPI_CMD_GET_MEAS_CURRENT,
41 SCPI_CMD_GET_MEAS_POWER,
4264f1c0 42 SCPI_CMD_GET_MEAS_FREQUENCY,
ca95e90f
BV
43 SCPI_CMD_GET_VOLTAGE_TARGET,
44 SCPI_CMD_SET_VOLTAGE_TARGET,
4264f1c0
AG
45 SCPI_CMD_GET_FREQUENCY_TARGET,
46 SCPI_CMD_SET_FREQUENCY_TARGET,
ca95e90f
BV
47 SCPI_CMD_GET_CURRENT_LIMIT,
48 SCPI_CMD_SET_CURRENT_LIMIT,
9e45cd41 49 SCPI_CMD_GET_OUTPUT_ENABLED,
53a81803
BV
50 SCPI_CMD_SET_OUTPUT_ENABLE,
51 SCPI_CMD_SET_OUTPUT_DISABLE,
9e45cd41
BV
52 SCPI_CMD_GET_OUTPUT_REGULATION,
53 SCPI_CMD_GET_OVER_TEMPERATURE_PROTECTION,
53a81803
BV
54 SCPI_CMD_SET_OVER_TEMPERATURE_PROTECTION_ENABLE,
55 SCPI_CMD_SET_OVER_TEMPERATURE_PROTECTION_DISABLE,
8b5eadf4 56 SCPI_CMD_GET_OVER_TEMPERATURE_PROTECTION_ACTIVE,
9e45cd41 57 SCPI_CMD_GET_OVER_VOLTAGE_PROTECTION_ENABLED,
53a81803
BV
58 SCPI_CMD_SET_OVER_VOLTAGE_PROTECTION_ENABLE,
59 SCPI_CMD_SET_OVER_VOLTAGE_PROTECTION_DISABLE,
9e45cd41
BV
60 SCPI_CMD_GET_OVER_VOLTAGE_PROTECTION_ACTIVE,
61 SCPI_CMD_GET_OVER_VOLTAGE_PROTECTION_THRESHOLD,
62 SCPI_CMD_SET_OVER_VOLTAGE_PROTECTION_THRESHOLD,
63 SCPI_CMD_GET_OVER_CURRENT_PROTECTION_ENABLED,
53a81803
BV
64 SCPI_CMD_SET_OVER_CURRENT_PROTECTION_ENABLE,
65 SCPI_CMD_SET_OVER_CURRENT_PROTECTION_DISABLE,
9e45cd41
BV
66 SCPI_CMD_GET_OVER_CURRENT_PROTECTION_ACTIVE,
67 SCPI_CMD_GET_OVER_CURRENT_PROTECTION_THRESHOLD,
68 SCPI_CMD_SET_OVER_CURRENT_PROTECTION_THRESHOLD,
aec7d855
MS
69 SCPI_CMD_GET_OVER_CURRENT_PROTECTION_DELAY,
70 SCPI_CMD_SET_OVER_CURRENT_PROTECTION_DELAY,
9e45cd41
BV
71};
72
5e7377f4
FS
73/* Defines the SCPI dialect */
74enum pps_scpi_dialect {
75 SCPI_DIALECT_UNKNOWN = 1,
76 SCPI_DIALECT_HP_COMP,
77 SCPI_DIALECT_HP_66XXB,
78 SCPI_DIALECT_PHILIPS,
bd5f0a14 79 SCPI_DIALECT_HMP,
5e7377f4
FS
80};
81
9e45cd41
BV
82/*
83 * These are bit values denoting features a device can have either globally,
84 * in scpi_pps.features, or on a per-channel-group basis in
85 * channel_group_spec.features.
86 */
87enum pps_features {
88 PPS_OTP = (1 << 0),
89 PPS_OVP = (1 << 1),
90 PPS_OCP = (1 << 2),
91 PPS_INDEPENDENT = (1 << 3),
92 PPS_SERIES = (1 << 4),
93 PPS_PARALLEL = (1 << 5),
94};
95
96struct scpi_pps {
329733d9
UH
97 const char *vendor;
98 const char *model;
5e7377f4 99 const enum pps_scpi_dialect dialect;
9e45cd41 100 uint64_t features;
584560f1 101 const uint32_t *devopts;
9e45cd41 102 unsigned int num_devopts;
584560f1 103 const uint32_t *devopts_cg;
9e45cd41 104 unsigned int num_devopts_cg;
329733d9 105 const struct channel_spec *channels;
9e45cd41 106 unsigned int num_channels;
329733d9 107 const struct channel_group_spec *channel_groups;
9e45cd41 108 unsigned int num_channel_groups;
329733d9 109 const struct scpi_command *commands;
4a471029
BV
110 int (*probe_channels) (struct sr_dev_inst *sdi, struct sr_scpi_hw_info *hwinfo,
111 struct channel_spec **channels, unsigned int *num_channels,
112 struct channel_group_spec **channel_groups, unsigned int *num_channel_groups);
fd243315 113 int (*init_acquisition) (const struct sr_dev_inst *sdi);
7e66bf05 114 int (*update_status) (const struct sr_dev_inst *sdi);
9e45cd41
BV
115};
116
117struct channel_spec {
329733d9 118 const char *name;
6ed709fe 119 /* Min, max, programming resolution, spec digits, encoding digits. */
bcee1299
UH
120 double voltage[5];
121 double current[5];
122 double power[5];
123 double frequency[5];
49a468ed
FS
124 double ovp[5];
125 double ocp[5];
aec7d855 126 double ocp_delay[5];
9e45cd41
BV
127};
128
9e45cd41 129struct channel_group_spec {
329733d9 130 const char *name;
9e45cd41
BV
131 uint64_t channel_index_mask;
132 uint64_t features;
f2bbcc33
FS
133 /* The mqflags will only be applied to voltage and current channels! */
134 enum sr_mqflag mqflags;
9e45cd41
BV
135};
136
01b0257a 137struct pps_channel {
0de290a5 138 enum sr_mq mq;
f2bbcc33 139 enum sr_mqflag mqflags;
01b0257a 140 unsigned int hw_output_idx;
329733d9 141 const char *hwname;
6ed709fe 142 int digits;
01b0257a
BV
143};
144
145struct pps_channel_instance {
0de290a5 146 enum sr_mq mq;
01b0257a 147 int command;
329733d9 148 const char *prefix;
01b0257a
BV
149};
150
9e45cd41
BV
151struct pps_channel_group {
152 uint64_t features;
153};
154
155enum acq_states {
156 STATE_VOLTAGE,
157 STATE_CURRENT,
158 STATE_STOP,
159};
160
ca1a7cb5 161struct dev_context {
9e45cd41 162 const struct scpi_pps *device;
ca1a7cb5 163
ee2860ee 164 gboolean beeper_was_set;
4a471029
BV
165 struct channel_spec *channels;
166 struct channel_group_spec *channel_groups;
ca1a7cb5 167
17a82e83 168 struct sr_channel *cur_acquisition_channel;
88e4daa9 169 struct sr_sw_limits limits;
ca1a7cb5
BV
170};
171
562a3490
UH
172SR_PRIV extern unsigned int num_pps_profiles;
173SR_PRIV extern const struct scpi_pps pps_profiles[];
174
60475cd7 175SR_PRIV int select_channel(const struct sr_dev_inst *sdi, struct sr_channel *ch);
ca1a7cb5
BV
176SR_PRIV int scpi_pps_receive_data(int fd, int revents, void *cb_data);
177
178#endif