cdc_acm_protocol.h 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  1. /*
  2. * cdc_acm_protocol.h
  3. *
  4. * Greaseweazle protocol over CDC ACM streams.
  5. *
  6. * Written & released by Keir Fraser <keir.xen@gmail.com>
  7. *
  8. * This is free and unencumbered software released into the public domain.
  9. * See the file COPYING for more details, or visit <http://unlicense.org>.
  10. */
  11. /*
  12. * GREASEWEAZLE COMMAND SET
  13. *
  14. * NOTE: Commands cannot be pipelined. Do not issue a new command until the
  15. * previous command is completed with all expected bytes received by the host.
  16. */
  17. /* CMD_GET_INFO, length=3, idx. Returns 32 bytes after ACK. */
  18. #define CMD_GET_INFO 0
  19. /* [BOOTLOADER] CMD_UPDATE, length=6, <update_len>.
  20. * Host follows after a successful ACK response with <update_len> bytes.
  21. * Bootloader finally returns a status byte, 0 on success. */
  22. /* [MAIN FIRMWARE] CMD_UPDATE, length=10, <update_len>, 0xdeafbee3.
  23. * Host follows after a successful ACK response with <update_len> bytes.
  24. * Main firmware finally returns a status byte, 0 on success. */
  25. #define CMD_UPDATE 1
  26. /* CMD_SEEK, length=3, cyl#. Seek to cyl# on selected drive. */
  27. #define CMD_SEEK 2
  28. /* CMD_HEAD, length=3, head# (0=bottom) */
  29. #define CMD_HEAD 3
  30. /* CMD_SET_PARAMS, length=3+nr, idx, <nr bytes> */
  31. #define CMD_SET_PARAMS 4
  32. /* CMD_GET_PARAMS, length=4, idx, nr_bytes. Returns nr_bytes after ACK. */
  33. #define CMD_GET_PARAMS 5
  34. /* CMD_MOTOR, length=4, drive#, on/off. Turn on/off a drive motor. */
  35. #define CMD_MOTOR 6
  36. /* CMD_READ_FLUX, length=8-12. Argument is gw_read_flux; optional fields
  37. * may be omitted. Returns flux readings terminating with EOStream (NUL). */
  38. #define CMD_READ_FLUX 7
  39. /* CMD_WRITE_FLUX, length=4. Argument is gw_write_flux.
  40. * Host follows the ACK with flux values terminating with EOStream (NUL).
  41. * Device finally returns a status byte, 0 on success. */
  42. #define CMD_WRITE_FLUX 8
  43. /* CMD_GET_FLUX_STATUS, length=2. Last read/write status returned in ACK. */
  44. #define CMD_GET_FLUX_STATUS 9
  45. /* CMD_SWITCH_FW_MODE, length=3, <mode>. No response on success: The device
  46. * resets into the requested mode, and the USB connection also resets. */
  47. #define CMD_SWITCH_FW_MODE 11
  48. /* CMD_SELECT, length=3, drive#. Select drive# as current unit. */
  49. #define CMD_SELECT 12
  50. /* CMD_DESELECT, length=2. Deselect current unit (if any). */
  51. #define CMD_DESELECT 13
  52. /* CMD_SET_BUS_TYPE, length=3, bus_type. Set the bus type. */
  53. #define CMD_SET_BUS_TYPE 14
  54. /* CMD_SET_PIN, length=4, pin#, level. */
  55. #define CMD_SET_PIN 15
  56. /* CMD_RESET, length=2. Reset all state to initial (power on) values. */
  57. #define CMD_RESET 16
  58. /* CMD_ERASE_FLUX, length=6. Argument is gw_erase_flux. */
  59. #define CMD_ERASE_FLUX 17
  60. /* CMD_SOURCE_BYTES, length=6. Argument is gw_sink_source_bytes. */
  61. #define CMD_SOURCE_BYTES 18
  62. /* CMD_SINK_BYTES, length=6. Argument is gw_sink_source_bytes. */
  63. #define CMD_SINK_BYTES 19
  64. #define CMD_MAX 19
  65. /*
  66. * CMD_SET_BUS CODES
  67. */
  68. #define BUS_NONE 0
  69. #define BUS_IBMPC 1
  70. #define BUS_SHUGART 2
  71. /*
  72. * ACK RETURN CODES
  73. */
  74. #define ACK_OKAY 0
  75. #define ACK_BAD_COMMAND 1
  76. #define ACK_NO_INDEX 2
  77. #define ACK_NO_TRK0 3
  78. #define ACK_FLUX_OVERFLOW 4
  79. #define ACK_FLUX_UNDERFLOW 5
  80. #define ACK_WRPROT 6
  81. #define ACK_NO_UNIT 7
  82. #define ACK_NO_BUS 8
  83. #define ACK_BAD_UNIT 9
  84. #define ACK_BAD_PIN 10
  85. #define ACK_BAD_CYLINDER 11
  86. /*
  87. * CONTROL-CHANNEL COMMAND SET:
  88. * We abuse SET_LINE_CODING requests over endpoint 0, stashing a command
  89. * in the baud-rate field.
  90. */
  91. #define BAUD_NORMAL 9600
  92. #define BAUD_CLEAR_COMMS 10000
  93. /*
  94. * Flux stream opcodes. Preceded by 0xFF byte.
  95. *
  96. * Argument types:
  97. * N28: 28-bit non-negative integer N, encoded as 4 bytes b0,b1,b2,b3:
  98. * b0 = (uint8_t)(1 | (N << 1))
  99. * b1 = (uint8_t)(1 | (N >> 6))
  100. * b2 = (uint8_t)(1 | (N >> 13))
  101. * b3 = (uint8_t)(1 | (N >> 20))
  102. */
  103. /* FLUXOP_INDEX [CMD_READ_FLUX]
  104. * Args:
  105. * +4 [N28]: ticks to index, relative to sample cursor.
  106. * Signals an index pulse in the read stream. Sample cursor is unaffected. */
  107. #define FLUXOP_INDEX 1
  108. /* FLUXOP_SPACE [CMD_READ_FLUX, CMD_WRITE_FLUX]
  109. * Args:
  110. * +4 [N28]: ticks to increment the sample cursor.
  111. * Increments the sample cursor with no intervening flux transitions. */
  112. #define FLUXOP_SPACE 2
  113. /* FLUXOP_ASTABLE [CMD_WRITE_FLUX]
  114. * Args:
  115. * +4 [N28]: astable period.
  116. * Generate regular flux transitions at specified astable period.
  117. * Duration is specified by immediately preceding FLUXOP_SPACE opcode(s). */
  118. #define FLUXOP_ASTABLE 3
  119. /*
  120. * COMMAND PACKETS
  121. */
  122. /* CMD_GET_INFO, index 0 */
  123. #define GETINFO_FIRMWARE 0
  124. struct packed gw_info {
  125. uint8_t fw_major;
  126. uint8_t fw_minor;
  127. uint8_t is_main_firmware; /* == 0 -> update bootloader */
  128. uint8_t max_cmd;
  129. uint32_t sample_freq;
  130. uint8_t hw_model, hw_submodel;
  131. uint8_t usb_speed;
  132. };
  133. extern struct gw_info gw_info;
  134. /* CMD_GET_INFO, index 1 */
  135. #define GETINFO_BW_STATS 1
  136. struct packed gw_bw_stats {
  137. struct packed {
  138. uint32_t bytes;
  139. uint32_t usecs;
  140. } min_bw, max_bw;
  141. };
  142. /* CMD_READ_FLUX */
  143. struct packed gw_read_flux {
  144. /** MANDATORY FIELDS: **/
  145. /* Maximum ticks to read for (or 0, for no limit). */
  146. uint32_t ticks;
  147. /* Maximum index pulses to read (or 0, for no limit). */
  148. uint16_t max_index;
  149. /** OPTIONAL FIELDS: **/
  150. /* Linger time, in ticks, to continue reading after @max_index pulses. */
  151. uint32_t max_index_linger; /* default: 500 microseconds */
  152. };
  153. /* CMD_WRITE_FLUX */
  154. struct packed gw_write_flux {
  155. /* If non-zero, start the write at the index pulse. */
  156. uint8_t cue_at_index;
  157. /* If non-zero, terminate the write at the next index pulse. */
  158. uint8_t terminate_at_index;
  159. };
  160. /* CMD_ERASE_FLUX */
  161. struct packed gw_erase_flux {
  162. uint32_t ticks;
  163. };
  164. /* CMD_SINK_SOURCE_BYTES */
  165. struct packed gw_sink_source_bytes {
  166. uint32_t nr_bytes;
  167. };
  168. /* CMD_{GET,SET}_PARAMS, index 0 */
  169. #define PARAMS_DELAYS 0
  170. struct packed gw_delay {
  171. uint16_t select_delay; /* usec */
  172. uint16_t step_delay; /* usec */
  173. uint16_t seek_settle; /* msec */
  174. uint16_t motor_delay; /* msec */
  175. uint16_t watchdog; /* msec */
  176. };
  177. /* CMD_SWITCH_FW_MODE */
  178. #define FW_MODE_BOOTLOADER 0
  179. #define FW_MODE_NORMAL 1
  180. /*
  181. * Local variables:
  182. * mode: C
  183. * c-file-style: "Linux"
  184. * c-basic-offset: 4
  185. * tab-width: 4
  186. * indent-tabs-mode: nil
  187. * End:
  188. */