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