cdc_acm_protocol.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  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. #define CMD_UPDATE 1
  20. /* CMD_SEEK, length=3, cyl#. Seek to cyl# on selected drive. */
  21. #define CMD_SEEK 2
  22. /* CMD_SIDE, length=3, side# (0=bottom) */
  23. #define CMD_SIDE 3
  24. /* CMD_SET_PARAMS, length=3+nr, idx, <nr bytes> */
  25. #define CMD_SET_PARAMS 4
  26. /* CMD_GET_PARAMS, length=4, idx, nr_bytes. Returns nr_bytes after ACK. */
  27. #define CMD_GET_PARAMS 5
  28. /* CMD_MOTOR, length=4, drive#, on/off. Turn on/off a drive motor. */
  29. #define CMD_MOTOR 6
  30. /* CMD_READ_FLUX, length=2-3. Optionally include all or part of gw_read_flux.
  31. * Returns flux readings until EOStream. */
  32. #define CMD_READ_FLUX 7
  33. /* CMD_WRITE_FLUX, length=2-3. Optionally include all or part of gw_write_flux.
  34. * Host follows with flux readings until EOStream. */
  35. #define CMD_WRITE_FLUX 8
  36. /* CMD_GET_FLUX_STATUS, length=2. Last read/write status returned in ACK. */
  37. #define CMD_GET_FLUX_STATUS 9
  38. /* CMD_GET_INDEX_TIMES, length=4, first, nr.
  39. * Returns nr*4 bytes after ACK. */
  40. #define CMD_GET_INDEX_TIMES 10
  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. #define CMD_MAX 17
  56. /*
  57. * CMD_SET_BUS CODES
  58. */
  59. #define BUS_NONE 0
  60. #define BUS_IBMPC 1
  61. #define BUS_SHUGART 2
  62. /*
  63. * ACK RETURN CODES
  64. */
  65. #define ACK_OKAY 0
  66. #define ACK_BAD_COMMAND 1
  67. #define ACK_NO_INDEX 2
  68. #define ACK_NO_TRK0 3
  69. #define ACK_FLUX_OVERFLOW 4
  70. #define ACK_FLUX_UNDERFLOW 5
  71. #define ACK_WRPROT 6
  72. #define ACK_NO_UNIT 7
  73. #define ACK_NO_BUS 8
  74. #define ACK_BAD_UNIT 9
  75. #define ACK_BAD_PIN 10
  76. /*
  77. * CONTROL-CHANNEL COMMAND SET:
  78. * We abuse SET_LINE_CODING requests over endpoint 0, stashing a command
  79. * in the baud-rate field.
  80. */
  81. #define BAUD_NORMAL 9600
  82. #define BAUD_CLEAR_COMMS 10000
  83. /*
  84. * COMMAND PACKETS
  85. */
  86. /* CMD_GET_INFO, index 0 */
  87. struct packed gw_info {
  88. uint8_t fw_major;
  89. uint8_t fw_minor;
  90. uint8_t max_index;
  91. uint8_t max_cmd;
  92. uint32_t sample_freq;
  93. uint16_t hw_type;
  94. };
  95. /* CMD_READ_FLUX */
  96. struct packed gw_read_flux {
  97. uint8_t nr_idx; /* default: 2 */
  98. };
  99. /* CMD_WRITE_FLUX */
  100. struct packed gw_write_flux {
  101. uint8_t terminate_at_index; /* default: 0 */
  102. };
  103. /* CMD_ERASE_FLUX */
  104. struct packed gw_erase_flux {
  105. uint32_t erase_ticks;
  106. };
  107. /* CMD_{GET,SET}_PARAMS, index 0 */
  108. #define PARAMS_DELAYS 0
  109. struct packed gw_delay {
  110. uint16_t select_delay; /* usec */
  111. uint16_t step_delay; /* usec */
  112. uint16_t seek_settle; /* msec */
  113. uint16_t motor_delay; /* msec */
  114. uint16_t auto_off; /* msec */
  115. };
  116. /* CMD_SWITCH_FW_MODE */
  117. #define FW_MODE_BOOTLOADER 0
  118. #define FW_MODE_NORMAL 1
  119. /*
  120. * Local variables:
  121. * mode: C
  122. * c-file-style: "Linux"
  123. * c-basic-offset: 4
  124. * tab-width: 4
  125. * indent-tabs-mode: nil
  126. * End:
  127. */