]>
Commit | Line | Data |
---|---|---|
1 | /* | |
2 | * This file is part of the libsigrok project. | |
3 | * | |
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> | |
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 | ||
25 | #include <stdint.h> | |
26 | #include <string.h> | |
27 | #include <glib.h> | |
28 | #include <libudev.h> | |
29 | #include "libsigrok.h" | |
30 | #include "libsigrok-internal.h" | |
31 | ||
32 | #define LOG_PREFIX "link-mso19" | |
33 | ||
34 | #define USB_VENDOR "3195" | |
35 | #define USB_PRODUCT "f190" | |
36 | ||
37 | #define NUM_CHANNELS (1 + 8) | |
38 | #define NUM_TRIGGER_STAGES 4 | |
39 | #define TRIGGER_TYPE "01" //the first r/f is used for the whole group | |
40 | #define SERIALCOMM "460800/8n1/flow=2" | |
41 | #define SERIALCONN "/dev/ttyUSB0" | |
42 | #define CLOCK_RATE SR_MHZ(100) | |
43 | #define MIN_NUM_SAMPLES 4 | |
44 | ||
45 | #define MSO_TRIGGER_UNKNOWN '!' | |
46 | #define MSO_TRIGGER_UNKNOWN1 '1' | |
47 | #define MSO_TRIGGER_UNKNOWN2 '2' | |
48 | #define MSO_TRIGGER_UNKNOWN3 '3' | |
49 | #define MSO_TRIGGER_WAIT '4' | |
50 | #define MSO_TRIGGER_FIRED '5' | |
51 | #define MSO_TRIGGER_DATAREADY '6' | |
52 | ||
53 | enum trigger_slopes { | |
54 | SLOPE_POSITIVE = 0, | |
55 | SLOPE_NEGATIVE, | |
56 | }; | |
57 | ||
58 | /* Structure for the pattern generator state */ | |
59 | struct mso_patgen { | |
60 | /* Pattern generator clock config */ | |
61 | uint16_t clock; | |
62 | /* Buffer start address */ | |
63 | uint16_t start; | |
64 | /* Buffer end address */ | |
65 | uint16_t end; | |
66 | /* Pattern generator config */ | |
67 | uint8_t config; | |
68 | /* Samples buffer */ | |
69 | uint8_t buffer[1024]; | |
70 | /* Input/output configuration for the samples buffer (?) */ | |
71 | uint8_t io[1024]; | |
72 | /* Number of loops for the pattern generator */ | |
73 | uint8_t loops; | |
74 | /* Bit enable mask for the I/O lines */ | |
75 | uint8_t mask; | |
76 | }; | |
77 | ||
78 | /* Data structure for the protocol trigger state */ | |
79 | struct mso_prototrig { | |
80 | /* Word match buffer */ | |
81 | uint8_t word[4]; | |
82 | /* Masks for the wordmatch buffer */ | |
83 | uint8_t mask[4]; | |
84 | /* SPI mode 0, 1, 2, 3. Set to 0 for I2C */ | |
85 | uint8_t spimode; | |
86 | }; | |
87 | ||
88 | /* Private, per-device-instance driver context. */ | |
89 | struct dev_context { | |
90 | /* info */ | |
91 | uint8_t hwmodel; | |
92 | uint8_t hwrev; | |
93 | struct sr_serial_dev_inst *serial; | |
94 | // uint8_t num_sample_rates; | |
95 | /* calibration */ | |
96 | double vbit; | |
97 | uint16_t dac_offset; | |
98 | uint16_t offset_range; | |
99 | uint64_t limit_samples; | |
100 | uint64_t num_samples; | |
101 | /* register cache */ | |
102 | uint8_t ctlbase1; | |
103 | uint8_t ctlbase2; | |
104 | /* state */ | |
105 | uint8_t la_threshold; | |
106 | uint64_t cur_rate; | |
107 | uint8_t dso_probe_attn; | |
108 | int8_t use_trigger; | |
109 | uint8_t trigger_chan; | |
110 | uint8_t trigger_slope; | |
111 | uint8_t trigger_outsrc; | |
112 | uint8_t trigger_state; | |
113 | uint8_t trigger_holdoff[2]; | |
114 | uint8_t la_trigger; | |
115 | uint8_t la_trigger_mask; | |
116 | double dso_trigger_voltage; | |
117 | uint16_t dso_trigger_width; | |
118 | struct mso_prototrig protocol_trigger; | |
119 | void *cb_data; | |
120 | uint16_t buffer_n; | |
121 | char buffer[4096]; | |
122 | }; | |
123 | ||
124 | SR_PRIV int mso_parse_serial(const char *iSerial, const char *iProduct, | |
125 | struct dev_context *ctx); | |
126 | SR_PRIV int mso_check_trigger(struct sr_serial_dev_inst *serial, | |
127 | uint8_t * info); | |
128 | SR_PRIV int mso_reset_adc(struct sr_dev_inst *sdi); | |
129 | SR_PRIV int mso_clkrate_out(struct sr_serial_dev_inst *serial, uint16_t val); | |
130 | SR_PRIV int mso_configure_rate(const struct sr_dev_inst *sdi, uint32_t rate); | |
131 | SR_PRIV int mso_receive_data(int fd, int revents, void *cb_data); | |
132 | SR_PRIV int mso_configure_trigger(const struct sr_dev_inst *sdi); | |
133 | SR_PRIV int mso_configure_threshold_level(const struct sr_dev_inst *sdi); | |
134 | SR_PRIV int mso_read_buffer(struct sr_dev_inst *sdi); | |
135 | SR_PRIV int mso_arm(const struct sr_dev_inst *sdi); | |
136 | SR_PRIV int mso_force_capture(struct sr_dev_inst *sdi); | |
137 | SR_PRIV int mso_dac_out(const struct sr_dev_inst *sdi, uint16_t val); | |
138 | SR_PRIV inline uint16_t mso_calc_raw_from_mv(struct dev_context *devc); | |
139 | SR_PRIV int mso_reset_fsm(struct sr_dev_inst *sdi); | |
140 | SR_PRIV int mso_toggle_led(struct sr_dev_inst *sdi, int state); | |
141 | ||
142 | SR_PRIV int mso_configure_channels(const struct sr_dev_inst *sdi); | |
143 | SR_PRIV void stop_acquisition(const struct sr_dev_inst *sdi); | |
144 | ||
145 | /* bank agnostic registers */ | |
146 | #define REG_CTL2 15 | |
147 | ||
148 | /* bank 0 registers */ | |
149 | #define REG_BUFFER 1 | |
150 | #define REG_TRIGGER 2 | |
151 | #define REG_CLKRATE1 9 | |
152 | #define REG_CLKRATE2 10 | |
153 | #define REG_DAC1 12 | |
154 | #define REG_DAC2 13 | |
155 | /* possibly bank agnostic: */ | |
156 | #define REG_CTL1 14 | |
157 | ||
158 | /* bank 2 registers (SPI/I2C protocol trigger) */ | |
159 | #define REG_PT_WORD(x) (x) | |
160 | #define REG_PT_MASK(x) (x + 4) | |
161 | #define REG_PT_SPIMODE 8 | |
162 | ||
163 | /* bits - REG_CTL1 */ | |
164 | #define BIT_CTL1_RESETFSM (1 << 0) | |
165 | #define BIT_CTL1_ARM (1 << 1) | |
166 | #define BIT_CTL1_ADC_UNKNOWN4 (1 << 4) /* adc enable? */ | |
167 | #define BIT_CTL1_RESETADC (1 << 6) | |
168 | #define BIT_CTL1_LED (1 << 7) | |
169 | ||
170 | /* bits - REG_CTL2 */ | |
171 | #define BITS_CTL2_BANK(x) (x & 0x3) | |
172 | #define BIT_CTL2_SLOWMODE (1 << 5) | |
173 | ||
174 | struct rate_map { | |
175 | uint32_t rate; | |
176 | uint16_t val; | |
177 | uint8_t slowmode; | |
178 | }; | |
179 | ||
180 | static const struct rate_map rate_map[] = { | |
181 | { SR_MHZ(200), 0x0205, 0 }, | |
182 | { SR_MHZ(100), 0x0105, 0 }, | |
183 | { SR_MHZ(50), 0x0005, 0 }, | |
184 | { SR_MHZ(20), 0x0303, 0 }, | |
185 | { SR_MHZ(10), 0x0308, 0 }, | |
186 | { SR_MHZ(5), 0x030c, 0 }, | |
187 | { SR_MHZ(2), 0x0330, 0 }, | |
188 | { SR_MHZ(1), 0x0362, 0 }, | |
189 | { SR_KHZ(500), 0x03c6, 0 }, | |
190 | { SR_KHZ(200), 0x07f2, 0 }, | |
191 | { SR_KHZ(100), 0x0fe6, 0 }, | |
192 | { SR_KHZ(50), 0x1fce, 0 }, | |
193 | { SR_KHZ(20), 0x4f86, 0 }, | |
194 | { SR_KHZ(10), 0x9f0e, 0 }, | |
195 | { SR_KHZ(5), 0x03c7, 0x20 }, | |
196 | { SR_KHZ(2), 0x07f3, 0x20 }, | |
197 | { SR_KHZ(1), 0x0fe7, 0x20 }, | |
198 | { SR_HZ(500), 0x1fcf, 0x20 }, | |
199 | { SR_HZ(200), 0x4f87, 0x20 }, | |
200 | { SR_HZ(100), 0x9f0f, 0x20 }, | |
201 | }; | |
202 | ||
203 | /* FIXME: Determine corresponding voltages */ | |
204 | static const uint16_t la_threshold_map[] = { | |
205 | 0x8600, | |
206 | 0x8770, | |
207 | 0x88ff, | |
208 | 0x8c70, | |
209 | 0x8eff, | |
210 | 0x8fff, | |
211 | }; | |
212 | ||
213 | #endif |