]> sigrok.org Git - libsigrok.git/blame - src/hardware/hp-3478a/protocol.h
output/csv: use intermediate time_t var, silence compiler warning
[libsigrok.git] / src / hardware / hp-3478a / protocol.h
CommitLineData
1d9eebf4
FS
1/*
2 * This file is part of the libsigrok project.
3 *
569165c0 4 * Copyright (C) 2017-2021 Frank Stettner <frank-stettner@gmx.net>
1d9eebf4
FS
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_HP_3478A_PROTOCOL_H
21#define LIBSIGROK_HARDWARE_HP_3478A_PROTOCOL_H
22
23#include <stdint.h>
24#include <glib.h>
25#include <libsigrok/libsigrok.h>
26#include "libsigrok-internal.h"
27
28#define LOG_PREFIX "hp-3478a"
29
d2c1730a
FS
30#define SB1_FUNCTION_BLOCK 0b11100000
31#define SB1_RANGE_BLOCK 0b00011100
32#define SB1_DIGITS_BLOCK 0b00000011
33
569165c0 34/** Status Byte 1 (Function) */
d2c1730a
FS
35enum sb1_function {
36 FUNCTION_VDC = 0b00100000,
37 FUNCTION_VAC = 0b01000000,
38 FUNCTION_2WR = 0b01100000,
39 FUNCTION_4WR = 0b10000000,
40 FUNCTION_ADC = 0b10100000,
41 FUNCTION_AAC = 0b11000000,
42 FUNCTION_EXR = 0b11100000,
43};
44
569165c0 45/** Status Byte 1 (Range V DC) */
d2c1730a
FS
46enum sb1_range_vdc {
47 RANGE_VDC_30MV = 0b00000100,
48 RANGE_VDC_300MV = 0b00001000,
49 RANGE_VDC_3V = 0b00001100,
50 RANGE_VDC_30V = 0b00010000,
51 RANGE_VDC_300V = 0b00010100,
52};
53
569165c0 54/** Status Byte 1 (Range V AC) */
d2c1730a
FS
55enum sb1_range_vac {
56 RANGE_VAC_300MV = 0b00000100,
57 RANGE_VAC_3V = 0b00001000,
58 RANGE_VAC_30V = 0b00001100,
59 RANGE_VAC_300V = 0b00010000,
60};
61
569165c0 62/** Status Byte 1 (Range A) */
d2c1730a
FS
63enum sb1_range_a {
64 RANGE_A_300MA = 0b00000100,
65 RANGE_A_3A = 0b00001000,
66};
67
569165c0 68/** Status Byte 1 (Range Ohm) */
d2c1730a
FS
69enum sb1_range_ohm {
70 RANGE_OHM_30R = 0b00000100,
71 RANGE_OHM_300R = 0b00001000,
72 RANGE_OHM_3KR = 0b00001100,
73 RANGE_OHM_30KR = 0b00010000,
74 RANGE_OHM_300KR = 0b00010100,
75 RANGE_OHM_3MR = 0b00011000,
76 RANGE_OHM_30MR = 0b00011100,
77};
78
569165c0 79/** Status Byte 1 (Digits) */
d2c1730a
FS
80enum sb1_digits {
81 DIGITS_5_5 = 0b00000001,
82 DIGITS_4_5 = 0b00000010,
83 DIGITS_3_5 = 0b00000011,
84};
85
569165c0 86/** Status Byte 2 */
d2c1730a
FS
87enum sb2_status {
88 STATUS_INT_TRIGGER = (1 << 0),
89 STATUS_AUTO_RANGE = (1 << 1),
90 STATUS_AUTO_ZERO = (1 << 2),
91 STATUS_50HZ = (1 << 3),
92 STATUS_FRONT_TERMINAL = (1 << 4),
93 STATUS_CAL_RAM = (1 << 5),
94 STATUS_EXT_TRIGGER = (1 << 6),
95};
96
569165c0 97/** Status Byte 3 (Serial Poll Mask) */
d2c1730a
FS
98enum sb3_srq {
99 SRQ_BUS_AVAIL = (1 << 0),
100 SRQ_SYNTAX_ERR = (1 << 2),
101 SRQ_HARDWARE_ERR = (1 << 3),
102 SRQ_KEYBORD = (1 << 4),
103 SRQ_CAL_FAILED = (1 << 5),
104 SRQ_POWER_ON = (1 << 7),
105};
106
569165c0 107/** Status Byte 4 (Error) */
d2c1730a
FS
108enum sb4_error {
109 ERROR_SELF_TEST = (1 << 0),
110 ERROR_RAM_SELF_TEST = (1 << 1),
111 ERROR_ROM_SELF_TEST = (1 << 2),
112 ERROR_AD_SLOPE = (1 << 3),
113 ERROR_AD_SELF_TEST = (1 << 4),
114 ERROR_AD_LINK = (1 << 5),
115};
116
569165c0 117/** Channel connector (front terminals or rear terminals. */
d2c1730a
FS
118enum terminal_connector {
119 TERMINAL_FRONT,
120 TERMINAL_REAR,
121};
122
569165c0 123/** Available triggers */
d2c1730a
FS
124enum trigger_state {
125 TRIGGER_UNDEFINED,
126 TRIGGER_EXTERNAL,
127 TRIGGER_INTERNAL,
128};
129
569165c0 130/** Available line frequencies */
d2c1730a
FS
131enum line_freq {
132 LINE_50HZ,
133 LINE_60HZ,
134};
135
1d9eebf4 136struct dev_context {
d2c1730a
FS
137 struct sr_sw_limits limits;
138
139 double measurement;
140 enum sr_mq measurement_mq;
569165c0
FS
141 /**
142 * The measurement mq flag can contain none or one of the
143 * following flags: AC, DC, or 4-wire.
144 */
145 enum sr_mqflag measurement_mq_flag;
146 /**
147 * The acquisition mq flags can contain multiple flags,
148 * for example autoranging, RMS, etc.
149 */
e5137b93 150 enum sr_mqflag acquisition_mq_flags;
d2c1730a 151 enum sr_unit measurement_unit;
e5137b93 152 int range_exp;
c8260fa8
FS
153 /**
154 * The total number of digits. Rounded up from the resoultion of
155 * the device, so a 5.5 resolution would be 6 digits.
156 */
157 uint8_t digits;
158 /**
159 * The digits used for encoding.digits and spec.spec_digits in
160 * the analog payload.
161 */
162 uint8_t sr_digits;
d2c1730a
FS
163
164 enum terminal_connector terminal;
165 enum trigger_state trigger;
166 enum line_freq line;
167 gboolean auto_zero;
168 gboolean calibration;
169};
170
171struct channel_context {
172 int index;
173 enum terminal_connector location;
1d9eebf4
FS
174};
175
d2c1730a
FS
176SR_PRIV int hp_3478a_set_mq(const struct sr_dev_inst *sdi, enum sr_mq mq,
177 enum sr_mqflag mq_flags);
e5137b93 178SR_PRIV int hp_3478a_set_range(const struct sr_dev_inst *sdi, int range_exp);
7812a5c8 179SR_PRIV int hp_3478a_set_digits(const struct sr_dev_inst *sdi, uint8_t digits);
d2c1730a 180SR_PRIV int hp_3478a_get_status_bytes(const struct sr_dev_inst *sdi);
1d9eebf4
FS
181SR_PRIV int hp_3478a_receive_data(int fd, int revents, void *cb_data);
182
183#endif