cdc_acm_protocol.h 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  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, 0. 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_SIDE, length=3, side# (0=bottom) */
  26. #define CMD_SIDE 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-3. Optionally include all or part of gw_read_flux.
  34. * Returns flux readings until EOStream. */
  35. #define CMD_READ_FLUX 7
  36. /* CMD_WRITE_FLUX, length=2-3. Optionally include all or part of 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_GET_INDEX_TIMES, length=4, first, nr.
  42. * Returns nr*4 bytes after ACK. */
  43. #define CMD_GET_INDEX_TIMES 10
  44. /* CMD_SWITCH_FW_MODE, length=3, <mode> */
  45. #define CMD_SWITCH_FW_MODE 11
  46. /* CMD_SELECT, length=3, drive#. Select drive# as current unit. */
  47. #define CMD_SELECT 12
  48. /* CMD_DESELECT, length=2. Deselect current unit (if any). */
  49. #define CMD_DESELECT 13
  50. /* CMD_SET_BUS_TYPE, length=3, bus_type. Set the bus type. */
  51. #define CMD_SET_BUS_TYPE 14
  52. /* CMD_SET_PIN, length=4, pin#, level. */
  53. #define CMD_SET_PIN 15
  54. /* CMD_RESET, length=2. Reset all state to initial (power on) values. */
  55. #define CMD_RESET 16
  56. /* CMD_ERASE_FLUX, length=6. Argument is gw_erase_flux. */
  57. #define CMD_ERASE_FLUX 17
  58. /* CMD_SOURCE_BYTES, length=6. Argument is gw_sink_source_bytes. */
  59. #define CMD_SOURCE_BYTES 18
  60. /* CMD_SINK_BYTES, length=6. Argument is gw_sink_source_bytes. */
  61. #define CMD_SINK_BYTES 19
  62. #define CMD_MAX 19
  63. /*
  64. * CMD_SET_BUS CODES
  65. */
  66. #define BUS_NONE 0
  67. #define BUS_IBMPC 1
  68. #define BUS_SHUGART 2
  69. /*
  70. * ACK RETURN CODES
  71. */
  72. #define ACK_OKAY 0
  73. #define ACK_BAD_COMMAND 1
  74. #define ACK_NO_INDEX 2
  75. #define ACK_NO_TRK0 3
  76. #define ACK_FLUX_OVERFLOW 4
  77. #define ACK_FLUX_UNDERFLOW 5
  78. #define ACK_WRPROT 6
  79. #define ACK_NO_UNIT 7
  80. #define ACK_NO_BUS 8
  81. #define ACK_BAD_UNIT 9
  82. #define ACK_BAD_PIN 10
  83. /*
  84. * CONTROL-CHANNEL COMMAND SET:
  85. * We abuse SET_LINE_CODING requests over endpoint 0, stashing a command
  86. * in the baud-rate field.
  87. */
  88. #define BAUD_NORMAL 9600
  89. #define BAUD_CLEAR_COMMS 10000
  90. /*
  91. * COMMAND PACKETS
  92. */
  93. /* CMD_GET_INFO, index 0 */
  94. #define GETINFO_FIRMWARE 0
  95. struct packed gw_info {
  96. uint8_t fw_major;
  97. uint8_t fw_minor;
  98. uint8_t max_index;
  99. uint8_t max_cmd;
  100. uint32_t sample_freq;
  101. uint8_t hw_model, hw_submodel;
  102. uint8_t usb_speed;
  103. };
  104. extern struct gw_info gw_info;
  105. /* CMD_GET_INFO, index 1 */
  106. #define GETINFO_BW_STATS 1
  107. struct packed gw_bw_stats {
  108. struct packed {
  109. uint32_t bytes;
  110. uint32_t usecs;
  111. } min_bw, max_bw;
  112. };
  113. /* CMD_READ_FLUX */
  114. struct packed gw_read_flux {
  115. uint8_t nr_idx; /* default: 2 */
  116. };
  117. /* CMD_WRITE_FLUX */
  118. struct packed gw_write_flux {
  119. uint8_t terminate_at_index; /* default: 0 */
  120. };
  121. /* CMD_ERASE_FLUX */
  122. struct packed gw_erase_flux {
  123. uint32_t erase_ticks;
  124. };
  125. /* CMD_SINK_SOURCE_BYTES */
  126. struct packed gw_sink_source_bytes {
  127. uint32_t nr_bytes;
  128. };
  129. /* CMD_{GET,SET}_PARAMS, index 0 */
  130. #define PARAMS_DELAYS 0
  131. struct packed gw_delay {
  132. uint16_t select_delay; /* usec */
  133. uint16_t step_delay; /* usec */
  134. uint16_t seek_settle; /* msec */
  135. uint16_t motor_delay; /* msec */
  136. uint16_t auto_off; /* msec */
  137. };
  138. /* CMD_SWITCH_FW_MODE */
  139. #define FW_MODE_BOOTLOADER 0
  140. #define FW_MODE_NORMAL 1
  141. /*
  142. * Local variables:
  143. * mode: C
  144. * c-file-style: "Linux"
  145. * c-basic-offset: 4
  146. * tab-width: 4
  147. * indent-tabs-mode: nil
  148. * End:
  149. */