Merge pull request #68 from fdesbiens/dev

Updated copyright headers and version number constants
This commit is contained in:
Frédéric Desbiens
2026-03-05 09:39:50 +01:00
committed by GitHub
71 changed files with 3127 additions and 3742 deletions
+41 -96
View File
@@ -1,19 +1,20 @@
/*************************************************************************** /***************************************************************************
* Copyright (c) 2024 Microsoft Corporation * Copyright (c) 2024 Microsoft Corporation
* Copyright (c) 2026-present Eclipse ThreadX contributors
* Portion Copyright (c) 2025 STMicroelectronics * Portion Copyright (c) 2025 STMicroelectronics
* *
* This program and the accompanying materials are made available under the * This program and the accompanying materials are made available under the
* terms of the MIT License which is available at * terms of the MIT License which is available at
* https://opensource.org/licenses/MIT. * https://opensource.org/licenses/MIT.
* *
* SPDX-License-Identifier: MIT * SPDX-License-Identifier: MIT
**************************************************************************/ **************************************************************************/
/**************************************************************************/ /**************************************************************************/
/**************************************************************************/ /**************************************************************************/
/** */ /** */
/** LevelX Component */ /** LevelX Component */
/** */ /** */
/** Application Interface (API) */ /** Application Interface (API) */
/** */ /** */
@@ -37,62 +38,6 @@
/* high-performance LevelX. All service prototypes and data structure */ /* high-performance LevelX. All service prototypes and data structure */
/* definitions are defined in this file. */ /* definitions are defined in this file. */
/* */ /* */
/* RELEASE HISTORY */
/* */
/* DATE NAME DESCRIPTION */
/* */
/* 05-19-2020 William E. Lamie Initial Version 6.0 */
/* 09-30-2020 William E. Lamie Modified comment(s), and */
/* updated product constants, */
/* resulting in version 6.1 */
/* 11-09-2020 William E. Lamie Modified comment(s), and */
/* added support for lx_user.h */
/* so user can specify values, */
/* resulting in version 6.1.2 */
/* 12-31-2020 William E. Lamie Modified comment(s), and */
/* updated product constants, */
/* resulting in version 6.1.3 */
/* 06-02-2021 Bhupendra Naphade Modified comment(s), */
/* added standalone support, */
/* resulting in version 6.1.7 */
/* 08-02-2021 William E. Lamie Modified comment(s), and */
/* updated product constants, */
/* resulting in version 6.1.8 */
/* 10-15-2021 Bhupendra Naphade Modified comment(s), */
/* updated configuration for */
/* nand flash */
/* resulting in version 6.1.9 */
/* 01-31-2022 Bhupendra Naphade Modified comment(s), */
/* updated include order for */
/* standalone mode, */
/* resulting in version 6.1.10 */
/* 04-25-2022 William E. Lamie Modified comment(s), and */
/* updated product constants, */
/* resulting in version 6.1.11 */
/* 07-29-2022 William E. Lamie Modified comment(s), and */
/* updated product constants, */
/* resulting in version 6.1.12 */
/* 10-31-2022 Xiuwen Cai Modified comment(s), and */
/* updated product constants, */
/* resulting in version 6.2.0 */
/* 03-08-2023 Xiuwen Cai Modified comment(s), */
/* modified NAND logic, */
/* added new driver interface */
/* and user extension, */
/* resulting in version 6.2.1 */
/* 10-31-2023 Xiuwen Cai Modified comment(s), */
/* made LX_NOR_SECTOR_SIZE */
/* configurable, added mapping */
/* bitmap and obsolete count */
/* cache for NOR flash, */
/* resulting in version 6.3.0 */
/* 12-31-2023 Xiuwen Cai Modified comment(s), */
/* added configuration checks, */
/* resulting in version 6.4.0 */
/* 03-01-2024 Tiejun Zhou Modified comment(s), */
/* update version number, */
/* resulting in version 6.4.1 */
/* */
/**************************************************************************/ /**************************************************************************/
#ifndef LX_API_H #ifndef LX_API_H
@@ -114,7 +59,7 @@ extern "C" {
#ifdef LX_INCLUDE_USER_DEFINE_FILE #ifdef LX_INCLUDE_USER_DEFINE_FILE
/* Yes, include the user defines in lx_user.h. The defines in this file may /* Yes, include the user defines in lx_user.h. The defines in this file may
alternately be defined on the command line. */ alternately be defined on the command line. */
#include "lx_user.h" #include "lx_user.h"
@@ -203,9 +148,9 @@ typedef unsigned long long ULONG64;
/* Define basic constants for the LevelX Stack. */ /* Define basic constants for the LevelX Stack. */
#define AZURE_RTOS_LEVELX #define AZURE_RTOS_LEVELX
#define LEVELX_MAJOR_VERSION 6 #define LEVELX_MAJOR_VERSION 6
#define LEVELX_MINOR_VERSION 4 #define LEVELX_MINOR_VERSION 5
#define LEVELX_PATCH_VERSION 5 #define LEVELX_PATCH_VERSION 0
#define LEVELX_BUILD_VERSION 202504 #define LEVELX_BUILD_VERSION 202601
#define LEVELX_HOTFIX_VERSION ' ' #define LEVELX_HOTFIX_VERSION ' '
@@ -240,7 +185,7 @@ typedef unsigned long long ULONG64;
#define LX_SYSTEM_INVALID_BLOCK 91 #define LX_SYSTEM_INVALID_BLOCK 91
#define LX_SYSTEM_ALLOCATION_FAILED 92 #define LX_SYSTEM_ALLOCATION_FAILED 92
#define LX_SYSTEM_MUTEX_CREATE_FAILED 93 #define LX_SYSTEM_MUTEX_CREATE_FAILED 93
#define LX_SYSTEM_INVALID_SECTOR_MAP 94 #define LX_SYSTEM_INVALID_SECTOR_MAP 94
/* Define NOR flash constants. */ /* Define NOR flash constants. */
@@ -269,9 +214,9 @@ typedef unsigned long long ULONG64;
#endif #endif
/* Define the mask for the hash index into the sector mapping cache table. The sector mapping cache is divided /* Define the mask for the hash index into the sector mapping cache table. The sector mapping cache is divided
into 4 entry pieces that are indexed by the formula: into 4 entry pieces that are indexed by the formula:
index = (sector & LX_NOR_SECTOR_MAPPING_CACHE_HASH_MASK) * LX_NOR_SECTOR_MAPPING_CACHE_DEPTH index = (sector & LX_NOR_SECTOR_MAPPING_CACHE_HASH_MASK) * LX_NOR_SECTOR_MAPPING_CACHE_DEPTH
The LX_NOR_SECTOR_MAPPING_CACHE_DEPTH define must not be changed unless the related source code is also changed. */ The LX_NOR_SECTOR_MAPPING_CACHE_DEPTH define must not be changed unless the related source code is also changed. */
@@ -312,22 +257,22 @@ typedef unsigned long long ULONG64;
/* Define the NAND sector mapping cache. */ /* Define the NAND sector mapping cache. */
#define LX_NAND_SECTOR_MAPPING_CACHE_DEPTH 4 /* Not required if LX_NAND_FLASH_DIRECT_MAPPING_CACHE is defined. */ #define LX_NAND_SECTOR_MAPPING_CACHE_DEPTH 4 /* Not required if LX_NAND_FLASH_DIRECT_MAPPING_CACHE is defined. */
#ifndef LX_NAND_SECTOR_MAPPING_CACHE_SIZE #ifndef LX_NAND_SECTOR_MAPPING_CACHE_SIZE
#define LX_NAND_SECTOR_MAPPING_CACHE_SIZE 128 /* Minimum value of 8, all sizes must be a power of 2, unless direct #define LX_NAND_SECTOR_MAPPING_CACHE_SIZE 128 /* Minimum value of 8, all sizes must be a power of 2, unless direct
mapping is defined, in which there is no power of 2 requirement. */ mapping is defined, in which there is no power of 2 requirement. */
#endif #endif
#ifndef LX_NAND_ERASE_COUNT_WRITE_SIZE #ifndef LX_NAND_ERASE_COUNT_WRITE_SIZE
#define LX_NAND_ERASE_COUNT_WRITE_SIZE (nand_flash -> lx_nand_flash_pages_per_block + 1) #define LX_NAND_ERASE_COUNT_WRITE_SIZE (nand_flash -> lx_nand_flash_pages_per_block + 1)
#endif #endif
#ifndef LX_NAND_FLASH_MAPPING_LIST_UPDATE_DISABLE #ifndef LX_NAND_FLASH_MAPPING_LIST_UPDATE_DISABLE
#define LX_NAND_FLASH_MAPPING_LIST_UPDATE_DISABLE #define LX_NAND_FLASH_MAPPING_LIST_UPDATE_DISABLE
#endif #endif
#ifndef LX_NAND_FLASH_MAX_METADATA_BLOCKS #ifndef LX_NAND_FLASH_MAX_METADATA_BLOCKS
#define LX_NAND_FLASH_MAX_METADATA_BLOCKS 4 #define LX_NAND_FLASH_MAX_METADATA_BLOCKS 4
#endif #endif
#ifndef LX_UTILITY_SHORT_SET #ifndef LX_UTILITY_SHORT_SET
#define LX_UTILITY_SHORT_SET(address, value) *((USHORT*)(address)) = (USHORT)(value) #define LX_UTILITY_SHORT_SET(address, value) *((USHORT*)(address)) = (USHORT)(value)
@@ -345,9 +290,9 @@ typedef unsigned long long ULONG64;
#define LX_UTILITY_LONG_GET(address) (*((ULONG*)(address))) #define LX_UTILITY_LONG_GET(address) (*((ULONG*)(address)))
#endif #endif
/* Define the mask for the hash index into the NAND sector mapping cache table. The sector mapping cache is divided /* Define the mask for the hash index into the NAND sector mapping cache table. The sector mapping cache is divided
into 4 entry pieces that are indexed by the formula: into 4 entry pieces that are indexed by the formula:
index = (sector & LX_NAND_SECTOR_MAPPING_CACHE_HASH_MASK) * LX_NAND_SECTOR_MAPPING_CACHE_DEPTH index = (sector & LX_NAND_SECTOR_MAPPING_CACHE_HASH_MASK) * LX_NAND_SECTOR_MAPPING_CACHE_DEPTH
The LX_NAND_SECTOR_MAPPING_CACHE_DEPTH define must not be changed unless the related source code is also changed. */ The LX_NAND_SECTOR_MAPPING_CACHE_DEPTH define must not be changed unless the related source code is also changed. */
@@ -422,7 +367,7 @@ typedef struct LX_NAND_DEVICE_INFO_STRUCT
} LX_NAND_DEVICE_INFO; } LX_NAND_DEVICE_INFO;
/* Determine if the flash control block has an extension defined. If not, /* Determine if the flash control block has an extension defined. If not,
define the extension to whitespace. */ define the extension to whitespace. */
#ifndef LX_NAND_FLASH_USER_EXTENSION #ifndef LX_NAND_FLASH_USER_EXTENSION
@@ -509,7 +454,7 @@ typedef struct LX_NAND_FLASH_STRUCT
UINT (*lx_nand_flash_driver_extra_bytes_get)(struct LX_NAND_FLASH_STRUCT *nand_flash, ULONG block, ULONG page, UCHAR *destination, UINT size); UINT (*lx_nand_flash_driver_extra_bytes_get)(struct LX_NAND_FLASH_STRUCT *nand_flash, ULONG block, ULONG page, UCHAR *destination, UINT size);
UINT (*lx_nand_flash_driver_extra_bytes_set)(struct LX_NAND_FLASH_STRUCT *nand_flash, ULONG block, ULONG page, UCHAR *source, UINT size); UINT (*lx_nand_flash_driver_extra_bytes_set)(struct LX_NAND_FLASH_STRUCT *nand_flash, ULONG block, ULONG page, UCHAR *source, UINT size);
UINT (*lx_nand_flash_driver_system_error)(struct LX_NAND_FLASH_STRUCT *nand_flash, UINT error_code, ULONG block, ULONG page); UINT (*lx_nand_flash_driver_system_error)(struct LX_NAND_FLASH_STRUCT *nand_flash, UINT error_code, ULONG block, ULONG page);
UINT (*lx_nand_flash_driver_pages_read)(struct LX_NAND_FLASH_STRUCT *nand_flash, ULONG block, ULONG page, UCHAR* main_buffer, UCHAR* spare_buffer, ULONG pages); UINT (*lx_nand_flash_driver_pages_read)(struct LX_NAND_FLASH_STRUCT *nand_flash, ULONG block, ULONG page, UCHAR* main_buffer, UCHAR* spare_buffer, ULONG pages);
UINT (*lx_nand_flash_driver_pages_write)(struct LX_NAND_FLASH_STRUCT *nand_flash, ULONG block, ULONG page, UCHAR* main_buffer, UCHAR* spare_buffer, ULONG pages); UINT (*lx_nand_flash_driver_pages_write)(struct LX_NAND_FLASH_STRUCT *nand_flash, ULONG block, ULONG page, UCHAR* main_buffer, UCHAR* spare_buffer, ULONG pages);
UINT (*lx_nand_flash_driver_pages_copy)(struct LX_NAND_FLASH_STRUCT *nand_flash, ULONG source_block, ULONG source_page, ULONG destination_block, ULONG destination_page, ULONG pages, UCHAR* data_buffer); UINT (*lx_nand_flash_driver_pages_copy)(struct LX_NAND_FLASH_STRUCT *nand_flash, ULONG source_block, ULONG source_page, ULONG destination_block, ULONG destination_page, ULONG pages, UCHAR* data_buffer);
@@ -524,7 +469,7 @@ typedef struct LX_NAND_FLASH_STRUCT
UINT (*lx_nand_flash_driver_extra_bytes_get)(ULONG block, ULONG page, UCHAR *destination, UINT size); UINT (*lx_nand_flash_driver_extra_bytes_get)(ULONG block, ULONG page, UCHAR *destination, UINT size);
UINT (*lx_nand_flash_driver_extra_bytes_set)(ULONG block, ULONG page, UCHAR *source, UINT size); UINT (*lx_nand_flash_driver_extra_bytes_set)(ULONG block, ULONG page, UCHAR *source, UINT size);
UINT (*lx_nand_flash_driver_system_error)(UINT error_code, ULONG block, ULONG page); UINT (*lx_nand_flash_driver_system_error)(UINT error_code, ULONG block, ULONG page);
UINT (*lx_nand_flash_driver_pages_read)(ULONG block, ULONG page, UCHAR* main_buffer, UCHAR* spare_buffer, ULONG pages); UINT (*lx_nand_flash_driver_pages_read)(ULONG block, ULONG page, UCHAR* main_buffer, UCHAR* spare_buffer, ULONG pages);
UINT (*lx_nand_flash_driver_pages_write)(ULONG block, ULONG page, UCHAR* main_buffer, UCHAR* spare_buffer, ULONG pages); UINT (*lx_nand_flash_driver_pages_write)(ULONG block, ULONG page, UCHAR* main_buffer, UCHAR* spare_buffer, ULONG pages);
UINT (*lx_nand_flash_driver_pages_copy)(ULONG source_block, ULONG source_page, ULONG destination_block, ULONG destination_page, ULONG pages, UCHAR* data_buffer); UINT (*lx_nand_flash_driver_pages_copy)(ULONG source_block, ULONG source_page, ULONG destination_block, ULONG destination_page, ULONG pages, UCHAR* data_buffer);
@@ -538,17 +483,17 @@ typedef struct LX_NAND_FLASH_STRUCT
a higher layer. */ a higher layer. */
TX_MUTEX lx_nand_flash_mutex; TX_MUTEX lx_nand_flash_mutex;
#endif #endif
/* user data pointer optionally passed by the application to the driver via the lx_nand_flash_open_extended */ /* user data pointer optionally passed by the application to the driver via the lx_nand_flash_open_extended */
VOID *lx_nand_flash_driver_info_ptr; VOID *lx_nand_flash_driver_info_ptr;
/* Define the NAND flash control block open next/previous pointers. */ /* Define the NAND flash control block open next/previous pointers. */
struct LX_NAND_FLASH_STRUCT *lx_nand_flash_open_next, struct LX_NAND_FLASH_STRUCT *lx_nand_flash_open_next,
*lx_nand_flash_open_previous; *lx_nand_flash_open_previous;
/* Define the user extension in the flash control block. This /* Define the user extension in the flash control block. This
is typically defined in lx_user.h. */ is typically defined in lx_user.h. */
LX_NAND_FLASH_USER_EXTENSION LX_NAND_FLASH_USER_EXTENSION
} LX_NAND_FLASH; } LX_NAND_FLASH;
@@ -558,7 +503,7 @@ typedef struct LX_NAND_FLASH_STRUCT
typedef struct LX_NOR_SECTOR_MAPPING_CACHE_ENTRY_STRUCT typedef struct LX_NOR_SECTOR_MAPPING_CACHE_ENTRY_STRUCT
{ {
ULONG lx_nor_sector_mapping_cache_logical_sector; ULONG lx_nor_sector_mapping_cache_logical_sector;
ULONG *lx_nor_sector_mapping_cache_physical_sector_map_entry; ULONG *lx_nor_sector_mapping_cache_physical_sector_map_entry;
ULONG *lx_nor_sector_mapping_cache_physical_sector_address; ULONG *lx_nor_sector_mapping_cache_physical_sector_address;
} LX_NOR_SECTOR_MAPPING_CACHE_ENTRY; } LX_NOR_SECTOR_MAPPING_CACHE_ENTRY;
@@ -567,13 +512,13 @@ typedef struct LX_NOR_SECTOR_MAPPING_CACHE_ENTRY_STRUCT
typedef struct LX_NOR_FLASH_EXTENDED_CACHE_ENTRY_STRUCT typedef struct LX_NOR_FLASH_EXTENDED_CACHE_ENTRY_STRUCT
{ {
ULONG *lx_nor_flash_extended_cache_entry_sector_address; ULONG *lx_nor_flash_extended_cache_entry_sector_address;
ULONG *lx_nor_flash_extended_cache_entry_sector_memory; ULONG *lx_nor_flash_extended_cache_entry_sector_memory;
ULONG lx_nor_flash_extended_cache_entry_access_count; ULONG lx_nor_flash_extended_cache_entry_access_count;
} LX_NOR_FLASH_EXTENDED_CACHE_ENTRY; } LX_NOR_FLASH_EXTENDED_CACHE_ENTRY;
/* Determine if the flash control block has an extension defined. If not, /* Determine if the flash control block has an extension defined. If not,
define the extension to whitespace. */ define the extension to whitespace. */
#ifndef LX_NOR_FLASH_USER_EXTENSION #ifndef LX_NOR_FLASH_USER_EXTENSION
@@ -606,7 +551,7 @@ typedef struct LX_NOR_FLASH_STRUCT
ULONG lx_nor_flash_free_block_search; ULONG lx_nor_flash_free_block_search;
ULONG lx_nor_flash_found_block_search; ULONG lx_nor_flash_found_block_search;
ULONG lx_nor_flash_found_sector_search; ULONG lx_nor_flash_found_sector_search;
ULONG lx_nor_flash_write_requests; ULONG lx_nor_flash_write_requests;
ULONG lx_nor_flash_read_requests; ULONG lx_nor_flash_read_requests;
@@ -642,7 +587,7 @@ typedef struct LX_NOR_FLASH_STRUCT
ULONG *lx_nor_flash_sector_buffer; ULONG *lx_nor_flash_sector_buffer;
UINT lx_nor_flash_sector_mapping_cache_enabled; UINT lx_nor_flash_sector_mapping_cache_enabled;
LX_NOR_SECTOR_MAPPING_CACHE_ENTRY LX_NOR_SECTOR_MAPPING_CACHE_ENTRY
lx_nor_flash_sector_mapping_cache[LX_NOR_SECTOR_MAPPING_CACHE_SIZE]; lx_nor_flash_sector_mapping_cache[LX_NOR_SECTOR_MAPPING_CACHE_SIZE];
#ifndef LX_NOR_DISABLE_EXTENDED_CACHE #ifndef LX_NOR_DISABLE_EXTENDED_CACHE
@@ -660,7 +605,7 @@ typedef struct LX_NOR_FLASH_STRUCT
LX_NOR_OBSOLETE_COUNT_CACHE_TYPE LX_NOR_OBSOLETE_COUNT_CACHE_TYPE
*lx_nor_flash_extended_cache_obsolete_count; *lx_nor_flash_extended_cache_obsolete_count;
ULONG lx_nor_flash_extended_cache_obsolete_count_max_block; ULONG lx_nor_flash_extended_cache_obsolete_count_max_block;
#endif #endif
#endif #endif
#ifdef LX_THREAD_SAFE_ENABLE #ifdef LX_THREAD_SAFE_ENABLE
@@ -675,8 +620,8 @@ typedef struct LX_NOR_FLASH_STRUCT
/* Define the NOR flash control block open next/previous pointers. */ /* Define the NOR flash control block open next/previous pointers. */
struct LX_NOR_FLASH_STRUCT *lx_nor_flash_open_next, struct LX_NOR_FLASH_STRUCT *lx_nor_flash_open_next,
*lx_nor_flash_open_previous; *lx_nor_flash_open_previous;
/* Define the user extension in the flash control block. This /* Define the user extension in the flash control block. This
is typically defined in lx_user.h. */ is typically defined in lx_user.h. */
LX_NOR_FLASH_USER_EXTENSION LX_NOR_FLASH_USER_EXTENSION
@@ -686,24 +631,24 @@ typedef struct LX_NOR_FLASH_STRUCT
/* Each physical NOR block has the following structure at the beginning of the block: /* Each physical NOR block has the following structure at the beginning of the block:
Offset Meaning Offset Meaning
0 Erase count 0 Erase count
4 Minimum logical sector number - only when the block is full 4 Minimum logical sector number - only when the block is full
8 Maximum logical sector number - only when the block is full 8 Maximum logical sector number - only when the block is full
12 Free physical sector bit map, where a value of 1 indicates a 12 Free physical sector bit map, where a value of 1 indicates a
free physical sector. The bit map is evenly divisible by 4 free physical sector. The bit map is evenly divisible by 4
. Array of physical sector mapping information (4 bytes per entry, . Array of physical sector mapping information (4 bytes per entry,
one entry for each physical sector in block). Each entry looks one entry for each physical sector in block). Each entry looks
like the following: like the following:
Bit(s) Meaning Bit(s) Meaning
0-29 Logical sector mapped if not 0x3FFFFFFF 0-29 Logical sector mapped if not 0x3FFFFFFF
30 If 0, entry is being superceded 30 If 0, entry is being superceded
31 If 1, entry is valid 31 If 1, entry is valid
Array of physical sectors, with each of size LX_NOR_SECTOR_SIZE Array of physical sectors, with each of size LX_NOR_SECTOR_SIZE
*/ */
typedef struct LX_NOR_FLASH_BLOCK_HEADER_STRUCT typedef struct LX_NOR_FLASH_BLOCK_HEADER_STRUCT
@@ -843,5 +788,5 @@ VOID _lx_nor_flash_system_error(LX_NOR_FLASH *nor_flash, UINT error_code);
} }
#endif #endif
#endif #endif
+23 -39
View File
@@ -1,10 +1,11 @@
/*************************************************************************** /***************************************************************************
* 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 * This program and the accompanying materials are made available under the
* terms of the MIT License which is available at * terms of the MIT License which is available at
* https://opensource.org/licenses/MIT. * https://opensource.org/licenses/MIT.
* *
* SPDX-License-Identifier: MIT * SPDX-License-Identifier: MIT
**************************************************************************/ **************************************************************************/
@@ -39,23 +40,6 @@
/* Note that all the defines in this file may also be made on the */ /* Note that all the defines in this file may also be made on the */
/* command line when building LevelX library and application objects. */ /* command line when building LevelX library and application objects. */
/* */ /* */
/* RELEASE HISTORY */
/* */
/* DATE NAME DESCRIPTION */
/* */
/* 11-09-2020 William E. Lamie Initial Version 6.1.2 */
/* 06-02-2021 Bhupendra Naphade Modified comment(s), and */
/* added standalone support, */
/* resulting in version 6.1.7 */
/* 03-08-2023 Xiuwen Cai Modified comment(s), and */
/* added new NAND options, */
/* resulting in version 6.2.1 */
/* 10-31-2023 Xiuwen Cai Modified comment(s), */
/* added options for mapping , */
/* bitmap cache and obsolete */
/* count cache, */
/* resulting in version 6.3.0 */
/* */
/**************************************************************************/ /**************************************************************************/
#ifndef LX_USER_H #ifndef LX_USER_H
@@ -63,22 +47,22 @@
/* Defined, this option bypasses the NOR flash driver read routine in favor or reading /* Defined, this option bypasses the NOR flash driver read routine in favor or reading
the NOR memory directly, resulting in a significant performance increase. the NOR memory directly, resulting in a significant performance increase.
*/ */
/* /*
#define LX_DIRECT_READ #define LX_DIRECT_READ
*/ */
/* Defined, this causes the LevelX NOR instance open logic to verify free NOR /* Defined, this causes the LevelX NOR instance open logic to verify free NOR
sectors are all ones. sectors are all ones.
*/ */
/* /*
#define LX_FREE_SECTOR_DATA_VERIFY #define LX_FREE_SECTOR_DATA_VERIFY
*/ */
/* By default this value is 4, which represents a maximum of 4 blocks that /* By default this value is 4, which represents a maximum of 4 blocks that
can be allocated for metadata. can be allocated for metadata.
*/ */
/* /*
@@ -90,23 +74,23 @@
#define LX_NOR_DISABLE_EXTENDED_CACHE #define LX_NOR_DISABLE_EXTENDED_CACHE
*/ */
/* By default this value is 8, which represents a maximum of 8 sectors that /* By default this value is 8, which represents a maximum of 8 sectors that
can be cached in a NOR instance. can be cached in a NOR instance.
*/ */
/* /*
#define LX_NOR_EXTENDED_CACHE_SIZE 8 #define LX_NOR_EXTENDED_CACHE_SIZE 8
*/ */
/* By default this value is 16 and defines the logical sector mapping cache size. /* By default this value is 16 and defines the logical sector mapping cache size.
Large values improve performance, but cost memory. The minimum size is 8 and all Large values improve performance, but cost memory. The minimum size is 8 and all
values must be a power of 2. values must be a power of 2.
*/ */
/* /*
#define LX_NOR_SECTOR_MAPPING_CACHE_SIZE 16 #define LX_NOR_SECTOR_MAPPING_CACHE_SIZE 16
*/ */
/* Defined, this makes LevelX thread-safe by using a ThreadX mutex object /* Defined, this makes LevelX thread-safe by using a ThreadX mutex object
throughout the API. throughout the API.
*/ */
/* /*
@@ -118,34 +102,34 @@
/* #define LX_STANDALONE_ENABLE */ /* #define LX_STANDALONE_ENABLE */
/* Define user extension for NOR flash control block. User extension is placed at the end of flash control block and it is not cleared on opening flash. */ /* Define user extension for NOR flash control block. User extension is placed at the end of flash control block and it is not cleared on opening flash. */
/* /*
#define LX_NOR_FLASH_USER_EXTENSION ???? #define LX_NOR_FLASH_USER_EXTENSION ????
*/ */
/* Define user extension for NAND flash control block. User extension is placed at the end of flash control block and it is not cleared on opening flash. */ /* Define user extension for NAND flash control block. User extension is placed at the end of flash control block and it is not cleared on opening flash. */
/* /*
#define LX_NAND_FLASH_USER_EXTENSION ???? #define LX_NAND_FLASH_USER_EXTENSION ????
*/ */
/* Determine if logical sector mapping bitmap should be enabled in extended cache. /* Determine if logical sector mapping bitmap should be enabled in extended cache.
Cache memory will be allocated to sector mapping bitmap first. One bit can be allocated for each physical sector. */ Cache memory will be allocated to sector mapping bitmap first. One bit can be allocated for each physical sector. */
/* /*
#define LX_NOR_ENABLE_MAPPING_BITMAP #define LX_NOR_ENABLE_MAPPING_BITMAP
*/ */
/* Determine if obsolete count cache should be enabled in extended cache. /* Determine if obsolete count cache should be enabled in extended cache.
Cache memory will be allocated to obsolete count cache after the mapping bitmap if enabled, Cache memory will be allocated to obsolete count cache after the mapping bitmap if enabled,
and the rest of the cache memory is allocated to sector cache. */ and the rest of the cache memory is allocated to sector cache. */
/* /*
#define LX_NOR_ENABLE_OBSOLETE_COUNT_CACHE #define LX_NOR_ENABLE_OBSOLETE_COUNT_CACHE
*/ */
/* Defines obsolete count cache element size. If number of sectors per block is greater than 256, use USHORT instead of UCHAR. */ /* Defines obsolete count cache element size. If number of sectors per block is greater than 256, use USHORT instead of UCHAR. */
/* /*
#define LX_NOR_OBSOLETE_COUNT_CACHE_TYPE UCHAR #define LX_NOR_OBSOLETE_COUNT_CACHE_TYPE UCHAR
*/ */
/* Define the logical sector size for NOR flash. The sector size is in units of 32-bit words. /* Define the logical sector size for NOR flash. The sector size is in units of 32-bit words.
This sector size should match the sector size used in file system. */ This sector size should match the sector size used in file system. */
/* /*
#define LX_NOR_SECTOR_SIZE (512/sizeof(ULONG)) #define LX_NOR_SECTOR_SIZE (512/sizeof(ULONG))
+106 -118
View File
@@ -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 * This program and the accompanying materials are made available under the
* terms of the MIT License which is available at * terms of the MIT License which is available at
* https://opensource.org/licenses/MIT. * https://opensource.org/licenses/MIT.
* *
* SPDX-License-Identifier: MIT * SPDX-License-Identifier: MIT
**************************************************************************/ **************************************************************************/
/**************************************************************************/ /**************************************************************************/
/**************************************************************************/ /**************************************************************************/
/** */ /** */
/** FileX Component */ /** FileX Component */
/** */ /** */
/** FileX NAND FLASH Simulator Driver */ /** 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 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_nand_sim_driver, // Driver entry
FX_NULL, // Unused FX_NULL, // Unused
media_memory, // Media buffer pointer media_memory, // Media buffer pointer
sizeof(media_memory), // Media buffer size sizeof(media_memory), // Media buffer size
"MY_NAND_DISK", // Volume Name "MY_NAND_DISK", // Volume Name
1, // Number of FATs 1, // Number of FATs
32, // Directory Entries 32, // Directory Entries
0, // Hidden sectors 0, // Hidden sectors
120, // Total sectors 120, // Total sectors
2048, // Sector size 2048, // Sector size
1, // Sectors per cluster 1, // Sectors per cluster
1, // Heads 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); VOID _fx_nand_flash_simulator_driver(FX_MEDIA *media_ptr);
/**************************************************************************/ /**************************************************************************/
/* */ /* */
/* FUNCTION RELEASE */ /* FUNCTION RELEASE */
/* */ /* */
/* _fx_nand_simulator_driver PORTABLE C */ /* _fx_nand_simulator_driver PORTABLE C */
/* 6.2.1 */ /* 6.2.1 */
/* AUTHOR */ /* AUTHOR */
/* */ /* */
/* William E. Lamie, Microsoft Corporation */ /* William E. Lamie, Microsoft Corporation */
/* */ /* */
/* DESCRIPTION */ /* 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 */
/* */ /* */
/* 05-19-2020 William E. Lamie Initial Version 6.0 */ /* This function is the entry point to the generic NAND simulated */
/* 09-30-2020 William E. Lamie Modified comment(s), */ /* disk driver that is delivered with the flash wear leveling product */
/* resulting in version 6.1 */ /* LevelX. */
/* 06-02-2021 Bhupendra Naphade Modified comment(s), */ /* */
/* resulting in version 6.1.7 */ /* This driver also serves as a template for developing other LevelX */
/* 03-08-2023 Xiuwen Cai Modified comment(s), */ /* NAND flash drivers for actual flash devices. Simply replace the */
/* changed to use new API, */ /* read/write sector logic with calls to read/write from the */
/* resulting in version 6.2.1 */ /* 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) VOID _fx_nand_flash_simulator_driver(FX_MEDIA *media_ptr)
@@ -137,19 +125,19 @@ ULONG logical_sector;
ULONG count; ULONG count;
UCHAR *buffer; UCHAR *buffer;
UINT status; UINT status;
/* There are several useful/important pieces of information contained in the media /* 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 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: setup. The following is a summary of the necessary FX_MEDIA structure members:
FX_MEDIA Member Meaning 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: as follows:
FX_DRIVER_READ FX_DRIVER_READ
FX_DRIVER_WRITE FX_DRIVER_WRITE
FX_DRIVER_FLUSH FX_DRIVER_FLUSH
FX_DRIVER_ABORT FX_DRIVER_ABORT
FX_DRIVER_INIT FX_DRIVER_INIT
@@ -158,11 +146,11 @@ UINT status;
FX_DRIVER_BOOT_WRITE FX_DRIVER_BOOT_WRITE
FX_DRIVER_UNINIT 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 operation is successful, this field should be
set to FX_SUCCESS for before returning. Otherwise, set to FX_SUCCESS for before returning. Otherwise,
if an error occurred, this field should be set 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. fx_media_driver_buffer Pointer to buffer to read or write sector data.
This is supplied by FileX. This is supplied by FileX.
@@ -173,24 +161,24 @@ UINT status;
The following is a summary of the optional FX_MEDIA structure members: The following is a summary of the optional FX_MEDIA structure members:
FX_MEDIA Member Meaning FX_MEDIA Member Meaning
fx_media_driver_info Pointer to any additional information or memory. fx_media_driver_info Pointer to any additional information or memory.
This is optional for the driver use and is setup This is optional for the driver use and is setup
from the fx_media_open call. The RAM disk uses from the fx_media_open call. The RAM disk uses
this pointer for the RAM disk memory itself. this pointer for the RAM disk memory itself.
fx_media_driver_write_protect The DRIVER sets this to FX_TRUE when media is write fx_media_driver_write_protect The DRIVER sets this to FX_TRUE when media is write
protected. This is typically done in initialization, protected. This is typically done in initialization,
but can be done anytime. 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 know when clusters are released. This is important
for FLASH wear-leveling drivers. for FLASH wear-leveling drivers.
fx_media_driver_system_write FileX sets this flag to FX_TRUE if the sector being 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 directory sector. The driver may choose to use this
to initiate error recovery logic for greater fault to initiate error recovery logic for greater fault
tolerance. 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 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. 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 sector being read or written. The following sector
types are identified: types are identified:
FX_UNKNOWN_SECTOR FX_UNKNOWN_SECTOR
FX_BOOT_SECTOR FX_BOOT_SECTOR
FX_FAT_SECTOR FX_FAT_SECTOR
FX_DIRECTORY_SECTOR FX_DIRECTORY_SECTOR
FX_DATA_SECTOR FX_DATA_SECTOR
*/ */
/* Process the driver request specified in the media control block. */ /* Process the driver request specified in the media control block. */
@@ -225,18 +213,18 @@ UINT status;
/* Call LevelX to read one flash sector. */ /* Call LevelX to read one flash sector. */
status = _lx_nand_flash_sector_read(&nand_flash, logical_sector, buffer); status = _lx_nand_flash_sector_read(&nand_flash, logical_sector, buffer);
/* Determine if the read was successful. */ /* Determine if the read was successful. */
if (status != LX_SUCCESS) if (status != LX_SUCCESS)
{ {
/* Return an I/O error to FileX. */ /* Return an I/O error to FileX. */
media_ptr -> fx_media_driver_status = FX_IO_ERROR; media_ptr -> fx_media_driver_status = FX_IO_ERROR;
return;
}
/* Successful sector read. */ return;
}
/* Successful sector read. */
count--; count--;
logical_sector++; logical_sector++;
buffer += media_ptr -> fx_media_bytes_per_sector; buffer += media_ptr -> fx_media_bytes_per_sector;
@@ -245,12 +233,12 @@ UINT status;
media_ptr -> fx_media_driver_status = FX_SUCCESS; media_ptr -> fx_media_driver_status = FX_SUCCESS;
break; break;
} }
case FX_DRIVER_WRITE: case FX_DRIVER_WRITE:
{ {
/* Write sector(s) to NAND flash. */ /* 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; count = media_ptr -> fx_media_driver_sectors;
buffer = (UCHAR *) media_ptr -> fx_media_driver_buffer; buffer = (UCHAR *) media_ptr -> fx_media_driver_buffer;
while (count) while (count)
@@ -262,12 +250,12 @@ UINT status;
/* Determine if the write was successful. */ /* Determine if the write was successful. */
if (status != LX_SUCCESS) if (status != LX_SUCCESS)
{ {
/* Return an I/O error to FileX. */ /* Return an I/O error to FileX. */
media_ptr -> fx_media_driver_status = FX_IO_ERROR; media_ptr -> fx_media_driver_status = FX_IO_ERROR;
return; return;
} }
/* Successful sector write. */ /* Successful sector write. */
count--; count--;
@@ -282,7 +270,7 @@ UINT status;
case FX_DRIVER_RELEASE_SECTORS: case FX_DRIVER_RELEASE_SECTORS:
{ {
/* Release the mapping of this sector. */ /* Release the mapping of this sector. */
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; count = media_ptr -> fx_media_driver_sectors;
@@ -295,18 +283,18 @@ UINT status;
/* Determine if the sector release was successful. */ /* Determine if the sector release was successful. */
if (status != LX_SUCCESS) if (status != LX_SUCCESS)
{ {
/* Return an I/O error to FileX. */ /* Return an I/O error to FileX. */
media_ptr -> fx_media_driver_status = FX_IO_ERROR; media_ptr -> fx_media_driver_status = FX_IO_ERROR;
return; return;
} }
/* Successful sector release. */ /* Successful sector release. */
count--; count--;
logical_sector++; logical_sector++;
} }
/* Successful driver request. */ /* Successful driver request. */
media_ptr -> fx_media_driver_status = FX_SUCCESS; media_ptr -> fx_media_driver_status = FX_SUCCESS;
break; break;
@@ -331,7 +319,7 @@ UINT status;
case FX_DRIVER_INIT: 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 structure, as follows:
media_ptr -> fx_media_driver_free_sector_update 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 The fx_media_driver_free_sector_update flag is used to instruct
FileX to inform the driver whenever sectors are not being used. 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. maintain mapping for sectors no longer in use.
The fx_media_driver_write_protect flag can be set anytime by the 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. */ /* Determine if the flash open was successful. */
if (status != LX_SUCCESS) if (status != LX_SUCCESS)
{ {
/* Return an I/O error to FileX. */ /* Return an I/O error to FileX. */
media_ptr -> fx_media_driver_status = FX_IO_ERROR; media_ptr -> fx_media_driver_status = FX_IO_ERROR;
return; return;
} }
/* Successful driver request. */ /* Successful driver request. */
media_ptr -> fx_media_driver_status = FX_SUCCESS; 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 /* There is nothing to do in this case for the RAM driver. For actual
devices some shutdown processing may be necessary. */ devices some shutdown processing may be necessary. */
/* Close the NAND flash simulation. */ /* Close the NAND flash simulation. */
status = _lx_nand_flash_close(&nand_flash); status = _lx_nand_flash_close(&nand_flash);
/* Determine if the flash close was successful. */ /* Determine if the flash close was successful. */
if (status != LX_SUCCESS) if (status != LX_SUCCESS)
{ {
/* Return an I/O error to FileX. */ /* Return an I/O error to FileX. */
media_ptr -> fx_media_driver_status = FX_IO_ERROR; media_ptr -> fx_media_driver_status = FX_IO_ERROR;
return; return;
} }
/* Successful driver request. */ /* Successful driver request. */
media_ptr -> fx_media_driver_status = FX_SUCCESS; media_ptr -> fx_media_driver_status = FX_SUCCESS;
break; break;
} }
case FX_DRIVER_BOOT_READ: case FX_DRIVER_BOOT_READ:
{ {
@@ -404,13 +392,13 @@ UINT status;
/* Determine if the read was successful. */ /* Determine if the read was successful. */
if (status != LX_SUCCESS) if (status != LX_SUCCESS)
{ {
/* Return an I/O error to FileX. */ /* Return an I/O error to FileX. */
media_ptr -> fx_media_driver_status = FX_IO_ERROR; media_ptr -> fx_media_driver_status = FX_IO_ERROR;
return; return;
} }
/* Successful driver request. */ /* Successful driver request. */
media_ptr -> fx_media_driver_status = FX_SUCCESS; media_ptr -> fx_media_driver_status = FX_SUCCESS;
break; break;
@@ -425,12 +413,12 @@ UINT status;
/* Determine if the write was successful. */ /* Determine if the write was successful. */
if (status != LX_SUCCESS) if (status != LX_SUCCESS)
{ {
/* Return an I/O error to FileX. */ /* Return an I/O error to FileX. */
media_ptr -> fx_media_driver_status = FX_IO_ERROR; media_ptr -> fx_media_driver_status = FX_IO_ERROR;
return; return;
} }
/* Successful driver request. */ /* Successful driver request. */
media_ptr -> fx_media_driver_status = FX_SUCCESS; media_ptr -> fx_media_driver_status = FX_SUCCESS;
+100 -109
View File
@@ -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 * This program and the accompanying materials are made available under the
* terms of the MIT License which is available at * terms of the MIT License which is available at
* https://opensource.org/licenses/MIT. * https://opensource.org/licenses/MIT.
* *
* SPDX-License-Identifier: MIT * SPDX-License-Identifier: MIT
**************************************************************************/ **************************************************************************/
/**************************************************************************/ /**************************************************************************/
/**************************************************************************/ /**************************************************************************/
/** */ /** */
/** FileX Component */ /** FileX Component */
/** */ /** */
/** FileX NOR FLASH Simulator Driver */ /** FileX NOR FLASH Simulator Driver */
/** */ /** */
@@ -32,22 +33,22 @@ LX_NOR_FLASH nor_flash;
/* The simulated NOR driver relies on the fx_media_format call to be made prior to /* The simulated NOR 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_nor_sim_driver, // Driver entry _fx_nor_sim_driver, // Driver entry
FX_NULL, // Unused FX_NULL, // Unused
media_memory, // Media buffer pointer media_memory, // Media buffer pointer
sizeof(media_memory), // Media buffer size sizeof(media_memory), // Media buffer size
"MY_NOR_DISK", // Volume Name "MY_NOR_DISK", // Volume Name
1, // Number of FATs 1, // Number of FATs
32, // Directory Entries 32, // Directory Entries
0, // Hidden sectors 0, // Hidden sectors
120, // Total sectors 120, // Total sectors
LX_NOR_SECTOR_SIZE * sizeof(ULONG), // Sector size LX_NOR_SECTOR_SIZE * sizeof(ULONG), // Sector size
1, // Sectors per cluster 1, // Sectors per cluster
1, // Heads 1, // Heads
1); // Sectors per track 1); // Sectors per track
*/ */
@@ -58,66 +59,56 @@ UINT _lx_nor_flash_simulator_initialize(LX_NOR_FLASH *nor_flash);
VOID _fx_nor_flash_simulator_driver(FX_MEDIA *media_ptr); VOID _fx_nor_flash_simulator_driver(FX_MEDIA *media_ptr);
/**************************************************************************/ /**************************************************************************/
/* */ /* */
/* FUNCTION RELEASE */ /* FUNCTION RELEASE */
/* */ /* */
/* _fx_nor_flash_simulator_driver PORTABLE C */ /* _fx_nor_flash_simulator_driver PORTABLE C */
/* 6.1.7 */ /* 6.1.7 */
/* AUTHOR */ /* AUTHOR */
/* */ /* */
/* William E. Lamie, Microsoft Corporation */ /* William E. Lamie, Microsoft Corporation */
/* */ /* */
/* DESCRIPTION */ /* DESCRIPTION */
/* */
/* This function is the entry point to the generic NOR simulated */
/* disk driver that is delivered with the flash wear leveling product */
/* LevelX. */
/* */
/* This driver also serves as a template for developing other LevelX */
/* NOR 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 NOR 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_nor_flash_close Close NOR flash manager */
/* lx_nor_flash_open Open NOR flash manager */
/* lx_nor_flash_sector_read Read a NOR sector */
/* lx_nor_flash_sector_release Release a NOR sector */
/* lx_nor_flash_sector_write Write a NOR sector */
/* */
/* CALLED BY */
/* */
/* FileX System Functions */
/* */
/* RELEASE HISTORY */
/* */
/* DATE NAME DESCRIPTION */
/* */ /* */
/* 05-19-2020 William E. Lamie Initial Version 6.0 */ /* This function is the entry point to the generic NOR simulated */
/* 09-30-2020 William E. Lamie Modified comment(s), */ /* disk driver that is delivered with the flash wear leveling product */
/* resulting in version 6.1 */ /* LevelX. */
/* 06-02-2021 Bhupendra Naphade Modified comment(s), */ /* */
/* resulting in version 6.1.7 */ /* This driver also serves as a template for developing other LevelX */
/* NOR 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 NOR 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_nor_flash_close Close NOR flash manager */
/* lx_nor_flash_open Open NOR flash manager */
/* lx_nor_flash_sector_read Read a NOR sector */
/* lx_nor_flash_sector_release Release a NOR sector */
/* lx_nor_flash_sector_write Write a NOR sector */
/* */
/* CALLED BY */
/* */
/* FileX System Functions */
/* */ /* */
/**************************************************************************/ /**************************************************************************/
VOID _fx_nor_flash_simulator_driver(FX_MEDIA *media_ptr) VOID _fx_nor_flash_simulator_driver(FX_MEDIA *media_ptr)
@@ -133,14 +124,14 @@ UINT status;
/* There are several useful/important pieces of information contained in the media /* 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 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: setup. The following is a summary of the necessary FX_MEDIA structure members:
FX_MEDIA Member Meaning 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: as follows:
FX_DRIVER_READ FX_DRIVER_READ
FX_DRIVER_WRITE FX_DRIVER_WRITE
FX_DRIVER_FLUSH FX_DRIVER_FLUSH
FX_DRIVER_ABORT FX_DRIVER_ABORT
FX_DRIVER_INIT FX_DRIVER_INIT
@@ -149,11 +140,11 @@ UINT status;
FX_DRIVER_BOOT_WRITE FX_DRIVER_BOOT_WRITE
FX_DRIVER_UNINIT 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 operation is successful, this field should be
set to FX_SUCCESS for before returning. Otherwise, set to FX_SUCCESS for before returning. Otherwise,
if an error occurred, this field should be set 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. fx_media_driver_buffer Pointer to buffer to read or write sector data.
This is supplied by FileX. This is supplied by FileX.
@@ -164,24 +155,24 @@ UINT status;
The following is a summary of the optional FX_MEDIA structure members: The following is a summary of the optional FX_MEDIA structure members:
FX_MEDIA Member Meaning FX_MEDIA Member Meaning
fx_media_driver_info Pointer to any additional information or memory. fx_media_driver_info Pointer to any additional information or memory.
This is optional for the driver use and is setup This is optional for the driver use and is setup
from the fx_media_open call. The RAM disk uses from the fx_media_open call. The RAM disk uses
this pointer for the RAM disk memory itself. this pointer for the RAM disk memory itself.
fx_media_driver_write_protect The DRIVER sets this to FX_TRUE when media is write fx_media_driver_write_protect The DRIVER sets this to FX_TRUE when media is write
protected. This is typically done in initialization, protected. This is typically done in initialization,
but can be done anytime. 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 know when clusters are released. This is important
for FLASH wear-leveling drivers. for FLASH wear-leveling drivers.
fx_media_driver_system_write FileX sets this flag to FX_TRUE if the sector being 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 directory sector. The driver may choose to use this
to initiate error recovery logic for greater fault to initiate error recovery logic for greater fault
tolerance. tolerance.
@@ -189,15 +180,15 @@ UINT status;
fx_media_driver_data_sector_read FileX sets this flag to FX_TRUE if the sector(s) being 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. 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 sector being read or written. The following sector
types are identified: types are identified:
FX_UNKNOWN_SECTOR FX_UNKNOWN_SECTOR
FX_BOOT_SECTOR FX_BOOT_SECTOR
FX_FAT_SECTOR FX_FAT_SECTOR
FX_DIRECTORY_SECTOR FX_DIRECTORY_SECTOR
FX_DATA_SECTOR FX_DATA_SECTOR
*/ */
/* Process the driver request specified in the media control block. */ /* Process the driver request specified in the media control block. */
@@ -214,19 +205,19 @@ UINT status;
/* Loop to read sectors from flash. */ /* Loop to read sectors from flash. */
for (i = 0; i < media_ptr -> fx_media_driver_sectors; i++) for (i = 0; i < media_ptr -> fx_media_driver_sectors; i++)
{ {
/* Read a sector from NOR flash. */ /* Read a sector from NOR flash. */
status = lx_nor_flash_sector_read(&nor_flash, logical_sector, destination_buffer); status = lx_nor_flash_sector_read(&nor_flash, logical_sector, destination_buffer);
/* Determine if the read was successful. */ /* Determine if the read was successful. */
if (status != LX_SUCCESS) if (status != LX_SUCCESS)
{ {
/* Return an I/O error to FileX. */ /* Return an I/O error to FileX. */
media_ptr -> fx_media_driver_status = FX_IO_ERROR; media_ptr -> fx_media_driver_status = FX_IO_ERROR;
return; return;
} }
/* Move to the next entries. */ /* Move to the next entries. */
logical_sector++; logical_sector++;
@@ -237,7 +228,7 @@ UINT status;
media_ptr -> fx_media_driver_status = FX_SUCCESS; media_ptr -> fx_media_driver_status = FX_SUCCESS;
break; break;
} }
case FX_DRIVER_WRITE: case FX_DRIVER_WRITE:
{ {
@@ -248,19 +239,19 @@ UINT status;
/* Loop to write sectors to flash. */ /* Loop to write sectors to flash. */
for (i = 0; i < media_ptr -> fx_media_driver_sectors; i++) for (i = 0; i < media_ptr -> fx_media_driver_sectors; i++)
{ {
/* Write a sector to NOR flash. */ /* Write a sector to NOR flash. */
status = lx_nor_flash_sector_write(&nor_flash, logical_sector, source_buffer); status = lx_nor_flash_sector_write(&nor_flash, logical_sector, source_buffer);
/* Determine if the write was successful. */ /* Determine if the write was successful. */
if (status != LX_SUCCESS) if (status != LX_SUCCESS)
{ {
/* Return an I/O error to FileX. */ /* Return an I/O error to FileX. */
media_ptr -> fx_media_driver_status = FX_IO_ERROR; media_ptr -> fx_media_driver_status = FX_IO_ERROR;
return; return;
} }
/* Move to the next entries. */ /* Move to the next entries. */
logical_sector++; logical_sector++;
@@ -274,26 +265,26 @@ UINT status;
case FX_DRIVER_RELEASE_SECTORS: case FX_DRIVER_RELEASE_SECTORS:
{ {
/* Setup the logical sector. */ /* Setup the logical sector. */
logical_sector = media_ptr -> fx_media_driver_logical_sector; logical_sector = media_ptr -> fx_media_driver_logical_sector;
/* Release sectors. */ /* Release sectors. */
for (i = 0; i < media_ptr -> fx_media_driver_sectors; i++) for (i = 0; i < media_ptr -> fx_media_driver_sectors; i++)
{ {
/* Release NOR flash sector. */ /* Release NOR flash sector. */
status = lx_nor_flash_sector_release(&nor_flash, logical_sector); status = lx_nor_flash_sector_release(&nor_flash, logical_sector);
/* Determine if the sector release was successful. */ /* Determine if the sector release was successful. */
if (status != LX_SUCCESS) if (status != LX_SUCCESS)
{ {
/* Return an I/O error to FileX. */ /* Return an I/O error to FileX. */
media_ptr -> fx_media_driver_status = FX_IO_ERROR; media_ptr -> fx_media_driver_status = FX_IO_ERROR;
return; return;
} }
/* Move to the next entries. */ /* Move to the next entries. */
logical_sector++; logical_sector++;
@@ -323,7 +314,7 @@ UINT status;
case FX_DRIVER_INIT: 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 structure, as follows:
media_ptr -> fx_media_driver_free_sector_update media_ptr -> fx_media_driver_free_sector_update
@@ -331,7 +322,7 @@ UINT status;
The fx_media_driver_free_sector_update flag is used to instruct The fx_media_driver_free_sector_update flag is used to instruct
FileX to inform the driver whenever sectors are not being used. 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. maintain mapping for sectors no longer in use.
The fx_media_driver_write_protect flag can be set anytime by the The fx_media_driver_write_protect flag can be set anytime by the
@@ -351,12 +342,12 @@ UINT status;
/* Determine if the flash open was successful. */ /* Determine if the flash open was successful. */
if (status != LX_SUCCESS) if (status != LX_SUCCESS)
{ {
/* Return an I/O error to FileX. */ /* Return an I/O error to FileX. */
media_ptr -> fx_media_driver_status = FX_IO_ERROR; media_ptr -> fx_media_driver_status = FX_IO_ERROR;
return; return;
} }
/* Successful driver request. */ /* Successful driver request. */
media_ptr -> fx_media_driver_status = FX_SUCCESS; media_ptr -> fx_media_driver_status = FX_SUCCESS;
@@ -375,18 +366,18 @@ UINT status;
/* Determine if the flash close was successful. */ /* Determine if the flash close was successful. */
if (status != LX_SUCCESS) if (status != LX_SUCCESS)
{ {
/* Return an I/O error to FileX. */ /* Return an I/O error to FileX. */
media_ptr -> fx_media_driver_status = FX_IO_ERROR; media_ptr -> fx_media_driver_status = FX_IO_ERROR;
return; return;
} }
/* Successful driver request. */ /* Successful driver request. */
media_ptr -> fx_media_driver_status = FX_SUCCESS; media_ptr -> fx_media_driver_status = FX_SUCCESS;
break; break;
} }
case FX_DRIVER_BOOT_READ: case FX_DRIVER_BOOT_READ:
{ {
@@ -412,12 +403,12 @@ UINT status;
/* Determine if the boot read was successful. */ /* Determine if the boot read was successful. */
if (status != LX_SUCCESS) if (status != LX_SUCCESS)
{ {
/* Return an I/O error to FileX. */ /* Return an I/O error to FileX. */
media_ptr -> fx_media_driver_status = FX_IO_ERROR; media_ptr -> fx_media_driver_status = FX_IO_ERROR;
return; return;
} }
/* Successful driver request. */ /* Successful driver request. */
media_ptr -> fx_media_driver_status = FX_SUCCESS; media_ptr -> fx_media_driver_status = FX_SUCCESS;
@@ -447,12 +438,12 @@ UINT status;
/* Determine if the boot write was successful. */ /* Determine if the boot write was successful. */
if (status != LX_SUCCESS) if (status != LX_SUCCESS)
{ {
/* Return an I/O error to FileX. */ /* Return an I/O error to FileX. */
media_ptr -> fx_media_driver_status = FX_IO_ERROR; media_ptr -> fx_media_driver_status = FX_IO_ERROR;
return; return;
} }
/* Successful driver request. */ /* Successful driver request. */
media_ptr -> fx_media_driver_status = FX_SUCCESS; media_ptr -> fx_media_driver_status = FX_SUCCESS;
+43 -52
View File
@@ -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 * This program and the accompanying materials are made available under the
* terms of the MIT License which is available at * terms of the MIT License which is available at
* https://opensource.org/licenses/MIT. * https://opensource.org/licenses/MIT.
* *
* SPDX-License-Identifier: MIT * SPDX-License-Identifier: MIT
**************************************************************************/ **************************************************************************/
/**************************************************************************/ /**************************************************************************/
/**************************************************************************/ /**************************************************************************/
/** */ /** */
/** LevelX Component */ /** LevelX Component */
/** */ /** */
/** NAND Flash */ /** NAND Flash */
/** */ /** */
@@ -34,54 +35,44 @@
#include "lx_api.h" #include "lx_api.h"
/**************************************************************************/ /**************************************************************************/
/* */ /* */
/* FUNCTION RELEASE */ /* FUNCTION RELEASE */
/* */ /* */
/* _lx_nand_flash_256byte_ecc_check PORTABLE C */ /* _lx_nand_flash_256byte_ecc_check PORTABLE C */
/* 6.1.7 */ /* 6.1.7 */
/* AUTHOR */ /* AUTHOR */
/* */ /* */
/* William E. Lamie, Microsoft Corporation */ /* William E. Lamie, Microsoft Corporation */
/* */ /* */
/* DESCRIPTION */ /* DESCRIPTION */
/* */
/* This function checks 256 bytes of a NAND flash and ECC and */
/* attempts to correct any single bit errors. */
/* */
/* INPUT */
/* */
/* page_buffer Page buffer */
/* ecc_buffer Returned ECC buffer */
/* */
/* OUTPUT */
/* */
/* return status */
/* */
/* CALLS */
/* */
/* _lx_nand_flash_256byte_ecc_compute Compute ECC for 256 bytes */
/* */
/* CALLED BY */
/* */
/* _lx_nand_flash_page_ecc_check NAND page check */
/* */
/* RELEASE HISTORY */
/* */
/* DATE NAME DESCRIPTION */
/* */ /* */
/* 05-19-2020 William E. Lamie Initial Version 6.0 */ /* This function checks 256 bytes of a NAND flash and ECC and */
/* 09-30-2020 William E. Lamie Modified comment(s), */ /* attempts to correct any single bit errors. */
/* resulting in version 6.1 */ /* */
/* 06-02-2021 Bhupendra Naphade Modified comment(s), */ /* INPUT */
/* resulting in version 6.1.7 */ /* */
/* page_buffer Page buffer */
/* ecc_buffer Returned ECC buffer */
/* */
/* OUTPUT */
/* */
/* return status */
/* */
/* CALLS */
/* */
/* _lx_nand_flash_256byte_ecc_compute Compute ECC for 256 bytes */
/* */
/* CALLED BY */
/* */
/* _lx_nand_flash_page_ecc_check NAND page check */
/* */ /* */
/**************************************************************************/ /**************************************************************************/
UINT _lx_nand_flash_256byte_ecc_check(UCHAR *page_buffer, UCHAR *ecc_buffer) UINT _lx_nand_flash_256byte_ecc_check(UCHAR *page_buffer, UCHAR *ecc_buffer)
{ {
INT i, j; INT i, j;
UCHAR mask; UCHAR mask;
UCHAR new_ecc_buffer[3]; UCHAR new_ecc_buffer[3];
UCHAR ecc_errors[3]; UCHAR ecc_errors[3];
INT error_count; INT error_count;
@@ -103,29 +94,29 @@ ULONG correction_code;
error_count = 0; error_count = 0;
/* Loop through the ECC bytes to determine if there is an error in the page. */ /* Loop through the ECC bytes to determine if there is an error in the page. */
for (i = 0; i < 3; i++) for (i = 0; i < 3; i++)
{ {
/* Check for differences in the ECCs. */ /* Check for differences in the ECCs. */
ecc_errors[i] = new_ecc_buffer[i] ^ ecc_buffer[i]; ecc_errors[i] = new_ecc_buffer[i] ^ ecc_buffer[i];
/* Are there any errors? */ /* Are there any errors? */
if (ecc_errors[i]) if (ecc_errors[i])
{ {
/* Accumulate the count of set bits. */ /* Accumulate the count of set bits. */
mask = 1; mask = 1;
for (j = 0; j < 8; j++) for (j = 0; j < 8; j++)
{ {
/* Is this bit set? */ /* Is this bit set? */
if (ecc_errors[i] & mask) if (ecc_errors[i] & mask)
{ {
/* Yes, increment the count. */ /* Yes, increment the count. */
error_count++; error_count++;
} }
/* Move mask to next bit. */ /* Move mask to next bit. */
mask = (UCHAR) ((mask << 1) & 0xFF); mask = (UCHAR) ((mask << 1) & 0xFF);
} }
@@ -141,7 +132,7 @@ ULONG correction_code;
} }
/* Was a correctable error discovered? */ /* Was a correctable error discovered? */
else if (error_count == 11) else if (error_count == 11)
{ {
/* Initialize bit and byte offset values. */ /* Initialize bit and byte offset values. */
@@ -169,13 +160,13 @@ ULONG correction_code;
/* Fix the error. */ /* Fix the error. */
data[byte] = (USHORT) ((data[byte] ^ (1 << bit)) & 0xFFFF); data[byte] = (USHORT) ((data[byte] ^ (1 << bit)) & 0xFFFF);
/* Return an error corrected status. */ /* Return an error corrected status. */
return(LX_NAND_ERROR_CORRECTED); return(LX_NAND_ERROR_CORRECTED);
} }
/* Otherwise, an unrecoverable ECC or data error is present. */ /* Otherwise, an unrecoverable ECC or data error is present. */
else else
{ {
/* Return an error. */ /* Return an error. */
+55 -67
View File
@@ -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 * This program and the accompanying materials are made available under the
* terms of the MIT License which is available at * terms of the MIT License which is available at
* https://opensource.org/licenses/MIT. * https://opensource.org/licenses/MIT.
* *
* SPDX-License-Identifier: MIT * SPDX-License-Identifier: MIT
**************************************************************************/ **************************************************************************/
/**************************************************************************/ /**************************************************************************/
/**************************************************************************/ /**************************************************************************/
/** */ /** */
/** LevelX Component */ /** LevelX Component */
/** */ /** */
/** NAND Flash */ /** NAND Flash */
/** */ /** */
@@ -34,51 +35,38 @@
#include "lx_api.h" #include "lx_api.h"
/**************************************************************************/ /**************************************************************************/
/* */ /* */
/* FUNCTION RELEASE */ /* FUNCTION RELEASE */
/* */ /* */
/* _lx_nand_flash_256byte_ecc_compute PORTABLE C */ /* _lx_nand_flash_256byte_ecc_compute PORTABLE C */
/* 6.2.1 */ /* 6.2.1 */
/* AUTHOR */ /* AUTHOR */
/* */ /* */
/* William E. Lamie, Microsoft Corporation */ /* William E. Lamie, Microsoft Corporation */
/* */ /* */
/* DESCRIPTION */ /* DESCRIPTION */
/* */
/* This function computes the ECC for 256 bytes of a NAND flash page. */
/* The resulting ECC code is returned in 3 bytes. */
/* */
/* INPUT */
/* */
/* page_buffer Page buffer */
/* ecc_buffer Returned ECC buffer */
/* */
/* OUTPUT */
/* */
/* return status */
/* */
/* CALLS */
/* */
/* None */
/* */
/* CALLED BY */
/* */
/* _lx_nand_flash_page_ecc_compute NAND page ECC compute */
/* _lx_nand_flash_256byte_ecc_check Check 256 bytes and ECC */
/* */
/* RELEASE HISTORY */
/* */
/* DATE NAME DESCRIPTION */
/* */ /* */
/* 05-19-2020 William E. Lamie Initial Version 6.0 */ /* This function computes the ECC for 256 bytes of a NAND flash page. */
/* 09-30-2020 William E. Lamie Modified comment(s), */ /* The resulting ECC code is returned in 3 bytes. */
/* resulting in version 6.1 */ /* */
/* 06-02-2021 Bhupendra Naphade Modified comment(s), */ /* INPUT */
/* resulting in version 6.1.7 */ /* */
/* 03-08-2023 Xiuwen Cai Modified comment(s), */ /* page_buffer Page buffer */
/* inverted output, */ /* ecc_buffer Returned ECC buffer */
/* resulting in version 6.2.1 */ /* */
/* OUTPUT */
/* */
/* return status */
/* */
/* CALLS */
/* */
/* None */
/* */
/* CALLED BY */
/* */
/* _lx_nand_flash_page_ecc_compute NAND page ECC compute */
/* _lx_nand_flash_256byte_ecc_check Check 256 bytes and ECC */
/* */ /* */
/**************************************************************************/ /**************************************************************************/
UINT _lx_nand_flash_256byte_ecc_compute(UCHAR *page_buffer, UCHAR *ecc_buffer) UINT _lx_nand_flash_256byte_ecc_compute(UCHAR *page_buffer, UCHAR *ecc_buffer)
@@ -105,27 +93,27 @@ USHORT odd_byte_parity;
ecc_buffer[0]= 0; ecc_buffer[0]= 0;
ecc_buffer[1]= 0; ecc_buffer[1]= 0;
ecc_buffer[2]= 0; ecc_buffer[2]= 0;
/* Setup a 16-bit pointer to the buffer area. */ /* Setup a 16-bit pointer to the buffer area. */
data = (USHORT *) page_buffer; data = (USHORT *) page_buffer;
/* Loop through the 256 byte buffer, 16 bits at a time. */ /* Loop through the 256 byte buffer, 16 bits at a time. */
for (i = 0; i < 128; i++) for (i = 0; i < 128; i++)
{ {
/* Compute the ECC value. */ /* Compute the ECC value. */
bit_parity = bit_parity ^ data[i]; bit_parity = bit_parity ^ data[i];
/* Now count the bits in the current data word. */ /* Now count the bits in the current data word. */
bits = 0; bits = 0;
mask = 1; mask = 1;
for (j = 0; j < 16; j++) for (j = 0; j < 16; j++)
{ {
/* Is the bit set? */ /* Is the bit set? */
if (data[i] & mask) if (data[i] & mask)
{ {
/* Yes, increment the bit count. */ /* Yes, increment the bit count. */
bits++; bits++;
} }
@@ -133,11 +121,11 @@ USHORT odd_byte_parity;
/* Move the mask to the next bit. */ /* Move the mask to the next bit. */
mask = (USHORT) ((mask << 1) & 0xFFFF); mask = (USHORT) ((mask << 1) & 0xFFFF);
} }
/* Determine if the number of bits is odd. */ /* Determine if the number of bits is odd. */
if ((bits & 1) == 1) if ((bits & 1) == 1)
{ {
/* Odd number of bits. Adjust the odd/even byte parity. */ /* Odd number of bits. Adjust the odd/even byte parity. */
even_byte_parity = (USHORT) ((even_byte_parity ^ (0xffff - i)) & 0xFFFF); even_byte_parity = (USHORT) ((even_byte_parity ^ (0xffff - i)) & 0xFFFF);
odd_byte_parity = odd_byte_parity ^ i; odd_byte_parity = odd_byte_parity ^ i;
@@ -145,11 +133,11 @@ USHORT odd_byte_parity;
} }
/* Now look for bits set in the bit parity. */ /* Now look for bits set in the bit parity. */
for (i = 0; i < 16; i++) for (i = 0; i < 16; i++)
{ {
/* Is the bit set? */ /* Is the bit set? */
if (bit_parity & 1) if (bit_parity & 1)
{ {
/* Yes, adjust the odd even byte parity. */ /* Yes, adjust the odd even byte parity. */
@@ -160,21 +148,21 @@ USHORT odd_byte_parity;
/* Look at next bit position. */ /* Look at next bit position. */
bit_parity = bit_parity >> 1; bit_parity = bit_parity >> 1;
} }
/* At this point, we need to pack the 22 ECC bits into the 3 byte return area. */ /* At this point, we need to pack the 22 ECC bits into the 3 byte return area. */
/* Pack bit 21. */ /* Pack bit 21. */
ecc_buffer[(21+2)/8] = ((UCHAR)(ecc_buffer[(21+2)/8] | ((odd_byte_parity >> 6) & 1) << (21+2)%8) & 0xFF); ecc_buffer[(21+2)/8] = ((UCHAR)(ecc_buffer[(21+2)/8] | ((odd_byte_parity >> 6) & 1) << (21+2)%8) & 0xFF);
/* Pack bit 20. */ /* Pack bit 20. */
ecc_buffer[(20+2)/8] = ((UCHAR)(ecc_buffer[(20+2)/8] | ((even_byte_parity >> 6) & 1) << (20+2)%8) & 0xFF); ecc_buffer[(20+2)/8] = ((UCHAR)(ecc_buffer[(20+2)/8] | ((even_byte_parity >> 6) & 1) << (20+2)%8) & 0xFF);
/* Pack bit 19. */ /* Pack bit 19. */
ecc_buffer[(19+2)/8] = ((UCHAR)(ecc_buffer[(19+2)/8] | ((odd_byte_parity >> 5) & 1) << (19+2)%8) & 0xFF); ecc_buffer[(19+2)/8] = ((UCHAR)(ecc_buffer[(19+2)/8] | ((odd_byte_parity >> 5) & 1) << (19+2)%8) & 0xFF);
/* Pack bit 18. */ /* Pack bit 18. */
ecc_buffer[(18+2)/8] = ((UCHAR)(ecc_buffer[(18+2)/8] | ((even_byte_parity >> 5) & 1) << (18+2)%8) & 0xFF); ecc_buffer[(18+2)/8] = ((UCHAR)(ecc_buffer[(18+2)/8] | ((even_byte_parity >> 5) & 1) << (18+2)%8) & 0xFF);
/* Pack bit 17. */ /* Pack bit 17. */
ecc_buffer[(17+2)/8] = ((UCHAR)(ecc_buffer[(17+2)/8] | ((odd_byte_parity >> 4) & 1) << (17+2)%8) & 0xFF); ecc_buffer[(17+2)/8] = ((UCHAR)(ecc_buffer[(17+2)/8] | ((odd_byte_parity >> 4) & 1) << (17+2)%8) & 0xFF);
@@ -189,7 +177,7 @@ USHORT odd_byte_parity;
/* Pack bit 13. */ /* Pack bit 13. */
ecc_buffer[(13+2)/8] = ((UCHAR)(ecc_buffer[(13+2)/8] | ((odd_byte_parity >> 2) & 1) << (13+2)%8) & 0xFF); ecc_buffer[(13+2)/8] = ((UCHAR)(ecc_buffer[(13+2)/8] | ((odd_byte_parity >> 2) & 1) << (13+2)%8) & 0xFF);
/* Pack bit 12. */ /* Pack bit 12. */
ecc_buffer[(12+2)/8] = ((UCHAR)(ecc_buffer[(12+2)/8] | ((even_byte_parity >> 2) & 1) << (12+2)%8) & 0xFF); ecc_buffer[(12+2)/8] = ((UCHAR)(ecc_buffer[(12+2)/8] | ((even_byte_parity >> 2) & 1) << (12+2)%8) & 0xFF);
@@ -199,18 +187,18 @@ USHORT odd_byte_parity;
/* Pack bit 10. */ /* Pack bit 10. */
ecc_buffer[(10+2)/8] = ((UCHAR)(ecc_buffer[(10+2)/8] | ((even_byte_parity >> 1) & 1) << (10+2)%8) & 0xFF); ecc_buffer[(10+2)/8] = ((UCHAR)(ecc_buffer[(10+2)/8] | ((even_byte_parity >> 1) & 1) << (10+2)%8) & 0xFF);
/* Pack bit 9. */ /* Pack bit 9. */
ecc_buffer[(9+2)/8] = ((UCHAR)(ecc_buffer[(9+2)/8] | ((odd_byte_parity >> 0) & 1) << (9+2)%8) & 0xFF); ecc_buffer[(9+2)/8] = ((UCHAR)(ecc_buffer[(9+2)/8] | ((odd_byte_parity >> 0) & 1) << (9+2)%8) & 0xFF);
/* Pack bit 8. */ /* Pack bit 8. */
ecc_buffer[(8+2)/8] = ((UCHAR)(ecc_buffer[(8+2)/8] | ((even_byte_parity >> 0) & 1) << (8+2)%8) & 0xFF); ecc_buffer[(8+2)/8] = ((UCHAR)(ecc_buffer[(8+2)/8] | ((even_byte_parity >> 0) & 1) << (8+2)%8) & 0xFF);
/* Pack bit 7. */ /* Pack bit 7. */
ecc_buffer[(7+2)/8] = ((UCHAR)(ecc_buffer[(7+2)/8] | ((odd_bit_parity >> 3) & 1) << (7+2)%8) & 0xFF); ecc_buffer[(7+2)/8] = ((UCHAR)(ecc_buffer[(7+2)/8] | ((odd_bit_parity >> 3) & 1) << (7+2)%8) & 0xFF);
/* Pack bit 6. */ /* Pack bit 6. */
ecc_buffer[(6+2)/8] = ((UCHAR)(ecc_buffer[(6+2)/8] | ((even_bit_parity >> 3) & 1) << (6+2)%8) & 0xFF); ecc_buffer[(6+2)/8] = ((UCHAR)(ecc_buffer[(6+2)/8] | ((even_bit_parity >> 3) & 1) << (6+2)%8) & 0xFF);
/* Pack bit 5. */ /* Pack bit 5. */
ecc_buffer[(5+2)/8] = ((UCHAR)(ecc_buffer[(5+2)/8] | ((odd_bit_parity >> 2) & 1) << (5+2)%8) & 0xFF); ecc_buffer[(5+2)/8] = ((UCHAR)(ecc_buffer[(5+2)/8] | ((odd_bit_parity >> 2) & 1) << (5+2)%8) & 0xFF);
@@ -223,10 +211,10 @@ USHORT odd_byte_parity;
/* Pack bit 2. */ /* Pack bit 2. */
ecc_buffer[(2+2)/8] = ((UCHAR)(ecc_buffer[(2+2)/8] | ((even_bit_parity >> 1) & 1) << (2+2)%8) & 0xFF); ecc_buffer[(2+2)/8] = ((UCHAR)(ecc_buffer[(2+2)/8] | ((even_bit_parity >> 1) & 1) << (2+2)%8) & 0xFF);
/* Pack bit 1. */ /* Pack bit 1. */
ecc_buffer[(1+2)/8] = ((UCHAR)(ecc_buffer[(1+2)/8] | ((odd_bit_parity >> 0) & 1) << (1+2)%8) & 0xFF); ecc_buffer[(1+2)/8] = ((UCHAR)(ecc_buffer[(1+2)/8] | ((odd_bit_parity >> 0) & 1) << (1+2)%8) & 0xFF);
/* Pack bit 0. */ /* Pack bit 0. */
ecc_buffer[(0+2)/8] = ((UCHAR)(ecc_buffer[(0+2)/8] | ((even_bit_parity >> 0) & 1) << (0+2)%8) & 0xFF); ecc_buffer[(0+2)/8] = ((UCHAR)(ecc_buffer[(0+2)/8] | ((even_bit_parity >> 0) & 1) << (0+2)%8) & 0xFF);
ecc_buffer[0] = (UCHAR)~ecc_buffer[0]; ecc_buffer[0] = (UCHAR)~ecc_buffer[0];
+30 -35
View File
@@ -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 * This program and the accompanying materials are made available under the
* terms of the MIT License which is available at * terms of the MIT License which is available at
* https://opensource.org/licenses/MIT. * https://opensource.org/licenses/MIT.
* *
* SPDX-License-Identifier: MIT * SPDX-License-Identifier: MIT
**************************************************************************/ **************************************************************************/
/**************************************************************************/ /**************************************************************************/
/**************************************************************************/ /**************************************************************************/
/** */ /** */
/** LevelX Component */ /** LevelX Component */
/** */ /** */
/** NAND Flash */ /** NAND Flash */
/** */ /** */
@@ -34,42 +35,36 @@
#include "lx_api.h" #include "lx_api.h"
/**************************************************************************/ /**************************************************************************/
/* */ /* */
/* FUNCTION RELEASE */ /* FUNCTION RELEASE */
/* */ /* */
/* _lx_nand_flash_block_allocate PORTABLE C */ /* _lx_nand_flash_block_allocate PORTABLE C */
/* 6.2.1 */ /* 6.2.1 */
/* AUTHOR */ /* AUTHOR */
/* */ /* */
/* Xiuwen Cai, Microsoft Corporation */ /* Xiuwen Cai, Microsoft Corporation */
/* */ /* */
/* DESCRIPTION */ /* DESCRIPTION */
/* */
/* This function attempts to get a block in the free block list. */
/* */
/* INPUT */
/* */
/* nand_flash NAND flash instance */
/* block Return block number */
/* */
/* OUTPUT */
/* */
/* return status */
/* */
/* CALLS */
/* */
/* None */
/* */
/* CALLED BY */
/* */
/* Internal LevelX */
/* */
/* RELEASE HISTORY */
/* */
/* DATE NAME DESCRIPTION */
/* */ /* */
/* 03-08-2023 Xiuwen Cai Initial Version 6.2.1 */ /* This function attempts to get a block in the free block list. */
/* */
/* INPUT */
/* */
/* nand_flash NAND flash instance */
/* block Return block number */
/* */
/* OUTPUT */
/* */
/* return status */
/* */
/* CALLS */
/* */
/* None */
/* */
/* CALLED BY */
/* */
/* Internal LevelX */
/* */ /* */
/**************************************************************************/ /**************************************************************************/
UINT _lx_nand_flash_block_allocate(LX_NAND_FLASH* nand_flash, ULONG* block) UINT _lx_nand_flash_block_allocate(LX_NAND_FLASH* nand_flash, ULONG* block)
+39 -44
View File
@@ -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 * This program and the accompanying materials are made available under the
* terms of the MIT License which is available at * terms of the MIT License which is available at
* https://opensource.org/licenses/MIT. * https://opensource.org/licenses/MIT.
* *
* SPDX-License-Identifier: MIT * SPDX-License-Identifier: MIT
**************************************************************************/ **************************************************************************/
/**************************************************************************/ /**************************************************************************/
/**************************************************************************/ /**************************************************************************/
/** */ /** */
/** LevelX Component */ /** LevelX Component */
/** */ /** */
/** NAND Flash */ /** NAND Flash */
/** */ /** */
@@ -34,55 +35,49 @@
#include "lx_api.h" #include "lx_api.h"
/**************************************************************************/ /**************************************************************************/
/* */ /* */
/* FUNCTION RELEASE */ /* FUNCTION RELEASE */
/* */ /* */
/* _lx_nand_flash_block_data_move PORTABLE C */ /* _lx_nand_flash_block_data_move PORTABLE C */
/* 6.2.1 */ /* 6.2.1 */
/* AUTHOR */ /* AUTHOR */
/* */ /* */
/* Xiuwen Cai, Microsoft Corporation */ /* Xiuwen Cai, Microsoft Corporation */
/* */ /* */
/* DESCRIPTION */ /* DESCRIPTION */
/* */ /* */
/* This function finds a block with less erase count and copies pages */ /* This function finds a block with less erase count and copies pages */
/* into new block. */ /* into new block. */
/* */ /* */
/* INPUT */ /* INPUT */
/* */ /* */
/* nand_flash NAND flash instance */ /* nand_flash NAND flash instance */
/* new_block New block number */ /* new_block New block number */
/* */ /* */
/* OUTPUT */ /* OUTPUT */
/* */ /* */
/* return status */ /* return status */
/* */ /* */
/* CALLS */ /* CALLS */
/* */ /* */
/* _lx_nand_flash_mapped_block_list_get Get mapped block index */ /* _lx_nand_flash_mapped_block_list_get Get mapped block index */
/* _lx_nand_flash_block_find Find the mapped block */ /* _lx_nand_flash_block_find Find the mapped block */
/* _lx_nand_flash_data_page_copy Copy data pages */ /* _lx_nand_flash_data_page_copy Copy data pages */
/* _lx_nand_flash_free_block_list_add Add free block to list */ /* _lx_nand_flash_free_block_list_add Add free block to list */
/* _lx_nand_flash_block_status_set Set block status */ /* _lx_nand_flash_block_status_set Set block status */
/* _lx_nand_flash_block_mapping_set Set block mapping */ /* _lx_nand_flash_block_mapping_set Set block mapping */
/* _lx_nand_flash_mapped_block_list_add Add mapped block to list */ /* _lx_nand_flash_mapped_block_list_add Add mapped block to list */
/* _lx_nand_flash_driver_block_erase Erase block */ /* _lx_nand_flash_driver_block_erase Erase block */
/* _lx_nand_flash_erase_count_set Set erase count */ /* _lx_nand_flash_erase_count_set Set erase count */
/* _lx_nand_flash_free_block_list_add Add free block to list */ /* _lx_nand_flash_free_block_list_add Add free block to list */
/* _lx_nand_flash_system_error Internal system error handler */ /* _lx_nand_flash_system_error Internal system error handler */
/* tx_mutex_get Get thread protection */ /* tx_mutex_get Get thread protection */
/* tx_mutex_put Release thread protection */ /* tx_mutex_put Release thread protection */
/* */
/* CALLED BY */
/* */
/* Application Code */
/* */
/* RELEASE HISTORY */
/* */
/* DATE NAME DESCRIPTION */
/* */ /* */
/* 03-08-2023 Xiuwen Cai Initial Version 6.2.1 */ /* CALLED BY */
/* */
/* Application Code */
/* */ /* */
/**************************************************************************/ /**************************************************************************/
UINT _lx_nand_flash_block_data_move(LX_NAND_FLASH *nand_flash, ULONG new_block) UINT _lx_nand_flash_block_data_move(LX_NAND_FLASH *nand_flash, ULONG new_block)
+37 -42
View File
@@ -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 * This program and the accompanying materials are made available under the
* terms of the MIT License which is available at * terms of the MIT License which is available at
* https://opensource.org/licenses/MIT. * https://opensource.org/licenses/MIT.
* *
* SPDX-License-Identifier: MIT * SPDX-License-Identifier: MIT
**************************************************************************/ **************************************************************************/
/**************************************************************************/ /**************************************************************************/
/**************************************************************************/ /**************************************************************************/
/** */ /** */
/** LevelX Component */ /** LevelX Component */
/** */ /** */
/** NAND Flash */ /** NAND Flash */
/** */ /** */
@@ -34,49 +35,43 @@
#include "lx_api.h" #include "lx_api.h"
/**************************************************************************/ /**************************************************************************/
/* */ /* */
/* FUNCTION RELEASE */ /* FUNCTION RELEASE */
/* */ /* */
/* _lx_nand_flash_block_find PORTABLE C */ /* _lx_nand_flash_block_find PORTABLE C */
/* 6.2.1 */ /* 6.2.1 */
/* AUTHOR */ /* AUTHOR */
/* */ /* */
/* Xiuwen Cai, Microsoft Corporation */ /* Xiuwen Cai, Microsoft Corporation */
/* */ /* */
/* DESCRIPTION */ /* DESCRIPTION */
/* */
/* This function attempts to find the mapped block for the logical */
/* sector in the mapping table. */
/* */
/* INPUT */
/* */
/* nand_flash NAND flash instance */
/* logical_sector Logical sector number */
/* superceded_check Check for page being */
/* superceded (can happen if */
/* on interruptions of page */
/* write) */
/* block Destination for block */
/* page Destination for page */
/* */
/* OUTPUT */
/* */
/* return status */
/* */
/* CALLS */
/* */
/* None */
/* */
/* CALLED BY */
/* */
/* Internal LevelX */
/* */
/* RELEASE HISTORY */
/* */
/* DATE NAME DESCRIPTION */
/* */ /* */
/* 03-08-2023 Xiuwen Cai Initial Version 6.2.1 */ /* This function attempts to find the mapped block for the logical */
/* sector in the mapping table. */
/* */
/* INPUT */
/* */
/* nand_flash NAND flash instance */
/* logical_sector Logical sector number */
/* superceded_check Check for page being */
/* superceded (can happen if */
/* on interruptions of page */
/* write) */
/* block Destination for block */
/* page Destination for page */
/* */
/* OUTPUT */
/* */
/* return status */
/* */
/* CALLS */
/* */
/* None */
/* */
/* CALLED BY */
/* */
/* Internal LevelX */
/* */ /* */
/**************************************************************************/ /**************************************************************************/
UINT _lx_nand_flash_block_find(LX_NAND_FLASH *nand_flash, ULONG logical_sector, ULONG *block, USHORT *block_status) UINT _lx_nand_flash_block_find(LX_NAND_FLASH *nand_flash, ULONG logical_sector, ULONG *block, USHORT *block_status)
+33 -38
View File
@@ -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 * This program and the accompanying materials are made available under the
* terms of the MIT License which is available at * terms of the MIT License which is available at
* https://opensource.org/licenses/MIT. * https://opensource.org/licenses/MIT.
* *
* SPDX-License-Identifier: MIT * SPDX-License-Identifier: MIT
**************************************************************************/ **************************************************************************/
/**************************************************************************/ /**************************************************************************/
/**************************************************************************/ /**************************************************************************/
/** */ /** */
/** LevelX Component */ /** LevelX Component */
/** */ /** */
/** NAND Flash */ /** NAND Flash */
/** */ /** */
@@ -34,43 +35,37 @@
#include "lx_api.h" #include "lx_api.h"
/**************************************************************************/ /**************************************************************************/
/* */ /* */
/* FUNCTION RELEASE */ /* FUNCTION RELEASE */
/* */ /* */
/* _lx_nand_flash_block_mapping_set PORTABLE C */ /* _lx_nand_flash_block_mapping_set PORTABLE C */
/* 6.2.1 */ /* 6.2.1 */
/* AUTHOR */ /* AUTHOR */
/* */ /* */
/* Xiuwen Cai, Microsoft Corporation */ /* Xiuwen Cai, Microsoft Corporation */
/* */ /* */
/* DESCRIPTION */ /* DESCRIPTION */
/* */
/* This function sets block mappings. */
/* */
/* INPUT */
/* */
/* nand_flash NAND flash instance */
/* logical_sector Logical sector number */
/* block Block number */
/* */
/* OUTPUT */
/* */
/* return status */
/* */
/* CALLS */
/* */
/* _lx_nand_flash_metadata_write Write metadata */
/* */
/* CALLED BY */
/* */
/* Internal LevelX */
/* */
/* RELEASE HISTORY */
/* */
/* DATE NAME DESCRIPTION */
/* */ /* */
/* 03-08-2023 Xiuwen Cai Initial Version 6.2.1 */ /* This function sets block mappings. */
/* */
/* INPUT */
/* */
/* nand_flash NAND flash instance */
/* logical_sector Logical sector number */
/* block Block number */
/* */
/* OUTPUT */
/* */
/* return status */
/* */
/* CALLS */
/* */
/* _lx_nand_flash_metadata_write Write metadata */
/* */
/* CALLED BY */
/* */
/* Internal LevelX */
/* */ /* */
/**************************************************************************/ /**************************************************************************/
UINT _lx_nand_flash_block_mapping_set(LX_NAND_FLASH *nand_flash, ULONG logical_sector, ULONG block) UINT _lx_nand_flash_block_mapping_set(LX_NAND_FLASH *nand_flash, ULONG logical_sector, ULONG block)
@@ -99,8 +94,8 @@ UINT status;
page_number = (UCHAR)(block_mapping_index * sizeof(*nand_flash -> lx_nand_flash_block_mapping_table) / nand_flash -> lx_nand_flash_bytes_per_page); page_number = (UCHAR)(block_mapping_index * sizeof(*nand_flash -> lx_nand_flash_block_mapping_table) / nand_flash -> lx_nand_flash_bytes_per_page);
/* Save the mapping table. */ /* Save the mapping table. */
status = _lx_nand_flash_metadata_write(nand_flash, ((UCHAR*)nand_flash -> lx_nand_flash_block_mapping_table) + status = _lx_nand_flash_metadata_write(nand_flash, ((UCHAR*)nand_flash -> lx_nand_flash_block_mapping_table) +
page_number * nand_flash -> lx_nand_flash_bytes_per_page, page_number * nand_flash -> lx_nand_flash_bytes_per_page,
LX_NAND_PAGE_TYPE_BLOCK_MAPPING_TABLE | page_number); LX_NAND_PAGE_TYPE_BLOCK_MAPPING_TABLE | page_number);
/* Return status. */ /* Return status. */
+32 -37
View File
@@ -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 * This program and the accompanying materials are made available under the
* terms of the MIT License which is available at * terms of the MIT License which is available at
* https://opensource.org/licenses/MIT. * https://opensource.org/licenses/MIT.
* *
* SPDX-License-Identifier: MIT * SPDX-License-Identifier: MIT
**************************************************************************/ **************************************************************************/
/**************************************************************************/ /**************************************************************************/
/**************************************************************************/ /**************************************************************************/
/** */ /** */
/** LevelX Component */ /** LevelX Component */
/** */ /** */
/** NAND Flash */ /** NAND Flash */
/** */ /** */
@@ -34,43 +35,37 @@
#include "lx_api.h" #include "lx_api.h"
/**************************************************************************/ /**************************************************************************/
/* */ /* */
/* FUNCTION RELEASE */ /* FUNCTION RELEASE */
/* */ /* */
/* _lx_nand_flash_block_status_set PORTABLE C */ /* _lx_nand_flash_block_status_set PORTABLE C */
/* 6.2.1 */ /* 6.2.1 */
/* AUTHOR */ /* AUTHOR */
/* */ /* */
/* Xiuwen Cai, Microsoft Corporation */ /* Xiuwen Cai, Microsoft Corporation */
/* */ /* */
/* DESCRIPTION */ /* DESCRIPTION */
/* */
/* This function sets block status. */
/* */
/* INPUT */
/* */
/* nand_flash NAND flash instance */
/* block Block number */
/* block_status Block status */
/* */
/* OUTPUT */
/* */
/* return status */
/* */
/* CALLS */
/* */
/* _lx_nand_flash_metadata_write Write metadata */
/* */
/* CALLED BY */
/* */
/* Internal LevelX */
/* */
/* RELEASE HISTORY */
/* */
/* DATE NAME DESCRIPTION */
/* */ /* */
/* 03-08-2023 Xiuwen Cai Initial Version 6.2.1 */ /* This function sets block status. */
/* */
/* INPUT */
/* */
/* nand_flash NAND flash instance */
/* block Block number */
/* block_status Block status */
/* */
/* OUTPUT */
/* */
/* return status */
/* */
/* CALLS */
/* */
/* _lx_nand_flash_metadata_write Write metadata */
/* */
/* CALLED BY */
/* */
/* Internal LevelX */
/* */ /* */
/**************************************************************************/ /**************************************************************************/
UINT _lx_nand_flash_block_status_set(LX_NAND_FLASH *nand_flash, ULONG block, ULONG block_status) UINT _lx_nand_flash_block_status_set(LX_NAND_FLASH *nand_flash, ULONG block, ULONG block_status)
@@ -87,7 +82,7 @@ UINT status;
page_number = (UCHAR)(block * sizeof(*nand_flash -> lx_nand_flash_block_status_table) / nand_flash -> lx_nand_flash_bytes_per_page); page_number = (UCHAR)(block * sizeof(*nand_flash -> lx_nand_flash_block_status_table) / nand_flash -> lx_nand_flash_bytes_per_page);
/* Save the status table. */ /* Save the status table. */
status = _lx_nand_flash_metadata_write(nand_flash, ((UCHAR*)nand_flash -> lx_nand_flash_block_status_table) + status = _lx_nand_flash_metadata_write(nand_flash, ((UCHAR*)nand_flash -> lx_nand_flash_block_status_table) +
page_number * nand_flash -> lx_nand_flash_bytes_per_page, LX_NAND_PAGE_TYPE_BLOCK_STATUS_TABLE | page_number); page_number * nand_flash -> lx_nand_flash_bytes_per_page, LX_NAND_PAGE_TYPE_BLOCK_STATUS_TABLE | page_number);
/* Return status. */ /* Return status. */
+32 -41
View File
@@ -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 * This program and the accompanying materials are made available under the
* terms of the MIT License which is available at * terms of the MIT License which is available at
* https://opensource.org/licenses/MIT. * https://opensource.org/licenses/MIT.
* *
* SPDX-License-Identifier: MIT * SPDX-License-Identifier: MIT
**************************************************************************/ **************************************************************************/
/**************************************************************************/ /**************************************************************************/
/**************************************************************************/ /**************************************************************************/
/** */ /** */
/** LevelX Component */ /** LevelX Component */
/** */ /** */
/** NAND Flash */ /** NAND Flash */
/** */ /** */
@@ -34,45 +35,35 @@
#include "lx_api.h" #include "lx_api.h"
/**************************************************************************/ /**************************************************************************/
/* */ /* */
/* FUNCTION RELEASE */ /* FUNCTION RELEASE */
/* */ /* */
/* _lx_nand_flash_close PORTABLE C */ /* _lx_nand_flash_close PORTABLE C */
/* 6.1.7 */ /* 6.1.7 */
/* AUTHOR */ /* AUTHOR */
/* */ /* */
/* William E. Lamie, Microsoft Corporation */ /* William E. Lamie, Microsoft Corporation */
/* */ /* */
/* DESCRIPTION */ /* DESCRIPTION */
/* */
/* This function closes a NAND flash instance. */
/* */
/* INPUT */
/* */
/* nand_flash NAND flash instance */
/* */
/* OUTPUT */
/* */
/* return status */
/* */
/* CALLS */
/* */
/* tx_mutex_delete Delete thread-safe mutex */
/* */
/* CALLED BY */
/* */
/* Application Code */
/* */
/* RELEASE HISTORY */
/* */
/* DATE NAME DESCRIPTION */
/* */ /* */
/* 05-19-2020 William E. Lamie Initial Version 6.0 */ /* This function closes a NAND flash instance. */
/* 09-30-2020 William E. Lamie Modified comment(s), */ /* */
/* resulting in version 6.1 */ /* INPUT */
/* 06-02-2021 Bhupendra Naphade Modified comment(s), */ /* */
/* resulting in version 6.1.7 */ /* nand_flash NAND flash instance */
/* */
/* OUTPUT */
/* */
/* return status */
/* */
/* CALLS */
/* */
/* tx_mutex_delete Delete thread-safe mutex */
/* */
/* CALLED BY */
/* */
/* Application Code */
/* */ /* */
/**************************************************************************/ /**************************************************************************/
UINT _lx_nand_flash_close(LX_NAND_FLASH *nand_flash) UINT _lx_nand_flash_close(LX_NAND_FLASH *nand_flash)
@@ -105,9 +96,9 @@ LX_INTERRUPT_SAVE_AREA
/* See if we have to update the opened list head pointer. */ /* See if we have to update the opened list head pointer. */
if (_lx_nand_flash_opened_ptr == nand_flash) if (_lx_nand_flash_opened_ptr == nand_flash)
{ {
/* Yes, move the head pointer to the next opened NAND flash. */ /* Yes, move the head pointer to the next opened NAND flash. */
_lx_nand_flash_opened_ptr = nand_flash -> lx_nand_flash_open_next; _lx_nand_flash_opened_ptr = nand_flash -> lx_nand_flash_open_next;
} }
} }
@@ -116,7 +107,7 @@ LX_INTERRUPT_SAVE_AREA
/* Finally, indicate that this NAND flash is closed. */ /* Finally, indicate that this NAND flash is closed. */
nand_flash -> lx_nand_flash_state = LX_NAND_FLASH_CLOSED; nand_flash -> lx_nand_flash_state = LX_NAND_FLASH_CLOSED;
/* Restore interrupt posture. */ /* Restore interrupt posture. */
LX_RESTORE LX_RESTORE
+39 -48
View File
@@ -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 * This program and the accompanying materials are made available under the
* terms of the MIT License which is available at * terms of the MIT License which is available at
* https://opensource.org/licenses/MIT. * https://opensource.org/licenses/MIT.
* *
* SPDX-License-Identifier: MIT * SPDX-License-Identifier: MIT
**************************************************************************/ **************************************************************************/
/**************************************************************************/ /**************************************************************************/
/**************************************************************************/ /**************************************************************************/
/** */ /** */
/** LevelX Component */ /** LevelX Component */
/** */ /** */
/** NAND Flash */ /** NAND Flash */
/** */ /** */
@@ -34,54 +35,44 @@
#include "lx_api.h" #include "lx_api.h"
/**************************************************************************/ /**************************************************************************/
/* */ /* */
/* FUNCTION RELEASE */ /* FUNCTION RELEASE */
/* */ /* */
/* _lx_nand_flash_data_page_copy PORTABLE C */ /* _lx_nand_flash_data_page_copy PORTABLE C */
/* 6.4.0 */ /* 6.4.0 */
/* AUTHOR */ /* AUTHOR */
/* */ /* */
/* Xiuwen Cai, Microsoft Corporation */ /* Xiuwen Cai, Microsoft Corporation */
/* */ /* */
/* DESCRIPTION */ /* DESCRIPTION */
/* */
/* This function copies logical sectors into new block. */
/* */
/* INPUT */
/* */
/* nand_flash NAND flash instance */
/* logical_sector Logical sector number */
/* source_block Source block number */
/* src_block_status Source block status */
/* destination_block Destination block number */
/* dest_block_status_ptr Pointer to destination block */
/* status */
/* sectors Number of sectors to copy */
/* */
/* OUTPUT */
/* */
/* return status */
/* */
/* CALLS */
/* */
/* lx_nand_flash_driver_pages_copy Driver pages copy */
/* lx_nand_flash_driver_pages_read Driver pages read */
/* _lx_nand_flash_system_error Internal system error handler */
/* */
/* CALLED BY */
/* */
/* Internal LevelX */
/* */
/* RELEASE HISTORY */
/* */
/* DATE NAME DESCRIPTION */
/* */ /* */
/* 03-08-2023 Xiuwen Cai Initial Version 6.2.1 */ /* This function copies logical sectors into new block. */
/* 12-31-2023 Xiuwen Cai Modified comment(s), */ /* */
/* fixed sequential checking */ /* INPUT */
/* logic, */ /* */
/* resulting in version 6.4.0 */ /* nand_flash NAND flash instance */
/* logical_sector Logical sector number */
/* source_block Source block number */
/* src_block_status Source block status */
/* destination_block Destination block number */
/* dest_block_status_ptr Pointer to destination block */
/* status */
/* sectors Number of sectors to copy */
/* */
/* OUTPUT */
/* */
/* return status */
/* */
/* CALLS */
/* */
/* lx_nand_flash_driver_pages_copy Driver pages copy */
/* lx_nand_flash_driver_pages_read Driver pages read */
/* _lx_nand_flash_system_error Internal system error handler */
/* */
/* CALLED BY */
/* */
/* Internal LevelX */
/* */ /* */
/**************************************************************************/ /**************************************************************************/
UINT _lx_nand_flash_data_page_copy(LX_NAND_FLASH* nand_flash, ULONG logical_sector, ULONG source_block, USHORT src_block_status, UINT _lx_nand_flash_data_page_copy(LX_NAND_FLASH* nand_flash, ULONG logical_sector, ULONG source_block, USHORT src_block_status,
@@ -200,7 +191,7 @@ ULONG number_of_pages;
source_page = (LONG)(logical_sector % nand_flash -> lx_nand_flash_pages_per_block); source_page = (LONG)(logical_sector % nand_flash -> lx_nand_flash_pages_per_block);
/* Check if the page to copy is greater than the available pages. */ /* Check if the page to copy is greater than the available pages. */
number_of_pages = ((ULONG)source_page + sectors) > available_pages ? number_of_pages = ((ULONG)source_page + sectors) > available_pages ?
(available_pages > (ULONG)source_page ? available_pages - (ULONG)source_page : 0) : sectors; (available_pages > (ULONG)source_page ? available_pages - (ULONG)source_page : 0) : sectors;
/* Check if there is any pages to be copied. */ /* Check if there is any pages to be copied. */
+33 -45
View File
@@ -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 * This program and the accompanying materials are made available under the
* terms of the MIT License which is available at * terms of the MIT License which is available at
* https://opensource.org/licenses/MIT. * https://opensource.org/licenses/MIT.
* *
* SPDX-License-Identifier: MIT * SPDX-License-Identifier: MIT
**************************************************************************/ **************************************************************************/
/**************************************************************************/ /**************************************************************************/
/**************************************************************************/ /**************************************************************************/
/** */ /** */
/** LevelX Component */ /** LevelX Component */
/** */ /** */
/** NAND Flash */ /** NAND Flash */
/** */ /** */
@@ -34,56 +35,43 @@
#include "lx_api.h" #include "lx_api.h"
/**************************************************************************/ /**************************************************************************/
/* */ /* */
/* FUNCTION RELEASE */ /* FUNCTION RELEASE */
/* */ /* */
/* _lx_nand_flash_defragment PORTABLE C */ /* _lx_nand_flash_defragment PORTABLE C */
/* 6.2.1 */ /* 6.2.1 */
/* AUTHOR */ /* AUTHOR */
/* */ /* */
/* William E. Lamie, Microsoft Corporation */ /* William E. Lamie, Microsoft Corporation */
/* */ /* */
/* DESCRIPTION */ /* DESCRIPTION */
/* */
/* This function defragments the NAND flash. */
/* */
/* INPUT */
/* */
/* nand_flash NAND flash instance */
/* */
/* OUTPUT */
/* */
/* return status */
/* */
/* CALLS */
/* */
/* _lx_nand_flash_block_reclaim Reclaim a NAND flash block */
/* tx_mutex_get Get thread protection */
/* tx_mutex_put Release thread protection */
/* */
/* CALLED BY */
/* */
/* Application Code */
/* Internal LevelX */
/* */
/* RELEASE HISTORY */
/* */
/* DATE NAME DESCRIPTION */
/* */ /* */
/* 05-19-2020 William E. Lamie Initial Version 6.0 */ /* This function defragments the NAND flash. */
/* 09-30-2020 William E. Lamie Modified comment(s), */ /* */
/* resulting in version 6.1 */ /* INPUT */
/* 06-02-2021 Bhupendra Naphade Modified comment(s), */ /* */
/* resulting in version 6.1.7 */ /* nand_flash NAND flash instance */
/* 03-08-2023 Xiuwen Cai Modified comment(s), */ /* */
/* deprecated this API, */ /* OUTPUT */
/* resulting in version 6.2.1 */ /* */
/* return status */
/* */
/* CALLS */
/* */
/* _lx_nand_flash_block_reclaim Reclaim a NAND flash block */
/* tx_mutex_get Get thread protection */
/* tx_mutex_put Release thread protection */
/* */
/* CALLED BY */
/* */
/* Application Code */
/* Internal LevelX */
/* */ /* */
/**************************************************************************/ /**************************************************************************/
UINT _lx_nand_flash_defragment(LX_NAND_FLASH *nand_flash) UINT _lx_nand_flash_defragment(LX_NAND_FLASH *nand_flash)
{ {
LX_PARAMETER_NOT_USED(nand_flash); LX_PARAMETER_NOT_USED(nand_flash);
/* Return not supported. */ /* Return not supported. */
+31 -44
View File
@@ -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 * This program and the accompanying materials are made available under the
* terms of the MIT License which is available at * terms of the MIT License which is available at
* https://opensource.org/licenses/MIT. * https://opensource.org/licenses/MIT.
* *
* SPDX-License-Identifier: MIT * SPDX-License-Identifier: MIT
**************************************************************************/ **************************************************************************/
/**************************************************************************/ /**************************************************************************/
/**************************************************************************/ /**************************************************************************/
/** */ /** */
/** LevelX Component */ /** LevelX Component */
/** */ /** */
/** NAND Flash */ /** NAND Flash */
/** */ /** */
@@ -34,51 +35,37 @@
#include "lx_api.h" #include "lx_api.h"
/**************************************************************************/ /**************************************************************************/
/* */ /* */
/* FUNCTION RELEASE */ /* FUNCTION RELEASE */
/* */ /* */
/* _lx_nand_flash_driver_block_erase PORTABLE C */ /* _lx_nand_flash_driver_block_erase PORTABLE C */
/* 6.2.1 */ /* 6.2.1 */
/* AUTHOR */ /* AUTHOR */
/* */ /* */
/* William E. Lamie, Microsoft Corporation */ /* William E. Lamie, Microsoft Corporation */
/* */ /* */
/* DESCRIPTION */ /* DESCRIPTION */
/* */
/* This function calls the driver to erase a block. */
/* */
/* INPUT */
/* */
/* nand_flash NAND flash instance */
/* block Block number */
/* erase_count Erase count for this block */
/* */
/* OUTPUT */
/* */
/* Completion Status */
/* */
/* CALLS */
/* */
/* (lx_nand_flash_driver_block_erase) Driver erase block */
/* */
/* CALLED BY */
/* */
/* Internal LevelX */
/* */
/* RELEASE HISTORY */
/* */
/* DATE NAME DESCRIPTION */
/* */ /* */
/* 05-19-2020 William E. Lamie Initial Version 6.0 */ /* This function calls the driver to erase a block. */
/* 09-30-2020 William E. Lamie Modified comment(s), */ /* */
/* resulting in version 6.1 */ /* INPUT */
/* 06-02-2021 Bhupendra Naphade Modified comment(s), */ /* */
/* resulting in version 6.1.7 */ /* nand_flash NAND flash instance */
/* 03-08-2023 Xiuwen Cai Modified comment(s), */ /* block Block number */
/* removed cache support, */ /* erase_count Erase count for this block */
/* added new driver interface, */ /* */
/* resulting in version 6.2.1 */ /* OUTPUT */
/* */
/* Completion Status */
/* */
/* CALLS */
/* */
/* (lx_nand_flash_driver_block_erase) Driver erase block */
/* */
/* CALLED BY */
/* */
/* Internal LevelX */
/* */ /* */
/**************************************************************************/ /**************************************************************************/
UINT _lx_nand_flash_driver_block_erase(LX_NAND_FLASH *nand_flash, ULONG block, ULONG erase_count) UINT _lx_nand_flash_driver_block_erase(LX_NAND_FLASH *nand_flash, ULONG block, ULONG erase_count)
@@ -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 * This program and the accompanying materials are made available under the
* terms of the MIT License which is available at * terms of the MIT License which is available at
* https://opensource.org/licenses/MIT. * https://opensource.org/licenses/MIT.
* *
* SPDX-License-Identifier: MIT * SPDX-License-Identifier: MIT
**************************************************************************/ **************************************************************************/
/**************************************************************************/ /**************************************************************************/
/**************************************************************************/ /**************************************************************************/
/** */ /** */
/** LevelX Component */ /** LevelX Component */
/** */ /** */
/** NAND Flash */ /** NAND Flash */
/** */ /** */
@@ -34,51 +35,38 @@
#include "lx_api.h" #include "lx_api.h"
/**************************************************************************/ /**************************************************************************/
/* */ /* */
/* FUNCTION RELEASE */ /* FUNCTION RELEASE */
/* */ /* */
/* _lx_nand_flash_driver_block_erased_verify PORTABLE C */ /* _lx_nand_flash_driver_block_erased_verify PORTABLE C */
/* 6.2.1 */ /* 6.2.1 */
/* AUTHOR */ /* AUTHOR */
/* */ /* */
/* William E. Lamie, Microsoft Corporation */ /* William E. Lamie, Microsoft Corporation */
/* */ /* */
/* DESCRIPTION */ /* DESCRIPTION */
/* */
/* This function calls the driver to verify the block was erased. */
/* */
/* INPUT */
/* */
/* nand_flash NAND flash instance */
/* block Block number */
/* page Page number */
/* */
/* OUTPUT */
/* */
/* Completion Status */
/* */
/* CALLS */
/* */
/* (lx_nand_flash_driver_block_erased_verify) */
/* Driver verify page erased */
/* */
/* CALLED BY */
/* */
/* Internal LevelX */
/* */
/* RELEASE HISTORY */
/* */
/* DATE NAME DESCRIPTION */
/* */ /* */
/* 05-19-2020 William E. Lamie Initial Version 6.0 */ /* This function calls the driver to verify the block was erased. */
/* 09-30-2020 William E. Lamie Modified comment(s), */ /* */
/* resulting in version 6.1 */ /* INPUT */
/* 06-02-2021 Bhupendra Naphade Modified comment(s), */ /* */
/* resulting in version 6.1.7 */ /* nand_flash NAND flash instance */
/* 03-08-2023 Xiuwen Cai Modified comment(s), */ /* block Block number */
/* added new driver interface, */ /* page Page number */
/* resulting in version 6.2.1 */ /* */
/* OUTPUT */
/* */
/* Completion Status */
/* */
/* CALLS */
/* */
/* (lx_nand_flash_driver_block_erased_verify) */
/* Driver verify page erased */
/* */
/* CALLED BY */
/* */
/* Internal LevelX */
/* */ /* */
/**************************************************************************/ /**************************************************************************/
UINT _lx_nand_flash_driver_block_erased_verify(LX_NAND_FLASH *nand_flash, ULONG block) UINT _lx_nand_flash_driver_block_erased_verify(LX_NAND_FLASH *nand_flash, ULONG block)
@@ -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 * This program and the accompanying materials are made available under the
* terms of the MIT License which is available at * terms of the MIT License which is available at
* https://opensource.org/licenses/MIT. * https://opensource.org/licenses/MIT.
* *
* SPDX-License-Identifier: MIT * SPDX-License-Identifier: MIT
**************************************************************************/ **************************************************************************/
/**************************************************************************/ /**************************************************************************/
/**************************************************************************/ /**************************************************************************/
/** */ /** */
/** LevelX Component */ /** LevelX Component */
/** */ /** */
/** NAND Flash */ /** NAND Flash */
/** */ /** */
@@ -34,53 +35,39 @@
#include "lx_api.h" #include "lx_api.h"
/**************************************************************************/ /**************************************************************************/
/* */ /* */
/* FUNCTION RELEASE */ /* FUNCTION RELEASE */
/* */ /* */
/* _lx_nand_flash_driver_block_status_get PORTABLE C */ /* _lx_nand_flash_driver_block_status_get PORTABLE C */
/* 6.2.1 */ /* 6.2.1 */
/* AUTHOR */ /* AUTHOR */
/* */ /* */
/* William E. Lamie, Microsoft Corporation */ /* William E. Lamie, Microsoft Corporation */
/* */ /* */
/* DESCRIPTION */ /* DESCRIPTION */
/* */
/* This function calls the driver to get the block status and */
/* updates the internal cache. */
/* */
/* INPUT */
/* */
/* nand_flash NAND flash instance */
/* block Block number */
/* bad_block_flag Pointer to Bad block flag */
/* */
/* OUTPUT */
/* */
/* Completion Status */
/* */
/* CALLS */
/* */
/* (lx_nand_flash_driver_block_status_get) */
/* NAND flash block status get */
/* */
/* CALLED BY */
/* */
/* Internal LevelX */
/* */
/* RELEASE HISTORY */
/* */
/* DATE NAME DESCRIPTION */
/* */ /* */
/* 05-19-2020 William E. Lamie Initial Version 6.0 */ /* This function calls the driver to get the block status and */
/* 09-30-2020 William E. Lamie Modified comment(s), */ /* updates the internal cache. */
/* resulting in version 6.1 */ /* */
/* 06-02-2021 Bhupendra Naphade Modified comment(s), */ /* INPUT */
/* resulting in version 6.1.7 */ /* */
/* 03-08-2023 Xiuwen Cai Modified comment(s), */ /* nand_flash NAND flash instance */
/* removed cache support, */ /* block Block number */
/* added new driver interface, */ /* bad_block_flag Pointer to Bad block flag */
/* resulting in version 6.2.1 */ /* */
/* OUTPUT */
/* */
/* Completion Status */
/* */
/* CALLS */
/* */
/* (lx_nand_flash_driver_block_status_get) */
/* NAND flash block status get */
/* */
/* CALLED BY */
/* */
/* Internal LevelX */
/* */ /* */
/**************************************************************************/ /**************************************************************************/
UINT _lx_nand_flash_driver_block_status_get(LX_NAND_FLASH *nand_flash, ULONG block, UCHAR *bad_block_flag) UINT _lx_nand_flash_driver_block_status_get(LX_NAND_FLASH *nand_flash, ULONG block, UCHAR *bad_block_flag)
@@ -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 * This program and the accompanying materials are made available under the
* terms of the MIT License which is available at * terms of the MIT License which is available at
* https://opensource.org/licenses/MIT. * https://opensource.org/licenses/MIT.
* *
* SPDX-License-Identifier: MIT * SPDX-License-Identifier: MIT
**************************************************************************/ **************************************************************************/
/**************************************************************************/ /**************************************************************************/
/**************************************************************************/ /**************************************************************************/
/** */ /** */
/** LevelX Component */ /** LevelX Component */
/** */ /** */
/** NAND Flash */ /** NAND Flash */
/** */ /** */
@@ -34,53 +35,39 @@
#include "lx_api.h" #include "lx_api.h"
/**************************************************************************/ /**************************************************************************/
/* */ /* */
/* FUNCTION RELEASE */ /* FUNCTION RELEASE */
/* */ /* */
/* _lx_nand_flash_driver_block_status_set PORTABLE C */ /* _lx_nand_flash_driver_block_status_set PORTABLE C */
/* 6.2.1 */ /* 6.2.1 */
/* AUTHOR */ /* AUTHOR */
/* */ /* */
/* William E. Lamie, Microsoft Corporation */ /* William E. Lamie, Microsoft Corporation */
/* */ /* */
/* DESCRIPTION */ /* DESCRIPTION */
/* */
/* This function calls the driver to set the block status and */
/* updates the internal cache. */
/* */
/* INPUT */
/* */
/* nand_flash NAND flash instance */
/* block Block number */
/* bad_block_flag Bad block flag */
/* */
/* OUTPUT */
/* */
/* Completion Status */
/* */
/* CALLS */
/* */
/* (lx_nand_flash_driver_block_status_set) */
/* NAND flash block status set */
/* */
/* CALLED BY */
/* */
/* Internal LevelX */
/* */
/* RELEASE HISTORY */
/* */
/* DATE NAME DESCRIPTION */
/* */ /* */
/* 05-19-2020 William E. Lamie Initial Version 6.0 */ /* This function calls the driver to set the block status and */
/* 09-30-2020 William E. Lamie Modified comment(s), */ /* updates the internal cache. */
/* resulting in version 6.1 */ /* */
/* 06-02-2021 Bhupendra Naphade Modified comment(s), */ /* INPUT */
/* resulting in version 6.1.7 */ /* */
/* 03-08-2023 Xiuwen Cai Modified comment(s), */ /* nand_flash NAND flash instance */
/* removed cache support, */ /* block Block number */
/* added new driver interface, */ /* bad_block_flag Bad block flag */
/* resulting in version 6.2.1 */ /* */
/* OUTPUT */
/* */
/* Completion Status */
/* */
/* CALLS */
/* */
/* (lx_nand_flash_driver_block_status_set) */
/* NAND flash block status set */
/* */
/* CALLED BY */
/* */
/* Internal LevelX */
/* */ /* */
/**************************************************************************/ /**************************************************************************/
UINT _lx_nand_flash_driver_block_status_set(LX_NAND_FLASH *nand_flash, ULONG block, UCHAR bad_block_flag) UINT _lx_nand_flash_driver_block_status_set(LX_NAND_FLASH *nand_flash, ULONG block, UCHAR bad_block_flag)
@@ -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 * This program and the accompanying materials are made available under the
* terms of the MIT License which is available at * terms of the MIT License which is available at
* https://opensource.org/licenses/MIT. * https://opensource.org/licenses/MIT.
* *
* SPDX-License-Identifier: MIT * SPDX-License-Identifier: MIT
**************************************************************************/ **************************************************************************/
/**************************************************************************/ /**************************************************************************/
/**************************************************************************/ /**************************************************************************/
/** */ /** */
/** LevelX Component */ /** LevelX Component */
/** */ /** */
/** NAND Flash */ /** NAND Flash */
/** */ /** */
@@ -34,51 +35,38 @@
#include "lx_api.h" #include "lx_api.h"
/**************************************************************************/ /**************************************************************************/
/* */ /* */
/* FUNCTION RELEASE */ /* FUNCTION RELEASE */
/* */ /* */
/* _lx_nand_flash_driver_page_erased_verify PORTABLE C */ /* _lx_nand_flash_driver_page_erased_verify PORTABLE C */
/* 6.2.1 */ /* 6.2.1 */
/* AUTHOR */ /* AUTHOR */
/* */ /* */
/* William E. Lamie, Microsoft Corporation */ /* William E. Lamie, Microsoft Corporation */
/* */ /* */
/* DESCRIPTION */ /* DESCRIPTION */
/* */
/* This function calls the driver to verify the page was erased. */
/* */
/* INPUT */
/* */
/* nand_flash NAND flash instance */
/* block Block number */
/* page Page number */
/* */
/* OUTPUT */
/* */
/* Completion Status */
/* */
/* CALLS */
/* */
/* (lx_nand_flash_driver_page_erased_verify) */
/* Driver verify page erased */
/* */
/* CALLED BY */
/* */
/* Internal LevelX */
/* */
/* RELEASE HISTORY */
/* */
/* DATE NAME DESCRIPTION */
/* */ /* */
/* 05-19-2020 William E. Lamie Initial Version 6.0 */ /* This function calls the driver to verify the page was erased. */
/* 09-30-2020 William E. Lamie Modified comment(s), */ /* */
/* resulting in version 6.1 */ /* INPUT */
/* 06-02-2021 Bhupendra Naphade Modified comment(s), */ /* */
/* resulting in version 6.1.7 */ /* nand_flash NAND flash instance */
/* 03-08-2023 Xiuwen Cai Modified comment(s), */ /* block Block number */
/* added new driver interface, */ /* page Page number */
/* resulting in version 6.2.1 */ /* */
/* OUTPUT */
/* */
/* Completion Status */
/* */
/* CALLS */
/* */
/* (lx_nand_flash_driver_page_erased_verify) */
/* Driver verify page erased */
/* */
/* CALLED BY */
/* */
/* Internal LevelX */
/* */ /* */
/**************************************************************************/ /**************************************************************************/
UINT _lx_nand_flash_driver_page_erased_verify(LX_NAND_FLASH *nand_flash, ULONG block, ULONG page) UINT _lx_nand_flash_driver_page_erased_verify(LX_NAND_FLASH *nand_flash, ULONG block, ULONG page)
+33 -38
View File
@@ -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 * This program and the accompanying materials are made available under the
* terms of the MIT License which is available at * terms of the MIT License which is available at
* https://opensource.org/licenses/MIT. * https://opensource.org/licenses/MIT.
* *
* SPDX-License-Identifier: MIT * SPDX-License-Identifier: MIT
**************************************************************************/ **************************************************************************/
/**************************************************************************/ /**************************************************************************/
/**************************************************************************/ /**************************************************************************/
/** */ /** */
/** LevelX Component */ /** LevelX Component */
/** */ /** */
/** NAND Flash */ /** NAND Flash */
/** */ /** */
@@ -34,43 +35,37 @@
#include "lx_api.h" #include "lx_api.h"
/**************************************************************************/ /**************************************************************************/
/* */ /* */
/* FUNCTION RELEASE */ /* FUNCTION RELEASE */
/* */ /* */
/* _lx_nand_flash_erase_count_set PORTABLE C */ /* _lx_nand_flash_erase_count_set PORTABLE C */
/* 6.2.1 */ /* 6.2.1 */
/* AUTHOR */ /* AUTHOR */
/* */ /* */
/* Xiuwen Cai, Microsoft Corporation */ /* Xiuwen Cai, Microsoft Corporation */
/* */ /* */
/* DESCRIPTION */ /* DESCRIPTION */
/* */
/* This function sets block erase count. */
/* */
/* INPUT */
/* */
/* nand_flash NAND flash instance */
/* block Block number */
/* erase_count Erase count */
/* */
/* OUTPUT */
/* */
/* return status */
/* */
/* CALLS */
/* */
/* _lx_nand_flash_metadata_write Write metadata */
/* */
/* CALLED BY */
/* */
/* Internal LevelX */
/* */
/* RELEASE HISTORY */
/* */
/* DATE NAME DESCRIPTION */
/* */ /* */
/* 03-08-2023 Xiuwen Cai Initial Version 6.2.1 */ /* This function sets block erase count. */
/* */
/* INPUT */
/* */
/* nand_flash NAND flash instance */
/* block Block number */
/* erase_count Erase count */
/* */
/* OUTPUT */
/* */
/* return status */
/* */
/* CALLS */
/* */
/* _lx_nand_flash_metadata_write Write metadata */
/* */
/* CALLED BY */
/* */
/* Internal LevelX */
/* */ /* */
/**************************************************************************/ /**************************************************************************/
UINT _lx_nand_flash_erase_count_set(LX_NAND_FLASH *nand_flash, ULONG block, UCHAR erase_count) UINT _lx_nand_flash_erase_count_set(LX_NAND_FLASH *nand_flash, ULONG block, UCHAR erase_count)
@@ -87,8 +82,8 @@ UINT status;
page_number = (UCHAR)(block * sizeof(*nand_flash -> lx_nand_flash_erase_count_table) / nand_flash -> lx_nand_flash_bytes_per_page); page_number = (UCHAR)(block * sizeof(*nand_flash -> lx_nand_flash_erase_count_table) / nand_flash -> lx_nand_flash_bytes_per_page);
/* Save the erase count table. */ /* Save the erase count table. */
status = _lx_nand_flash_metadata_write(nand_flash, ((UCHAR*)nand_flash -> lx_nand_flash_erase_count_table) + status = _lx_nand_flash_metadata_write(nand_flash, ((UCHAR*)nand_flash -> lx_nand_flash_erase_count_table) +
page_number * nand_flash -> lx_nand_flash_bytes_per_page, page_number * nand_flash -> lx_nand_flash_bytes_per_page,
LX_NAND_PAGE_TYPE_ERASE_COUNT_TABLE | page_number); LX_NAND_PAGE_TYPE_ERASE_COUNT_TABLE | page_number);
/* Return sector not found status. */ /* Return sector not found status. */
@@ -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 * This program and the accompanying materials are made available under the
* terms of the MIT License which is available at * terms of the MIT License which is available at
* https://opensource.org/licenses/MIT. * https://opensource.org/licenses/MIT.
* *
* SPDX-License-Identifier: MIT * SPDX-License-Identifier: MIT
**************************************************************************/ **************************************************************************/
/**************************************************************************/ /**************************************************************************/
/**************************************************************************/ /**************************************************************************/
/** */ /** */
/** LevelX Component */ /** LevelX Component */
/** */ /** */
/** NAND Flash */ /** NAND Flash */
/** */ /** */
@@ -34,53 +35,40 @@
#include "lx_api.h" #include "lx_api.h"
/**************************************************************************/ /**************************************************************************/
/* */ /* */
/* FUNCTION RELEASE */ /* FUNCTION RELEASE */
/* */ /* */
/* _lx_nand_flash_extended_cache_enable PORTABLE C */ /* _lx_nand_flash_extended_cache_enable PORTABLE C */
/* 6.2.1 */ /* 6.2.1 */
/* AUTHOR */ /* AUTHOR */
/* */ /* */
/* William E. Lamie, Microsoft Corporation */ /* William E. Lamie, Microsoft Corporation */
/* */ /* */
/* DESCRIPTION */ /* DESCRIPTION */
/* */
/* This function sets up the extended NAND cache for block status, */
/* page extra bytes, and page 0 contents. The routine will enable as */
/* many cache capabilities as possible until the supplied memory is */
/* exhausted. */
/* */
/* INPUT */
/* */
/* nand_flash NAND flash instance */
/* memory Pointer to memory for caches */
/* size Size of memory in bytes */
/* */
/* OUTPUT */
/* */
/* Completion Status */
/* */
/* CALLS */
/* */
/* None */
/* */
/* CALLED BY */
/* */
/* Internal LevelX */
/* */
/* RELEASE HISTORY */
/* */
/* DATE NAME DESCRIPTION */
/* */ /* */
/* 05-19-2020 William E. Lamie Initial Version 6.0 */ /* This function sets up the extended NAND cache for block status, */
/* 09-30-2020 William E. Lamie Modified comment(s), */ /* page extra bytes, and page 0 contents. The routine will enable as */
/* resulting in version 6.1 */ /* many cache capabilities as possible until the supplied memory is */
/* 06-02-2021 Bhupendra Naphade Modified comment(s), */ /* exhausted. */
/* resulting in version 6.1.7 */ /* */
/* 03-08-2023 Xiuwen Cai Modified comment(s), */ /* INPUT */
/* deprecated this API, */ /* */
/* resulting in version 6.2.1 */ /* nand_flash NAND flash instance */
/* memory Pointer to memory for caches */
/* size Size of memory in bytes */
/* */
/* OUTPUT */
/* */
/* Completion Status */
/* */
/* CALLS */
/* */
/* None */
/* */
/* CALLED BY */
/* */
/* Internal LevelX */
/* */ /* */
/**************************************************************************/ /**************************************************************************/
UINT _lx_nand_flash_extended_cache_enable(LX_NAND_FLASH *nand_flash, VOID *memory, ULONG size) UINT _lx_nand_flash_extended_cache_enable(LX_NAND_FLASH *nand_flash, VOID *memory, ULONG size)
@@ -89,7 +77,7 @@ UINT _lx_nand_flash_extended_cache_enable(LX_NAND_FLASH *nand_flash, VOID *mem
LX_PARAMETER_NOT_USED(nand_flash); LX_PARAMETER_NOT_USED(nand_flash);
LX_PARAMETER_NOT_USED(memory); LX_PARAMETER_NOT_USED(memory);
LX_PARAMETER_NOT_USED(size); LX_PARAMETER_NOT_USED(size);
/* Return not supported. */ /* Return not supported. */
return(LX_NOT_SUPPORTED); return(LX_NOT_SUPPORTED);
} }
+30 -29
View File
@@ -1,19 +1,20 @@
/*************************************************************************** /***************************************************************************
* Copyright (c) 2024 Microsoft Corporation * Copyright (c) 2024 Microsoft Corporation
* Copyright (c) 2026-present Eclipse ThreadX contributors
* Copyright (c) 2025 STMicroelectronics * Copyright (c) 2025 STMicroelectronics
* *
* This program and the accompanying materials are made available under the * This program and the accompanying materials are made available under the
* terms of the MIT License which is available at * terms of the MIT License which is available at
* https://opensource.org/licenses/MIT. * https://opensource.org/licenses/MIT.
* *
* SPDX-License-Identifier: MIT * SPDX-License-Identifier: MIT
**************************************************************************/ **************************************************************************/
/**************************************************************************/ /**************************************************************************/
/**************************************************************************/ /**************************************************************************/
/** */ /** */
/** LevelX Component */ /** LevelX Component */
/** */ /** */
/** NAND Flash */ /** NAND Flash */
/** */ /** */
@@ -35,42 +36,42 @@
#include "lx_api.h" #include "lx_api.h"
/**************************************************************************/ /**************************************************************************/
/* */ /* */
/* FUNCTION RELEASE */ /* FUNCTION RELEASE */
/* */ /* */
/* _lx_nand_flash_format PORTABLE C */ /* _lx_nand_flash_format PORTABLE C */
/* */ /* */
/* AUTHOR */ /* AUTHOR */
/* */ /* */
/* Xiuwen Cai, Microsoft Corporation */ /* Xiuwen Cai, Microsoft Corporation */
/* */ /* */
/* DESCRIPTION */ /* DESCRIPTION */
/* */ /* */
/* This function erases and formats a NAND flash. */ /* This function erases and formats a NAND flash. */
/* */ /* */
/* INPUT */ /* INPUT */
/* */ /* */
/* nand_flash NAND flash instance */ /* nand_flash NAND flash instance */
/* name Name of NAND flash instance */ /* name Name of NAND flash instance */
/* nand_driver_initialize Driver initialize */ /* nand_driver_initialize Driver initialize */
/* memory_ptr Pointer to memory used by the */ /* memory_ptr Pointer to memory used by the */
/* LevelX for this NAND. */ /* LevelX for this NAND. */
/* memory_size Size of memory - must at least*/ /* memory_size Size of memory - must at least*/
/* 7 * total block count + */ /* 7 * total block count + */
/* 2 * page size */ /* 2 * page size */
/* */ /* */
/* OUTPUT */ /* OUTPUT */
/* */ /* */
/* return status */ /* return status */
/* */ /* */
/* CALLS */ /* CALLS */
/* _lx_nand_flash_format_extended */ /* _lx_nand_flash_format_extended */
/* */ /* */
/* CALLED BY */ /* CALLED BY */
/* */ /* */
/* Application Code */ /* Application Code */
/* */ /* */
/**************************************************************************/ /**************************************************************************/
UINT _lx_nand_flash_format(LX_NAND_FLASH* nand_flash, CHAR* name, UINT _lx_nand_flash_format(LX_NAND_FLASH* nand_flash, CHAR* name,
UINT(*nand_driver_initialize)(LX_NAND_FLASH*), UINT(*nand_driver_initialize)(LX_NAND_FLASH*),
+44 -43
View File
@@ -1,19 +1,20 @@
/*************************************************************************** /***************************************************************************
* Copyright (c) 2024 Microsoft Corporation * Copyright (c) 2024 Microsoft Corporation
* Copyright (c) 2026-present Eclipse ThreadX contributors
* Copyright (c) 2025 STMicroelectronics * Copyright (c) 2025 STMicroelectronics
* *
* This program and the accompanying materials are made available under the * This program and the accompanying materials are made available under the
* terms of the MIT License which is available at * terms of the MIT License which is available at
* https://opensource.org/licenses/MIT. * https://opensource.org/licenses/MIT.
* *
* SPDX-License-Identifier: MIT * SPDX-License-Identifier: MIT
**************************************************************************/ **************************************************************************/
/**************************************************************************/ /**************************************************************************/
/**************************************************************************/ /**************************************************************************/
/** */ /** */
/** LevelX Component */ /** LevelX Component */
/** */ /** */
/** NAND Flash */ /** NAND Flash */
/** */ /** */
@@ -35,55 +36,55 @@
#include "lx_api.h" #include "lx_api.h"
/**************************************************************************/ /**************************************************************************/
/* */ /* */
/* FUNCTION RELEASE */ /* FUNCTION RELEASE */
/* */ /* */
/* _lx_nand_flash_format_extended PORTABLE C */ /* _lx_nand_flash_format_extended PORTABLE C */
/* */ /* */
/* AUTHOR */ /* AUTHOR */
/* */ /* */
/* Xiuwen Cai, Microsoft Corporation */ /* Xiuwen Cai, Microsoft Corporation */
/* */ /* */
/* DESCRIPTION */ /* DESCRIPTION */
/* */ /* */
/* This function erases and formats a NAND flash. */ /* This function erases and formats a NAND flash. */
/* */ /* */
/* INPUT */ /* INPUT */
/* */ /* */
/* nand_flash NAND flash instance */ /* nand_flash NAND flash instance */
/* name Name of NAND flash instance */ /* name Name of NAND flash instance */
/* nand_driver_initialize Driver initialize */ /* nand_driver_initialize Driver initialize */
/* nand_driver_info_ptr Driver user data pointer */ /* nand_driver_info_ptr Driver user data pointer */
/* memory_ptr Pointer to memory used by the */ /* memory_ptr Pointer to memory used by the */
/* LevelX for this NAND. */ /* LevelX for this NAND. */
/* memory_size Size of memory - must at least*/ /* memory_size Size of memory - must at least*/
/* 7 * total block count + */ /* 7 * total block count + */
/* 2 * page size */ /* 2 * page size */
/* */ /* */
/* OUTPUT */ /* OUTPUT */
/* */ /* */
/* return status */ /* return status */
/* */ /* */
/* CALLS */ /* CALLS */
/* */ /* */
/* (nand_driver_initialize) Driver initialize */ /* (nand_driver_initialize) Driver initialize */
/* LX_MEMSET Initialize memory */ /* LX_MEMSET Initialize memory */
/* _lx_nand_flash_memory_initialize Initialize buffer */ /* _lx_nand_flash_memory_initialize Initialize buffer */
/* _lx_nand_flash_driver_block_status_get */ /* _lx_nand_flash_driver_block_status_get */
/* Driver block status get */ /* Driver block status get */
/* _lx_nand_flash_driver_block_status_set */ /* _lx_nand_flash_driver_block_status_set */
/* Driver block status set */ /* Driver block status set */
/* _lx_nand_flash_metadata_build Build metadata */ /* _lx_nand_flash_metadata_build Build metadata */
/* _lx_nand_flash_metadata_write Write metadata */ /* _lx_nand_flash_metadata_write Write metadata */
/* _lx_nand_flash_driver_block_erase Driver block erase */ /* _lx_nand_flash_driver_block_erase Driver block erase */
/* _lx_nand_flash_system_error System error handler */ /* _lx_nand_flash_system_error System error handler */
/* tx_mutex_create Create thread-safe mutex */ /* tx_mutex_create Create thread-safe mutex */
/* */ /* */
/* CALLED BY */ /* CALLED BY */
/* */ /* */
/* Application Code */ /* Application Code */
/* */ /* */
/**************************************************************************/ /**************************************************************************/
UINT _lx_nand_flash_format_extended(LX_NAND_FLASH* nand_flash, CHAR* name, UINT _lx_nand_flash_format_extended(LX_NAND_FLASH* nand_flash, CHAR* name,
UINT(*nand_driver_initialize)(LX_NAND_FLASH*),VOID* nand_driver_info_ptr, UINT(*nand_driver_initialize)(LX_NAND_FLASH*),VOID* nand_driver_info_ptr,
@@ -242,7 +243,7 @@ UCHAR *page_buffer_ptr;
nand_flash -> lx_nand_flash_block_status_table[nand_flash -> lx_nand_flash_metadata_block_number_next] = LX_NAND_BLOCK_STATUS_ALLOCATED; nand_flash -> lx_nand_flash_block_status_table[nand_flash -> lx_nand_flash_metadata_block_number_next] = LX_NAND_BLOCK_STATUS_ALLOCATED;
nand_flash -> lx_nand_flash_block_status_table[nand_flash -> lx_nand_flash_backup_metadata_block_number] = (USHORT)nand_flash -> lx_nand_flash_backup_metadata_block_number_next; nand_flash -> lx_nand_flash_block_status_table[nand_flash -> lx_nand_flash_backup_metadata_block_number] = (USHORT)nand_flash -> lx_nand_flash_backup_metadata_block_number_next;
nand_flash -> lx_nand_flash_block_status_table[nand_flash -> lx_nand_flash_metadata_block_number] = (USHORT)nand_flash -> lx_nand_flash_metadata_block_number_next; nand_flash -> lx_nand_flash_block_status_table[nand_flash -> lx_nand_flash_metadata_block_number] = (USHORT)nand_flash -> lx_nand_flash_metadata_block_number_next;
/* Initialize the mapping table. */ /* Initialize the mapping table. */
LX_MEMSET(nand_flash -> lx_nand_flash_block_mapping_table, 0xFF, nand_flash -> lx_nand_flash_block_mapping_table_size); LX_MEMSET(nand_flash -> lx_nand_flash_block_mapping_table, 0xFF, nand_flash -> lx_nand_flash_block_mapping_table_size);
+31 -36
View File
@@ -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 * This program and the accompanying materials are made available under the
* terms of the MIT License which is available at * terms of the MIT License which is available at
* https://opensource.org/licenses/MIT. * https://opensource.org/licenses/MIT.
* *
* SPDX-License-Identifier: MIT * SPDX-License-Identifier: MIT
**************************************************************************/ **************************************************************************/
/**************************************************************************/ /**************************************************************************/
/**************************************************************************/ /**************************************************************************/
/** */ /** */
/** LevelX Component */ /** LevelX Component */
/** */ /** */
/** NAND Flash */ /** NAND Flash */
/** */ /** */
@@ -34,42 +35,36 @@
#include "lx_api.h" #include "lx_api.h"
/**************************************************************************/ /**************************************************************************/
/* */ /* */
/* FUNCTION RELEASE */ /* FUNCTION RELEASE */
/* */ /* */
/* _lx_nand_flash_free_block_list_add PORTABLE C */ /* _lx_nand_flash_free_block_list_add PORTABLE C */
/* 6.2.1 */ /* 6.2.1 */
/* AUTHOR */ /* AUTHOR */
/* */ /* */
/* Xiuwen Cai, Microsoft Corporation */ /* Xiuwen Cai, Microsoft Corporation */
/* */ /* */
/* DESCRIPTION */ /* DESCRIPTION */
/* */
/* This function adds a block to free block list. */
/* */
/* INPUT */
/* */
/* nand_flash NAND flash instance */
/* block Block number */
/* */
/* OUTPUT */
/* */
/* return status */
/* */
/* CALLS */
/* */
/* None */
/* */
/* CALLED BY */
/* */
/* Internal LevelX */
/* */
/* RELEASE HISTORY */
/* */
/* DATE NAME DESCRIPTION */
/* */ /* */
/* 03-08-2023 Xiuwen Cai Initial Version 6.2.1 */ /* This function adds a block to free block list. */
/* */
/* INPUT */
/* */
/* nand_flash NAND flash instance */
/* block Block number */
/* */
/* OUTPUT */
/* */
/* return status */
/* */
/* CALLS */
/* */
/* None */
/* */
/* CALLED BY */
/* */
/* Internal LevelX */
/* */ /* */
/**************************************************************************/ /**************************************************************************/
UINT _lx_nand_flash_free_block_list_add(LX_NAND_FLASH* nand_flash, ULONG block) UINT _lx_nand_flash_free_block_list_add(LX_NAND_FLASH* nand_flash, ULONG block)
@@ -101,7 +96,7 @@ UCHAR new_block_erase_count;
search_position = (INT)insert_position - 1; search_position = (INT)insert_position - 1;
/* Loop to search the insert position by block erase count. */ /* Loop to search the insert position by block erase count. */
while ((search_position >= 0) && while ((search_position >= 0) &&
(nand_flash -> lx_nand_flash_erase_count_table[nand_flash -> lx_nand_flash_block_list[search_position]] < new_block_erase_count)) (nand_flash -> lx_nand_flash_erase_count_table[nand_flash -> lx_nand_flash_block_list[search_position]] < new_block_erase_count))
{ {
+30 -37
View File
@@ -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 * This program and the accompanying materials are made available under the
* terms of the MIT License which is available at * terms of the MIT License which is available at
* https://opensource.org/licenses/MIT. * https://opensource.org/licenses/MIT.
* *
* SPDX-License-Identifier: MIT * SPDX-License-Identifier: MIT
**************************************************************************/ **************************************************************************/
/**************************************************************************/ /**************************************************************************/
/**************************************************************************/ /**************************************************************************/
/** */ /** */
/** LevelX Component */ /** LevelX Component */
/** */ /** */
/** NAND Flash */ /** NAND Flash */
/** */ /** */
@@ -33,43 +34,35 @@ LX_NAND_FLASH *_lx_nand_flash_opened_ptr;
ULONG _lx_nand_flash_opened_count; ULONG _lx_nand_flash_opened_count;
/**************************************************************************/ /**************************************************************************/
/* */ /* */
/* FUNCTION RELEASE */ /* FUNCTION RELEASE */
/* */ /* */
/* _lx_nand_flash_initialize PORTABLE C */ /* _lx_nand_flash_initialize PORTABLE C */
/* 6.1 */ /* 6.1 */
/* AUTHOR */ /* AUTHOR */
/* */ /* */
/* William E. Lamie, Microsoft Corporation */ /* William E. Lamie, Microsoft Corporation */
/* */ /* */
/* DESCRIPTION */ /* DESCRIPTION */
/* */
/* This function initializes the NAND flash data structures. */
/* */
/* INPUT */
/* */
/* None */
/* */
/* OUTPUT */
/* */
/* return status */
/* */
/* CALLS */
/* */
/* None */
/* */
/* CALLED BY */
/* */
/* Application Code */
/* */
/* RELEASE HISTORY */
/* */
/* DATE NAME DESCRIPTION */
/* */ /* */
/* 05-19-2020 William E. Lamie Initial Version 6.0 */ /* This function initializes the NAND flash data structures. */
/* 09-30-2020 William E. Lamie Modified comment(s), */ /* */
/* resulting in version 6.1 */ /* INPUT */
/* */
/* None */
/* */
/* OUTPUT */
/* */
/* return status */
/* */
/* CALLS */
/* */
/* None */
/* */
/* CALLED BY */
/* */
/* Application Code */
/* */ /* */
/**************************************************************************/ /**************************************************************************/
UINT _lx_nand_flash_initialize(void) UINT _lx_nand_flash_initialize(void)
@@ -78,7 +71,7 @@ UINT _lx_nand_flash_initialize(void)
/* Clear open list head pointer and opened count. */ /* Clear open list head pointer and opened count. */
_lx_nand_flash_opened_ptr = LX_NULL; _lx_nand_flash_opened_ptr = LX_NULL;
_lx_nand_flash_opened_count = 0; _lx_nand_flash_opened_count = 0;
/* Return success! */ /* Return success! */
return(LX_SUCCESS); return(LX_SUCCESS);
} }
@@ -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 * This program and the accompanying materials are made available under the
* terms of the MIT License which is available at * terms of the MIT License which is available at
* https://opensource.org/licenses/MIT. * https://opensource.org/licenses/MIT.
* *
* SPDX-License-Identifier: MIT * SPDX-License-Identifier: MIT
**************************************************************************/ **************************************************************************/
/**************************************************************************/ /**************************************************************************/
/**************************************************************************/ /**************************************************************************/
/** */ /** */
/** LevelX Component */ /** LevelX Component */
/** */ /** */
/** NAND Flash */ /** NAND Flash */
/** */ /** */
@@ -34,42 +35,36 @@
#include "lx_api.h" #include "lx_api.h"
/**************************************************************************/ /**************************************************************************/
/* */ /* */
/* FUNCTION RELEASE */ /* FUNCTION RELEASE */
/* */ /* */
/* _lx_nand_flash_mapped_block_list_add PORTABLE C */ /* _lx_nand_flash_mapped_block_list_add PORTABLE C */
/* 6.2.1 */ /* 6.2.1 */
/* AUTHOR */ /* AUTHOR */
/* */ /* */
/* Xiuwen Cai, Microsoft Corporation */ /* Xiuwen Cai, Microsoft Corporation */
/* */ /* */
/* DESCRIPTION */ /* DESCRIPTION */
/* */
/* This function adds a block to mapped block list. */
/* */
/* INPUT */
/* */
/* nand_flash NAND flash instance */
/* block_mapping_index Block mapping index */
/* */
/* OUTPUT */
/* */
/* return status */
/* */
/* CALLS */
/* */
/* None */
/* */
/* CALLED BY */
/* */
/* Internal LevelX */
/* */
/* RELEASE HISTORY */
/* */
/* DATE NAME DESCRIPTION */
/* */ /* */
/* 03-08-2023 Xiuwen Cai Initial Version 6.2.1 */ /* This function adds a block to mapped block list. */
/* */
/* INPUT */
/* */
/* nand_flash NAND flash instance */
/* block_mapping_index Block mapping index */
/* */
/* OUTPUT */
/* */
/* return status */
/* */
/* CALLS */
/* */
/* None */
/* */
/* CALLED BY */
/* */
/* Internal LevelX */
/* */ /* */
/**************************************************************************/ /**************************************************************************/
UINT _lx_nand_flash_mapped_block_list_add(LX_NAND_FLASH* nand_flash, ULONG block_mapping_index) UINT _lx_nand_flash_mapped_block_list_add(LX_NAND_FLASH* nand_flash, ULONG block_mapping_index)
@@ -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 * This program and the accompanying materials are made available under the
* terms of the MIT License which is available at * terms of the MIT License which is available at
* https://opensource.org/licenses/MIT. * https://opensource.org/licenses/MIT.
* *
* SPDX-License-Identifier: MIT * SPDX-License-Identifier: MIT
**************************************************************************/ **************************************************************************/
/**************************************************************************/ /**************************************************************************/
/**************************************************************************/ /**************************************************************************/
/** */ /** */
/** LevelX Component */ /** LevelX Component */
/** */ /** */
/** NAND Flash */ /** NAND Flash */
/** */ /** */
@@ -34,43 +35,37 @@
#include "lx_api.h" #include "lx_api.h"
/**************************************************************************/ /**************************************************************************/
/* */ /* */
/* FUNCTION RELEASE */ /* FUNCTION RELEASE */
/* */ /* */
/* _lx_nand_flash_mapped_block_list_get PORTABLE C */ /* _lx_nand_flash_mapped_block_list_get PORTABLE C */
/* 6.2.1 */ /* 6.2.1 */
/* AUTHOR */ /* AUTHOR */
/* */ /* */
/* Xiuwen Cai, Microsoft Corporation */ /* Xiuwen Cai, Microsoft Corporation */
/* */ /* */
/* DESCRIPTION */ /* DESCRIPTION */
/* */
/* This function gets a block from mapped block list and removes it */
/* from the list. */
/* */
/* INPUT */
/* */
/* nand_flash NAND flash instance */
/* block_mapping_index Pointer to block mapping index*/
/* */
/* OUTPUT */
/* */
/* return status */
/* */
/* CALLS */
/* */
/* None */
/* */
/* CALLED BY */
/* */
/* Internal LevelX */
/* */
/* RELEASE HISTORY */
/* */
/* DATE NAME DESCRIPTION */
/* */ /* */
/* 03-08-2023 Xiuwen Cai Initial Version 6.2.1 */ /* This function gets a block from mapped block list and removes it */
/* from the list. */
/* */
/* INPUT */
/* */
/* nand_flash NAND flash instance */
/* block_mapping_index Pointer to block mapping index*/
/* */
/* OUTPUT */
/* */
/* return status */
/* */
/* CALLS */
/* */
/* None */
/* */
/* CALLED BY */
/* */
/* Internal LevelX */
/* */ /* */
/**************************************************************************/ /**************************************************************************/
UINT _lx_nand_flash_mapped_block_list_get(LX_NAND_FLASH* nand_flash, ULONG *block_mapping_index) UINT _lx_nand_flash_mapped_block_list_get(LX_NAND_FLASH* nand_flash, ULONG *block_mapping_index)
@@ -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 * This program and the accompanying materials are made available under the
* terms of the MIT License which is available at * terms of the MIT License which is available at
* https://opensource.org/licenses/MIT. * https://opensource.org/licenses/MIT.
* *
* SPDX-License-Identifier: MIT * SPDX-License-Identifier: MIT
**************************************************************************/ **************************************************************************/
/**************************************************************************/ /**************************************************************************/
/**************************************************************************/ /**************************************************************************/
/** */ /** */
/** LevelX Component */ /** LevelX Component */
/** */ /** */
/** NAND Flash */ /** NAND Flash */
/** */ /** */
@@ -34,42 +35,36 @@
#include "lx_api.h" #include "lx_api.h"
/**************************************************************************/ /**************************************************************************/
/* */ /* */
/* FUNCTION RELEASE */ /* FUNCTION RELEASE */
/* */ /* */
/* _lx_nand_flash_mapped_block_list_remove PORTABLE C */ /* _lx_nand_flash_mapped_block_list_remove PORTABLE C */
/* 6.2.1 */ /* 6.2.1 */
/* AUTHOR */ /* AUTHOR */
/* */ /* */
/* Xiuwen Cai, Microsoft Corporation */ /* Xiuwen Cai, Microsoft Corporation */
/* */ /* */
/* DESCRIPTION */ /* DESCRIPTION */
/* */
/* This function removes mapped block from list. */
/* */
/* INPUT */
/* */
/* nand_flash NAND flash instance */
/* block_mapping_index Block mapping index */
/* */
/* OUTPUT */
/* */
/* return status */
/* */
/* CALLS */
/* */
/* None */
/* */
/* CALLED BY */
/* */
/* Internal LevelX */
/* */
/* RELEASE HISTORY */
/* */
/* DATE NAME DESCRIPTION */
/* */ /* */
/* 03-08-2023 Xiuwen Cai Initial Version 6.2.1 */ /* This function removes mapped block from list. */
/* */
/* INPUT */
/* */
/* nand_flash NAND flash instance */
/* block_mapping_index Block mapping index */
/* */
/* OUTPUT */
/* */
/* return status */
/* */
/* CALLS */
/* */
/* None */
/* */
/* CALLED BY */
/* */
/* Internal LevelX */
/* */ /* */
/**************************************************************************/ /**************************************************************************/
UINT _lx_nand_flash_mapped_block_list_remove(LX_NAND_FLASH* nand_flash, ULONG block_mapping_index) UINT _lx_nand_flash_mapped_block_list_remove(LX_NAND_FLASH* nand_flash, ULONG block_mapping_index)
+30 -35
View File
@@ -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 * This program and the accompanying materials are made available under the
* terms of the MIT License which is available at * terms of the MIT License which is available at
* https://opensource.org/licenses/MIT. * https://opensource.org/licenses/MIT.
* *
* SPDX-License-Identifier: MIT * SPDX-License-Identifier: MIT
**************************************************************************/ **************************************************************************/
/**************************************************************************/ /**************************************************************************/
/**************************************************************************/ /**************************************************************************/
/** */ /** */
/** LevelX Component */ /** LevelX Component */
/** */ /** */
/** NAND Flash */ /** NAND Flash */
/** */ /** */
@@ -34,45 +35,39 @@
#include "lx_api.h" #include "lx_api.h"
/**************************************************************************/ /**************************************************************************/
/* */ /* */
/* FUNCTION RELEASE */ /* FUNCTION RELEASE */
/* */ /* */
/* _lx_nand_flash_memory_initialize PORTABLE C */ /* _lx_nand_flash_memory_initialize PORTABLE C */
/* 6.2.1 */ /* 6.2.1 */
/* AUTHOR */ /* AUTHOR */
/* */ /* */
/* Xiuwen Cai, Microsoft Corporation */ /* Xiuwen Cai, Microsoft Corporation */
/* */ /* */
/* DESCRIPTION */ /* DESCRIPTION */
/* */ /* */
/* This function imitialize memory buffer for NAND flash instance. */ /* This function imitialize memory buffer for NAND flash instance. */
/* */ /* */
/* INPUT */ /* INPUT */
/* */ /* */
/* nand_flash NAND flash instance */ /* nand_flash NAND flash instance */
/* memory_ptr Pointer to memory used by the */ /* memory_ptr Pointer to memory used by the */
/* LevelX for this NAND. */ /* LevelX for this NAND. */
/* memory_size Size of memory */ /* memory_size Size of memory */
/* */ /* */
/* OUTPUT */ /* OUTPUT */
/* */ /* */
/* return status */ /* return status */
/* */ /* */
/* CALLS */ /* CALLS */
/* */ /* */
/* LX_MEMSET Initialize memory */ /* LX_MEMSET Initialize memory */
/* */ /* */
/* CALLED BY */ /* CALLED BY */
/* */ /* */
/* Internal LevelX */ /* Internal LevelX */
/* */ /* */
/* RELEASE HISTORY */
/* */
/* DATE NAME DESCRIPTION */
/* */
/* 03-08-2023 Xiuwen Cai Initial Version 6.2.1 */
/* */
/**************************************************************************/ /**************************************************************************/
UINT _lx_nand_flash_memory_initialize(LX_NAND_FLASH *nand_flash, ULONG* memory_ptr, UINT memory_size) UINT _lx_nand_flash_memory_initialize(LX_NAND_FLASH *nand_flash, ULONG* memory_ptr, UINT memory_size)
{ {
@@ -124,7 +119,7 @@ UINT buffer_size;
/* Assign memory for erase count table. */ /* Assign memory for erase count table. */
nand_flash -> lx_nand_flash_erase_count_table = (UCHAR*)(((UCHAR*)memory_ptr) + memory_offset); nand_flash -> lx_nand_flash_erase_count_table = (UCHAR*)(((UCHAR*)memory_ptr) + memory_offset);
/* Update memory offset. */ /* Update memory offset. */
memory_offset += buffer_size; memory_offset += buffer_size;
+35 -40
View File
@@ -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 * This program and the accompanying materials are made available under the
* terms of the MIT License which is available at * terms of the MIT License which is available at
* https://opensource.org/licenses/MIT. * https://opensource.org/licenses/MIT.
* *
* SPDX-License-Identifier: MIT * SPDX-License-Identifier: MIT
**************************************************************************/ **************************************************************************/
/**************************************************************************/ /**************************************************************************/
/**************************************************************************/ /**************************************************************************/
/** */ /** */
/** LevelX Component */ /** LevelX Component */
/** */ /** */
/** NAND Flash */ /** NAND Flash */
/** */ /** */
@@ -34,50 +35,44 @@
#include "lx_api.h" #include "lx_api.h"
/**************************************************************************/ /**************************************************************************/
/* */ /* */
/* FUNCTION RELEASE */ /* FUNCTION RELEASE */
/* */ /* */
/* _lx_nand_flash_metadata_allocate PORTABLE C */ /* _lx_nand_flash_metadata_allocate PORTABLE C */
/* 6.2.1 */ /* 6.2.1 */
/* AUTHOR */ /* AUTHOR */
/* */ /* */
/* Xiuwen Cai, Microsoft Corporation */ /* Xiuwen Cai, Microsoft Corporation */
/* */ /* */
/* DESCRIPTION */ /* DESCRIPTION */
/* */ /* */
/* This function allocates new blocks for metadata if current metadata */ /* This function allocates new blocks for metadata if current metadata */
/* block is full. This function also frees metadata blocks if the chain*/ /* block is full. This function also frees metadata blocks if the chain*/
/* is too long. */ /* is too long. */
/* */ /* */
/* INPUT */ /* INPUT */
/* */ /* */
/* nand_flash NAND flash instance */ /* nand_flash NAND flash instance */
/* */ /* */
/* OUTPUT */ /* OUTPUT */
/* */ /* */
/* return status */ /* return status */
/* */ /* */
/* CALLS */ /* CALLS */
/* */ /* */
/* _lx_nand_flash_metadata_build Build metadata */ /* _lx_nand_flash_metadata_build Build metadata */
/* _lx_nand_flash_driver_block_erase Erase block */ /* _lx_nand_flash_driver_block_erase Erase block */
/* _lx_nand_flash_block_data_move Move block data */ /* _lx_nand_flash_block_data_move Move block data */
/* _lx_nand_flash_free_block_list_add Add free block list */ /* _lx_nand_flash_free_block_list_add Add free block list */
/* _lx_nand_flash_block_allocate Allocate block */ /* _lx_nand_flash_block_allocate Allocate block */
/* _lx_nand_flash_block_status_set Set block status */ /* _lx_nand_flash_block_status_set Set block status */
/* _lx_nand_flash_metadata_write Write metadata */ /* _lx_nand_flash_metadata_write Write metadata */
/* _lx_nand_flash_system_error Internal system error handler */ /* _lx_nand_flash_system_error Internal system error handler */
/* */
/* CALLED BY */
/* */
/* Internal LevelX */
/* */
/* RELEASE HISTORY */
/* */
/* DATE NAME DESCRIPTION */
/* */ /* */
/* 03-08-2023 Xiuwen Cai Initial Version 6.2.1 */ /* CALLED BY */
/* */
/* Internal LevelX */
/* */ /* */
/**************************************************************************/ /**************************************************************************/
UINT _lx_nand_flash_metadata_allocate(LX_NAND_FLASH *nand_flash) UINT _lx_nand_flash_metadata_allocate(LX_NAND_FLASH *nand_flash)
@@ -150,7 +145,7 @@ UCHAR min_erase_count;
/* Exclude erase count of bad block. */ /* Exclude erase count of bad block. */
if(nand_flash -> lx_nand_flash_block_status_table[j] != LX_NAND_BLOCK_STATUS_BAD) if(nand_flash -> lx_nand_flash_block_status_table[j] != LX_NAND_BLOCK_STATUS_BAD)
{ {
/* Check if it has less erase count. */ /* Check if it has less erase count. */
if (nand_flash -> lx_nand_flash_erase_count_table[j] < min_erase_count) if (nand_flash -> lx_nand_flash_erase_count_table[j] < min_erase_count)
@@ -239,7 +234,7 @@ UCHAR min_erase_count;
/* Erase the block. */ /* Erase the block. */
status = _lx_nand_flash_driver_block_erase(nand_flash, block, nand_flash -> lx_nand_flash_base_erase_count + nand_flash -> lx_nand_flash_erase_count_table[block]); status = _lx_nand_flash_driver_block_erase(nand_flash, block, nand_flash -> lx_nand_flash_base_erase_count + nand_flash -> lx_nand_flash_erase_count_table[block]);
/* Check for an error from flash driver. */ /* Check for an error from flash driver. */
if (status) if (status)
{ {
+35 -40
View File
@@ -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 * This program and the accompanying materials are made available under the
* terms of the MIT License which is available at * terms of the MIT License which is available at
* https://opensource.org/licenses/MIT. * https://opensource.org/licenses/MIT.
* *
* SPDX-License-Identifier: MIT * SPDX-License-Identifier: MIT
**************************************************************************/ **************************************************************************/
/**************************************************************************/ /**************************************************************************/
/**************************************************************************/ /**************************************************************************/
/** */ /** */
/** LevelX Component */ /** LevelX Component */
/** */ /** */
/** NAND Flash */ /** NAND Flash */
/** */ /** */
@@ -34,41 +35,35 @@
#include "lx_api.h" #include "lx_api.h"
/**************************************************************************/ /**************************************************************************/
/* */ /* */
/* FUNCTION RELEASE */ /* FUNCTION RELEASE */
/* */ /* */
/* _lx_nand_flash_metadata_build PORTABLE C */ /* _lx_nand_flash_metadata_build PORTABLE C */
/* 6.2.1 */ /* 6.2.1 */
/* AUTHOR */ /* AUTHOR */
/* */ /* */
/* Xiuwen Cai, Microsoft Corporation */ /* Xiuwen Cai, Microsoft Corporation */
/* */ /* */
/* DESCRIPTION */ /* DESCRIPTION */
/* */
/* This function rewrites all metadata pages. */
/* */
/* INPUT */
/* */
/* nand_flash NAND flash instance */
/* */
/* OUTPUT */
/* */
/* return status */
/* */
/* CALLS */
/* */
/* _lx_nand_flash_metadata_write Write metadata */
/* */
/* CALLED BY */
/* */
/* Internal LevelX */
/* */
/* RELEASE HISTORY */
/* */
/* DATE NAME DESCRIPTION */
/* */ /* */
/* 03-08-2023 Xiuwen Cai Initial Version 6.2.1 */ /* This function rewrites all metadata pages. */
/* */
/* INPUT */
/* */
/* nand_flash NAND flash instance */
/* */
/* OUTPUT */
/* */
/* return status */
/* */
/* CALLS */
/* */
/* _lx_nand_flash_metadata_write Write metadata */
/* */
/* CALLED BY */
/* */
/* Internal LevelX */
/* */ /* */
/**************************************************************************/ /**************************************************************************/
UINT _lx_nand_flash_metadata_build(LX_NAND_FLASH *nand_flash) UINT _lx_nand_flash_metadata_build(LX_NAND_FLASH *nand_flash)
@@ -109,7 +104,7 @@ UINT i;
{ {
/* Write erase count table. */ /* Write erase count table. */
status = _lx_nand_flash_metadata_write(nand_flash, (UCHAR*)(nand_flash -> lx_nand_flash_erase_count_table + status = _lx_nand_flash_metadata_write(nand_flash, (UCHAR*)(nand_flash -> lx_nand_flash_erase_count_table +
i * nand_flash -> lx_nand_flash_bytes_per_page), i * nand_flash -> lx_nand_flash_bytes_per_page),
LX_NAND_PAGE_TYPE_ERASE_COUNT_TABLE | i); LX_NAND_PAGE_TYPE_ERASE_COUNT_TABLE | i);
@@ -130,8 +125,8 @@ UINT i;
{ {
/* Write block mapping table. */ /* Write block mapping table. */
status = _lx_nand_flash_metadata_write(nand_flash, (UCHAR*)(nand_flash -> lx_nand_flash_block_mapping_table + status = _lx_nand_flash_metadata_write(nand_flash, (UCHAR*)(nand_flash -> lx_nand_flash_block_mapping_table +
i * nand_flash -> lx_nand_flash_bytes_per_page / sizeof(*nand_flash -> lx_nand_flash_block_mapping_table)), i * nand_flash -> lx_nand_flash_bytes_per_page / sizeof(*nand_flash -> lx_nand_flash_block_mapping_table)),
LX_NAND_PAGE_TYPE_BLOCK_MAPPING_TABLE | i); LX_NAND_PAGE_TYPE_BLOCK_MAPPING_TABLE | i);
/* Check return status. */ /* Check return status. */
if (status != LX_SUCCESS) if (status != LX_SUCCESS)
@@ -150,14 +145,14 @@ UINT i;
{ {
/* Write block status table. */ /* Write block status table. */
status = _lx_nand_flash_metadata_write(nand_flash, (UCHAR*)(nand_flash -> lx_nand_flash_block_status_table + status = _lx_nand_flash_metadata_write(nand_flash, (UCHAR*)(nand_flash -> lx_nand_flash_block_status_table +
i * nand_flash -> lx_nand_flash_bytes_per_page / sizeof(*nand_flash -> lx_nand_flash_block_status_table)), i * nand_flash -> lx_nand_flash_bytes_per_page / sizeof(*nand_flash -> lx_nand_flash_block_status_table)),
LX_NAND_PAGE_TYPE_BLOCK_STATUS_TABLE | i); LX_NAND_PAGE_TYPE_BLOCK_STATUS_TABLE | i);
/* Check return status. */ /* Check return status. */
if (status != LX_SUCCESS) if (status != LX_SUCCESS)
{ {
/* Return error status. */ /* Return error status. */
return(status); return(status);
} }
+35 -40
View File
@@ -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 * This program and the accompanying materials are made available under the
* terms of the MIT License which is available at * terms of the MIT License which is available at
* https://opensource.org/licenses/MIT. * https://opensource.org/licenses/MIT.
* *
* SPDX-License-Identifier: MIT * SPDX-License-Identifier: MIT
**************************************************************************/ **************************************************************************/
/**************************************************************************/ /**************************************************************************/
/**************************************************************************/ /**************************************************************************/
/** */ /** */
/** LevelX Component */ /** LevelX Component */
/** */ /** */
/** NAND Flash */ /** NAND Flash */
/** */ /** */
@@ -34,46 +35,40 @@
#include "lx_api.h" #include "lx_api.h"
/**************************************************************************/ /**************************************************************************/
/* */ /* */
/* FUNCTION RELEASE */ /* FUNCTION RELEASE */
/* */ /* */
/* _lx_nand_flash_metadata_write PORTABLE C */ /* _lx_nand_flash_metadata_write PORTABLE C */
/* 6.2.1 */ /* 6.2.1 */
/* AUTHOR */ /* AUTHOR */
/* */ /* */
/* Xiuwen Cai, Microsoft Corporation */ /* Xiuwen Cai, Microsoft Corporation */
/* */ /* */
/* DESCRIPTION */ /* DESCRIPTION */
/* */
/* This function writes metadata pages into current metadata block and */
/* allocates new blocks for metadata. */
/* */
/* INPUT */
/* */
/* nand_flash NAND flash instance */
/* main_buffer Main page buffer */
/* spare_value Value for spare bytes */
/* */
/* OUTPUT */
/* */
/* return status */
/* */
/* CALLS */
/* */
/* lx_nand_flash_driver_pages_write Driver pages write */
/* _lx_nand_flash_metadata_allocate Allocate blocks for metadata */
/* _lx_nand_flash_system_error Internal system error handler */
/* */
/* CALLED BY */
/* */
/* Internal LevelX */
/* */
/* RELEASE HISTORY */
/* */
/* DATE NAME DESCRIPTION */
/* */ /* */
/* 03-08-2023 Xiuwen Cai Initial Version 6.2.1 */ /* This function writes metadata pages into current metadata block and */
/* allocates new blocks for metadata. */
/* */
/* INPUT */
/* */
/* nand_flash NAND flash instance */
/* main_buffer Main page buffer */
/* spare_value Value for spare bytes */
/* */
/* OUTPUT */
/* */
/* return status */
/* */
/* CALLS */
/* */
/* lx_nand_flash_driver_pages_write Driver pages write */
/* _lx_nand_flash_metadata_allocate Allocate blocks for metadata */
/* _lx_nand_flash_system_error Internal system error handler */
/* */
/* CALLED BY */
/* */
/* Internal LevelX */
/* */ /* */
/**************************************************************************/ /**************************************************************************/
UINT _lx_nand_flash_metadata_write(LX_NAND_FLASH *nand_flash, UCHAR* main_buffer, ULONG spare_value) UINT _lx_nand_flash_metadata_write(LX_NAND_FLASH *nand_flash, UCHAR* main_buffer, ULONG spare_value)
@@ -115,7 +110,7 @@ UCHAR *spare_buffer_ptr;
status = (nand_flash -> lx_nand_flash_driver_pages_write)(block, page, main_buffer, spare_buffer_ptr, 1); status = (nand_flash -> lx_nand_flash_driver_pages_write)(block, page, main_buffer, spare_buffer_ptr, 1);
#endif #endif
/* Check for an error from flash driver. */ /* Check for an error from flash driver. */
if (status) if (status)
{ {
+32 -42
View File
@@ -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 * This program and the accompanying materials are made available under the
* terms of the MIT License which is available at * terms of the MIT License which is available at
* https://opensource.org/licenses/MIT. * https://opensource.org/licenses/MIT.
* *
* SPDX-License-Identifier: MIT * SPDX-License-Identifier: MIT
**************************************************************************/ **************************************************************************/
/**************************************************************************/ /**************************************************************************/
/**************************************************************************/ /**************************************************************************/
/** */ /** */
/** LevelX Component */ /** LevelX Component */
/** */ /** */
/** NAND Flash */ /** NAND Flash */
/** */ /** */
@@ -34,55 +35,44 @@
#include "lx_api.h" #include "lx_api.h"
/**************************************************************************/ /**************************************************************************/
/* */ /* */
/* FUNCTION RELEASE */ /* FUNCTION RELEASE */
/* */ /* */
/* _lx_nand_flash_open PORTABLE C */ /* _lx_nand_flash_open PORTABLE C */
/* 6.3.0 */ /* 6.3.0 */
/* AUTHOR */ /* AUTHOR */
/* */ /* */
/* Xiuwen Cai, Microsoft Corporation */ /* Xiuwen Cai, Microsoft Corporation */
/* */ /* */
/* DESCRIPTION */ /* DESCRIPTION */
/* */ /* */
/* This function opens a NAND flash instance and ensures the */ /* This function opens a NAND flash instance and ensures the */
/* NAND flash is in a coherent state. */ /* NAND flash is in a coherent state. */
/* */ /* */
/* INPUT */ /* INPUT */
/* */ /* */
/* nand_flash NAND flash instance */ /* nand_flash NAND flash instance */
/* name Name of NAND flash instance */ /* name Name of NAND flash instance */
/* nand_driver_initialize Driver initialize */ /* nand_driver_initialize Driver initialize */
/* nand_driver_info_ptr User data pointer */ /* nand_driver_info_ptr User data pointer */
/* memory_ptr Pointer to memory used by the */ /* memory_ptr Pointer to memory used by the */
/* LevelX for this NAND. */ /* LevelX for this NAND. */
/* memory_size Size of memory - must at least*/ /* memory_size Size of memory - must at least*/
/* 7 * total block count + */ /* 7 * total block count + */
/* 2 * page size */ /* 2 * page size */
/* */
/* OUTPUT */
/* */
/* return status */
/* */
/* CALLS */
/* */
/* lx_nand_flash_open_extended Pass NULL as driver_info_ptr */
/* */
/* CALLED BY */
/* */
/* Application Code */
/* */
/* RELEASE HISTORY */
/* */
/* DATE NAME DESCRIPTION */
/* */ /* */
/* 03-08-2023 Xiuwen Cai Initial Version 6.2.1 */ /* OUTPUT */
/* 10-31-2023 Xiuwen Cai Modified comment(s), */ /* */
/* avoided clearing user */ /* return status */
/* extension in flash control */ /* */
/* block, */ /* CALLS */
/* resulting in version 6.3.0 */ /* */
/* lx_nand_flash_open_extended Pass NULL as driver_info_ptr */
/* */
/* CALLED BY */
/* */
/* Application Code */
/* */ /* */
/**************************************************************************/ /**************************************************************************/
UINT _lx_nand_flash_open(LX_NAND_FLASH *nand_flash, CHAR *name, UINT (*nand_driver_initialize)(LX_NAND_FLASH *), UINT _lx_nand_flash_open(LX_NAND_FLASH *nand_flash, CHAR *name, UINT (*nand_driver_initialize)(LX_NAND_FLASH *),
+55 -65
View File
@@ -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 * This program and the accompanying materials are made available under the
* terms of the MIT License which is available at * terms of the MIT License which is available at
* https://opensource.org/licenses/MIT. * https://opensource.org/licenses/MIT.
* *
* SPDX-License-Identifier: MIT * SPDX-License-Identifier: MIT
**************************************************************************/ **************************************************************************/
/**************************************************************************/ /**************************************************************************/
/**************************************************************************/ /**************************************************************************/
/** */ /** */
/** LevelX Component */ /** LevelX Component */
/** */ /** */
/** NAND Flash */ /** NAND Flash */
/** */ /** */
@@ -34,62 +35,51 @@
#include "lx_api.h" #include "lx_api.h"
/**************************************************************************/ /**************************************************************************/
/* */ /* */
/* FUNCTION RELEASE */ /* FUNCTION RELEASE */
/* */ /* */
/* _lx_nand_flash_open PORTABLE C */ /* _lx_nand_flash_open PORTABLE C */
/* 6.3.0 */ /* 6.3.0 */
/* AUTHOR */ /* AUTHOR */
/* */ /* */
/* Xiuwen Cai, Microsoft Corporation */ /* Xiuwen Cai, Microsoft Corporation */
/* */ /* */
/* DESCRIPTION */ /* DESCRIPTION */
/* */ /* */
/* This function opens a NAND flash instance and ensures the */ /* This function opens a NAND flash instance and ensures the */
/* NAND flash is in a coherent state. */ /* NAND flash is in a coherent state. */
/* */ /* */
/* INPUT */ /* INPUT */
/* */ /* */
/* nand_flash NAND flash instance */ /* nand_flash NAND flash instance */
/* name Name of NAND flash instance */ /* name Name of NAND flash instance */
/* nand_driver_initialize Driver initialize */ /* nand_driver_initialize Driver initialize */
/* memory_ptr Pointer to memory used by the */ /* memory_ptr Pointer to memory used by the */
/* LevelX for this NAND. */ /* LevelX for this NAND. */
/* memory_size Size of memory - must at least*/ /* memory_size Size of memory - must at least*/
/* 7 * total block count + */ /* 7 * total block count + */
/* 2 * page size */ /* 2 * page size */
/* */ /* */
/* OUTPUT */ /* OUTPUT */
/* */ /* */
/* return status */ /* return status */
/* */ /* */
/* CALLS */ /* CALLS */
/* */ /* */
/* (nand_driver_initialize) Driver initialize */ /* (nand_driver_initialize) Driver initialize */
/* _lx_nand_flash_memory_initialize Initialize buffer */ /* _lx_nand_flash_memory_initialize Initialize buffer */
/* _lx_nand_flash_driver_block_status_get */ /* _lx_nand_flash_driver_block_status_get */
/* Get block status */ /* Get block status */
/* lx_nand_flash_driver_pages_read Read pages */ /* lx_nand_flash_driver_pages_read Read pages */
/* _lx_nand_flash_free_block_list_add Add free block to list */ /* _lx_nand_flash_free_block_list_add Add free block to list */
/* _lx_nand_flash_mapped_block_list_add Add mapped block to list */ /* _lx_nand_flash_mapped_block_list_add Add mapped block to list */
/* _lx_nand_flash_system_error System error handler */ /* _lx_nand_flash_system_error System error handler */
/* tx_mutex_create Create thread-safe mutex */ /* tx_mutex_create Create thread-safe mutex */
/* */
/* CALLED BY */
/* */
/* Application Code */
/* */
/* RELEASE HISTORY */
/* */
/* DATE NAME DESCRIPTION */
/* */ /* */
/* 03-08-2023 Xiuwen Cai Initial Version 6.2.1 */ /* CALLED BY */
/* 10-31-2023 Xiuwen Cai Modified comment(s), */ /* */
/* avoided clearing user */ /* Application Code */
/* extension in flash control */
/* block, */
/* resulting in version 6.3.0 */
/* */ /* */
/**************************************************************************/ /**************************************************************************/
@@ -170,17 +160,17 @@ LX_INTERRUPT_SAVE_AREA
/* Loop through the blocks to check for bad blocks and determine the minimum and maximum erase count for each good block. */ /* Loop through the blocks to check for bad blocks and determine the minimum and maximum erase count for each good block. */
for (block = 0; block < nand_flash -> lx_nand_flash_total_blocks; block++) for (block = 0; block < nand_flash -> lx_nand_flash_total_blocks; block++)
{ {
/* First, check to make sure this block is good. */ /* First, check to make sure this block is good. */
status = _lx_nand_flash_driver_block_status_get(nand_flash, block, &block_status); status = _lx_nand_flash_driver_block_status_get(nand_flash, block, &block_status);
/* Check for an error from flash driver. */ /* Check for an error from flash driver. */
if (status) if (status)
{ {
/* Call system error handler. */ /* Call system error handler. */
_lx_nand_flash_system_error(nand_flash, status, block, 0); _lx_nand_flash_system_error(nand_flash, status, block, 0);
/* Return an error. */ /* Return an error. */
return(LX_ERROR); return(LX_ERROR);
} }
@@ -188,9 +178,9 @@ LX_INTERRUPT_SAVE_AREA
/* Is this block bad? */ /* Is this block bad? */
if (block_status != LX_NAND_GOOD_BLOCK) if (block_status != LX_NAND_GOOD_BLOCK)
{ {
/* Yes, this block is bad. */ /* Yes, this block is bad. */
/* Increment the number of bad blocks. */ /* Increment the number of bad blocks. */
nand_flash -> lx_nand_flash_bad_blocks++; nand_flash -> lx_nand_flash_bad_blocks++;
@@ -211,14 +201,14 @@ LX_INTERRUPT_SAVE_AREA
/* Check for an error from flash driver. */ /* Check for an error from flash driver. */
if (status) if (status)
{ {
/* Call system error handler. */ /* Call system error handler. */
_lx_nand_flash_system_error(nand_flash, status, block, 0); _lx_nand_flash_system_error(nand_flash, status, block, 0);
/* Determine if the error is fatal. */ /* Determine if the error is fatal. */
if (status != LX_NAND_ERROR_CORRECTED) if (status != LX_NAND_ERROR_CORRECTED)
{ {
/* Return an error. */ /* Return an error. */
return(LX_ERROR); return(LX_ERROR);
} }
@@ -247,7 +237,7 @@ LX_INTERRUPT_SAVE_AREA
} }
} }
/* Check if we have found the metadata block. */ /* Check if we have found the metadata block. */
if (nand_flash -> lx_nand_flash_metadata_block_number == LX_NAND_BLOCK_UNMAPPED) if (nand_flash -> lx_nand_flash_metadata_block_number == LX_NAND_BLOCK_UNMAPPED)
@@ -270,13 +260,13 @@ LX_INTERRUPT_SAVE_AREA
block_count = 0; block_count = 0;
do do
{ {
/* Initialize next block to unmapped. */ /* Initialize next block to unmapped. */
nand_flash -> lx_nand_flash_metadata_block_number_next = LX_NAND_BLOCK_UNMAPPED; nand_flash -> lx_nand_flash_metadata_block_number_next = LX_NAND_BLOCK_UNMAPPED;
nand_flash -> lx_nand_flash_backup_metadata_block_number_next = LX_NAND_BLOCK_UNMAPPED; nand_flash -> lx_nand_flash_backup_metadata_block_number_next = LX_NAND_BLOCK_UNMAPPED;
/* Loop to read pages in the metadata block. */ /* Loop to read pages in the metadata block. */
for (page = 0; page < nand_flash -> lx_nand_flash_pages_per_block ; page++) for (page = 0; page < nand_flash -> lx_nand_flash_pages_per_block ; page++)
{ {
@@ -397,7 +387,7 @@ LX_INTERRUPT_SAVE_AREA
/* Unknown type, return error. */ /* Unknown type, return error. */
status = LX_ERROR; status = LX_ERROR;
} }
/* Check status. */ /* Check status. */
if (status == LX_ERROR) if (status == LX_ERROR)
{ {
@@ -459,7 +449,7 @@ LX_INTERRUPT_SAVE_AREA
/* Add the block to free block list. */ /* Add the block to free block list. */
_lx_nand_flash_free_block_list_add(nand_flash, block); _lx_nand_flash_free_block_list_add(nand_flash, block);
} }
/* Check for mapped blocks. */ /* Check for mapped blocks. */
if (nand_flash -> lx_nand_flash_block_mapping_table[block] != LX_NAND_BLOCK_UNMAPPED) if (nand_flash -> lx_nand_flash_block_mapping_table[block] != LX_NAND_BLOCK_UNMAPPED)
{ {
@@ -472,17 +462,17 @@ LX_INTERRUPT_SAVE_AREA
#ifdef LX_THREAD_SAFE_ENABLE #ifdef LX_THREAD_SAFE_ENABLE
/* If the thread safe option is enabled, create a ThreadX mutex that will be used in all external APIs /* If the thread safe option is enabled, create a ThreadX mutex that will be used in all external APIs
in order to provide thread-safe operation. */ in order to provide thread-safe operation. */
status = tx_mutex_create(&nand_flash -> lx_nand_flash_mutex, "NAND Flash Mutex", TX_NO_INHERIT); status = tx_mutex_create(&nand_flash -> lx_nand_flash_mutex, "NAND Flash Mutex", TX_NO_INHERIT);
/* Determine if the mutex creation encountered an error. */ /* Determine if the mutex creation encountered an error. */
if (status != LX_SUCCESS) if (status != LX_SUCCESS)
{ {
/* Call system error handler, since this should not happen. */ /* Call system error handler, since this should not happen. */
_lx_nand_flash_system_error(nand_flash, LX_SYSTEM_MUTEX_CREATE_FAILED, 0, 0); _lx_nand_flash_system_error(nand_flash, LX_SYSTEM_MUTEX_CREATE_FAILED, 0, 0);
/* Return error to caller. */ /* Return error to caller. */
return(LX_ERROR); return(LX_ERROR);
} }
@@ -491,7 +481,7 @@ LX_INTERRUPT_SAVE_AREA
/* Lockout interrupts. */ /* Lockout interrupts. */
LX_DISABLE LX_DISABLE
/* At this point, the NAND flash has been opened successfully. Place the /* At this point, the NAND flash has been opened successfully. Place the
NAND flash control block on the linked list of currently opened NAND flashes. */ NAND flash control block on the linked list of currently opened NAND flashes. */
/* Set the NAND flash state to open. */ /* Set the NAND flash state to open. */
@@ -513,7 +503,7 @@ LX_INTERRUPT_SAVE_AREA
/* Setup this NAND flash's opened links. */ /* Setup this NAND flash's opened links. */
nand_flash -> lx_nand_flash_open_previous = tail_ptr; nand_flash -> lx_nand_flash_open_previous = tail_ptr;
nand_flash -> lx_nand_flash_open_next = _lx_nand_flash_opened_ptr; nand_flash -> lx_nand_flash_open_next = _lx_nand_flash_opened_ptr;
} }
else else
{ {
+45 -54
View File
@@ -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 * This program and the accompanying materials are made available under the
* terms of the MIT License which is available at * terms of the MIT License which is available at
* https://opensource.org/licenses/MIT. * https://opensource.org/licenses/MIT.
* *
* SPDX-License-Identifier: MIT * SPDX-License-Identifier: MIT
**************************************************************************/ **************************************************************************/
/**************************************************************************/ /**************************************************************************/
/**************************************************************************/ /**************************************************************************/
/** */ /** */
/** LevelX Component */ /** LevelX Component */
/** */ /** */
/** NAND Flash */ /** NAND Flash */
/** */ /** */
@@ -34,48 +35,38 @@
#include "lx_api.h" #include "lx_api.h"
/**************************************************************************/ /**************************************************************************/
/* */ /* */
/* FUNCTION RELEASE */ /* FUNCTION RELEASE */
/* */ /* */
/* _lx_nand_flash_page_ecc_check PORTABLE C */ /* _lx_nand_flash_page_ecc_check PORTABLE C */
/* 6.1.7 */ /* 6.1.7 */
/* AUTHOR */ /* AUTHOR */
/* */ /* */
/* William E. Lamie, Microsoft Corporation */ /* William E. Lamie, Microsoft Corporation */
/* */ /* */
/* DESCRIPTION */ /* DESCRIPTION */
/* */
/* This function checks the NAND page and ECC for errors and */
/* attempts to correct 1 bit errors. */
/* */
/* INPUT */
/* */
/* nand_flash NAND flash instance */
/* page_buffer Page buffer */
/* ecc_buffer Returned ECC buffer */
/* */
/* OUTPUT */
/* */
/* return status */
/* */
/* CALLS */
/* */
/* _lx_nand_flash_256byte_ecc_check Check 256 bytes and ECC */
/* */
/* CALLED BY */
/* */
/* NAND flash driver */
/* */
/* RELEASE HISTORY */
/* */
/* DATE NAME DESCRIPTION */
/* */ /* */
/* 05-19-2020 William E. Lamie Initial Version 6.0 */ /* This function checks the NAND page and ECC for errors and */
/* 09-30-2020 William E. Lamie Modified comment(s), */ /* attempts to correct 1 bit errors. */
/* resulting in version 6.1 */ /* */
/* 06-02-2021 Bhupendra Naphade Modified comment(s), */ /* INPUT */
/* resulting in version 6.1.7 */ /* */
/* nand_flash NAND flash instance */
/* page_buffer Page buffer */
/* ecc_buffer Returned ECC buffer */
/* */
/* OUTPUT */
/* */
/* return status */
/* */
/* CALLS */
/* */
/* _lx_nand_flash_256byte_ecc_check Check 256 bytes and ECC */
/* */
/* CALLED BY */
/* */
/* NAND flash driver */
/* */ /* */
/**************************************************************************/ /**************************************************************************/
UINT _lx_nand_flash_page_ecc_check(LX_NAND_FLASH *nand_flash, UCHAR *page_buffer, UCHAR *ecc_buffer) UINT _lx_nand_flash_page_ecc_check(LX_NAND_FLASH *nand_flash, UCHAR *page_buffer, UCHAR *ecc_buffer)
@@ -85,48 +76,48 @@ UINT bytes_checked;
UINT status; UINT status;
UINT return_status = LX_SUCCESS; UINT return_status = LX_SUCCESS;
/* Loop to check the entire NAND flash page. */ /* Loop to check the entire NAND flash page. */
bytes_checked = 0; bytes_checked = 0;
while (bytes_checked < nand_flash -> lx_nand_flash_bytes_per_page) while (bytes_checked < nand_flash -> lx_nand_flash_bytes_per_page)
{ {
/* Check this 256 byte piece of the NAND page. */ /* Check this 256 byte piece of the NAND page. */
status = _lx_nand_flash_256byte_ecc_check(page_buffer, ecc_buffer); status = _lx_nand_flash_256byte_ecc_check(page_buffer, ecc_buffer);
/* Determine if there was an error. */ /* Determine if there was an error. */
if (status != LX_SUCCESS) if (status != LX_SUCCESS)
{ {
/* Determine if a non-correctable error is present. */ /* Determine if a non-correctable error is present. */
if (status == LX_NAND_ERROR_NOT_CORRECTED) if (status == LX_NAND_ERROR_NOT_CORRECTED)
{ {
/* Always return a non-correctable error, if present. */ /* Always return a non-correctable error, if present. */
return_status = LX_NAND_ERROR_NOT_CORRECTED; return_status = LX_NAND_ERROR_NOT_CORRECTED;
break; break;
} }
/* A single-bit error was corrected, return this status /* A single-bit error was corrected, return this status
if there is no LX_ERROR status already detected. */ if there is no LX_ERROR status already detected. */
else if (return_status == LX_SUCCESS) else if (return_status == LX_SUCCESS)
{ {
/* Return a notice that the single bit error was corrected. */ /* Return a notice that the single bit error was corrected. */
return_status = LX_NAND_ERROR_CORRECTED; return_status = LX_NAND_ERROR_CORRECTED;
} }
} }
/* Move to the next 256 byte portion of the page. */ /* Move to the next 256 byte portion of the page. */
bytes_checked = bytes_checked + 256; bytes_checked = bytes_checked + 256;
/* Move the page buffer forward. */ /* Move the page buffer forward. */
page_buffer = page_buffer + 256; page_buffer = page_buffer + 256;
/* Move the ECC buffer forward, note there are 3 bytes of ECC per page. */ /* Move the ECC buffer forward, note there are 3 bytes of ECC per page. */
ecc_buffer = ecc_buffer + 3; ecc_buffer = ecc_buffer + 3;
} }
/* Return status. */ /* Return status. */
return(return_status); return(return_status);
} }
+37 -46
View File
@@ -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 * This program and the accompanying materials are made available under the
* terms of the MIT License which is available at * terms of the MIT License which is available at
* https://opensource.org/licenses/MIT. * https://opensource.org/licenses/MIT.
* *
* SPDX-License-Identifier: MIT * SPDX-License-Identifier: MIT
**************************************************************************/ **************************************************************************/
/**************************************************************************/ /**************************************************************************/
/**************************************************************************/ /**************************************************************************/
/** */ /** */
/** LevelX Component */ /** LevelX Component */
/** */ /** */
/** NAND Flash */ /** NAND Flash */
/** */ /** */
@@ -34,47 +35,37 @@
#include "lx_api.h" #include "lx_api.h"
/**************************************************************************/ /**************************************************************************/
/* */ /* */
/* FUNCTION RELEASE */ /* FUNCTION RELEASE */
/* */ /* */
/* _lx_nand_flash_page_ecc_compute PORTABLE C */ /* _lx_nand_flash_page_ecc_compute PORTABLE C */
/* 6.1.7 */ /* 6.1.7 */
/* AUTHOR */ /* AUTHOR */
/* */ /* */
/* William E. Lamie, Microsoft Corporation */ /* William E. Lamie, Microsoft Corporation */
/* */ /* */
/* DESCRIPTION */ /* DESCRIPTION */
/* */
/* This function computes the ECC for a NAND flash page. */
/* */
/* INPUT */
/* */
/* nand_flash NAND flash instance */
/* page_buffer Page buffer */
/* ecc_buffer Returned ECC buffer */
/* */
/* OUTPUT */
/* */
/* return status */
/* */
/* CALLS */
/* */
/* _lx_nand_flash_256byte_ecc_compute Compute ECC for 256 bytes */
/* */
/* CALLED BY */
/* */
/* NAND flash driver */
/* */
/* RELEASE HISTORY */
/* */
/* DATE NAME DESCRIPTION */
/* */ /* */
/* 05-19-2020 William E. Lamie Initial Version 6.0 */ /* This function computes the ECC for a NAND flash page. */
/* 09-30-2020 William E. Lamie Modified comment(s), */ /* */
/* resulting in version 6.1 */ /* INPUT */
/* 06-02-2021 Bhupendra Naphade Modified comment(s), */ /* */
/* resulting in version 6.1.7 */ /* nand_flash NAND flash instance */
/* page_buffer Page buffer */
/* ecc_buffer Returned ECC buffer */
/* */
/* OUTPUT */
/* */
/* return status */
/* */
/* CALLS */
/* */
/* _lx_nand_flash_256byte_ecc_compute Compute ECC for 256 bytes */
/* */
/* CALLED BY */
/* */
/* NAND flash driver */
/* */ /* */
/**************************************************************************/ /**************************************************************************/
UINT _lx_nand_flash_page_ecc_compute(LX_NAND_FLASH *nand_flash, UCHAR *page_buffer, UCHAR *ecc_buffer) UINT _lx_nand_flash_page_ecc_compute(LX_NAND_FLASH *nand_flash, UCHAR *page_buffer, UCHAR *ecc_buffer)
@@ -82,25 +73,25 @@ UINT _lx_nand_flash_page_ecc_compute(LX_NAND_FLASH *nand_flash, UCHAR *page_buf
UINT bytes_computed; UINT bytes_computed;
/* Loop to compute the ECC over the entire NAND flash page. */ /* Loop to compute the ECC over the entire NAND flash page. */
bytes_computed = 0; bytes_computed = 0;
while (bytes_computed < nand_flash -> lx_nand_flash_bytes_per_page) while (bytes_computed < nand_flash -> lx_nand_flash_bytes_per_page)
{ {
/* Compute the ECC for this 256 byte piece of the page. */ /* Compute the ECC for this 256 byte piece of the page. */
_lx_nand_flash_256byte_ecc_compute(page_buffer, ecc_buffer); _lx_nand_flash_256byte_ecc_compute(page_buffer, ecc_buffer);
/* Move to the next 256 byte portion of the page. */ /* Move to the next 256 byte portion of the page. */
bytes_computed = bytes_computed + 256; bytes_computed = bytes_computed + 256;
/* Move the page buffer forward. */ /* Move the page buffer forward. */
page_buffer = page_buffer + 256; page_buffer = page_buffer + 256;
/* Move the ECC buffer forward, note there are 3 bytes of ECC per page. */ /* Move the ECC buffer forward, note there are 3 bytes of ECC per page. */
ecc_buffer = ecc_buffer + 3; ecc_buffer = ecc_buffer + 3;
} }
/* Return success. */ /* Return success. */
return(LX_SUCCESS); return(LX_SUCCESS);
} }
+34 -46
View File
@@ -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 * This program and the accompanying materials are made available under the
* terms of the MIT License which is available at * terms of the MIT License which is available at
* https://opensource.org/licenses/MIT. * https://opensource.org/licenses/MIT.
* *
* SPDX-License-Identifier: MIT * SPDX-License-Identifier: MIT
**************************************************************************/ **************************************************************************/
/**************************************************************************/ /**************************************************************************/
/**************************************************************************/ /**************************************************************************/
/** */ /** */
/** LevelX Component */ /** LevelX Component */
/** */ /** */
/** NAND Flash */ /** NAND Flash */
/** */ /** */
@@ -34,57 +35,44 @@
#include "lx_api.h" #include "lx_api.h"
/**************************************************************************/ /**************************************************************************/
/* */ /* */
/* FUNCTION RELEASE */ /* FUNCTION RELEASE */
/* */ /* */
/* _lx_nand_flash_partial_defragment PORTABLE C */ /* _lx_nand_flash_partial_defragment PORTABLE C */
/* 6.2.1 */ /* 6.2.1 */
/* AUTHOR */ /* AUTHOR */
/* */ /* */
/* William E. Lamie, Microsoft Corporation */ /* William E. Lamie, Microsoft Corporation */
/* */ /* */
/* DESCRIPTION */ /* DESCRIPTION */
/* */
/* This function defragments the NAND flash up to the specified */
/* number of blocks. */
/* */
/* INPUT */
/* */
/* nand_flash NAND flash instance */
/* max_blocks Maximum number of blocks to */
/* defragment */
/* */
/* OUTPUT */
/* */
/* return status */
/* */
/* CALLS */
/* */
/* None */
/* */
/* CALLED BY */
/* */
/* Application Code */
/* Internal LevelX */
/* */
/* RELEASE HISTORY */
/* */
/* DATE NAME DESCRIPTION */
/* */ /* */
/* 05-19-2020 William E. Lamie Initial Version 6.0 */ /* This function defragments the NAND flash up to the specified */
/* 09-30-2020 William E. Lamie Modified comment(s), */ /* number of blocks. */
/* resulting in version 6.1 */ /* */
/* 06-02-2021 Bhupendra Naphade Modified comment(s), */ /* INPUT */
/* resulting in version 6.1.7 */ /* */
/* 03-08-2023 Xiuwen Cai Modified comment(s), */ /* nand_flash NAND flash instance */
/* deprecated this API, */ /* max_blocks Maximum number of blocks to */
/* resulting in version 6.2.1 */ /* defragment */
/* */
/* OUTPUT */
/* */
/* return status */
/* */
/* CALLS */
/* */
/* None */
/* */
/* CALLED BY */
/* */
/* Application Code */
/* Internal LevelX */
/* */ /* */
/**************************************************************************/ /**************************************************************************/
UINT _lx_nand_flash_partial_defragment(LX_NAND_FLASH *nand_flash, UINT max_blocks) UINT _lx_nand_flash_partial_defragment(LX_NAND_FLASH *nand_flash, UINT max_blocks)
{ {
LX_PARAMETER_NOT_USED(nand_flash); LX_PARAMETER_NOT_USED(nand_flash);
LX_PARAMETER_NOT_USED(max_blocks); LX_PARAMETER_NOT_USED(max_blocks);
+42 -47
View File
@@ -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 * This program and the accompanying materials are made available under the
* terms of the MIT License which is available at * terms of the MIT License which is available at
* https://opensource.org/licenses/MIT. * https://opensource.org/licenses/MIT.
* *
* SPDX-License-Identifier: MIT * SPDX-License-Identifier: MIT
**************************************************************************/ **************************************************************************/
/**************************************************************************/ /**************************************************************************/
/**************************************************************************/ /**************************************************************************/
/** */ /** */
/** LevelX Component */ /** LevelX Component */
/** */ /** */
/** NAND Flash */ /** NAND Flash */
/** */ /** */
@@ -34,49 +35,43 @@
#include "lx_api.h" #include "lx_api.h"
/**************************************************************************/ /**************************************************************************/
/* */ /* */
/* FUNCTION RELEASE */ /* FUNCTION RELEASE */
/* */ /* */
/* _lx_nand_flash_sector_read PORTABLE C */ /* _lx_nand_flash_sector_read PORTABLE C */
/* 6.2.1 */ /* 6.2.1 */
/* AUTHOR */ /* AUTHOR */
/* */ /* */
/* Xiuwen Cai, Microsoft Corporation */ /* Xiuwen Cai, Microsoft Corporation */
/* */ /* */
/* DESCRIPTION */ /* DESCRIPTION */
/* */
/* This function reads a logical sector from NAND flash. */
/* */
/* INPUT */
/* */
/* nand_flash NAND flash instance */
/* logical_sector Logical sector number */
/* buffer Pointer to buffer to read into*/
/* (the size is number of */
/* bytes in a page) */
/* */
/* OUTPUT */
/* */
/* return status */
/* */
/* CALLS */
/* */
/* _lx_nand_flash_block_find Find the mapped block */
/* lx_nand_flash_driver_pages_read Read pages */
/* _lx_nand_flash_system_error Internal system error handler */
/* tx_mutex_get Get thread protection */
/* tx_mutex_put Release thread protection */
/* */
/* CALLED BY */
/* */
/* Application Code */
/* */
/* RELEASE HISTORY */
/* */
/* DATE NAME DESCRIPTION */
/* */ /* */
/* 03-08-2023 Xiuwen Cai Initial Version 6.2.1 */ /* This function reads a logical sector from NAND flash. */
/* */
/* INPUT */
/* */
/* nand_flash NAND flash instance */
/* logical_sector Logical sector number */
/* buffer Pointer to buffer to read into*/
/* (the size is number of */
/* bytes in a page) */
/* */
/* OUTPUT */
/* */
/* return status */
/* */
/* CALLS */
/* */
/* _lx_nand_flash_block_find Find the mapped block */
/* lx_nand_flash_driver_pages_read Read pages */
/* _lx_nand_flash_system_error Internal system error handler */
/* tx_mutex_get Get thread protection */
/* tx_mutex_put Release thread protection */
/* */
/* CALLED BY */
/* */
/* Application Code */
/* */ /* */
/**************************************************************************/ /**************************************************************************/
UINT _lx_nand_flash_sector_read(LX_NAND_FLASH *nand_flash, ULONG logical_sector, VOID *buffer) UINT _lx_nand_flash_sector_read(LX_NAND_FLASH *nand_flash, ULONG logical_sector, VOID *buffer)
@@ -126,7 +121,7 @@ LONG page;
/* Determine if the block is mapped. */ /* Determine if the block is mapped. */
if (block != LX_NAND_BLOCK_UNMAPPED) if (block != LX_NAND_BLOCK_UNMAPPED)
{ {
/* Setup spare buffer pointer. */ /* Setup spare buffer pointer. */
spare_buffer_ptr = (UCHAR*)nand_flash -> lx_nand_flash_page_buffer; spare_buffer_ptr = (UCHAR*)nand_flash -> lx_nand_flash_page_buffer;
@@ -162,7 +157,7 @@ LONG page;
/* Return an error. */ /* Return an error. */
return(LX_ERROR); return(LX_ERROR);
} }
/* Get the logical sector number from spare bytes, and check if it matches the addressed sector number. */ /* Get the logical sector number from spare bytes, and check if it matches the addressed sector number. */
if ((LX_UTILITY_LONG_GET(&spare_buffer_ptr[nand_flash -> lx_nand_flash_spare_data1_offset]) & LX_NAND_PAGE_TYPE_USER_DATA_MASK) == logical_sector) if ((LX_UTILITY_LONG_GET(&spare_buffer_ptr[nand_flash -> lx_nand_flash_spare_data1_offset]) & LX_NAND_PAGE_TYPE_USER_DATA_MASK) == logical_sector)
{ {
@@ -240,14 +235,14 @@ LONG page;
/* Setup pointer to users buffer. */ /* Setup pointer to users buffer. */
word_ptr = (ULONG *) buffer; word_ptr = (ULONG *) buffer;
/* Put all ones in he buffer. */ /* Put all ones in he buffer. */
for (i = 0; i < nand_flash -> lx_nand_flash_words_per_page; i++) for (i = 0; i < nand_flash -> lx_nand_flash_words_per_page; i++)
{ {
/* Copy a word. */ /* Copy a word. */
*word_ptr++ = LX_ALL_ONES; *word_ptr++ = LX_ALL_ONES;
} }
/* Set the status to success. */ /* Set the status to success. */
status = LX_SUCCESS; status = LX_SUCCESS;
+44 -49
View File
@@ -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 * This program and the accompanying materials are made available under the
* terms of the MIT License which is available at * terms of the MIT License which is available at
* https://opensource.org/licenses/MIT. * https://opensource.org/licenses/MIT.
* *
* SPDX-License-Identifier: MIT * SPDX-License-Identifier: MIT
**************************************************************************/ **************************************************************************/
/**************************************************************************/ /**************************************************************************/
/**************************************************************************/ /**************************************************************************/
/** */ /** */
/** LevelX Component */ /** LevelX Component */
/** */ /** */
/** NAND Flash */ /** NAND Flash */
/** */ /** */
@@ -34,58 +35,52 @@
#include "lx_api.h" #include "lx_api.h"
/**************************************************************************/ /**************************************************************************/
/* */ /* */
/* FUNCTION RELEASE */ /* FUNCTION RELEASE */
/* */ /* */
/* _lx_nand_flash_sector_release PORTABLE C */ /* _lx_nand_flash_sector_release PORTABLE C */
/* 6.2.1 */ /* 6.2.1 */
/* AUTHOR */ /* AUTHOR */
/* */ /* */
/* Xiuwen Cai, Microsoft Corporation */ /* Xiuwen Cai, Microsoft Corporation */
/* */ /* */
/* DESCRIPTION */ /* DESCRIPTION */
/* */ /* */
/* This function releases a logical sector from being managed in the */ /* This function releases a logical sector from being managed in the */
/* NAND flash. */ /* NAND flash. */
/* */ /* */
/* INPUT */ /* INPUT */
/* */ /* */
/* nand_flash NAND flash instance */ /* nand_flash NAND flash instance */
/* logical_sector Logical sector number */ /* logical_sector Logical sector number */
/* */ /* */
/* OUTPUT */ /* OUTPUT */
/* */ /* */
/* return status */ /* return status */
/* */ /* */
/* CALLS */ /* CALLS */
/* */ /* */
/* _lx_nand_flash_block_find Find the mapped block */ /* _lx_nand_flash_block_find Find the mapped block */
/* lx_nand_flash_driver_pages_read Read pages */ /* lx_nand_flash_driver_pages_read Read pages */
/* _lx_nand_flash_block_allocate Allocate block */ /* _lx_nand_flash_block_allocate Allocate block */
/* _lx_nand_flash_mapped_block_list_remove */ /* _lx_nand_flash_mapped_block_list_remove */
/* Remove mapped block */ /* Remove mapped block */
/* _lx_nand_flash_data_page_copy Copy data pages */ /* _lx_nand_flash_data_page_copy Copy data pages */
/* _lx_nand_flash_free_block_list_add Add free block to list */ /* _lx_nand_flash_free_block_list_add Add free block to list */
/* _lx_nand_flash_block_mapping_set Set block mapping */ /* _lx_nand_flash_block_mapping_set Set block mapping */
/* _lx_nand_flash_driver_block_erase Erase block */ /* _lx_nand_flash_driver_block_erase Erase block */
/* _lx_nand_flash_erase_count_set Set erase count */ /* _lx_nand_flash_erase_count_set Set erase count */
/* _lx_nand_flash_block_data_move Move block data */ /* _lx_nand_flash_block_data_move Move block data */
/* _lx_nand_flash_block_status_set Set block status */ /* _lx_nand_flash_block_status_set Set block status */
/* _lx_nand_flash_mapped_block_list_add Add mapped block to list */ /* _lx_nand_flash_mapped_block_list_add Add mapped block to list */
/* _lx_nand_flash_system_error Internal system error handler */ /* _lx_nand_flash_system_error Internal system error handler */
/* tx_mutex_get Get thread protection */ /* tx_mutex_get Get thread protection */
/* tx_mutex_put Release thread protection */ /* tx_mutex_put Release thread protection */
/* */
/* CALLED BY */
/* */
/* Application Code */
/* */
/* RELEASE HISTORY */
/* */
/* DATE NAME DESCRIPTION */
/* */ /* */
/* 03-08-2023 Xiuwen Cai Initial Version 6.2.1 */ /* CALLED BY */
/* */
/* Application Code */
/* */ /* */
/**************************************************************************/ /**************************************************************************/
UINT _lx_nand_flash_sector_release(LX_NAND_FLASH *nand_flash, ULONG logical_sector) UINT _lx_nand_flash_sector_release(LX_NAND_FLASH *nand_flash, ULONG logical_sector)
@@ -388,7 +383,7 @@ USHORT new_block_status;
/* Check if there is valid pages in the new block. */ /* Check if there is valid pages in the new block. */
if ((new_block_status & LX_NAND_BLOCK_STATUS_PAGE_NUMBER_MASK) != 0) if ((new_block_status & LX_NAND_BLOCK_STATUS_PAGE_NUMBER_MASK) != 0)
{ {
/* Add the new block to mapped block list. */ /* Add the new block to mapped block list. */
_lx_nand_flash_mapped_block_list_add(nand_flash, logical_sector / nand_flash -> lx_nand_flash_pages_per_block); _lx_nand_flash_mapped_block_list_add(nand_flash, logical_sector / nand_flash -> lx_nand_flash_pages_per_block);
} }
@@ -398,7 +393,7 @@ USHORT new_block_status;
/* Set page buffer to all 0xFF bytes. */ /* Set page buffer to all 0xFF bytes. */
LX_MEMSET(nand_flash -> lx_nand_flash_page_buffer, 0xFF, nand_flash -> lx_nand_flash_bytes_per_page + nand_flash -> lx_nand_flash_spare_total_length); LX_MEMSET(nand_flash -> lx_nand_flash_page_buffer, 0xFF, nand_flash -> lx_nand_flash_bytes_per_page + nand_flash -> lx_nand_flash_spare_total_length);
/* Setup spare buffer pointer. */ /* Setup spare buffer pointer. */
spare_buffer_ptr = nand_flash -> lx_nand_flash_page_buffer + nand_flash -> lx_nand_flash_bytes_per_page; spare_buffer_ptr = nand_flash -> lx_nand_flash_page_buffer + nand_flash -> lx_nand_flash_bytes_per_page;
@@ -412,7 +407,7 @@ USHORT new_block_status;
/* Set page type and sector address. */ /* Set page type and sector address. */
LX_UTILITY_LONG_SET(&spare_buffer_ptr[nand_flash -> lx_nand_flash_spare_data1_offset], LX_NAND_PAGE_TYPE_USER_DATA_RELEASED | logical_sector); LX_UTILITY_LONG_SET(&spare_buffer_ptr[nand_flash -> lx_nand_flash_spare_data1_offset], LX_NAND_PAGE_TYPE_USER_DATA_RELEASED | logical_sector);
/* Write the page. */ /* Write the page. */
#ifdef LX_NAND_ENABLE_CONTROL_BLOCK_FOR_DRIVER_INTERFACE #ifdef LX_NAND_ENABLE_CONTROL_BLOCK_FOR_DRIVER_INTERFACE
status = (nand_flash -> lx_nand_flash_driver_pages_write)(nand_flash, block, available_pages, (UCHAR*)nand_flash -> lx_nand_flash_page_buffer, spare_buffer_ptr, 1); status = (nand_flash -> lx_nand_flash_driver_pages_write)(nand_flash, block, available_pages, (UCHAR*)nand_flash -> lx_nand_flash_page_buffer, spare_buffer_ptr, 1);
+48 -53
View File
@@ -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 * This program and the accompanying materials are made available under the
* terms of the MIT License which is available at * terms of the MIT License which is available at
* https://opensource.org/licenses/MIT. * https://opensource.org/licenses/MIT.
* *
* SPDX-License-Identifier: MIT * SPDX-License-Identifier: MIT
**************************************************************************/ **************************************************************************/
/**************************************************************************/ /**************************************************************************/
/**************************************************************************/ /**************************************************************************/
/** */ /** */
/** LevelX Component */ /** LevelX Component */
/** */ /** */
/** NAND Flash */ /** NAND Flash */
/** */ /** */
@@ -34,60 +35,54 @@
#include "lx_api.h" #include "lx_api.h"
/**************************************************************************/ /**************************************************************************/
/* */ /* */
/* FUNCTION RELEASE */ /* FUNCTION RELEASE */
/* */ /* */
/* _lx_nand_flash_sector_write PORTABLE C */ /* _lx_nand_flash_sector_write PORTABLE C */
/* 6.2.1 */ /* 6.2.1 */
/* AUTHOR */ /* AUTHOR */
/* */ /* */
/* Xiuwen Cai, Microsoft Corporation */ /* Xiuwen Cai, Microsoft Corporation */
/* */ /* */
/* DESCRIPTION */ /* DESCRIPTION */
/* */ /* */
/* This function writes a logical sector to the NAND flash page. */ /* This function writes a logical sector to the NAND flash page. */
/* */ /* */
/* INPUT */ /* INPUT */
/* */ /* */
/* nand_flash NAND flash instance */ /* nand_flash NAND flash instance */
/* logical_sector Logical sector number */ /* logical_sector Logical sector number */
/* buffer Pointer to buffer to write */ /* buffer Pointer to buffer to write */
/* (the size is number of */ /* (the size is number of */
/* bytes in a page) */ /* bytes in a page) */
/* */ /* */
/* OUTPUT */ /* OUTPUT */
/* */ /* */
/* return status */ /* return status */
/* */ /* */
/* CALLS */ /* CALLS */
/* */ /* */
/* _lx_nand_flash_block_find Find the mapped block */ /* _lx_nand_flash_block_find Find the mapped block */
/* _lx_nand_flash_block_allocate Allocate block */ /* _lx_nand_flash_block_allocate Allocate block */
/* _lx_nand_flash_mapped_block_list_remove */ /* _lx_nand_flash_mapped_block_list_remove */
/* Remove mapped block */ /* Remove mapped block */
/* _lx_nand_flash_data_page_copy Copy data pages */ /* _lx_nand_flash_data_page_copy Copy data pages */
/* _lx_nand_flash_free_block_list_add Add free block to list */ /* _lx_nand_flash_free_block_list_add Add free block to list */
/* _lx_nand_flash_block_mapping_set Set block mapping */ /* _lx_nand_flash_block_mapping_set Set block mapping */
/* lx_nand_flash_driver_pages_write Write pages */ /* lx_nand_flash_driver_pages_write Write pages */
/* _lx_nand_flash_block_status_set Set block status */ /* _lx_nand_flash_block_status_set Set block status */
/* _lx_nand_flash_driver_block_erase Erase block */ /* _lx_nand_flash_driver_block_erase Erase block */
/* _lx_nand_flash_erase_count_set Set erase count */ /* _lx_nand_flash_erase_count_set Set erase count */
/* _lx_nand_flash_block_data_move Move block data */ /* _lx_nand_flash_block_data_move Move block data */
/* _lx_nand_flash_mapped_block_list_add Add mapped block to list */ /* _lx_nand_flash_mapped_block_list_add Add mapped block to list */
/* _lx_nand_flash_system_error Internal system error handler */ /* _lx_nand_flash_system_error Internal system error handler */
/* tx_mutex_get Get thread protection */ /* tx_mutex_get Get thread protection */
/* tx_mutex_put Release thread protection */ /* tx_mutex_put Release thread protection */
/* */
/* CALLED BY */
/* */
/* Application Code */
/* */
/* RELEASE HISTORY */
/* */
/* DATE NAME DESCRIPTION */
/* */ /* */
/* 03-08-2023 Xiuwen Cai Initial Version 6.2.1 */ /* CALLED BY */
/* */
/* Application Code */
/* */ /* */
/**************************************************************************/ /**************************************************************************/
UINT _lx_nand_flash_sector_write(LX_NAND_FLASH *nand_flash, ULONG logical_sector, VOID *buffer) UINT _lx_nand_flash_sector_write(LX_NAND_FLASH *nand_flash, ULONG logical_sector, VOID *buffer)
@@ -114,7 +109,7 @@ UINT copy_block = LX_FALSE;
/* See if we can find the logical sector in the current mapping. */ /* See if we can find the logical sector in the current mapping. */
status = _lx_nand_flash_block_find(nand_flash, logical_sector, &block, &block_status); status = _lx_nand_flash_block_find(nand_flash, logical_sector, &block, &block_status);
/* Check return status. */ /* Check return status. */
if(status != LX_SUCCESS) if(status != LX_SUCCESS)
{ {
@@ -195,7 +190,7 @@ UINT copy_block = LX_FALSE;
new_block = block; new_block = block;
new_block_status = block_status; new_block_status = block_status;
} }
/* Check if copy block flag is set. */ /* Check if copy block flag is set. */
if (copy_block) if (copy_block)
{ {
@@ -222,7 +217,7 @@ UINT copy_block = LX_FALSE;
return(LX_ERROR); return(LX_ERROR);
} }
} }
/* Check if update mapping flag is set. */ /* Check if update mapping flag is set. */
if (update_mapping) if (update_mapping)
{ {
@@ -236,7 +231,7 @@ UINT copy_block = LX_FALSE;
/* Set spare buffer to all 0xFF bytes. */ /* Set spare buffer to all 0xFF bytes. */
LX_MEMSET(spare_buffer_ptr, 0xFF, nand_flash -> lx_nand_flash_spare_total_length); LX_MEMSET(spare_buffer_ptr, 0xFF, nand_flash -> lx_nand_flash_spare_total_length);
/* Check if there is enough spare data for metadata block number. */ /* Check if there is enough spare data for metadata block number. */
if (nand_flash -> lx_nand_flash_spare_data2_length >= sizeof(USHORT)) if (nand_flash -> lx_nand_flash_spare_data2_length >= sizeof(USHORT))
{ {
@@ -247,7 +242,7 @@ UINT copy_block = LX_FALSE;
/* Set page type and sector address. */ /* Set page type and sector address. */
LX_UTILITY_LONG_SET(&spare_buffer_ptr[nand_flash -> lx_nand_flash_spare_data1_offset], LX_NAND_PAGE_TYPE_USER_DATA | logical_sector); LX_UTILITY_LONG_SET(&spare_buffer_ptr[nand_flash -> lx_nand_flash_spare_data1_offset], LX_NAND_PAGE_TYPE_USER_DATA | logical_sector);
/* Get page to write. */ /* Get page to write. */
page = new_block_status & LX_NAND_BLOCK_STATUS_PAGE_NUMBER_MASK; page = new_block_status & LX_NAND_BLOCK_STATUS_PAGE_NUMBER_MASK;
+34 -39
View File
@@ -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 * This program and the accompanying materials are made available under the
* terms of the MIT License which is available at * terms of the MIT License which is available at
* https://opensource.org/licenses/MIT. * https://opensource.org/licenses/MIT.
* *
* SPDX-License-Identifier: MIT * SPDX-License-Identifier: MIT
**************************************************************************/ **************************************************************************/
/**************************************************************************/ /**************************************************************************/
/**************************************************************************/ /**************************************************************************/
/** */ /** */
/** LevelX Component */ /** LevelX Component */
/** */ /** */
/** NAND Flash */ /** NAND Flash */
/** */ /** */
@@ -34,46 +35,40 @@
#include "lx_api.h" #include "lx_api.h"
/**************************************************************************/ /**************************************************************************/
/* */ /* */
/* FUNCTION RELEASE */ /* FUNCTION RELEASE */
/* */ /* */
/* _lx_nand_flash_sectors_read PORTABLE C */ /* _lx_nand_flash_sectors_read PORTABLE C */
/* 6.2.1 */ /* 6.2.1 */
/* AUTHOR */ /* AUTHOR */
/* */ /* */
/* Xiuwen Cai, Microsoft Corporation */ /* Xiuwen Cai, Microsoft Corporation */
/* */ /* */
/* DESCRIPTION */ /* DESCRIPTION */
/* */
/* This function reads multiple logical sectors from NAND flash. */
/* */
/* INPUT */
/* */
/* nand_flash NAND flash instance */
/* logical_sector Logical sector number */
/* buffer Pointer to buffer to read into*/
/* (the size is number of */
/* bytes in a page) */
/* sector_count Number of sector to read */
/* */
/* OUTPUT */
/* */
/* return status */
/* */
/* CALLS */
/* */
/* _lx_nand_flash_sector_read Read a sector */
/* */
/* CALLED BY */
/* */
/* Application Code */
/* */
/* RELEASE HISTORY */
/* */
/* DATE NAME DESCRIPTION */
/* */ /* */
/* 03-08-2023 Xiuwen Cai Initial Version 6.2.1 */ /* This function reads multiple logical sectors from NAND flash. */
/* */
/* INPUT */
/* */
/* nand_flash NAND flash instance */
/* logical_sector Logical sector number */
/* buffer Pointer to buffer to read into*/
/* (the size is number of */
/* bytes in a page) */
/* sector_count Number of sector to read */
/* */
/* OUTPUT */
/* */
/* return status */
/* */
/* CALLS */
/* */
/* _lx_nand_flash_sector_read Read a sector */
/* */
/* CALLED BY */
/* */
/* Application Code */
/* */ /* */
/**************************************************************************/ /**************************************************************************/
UINT _lx_nand_flash_sectors_read(LX_NAND_FLASH *nand_flash, ULONG logical_sector, VOID *buffer, ULONG sector_count) UINT _lx_nand_flash_sectors_read(LX_NAND_FLASH *nand_flash, ULONG logical_sector, VOID *buffer, ULONG sector_count)
+32 -37
View File
@@ -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 * This program and the accompanying materials are made available under the
* terms of the MIT License which is available at * terms of the MIT License which is available at
* https://opensource.org/licenses/MIT. * https://opensource.org/licenses/MIT.
* *
* SPDX-License-Identifier: MIT * SPDX-License-Identifier: MIT
**************************************************************************/ **************************************************************************/
/**************************************************************************/ /**************************************************************************/
/**************************************************************************/ /**************************************************************************/
/** */ /** */
/** LevelX Component */ /** LevelX Component */
/** */ /** */
/** NAND Flash */ /** NAND Flash */
/** */ /** */
@@ -34,44 +35,38 @@
#include "lx_api.h" #include "lx_api.h"
/**************************************************************************/ /**************************************************************************/
/* */ /* */
/* FUNCTION RELEASE */ /* FUNCTION RELEASE */
/* */ /* */
/* _lx_nand_flash_sectors_release PORTABLE C */ /* _lx_nand_flash_sectors_release PORTABLE C */
/* 6.2.1 */ /* 6.2.1 */
/* AUTHOR */ /* AUTHOR */
/* */ /* */
/* Xiuwen Cai, Microsoft Corporation */ /* Xiuwen Cai, Microsoft Corporation */
/* */ /* */
/* DESCRIPTION */ /* DESCRIPTION */
/* */
/* This function releases multiple logical sectors from being managed */
/* in the NAND flash. */
/* */
/* INPUT */
/* */
/* nand_flash NAND flash instance */
/* logical_sector Logical sector number */
/* sector_count Number of sector to release */
/* */
/* OUTPUT */
/* */
/* return status */
/* */
/* CALLS */
/* */
/* _lx_nand_flash_sector_release Release one sector */
/* */
/* CALLED BY */
/* */
/* Application Code */
/* */
/* RELEASE HISTORY */
/* */
/* DATE NAME DESCRIPTION */
/* */ /* */
/* 03-08-2023 Xiuwen Cai Initial Version 6.2.1 */ /* This function releases multiple logical sectors from being managed */
/* in the NAND flash. */
/* */
/* INPUT */
/* */
/* nand_flash NAND flash instance */
/* logical_sector Logical sector number */
/* sector_count Number of sector to release */
/* */
/* OUTPUT */
/* */
/* return status */
/* */
/* CALLS */
/* */
/* _lx_nand_flash_sector_release Release one sector */
/* */
/* CALLED BY */
/* */
/* Application Code */
/* */ /* */
/**************************************************************************/ /**************************************************************************/
UINT _lx_nand_flash_sectors_release(LX_NAND_FLASH *nand_flash, ULONG logical_sector, ULONG sector_count) UINT _lx_nand_flash_sectors_release(LX_NAND_FLASH *nand_flash, ULONG logical_sector, ULONG sector_count)
+35 -40
View File
@@ -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 * This program and the accompanying materials are made available under the
* terms of the MIT License which is available at * terms of the MIT License which is available at
* https://opensource.org/licenses/MIT. * https://opensource.org/licenses/MIT.
* *
* SPDX-License-Identifier: MIT * SPDX-License-Identifier: MIT
**************************************************************************/ **************************************************************************/
/**************************************************************************/ /**************************************************************************/
/**************************************************************************/ /**************************************************************************/
/** */ /** */
/** LevelX Component */ /** LevelX Component */
/** */ /** */
/** NAND Flash */ /** NAND Flash */
/** */ /** */
@@ -34,46 +35,40 @@
#include "lx_api.h" #include "lx_api.h"
/**************************************************************************/ /**************************************************************************/
/* */ /* */
/* FUNCTION RELEASE */ /* FUNCTION RELEASE */
/* */ /* */
/* _lx_nand_flash_sectors_write PORTABLE C */ /* _lx_nand_flash_sectors_write PORTABLE C */
/* 6.2.1 */ /* 6.2.1 */
/* AUTHOR */ /* AUTHOR */
/* */ /* */
/* Xiuwen Cai, Microsoft Corporation */ /* Xiuwen Cai, Microsoft Corporation */
/* */ /* */
/* DESCRIPTION */ /* DESCRIPTION */
/* */
/* This function writes multiple logical sectors to the NAND flash. */
/* */
/* INPUT */
/* */
/* nand_flash NAND flash instance */
/* logical_sector Logical sector number */
/* buffer Pointer to buffer to write */
/* (the size is number of */
/* bytes in a page) */
/* sector_count Number of sector to write */
/* */
/* OUTPUT */
/* */
/* return status */
/* */
/* CALLS */
/* */
/* _lx_nand_flash_sector_write Write one sector */
/* */
/* CALLED BY */
/* */
/* Application Code */
/* */
/* RELEASE HISTORY */
/* */
/* DATE NAME DESCRIPTION */
/* */ /* */
/* 03-08-2023 Xiuwen Cai Initial Version 6.2.1 */ /* This function writes multiple logical sectors to the NAND flash. */
/* */
/* INPUT */
/* */
/* nand_flash NAND flash instance */
/* logical_sector Logical sector number */
/* buffer Pointer to buffer to write */
/* (the size is number of */
/* bytes in a page) */
/* sector_count Number of sector to write */
/* */
/* OUTPUT */
/* */
/* return status */
/* */
/* CALLS */
/* */
/* _lx_nand_flash_sector_write Write one sector */
/* */
/* CALLED BY */
/* */
/* Application Code */
/* */ /* */
/**************************************************************************/ /**************************************************************************/
UINT _lx_nand_flash_sectors_write(LX_NAND_FLASH *nand_flash, ULONG logical_sector, VOID *buffer, ULONG sector_count) UINT _lx_nand_flash_sectors_write(LX_NAND_FLASH *nand_flash, ULONG logical_sector, VOID *buffer, ULONG sector_count)
@@ -89,7 +84,7 @@ UINT i;
/* Write one sector. */ /* Write one sector. */
status = _lx_nand_flash_sector_write(nand_flash, logical_sector + i, ((UCHAR*)buffer) + i * nand_flash -> lx_nand_flash_bytes_per_page); status = _lx_nand_flash_sector_write(nand_flash, logical_sector + i, ((UCHAR*)buffer) + i * nand_flash -> lx_nand_flash_bytes_per_page);
/* Check return status. */ /* Check return status. */
if (status) if (status)
{ {
+53 -52
View File
@@ -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 * This program and the accompanying materials are made available under the
* terms of the MIT License which is available at * terms of the MIT License which is available at
* https://opensource.org/licenses/MIT. * https://opensource.org/licenses/MIT.
* *
* SPDX-License-Identifier: MIT * SPDX-License-Identifier: MIT
**************************************************************************/ **************************************************************************/
/**************************************************************************/ /**************************************************************************/
/**************************************************************************/ /**************************************************************************/
/** */ /** */
/** LevelX Component */ /** LevelX Component */
/** */ /** */
/** NAND Flash Simulator */ /** NAND Flash Simulator */
/** */ /** */
@@ -28,13 +29,13 @@
#define TOTAL_BLOCKS 1024 #define TOTAL_BLOCKS 1024
#define PHYSICAL_PAGES_PER_BLOCK 256 /* Min value of 2 */ #define PHYSICAL_PAGES_PER_BLOCK 256 /* Min value of 2 */
#define BYTES_PER_PHYSICAL_PAGE 512 /* 512 bytes per page */ #define BYTES_PER_PHYSICAL_PAGE 512 /* 512 bytes per page */
#define WORDS_PER_PHYSICAL_PAGE 512 / 4 /* Words per page */ #define WORDS_PER_PHYSICAL_PAGE 512 / 4 /* Words per page */
#define SPARE_BYTES_PER_PAGE 16 /* 16 "spare" bytes per page */ #define SPARE_BYTES_PER_PAGE 16 /* 16 "spare" bytes per page */
/* For 2048 byte block spare area: */ /* For 2048 byte block spare area: */
#define BAD_BLOCK_POSITION 0 /* 0 is the bad block byte postion */ #define BAD_BLOCK_POSITION 0 /* 0 is the bad block byte postion */
#define EXTRA_BYTE_POSITION 0 /* 0 is the extra bytes starting byte postion */ #define EXTRA_BYTE_POSITION 0 /* 0 is the extra bytes starting byte postion */
#define ECC_BYTE_POSITION 8 /* 8 is the ECC starting byte position */ #define ECC_BYTE_POSITION 8 /* 8 is the ECC starting byte position */
#define SPARE_DATA1_OFFSET 4 #define SPARE_DATA1_OFFSET 4
#define SPARE_DATA1_LENGTH 4 #define SPARE_DATA1_LENGTH 4
#define SPARE_DATA2_OFFSET 2 #define SPARE_DATA2_OFFSET 2
@@ -42,29 +43,29 @@
/* Definition of the spare area is relative to the block size of the NAND part and perhaps manufactures of the NAND part. /* Definition of the spare area is relative to the block size of the NAND part and perhaps manufactures of the NAND part.
Here are some common definitions: Here are some common definitions:
256 Byte Block 256 Byte Block
Bytes Meaning Bytes Meaning
0,1,2 ECC bytes 0,1,2 ECC bytes
3,4,6,7 Extra 3,4,6,7 Extra
5 Bad block flag 5 Bad block flag
512 Byte Block 512 Byte Block
Bytes Meaning Bytes Meaning
0,1,2,3,6,7 ECC bytes 0,1,2,3,6,7 ECC bytes
8-15 Extra 8-15 Extra
5 Bad block flag 5 Bad block flag
2048 Byte Block 2048 Byte Block
Bytes Meaning Bytes Meaning
0 Bad block flag 0 Bad block flag
2-39 Extra 2-39 Extra
40-63 ECC bytes 40-63 ECC bytes
@@ -288,7 +289,7 @@ UINT ecc_status = LX_SUCCESS;
status = _lx_nand_flash_simulator_extra_bytes_get(block, page + i, spare_buffer + i * SPARE_BYTES_PER_PAGE, SPARE_BYTES_PER_PAGE); status = _lx_nand_flash_simulator_extra_bytes_get(block, page + i, spare_buffer + i * SPARE_BYTES_PER_PAGE, SPARE_BYTES_PER_PAGE);
#endif #endif
} }
} }
return (ecc_status); return (ecc_status);
} }
@@ -328,32 +329,32 @@ ULONG *page_ptr = &(nand_memory_area[block].physical_pages[page].memory[0]);
in a NAND device. */ in a NAND device. */
if ((*source & *flash_address) != *source) if ((*source & *flash_address) != *source)
return(LX_INVALID_WRITE); return(LX_INVALID_WRITE);
/* Copy word. */ /* Copy word. */
*flash_address++ = *source++; *flash_address++ = *source++;
} }
/* Loop to compute the ECC over the entire NAND flash page. */ /* Loop to compute the ECC over the entire NAND flash page. */
bytes_computed = 0; bytes_computed = 0;
while (bytes_computed < BYTES_PER_PHYSICAL_PAGE) while (bytes_computed < BYTES_PER_PHYSICAL_PAGE)
{ {
/* Compute the ECC for this 256 byte piece of the page. */ /* Compute the ECC for this 256 byte piece of the page. */
_lx_nand_flash_256byte_ecc_compute((UCHAR *)page_ptr, (UCHAR *)new_ecc_buffer_ptr); _lx_nand_flash_256byte_ecc_compute((UCHAR *)page_ptr, (UCHAR *)new_ecc_buffer_ptr);
/* Move to the next 256 byte portion of the page. */ /* Move to the next 256 byte portion of the page. */
bytes_computed = bytes_computed + 256; bytes_computed = bytes_computed + 256;
/* Move the page buffer forward. */ /* Move the page buffer forward. */
page_ptr = page_ptr + 64; page_ptr = page_ptr + 64;
ecc_bytes = ecc_bytes + 3; ecc_bytes = ecc_bytes + 3;
/* Move the ECC buffer forward, note there are 3 bytes of ECC per page. */ /* Move the ECC buffer forward, note there are 3 bytes of ECC per page. */
new_ecc_buffer_ptr = new_ecc_buffer_ptr + 3; new_ecc_buffer_ptr = new_ecc_buffer_ptr + 3;
} }
/* Setup destination pointer in the spare area. */ /* Setup destination pointer in the spare area. */
flash_spare_address = (UCHAR *) &(nand_memory_area[block].physical_pages[page].spare[ECC_BYTE_POSITION]); flash_spare_address = (UCHAR *) &(nand_memory_area[block].physical_pages[page].spare[ECC_BYTE_POSITION]);
while(ecc_bytes--) while(ecc_bytes--)
@@ -464,7 +465,7 @@ UINT i;
words = sizeof(NAND_FLASH_BLOCK)/sizeof(ULONG); words = sizeof(NAND_FLASH_BLOCK)/sizeof(ULONG);
while (words--) while (words--)
{ {
/* Erase word of block. */ /* Erase word of block. */
*pointer++ = (ULONG) 0xFFFFFFFF; *pointer++ = (ULONG) 0xFFFFFFFF;
} }
@@ -488,7 +489,7 @@ UINT i, j;
for (j = 0; j < PHYSICAL_PAGES_PER_BLOCK;j++) for (j = 0; j < PHYSICAL_PAGES_PER_BLOCK;j++)
nand_block_diag[i].page_writes[j] = 0; nand_block_diag[i].page_writes[j] = 0;
} }
/* Setup pointer. */ /* Setup pointer. */
pointer = (ULONG *) &nand_memory_area[0]; pointer = (ULONG *) &nand_memory_area[0];
@@ -496,7 +497,7 @@ UINT i, j;
words = sizeof(nand_memory_area)/(sizeof(ULONG)); words = sizeof(nand_memory_area)/(sizeof(ULONG));
while (words--) while (words--)
{ {
/* Erase word of block. */ /* Erase word of block. */
*pointer++ = (ULONG) 0xFFFFFFFF; *pointer++ = (ULONG) 0xFFFFFFFF;
} }
@@ -520,22 +521,22 @@ ULONG words;
#endif #endif
/* Determine if the block is completely erased. */ /* Determine if the block is completely erased. */
/* Pickup the pointer to the first word of the block. */ /* Pickup the pointer to the first word of the block. */
word_ptr = (ULONG *) &nand_memory_area[block]; word_ptr = (ULONG *) &nand_memory_area[block];
/* Calculate the number of words in a block. */ /* Calculate the number of words in a block. */
words = sizeof(NAND_FLASH_BLOCK)/sizeof(ULONG); words = sizeof(NAND_FLASH_BLOCK)/sizeof(ULONG);
/* Loop to check if the block is erased. */ /* Loop to check if the block is erased. */
while (words--) while (words--)
{ {
/* Is this word erased? */ /* Is this word erased? */
if (*word_ptr++ != 0xFFFFFFFF) if (*word_ptr++ != 0xFFFFFFFF)
return(LX_ERROR); return(LX_ERROR);
} }
/* Return success. */ /* Return success. */
return(LX_SUCCESS); return(LX_SUCCESS);
} }
@@ -555,22 +556,22 @@ ULONG words;
#endif #endif
/* Determine if the block is completely erased. */ /* Determine if the block is completely erased. */
/* Pickup the pointer to the first word of the block's page. */ /* Pickup the pointer to the first word of the block's page. */
word_ptr = (ULONG *) &nand_memory_area[block].physical_pages[page]; word_ptr = (ULONG *) &nand_memory_area[block].physical_pages[page];
/* Calculate the number of words in a block. */ /* Calculate the number of words in a block. */
words = WORDS_PER_PHYSICAL_PAGE; words = WORDS_PER_PHYSICAL_PAGE;
/* Loop to check if the page is erased. */ /* Loop to check if the page is erased. */
while (words--) while (words--)
{ {
/* Is this word erased? */ /* Is this word erased? */
if (*word_ptr++ != 0xFFFFFFFF) if (*word_ptr++ != 0xFFFFFFFF)
return(LX_ERROR); return(LX_ERROR);
} }
/* Return success. */ /* Return success. */
return(LX_SUCCESS); return(LX_SUCCESS);
} }
@@ -588,7 +589,7 @@ UINT _lx_nand_flash_simulator_block_status_get(ULONG block, UCHAR *bad_block_by
/* Pickup the bad block byte and return it. */ /* Pickup the bad block byte and return it. */
*bad_block_byte = nand_memory_area[block].physical_pages[0].spare[BAD_BLOCK_POSITION]; *bad_block_byte = nand_memory_area[block].physical_pages[0].spare[BAD_BLOCK_POSITION];
/* Return success. */ /* Return success. */
return(LX_SUCCESS); return(LX_SUCCESS);
} }
@@ -606,7 +607,7 @@ UINT _lx_nand_flash_simulator_block_status_set(ULONG block, UCHAR bad_block_byt
/* Set the bad block byte. */ /* Set the bad block byte. */
nand_memory_area[block].physical_pages[0].spare[BAD_BLOCK_POSITION] = bad_block_byte; nand_memory_area[block].physical_pages[0].spare[BAD_BLOCK_POSITION] = bad_block_byte;
/* Return success. */ /* Return success. */
return(LX_SUCCESS); return(LX_SUCCESS);
} }
@@ -624,14 +625,14 @@ UCHAR *source;
#ifdef LX_NAND_ENABLE_CONTROL_BLOCK_FOR_DRIVER_INTERFACE #ifdef LX_NAND_ENABLE_CONTROL_BLOCK_FOR_DRIVER_INTERFACE
LX_PARAMETER_NOT_USED(nand_flash); LX_PARAMETER_NOT_USED(nand_flash);
#endif #endif
/* Setup source pointer in the spare area. */ /* Setup source pointer in the spare area. */
source = (UCHAR *) &(nand_memory_area[block].physical_pages[page].spare[EXTRA_BYTE_POSITION]); source = (UCHAR *) &(nand_memory_area[block].physical_pages[page].spare[EXTRA_BYTE_POSITION]);
/* Loop to return the extra bytes requested. */ /* Loop to return the extra bytes requested. */
while (size--) while (size--)
{ {
/* Retrieve an extra byte from the spare area. */ /* Retrieve an extra byte from the spare area. */
*destination++ = *source++; *destination++ = *source++;
} }
@@ -652,19 +653,19 @@ UCHAR *destination;
#ifdef LX_NAND_ENABLE_CONTROL_BLOCK_FOR_DRIVER_INTERFACE #ifdef LX_NAND_ENABLE_CONTROL_BLOCK_FOR_DRIVER_INTERFACE
LX_PARAMETER_NOT_USED(nand_flash); LX_PARAMETER_NOT_USED(nand_flash);
#endif #endif
/* Increment the diag info. */ /* Increment the diag info. */
nand_block_diag[block].page_writes[page]++; nand_block_diag[block].page_writes[page]++;
if (nand_block_diag[block].page_writes[page] > nand_block_diag[block].max_page_writes[page]) if (nand_block_diag[block].page_writes[page] > nand_block_diag[block].max_page_writes[page])
nand_block_diag[block].max_page_writes[page] = nand_block_diag[block].page_writes[page]; nand_block_diag[block].max_page_writes[page] = nand_block_diag[block].page_writes[page];
/* Setup destination pointer in the spare area. */ /* Setup destination pointer in the spare area. */
destination = (UCHAR *) &(nand_memory_area[block].physical_pages[page].spare[EXTRA_BYTE_POSITION]); destination = (UCHAR *) &(nand_memory_area[block].physical_pages[page].spare[EXTRA_BYTE_POSITION]);
/* Loop to set the extra bytes. */ /* Loop to set the extra bytes. */
while (size--) while (size--)
{ {
/* Set an extra byte in the spare area. */ /* Set an extra byte in the spare area. */
*destination++ = *source++; *destination++ = *source++;
} }
+38 -50
View File
@@ -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 * This program and the accompanying materials are made available under the
* terms of the MIT License which is available at * terms of the MIT License which is available at
* https://opensource.org/licenses/MIT. * https://opensource.org/licenses/MIT.
* *
* SPDX-License-Identifier: MIT * SPDX-License-Identifier: MIT
**************************************************************************/ **************************************************************************/
/**************************************************************************/ /**************************************************************************/
/**************************************************************************/ /**************************************************************************/
/** */ /** */
/** LevelX Component */ /** LevelX Component */
/** */ /** */
/** NAND Flash */ /** NAND Flash */
/** */ /** */
@@ -34,51 +35,38 @@
#include "lx_api.h" #include "lx_api.h"
/**************************************************************************/ /**************************************************************************/
/* */ /* */
/* FUNCTION RELEASE */ /* FUNCTION RELEASE */
/* */ /* */
/* _lx_nand_flash_system_error PORTABLE C */ /* _lx_nand_flash_system_error PORTABLE C */
/* 6.2.1 */ /* 6.2.1 */
/* AUTHOR */ /* AUTHOR */
/* */ /* */
/* William E. Lamie, Microsoft Corporation */ /* William E. Lamie, Microsoft Corporation */
/* */ /* */
/* DESCRIPTION */ /* DESCRIPTION */
/* */
/* This function handles system errors in the NAND flash. */
/* */
/* INPUT */
/* */
/* nand_flash NAND flash instance */
/* error_code System error code */
/* block Block where error occurred */
/* page Page where error occurred */
/* */
/* OUTPUT */
/* */
/* None */
/* */
/* CALLS */
/* */
/* (lx_nand_flash_driver_system_error) Driver system error handler */
/* */
/* CALLED BY */
/* */
/* Internal LevelX */
/* */
/* RELEASE HISTORY */
/* */
/* DATE NAME DESCRIPTION */
/* */ /* */
/* 05-19-2020 William E. Lamie Initial Version 6.0 */ /* This function handles system errors in the NAND flash. */
/* 09-30-2020 William E. Lamie Modified comment(s), */ /* */
/* resulting in version 6.1 */ /* INPUT */
/* 06-02-2021 Bhupendra Naphade Modified comment(s), */ /* */
/* resulting in version 6.1.7 */ /* nand_flash NAND flash instance */
/* 03-08-2023 Xiuwen Cai Modified comment(s), */ /* error_code System error code */
/* added new driver interface, */ /* block Block where error occurred */
/* resulting in version 6.2.1 */ /* page Page where error occurred */
/* */
/* OUTPUT */
/* */
/* None */
/* */
/* CALLS */
/* */
/* (lx_nand_flash_driver_system_error) Driver system error handler */
/* */
/* CALLED BY */
/* */
/* Internal LevelX */
/* */ /* */
/**************************************************************************/ /**************************************************************************/
VOID _lx_nand_flash_system_error(LX_NAND_FLASH *nand_flash, UINT error_code, ULONG block, ULONG page) VOID _lx_nand_flash_system_error(LX_NAND_FLASH *nand_flash, UINT error_code, ULONG block, ULONG page)
@@ -86,26 +74,26 @@ VOID _lx_nand_flash_system_error(LX_NAND_FLASH *nand_flash, UINT error_code, UL
/* Increment the system error counter. */ /* Increment the system error counter. */
nand_flash -> lx_nand_flash_diagnostic_system_errors++; nand_flash -> lx_nand_flash_diagnostic_system_errors++;
/* Save the most recent system error code. */ /* Save the most recent system error code. */
nand_flash -> lx_nand_flash_diagnostic_system_error = error_code; nand_flash -> lx_nand_flash_diagnostic_system_error = error_code;
/* Determine if the system error is a NAND page corrected error. */ /* Determine if the system error is a NAND page corrected error. */
if (error_code == LX_NAND_ERROR_CORRECTED) if (error_code == LX_NAND_ERROR_CORRECTED)
{ {
/* Yes, increment error correction information. */ /* Yes, increment error correction information. */
nand_flash -> lx_nand_flash_page_corrections++; nand_flash -> lx_nand_flash_page_corrections++;
/* Remember the last block/page of corrected error. */ /* Remember the last block/page of corrected error. */
nand_flash -> lx_nand_flash_last_block_correction = block; nand_flash -> lx_nand_flash_last_block_correction = block;
nand_flash -> lx_nand_flash_last_page_correction = page; nand_flash -> lx_nand_flash_last_page_correction = page;
} }
/* Determine if the driver has setup a system error handler. */ /* Determine if the driver has setup a system error handler. */
if (nand_flash -> lx_nand_flash_driver_system_error) if (nand_flash -> lx_nand_flash_driver_system_error)
{ {
/* Yes, call the driver's system error handler. */ /* Yes, call the driver's system error handler. */
#ifdef LX_NAND_ENABLE_CONTROL_BLOCK_FOR_DRIVER_INTERFACE #ifdef LX_NAND_ENABLE_CONTROL_BLOCK_FOR_DRIVER_INTERFACE
(nand_flash -> lx_nand_flash_driver_system_error)(nand_flash, error_code, block, page); (nand_flash -> lx_nand_flash_driver_system_error)(nand_flash, error_code, block, page);
+109 -123
View File
@@ -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 * This program and the accompanying materials are made available under the
* terms of the MIT License which is available at * terms of the MIT License which is available at
* https://opensource.org/licenses/MIT. * https://opensource.org/licenses/MIT.
* *
* SPDX-License-Identifier: MIT * SPDX-License-Identifier: MIT
**************************************************************************/ **************************************************************************/
/**************************************************************************/ /**************************************************************************/
/**************************************************************************/ /**************************************************************************/
/** */ /** */
/** LevelX Component */ /** LevelX Component */
/** */ /** */
/** NOR Flash */ /** NOR Flash */
/** */ /** */
@@ -34,59 +35,44 @@
#include "lx_api.h" #include "lx_api.h"
/**************************************************************************/ /**************************************************************************/
/* */ /* */
/* FUNCTION RELEASE */ /* FUNCTION RELEASE */
/* */ /* */
/* _lx_nor_flash_block_reclaim PORTABLE C */ /* _lx_nor_flash_block_reclaim PORTABLE C */
/* 6.3.0 */ /* 6.3.0 */
/* AUTHOR */ /* AUTHOR */
/* */ /* */
/* William E. Lamie, Microsoft Corporation */ /* William E. Lamie, Microsoft Corporation */
/* */ /* */
/* DESCRIPTION */ /* DESCRIPTION */
/* */
/* This function reclaims one block from the NOR flash. */
/* */
/* INPUT */
/* */
/* nor_flash NOR flash instance */
/* */
/* OUTPUT */
/* */
/* return status */
/* */
/* CALLS */
/* */
/* _lx_nor_flash_driver_block_erase Driver erase block */
/* _lx_nor_flash_driver_write Driver flash sector write */
/* _lx_nor_flash_driver_read Driver flash sector read */
/* _lx_nor_flash_next_block_to_erase_find */
/* Find next block to erase */
/* _lx_nor_flash_physical_sector_allocate */
/* Allocate new logical sector */
/* _lx_nor_flash_sector_mapping_cache_invalidate */
/* Invalidate cache entry */
/* _lx_nor_flash_system_error Internal system error handler */
/* */
/* CALLED BY */
/* */
/* Internal LevelX */
/* */
/* RELEASE HISTORY */
/* */
/* DATE NAME DESCRIPTION */
/* */ /* */
/* 05-19-2020 William E. Lamie Initial Version 6.0 */ /* This function reclaims one block from the NOR flash. */
/* 09-30-2020 William E. Lamie Modified comment(s), */ /* */
/* resulting in version 6.1 */ /* INPUT */
/* 06-02-2021 Bhupendra Naphade Modified comment(s), */ /* */
/* resulting in version 6.1.7 */ /* nor_flash NOR flash instance */
/* 10-31-2023 Xiuwen Cai Modified comment(s), */ /* */
/* added count for minimum */ /* OUTPUT */
/* erased blocks, added */ /* */
/* obsolete count cache, */ /* return status */
/* resulting in version 6.3.0 */ /* */
/* CALLS */
/* */
/* _lx_nor_flash_driver_block_erase Driver erase block */
/* _lx_nor_flash_driver_write Driver flash sector write */
/* _lx_nor_flash_driver_read Driver flash sector read */
/* _lx_nor_flash_next_block_to_erase_find */
/* Find next block to erase */
/* _lx_nor_flash_physical_sector_allocate */
/* Allocate new logical sector */
/* _lx_nor_flash_sector_mapping_cache_invalidate */
/* Invalidate cache entry */
/* _lx_nor_flash_system_error Internal system error handler */
/* */
/* CALLED BY */
/* */
/* Internal LevelX */
/* */ /* */
/**************************************************************************/ /**************************************************************************/
UINT _lx_nor_flash_block_reclaim(LX_NOR_FLASH *nor_flash) UINT _lx_nor_flash_block_reclaim(LX_NOR_FLASH *nor_flash)
@@ -116,10 +102,10 @@ UINT status;
/* Determine if the search pointer is set for this block. */ /* Determine if the search pointer is set for this block. */
if (nor_flash -> lx_nor_flash_free_block_search == erase_block) if (nor_flash -> lx_nor_flash_free_block_search == erase_block)
{ {
/* Ensure the search block is not the block we are trying to free. */ /* Ensure the search block is not the block we are trying to free. */
nor_flash -> lx_nor_flash_free_block_search = erase_block + 1; nor_flash -> lx_nor_flash_free_block_search = erase_block + 1;
/* Check for wrap condition. */ /* Check for wrap condition. */
if (nor_flash -> lx_nor_flash_free_block_search >= nor_flash -> lx_nor_flash_total_blocks) if (nor_flash -> lx_nor_flash_free_block_search >= nor_flash -> lx_nor_flash_total_blocks)
nor_flash -> lx_nor_flash_free_block_search = 0; nor_flash -> lx_nor_flash_free_block_search = 0;
@@ -132,31 +118,31 @@ UINT status;
if (obsolete_sectors == nor_flash -> lx_nor_flash_physical_sectors_per_block) if (obsolete_sectors == nor_flash -> lx_nor_flash_physical_sectors_per_block)
{ {
/* Write the erased started indication. */ /* Write the erased started indication. */
erase_started_value = LX_BLOCK_ERASE_STARTED; erase_started_value = LX_BLOCK_ERASE_STARTED;
status = _lx_nor_flash_driver_write(nor_flash, block_word_ptr, &erase_started_value, 1); status = _lx_nor_flash_driver_write(nor_flash, block_word_ptr, &erase_started_value, 1);
/* Check for an error from flash driver. Drivers should never return an error.. */ /* Check for an error from flash driver. Drivers should never return an error.. */
if (status) if (status)
{ {
/* Call system error handler. */ /* Call system error handler. */
_lx_nor_flash_system_error(nor_flash, status); _lx_nor_flash_system_error(nor_flash, status);
/* Return the error. */ /* Return the error. */
return(status); return(status);
} }
/* Erase the entire block. */ /* Erase the entire block. */
status = _lx_nor_flash_driver_block_erase(nor_flash, erase_block, erase_count+1); status = _lx_nor_flash_driver_block_erase(nor_flash, erase_block, erase_count+1);
/* Check for an error from flash driver. Drivers should never return an error.. */ /* Check for an error from flash driver. Drivers should never return an error.. */
if (status) if (status)
{ {
/* Call system error handler. */ /* Call system error handler. */
_lx_nor_flash_system_error(nor_flash, status); _lx_nor_flash_system_error(nor_flash, status);
/* Return the error. */ /* Return the error. */
return(status); return(status);
} }
@@ -164,47 +150,47 @@ UINT status;
/* Determine if the erase count is at the minimum. */ /* Determine if the erase count is at the minimum. */
if (erase_count == nor_flash -> lx_nor_flash_minimum_erase_count) if (erase_count == nor_flash -> lx_nor_flash_minimum_erase_count)
{ {
/* Yes, decrement the minimum erased block count. */ /* Yes, decrement the minimum erased block count. */
nor_flash -> lx_nor_flash_minimum_erased_blocks--; nor_flash -> lx_nor_flash_minimum_erased_blocks--;
} }
/* Increment the erase count. */ /* Increment the erase count. */
erase_count++; erase_count++;
/* Determine if the new erase count exceeds the maximum. */ /* Determine if the new erase count exceeds the maximum. */
if (erase_count > ((ULONG) LX_BLOCK_ERASE_COUNT_MAX)) if (erase_count > ((ULONG) LX_BLOCK_ERASE_COUNT_MAX))
{ {
/* Yes, erase count is in overflow. Stay at the maximum count. */ /* Yes, erase count is in overflow. Stay at the maximum count. */
erase_count = ((ULONG) LX_BLOCK_ERASE_COUNT_MAX); erase_count = ((ULONG) LX_BLOCK_ERASE_COUNT_MAX);
} }
/* Determine if we need to update the maximum erase count. */ /* Determine if we need to update the maximum erase count. */
if (erase_count > nor_flash -> lx_nor_flash_maximum_erase_count) if (erase_count > nor_flash -> lx_nor_flash_maximum_erase_count)
{ {
/* Yes, a new maximum is present. */ /* Yes, a new maximum is present. */
nor_flash -> lx_nor_flash_maximum_erase_count = erase_count; nor_flash -> lx_nor_flash_maximum_erase_count = erase_count;
} }
/* Setup the free bit map that corresponds to the free physical sectors in this /* Setup the free bit map that corresponds to the free physical sectors in this
block. Note that we only need to setup the portion of the free bit map that doesn't block. Note that we only need to setup the portion of the free bit map that doesn't
have sectors associated with it. */ have sectors associated with it. */
status = _lx_nor_flash_driver_write(nor_flash, block_word_ptr+(nor_flash -> lx_nor_flash_block_free_bit_map_offset + (nor_flash -> lx_nor_flash_block_bit_map_words - 1)), status = _lx_nor_flash_driver_write(nor_flash, block_word_ptr+(nor_flash -> lx_nor_flash_block_free_bit_map_offset + (nor_flash -> lx_nor_flash_block_bit_map_words - 1)),
&(nor_flash -> lx_nor_flash_block_bit_map_mask), 1); &(nor_flash -> lx_nor_flash_block_bit_map_mask), 1);
/* Check for an error from flash driver. Drivers should never return an error.. */ /* Check for an error from flash driver. Drivers should never return an error.. */
if (status) if (status)
{ {
/* Call system error handler. */ /* Call system error handler. */
_lx_nor_flash_system_error(nor_flash, status); _lx_nor_flash_system_error(nor_flash, status);
/* Return the error. */ /* Return the error. */
return(status); return(status);
} }
/* Write the initial erase count for the block with upper bit set. */ /* Write the initial erase count for the block with upper bit set. */
temp_erase_count = (erase_count | LX_BLOCK_ERASED); temp_erase_count = (erase_count | LX_BLOCK_ERASED);
status = _lx_nor_flash_driver_write(nor_flash, block_word_ptr, &temp_erase_count, 1); status = _lx_nor_flash_driver_write(nor_flash, block_word_ptr, &temp_erase_count, 1);
@@ -212,7 +198,7 @@ UINT status;
/* Check for an error from flash driver. Drivers should never return an error.. */ /* Check for an error from flash driver. Drivers should never return an error.. */
if (status) if (status)
{ {
/* Call system error handler. */ /* Call system error handler. */
_lx_nor_flash_system_error(nor_flash, status); _lx_nor_flash_system_error(nor_flash, status);
@@ -226,14 +212,14 @@ UINT status;
/* Check for an error from flash driver. Drivers should never return an error.. */ /* Check for an error from flash driver. Drivers should never return an error.. */
if (status) if (status)
{ {
/* Call system error handler. */ /* Call system error handler. */
_lx_nor_flash_system_error(nor_flash, status); _lx_nor_flash_system_error(nor_flash, status);
/* Return the error. */ /* Return the error. */
return(status); return(status);
} }
/* Update parameters of this flash. */ /* Update parameters of this flash. */
nor_flash -> lx_nor_flash_free_physical_sectors = nor_flash -> lx_nor_flash_free_physical_sectors + obsolete_sectors; nor_flash -> lx_nor_flash_free_physical_sectors = nor_flash -> lx_nor_flash_free_physical_sectors + obsolete_sectors;
nor_flash -> lx_nor_flash_obsolete_physical_sectors = nor_flash -> lx_nor_flash_obsolete_physical_sectors - obsolete_sectors; nor_flash -> lx_nor_flash_obsolete_physical_sectors = nor_flash -> lx_nor_flash_obsolete_physical_sectors - obsolete_sectors;
@@ -248,16 +234,16 @@ UINT status;
} }
#endif #endif
} }
else else
{ {
/* Calculate the number of free sectors in this block. */ /* Calculate the number of free sectors in this block. */
free_sectors = nor_flash -> lx_nor_flash_physical_sectors_per_block - (obsolete_sectors + mapped_sectors); free_sectors = nor_flash -> lx_nor_flash_physical_sectors_per_block - (obsolete_sectors + mapped_sectors);
/* Determine if there are enough free sectors outside of this block to reclaim this block. */ /* Determine if there are enough free sectors outside of this block to reclaim this block. */
if (mapped_sectors <= (nor_flash -> lx_nor_flash_free_physical_sectors - free_sectors)) if (mapped_sectors <= (nor_flash -> lx_nor_flash_free_physical_sectors - free_sectors))
{ {
/* Setup a pointer to the mapped list. */ /* Setup a pointer to the mapped list. */
list_word_ptr = block_word_ptr + nor_flash -> lx_nor_flash_block_physical_sector_mapping_offset; list_word_ptr = block_word_ptr + nor_flash -> lx_nor_flash_block_physical_sector_mapping_offset;
@@ -267,7 +253,7 @@ UINT status;
/* Pickup the mapped sector list entry. */ /* Pickup the mapped sector list entry. */
#ifdef LX_DIRECT_READ #ifdef LX_DIRECT_READ
/* Read the word directly. */ /* Read the word directly. */
list_word = *(list_word_ptr); list_word = *(list_word_ptr);
#else #else
@@ -276,7 +262,7 @@ UINT status;
/* Check for an error from flash driver. Drivers should never return an error.. */ /* Check for an error from flash driver. Drivers should never return an error.. */
if (status) if (status)
{ {
/* Call system error handler. */ /* Call system error handler. */
_lx_nor_flash_system_error(nor_flash, status); _lx_nor_flash_system_error(nor_flash, status);
@@ -288,33 +274,33 @@ UINT status;
/* Determine if the entry hasn't been used. */ /* Determine if the entry hasn't been used. */
if (list_word == LX_NOR_PHYSICAL_SECTOR_FREE) if (list_word == LX_NOR_PHYSICAL_SECTOR_FREE)
{ {
/* Since allocations are done sequentially in the block, we know nothing /* Since allocations are done sequentially in the block, we know nothing
else exists after this point. */ else exists after this point. */
break; break;
} }
/* Is this entry mapped? */ /* Is this entry mapped? */
if (list_word & LX_NOR_PHYSICAL_SECTOR_VALID) if (list_word & LX_NOR_PHYSICAL_SECTOR_VALID)
{ {
/* Pickup the logical sector associated with this mapped physical sector. */ /* Pickup the logical sector associated with this mapped physical sector. */
logical_sector = list_word & LX_NOR_LOGICAL_SECTOR_MASK; logical_sector = list_word & LX_NOR_LOGICAL_SECTOR_MASK;
/* Invalidate the old sector mapping cache entry. */ /* Invalidate the old sector mapping cache entry. */
_lx_nor_flash_sector_mapping_cache_invalidate(nor_flash, logical_sector); _lx_nor_flash_sector_mapping_cache_invalidate(nor_flash, logical_sector);
/* Allocate a new physical sector for this write. */ /* Allocate a new physical sector for this write. */
_lx_nor_flash_physical_sector_allocate(nor_flash, logical_sector, &new_mapping_address, &new_sector_address); _lx_nor_flash_physical_sector_allocate(nor_flash, logical_sector, &new_mapping_address, &new_sector_address);
/* Check to see if the new sector is also in the erase block. */ /* Check to see if the new sector is also in the erase block. */
if ((new_sector_address >= block_word_ptr) && (new_sector_address < (block_word_ptr + nor_flash -> lx_nor_flash_words_per_block))) if ((new_sector_address >= block_word_ptr) && (new_sector_address < (block_word_ptr + nor_flash -> lx_nor_flash_words_per_block)))
{ {
/* Yes, the new sector was found in the block to be erased. Simply move the search pointer /* Yes, the new sector was found in the block to be erased. Simply move the search pointer
to the block after the erase block and search for another sector from there. */ to the block after the erase block and search for another sector from there. */
nor_flash -> lx_nor_flash_free_block_search = erase_block + 1; nor_flash -> lx_nor_flash_free_block_search = erase_block + 1;
/* Check for wrap condition. */ /* Check for wrap condition. */
if (nor_flash -> lx_nor_flash_free_block_search >= nor_flash -> lx_nor_flash_total_blocks) if (nor_flash -> lx_nor_flash_free_block_search >= nor_flash -> lx_nor_flash_total_blocks)
nor_flash -> lx_nor_flash_free_block_search = 0; nor_flash -> lx_nor_flash_free_block_search = 0;
@@ -328,7 +314,7 @@ UINT status;
if ((new_sector_address >= block_word_ptr) && (new_sector_address < (block_word_ptr + LX_NOR_SECTOR_SIZE))) if ((new_sector_address >= block_word_ptr) && (new_sector_address < (block_word_ptr + LX_NOR_SECTOR_SIZE)))
{ {
/* System error, a new sector is not available outside of the erase block. /* System error, a new sector is not available outside of the erase block.
Clear the new sector so we fall through to the error handling. */ Clear the new sector so we fall through to the error handling. */
new_mapping_address = LX_NULL; new_mapping_address = LX_NULL;
} }
@@ -337,9 +323,9 @@ UINT status;
/* Determine if the new sector allocation was successful. */ /* Determine if the new sector allocation was successful. */
if (new_mapping_address) if (new_mapping_address)
{ {
/* Yes, we were able to allocate a new physical sector. */ /* Yes, we were able to allocate a new physical sector. */
#ifdef LX_DIRECT_READ #ifdef LX_DIRECT_READ
/* First, write the sector data to the new physical sector. */ /* First, write the sector data to the new physical sector. */
status = _lx_nor_flash_driver_write(nor_flash, new_sector_address, (block_word_ptr + nor_flash -> lx_nor_flash_block_physical_sector_offset) + status = _lx_nor_flash_driver_write(nor_flash, new_sector_address, (block_word_ptr + nor_flash -> lx_nor_flash_block_physical_sector_offset) +
@@ -348,7 +334,7 @@ UINT status;
/* Check for an error from flash driver. Drivers should never return an error.. */ /* Check for an error from flash driver. Drivers should never return an error.. */
if (status) if (status)
{ {
/* Call system error handler. */ /* Call system error handler. */
_lx_nor_flash_system_error(nor_flash, status); _lx_nor_flash_system_error(nor_flash, status);
@@ -366,7 +352,7 @@ UINT status;
/* Check for an error from flash driver. Drivers should never return an error.. */ /* Check for an error from flash driver. Drivers should never return an error.. */
if (status) if (status)
{ {
/* Call system error handler. */ /* Call system error handler. */
_lx_nor_flash_system_error(nor_flash, status); _lx_nor_flash_system_error(nor_flash, status);
@@ -380,7 +366,7 @@ UINT status;
/* Check for an error from flash driver. Drivers should never return an error.. */ /* Check for an error from flash driver. Drivers should never return an error.. */
if (status) if (status)
{ {
/* Call system error handler. */ /* Call system error handler. */
_lx_nor_flash_system_error(nor_flash, status); _lx_nor_flash_system_error(nor_flash, status);
@@ -390,34 +376,34 @@ UINT status;
#endif #endif
/* Now deprecate the old sector mapping. */ /* Now deprecate the old sector mapping. */
/* Clear bit 30, which indicates this sector is superceded. */ /* Clear bit 30, which indicates this sector is superceded. */
list_word = list_word & ~((ULONG) LX_NOR_PHYSICAL_SECTOR_SUPERCEDED); list_word = list_word & ~((ULONG) LX_NOR_PHYSICAL_SECTOR_SUPERCEDED);
/* Write the value back to the flash to clear bit 30. */ /* Write the value back to the flash to clear bit 30. */
status = _lx_nor_flash_driver_write(nor_flash, list_word_ptr, &list_word, 1); status = _lx_nor_flash_driver_write(nor_flash, list_word_ptr, &list_word, 1);
/* Check for an error from flash driver. Drivers should never return an error.. */ /* Check for an error from flash driver. Drivers should never return an error.. */
if (status) if (status)
{ {
/* Call system error handler. */ /* Call system error handler. */
_lx_nor_flash_system_error(nor_flash, status); _lx_nor_flash_system_error(nor_flash, status);
/* Return the error. */ /* Return the error. */
return(status); return(status);
} }
/* Now build the new mapping entry - with the not valid bit set initially. */ /* Now build the new mapping entry - with the not valid bit set initially. */
new_mapping_entry = ((ULONG) LX_NOR_PHYSICAL_SECTOR_VALID) | ((ULONG) LX_NOR_PHYSICAL_SECTOR_SUPERCEDED) | (ULONG) LX_NOR_PHYSICAL_SECTOR_MAPPING_NOT_VALID | logical_sector; new_mapping_entry = ((ULONG) LX_NOR_PHYSICAL_SECTOR_VALID) | ((ULONG) LX_NOR_PHYSICAL_SECTOR_SUPERCEDED) | (ULONG) LX_NOR_PHYSICAL_SECTOR_MAPPING_NOT_VALID | logical_sector;
/* Write out the new mapping entry. */ /* Write out the new mapping entry. */
status = _lx_nor_flash_driver_write(nor_flash, new_mapping_address, &new_mapping_entry, 1); status = _lx_nor_flash_driver_write(nor_flash, new_mapping_address, &new_mapping_entry, 1);
/* Check for an error from flash driver. Drivers should never return an error.. */ /* Check for an error from flash driver. Drivers should never return an error.. */
if (status) if (status)
{ {
/* Call system error handler. */ /* Call system error handler. */
_lx_nor_flash_system_error(nor_flash, status); _lx_nor_flash_system_error(nor_flash, status);
@@ -425,17 +411,17 @@ UINT status;
return(status); return(status);
} }
/* Now clear the not valid bit to make this sector mapping valid. This is done because the writing of the extra bytes itself can /* Now clear the not valid bit to make this sector mapping valid. This is done because the writing of the extra bytes itself can
be interrupted and we need to make sure this can be detected when the flash is opened again. */ be interrupted and we need to make sure this can be detected when the flash is opened again. */
new_mapping_entry = new_mapping_entry & ~((ULONG) LX_NOR_PHYSICAL_SECTOR_MAPPING_NOT_VALID); new_mapping_entry = new_mapping_entry & ~((ULONG) LX_NOR_PHYSICAL_SECTOR_MAPPING_NOT_VALID);
/* Clear the not valid bit. */ /* Clear the not valid bit. */
status = _lx_nor_flash_driver_write(nor_flash, new_mapping_address, &new_mapping_entry, 1); status = _lx_nor_flash_driver_write(nor_flash, new_mapping_address, &new_mapping_entry, 1);
/* Check for an error from flash driver. Drivers should never return an error.. */ /* Check for an error from flash driver. Drivers should never return an error.. */
if (status) if (status)
{ {
/* Call system error handler. */ /* Call system error handler. */
_lx_nor_flash_system_error(nor_flash, status); _lx_nor_flash_system_error(nor_flash, status);
@@ -445,14 +431,14 @@ UINT status;
/* Now clear bit 31, which indicates this sector is now obsoleted. */ /* Now clear bit 31, which indicates this sector is now obsoleted. */
list_word = list_word & ~((ULONG) LX_NOR_PHYSICAL_SECTOR_VALID); list_word = list_word & ~((ULONG) LX_NOR_PHYSICAL_SECTOR_VALID);
/* Write the value back to the flash to clear bit 31. */ /* Write the value back to the flash to clear bit 31. */
status = _lx_nor_flash_driver_write(nor_flash, list_word_ptr, &list_word, 1); status = _lx_nor_flash_driver_write(nor_flash, list_word_ptr, &list_word, 1);
/* Check for an error from flash driver. Drivers should never return an error.. */ /* Check for an error from flash driver. Drivers should never return an error.. */
if (status) if (status)
{ {
/* Call system error handler. */ /* Call system error handler. */
_lx_nor_flash_system_error(nor_flash, status); _lx_nor_flash_system_error(nor_flash, status);
@@ -469,10 +455,10 @@ UINT status;
/* Return the error. */ /* Return the error. */
return(status); return(status);
} }
/* Decrement the number of mapped sectors. */ /* Decrement the number of mapped sectors. */
mapped_sectors--; mapped_sectors--;
/* Determine if we are done. */ /* Determine if we are done. */
if (mapped_sectors == 0) if (mapped_sectors == 0)
break; break;
@@ -482,50 +468,50 @@ UINT status;
list_word_ptr++; list_word_ptr++;
} }
/* Write the erased started indication. */ /* Write the erased started indication. */
erase_started_value = LX_BLOCK_ERASE_STARTED; erase_started_value = LX_BLOCK_ERASE_STARTED;
status = _lx_nor_flash_driver_write(nor_flash, block_word_ptr, &erase_started_value, 1); status = _lx_nor_flash_driver_write(nor_flash, block_word_ptr, &erase_started_value, 1);
/* Check for an error from flash driver. Drivers should never return an error.. */ /* Check for an error from flash driver. Drivers should never return an error.. */
if (status) if (status)
{ {
/* Call system error handler. */ /* Call system error handler. */
_lx_nor_flash_system_error(nor_flash, status); _lx_nor_flash_system_error(nor_flash, status);
/* Return the error. */ /* Return the error. */
return(status); return(status);
} }
/* Erase the entire block. */ /* Erase the entire block. */
status = _lx_nor_flash_driver_block_erase(nor_flash, erase_block, erase_count+1); status = _lx_nor_flash_driver_block_erase(nor_flash, erase_block, erase_count+1);
/* Check for an error from flash driver. Drivers should never return an error.. */ /* Check for an error from flash driver. Drivers should never return an error.. */
if (status) if (status)
{ {
/* Call system error handler. */ /* Call system error handler. */
_lx_nor_flash_system_error(nor_flash, status); _lx_nor_flash_system_error(nor_flash, status);
/* Return the error. */ /* Return the error. */
return(status); return(status);
} }
/* Determine if the erase count is at the minimum. */ /* Determine if the erase count is at the minimum. */
if (erase_count == nor_flash -> lx_nor_flash_minimum_erase_count) if (erase_count == nor_flash -> lx_nor_flash_minimum_erase_count)
{ {
/* Yes, decrement the minimum erased block count. */ /* Yes, decrement the minimum erased block count. */
nor_flash -> lx_nor_flash_minimum_erased_blocks--; nor_flash -> lx_nor_flash_minimum_erased_blocks--;
} }
/* Increment the erase count. */ /* Increment the erase count. */
erase_count++; erase_count++;
/* Determine if the new erase count exceeds the maximum. */ /* Determine if the new erase count exceeds the maximum. */
if (erase_count > ((ULONG) LX_BLOCK_ERASE_COUNT_MAX)) if (erase_count > ((ULONG) LX_BLOCK_ERASE_COUNT_MAX))
{ {
/* Yes, erase count is in overflow. Stay at the maximum count. */ /* Yes, erase count is in overflow. Stay at the maximum count. */
erase_count = ((ULONG) LX_BLOCK_ERASE_COUNT_MAX); erase_count = ((ULONG) LX_BLOCK_ERASE_COUNT_MAX);
} }
@@ -533,21 +519,21 @@ UINT status;
/* Determine if we need to update the maximum erase count. */ /* Determine if we need to update the maximum erase count. */
if (erase_count > nor_flash -> lx_nor_flash_maximum_erase_count) if (erase_count > nor_flash -> lx_nor_flash_maximum_erase_count)
{ {
/* Yes, a new maximum is present. */ /* Yes, a new maximum is present. */
nor_flash -> lx_nor_flash_maximum_erase_count = erase_count; nor_flash -> lx_nor_flash_maximum_erase_count = erase_count;
} }
/* Setup the free bit map that corresponds to the free physical sectors in this /* Setup the free bit map that corresponds to the free physical sectors in this
block. Note that we only need to setup the portion of the free bit map that doesn't block. Note that we only need to setup the portion of the free bit map that doesn't
have sectors associated with it. */ have sectors associated with it. */
status = _lx_nor_flash_driver_write(nor_flash, block_word_ptr+(nor_flash -> lx_nor_flash_block_free_bit_map_offset + (nor_flash -> lx_nor_flash_block_bit_map_words - 1)) , status = _lx_nor_flash_driver_write(nor_flash, block_word_ptr+(nor_flash -> lx_nor_flash_block_free_bit_map_offset + (nor_flash -> lx_nor_flash_block_bit_map_words - 1)) ,
&(nor_flash -> lx_nor_flash_block_bit_map_mask), 1); &(nor_flash -> lx_nor_flash_block_bit_map_mask), 1);
/* Check for an error from flash driver. Drivers should never return an error.. */ /* Check for an error from flash driver. Drivers should never return an error.. */
if (status) if (status)
{ {
/* Call system error handler. */ /* Call system error handler. */
_lx_nor_flash_system_error(nor_flash, status); _lx_nor_flash_system_error(nor_flash, status);
@@ -562,7 +548,7 @@ UINT status;
/* Check for an error from flash driver. Drivers should never return an error.. */ /* Check for an error from flash driver. Drivers should never return an error.. */
if (status) if (status)
{ {
/* Call system error handler. */ /* Call system error handler. */
_lx_nor_flash_system_error(nor_flash, status); _lx_nor_flash_system_error(nor_flash, status);
@@ -576,7 +562,7 @@ UINT status;
/* Check for an error from flash driver. Drivers should never return an error.. */ /* Check for an error from flash driver. Drivers should never return an error.. */
if (status) if (status)
{ {
/* Call system error handler. */ /* Call system error handler. */
_lx_nor_flash_system_error(nor_flash, status); _lx_nor_flash_system_error(nor_flash, status);
+32 -41
View File
@@ -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 * This program and the accompanying materials are made available under the
* terms of the MIT License which is available at * terms of the MIT License which is available at
* https://opensource.org/licenses/MIT. * https://opensource.org/licenses/MIT.
* *
* SPDX-License-Identifier: MIT * SPDX-License-Identifier: MIT
**************************************************************************/ **************************************************************************/
/**************************************************************************/ /**************************************************************************/
/**************************************************************************/ /**************************************************************************/
/** */ /** */
/** LevelX Component */ /** LevelX Component */
/** */ /** */
/** NOR Flash */ /** NOR Flash */
/** */ /** */
@@ -34,45 +35,35 @@
#include "lx_api.h" #include "lx_api.h"
/**************************************************************************/ /**************************************************************************/
/* */ /* */
/* FUNCTION RELEASE */ /* FUNCTION RELEASE */
/* */ /* */
/* _lx_nor_flash_close PORTABLE C */ /* _lx_nor_flash_close PORTABLE C */
/* 6.1.7 */ /* 6.1.7 */
/* AUTHOR */ /* AUTHOR */
/* */ /* */
/* William E. Lamie, Microsoft Corporation */ /* William E. Lamie, Microsoft Corporation */
/* */ /* */
/* DESCRIPTION */ /* DESCRIPTION */
/* */
/* This function closes a NOR flash instance. */
/* */
/* INPUT */
/* */
/* nor_flash NOR flash instance */
/* */
/* OUTPUT */
/* */
/* return status */
/* */
/* CALLS */
/* */
/* tx_mutex_delete Delete thread-safe mutex */
/* */
/* CALLED BY */
/* */
/* Application Code */
/* */
/* RELEASE HISTORY */
/* */
/* DATE NAME DESCRIPTION */
/* */ /* */
/* 05-19-2020 William E. Lamie Initial Version 6.0 */ /* This function closes a NOR flash instance. */
/* 09-30-2020 William E. Lamie Modified comment(s), */ /* */
/* resulting in version 6.1 */ /* INPUT */
/* 06-02-2021 Bhupendra Naphade Modified comment(s), */ /* */
/* resulting in version 6.1.7 */ /* nor_flash NOR flash instance */
/* */
/* OUTPUT */
/* */
/* return status */
/* */
/* CALLS */
/* */
/* tx_mutex_delete Delete thread-safe mutex */
/* */
/* CALLED BY */
/* */
/* Application Code */
/* */ /* */
/**************************************************************************/ /**************************************************************************/
UINT _lx_nor_flash_close(LX_NOR_FLASH *nor_flash) UINT _lx_nor_flash_close(LX_NOR_FLASH *nor_flash)
@@ -105,9 +96,9 @@ LX_INTERRUPT_SAVE_AREA
/* See if we have to update the opened list head pointer. */ /* See if we have to update the opened list head pointer. */
if (_lx_nor_flash_opened_ptr == nor_flash) if (_lx_nor_flash_opened_ptr == nor_flash)
{ {
/* Yes, move the head pointer to the next opened NOR flash. */ /* Yes, move the head pointer to the next opened NOR flash. */
_lx_nor_flash_opened_ptr = nor_flash -> lx_nor_flash_open_next; _lx_nor_flash_opened_ptr = nor_flash -> lx_nor_flash_open_next;
} }
} }
@@ -116,7 +107,7 @@ LX_INTERRUPT_SAVE_AREA
/* Finally, indicate that this NOR flash is closed. */ /* Finally, indicate that this NOR flash is closed. */
nor_flash -> lx_nor_flash_state = LX_NOR_FLASH_CLOSED; nor_flash -> lx_nor_flash_state = LX_NOR_FLASH_CLOSED;
/* Restore interrupt posture. */ /* Restore interrupt posture. */
LX_RESTORE LX_RESTORE
+37 -46
View File
@@ -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 * This program and the accompanying materials are made available under the
* terms of the MIT License which is available at * terms of the MIT License which is available at
* https://opensource.org/licenses/MIT. * https://opensource.org/licenses/MIT.
* *
* SPDX-License-Identifier: MIT * SPDX-License-Identifier: MIT
**************************************************************************/ **************************************************************************/
/**************************************************************************/ /**************************************************************************/
/**************************************************************************/ /**************************************************************************/
/** */ /** */
/** LevelX Component */ /** LevelX Component */
/** */ /** */
/** NOR Flash */ /** NOR Flash */
/** */ /** */
@@ -34,53 +35,43 @@
#include "lx_api.h" #include "lx_api.h"
/**************************************************************************/ /**************************************************************************/
/* */ /* */
/* FUNCTION RELEASE */ /* FUNCTION RELEASE */
/* */ /* */
/* _lx_nor_flash_defragment PORTABLE C */ /* _lx_nor_flash_defragment PORTABLE C */
/* 6.1.7 */ /* 6.1.7 */
/* AUTHOR */ /* AUTHOR */
/* */ /* */
/* William E. Lamie, Microsoft Corporation */ /* William E. Lamie, Microsoft Corporation */
/* */ /* */
/* DESCRIPTION */ /* DESCRIPTION */
/* */
/* This function defragments the NOR flash. */
/* */
/* INPUT */
/* */
/* nor_flash NOR flash instance */
/* */
/* OUTPUT */
/* */
/* return status */
/* */
/* CALLS */
/* */
/* _lx_nor_flash_block_reclaim Reclaim a NOR flash block */
/* tx_mutex_get Get thread protection */
/* tx_mutex_put Release thread protection */
/* */
/* CALLED BY */
/* */
/* Application Code */
/* Internal LevelX */
/* */
/* RELEASE HISTORY */
/* */
/* DATE NAME DESCRIPTION */
/* */ /* */
/* 05-19-2020 William E. Lamie Initial Version 6.0 */ /* This function defragments the NOR flash. */
/* 09-30-2020 William E. Lamie Modified comment(s), */ /* */
/* resulting in version 6.1 */ /* INPUT */
/* 06-02-2021 Bhupendra Naphade Modified comment(s), */ /* */
/* resulting in version 6.1.7 */ /* nor_flash NOR flash instance */
/* */
/* OUTPUT */
/* */
/* return status */
/* */
/* CALLS */
/* */
/* _lx_nor_flash_block_reclaim Reclaim a NOR flash block */
/* tx_mutex_get Get thread protection */
/* tx_mutex_put Release thread protection */
/* */
/* CALLED BY */
/* */
/* Application Code */
/* Internal LevelX */
/* */ /* */
/**************************************************************************/ /**************************************************************************/
UINT _lx_nor_flash_defragment(LX_NOR_FLASH *nor_flash) UINT _lx_nor_flash_defragment(LX_NOR_FLASH *nor_flash)
{ {
ULONG i; ULONG i;
@@ -93,11 +84,11 @@ ULONG i;
/* Loop for max number of blocks, while there are obsolete count. */ /* Loop for max number of blocks, while there are obsolete count. */
for (i = 0; i < nor_flash -> lx_nor_flash_total_blocks; i++) for (i = 0; i < nor_flash -> lx_nor_flash_total_blocks; i++)
{ {
/* Determine if there is any more defragment work. */ /* Determine if there is any more defragment work. */
if (nor_flash -> lx_nor_flash_obsolete_physical_sectors == 0) if (nor_flash -> lx_nor_flash_obsolete_physical_sectors == 0)
break; break;
/* Call the block reclaim function to defragment. */ /* Call the block reclaim function to defragment. */
_lx_nor_flash_block_reclaim(nor_flash); _lx_nor_flash_block_reclaim(nor_flash);
} }
@@ -108,7 +99,7 @@ ULONG i;
tx_mutex_put(&nor_flash -> lx_nor_flash_mutex); tx_mutex_put(&nor_flash -> lx_nor_flash_mutex);
#endif #endif
/* Return successful completion. */ /* Return successful completion. */
return(LX_SUCCESS); return(LX_SUCCESS);
} }
+37 -49
View File
@@ -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 * This program and the accompanying materials are made available under the
* terms of the MIT License which is available at * terms of the MIT License which is available at
* https://opensource.org/licenses/MIT. * https://opensource.org/licenses/MIT.
* *
* SPDX-License-Identifier: MIT * SPDX-License-Identifier: MIT
**************************************************************************/ **************************************************************************/
/**************************************************************************/ /**************************************************************************/
/**************************************************************************/ /**************************************************************************/
/** */ /** */
/** LevelX Component */ /** LevelX Component */
/** */ /** */
/** NOR Flash */ /** NOR Flash */
/** */ /** */
@@ -34,50 +35,37 @@
#include "lx_api.h" #include "lx_api.h"
/**************************************************************************/ /**************************************************************************/
/* */ /* */
/* FUNCTION RELEASE */ /* FUNCTION RELEASE */
/* */ /* */
/* _lx_nor_flash_driver_block_erase PORTABLE C */ /* _lx_nor_flash_driver_block_erase PORTABLE C */
/* 6.2.1 */ /* 6.2.1 */
/* AUTHOR */ /* AUTHOR */
/* */ /* */
/* William E. Lamie, Microsoft Corporation */ /* William E. Lamie, Microsoft Corporation */
/* */ /* */
/* DESCRIPTION */ /* DESCRIPTION */
/* */
/* This function performs a NOR flash block erase. */
/* */
/* INPUT */
/* */
/* nor_flash NOR flash instance */
/* block Block number to erase */
/* erase_count Erase count for this block */
/* */
/* OUTPUT */
/* */
/* return status */
/* */
/* CALLS */
/* */
/* (lx_nor_flash_driver_block_erase) Actual driver block erase */
/* */
/* CALLED BY */
/* */
/* Application Code */
/* */
/* RELEASE HISTORY */
/* */
/* DATE NAME DESCRIPTION */
/* */ /* */
/* 05-19-2020 William E. Lamie Initial Version 6.0 */ /* This function performs a NOR flash block erase. */
/* 09-30-2020 William E. Lamie Modified comment(s), */ /* */
/* resulting in version 6.1 */ /* INPUT */
/* 06-02-2021 Bhupendra Naphade Modified comment(s), */ /* */
/* resulting in version 6.1.7 */ /* nor_flash NOR flash instance */
/* 03-08-2023 Xiuwen Cai Modified comment(s), */ /* block Block number to erase */
/* added new driver interface, */ /* erase_count Erase count for this block */
/* resulting in version 6.2.1 */ /* */
/* OUTPUT */
/* */
/* return status */
/* */
/* CALLS */
/* */
/* (lx_nor_flash_driver_block_erase) Actual driver block erase */
/* */
/* CALLED BY */
/* */
/* Application Code */
/* */ /* */
/**************************************************************************/ /**************************************************************************/
UINT _lx_nor_flash_driver_block_erase(LX_NOR_FLASH *nor_flash, ULONG block, ULONG erase_count) UINT _lx_nor_flash_driver_block_erase(LX_NOR_FLASH *nor_flash, ULONG block, ULONG erase_count)
@@ -97,21 +85,21 @@ ULONG *cache_entry_end;
/* Calculate the block starting address. */ /* Calculate the block starting address. */
block_start_address = nor_flash -> lx_nor_flash_base_address + (block * nor_flash -> lx_nor_flash_words_per_block); block_start_address = nor_flash -> lx_nor_flash_base_address + (block * nor_flash -> lx_nor_flash_words_per_block);
block_end_address = block_start_address + nor_flash -> lx_nor_flash_words_per_block; block_end_address = block_start_address + nor_flash -> lx_nor_flash_words_per_block;
/* Loop through the cache entries to see if there is a sector in cache. */ /* Loop through the cache entries to see if there is a sector in cache. */
for (i = 0; i < nor_flash -> lx_nor_flash_extended_cache_entries; i++) for (i = 0; i < nor_flash -> lx_nor_flash_extended_cache_entries; i++)
{ {
/* Search through the cache to see if this cache entry needs to be invalidated. */ /* Search through the cache to see if this cache entry needs to be invalidated. */
/* Determine the cache entry addresses. */ /* Determine the cache entry addresses. */
cache_entry_start = nor_flash -> lx_nor_flash_extended_cache[i].lx_nor_flash_extended_cache_entry_sector_address; cache_entry_start = nor_flash -> lx_nor_flash_extended_cache[i].lx_nor_flash_extended_cache_entry_sector_address;
cache_entry_end = cache_entry_start + LX_NOR_SECTOR_SIZE; cache_entry_end = cache_entry_start + LX_NOR_SECTOR_SIZE;
/* Determine if the flash address in in the cache entry. */ /* Determine if the flash address in in the cache entry. */
if ((cache_entry_start) && (block_start_address <= cache_entry_start) && (block_end_address > cache_entry_end)) if ((cache_entry_start) && (block_start_address <= cache_entry_start) && (block_end_address > cache_entry_end))
{ {
/* Yes, this cache entry is in the block to be erased so invalidate it. */ /* Yes, this cache entry is in the block to be erased so invalidate it. */
nor_flash -> lx_nor_flash_extended_cache[i].lx_nor_flash_extended_cache_entry_sector_address = LX_NULL; nor_flash -> lx_nor_flash_extended_cache[i].lx_nor_flash_extended_cache_entry_sector_address = LX_NULL;
nor_flash -> lx_nor_flash_extended_cache[i].lx_nor_flash_extended_cache_entry_access_count = 0; nor_flash -> lx_nor_flash_extended_cache[i].lx_nor_flash_extended_cache_entry_access_count = 0;
@@ -127,7 +115,7 @@ ULONG *cache_entry_end;
#endif #endif
/* Return completion status. */ /* Return completion status. */
return(status); return(status);
} }
+63 -75
View File
@@ -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 * This program and the accompanying materials are made available under the
* terms of the MIT License which is available at * terms of the MIT License which is available at
* https://opensource.org/licenses/MIT. * https://opensource.org/licenses/MIT.
* *
* SPDX-License-Identifier: MIT * SPDX-License-Identifier: MIT
**************************************************************************/ **************************************************************************/
/**************************************************************************/ /**************************************************************************/
/**************************************************************************/ /**************************************************************************/
/** */ /** */
/** LevelX Component */ /** LevelX Component */
/** */ /** */
/** NOR Flash */ /** NOR Flash */
/** */ /** */
@@ -34,51 +35,38 @@
#include "lx_api.h" #include "lx_api.h"
/**************************************************************************/ /**************************************************************************/
/* */ /* */
/* FUNCTION RELEASE */ /* FUNCTION RELEASE */
/* */ /* */
/* _lx_nor_flash_extended_cache_read PORTABLE C */ /* _lx_nor_flash_extended_cache_read PORTABLE C */
/* 6.2.1 */ /* 6.2.1 */
/* AUTHOR */ /* AUTHOR */
/* */ /* */
/* William E. Lamie, Microsoft Corporation */ /* William E. Lamie, Microsoft Corporation */
/* */ /* */
/* DESCRIPTION */ /* DESCRIPTION */
/* */
/* This function performs a read of the NOR flash memory. */
/* */
/* INPUT */
/* */
/* nor_flash NOR flash instance */
/* flash_address Address of NOR flash to read */
/* destination Destination for the read */
/* words Number of words to read */
/* */
/* OUTPUT */
/* */
/* return status */
/* */
/* CALLS */
/* */
/* (lx_nor_flash_driver_read) Actual driver read */
/* */
/* CALLED BY */
/* */
/* Application Code */
/* */
/* RELEASE HISTORY */
/* */
/* DATE NAME DESCRIPTION */
/* */ /* */
/* 05-19-2020 William E. Lamie Initial Version 6.0 */ /* This function performs a read of the NOR flash memory. */
/* 09-30-2020 William E. Lamie Modified comment(s), */ /* */
/* resulting in version 6.1 */ /* INPUT */
/* 06-02-2021 Bhupendra Naphade Modified comment(s), */ /* */
/* resulting in version 6.1.7 */ /* nor_flash NOR flash instance */
/* 03-08-2023 Xiuwen Cai Modified comment(s), */ /* flash_address Address of NOR flash to read */
/* added new driver interface, */ /* destination Destination for the read */
/* resulting in version 6.2.1 */ /* words Number of words to read */
/* */
/* OUTPUT */
/* */
/* return status */
/* */
/* CALLS */
/* */
/* (lx_nor_flash_driver_read) Actual driver read */
/* */
/* CALLED BY */
/* */
/* Application Code */
/* */ /* */
/**************************************************************************/ /**************************************************************************/
UINT _lx_nor_flash_driver_read(LX_NOR_FLASH *nor_flash, ULONG *flash_address, ULONG *destination, ULONG words) UINT _lx_nor_flash_driver_read(LX_NOR_FLASH *nor_flash, ULONG *flash_address, ULONG *destination, ULONG words)
@@ -98,57 +86,57 @@ UINT least_used_cache_entry;
{ {
/* One word request, which implies that it is a NOR flash metadata read. */ /* One word request, which implies that it is a NOR flash metadata read. */
/* Initialize the least used cache entry. */ /* Initialize the least used cache entry. */
least_used_cache_entry = 0; least_used_cache_entry = 0;
do do
{ {
/* Loop through the cache entries to see if there is a sector in cache. */ /* Loop through the cache entries to see if there is a sector in cache. */
for (i = 0; i < nor_flash -> lx_nor_flash_extended_cache_entries; i++) for (i = 0; i < nor_flash -> lx_nor_flash_extended_cache_entries; i++)
{ {
/* Search through the cache to find the entry. */ /* Search through the cache to find the entry. */
/* Determine the cache entry addresses. */ /* Determine the cache entry addresses. */
cache_entry_start = nor_flash -> lx_nor_flash_extended_cache[i].lx_nor_flash_extended_cache_entry_sector_address; cache_entry_start = nor_flash -> lx_nor_flash_extended_cache[i].lx_nor_flash_extended_cache_entry_sector_address;
cache_entry_end = cache_entry_start + LX_NOR_SECTOR_SIZE; cache_entry_end = cache_entry_start + LX_NOR_SECTOR_SIZE;
/* Determine if the flash address in in the cache entry. */ /* Determine if the flash address in in the cache entry. */
if ((cache_entry_start) && (flash_address >= cache_entry_start) && (flash_address < cache_entry_end)) if ((cache_entry_start) && (flash_address >= cache_entry_start) && (flash_address < cache_entry_end))
{ {
/* Yes, we found the entry. */ /* Yes, we found the entry. */
/* Increment the accessed count. */ /* Increment the accessed count. */
nor_flash -> lx_nor_flash_extended_cache[i].lx_nor_flash_extended_cache_entry_access_count++; nor_flash -> lx_nor_flash_extended_cache[i].lx_nor_flash_extended_cache_entry_access_count++;
/* Calculate the offset into the cache entry. */ /* Calculate the offset into the cache entry. */
cache_offset = (ULONG)(flash_address - cache_entry_start); cache_offset = (ULONG)(flash_address - cache_entry_start);
/* Copy the word from the cache. */ /* Copy the word from the cache. */
*destination = *(nor_flash -> lx_nor_flash_extended_cache[i].lx_nor_flash_extended_cache_entry_sector_memory + cache_offset); *destination = *(nor_flash -> lx_nor_flash_extended_cache[i].lx_nor_flash_extended_cache_entry_sector_memory + cache_offset);
/* Increment the number of cache hits. */ /* Increment the number of cache hits. */
nor_flash -> lx_nor_flash_extended_cache_hits++; nor_flash -> lx_nor_flash_extended_cache_hits++;
/* Return success. */ /* Return success. */
return(LX_SUCCESS); return(LX_SUCCESS);
} }
else else
{ {
/* Determine if we have a new least used sector. */ /* Determine if we have a new least used sector. */
if (i != least_used_cache_entry) if (i != least_used_cache_entry)
{ {
/* Determine if this entry has a smaller accessed count. */ /* Determine if this entry has a smaller accessed count. */
if (nor_flash -> lx_nor_flash_extended_cache[i].lx_nor_flash_extended_cache_entry_access_count < if (nor_flash -> lx_nor_flash_extended_cache[i].lx_nor_flash_extended_cache_entry_access_count <
nor_flash -> lx_nor_flash_extended_cache[least_used_cache_entry].lx_nor_flash_extended_cache_entry_access_count) nor_flash -> lx_nor_flash_extended_cache[least_used_cache_entry].lx_nor_flash_extended_cache_entry_access_count)
{ {
/* New least used entry. */ /* New least used entry. */
least_used_cache_entry = i; least_used_cache_entry = i;
} }
@@ -160,44 +148,44 @@ UINT least_used_cache_entry;
cache_offset = (ULONG)(flash_address - nor_flash -> lx_nor_flash_base_address); cache_offset = (ULONG)(flash_address - nor_flash -> lx_nor_flash_base_address);
cache_offset = cache_offset & ~((ULONG) (LX_NOR_SECTOR_SIZE-1)); cache_offset = cache_offset & ~((ULONG) (LX_NOR_SECTOR_SIZE-1));
cache_entry_start = nor_flash -> lx_nor_flash_base_address + cache_offset; cache_entry_start = nor_flash -> lx_nor_flash_base_address + cache_offset;
/* Call the actual driver read function. */ /* Call the actual driver read function. */
#ifdef LX_NOR_ENABLE_CONTROL_BLOCK_FOR_DRIVER_INTERFACE #ifdef LX_NOR_ENABLE_CONTROL_BLOCK_FOR_DRIVER_INTERFACE
status = (nor_flash -> lx_nor_flash_driver_read)(nor_flash, cache_entry_start, status = (nor_flash -> lx_nor_flash_driver_read)(nor_flash, cache_entry_start,
nor_flash -> lx_nor_flash_extended_cache[least_used_cache_entry].lx_nor_flash_extended_cache_entry_sector_memory, nor_flash -> lx_nor_flash_extended_cache[least_used_cache_entry].lx_nor_flash_extended_cache_entry_sector_memory,
LX_NOR_SECTOR_SIZE); LX_NOR_SECTOR_SIZE);
#else #else
status = (nor_flash -> lx_nor_flash_driver_read)(cache_entry_start, status = (nor_flash -> lx_nor_flash_driver_read)(cache_entry_start,
nor_flash -> lx_nor_flash_extended_cache[least_used_cache_entry].lx_nor_flash_extended_cache_entry_sector_memory, nor_flash -> lx_nor_flash_extended_cache[least_used_cache_entry].lx_nor_flash_extended_cache_entry_sector_memory,
LX_NOR_SECTOR_SIZE); LX_NOR_SECTOR_SIZE);
#endif #endif
/* Determine if there was an error. */ /* Determine if there was an error. */
if (status != LX_SUCCESS) if (status != LX_SUCCESS)
{ {
/* Return the error to the caller. */ /* Return the error to the caller. */
return(status); return(status);
} }
/* Setup the cache entry. */ /* Setup the cache entry. */
nor_flash -> lx_nor_flash_extended_cache[least_used_cache_entry].lx_nor_flash_extended_cache_entry_sector_address = cache_entry_start; nor_flash -> lx_nor_flash_extended_cache[least_used_cache_entry].lx_nor_flash_extended_cache_entry_sector_address = cache_entry_start;
nor_flash -> lx_nor_flash_extended_cache[least_used_cache_entry].lx_nor_flash_extended_cache_entry_access_count = 0; nor_flash -> lx_nor_flash_extended_cache[least_used_cache_entry].lx_nor_flash_extended_cache_entry_access_count = 0;
/* Increment the number of cache misses. */ /* Increment the number of cache misses. */
nor_flash -> lx_nor_flash_extended_cache_misses++; nor_flash -> lx_nor_flash_extended_cache_misses++;
/* Decrement the number of cache hits, so that the increment that will happen next will be cancelled out. */ /* Decrement the number of cache hits, so that the increment that will happen next will be cancelled out. */
nor_flash -> lx_nor_flash_extended_cache_hits--; nor_flash -> lx_nor_flash_extended_cache_hits--;
} while (status == LX_SUCCESS); } while (status == LX_SUCCESS);
/* Return success. */ /* Return success. */
return(LX_SUCCESS); return(LX_SUCCESS);
} }
else else
{ {
/* Call the actual driver read function. */ /* Call the actual driver read function. */
#ifdef LX_NOR_ENABLE_CONTROL_BLOCK_FOR_DRIVER_INTERFACE #ifdef LX_NOR_ENABLE_CONTROL_BLOCK_FOR_DRIVER_INTERFACE
status = (nor_flash -> lx_nor_flash_driver_read)(nor_flash, flash_address, destination, words); status = (nor_flash -> lx_nor_flash_driver_read)(nor_flash, flash_address, destination, words);
@@ -206,7 +194,7 @@ UINT least_used_cache_entry;
#endif #endif
/* Return completion status. */ /* Return completion status. */
return(status); return(status);
} }
#else #else
UINT status; UINT status;
@@ -220,7 +208,7 @@ UINT status;
#endif #endif
/* Return completion status. */ /* Return completion status. */
return(status); return(status);
#endif #endif
} }
+44 -56
View File
@@ -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 * This program and the accompanying materials are made available under the
* terms of the MIT License which is available at * terms of the MIT License which is available at
* https://opensource.org/licenses/MIT. * https://opensource.org/licenses/MIT.
* *
* SPDX-License-Identifier: MIT * SPDX-License-Identifier: MIT
**************************************************************************/ **************************************************************************/
/**************************************************************************/ /**************************************************************************/
/**************************************************************************/ /**************************************************************************/
/** */ /** */
/** LevelX Component */ /** LevelX Component */
/** */ /** */
/** NOR Flash */ /** NOR Flash */
/** */ /** */
@@ -34,51 +35,38 @@
#include "lx_api.h" #include "lx_api.h"
/**************************************************************************/ /**************************************************************************/
/* */ /* */
/* FUNCTION RELEASE */ /* FUNCTION RELEASE */
/* */ /* */
/* _lx_nor_flash_driver_write PORTABLE C */ /* _lx_nor_flash_driver_write PORTABLE C */
/* 6.2.1 */ /* 6.2.1 */
/* AUTHOR */ /* AUTHOR */
/* */ /* */
/* William E. Lamie, Microsoft Corporation */ /* William E. Lamie, Microsoft Corporation */
/* */ /* */
/* DESCRIPTION */ /* DESCRIPTION */
/* */
/* This function performs a write of the NOR flash memory. */
/* */
/* INPUT */
/* */
/* nor_flash NOR flash instance */
/* flash_address Address of NOR flash to write */
/* source Source for the write */
/* words Number of words to write */
/* */
/* OUTPUT */
/* */
/* return status */
/* */
/* CALLS */
/* */
/* (lx_nor_flash_driver_write) Actual driver write */
/* */
/* CALLED BY */
/* */
/* Application Code */
/* */
/* RELEASE HISTORY */
/* */
/* DATE NAME DESCRIPTION */
/* */ /* */
/* 05-19-2020 William E. Lamie Initial Version 6.0 */ /* This function performs a write of the NOR flash memory. */
/* 09-30-2020 William E. Lamie Modified comment(s), */ /* */
/* resulting in version 6.1 */ /* INPUT */
/* 06-02-2021 Bhupendra Naphade Modified comment(s), */ /* */
/* resulting in version 6.1.7 */ /* nor_flash NOR flash instance */
/* 03-08-2023 Xiuwen Cai Modified comment(s), */ /* flash_address Address of NOR flash to write */
/* added new driver interface, */ /* source Source for the write */
/* resulting in version 6.2.1 */ /* words Number of words to write */
/* */
/* OUTPUT */
/* */
/* return status */
/* */
/* CALLS */
/* */
/* (lx_nor_flash_driver_write) Actual driver write */
/* */
/* CALLED BY */
/* */
/* Application Code */
/* */ /* */
/**************************************************************************/ /**************************************************************************/
UINT _lx_nor_flash_driver_write(LX_NOR_FLASH *nor_flash, ULONG *flash_address, ULONG *source, ULONG words) UINT _lx_nor_flash_driver_write(LX_NOR_FLASH *nor_flash, ULONG *flash_address, ULONG *source, ULONG words)
@@ -102,31 +90,31 @@ ULONG cache_offset;
/* Loop through the cache entries to see if there is a sector in cache. */ /* Loop through the cache entries to see if there is a sector in cache. */
for (i = 0; i < nor_flash -> lx_nor_flash_extended_cache_entries; i++) for (i = 0; i < nor_flash -> lx_nor_flash_extended_cache_entries; i++)
{ {
/* Search through the cache to see if there is a cache entry. */ /* Search through the cache to see if there is a cache entry. */
/* Determine the cache entry addresses. */ /* Determine the cache entry addresses. */
cache_entry_start = nor_flash -> lx_nor_flash_extended_cache[i].lx_nor_flash_extended_cache_entry_sector_address; cache_entry_start = nor_flash -> lx_nor_flash_extended_cache[i].lx_nor_flash_extended_cache_entry_sector_address;
cache_entry_end = cache_entry_start + LX_NOR_SECTOR_SIZE; cache_entry_end = cache_entry_start + LX_NOR_SECTOR_SIZE;
/* Determine if the flash address in in the cache entry. */ /* Determine if the flash address in in the cache entry. */
if ((cache_entry_start) && (flash_address >= cache_entry_start) && (flash_address < cache_entry_end)) if ((cache_entry_start) && (flash_address >= cache_entry_start) && (flash_address < cache_entry_end))
{ {
/* Yes, we found the entry. */ /* Yes, we found the entry. */
/* Calculate the offset into the cache entry. */ /* Calculate the offset into the cache entry. */
cache_offset = (ULONG)(flash_address - cache_entry_start); cache_offset = (ULONG)(flash_address - cache_entry_start);
/* Copy the word into the cache. */ /* Copy the word into the cache. */
*(nor_flash -> lx_nor_flash_extended_cache[i].lx_nor_flash_extended_cache_entry_sector_memory + cache_offset) = *source; *(nor_flash -> lx_nor_flash_extended_cache[i].lx_nor_flash_extended_cache_entry_sector_memory + cache_offset) = *source;
/* Get out of the loop. */ /* Get out of the loop. */
break; break;
} }
} }
} }
/* In any case, call the actual driver write function. */ /* In any case, call the actual driver write function. */
#ifdef LX_NOR_ENABLE_CONTROL_BLOCK_FOR_DRIVER_INTERFACE #ifdef LX_NOR_ENABLE_CONTROL_BLOCK_FOR_DRIVER_INTERFACE
status = (nor_flash -> lx_nor_flash_driver_write)(nor_flash, flash_address, source, words); status = (nor_flash -> lx_nor_flash_driver_write)(nor_flash, flash_address, source, words);
@@ -135,8 +123,8 @@ ULONG cache_offset;
#endif #endif
/* Return completion status. */ /* Return completion status. */
return(status); return(status);
#else #else
UINT status; UINT status;
@@ -147,9 +135,9 @@ UINT status;
#else #else
status = (nor_flash -> lx_nor_flash_driver_write)(flash_address, source, words); status = (nor_flash -> lx_nor_flash_driver_write)(flash_address, source, words);
#endif #endif
/* Return completion status. */ /* Return completion status. */
return(status); return(status);
#endif #endif
} }
+52 -73
View File
@@ -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 * This program and the accompanying materials are made available under the
* terms of the MIT License which is available at * terms of the MIT License which is available at
* https://opensource.org/licenses/MIT. * https://opensource.org/licenses/MIT.
* *
* SPDX-License-Identifier: MIT * SPDX-License-Identifier: MIT
**************************************************************************/ **************************************************************************/
/**************************************************************************/ /**************************************************************************/
/**************************************************************************/ /**************************************************************************/
/** */ /** */
/** LevelX Component */ /** LevelX Component */
/** */ /** */
/** NOR Flash */ /** NOR Flash */
/** */ /** */
@@ -34,59 +35,37 @@
#include "lx_api.h" #include "lx_api.h"
/**************************************************************************/ /**************************************************************************/
/* */ /* */
/* FUNCTION RELEASE */ /* FUNCTION RELEASE */
/* */ /* */
/* _lx_nor_flash_extended_cache_enable PORTABLE C */ /* _lx_nor_flash_extended_cache_enable PORTABLE C */
/* 6.3.0 */ /* 6.3.0 */
/* AUTHOR */ /* AUTHOR */
/* */ /* */
/* William E. Lamie, Microsoft Corporation */ /* William E. Lamie, Microsoft Corporation */
/* */ /* */
/* DESCRIPTION */ /* DESCRIPTION */
/* */
/* This function enables or disables the extended cache. */
/* */
/* INPUT */
/* */
/* nor_flash NOR flash instance */
/* memory Address of RAM for cache */
/* size Size of the RAM for cache */
/* */
/* OUTPUT */
/* */
/* return status */
/* */
/* CALLS */
/* */
/* None */
/* */
/* CALLED BY */
/* */
/* Application Code */
/* */
/* RELEASE HISTORY */
/* */
/* DATE NAME DESCRIPTION */
/* */ /* */
/* 05-19-2020 William E. Lamie Initial Version 6.0 */ /* This function enables or disables the extended cache. */
/* 09-30-2020 William E. Lamie Modified comment(s), */ /* */
/* resulting in version 6.1 */ /* INPUT */
/* 12-31-2020 William E. Lamie Modified comment(s), */ /* */
/* fixed compiler warnings, */ /* nor_flash NOR flash instance */
/* resulting in version 6.1.3 */ /* memory Address of RAM for cache */
/* 06-02-2021 Bhupendra Naphade Modified comment(s), and */ /* size Size of the RAM for cache */
/* updated product constants */ /* */
/* resulting in version 6.1.7 */ /* OUTPUT */
/* 10-15-2021 Bhupendra Naphade Modified comment(s), and */ /* */
/* added check for out of */ /* return status */
/* bound memory access, */ /* */
/* resulting in version 6.1.9 */ /* CALLS */
/* 10-31-2023 Xiuwen Cai Modified comment(s), */ /* */
/* added mapping bitmap cache, */ /* None */
/* added obsolete count cache, */ /* */
/* resulting in version 6.3.0 */ /* CALLED BY */
/* */
/* Application Code */
/* */ /* */
/**************************************************************************/ /**************************************************************************/
UINT _lx_nor_flash_extended_cache_enable(LX_NOR_FLASH *nor_flash, VOID *memory, ULONG size) UINT _lx_nor_flash_extended_cache_enable(LX_NOR_FLASH *nor_flash, VOID *memory, ULONG size)
@@ -117,7 +96,7 @@ ULONG block_word;
/* Determine if memory was specified but with an invalid size (less than one NOR sector). */ /* Determine if memory was specified but with an invalid size (less than one NOR sector). */
if ((memory) && (size < LX_NOR_SECTOR_SIZE)) if ((memory) && (size < LX_NOR_SECTOR_SIZE))
{ {
/* Error in memory size supplied. */ /* Error in memory size supplied. */
return(LX_ERROR); return(LX_ERROR);
} }
@@ -146,7 +125,7 @@ ULONG block_word;
/* Get the mapping bitmap cache size. */ /* Get the mapping bitmap cache size. */
mapping_bitmap_words = (nor_flash -> lx_nor_flash_total_physical_sectors + 31) / 32; mapping_bitmap_words = (nor_flash -> lx_nor_flash_total_physical_sectors + 31) / 32;
/* Check if the mapping bitmap cache fits in the suppiled cache memory. */ /* Check if the mapping bitmap cache fits in the suppiled cache memory. */
if (cache_size < mapping_bitmap_words) if (cache_size < mapping_bitmap_words)
{ {
@@ -154,13 +133,13 @@ ULONG block_word;
/* Update the cache size. */ /* Update the cache size. */
mapping_bitmap_words = cache_size; mapping_bitmap_words = cache_size;
} }
/* Setup the mapping bitmap cache. */ /* Setup the mapping bitmap cache. */
nor_flash -> lx_nor_flash_extended_cache_mapping_bitmap = cache_memory; nor_flash -> lx_nor_flash_extended_cache_mapping_bitmap = cache_memory;
/* Setup the mapping bitmap cache size. */ /* Setup the mapping bitmap cache size. */
nor_flash -> lx_nor_flash_extended_cache_mapping_bitmap_max_logical_sector = mapping_bitmap_words * 32; nor_flash -> lx_nor_flash_extended_cache_mapping_bitmap_max_logical_sector = mapping_bitmap_words * 32;
/* Clear the mapping bitmap cache. */ /* Clear the mapping bitmap cache. */
for (i = 0; i < mapping_bitmap_words; i++) for (i = 0; i < mapping_bitmap_words; i++)
{ {
@@ -176,12 +155,12 @@ ULONG block_word;
/* Update the cache memory pointer. */ /* Update the cache memory pointer. */
cache_memory = cache_memory + mapping_bitmap_words; cache_memory = cache_memory + mapping_bitmap_words;
#endif #endif
#if defined(LX_NOR_ENABLE_OBSOLETE_COUNT_CACHE) #if defined(LX_NOR_ENABLE_OBSOLETE_COUNT_CACHE)
/* Get the obsolete count cache size. */ /* Get the obsolete count cache size. */
obsolete_count_words = nor_flash -> lx_nor_flash_total_blocks * sizeof(LX_NOR_OBSOLETE_COUNT_CACHE_TYPE) / 4; obsolete_count_words = nor_flash -> lx_nor_flash_total_blocks * sizeof(LX_NOR_OBSOLETE_COUNT_CACHE_TYPE) / 4;
/* Check if the obsolete count cache fits in the suppiled cache memory. */ /* Check if the obsolete count cache fits in the suppiled cache memory. */
if (cache_size < obsolete_count_words) if (cache_size < obsolete_count_words)
{ {
@@ -189,7 +168,7 @@ ULONG block_word;
/* Update the cache size. */ /* Update the cache size. */
obsolete_count_words = cache_size; obsolete_count_words = cache_size;
} }
/* Setup the obsolete count cache. */ /* Setup the obsolete count cache. */
nor_flash -> lx_nor_flash_extended_cache_obsolete_count = (LX_NOR_OBSOLETE_COUNT_CACHE_TYPE*)cache_memory; nor_flash -> lx_nor_flash_extended_cache_obsolete_count = (LX_NOR_OBSOLETE_COUNT_CACHE_TYPE*)cache_memory;
@@ -218,10 +197,10 @@ ULONG block_word;
/* Now walk the list of logical-physical sector mapping. */ /* Now walk the list of logical-physical sector mapping. */
for (j = 0; j < nor_flash ->lx_nor_flash_physical_sectors_per_block; j++) for (j = 0; j < nor_flash ->lx_nor_flash_physical_sectors_per_block; j++)
{ {
/* Read this word of the sector mapping list. */ /* Read this word of the sector mapping list. */
#ifdef LX_DIRECT_READ #ifdef LX_DIRECT_READ
/* Read the word directly. */ /* Read the word directly. */
block_word = *(block_word_ptr + nor_flash -> lx_nor_flash_block_physical_sector_mapping_offset + j); block_word = *(block_word_ptr + nor_flash -> lx_nor_flash_block_physical_sector_mapping_offset + j);
#else #else
@@ -230,7 +209,7 @@ ULONG block_word;
/* Check for an error from flash driver. Drivers should never return an error.. */ /* Check for an error from flash driver. Drivers should never return an error.. */
if (status) if (status)
{ {
/* Call system error handler. */ /* Call system error handler. */
_lx_nor_flash_system_error(nor_flash, status); _lx_nor_flash_system_error(nor_flash, status);
@@ -243,7 +222,7 @@ ULONG block_word;
{ {
break; break;
} }
/* Is this entry valid? */ /* Is this entry valid? */
if ((block_word & (LX_NOR_PHYSICAL_SECTOR_VALID | LX_NOR_PHYSICAL_SECTOR_MAPPING_NOT_VALID)) == LX_NOR_PHYSICAL_SECTOR_VALID) if ((block_word & (LX_NOR_PHYSICAL_SECTOR_VALID | LX_NOR_PHYSICAL_SECTOR_MAPPING_NOT_VALID)) == LX_NOR_PHYSICAL_SECTOR_VALID)
{ {
@@ -251,10 +230,10 @@ ULONG block_word;
/* Yes, get the logical sector. */ /* Yes, get the logical sector. */
logical_sector = block_word & LX_NOR_LOGICAL_SECTOR_MASK; logical_sector = block_word & LX_NOR_LOGICAL_SECTOR_MASK;
/* Get the mapping bitmap word. */ /* Get the mapping bitmap word. */
mapping_bitmap_word = logical_sector >> 5; mapping_bitmap_word = logical_sector >> 5;
/* Check if the mapping bitmap word is within the cache. */ /* Check if the mapping bitmap word is within the cache. */
if (mapping_bitmap_word < mapping_bitmap_words) if (mapping_bitmap_word < mapping_bitmap_words)
{ {
@@ -263,7 +242,7 @@ ULONG block_word;
mapping_bitmap_ptr[mapping_bitmap_word] |= (ULONG)(1 << (logical_sector & 31)); mapping_bitmap_ptr[mapping_bitmap_word] |= (ULONG)(1 << (logical_sector & 31));
} }
#endif #endif
} }
else else
{ {
@@ -287,27 +266,27 @@ ULONG block_word;
} }
} }
#endif #endif
/* Loop through the memory supplied and assign to cache entries. */ /* Loop through the memory supplied and assign to cache entries. */
i = 0; i = 0;
while ((cache_size >= LX_NOR_SECTOR_SIZE) && (i < LX_NOR_EXTENDED_CACHE_SIZE)) while ((cache_size >= LX_NOR_SECTOR_SIZE) && (i < LX_NOR_EXTENDED_CACHE_SIZE))
{ {
/* Setup this cache entry. */ /* Setup this cache entry. */
nor_flash -> lx_nor_flash_extended_cache[i].lx_nor_flash_extended_cache_entry_sector_address = LX_NULL; nor_flash -> lx_nor_flash_extended_cache[i].lx_nor_flash_extended_cache_entry_sector_address = LX_NULL;
nor_flash -> lx_nor_flash_extended_cache[i].lx_nor_flash_extended_cache_entry_sector_memory = cache_memory; nor_flash -> lx_nor_flash_extended_cache[i].lx_nor_flash_extended_cache_entry_sector_memory = cache_memory;
nor_flash -> lx_nor_flash_extended_cache[i].lx_nor_flash_extended_cache_entry_access_count = 0; nor_flash -> lx_nor_flash_extended_cache[i].lx_nor_flash_extended_cache_entry_access_count = 0;
/* Move the cache memory forward. */ /* Move the cache memory forward. */
cache_memory = cache_memory + LX_NOR_SECTOR_SIZE; cache_memory = cache_memory + LX_NOR_SECTOR_SIZE;
/* Decrement the size. */ /* Decrement the size. */
cache_size = cache_size - LX_NOR_SECTOR_SIZE; cache_size = cache_size - LX_NOR_SECTOR_SIZE;
/* Move to next cache entry. */ /* Move to next cache entry. */
i++; i++;
} }
/* Save the number of cache entries. */ /* Save the number of cache entries. */
if(i == LX_NOR_EXTENDED_CACHE_SIZE) if(i == LX_NOR_EXTENDED_CACHE_SIZE)
{ {
@@ -318,7 +297,7 @@ ULONG block_word;
{ {
nor_flash -> lx_nor_flash_extended_cache_entries = i; nor_flash -> lx_nor_flash_extended_cache_entries = i;
} }
#ifdef LX_THREAD_SAFE_ENABLE #ifdef LX_THREAD_SAFE_ENABLE
+3 -3
View File
@@ -1,11 +1,11 @@
/*************************************************************************** /***************************************************************************
* Copyright (c) 2025 Microsoft Corporation * Copyright (c) 2025 Microsoft Corporation
* Copyright (c) 2025 STmicroelectronics * Copyright (c) 2025 STmicroelectronics
* *
* This program and the accompanying materials are made available under the * This program and the accompanying materials are made available under the
* terms of the MIT License which is available at * terms of the MIT License which is available at
* https://opensource.org/licenses/MIT. * https://opensource.org/licenses/MIT.
* *
* SPDX-License-Identifier: MIT * SPDX-License-Identifier: MIT
**************************************************************************/ **************************************************************************/
+30 -39
View File
@@ -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 * This program and the accompanying materials are made available under the
* terms of the MIT License which is available at * terms of the MIT License which is available at
* https://opensource.org/licenses/MIT. * https://opensource.org/licenses/MIT.
* *
* SPDX-License-Identifier: MIT * SPDX-License-Identifier: MIT
**************************************************************************/ **************************************************************************/
/**************************************************************************/ /**************************************************************************/
/**************************************************************************/ /**************************************************************************/
/** */ /** */
/** LevelX Component */ /** LevelX Component */
/** */ /** */
/** NOR Flash */ /** NOR Flash */
/** */ /** */
@@ -33,45 +34,35 @@ LX_NOR_FLASH *_lx_nor_flash_opened_ptr;
ULONG _lx_nor_flash_opened_count; ULONG _lx_nor_flash_opened_count;
/**************************************************************************/ /**************************************************************************/
/* */ /* */
/* FUNCTION RELEASE */ /* FUNCTION RELEASE */
/* */ /* */
/* _lx_nor_flash_initialize PORTABLE C */ /* _lx_nor_flash_initialize PORTABLE C */
/* 6.1.7 */ /* 6.1.7 */
/* AUTHOR */ /* AUTHOR */
/* */ /* */
/* William E. Lamie, Microsoft Corporation */ /* William E. Lamie, Microsoft Corporation */
/* */ /* */
/* DESCRIPTION */ /* DESCRIPTION */
/* */
/* This function initializes the NOR flash data structures. */
/* */
/* INPUT */
/* */
/* None */
/* */
/* OUTPUT */
/* */
/* return status */
/* */
/* CALLS */
/* */
/* None */
/* */
/* CALLED BY */
/* */
/* Application Code */
/* */
/* RELEASE HISTORY */
/* */
/* DATE NAME DESCRIPTION */
/* */ /* */
/* 05-19-2020 William E. Lamie Initial Version 6.0 */ /* This function initializes the NOR flash data structures. */
/* 09-30-2020 William E. Lamie Modified comment(s), */ /* */
/* resulting in version 6.1 */ /* INPUT */
/* 06-02-2021 Bhupendra Naphade Modified comment(s), */ /* */
/* resulting in version 6.1.7 */ /* None */
/* */
/* OUTPUT */
/* */
/* return status */
/* */
/* CALLS */
/* */
/* None */
/* */
/* CALLED BY */
/* */
/* Application Code */
/* */ /* */
/**************************************************************************/ /**************************************************************************/
UINT _lx_nor_flash_initialize(void) UINT _lx_nor_flash_initialize(void)
@@ -80,7 +71,7 @@ UINT _lx_nor_flash_initialize(void)
/* Clear open list head pointer and opened count. */ /* Clear open list head pointer and opened count. */
_lx_nor_flash_opened_ptr = LX_NULL; _lx_nor_flash_opened_ptr = LX_NULL;
_lx_nor_flash_opened_count = 0; _lx_nor_flash_opened_count = 0;
/* Return success! */ /* Return success! */
return(LX_SUCCESS); return(LX_SUCCESS);
} }
+99 -114
View File
@@ -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 * This program and the accompanying materials are made available under the
* terms of the MIT License which is available at * terms of the MIT License which is available at
* https://opensource.org/licenses/MIT. * https://opensource.org/licenses/MIT.
* *
* SPDX-License-Identifier: MIT * SPDX-License-Identifier: MIT
**************************************************************************/ **************************************************************************/
/**************************************************************************/ /**************************************************************************/
/**************************************************************************/ /**************************************************************************/
/** */ /** */
/** LevelX Component */ /** LevelX Component */
/** */ /** */
/** NOR Flash */ /** NOR Flash */
/** */ /** */
@@ -34,63 +35,47 @@
#include "lx_api.h" #include "lx_api.h"
/**************************************************************************/ /**************************************************************************/
/* */ /* */
/* FUNCTION RELEASE */ /* FUNCTION RELEASE */
/* */ /* */
/* _lx_nor_flash_logical_sector_find PORTABLE C */ /* _lx_nor_flash_logical_sector_find PORTABLE C */
/* 6.3.0 */ /* 6.3.0 */
/* AUTHOR */ /* AUTHOR */
/* */ /* */
/* William E. Lamie, Microsoft Corporation */ /* William E. Lamie, Microsoft Corporation */
/* */ /* */
/* DESCRIPTION */ /* DESCRIPTION */
/* */
/* This function attempts to find the specified logical sector in */
/* the NOR flash. */
/* */
/* INPUT */
/* */
/* nor_flash NOR flash instance */
/* logical_sector Logical sector number */
/* superceded_check Check for sector being */
/* superceded (can happen if */
/* on interruptions of sector */
/* write) */
/* physical_sector_map_entry Destination for physical */
/* sector map entry address */
/* physical_sector_address Destination for physical */
/* sector data */
/* */
/* OUTPUT */
/* */
/* return status */
/* */
/* CALLS */
/* */
/* _lx_nor_flash_driver_read Driver flash sector read */
/* _lx_nor_flash_driver_write Driver flash sector write */
/* _lx_nor_flash_system_error Internal system error handler */
/* */
/* CALLED BY */
/* */
/* Internal LevelX */
/* */
/* RELEASE HISTORY */
/* */
/* DATE NAME DESCRIPTION */
/* */ /* */
/* 05-19-2020 William E. Lamie Initial Version 6.0 */ /* This function attempts to find the specified logical sector in */
/* 09-30-2020 William E. Lamie Modified comment(s), */ /* the NOR flash. */
/* resulting in version 6.1 */ /* */
/* 06-02-2021 Bhupendra Naphade Modified comment(s), */ /* INPUT */
/* resulting in version 6.1.7 */ /* */
/* 10-31-2023 Xiuwen Cai Modified comment(s), */ /* nor_flash NOR flash instance */
/* added mapping bitmap cache, */ /* logical_sector Logical sector number */
/* added obsolete count cache, */ /* superceded_check Check for sector being */
/* optimized full obsoleted */ /* superceded (can happen if */
/* block searching logic, */ /* on interruptions of sector */
/* resulting in version 6.3.0 */ /* write) */
/* physical_sector_map_entry Destination for physical */
/* sector map entry address */
/* physical_sector_address Destination for physical */
/* sector data */
/* */
/* OUTPUT */
/* */
/* return status */
/* */
/* CALLS */
/* */
/* _lx_nor_flash_driver_read Driver flash sector read */
/* _lx_nor_flash_driver_write Driver flash sector write */
/* _lx_nor_flash_system_error Internal system error handler */
/* */
/* CALLED BY */
/* */
/* Internal LevelX */
/* */ /* */
/**************************************************************************/ /**************************************************************************/
UINT _lx_nor_flash_logical_sector_find(LX_NOR_FLASH *nor_flash, ULONG logical_sector, ULONG superceded_check, ULONG **physical_sector_map_entry, ULONG **physical_sector_address) UINT _lx_nor_flash_logical_sector_find(LX_NOR_FLASH *nor_flash, ULONG logical_sector, ULONG superceded_check, ULONG **physical_sector_map_entry, ULONG **physical_sector_address)
@@ -119,7 +104,7 @@ UINT status;
/* Initialize the return parameters. */ /* Initialize the return parameters. */
*physical_sector_map_entry = (ULONG *) 0; *physical_sector_map_entry = (ULONG *) 0;
*physical_sector_address = (ULONG *) 0; *physical_sector_address = (ULONG *) 0;
/* Determine if there are any mapped physical sectors. */ /* Determine if there are any mapped physical sectors. */
if (nor_flash -> lx_nor_flash_mapped_physical_sectors == 0) if (nor_flash -> lx_nor_flash_mapped_physical_sectors == 0)
{ {
@@ -127,7 +112,7 @@ UINT status;
/* No mapped sector so nothing can be found!. */ /* No mapped sector so nothing can be found!. */
return(LX_SECTOR_NOT_FOUND); return(LX_SECTOR_NOT_FOUND);
} }
#ifndef LX_NOR_DISABLE_EXTENDED_CACHE #ifndef LX_NOR_DISABLE_EXTENDED_CACHE
#ifdef LX_NOR_ENABLE_MAPPING_BITMAP #ifdef LX_NOR_ENABLE_MAPPING_BITMAP
@@ -138,7 +123,7 @@ UINT status;
/* Determine if the logical sector is mapped. */ /* Determine if the logical sector is mapped. */
if ((nor_flash -> lx_nor_flash_extended_cache_mapping_bitmap[logical_sector >> 5] & (ULONG)(1 << (logical_sector & 31))) == 0) if ((nor_flash -> lx_nor_flash_extended_cache_mapping_bitmap[logical_sector >> 5] & (ULONG)(1 << (logical_sector & 31))) == 0)
{ {
/* Not mapped, return not found. */ /* Not mapped, return not found. */
return(LX_SECTOR_NOT_FOUND); return(LX_SECTOR_NOT_FOUND);
} }
@@ -149,14 +134,14 @@ UINT status;
/* Determine if the sector mapping cache is enabled. */ /* Determine if the sector mapping cache is enabled. */
if (nor_flash -> lx_nor_flash_sector_mapping_cache_enabled) if (nor_flash -> lx_nor_flash_sector_mapping_cache_enabled)
{ {
/* Calculate the starting index of the sector cache for this sector entry. */ /* Calculate the starting index of the sector cache for this sector entry. */
i = (logical_sector & LX_NOR_SECTOR_MAPPING_CACHE_HASH_MASK) * LX_NOR_SECTOR_MAPPING_CACHE_DEPTH; i = (logical_sector & LX_NOR_SECTOR_MAPPING_CACHE_HASH_MASK) * LX_NOR_SECTOR_MAPPING_CACHE_DEPTH;
/* Build a pointer to the cache entry. */ /* Build a pointer to the cache entry. */
sector_mapping_cache_entry_ptr = &nor_flash -> lx_nor_flash_sector_mapping_cache[i]; sector_mapping_cache_entry_ptr = &nor_flash -> lx_nor_flash_sector_mapping_cache[i];
/* Determine if the sector is in the sector mapping cache - assuming the depth of the sector /* Determine if the sector is in the sector mapping cache - assuming the depth of the sector
mapping cache is LX_NOR_SECTOR_MAPPING_CACHE_DEPTH entries. */ mapping cache is LX_NOR_SECTOR_MAPPING_CACHE_DEPTH entries. */
if ((sector_mapping_cache_entry_ptr -> lx_nor_sector_mapping_cache_logical_sector) == (logical_sector | LX_NOR_SECTOR_MAPPING_CACHE_ENTRY_VALID)) if ((sector_mapping_cache_entry_ptr -> lx_nor_sector_mapping_cache_logical_sector) == (logical_sector | LX_NOR_SECTOR_MAPPING_CACHE_ENTRY_VALID))
{ {
@@ -230,7 +215,7 @@ UINT status;
/* Return a successful status. */ /* Return a successful status. */
return(LX_SUCCESS); return(LX_SUCCESS);
} }
/* If we get here, we have a cache miss so increment the counter before we fall through the loop. */ /* If we get here, we have a cache miss so increment the counter before we fall through the loop. */
nor_flash -> lx_nor_flash_sector_mapping_cache_misses++; nor_flash -> lx_nor_flash_sector_mapping_cache_misses++;
} }
@@ -248,9 +233,9 @@ UINT status;
total_blocks = nor_flash -> lx_nor_flash_total_blocks; total_blocks = nor_flash -> lx_nor_flash_total_blocks;
/* Loop through the blocks to attempt to find the mapped logical sector. */ /* Loop through the blocks to attempt to find the mapped logical sector. */
while (total_blocks--) while (total_blocks--)
{ {
#ifdef LX_NOR_ENABLE_OBSOLETE_COUNT_CACHE #ifdef LX_NOR_ENABLE_OBSOLETE_COUNT_CACHE
/* Determine if the obsolete sector count is available in the cache. */ /* Determine if the obsolete sector count is available in the cache. */
if (i < nor_flash -> lx_nor_flash_extended_cache_obsolete_count_max_block) if (i < nor_flash -> lx_nor_flash_extended_cache_obsolete_count_max_block)
@@ -262,20 +247,20 @@ UINT status;
/* Move to the next block. */ /* Move to the next block. */
i++; i++;
/* Determine if we have wrapped. */ /* Determine if we have wrapped. */
if (i >= nor_flash -> lx_nor_flash_total_blocks) if (i >= nor_flash -> lx_nor_flash_total_blocks)
{ {
/* Yes, we have wrapped, set to block 0. */ /* Yes, we have wrapped, set to block 0. */
i = 0; i = 0;
} }
/* Start at the first sector in the next block. */ /* Start at the first sector in the next block. */
j = 0; j = 0;
/* No point in looking further into this block, just continue the loop. */ /* No point in looking further into this block, just continue the loop. */
continue; continue;
} }
} }
@@ -284,12 +269,12 @@ UINT status;
/* Setup the block word pointer to the first word of the search block. */ /* Setup the block word pointer to the first word of the search block. */
block_word_ptr = (nor_flash -> lx_nor_flash_base_address + (i * nor_flash -> lx_nor_flash_words_per_block)); block_word_ptr = (nor_flash -> lx_nor_flash_base_address + (i * nor_flash -> lx_nor_flash_words_per_block));
/* Determine if the minimum and maximum logical sector values are present in the block header. If these are /* Determine if the minimum and maximum logical sector values are present in the block header. If these are
present, we can quickly skip blocks that don't have our sector. */ present, we can quickly skip blocks that don't have our sector. */
/* Read the minimum and maximum logical sector values in this block. */ /* Read the minimum and maximum logical sector values in this block. */
#ifdef LX_DIRECT_READ #ifdef LX_DIRECT_READ
/* Read the word directly. */ /* Read the word directly. */
min_logical_sector = *(block_word_ptr + LX_NOR_FLASH_MIN_LOGICAL_SECTOR_OFFSET); min_logical_sector = *(block_word_ptr + LX_NOR_FLASH_MIN_LOGICAL_SECTOR_OFFSET);
#else #else
@@ -298,7 +283,7 @@ UINT status;
/* Check for an error from flash driver. Drivers should never return an error.. */ /* Check for an error from flash driver. Drivers should never return an error.. */
if (status) if (status)
{ {
/* Call system error handler. */ /* Call system error handler. */
_lx_nor_flash_system_error(nor_flash, status); _lx_nor_flash_system_error(nor_flash, status);
@@ -306,12 +291,12 @@ UINT status;
return(status); return(status);
} }
#endif #endif
/* Is the value valid? */ /* Is the value valid? */
if (min_logical_sector != LX_ALL_ONES) if (min_logical_sector != LX_ALL_ONES)
{ {
#ifdef LX_DIRECT_READ #ifdef LX_DIRECT_READ
/* Read the word directly. */ /* Read the word directly. */
max_logical_sector = *(block_word_ptr + LX_NOR_FLASH_MAX_LOGICAL_SECTOR_OFFSET); max_logical_sector = *(block_word_ptr + LX_NOR_FLASH_MAX_LOGICAL_SECTOR_OFFSET);
#else #else
@@ -320,7 +305,7 @@ UINT status;
/* Check for an error from flash driver. Drivers should never return an error.. */ /* Check for an error from flash driver. Drivers should never return an error.. */
if (status) if (status)
{ {
/* Call system error handler. */ /* Call system error handler. */
_lx_nor_flash_system_error(nor_flash, status); _lx_nor_flash_system_error(nor_flash, status);
@@ -339,20 +324,20 @@ UINT status;
/* Move to the next block. */ /* Move to the next block. */
i++; i++;
/* Determine if we have wrapped. */ /* Determine if we have wrapped. */
if (i >= nor_flash -> lx_nor_flash_total_blocks) if (i >= nor_flash -> lx_nor_flash_total_blocks)
{ {
/* Yes, we have wrapped, set to block 0. */ /* Yes, we have wrapped, set to block 0. */
i = 0; i = 0;
} }
/* Start at the first sector in the next block. */ /* Start at the first sector in the next block. */
j = 0; j = 0;
/* No point in looking further into this block, just continue the loop. */ /* No point in looking further into this block, just continue the loop. */
continue; continue;
} }
} }
} }
@@ -363,17 +348,17 @@ UINT status;
max_logical_sector = LX_ALL_ONES; max_logical_sector = LX_ALL_ONES;
} }
#ifndef LX_NOR_ENABLE_OBSOLETE_COUNT_CACHE #ifndef LX_NOR_ENABLE_OBSOLETE_COUNT_CACHE
/* Clear the valid sector found flag. */ /* Clear the valid sector found flag. */
valid_sector_found = LX_FALSE; valid_sector_found = LX_FALSE;
#endif #endif
/* Setup the total number of sectors. */ /* Setup the total number of sectors. */
total_sectors = nor_flash -> lx_nor_flash_physical_sectors_per_block; total_sectors = nor_flash -> lx_nor_flash_physical_sectors_per_block;
/* Remember the start of the search. */ /* Remember the start of the search. */
search_start = j; search_start = j;
/* Now search through the sector list to find a match. */ /* Now search through the sector list to find a match. */
while (total_sectors--) while (total_sectors--)
{ {
@@ -381,10 +366,10 @@ UINT status;
/* Setup a pointer to the mapped list. */ /* Setup a pointer to the mapped list. */
list_word_ptr = block_word_ptr + nor_flash -> lx_nor_flash_block_physical_sector_mapping_offset + j; list_word_ptr = block_word_ptr + nor_flash -> lx_nor_flash_block_physical_sector_mapping_offset + j;
/* Read in the mapped list for this block. */ /* Read in the mapped list for this block. */
#ifdef LX_DIRECT_READ #ifdef LX_DIRECT_READ
/* Read the word directly. */ /* Read the word directly. */
list_word = *(list_word_ptr); list_word = *(list_word_ptr);
#else #else
@@ -393,7 +378,7 @@ UINT status;
/* Check for an error from flash driver. Drivers should never return an error.. */ /* Check for an error from flash driver. Drivers should never return an error.. */
if (status) if (status)
{ {
/* Call system error handler. */ /* Call system error handler. */
_lx_nor_flash_system_error(nor_flash, status); _lx_nor_flash_system_error(nor_flash, status);
@@ -401,42 +386,42 @@ UINT status;
return(status); return(status);
} }
#endif #endif
/* Determine if the entry hasn't been used. */ /* Determine if the entry hasn't been used. */
if (list_word == LX_NOR_PHYSICAL_SECTOR_FREE) if (list_word == LX_NOR_PHYSICAL_SECTOR_FREE)
{ {
/* Since the mapping is done sequentially in the block, we know nothing /* Since the mapping is done sequentially in the block, we know nothing
else exists after this point. */ else exists after this point. */
/* Determine if the search started at the beginning of the block. */ /* Determine if the search started at the beginning of the block. */
if (search_start == 0) if (search_start == 0)
{ {
/* Yes, we started at the beginning of the block. We are now done with this block. */ /* Yes, we started at the beginning of the block. We are now done with this block. */
break; break;
} }
else else
{ {
/* Setup the new total to the search start. */ /* Setup the new total to the search start. */
total_sectors = search_start; total_sectors = search_start;
/* Clear search start. */ /* Clear search start. */
search_start = 0; search_start = 0;
/* Start search over. */ /* Start search over. */
j = 0; j = 0;
continue; continue;
} }
} }
/* Is this entry valid? */ /* Is this entry valid? */
if ((list_word & (LX_NOR_PHYSICAL_SECTOR_VALID | LX_NOR_PHYSICAL_SECTOR_MAPPING_NOT_VALID)) == LX_NOR_PHYSICAL_SECTOR_VALID) if ((list_word & (LX_NOR_PHYSICAL_SECTOR_VALID | LX_NOR_PHYSICAL_SECTOR_MAPPING_NOT_VALID)) == LX_NOR_PHYSICAL_SECTOR_VALID)
{ {
/* Decrement the number of mapped sectors. */ /* Decrement the number of mapped sectors. */
mapped_sectors--; mapped_sectors--;
/* Do we have a valid sector match? */ /* Do we have a valid sector match? */
if ((list_word & LX_NOR_LOGICAL_SECTOR_MASK) == logical_sector) if ((list_word & LX_NOR_LOGICAL_SECTOR_MASK) == logical_sector)
@@ -445,7 +430,7 @@ UINT status;
/* Determine if we care about the superceded bit. */ /* Determine if we care about the superceded bit. */
if (superceded_check == LX_FALSE) if (superceded_check == LX_FALSE)
{ {
/* Prepare the return information. */ /* Prepare the return information. */
*physical_sector_map_entry = list_word_ptr; *physical_sector_map_entry = list_word_ptr;
*physical_sector_address = block_word_ptr + nor_flash -> lx_nor_flash_block_physical_sector_offset + (j * LX_NOR_SECTOR_SIZE); *physical_sector_address = block_word_ptr + nor_flash -> lx_nor_flash_block_physical_sector_offset + (j * LX_NOR_SECTOR_SIZE);
@@ -455,7 +440,7 @@ UINT status;
{ {
/* Yes, update the cache with the sector mapping. */ /* Yes, update the cache with the sector mapping. */
/* Move all the cache entries down so the oldest is at the bottom. */ /* Move all the cache entries down so the oldest is at the bottom. */
*(sector_mapping_cache_entry_ptr + 3) = *(sector_mapping_cache_entry_ptr + 2); *(sector_mapping_cache_entry_ptr + 3) = *(sector_mapping_cache_entry_ptr + 2);
*(sector_mapping_cache_entry_ptr + 2) = *(sector_mapping_cache_entry_ptr + 1); *(sector_mapping_cache_entry_ptr + 2) = *(sector_mapping_cache_entry_ptr + 1);
@@ -469,26 +454,26 @@ UINT status;
/* Remember the last found block for next search. */ /* Remember the last found block for next search. */
nor_flash -> lx_nor_flash_found_block_search = i; nor_flash -> lx_nor_flash_found_block_search = i;
/* Remember the last found sector. */ /* Remember the last found sector. */
nor_flash -> lx_nor_flash_found_sector_search = j+1; nor_flash -> lx_nor_flash_found_sector_search = j+1;
/* Has this wrapped around? */ /* Has this wrapped around? */
if (nor_flash -> lx_nor_flash_found_sector_search >= nor_flash -> lx_nor_flash_physical_sectors_per_block) if (nor_flash -> lx_nor_flash_found_sector_search >= nor_flash -> lx_nor_flash_physical_sectors_per_block)
{ {
/* Reset to the beginning sector. */ /* Reset to the beginning sector. */
nor_flash -> lx_nor_flash_found_sector_search = 0; nor_flash -> lx_nor_flash_found_sector_search = 0;
} }
/* Return success! */ /* Return success! */
return(LX_SUCCESS); return(LX_SUCCESS);
} }
/* Check for the superceded bit being clear, which means the sector was superceded. */ /* Check for the superceded bit being clear, which means the sector was superceded. */
else if (list_word & LX_NOR_PHYSICAL_SECTOR_SUPERCEDED) else if (list_word & LX_NOR_PHYSICAL_SECTOR_SUPERCEDED)
{ {
/* Prepare the return information. */ /* Prepare the return information. */
*physical_sector_map_entry = list_word_ptr; *physical_sector_map_entry = list_word_ptr;
*physical_sector_address = block_word_ptr + nor_flash -> lx_nor_flash_block_physical_sector_offset + (j * LX_NOR_SECTOR_SIZE); *physical_sector_address = block_word_ptr + nor_flash -> lx_nor_flash_block_physical_sector_offset + (j * LX_NOR_SECTOR_SIZE);
@@ -500,17 +485,17 @@ UINT status;
/* Remember the last found sector. */ /* Remember the last found sector. */
nor_flash -> lx_nor_flash_found_sector_search = j+1; nor_flash -> lx_nor_flash_found_sector_search = j+1;
/* Has this wrapped around? */ /* Has this wrapped around? */
if (nor_flash -> lx_nor_flash_found_sector_search >= nor_flash -> lx_nor_flash_physical_sectors_per_block) if (nor_flash -> lx_nor_flash_found_sector_search >= nor_flash -> lx_nor_flash_physical_sectors_per_block)
{ {
/* Reset to the beginning sector. */ /* Reset to the beginning sector. */
nor_flash -> lx_nor_flash_found_sector_search = 0; nor_flash -> lx_nor_flash_found_sector_search = 0;
} }
/* Return success! */ /* Return success! */
return(LX_SUCCESS); return(LX_SUCCESS);
} }
} }
#ifndef LX_NOR_ENABLE_OBSOLETE_COUNT_CACHE #ifndef LX_NOR_ENABLE_OBSOLETE_COUNT_CACHE
@@ -522,11 +507,11 @@ UINT status;
/* Move to the next list entry. */ /* Move to the next list entry. */
j++; j++;
/* Check for wrap around. */ /* Check for wrap around. */
if (j >= nor_flash -> lx_nor_flash_physical_sectors_per_block) if (j >= nor_flash -> lx_nor_flash_physical_sectors_per_block)
{ {
/* Yes, wrap around, go back to the beginning. */ /* Yes, wrap around, go back to the beginning. */
j = 0; j = 0;
} }
@@ -541,14 +526,14 @@ UINT status;
/* Write the max logical sector to the block header. */ /* Write the max logical sector to the block header. */
status = _lx_nor_flash_driver_write(nor_flash, block_word_ptr + LX_NOR_FLASH_MAX_LOGICAL_SECTOR_OFFSET, &max_logical_sector, 1); status = _lx_nor_flash_driver_write(nor_flash, block_word_ptr + LX_NOR_FLASH_MAX_LOGICAL_SECTOR_OFFSET, &max_logical_sector, 1);
/* Check for an error from flash driver. Drivers should never return an error.. */ /* Check for an error from flash driver. Drivers should never return an error.. */
if (status) if (status)
{ {
/* Call system error handler. */ /* Call system error handler. */
_lx_nor_flash_system_error(nor_flash, status); _lx_nor_flash_system_error(nor_flash, status);
/* Return the error. */ /* Return the error. */
return(status); return(status);
} }
@@ -558,14 +543,14 @@ UINT status;
/* Determine if there are any more mapped sectors. */ /* Determine if there are any more mapped sectors. */
if (mapped_sectors == 0) if (mapped_sectors == 0)
break; break;
/* Move to the next block. */ /* Move to the next block. */
i++; i++;
/* Determine if we have wrapped. */ /* Determine if we have wrapped. */
if (i >= nor_flash -> lx_nor_flash_total_blocks) if (i >= nor_flash -> lx_nor_flash_total_blocks)
{ {
/* Yes, we have wrapped, set to block 0. */ /* Yes, we have wrapped, set to block 0. */
i = 0; i = 0;
} }
@@ -575,6 +560,6 @@ UINT status;
} }
/* Return sector not found status. */ /* Return sector not found status. */
return(LX_SECTOR_NOT_FOUND); return(LX_SECTOR_NOT_FOUND);
} }
@@ -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 * This program and the accompanying materials are made available under the
* terms of the MIT License which is available at * terms of the MIT License which is available at
* https://opensource.org/licenses/MIT. * https://opensource.org/licenses/MIT.
* *
* SPDX-License-Identifier: MIT * SPDX-License-Identifier: MIT
**************************************************************************/ **************************************************************************/
/**************************************************************************/ /**************************************************************************/
/**************************************************************************/ /**************************************************************************/
/** */ /** */
/** LevelX Component */ /** LevelX Component */
/** */ /** */
/** NOR Flash */ /** NOR Flash */
/** */ /** */
@@ -34,58 +35,42 @@
#include "lx_api.h" #include "lx_api.h"
/**************************************************************************/ /**************************************************************************/
/* */ /* */
/* FUNCTION RELEASE */ /* FUNCTION RELEASE */
/* */ /* */
/* _lx_nor_flash_next_block_to_erase_find PORTABLE C */ /* _lx_nor_flash_next_block_to_erase_find PORTABLE C */
/* 6.3.0 */ /* 6.3.0 */
/* AUTHOR */ /* AUTHOR */
/* */ /* */
/* William E. Lamie, Microsoft Corporation */ /* William E. Lamie, Microsoft Corporation */
/* */ /* */
/* DESCRIPTION */ /* DESCRIPTION */
/* */
/* This function finds the next block to erase in the NOR flash. */
/* */
/* INPUT */
/* */
/* nor_flash NOR flash instance */
/* return_erase_block Returned block to erase */
/* return_erase_count Returned erase count of block */
/* return_mapped_sectors Returned number of mapped */
/* sectors */
/* return_obsolete_sectors Returned number of obsolete */
/* sectors */
/* */
/* OUTPUT */
/* */
/* return status */
/* */
/* CALLS */
/* */
/* _lx_nor_flash_driver_read Driver flash sector read */
/* _lx_nor_flash_system_error Internal system error handler */
/* */
/* CALLED BY */
/* */
/* Internal LevelX */
/* */
/* RELEASE HISTORY */
/* */
/* DATE NAME DESCRIPTION */
/* */ /* */
/* 05-19-2020 William E. Lamie Initial Version 6.0 */ /* This function finds the next block to erase in the NOR flash. */
/* 09-30-2020 William E. Lamie Modified comment(s), */ /* */
/* resulting in version 6.1 */ /* INPUT */
/* 06-02-2021 Bhupendra Naphade Modified comment(s), */ /* */
/* resulting in version 6.1.7 */ /* nor_flash NOR flash instance */
/* 10-31-2023 Xiuwen Cai Modified comment(s), */ /* return_erase_block Returned block to erase */
/* added mapping bitmap cache, */ /* return_erase_count Returned erase count of block */
/* added obsolete count cache, */ /* return_mapped_sectors Returned number of mapped */
/* optimized full obsoleted */ /* sectors */
/* block searching logic, */ /* return_obsolete_sectors Returned number of obsolete */
/* resulting in version 6.3.0 */ /* sectors */
/* */
/* OUTPUT */
/* */
/* return status */
/* */
/* CALLS */
/* */
/* _lx_nor_flash_driver_read Driver flash sector read */
/* _lx_nor_flash_system_error Internal system error handler */
/* */
/* CALLED BY */
/* */
/* Internal LevelX */
/* */ /* */
/**************************************************************************/ /**************************************************************************/
UINT _lx_nor_flash_next_block_to_erase_find(LX_NOR_FLASH *nor_flash, ULONG *return_erase_block, ULONG *return_erase_count, ULONG *return_mapped_sectors, ULONG *return_obsolete_sectors) UINT _lx_nor_flash_next_block_to_erase_find(LX_NOR_FLASH *nor_flash, ULONG *return_erase_block, ULONG *return_erase_count, ULONG *return_mapped_sectors, ULONG *return_obsolete_sectors)
@@ -126,36 +111,36 @@ UINT mapped_sectors_available;
/* Initialize the minimum erase count. */ /* Initialize the minimum erase count. */
min_block_erase_count = LX_ALL_ONES; min_block_erase_count = LX_ALL_ONES;
/* Initialize the system minimum and maximum erase counts. */ /* Initialize the system minimum and maximum erase counts. */
min_system_block_erase_count = LX_ALL_ONES; min_system_block_erase_count = LX_ALL_ONES;
system_min_erased_blocks = 0; system_min_erased_blocks = 0;
max_system_block_erase_count = 0; max_system_block_erase_count = 0;
/* Initialize the maximum obsolete sector count. */ /* Initialize the maximum obsolete sector count. */
max_obsolete_sectors = 0; max_obsolete_sectors = 0;
/* Calculate the erase count threshold. */ /* Calculate the erase count threshold. */
if (nor_flash -> lx_nor_flash_free_physical_sectors >= nor_flash -> lx_nor_flash_physical_sectors_per_block) if (nor_flash -> lx_nor_flash_free_physical_sectors >= nor_flash -> lx_nor_flash_physical_sectors_per_block)
{ {
/* Calculate erase count threshold by adding constant to the current minimum. */ /* Calculate erase count threshold by adding constant to the current minimum. */
erase_count_threshold = nor_flash -> lx_nor_flash_minimum_erase_count + LX_NOR_FLASH_MAX_ERASE_COUNT_DELTA; erase_count_threshold = nor_flash -> lx_nor_flash_minimum_erase_count + LX_NOR_FLASH_MAX_ERASE_COUNT_DELTA;
} }
else else
{ {
/* When the number of free sectors is low, simply pick the block that has the most number of obsolete sectors. */ /* When the number of free sectors is low, simply pick the block that has the most number of obsolete sectors. */
erase_count_threshold = LX_ALL_ONES; erase_count_threshold = LX_ALL_ONES;
} }
/* Loop through the blocks to attempt to find the mapped logical sector. */ /* Loop through the blocks to attempt to find the mapped logical sector. */
for (i = 0; i < nor_flash -> lx_nor_flash_total_blocks; i++) for (i = 0; i < nor_flash -> lx_nor_flash_total_blocks; i++)
{ {
/* Read the erase count of this block. */ /* Read the erase count of this block. */
#ifdef LX_DIRECT_READ #ifdef LX_DIRECT_READ
/* Read the word directly. */ /* Read the word directly. */
erase_count = *(block_word_ptr); erase_count = *(block_word_ptr);
#else #else
@@ -164,7 +149,7 @@ UINT mapped_sectors_available;
/* Check for an error from flash driver. Drivers should never return an error.. */ /* Check for an error from flash driver. Drivers should never return an error.. */
if (status) if (status)
{ {
/* Call system error handler. */ /* Call system error handler. */
_lx_nor_flash_system_error(nor_flash, status); _lx_nor_flash_system_error(nor_flash, status);
@@ -189,7 +174,7 @@ UINT mapped_sectors_available;
/* Initialize the obsolete and mapped sector count available flags. */ /* Initialize the obsolete and mapped sector count available flags. */
obsolete_sectors_available = LX_FALSE; obsolete_sectors_available = LX_FALSE;
mapped_sectors_available = LX_FALSE; mapped_sectors_available = LX_FALSE;
#ifdef LX_NOR_ENABLE_OBSOLETE_COUNT_CACHE #ifdef LX_NOR_ENABLE_OBSOLETE_COUNT_CACHE
/* Determine if the obsolete sector count is available in the cache. */ /* Determine if the obsolete sector count is available in the cache. */
@@ -207,7 +192,7 @@ UINT mapped_sectors_available;
#endif #endif
/* Read the minimum and maximum logical sector values in this block. */ /* Read the minimum and maximum logical sector values in this block. */
#ifdef LX_DIRECT_READ #ifdef LX_DIRECT_READ
/* Read the word directly. */ /* Read the word directly. */
min_logical_sector = *(block_word_ptr + LX_NOR_FLASH_MIN_LOGICAL_SECTOR_OFFSET); min_logical_sector = *(block_word_ptr + LX_NOR_FLASH_MIN_LOGICAL_SECTOR_OFFSET);
#else #else
@@ -216,7 +201,7 @@ UINT mapped_sectors_available;
/* Check for an error from flash driver. Drivers should never return an error.. */ /* Check for an error from flash driver. Drivers should never return an error.. */
if (status) if (status)
{ {
/* Call system error handler. */ /* Call system error handler. */
_lx_nor_flash_system_error(nor_flash, status); _lx_nor_flash_system_error(nor_flash, status);
@@ -224,12 +209,12 @@ UINT mapped_sectors_available;
return(status); return(status);
} }
#endif #endif
/* Determine if the minimum logical sector is valid. */ /* Determine if the minimum logical sector is valid. */
if (min_logical_sector != LX_ALL_ONES) if (min_logical_sector != LX_ALL_ONES)
{ {
#ifdef LX_DIRECT_READ #ifdef LX_DIRECT_READ
/* Read the word directly. */ /* Read the word directly. */
max_logical_sector = *(block_word_ptr + LX_NOR_FLASH_MAX_LOGICAL_SECTOR_OFFSET); max_logical_sector = *(block_word_ptr + LX_NOR_FLASH_MAX_LOGICAL_SECTOR_OFFSET);
#else #else
@@ -238,7 +223,7 @@ UINT mapped_sectors_available;
/* Check for an error from flash driver. Drivers should never return an error.. */ /* Check for an error from flash driver. Drivers should never return an error.. */
if (status) if (status)
{ {
/* Call system error handler. */ /* Call system error handler. */
_lx_nor_flash_system_error(nor_flash, status); _lx_nor_flash_system_error(nor_flash, status);
@@ -251,7 +236,7 @@ UINT mapped_sectors_available;
/* Now let's check to see if all the sector are obsoleted. */ /* Now let's check to see if all the sector are obsoleted. */
if ((max_logical_sector != LX_ALL_ONES) && (max_logical_sector < min_logical_sector)) if ((max_logical_sector != LX_ALL_ONES) && (max_logical_sector < min_logical_sector))
{ {
obsolete_sectors_available = LX_TRUE; obsolete_sectors_available = LX_TRUE;
obsolete_sectors = nor_flash -> lx_nor_flash_physical_sectors_per_block; obsolete_sectors = nor_flash -> lx_nor_flash_physical_sectors_per_block;
} }
@@ -280,10 +265,10 @@ UINT mapped_sectors_available;
/* Loop through the mapped list for this block. */ /* Loop through the mapped list for this block. */
for (j = 0; j < nor_flash -> lx_nor_flash_physical_sectors_per_block; j++) for (j = 0; j < nor_flash -> lx_nor_flash_physical_sectors_per_block; j++)
{ {
/* Read the current mapping entry. */ /* Read the current mapping entry. */
#ifdef LX_DIRECT_READ #ifdef LX_DIRECT_READ
/* Read the word directly. */ /* Read the word directly. */
list_word = *(list_word_ptr); list_word = *(list_word_ptr);
#else #else
@@ -292,7 +277,7 @@ UINT mapped_sectors_available;
/* Check for an error from flash driver. Drivers should never return an error.. */ /* Check for an error from flash driver. Drivers should never return an error.. */
if (status) if (status)
{ {
/* Call system error handler. */ /* Call system error handler. */
_lx_nor_flash_system_error(nor_flash, status); _lx_nor_flash_system_error(nor_flash, status);
@@ -300,26 +285,26 @@ UINT mapped_sectors_available;
return(status); return(status);
} }
#endif #endif
/* Determine if the entry hasn't been used. */ /* Determine if the entry hasn't been used. */
if (list_word == LX_NOR_PHYSICAL_SECTOR_FREE) if (list_word == LX_NOR_PHYSICAL_SECTOR_FREE)
{ {
/* Since allocations are done sequentially in the block, we know nothing /* Since allocations are done sequentially in the block, we know nothing
else exists after this point. */ else exists after this point. */
break; break;
} }
/* Is this entry obsolete? */ /* Is this entry obsolete? */
if ((list_word & LX_NOR_PHYSICAL_SECTOR_VALID) == 0) if ((list_word & LX_NOR_PHYSICAL_SECTOR_VALID) == 0)
{ {
/* Increment the number of obsolete sectors. */ /* Increment the number of obsolete sectors. */
obsolete_sectors++; obsolete_sectors++;
} }
else else
{ {
/* Increment the number of mapped sectors. */ /* Increment the number of mapped sectors. */
mapped_sectors++; mapped_sectors++;
} }
@@ -328,9 +313,9 @@ UINT mapped_sectors_available;
list_word_ptr++; list_word_ptr++;
} }
} }
/* Determine if this block contains full obsoleted sectors and the erase count is minimum. */ /* Determine if this block contains full obsoleted sectors and the erase count is minimum. */
if ((obsolete_sectors == nor_flash -> lx_nor_flash_physical_sectors_per_block) && if ((obsolete_sectors == nor_flash -> lx_nor_flash_physical_sectors_per_block) &&
(erase_count == nor_flash -> lx_nor_flash_minimum_erase_count) && (erase_count == nor_flash -> lx_nor_flash_minimum_erase_count) &&
(nor_flash -> lx_nor_flash_minimum_erased_blocks > 0)) (nor_flash -> lx_nor_flash_minimum_erased_blocks > 0))
{ {
@@ -343,28 +328,28 @@ UINT mapped_sectors_available;
break; break;
} }
/* Determine if we have a block with a new maximum number of obsolete sectors. */ /* Determine if we have a block with a new maximum number of obsolete sectors. */
if ((obsolete_sectors > max_obsolete_sectors) && (erase_count <= erase_count_threshold)) if ((obsolete_sectors > max_obsolete_sectors) && (erase_count <= erase_count_threshold))
{ {
/* Update the new maximum obsolete sectors and related information. */ /* Update the new maximum obsolete sectors and related information. */
max_obsolete_sectors = obsolete_sectors; max_obsolete_sectors = obsolete_sectors;
max_obsolete_block = i; max_obsolete_block = i;
max_obsolete_erase_count = erase_count; max_obsolete_erase_count = erase_count;
max_obsolete_mapped_count = mapped_sectors; max_obsolete_mapped_count = mapped_sectors;
max_obsolete_mapped_count_available = mapped_sectors_available; max_obsolete_mapped_count_available = mapped_sectors_available;
} }
else if ((max_obsolete_sectors) && (obsolete_sectors == max_obsolete_sectors) && (erase_count <= erase_count_threshold)) else if ((max_obsolete_sectors) && (obsolete_sectors == max_obsolete_sectors) && (erase_count <= erase_count_threshold))
{ {
/* Another block has the same number of obsolete sectors. Does this new block have a smaller erase /* Another block has the same number of obsolete sectors. Does this new block have a smaller erase
count? */ count? */
if (erase_count < max_obsolete_erase_count) if (erase_count < max_obsolete_erase_count)
{ {
/* Yes, erase the block with the smaller erase count. */ /* Yes, erase the block with the smaller erase count. */
max_obsolete_sectors = obsolete_sectors; max_obsolete_sectors = obsolete_sectors;
max_obsolete_block = i; max_obsolete_block = i;
@@ -373,11 +358,11 @@ UINT mapped_sectors_available;
max_obsolete_mapped_count_available = mapped_sectors_available; max_obsolete_mapped_count_available = mapped_sectors_available;
} }
} }
/* Determine if we have a new minimum erase count. */ /* Determine if we have a new minimum erase count. */
if (erase_count < min_block_erase_count) if (erase_count < min_block_erase_count)
{ {
/* Update the new minimum erase count and related information. */ /* Update the new minimum erase count and related information. */
min_block_erase_count = erase_count; min_block_erase_count = erase_count;
min_block_erase = i; min_block_erase = i;
@@ -385,7 +370,7 @@ UINT mapped_sectors_available;
min_block_mapped_count = mapped_sectors; min_block_mapped_count = mapped_sectors;
min_block_mapped_count_available = mapped_sectors_available; min_block_mapped_count_available = mapped_sectors_available;
} }
/* Move to the next block. */ /* Move to the next block. */
block_word_ptr = block_word_ptr + nor_flash -> lx_nor_flash_words_per_block; block_word_ptr = block_word_ptr + nor_flash -> lx_nor_flash_words_per_block;
} }
@@ -397,7 +382,7 @@ UINT mapped_sectors_available;
/* Determine if we can erase the block with the most obsolete sectors. */ /* Determine if we can erase the block with the most obsolete sectors. */
if (max_obsolete_sectors) if (max_obsolete_sectors)
{ {
/* Erase the block with the most obsolete sectors. */ /* Erase the block with the most obsolete sectors. */
*return_erase_block = max_obsolete_block; *return_erase_block = max_obsolete_block;
*return_erase_count = max_obsolete_erase_count; *return_erase_count = max_obsolete_erase_count;
@@ -407,7 +392,7 @@ UINT mapped_sectors_available;
} }
else else
{ {
/* Otherwise, choose the block with the smallest erase count. */ /* Otherwise, choose the block with the smallest erase count. */
*return_erase_block = min_block_erase; *return_erase_block = min_block_erase;
*return_erase_count = min_block_erase_count; *return_erase_count = min_block_erase_count;
@@ -432,55 +417,55 @@ UINT mapped_sectors_available;
/* Setup a pointer to the mapped list. */ /* Setup a pointer to the mapped list. */
block_word_ptr = nor_flash -> lx_nor_flash_base_address + *return_erase_block * nor_flash -> lx_nor_flash_words_per_block; block_word_ptr = nor_flash -> lx_nor_flash_base_address + *return_erase_block * nor_flash -> lx_nor_flash_words_per_block;
list_word_ptr = block_word_ptr + nor_flash -> lx_nor_flash_block_physical_sector_mapping_offset; list_word_ptr = block_word_ptr + nor_flash -> lx_nor_flash_block_physical_sector_mapping_offset;
/* Loop through the mapped list for this block. */ /* Loop through the mapped list for this block. */
for (j = 0; j < nor_flash -> lx_nor_flash_physical_sectors_per_block; j++) for (j = 0; j < nor_flash -> lx_nor_flash_physical_sectors_per_block; j++)
{ {
/* Read the current mapping entry. */ /* Read the current mapping entry. */
#ifdef LX_DIRECT_READ #ifdef LX_DIRECT_READ
/* Read the word directly. */ /* Read the word directly. */
list_word = *(list_word_ptr); list_word = *(list_word_ptr);
#else #else
status = _lx_nor_flash_driver_read(nor_flash, list_word_ptr, &list_word, 1); status = _lx_nor_flash_driver_read(nor_flash, list_word_ptr, &list_word, 1);
/* Check for an error from flash driver. Drivers should never return an error.. */ /* Check for an error from flash driver. Drivers should never return an error.. */
if (status) if (status)
{ {
/* Call system error handler. */ /* Call system error handler. */
_lx_nor_flash_system_error(nor_flash, status); _lx_nor_flash_system_error(nor_flash, status);
/* Return the error. */ /* Return the error. */
return(status); return(status);
} }
#endif #endif
/* Determine if the entry hasn't been used. */ /* Determine if the entry hasn't been used. */
if (list_word == LX_NOR_PHYSICAL_SECTOR_FREE) if (list_word == LX_NOR_PHYSICAL_SECTOR_FREE)
{ {
/* Since allocations are done sequentially in the block, we know nothing /* Since allocations are done sequentially in the block, we know nothing
else exists after this point. */ else exists after this point. */
break; break;
} }
/* Is this entry mapped? */ /* Is this entry mapped? */
if ((list_word & LX_NOR_PHYSICAL_SECTOR_VALID) != 0) if ((list_word & LX_NOR_PHYSICAL_SECTOR_VALID) != 0)
{ {
/* Increment the number of mapped sectors. */ /* Increment the number of mapped sectors. */
mapped_sectors++; mapped_sectors++;
} }
/* Move the list pointer ahead. */ /* Move the list pointer ahead. */
list_word_ptr++; list_word_ptr++;
} }
/* Return the mapped sector count. */ /* Return the mapped sector count. */
*return_mapped_sectors = mapped_sectors; *return_mapped_sectors = mapped_sectors;
} }
/* Return success. */ /* Return success. */
return(LX_SUCCESS); return(LX_SUCCESS);
+5 -4
View File
@@ -1,19 +1,20 @@
/*************************************************************************** /***************************************************************************
* Copyright (c) 2024 Microsoft Corporation * Copyright (c) 2024 Microsoft Corporation
* Copyright (c) 2026-present Eclipse ThreadX contributors
* Portion Copyright (c) 2025 STMicroelectronics * Portion Copyright (c) 2025 STMicroelectronics
* *
* This program and the accompanying materials are made available under the * This program and the accompanying materials are made available under the
* terms of the MIT License which is available at * terms of the MIT License which is available at
* https://opensource.org/licenses/MIT. * https://opensource.org/licenses/MIT.
* *
* SPDX-License-Identifier: MIT * SPDX-License-Identifier: MIT
**************************************************************************/ **************************************************************************/
/**************************************************************************/ /**************************************************************************/
/**************************************************************************/ /**************************************************************************/
/** */ /** */
/** LevelX Component */ /** LevelX Component */
/** */ /** */
/** NOR Flash */ /** NOR Flash */
/** */ /** */
-28
View File
@@ -76,34 +76,6 @@
/* */ /* */
/* Application Code */ /* Application Code */
/* */ /* */
/* RELEASE HISTORY */
/* */
/* DATE NAME 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 */
/* 11-09-2020 William E. Lamie Modified comment(s), */
/* fixed compiler warnings, */
/* resulting in version 6.1.2 */
/* 12-30-2020 William E. Lamie Modified comment(s), */
/* fixed compiler warnings, */
/* resulting in version 6.1.3 */
/* 06-02-2021 Bhupendra Naphade Modified comment(s), and */
/* updated product constants */
/* resulting in version 6.1.7 */
/* 03-08-2023 Xiuwen Cai Modified comment(s), */
/* added new driver interface, */
/* resulting in version 6.2.1 */
/* 10-31-2023 Xiuwen Cai Modified comment(s), */
/* added count for minimum */
/* erased blocks, added */
/* obsolete count cache, */
/* avoided clearing user */
/* extension in flash control */
/* block, */
/* resulting in version 6.3.0 */
/* */
/**************************************************************************/ /**************************************************************************/
UINT _lx_nor_flash_open_extended(LX_NOR_FLASH *nor_flash, CHAR *name, UINT (*nor_driver_initialize)(LX_NOR_FLASH *), VOID *nor_driver_info_ptr) UINT _lx_nor_flash_open_extended(LX_NOR_FLASH *nor_flash, CHAR *name, UINT (*nor_driver_initialize)(LX_NOR_FLASH *), VOID *nor_driver_info_ptr)
+41 -50
View File
@@ -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 * This program and the accompanying materials are made available under the
* terms of the MIT License which is available at * terms of the MIT License which is available at
* https://opensource.org/licenses/MIT. * https://opensource.org/licenses/MIT.
* *
* SPDX-License-Identifier: MIT * SPDX-License-Identifier: MIT
**************************************************************************/ **************************************************************************/
/**************************************************************************/ /**************************************************************************/
/**************************************************************************/ /**************************************************************************/
/** */ /** */
/** LevelX Component */ /** LevelX Component */
/** */ /** */
/** NOR Flash */ /** NOR Flash */
/** */ /** */
@@ -34,56 +35,46 @@
#include "lx_api.h" #include "lx_api.h"
/**************************************************************************/ /**************************************************************************/
/* */ /* */
/* FUNCTION RELEASE */ /* FUNCTION RELEASE */
/* */ /* */
/* _lx_nor_flash_partial_defragment PORTABLE C */ /* _lx_nor_flash_partial_defragment PORTABLE C */
/* 6.1.7 */ /* 6.1.7 */
/* AUTHOR */ /* AUTHOR */
/* */ /* */
/* William E. Lamie, Microsoft Corporation */ /* William E. Lamie, Microsoft Corporation */
/* */ /* */
/* DESCRIPTION */ /* DESCRIPTION */
/* */
/* This function defragments the NOR flash up to the specified */
/* number of blocks. . */
/* */
/* INPUT */
/* */
/* nor_flash NOR flash instance */
/* max_blocks Maximum number of blocks to */
/* defragment */
/* */
/* OUTPUT */
/* */
/* return status */
/* */
/* CALLS */
/* */
/* _lx_nor_flash_block_reclaim Reclaim a NOR flash block */
/* tx_mutex_get Get thread protection */
/* tx_mutex_put Release thread protection */
/* */
/* CALLED BY */
/* */
/* Application Code */
/* Internal LevelX */
/* */
/* RELEASE HISTORY */
/* */
/* DATE NAME DESCRIPTION */
/* */ /* */
/* 05-19-2020 William E. Lamie Initial Version 6.0 */ /* This function defragments the NOR flash up to the specified */
/* 09-30-2020 William E. Lamie Modified comment(s), */ /* number of blocks. . */
/* resulting in version 6.1 */ /* */
/* 06-02-2021 Bhupendra Naphade Modified comment(s), */ /* INPUT */
/* resulting in version 6.1.7 */ /* */
/* nor_flash NOR flash instance */
/* max_blocks Maximum number of blocks to */
/* defragment */
/* */
/* OUTPUT */
/* */
/* return status */
/* */
/* CALLS */
/* */
/* _lx_nor_flash_block_reclaim Reclaim a NOR flash block */
/* tx_mutex_get Get thread protection */
/* tx_mutex_put Release thread protection */
/* */
/* CALLED BY */
/* */
/* Application Code */
/* Internal LevelX */
/* */ /* */
/**************************************************************************/ /**************************************************************************/
UINT _lx_nor_flash_partial_defragment(LX_NOR_FLASH *nor_flash, UINT max_blocks) UINT _lx_nor_flash_partial_defragment(LX_NOR_FLASH *nor_flash, UINT max_blocks)
{ {
ULONG i; ULONG i;
@@ -96,7 +87,7 @@ ULONG i;
/* Determine if the maximum number of blocks exceeds the total blocks in this flash instance. */ /* Determine if the maximum number of blocks exceeds the total blocks in this flash instance. */
if (max_blocks >= nor_flash -> lx_nor_flash_total_blocks) if (max_blocks >= nor_flash -> lx_nor_flash_total_blocks)
{ {
/* Adjust the maximum to the total number of blocks. */ /* Adjust the maximum to the total number of blocks. */
max_blocks = nor_flash -> lx_nor_flash_total_blocks; max_blocks = nor_flash -> lx_nor_flash_total_blocks;
} }
@@ -104,11 +95,11 @@ ULONG i;
/* Loop for max number of blocks, while there are obsolete count. */ /* Loop for max number of blocks, while there are obsolete count. */
for (i = 0; i < max_blocks; i++) for (i = 0; i < max_blocks; i++)
{ {
/* Determine if there is any more defragment work. */ /* Determine if there is any more defragment work. */
if (nor_flash -> lx_nor_flash_obsolete_physical_sectors == 0) if (nor_flash -> lx_nor_flash_obsolete_physical_sectors == 0)
break; break;
/* Call the block reclaim function to defragment. */ /* Call the block reclaim function to defragment. */
_lx_nor_flash_block_reclaim(nor_flash); _lx_nor_flash_block_reclaim(nor_flash);
} }
@@ -119,7 +110,7 @@ ULONG i;
tx_mutex_put(&nor_flash -> lx_nor_flash_mutex); tx_mutex_put(&nor_flash -> lx_nor_flash_mutex);
#endif #endif
/* Return successful completion. */ /* Return successful completion. */
return(LX_SUCCESS); return(LX_SUCCESS);
} }
@@ -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 * This program and the accompanying materials are made available under the
* terms of the MIT License which is available at * terms of the MIT License which is available at
* https://opensource.org/licenses/MIT. * https://opensource.org/licenses/MIT.
* *
* SPDX-License-Identifier: MIT * SPDX-License-Identifier: MIT
**************************************************************************/ **************************************************************************/
/**************************************************************************/ /**************************************************************************/
/**************************************************************************/ /**************************************************************************/
/** */ /** */
/** LevelX Component */ /** LevelX Component */
/** */ /** */
/** NOR Flash */ /** NOR Flash */
/** */ /** */
@@ -34,51 +35,41 @@
#include "lx_api.h" #include "lx_api.h"
/**************************************************************************/ /**************************************************************************/
/* */ /* */
/* FUNCTION RELEASE */ /* FUNCTION RELEASE */
/* */ /* */
/* _lx_nor_flash_physical_sector_allocate PORTABLE C */ /* _lx_nor_flash_physical_sector_allocate PORTABLE C */
/* 6.1.7 */ /* 6.1.7 */
/* AUTHOR */ /* AUTHOR */
/* */ /* */
/* William E. Lamie, Microsoft Corporation */ /* William E. Lamie, Microsoft Corporation */
/* */ /* */
/* DESCRIPTION */ /* DESCRIPTION */
/* */
/* This function allocates a free physical sector for mapping to a */
/* logical sector. */
/* */
/* INPUT */
/* */
/* nor_flash NOR flash instance */
/* logical_sector Logical sector number */
/* physical_sector_map_entry Pointer to sector map entry */
/* physical_sector_address Address of physical sector */
/* */
/* OUTPUT */
/* */
/* return status */
/* */
/* CALLS */
/* */
/* _lx_nor_flash_driver_write Driver flash sector write */
/* _lx_nor_flash_driver_read Driver flash sector read */
/* _lx_nor_flash_system_error Internal system error handler */
/* */
/* CALLED BY */
/* */
/* Internal LevelX */
/* */
/* RELEASE HISTORY */
/* */
/* DATE NAME DESCRIPTION */
/* */ /* */
/* 05-19-2020 William E. Lamie Initial Version 6.0 */ /* This function allocates a free physical sector for mapping to a */
/* 09-30-2020 William E. Lamie Modified comment(s), */ /* logical sector. */
/* resulting in version 6.1 */ /* */
/* 06-02-2021 Bhupendra Naphade Modified comment(s), */ /* INPUT */
/* resulting in version 6.1.7 */ /* */
/* nor_flash NOR flash instance */
/* logical_sector Logical sector number */
/* physical_sector_map_entry Pointer to sector map entry */
/* physical_sector_address Address of physical sector */
/* */
/* OUTPUT */
/* */
/* return status */
/* */
/* CALLS */
/* */
/* _lx_nor_flash_driver_write Driver flash sector write */
/* _lx_nor_flash_driver_read Driver flash sector read */
/* _lx_nor_flash_system_error Internal system error handler */
/* */
/* CALLED BY */
/* */
/* Internal LevelX */
/* */ /* */
/**************************************************************************/ /**************************************************************************/
UINT _lx_nor_flash_physical_sector_allocate(LX_NOR_FLASH *nor_flash, ULONG logical_sector, ULONG **physical_sector_map_entry, ULONG **physical_sector_address) UINT _lx_nor_flash_physical_sector_allocate(LX_NOR_FLASH *nor_flash, ULONG logical_sector, ULONG **physical_sector_map_entry, ULONG **physical_sector_address)
@@ -101,7 +92,7 @@ UINT status;
/* Initialize the return parameters. */ /* Initialize the return parameters. */
*physical_sector_map_entry = (ULONG *) 0; *physical_sector_map_entry = (ULONG *) 0;
*physical_sector_address = (ULONG *) 0; *physical_sector_address = (ULONG *) 0;
/* Determine if there are any free physical sectors. */ /* Determine if there are any free physical sectors. */
if (nor_flash -> lx_nor_flash_free_physical_sectors == 0) if (nor_flash -> lx_nor_flash_free_physical_sectors == 0)
{ {
@@ -126,10 +117,10 @@ UINT status;
/* Find the first free physical sector from the free sector bit map of this block. */ /* Find the first free physical sector from the free sector bit map of this block. */
for (j = 0; j < nor_flash -> lx_nor_flash_block_bit_map_words; j++) for (j = 0; j < nor_flash -> lx_nor_flash_block_bit_map_words; j++)
{ {
/* Read this word of the free sector bit map. */ /* Read this word of the free sector bit map. */
#ifdef LX_DIRECT_READ #ifdef LX_DIRECT_READ
/* Read the word directly. */ /* Read the word directly. */
block_word = *(block_word_ptr + nor_flash -> lx_nor_flash_block_free_bit_map_offset + j); block_word = *(block_word_ptr + nor_flash -> lx_nor_flash_block_free_bit_map_offset + j);
#else #else
@@ -138,32 +129,32 @@ UINT status;
/* Check for an error from flash driver. Drivers should never return an error.. */ /* Check for an error from flash driver. Drivers should never return an error.. */
if (status) if (status)
{ {
/* Call system error handler. */ /* Call system error handler. */
_lx_nor_flash_system_error(nor_flash, status); _lx_nor_flash_system_error(nor_flash, status);
/* Return the error. */ /* Return the error. */
return(status); return(status);
} }
#endif #endif
/* Are there any free sectors in this word? */ /* Are there any free sectors in this word? */
if (block_word) if (block_word)
{ {
/* Yes, there are free sectors in this word. */ /* Yes, there are free sectors in this word. */
for (k = 0; k < 32; k++) for (k = 0; k < 32; k++)
{ {
/* Is this sector free? */ /* Is this sector free? */
if (block_word & 1) if (block_word & 1)
{ {
/* Yes, this sector is free, clear the bit for this sector in the free sector map. */ /* Yes, this sector is free, clear the bit for this sector in the free sector map. */
/* Read this word of the free sector bit map again. */ /* Read this word of the free sector bit map again. */
#ifdef LX_DIRECT_READ #ifdef LX_DIRECT_READ
/* Read the word directly. */ /* Read the word directly. */
block_word = *(block_word_ptr + nor_flash -> lx_nor_flash_block_free_bit_map_offset + j); block_word = *(block_word_ptr + nor_flash -> lx_nor_flash_block_free_bit_map_offset + j);
#else #else
@@ -172,7 +163,7 @@ UINT status;
/* Check for an error from flash driver. Drivers should never return an error.. */ /* Check for an error from flash driver. Drivers should never return an error.. */
if (status) if (status)
{ {
/* Call system error handler. */ /* Call system error handler. */
_lx_nor_flash_system_error(nor_flash, status); _lx_nor_flash_system_error(nor_flash, status);
@@ -180,17 +171,17 @@ UINT status;
return(status); return(status);
} }
#endif #endif
/* Clear the bit associated with the free sector to indicate it is not free. */ /* Clear the bit associated with the free sector to indicate it is not free. */
block_word = block_word & ~(((ULONG) 1) << k); block_word = block_word & ~(((ULONG) 1) << k);
/* Now write back free bit map word with the bit for this sector cleared. */ /* Now write back free bit map word with the bit for this sector cleared. */
status = _lx_nor_flash_driver_write(nor_flash, (block_word_ptr + nor_flash -> lx_nor_flash_block_free_bit_map_offset + j), &block_word, 1); status = _lx_nor_flash_driver_write(nor_flash, (block_word_ptr + nor_flash -> lx_nor_flash_block_free_bit_map_offset + j), &block_word, 1);
/* Check for an error from flash driver. Drivers should never return an error.. */ /* Check for an error from flash driver. Drivers should never return an error.. */
if (status) if (status)
{ {
/* Call system error handler. */ /* Call system error handler. */
_lx_nor_flash_system_error(nor_flash, status); _lx_nor_flash_system_error(nor_flash, status);
@@ -201,14 +192,14 @@ UINT status;
/* Determine if this is the last entry available in this block. */ /* Determine if this is the last entry available in this block. */
if (((block_word >> 1) == 0) && (j == (nor_flash -> lx_nor_flash_block_bit_map_words - 1))) if (((block_word >> 1) == 0) && (j == (nor_flash -> lx_nor_flash_block_bit_map_words - 1)))
{ {
/* This is the last physical sector in the block. Now we need to calculate the minimum valid logical /* This is the last physical sector in the block. Now we need to calculate the minimum valid logical
sector and the maximum valid logical sector. */ sector and the maximum valid logical sector. */
/* Setup the minimum and maximum logical sectors to the current logical sector. */ /* Setup the minimum and maximum logical sectors to the current logical sector. */
min_logical_sector = logical_sector; min_logical_sector = logical_sector;
max_logical_sector = logical_sector; max_logical_sector = logical_sector;
/* Setup a pointer to the mapped list. */ /* Setup a pointer to the mapped list. */
list_word_ptr = block_word_ptr + nor_flash -> lx_nor_flash_block_physical_sector_mapping_offset; list_word_ptr = block_word_ptr + nor_flash -> lx_nor_flash_block_physical_sector_mapping_offset;
@@ -218,16 +209,16 @@ UINT status;
/* Read the mapped sector entry. */ /* Read the mapped sector entry. */
#ifdef LX_DIRECT_READ #ifdef LX_DIRECT_READ
/* Read the word directly. */ /* Read the word directly. */
list_word = *(list_word_ptr); list_word = *(list_word_ptr);
#else #else
status = _lx_nor_flash_driver_read(nor_flash, list_word_ptr, &list_word, 1); status = _lx_nor_flash_driver_read(nor_flash, list_word_ptr, &list_word, 1);
/* Check for an error from flash driver. Drivers should never return an error.. */ /* Check for an error from flash driver. Drivers should never return an error.. */
if (status) if (status)
{ {
/* Call system error handler. */ /* Call system error handler. */
_lx_nor_flash_system_error(nor_flash, status); _lx_nor_flash_system_error(nor_flash, status);
@@ -235,7 +226,7 @@ UINT status;
return(status); return(status);
} }
#endif #endif
/* Is this entry valid? */ /* Is this entry valid? */
if (list_word & LX_NOR_PHYSICAL_SECTOR_VALID) if (list_word & LX_NOR_PHYSICAL_SECTOR_VALID)
{ {
@@ -246,50 +237,50 @@ UINT status;
/* Determine if a new minimum has been found. */ /* Determine if a new minimum has been found. */
if (list_word < min_logical_sector) if (list_word < min_logical_sector)
min_logical_sector = list_word; min_logical_sector = list_word;
/* Determine if a new maximum has been found. */ /* Determine if a new maximum has been found. */
if (list_word != LX_NOR_LOGICAL_SECTOR_MASK) if (list_word != LX_NOR_LOGICAL_SECTOR_MASK)
{ {
if (list_word > max_logical_sector) if (list_word > max_logical_sector)
max_logical_sector = list_word; max_logical_sector = list_word;
} }
} }
/* Move the list pointer ahead. */ /* Move the list pointer ahead. */
list_word_ptr++; list_word_ptr++;
} }
/* Move the search pointer forward, since we know this block is exhausted. */ /* Move the search pointer forward, since we know this block is exhausted. */
search_block++; search_block++;
/* Check for wrap condition on the search block. */ /* Check for wrap condition on the search block. */
if (search_block >= nor_flash -> lx_nor_flash_total_blocks) if (search_block >= nor_flash -> lx_nor_flash_total_blocks)
{ {
/* Reset search block to the beginning. */ /* Reset search block to the beginning. */
search_block = 0; search_block = 0;
} }
/* Now write the minimum and maximum logical sector in this block. */ /* Now write the minimum and maximum logical sector in this block. */
status = _lx_nor_flash_driver_write(nor_flash, block_word_ptr + LX_NOR_FLASH_MIN_LOGICAL_SECTOR_OFFSET, &min_logical_sector, 1); status = _lx_nor_flash_driver_write(nor_flash, block_word_ptr + LX_NOR_FLASH_MIN_LOGICAL_SECTOR_OFFSET, &min_logical_sector, 1);
/* Check for an error from flash driver. Drivers should never return an error.. */ /* Check for an error from flash driver. Drivers should never return an error.. */
if (status) if (status)
{ {
/* Call system error handler. */ /* Call system error handler. */
_lx_nor_flash_system_error(nor_flash, status); _lx_nor_flash_system_error(nor_flash, status);
/* Return the error. */ /* Return the error. */
return(status); return(status);
} }
status = _lx_nor_flash_driver_write(nor_flash, block_word_ptr + LX_NOR_FLASH_MAX_LOGICAL_SECTOR_OFFSET, &max_logical_sector, 1); status = _lx_nor_flash_driver_write(nor_flash, block_word_ptr + LX_NOR_FLASH_MAX_LOGICAL_SECTOR_OFFSET, &max_logical_sector, 1);
/* Check for an error from flash driver. Drivers should never return an error.. */ /* Check for an error from flash driver. Drivers should never return an error.. */
if (status) if (status)
{ {
/* Call system error handler. */ /* Call system error handler. */
_lx_nor_flash_system_error(nor_flash, status); _lx_nor_flash_system_error(nor_flash, status);
@@ -297,35 +288,35 @@ UINT status;
return(status); return(status);
} }
} }
/* Remember the block to search. */ /* Remember the block to search. */
nor_flash -> lx_nor_flash_free_block_search = search_block; nor_flash -> lx_nor_flash_free_block_search = search_block;
/* Prepare the return information. */ /* Prepare the return information. */
*physical_sector_map_entry = block_word_ptr + (nor_flash -> lx_nor_flash_block_physical_sector_mapping_offset + (j * 32)) + k; *physical_sector_map_entry = block_word_ptr + (nor_flash -> lx_nor_flash_block_physical_sector_mapping_offset + (j * 32)) + k;
*physical_sector_address = block_word_ptr + (nor_flash -> lx_nor_flash_block_physical_sector_offset) + (((j * 32) + k) * LX_NOR_SECTOR_SIZE); *physical_sector_address = block_word_ptr + (nor_flash -> lx_nor_flash_block_physical_sector_offset) + (((j * 32) + k) * LX_NOR_SECTOR_SIZE);
/* Return success! */ /* Return success! */
return(LX_SUCCESS); return(LX_SUCCESS);
} }
/* Shift down the bit map. */ /* Shift down the bit map. */
block_word = block_word >> 1; block_word = block_word >> 1;
/* Determine if there are any more bits set? If not, we can break out of the search of this word. */ /* Determine if there are any more bits set? If not, we can break out of the search of this word. */
if (block_word == 0) if (block_word == 0)
break; break;
} }
} }
} }
/* Move to the next flash block. */ /* Move to the next flash block. */
search_block++; search_block++;
/* Determine if we have to wrap the search block. */ /* Determine if we have to wrap the search block. */
if (search_block >= nor_flash -> lx_nor_flash_total_blocks) if (search_block >= nor_flash -> lx_nor_flash_total_blocks)
{ {
/* Set the search block to the beginning. */ /* Set the search block to the beginning. */
search_block = 0; search_block = 0;
} }
@@ -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 * This program and the accompanying materials are made available under the
* terms of the MIT License which is available at * terms of the MIT License which is available at
* https://opensource.org/licenses/MIT. * https://opensource.org/licenses/MIT.
* *
* SPDX-License-Identifier: MIT * SPDX-License-Identifier: MIT
**************************************************************************/ **************************************************************************/
/**************************************************************************/ /**************************************************************************/
/**************************************************************************/ /**************************************************************************/
/** */ /** */
/** LevelX Component */ /** LevelX Component */
/** */ /** */
/** NOR Flash */ /** NOR Flash */
/** */ /** */
@@ -34,47 +35,37 @@
#include "lx_api.h" #include "lx_api.h"
/**************************************************************************/ /**************************************************************************/
/* */ /* */
/* FUNCTION RELEASE */ /* FUNCTION RELEASE */
/* */ /* */
/* _lx_nor_flash_sector_mapping_cache_invalidate PORTABLE C */ /* _lx_nor_flash_sector_mapping_cache_invalidate PORTABLE C */
/* 6.1.7 */ /* 6.1.7 */
/* AUTHOR */ /* AUTHOR */
/* */ /* */
/* William E. Lamie, Microsoft Corporation */ /* William E. Lamie, Microsoft Corporation */
/* */ /* */
/* DESCRIPTION */ /* DESCRIPTION */
/* */
/* This function invalidates the sector's entry in the NOR flash */
/* cache. */
/* */
/* INPUT */
/* */
/* nor_flash NOR flash instance */
/* logical_sector Logical sector */
/* */
/* OUTPUT */
/* */
/* None */
/* */
/* CALLS */
/* */
/* None */
/* */
/* CALLED BY */
/* */
/* Internal LevelX */
/* */
/* RELEASE HISTORY */
/* */
/* DATE NAME DESCRIPTION */
/* */ /* */
/* 05-19-2020 William E. Lamie Initial Version 6.0 */ /* This function invalidates the sector's entry in the NOR flash */
/* 09-30-2020 William E. Lamie Modified comment(s), */ /* cache. */
/* resulting in version 6.1 */ /* */
/* 06-02-2021 Bhupendra Naphade Modified comment(s), */ /* INPUT */
/* resulting in version 6.1.7 */ /* */
/* nor_flash NOR flash instance */
/* logical_sector Logical sector */
/* */
/* OUTPUT */
/* */
/* None */
/* */
/* CALLS */
/* */
/* None */
/* */
/* CALLED BY */
/* */
/* Internal LevelX */
/* */ /* */
/**************************************************************************/ /**************************************************************************/
VOID _lx_nor_flash_sector_mapping_cache_invalidate(LX_NOR_FLASH *nor_flash, ULONG logical_sector) VOID _lx_nor_flash_sector_mapping_cache_invalidate(LX_NOR_FLASH *nor_flash, ULONG logical_sector)
@@ -87,14 +78,14 @@ LX_NOR_SECTOR_MAPPING_CACHE_ENTRY *sector_mapping_cache_entry_ptr;
/* Determine if the sector mapping cache is enabled. */ /* Determine if the sector mapping cache is enabled. */
if (nor_flash -> lx_nor_flash_sector_mapping_cache_enabled) if (nor_flash -> lx_nor_flash_sector_mapping_cache_enabled)
{ {
/* Calculate the starting index of the sector mapping cache for this sector entry. */ /* Calculate the starting index of the sector mapping cache for this sector entry. */
i = (logical_sector & LX_NOR_SECTOR_MAPPING_CACHE_HASH_MASK) * LX_NOR_SECTOR_MAPPING_CACHE_DEPTH; i = (logical_sector & LX_NOR_SECTOR_MAPPING_CACHE_HASH_MASK) * LX_NOR_SECTOR_MAPPING_CACHE_DEPTH;
/* Build a pointer to the cache entry. */ /* Build a pointer to the cache entry. */
sector_mapping_cache_entry_ptr = &nor_flash -> lx_nor_flash_sector_mapping_cache[i]; sector_mapping_cache_entry_ptr = &nor_flash -> lx_nor_flash_sector_mapping_cache[i];
/* Determine if the sector is in the sector mapping cache - assuming the depth of the sector /* Determine if the sector is in the sector mapping cache - assuming the depth of the sector
mapping cache is LX_NOR_SECTOR_MAPPING_CACHE_DEPTH entries. */ mapping cache is LX_NOR_SECTOR_MAPPING_CACHE_DEPTH entries. */
if ((sector_mapping_cache_entry_ptr -> lx_nor_sector_mapping_cache_logical_sector) == (logical_sector | LX_NOR_SECTOR_MAPPING_CACHE_ENTRY_VALID)) if ((sector_mapping_cache_entry_ptr -> lx_nor_sector_mapping_cache_logical_sector) == (logical_sector | LX_NOR_SECTOR_MAPPING_CACHE_ENTRY_VALID))
{ {
@@ -103,7 +94,7 @@ LX_NOR_SECTOR_MAPPING_CACHE_ENTRY *sector_mapping_cache_entry_ptr;
*(sector_mapping_cache_entry_ptr) = *(sector_mapping_cache_entry_ptr + 1); *(sector_mapping_cache_entry_ptr) = *(sector_mapping_cache_entry_ptr + 1);
*(sector_mapping_cache_entry_ptr + 1) = *(sector_mapping_cache_entry_ptr + 2); *(sector_mapping_cache_entry_ptr + 1) = *(sector_mapping_cache_entry_ptr + 2);
*(sector_mapping_cache_entry_ptr + 2) = *(sector_mapping_cache_entry_ptr + 3); *(sector_mapping_cache_entry_ptr + 2) = *(sector_mapping_cache_entry_ptr + 3);
/* Invalidate the last entry. */ /* Invalidate the last entry. */
(sector_mapping_cache_entry_ptr + 3) -> lx_nor_sector_mapping_cache_logical_sector = 0; (sector_mapping_cache_entry_ptr + 3) -> lx_nor_sector_mapping_cache_logical_sector = 0;
} }
@@ -113,7 +104,7 @@ LX_NOR_SECTOR_MAPPING_CACHE_ENTRY *sector_mapping_cache_entry_ptr;
/* Move all subsequent cache entries up and invalidate the last entry. */ /* Move all subsequent cache entries up and invalidate the last entry. */
*(sector_mapping_cache_entry_ptr + 1) = *(sector_mapping_cache_entry_ptr + 2); *(sector_mapping_cache_entry_ptr + 1) = *(sector_mapping_cache_entry_ptr + 2);
*(sector_mapping_cache_entry_ptr + 2) = *(sector_mapping_cache_entry_ptr + 3); *(sector_mapping_cache_entry_ptr + 2) = *(sector_mapping_cache_entry_ptr + 3);
/* Invalidate the last entry. */ /* Invalidate the last entry. */
(sector_mapping_cache_entry_ptr + 3) -> lx_nor_sector_mapping_cache_logical_sector = 0; (sector_mapping_cache_entry_ptr + 3) -> lx_nor_sector_mapping_cache_logical_sector = 0;
} }
@@ -122,7 +113,7 @@ LX_NOR_SECTOR_MAPPING_CACHE_ENTRY *sector_mapping_cache_entry_ptr;
/* Move all subsequent cache entries up and invalidate the last entry. */ /* Move all subsequent cache entries up and invalidate the last entry. */
*(sector_mapping_cache_entry_ptr + 2) = *(sector_mapping_cache_entry_ptr + 3); *(sector_mapping_cache_entry_ptr + 2) = *(sector_mapping_cache_entry_ptr + 3);
/* Invalidate the last entry. */ /* Invalidate the last entry. */
(sector_mapping_cache_entry_ptr + 3) -> lx_nor_sector_mapping_cache_logical_sector = 0; (sector_mapping_cache_entry_ptr + 3) -> lx_nor_sector_mapping_cache_logical_sector = 0;
} }
+52 -64
View File
@@ -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 * This program and the accompanying materials are made available under the
* terms of the MIT License which is available at * terms of the MIT License which is available at
* https://opensource.org/licenses/MIT. * https://opensource.org/licenses/MIT.
* *
* SPDX-License-Identifier: MIT * SPDX-License-Identifier: MIT
**************************************************************************/ **************************************************************************/
/**************************************************************************/ /**************************************************************************/
/**************************************************************************/ /**************************************************************************/
/** */ /** */
/** LevelX Component */ /** LevelX Component */
/** */ /** */
/** NOR Flash */ /** NOR Flash */
/** */ /** */
@@ -34,58 +35,45 @@
#include "lx_api.h" #include "lx_api.h"
/**************************************************************************/ /**************************************************************************/
/* */ /* */
/* FUNCTION RELEASE */ /* FUNCTION RELEASE */
/* */ /* */
/* _lx_nor_flash_sector_read PORTABLE C */ /* _lx_nor_flash_sector_read PORTABLE C */
/* 6.3.0 */ /* 6.3.0 */
/* AUTHOR */ /* AUTHOR */
/* */ /* */
/* William E. Lamie, Microsoft Corporation */ /* William E. Lamie, Microsoft Corporation */
/* */ /* */
/* DESCRIPTION */ /* DESCRIPTION */
/* */
/* This function reads a logical sector from NOR flash. */
/* */
/* INPUT */
/* */
/* nor_flash NOR flash instance */
/* logical_sector Logical sector number */
/* buffer Pointer to buffer to read into*/
/* (the size is 512 bytes) */
/* */
/* OUTPUT */
/* */
/* return status */
/* */
/* CALLS */
/* */
/* _lx_nor_flash_driver_write Driver flash sector write */
/* _lx_nor_flash_driver_read Driver flash sector read */
/* _lx_nor_flash_logical_sector_find Find logical sector */
/* _lx_nor_flash_physical_sector_allocate */
/* Allocate new logical sector */
/* _lx_nor_flash_system_error Internal system error handler */
/* tx_mutex_get Get thread protection */
/* tx_mutex_put Release thread protection */
/* */
/* CALLED BY */
/* */
/* Application Code */
/* */
/* RELEASE HISTORY */
/* */
/* DATE NAME DESCRIPTION */
/* */ /* */
/* 05-19-2020 William E. Lamie Initial Version 6.0 */ /* This function reads a logical sector from NOR flash. */
/* 09-30-2020 William E. Lamie Modified comment(s), */ /* */
/* resulting in version 6.1 */ /* INPUT */
/* 06-02-2021 Bhupendra Naphade Modified comment(s), */ /* */
/* resulting in version 6.1.7 */ /* nor_flash NOR flash instance */
/* 10-31-2023 Xiuwen Cai Modified comment(s), */ /* logical_sector Logical sector number */
/* added mapping bitmap cache, */ /* buffer Pointer to buffer to read into*/
/* resulting in version 6.3.0 */ /* (the size is 512 bytes) */
/* */
/* OUTPUT */
/* */
/* return status */
/* */
/* CALLS */
/* */
/* _lx_nor_flash_driver_write Driver flash sector write */
/* _lx_nor_flash_driver_read Driver flash sector read */
/* _lx_nor_flash_logical_sector_find Find logical sector */
/* _lx_nor_flash_physical_sector_allocate */
/* Allocate new logical sector */
/* _lx_nor_flash_system_error Internal system error handler */
/* tx_mutex_get Get thread protection */
/* tx_mutex_put Release thread protection */
/* */
/* CALLED BY */
/* */
/* Application Code */
/* */ /* */
/**************************************************************************/ /**************************************************************************/
UINT _lx_nor_flash_sector_read(LX_NOR_FLASH *nor_flash, ULONG logical_sector, VOID *buffer) UINT _lx_nor_flash_sector_read(LX_NOR_FLASH *nor_flash, ULONG logical_sector, VOID *buffer)
@@ -108,23 +96,23 @@ ULONG *sector_address;
/* See if we can find the sector in the current mapping. */ /* See if we can find the sector in the current mapping. */
_lx_nor_flash_logical_sector_find(nor_flash, logical_sector, LX_FALSE, &mapping_address, &sector_address); _lx_nor_flash_logical_sector_find(nor_flash, logical_sector, LX_FALSE, &mapping_address, &sector_address);
/* Determine if the logical sector was found. */ /* Determine if the logical sector was found. */
if (mapping_address) if (mapping_address)
{ {
/* Yes, we were able to find the logical sector. */ /* Yes, we were able to find the logical sector. */
/* Read the sector data from the physical sector. */ /* Read the sector data from the physical sector. */
status = _lx_nor_flash_driver_read(nor_flash, sector_address, buffer, LX_NOR_SECTOR_SIZE); status = _lx_nor_flash_driver_read(nor_flash, sector_address, buffer, LX_NOR_SECTOR_SIZE);
/* Check for an error from flash driver. Drivers should never return an error.. */ /* Check for an error from flash driver. Drivers should never return an error.. */
if (status) if (status)
{ {
/* Call system error handler. */ /* Call system error handler. */
_lx_nor_flash_system_error(nor_flash, status); _lx_nor_flash_system_error(nor_flash, status);
/* Adjust return status. */ /* Adjust return status. */
status = LX_ERROR; status = LX_ERROR;
} }
@@ -137,7 +125,7 @@ ULONG *sector_address;
} }
else else
{ {
/* Allocate a new physical sector for this write. */ /* Allocate a new physical sector for this write. */
_lx_nor_flash_physical_sector_allocate(nor_flash, logical_sector, &mapping_address, &sector_address); _lx_nor_flash_physical_sector_allocate(nor_flash, logical_sector, &mapping_address, &sector_address);
@@ -147,31 +135,31 @@ ULONG *sector_address;
/* Update the number of free physical sectors. */ /* Update the number of free physical sectors. */
nor_flash -> lx_nor_flash_free_physical_sectors--; nor_flash -> lx_nor_flash_free_physical_sectors--;
/* Read the sector data from the physical sector. */ /* Read the sector data from the physical sector. */
status = _lx_nor_flash_driver_read(nor_flash, sector_address, buffer, LX_NOR_SECTOR_SIZE); status = _lx_nor_flash_driver_read(nor_flash, sector_address, buffer, LX_NOR_SECTOR_SIZE);
/* Check for an error from flash driver. Drivers should never return an error.. */ /* Check for an error from flash driver. Drivers should never return an error.. */
if (status) if (status)
{ {
/* Call system error handler. */ /* Call system error handler. */
_lx_nor_flash_system_error(nor_flash, status); _lx_nor_flash_system_error(nor_flash, status);
} }
/* Now build the new mapping entry. */ /* Now build the new mapping entry. */
mapping_entry = ((ULONG) LX_NOR_PHYSICAL_SECTOR_VALID) | ((ULONG) LX_NOR_PHYSICAL_SECTOR_SUPERCEDED) | logical_sector; mapping_entry = ((ULONG) LX_NOR_PHYSICAL_SECTOR_VALID) | ((ULONG) LX_NOR_PHYSICAL_SECTOR_SUPERCEDED) | logical_sector;
/* Write out the new mapping entry. */ /* Write out the new mapping entry. */
status = _lx_nor_flash_driver_write(nor_flash, mapping_address, &mapping_entry, 1); status = _lx_nor_flash_driver_write(nor_flash, mapping_address, &mapping_entry, 1);
/* Check for an error from flash driver. Drivers should never return an error.. */ /* Check for an error from flash driver. Drivers should never return an error.. */
if (status) if (status)
{ {
/* Call system error handler. */ /* Call system error handler. */
_lx_nor_flash_system_error(nor_flash, status); _lx_nor_flash_system_error(nor_flash, status);
#ifdef LX_THREAD_SAFE_ENABLE #ifdef LX_THREAD_SAFE_ENABLE
/* Release the thread safe mutex. */ /* Release the thread safe mutex. */
@@ -202,12 +190,12 @@ ULONG *sector_address;
} }
else else
{ {
/* Could not find the logical sector. */ /* Could not find the logical sector. */
status = LX_SECTOR_NOT_FOUND; status = LX_SECTOR_NOT_FOUND;
} }
} }
#ifdef LX_THREAD_SAFE_ENABLE #ifdef LX_THREAD_SAFE_ENABLE
/* Release the thread safe mutex. */ /* Release the thread safe mutex. */
+53 -66
View File
@@ -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 * This program and the accompanying materials are made available under the
* terms of the MIT License which is available at * terms of the MIT License which is available at
* https://opensource.org/licenses/MIT. * https://opensource.org/licenses/MIT.
* *
* SPDX-License-Identifier: MIT * SPDX-License-Identifier: MIT
**************************************************************************/ **************************************************************************/
/**************************************************************************/ /**************************************************************************/
/**************************************************************************/ /**************************************************************************/
/** */ /** */
/** LevelX Component */ /** LevelX Component */
/** */ /** */
/** NOR Flash */ /** NOR Flash */
/** */ /** */
@@ -34,59 +35,45 @@
#include "lx_api.h" #include "lx_api.h"
/**************************************************************************/ /**************************************************************************/
/* */ /* */
/* FUNCTION RELEASE */ /* FUNCTION RELEASE */
/* */ /* */
/* _lx_nor_flash_sector_release PORTABLE C */ /* _lx_nor_flash_sector_release PORTABLE C */
/* 6.3.0 */ /* 6.3.0 */
/* AUTHOR */ /* AUTHOR */
/* */ /* */
/* William E. Lamie, Microsoft Corporation */ /* William E. Lamie, Microsoft Corporation */
/* */ /* */
/* DESCRIPTION */ /* DESCRIPTION */
/* */
/* This function releases a logical sector from being managed in the */
/* NOR flash. */
/* */
/* INPUT */
/* */
/* nor_flash NOR flash instance */
/* logical_sector Logical sector number */
/* */
/* OUTPUT */
/* */
/* return status */
/* */
/* CALLS */
/* */
/* _lx_nor_flash_driver_write Driver flash sector write */
/* _lx_nor_flash_driver_read Driver flash sector read */
/* _lx_nor_flash_block_reclaim Reclaim one flash block */
/* _lx_nor_flash_sector_mapping_cache_invalidate */
/* Invalidate cache entry */
/* _lx_nor_flash_logical_sector_find Find logical sector */
/* _lx_nor_flash_system_error Internal system error handler */
/* tx_mutex_get Get thread protection */
/* tx_mutex_put Release thread protection */
/* */
/* CALLED BY */
/* */
/* Application Code */
/* */
/* RELEASE HISTORY */
/* */
/* DATE NAME DESCRIPTION */
/* */ /* */
/* 05-19-2020 William E. Lamie Initial Version 6.0 */ /* This function releases a logical sector from being managed in the */
/* 09-30-2020 William E. Lamie Modified comment(s), */ /* NOR flash. */
/* resulting in version 6.1 */ /* */
/* 06-02-2021 Bhupendra Naphade Modified comment(s), */ /* INPUT */
/* resulting in version 6.1.7 */ /* */
/* 10-31-2023 Xiuwen Cai Modified comment(s), */ /* nor_flash NOR flash instance */
/* added mapping bitmap cache, */ /* logical_sector Logical sector number */
/* added obsolete count cache, */ /* */
/* resulting in version 6.3.0 */ /* OUTPUT */
/* */
/* return status */
/* */
/* CALLS */
/* */
/* _lx_nor_flash_driver_write Driver flash sector write */
/* _lx_nor_flash_driver_read Driver flash sector read */
/* _lx_nor_flash_block_reclaim Reclaim one flash block */
/* _lx_nor_flash_sector_mapping_cache_invalidate */
/* Invalidate cache entry */
/* _lx_nor_flash_logical_sector_find Find logical sector */
/* _lx_nor_flash_system_error Internal system error handler */
/* tx_mutex_get Get thread protection */
/* tx_mutex_put Release thread protection */
/* */
/* CALLED BY */
/* */
/* Application Code */
/* */ /* */
/**************************************************************************/ /**************************************************************************/
UINT _lx_nor_flash_sector_release(LX_NOR_FLASH *nor_flash, ULONG logical_sector) UINT _lx_nor_flash_sector_release(LX_NOR_FLASH *nor_flash, ULONG logical_sector)
@@ -113,16 +100,16 @@ ULONG block;
/* See if we can find the sector in the current mapping. */ /* See if we can find the sector in the current mapping. */
_lx_nor_flash_logical_sector_find(nor_flash, logical_sector, LX_FALSE, &mapping_address, &sector_address); _lx_nor_flash_logical_sector_find(nor_flash, logical_sector, LX_FALSE, &mapping_address, &sector_address);
/* Determine if the logical sector was found. */ /* Determine if the logical sector was found. */
if (mapping_address) if (mapping_address)
{ {
/* Yes, we were able to find the logical sector. */ /* Yes, we were able to find the logical sector. */
/* Read in the old sector mapping. */ /* Read in the old sector mapping. */
#ifdef LX_DIRECT_READ #ifdef LX_DIRECT_READ
/* Read the word directly. */ /* Read the word directly. */
mapping_entry = *(mapping_address); mapping_entry = *(mapping_address);
#else #else
@@ -131,7 +118,7 @@ ULONG block;
/* Check for an error from flash driver. Drivers should never return an error.. */ /* Check for an error from flash driver. Drivers should never return an error.. */
if (status) if (status)
{ {
/* Call system error handler. */ /* Call system error handler. */
_lx_nor_flash_system_error(nor_flash, status); _lx_nor_flash_system_error(nor_flash, status);
@@ -149,14 +136,14 @@ ULONG block;
/* Mark this sector as invalid. */ /* Mark this sector as invalid. */
/* Now clear bits 31 and 30, which indicates this sector is now obsoleted. */ /* Now clear bits 31 and 30, which indicates this sector is now obsoleted. */
mapping_entry = mapping_entry & ~(((ULONG) LX_NOR_PHYSICAL_SECTOR_VALID) | ((ULONG) LX_NOR_PHYSICAL_SECTOR_SUPERCEDED)); mapping_entry = mapping_entry & ~(((ULONG) LX_NOR_PHYSICAL_SECTOR_VALID) | ((ULONG) LX_NOR_PHYSICAL_SECTOR_SUPERCEDED));
/* Write the value back to the flash to clear bits 31 & 30. */ /* Write the value back to the flash to clear bits 31 & 30. */
status = _lx_nor_flash_driver_write(nor_flash, mapping_address, &mapping_entry, 1); status = _lx_nor_flash_driver_write(nor_flash, mapping_address, &mapping_entry, 1);
/* Check for an error from flash driver. Drivers should never return an error.. */ /* Check for an error from flash driver. Drivers should never return an error.. */
if (status) if (status)
{ {
/* Call system error handler. */ /* Call system error handler. */
_lx_nor_flash_system_error(nor_flash, status); _lx_nor_flash_system_error(nor_flash, status);
@@ -190,7 +177,7 @@ ULONG block;
/* Get the block number from mapping address. */ /* Get the block number from mapping address. */
block = (ULONG)(mapping_address - nor_flash -> lx_nor_flash_base_address) / nor_flash -> lx_nor_flash_words_per_block; block = (ULONG)(mapping_address - nor_flash -> lx_nor_flash_base_address) / nor_flash -> lx_nor_flash_words_per_block;
/* Determine if this block is within the range of the obsolete count cache. */ /* Determine if this block is within the range of the obsolete count cache. */
if (block < nor_flash -> lx_nor_flash_extended_cache_obsolete_count_max_block) if (block < nor_flash -> lx_nor_flash_extended_cache_obsolete_count_max_block)
{ {
@@ -202,7 +189,7 @@ ULONG block;
/* Decrement the number of mapped physical sectors. */ /* Decrement the number of mapped physical sectors. */
nor_flash -> lx_nor_flash_mapped_physical_sectors--; nor_flash -> lx_nor_flash_mapped_physical_sectors--;
/* Ensure the sector mapping cache no longer has this sector. */ /* Ensure the sector mapping cache no longer has this sector. */
_lx_nor_flash_sector_mapping_cache_invalidate(nor_flash, logical_sector); _lx_nor_flash_sector_mapping_cache_invalidate(nor_flash, logical_sector);
@@ -210,7 +197,7 @@ ULONG block;
i = 0; i = 0;
while (nor_flash -> lx_nor_flash_free_physical_sectors <= nor_flash -> lx_nor_flash_physical_sectors_per_block) while (nor_flash -> lx_nor_flash_free_physical_sectors <= nor_flash -> lx_nor_flash_physical_sectors_per_block)
{ {
/* Attempt to reclaim one physical block. */ /* Attempt to reclaim one physical block. */
_lx_nor_flash_block_reclaim(nor_flash); _lx_nor_flash_block_reclaim(nor_flash);
@@ -219,8 +206,8 @@ ULONG block;
/* Have we exceeded the number of blocks in the system? */ /* Have we exceeded the number of blocks in the system? */
if (i >= nor_flash -> lx_nor_flash_total_blocks) if (i >= nor_flash -> lx_nor_flash_total_blocks)
{ {
/* Yes, break out of the loop. */ /* Yes, break out of the loop. */
break; break;
} }
@@ -235,7 +222,7 @@ ULONG block;
/* Could not find the logical sector. */ /* Could not find the logical sector. */
status = LX_SECTOR_NOT_FOUND; status = LX_SECTOR_NOT_FOUND;
} }
#ifdef LX_THREAD_SAFE_ENABLE #ifdef LX_THREAD_SAFE_ENABLE
/* Release the thread safe mutex. */ /* Release the thread safe mutex. */
+71 -84
View File
@@ -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 * This program and the accompanying materials are made available under the
* terms of the MIT License which is available at * terms of the MIT License which is available at
* https://opensource.org/licenses/MIT. * https://opensource.org/licenses/MIT.
* *
* SPDX-License-Identifier: MIT * SPDX-License-Identifier: MIT
**************************************************************************/ **************************************************************************/
/**************************************************************************/ /**************************************************************************/
/**************************************************************************/ /**************************************************************************/
/** */ /** */
/** LevelX Component */ /** LevelX Component */
/** */ /** */
/** NOR Flash */ /** NOR Flash */
/** */ /** */
@@ -34,62 +35,48 @@
#include "lx_api.h" #include "lx_api.h"
/**************************************************************************/ /**************************************************************************/
/* */ /* */
/* FUNCTION RELEASE */ /* FUNCTION RELEASE */
/* */ /* */
/* _lx_nor_flash_sector_write PORTABLE C */ /* _lx_nor_flash_sector_write PORTABLE C */
/* 6.3.0 */ /* 6.3.0 */
/* AUTHOR */ /* AUTHOR */
/* */ /* */
/* William E. Lamie, Microsoft Corporation */ /* William E. Lamie, Microsoft Corporation */
/* */ /* */
/* DESCRIPTION */ /* DESCRIPTION */
/* */
/* This function writes a logical sector to the NOR flash. */
/* */
/* INPUT */
/* */
/* nor_flash NOR flash instance */
/* logical_sector Logical sector number */
/* buffer Pointer to buffer to write */
/* (the size is 512 bytes) */
/* */
/* OUTPUT */
/* */
/* return status */
/* */
/* CALLS */
/* */
/* _lx_nor_flash_driver_write Driver flash sector write */
/* _lx_nor_flash_driver_read Driver flash sector read */
/* _lx_nor_flash_block_reclaim Reclaim one flash block */
/* _lx_nor_flash_logical_sector_find Find logical sector */
/* _lx_nor_flash_physical_sector_allocate */
/* Allocate new physical sector */
/* _lx_nor_flash_sector_mapping_cache_invalidate */
/* Invalidate cache entry */
/* _lx_nor_flash_system_error Internal system error handler */
/* tx_mutex_get Get thread protection */
/* tx_mutex_put Release thread protection */
/* */
/* CALLED BY */
/* */
/* Application Code */
/* */
/* RELEASE HISTORY */
/* */
/* DATE NAME DESCRIPTION */
/* */ /* */
/* 05-19-2020 William E. Lamie Initial Version 6.0 */ /* This function writes a logical sector to the NOR flash. */
/* 09-30-2020 William E. Lamie Modified comment(s), */ /* */
/* resulting in version 6.1 */ /* INPUT */
/* 06-02-2021 Bhupendra Naphade Modified comment(s), */ /* */
/* resulting in version 6.1.7 */ /* nor_flash NOR flash instance */
/* 10-31-2023 Xiuwen Cai Modified comment(s), */ /* logical_sector Logical sector number */
/* added mapping bitmap cache, */ /* buffer Pointer to buffer to write */
/* added obsolete count cache, */ /* (the size is 512 bytes) */
/* resulting in version 6.3.0 */ /* */
/* OUTPUT */
/* */
/* return status */
/* */
/* CALLS */
/* */
/* _lx_nor_flash_driver_write Driver flash sector write */
/* _lx_nor_flash_driver_read Driver flash sector read */
/* _lx_nor_flash_block_reclaim Reclaim one flash block */
/* _lx_nor_flash_logical_sector_find Find logical sector */
/* _lx_nor_flash_physical_sector_allocate */
/* Allocate new physical sector */
/* _lx_nor_flash_sector_mapping_cache_invalidate */
/* Invalidate cache entry */
/* _lx_nor_flash_system_error Internal system error handler */
/* tx_mutex_get Get thread protection */
/* tx_mutex_put Release thread protection */
/* */
/* CALLED BY */
/* */
/* Application Code */
/* */ /* */
/**************************************************************************/ /**************************************************************************/
UINT _lx_nor_flash_sector_write(LX_NOR_FLASH *nor_flash, ULONG logical_sector, VOID *buffer) UINT _lx_nor_flash_sector_write(LX_NOR_FLASH *nor_flash, ULONG logical_sector, VOID *buffer)
@@ -118,7 +105,7 @@ ULONG block;
i = 0; i = 0;
while (nor_flash -> lx_nor_flash_free_physical_sectors <= nor_flash -> lx_nor_flash_physical_sectors_per_block) while (nor_flash -> lx_nor_flash_free_physical_sectors <= nor_flash -> lx_nor_flash_physical_sectors_per_block)
{ {
/* Attempt to reclaim one physical block. */ /* Attempt to reclaim one physical block. */
_lx_nor_flash_block_reclaim(nor_flash); _lx_nor_flash_block_reclaim(nor_flash);
@@ -127,8 +114,8 @@ ULONG block;
/* Have we exceeded the number of blocks in the system? */ /* Have we exceeded the number of blocks in the system? */
if (i >= nor_flash -> lx_nor_flash_total_blocks) if (i >= nor_flash -> lx_nor_flash_total_blocks)
{ {
/* Yes, break out of the loop. */ /* Yes, break out of the loop. */
break; break;
} }
@@ -139,14 +126,14 @@ ULONG block;
/* See if we can find the sector in the current mapping. */ /* See if we can find the sector in the current mapping. */
_lx_nor_flash_logical_sector_find(nor_flash, logical_sector, LX_FALSE, &old_mapping_address, &old_sector_address); _lx_nor_flash_logical_sector_find(nor_flash, logical_sector, LX_FALSE, &old_mapping_address, &old_sector_address);
/* Allocate a new physical sector for this write. */ /* Allocate a new physical sector for this write. */
_lx_nor_flash_physical_sector_allocate(nor_flash, logical_sector, &new_mapping_address, &new_sector_address); _lx_nor_flash_physical_sector_allocate(nor_flash, logical_sector, &new_mapping_address, &new_sector_address);
/* Determine if the new sector allocation was successful. */ /* Determine if the new sector allocation was successful. */
if (new_mapping_address) if (new_mapping_address)
{ {
/* Yes, we were able to allocate a new physical sector. */ /* Yes, we were able to allocate a new physical sector. */
/* Update the number of free physical sectors. */ /* Update the number of free physical sectors. */
@@ -158,7 +145,7 @@ ULONG block;
/* Check for an error from flash driver. Drivers should never return an error.. */ /* Check for an error from flash driver. Drivers should never return an error.. */
if (status) if (status)
{ {
/* Call system error handler. */ /* Call system error handler. */
_lx_nor_flash_system_error(nor_flash, status); _lx_nor_flash_system_error(nor_flash, status);
@@ -177,10 +164,10 @@ ULONG block;
{ {
/* Now deprecate the old sector mapping. */ /* Now deprecate the old sector mapping. */
/* Read in the old sector mapping. */ /* Read in the old sector mapping. */
#ifdef LX_DIRECT_READ #ifdef LX_DIRECT_READ
/* Read the word directly. */ /* Read the word directly. */
old_mapping_entry = *(old_mapping_address); old_mapping_entry = *(old_mapping_address);
#else #else
@@ -189,7 +176,7 @@ ULONG block;
/* Check for an error from flash driver. Drivers should never return an error.. */ /* Check for an error from flash driver. Drivers should never return an error.. */
if (status) if (status)
{ {
/* Call system error handler. */ /* Call system error handler. */
_lx_nor_flash_system_error(nor_flash, status); _lx_nor_flash_system_error(nor_flash, status);
@@ -203,17 +190,17 @@ ULONG block;
return(LX_ERROR); return(LX_ERROR);
} }
#endif #endif
/* Clear bit 30, which indicates this sector is superceded. */ /* Clear bit 30, which indicates this sector is superceded. */
old_mapping_entry = old_mapping_entry & ~((ULONG) LX_NOR_PHYSICAL_SECTOR_SUPERCEDED); old_mapping_entry = old_mapping_entry & ~((ULONG) LX_NOR_PHYSICAL_SECTOR_SUPERCEDED);
/* Write the value back to the flash to clear bit 30. */ /* Write the value back to the flash to clear bit 30. */
status = _lx_nor_flash_driver_write(nor_flash, old_mapping_address, &old_mapping_entry, 1); status = _lx_nor_flash_driver_write(nor_flash, old_mapping_address, &old_mapping_entry, 1);
/* Check for an error from flash driver. Drivers should never return an error.. */ /* Check for an error from flash driver. Drivers should never return an error.. */
if (status) if (status)
{ {
/* Call system error handler. */ /* Call system error handler. */
_lx_nor_flash_system_error(nor_flash, status); _lx_nor_flash_system_error(nor_flash, status);
@@ -227,17 +214,17 @@ ULONG block;
return(LX_ERROR); return(LX_ERROR);
} }
} }
/* Now build the new mapping entry - with the not valid bit set initially. */ /* Now build the new mapping entry - with the not valid bit set initially. */
new_mapping_entry = ((ULONG) LX_NOR_PHYSICAL_SECTOR_VALID) | ((ULONG) LX_NOR_PHYSICAL_SECTOR_SUPERCEDED) | ((ULONG) LX_NOR_PHYSICAL_SECTOR_MAPPING_NOT_VALID) | logical_sector; new_mapping_entry = ((ULONG) LX_NOR_PHYSICAL_SECTOR_VALID) | ((ULONG) LX_NOR_PHYSICAL_SECTOR_SUPERCEDED) | ((ULONG) LX_NOR_PHYSICAL_SECTOR_MAPPING_NOT_VALID) | logical_sector;
/* Write out the new mapping entry. */ /* Write out the new mapping entry. */
status = _lx_nor_flash_driver_write(nor_flash, new_mapping_address, &new_mapping_entry, 1); status = _lx_nor_flash_driver_write(nor_flash, new_mapping_address, &new_mapping_entry, 1);
/* Check for an error from flash driver. Drivers should never return an error.. */ /* Check for an error from flash driver. Drivers should never return an error.. */
if (status) if (status)
{ {
/* Call system error handler. */ /* Call system error handler. */
_lx_nor_flash_system_error(nor_flash, status); _lx_nor_flash_system_error(nor_flash, status);
@@ -251,17 +238,17 @@ ULONG block;
return(LX_ERROR); return(LX_ERROR);
} }
/* Now clear the not valid bit to make this sector mapping valid. This is done because the writing of the extra bytes itself can /* Now clear the not valid bit to make this sector mapping valid. This is done because the writing of the extra bytes itself can
be interrupted and we need to make sure this can be detected when the flash is opened again. */ be interrupted and we need to make sure this can be detected when the flash is opened again. */
new_mapping_entry = new_mapping_entry & ~((ULONG) LX_NOR_PHYSICAL_SECTOR_MAPPING_NOT_VALID); new_mapping_entry = new_mapping_entry & ~((ULONG) LX_NOR_PHYSICAL_SECTOR_MAPPING_NOT_VALID);
/* Clear the not valid bit. */ /* Clear the not valid bit. */
status = _lx_nor_flash_driver_write(nor_flash, new_mapping_address, &new_mapping_entry, 1); status = _lx_nor_flash_driver_write(nor_flash, new_mapping_address, &new_mapping_entry, 1);
/* Check for an error from flash driver. Drivers should never return an error.. */ /* Check for an error from flash driver. Drivers should never return an error.. */
if (status) if (status)
{ {
/* Call system error handler. */ /* Call system error handler. */
_lx_nor_flash_system_error(nor_flash, status); _lx_nor_flash_system_error(nor_flash, status);
@@ -289,21 +276,21 @@ ULONG block;
/* Increment the number of mapped physical sectors. */ /* Increment the number of mapped physical sectors. */
nor_flash -> lx_nor_flash_mapped_physical_sectors++; nor_flash -> lx_nor_flash_mapped_physical_sectors++;
/* Was there a previously mapped sector? */ /* Was there a previously mapped sector? */
if (old_mapping_address) if (old_mapping_address)
{ {
/* Now clear bit 31, which indicates this sector is now obsoleted. */ /* Now clear bit 31, which indicates this sector is now obsoleted. */
old_mapping_entry = old_mapping_entry & ~((ULONG) LX_NOR_PHYSICAL_SECTOR_VALID); old_mapping_entry = old_mapping_entry & ~((ULONG) LX_NOR_PHYSICAL_SECTOR_VALID);
/* Write the value back to the flash to clear bit 31. */ /* Write the value back to the flash to clear bit 31. */
status = _lx_nor_flash_driver_write(nor_flash, old_mapping_address, &old_mapping_entry, 1); status = _lx_nor_flash_driver_write(nor_flash, old_mapping_address, &old_mapping_entry, 1);
/* Check for an error from flash driver. Drivers should never return an error.. */ /* Check for an error from flash driver. Drivers should never return an error.. */
if (status) if (status)
{ {
/* Call system error handler. */ /* Call system error handler. */
_lx_nor_flash_system_error(nor_flash, status); _lx_nor_flash_system_error(nor_flash, status);
@@ -336,7 +323,7 @@ ULONG block;
/* Decrement the number of mapped physical sectors. */ /* Decrement the number of mapped physical sectors. */
nor_flash -> lx_nor_flash_mapped_physical_sectors--; nor_flash -> lx_nor_flash_mapped_physical_sectors--;
/* Invalidate the old sector mapping cache entry. */ /* Invalidate the old sector mapping cache entry. */
_lx_nor_flash_sector_mapping_cache_invalidate(nor_flash, logical_sector); _lx_nor_flash_sector_mapping_cache_invalidate(nor_flash, logical_sector);
} }
@@ -344,9 +331,9 @@ ULONG block;
/* Determine if the sector mapping cache is enabled. */ /* Determine if the sector mapping cache is enabled. */
if (nor_flash -> lx_nor_flash_sector_mapping_cache_enabled) if (nor_flash -> lx_nor_flash_sector_mapping_cache_enabled)
{ {
/* Yes, sector mapping cache is enabled, place this sector information in the cache. */ /* Yes, sector mapping cache is enabled, place this sector information in the cache. */
/* Calculate the starting index of the sector mapping cache for this sector entry. */ /* Calculate the starting index of the sector mapping cache for this sector entry. */
i = (logical_sector & LX_NOR_SECTOR_MAPPING_CACHE_HASH_MASK) * LX_NOR_SECTOR_MAPPING_CACHE_DEPTH; i = (logical_sector & LX_NOR_SECTOR_MAPPING_CACHE_HASH_MASK) * LX_NOR_SECTOR_MAPPING_CACHE_DEPTH;
@@ -357,7 +344,7 @@ ULONG block;
*(sector_mapping_cache_entry_ptr + 3) = *(sector_mapping_cache_entry_ptr + 2); *(sector_mapping_cache_entry_ptr + 3) = *(sector_mapping_cache_entry_ptr + 2);
*(sector_mapping_cache_entry_ptr + 2) = *(sector_mapping_cache_entry_ptr + 1); *(sector_mapping_cache_entry_ptr + 2) = *(sector_mapping_cache_entry_ptr + 1);
*(sector_mapping_cache_entry_ptr + 1) = *(sector_mapping_cache_entry_ptr); *(sector_mapping_cache_entry_ptr + 1) = *(sector_mapping_cache_entry_ptr);
/* Setup the new sector information in the cache. */ /* Setup the new sector information in the cache. */
sector_mapping_cache_entry_ptr -> lx_nor_sector_mapping_cache_logical_sector = (logical_sector | LX_NOR_SECTOR_MAPPING_CACHE_ENTRY_VALID); sector_mapping_cache_entry_ptr -> lx_nor_sector_mapping_cache_logical_sector = (logical_sector | LX_NOR_SECTOR_MAPPING_CACHE_ENTRY_VALID);
sector_mapping_cache_entry_ptr -> lx_nor_sector_mapping_cache_physical_sector_map_entry = new_mapping_address; sector_mapping_cache_entry_ptr -> lx_nor_sector_mapping_cache_physical_sector_map_entry = new_mapping_address;
@@ -365,11 +352,11 @@ ULONG block;
} }
/* Indicate the write was successful. */ /* Indicate the write was successful. */
status = LX_SUCCESS; status = LX_SUCCESS;
} }
else else
{ {
/* Indicate the write was unsuccessful. */ /* Indicate the write was unsuccessful. */
status = LX_NO_SECTORS; status = LX_NO_SECTORS;
} }
+14 -13
View File
@@ -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 * This program and the accompanying materials are made available under the
* terms of the MIT License which is available at * terms of the MIT License which is available at
* https://opensource.org/licenses/MIT. * https://opensource.org/licenses/MIT.
* *
* SPDX-License-Identifier: MIT * SPDX-License-Identifier: MIT
**************************************************************************/ **************************************************************************/
/**************************************************************************/ /**************************************************************************/
/**************************************************************************/ /**************************************************************************/
/** */ /** */
/** LevelX Component */ /** LevelX Component */
/** */ /** */
/** NOR Flash Simulator */ /** NOR Flash Simulator */
/** */ /** */
@@ -134,7 +135,7 @@ UINT _lx_nor_flash_simulator_write(ULONG *flash_address, ULONG *source, ULONG w
/* Loop to write flash. */ /* Loop to write flash. */
while (words--) while (words--)
{ {
/* Copy word. */ /* Copy word. */
*flash_address++ = *source++; *flash_address++ = *source++;
} }
@@ -164,7 +165,7 @@ ULONG words;
words = sizeof(FLASH_BLOCK)/sizeof(ULONG); words = sizeof(FLASH_BLOCK)/sizeof(ULONG);
while (words--) while (words--)
{ {
/* Erase word of block. */ /* Erase word of block. */
*pointer++ = (ULONG) 0xFFFFFFFF; *pointer++ = (ULONG) 0xFFFFFFFF;
} }
@@ -187,7 +188,7 @@ ULONG words;
words = sizeof(nor_memory_area)/(sizeof(ULONG)); words = sizeof(nor_memory_area)/(sizeof(ULONG));
while (words--) while (words--)
{ {
/* Erase word of block. */ /* Erase word of block. */
*pointer++ = (ULONG) 0xFFFFFFFF; *pointer++ = (ULONG) 0xFFFFFFFF;
} }
@@ -211,22 +212,22 @@ ULONG words;
#endif #endif
/* Determine if the block is completely erased. */ /* Determine if the block is completely erased. */
/* Pickup the pointer to the first word of the block. */ /* Pickup the pointer to the first word of the block. */
word_ptr = (ULONG *) &nor_memory_area[block].erase_count; word_ptr = (ULONG *) &nor_memory_area[block].erase_count;
/* Calculate the number of words in a block. */ /* Calculate the number of words in a block. */
words = sizeof(FLASH_BLOCK)/sizeof(ULONG); words = sizeof(FLASH_BLOCK)/sizeof(ULONG);
/* Loop to check if the block is erased. */ /* Loop to check if the block is erased. */
while (words--) while (words--)
{ {
/* Is this word erased? */ /* Is this word erased? */
if (*word_ptr++ != 0xFFFFFFFF) if (*word_ptr++ != 0xFFFFFFFF)
return(LX_ERROR); return(LX_ERROR);
} }
/* Return success. */ /* Return success. */
return(LX_SUCCESS); return(LX_SUCCESS);
} }
+33 -45
View File
@@ -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 * This program and the accompanying materials are made available under the
* terms of the MIT License which is available at * terms of the MIT License which is available at
* https://opensource.org/licenses/MIT. * https://opensource.org/licenses/MIT.
* *
* SPDX-License-Identifier: MIT * SPDX-License-Identifier: MIT
**************************************************************************/ **************************************************************************/
/**************************************************************************/ /**************************************************************************/
/**************************************************************************/ /**************************************************************************/
/** */ /** */
/** LevelX Component */ /** LevelX Component */
/** */ /** */
/** NOR Flash */ /** NOR Flash */
/** */ /** */
@@ -34,49 +35,36 @@
#include "lx_api.h" #include "lx_api.h"
/**************************************************************************/ /**************************************************************************/
/* */ /* */
/* FUNCTION RELEASE */ /* FUNCTION RELEASE */
/* */ /* */
/* _lx_nor_flash_system_error PORTABLE C */ /* _lx_nor_flash_system_error PORTABLE C */
/* 6.2.1 */ /* 6.2.1 */
/* AUTHOR */ /* AUTHOR */
/* */ /* */
/* William E. Lamie, Microsoft Corporation */ /* William E. Lamie, Microsoft Corporation */
/* */ /* */
/* DESCRIPTION */ /* DESCRIPTION */
/* */
/* This function handles system errors in the NOR flash. */
/* */
/* INPUT */
/* */
/* nor_flash NOR flash instance */
/* error_code System error code */
/* */
/* OUTPUT */
/* */
/* None */
/* */
/* CALLS */
/* */
/* (lx_nor_flash_driver_system_error) Driver system error handler */
/* */
/* CALLED BY */
/* */
/* Internal LevelX */
/* */
/* RELEASE HISTORY */
/* */
/* DATE NAME DESCRIPTION */
/* */ /* */
/* 05-19-2020 William E. Lamie Initial Version 6.0 */ /* This function handles system errors in the NOR flash. */
/* 09-30-2020 William E. Lamie Modified comment(s), */ /* */
/* resulting in version 6.1 */ /* INPUT */
/* 06-02-2021 Bhupendra Naphade Modified comment(s), */ /* */
/* resulting in version 6.1.7 */ /* nor_flash NOR flash instance */
/* 03-08-2023 Xiuwen Cai Modified comment(s), */ /* error_code System error code */
/* added new driver interface, */ /* */
/* resulting in version 6.2.1 */ /* OUTPUT */
/* */
/* None */
/* */
/* CALLS */
/* */
/* (lx_nor_flash_driver_system_error) Driver system error handler */
/* */
/* CALLED BY */
/* */
/* Internal LevelX */
/* */ /* */
/**************************************************************************/ /**************************************************************************/
VOID _lx_nor_flash_system_error(LX_NOR_FLASH *nor_flash, UINT error_code) VOID _lx_nor_flash_system_error(LX_NOR_FLASH *nor_flash, UINT error_code)
@@ -84,14 +72,14 @@ VOID _lx_nor_flash_system_error(LX_NOR_FLASH *nor_flash, UINT error_code)
/* Increment the system error counter. */ /* Increment the system error counter. */
nor_flash -> lx_nor_flash_diagnostic_system_errors++; nor_flash -> lx_nor_flash_diagnostic_system_errors++;
/* Save the most recent system error code. */ /* Save the most recent system error code. */
nor_flash -> lx_nor_flash_diagnostic_system_error = error_code; nor_flash -> lx_nor_flash_diagnostic_system_error = error_code;
/* Determine if the driver has setup a system error handler. */ /* Determine if the driver has setup a system error handler. */
if (nor_flash -> lx_nor_flash_driver_system_error) if (nor_flash -> lx_nor_flash_driver_system_error)
{ {
/* Yes, call the driver's system error handler. */ /* Yes, call the driver's system error handler. */
#ifdef LX_NOR_ENABLE_CONTROL_BLOCK_FOR_DRIVER_INTERFACE #ifdef LX_NOR_ENABLE_CONTROL_BLOCK_FOR_DRIVER_INTERFACE
(nor_flash -> lx_nor_flash_driver_system_error)(nor_flash, error_code); (nor_flash -> lx_nor_flash_driver_system_error)(nor_flash, error_code);
+21 -21
View File
@@ -1,4 +1,4 @@
/* This is a small demo of the high-performance FileX FAT file system with LevelX /* This is a small demo of the high-performance FileX FAT file system with LevelX
and the NAND simulated driver. */ and the NAND simulated driver. */
#include <stdio.h> #include <stdio.h>
@@ -9,7 +9,7 @@
#define DEMO_STACK_SIZE 4096 #define DEMO_STACK_SIZE 4096
/* Buffer for FileX FX_MEDIA sector cache. This must be large enough for at least one /* Buffer for FileX FX_MEDIA sector cache. This must be large enough for at least one
sector, which are typically 512 bytes in size. */ sector, which are typically 512 bytes in size. */
unsigned char media_memory[4096]; unsigned char media_memory[4096];
@@ -23,8 +23,8 @@ VOID _fx_nand_flash_simulator_driver(FX_MEDIA *media_ptr);
/* Define LevelX NAND simulated flash erase. */ /* Define LevelX NAND simulated flash erase. */
UINT _lx_nand_flash_simulator_erase_all(VOID); UINT _lx_nand_flash_simulator_erase_all(VOID);
/* Define thread prototypes. */ /* Define thread prototypes. */
void thread_0_entry(ULONG thread_input); void thread_0_entry(ULONG thread_input);
@@ -54,8 +54,8 @@ int main(void)
#else #else
/* Initialize NAND flash. */ /* Initialize NAND flash. */
lx_nand_flash_initialize(); lx_nand_flash_initialize();
/* Initialize FileX. */ /* Initialize FileX. */
fx_system_initialize(); fx_system_initialize();
@@ -76,13 +76,13 @@ void tx_application_define(void *first_unused_memory)
create information. */ create information. */
/* Create the main thread. */ /* Create the main thread. */
tx_thread_create(&thread_0, "thread 0", thread_0_entry, 0, tx_thread_create(&thread_0, "thread 0", thread_0_entry, 0,
thread_0_stack, DEMO_STACK_SIZE, thread_0_stack, DEMO_STACK_SIZE,
1, 1, TX_NO_TIME_SLICE, TX_AUTO_START); 1, 1, TX_NO_TIME_SLICE, TX_AUTO_START);
/* Initialize NAND flash. */ /* Initialize NAND flash. */
lx_nand_flash_initialize(); lx_nand_flash_initialize();
/* Initialize FileX. */ /* Initialize FileX. */
fx_system_initialize(); fx_system_initialize();
} }
@@ -97,27 +97,27 @@ ULONG actual;
CHAR local_buffer[30]; CHAR local_buffer[30];
LX_PARAMETER_NOT_USED(thread_input); LX_PARAMETER_NOT_USED(thread_input);
/* Erase the simulated NAND flash. */ /* Erase the simulated NAND flash. */
_lx_nand_flash_simulator_erase_all(); _lx_nand_flash_simulator_erase_all();
/* Format the NAND disk - the memory for the NAND flash disk is setup in /* Format the NAND disk - the memory for the NAND flash disk is setup in
the NAND simulator. Note that for best performance, the format of the the NAND simulator. Note that for best performance, the format of the
NAND flash should be less than one full NAND flash block of sectors. */ NAND flash should be less than one full NAND flash block of sectors. */
fx_media_format(&nand_disk, fx_media_format(&nand_disk,
_fx_nand_flash_simulator_driver, // Driver entry _fx_nand_flash_simulator_driver, // Driver entry
FX_NULL, // Unused FX_NULL, // Unused
media_memory, // Media buffer pointer media_memory, // Media buffer pointer
sizeof(media_memory), // Media buffer size sizeof(media_memory), // Media buffer size
"MY_NAND_DISK", // Volume Name "MY_NAND_DISK", // Volume Name
1, // Number of FATs 1, // Number of FATs
32, // Directory Entries 32, // Directory Entries
0, // Hidden sectors 0, // Hidden sectors
120, // Total sectors 120, // Total sectors
2048, // Sector size 2048, // Sector size
1, // Sectors per cluster 1, // Sectors per cluster
1, // Heads 1, // Heads
1); // Sectors per track 1); // Sectors per track
/* Loop to repeat the demo over and over! */ /* Loop to repeat the demo over and over! */
do do
@@ -219,7 +219,7 @@ CHAR local_buffer[30];
/* Delete the file. */ /* Delete the file. */
status = fx_file_delete(&nand_disk, "TEST.TXT"); status = fx_file_delete(&nand_disk, "TEST.TXT");
/* Check the file delete status. */ /* Check the file delete status. */
if (status != FX_SUCCESS) if (status != FX_SUCCESS)
{ {
@@ -227,7 +227,7 @@ CHAR local_buffer[30];
/* Error deleting the file, break the loop. */ /* Error deleting the file, break the loop. */
break; break;
} }
/* Close the media. */ /* Close the media. */
status = fx_media_close(&nand_disk); status = fx_media_close(&nand_disk);
@@ -243,7 +243,7 @@ CHAR local_buffer[30];
of successful passes through this loop. */ of successful passes through this loop. */
thread_0_counter++; thread_0_counter++;
} while (1); } while (1);
/* If we get here the FileX test failed! */ /* If we get here the FileX test failed! */
return; return;
} }
+20 -20
View File
@@ -1,4 +1,4 @@
/* This is a small demo of the high-performance FileX FAT file system with LevelX /* This is a small demo of the high-performance FileX FAT file system with LevelX
and the NOR simulated driver. */ and the NOR simulated driver. */
#include "fx_api.h" #include "fx_api.h"
@@ -8,7 +8,7 @@
#define DEMO_STACK_SIZE 2048 #define DEMO_STACK_SIZE 2048
/* Buffer for FileX FX_MEDIA sector cache. This must be large enough for at least one /* Buffer for FileX FX_MEDIA sector cache. This must be large enough for at least one
sector, which are typically 512 bytes in size. */ sector, which are typically 512 bytes in size. */
unsigned char media_memory[512]; unsigned char media_memory[512];
@@ -22,8 +22,8 @@ VOID _fx_nor_flash_simulator_driver(FX_MEDIA *media_ptr);
/* Define LevelX NOR simulated flash erase. */ /* Define LevelX NOR simulated flash erase. */
UINT _lx_nor_flash_simulator_erase_all(VOID); UINT _lx_nor_flash_simulator_erase_all(VOID);
/* Define thread prototypes. */ /* Define thread prototypes. */
void thread_0_entry(ULONG thread_input); void thread_0_entry(ULONG thread_input);
@@ -53,8 +53,8 @@ int main(void)
#else #else
/* Initialize NOR flash. */ /* Initialize NOR flash. */
lx_nor_flash_initialize(); lx_nor_flash_initialize();
/* Initialize FileX. */ /* Initialize FileX. */
fx_system_initialize(); fx_system_initialize();
@@ -74,13 +74,13 @@ void tx_application_define(void *first_unused_memory)
create information. */ create information. */
/* Create the main thread. */ /* Create the main thread. */
tx_thread_create(&thread_0, "thread 0", thread_0_entry, 0, tx_thread_create(&thread_0, "thread 0", thread_0_entry, 0,
thread_0_stack, DEMO_STACK_SIZE, thread_0_stack, DEMO_STACK_SIZE,
1, 1, TX_NO_TIME_SLICE, TX_AUTO_START); 1, 1, TX_NO_TIME_SLICE, TX_AUTO_START);
/* Initialize NOR flash. */ /* Initialize NOR flash. */
lx_nor_flash_initialize(); lx_nor_flash_initialize();
/* Initialize FileX. */ /* Initialize FileX. */
fx_system_initialize(); fx_system_initialize();
} }
@@ -96,27 +96,27 @@ ULONG actual;
CHAR local_buffer[30]; CHAR local_buffer[30];
LX_PARAMETER_NOT_USED(thread_input); LX_PARAMETER_NOT_USED(thread_input);
/* Erase the simulated NOR flash. */ /* Erase the simulated NOR flash. */
_lx_nor_flash_simulator_erase_all(); _lx_nor_flash_simulator_erase_all();
/* Format the NOR disk - the memory for the NOR flash disk is setup in /* Format the NOR disk - the memory for the NOR flash disk is setup in
the NOR simulator. Note that for best performance, the format of the the NOR simulator. Note that for best performance, the format of the
NOR flash should be less than one full NOR flash block of sectors. */ NOR flash should be less than one full NOR flash block of sectors. */
fx_media_format(&nor_disk, fx_media_format(&nor_disk,
_fx_nor_flash_simulator_driver, // Driver entry _fx_nor_flash_simulator_driver, // Driver entry
FX_NULL, // Unused FX_NULL, // Unused
media_memory, // Media buffer pointer media_memory, // Media buffer pointer
sizeof(media_memory), // Media buffer size sizeof(media_memory), // Media buffer size
"MY_NOR_DISK", // Volume Name "MY_NOR_DISK", // Volume Name
1, // Number of FATs 1, // Number of FATs
32, // Directory Entries 32, // Directory Entries
0, // Hidden sectors 0, // Hidden sectors
120, // Total sectors 120, // Total sectors
512, // Sector size 512, // Sector size
1, // Sectors per cluster 1, // Sectors per cluster
1, // Heads 1, // Heads
1); // Sectors per track 1); // Sectors per track
/* Loop to repeat the demo over and over! */ /* Loop to repeat the demo over and over! */
do do
@@ -218,7 +218,7 @@ CHAR local_buffer[30];
/* Delete the file. */ /* Delete the file. */
status = fx_file_delete(&nor_disk, "TEST.TXT"); status = fx_file_delete(&nor_disk, "TEST.TXT");
/* Check the file delete status. */ /* Check the file delete status. */
if (status != FX_SUCCESS) if (status != FX_SUCCESS)
{ {
@@ -226,7 +226,7 @@ CHAR local_buffer[30];
/* Error deleting the file, break the loop. */ /* Error deleting the file, break the loop. */
break; break;
} }
/* Close the media. */ /* Close the media. */
status = fx_media_close(&nor_disk); status = fx_media_close(&nor_disk);
+171 -171
View File
@@ -64,7 +64,7 @@ INT CorrectPageECC(UCHAR *data, INT size, UCHAR *code);
int main() int main()
{ {
/* Enter the ThreadX kernel. */ /* Enter the ThreadX kernel. */
#ifndef LX_STANDALONE_ENABLE #ifndef LX_STANDALONE_ENABLE
tx_kernel_enter(); tx_kernel_enter();
@@ -82,8 +82,8 @@ void tx_application_define(void *first_unused_memory)
/* Create the main thread. */ /* Create the main thread. */
tx_thread_create(&thread_0, "thread 0", thread_0_entry, 0, tx_thread_create(&thread_0, "thread 0", thread_0_entry, 0,
thread_0_stack, DEMO_STACK_SIZE, thread_0_stack, DEMO_STACK_SIZE,
1, 1, TX_NO_TIME_SLICE, TX_AUTO_START); 1, 1, TX_NO_TIME_SLICE, TX_AUTO_START);
} }
#endif #endif
@@ -109,10 +109,10 @@ UINT status;
ULONG *word_ptr; ULONG *word_ptr;
UCHAR *byte_ptr; UCHAR *byte_ptr;
/* Erase the simulated NOR flash. */ /* Erase the simulated NOR flash. */
_lx_nand_flash_simulator_erase_all(); _lx_nand_flash_simulator_erase_all();
/* Initialize LevelX. */ /* Initialize LevelX. */
_lx_nand_flash_initialize(); _lx_nand_flash_initialize();
@@ -145,15 +145,15 @@ UCHAR *byte_ptr;
#ifdef EXTENDED_CACHE #ifdef EXTENDED_CACHE
lx_nand_flash_extended_cache_enable(&nand_sim_flash, cache_memory, sizeof(cache_memory)); lx_nand_flash_extended_cache_enable(&nand_sim_flash, cache_memory, sizeof(cache_memory));
#endif #endif
/* Write 520 sectors.... */ /* Write 520 sectors.... */
for (i = 0; i < 520; i++) for (i = 0; i < 520; i++)
{ {
for (j = 0; j < 512; j++) for (j = 0; j < 512; j++)
buffer[j] = i; buffer[j] = i;
status = lx_nand_flash_sector_write(&nand_sim_flash, i, buffer); status = lx_nand_flash_sector_write(&nand_sim_flash, i, buffer);
if (status != LX_SUCCESS) if (status != LX_SUCCESS)
{ {
printf("FAILED!\n"); printf("FAILED!\n");
@@ -165,7 +165,7 @@ UCHAR *byte_ptr;
} }
} }
} }
/* Close and reopen the flash. */ /* Close and reopen the flash. */
lx_nand_flash_close(&nand_sim_flash); lx_nand_flash_close(&nand_sim_flash);
@@ -187,9 +187,9 @@ UCHAR *byte_ptr;
/* Read back 520 sectors... */ /* Read back 520 sectors... */
for (i = 0; i < 520; i++) for (i = 0; i < 520; i++)
{ {
status = lx_nand_flash_sector_read(&nand_sim_flash, i, buffer); status = lx_nand_flash_sector_read(&nand_sim_flash, i, buffer);
if (status != LX_SUCCESS) if (status != LX_SUCCESS)
{ {
#ifdef BATCH_TEST #ifdef BATCH_TEST
@@ -200,10 +200,10 @@ UCHAR *byte_ptr;
{ {
} }
} }
for (j = 0; j < 128; j++) for (j = 0; j < 128; j++)
{ {
if (buffer[j] != i) if (buffer[j] != i)
{ {
printf("FAILED!\n"); printf("FAILED!\n");
@@ -222,11 +222,11 @@ UCHAR *byte_ptr;
/* Test 2: Write same sector 320 times. */ /* Test 2: Write same sector 320 times. */
printf("Test 2: Write same sector 320 times............."); printf("Test 2: Write same sector 320 times.............");
/* Reinitialize... */ /* Reinitialize... */
_lx_nand_flash_simulator_erase_all(); _lx_nand_flash_simulator_erase_all();
lx_nand_flash_initialize(); lx_nand_flash_initialize();
status = lx_nand_flash_format(&nand_sim_flash, "sim nand flash", _lx_nand_flash_simulator_initialize, nand_memory_space, sizeof(nand_memory_space)); status = lx_nand_flash_format(&nand_sim_flash, "sim nand flash", _lx_nand_flash_simulator_initialize, nand_memory_space, sizeof(nand_memory_space));
@@ -236,20 +236,20 @@ UCHAR *byte_ptr;
#ifdef EXTENDED_CACHE #ifdef EXTENDED_CACHE
lx_nand_flash_extended_cache_enable(&nand_sim_flash, cache_memory, sizeof(cache_memory)); lx_nand_flash_extended_cache_enable(&nand_sim_flash, cache_memory, sizeof(cache_memory));
#endif #endif
for (j = 0; j < 512; j++) for (j = 0; j < 512; j++)
buffer[j] = 0xFFFFFFFF; buffer[j] = 0xFFFFFFFF;
/* Write same sector 320 sectors.... */ /* Write same sector 320 sectors.... */
for (i = 0; i < 320; i++) for (i = 0; i < 320; i++)
{ {
for (j = 0; j < 512; j++) for (j = 0; j < 512; j++)
buffer[j] = i; buffer[j] = i;
if (i == 319) if (i == 319)
buffer[j-1]--; buffer[j-1]--;
status = lx_nand_flash_sector_write(&nand_sim_flash, 7, buffer); status = lx_nand_flash_sector_write(&nand_sim_flash, 7, buffer);
if (status != LX_SUCCESS) if (status != LX_SUCCESS)
{ {
printf("FAILED!\n"); printf("FAILED!\n");
@@ -260,9 +260,9 @@ UCHAR *byte_ptr;
{ {
} }
} }
status = lx_nand_flash_sector_read(&nand_sim_flash, 7, readbuffer); status = lx_nand_flash_sector_read(&nand_sim_flash, 7, readbuffer);
if (status != LX_SUCCESS) if (status != LX_SUCCESS)
{ {
printf("FAILED!\n"); printf("FAILED!\n");
@@ -273,10 +273,10 @@ UCHAR *byte_ptr;
{ {
} }
} }
for (j = 0; j < 128; j++) for (j = 0; j < 128; j++)
{ {
if (buffer[j] != readbuffer[j]) if (buffer[j] != readbuffer[j])
{ {
printf("FAILED!\n"); printf("FAILED!\n");
@@ -288,7 +288,7 @@ UCHAR *byte_ptr;
} }
} }
} }
/* Write other sectors just to have additional sectors to manage. */ /* Write other sectors just to have additional sectors to manage. */
if (i == 1) if (i == 1)
lx_nand_flash_sector_write(&nand_sim_flash, 1, buffer); lx_nand_flash_sector_write(&nand_sim_flash, 1, buffer);
@@ -310,7 +310,7 @@ UCHAR *byte_ptr;
status = lx_nand_flash_defragment(&nand_sim_flash); status = lx_nand_flash_defragment(&nand_sim_flash);
status = lx_nand_flash_sector_read(&nand_sim_flash, 7, readbuffer); status = lx_nand_flash_sector_read(&nand_sim_flash, 7, readbuffer);
if (status != LX_SUCCESS) if (status != LX_SUCCESS)
{ {
@@ -502,7 +502,7 @@ UCHAR *byte_ptr;
} }
status = lx_nand_flash_defragment(&nand_sim_flash); status = lx_nand_flash_defragment(&nand_sim_flash);
if (status != LX_NOT_SUPPORTED) if (status != LX_NOT_SUPPORTED)
{ {
printf("FAILED!\n"); printf("FAILED!\n");
@@ -513,9 +513,9 @@ UCHAR *byte_ptr;
{ {
} }
} }
status = lx_nand_flash_close(&nand_sim_flash); status = lx_nand_flash_close(&nand_sim_flash);
if (status != LX_SUCCESS) if (status != LX_SUCCESS)
{ {
printf("FAILED!\n"); printf("FAILED!\n");
@@ -527,7 +527,7 @@ UCHAR *byte_ptr;
} }
} }
printf("SUCCESS!\n"); printf("SUCCESS!\n");
printf("Test 3: Page copy test.........................."); printf("Test 3: Page copy test..........................");
/* Reinitialize... */ /* Reinitialize... */
@@ -612,9 +612,9 @@ UCHAR *byte_ptr;
{ {
} }
} }
status = lx_nand_flash_close(&nand_sim_flash); status = lx_nand_flash_close(&nand_sim_flash);
if (status != LX_SUCCESS) if (status != LX_SUCCESS)
{ {
printf("FAILED!\n"); printf("FAILED!\n");
@@ -760,7 +760,7 @@ UCHAR *byte_ptr;
while (sector_count--) while (sector_count--)
{ {
#ifdef FULL_SECTOR_DATA_VERIFY #ifdef FULL_SECTOR_DATA_VERIFY
LX_MEMSET((local_data_buffer + sector_number * SECTOR_SIZE), data_byte, SECTOR_SIZE); LX_MEMSET((local_data_buffer + sector_number * SECTOR_SIZE), data_byte, SECTOR_SIZE);
#else #else
@@ -816,25 +816,25 @@ UCHAR *byte_ptr;
#if 0 #if 0
/* Point at the simulated NOR flash memory. */ /* Point at the simulated NOR flash memory. */
word_ptr = nand_flash_memory; word_ptr = nand_flash_memory;
/* Test 3: Corrupt block 0, simulate a power interruption during erase of block 0, /* Test 3: Corrupt block 0, simulate a power interruption during erase of block 0,
after the erase, but before the erase count is setup. */ after the erase, but before the erase count is setup. */
printf("Test 3: Block erase-initialize interrupted......"); printf("Test 3: Block erase-initialize interrupted......");
word_ptr[0] = 0xFFFFFFFF; word_ptr[0] = 0xFFFFFFFF;
word_ptr[3] = 0x00000000; /* This simulates a non-erased block. */ word_ptr[3] = 0x00000000; /* This simulates a non-erased block. */
/* Open the flash and see if we recover properly. */ /* Open the flash and see if we recover properly. */
status = lx_nand_flash_open(&nand_sim_flash, "sim nor flash", _lx_nand_flash_simulator_initialize, nand_memory_space, sizeof(nand_memory_space)); status = lx_nand_flash_open(&nand_sim_flash, "sim nor flash", _lx_nand_flash_simulator_initialize, nand_memory_space, sizeof(nand_memory_space));
#ifdef EXTENDED_CACHE #ifdef EXTENDED_CACHE
status += lx_nand_flash_extended_cache_enable(&nand_sim_flash, cache_memory, sizeof(cache_memory)); status += lx_nand_flash_extended_cache_enable(&nand_sim_flash, cache_memory, sizeof(cache_memory));
#endif #endif
if ((status != LX_SUCCESS) || if ((status != LX_SUCCESS) ||
(nand_sim_flash.lx_nand_flash_free_pages != 111) || (nand_sim_flash.lx_nand_flash_free_pages != 111) ||
(nand_sim_flash.lx_nand_flash_mapped_pages != 9)) (nand_sim_flash.lx_nand_flash_mapped_pages != 9))
{ {
printf("FAILED!\n"); printf("FAILED!\n");
#ifdef BATCH_TEST #ifdef BATCH_TEST
exit(1); exit(1);
@@ -843,9 +843,9 @@ UCHAR *byte_ptr;
{ {
} }
} }
status = lx_nand_flash_close(&nand_sim_flash); status = lx_nand_flash_close(&nand_sim_flash);
if (status != LX_SUCCESS) if (status != LX_SUCCESS)
{ {
printf("FAILED!\n"); printf("FAILED!\n");
@@ -857,22 +857,22 @@ UCHAR *byte_ptr;
} }
} }
/* Corrupt block 0, simulate a power interruption after erase of block 0, /* Corrupt block 0, simulate a power interruption after erase of block 0,
but before erase count is setup. */ but before erase count is setup. */
word_ptr[0] = 0xFFFFFFFF; word_ptr[0] = 0xFFFFFFFF;
/* Open the flash and see if we recover properly. */ /* Open the flash and see if we recover properly. */
status = lx_nand_flash_open(&nand_sim_flash, "sim nor flash", _lx_nand_flash_simulator_initialize, nand_memory_space, sizeof(nand_memory_space)); status = lx_nand_flash_open(&nand_sim_flash, "sim nor flash", _lx_nand_flash_simulator_initialize, nand_memory_space, sizeof(nand_memory_space));
#ifdef EXTENDED_CACHE #ifdef EXTENDED_CACHE
status += lx_nand_flash_extended_cache_enable(&nand_sim_flash, cache_memory, sizeof(cache_memory)); status += lx_nand_flash_extended_cache_enable(&nand_sim_flash, cache_memory, sizeof(cache_memory));
#endif #endif
if ((status != LX_SUCCESS) || if ((status != LX_SUCCESS) ||
(nand_sim_flash.lx_nand_flash_free_pages != 111) || (nand_sim_flash.lx_nand_flash_free_pages != 111) ||
(nand_sim_flash.lx_nand_flash_mapped_pages != 9)) (nand_sim_flash.lx_nand_flash_mapped_pages != 9))
{ {
printf("FAILED!\n"); printf("FAILED!\n");
#ifdef BATCH_TEST #ifdef BATCH_TEST
exit(1); exit(1);
@@ -883,7 +883,7 @@ UCHAR *byte_ptr;
} }
status = lx_nand_flash_close(&nand_sim_flash); status = lx_nand_flash_close(&nand_sim_flash);
if (status != LX_SUCCESS) if (status != LX_SUCCESS)
{ {
printf("FAILED!\n"); printf("FAILED!\n");
@@ -899,23 +899,23 @@ UCHAR *byte_ptr;
/* Test 4: simulate a power interruption while a new page is being setup. */ /* Test 4: simulate a power interruption while a new page is being setup. */
printf("Test 4: Power interrupted new page setup........"); printf("Test 4: Power interrupted new page setup........");
/* Partially setup new page. */ /* Partially setup new page. */
byte_ptr = (UCHAR *) word_ptr; byte_ptr = (UCHAR *) word_ptr;
byte_ptr[2053] = 0xBF; /* Set block 0/page 0 extra bytes to indicate block not empty. */ byte_ptr[2053] = 0xBF; /* Set block 0/page 0 extra bytes to indicate block not empty. */
word_ptr[528] = 0x60; word_ptr[528] = 0x60;
/* Open the flash and see if we recover properly. We should mark this page as obsolete. */ /* Open the flash and see if we recover properly. We should mark this page as obsolete. */
status = lx_nand_flash_open(&nand_sim_flash, "sim nor flash", _lx_nand_flash_simulator_initialize, nand_memory_space, sizeof(nand_memory_space)); status = lx_nand_flash_open(&nand_sim_flash, "sim nor flash", _lx_nand_flash_simulator_initialize, nand_memory_space, sizeof(nand_memory_space));
#ifdef EXTENDED_CACHE #ifdef EXTENDED_CACHE
status += lx_nand_flash_extended_cache_enable(&nand_sim_flash, cache_memory, sizeof(cache_memory)); status += lx_nand_flash_extended_cache_enable(&nand_sim_flash, cache_memory, sizeof(cache_memory));
#endif #endif
if ((status != LX_SUCCESS) || if ((status != LX_SUCCESS) ||
(nand_sim_flash.lx_nand_flash_free_pages != 110) || (nand_sim_flash.lx_nand_flash_free_pages != 110) ||
(nand_sim_flash.lx_nand_flash_mapped_pages != 9)) (nand_sim_flash.lx_nand_flash_mapped_pages != 9))
{ {
printf("FAILED!\n"); printf("FAILED!\n");
#ifdef BATCH_TEST #ifdef BATCH_TEST
exit(1); exit(1);
@@ -924,9 +924,9 @@ UCHAR *byte_ptr;
{ {
} }
} }
status = lx_nand_flash_close(&nand_sim_flash); status = lx_nand_flash_close(&nand_sim_flash);
if (status != LX_SUCCESS) if (status != LX_SUCCESS)
{ {
printf("FAILED!\n"); printf("FAILED!\n");
@@ -942,28 +942,28 @@ UCHAR *byte_ptr;
/* Simulate a power interruption after a new sector is allocated, after data /* Simulate a power interruption after a new sector is allocated, after data
had been copied, and the superceeded bit is clear, but before the new entry can be had been copied, and the superceeded bit is clear, but before the new entry can be
setup. */ setup. */
/* Copy data block and reset spare. */ /* Copy data block and reset spare. */
byte_ptr[2053] = 0xBF; /* Set block 0/page 0 extra bytes to indicate block not empty. */ byte_ptr[2053] = 0xBF; /* Set block 0/page 0 extra bytes to indicate block not empty. */
for (i = 1; i < 512; i++) /* Fill block 0, page 1 data */ for (i = 1; i < 512; i++) /* Fill block 0, page 1 data */
word_ptr[i+528] = 0x60; word_ptr[i+528] = 0x60;
word_ptr[i+528] = 0xFFFFFFFF; /* Reset extra bytes for block 0, page 1 */ word_ptr[i+528] = 0xFFFFFFFF; /* Reset extra bytes for block 0, page 1 */
word_ptr[i+529] = 0xFFFFFFFF; /* Reset extra bytes for block 0, page 1 */ word_ptr[i+529] = 0xFFFFFFFF; /* Reset extra bytes for block 0, page 1 */
/* Set the superceded bit in block 1/page 1. */ /* Set the superceded bit in block 1/page 1. */
byte_ptr[37957] = 0x80; byte_ptr[37957] = 0x80;
/* Open the flash and see if we recover properly. */ /* Open the flash and see if we recover properly. */
status = lx_nand_flash_open(&nand_sim_flash, "sim nor flash", _lx_nand_flash_simulator_initialize, nand_memory_space, sizeof(nand_memory_space)); status = lx_nand_flash_open(&nand_sim_flash, "sim nor flash", _lx_nand_flash_simulator_initialize, nand_memory_space, sizeof(nand_memory_space));
#ifdef EXTENDED_CACHE #ifdef EXTENDED_CACHE
lx_nand_flash_extended_cache_enable(&nand_sim_flash, cache_memory, sizeof(cache_memory)); lx_nand_flash_extended_cache_enable(&nand_sim_flash, cache_memory, sizeof(cache_memory));
#endif #endif
if ((status != LX_SUCCESS) || if ((status != LX_SUCCESS) ||
(nand_sim_flash.lx_nand_flash_free_pages != 110) || (nand_sim_flash.lx_nand_flash_free_pages != 110) ||
(nand_sim_flash.lx_nand_flash_mapped_pages != 9)) (nand_sim_flash.lx_nand_flash_mapped_pages != 9))
{ {
printf("FAILED!\n"); printf("FAILED!\n");
#ifdef BATCH_TEST #ifdef BATCH_TEST
exit(1); exit(1);
@@ -980,10 +980,10 @@ UCHAR *byte_ptr;
has not been invalidated. */ has not been invalidated. */
byte_ptr[2053] = 0xBF; /* Set block 0/page 0 extra bytes to indicate block not empty. */ byte_ptr[2053] = 0xBF; /* Set block 0/page 0 extra bytes to indicate block not empty. */
for (i = 1; i < 512; i++) /* Fill block 0, page 1 data */ for (i = 1; i < 512; i++) /* Fill block 0, page 1 data */
word_ptr[i+528] = 0x60; word_ptr[i+528] = 0x60;
word_ptr[i+528] = 0xFFFFFFFF; /* Reset extra bytes for block 0, page 1 */ word_ptr[i+528] = 0xFFFFFFFF; /* Reset extra bytes for block 0, page 1 */
word_ptr[i+529] = 0xFFFFFFFF; /* Reset extra bytes for block 0, page 1 */ word_ptr[i+529] = 0xFFFFFFFF; /* Reset extra bytes for block 0, page 1 */
byte_ptr = (UCHAR *) word_ptr; byte_ptr = (UCHAR *) word_ptr;
/* set the spare info in the new page. */ /* set the spare info in the new page. */
@@ -995,17 +995,17 @@ UCHAR *byte_ptr;
/* Set the superceded bit in block 1/page 1. */ /* Set the superceded bit in block 1/page 1. */
byte_ptr[37957] = 0x80; byte_ptr[37957] = 0x80;
/* Open the flash and see if we recover properly. */ /* Open the flash and see if we recover properly. */
status = lx_nand_flash_open(&nand_sim_flash, "sim nor flash", _lx_nand_flash_simulator_initialize, nand_memory_space, sizeof(nand_memory_space)); status = lx_nand_flash_open(&nand_sim_flash, "sim nor flash", _lx_nand_flash_simulator_initialize, nand_memory_space, sizeof(nand_memory_space));
#ifdef EXTENDED_CACHE #ifdef EXTENDED_CACHE
status += lx_nand_flash_extended_cache_enable(&nand_sim_flash, cache_memory, sizeof(cache_memory)); status += lx_nand_flash_extended_cache_enable(&nand_sim_flash, cache_memory, sizeof(cache_memory));
#endif #endif
if ((status != LX_SUCCESS) || if ((status != LX_SUCCESS) ||
(nand_sim_flash.lx_nand_flash_free_pages != 110) || (nand_sim_flash.lx_nand_flash_free_pages != 110) ||
(nand_sim_flash.lx_nand_flash_mapped_pages != 9)) (nand_sim_flash.lx_nand_flash_mapped_pages != 9))
{ {
printf("FAILED!\n"); printf("FAILED!\n");
#ifdef BATCH_TEST #ifdef BATCH_TEST
exit(1); exit(1);
@@ -1206,7 +1206,7 @@ UCHAR *byte_ptr;
} }
status = lx_nand_flash_defragment(&nand_sim_flash); status = lx_nand_flash_defragment(&nand_sim_flash);
if (status != LX_NOT_SUPPORTED) if (status != LX_NOT_SUPPORTED)
{ {
printf("FAILED!\n"); printf("FAILED!\n");
@@ -1217,10 +1217,10 @@ UCHAR *byte_ptr;
{ {
} }
} }
status = lx_nand_flash_defragment(&nand_sim_flash); status = lx_nand_flash_defragment(&nand_sim_flash);
if (status != LX_NOT_SUPPORTED) if (status != LX_NOT_SUPPORTED)
{ {
printf("FAILED!\n"); printf("FAILED!\n");
@@ -1231,7 +1231,7 @@ UCHAR *byte_ptr;
{ {
} }
} }
status = lx_nand_flash_sector_read(&nand_sim_flash, 7, readbuffer); status = lx_nand_flash_sector_read(&nand_sim_flash, 7, readbuffer);
if (status != LX_SUCCESS) if (status != LX_SUCCESS)
{ {
@@ -1612,7 +1612,7 @@ UCHAR *byte_ptr;
{ {
} }
} }
status = lx_nand_flash_sector_release(&nand_sim_flash, 7); status = lx_nand_flash_sector_release(&nand_sim_flash, 7);
if (status != LX_SUCCESS) if (status != LX_SUCCESS)
{ {
@@ -1635,9 +1635,9 @@ UCHAR *byte_ptr;
{ {
} }
} }
status = lx_nand_flash_defragment(&nand_sim_flash); status = lx_nand_flash_defragment(&nand_sim_flash);
if (status != LX_SUCCESS) if (status != LX_SUCCESS)
{ {
printf("FAILED!\n"); printf("FAILED!\n");
@@ -1661,7 +1661,7 @@ UCHAR *byte_ptr;
{ {
} }
} }
printf("SUCCESS!\n"); printf("SUCCESS!\n");
#endif #endif
#if 0 #if 0
@@ -1670,15 +1670,15 @@ UCHAR *byte_ptr;
/* Erase the simulated NOR flash. */ /* Erase the simulated NOR flash. */
_lx_nand_flash_simulator_erase_all(); _lx_nand_flash_simulator_erase_all();
/* Open the flash. */ /* Open the flash. */
status = lx_nand_flash_open(&nand_sim_flash, "sim nor flash", _lx_nand_flash_simulator_initialize, nand_memory_space, sizeof(nand_memory_space)); status = lx_nand_flash_open(&nand_sim_flash, "sim nor flash", _lx_nand_flash_simulator_initialize, nand_memory_space, sizeof(nand_memory_space));
#ifdef EXTENDED_CACHE #ifdef EXTENDED_CACHE
status += lx_nand_flash_extended_cache_enable(&nand_sim_flash, cache_memory, sizeof(cache_memory)); status += lx_nand_flash_extended_cache_enable(&nand_sim_flash, cache_memory, sizeof(cache_memory));
#endif #endif
if (status != LX_SUCCESS) if (status != LX_SUCCESS)
{ {
printf("FAILED!\n"); printf("FAILED!\n");
#ifdef BATCH_TEST #ifdef BATCH_TEST
exit(1); exit(1);
@@ -1687,15 +1687,15 @@ UCHAR *byte_ptr;
{ {
} }
} }
/* Write 100 sectors.... */ /* Write 100 sectors.... */
for (i = 0; i < 100; i++) for (i = 0; i < 100; i++)
{ {
for (j = 0; j < 512; j++) for (j = 0; j < 512; j++)
buffer[j] = i; buffer[j] = i;
status = lx_nand_flash_sector_write(&nand_sim_flash, i, buffer); status = lx_nand_flash_sector_write(&nand_sim_flash, i, buffer);
if (status != LX_SUCCESS) if (status != LX_SUCCESS)
{ {
printf("FAILED!\n"); printf("FAILED!\n");
@@ -1707,13 +1707,13 @@ UCHAR *byte_ptr;
} }
} }
} }
/* Read back 100 sectors... */ /* Read back 100 sectors... */
for (i = 0; i < 100; i++) for (i = 0; i < 100; i++)
{ {
status = lx_nand_flash_sector_read(&nand_sim_flash, i, buffer); status = lx_nand_flash_sector_read(&nand_sim_flash, i, buffer);
if (status != LX_SUCCESS) if (status != LX_SUCCESS)
{ {
printf("FAILED!\n"); printf("FAILED!\n");
@@ -1724,10 +1724,10 @@ UCHAR *byte_ptr;
{ {
} }
} }
for (j = 0; j < 512; j++) for (j = 0; j < 512; j++)
{ {
if (buffer[j] != i) if (buffer[j] != i)
{ {
printf("FAILED!\n"); printf("FAILED!\n");
@@ -1740,18 +1740,18 @@ UCHAR *byte_ptr;
} }
} }
} }
/* Now, perform 1000 sector writes to randomly selected sectors, each time /* Now, perform 1000 sector writes to randomly selected sectors, each time
reading first to make sure the previous contents are valid. */ reading first to make sure the previous contents are valid. */
for (i = 0; i < 1000; i++) for (i = 0; i < 1000; i++)
{ {
/* Pickup random sector. */ /* Pickup random sector. */
sector = (rand() % 100); sector = (rand() % 100);
/* Read that sector. */ /* Read that sector. */
status = lx_nand_flash_sector_read(&nand_sim_flash, sector, buffer); status = lx_nand_flash_sector_read(&nand_sim_flash, sector, buffer);
if (status != LX_SUCCESS) if (status != LX_SUCCESS)
{ {
printf("FAILED!\n"); printf("FAILED!\n");
@@ -1762,10 +1762,10 @@ UCHAR *byte_ptr;
{ {
} }
} }
for (j = 0; j < 512; j++) for (j = 0; j < 512; j++)
{ {
if ((buffer[j] & 0x0000FFFF) != sector) if ((buffer[j] & 0x0000FFFF) != sector)
{ {
printf("FAILED!\n"); printf("FAILED!\n");
@@ -1781,10 +1781,10 @@ UCHAR *byte_ptr;
/* Include the itteraction in the buffer to generate a new write. */ /* Include the itteraction in the buffer to generate a new write. */
for (j = 0; j < 512; j++) for (j = 0; j < 512; j++)
{ {
buffer[j] = (buffer[j] & 0x0000FFFF) | (i << 16); buffer[j] = (buffer[j] & 0x0000FFFF) | (i << 16);
} }
status = lx_nand_flash_sector_write(&nand_sim_flash, sector, buffer); status = lx_nand_flash_sector_write(&nand_sim_flash, sector, buffer);
if (status != LX_SUCCESS) if (status != LX_SUCCESS)
@@ -1798,9 +1798,9 @@ UCHAR *byte_ptr;
} }
} }
} }
status = lx_nand_flash_close(&nand_sim_flash); status = lx_nand_flash_close(&nand_sim_flash);
if (status != LX_SUCCESS) if (status != LX_SUCCESS)
{ {
printf("FAILED!\n"); printf("FAILED!\n");
@@ -1813,22 +1813,22 @@ UCHAR *byte_ptr;
} }
printf("SUCCESS!\n"); printf("SUCCESS!\n");
#endif #endif
#if 0 #if 0
for (i = 0; i < 256; i++) for (i = 0; i < 256; i++)
{ {
/* Setup buffer. */ /* Setup buffer. */
for (j = 0; j < 2048; j++) for (j = 0; j < 2048; j++)
byte_buffer[j] = (UCHAR) (rand() % 256); byte_buffer[j] = (UCHAR) (rand() % 256);
/* Call the ECC calculate routine. */ /* Call the ECC calculate routine. */
ComputePageECC(byte_buffer, 2048, ecc_bytes); ComputePageECC(byte_buffer, 2048, ecc_bytes);
status = (UINT) CorrectPageECC(byte_buffer, 2048, ecc_bytes); status = (UINT) CorrectPageECC(byte_buffer, 2048, ecc_bytes);
if (status != 0) if (status != 0)
{ {
/* Check for corrected return value. */ /* Check for corrected return value. */
if (status != 1) if (status != 1)
{ {
@@ -1837,7 +1837,7 @@ UCHAR *byte_ptr;
} }
} }
} }
/* Call LevelX ECC routines to do the same thing. */ /* Call LevelX ECC routines to do the same thing. */
status = lx_nand_flash_page_ecc_compute(&nand_sim_flash, byte_buffer, lx_ecc_buffer); status = lx_nand_flash_page_ecc_compute(&nand_sim_flash, byte_buffer, lx_ecc_buffer);
@@ -1851,17 +1851,17 @@ UCHAR *byte_ptr;
// ComputePageECC(byte_buffer, 2048, ecc_bytes); // ComputePageECC(byte_buffer, 2048, ecc_bytes);
/* Determine if there is any difference between the original and the new ECC routine. */ /* Determine if there is any difference between the original and the new ECC routine. */
if ((ecc_bytes[0] != lx_ecc_buffer[0]) || if ((ecc_bytes[0] != lx_ecc_buffer[0]) ||
(ecc_bytes[1] != lx_ecc_buffer[1]) || (ecc_bytes[1] != lx_ecc_buffer[1]) ||
(ecc_bytes[2] != lx_ecc_buffer[2]) || (ecc_bytes[2] != lx_ecc_buffer[2]) ||
(ecc_bytes[3] != lx_ecc_buffer[3]) || (ecc_bytes[3] != lx_ecc_buffer[3]) ||
(ecc_bytes[4] != lx_ecc_buffer[4]) || (ecc_bytes[4] != lx_ecc_buffer[4]) ||
(ecc_bytes[5] != lx_ecc_buffer[5]) || (ecc_bytes[5] != lx_ecc_buffer[5]) ||
(ecc_bytes[6] != lx_ecc_buffer[6]) || (ecc_bytes[6] != lx_ecc_buffer[6]) ||
(ecc_bytes[7] != lx_ecc_buffer[7]) || (ecc_bytes[7] != lx_ecc_buffer[7]) ||
(ecc_bytes[8] != lx_ecc_buffer[8]) || (ecc_bytes[8] != lx_ecc_buffer[8]) ||
(ecc_bytes[9] != lx_ecc_buffer[9]) || (ecc_bytes[9] != lx_ecc_buffer[9]) ||
(ecc_bytes[10] != lx_ecc_buffer[10]) || (ecc_bytes[10] != lx_ecc_buffer[10]) ||
(ecc_bytes[11] != lx_ecc_buffer[11])) (ecc_bytes[11] != lx_ecc_buffer[11]))
@@ -1875,7 +1875,7 @@ UCHAR *byte_ptr;
if (status != LX_SUCCESS) if (status != LX_SUCCESS)
{ {
/* Is it the corrected status? */ /* Is it the corrected status? */
if (status != LX_NAND_ERROR_CORRECTED) if (status != LX_NAND_ERROR_CORRECTED)
{ {
@@ -1888,23 +1888,23 @@ UCHAR *byte_ptr;
} }
#endif #endif
#if 0 #if 0
for (i = 0; i < 256; i++) for (i = 0; i < 256; i++)
{ {
/* Setup buffer. */ /* Setup buffer. */
for (j = 0; j < 2048; j++) for (j = 0; j < 2048; j++)
byte_buffer[j] = (UCHAR) (rand() % 256); byte_buffer[j] = (UCHAR) (rand() % 256);
/* Call the ECC calculate routine. */ /* Call the ECC calculate routine. */
ComputePageECC(byte_buffer, 2048, ecc_bytes); ComputePageECC(byte_buffer, 2048, ecc_bytes);
/* Corrupt a bit in each 256 byte page. */ /* Corrupt a bit in each 256 byte page. */
if (byte_buffer[7] & 1) if (byte_buffer[7] & 1)
byte_buffer[7] = byte_buffer[7] & 0xFE; byte_buffer[7] = byte_buffer[7] & 0xFE;
else else
byte_buffer[7] = byte_buffer[7] | 1; byte_buffer[7] = byte_buffer[7] | 1;
if (byte_buffer[277] & 1) if (byte_buffer[277] & 1)
byte_buffer[277] = byte_buffer[277] & 0xFE; byte_buffer[277] = byte_buffer[277] & 0xFE;
else else
@@ -1914,12 +1914,12 @@ UCHAR *byte_ptr;
byte_buffer[577] = byte_buffer[577] & 0xFE; byte_buffer[577] = byte_buffer[577] & 0xFE;
else else
byte_buffer[577] = byte_buffer[577] | 1; byte_buffer[577] = byte_buffer[577] | 1;
if (byte_buffer[777] & 1) if (byte_buffer[777] & 1)
byte_buffer[777] = byte_buffer[777] & 0xFE; byte_buffer[777] = byte_buffer[777] & 0xFE;
else else
byte_buffer[777] = byte_buffer[777] | 1; byte_buffer[777] = byte_buffer[777] | 1;
if (byte_buffer[1077] & 1) if (byte_buffer[1077] & 1)
byte_buffer[1077] = byte_buffer[1077] & 0xFE; byte_buffer[1077] = byte_buffer[1077] & 0xFE;
else else
@@ -1929,7 +1929,7 @@ UCHAR *byte_ptr;
byte_buffer[1297] = byte_buffer[1297] & 0xFE; byte_buffer[1297] = byte_buffer[1297] & 0xFE;
else else
byte_buffer[1297] = byte_buffer[1297] | 1; byte_buffer[1297] = byte_buffer[1297] | 1;
if (byte_buffer[1636] & 1) if (byte_buffer[1636] & 1)
byte_buffer[1636] = byte_buffer[1636] & 0xFE; byte_buffer[1636] = byte_buffer[1636] & 0xFE;
else else
@@ -1939,12 +1939,12 @@ UCHAR *byte_ptr;
byte_buffer[1892] = byte_buffer[1892] & 0xFE; byte_buffer[1892] = byte_buffer[1892] & 0xFE;
else else
byte_buffer[1892] = byte_buffer[1892] | 1; byte_buffer[1892] = byte_buffer[1892] | 1;
status = (UINT) CorrectPageECC(byte_buffer, 2048, ecc_bytes); status = (UINT) CorrectPageECC(byte_buffer, 2048, ecc_bytes);
if (status != 0) if (status != 0)
{ {
/* Check for corrected return value. */ /* Check for corrected return value. */
if (status != 1) if (status != 1)
{ {
@@ -1953,7 +1953,7 @@ UCHAR *byte_ptr;
} }
} }
} }
/* Call LevelX ECC routines to do the same thing. */ /* Call LevelX ECC routines to do the same thing. */
status = lx_nand_flash_page_ecc_compute(&nand_sim_flash, byte_buffer, lx_ecc_buffer); status = lx_nand_flash_page_ecc_compute(&nand_sim_flash, byte_buffer, lx_ecc_buffer);
@@ -1966,17 +1966,17 @@ UCHAR *byte_ptr;
} }
/* Determine if there is any difference between the original and the new ECC routine. */ /* Determine if there is any difference between the original and the new ECC routine. */
if ((ecc_bytes[0] != lx_ecc_buffer[0]) || if ((ecc_bytes[0] != lx_ecc_buffer[0]) ||
(ecc_bytes[1] != lx_ecc_buffer[1]) || (ecc_bytes[1] != lx_ecc_buffer[1]) ||
(ecc_bytes[2] != lx_ecc_buffer[2]) || (ecc_bytes[2] != lx_ecc_buffer[2]) ||
(ecc_bytes[3] != lx_ecc_buffer[3]) || (ecc_bytes[3] != lx_ecc_buffer[3]) ||
(ecc_bytes[4] != lx_ecc_buffer[4]) || (ecc_bytes[4] != lx_ecc_buffer[4]) ||
(ecc_bytes[5] != lx_ecc_buffer[5]) || (ecc_bytes[5] != lx_ecc_buffer[5]) ||
(ecc_bytes[6] != lx_ecc_buffer[6]) || (ecc_bytes[6] != lx_ecc_buffer[6]) ||
(ecc_bytes[7] != lx_ecc_buffer[7]) || (ecc_bytes[7] != lx_ecc_buffer[7]) ||
(ecc_bytes[8] != lx_ecc_buffer[8]) || (ecc_bytes[8] != lx_ecc_buffer[8]) ||
(ecc_bytes[9] != lx_ecc_buffer[9]) || (ecc_bytes[9] != lx_ecc_buffer[9]) ||
(ecc_bytes[10] != lx_ecc_buffer[10]) || (ecc_bytes[10] != lx_ecc_buffer[10]) ||
(ecc_bytes[11] != lx_ecc_buffer[11])) (ecc_bytes[11] != lx_ecc_buffer[11]))
@@ -1991,7 +1991,7 @@ UCHAR *byte_ptr;
byte_buffer[7] = byte_buffer[7] & 0xFE; byte_buffer[7] = byte_buffer[7] & 0xFE;
else else
byte_buffer[7] = byte_buffer[7] | 1; byte_buffer[7] = byte_buffer[7] | 1;
if (byte_buffer[277] & 1) if (byte_buffer[277] & 1)
byte_buffer[277] = byte_buffer[277] & 0xFE; byte_buffer[277] = byte_buffer[277] & 0xFE;
else else
@@ -2001,12 +2001,12 @@ UCHAR *byte_ptr;
byte_buffer[577] = byte_buffer[577] & 0xFE; byte_buffer[577] = byte_buffer[577] & 0xFE;
else else
byte_buffer[577] = byte_buffer[577] | 1; byte_buffer[577] = byte_buffer[577] | 1;
if (byte_buffer[777] & 1) if (byte_buffer[777] & 1)
byte_buffer[777] = byte_buffer[777] & 0xFE; byte_buffer[777] = byte_buffer[777] & 0xFE;
else else
byte_buffer[777] = byte_buffer[777] | 1; byte_buffer[777] = byte_buffer[777] | 1;
if (byte_buffer[1077] & 1) if (byte_buffer[1077] & 1)
byte_buffer[1077] = byte_buffer[1077] & 0xFE; byte_buffer[1077] = byte_buffer[1077] & 0xFE;
else else
@@ -2016,7 +2016,7 @@ UCHAR *byte_ptr;
byte_buffer[1297] = byte_buffer[1297] & 0xFE; byte_buffer[1297] = byte_buffer[1297] & 0xFE;
else else
byte_buffer[1297] = byte_buffer[1297] | 1; byte_buffer[1297] = byte_buffer[1297] | 1;
if (byte_buffer[1636] & 1) if (byte_buffer[1636] & 1)
byte_buffer[1636] = byte_buffer[1636] & 0xFE; byte_buffer[1636] = byte_buffer[1636] & 0xFE;
else else
@@ -2026,12 +2026,12 @@ UCHAR *byte_ptr;
byte_buffer[1892] = byte_buffer[1892] & 0xFE; byte_buffer[1892] = byte_buffer[1892] & 0xFE;
else else
byte_buffer[1892] = byte_buffer[1892] | 1; byte_buffer[1892] = byte_buffer[1892] | 1;
status = lx_nand_flash_page_ecc_check(&nand_sim_flash, byte_buffer, lx_ecc_buffer); status = lx_nand_flash_page_ecc_check(&nand_sim_flash, byte_buffer, lx_ecc_buffer);
if (status != LX_SUCCESS) if (status != LX_SUCCESS)
{ {
/* Is it the corrected status? */ /* Is it the corrected status? */
if (status != LX_NAND_ERROR_CORRECTED) if (status != LX_NAND_ERROR_CORRECTED)
{ {
@@ -2064,22 +2064,22 @@ UCHAR *byte_ptr;
#endif #endif
#if 0 #if 0
/* Corrupting ECC code is detected and returns a failure... this test is not valid! */ /* Corrupting ECC code is detected and returns a failure... this test is not valid! */
for (i = 0; i < 256; i++) for (i = 0; i < 256; i++)
{ {
/* Setup buffer. */ /* Setup buffer. */
for (j = 0; j < 2048; j++) for (j = 0; j < 2048; j++)
byte_buffer[j] = (UCHAR) (rand() % 256); byte_buffer[j] = (UCHAR) (rand() % 256);
/* Call the ECC calculate routine. */ /* Call the ECC calculate routine. */
ComputePageECC(byte_buffer, 2048, ecc_bytes); ComputePageECC(byte_buffer, 2048, ecc_bytes);
/* Call LevelX ECC routines to do the same thing. */ /* Call LevelX ECC routines to do the same thing. */
status = lx_nand_flash_page_ecc_compute(&nand_sim_flash, byte_buffer, lx_ecc_buffer); status = lx_nand_flash_page_ecc_compute(&nand_sim_flash, byte_buffer, lx_ecc_buffer);
@@ -2092,15 +2092,15 @@ UCHAR *byte_ptr;
} }
/* Determine if there is any difference between the original and the new ECC routine. */ /* Determine if there is any difference between the original and the new ECC routine. */
if ((ecc_bytes[0] != lx_ecc_buffer[0]) || if ((ecc_bytes[0] != lx_ecc_buffer[0]) ||
(ecc_bytes[1] != lx_ecc_buffer[1]) || (ecc_bytes[1] != lx_ecc_buffer[1]) ||
(ecc_bytes[2] != lx_ecc_buffer[2]) || (ecc_bytes[2] != lx_ecc_buffer[2]) ||
(ecc_bytes[3] != lx_ecc_buffer[3]) || (ecc_bytes[3] != lx_ecc_buffer[3]) ||
(ecc_bytes[4] != lx_ecc_buffer[4]) || (ecc_bytes[4] != lx_ecc_buffer[4]) ||
(ecc_bytes[5] != lx_ecc_buffer[5]) || (ecc_bytes[5] != lx_ecc_buffer[5]) ||
(ecc_bytes[6] != lx_ecc_buffer[6]) || (ecc_bytes[6] != lx_ecc_buffer[6]) ||
(ecc_bytes[7] != lx_ecc_buffer[7]) || (ecc_bytes[7] != lx_ecc_buffer[7]) ||
(ecc_bytes[8] != lx_ecc_buffer[8]) || (ecc_bytes[8] != lx_ecc_buffer[8]) ||
(ecc_bytes[9] != lx_ecc_buffer[9]) || (ecc_bytes[9] != lx_ecc_buffer[9]) ||
(ecc_bytes[10] != lx_ecc_buffer[10]) || (ecc_bytes[10] != lx_ecc_buffer[10]) ||
(ecc_bytes[11] != lx_ecc_buffer[11])) (ecc_bytes[11] != lx_ecc_buffer[11]))
@@ -2115,7 +2115,7 @@ UCHAR *byte_ptr;
ecc_bytes[1] = ecc_bytes[1] & 0xFE; ecc_bytes[1] = ecc_bytes[1] & 0xFE;
else else
ecc_bytes[1] = ecc_bytes[1] | 1; ecc_bytes[1] = ecc_bytes[1] | 1;
if (ecc_bytes[4] & 1) if (ecc_bytes[4] & 1)
ecc_bytes[4] = ecc_bytes[4] & 0xFE; ecc_bytes[4] = ecc_bytes[4] & 0xFE;
else else
@@ -2125,12 +2125,12 @@ UCHAR *byte_ptr;
ecc_bytes[7] = ecc_bytes[7] & 0xFE; ecc_bytes[7] = ecc_bytes[7] & 0xFE;
else else
ecc_bytes[7] = ecc_bytes[7] | 1; ecc_bytes[7] = ecc_bytes[7] | 1;
if (ecc_bytes[10] & 1) if (ecc_bytes[10] & 1)
ecc_bytes[10] = ecc_bytes[10] & 0xFE; ecc_bytes[10] = ecc_bytes[10] & 0xFE;
else else
ecc_bytes[10] = ecc_bytes[10] | 1; ecc_bytes[10] = ecc_bytes[10] | 1;
if (ecc_bytes[13] & 1) if (ecc_bytes[13] & 1)
ecc_bytes[13] = ecc_bytes[13] & 0xFE; ecc_bytes[13] = ecc_bytes[13] & 0xFE;
else else
@@ -2140,7 +2140,7 @@ UCHAR *byte_ptr;
ecc_bytes[16] = ecc_bytes[16] & 0xFE; ecc_bytes[16] = ecc_bytes[16] & 0xFE;
else else
ecc_bytes[16] = ecc_bytes[16] | 1; ecc_bytes[16] = ecc_bytes[16] | 1;
if (ecc_bytes[19] & 1) if (ecc_bytes[19] & 1)
ecc_bytes[19] = ecc_bytes[19] & 0xFE; ecc_bytes[19] = ecc_bytes[19] & 0xFE;
else else
@@ -2150,12 +2150,12 @@ UCHAR *byte_ptr;
ecc_bytes[22] = ecc_bytes[22] & 0xFE; ecc_bytes[22] = ecc_bytes[22] & 0xFE;
else else
ecc_bytes[22] = ecc_bytes[22] | 1; ecc_bytes[22] = ecc_bytes[22] | 1;
status = (UINT) CorrectPageECC(byte_buffer, 2048, ecc_bytes); status = (UINT) CorrectPageECC(byte_buffer, 2048, ecc_bytes);
if (status != 0) if (status != 0)
{ {
/* Check for corrected return value. */ /* Check for corrected return value. */
if (status != 1) if (status != 1)
{ {
@@ -2170,7 +2170,7 @@ UCHAR *byte_ptr;
lx_ecc_buffer[1] = lx_ecc_buffer[1] & 0xFE; lx_ecc_buffer[1] = lx_ecc_buffer[1] & 0xFE;
else else
lx_ecc_buffer[1] = lx_ecc_buffer[1] | 1; lx_ecc_buffer[1] = lx_ecc_buffer[1] | 1;
if (lx_ecc_buffer[4] & 1) if (lx_ecc_buffer[4] & 1)
lx_ecc_buffer[4] = lx_ecc_buffer[4] & 0xFE; lx_ecc_buffer[4] = lx_ecc_buffer[4] & 0xFE;
else else
@@ -2180,12 +2180,12 @@ UCHAR *byte_ptr;
lx_ecc_buffer[7] = lx_ecc_buffer[7] & 0xFE; lx_ecc_buffer[7] = lx_ecc_buffer[7] & 0xFE;
else else
lx_ecc_buffer[7] = lx_ecc_buffer[7] | 1; lx_ecc_buffer[7] = lx_ecc_buffer[7] | 1;
if (lx_ecc_buffer[10] & 1) if (lx_ecc_buffer[10] & 1)
lx_ecc_buffer[10] = lx_ecc_buffer[10] & 0xFE; lx_ecc_buffer[10] = lx_ecc_buffer[10] & 0xFE;
else else
lx_ecc_buffer[10] = lx_ecc_buffer[10] | 1; lx_ecc_buffer[10] = lx_ecc_buffer[10] | 1;
if (lx_ecc_buffer[13] & 1) if (lx_ecc_buffer[13] & 1)
lx_ecc_buffer[13] = lx_ecc_buffer[13] & 0xFE; lx_ecc_buffer[13] = lx_ecc_buffer[13] & 0xFE;
else else
@@ -2195,7 +2195,7 @@ UCHAR *byte_ptr;
lx_ecc_buffer[16] = lx_ecc_buffer[16] & 0xFE; lx_ecc_buffer[16] = lx_ecc_buffer[16] & 0xFE;
else else
lx_ecc_buffer[16] = lx_ecc_buffer[16] | 1; lx_ecc_buffer[16] = lx_ecc_buffer[16] | 1;
if (lx_ecc_buffer[19] & 1) if (lx_ecc_buffer[19] & 1)
lx_ecc_buffer[19] = lx_ecc_buffer[19] & 0xFE; lx_ecc_buffer[19] = lx_ecc_buffer[19] & 0xFE;
else else
@@ -2205,14 +2205,14 @@ UCHAR *byte_ptr;
lx_ecc_buffer[22] = lx_ecc_buffer[22] & 0xFE; lx_ecc_buffer[22] = lx_ecc_buffer[22] & 0xFE;
else else
lx_ecc_buffer[22] = lx_ecc_buffer[22] | 1; lx_ecc_buffer[22] = lx_ecc_buffer[22] | 1;
status = lx_nand_flash_page_ecc_check(&nand_sim_flash, byte_buffer, lx_ecc_buffer); status = lx_nand_flash_page_ecc_check(&nand_sim_flash, byte_buffer, lx_ecc_buffer);
if (status != LX_SUCCESS) if (status != LX_SUCCESS)
{ {
/* Is it the corrected status? */ /* Is it the corrected status? */
if (status != LX_NAND_ERROR_CORRECTED) if (status != LX_NAND_ERROR_CORRECTED)
{ {
@@ -2245,24 +2245,24 @@ UCHAR *byte_ptr;
#endif #endif
#if 0 #if 0
/* TEST FileX packing routines. */ /* TEST FileX packing routines. */
/* Erase the simulated NAND flash. */ /* Erase the simulated NAND flash. */
_lx_nand_flash_simulator_erase_all(); _lx_nand_flash_simulator_erase_all();
/* Open the flash. */ /* Open the flash. */
status = lx_nand_flash_open(&nand_sim_flash, "sim nor flash", _lx_nand_flash_simulator_initialize); status = lx_nand_flash_open(&nand_sim_flash, "sim nor flash", _lx_nand_flash_simulator_initialize);
#ifdef EXTENDED_CACHE #ifdef EXTENDED_CACHE
status += lx_nand_flash_extended_cache_enable(&nand_sim_flash, cache_memory, sizeof(cache_memory)); status += lx_nand_flash_extended_cache_enable(&nand_sim_flash, cache_memory, sizeof(cache_memory));
#endif #endif
if (status != LX_SUCCESS) if (status != LX_SUCCESS)
{ {
printf("FAILED!\n"); printf("FAILED!\n");
while(1) while(1)
{ {
@@ -2294,7 +2294,7 @@ UCHAR *byte_ptr;
{ {
_fx_nand_flash_read_sectors(i, 1, (UCHAR *) &test_read[i].words[0]); _fx_nand_flash_read_sectors(i, 1, (UCHAR *) &test_read[i].words[0]);
} }
/* Setup the read buffer. */ /* Setup the read buffer. */
for (i = 0; i < 8; i++) for (i = 0; i < 8; i++)
{ {
@@ -2315,9 +2315,9 @@ UCHAR *byte_ptr;
_fx_nand_flash_read_sectors(0, 8, (UCHAR *) &test_read[0].words[0]); _fx_nand_flash_read_sectors(0, 8, (UCHAR *) &test_read[0].words[0]);
status = lx_nand_flash_close(&nand_sim_flash); status = lx_nand_flash_close(&nand_sim_flash);
if (status != LX_SUCCESS) if (status != LX_SUCCESS)
{ {
printf("FAILED!\n"); printf("FAILED!\n");
@@ -2329,15 +2329,15 @@ UCHAR *byte_ptr;
/* Erase the simulated NAND flash. */ /* Erase the simulated NAND flash. */
_lx_nand_flash_simulator_erase_all(); _lx_nand_flash_simulator_erase_all();
/* Open the flash. */ /* Open the flash. */
status = lx_nand_flash_open(&nand_sim_flash, "sim nor flash", _lx_nand_flash_simulator_initialize); status = lx_nand_flash_open(&nand_sim_flash, "sim nor flash", _lx_nand_flash_simulator_initialize);
#ifdef EXTENDED_CACHE #ifdef EXTENDED_CACHE
status += lx_nand_flash_extended_cache_enable(&nand_sim_flash, cache_memory, sizeof(cache_memory)); status += lx_nand_flash_extended_cache_enable(&nand_sim_flash, cache_memory, sizeof(cache_memory));
#endif #endif
if (status != LX_SUCCESS) if (status != LX_SUCCESS)
{ {
printf("FAILED!\n"); printf("FAILED!\n");
while(1) while(1)
{ {
@@ -2360,7 +2360,7 @@ UCHAR *byte_ptr;
_fx_nand_flash_read_sectors(3, 5, (UCHAR *) &test_read[3].words[0]); _fx_nand_flash_read_sectors(3, 5, (UCHAR *) &test_read[3].words[0]);
status = lx_nand_flash_close(&nand_sim_flash); status = lx_nand_flash_close(&nand_sim_flash);
if (status != LX_SUCCESS) if (status != LX_SUCCESS)
{ {
printf("FAILED!\n"); printf("FAILED!\n");
@@ -2369,9 +2369,9 @@ UCHAR *byte_ptr;
} }
} }
/* End */ /* End */
#endif #endif
#ifdef BATCH_TEST #ifdef BATCH_TEST
exit(0); exit(0);
#endif #endif
+86 -86
View File
@@ -35,7 +35,7 @@ void thread_0_entry(ULONG thread_input);
int main() int main()
{ {
/* Enter the ThreadX kernel. */ /* Enter the ThreadX kernel. */
#ifndef LX_STANDALONE_ENABLE #ifndef LX_STANDALONE_ENABLE
tx_kernel_enter(); tx_kernel_enter();
@@ -52,8 +52,8 @@ void tx_application_define(void *first_unused_memory)
/* Create the main thread. */ /* Create the main thread. */
tx_thread_create(&thread_0, "thread 0", thread_0_entry, 0, tx_thread_create(&thread_0, "thread 0", thread_0_entry, 0,
thread_0_stack, DEMO_STACK_SIZE, thread_0_stack, DEMO_STACK_SIZE,
1, 1, TX_NO_TIME_SLICE, TX_AUTO_START); 1, 1, TX_NO_TIME_SLICE, TX_AUTO_START);
} }
#endif #endif
@@ -68,27 +68,27 @@ UINT status;
ULONG *word_ptr; ULONG *word_ptr;
/* format the simulated NOR flash. */ /* format the simulated NOR flash. */
/* Initialize LevelX. */ /* Initialize LevelX. */
_lx_nor_flash_initialize(); _lx_nor_flash_initialize();
lx_nor_flash_format(&nor_sim_flash, "sim nor flash", _lx_nor_flash_simulator_initialize, NULL); lx_nor_flash_format(&nor_sim_flash, "sim nor flash", _lx_nor_flash_simulator_initialize, NULL);
/* Test 1: Simple write 100 sectors and read 100 sectors. */ /* Test 1: Simple write 100 sectors and read 100 sectors. */
printf("Test 1: Simple write-read 100 sectors..........."); printf("Test 1: Simple write-read 100 sectors...........");
lx_nor_flash_open(&nor_sim_flash, "sim nor flash", _lx_nor_flash_simulator_initialize); lx_nor_flash_open(&nor_sim_flash, "sim nor flash", _lx_nor_flash_simulator_initialize);
/* Write 100 sectors.... */ /* Write 100 sectors.... */
for (i = 0; i < 100; i++) for (i = 0; i < 100; i++)
{ {
for (j = 0; j < 128; j++) for (j = 0; j < 128; j++)
buffer[j] = i; buffer[j] = i;
status = lx_nor_flash_sector_write(&nor_sim_flash, i, buffer); status = lx_nor_flash_sector_write(&nor_sim_flash, i, buffer);
if (status != LX_SUCCESS) if (status != LX_SUCCESS)
{ {
printf("FAILED!\n"); printf("FAILED!\n");
@@ -100,13 +100,13 @@ ULONG *word_ptr;
} }
} }
} }
/* Read back 100 sectors... */ /* Read back 100 sectors... */
for (i = 0; i < 100; i++) for (i = 0; i < 100; i++)
{ {
status = lx_nor_flash_sector_read(&nor_sim_flash, i, buffer); status = lx_nor_flash_sector_read(&nor_sim_flash, i, buffer);
if (status != LX_SUCCESS) if (status != LX_SUCCESS)
{ {
printf("FAILED!\n"); printf("FAILED!\n");
@@ -117,10 +117,10 @@ ULONG *word_ptr;
{ {
} }
} }
for (j = 0; j < 128; j++) for (j = 0; j < 128; j++)
{ {
if (buffer[j] != i) if (buffer[j] != i)
{ {
printf("FAILED!\n"); printf("FAILED!\n");
@@ -139,9 +139,9 @@ ULONG *word_ptr;
/* Test 2: Write same sector 120 times. */ /* Test 2: Write same sector 120 times. */
printf("Test 2: Write same sector 120 times............."); printf("Test 2: Write same sector 120 times.............");
/* Reinitialize... */ /* Reinitialize... */
lx_nor_flash_initialize(); lx_nor_flash_initialize();
lx_nor_flash_format(&nor_sim_flash, "sim nor flash", _lx_nor_flash_simulator_initialize, NULL); lx_nor_flash_format(&nor_sim_flash, "sim nor flash", _lx_nor_flash_simulator_initialize, NULL);
@@ -149,15 +149,15 @@ ULONG *word_ptr;
for (j = 0; j < 128; j++) for (j = 0; j < 128; j++)
buffer[j] = 0xFFFFFFFF; buffer[j] = 0xFFFFFFFF;
/* Write same sector 120 sectors.... */ /* Write same sector 120 sectors.... */
for (i = 0; i < 120; i++) for (i = 0; i < 120; i++)
{ {
for (j = 0; j < 128; j++) for (j = 0; j < 128; j++)
buffer[j] = i; buffer[j] = i;
status = lx_nor_flash_sector_write(&nor_sim_flash, 7, buffer); status = lx_nor_flash_sector_write(&nor_sim_flash, 7, buffer);
if (status != LX_SUCCESS) if (status != LX_SUCCESS)
{ {
printf("FAILED!\n"); printf("FAILED!\n");
@@ -168,9 +168,9 @@ ULONG *word_ptr;
{ {
} }
} }
status = lx_nor_flash_sector_read(&nor_sim_flash, 7, readbuffer); status = lx_nor_flash_sector_read(&nor_sim_flash, 7, readbuffer);
if (status != LX_SUCCESS) if (status != LX_SUCCESS)
{ {
printf("FAILED!\n"); printf("FAILED!\n");
@@ -181,10 +181,10 @@ ULONG *word_ptr;
{ {
} }
} }
for (j = 0; j < 128; j++) for (j = 0; j < 128; j++)
{ {
if (buffer[j] != readbuffer[j]) if (buffer[j] != readbuffer[j])
{ {
printf("FAILED!\n"); printf("FAILED!\n");
@@ -196,7 +196,7 @@ ULONG *word_ptr;
} }
} }
} }
/* Write other sectors just to have additional sectors to manage. */ /* Write other sectors just to have additional sectors to manage. */
if (i == 1) if (i == 1)
lx_nor_flash_sector_write(&nor_sim_flash, 1, buffer); lx_nor_flash_sector_write(&nor_sim_flash, 1, buffer);
@@ -218,7 +218,7 @@ ULONG *word_ptr;
status = lx_nor_flash_defragment(&nor_sim_flash); status = lx_nor_flash_defragment(&nor_sim_flash);
status = lx_nor_flash_sector_read(&nor_sim_flash, 7, readbuffer); status = lx_nor_flash_sector_read(&nor_sim_flash, 7, readbuffer);
if (status != LX_SUCCESS) if (status != LX_SUCCESS)
{ {
@@ -410,7 +410,7 @@ ULONG *word_ptr;
} }
status = lx_nor_flash_defragment(&nor_sim_flash); status = lx_nor_flash_defragment(&nor_sim_flash);
if (status != LX_SUCCESS) if (status != LX_SUCCESS)
{ {
printf("FAILED!\n"); printf("FAILED!\n");
@@ -421,13 +421,13 @@ ULONG *word_ptr;
{ {
} }
} }
/* Point at the simulated NOR flash memory. */ /* Point at the simulated NOR flash memory. */
word_ptr = nor_sim_flash.lx_nor_flash_base_address; word_ptr = nor_sim_flash.lx_nor_flash_base_address;
status = lx_nor_flash_close(&nor_sim_flash); status = lx_nor_flash_close(&nor_sim_flash);
if (status != LX_SUCCESS) if (status != LX_SUCCESS)
{ {
printf("FAILED!\n"); printf("FAILED!\n");
@@ -439,21 +439,21 @@ ULONG *word_ptr;
} }
} }
printf("SUCCESS!\n"); printf("SUCCESS!\n");
/* Test 3: Corrupt block 0, simulate a power interruption during erase of block 0, /* Test 3: Corrupt block 0, simulate a power interruption during erase of block 0,
after the erase, but before the free bit map and erase count is setup. */ after the erase, but before the free bit map and erase count is setup. */
printf("Test 3: Block erase-initialize interrupted......"); printf("Test 3: Block erase-initialize interrupted......");
word_ptr[0] = 0xFFFFFFFF; word_ptr[0] = 0xFFFFFFFF;
word_ptr[3] = 0xFFFFFFFF; word_ptr[3] = 0xFFFFFFFF;
/* Open the flash and see if we recover properly. */ /* Open the flash and see if we recover properly. */
status = lx_nor_flash_open(&nor_sim_flash, "sim nor flash", _lx_nor_flash_simulator_initialize); status = lx_nor_flash_open(&nor_sim_flash, "sim nor flash", _lx_nor_flash_simulator_initialize);
if ((status != LX_SUCCESS) || if ((status != LX_SUCCESS) ||
(nor_sim_flash.lx_nor_flash_free_physical_sectors != 111) || (nor_sim_flash.lx_nor_flash_free_physical_sectors != 111) ||
(nor_sim_flash.lx_nor_flash_mapped_physical_sectors != 9)) (nor_sim_flash.lx_nor_flash_mapped_physical_sectors != 9))
{ {
printf("FAILED!\n"); printf("FAILED!\n");
#ifdef BATCH_TEST #ifdef BATCH_TEST
exit(1); exit(1);
@@ -462,9 +462,9 @@ ULONG *word_ptr;
{ {
} }
} }
status = lx_nor_flash_close(&nor_sim_flash); status = lx_nor_flash_close(&nor_sim_flash);
if (status != LX_SUCCESS) if (status != LX_SUCCESS)
{ {
printf("FAILED!\n"); printf("FAILED!\n");
@@ -475,19 +475,19 @@ ULONG *word_ptr;
{ {
} }
} }
/* Corrupt block 0, simulate a power interruption during erase of block 0, /* Corrupt block 0, simulate a power interruption during erase of block 0,
after the erase, and after the free bit map setup, but before erase count is setup. */ after the erase, and after the free bit map setup, but before erase count is setup. */
word_ptr[0] = 0xFFFFFFFF; word_ptr[0] = 0xFFFFFFFF;
/* Open the flash and see if we recover properly. */ /* Open the flash and see if we recover properly. */
status = lx_nor_flash_open(&nor_sim_flash, "sim nor flash", _lx_nor_flash_simulator_initialize); status = lx_nor_flash_open(&nor_sim_flash, "sim nor flash", _lx_nor_flash_simulator_initialize);
if ((status != LX_SUCCESS) || if ((status != LX_SUCCESS) ||
(nor_sim_flash.lx_nor_flash_free_physical_sectors != 111) || (nor_sim_flash.lx_nor_flash_free_physical_sectors != 111) ||
(nor_sim_flash.lx_nor_flash_mapped_physical_sectors != 9)) (nor_sim_flash.lx_nor_flash_mapped_physical_sectors != 9))
{ {
printf("FAILED!\n"); printf("FAILED!\n");
#ifdef BATCH_TEST #ifdef BATCH_TEST
exit(1); exit(1);
@@ -498,7 +498,7 @@ ULONG *word_ptr;
} }
status = lx_nor_flash_close(&nor_sim_flash); status = lx_nor_flash_close(&nor_sim_flash);
if (status != LX_SUCCESS) if (status != LX_SUCCESS)
{ {
printf("FAILED!\n"); printf("FAILED!\n");
@@ -516,14 +516,14 @@ ULONG *word_ptr;
printf("Test 4: Power interrupted new block allocation.."); printf("Test 4: Power interrupted new block allocation..");
word_ptr[3] = word_ptr[3] & ~((ULONG) 1); word_ptr[3] = word_ptr[3] & ~((ULONG) 1);
/* Open the flash and see if we recover properly. */ /* Open the flash and see if we recover properly. */
status = lx_nor_flash_open(&nor_sim_flash, "sim nor flash", _lx_nor_flash_simulator_initialize); status = lx_nor_flash_open(&nor_sim_flash, "sim nor flash", _lx_nor_flash_simulator_initialize);
if ((status != LX_SUCCESS) || if ((status != LX_SUCCESS) ||
(nor_sim_flash.lx_nor_flash_free_physical_sectors != 110) || (nor_sim_flash.lx_nor_flash_free_physical_sectors != 110) ||
(nor_sim_flash.lx_nor_flash_mapped_physical_sectors != 9)) (nor_sim_flash.lx_nor_flash_mapped_physical_sectors != 9))
{ {
printf("FAILED!\n"); printf("FAILED!\n");
#ifdef BATCH_TEST #ifdef BATCH_TEST
exit(1); exit(1);
@@ -532,9 +532,9 @@ ULONG *word_ptr;
{ {
} }
} }
status = lx_nor_flash_close(&nor_sim_flash); status = lx_nor_flash_close(&nor_sim_flash);
if (status != LX_SUCCESS) if (status != LX_SUCCESS)
{ {
printf("FAILED!\n"); printf("FAILED!\n");
@@ -550,14 +550,14 @@ ULONG *word_ptr;
anything else can be done. */ anything else can be done. */
word_ptr[(16*128)+3] = 0x7C00; word_ptr[(16*128)+3] = 0x7C00;
/* Open the flash and see if we recover properly. */ /* Open the flash and see if we recover properly. */
status = lx_nor_flash_open(&nor_sim_flash, "sim nor flash", _lx_nor_flash_simulator_initialize); status = lx_nor_flash_open(&nor_sim_flash, "sim nor flash", _lx_nor_flash_simulator_initialize);
if ((status != LX_SUCCESS) || if ((status != LX_SUCCESS) ||
(nor_sim_flash.lx_nor_flash_free_physical_sectors != 109) || (nor_sim_flash.lx_nor_flash_free_physical_sectors != 109) ||
(nor_sim_flash.lx_nor_flash_mapped_physical_sectors != 9)) (nor_sim_flash.lx_nor_flash_mapped_physical_sectors != 9))
{ {
printf("FAILED!\n"); printf("FAILED!\n");
#ifdef BATCH_TEST #ifdef BATCH_TEST
exit(1); exit(1);
@@ -568,7 +568,7 @@ ULONG *word_ptr;
} }
status = lx_nor_flash_close(&nor_sim_flash); status = lx_nor_flash_close(&nor_sim_flash);
if (status != LX_SUCCESS) if (status != LX_SUCCESS)
{ {
printf("FAILED!\n"); printf("FAILED!\n");
@@ -585,15 +585,15 @@ ULONG *word_ptr;
setup. */ setup. */
word_ptr[3] = 0x7FFC; word_ptr[3] = 0x7FFC;
word_ptr[(16*128)+6] = word_ptr[(16*128)+6] & ~((ULONG) 0x40000000); word_ptr[(16*128)+6] = word_ptr[(16*128)+6] & ~((ULONG) 0x40000000);
/* Open the flash and see if we recover properly. */ /* Open the flash and see if we recover properly. */
status = lx_nor_flash_open(&nor_sim_flash, "sim nor flash", _lx_nor_flash_simulator_initialize); status = lx_nor_flash_open(&nor_sim_flash, "sim nor flash", _lx_nor_flash_simulator_initialize);
if ((status != LX_SUCCESS) || if ((status != LX_SUCCESS) ||
(nor_sim_flash.lx_nor_flash_free_physical_sectors != 108) || (nor_sim_flash.lx_nor_flash_free_physical_sectors != 108) ||
(nor_sim_flash.lx_nor_flash_mapped_physical_sectors != 9)) (nor_sim_flash.lx_nor_flash_mapped_physical_sectors != 9))
{ {
printf("FAILED!\n"); printf("FAILED!\n");
#ifdef BATCH_TEST #ifdef BATCH_TEST
exit(1); exit(1);
@@ -604,7 +604,7 @@ ULONG *word_ptr;
} }
lx_nor_flash_close(&nor_sim_flash); lx_nor_flash_close(&nor_sim_flash);
/* Simulate a power interruption after a new sector is allocated, after data /* Simulate a power interruption after a new sector is allocated, after data
had been copied, and the superceeded bit is clear, the new entry is setup, but the old entry had been copied, and the superceeded bit is clear, the new entry is setup, but the old entry
has not been invalidated. */ has not been invalidated. */
@@ -614,15 +614,15 @@ ULONG *word_ptr;
{ {
word_ptr[(3*128)+i] = 0x70; word_ptr[(3*128)+i] = 0x70;
} }
/* Open the flash and see if we recover properly. */ /* Open the flash and see if we recover properly. */
status = lx_nor_flash_open(&nor_sim_flash, "sim nor flash", _lx_nor_flash_simulator_initialize); status = lx_nor_flash_open(&nor_sim_flash, "sim nor flash", _lx_nor_flash_simulator_initialize);
if ((status != LX_SUCCESS) || if ((status != LX_SUCCESS) ||
(nor_sim_flash.lx_nor_flash_free_physical_sectors != 107) || (nor_sim_flash.lx_nor_flash_free_physical_sectors != 107) ||
(nor_sim_flash.lx_nor_flash_mapped_physical_sectors != 9)) (nor_sim_flash.lx_nor_flash_mapped_physical_sectors != 9))
{ {
printf("FAILED!\n"); printf("FAILED!\n");
#ifdef BATCH_TEST #ifdef BATCH_TEST
exit(1); exit(1);
@@ -823,7 +823,7 @@ ULONG *word_ptr;
} }
status = lx_nor_flash_defragment(&nor_sim_flash); status = lx_nor_flash_defragment(&nor_sim_flash);
if (status != LX_SUCCESS) if (status != LX_SUCCESS)
{ {
printf("FAILED!\n"); printf("FAILED!\n");
@@ -834,10 +834,10 @@ ULONG *word_ptr;
{ {
} }
} }
status = lx_nor_flash_defragment(&nor_sim_flash); status = lx_nor_flash_defragment(&nor_sim_flash);
if (status != LX_SUCCESS) if (status != LX_SUCCESS)
{ {
printf("FAILED!\n"); printf("FAILED!\n");
@@ -848,7 +848,7 @@ ULONG *word_ptr;
{ {
} }
} }
status = lx_nor_flash_sector_read(&nor_sim_flash, 7, readbuffer); status = lx_nor_flash_sector_read(&nor_sim_flash, 7, readbuffer);
if (status != LX_SUCCESS) if (status != LX_SUCCESS)
{ {
@@ -1229,7 +1229,7 @@ ULONG *word_ptr;
{ {
} }
} }
status = lx_nor_flash_sector_release(&nor_sim_flash, 7); status = lx_nor_flash_sector_release(&nor_sim_flash, 7);
if (status != LX_SUCCESS) if (status != LX_SUCCESS)
{ {
@@ -1252,9 +1252,9 @@ ULONG *word_ptr;
{ {
} }
} }
status = lx_nor_flash_defragment(&nor_sim_flash); status = lx_nor_flash_defragment(&nor_sim_flash);
if (status != LX_SUCCESS) if (status != LX_SUCCESS)
{ {
printf("FAILED!\n"); printf("FAILED!\n");
@@ -1278,7 +1278,7 @@ ULONG *word_ptr;
{ {
} }
} }
printf("SUCCESS!\n"); printf("SUCCESS!\n");
printf("Test 5: Randow write/read sector................"); printf("Test 5: Randow write/read sector................");
@@ -1286,12 +1286,12 @@ ULONG *word_ptr;
/* format the simulated NOR flash. */ /* format the simulated NOR flash. */
lx_nor_flash_format(&nor_sim_flash, "sim nor flash", _lx_nor_flash_simulator_initialize, NULL); lx_nor_flash_format(&nor_sim_flash, "sim nor flash", _lx_nor_flash_simulator_initialize, NULL);
/* Open the flash. */ /* Open the flash. */
status = lx_nor_flash_open(&nor_sim_flash, "sim nor flash", _lx_nor_flash_simulator_initialize); status = lx_nor_flash_open(&nor_sim_flash, "sim nor flash", _lx_nor_flash_simulator_initialize);
if (status != LX_SUCCESS) if (status != LX_SUCCESS)
{ {
printf("FAILED!\n"); printf("FAILED!\n");
#ifdef BATCH_TEST #ifdef BATCH_TEST
exit(1); exit(1);
@@ -1300,15 +1300,15 @@ ULONG *word_ptr;
{ {
} }
} }
/* Write 100 sectors.... */ /* Write 100 sectors.... */
for (i = 0; i < 100; i++) for (i = 0; i < 100; i++)
{ {
for (j = 0; j < 128; j++) for (j = 0; j < 128; j++)
buffer[j] = i; buffer[j] = i;
status = lx_nor_flash_sector_write(&nor_sim_flash, i, buffer); status = lx_nor_flash_sector_write(&nor_sim_flash, i, buffer);
if (status != LX_SUCCESS) if (status != LX_SUCCESS)
{ {
printf("FAILED!\n"); printf("FAILED!\n");
@@ -1320,13 +1320,13 @@ ULONG *word_ptr;
} }
} }
} }
/* Read back 100 sectors... */ /* Read back 100 sectors... */
for (i = 0; i < 100; i++) for (i = 0; i < 100; i++)
{ {
status = lx_nor_flash_sector_read(&nor_sim_flash, i, buffer); status = lx_nor_flash_sector_read(&nor_sim_flash, i, buffer);
if (status != LX_SUCCESS) if (status != LX_SUCCESS)
{ {
printf("FAILED!\n"); printf("FAILED!\n");
@@ -1337,10 +1337,10 @@ ULONG *word_ptr;
{ {
} }
} }
for (j = 0; j < 128; j++) for (j = 0; j < 128; j++)
{ {
if (buffer[j] != i) if (buffer[j] != i)
{ {
printf("FAILED!\n"); printf("FAILED!\n");
@@ -1353,18 +1353,18 @@ ULONG *word_ptr;
} }
} }
} }
/* Now, perform 1000 sector writes to randomly selected sectors, each time /* Now, perform 1000 sector writes to randomly selected sectors, each time
reading first to make sure the previous contents are valid. */ reading first to make sure the previous contents are valid. */
for (i = 0; i < 1000; i++) for (i = 0; i < 1000; i++)
{ {
/* Pickup random sector. */ /* Pickup random sector. */
sector = (rand() % 100); sector = (rand() % 100);
/* Read that sector. */ /* Read that sector. */
status = lx_nor_flash_sector_read(&nor_sim_flash, sector, buffer); status = lx_nor_flash_sector_read(&nor_sim_flash, sector, buffer);
if (status != LX_SUCCESS) if (status != LX_SUCCESS)
{ {
printf("FAILED!\n"); printf("FAILED!\n");
@@ -1375,10 +1375,10 @@ ULONG *word_ptr;
{ {
} }
} }
for (j = 0; j < 128; j++) for (j = 0; j < 128; j++)
{ {
if ((buffer[j] & 0x0000FFFF) != sector) if ((buffer[j] & 0x0000FFFF) != sector)
{ {
printf("FAILED!\n"); printf("FAILED!\n");
@@ -1394,10 +1394,10 @@ ULONG *word_ptr;
/* Include the itteraction in the buffer to generate a new write. */ /* Include the itteraction in the buffer to generate a new write. */
for (j = 0; j < 128; j++) for (j = 0; j < 128; j++)
{ {
buffer[j] = (buffer[j] & 0x0000FFFF) | (i << 16); buffer[j] = (buffer[j] & 0x0000FFFF) | (i << 16);
} }
status = lx_nor_flash_sector_write(&nor_sim_flash, sector, buffer); status = lx_nor_flash_sector_write(&nor_sim_flash, sector, buffer);
if (status != LX_SUCCESS) if (status != LX_SUCCESS)
@@ -1411,9 +1411,9 @@ ULONG *word_ptr;
} }
} }
} }
status = lx_nor_flash_close(&nor_sim_flash); status = lx_nor_flash_close(&nor_sim_flash);
if (status != LX_SUCCESS) if (status != LX_SUCCESS)
{ {
printf("FAILED!\n"); printf("FAILED!\n");
+98 -98
View File
@@ -38,7 +38,7 @@ void thread_0_entry(ULONG thread_input);
int main() int main()
{ {
/* Enter the ThreadX kernel. */ /* Enter the ThreadX kernel. */
#ifndef LX_STANDALONE_ENABLE #ifndef LX_STANDALONE_ENABLE
tx_kernel_enter(); tx_kernel_enter();
@@ -56,8 +56,8 @@ void tx_application_define(void *first_unused_memory)
/* Create the main thread. */ /* Create the main thread. */
tx_thread_create(&thread_0, "thread 0", thread_0_entry, 0, tx_thread_create(&thread_0, "thread 0", thread_0_entry, 0,
thread_0_stack, DEMO_STACK_SIZE, thread_0_stack, DEMO_STACK_SIZE,
1, 1, TX_NO_TIME_SLICE, TX_AUTO_START); 1, 1, TX_NO_TIME_SLICE, TX_AUTO_START);
} }
#endif #endif
@@ -72,13 +72,13 @@ UINT status;
ULONG *word_ptr; ULONG *word_ptr;
/* Initialize LevelX. */ /* Initialize LevelX. */
_lx_nor_flash_initialize(); _lx_nor_flash_initialize();
/* Test 1: Simple write 100 sectors and read 100 sectors. */ /* Test 1: Simple write 100 sectors and read 100 sectors. */
printf("Test 1: Simple write-read 100 sectors..........."); printf("Test 1: Simple write-read 100 sectors...........");
lx_nor_flash_format(&nor_sim_flash, "sim nor flash", _lx_nor_flash_simulator_initialize, NULL); lx_nor_flash_format(&nor_sim_flash, "sim nor flash", _lx_nor_flash_simulator_initialize, NULL);
lx_nor_flash_open(&nor_sim_flash, "sim nor flash", _lx_nor_flash_simulator_initialize); lx_nor_flash_open(&nor_sim_flash, "sim nor flash", _lx_nor_flash_simulator_initialize);
#ifndef LX_NOR_DISABLE_EXTENDED_CACHE #ifndef LX_NOR_DISABLE_EXTENDED_CACHE
@@ -115,9 +115,9 @@ lx_nor_flash_extended_cache_enable(&nor_sim_flash, nor_cache_memory, sizeof(nor_
{ {
for (j = 0; j < 128; j++) for (j = 0; j < 128; j++)
buffer[j] = i; buffer[j] = i;
status = lx_nor_flash_sector_write(&nor_sim_flash, i, buffer); status = lx_nor_flash_sector_write(&nor_sim_flash, i, buffer);
if (status != LX_SUCCESS) if (status != LX_SUCCESS)
{ {
printf("FAILED!\n"); printf("FAILED!\n");
@@ -129,13 +129,13 @@ lx_nor_flash_extended_cache_enable(&nor_sim_flash, nor_cache_memory, sizeof(nor_
} }
} }
} }
/* Read back 100 sectors... */ /* Read back 100 sectors... */
for (i = 0; i < 100; i++) for (i = 0; i < 100; i++)
{ {
status = lx_nor_flash_sector_read(&nor_sim_flash, i, buffer); status = lx_nor_flash_sector_read(&nor_sim_flash, i, buffer);
if (status != LX_SUCCESS) if (status != LX_SUCCESS)
{ {
printf("FAILED!\n"); printf("FAILED!\n");
@@ -146,10 +146,10 @@ lx_nor_flash_extended_cache_enable(&nor_sim_flash, nor_cache_memory, sizeof(nor_
{ {
} }
} }
for (j = 0; j < 128; j++) for (j = 0; j < 128; j++)
{ {
if (buffer[j] != i) if (buffer[j] != i)
{ {
printf("FAILED!\n"); printf("FAILED!\n");
@@ -198,9 +198,9 @@ lx_nor_flash_extended_cache_enable(&nor_sim_flash, nor_cache_memory, sizeof(nor_
/* Release 100 sectors... */ /* Release 100 sectors... */
for (i = 0; i < 100; i++) for (i = 0; i < 100; i++)
{ {
status = lx_nor_flash_sector_release(&nor_sim_flash, i); status = lx_nor_flash_sector_release(&nor_sim_flash, i);
if (status != LX_SUCCESS) if (status != LX_SUCCESS)
{ {
printf("FAILED!\n"); printf("FAILED!\n");
@@ -262,9 +262,9 @@ lx_nor_flash_extended_cache_enable(&nor_sim_flash, nor_cache_memory, sizeof(nor_
/* Test 2: Write same sector 120 times. */ /* Test 2: Write same sector 120 times. */
printf("Test 2: Write same sector 120 times............."); printf("Test 2: Write same sector 120 times.............");
/* Reinitialize... */ /* Reinitialize... */
lx_nor_flash_initialize(); lx_nor_flash_initialize();
lx_nor_flash_format(&nor_sim_flash, "sim nor flash", _lx_nor_flash_simulator_initialize, NULL); lx_nor_flash_format(&nor_sim_flash, "sim nor flash", _lx_nor_flash_simulator_initialize, NULL);
lx_nor_flash_open(&nor_sim_flash, "sim nor flash", _lx_nor_flash_simulator_initialize); lx_nor_flash_open(&nor_sim_flash, "sim nor flash", _lx_nor_flash_simulator_initialize);
@@ -274,15 +274,15 @@ lx_nor_flash_extended_cache_enable(&nor_sim_flash, nor_cache_memory, sizeof(nor_
for (j = 0; j < 128; j++) for (j = 0; j < 128; j++)
buffer[j] = 0xFFFFFFFF; buffer[j] = 0xFFFFFFFF;
/* Write same sector 120 sectors.... */ /* Write same sector 120 sectors.... */
for (i = 0; i < 120; i++) for (i = 0; i < 120; i++)
{ {
for (j = 0; j < 128; j++) for (j = 0; j < 128; j++)
buffer[j] = i; buffer[j] = i;
status = lx_nor_flash_sector_write(&nor_sim_flash, 7, buffer); status = lx_nor_flash_sector_write(&nor_sim_flash, 7, buffer);
if (status != LX_SUCCESS) if (status != LX_SUCCESS)
{ {
printf("FAILED!\n"); printf("FAILED!\n");
@@ -293,9 +293,9 @@ lx_nor_flash_extended_cache_enable(&nor_sim_flash, nor_cache_memory, sizeof(nor_
{ {
} }
} }
status = lx_nor_flash_sector_read(&nor_sim_flash, 7, readbuffer); status = lx_nor_flash_sector_read(&nor_sim_flash, 7, readbuffer);
if (status != LX_SUCCESS) if (status != LX_SUCCESS)
{ {
printf("FAILED!\n"); printf("FAILED!\n");
@@ -306,10 +306,10 @@ lx_nor_flash_extended_cache_enable(&nor_sim_flash, nor_cache_memory, sizeof(nor_
{ {
} }
} }
for (j = 0; j < 128; j++) for (j = 0; j < 128; j++)
{ {
if (buffer[j] != readbuffer[j]) if (buffer[j] != readbuffer[j])
{ {
printf("FAILED!\n"); printf("FAILED!\n");
@@ -321,7 +321,7 @@ lx_nor_flash_extended_cache_enable(&nor_sim_flash, nor_cache_memory, sizeof(nor_
} }
} }
} }
/* Write other sectors just to have additional sectors to manage. */ /* Write other sectors just to have additional sectors to manage. */
if (i == 1) if (i == 1)
lx_nor_flash_sector_write(&nor_sim_flash, 1, buffer); lx_nor_flash_sector_write(&nor_sim_flash, 1, buffer);
@@ -343,7 +343,7 @@ lx_nor_flash_extended_cache_enable(&nor_sim_flash, nor_cache_memory, sizeof(nor_
status = lx_nor_flash_defragment(&nor_sim_flash); status = lx_nor_flash_defragment(&nor_sim_flash);
status = lx_nor_flash_sector_read(&nor_sim_flash, 7, readbuffer); status = lx_nor_flash_sector_read(&nor_sim_flash, 7, readbuffer);
if (status != LX_SUCCESS) if (status != LX_SUCCESS)
{ {
@@ -535,7 +535,7 @@ lx_nor_flash_extended_cache_enable(&nor_sim_flash, nor_cache_memory, sizeof(nor_
} }
status = lx_nor_flash_defragment(&nor_sim_flash); status = lx_nor_flash_defragment(&nor_sim_flash);
if (status != LX_SUCCESS) if (status != LX_SUCCESS)
{ {
printf("FAILED!\n"); printf("FAILED!\n");
@@ -546,13 +546,13 @@ lx_nor_flash_extended_cache_enable(&nor_sim_flash, nor_cache_memory, sizeof(nor_
{ {
} }
} }
/* Point at the simulated NOR flash memory. */ /* Point at the simulated NOR flash memory. */
word_ptr = nor_sim_flash.lx_nor_flash_base_address; word_ptr = nor_sim_flash.lx_nor_flash_base_address;
status = lx_nor_flash_close(&nor_sim_flash); status = lx_nor_flash_close(&nor_sim_flash);
if (status != LX_SUCCESS) if (status != LX_SUCCESS)
{ {
printf("FAILED!\n"); printf("FAILED!\n");
@@ -564,14 +564,14 @@ lx_nor_flash_extended_cache_enable(&nor_sim_flash, nor_cache_memory, sizeof(nor_
} }
} }
printf("SUCCESS!\n"); printf("SUCCESS!\n");
/* Test 3: Corrupt block 0, simulate a power interruption during erase of block 0, /* Test 3: Corrupt block 0, simulate a power interruption during erase of block 0,
after the erase, but before the free bit map and erase count is setup. */ after the erase, but before the free bit map and erase count is setup. */
printf("Test 3: Block erase-initialize interrupted......"); printf("Test 3: Block erase-initialize interrupted......");
word_ptr[0] = 0xFFFFFFFF; word_ptr[0] = 0xFFFFFFFF;
word_ptr[3] = 0xFFFFFFFF; word_ptr[3] = 0xFFFFFFFF;
/* Open the flash and see if we recover properly. */ /* Open the flash and see if we recover properly. */
status = lx_nor_flash_open(&nor_sim_flash, "sim nor flash", _lx_nor_flash_simulator_initialize); status = lx_nor_flash_open(&nor_sim_flash, "sim nor flash", _lx_nor_flash_simulator_initialize);
#ifndef LX_NOR_DISABLE_EXTENDED_CACHE #ifndef LX_NOR_DISABLE_EXTENDED_CACHE
status += lx_nor_flash_extended_cache_enable(&nor_sim_flash, nor_cache_memory, sizeof(nor_cache_memory)); status += lx_nor_flash_extended_cache_enable(&nor_sim_flash, nor_cache_memory, sizeof(nor_cache_memory));
@@ -581,7 +581,7 @@ status += lx_nor_flash_extended_cache_enable(&nor_sim_flash, nor_cache_memory, s
(nor_sim_flash.lx_nor_flash_free_physical_sectors != 111) || (nor_sim_flash.lx_nor_flash_free_physical_sectors != 111) ||
(nor_sim_flash.lx_nor_flash_mapped_physical_sectors != 9)) (nor_sim_flash.lx_nor_flash_mapped_physical_sectors != 9))
{ {
printf("FAILED!\n"); printf("FAILED!\n");
#ifdef BATCH_TEST #ifdef BATCH_TEST
exit(1); exit(1);
@@ -590,9 +590,9 @@ status += lx_nor_flash_extended_cache_enable(&nor_sim_flash, nor_cache_memory, s
{ {
} }
} }
status = lx_nor_flash_close(&nor_sim_flash); status = lx_nor_flash_close(&nor_sim_flash);
if (status != LX_SUCCESS) if (status != LX_SUCCESS)
{ {
printf("FAILED!\n"); printf("FAILED!\n");
@@ -603,12 +603,12 @@ status += lx_nor_flash_extended_cache_enable(&nor_sim_flash, nor_cache_memory, s
{ {
} }
} }
/* Corrupt block 0, simulate a power interruption during erase of block 0, /* Corrupt block 0, simulate a power interruption during erase of block 0,
after the erase, and after the free bit map setup, but before erase count is setup. */ after the erase, and after the free bit map setup, but before erase count is setup. */
word_ptr[0] = 0xFFFFFFFF; word_ptr[0] = 0xFFFFFFFF;
/* Open the flash and see if we recover properly. */ /* Open the flash and see if we recover properly. */
status = lx_nor_flash_open(&nor_sim_flash, "sim nor flash", _lx_nor_flash_simulator_initialize); status = lx_nor_flash_open(&nor_sim_flash, "sim nor flash", _lx_nor_flash_simulator_initialize);
#ifndef LX_NOR_DISABLE_EXTENDED_CACHE #ifndef LX_NOR_DISABLE_EXTENDED_CACHE
status += lx_nor_flash_extended_cache_enable(&nor_sim_flash, nor_cache_memory, sizeof(nor_cache_memory)); status += lx_nor_flash_extended_cache_enable(&nor_sim_flash, nor_cache_memory, sizeof(nor_cache_memory));
@@ -618,7 +618,7 @@ status += lx_nor_flash_extended_cache_enable(&nor_sim_flash, nor_cache_memory, s
(nor_sim_flash.lx_nor_flash_free_physical_sectors != 111) || (nor_sim_flash.lx_nor_flash_free_physical_sectors != 111) ||
(nor_sim_flash.lx_nor_flash_mapped_physical_sectors != 9)) (nor_sim_flash.lx_nor_flash_mapped_physical_sectors != 9))
{ {
printf("FAILED!\n"); printf("FAILED!\n");
#ifdef BATCH_TEST #ifdef BATCH_TEST
exit(1); exit(1);
@@ -629,7 +629,7 @@ status += lx_nor_flash_extended_cache_enable(&nor_sim_flash, nor_cache_memory, s
} }
status = lx_nor_flash_close(&nor_sim_flash); status = lx_nor_flash_close(&nor_sim_flash);
if (status != LX_SUCCESS) if (status != LX_SUCCESS)
{ {
printf("FAILED!\n"); printf("FAILED!\n");
@@ -647,7 +647,7 @@ status += lx_nor_flash_extended_cache_enable(&nor_sim_flash, nor_cache_memory, s
printf("Test 4: Power interrupted new block allocation.."); printf("Test 4: Power interrupted new block allocation..");
word_ptr[3] = word_ptr[3] & ~((ULONG) 1); word_ptr[3] = word_ptr[3] & ~((ULONG) 1);
/* Open the flash and see if we recover properly. */ /* Open the flash and see if we recover properly. */
status = lx_nor_flash_open(&nor_sim_flash, "sim nor flash", _lx_nor_flash_simulator_initialize); status = lx_nor_flash_open(&nor_sim_flash, "sim nor flash", _lx_nor_flash_simulator_initialize);
#ifndef LX_NOR_DISABLE_EXTENDED_CACHE #ifndef LX_NOR_DISABLE_EXTENDED_CACHE
status += lx_nor_flash_extended_cache_enable(&nor_sim_flash, nor_cache_memory, sizeof(nor_cache_memory)); status += lx_nor_flash_extended_cache_enable(&nor_sim_flash, nor_cache_memory, sizeof(nor_cache_memory));
@@ -657,7 +657,7 @@ status += lx_nor_flash_extended_cache_enable(&nor_sim_flash, nor_cache_memory, s
(nor_sim_flash.lx_nor_flash_free_physical_sectors != 110) || (nor_sim_flash.lx_nor_flash_free_physical_sectors != 110) ||
(nor_sim_flash.lx_nor_flash_mapped_physical_sectors != 9)) (nor_sim_flash.lx_nor_flash_mapped_physical_sectors != 9))
{ {
printf("FAILED!\n"); printf("FAILED!\n");
#ifdef BATCH_TEST #ifdef BATCH_TEST
exit(1); exit(1);
@@ -666,9 +666,9 @@ status += lx_nor_flash_extended_cache_enable(&nor_sim_flash, nor_cache_memory, s
{ {
} }
} }
status = lx_nor_flash_close(&nor_sim_flash); status = lx_nor_flash_close(&nor_sim_flash);
if (status != LX_SUCCESS) if (status != LX_SUCCESS)
{ {
printf("FAILED!\n"); printf("FAILED!\n");
@@ -684,7 +684,7 @@ status += lx_nor_flash_extended_cache_enable(&nor_sim_flash, nor_cache_memory, s
anything else can be done. */ anything else can be done. */
word_ptr[(16*128)+3] = 0x7C00; word_ptr[(16*128)+3] = 0x7C00;
/* Open the flash and see if we recover properly. */ /* Open the flash and see if we recover properly. */
status = lx_nor_flash_open(&nor_sim_flash, "sim nor flash", _lx_nor_flash_simulator_initialize); status = lx_nor_flash_open(&nor_sim_flash, "sim nor flash", _lx_nor_flash_simulator_initialize);
#ifndef LX_NOR_DISABLE_EXTENDED_CACHE #ifndef LX_NOR_DISABLE_EXTENDED_CACHE
status += lx_nor_flash_extended_cache_enable(&nor_sim_flash, nor_cache_memory, sizeof(nor_cache_memory)); status += lx_nor_flash_extended_cache_enable(&nor_sim_flash, nor_cache_memory, sizeof(nor_cache_memory));
@@ -694,7 +694,7 @@ status += lx_nor_flash_extended_cache_enable(&nor_sim_flash, nor_cache_memory, s
(nor_sim_flash.lx_nor_flash_free_physical_sectors != 109) || (nor_sim_flash.lx_nor_flash_free_physical_sectors != 109) ||
(nor_sim_flash.lx_nor_flash_mapped_physical_sectors != 9)) (nor_sim_flash.lx_nor_flash_mapped_physical_sectors != 9))
{ {
printf("FAILED!\n"); printf("FAILED!\n");
#ifdef BATCH_TEST #ifdef BATCH_TEST
exit(1); exit(1);
@@ -705,7 +705,7 @@ status += lx_nor_flash_extended_cache_enable(&nor_sim_flash, nor_cache_memory, s
} }
status = lx_nor_flash_close(&nor_sim_flash); status = lx_nor_flash_close(&nor_sim_flash);
if (status != LX_SUCCESS) if (status != LX_SUCCESS)
{ {
printf("FAILED!\n"); printf("FAILED!\n");
@@ -722,8 +722,8 @@ status += lx_nor_flash_extended_cache_enable(&nor_sim_flash, nor_cache_memory, s
setup. */ setup. */
word_ptr[3] = 0x7FFC; word_ptr[3] = 0x7FFC;
word_ptr[(16*128)+6] = word_ptr[(16*128)+6] & ~((ULONG) 0x40000000); word_ptr[(16*128)+6] = word_ptr[(16*128)+6] & ~((ULONG) 0x40000000);
/* Open the flash and see if we recover properly. */ /* Open the flash and see if we recover properly. */
status = lx_nor_flash_open(&nor_sim_flash, "sim nor flash", _lx_nor_flash_simulator_initialize); status = lx_nor_flash_open(&nor_sim_flash, "sim nor flash", _lx_nor_flash_simulator_initialize);
#ifndef LX_NOR_DISABLE_EXTENDED_CACHE #ifndef LX_NOR_DISABLE_EXTENDED_CACHE
status += lx_nor_flash_extended_cache_enable(&nor_sim_flash, nor_cache_memory, sizeof(nor_cache_memory)); status += lx_nor_flash_extended_cache_enable(&nor_sim_flash, nor_cache_memory, sizeof(nor_cache_memory));
@@ -733,7 +733,7 @@ status += lx_nor_flash_extended_cache_enable(&nor_sim_flash, nor_cache_memory, s
(nor_sim_flash.lx_nor_flash_free_physical_sectors != 108) || (nor_sim_flash.lx_nor_flash_free_physical_sectors != 108) ||
(nor_sim_flash.lx_nor_flash_mapped_physical_sectors != 9)) (nor_sim_flash.lx_nor_flash_mapped_physical_sectors != 9))
{ {
printf("FAILED!\n"); printf("FAILED!\n");
#ifdef BATCH_TEST #ifdef BATCH_TEST
exit(1); exit(1);
@@ -744,7 +744,7 @@ status += lx_nor_flash_extended_cache_enable(&nor_sim_flash, nor_cache_memory, s
} }
lx_nor_flash_close(&nor_sim_flash); lx_nor_flash_close(&nor_sim_flash);
/* Simulate a power interruption after a new sector is allocated, after data /* Simulate a power interruption after a new sector is allocated, after data
had been copied, and the superceeded bit is clear, the new entry is setup, but the old entry had been copied, and the superceeded bit is clear, the new entry is setup, but the old entry
has not been invalidated. */ has not been invalidated. */
@@ -754,8 +754,8 @@ status += lx_nor_flash_extended_cache_enable(&nor_sim_flash, nor_cache_memory, s
{ {
word_ptr[(3*128)+i] = 0x70; word_ptr[(3*128)+i] = 0x70;
} }
/* Open the flash and see if we recover properly. */ /* Open the flash and see if we recover properly. */
status = lx_nor_flash_open(&nor_sim_flash, "sim nor flash", _lx_nor_flash_simulator_initialize); status = lx_nor_flash_open(&nor_sim_flash, "sim nor flash", _lx_nor_flash_simulator_initialize);
#ifndef LX_NOR_DISABLE_EXTENDED_CACHE #ifndef LX_NOR_DISABLE_EXTENDED_CACHE
status += lx_nor_flash_extended_cache_enable(&nor_sim_flash, nor_cache_memory, sizeof(nor_cache_memory)); status += lx_nor_flash_extended_cache_enable(&nor_sim_flash, nor_cache_memory, sizeof(nor_cache_memory));
@@ -765,7 +765,7 @@ status += lx_nor_flash_extended_cache_enable(&nor_sim_flash, nor_cache_memory, s
(nor_sim_flash.lx_nor_flash_free_physical_sectors != 107) || (nor_sim_flash.lx_nor_flash_free_physical_sectors != 107) ||
(nor_sim_flash.lx_nor_flash_mapped_physical_sectors != 9)) (nor_sim_flash.lx_nor_flash_mapped_physical_sectors != 9))
{ {
printf("FAILED!\n"); printf("FAILED!\n");
#ifdef BATCH_TEST #ifdef BATCH_TEST
exit(1); exit(1);
@@ -966,7 +966,7 @@ status += lx_nor_flash_extended_cache_enable(&nor_sim_flash, nor_cache_memory, s
} }
status = lx_nor_flash_defragment(&nor_sim_flash); status = lx_nor_flash_defragment(&nor_sim_flash);
if (status != LX_SUCCESS) if (status != LX_SUCCESS)
{ {
printf("FAILED!\n"); printf("FAILED!\n");
@@ -977,10 +977,10 @@ status += lx_nor_flash_extended_cache_enable(&nor_sim_flash, nor_cache_memory, s
{ {
} }
} }
status = lx_nor_flash_defragment(&nor_sim_flash); status = lx_nor_flash_defragment(&nor_sim_flash);
if (status != LX_SUCCESS) if (status != LX_SUCCESS)
{ {
printf("FAILED!\n"); printf("FAILED!\n");
@@ -991,7 +991,7 @@ status += lx_nor_flash_extended_cache_enable(&nor_sim_flash, nor_cache_memory, s
{ {
} }
} }
status = lx_nor_flash_sector_read(&nor_sim_flash, 7, readbuffer); status = lx_nor_flash_sector_read(&nor_sim_flash, 7, readbuffer);
if (status != LX_SUCCESS) if (status != LX_SUCCESS)
{ {
@@ -1372,7 +1372,7 @@ status += lx_nor_flash_extended_cache_enable(&nor_sim_flash, nor_cache_memory, s
{ {
} }
} }
status = lx_nor_flash_sector_release(&nor_sim_flash, 7); status = lx_nor_flash_sector_release(&nor_sim_flash, 7);
if (status != LX_SUCCESS) if (status != LX_SUCCESS)
{ {
@@ -1395,9 +1395,9 @@ status += lx_nor_flash_extended_cache_enable(&nor_sim_flash, nor_cache_memory, s
{ {
} }
} }
status = lx_nor_flash_defragment(&nor_sim_flash); status = lx_nor_flash_defragment(&nor_sim_flash);
if (status != LX_SUCCESS) if (status != LX_SUCCESS)
{ {
printf("FAILED!\n"); printf("FAILED!\n");
@@ -1421,24 +1421,24 @@ status += lx_nor_flash_extended_cache_enable(&nor_sim_flash, nor_cache_memory, s
{ {
} }
} }
printf("SUCCESS!\n"); printf("SUCCESS!\n");
printf("Test 5: Randow write/read sector................"); printf("Test 5: Randow write/read sector................");
/*format the simulated NOR flash. */ /*format the simulated NOR flash. */
/* Open the flash. */
/* Open the flash. */
status = lx_nor_flash_format(&nor_sim_flash, "sim nor flash", _lx_nor_flash_simulator_initialize, NULL); status = lx_nor_flash_format(&nor_sim_flash, "sim nor flash", _lx_nor_flash_simulator_initialize, NULL);
status = lx_nor_flash_open(&nor_sim_flash, "sim nor flash", _lx_nor_flash_simulator_initialize); status = lx_nor_flash_open(&nor_sim_flash, "sim nor flash", _lx_nor_flash_simulator_initialize);
#ifndef LX_NOR_DISABLE_EXTENDED_CACHE #ifndef LX_NOR_DISABLE_EXTENDED_CACHE
status += lx_nor_flash_extended_cache_enable(&nor_sim_flash, nor_cache_memory, sizeof(nor_cache_memory)); status += lx_nor_flash_extended_cache_enable(&nor_sim_flash, nor_cache_memory, sizeof(nor_cache_memory));
#endif #endif
if (status != LX_SUCCESS) if (status != LX_SUCCESS)
{ {
printf("FAILED!\n"); printf("FAILED!\n");
#ifdef BATCH_TEST #ifdef BATCH_TEST
exit(1); exit(1);
@@ -1447,15 +1447,15 @@ status += lx_nor_flash_extended_cache_enable(&nor_sim_flash, nor_cache_memory, s
{ {
} }
} }
/* Write 100 sectors.... */ /* Write 100 sectors.... */
for (i = 0; i < 100; i++) for (i = 0; i < 100; i++)
{ {
for (j = 0; j < 128; j++) for (j = 0; j < 128; j++)
buffer[j] = i; buffer[j] = i;
status = lx_nor_flash_sector_write(&nor_sim_flash, i, buffer); status = lx_nor_flash_sector_write(&nor_sim_flash, i, buffer);
if (status != LX_SUCCESS) if (status != LX_SUCCESS)
{ {
printf("FAILED!\n"); printf("FAILED!\n");
@@ -1467,13 +1467,13 @@ status += lx_nor_flash_extended_cache_enable(&nor_sim_flash, nor_cache_memory, s
} }
} }
} }
/* Read back 100 sectors... */ /* Read back 100 sectors... */
for (i = 0; i < 100; i++) for (i = 0; i < 100; i++)
{ {
status = lx_nor_flash_sector_read(&nor_sim_flash, i, buffer); status = lx_nor_flash_sector_read(&nor_sim_flash, i, buffer);
if (status != LX_SUCCESS) if (status != LX_SUCCESS)
{ {
printf("FAILED!\n"); printf("FAILED!\n");
@@ -1484,10 +1484,10 @@ status += lx_nor_flash_extended_cache_enable(&nor_sim_flash, nor_cache_memory, s
{ {
} }
} }
for (j = 0; j < 128; j++) for (j = 0; j < 128; j++)
{ {
if (buffer[j] != i) if (buffer[j] != i)
{ {
printf("FAILED!\n"); printf("FAILED!\n");
@@ -1500,18 +1500,18 @@ status += lx_nor_flash_extended_cache_enable(&nor_sim_flash, nor_cache_memory, s
} }
} }
} }
/* Now, perform 1000 sector writes to randomly selected sectors, each time /* Now, perform 1000 sector writes to randomly selected sectors, each time
reading first to make sure the previous contents are valid. */ reading first to make sure the previous contents are valid. */
for (i = 0; i < 1000; i++) for (i = 0; i < 1000; i++)
{ {
/* Pickup random sector. */ /* Pickup random sector. */
sector = (rand() % 100); sector = (rand() % 100);
/* Read that sector. */ /* Read that sector. */
status = lx_nor_flash_sector_read(&nor_sim_flash, sector, buffer); status = lx_nor_flash_sector_read(&nor_sim_flash, sector, buffer);
if (status != LX_SUCCESS) if (status != LX_SUCCESS)
{ {
printf("FAILED!\n"); printf("FAILED!\n");
@@ -1522,10 +1522,10 @@ status += lx_nor_flash_extended_cache_enable(&nor_sim_flash, nor_cache_memory, s
{ {
} }
} }
for (j = 0; j < 128; j++) for (j = 0; j < 128; j++)
{ {
if ((buffer[j] & 0x0000FFFF) != sector) if ((buffer[j] & 0x0000FFFF) != sector)
{ {
printf("FAILED!\n"); printf("FAILED!\n");
@@ -1541,10 +1541,10 @@ status += lx_nor_flash_extended_cache_enable(&nor_sim_flash, nor_cache_memory, s
/* Include the itteraction in the buffer to generate a new write. */ /* Include the itteraction in the buffer to generate a new write. */
for (j = 0; j < 128; j++) for (j = 0; j < 128; j++)
{ {
buffer[j] = (buffer[j] & 0x0000FFFF) | (i << 16); buffer[j] = (buffer[j] & 0x0000FFFF) | (i << 16);
} }
status = lx_nor_flash_sector_write(&nor_sim_flash, sector, buffer); status = lx_nor_flash_sector_write(&nor_sim_flash, sector, buffer);
if (status != LX_SUCCESS) if (status != LX_SUCCESS)
@@ -1558,9 +1558,9 @@ status += lx_nor_flash_extended_cache_enable(&nor_sim_flash, nor_cache_memory, s
} }
} }
} }
status = lx_nor_flash_close(&nor_sim_flash); status = lx_nor_flash_close(&nor_sim_flash);
if (status != LX_SUCCESS) if (status != LX_SUCCESS)
{ {
printf("FAILED!\n"); printf("FAILED!\n");
@@ -1578,15 +1578,15 @@ status += lx_nor_flash_extended_cache_enable(&nor_sim_flash, nor_cache_memory, s
/* Format the simulated NOR flash. */ /* Format the simulated NOR flash. */
status = lx_nor_flash_format(&nor_sim_flash, "sim nor flash", _lx_nor_flash_simulator_initialize, NULL); status = lx_nor_flash_format(&nor_sim_flash, "sim nor flash", _lx_nor_flash_simulator_initialize, NULL);
/* Open the flash. */ /* Open the flash. */
status = lx_nor_flash_open(&nor_sim_flash, "sim nor flash", _lx_nor_flash_simulator_initialize); status = lx_nor_flash_open(&nor_sim_flash, "sim nor flash", _lx_nor_flash_simulator_initialize);
#ifndef LX_NOR_DISABLE_EXTENDED_CACHE #ifndef LX_NOR_DISABLE_EXTENDED_CACHE
status += lx_nor_flash_extended_cache_enable(&nor_sim_flash, nor_cache_memory2, sizeof(nor_cache_memory2)); status += lx_nor_flash_extended_cache_enable(&nor_sim_flash, nor_cache_memory2, sizeof(nor_cache_memory2));
#endif #endif
if (status != LX_SUCCESS) if (status != LX_SUCCESS)
{ {
printf("FAILED!\n"); printf("FAILED!\n");
#ifdef BATCH_TEST #ifdef BATCH_TEST
exit(1); exit(1);
@@ -1601,9 +1601,9 @@ status += lx_nor_flash_extended_cache_enable(&nor_sim_flash, nor_cache_memory2,
{ {
for (j = 0; j < 128; j++) for (j = 0; j < 128; j++)
buffer[j] = i; buffer[j] = i;
status = lx_nor_flash_sector_write(&nor_sim_flash, i, buffer); status = lx_nor_flash_sector_write(&nor_sim_flash, i, buffer);
if (status != LX_SUCCESS) if (status != LX_SUCCESS)
{ {
printf("FAILED!\n"); printf("FAILED!\n");
@@ -1615,13 +1615,13 @@ status += lx_nor_flash_extended_cache_enable(&nor_sim_flash, nor_cache_memory2,
} }
} }
} }
/* Read back 100 sectors... */ /* Read back 100 sectors... */
for (i = 0; i < 100; i++) for (i = 0; i < 100; i++)
{ {
status = lx_nor_flash_sector_read(&nor_sim_flash, i, buffer); status = lx_nor_flash_sector_read(&nor_sim_flash, i, buffer);
if (status != LX_SUCCESS) if (status != LX_SUCCESS)
{ {
printf("FAILED!\n"); printf("FAILED!\n");
@@ -1632,10 +1632,10 @@ status += lx_nor_flash_extended_cache_enable(&nor_sim_flash, nor_cache_memory2,
{ {
} }
} }
for (j = 0; j < 128; j++) for (j = 0; j < 128; j++)
{ {
if (buffer[j] != i) if (buffer[j] != i)
{ {
printf("FAILED!\n"); printf("FAILED!\n");
@@ -1648,7 +1648,7 @@ status += lx_nor_flash_extended_cache_enable(&nor_sim_flash, nor_cache_memory2,
} }
} }
} }
#ifdef BATCH_TEST #ifdef BATCH_TEST
exit(0); exit(0);
#endif #endif