]>
Commit | Line | Data |
---|---|---|
df92e5cf | 1 | /* |
50985c20 | 2 | * This file is part of the libsigrok project. |
df92e5cf | 3 | * |
f48cef78 UH |
4 | * Copyright (C) 2011 Daniel Ribeiro <drwyrm@gmail.com> |
5 | * Copyright (C) 2012 Renato Caldas <rmsc@fe.up.pt> | |
6 | * Copyright (C) 2013 Lior Elazary <lelazary@yahoo.com> | |
df92e5cf | 7 | * |
8 | * This program is free software: you can redistribute it and/or modify | |
9 | * it under the terms of the GNU General Public License as published by | |
10 | * the Free Software Foundation, either version 3 of the License, or | |
11 | * (at your option) any later version. | |
12 | * | |
13 | * This program is distributed in the hope that it will be useful, | |
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
16 | * GNU General Public License for more details. | |
17 | * | |
18 | * You should have received a copy of the GNU General Public License | |
19 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | |
20 | */ | |
21 | ||
22 | #ifndef LIBSIGROK_HARDWARE_LINK_MSO19_PROTOCOL_H | |
23 | #define LIBSIGROK_HARDWARE_LINK_MSO19_PROTOCOL_H | |
24 | ||
df92e5cf | 25 | #include <stdint.h> |
26 | #include <string.h> | |
27 | #include <glib.h> | |
753d722f | 28 | #include <libudev.h> |
c1aae900 | 29 | #include <libsigrok/libsigrok.h> |
df92e5cf | 30 | #include "libsigrok-internal.h" |
31 | ||
b95dd761 | 32 | #define LOG_PREFIX "link-mso19" |
df92e5cf | 33 | |
00b44ccb UH |
34 | #define USB_VENDOR "3195" |
35 | #define USB_PRODUCT "f190" | |
36 | ||
00b44ccb | 37 | #define NUM_TRIGGER_STAGES 4 |
c50277a6 | 38 | #define TRIGGER_TYPE "01" //the first r/f is used for the whole group |
00b44ccb UH |
39 | #define SERIALCOMM "460800/8n1/flow=2" |
40 | #define SERIALCONN "/dev/ttyUSB0" | |
41 | #define CLOCK_RATE SR_MHZ(100) | |
42 | #define MIN_NUM_SAMPLES 4 | |
df92e5cf | 43 | |
df92e5cf | 44 | #define MSO_TRIGGER_UNKNOWN '!' |
45 | #define MSO_TRIGGER_UNKNOWN1 '1' | |
46 | #define MSO_TRIGGER_UNKNOWN2 '2' | |
47 | #define MSO_TRIGGER_UNKNOWN3 '3' | |
48 | #define MSO_TRIGGER_WAIT '4' | |
49 | #define MSO_TRIGGER_FIRED '5' | |
50 | #define MSO_TRIGGER_DATAREADY '6' | |
51 | ||
087a9161 | 52 | enum trigger_slopes { |
00b44ccb UH |
53 | SLOPE_POSITIVE = 0, |
54 | SLOPE_NEGATIVE, | |
087a9161 | 55 | }; |
56 | ||
df92e5cf | 57 | /* Structure for the pattern generator state */ |
58 | struct mso_patgen { | |
59 | /* Pattern generator clock config */ | |
60 | uint16_t clock; | |
61 | /* Buffer start address */ | |
62 | uint16_t start; | |
63 | /* Buffer end address */ | |
64 | uint16_t end; | |
65 | /* Pattern generator config */ | |
66 | uint8_t config; | |
67 | /* Samples buffer */ | |
68 | uint8_t buffer[1024]; | |
00b44ccb | 69 | /* Input/output configuration for the samples buffer (?) */ |
df92e5cf | 70 | uint8_t io[1024]; |
71 | /* Number of loops for the pattern generator */ | |
72 | uint8_t loops; | |
73 | /* Bit enable mask for the I/O lines */ | |
74 | uint8_t mask; | |
75 | }; | |
76 | ||
77 | /* Data structure for the protocol trigger state */ | |
78 | struct mso_prototrig { | |
79 | /* Word match buffer */ | |
80 | uint8_t word[4]; | |
81 | /* Masks for the wordmatch buffer */ | |
82 | uint8_t mask[4]; | |
83 | /* SPI mode 0, 1, 2, 3. Set to 0 for I2C */ | |
84 | uint8_t spimode; | |
85 | }; | |
86 | ||
87 | /* Private, per-device-instance driver context. */ | |
88 | struct dev_context { | |
89 | /* info */ | |
90 | uint8_t hwmodel; | |
91 | uint8_t hwrev; | |
92 | struct sr_serial_dev_inst *serial; | |
00b44ccb | 93 | // uint8_t num_sample_rates; |
df92e5cf | 94 | /* calibration */ |
95 | double vbit; | |
96 | uint16_t dac_offset; | |
97 | uint16_t offset_range; | |
00b44ccb UH |
98 | uint64_t limit_samples; |
99 | uint64_t num_samples; | |
df92e5cf | 100 | /* register cache */ |
101 | uint8_t ctlbase1; | |
102 | uint8_t ctlbase2; | |
103 | /* state */ | |
104 | uint8_t la_threshold; | |
105 | uint64_t cur_rate; | |
106 | uint8_t dso_probe_attn; | |
00b44ccb | 107 | int8_t use_trigger; |
df92e5cf | 108 | uint8_t trigger_chan; |
109 | uint8_t trigger_slope; | |
110 | uint8_t trigger_outsrc; | |
111 | uint8_t trigger_state; | |
087a9161 | 112 | uint8_t trigger_holdoff[2]; |
df92e5cf | 113 | uint8_t la_trigger; |
114 | uint8_t la_trigger_mask; | |
115 | double dso_trigger_voltage; | |
116 | uint16_t dso_trigger_width; | |
117 | struct mso_prototrig protocol_trigger; | |
3e9b7f9c | 118 | void *cb_data; |
df92e5cf | 119 | uint16_t buffer_n; |
120 | char buffer[4096]; | |
121 | }; | |
122 | ||
123 | SR_PRIV int mso_parse_serial(const char *iSerial, const char *iProduct, | |
00b44ccb UH |
124 | struct dev_context *ctx); |
125 | SR_PRIV int mso_check_trigger(struct sr_serial_dev_inst *serial, | |
126 | uint8_t * info); | |
df92e5cf | 127 | SR_PRIV int mso_reset_adc(struct sr_dev_inst *sdi); |
128 | SR_PRIV int mso_clkrate_out(struct sr_serial_dev_inst *serial, uint16_t val); | |
753d722f | 129 | SR_PRIV int mso_configure_rate(const struct sr_dev_inst *sdi, uint32_t rate); |
df92e5cf | 130 | SR_PRIV int mso_receive_data(int fd, int revents, void *cb_data); |
753d722f UH |
131 | SR_PRIV int mso_configure_trigger(const struct sr_dev_inst *sdi); |
132 | SR_PRIV int mso_configure_threshold_level(const struct sr_dev_inst *sdi); | |
4b719338 | 133 | SR_PRIV int mso_read_buffer(struct sr_dev_inst *sdi); |
753d722f | 134 | SR_PRIV int mso_arm(const struct sr_dev_inst *sdi); |
4b719338 | 135 | SR_PRIV int mso_force_capture(struct sr_dev_inst *sdi); |
753d722f | 136 | SR_PRIV int mso_dac_out(const struct sr_dev_inst *sdi, uint16_t val); |
c442ffda | 137 | SR_PRIV uint16_t mso_calc_raw_from_mv(struct dev_context *devc); |
4db2aaff | 138 | SR_PRIV int mso_reset_fsm(struct sr_dev_inst *sdi); |
139 | SR_PRIV int mso_toggle_led(struct sr_dev_inst *sdi, int state); | |
4b719338 | 140 | |
ba7dd8bb | 141 | SR_PRIV int mso_configure_channels(const struct sr_dev_inst *sdi); |
df92e5cf | 142 | SR_PRIV void stop_acquisition(const struct sr_dev_inst *sdi); |
143 | ||
df92e5cf | 144 | /* bank agnostic registers */ |
145 | #define REG_CTL2 15 | |
146 | ||
147 | /* bank 0 registers */ | |
148 | #define REG_BUFFER 1 | |
149 | #define REG_TRIGGER 2 | |
150 | #define REG_CLKRATE1 9 | |
151 | #define REG_CLKRATE2 10 | |
152 | #define REG_DAC1 12 | |
153 | #define REG_DAC2 13 | |
154 | /* possibly bank agnostic: */ | |
155 | #define REG_CTL1 14 | |
156 | ||
157 | /* bank 2 registers (SPI/I2C protocol trigger) */ | |
00b44ccb UH |
158 | #define REG_PT_WORD(x) (x) |
159 | #define REG_PT_MASK(x) (x + 4) | |
160 | #define REG_PT_SPIMODE 8 | |
df92e5cf | 161 | |
162 | /* bits - REG_CTL1 */ | |
00b44ccb UH |
163 | #define BIT_CTL1_RESETFSM (1 << 0) |
164 | #define BIT_CTL1_ARM (1 << 1) | |
165 | #define BIT_CTL1_ADC_UNKNOWN4 (1 << 4) /* adc enable? */ | |
166 | #define BIT_CTL1_RESETADC (1 << 6) | |
167 | #define BIT_CTL1_LED (1 << 7) | |
df92e5cf | 168 | |
169 | /* bits - REG_CTL2 */ | |
00b44ccb UH |
170 | #define BITS_CTL2_BANK(x) (x & 0x3) |
171 | #define BIT_CTL2_SLOWMODE (1 << 5) | |
df92e5cf | 172 | |
173 | struct rate_map { | |
174 | uint32_t rate; | |
175 | uint16_t val; | |
176 | uint8_t slowmode; | |
177 | }; | |
178 | ||
753d722f | 179 | static const struct rate_map rate_map[] = { |
00b44ccb UH |
180 | { SR_MHZ(200), 0x0205, 0 }, |
181 | { SR_MHZ(100), 0x0105, 0 }, | |
182 | { SR_MHZ(50), 0x0005, 0 }, | |
183 | { SR_MHZ(20), 0x0303, 0 }, | |
184 | { SR_MHZ(10), 0x0308, 0 }, | |
185 | { SR_MHZ(5), 0x030c, 0 }, | |
186 | { SR_MHZ(2), 0x0330, 0 }, | |
187 | { SR_MHZ(1), 0x0362, 0 }, | |
188 | { SR_KHZ(500), 0x03c6, 0 }, | |
189 | { SR_KHZ(200), 0x07f2, 0 }, | |
190 | { SR_KHZ(100), 0x0fe6, 0 }, | |
191 | { SR_KHZ(50), 0x1fce, 0 }, | |
192 | { SR_KHZ(20), 0x4f86, 0 }, | |
193 | { SR_KHZ(10), 0x9f0e, 0 }, | |
194 | { SR_KHZ(5), 0x03c7, 0x20 }, | |
195 | { SR_KHZ(2), 0x07f3, 0x20 }, | |
196 | { SR_KHZ(1), 0x0fe7, 0x20 }, | |
197 | { SR_HZ(500), 0x1fcf, 0x20 }, | |
198 | { SR_HZ(200), 0x4f87, 0x20 }, | |
199 | { SR_HZ(100), 0x9f0f, 0x20 }, | |
df92e5cf | 200 | }; |
201 | ||
202 | /* FIXME: Determine corresponding voltages */ | |
753d722f | 203 | static const uint16_t la_threshold_map[] = { |
df92e5cf | 204 | 0x8600, |
205 | 0x8770, | |
206 | 0x88ff, | |
207 | 0x8c70, | |
208 | 0x8eff, | |
209 | 0x8fff, | |
210 | }; | |
211 | ||
df92e5cf | 212 | #endif |