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