1 #ifndef FX_STANDALONE_ENABLE
2 #include "tx_api.h"
3 #include "tx_thread.h"
4 #endif
5 #include "fx_api.h"
6 #include "fx_utility.h"
7 #include "fx_ram_driver_test.h"
8 #include <stdio.h>
9 #include <string.h>
10
11 #define DEMO_STACK_SIZE 8192
12 /* Set the cache size as the size of one sector causing frequently IO operation. */
13 #define CACHE_SIZE 128
14 #define CACHE_SIZE1 512
15
16 #define VOLUME_LABEL "Vlabel"
17
18 /* Define the global variable we may use in the future. */
19 extern ULONG _fx_ram_driver_copy_default_format;
20 extern UCHAR large_file_name_format[];
21
22 /* Define the ThreadX and FileX object control blocks... */
23
24 #ifndef FX_STANDALONE_ENABLE
25 static TX_THREAD ftest_0;
26 #endif
27 static FX_MEDIA ram_disk;
28
29 /* Define the counters used in the test application... */
30
31 #ifndef FX_STANDALONE_ENABLE
32 static UCHAR *ram_disk_memory;
33 static UCHAR *cache_buffer;
34 static UCHAR *cache_buffer1;
35 #else
36 static UCHAR cache_buffer[CACHE_SIZE];
37 static UCHAR cache_buffer1[CACHE_SIZE1];
38 #endif
39
40 /* Define thread prototypes. */
41
42 void filex_media_volume_directory_entry_application_define(void *first_unused_memory);
43 static void ftest_0_entry(ULONG thread_input);
44
45 VOID _fx_ram_driver(FX_MEDIA *media_ptr);
46 void test_control_return(UINT status);
47
48 /* Define what the initial system looks like. */
49
50 #ifdef CTEST
test_application_define(void * first_unused_memory)51 void test_application_define(void *first_unused_memory)
52 #else
53 void filex_media_volume_directory_entry_application_define(void *first_unused_memory)
54 #endif
55 {
56
57 #ifndef FX_STANDALONE_ENABLE
58 UCHAR *pointer;
59
60
61 /* Setup the working pointer. */
62 pointer = (UCHAR *)first_unused_memory;
63
64 /* Create the main thread. */
65 tx_thread_create(&ftest_0, "thread 0", ftest_0_entry, 0,
66 pointer, DEMO_STACK_SIZE,
67 4, 4, TX_NO_TIME_SLICE, TX_AUTO_START);
68
69 pointer = pointer + DEMO_STACK_SIZE;
70
71 /* Setup memory for the RAM disk and the sector cache. */
72 cache_buffer = pointer;
73 pointer = pointer + CACHE_SIZE;
74 cache_buffer1 = pointer;
75 pointer = pointer + CACHE_SIZE1;
76 ram_disk_memory = pointer;
77
78 #endif
79
80 /* Initialize the FileX system. */
81 fx_system_initialize();
82 #ifdef FX_STANDALONE_ENABLE
83 ftest_0_entry(0);
84 #endif
85 }
86
87 static UCHAR specified_unicode_file_name[] = { 'Z', 0, '1', 0, '2', 0, '3', 0, '4', 0, '5', 0, '6', 0, '7', 0, '.', 0, 't', 0, 'x', 0, 't', 0, 0, 0 };
88
89 /* Define the test threads. */
90
ftest_0_entry(ULONG thread_input)91 static void ftest_0_entry(ULONG thread_input)
92 {
93 UINT status;
94 ULONG ulength;
95 UCHAR destination_name[128];
96 UCHAR name_buffer[128];
97
98 FX_PARAMETER_NOT_USED(thread_input);
99
100 /* Print out some test information banners. */
101 printf("FileX Test: Media volume directory entry test......................");
102
103 /* Format the media. This needs to be done before opening it! */
104 status = fx_media_format(&ram_disk,
105 _fx_ram_driver, // Driver entry
106 ram_disk_memory_large, // RAM disk memory pointer
107 cache_buffer, // Media buffer pointer
108 CACHE_SIZE, // Media buffer size
109 "MY_RAM_DISK", // Volume Name
110 1, // Number of FATs
111 32, // Directory Entries
112 0, // Hidden sectors
113 70000, // Total sectors
114 128, // Sector size
115 1, // Sectors per cluster
116 1, // Heads
117 1); // Sectors per track
118 return_if_fail( status == FX_SUCCESS);
119
120 status = fx_media_open(&ram_disk, "RAM DISK", _fx_ram_driver, ram_disk_memory_large, cache_buffer, CACHE_SIZE);
121 return_if_fail( status == FX_SUCCESS);
122
123 /* Create a file with long file name. */
124 ulength = fx_unicode_length_get( specified_unicode_file_name);
125 status = fx_unicode_file_create( &ram_disk, specified_unicode_file_name, ulength, (CHAR *)destination_name);
126 return_if_fail( status == FX_SUCCESS);
127
128 /* Set and get the volume name. */
129 status = fx_media_volume_set( &ram_disk, "NO NAME");
130 return_if_fail( status == FX_SUCCESS);
131
132 status = fx_media_volume_get( &ram_disk, (CHAR *)name_buffer, FX_DIRECTORY_SECTOR);
133 return_if_fail( ( status == FX_SUCCESS) && ( 0 == strcmp( (CHAR *)name_buffer, "NO NAME")));
134
135 status = fx_media_close( &ram_disk);
136 return_if_fail( status == FX_SUCCESS);
137
138 /* Test for creating direcoty with same name as volume" */
139
140 /* Format the media. This needs to be done before opening it! */
141 status = fx_media_format(&ram_disk,
142 _fx_ram_driver, // Driver entry
143 ram_disk_memory_large, // RAM disk memory pointer
144 cache_buffer, // Media buffer pointer
145 CACHE_SIZE, // Media buffer size
146 "MY_RAM_DISK", // Volume Name
147 1, // Number of FATs
148 32, // Directory Entries
149 0, // Hidden sectors
150 70000, // Total sectors
151 128, // Sector size
152 1, // Sectors per cluster
153 1, // Heads
154 1); // Sectors per track
155 return_if_fail( status == FX_SUCCESS);
156
157 status = fx_media_open(&ram_disk, "RAM DISK", _fx_ram_driver, ram_disk_memory_large, cache_buffer, CACHE_SIZE);
158 return_if_fail( status == FX_SUCCESS);
159
160 status = fx_media_volume_set(&ram_disk, VOLUME_LABEL);
161 return_if_fail( status == FX_SUCCESS);
162
163 status = fx_media_flush(&ram_disk);
164 return_if_fail( status == FX_SUCCESS);
165
166 status = fx_directory_create(&ram_disk, VOLUME_LABEL);
167 return_if_fail( status == FX_SUCCESS);
168
169 status = fx_media_flush(&ram_disk);
170 return_if_fail( status == FX_SUCCESS);
171
172 status = fx_media_close( &ram_disk);
173 return_if_fail( status == FX_SUCCESS);
174
175
176
177 printf("SUCCESS!\n");
178 test_control_return(0);
179 }
180