Author SHA1 Message Date
Frédéric Desbiens a46b74fb8a Merge pull request #69 from eclipse-threadx/dev
Merge changes ahead of the v6.5.0.202601 release
2026-03-06 19:43:03 +01:00
Frédéric Desbiens b80f28e0e6 Merge pull request #68 from fdesbiens/dev
Updated copyright headers and version number constants
2026-03-05 09:39:50 +01:00
Frédéric Desbiens f98a5c4eb8 Updated version number constants. 2026-03-05 09:23:24 +01:00
Frédéric Desbiens b9ba4a97bf Updated copyright headers and removed trailing whitespace 2026-03-05 09:17:20 +01:00
Frédéric Desbiens fa1a8e5ff4 Merge pull request #65 from borlandong/fix-performance-issue
Updated the logic to skip unnecessary main data read in _lx_nand_flash_sector_read
2026-02-17 11:38:13 -05:00
Frédéric Desbiens 89c745fcf5 Merge pull request #66 from rahmanih/update_nand_simulator
Updated the nand flash simulator
2026-02-17 11:36:36 -05:00
Haithem Rahmani 4782f22568 update nand flash simulator
align the nand flash simulator against the PR #65

Tests:
Total Test time (real) =   6.33 sec
~/work/git_repos/github/eclipse/levelx_rahmanih/test/cmake
3/3 Test #1: default_build_coverage::levelx_nand_flash_test ........   Passed   44.06 sec

100% tests passed, 0 tests failed out of 3
2026-02-10 09:28:48 +01:00
borlandong 58dc81e83c perf: skip unnecessary main data read in _lx_nand_flash_sector_read 2026-01-22 12:09:25 +08:00
Frédéric Desbiens 1751446fb0 Merge pull request #63 from eclipse-threadx/dev
Merge changes ahead of the 202504 release
2026-01-12 18:05:43 -05:00
Frédéric Desbiens c27eb52bd2 Updated version number constants 2026-01-12 18:01:37 -05:00
Frédéric Desbiens c03223909a Merge pull request #62 from rahmanih/fix_nor_flash_format
Fix: force initial erase count to 1
2026-01-12 17:55:06 -05:00
Haithem Rahmani 9bf1c24243 fix: force initial erase count to 1
for each erased block write the word (1 | LX_NOR_ERASED) at the
first word. this is actually equivalent to 0x80000001.
When the lx_nor_flash_open_extended() is called, only the erase count will remain
valid.

Remove the LX_DISABLE/LX_RESTORE sequence.
2026-01-08 10:36:43 +01:00
Frédéric Desbiens 6a534bed34 Update minimal CMake version in CMakeLists.txt to 3.13 2025-11-25 10:48:08 -05:00
Frédéric Desbiens 4585b92f15 Update minimal CMake version in CMakeLists.txt to 3.13 2025-11-25 10:45:08 -05:00
Frédéric Desbiens 63ed12cfd6 Merge pull request #60 from rahmanih/add_new_level_apis_pr
New APIs:
- lx_nor_flash_format(): setup the NOR Flash for a new and fresh filesystem.
- lx_nor_flash_open_extended(): adds a user data pointer that could be passed to the underlying low-level NOR driver.
-  lx_nand_flash_open_extended(): adds a user data pointer that could be passed to the underlying low-level NAND driver.

Updated APIs:
- lx_nor_flash_open(): call the lx_nor_flash_open_extended() with a NULL as user data pointer.
- lx_nand_flash_open(): call the lx_nand_flash_open_extended() with a NULL as user data pointer.
2025-11-25 10:40:13 -05:00
Frédéric Desbiens a1761869fd Merge pull request #59 from rahmanih/fix_issue_58
fix: "array out of bounds" error leading to memory corruption
2025-11-25 10:09:17 -05:00
Frédéric Desbiens 5783f64fe1 Merge pull request #61 from rahmanih/fix_issue_53
fix: Wrong out-of-range check in lx_nand_flash_block_find.
2025-11-25 09:59:41 -05:00
Haithem Rahmani 47b2a17d4b Add new levelx APIs
New APIs
--------
- lx_nor_flash_format(): erases nor flash blocks and setup block metadata
- lx_nor_flash_open_extended(): same as lx_nor_flash_open() with
  user data pointer a last argument.
- lx_nand_flash_open_extended(): same as lx_nand_flash_open() with
  user data pointer a last argument.

Updates
-------
- lx_nor_flash_open(): calls lx_nor_flash_open_extended() with a NULL as
  last argument
- lx_nand_flash_open(): calls lx_nand_flash_open_extended() with a NULL as
  last argument
- regression tests: to call the lx_nor_flash_format()

Test results
-------------
100% tests passed, 0 tests failed out of 3

Total Test time (real) =   6.27 sec
3/3 Test #1: standalone_free_sector_verify_build::levelx_nand_flash_test ........   Passed    6.29 sec

100% tests passed, 0 tests failed out of 3

Total Test time (real) =   6.29 sec
3/3 Test #1: nor_obsolete_mapping_cache_build::levelx_nand_flash_test ........   Passed    6.58 sec

100% tests passed, 0 tests failed out of 3

Total Test time (real) =   6.58 sec
3/3 Test #1: nor_obsolete_cache_build::levelx_nand_flash_test ........   Passed    6.67 sec

100% tests passed, 0 tests failed out of 3

Total Test time (real) =   6.67 sec
3/3 Test #1: nor_mapping_cache_build::levelx_nand_flash_test ........   Passed    6.77 sec

100% tests passed, 0 tests failed out of 3

Total Test time (real) =   6.78 sec
3/3 Test #1: full_build::levelx_nand_flash_test ........   Passed    6.91 sec

100% tests passed, 0 tests failed out of 3

Total Test time (real) =   6.91 sec
3/3 Test #1: free_sector_verify_build::levelx_nand_flash_test ........   Passed    7.14 sec

100% tests passed, 0 tests failed out of 3

Total Test time (real) =   7.14 sec
3/3 Test #1: standalone_full_build::levelx_nand_flash_test ........   Passed    7.21 sec

100% tests passed, 0 tests failed out of 3

Total Test time (real) =   7.21 sec
3/3 Test #1: standalone_build::levelx_nand_flash_test ........   Passed   12.05 sec

100% tests passed, 0 tests failed out of 3

Total Test time (real) =  12.06 sec
3/3 Test #1: default_build_coverage::levelx_nand_flash_test ........   Passed   48.78 sec

100% tests passed, 0 tests failed out of 3

Total Test time (real) =  48.81 sec

Add new levelx APIs

New APIs
--------
- lx_nor_flash_format(): erases nor flash blocks and setup block metadata
- lx_nor_flash_open_extended(): same as lx_nor_flash_open() with
  user data pointer a last argument.
- lx_nand_flash_open_extended(): same as lx_nand_flash_open() with
  user data pointer a last argument.

Updates
-------
- lx_nor_flash_open(): calls lx_nor_flash_open_extended() with a NULL as
  last argument
- lx_nand_flash_open(): calls lx_nand_flash_open_extended() with a NULL as
  last argument
- regression tests: to call the lx_nor_flash_format()

Test results
-------------
100% tests passed, 0 tests failed out of 3

Total Test time (real) =   6.27 sec
3/3 Test #1: standalone_free_sector_verify_build::levelx_nand_flash_test ........   Passed    6.29 sec

100% tests passed, 0 tests failed out of 3

Total Test time (real) =   6.29 sec
3/3 Test #1: nor_obsolete_mapping_cache_build::levelx_nand_flash_test ........   Passed    6.58 sec

100% tests passed, 0 tests failed out of 3

Total Test time (real) =   6.58 sec
3/3 Test #1: nor_obsolete_cache_build::levelx_nand_flash_test ........   Passed    6.67 sec

100% tests passed, 0 tests failed out of 3

Total Test time (real) =   6.67 sec
3/3 Test #1: nor_mapping_cache_build::levelx_nand_flash_test ........   Passed    6.77 sec

100% tests passed, 0 tests failed out of 3

Total Test time (real) =   6.78 sec
3/3 Test #1: full_build::levelx_nand_flash_test ........   Passed    6.91 sec

100% tests passed, 0 tests failed out of 3

Total Test time (real) =   6.91 sec
3/3 Test #1: free_sector_verify_build::levelx_nand_flash_test ........   Passed    7.14 sec

100% tests passed, 0 tests failed out of 3

Total Test time (real) =   7.14 sec
3/3 Test #1: standalone_full_build::levelx_nand_flash_test ........   Passed    7.21 sec

100% tests passed, 0 tests failed out of 3

Total Test time (real) =   7.21 sec
3/3 Test #1: standalone_build::levelx_nand_flash_test ........   Passed   12.05 sec

100% tests passed, 0 tests failed out of 3

Total Test time (real) =  12.06 sec
3/3 Test #1: default_build_coverage::levelx_nand_flash_test ........   Passed   48.78 sec

100% tests passed, 0 tests failed out of 3

Total Test time (real) =  48.81 sec

fix: Write the correct meta data on the block after erase

add missing nand_flash_format_extended API
2025-11-14 18:24:59 +01:00
Haithem Rahmani 0f7dd521e5 fix: Wrong out of range check in lx_nand_flash_block_find
Fix issue 53

Signed-off-by: Haithem Rahmani <haithem.rahmani@st.com>
2025-11-04 16:51:46 +01:00
Haithem Rahmani b5dcbff38c fix: "array out of bounds" error leading to memory corruption
Fix description
----------------
add missing checks on the index of nor_flash -> lx_nor_flash_extended_cache[i]

Fixes Issue#58

Signed-off-by: Haithem Rahmani <haithem.rahmani@st.com>
2025-11-04 08:51:41 +01:00
Haithem Rahmani 7d1ef20acf fix: "array out of bounds" error leading to memory corruption
Fix description
----------------
add missing checks on the index of nor_flash -> lx_nor_flash_extended_cache[i]

Fixes Issue#58

Signed-off-by: Haithem Rahmani <haithem.rahmani@st.com>
2025-10-22 16:14:04 +01:00
Frédéric Desbiens 04e385f3d5 Merge pull request #50 from ayedm1/fix_levelx_github_action_job
fix github levelx regression test action issue
2024-12-12 17:31:11 +01:00
Mohamed AYED 7c5d83d794 update regression_test.yml
fix github levelx regression test action issue

update regression_test.yml

