cdc_acm_protocol.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  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. /* CMD_SEEK, length=3, cyl# */
  17. #define CMD_SEEK 1
  18. /* CMD_SIDE, length=3, side# (0=bottom) */
  19. #define CMD_SIDE 2
  20. /* CMD_SET_PARAMS, length=3+nr, idx, <nr bytes> */
  21. #define CMD_SET_PARAMS 3
  22. /* CMD_GET_PARAMS, length=4, idx, nr_bytes. Returns nr_bytes after ACK. */
  23. #define CMD_GET_PARAMS 4
  24. /* CMD_MOTOR, length=3, motor_mask */
  25. #define CMD_MOTOR 5
  26. /* CMD_READ_FLUX, length=2-3. Optionally include all or part of gw_read_flux.
  27. * Returns flux readings until EOStream. */
  28. #define CMD_READ_FLUX 6
  29. /* CMD_WRITE_FLUX, length=2-7. Optionally include all or part of gw_write_flux.
  30. * Host follows with flux readings until EOStream. */
  31. #define CMD_WRITE_FLUX 7
  32. /* CMD_GET_FLUX_STATUS, length=2. Last read/write status returned in ACK. */
  33. #define CMD_GET_FLUX_STATUS 8
  34. /* CMD_GET_INDEX_TIMES, length=4, first, nr.
  35. * Returns nr*4 bytes after ACK. */
  36. #define CMD_GET_INDEX_TIMES 9
  37. /* CMD_SELECT, length=3, select_mask */
  38. #define CMD_SELECT 10
  39. /* CMD_SWITCH_FW_MODE, length=3, <mode> */
  40. #define CMD_SWITCH_FW_MODE 11
  41. #define CMD_MAX 11
  42. /* [BOOTLOADER] CMD_UPDATE, length=6, <update_len>.
  43. * Host follows with <update_len> bytes.
  44. * Bootloader finally returns a status byte, 0 on success. */
  45. #define CMD_UPDATE 1
  46. /*
  47. * ACK RETURN CODES
  48. */
  49. #define ACK_OKAY 0
  50. #define ACK_BAD_COMMAND 1
  51. #define ACK_NO_INDEX 2
  52. #define ACK_NO_TRK0 3
  53. #define ACK_FLUX_OVERFLOW 4
  54. #define ACK_FLUX_UNDERFLOW 5
  55. #define ACK_WRPROT 6
  56. /*
  57. * CONTROL-CHANNEL COMMAND SET:
  58. * We abuse SET_LINE_CODING requests over endpoint 0, stashing a command
  59. * in the baud-rate field.
  60. */
  61. #define BAUD_NORMAL 9600
  62. #define BAUD_CLEAR_COMMS 10000
  63. /*
  64. * COMMAND PACKETS
  65. */
  66. /* CMD_GET_INFO, index 0 */
  67. struct packed gw_info {
  68. uint8_t fw_major;
  69. uint8_t fw_minor;
  70. uint8_t max_index;
  71. uint8_t max_cmd;
  72. uint32_t sample_freq;
  73. uint16_t hw_type;
  74. };
  75. /* CMD_READ_FLUX */
  76. struct packed gw_read_flux {
  77. uint8_t nr_idx; /* default: 2 */
  78. };
  79. /* CMD_WRITE_FLUX */
  80. struct packed gw_write_flux {
  81. uint32_t index_delay_ticks; /* default: 0 */
  82. uint8_t terminate_at_index; /* default: 0 */
  83. };
  84. /* CMD_{GET,SET}_PARAMS, index 0 */
  85. #define PARAMS_DELAYS 0
  86. struct packed gw_delay {
  87. uint16_t select_delay; /* usec */
  88. uint16_t step_delay; /* usec */
  89. uint16_t seek_settle; /* msec */
  90. uint16_t motor_delay; /* msec */
  91. uint16_t auto_off; /* msec */
  92. };
  93. /* CMD_SWITCH_FW_MODE */
  94. #define FW_MODE_BOOTLOADER 0
  95. #define FW_MODE_NORMAL 1
  96. /*
  97. * Local variables:
  98. * mode: C
  99. * c-file-style: "Linux"
  100. * c-basic-offset: 4
  101. * tab-width: 4
  102. * indent-tabs-mode: nil
  103. * End:
  104. */