ibcmd.c 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. /***************************************************************************
  2. sys/ibcmd.c
  3. -------------------
  4. copyright : (C) 2001, 2002 by Frank Mori Hess
  5. email : fmhess@users.sourceforge.net
  6. ***************************************************************************/
  7. /***************************************************************************
  8. * *
  9. * This program is free software; you can redistribute it and/or modify *
  10. * it under the terms of the GNU General Public License as published by *
  11. * the Free Software Foundation; either version 2 of the License, or *
  12. * (at your option) any later version. *
  13. * *
  14. ***************************************************************************/
  15. #include "gpibP.h"
  16. /*
  17. * IBCMD
  18. * Write cnt command bytes from buf to the GPIB. The
  19. * command operation terminates only on I/O complete.
  20. *
  21. * NOTE:
  22. * 1. Prior to beginning the command, the interface is
  23. * placed in the controller active state.
  24. * 2. Before calling ibcmd for the first time, ibsic
  25. * must be called to initialize the GPIB and enable
  26. * the interface to leave the controller idle state.
  27. */
  28. ssize_t ibcmd( gpib_board_t *board, uint8_t *buf, size_t length )
  29. {
  30. size_t count = 0;
  31. ssize_t ret = 0;
  32. int status = ibstatus( board );
  33. if(length == 0) return 0;
  34. if((status & CIC) == 0)
  35. {
  36. printk("gpib: cannot send command when not controller-in-charge\n");
  37. return -1;
  38. }
  39. osStartTimer( board, board->usec_timeout );
  40. ret = ibcac( board, 0 );
  41. if( ret == 0 )
  42. {
  43. ret = board->interface->command(board, buf, length - count);
  44. if(ret < 0)
  45. {
  46. printk("gpib: error writing gpib command bytes\n");
  47. }else
  48. {
  49. buf += ret;
  50. count += ret;
  51. }
  52. }
  53. osRemoveTimer(board);
  54. if( io_timed_out( board ) )
  55. ret = -ETIMEDOUT;
  56. return ret ? ret : count;
  57. }