2 FreeRTOS V8.0.1 - Copyright (C) 2014 Real Time Engineers Ltd.
\r
5 FEATURES AND PORTS ARE ADDED TO FREERTOS ALL THE TIME. PLEASE VISIT
\r
6 http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION.
\r
8 ***************************************************************************
\r
10 * FreeRTOS tutorial books are available in pdf and paperback. *
\r
11 * Complete, revised, and edited pdf reference manuals are also *
\r
14 * Purchasing FreeRTOS documentation will not only help you, by *
\r
15 * ensuring you get running as quickly as possible and with an *
\r
16 * in-depth knowledge of how to use FreeRTOS, it will also help *
\r
17 * the FreeRTOS project to continue with its mission of providing *
\r
18 * professional grade, cross platform, de facto standard solutions *
\r
19 * for microcontrollers - completely free of charge! *
\r
21 * >>> See http://www.FreeRTOS.org/Documentation for details. <<< *
\r
23 * Thank you for using FreeRTOS, and thank you for your support! *
\r
25 ***************************************************************************
\r
28 This file is part of the FreeRTOS distribution.
\r
30 FreeRTOS is free software; you can redistribute it and/or modify it under
\r
31 the terms of the GNU General Public License (version 2) as published by the
\r
32 Free Software Foundation AND MODIFIED BY the FreeRTOS exception.
\r
34 >>>>>>NOTE<<<<<< The modification to the GPL is included to allow you to
\r
35 distribute a combined work that includes FreeRTOS without being obliged to
\r
36 provide the source code for proprietary components outside of the FreeRTOS
\r
39 FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY
\r
40 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
\r
41 FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
\r
42 details. You should have received a copy of the GNU General Public License
\r
43 and the FreeRTOS license exception along with FreeRTOS; if not itcan be
\r
44 viewed here: http://www.freertos.org/a00114.html and also obtained by
\r
45 writing to Real Time Engineers Ltd., contact details for whom are available
\r
46 on the FreeRTOS WEB site.
\r
50 ***************************************************************************
\r
52 * Having a problem? Start by reading the FAQ "My application does *
\r
53 * not run, what could be wrong?" *
\r
55 * http://www.FreeRTOS.org/FAQHelp.html *
\r
57 ***************************************************************************
\r
60 http://www.FreeRTOS.org - Documentation, books, training, latest versions,
\r
61 license and Real Time Engineers Ltd. contact details.
\r
63 http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,
\r
64 including FreeRTOS+Trace - an indispensable productivity tool, and our new
\r
65 fully thread aware and reentrant UDP/IP stack.
\r
67 http://www.OpenRTOS.com - Real Time Engineers ltd license FreeRTOS to High
\r
68 Integrity Systems, who sell the code with commercial support,
\r
69 indemnification and middleware, under the OpenRTOS brand.
\r
71 http://www.SafeRTOS.com - High Integrity Systems also provide a safety
\r
72 engineered and independently SIL3 certified version for use in safety and
\r
73 mission critical applications that require provable dependability.
\r
76 /*******************************************************************************
\r
77 * See the URL in the comments within main.c for the location of the online
\r
79 ******************************************************************************/
\r
81 /* Standard includes. */
\r
85 /* FreeRTOS includes. */
\r
86 #include "FreeRTOS.h"
\r
89 /* File system includes. */
\r
91 #include "api_mdriver_ram.h"
\r
93 /* 8.3 format, plus null terminator. */
\r
94 #define fsMAX_FILE_NAME_LEN 13
\r
96 /* The number of bytes read/written to the example files at a time. */
\r
97 #define fsRAM_BUFFER_SIZE 200
\r
99 /* The number of bytes written to the file that uses f_putc() and f_getc(). */
\r
100 #define fsPUTC_FILE_SIZE 100
\r
102 /* The number of files created in root. */
\r
103 #define fsROOT_FILES 3
\r
105 /*-----------------------------------------------------------*/
\r
108 * Creates and verifies different files on the volume, demonstrating the use of
\r
109 * various different API functions.
\r
111 void vCreateAndVerifySampleFiles( void );
\r
114 * Create a set of example files in the root directory of the volume using
\r
117 static void prvCreateDemoFilesUsing_f_write( void );
\r
120 * Use f_read() to read back and verify the files that were created by
\r
121 * prvCreateDemoFilesUsing_f_write().
\r
123 static void prvVerifyDemoFileUsing_f_read( void );
\r
126 * Create an example file in a sub-directory using f_putc().
\r
128 static void prvCreateDemoFileUsing_f_putc( void );
\r
131 * Use f_getc() to read back and verify the file that was created by
\r
132 * prvCreateDemoFileUsing_f_putc().
\r
134 static void prvVerifyDemoFileUsing_f_getc( void );
\r
136 /*-----------------------------------------------------------*/
\r
138 /* A buffer used to both create content to write to disk, and read content back
\r
139 from a disk. Note there is no mutual exclusion on this buffer. */
\r
140 static char cRAMBuffer[ fsRAM_BUFFER_SIZE ];
\r
142 /* Names of directories that are created. */
\r
143 static const char *pcRoot = "/", *pcDirectory1 = "SUB1", *pcDirectory2 = "SUB2", *pcFullPath = "/SUB1/SUB2";
\r
145 /*-----------------------------------------------------------*/
\r
147 void vCreateAndVerifySampleFiles( void )
\r
149 unsigned char ucStatus;
\r
151 /* First create the volume. */
\r
152 ucStatus = f_initvolume( ram_initfunc );
\r
154 /* It is expected that the volume is not formatted. */
\r
155 if( ucStatus == F_ERR_NOTFORMATTED )
\r
157 /* Format the created volume. */
\r
158 ucStatus = f_format( F_FAT12_MEDIA );
\r
161 if( ucStatus == F_NO_ERROR )
\r
163 /* Create a set of files using f_write(). */
\r
164 prvCreateDemoFilesUsing_f_write();
\r
166 /* Read back and verify the files that were created using f_write(). */
\r
167 prvVerifyDemoFileUsing_f_read();
\r
169 /* Create sub directories two deep then create a file using putc. */
\r
170 prvCreateDemoFileUsing_f_putc();
\r
172 /* Read back and verify the file created by
\r
173 prvCreateDemoFileUsing_f_putc(). */
\r
174 prvVerifyDemoFileUsing_f_getc();
\r
177 /*-----------------------------------------------------------*/
\r
179 static void prvCreateDemoFilesUsing_f_write( void )
\r
181 portBASE_TYPE xFileNumber, xWriteNumber;
\r
182 char cFileName[ fsMAX_FILE_NAME_LEN ];
\r
183 long lItemsWritten;
\r
186 /* Create fsROOT_FILES files. Each created file will be
\r
187 ( xFileNumber * fsRAM_BUFFER_SIZE ) bytes in length, and filled
\r
188 with a different repeating character. */
\r
189 for( xFileNumber = 1; xFileNumber <= fsROOT_FILES; xFileNumber++ )
\r
191 /* Generate a file name. */
\r
192 sprintf( cFileName, "root%03d.txt", ( int ) xFileNumber );
\r
194 /* Obtain the current working directory and print out the file name and
\r
195 the directory into which the file is being written. */
\r
196 f_getcwd( cRAMBuffer, fsRAM_BUFFER_SIZE );
\r
197 printf( "Creating file %s in %s\r\n", cFileName, cRAMBuffer );
\r
199 /* Open the file, creating the file if it does not already exist. */
\r
200 pxFile = f_open( cFileName, "w" );
\r
201 configASSERT( pxFile );
\r
203 /* Fill the RAM buffer with data that will be written to the file. This
\r
204 is just a repeating ascii character that indicates the file number. */
\r
205 memset( cRAMBuffer, ( int ) ( '0' + xFileNumber ), fsRAM_BUFFER_SIZE );
\r
207 /* Write the RAM buffer to the opened file a number of times. The
\r
208 number of times the RAM buffer is written to the file depends on the
\r
209 file number, so the length of each created file will be different. */
\r
210 for( xWriteNumber = 0; xWriteNumber < xFileNumber; xWriteNumber++ )
\r
212 lItemsWritten = f_write( cRAMBuffer, fsRAM_BUFFER_SIZE, 1, pxFile );
\r
213 configASSERT( lItemsWritten == 1 );
\r
216 /* Close the file so another file can be created. */
\r
220 /*-----------------------------------------------------------*/
\r
222 static void prvVerifyDemoFileUsing_f_read( void )
\r
224 portBASE_TYPE xFileNumber, xReadNumber;
\r
225 char cFileName[ fsMAX_FILE_NAME_LEN ];
\r
226 long lItemsRead, lChar;
\r
229 /* Read back the files that were created by
\r
230 prvCreateDemoFilesUsing_f_write(). */
\r
231 for( xFileNumber = 1; xFileNumber <= fsROOT_FILES; xFileNumber++ )
\r
233 /* Generate the file name. */
\r
234 sprintf( cFileName, "root%03d.txt", ( int ) xFileNumber );
\r
236 /* Obtain the current working directory and print out the file name and
\r
237 the directory from which the file is being read. */
\r
238 f_getcwd( cRAMBuffer, fsRAM_BUFFER_SIZE );
\r
239 printf( "Reading file %s from %s\r\n", cFileName, cRAMBuffer );
\r
241 /* Open the file for reading. */
\r
242 pxFile = f_open( cFileName, "r" );
\r
243 configASSERT( pxFile );
\r
245 /* Read the file into the RAM buffer, checking the file contents are as
\r
246 expected. The size of the file depends on the file number. */
\r
247 for( xReadNumber = 0; xReadNumber < xFileNumber; xReadNumber++ )
\r
249 /* Start with the RAM buffer clear. */
\r
250 memset( cRAMBuffer, 0x00, fsRAM_BUFFER_SIZE );
\r
252 lItemsRead = f_read( cRAMBuffer, fsRAM_BUFFER_SIZE, 1, pxFile );
\r
253 configASSERT( lItemsRead == 1 );
\r
255 /* Check the RAM buffer is filled with the expected data. Each
\r
256 file contains a different repeating ascii character that indicates
\r
257 the number of the file. */
\r
258 for( lChar = 0; lChar < fsRAM_BUFFER_SIZE; lChar++ )
\r
260 configASSERT( cRAMBuffer[ lChar ] == ( '0' + ( char ) xFileNumber ) );
\r
264 /* Close the file. */
\r
268 /*-----------------------------------------------------------*/
\r
270 static void prvCreateDemoFileUsing_f_putc( void )
\r
272 unsigned char ucReturn;
\r
273 int iByte, iReturned;
\r
275 char cFileName[ fsMAX_FILE_NAME_LEN ];
\r
277 /* Obtain and print out the working directory. */
\r
278 f_getcwd( cRAMBuffer, fsRAM_BUFFER_SIZE );
\r
279 printf( "In directory %s\r\n", cRAMBuffer );
\r
281 /* Create a sub directory. */
\r
282 ucReturn = f_mkdir( pcDirectory1 );
\r
283 configASSERT( ucReturn == F_NO_ERROR );
\r
285 /* Move into the created sub-directory. */
\r
286 ucReturn = f_chdir( pcDirectory1 );
\r
287 configASSERT( ucReturn == F_NO_ERROR );
\r
289 /* Obtain and print out the working directory. */
\r
290 f_getcwd( cRAMBuffer, fsRAM_BUFFER_SIZE );
\r
291 printf( "In directory %s\r\n", cRAMBuffer );
\r
293 /* Create a subdirectory in the new directory. */
\r
294 ucReturn = f_mkdir( pcDirectory2 );
\r
295 configASSERT( ucReturn == F_NO_ERROR );
\r
297 /* Move into the directory just created - now two directories down from
\r
299 ucReturn = f_chdir( pcDirectory2 );
\r
300 configASSERT( ucReturn == F_NO_ERROR );
\r
302 /* Obtain and print out the working directory. */
\r
303 f_getcwd( cRAMBuffer, fsRAM_BUFFER_SIZE );
\r
304 printf( "In directory %s\r\n", cRAMBuffer );
\r
305 configASSERT( strcmp( cRAMBuffer, pcFullPath ) == 0 );
\r
307 /* Generate the file name. */
\r
308 sprintf( cFileName, "%s.txt", pcDirectory2 );
\r
310 /* Print out the file name and the directory into which the file is being
\r
312 printf( "Writing file %s in %s\r\n", cFileName, cRAMBuffer );
\r
314 pxFile = f_open( cFileName, "w" );
\r
316 /* Create a file 1 byte at a time. The file is filled with incrementing
\r
317 ascii characters starting from '0'. */
\r
318 for( iByte = 0; iByte < fsPUTC_FILE_SIZE; iByte++ )
\r
320 iReturned = f_putc( ( ( int ) '0' + iByte ), pxFile );
\r
321 configASSERT( iReturned == ( ( int ) '0' + iByte ) );
\r
324 /* Finished so close the file. */
\r
327 /* Move back to the root directory. */
\r
328 ucReturn = f_chdir( "../.." );
\r
329 configASSERT( ucReturn == F_NO_ERROR );
\r
331 /* Obtain and print out the working directory. */
\r
332 f_getcwd( cRAMBuffer, fsRAM_BUFFER_SIZE );
\r
333 printf( "Back in root directory %s\r\n", cRAMBuffer );
\r
334 configASSERT( strcmp( cRAMBuffer, pcRoot ) == 0 );
\r
336 /*-----------------------------------------------------------*/
\r
338 static void prvVerifyDemoFileUsing_f_getc( void )
\r
340 unsigned char ucReturn;
\r
341 int iByte, iReturned;
\r
343 char cFileName[ fsMAX_FILE_NAME_LEN ];
\r
345 /* Move into the directory in which the file was created. */
\r
346 ucReturn = f_chdir( pcFullPath );
\r
347 configASSERT( ucReturn == F_NO_ERROR );
\r
349 /* Obtain and print out the working directory. */
\r
350 f_getcwd( cRAMBuffer, fsRAM_BUFFER_SIZE );
\r
351 printf( "Back in directory %s\r\n", cRAMBuffer );
\r
352 configASSERT( strcmp( cRAMBuffer, pcFullPath ) == 0 );
\r
354 /* Generate the file name. */
\r
355 sprintf( cFileName, "%s.txt", pcDirectory2 );
\r
357 /* Print out the file name and the directory from which the file is being
\r
359 printf( "Reading file %s in %s\r\n", cFileName, cRAMBuffer );
\r
361 /* This time the file is opened for reading. */
\r
362 pxFile = f_open( cFileName, "r" );
\r
364 /* Read the file 1 byte at a time. */
\r
365 for( iByte = 0; iByte < fsPUTC_FILE_SIZE; iByte++ )
\r
367 iReturned = f_getc( pxFile );
\r
368 configASSERT( iReturned == ( ( int ) '0' + iByte ) );
\r
371 /* Finished so close the file. */
\r
374 /* Move back to the root directory. */
\r
375 ucReturn = f_chdir( "../.." );
\r
376 configASSERT( ucReturn == F_NO_ERROR );
\r
378 /* Obtain and print out the working directory. */
\r
379 f_getcwd( cRAMBuffer, fsRAM_BUFFER_SIZE );
\r
380 printf( "Back in root directory %s\r\n", cRAMBuffer );
\r