ibSic.c 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. /***************************************************************************
  2. lib/ibSic.c
  3. -------------------
  4. copyright : (C) 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 "ib_internal.h"
  16. int assert_ifc( ibBoard_t *board, unsigned int usec_duration )
  17. {
  18. int retval;
  19. retval = ioctl( board->fileno, IBSIC, &usec_duration );
  20. if( retval < 0 )
  21. {
  22. setIberr( EDVR );
  23. setIbcnt( errno );
  24. }
  25. return retval;
  26. }
  27. int internal_ibsic( ibConf_t *conf )
  28. {
  29. ibBoard_t *board;
  30. if( conf->is_interface == 0 )
  31. {
  32. setIberr( EARG );
  33. return -1;
  34. }
  35. board = interfaceBoard( conf );
  36. if( is_system_controller( board ) == 0 )
  37. {
  38. setIberr( ESAC );
  39. return -1;
  40. }
  41. return assert_ifc( board, 100 );
  42. }
  43. int ibsic(int ud)
  44. {
  45. ibConf_t *conf;
  46. int retval;
  47. conf = enter_library( ud );
  48. if( conf == NULL )
  49. return exit_library( ud, 1 );
  50. retval = internal_ibsic( conf );
  51. if( retval < 0 )
  52. {
  53. return exit_library( ud, 1 );
  54. }
  55. return exit_library( ud, 0 );
  56. }
  57. void SendIFC( int boardID )
  58. {
  59. ibsic( boardID );
  60. }
  61. int request_system_control( ibBoard_t *board, int request_control )
  62. {
  63. rsc_ioctl_t rsc_cmd;
  64. int retval;
  65. rsc_cmd = request_control != 0;
  66. retval = ioctl( board->fileno, IBRSC, &rsc_cmd );
  67. if( retval < 0 )
  68. {
  69. fprintf( stderr, "libgpib: IBRSC ioctl failed\n" );
  70. setIberr( EDVR );
  71. setIbcnt( errno );
  72. return retval;
  73. }
  74. board->is_system_controller = request_control != 0;
  75. return 0;
  76. }
  77. int internal_ibrsc( ibConf_t *conf, int request_control )
  78. {
  79. int retval;
  80. if( conf->is_interface == 0 )
  81. {
  82. setIberr( EARG );
  83. return -1;
  84. }
  85. retval = request_system_control( interfaceBoard( conf ), request_control );
  86. if( retval < 0 )
  87. return retval;
  88. return 0;
  89. }
  90. int ibrsc( int ud, int request_control )
  91. {
  92. ibConf_t *conf;
  93. int retval;
  94. conf = enter_library( ud );
  95. if( conf == NULL )
  96. return exit_library( ud, 1 );
  97. retval = internal_ibrsc( conf, request_control );
  98. if( retval < 0 )
  99. {
  100. return exit_library( ud, 1 );
  101. }
  102. return exit_library( ud, 0 );
  103. }