]>
Commit | Line | Data |
---|---|---|
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 | 30 | enum 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, | |
4264f1c0 | 40 | SCPI_CMD_GET_MEAS_FREQUENCY, |
ca95e90f BV |
41 | SCPI_CMD_GET_VOLTAGE_TARGET, |
42 | SCPI_CMD_SET_VOLTAGE_TARGET, | |
4264f1c0 AG |
43 | SCPI_CMD_GET_FREQUENCY_TARGET, |
44 | SCPI_CMD_SET_FREQUENCY_TARGET, | |
ca95e90f BV |
45 | SCPI_CMD_GET_CURRENT_LIMIT, |
46 | SCPI_CMD_SET_CURRENT_LIMIT, | |
9e45cd41 | 47 | SCPI_CMD_GET_OUTPUT_ENABLED, |
53a81803 BV |
48 | SCPI_CMD_SET_OUTPUT_ENABLE, |
49 | SCPI_CMD_SET_OUTPUT_DISABLE, | |
9e45cd41 BV |
50 | SCPI_CMD_GET_OUTPUT_REGULATION, |
51 | SCPI_CMD_GET_OVER_TEMPERATURE_PROTECTION, | |
53a81803 BV |
52 | SCPI_CMD_SET_OVER_TEMPERATURE_PROTECTION_ENABLE, |
53 | SCPI_CMD_SET_OVER_TEMPERATURE_PROTECTION_DISABLE, | |
9e45cd41 | 54 | SCPI_CMD_GET_OVER_VOLTAGE_PROTECTION_ENABLED, |
53a81803 BV |
55 | SCPI_CMD_SET_OVER_VOLTAGE_PROTECTION_ENABLE, |
56 | SCPI_CMD_SET_OVER_VOLTAGE_PROTECTION_DISABLE, | |
9e45cd41 BV |
57 | SCPI_CMD_GET_OVER_VOLTAGE_PROTECTION_ACTIVE, |
58 | SCPI_CMD_GET_OVER_VOLTAGE_PROTECTION_THRESHOLD, | |
59 | SCPI_CMD_SET_OVER_VOLTAGE_PROTECTION_THRESHOLD, | |
60 | SCPI_CMD_GET_OVER_CURRENT_PROTECTION_ENABLED, | |
53a81803 BV |
61 | SCPI_CMD_SET_OVER_CURRENT_PROTECTION_ENABLE, |
62 | SCPI_CMD_SET_OVER_CURRENT_PROTECTION_DISABLE, | |
9e45cd41 BV |
63 | SCPI_CMD_GET_OVER_CURRENT_PROTECTION_ACTIVE, |
64 | SCPI_CMD_GET_OVER_CURRENT_PROTECTION_THRESHOLD, | |
65 | SCPI_CMD_SET_OVER_CURRENT_PROTECTION_THRESHOLD, | |
9e45cd41 BV |
66 | }; |
67 | ||
68 | /* | |
69 | * These are bit values denoting features a device can have either globally, | |
70 | * in scpi_pps.features, or on a per-channel-group basis in | |
71 | * channel_group_spec.features. | |
72 | */ | |
73 | enum pps_features { | |
74 | PPS_OTP = (1 << 0), | |
75 | PPS_OVP = (1 << 1), | |
76 | PPS_OCP = (1 << 2), | |
77 | PPS_INDEPENDENT = (1 << 3), | |
78 | PPS_SERIES = (1 << 4), | |
79 | PPS_PARALLEL = (1 << 5), | |
80 | }; | |
81 | ||
82 | struct scpi_pps { | |
329733d9 UH |
83 | const char *vendor; |
84 | const char *model; | |
9e45cd41 | 85 | uint64_t features; |
584560f1 | 86 | const uint32_t *devopts; |
9e45cd41 | 87 | unsigned int num_devopts; |
584560f1 | 88 | const uint32_t *devopts_cg; |
9e45cd41 | 89 | unsigned int num_devopts_cg; |
329733d9 | 90 | const struct channel_spec *channels; |
9e45cd41 | 91 | unsigned int num_channels; |
329733d9 | 92 | const struct channel_group_spec *channel_groups; |
9e45cd41 | 93 | unsigned int num_channel_groups; |
329733d9 | 94 | const struct scpi_command *commands; |
9e45cd41 | 95 | unsigned int num_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 | ||
101 | struct channel_spec { | |
329733d9 | 102 | const char *name; |
9e45cd41 BV |
103 | /* Min, max, programming resolution. */ |
104 | float voltage[3]; | |
105 | float current[3]; | |
4264f1c0 | 106 | float frequency[3]; |
9e45cd41 BV |
107 | }; |
108 | ||
109 | struct scpi_command { | |
110 | int command; | |
329733d9 | 111 | const char *string; |
9e45cd41 BV |
112 | }; |
113 | ||
114 | struct channel_group_spec { | |
329733d9 | 115 | const char *name; |
9e45cd41 BV |
116 | uint64_t channel_index_mask; |
117 | uint64_t features; | |
118 | }; | |
119 | ||
01b0257a BV |
120 | struct pps_channel { |
121 | int mq; | |
122 | unsigned int hw_output_idx; | |
329733d9 | 123 | const char *hwname; |
01b0257a BV |
124 | }; |
125 | ||
126 | struct pps_channel_instance { | |
127 | int mq; | |
128 | int command; | |
329733d9 | 129 | const char *prefix; |
01b0257a BV |
130 | }; |
131 | ||
9e45cd41 BV |
132 | struct pps_channel_group { |
133 | uint64_t features; | |
134 | }; | |
135 | ||
136 | enum acq_states { | |
137 | STATE_VOLTAGE, | |
138 | STATE_CURRENT, | |
139 | STATE_STOP, | |
140 | }; | |
141 | ||
ca1a7cb5 BV |
142 | /** Private, per-device-instance driver context. */ |
143 | struct dev_context { | |
144 | /* Model-specific information */ | |
9e45cd41 | 145 | const struct scpi_pps *device; |
ca1a7cb5 BV |
146 | |
147 | /* Acquisition settings */ | |
9e45cd41 | 148 | void *cb_data; |
ca1a7cb5 BV |
149 | |
150 | /* Operational state */ | |
ee2860ee | 151 | gboolean beeper_was_set; |
4a471029 BV |
152 | struct channel_spec *channels; |
153 | struct channel_group_spec *channel_groups; | |
ca1a7cb5 BV |
154 | |
155 | /* Temporary state across callbacks */ | |
9e45cd41 | 156 | struct sr_channel *cur_channel; |
ca1a7cb5 BV |
157 | }; |
158 | ||
562a3490 UH |
159 | SR_PRIV extern unsigned int num_pps_profiles; |
160 | SR_PRIV extern const struct scpi_pps pps_profiles[]; | |
161 | ||
162 | SR_PRIV const char *get_vendor(const char *raw_vendor); | |
329733d9 | 163 | SR_PRIV const char *scpi_cmd_get(const struct sr_dev_inst *sdi, int command); |
9e45cd41 | 164 | SR_PRIV int scpi_cmd(const struct sr_dev_inst *sdi, int command, ...); |
478c8d92 BV |
165 | SR_PRIV int scpi_cmd_resp(const struct sr_dev_inst *sdi, GVariant **gvar, |
166 | const GVariantType *gvtype, int command, ...); | |
60475cd7 | 167 | SR_PRIV int select_channel(const struct sr_dev_inst *sdi, struct sr_channel *ch); |
624503ae BV |
168 | SR_PRIV struct sr_channel *next_enabled_channel(const struct sr_dev_inst *sdi, |
169 | struct sr_channel *cur_channel); | |
ca1a7cb5 BV |
170 | SR_PRIV int scpi_pps_receive_data(int fd, int revents, void *cb_data); |
171 | ||
172 | #endif |