mirror of
https://github.com/azure-rtos/filex.git
synced 2025-01-25 01:32:54 +08:00
431 lines
13 KiB
C
431 lines
13 KiB
C
|
/* This FileX test concentrates on the utility FAT flush operation. */
|
||
|
|
||
|
#ifndef FX_STANDALONE_ENABLE
|
||
|
#include "tx_api.h"
|
||
|
#endif
|
||
|
#include "fx_api.h"
|
||
|
#include "fx_utility.h"
|
||
|
#include <stdio.h>
|
||
|
#include "fx_ram_driver_test.h"
|
||
|
|
||
|
#define DEMO_STACK_SIZE 4096
|
||
|
#define CACHE_SIZE 16*128
|
||
|
|
||
|
|
||
|
/* Define the ThreadX and FileX object control blocks... */
|
||
|
|
||
|
#ifndef FX_STANDALONE_ENABLE
|
||
|
static TX_THREAD ftest_0;
|
||
|
#endif
|
||
|
static FX_MEDIA ram_disk;
|
||
|
static FX_FILE my_file;
|
||
|
|
||
|
|
||
|
/* Define the counters used in the test application... */
|
||
|
|
||
|
#ifndef FX_STANDALONE_ENABLE
|
||
|
static UCHAR *ram_disk_memory;
|
||
|
static UCHAR *cache_buffer;
|
||
|
#else
|
||
|
static UCHAR cache_buffer[CACHE_SIZE];
|
||
|
#endif
|
||
|
|
||
|
|
||
|
/* Define thread prototypes. */
|
||
|
|
||
|
void filex_utility_fat_flush_application_define(void *first_unused_memory);
|
||
|
static void ftest_0_entry(ULONG thread_input);
|
||
|
|
||
|
VOID _fx_ram_driver(FX_MEDIA *media_ptr);
|
||
|
void test_control_return(UINT status);
|
||
|
|
||
|
|
||
|
|
||
|
/* Define what the initial system looks like. */
|
||
|
|
||
|
#ifdef CTEST
|
||
|
void test_application_define(void *first_unused_memory)
|
||
|
#else
|
||
|
void filex_utility_fat_flush_application_define(void *first_unused_memory)
|
||
|
#endif
|
||
|
{
|
||
|
|
||
|
#ifndef FX_STANDALONE_ENABLE
|
||
|
UCHAR *pointer;
|
||
|
|
||
|
|
||
|
/* Setup the working pointer. */
|
||
|
pointer = (UCHAR *) first_unused_memory;
|
||
|
|
||
|
/* Create the main thread. */
|
||
|
tx_thread_create(&ftest_0, "thread 0", ftest_0_entry, 0,
|
||
|
pointer, DEMO_STACK_SIZE,
|
||
|
4, 4, TX_NO_TIME_SLICE, TX_AUTO_START);
|
||
|
pointer = pointer + DEMO_STACK_SIZE;
|
||
|
|
||
|
/* Setup memory for the RAM disk and the sector cache. */
|
||
|
cache_buffer = pointer;
|
||
|
pointer = pointer + CACHE_SIZE;
|
||
|
ram_disk_memory = pointer;
|
||
|
#endif
|
||
|
|
||
|
/* Initialize the FileX system. */
|
||
|
fx_system_initialize();
|
||
|
|
||
|
#ifdef FX_STANDALONE_ENABLE
|
||
|
ftest_0_entry(0);
|
||
|
#endif
|
||
|
}
|
||
|
|
||
|
|
||
|
|
||
|
/* Define the test threads. */
|
||
|
|
||
|
static void ftest_0_entry(ULONG thread_input)
|
||
|
{
|
||
|
|
||
|
UINT status;
|
||
|
ULONG actual;
|
||
|
ULONG read_value;
|
||
|
ULONG write_value;
|
||
|
ULONG available_bytes;
|
||
|
ULONG i;
|
||
|
|
||
|
FX_PARAMETER_NOT_USED(thread_input);
|
||
|
|
||
|
/* Print out some test information banners. */
|
||
|
printf("FileX Test: Utility FAT flush test.......................................");
|
||
|
|
||
|
/* Format the media. This needs to be done before opening it! */
|
||
|
status = fx_media_format(&ram_disk,
|
||
|
_fx_ram_driver, // Driver entry
|
||
|
ram_disk_memory, // RAM disk memory pointer
|
||
|
cache_buffer, // Media buffer pointer
|
||
|
CACHE_SIZE, // Media buffer size
|
||
|
"MY_RAM_DISK", // Volume Name
|
||
|
1, // Number of FATs
|
||
|
32, // Directory Entries
|
||
|
0, // Hidden sectors
|
||
|
511, // Total sectors
|
||
|
128, // Sector size
|
||
|
1, // Sectors per cluster
|
||
|
1, // Heads
|
||
|
1); // Sectors per track
|
||
|
|
||
|
/* Determine if the format had an error. */
|
||
|
if (status)
|
||
|
{
|
||
|
|
||
|
printf("ERROR!\n");
|
||
|
test_control_return(2);
|
||
|
}
|
||
|
|
||
|
/* Open the ram_disk. */
|
||
|
status = fx_media_open(&ram_disk, "RAM DISK", _fx_ram_driver, ram_disk_memory, cache_buffer, CACHE_SIZE);
|
||
|
|
||
|
/* Check the status. */
|
||
|
if (status != FX_SUCCESS)
|
||
|
{
|
||
|
|
||
|
/* Error, return error code. */
|
||
|
printf("ERROR!\n");
|
||
|
test_control_return(21);
|
||
|
}
|
||
|
|
||
|
/* Create a file called TEST.TXT in the root directory. */
|
||
|
status = fx_file_create(&ram_disk, "TEST.TXT");
|
||
|
|
||
|
/* Check the create status. */
|
||
|
if (status != FX_SUCCESS)
|
||
|
{
|
||
|
|
||
|
printf("ERROR!\n");
|
||
|
test_control_return(3);
|
||
|
}
|
||
|
/* Open the test file. */
|
||
|
status = fx_file_open(&ram_disk, &my_file, "TEST.TXT", FX_OPEN_FOR_WRITE);
|
||
|
|
||
|
/* Check the file open status. */
|
||
|
if (status != FX_SUCCESS)
|
||
|
{
|
||
|
|
||
|
printf("ERROR!\n");
|
||
|
test_control_return(4);
|
||
|
}
|
||
|
|
||
|
/* Pickup the available bytes in the media. */
|
||
|
status = fx_media_space_available(&ram_disk, &available_bytes);
|
||
|
|
||
|
/* Check for available bytes error. */
|
||
|
if ((status != FX_SUCCESS) || (available_bytes < sizeof(ULONG)))
|
||
|
{
|
||
|
|
||
|
printf("ERROR!\n");
|
||
|
test_control_return(5);
|
||
|
}
|
||
|
|
||
|
/* Loop to write successive bytes out to the file.... to fill the media! */
|
||
|
i = 0;
|
||
|
write_value = 0;
|
||
|
while (i < available_bytes)
|
||
|
{
|
||
|
|
||
|
/* Write 4 bytes to the file. */
|
||
|
status = fx_file_write(&my_file, (void *) &write_value, sizeof(ULONG));
|
||
|
|
||
|
/* Check the file write status. */
|
||
|
if (status != FX_SUCCESS)
|
||
|
{
|
||
|
|
||
|
printf("ERROR!\n");
|
||
|
test_control_return(6);
|
||
|
}
|
||
|
|
||
|
/* Increment byte count. */
|
||
|
i = i + sizeof(ULONG);
|
||
|
|
||
|
/* Increment write value. */
|
||
|
write_value++;
|
||
|
}
|
||
|
|
||
|
/* Pickup the available bytes in the media again. */
|
||
|
status = fx_media_space_available(&ram_disk, &i);
|
||
|
|
||
|
/* Check for available bytes error. */
|
||
|
if ((status != FX_SUCCESS) || (i != 0))
|
||
|
{
|
||
|
|
||
|
printf("ERROR!\n");
|
||
|
test_control_return(7);
|
||
|
}
|
||
|
|
||
|
for (i = 0; i < FX_MAX_FAT_CACHE; i++)
|
||
|
{
|
||
|
ram_disk.fx_media_fat_cache[i].fx_fat_cache_entry_cluster = 496;
|
||
|
ram_disk.fx_media_fat_cache[i].fx_fat_cache_entry_value = 1;
|
||
|
ram_disk.fx_media_fat_cache[i].fx_fat_cache_entry_dirty = 1;
|
||
|
}
|
||
|
|
||
|
_fx_utility_FAT_flush(&ram_disk);
|
||
|
|
||
|
/* Note: If definition of FX_FAT_MAP_SIZE is changed in future, the value checked in
|
||
|
return_value_if_fail will change for individual array element */
|
||
|
for(i=0;i<FX_FAT_MAP_SIZE;i++)
|
||
|
{
|
||
|
return_value_if_fail((ram_disk.fx_media_fat_secondary_update_map[i]==63),8)
|
||
|
}
|
||
|
|
||
|
fx_media_close(&ram_disk);
|
||
|
|
||
|
/* Test with FAT 16 */
|
||
|
/* Format the media. This needs to be done before opening it! */
|
||
|
status = fx_media_format(&ram_disk,
|
||
|
_fx_ram_driver, // Driver entry
|
||
|
ram_disk_memory, // RAM disk memory pointer
|
||
|
cache_buffer, // Media buffer pointer
|
||
|
CACHE_SIZE, // Media buffer size
|
||
|
"MY_RAM_DISK", // Volume Name
|
||
|
1, // Number of FATs
|
||
|
32, // Directory Entries
|
||
|
0, // Hidden sectors
|
||
|
14000, // Total sectors - FAT16
|
||
|
64, // Sector size
|
||
|
2, // Sectors per cluster
|
||
|
1, // Heads
|
||
|
1); // Sectors per track
|
||
|
|
||
|
/* Determine if the format had an error. */
|
||
|
if (status)
|
||
|
{
|
||
|
|
||
|
printf("ERROR!\n");
|
||
|
test_control_return(2);
|
||
|
}
|
||
|
|
||
|
/* Open the ram_disk. */
|
||
|
status = fx_media_open(&ram_disk, "RAM DISK", _fx_ram_driver, ram_disk_memory, cache_buffer, CACHE_SIZE);
|
||
|
|
||
|
/* Check the status. */
|
||
|
if (status != FX_SUCCESS)
|
||
|
{
|
||
|
|
||
|
/* Error, return error code. */
|
||
|
printf("ERROR!\n");
|
||
|
test_control_return(21);
|
||
|
}
|
||
|
/* Create a file called TEST.TXT in the root directory. */
|
||
|
status = fx_file_create(&ram_disk, "TEST.TXT");
|
||
|
|
||
|
/* Check the create status. */
|
||
|
if (status != FX_SUCCESS)
|
||
|
{
|
||
|
|
||
|
printf("ERROR!\n");
|
||
|
test_control_return(3);
|
||
|
}
|
||
|
|
||
|
/* Open the test file. */
|
||
|
status = fx_file_open(&ram_disk, &my_file, "TEST.TXT", FX_OPEN_FOR_WRITE);
|
||
|
|
||
|
/* Check the file open status. */
|
||
|
if (status != FX_SUCCESS)
|
||
|
{
|
||
|
|
||
|
printf("ERROR!\n");
|
||
|
test_control_return(4);
|
||
|
}
|
||
|
|
||
|
/* Pickup the available bytes in the media. */
|
||
|
status = fx_media_space_available(&ram_disk, &available_bytes);
|
||
|
|
||
|
/* Check for available bytes error. */
|
||
|
if ((status != FX_SUCCESS) || (available_bytes < sizeof(ULONG)))
|
||
|
{
|
||
|
|
||
|
printf("ERROR!\n");
|
||
|
test_control_return(5);
|
||
|
}
|
||
|
|
||
|
/* Loop to write successive bytes out to the file.... to fill the media! */
|
||
|
i = 0;
|
||
|
write_value = 0;
|
||
|
while (i < available_bytes)
|
||
|
{
|
||
|
|
||
|
/* Write 4 bytes to the file. */
|
||
|
status = fx_file_write(&my_file, (void *) &write_value, sizeof(ULONG));
|
||
|
|
||
|
/* Check the file write status. */
|
||
|
if (status != FX_SUCCESS)
|
||
|
{
|
||
|
|
||
|
printf("ERROR!\n");
|
||
|
test_control_return(6);
|
||
|
}
|
||
|
|
||
|
/* Increment byte count. */
|
||
|
i = i + sizeof(ULONG);
|
||
|
|
||
|
/* Increment write value. */
|
||
|
write_value++;
|
||
|
}
|
||
|
|
||
|
/* Pickup the available bytes in the media again. */
|
||
|
status = fx_media_space_available(&ram_disk, &i);
|
||
|
|
||
|
/* Check for available bytes error. */
|
||
|
if ((status != FX_SUCCESS) || (i != 0))
|
||
|
{
|
||
|
|
||
|
printf("ERROR!\n");
|
||
|
test_control_return(7);
|
||
|
}
|
||
|
|
||
|
for (i = 0; i < FX_MAX_FAT_CACHE; i++)
|
||
|
{
|
||
|
ram_disk.fx_media_fat_cache[i].fx_fat_cache_entry_cluster = 0xA6;
|
||
|
ram_disk.fx_media_fat_cache[i].fx_fat_cache_entry_value = 1;
|
||
|
ram_disk.fx_media_fat_cache[i].fx_fat_cache_entry_dirty = 1;
|
||
|
}
|
||
|
|
||
|
_fx_utility_FAT_flush(&ram_disk);
|
||
|
|
||
|
/* Note: If definition of FX_FAT_MAP_SIZE is changed in future, the value checked in
|
||
|
return_value_if_fail will change for individual array element */
|
||
|
for(i=0;i<FX_FAT_MAP_SIZE;i++)
|
||
|
{
|
||
|
return_value_if_fail((ram_disk.fx_media_fat_secondary_update_map[i]==255),8)
|
||
|
}
|
||
|
|
||
|
fx_media_close(&ram_disk);
|
||
|
|
||
|
|
||
|
/* Test with FAT32. */
|
||
|
status = fx_media_format(&ram_disk,
|
||
|
_fx_ram_driver, // Driver entry
|
||
|
ram_disk_memory, // RAM disk memory pointer
|
||
|
cache_buffer, // Media buffer pointer
|
||
|
CACHE_SIZE, // Media buffer size
|
||
|
"MY_RAM_DISK", // Volume Name
|
||
|
1, // Number of FATs
|
||
|
32, // Directory Entries
|
||
|
0, // Hidden sectors
|
||
|
70000, // Total sectors - FAT32
|
||
|
512, // Sector size
|
||
|
1, // Sectors per cluster
|
||
|
1, // Heads
|
||
|
1); // Sectors per track
|
||
|
status += fx_media_open(&ram_disk, "RAM DISK", _fx_ram_driver, ram_disk_memory, cache_buffer, CACHE_SIZE);
|
||
|
status += fx_file_create(&ram_disk, "TEST.TXT");
|
||
|
return_if_fail(FX_SUCCESS == status);
|
||
|
|
||
|
/* Open the test file. */
|
||
|
status = fx_file_open(&ram_disk, &my_file, "TEST.TXT", FX_OPEN_FOR_WRITE);
|
||
|
|
||
|
/* Check the file open status. */
|
||
|
if (status != FX_SUCCESS)
|
||
|
{
|
||
|
|
||
|
printf("ERROR!\n");
|
||
|
test_control_return(4);
|
||
|
}
|
||
|
|
||
|
/* Pickup the available bytes in the media. */
|
||
|
status = fx_media_space_available(&ram_disk, &available_bytes);
|
||
|
|
||
|
/* Check for available bytes error. */
|
||
|
if ((status != FX_SUCCESS) || (available_bytes < sizeof(ULONG)))
|
||
|
{
|
||
|
|
||
|
printf("ERROR!\n");
|
||
|
test_control_return(5);
|
||
|
}
|
||
|
|
||
|
/* Loop to write successive bytes out to the file.... to fill the media! */
|
||
|
i = 0;
|
||
|
write_value = 0;
|
||
|
while (i < available_bytes/128)
|
||
|
{
|
||
|
|
||
|
/* Write 4 bytes to the file. */
|
||
|
status = fx_file_write(&my_file, (void *) &write_value, sizeof(ULONG));
|
||
|
|
||
|
/* Check the file write status. */
|
||
|
if (status != FX_SUCCESS)
|
||
|
{
|
||
|
|
||
|
printf("ERROR!\n");
|
||
|
test_control_return(6);
|
||
|
}
|
||
|
|
||
|
/* Increment byte count. */
|
||
|
i = i + sizeof(ULONG);
|
||
|
|
||
|
/* Increment write value. */
|
||
|
write_value++;
|
||
|
}
|
||
|
|
||
|
for (i = 0; i < FX_MAX_FAT_CACHE; i++)
|
||
|
{
|
||
|
ram_disk.fx_media_fat_cache[i].fx_fat_cache_entry_cluster = 0xF160;
|
||
|
ram_disk.fx_media_fat_cache[i].fx_fat_cache_entry_value = 1;
|
||
|
ram_disk.fx_media_fat_cache[i].fx_fat_cache_entry_dirty = 1;
|
||
|
}
|
||
|
|
||
|
_fx_utility_FAT_flush(&ram_disk);
|
||
|
|
||
|
/* Note: If definition of FX_FAT_MAP_SIZE is changed in future, the value checked in
|
||
|
return_value_if_fail will change for individual array element */
|
||
|
for(i=0;i<FX_FAT_MAP_SIZE;i++)
|
||
|
{
|
||
|
return_value_if_fail((ram_disk.fx_media_fat_secondary_update_map[i]==65),8)
|
||
|
}
|
||
|
|
||
|
fx_media_close(&ram_disk);
|
||
|
|
||
|
printf("SUCCESS!\n");
|
||
|
|
||
|
test_control_return(0);
|
||
|
|
||
|
}
|