Added error handling to the sample.

Signed-off-by: Frédéric Desbiens <frederic.desbiens@eclipse-foundation.org>
This commit is contained in:
Frédéric Desbiens
2025-07-21 12:38:46 -04:00
parent 9023227ba4
commit 8112cd45cc
+35 -10
View File
@@ -1,3 +1,15 @@
/***************************************************************************
* Copyright (c) 2024 Microsoft Corporation
* Copyright (c) 2025 Eclipse ThreadX contributors
*
* This program and the accompanying materials are made available under the
* terms of the MIT License which is available at
* https://opensource.org/licenses/MIT.
*
* SPDX-License-Identifier: MIT
**************************************************************************/
/* This is a small demo of the high-performance FileX FAT file system. It includes setup for
a small 34KB RAM disk and a loop that writes and reads a small file. */
#include "fx_api.h"
@@ -29,10 +41,12 @@ void thread_0_entry(ULONG thread_input);
/* Define FileX global data structures. */
#define TOTAL_SECTORS 256
#define SECTOR_SIZE 512
FX_MEDIA ram_disk;
FX_FILE my_file;
#ifndef FX_STANDALONE_ENABLE
CHAR *ram_disk_memory;
#else
@@ -102,8 +116,12 @@ CHAR local_buffer[30];
/* Format the RAM disk - the memory for the RAM disk was setup in
tx_application_define above. */
fx_media_format(&ram_disk,
tx_application_define above.
Important Note: The user must ensure there is enough RAM for the format
specified. Otherwise, memory corruption can occur.
*/
status = fx_media_format(&ram_disk,
_fx_ram_driver, // Driver entry
ram_disk_memory, // RAM disk memory pointer
media_memory, // Media buffer pointer
@@ -112,27 +130,34 @@ CHAR local_buffer[30];
1, // Number of FATs
32, // Directory Entries
0, // Hidden sectors
256, // Total sectors
512, // Sector size
TOTAL_SECTORS, // Total sectors
SECTOR_SIZE, // Sector size
8, // Sectors per cluster
1, // Heads
1); // Sectors per track
/* Determine if the RAM disk format was successful. */
if (status != FX_SUCCESS)
{
/* Error formatting the RAM disk. */
printf("HTTPS RAM disk format failed, error: %x\n", status);
return;
}
/* Loop to repeat the demo over and over! */
do
{
/* Open the RAM disk. */
status = fx_media_open(&ram_disk, "RAM DISK", _fx_ram_driver, ram_disk_memory, media_memory, sizeof(media_memory));
/* Check the media open status. */
/* Determine if the RAM disk open was successful. */
if (status != FX_SUCCESS)
{
/* Error, break the loop! */
break;
/* Error opening the RAM disk. */
printf("RAM disk open failed, error: %x\n", status);
return;
}
}
#ifdef FX_ENABLE_FAULT_TOLERANT
status = fx_fault_tolerant_enable(&ram_disk, fault_tolerant_memory, sizeof(fault_tolerant_memory));