@@ -122,36 +122,46 @@ Test(ceda_fdc, seekCommand) {
122
122
cr_expect_eq (data , 5 );
123
123
}
124
124
125
+ /**
126
+ * @brief Auxiliary function, send a data buffer to the FDC checking that it is
127
+ * in input mode for each byte
128
+ */
129
+ static void sendBuffer (const uint8_t * buffer , size_t size ) {
130
+ while (size -- > 0 ) {
131
+ assert_fdc_sr (FDC_ST_RQM | FDC_ST_CB );
132
+ fdc_out (FDC_ADDR_DATA_REGISTER , * (buffer ++ ));
133
+ }
134
+ }
135
+
136
+ /**
137
+ * @brief Auxiliary function, receive a data buffer from the FDC checking that
138
+ * it is in output mode for each byte
139
+ */
140
+ static void receiveBuffer (uint8_t * buffer , size_t size ) {
141
+ while (size -- > 0 ) {
142
+ assert_fdc_sr (FDC_ST_RQM | FDC_ST_DIO | FDC_ST_CB );
143
+ * (buffer ++ ) = fdc_in (FDC_ADDR_DATA_REGISTER );
144
+ }
145
+ }
146
+
125
147
Test (ceda_fdc , readCommandNoMedium ) {
148
+ uint8_t arguments [8 ] = {
149
+ 0 , // drive number
150
+ 1 , // cylinder
151
+ 0 , // head
152
+ 1 , // record
153
+ 1 , // N - bytes per sector size factor
154
+ 5 , // EOT (end of track)
155
+ 0 , // GPL (ignored)
156
+ 0 , // DTL (ignored)
157
+ };
158
+
126
159
fdc_init ();
127
160
128
161
fdc_out (FDC_ADDR_DATA_REGISTER , FDC_READ_DATA );
129
162
130
- /* Provide the argument, dummy ones! */
131
- assert_fdc_sr (FDC_ST_RQM | FDC_ST_CB );
132
- // 1st argument is number of drive
133
- fdc_out (FDC_ADDR_DATA_REGISTER , 0 );
134
- assert_fdc_sr (FDC_ST_RQM | FDC_ST_CB );
135
- // 2nd argument is cylinder number
136
- fdc_out (FDC_ADDR_DATA_REGISTER , 1 );
137
- assert_fdc_sr (FDC_ST_RQM | FDC_ST_CB );
138
- // 3rd argument is head number
139
- fdc_out (FDC_ADDR_DATA_REGISTER , 0 );
140
- assert_fdc_sr (FDC_ST_RQM | FDC_ST_CB );
141
- // 4th argument is record number
142
- fdc_out (FDC_ADDR_DATA_REGISTER , 1 );
143
- assert_fdc_sr (FDC_ST_RQM | FDC_ST_CB );
144
- // 5th argument is bytes per sector factor
145
- fdc_out (FDC_ADDR_DATA_REGISTER , 1 );
146
- assert_fdc_sr (FDC_ST_RQM | FDC_ST_CB );
147
- // 6th argument is EOT
148
- fdc_out (FDC_ADDR_DATA_REGISTER , 5 );
149
- assert_fdc_sr (FDC_ST_RQM | FDC_ST_CB );
150
- // 7th argument is GPL
151
- fdc_out (FDC_ADDR_DATA_REGISTER , 0 );
152
- assert_fdc_sr (FDC_ST_RQM | FDC_ST_CB );
153
- // 8th argument is DTL
154
- fdc_out (FDC_ADDR_DATA_REGISTER , 0 );
163
+ // Send arguments checking for no error
164
+ sendBuffer (arguments , sizeof (arguments ));
155
165
156
166
// FDC switches IO mode, but...
157
167
assert_fdc_sr (FDC_ST_RQM | FDC_ST_DIO | FDC_ST_EXM | FDC_ST_CB );
@@ -164,38 +174,237 @@ Test(ceda_fdc, readCommandNoMedium) {
164
174
cr_assert_eq (fdc_getIntStatus (), true);
165
175
}
166
176
167
- Test (ceda_fdc , readCommand ) {
177
+ /**
178
+ * @brief This section covers the cases described in table 2-2 of xxxxxxx
179
+ * datasheet.
180
+ * Please note that the FDC should accept logical head value different than
181
+ * physical one.
182
+ */
183
+
184
+ struct rw_test_params_t {
185
+ uint8_t cmd_alteration ;
186
+ uint8_t arguments [8 ];
168
187
uint8_t result [7 ];
188
+ };
189
+
190
+ ParameterizedTestParameters (ceda_fdc , readCommand0 ) {
191
+ static struct rw_test_params_t params [] = {
192
+ {
193
+ // No MT, end record < EOT, physical head 0
194
+ 0 , // No alteration
195
+ {
196
+ 0 , // drive number
197
+ 7 , // cylinder
198
+ 0 , // head
199
+ 5 , // record
200
+ 1 , // N - bytes per sector size factor
201
+ 10 , // EOT (end of track)
202
+ 0 , // GPL (ignored)
203
+ 0 , // DTL (ignored)
204
+ },
205
+ {
206
+ 0 , // Drive number, no error
207
+ 0 , // no error
208
+ 0 , // no error
209
+ 7 , // cylinder
210
+ 0 , // head
211
+ 7 , // record
212
+ 1 , // N
213
+ },
214
+ },
215
+ {
216
+ // No MT, end record = EOT, physical head 0
217
+ 0 ,
218
+ {
219
+ 1 , // drive number
220
+ 7 , // cylinder
221
+ 1 , // head - different from physical head just for fun
222
+ 9 , // record
223
+ 1 , // N - bytes per sector size factor
224
+ 10 , // EOT (end of track)
225
+ 0 , // GPL
226
+ 0 , // DTL
227
+ },
228
+ {
229
+ 1 , // drive number, no error
230
+ 0 , // no error
231
+ 0 , // no error
232
+ 8 , // cylinder
233
+ 1 , // head
234
+ 1 , // record
235
+ 1 , // N
236
+ },
237
+ },
238
+ {
239
+ // No MT, end record < EOT, physical head 1
240
+ 0 ,
241
+ {
242
+ FDC_ST0_HD | 2 , // Drive number, physical head 1
243
+ 7 , // cylinder
244
+ 0 , // head - different from physical head just for fun
245
+ 5 , // record
246
+ 1 , // N - bytes per sector size factor
247
+ 10 , // EOT (end of track)
248
+ 0 , // GPL
249
+ 0 , // DTL
250
+ },
251
+ {
252
+ FDC_ST0_HD | 2 , // drive number, physical head 1, no error
253
+ 0 , // no error
254
+ 0 , // no error
255
+ 7 , // cylinder
256
+ 0 , // head
257
+ 7 , // record
258
+ 1 , // N
259
+ },
260
+ },
261
+ {
262
+ // No MT, end record = EOT, physical head 1
263
+ 0 ,
264
+ {
265
+ FDC_ST0_HD | 3 , // Drive number, physical head 1
266
+ 7 , // cylinder
267
+ 1 , // head
268
+ 9 , // record
269
+ 1 , // N - bytes per sector size factor
270
+ 10 , // EOT (end of track)
271
+ 0 , // GPL
272
+ 0 , // DTL
273
+ },
274
+ {
275
+ FDC_ST0_HD | 3 , // drive number, physical head 1, no error
276
+ 0 , // no error
277
+ 0 , // no error
278
+ 8 , // cylinder
279
+ 1 , // head
280
+ 1 , // record
281
+ 1 , // N
282
+ },
283
+ },
284
+ /* * * * * * */
285
+ {
286
+ // MT (multi-track), end record < EOT, physical head 0
287
+ FDC_CMD_ARGS_MT_bm ,
288
+ {
289
+ 3 , // Drive number
290
+ 7 , // cylinder
291
+ 0 , // head
292
+ 5 , // record
293
+ 1 , // N - bytes per sector size factor
294
+ 10 , // EOT (end of track)
295
+ 0 , // GPL
296
+ 0 , // DTL
297
+ },
298
+ {
299
+ 3 , // drive number, physical head 0, no error
300
+ 0 , // no error
301
+ 0 , // no error
302
+ 7 , // cylinder
303
+ 0 , // head
304
+ 7 , // record
305
+ 1 , // N
306
+ },
307
+ },
308
+ {
309
+ // MT (multi-track), end record = EOT, physical head 0
310
+ FDC_CMD_ARGS_MT_bm ,
311
+ {
312
+ 2 , // Drive number
313
+ 7 , // cylinder
314
+ 1 , // head - different from physical head just for fun
315
+ 9 , // record
316
+ 1 , // N - bytes per sector size factor
317
+ 10 , // EOT (end of track)
318
+ 0 , // GPL
319
+ 0 , // DTL
320
+ },
321
+ {
322
+ FDC_ST0_HD | 2 , // drive number, physical head 1, no error
323
+ 0 , // no error
324
+ 0 , // no error
325
+ 7 , // cylinder
326
+ 0 , // head
327
+ 1 , // record
328
+ 1 , // N
329
+ },
330
+ },
331
+ {
332
+ // MT (multi-track), end record < EOT, physical head 1
333
+ FDC_CMD_ARGS_MT_bm ,
334
+ {
335
+ FDC_ST0_HD | 1 , // Drive number, physical head 1
336
+ 7 , // cylinder
337
+ 0 , // head
338
+ 5 , // record
339
+ 1 , // N - bytes per sector size factor
340
+ 10 , // EOT (end of track)
341
+ 0 , // GPL
342
+ 0 , // DTL
343
+ },
344
+ {
345
+ FDC_ST0_HD | 1 , // drive number, physical head 1, no error
346
+ 0 , // no error
347
+ 0 , // no error
348
+ 7 , // cylinder
349
+ 0 , // head
350
+ 7 , // record
351
+ 1 , // N
352
+ },
353
+ },
354
+ {
355
+ // MT (multi-track), end record = EOT, physical head 1
356
+ FDC_CMD_ARGS_MT_bm ,
357
+ {
358
+ FDC_ST0_HD | 0 , // Drive number, physical head 1
359
+ 7 , // cylinder
360
+ 0 , // head - different from physical head just for fun
361
+ 9 , // record
362
+ 1 , // N - bytes per sector size factor
363
+ 10 , // EOT (end of track)
364
+ 0 , // GPL
365
+ 0 , // DTL
366
+ },
367
+ {
368
+ 0 , // drive number, physical head 0, no error
369
+ 0 , // no error
370
+ 0 , // no error
371
+ 8 , // cylinder
372
+ 1 , // head
373
+ 1 , // record
374
+ 1 , // N
375
+ },
376
+ },
377
+ };
378
+
379
+ size_t nb_params = sizeof (params ) / sizeof (struct rw_test_params_t );
380
+ return cr_make_param_array (struct rw_test_params_t , params , nb_params );
381
+ }
382
+
383
+ ParameterizedTest (struct rw_test_params_t * param , ceda_fdc , readCommand0 ) {
384
+ uint8_t result [sizeof (param -> result )];
169
385
170
386
fdc_init ();
171
387
172
- // Link a fake reading function.
173
- // TODO(giuliof): mocking may be better here
388
+ // Link a fake reading function
174
389
fdc_kickDiskImage (fake_read , NULL );
175
390
176
- fdc_out (FDC_ADDR_DATA_REGISTER , FDC_READ_DATA );
391
+ fdc_out (FDC_ADDR_DATA_REGISTER , FDC_READ_DATA | param -> cmd_alteration );
177
392
178
- // 1st argument is number of drive
179
- fdc_out (FDC_ADDR_DATA_REGISTER , 2 | 1 << 2 );
180
- // 2nd argument is cylinder number
181
- fdc_out (FDC_ADDR_DATA_REGISTER , 7 );
182
- // 3rd argument is head number
183
- fdc_out (FDC_ADDR_DATA_REGISTER , 1 );
184
- // 4th argument is record number
185
- fdc_out (FDC_ADDR_DATA_REGISTER , 5 );
186
- // 5th argument is bytes per sector factor
187
- fdc_out (FDC_ADDR_DATA_REGISTER , 1 );
188
- // 6th argument is EOT
189
- fdc_out (FDC_ADDR_DATA_REGISTER , 10 );
190
- // 7th argument is GPL
191
- fdc_out (FDC_ADDR_DATA_REGISTER , 0 );
192
- // 8th argument is DTL
193
- fdc_out (FDC_ADDR_DATA_REGISTER , 0 );
393
+ // Send arguments checking for no error
394
+ sendBuffer (param -> arguments , sizeof (param -> arguments ));
194
395
195
396
// FDC is in execution mode
196
397
assert_fdc_sr (FDC_ST_RQM | FDC_ST_DIO | FDC_ST_EXM | FDC_ST_CB );
197
398
198
- // Read four times
399
+ // FDC is ready to serve data
400
+ cr_assert_eq (fdc_getIntStatus (), true);
401
+
402
+ // Read two full sectors
403
+ fdc_in (FDC_ADDR_DATA_REGISTER );
404
+ fdc_in (FDC_ADDR_DATA_REGISTER );
405
+ fdc_in (FDC_ADDR_DATA_REGISTER );
406
+ fdc_in (FDC_ADDR_DATA_REGISTER );
407
+
199
408
fdc_in (FDC_ADDR_DATA_REGISTER );
200
409
fdc_in (FDC_ADDR_DATA_REGISTER );
201
410
fdc_in (FDC_ADDR_DATA_REGISTER );
@@ -207,26 +416,10 @@ Test(ceda_fdc, readCommand) {
207
416
// Stop the reading
208
417
fdc_tc_out (0 , 0 );
209
418
210
- // Execution is finished, but still busy waiting for read of results
211
- assert_fdc_sr (FDC_ST_RQM | FDC_ST_DIO | FDC_ST_CB );
419
+ receiveBuffer (result , sizeof (result ));
212
420
213
- result [0 ] = fdc_in (FDC_ADDR_DATA_REGISTER );
214
- result [1 ] = fdc_in (FDC_ADDR_DATA_REGISTER );
215
- result [2 ] = fdc_in (FDC_ADDR_DATA_REGISTER );
216
- result [3 ] = fdc_in (FDC_ADDR_DATA_REGISTER );
217
- result [4 ] = fdc_in (FDC_ADDR_DATA_REGISTER );
218
- result [5 ] = fdc_in (FDC_ADDR_DATA_REGISTER );
219
- result [6 ] = fdc_in (FDC_ADDR_DATA_REGISTER );
421
+ cr_assert_arr_eq (result , param -> result , sizeof (result ));
220
422
221
423
// Execution is finished
222
424
assert_fdc_sr (FDC_ST_RQM );
223
-
224
- // check the content of result
225
- cr_expect_eq (result [0 ], FDC_ST0_HD | 2 );
226
- cr_expect_eq (result [1 ], 0 );
227
- cr_expect_eq (result [2 ], 0 );
228
- cr_expect_eq (result [3 ], 7 );
229
- cr_expect_eq (result [4 ], 1 );
230
- cr_expect_eq (result [5 ], 6 );
231
- cr_expect_eq (result [6 ], 1 );
232
425
}
0 commit comments