cdc_acm_protocol.h 5.7 KB

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