gpib_user.h 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323
  1. /***************************************************************************
  2. gpib_user.h - header file for gpib library
  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. #ifndef _GPIB_USER_H
  16. #define _GPIB_USER_H
  17. #define GPIB_MAX_NUM_BOARDS 16
  18. #define GPIB_MAX_NUM_DESCRIPTORS 0x1000
  19. enum ibsta_bit_numbers
  20. {
  21. DCAS_NUM = 0,
  22. DTAS_NUM = 1,
  23. LACS_NUM = 2,
  24. TACS_NUM = 3,
  25. ATN_NUM = 4,
  26. CIC_NUM = 5,
  27. REM_NUM = 6,
  28. LOK_NUM = 7,
  29. CMPL_NUM = 8,
  30. EVENT_NUM = 9,
  31. SPOLL_NUM = 10,
  32. RQS_NUM = 11,
  33. SRQI_NUM = 12,
  34. END_NUM = 13,
  35. TIMO_NUM = 14,
  36. ERR_NUM = 15
  37. };
  38. /* IBSTA status bits (returned by all functions) */
  39. enum ibsta_bits
  40. {
  41. DCAS = ( 1 << DCAS_NUM ), /* device clear state */
  42. DTAS = ( 1 << DTAS_NUM ), /* device trigger state */
  43. LACS = ( 1 << LACS_NUM ), /* GPIB interface is addressed as Listener */
  44. TACS = ( 1 << TACS_NUM ), /* GPIB interface is addressed as Talker */
  45. ATN = ( 1 << ATN_NUM ), /* Attention is asserted */
  46. CIC = ( 1 << CIC_NUM ), /* GPIB interface is Controller-in-Charge */
  47. REM = ( 1 << REM_NUM ), /* remote state */
  48. LOK = ( 1 << LOK_NUM ), /* lockout state */
  49. CMPL = ( 1 << CMPL_NUM ), /* I/O is complete */
  50. EVENT = ( 1 << EVENT_NUM ), /* DCAS, DTAS, or IFC has occurred */
  51. SPOLL = ( 1 << SPOLL_NUM ), /* board serial polled by busmaster */
  52. RQS = ( 1 << RQS_NUM ), /* Device requesting service */
  53. SRQI = ( 1 << SRQI_NUM ), /* SRQ is asserted */
  54. END = ( 1 << END_NUM ), /* EOI or EOS encountered */
  55. TIMO = ( 1 << TIMO_NUM ), /* Time limit on I/O or wait function exceeded */
  56. ERR = ( 1 << ERR_NUM ) /* Function call terminated on error */
  57. };
  58. static const int device_status_mask = ERR | TIMO | END | CMPL | RQS;
  59. static const int board_status_mask = ERR | TIMO | END | CMPL | SPOLL |
  60. EVENT | LOK | REM | CIC | ATN | TACS | LACS | DTAS | DCAS | SRQI;
  61. /* IBERR error codes */
  62. enum iberr_code
  63. {
  64. EDVR = 0, /* system error */
  65. ECIC = 1, /* not CIC */
  66. ENOL = 2, /* no listeners */
  67. EADR = 3, /* CIC and not addressed before I/O */
  68. EARG = 4, /* bad argument to function call */
  69. ESAC = 5, /* not SAC */
  70. EABO = 6, /* I/O operation was aborted */
  71. ENEB = 7, /* non-existent board (GPIB interface offline) */
  72. EDMA = 8, /* DMA hardware error detected */
  73. EOIP = 10, /* new I/O attempted with old I/O in progress */
  74. ECAP = 11, /* no capability for intended opeation */
  75. EFSO = 12, /* file system operation error */
  76. EBUS = 14, /* bus error */
  77. ESTB = 15, /* lost serial poll bytes */
  78. ESRQ = 16, /* SRQ stuck on */
  79. ETAB = 20 /* Table Overflow */
  80. };
  81. /* Timeout values and meanings */
  82. enum gpib_timeout
  83. {
  84. TNONE = 0, /* Infinite timeout (disabled) */
  85. T10us = 1, /* Timeout of 10 usec (ideal) */
  86. T30us = 2, /* Timeout of 30 usec (ideal) */
  87. T100us = 3, /* Timeout of 100 usec (ideal) */
  88. T300us = 4, /* Timeout of 300 usec (ideal) */
  89. T1ms = 5, /* Timeout of 1 msec (ideal) */
  90. T3ms = 6, /* Timeout of 3 msec (ideal) */
  91. T10ms = 7, /* Timeout of 10 msec (ideal) */
  92. T30ms = 8, /* Timeout of 30 msec (ideal) */
  93. T100ms = 9, /* Timeout of 100 msec (ideal) */
  94. T300ms = 10, /* Timeout of 300 msec (ideal) */
  95. T1s = 11, /* Timeout of 1 sec (ideal) */
  96. T3s = 12, /* Timeout of 3 sec (ideal) */
  97. T10s = 13, /* Timeout of 10 sec (ideal) */
  98. T30s = 14, /* Timeout of 30 sec (ideal) */
  99. T100s = 15, /* Timeout of 100 sec (ideal) */
  100. T300s = 16, /* Timeout of 300 sec (ideal) */
  101. T1000s = 17 /* Timeout of 1000 sec (maximum) */
  102. };
  103. /* End-of-string (EOS) modes for use with ibeos */
  104. enum eos_flags
  105. {
  106. EOS_MASK = 0x1c00,
  107. REOS = 0x0400, /* Terminate reads on EOS */
  108. XEOS = 0x800, /* assert EOI when EOS char is sent */
  109. BIN = 0x1000 /* Do 8-bit compare on EOS */
  110. };
  111. /* GPIB Bus Control Lines bit vector */
  112. enum bus_control_line
  113. {
  114. ValidDAV = 0x01,
  115. ValidNDAC = 0x02,
  116. ValidNRFD = 0x04,
  117. ValidIFC = 0x08,
  118. ValidREN = 0x10,
  119. ValidSRQ = 0x20,
  120. ValidATN = 0x40,
  121. ValidEOI = 0x80,
  122. ValidALL = 0xff,
  123. BusDAV = 0x0100, /* DAV line status bit */
  124. BusNDAC = 0x0200, /* NDAC line status bit */
  125. BusNRFD = 0x0400, /* NRFD line status bit */
  126. BusIFC = 0x0800, /* IFC line status bit */
  127. BusREN = 0x1000, /* REN line status bit */
  128. BusSRQ = 0x2000, /* SRQ line status bit */
  129. BusATN = 0x4000, /* ATN line status bit */
  130. BusEOI = 0x8000 /* EOI line status bit */
  131. };
  132. enum old_bus_control_line
  133. {
  134. BUS_DAV = 0x0100, /* DAV line status bit */
  135. BUS_NDAC = 0x0200, /* NDAC line status bit */
  136. BUS_NRFD = 0x0400, /* NRFD line status bit */
  137. BUS_IFC = 0x0800, /* IFC line status bit */
  138. BUS_REN = 0x1000, /* REN line status bit */
  139. BUS_SRQ = 0x2000, /* SRQ line status bit */
  140. BUS_ATN = 0x4000, /* ATN line status bit */
  141. BUS_EOI = 0x8000 /* EOI line status bit */
  142. };
  143. /* Possible GPIB command messages */
  144. enum cmd_byte
  145. {
  146. GTL = 0x1, /* go to local */
  147. SDC = 0x4, /* selected device clear */
  148. PPConfig = 0x5,
  149. #ifndef PPC
  150. PPC = PPConfig, /* parallel poll configure */
  151. #endif
  152. GET = 0x8, /* group execute trigger */
  153. TCT = 0x9, /* take control */
  154. LLO = 0x11, /* local lockout */
  155. DCL = 0x14, /* device clear */
  156. PPU = 0x15, /* parallel poll unconfigure */
  157. SPE = 0x18, /* serial poll enable */
  158. SPD = 0x19, /* serial poll disable */
  159. LAD = 0x20, /* value to be 'ored' in to obtain listen address */
  160. UNL = 0x3F, /* unlisten */
  161. TAD = 0x40, /* value to be 'ored' in to obtain talk address */
  162. UNT = 0x5F, /* untalk */
  163. SAD = 0x60, /* my secondary address (base) */
  164. PPE = 0x60, /* parallel poll enable (base) */
  165. PPD = 0x70 /* parallel poll disable */
  166. };
  167. enum ppe_bits
  168. {
  169. PPC_DISABLE = 0x10,
  170. PPC_SENSE = 0x8, /* parallel poll sense bit */
  171. PPC_DIO_MASK = 0x7
  172. };
  173. static __inline__ uint8_t MLA( unsigned int addr )
  174. {
  175. return addr | LAD;
  176. }
  177. static __inline__ uint8_t MTA( unsigned int addr )
  178. {
  179. return addr | TAD;
  180. }
  181. static __inline__ uint8_t MSA( unsigned int addr )
  182. {
  183. return addr | SAD;
  184. }
  185. static __inline__ uint8_t PPE_byte( unsigned int dio_line, int sense )
  186. {
  187. uint8_t cmd;
  188. cmd = PPE;
  189. if( sense )
  190. cmd |= PPC_SENSE;
  191. cmd |= ( dio_line - 1 ) & 0x7;
  192. return cmd;
  193. }
  194. static __inline__ int gpib_address_equal( unsigned int pad1, int sad1, unsigned int pad2, int sad2 )
  195. {
  196. if( pad1 == pad2 )
  197. {
  198. if( sad1 == sad2 ) return 1;
  199. if( sad1 < 0 && sad2 < 0 ) return 1;
  200. }
  201. return 0;
  202. }
  203. static const int gpib_addr_max = 30; /* max address for primary/secondary gpib addresses */
  204. enum ibask_option
  205. {
  206. IbaPAD = 0x1,
  207. IbaSAD = 0x2,
  208. IbaTMO = 0x3,
  209. IbaEOT = 0x4,
  210. IbaPPC = 0x5, /* board only */
  211. IbaREADDR = 0x6, /* device only */
  212. IbaAUTOPOLL = 0x7, /* board only */
  213. IbaCICPROT = 0x8, /* board only */
  214. IbaIRQ = 0x9, /* board only */
  215. IbaSC = 0xa, /* board only */
  216. IbaSRE = 0xb, /* board only */
  217. IbaEOSrd = 0xc,
  218. IbaEOSwrt = 0xd,
  219. IbaEOScmp = 0xe,
  220. IbaEOSchar = 0xf,
  221. IbaPP2 = 0x10, /* board only */
  222. IbaTIMING = 0x11, /* board only */
  223. IbaDMA = 0x12, /* board only */
  224. IbaReadAdjust = 0x13,
  225. IbaWriteAdjust = 0x14,
  226. IbaEventQueue = 0x15, /* board only */
  227. IbaSPollBit = 0x16, /* board only */
  228. IbaSpollBit = 0x16, /* board only */
  229. IbaSendLLO = 0x17, /* board only */
  230. IbaSPollTime = 0x18, /* device only */
  231. IbaPPollTime = 0x19, /* board only */
  232. IbaEndBitIsNormal = 0x1a,
  233. IbaUnAddr = 0x1b, /* device only */
  234. IbaHSCableLength = 0x1f, /* board only */
  235. IbaIst = 0x20, /* board only */
  236. IbaRsv = 0x21, /* board only */
  237. IbaBNA = 0x200, /* device only */
  238. /* linux-gpib extensions */
  239. Iba7BitEOS = 0x1000 /* board only. Returns 1 if board supports 7 bit eos compares*/
  240. };
  241. enum ibconfig_option
  242. {
  243. IbcPAD = 0x1,
  244. IbcSAD = 0x2,
  245. IbcTMO = 0x3,
  246. IbcEOT = 0x4,
  247. IbcPPC = 0x5, /* board only */
  248. IbcREADDR = 0x6, /* device only */
  249. IbcAUTOPOLL = 0x7, /* board only */
  250. IbcCICPROT = 0x8, /* board only */
  251. IbcIRQ = 0x9, /* board only */
  252. IbcSC = 0xa, /* board only */
  253. IbcSRE = 0xb, /* board only */
  254. IbcEOSrd = 0xc,
  255. IbcEOSwrt = 0xd,
  256. IbcEOScmp = 0xe,
  257. IbcEOSchar = 0xf,
  258. IbcPP2 = 0x10, /* board only */
  259. IbcTIMING = 0x11, /* board only */
  260. IbcDMA = 0x12, /* board only */
  261. IbcReadAdjust = 0x13,
  262. IbcWriteAdjust = 0x14,
  263. IbcEventQueue = 0x15, /* board only */
  264. IbcSPollBit = 0x16, /* board only */
  265. IbcSpollBit = 0x16, /* board only */
  266. IbcSendLLO = 0x17, /* board only */
  267. IbcSPollTime = 0x18, /* device only */
  268. IbcPPollTime = 0x19, /* board only */
  269. IbcEndBitIsNormal = 0x1a,
  270. IbcUnAddr = 0x1b, /* device only */
  271. IbcHSCableLength = 0x1f, /* board only */
  272. IbcIst = 0x20, /* board only */
  273. IbcRsv = 0x21, /* board only */
  274. IbcBNA = 0x200 /* device only */
  275. };
  276. enum t1_delays
  277. {
  278. T1_DELAY_2000ns = 1,
  279. T1_DELAY_500ns = 2,
  280. T1_DELAY_350ns = 3
  281. };
  282. static const int request_service_bit = 0x40;
  283. enum gpib_events
  284. {
  285. EventNone = 0,
  286. EventDevTrg = 1,
  287. EventDevClr = 2,
  288. EventIFC = 3
  289. };
  290. #endif /* _GPIB_USER_H */