]>
Commit | Line | Data |
---|---|---|
88d2037b KA |
1 | /* |
2 | * This file is part of the libsigrok project. | |
3 | * | |
4 | * Copyright (C) 2014, 2017 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 | #include "protocol.h" | |
21 | #include "beaglelogic.h" | |
22 | ||
23 | SR_PRIV inline int beaglelogic_open_nonblock(struct dev_context *devc) { | |
24 | devc->fd = open(BEAGLELOGIC_DEV_NODE, O_RDONLY | O_NONBLOCK); | |
25 | return (devc->fd == -1 ? SR_ERR : SR_OK); | |
26 | } | |
27 | ||
28 | SR_PRIV inline int beaglelogic_close(struct dev_context *devc) { | |
29 | return close(devc->fd); | |
30 | } | |
31 | ||
32 | SR_PRIV inline int beaglelogic_get_buffersize(struct dev_context *devc) { | |
33 | return ioctl(devc->fd, IOCTL_BL_GET_BUFFER_SIZE, &devc->buffersize); | |
34 | } | |
35 | ||
36 | SR_PRIV inline int beaglelogic_set_buffersize(struct dev_context *devc) { | |
37 | return ioctl(devc->fd, IOCTL_BL_SET_BUFFER_SIZE, devc->buffersize); | |
38 | } | |
39 | ||
40 | /* This is treated differently as it gets a uint64_t while a uint32_t is read */ | |
41 | SR_PRIV inline int beaglelogic_get_samplerate(struct dev_context *devc) { | |
42 | uint32_t arg, err; | |
43 | err = ioctl(devc->fd, IOCTL_BL_GET_SAMPLE_RATE, &arg); | |
44 | devc->cur_samplerate = arg; | |
45 | return err; | |
46 | } | |
47 | ||
48 | SR_PRIV inline int beaglelogic_set_samplerate(struct dev_context *devc) { | |
49 | return ioctl(devc->fd, IOCTL_BL_SET_SAMPLE_RATE, | |
50 | (uint32_t)devc->cur_samplerate); | |
51 | } | |
52 | ||
53 | SR_PRIV inline int beaglelogic_get_sampleunit(struct dev_context *devc) { | |
54 | return ioctl(devc->fd, IOCTL_BL_GET_SAMPLE_UNIT, &devc->sampleunit); | |
55 | } | |
56 | ||
57 | SR_PRIV inline int beaglelogic_set_sampleunit(struct dev_context *devc) { | |
58 | return ioctl(devc->fd, IOCTL_BL_SET_SAMPLE_UNIT, devc->sampleunit); | |
59 | } | |
60 | ||
61 | SR_PRIV inline int beaglelogic_get_triggerflags(struct dev_context *devc) { | |
62 | return ioctl(devc->fd, IOCTL_BL_GET_TRIGGER_FLAGS, &devc->triggerflags); | |
63 | } | |
64 | ||
65 | SR_PRIV inline int beaglelogic_set_triggerflags(struct dev_context *devc) { | |
66 | return ioctl(devc->fd, IOCTL_BL_SET_TRIGGER_FLAGS, devc->triggerflags); | |
67 | } | |
68 | ||
69 | SR_PRIV int beaglelogic_getlasterror(struct dev_context *devc) { | |
70 | int fd; | |
71 | char buf[16]; | |
72 | int ret; | |
73 | ||
74 | if ((fd = open(BEAGLELOGIC_SYSFS_ATTR(lasterror), O_RDONLY)) == -1) | |
75 | return SR_ERR; | |
76 | ||
77 | if ((ret = read(fd, buf, 16)) < 0) | |
78 | return SR_ERR; | |
79 | ||
80 | close(fd); | |
81 | devc->last_error = strtoul(buf, NULL, 10); | |
82 | ||
83 | return SR_OK; | |
84 | } | |
85 | ||
86 | SR_PRIV inline int beaglelogic_start(struct dev_context *devc) { | |
87 | return ioctl(devc->fd, IOCTL_BL_START); | |
88 | } | |
89 | ||
90 | SR_PRIV inline int beaglelogic_stop(struct dev_context *devc) { | |
91 | return ioctl(devc->fd, IOCTL_BL_STOP); | |
92 | } | |
93 | ||
94 | SR_PRIV int beaglelogic_get_bufunitsize(struct dev_context *devc) { | |
95 | return ioctl(devc->fd, IOCTL_BL_GET_BUFUNIT_SIZE, &devc->bufunitsize); | |
96 | } | |
97 | ||
98 | SR_PRIV int beaglelogic_mmap(struct dev_context *devc) { | |
99 | if (!devc->buffersize) | |
100 | beaglelogic_get_buffersize(devc); | |
101 | devc->sample_buf = mmap(NULL, devc->buffersize, | |
102 | PROT_READ, MAP_SHARED, devc->fd, 0); | |
103 | return (devc->sample_buf == MAP_FAILED ? -1 : SR_OK); | |
104 | } | |
105 | ||
106 | SR_PRIV int beaglelogic_munmap(struct dev_context *devc) { | |
107 | return munmap(devc->sample_buf, devc->buffersize); | |
108 | } |