-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapcilib.cpp
More file actions
executable file
·234 lines (176 loc) · 5.71 KB
/
Copy pathapcilib.cpp
File metadata and controls
executable file
·234 lines (176 loc) · 5.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
/*
This software is a driver for ACCES I/O Products, Inc. PCI cards.
Copyright (C) 2007 ACCES I/O Products, Inc.
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation. This software is released under
version 2 of the GPL.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
In addition ACCES provides other licenses with its software at customer request.
For more information please contact the ACCES software department at
(800)-326-1649 or visit www.accesio.com
*/
#include <sys/ioctl.h>
#include <linux/errno.h>
#include <stddef.h>
#include <stdint.h>
#include "apcilib.h"
#include "apci_ioctl.h"
int apci_get_devices(int fd)
{
return ioctl(fd, apci_get_devices_ioctl);
}
int apci_get_device_info(int fd, unsigned long device_index, unsigned int *dev_id, unsigned long base_addresses[6])
{
info_struct dev_info;
int count;
int status;
dev_info.device_index = device_index;
status = ioctl(fd, apci_get_device_info_ioctl, &dev_info);
if (dev_id != NULL) *dev_id = dev_info.dev_id;
if (base_addresses != NULL)
for (count = 0; count < 6; count ++) base_addresses[count] = dev_info.base_addresses[count];
return status;
}
int apci_write8(int fd, unsigned long device_index, int bar, int offset, __u8 data)
{
iopack io_pack;
io_pack.device_index = device_index;
io_pack.bar = bar;
io_pack.offset = offset;
io_pack.data = data;
io_pack.size = BYTE;
return ioctl(fd, apci_write_ioctl, &io_pack);
}
int apci_write16(int fd, unsigned long device_index, int bar, int offset, __u16 data)
{
iopack io_pack;
io_pack.device_index = device_index;
io_pack.bar = bar;
io_pack.offset = offset;
io_pack.data = data;
io_pack.size = WORD;
return ioctl(fd, apci_write_ioctl, &io_pack);
}
int apci_write32(int fd, unsigned long device_index, int bar, int offset, __u32 data)
{
iopack io_pack;
io_pack.device_index = device_index;
io_pack.bar = bar;
io_pack.offset = offset;
io_pack.data = data;
io_pack.size = DWORD;
return ioctl(fd, apci_write_ioctl, &io_pack);
}
int apci_writebuf32(int fd, unsigned long device_index, int bar, int bar_offset, unsigned int mmap_offset, int length)
{
buff_iopack buff_pack;
buff_pack.device_index = device_index;
buff_pack.bar = bar;
buff_pack.bar_offset = bar_offset;
buff_pack.mmap_offset = mmap_offset;
buff_pack.length = length;
buff_pack.size = DWORD;
return ioctl(fd, apci_write_buff_ioctl, &buff_pack);
}
int apci_writebuf16(int fd, unsigned long device_index, int bar, int bar_offset, unsigned int mmap_offset, int length)
{
buff_iopack buff_pack;
buff_pack.device_index = device_index;
buff_pack.bar = bar;
buff_pack.bar_offset = bar_offset;
buff_pack.mmap_offset = mmap_offset;
buff_pack.length = length;
buff_pack.size = WORD;
return ioctl(fd, apci_write_buff_ioctl, &buff_pack);
}
int apci_writebuf8(int fd, unsigned long device_index, int bar, int bar_offset, unsigned int mmap_offset, int length)
{
buff_iopack buff_pack;
buff_pack.device_index = device_index;
buff_pack.bar = bar;
buff_pack.bar_offset = bar_offset;
buff_pack.mmap_offset = mmap_offset;
buff_pack.length = length;
buff_pack.size = BYTE;
return ioctl(fd, apci_write_buff_ioctl, &buff_pack);
}
int apci_read8(int fd, unsigned long device_index, int bar, int offset, __u8 *data)
{
iopack io_pack;
int status;
io_pack.device_index = device_index;
io_pack.bar = bar;
io_pack.offset = offset;
io_pack.size = BYTE;
status = ioctl(fd, apci_read_ioctl, &io_pack);
if (data != NULL) *data = static_cast<__u8>(io_pack.data);
return status;
}
int apci_read16(int fd, unsigned long device_index, int bar, int offset, __u16 *data)
{
iopack io_pack;
int status;
io_pack.device_index = device_index;
io_pack.bar = bar;
io_pack.offset = offset;
io_pack.size = WORD;
status = ioctl(fd, apci_read_ioctl, &io_pack);
if (data != NULL) *data = static_cast<__u16>(io_pack.data);
return status;
}
int apci_read32(int fd, unsigned long device_index, int bar, int offset, __u32 *data)
{
iopack io_pack;
int status;
io_pack.device_index = device_index;
io_pack.bar = bar;
io_pack.offset = offset;
io_pack.size = DWORD;
status = ioctl(fd, apci_read_ioctl, &io_pack);
if (data != NULL) *data = io_pack.data;
return status;
}
int apci_wait_for_irq(int fd, unsigned long device_index)
{
return ioctl(fd, apci_wait_for_irq_ioctl, device_index);
}
int apci_cancel_irq(int fd, unsigned long device_index)
{
return ioctl(fd, apci_cancel_wait_ioctl, device_index);
}
int apci_dma_transfer_size(int fd, unsigned long device_index, __u8 num_slots, size_t slot_size)
{
dma_buffer_settings_t settings;
settings.num_slots = num_slots;
settings.slot_size = slot_size;
return ioctl(fd, apci_set_dma_transfer_size, &settings);
}
int apci_dma_data_ready(int fd, unsigned long device_index, int *start_index, int *slots, int *data_discarded)
{
int status;
data_ready_t ready = {0,0,0};
status = ioctl(fd, apci_data_ready, &ready);
*start_index = ready.start_index;
*slots = ready.slots;
*data_discarded = ready.data_discarded;
return status;
}
int apci_dma_data_done(int fd, unsigned long device_index, int num_slots)
{
return ioctl(fd, apci_data_done, num_slots);
}
int apci_dac_buffer_size (int fd, unsigned long size)
{
return ioctl(fd, apci_set_dac_buff_size, size);
}
int apci_start_dma (int fd)
{
return ioctl(fd, apci_start_dma_data);
}