ibutil.c 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. #include "gpibP.h"
  2. #include "autopoll.h"
  3. /*
  4. * IBPAD
  5. * change the GPIB address of the interface board. The address
  6. * must be 0 through 30. ibonl resets the address to PAD.
  7. */
  8. int ibpad( gpib_board_t *board, unsigned int addr )
  9. {
  10. if ( addr > 30 )
  11. {
  12. printk("gpib: invalid primary address %u\n", addr );
  13. return -1;
  14. }else
  15. {
  16. board->pad = addr;
  17. if( board->online )
  18. board->interface->primary_address( board, board->pad );
  19. GPIB_DPRINTK( "set primary addr to %i\n", board->pad );
  20. }
  21. return 0;
  22. }
  23. /*
  24. * IBSAD
  25. * change the secondary GPIB address of the interface board.
  26. * The address must be 0 through 30, or negative disables. ibonl resets the
  27. * address to SAD.
  28. */
  29. int ibsad( gpib_board_t *board, int addr )
  30. {
  31. if( addr > 30 )
  32. {
  33. printk("gpib: invalid secondary address %i, must be 0-30\n", addr);
  34. return -1;
  35. }else
  36. {
  37. board->sad = addr;
  38. if( board->online )
  39. {
  40. if( board->sad >= 0 )
  41. {
  42. board->interface->secondary_address( board, board->sad, 1 );
  43. }else
  44. {
  45. board->interface->secondary_address( board, 0, 0 );
  46. }
  47. }
  48. GPIB_DPRINTK( "set secondary addr to %i\n", board->sad );
  49. }
  50. return 0;
  51. }
  52. /*
  53. * IBEOS
  54. * Set the end-of-string modes for I/O operations to v.
  55. *
  56. */
  57. int ibeos( gpib_board_t *board, int eos, int eosflags )
  58. {
  59. int retval;
  60. if( eosflags & ~EOS_MASK )
  61. {
  62. printk( "bad EOS modes\n" );
  63. return -EINVAL;
  64. }else
  65. {
  66. if( eosflags & REOS )
  67. {
  68. retval = board->interface->enable_eos( board, eos, eosflags & BIN );
  69. }else
  70. {
  71. board->interface->disable_eos( board );
  72. retval = 0;
  73. }
  74. }
  75. return retval;
  76. }
  77. int ibstatus( gpib_board_t *board )
  78. {
  79. return general_ibstatus( board, NULL, 0, 0, NULL);
  80. }
  81. int general_ibstatus( gpib_board_t *board, const gpib_status_queue_t *device,
  82. int clear_mask, int set_mask, gpib_descriptor_t *desc )
  83. {
  84. int status = 0;
  85. short line_status;
  86. if( board->private_data )
  87. {
  88. status = board->interface->update_status( board, clear_mask );
  89. /* XXX should probably stop having drivers use TIMO bit in
  90. * board->status to avoid confusion */
  91. status &= ~TIMO;
  92. /* get real SRQI status if we can */
  93. if(iblines(board, &line_status) == 0)
  94. {
  95. if((line_status & ValidSRQ))
  96. {
  97. if((line_status & BusSRQ))
  98. {
  99. status |= SRQI;
  100. }else
  101. {
  102. status &= ~SRQI;
  103. }
  104. }
  105. }
  106. }
  107. if( device )
  108. if( num_status_bytes( device ) ) status |= RQS;
  109. if( desc )
  110. {
  111. if( desc->io_in_progress )
  112. status &= ~CMPL;
  113. else
  114. status |= CMPL;
  115. if( clear_mask & CMPL )
  116. desc->io_in_progress = 0;
  117. if( set_mask & CMPL )
  118. desc->io_in_progress = 1;
  119. }
  120. if( num_gpib_events( &board->event_queue ) )
  121. status |= EVENT;
  122. else
  123. status &= ~EVENT;
  124. return status;
  125. }