]> sigrok.org Git - libsigrok.git/blame - src/hardware/beaglelogic/beaglelogic.h
beaglelogic: Implement TCP protocol
[libsigrok.git] / src / hardware / beaglelogic / beaglelogic.h
CommitLineData
ad9dbc1c
KA
1/*
2 * This file is part of the libsigrok project.
3 *
4 * Copyright (C) 2014 Kumar Abhishek <abhishek@theembeddedkitchen.net>
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 3 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, see <http://www.gnu.org/licenses/>.
18 */
19
20#ifndef BEAGLELOGIC_H_
21#define BEAGLELOGIC_H_
22
23#include <fcntl.h>
ad9dbc1c
KA
24#include <sys/mman.h>
25#include <sys/types.h>
26#include <sys/errno.h>
27#include <sys/ioctl.h>
ad9dbc1c 28#include <stdlib.h>
ad9dbc1c
KA
29#include <unistd.h>
30
31/* BeagleLogic device node name */
32#define BEAGLELOGIC_DEV_NODE "/dev/beaglelogic"
83bf4762 33#define BEAGLELOGIC_SYSFS_ATTR(a) "/sys/devices/virtual/misc/beaglelogic/" #a
ad9dbc1c
KA
34
35/* Reproduced verbatim from beaglelogic.h in the kernel tree until the kernel
36 * module hits the mainline. Contains the ABI, so DO NOT TOUCH this section */
37
38/* ioctl calls that can be issued on /dev/beaglelogic */
39#define IOCTL_BL_GET_VERSION _IOR('k', 0x20, uint32_t)
40
41#define IOCTL_BL_GET_SAMPLE_RATE _IOR('k', 0x21, uint32_t)
42#define IOCTL_BL_SET_SAMPLE_RATE _IOW('k', 0x21, uint32_t)
43
44#define IOCTL_BL_GET_SAMPLE_UNIT _IOR('k', 0x22, uint32_t)
45#define IOCTL_BL_SET_SAMPLE_UNIT _IOW('k', 0x22, uint32_t)
46
47#define IOCTL_BL_GET_TRIGGER_FLAGS _IOR('k', 0x23, uint32_t)
48#define IOCTL_BL_SET_TRIGGER_FLAGS _IOW('k', 0x23, uint32_t)
49
0bca2e75 50#define IOCTL_BL_GET_CUR_INDEX _IOR('k', 0x24, uint32_t)
ad9dbc1c
KA
51#define IOCTL_BL_CACHE_INVALIDATE _IO('k', 0x25)
52
53#define IOCTL_BL_GET_BUFFER_SIZE _IOR('k', 0x26, uint32_t)
54#define IOCTL_BL_SET_BUFFER_SIZE _IOW('k', 0x26, uint32_t)
55
56#define IOCTL_BL_GET_BUFUNIT_SIZE _IOR('k', 0x27, uint32_t)
0bca2e75 57#define IOCTL_BL_SET_BUFUNIT_SIZE _IOW('k', 0x27, uint32_t)
ad9dbc1c
KA
58
59#define IOCTL_BL_FILL_TEST_PATTERN _IO('k', 0x28)
60
61#define IOCTL_BL_START _IO('k', 0x29)
62#define IOCTL_BL_STOP _IO('k', 0x2A)
63
64/* Possible States of BeagleLogic */
65enum beaglelogic_states {
66 STATE_BL_DISABLED, /* Powered off (at module start) */
67 STATE_BL_INITIALIZED, /* Powered on */
68 STATE_BL_MEMALLOCD, /* Buffers allocated */
69 STATE_BL_ARMED, /* All Buffers DMA-mapped and configuration done */
70 STATE_BL_RUNNING, /* Data being captured */
71 STATE_BL_REQUEST_STOP, /* Stop requested */
72 STATE_BL_ERROR /* Buffer overrun */
73};
74
75/* Setting attributes */
76enum beaglelogic_triggerflags {
77 BL_TRIGGERFLAGS_ONESHOT = 0,
78 BL_TRIGGERFLAGS_CONTINUOUS
79};
80
81/* Possible sample unit / formats */
82enum beaglelogic_sampleunit {
83 BL_SAMPLEUNIT_16_BITS = 0,
84 BL_SAMPLEUNIT_8_BITS
85};
86/* END beaglelogic.h */
87
88/* For all the functions below:
89 * Parameters:
90 * devc : Device context structure to operate on
91 * Returns:
92 * SR_OK or SR_ERR
93 */
94
0bca2e75
KA
95struct beaglelogic_ops {
96 int (*open)(struct dev_context *devc);
97 int (*close)(struct dev_context *devc);
ad9dbc1c 98
0bca2e75
KA
99 int (*get_buffersize)(struct dev_context *devc);
100 int (*set_buffersize)(struct dev_context *devc);
ad9dbc1c 101
0bca2e75
KA
102 int (*get_samplerate)(struct dev_context *devc);
103 int (*set_samplerate)(struct dev_context *devc);
ad9dbc1c 104
0bca2e75
KA
105 int (*get_sampleunit)(struct dev_context *devc);
106 int (*set_sampleunit)(struct dev_context *devc);
ad9dbc1c 107
0bca2e75
KA
108 int (*get_triggerflags)(struct dev_context *devc);
109 int (*set_triggerflags)(struct dev_context *devc);
ad9dbc1c 110
0bca2e75
KA
111 /* Start and stop the capture operation */
112 int (*start)(struct dev_context *devc);
113 int (*stop)(struct dev_context *devc);
ad9dbc1c 114
0bca2e75
KA
115 /* Get the last error size */
116 int (*get_lasterror)(struct dev_context *devc);
ad9dbc1c 117
0bca2e75
KA
118 /* Gets the unit size of the capture buffer (usually 4 or 8 MB) */
119 int (*get_bufunitsize)(struct dev_context *devc);
120 int (*set_bufunitsize)(struct dev_context *devc);
ad9dbc1c 121
0bca2e75
KA
122 int (*mmap)(struct dev_context *devc);
123 int (*munmap)(struct dev_context *devc);
124};
125
126SR_PRIV extern const struct beaglelogic_ops beaglelogic_native_ops;
9b2b3ef9
KA
127SR_PRIV extern const struct beaglelogic_ops beaglelogic_tcp_ops;
128
129SR_PRIV int beaglelogic_tcp_detect(struct dev_context *devc);
ad9dbc1c 130
db24496a 131#endif