1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
24
29
34
38
43
50
51
52
53
54
55
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
82
83
84
85
86
87
88
89
90
91
96
97
98
99
100
101
102
103
104
109
110
111
112
113
114
119
120
121
122
123
124
129
130
131
132
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
180
185
186
187
188
189
190
191
192
193
198
199
200
201
202
203
204
205
206
211
216
217
218
219
220
/* ... */
#include "app_filex.h"
Includes
#include "ux_api.h"
Private includes
Private typedef
Private define
Private macro
UCHAR Read_buffer[100];
UCHAR Write_buffer[] = "USBX_STM32_Host_Mass_Storage";
Private variables
/* ... */
UINT MX_FileX_Init(VOID *memory_ptr)
{
UINT ret = FX_SUCCESS;
TX_BYTE_POOL *byte_pool = (TX_BYTE_POOL*)memory_ptr;
(void)byte_pool;
fx_system_initialize();
return ret;
}{ ... }
/* ... */
UINT App_File_Write(FX_MEDIA *fx_media)
{
FX_FILE my_file;
UINT status;
status = fx_file_open(fx_media, &my_file, "TEST.TXT", FX_OPEN_FOR_WRITE);
if (status != FX_SUCCESS)
{
status = FX_IO_ERROR;
}if (status != FX_SUCCESS) { ... }
fx_file_seek(&my_file, 0);
status = fx_file_write(&my_file, Write_buffer, sizeof(Write_buffer));
if (status != FX_SUCCESS)
{
status = FX_IO_ERROR;
}if (status != FX_SUCCESS) { ... }
status = fx_file_close(&my_file);
if (status != FX_SUCCESS)
{
status = FX_IO_ERROR;
}if (status != FX_SUCCESS) { ... }
status = fx_media_flush(fx_media);
if (status != FX_SUCCESS)
{
status = FX_IO_ERROR;
}if (status != FX_SUCCESS) { ... }
return status ;
}{ ... }
/* ... */
UINT App_File_Read(FX_MEDIA *fx_media)
{
FX_FILE my_file;
ULONG requested_length;
UINT file_attribute;
UINT status;
file_attribute = 0;
status = fx_file_attributes_read(fx_media, "TEST.TXT", &file_attribute);
if (!(file_attribute & 0x18) && (status == FX_SUCCESS))
{
status = fx_file_open(fx_media, &my_file, "TEST.TXT", FX_OPEN_FOR_READ);
if (status == FX_SUCCESS)
{
fx_file_seek(&my_file, 0);
status = fx_file_read(&my_file, Read_buffer, sizeof(Read_buffer),
&requested_length);
if (status == FX_SUCCESS)
{
if (requested_length != sizeof(Write_buffer))
{
status = FX_IO_ERROR;
}if (requested_length != sizeof(Write_buffer)) { ... }
else
{
status = (_ux_utility_memory_compare(Write_buffer, Read_buffer,
sizeof(Write_buffer)));
}else { ... }
}if (status == FX_SUCCESS) { ... }
else
{
status = FX_IO_ERROR;
}else { ... }
fx_file_close(&my_file);
}if (status == FX_SUCCESS) { ... }
}if (!(file_attribute & 0x18) && (status == FX_SUCCESS)) { ... }
return status;
}{ ... }
/* ... */
UINT App_File_Create( FX_MEDIA *fx_media)
{
UINT status;
status = fx_file_create(fx_media, "TEST.TXT");
if ((status == FX_SUCCESS) || (status == FX_ALREADY_CREATED))
{
status = FX_SUCCESS;
}if ((status == FX_SUCCESS) || (status == FX_ALREADY_CREATED)) { ... }
else
{
status = FX_INVALID_STATE;
}else { ... }
return status;
}{ ... }
Private function prototypes