mirror of
https://github.com/eclipse-threadx/levelx.git
synced 2026-09-15 04:55:33 +08:00
Compare commits
66
Commits
v6.3.0_rel
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
9f1cfdc181 | ||
|
|
37dd169031 | ||
|
|
4005a425b7 | ||
|
|
123218cc51 | ||
|
|
b9f54b87bb | ||
|
|
2e061ba319 | ||
|
|
bfb39676df | ||
|
|
a46b74fb8a | ||
|
|
b80f28e0e6 | ||
|
|
f98a5c4eb8 | ||
|
|
b9ba4a97bf | ||
|
|
fa1a8e5ff4 | ||
|
|
89c745fcf5 | ||
|
|
4782f22568 | ||
|
|
58dc81e83c | ||
|
|
1751446fb0 | ||
|
|
c27eb52bd2 | ||
|
|
c03223909a | ||
|
|
9bf1c24243 | ||
|
|
6a534bed34 | ||
|
|
4585b92f15 | ||
|
|
63ed12cfd6 | ||
|
|
a1761869fd | ||
|
|
5783f64fe1 | ||
|
|
47b2a17d4b | ||
|
|
0f7dd521e5 | ||
|
|
b5dcbff38c | ||
|
|
7d1ef20acf | ||
|
|
04e385f3d5 | ||
|
|
7c5d83d794 | ||
|
|
24eb7d8692 | ||
|
|
058b242a9a | ||
|
|
a3c9691d89 | ||
|
|
f5a55077ad | ||
|
|
656d1490f4 | ||
|
|
8e1d00b591 | ||
|
|
f8899e5d6d | ||
|
|
acc5190739 | ||
|
|
79cbf4019f | ||
|
|
2a963969bc | ||
|
|
1317123fdc | ||
|
|
814a8a346c | ||
|
|
34616e26e7 | ||
|
|
f840cf4ce6 | ||
|
|
ec683ddf14 | ||
|
|
1d6706dfa9 | ||
|
|
6809f87fdd | ||
|
|
9b766d144f | ||
|
|
fb4b913dc2 | ||
|
|
01517ad256 | ||
|
|
9f85e68bd1 | ||
|
|
bc8f7f3623 | ||
|
|
3ca016c042 | ||
|
|
4e747beb15 | ||
|
|
151863ad7c | ||
|
|
d7b2a72452 | ||
|
|
e432e2cfa2 | ||
|
|
0ea87a458d | ||
|
|
f8ab75e3ee | ||
|
|
e74a289b41 | ||
|
|
9551a4cda1 | ||
|
|
268e4edf97 | ||
|
|
fcce06af34 | ||
|
|
521fe0bacb | ||
|
|
772f99b415 | ||
|
|
df4ecd8404 |
@@ -0,0 +1,13 @@
|
|||||||
|
{
|
||||||
|
"image": "ghcr.io/tiejunms/azure_rtos_docker",
|
||||||
|
|
||||||
|
// Add the IDs of extensions you want installed when the container is created.
|
||||||
|
"extensions": [
|
||||||
|
"ms-vscode.cpptools",
|
||||||
|
"ms-vscode.cmake-tools"
|
||||||
|
],
|
||||||
|
|
||||||
|
"remoteUser": "vscode",
|
||||||
|
|
||||||
|
"runArgs": [ "--cap-add=NET_ADMIN"]
|
||||||
|
}
|
||||||
@@ -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,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.
|
||||||
|
|||||||
@@ -0,0 +1,25 @@
|
|||||||
|
# This is a basic workflow that is manually triggered
|
||||||
|
|
||||||
|
name: regression_test
|
||||||
|
|
||||||
|
# Controls when the action will run. Triggers the workflow on push or pull request
|
||||||
|
# events but only for the master branch
|
||||||
|
on:
|
||||||
|
workflow_dispatch:
|
||||||
|
push:
|
||||||
|
branches: [ master ]
|
||||||
|
pull_request:
|
||||||
|
branches: [ master ]
|
||||||
|
|
||||||
|
# A workflow run is made up of one or more jobs that can run sequentially or in parallel
|
||||||
|
jobs:
|
||||||
|
# This workflow contains a single job called "linux_job"
|
||||||
|
run_tests:
|
||||||
|
permissions:
|
||||||
|
contents: read
|
||||||
|
issues: read
|
||||||
|
checks: write
|
||||||
|
pull-requests: write
|
||||||
|
pages: write
|
||||||
|
id-token: write
|
||||||
|
uses: eclipse-threadx/threadx/.github/workflows/regression_template.yml@master
|
||||||
+1
-1
@@ -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
@@ -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 that’s 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
@@ -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 Microsoft’s 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
|
|
||||||
Microsoft’s 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 Microsoft’s 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
|
|
||||||
Microsoft’s 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
|
|
||||||
n’accorde 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, d’adéquation à un usage particulier
|
|
||||||
et d’absence de contrefaçon sont exclues.
|
|
||||||
b) CLAUSE D’EXCLUSION DE RESPONSABILITÉ RELATIVE À L’UTILISATION À HAUT RISQUE.
|
|
||||||
AVERTISSEMENT: LE LOGICIEL N’EST PAS CONÇU OU DESTINÉ À ÊTRE UTILISÉ LORSQU’UNE
|
|
||||||
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 d’interruption, de défaut, d’erreur
|
|
||||||
ou de toute autre défaillance du logiciel, la sécurité des personnes, des biens et de l’environnement ne
|
|
||||||
soit pas réduite en dessous d’un 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 d’une autre faute dans la limite
|
|
||||||
autorisée par la loi en vigueur.
|
|
||||||
|
|
||||||
Elle s’applique également, même si Microsoft connaissait ou devrait connaître
|
|
||||||
l’éventualité d’un tel dommage. Si votre pays n’autorise pas l’exclusion ou la
|
|
||||||
limitation de responsabilité pour les dommages indirects, accessoires ou de
|
|
||||||
quelque nature que ce soit, il se peut que la limitation ou l’exclusion
|
|
||||||
ci-dessus ne s’appliquera pas à votre égard.
|
|
||||||
|
|
||||||
EFFET JURIDIQUE. Le présent contrat décrit certains droits juridiques. Vous
|
|
||||||
pourriez avoir d’autres 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.
|
|
||||||
|
|||||||
@@ -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.
|
|
||||||
@@ -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, it’s 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, it’s 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.
|
||||||
|
|
||||||

|

