scpi_gpib_core.c 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767
  1. #define SCPI_GPIB_CORE_C
  2. #include "app/scpi/scpi_gpib_core.h"
  3. #include "my_assert.h"
  4. // Reference:
  5. // [1] SCPI Specification, revision 1999.0
  6. // "Standard Commands for Programmable Instruments (SCPI), VERSION 1999.0, May 1999"
  7. // [2], Gpib Programming Tutorial, Electronics Group (http://www.few.vu.nl/~elec), 11 January 2000 Electronics Group, (http://g2pc1.bu.edu/~qzpeng/gpib/manual/GpibProgTut.pdf)
  8. // [3] USBTMC-USB488 Standard, rev. 1.0, 14/04/2003
  9. // "Universal Serial Bus Test and Measurement Class, Subclass USB488 Specification (USBTMC-USB488)
  10. // [4] IEEE 488.2 Standard, revision IEEE Std 488.2-1987 (1992)
  11. // "IEEE Standard Codes, Formats, Protocols, and Common Commands for Use With IEEE Std 488.1-1987, IEEE
  12. static void gpib_get_event_status_register( xGPIBRegisters_t * _gpibr, uint8_t * pesr );
  13. static void gpib_set_event_status_register_power_on_state( xGPIBRegisters_t * _gpibr, bool pon );
  14. static void gpib_set_event_status_register_user_request_state( xGPIBRegisters_t * _gpibr, bool urq );
  15. static void gpib_set_event_status_register_command_error_state( xGPIBRegisters_t * _gpibr, bool cme );
  16. static void gpib_set_event_status_register_execution_error_state( xGPIBRegisters_t * _gpibr, bool e );
  17. static void gpib_set_event_status_register_device_specific_error_state( xGPIBRegisters_t * _gpibr, bool dde );
  18. static void gpib_set_event_status_register_query_error_state( xGPIBRegisters_t * _gpibr, bool qye );
  19. static void gpib_set_event_status_register_request_control_state( xGPIBRegisters_t * _gpibr, bool rqc );
  20. static void gpib_set_event_status_register_operation_complete_state( xGPIBRegisters_t * _gpibr, bool opc );
  21. static void gpib_get_event_status_enable_register( xGPIBRegisters_t * _gpibr, uint8_t * pese );
  22. static void gpib_set_event_status_enable_register( xGPIBRegisters_t * _gpibr, uint8_t ese );
  23. static void gpib_get_event_summary_bit( xGPIBRegisters_t * _gpibr, uint8_t * pesb );
  24. static void gpib_set_event_summary_enable_state( xGPIBRegisters_t * _gpibr, bool esb );
  25. static void gpib_set_message_available_bit( xGPIBRegisters_t * _gpibr, bool mav );
  26. static void gpib_set_message_available_enable_state( xGPIBRegisters_t * _gpibr, bool mav );
  27. static void gpib_get_message_available_bit( xGPIBRegisters_t * _gpibr, uint8_t * pmav );
  28. static void gpib_set_error_available_bit( xGPIBRegisters_t * _gpibr, bool eav );
  29. static void gpib_set_error_available_enable_state( xGPIBRegisters_t * _gpibr, bool eav );
  30. static void gpib_get_error_available_bit( xGPIBRegisters_t * _gpibr, uint8_t * peav );
  31. static void gpib_get_status_byte_serial_poll( xGPIBRegisters_t * _gpibr, uint8_t * pstb );
  32. static void gpib_get_status_byte_normal_poll( xGPIBRegisters_t * _gpibr, uint8_t * pstb );
  33. static void gpib_clr_status_byte( xGPIBRegisters_t * _gpibr );
  34. static void gpib_get_service_request_enable_register( xGPIBRegisters_t * _gpibr, uint8_t * psre );
  35. static void gpib_set_service_request_enable_register( xGPIBRegisters_t * _gpibr, uint8_t sre );
  36. static void gpib_get_service_request_status( xGPIBRegisters_t * _gpibr, bool * psrq );
  37. static void gpib_set_service_request_status( xGPIBRegisters_t * _gpibr, bool srq );
  38. const sGPIBMachineRoutines_t GPIBMachine =
  39. {
  40. .fGPIB_get_event_status_register = gpib_get_event_status_register,
  41. .fGPIB_set_event_status_register_power_on_state = gpib_set_event_status_register_power_on_state,
  42. .fGPIB_set_event_status_register_user_request_state = gpib_set_event_status_register_user_request_state,
  43. .fGPIB_set_event_status_register_command_error_state = gpib_set_event_status_register_command_error_state,
  44. .fGPIB_set_event_status_register_execution_error_state = gpib_set_event_status_register_execution_error_state,
  45. .fGPIB_set_event_status_register_device_specific_error_state = gpib_set_event_status_register_device_specific_error_state,
  46. .fGPIB_set_event_status_register_query_error_state = gpib_set_event_status_register_query_error_state,
  47. .fGPIB_set_event_status_register_request_control_state = gpib_set_event_status_register_request_control_state,
  48. .fGPIB_set_event_status_register_operation_complete_state = gpib_set_event_status_register_operation_complete_state,
  49. .fGPIB_get_event_status_enable_register = gpib_get_event_status_enable_register,
  50. .fGPIB_set_event_status_enable_register = gpib_set_event_status_enable_register,
  51. .fGPIB_get_event_summary_bit = gpib_get_event_summary_bit,
  52. .fGPIB_set_event_summary_enable_state = gpib_set_event_summary_enable_state,
  53. .fGPIB_set_message_available_bit = gpib_set_message_available_bit,
  54. .fGPIB_set_message_available_enable_state = gpib_set_message_available_enable_state,
  55. .fGPIB_get_message_available_bit = gpib_get_message_available_bit,
  56. .fGPIB_set_error_available_bit = gpib_set_error_available_bit,
  57. .fGPIB_set_error_available_enable_state = gpib_set_error_available_enable_state,
  58. .fGPIB_get_error_available_bit = gpib_get_error_available_bit,
  59. .fGPIB_get_status_byte_serial_poll = gpib_get_status_byte_serial_poll,
  60. .fGPIB_get_status_byte_normal_poll = gpib_get_status_byte_normal_poll,
  61. .fGPIB_clr_status_byte = gpib_clr_status_byte,
  62. .fGPIB_get_service_request_enable_register = gpib_get_service_request_enable_register,
  63. .fGPIB_set_service_request_enable_register = gpib_set_service_request_enable_register,
  64. .fGPIB_get_service_request_status = gpib_get_service_request_status,
  65. .fGPIB_set_service_request_status = gpib_set_service_request_status,
  66. };
  67. // Reference:
  68. // [1] SCPI Specification, revision 1999.0
  69. // "Standard Commands for Programmable Instruments (SCPI), VERSION 1999.0, May 1999"
  70. // [2], Gpib Programming Tutorial, Electronics Group (http://www.few.vu.nl/~elec), 11 January 2000 Electronics Group, (http://g2pc1.bu.edu/~qzpeng/gpib/manual/GpibProgTut.pdf)
  71. // [3] USBTMC-USB488 Standard, rev. 1.0, 14/04/2003
  72. // "Universal Serial Bus Test and Measurement Class, Subclass USB488 Specification (USBTMC-USB488)
  73. // --------------------------------------------------------------------------------------------------------
  74. #pragma pack(push,1)
  75. typedef struct
  76. {
  77. uint8_t operationComplete : 1;
  78. uint8_t requestControl : 1;
  79. uint8_t queryError : 1;
  80. uint8_t deviceError : 1;
  81. uint8_t executionError : 1;
  82. uint8_t commandError : 1;
  83. uint8_t userRequest : 1;
  84. uint8_t powerOn : 1;
  85. }
  86. sGPIBEventStatusRegisterBits_t; // "4 Instrument status", [2]
  87. typedef struct
  88. {
  89. uint8_t bit_0 : 1;
  90. uint8_t bit_1 : 1;
  91. uint8_t EAV : 1; // Error AVailable bit
  92. uint8_t bit_3 : 1;
  93. uint8_t MAV : 1; // Message AVailable bit
  94. uint8_t ESB : 1; // Event Summary Bit
  95. uint8_t RQS_MSS : 1; // ReQuested Service / Master Summary Status
  96. uint8_t bit_7 : 1;
  97. }
  98. sGPIBStatusByteRegisterBits_t; // "4 Instrument status", [2]; "4.3.1 READ_STATUS_BYTE", [3]
  99. typedef struct
  100. {
  101. union
  102. {
  103. sGPIBEventStatusRegisterBits_t bits;
  104. uint8_t byte;
  105. }
  106. ESR; // "ESR", "Event Status Register"
  107. union
  108. {
  109. sGPIBEventStatusRegisterBits_t bits;
  110. uint8_t byte;
  111. }
  112. ESE; // "ESE", "Event Status Enable Register"
  113. }
  114. sGPIBEventStatus_t; // "4 Instrument status", [2]
  115. typedef union
  116. {
  117. sGPIBStatusByteRegisterBits_t bits;
  118. uint8_t byte;
  119. }
  120. sGPIB_STB_t; // "STB", "Status Byte Register"
  121. typedef union
  122. {
  123. sGPIBStatusByteRegisterBits_t bits;
  124. uint8_t byte;
  125. }
  126. sGPIB_SRE_t; // "SRE", "Service Request Enable Register"
  127. typedef struct
  128. {
  129. sGPIB_STB_t STB;
  130. sGPIB_SRE_t SRE;
  131. union
  132. {
  133. bool requestService;
  134. uint32_t reserved;
  135. };
  136. }
  137. sGPIBStatusByte_t; // "4 Instrument status", [2]
  138. typedef struct
  139. {
  140. sGPIBEventStatus_t EventStatus;
  141. sGPIBStatusByte_t Status;
  142. }
  143. sGPIBRegisters_t;
  144. #pragma pack(pop)
  145. // --------------------------------------------------------------------------------------------------------
  146. STATIC_ASSERT( sizeof(xGPIBRegisters_t) == sizeof(sGPIBRegisters_t), "Invalid xGPIBRegisters_t/sGPIBRegisters_t size" );
  147. // --------------------------------------------------------------------------------------------------------
  148. static void gpib_RQS_set( xGPIBRegisters_t * _gpibr )
  149. {
  150. my_assert( _gpibr );
  151. sGPIBRegisters_t * gpibr = (sGPIBRegisters_t*)_gpibr;
  152. gpibr->Status.requestService = true;
  153. }
  154. static void gpib_RQS_reset( xGPIBRegisters_t * _gpibr )
  155. {
  156. my_assert( _gpibr );
  157. sGPIBRegisters_t * gpibr = (sGPIBRegisters_t*)_gpibr;
  158. gpibr->Status.requestService = false;
  159. }
  160. // --------------------------------------------------------------------------------------------------------
  161. static void gpib_STB_update( xGPIBRegisters_t * _gpibr )
  162. {
  163. my_assert( _gpibr );
  164. sGPIBRegisters_t * gpibr = (sGPIBRegisters_t*)_gpibr;
  165. sGPIB_STB_t MASK = { .byte = 0xff }; MASK.bits.RQS_MSS = 0;
  166. gpibr->Status.STB.bits.RQS_MSS = (gpibr->Status.SRE.byte & gpibr->Status.STB.byte & MASK.byte)?1:0;
  167. }
  168. // --------------------------------------------------------------------------------------------------------
  169. // @gpib_get_event_status_register
  170. // Returns GPIB event status register
  171. // Reference:
  172. // "4 Instrument status", [2]
  173. // "10.12 *ESR?, Standard Event Status Register Query", [4]
  174. // "11.5.1.2 Standard Event Status Register Operation", [4]
  175. // Parameters:
  176. // @_gpibr - GPIB Register structure;
  177. // @pesr - pointer to the variable to store the value of ESR (event status register) to.
  178. // Returns: none
  179. static void gpib_get_event_status_register( xGPIBRegisters_t * _gpibr, uint8_t * pesr )
  180. {
  181. my_assert( _gpibr );
  182. my_assert( pesr );
  183. sGPIBRegisters_t * gpibr = (sGPIBRegisters_t*)_gpibr;
  184. *pesr = gpibr->EventStatus.ESR.byte;
  185. // "10.12 *ESR?, Standard Event Status Register Query", [4]
  186. // "11.5.1.2 Standard Event Status Register Operation", [4]
  187. // "<...> Reading the Standard Event Status Register clears it <...>", [4]
  188. gpibr->EventStatus.ESR.byte = 0;
  189. gpibr->Status.STB.bits.ESB = ((gpibr->EventStatus.ESR.byte & gpibr->EventStatus.ESE.byte)?1:0);
  190. gpib_STB_update(_gpibr);
  191. }
  192. // --------------------------------------------------------------------------------------------------------
  193. // @gpib_set_event_status_register_power_on_state
  194. // Sets GPIB event status register status: power on
  195. // Reference:
  196. // "4 Instrument status", [2]
  197. // "11.5.1.1 Standard Event Status Register Bit Definitions", [4]
  198. // Parameters:
  199. // @_gpibr - GPIB Register structure;
  200. // @pon - value of Power On bit (PON) in ESR (event status register) to write to GPIB Register structure.
  201. // Returns: none
  202. static void gpib_set_event_status_register_power_on_state( xGPIBRegisters_t * _gpibr, bool pon )
  203. {
  204. my_assert( _gpibr );
  205. sGPIBRegisters_t * gpibr = (sGPIBRegisters_t*)_gpibr;
  206. gpibr->EventStatus.ESR.bits.powerOn = (pon)?1:0;
  207. gpibr->Status.STB.bits.ESB = ((gpibr->EventStatus.ESR.byte & gpibr->EventStatus.ESE.byte)?1:0);
  208. gpib_STB_update(_gpibr);
  209. }
  210. // --------------------------------------------------------------------------------------------------------
  211. // @gpib_set_event_status_register_user_request_state
  212. // Sets GPIB event status register status: user request
  213. // Reference:
  214. // "4 Instrument status", [2]
  215. // "11.5.1.1 Standard Event Status Register Bit Definitions", [4]
  216. // Parameters:
  217. // @_gpibr - GPIB Register structure;
  218. // @urq - value of User Request bit (URQ) in ESR (event status register) to write to GPIB Register structure.
  219. // Returns: none
  220. static void gpib_set_event_status_register_user_request_state( xGPIBRegisters_t * _gpibr, bool urq )
  221. {
  222. my_assert( _gpibr );
  223. sGPIBRegisters_t * gpibr = (sGPIBRegisters_t*)_gpibr;
  224. gpibr->EventStatus.ESR.bits.userRequest = (urq)?1:0;
  225. gpibr->Status.STB.bits.ESB = ((gpibr->EventStatus.ESR.byte & gpibr->EventStatus.ESE.byte)?1:0);
  226. gpib_STB_update(_gpibr);
  227. }
  228. // --------------------------------------------------------------------------------------------------------
  229. // @gpib_set_event_status_register_command_error_state
  230. // Sets GPIB event status register status: command error
  231. // Reference:
  232. // "4 Instrument status", [2]
  233. // "11.5.1.1 Standard Event Status Register Bit Definitions", [4]
  234. // Parameters:
  235. // @_gpibr - GPIB Register structure;
  236. // @cme - value of Command Error bit (CME) in ESR (event status register) to write to GPIB Register structure.
  237. // Returns: none
  238. static void gpib_set_event_status_register_command_error_state( xGPIBRegisters_t * _gpibr, bool cme )
  239. {
  240. my_assert( _gpibr );
  241. sGPIBRegisters_t * gpibr = (sGPIBRegisters_t*)_gpibr;
  242. gpibr->EventStatus.ESR.bits.commandError = (cme)?1:0;
  243. gpibr->Status.STB.bits.ESB = ((gpibr->EventStatus.ESR.byte & gpibr->EventStatus.ESE.byte)?1:0);
  244. gpib_STB_update(_gpibr);
  245. }
  246. // --------------------------------------------------------------------------------------------------------
  247. // @gpib_set_event_status_register_execution_error_state
  248. // Sets GPIB event status register status: execution error
  249. // Reference:
  250. // "4 Instrument status", [2]
  251. // "11.5.1.1 Standard Event Status Register Bit Definitions", [4]
  252. // Parameters:
  253. // @_gpibr - GPIB Register structure;
  254. // @e - value of Execution Error bit (E) in ESR (event status register) to write to GPIB Register structure.
  255. // Returns: none
  256. static void gpib_set_event_status_register_execution_error_state( xGPIBRegisters_t * _gpibr, bool e )
  257. {
  258. my_assert( _gpibr );
  259. sGPIBRegisters_t * gpibr = (sGPIBRegisters_t*)_gpibr;
  260. gpibr->EventStatus.ESR.bits.executionError = (e)?1:0;
  261. gpibr->Status.STB.bits.ESB = ((gpibr->EventStatus.ESR.byte & gpibr->EventStatus.ESE.byte)?1:0);
  262. gpib_STB_update(_gpibr);
  263. }
  264. // --------------------------------------------------------------------------------------------------------
  265. // @gpib_set_event_status_register_device_specific_error_state
  266. // Sets GPIB event status register status: device specific error
  267. // Reference:
  268. // "4 Instrument status", [2]
  269. // "11.5.1.1 Standard Event Status Register Bit Definitions", [4]
  270. // Parameters:
  271. // @_gpibr - GPIB Register structure;
  272. // @dde - value of Device Specific Error bit (DDE) in ESR (event status register) to write to GPIB Register structure.
  273. // Returns: none
  274. static void gpib_set_event_status_register_device_specific_error_state( xGPIBRegisters_t * _gpibr, bool dde )
  275. {
  276. my_assert( _gpibr );
  277. sGPIBRegisters_t * gpibr = (sGPIBRegisters_t*)_gpibr;
  278. gpibr->EventStatus.ESR.bits.deviceError = (dde)?1:0;
  279. gpibr->Status.STB.bits.ESB = ((gpibr->EventStatus.ESR.byte & gpibr->EventStatus.ESE.byte)?1:0);
  280. gpib_STB_update(_gpibr);
  281. }
  282. // --------------------------------------------------------------------------------------------------------
  283. // @gpib_set_event_status_register_query_error_state
  284. // Sets GPIB event status register status: query error
  285. // Reference:
  286. // "4 Instrument status", [2]
  287. // "11.5.1.1 Standard Event Status Register Bit Definitions", [4]
  288. // Parameters:
  289. // @_gpibr - GPIB Register structure;
  290. // @qye - value of Device Specific Error bit (QYE) in ESR (event status register) to write to GPIB Register structure.
  291. // Returns: none
  292. static void gpib_set_event_status_register_query_error_state( xGPIBRegisters_t * _gpibr, bool qye )
  293. {
  294. my_assert( _gpibr );
  295. sGPIBRegisters_t * gpibr = (sGPIBRegisters_t*)_gpibr;
  296. gpibr->EventStatus.ESR.bits.queryError = (qye)?1:0;
  297. gpibr->Status.STB.bits.ESB = ((gpibr->EventStatus.ESR.byte & gpibr->EventStatus.ESE.byte)?1:0);
  298. gpib_STB_update(_gpibr);
  299. }
  300. // --------------------------------------------------------------------------------------------------------
  301. // @gpib_set_event_status_register_request_control_state
  302. // Sets GPIB event status register status: request control
  303. // Reference:
  304. // "4 Instrument status", [2]
  305. // "11.5.1.1 Standard Event Status Register Bit Definitions", [4]
  306. // Parameters:
  307. // @_gpibr - GPIB Register structure;
  308. // @rqc - value of Request Control bit (RQC) in ESR (event status register) to write to GPIB Register structure.
  309. // Returns: none
  310. static void gpib_set_event_status_register_request_control_state( xGPIBRegisters_t * _gpibr, bool rqc )
  311. {
  312. my_assert( _gpibr );
  313. sGPIBRegisters_t * gpibr = (sGPIBRegisters_t*)_gpibr;
  314. gpibr->EventStatus.ESR.bits.requestControl = (rqc)?1:0;
  315. gpibr->Status.STB.bits.ESB = ((gpibr->EventStatus.ESR.byte & gpibr->EventStatus.ESE.byte)?1:0);
  316. gpib_STB_update(_gpibr);
  317. }
  318. // --------------------------------------------------------------------------------------------------------
  319. // @gpib_set_event_status_register_operation_complete_state
  320. // Sets GPIB event status register status: operation complete
  321. // Reference:
  322. // "4 Instrument status", [2]
  323. // "11.5.1.1 Standard Event Status Register Bit Definitions", [4]
  324. // Parameters:
  325. // @_gpibr - GPIB Register structure;
  326. // @opc - value of Operation Complete bit (RQC) in ESR (event status register) to write to GPIB Register structure.
  327. // Returns: none
  328. static void gpib_set_event_status_register_operation_complete_state( xGPIBRegisters_t * _gpibr, bool opc )
  329. {
  330. my_assert( _gpibr );
  331. sGPIBRegisters_t * gpibr = (sGPIBRegisters_t*)_gpibr;
  332. gpibr->EventStatus.ESR.bits.operationComplete = (opc)?1:0;
  333. gpibr->Status.STB.bits.ESB = ((gpibr->EventStatus.ESR.byte & gpibr->EventStatus.ESE.byte)?1:0);
  334. gpib_STB_update(_gpibr);
  335. }
  336. // --------------------------------------------------------------------------------------------------------
  337. // @gpib_get_event_status_enable_register
  338. // Returns GPIB event status enable register
  339. // Reference:
  340. // "4 Instrument status", [2]
  341. // Parameters:
  342. // @_gpibr - GPIB Register structure;
  343. // @pesr - pointer to the variable to store the value of ESE (event status enable register) to.
  344. // Returns: none
  345. static void gpib_get_event_status_enable_register( xGPIBRegisters_t * _gpibr, uint8_t * pese )
  346. {
  347. my_assert( _gpibr );
  348. my_assert( pese );
  349. sGPIBRegisters_t * gpibr = (sGPIBRegisters_t*)_gpibr;
  350. *pese = gpibr->EventStatus.ESE.byte;
  351. }
  352. // --------------------------------------------------------------------------------------------------------
  353. // @gpib_set_event_status_enable_register
  354. // Sets GPIB event status enable register
  355. // Reference:
  356. // "4 Instrument status", [2]
  357. // Parameters:
  358. // @_gpibr - GPIB Register structure;
  359. // @ese - value of ESE (event status enable register) to write to GPIB Register structure.
  360. // Returns: none
  361. static void gpib_set_event_status_enable_register( xGPIBRegisters_t * _gpibr, uint8_t ese )
  362. {
  363. my_assert( _gpibr );
  364. sGPIBRegisters_t * gpibr = (sGPIBRegisters_t*)_gpibr;
  365. gpibr->EventStatus.ESE.byte = ese;
  366. gpibr->Status.STB.bits.ESB = ((gpibr->EventStatus.ESR.byte & gpibr->EventStatus.ESE.byte)?1:0);
  367. gpib_STB_update(_gpibr);
  368. }
  369. // --------------------------------------------------------------------------------------------------------
  370. // @gpib_get_event_summary_bit
  371. // Return GPIB event summary bit
  372. // Reference:
  373. // "4.1 Status Byte registers (STB and SRE)", "Event Summary Bit", [2]
  374. // "11.2.2.3 Master Summary Status", [4]
  375. // "11.3.2.4 Clearing the Service Request Enable Register", [4]
  376. // Parameters:
  377. // @_gpibr - GPIB Register structure;
  378. // @pesb - pointer to the variable to store the value of ESB (event summary bit) to.
  379. // Note: the value of the bit will be set to the corresponding bit position, all the rest bits are reset to zero.
  380. // Returns: none
  381. static void gpib_get_event_summary_bit( xGPIBRegisters_t * _gpibr, uint8_t * pesb )
  382. {
  383. my_assert( _gpibr );
  384. my_assert( pesb );
  385. sGPIBRegisters_t * gpibr = (sGPIBRegisters_t*)_gpibr;
  386. sGPIB_STB_t MASK = { .byte = 0 }; MASK.bits.ESB = 1;
  387. *pesb = gpibr->Status.STB.byte & MASK.byte;
  388. }
  389. // --------------------------------------------------------------------------------------------------------
  390. // @gpib_set_event_summary_enable_state
  391. // Set GPIB event summary enable bit in Service Request Enable Register (SRE)
  392. // Reference:
  393. // "4 Instrument status", [2]
  394. // "4.1 Status Byte registers (STB and SRE)", [2]
  395. // Parameters:
  396. // @_gpibr - GPIB Register structure;
  397. // @esb - the event summary indictor enable to set to GPIB Register structure.
  398. // Returns: none
  399. static void gpib_set_event_summary_enable_state( xGPIBRegisters_t * _gpibr, bool esb )
  400. {
  401. my_assert( _gpibr );
  402. sGPIBRegisters_t * gpibr = (sGPIBRegisters_t*)_gpibr;
  403. gpibr->Status.SRE.bits.ESB = (esb)?1:0;
  404. gpib_STB_update(_gpibr);
  405. }
  406. // --------------------------------------------------------------------------------------------------------
  407. // @gpib_set_message_available_bit
  408. // Return GPIB message available bit
  409. // Reference:
  410. // "4 Instrument status", [2]
  411. // "4.1 Status Byte registers (STB and SRE)", [2]
  412. // "11.2.2.3 Master Summary Status", [4]
  413. // "11.3.2.4 Clearing the Service Request Enable Register", [4]
  414. // Parameters:
  415. // @_gpibr - GPIB Register structure;
  416. // @mav - the message available indictor to set to GPIB Register structure.
  417. // Returns: none
  418. static void gpib_set_message_available_bit( xGPIBRegisters_t * _gpibr, bool mav )
  419. {
  420. my_assert( _gpibr );
  421. sGPIBRegisters_t * gpibr = (sGPIBRegisters_t*)_gpibr;
  422. gpibr->Status.STB.bits.MAV = (mav)?1:0;
  423. gpib_STB_update(_gpibr);
  424. }
  425. // --------------------------------------------------------------------------------------------------------
  426. // @gpib_set_message_available_enable_state
  427. // Set GPIB message available enable bit in Service Request Enable Register (SRE)
  428. // Reference:
  429. // "4 Instrument status", [2]
  430. // "4.1 Status Byte registers (STB and SRE)", [2]
  431. // Parameters:
  432. // @_gpibr - GPIB Register structure;
  433. // @mav - the message available indictor enable to set to GPIB Register structure.
  434. // Returns: none
  435. static void gpib_set_message_available_enable_state( xGPIBRegisters_t * _gpibr, bool mav )
  436. {
  437. my_assert( _gpibr );
  438. sGPIBRegisters_t * gpibr = (sGPIBRegisters_t*)_gpibr;
  439. gpibr->Status.SRE.bits.MAV = (mav)?1:0;
  440. gpib_STB_update(_gpibr);
  441. }
  442. // --------------------------------------------------------------------------------------------------------
  443. // @gpib_get_message_available_bit
  444. // Set GPIB message available bit
  445. // Reference:
  446. // "4 Instrument status", [2]
  447. // "4.1 Status Byte registers (STB and SRE)", [2]
  448. // "11.2.2.3 Master Summary Status", [4]
  449. // "11.3.2.4 Clearing the Service Request Enable Register", [4]
  450. // Parameters:
  451. // @_gpibr - GPIB Register structure;
  452. // @pmav - pointer to the variable to store the value of MAV (message available bit) to.
  453. // Note: the value of the bit will be set to the corresponding bit position, all the rest bits are reset to zero.
  454. // Returns: none
  455. static void gpib_get_message_available_bit( xGPIBRegisters_t * _gpibr, uint8_t * pmav )
  456. {
  457. my_assert( _gpibr );
  458. my_assert( pmav );
  459. sGPIBRegisters_t * gpibr = (sGPIBRegisters_t*)_gpibr;
  460. sGPIB_STB_t MASK = { .byte = 0 }; MASK.bits.MAV = 1;
  461. *pmav = gpibr->Status.STB.byte & MASK.byte;
  462. }
  463. // --------------------------------------------------------------------------------------------------------
  464. // @gpib_set_error_available_bit
  465. // Set GPIB error available bit
  466. // Reference:
  467. // "4 Instrument status", [2]
  468. // "4.1 Status Byte registers (STB and SRE)", [2]
  469. // "11.2.2.3 Master Summary Status", [4]
  470. // "11.3.2.4 Clearing the Service Request Enable Register", [4]
  471. // Parameters:
  472. // @_gpibr - GPIB Register structure;
  473. // @eav - the error available indictor to set to GPIB Register structure.
  474. // Returns: none
  475. static void gpib_set_error_available_bit( xGPIBRegisters_t * _gpibr, bool eav )
  476. {
  477. my_assert( _gpibr );
  478. sGPIBRegisters_t * gpibr = (sGPIBRegisters_t*)_gpibr;
  479. gpibr->Status.STB.bits.EAV = (eav)?1:0;
  480. gpib_STB_update(_gpibr);
  481. }
  482. // --------------------------------------------------------------------------------------------------------
  483. // @gpib_set_error_available_enable_state
  484. // Set GPIB error available enable bit in Service Request Enable Register (SRE)
  485. // Reference:
  486. // "4 Instrument status", [2]
  487. // "4.1 Status Byte registers (STB and SRE)", [2]
  488. // Parameters:
  489. // @_gpibr - GPIB Register structure;
  490. // @eav - the error available indictor enable to set to GPIB Register structure.
  491. // Returns: none
  492. static void gpib_set_error_available_enable_state( xGPIBRegisters_t * _gpibr, bool eav )
  493. {
  494. my_assert( _gpibr );
  495. sGPIBRegisters_t * gpibr = (sGPIBRegisters_t*)_gpibr;
  496. gpibr->Status.SRE.bits.EAV = (eav)?1:0;
  497. gpib_STB_update(_gpibr);
  498. }
  499. // --------------------------------------------------------------------------------------------------------
  500. // @gpib_get_error_available_bit
  501. // Return GPIB error available bit
  502. // Reference:
  503. // "4 Instrument status", [2]
  504. // "4.1 Status Byte registers (STB and SRE)", [2]
  505. // "11.2.2.3 Master Summary Status", [4]
  506. // "11.3.2.4 Clearing the Service Request Enable Register", [4]
  507. // Parameters:
  508. // @_gpibr - GPIB Register structure;
  509. // @peav - pointer to the variable to store the value of EAV (error available bit) to.
  510. // Note: the value of the bit will be set to the corresponding bit position, all the rest bits are reset to zero.
  511. // Returns: none
  512. static void gpib_get_error_available_bit( xGPIBRegisters_t * _gpibr, uint8_t * peav )
  513. {
  514. my_assert( _gpibr );
  515. my_assert( peav );
  516. sGPIBRegisters_t * gpibr = (sGPIBRegisters_t*)_gpibr;
  517. sGPIB_STB_t MASK = { .byte = 0 }; MASK.bits.EAV = 1;
  518. *peav = gpibr->Status.STB.byte & MASK.byte;
  519. }
  520. // --------------------------------------------------------------------------------------------------------
  521. // @gpib_get_status_byte_serial_poll
  522. // Return GPIB Status Byte during Serial Poll procedure.
  523. // Reference:
  524. // "4 Instrument status", [2]
  525. // "4.1 Status Byte registers (STB and SRE)", [2]
  526. // "3.4.1 Interrupt-IN DATA sent due to an SRQ condition", [3]
  527. // "3.4.2 Interrupt-IN DATA sent due to READ_STATUS_BYTE request", [3]
  528. // "11.2.2 Reading the Status Byte Register", [4]
  529. // "11.2.2.3 Master Summary Status", [4]
  530. // "11.3.2.4 Clearing the Service Request Enable Register", [4]
  531. // Parameters:
  532. // @_gpibr - GPIB Register structure;
  533. // @pstb - pointer to the variable to store the value of STB (status byte) to.
  534. // Returns: none
  535. static void gpib_get_status_byte_serial_poll( xGPIBRegisters_t * _gpibr, uint8_t * pstb )
  536. {
  537. my_assert( _gpibr );
  538. my_assert( pstb );
  539. sGPIBRegisters_t * gpibr = (sGPIBRegisters_t*)_gpibr;
  540. sGPIB_STB_t MASK = { .byte = 0x00 }; MASK.bits.RQS_MSS = (gpibr->Status.requestService)?1:0;
  541. *pstb = gpibr->Status.STB.byte | MASK.byte;
  542. gpib_RQS_reset(_gpibr); // "11.2.2.1 Reading with a Serial Poll", [4]
  543. }
  544. // --------------------------------------------------------------------------------------------------------
  545. // @gpib_get_status_byte_normal_poll
  546. // Return GPIB Status Byte during *STB? procedure.
  547. // Reference:
  548. // "4 Instrument status", [2]
  549. // "4.1 Status Byte registers (STB and SRE)", [2]
  550. // "3.4.1 Interrupt-IN DATA sent due to an SRQ condition", [3]
  551. // "3.4.2 Interrupt-IN DATA sent due to READ_STATUS_BYTE request", [3]
  552. // "11.2.2 Reading the Status Byte Register", [4]
  553. // "11.2.2.3 Master Summary Status", [4]
  554. // "11.3.2.4 Clearing the Service Request Enable Register", [4]
  555. // Parameters:
  556. // @_gpibr - GPIB Register structure;
  557. // @pstb - pointer to the variable to store the value of STB (status byte) to.
  558. // Returns: none
  559. static void gpib_get_status_byte_normal_poll( xGPIBRegisters_t * _gpibr, uint8_t * pstb )
  560. {
  561. my_assert( _gpibr );
  562. my_assert( pstb );
  563. sGPIBRegisters_t * gpibr = (sGPIBRegisters_t*)_gpibr;
  564. sGPIB_STB_t MASK = { .byte = 0x00 }; MASK.bits.RQS_MSS = (gpibr->Status.requestService)?1:0;
  565. *pstb = gpibr->Status.STB.byte | MASK.byte;
  566. }
  567. // --------------------------------------------------------------------------------------------------------
  568. // @gpib_clr_status_byte
  569. // Clears GPIB Status Byte
  570. // Reference:
  571. // "4 Instrument status", [2]
  572. // "4.1 Status Byte registers (STB and SRE)", [2]
  573. // "11.2.4 Clearing the Status Byte Register"
  574. // Parameters:
  575. // @_gpibr - GPIB Register structure;
  576. // Returns: none
  577. void gpib_clr_status_byte( xGPIBRegisters_t * _gpibr )
  578. {
  579. my_assert( _gpibr );
  580. sGPIBRegisters_t * gpibr = (sGPIBRegisters_t*)_gpibr;
  581. gpibr->Status.STB.bits.bit_0 = 0;
  582. gpibr->Status.STB.bits.bit_1 = 0;
  583. gpibr->Status.STB.bits.bit_3 = 0;
  584. gpibr->Status.STB.bits.bit_7 = 0;
  585. gpibr->Status.STB.bits.EAV = 0;
  586. gpibr->Status.STB.bits.ESB = 0;
  587. sGPIB_STB_t MASK = { .byte = 0xff }; MASK.bits.RQS_MSS = 0;
  588. gpibr->Status.STB.bits.RQS_MSS = (gpibr->Status.SRE.byte & gpibr->Status.STB.byte & MASK.byte)?1:0;
  589. }
  590. // --------------------------------------------------------------------------------------------------------
  591. // @gpib_get_service_request_enable_register
  592. // Return GPIB Service Request Enable Register
  593. // Reference:
  594. // "4 Instrument status", [2]
  595. // "4.1 Status Byte registers (STB and SRE)", [2]
  596. // "11.2.2.3 Master Summary Status", [4]
  597. // "11.3.2.4 Clearing the Service Request Enable Register", [4]
  598. // Parameters:
  599. // @_gpibr - GPIB Register structure;
  600. // @psre - pointer to the variable to store the value of SRE (Service Request Enable Register) to.
  601. // Returns: none
  602. static void gpib_get_service_request_enable_register( xGPIBRegisters_t * _gpibr, uint8_t * psre )
  603. {
  604. my_assert( _gpibr );
  605. my_assert( psre );
  606. sGPIBRegisters_t * gpibr = (sGPIBRegisters_t*)_gpibr;
  607. sGPIB_SRE_t MASK = { .byte = 0xff }; MASK.bits.RQS_MSS = 0;
  608. *psre = (gpibr->Status.SRE.byte) & (MASK.byte);
  609. }
  610. // --------------------------------------------------------------------------------------------------------
  611. // @gpib_set_service_request_enable_register
  612. // Set GPIB Service Request Enable Register
  613. // Reference:
  614. // "4 Instrument status", [2]
  615. // "4.1 Status Byte registers (STB and SRE)", [2]
  616. // "11.2.2.3 Master Summary Status", [4]
  617. // "11.3.2.4 Clearing the Service Request Enable Register", [4]
  618. // Parameters:
  619. // @_gpibr - GPIB Register structure;
  620. // @sre - value of SRE (Service Request Enable Register) to write to GPIB Register structure.
  621. // Returns: none
  622. static void gpib_set_service_request_enable_register( xGPIBRegisters_t * _gpibr, uint8_t sre )
  623. {
  624. my_assert( _gpibr );
  625. sGPIBRegisters_t * gpibr = (sGPIBRegisters_t*)_gpibr;
  626. {
  627. sGPIB_SRE_t MASK = { .byte = 0 }; MASK.bits.RQS_MSS = 0;
  628. gpibr->Status.SRE.byte = (sre) & (MASK.byte);
  629. }
  630. gpib_STB_update(_gpibr);
  631. }
  632. // --------------------------------------------------------------------------------------------------------
  633. // @gpib_get_service_request_status
  634. // Return GPIB Service Request indicator (Service Request Generation, SRQ)
  635. // Reference:
  636. // "4 Instrument status", [2]
  637. // "4.1 Status Byte registers (STB and SRE)", [2]
  638. // "11.2.2.3 Master Summary Status", [4]
  639. // "11.3.2.4 Clearing the Service Request Enable Register", [4]
  640. // Parameters:
  641. // @_gpibr - GPIB Register structure;
  642. // @psrq - pointer to the variable to store the state of SRQ indicator (Service ReQuest) to.
  643. // Returns: none
  644. static void gpib_get_service_request_status( xGPIBRegisters_t * _gpibr, bool * psrq )
  645. {
  646. my_assert( _gpibr );
  647. my_assert( psrq );
  648. sGPIBRegisters_t * gpibr = (sGPIBRegisters_t*)_gpibr;
  649. *psrq = gpibr->Status.requestService;
  650. }
  651. // --------------------------------------------------------------------------------------------------------
  652. // @gpib_set_service_request_status
  653. // Writes GPIB Service Request indicator (Service Request Generation, SRQ)
  654. // Reference:
  655. // "4 Instrument status", [2]
  656. // "4.1 Status Byte registers (STB and SRE)", [2]
  657. // "11.2.2.3 Master Summary Status", [4]
  658. // "11.3.2.4 Clearing the Service Request Enable Register", [4]
  659. // Parameters:
  660. // @_gpibr - GPIB Register structure;
  661. // @srq - SRQ indicator value (Service ReQuest) to write
  662. // Returns: none
  663. static void gpib_set_service_request_status( xGPIBRegisters_t * _gpibr, bool srq )
  664. {
  665. my_assert( _gpibr );
  666. if( srq )
  667. gpib_RQS_set( _gpibr );
  668. else
  669. gpib_RQS_reset( _gpibr );
  670. }