ibask.c 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370
  1. /***************************************************************************
  2. lib/ibask.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 query_ist( const ibBoard_t *board )
  17. {
  18. int retval;
  19. board_info_ioctl_t info;
  20. retval = ioctl( board->fileno, IBBOARD_INFO, &info );
  21. if( retval < 0 )
  22. {
  23. setIberr( EDVR );
  24. setIbcnt( errno );
  25. return retval;
  26. }
  27. return info.ist;
  28. }
  29. int query_ppc( const ibBoard_t *board )
  30. {
  31. int retval;
  32. board_info_ioctl_t info;
  33. retval = ioctl( board->fileno, IBBOARD_INFO, &info );
  34. if( retval < 0 )
  35. {
  36. setIberr( EDVR );
  37. setIbcnt( errno );
  38. return retval;
  39. }
  40. return info.parallel_poll_configuration;
  41. }
  42. int query_autopoll( const ibBoard_t *board )
  43. {
  44. int retval;
  45. board_info_ioctl_t info;
  46. retval = ioctl( board->fileno, IBBOARD_INFO, &info );
  47. if( retval < 0 )
  48. {
  49. setIberr( EDVR );
  50. setIbcnt( errno );
  51. return retval;
  52. }
  53. return info.autopolling;
  54. }
  55. int query_board_t1_delay( const ibBoard_t *board )
  56. {
  57. int retval;
  58. board_info_ioctl_t info;
  59. retval = ioctl( board->fileno, IBBOARD_INFO, &info );
  60. if( retval < 0 )
  61. {
  62. setIberr( EDVR );
  63. setIbcnt( errno );
  64. return retval;
  65. }
  66. if(info.t1_delay == 0)
  67. {
  68. fprintf(stderr, "%s: bug! we don't know what the T1 delay is because it has never been set.\n",
  69. __FUNCTION__);
  70. return -EIO;
  71. }else if( info.t1_delay < 500 ) return T1_DELAY_350ns;
  72. else if( info.t1_delay < 2000 ) return T1_DELAY_500ns;
  73. return T1_DELAY_2000ns;
  74. }
  75. int query_board_rsv( const ibBoard_t *board )
  76. {
  77. int retval;
  78. int status;
  79. retval = ioctl( board->fileno, IBQUERY_BOARD_RSV, &status );
  80. if( retval < 0 )
  81. {
  82. setIberr( EDVR );
  83. setIbcnt( errno );
  84. return retval;
  85. }
  86. return status;
  87. }
  88. int query_pad( const ibBoard_t *board, unsigned int *pad )
  89. {
  90. int retval;
  91. board_info_ioctl_t info;
  92. retval = ioctl( board->fileno, IBBOARD_INFO, &info );
  93. if( retval < 0 )
  94. {
  95. setIberr( EDVR );
  96. setIbcnt( errno );
  97. return retval;
  98. }
  99. *pad = info.pad;
  100. return 0;
  101. }
  102. int query_sad( const ibBoard_t *board, int *sad )
  103. {
  104. int retval;
  105. board_info_ioctl_t info;
  106. retval = ioctl( board->fileno, IBBOARD_INFO, &info );
  107. if( retval < 0 )
  108. {
  109. setIberr( EDVR );
  110. setIbcnt( errno );
  111. return retval;
  112. }
  113. *sad = info.sad;
  114. return 0;
  115. }
  116. int query_no_7_bit_eos(const ibBoard_t *board)
  117. {
  118. int retval;
  119. board_info_ioctl_t info;
  120. retval = ioctl(board->fileno, IBBOARD_INFO, &info);
  121. if( retval < 0 )
  122. {
  123. setIberr( EDVR );
  124. setIbcnt( errno );
  125. return retval;
  126. }
  127. return info.no_7_bit_eos;
  128. }
  129. int ibask( int ud, int option, int *value )
  130. {
  131. ibConf_t *conf;
  132. ibBoard_t *board;
  133. int retval;
  134. conf = general_enter_library( ud, 1, 0 );
  135. if( conf == NULL )
  136. return exit_library( ud, 1);
  137. board = interfaceBoard( conf );
  138. switch( option )
  139. {
  140. case IbaPAD:
  141. if( conf->is_interface )
  142. {
  143. unsigned int pad;
  144. retval = query_pad( board, &pad );
  145. if( retval < 0 ) return exit_library( ud, 1 );
  146. conf->settings.pad = pad;
  147. }
  148. *value = conf->settings.pad;
  149. return exit_library( ud, 0 );
  150. break;
  151. case IbaSAD:
  152. if( conf->is_interface )
  153. {
  154. int sad;
  155. retval = query_sad( board, &sad );
  156. if( retval < 0 ) return exit_library( ud, 1 );
  157. conf->settings.sad = sad;
  158. }
  159. if( conf->settings.sad < 0 ) *value = 0;
  160. else *value = MSA( conf->settings.sad );
  161. return exit_library( ud, 0 );
  162. break;
  163. case IbaTMO:
  164. *value = usec_to_timeout( conf->settings.usec_timeout );
  165. return exit_library( ud, 0 );
  166. break;
  167. case IbaEOT:
  168. *value = conf->settings.send_eoi;
  169. return exit_library( ud, 0 );
  170. break;
  171. case IbaEOSrd:
  172. *value = conf->settings.eos_flags & REOS;
  173. return exit_library( ud, 0 );
  174. break;
  175. case IbaEOSwrt:
  176. *value = conf->settings.eos_flags & XEOS;
  177. return exit_library( ud, 0 );
  178. break;
  179. case IbaEOScmp:
  180. *value = conf->settings.eos_flags & BIN;
  181. return exit_library( ud, 0 );
  182. break;
  183. case IbaEOSchar:
  184. *value = conf->settings.eos;
  185. return exit_library( ud, 0 );
  186. break;
  187. case IbaReadAdjust:
  188. /* XXX I guess I could implement byte swapping stuff,
  189. * it's pretty stupid though */
  190. *value = 0;
  191. return exit_library( ud, 0 );
  192. break;
  193. case IbaWriteAdjust:
  194. /* XXX I guess I could implement byte swapping stuff,
  195. * it's pretty stupid though */
  196. *value = 0;
  197. return exit_library( ud, 0 );
  198. break;
  199. case IbaEndBitIsNormal:
  200. /* XXX no support for setting END status on EOI only yet */
  201. *value = 1;
  202. return exit_library( ud, 0 );
  203. break;
  204. default:
  205. break;
  206. }
  207. if( conf->is_interface )
  208. {
  209. switch( option )
  210. {
  211. case IbaPPC:
  212. retval = query_ppc( board );
  213. if( retval < 0 ) return exit_library( ud, 1 );
  214. *value = retval;
  215. return exit_library( ud, 0 );
  216. break;
  217. case IbaAUTOPOLL:
  218. retval = query_autopoll( board );
  219. if( retval < 0 ) return exit_library( ud, 1 );
  220. *value = retval;
  221. return exit_library( ud, 0 );
  222. break;
  223. case IbaCICPROT:
  224. // XXX we don't support pass control protocol yet
  225. *value = 0;
  226. return exit_library( ud, 0 );
  227. break;
  228. case IbaIRQ:
  229. // XXX we don't support interrupt-less operation yet
  230. *value = 0;
  231. return exit_library( ud, 0 );
  232. break;
  233. case IbaSC:
  234. retval = is_system_controller( board );
  235. if( retval < 0 ) return exit_library( ud, 1 );
  236. *value = retval;
  237. return exit_library( ud, 0 );
  238. break;
  239. case IbaSRE:
  240. /* XXX pretty worthless, until changing
  241. * system controllers is supported */
  242. *value = 1;
  243. return exit_library( ud, 0 );
  244. break;
  245. case IbaPP2:
  246. *value = conf->settings.local_ppc;
  247. return exit_library( ud, 0 );
  248. break;
  249. case IbaTIMING:
  250. retval = query_board_t1_delay( board );
  251. if( retval < 0 ) return exit_library( ud, 1 );
  252. *value = retval;
  253. return exit_library( ud, 0 );
  254. break;
  255. case IbaDMA:
  256. // XXX bogus, but pretty unimportant
  257. *value = board->dma;
  258. return exit_library( ud, 0 );
  259. break;
  260. case IbaEventQueue:
  261. *value = board->use_event_queue;
  262. return exit_library( ud, 0 );
  263. break;
  264. case IbaSPollBit:
  265. *value = 1;
  266. return exit_library( ud, 0 );
  267. break;
  268. case IbaSendLLO:
  269. *value = conf->settings.local_lockout;
  270. return exit_library( ud, 0 );
  271. break;
  272. case IbaPPollTime:
  273. *value = usec_to_ppoll_timeout( conf->settings.ppoll_usec_timeout );
  274. return exit_library( ud, 0 );
  275. break;
  276. case IbaHSCableLength:
  277. /* HS transfer not supported and may never
  278. * be as it is not part of GPIB standard */
  279. *value = 0;
  280. return exit_library( ud, 0 );
  281. break;
  282. case IbaIst:
  283. retval = query_ist( board );
  284. if( retval < 0 ) return exit_library( ud, 1 );
  285. *value = retval;
  286. return exit_library( ud, 0 );
  287. break;
  288. case IbaRsv:
  289. retval = query_board_rsv( board );
  290. if( retval < 0 ) return exit_library( ud, 1 );
  291. *value = retval;
  292. return exit_library( ud, 0 );
  293. break;
  294. case Iba7BitEOS:
  295. retval = query_no_7_bit_eos(board);
  296. if( retval < 0 ) return exit_library( ud, 1 );
  297. *value = !retval;
  298. return exit_library( ud, 0 );
  299. break;
  300. default:
  301. break;
  302. }
  303. }else
  304. {
  305. switch( option )
  306. {
  307. case IbaREADDR:
  308. *value = conf->settings.readdr;
  309. return exit_library( ud, 0 );
  310. break;
  311. case IbaSPollTime:
  312. *value = usec_to_timeout( conf->settings.spoll_usec_timeout );
  313. return exit_library( ud, 0 );
  314. break;
  315. case IbaUnAddr:
  316. /* XXX sending UNT and UNL after device level read/write
  317. * not supported yet, I suppose it could be since it
  318. * is harmless. */
  319. *value = 0;
  320. return exit_library( ud, 0 );
  321. break;
  322. case IbaBNA:
  323. *value = conf->settings.board;
  324. return exit_library( ud, 0 );
  325. break;
  326. default:
  327. break;
  328. }
  329. }
  330. setIberr( EARG );
  331. return exit_library( ud, 1 );
  332. }