|
||||||
|
|
||||||
@@ -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
|
||||||
|
|
||||||
|
|||||||
+25
-21
@@ -1,35 +1,39 @@
|
|||||||
## 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/).
|
This Eclipse Foundation Project adheres to the [Eclipse Foundation Vulnerability Reporting Policy](https://www.eclipse.org/security/policy/).
|
||||||
|
|
||||||
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.
|
## How To Report a Vulnerability
|
||||||
|
|
||||||
## Reporting Security Issues
|
If you think you have found a vulnerability in this repository, please report it to us through coordinated disclosure.
|
||||||
|
|
||||||
**Please do not report security vulnerabilities through public GitHub issues.**
|
**Please do not report security vulnerabilities through public issues, discussions, or change requests.**
|
||||||
|
|
||||||
Instead, please report them to the Microsoft Security Response Center (MSRC) at [https://msrc.microsoft.com/create-report](https://msrc.microsoft.com/create-report).
|
Instead, [report it privately here](https://github.com/eclipse-threadx/levelx/security/advisories/new) on GitHub
|
||||||
|
|
||||||
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).
|
Please include as much of the information listed below as you can to help us better understand and resolve the issue:
|
||||||
|
|
||||||
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:
|
* The type of issue (e.g., buffer overflow, SQL injection, or cross-site scripting)
|
||||||
|
* Affected version(s)
|
||||||
* Type of issue (e.g. buffer overflow, SQL injection, cross-site scripting, etc.)
|
* Impact of the issue, including how an attacker might exploit the issue
|
||||||
* Full paths of source file(s) related to the manifestation of the issue
|
* Step-by-step instructions to reproduce the issue
|
||||||
* The location of the affected source code (tag/branch/commit or direct URL)
|
* The location of the affected source code (tag/branch/commit or direct URL)
|
||||||
* Any special configuration required to reproduce the issue
|
* Full paths of source file(s) related to the manifestation of the issue
|
||||||
* Step-by-step instructions to reproduce the issue
|
* Configuration required to reproduce the issue
|
||||||
* Proof-of-concept or exploit code (if possible)
|
* Log files that are related to this issue (if possible)
|
||||||
* Impact of the issue, including how an attacker might exploit the issue
|
* Proof-of-concept or exploit code (if possible)
|
||||||
|
|
||||||
This information will help us triage your report more quickly.
|
This information will help us triage your report more quickly.
|
||||||
|
|
||||||
## Preferred Languages
|
## Supported Versions
|
||||||
|
|
||||||
We prefer all communications to be in English.
|
| Version | Supported |
|
||||||
|
| ------- | ------------------ |
|
||||||
|
| 6.5.x | :white_check_mark: |
|
||||||
|
|
||||||
## Policy
|
Eclipse ThreadX publishes a release every quarter. There are no long-term support branches or backports to older releases.
|
||||||
|
|
||||||
Microsoft follows the principle of [Coordinated Vulnerability Disclosure](https://www.microsoft.com/en-us/msrc/cvd).
|
Normally, fixes for non-critical vulnerabilities will ship in a regularly scheduled quarterly release. If fixes for an urgent or critical vulnerability must ship quickly, then the project will publish a hotfix release of the affected component(s) without waiting for the next quarterly release.
|
||||||
|
|
||||||
|
You can learn more about the [project's release cadence in this blog post](https://blogs.eclipse.org/post/fr%C3%A9d%C3%A9ric-desbiens/eclipse-threadx-more-predictable-more-open).
|
||||||
|
|||||||
@@ -20,8 +20,10 @@ 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_logical_group_compact.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
|
||||||
${CMAKE_CURRENT_LIST_DIR}/src/lx_nand_flash_mapped_block_list_get.c
|
${CMAKE_CURRENT_LIST_DIR}/src/lx_nand_flash_mapped_block_list_get.c
|
||||||
${CMAKE_CURRENT_LIST_DIR}/src/lx_nand_flash_mapped_block_list_remove.c
|
${CMAKE_CURRENT_LIST_DIR}/src/lx_nand_flash_mapped_block_list_remove.c
|
||||||
@@ -30,6 +32,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 +55,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
|
||||||
|
|||||||
+106
-101
@@ -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.3.0 */
|
/* 6.4.1 */
|
||||||
/* AUTHOR */
|
/* AUTHOR */
|
||||||
/* */
|
/* */
|
||||||
/* William E. Lamie, Microsoft Corporation */
|
/* William E. Lamie, Microsoft Corporation */
|
||||||
@@ -37,56 +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 */
|
|
||||||
/* */
|
|
||||||
/**************************************************************************/
|
/**************************************************************************/
|
||||||
|
|
||||||
#ifndef LX_API_H
|
#ifndef LX_API_H
|
||||||
@@ -108,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"
|
||||||
@@ -197,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 3
|
#define LEVELX_MINOR_VERSION 5
|
||||||
#define LEVELX_PATCH_VERSION 0
|
#define LEVELX_PATCH_VERSION 1
|
||||||
|
#define LEVELX_BUILD_VERSION 202602
|
||||||
|
#define LEVELX_HOTFIX_VERSION ' '
|
||||||
|
|
||||||
|
|
||||||
/* Define general LevelX Constants. */
|
/* Define general LevelX Constants. */
|
||||||
@@ -232,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. */
|
||||||
@@ -261,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. */
|
||||||
@@ -279,6 +232,19 @@ typedef unsigned long long ULONG64;
|
|||||||
#define LX_NOR_PHYSICAL_SECTOR_FREE 0xFFFFFFFF
|
#define LX_NOR_PHYSICAL_SECTOR_FREE 0xFFFFFFFF
|
||||||
|
|
||||||
|
|
||||||
|
/* Check extended cache configurations. */
|
||||||
|
#ifdef LX_NOR_DISABLE_EXTENDED_CACHE
|
||||||
|
|
||||||
|
#ifdef LX_NOR_ENABLE_MAPPING_BITMAP
|
||||||
|
#error "To enable mapping bitmap, you need to undefine LX_NOR_DISABLE_EXTENDED_CACHE."
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef LX_NOR_ENABLE_OBSOLETE_COUNT_CACHE
|
||||||
|
#error "To enable obsolete count cache, you need to undefine LX_NOR_DISABLE_EXTENDED_CACHE."
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
/* Define NAND flash constants. */
|
/* Define NAND flash constants. */
|
||||||
|
|
||||||
#define LX_NAND_GOOD_BLOCK 0xFF
|
#define LX_NAND_GOOD_BLOCK 0xFF
|
||||||
@@ -291,22 +257,33 @@ 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
|
||||||
|
|
||||||
|
/* When LX_NAND_FLASH_ENABLE_LAZY_SECTOR_RELEASE is defined, sector releases from full blocks
|
||||||
|
are deferred when free block count exceeds the threshold below (opt-in, default: off).
|
||||||
|
Requires pages_per_block <= 4095 (bit 12 is reserved for COMPACTION_PENDING flag). */
|
||||||
|
/* #define LX_NAND_FLASH_ENABLE_LAZY_SECTOR_RELEASE */
|
||||||
|
|
||||||
|
#ifdef LX_NAND_FLASH_ENABLE_LAZY_SECTOR_RELEASE
|
||||||
|
#ifndef LX_NAND_FLASH_SECTOR_RELEASE_LAZY_THRESHOLD
|
||||||
|
#define LX_NAND_FLASH_SECTOR_RELEASE_LAZY_THRESHOLD 10u
|
||||||
|
#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)
|
||||||
@@ -324,9 +301,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. */
|
||||||
@@ -362,6 +339,11 @@ typedef unsigned long long ULONG64;
|
|||||||
#define LX_NAND_BLOCK_STATUS_FULL 0x4000u
|
#define LX_NAND_BLOCK_STATUS_FULL 0x4000u
|
||||||
#define LX_NAND_BLOCK_STATUS_NON_SEQUENTIAL 0x2000u
|
#define LX_NAND_BLOCK_STATUS_NON_SEQUENTIAL 0x2000u
|
||||||
#define LX_NAND_BLOCK_STATUS_MAPPING_PRESENT 0x1000u
|
#define LX_NAND_BLOCK_STATUS_MAPPING_PRESENT 0x1000u
|
||||||
|
#ifdef LX_NAND_FLASH_ENABLE_LAZY_SECTOR_RELEASE
|
||||||
|
/* Repurpose the otherwise-unused MAPPING_PRESENT bit to signal a block whose compaction
|
||||||
|
has been deferred. Only valid when pages_per_block <= 4095. */
|
||||||
|
#define LX_NAND_BLOCK_STATUS_COMPACTION_PENDING LX_NAND_BLOCK_STATUS_MAPPING_PRESENT
|
||||||
|
#endif
|
||||||
#define LX_NAND_BLOCK_STATUS_PAGE_NUMBER_MASK 0x0FFFu
|
#define LX_NAND_BLOCK_STATUS_PAGE_NUMBER_MASK 0x0FFFu
|
||||||
#define LX_NAND_BLOCK_STATUS_FREE 0xFFFFu
|
#define LX_NAND_BLOCK_STATUS_FREE 0xFFFFu
|
||||||
#define LX_NAND_BLOCK_STATUS_BAD 0xFF00u
|
#define LX_NAND_BLOCK_STATUS_BAD 0xFF00u
|
||||||
@@ -401,7 +383,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
|
||||||
@@ -436,6 +418,12 @@ typedef struct LX_NAND_FLASH_STRUCT
|
|||||||
USHORT *lx_nand_flash_block_list;
|
USHORT *lx_nand_flash_block_list;
|
||||||
ULONG lx_nand_flash_block_list_size;
|
ULONG lx_nand_flash_block_list_size;
|
||||||
ULONG lx_nand_flash_free_block_list_tail;
|
ULONG lx_nand_flash_free_block_list_tail;
|
||||||
|
#ifdef LX_NAND_FLASH_ENABLE_LAZY_SECTOR_RELEASE
|
||||||
|
/* Parallel to block_mapping_table: physical block with pending compaction for a group,
|
||||||
|
or LX_NAND_BLOCK_UNMAPPED when no compaction is pending. */
|
||||||
|
USHORT *lx_nand_flash_block_compaction_table;
|
||||||
|
ULONG lx_nand_flash_block_compaction_table_size;
|
||||||
|
#endif
|
||||||
ULONG lx_nand_flash_mapped_block_list_head;
|
ULONG lx_nand_flash_mapped_block_list_head;
|
||||||
|
|
||||||
ULONG lx_nand_flash_metadata_block_number;
|
ULONG lx_nand_flash_metadata_block_number;
|
||||||
@@ -488,7 +476,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);
|
||||||
@@ -503,14 +491,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
|
||||||
@@ -518,15 +505,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;
|
||||||
|
|
||||||
|
|
||||||
@@ -536,7 +525,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;
|
||||||
|
|
||||||
@@ -545,13 +534,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
|
||||||
@@ -584,7 +573,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;
|
||||||
@@ -620,7 +609,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
|
||||||
@@ -638,7 +627,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
|
||||||
@@ -648,12 +637,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
|
||||||
|
|
||||||
@@ -663,24 +653,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
|
||||||
@@ -707,8 +697,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
|
||||||
@@ -725,7 +717,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
|
||||||
@@ -741,7 +735,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);
|
||||||
@@ -756,7 +756,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);
|
||||||
@@ -791,6 +793,9 @@ UINT _lx_nand_flash_metadata_write(LX_NAND_FLASH *nand_flash, UCHAR* main_buf
|
|||||||
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);
|
||||||
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);
|
||||||
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);
|
||||||
|
#ifdef LX_NAND_FLASH_ENABLE_LAZY_SECTOR_RELEASE
|
||||||
|
UINT _lx_nand_flash_logical_group_compact(LX_NAND_FLASH *nand_flash, ULONG logical_group);
|
||||||
|
#endif
|
||||||
|
|
||||||
UINT _lx_nor_flash_block_reclaim(LX_NOR_FLASH *nor_flash);
|
UINT _lx_nor_flash_block_reclaim(LX_NOR_FLASH *nor_flash);
|
||||||
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);
|
||||||
@@ -808,5 +813,5 @@ VOID _lx_nor_flash_system_error(LX_NOR_FLASH *nor_flash, UINT error_code);
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|||||||
+29
-46
@@ -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))
|
||||||
|
|||||||
@@ -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;
|
||||||
|
|||||||
@@ -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;
|
||||||
|
|||||||
@@ -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. */
|
||||||
|
|||||||
@@ -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];
|
||||||
|
|||||||
@@ -1,19 +1,20 @@
|
|||||||
/**************************************************************************/
|
/***************************************************************************
|
||||||
/* */
|
* 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
|
||||||
/**************************************************************************/
|
**************************************************************************/
|
||||||
|
|
||||||
|
// Some portions generated by Copilot (Sonnet 4.6).
|
||||||
|
|
||||||
/**************************************************************************/
|
/**************************************************************************/
|
||||||
/**************************************************************************/
|
/**************************************************************************/
|
||||||
/** */
|
/** */
|
||||||
/** LevelX Component */
|
/** LevelX Component */
|
||||||
/** */
|
/** */
|
||||||
/** NAND Flash */
|
/** NAND Flash */
|
||||||
/** */
|
/** */
|
||||||
@@ -35,42 +36,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)
|
||||||
@@ -81,6 +76,43 @@ UINT _lx_nand_flash_block_allocate(LX_NAND_FLASH* nand_flash, ULONG* block)
|
|||||||
if (nand_flash -> lx_nand_flash_free_block_list_tail == 0)
|
if (nand_flash -> lx_nand_flash_free_block_list_tail == 0)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
#ifdef LX_NAND_FLASH_ENABLE_LAZY_SECTOR_RELEASE
|
||||||
|
{
|
||||||
|
|
||||||
|
ULONG lg;
|
||||||
|
UINT compact_status;
|
||||||
|
|
||||||
|
/* Emergency compaction: find any pending compaction and execute it to
|
||||||
|
reclaim the old full block. */
|
||||||
|
for (lg = 0; lg < nand_flash -> lx_nand_flash_total_blocks; lg++)
|
||||||
|
{
|
||||||
|
|
||||||
|
if (nand_flash -> lx_nand_flash_block_compaction_table[lg] != (USHORT)LX_NAND_BLOCK_UNMAPPED)
|
||||||
|
{
|
||||||
|
|
||||||
|
compact_status = _lx_nand_flash_logical_group_compact(nand_flash, lg);
|
||||||
|
|
||||||
|
if (compact_status == LX_SUCCESS)
|
||||||
|
{
|
||||||
|
|
||||||
|
/* Retry the allocation after compaction freed a block. */
|
||||||
|
if (nand_flash -> lx_nand_flash_free_block_list_tail > 0)
|
||||||
|
{
|
||||||
|
|
||||||
|
nand_flash -> lx_nand_flash_free_block_list_tail--;
|
||||||
|
*block = nand_flash -> lx_nand_flash_block_list[nand_flash -> lx_nand_flash_free_block_list_tail];
|
||||||
|
return(LX_SUCCESS);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Attempt only one compaction per allocate call. */
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
#endif /* LX_NAND_FLASH_ENABLE_LAZY_SECTOR_RELEASE */
|
||||||
|
|
||||||
/* Empty list, return error. */
|
/* Empty list, return error. */
|
||||||
return(LX_NO_BLOCKS);
|
return(LX_NO_BLOCKS);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,19 +1,20 @@
|
|||||||
/**************************************************************************/
|
/***************************************************************************
|
||||||
/* */
|
* 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
|
||||||
/**************************************************************************/
|
**************************************************************************/
|
||||||
|
|
||||||
|
// Some portions generated by Copilot (Sonnet 4.6).
|
||||||
|
|
||||||
/**************************************************************************/
|
/**************************************************************************/
|
||||||
/**************************************************************************/
|
/**************************************************************************/
|
||||||
/** */
|
/** */
|
||||||
/** LevelX Component */
|
/** LevelX Component */
|
||||||
/** */
|
/** */
|
||||||
/** NAND Flash */
|
/** NAND Flash */
|
||||||
/** */
|
/** */
|
||||||
@@ -35,55 +36,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)
|
||||||
@@ -117,6 +112,33 @@ ULONG block_mapping_index;
|
|||||||
return(LX_ERROR);
|
return(LX_ERROR);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef LX_NAND_FLASH_ENABLE_LAZY_SECTOR_RELEASE
|
||||||
|
/* If this logical group has a pending compaction source, redirect the
|
||||||
|
data move to a full logical-group compact to correctly merge data from
|
||||||
|
both source blocks. */
|
||||||
|
if (nand_flash -> lx_nand_flash_block_compaction_table[block_mapping_index] != (USHORT)LX_NAND_BLOCK_UNMAPPED)
|
||||||
|
{
|
||||||
|
|
||||||
|
/* Return the pre-allocated new_block to the free list. */
|
||||||
|
status = _lx_nand_flash_block_status_set(nand_flash, new_block, LX_NAND_BLOCK_STATUS_FREE);
|
||||||
|
|
||||||
|
if (status)
|
||||||
|
{
|
||||||
|
_lx_nand_flash_system_error(nand_flash, status, new_block, 0);
|
||||||
|
return(LX_ERROR);
|
||||||
|
}
|
||||||
|
|
||||||
|
_lx_nand_flash_free_block_list_add(nand_flash, new_block);
|
||||||
|
|
||||||
|
/* Restore block_mapping_index to the mapped list; mapped_block_list_get
|
||||||
|
already removed it before this function was called. */
|
||||||
|
_lx_nand_flash_mapped_block_list_add(nand_flash, block_mapping_index);
|
||||||
|
|
||||||
|
/* Perform full compaction merge of both source blocks. */
|
||||||
|
return(_lx_nand_flash_logical_group_compact(nand_flash, block_mapping_index));
|
||||||
|
}
|
||||||
|
#endif /* LX_NAND_FLASH_ENABLE_LAZY_SECTOR_RELEASE */
|
||||||
|
|
||||||
/* Set new block status to allocated for now. */
|
/* Set new block status to allocated for now. */
|
||||||
new_block_status = LX_NAND_BLOCK_STATUS_ALLOCATED;
|
new_block_status = LX_NAND_BLOCK_STATUS_ALLOCATED;
|
||||||
|
|
||||||
|
|||||||
@@ -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. */
|
||||||
|
|||||||
@@ -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. */
|
||||||
|
|||||||
@@ -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. */
|
||||||
|
|||||||
@@ -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
|
||||||
|
|
||||||
|
|||||||
@@ -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_data_page_copy PORTABLE C */
|
/* _lx_nand_flash_data_page_copy PORTABLE C */
|
||||||
/* 6.2.1 */
|
/* 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. */
|
||||||
|
/* */
|
||||||
|
/* 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 */
|
||||||
/* */
|
/* */
|
||||||
/**************************************************************************/
|
/**************************************************************************/
|
||||||
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,
|
||||||
@@ -168,7 +162,7 @@ ULONG number_of_pages;
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Check if the pages in destination block is still sequential. */
|
/* Check if the pages in destination block is still sequential. */
|
||||||
if ((destination_page) != (logical_sector + i % nand_flash -> lx_nand_flash_pages_per_block))
|
if (destination_page != ((logical_sector + i) % nand_flash -> lx_nand_flash_pages_per_block))
|
||||||
{
|
{
|
||||||
/* Mark the block status as non sequential. */
|
/* Mark the block status as non sequential. */
|
||||||
dest_block_status |= LX_NAND_BLOCK_STATUS_NON_SEQUENTIAL;
|
dest_block_status |= LX_NAND_BLOCK_STATUS_NON_SEQUENTIAL;
|
||||||
@@ -197,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. */
|
||||||
|
|||||||
@@ -1,19 +1,20 @@
|
|||||||
/**************************************************************************/
|
/***************************************************************************
|
||||||
/* */
|
* 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
|
||||||
/**************************************************************************/
|
**************************************************************************/
|
||||||
|
|
||||||
|
// Some portions generated by Copilot (Sonnet 4.6).
|
||||||
|
|
||||||
/**************************************************************************/
|
/**************************************************************************/
|
||||||
/**************************************************************************/
|
/**************************************************************************/
|
||||||
/** */
|
/** */
|
||||||
/** LevelX Component */
|
/** LevelX Component */
|
||||||
/** */
|
/** */
|
||||||
/** NAND Flash */
|
/** NAND Flash */
|
||||||
/** */
|
/** */
|
||||||
@@ -35,60 +36,75 @@
|
|||||||
#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)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
#ifdef LX_NAND_FLASH_ENABLE_LAZY_SECTOR_RELEASE
|
||||||
|
|
||||||
|
UINT status;
|
||||||
|
ULONG lg;
|
||||||
|
|
||||||
|
/* Compact every logical group that has a deferred compaction pending. */
|
||||||
|
for (lg = 0; lg < nand_flash -> lx_nand_flash_total_blocks; lg++)
|
||||||
|
{
|
||||||
|
|
||||||
|
if (nand_flash -> lx_nand_flash_block_compaction_table[lg] != (USHORT)LX_NAND_BLOCK_UNMAPPED)
|
||||||
|
{
|
||||||
|
|
||||||
|
status = _lx_nand_flash_logical_group_compact(nand_flash, lg);
|
||||||
|
|
||||||
|
/* On error, continue to compact remaining groups. */
|
||||||
|
if (status)
|
||||||
|
{
|
||||||
|
_lx_nand_flash_system_error(nand_flash, status, lg, 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return(LX_SUCCESS);
|
||||||
|
|
||||||
|
#else
|
||||||
|
|
||||||
LX_PARAMETER_NOT_USED(nand_flash);
|
LX_PARAMETER_NOT_USED(nand_flash);
|
||||||
|
|
||||||
/* Return not supported. */
|
/* Return not supported. */
|
||||||
return(LX_NOT_SUPPORTED);
|
return(LX_NOT_SUPPORTED);
|
||||||
|
|
||||||
|
#endif /* LX_NAND_FLASH_ENABLE_LAZY_SECTOR_RELEASE */
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -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)
|
||||||
|
|||||||
@@ -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);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -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);
|
||||||
|
}
|
||||||
|
|
||||||
@@ -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))
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|||||||
@@ -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);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,447 @@
|
|||||||
|
/***************************************************************************
|
||||||
|
* 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
|
||||||
|
**************************************************************************/
|
||||||
|
|
||||||
|
// Some portions generated by Copilot (Sonnet 4.6).
|
||||||
|
|
||||||
|
/**************************************************************************/
|
||||||
|
/**************************************************************************/
|
||||||
|
/** */
|
||||||
|
/** 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"
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef LX_NAND_FLASH_ENABLE_LAZY_SECTOR_RELEASE
|
||||||
|
|
||||||
|
|
||||||
|
/**************************************************************************/
|
||||||
|
/* */
|
||||||
|
/* FUNCTION RELEASE */
|
||||||
|
/* */
|
||||||
|
/* _lx_nand_sector_find_in_block PORTABLE C */
|
||||||
|
/* 6.5.0 */
|
||||||
|
/* AUTHOR */
|
||||||
|
/* */
|
||||||
|
/* Eclipse ThreadX contributors */
|
||||||
|
/* */
|
||||||
|
/* DESCRIPTION */
|
||||||
|
/* */
|
||||||
|
/* This helper scans a block for a specific logical sector and returns */
|
||||||
|
/* the page number and kind (data / released / not found). */
|
||||||
|
/* */
|
||||||
|
/* INPUT */
|
||||||
|
/* */
|
||||||
|
/* nand_flash NAND flash instance */
|
||||||
|
/* block Physical block number */
|
||||||
|
/* block_status Block status word */
|
||||||
|
/* logical_sector Logical sector to search for */
|
||||||
|
/* found_page Destination: page index found */
|
||||||
|
/* sector_kind Destination: kind (see below) */
|
||||||
|
/* */
|
||||||
|
/* OUTPUT */
|
||||||
|
/* */
|
||||||
|
/* LX_SUCCESS Sector found; outputs set */
|
||||||
|
/* LX_NO_BLOCKS Sector not present in block */
|
||||||
|
/* LX_ERROR Driver error */
|
||||||
|
/* */
|
||||||
|
/* SECTOR KIND VALUES (written to *sector_kind) */
|
||||||
|
/* */
|
||||||
|
/* LX_NAND_PAGE_TYPE_USER_DATA Sector contains live data */
|
||||||
|
/* LX_NAND_PAGE_TYPE_USER_DATA_RELEASED Sector is tombstoned */
|
||||||
|
/* */
|
||||||
|
/**************************************************************************/
|
||||||
|
static UINT _lx_nand_sector_find_in_block(LX_NAND_FLASH *nand_flash,
|
||||||
|
ULONG block,
|
||||||
|
USHORT block_status,
|
||||||
|
ULONG logical_sector,
|
||||||
|
LONG *found_page,
|
||||||
|
ULONG *sector_kind)
|
||||||
|
{
|
||||||
|
|
||||||
|
ULONG available_pages;
|
||||||
|
LONG page;
|
||||||
|
ULONG spare_data1;
|
||||||
|
UINT status;
|
||||||
|
UCHAR *spare_buffer_ptr;
|
||||||
|
|
||||||
|
|
||||||
|
/* Use page buffer as scratch for spare-only reads (per existing LevelX convention). */
|
||||||
|
spare_buffer_ptr = nand_flash -> lx_nand_flash_page_buffer;
|
||||||
|
|
||||||
|
/* Determine page count. */
|
||||||
|
available_pages = (block_status & LX_NAND_BLOCK_STATUS_FULL) ?
|
||||||
|
nand_flash -> lx_nand_flash_pages_per_block :
|
||||||
|
(block_status & LX_NAND_BLOCK_STATUS_PAGE_NUMBER_MASK);
|
||||||
|
|
||||||
|
if (block_status & LX_NAND_BLOCK_STATUS_NON_SEQUENTIAL)
|
||||||
|
{
|
||||||
|
|
||||||
|
/* Scan newest-to-oldest so the first match is the authoritative version. */
|
||||||
|
for (page = (LONG)available_pages - 1; page >= 0; page--)
|
||||||
|
{
|
||||||
|
|
||||||
|
#ifdef LX_NAND_ENABLE_CONTROL_BLOCK_FOR_DRIVER_INTERFACE
|
||||||
|
status = (nand_flash -> lx_nand_flash_driver_pages_read)(nand_flash, block, (ULONG)page, LX_NULL, spare_buffer_ptr, 1);
|
||||||
|
#else
|
||||||
|
status = (nand_flash -> lx_nand_flash_driver_pages_read)(block, (ULONG)page, LX_NULL, spare_buffer_ptr, 1);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* Check for an error from flash driver. */
|
||||||
|
if (status)
|
||||||
|
{
|
||||||
|
_lx_nand_flash_system_error(nand_flash, status, block, 0);
|
||||||
|
return(LX_ERROR);
|
||||||
|
}
|
||||||
|
|
||||||
|
spare_data1 = LX_UTILITY_LONG_GET(&spare_buffer_ptr[nand_flash -> lx_nand_flash_spare_data1_offset]);
|
||||||
|
|
||||||
|
if ((spare_data1 & LX_NAND_PAGE_TYPE_USER_DATA_MASK) == logical_sector)
|
||||||
|
{
|
||||||
|
|
||||||
|
/* Sector found; return its page index and kind. */
|
||||||
|
*found_page = page;
|
||||||
|
*sector_kind = spare_data1 & (~LX_NAND_PAGE_TYPE_USER_DATA_MASK);
|
||||||
|
return(LX_SUCCESS);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
|
||||||
|
/* Sequential block: page index == sector offset within group. */
|
||||||
|
page = (LONG)(logical_sector % nand_flash -> lx_nand_flash_pages_per_block);
|
||||||
|
if ((ULONG)page < available_pages)
|
||||||
|
{
|
||||||
|
*found_page = page;
|
||||||
|
*sector_kind = LX_NAND_PAGE_TYPE_USER_DATA;
|
||||||
|
return(LX_SUCCESS);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
*found_page = -1L;
|
||||||
|
return(LX_NO_BLOCKS);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**************************************************************************/
|
||||||
|
/* */
|
||||||
|
/* FUNCTION RELEASE */
|
||||||
|
/* */
|
||||||
|
/* _lx_nand_flash_logical_group_compact PORTABLE C */
|
||||||
|
/* 6.5.0 */
|
||||||
|
/* AUTHOR */
|
||||||
|
/* */
|
||||||
|
/* Eclipse ThreadX contributors */
|
||||||
|
/* */
|
||||||
|
/* DESCRIPTION */
|
||||||
|
/* */
|
||||||
|
/* This function completes a deferred full-block compaction created by */
|
||||||
|
/* the lazy sector-release path. It merges the tombstone block */
|
||||||
|
/* (current mapping) and the compaction-pending old block into a fresh */
|
||||||
|
/* destination block, then erases both source blocks. */
|
||||||
|
/* */
|
||||||
|
/* The tombstone block takes priority: if a sector appears in both */
|
||||||
|
/* blocks the tombstone block's version is used (newer). */
|
||||||
|
/* */
|
||||||
|
/* INPUT */
|
||||||
|
/* */
|
||||||
|
/* nand_flash NAND flash instance */
|
||||||
|
/* logical_group Logical group index */
|
||||||
|
/* */
|
||||||
|
/* OUTPUT */
|
||||||
|
/* */
|
||||||
|
/* LX_SUCCESS Compaction completed */
|
||||||
|
/* LX_ERROR / LX_NO_BLOCKS Error during compaction */
|
||||||
|
/* */
|
||||||
|
/* CALLS */
|
||||||
|
/* */
|
||||||
|
/* _lx_nand_sector_find_in_block Find sector in a block */
|
||||||
|
/* _lx_nand_flash_block_allocate Allocate a free block */
|
||||||
|
/* _lx_nand_flash_block_status_set Set block status */
|
||||||
|
/* _lx_nand_flash_block_mapping_set Update logical-to-physical map*/
|
||||||
|
/* _lx_nand_flash_mapped_block_list_remove Remove from mapped list */
|
||||||
|
/* _lx_nand_flash_mapped_block_list_add Add to mapped list */
|
||||||
|
/* _lx_nand_flash_free_block_list_add Return block to free list */
|
||||||
|
/* _lx_nand_flash_driver_block_erase Erase a block */
|
||||||
|
/* _lx_nand_flash_erase_count_set Record new erase count */
|
||||||
|
/* _lx_nand_flash_block_data_move Wear-level an over-erased blk */
|
||||||
|
/* _lx_nand_flash_system_error Internal system error handler */
|
||||||
|
/* lx_nand_flash_driver_pages_copy Copy a page between blocks */
|
||||||
|
/* */
|
||||||
|
/* CALLED BY */
|
||||||
|
/* */
|
||||||
|
/* _lx_nand_flash_sector_release Lazy release pre-compact */
|
||||||
|
/* _lx_nand_flash_sector_write Pre-compact before block copy */
|
||||||
|
/* _lx_nand_flash_block_data_move Wear-level with pending compact*/
|
||||||
|
/* _lx_nand_flash_defragment Explicit defragment pass */
|
||||||
|
/* _lx_nand_flash_block_allocate Emergency compaction */
|
||||||
|
/* */
|
||||||
|
/**************************************************************************/
|
||||||
|
UINT _lx_nand_flash_logical_group_compact(LX_NAND_FLASH *nand_flash, ULONG logical_group)
|
||||||
|
{
|
||||||
|
|
||||||
|
UINT status;
|
||||||
|
ULONG tombstone_block;
|
||||||
|
ULONG compaction_block;
|
||||||
|
ULONG dest_block;
|
||||||
|
USHORT tombstone_block_status;
|
||||||
|
USHORT compaction_block_status;
|
||||||
|
USHORT dest_block_status;
|
||||||
|
ULONG sector;
|
||||||
|
ULONG base_sector;
|
||||||
|
LONG source_page;
|
||||||
|
ULONG dest_page;
|
||||||
|
ULONG sector_kind;
|
||||||
|
UINT find_status;
|
||||||
|
|
||||||
|
|
||||||
|
/* Retrieve the two source blocks. */
|
||||||
|
tombstone_block = nand_flash -> lx_nand_flash_block_mapping_table[logical_group];
|
||||||
|
compaction_block = nand_flash -> lx_nand_flash_block_compaction_table[logical_group];
|
||||||
|
tombstone_block_status = nand_flash -> lx_nand_flash_block_status_table[tombstone_block];
|
||||||
|
compaction_block_status = nand_flash -> lx_nand_flash_block_status_table[compaction_block];
|
||||||
|
|
||||||
|
/* Allocate a fresh destination block. */
|
||||||
|
status = _lx_nand_flash_block_allocate(nand_flash, &dest_block);
|
||||||
|
if (status != LX_SUCCESS)
|
||||||
|
{
|
||||||
|
return(status);
|
||||||
|
}
|
||||||
|
|
||||||
|
dest_block_status = LX_NAND_BLOCK_STATUS_ALLOCATED;
|
||||||
|
dest_page = 0;
|
||||||
|
base_sector = logical_group * nand_flash -> lx_nand_flash_pages_per_block;
|
||||||
|
|
||||||
|
/* Merge loop: iterate every sector in the logical group.
|
||||||
|
The tombstone block (current mapping) supersedes the compaction block. */
|
||||||
|
for (sector = base_sector;
|
||||||
|
sector < base_sector + nand_flash -> lx_nand_flash_pages_per_block;
|
||||||
|
sector++)
|
||||||
|
{
|
||||||
|
|
||||||
|
source_page = -1L;
|
||||||
|
sector_kind = 0;
|
||||||
|
|
||||||
|
/* Search the tombstone block first (newer data). */
|
||||||
|
find_status = _lx_nand_sector_find_in_block(nand_flash, tombstone_block,
|
||||||
|
tombstone_block_status, sector,
|
||||||
|
&source_page, §or_kind);
|
||||||
|
if (find_status == LX_ERROR)
|
||||||
|
{
|
||||||
|
return(LX_ERROR);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (find_status == LX_NO_BLOCKS)
|
||||||
|
{
|
||||||
|
|
||||||
|
/* Not in tombstone block; try the compaction block (older data). */
|
||||||
|
find_status = _lx_nand_sector_find_in_block(nand_flash, compaction_block,
|
||||||
|
compaction_block_status, sector,
|
||||||
|
&source_page, §or_kind);
|
||||||
|
if (find_status == LX_ERROR)
|
||||||
|
{
|
||||||
|
return(LX_ERROR);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((find_status == LX_SUCCESS) && (sector_kind == LX_NAND_PAGE_TYPE_USER_DATA))
|
||||||
|
{
|
||||||
|
|
||||||
|
/* Copy live data from compaction block to destination. */
|
||||||
|
#ifdef LX_NAND_ENABLE_CONTROL_BLOCK_FOR_DRIVER_INTERFACE
|
||||||
|
status = (nand_flash -> lx_nand_flash_driver_pages_copy)(nand_flash, compaction_block, (ULONG)source_page, dest_block, dest_page, 1, nand_flash -> lx_nand_flash_page_buffer);
|
||||||
|
#else
|
||||||
|
status = (nand_flash -> lx_nand_flash_driver_pages_copy)(compaction_block, (ULONG)source_page, dest_block, dest_page, 1, nand_flash -> lx_nand_flash_page_buffer);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
if (status)
|
||||||
|
{
|
||||||
|
_lx_nand_flash_system_error(nand_flash, status, dest_block, 0);
|
||||||
|
return(LX_ERROR);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (dest_page != (sector % nand_flash -> lx_nand_flash_pages_per_block))
|
||||||
|
{
|
||||||
|
dest_block_status |= LX_NAND_BLOCK_STATUS_NON_SEQUENTIAL;
|
||||||
|
}
|
||||||
|
|
||||||
|
dest_page++;
|
||||||
|
}
|
||||||
|
/* RELEASED or NOT_FOUND in compaction block: sector no longer exists, skip. */
|
||||||
|
}
|
||||||
|
else if ((find_status == LX_SUCCESS) && (sector_kind == LX_NAND_PAGE_TYPE_USER_DATA))
|
||||||
|
{
|
||||||
|
|
||||||
|
/* Copy live data from tombstone block to destination. */
|
||||||
|
#ifdef LX_NAND_ENABLE_CONTROL_BLOCK_FOR_DRIVER_INTERFACE
|
||||||
|
status = (nand_flash -> lx_nand_flash_driver_pages_copy)(nand_flash, tombstone_block, (ULONG)source_page, dest_block, dest_page, 1, nand_flash -> lx_nand_flash_page_buffer);
|
||||||
|
#else
|
||||||
|
status = (nand_flash -> lx_nand_flash_driver_pages_copy)(tombstone_block, (ULONG)source_page, dest_block, dest_page, 1, nand_flash -> lx_nand_flash_page_buffer);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
if (status)
|
||||||
|
{
|
||||||
|
_lx_nand_flash_system_error(nand_flash, status, dest_block, 0);
|
||||||
|
return(LX_ERROR);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (dest_page != (sector % nand_flash -> lx_nand_flash_pages_per_block))
|
||||||
|
{
|
||||||
|
dest_block_status |= LX_NAND_BLOCK_STATUS_NON_SEQUENTIAL;
|
||||||
|
}
|
||||||
|
|
||||||
|
dest_page++;
|
||||||
|
}
|
||||||
|
/* RELEASED (tombstone found in tombstone block): sector is gone, skip. */
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Encode page count into dest_block_status. */
|
||||||
|
dest_block_status = (USHORT)((dest_block_status & ~(USHORT)LX_NAND_BLOCK_STATUS_PAGE_NUMBER_MASK) |
|
||||||
|
(dest_page & LX_NAND_BLOCK_STATUS_PAGE_NUMBER_MASK));
|
||||||
|
|
||||||
|
/* Commit destination block or discard it if the entire group was released. */
|
||||||
|
if (dest_page == 0)
|
||||||
|
{
|
||||||
|
|
||||||
|
/* All sectors released; destination block is unused. */
|
||||||
|
status = _lx_nand_flash_block_status_set(nand_flash, dest_block, LX_NAND_BLOCK_STATUS_FREE);
|
||||||
|
if (status)
|
||||||
|
{
|
||||||
|
_lx_nand_flash_system_error(nand_flash, status, dest_block, 0);
|
||||||
|
return(LX_ERROR);
|
||||||
|
}
|
||||||
|
_lx_nand_flash_free_block_list_add(nand_flash, dest_block);
|
||||||
|
dest_block = (ULONG)LX_NAND_BLOCK_UNMAPPED;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
status = _lx_nand_flash_block_status_set(nand_flash, dest_block, dest_block_status);
|
||||||
|
if (status)
|
||||||
|
{
|
||||||
|
_lx_nand_flash_system_error(nand_flash, status, dest_block, 0);
|
||||||
|
return(LX_ERROR);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Remove tombstone block from the mapped list. */
|
||||||
|
_lx_nand_flash_mapped_block_list_remove(nand_flash, logical_group);
|
||||||
|
|
||||||
|
/* Persist the new mapping (or UNMAPPED if all sectors were released). */
|
||||||
|
_lx_nand_flash_block_mapping_set(nand_flash, logical_group * nand_flash -> lx_nand_flash_pages_per_block, dest_block);
|
||||||
|
|
||||||
|
/* Clear the in-RAM compaction table entry. */
|
||||||
|
nand_flash -> lx_nand_flash_block_compaction_table[logical_group] = (USHORT)LX_NAND_BLOCK_UNMAPPED;
|
||||||
|
|
||||||
|
/* Add destination block to the mapped list if it holds data. */
|
||||||
|
if (dest_block != (ULONG)LX_NAND_BLOCK_UNMAPPED)
|
||||||
|
{
|
||||||
|
_lx_nand_flash_mapped_block_list_add(nand_flash, logical_group);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ---- Erase tombstone block ---- */
|
||||||
|
status = _lx_nand_flash_driver_block_erase(nand_flash, tombstone_block,
|
||||||
|
nand_flash -> lx_nand_flash_base_erase_count +
|
||||||
|
nand_flash -> lx_nand_flash_erase_count_table[tombstone_block] + 1);
|
||||||
|
if (status)
|
||||||
|
{
|
||||||
|
_lx_nand_flash_system_error(nand_flash, status, tombstone_block, 0);
|
||||||
|
return(LX_ERROR);
|
||||||
|
}
|
||||||
|
|
||||||
|
status = _lx_nand_flash_erase_count_set(nand_flash, tombstone_block,
|
||||||
|
(UCHAR)(nand_flash -> lx_nand_flash_erase_count_table[tombstone_block] + 1));
|
||||||
|
if (status)
|
||||||
|
{
|
||||||
|
_lx_nand_flash_system_error(nand_flash, status, tombstone_block, 0);
|
||||||
|
return(LX_ERROR);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (nand_flash -> lx_nand_flash_erase_count_table[tombstone_block] > LX_NAND_FLASH_MAX_ERASE_COUNT_DELTA)
|
||||||
|
{
|
||||||
|
status = _lx_nand_flash_block_data_move(nand_flash, tombstone_block);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
status = _lx_nand_flash_block_status_set(nand_flash, tombstone_block, LX_NAND_BLOCK_STATUS_FREE);
|
||||||
|
if (status)
|
||||||
|
{
|
||||||
|
_lx_nand_flash_system_error(nand_flash, status, tombstone_block, 0);
|
||||||
|
return(LX_ERROR);
|
||||||
|
}
|
||||||
|
status = _lx_nand_flash_free_block_list_add(nand_flash, tombstone_block);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (status)
|
||||||
|
{
|
||||||
|
return(LX_ERROR);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ---- Clear COMPACTION_PENDING flag on the old block, then erase it ---- */
|
||||||
|
status = _lx_nand_flash_block_status_set(nand_flash, compaction_block,
|
||||||
|
(USHORT)(nand_flash -> lx_nand_flash_block_status_table[compaction_block] &
|
||||||
|
~(USHORT)LX_NAND_BLOCK_STATUS_COMPACTION_PENDING));
|
||||||
|
if (status)
|
||||||
|
{
|
||||||
|
_lx_nand_flash_system_error(nand_flash, status, compaction_block, 0);
|
||||||
|
return(LX_ERROR);
|
||||||
|
}
|
||||||
|
|
||||||
|
status = _lx_nand_flash_driver_block_erase(nand_flash, compaction_block,
|
||||||
|
nand_flash -> lx_nand_flash_base_erase_count +
|
||||||
|
nand_flash -> lx_nand_flash_erase_count_table[compaction_block] + 1);
|
||||||
|
if (status)
|
||||||
|
{
|
||||||
|
_lx_nand_flash_system_error(nand_flash, status, compaction_block, 0);
|
||||||
|
return(LX_ERROR);
|
||||||
|
}
|
||||||
|
|
||||||
|
status = _lx_nand_flash_erase_count_set(nand_flash, compaction_block,
|
||||||
|
(UCHAR)(nand_flash -> lx_nand_flash_erase_count_table[compaction_block] + 1));
|
||||||
|
if (status)
|
||||||
|
{
|
||||||
|
_lx_nand_flash_system_error(nand_flash, status, compaction_block, 0);
|
||||||
|
return(LX_ERROR);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (nand_flash -> lx_nand_flash_erase_count_table[compaction_block] > LX_NAND_FLASH_MAX_ERASE_COUNT_DELTA)
|
||||||
|
{
|
||||||
|
status = _lx_nand_flash_block_data_move(nand_flash, compaction_block);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
status = _lx_nand_flash_block_status_set(nand_flash, compaction_block, LX_NAND_BLOCK_STATUS_FREE);
|
||||||
|
if (status)
|
||||||
|
{
|
||||||
|
_lx_nand_flash_system_error(nand_flash, status, compaction_block, 0);
|
||||||
|
return(LX_ERROR);
|
||||||
|
}
|
||||||
|
status = _lx_nand_flash_free_block_list_add(nand_flash, compaction_block);
|
||||||
|
}
|
||||||
|
|
||||||
|
return(status);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif /* LX_NAND_FLASH_ENABLE_LAZY_SECTOR_RELEASE */
|
||||||
@@ -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)
|
||||||
|
|||||||
@@ -1,19 +1,20 @@
|
|||||||
/**************************************************************************/
|
/***************************************************************************
|
||||||
/* */
|
* 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
|
||||||
/**************************************************************************/
|
**************************************************************************/
|
||||||
|
|
||||||
|
// Some portions generated by Copilot (Sonnet 4.6).
|
||||||
|
|
||||||
/**************************************************************************/
|
/**************************************************************************/
|
||||||
/**************************************************************************/
|
/**************************************************************************/
|
||||||
/** */
|
/** */
|
||||||
/** LevelX Component */
|
/** LevelX Component */
|
||||||
/** */
|
/** */
|
||||||
/** NAND Flash */
|
/** NAND Flash */
|
||||||
/** */
|
/** */
|
||||||
@@ -35,45 +36,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 +120,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;
|
||||||
|
|
||||||
@@ -187,6 +182,48 @@ UINT buffer_size;
|
|||||||
return(LX_NO_MEMORY);
|
return(LX_NO_MEMORY);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef LX_NAND_FLASH_ENABLE_LAZY_SECTOR_RELEASE
|
||||||
|
{
|
||||||
|
|
||||||
|
ULONG i;
|
||||||
|
ULONG compaction_table_entries;
|
||||||
|
|
||||||
|
/* Set memory size for block compaction table. Same element type as block_mapping_table. */
|
||||||
|
buffer_size = nand_flash -> lx_nand_flash_total_blocks * sizeof(*nand_flash -> lx_nand_flash_block_compaction_table);
|
||||||
|
|
||||||
|
/* Make sure the size is at least one page size. */
|
||||||
|
if (buffer_size < nand_flash -> lx_nand_flash_bytes_per_page)
|
||||||
|
{
|
||||||
|
buffer_size = nand_flash -> lx_nand_flash_bytes_per_page;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Assign memory for block compaction table. */
|
||||||
|
nand_flash -> lx_nand_flash_block_compaction_table = (USHORT*)(((UCHAR*)memory_ptr) + memory_offset);
|
||||||
|
|
||||||
|
/* Update block compaction table size. */
|
||||||
|
nand_flash -> lx_nand_flash_block_compaction_table_size = buffer_size;
|
||||||
|
|
||||||
|
/* Update memory offset. */
|
||||||
|
memory_offset += buffer_size;
|
||||||
|
|
||||||
|
/* Check if there is enough memory. */
|
||||||
|
if (memory_offset > memory_size)
|
||||||
|
{
|
||||||
|
|
||||||
|
/* No enough memory, return error. */
|
||||||
|
return(LX_NO_MEMORY);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Initialize all compaction table entries to unmapped. (LX_MEMSET zero-fills the buffer
|
||||||
|
above, but LX_NAND_BLOCK_UNMAPPED is 0xFFFF, so explicit initialisation is required.) */
|
||||||
|
compaction_table_entries = buffer_size / sizeof(*nand_flash -> lx_nand_flash_block_compaction_table);
|
||||||
|
for (i = 0; i < compaction_table_entries; i++)
|
||||||
|
{
|
||||||
|
nand_flash -> lx_nand_flash_block_compaction_table[i] = (USHORT)LX_NAND_BLOCK_UNMAPPED;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
/* Assign memory for page buffer. */
|
/* Assign memory for page buffer. */
|
||||||
nand_flash -> lx_nand_flash_page_buffer = ((UCHAR*)memory_ptr) + memory_offset;
|
nand_flash -> lx_nand_flash_page_buffer = ((UCHAR*)memory_ptr) + memory_offset;
|
||||||
|
|
||||||
|
|||||||
@@ -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)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -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);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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
@@ -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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,682 @@
|
|||||||
|
/***************************************************************************
|
||||||
|
* 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
|
||||||
|
**************************************************************************/
|
||||||
|
|
||||||
|
// Some portions generated by Copilot (Sonnet 4.6).
|
||||||
|
|
||||||
|
/**************************************************************************/
|
||||||
|
/**************************************************************************/
|
||||||
|
/** */
|
||||||
|
/** 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_NAND_FLASH_ENABLE_LAZY_SECTOR_RELEASE
|
||||||
|
{
|
||||||
|
|
||||||
|
ULONG blk;
|
||||||
|
ULONG lg;
|
||||||
|
USHORT blk_status;
|
||||||
|
|
||||||
|
/* Phase 1: Rebuild compaction table and recover from mid-release crashes.
|
||||||
|
Scan all blocks for COMPACTION_PENDING. */
|
||||||
|
for (blk = 0; blk < nand_flash -> lx_nand_flash_total_blocks; blk++)
|
||||||
|
{
|
||||||
|
|
||||||
|
blk_status = nand_flash -> lx_nand_flash_block_status_table[blk];
|
||||||
|
|
||||||
|
/* FREE (0xFFFF) and BAD (0xFF00) both have COMPACTION_PENDING bit set; skip them. */
|
||||||
|
if ((blk_status == LX_NAND_BLOCK_STATUS_FREE) || (blk_status == LX_NAND_BLOCK_STATUS_BAD))
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (blk_status & LX_NAND_BLOCK_STATUS_COMPACTION_PENDING)
|
||||||
|
{
|
||||||
|
|
||||||
|
/* Check if any logical group still maps to this physical block.
|
||||||
|
If so, the mapping update didn't happen — abort the lazy release. */
|
||||||
|
lg = nand_flash -> lx_nand_flash_total_blocks;
|
||||||
|
{
|
||||||
|
ULONG search_lg;
|
||||||
|
for (search_lg = 0; search_lg < nand_flash -> lx_nand_flash_total_blocks; search_lg++)
|
||||||
|
{
|
||||||
|
if (nand_flash -> lx_nand_flash_block_mapping_table[search_lg] == (USHORT)blk)
|
||||||
|
{
|
||||||
|
lg = search_lg;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (lg != nand_flash -> lx_nand_flash_total_blocks)
|
||||||
|
{
|
||||||
|
|
||||||
|
/* Scenario A: crash after COMPACTION_PENDING set, before mapping updated.
|
||||||
|
Clear COMPACTION_PENDING to restore the block to its normal state. */
|
||||||
|
blk_status = (USHORT)(blk_status & (USHORT)(~LX_NAND_BLOCK_STATUS_COMPACTION_PENDING));
|
||||||
|
(void)_lx_nand_flash_block_status_set(nand_flash, blk, blk_status);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
|
||||||
|
/* Scenario B: deferred compaction — scan block pages to find the LG. */
|
||||||
|
ULONG page;
|
||||||
|
ULONG spare_word;
|
||||||
|
ULONG found_lg;
|
||||||
|
UCHAR *spare_ptr;
|
||||||
|
|
||||||
|
spare_ptr = (UCHAR*)nand_flash -> lx_nand_flash_page_buffer;
|
||||||
|
found_lg = nand_flash -> lx_nand_flash_total_blocks;
|
||||||
|
|
||||||
|
for (page = 0; page < nand_flash -> lx_nand_flash_pages_per_block; page++)
|
||||||
|
{
|
||||||
|
|
||||||
|
#ifdef LX_NAND_ENABLE_CONTROL_BLOCK_FOR_DRIVER_INTERFACE
|
||||||
|
status = (nand_flash -> lx_nand_flash_driver_pages_read)(nand_flash, blk, page, (UCHAR*)NULL, spare_ptr, 1);
|
||||||
|
#else
|
||||||
|
status = (nand_flash -> lx_nand_flash_driver_pages_read)(blk, page, (UCHAR*)NULL, spare_ptr, 1);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
if (status)
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
spare_word = LX_UTILITY_LONG_GET(&spare_ptr[nand_flash -> lx_nand_flash_spare_data1_offset]);
|
||||||
|
|
||||||
|
if ((spare_word & (~LX_NAND_PAGE_TYPE_USER_DATA_MASK)) == LX_NAND_PAGE_TYPE_USER_DATA)
|
||||||
|
{
|
||||||
|
found_lg = (spare_word & LX_NAND_PAGE_TYPE_USER_DATA_MASK) /
|
||||||
|
nand_flash -> lx_nand_flash_pages_per_block;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((found_lg != nand_flash -> lx_nand_flash_total_blocks) &&
|
||||||
|
(found_lg < nand_flash -> lx_nand_flash_total_blocks))
|
||||||
|
{
|
||||||
|
nand_flash -> lx_nand_flash_block_compaction_table[found_lg] = (USHORT)blk;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Phase 2: Orphan block recovery — erase ALLOCATED blocks not referenced
|
||||||
|
by any mapping entry and not marked COMPACTION_PENDING. */
|
||||||
|
for (blk = 0; blk < nand_flash -> lx_nand_flash_total_blocks; blk++)
|
||||||
|
{
|
||||||
|
|
||||||
|
ULONG found;
|
||||||
|
|
||||||
|
blk_status = nand_flash -> lx_nand_flash_block_status_table[blk];
|
||||||
|
|
||||||
|
if ((blk_status == LX_NAND_BLOCK_STATUS_FREE) || (blk_status == LX_NAND_BLOCK_STATUS_BAD))
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (blk_status & LX_NAND_BLOCK_STATUS_COMPACTION_PENDING)
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!(blk_status & LX_NAND_BLOCK_STATUS_ALLOCATED))
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Search for this block in the mapping table. */
|
||||||
|
found = LX_FALSE;
|
||||||
|
for (lg = 0; lg < nand_flash -> lx_nand_flash_total_blocks; lg++)
|
||||||
|
{
|
||||||
|
if (nand_flash -> lx_nand_flash_block_mapping_table[lg] == (USHORT)blk)
|
||||||
|
{
|
||||||
|
found = LX_TRUE;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!found)
|
||||||
|
{
|
||||||
|
|
||||||
|
/* Orphan block: erase and reclaim. */
|
||||||
|
status = _lx_nand_flash_driver_block_erase(nand_flash, blk,
|
||||||
|
nand_flash -> lx_nand_flash_base_erase_count +
|
||||||
|
nand_flash -> lx_nand_flash_erase_count_table[blk] + 1);
|
||||||
|
|
||||||
|
if (status)
|
||||||
|
{
|
||||||
|
_lx_nand_flash_system_error(nand_flash, status, blk, 0);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
status = _lx_nand_flash_erase_count_set(nand_flash, blk,
|
||||||
|
(UCHAR)(nand_flash -> lx_nand_flash_erase_count_table[blk] + 1));
|
||||||
|
|
||||||
|
if (!status)
|
||||||
|
{
|
||||||
|
(void)_lx_nand_flash_block_status_set(nand_flash, blk, LX_NAND_BLOCK_STATUS_FREE);
|
||||||
|
_lx_nand_flash_free_block_list_add(nand_flash, blk);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
#endif /* LX_NAND_FLASH_ENABLE_LAZY_SECTOR_RELEASE */
|
||||||
|
|
||||||
|
|
||||||
|
#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);
|
||||||
|
}
|
||||||
|
|
||||||
@@ -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);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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);
|
||||||
|
|
||||||
|
|||||||
@@ -1,19 +1,20 @@
|
|||||||
/**************************************************************************/
|
/***************************************************************************
|
||||||
/* */
|
* 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
|
||||||
/**************************************************************************/
|
**************************************************************************/
|
||||||
|
|
||||||
|
// Some portions generated by Copilot (Sonnet 4.6).
|
||||||
|
|
||||||
/**************************************************************************/
|
/**************************************************************************/
|
||||||
/**************************************************************************/
|
/**************************************************************************/
|
||||||
/** */
|
/** */
|
||||||
/** LevelX Component */
|
/** LevelX Component */
|
||||||
/** */
|
/** */
|
||||||
/** NAND Flash */
|
/** NAND Flash */
|
||||||
/** */
|
/** */
|
||||||
@@ -35,49 +36,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 +122,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 +139,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 +158,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. */
|
||||||
@@ -217,18 +232,88 @@ LONG page;
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef LX_NAND_FLASH_ENABLE_LAZY_SECTOR_RELEASE
|
||||||
|
{
|
||||||
|
|
||||||
|
ULONG logical_group;
|
||||||
|
ULONG old_block;
|
||||||
|
|
||||||
|
/* Check the compaction table for a deferred source block that might hold
|
||||||
|
the requested sector. The primary block (tombstone block) was already
|
||||||
|
scanned above; fall back to the old full block here. */
|
||||||
|
logical_group = logical_sector / nand_flash -> lx_nand_flash_pages_per_block;
|
||||||
|
|
||||||
|
if (nand_flash -> lx_nand_flash_block_compaction_table[logical_group] != (USHORT)LX_NAND_BLOCK_UNMAPPED)
|
||||||
|
{
|
||||||
|
|
||||||
|
old_block = nand_flash -> lx_nand_flash_block_compaction_table[logical_group];
|
||||||
|
|
||||||
|
/* Set spare buffer pointer. */
|
||||||
|
spare_buffer_ptr = (UCHAR*)nand_flash -> lx_nand_flash_page_buffer;
|
||||||
|
|
||||||
|
/* The compaction-pending block is always FULL; scan all pages in reverse. */
|
||||||
|
for (page = (LONG)nand_flash -> lx_nand_flash_pages_per_block - 1; page >= 0; page--)
|
||||||
|
{
|
||||||
|
|
||||||
|
#ifdef LX_NAND_ENABLE_CONTROL_BLOCK_FOR_DRIVER_INTERFACE
|
||||||
|
status = (nand_flash -> lx_nand_flash_driver_pages_read)(nand_flash, old_block, (ULONG)page, (UCHAR*)NULL, spare_buffer_ptr, 1);
|
||||||
|
#else
|
||||||
|
status = (nand_flash -> lx_nand_flash_driver_pages_read)(old_block, (ULONG)page, (UCHAR*)NULL, spare_buffer_ptr, 1);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* Check for an error from flash driver. */
|
||||||
|
if (status)
|
||||||
|
{
|
||||||
|
_lx_nand_flash_system_error(nand_flash, status, old_block, 0);
|
||||||
|
#ifdef LX_THREAD_SAFE_ENABLE
|
||||||
|
tx_mutex_put(&nand_flash -> lx_nand_flash_mutex);
|
||||||
|
#endif
|
||||||
|
return(LX_ERROR);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Check if this page matches the requested 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, old_block, (ULONG)page, (UCHAR*)buffer, NULL, 1);
|
||||||
|
#else
|
||||||
|
status = (nand_flash -> lx_nand_flash_driver_pages_read)(old_block, (ULONG)page, (UCHAR*)buffer, NULL, 1);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* Check for an error from flash driver. */
|
||||||
|
if (status)
|
||||||
|
{
|
||||||
|
_lx_nand_flash_system_error(nand_flash, status, old_block, 0);
|
||||||
|
#ifdef LX_THREAD_SAFE_ENABLE
|
||||||
|
tx_mutex_put(&nand_flash -> lx_nand_flash_mutex);
|
||||||
|
#endif
|
||||||
|
return(LX_ERROR);
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifdef LX_THREAD_SAFE_ENABLE
|
||||||
|
tx_mutex_put(&nand_flash -> lx_nand_flash_mutex);
|
||||||
|
#endif
|
||||||
|
return(LX_SUCCESS);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
#endif /* LX_NAND_FLASH_ENABLE_LAZY_SECTOR_RELEASE */
|
||||||
|
|
||||||
/* Sector hasn't been written. Simply fill the destination buffer with ones and return success. */
|
/* Sector hasn't been written. Simply fill the destination buffer with ones and return success. */
|
||||||
|
|
||||||
/* 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;
|
||||||
|
|||||||
@@ -1,19 +1,20 @@
|
|||||||
/**************************************************************************/
|
/***************************************************************************
|
||||||
/* */
|
* 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
|
||||||
/**************************************************************************/
|
**************************************************************************/
|
||||||
|
|
||||||
|
// Some portions generated by Copilot (Sonnet 4.6).
|
||||||
|
|
||||||
/**************************************************************************/
|
/**************************************************************************/
|
||||||
/**************************************************************************/
|
/**************************************************************************/
|
||||||
/** */
|
/** */
|
||||||
/** LevelX Component */
|
/** LevelX Component */
|
||||||
/** */
|
/** */
|
||||||
/** NAND Flash */
|
/** NAND Flash */
|
||||||
/** */
|
/** */
|
||||||
@@ -35,58 +36,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)
|
||||||
@@ -211,6 +206,119 @@ USHORT new_block_status;
|
|||||||
if (block_status & LX_NAND_BLOCK_STATUS_FULL)
|
if (block_status & LX_NAND_BLOCK_STATUS_FULL)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
#ifdef LX_NAND_FLASH_ENABLE_LAZY_SECTOR_RELEASE
|
||||||
|
/* Lazy path: defer the copy+erase when enough free blocks are available.
|
||||||
|
The old block is kept as a compaction source; a new block holds only
|
||||||
|
the tombstone for the released sector. */
|
||||||
|
if (nand_flash -> lx_nand_flash_free_block_list_tail >
|
||||||
|
(ULONG)LX_NAND_FLASH_SECTOR_RELEASE_LAZY_THRESHOLD)
|
||||||
|
{
|
||||||
|
|
||||||
|
/* Allocate a new block for the tombstone. */
|
||||||
|
status = _lx_nand_flash_block_allocate(nand_flash, &new_block);
|
||||||
|
|
||||||
|
/* Check return status. */
|
||||||
|
if (status != LX_SUCCESS)
|
||||||
|
{
|
||||||
|
|
||||||
|
/* Call system error handler. */
|
||||||
|
_lx_nand_flash_system_error(nand_flash, status, new_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);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Set page buffer to all 0xFF (data = erased, sector is released). */
|
||||||
|
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. */
|
||||||
|
spare_buffer_ptr = nand_flash -> lx_nand_flash_page_buffer +
|
||||||
|
nand_flash -> lx_nand_flash_bytes_per_page;
|
||||||
|
|
||||||
|
/* Save metadata block number in spare bytes if space allows. */
|
||||||
|
if (nand_flash -> lx_nand_flash_spare_data2_length >= sizeof(USHORT))
|
||||||
|
{
|
||||||
|
LX_UTILITY_SHORT_SET(&spare_buffer_ptr[nand_flash -> lx_nand_flash_spare_data2_offset],
|
||||||
|
nand_flash -> lx_nand_flash_metadata_block_number);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Set page type to USER_DATA_RELEASED. */
|
||||||
|
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 tombstone page to page 0 of the new block. */
|
||||||
|
#ifdef LX_NAND_ENABLE_CONTROL_BLOCK_FOR_DRIVER_INTERFACE
|
||||||
|
status = (nand_flash -> lx_nand_flash_driver_pages_write)(nand_flash, new_block, 0,
|
||||||
|
(UCHAR*)nand_flash -> lx_nand_flash_page_buffer, spare_buffer_ptr, 1);
|
||||||
|
#else
|
||||||
|
status = (nand_flash -> lx_nand_flash_driver_pages_write)(new_block, 0,
|
||||||
|
(UCHAR*)nand_flash -> lx_nand_flash_page_buffer, spare_buffer_ptr, 1);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* Check for an error from flash driver. */
|
||||||
|
if (status)
|
||||||
|
{
|
||||||
|
_lx_nand_flash_system_error(nand_flash, status, new_block, 0);
|
||||||
|
#ifdef LX_THREAD_SAFE_ENABLE
|
||||||
|
tx_mutex_put(&nand_flash -> lx_nand_flash_mutex);
|
||||||
|
#endif
|
||||||
|
return(LX_ERROR);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Set new block status: allocated, non-sequential, 1 page written. */
|
||||||
|
new_block_status = (USHORT)(LX_NAND_BLOCK_STATUS_ALLOCATED |
|
||||||
|
LX_NAND_BLOCK_STATUS_NON_SEQUENTIAL | 1u);
|
||||||
|
status = _lx_nand_flash_block_status_set(nand_flash, new_block, new_block_status);
|
||||||
|
if (status)
|
||||||
|
{
|
||||||
|
_lx_nand_flash_system_error(nand_flash, status, new_block, 0);
|
||||||
|
#ifdef LX_THREAD_SAFE_ENABLE
|
||||||
|
tx_mutex_put(&nand_flash -> lx_nand_flash_mutex);
|
||||||
|
#endif
|
||||||
|
return(LX_ERROR);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Mark old block as compaction-pending (persisted to flash).
|
||||||
|
Write order: tombstone written → new_block status set →
|
||||||
|
COMPACTION_PENDING set → mapping updated.
|
||||||
|
This ordering ensures safe crash recovery at open time. */
|
||||||
|
status = _lx_nand_flash_block_status_set(nand_flash, block,
|
||||||
|
(USHORT)(block_status | LX_NAND_BLOCK_STATUS_COMPACTION_PENDING));
|
||||||
|
if (status)
|
||||||
|
{
|
||||||
|
_lx_nand_flash_system_error(nand_flash, status, block, 0);
|
||||||
|
#ifdef LX_THREAD_SAFE_ENABLE
|
||||||
|
tx_mutex_put(&nand_flash -> lx_nand_flash_mutex);
|
||||||
|
#endif
|
||||||
|
return(LX_ERROR);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Remove old mapping before updating to new block. */
|
||||||
|
_lx_nand_flash_mapped_block_list_remove(nand_flash,
|
||||||
|
logical_sector / nand_flash -> lx_nand_flash_pages_per_block);
|
||||||
|
|
||||||
|
/* Update logical-to-physical mapping to the new tombstone block. */
|
||||||
|
_lx_nand_flash_block_mapping_set(nand_flash, logical_sector, new_block);
|
||||||
|
|
||||||
|
/* Record the old block as the compaction source (RAM only; rebuilt at open). */
|
||||||
|
nand_flash -> lx_nand_flash_block_compaction_table[logical_sector / nand_flash -> lx_nand_flash_pages_per_block] = (USHORT)block;
|
||||||
|
|
||||||
|
/* Add new tombstone block to the mapped list. */
|
||||||
|
_lx_nand_flash_mapped_block_list_add(nand_flash,
|
||||||
|
logical_sector / nand_flash -> lx_nand_flash_pages_per_block);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
#endif /* LX_NAND_FLASH_ENABLE_LAZY_SECTOR_RELEASE */
|
||||||
|
{
|
||||||
|
|
||||||
|
/* Eager path (existing): allocate a new block and copy + erase immediately. */
|
||||||
|
|
||||||
/* Allocate a new block. */
|
/* Allocate a new block. */
|
||||||
status = _lx_nand_flash_block_allocate(nand_flash, &new_block);
|
status = _lx_nand_flash_block_allocate(nand_flash, &new_block);
|
||||||
|
|
||||||
@@ -389,17 +497,18 @@ 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);
|
||||||
}
|
}
|
||||||
|
} /* end eager path else block */
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
||||||
/* 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 +522,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);
|
||||||
|
|||||||
@@ -1,19 +1,20 @@
|
|||||||
/**************************************************************************/
|
/***************************************************************************
|
||||||
/* */
|
* 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
|
||||||
/**************************************************************************/
|
**************************************************************************/
|
||||||
|
|
||||||
|
// Some portions generated by Copilot (Sonnet 4.6).
|
||||||
|
|
||||||
/**************************************************************************/
|
/**************************************************************************/
|
||||||
/**************************************************************************/
|
/**************************************************************************/
|
||||||
/** */
|
/** */
|
||||||
/** LevelX Component */
|
/** LevelX Component */
|
||||||
/** */
|
/** */
|
||||||
/** NAND Flash */
|
/** NAND Flash */
|
||||||
/** */
|
/** */
|
||||||
@@ -35,60 +36,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 +110,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)
|
||||||
{
|
{
|
||||||
@@ -137,6 +132,42 @@ UINT copy_block = LX_FALSE;
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef LX_NAND_FLASH_ENABLE_LAZY_SECTOR_RELEASE
|
||||||
|
/* If the block is full and has a pending compaction source, compact it now
|
||||||
|
before writing so the new data merges correctly with a single source block. */
|
||||||
|
if ((block != LX_NAND_BLOCK_UNMAPPED) && (block_status & LX_NAND_BLOCK_STATUS_FULL) &&
|
||||||
|
(nand_flash -> lx_nand_flash_block_compaction_table[logical_sector / nand_flash -> lx_nand_flash_pages_per_block] != (USHORT)LX_NAND_BLOCK_UNMAPPED))
|
||||||
|
{
|
||||||
|
|
||||||
|
status = _lx_nand_flash_logical_group_compact(nand_flash,
|
||||||
|
logical_sector / nand_flash -> lx_nand_flash_pages_per_block);
|
||||||
|
|
||||||
|
if (status)
|
||||||
|
{
|
||||||
|
_lx_nand_flash_system_error(nand_flash, status, block, 0);
|
||||||
|
#ifdef LX_THREAD_SAFE_ENABLE
|
||||||
|
tx_mutex_put(&nand_flash -> lx_nand_flash_mutex);
|
||||||
|
#endif
|
||||||
|
return(LX_ERROR);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Refresh block and block_status after compaction. */
|
||||||
|
status = _lx_nand_flash_block_find(nand_flash, logical_sector, &block, &block_status);
|
||||||
|
|
||||||
|
if (status != LX_SUCCESS)
|
||||||
|
{
|
||||||
|
|
||||||
|
if (status != LX_NAND_ERROR_CORRECTED)
|
||||||
|
{
|
||||||
|
#ifdef LX_THREAD_SAFE_ENABLE
|
||||||
|
tx_mutex_put(&nand_flash -> lx_nand_flash_mutex);
|
||||||
|
#endif
|
||||||
|
return(LX_ERROR);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif /* LX_NAND_FLASH_ENABLE_LAZY_SECTOR_RELEASE */
|
||||||
|
|
||||||
/* Check if block is unmapped or block is full. */
|
/* Check if block is unmapped or block is full. */
|
||||||
if (block == LX_NAND_BLOCK_UNMAPPED || block_status & LX_NAND_BLOCK_STATUS_FULL)
|
if (block == LX_NAND_BLOCK_UNMAPPED || block_status & LX_NAND_BLOCK_STATUS_FULL)
|
||||||
{
|
{
|
||||||
@@ -196,7 +227,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 +254,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 +268,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 +279,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;
|
||||||
|
|
||||||
|
|||||||
@@ -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)
|
||||||
|
|||||||
@@ -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)
|
||||||
|
|||||||
@@ -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)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -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++;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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);
|
||||||
|
|||||||
@@ -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);
|
||||||
|
|
||||||
|
|||||||
@@ -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
|
||||||
|
|
||||||
|
|||||||
@@ -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);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -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);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -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
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -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
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -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
|
||||||
|
|
||||||
|
|||||||
@@ -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);
|
||||||
|
}
|
||||||
@@ -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);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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
@@ -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), §or_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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -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), §or_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);
|
||||||
|
}
|
||||||
|
|
||||||
@@ -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;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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, §or_address);
|
_lx_nor_flash_logical_sector_find(nor_flash, logical_sector, LX_FALSE, &mapping_address, §or_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, §or_address);
|
_lx_nor_flash_physical_sector_allocate(nor_flash, logical_sector, &mapping_address, §or_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. */
|
||||||
|
|||||||
@@ -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, §or_address);
|
_lx_nor_flash_logical_sector_find(nor_flash, logical_sector, LX_FALSE, &mapping_address, §or_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. */
|
||||||
|
|||||||
@@ -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;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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);
|
||||||
|
|||||||
@@ -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.
|
||||||
@@ -1,4 +1,15 @@
|
|||||||
/* This is a small demo of the high-performance FileX FAT file system with LevelX
|
/***************************************************************************/
|
||||||
|
/* Copyright (c) 2024 Microsoft Corporation */
|
||||||
|
/* Copyright (c) 2026 Eclipse ThreadX contributors */
|
||||||
|
/* */
|
||||||
|
/* This program and the accompanying materials are made available under */
|
||||||
|
/* the terms of the MIT License which is available at */
|
||||||
|
/* https://opensource.org/licenses/MIT. */
|
||||||
|
/* */
|
||||||
|
/* SPDX-License-Identifier: MIT */
|
||||||
|
/***************************************************************************/
|
||||||
|
|
||||||
|
/* This is a small demo of the high-performance FileX FAT file system with LevelX
|
||||||
and the NAND simulated driver. */
|
and the NAND simulated driver. */
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
@@ -9,7 +20,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 +34,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 +65,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 +87,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 +108,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 +230,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 +238,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 +254,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;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,15 @@
|
|||||||
/* This is a small demo of the high-performance FileX FAT file system with LevelX
|
/***************************************************************************/
|
||||||
|
/* Copyright (c) 2024 Microsoft Corporation */
|
||||||
|
/* Copyright (c) 2026 Eclipse ThreadX contributors */
|
||||||
|
/* */
|
||||||
|
/* This program and the accompanying materials are made available under */
|
||||||
|
/* the terms of the MIT License which is available at */
|
||||||
|
/* https://opensource.org/licenses/MIT. */
|
||||||
|
/* */
|
||||||
|
/* SPDX-License-Identifier: MIT */
|
||||||
|
/***************************************************************************/
|
||||||
|
|
||||||
|
/* This is a small demo of the high-performance FileX FAT file system with LevelX
|
||||||
and the NOR simulated driver. */
|
and the NOR simulated driver. */
|
||||||
|
|
||||||
#include "fx_api.h"
|
#include "fx_api.h"
|
||||||
@@ -8,7 +19,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 +33,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 +64,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 +85,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 +107,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 +229,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 +237,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);
|
||||||
|
|
||||||
|
|||||||
Executable
+13
@@ -0,0 +1,13 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
##############################################################################
|
||||||
|
# Copyright (c) 2024 Microsoft Corporation
|
||||||
|
# Copyright (c) 2026 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
|
||||||
|
##############################################################################
|
||||||
|
|
||||||
|
$(dirname `realpath $0`)/../test/cmake/run.sh build all
|
||||||
Executable
+39
@@ -0,0 +1,39 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
##############################################################################
|
||||||
|
# Copyright (c) 2024 Microsoft Corporation
|
||||||
|
# Copyright (c) 2026 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
|
||||||
|
##############################################################################
|
||||||
|
|
||||||
|
#
|
||||||
|
|
||||||
|
# Remove large folder
|
||||||
|
rm -rf /opt/hostedtoolcache
|
||||||
|
|
||||||
|
# Install necessary softwares for Ubuntu.
|
||||||
|
|
||||||
|
sudo apt-get update
|
||||||
|
sudo apt-get install -y \
|
||||||
|
gcc-multilib \
|
||||||
|
git \
|
||||||
|
g++ \
|
||||||
|
python3-pip \
|
||||||
|
ninja-build \
|
||||||
|
unifdef \
|
||||||
|
p7zip-full \
|
||||||
|
tofrodos \
|
||||||
|
gawk \
|
||||||
|
software-properties-common
|
||||||
|
|
||||||
|
wget -O - https://apt.kitware.com/keys/kitware-archive-latest.asc 2>/dev/null | sudo apt-key add -
|
||||||
|
CODENAME=$(lsb_release -c | cut -f2 -d':' | sed 's/\t//')
|
||||||
|
apt-add-repository "deb https://apt.kitware.com/ubuntu/ $CODENAME main"
|
||||||
|
|
||||||
|
python3 -m pip install --upgrade pip
|
||||||
|
pip3 install gcovr==4.1
|
||||||
|
pip install --upgrade cmake
|
||||||
Executable
+132
@@ -0,0 +1,132 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
# prepare_release.sh
|
||||||
|
# Prepares a LevelX release by updating version constants.
|
||||||
|
#
|
||||||
|
# Usage: prepare_release.sh <version>
|
||||||
|
# Example: prepare_release.sh 6.5.1.202602
|
||||||
|
# Hotfix: prepare_release.sh 6.5.1.202602a
|
||||||
|
#
|
||||||
|
# This script:
|
||||||
|
# 1. Creates branch release-<version>-preparation from dev
|
||||||
|
# 2. Updates version constants in common/inc/lx_api.h
|
||||||
|
# (commit: "Updated version number constants")
|
||||||
|
# (No port-specific version strings in this repository)
|
||||||
|
#
|
||||||
|
# Copyright (C) 2026 Eclipse ThreadX contributors
|
||||||
|
# SPDX-License-Identifier: MIT
|
||||||
|
|
||||||
|
set -eu
|
||||||
|
|
||||||
|
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
|
||||||
|
REPO_ROOT="$(cd "${SCRIPT_DIR}/.." && pwd)"
|
||||||
|
|
||||||
|
API_HEADER="${REPO_ROOT}/common/inc/lx_api.h"
|
||||||
|
|
||||||
|
# --------------------------------------------------------------------------
|
||||||
|
# Argument validation
|
||||||
|
# --------------------------------------------------------------------------
|
||||||
|
if [ "$#" -ne 1 ]; then
|
||||||
|
printf "Usage: %s <version>\n" "$(basename "$0")" >&2
|
||||||
|
printf "Example: %s 6.5.1.202602\n" "$(basename "$0")" >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
VERSION="$1"
|
||||||
|
|
||||||
|
if ! printf "%s" "${VERSION}" | grep -qE '^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+[a-z]?$'; then
|
||||||
|
printf "Error: Invalid version format '%s'.\n" "${VERSION}" >&2
|
||||||
|
printf "Expected: MAJOR.MINOR.PATCH.BUILD[hotfix_letter]\n" >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# --------------------------------------------------------------------------
|
||||||
|
# Parse version components
|
||||||
|
# --------------------------------------------------------------------------
|
||||||
|
MAJOR=$(printf "%s" "${VERSION}" | cut -d. -f1)
|
||||||
|
MINOR=$(printf "%s" "${VERSION}" | cut -d. -f2)
|
||||||
|
PATCH=$(printf "%s" "${VERSION}" | cut -d. -f3)
|
||||||
|
BUILD_AND_HOTFIX=$(printf "%s" "${VERSION}" | cut -d. -f4)
|
||||||
|
BUILD=$(printf "%s" "${BUILD_AND_HOTFIX}" | sed -E 's/[a-z]+$//')
|
||||||
|
HOTFIX=$(printf "%s" "${BUILD_AND_HOTFIX}" | sed -E 's/^[0-9]+//')
|
||||||
|
|
||||||
|
if [ -z "${HOTFIX}" ]; then
|
||||||
|
HOTFIX_DEFINE="' '"
|
||||||
|
else
|
||||||
|
HOTFIX_DEFINE="'${HOTFIX}'"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# --------------------------------------------------------------------------
|
||||||
|
# Read and display current version
|
||||||
|
# --------------------------------------------------------------------------
|
||||||
|
CURR_MAJOR=$(grep -E "^#define LEVELX_MAJOR_VERSION" "${API_HEADER}" | awk '{print $NF}')
|
||||||
|
CURR_MINOR=$(grep -E "^#define LEVELX_MINOR_VERSION" "${API_HEADER}" | awk '{print $NF}')
|
||||||
|
CURR_PATCH=$(grep -E "^#define LEVELX_PATCH_VERSION" "${API_HEADER}" | awk '{print $NF}')
|
||||||
|
CURR_BUILD=$(grep -E "^#define LEVELX_BUILD_VERSION" "${API_HEADER}" | awk '{print $NF}')
|
||||||
|
CURR_HOTFIX=$(grep -E "^#define LEVELX_HOTFIX_VERSION" "${API_HEADER}" | \
|
||||||
|
sed -E "s/.*'([^']*)'.*/\1/" | tr -d ' ')
|
||||||
|
|
||||||
|
if [ -z "${CURR_HOTFIX}" ]; then
|
||||||
|
CURR_VER="${CURR_MAJOR}.${CURR_MINOR}.${CURR_PATCH}.${CURR_BUILD}"
|
||||||
|
else
|
||||||
|
CURR_VER="${CURR_MAJOR}.${CURR_MINOR}.${CURR_PATCH}.${CURR_BUILD}${CURR_HOTFIX}"
|
||||||
|
fi
|
||||||
|
|
||||||
|
printf "\nLevelX release preparation\n"
|
||||||
|
printf " Repository : %s\n" "${REPO_ROOT}"
|
||||||
|
printf " Current version : %s\n" "${CURR_VER}"
|
||||||
|
printf " Target version : %s\n\n" "${VERSION}"
|
||||||
|
printf "Proceed with update? [y/N] "
|
||||||
|
read -r CONFIRM
|
||||||
|
case "${CONFIRM}" in
|
||||||
|
y|Y) ;;
|
||||||
|
*)
|
||||||
|
printf "Aborted.\n"
|
||||||
|
exit 0
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
|
||||||
|
# --------------------------------------------------------------------------
|
||||||
|
# Pre-flight checks
|
||||||
|
# --------------------------------------------------------------------------
|
||||||
|
if ! git -C "${REPO_ROOT}" diff --quiet HEAD 2>/dev/null; then
|
||||||
|
printf "Error: Working tree has uncommitted changes. Commit or stash first.\n" >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# --------------------------------------------------------------------------
|
||||||
|
# Create feature branch from dev
|
||||||
|
# --------------------------------------------------------------------------
|
||||||
|
BRANCH_NAME="release-${VERSION}-preparation"
|
||||||
|
printf "\nChecking out dev and pulling latest changes...\n"
|
||||||
|
git -C "${REPO_ROOT}" checkout dev
|
||||||
|
git -C "${REPO_ROOT}" pull origin dev
|
||||||
|
printf "Creating branch '%s'...\n" "${BRANCH_NAME}"
|
||||||
|
git -C "${REPO_ROOT}" checkout -b "${BRANCH_NAME}"
|
||||||
|
|
||||||
|
# --------------------------------------------------------------------------
|
||||||
|
# Update version constants
|
||||||
|
# --------------------------------------------------------------------------
|
||||||
|
printf "\nUpdating version constants in %s...\n" "${API_HEADER}"
|
||||||
|
|
||||||
|
sed -i -E "s|(#define LEVELX_MAJOR_VERSION[[:space:]]+)[0-9]+|\1${MAJOR}|" "${API_HEADER}"
|
||||||
|
sed -i -E "s|(#define LEVELX_MINOR_VERSION[[:space:]]+)[0-9]+|\1${MINOR}|" "${API_HEADER}"
|
||||||
|
sed -i -E "s|(#define LEVELX_PATCH_VERSION[[:space:]]+)[0-9]+|\1${PATCH}|" "${API_HEADER}"
|
||||||
|
sed -i -E "s|(#define LEVELX_BUILD_VERSION[[:space:]]+)[0-9]+|\1${BUILD}|" "${API_HEADER}"
|
||||||
|
sed -i -E "s|(#define LEVELX_HOTFIX_VERSION[[:space:]]+)'[^']*'|\1${HOTFIX_DEFINE}|" "${API_HEADER}"
|
||||||
|
|
||||||
|
git -C "${REPO_ROOT}" add "${API_HEADER}"
|
||||||
|
git -C "${REPO_ROOT}" commit -F - <<'COMMIT_EOF'
|
||||||
|
Updated version number constants
|
||||||
|
|
||||||
|
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
|
||||||
|
COMMIT_EOF
|
||||||
|
|
||||||
|
printf "Committed version constant updates.\n"
|
||||||
|
|
||||||
|
# --------------------------------------------------------------------------
|
||||||
|
# Port version strings
|
||||||
|
# --------------------------------------------------------------------------
|
||||||
|
printf "\nNo port-specific version strings in this repository. Skipping port commit.\n"
|
||||||
|
|
||||||
|
printf "\nRelease preparation complete.\n"
|
||||||
|
printf "Branch '%s' is ready for review.\n" "${BRANCH_NAME}"
|
||||||
Executable
+13
@@ -0,0 +1,13 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
##############################################################################
|
||||||
|
# Copyright (c) 2024 Microsoft Corporation
|
||||||
|
# Copyright (c) 2026 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
|
||||||
|
##############################################################################
|
||||||
|
|
||||||
|
$(dirname `realpath $0`)/../test/cmake/run.sh test all
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
threadx
|
||||||
|
filex
|
||||||
|
coverage_report
|
||||||
|
.run.sh
|
||||||
@@ -0,0 +1,128 @@
|
|||||||
|
cmake_minimum_required(VERSION 3.13 FATAL_ERROR)
|
||||||
|
cmake_policy(SET CMP0054 NEW)
|
||||||
|
cmake_policy(SET CMP0057 NEW)
|
||||||
|
|
||||||
|
project(levelx_test LANGUAGES C)
|
||||||
|
|
||||||
|
# Set build configurations
|
||||||
|
set(BUILD_CONFIGURATIONS default_build_coverage
|
||||||
|
free_sector_verify_build
|
||||||
|
full_build
|
||||||
|
standalone_build
|
||||||
|
standalone_free_sector_verify_build
|
||||||
|
standalone_full_build
|
||||||
|
new_driver_interface_build
|
||||||
|
nor_obsolete_cache_build
|
||||||
|
nor_mapping_cache_build
|
||||||
|
nor_obsolete_mapping_cache_build)
|
||||||
|
set(CMAKE_CONFIGURATION_TYPES
|
||||||
|
${BUILD_CONFIGURATIONS}
|
||||||
|
CACHE STRING "list of supported configuration types" FORCE)
|
||||||
|
set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS
|
||||||
|
${CMAKE_CONFIGURATION_TYPES})
|
||||||
|
list(GET CMAKE_CONFIGURATION_TYPES 0 BUILD_TYPE)
|
||||||
|
if((NOT CMAKE_BUILD_TYPE) OR (NOT ("${CMAKE_BUILD_TYPE}" IN_LIST
|
||||||
|
CMAKE_CONFIGURATION_TYPES)))
|
||||||
|
set(CMAKE_BUILD_TYPE
|
||||||
|
"${BUILD_TYPE}"
|
||||||
|
CACHE STRING "Build Type of the project" FORCE)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
message(STATUS "Build type: ${CMAKE_BUILD_TYPE}")
|
||||||
|
message(STATUS "Using toolchain file: ${CMAKE_TOOLCHAIN_FILE}.")
|
||||||
|
set(FX_FAULT_TOLERANT_DEFINITIONS
|
||||||
|
-DFX_ENABLE_FAULT_TOLERANT -DFX_UPDATE_FILE_SIZE_ON_ALLOCATE
|
||||||
|
-DFX_FAULT_TOLERANT_TRANSACTION_FAIL_FUNCTION)
|
||||||
|
set(default_build_coverage "")
|
||||||
|
set(free_sector_verify_build -DLX_FREE_SECTOR_DATA_VERIFY)
|
||||||
|
set(full_build -DLX_FREE_SECTOR_DATA_VERIFY
|
||||||
|
-DLX_DIRECT_READ
|
||||||
|
-DLX_NAND_FLASH_DIRECT_MAPPING_CACHE
|
||||||
|
-DLX_NOR_DISABLE_EXTENDED_CACHE
|
||||||
|
-DLX_THREAD_SAFE_ENABLE)
|
||||||
|
# For Standalone builds LX_STANADLONE_ENABLE is defined in line 61
|
||||||
|
set(standalone_build -DLX_STANDALONE_ENABLE)
|
||||||
|
set(standalone_free_sector_verify_build -DLX_STANDALONE_ENABLE ${free_sector_verify_build})
|
||||||
|
set(standalone_full_build -DLX_STANDALONE_ENABLE ${full_build})
|
||||||
|
set(new_driver_interface_build -DLX_NOR_ENABLE_CONTROL_BLOCK_FOR_DRIVER_INTERFACE
|
||||||
|
-DLX_NAND_ENABLE_CONTROL_BLOCK_FOR_DRIVER_INTERFACE)
|
||||||
|
set(nor_obsolete_cache_build -DLX_NOR_ENABLE_OBSOLETE_COUNT_CACHE)
|
||||||
|
set(nor_mapping_cache_build -DLX_NOR_ENABLE_MAPPING_BITMAP)
|
||||||
|
set(nor_obsolete_mapping_cache_build -DLX_NOR_ENABLE_MAPPING_BITMAP
|
||||||
|
-DLX_NOR_ENABLE_OBSOLETE_COUNT_CACHE)
|
||||||
|
|
||||||
|
add_compile_options(
|
||||||
|
-m32
|
||||||
|
-std=c99
|
||||||
|
-ggdb
|
||||||
|
-g3
|
||||||
|
-gdwarf-2
|
||||||
|
-fdiagnostics-color
|
||||||
|
-Werror
|
||||||
|
${${CMAKE_BUILD_TYPE}})
|
||||||
|
add_link_options(-m32)
|
||||||
|
|
||||||
|
enable_testing()
|
||||||
|
|
||||||
|
if(CMAKE_BUILD_TYPE MATCHES "standalone.*")
|
||||||
|
set(LX_STANDALONE_ENABLE
|
||||||
|
ON
|
||||||
|
CACHE BOOL "LevelX standalone enabled(No Azure RTOS ThreadX)" FORCE)
|
||||||
|
set(FX_STANDALONE_ENABLE
|
||||||
|
ON
|
||||||
|
CACHE BOOL "FileX standalone enabled(No Azure RTOS ThreadX)" FORCE)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
add_subdirectory(${CMAKE_CURRENT_LIST_DIR}/../.. levelx)
|
||||||
|
add_subdirectory(regression)
|
||||||
|
add_subdirectory(samples)
|
||||||
|
|
||||||
|
# Coverage
|
||||||
|
if(CMAKE_BUILD_TYPE MATCHES ".*_coverage")
|
||||||
|
target_compile_options(levelx PRIVATE -fprofile-arcs -ftest-coverage)
|
||||||
|
target_link_options(levelx PRIVATE -fprofile-arcs -ftest-coverage)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
|
||||||
|
# Build ThreadX library once
|
||||||
|
execute_process(COMMAND ${CMAKE_CURRENT_LIST_DIR}/run.sh build_libs)
|
||||||
|
add_custom_target(build_libs ALL COMMAND ${CMAKE_CURRENT_LIST_DIR}/run.sh
|
||||||
|
build_libs)
|
||||||
|
add_dependencies(levelx build_libs)
|
||||||
|
target_include_directories(levelx PUBLIC ${CMAKE_BINARY_DIR}/../libs/inc)
|
||||||
|
if(NOT LX_STANDALONE_ENABLE)
|
||||||
|
add_library(threadx SHARED IMPORTED GLOBAL)
|
||||||
|
add_library("azrtos::threadx" ALIAS threadx)
|
||||||
|
set_target_properties(
|
||||||
|
threadx PROPERTIES IMPORTED_LOCATION
|
||||||
|
${CMAKE_BINARY_DIR}/../libs/threadx/libthreadx.so)
|
||||||
|
add_library(filex SHARED IMPORTED GLOBAL)
|
||||||
|
add_library("azrtos::filex" ALIAS filex)
|
||||||
|
set_target_properties(filex PROPERTIES IMPORTED_LOCATION
|
||||||
|
${CMAKE_BINARY_DIR}/../libs/filex/libfilex.so)
|
||||||
|
else()
|
||||||
|
get_filename_component(
|
||||||
|
externals ${CMAKE_CURRENT_SOURCE_DIR} ABSOLUTE)
|
||||||
|
add_subdirectory(${externals}/filex filex)
|
||||||
|
add_library("azrtos::filex" ALIAS filex)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
target_compile_options(
|
||||||
|
levelx
|
||||||
|
PRIVATE -Werror
|
||||||
|
-Wall
|
||||||
|
-Wextra
|
||||||
|
-pedantic
|
||||||
|
-fmessage-length=0
|
||||||
|
-fsigned-char
|
||||||
|
-ffunction-sections
|
||||||
|
-fdata-sections
|
||||||
|
-Wunused
|
||||||
|
-Wuninitialized
|
||||||
|
-Wmissing-declarations
|
||||||
|
-Wconversion
|
||||||
|
-Wpointer-arith
|
||||||
|
-Wshadow
|
||||||
|
-Wlogical-op
|
||||||
|
-Waggregate-return
|
||||||
|
-Wfloat-equal)
|
||||||
Executable
+19
@@ -0,0 +1,19 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
##############################################################################
|
||||||
|
# Copyright (c) 2024 Microsoft Corporation
|
||||||
|
# Copyright (c) 2026 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
|
||||||
|
##############################################################################
|
||||||
|
|
||||||
|
|
||||||
|
set -e
|
||||||
|
|
||||||
|
cd $(dirname $0)
|
||||||
|
mkdir -p coverage_report/$1
|
||||||
|
gcovr --object-directory=build/$1/levelx/CMakeFiles/levelx.dir/common/src -r ../../common/src --xml-pretty --output coverage_report/$1.xml
|
||||||
|
gcovr --object-directory=build/$1/levelx/CMakeFiles/levelx.dir/common/src -r ../../common/src --html --html-details --output coverage_report/$1/index.html
|
||||||
@@ -0,0 +1,38 @@
|
|||||||
|
cmake_minimum_required(VERSION 3.13 FATAL_ERROR)
|
||||||
|
|
||||||
|
project(libs LANGUAGES C)
|
||||||
|
|
||||||
|
if($ENV{ENABLE_64})
|
||||||
|
message(STATUS "Building for 64bit")
|
||||||
|
else()
|
||||||
|
add_compile_options(-m32)
|
||||||
|
add_link_options(-m32)
|
||||||
|
message(STATUS "Building for 32bit")
|
||||||
|
endif()
|
||||||
|
message(STATUS "Using toolchain file: ${CMAKE_TOOLCHAIN_FILE}.")
|
||||||
|
|
||||||
|
get_filename_component(
|
||||||
|
externals ${CMAKE_CURRENT_SOURCE_DIR}/.. ABSOLUTE)
|
||||||
|
|
||||||
|
if(NOT LX_STANDALONE_ENABLE)
|
||||||
|
add_subdirectory(${externals}/threadx threadx)
|
||||||
|
endif()
|
||||||
|
add_subdirectory(${externals}/filex filex)
|
||||||
|
target_compile_options(threadx PRIVATE -DTX_ENABLE_EVENT_TRACE)
|
||||||
|
if(NOT DEFINED ENV{ENABLE_IDLE})
|
||||||
|
target_compile_options(threadx PRIVATE -DTX_LINUX_NO_IDLE_ENABLE)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
|
||||||
|
if((NOT LX_STANDALONE_ENABLE) OR (NOT FX_STANDALONE_ENABLE))
|
||||||
|
foreach(lib threadx filex)
|
||||||
|
get_target_property(dirs ${lib} INCLUDE_DIRECTORIES)
|
||||||
|
execute_process(COMMAND mkdir -p ${CMAKE_BINARY_DIR}/inc)
|
||||||
|
foreach(dir ${dirs})
|
||||||
|
file(GLOB header_files ${dir}/*.h)
|
||||||
|
foreach(header_file ${header_files})
|
||||||
|
execute_process(COMMAND ln -sf ${header_file} ${CMAKE_BINARY_DIR}/inc)
|
||||||
|
endforeach()
|
||||||
|
endforeach()
|
||||||
|
endforeach()
|
||||||
|
endif()
|
||||||
@@ -0,0 +1,20 @@
|
|||||||
|
cmake_minimum_required(VERSION 3.13 FATAL_ERROR)
|
||||||
|
cmake_policy(SET CMP0057 NEW)
|
||||||
|
|
||||||
|
project(regression_test LANGUAGES C)
|
||||||
|
|
||||||
|
set(SOURCE_DIR ${CMAKE_CURRENT_LIST_DIR}/../../regression)
|
||||||
|
|
||||||
|
set(regression_test_cases
|
||||||
|
${SOURCE_DIR}/levelx_nand_flash_test.c
|
||||||
|
${SOURCE_DIR}/levelx_nor_flash_test.c
|
||||||
|
${SOURCE_DIR}/levelx_nor_flash_test_cache.c)
|
||||||
|
|
||||||
|
foreach(test_case ${regression_test_cases} ${regression_test_cases_exfat})
|
||||||
|
get_filename_component(test_name ${test_case} NAME_WE)
|
||||||
|
add_executable(${test_name} ${test_case})
|
||||||
|
target_link_libraries(${test_name} PRIVATE azrtos::filex)
|
||||||
|
target_link_libraries(${test_name} PRIVATE azrtos::levelx)
|
||||||
|
target_compile_definitions(${test_name} PRIVATE BATCH_TEST)
|
||||||
|
add_test(${CMAKE_BUILD_TYPE}::${test_name} ${test_name})
|
||||||
|
endforeach()
|
||||||
Executable
+20
@@ -0,0 +1,20 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
##############################################################################
|
||||||
|
# Copyright (c) 2024 Microsoft Corporation
|
||||||
|
# Copyright (c) 2026 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
|
||||||
|
##############################################################################
|
||||||
|
|
||||||
|
|
||||||
|
cd $(dirname $0)
|
||||||
|
|
||||||
|
# if threadx repo does not exist, clone it
|
||||||
|
[ -d threadx ] || git clone https://github.com/eclipse-threadx/threadx.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
|
||||||
|
./.run.sh $*
|
||||||
@@ -0,0 +1,17 @@
|
|||||||
|
cmake_minimum_required(VERSION 3.13 FATAL_ERROR)
|
||||||
|
cmake_policy(SET CMP0057 NEW)
|
||||||
|
|
||||||
|
project(samples LANGUAGES C)
|
||||||
|
|
||||||
|
set(SOURCE_DIR ${CMAKE_CURRENT_LIST_DIR}/../../../samples)
|
||||||
|
|
||||||
|
set(sample_files
|
||||||
|
${SOURCE_DIR}/demo_filex_nand_flash.c
|
||||||
|
${SOURCE_DIR}/demo_filex_nor_flash.c)
|
||||||
|
|
||||||
|
foreach(sample_file ${sample_files})
|
||||||
|
get_filename_component(sample_file_name ${sample_file} NAME_WE)
|
||||||
|
add_executable(${sample_file_name} ${sample_file})
|
||||||
|
target_link_libraries(${sample_file_name} PRIVATE azrtos::filex)
|
||||||
|
target_link_libraries(${sample_file_name} PRIVATE azrtos::levelx)
|
||||||
|
endforeach()
|
||||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user