]> sigrok.org Git - libsigrok.git/blob - src/hardware/sysclk-sla5032/protocol.h
output/csv: use intermediate time_t var, silence compiler warning
[libsigrok.git] / src / hardware / sysclk-sla5032 / protocol.h
1 /*
2  * This file is part of the libsigrok project.
3  *
4  * Copyright (C) 2019 Vitaliy Vorobyov
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_SYSCLK_SLA5032_PROTOCOL_H
21 #define LIBSIGROK_HARDWARE_SYSCLK_SLA5032_PROTOCOL_H
22
23 #include <stdint.h>
24 #include <libusb.h>
25 #include <glib.h>
26 #include <libsigrok/libsigrok.h>
27 #include <libsigrok-internal.h>
28
29 #define LOG_PREFIX "sysclk-sla5032"
30
31 /* Maximum configurable sample count limit. */
32 #define MAX_LIMIT_SAMPLES       (64 * 1024 * 1024)
33 #define MIN_LIMIT_SAMPLES       512
34
35 /* USB vendor and product IDs. */
36 enum {
37         USB_VID_SYSCLK   = 0x2961,
38         USB_PID_SLA5032  = 0x66B0,
39 };
40
41 /* USB device characteristics. */
42 enum {
43         USB_CONFIG              = 1,
44         USB_INTERFACE           = 0,
45         USB_CMD_TIMEOUT_MS      = 5000,
46         USB_REPLY_TIMEOUT_MS    = 500000,
47         USB_DATA_TIMEOUT_MS     = 2000,
48 };
49
50 /* USB device end points. */
51 enum usb_endpoint {
52         EP_COMMAND = 4 | LIBUSB_ENDPOINT_OUT,
53         EP_REPLY   = 8 | LIBUSB_ENDPOINT_IN,
54         EP_DATA    = 6 | LIBUSB_ENDPOINT_IN,
55 };
56
57
58 /* Common indicator for no or unknown FPGA config. */
59 enum {
60         FPGA_NOCONF = -1,
61         FPGA_CONF,
62 };
63
64 /** Acquisition protocol states. */
65 enum protocol_state {
66         /* idle states */
67         STATE_IDLE = 0,
68         STATE_STATUS_WAIT,
69         /* device command states */
70         STATE_START_CAPTURE,
71         STATE_STOP_CAPTURE,
72         STATE_READ_PREPARE,
73         STATE_READ_FINISH,
74         /* command followed by response */
75         STATE_EXPECT_RESPONSE = 1 << 3,
76         STATE_STATUS_REQUEST = STATE_EXPECT_RESPONSE,
77         STATE_LENGTH_REQUEST,
78         STATE_READ_REQUEST,
79 };
80
81 /** SLA5032 protocol command ID codes. */
82 enum command_id {
83         CMD_INIT_FW_UPLOAD = 1,
84         CMD_UPLOAD_FW_CHUNK = 2,
85         CMD_READ_REG = 3,
86         CMD_WRITE_REG = 4,
87         CMD_READ_MEM = 5,
88         CMD_READ_DATA = 7,
89 };
90
91 struct dev_context {
92         uint64_t samplerate;            /* requested samplerate */
93         uint64_t limit_samples;         /* requested capture length (samples) */
94         uint64_t capture_ratio;
95
96         uint64_t channel_mask;          /* bit mask of enabled channels */
97         uint64_t trigger_mask;          /* trigger enable mask */
98         uint64_t trigger_edge_mask;     /* trigger type mask */
99         uint64_t trigger_values;        /* trigger level/slope bits */
100
101         struct soft_trigger_logic *stl;
102         gboolean trigger_fired;
103
104         int active_fpga_config;         /* FPGA configuration index */
105
106         enum protocol_state state;      /* async protocol state */
107 };
108
109 SR_PRIV int sla5032_start_acquisition(const struct sr_dev_inst *sdi);
110 SR_PRIV int sla5032_apply_fpga_config(const struct sr_dev_inst *sdi);
111
112 #endif