cdc_acm_protocol.h 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  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. * No further commands should be issued until the status byte is received. */
  43. #define CMD_WRITE_FLUX 8
  44. /* CMD_GET_FLUX_STATUS, length=2. Last read/write status returned in ACK. */
  45. #define CMD_GET_FLUX_STATUS 9
  46. /* CMD_SWITCH_FW_MODE, length=3, <mode>. No response on success: The device
  47. * resets into the requested mode, and the USB connection also resets. */
  48. #define CMD_SWITCH_FW_MODE 11
  49. /* CMD_SELECT, length=3, drive#. Select drive# as current unit. */
  50. #define CMD_SELECT 12
  51. /* CMD_DESELECT, length=2. Deselect current unit (if any). */
  52. #define CMD_DESELECT 13
  53. /* CMD_SET_BUS_TYPE, length=3, bus_type. Set the bus type. */
  54. #define CMD_SET_BUS_TYPE 14
  55. /* CMD_SET_PIN, length=4, pin#, level. */
  56. #define CMD_SET_PIN 15
  57. /* CMD_RESET, length=2. Reset all state to initial (power on) values. */
  58. #define CMD_RESET 16
  59. /* CMD_ERASE_FLUX, length=6. Argument is gw_erase_flux.
  60. * Device returns a status byte when erasure is completed, 0 on success.
  61. * No further commands should be issued until the status byte is received. */
  62. #define CMD_ERASE_FLUX 17
  63. /* CMD_SOURCE_BYTES, length=6. Argument is gw_sink_source_bytes. */
  64. #define CMD_SOURCE_BYTES 18
  65. /* CMD_SINK_BYTES, length=6. Argument is gw_sink_source_bytes. */
  66. #define CMD_SINK_BYTES 19
  67. /* CMD_GET_PIN, length=3, pin#. Successful ACK is followed by pin-level byte
  68. * (1=High, 0=Low). Unsupported pin returns ACK_BAD_PIN and no pin level. */
  69. #define CMD_GET_PIN 20
  70. /* CMD_TEST_MODE, length=10, 0x6e504b4e, 0x382910d3
  71. * Responds ACK_OKAY and then switches to board test mode until reset. */
  72. #define CMD_TEST_MODE 21
  73. /* CMD_NOCLICK_STEP, length=2
  74. * Steps outward from cylinder 0. This is expected to be ignored by the drive,
  75. * but will reset the Disk Change signal if a disk has been inserted.
  76. * On successful return the drive is always at cylinder 0. */
  77. #define CMD_NOCLICK_STEP 22
  78. #define CMD_MAX 22
  79. /*
  80. * CMD_SET_BUS CODES
  81. */
  82. #define BUS_NONE 0
  83. #define BUS_IBMPC 1
  84. #define BUS_SHUGART 2
  85. /*
  86. * ACK RETURN CODES
  87. */
  88. #define ACK_OKAY 0
  89. #define ACK_BAD_COMMAND 1
  90. #define ACK_NO_INDEX 2
  91. #define ACK_NO_TRK0 3
  92. #define ACK_FLUX_OVERFLOW 4
  93. #define ACK_FLUX_UNDERFLOW 5
  94. #define ACK_WRPROT 6
  95. #define ACK_NO_UNIT 7
  96. #define ACK_NO_BUS 8
  97. #define ACK_BAD_UNIT 9
  98. #define ACK_BAD_PIN 10
  99. #define ACK_BAD_CYLINDER 11
  100. #define ACK_OUT_OF_SRAM 12
  101. #define ACK_OUT_OF_FLASH 13
  102. /*
  103. * CONTROL-CHANNEL COMMAND SET:
  104. * We abuse SET_LINE_CODING requests over endpoint 0, stashing a command
  105. * in the baud-rate field.
  106. */
  107. #define BAUD_NORMAL 9600
  108. #define BAUD_CLEAR_COMMS 10000
  109. /*
  110. * Flux stream opcodes. Preceded by 0xFF byte.
  111. *
  112. * Argument types:
  113. * N28: 28-bit non-negative integer N, encoded as 4 bytes b0,b1,b2,b3:
  114. * b0 = (uint8_t)(1 | (N << 1))
  115. * b1 = (uint8_t)(1 | (N >> 6))
  116. * b2 = (uint8_t)(1 | (N >> 13))
  117. * b3 = (uint8_t)(1 | (N >> 20))
  118. */
  119. /* FLUXOP_INDEX [CMD_READ_FLUX]
  120. * Args:
  121. * +4 [N28]: ticks to index, relative to sample cursor.
  122. * Signals an index pulse in the read stream. Sample cursor is unaffected. */
  123. #define FLUXOP_INDEX 1
  124. /* FLUXOP_SPACE [CMD_READ_FLUX, CMD_WRITE_FLUX]
  125. * Args:
  126. * +4 [N28]: ticks to increment the sample cursor.
  127. * Increments the sample cursor with no intervening flux transitions. */
  128. #define FLUXOP_SPACE 2
  129. /* FLUXOP_ASTABLE [CMD_WRITE_FLUX]
  130. * Args:
  131. * +4 [N28]: astable period.
  132. * Generate regular flux transitions at specified astable period.
  133. * Duration is specified by immediately preceding FLUXOP_SPACE opcode(s). */
  134. #define FLUXOP_ASTABLE 3
  135. /*
  136. * COMMAND PACKETS
  137. */
  138. /* CMD_GET_INFO, index 0 */
  139. #define GETINFO_FIRMWARE 0
  140. struct packed gw_info {
  141. uint8_t fw_major;
  142. uint8_t fw_minor;
  143. uint8_t is_main_firmware; /* == 0 -> update bootloader */
  144. uint8_t max_cmd;
  145. uint32_t sample_freq;
  146. uint8_t hw_model, hw_submodel;
  147. uint8_t usb_speed;
  148. };
  149. extern struct gw_info gw_info;
  150. /* CMD_GET_INFO, index 1 */
  151. #define GETINFO_BW_STATS 1
  152. struct packed gw_bw_stats {
  153. struct packed {
  154. uint32_t bytes;
  155. uint32_t usecs;
  156. } min_bw, max_bw;
  157. };
  158. /* CMD_READ_FLUX */
  159. struct packed gw_read_flux {
  160. /** MANDATORY FIELDS: **/
  161. /* Maximum ticks to read for (or 0, for no limit). */
  162. uint32_t ticks;
  163. /* Maximum index pulses to read (or 0, for no limit). */
  164. uint16_t max_index;
  165. /** OPTIONAL FIELDS: **/
  166. /* Linger time, in ticks, to continue reading after @max_index pulses. */
  167. uint32_t max_index_linger; /* default: 500 microseconds */
  168. };
  169. /* CMD_WRITE_FLUX */
  170. struct packed gw_write_flux {
  171. /* If non-zero, start the write at the index pulse. */
  172. uint8_t cue_at_index;
  173. /* If non-zero, terminate the write at the next index pulse. */
  174. uint8_t terminate_at_index;
  175. };
  176. /* CMD_ERASE_FLUX */
  177. struct packed gw_erase_flux {
  178. uint32_t ticks;
  179. };
  180. /* CMD_SINK_SOURCE_BYTES */
  181. struct packed gw_sink_source_bytes {
  182. uint32_t nr_bytes;
  183. uint32_t seed;
  184. };
  185. /* CMD_{GET,SET}_PARAMS, index 0 */
  186. #define PARAMS_DELAYS 0
  187. struct packed gw_delay {
  188. uint16_t select_delay; /* usec */
  189. uint16_t step_delay; /* usec */
  190. uint16_t seek_settle; /* msec */
  191. uint16_t motor_delay; /* msec */
  192. uint16_t watchdog; /* msec */
  193. };
  194. /* CMD_SWITCH_FW_MODE */
  195. #define FW_MODE_BOOTLOADER 0
  196. #define FW_MODE_NORMAL 1
  197. /*
  198. * Local variables:
  199. * mode: C
  200. * c-file-style: "Linux"
  201. * c-basic-offset: 4
  202. * tab-width: 4
  203. * indent-tabs-mode: nil
  204. * End:
  205. */