mirror of
https://github.com/eclipse-threadx/levelx.git
synced 2026-09-14 12:37:01 +08:00
Updated copyright headers and removed trailing whitespace
This commit is contained in:
@@ -1,18 +1,19 @@
|
||||
/***************************************************************************
|
||||
* Copyright (c) 2024 Microsoft Corporation
|
||||
*
|
||||
* Copyright (c) 2024 Microsoft Corporation
|
||||
* Copyright (c) 2026-present 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
|
||||
**************************************************************************/
|
||||
|
||||
|
||||
/**************************************************************************/
|
||||
/**************************************************************************/
|
||||
/** */
|
||||
/** FileX Component */
|
||||
/** */
|
||||
/** FileX Component */
|
||||
/** */
|
||||
/** FileX NAND FLASH Simulator Driver */
|
||||
/** */
|
||||
@@ -42,22 +43,22 @@ VOID _fx_nand_flash_write_sectors(ULONG logical_sector, ULONG sectors, UCHAR *s
|
||||
|
||||
|
||||
/* The simulated NAND driver relies on the fx_media_format call to be made prior to
|
||||
the fx_media_open call.
|
||||
the fx_media_open call.
|
||||
|
||||
fx_media_format(&ram_disk,
|
||||
fx_media_format(&ram_disk,
|
||||
_fx_nand_sim_driver, // Driver entry
|
||||
FX_NULL, // Unused
|
||||
media_memory, // Media buffer pointer
|
||||
sizeof(media_memory), // Media buffer size
|
||||
sizeof(media_memory), // Media buffer size
|
||||
"MY_NAND_DISK", // Volume Name
|
||||
1, // Number of FATs
|
||||
32, // Directory Entries
|
||||
0, // Hidden sectors
|
||||
120, // Total sectors
|
||||
2048, // Sector size
|
||||
120, // Total sectors
|
||||
2048, // Sector size
|
||||
1, // Sectors per cluster
|
||||
1, // Heads
|
||||
1); // Sectors per track
|
||||
1); // Sectors per track
|
||||
|
||||
*/
|
||||
|
||||
@@ -65,69 +66,56 @@ VOID _fx_nand_flash_write_sectors(ULONG logical_sector, ULONG sectors, UCHAR *s
|
||||
VOID _fx_nand_flash_simulator_driver(FX_MEDIA *media_ptr);
|
||||
|
||||
|
||||
/**************************************************************************/
|
||||
/* */
|
||||
/* FUNCTION RELEASE */
|
||||
/* */
|
||||
/* _fx_nand_simulator_driver PORTABLE C */
|
||||
/**************************************************************************/
|
||||
/* */
|
||||
/* FUNCTION RELEASE */
|
||||
/* */
|
||||
/* _fx_nand_simulator_driver PORTABLE C */
|
||||
/* 6.2.1 */
|
||||
/* AUTHOR */
|
||||
/* */
|
||||
/* William E. Lamie, Microsoft Corporation */
|
||||
/* */
|
||||
/* DESCRIPTION */
|
||||
/* */
|
||||
/* This function is the entry point to the generic NAND simulated */
|
||||
/* disk driver that is delivered with the flash wear leveling product */
|
||||
/* LevelX. */
|
||||
/* */
|
||||
/* This driver also serves as a template for developing other LevelX */
|
||||
/* NAND flash drivers for actual flash devices. Simply replace the */
|
||||
/* read/write sector logic with calls to read/write from the */
|
||||
/* appropriate physical device access functions. */
|
||||
/* */
|
||||
/* FileX NAND FLASH structures look like the following: */
|
||||
/* */
|
||||
/* Logical Sector Contents */
|
||||
/* */
|
||||
/* 0 Boot record */
|
||||
/* 1 FAT Area Start */
|
||||
/* +FAT Sectors Root Directory Start */
|
||||
/* +Directory Sectors Data Sector Start */
|
||||
/* */
|
||||
/* */
|
||||
/* INPUT */
|
||||
/* */
|
||||
/* media_ptr Media control block pointer */
|
||||
/* */
|
||||
/* OUTPUT */
|
||||
/* */
|
||||
/* None */
|
||||
/* */
|
||||
/* CALLS */
|
||||
/* */
|
||||
/* _lx_nand_flash_close Close NAND flash manager */
|
||||
/* _lx_nand_flash_open Open NAND flash manager */
|
||||
/* _lx_nand_flash_sector_read Read a NAND sector */
|
||||
/* _lx_nand_flash_sector_release Release a NAND sector */
|
||||
/* _lx_nand_flash_sector_write Write a NAND sector */
|
||||
/* */
|
||||
/* CALLED BY */
|
||||
/* */
|
||||
/* FileX System Functions */
|
||||
/* */
|
||||
/* RELEASE HISTORY */
|
||||
/* */
|
||||
/* DATE NAME DESCRIPTION */
|
||||
/* DESCRIPTION */
|
||||
/* */
|
||||
/* 05-19-2020 William E. Lamie Initial Version 6.0 */
|
||||
/* 09-30-2020 William E. Lamie Modified comment(s), */
|
||||
/* resulting in version 6.1 */
|
||||
/* 06-02-2021 Bhupendra Naphade Modified comment(s), */
|
||||
/* resulting in version 6.1.7 */
|
||||
/* 03-08-2023 Xiuwen Cai Modified comment(s), */
|
||||
/* changed to use new API, */
|
||||
/* resulting in version 6.2.1 */
|
||||
/* This function is the entry point to the generic NAND simulated */
|
||||
/* disk driver that is delivered with the flash wear leveling product */
|
||||
/* LevelX. */
|
||||
/* */
|
||||
/* This driver also serves as a template for developing other LevelX */
|
||||
/* NAND flash drivers for actual flash devices. Simply replace the */
|
||||
/* read/write sector logic with calls to read/write from the */
|
||||
/* appropriate physical device access functions. */
|
||||
/* */
|
||||
/* FileX NAND FLASH structures look like the following: */
|
||||
/* */
|
||||
/* Logical Sector Contents */
|
||||
/* */
|
||||
/* 0 Boot record */
|
||||
/* 1 FAT Area Start */
|
||||
/* +FAT Sectors Root Directory Start */
|
||||
/* +Directory Sectors Data Sector Start */
|
||||
/* */
|
||||
/* */
|
||||
/* INPUT */
|
||||
/* */
|
||||
/* media_ptr Media control block pointer */
|
||||
/* */
|
||||
/* OUTPUT */
|
||||
/* */
|
||||
/* None */
|
||||
/* */
|
||||
/* CALLS */
|
||||
/* */
|
||||
/* _lx_nand_flash_close Close NAND flash manager */
|
||||
/* _lx_nand_flash_open Open NAND flash manager */
|
||||
/* _lx_nand_flash_sector_read Read a NAND sector */
|
||||
/* _lx_nand_flash_sector_release Release a NAND sector */
|
||||
/* _lx_nand_flash_sector_write Write a NAND sector */
|
||||
/* */
|
||||
/* CALLED BY */
|
||||
/* */
|
||||
/* FileX System Functions */
|
||||
/* */
|
||||
/**************************************************************************/
|
||||
VOID _fx_nand_flash_simulator_driver(FX_MEDIA *media_ptr)
|
||||
@@ -137,19 +125,19 @@ ULONG logical_sector;
|
||||
ULONG count;
|
||||
UCHAR *buffer;
|
||||
UINT status;
|
||||
|
||||
|
||||
|
||||
/* There are several useful/important pieces of information contained in the media
|
||||
structure, some of which are supplied by FileX and others are for the driver to
|
||||
setup. The following is a summary of the necessary FX_MEDIA structure members:
|
||||
|
||||
|
||||
FX_MEDIA Member Meaning
|
||||
|
||||
fx_media_driver_request FileX request type. Valid requests from FileX are
|
||||
|
||||
fx_media_driver_request FileX request type. Valid requests from FileX are
|
||||
as follows:
|
||||
|
||||
FX_DRIVER_READ
|
||||
FX_DRIVER_WRITE
|
||||
FX_DRIVER_WRITE
|
||||
FX_DRIVER_FLUSH
|
||||
FX_DRIVER_ABORT
|
||||
FX_DRIVER_INIT
|
||||
@@ -158,11 +146,11 @@ UINT status;
|
||||
FX_DRIVER_BOOT_WRITE
|
||||
FX_DRIVER_UNINIT
|
||||
|
||||
fx_media_driver_status This value is RETURNED by the driver. If the
|
||||
fx_media_driver_status This value is RETURNED by the driver. If the
|
||||
operation is successful, this field should be
|
||||
set to FX_SUCCESS for before returning. Otherwise,
|
||||
if an error occurred, this field should be set
|
||||
to FX_IO_ERROR.
|
||||
to FX_IO_ERROR.
|
||||
|
||||
fx_media_driver_buffer Pointer to buffer to read or write sector data.
|
||||
This is supplied by FileX.
|
||||
@@ -173,24 +161,24 @@ UINT status;
|
||||
|
||||
|
||||
The following is a summary of the optional FX_MEDIA structure members:
|
||||
|
||||
|
||||
FX_MEDIA Member Meaning
|
||||
|
||||
|
||||
fx_media_driver_info Pointer to any additional information or memory.
|
||||
This is optional for the driver use and is setup
|
||||
from the fx_media_open call. The RAM disk uses
|
||||
this pointer for the RAM disk memory itself.
|
||||
|
||||
fx_media_driver_write_protect The DRIVER sets this to FX_TRUE when media is write
|
||||
protected. This is typically done in initialization,
|
||||
fx_media_driver_write_protect The DRIVER sets this to FX_TRUE when media is write
|
||||
protected. This is typically done in initialization,
|
||||
but can be done anytime.
|
||||
|
||||
fx_media_driver_free_sector_update The DRIVER sets this to FX_TRUE when it needs to
|
||||
fx_media_driver_free_sector_update The DRIVER sets this to FX_TRUE when it needs to
|
||||
know when clusters are released. This is important
|
||||
for FLASH wear-leveling drivers.
|
||||
|
||||
fx_media_driver_system_write FileX sets this flag to FX_TRUE if the sector being
|
||||
written is a system sector, e.g., a boot, FAT, or
|
||||
written is a system sector, e.g., a boot, FAT, or
|
||||
directory sector. The driver may choose to use this
|
||||
to initiate error recovery logic for greater fault
|
||||
tolerance.
|
||||
@@ -198,15 +186,15 @@ UINT status;
|
||||
fx_media_driver_data_sector_read FileX sets this flag to FX_TRUE if the sector(s) being
|
||||
read are file data sectors, i.e., NOT system sectors.
|
||||
|
||||
fx_media_driver_sector_type FileX sets this variable to the specific type of
|
||||
fx_media_driver_sector_type FileX sets this variable to the specific type of
|
||||
sector being read or written. The following sector
|
||||
types are identified:
|
||||
|
||||
FX_UNKNOWN_SECTOR
|
||||
FX_UNKNOWN_SECTOR
|
||||
FX_BOOT_SECTOR
|
||||
FX_FAT_SECTOR
|
||||
FX_DIRECTORY_SECTOR
|
||||
FX_DATA_SECTOR
|
||||
FX_DATA_SECTOR
|
||||
*/
|
||||
|
||||
/* Process the driver request specified in the media control block. */
|
||||
@@ -225,18 +213,18 @@ UINT status;
|
||||
|
||||
/* Call LevelX to read one flash sector. */
|
||||
status = _lx_nand_flash_sector_read(&nand_flash, logical_sector, buffer);
|
||||
|
||||
|
||||
/* Determine if the read was successful. */
|
||||
if (status != LX_SUCCESS)
|
||||
{
|
||||
|
||||
|
||||
/* Return an I/O error to FileX. */
|
||||
media_ptr -> fx_media_driver_status = FX_IO_ERROR;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
/* Successful sector read. */
|
||||
return;
|
||||
}
|
||||
|
||||
/* Successful sector read. */
|
||||
count--;
|
||||
logical_sector++;
|
||||
buffer += media_ptr -> fx_media_bytes_per_sector;
|
||||
@@ -245,12 +233,12 @@ UINT status;
|
||||
media_ptr -> fx_media_driver_status = FX_SUCCESS;
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
case FX_DRIVER_WRITE:
|
||||
{
|
||||
|
||||
/* Write sector(s) to NAND flash. */
|
||||
logical_sector = media_ptr -> fx_media_driver_logical_sector;
|
||||
logical_sector = media_ptr -> fx_media_driver_logical_sector;
|
||||
count = media_ptr -> fx_media_driver_sectors;
|
||||
buffer = (UCHAR *) media_ptr -> fx_media_driver_buffer;
|
||||
while (count)
|
||||
@@ -262,12 +250,12 @@ UINT status;
|
||||
/* Determine if the write was successful. */
|
||||
if (status != LX_SUCCESS)
|
||||
{
|
||||
|
||||
|
||||
/* Return an I/O error to FileX. */
|
||||
media_ptr -> fx_media_driver_status = FX_IO_ERROR;
|
||||
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/* Successful sector write. */
|
||||
count--;
|
||||
@@ -282,7 +270,7 @@ UINT status;
|
||||
|
||||
case FX_DRIVER_RELEASE_SECTORS:
|
||||
{
|
||||
|
||||
|
||||
/* Release the mapping of this sector. */
|
||||
logical_sector = media_ptr -> fx_media_driver_logical_sector;
|
||||
count = media_ptr -> fx_media_driver_sectors;
|
||||
@@ -295,18 +283,18 @@ UINT status;
|
||||
/* Determine if the sector release was successful. */
|
||||
if (status != LX_SUCCESS)
|
||||
{
|
||||
|
||||
|
||||
/* Return an I/O error to FileX. */
|
||||
media_ptr -> fx_media_driver_status = FX_IO_ERROR;
|
||||
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/* Successful sector release. */
|
||||
count--;
|
||||
logical_sector++;
|
||||
}
|
||||
|
||||
|
||||
/* Successful driver request. */
|
||||
media_ptr -> fx_media_driver_status = FX_SUCCESS;
|
||||
break;
|
||||
@@ -331,7 +319,7 @@ UINT status;
|
||||
case FX_DRIVER_INIT:
|
||||
{
|
||||
|
||||
/* FLASH drivers are responsible for setting several fields in the
|
||||
/* FLASH drivers are responsible for setting several fields in the
|
||||
media structure, as follows:
|
||||
|
||||
media_ptr -> fx_media_driver_free_sector_update
|
||||
@@ -339,7 +327,7 @@ UINT status;
|
||||
|
||||
The fx_media_driver_free_sector_update flag is used to instruct
|
||||
FileX to inform the driver whenever sectors are not being used.
|
||||
This is especially useful for FLASH managers so they don't have
|
||||
This is especially useful for FLASH managers so they don't have
|
||||
maintain mapping for sectors no longer in use.
|
||||
|
||||
The fx_media_driver_write_protect flag can be set anytime by the
|
||||
@@ -359,12 +347,12 @@ UINT status;
|
||||
/* Determine if the flash open was successful. */
|
||||
if (status != LX_SUCCESS)
|
||||
{
|
||||
|
||||
|
||||
/* Return an I/O error to FileX. */
|
||||
media_ptr -> fx_media_driver_status = FX_IO_ERROR;
|
||||
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/* Successful driver request. */
|
||||
media_ptr -> fx_media_driver_status = FX_SUCCESS;
|
||||
@@ -376,25 +364,25 @@ UINT status;
|
||||
|
||||
/* There is nothing to do in this case for the RAM driver. For actual
|
||||
devices some shutdown processing may be necessary. */
|
||||
|
||||
|
||||
/* Close the NAND flash simulation. */
|
||||
status = _lx_nand_flash_close(&nand_flash);
|
||||
|
||||
|
||||
/* Determine if the flash close was successful. */
|
||||
if (status != LX_SUCCESS)
|
||||
{
|
||||
|
||||
|
||||
/* Return an I/O error to FileX. */
|
||||
media_ptr -> fx_media_driver_status = FX_IO_ERROR;
|
||||
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/* Successful driver request. */
|
||||
media_ptr -> fx_media_driver_status = FX_SUCCESS;
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
case FX_DRIVER_BOOT_READ:
|
||||
{
|
||||
|
||||
@@ -404,13 +392,13 @@ UINT status;
|
||||
/* Determine if the read was successful. */
|
||||
if (status != LX_SUCCESS)
|
||||
{
|
||||
|
||||
|
||||
/* Return an I/O error to FileX. */
|
||||
media_ptr -> fx_media_driver_status = FX_IO_ERROR;
|
||||
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/* Successful driver request. */
|
||||
media_ptr -> fx_media_driver_status = FX_SUCCESS;
|
||||
break;
|
||||
@@ -425,12 +413,12 @@ UINT status;
|
||||
/* Determine if the write was successful. */
|
||||
if (status != LX_SUCCESS)
|
||||
{
|
||||
|
||||
|
||||
/* Return an I/O error to FileX. */
|
||||
media_ptr -> fx_media_driver_status = FX_IO_ERROR;
|
||||
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/* Successful driver request. */
|
||||
media_ptr -> fx_media_driver_status = FX_SUCCESS;
|
||||
|
||||
Reference in New Issue
Block a user