1 /* This test is designed to test the simple dpump host/device class operation. */
2
3 #include <stdio.h>
4 #include "tx_api.h"
5 #include "ux_api.h"
6 #include "ux_system.h"
7 #include "ux_utility.h"
8
9 #include "fx_api.h"
10
11 #include "ux_device_class_storage.h"
12 #include "ux_device_stack.h"
13 #include "ux_host_class_storage.h"
14
15 /* Define constants. */
16 #define UX_DEMO_STACK_SIZE 2048
17 #define UX_DEMO_BUFFER_SIZE 2048
18 #define UX_DEMO_RECEPTION_BUFFER_SIZE 512
19 #define UX_DEMO_FILE_BUFFER_SIZE 512
20 #define UX_DEMO_RECEPTION_BLOCK_SIZE 64
21 #define UX_DEMO_MEMORY_SIZE (256*1024)
22 #define UX_DEMO_FILE_SIZE (128 * 512)
23 #define UX_RAM_DISK_SIZE (200 * 1024)
24 #define UX_RAM_DISK_LAST_LBA ((UX_RAM_DISK_SIZE / 512) -1)
25
26 /* Define local/extern function prototypes. */
27 static void demo_thread_entry(ULONG);
28 static TX_THREAD tx_demo_thread_host_simulation;
29 static TX_THREAD tx_demo_thread_slave_simulation;
30 static void tx_demo_thread_host_simulation_entry(ULONG);
31
32
33
34 VOID _fx_ram_driver(FX_MEDIA *media_ptr);
35
36 static UINT demo_thread_media_read1(VOID *storage, ULONG lun, UCHAR * data_pointer, ULONG number_blocks, ULONG lba, ULONG *media_status);
37 static UINT demo_thread_media_write1(VOID *storage, ULONG lun, UCHAR * data_pointer, ULONG number_blocks, ULONG lba, ULONG *media_status);
38 static UINT demo_thread_media_status1(VOID *storage, ULONG lun, ULONG media_id, ULONG *media_status);
39
40 static UINT demo_thread_media_read2(VOID *storage, ULONG lun, UCHAR * data_pointer, ULONG number_blocks, ULONG lba, ULONG *media_status);
41 static UINT demo_thread_media_write2(VOID *storage, ULONG lun, UCHAR * data_pointer, ULONG number_blocks, ULONG lba, ULONG *media_status);
42 static UINT demo_thread_media_status2(VOID *storage, ULONG lun, ULONG media_id, ULONG *media_status);
43
44
45 /* Define global data structures. */
46 UCHAR usbx_memory[UX_DEMO_MEMORY_SIZE + (UX_DEMO_STACK_SIZE * 2)];
47 ULONG error_counter;
48 TX_THREAD demo_thread;
49 UX_HOST_CLASS_STORAGE *storage;
50 UX_HOST_CLASS_STORAGE_MEDIA *global_storage_media;
51 FX_MEDIA *media1;
52 FX_MEDIA *media2;
53 UINT status;
54 UINT transfer_completed;
55 ULONG requested_length;
56 FX_FILE my_file;
57 TX_SEMAPHORE demo_semaphore;
58 CHAR file_name[64];
59 UCHAR global_buffer[UX_DEMO_FILE_BUFFER_SIZE];
60 UCHAR buffer[512];
61 FX_MEDIA ram_disk1;
62 CHAR ram_disk_memory1[UX_RAM_DISK_SIZE];
63 FX_MEDIA ram_disk2;
64 CHAR ram_disk_memory2[UX_RAM_DISK_SIZE];
65 UX_SLAVE_CLASS_STORAGE_PARAMETER global_storage_parameter;
66
67 #if defined(UX_HOST_CLASS_STORAGE_NO_FILEX)
68 FX_MEDIA *_ux_host_class_storage_driver_media(INT i);
69 VOID _ux_host_class_storage_driver_entry(FX_MEDIA *media);
70 VOID _ux_host_class_storage_media_insert(UX_HOST_CLASS_STORAGE_MEDIA *storage_media, ULONG format_open);
71 VOID _ux_host_class_storage_media_remove(UX_HOST_CLASS_STORAGE_MEDIA *storage_media);
72 FX_MEDIA *_ux_host_class_storage_media_fx_media(UX_HOST_CLASS_STORAGE_MEDIA *storage_media);
73 UCHAR *_ux_host_class_storage_media_fx_media_memory(UX_HOST_CLASS_STORAGE_MEDIA *storage_media);
74
ux_test_system_host_change_function(ULONG event,UX_HOST_CLASS * cls,VOID * inst)75 static UINT ux_test_system_host_change_function(ULONG event, UX_HOST_CLASS *cls, VOID *inst)
76 {
77
78 switch(event)
79 {
80
81 case UX_STORAGE_MEDIA_INSERTION:
82 _ux_host_class_storage_media_insert((UX_HOST_CLASS_STORAGE_MEDIA*)inst, 1);
83 break;
84
85 case UX_STORAGE_MEDIA_REMOVAL:
86 _ux_host_class_storage_media_remove((UX_HOST_CLASS_STORAGE_MEDIA*)inst);
87 _ux_host_class_storage_media_fx_media((UX_HOST_CLASS_STORAGE_MEDIA*)inst) -> fx_media_id = 0;/* Testing code is checking ID to detect removal. */
88 break;
89
90 default:
91 break;
92 }
93
94 return 0;
95 }
96 #else
97 #define ux_test_system_host_change_function UX_NULL
98 #endif
99
100
101 #define DEVICE_FRAMEWORK_LENGTH_FULL_SPEED 50
102 static UCHAR device_framework_full_speed[] = {
103
104 /* Device descriptor */
105 0x12, 0x01, 0x10, 0x01, 0x00, 0x00, 0x00, 0x08,
106 0x81, 0x07, 0x00, 0x00, 0x00, 0x00, 0x01, 0x02,
107 0x03, 0x01,
108
109 /* Configuration descriptor */
110 0x09, 0x02, 0x20, 0x00, 0x01, 0x01, 0x00, 0xc0,
111 0x32,
112
113 /* Interface descriptor */
114 0x09, 0x04, 0x00, 0x00, 0x02, 0x08, 0x06, 0x50,
115 0x00,
116
117 /* Endpoint descriptor (Bulk In) */
118 0x07, 0x05, 0x81, 0x02, 0x40, 0x00, 0x00,
119
120 /* Endpoint descriptor (Bulk Out) */
121 0x07, 0x05, 0x02, 0x02, 0x40, 0x00, 0x00
122
123 };
124
125
126 #define DEVICE_FRAMEWORK_LENGTH_HIGH_SPEED 60
127 static UCHAR device_framework_high_speed[] = {
128
129 /* Device descriptor */
130 0x12, 0x01, 0x00, 0x02, 0x00, 0x00, 0x00, 0x40,
131 0x81, 0x07, 0x00, 0x00, 0x01, 0x00, 0x01, 0x02,
132 0x03, 0x01,
133
134 /* Device qualifier descriptor */
135 0x0a, 0x06, 0x00, 0x02, 0x00, 0x00, 0x00, 0x40,
136 0x01, 0x00,
137
138 /* Configuration descriptor */
139 0x09, 0x02, 0x20, 0x00, 0x01, 0x01, 0x00, 0xc0,
140 0x32,
141
142 /* Interface descriptor */
143 0x09, 0x04, 0x00, 0x00, 0x02, 0x08, 0x06, 0x50,
144 0x00,
145
146 /* Endpoint descriptor (Bulk In) */
147 0x07, 0x05, 0x81, 0x02, 0x00, 0x01, 0x00,
148
149 /* Endpoint descriptor (Bulk Out) */
150 0x07, 0x05, 0x02, 0x02, 0x00, 0x01, 0x00
151
152 };
153
154
155 /* String Device Framework :
156 Byte 0 and 1 : Word containing the language ID : 0x0904 for US
157 Byte 2 : Byte containing the index of the descriptor
158 Byte 3 : Byte containing the length of the descriptor string
159 */
160
161 #define STRING_FRAMEWORK_LENGTH 38
162 static UCHAR string_framework[] = {
163
164 /* Manufacturer string descriptor : Index 1 */
165 0x09, 0x04, 0x01, 0x0c,
166 0x45, 0x78, 0x70, 0x72,0x65, 0x73, 0x20, 0x4c,
167 0x6f, 0x67, 0x69, 0x63,
168
169 /* Product string descriptor : Index 2 */
170 0x09, 0x04, 0x02, 0x0a,
171 0x46, 0x6c, 0x61, 0x73, 0x68, 0x20, 0x44, 0x69,
172 0x73, 0x6b,
173
174 /* Serial Number string descriptor : Index 3 */
175 0x09, 0x04, 0x03, 0x04,
176 0x30, 0x30, 0x30, 0x31
177 };
178
179
180 /* Multiple languages are supported on the device, to add
181 a language besides english, the unicode language code must
182 be appended to the language_id_framework array and the length
183 adjusted accordingly. */
184 #define LANGUAGE_ID_FRAMEWORK_LENGTH 2
185 static UCHAR language_id_framework[] = {
186
187 /* English. */
188 0x09, 0x04
189 };
190
191
192
193
194
195 /* Define the ISR dispatch. */
196
197 extern VOID (*test_isr_dispatch)(void);
198
199
200 /* Prototype for test control return. */
201
202 void test_control_return(UINT status);
203
204
205 /* Define the ISR dispatch routine. */
206
test_isr(void)207 static void test_isr(void)
208 {
209
210 /* For further expansion of interrupt-level testing. */
211 }
212
213
error_callback(UINT system_level,UINT system_context,UINT error_code)214 static VOID error_callback(UINT system_level, UINT system_context, UINT error_code)
215 {
216
217 /* Failed test. */
218 printf("Error on line %d, system_level: %d, system_context: %d, error code: %d\n", __LINE__, system_level, system_context, error_code);
219 test_control_return(1);
220 }
221
222 /* Define what the initial system looks like. */
223
224 #ifdef CTEST
test_application_define(void * first_unused_memory)225 void test_application_define(void *first_unused_memory)
226 #else
227 void usbx_storage_multi_lun_test_application_define(void *first_unused_memory)
228 #endif
229 {
230
231 UINT status;
232 CHAR * stack_pointer;
233 CHAR * memory_pointer;
234
235
236 /* Initialize FileX. */
237 fx_system_initialize();
238
239 /* Initialize the free memory pointer */
240 stack_pointer = (CHAR *) usbx_memory;
241 memory_pointer = stack_pointer + (UX_DEMO_STACK_SIZE * 2);
242
243 /* Initialize USBX. Memory */
244 status = ux_system_initialize(memory_pointer, UX_DEMO_MEMORY_SIZE, UX_NULL,0);
245
246 /* Check for error. */
247 if (status != UX_SUCCESS)
248 {
249
250 printf("Running Multiple LUN Storage Test................................... ERROR #1\n");
251 test_control_return(1);
252 }
253
254 /* Register the error callback. */
255 _ux_utility_error_callback_register(error_callback);
256
257 /* Reset ram disks memory. */
258 ux_utility_memory_set(ram_disk_memory1, 0, UX_RAM_DISK_SIZE);
259 ux_utility_memory_set(ram_disk_memory2, 0, UX_RAM_DISK_SIZE);
260
261 /* The code below is required for installing the device portion of USBX.
262 In this demo, DFU is possible and we have a call back for state change. */
263 status = ux_device_stack_initialize(device_framework_high_speed, DEVICE_FRAMEWORK_LENGTH_HIGH_SPEED,
264 device_framework_full_speed, DEVICE_FRAMEWORK_LENGTH_FULL_SPEED,
265 string_framework, STRING_FRAMEWORK_LENGTH,
266 language_id_framework, LANGUAGE_ID_FRAMEWORK_LENGTH,UX_NULL);
267 if(status!=UX_SUCCESS)
268 {
269
270 printf("Running Multiple LUN Storage Test................................... ERROR #5\n");
271 test_control_return(1);
272 }
273
274 /* Store the number of LUN in this device storage instance. */
275 global_storage_parameter.ux_slave_class_storage_parameter_number_lun = 2;
276
277 /* Initialize the storage class parameters for reading/writing to the first Flash Disk. */
278 global_storage_parameter.ux_slave_class_storage_parameter_lun[0].ux_slave_class_storage_media_last_lba = UX_RAM_DISK_LAST_LBA;
279 global_storage_parameter.ux_slave_class_storage_parameter_lun[0].ux_slave_class_storage_media_block_length = 512;
280 global_storage_parameter.ux_slave_class_storage_parameter_lun[0].ux_slave_class_storage_media_type = 0;
281 global_storage_parameter.ux_slave_class_storage_parameter_lun[0].ux_slave_class_storage_media_removable_flag = 0x80;
282 global_storage_parameter.ux_slave_class_storage_parameter_lun[0].ux_slave_class_storage_media_read = demo_thread_media_read1;
283 global_storage_parameter.ux_slave_class_storage_parameter_lun[0].ux_slave_class_storage_media_write = demo_thread_media_write1;
284 global_storage_parameter.ux_slave_class_storage_parameter_lun[0].ux_slave_class_storage_media_status = demo_thread_media_status1;
285
286 /* Initialize the storage class parameters for reading/writing to the second Flash Disk. */
287 global_storage_parameter.ux_slave_class_storage_parameter_lun[1].ux_slave_class_storage_media_last_lba = UX_RAM_DISK_LAST_LBA;
288 global_storage_parameter.ux_slave_class_storage_parameter_lun[1].ux_slave_class_storage_media_block_length = 512;
289 global_storage_parameter.ux_slave_class_storage_parameter_lun[1].ux_slave_class_storage_media_type = 0;
290 global_storage_parameter.ux_slave_class_storage_parameter_lun[1].ux_slave_class_storage_media_removable_flag = 0x80;
291 global_storage_parameter.ux_slave_class_storage_parameter_lun[1].ux_slave_class_storage_media_read = demo_thread_media_read2;
292 global_storage_parameter.ux_slave_class_storage_parameter_lun[1].ux_slave_class_storage_media_write = demo_thread_media_write2;
293 global_storage_parameter.ux_slave_class_storage_parameter_lun[1].ux_slave_class_storage_media_status = demo_thread_media_status2;
294
295 /* Initilize the device storage class. The class is connected with interface 0 on configuration 1. */
296 status = ux_device_stack_class_register(_ux_system_slave_class_storage_name, ux_device_class_storage_entry,
297 1, 0, (VOID *)&global_storage_parameter);
298 if(status!=UX_SUCCESS)
299 {
300
301 printf("Running Multiple LUN Storage Test................................... ERROR #6\n");
302 test_control_return(1);
303 }
304
305 /* Initialize the simulated device controller. */
306 status = _ux_dcd_sim_slave_initialize();
307
308 /* Check for error. */
309 if (status != UX_SUCCESS)
310 {
311
312 printf("Running Multiple LUN Storage Test................................... ERROR #7\n");
313 test_control_return(1);
314 }
315
316 /* The code below is required for installing the host portion of USBX */
317 status = ux_host_stack_initialize(ux_test_system_host_change_function);
318 if (status != UX_SUCCESS)
319 {
320
321 printf("Running Multiple LUN Storage Test................................... ERROR #2\n");
322 test_control_return(1);
323 }
324
325 /* Register storage class. */
326 status = ux_host_stack_class_register(_ux_system_host_class_storage_name, ux_host_class_storage_entry);
327 if (status != UX_SUCCESS)
328 {
329
330 printf("Running Multiple LUN Storage Test................................... ERROR #3\n");
331 test_control_return(1);
332 }
333
334 /* Register all the USB host controllers available in this system */
335 status = ux_host_stack_hcd_register(_ux_system_host_hcd_simulator_name, ux_hcd_sim_host_initialize,0,0);
336
337 /* Check for error. */
338 if (status != UX_SUCCESS)
339 {
340
341 printf("Running Multiple LUN Storage Test................................... ERROR #4\n");
342 test_control_return(1);
343 }
344
345 /* Create the main host simulation thread. */
346 status = tx_thread_create(&tx_demo_thread_host_simulation, "tx demo host simulation", tx_demo_thread_host_simulation_entry, 0,
347 stack_pointer, UX_DEMO_STACK_SIZE,
348 20, 20, 1, TX_AUTO_START);
349
350 /* Check for error. */
351 if (status != TX_SUCCESS)
352 {
353
354 printf("Running Multiple LUN Storage Test................................... ERROR #8\n");
355 test_control_return(1);
356 }
357
358 }
359
host_storage_instance_get(void)360 static UINT host_storage_instance_get(void)
361 {
362
363 UINT status;
364 UX_HOST_CLASS *class;
365
366
367 /* Find the main storage container */
368 status = ux_host_stack_class_get(_ux_system_host_class_storage_name, &class);
369 if (status != UX_SUCCESS)
370 return(status);
371
372 /* We get the first instance of the storage device */
373 do
374 {
375
376 status = ux_host_stack_class_instance_get(class, 0, (void **) &storage);
377 tx_thread_sleep(10);
378 } while (status != UX_SUCCESS);
379
380 /* We still need to wait for the storage status to be live */
381 while (storage -> ux_host_class_storage_state != UX_HOST_CLASS_INSTANCE_LIVE)
382 tx_thread_sleep(10);
383
384 /* We try to get the first media attached to the class container. */
385 while (class -> ux_host_class_media == UX_NULL)
386 {
387
388 tx_thread_sleep(10);
389 }
390
391 /* Setup media pointers. */
392 global_storage_media = (UX_HOST_CLASS_STORAGE_MEDIA *) class -> ux_host_class_media;
393
394 #if !defined(UX_HOST_CLASS_STORAGE_NO_FILEX)
395 media1 = &global_storage_media -> ux_host_class_storage_media;
396 media2 = &(global_storage_media+1) -> ux_host_class_storage_media;
397 #else
398 media1 = _ux_host_class_storage_media_fx_media(global_storage_media);
399 media2 = _ux_host_class_storage_media_fx_media(global_storage_media+1);
400 #endif
401
402 return(UX_SUCCESS);
403 }
404
405
tx_demo_thread_host_simulation_entry(ULONG arg)406 static void tx_demo_thread_host_simulation_entry(ULONG arg)
407 {
408
409 UINT status;
410 FX_FILE my_file;
411 ULONG error_count = 0;
412 ULONG total_length;
413 UCHAR buffer_pattern;
414
415
416 /* Inform user. */
417 printf("Running Multiple LUN Storage Test................................... ");
418
419 /* Format the ram drive 1. */
420 status = fx_media_format(&ram_disk1, _fx_ram_driver, ram_disk_memory1, buffer, 512, "RAM DISK", 2, 512, 0, UX_RAM_DISK_SIZE/512, 512, 4, 1, 1);
421
422 /* Check the media format status. */
423 if (status != FX_SUCCESS)
424 {
425
426 /* Multiple LUN Storage test error. */
427 printf("ERROR #9\n");
428 test_control_return(1);
429 }
430
431 /* Format the ram drive 2. */
432 status = fx_media_format(&ram_disk2, _fx_ram_driver, ram_disk_memory2, buffer, 512, "RAM DISK", 2, 512, 0, UX_RAM_DISK_SIZE/512, 512, 4, 1, 1);
433
434 /* Check the media format status. */
435 if (status != FX_SUCCESS)
436 {
437
438 /* Multiple LUN Storage test error. */
439 printf("ERROR #10\n");
440 test_control_return(1);
441 }
442
443
444 /* Open the ram_disk1 . */
445 status = fx_media_open(&ram_disk1, "RAM DISK", _fx_ram_driver, ram_disk_memory1, buffer, 512);
446
447 /* Check the media open status. */
448 if (status != FX_SUCCESS)
449 {
450
451 /* Multiple LUN Storage test error. */
452 printf("ERROR #11\n");
453 test_control_return(1);
454 }
455
456 /* Open the ram_disk2 . */
457 status = fx_media_open(&ram_disk2, "RAM DISK", _fx_ram_driver, ram_disk_memory2, buffer, 512);
458
459 /* Check the media open status. */
460 if (status != FX_SUCCESS)
461 {
462
463 /* Multiple LUN Storage test error. */
464 printf("ERROR #12\n");
465 test_control_return(1);
466 }
467
468
469 /* Find the storage class */
470 status = host_storage_instance_get();
471 if (status != UX_SUCCESS)
472 {
473
474 /* Multiple LUN Storage test error. */
475 printf("ERROR #13\n");
476 test_control_return(1);
477 }
478
479 /* Medfia 1. */
480 /* Delete the target file. */
481 status = fx_file_delete(media1, "FILE.CPY");
482
483 /* Create the file. */
484 status = fx_file_create(media1, "FILE.CPY");
485 if (status != UX_SUCCESS)
486 {
487
488 /* Multiple LUN Storage test error. */
489 printf("ERROR #14\n");
490 test_control_return(1);
491 }
492
493 memset(&my_file, 0, sizeof(my_file));
494
495 /* Open file for copying. */
496 status = fx_file_open(media1, &my_file, "FILE.CPY", FX_OPEN_FOR_WRITE);
497 if (status != UX_SUCCESS)
498 {
499
500 /* Multiple LUN Storage test error. */
501 printf("ERROR #15\n");
502 test_control_return(1);
503 }
504
505 /* Seek to the beginning to copy over an existing file. */
506 fx_file_seek(&my_file, 0);
507
508 /* Set the file length. */
509 total_length = UX_DEMO_FILE_SIZE;
510
511 /* Set pattern first letter. */
512 buffer_pattern = 'a';
513
514 while(total_length !=0)
515 {
516
517 /* Set the buffer with pattern. */
518 ux_utility_memory_set(global_buffer, buffer_pattern, UX_DEMO_FILE_BUFFER_SIZE);
519
520 /* Copy the file in blocks */
521 status = fx_file_write(&my_file, global_buffer, UX_DEMO_FILE_BUFFER_SIZE);
522
523 /* Check if status OK. */
524 if (status != UX_SUCCESS)
525 {
526
527 /* Multiple LUN Storage test error. */
528 printf("ERROR #16\n");
529 test_control_return(1);
530 }
531
532 /* Decrement the length remaining. */
533 total_length -= UX_DEMO_FILE_BUFFER_SIZE;
534
535 /* Next pattern. */
536 buffer_pattern++;
537
538 /* Check pattern end. */
539 if (buffer_pattern > 'z')
540
541 /* Back to beginning. */
542 buffer_pattern = 'a';
543
544 }
545 /* Finished reading file either at the end or because of error. */
546 fx_file_close(&my_file);
547
548 /* Media 2. */
549 /* Delete the target file. */
550 status = fx_file_delete(media2, "FILE.CPY");
551
552 /* Create the file. */
553 status = fx_file_create(media2, "FILE.CPY");
554 if (status != UX_SUCCESS)
555 {
556
557 /* Multiple LUN Storage test error. */
558 printf("ERROR #17\n");
559 test_control_return(1);
560 }
561
562 /* Open file for copying. */
563 status = fx_file_open(media2, &my_file, "FILE.CPY", FX_OPEN_FOR_WRITE);
564 if (status != UX_SUCCESS)
565 {
566
567 /* Multiple LUN Storage test error. */
568 printf("ERROR #18\n");
569 test_control_return(1);
570 }
571
572 /* Seek to the beginning to copy over an existing file. */
573 fx_file_seek(&my_file, 0);
574
575 /* Set the file length. */
576 total_length = UX_DEMO_FILE_SIZE;
577
578 /* Set pattern first letter. */
579 buffer_pattern = 'a';
580
581 while(total_length !=0)
582 {
583
584 /* Set the buffer with pattern. */
585 ux_utility_memory_set(global_buffer, buffer_pattern, UX_DEMO_FILE_BUFFER_SIZE);
586
587 /* Copy the file in blocks */
588 status = fx_file_write(&my_file, global_buffer, UX_DEMO_FILE_BUFFER_SIZE);
589
590 /* Check if status OK. */
591 if (status != UX_SUCCESS)
592 {
593
594 /* Multiple LUN Storage test error. */
595 printf("ERROR #19\n");
596 test_control_return(1);
597 }
598
599 /* Decrement the length remaining. */
600 total_length -= UX_DEMO_FILE_BUFFER_SIZE;
601
602 /* Next pattern. */
603 buffer_pattern++;
604
605 /* Check pattern end. */
606 if (buffer_pattern > 'z')
607
608 /* Back to beginning. */
609 buffer_pattern = 'a';
610
611 }
612 /* Finished reading file either at the end or because of error. */
613 fx_file_close(&my_file);
614
615 /* Successful test. */
616 printf("SUCCESS!\n");
617 test_control_return(0);
618 }
619
620
demo_thread_media_status1(VOID * storage,ULONG lun,ULONG media_id,ULONG * media_status)621 static UINT demo_thread_media_status1(VOID *storage, ULONG lun, ULONG media_id, ULONG *media_status)
622 {
623
624 /* The ATA drive never fails. This is just for demo only !!!! */
625 return(UX_SUCCESS);
626 }
627
demo_thread_media_read1(VOID * storage,ULONG lun,UCHAR * data_pointer,ULONG number_blocks,ULONG lba,ULONG * media_status)628 static UINT demo_thread_media_read1(VOID *storage, ULONG lun, UCHAR * data_pointer, ULONG number_blocks, ULONG lba, ULONG *media_status)
629 {
630
631 UINT status;
632
633 if(lba == 0)
634 {
635 ram_disk1.fx_media_driver_logical_sector = 0;
636 ram_disk1.fx_media_driver_sectors = 1;
637 ram_disk1.fx_media_driver_request = FX_DRIVER_BOOT_READ;
638 ram_disk1.fx_media_driver_buffer = data_pointer;
639 _fx_ram_driver(&ram_disk1);
640 *(data_pointer) = 0xeb;
641 *(data_pointer+1) = 0x3c;
642 *(data_pointer+2) = 0x90;
643 *(data_pointer+21) = 0xF8;
644
645 *(data_pointer+24) = 0x01;
646 *(data_pointer+26) = 0x10;
647 *(data_pointer+28) = 0x01;
648
649 *(data_pointer+510) = 0x55;
650 *(data_pointer+511) = 0xaa;
651 ux_utility_memory_copy(data_pointer+0x36,"FAT12",5);
652
653
654 status = ram_disk1.fx_media_driver_status;
655 }
656 else
657 {
658 while(number_blocks--)
659 {
660 status = fx_media_read(&ram_disk1,lba,data_pointer);
661 data_pointer+=512;
662 lba++;
663 }
664 }
665 return(status);
666 }
667
demo_thread_media_write1(VOID * storage,ULONG lun,UCHAR * data_pointer,ULONG number_blocks,ULONG lba,ULONG * media_status)668 static UINT demo_thread_media_write1(VOID *storage, ULONG lun, UCHAR * data_pointer, ULONG number_blocks, ULONG lba, ULONG *media_status)
669 {
670
671 UINT status;
672
673 if(lba == 0)
674 {
675 ram_disk1.fx_media_driver_logical_sector = 0;
676 ram_disk1.fx_media_driver_sectors = 1;
677 ram_disk1.fx_media_driver_request = FX_DRIVER_BOOT_WRITE;
678 ram_disk1.fx_media_driver_buffer = data_pointer;
679 _fx_ram_driver(&ram_disk1);
680
681 status = ram_disk1.fx_media_driver_status;
682
683 }
684 else
685 {
686
687 while(number_blocks--)
688 {
689 status = fx_media_write(&ram_disk1,lba,data_pointer);
690 data_pointer+=512;
691 lba++;
692 }
693 return(status);
694 }
695 return(1);
696 }
697
698
699
700
demo_thread_media_status2(VOID * storage,ULONG lun,ULONG media_id,ULONG * media_status)701 static UINT demo_thread_media_status2(VOID *storage, ULONG lun, ULONG media_id, ULONG *media_status)
702 {
703
704 /* The ATA drive never fails. This is just for demo only !!!! */
705 return(UX_SUCCESS);
706 }
707
demo_thread_media_read2(VOID * storage,ULONG lun,UCHAR * data_pointer,ULONG number_blocks,ULONG lba,ULONG * media_status)708 static UINT demo_thread_media_read2(VOID *storage, ULONG lun, UCHAR * data_pointer, ULONG number_blocks, ULONG lba, ULONG *media_status)
709 {
710
711 UINT status;
712
713 if(lba == 0)
714 {
715 ram_disk2.fx_media_driver_logical_sector = 0;
716 ram_disk2.fx_media_driver_sectors = 1;
717 ram_disk2.fx_media_driver_request = FX_DRIVER_BOOT_READ;
718 ram_disk2.fx_media_driver_buffer = data_pointer;
719 _fx_ram_driver(&ram_disk2);
720 *(data_pointer) = 0xeb;
721 *(data_pointer+1) = 0x3c;
722 *(data_pointer+2) = 0x90;
723 *(data_pointer+21) = 0xF8;
724
725 *(data_pointer+24) = 0x01;
726 *(data_pointer+26) = 0x10;
727 *(data_pointer+28) = 0x01;
728
729 *(data_pointer+510) = 0x55;
730 *(data_pointer+511) = 0xaa;
731 ux_utility_memory_copy(data_pointer+0x36,"FAT12",5);
732
733
734 status = ram_disk2.fx_media_driver_status;
735 }
736 else
737 {
738 while(number_blocks--)
739 {
740 status = fx_media_read(&ram_disk2,lba,data_pointer);
741 data_pointer+=512;
742 lba++;
743 }
744 }
745 return(status);
746 }
747
demo_thread_media_write2(VOID * storage,ULONG lun,UCHAR * data_pointer,ULONG number_blocks,ULONG lba,ULONG * media_status)748 static UINT demo_thread_media_write2(VOID *storage, ULONG lun, UCHAR * data_pointer, ULONG number_blocks, ULONG lba, ULONG *media_status)
749 {
750
751 UINT status;
752
753 if(lba == 0)
754 {
755 ram_disk2.fx_media_driver_logical_sector = 0;
756 ram_disk2.fx_media_driver_sectors = 1;
757 ram_disk2.fx_media_driver_request = FX_DRIVER_BOOT_WRITE;
758 ram_disk2.fx_media_driver_buffer = data_pointer;
759 _fx_ram_driver(&ram_disk2);
760
761 status = ram_disk2.fx_media_driver_status;
762
763 }
764 else
765 {
766
767 while(number_blocks--)
768 {
769 status = fx_media_write(&ram_disk2,lba,data_pointer);
770 data_pointer+=512;
771 lba++;
772 }
773 return(status);
774 }
775 return(1);
776 }
777
778