]> sigrok.org Git - libsigrok.git/blame - hardware/chronovu-la8/protocol.h
la8: Cleanups, cosmetics, simplifications.
[libsigrok.git] / hardware / chronovu-la8 / protocol.h
CommitLineData
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
45e080b6
UH
21#ifndef LIBSIGROK_HARDWARE_CHRONOVU_LA8_PROTOCOL_H
22#define LIBSIGROK_HARDWARE_CHRONOVU_LA8_PROTOCOL_H
b908f067
UH
23
24#include <glib.h>
25#include <ftdi.h>
26#include <stdint.h>
45c59c8b
BV
27#include "libsigrok.h"
28#include "libsigrok-internal.h"
b908f067 29
b95dd761 30#define LOG_PREFIX "chronovu-la8"
f3a35908 31
b908f067 32#define USB_VENDOR_ID 0x0403
b908f067
UH
33#define USB_DESCRIPTION "ChronoVu LA8"
34#define USB_VENDOR_NAME "ChronoVu"
35#define USB_MODEL_NAME "LA8"
36#define USB_MODEL_VERSION ""
37
3f239f08 38#define NUM_CHANNELS 8
c50277a6 39#define TRIGGER_TYPE "01"
b908f067 40#define SDRAM_SIZE (8 * 1024 * 1024)
14563512 41#define MAX_NUM_SAMPLES SDRAM_SIZE
b908f067
UH
42
43#define BS 4096 /* Block size */
44#define NUM_BLOCKS 2048 /* Number of blocks */
45
46/* Private, per-device-instance driver context. */
1644fb24 47struct dev_context {
b908f067
UH
48 /** FTDI device context (used by libftdi). */
49 struct ftdi_context *ftdic;
50
51 /** The currently configured samplerate of the device. */
52 uint64_t cur_samplerate;
53
54 /** The current sampling limit (in ms). */
55 uint64_t limit_msec;
56
57 /** The current sampling limit (in number of samples). */
58 uint64_t limit_samples;
59
3e9b7f9c 60 void *cb_data;
b908f067
UH
61
62 /**
63 * A buffer containing some (mangled) samples from the device.
64 * Format: Pretty mangled-up (due to hardware reasons), see code.
65 */
66 uint8_t mangled_buf[BS];
67
68 /**
69 * An 8MB buffer where we'll store the de-mangled samples.
70 * Format: Each sample is 1 byte, MSB is channel 7, LSB is channel 0.
71 */
72 uint8_t *final_buf;
73
74 /**
75 * Trigger pattern (MSB = channel 7, LSB = channel 0).
ba7dd8bb 76 * A 1 bit matches a high signal, 0 matches a low signal on a channel.
b908f067
UH
77 * Only low/high triggers (but not e.g. rising/falling) are supported.
78 */
79 uint8_t trigger_pattern;
80
81 /**
82 * Trigger mask (MSB = channel 7, LSB = channel 0).
83 * A 1 bit means "must match trigger_pattern", 0 means "don't care".
84 */
85 uint8_t trigger_mask;
86
87 /** Time (in seconds) before the trigger times out. */
88 uint64_t trigger_timeout;
89
90 /** Tells us whether an SR_DF_TRIGGER packet was already sent. */
91 int trigger_found;
92
b172c130 93 /** Used for keeping track how much time has passed. */
b908f067
UH
94 time_t done;
95
96 /** Counter/index for the data block to be read. */
97 int block_counter;
98
b172c130 99 /** The divcount value (determines the sample period). */
b908f067 100 uint8_t divcount;
74e5f12d 101
b172c130 102 /** This ChronoVu device's USB PID. */
74e5f12d 103 uint16_t usb_pid;
b908f067
UH
104};
105
45e080b6 106/* protocol.c */
b172c130
UH
107extern const int32_t cv_hwcaps[];
108extern uint64_t cv_samplerates[];
109extern SR_PRIV const char *cv_channel_names[];
110SR_PRIV void cv_fill_samplerates_if_needed(void);
111SR_PRIV uint8_t cv_samplerate_to_divcount(uint64_t samplerate);
112SR_PRIV int cv_write(struct dev_context *devc, uint8_t *buf, int size);
113SR_PRIV int cv_close(struct dev_context *devc);
114SR_PRIV int cv_close_usb_reset_sequencer(struct dev_context *devc);
115SR_PRIV int cv_configure_channels(const struct sr_dev_inst *sdi);
116SR_PRIV int cv_set_samplerate(const struct sr_dev_inst *sdi, uint64_t samplerate);
117SR_PRIV int cv_read_block(struct dev_context *devc);
118SR_PRIV void cv_send_block_to_session_bus(struct dev_context *devc, int block);
b908f067
UH
119
120#endif