]> sigrok.org Git - libsigrok.git/blob - hardware/chronovu-la8/protocol.h
146fc112d5955feb4b8fb6c031bb76e665711267
[libsigrok.git] / hardware / chronovu-la8 / protocol.h
1 /*
2  * This file is part of the libsigrok project.
3  *
4  * Copyright (C) 2011-2012 Uwe Hermann <uwe@hermann-uwe.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 2 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, write to the Free Software
18  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
19  */
20
21 #ifndef LIBSIGROK_HARDWARE_CHRONOVU_LA8_PROTOCOL_H
22 #define LIBSIGROK_HARDWARE_CHRONOVU_LA8_PROTOCOL_H
23
24 #include <glib.h>
25 #include <ftdi.h>
26 #include <stdint.h>
27 #include "libsigrok.h"
28 #include "libsigrok-internal.h"
29
30 #define LOG_PREFIX "chronovu-la8"
31
32 #define USB_VENDOR_ID                   0x0403
33 #define USB_DESCRIPTION                 "ChronoVu LA8"
34 #define USB_VENDOR_NAME                 "ChronoVu"
35 #define USB_MODEL_NAME                  "LA8"
36 #define USB_MODEL_VERSION               ""
37
38 #define NUM_PROBES                      8
39 #define TRIGGER_TYPE                    "01"
40 #define SDRAM_SIZE                      (8 * 1024 * 1024)
41 #define MIN_NUM_SAMPLES                 1
42 #define MAX_NUM_SAMPLES                 SDRAM_SIZE
43
44 #define BS                              4096 /* Block size */
45 #define NUM_BLOCKS                      2048 /* Number of blocks */
46
47 /* Private, per-device-instance driver context. */
48 struct dev_context {
49         /** FTDI device context (used by libftdi). */
50         struct ftdi_context *ftdic;
51
52         /** The currently configured samplerate of the device. */
53         uint64_t cur_samplerate;
54
55         /** The current sampling limit (in ms). */
56         uint64_t limit_msec;
57
58         /** The current sampling limit (in number of samples). */
59         uint64_t limit_samples;
60
61         void *cb_data;
62
63         /**
64          * A buffer containing some (mangled) samples from the device.
65          * Format: Pretty mangled-up (due to hardware reasons), see code.
66          */
67         uint8_t mangled_buf[BS];
68
69         /**
70          * An 8MB buffer where we'll store the de-mangled samples.
71          * Format: Each sample is 1 byte, MSB is channel 7, LSB is channel 0.
72          */
73         uint8_t *final_buf;
74
75         /**
76          * Trigger pattern (MSB = channel 7, LSB = channel 0).
77          * A 1 bit matches a high signal, 0 matches a low signal on a probe.
78          * Only low/high triggers (but not e.g. rising/falling) are supported.
79          */
80         uint8_t trigger_pattern;
81
82         /**
83          * Trigger mask (MSB = channel 7, LSB = channel 0).
84          * A 1 bit means "must match trigger_pattern", 0 means "don't care".
85          */
86         uint8_t trigger_mask;
87
88         /** Time (in seconds) before the trigger times out. */
89         uint64_t trigger_timeout;
90
91         /** Tells us whether an SR_DF_TRIGGER packet was already sent. */
92         int trigger_found;
93
94         /** TODO */
95         time_t done;
96
97         /** Counter/index for the data block to be read. */
98         int block_counter;
99
100         /** The divcount value (determines the sample period) for the LA8. */
101         uint8_t divcount;
102
103         /** This ChronoVu LA8's USB PID (multiple versions exist). */
104         uint16_t usb_pid;
105 };
106
107 /* protocol.c */
108 extern const int32_t chronovu_la8_hwcaps[];
109 extern uint64_t chronovu_la8_samplerates[];
110 extern SR_PRIV const char *chronovu_la8_probe_names[];
111 SR_PRIV void fill_supported_samplerates_if_needed(void);
112 SR_PRIV int is_valid_samplerate(uint64_t samplerate);
113 SR_PRIV uint8_t samplerate_to_divcount(uint64_t samplerate);
114 SR_PRIV int la8_write(struct dev_context *devc, uint8_t *buf, int size);
115 SR_PRIV int la8_read(struct dev_context *devc, uint8_t *buf, int size);
116 SR_PRIV int la8_close(struct dev_context *devc);
117 SR_PRIV int la8_close_usb_reset_sequencer(struct dev_context *devc);
118 SR_PRIV int la8_reset(struct dev_context *devc);
119 SR_PRIV int configure_probes(const struct sr_dev_inst *sdi);
120 SR_PRIV int set_samplerate(const struct sr_dev_inst *sdi, uint64_t samplerate);
121 SR_PRIV int la8_read_block(struct dev_context *devc);
122 SR_PRIV void send_block_to_session_bus(struct dev_context *devc, int block);
123
124 #endif