]>
Commit | Line | Data |
---|---|---|
b908f067 | 1 | /* |
50985c20 | 2 | * This file is part of the libsigrok project. |
b908f067 | 3 | * |
b172c130 | 4 | * Copyright (C) 2011-2014 Uwe Hermann <uwe@hermann-uwe.de> |
b908f067 UH |
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 | ||
7b356712 UH |
21 | #ifndef LIBSIGROK_HARDWARE_CHRONOVU_LA_PROTOCOL_H |
22 | #define LIBSIGROK_HARDWARE_CHRONOVU_LA_PROTOCOL_H | |
b908f067 UH |
23 | |
24 | #include <glib.h> | |
382bea82 | 25 | #include <libusb.h> |
b908f067 UH |
26 | #include <ftdi.h> |
27 | #include <stdint.h> | |
00910580 | 28 | #include <string.h> |
c1aae900 | 29 | #include <libsigrok/libsigrok.h> |
45c59c8b | 30 | #include "libsigrok-internal.h" |
b908f067 | 31 | |
00910580 | 32 | #define LOG_PREFIX "la8/la16" |
f3a35908 | 33 | |
b908f067 | 34 | #define SDRAM_SIZE (8 * 1024 * 1024) |
14563512 | 35 | #define MAX_NUM_SAMPLES SDRAM_SIZE |
b908f067 UH |
36 | |
37 | #define BS 4096 /* Block size */ | |
38 | #define NUM_BLOCKS 2048 /* Number of blocks */ | |
39 | ||
00910580 UH |
40 | enum { |
41 | CHRONOVU_LA8, | |
42 | CHRONOVU_LA16, | |
43 | }; | |
44 | ||
45 | struct cv_profile { | |
46 | int model; | |
47 | const char *modelname; | |
48 | const char *iproduct; /* USB iProduct string */ | |
49 | unsigned int num_channels; | |
50 | uint64_t max_samplerate; | |
aeff7fa2 | 51 | const int num_trigger_matches; |
00910580 UH |
52 | float trigger_constant; |
53 | }; | |
54 | ||
b908f067 | 55 | /* Private, per-device-instance driver context. */ |
1644fb24 | 56 | struct dev_context { |
00910580 UH |
57 | /** Device profile struct for this device. */ |
58 | const struct cv_profile *prof; | |
59 | ||
b908f067 UH |
60 | /** FTDI device context (used by libftdi). */ |
61 | struct ftdi_context *ftdic; | |
62 | ||
63 | /** The currently configured samplerate of the device. */ | |
64 | uint64_t cur_samplerate; | |
65 | ||
66 | /** The current sampling limit (in ms). */ | |
67 | uint64_t limit_msec; | |
68 | ||
69 | /** The current sampling limit (in number of samples). */ | |
70 | uint64_t limit_samples; | |
71 | ||
3e9b7f9c | 72 | void *cb_data; |
b908f067 UH |
73 | |
74 | /** | |
75 | * A buffer containing some (mangled) samples from the device. | |
76 | * Format: Pretty mangled-up (due to hardware reasons), see code. | |
77 | */ | |
78 | uint8_t mangled_buf[BS]; | |
79 | ||
80 | /** | |
81 | * An 8MB buffer where we'll store the de-mangled samples. | |
00910580 UH |
82 | * LA8: Each sample is 1 byte, MSB is channel 7, LSB is channel 0. |
83 | * LA16: Each sample is 2 bytes, MSB is channel 15, LSB is channel 0. | |
b908f067 UH |
84 | */ |
85 | uint8_t *final_buf; | |
86 | ||
87 | /** | |
00910580 | 88 | * Trigger pattern. |
ba7dd8bb | 89 | * A 1 bit matches a high signal, 0 matches a low signal on a channel. |
00910580 UH |
90 | * |
91 | * If the resp. 'trigger_edgemask' bit is set, 1 means "rising edge", | |
92 | * and 0 means "falling edge". | |
b908f067 | 93 | */ |
00910580 | 94 | uint16_t trigger_pattern; |
b908f067 UH |
95 | |
96 | /** | |
00910580 | 97 | * Trigger mask. |
b908f067 UH |
98 | * A 1 bit means "must match trigger_pattern", 0 means "don't care". |
99 | */ | |
00910580 | 100 | uint16_t trigger_mask; |
b908f067 | 101 | |
00910580 UH |
102 | /** |
103 | * Trigger edge mask. | |
104 | * A 1 bit means "edge triggered", 0 means "state triggered". | |
105 | * | |
106 | * Edge triggering is only supported on LA16 (but not LA8). | |
107 | */ | |
108 | uint16_t trigger_edgemask; | |
b908f067 UH |
109 | |
110 | /** Tells us whether an SR_DF_TRIGGER packet was already sent. */ | |
111 | int trigger_found; | |
112 | ||
b172c130 | 113 | /** Used for keeping track how much time has passed. */ |
00910580 | 114 | gint64 done; |
b908f067 UH |
115 | |
116 | /** Counter/index for the data block to be read. */ | |
117 | int block_counter; | |
118 | ||
b172c130 | 119 | /** The divcount value (determines the sample period). */ |
b908f067 | 120 | uint8_t divcount; |
74e5f12d | 121 | |
00910580 UH |
122 | /** This ChronoVu device's USB VID/PID. */ |
123 | uint16_t usb_vid; | |
74e5f12d | 124 | uint16_t usb_pid; |
00910580 UH |
125 | |
126 | /** Samplerates supported by this device. */ | |
127 | uint64_t samplerates[255]; | |
b908f067 UH |
128 | }; |
129 | ||
45e080b6 | 130 | /* protocol.c */ |
b172c130 | 131 | extern SR_PRIV const char *cv_channel_names[]; |
00910580 UH |
132 | extern const struct cv_profile cv_profiles[]; |
133 | SR_PRIV void cv_fill_samplerates_if_needed(const struct sr_dev_inst *sdi); | |
134 | SR_PRIV uint8_t cv_samplerate_to_divcount(const struct sr_dev_inst *sdi, | |
135 | uint64_t samplerate); | |
b172c130 | 136 | SR_PRIV int cv_write(struct dev_context *devc, uint8_t *buf, int size); |
aeff7fa2 | 137 | SR_PRIV int cv_convert_trigger(const struct sr_dev_inst *sdi); |
b172c130 UH |
138 | SR_PRIV int cv_set_samplerate(const struct sr_dev_inst *sdi, uint64_t samplerate); |
139 | SR_PRIV int cv_read_block(struct dev_context *devc); | |
140 | SR_PRIV void cv_send_block_to_session_bus(struct dev_context *devc, int block); | |
b908f067 UH |
141 | |
142 | #endif |