ibfoo.c revision 141402
1/*- 2 * Copyright (c) 2005 Poul-Henning Kamp 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright 9 * notice, this list of conditions and the following disclaimer. 10 * 2. Redistributions in binary form must reproduce the above copyright 11 * notice, this list of conditions and the following disclaimer in the 12 * documentation and/or other materials provided with the distribution. 13 * 14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24 * SUCH DAMAGE. 25 * 26 * This file merely redirects to the file in <dev/ieee488/ugpib.h> 27 * 28 * $FreeBSD: head/lib/libgpib/ibfoo.c 141402 2005-02-06 16:45:20Z phk $ 29 */ 30 31#include <stdio.h> 32#include <errno.h> 33#include <err.h> 34#include <sys/types.h> 35#include <fcntl.h> 36 37#include <dev/ieee488/ugpib.h> 38#include <dev/ieee488/ibfoo_int.h> 39 40int ibcnt, iberr; 41 42static int fd = -1; 43 44static int 45__ibsubmit(struct ibfoo_iocarg *ap) 46{ 47 int i; 48 49 if (fd < 0) 50 fd = open("/dev/gpib0ib", O_RDWR); 51 if (fd < 0) 52 err(1, "Could not open /dev/gpib0ib"); 53 i = ioctl(fd, GPIB_IBFOO, ap); 54 if (i) 55 err(1, "GPIB_IBFOO(%d, 0x%x) failed", ap->__ident, ap->__field); 56 ibcnt = ap->__ibcnt; 57 iberr = ap->__iberr; 58 return (ap->__retval); 59} 60 61int 62ibask (int handle, int option, int * retval) 63{ 64 struct ibfoo_iocarg io; 65 66 io.__ident = __ID_IBASK; 67 io.handle = handle; 68 io.option = option; 69 io.retval = retval; 70 io.__field = __F_HANDLE | __F_OPTION | __F_RETVAL; 71 return (__ibsubmit(&io)); 72} 73 74int 75ibbna (int handle, char * bdname) 76{ 77 struct ibfoo_iocarg io; 78 79 io.__ident = __ID_IBBNA; 80 io.handle = handle; 81 io.bdname = bdname; 82 io.__field = __F_HANDLE | __F_BDNAME; 83 return (__ibsubmit(&io)); 84} 85 86int 87ibcac (int handle, int v) 88{ 89 struct ibfoo_iocarg io; 90 91 io.__ident = __ID_IBCAC; 92 io.handle = handle; 93 io.v = v; 94 io.__field = __F_HANDLE | __F_V; 95 return (__ibsubmit(&io)); 96} 97 98int 99ibclr (int handle) 100{ 101 struct ibfoo_iocarg io; 102 103 io.__ident = __ID_IBCLR; 104 io.handle = handle; 105 io.__field = __F_HANDLE; 106 return (__ibsubmit(&io)); 107} 108 109int 110ibcmd (int handle, void * buffer, long cnt) 111{ 112 struct ibfoo_iocarg io; 113 114 io.__ident = __ID_IBCMD; 115 io.handle = handle; 116 io.buffer = buffer; 117 io.cnt = cnt; 118 io.__field = __F_HANDLE | __F_BUFFER | __F_CNT; 119 return (__ibsubmit(&io)); 120} 121 122int 123ibcmda (int handle, void * buffer, long cnt) 124{ 125 struct ibfoo_iocarg io; 126 127 io.__ident = __ID_IBCMDA; 128 io.handle = handle; 129 io.buffer = buffer; 130 io.cnt = cnt; 131 io.__field = __F_HANDLE | __F_BUFFER | __F_CNT; 132 return (__ibsubmit(&io)); 133} 134 135int 136ibconfig (int handle, int option, int value) 137{ 138 struct ibfoo_iocarg io; 139 140 io.__ident = __ID_IBCONFIG; 141 io.handle = handle; 142 io.option = option; 143 io.value = value; 144 io.__field = __F_HANDLE | __F_OPTION | __F_VALUE; 145 return (__ibsubmit(&io)); 146} 147 148int 149ibdev (int boardID, int pad, int sad, int tmo, int eot, int eos) 150{ 151 struct ibfoo_iocarg io; 152 153 io.__ident = __ID_IBDEV; 154 io.boardID = boardID; 155 io.pad = pad; 156 io.sad = sad; 157 io.tmo = tmo; 158 io.eot = eot; 159 io.eos = eos; 160 io.__field = __F_BOARDID | __F_PAD | __F_SAD | __F_TMO | __F_EOT | __F_EOS; 161 return (__ibsubmit(&io)); 162} 163 164int 165ibdiag (int handle, void * buffer, long cnt) 166{ 167 struct ibfoo_iocarg io; 168 169 io.__ident = __ID_IBDIAG; 170 io.handle = handle; 171 io.buffer = buffer; 172 io.cnt = cnt; 173 io.__field = __F_HANDLE | __F_BUFFER | __F_CNT; 174 return (__ibsubmit(&io)); 175} 176 177int 178ibdma (int handle, int v) 179{ 180 struct ibfoo_iocarg io; 181 182 io.__ident = __ID_IBDMA; 183 io.handle = handle; 184 io.v = v; 185 io.__field = __F_HANDLE | __F_V; 186 return (__ibsubmit(&io)); 187} 188 189int 190ibeos (int handle, int eos) 191{ 192 struct ibfoo_iocarg io; 193 194 io.__ident = __ID_IBEOS; 195 io.handle = handle; 196 io.eos = eos; 197 io.__field = __F_HANDLE | __F_EOS; 198 return (__ibsubmit(&io)); 199} 200 201int 202ibeot (int handle, int v) 203{ 204 struct ibfoo_iocarg io; 205 206 io.__ident = __ID_IBEOT; 207 io.handle = handle; 208 io.v = v; 209 io.__field = __F_HANDLE | __F_V; 210 return (__ibsubmit(&io)); 211} 212 213int 214ibevent (int handle, short * event) 215{ 216 struct ibfoo_iocarg io; 217 218 io.__ident = __ID_IBEVENT; 219 io.handle = handle; 220 io.event = event; 221 io.__field = __F_HANDLE | __F_EVENT; 222 return (__ibsubmit(&io)); 223} 224 225int 226ibfind (char * bdname) 227{ 228 struct ibfoo_iocarg io; 229 230 io.__ident = __ID_IBFIND; 231 io.bdname = bdname; 232 io.__field = __F_BDNAME; 233 return (__ibsubmit(&io)); 234} 235 236int 237ibgts (int handle, int v) 238{ 239 struct ibfoo_iocarg io; 240 241 io.__ident = __ID_IBGTS; 242 io.handle = handle; 243 io.v = v; 244 io.__field = __F_HANDLE | __F_V; 245 return (__ibsubmit(&io)); 246} 247 248int 249ibist (int handle, int v) 250{ 251 struct ibfoo_iocarg io; 252 253 io.__ident = __ID_IBIST; 254 io.handle = handle; 255 io.v = v; 256 io.__field = __F_HANDLE | __F_V; 257 return (__ibsubmit(&io)); 258} 259 260int 261iblines (int handle, short * lines) 262{ 263 struct ibfoo_iocarg io; 264 265 io.__ident = __ID_IBLINES; 266 io.handle = handle; 267 io.lines = lines; 268 io.__field = __F_HANDLE | __F_LINES; 269 return (__ibsubmit(&io)); 270} 271 272int 273ibllo (int handle) 274{ 275 struct ibfoo_iocarg io; 276 277 io.__ident = __ID_IBLLO; 278 io.handle = handle; 279 io.__field = __F_HANDLE; 280 return (__ibsubmit(&io)); 281} 282 283int 284ibln (int handle, int padval, int sadval, short * listenflag) 285{ 286 struct ibfoo_iocarg io; 287 288 io.__ident = __ID_IBLN; 289 io.handle = handle; 290 io.padval = padval; 291 io.sadval = sadval; 292 io.listenflag = listenflag; 293 io.__field = __F_HANDLE | __F_PADVAL | __F_SADVAL | __F_LISTENFLAG; 294 return (__ibsubmit(&io)); 295} 296 297int 298ibloc (int handle) 299{ 300 struct ibfoo_iocarg io; 301 302 io.__ident = __ID_IBLOC; 303 io.handle = handle; 304 io.__field = __F_HANDLE; 305 return (__ibsubmit(&io)); 306} 307 308int 309ibonl (int handle, int v) 310{ 311 struct ibfoo_iocarg io; 312 313 io.__ident = __ID_IBONL; 314 io.handle = handle; 315 io.v = v; 316 io.__field = __F_HANDLE | __F_V; 317 return (__ibsubmit(&io)); 318} 319 320int 321ibpad (int handle, int v) 322{ 323 struct ibfoo_iocarg io; 324 325 io.__ident = __ID_IBPAD; 326 io.handle = handle; 327 io.v = v; 328 io.__field = __F_HANDLE | __F_V; 329 return (__ibsubmit(&io)); 330} 331 332int 333ibpct (int handle) 334{ 335 struct ibfoo_iocarg io; 336 337 io.__ident = __ID_IBPCT; 338 io.handle = handle; 339 io.__field = __F_HANDLE; 340 return (__ibsubmit(&io)); 341} 342 343int 344ibpoke (int handle, int option, int value) 345{ 346 struct ibfoo_iocarg io; 347 348 io.__ident = __ID_IBPOKE; 349 io.handle = handle; 350 io.option = option; 351 io.value = value; 352 io.__field = __F_HANDLE | __F_OPTION | __F_VALUE; 353 return (__ibsubmit(&io)); 354} 355 356int 357ibppc (int handle, int v) 358{ 359 struct ibfoo_iocarg io; 360 361 io.__ident = __ID_IBPPC; 362 io.handle = handle; 363 io.v = v; 364 io.__field = __F_HANDLE | __F_V; 365 return (__ibsubmit(&io)); 366} 367 368int 369ibrd (int handle, void * buffer, long cnt) 370{ 371 struct ibfoo_iocarg io; 372 373 io.__ident = __ID_IBRD; 374 io.handle = handle; 375 io.buffer = buffer; 376 io.cnt = cnt; 377 io.__field = __F_HANDLE | __F_BUFFER | __F_CNT; 378 return (__ibsubmit(&io)); 379} 380 381int 382ibrda (int handle, void * buffer, long cnt) 383{ 384 struct ibfoo_iocarg io; 385 386 io.__ident = __ID_IBRDA; 387 io.handle = handle; 388 io.buffer = buffer; 389 io.cnt = cnt; 390 io.__field = __F_HANDLE | __F_BUFFER | __F_CNT; 391 return (__ibsubmit(&io)); 392} 393 394int 395ibrdf (int handle, char * flname) 396{ 397 struct ibfoo_iocarg io; 398 399 io.__ident = __ID_IBRDF; 400 io.handle = handle; 401 io.flname = flname; 402 io.__field = __F_HANDLE | __F_FLNAME; 403 return (__ibsubmit(&io)); 404} 405 406int 407ibrdkey (int handle, void * buffer, int cnt) 408{ 409 struct ibfoo_iocarg io; 410 411 io.__ident = __ID_IBRDKEY; 412 io.handle = handle; 413 io.buffer = buffer; 414 io.cnt = cnt; 415 io.__field = __F_HANDLE | __F_BUFFER | __F_CNT; 416 return (__ibsubmit(&io)); 417} 418 419int 420ibrpp (int handle, char * ppr) 421{ 422 struct ibfoo_iocarg io; 423 424 io.__ident = __ID_IBRPP; 425 io.handle = handle; 426 io.ppr = ppr; 427 io.__field = __F_HANDLE | __F_PPR; 428 return (__ibsubmit(&io)); 429} 430 431int 432ibrsc (int handle, int v) 433{ 434 struct ibfoo_iocarg io; 435 436 io.__ident = __ID_IBRSC; 437 io.handle = handle; 438 io.v = v; 439 io.__field = __F_HANDLE | __F_V; 440 return (__ibsubmit(&io)); 441} 442 443int 444ibrsp (int handle, char * spr) 445{ 446 struct ibfoo_iocarg io; 447 448 io.__ident = __ID_IBRSP; 449 io.handle = handle; 450 io.spr = spr; 451 io.__field = __F_HANDLE | __F_SPR; 452 return (__ibsubmit(&io)); 453} 454 455int 456ibrsv (int handle, int v) 457{ 458 struct ibfoo_iocarg io; 459 460 io.__ident = __ID_IBRSV; 461 io.handle = handle; 462 io.v = v; 463 io.__field = __F_HANDLE | __F_V; 464 return (__ibsubmit(&io)); 465} 466 467int 468ibsad (int handle, int v) 469{ 470 struct ibfoo_iocarg io; 471 472 io.__ident = __ID_IBSAD; 473 io.handle = handle; 474 io.v = v; 475 io.__field = __F_HANDLE | __F_V; 476 return (__ibsubmit(&io)); 477} 478 479int 480ibsgnl (int handle, int v) 481{ 482 struct ibfoo_iocarg io; 483 484 io.__ident = __ID_IBSGNL; 485 io.handle = handle; 486 io.v = v; 487 io.__field = __F_HANDLE | __F_V; 488 return (__ibsubmit(&io)); 489} 490 491int 492ibsic (int handle) 493{ 494 struct ibfoo_iocarg io; 495 496 io.__ident = __ID_IBSIC; 497 io.handle = handle; 498 io.__field = __F_HANDLE; 499 return (__ibsubmit(&io)); 500} 501 502int 503ibsre (int handle, int v) 504{ 505 struct ibfoo_iocarg io; 506 507 io.__ident = __ID_IBSRE; 508 io.handle = handle; 509 io.v = v; 510 io.__field = __F_HANDLE | __F_V; 511 return (__ibsubmit(&io)); 512} 513 514int 515ibsrq (ibsrq_t * func) 516{ 517 struct ibfoo_iocarg io; 518 519 io.__ident = __ID_IBSRQ; 520 io.func = func; 521 io.__field = __F_FUNC; 522 return (__ibsubmit(&io)); 523} 524 525int 526ibstop (int handle) 527{ 528 struct ibfoo_iocarg io; 529 530 io.__ident = __ID_IBSTOP; 531 io.handle = handle; 532 io.__field = __F_HANDLE; 533 return (__ibsubmit(&io)); 534} 535 536int 537ibtmo (int handle, int tmo) 538{ 539 struct ibfoo_iocarg io; 540 541 io.__ident = __ID_IBTMO; 542 io.handle = handle; 543 io.tmo = tmo; 544 io.__field = __F_HANDLE | __F_TMO; 545 return (__ibsubmit(&io)); 546} 547 548int 549ibtrap (int mask, int mode) 550{ 551 struct ibfoo_iocarg io; 552 553 io.__ident = __ID_IBTRAP; 554 io.mask = mask; 555 io.mode = mode; 556 io.__field = __F_MASK | __F_MODE; 557 return (__ibsubmit(&io)); 558} 559 560int 561ibtrg (int handle) 562{ 563 struct ibfoo_iocarg io; 564 565 io.__ident = __ID_IBTRG; 566 io.handle = handle; 567 io.__field = __F_HANDLE; 568 return (__ibsubmit(&io)); 569} 570 571int 572ibwait (int handle, int mask) 573{ 574 struct ibfoo_iocarg io; 575 576 io.__ident = __ID_IBWAIT; 577 io.handle = handle; 578 io.mask = mask; 579 io.__field = __F_HANDLE | __F_MASK; 580 return (__ibsubmit(&io)); 581} 582 583int 584ibwrt (int handle, void * buffer, long cnt) 585{ 586 struct ibfoo_iocarg io; 587 588 io.__ident = __ID_IBWRT; 589 io.handle = handle; 590 io.buffer = buffer; 591 io.cnt = cnt; 592 io.__field = __F_HANDLE | __F_BUFFER | __F_CNT; 593 return (__ibsubmit(&io)); 594} 595 596int 597ibwrta (int handle, void * buffer, long cnt) 598{ 599 struct ibfoo_iocarg io; 600 601 io.__ident = __ID_IBWRTA; 602 io.handle = handle; 603 io.buffer = buffer; 604 io.cnt = cnt; 605 io.__field = __F_HANDLE | __F_BUFFER | __F_CNT; 606 return (__ibsubmit(&io)); 607} 608 609int 610ibwrtf (int handle, char * flname) 611{ 612 struct ibfoo_iocarg io; 613 614 io.__ident = __ID_IBWRTF; 615 io.handle = handle; 616 io.flname = flname; 617 io.__field = __F_HANDLE | __F_FLNAME; 618 return (__ibsubmit(&io)); 619} 620 621int 622ibwrtkey (int handle, void * buffer, int cnt) 623{ 624 struct ibfoo_iocarg io; 625 626 io.__ident = __ID_IBWRTKEY; 627 io.handle = handle; 628 io.buffer = buffer; 629 io.cnt = cnt; 630 io.__field = __F_HANDLE | __F_BUFFER | __F_CNT; 631 return (__ibsubmit(&io)); 632} 633 634int 635ibxtrc (int handle, void * buffer, long cnt) 636{ 637 struct ibfoo_iocarg io; 638 639 io.__ident = __ID_IBXTRC; 640 io.handle = handle; 641 io.buffer = buffer; 642 io.cnt = cnt; 643 io.__field = __F_HANDLE | __F_BUFFER | __F_CNT; 644 return (__ibsubmit(&io)); 645} 646 647