]> sigrok.org Git - libsigrok.git/blob - src/hardware/lecroy-logicstudio/protocol.h
lecroy-logicstudio: Initial driver implementation.
[libsigrok.git] / src / hardware / lecroy-logicstudio / protocol.h
1 /*
2  * This file is part of the libsigrok project.
3  *
4  * Copyright (C) 2015 Tilman Sauerbeck <tilman@code-monkey.de>
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_LECROY_LOGICSTUDIO_PROTOCOL_H
21 #define LIBSIGROK_HARDWARE_LECROY_LOGICSTUDIO_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 "lecroy-logicstudio"
29
30 #define SAMPLE_BUF_SIZE 40960u
31 #define CONV_8TO16_BUF_SIZE 8192
32 #define INTR_BUF_SIZE 32
33
34 struct samplerate_info;
35
36 /** Private, per-device-instance driver context. */
37 struct dev_context {
38         struct libusb_transfer *intr_xfer;
39         struct libusb_transfer *bulk_xfer;
40
41         const struct samplerate_info *samplerate_info;
42
43         /**
44          * When the device is opened, this will point at a buffer
45          * of SAMPLE_BUF_SIZE bytes.
46          */
47         uint8_t *fetched_samples;
48
49         /**
50          * Used to convert 8 bit samples (8 channels) to 16 bit samples
51          * (16 channels), thus only used in 8 channel mode.
52          * Holds CONV_8TO16_BUF_SIZE bytes.
53          */
54         uint16_t *conv8to16;
55
56         int64_t fw_updated; /* Time of last FX2 firmware upload. */
57
58         /** The pre-trigger capture ratio in percent. */
59         uint64_t capture_ratio;
60
61         uint64_t earliest_sample;
62         uint64_t trigger_sample;
63
64         /** The number of eight-channel groups enabled (either 1 or 2). */
65         uint32_t num_enabled_channel_groups;
66
67         /**
68          * The number of samples to acquire (in thousands).
69          * This is not customizable, but depending on the number
70          * of enabled channel groups.
71          */
72         uint32_t num_thousand_samples;
73
74         uint32_t total_received_sample_bytes;
75
76         /** Mask of enabled channels. */
77         uint16_t channel_mask;
78
79         uint16_t acquisition_id;
80
81         gboolean want_trigger;
82         gboolean abort_acquisition;
83
84         /**
85          * These two magic values are required in order to fix a sample
86          * buffer corruption. Before the first acquisition is run, they
87          * need to be set to 0.
88          */
89         uint8_t magic_arm_trigger;
90         uint8_t magic_fetch_samples;
91
92         /**
93          * Buffer for interrupt transfers (acquisition state notifications).
94          */
95         uint8_t intr_buf[INTR_BUF_SIZE];
96 };
97
98 SR_PRIV void lls_update_channel_mask(const struct sr_dev_inst *sdi);
99
100 SR_PRIV int lls_set_samplerate(const struct sr_dev_inst *sdi, uint64_t samplerate);
101 SR_PRIV uint64_t lls_get_samplerate(const struct sr_dev_inst *sdi);
102
103 SR_PRIV int lls_setup_acquisition(const struct sr_dev_inst *sdi);
104 SR_PRIV int lls_start_acquisition(const struct sr_dev_inst *sdi);
105 SR_PRIV int lls_stop_acquisition(const struct sr_dev_inst *sdi);
106
107 #endif