1 #ifndef PROTOCOL_H
2 #define PROTOCOL_H
3 
4 enum
5 {
6     FLUXENGINE_VERSION = 15,
7 
8     FLUXENGINE_VID = 0x1209,
9     FLUXENGINE_PID = 0x6e00,
10 
11     /* libusb uses these numbers */
12     FLUXENGINE_DATA_OUT_EP = 0x01,
13     FLUXENGINE_DATA_IN_EP = 0x82,
14     FLUXENGINE_CMD_OUT_EP = 0x03,
15     FLUXENGINE_CMD_IN_EP = 0x84,
16 
17     /* the PSoC code uses these, sigh */
18     FLUXENGINE_DATA_OUT_EP_NUM = FLUXENGINE_DATA_OUT_EP & 0x0f,
19     FLUXENGINE_DATA_IN_EP_NUM = FLUXENGINE_DATA_IN_EP & 0x0f,
20     FLUXENGINE_CMD_OUT_EP_NUM = FLUXENGINE_CMD_OUT_EP & 0x0f,
21     FLUXENGINE_CMD_IN_EP_NUM = FLUXENGINE_CMD_IN_EP & 0x0f,
22 
23     SIDE_SIDEA = 0<<0,
24     SIDE_SIDEB = 1<<0,
25 
26     DRIVE_0 = 0,
27     DRIVE_1 = 1,
28     DRIVE_DD = 0<<1,
29     DRIVE_HD = 1<<1,
30 
31     FRAME_SIZE = 64,
32     TICK_FREQUENCY = 12000000,
33     TICKS_PER_US = TICK_FREQUENCY / 1000000,
34     TICKS_PER_MS = TICK_FREQUENCY / 1000,
35 
36     PRECOMPENSATION_THRESHOLD_TICKS = (int)(2.25 * TICKS_PER_US),
37 };
38 
39 #define NS_PER_TICK (1000000000.0 / (double)TICK_FREQUENCY)
40 #define US_PER_TICK (1000000.0 / (double)TICK_FREQUENCY)
41 #define MS_PER_TICK (1000.0 / (double)TICK_FREQUENCY)
42 
43 enum
44 {
45     F_FRAME_ERROR = 0,            /* any_frame */
46     F_FRAME_DEBUG,                /* debug_frame */
47     F_FRAME_GET_VERSION_CMD,      /* any_frame */
48     F_FRAME_GET_VERSION_REPLY,    /* version_frame */
49     F_FRAME_SEEK_CMD,             /* seek_frame */
50     F_FRAME_SEEK_REPLY,           /* any_frame */
51     F_FRAME_MEASURE_SPEED_CMD,    /* measurespeed_frame */
52     F_FRAME_MEASURE_SPEED_REPLY,  /* speed_frame */
53     F_FRAME_BULK_WRITE_TEST_CMD,   /* any_frame */
54     F_FRAME_BULK_WRITE_TEST_REPLY, /* any_frame */
55     F_FRAME_BULK_READ_TEST_CMD,   /* any_frame */
56     F_FRAME_BULK_READ_TEST_REPLY, /* any_frame */
57     F_FRAME_READ_CMD,             /* read_frame */
58     F_FRAME_READ_REPLY,           /* any_frame */
59     F_FRAME_WRITE_CMD,            /* write_frame */
60     F_FRAME_WRITE_REPLY,          /* any_frame */
61     F_FRAME_ERASE_CMD,            /* erase_frame */
62     F_FRAME_ERASE_REPLY,          /* any_frame */
63     F_FRAME_RECALIBRATE_CMD,      /* any_frame */
64     F_FRAME_RECALIBRATE_REPLY,    /* any_frame */
65     F_FRAME_SET_DRIVE_CMD,        /* setdrive_frame */
66     F_FRAME_SET_DRIVE_REPLY,      /* any_frame */
67     F_FRAME_MEASURE_VOLTAGES_CMD, /* any_frame */
68     F_FRAME_MEASURE_VOLTAGES_REPLY, /* voltages_frame */
69 };
70 
71 enum
72 {
73     F_ERROR_NONE = 0,
74     F_ERROR_BAD_COMMAND,
75     F_ERROR_UNDERRUN,
76     F_ERROR_INVALID_VALUE,
77     F_ERROR_INTERNAL,
78 };
79 
80 enum
81 {
82     F_INDEX_REAL,
83     F_INDEX_300,
84     F_INDEX_360
85 };
86 
87 enum
88 {
89     F_BIT_PULSE = 0x80,
90     F_BIT_INDEX = 0x40
91 };
92 
93 struct frame_header
94 {
95     uint8_t type;
96     uint8_t size;
97 };
98 
99 struct any_frame
100 {
101     struct frame_header f;
102 };
103 
104 struct error_frame
105 {
106     struct frame_header f;
107     uint8_t error;
108 };
109 
110 struct debug_frame
111 {
112     struct frame_header f;
113     char payload[60];
114 };
115 
116 struct version_frame
117 {
118     struct frame_header f;
119     uint8_t version;
120 };
121 
122 struct seek_frame
123 {
124     struct frame_header f;
125     uint8_t track;
126 };
127 
128 struct measurespeed_frame
129 {
130     struct frame_header f;
131 	uint8_t hard_sector_count;
132 };
133 
134 struct speed_frame
135 {
136     struct frame_header f;
137     uint16_t period_ms;
138 };
139 
140 struct read_frame
141 {
142     struct frame_header f;
143     uint8_t side;
144     uint8_t synced;
145     uint16_t milliseconds;
146     uint8_t hardsec_threshold_ms;
147 };
148 
149 struct write_frame
150 {
151     struct frame_header f;
152     uint8_t side;
153     uint32_t bytes_to_write;
154     uint8_t hardsec_threshold_ms;
155 };
156 
157 struct erase_frame
158 {
159     struct frame_header f;
160     uint8_t side;
161     uint8_t hardsec_threshold_ms;
162 };
163 
164 struct set_drive_frame
165 {
166     struct frame_header f;
167     uint8_t drive;
168     uint8_t high_density;
169     uint8_t index_mode;
170 };
171 
172 struct voltages
173 {
174     uint16_t logic0_mv;
175     uint16_t logic1_mv;
176 };
177 
178 struct voltages_frame
179 {
180     struct frame_header f;
181     struct voltages output_both_off;
182     struct voltages output_drive_0_selected;
183     struct voltages output_drive_1_selected;
184     struct voltages output_drive_0_running;
185     struct voltages output_drive_1_running;
186     struct voltages input_both_off;
187     struct voltages input_drive_0_selected;
188     struct voltages input_drive_1_selected;
189     struct voltages input_drive_0_running;
190     struct voltages input_drive_1_running;
191 };
192 
193 #endif
194