gpib_cmd.h 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. #ifndef _GPIB_CMD_H
  3. #define _GPIB_CMD_H
  4. #include <linux/types.h>
  5. /* Command byte definitions tests and functions */
  6. /* mask of bits that actually matter in a command byte */
  7. enum {
  8. gpib_command_mask = 0x7f,
  9. };
  10. /* Possible GPIB command messages */
  11. enum cmd_byte {
  12. GTL = 0x1, /* go to local */
  13. SDC = 0x4, /* selected device clear */
  14. PP_CONFIG = 0x5,
  15. GET = 0x8, /* group execute trigger */
  16. TCT = 0x9, /* take control */
  17. LLO = 0x11, /* local lockout */
  18. DCL = 0x14, /* device clear */
  19. PPU = 0x15, /* parallel poll unconfigure */
  20. SPE = 0x18, /* serial poll enable */
  21. SPD = 0x19, /* serial poll disable */
  22. CFE = 0x1f, /* configure enable */
  23. LAD = 0x20, /* value to be 'ored' in to obtain listen address */
  24. UNL = 0x3F, /* unlisten */
  25. TAD = 0x40, /* value to be 'ored' in to obtain talk address */
  26. UNT = 0x5F, /* untalk */
  27. SAD = 0x60, /* my secondary address (base) */
  28. PPE = 0x60, /* parallel poll enable (base) */
  29. PPD = 0x70 /* parallel poll disable */
  30. };
  31. /* confine address to range 0 to 30. */
  32. static inline unsigned int gpib_address_restrict(u32 addr)
  33. {
  34. addr &= 0x1f;
  35. if (addr == 0x1f)
  36. addr = 0;
  37. return addr;
  38. }
  39. static inline u8 MLA(u32 addr)
  40. {
  41. return gpib_address_restrict(addr) | LAD;
  42. }
  43. static inline u8 MTA(u32 addr)
  44. {
  45. return gpib_address_restrict(addr) | TAD;
  46. }
  47. static inline u8 MSA(u32 addr)
  48. {
  49. return (addr & 0x1f) | SAD;
  50. }
  51. static inline s32 gpib_address_equal(u32 pad1, s32 sad1, u32 pad2, s32 sad2)
  52. {
  53. if (pad1 == pad2) {
  54. if (sad1 == sad2)
  55. return 1;
  56. if (sad1 < 0 && sad2 < 0)
  57. return 1;
  58. }
  59. return 0;
  60. }
  61. static inline s32 is_PPE(u8 command)
  62. {
  63. return (command & 0x70) == 0x60;
  64. }
  65. static inline s32 is_PPD(u8 command)
  66. {
  67. return (command & 0x70) == 0x70;
  68. }
  69. static inline s32 in_addressed_command_group(u8 command)
  70. {
  71. return (command & 0x70) == 0x0;
  72. }
  73. static inline s32 in_universal_command_group(u8 command)
  74. {
  75. return (command & 0x70) == 0x10;
  76. }
  77. static inline s32 in_listen_address_group(u8 command)
  78. {
  79. return (command & 0x60) == 0x20;
  80. }
  81. static inline s32 in_talk_address_group(u8 command)
  82. {
  83. return (command & 0x60) == 0x40;
  84. }
  85. static inline s32 in_primary_command_group(u8 command)
  86. {
  87. return in_addressed_command_group(command) ||
  88. in_universal_command_group(command) ||
  89. in_listen_address_group(command) ||
  90. in_talk_address_group(command);
  91. }
  92. #endif /* _GPIB_CMD_H */