]>
Commit | Line | Data |
---|---|---|
1d9eebf4 FS |
1 | /* |
2 | * This file is part of the libsigrok project. | |
3 | * | |
4 | * Copyright (C) 2017 Frank Stettner <frank-stettner@gmx.net> | |
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 | ||
34 | /* Status Byte 1 (Function) */ | |
35 | enum 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 | ||
45 | /* Status Byte 1 (Range V DC) */ | |
46 | enum 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 | ||
54 | /* Status Byte 1 (Range V AC) */ | |
55 | enum 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 | ||
62 | /* Status Byte 1 (Range A) */ | |
63 | enum sb1_range_a { | |
64 | RANGE_A_300MA = 0b00000100, | |
65 | RANGE_A_3A = 0b00001000, | |
66 | }; | |
67 | ||
68 | /* Status Byte 1 (Range Ohm) */ | |
69 | enum 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 | ||
79 | /* Status Byte 1 (Digits) */ | |
80 | enum sb1_digits { | |
81 | DIGITS_5_5 = 0b00000001, | |
82 | DIGITS_4_5 = 0b00000010, | |
83 | DIGITS_3_5 = 0b00000011, | |
84 | }; | |
85 | ||
86 | /* Status Byte 2 */ | |
87 | enum 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 | ||
97 | /* Status Byte 3 (Serial Poll Mask) */ | |
98 | enum 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 | ||
107 | /* Status Byte 4 (Error) */ | |
108 | enum 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 | ||
117 | /* Channel connector (front terminals or rear terminals. */ | |
118 | enum terminal_connector { | |
119 | TERMINAL_FRONT, | |
120 | TERMINAL_REAR, | |
121 | }; | |
122 | ||
123 | /* Possible triggers */ | |
124 | enum trigger_state { | |
125 | TRIGGER_UNDEFINED, | |
126 | TRIGGER_EXTERNAL, | |
127 | TRIGGER_INTERNAL, | |
128 | }; | |
129 | ||
130 | /* Possible line frequencies */ | |
131 | enum line_freq { | |
132 | LINE_50HZ, | |
133 | LINE_60HZ, | |
134 | }; | |
135 | ||
1d9eebf4 | 136 | struct dev_context { |
d2c1730a FS |
137 | struct sr_sw_limits limits; |
138 | ||
139 | double measurement; | |
140 | enum sr_mq measurement_mq; | |
e5137b93 | 141 | /** The measurement mq flags only contain flags for AC, DC and 4-wire. */ |
d2c1730a | 142 | enum sr_mqflag measurement_mq_flags; |
e5137b93 FS |
143 | /** The acquisition mq flags also contain flags for autoranging and RMS. */ |
144 | enum sr_mqflag acquisition_mq_flags; | |
d2c1730a | 145 | enum sr_unit measurement_unit; |
e5137b93 | 146 | int range_exp; |
d2c1730a FS |
147 | uint8_t enc_digits; |
148 | uint8_t spec_digits; | |
149 | ||
150 | enum terminal_connector terminal; | |
151 | enum trigger_state trigger; | |
152 | enum line_freq line; | |
153 | gboolean auto_zero; | |
154 | gboolean calibration; | |
155 | }; | |
156 | ||
157 | struct channel_context { | |
158 | int index; | |
159 | enum terminal_connector location; | |
1d9eebf4 FS |
160 | }; |
161 | ||
d2c1730a FS |
162 | SR_PRIV int hp_3478a_set_mq(const struct sr_dev_inst *sdi, enum sr_mq mq, |
163 | enum sr_mqflag mq_flags); | |
e5137b93 | 164 | SR_PRIV int hp_3478a_set_range(const struct sr_dev_inst *sdi, int range_exp); |
7812a5c8 | 165 | SR_PRIV int hp_3478a_set_digits(const struct sr_dev_inst *sdi, uint8_t digits); |
d2c1730a | 166 | SR_PRIV int hp_3478a_get_status_bytes(const struct sr_dev_inst *sdi); |
1d9eebf4 FS |
167 | SR_PRIV int hp_3478a_receive_data(int fd, int revents, void *cb_data); |
168 | ||
169 | #endif |