ibppc.c 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287
  1. /***************************************************************************
  2. lib/ibppc.c
  3. -------------------
  4. begin : Oct 2002
  5. copyright : (C) 2002 by Frank Mori Hess
  6. email : fmhess@users.sourceforge.net
  7. ***************************************************************************/
  8. /***************************************************************************
  9. * *
  10. * This program is free software; you can redistribute it and/or modify *
  11. * it under the terms of the GNU General Public License as published by *
  12. * the Free Software Foundation; either version 2 of the License, or *
  13. * (at your option) any later version. *
  14. * *
  15. ***************************************************************************/
  16. #include "ib_internal.h"
  17. #include <stdlib.h>
  18. int ppoll_configure_device( ibConf_t *conf, const Addr4882_t addressList[],
  19. int ppc_configuration )
  20. {
  21. uint8_t *cmd;
  22. int i;
  23. int retval;
  24. if( is_cic( interfaceBoard( conf ) ) == 0 )
  25. {
  26. setIberr( ECIC );
  27. return -1;
  28. }
  29. cmd = malloc( 16 + 2 * numAddresses( addressList ) );
  30. if( cmd == NULL )
  31. {
  32. setIberr( EDVR );
  33. setIbcnt( ENOMEM );
  34. return -1;
  35. }
  36. i = create_send_setup( interfaceBoard( conf ), addressList, cmd );
  37. cmd[ i++ ] = PPC;
  38. cmd[ i++ ] = ppc_configuration;
  39. retval = my_ibcmd( conf, cmd, i );
  40. free( cmd );
  41. cmd = NULL;
  42. if( retval < 0 )
  43. {
  44. return -1;
  45. }
  46. return 0;
  47. }
  48. int device_ppc( ibConf_t *conf, int ppc_configuration )
  49. {
  50. Addr4882_t addressList[ 2 ];
  51. addressList[ 0 ] = packAddress( conf->settings.pad, conf->settings.sad );
  52. addressList [ 1 ] = NOADDR;
  53. return ppoll_configure_device( conf, addressList, ppc_configuration );
  54. }
  55. int board_ppc( ibConf_t *conf, int ppc_configuration )
  56. {
  57. ibBoard_t *board;
  58. int retval;
  59. ppoll_config_ioctl_t cmd;
  60. board = interfaceBoard( conf );
  61. if( conf->settings.local_ppc == 0 )
  62. {
  63. setIberr( ECAP );
  64. return -1;
  65. }
  66. retval = query_ppc( board );
  67. if( retval < 0 ) return retval;
  68. conf->settings.ppoll_config = retval; // store old value
  69. cmd.config = ppc_configuration;
  70. cmd.set_ist = 0;
  71. cmd.clear_ist = 0;
  72. retval = ioctl( board->fileno, IBPPC, &cmd );
  73. if( retval < 0 )
  74. {
  75. setIberr( EDVR );
  76. setIbcnt( errno );
  77. return -1;
  78. }
  79. return 0;
  80. }
  81. int internal_ibppc( ibConf_t *conf, int v )
  82. {
  83. static const int ppc_mask = 0xe0;
  84. int retval;
  85. if( v && ( v & ppc_mask ) != PPE )
  86. {
  87. fprintf( stderr, "libgpib: illegal parallel poll configuration\n" );
  88. setIberr( EARG );
  89. return -1;
  90. }
  91. if( !v || (v & PPC_DISABLE) )
  92. v = PPD;
  93. if( conf->is_interface )
  94. {
  95. retval = board_ppc( conf, v );
  96. if( retval < 0 )
  97. return retval;
  98. }else
  99. {
  100. retval = device_ppc( conf, v );
  101. if( retval < 0 ) return retval;
  102. }
  103. setIberr( conf->settings.ppoll_config );
  104. conf->settings.ppoll_config = v;
  105. return 0;
  106. }
  107. int ibppc( int ud, int v )
  108. {
  109. ibConf_t *conf;
  110. int retval;
  111. conf = enter_library( ud );
  112. if( conf == NULL )
  113. return exit_library( ud, 1 );
  114. retval = internal_ibppc( conf, v );
  115. if( retval < 0 ) return exit_library( ud, 1 );
  116. return exit_library( ud, 0 );
  117. }
  118. void PPollConfig( int boardID, Addr4882_t address,
  119. int dataLine, int lineSense )
  120. {
  121. ibConf_t *conf;
  122. int retval;
  123. int ppoll_config;
  124. Addr4882_t addressList[ 2 ];
  125. conf = enter_library( boardID );
  126. if( conf == NULL )
  127. {
  128. exit_library( boardID, 1 );
  129. return;
  130. }
  131. if( conf->is_interface == 0 )
  132. {
  133. setIberr( EDVR );
  134. exit_library( boardID, 1 );
  135. return;
  136. }
  137. if( dataLine < 1 || dataLine > 8 ||
  138. addressIsValid( address ) == 0 || address == NOADDR )
  139. {
  140. setIberr( EARG );
  141. exit_library( boardID, 1 );
  142. return;
  143. }
  144. ppoll_config = PPE_byte( dataLine, lineSense );
  145. addressList[ 0 ] = address;
  146. addressList[ 1 ]= NOADDR;
  147. retval = ppoll_configure_device( conf,
  148. addressList, ppoll_config );
  149. if( retval < 0 )
  150. {
  151. exit_library( boardID, 1 );
  152. return;
  153. }
  154. exit_library( boardID, 0 );
  155. }
  156. void PPollUnconfig( int boardID, const Addr4882_t addressList[] )
  157. {
  158. ibConf_t *conf;
  159. int retval;
  160. conf = enter_library( boardID );
  161. if( conf == NULL )
  162. {
  163. exit_library( boardID, 1 );
  164. return;
  165. }
  166. if( conf->is_interface == 0 )
  167. {
  168. setIberr( EDVR );
  169. exit_library( boardID, 1 );
  170. return;
  171. }
  172. if( addressListIsValid( addressList ) == 0 )
  173. {
  174. setIberr( EARG );
  175. exit_library( boardID, 1 );
  176. return;
  177. }
  178. if( numAddresses( addressList ) )
  179. {
  180. retval = ppoll_configure_device( conf,
  181. addressList, PPD );
  182. }else
  183. {
  184. uint8_t cmd = PPU;
  185. retval = my_ibcmd( conf, &cmd, 1 );
  186. }
  187. if( retval < 0 )
  188. {
  189. exit_library( boardID, 1 );
  190. return;
  191. }
  192. exit_library( boardID, 0 );
  193. }
  194. int internal_ibist( ibConf_t *conf, int ist )
  195. {
  196. int retval;
  197. ppoll_config_ioctl_t cmd;
  198. if( conf->is_interface == 0 )
  199. {
  200. setIberr( EARG );
  201. return -1;
  202. }
  203. retval = query_ist( interfaceBoard( conf ) );
  204. if( retval < 0 ) return retval;
  205. setIberr( retval ); // set iberr to old ist value
  206. cmd.config = 0;
  207. cmd.set_ist = 0;
  208. cmd.clear_ist = 0;
  209. if( ist )
  210. cmd.set_ist = 1;
  211. else
  212. cmd.clear_ist = 1;
  213. retval = ioctl( interfaceBoard( conf )->fileno, IBPPC, &cmd );
  214. if( retval < 0 )
  215. {
  216. setIberr( EDVR );
  217. setIbcnt( errno );
  218. return -1;
  219. }
  220. return 0;
  221. }
  222. int ibist( int ud, int ist )
  223. {
  224. ibConf_t *conf;
  225. int retval;
  226. conf = enter_library( ud );
  227. if( conf == NULL )
  228. return exit_library( ud, 1 );
  229. retval = internal_ibist( conf, ist );
  230. if( retval < 0 ) return exit_library( ud, 1 );
  231. return exit_library( ud, 0 );
  232. }