uses: azure-rtos/threadx/.github/workflows/regression_template.yml@master
==>
uses: eclipse-threadx/threadx/.github/workflows/regression_template.yml@master
2024-11-29 21:54:31 +01:00
Stefan Wick 24eb7d8692 Merge pull request #40 from eclipse-threadx/wickste-patch-6
Update branding in issues templates
2024-03-10 22:18:15 -07:00
Stefan Wick 058b242a9a Update hardware-or-architecture-support.md 2024-03-10 22:04:45 -07:00
Stefan Wick a3c9691d89 Update feature_request.md 2024-03-10 22:04:18 -07:00
Stefan Wick f5a55077ad Update bug_report.md 2024-03-10 22:03:35 -07:00
Stefan Wick 656d1490f4 Merge pull request #39 from eclipse-threadx/wickste-patch-5
Update README.md
2024-03-07 07:20:23 -08:00
Stefan Wick 8e1d00b591 Update README.md 2024-03-06 16:56:23 -08:00
Stefan Wick f8899e5d6d Merge pull request #38 from eclipse-threadx/bo-ms/add_revision_history
Add revision history file.
2024-02-27 17:24:08 -08:00
Stefan Wick acc5190739 Merge branch 'master' into bo-ms/add_revision_history 2024-02-27 17:14:01 -08:00
Stefan Wick 79cbf4019f Merge branch 'master' into bo-ms/add_revision_history 2024-02-27 17:11:51 -08:00
Stefan Wick 2a963969bc Merge pull request #37 from eclipse-threadx/tizho/update_version
Update version number to 6.4.1
2024-02-27 17:07:24 -08:00
Bo Chen (from Dev Box) 1317123fdc Add revision history file. 2024-02-27 16:58:07 +08:00
TiejunZhou 814a8a346c Update version number to 6.4.1 2024-02-27 06:37:17 +00:00
Stefan Wick 34616e26e7 Merge pull request #35 from eclipse-threadx/wickste-patch-4
Update README.md
2024-02-21 07:09:23 -08:00
Stefan Wick f840cf4ce6 Update README.md 2024-02-20 22:51:45 -08:00
Stefan Wick ec683ddf14 Merge pull request #33 from eclipse-threadx/wickste-patch-3
Update LICENSE.txt and Delete LICENSED-HARDWARE.txt
2024-02-13 12:23:50 -08:00
Stefan Wick 1d6706dfa9 Merge branch 'master' into wickste-patch-3 2024-02-12 09:04:40 -08:00
Stefan Wick 6809f87fdd Merge pull request #32 from eclipse-threadx/wickste-patch-2
Update CONTRIBUTING.md
2024-02-12 08:20:24 -08:00
Stefan Wick 9b766d144f Merge branch 'master' into wickste-patch-2 2024-02-12 08:20:12 -08:00
Stefan Wick fb4b913dc2 Merge pull request #31 from eclipse-threadx/wickste-patch-1
Create SECURITY.md
2024-02-09 10:48:15 -08:00
Stefan Wick 01517ad256 Delete LICENSED-HARDWARE.txt 2024-02-06 21:41:48 -08:00
Stefan Wick 9f85e68bd1 Update LICENSE.txt 2024-02-06 21:41:28 -08:00
Stefan Wick bc8f7f3623 Update CONTRIBUTING.md 2024-02-06 21:15:04 -08:00
Stefan Wick 3ca016c042 Create SECURITY.md 2024-02-06 18:34:50 -08:00
Stefan Wick 4e747beb15 Merge pull request #30 from eclipse-threadx/bo-ms/copyright
Update copyright.
2024-01-28 22:20:07 -08:00
Bo Chen (from Dev Box) 151863ad7c Update copyright. 2024-01-29 14:15:48 +08:00
Stefan Wick d7b2a72452 Merge pull request #29 from ericwol-msft/SECURITY.md-update
Delete SECURITY.md
2024-01-18 17:53:20 -08:00
Eric Wolz e432e2cfa2 Delete SECURITY.md 2024-01-18 11:38:21 -08:00
Stefan Wick 0ea87a458d Merge pull request #28 from eclipse-threadx/tizho/update_script
Update links in run.sh script
2024-01-12 14:03:10 -08:00
TiejunZhou f8ab75e3ee Update links in run.sh script 2024-01-12 05:58:52 +00:00
86 changed files with 5722 additions and 5940 deletions
+2 -2
View File
@@ -1,6 +1,6 @@
--- ---
name: Bug report name: Bug report
about: Create a report to help us improve Azure RTOS. about: Create a report to help us improve Eclipse ThreadX.
title: '' title: ''
labels: bug labels: bug
assignees: '' assignees: ''
@@ -13,7 +13,7 @@ A clear and concise description of what the bug is.
Please also mention any information which could help others to understand Please also mention any information which could help others to understand
the problem you're facing: the problem you're facing:
- What target device are you using? - What target device are you using?
- Which version of Azure RTOS? - Which version of Eclipse ThreadX?
- What toolchain and environment? - What toolchain and environment?
- What have you tried to diagnose or workaround this issue? - What have you tried to diagnose or workaround this issue?
+1 -1
View File
@@ -1,6 +1,6 @@
--- ---
name: Feature request name: Feature request
about: Suggest an idea or enhancement to existing feature for Azure RTOS. about: Suggest an idea or enhancement to existing feature for Eclipse ThreadX.
title: '' title: ''
labels: feature labels: feature
assignees: '' assignees: ''
@@ -8,12 +8,12 @@ assignees: ''
--- ---
**Is this request related to a particular hardware platform, SoC, board? Please describe.** **Is this request related to a particular hardware platform, SoC, board? Please describe.**
Describe in details the hardware support being requested and why this support benefits Azure RTOS. Describe in details the hardware support being requested and why this support benefits Eclipse ThreadX.
**Describe why you are asking for this support?** **Describe why you are asking for this support?**
Describe why you are asking for this support. Describe why you are asking for this support.
If this is a new board or SoC, please state whether you are willing to maintain the Azure RTOS support together with you. If this is a new board or SoC, please state whether you are willing to maintain the Eclipse ThreadX support together with you.
**Additional context** **Additional context**
Add any other context or graphics (drag-and-drop an image) about the hardware here. Add any other context or graphics (drag-and-drop an image) about the hardware here.
+1 -1
View File
@@ -22,4 +22,4 @@ jobs:
pull-requests: write pull-requests: write
pages: write pages: write
id-token: write id-token: write
uses: azure-rtos/threadx/.github/workflows/regression_template.yml@master uses: eclipse-threadx/threadx/.github/workflows/regression_template.yml@master
+1 -1
View File
@@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 3.0.0 FATAL_ERROR) cmake_minimum_required(VERSION 3.13 FATAL_ERROR)
# Set up the project # Set up the project
project(levelx project(levelx
+69 -11
View File
@@ -1,14 +1,72 @@
# Contributing # Contributing to Eclipse ThreadX
This project welcomes contributions and suggestions. Most contributions require you to Thanks for your interest in this project.
agree to a Contributor License Agreement (CLA) declaring that you have the right to,
and actually do, grant us the rights to use your contribution. For details, visit
https://cla.microsoft.com.
When you submit a pull request, a CLA-bot will automatically determine whether you need ## Project description
to provide a CLA and decorate the PR appropriately (e.g., label, comment). Simply follow the
instructions provided by the bot. You will only need to do this once across all repositories using our CLA.
This project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/). Eclipse ThreadX provides a vendor-neutral, open source, safety certified OS for
For more information see the [Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/) real-time applications published on under a permissive license. The Eclipse
or contact [opencode@microsoft.com](mailto:opencode@microsoft.com) with any additional questions or comments. ThreadX suite encompasses:
* ThreadX - advanced real-time operating system (RTOS) designed specifically for deeply embedded applications
* NetX Duo - advanced, industrial-grade TCP/IP network stack designed specifically for deeply embedded real-time and IoT applications
* FileX - high-performance, FAT-compatible file system thats fully integrated with ThreadX kernel
* GUIX - provides a complete, embedded graphical user interface (GUI) library
* USBX - high-performance USB host, device, and on-the-go (OTG) embedded stack, that is fully integrated with ThreadX kernel
* LevelX - Flash Wear Leveling for FileX and stand-alone purposes
* GuiX Studio - design environment, facilitating the creation and maintenance of all graphical elements for GUIX
* TraceX - analysis tool that provides a graphical view of real-time system events to better understand the behavior of real-time systems
Project site: https://projects.eclipse.org/projects/iot.threadx
## Terms of Use
This repository is subject to the Terms of Use of the Eclipse Foundation
https://www.eclipse.org/legal/termsofuse.php
## Developer resources
Information regarding source code management, builds, coding standards, and more.
https://projects.eclipse.org/projects/iot.threadx/developer
The project maintains the following source code repositories
* https://github.com/eclipse-threadx/.github
* https://github.com/eclipse-threadx/cmsis-packs
* https://github.com/eclipse-threadx/filex
* https://github.com/eclipse-threadx/getting-started
* https://github.com/eclipse-threadx/guix
* https://github.com/eclipse-threadx/levelx
* https://github.com/eclipse-threadx/netxduo
* https://github.com/eclipse-threadx/rtos-docs
* https://github.com/eclipse-threadx/samples
* https://github.com/eclipse-threadx/threadx
* https://github.com/eclipse-threadx/threadx-learn-samples
* https://github.com/eclipse-threadx/tracex
* https://github.com/eclipse-threadx/usbx
## Eclipse Development Process
This Eclipse Foundation open project is governed by the Eclipse Foundation
Development Process and operates under the terms of the Eclipse IP Policy.
* https://eclipse.org/projects/dev_process
* https://www.eclipse.org/org/documents/Eclipse_IP_Policy.pdf
## Eclipse Contributor Agreement
In order to be able to contribute to Eclipse Foundation projects you must electronically sign the Eclipse Contributor Agreement (ECA).
https://www.eclipse.org/legal/ECA.php
The ECA provides the Eclipse Foundation with a permanent record that you agree
that each of your contributions will comply with the commitments documented in
the Developer Certificate of Origin (DCO). Having an ECA on file associated with
the email address matching the "Author" field of your contribution's Git commits
fulfills the DCO's requirement that you sign-off on your contributions.
For more information, please see the Eclipse Committer Handbook:
https://www.eclipse.org/projects/handbook/#resources-commit
## Contact
Contact the project developers via the project's "dev" list.
https://accounts.eclipse.org/mailing-list/threadx-dev
+17 -245
View File
@@ -1,249 +1,21 @@
MICROSOFT SOFTWARE LICENSE TERMS MIT License
MICROSOFT AZURE RTOS Copyright (c) 2024 - present Microsoft Corporation
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
These license terms are an agreement between you and Microsoft Corporation (or The above copyright notice and this permission notice shall be included in all
one of its affiliates). They apply to the software named above and any Microsoft copies or substantial portions of the Software.
services or software updates (except to the extent such services or updates are
accompanied by new or additional terms, in which case those different terms
apply prospectively and do not alter your or Microsofts rights relating to
pre-updated software or services). IF YOU COMPLY WITH THESE LICENSE TERMS, YOU
HAVE THE RIGHTS BELOW. BY USING THE SOFTWARE, YOU ACCEPT THESE TERMS.
1. INSTALLATION AND USE RIGHTS. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
a) General. You may (I) install, use and modify the software and (ii) install and use the included Microsoft FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
Applications (if any), each solely for internal development, testing and evaluation purposes. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
Distribution or production use is governed by the license terms set forth in LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
Section 2. You may also obtain distribution or production use rights through a separate agreement with OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
Microsoft. SOFTWARE.
b) Contributions. Microsoft welcomes contributions to this software. In the event
that you make a contribution to this software you will be required to agree to a
Contributor License Agreement (CLA) declaring that you have the right to, and
actually do, grant Microsoft the rights to use your contribution. For details,
visit https://cla.microsoft.com.
c) Included Microsoft Applications. The software may include other Microsoft
applications which are governed by the licenses embedded in or made available
with those applications.
d) Third Party Components. The software may include third party components with
separate legal notices or governed by other agreements, as may be described
within the software or in the ThirdPartyNotices file(s) accompanying the
software.
e) Competitive Benchmarking. If you are a direct competitor, and you access or use
the software for purposes of competitive benchmarking, analysis, or intelligence
gathering, you waive as against Microsoft, its subsidiaries, and its affiliated
companies (including prospectively) any competitive use, access, and
benchmarking test restrictions in the terms governing your software to the
extent your terms of use are, or purport to be, more restrictive than
Microsofts terms. If you do not waive any such purported restrictions in the
terms governing your software, you are not allowed to access or use this
software, and will not do so.
2. DISTRIBUTION AND PRODUCTION USE. If you have obtained and/or are developing on
microprocessor(s) and/or microcontroller(s) (“hardware”) listed in the file
named “LICENSED-HARDWARE.txt” included in the repository and/or distributed with
the software you have the following rights in and to the software solely when
used in combination with the hardware. In the event hardware is not listed in
the LICENSED-HARDWARE.txt file, you do not have the rights in this Section 2.
a) Distribution and Production Use Rights.
i. You may use the software in production (e.g. program the modified or unmodified
software to devices you own or control) and distribute (i.e. make available to
third parties) the modified or unmodified binary image produced from this code.
ii. You may permit your device distributors or developers to copy and distribute the
binary image as programmed or to be programmed to your devices.
iii. You may redistribute the unmodified or modified source to your device
distributors or developers. Modifications must be clearly marked. Any
redistribution in source code form must contain this license and any other
licenses that accompany the software.
b) Requirements. For any code you distribute, you must:
i. when distributed in binary form, except as embedded in a device, include with
such distribution the terms of this agreement;
ii. when distributed in source code form to distributors or developers of your
devices, include with such distribution the terms of this agreement; and
iii. indemnify, defend and hold harmless Microsoft from any claims, including claims arising from any High Risk Uses, and inclusive of attorneys fees, related to the distribution or use of your devices that include the software, except to the extent that any intellectual property claim is based solely on the unmodified software.
c) Restrictions. You may not:
i. use or modify the software to create competing real time operating system
software;
ii. remove any copyright notices or licenses contained in the software;
iii. use Microsofts trademarks or trade dress in your application in any way that
suggests your device or application comes from or is endorsed by Microsoft;
iv. transfer individual components, specific libraries, classes, functions or code
fragments of the software separately for purposes unrelated to the software; or
v. use or distribute the software in any way that would subject the software or
Microsofts intellectual property or technology to any other license terms.
3. SCOPE OF LICENSE. The software is licensed, not sold. Microsoft reserves all
other rights. Unless applicable law gives you more rights despite this
limitation, you will not (and have no right to):
a) remove, minimize, block, or modify any notices of Microsoft or its suppliers in
the software;
b) use the software in any way that is against the law or to create or propagate
malware; or
c) share, publish, distribute, or lease the software (except as permitted in
Section 2 above), or provide the software as a stand-alone offering for others
to use.
4. DATA. This software may interact with other Microsoft products that collect data
that is transmitted to Microsoft. To learn more about how Microsoft processes
personal data we collect, please see the Microsoft Privacy Statement at
https://go.microsoft.com/fwlink/?LinkId=248681.
5. EXPORT RESTRICTIONS. You must comply with all domestic and international export
laws and regulations that apply to the software, which include restrictions on
destinations, end users, and end use. For further information on export
restrictions, visit https://aka.ms/exporting.
6. SUPPORT SERVICES. Microsoft is not obligated under this agreement to provide any
support services for the software. Any support provided is “as is”, “with all
faults”, and without warranty of any kind.
7. UPDATES. Microsoft may periodically update the software. You may obtain updates
only from Microsoft or Microsoft-authorized sources. Updates may not include or
support all existing software features, services, or peripheral devices.
8. TERMINATION. Without prejudice to any other rights, Microsoft may terminate this
agreement if you fail to comply with any of its terms or conditions. In such
event, you must destroy all copies of the software and all of its component
parts.
9. ENTIRE AGREEMENT. This agreement, and any other terms Microsoft may provide for
supplements, updates, or third-party applications, is the entire agreement for
the software. To the extent you have entered into a separate agreement with
Microsoft relating specifically to the software, the terms in such agreement
shall control.
10. APPLICABLE LAW AND PLACE TO RESOLVE DISPUTES. If you acquired the software in
the United States or Canada, the laws of the state or province where you live
(or, if a business, where your principal place of business is located) govern
the interpretation of this agreement, claims for its breach, and all other
claims (including consumer protection, unfair competition, and tort claims),
regardless of conflict of laws principles. If you acquired the software in any
other country, its laws apply. If U.S. federal jurisdiction exists, you and
Microsoft consent to exclusive jurisdiction and venue in the federal court in
King County, Washington for all disputes heard in court. If not, you and
Microsoft consent to exclusive jurisdiction and venue in the Superior Court of
King County, Washington for all disputes heard in court.
11. CONSUMER RIGHTS; REGIONAL VARIATIONS. This agreement describes certain legal
rights. You may have other rights, including consumer rights, under the laws of
your state or country. Separate and apart from your relationship with Microsoft,
you may also have rights with respect to the party from which you acquired the
software. This agreement does not change those other rights if the laws of your
state or country do not permit it to do so. For example, if you acquired the
software in one of the below regions, or mandatory country law applies, then the
following provisions apply to you:
a) Australia. You have statutory guarantees under the Australian Consumer Law and
nothing in this agreement is intended to affect those rights.
b) Germany and Austria.
i. Warranty. The properly licensed software will perform substantially as
described in any Microsoft materials that accompany the software. However,
Microsoft gives no contractual guarantee in relation to the licensed software.
ii. Limitation of Liability. In case of intentional conduct, gross negligence,
claims based on the Product Liability Act, as well as, in case of death or
personal or physical injury, Microsoft is liable according to the statutory law.
Subject to the foregoing clause ii., Microsoft will only be liable for slight
negligence if Microsoft is in breach of such material contractual obligations,
the fulfillment of which facilitate the due performance of this agreement, the
breach of which would endanger the purpose of this agreement and the compliance
with which a party may constantly trust in (so-called "cardinal obligations").
In other cases of slight negligence, Microsoft will not be liable for slight
negligence.
12. DISCLAIMER OF WARRANTY.
a) THE SOFTWARE IS LICENSED “AS IS.” YOU BEAR THE RISK OF
USING IT. MICROSOFT GIVES NO EXPRESS WARRANTIES, GUARANTEES, OR CONDITIONS. TO
THE EXTENT PERMITTED UNDER APPLICABLE LAWS, MICROSOFT EXCLUDES ALL IMPLIED
WARRANTIES, INCLUDING MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, AND
NON-INFRINGEMENT.
b) HIGH RISK USE DISCLAIMER. WARNING: THE SOFTWARE IS NOT DESIGNED OR INTENDED FOR USE WHERE FAILURE OR FAULT OF ANY KIND OF THE SOFTWARE COULD RESULT IN DEATH OR SERIOUS BODILY INJURY, OR IN PHYSICAL OR ENVIRONMENTAL DAMAGE (“collectively High Risk Use”). Accordingly, You must design and implement your hardware and software such that, in the event of any interruption, defect, error, or other failure of the software, the safety of people, property, and the environment are not reduced below a level that is reasonable, appropriate, and legal, whether in general or for a specific industry. Your High Risk Use of the software is at Your own risk.
13. LIMITATION ON AND EXCLUSION OF DAMAGES. IF YOU HAVE ANY BASIS FOR RECOVERING
DAMAGES DESPITE THE PRECEDING DISCLAIMER OF WARRANTY, YOU CAN RECOVER FROM
MICROSOFT AND ITS SUPPLIERS ONLY DIRECT DAMAGES UP TO U.S. $5.00. YOU CANNOT
RECOVER ANY OTHER DAMAGES, INCLUDING CONSEQUENTIAL, LOST PROFITS, SPECIAL,
INDIRECT, OR INCIDENTAL DAMAGES.
This limitation applies to (a) anything related to the software, services,
content (including code) on third party Internet sites, or third party
applications; and (b) claims for breach of contract, warranty, guarantee, or
condition; strict liability, negligence, or other tort; or any other claim; in
each case to the extent permitted by applicable law.
It also applies even if Microsoft knew or should have known about the
possibility of the damages. The above limitation or exclusion may not apply to
you because your state, province, or country may not allow the exclusion or
limitation of incidental, consequential, or other damages.
Please note: As this software is distributed in Canada, some of the clauses in
this agreement are provided below in French.
Remarque: Ce logiciel étant distribué au Canada, certaines des clauses dans ce
contrat sont fournies ci-dessous en français.
EXONÉRATION DE GARANTIE.
a) Le logiciel visé par une licence est offert « tel quel
». Toute utilisation de ce logiciel est à votre seule risque et péril. Microsoft
naccorde aucune autre garantie expresse. Vous pouvez bénéficier de droits
additionnels en vertu du droit local sur la protection des consommateurs, que ce
contrat ne peut modifier. La ou elles sont permises par le droit locale, les
garanties implicites de qualité marchande, dadéquation à un usage particulier
et dabsence de contrefaçon sont exclues.
b) CLAUSE DEXCLUSION DE RESPONSABILITÉ RELATIVE À LUTILISATION À HAUT RISQUE.
AVERTISSEMENT: LE LOGICIEL NEST PAS CONÇU OU DESTINÉ À ÊTRE UTILISÉ LORSQUUNE
DÉFAILLANCE OU UN DÉFAUT DE QUELQUE NATURE QUE CE SOIT POURRAIT ENTRAÎNER LA
MORT OU DES BLESSURES CORPORELLES GRAVES, OU DES DOMMAGES PHYSIQUES OU
ENVIRONNEMENTAUX (« Utilisation à haut risque »). Par conséquent, vous devez concevoir et mettre en
œuvre votre équipement et votre logiciel de manière à ce que, en cas dinterruption, de défaut, derreur
ou de toute autre défaillance du logiciel, la sécurité des personnes, des biens et de lenvironnement ne
soit pas réduite en dessous dun niveau raisonnable, approprié et légal, que ce soit en général ou pour
un secteur spécifique. Votre utilisation à haut risque du logiciel est à vos propres risques.
LIMITATION DES DOMMAGES-INTÉRÊTS ET EXCLUSION DE RESPONSABILITÉ POUR LES
DOMMAGES. Vous pouvez obtenir de Microsoft et de ses fournisseurs une
indemnisation en cas de dommages directs uniquement à hauteur de 5,00 $ US. Vous
ne pouvez prétendre à aucune indemnisation pour les autres dommages, y compris
les dommages spéciaux, indirects ou accessoires et pertes de bénéfices.
Cette limitation concerne:
•tout ce qui est relié au logiciel, aux services ou au contenu (y compris le
code) figurant sur des sites Internet tiers ou dans des programmes tiers; et
•les réclamations au titre de violation de contrat ou de garantie, ou au titre
de responsabilité stricte, de négligence ou dune autre faute dans la limite
autorisée par la loi en vigueur.
Elle sapplique également, même si Microsoft connaissait ou devrait connaître
l’éventualité dun tel dommage. Si votre pays nautorise pas lexclusion ou la
limitation de responsabilité pour les dommages indirects, accessoires ou de
quelque nature que ce soit, il se peut que la limitation ou lexclusion
ci-dessus ne sappliquera pas à votre égard.
EFFET JURIDIQUE. Le présent contrat décrit certains droits juridiques. Vous
pourriez avoir dautres droits prévus par les lois de votre pays. Le présent
contrat ne modifie pas les droits que vous confèrent les lois de votre pays si
celles-ci ne le permettent pas.
-45
View File
@@ -1,45 +0,0 @@
LICENSED HARDWARE LIST
Last Updated: 2023-02-10
Microsoft has entered into OEM Agreements with manufacturers of the following
microprocessors and microcontrollers (the “hardware”) to enable those
manufacturers to include and distribute Azure RTOS in certain hardware. If you
have obtained and/or are developing on microprocessor(s) and/or
microcontroller(s) (“hardware”) listed below you inherit the “Distribution and
Production Use” rights in Section 2 of the Microsoft Software License Terms for
Microsoft Azure RTOS. If hardware is not listed below, you do not have those
rights.
STMicroelectronics:
STM32 MCUs
STM32 MPUs
MediaTek:
MT3620 MCU (Azure Sphere)
Microchip:
PIC 32-bit MCUs
SAM 32-bit MCUs
SAM 32-bit MPUs
NXP:
i.MX RT10xx and RT116x/7x series crossover MCUs
LPC5500 series
MCX N series
Renesas:
Synergy Platform
RX Family of MCUs
RA Family of MCUs
RZ Family of MPUs
--------------------------------------------------------------------------------
More coming soon. Please check back frequently for updates.
+15 -23
View File
@@ -1,12 +1,12 @@
# Azure RTOS LevelX # Eclipse ThreadX LevelX
LevelX provides NAND and NOR flash wear leveling facilities to embedded applications. Since both NAND and NOR flash memory can only be erased a finite number of times, its critical to distribute the flash memory use evenly. This is typically called **wear leveling** and is the purpose behind LevelX. LevelX presents to the user an array of logical sectors that are mapped to physical flash memory inside of LevelX. Applications may use LevelX in conjunction with FileX or may read/write logical sectors directly. LevelX is designed for fault tolerance. Flash updates are performed in a multiple-step process that can be interrupted in each step. LevelX automatically recovers to the optimal state during the next operation. LevelX provides NAND and NOR flash wear leveling facilities to embedded applications. Since both NAND and NOR flash memory can only be erased a finite number of times, its critical to distribute the flash memory use evenly. This is typically called **wear leveling** and is the purpose behind LevelX. LevelX presents to the user an array of logical sectors that are mapped to physical flash memory inside of LevelX. Applications may use LevelX in conjunction with FileX or may read/write logical sectors directly. LevelX is designed for fault tolerance. Flash updates are performed in a multiple-step process that can be interrupted in each step. LevelX automatically recovers to the optimal state during the next operation.
## Getting Started ## Getting Started
Azure RTOS LevelX as part of Azure RTOS has been integrated to the semiconductor's SDKs and development environment. You can develop using the tools of choice from [STMicroelectronics](https://www.st.com/content/st_com/en/campaigns/x-cube-azrtos-azure-rtos-stm32.html), [NXP](https://www.nxp.com/design/software/embedded-software/azure-rtos-for-nxp-microcontrollers:AZURE-RTOS), [Renesas](https://github.com/renesas/azure-rtos) and [Microchip](https://mu.microchip.com/get-started-simplifying-your-iot-design-with-azure-rtos). LevelX as part of Eclipse ThreadX has been integrated to the semiconductor's SDKs and development environment. You can develop using the tools of choice from [STMicroelectronics](https://www.st.com/content/st_com/en/campaigns/x-cube-azrtos-azure-rtos-stm32.html), [NXP](https://www.nxp.com/design/software/embedded-software/azure-rtos-for-nxp-microcontrollers:AZURE-RTOS), [Renesas](https://github.com/renesas/azure-rtos) and [Microchip](https://mu.microchip.com/get-started-simplifying-your-iot-design-with-azure-rtos).
See [Overview of Azure RTOS LevelX](https://learn.microsoft.com/azure/rtos/levelx/overview-levelx) for the high-level overview, and all documentation and APIs can be found in: [Azure RTOS LevelX documentation](https://learn.microsoft.com/azure/rtos/levelx/). See [Overview of Eclipse ThreadX LevelX](https://github.com/eclipse-threadx/rtos-docs/blob/main/rtos-docs/levelx/index.md) for the high-level overview.
## Repository Structure and Usage ## Repository Structure and Usage
@@ -19,7 +19,7 @@ See [Overview of Azure RTOS LevelX](https://learn.microsoft.com/azure/rtos/level
├── LICENSE.txt # License terms ├── LICENSE.txt # License terms
├── LICENSE-HARDWARE.txt # Licensed hardware from semiconductors ├── LICENSE-HARDWARE.txt # Licensed hardware from semiconductors
├── CONTRIBUTING.md # Contribution guidance ├── CONTRIBUTING.md # Contribution guidance
└── SECURITY.md # Microsoft repo security guidance └── SECURITY.md # Repo security guidance
### Branches & Releases ### Branches & Releases
@@ -74,7 +74,7 @@ The master branch has the most recent code with all new features and bug fixes.
## Component dependencies ## Component dependencies
The main components of Azure RTOS are each provided in their own repository, but there are dependencies between them, as shown in the following graph. This is important to understand when setting up your builds. The main components of Eclipse ThreadX are each provided in their own repository, but there are dependencies between them, as shown in the following graph. This is important to understand when setting up your builds.
![dependency graph](docs/deps.png) ![dependency graph](docs/deps.png)
@@ -82,7 +82,7 @@ The main components of Azure RTOS are each provided in their own repository, but
### Building and using the library ### Building and using the library
Instruction for building the LevelX as static library using Arm GNU Toolchain and CMake. If you are using toolchain and IDE from semiconductor, you might follow its own instructions to use Azure RTOS components as explained in the [Getting Started](#getting-started) section. Instruction for building the LevelX as static library using Arm GNU Toolchain and CMake. If you are using toolchain and IDE from semiconductor, you might follow its own instructions to use Eclipse ThreadX components as explained in the [Getting Started](#getting-started) section.
1. Install the following tools: 1. Install the following tools:
@@ -95,14 +95,14 @@ Instruction for building the LevelX as static library using Arm GNU Toolchain an
1. Cloning the repo. 1. Cloning the repo.
```bash ```bash
$ git clone --recursive https://github.com/azure-rtos/levelx.git $ git clone --recursive https://github.com/eclipse-threadx/levelx.git
``` ```
1. Define the features and addons you need in `lx_user.h` and build together with the component source code. You can refer to [`lx_user_sample.h`](https://github.com/azure-rtos/levelx/blob/master/common/inc/lx_user_sample.h) as an example. 1. Define the features and addons you need in `lx_user.h` and build together with the component source code. You can refer to [`lx_user_sample.h`](https://github.com/azure-rtos/levelx/blob/master/common/inc/lx_user_sample.h) as an example.
1. Building as a static library 1. Building as a static library
Each component of Azure RTOS comes with a composable CMake-based build system that supports many different MCUs and host systems. Integrating any of these components into your device app code is as simple as adding a git submodule and then including it in your build using the CMake `add_subdirectory()`. Each component of Eclipse ThreadX comes with a composable CMake-based build system that supports many different MCUs and host systems. Integrating any of these components into your device app code is as simple as adding a git submodule and then including it in your build using the CMake `add_subdirectory()`.
While the typical usage pattern is to include LevelX into your device code source tree to be built & linked with your code, you can compile this project as a standalone static library to confirm your build is set up correctly. While the typical usage pattern is to include LevelX into your device code source tree to be built & linked with your code, you can compile this project as a standalone static library to confirm your build is set up correctly.
@@ -114,31 +114,23 @@ Instruction for building the LevelX as static library using Arm GNU Toolchain an
$ cmake --build ./build $ cmake --build ./build
``` ```
## Professional support
[Professional support plans](https://azure.microsoft.com/support/options/) are available from Microsoft. For community support and others, see the [Resources](#resources) section below.
## Licensing ## Licensing
License terms for using Azure RTOS are defined in the LICENSE.txt file of this repo. Please refer to this file for all definitive licensing information. No additional license fees are required for deploying Azure RTOS on hardware defined in the [LICENSED-HARDWARE.txt](./LICENSED-HARDWARE.txt) file. If you are using hardware not listed in the file or having licensing questions in general, please contact Microsoft directly at https://aka.ms/azrtos-license. License terms for using Eclipse ThreadX are defined in the LICENSE.txt file of this repo. Please refer to this file for all definitive licensing information for all content, incl. the history of this repo.
## Resources ## Resources
The following are references to additional Azure RTOS resources: The following are references to additional Eclipse ThreadX resources:
- **Product introduction and white papers**: https://azure.com/rtos - **Product introduction**: https://github.com/eclipse-threadx/rtos-docs
- **General technical questions**: https://aka.ms/QnA/azure-rtos - **Product issues and bugs, or feature requests**: https://github.com/eclipse-threadx/levelx/issues
- **Product issues and bugs, or feature requests**: https://github.com/azure-rtos/levelx/issues - **TraceX Installer**: https://aka.ms/azrtos-tracex-installer
- **Licensing and sales questions**: https://aka.ms/azrtos-license
- **Product roadmap and support policy**: https://aka.ms/azrtos/lts
- **Blogs and videos**: http://msiotblog.com and https://aka.ms/iotshow
- **Azure RTOS TraceX Installer**: https://aka.ms/azrtos-tracex-installer
You can also check [previous questions](https://stackoverflow.com/questions/tagged/azure-rtos+levelx) or ask new ones on StackOverflow using the `azure-rtos` and `levelx` tags. You can also check [previous questions](https://stackoverflow.com/questions/tagged/azure-rtos+levelx) or ask new ones on StackOverflow using the `threadx` and `levelx` tags.
## Security ## Security
Azure RTOS provides OEMs with components to secure communication and to create code and data isolation using underlying MCU/MPU hardware protection mechanisms. It is ultimately the responsibility of the device builder to ensure the device fully meets the evolving security requirements associated with its specific use case. Eclipse ThreadX provides OEMs with components to secure communication and to create code and data isolation using underlying MCU/MPU hardware protection mechanisms. It is ultimately the responsibility of the device builder to ensure the device fully meets the evolving security requirements associated with its specific use case.
## Contribution ## Contribution
+12 -27
View File
@@ -1,35 +1,20 @@
## Security # Security Policy
Microsoft takes the security of our software products and services seriously, which includes all source code repositories managed through our GitHub organizations, which include [Microsoft](https://github.com/Microsoft), [Azure](https://github.com/Azure), [DotNet](https://github.com/dotnet), [AspNet](https://github.com/aspnet), [Xamarin](https://github.com/xamarin), and [our GitHub organizations](https://opensource.microsoft.com/). ## Supported Versions
If you believe you have found a security vulnerability in any Microsoft-owned repository that meets Microsoft's [Microsoft's definition of a security vulnerability](https://docs.microsoft.com/en-us/previous-versions/tn-archive/cc751383(v=technet.10)), please report it to us as described below. | Version | Supported |
| ------- | ------------------ |
| 6.4.x | :white_check_mark: |
## Reporting Security Issues ## Reporting a Vulnerability
**Please do not report security vulnerabilities through public GitHub issues.** If you think you have found a vulnerability in <project> you can report it using one of the following ways:
Instead, please report them to the Microsoft Security Response Center (MSRC) at [https://msrc.microsoft.com/create-report](https://msrc.microsoft.com/create-report). * Contact the [Eclipse Foundation Security Team](mailto:security@eclipse-foundation.org)
* [Report a Vulnerability](https://github.com/eclipse-threadx/levelx/security/advisories/new)
If you prefer to submit without logging in, send email to [secure@microsoft.com](mailto:secure@microsoft.com). If possible, encrypt your message with our PGP key; please download it from the the [Microsoft Security Response Center PGP Key page](https://www.microsoft.com/en-us/msrc/pgp-key-msrc). You can find more information about reporting and disclosure at the [Eclipse Foundation Security page](https://www.eclipse.org/security/).
You should receive a response within 24 hours. If for some reason you do not, please follow up via email to ensure we received your original message. Additional information can be found at [microsoft.com/msrc](https://www.microsoft.com/msrc). ## Security Policy
Please include the requested information listed below (as much as you can provide) to help us better understand the nature and scope of the possible issue: This project follows [Eclipse Foundation Vulnerability Reporting Policy](https://www.eclipse.org/security/policy/).
* Type of issue (e.g. buffer overflow, SQL injection, cross-site scripting, etc.)
* Full paths of source file(s) related to the manifestation of the issue
* The location of the affected source code (tag/branch/commit or direct URL)
* Any special configuration required to reproduce the issue
* Step-by-step instructions to reproduce the issue
* Proof-of-concept or exploit code (if possible)
* Impact of the issue, including how an attacker might exploit the issue
This information will help us triage your report more quickly.
## Preferred Languages
We prefer all communications to be in English.
## Policy
Microsoft follows the principle of [Coordinated Vulnerability Disclosure](https://www.microsoft.com/en-us/msrc/cvd).
+4
View File
@@ -20,6 +20,7 @@ target_sources(${PROJECT_NAME} PRIVATE
${CMAKE_CURRENT_LIST_DIR}/src/lx_nand_flash_erase_count_set.c ${CMAKE_CURRENT_LIST_DIR}/src/lx_nand_flash_erase_count_set.c
${CMAKE_CURRENT_LIST_DIR}/src/lx_nand_flash_extended_cache_enable.c ${CMAKE_CURRENT_LIST_DIR}/src/lx_nand_flash_extended_cache_enable.c
${CMAKE_CURRENT_LIST_DIR}/src/lx_nand_flash_format.c ${CMAKE_CURRENT_LIST_DIR}/src/lx_nand_flash_format.c
${CMAKE_CURRENT_LIST_DIR}/src/lx_nand_flash_format_extended.c
${CMAKE_CURRENT_LIST_DIR}/src/lx_nand_flash_free_block_list_add.c ${CMAKE_CURRENT_LIST_DIR}/src/lx_nand_flash_free_block_list_add.c
${CMAKE_CURRENT_LIST_DIR}/src/lx_nand_flash_initialize.c ${CMAKE_CURRENT_LIST_DIR}/src/lx_nand_flash_initialize.c
${CMAKE_CURRENT_LIST_DIR}/src/lx_nand_flash_mapped_block_list_add.c ${CMAKE_CURRENT_LIST_DIR}/src/lx_nand_flash_mapped_block_list_add.c
@@ -30,6 +31,7 @@ target_sources(${PROJECT_NAME} PRIVATE
${CMAKE_CURRENT_LIST_DIR}/src/lx_nand_flash_metadata_build.c ${CMAKE_CURRENT_LIST_DIR}/src/lx_nand_flash_metadata_build.c
${CMAKE_CURRENT_LIST_DIR}/src/lx_nand_flash_metadata_write.c ${CMAKE_CURRENT_LIST_DIR}/src/lx_nand_flash_metadata_write.c
${CMAKE_CURRENT_LIST_DIR}/src/lx_nand_flash_open.c ${CMAKE_CURRENT_LIST_DIR}/src/lx_nand_flash_open.c
${CMAKE_CURRENT_LIST_DIR}/src/lx_nand_flash_open_extended.c
${CMAKE_CURRENT_LIST_DIR}/src/lx_nand_flash_page_ecc_check.c ${CMAKE_CURRENT_LIST_DIR}/src/lx_nand_flash_page_ecc_check.c
${CMAKE_CURRENT_LIST_DIR}/src/lx_nand_flash_page_ecc_compute.c ${CMAKE_CURRENT_LIST_DIR}/src/lx_nand_flash_page_ecc_compute.c
${CMAKE_CURRENT_LIST_DIR}/src/lx_nand_flash_partial_defragment.c ${CMAKE_CURRENT_LIST_DIR}/src/lx_nand_flash_partial_defragment.c
@@ -52,6 +54,8 @@ target_sources(${PROJECT_NAME} PRIVATE
${CMAKE_CURRENT_LIST_DIR}/src/lx_nor_flash_logical_sector_find.c ${CMAKE_CURRENT_LIST_DIR}/src/lx_nor_flash_logical_sector_find.c
${CMAKE_CURRENT_LIST_DIR}/src/lx_nor_flash_next_block_to_erase_find.c ${CMAKE_CURRENT_LIST_DIR}/src/lx_nor_flash_next_block_to_erase_find.c
${CMAKE_CURRENT_LIST_DIR}/src/lx_nor_flash_open.c ${CMAKE_CURRENT_LIST_DIR}/src/lx_nor_flash_open.c
${CMAKE_CURRENT_LIST_DIR}/src/lx_nor_flash_open_extended.c
${CMAKE_CURRENT_LIST_DIR}/src/lx_nor_flash_format.c
${CMAKE_CURRENT_LIST_DIR}/src/lx_nor_flash_partial_defragment.c ${CMAKE_CURRENT_LIST_DIR}/src/lx_nor_flash_partial_defragment.c
${CMAKE_CURRENT_LIST_DIR}/src/lx_nor_flash_physical_sector_allocate.c ${CMAKE_CURRENT_LIST_DIR}/src/lx_nor_flash_physical_sector_allocate.c
${CMAKE_CURRENT_LIST_DIR}/src/lx_nor_flash_sector_mapping_cache_invalidate.c ${CMAKE_CURRENT_LIST_DIR}/src/lx_nor_flash_sector_mapping_cache_invalidate.c
+67 -103
View File
@@ -1,19 +1,20 @@
/**************************************************************************/ /***************************************************************************
/* */ * Copyright (c) 2024 Microsoft Corporation
/* Copyright (c) Microsoft Corporation. All rights reserved. */ * Copyright (c) 2026-present Eclipse ThreadX contributors
/* */ * Portion Copyright (c) 2025 STMicroelectronics
/* This software is licensed under the Microsoft Software License */ *
/* Terms for Microsoft Azure RTOS. Full text of the license can be */ * This program and the accompanying materials are made available under the
/* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */ * terms of the MIT License which is available at
/* and in the root directory of this software. */ * https://opensource.org/licenses/MIT.
/* */ *
/**************************************************************************/ * SPDX-License-Identifier: MIT
**************************************************************************/
/**************************************************************************/ /**************************************************************************/
/**************************************************************************/ /**************************************************************************/
/** */ /** */
/** LevelX Component */ /** LevelX Component */
/** */ /** */
/** Application Interface (API) */ /** Application Interface (API) */
/** */ /** */
@@ -26,7 +27,7 @@
/* APPLICATION INTERFACE DEFINITION RELEASE */ /* APPLICATION INTERFACE DEFINITION RELEASE */
/* */ /* */
/* lx_api.h PORTABLE C */ /* lx_api.h PORTABLE C */
/* 6.4.0 */ /* 6.4.1 */
/* AUTHOR */ /* AUTHOR */
/* */ /* */
/* William E. Lamie, Microsoft Corporation */ /* William E. Lamie, Microsoft Corporation */
@@ -37,59 +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 */
/* */
/**************************************************************************/ /**************************************************************************/
#ifndef LX_API_H #ifndef LX_API_H
@@ -111,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"
@@ -200,8 +148,10 @@ 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 0 #define LEVELX_PATCH_VERSION 0
#define LEVELX_BUILD_VERSION 202601
#define LEVELX_HOTFIX_VERSION ' '
/* Define general LevelX Constants. */ /* Define general LevelX Constants. */
@@ -235,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. */
@@ -264,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. */
@@ -307,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)
@@ -340,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. */
@@ -417,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
@@ -504,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);
@@ -519,14 +469,13 @@ 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);
#endif #endif
UCHAR *lx_nand_flash_page_buffer; UCHAR *lx_nand_flash_page_buffer;
UINT lx_nand_flash_page_buffer_size; UINT lx_nand_flash_page_buffer_size;
#ifdef LX_THREAD_SAFE_ENABLE #ifdef LX_THREAD_SAFE_ENABLE
/* When this conditional is used, the LevelX code utilizes a ThreadX mutex for thread /* When this conditional is used, the LevelX code utilizes a ThreadX mutex for thread
@@ -534,15 +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 */
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;
@@ -552,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;
@@ -561,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
@@ -600,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;
@@ -636,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
@@ -654,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
@@ -664,12 +615,13 @@ typedef struct LX_NOR_FLASH_STRUCT
a higher layer. */ a higher layer. */
TX_MUTEX lx_nor_flash_mutex; TX_MUTEX lx_nor_flash_mutex;
#endif #endif
/* user data pointer optionally passed by the application to the driver via the lx_nor_flash_open_extended */
VOID *lx_nor_flash_driver_info_ptr;
/* 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
@@ -679,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
@@ -723,8 +675,10 @@ extern ULONG _lx_nor_flash_opened_cou
#define lx_nand_flash_partial_defragment _lx_nand_flash_partial_defragment #define lx_nand_flash_partial_defragment _lx_nand_flash_partial_defragment
#define lx_nand_flash_extended_cache_enable _lx_nand_flash_extended_cache_enable #define lx_nand_flash_extended_cache_enable _lx_nand_flash_extended_cache_enable
#define lx_nand_flash_format _lx_nand_flash_format #define lx_nand_flash_format _lx_nand_flash_format
#define lx_nand_flash_format_extended _lx_nand_flash_format_extended
#define lx_nand_flash_initialize _lx_nand_flash_initialize #define lx_nand_flash_initialize _lx_nand_flash_initialize
#define lx_nand_flash_open _lx_nand_flash_open #define lx_nand_flash_open _lx_nand_flash_open
#define lx_nand_flash_open_extended _lx_nand_flash_open_extended
#define lx_nand_flash_page_ecc_check _lx_nand_flash_page_ecc_check #define lx_nand_flash_page_ecc_check _lx_nand_flash_page_ecc_check
#define lx_nand_flash_page_ecc_compute _lx_nand_flash_page_ecc_compute #define lx_nand_flash_page_ecc_compute _lx_nand_flash_page_ecc_compute
#define lx_nand_flash_sector_read _lx_nand_flash_sector_read #define lx_nand_flash_sector_read _lx_nand_flash_sector_read
@@ -741,7 +695,9 @@ extern ULONG _lx_nor_flash_opened_cou
#define lx_nor_flash_partial_defragment _lx_nor_flash_partial_defragment #define lx_nor_flash_partial_defragment _lx_nor_flash_partial_defragment
#define lx_nor_flash_extended_cache_enable _lx_nor_flash_extended_cache_enable #define lx_nor_flash_extended_cache_enable _lx_nor_flash_extended_cache_enable
#define lx_nor_flash_initialize _lx_nor_flash_initialize #define lx_nor_flash_initialize _lx_nor_flash_initialize
#define lx_nor_flash_format _lx_nor_flash_format
#define lx_nor_flash_open _lx_nor_flash_open #define lx_nor_flash_open _lx_nor_flash_open
#define lx_nor_flash_open_extended _lx_nor_flash_open_extended
#define lx_nor_flash_sector_read _lx_nor_flash_sector_read #define lx_nor_flash_sector_read _lx_nor_flash_sector_read
#define lx_nor_flash_sector_release _lx_nor_flash_sector_release #define lx_nor_flash_sector_release _lx_nor_flash_sector_release
#define lx_nor_flash_sector_write _lx_nor_flash_sector_write #define lx_nor_flash_sector_write _lx_nor_flash_sector_write
@@ -757,7 +713,13 @@ UINT _lx_nand_flash_extended_cache_enable(LX_NAND_FLASH *nand_flash, VOID *m
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*),
ULONG* memory_ptr, UINT memory_size); ULONG* memory_ptr, UINT memory_size);
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,
ULONG* memory_ptr, UINT memory_size);
UINT _lx_nand_flash_open(LX_NAND_FLASH *nand_flash, CHAR *name, UINT (*nand_driver_initialize)(LX_NAND_FLASH *), ULONG* memory_ptr, UINT memory_size); UINT _lx_nand_flash_open(LX_NAND_FLASH *nand_flash, CHAR *name, UINT (*nand_driver_initialize)(LX_NAND_FLASH *), ULONG* memory_ptr, UINT memory_size);
UINT _lx_nand_flash_open_extended(LX_NAND_FLASH *nand_flash, CHAR *name,
UINT (*nand_driver_initialize)(LX_NAND_FLASH *), VOID *nand_driver_info_ptr,
ULONG* memory_ptr, UINT memory_size);
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);
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);
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);
@@ -772,7 +734,9 @@ UINT _lx_nor_flash_close(LX_NOR_FLASH *nor_flash);
UINT _lx_nor_flash_defragment(LX_NOR_FLASH *nor_flash); UINT _lx_nor_flash_defragment(LX_NOR_FLASH *nor_flash);
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);
UINT _lx_nor_flash_initialize(void); UINT _lx_nor_flash_initialize(void);
UINT _lx_nor_flash_format(LX_NOR_FLASH *nor_flash, CHAR *name, UINT (*nor_driver_initialize)(LX_NOR_FLASH *), VOID *nor_driver_info_ptr);
UINT _lx_nor_flash_open(LX_NOR_FLASH *nor_flash, CHAR *name, UINT (*nor_driver_initialize)(LX_NOR_FLASH *)); UINT _lx_nor_flash_open(LX_NOR_FLASH *nor_flash, CHAR *name, UINT (*nor_driver_initialize)(LX_NOR_FLASH *));
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_partial_defragment(LX_NOR_FLASH *nor_flash, UINT max_blocks); UINT _lx_nor_flash_partial_defragment(LX_NOR_FLASH *nor_flash, UINT max_blocks);
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);
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);
@@ -824,5 +788,5 @@ VOID _lx_nor_flash_system_error(LX_NOR_FLASH *nor_flash, UINT error_code);
} }
#endif #endif
#endif #endif
+29 -46
View File
@@ -1,13 +1,13 @@
/**************************************************************************/ /***************************************************************************
/* */ * Copyright (c) 2024 Microsoft Corporation
/* Copyright (c) Microsoft Corporation. All rights reserved. */ * Copyright (c) 2026-present Eclipse ThreadX contributors
/* */ *
/* This software is licensed under the Microsoft Software License */ * This program and the accompanying materials are made available under the
/* Terms for Microsoft Azure RTOS. Full text of the license can be */ * terms of the MIT License which is available at
/* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */ * https://opensource.org/licenses/MIT.
/* and in the root directory of this software. */ *
/* */ * SPDX-License-Identifier: MIT
/**************************************************************************/ **************************************************************************/
/**************************************************************************/ /**************************************************************************/
@@ -40,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
@@ -64,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.
*/ */
/* /*
@@ -91,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.
*/ */
/* /*
@@ -119,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))
+112 -125
View File
@@ -1,19 +1,19 @@
/**************************************************************************/ /***************************************************************************
/* */ * Copyright (c) 2024 Microsoft Corporation
/* Copyright (c) Microsoft Corporation. All rights reserved. */ * Copyright (c) 2026-present Eclipse ThreadX contributors
/* */ *
/* This software is licensed under the Microsoft Software License */ * This program and the accompanying materials are made available under the
/* Terms for Microsoft Azure RTOS. Full text of the license can be */ * terms of the MIT License which is available at
/* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */ * https://opensource.org/licenses/MIT.
/* and in the root directory of this software. */ *
/* */ * SPDX-License-Identifier: MIT
/**************************************************************************/ **************************************************************************/
/**************************************************************************/ /**************************************************************************/
/**************************************************************************/ /**************************************************************************/
/** */ /** */
/** FileX Component */ /** FileX Component */
/** */ /** */
/** FileX NAND FLASH Simulator Driver */ /** FileX NAND FLASH Simulator Driver */
/** */ /** */
@@ -43,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
*/ */
@@ -66,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)
@@ -138,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
@@ -159,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.
@@ -174,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.
@@ -199,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. */
@@ -226,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;
@@ -246,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)
@@ -263,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--;
@@ -283,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;
@@ -296,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;
@@ -332,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
@@ -340,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
@@ -360,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;
@@ -377,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:
{ {
@@ -405,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;
@@ -426,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;
+106 -116
View File
@@ -1,19 +1,19 @@
/**************************************************************************/ /***************************************************************************
/* */ * Copyright (c) 2024 Microsoft Corporation
/* Copyright (c) Microsoft Corporation. All rights reserved. */ * Copyright (c) 2026-present Eclipse ThreadX contributors
/* */ *
/* This software is licensed under the Microsoft Software License */ * This program and the accompanying materials are made available under the
/* Terms for Microsoft Azure RTOS. Full text of the license can be */ * terms of the MIT License which is available at
/* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */ * https://opensource.org/licenses/MIT.
/* and in the root directory of this software. */ *
/* */ * SPDX-License-Identifier: MIT
/**************************************************************************/ **************************************************************************/
/**************************************************************************/ /**************************************************************************/
/**************************************************************************/ /**************************************************************************/
/** */ /** */
/** FileX Component */ /** FileX Component */
/** */ /** */
/** FileX NOR FLASH Simulator Driver */ /** FileX NOR FLASH Simulator Driver */
/** */ /** */
@@ -33,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
*/ */
@@ -59,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)
@@ -134,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
@@ -150,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.
@@ -165,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.
@@ -190,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. */
@@ -215,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++;
@@ -238,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:
{ {
@@ -249,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++;
@@ -275,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++;
@@ -324,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
@@ -332,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
@@ -352,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;
@@ -376,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:
{ {
@@ -413,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;
@@ -448,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;
+49 -59
View File
@@ -1,19 +1,19 @@
/**************************************************************************/ /***************************************************************************
/* */ * Copyright (c) 2024 Microsoft Corporation
/* Copyright (c) Microsoft Corporation. All rights reserved. */ * Copyright (c) 2026-present Eclipse ThreadX contributors
/* */ *
/* This software is licensed under the Microsoft Software License */ * This program and the accompanying materials are made available under the
/* Terms for Microsoft Azure RTOS. Full text of the license can be */ * terms of the MIT License which is available at
/* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */ * https://opensource.org/licenses/MIT.
/* and in the root directory of this software. */ *
/* */ * SPDX-License-Identifier: MIT
/**************************************************************************/ **************************************************************************/
/**************************************************************************/ /**************************************************************************/
/**************************************************************************/ /**************************************************************************/
/** */ /** */
/** LevelX Component */ /** LevelX Component */
/** */ /** */
/** NAND Flash */ /** NAND Flash */
/** */ /** */
@@ -35,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;
@@ -104,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);
} }
@@ -142,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. */
@@ -170,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. */
+61 -74
View File
@@ -1,19 +1,19 @@
/**************************************************************************/ /***************************************************************************
/* */ * Copyright (c) 2024 Microsoft Corporation
/* Copyright (c) Microsoft Corporation. All rights reserved. */ * Copyright (c) 2026-present Eclipse ThreadX contributors
/* */ *
/* This software is licensed under the Microsoft Software License */ * This program and the accompanying materials are made available under the
/* Terms for Microsoft Azure RTOS. Full text of the license can be */ * terms of the MIT License which is available at
/* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */ * https://opensource.org/licenses/MIT.
/* and in the root directory of this software. */ *
/* */ * SPDX-License-Identifier: MIT
/**************************************************************************/ **************************************************************************/
/**************************************************************************/ /**************************************************************************/
/**************************************************************************/ /**************************************************************************/
/** */ /** */
/** LevelX Component */ /** LevelX Component */
/** */ /** */
/** NAND Flash */ /** NAND Flash */
/** */ /** */
@@ -35,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)
@@ -106,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++;
} }
@@ -134,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;
@@ -146,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. */
@@ -161,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);
@@ -190,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);
@@ -200,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);
@@ -224,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];
+36 -42
View File
@@ -1,19 +1,19 @@
/**************************************************************************/ /***************************************************************************
/* */ * Copyright (c) 2024 Microsoft Corporation
/* Copyright (c) Microsoft Corporation. All rights reserved. */ * Copyright (c) 2026-present Eclipse ThreadX contributors
/* */ *
/* This software is licensed under the Microsoft Software License */ * This program and the accompanying materials are made available under the
/* Terms for Microsoft Azure RTOS. Full text of the license can be */ * terms of the MIT License which is available at
/* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */ * https://opensource.org/licenses/MIT.
/* and in the root directory of this software. */ *
/* */ * SPDX-License-Identifier: MIT
/**************************************************************************/ **************************************************************************/
/**************************************************************************/ /**************************************************************************/
/**************************************************************************/ /**************************************************************************/
/** */ /** */
/** LevelX Component */ /** LevelX Component */
/** */ /** */
/** NAND Flash */ /** NAND Flash */
/** */ /** */
@@ -35,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)
+45 -51
View File
@@ -1,19 +1,19 @@
/**************************************************************************/ /***************************************************************************
/* */ * Copyright (c) 2024 Microsoft Corporation
/* Copyright (c) Microsoft Corporation. All rights reserved. */ * Copyright (c) 2026-present Eclipse ThreadX contributors
/* */ *
/* This software is licensed under the Microsoft Software License */ * This program and the accompanying materials are made available under the
/* Terms for Microsoft Azure RTOS. Full text of the license can be */ * terms of the MIT License which is available at
/* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */ * https://opensource.org/licenses/MIT.
/* and in the root directory of this software. */ *
/* */ * SPDX-License-Identifier: MIT
/**************************************************************************/ **************************************************************************/
/**************************************************************************/ /**************************************************************************/
/**************************************************************************/ /**************************************************************************/
/** */ /** */
/** LevelX Component */ /** LevelX Component */
/** */ /** */
/** NAND Flash */ /** NAND Flash */
/** */ /** */
@@ -35,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)
+44 -50
View File
@@ -1,19 +1,19 @@
/**************************************************************************/ /***************************************************************************
/* */ * Copyright (c) 2024 Microsoft Corporation
/* Copyright (c) Microsoft Corporation. All rights reserved. */ * Copyright (c) 2026-present Eclipse ThreadX contributors
/* */ *
/* This software is licensed under the Microsoft Software License */ * This program and the accompanying materials are made available under the
/* Terms for Microsoft Azure RTOS. Full text of the license can be */ * terms of the MIT License which is available at
/* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */ * https://opensource.org/licenses/MIT.
/* and in the root directory of this software. */ *
/* */ * SPDX-License-Identifier: MIT
/**************************************************************************/ **************************************************************************/
/**************************************************************************/ /**************************************************************************/
/**************************************************************************/ /**************************************************************************/
/** */ /** */
/** LevelX Component */ /** LevelX Component */
/** */ /** */
/** NAND Flash */ /** NAND Flash */
/** */ /** */
@@ -35,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)
@@ -91,7 +85,7 @@ UINT _lx_nand_flash_block_find(LX_NAND_FLASH *nand_flash, ULONG logical_sector,
block_mapping_index = logical_sector / nand_flash -> lx_nand_flash_pages_per_block; block_mapping_index = logical_sector / nand_flash -> lx_nand_flash_pages_per_block;
/* Check the address range. */ /* Check the address range. */
if (block_mapping_index > nand_flash -> lx_nand_flash_block_mapping_table_size / sizeof(*nand_flash -> lx_nand_flash_block_mapping_table)) if (block_mapping_index >= nand_flash -> lx_nand_flash_block_mapping_table_size / sizeof(*nand_flash -> lx_nand_flash_block_mapping_table))
{ {
/* Out of range, return an error. */ /* Out of range, return an error. */
+39 -45
View File
@@ -1,19 +1,19 @@
/**************************************************************************/ /***************************************************************************
/* */ * Copyright (c) 2024 Microsoft Corporation
/* Copyright (c) Microsoft Corporation. All rights reserved. */ * Copyright (c) 2026-present Eclipse ThreadX contributors
/* */ *
/* This software is licensed under the Microsoft Software License */ * This program and the accompanying materials are made available under the
/* Terms for Microsoft Azure RTOS. Full text of the license can be */ * terms of the MIT License which is available at
/* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */ * https://opensource.org/licenses/MIT.
/* and in the root directory of this software. */ *
/* */ * SPDX-License-Identifier: MIT
/**************************************************************************/ **************************************************************************/
/**************************************************************************/ /**************************************************************************/
/**************************************************************************/ /**************************************************************************/
/** */ /** */
/** LevelX Component */ /** LevelX Component */
/** */ /** */
/** NAND Flash */ /** NAND Flash */
/** */ /** */
@@ -35,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)
@@ -100,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. */
+38 -44
View File
@@ -1,19 +1,19 @@
/**************************************************************************/ /***************************************************************************
/* */ * Copyright (c) 2024 Microsoft Corporation
/* Copyright (c) Microsoft Corporation. All rights reserved. */ * Copyright (c) 2026-present Eclipse ThreadX contributors
/* */ *
/* This software is licensed under the Microsoft Software License */ * This program and the accompanying materials are made available under the
/* Terms for Microsoft Azure RTOS. Full text of the license can be */ * terms of the MIT License which is available at
/* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */ * https://opensource.org/licenses/MIT.
/* and in the root directory of this software. */ *
/* */ * SPDX-License-Identifier: MIT
/**************************************************************************/ **************************************************************************/
/**************************************************************************/ /**************************************************************************/
/**************************************************************************/ /**************************************************************************/
/** */ /** */
/** LevelX Component */ /** LevelX Component */
/** */ /** */
/** NAND Flash */ /** NAND Flash */
/** */ /** */
@@ -35,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)
@@ -88,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. */
+38 -48
View File
@@ -1,19 +1,19 @@
/**************************************************************************/ /***************************************************************************
/* */ * Copyright (c) 2024 Microsoft Corporation
/* Copyright (c) Microsoft Corporation. All rights reserved. */ * Copyright (c) 2026-present Eclipse ThreadX contributors
/* */ *
/* This software is licensed under the Microsoft Software License */ * This program and the accompanying materials are made available under the
/* Terms for Microsoft Azure RTOS. Full text of the license can be */ * terms of the MIT License which is available at
/* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */ * https://opensource.org/licenses/MIT.
/* and in the root directory of this software. */ *
/* */ * SPDX-License-Identifier: MIT
/**************************************************************************/ **************************************************************************/
/**************************************************************************/ /**************************************************************************/
/**************************************************************************/ /**************************************************************************/
/** */ /** */
/** LevelX Component */ /** LevelX Component */
/** */ /** */
/** NAND Flash */ /** NAND Flash */
/** */ /** */
@@ -35,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)
@@ -106,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;
} }
} }
@@ -117,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
+45 -55
View File
@@ -1,19 +1,19 @@
/**************************************************************************/ /***************************************************************************
/* */ * Copyright (c) 2024 Microsoft Corporation
/* Copyright (c) Microsoft Corporation. All rights reserved. */ * Copyright (c) 2026-present Eclipse ThreadX contributors
/* */ *
/* This software is licensed under the Microsoft Software License */ * This program and the accompanying materials are made available under the
/* Terms for Microsoft Azure RTOS. Full text of the license can be */ * terms of the MIT License which is available at
/* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */ * https://opensource.org/licenses/MIT.
/* and in the root directory of this software. */ *
/* */ * SPDX-License-Identifier: MIT
/**************************************************************************/ **************************************************************************/
/**************************************************************************/ /**************************************************************************/
/**************************************************************************/ /**************************************************************************/
/** */ /** */
/** LevelX Component */ /** LevelX Component */
/** */ /** */
/** NAND Flash */ /** NAND Flash */
/** */ /** */
@@ -35,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,
@@ -201,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. */
+39 -52
View File
@@ -1,19 +1,19 @@
/**************************************************************************/ /***************************************************************************
/* */ * Copyright (c) 2024 Microsoft Corporation
/* Copyright (c) Microsoft Corporation. All rights reserved. */ * Copyright (c) 2026-present Eclipse ThreadX contributors
/* */ *
/* This software is licensed under the Microsoft Software License */ * This program and the accompanying materials are made available under the
/* Terms for Microsoft Azure RTOS. Full text of the license can be */ * terms of the MIT License which is available at
/* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */ * https://opensource.org/licenses/MIT.
/* and in the root directory of this software. */ *
/* */ * SPDX-License-Identifier: MIT
/**************************************************************************/ **************************************************************************/
/**************************************************************************/ /**************************************************************************/
/**************************************************************************/ /**************************************************************************/
/** */ /** */
/** LevelX Component */ /** LevelX Component */
/** */ /** */
/** NAND Flash */ /** NAND Flash */
/** */ /** */
@@ -35,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. */
+37 -51
View File
@@ -1,19 +1,19 @@
/**************************************************************************/ /***************************************************************************
/* */ * Copyright (c) 2024 Microsoft Corporation
/* Copyright (c) Microsoft Corporation. All rights reserved. */ * Copyright (c) 2026-present Eclipse ThreadX contributors
/* */ *
/* This software is licensed under the Microsoft Software License */ * This program and the accompanying materials are made available under the
/* Terms for Microsoft Azure RTOS. Full text of the license can be */ * terms of the MIT License which is available at
/* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */ * https://opensource.org/licenses/MIT.
/* and in the root directory of this software. */ *
/* */ * SPDX-License-Identifier: MIT
/**************************************************************************/ **************************************************************************/
/**************************************************************************/ /**************************************************************************/
/**************************************************************************/ /**************************************************************************/
/** */ /** */
/** LevelX Component */ /** LevelX Component */
/** */ /** */
/** NAND Flash */ /** NAND Flash */
/** */ /** */
@@ -35,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,19 +1,19 @@
/**************************************************************************/ /***************************************************************************
/* */ * Copyright (c) 2024 Microsoft Corporation
/* Copyright (c) Microsoft Corporation. All rights reserved. */ * Copyright (c) 2026-present Eclipse ThreadX contributors
/* */ *
/* This software is licensed under the Microsoft Software License */ * This program and the accompanying materials are made available under the
/* Terms for Microsoft Azure RTOS. Full text of the license can be */ * terms of the MIT License which is available at
/* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */ * https://opensource.org/licenses/MIT.
/* and in the root directory of this software. */ *
/* */ * SPDX-License-Identifier: MIT
/**************************************************************************/ **************************************************************************/
/**************************************************************************/ /**************************************************************************/
/**************************************************************************/ /**************************************************************************/
/** */ /** */
/** LevelX Component */ /** LevelX Component */
/** */ /** */
/** NAND Flash */ /** NAND Flash */
/** */ /** */
@@ -35,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,19 +1,19 @@
/**************************************************************************/ /***************************************************************************
/* */ * Copyright (c) 2024 Microsoft Corporation
/* Copyright (c) Microsoft Corporation. All rights reserved. */ * Copyright (c) 2026-present Eclipse ThreadX contributors
/* */ *
/* This software is licensed under the Microsoft Software License */ * This program and the accompanying materials are made available under the
/* Terms for Microsoft Azure RTOS. Full text of the license can be */ * terms of the MIT License which is available at
/* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */ * https://opensource.org/licenses/MIT.
/* and in the root directory of this software. */ *
/* */ * SPDX-License-Identifier: MIT
/**************************************************************************/ **************************************************************************/
/**************************************************************************/ /**************************************************************************/
/**************************************************************************/ /**************************************************************************/
/** */ /** */
/** LevelX Component */ /** LevelX Component */
/** */ /** */
/** NAND Flash */ /** NAND Flash */
/** */ /** */
@@ -35,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,19 +1,19 @@
/**************************************************************************/ /***************************************************************************
/* */ * Copyright (c) 2024 Microsoft Corporation
/* Copyright (c) Microsoft Corporation. All rights reserved. */ * Copyright (c) 2026-present Eclipse ThreadX contributors
/* */ *
/* This software is licensed under the Microsoft Software License */ * This program and the accompanying materials are made available under the
/* Terms for Microsoft Azure RTOS. Full text of the license can be */ * terms of the MIT License which is available at
/* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */ * https://opensource.org/licenses/MIT.
/* and in the root directory of this software. */ *
/* */ * SPDX-License-Identifier: MIT
/**************************************************************************/ **************************************************************************/
/**************************************************************************/ /**************************************************************************/
/**************************************************************************/ /**************************************************************************/
/** */ /** */
/** LevelX Component */ /** LevelX Component */
/** */ /** */
/** NAND Flash */ /** NAND Flash */
/** */ /** */
@@ -35,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,19 +1,19 @@
/**************************************************************************/ /***************************************************************************
/* */ * Copyright (c) 2024 Microsoft Corporation
/* Copyright (c) Microsoft Corporation. All rights reserved. */ * Copyright (c) 2026-present Eclipse ThreadX contributors
/* */ *
/* This software is licensed under the Microsoft Software License */ * This program and the accompanying materials are made available under the
/* Terms for Microsoft Azure RTOS. Full text of the license can be */ * terms of the MIT License which is available at
/* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */ * https://opensource.org/licenses/MIT.
/* and in the root directory of this software. */ *
/* */ * SPDX-License-Identifier: MIT
/**************************************************************************/ **************************************************************************/
/**************************************************************************/ /**************************************************************************/
/**************************************************************************/ /**************************************************************************/
/** */ /** */
/** LevelX Component */ /** LevelX Component */
/** */ /** */
/** NAND Flash */ /** NAND Flash */
/** */ /** */
@@ -35,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)
+39 -45
View File
@@ -1,19 +1,19 @@
/**************************************************************************/ /***************************************************************************
/* */ * Copyright (c) 2024 Microsoft Corporation
/* Copyright (c) Microsoft Corporation. All rights reserved. */ * Copyright (c) 2026-present Eclipse ThreadX contributors
/* */ *
/* This software is licensed under the Microsoft Software License */ * This program and the accompanying materials are made available under the
/* Terms for Microsoft Azure RTOS. Full text of the license can be */ * terms of the MIT License which is available at
/* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */ * https://opensource.org/licenses/MIT.
/* and in the root directory of this software. */ *
/* */ * SPDX-License-Identifier: MIT
/**************************************************************************/ **************************************************************************/
/**************************************************************************/ /**************************************************************************/
/**************************************************************************/ /**************************************************************************/
/** */ /** */
/** LevelX Component */ /** LevelX Component */
/** */ /** */
/** NAND Flash */ /** NAND Flash */
/** */ /** */
@@ -35,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)
@@ -88,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,19 +1,19 @@
/**************************************************************************/ /***************************************************************************
/* */ * Copyright (c) 2024 Microsoft Corporation
/* Copyright (c) Microsoft Corporation. All rights reserved. */ * Copyright (c) 2026-present Eclipse ThreadX contributors
/* */ *
/* This software is licensed under the Microsoft Software License */ * This program and the accompanying materials are made available under the
/* Terms for Microsoft Azure RTOS. Full text of the license can be */ * terms of the MIT License which is available at
/* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */ * https://opensource.org/licenses/MIT.
/* and in the root directory of this software. */ *
/* */ * SPDX-License-Identifier: MIT
/**************************************************************************/ **************************************************************************/
/**************************************************************************/ /**************************************************************************/
/**************************************************************************/ /**************************************************************************/
/** */ /** */
/** LevelX Component */ /** LevelX Component */
/** */ /** */
/** NAND Flash */ /** NAND Flash */
/** */ /** */
@@ -35,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)
@@ -90,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);
} }
+41 -243
View File
@@ -1,19 +1,20 @@
/**************************************************************************/ /***************************************************************************
/* */ * Copyright (c) 2024 Microsoft Corporation
/* Copyright (c) Microsoft Corporation. All rights reserved. */ * Copyright (c) 2026-present Eclipse ThreadX contributors
/* */ * Copyright (c) 2025 STMicroelectronics
/* This software is licensed under the Microsoft Software License */ *
/* Terms for Microsoft Azure RTOS. Full text of the license can be */ * This program and the accompanying materials are made available under the
/* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */ * terms of the MIT License which is available at
/* and in the root directory of this software. */ * https://opensource.org/licenses/MIT.
/* */ *
/**************************************************************************/ * SPDX-License-Identifier: MIT
**************************************************************************/
/**************************************************************************/ /**************************************************************************/
/**************************************************************************/ /**************************************************************************/
/** */ /** */
/** LevelX Component */ /** LevelX Component */
/** */ /** */
/** NAND Flash */ /** NAND Flash */
/** */ /** */
@@ -35,64 +36,41 @@
#include "lx_api.h" #include "lx_api.h"
/**************************************************************************/ /**************************************************************************/
/* */ /* */
/* FUNCTION RELEASE */ /* FUNCTION RELEASE */
/* */ /* */
/* _lx_nand_flash_format PORTABLE C */ /* _lx_nand_flash_format PORTABLE C */
/* 6.3.0 */ /* */
/* 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 */
/* */
/* return status */
/* */
/* CALLS */
/* */
/* (nand_driver_initialize) Driver initialize */
/* LX_MEMSET Initialize memory */
/* _lx_nand_flash_memory_initialize Initialize buffer */
/* _lx_nand_flash_driver_block_status_get */
/* Driver block status get */
/* _lx_nand_flash_driver_block_status_set */
/* Driver block status set */
/* _lx_nand_flash_metadata_build Build metadata */
/* _lx_nand_flash_metadata_write Write metadata */
/* _lx_nand_flash_driver_block_erase Driver block erase */
/* _lx_nand_flash_system_error System error handler */
/* 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 */ /* 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_format_extended */
/* */
/* CALLED BY */
/* */
/* 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,
@@ -100,189 +78,9 @@ UINT _lx_nand_flash_format(LX_NAND_FLASH* nand_flash, CHAR* name,
ULONG* memory_ptr, UINT memory_size) ULONG* memory_ptr, UINT memory_size)
{ {
ULONG block; UINT status;
UCHAR block_status;
UINT status;
UCHAR *page_buffer_ptr;
LX_PARAMETER_NOT_USED(name); status = _lx_nand_flash_format_extended(nand_flash, name, nand_driver_initialize, NULL, memory_ptr, memory_size);
/* Clear the NAND flash control block. User extension is not cleared. */ return status;
LX_MEMSET(nand_flash, 0, (ULONG)((UCHAR*)&(nand_flash -> lx_nand_flash_open_previous) - (UCHAR*)nand_flash) + sizeof(nand_flash -> lx_nand_flash_open_previous));
/* Call the flash driver's initialization function. */
(nand_driver_initialize)(nand_flash);
/* Determine if we can support this NAND flash size. */
if (nand_flash -> lx_nand_flash_pages_per_block > LX_NAND_MAX_PAGE_PER_BLOCK || nand_flash -> lx_nand_flash_total_blocks > LX_NAND_MAX_BLOCK_COUNT)
{
return(LX_ERROR);
}
/* Check if it is new LevelX NAND driver. */
if (nand_flash -> lx_nand_flash_driver_pages_read == LX_NULL || nand_flash -> lx_nand_flash_driver_pages_write == LX_NULL || nand_flash -> lx_nand_flash_driver_pages_copy == LX_NULL)
{
return(LX_ERROR);
}
/* Check the spare data length. */
if (nand_flash -> lx_nand_flash_spare_data1_length < sizeof(ULONG))
{
return(LX_ERROR);
}
/* Calculate the number of words per block and per page. */
nand_flash -> lx_nand_flash_words_per_page = (nand_flash -> lx_nand_flash_bytes_per_page / sizeof(ULONG));
nand_flash -> lx_nand_flash_words_per_block = (nand_flash -> lx_nand_flash_words_per_page * nand_flash -> lx_nand_flash_pages_per_block);
/* Calculate the total pages. */
nand_flash -> lx_nand_flash_total_pages = nand_flash -> lx_nand_flash_total_blocks * nand_flash -> lx_nand_flash_pages_per_block;
/* Initialize memory buffer. */
status = _lx_nand_flash_memory_initialize(nand_flash, memory_ptr, memory_size);
if (status != LX_SUCCESS)
{
return(status);
}
/* Initialize block numbers. */
nand_flash -> lx_nand_flash_metadata_block_number = 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 = LX_NAND_BLOCK_UNMAPPED;
nand_flash -> lx_nand_flash_backup_metadata_block_number_next = LX_NAND_BLOCK_UNMAPPED;
/* Initialize the block status buffer. */
LX_MEMSET(nand_flash -> lx_nand_flash_block_status_table, 0xFF, nand_flash -> lx_nand_flash_block_status_table_size);
/* 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++)
{
/* First, check to make sure this block is good. */
status = _lx_nand_flash_driver_block_status_get(nand_flash, block, &block_status);
/* Check for an error from flash driver. */
if (status)
{
/* Call system error handler. */
_lx_nand_flash_system_error(nand_flash, status, block, 0);
/* Return an error. */
return(LX_ERROR);
}
/* Is this block bad? */
if (block_status != LX_NAND_GOOD_BLOCK)
{
/* Yes, this block is bad. */
/* Increment the number of bad blocks. */
nand_flash -> lx_nand_flash_bad_blocks++;
/* Save the block status. */
nand_flash -> lx_nand_flash_block_status_table[block] = LX_NAND_BLOCK_STATUS_BAD;
/* Continue to the next block. */
continue;
}
/* Erase the block. */
status = _lx_nand_flash_driver_block_erase(nand_flash, block, 0);
/* Check for an error from flash driver. */
if (status)
{
/* Call system error handler. */
_lx_nand_flash_system_error(nand_flash, status, block, 0);
/* Attempt to mark this block as bad. */
status = _lx_nand_flash_driver_block_status_set(nand_flash, block, LX_NAND_BAD_BLOCK);
/* Check for error in setting the block status. */
if (status)
{
/* Call system error handler. */
_lx_nand_flash_system_error(nand_flash, status, block, 0);
}
/* Increment the bad block count. */
nand_flash -> lx_nand_flash_bad_blocks++;
/* Save the block status. */
nand_flash -> lx_nand_flash_block_status_table[block] = LX_NAND_BLOCK_STATUS_BAD;
}
else
{
/* Allocate blocks for metadata. */
if (nand_flash -> lx_nand_flash_metadata_block_number == LX_NAND_BLOCK_UNMAPPED)
{
nand_flash -> lx_nand_flash_metadata_block_number = block;
nand_flash -> lx_nand_flash_metadata_block_number_current = block;
}
else if (nand_flash -> lx_nand_flash_backup_metadata_block_number == LX_NAND_BLOCK_UNMAPPED)
{
nand_flash -> lx_nand_flash_backup_metadata_block_number = block;
nand_flash -> lx_nand_flash_backup_metadata_block_number_current = block;
}
else if (nand_flash -> lx_nand_flash_metadata_block_number_next == LX_NAND_BLOCK_UNMAPPED)
{
nand_flash -> lx_nand_flash_metadata_block_number_next = block;
}
else if (nand_flash -> lx_nand_flash_backup_metadata_block_number_next == LX_NAND_BLOCK_UNMAPPED)
{
nand_flash -> lx_nand_flash_backup_metadata_block_number_next = block;
}
}
}
/* There should be enough blocks for metadata. */
if (nand_flash -> lx_nand_flash_backup_metadata_block_number_next == LX_NAND_BLOCK_UNMAPPED)
{
return (LX_NO_BLOCKS);
}
/* Save the block status for metadata. */
nand_flash -> lx_nand_flash_block_status_table[nand_flash -> lx_nand_flash_backup_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_metadata_block_number] = (USHORT)nand_flash -> lx_nand_flash_metadata_block_number_next;
/* Initialize the mapping table. */
LX_MEMSET(nand_flash -> lx_nand_flash_block_mapping_table, 0xFF, nand_flash -> lx_nand_flash_block_mapping_table_size);
/* Build initial metadata. */
status = _lx_nand_flash_metadata_build(nand_flash);
if (status != LX_SUCCESS)
{
/* Return error status. */
return(status);
}
/* Get buffer for page data. */
page_buffer_ptr = nand_flash -> lx_nand_flash_page_buffer;
/* Initialize the page buffer. */
LX_MEMSET(page_buffer_ptr, 0xFF, nand_flash -> lx_nand_flash_bytes_per_page);
/* Set the next block numbers. */
LX_UTILITY_LONG_SET(&page_buffer_ptr[LX_NAND_BLOCK_LINK_MAIN_METADATA_OFFSET], nand_flash -> lx_nand_flash_metadata_block_number_next);
LX_UTILITY_LONG_SET(&page_buffer_ptr[LX_NAND_BLOCK_LINK_BACKUP_METADATA_OFFSET], nand_flash -> lx_nand_flash_backup_metadata_block_number_next);
/* Save the next block numbers to metadata block. */
status = _lx_nand_flash_metadata_write(nand_flash, page_buffer_ptr, LX_NAND_PAGE_TYPE_BLOCK_LINK);
if (status != LX_SUCCESS)
{
/* Return error status. */
return(status);
}
/* Return a successful completion. */
return(LX_SUCCESS);
} }
+280
View File
@@ -0,0 +1,280 @@
/***************************************************************************
* Copyright (c) 2024 Microsoft Corporation
* Copyright (c) 2026-present Eclipse ThreadX contributors
* Copyright (c) 2025 STMicroelectronics
*
* This program and the accompanying materials are made available under the
* terms of the MIT License which is available at
* https://opensource.org/licenses/MIT.
*
* SPDX-License-Identifier: MIT
**************************************************************************/
/**************************************************************************/
/**************************************************************************/
/** */
/** LevelX Component */
/** */
/** NAND Flash */
/** */
/**************************************************************************/
/**************************************************************************/
#define LX_SOURCE_CODE
/* Disable ThreadX error checking. */
#ifndef LX_DISABLE_ERROR_CHECKING
#define LX_DISABLE_ERROR_CHECKING
#endif
/* Include necessary system files. */
#include "lx_api.h"
/**************************************************************************/
/* */
/* FUNCTION RELEASE */
/* */
/* _lx_nand_flash_format_extended PORTABLE C */
/* */
/* AUTHOR */
/* */
/* Xiuwen Cai, Microsoft Corporation */
/* */
/* DESCRIPTION */
/* */
/* This function erases and formats a NAND flash. */
/* */
/* INPUT */
/* */
/* nand_flash NAND flash instance */
/* name Name of NAND flash instance */
/* nand_driver_initialize Driver initialize */
/* nand_driver_info_ptr Driver user data pointer */
/* memory_ptr Pointer to memory used by the */
/* LevelX for this NAND. */
/* memory_size Size of memory - must at least*/
/* 7 * total block count + */
/* 2 * page size */
/* */
/* OUTPUT */
/* */
/* return status */
/* */
/* CALLS */
/* */
/* (nand_driver_initialize) Driver initialize */
/* LX_MEMSET Initialize memory */
/* _lx_nand_flash_memory_initialize Initialize buffer */
/* _lx_nand_flash_driver_block_status_get */
/* Driver block status get */
/* _lx_nand_flash_driver_block_status_set */
/* Driver block status set */
/* _lx_nand_flash_metadata_build Build metadata */
/* _lx_nand_flash_metadata_write Write metadata */
/* _lx_nand_flash_driver_block_erase Driver block erase */
/* _lx_nand_flash_system_error System error handler */
/* tx_mutex_create Create thread-safe mutex */
/* */
/* CALLED BY */
/* */
/* Application Code */
/* */
/**************************************************************************/
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,
ULONG* memory_ptr, UINT memory_size)
{
ULONG block;
UCHAR block_status;
UINT status;
UCHAR *page_buffer_ptr;
LX_PARAMETER_NOT_USED(name);
/* Clear the NAND flash control block. User extension is not cleared. */
LX_MEMSET(nand_flash, 0, (ULONG)((UCHAR*)&(nand_flash -> lx_nand_flash_open_previous) - (UCHAR*)nand_flash) + sizeof(nand_flash -> lx_nand_flash_open_previous));
nand_flash -> lx_nand_flash_driver_info_ptr = nand_driver_info_ptr;
/* Call the flash driver's initialization function. */
(nand_driver_initialize)(nand_flash);
/* Determine if we can support this NAND flash size. */
if (nand_flash -> lx_nand_flash_pages_per_block > LX_NAND_MAX_PAGE_PER_BLOCK || nand_flash -> lx_nand_flash_total_blocks > LX_NAND_MAX_BLOCK_COUNT)
{
return(LX_ERROR);
}
/* Check if it is new LevelX NAND driver. */
if (nand_flash -> lx_nand_flash_driver_pages_read == LX_NULL || nand_flash -> lx_nand_flash_driver_pages_write == LX_NULL || nand_flash -> lx_nand_flash_driver_pages_copy == LX_NULL)
{
return(LX_ERROR);
}
/* Check the spare data length. */
if (nand_flash -> lx_nand_flash_spare_data1_length < sizeof(ULONG))
{
return(LX_ERROR);
}
/* Calculate the number of words per block and per page. */
nand_flash -> lx_nand_flash_words_per_page = (nand_flash -> lx_nand_flash_bytes_per_page / sizeof(ULONG));
nand_flash -> lx_nand_flash_words_per_block = (nand_flash -> lx_nand_flash_words_per_page * nand_flash -> lx_nand_flash_pages_per_block);
/* Calculate the total pages. */
nand_flash -> lx_nand_flash_total_pages = nand_flash -> lx_nand_flash_total_blocks * nand_flash -> lx_nand_flash_pages_per_block;
/* Initialize memory buffer. */
status = _lx_nand_flash_memory_initialize(nand_flash, memory_ptr, memory_size);
if (status != LX_SUCCESS)
{
return(status);
}
/* Initialize block numbers. */
nand_flash -> lx_nand_flash_metadata_block_number = 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 = LX_NAND_BLOCK_UNMAPPED;
nand_flash -> lx_nand_flash_backup_metadata_block_number_next = LX_NAND_BLOCK_UNMAPPED;
/* Initialize the block status buffer. */
LX_MEMSET(nand_flash -> lx_nand_flash_block_status_table, 0xFF, nand_flash -> lx_nand_flash_block_status_table_size);
/* 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++)
{
/* First, check to make sure this block is good. */
status = _lx_nand_flash_driver_block_status_get(nand_flash, block, &block_status);
/* Check for an error from flash driver. */
if (status)
{
/* Call system error handler. */
_lx_nand_flash_system_error(nand_flash, status, block, 0);
/* Return an error. */
return(LX_ERROR);
}
/* Is this block bad? */
if (block_status != LX_NAND_GOOD_BLOCK)
{
/* Yes, this block is bad. */
/* Increment the number of bad blocks. */
nand_flash -> lx_nand_flash_bad_blocks++;
/* Save the block status. */
nand_flash -> lx_nand_flash_block_status_table[block] = LX_NAND_BLOCK_STATUS_BAD;
/* Continue to the next block. */
continue;
}
/* Erase the block. */
status = _lx_nand_flash_driver_block_erase(nand_flash, block, 0);
/* Check for an error from flash driver. */
if (status)
{
/* Call system error handler. */
_lx_nand_flash_system_error(nand_flash, status, block, 0);
/* Attempt to mark this block as bad. */
status = _lx_nand_flash_driver_block_status_set(nand_flash, block, LX_NAND_BAD_BLOCK);
/* Check for error in setting the block status. */
if (status)
{
/* Call system error handler. */
_lx_nand_flash_system_error(nand_flash, status, block, 0);
}
/* Increment the bad block count. */
nand_flash -> lx_nand_flash_bad_blocks++;
/* Save the block status. */
nand_flash -> lx_nand_flash_block_status_table[block] = LX_NAND_BLOCK_STATUS_BAD;
}
else
{
/* Allocate blocks for metadata. */
if (nand_flash -> lx_nand_flash_metadata_block_number == LX_NAND_BLOCK_UNMAPPED)
{
nand_flash -> lx_nand_flash_metadata_block_number = block;
nand_flash -> lx_nand_flash_metadata_block_number_current = block;
}
else if (nand_flash -> lx_nand_flash_backup_metadata_block_number == LX_NAND_BLOCK_UNMAPPED)
{
nand_flash -> lx_nand_flash_backup_metadata_block_number = block;
nand_flash -> lx_nand_flash_backup_metadata_block_number_current = block;
}
else if (nand_flash -> lx_nand_flash_metadata_block_number_next == LX_NAND_BLOCK_UNMAPPED)
{
nand_flash -> lx_nand_flash_metadata_block_number_next = block;
}
else if (nand_flash -> lx_nand_flash_backup_metadata_block_number_next == LX_NAND_BLOCK_UNMAPPED)
{
nand_flash -> lx_nand_flash_backup_metadata_block_number_next = block;
}
}
}
/* There should be enough blocks for metadata. */
if (nand_flash -> lx_nand_flash_backup_metadata_block_number_next == LX_NAND_BLOCK_UNMAPPED)
{
return (LX_NO_BLOCKS);
}
/* Save the block status for metadata. */
nand_flash -> lx_nand_flash_block_status_table[nand_flash -> lx_nand_flash_backup_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_metadata_block_number] = (USHORT)nand_flash -> lx_nand_flash_metadata_block_number_next;
/* Initialize the mapping table. */
LX_MEMSET(nand_flash -> lx_nand_flash_block_mapping_table, 0xFF, nand_flash -> lx_nand_flash_block_mapping_table_size);
/* Build initial metadata. */
status = _lx_nand_flash_metadata_build(nand_flash);
if (status != LX_SUCCESS)
{
/* Return error status. */
return(status);
}
/* Get buffer for page data. */
page_buffer_ptr = nand_flash -> lx_nand_flash_page_buffer;
/* Initialize the page buffer. */
LX_MEMSET(page_buffer_ptr, 0xFF, nand_flash -> lx_nand_flash_bytes_per_page);
/* Set the next block numbers. */
LX_UTILITY_LONG_SET(&page_buffer_ptr[LX_NAND_BLOCK_LINK_MAIN_METADATA_OFFSET], nand_flash -> lx_nand_flash_metadata_block_number_next);
LX_UTILITY_LONG_SET(&page_buffer_ptr[LX_NAND_BLOCK_LINK_BACKUP_METADATA_OFFSET], nand_flash -> lx_nand_flash_backup_metadata_block_number_next);
/* Save the next block numbers to metadata block. */
status = _lx_nand_flash_metadata_write(nand_flash, page_buffer_ptr, LX_NAND_PAGE_TYPE_BLOCK_LINK);
if (status != LX_SUCCESS)
{
/* Return error status. */
return(status);
}
/* Return a successful completion. */
return(LX_SUCCESS);
}
+37 -43
View File
@@ -1,19 +1,19 @@
/**************************************************************************/ /***************************************************************************
/* */ * Copyright (c) 2024 Microsoft Corporation
/* Copyright (c) Microsoft Corporation. All rights reserved. */ * Copyright (c) 2026-present Eclipse ThreadX contributors
/* */ *
/* This software is licensed under the Microsoft Software License */ * This program and the accompanying materials are made available under the
/* Terms for Microsoft Azure RTOS. Full text of the license can be */ * terms of the MIT License which is available at
/* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */ * https://opensource.org/licenses/MIT.
/* and in the root directory of this software. */ *
/* */ * SPDX-License-Identifier: MIT
/**************************************************************************/ **************************************************************************/
/**************************************************************************/ /**************************************************************************/
/**************************************************************************/ /**************************************************************************/
/** */ /** */
/** LevelX Component */ /** LevelX Component */
/** */ /** */
/** NAND Flash */ /** NAND Flash */
/** */ /** */
@@ -35,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)
@@ -102,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))
{ {
+36 -44
View File
@@ -1,19 +1,19 @@
/**************************************************************************/ /***************************************************************************
/* */ * Copyright (c) 2024 Microsoft Corporation
/* Copyright (c) Microsoft Corporation. All rights reserved. */ * Copyright (c) 2026-present Eclipse ThreadX contributors
/* */ *
/* This software is licensed under the Microsoft Software License */ * This program and the accompanying materials are made available under the
/* Terms for Microsoft Azure RTOS. Full text of the license can be */ * terms of the MIT License which is available at
/* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */ * https://opensource.org/licenses/MIT.
/* and in the root directory of this software. */ *
/* */ * SPDX-License-Identifier: MIT
/**************************************************************************/ **************************************************************************/
/**************************************************************************/ /**************************************************************************/
/**************************************************************************/ /**************************************************************************/
/** */ /** */
/** LevelX Component */ /** LevelX Component */
/** */ /** */
/** NAND Flash */ /** NAND Flash */
/** */ /** */
@@ -34,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)
@@ -79,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,19 +1,19 @@
/**************************************************************************/ /***************************************************************************
/* */ * Copyright (c) 2024 Microsoft Corporation
/* Copyright (c) Microsoft Corporation. All rights reserved. */ * Copyright (c) 2026-present Eclipse ThreadX contributors
/* */ *
/* This software is licensed under the Microsoft Software License */ * This program and the accompanying materials are made available under the
/* Terms for Microsoft Azure RTOS. Full text of the license can be */ * terms of the MIT License which is available at
/* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */ * https://opensource.org/licenses/MIT.
/* and in the root directory of this software. */ *
/* */ * SPDX-License-Identifier: MIT
/**************************************************************************/ **************************************************************************/
/**************************************************************************/ /**************************************************************************/
/**************************************************************************/ /**************************************************************************/
/** */ /** */
/** LevelX Component */ /** LevelX Component */
/** */ /** */
/** NAND Flash */ /** NAND Flash */
/** */ /** */
@@ -35,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,19 +1,19 @@
/**************************************************************************/ /***************************************************************************
/* */ * Copyright (c) 2024 Microsoft Corporation
/* Copyright (c) Microsoft Corporation. All rights reserved. */ * Copyright (c) 2026-present Eclipse ThreadX contributors
/* */ *
/* This software is licensed under the Microsoft Software License */ * This program and the accompanying materials are made available under the
/* Terms for Microsoft Azure RTOS. Full text of the license can be */ * terms of the MIT License which is available at
/* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */ * https://opensource.org/licenses/MIT.
/* and in the root directory of this software. */ *
/* */ * SPDX-License-Identifier: MIT
/**************************************************************************/ **************************************************************************/
/**************************************************************************/ /**************************************************************************/
/**************************************************************************/ /**************************************************************************/
/** */ /** */
/** LevelX Component */ /** LevelX Component */
/** */ /** */
/** NAND Flash */ /** NAND Flash */
/** */ /** */
@@ -35,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,19 +1,19 @@
/**************************************************************************/ /***************************************************************************
/* */ * Copyright (c) 2024 Microsoft Corporation
/* Copyright (c) Microsoft Corporation. All rights reserved. */ * Copyright (c) 2026-present Eclipse ThreadX contributors
/* */ *
/* This software is licensed under the Microsoft Software License */ * This program and the accompanying materials are made available under the
/* Terms for Microsoft Azure RTOS. Full text of the license can be */ * terms of the MIT License which is available at
/* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */ * https://opensource.org/licenses/MIT.
/* and in the root directory of this software. */ *
/* */ * SPDX-License-Identifier: MIT
/**************************************************************************/ **************************************************************************/
/**************************************************************************/ /**************************************************************************/
/**************************************************************************/ /**************************************************************************/
/** */ /** */
/** LevelX Component */ /** LevelX Component */
/** */ /** */
/** NAND Flash */ /** NAND Flash */
/** */ /** */
@@ -35,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)
+36 -42
View File
@@ -1,19 +1,19 @@
/**************************************************************************/ /***************************************************************************
/* */ * Copyright (c) 2024 Microsoft Corporation
/* Copyright (c) Microsoft Corporation. All rights reserved. */ * Copyright (c) 2026-present Eclipse ThreadX contributors
/* */ *
/* This software is licensed under the Microsoft Software License */ * This program and the accompanying materials are made available under the
/* Terms for Microsoft Azure RTOS. Full text of the license can be */ * terms of the MIT License which is available at
/* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */ * https://opensource.org/licenses/MIT.
/* and in the root directory of this software. */ *
/* */ * SPDX-License-Identifier: MIT
/**************************************************************************/ **************************************************************************/
/**************************************************************************/ /**************************************************************************/
/**************************************************************************/ /**************************************************************************/
/** */ /** */
/** LevelX Component */ /** LevelX Component */
/** */ /** */
/** NAND Flash */ /** NAND Flash */
/** */ /** */
@@ -35,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)
{ {
@@ -125,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;
+41 -47
View File
@@ -1,19 +1,19 @@
/**************************************************************************/ /***************************************************************************
/* */ * Copyright (c) 2024 Microsoft Corporation
/* Copyright (c) Microsoft Corporation. All rights reserved. */ * Copyright (c) 2026-present Eclipse ThreadX contributors
/* */ *
/* This software is licensed under the Microsoft Software License */ * This program and the accompanying materials are made available under the
/* Terms for Microsoft Azure RTOS. Full text of the license can be */ * terms of the MIT License which is available at
/* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */ * https://opensource.org/licenses/MIT.
/* and in the root directory of this software. */ *
/* */ * SPDX-License-Identifier: MIT
/**************************************************************************/ **************************************************************************/
/**************************************************************************/ /**************************************************************************/
/**************************************************************************/ /**************************************************************************/
/** */ /** */
/** LevelX Component */ /** LevelX Component */
/** */ /** */
/** NAND Flash */ /** NAND Flash */
/** */ /** */
@@ -35,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)
@@ -151,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)
@@ -240,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)
{ {
+41 -47
View File
@@ -1,19 +1,19 @@
/**************************************************************************/ /***************************************************************************
/* */ * Copyright (c) 2024 Microsoft Corporation
/* Copyright (c) Microsoft Corporation. All rights reserved. */ * Copyright (c) 2026-present Eclipse ThreadX contributors
/* */ *
/* This software is licensed under the Microsoft Software License */ * This program and the accompanying materials are made available under the
/* Terms for Microsoft Azure RTOS. Full text of the license can be */ * terms of the MIT License which is available at
/* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */ * https://opensource.org/licenses/MIT.
/* and in the root directory of this software. */ *
/* */ * SPDX-License-Identifier: MIT
/**************************************************************************/ **************************************************************************/
/**************************************************************************/ /**************************************************************************/
/**************************************************************************/ /**************************************************************************/
/** */ /** */
/** LevelX Component */ /** LevelX Component */
/** */ /** */
/** NAND Flash */ /** NAND Flash */
/** */ /** */
@@ -35,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)
@@ -110,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);
@@ -131,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)
@@ -151,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);
} }
+41 -47
View File
@@ -1,19 +1,19 @@
/**************************************************************************/ /***************************************************************************
/* */ * Copyright (c) 2024 Microsoft Corporation
/* Copyright (c) Microsoft Corporation. All rights reserved. */ * Copyright (c) 2026-present Eclipse ThreadX contributors
/* */ *
/* This software is licensed under the Microsoft Software License */ * This program and the accompanying materials are made available under the
/* Terms for Microsoft Azure RTOS. Full text of the license can be */ * terms of the MIT License which is available at
/* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */ * https://opensource.org/licenses/MIT.
/* and in the root directory of this software. */ *
/* */ * SPDX-License-Identifier: MIT
/**************************************************************************/ **************************************************************************/
/**************************************************************************/ /**************************************************************************/
/**************************************************************************/ /**************************************************************************/
/** */ /** */
/** LevelX Component */ /** LevelX Component */
/** */ /** */
/** NAND Flash */ /** NAND Flash */
/** */ /** */
@@ -35,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)
@@ -116,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)
{ {
+42 -489
View File
@@ -1,19 +1,19 @@
/**************************************************************************/ /***************************************************************************
/* */ * Copyright (c) 2024 Microsoft Corporation
/* Copyright (c) Microsoft Corporation. All rights reserved. */ * Copyright (c) 2026-present Eclipse ThreadX contributors
/* */ *
/* This software is licensed under the Microsoft Software License */ * This program and the accompanying materials are made available under the
/* Terms for Microsoft Azure RTOS. Full text of the license can be */ * terms of the MIT License which is available at
/* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */ * https://opensource.org/licenses/MIT.
/* and in the root directory of this software. */ *
/* */ * SPDX-License-Identifier: MIT
/**************************************************************************/ **************************************************************************/
/**************************************************************************/ /**************************************************************************/
/**************************************************************************/ /**************************************************************************/
/** */ /** */
/** LevelX Component */ /** LevelX Component */
/** */ /** */
/** NAND Flash */ /** NAND Flash */
/** */ /** */
@@ -35,499 +35,52 @@
#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 */
/* 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 */
/* */
/* (nand_driver_initialize) Driver initialize */
/* _lx_nand_flash_memory_initialize Initialize buffer */
/* _lx_nand_flash_driver_block_status_get */
/* Get block status */
/* lx_nand_flash_driver_pages_read Read pages */
/* _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_system_error System error handler */
/* 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 */ /* 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 *),
ULONG* memory_ptr, UINT memory_size) ULONG* memory_ptr, UINT memory_size)
{ {
UINT status = LX_ERROR;
ULONG block; status = _lx_nand_flash_open_extended(nand_flash, name, nand_driver_initialize, NULL, memory_ptr, memory_size);
ULONG page;
UCHAR block_status;
ULONG block_count;
UINT status;
LX_NAND_FLASH *tail_ptr;
LX_NAND_DEVICE_INFO *nand_device_info_page;
UCHAR *spare_buffer_ptr;
UCHAR *page_buffer_ptr;
ULONG page_type;
UCHAR page_index;
LX_INTERRUPT_SAVE_AREA
LX_PARAMETER_NOT_USED(name); return status;
/* Clear the NAND flash control block. User extension is not cleared. */
LX_MEMSET(nand_flash, 0, (ULONG)((UCHAR*)&(nand_flash -> lx_nand_flash_open_previous) - (UCHAR*)nand_flash) + sizeof(nand_flash -> lx_nand_flash_open_previous));
/* Call the flash driver's initialization function. */
(nand_driver_initialize)(nand_flash);
/* Determine if we can support this NAND flash size. */
if (nand_flash -> lx_nand_flash_pages_per_block > LX_NAND_MAX_PAGE_PER_BLOCK || nand_flash -> lx_nand_flash_total_blocks > LX_NAND_MAX_BLOCK_COUNT)
{
/* Return an error. */
return(LX_ERROR);
}
/* Check if it is new LevelX NAND driver. */
if (nand_flash -> lx_nand_flash_driver_pages_read == LX_NULL || nand_flash -> lx_nand_flash_driver_pages_write == LX_NULL || nand_flash -> lx_nand_flash_driver_pages_copy == LX_NULL)
{
/* Return an error. */
return(LX_ERROR);
}
/* Check the spare data length. */
if (nand_flash -> lx_nand_flash_spare_data1_length < sizeof(ULONG))
{
/* Return an error. */
return(LX_ERROR);
}
/* Calculate the number of words per block and per page. */
nand_flash -> lx_nand_flash_words_per_page = (nand_flash -> lx_nand_flash_bytes_per_page / sizeof(ULONG));
nand_flash -> lx_nand_flash_words_per_block = (nand_flash -> lx_nand_flash_words_per_page * nand_flash -> lx_nand_flash_pages_per_block);
/* Calculate the total pages. */
nand_flash -> lx_nand_flash_total_pages = nand_flash -> lx_nand_flash_total_blocks * nand_flash -> lx_nand_flash_pages_per_block;
/* Initialize memory buffer. */
status = _lx_nand_flash_memory_initialize(nand_flash, memory_ptr, memory_size);
if (status != LX_SUCCESS)
{
return(status);
}
/* Initialize block numbers. */
nand_flash -> lx_nand_flash_metadata_block_number = LX_NAND_BLOCK_UNMAPPED;
nand_flash -> lx_nand_flash_backup_metadata_block_number = LX_NAND_BLOCK_UNMAPPED;
/* Setup page buffer and spare buffer pointers. */
page_buffer_ptr = nand_flash -> lx_nand_flash_page_buffer;
spare_buffer_ptr = page_buffer_ptr + nand_flash -> lx_nand_flash_bytes_per_page;
/* 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++)
{
/* First, check to make sure this block is good. */
status = _lx_nand_flash_driver_block_status_get(nand_flash, block, &block_status);
/* Check for an error from flash driver. */
if (status)
{
/* Call system error handler. */
_lx_nand_flash_system_error(nand_flash, status, block, 0);
/* Return an error. */
return(LX_ERROR);
}
/* Is this block bad? */
if (block_status != LX_NAND_GOOD_BLOCK)
{
/* Yes, this block is bad. */
/* Increment the number of bad blocks. */
nand_flash -> lx_nand_flash_bad_blocks++;
/* Save the block status. */
nand_flash -> lx_nand_flash_block_status_table[block] = LX_NAND_BLOCK_STATUS_BAD;
/* Continue to the next block. */
continue;
}
/* Call driver read function to read page 0. */
#ifdef LX_NAND_ENABLE_CONTROL_BLOCK_FOR_DRIVER_INTERFACE
status = (nand_flash -> lx_nand_flash_driver_pages_read)(nand_flash, block, 0, page_buffer_ptr, spare_buffer_ptr, 1);
#else
status = (nand_flash -> lx_nand_flash_driver_pages_read)(block, 0, page_buffer_ptr, spare_buffer_ptr, 1);
#endif
/* Check for an error from flash driver. */
if (status)
{
/* Call system error handler. */
_lx_nand_flash_system_error(nand_flash, status, block, 0);
/* Determine if the error is fatal. */
if (status != LX_NAND_ERROR_CORRECTED)
{
/* Return an error. */
return(LX_ERROR);
}
}
/* Get the page type. */
page_type = LX_UTILITY_LONG_GET(&spare_buffer_ptr[nand_flash -> lx_nand_flash_spare_data1_offset]);
/* Check if the type is device info. */
if (page_type == LX_NAND_PAGE_TYPE_DEVICE_INFO)
{
/* Get the device info page. */
nand_device_info_page = (LX_NAND_DEVICE_INFO*)page_buffer_ptr;
/* Check signature. */
if (nand_device_info_page -> lx_nand_device_info_signature1 == LX_NAND_DEVICE_INFO_SIGNATURE1 &&
nand_device_info_page -> lx_nand_device_info_signature2 == LX_NAND_DEVICE_INFO_SIGNATURE2)
{
/* Save the block numbers. */
nand_flash -> lx_nand_flash_metadata_block_number = nand_device_info_page -> lx_nand_device_info_metadata_block_number;
nand_flash -> lx_nand_flash_backup_metadata_block_number = nand_device_info_page -> lx_nand_device_info_backup_metadata_block_number;
break;
}
}
}
/* Check if we have found the metadata block. */
if (nand_flash -> lx_nand_flash_metadata_block_number == LX_NAND_BLOCK_UNMAPPED)
{
/* Not found, return an error. */
return (LX_ERROR);
}
/* Initialize metadata block numbers and lists. */
nand_flash -> lx_nand_flash_metadata_block_number_current = nand_flash -> lx_nand_flash_metadata_block_number;
nand_flash -> lx_nand_flash_backup_metadata_block_number_current = nand_flash -> lx_nand_flash_backup_metadata_block_number;
nand_flash -> lx_nand_flash_metadata_block[0] = (USHORT)nand_flash -> lx_nand_flash_metadata_block_number;
nand_flash -> lx_nand_flash_backup_metadata_block[0] = (USHORT)nand_flash -> lx_nand_flash_backup_metadata_block_number;
/* Found one metadata block. */
nand_flash -> lx_nand_flash_metadata_block_count = 1;
/* Clear searched block count. */
block_count = 0;
do
{
/* Initialize next block to 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;
/* Loop to read pages in the metadata block. */
for (page = 0; page < nand_flash -> lx_nand_flash_pages_per_block ; page++)
{
/* Call driver read function to read page. */
#ifdef LX_NAND_ENABLE_CONTROL_BLOCK_FOR_DRIVER_INTERFACE
status = (nand_flash -> lx_nand_flash_driver_pages_read)(nand_flash, block, page, page_buffer_ptr, spare_buffer_ptr, 1);
#else
status = (nand_flash -> lx_nand_flash_driver_pages_read)(block, page, page_buffer_ptr, spare_buffer_ptr, 1);
#endif
/* Check for an error from flash driver. */
if (status)
{
/* Call system error handler. */
_lx_nand_flash_system_error(nand_flash, status, block, 0);
/* Determine if the error is fatal. */
if (status != LX_NAND_ERROR_CORRECTED)
{
/* Return an error. */
return(LX_ERROR);
}
}
/* Get page type and page index. */
page_type = LX_UTILITY_LONG_GET(&spare_buffer_ptr[nand_flash -> lx_nand_flash_spare_data1_offset]) & (~LX_NAND_PAGE_TYPE_PAGE_NUMBER_MASK);
page_index = LX_UTILITY_LONG_GET(&spare_buffer_ptr[nand_flash -> lx_nand_flash_spare_data1_offset]) & LX_NAND_PAGE_TYPE_PAGE_NUMBER_MASK;
/* Process metadata page by type. */
switch (page_type)
{
case LX_NAND_PAGE_TYPE_DEVICE_INFO:
/* This page is for device info. */
nand_device_info_page = (LX_NAND_DEVICE_INFO*)page_buffer_ptr;
/* Get the base erase count. */
nand_flash -> lx_nand_flash_base_erase_count = nand_device_info_page -> lx_nand_device_info_base_erase_count;
break;
case LX_NAND_PAGE_TYPE_ERASE_COUNT_TABLE:
/* Check if page index is valid. */
if (((ULONG)page_index + 1) * nand_flash -> lx_nand_flash_bytes_per_page > nand_flash -> lx_nand_flash_erase_count_table_size)
{
/* Invalid page index. Return an error. */
status = LX_ERROR;
break;
}
/* Copy page data to erase count table. */
LX_MEMCPY(nand_flash -> lx_nand_flash_erase_count_table + page_index * nand_flash -> lx_nand_flash_bytes_per_page, /* Use case of memcpy is verified. */
page_buffer_ptr, nand_flash -> lx_nand_flash_bytes_per_page);
break;
case LX_NAND_PAGE_TYPE_BLOCK_MAPPING_TABLE:
/* Check if page index is valid. */
if (((ULONG)page_index + 1) * nand_flash -> lx_nand_flash_bytes_per_page > nand_flash -> lx_nand_flash_block_mapping_table_size)
{
/* Invalid page index. Return an error. */
status = LX_ERROR;
break;
}
/* Copy page data to block mapping table. */
LX_MEMCPY(nand_flash -> lx_nand_flash_block_mapping_table + page_index * nand_flash -> lx_nand_flash_bytes_per_page / sizeof(*nand_flash -> lx_nand_flash_block_mapping_table), /* Use case of memcpy is verified. */
page_buffer_ptr, nand_flash -> lx_nand_flash_bytes_per_page);
break;
case LX_NAND_PAGE_TYPE_BLOCK_STATUS_TABLE:
/* Check if page index is valid. */
if (((ULONG)page_index + 1) * nand_flash -> lx_nand_flash_bytes_per_page > nand_flash -> lx_nand_flash_block_status_table_size)
{
/* Invalid page index. Return an error. */
status = LX_ERROR;
break;
}
/* Copy page data to block status table. */
LX_MEMCPY(nand_flash -> lx_nand_flash_block_status_table + page_index * nand_flash -> lx_nand_flash_bytes_per_page / sizeof(*nand_flash -> lx_nand_flash_block_status_table), /* Use case of memcpy is verified. */
page_buffer_ptr, nand_flash -> lx_nand_flash_bytes_per_page);
break;
case LX_NAND_PAGE_TYPE_FREE_PAGE:
/* Found a free page. Update current page. */
nand_flash -> lx_nand_flash_metadata_block_current_page = page;
nand_flash -> lx_nand_flash_backup_metadata_block_current_page = page;
/* Skip all the remaining pages. */
page = nand_flash -> lx_nand_flash_pages_per_block;
break;
case LX_NAND_PAGE_TYPE_BLOCK_LINK:
/* Found next blocks. Update next block numbers. */
nand_flash -> lx_nand_flash_metadata_block_number_next = LX_UTILITY_LONG_GET(&page_buffer_ptr[LX_NAND_BLOCK_LINK_MAIN_METADATA_OFFSET]);
nand_flash -> lx_nand_flash_backup_metadata_block_number_next = LX_UTILITY_LONG_GET(&page_buffer_ptr[LX_NAND_BLOCK_LINK_BACKUP_METADATA_OFFSET]);
/* Save block numbers in metadata block lists. */
nand_flash -> lx_nand_flash_metadata_block[nand_flash -> lx_nand_flash_metadata_block_count] = (USHORT)LX_UTILITY_LONG_GET(&page_buffer_ptr[LX_NAND_BLOCK_LINK_MAIN_METADATA_OFFSET]);
nand_flash -> lx_nand_flash_backup_metadata_block[nand_flash -> lx_nand_flash_metadata_block_count] = (USHORT)LX_UTILITY_LONG_GET(&page_buffer_ptr[LX_NAND_BLOCK_LINK_BACKUP_METADATA_OFFSET]);
/* Increase metadata block count. */
nand_flash -> lx_nand_flash_metadata_block_count++;
break;
default:
/* Unknown type, return error. */
status = LX_ERROR;
}
/* Check status. */
if (status == LX_ERROR)
{
/* Error, break the loop. */
break;
}
}
/* Check if we have reached the last page. */
if (page == nand_flash -> lx_nand_flash_pages_per_block)
{
/* Move to next block. */
nand_flash -> lx_nand_flash_metadata_block_number_current = nand_flash -> lx_nand_flash_metadata_block_number_next;
nand_flash -> lx_nand_flash_backup_metadata_block_number_current = nand_flash -> lx_nand_flash_backup_metadata_block_number_next;
/* Make sure the block is valid. */
if (nand_flash -> lx_nand_flash_metadata_block_number_current == LX_NAND_BLOCK_UNMAPPED)
{
/* Error, break the loop. */
break;
}
/* Get the block to process. */
block = nand_flash -> lx_nand_flash_metadata_block_number_current;
}
/* Increase the processed block number. */
block_count++;
/* If block count is larger than total blocks, there is an error. */
if (block_count >= nand_flash -> lx_nand_flash_total_blocks)
{
/* Break the loop. */
break;
}
} while (nand_flash -> lx_nand_flash_metadata_block_current_page == 0 && status != LX_ERROR);
/* Check if metadata page is processed correctly. */
if (nand_flash -> lx_nand_flash_metadata_block_current_page == 0 || status == LX_ERROR)
{
/* Return an error. */
return(LX_ERROR);
}
/* Loop to build free and mapped block lists. */
for (block = 0; block < nand_flash -> lx_nand_flash_total_blocks; block++)
{
/* Check for free blocks. */
if (nand_flash -> lx_nand_flash_block_status_table[block] == LX_NAND_BLOCK_STATUS_FREE)
{
/* Add the block to free block list. */
_lx_nand_flash_free_block_list_add(nand_flash, block);
}
/* Check for mapped blocks. */
if (nand_flash -> lx_nand_flash_block_mapping_table[block] != LX_NAND_BLOCK_UNMAPPED)
{
/* Add the block to free block list. */
_lx_nand_flash_mapped_block_list_add(nand_flash, block);
}
}
#ifdef LX_THREAD_SAFE_ENABLE
/* 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. */
status = tx_mutex_create(&nand_flash -> lx_nand_flash_mutex, "NAND Flash Mutex", TX_NO_INHERIT);
/* Determine if the mutex creation encountered an error. */
if (status != LX_SUCCESS)
{
/* Call system error handler, since this should not happen. */
_lx_nand_flash_system_error(nand_flash, LX_SYSTEM_MUTEX_CREATE_FAILED, 0, 0);
/* Return error to caller. */
return(LX_ERROR);
}
#endif
/* Lockout interrupts. */
LX_DISABLE
/* 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. */
/* Set the NAND flash state to open. */
nand_flash -> lx_nand_flash_state = LX_NAND_FLASH_OPENED;
/* Place the NAND flash control block on the list of opened NAND flashes. First,
check for an empty list. */
if (_lx_nand_flash_opened_count)
{
/* List is not empty - other NAND flashes are open. */
/* Pickup tail pointer. */
tail_ptr = _lx_nand_flash_opened_ptr -> lx_nand_flash_open_previous;
/* Place the new NAND flash control block in the list. */
_lx_nand_flash_opened_ptr -> lx_nand_flash_open_previous = nand_flash;
tail_ptr -> lx_nand_flash_open_next = nand_flash;
/* Setup this NAND flash's opened links. */
nand_flash -> lx_nand_flash_open_previous = tail_ptr;
nand_flash -> lx_nand_flash_open_next = _lx_nand_flash_opened_ptr;
}
else
{
/* The opened NAND flash list is empty. Add the NAND flash to empty list. */
_lx_nand_flash_opened_ptr = nand_flash;
nand_flash -> lx_nand_flash_open_next = nand_flash;
nand_flash -> lx_nand_flash_open_previous = nand_flash;
}
/* Increment the opened NAND flash counter. */
_lx_nand_flash_opened_count++;
/* Restore interrupts. */
LX_RESTORE
/* Return a successful completion. */
return(LX_SUCCESS);
} }
+526
View File
@@ -0,0 +1,526 @@
/***************************************************************************
* Copyright (c) 2024 Microsoft Corporation
* Copyright (c) 2026-present Eclipse ThreadX contributors
*
* This program and the accompanying materials are made available under the
* terms of the MIT License which is available at
* https://opensource.org/licenses/MIT.
*
* SPDX-License-Identifier: MIT
**************************************************************************/
/**************************************************************************/
/**************************************************************************/
/** */
/** LevelX Component */
/** */
/** NAND Flash */
/** */
/**************************************************************************/
/**************************************************************************/
#define LX_SOURCE_CODE
/* Disable ThreadX error checking. */
#ifndef LX_DISABLE_ERROR_CHECKING
#define LX_DISABLE_ERROR_CHECKING
#endif
/* Include necessary system files. */
#include "lx_api.h"
/**************************************************************************/
/* */
/* FUNCTION RELEASE */
/* */
/* _lx_nand_flash_open PORTABLE C */
/* 6.3.0 */
/* AUTHOR */
/* */
/* Xiuwen Cai, Microsoft Corporation */
/* */
/* DESCRIPTION */
/* */
/* This function opens a NAND flash instance and ensures the */
/* NAND flash is in a coherent state. */
/* */
/* INPUT */
/* */
/* nand_flash NAND flash instance */
/* name Name of NAND flash instance */
/* nand_driver_initialize Driver initialize */
/* memory_ptr Pointer to memory used by the */
/* LevelX for this NAND. */
/* memory_size Size of memory - must at least*/
/* 7 * total block count + */
/* 2 * page size */
/* */
/* OUTPUT */
/* */
/* return status */
/* */
/* CALLS */
/* */
/* (nand_driver_initialize) Driver initialize */
/* _lx_nand_flash_memory_initialize Initialize buffer */
/* _lx_nand_flash_driver_block_status_get */
/* Get block status */
/* lx_nand_flash_driver_pages_read Read pages */
/* _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_system_error System error handler */
/* tx_mutex_create Create thread-safe mutex */
/* */
/* CALLED BY */
/* */
/* Application Code */
/* */
/**************************************************************************/
UINT _lx_nand_flash_open_extended(LX_NAND_FLASH *nand_flash, CHAR *name, UINT (*nand_driver_initialize)(LX_NAND_FLASH *),
VOID *nand_driver_info_ptr, ULONG* memory_ptr, UINT memory_size)
{
ULONG block;
ULONG page;
UCHAR block_status;
ULONG block_count;
UINT status;
LX_NAND_FLASH *tail_ptr;
LX_NAND_DEVICE_INFO *nand_device_info_page;
UCHAR *spare_buffer_ptr;
UCHAR *page_buffer_ptr;
ULONG page_type;
UCHAR page_index;
LX_INTERRUPT_SAVE_AREA
LX_PARAMETER_NOT_USED(name);
/* Clear the NAND flash control block. User extension is not cleared. */
LX_MEMSET(nand_flash, 0, (ULONG)((UCHAR*)&(nand_flash -> lx_nand_flash_open_previous) - (UCHAR*)nand_flash) + sizeof(nand_flash -> lx_nand_flash_open_previous));
/* Pass the driver_info_ptr */
nand_flash -> lx_nand_flash_driver_info_ptr = nand_driver_info_ptr;
/* Call the flash driver's initialization function. */
(nand_driver_initialize)(nand_flash);
/* Determine if we can support this NAND flash size. */
if (nand_flash -> lx_nand_flash_pages_per_block > LX_NAND_MAX_PAGE_PER_BLOCK || nand_flash -> lx_nand_flash_total_blocks > LX_NAND_MAX_BLOCK_COUNT)
{
/* Return an error. */
return(LX_ERROR);
}
/* Check if it is new LevelX NAND driver. */
if (nand_flash -> lx_nand_flash_driver_pages_read == LX_NULL || nand_flash -> lx_nand_flash_driver_pages_write == LX_NULL || nand_flash -> lx_nand_flash_driver_pages_copy == LX_NULL)
{
/* Return an error. */
return(LX_ERROR);
}
/* Check the spare data length. */
if (nand_flash -> lx_nand_flash_spare_data1_length < sizeof(ULONG))
{
/* Return an error. */
return(LX_ERROR);
}
/* Calculate the number of words per block and per page. */
nand_flash -> lx_nand_flash_words_per_page = (nand_flash -> lx_nand_flash_bytes_per_page / sizeof(ULONG));
nand_flash -> lx_nand_flash_words_per_block = (nand_flash -> lx_nand_flash_words_per_page * nand_flash -> lx_nand_flash_pages_per_block);
/* Calculate the total pages. */
nand_flash -> lx_nand_flash_total_pages = nand_flash -> lx_nand_flash_total_blocks * nand_flash -> lx_nand_flash_pages_per_block;
/* Initialize memory buffer. */
status = _lx_nand_flash_memory_initialize(nand_flash, memory_ptr, memory_size);
if (status != LX_SUCCESS)
{
return(status);
}
/* Initialize block numbers. */
nand_flash -> lx_nand_flash_metadata_block_number = LX_NAND_BLOCK_UNMAPPED;
nand_flash -> lx_nand_flash_backup_metadata_block_number = LX_NAND_BLOCK_UNMAPPED;
/* Setup page buffer and spare buffer pointers. */
page_buffer_ptr = nand_flash -> lx_nand_flash_page_buffer;
spare_buffer_ptr = page_buffer_ptr + nand_flash -> lx_nand_flash_bytes_per_page;
/* 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++)
{
/* First, check to make sure this block is good. */
status = _lx_nand_flash_driver_block_status_get(nand_flash, block, &block_status);
/* Check for an error from flash driver. */
if (status)
{
/* Call system error handler. */
_lx_nand_flash_system_error(nand_flash, status, block, 0);
/* Return an error. */
return(LX_ERROR);
}
/* Is this block bad? */
if (block_status != LX_NAND_GOOD_BLOCK)
{
/* Yes, this block is bad. */
/* Increment the number of bad blocks. */
nand_flash -> lx_nand_flash_bad_blocks++;
/* Save the block status. */
nand_flash -> lx_nand_flash_block_status_table[block] = LX_NAND_BLOCK_STATUS_BAD;
/* Continue to the next block. */
continue;
}
/* Call driver read function to read page 0. */
#ifdef LX_NAND_ENABLE_CONTROL_BLOCK_FOR_DRIVER_INTERFACE
status = (nand_flash -> lx_nand_flash_driver_pages_read)(nand_flash, block, 0, page_buffer_ptr, spare_buffer_ptr, 1);
#else
status = (nand_flash -> lx_nand_flash_driver_pages_read)(block, 0, page_buffer_ptr, spare_buffer_ptr, 1);
#endif
/* Check for an error from flash driver. */
if (status)
{
/* Call system error handler. */
_lx_nand_flash_system_error(nand_flash, status, block, 0);
/* Determine if the error is fatal. */
if (status != LX_NAND_ERROR_CORRECTED)
{
/* Return an error. */
return(LX_ERROR);
}
}
/* Get the page type. */
page_type = LX_UTILITY_LONG_GET(&spare_buffer_ptr[nand_flash -> lx_nand_flash_spare_data1_offset]);
/* Check if the type is device info. */
if (page_type == LX_NAND_PAGE_TYPE_DEVICE_INFO)
{
/* Get the device info page. */
nand_device_info_page = (LX_NAND_DEVICE_INFO*)page_buffer_ptr;
/* Check signature. */
if (nand_device_info_page -> lx_nand_device_info_signature1 == LX_NAND_DEVICE_INFO_SIGNATURE1 &&
nand_device_info_page -> lx_nand_device_info_signature2 == LX_NAND_DEVICE_INFO_SIGNATURE2)
{
/* Save the block numbers. */
nand_flash -> lx_nand_flash_metadata_block_number = nand_device_info_page -> lx_nand_device_info_metadata_block_number;
nand_flash -> lx_nand_flash_backup_metadata_block_number = nand_device_info_page -> lx_nand_device_info_backup_metadata_block_number;
break;
}
}
}
/* Check if we have found the metadata block. */
if (nand_flash -> lx_nand_flash_metadata_block_number == LX_NAND_BLOCK_UNMAPPED)
{
/* Not found, return an error. */
return (LX_ERROR);
}
/* Initialize metadata block numbers and lists. */
nand_flash -> lx_nand_flash_metadata_block_number_current = nand_flash -> lx_nand_flash_metadata_block_number;
nand_flash -> lx_nand_flash_backup_metadata_block_number_current = nand_flash -> lx_nand_flash_backup_metadata_block_number;
nand_flash -> lx_nand_flash_metadata_block[0] = (USHORT)nand_flash -> lx_nand_flash_metadata_block_number;
nand_flash -> lx_nand_flash_backup_metadata_block[0] = (USHORT)nand_flash -> lx_nand_flash_backup_metadata_block_number;
/* Found one metadata block. */
nand_flash -> lx_nand_flash_metadata_block_count = 1;
/* Clear searched block count. */
block_count = 0;
do
{
/* Initialize next block to 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;
/* Loop to read pages in the metadata block. */
for (page = 0; page < nand_flash -> lx_nand_flash_pages_per_block ; page++)
{
/* Call driver read function to read page. */
#ifdef LX_NAND_ENABLE_CONTROL_BLOCK_FOR_DRIVER_INTERFACE
status = (nand_flash -> lx_nand_flash_driver_pages_read)(nand_flash, block, page, page_buffer_ptr, spare_buffer_ptr, 1);
#else
status = (nand_flash -> lx_nand_flash_driver_pages_read)(block, page, page_buffer_ptr, spare_buffer_ptr, 1);
#endif
/* Check for an error from flash driver. */
if (status)
{
/* Call system error handler. */
_lx_nand_flash_system_error(nand_flash, status, block, 0);
/* Determine if the error is fatal. */
if (status != LX_NAND_ERROR_CORRECTED)
{
/* Return an error. */
return(LX_ERROR);
}
}
/* Get page type and page index. */
page_type = LX_UTILITY_LONG_GET(&spare_buffer_ptr[nand_flash -> lx_nand_flash_spare_data1_offset]) & (~LX_NAND_PAGE_TYPE_PAGE_NUMBER_MASK);
page_index = LX_UTILITY_LONG_GET(&spare_buffer_ptr[nand_flash -> lx_nand_flash_spare_data1_offset]) & LX_NAND_PAGE_TYPE_PAGE_NUMBER_MASK;
/* Process metadata page by type. */
switch (page_type)
{
case LX_NAND_PAGE_TYPE_DEVICE_INFO:
/* This page is for device info. */
nand_device_info_page = (LX_NAND_DEVICE_INFO*)page_buffer_ptr;
/* Get the base erase count. */
nand_flash -> lx_nand_flash_base_erase_count = nand_device_info_page -> lx_nand_device_info_base_erase_count;
break;
case LX_NAND_PAGE_TYPE_ERASE_COUNT_TABLE:
/* Check if page index is valid. */
if (((ULONG)page_index + 1) * nand_flash -> lx_nand_flash_bytes_per_page > nand_flash -> lx_nand_flash_erase_count_table_size)
{
/* Invalid page index. Return an error. */
status = LX_ERROR;
break;
}
/* Copy page data to erase count table. */
LX_MEMCPY(nand_flash -> lx_nand_flash_erase_count_table + page_index * nand_flash -> lx_nand_flash_bytes_per_page, /* Use case of memcpy is verified. */
page_buffer_ptr, nand_flash -> lx_nand_flash_bytes_per_page);
break;
case LX_NAND_PAGE_TYPE_BLOCK_MAPPING_TABLE:
/* Check if page index is valid. */
if (((ULONG)page_index + 1) * nand_flash -> lx_nand_flash_bytes_per_page > nand_flash -> lx_nand_flash_block_mapping_table_size)
{
/* Invalid page index. Return an error. */
status = LX_ERROR;
break;
}
/* Copy page data to block mapping table. */
LX_MEMCPY(nand_flash -> lx_nand_flash_block_mapping_table + page_index * nand_flash -> lx_nand_flash_bytes_per_page / sizeof(*nand_flash -> lx_nand_flash_block_mapping_table), /* Use case of memcpy is verified. */
page_buffer_ptr, nand_flash -> lx_nand_flash_bytes_per_page);
break;
case LX_NAND_PAGE_TYPE_BLOCK_STATUS_TABLE:
/* Check if page index is valid. */
if (((ULONG)page_index + 1) * nand_flash -> lx_nand_flash_bytes_per_page > nand_flash -> lx_nand_flash_block_status_table_size)
{
/* Invalid page index. Return an error. */
status = LX_ERROR;
break;
}
/* Copy page data to block status table. */
LX_MEMCPY(nand_flash -> lx_nand_flash_block_status_table + page_index * nand_flash -> lx_nand_flash_bytes_per_page / sizeof(*nand_flash -> lx_nand_flash_block_status_table), /* Use case of memcpy is verified. */
page_buffer_ptr, nand_flash -> lx_nand_flash_bytes_per_page);
break;
case LX_NAND_PAGE_TYPE_FREE_PAGE:
/* Found a free page. Update current page. */
nand_flash -> lx_nand_flash_metadata_block_current_page = page;
nand_flash -> lx_nand_flash_backup_metadata_block_current_page = page;
/* Skip all the remaining pages. */
page = nand_flash -> lx_nand_flash_pages_per_block;
break;
case LX_NAND_PAGE_TYPE_BLOCK_LINK:
/* Found next blocks. Update next block numbers. */
nand_flash -> lx_nand_flash_metadata_block_number_next = LX_UTILITY_LONG_GET(&page_buffer_ptr[LX_NAND_BLOCK_LINK_MAIN_METADATA_OFFSET]);
nand_flash -> lx_nand_flash_backup_metadata_block_number_next = LX_UTILITY_LONG_GET(&page_buffer_ptr[LX_NAND_BLOCK_LINK_BACKUP_METADATA_OFFSET]);
/* Save block numbers in metadata block lists. */
nand_flash -> lx_nand_flash_metadata_block[nand_flash -> lx_nand_flash_metadata_block_count] = (USHORT)LX_UTILITY_LONG_GET(&page_buffer_ptr[LX_NAND_BLOCK_LINK_MAIN_METADATA_OFFSET]);
nand_flash -> lx_nand_flash_backup_metadata_block[nand_flash -> lx_nand_flash_metadata_block_count] = (USHORT)LX_UTILITY_LONG_GET(&page_buffer_ptr[LX_NAND_BLOCK_LINK_BACKUP_METADATA_OFFSET]);
/* Increase metadata block count. */
nand_flash -> lx_nand_flash_metadata_block_count++;
break;
default:
/* Unknown type, return error. */
status = LX_ERROR;
}
/* Check status. */
if (status == LX_ERROR)
{
/* Error, break the loop. */
break;
}
}
/* Check if we have reached the last page. */
if (page == nand_flash -> lx_nand_flash_pages_per_block)
{
/* Move to next block. */
nand_flash -> lx_nand_flash_metadata_block_number_current = nand_flash -> lx_nand_flash_metadata_block_number_next;
nand_flash -> lx_nand_flash_backup_metadata_block_number_current = nand_flash -> lx_nand_flash_backup_metadata_block_number_next;
/* Make sure the block is valid. */
if (nand_flash -> lx_nand_flash_metadata_block_number_current == LX_NAND_BLOCK_UNMAPPED)
{
/* Error, break the loop. */
break;
}
/* Get the block to process. */
block = nand_flash -> lx_nand_flash_metadata_block_number_current;
}
/* Increase the processed block number. */
block_count++;
/* If block count is larger than total blocks, there is an error. */
if (block_count >= nand_flash -> lx_nand_flash_total_blocks)
{
/* Break the loop. */
break;
}
} while (nand_flash -> lx_nand_flash_metadata_block_current_page == 0 && status != LX_ERROR);
/* Check if metadata page is processed correctly. */
if (nand_flash -> lx_nand_flash_metadata_block_current_page == 0 || status == LX_ERROR)
{
/* Return an error. */
return(LX_ERROR);
}
/* Loop to build free and mapped block lists. */
for (block = 0; block < nand_flash -> lx_nand_flash_total_blocks; block++)
{
/* Check for free blocks. */
if (nand_flash -> lx_nand_flash_block_status_table[block] == LX_NAND_BLOCK_STATUS_FREE)
{
/* Add the block to free block list. */
_lx_nand_flash_free_block_list_add(nand_flash, block);
}
/* Check for mapped blocks. */
if (nand_flash -> lx_nand_flash_block_mapping_table[block] != LX_NAND_BLOCK_UNMAPPED)
{
/* Add the block to free block list. */
_lx_nand_flash_mapped_block_list_add(nand_flash, block);
}
}
#ifdef LX_THREAD_SAFE_ENABLE
/* 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. */
status = tx_mutex_create(&nand_flash -> lx_nand_flash_mutex, "NAND Flash Mutex", TX_NO_INHERIT);
/* Determine if the mutex creation encountered an error. */
if (status != LX_SUCCESS)
{
/* Call system error handler, since this should not happen. */
_lx_nand_flash_system_error(nand_flash, LX_SYSTEM_MUTEX_CREATE_FAILED, 0, 0);
/* Return error to caller. */
return(LX_ERROR);
}
#endif
/* Lockout interrupts. */
LX_DISABLE
/* 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. */
/* Set the NAND flash state to open. */
nand_flash -> lx_nand_flash_state = LX_NAND_FLASH_OPENED;
/* Place the NAND flash control block on the list of opened NAND flashes. First,
check for an empty list. */
if (_lx_nand_flash_opened_count)
{
/* List is not empty - other NAND flashes are open. */
/* Pickup tail pointer. */
tail_ptr = _lx_nand_flash_opened_ptr -> lx_nand_flash_open_previous;
/* Place the new NAND flash control block in the list. */
_lx_nand_flash_opened_ptr -> lx_nand_flash_open_previous = nand_flash;
tail_ptr -> lx_nand_flash_open_next = nand_flash;
/* Setup this NAND flash's opened links. */
nand_flash -> lx_nand_flash_open_previous = tail_ptr;
nand_flash -> lx_nand_flash_open_next = _lx_nand_flash_opened_ptr;
}
else
{
/* The opened NAND flash list is empty. Add the NAND flash to empty list. */
_lx_nand_flash_opened_ptr = nand_flash;
nand_flash -> lx_nand_flash_open_next = nand_flash;
nand_flash -> lx_nand_flash_open_previous = nand_flash;
}
/* Increment the opened NAND flash counter. */
_lx_nand_flash_opened_count++;
/* Restore interrupts. */
LX_RESTORE
/* Return a successful completion. */
return(LX_SUCCESS);
}
+51 -61
View File
@@ -1,19 +1,19 @@
/**************************************************************************/ /***************************************************************************
/* */ * Copyright (c) 2024 Microsoft Corporation
/* Copyright (c) Microsoft Corporation. All rights reserved. */ * Copyright (c) 2026-present Eclipse ThreadX contributors
/* */ *
/* This software is licensed under the Microsoft Software License */ * This program and the accompanying materials are made available under the
/* Terms for Microsoft Azure RTOS. Full text of the license can be */ * terms of the MIT License which is available at
/* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */ * https://opensource.org/licenses/MIT.
/* and in the root directory of this software. */ *
/* */ * SPDX-License-Identifier: MIT
/**************************************************************************/ **************************************************************************/
/**************************************************************************/ /**************************************************************************/
/**************************************************************************/ /**************************************************************************/
/** */ /** */
/** LevelX Component */ /** LevelX Component */
/** */ /** */
/** NAND Flash */ /** NAND Flash */
/** */ /** */
@@ -35,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)
@@ -86,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);
} }
+43 -53
View File
@@ -1,19 +1,19 @@
/**************************************************************************/ /***************************************************************************
/* */ * Copyright (c) 2024 Microsoft Corporation
/* Copyright (c) Microsoft Corporation. All rights reserved. */ * Copyright (c) 2026-present Eclipse ThreadX contributors
/* */ *
/* This software is licensed under the Microsoft Software License */ * This program and the accompanying materials are made available under the
/* Terms for Microsoft Azure RTOS. Full text of the license can be */ * terms of the MIT License which is available at
/* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */ * https://opensource.org/licenses/MIT.
/* and in the root directory of this software. */ *
/* */ * SPDX-License-Identifier: MIT
/**************************************************************************/ **************************************************************************/
/**************************************************************************/ /**************************************************************************/
/**************************************************************************/ /**************************************************************************/
/** */ /** */
/** LevelX Component */ /** LevelX Component */
/** */ /** */
/** NAND Flash */ /** NAND Flash */
/** */ /** */
@@ -35,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)
@@ -83,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);
} }
+40 -53
View File
@@ -1,19 +1,19 @@
/**************************************************************************/ /***************************************************************************
/* */ * Copyright (c) 2024 Microsoft Corporation
/* Copyright (c) Microsoft Corporation. All rights reserved. */ * Copyright (c) 2026-present Eclipse ThreadX contributors
/* */ *
/* This software is licensed under the Microsoft Software License */ * This program and the accompanying materials are made available under the
/* Terms for Microsoft Azure RTOS. Full text of the license can be */ * terms of the MIT License which is available at
/* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */ * https://opensource.org/licenses/MIT.
/* and in the root directory of this software. */ *
/* */ * SPDX-License-Identifier: MIT
/**************************************************************************/ **************************************************************************/
/**************************************************************************/ /**************************************************************************/
/**************************************************************************/ /**************************************************************************/
/** */ /** */
/** LevelX Component */ /** LevelX Component */
/** */ /** */
/** NAND Flash */ /** NAND Flash */
/** */ /** */
@@ -35,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);
+70 -56
View File
@@ -1,19 +1,19 @@
/**************************************************************************/ /***************************************************************************
/* */ * Copyright (c) 2024 Microsoft Corporation
/* Copyright (c) Microsoft Corporation. All rights reserved. */ * Copyright (c) 2026-present Eclipse ThreadX contributors
/* */ *
/* This software is licensed under the Microsoft Software License */ * This program and the accompanying materials are made available under the
/* Terms for Microsoft Azure RTOS. Full text of the license can be */ * terms of the MIT License which is available at
/* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */ * https://opensource.org/licenses/MIT.
/* and in the root directory of this software. */ *
/* */ * SPDX-License-Identifier: MIT
/**************************************************************************/ **************************************************************************/
/**************************************************************************/ /**************************************************************************/
/**************************************************************************/ /**************************************************************************/
/** */ /** */
/** LevelX Component */ /** LevelX Component */
/** */ /** */
/** NAND Flash */ /** NAND Flash */
/** */ /** */
@@ -35,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)
@@ -127,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;
@@ -144,9 +138,9 @@ LONG page;
/* Read a page. */ /* Read a 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_read)(nand_flash, block, (ULONG)page, (UCHAR*)buffer, spare_buffer_ptr, 1); status = (nand_flash -> lx_nand_flash_driver_pages_read)(nand_flash, block, (ULONG)page, (UCHAR*)NULL, spare_buffer_ptr, 1);
#else #else
status = (nand_flash -> lx_nand_flash_driver_pages_read)(block, (ULONG)page, (UCHAR*)buffer, spare_buffer_ptr, 1); status = (nand_flash -> lx_nand_flash_driver_pages_read)(block, (ULONG)page, (UCHAR*)NULL, spare_buffer_ptr, 1);
#endif #endif
/* Check for an error from flash driver. */ /* Check for an error from flash driver. */
@@ -163,10 +157,30 @@ 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)
{ {
#ifdef LX_NAND_ENABLE_CONTROL_BLOCK_FOR_DRIVER_INTERFACE
status = (nand_flash -> lx_nand_flash_driver_pages_read)(nand_flash, block, (ULONG)page, (UCHAR*)buffer, NULL, 1);
#else
status = (nand_flash -> lx_nand_flash_driver_pages_read)(block, (ULONG)page, (UCHAR*)buffer, NULL, 1);
#endif
/* Check for an error from flash driver. */
if (status)
{
/* Call system error handler. */
_lx_nand_flash_system_error(nand_flash, status, block, 0);
#ifdef LX_THREAD_SAFE_ENABLE
/* Release the thread safe mutex. */
tx_mutex_put(&nand_flash -> lx_nand_flash_mutex);
#endif
/* Return an error. */
return(LX_ERROR);
}
#ifdef LX_THREAD_SAFE_ENABLE #ifdef LX_THREAD_SAFE_ENABLE
/* Release the thread safe mutex. */ /* Release the thread safe mutex. */
@@ -221,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;
+50 -56
View File
@@ -1,19 +1,19 @@
/**************************************************************************/ /***************************************************************************
/* */ * Copyright (c) 2024 Microsoft Corporation
/* Copyright (c) Microsoft Corporation. All rights reserved. */ * Copyright (c) 2026-present Eclipse ThreadX contributors
/* */ *
/* This software is licensed under the Microsoft Software License */ * This program and the accompanying materials are made available under the
/* Terms for Microsoft Azure RTOS. Full text of the license can be */ * terms of the MIT License which is available at
/* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */ * https://opensource.org/licenses/MIT.
/* and in the root directory of this software. */ *
/* */ * SPDX-License-Identifier: MIT
/**************************************************************************/ **************************************************************************/
/**************************************************************************/ /**************************************************************************/
/**************************************************************************/ /**************************************************************************/
/** */ /** */
/** LevelX Component */ /** LevelX Component */
/** */ /** */
/** NAND Flash */ /** NAND Flash */
/** */ /** */
@@ -35,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)
@@ -389,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);
} }
@@ -399,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;
@@ -413,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);
+54 -60
View File
@@ -1,19 +1,19 @@
/**************************************************************************/ /***************************************************************************
/* */ * Copyright (c) 2024 Microsoft Corporation
/* Copyright (c) Microsoft Corporation. All rights reserved. */ * Copyright (c) 2026-present Eclipse ThreadX contributors
/* */ *
/* This software is licensed under the Microsoft Software License */ * This program and the accompanying materials are made available under the
/* Terms for Microsoft Azure RTOS. Full text of the license can be */ * terms of the MIT License which is available at
/* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */ * https://opensource.org/licenses/MIT.
/* and in the root directory of this software. */ *
/* */ * SPDX-License-Identifier: MIT
/**************************************************************************/ **************************************************************************/
/**************************************************************************/ /**************************************************************************/
/**************************************************************************/ /**************************************************************************/
/** */ /** */
/** LevelX Component */ /** LevelX Component */
/** */ /** */
/** NAND Flash */ /** NAND Flash */
/** */ /** */
@@ -35,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)
@@ -115,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)
{ {
@@ -196,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)
{ {
@@ -223,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)
{ {
@@ -237,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))
{ {
@@ -248,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;
+40 -46
View File
@@ -1,19 +1,19 @@
/**************************************************************************/ /***************************************************************************
/* */ * Copyright (c) 2024 Microsoft Corporation
/* Copyright (c) Microsoft Corporation. All rights reserved. */ * Copyright (c) 2026-present Eclipse ThreadX contributors
/* */ *
/* This software is licensed under the Microsoft Software License */ * This program and the accompanying materials are made available under the
/* Terms for Microsoft Azure RTOS. Full text of the license can be */ * terms of the MIT License which is available at
/* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */ * https://opensource.org/licenses/MIT.
/* and in the root directory of this software. */ *
/* */ * SPDX-License-Identifier: MIT
/**************************************************************************/ **************************************************************************/
/**************************************************************************/ /**************************************************************************/
/**************************************************************************/ /**************************************************************************/
/** */ /** */
/** LevelX Component */ /** LevelX Component */
/** */ /** */
/** NAND Flash */ /** NAND Flash */
/** */ /** */
@@ -35,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)
+38 -44
View File
@@ -1,19 +1,19 @@
/**************************************************************************/ /***************************************************************************
/* */ * Copyright (c) 2024 Microsoft Corporation
/* Copyright (c) Microsoft Corporation. All rights reserved. */ * Copyright (c) 2026-present Eclipse ThreadX contributors
/* */ *
/* This software is licensed under the Microsoft Software License */ * This program and the accompanying materials are made available under the
/* Terms for Microsoft Azure RTOS. Full text of the license can be */ * terms of the MIT License which is available at
/* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */ * https://opensource.org/licenses/MIT.
/* and in the root directory of this software. */ *
/* */ * SPDX-License-Identifier: MIT
/**************************************************************************/ **************************************************************************/
/**************************************************************************/ /**************************************************************************/
/**************************************************************************/ /**************************************************************************/
/** */ /** */
/** LevelX Component */ /** LevelX Component */
/** */ /** */
/** NAND Flash */ /** NAND Flash */
/** */ /** */
@@ -35,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)
+41 -47
View File
@@ -1,19 +1,19 @@
/**************************************************************************/ /***************************************************************************
/* */ * Copyright (c) 2024 Microsoft Corporation
/* Copyright (c) Microsoft Corporation. All rights reserved. */ * Copyright (c) 2026-present Eclipse ThreadX contributors
/* */ *
/* This software is licensed under the Microsoft Software License */ * This program and the accompanying materials are made available under the
/* Terms for Microsoft Azure RTOS. Full text of the license can be */ * terms of the MIT License which is available at
/* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */ * https://opensource.org/licenses/MIT.
/* and in the root directory of this software. */ *
/* */ * SPDX-License-Identifier: MIT
/**************************************************************************/ **************************************************************************/
/**************************************************************************/ /**************************************************************************/
/**************************************************************************/ /**************************************************************************/
/** */ /** */
/** LevelX Component */ /** LevelX Component */
/** */ /** */
/** NAND Flash */ /** NAND Flash */
/** */ /** */
@@ -35,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)
@@ -90,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)
{ {
+66 -61
View File
@@ -1,19 +1,19 @@
/**************************************************************************/ /***************************************************************************
/* */ * Copyright (c) 2024 Microsoft Corporation
/* Copyright (c) Microsoft Corporation. All rights reserved. */ * Copyright (c) 2026-present Eclipse ThreadX contributors
/* */ *
/* This software is licensed under the Microsoft Software License */ * This program and the accompanying materials are made available under the
/* Terms for Microsoft Azure RTOS. Full text of the license can be */ * terms of the MIT License which is available at
/* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */ * https://opensource.org/licenses/MIT.
/* and in the root directory of this software. */ *
/* */ * SPDX-License-Identifier: MIT
/**************************************************************************/ **************************************************************************/
/**************************************************************************/ /**************************************************************************/
/**************************************************************************/ /**************************************************************************/
/** */ /** */
/** LevelX Component */ /** LevelX Component */
/** */ /** */
/** NAND Flash Simulator */ /** NAND Flash Simulator */
/** */ /** */
@@ -29,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
@@ -43,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
@@ -279,12 +279,17 @@ UINT ecc_status = LX_SUCCESS;
break; break;
} }
} }
if (spare_buffer)
{
#ifdef LX_NAND_ENABLE_CONTROL_BLOCK_FOR_DRIVER_INTERFACE #ifdef LX_NAND_ENABLE_CONTROL_BLOCK_FOR_DRIVER_INTERFACE
status = _lx_nand_flash_simulator_extra_bytes_get(nand_flash, block, page + i, spare_buffer + i * SPARE_BYTES_PER_PAGE, SPARE_BYTES_PER_PAGE); status = _lx_nand_flash_simulator_extra_bytes_get(nand_flash, block, page + i, spare_buffer + i * SPARE_BYTES_PER_PAGE, SPARE_BYTES_PER_PAGE);
#else #else
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);
} }
@@ -324,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--)
@@ -460,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;
} }
@@ -484,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];
@@ -492,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;
} }
@@ -516,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);
} }
@@ -551,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);
} }
@@ -584,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);
} }
@@ -602,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);
} }
@@ -620,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++;
} }
@@ -648,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++;
} }
+44 -57
View File
@@ -1,19 +1,19 @@
/**************************************************************************/ /***************************************************************************
/* */ * Copyright (c) 2024 Microsoft Corporation
/* Copyright (c) Microsoft Corporation. All rights reserved. */ * Copyright (c) 2026-present Eclipse ThreadX contributors
/* */ *
/* This software is licensed under the Microsoft Software License */ * This program and the accompanying materials are made available under the
/* Terms for Microsoft Azure RTOS. Full text of the license can be */ * terms of the MIT License which is available at
/* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */ * https://opensource.org/licenses/MIT.
/* and in the root directory of this software. */ *
/* */ * SPDX-License-Identifier: MIT
/**************************************************************************/ **************************************************************************/
/**************************************************************************/ /**************************************************************************/
/**************************************************************************/ /**************************************************************************/
/** */ /** */
/** LevelX Component */ /** LevelX Component */
/** */ /** */
/** NAND Flash */ /** NAND Flash */
/** */ /** */
@@ -35,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)
@@ -87,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);
+115 -130
View File
@@ -1,19 +1,19 @@
/**************************************************************************/ /***************************************************************************
/* */ * Copyright (c) 2024 Microsoft Corporation
/* Copyright (c) Microsoft Corporation. All rights reserved. */ * Copyright (c) 2026-present Eclipse ThreadX contributors
/* */ *
/* This software is licensed under the Microsoft Software License */ * This program and the accompanying materials are made available under the
/* Terms for Microsoft Azure RTOS. Full text of the license can be */ * terms of the MIT License which is available at
/* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */ * https://opensource.org/licenses/MIT.
/* and in the root directory of this software. */ *
/* */ * SPDX-License-Identifier: MIT
/**************************************************************************/ **************************************************************************/
/**************************************************************************/ /**************************************************************************/
/**************************************************************************/ /**************************************************************************/
/** */ /** */
/** LevelX Component */ /** LevelX Component */
/** */ /** */
/** NOR Flash */ /** NOR Flash */
/** */ /** */
@@ -35,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)
@@ -117,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;
@@ -133,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);
} }
@@ -165,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);
@@ -213,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);
@@ -227,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;
@@ -249,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;
@@ -268,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
@@ -277,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);
@@ -289,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;
@@ -329,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;
} }
@@ -338,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) +
@@ -349,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);
@@ -367,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);
@@ -381,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);
@@ -391,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);
@@ -426,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);
@@ -446,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);
@@ -470,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;
@@ -483,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);
} }
@@ -534,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);
@@ -563,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);
@@ -577,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);
+38 -48
View File
@@ -1,19 +1,19 @@
/**************************************************************************/ /***************************************************************************
/* */ * Copyright (c) 2024 Microsoft Corporation
/* Copyright (c) Microsoft Corporation. All rights reserved. */ * Copyright (c) 2026-present Eclipse ThreadX contributors
/* */ *
/* This software is licensed under the Microsoft Software License */ * This program and the accompanying materials are made available under the
/* Terms for Microsoft Azure RTOS. Full text of the license can be */ * terms of the MIT License which is available at
/* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */ * https://opensource.org/licenses/MIT.
/* and in the root directory of this software. */ *
/* */ * SPDX-License-Identifier: MIT
/**************************************************************************/ **************************************************************************/
/**************************************************************************/ /**************************************************************************/
/**************************************************************************/ /**************************************************************************/
/** */ /** */
/** LevelX Component */ /** LevelX Component */
/** */ /** */
/** NOR Flash */ /** NOR Flash */
/** */ /** */
@@ -35,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)
@@ -106,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;
} }
} }
@@ -117,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
+43 -53
View File
@@ -1,19 +1,19 @@
/**************************************************************************/ /***************************************************************************
/* */ * Copyright (c) 2024 Microsoft Corporation
/* Copyright (c) Microsoft Corporation. All rights reserved. */ * Copyright (c) 2026-present Eclipse ThreadX contributors
/* */ *
/* This software is licensed under the Microsoft Software License */ * This program and the accompanying materials are made available under the
/* Terms for Microsoft Azure RTOS. Full text of the license can be */ * terms of the MIT License which is available at
/* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */ * https://opensource.org/licenses/MIT.
/* and in the root directory of this software. */ *
/* */ * SPDX-License-Identifier: MIT
/**************************************************************************/ **************************************************************************/
/**************************************************************************/ /**************************************************************************/
/**************************************************************************/ /**************************************************************************/
/** */ /** */
/** LevelX Component */ /** LevelX Component */
/** */ /** */
/** NOR Flash */ /** NOR Flash */
/** */ /** */
@@ -35,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;
@@ -94,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);
} }
@@ -109,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);
} }
+43 -56
View File
@@ -1,19 +1,19 @@
/**************************************************************************/ /***************************************************************************
/* */ * Copyright (c) 2024 Microsoft Corporation
/* Copyright (c) Microsoft Corporation. All rights reserved. */ * Copyright (c) 2026-present Eclipse ThreadX contributors
/* */ *
/* This software is licensed under the Microsoft Software License */ * This program and the accompanying materials are made available under the
/* Terms for Microsoft Azure RTOS. Full text of the license can be */ * terms of the MIT License which is available at
/* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */ * https://opensource.org/licenses/MIT.
/* and in the root directory of this software. */ *
/* */ * SPDX-License-Identifier: MIT
/**************************************************************************/ **************************************************************************/
/**************************************************************************/ /**************************************************************************/
/**************************************************************************/ /**************************************************************************/
/** */ /** */
/** LevelX Component */ /** LevelX Component */
/** */ /** */
/** NOR Flash */ /** NOR Flash */
/** */ /** */
@@ -35,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)
@@ -98,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;
@@ -128,7 +115,7 @@ ULONG *cache_entry_end;
#endif #endif
/* Return completion status. */ /* Return completion status. */
return(status); return(status);
} }
+69 -82
View File
@@ -1,19 +1,19 @@
/**************************************************************************/ /***************************************************************************
/* */ * Copyright (c) 2024 Microsoft Corporation
/* Copyright (c) Microsoft Corporation. All rights reserved. */ * Copyright (c) 2026-present Eclipse ThreadX contributors
/* */ *
/* This software is licensed under the Microsoft Software License */ * This program and the accompanying materials are made available under the
/* Terms for Microsoft Azure RTOS. Full text of the license can be */ * terms of the MIT License which is available at
/* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */ * https://opensource.org/licenses/MIT.
/* and in the root directory of this software. */ *
/* */ * SPDX-License-Identifier: MIT
/**************************************************************************/ **************************************************************************/
/**************************************************************************/ /**************************************************************************/
/**************************************************************************/ /**************************************************************************/
/** */ /** */
/** LevelX Component */ /** LevelX Component */
/** */ /** */
/** NOR Flash */ /** NOR Flash */
/** */ /** */
@@ -35,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)
@@ -99,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;
} }
@@ -161,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);
@@ -207,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;
@@ -221,7 +208,7 @@ UINT status;
#endif #endif
/* Return completion status. */ /* Return completion status. */
return(status); return(status);
#endif #endif
} }
+50 -63
View File
@@ -1,19 +1,19 @@
/**************************************************************************/ /***************************************************************************
/* */ * Copyright (c) 2024 Microsoft Corporation
/* Copyright (c) Microsoft Corporation. All rights reserved. */ * Copyright (c) 2026-present Eclipse ThreadX contributors
/* */ *
/* This software is licensed under the Microsoft Software License */ * This program and the accompanying materials are made available under the
/* Terms for Microsoft Azure RTOS. Full text of the license can be */ * terms of the MIT License which is available at
/* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */ * https://opensource.org/licenses/MIT.
/* and in the root directory of this software. */ *
/* */ * SPDX-License-Identifier: MIT
/**************************************************************************/ **************************************************************************/
/**************************************************************************/ /**************************************************************************/
/**************************************************************************/ /**************************************************************************/
/** */ /** */
/** LevelX Component */ /** LevelX Component */
/** */ /** */
/** NOR Flash */ /** NOR Flash */
/** */ /** */
@@ -35,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)
@@ -103,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);
@@ -136,8 +123,8 @@ ULONG cache_offset;
#endif #endif
/* Return completion status. */ /* Return completion status. */
return(status); return(status);
#else #else
UINT status; UINT status;
@@ -148,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
} }
+60 -82
View File
@@ -1,19 +1,19 @@
/**************************************************************************/ /***************************************************************************
/* */ * Copyright (c) 2024 Microsoft Corporation
/* Copyright (c) Microsoft Corporation. All rights reserved. */ * Copyright (c) 2026-present Eclipse ThreadX contributors
/* */ *
/* This software is licensed under the Microsoft Software License */ * This program and the accompanying materials are made available under the
/* Terms for Microsoft Azure RTOS. Full text of the license can be */ * terms of the MIT License which is available at
/* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */ * https://opensource.org/licenses/MIT.
/* and in the root directory of this software. */ *
/* */ * SPDX-License-Identifier: MIT
/**************************************************************************/ **************************************************************************/
/**************************************************************************/ /**************************************************************************/
/**************************************************************************/ /**************************************************************************/
/** */ /** */
/** LevelX Component */ /** LevelX Component */
/** */ /** */
/** NOR Flash */ /** NOR Flash */
/** */ /** */
@@ -35,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)
@@ -118,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);
} }
@@ -147,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)
{ {
@@ -155,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++)
{ {
@@ -177,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)
{ {
@@ -190,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;
@@ -219,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
@@ -231,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);
@@ -244,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)
{ {
@@ -252,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)
{ {
@@ -264,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
{ {
@@ -288,29 +266,29 @@ 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) 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)
{ {
nor_flash -> lx_nor_flash_extended_cache_entries = LX_NOR_EXTENDED_CACHE_SIZE; nor_flash -> lx_nor_flash_extended_cache_entries = LX_NOR_EXTENDED_CACHE_SIZE;
@@ -319,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
+167
View File
@@ -0,0 +1,167 @@
/***************************************************************************
* Copyright (c) 2025 Microsoft Corporation
* Copyright (c) 2025 STmicroelectronics
*
* This program and the accompanying materials are made available under the
* terms of the MIT License which is available at
* https://opensource.org/licenses/MIT.
*
* SPDX-License-Identifier: MIT
**************************************************************************/
/**************************************************************************/
/**************************************************************************/
/** */
/** LevelX Component */
/** */
/** NOR Flash */
/** */
/**************************************************************************/
/**************************************************************************/
#define LX_SOURCE_CODE
/* Disable ThreadX error checking. */
#ifndef LX_DISABLE_ERROR_CHECKING
#define LX_DISABLE_ERROR_CHECKING
#endif
/* Include necessary system files. */
#include "lx_api.h"
/**************************************************************************/
/* */
/* FUNCTION RELEASE */
/* */
/* _lx_nor_flash_format PORTABLE C */
/* */
/* DESCRIPTION */
/* */
/* This function opens a NOR flash instance then erases all the non */
/* erased blocks, then writes the erase count */
/* */
/* INPUT */
/* */
/* nor_flash NOR flash instance */
/* name Name of NOR flash instance */
/* nor_driver_initialize Driver initialize */
/* nor_driver_info_ptr Drivier user data pointer */
/* */
/* OUTPUT */
/* */
/* return status */
/* */
/* CALLS */
/* */
/* (nor_driver_initialize) Driver initialize */
/* _lx_nor_flash_driver_read Driver read */
/* _lx_nor_flash_driver_write Driver write */
/* (lx_nor_flash_driver_block_erased_verify) */
/* NOR flash verify block erased */
/* _lx_nor_flash_driver_block_erase Driver block erase */
/* */
/* CALLED BY */
/* */
/* Application Code */
/* */
/**************************************************************************/
UINT _lx_nor_flash_format(LX_NOR_FLASH *nor_flash, CHAR *name, UINT (*nor_driver_initialize)(LX_NOR_FLASH *), VOID *nor_driver_info_ptr)
{
ULONG l;
UINT status;
ULONG block_word;
ULONG *block_word_ptr;
LX_PARAMETER_NOT_USED(name);
/* Clear the NOR flash control block. User extension is not cleared. */
LX_MEMSET(nor_flash, 0, (ULONG)((UCHAR*)&(nor_flash -> lx_nor_flash_open_previous) - (UCHAR*)nor_flash) + sizeof(nor_flash -> lx_nor_flash_open_previous));
nor_flash -> lx_nor_flash_driver_info_ptr = nor_driver_info_ptr;
/* Call the flash driver's initialization function. */
(nor_driver_initialize)(nor_flash);
#ifndef LX_DIRECT_READ
/* Determine if the driver supplied a RAM buffer for reading the NOR sector if direct read is not
supported. */
if (nor_flash -> lx_nor_flash_sector_buffer == LX_NULL)
{
/* Return an error. */
return(LX_NO_MEMORY);
}
#endif
for (l = 0; l < nor_flash -> lx_nor_flash_total_blocks; l++)
{
#ifdef LX_NOR_ENABLE_CONTROL_BLOCK_FOR_DRIVER_INTERFACE
/* Check that the block is already erased */
status = (nor_flash -> lx_nor_flash_driver_block_erased_verify)(nor_flash, l);
#else
status = (nor_flash -> lx_nor_flash_driver_block_erased_verify)(l);
#endif
/* the block is not erased, thus make sure to erase it */
if (status)
{
/* the max erase count is not needed just pass the value 0 */
status = _lx_nor_flash_driver_block_erase(nor_flash, l, 0);
/* Check for an error from flash driver */
if (status)
{
/* Call system error handler. */
_lx_nor_flash_system_error(nor_flash, status);
/* Return an error. */
return(LX_ERROR);
}
/* check that the sector was correctly erased */
#ifdef LX_NOR_ENABLE_CONTROL_BLOCK_FOR_DRIVER_INTERFACE
status = (nor_flash -> lx_nor_flash_driver_block_erased_verify)(nor_flash, l);
#else
status = (nor_flash -> lx_nor_flash_driver_block_erased_verify)(l);
#endif
if (status)
{
/* Call system error handler. */
_lx_nor_flash_system_error(nor_flash, status);
/* Return an error. */
return(LX_ERROR);
}
}
/* Setup the block word pointer to the first word of the first block */
block_word_ptr = nor_flash -> lx_nor_flash_base_address + l * nor_flash -> lx_nor_flash_words_per_block;
/* Setup the initial erase_count to 1 and mark the block as erased.
* When the lx_nor_flash_open() gets called only the erase count will be kept.
*/
block_word = ((ULONG)1 | LX_BLOCK_ERASED);
status = _lx_nor_flash_driver_write(nor_flash, block_word_ptr, &block_word, 1);
if (status)
{
/* Call system error handler. */
_lx_nor_flash_system_error(nor_flash, status);
/* Return an error. */
return(LX_ERROR);
}
}
return(LX_SUCCESS);
}
+36 -46
View File
@@ -1,19 +1,19 @@
/**************************************************************************/ /***************************************************************************
/* */ * Copyright (c) 2024 Microsoft Corporation
/* Copyright (c) Microsoft Corporation. All rights reserved. */ * Copyright (c) 2026-present Eclipse ThreadX contributors
/* */ *
/* This software is licensed under the Microsoft Software License */ * This program and the accompanying materials are made available under the
/* Terms for Microsoft Azure RTOS. Full text of the license can be */ * terms of the MIT License which is available at
/* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */ * https://opensource.org/licenses/MIT.
/* and in the root directory of this software. */ *
/* */ * SPDX-License-Identifier: MIT
/**************************************************************************/ **************************************************************************/
/**************************************************************************/ /**************************************************************************/
/**************************************************************************/ /**************************************************************************/
/** */ /** */
/** LevelX Component */ /** LevelX Component */
/** */ /** */
/** NOR Flash */ /** NOR Flash */
/** */ /** */
@@ -34,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)
@@ -81,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);
} }
+105 -121
View File
@@ -1,19 +1,19 @@
/**************************************************************************/ /***************************************************************************
/* */ * Copyright (c) 2024 Microsoft Corporation
/* Copyright (c) Microsoft Corporation. All rights reserved. */ * Copyright (c) 2026-present Eclipse ThreadX contributors
/* */ *
/* This software is licensed under the Microsoft Software License */ * This program and the accompanying materials are made available under the
/* Terms for Microsoft Azure RTOS. Full text of the license can be */ * terms of the MIT License which is available at
/* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */ * https://opensource.org/licenses/MIT.
/* and in the root directory of this software. */ *
/* */ * SPDX-License-Identifier: MIT
/**************************************************************************/ **************************************************************************/
/**************************************************************************/ /**************************************************************************/
/**************************************************************************/ /**************************************************************************/
/** */ /** */
/** LevelX Component */ /** LevelX Component */
/** */ /** */
/** NOR Flash */ /** NOR Flash */
/** */ /** */
@@ -35,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)
@@ -120,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)
{ {
@@ -128,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
@@ -139,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);
} }
@@ -150,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))
{ {
@@ -231,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++;
} }
@@ -249,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)
@@ -263,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;
} }
} }
@@ -285,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
@@ -299,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);
@@ -307,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
@@ -321,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);
@@ -340,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;
} }
} }
} }
@@ -364,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--)
{ {
@@ -382,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
@@ -394,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);
@@ -402,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)
@@ -446,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);
@@ -456,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);
@@ -470,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);
@@ -501,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
@@ -523,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;
} }
@@ -542,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);
} }
@@ -559,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;
} }
@@ -576,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,19 +1,19 @@
/**************************************************************************/ /***************************************************************************
/* */ * Copyright (c) 2024 Microsoft Corporation
/* Copyright (c) Microsoft Corporation. All rights reserved. */ * Copyright (c) 2026-present Eclipse ThreadX contributors
/* */ *
/* This software is licensed under the Microsoft Software License */ * This program and the accompanying materials are made available under the
/* Terms for Microsoft Azure RTOS. Full text of the license can be */ * terms of the MIT License which is available at
/* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */ * https://opensource.org/licenses/MIT.
/* and in the root directory of this software. */ *
/* */ * SPDX-License-Identifier: MIT
/**************************************************************************/ **************************************************************************/
/**************************************************************************/ /**************************************************************************/
/**************************************************************************/ /**************************************************************************/
/** */ /** */
/** LevelX Component */ /** LevelX Component */
/** */ /** */
/** NOR Flash */ /** NOR Flash */
/** */ /** */
@@ -35,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)
@@ -127,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
@@ -165,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);
@@ -190,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. */
@@ -208,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
@@ -217,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);
@@ -225,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
@@ -239,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);
@@ -252,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;
} }
@@ -281,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
@@ -293,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);
@@ -301,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++;
} }
@@ -329,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))
{ {
@@ -344,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;
@@ -374,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;
@@ -386,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;
} }
@@ -398,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;
@@ -408,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;
@@ -433,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);
+78 -882
View File
@@ -1,19 +1,20 @@
/**************************************************************************/ /***************************************************************************
/* */ * Copyright (c) 2024 Microsoft Corporation
/* Copyright (c) Microsoft Corporation. All rights reserved. */ * Copyright (c) 2026-present Eclipse ThreadX contributors
/* */ * Portion Copyright (c) 2025 STMicroelectronics
/* This software is licensed under the Microsoft Software License */ *
/* Terms for Microsoft Azure RTOS. Full text of the license can be */ * This program and the accompanying materials are made available under the
/* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */ * terms of the MIT License which is available at
/* and in the root directory of this software. */ * https://opensource.org/licenses/MIT.
/* */ *
/**************************************************************************/ * SPDX-License-Identifier: MIT
**************************************************************************/
/**************************************************************************/ /**************************************************************************/
/**************************************************************************/ /**************************************************************************/
/** */ /** */
/** LevelX Component */ /** LevelX Component */
/** */ /** */
/** NOR Flash */ /** NOR Flash */
/** */ /** */
@@ -34,879 +35,74 @@
#include "lx_api.h" #include "lx_api.h"
/***************************************************************************/
/* */
/* FUNCTION RELEASE */
/* */
/* _lx_nor_flash_open PORTABLE C */
/* 6.3.0 */
/* AUTHOR */
/* */
/* William E. Lamie, Microsoft Corporation */
/* */
/* DESCRIPTION */
/* */
/* This function opens a NOR flash instance and ensures the NOR flash */
/* is in a coherent state. */
/* */
/* INPUT */
/* */
/* nor_flash NOR flash instance */
/* name Name of NOR flash instance */
/* nor_driver_initialize Driver initialize */
/* */
/* OUTPUT */
/* */
/* return status */
/* */
/* CALLS */
/* lx_nor_flash_open_extended() */
/* */
/* CALLED BY */
/* */
/* 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 */
/* 10-21-2025 Modified comment(s) */
/* call the extended equivalent */
/* API */
/**************************************************************************/
/* */
/* FUNCTION RELEASE */
/* */
/* _lx_nor_flash_open PORTABLE C */
/* 6.3.0 */
/* AUTHOR */
/* */
/* William E. Lamie, Microsoft Corporation */
/* */
/* DESCRIPTION */
/* */
/* This function opens a NOR flash instance and ensures the NOR flash */
/* is in a coherent state. */
/* */
/* INPUT */
/* */
/* nor_flash NOR flash instance */
/* name Name of NOR flash instance */
/* nor_driver_initialize Driver initialize */
/* */
/* OUTPUT */
/* */
/* return status */
/* */
/* CALLS */
/* */
/* (nor_driver_initialize) Driver initialize */
/* _lx_nor_flash_driver_read Driver read */
/* _lx_nor_flash_driver_write Driver write */
/* (lx_nor_flash_driver_block_erased_verify) */
/* NOR flash verify block erased */
/* _lx_nor_flash_driver_block_erase Driver block erase */
/* _lx_nor_flash_logical_sector_find Find logical sector */
/* _lx_nor_flash_system_error System error handler */
/* tx_mutex_create Create thread-safe mutex */
/* */
/* CALLED BY */
/* */
/* 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(LX_NOR_FLASH *nor_flash, CHAR *name, UINT (*nor_driver_initialize)(LX_NOR_FLASH *)) UINT _lx_nor_flash_open(LX_NOR_FLASH *nor_flash, CHAR *name, UINT (*nor_driver_initialize)(LX_NOR_FLASH *))
{ {
ULONG sectors_per_block; UINT status = LX_ERROR;
ULONG sector_map_words;
ULONG bit_map_words;
ULONG bit_map_mask;
ULONG total_header_words;
ULONG header_sectors;
ULONG *block_word_ptr;
ULONG block_word;
ULONG temp;
ULONG free_sectors;
ULONG used_sectors;
ULONG *new_map_entry;
ULONG *new_sector_address;
ULONG erased_count, min_erased_count, max_erased_count, temp_erased_count, min_erased_blocks;
ULONG j, k, l;
UINT status;
#ifdef LX_FREE_SECTOR_DATA_VERIFY
ULONG *sector_word_ptr;
ULONG sector_word;
#endif
LX_NOR_FLASH *tail_ptr;
LX_INTERRUPT_SAVE_AREA
LX_PARAMETER_NOT_USED(name); status = _lx_nor_flash_open_extended(nor_flash, name, nor_driver_initialize, NULL);
/* Clear the NOR flash control block. User extension is not cleared. */ return status;
LX_MEMSET(nor_flash, 0, (ULONG)((UCHAR*)&(nor_flash -> lx_nor_flash_open_previous) - (UCHAR*)nor_flash) + sizeof(nor_flash -> lx_nor_flash_open_previous));
/* Call the flash driver's initialization function. */
(nor_driver_initialize)(nor_flash);
#ifndef LX_DIRECT_READ
/* Determine if the driver supplied a RAM buffer for reading the NOR sector if direct read is not
supported. */
if (nor_flash -> lx_nor_flash_sector_buffer == LX_NULL)
{
/* Return an error. */
return(LX_NO_MEMORY);
}
#endif
/* Setup the offset to the free bit map. */
nor_flash -> lx_nor_flash_block_free_bit_map_offset = sizeof(LX_NOR_FLASH_BLOCK_HEADER)/sizeof(ULONG);
/* Calculate the number of bits we need in the free physical sector bit map. Subtract 1 to account for the
flash block header itself. The case where multiple physical sectors are needed for certain sized flash
devices is handled below. */
sectors_per_block = (nor_flash -> lx_nor_flash_words_per_block / LX_NOR_SECTOR_SIZE) - 1;
/* Calculate the number of words required for the sector map array. */
sector_map_words = sectors_per_block;
/* Calculate the number of words we need for the free physical sector bit map. */
bit_map_words = (sectors_per_block + 31)/ 32;
/* Save the number of bit map words. */
nor_flash -> lx_nor_flash_block_bit_map_words = bit_map_words;
/* Setup the offset (in words) to the array of physical sector mapping. */
nor_flash -> lx_nor_flash_block_physical_sector_mapping_offset = nor_flash -> lx_nor_flash_block_free_bit_map_offset + bit_map_words;
/* Calculate the total number of words required for the flash block header. */
total_header_words = sizeof(LX_NOR_FLASH_BLOCK_HEADER)/sizeof(ULONG) + bit_map_words + sector_map_words;
/* Determine if more physical sectors are needed, which can happen on large devices. */
if (total_header_words <= LX_NOR_SECTOR_SIZE)
{
/* Round up to the size of 1 physical sector. */
total_header_words = LX_NOR_SECTOR_SIZE;
}
else
{
/* Otherwise calculate how many header sectors are necessary. */
header_sectors = (total_header_words-1)/LX_NOR_SECTOR_SIZE;
/* Round up to the next sector. */
header_sectors++;
/* Compute the total header words, rounding to the next sector. */
total_header_words = header_sectors * LX_NOR_SECTOR_SIZE;
/* Adjust the number of sectors per block. */
sectors_per_block = sectors_per_block - (header_sectors - 1);
}
/* Save the offset to the sector area. */
nor_flash -> lx_nor_flash_block_physical_sector_offset = total_header_words;
/* Save the physical sectors per block and total physical sectors. */
nor_flash -> lx_nor_flash_physical_sectors_per_block = sectors_per_block;
nor_flash -> lx_nor_flash_total_physical_sectors = nor_flash -> lx_nor_flash_total_blocks * sectors_per_block;
/* Build the free bit map mask, for the portion of the bit map that is less than 32 bits. */
if ((sectors_per_block % 32) != 0)
{
bit_map_mask = (ULONG)(1 << (sectors_per_block % 32));
bit_map_mask = bit_map_mask - 1;
}
else
{
/* Exactly 32 sectors for the bit map mask. */
bit_map_mask = LX_ALL_ONES;
}
/* Save the free bit map mask in the control block. */
nor_flash -> lx_nor_flash_block_bit_map_mask = bit_map_mask;
/* Setup default values for the max/min erased counts. */
min_erased_count = LX_ALL_ONES;
min_erased_blocks = 0;
max_erased_count = 0;
/* Setup the block word pointer to the first word of the first block, which is effectively the
flash base address. */
block_word_ptr = nor_flash -> lx_nor_flash_base_address;
/* Loop through the blocks to determine the minimum and maximum erase count. */
for (l = 0; l < nor_flash -> lx_nor_flash_total_blocks; l++)
{
/* Pickup the first word of the block. If the flash manager has executed before, this word contains the
erase count for the block. Otherwise, if the word is 0xFFFFFFFF, this flash block was either erased
or this is the first time it was used. */
#ifdef LX_DIRECT_READ
/* Read the word directly. */
block_word = *block_word_ptr;
#else
status = _lx_nor_flash_driver_read(nor_flash, block_word_ptr, &block_word, 1);
/* Check for an error from flash driver. Drivers should never return an error.. */
if (status)
{
/* Call system error handler. */
_lx_nor_flash_system_error(nor_flash, status);
/* Return an error. */
return(LX_ERROR);
}
#endif
/* Is the block erased? */
if (((block_word & LX_BLOCK_ERASED) != LX_BLOCK_ERASED) && (block_word != LX_BLOCK_ERASE_STARTED))
{
/* No, valid block. Isolate the erased count. */
erased_count = (block_word & LX_BLOCK_ERASE_COUNT_MASK);
/* Is the erased count the minimum? */
if (erased_count == min_erased_count)
{
/* Yes, increment the minimum erased block count. */
min_erased_blocks++;
}
/* Is this the new minimum? */
if (erased_count < min_erased_count)
{
/* Yes, remember the new minimum. */
min_erased_count = erased_count;
/* Reset the minimum erased block count. */
min_erased_blocks = 1;
}
/* Is this the new maximum? */
if (erased_count > max_erased_count)
{
/* Yes, remember the new maximum. */
max_erased_count = erased_count;
}
}
/* Move to the next flash block. */
block_word_ptr = block_word_ptr + (nor_flash -> lx_nor_flash_words_per_block);
}
/* If we haven't found any erased counts, we can assume the flash is completely erased and needs to
be setup for the first time. */
if (min_erased_count == LX_ALL_ONES)
{
/* Indicate that this is the initial format. */
nor_flash -> lx_nor_flash_diagnostic_initial_format = LX_TRUE;
/* Setup the block word pointer to the first word of the first block, which is effectively the
flash base address. */
block_word_ptr = nor_flash -> lx_nor_flash_base_address;
/* Loop through the blocks to setup the flash the fist time. */
for (l = 0; l < nor_flash -> lx_nor_flash_total_blocks; l++)
{
/* 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
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 + (bit_map_words-1)) , &bit_map_mask, 1);
/* Check for an error from flash driver. Drivers should never return an error.. */
if (status)
{
/* Call system error handler. */
_lx_nor_flash_system_error(nor_flash, status);
/* Return an error. */
return(LX_ERROR);
}
/* Setup the initial erase count to 1. */
block_word = ((ULONG) 1);
/* Write the initial erase count for the block. */
status = _lx_nor_flash_driver_write(nor_flash, block_word_ptr, &block_word, 1);
/* Check for an error from flash driver. Drivers should never return an error.. */
if (status)
{
/* Call system error handler. */
_lx_nor_flash_system_error(nor_flash, status);
/* Return an error. */
return(LX_ERROR);
}
/* Update the overall minimum and maximum erase count. */
nor_flash -> lx_nor_flash_minimum_erase_count = 1;
nor_flash -> lx_nor_flash_minimum_erased_blocks = nor_flash -> lx_nor_flash_total_blocks;
nor_flash -> lx_nor_flash_maximum_erase_count = 1;
/* Update the number of free physical sectors. */
nor_flash -> lx_nor_flash_free_physical_sectors = nor_flash -> lx_nor_flash_free_physical_sectors + sectors_per_block;
/* Move to the next flash block. */
block_word_ptr = block_word_ptr + (nor_flash -> lx_nor_flash_words_per_block);
}
}
else
{
/* At this point, we have a previously managed flash structure. This needs to be traversed to prepare for the
current flash operation. */
/* Default the flash free sector search to an invalid value. */
nor_flash -> lx_nor_flash_free_block_search = nor_flash -> lx_nor_flash_total_blocks;
/* Setup the block word pointer to the first word of the first block, which is effectively the
flash base address. */
block_word_ptr = nor_flash -> lx_nor_flash_base_address;
/* Loop through the blocks. */
for (l = 0; l < nor_flash -> lx_nor_flash_total_blocks; l++)
{
/* First, determine if this block has a valid erase count. */
#ifdef LX_DIRECT_READ
/* Read the word directly. */
block_word = *block_word_ptr;
#else
status = _lx_nor_flash_driver_read(nor_flash, block_word_ptr, &block_word, 1);
/* Check for an error from flash driver. Drivers should never return an error.. */
if (status)
{
/* Call system error handler. */
_lx_nor_flash_system_error(nor_flash, status);
/* Return an error. */
return(LX_ERROR);
}
#endif
/* Is the block erased? */
if (((block_word & LX_BLOCK_ERASED) == LX_BLOCK_ERASED) || (block_word == LX_BLOCK_ERASE_STARTED))
{
/* This can happen if we were previously in the process of erasing the flash block and a
power interruption occurs. It should only occur once though. */
/* Is this the first time? */
if (nor_flash -> lx_nor_flash_diagnostic_erased_block)
{
/* No, this is a potential format error, since this should only happen once in a given
NOR flash format. */
_lx_nor_flash_system_error(nor_flash, LX_SYSTEM_INVALID_BLOCK);
/* Return an error. */
return(LX_ERROR);
}
/* Increment the erased block diagnostic. */
nor_flash -> lx_nor_flash_diagnostic_erased_block++;
/* Check to see if the block is erased. */
#ifdef LX_NOR_ENABLE_CONTROL_BLOCK_FOR_DRIVER_INTERFACE
status = (nor_flash -> lx_nor_flash_driver_block_erased_verify)(nor_flash, l);
#else
status = (nor_flash -> lx_nor_flash_driver_block_erased_verify)(l);
#endif
/* Is the block completely erased? */
if (status != LX_SUCCESS)
{
/* Is this the first time? */
if (nor_flash -> lx_nor_flash_diagnostic_re_erase_block)
{
/* No, this is a potential format error, since this should only happen once in a given
NOR flash format. */
_lx_nor_flash_system_error(nor_flash, LX_SYSTEM_INVALID_BLOCK);
/* Return an error. */
return(LX_ERROR);
}
/* Increment the erased block diagnostic. */
nor_flash -> lx_nor_flash_diagnostic_re_erase_block++;
/* No, the block is not fully erased, erase it again. */
status = _lx_nor_flash_driver_block_erase(nor_flash, l, max_erased_count);
/* Check for an error from flash driver. Drivers should never return an error.. */
if (status)
{
/* Call system error handler. */
_lx_nor_flash_system_error(nor_flash, status);
/* Return an error. */
return(LX_ERROR);
}
}
/* 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
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 + (bit_map_words-1)) , &bit_map_mask, 1);
/* Check for an error from flash driver. Drivers should never return an error.. */
if (status)
{
/* Call system error handler. */
_lx_nor_flash_system_error(nor_flash, status);
/* Return an error. */
return(LX_ERROR);
}
/* Write the initial erase count for the block with upper bit set. */
temp_erased_count = (max_erased_count | LX_BLOCK_ERASED);
status = _lx_nor_flash_driver_write(nor_flash, block_word_ptr, &temp_erased_count, 1);
/* Check for an error from flash driver. Drivers should never return an error.. */
if (status)
{
/* Call system error handler. */
_lx_nor_flash_system_error(nor_flash, status);
/* Return an error. */
return(LX_ERROR);
}
/* Write the final initial erase count for the block. */
status = _lx_nor_flash_driver_write(nor_flash, block_word_ptr, &max_erased_count, 1);
/* Check for an error from flash driver. Drivers should never return an error.. */
if (status)
{
/* Call system error handler. */
_lx_nor_flash_system_error(nor_flash, status);
/* Return an error. */
return(LX_ERROR);
}
/* Update the number of free physical sectors. */
nor_flash -> lx_nor_flash_free_physical_sectors = nor_flash -> lx_nor_flash_free_physical_sectors + sectors_per_block;
}
else
{
/* Calculate the number of free sectors from the free sector bit map. */
free_sectors = 0;
for (j = 0; j < bit_map_words; j++)
{
/* Read this word of the free sector bit map. */
#ifdef LX_DIRECT_READ
/* Read the word directly. */
block_word = *(block_word_ptr + nor_flash -> lx_nor_flash_block_free_bit_map_offset + j);
#else
status = _lx_nor_flash_driver_read(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.. */
if (status)
{
/* Call system error handler. */
_lx_nor_flash_system_error(nor_flash, status);
/* Return an error. */
return(LX_ERROR);
}
#endif
/* Count the number of set bits (free sectors). */
for (k = 0; k < 32; k++)
{
/* Is this sector free? */
if (block_word & 1)
{
/* Yes, this sector is free, increment the free sectors count. */
free_sectors++;
/* Determine if we need to update the search pointer. */
if (nor_flash -> lx_nor_flash_free_block_search == nor_flash -> lx_nor_flash_total_blocks)
{
/* Remember the block with free sectors. */
nor_flash -> lx_nor_flash_free_block_search = l;
}
}
/* Shift down the free sector. */
block_word = block_word >> 1;
}
}
/* Update the number of free physical sectors. */
nor_flash -> lx_nor_flash_free_physical_sectors = nor_flash -> lx_nor_flash_free_physical_sectors + free_sectors;
/* We need to now examine the mapping list. */
/* Calculate how many non-free sectors there are - this includes valid and obsolete sectors. */
used_sectors = sectors_per_block - free_sectors;
/* Now walk the list of logical-physical sector mapping. */
for (j = 0; j < sectors_per_block; j++)
{
/* Read this word of the sector mapping list. */
#ifdef LX_DIRECT_READ
/* Read the word directly. */
block_word = *(block_word_ptr + nor_flash -> lx_nor_flash_block_physical_sector_mapping_offset + j);
#else
status = _lx_nor_flash_driver_read(nor_flash, (block_word_ptr + nor_flash -> lx_nor_flash_block_physical_sector_mapping_offset + j), &block_word, 1);
/* Check for an error from flash driver. Drivers should never return an error.. */
if (status)
{
/* Call system error handler. */
_lx_nor_flash_system_error(nor_flash, status);
/* Return an error. */
return(LX_ERROR);
}
#endif
/* Determine if we are expecting to find a used sector. */
if (used_sectors)
{
/* Yes, we expect this entry to be used. */
/* Is this sector in-use? */
if ((block_word & LX_NOR_LOGICAL_SECTOR_MASK) != LX_NOR_LOGICAL_SECTOR_MASK)
{
/* Determine if the valid bit is set and the superceded bit is clear. This indicates the block was
about to become obsolete. */
if ((block_word & LX_NOR_PHYSICAL_SECTOR_VALID) && ((block_word & LX_NOR_PHYSICAL_SECTOR_SUPERCEDED) == 0))
{
/* Increment the being obsoleted count. */
nor_flash -> lx_nor_flash_diagnostic_sector_being_obsoleted++;
/* Save the currently mapped physical sectors. */
temp = nor_flash -> lx_nor_flash_mapped_physical_sectors;
/* Indicate all the physical sectors are mapped for the purpose of this search. */
nor_flash -> lx_nor_flash_mapped_physical_sectors = nor_flash -> lx_nor_flash_total_physical_sectors;
/* Yes, this block was about to become obsolete. Perform a search for a logical sector entry that
has both of these bits set. */
_lx_nor_flash_logical_sector_find(nor_flash, (block_word & LX_NOR_LOGICAL_SECTOR_MASK), LX_TRUE, &new_map_entry, &new_sector_address);
/* Restore the number of mapped physical sectors. */
nor_flash -> lx_nor_flash_mapped_physical_sectors = temp;
/* Determine if the new logical sector entry is present. */
if (new_map_entry)
{
/* Yes, make the current entry obsolete in favor of the new entry. */
block_word = block_word & ~((ULONG) LX_NOR_PHYSICAL_SECTOR_VALID);
status = _lx_nor_flash_driver_write(nor_flash, (block_word_ptr + nor_flash -> lx_nor_flash_block_physical_sector_mapping_offset + j), &block_word, 1);
/* Check for an error from flash driver. Drivers should never return an error.. */
if (status)
{
/* Call system error handler. */
_lx_nor_flash_system_error(nor_flash, status);
/* Return an error. */
return(LX_ERROR);
}
/* Is this the first time? */
if (nor_flash -> lx_nor_flash_diagnostic_sector_obsoleted)
{
/* No, this is a potential format error, since this should only happen once in a given
NOR flash format. */
_lx_nor_flash_system_error(nor_flash, LX_SYSTEM_INVALID_FORMAT);
/* Return an error. */
return(LX_ERROR);
}
/* Increment the obsoleted count. */
nor_flash -> lx_nor_flash_diagnostic_sector_obsoleted++;
}
}
}
/* Determine if the sector is free. */
else if (block_word == LX_NOR_PHYSICAL_SECTOR_FREE)
{
/* A free entry when there are still used sectors implies that the sector was allocated and a power interruption
took place prior to writing the new logical sector number into the list. */
/* Is this the first time? */
if (nor_flash -> lx_nor_flash_diagnostic_mapping_invalidated)
{
/* No, this is a potential format error, since this should only happen once in a given
NOR flash format. */
_lx_nor_flash_system_error(nor_flash, LX_SYSTEM_INVALID_FORMAT);
/* Return an error. */
return(LX_ERROR);
}
/* Write 0s out to this entry to invalidate the sector entry. */
block_word = 0;
status = _lx_nor_flash_driver_write(nor_flash, (block_word_ptr + nor_flash -> lx_nor_flash_block_physical_sector_mapping_offset + j), &block_word, 1);
/* Check for an error from flash driver. Drivers should never return an error.. */
if (status)
{
/* Call system error handler. */
_lx_nor_flash_system_error(nor_flash, status);
/* Return an error. */
return(LX_ERROR);
}
/* Increment the number of mapping invalidates. */
nor_flash -> lx_nor_flash_diagnostic_mapping_invalidated++;
}
/* Yes, now determine if the sector is obsolete. */
if ((block_word & LX_NOR_PHYSICAL_SECTOR_VALID) == 0)
{
/* Increment the number of obsolete sectors. */
nor_flash -> lx_nor_flash_obsolete_physical_sectors++;
}
/* Determine if the mapping for this sector isn't yet valid. */
else if (block_word & LX_NOR_PHYSICAL_SECTOR_MAPPING_NOT_VALID)
{
/* Yes, a power interruption or reset occurred while the sector mapping entry was being written. */
/* Increment the number of obsolete sectors. */
nor_flash -> lx_nor_flash_obsolete_physical_sectors++;
/* Increment the interrupted mapping counter. */
nor_flash -> lx_nor_flash_diagnostic_mapping_write_interrupted++;
/* Invalidate this entry - clearing valid bit, superceded bit and logical sector. */
block_word = 0;
status = _lx_nor_flash_driver_write(nor_flash, (block_word_ptr + nor_flash -> lx_nor_flash_block_physical_sector_mapping_offset + j), &block_word, 1);
/* Check for an error from flash driver. Drivers should never return an error.. */
if (status)
{
/* Call system error handler. */
_lx_nor_flash_system_error(nor_flash, status);
/* Return an error. */
return(LX_ERROR);
}
}
else
{
/* Increment the number of mapped physical sectors. */
nor_flash -> lx_nor_flash_mapped_physical_sectors++;
}
/* Decrease the number of used sectors. */
used_sectors--;
}
else
{
/* No more used sectors in this flash block. */
/* In this case the entry must be free or there is a serious NOR flash format error present. */
if (block_word != LX_NOR_PHYSICAL_SECTOR_FREE)
{
/* Increment the sector not free diagnostic. */
nor_flash -> lx_nor_flash_diagnostic_sector_not_free++;
/* NOR flash format. */
_lx_nor_flash_system_error(nor_flash, LX_SYSTEM_INVALID_FORMAT);
/* Write 0s out to this entry to invalidate the sector entry. */
block_word = 0;
status = _lx_nor_flash_driver_write(nor_flash, (block_word_ptr + nor_flash -> lx_nor_flash_block_physical_sector_mapping_offset + j), &block_word, 1);
/* Check for an error from flash driver. Drivers should never return an error.. */
if (status)
{
/* Call system error handler. */
_lx_nor_flash_system_error(nor_flash, status);
/* Return an error. */
return(LX_ERROR);
}
}
#ifdef LX_FREE_SECTOR_DATA_VERIFY
/* Pickup address of the free sector data area. */
sector_word_ptr = block_word_ptr + (nor_flash -> lx_nor_flash_block_physical_sector_offset) + (j * LX_NOR_SECTOR_SIZE);
/* Determine if the data for this sector is free. */
for (k = 0; k < LX_NOR_SECTOR_SIZE; k++)
{
#ifdef LX_DIRECT_READ
/* Read the word directly. */
sector_word = *(sector_word_ptr);
#else
status = _lx_nor_flash_driver_read(nor_flash, (sector_word_ptr), &sector_word, 1);
/* Check for an error from flash driver. Drivers should never return an error.. */
if (status)
{
/* Call system error handler. */
_lx_nor_flash_system_error(nor_flash, status);
/* Return an error. */
return(LX_ERROR);
}
#endif
/* Determine if this word is not available. */
if (sector_word != LX_NOR_PHYSICAL_SECTOR_FREE)
{
/* Increment the sector data not free diagnostic. */
nor_flash -> lx_nor_flash_diagnostic_sector_data_not_free++;
/* This is a format error. */
_lx_nor_flash_system_error(nor_flash, LX_SYSTEM_INVALID_BLOCK);
/* Return an error. */
return(LX_ERROR);
}
/* Move to the next word in the sector. */
sector_word_ptr++;
}
#endif
}
}
}
/* Move to the next flash block. */
block_word_ptr = block_word_ptr + (nor_flash -> lx_nor_flash_words_per_block);
}
/* Update the overall minimum and maximum erase count. */
nor_flash -> lx_nor_flash_minimum_erase_count = min_erased_count;
nor_flash -> lx_nor_flash_minimum_erased_blocks = min_erased_blocks;
nor_flash -> lx_nor_flash_maximum_erase_count = max_erased_count;
/* Determine if we need to update the free sector search pointer. */
if (nor_flash -> lx_nor_flash_free_block_search == nor_flash -> lx_nor_flash_total_blocks)
{
/* Just start at the beginning. */
nor_flash -> lx_nor_flash_free_block_search = 0;
}
}
#ifdef LX_THREAD_SAFE_ENABLE
/* 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. */
status = tx_mutex_create(&nor_flash -> lx_nor_flash_mutex, "NOR Flash Mutex", TX_NO_INHERIT);
/* Determine if the mutex creation encountered an error. */
if (status != LX_SUCCESS)
{
/* Call system error handler, since this should not happen. */
_lx_nor_flash_system_error(nor_flash, LX_SYSTEM_MUTEX_CREATE_FAILED);
/* Return error to caller. */
return(LX_ERROR);
}
#endif
/* Enable the sector mapping cache. */
nor_flash -> lx_nor_flash_sector_mapping_cache_enabled = LX_TRUE;
/* Initialize the last found block and sector markers. */
nor_flash -> lx_nor_flash_found_block_search = 0;
nor_flash -> lx_nor_flash_found_sector_search = 0;
/* Lockout interrupts. */
LX_DISABLE
/* At this point, the NOR flash has been opened successfully. Place the
NOR flash control block on the linked list of currently opened NOR flashes. */
/* Set the NOR flash state to open. */
nor_flash -> lx_nor_flash_state = LX_NOR_FLASH_OPENED;
/* Place the NOR flash control block on the list of opened NOR flashes. First,
check for an empty list. */
if (_lx_nor_flash_opened_count)
{
/* List is not empty - other NOR flashes are open. */
/* Pickup tail pointer. */
tail_ptr = _lx_nor_flash_opened_ptr -> lx_nor_flash_open_previous;
/* Place the new NOR flash control block in the list. */
_lx_nor_flash_opened_ptr -> lx_nor_flash_open_previous = nor_flash;
tail_ptr -> lx_nor_flash_open_next = nor_flash;
/* Setup this NOR flash's opened links. */
nor_flash -> lx_nor_flash_open_previous = tail_ptr;
nor_flash -> lx_nor_flash_open_next = _lx_nor_flash_opened_ptr;
}
else
{
/* The opened NOR flash list is empty. Add the NOR flash to empty list. */
_lx_nor_flash_opened_ptr = nor_flash;
nor_flash -> lx_nor_flash_open_next = nor_flash;
nor_flash -> lx_nor_flash_open_previous = nor_flash;
}
/* Increment the opened NOR flash counter. */
_lx_nor_flash_opened_count++;
/* Restore interrupts. */
LX_RESTORE
/* Return a successful completion. */
return(LX_SUCCESS);
} }
+886
View File
@@ -0,0 +1,886 @@
/***************************************************************************
* Copyright (c) 2025 Microsoft Corporation
* Portion Copyright (c) 2025 STMicroelectronics
*
* This program and the accompanying materials are made available under the
* terms of the MIT License which is available at
* https://opensource.org/licenses/MIT.
*
* SPDX-License-Identifier: MIT
**************************************************************************/
/**************************************************************************/
/**************************************************************************/
/** */
/** LevelX Component */
/** */
/** NOR Flash */
/** */
/**************************************************************************/
/**************************************************************************/
#define LX_SOURCE_CODE
/* Disable ThreadX error checking. */
#ifndef LX_DISABLE_ERROR_CHECKING
#define LX_DISABLE_ERROR_CHECKING
#endif
/* Include necessary system files. */
#include "lx_api.h"
/**************************************************************************/
/* */
/* FUNCTION RELEASE */
/* */
/* _lx_nor_flash_open_extended PORTABLE C */
/* 6.3.0 */
/* AUTHOR */
/* */
/* William E. Lamie, Microsoft Corporation */
/* */
/* DESCRIPTION */
/* */
/* This function opens a NOR flash instance and ensures the NOR flash */
/* is in a coherent state. */
/* */
/* INPUT */
/* */
/* nor_flash NOR flash instance */
/* name Name of NOR flash instance */
/* nor_driver_initialize Driver initialize */
/* nor_driver_info_ptr Driver user data pointer */
/* */
/* OUTPUT */
/* */
/* return status */
/* */
/* CALLS */
/* */
/* (nor_driver_initialize) Driver initialize */
/* _lx_nor_flash_driver_read Driver read */
/* _lx_nor_flash_driver_write Driver write */
/* (lx_nor_flash_driver_block_erased_verify) */
/* NOR flash verify block erased */
/* _lx_nor_flash_driver_block_erase Driver block erase */
/* _lx_nor_flash_logical_sector_find Find logical sector */
/* _lx_nor_flash_system_error System error handler */
/* tx_mutex_create Create thread-safe mutex */
/* */
/* CALLED BY */
/* */
/* Application Code */
/* */
/**************************************************************************/
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)
{
ULONG sectors_per_block;
ULONG sector_map_words;
ULONG bit_map_words;
ULONG bit_map_mask;
ULONG total_header_words;
ULONG header_sectors;
ULONG *block_word_ptr;
ULONG block_word;
ULONG temp;
ULONG free_sectors;
ULONG used_sectors;
ULONG *new_map_entry;
ULONG *new_sector_address;
ULONG erased_count, min_erased_count, max_erased_count, temp_erased_count, min_erased_blocks;
ULONG j, k, l;
UINT status;
#ifdef LX_FREE_SECTOR_DATA_VERIFY
ULONG *sector_word_ptr;
ULONG sector_word;
#endif
LX_NOR_FLASH *tail_ptr;
LX_INTERRUPT_SAVE_AREA
LX_PARAMETER_NOT_USED(name);
/* Clear the NOR flash control block. User extension is not cleared. */
LX_MEMSET(nor_flash, 0, (ULONG)((UCHAR*)&(nor_flash -> lx_nor_flash_open_previous) - (UCHAR*)nor_flash) + sizeof(nor_flash -> lx_nor_flash_open_previous));
/* Pass the driver info ptr */
nor_flash -> lx_nor_flash_driver_info_ptr = nor_driver_info_ptr;
/* Call the flash driver's initialization function. */
(nor_driver_initialize)(nor_flash);
#ifndef LX_DIRECT_READ
/* Determine if the driver supplied a RAM buffer for reading the NOR sector if direct read is not
supported. */
if (nor_flash -> lx_nor_flash_sector_buffer == LX_NULL)
{
/* Return an error. */
return(LX_NO_MEMORY);
}
#endif
/* Setup the offset to the free bit map. */
nor_flash -> lx_nor_flash_block_free_bit_map_offset = sizeof(LX_NOR_FLASH_BLOCK_HEADER)/sizeof(ULONG);
/* Calculate the number of bits we need in the free physical sector bit map. Subtract 1 to account for the
flash block header itself. The case where multiple physical sectors are needed for certain sized flash
devices is handled below. */
sectors_per_block = (nor_flash -> lx_nor_flash_words_per_block / LX_NOR_SECTOR_SIZE) - 1;
/* Calculate the number of words required for the sector map array. */
sector_map_words = sectors_per_block;
/* Calculate the number of words we need for the free physical sector bit map. */
bit_map_words = (sectors_per_block + 31)/ 32;
/* Save the number of bit map words. */
nor_flash -> lx_nor_flash_block_bit_map_words = bit_map_words;
/* Setup the offset (in words) to the array of physical sector mapping. */
nor_flash -> lx_nor_flash_block_physical_sector_mapping_offset = nor_flash -> lx_nor_flash_block_free_bit_map_offset + bit_map_words;
/* Calculate the total number of words required for the flash block header. */
total_header_words = sizeof(LX_NOR_FLASH_BLOCK_HEADER)/sizeof(ULONG) + bit_map_words + sector_map_words;
/* Determine if more physical sectors are needed, which can happen on large devices. */
if (total_header_words <= LX_NOR_SECTOR_SIZE)
{
/* Round up to the size of 1 physical sector. */
total_header_words = LX_NOR_SECTOR_SIZE;
}
else
{
/* Otherwise calculate how many header sectors are necessary. */
header_sectors = (total_header_words-1)/LX_NOR_SECTOR_SIZE;
/* Round up to the next sector. */
header_sectors++;
/* Compute the total header words, rounding to the next sector. */
total_header_words = header_sectors * LX_NOR_SECTOR_SIZE;
/* Adjust the number of sectors per block. */
sectors_per_block = sectors_per_block - (header_sectors - 1);
}
/* Save the offset to the sector area. */
nor_flash -> lx_nor_flash_block_physical_sector_offset = total_header_words;
/* Save the physical sectors per block and total physical sectors. */
nor_flash -> lx_nor_flash_physical_sectors_per_block = sectors_per_block;
nor_flash -> lx_nor_flash_total_physical_sectors = nor_flash -> lx_nor_flash_total_blocks * sectors_per_block;
/* Build the free bit map mask, for the portion of the bit map that is less than 32 bits. */
if ((sectors_per_block % 32) != 0)
{
bit_map_mask = (ULONG)(1 << (sectors_per_block % 32));
bit_map_mask = bit_map_mask - 1;
}
else
{
/* Exactly 32 sectors for the bit map mask. */
bit_map_mask = LX_ALL_ONES;
}
/* Save the free bit map mask in the control block. */
nor_flash -> lx_nor_flash_block_bit_map_mask = bit_map_mask;
/* Setup default values for the max/min erased counts. */
min_erased_count = LX_ALL_ONES;
min_erased_blocks = 0;
max_erased_count = 0;
/* Setup the block word pointer to the first word of the first block, which is effectively the
flash base address. */
block_word_ptr = nor_flash -> lx_nor_flash_base_address;
/* Loop through the blocks to determine the minimum and maximum erase count. */
for (l = 0; l < nor_flash -> lx_nor_flash_total_blocks; l++)
{
/* Pickup the first word of the block. If the flash manager has executed before, this word contains the
erase count for the block. Otherwise, if the word is 0xFFFFFFFF, this flash block was either erased
or this is the first time it was used. */
#ifdef LX_DIRECT_READ
/* Read the word directly. */
block_word = *block_word_ptr;
#else
status = _lx_nor_flash_driver_read(nor_flash, block_word_ptr, &block_word, 1);
/* Check for an error from flash driver. Drivers should never return an error.. */
if (status)
{
/* Call system error handler. */
_lx_nor_flash_system_error(nor_flash, status);
/* Return an error. */
return(LX_ERROR);
}
#endif
/* Is the block erased? */
if (((block_word & LX_BLOCK_ERASED) != LX_BLOCK_ERASED) && (block_word != LX_BLOCK_ERASE_STARTED))
{
/* No, valid block. Isolate the erased count. */
erased_count = (block_word & LX_BLOCK_ERASE_COUNT_MASK);
/* Is the erased count the minimum? */
if (erased_count == min_erased_count)
{
/* Yes, increment the minimum erased block count. */
min_erased_blocks++;
}
/* Is this the new minimum? */
if (erased_count < min_erased_count)
{
/* Yes, remember the new minimum. */
min_erased_count = erased_count;
/* Reset the minimum erased block count. */
min_erased_blocks = 1;
}
/* Is this the new maximum? */
if (erased_count > max_erased_count)
{
/* Yes, remember the new maximum. */
max_erased_count = erased_count;
}
}
/* Move to the next flash block. */
block_word_ptr = block_word_ptr + (nor_flash -> lx_nor_flash_words_per_block);
}
/* If we haven't found any erased counts, we can assume the flash is completely erased and needs to
be setup for the first time. */
if (min_erased_count == LX_ALL_ONES)
{
/* Indicate that this is the initial format. */
nor_flash -> lx_nor_flash_diagnostic_initial_format = LX_TRUE;
/* Setup the block word pointer to the first word of the first block, which is effectively the
flash base address. */
block_word_ptr = nor_flash -> lx_nor_flash_base_address;
/* Loop through the blocks to setup the flash the fist time. */
for (l = 0; l < nor_flash -> lx_nor_flash_total_blocks; l++)
{
/* 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
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 + (bit_map_words-1)) , &bit_map_mask, 1);
/* Check for an error from flash driver. Drivers should never return an error.. */
if (status)
{
/* Call system error handler. */
_lx_nor_flash_system_error(nor_flash, status);
/* Return an error. */
return(LX_ERROR);
}
/* Setup the initial erase count to 1. */
block_word = ((ULONG) 1);
/* Write the initial erase count for the block. */
status = _lx_nor_flash_driver_write(nor_flash, block_word_ptr, &block_word, 1);
/* Check for an error from flash driver. Drivers should never return an error.. */
if (status)
{
/* Call system error handler. */
_lx_nor_flash_system_error(nor_flash, status);
/* Return an error. */
return(LX_ERROR);
}
/* Update the overall minimum and maximum erase count. */
nor_flash -> lx_nor_flash_minimum_erase_count = 1;
nor_flash -> lx_nor_flash_minimum_erased_blocks = nor_flash -> lx_nor_flash_total_blocks;
nor_flash -> lx_nor_flash_maximum_erase_count = 1;
/* Update the number of free physical sectors. */
nor_flash -> lx_nor_flash_free_physical_sectors = nor_flash -> lx_nor_flash_free_physical_sectors + sectors_per_block;
/* Move to the next flash block. */
block_word_ptr = block_word_ptr + (nor_flash -> lx_nor_flash_words_per_block);
}
}
else
{
/* At this point, we have a previously managed flash structure. This needs to be traversed to prepare for the
current flash operation. */
/* Default the flash free sector search to an invalid value. */
nor_flash -> lx_nor_flash_free_block_search = nor_flash -> lx_nor_flash_total_blocks;
/* Setup the block word pointer to the first word of the first block, which is effectively the
flash base address. */
block_word_ptr = nor_flash -> lx_nor_flash_base_address;
/* Loop through the blocks. */
for (l = 0; l < nor_flash -> lx_nor_flash_total_blocks; l++)
{
/* First, determine if this block has a valid erase count. */
#ifdef LX_DIRECT_READ
/* Read the word directly. */
block_word = *block_word_ptr;
#else
status = _lx_nor_flash_driver_read(nor_flash, block_word_ptr, &block_word, 1);
/* Check for an error from flash driver. Drivers should never return an error.. */
if (status)
{
/* Call system error handler. */
_lx_nor_flash_system_error(nor_flash, status);
/* Return an error. */
return(LX_ERROR);
}
#endif
/* Is the block erased? */
if (((block_word & LX_BLOCK_ERASED) == LX_BLOCK_ERASED) || (block_word == LX_BLOCK_ERASE_STARTED))
{
/* This can happen if we were previously in the process of erasing the flash block and a
power interruption occurs. It should only occur once though. */
/* Is this the first time? */
if (nor_flash -> lx_nor_flash_diagnostic_erased_block)
{
/* No, this is a potential format error, since this should only happen once in a given
NOR flash format. */
_lx_nor_flash_system_error(nor_flash, LX_SYSTEM_INVALID_BLOCK);
/* Return an error. */
return(LX_ERROR);
}
/* Increment the erased block diagnostic. */
nor_flash -> lx_nor_flash_diagnostic_erased_block++;
/* Check to see if the block is erased. */
#ifdef LX_NOR_ENABLE_CONTROL_BLOCK_FOR_DRIVER_INTERFACE
status = (nor_flash -> lx_nor_flash_driver_block_erased_verify)(nor_flash, l);
#else
status = (nor_flash -> lx_nor_flash_driver_block_erased_verify)(l);
#endif
/* Is the block completely erased? */
if (status != LX_SUCCESS)
{
/* Is this the first time? */
if (nor_flash -> lx_nor_flash_diagnostic_re_erase_block)
{
/* No, this is a potential format error, since this should only happen once in a given
NOR flash format. */
_lx_nor_flash_system_error(nor_flash, LX_SYSTEM_INVALID_BLOCK);
/* Return an error. */
return(LX_ERROR);
}
/* Increment the erased block diagnostic. */
nor_flash -> lx_nor_flash_diagnostic_re_erase_block++;
/* No, the block is not fully erased, erase it again. */
status = _lx_nor_flash_driver_block_erase(nor_flash, l, max_erased_count);
/* Check for an error from flash driver. Drivers should never return an error.. */
if (status)
{
/* Call system error handler. */
_lx_nor_flash_system_error(nor_flash, status);
/* Return an error. */
return(LX_ERROR);
}
}
/* 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
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 + (bit_map_words-1)) , &bit_map_mask, 1);
/* Check for an error from flash driver. Drivers should never return an error.. */
if (status)
{
/* Call system error handler. */
_lx_nor_flash_system_error(nor_flash, status);
/* Return an error. */
return(LX_ERROR);
}
/* Write the initial erase count for the block with upper bit set. */
temp_erased_count = (max_erased_count | LX_BLOCK_ERASED);
status = _lx_nor_flash_driver_write(nor_flash, block_word_ptr, &temp_erased_count, 1);
/* Check for an error from flash driver. Drivers should never return an error.. */
if (status)
{
/* Call system error handler. */
_lx_nor_flash_system_error(nor_flash, status);
/* Return an error. */
return(LX_ERROR);
}
/* Write the final initial erase count for the block. */
status = _lx_nor_flash_driver_write(nor_flash, block_word_ptr, &max_erased_count, 1);
/* Check for an error from flash driver. Drivers should never return an error.. */
if (status)
{
/* Call system error handler. */
_lx_nor_flash_system_error(nor_flash, status);
/* Return an error. */
return(LX_ERROR);
}
/* Update the number of free physical sectors. */
nor_flash -> lx_nor_flash_free_physical_sectors = nor_flash -> lx_nor_flash_free_physical_sectors + sectors_per_block;
}
else
{
/* Calculate the number of free sectors from the free sector bit map. */
free_sectors = 0;
for (j = 0; j < bit_map_words; j++)
{
/* Read this word of the free sector bit map. */
#ifdef LX_DIRECT_READ
/* Read the word directly. */
block_word = *(block_word_ptr + nor_flash -> lx_nor_flash_block_free_bit_map_offset + j);
#else
status = _lx_nor_flash_driver_read(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.. */
if (status)
{
/* Call system error handler. */
_lx_nor_flash_system_error(nor_flash, status);
/* Return an error. */
return(LX_ERROR);
}
#endif
/* Count the number of set bits (free sectors). */
for (k = 0; k < 32; k++)
{
/* Is this sector free? */
if (block_word & 1)
{
/* Yes, this sector is free, increment the free sectors count. */
free_sectors++;
/* Determine if we need to update the search pointer. */
if (nor_flash -> lx_nor_flash_free_block_search == nor_flash -> lx_nor_flash_total_blocks)
{
/* Remember the block with free sectors. */
nor_flash -> lx_nor_flash_free_block_search = l;
}
}
/* Shift down the free sector. */
block_word = block_word >> 1;
}
}
/* Update the number of free physical sectors. */
nor_flash -> lx_nor_flash_free_physical_sectors = nor_flash -> lx_nor_flash_free_physical_sectors + free_sectors;
/* We need to now examine the mapping list. */
/* Calculate how many non-free sectors there are - this includes valid and obsolete sectors. */
used_sectors = sectors_per_block - free_sectors;
/* Now walk the list of logical-physical sector mapping. */
for (j = 0; j < sectors_per_block; j++)
{
/* Read this word of the sector mapping list. */
#ifdef LX_DIRECT_READ
/* Read the word directly. */
block_word = *(block_word_ptr + nor_flash -> lx_nor_flash_block_physical_sector_mapping_offset + j);
#else
status = _lx_nor_flash_driver_read(nor_flash, (block_word_ptr + nor_flash -> lx_nor_flash_block_physical_sector_mapping_offset + j), &block_word, 1);
/* Check for an error from flash driver. Drivers should never return an error.. */
if (status)
{
/* Call system error handler. */
_lx_nor_flash_system_error(nor_flash, status);
/* Return an error. */
return(LX_ERROR);
}
#endif
/* Determine if we are expecting to find a used sector. */
if (used_sectors)
{
/* Yes, we expect this entry to be used. */
/* Is this sector in-use? */
if ((block_word & LX_NOR_LOGICAL_SECTOR_MASK) != LX_NOR_LOGICAL_SECTOR_MASK)
{
/* Determine if the valid bit is set and the superceded bit is clear. This indicates the block was
about to become obsolete. */
if ((block_word & LX_NOR_PHYSICAL_SECTOR_VALID) && ((block_word & LX_NOR_PHYSICAL_SECTOR_SUPERCEDED) == 0))
{
/* Increment the being obsoleted count. */
nor_flash -> lx_nor_flash_diagnostic_sector_being_obsoleted++;
/* Save the currently mapped physical sectors. */
temp = nor_flash -> lx_nor_flash_mapped_physical_sectors;
/* Indicate all the physical sectors are mapped for the purpose of this search. */
nor_flash -> lx_nor_flash_mapped_physical_sectors = nor_flash -> lx_nor_flash_total_physical_sectors;
/* Yes, this block was about to become obsolete. Perform a search for a logical sector entry that
has both of these bits set. */
_lx_nor_flash_logical_sector_find(nor_flash, (block_word & LX_NOR_LOGICAL_SECTOR_MASK), LX_TRUE, &new_map_entry, &new_sector_address);
/* Restore the number of mapped physical sectors. */
nor_flash -> lx_nor_flash_mapped_physical_sectors = temp;
/* Determine if the new logical sector entry is present. */
if (new_map_entry)
{
/* Yes, make the current entry obsolete in favor of the new entry. */
block_word = block_word & ~((ULONG) LX_NOR_PHYSICAL_SECTOR_VALID);
status = _lx_nor_flash_driver_write(nor_flash, (block_word_ptr + nor_flash -> lx_nor_flash_block_physical_sector_mapping_offset + j), &block_word, 1);
/* Check for an error from flash driver. Drivers should never return an error.. */
if (status)
{
/* Call system error handler. */
_lx_nor_flash_system_error(nor_flash, status);
/* Return an error. */
return(LX_ERROR);
}
/* Is this the first time? */
if (nor_flash -> lx_nor_flash_diagnostic_sector_obsoleted)
{
/* No, this is a potential format error, since this should only happen once in a given
NOR flash format. */
_lx_nor_flash_system_error(nor_flash, LX_SYSTEM_INVALID_FORMAT);
/* Return an error. */
return(LX_ERROR);
}
/* Increment the obsoleted count. */
nor_flash -> lx_nor_flash_diagnostic_sector_obsoleted++;
}
}
}
/* Determine if the sector is free. */
else if (block_word == LX_NOR_PHYSICAL_SECTOR_FREE)
{
/* A free entry when there are still used sectors implies that the sector was allocated and a power interruption
took place prior to writing the new logical sector number into the list. */
/* Is this the first time? */
if (nor_flash -> lx_nor_flash_diagnostic_mapping_invalidated)
{
/* No, this is a potential format error, since this should only happen once in a given
NOR flash format. */
_lx_nor_flash_system_error(nor_flash, LX_SYSTEM_INVALID_FORMAT);
/* Return an error. */
return(LX_ERROR);
}
/* Write 0s out to this entry to invalidate the sector entry. */
block_word = 0;
status = _lx_nor_flash_driver_write(nor_flash, (block_word_ptr + nor_flash -> lx_nor_flash_block_physical_sector_mapping_offset + j), &block_word, 1);
/* Check for an error from flash driver. Drivers should never return an error.. */
if (status)
{
/* Call system error handler. */
_lx_nor_flash_system_error(nor_flash, status);
/* Return an error. */
return(LX_ERROR);
}
/* Increment the number of mapping invalidates. */
nor_flash -> lx_nor_flash_diagnostic_mapping_invalidated++;
}
/* Yes, now determine if the sector is obsolete. */
if ((block_word & LX_NOR_PHYSICAL_SECTOR_VALID) == 0)
{
/* Increment the number of obsolete sectors. */
nor_flash -> lx_nor_flash_obsolete_physical_sectors++;
}
/* Determine if the mapping for this sector isn't yet valid. */
else if (block_word & LX_NOR_PHYSICAL_SECTOR_MAPPING_NOT_VALID)
{
/* Yes, a power interruption or reset occurred while the sector mapping entry was being written. */
/* Increment the number of obsolete sectors. */
nor_flash -> lx_nor_flash_obsolete_physical_sectors++;
/* Increment the interrupted mapping counter. */
nor_flash -> lx_nor_flash_diagnostic_mapping_write_interrupted++;
/* Invalidate this entry - clearing valid bit, superceded bit and logical sector. */
block_word = 0;
status = _lx_nor_flash_driver_write(nor_flash, (block_word_ptr + nor_flash -> lx_nor_flash_block_physical_sector_mapping_offset + j), &block_word, 1);
/* Check for an error from flash driver. Drivers should never return an error.. */
if (status)
{
/* Call system error handler. */
_lx_nor_flash_system_error(nor_flash, status);
/* Return an error. */
return(LX_ERROR);
}
}
else
{
/* Increment the number of mapped physical sectors. */
nor_flash -> lx_nor_flash_mapped_physical_sectors++;
}
/* Decrease the number of used sectors. */
used_sectors--;
}
else
{
/* No more used sectors in this flash block. */
/* In this case the entry must be free or there is a serious NOR flash format error present. */
if (block_word != LX_NOR_PHYSICAL_SECTOR_FREE)
{
/* Increment the sector not free diagnostic. */
nor_flash -> lx_nor_flash_diagnostic_sector_not_free++;
/* NOR flash format. */
_lx_nor_flash_system_error(nor_flash, LX_SYSTEM_INVALID_FORMAT);
/* Write 0s out to this entry to invalidate the sector entry. */
block_word = 0;
status = _lx_nor_flash_driver_write(nor_flash, (block_word_ptr + nor_flash -> lx_nor_flash_block_physical_sector_mapping_offset + j), &block_word, 1);
/* Check for an error from flash driver. Drivers should never return an error.. */
if (status)
{
/* Call system error handler. */
_lx_nor_flash_system_error(nor_flash, status);
/* Return an error. */
return(LX_ERROR);
}
}
#ifdef LX_FREE_SECTOR_DATA_VERIFY
/* Pickup address of the free sector data area. */
sector_word_ptr = block_word_ptr + (nor_flash -> lx_nor_flash_block_physical_sector_offset) + (j * LX_NOR_SECTOR_SIZE);
/* Determine if the data for this sector is free. */
for (k = 0; k < LX_NOR_SECTOR_SIZE; k++)
{
#ifdef LX_DIRECT_READ
/* Read the word directly. */
sector_word = *(sector_word_ptr);
#else
status = _lx_nor_flash_driver_read(nor_flash, (sector_word_ptr), &sector_word, 1);
/* Check for an error from flash driver. Drivers should never return an error.. */
if (status)
{
/* Call system error handler. */
_lx_nor_flash_system_error(nor_flash, status);
/* Return an error. */
return(LX_ERROR);
}
#endif
/* Determine if this word is not available. */
if (sector_word != LX_NOR_PHYSICAL_SECTOR_FREE)
{
/* Increment the sector data not free diagnostic. */
nor_flash -> lx_nor_flash_diagnostic_sector_data_not_free++;
/* This is a format error. */
_lx_nor_flash_system_error(nor_flash, LX_SYSTEM_INVALID_BLOCK);
/* Return an error. */
return(LX_ERROR);
}
/* Move to the next word in the sector. */
sector_word_ptr++;
}
#endif
}
}
}
/* Move to the next flash block. */
block_word_ptr = block_word_ptr + (nor_flash -> lx_nor_flash_words_per_block);
}
/* Update the overall minimum and maximum erase count. */
nor_flash -> lx_nor_flash_minimum_erase_count = min_erased_count;
nor_flash -> lx_nor_flash_minimum_erased_blocks = min_erased_blocks;
nor_flash -> lx_nor_flash_maximum_erase_count = max_erased_count;
/* Determine if we need to update the free sector search pointer. */
if (nor_flash -> lx_nor_flash_free_block_search == nor_flash -> lx_nor_flash_total_blocks)
{
/* Just start at the beginning. */
nor_flash -> lx_nor_flash_free_block_search = 0;
}
}
#ifdef LX_THREAD_SAFE_ENABLE
/* 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. */
status = tx_mutex_create(&nor_flash -> lx_nor_flash_mutex, "NOR Flash Mutex", TX_NO_INHERIT);
/* Determine if the mutex creation encountered an error. */
if (status != LX_SUCCESS)
{
/* Call system error handler, since this should not happen. */
_lx_nor_flash_system_error(nor_flash, LX_SYSTEM_MUTEX_CREATE_FAILED);
/* Return error to caller. */
return(LX_ERROR);
}
#endif
/* Enable the sector mapping cache. */
nor_flash -> lx_nor_flash_sector_mapping_cache_enabled = LX_TRUE;
/* Initialize the last found block and sector markers. */
nor_flash -> lx_nor_flash_found_block_search = 0;
nor_flash -> lx_nor_flash_found_sector_search = 0;
/* Lockout interrupts. */
LX_DISABLE
/* At this point, the NOR flash has been opened successfully. Place the
NOR flash control block on the linked list of currently opened NOR flashes. */
/* Set the NOR flash state to open. */
nor_flash -> lx_nor_flash_state = LX_NOR_FLASH_OPENED;
/* Place the NOR flash control block on the list of opened NOR flashes. First,
check for an empty list. */
if (_lx_nor_flash_opened_count)
{
/* List is not empty - other NOR flashes are open. */
/* Pickup tail pointer. */
tail_ptr = _lx_nor_flash_opened_ptr -> lx_nor_flash_open_previous;
/* Place the new NOR flash control block in the list. */
_lx_nor_flash_opened_ptr -> lx_nor_flash_open_previous = nor_flash;
tail_ptr -> lx_nor_flash_open_next = nor_flash;
/* Setup this NOR flash's opened links. */
nor_flash -> lx_nor_flash_open_previous = tail_ptr;
nor_flash -> lx_nor_flash_open_next = _lx_nor_flash_opened_ptr;
}
else
{
/* The opened NOR flash list is empty. Add the NOR flash to empty list. */
_lx_nor_flash_opened_ptr = nor_flash;
nor_flash -> lx_nor_flash_open_next = nor_flash;
nor_flash -> lx_nor_flash_open_previous = nor_flash;
}
/* Increment the opened NOR flash counter. */
_lx_nor_flash_opened_count++;
/* Restore interrupts. */
LX_RESTORE
/* Return a successful completion. */
return(LX_SUCCESS);
}
+47 -57
View File
@@ -1,19 +1,19 @@
/**************************************************************************/ /***************************************************************************
/* */ * Copyright (c) 2024 Microsoft Corporation
/* Copyright (c) Microsoft Corporation. All rights reserved. */ * Copyright (c) 2026-present Eclipse ThreadX contributors
/* */ *
/* This software is licensed under the Microsoft Software License */ * This program and the accompanying materials are made available under the
/* Terms for Microsoft Azure RTOS. Full text of the license can be */ * terms of the MIT License which is available at
/* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */ * https://opensource.org/licenses/MIT.
/* and in the root directory of this software. */ *
/* */ * SPDX-License-Identifier: MIT
/**************************************************************************/ **************************************************************************/
/**************************************************************************/ /**************************************************************************/
/**************************************************************************/ /**************************************************************************/
/** */ /** */
/** LevelX Component */ /** LevelX Component */
/** */ /** */
/** NOR Flash */ /** NOR Flash */
/** */ /** */
@@ -35,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;
@@ -97,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;
} }
@@ -105,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);
} }
@@ -120,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,19 +1,19 @@
/**************************************************************************/ /***************************************************************************
/* */ * Copyright (c) 2024 Microsoft Corporation
/* Copyright (c) Microsoft Corporation. All rights reserved. */ * Copyright (c) 2026-present Eclipse ThreadX contributors
/* */ *
/* This software is licensed under the Microsoft Software License */ * This program and the accompanying materials are made available under the
/* Terms for Microsoft Azure RTOS. Full text of the license can be */ * terms of the MIT License which is available at
/* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */ * https://opensource.org/licenses/MIT.
/* and in the root directory of this software. */ *
/* */ * SPDX-License-Identifier: MIT
/**************************************************************************/ **************************************************************************/
/**************************************************************************/ /**************************************************************************/
/**************************************************************************/ /**************************************************************************/
/** */ /** */
/** LevelX Component */ /** LevelX Component */
/** */ /** */
/** NOR Flash */ /** NOR Flash */
/** */ /** */
@@ -35,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)
@@ -102,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)
{ {
@@ -127,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
@@ -139,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
@@ -173,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);
@@ -181,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);
@@ -202,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;
@@ -219,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);
@@ -236,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)
{ {
@@ -247,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);
@@ -298,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,19 +1,19 @@
/**************************************************************************/ /***************************************************************************
/* */ * Copyright (c) 2024 Microsoft Corporation
/* Copyright (c) Microsoft Corporation. All rights reserved. */ * Copyright (c) 2026-present Eclipse ThreadX contributors
/* */ *
/* This software is licensed under the Microsoft Software License */ * This program and the accompanying materials are made available under the
/* Terms for Microsoft Azure RTOS. Full text of the license can be */ * terms of the MIT License which is available at
/* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */ * https://opensource.org/licenses/MIT.
/* and in the root directory of this software. */ *
/* */ * SPDX-License-Identifier: MIT
/**************************************************************************/ **************************************************************************/
/**************************************************************************/ /**************************************************************************/
/**************************************************************************/ /**************************************************************************/
/** */ /** */
/** LevelX Component */ /** LevelX Component */
/** */ /** */
/** NOR Flash */ /** NOR Flash */
/** */ /** */
@@ -35,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)
@@ -88,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))
{ {
@@ -104,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;
} }
@@ -114,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;
} }
@@ -123,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;
} }
+58 -71
View File
@@ -1,19 +1,19 @@
/**************************************************************************/ /***************************************************************************
/* */ * Copyright (c) 2024 Microsoft Corporation
/* Copyright (c) Microsoft Corporation. All rights reserved. */ * Copyright (c) 2026-present Eclipse ThreadX contributors
/* */ *
/* This software is licensed under the Microsoft Software License */ * This program and the accompanying materials are made available under the
/* Terms for Microsoft Azure RTOS. Full text of the license can be */ * terms of the MIT License which is available at
/* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */ * https://opensource.org/licenses/MIT.
/* and in the root directory of this software. */ *
/* */ * SPDX-License-Identifier: MIT
/**************************************************************************/ **************************************************************************/
/**************************************************************************/ /**************************************************************************/
/**************************************************************************/ /**************************************************************************/
/** */ /** */
/** LevelX Component */ /** LevelX Component */
/** */ /** */
/** NOR Flash */ /** NOR Flash */
/** */ /** */
@@ -35,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)
@@ -109,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;
} }
@@ -138,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);
@@ -148,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. */
@@ -203,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. */
+59 -73
View File
@@ -1,19 +1,19 @@
/**************************************************************************/ /***************************************************************************
/* */ * Copyright (c) 2024 Microsoft Corporation
/* Copyright (c) Microsoft Corporation. All rights reserved. */ * Copyright (c) 2026-present Eclipse ThreadX contributors
/* */ *
/* This software is licensed under the Microsoft Software License */ * This program and the accompanying materials are made available under the
/* Terms for Microsoft Azure RTOS. Full text of the license can be */ * terms of the MIT License which is available at
/* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */ * https://opensource.org/licenses/MIT.
/* and in the root directory of this software. */ *
/* */ * SPDX-License-Identifier: MIT
/**************************************************************************/ **************************************************************************/
/**************************************************************************/ /**************************************************************************/
/**************************************************************************/ /**************************************************************************/
/** */ /** */
/** LevelX Component */ /** LevelX Component */
/** */ /** */
/** NOR Flash */ /** NOR Flash */
/** */ /** */
@@ -35,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)
@@ -114,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
@@ -132,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);
@@ -150,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);
@@ -191,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)
{ {
@@ -203,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);
@@ -211,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);
@@ -220,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;
} }
@@ -236,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. */
+77 -91
View File
@@ -1,19 +1,19 @@
/**************************************************************************/ /***************************************************************************
/* */ * Copyright (c) 2024 Microsoft Corporation
/* Copyright (c) Microsoft Corporation. All rights reserved. */ * Copyright (c) 2026-present Eclipse ThreadX contributors
/* */ *
/* This software is licensed under the Microsoft Software License */ * This program and the accompanying materials are made available under the
/* Terms for Microsoft Azure RTOS. Full text of the license can be */ * terms of the MIT License which is available at
/* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */ * https://opensource.org/licenses/MIT.
/* and in the root directory of this software. */ *
/* */ * SPDX-License-Identifier: MIT
/**************************************************************************/ **************************************************************************/
/**************************************************************************/ /**************************************************************************/
/**************************************************************************/ /**************************************************************************/
/** */ /** */
/** LevelX Component */ /** LevelX Component */
/** */ /** */
/** NOR Flash */ /** NOR Flash */
/** */ /** */
@@ -35,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)
@@ -119,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);
@@ -128,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;
} }
@@ -140,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. */
@@ -159,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);
@@ -178,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
@@ -190,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);
@@ -204,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);
@@ -228,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);
@@ -252,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);
@@ -290,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);
@@ -337,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);
} }
@@ -345,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;
@@ -358,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;
@@ -366,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;
} }
+20 -20
View File
@@ -1,19 +1,19 @@
/**************************************************************************/ /***************************************************************************
/* */ * Copyright (c) 2024 Microsoft Corporation
/* Copyright (c) Microsoft Corporation. All rights reserved. */ * Copyright (c) 2026-present Eclipse ThreadX contributors
/* */ *
/* This software is licensed under the Microsoft Software License */ * This program and the accompanying materials are made available under the
/* Terms for Microsoft Azure RTOS. Full text of the license can be */ * terms of the MIT License which is available at
/* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */ * https://opensource.org/licenses/MIT.
/* and in the root directory of this software. */ *
/* */ * SPDX-License-Identifier: MIT
/**************************************************************************/ **************************************************************************/
/**************************************************************************/ /**************************************************************************/
/**************************************************************************/ /**************************************************************************/
/** */ /** */
/** LevelX Component */ /** LevelX Component */
/** */ /** */
/** NOR Flash Simulator */ /** NOR Flash Simulator */
/** */ /** */
@@ -135,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++;
} }
@@ -165,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;
} }
@@ -188,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;
} }
@@ -212,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);
} }
+39 -52
View File
@@ -1,19 +1,19 @@
/**************************************************************************/ /***************************************************************************
/* */ * Copyright (c) 2024 Microsoft Corporation
/* Copyright (c) Microsoft Corporation. All rights reserved. */ * Copyright (c) 2026-present Eclipse ThreadX contributors
/* */ *
/* This software is licensed under the Microsoft Software License */ * This program and the accompanying materials are made available under the
/* Terms for Microsoft Azure RTOS. Full text of the license can be */ * terms of the MIT License which is available at
/* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */ * https://opensource.org/licenses/MIT.
/* and in the root directory of this software. */ *
/* */ * SPDX-License-Identifier: MIT
/**************************************************************************/ **************************************************************************/
/**************************************************************************/ /**************************************************************************/
/**************************************************************************/ /**************************************************************************/
/** */ /** */
/** LevelX Component */ /** LevelX Component */
/** */ /** */
/** NOR Flash */ /** NOR Flash */
/** */ /** */
@@ -35,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)
@@ -85,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);
+197
View File
@@ -0,0 +1,197 @@
LevelX
For version 6 and higher, please refer to the release notes on GitHub at https://github.com/eclipse-threadx/levelx/releases.
Below is the revision history for 5.x.
08/15/2019 LevelX generic code version 5.6. This release includes the
following major features:
Files are modified to fix compiler warnings:
demo_filex_nand_flash.c
demo_filex_nor_flash.c
lx_nand_flash_256byte_ecc_check.c
lx_nand_flash_256byte_ecc_compute.c
10/10/2018 LevelX generic code version 5.5. This release includes the following
modifications:
lx_api.h Removed compiler warnings, added extended NOR cache
support, new APIs, and new constants.
lx_nand_flash_256byte_ecc_check.c Removed compiler warnings.
lx_nand_flash_256byte_ecc_compute.c Removed compiler warnings.
lx_nand_flash_block_obsoleted_check.c Added logic to mark the beginning of block erase.
lx_nand_flash_block_reclaim.c Removed compiler warnings, and added logic to mark
the beginning of block erase.
lx_nand_flash_logical_sector_find.c Removed compiler warnings, and added logic to use
and maintain the last found page.
lx_nand_flash_next_block_to_erase_find.c Removed compiler warnings.
lx_nand_flash_open.c Added logic to detect start of a block erase that
was interrupted, removed system error call for more
than one page being obsoleted since this can happen
normally, removed compiler warnings, and added logic
to initialize the last found page.
lx_nand_flash_partial_defragment.c Added file in this release.
lx_nand_flash_sector_release.c Removed compiler warnings.
lx_nand_flash_sector_write.c Removed compiler warnings.
lx_nor_flash_block_reclaim.c Removed direct driver access for erases/reads/writes,
removed compiler warnings, and added logic to mark
the beginning of block erase.
lx_nor_flash_driver_block_erase.c Added file in this release.
lx_nor_flash_driver_read.c Added file in this release.
lx_nor_flash_driver_write.c Added file in this release.
lx_nor_flash_extended_cache_enable.c Added file in this release.
lx_nor_flash_logical_sector_find.c Removed direct driver access for reads, removed compiler
warnings, and added logic to use and maintain the last
found sector/block.
lx_nor_flash_next_block_to_erase_find.c Removed compiler warnings, and removed direct driver
access for reads.
lx_nor_flash_open.c Removed direct driver access for erases/reads/writes,
added logic to detect start of a block erase that was
interrupted, removed system error call for more than
one page being obsoleted since this can happen normally,
removed compiler warnings, and added logic to initialize
the last found sector/block.
lx_nor_flash_partial_defragment.c Added file in this release.
lx_nor_flash_physical_sector_allocate.c Removed direct driver access for reads/writes.
lx_nor_flash_sector_read.c Removed direct driver access for reads/writes.
lx_nor_flash_sector_release.c Removed direct driver access for reads/writes.
lx_nor_flash_sector_write.c Removed direct driver access for reads/writes.
lx_nor_flash_simulator.c Removed compiler warnings.
lx*.c Changed comments and copyright header, and added
conditional around disabling ThreadX error checking.
lx*.h Changed comments and copyright header.
05/01/2018 LevelX generic code version 5.4. This release includes the following
modifications:
lx_api.h Added NOR flash RAM buffer, added bit constant
for both NOR and NAND flash to indicate when
mapping write is valid, added diagnostic counter
for tracking when incomplete mapping is detected
on open, add added new error code when driver
does not supply a sector/page RAM buffer.
fx_nand_flash_simulated_driver.c Added error checking, and corrected sector
read/write processing.
fx_nor_flash_simulator_driver.c Added error checking.
lx_nand_flash_block_reclaim.c Added clearing of additional bit to indicate when
mapping is valid, and corrected logic that could
cause a newly mapped sector to be erased.
lx_nand_flash_logical_sector_find.c Added logic to make sure the sector mapping is valid.
lx_nand_flash_next_block_to_erase_find.c Added logic to improve search for free sectors.
lx_nand_flash_open.c Added logic to detect and handle a mapping entry
interrupted before completion, and added logic to
ensure there is a page buffer supplied by the
driver.
lx_nand_flash_sector_release.c Added reclaim logic to help increase free sectors.
lx_nand_flash_sector_write.c Added clearing of additional bit to indicate when
mapping is valid.
lx_nor_flash_block_reclaim.c Added clearing of additional bit to indicate when
mapping is valid, added logic to read NOR sector
into RAM buffer if direct NOR access is not possible,
and corrected logic that could cause a newly mapped
sector to be erased.
lx_nor_flash_logical_sector_find.c Added logic to make sure the sector mapping is valid.
lx_nor_flash_next_block_to_erase_find.c Added logic to improve search for free sectors.
lx_nor_flash_open.c Added logic to detect and handle a mapping entry
interrupted before completion, and added logic to
ensure there is a sector buffer supplied by the
driver if LX_DIRECT_READ is not specified.
lx_nor_flash_sector_release.c Added reclaim logic to help increase free sectors.
lx_nor_flash_sector_write.c Added clearing of additional bit to indicate when
mapping is valid, and removed optimization to ensure
atomic sector write.
lx_nor_flash_simulator.c Added logic to supply RAM buffer for reading
sector when LX_DIRECT_READ is not specified,
and removed write attempt to already written
sector, since this is no longer required.
fx*.c Changed comments and copyright header.
lx*.c Changed comments and copyright header.
lx*.h Changed comments and copyright header.
11/01/2017 LevelX generic code version 5.3. This release includes the following
modifications:
lx_nand_flash_block_full_update.c Added check to make sure the block is
actually full.
lx_nand_flash_block_reclaim.c Added support for direct logical sector
cache.
lx_nand_flash_logical_sector_find.c Added adjustment of mapped sectors when
examining the mapped list, added support
for direct logical sector cache.
lx_nand_flash_open.c Added support for direct logical sector cache,
and updated diagnostics.
lx_nand_flash_physical_page_allocate.c Added adjustment of the search pointer for
next allocate request.
lx_nand_flash_sector_mapping_cache_invalidate.c Added support for direct logical sector cache.
lx_nand_flash_sector_release.c Added logic to update the page 0 mapping list
if present.
lx_nand_flash_sector_write.c Added logic to update the page 0 mapping list
if present, and added check to make sure the
new mapping wasn't moved, added direct logical
sector cache.
fx*.c Changed comments and copyright header.
lx*.c Changed comments and copyright header.
lx*.h Changed comments and copyright header.
03/01/2017 LevelX generic code version 5.2. This release includes the following
modifications:
lx_nand_flash_block_full_update.c Reduced the number of words accessed in
page 0, added driver interface layer,
and modified the extra bytes usage in
page 0 to support block valid-full-empty.
lx_nand_flash_block_obsoleted_check.c Added file in this release.
lx_nand_flash_block_reclaim.c Added logic to update page 0 on a full
block update, added driver interface layer,
and added additional diagnostic information.
lx_nand_flash_driver_block_erase.c Added file in this release.
lx_nand_flash_driver_block_erased_verify.c Added file in this release.
lx_nand_flash_driver_block_status_get.c Added file in this release.
lx_nand_flash_driver_block_status_set.c Added file in this release.
lx_nand_flash_driver_extra_bytes_get.c Added file in this release.
lx_nand_flash_driver_extra_bytes_set.c Added file in this release.
lx_nand_flash_driver_page_erased_verify.c Added file in this release.
lx_nand_flash_driver_read.c Added file in this release.
lx_nand_flash_driver_write.c Added file in this release.
lx_nand_flash_extended_cache_enable.c Added file in this release.
lx_nand_flash_logical_sector_find.c Reduced the number of words accessed in
page 0, corrected check for valid sector
mapping list, added max mapped sector logic,
added driver interface layer, and added logic
to use and maintain the last found sector block.
lx_nand_flash_next_block_to_erase_find.c Reduced the number of words accessed in page 0,
and added driver interface layer.
lx_nand_flash_open.c Reduced the number of words accessed in page 0,
added driver interface layer, added additional
diagnostic information, added logic to initialize
the maximum mapped logical sector, and added
initialization of the last found sector block.
lx_nand_flash_physical_page_allocate.c Reduced the number of words accessed in page 0,
added driver interface layer, and added logic
to use page 0's extra bytes to determine if
block has available pages.
lx_nand_flash_sector_read.c Added driver interface layer.
lx_nand_flash_sector_release.c Added logic to maintain the maximum mapped
sector, and added driver interface layer.
lx_nand_flash_sector_write.c Added call to see if the block is completely
obsoleted, added logic to remember the maximum
mapped sector, and added driver interface layer.
fx_nand_flash_simulator_driver.c Removed sector packing by requiring sector and
cluster size to match, and added release sector
support.
fx*.c Changed comments and copyright header.
lx*.c Changed comments and copyright header.
lx*.h Changed comments and copyright header.
08/01/2016 LevelX generic code version 5.1. This release includes the following
modifications:
lx_nor_flash_physical_sector_allocate.c Corrected problem with more than 32 sectors per
flash block.
fx*.c Changed comments and copyright header.
lx*.c Changed comments and copyright header.
lx*.h Changed comments and copyright header.
01/22/2015 Initial LevelX generic code version 5.0.
+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);
+1 -1
View File
@@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 3.0.0 FATAL_ERROR) cmake_minimum_required(VERSION 3.13 FATAL_ERROR)
cmake_policy(SET CMP0057 NEW) cmake_policy(SET CMP0057 NEW)
project(regression_test LANGUAGES C) project(regression_test LANGUAGES C)
+2 -2
View File
@@ -3,7 +3,7 @@
cd $(dirname $0) cd $(dirname $0)
# if threadx repo does not exist, clone it # if threadx repo does not exist, clone it
[ -d threadx ] || git clone https://github.com/azure-rtos/threadx.git --depth 1 [ -d threadx ] || git clone https://github.com/eclipse-threadx/threadx.git --depth 1
[ -d filex ] || git clone https://github.com/azure-rtos/filex.git --depth 1 [ -d filex ] || git clone https://github.com/eclipse-threadx/filex.git --depth 1
[ -f .run.sh ] || ln -sf threadx/scripts/cmake_bootstrap.sh .run.sh [ -f .run.sh ] || ln -sf threadx/scripts/cmake_bootstrap.sh .run.sh
./.run.sh $* ./.run.sh $*
+1 -1
View File
@@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 3.0.0 FATAL_ERROR) cmake_minimum_required(VERSION 3.13 FATAL_ERROR)
cmake_policy(SET CMP0057 NEW) cmake_policy(SET CMP0057 NEW)
project(samples LANGUAGES C) project(samples LANGUAGES C)
+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
+93 -93
View File
@@ -21,7 +21,6 @@ ULONG readbuffer[128];
/* Define LevelX NOR flash simulator prototoypes. */ /* Define LevelX NOR flash simulator prototoypes. */
UINT _lx_nor_flash_simulator_erase_all(VOID);
UINT _lx_nor_flash_simulator_initialize(LX_NOR_FLASH *nor_flash); UINT _lx_nor_flash_simulator_initialize(LX_NOR_FLASH *nor_flash);
@@ -36,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();
@@ -53,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
@@ -69,26 +68,27 @@ UINT status;
ULONG *word_ptr; ULONG *word_ptr;
/* Erase the simulated NOR flash. */ /* format the simulated NOR flash. */
_lx_nor_flash_simulator_erase_all();
/* 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);
/* 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,25 +139,25 @@ 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_simulator_erase_all();
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_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);
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,20 +1278,20 @@ ULONG *word_ptr;
{ {
} }
} }
printf("SUCCESS!\n"); printf("SUCCESS!\n");
printf("Test 5: Randow write/read sector................"); printf("Test 5: Randow write/read sector................");
/* Erase the simulated NOR flash. */ /* format the simulated NOR flash. */
_lx_nor_flash_simulator_erase_all();
/* Open the flash. */ lx_nor_flash_format(&nor_sim_flash, "sim nor flash", _lx_nor_flash_simulator_initialize, NULL);
/* 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");
+104 -107
View File
@@ -24,7 +24,6 @@ UCHAR nor_cache_memory2[8192];
/* Define LevelX NOR flash simulator prototoypes. */ /* Define LevelX NOR flash simulator prototoypes. */
UINT _lx_nor_flash_simulator_erase_all(VOID);
UINT _lx_nor_flash_simulator_initialize(LX_NOR_FLASH *nor_flash); UINT _lx_nor_flash_simulator_initialize(LX_NOR_FLASH *nor_flash);
@@ -39,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();
@@ -57,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
@@ -73,16 +72,14 @@ UINT status;
ULONG *word_ptr; ULONG *word_ptr;
/* Erase the simulated NOR flash. */
_lx_nor_flash_simulator_erase_all();
/* 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_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
lx_nor_flash_extended_cache_enable(&nor_sim_flash, nor_cache_memory, sizeof(nor_cache_memory)); lx_nor_flash_extended_cache_enable(&nor_sim_flash, nor_cache_memory, sizeof(nor_cache_memory));
@@ -118,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");
@@ -132,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");
@@ -149,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");
@@ -201,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");
@@ -265,12 +262,11 @@ 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_simulator_erase_all();
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_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
lx_nor_flash_extended_cache_enable(&nor_sim_flash, nor_cache_memory, sizeof(nor_cache_memory)); lx_nor_flash_extended_cache_enable(&nor_sim_flash, nor_cache_memory, sizeof(nor_cache_memory));
@@ -278,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");
@@ -297,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");
@@ -310,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");
@@ -325,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);
@@ -347,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)
{ {
@@ -539,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");
@@ -550,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");
@@ -568,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));
@@ -585,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);
@@ -594,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");
@@ -607,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));
@@ -622,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);
@@ -633,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");
@@ -651,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));
@@ -661,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);
@@ -670,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");
@@ -688,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));
@@ -698,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);
@@ -709,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");
@@ -726,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));
@@ -737,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);
@@ -748,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. */
@@ -758,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));
@@ -769,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);
@@ -970,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");
@@ -981,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");
@@ -995,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)
{ {
@@ -1376,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)
{ {
@@ -1399,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");
@@ -1425,23 +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................");
/* Erase the simulated NOR flash. */ /*format the simulated NOR flash. */
_lx_nor_flash_simulator_erase_all();
/* 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_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);
@@ -1450,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");
@@ -1470,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");
@@ -1487,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");
@@ -1503,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");
@@ -1525,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");
@@ -1544,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)
@@ -1561,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,18 +1575,18 @@ status += lx_nor_flash_extended_cache_enable(&nor_sim_flash, nor_cache_memory, s
printf("Test 6: Check lx_nor_flash_extended_cache_entries size................"); printf("Test 6: Check lx_nor_flash_extended_cache_entries size................");
/* Erase the simulated NOR flash. */ /* Format the simulated NOR flash. */
_lx_nor_flash_simulator_erase_all(); 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);
@@ -1604,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");
@@ -1618,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");
@@ -1635,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");
@@ -1651,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