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