mirror of
https://github.com/eclipse-threadx/levelx.git
synced 2026-09-14 04:06:00 +08:00
Compare commits
| 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 | ||
|
|
cef8e4ffeb | ||
|
|
e1a2752d6c | ||
|
|
39de3e54bd | ||
|
|
a8bc412907 | ||
|
|
718fb514a9 | ||
|
|
27e3f5d915 | ||
|
|
dbf4f90598 | ||
|
|
8b3a8293ce | ||
|
|
2f639bac26 | ||
|
|
9075ca321b | ||
|
|
c53a6c6bca | ||
|
|
bbab2bbf6b | ||
|
|
79cefa16a4 | ||
|
|
e848ac3db2 | ||
|
|
fdf7799991 | ||
|
|
61f92c00c7 | ||
|
|
d4089f56e3 | ||
|
|
d42808cdeb | ||
|
|
c1d0fb9275 | ||
|
|
6eadbd6d97 | ||
|
|
f11f115a41 | ||
|
|
ce04276ace | ||
|
|
6b20a667e3 | ||
|
|
2af719ed1a | ||
|
|
71a3152556 | ||
|
|
d5a5b7f13e | ||
|
|
79f18aa137 | ||
|
|
b2faa5eabe | ||
|
|
e9a11fbba9 | ||
|
|
e75d8c5fb0 | ||
|
|
c88e35d9f8 | ||
|
|
aa7076b48c | ||
|
|
c731776882 | ||
|
|
d0145d66c3 | ||
|
|
8ce5b14c53 | ||
|
|
d328a38362 |
@@ -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"]
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
---
|
||||
name: Bug report
|
||||
about: Create a report to help us improve Eclipse ThreadX.
|
||||
title: ''
|
||||
labels: bug
|
||||
assignees: ''
|
||||
|
||||
---
|
||||
|
||||
**Describe the bug**
|
||||
A clear and concise description of what the bug is.
|
||||
|
||||
Please also mention any information which could help others to understand
|
||||
the problem you're facing:
|
||||
- What target device are you using?
|
||||
- Which version of Eclipse ThreadX?
|
||||
- What toolchain and environment?
|
||||
- What have you tried to diagnose or workaround this issue?
|
||||
|
||||
**To Reproduce**
|
||||
Steps to reproduce the behavior:
|
||||
1. Build my project in IAR Workbench.
|
||||
1. See error
|
||||
|
||||
**Expected behavior**
|
||||
A clear and concise description of what you expected to happen.
|
||||
|
||||
**Impact**
|
||||
What impact does this issue have on your progress (e.g., annoyance, showstopper)
|
||||
|
||||
**Logs and console output**
|
||||
If applicable, add console logs or other types of debug information like Wireshark capture as `.zip` file.
|
||||
|
||||
**Additional context**
|
||||
Add any other context about the problem here.
|
||||
@@ -0,0 +1,20 @@
|
||||
---
|
||||
name: Feature request
|
||||
about: Suggest an idea or enhancement to existing feature for Eclipse ThreadX.
|
||||
title: ''
|
||||
labels: feature
|
||||
assignees: ''
|
||||
|
||||
---
|
||||
|
||||
**Is your feature request related to a problem? Please describe.**
|
||||
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
|
||||
|
||||
**Describe the solution you'd like**
|
||||
A clear and concise description of what you want to happen.
|
||||
|
||||
**Describe alternatives you've considered**
|
||||
A clear and concise description of any alternative solutions or features you've considered.
|
||||
|
||||
**Additional context**
|
||||
Add any other context or screenshots about the feature request here.
|
||||
@@ -0,0 +1,19 @@
|
||||
---
|
||||
name: Hardware or architecture support
|
||||
about: Suggest adding hardware or new architecture support.
|
||||
title: ''
|
||||
labels: hardware
|
||||
assignees: ''
|
||||
|
||||
---
|
||||
|
||||
**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 Eclipse ThreadX.
|
||||
|
||||
**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 Eclipse ThreadX support together with you.
|
||||
|
||||
**Additional context**
|
||||
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
|
||||
+39
-7
@@ -1,11 +1,13 @@
|
||||
cmake_minimum_required(VERSION 3.0.0 FATAL_ERROR)
|
||||
cmake_minimum_required(VERSION 3.13 FATAL_ERROR)
|
||||
|
||||
# Set up the project
|
||||
project(levelx
|
||||
VERSION 6.0.0
|
||||
LANGUAGES C ASM
|
||||
)
|
||||
|
||||
option(LX_STANDALONE_ENABLE "Enable LevelX in standalone mode" OFF)
|
||||
option(LX_ENABLE_FILE_SERVERS "Includes a dependency on FileX" ON)
|
||||
|
||||
if(NOT DEFINED THREADX_ARCH)
|
||||
message(FATAL_ERROR "Error: THREADX_ARCH not defined")
|
||||
endif()
|
||||
@@ -19,14 +21,43 @@ add_library(${PROJECT_NAME})
|
||||
add_library("azrtos::${PROJECT_NAME}" ALIAS ${PROJECT_NAME})
|
||||
|
||||
# Define any required dependencies between this library and others
|
||||
target_link_libraries(${PROJECT_NAME} PUBLIC
|
||||
"azrtos::threadx"
|
||||
"azrtos::filex"
|
||||
)
|
||||
if(NOT LX_STANDALONE_ENABLE)
|
||||
target_link_libraries(${PROJECT_NAME} PUBLIC
|
||||
"azrtos::threadx")
|
||||
endif()
|
||||
|
||||
if(LX_ENABLE_FILE_SERVERS)
|
||||
message(STATUS "LX_ENABLE_FILE_SERVERS - defined")
|
||||
target_link_libraries(${PROJECT_NAME} PUBLIC "azrtos::filex")
|
||||
endif()
|
||||
|
||||
# A place for generated/copied include files (no need to change)
|
||||
set(CUSTOM_INC_DIR ${CMAKE_CURRENT_BINARY_DIR}/custom_inc)
|
||||
|
||||
# Pick up the common stuff
|
||||
add_subdirectory(${CMAKE_CURRENT_LIST_DIR}/common)
|
||||
|
||||
# Include the user's override file if required
|
||||
if (NOT LX_USER_FILE)
|
||||
message(STATUS "Using default lx_user.h file")
|
||||
set(LX_USER_FILE ${CMAKE_CURRENT_LIST_DIR}/common/inc/lx_user_sample.h)
|
||||
else()
|
||||
message(STATUS "Using custom lx_user.h file from ${LX_USER_FILE}")
|
||||
endif()
|
||||
configure_file(${LX_USER_FILE} ${CUSTOM_INC_DIR}/lx_user.h COPYONLY)
|
||||
target_include_directories(${PROJECT_NAME}
|
||||
PUBLIC
|
||||
${CUSTOM_INC_DIR}
|
||||
)
|
||||
|
||||
if(NOT LX_STANDALONE_ENABLE)
|
||||
target_compile_definitions(${PROJECT_NAME} PUBLIC "LX_INCLUDE_USER_DEFINE_FILE" )
|
||||
else()
|
||||
# Enable LevelX and FileX standalone support (No Azure RTOS support)
|
||||
set(FX_STANDALONE_ENABLE ON CACHE BOOL "Standalone enable")
|
||||
target_compile_definitions(${PROJECT_NAME} PUBLIC "LX_INCLUDE_USER_DEFINE_FILE" -DLX_STANDALONE_ENABLE -DFX_STANDALONE_ENABLE)
|
||||
endif()
|
||||
|
||||
# Enable a build target that produces a ZIP file of all sources
|
||||
set(CPACK_SOURCE_GENERATOR "ZIP")
|
||||
set(CPACK_SOURCE_IGNORE_FILES
|
||||
@@ -39,4 +70,5 @@ set(CPACK_SOURCE_IGNORE_FILES
|
||||
".*~$"
|
||||
)
|
||||
set(CPACK_VERBATIM_VARIABLES YES)
|
||||
include(CPack)
|
||||
include(CPack)
|
||||
|
||||
|
||||
+69
-11
@@ -1,14 +1,72 @@
|
||||
# Contributing
|
||||
# Contributing to Eclipse ThreadX
|
||||
|
||||
This project welcomes contributions and suggestions. Most contributions require you to
|
||||
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.
|
||||
Thanks for your interest in this project.
|
||||
|
||||
When you submit a pull request, a CLA-bot will automatically determine whether you need
|
||||
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.
|
||||
## Project description
|
||||
|
||||
This project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/).
|
||||
For more information see the [Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/)
|
||||
or contact [opencode@microsoft.com](mailto:opencode@microsoft.com) with any additional questions or comments.
|
||||
Eclipse ThreadX provides a vendor-neutral, open source, safety certified OS for
|
||||
real-time applications published on under a permissive license. The Eclipse
|
||||
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
-242
@@ -1,246 +1,21 @@
|
||||
MICROSOFT SOFTWARE LICENSE TERMS
|
||||
MIT License
|
||||
|
||||
MICROSOFT AZURE RTOS
|
||||
Copyright (c) 2024 - present Microsoft Corporation
|
||||
|
||||
Shape
|
||||
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
|
||||
one of its affiliates). They apply to the software named above and any Microsoft
|
||||
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.
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
INSTALLATION AND USE RIGHTS.
|
||||
|
||||
General. You may install and use the software and the included Microsoft
|
||||
applications solely for internal development, testing and evaluation purposes.
|
||||
Any distribution or production use requires a separate license as set forth in
|
||||
Section 2.
|
||||
|
||||
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.
|
||||
|
||||
Included Microsoft Applications. The software includes other Microsoft
|
||||
applications which are governed by the licenses embedded in or made available
|
||||
with those applications.
|
||||
|
||||
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.
|
||||
|
||||
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.
|
||||
|
||||
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.
|
||||
|
||||
Distribution and Production Use Rights.
|
||||
|
||||
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.
|
||||
|
||||
|
||||
You may permit your device distributors or developers to copy and distribute the
|
||||
binary image as programmed or to be programmed to your devices.
|
||||
|
||||
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.
|
||||
|
||||
Requirements. For any code you distribute, you must:
|
||||
|
||||
when distributed in binary form, except as embedded in a device, include with
|
||||
such distribution the terms of this agreement;
|
||||
|
||||
when distributed in source code form to distributors or developers of your
|
||||
devices, include with such distribution the terms of this agreement; and
|
||||
|
||||
indemnify, defend and hold harmless Microsoft from any claims, including
|
||||
attorneys’ fees, related to the distribution or use of your devices, except to
|
||||
the extent that any claim is based solely on the unmodified software.
|
||||
|
||||
Restrictions. You may not:
|
||||
|
||||
use or modify the software to create a competing real time operating system
|
||||
software;
|
||||
|
||||
remove any copyright notices or licenses contained in the software;
|
||||
|
||||
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;
|
||||
|
||||
transfer individual components, specific libraries, classes, functions or code
|
||||
fragments of the software separately for purposes unrelated to the software; or
|
||||
|
||||
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.
|
||||
|
||||
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):
|
||||
|
||||
remove, minimize, block, or modify any notices of Microsoft or its suppliers in
|
||||
the software;
|
||||
|
||||
use the software in any way that is against the law or to create or propagate
|
||||
malware; or
|
||||
|
||||
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.
|
||||
|
||||
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.
|
||||
|
||||
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.
|
||||
|
||||
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.
|
||||
|
||||
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.
|
||||
|
||||
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.
|
||||
|
||||
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.
|
||||
|
||||
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.
|
||||
|
||||
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:
|
||||
|
||||
Australia. You have statutory guarantees under the Australian Consumer Law and
|
||||
nothing in this agreement is intended to affect those rights.
|
||||
|
||||
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.
|
||||
|
||||
DISCLAIMER OF WARRANTY. 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.
|
||||
|
||||
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. 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.
|
||||
|
||||
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.
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
|
||||
@@ -1,16 +0,0 @@
|
||||
LICENSED HARDWARE LIST
|
||||
|
||||
Last Updated: 2020-05-08
|
||||
|
||||
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.
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
More coming soon. Please check back frequently for updates.
|
||||
@@ -1,73 +1,137 @@
|
||||
# Azure RTOS NetX
|
||||
# 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.
|
||||
|
||||
## Documentation
|
||||
## Getting Started
|
||||
|
||||
Documentation for this library can be found here: http://docs.microsoft.com/azure/rtos/levelx
|
||||
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).
|
||||
|
||||
# Understanding inter-component dependencies
|
||||
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.
|
||||
|
||||
The main components of Azure RTOS are each provided in their own repository, but there are dependencies between them--shown in the following graph--that are important to understand when setting up your builds.
|
||||
## Repository Structure and Usage
|
||||
|
||||
### Directory layout
|
||||
|
||||
.
|
||||
├── cmake # CMakeList files for building the project
|
||||
├── common # Core LevelX files
|
||||
├── samples # Sample codes
|
||||
├── LICENSE.txt # License terms
|
||||
├── LICENSE-HARDWARE.txt # Licensed hardware from semiconductors
|
||||
├── CONTRIBUTING.md # Contribution guidance
|
||||
└── SECURITY.md # Repo security guidance
|
||||
|
||||
### Branches & Releases
|
||||
|
||||
The master branch has the most recent code with all new features and bug fixes. It does not represent the latest General Availability (GA) release of the library. Each official release (preview or GA) will be tagged to mark the commit and push it into the Github releases tab, e.g. `v6.2-rel`.
|
||||
|
||||
> When you see xx-xx-xxxx, 6.x or x.x in function header, this means the file is not officially released yet. They will be updated in the next release. See example below.
|
||||
```
|
||||
/**************************************************************************/
|
||||
/* */
|
||||
/* FUNCTION RELEASE */
|
||||
/* */
|
||||
/* _tx_initialize_low_level Cortex-M23/GNU */
|
||||
/* 6.x */
|
||||
/* AUTHOR */
|
||||
/* */
|
||||
/* Scott Larson, Microsoft Corporation */
|
||||
/* */
|
||||
/* DESCRIPTION */
|
||||
/* */
|
||||
/* This function is responsible for any low-level processor */
|
||||
/* initialization, including setting up interrupt vectors, setting */
|
||||
/* up a periodic timer interrupt source, saving the system stack */
|
||||
/* pointer for use in ISR processing later, and finding the first */
|
||||
/* available RAM memory address for tx_application_define. */
|
||||
/* */
|
||||
/* INPUT */
|
||||
/* */
|
||||
/* None */
|
||||
/* */
|
||||
/* OUTPUT */
|
||||
/* */
|
||||
/* None */
|
||||
/* */
|
||||
/* CALLS */
|
||||
/* */
|
||||
/* None */
|
||||
/* */
|
||||
/* CALLED BY */
|
||||
/* */
|
||||
/* _tx_initialize_kernel_enter ThreadX entry function */
|
||||
/* */
|
||||
/* RELEASE HISTORY */
|
||||
/* */
|
||||
/* DATE NAME DESCRIPTION */
|
||||
/* */
|
||||
/* 09-30-2020 Scott Larson Initial Version 6.1 */
|
||||
/* xx-xx-xxxx Scott Larson Include tx_user.h, */
|
||||
/* resulting in version 6.x */
|
||||
/* */
|
||||
/**************************************************************************/
|
||||
```
|
||||
|
||||
## Component dependencies
|
||||
|
||||
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.
|
||||
|
||||

|
||||
|
||||
# Building and using the library
|
||||
> You will have to take the dependency graph above into account when building anything other than ThreadX itself.
|
||||
|
||||
## Prerequisites
|
||||
### Building and using the library
|
||||
|
||||
Install the following tools:
|
||||
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.
|
||||
|
||||
* [CMake](https://cmake.org/download/) version 3.0 or later
|
||||
* [GCC compilers for arm-none-eabi](https://developer.arm.com/tools-and-software/open-source-software/developer-tools/gnu-toolchain/gnu-rm/downloads)
|
||||
* [Ninja](https://ninja-build.org/)
|
||||
1. Install the following tools:
|
||||
|
||||
## Cloning the repo
|
||||
* [CMake](https://cmake.org/download/) version 3.0 or later
|
||||
* [Arm GNU Toolchain for arm-none-eabi](https://developer.arm.com/downloads/-/arm-gnu-toolchain-downloads)
|
||||
* [Ninja](https://ninja-build.org/)
|
||||
|
||||
```bash
|
||||
$ git clone https://github.com/azure-rtos/levelx.git
|
||||
```
|
||||
1. Build the [ThreadX library](https://github.com/azure-rtos/threadx#building-and-using-the-library) as the dependency.
|
||||
|
||||
## Building as a static library
|
||||
1. Cloning the repo.
|
||||
|
||||
Each component of Azure RTOS comes with a composible 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 command `add_subdirectory()`.
|
||||
```bash
|
||||
$ git clone --recursive https://github.com/eclipse-threadx/levelx.git
|
||||
```
|
||||
|
||||
While the typical usage pattern is to include threadx 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.
|
||||
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.
|
||||
|
||||
```bash
|
||||
$ cmake -Bbuild -DCMAKE_TOOLCHAIN_FILE=cmake/cortex_m4.cmake -GNinja .
|
||||
1. Building as a static library
|
||||
|
||||
$ cmake --build ./build
|
||||
```
|
||||
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()`.
|
||||
|
||||
NOTE: You will have to take the dependency graph above into account when building anything other than threadx itself.
|
||||
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.
|
||||
|
||||
# Repository Structure and Usage
|
||||
An example of building the library for Cortex-M4:
|
||||
|
||||
## Branches & Releases
|
||||
```bash
|
||||
$ cmake -Bbuild -GNinja -DCMAKE_TOOLCHAIN_FILE=cmake/cortex_m4.cmake .
|
||||
|
||||
The master branch has the most recent code with all new features and bug fixes. It does not represent the latest General Availability (GA) release of the library.
|
||||
$ cmake --build ./build
|
||||
```
|
||||
|
||||
## Releases
|
||||
## Licensing
|
||||
|
||||
Each official release (preview or GA) will be tagged to mark the commit and push it into the Github releases tab, e.g. `v6.0-rel`.
|
||||
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.
|
||||
|
||||
## Directory layout
|
||||
## Resources
|
||||
|
||||
```
|
||||
- cmake
|
||||
- common
|
||||
- inc
|
||||
- src
|
||||
- samples
|
||||
```
|
||||
The following are references to additional Eclipse ThreadX resources:
|
||||
|
||||
# Security
|
||||
- **Product introduction**: https://github.com/eclipse-threadx/rtos-docs
|
||||
- **Product issues and bugs, or feature requests**: https://github.com/eclipse-threadx/levelx/issues
|
||||
- **TraceX Installer**: https://aka.ms/azrtos-tracex-installer
|
||||
|
||||
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.
|
||||
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.
|
||||
|
||||
# Contribution, feedback and issues
|
||||
## Security
|
||||
|
||||
If you encounter any bugs, have suggestions for new features or if you would like to become an active contributor to this project please follow the instructions provided in the contribution guideline for the corresponding repo.
|
||||
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.
|
||||
|
||||
For general support, please post a question to [Stack Overflow](http://stackoverflow.com/questions/tagged/azure-rtos+threadx) using the `threadx` and `azure-rtos` tags.
|
||||
## Contribution
|
||||
|
||||
Please follow the instructions provided in the [CONTRIBUTING.md](./CONTRIBUTING.md) for the corresponding repository.
|
||||
|
||||
+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:
|
||||
|
||||
* Type of issue (e.g. buffer overflow, SQL injection, cross-site scripting, etc.)
|
||||
* Full paths of source file(s) related to the manifestation of the issue
|
||||
* The location of the affected source code (tag/branch/commit or direct URL)
|
||||
* Any special configuration required to reproduce the issue
|
||||
* Step-by-step instructions to reproduce the issue
|
||||
* Proof-of-concept or exploit code (if possible)
|
||||
* Impact of the issue, including how an attacker might exploit the issue
|
||||
* The type of issue (e.g., buffer overflow, SQL injection, or cross-site scripting)
|
||||
* Affected version(s)
|
||||
* Impact of the issue, including how an attacker might exploit the issue
|
||||
* Step-by-step instructions to reproduce the issue
|
||||
* The location of the affected source code (tag/branch/commit or direct URL)
|
||||
* Full paths of source file(s) related to the manifestation of the issue
|
||||
* Configuration required to reproduce the issue
|
||||
* Log files that are related to this issue (if possible)
|
||||
* Proof-of-concept or exploit code (if possible)
|
||||
|
||||
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).
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
# Name of the target
|
||||
set(CMAKE_SYSTEM_NAME Generic)
|
||||
set(CMAKE_SYSTEM_PROCESSOR cortex-m4)
|
||||
set(CMAKE_SYSTEM_PROCESSOR cortex-m0)
|
||||
|
||||
set(THREADX_ARCH "cortex_m0")
|
||||
set(THREADX_TOOLCHAIN "gnu")
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
# Name of the target
|
||||
set(CMAKE_SYSTEM_NAME Generic)
|
||||
set(CMAKE_SYSTEM_PROCESSOR cortex-m4)
|
||||
set(CMAKE_SYSTEM_PROCESSOR cortex-m0)
|
||||
|
||||
set(THREADX_ARCH "cortex_m3")
|
||||
set(THREADX_TOOLCHAIN "gnu")
|
||||
|
||||
+24
-11
@@ -4,30 +4,41 @@ target_sources(${PROJECT_NAME} PRIVATE
|
||||
${CMAKE_CURRENT_LIST_DIR}/src/fx_nor_flash_simulator_driver.c
|
||||
${CMAKE_CURRENT_LIST_DIR}/src/lx_nand_flash_256byte_ecc_check.c
|
||||
${CMAKE_CURRENT_LIST_DIR}/src/lx_nand_flash_256byte_ecc_compute.c
|
||||
${CMAKE_CURRENT_LIST_DIR}/src/lx_nand_flash_block_full_update.c
|
||||
${CMAKE_CURRENT_LIST_DIR}/src/lx_nand_flash_block_obsoleted_check.c
|
||||
${CMAKE_CURRENT_LIST_DIR}/src/lx_nand_flash_block_reclaim.c
|
||||
${CMAKE_CURRENT_LIST_DIR}/src/lx_nand_flash_block_allocate.c
|
||||
${CMAKE_CURRENT_LIST_DIR}/src/lx_nand_flash_block_data_move.c
|
||||
${CMAKE_CURRENT_LIST_DIR}/src/lx_nand_flash_block_find.c
|
||||
${CMAKE_CURRENT_LIST_DIR}/src/lx_nand_flash_block_mapping_set.c
|
||||
${CMAKE_CURRENT_LIST_DIR}/src/lx_nand_flash_block_status_set.c
|
||||
${CMAKE_CURRENT_LIST_DIR}/src/lx_nand_flash_close.c
|
||||
${CMAKE_CURRENT_LIST_DIR}/src/lx_nand_flash_data_page_copy.c
|
||||
${CMAKE_CURRENT_LIST_DIR}/src/lx_nand_flash_defragment.c
|
||||
${CMAKE_CURRENT_LIST_DIR}/src/lx_nand_flash_driver_block_erase.c
|
||||
${CMAKE_CURRENT_LIST_DIR}/src/lx_nand_flash_driver_block_erased_verify.c
|
||||
${CMAKE_CURRENT_LIST_DIR}/src/lx_nand_flash_driver_block_status_get.c
|
||||
${CMAKE_CURRENT_LIST_DIR}/src/lx_nand_flash_driver_block_status_set.c
|
||||
${CMAKE_CURRENT_LIST_DIR}/src/lx_nand_flash_driver_extra_bytes_get.c
|
||||
${CMAKE_CURRENT_LIST_DIR}/src/lx_nand_flash_driver_extra_bytes_set.c
|
||||
${CMAKE_CURRENT_LIST_DIR}/src/lx_nand_flash_driver_page_erased_verify.c
|
||||
${CMAKE_CURRENT_LIST_DIR}/src/lx_nand_flash_driver_read.c
|
||||
${CMAKE_CURRENT_LIST_DIR}/src/lx_nand_flash_driver_write.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_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_initialize.c
|
||||
${CMAKE_CURRENT_LIST_DIR}/src/lx_nand_flash_logical_sector_find.c
|
||||
${CMAKE_CURRENT_LIST_DIR}/src/lx_nand_flash_next_block_to_erase_find.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_get.c
|
||||
${CMAKE_CURRENT_LIST_DIR}/src/lx_nand_flash_mapped_block_list_remove.c
|
||||
${CMAKE_CURRENT_LIST_DIR}/src/lx_nand_flash_memory_initialize.c
|
||||
${CMAKE_CURRENT_LIST_DIR}/src/lx_nand_flash_metadata_allocate.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_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_compute.c
|
||||
${CMAKE_CURRENT_LIST_DIR}/src/lx_nand_flash_partial_defragment.c
|
||||
${CMAKE_CURRENT_LIST_DIR}/src/lx_nand_flash_physical_page_allocate.c
|
||||
${CMAKE_CURRENT_LIST_DIR}/src/lx_nand_flash_sector_mapping_cache_invalidate.c
|
||||
${CMAKE_CURRENT_LIST_DIR}/src/lx_nand_flash_sectors_read.c
|
||||
${CMAKE_CURRENT_LIST_DIR}/src/lx_nand_flash_sectors_release.c
|
||||
${CMAKE_CURRENT_LIST_DIR}/src/lx_nand_flash_sectors_write.c
|
||||
${CMAKE_CURRENT_LIST_DIR}/src/lx_nand_flash_sector_read.c
|
||||
${CMAKE_CURRENT_LIST_DIR}/src/lx_nand_flash_sector_release.c
|
||||
${CMAKE_CURRENT_LIST_DIR}/src/lx_nand_flash_sector_write.c
|
||||
@@ -44,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_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_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_physical_sector_allocate.c
|
||||
${CMAKE_CURRENT_LIST_DIR}/src/lx_nor_flash_sector_mapping_cache_invalidate.c
|
||||
|
||||
+402
-115
@@ -1,19 +1,20 @@
|
||||
/**************************************************************************/
|
||||
/* */
|
||||
/* Copyright (c) Microsoft Corporation. All rights reserved. */
|
||||
/* */
|
||||
/* This software is licensed under the Microsoft Software License */
|
||||
/* Terms for Microsoft Azure RTOS. Full text of the license can be */
|
||||
/* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */
|
||||
/* and in the root directory of this software. */
|
||||
/* */
|
||||
/**************************************************************************/
|
||||
/***************************************************************************
|
||||
* Copyright (c) 2024 Microsoft Corporation
|
||||
* Copyright (c) 2026-present Eclipse ThreadX contributors
|
||||
* 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 */
|
||||
/** */
|
||||
/** LevelX Component */
|
||||
/** */
|
||||
/** Application Interface (API) */
|
||||
/** */
|
||||
@@ -26,7 +27,7 @@
|
||||
/* APPLICATION INTERFACE DEFINITION RELEASE */
|
||||
/* */
|
||||
/* lx_api.h PORTABLE C */
|
||||
/* 6.0 */
|
||||
/* 6.4.1 */
|
||||
/* AUTHOR */
|
||||
/* */
|
||||
/* William E. Lamie, Microsoft Corporation */
|
||||
@@ -37,21 +38,106 @@
|
||||
/* high-performance LevelX. All service prototypes and data structure */
|
||||
/* definitions are defined in this file. */
|
||||
/* */
|
||||
/* RELEASE HISTORY */
|
||||
/* */
|
||||
/* DATE NAME DESCRIPTION */
|
||||
/* */
|
||||
/* 05-19-2020 William E. Lamie Initial Version 6.0 */
|
||||
/* */
|
||||
/**************************************************************************/
|
||||
|
||||
#ifndef LX_API_H
|
||||
#define LX_API_H
|
||||
|
||||
|
||||
/* Include necessary system files. */
|
||||
/* Determine if a C++ compiler is being used. If so, ensure that standard
|
||||
C is used to process the API information. */
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
||||
/* Yes, C++ compiler is present. Use standard C. */
|
||||
extern "C" {
|
||||
|
||||
#endif
|
||||
|
||||
/* Determine if the optional LevelX user define file should be used. */
|
||||
|
||||
#ifdef LX_INCLUDE_USER_DEFINE_FILE
|
||||
|
||||
|
||||
/* Yes, include the user defines in lx_user.h. The defines in this file may
|
||||
alternately be defined on the command line. */
|
||||
|
||||
#include "lx_user.h"
|
||||
#endif
|
||||
|
||||
/* Include the ThreadX api file. */
|
||||
|
||||
#ifndef LX_STANDALONE_ENABLE
|
||||
#include "tx_api.h"
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef LX_STANDALONE_ENABLE
|
||||
|
||||
/* Define compiler library include files. */
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#ifndef VOID
|
||||
#define VOID void
|
||||
typedef char CHAR;
|
||||
typedef char BOOL;
|
||||
typedef unsigned char UCHAR;
|
||||
typedef int INT;
|
||||
typedef unsigned int UINT;
|
||||
typedef long LONG;
|
||||
typedef unsigned long ULONG;
|
||||
typedef short SHORT;
|
||||
typedef unsigned short USHORT;
|
||||
#endif
|
||||
|
||||
#ifndef ULONG64_DEFINED
|
||||
#define ULONG64_DEFINED
|
||||
typedef unsigned long long ULONG64;
|
||||
#endif
|
||||
|
||||
/* Define basic alignment type used in block and byte pool operations. This data type must
|
||||
be at least 32-bits in size and also be large enough to hold a pointer type. */
|
||||
|
||||
#ifndef ALIGN_TYPE_DEFINED
|
||||
#define ALIGN_TYPE_DEFINED
|
||||
#define ALIGN_TYPE ULONG
|
||||
#endif
|
||||
|
||||
/* Define the LX_MEMSET macro to the standard library function, if not already defined. */
|
||||
#ifndef LX_MEMSET
|
||||
#define LX_MEMSET(a,b,c) memset((a),(b),(c))
|
||||
#endif
|
||||
|
||||
#ifndef LX_MEMCPY
|
||||
#define LX_MEMCPY(a,b,c) memcpy((a),(b),(c))
|
||||
#endif
|
||||
|
||||
/* Disable usage of ThreadX mutex in standalone mode */
|
||||
#ifdef LX_THREAD_SAFE_ENABLE
|
||||
#undef LX_THREAD_SAFE_ENABLE
|
||||
#endif
|
||||
|
||||
#define LX_INTERRUPT_SAVE_AREA
|
||||
#define LX_DISABLE
|
||||
#define LX_RESTORE
|
||||
|
||||
#else
|
||||
|
||||
#define LX_MEMSET TX_MEMSET
|
||||
#ifndef LX_MEMCPY
|
||||
#include <string.h>
|
||||
#define LX_MEMCPY(a,b,c) memcpy((a),(b),(c))
|
||||
#endif
|
||||
|
||||
#define LX_INTERRUPT_SAVE_AREA TX_INTERRUPT_SAVE_AREA
|
||||
#define LX_DISABLE TX_DISABLE
|
||||
#define LX_RESTORE TX_RESTORE
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
/* Disable warning of parameter not used. */
|
||||
#ifndef LX_PARAMETER_NOT_USED
|
||||
@@ -59,6 +145,15 @@
|
||||
#endif /* LX_PARAMETER_NOT_USED */
|
||||
|
||||
|
||||
/* Define basic constants for the LevelX Stack. */
|
||||
#define AZURE_RTOS_LEVELX
|
||||
#define LEVELX_MAJOR_VERSION 6
|
||||
#define LEVELX_MINOR_VERSION 5
|
||||
#define LEVELX_PATCH_VERSION 1
|
||||
#define LEVELX_BUILD_VERSION 202602
|
||||
#define LEVELX_HOTFIX_VERSION ' '
|
||||
|
||||
|
||||
/* Define general LevelX Constants. */
|
||||
|
||||
#define LX_FALSE 0
|
||||
@@ -83,18 +178,23 @@
|
||||
#define LX_NAND_ERROR_NOT_CORRECTED 7
|
||||
#define LX_NO_MEMORY 8
|
||||
#define LX_DISABLED 9
|
||||
#define LX_BAD_BLOCK 10
|
||||
#define LX_NO_BLOCKS 11
|
||||
#define LX_NOT_SUPPORTED 12
|
||||
#define LX_SYSTEM_INVALID_FORMAT 90
|
||||
#define LX_SYSTEM_INVALID_BLOCK 91
|
||||
#define LX_SYSTEM_ALLOCATION_FAILED 92
|
||||
#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 LX_NOR_FLASH_OPENED ((ULONG) 0x4E4F524F)
|
||||
#define LX_NOR_FLASH_CLOSED ((ULONG) 0x4E4F5244)
|
||||
#ifndef LX_NOR_SECTOR_SIZE
|
||||
#define LX_NOR_SECTOR_SIZE (512/sizeof(ULONG))
|
||||
#endif
|
||||
#define LX_NOR_FLASH_MIN_LOGICAL_SECTOR_OFFSET 1
|
||||
#define LX_NOR_FLASH_MAX_LOGICAL_SECTOR_OFFSET 2
|
||||
#ifndef LX_NOR_FLASH_MAX_ERASE_COUNT_DELTA
|
||||
@@ -107,11 +207,16 @@
|
||||
#ifndef LX_NOR_EXTENDED_CACHE_SIZE
|
||||
#define LX_NOR_EXTENDED_CACHE_SIZE 8 /* Maximum number of extended cache sectors. */
|
||||
#endif
|
||||
#ifdef LX_NOR_ENABLE_OBSOLETE_COUNT_CACHE
|
||||
#ifndef LX_NOR_OBSOLETE_COUNT_CACHE_TYPE
|
||||
#define LX_NOR_OBSOLETE_COUNT_CACHE_TYPE UCHAR
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
||||
/* 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:
|
||||
|
||||
/* 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:
|
||||
|
||||
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. */
|
||||
@@ -127,6 +232,19 @@
|
||||
#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 LX_NAND_GOOD_BLOCK 0xFF
|
||||
@@ -139,19 +257,53 @@
|
||||
|
||||
/* 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
|
||||
#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. */
|
||||
#endif
|
||||
#ifndef LX_NAND_ERASE_COUNT_WRITE_SIZE
|
||||
#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
|
||||
#define LX_NAND_FLASH_MAPPING_LIST_UPDATE_DISABLE
|
||||
#endif
|
||||
|
||||
#ifndef LX_NAND_FLASH_MAX_METADATA_BLOCKS
|
||||
#define LX_NAND_FLASH_MAX_METADATA_BLOCKS 4
|
||||
#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
|
||||
#define LX_UTILITY_SHORT_SET(address, value) *((USHORT*)(address)) = (USHORT)(value)
|
||||
#endif
|
||||
|
||||
#ifndef LX_UTILITY_LONG_SET
|
||||
#define LX_UTILITY_LONG_SET(address, value) *((ULONG*)(address)) = (ULONG)(value)
|
||||
#endif
|
||||
|
||||
#ifndef LX_UTILITY_SHORT_GET
|
||||
#define LX_UTILITY_SHORT_GET(address) (*((USHORT*)(address)))
|
||||
#endif
|
||||
|
||||
#ifndef LX_UTILITY_LONG_GET
|
||||
#define LX_UTILITY_LONG_GET(address) (*((ULONG*)(address)))
|
||||
#endif
|
||||
|
||||
/* 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:
|
||||
|
||||
/* 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:
|
||||
|
||||
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. */
|
||||
@@ -170,26 +322,73 @@
|
||||
#define LX_NAND_PAGE_FREE 0xFFFFFFFF
|
||||
#define LX_NAND_PAGE_LIST_VALID 0xF0F0F0F0
|
||||
|
||||
#define LX_NAND_PAGE_TYPE_DEVICE_INFO 0x10000000u
|
||||
#define LX_NAND_PAGE_TYPE_ERASE_COUNT_TABLE 0x20000000u
|
||||
#define LX_NAND_PAGE_TYPE_BLOCK_MAPPING_TABLE 0x30000000u
|
||||
#define LX_NAND_PAGE_TYPE_USER_DATA 0x40000000u
|
||||
#define LX_NAND_PAGE_TYPE_USER_DATA_RELEASED 0x50000000u
|
||||
#define LX_NAND_PAGE_TYPE_READ_COUNT_TABLE 0x60000000u
|
||||
#define LX_NAND_PAGE_TYPE_PAGE_MAPPING_TABLE 0x70000000u
|
||||
#define LX_NAND_PAGE_TYPE_BLOCK_STATUS_TABLE 0x80000000u
|
||||
#define LX_NAND_PAGE_TYPE_BLOCK_LINK 0x90000000u
|
||||
#define LX_NAND_PAGE_TYPE_USER_DATA_MASK 0x0FFFFFFFu
|
||||
#define LX_NAND_PAGE_TYPE_PAGE_NUMBER_MASK 0x000000FFu
|
||||
|
||||
/* Define the NAND flash extra byte structure. This will be set in the spare area of each mapped physical page. */
|
||||
#define LX_NAND_PAGE_TYPE_FREE_PAGE 0xFFFFFF00u
|
||||
|
||||
typedef struct LX_NAND_PAGE_EXTRA_INFO_STRUCT
|
||||
{
|
||||
ULONG lx_nand_page_extra_info_logical_sector;
|
||||
} LX_NAND_PAGE_EXTRA_INFO;
|
||||
|
||||
|
||||
/* Define the NAND flash logical sector cache entry structure. */
|
||||
|
||||
typedef struct LX_NAND_SECTOR_MAPPING_CACHE_ENTRY_STRUCT
|
||||
{
|
||||
#ifndef LX_NAND_FLASH_DIRECT_MAPPING_CACHE
|
||||
ULONG lx_nand_sector_mapping_cache_logical_sector;
|
||||
#define LX_NAND_BLOCK_STATUS_FULL 0x4000u
|
||||
#define LX_NAND_BLOCK_STATUS_NON_SEQUENTIAL 0x2000u
|
||||
#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
|
||||
USHORT lx_nand_sector_mapping_cache_block;
|
||||
USHORT lx_nand_sector_mapping_cache_page;
|
||||
} LX_NAND_SECTOR_MAPPING_CACHE_ENTRY;
|
||||
#define LX_NAND_BLOCK_STATUS_PAGE_NUMBER_MASK 0x0FFFu
|
||||
#define LX_NAND_BLOCK_STATUS_FREE 0xFFFFu
|
||||
#define LX_NAND_BLOCK_STATUS_BAD 0xFF00u
|
||||
#define LX_NAND_BLOCK_STATUS_ALLOCATED 0x8000u
|
||||
|
||||
#define LX_NAND_BLOCK_LINK_MAIN_METADATA_OFFSET 0
|
||||
#define LX_NAND_BLOCK_LINK_BACKUP_METADATA_OFFSET 4
|
||||
|
||||
#define LX_NAND_MAX_BLOCK_COUNT 32768
|
||||
#define LX_NAND_MAX_PAGE_PER_BLOCK 4096
|
||||
|
||||
|
||||
|
||||
#define LX_NAND_BLOCK_UNMAPPED 0xFFFF
|
||||
|
||||
#define LX_NAND_DEVICE_INFO_SIGNATURE1 0x76654C20
|
||||
#define LX_NAND_DEVICE_INFO_SIGNATURE2 0x20586C65
|
||||
|
||||
#define LX_NAND_DEVICE_INFO_METADATA_TYPE_MAIN 0x01
|
||||
#define LX_NAND_DEVICE_INFO_METADATA_TYPE_SECONDARY 0x02
|
||||
|
||||
|
||||
|
||||
|
||||
/* Define the NAND device information structure. This will be set in the spare area. */
|
||||
|
||||
typedef struct LX_NAND_DEVICE_INFO_STRUCT
|
||||
{
|
||||
ULONG lx_nand_device_info_signature1;
|
||||
ULONG lx_nand_device_info_signature2;
|
||||
ULONG lx_nand_device_info_major_version;
|
||||
ULONG lx_nand_device_info_minor_version;
|
||||
ULONG lx_nand_device_info_patch_version;
|
||||
ULONG lx_nand_device_info_metadata_block_number;
|
||||
ULONG lx_nand_device_info_backup_metadata_block_number;
|
||||
ULONG lx_nand_device_info_base_erase_count;
|
||||
} LX_NAND_DEVICE_INFO;
|
||||
|
||||
|
||||
/* Determine if the flash control block has an extension defined. If not,
|
||||
define the extension to whitespace. */
|
||||
|
||||
#ifndef LX_NAND_FLASH_USER_EXTENSION
|
||||
#define LX_NAND_FLASH_USER_EXTENSION
|
||||
#endif
|
||||
|
||||
/* Define the NAND flash control block structure. */
|
||||
|
||||
@@ -204,20 +403,48 @@ typedef struct LX_NAND_FLASH_STRUCT
|
||||
ULONG lx_nand_flash_total_pages;
|
||||
|
||||
ULONG lx_nand_flash_bad_blocks;
|
||||
ULONG lx_nand_flash_free_pages;
|
||||
ULONG lx_nand_flash_mapped_pages;
|
||||
ULONG lx_nand_flash_obsolete_pages;
|
||||
ULONG lx_nand_flash_minimum_erase_count;
|
||||
ULONG lx_nand_flash_maximum_erase_count;
|
||||
ULONG lx_nand_flash_free_block_search;
|
||||
ULONG lx_nand_flash_found_block_search;
|
||||
ULONG lx_nand_flash_found_page_search;
|
||||
ULONG lx_nand_flash_base_erase_count;
|
||||
|
||||
ULONG lx_nand_flash_max_mapped_sector;
|
||||
ULONG lx_nand_flash_page_corrections;
|
||||
ULONG lx_nand_flash_last_block_correction;
|
||||
ULONG lx_nand_flash_last_page_correction;
|
||||
|
||||
USHORT *lx_nand_flash_block_mapping_table;
|
||||
ULONG lx_nand_flash_block_mapping_table_size;
|
||||
USHORT *lx_nand_flash_block_status_table;
|
||||
ULONG lx_nand_flash_block_status_table_size;
|
||||
UCHAR *lx_nand_flash_erase_count_table;
|
||||
ULONG lx_nand_flash_erase_count_table_size;
|
||||
USHORT *lx_nand_flash_block_list;
|
||||
ULONG lx_nand_flash_block_list_size;
|
||||
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_metadata_block_number;
|
||||
ULONG lx_nand_flash_metadata_block_number_current;
|
||||
ULONG lx_nand_flash_metadata_block_number_next;
|
||||
ULONG lx_nand_flash_metadata_block_current_page;
|
||||
ULONG lx_nand_flash_metadata_block_count;
|
||||
USHORT lx_nand_flash_metadata_block[LX_NAND_FLASH_MAX_METADATA_BLOCKS];
|
||||
|
||||
ULONG lx_nand_flash_backup_metadata_block_number;
|
||||
ULONG lx_nand_flash_backup_metadata_block_number_current;
|
||||
ULONG lx_nand_flash_backup_metadata_block_number_next;
|
||||
ULONG lx_nand_flash_backup_metadata_block_current_page;
|
||||
USHORT lx_nand_flash_backup_metadata_block[LX_NAND_FLASH_MAX_METADATA_BLOCKS];
|
||||
|
||||
ULONG lx_nand_flash_spare_data1_offset;
|
||||
ULONG lx_nand_flash_spare_data1_length;
|
||||
ULONG lx_nand_flash_spare_data2_offset;
|
||||
ULONG lx_nand_flash_spare_data2_length;
|
||||
ULONG lx_nand_flash_spare_total_length;
|
||||
|
||||
ULONG lx_nand_flash_diagnostic_system_errors;
|
||||
ULONG lx_nand_flash_diagnostic_system_error;
|
||||
ULONG lx_nand_flash_diagnostic_sector_write_requests;
|
||||
@@ -226,15 +453,6 @@ typedef struct LX_NAND_FLASH_STRUCT
|
||||
ULONG lx_nand_flash_diagnostic_page_allocates;
|
||||
ULONG lx_nand_flash_diagnostic_page_allocate_errors;
|
||||
|
||||
ULONG lx_nand_flash_diagnostic_sector_mapping_cache_hits;
|
||||
ULONG lx_nand_flash_diagnostic_sector_mapping_cache_misses;
|
||||
ULONG lx_nand_flash_diagnostic_page_extra_bytes_cache_hits;
|
||||
ULONG lx_nand_flash_diagnostic_page_extra_bytes_cache_misses;
|
||||
ULONG lx_nand_flash_diagnostic_page_0_cache_hits;
|
||||
ULONG lx_nand_flash_diagnostic_page_0_cache_misses;
|
||||
ULONG lx_nand_flash_diagnostic_block_status_cache_hits;
|
||||
ULONG lx_nand_flash_diagnostic_block_status_cache_misses;
|
||||
|
||||
ULONG lx_nand_flash_diagnostic_block_reclaim_attempts;
|
||||
ULONG lx_nand_flash_diagnostic_block_erases;
|
||||
ULONG lx_nand_flash_diagnostic_block_status_gets;
|
||||
@@ -246,17 +464,23 @@ typedef struct LX_NAND_FLASH_STRUCT
|
||||
ULONG lx_nand_flash_diagnostic_moved_pages;
|
||||
ULONG lx_nand_flash_diagnostic_block_erased_verifies;
|
||||
ULONG lx_nand_flash_diagnostic_page_erased_verifies;
|
||||
|
||||
ULONG lx_nand_flash_diagnostic_initial_format;
|
||||
ULONG lx_nand_flash_diagnostic_erased_block;
|
||||
ULONG lx_nand_flash_diagnostic_re_erase_block;
|
||||
ULONG lx_nand_flash_diagnostic_page_being_obsoleted;
|
||||
ULONG lx_nand_flash_diagnostic_page_obsoleted;
|
||||
ULONG lx_nand_flash_diagnostic_mapping_invalid;
|
||||
ULONG lx_nand_flash_diagnostic_mapping_write_interrupted;
|
||||
ULONG lx_nand_flash_diagnostic_page_not_free;
|
||||
ULONG lx_nand_flash_diagnostic_page_data_not_free;
|
||||
|
||||
#ifdef LX_NAND_ENABLE_CONTROL_BLOCK_FOR_DRIVER_INTERFACE
|
||||
UINT (*lx_nand_flash_driver_read)(struct LX_NAND_FLASH_STRUCT *nand_flash, ULONG block, ULONG page, ULONG *destination, ULONG words);
|
||||
UINT (*lx_nand_flash_driver_write)(struct LX_NAND_FLASH_STRUCT *nand_flash, ULONG block, ULONG page, ULONG *source, ULONG words);
|
||||
UINT (*lx_nand_flash_driver_block_erase)(struct LX_NAND_FLASH_STRUCT *nand_flash, ULONG block, ULONG erase_count);
|
||||
UINT (*lx_nand_flash_driver_block_erased_verify)(struct LX_NAND_FLASH_STRUCT *nand_flash, ULONG block);
|
||||
UINT (*lx_nand_flash_driver_page_erased_verify)(struct LX_NAND_FLASH_STRUCT *nand_flash, ULONG block, ULONG page);
|
||||
UINT (*lx_nand_flash_driver_block_status_get)(struct LX_NAND_FLASH_STRUCT *nand_flash, ULONG block, UCHAR *bad_block_flag);
|
||||
UINT (*lx_nand_flash_driver_block_status_set)(struct LX_NAND_FLASH_STRUCT *nand_flash, ULONG block, UCHAR bad_block_flag);
|
||||
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_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_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);
|
||||
#else
|
||||
UINT (*lx_nand_flash_driver_read)(ULONG block, ULONG page, ULONG *destination, ULONG words);
|
||||
UINT (*lx_nand_flash_driver_write)(ULONG block, ULONG page, ULONG *source, ULONG words);
|
||||
UINT (*lx_nand_flash_driver_block_erase)(ULONG block, ULONG erase_count);
|
||||
@@ -267,20 +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_set)(ULONG block, ULONG page, UCHAR *source, UINT size);
|
||||
UINT (*lx_nand_flash_driver_system_error)(UINT error_code, ULONG block, ULONG page);
|
||||
|
||||
ULONG *lx_nand_flash_page_buffer;
|
||||
UINT lx_nand_flash_sector_mapping_cache_enabled;
|
||||
LX_NAND_SECTOR_MAPPING_CACHE_ENTRY
|
||||
lx_nand_flash_sector_mapping_cache[LX_NAND_SECTOR_MAPPING_CACHE_SIZE];
|
||||
|
||||
|
||||
/* Define the extended cache structures for block status, page extra bytes, and block page 0 caches. The memory for these cache
|
||||
extensions is optionally supplied by the application after the lx_nand_flash_open call has been made. */
|
||||
|
||||
UCHAR *lx_nand_flash_block_status_cache;
|
||||
LX_NAND_PAGE_EXTRA_INFO *lx_nand_flash_page_extra_bytes_cache;
|
||||
ULONG *lx_nand_flash_page_0_cache;
|
||||
|
||||
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_copy)(ULONG source_block, ULONG source_page, ULONG destination_block, ULONG destination_page, ULONG pages, UCHAR* data_buffer);
|
||||
#endif
|
||||
UCHAR *lx_nand_flash_page_buffer;
|
||||
UINT lx_nand_flash_page_buffer_size;
|
||||
#ifdef LX_THREAD_SAFE_ENABLE
|
||||
|
||||
/* When this conditional is used, the LevelX code utilizes a ThreadX mutex for thread
|
||||
@@ -288,11 +505,17 @@ typedef struct LX_NAND_FLASH_STRUCT
|
||||
a higher layer. */
|
||||
TX_MUTEX lx_nand_flash_mutex;
|
||||
#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. */
|
||||
struct LX_NAND_FLASH_STRUCT *lx_nand_flash_open_next,
|
||||
*lx_nand_flash_open_previous;
|
||||
|
||||
|
||||
/* Define the user extension in the flash control block. This
|
||||
is typically defined in lx_user.h. */
|
||||
LX_NAND_FLASH_USER_EXTENSION
|
||||
|
||||
} LX_NAND_FLASH;
|
||||
|
||||
|
||||
@@ -302,7 +525,7 @@ typedef struct LX_NAND_FLASH_STRUCT
|
||||
typedef struct LX_NOR_SECTOR_MAPPING_CACHE_ENTRY_STRUCT
|
||||
{
|
||||
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;
|
||||
} LX_NOR_SECTOR_MAPPING_CACHE_ENTRY;
|
||||
|
||||
@@ -311,12 +534,19 @@ typedef struct LX_NOR_SECTOR_MAPPING_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_access_count;
|
||||
} LX_NOR_FLASH_EXTENDED_CACHE_ENTRY;
|
||||
|
||||
|
||||
/* Determine if the flash control block has an extension defined. If not,
|
||||
define the extension to whitespace. */
|
||||
|
||||
#ifndef LX_NOR_FLASH_USER_EXTENSION
|
||||
#define LX_NOR_FLASH_USER_EXTENSION
|
||||
#endif
|
||||
|
||||
/* Define the NOR flash control block structure. */
|
||||
|
||||
typedef struct LX_NOR_FLASH_STRUCT
|
||||
@@ -338,11 +568,12 @@ typedef struct LX_NOR_FLASH_STRUCT
|
||||
ULONG lx_nor_flash_mapped_physical_sectors;
|
||||
ULONG lx_nor_flash_obsolete_physical_sectors;
|
||||
ULONG lx_nor_flash_minimum_erase_count;
|
||||
ULONG lx_nor_flash_minimum_erased_blocks;
|
||||
ULONG lx_nor_flash_maximum_erase_count;
|
||||
|
||||
ULONG lx_nor_flash_free_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_read_requests;
|
||||
@@ -362,15 +593,23 @@ typedef struct LX_NOR_FLASH_STRUCT
|
||||
ULONG lx_nor_flash_diagnostic_sector_not_free;
|
||||
ULONG lx_nor_flash_diagnostic_sector_data_not_free;
|
||||
|
||||
#ifdef LX_NOR_ENABLE_CONTROL_BLOCK_FOR_DRIVER_INTERFACE
|
||||
UINT (*lx_nor_flash_driver_read)(struct LX_NOR_FLASH_STRUCT *nor_flash, ULONG *flash_address, ULONG *destination, ULONG words);
|
||||
UINT (*lx_nor_flash_driver_write)(struct LX_NOR_FLASH_STRUCT *nor_flash, ULONG *flash_address, ULONG *source, ULONG words);
|
||||
UINT (*lx_nor_flash_driver_block_erase)(struct LX_NOR_FLASH_STRUCT *nor_flash, ULONG block, ULONG erase_count);
|
||||
UINT (*lx_nor_flash_driver_block_erased_verify)(struct LX_NOR_FLASH_STRUCT *nor_flash, ULONG block);
|
||||
UINT (*lx_nor_flash_driver_system_error)(struct LX_NOR_FLASH_STRUCT *nor_flash, UINT error_code);
|
||||
#else
|
||||
UINT (*lx_nor_flash_driver_read)(ULONG *flash_address, ULONG *destination, ULONG words);
|
||||
UINT (*lx_nor_flash_driver_write)(ULONG *flash_address, ULONG *source, ULONG words);
|
||||
UINT (*lx_nor_flash_driver_block_erase)(ULONG block, ULONG erase_count);
|
||||
UINT (*lx_nor_flash_driver_block_erased_verify)(ULONG block);
|
||||
UINT (*lx_nor_flash_driver_system_error)(UINT error_code);
|
||||
#endif
|
||||
|
||||
ULONG *lx_nor_flash_sector_buffer;
|
||||
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];
|
||||
|
||||
#ifndef LX_NOR_DISABLE_EXTENDED_CACHE
|
||||
@@ -380,6 +619,15 @@ typedef struct LX_NOR_FLASH_STRUCT
|
||||
lx_nor_flash_extended_cache[LX_NOR_EXTENDED_CACHE_SIZE];
|
||||
ULONG lx_nor_flash_extended_cache_hits;
|
||||
ULONG lx_nor_flash_extended_cache_misses;
|
||||
#ifdef LX_NOR_ENABLE_MAPPING_BITMAP
|
||||
ULONG *lx_nor_flash_extended_cache_mapping_bitmap;
|
||||
ULONG lx_nor_flash_extended_cache_mapping_bitmap_max_logical_sector;
|
||||
#endif
|
||||
#ifdef LX_NOR_ENABLE_OBSOLETE_COUNT_CACHE
|
||||
LX_NOR_OBSOLETE_COUNT_CACHE_TYPE
|
||||
*lx_nor_flash_extended_cache_obsolete_count;
|
||||
ULONG lx_nor_flash_extended_cache_obsolete_count_max_block;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef LX_THREAD_SAFE_ENABLE
|
||||
@@ -389,35 +637,40 @@ typedef struct LX_NOR_FLASH_STRUCT
|
||||
a higher layer. */
|
||||
TX_MUTEX lx_nor_flash_mutex;
|
||||
#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. */
|
||||
struct LX_NOR_FLASH_STRUCT *lx_nor_flash_open_next,
|
||||
*lx_nor_flash_open_previous;
|
||||
|
||||
|
||||
/* Define the user extension in the flash control block. This
|
||||
is typically defined in lx_user.h. */
|
||||
LX_NOR_FLASH_USER_EXTENSION
|
||||
|
||||
} LX_NOR_FLASH;
|
||||
|
||||
|
||||
/* Each physical NOR block has the following structure at the beginning of the block:
|
||||
|
||||
Offset Meaning
|
||||
|
||||
|
||||
0 Erase count
|
||||
4 Minimum 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
|
||||
. 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
|
||||
like the following:
|
||||
|
||||
|
||||
Bit(s) Meaning
|
||||
|
||||
|
||||
0-29 Logical sector mapped if not 0x3FFFFFFF
|
||||
30 If 0, entry is being superceded
|
||||
31 If 1, entry is valid
|
||||
|
||||
|
||||
Array of physical sectors, with each of size LX_NOR_SECTOR_SIZE
|
||||
*/
|
||||
*/
|
||||
|
||||
|
||||
typedef struct LX_NOR_FLASH_BLOCK_HEADER_STRUCT
|
||||
@@ -443,13 +696,19 @@ extern ULONG _lx_nor_flash_opened_cou
|
||||
#define lx_nand_flash_defragment _lx_nand_flash_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_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_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_compute _lx_nand_flash_page_ecc_compute
|
||||
#define lx_nand_flash_sector_read _lx_nand_flash_sector_read
|
||||
#define lx_nand_flash_sector_release _lx_nand_flash_sector_release
|
||||
#define lx_nand_flash_sector_write _lx_nand_flash_sector_write
|
||||
#define lx_nand_flash_sectors_read _lx_nand_flash_sectors_read
|
||||
#define lx_nand_flash_sectors_release _lx_nand_flash_sectors_release
|
||||
#define lx_nand_flash_sectors_write _lx_nand_flash_sectors_write
|
||||
#define lx_nand_flash_256byte_ecc_check _lx_nand_flash_256byte_ecc_check
|
||||
#define lx_nand_flash_256byte_ecc_compute _lx_nand_flash_256byte_ecc_compute
|
||||
|
||||
@@ -458,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_extended_cache_enable _lx_nor_flash_extended_cache_enable
|
||||
#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_extended _lx_nor_flash_open_extended
|
||||
#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_write _lx_nor_flash_sector_write
|
||||
@@ -471,19 +732,33 @@ UINT _lx_nand_flash_close(LX_NAND_FLASH *nand_flash);
|
||||
UINT _lx_nand_flash_defragment(LX_NAND_FLASH *nand_flash);
|
||||
UINT _lx_nand_flash_initialize(void);
|
||||
UINT _lx_nand_flash_extended_cache_enable(LX_NAND_FLASH *nand_flash, VOID *memory, ULONG size);
|
||||
UINT _lx_nand_flash_open(LX_NAND_FLASH *nand_flash, CHAR *name, UINT (*nand_driver_initialize)(LX_NAND_FLASH *));
|
||||
UINT _lx_nand_flash_format(LX_NAND_FLASH* nand_flash, CHAR* name,
|
||||
UINT(*nand_driver_initialize)(LX_NAND_FLASH*),
|
||||
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_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_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_sector_read(LX_NAND_FLASH *nand_flash, ULONG logical_sector, VOID *buffer);
|
||||
UINT _lx_nand_flash_sector_release(LX_NAND_FLASH *nand_flash, ULONG logical_sector);
|
||||
UINT _lx_nand_flash_sector_write(LX_NAND_FLASH *nand_flash, ULONG logical_sector, VOID *buffer);
|
||||
UINT _lx_nand_flash_sectors_read(LX_NAND_FLASH* nand_flash, ULONG logical_sector, VOID* buffer, ULONG sector_count);
|
||||
UINT _lx_nand_flash_sectors_release(LX_NAND_FLASH* nand_flash, ULONG logical_sector, ULONG sector_count);
|
||||
UINT _lx_nand_flash_sectors_write(LX_NAND_FLASH* nand_flash, ULONG logical_sector, VOID* buffer, ULONG sector_count);
|
||||
|
||||
UINT _lx_nor_flash_close(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_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_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_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);
|
||||
@@ -492,28 +767,35 @@ UINT _lx_nor_flash_sector_write(LX_NOR_FLASH *nor_flash, ULONG logical_sector
|
||||
|
||||
/* Internal LevelX prototypes. */
|
||||
|
||||
UINT _lx_nand_flash_block_full_update(LX_NAND_FLASH *nand_flash, ULONG block, ULONG erase_count);
|
||||
VOID _lx_nand_flash_block_obsoleted_check(LX_NAND_FLASH *nand_flash, ULONG block);
|
||||
UINT _lx_nand_flash_block_reclaim(LX_NAND_FLASH *nand_flash);
|
||||
|
||||
UINT _lx_nand_flash_driver_read(LX_NAND_FLASH *nand_flash, ULONG block, ULONG page, ULONG *destination, ULONG words);
|
||||
UINT _lx_nand_flash_driver_write(LX_NAND_FLASH *nand_flash, ULONG block, ULONG page, ULONG *source, ULONG words);
|
||||
UINT _lx_nand_flash_driver_block_erase(LX_NAND_FLASH *nand_flash, ULONG block, ULONG erase_count);
|
||||
UINT _lx_nand_flash_driver_block_erased_verify(LX_NAND_FLASH *nand_flash, ULONG block);
|
||||
UINT _lx_nand_flash_driver_page_erased_verify(LX_NAND_FLASH *nand_flash, ULONG block, ULONG page);
|
||||
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_set(LX_NAND_FLASH *nand_flash, ULONG block, UCHAR bad_block_flag);
|
||||
UINT _lx_nand_flash_driver_extra_bytes_get(LX_NAND_FLASH *nand_flash, ULONG block, ULONG page, UCHAR *destination, UINT size);
|
||||
UINT _lx_nand_flash_driver_extra_bytes_set(LX_NAND_FLASH *nand_flash, ULONG block, ULONG page, UCHAR *source, UINT size);
|
||||
|
||||
VOID _lx_nand_flash_internal_error(LX_NAND_FLASH *nand_flash, ULONG error_code);
|
||||
UINT _lx_nand_flash_logical_sector_find(LX_NAND_FLASH *nand_flash, ULONG logical_sector, ULONG superceded_check, ULONG *block, ULONG *page);
|
||||
UINT _lx_nand_flash_next_block_to_erase_find(LX_NAND_FLASH *nand_flash, ULONG *return_erase_block, ULONG *return_erase_count, ULONG *return_mapped_pages, ULONG *return_obsolete_pages);
|
||||
UINT _lx_nand_flash_physical_page_allocate(LX_NAND_FLASH *nand_flash, ULONG *block, ULONG *page, ULONG *erase_count);
|
||||
VOID _lx_nand_flash_sector_mapping_cache_invalidate(LX_NAND_FLASH *nand_flash, ULONG logical_sector);
|
||||
UINT _lx_nand_flash_block_find(LX_NAND_FLASH *nand_flash, ULONG logical_sector, ULONG *block, USHORT *block_status);
|
||||
UINT _lx_nand_flash_block_allocate(LX_NAND_FLASH *nand_flash, ULONG *block);
|
||||
UINT _lx_nand_flash_block_data_move(LX_NAND_FLASH* nand_flash, ULONG new_block);
|
||||
UINT _lx_nand_flash_block_status_set(LX_NAND_FLASH *nand_flash, ULONG block, ULONG block_status);
|
||||
UINT _lx_nand_flash_erase_count_set(LX_NAND_FLASH* nand_flash, ULONG block, UCHAR erase_count);
|
||||
UINT _lx_nand_flash_block_mapping_set(LX_NAND_FLASH* nand_flash, ULONG logical_sector, ULONG block);
|
||||
UINT _lx_nand_flash_data_page_copy(LX_NAND_FLASH* nand_flash, ULONG logical_sector, ULONG source_block, USHORT src_block_status,
|
||||
ULONG destination_block, USHORT* dest_block_status_ptr, ULONG sectors);
|
||||
UINT _lx_nand_flash_free_block_list_add(LX_NAND_FLASH* nand_flash, ULONG block);
|
||||
UINT _lx_nand_flash_mapped_block_list_add(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);
|
||||
UINT _lx_nand_flash_mapped_block_list_remove(LX_NAND_FLASH* nand_flash, ULONG block_mapping_index);
|
||||
UINT _lx_nand_flash_memory_initialize(LX_NAND_FLASH* nand_flash, ULONG* memory_ptr, UINT memory_size);
|
||||
UINT _lx_nand_flash_metadata_allocate(LX_NAND_FLASH* nand_flash);
|
||||
UINT _lx_nand_flash_metadata_build(LX_NAND_FLASH* nand_flash);
|
||||
UINT _lx_nand_flash_metadata_write(LX_NAND_FLASH *nand_flash, UCHAR* main_buffer, ULONG spare_value);
|
||||
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_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_driver_block_erase(LX_NOR_FLASH *nor_flash, ULONG block, ULONG erase_count);
|
||||
@@ -526,5 +808,10 @@ UINT _lx_nor_flash_physical_sector_allocate(LX_NOR_FLASH *nor_flash, ULONG lo
|
||||
VOID _lx_nor_flash_sector_mapping_cache_invalidate(LX_NOR_FLASH *nor_flash, ULONG logical_sector);
|
||||
VOID _lx_nor_flash_system_error(LX_NOR_FLASH *nor_flash, UINT error_code);
|
||||
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
@@ -0,0 +1,139 @@
|
||||
/***************************************************************************
|
||||
* Copyright (c) 2024 Microsoft Corporation
|
||||
* Copyright (c) 2026-present Eclipse ThreadX contributors
|
||||
*
|
||||
* This program and the accompanying materials are made available under the
|
||||
* terms of the MIT License which is available at
|
||||
* https://opensource.org/licenses/MIT.
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
**************************************************************************/
|
||||
|
||||
|
||||
/**************************************************************************/
|
||||
/**************************************************************************/
|
||||
/** */
|
||||
/** LevelX Component */
|
||||
/** */
|
||||
/** User Specific */
|
||||
/** */
|
||||
/**************************************************************************/
|
||||
/**************************************************************************/
|
||||
|
||||
|
||||
/**************************************************************************/
|
||||
/* */
|
||||
/* PORT SPECIFIC C INFORMATION RELEASE */
|
||||
/* */
|
||||
/* lx_user.h PORTABLE C */
|
||||
/* 6.3.0 */
|
||||
/* */
|
||||
/* AUTHOR */
|
||||
/* */
|
||||
/* William E. Lamie, Microsoft Corporation */
|
||||
/* */
|
||||
/* DESCRIPTION */
|
||||
/* */
|
||||
/* This file contains user defines for configuring LevelX in specific */
|
||||
/* ways. This file will have an effect only if the application and */
|
||||
/* LevelX library are built with LX_INCLUDE_USER_DEFINE_FILE defined. */
|
||||
/* Note that all the defines in this file may also be made on the */
|
||||
/* command line when building LevelX library and application objects. */
|
||||
/* */
|
||||
/**************************************************************************/
|
||||
|
||||
#ifndef LX_USER_H
|
||||
#define LX_USER_H
|
||||
|
||||
|
||||
|
||||
/* Defined, this option bypasses the NOR flash driver read routine in favor or reading
|
||||
the NOR memory directly, resulting in a significant performance increase.
|
||||
*/
|
||||
/*
|
||||
#define LX_DIRECT_READ
|
||||
*/
|
||||
|
||||
|
||||
/* Defined, this causes the LevelX NOR instance open logic to verify free NOR
|
||||
sectors are all ones.
|
||||
*/
|
||||
/*
|
||||
#define LX_FREE_SECTOR_DATA_VERIFY
|
||||
*/
|
||||
|
||||
/* By default this value is 4, which represents a maximum of 4 blocks that
|
||||
can be allocated for metadata.
|
||||
*/
|
||||
/*
|
||||
#define LX_NAND_FLASH_MAX_METADATA_BLOCKS 4
|
||||
*/
|
||||
|
||||
/* Defined, this disabled the extended NOR cache. */
|
||||
/*
|
||||
#define LX_NOR_DISABLE_EXTENDED_CACHE
|
||||
*/
|
||||
|
||||
/* By default this value is 8, which represents a maximum of 8 sectors that
|
||||
can be cached in a NOR instance.
|
||||
*/
|
||||
/*
|
||||
#define LX_NOR_EXTENDED_CACHE_SIZE 8
|
||||
*/
|
||||
|
||||
|
||||
/* 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
|
||||
values must be a power of 2.
|
||||
*/
|
||||
/*
|
||||
#define LX_NOR_SECTOR_MAPPING_CACHE_SIZE 16
|
||||
*/
|
||||
|
||||
/* Defined, this makes LevelX thread-safe by using a ThreadX mutex object
|
||||
throughout the API.
|
||||
*/
|
||||
/*
|
||||
#define LX_THREAD_SAFE_ENABLE
|
||||
*/
|
||||
|
||||
/* Defined, LevelX will be used in standalone mode (without Azure RTOS ThreadX) */
|
||||
|
||||
/* #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 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 LX_NAND_FLASH_USER_EXTENSION ????
|
||||
*/
|
||||
|
||||
/* 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. */
|
||||
/*
|
||||
#define LX_NOR_ENABLE_MAPPING_BITMAP
|
||||
*/
|
||||
|
||||
/* 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,
|
||||
and the rest of the cache memory is allocated to sector 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. */
|
||||
/*
|
||||
#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.
|
||||
This sector size should match the sector size used in file system. */
|
||||
/*
|
||||
#define LX_NOR_SECTOR_SIZE (512/sizeof(ULONG))
|
||||
*/
|
||||
|
||||
#endif
|
||||
|
||||
@@ -1,19 +1,19 @@
|
||||
/**************************************************************************/
|
||||
/* */
|
||||
/* Copyright (c) Microsoft Corporation. All rights reserved. */
|
||||
/* */
|
||||
/* This software is licensed under the Microsoft Software License */
|
||||
/* Terms for Microsoft Azure RTOS. Full text of the license can be */
|
||||
/* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */
|
||||
/* and in the root directory of this software. */
|
||||
/* */
|
||||
/**************************************************************************/
|
||||
/***************************************************************************
|
||||
* Copyright (c) 2024 Microsoft Corporation
|
||||
* Copyright (c) 2026-present Eclipse ThreadX contributors
|
||||
*
|
||||
* This program and the accompanying materials are made available under the
|
||||
* terms of the MIT License which is available at
|
||||
* https://opensource.org/licenses/MIT.
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
**************************************************************************/
|
||||
|
||||
|
||||
/**************************************************************************/
|
||||
/**************************************************************************/
|
||||
/** */
|
||||
/** FileX Component */
|
||||
/** */
|
||||
/** FileX Component */
|
||||
/** */
|
||||
/** FileX NAND FLASH Simulator Driver */
|
||||
/** */
|
||||
@@ -23,7 +23,6 @@
|
||||
|
||||
/* Include necessary system files. */
|
||||
|
||||
#include "tx_api.h"
|
||||
#include "fx_api.h"
|
||||
#include "lx_api.h"
|
||||
|
||||
@@ -32,6 +31,9 @@
|
||||
|
||||
LX_NAND_FLASH nand_flash;
|
||||
|
||||
/* Memory buffer size should be at least 7 * total block count + 2 * page size,
|
||||
that is 7 * 1024 + 2 * 528 = 8224 bytes */
|
||||
ULONG lx_memory_buffer[8224 / sizeof (ULONG)];
|
||||
|
||||
/* Define the NAND flash simulation initialization function. */
|
||||
|
||||
@@ -41,22 +43,22 @@ VOID _fx_nand_flash_write_sectors(ULONG logical_sector, ULONG sectors, UCHAR *s
|
||||
|
||||
|
||||
/* The simulated NAND driver relies on the fx_media_format call to be made prior to
|
||||
the fx_media_open call.
|
||||
the fx_media_open call.
|
||||
|
||||
fx_media_format(&ram_disk,
|
||||
fx_media_format(&ram_disk,
|
||||
_fx_nand_sim_driver, // Driver entry
|
||||
FX_NULL, // Unused
|
||||
media_memory, // Media buffer pointer
|
||||
sizeof(media_memory), // Media buffer size
|
||||
sizeof(media_memory), // Media buffer size
|
||||
"MY_NAND_DISK", // Volume Name
|
||||
1, // Number of FATs
|
||||
32, // Directory Entries
|
||||
0, // Hidden sectors
|
||||
120, // Total sectors
|
||||
2048, // Sector size
|
||||
120, // Total sectors
|
||||
2048, // Sector size
|
||||
1, // Sectors per cluster
|
||||
1, // Heads
|
||||
1); // Sectors per track
|
||||
1); // Sectors per track
|
||||
|
||||
*/
|
||||
|
||||
@@ -64,62 +66,56 @@ VOID _fx_nand_flash_write_sectors(ULONG logical_sector, ULONG sectors, UCHAR *s
|
||||
VOID _fx_nand_flash_simulator_driver(FX_MEDIA *media_ptr);
|
||||
|
||||
|
||||
/**************************************************************************/
|
||||
/* */
|
||||
/* FUNCTION RELEASE */
|
||||
/* */
|
||||
/* _fx_nand_simulator_driver PORTABLE C */
|
||||
/* 6.0 */
|
||||
/**************************************************************************/
|
||||
/* */
|
||||
/* FUNCTION RELEASE */
|
||||
/* */
|
||||
/* _fx_nand_simulator_driver PORTABLE C */
|
||||
/* 6.2.1 */
|
||||
/* AUTHOR */
|
||||
/* */
|
||||
/* William E. Lamie, Microsoft Corporation */
|
||||
/* */
|
||||
/* DESCRIPTION */
|
||||
/* */
|
||||
/* This function is the entry point to the generic NAND simulated */
|
||||
/* disk driver that is delivered with the flash wear leveling product */
|
||||
/* LevelX. */
|
||||
/* */
|
||||
/* This driver also serves as a template for developing other LevelX */
|
||||
/* NAND flash drivers for actual flash devices. Simply replace the */
|
||||
/* read/write sector logic with calls to read/write from the */
|
||||
/* appropriate physical device access functions. */
|
||||
/* */
|
||||
/* FileX NAND FLASH structures look like the following: */
|
||||
/* */
|
||||
/* Logical Sector Contents */
|
||||
/* */
|
||||
/* 0 Boot record */
|
||||
/* 1 FAT Area Start */
|
||||
/* +FAT Sectors Root Directory Start */
|
||||
/* +Directory Sectors Data Sector Start */
|
||||
/* */
|
||||
/* */
|
||||
/* INPUT */
|
||||
/* */
|
||||
/* media_ptr Media control block pointer */
|
||||
/* */
|
||||
/* OUTPUT */
|
||||
/* */
|
||||
/* None */
|
||||
/* */
|
||||
/* CALLS */
|
||||
/* */
|
||||
/* _lx_nand_flash_close Close NAND flash manager */
|
||||
/* _lx_nand_flash_open Open NAND flash manager */
|
||||
/* _lx_nand_flash_sector_read Read a NAND sector */
|
||||
/* _lx_nand_flash_sector_release Release a NAND sector */
|
||||
/* _lx_nand_flash_sector_write Write a NAND sector */
|
||||
/* */
|
||||
/* CALLED BY */
|
||||
/* */
|
||||
/* FileX System Functions */
|
||||
/* */
|
||||
/* RELEASE HISTORY */
|
||||
/* */
|
||||
/* DATE NAME DESCRIPTION */
|
||||
/* DESCRIPTION */
|
||||
/* */
|
||||
/* 05-19-2020 William E. Lamie Initial Version 6.0 */
|
||||
/* This function is the entry point to the generic NAND simulated */
|
||||
/* disk driver that is delivered with the flash wear leveling product */
|
||||
/* LevelX. */
|
||||
/* */
|
||||
/* This driver also serves as a template for developing other LevelX */
|
||||
/* NAND flash drivers for actual flash devices. Simply replace the */
|
||||
/* read/write sector logic with calls to read/write from the */
|
||||
/* appropriate physical device access functions. */
|
||||
/* */
|
||||
/* FileX NAND FLASH structures look like the following: */
|
||||
/* */
|
||||
/* Logical Sector Contents */
|
||||
/* */
|
||||
/* 0 Boot record */
|
||||
/* 1 FAT Area Start */
|
||||
/* +FAT Sectors Root Directory Start */
|
||||
/* +Directory Sectors Data Sector Start */
|
||||
/* */
|
||||
/* */
|
||||
/* INPUT */
|
||||
/* */
|
||||
/* media_ptr Media control block pointer */
|
||||
/* */
|
||||
/* OUTPUT */
|
||||
/* */
|
||||
/* None */
|
||||
/* */
|
||||
/* CALLS */
|
||||
/* */
|
||||
/* _lx_nand_flash_close Close NAND flash manager */
|
||||
/* _lx_nand_flash_open Open NAND flash manager */
|
||||
/* _lx_nand_flash_sector_read Read a NAND sector */
|
||||
/* _lx_nand_flash_sector_release Release a NAND sector */
|
||||
/* _lx_nand_flash_sector_write Write a NAND sector */
|
||||
/* */
|
||||
/* CALLED BY */
|
||||
/* */
|
||||
/* FileX System Functions */
|
||||
/* */
|
||||
/**************************************************************************/
|
||||
VOID _fx_nand_flash_simulator_driver(FX_MEDIA *media_ptr)
|
||||
@@ -129,19 +125,19 @@ ULONG logical_sector;
|
||||
ULONG count;
|
||||
UCHAR *buffer;
|
||||
UINT status;
|
||||
|
||||
|
||||
|
||||
/* There are several useful/important pieces of information contained in the media
|
||||
structure, some of which are supplied by FileX and others are for the driver to
|
||||
setup. The following is a summary of the necessary FX_MEDIA structure members:
|
||||
|
||||
|
||||
FX_MEDIA Member Meaning
|
||||
|
||||
fx_media_driver_request FileX request type. Valid requests from FileX are
|
||||
|
||||
fx_media_driver_request FileX request type. Valid requests from FileX are
|
||||
as follows:
|
||||
|
||||
FX_DRIVER_READ
|
||||
FX_DRIVER_WRITE
|
||||
FX_DRIVER_WRITE
|
||||
FX_DRIVER_FLUSH
|
||||
FX_DRIVER_ABORT
|
||||
FX_DRIVER_INIT
|
||||
@@ -150,11 +146,11 @@ UINT status;
|
||||
FX_DRIVER_BOOT_WRITE
|
||||
FX_DRIVER_UNINIT
|
||||
|
||||
fx_media_driver_status This value is RETURNED by the driver. If the
|
||||
fx_media_driver_status This value is RETURNED by the driver. If the
|
||||
operation is successful, this field should be
|
||||
set to FX_SUCCESS for before returning. Otherwise,
|
||||
if an error occurred, this field should be set
|
||||
to FX_IO_ERROR.
|
||||
to FX_IO_ERROR.
|
||||
|
||||
fx_media_driver_buffer Pointer to buffer to read or write sector data.
|
||||
This is supplied by FileX.
|
||||
@@ -165,24 +161,24 @@ UINT status;
|
||||
|
||||
|
||||
The following is a summary of the optional FX_MEDIA structure members:
|
||||
|
||||
|
||||
FX_MEDIA Member Meaning
|
||||
|
||||
|
||||
fx_media_driver_info Pointer to any additional information or memory.
|
||||
This is optional for the driver use and is setup
|
||||
from the fx_media_open call. The RAM disk uses
|
||||
this pointer for the RAM disk memory itself.
|
||||
|
||||
fx_media_driver_write_protect The DRIVER sets this to FX_TRUE when media is write
|
||||
protected. This is typically done in initialization,
|
||||
fx_media_driver_write_protect The DRIVER sets this to FX_TRUE when media is write
|
||||
protected. This is typically done in initialization,
|
||||
but can be done anytime.
|
||||
|
||||
fx_media_driver_free_sector_update The DRIVER sets this to FX_TRUE when it needs to
|
||||
fx_media_driver_free_sector_update The DRIVER sets this to FX_TRUE when it needs to
|
||||
know when clusters are released. This is important
|
||||
for FLASH wear-leveling drivers.
|
||||
|
||||
fx_media_driver_system_write FileX sets this flag to FX_TRUE if the sector being
|
||||
written is a system sector, e.g., a boot, FAT, or
|
||||
written is a system sector, e.g., a boot, FAT, or
|
||||
directory sector. The driver may choose to use this
|
||||
to initiate error recovery logic for greater fault
|
||||
tolerance.
|
||||
@@ -190,15 +186,15 @@ UINT status;
|
||||
fx_media_driver_data_sector_read FileX sets this flag to FX_TRUE if the sector(s) being
|
||||
read are file data sectors, i.e., NOT system sectors.
|
||||
|
||||
fx_media_driver_sector_type FileX sets this variable to the specific type of
|
||||
fx_media_driver_sector_type FileX sets this variable to the specific type of
|
||||
sector being read or written. The following sector
|
||||
types are identified:
|
||||
|
||||
FX_UNKNOWN_SECTOR
|
||||
FX_UNKNOWN_SECTOR
|
||||
FX_BOOT_SECTOR
|
||||
FX_FAT_SECTOR
|
||||
FX_DIRECTORY_SECTOR
|
||||
FX_DATA_SECTOR
|
||||
FX_DATA_SECTOR
|
||||
*/
|
||||
|
||||
/* Process the driver request specified in the media control block. */
|
||||
@@ -217,18 +213,18 @@ UINT status;
|
||||
|
||||
/* Call LevelX to read one flash sector. */
|
||||
status = _lx_nand_flash_sector_read(&nand_flash, logical_sector, buffer);
|
||||
|
||||
|
||||
/* Determine if the read was successful. */
|
||||
if (status != LX_SUCCESS)
|
||||
{
|
||||
|
||||
|
||||
/* Return an I/O error to FileX. */
|
||||
media_ptr -> fx_media_driver_status = FX_IO_ERROR;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
/* Successful sector read. */
|
||||
return;
|
||||
}
|
||||
|
||||
/* Successful sector read. */
|
||||
count--;
|
||||
logical_sector++;
|
||||
buffer += media_ptr -> fx_media_bytes_per_sector;
|
||||
@@ -237,12 +233,12 @@ UINT status;
|
||||
media_ptr -> fx_media_driver_status = FX_SUCCESS;
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
case FX_DRIVER_WRITE:
|
||||
{
|
||||
|
||||
/* Write sector(s) to NAND flash. */
|
||||
logical_sector = media_ptr -> fx_media_driver_logical_sector;
|
||||
logical_sector = media_ptr -> fx_media_driver_logical_sector;
|
||||
count = media_ptr -> fx_media_driver_sectors;
|
||||
buffer = (UCHAR *) media_ptr -> fx_media_driver_buffer;
|
||||
while (count)
|
||||
@@ -254,12 +250,12 @@ UINT status;
|
||||
/* Determine if the write was successful. */
|
||||
if (status != LX_SUCCESS)
|
||||
{
|
||||
|
||||
|
||||
/* Return an I/O error to FileX. */
|
||||
media_ptr -> fx_media_driver_status = FX_IO_ERROR;
|
||||
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/* Successful sector write. */
|
||||
count--;
|
||||
@@ -274,7 +270,7 @@ UINT status;
|
||||
|
||||
case FX_DRIVER_RELEASE_SECTORS:
|
||||
{
|
||||
|
||||
|
||||
/* Release the mapping of this sector. */
|
||||
logical_sector = media_ptr -> fx_media_driver_logical_sector;
|
||||
count = media_ptr -> fx_media_driver_sectors;
|
||||
@@ -287,18 +283,18 @@ UINT status;
|
||||
/* Determine if the sector release was successful. */
|
||||
if (status != LX_SUCCESS)
|
||||
{
|
||||
|
||||
|
||||
/* Return an I/O error to FileX. */
|
||||
media_ptr -> fx_media_driver_status = FX_IO_ERROR;
|
||||
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/* Successful sector release. */
|
||||
count--;
|
||||
logical_sector++;
|
||||
}
|
||||
|
||||
|
||||
/* Successful driver request. */
|
||||
media_ptr -> fx_media_driver_status = FX_SUCCESS;
|
||||
break;
|
||||
@@ -323,7 +319,7 @@ UINT status;
|
||||
case FX_DRIVER_INIT:
|
||||
{
|
||||
|
||||
/* FLASH drivers are responsible for setting several fields in the
|
||||
/* FLASH drivers are responsible for setting several fields in the
|
||||
media structure, as follows:
|
||||
|
||||
media_ptr -> fx_media_driver_free_sector_update
|
||||
@@ -331,7 +327,7 @@ UINT status;
|
||||
|
||||
The fx_media_driver_free_sector_update flag is used to instruct
|
||||
FileX to inform the driver whenever sectors are not being used.
|
||||
This is especially useful for FLASH managers so they don't have
|
||||
This is especially useful for FLASH managers so they don't have
|
||||
maintain mapping for sectors no longer in use.
|
||||
|
||||
The fx_media_driver_write_protect flag can be set anytime by the
|
||||
@@ -346,17 +342,17 @@ UINT status;
|
||||
media_ptr -> fx_media_driver_free_sector_update = FX_TRUE;
|
||||
|
||||
/* Open the NAND flash simulation. */
|
||||
status = _lx_nand_flash_open(&nand_flash, "sim nand flash", _lx_nand_flash_simulator_initialize);
|
||||
status = _lx_nand_flash_open(&nand_flash, "sim nand flash", _lx_nand_flash_simulator_initialize, lx_memory_buffer, sizeof(lx_memory_buffer));
|
||||
|
||||
/* Determine if the flash open was successful. */
|
||||
if (status != LX_SUCCESS)
|
||||
{
|
||||
|
||||
|
||||
/* Return an I/O error to FileX. */
|
||||
media_ptr -> fx_media_driver_status = FX_IO_ERROR;
|
||||
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/* Successful driver request. */
|
||||
media_ptr -> fx_media_driver_status = FX_SUCCESS;
|
||||
@@ -368,25 +364,25 @@ UINT status;
|
||||
|
||||
/* There is nothing to do in this case for the RAM driver. For actual
|
||||
devices some shutdown processing may be necessary. */
|
||||
|
||||
|
||||
/* Close the NAND flash simulation. */
|
||||
status = _lx_nand_flash_close(&nand_flash);
|
||||
|
||||
|
||||
/* Determine if the flash close was successful. */
|
||||
if (status != LX_SUCCESS)
|
||||
{
|
||||
|
||||
|
||||
/* Return an I/O error to FileX. */
|
||||
media_ptr -> fx_media_driver_status = FX_IO_ERROR;
|
||||
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/* Successful driver request. */
|
||||
media_ptr -> fx_media_driver_status = FX_SUCCESS;
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
case FX_DRIVER_BOOT_READ:
|
||||
{
|
||||
|
||||
@@ -396,13 +392,13 @@ UINT status;
|
||||
/* Determine if the read was successful. */
|
||||
if (status != LX_SUCCESS)
|
||||
{
|
||||
|
||||
|
||||
/* Return an I/O error to FileX. */
|
||||
media_ptr -> fx_media_driver_status = FX_IO_ERROR;
|
||||
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/* Successful driver request. */
|
||||
media_ptr -> fx_media_driver_status = FX_SUCCESS;
|
||||
break;
|
||||
@@ -417,12 +413,12 @@ UINT status;
|
||||
/* Determine if the write was successful. */
|
||||
if (status != LX_SUCCESS)
|
||||
{
|
||||
|
||||
|
||||
/* Return an I/O error to FileX. */
|
||||
media_ptr -> fx_media_driver_status = FX_IO_ERROR;
|
||||
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/* Successful driver request. */
|
||||
media_ptr -> fx_media_driver_status = FX_SUCCESS;
|
||||
|
||||
@@ -1,19 +1,19 @@
|
||||
/**************************************************************************/
|
||||
/* */
|
||||
/* Copyright (c) Microsoft Corporation. All rights reserved. */
|
||||
/* */
|
||||
/* This software is licensed under the Microsoft Software License */
|
||||
/* Terms for Microsoft Azure RTOS. Full text of the license can be */
|
||||
/* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */
|
||||
/* and in the root directory of this software. */
|
||||
/* */
|
||||
/**************************************************************************/
|
||||
/***************************************************************************
|
||||
* Copyright (c) 2024 Microsoft Corporation
|
||||
* Copyright (c) 2026-present Eclipse ThreadX contributors
|
||||
*
|
||||
* This program and the accompanying materials are made available under the
|
||||
* terms of the MIT License which is available at
|
||||
* https://opensource.org/licenses/MIT.
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
**************************************************************************/
|
||||
|
||||
|
||||
/**************************************************************************/
|
||||
/**************************************************************************/
|
||||
/** */
|
||||
/** FileX Component */
|
||||
/** */
|
||||
/** FileX Component */
|
||||
/** */
|
||||
/** FileX NOR FLASH Simulator Driver */
|
||||
/** */
|
||||
@@ -23,7 +23,6 @@
|
||||
|
||||
/* Include necessary system files. */
|
||||
|
||||
#include "tx_api.h"
|
||||
#include "fx_api.h"
|
||||
#include "lx_api.h"
|
||||
|
||||
@@ -34,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 fx_media_open call.
|
||||
the fx_media_open call.
|
||||
|
||||
fx_media_format(&ram_disk,
|
||||
_fx_nor_sim_driver, // Driver entry
|
||||
FX_NULL, // Unused
|
||||
media_memory, // Media buffer pointer
|
||||
sizeof(media_memory), // Media buffer size
|
||||
"MY_NOR_DISK", // Volume Name
|
||||
1, // Number of FATs
|
||||
32, // Directory Entries
|
||||
0, // Hidden sectors
|
||||
120, // Total sectors
|
||||
512, // Sector size
|
||||
1, // Sectors per cluster
|
||||
1, // Heads
|
||||
1); // Sectors per track
|
||||
fx_media_format(&ram_disk,
|
||||
_fx_nor_sim_driver, // Driver entry
|
||||
FX_NULL, // Unused
|
||||
media_memory, // Media buffer pointer
|
||||
sizeof(media_memory), // Media buffer size
|
||||
"MY_NOR_DISK", // Volume Name
|
||||
1, // Number of FATs
|
||||
32, // Directory Entries
|
||||
0, // Hidden sectors
|
||||
120, // Total sectors
|
||||
LX_NOR_SECTOR_SIZE * sizeof(ULONG), // Sector size
|
||||
1, // Sectors per cluster
|
||||
1, // Heads
|
||||
1); // Sectors per track
|
||||
|
||||
*/
|
||||
|
||||
@@ -60,62 +59,56 @@ UINT _lx_nor_flash_simulator_initialize(LX_NOR_FLASH *nor_flash);
|
||||
VOID _fx_nor_flash_simulator_driver(FX_MEDIA *media_ptr);
|
||||
|
||||
|
||||
/**************************************************************************/
|
||||
/* */
|
||||
/* FUNCTION RELEASE */
|
||||
/* */
|
||||
/* _fx_nor_flash_simulator_driver PORTABLE C */
|
||||
/* 6.0 */
|
||||
/**************************************************************************/
|
||||
/* */
|
||||
/* FUNCTION RELEASE */
|
||||
/* */
|
||||
/* _fx_nor_flash_simulator_driver PORTABLE C */
|
||||
/* 6.1.7 */
|
||||
/* AUTHOR */
|
||||
/* */
|
||||
/* William E. Lamie, Microsoft Corporation */
|
||||
/* */
|
||||
/* 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 */
|
||||
/* DESCRIPTION */
|
||||
/* */
|
||||
/* 05-19-2020 William E. Lamie Initial Version 6.0 */
|
||||
/* 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 */
|
||||
/* */
|
||||
/**************************************************************************/
|
||||
VOID _fx_nor_flash_simulator_driver(FX_MEDIA *media_ptr)
|
||||
@@ -131,14 +124,14 @@ UINT status;
|
||||
/* There are several useful/important pieces of information contained in the media
|
||||
structure, some of which are supplied by FileX and others are for the driver to
|
||||
setup. The following is a summary of the necessary FX_MEDIA structure members:
|
||||
|
||||
|
||||
FX_MEDIA Member Meaning
|
||||
|
||||
fx_media_driver_request FileX request type. Valid requests from FileX are
|
||||
|
||||
fx_media_driver_request FileX request type. Valid requests from FileX are
|
||||
as follows:
|
||||
|
||||
FX_DRIVER_READ
|
||||
FX_DRIVER_WRITE
|
||||
FX_DRIVER_WRITE
|
||||
FX_DRIVER_FLUSH
|
||||
FX_DRIVER_ABORT
|
||||
FX_DRIVER_INIT
|
||||
@@ -147,11 +140,11 @@ UINT status;
|
||||
FX_DRIVER_BOOT_WRITE
|
||||
FX_DRIVER_UNINIT
|
||||
|
||||
fx_media_driver_status This value is RETURNED by the driver. If the
|
||||
fx_media_driver_status This value is RETURNED by the driver. If the
|
||||
operation is successful, this field should be
|
||||
set to FX_SUCCESS for before returning. Otherwise,
|
||||
if an error occurred, this field should be set
|
||||
to FX_IO_ERROR.
|
||||
to FX_IO_ERROR.
|
||||
|
||||
fx_media_driver_buffer Pointer to buffer to read or write sector data.
|
||||
This is supplied by FileX.
|
||||
@@ -162,24 +155,24 @@ UINT status;
|
||||
|
||||
|
||||
The following is a summary of the optional FX_MEDIA structure members:
|
||||
|
||||
|
||||
FX_MEDIA Member Meaning
|
||||
|
||||
|
||||
fx_media_driver_info Pointer to any additional information or memory.
|
||||
This is optional for the driver use and is setup
|
||||
from the fx_media_open call. The RAM disk uses
|
||||
this pointer for the RAM disk memory itself.
|
||||
|
||||
fx_media_driver_write_protect The DRIVER sets this to FX_TRUE when media is write
|
||||
protected. This is typically done in initialization,
|
||||
fx_media_driver_write_protect The DRIVER sets this to FX_TRUE when media is write
|
||||
protected. This is typically done in initialization,
|
||||
but can be done anytime.
|
||||
|
||||
fx_media_driver_free_sector_update The DRIVER sets this to FX_TRUE when it needs to
|
||||
fx_media_driver_free_sector_update The DRIVER sets this to FX_TRUE when it needs to
|
||||
know when clusters are released. This is important
|
||||
for FLASH wear-leveling drivers.
|
||||
|
||||
fx_media_driver_system_write FileX sets this flag to FX_TRUE if the sector being
|
||||
written is a system sector, e.g., a boot, FAT, or
|
||||
written is a system sector, e.g., a boot, FAT, or
|
||||
directory sector. The driver may choose to use this
|
||||
to initiate error recovery logic for greater fault
|
||||
tolerance.
|
||||
@@ -187,15 +180,15 @@ UINT status;
|
||||
fx_media_driver_data_sector_read FileX sets this flag to FX_TRUE if the sector(s) being
|
||||
read are file data sectors, i.e., NOT system sectors.
|
||||
|
||||
fx_media_driver_sector_type FileX sets this variable to the specific type of
|
||||
fx_media_driver_sector_type FileX sets this variable to the specific type of
|
||||
sector being read or written. The following sector
|
||||
types are identified:
|
||||
|
||||
FX_UNKNOWN_SECTOR
|
||||
FX_UNKNOWN_SECTOR
|
||||
FX_BOOT_SECTOR
|
||||
FX_FAT_SECTOR
|
||||
FX_DIRECTORY_SECTOR
|
||||
FX_DATA_SECTOR
|
||||
FX_DATA_SECTOR
|
||||
*/
|
||||
|
||||
/* Process the driver request specified in the media control block. */
|
||||
@@ -212,30 +205,30 @@ UINT status;
|
||||
/* Loop to read sectors from flash. */
|
||||
for (i = 0; i < media_ptr -> fx_media_driver_sectors; i++)
|
||||
{
|
||||
|
||||
|
||||
/* Read a sector from NOR flash. */
|
||||
status = lx_nor_flash_sector_read(&nor_flash, logical_sector, destination_buffer);
|
||||
|
||||
/* Determine if the read was successful. */
|
||||
if (status != LX_SUCCESS)
|
||||
{
|
||||
|
||||
|
||||
/* Return an I/O error to FileX. */
|
||||
media_ptr -> fx_media_driver_status = FX_IO_ERROR;
|
||||
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/* Move to the next entries. */
|
||||
logical_sector++;
|
||||
destination_buffer = destination_buffer + 512;
|
||||
destination_buffer = destination_buffer + media_ptr -> fx_media_bytes_per_sector;
|
||||
}
|
||||
|
||||
/* Successful driver request. */
|
||||
media_ptr -> fx_media_driver_status = FX_SUCCESS;
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
case FX_DRIVER_WRITE:
|
||||
{
|
||||
|
||||
@@ -246,23 +239,23 @@ UINT status;
|
||||
/* Loop to write sectors to flash. */
|
||||
for (i = 0; i < media_ptr -> fx_media_driver_sectors; i++)
|
||||
{
|
||||
|
||||
|
||||
/* Write a sector to NOR flash. */
|
||||
status = lx_nor_flash_sector_write(&nor_flash, logical_sector, source_buffer);
|
||||
|
||||
/* Determine if the write was successful. */
|
||||
if (status != LX_SUCCESS)
|
||||
{
|
||||
|
||||
|
||||
/* Return an I/O error to FileX. */
|
||||
media_ptr -> fx_media_driver_status = FX_IO_ERROR;
|
||||
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/* Move to the next entries. */
|
||||
logical_sector++;
|
||||
source_buffer = source_buffer + 512;
|
||||
source_buffer = source_buffer + media_ptr -> fx_media_bytes_per_sector;
|
||||
}
|
||||
|
||||
/* Successful driver request. */
|
||||
@@ -272,26 +265,26 @@ UINT status;
|
||||
|
||||
case FX_DRIVER_RELEASE_SECTORS:
|
||||
{
|
||||
|
||||
|
||||
/* Setup the logical sector. */
|
||||
logical_sector = media_ptr -> fx_media_driver_logical_sector;
|
||||
|
||||
/* Release sectors. */
|
||||
for (i = 0; i < media_ptr -> fx_media_driver_sectors; i++)
|
||||
{
|
||||
|
||||
|
||||
/* Release NOR flash sector. */
|
||||
status = lx_nor_flash_sector_release(&nor_flash, logical_sector);
|
||||
|
||||
/* Determine if the sector release was successful. */
|
||||
if (status != LX_SUCCESS)
|
||||
{
|
||||
|
||||
|
||||
/* Return an I/O error to FileX. */
|
||||
media_ptr -> fx_media_driver_status = FX_IO_ERROR;
|
||||
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/* Move to the next entries. */
|
||||
logical_sector++;
|
||||
@@ -321,7 +314,7 @@ UINT status;
|
||||
case FX_DRIVER_INIT:
|
||||
{
|
||||
|
||||
/* FLASH drivers are responsible for setting several fields in the
|
||||
/* FLASH drivers are responsible for setting several fields in the
|
||||
media structure, as follows:
|
||||
|
||||
media_ptr -> fx_media_driver_free_sector_update
|
||||
@@ -329,7 +322,7 @@ UINT status;
|
||||
|
||||
The fx_media_driver_free_sector_update flag is used to instruct
|
||||
FileX to inform the driver whenever sectors are not being used.
|
||||
This is especially useful for FLASH managers so they don't have
|
||||
This is especially useful for FLASH managers so they don't have
|
||||
maintain mapping for sectors no longer in use.
|
||||
|
||||
The fx_media_driver_write_protect flag can be set anytime by the
|
||||
@@ -349,12 +342,12 @@ UINT status;
|
||||
/* Determine if the flash open was successful. */
|
||||
if (status != LX_SUCCESS)
|
||||
{
|
||||
|
||||
|
||||
/* Return an I/O error to FileX. */
|
||||
media_ptr -> fx_media_driver_status = FX_IO_ERROR;
|
||||
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/* Successful driver request. */
|
||||
media_ptr -> fx_media_driver_status = FX_SUCCESS;
|
||||
@@ -373,18 +366,18 @@ UINT status;
|
||||
/* Determine if the flash close was successful. */
|
||||
if (status != LX_SUCCESS)
|
||||
{
|
||||
|
||||
|
||||
/* Return an I/O error to FileX. */
|
||||
media_ptr -> fx_media_driver_status = FX_IO_ERROR;
|
||||
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/* Successful driver request. */
|
||||
media_ptr -> fx_media_driver_status = FX_SUCCESS;
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
case FX_DRIVER_BOOT_READ:
|
||||
{
|
||||
|
||||
@@ -410,12 +403,12 @@ UINT status;
|
||||
/* Determine if the boot read was successful. */
|
||||
if (status != LX_SUCCESS)
|
||||
{
|
||||
|
||||
|
||||
/* Return an I/O error to FileX. */
|
||||
media_ptr -> fx_media_driver_status = FX_IO_ERROR;
|
||||
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/* Successful driver request. */
|
||||
media_ptr -> fx_media_driver_status = FX_SUCCESS;
|
||||
@@ -425,6 +418,15 @@ UINT status;
|
||||
case FX_DRIVER_BOOT_WRITE:
|
||||
{
|
||||
|
||||
/* Make sure the media bytes per sector equals to the LevelX logical sector size. */
|
||||
if (media_ptr -> fx_media_bytes_per_sector != (LX_NOR_SECTOR_SIZE) * sizeof(ULONG))
|
||||
{
|
||||
|
||||
/* Sector size mismatch, return error. */
|
||||
media_ptr -> fx_media_driver_status = FX_IO_ERROR;
|
||||
break;
|
||||
}
|
||||
|
||||
/* Write the boot record and return to the caller. */
|
||||
|
||||
/* Setup the source buffer. */
|
||||
@@ -436,12 +438,12 @@ UINT status;
|
||||
/* Determine if the boot write was successful. */
|
||||
if (status != LX_SUCCESS)
|
||||
{
|
||||
|
||||
|
||||
/* Return an I/O error to FileX. */
|
||||
media_ptr -> fx_media_driver_status = FX_IO_ERROR;
|
||||
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/* Successful driver request. */
|
||||
media_ptr -> fx_media_driver_status = FX_SUCCESS;
|
||||
|
||||
@@ -1,19 +1,19 @@
|
||||
/**************************************************************************/
|
||||
/* */
|
||||
/* Copyright (c) Microsoft Corporation. All rights reserved. */
|
||||
/* */
|
||||
/* This software is licensed under the Microsoft Software License */
|
||||
/* Terms for Microsoft Azure RTOS. Full text of the license can be */
|
||||
/* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */
|
||||
/* and in the root directory of this software. */
|
||||
/* */
|
||||
/**************************************************************************/
|
||||
/***************************************************************************
|
||||
* Copyright (c) 2024 Microsoft Corporation
|
||||
* Copyright (c) 2026-present Eclipse ThreadX contributors
|
||||
*
|
||||
* This program and the accompanying materials are made available under the
|
||||
* terms of the MIT License which is available at
|
||||
* https://opensource.org/licenses/MIT.
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
**************************************************************************/
|
||||
|
||||
|
||||
/**************************************************************************/
|
||||
/**************************************************************************/
|
||||
/** */
|
||||
/** LevelX Component */
|
||||
/** */
|
||||
/** LevelX Component */
|
||||
/** */
|
||||
/** NAND Flash */
|
||||
/** */
|
||||
@@ -25,8 +25,8 @@
|
||||
|
||||
/* Disable ThreadX error checking. */
|
||||
|
||||
#ifndef TX_DISABLE_ERROR_CHECKING
|
||||
#define TX_DISABLE_ERROR_CHECKING
|
||||
#ifndef LX_DISABLE_ERROR_CHECKING
|
||||
#define LX_DISABLE_ERROR_CHECKING
|
||||
#endif
|
||||
|
||||
|
||||
@@ -35,50 +35,44 @@
|
||||
#include "lx_api.h"
|
||||
|
||||
|
||||
/**************************************************************************/
|
||||
/* */
|
||||
/* FUNCTION RELEASE */
|
||||
/* */
|
||||
/* _lx_nand_flash_256byte_ecc_check PORTABLE C */
|
||||
/* 6.0 */
|
||||
/**************************************************************************/
|
||||
/* */
|
||||
/* FUNCTION RELEASE */
|
||||
/* */
|
||||
/* _lx_nand_flash_256byte_ecc_check PORTABLE C */
|
||||
/* 6.1.7 */
|
||||
/* AUTHOR */
|
||||
/* */
|
||||
/* William E. Lamie, Microsoft Corporation */
|
||||
/* */
|
||||
/* 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 */
|
||||
/* DESCRIPTION */
|
||||
/* */
|
||||
/* 05-19-2020 William E. Lamie Initial Version 6.0 */
|
||||
/* 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 */
|
||||
/* */
|
||||
/**************************************************************************/
|
||||
UINT _lx_nand_flash_256byte_ecc_check(UCHAR *page_buffer, UCHAR *ecc_buffer)
|
||||
{
|
||||
|
||||
INT i, j;
|
||||
UCHAR mask;
|
||||
UCHAR mask;
|
||||
UCHAR new_ecc_buffer[3];
|
||||
UCHAR ecc_errors[3];
|
||||
INT error_count;
|
||||
@@ -100,29 +94,29 @@ ULONG correction_code;
|
||||
error_count = 0;
|
||||
|
||||
/* 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. */
|
||||
ecc_errors[i] = new_ecc_buffer[i] ^ ecc_buffer[i];
|
||||
|
||||
|
||||
/* Are there any errors? */
|
||||
if (ecc_errors[i])
|
||||
{
|
||||
|
||||
|
||||
/* Accumulate the count of set bits. */
|
||||
mask = 1;
|
||||
for (j = 0; j < 8; j++)
|
||||
{
|
||||
|
||||
|
||||
/* Is this bit set? */
|
||||
if (ecc_errors[i] & mask)
|
||||
{
|
||||
|
||||
|
||||
/* Yes, increment the count. */
|
||||
error_count++;
|
||||
}
|
||||
|
||||
|
||||
/* Move mask to next bit. */
|
||||
mask = (UCHAR) ((mask << 1) & 0xFF);
|
||||
}
|
||||
@@ -138,7 +132,7 @@ ULONG correction_code;
|
||||
}
|
||||
|
||||
/* Was a correctable error discovered? */
|
||||
else if (error_count == 11)
|
||||
else if (error_count == 11)
|
||||
{
|
||||
|
||||
/* Initialize bit and byte offset values. */
|
||||
@@ -166,13 +160,13 @@ ULONG correction_code;
|
||||
|
||||
/* Fix the error. */
|
||||
data[byte] = (USHORT) ((data[byte] ^ (1 << bit)) & 0xFFFF);
|
||||
|
||||
|
||||
/* Return an error corrected status. */
|
||||
return(LX_NAND_ERROR_CORRECTED);
|
||||
}
|
||||
|
||||
|
||||
/* Otherwise, an unrecoverable ECC or data error is present. */
|
||||
else
|
||||
else
|
||||
{
|
||||
|
||||
/* Return an error. */
|
||||
|
||||
@@ -1,19 +1,19 @@
|
||||
/**************************************************************************/
|
||||
/* */
|
||||
/* Copyright (c) Microsoft Corporation. All rights reserved. */
|
||||
/* */
|
||||
/* This software is licensed under the Microsoft Software License */
|
||||
/* Terms for Microsoft Azure RTOS. Full text of the license can be */
|
||||
/* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */
|
||||
/* and in the root directory of this software. */
|
||||
/* */
|
||||
/**************************************************************************/
|
||||
/***************************************************************************
|
||||
* Copyright (c) 2024 Microsoft Corporation
|
||||
* Copyright (c) 2026-present Eclipse ThreadX contributors
|
||||
*
|
||||
* This program and the accompanying materials are made available under the
|
||||
* terms of the MIT License which is available at
|
||||
* https://opensource.org/licenses/MIT.
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
**************************************************************************/
|
||||
|
||||
|
||||
/**************************************************************************/
|
||||
/**************************************************************************/
|
||||
/** */
|
||||
/** LevelX Component */
|
||||
/** */
|
||||
/** LevelX Component */
|
||||
/** */
|
||||
/** NAND Flash */
|
||||
/** */
|
||||
@@ -25,8 +25,8 @@
|
||||
|
||||
/* Disable ThreadX error checking. */
|
||||
|
||||
#ifndef TX_DISABLE_ERROR_CHECKING
|
||||
#define TX_DISABLE_ERROR_CHECKING
|
||||
#ifndef LX_DISABLE_ERROR_CHECKING
|
||||
#define LX_DISABLE_ERROR_CHECKING
|
||||
#endif
|
||||
|
||||
|
||||
@@ -35,44 +35,38 @@
|
||||
#include "lx_api.h"
|
||||
|
||||
|
||||
/**************************************************************************/
|
||||
/* */
|
||||
/* FUNCTION RELEASE */
|
||||
/* */
|
||||
/* _lx_nand_flash_256byte_ecc_compute PORTABLE C */
|
||||
/* 6.0 */
|
||||
/**************************************************************************/
|
||||
/* */
|
||||
/* FUNCTION RELEASE */
|
||||
/* */
|
||||
/* _lx_nand_flash_256byte_ecc_compute PORTABLE C */
|
||||
/* 6.2.1 */
|
||||
/* AUTHOR */
|
||||
/* */
|
||||
/* William E. Lamie, Microsoft Corporation */
|
||||
/* */
|
||||
/* 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 */
|
||||
/* DESCRIPTION */
|
||||
/* */
|
||||
/* 05-19-2020 William E. Lamie Initial Version 6.0 */
|
||||
/* 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 */
|
||||
/* */
|
||||
/**************************************************************************/
|
||||
UINT _lx_nand_flash_256byte_ecc_compute(UCHAR *page_buffer, UCHAR *ecc_buffer)
|
||||
@@ -99,27 +93,27 @@ USHORT odd_byte_parity;
|
||||
ecc_buffer[0]= 0;
|
||||
ecc_buffer[1]= 0;
|
||||
ecc_buffer[2]= 0;
|
||||
|
||||
|
||||
/* Setup a 16-bit pointer to the buffer area. */
|
||||
data = (USHORT *) page_buffer;
|
||||
|
||||
|
||||
/* 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. */
|
||||
bit_parity = bit_parity ^ data[i];
|
||||
|
||||
|
||||
/* Now count the bits in the current data word. */
|
||||
bits = 0;
|
||||
mask = 1;
|
||||
for (j = 0; j < 16; j++)
|
||||
{
|
||||
|
||||
/* Is the bit set? */
|
||||
/* Is the bit set? */
|
||||
if (data[i] & mask)
|
||||
{
|
||||
|
||||
|
||||
/* Yes, increment the bit count. */
|
||||
bits++;
|
||||
}
|
||||
@@ -127,11 +121,11 @@ USHORT odd_byte_parity;
|
||||
/* Move the mask to the next bit. */
|
||||
mask = (USHORT) ((mask << 1) & 0xFFFF);
|
||||
}
|
||||
|
||||
|
||||
/* 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. */
|
||||
even_byte_parity = (USHORT) ((even_byte_parity ^ (0xffff - i)) & 0xFFFF);
|
||||
odd_byte_parity = odd_byte_parity ^ i;
|
||||
@@ -139,11 +133,11 @@ USHORT odd_byte_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? */
|
||||
if (bit_parity & 1)
|
||||
if (bit_parity & 1)
|
||||
{
|
||||
|
||||
/* Yes, adjust the odd even byte parity. */
|
||||
@@ -154,21 +148,21 @@ USHORT odd_byte_parity;
|
||||
/* Look at next bit position. */
|
||||
bit_parity = bit_parity >> 1;
|
||||
}
|
||||
|
||||
|
||||
/* At this point, we need to pack the 22 ECC bits into the 3 byte return area. */
|
||||
|
||||
|
||||
/* Pack bit 21. */
|
||||
ecc_buffer[(21+2)/8] = ((UCHAR)(ecc_buffer[(21+2)/8] | ((odd_byte_parity >> 6) & 1) << (21+2)%8) & 0xFF);
|
||||
|
||||
|
||||
/* Pack bit 20. */
|
||||
ecc_buffer[(20+2)/8] = ((UCHAR)(ecc_buffer[(20+2)/8] | ((even_byte_parity >> 6) & 1) << (20+2)%8) & 0xFF);
|
||||
|
||||
|
||||
/* Pack bit 19. */
|
||||
ecc_buffer[(19+2)/8] = ((UCHAR)(ecc_buffer[(19+2)/8] | ((odd_byte_parity >> 5) & 1) << (19+2)%8) & 0xFF);
|
||||
|
||||
/* Pack bit 18. */
|
||||
ecc_buffer[(18+2)/8] = ((UCHAR)(ecc_buffer[(18+2)/8] | ((even_byte_parity >> 5) & 1) << (18+2)%8) & 0xFF);
|
||||
|
||||
|
||||
/* Pack bit 17. */
|
||||
ecc_buffer[(17+2)/8] = ((UCHAR)(ecc_buffer[(17+2)/8] | ((odd_byte_parity >> 4) & 1) << (17+2)%8) & 0xFF);
|
||||
|
||||
@@ -183,7 +177,7 @@ USHORT odd_byte_parity;
|
||||
|
||||
/* Pack bit 13. */
|
||||
ecc_buffer[(13+2)/8] = ((UCHAR)(ecc_buffer[(13+2)/8] | ((odd_byte_parity >> 2) & 1) << (13+2)%8) & 0xFF);
|
||||
|
||||
|
||||
/* Pack bit 12. */
|
||||
ecc_buffer[(12+2)/8] = ((UCHAR)(ecc_buffer[(12+2)/8] | ((even_byte_parity >> 2) & 1) << (12+2)%8) & 0xFF);
|
||||
|
||||
@@ -193,18 +187,18 @@ USHORT odd_byte_parity;
|
||||
/* Pack bit 10. */
|
||||
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);
|
||||
|
||||
/* 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);
|
||||
|
||||
/* Pack bit 7. */
|
||||
ecc_buffer[(7+2)/8] = ((UCHAR)(ecc_buffer[(7+2)/8] | ((odd_bit_parity >> 3) & 1) << (7+2)%8) & 0xFF);
|
||||
|
||||
|
||||
/* Pack bit 6. */
|
||||
ecc_buffer[(6+2)/8] = ((UCHAR)(ecc_buffer[(6+2)/8] | ((even_bit_parity >> 3) & 1) << (6+2)%8) & 0xFF);
|
||||
|
||||
|
||||
/* Pack bit 5. */
|
||||
ecc_buffer[(5+2)/8] = ((UCHAR)(ecc_buffer[(5+2)/8] | ((odd_bit_parity >> 2) & 1) << (5+2)%8) & 0xFF);
|
||||
|
||||
@@ -217,12 +211,16 @@ USHORT odd_byte_parity;
|
||||
/* Pack bit 2. */
|
||||
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);
|
||||
|
||||
/* 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] = (UCHAR)~ecc_buffer[0];
|
||||
ecc_buffer[1] = (UCHAR)~ecc_buffer[1];
|
||||
ecc_buffer[2] = (UCHAR)~ecc_buffer[2];
|
||||
|
||||
/* Return success! */
|
||||
return(LX_SUCCESS);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,129 @@
|
||||
/***************************************************************************
|
||||
* 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_block_allocate PORTABLE C */
|
||||
/* 6.2.1 */
|
||||
/* AUTHOR */
|
||||
/* */
|
||||
/* Xiuwen Cai, Microsoft Corporation */
|
||||
/* */
|
||||
/* 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 */
|
||||
/* */
|
||||
/**************************************************************************/
|
||||
UINT _lx_nand_flash_block_allocate(LX_NAND_FLASH* nand_flash, ULONG* block)
|
||||
{
|
||||
|
||||
|
||||
/* Check if the free block list is empty. */
|
||||
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. */
|
||||
return(LX_NO_BLOCKS);
|
||||
}
|
||||
|
||||
/* Remove one block from the list. */
|
||||
nand_flash -> lx_nand_flash_free_block_list_tail--;
|
||||
|
||||
/* Return the block number. */
|
||||
*block = nand_flash -> lx_nand_flash_block_list[nand_flash -> lx_nand_flash_free_block_list_tail];
|
||||
|
||||
/* Return successful completion. */
|
||||
return(LX_SUCCESS);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,253 @@
|
||||
/***************************************************************************
|
||||
* 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_block_data_move PORTABLE C */
|
||||
/* 6.2.1 */
|
||||
/* AUTHOR */
|
||||
/* */
|
||||
/* Xiuwen Cai, Microsoft Corporation */
|
||||
/* */
|
||||
/* DESCRIPTION */
|
||||
/* */
|
||||
/* This function finds a block with less erase count and copies pages */
|
||||
/* into new block. */
|
||||
/* */
|
||||
/* INPUT */
|
||||
/* */
|
||||
/* nand_flash NAND flash instance */
|
||||
/* new_block New block number */
|
||||
/* */
|
||||
/* OUTPUT */
|
||||
/* */
|
||||
/* return status */
|
||||
/* */
|
||||
/* CALLS */
|
||||
/* */
|
||||
/* _lx_nand_flash_mapped_block_list_get Get mapped block index */
|
||||
/* _lx_nand_flash_block_find Find the mapped block */
|
||||
/* _lx_nand_flash_data_page_copy Copy data pages */
|
||||
/* _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_mapping_set Set block mapping */
|
||||
/* _lx_nand_flash_mapped_block_list_add Add mapped block to list */
|
||||
/* _lx_nand_flash_driver_block_erase Erase block */
|
||||
/* _lx_nand_flash_erase_count_set Set erase count */
|
||||
/* _lx_nand_flash_free_block_list_add Add free block to list */
|
||||
/* _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_block_data_move(LX_NAND_FLASH *nand_flash, ULONG new_block)
|
||||
{
|
||||
|
||||
UINT status;
|
||||
ULONG block;
|
||||
USHORT block_status;
|
||||
USHORT new_block_status;
|
||||
ULONG block_mapping_index;
|
||||
|
||||
|
||||
/* Get the mapped address to move the data. */
|
||||
status = _lx_nand_flash_mapped_block_list_get(nand_flash, &block_mapping_index);
|
||||
|
||||
if (status)
|
||||
{
|
||||
|
||||
/* Return an error. */
|
||||
return(LX_ERROR);
|
||||
}
|
||||
|
||||
/* Find the block number to be moved. */
|
||||
status = _lx_nand_flash_block_find(nand_flash, block_mapping_index * nand_flash -> lx_nand_flash_pages_per_block, &block, &block_status);
|
||||
|
||||
/* Check the status. */
|
||||
if (status)
|
||||
{
|
||||
|
||||
/* Return an 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. */
|
||||
new_block_status = LX_NAND_BLOCK_STATUS_ALLOCATED;
|
||||
|
||||
/* Copy data from old block to new block. */
|
||||
status = _lx_nand_flash_data_page_copy(nand_flash, block_mapping_index * nand_flash -> lx_nand_flash_pages_per_block, block, block_status, new_block, &new_block_status, nand_flash -> lx_nand_flash_pages_per_block);
|
||||
|
||||
/* Check the status. */
|
||||
if (status)
|
||||
{
|
||||
|
||||
/* Call system error handler. */
|
||||
_lx_nand_flash_system_error(nand_flash, status, new_block, 0);
|
||||
|
||||
/* Return an error. */
|
||||
return(LX_ERROR);
|
||||
}
|
||||
|
||||
/* Check if no page was written. */
|
||||
if ((new_block_status & LX_NAND_BLOCK_STATUS_PAGE_NUMBER_MASK) == 0)
|
||||
{
|
||||
|
||||
/* Mark the new block as free. */
|
||||
new_block_status = LX_NAND_BLOCK_STATUS_FREE;
|
||||
|
||||
/* Add the new block to free list. */
|
||||
_lx_nand_flash_free_block_list_add(nand_flash, new_block);
|
||||
|
||||
}
|
||||
|
||||
/* Set the block status for the new block. */
|
||||
status = _lx_nand_flash_block_status_set(nand_flash, new_block, new_block_status);
|
||||
|
||||
/* Check for an error from flash driver. */
|
||||
if (status)
|
||||
{
|
||||
|
||||
/* Call system error handler. */
|
||||
_lx_nand_flash_system_error(nand_flash, status, new_block, 0);
|
||||
|
||||
/* Return an error. */
|
||||
return(LX_ERROR);
|
||||
}
|
||||
|
||||
/* Check if the block is actually mapped. */
|
||||
if (new_block_status == LX_NAND_BLOCK_STATUS_FREE)
|
||||
{
|
||||
|
||||
/* Unmap the block. */
|
||||
new_block = LX_NAND_BLOCK_UNMAPPED;
|
||||
}
|
||||
|
||||
/* Update block mapping. */
|
||||
_lx_nand_flash_block_mapping_set(nand_flash, block_mapping_index * nand_flash -> lx_nand_flash_pages_per_block, new_block);
|
||||
|
||||
/* Check if the block is actually mapped. */
|
||||
if (new_block != LX_NAND_BLOCK_UNMAPPED)
|
||||
{
|
||||
|
||||
/* Add the block to mapped list. */
|
||||
_lx_nand_flash_mapped_block_list_add(nand_flash, block_mapping_index);
|
||||
}
|
||||
|
||||
/* Erase the old 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] + 1);
|
||||
|
||||
/* 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);
|
||||
}
|
||||
|
||||
/* Update the erase count for the erased block. */
|
||||
status = _lx_nand_flash_erase_count_set(nand_flash, block, (UCHAR)(nand_flash -> lx_nand_flash_erase_count_table[block] + 1));
|
||||
|
||||
/* 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);
|
||||
}
|
||||
|
||||
/* Set the block status to free. */
|
||||
status = _lx_nand_flash_block_status_set(nand_flash, block, LX_NAND_BLOCK_STATUS_FREE);
|
||||
|
||||
/* 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);
|
||||
}
|
||||
|
||||
/* Add the block to free block list. */
|
||||
status = _lx_nand_flash_free_block_list_add(nand_flash, block);
|
||||
|
||||
/* Return status. */
|
||||
return(status);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,112 @@
|
||||
/***************************************************************************
|
||||
* Copyright (c) 2024 Microsoft Corporation
|
||||
* Copyright (c) 2026-present Eclipse ThreadX contributors
|
||||
*
|
||||
* This program and the accompanying materials are made available under the
|
||||
* terms of the MIT License which is available at
|
||||
* https://opensource.org/licenses/MIT.
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
**************************************************************************/
|
||||
|
||||
|
||||
/**************************************************************************/
|
||||
/**************************************************************************/
|
||||
/** */
|
||||
/** LevelX Component */
|
||||
/** */
|
||||
/** NAND Flash */
|
||||
/** */
|
||||
/**************************************************************************/
|
||||
/**************************************************************************/
|
||||
|
||||
#define LX_SOURCE_CODE
|
||||
|
||||
|
||||
/* Disable ThreadX error checking. */
|
||||
|
||||
#ifndef LX_DISABLE_ERROR_CHECKING
|
||||
#define LX_DISABLE_ERROR_CHECKING
|
||||
#endif
|
||||
|
||||
|
||||
/* Include necessary system files. */
|
||||
|
||||
#include "lx_api.h"
|
||||
|
||||
|
||||
/**************************************************************************/
|
||||
/* */
|
||||
/* FUNCTION RELEASE */
|
||||
/* */
|
||||
/* _lx_nand_flash_block_find PORTABLE C */
|
||||
/* 6.2.1 */
|
||||
/* AUTHOR */
|
||||
/* */
|
||||
/* Xiuwen Cai, Microsoft Corporation */
|
||||
/* */
|
||||
/* 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 */
|
||||
/* */
|
||||
/**************************************************************************/
|
||||
UINT _lx_nand_flash_block_find(LX_NAND_FLASH *nand_flash, ULONG logical_sector, ULONG *block, USHORT *block_status)
|
||||
{
|
||||
|
||||
UINT block_mapping_index;
|
||||
USHORT block_number;
|
||||
|
||||
|
||||
/* Get the mapping index from logic sector address. */
|
||||
block_mapping_index = logical_sector / nand_flash -> lx_nand_flash_pages_per_block;
|
||||
|
||||
/* 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))
|
||||
{
|
||||
|
||||
/* Out of range, return an error. */
|
||||
return(LX_ERROR);
|
||||
}
|
||||
|
||||
/* Get the block number from mapping table. */
|
||||
block_number = nand_flash -> lx_nand_flash_block_mapping_table[block_mapping_index];
|
||||
|
||||
/* Check if it is mapped. */
|
||||
if (block_number != LX_NAND_BLOCK_UNMAPPED)
|
||||
{
|
||||
|
||||
/* Return the block status. */
|
||||
*block_status = nand_flash -> lx_nand_flash_block_status_table[block_number];
|
||||
}
|
||||
|
||||
/* Return the block number. */
|
||||
*block = (ULONG)block_number;
|
||||
|
||||
/* Return successful completion. */
|
||||
return(LX_SUCCESS);
|
||||
}
|
||||
|
||||
@@ -1,180 +0,0 @@
|
||||
/**************************************************************************/
|
||||
/* */
|
||||
/* Copyright (c) Microsoft Corporation. All rights reserved. */
|
||||
/* */
|
||||
/* This software is licensed under the Microsoft Software License */
|
||||
/* Terms for Microsoft Azure RTOS. Full text of the license can be */
|
||||
/* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */
|
||||
/* and in the root directory of this software. */
|
||||
/* */
|
||||
/**************************************************************************/
|
||||
|
||||
|
||||
/**************************************************************************/
|
||||
/**************************************************************************/
|
||||
/** */
|
||||
/** LevelX Component */
|
||||
/** */
|
||||
/** NAND Flash */
|
||||
/** */
|
||||
/**************************************************************************/
|
||||
/**************************************************************************/
|
||||
|
||||
#define LX_SOURCE_CODE
|
||||
|
||||
|
||||
/* Disable ThreadX error checking. */
|
||||
|
||||
#ifndef TX_DISABLE_ERROR_CHECKING
|
||||
#define TX_DISABLE_ERROR_CHECKING
|
||||
#endif
|
||||
|
||||
|
||||
/* Include necessary system files. */
|
||||
|
||||
#include "lx_api.h"
|
||||
|
||||
|
||||
/**************************************************************************/
|
||||
/* */
|
||||
/* FUNCTION RELEASE */
|
||||
/* */
|
||||
/* _lx_nand_flash_block_full_update PORTABLE C */
|
||||
/* 6.0 */
|
||||
/* AUTHOR */
|
||||
/* */
|
||||
/* William E. Lamie, Microsoft Corporation */
|
||||
/* */
|
||||
/* DESCRIPTION */
|
||||
/* */
|
||||
/* This function writes the list of page to logical sector mapping */
|
||||
/* when the block is full. */
|
||||
/* */
|
||||
/* INPUT */
|
||||
/* */
|
||||
/* nand_flash NAND flash instance */
|
||||
/* block Block that is full */
|
||||
/* erase_count Block erase count */
|
||||
/* */
|
||||
/* OUTPUT */
|
||||
/* */
|
||||
/* return status */
|
||||
/* */
|
||||
/* CALLS */
|
||||
/* */
|
||||
/* _lx_nand_flash_driver_write Driver flash page write */
|
||||
/* _lx_nand_flash_driver_extra_bytes_get Get extra bytes from spare */
|
||||
/* _lx_nand_flash_driver_extra_bytes_set Set extra bytes from spare */
|
||||
/* _lx_nand_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 */
|
||||
/* */
|
||||
/**************************************************************************/
|
||||
UINT _lx_nand_flash_block_full_update(LX_NAND_FLASH *nand_flash, ULONG block, ULONG erase_count)
|
||||
{
|
||||
|
||||
LX_NAND_PAGE_EXTRA_INFO extra_info;
|
||||
UINT status;
|
||||
ULONG i;
|
||||
ULONG *list_ptr;
|
||||
|
||||
|
||||
/* Setup pointer to internal buffer. */
|
||||
list_ptr = nand_flash -> lx_nand_flash_page_buffer;
|
||||
|
||||
/* Set the internal buffer of all ones. */
|
||||
for (i = 0; i < nand_flash -> lx_nand_flash_words_per_page; i++)
|
||||
{
|
||||
|
||||
/* Set the buffer to all ones. */
|
||||
list_ptr[i] = LX_ALL_ONES;
|
||||
}
|
||||
|
||||
/* Set the initial word to the erase count (this is what is already there!). */
|
||||
list_ptr[0] = erase_count;
|
||||
|
||||
/* Now walk through the pages in the block to build the list of mapped logical
|
||||
sectors to pages. */
|
||||
i = 1;
|
||||
while (i < nand_flash -> lx_nand_flash_pages_per_block)
|
||||
{
|
||||
|
||||
/* Read the extra bytes of each page to pickup the associated mapping. */
|
||||
status = _lx_nand_flash_driver_extra_bytes_get(nand_flash, block, i, (UCHAR *) &extra_info, sizeof(extra_info));
|
||||
|
||||
/* Check for an error from flash driver. */
|
||||
if (status)
|
||||
{
|
||||
|
||||
/* Call system error handler. */
|
||||
_lx_nand_flash_system_error(nand_flash, status, block, i);
|
||||
|
||||
/* Return the error... no point in continuing. */
|
||||
return(status);
|
||||
}
|
||||
|
||||
/* Determine if the extra info indicates the page has not yet been allocated. */
|
||||
if (extra_info.lx_nand_page_extra_info_logical_sector == LX_NAND_PAGE_FREE)
|
||||
{
|
||||
|
||||
/* Block not full, get out of the loop. */
|
||||
break;
|
||||
}
|
||||
|
||||
/* Save the mapping. */
|
||||
list_ptr[i] = extra_info.lx_nand_page_extra_info_logical_sector;
|
||||
|
||||
/* Move to next entry. */
|
||||
i++;
|
||||
}
|
||||
|
||||
/* Check for a full block. */
|
||||
if (i == nand_flash -> lx_nand_flash_pages_per_block)
|
||||
{
|
||||
|
||||
/* Yes, the block is full. */
|
||||
|
||||
/* Place the list complete marker so we know the list is intact. */
|
||||
list_ptr[i] = LX_NAND_PAGE_LIST_VALID;
|
||||
|
||||
/* At this point we can write the buffer to page 0 of the block. */
|
||||
|
||||
/* Write the mapping list to page 0. */
|
||||
status = _lx_nand_flash_driver_write(nand_flash, block, 0, list_ptr, (nand_flash -> lx_nand_flash_pages_per_block + 1));
|
||||
|
||||
/* Check for an error from flash driver. */
|
||||
if (status)
|
||||
{
|
||||
|
||||
/* Call system error handler. */
|
||||
_lx_nand_flash_system_error(nand_flash, status, block, 0);
|
||||
|
||||
/* Return the error... no point in continuing. */
|
||||
return(status);
|
||||
}
|
||||
|
||||
/* Write the extra bytes for page 0. */
|
||||
extra_info.lx_nand_page_extra_info_logical_sector = ((ULONG) LX_NAND_PAGE_FREE) & ~(((ULONG) LX_NAND_BLOCK_EMPTY) | ((ULONG) LX_NAND_BLOCK_FULL));
|
||||
status = _lx_nand_flash_driver_extra_bytes_set(nand_flash, block, 0, (UCHAR *) &extra_info, sizeof(extra_info));
|
||||
|
||||
/* Check for an error from flash driver. */
|
||||
if (status)
|
||||
{
|
||||
|
||||
/* Call system error handler. */
|
||||
_lx_nand_flash_system_error(nand_flash, status, block, 0);
|
||||
}
|
||||
}
|
||||
|
||||
/* Return status. */
|
||||
return(status);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,104 @@
|
||||
/***************************************************************************
|
||||
* Copyright (c) 2024 Microsoft Corporation
|
||||
* Copyright (c) 2026-present Eclipse ThreadX contributors
|
||||
*
|
||||
* This program and the accompanying materials are made available under the
|
||||
* terms of the MIT License which is available at
|
||||
* https://opensource.org/licenses/MIT.
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
**************************************************************************/
|
||||
|
||||
|
||||
/**************************************************************************/
|
||||
/**************************************************************************/
|
||||
/** */
|
||||
/** LevelX Component */
|
||||
/** */
|
||||
/** NAND Flash */
|
||||
/** */
|
||||
/**************************************************************************/
|
||||
/**************************************************************************/
|
||||
|
||||
#define LX_SOURCE_CODE
|
||||
|
||||
|
||||
/* Disable ThreadX error checking. */
|
||||
|
||||
#ifndef LX_DISABLE_ERROR_CHECKING
|
||||
#define LX_DISABLE_ERROR_CHECKING
|
||||
#endif
|
||||
|
||||
|
||||
/* Include necessary system files. */
|
||||
|
||||
#include "lx_api.h"
|
||||
|
||||
|
||||
/**************************************************************************/
|
||||
/* */
|
||||
/* FUNCTION RELEASE */
|
||||
/* */
|
||||
/* _lx_nand_flash_block_mapping_set PORTABLE C */
|
||||
/* 6.2.1 */
|
||||
/* AUTHOR */
|
||||
/* */
|
||||
/* Xiuwen Cai, Microsoft Corporation */
|
||||
/* */
|
||||
/* 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 */
|
||||
/* */
|
||||
/**************************************************************************/
|
||||
UINT _lx_nand_flash_block_mapping_set(LX_NAND_FLASH *nand_flash, ULONG logical_sector, ULONG block)
|
||||
{
|
||||
|
||||
UINT block_mapping_index;
|
||||
UCHAR page_number;
|
||||
UINT status;
|
||||
|
||||
|
||||
/* Get the mapping index from logic sector address. */
|
||||
block_mapping_index = logical_sector / nand_flash -> lx_nand_flash_pages_per_block;
|
||||
|
||||
/* 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))
|
||||
{
|
||||
|
||||
/* Out of range, return an error. */
|
||||
return(LX_ERROR);
|
||||
}
|
||||
|
||||
/* Save the block number to mapping table. */
|
||||
nand_flash -> lx_nand_flash_block_mapping_table[block_mapping_index] = (USHORT)block;
|
||||
|
||||
/* Get the page number to write. */
|
||||
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. */
|
||||
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,
|
||||
LX_NAND_PAGE_TYPE_BLOCK_MAPPING_TABLE | page_number);
|
||||
|
||||
/* Return status. */
|
||||
return(status);
|
||||
}
|
||||
|
||||
@@ -1,369 +0,0 @@
|
||||
/**************************************************************************/
|
||||
/* */
|
||||
/* Copyright (c) Microsoft Corporation. All rights reserved. */
|
||||
/* */
|
||||
/* This software is licensed under the Microsoft Software License */
|
||||
/* Terms for Microsoft Azure RTOS. Full text of the license can be */
|
||||
/* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */
|
||||
/* and in the root directory of this software. */
|
||||
/* */
|
||||
/**************************************************************************/
|
||||
|
||||
|
||||
/**************************************************************************/
|
||||
/**************************************************************************/
|
||||
/** */
|
||||
/** LevelX Component */
|
||||
/** */
|
||||
/** NAND Flash */
|
||||
/** */
|
||||
/**************************************************************************/
|
||||
/**************************************************************************/
|
||||
|
||||
#define LX_SOURCE_CODE
|
||||
|
||||
|
||||
/* Disable ThreadX error checking. */
|
||||
|
||||
#ifndef TX_DISABLE_ERROR_CHECKING
|
||||
#define TX_DISABLE_ERROR_CHECKING
|
||||
#endif
|
||||
|
||||
|
||||
/* Include necessary system files. */
|
||||
|
||||
#include "lx_api.h"
|
||||
|
||||
|
||||
/**************************************************************************/
|
||||
/* */
|
||||
/* FUNCTION RELEASE */
|
||||
/* */
|
||||
/* _lx_nand_flash_block_obsoleted_check PORTABLE C */
|
||||
/* 6.0 */
|
||||
/* AUTHOR */
|
||||
/* */
|
||||
/* William E. Lamie, Microsoft Corporation */
|
||||
/* */
|
||||
/* DESCRIPTION */
|
||||
/* */
|
||||
/* This function checks to see if the specified block is completely */
|
||||
/* obsoleted. If so, the block is reclaimed (erased) and made */
|
||||
/* available. */
|
||||
/* */
|
||||
/* INPUT */
|
||||
/* */
|
||||
/* nand_flash NAND flash instance */
|
||||
/* block Block number to check */
|
||||
/* */
|
||||
/* OUTPUT */
|
||||
/* */
|
||||
/* None */
|
||||
/* */
|
||||
/* CALLS */
|
||||
/* */
|
||||
/* _lx_nand_flash_driver_block_status_get */
|
||||
/* Driver block status */
|
||||
/* _lx_nand_flash_driver_block_erase Driver block erase */
|
||||
/* _lx_nand_flash_driver_extra_bytes_get Driver get extra bytes */
|
||||
/* _lx_nand_flash_driver_block_status_set */
|
||||
/* Driver set extra bytes */
|
||||
/* _lx_nand_flash_driver_read Driver page read */
|
||||
/* _lx_nand_flash_driver_write Driver page write */
|
||||
/* _lx_nand_flash_block_reclaim Reclaim one block */
|
||||
/* _lx_nand_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 */
|
||||
/* */
|
||||
/**************************************************************************/
|
||||
VOID _lx_nand_flash_block_obsoleted_check(LX_NAND_FLASH *nand_flash, ULONG block)
|
||||
{
|
||||
|
||||
LX_NAND_PAGE_EXTRA_INFO extra_info;
|
||||
UCHAR block_status;
|
||||
ULONG *page_word_ptr;
|
||||
ULONG erase_count;
|
||||
ULONG j;
|
||||
UINT status;
|
||||
|
||||
|
||||
/* 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);
|
||||
|
||||
/* Simply return. */
|
||||
return;
|
||||
}
|
||||
|
||||
/* Is this block bad? */
|
||||
if (block_status != LX_NAND_GOOD_BLOCK)
|
||||
{
|
||||
|
||||
/* Yes, this block is bad. */
|
||||
|
||||
/* Call system error handler. */
|
||||
_lx_nand_flash_system_error(nand_flash, status, block, 0);
|
||||
|
||||
/* Simply return. */
|
||||
return;
|
||||
}
|
||||
|
||||
/* Read the extra bytes of page 0. This will tell us if the page has any valid mappings. */
|
||||
status = _lx_nand_flash_driver_extra_bytes_get(nand_flash, block, 0, (UCHAR *) &extra_info, sizeof(extra_info));
|
||||
|
||||
/* Check for an error from flash driver. */
|
||||
if (status)
|
||||
{
|
||||
|
||||
/* Call system error handler. */
|
||||
_lx_nand_flash_system_error(nand_flash, status, block, 0);
|
||||
|
||||
/* Simply return. */
|
||||
return;
|
||||
}
|
||||
|
||||
/* Determine if the block is full, since it must be full first before it can be
|
||||
completely obsoleted. */
|
||||
if ((extra_info.lx_nand_page_extra_info_logical_sector & LX_NAND_BLOCK_FULL) != 0)
|
||||
{
|
||||
|
||||
/* This block is not full, therefore it cannot be obsoleted. */
|
||||
|
||||
/* Simply return. */
|
||||
return;
|
||||
}
|
||||
|
||||
/* Setup pointer to internal buffer. */
|
||||
page_word_ptr = nand_flash -> lx_nand_flash_page_buffer;
|
||||
|
||||
/* Now read page 0 of the block, which has the erase count in the first 4 bytes. */
|
||||
status = _lx_nand_flash_driver_read(nand_flash, block, 0, page_word_ptr, (nand_flash -> lx_nand_flash_pages_per_block + 1));
|
||||
|
||||
/* 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)
|
||||
{
|
||||
|
||||
/* Simply return. */
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/* Determine if we have a valid logical sector mapping list. */
|
||||
if ((page_word_ptr[1] != LX_NAND_PAGE_FREE) &&
|
||||
(page_word_ptr[nand_flash -> lx_nand_flash_pages_per_block] == LX_NAND_PAGE_LIST_VALID))
|
||||
{
|
||||
|
||||
/* Yes, we have a valid logical sector mapping list in page 0. */
|
||||
|
||||
/* Traverse the list to look for the logical sector. */
|
||||
for (j = 1; j < nand_flash -> lx_nand_flash_pages_per_block; j++)
|
||||
{
|
||||
|
||||
/* Is this entry valid? */
|
||||
if (page_word_ptr[j] & LX_NAND_PAGE_VALID)
|
||||
{
|
||||
|
||||
/* Read in the actual page entry to make sure this logical sector mapping is still valid. */
|
||||
status = _lx_nand_flash_driver_extra_bytes_get(nand_flash, block, j, (UCHAR *) &extra_info, sizeof(extra_info));
|
||||
|
||||
/* Check for an error from flash driver. */
|
||||
if (status)
|
||||
{
|
||||
|
||||
/* Call system error handler. */
|
||||
_lx_nand_flash_system_error(nand_flash, status, block, j);
|
||||
|
||||
/* Simply return. */
|
||||
return;
|
||||
}
|
||||
|
||||
/* Determine if the actual page is still valid. */
|
||||
if (extra_info.lx_nand_page_extra_info_logical_sector & LX_NAND_PAGE_VALID)
|
||||
{
|
||||
|
||||
/* If so, we found a valid page so the block isn't completely obsoleted. */
|
||||
|
||||
/* Simply return. */
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Pickup the erase count. */
|
||||
erase_count = page_word_ptr[0];
|
||||
|
||||
/* Determine if we need to reclaim blocks to balance out the erase counts. */
|
||||
if ((erase_count == nand_flash -> lx_nand_flash_maximum_erase_count) &&
|
||||
((nand_flash -> lx_nand_flash_maximum_erase_count - nand_flash -> lx_nand_flash_minimum_erase_count) >= LX_NAND_FLASH_MAX_ERASE_COUNT_DELTA))
|
||||
{
|
||||
|
||||
/* Attempt to reclaim one block. */
|
||||
_lx_nand_flash_block_reclaim(nand_flash);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
/* At this point we can reclaim the block. */
|
||||
|
||||
/* Write the erased started indication. */
|
||||
page_word_ptr[0] = LX_BLOCK_ERASE_STARTED;
|
||||
status = _lx_nand_flash_driver_write(nand_flash, block, 0, page_word_ptr, LX_NAND_ERASE_COUNT_WRITE_SIZE);
|
||||
|
||||
/* Check for an error from flash driver. */
|
||||
if (status)
|
||||
{
|
||||
|
||||
/* Call system error handler. */
|
||||
_lx_nand_flash_system_error(nand_flash, status, block, 0);
|
||||
}
|
||||
|
||||
/* Erase the entire block. */
|
||||
status = _lx_nand_flash_driver_block_erase(nand_flash, block, erase_count+1);
|
||||
|
||||
/* 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++;
|
||||
|
||||
/* Update number of obsolete pages but not free pages since this block is now bad. */
|
||||
nand_flash -> lx_nand_flash_obsolete_pages = nand_flash -> lx_nand_flash_obsolete_pages - (nand_flash -> lx_nand_flash_pages_per_block - 1);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
/* Increment the erase count. */
|
||||
erase_count++;
|
||||
|
||||
/* Determine if the new erase count exceeds the maximum. */
|
||||
if (erase_count > ((ULONG) LX_BLOCK_ERASE_COUNT_MAX))
|
||||
{
|
||||
|
||||
/* Yes, erase count is in overflow. Stay at the maximum count. */
|
||||
erase_count = ((ULONG) LX_BLOCK_ERASE_COUNT_MAX);
|
||||
}
|
||||
|
||||
/* Determine if we need to update the maximum erase count. */
|
||||
if (erase_count > nand_flash -> lx_nand_flash_maximum_erase_count)
|
||||
{
|
||||
|
||||
/* Yes, a new maximum is present. */
|
||||
nand_flash -> lx_nand_flash_maximum_erase_count = erase_count;
|
||||
|
||||
/* Determine if the search pointer is on this block. */
|
||||
if (nand_flash -> lx_nand_flash_free_block_search == block)
|
||||
{
|
||||
|
||||
/* Move to next block. */
|
||||
nand_flash -> lx_nand_flash_free_block_search++;
|
||||
|
||||
/* Check for wrap condition. */
|
||||
if (nand_flash -> lx_nand_flash_free_block_search >= nand_flash -> lx_nand_flash_total_blocks)
|
||||
{
|
||||
|
||||
/* Reset to the beginning block. */
|
||||
nand_flash -> lx_nand_flash_free_block_search = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Set the buffer to all ones. */
|
||||
for (j = 0; j < nand_flash -> lx_nand_flash_words_per_page; j++)
|
||||
{
|
||||
|
||||
/* Set word to all ones. */
|
||||
page_word_ptr[j] = LX_ALL_ONES;
|
||||
}
|
||||
|
||||
/* Now store the erase count. */
|
||||
page_word_ptr[0] = (erase_count | LX_BLOCK_ERASED);
|
||||
|
||||
/* Write the erase count for the block. */
|
||||
status = _lx_nand_flash_driver_write(nand_flash, block, 0, page_word_ptr, LX_NAND_ERASE_COUNT_WRITE_SIZE);
|
||||
|
||||
/* Check to see if the write was successful. */
|
||||
if (status == LX_SUCCESS)
|
||||
{
|
||||
|
||||
/* Now store the erase count. */
|
||||
page_word_ptr[0] = erase_count;
|
||||
|
||||
/* Write the erase count for the block. */
|
||||
status = _lx_nand_flash_driver_write(nand_flash, block, 0, page_word_ptr, LX_NAND_ERASE_COUNT_WRITE_SIZE);
|
||||
}
|
||||
|
||||
/* 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);
|
||||
|
||||
/* Simply return. */
|
||||
return;
|
||||
}
|
||||
|
||||
/* Increment the bad block count. */
|
||||
nand_flash -> lx_nand_flash_bad_blocks++;
|
||||
|
||||
/* Update number of obsolete pages but not free pages since this block is now bad. */
|
||||
nand_flash -> lx_nand_flash_obsolete_pages = nand_flash -> lx_nand_flash_obsolete_pages - (nand_flash -> lx_nand_flash_pages_per_block - 1);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
/* Update parameters of this flash. */
|
||||
nand_flash -> lx_nand_flash_free_pages = nand_flash -> lx_nand_flash_free_pages + (nand_flash -> lx_nand_flash_pages_per_block - 1);
|
||||
nand_flash -> lx_nand_flash_obsolete_pages = nand_flash -> lx_nand_flash_obsolete_pages - (nand_flash -> lx_nand_flash_pages_per_block - 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,631 +0,0 @@
|
||||
/**************************************************************************/
|
||||
/* */
|
||||
/* Copyright (c) Microsoft Corporation. All rights reserved. */
|
||||
/* */
|
||||
/* This software is licensed under the Microsoft Software License */
|
||||
/* Terms for Microsoft Azure RTOS. Full text of the license can be */
|
||||
/* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */
|
||||
/* and in the root directory of this software. */
|
||||
/* */
|
||||
/**************************************************************************/
|
||||
|
||||
|
||||
/**************************************************************************/
|
||||
/**************************************************************************/
|
||||
/** */
|
||||
/** LevelX Component */
|
||||
/** */
|
||||
/** NAND Flash */
|
||||
/** */
|
||||
/**************************************************************************/
|
||||
/**************************************************************************/
|
||||
|
||||
#define LX_SOURCE_CODE
|
||||
|
||||
|
||||
/* Disable ThreadX error checking. */
|
||||
|
||||
#ifndef TX_DISABLE_ERROR_CHECKING
|
||||
#define TX_DISABLE_ERROR_CHECKING
|
||||
#endif
|
||||
|
||||
|
||||
/* Include necessary system files. */
|
||||
|
||||
#include "lx_api.h"
|
||||
|
||||
|
||||
/**************************************************************************/
|
||||
/* */
|
||||
/* FUNCTION RELEASE */
|
||||
/* */
|
||||
/* _lx_nand_flash_block_reclaim PORTABLE C */
|
||||
/* 6.0 */
|
||||
/* AUTHOR */
|
||||
/* */
|
||||
/* William E. Lamie, Microsoft Corporation */
|
||||
/* */
|
||||
/* DESCRIPTION */
|
||||
/* */
|
||||
/* This function reclaims one block from the NAND flash. */
|
||||
/* */
|
||||
/* INPUT */
|
||||
/* */
|
||||
/* nand_flash NAND flash instance */
|
||||
/* */
|
||||
/* OUTPUT */
|
||||
/* */
|
||||
/* return status */
|
||||
/* */
|
||||
/* CALLS */
|
||||
/* */
|
||||
/* _lx_nand_flash_driver_block_erase Driver erase block */
|
||||
/* _lx_nand_flash_driver_block_status_set */
|
||||
/* Set block status to bad */
|
||||
/* _lx_nand_flash_driver_extra_bytes_get NAND flash get extra bytes */
|
||||
/* _lx_nand_flash_driver_extra_bytes_set NAND flash set extra bytes */
|
||||
/* _lx_nand_flash_driver_write Driver flash page write */
|
||||
/* _lx_nand_flash_driver_read Driver flash page read */
|
||||
/* _lx_nand_flash_block_full_update Update page 0 with list of */
|
||||
/* mapped pages */
|
||||
/* _lx_nand_flash_next_block_to_erase_find */
|
||||
/* Find next block to erase */
|
||||
/* _lx_nand_flash_physical_page_allocate Allocate new page */
|
||||
/* _lx_nand_flash_sector_mapping_cache_invalidate */
|
||||
/* Invalidate cache entry */
|
||||
/* _lx_nand_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 */
|
||||
/* */
|
||||
/**************************************************************************/
|
||||
UINT _lx_nand_flash_block_reclaim(LX_NAND_FLASH *nand_flash)
|
||||
{
|
||||
|
||||
LX_NAND_PAGE_EXTRA_INFO old_extra_info;
|
||||
LX_NAND_PAGE_EXTRA_INFO new_extra_info;
|
||||
ULONG *page_word_ptr;
|
||||
ULONG i;
|
||||
ULONG erase_block;
|
||||
ULONG erase_count;
|
||||
ULONG mapped_pages;
|
||||
ULONG obsolete_pages;
|
||||
ULONG free_pages;
|
||||
ULONG logical_sector;
|
||||
ULONG new_block;
|
||||
ULONG new_page;
|
||||
ULONG new_erase_count;
|
||||
UINT status;
|
||||
|
||||
|
||||
/* Increment the reclaim attempts counter. */
|
||||
nand_flash -> lx_nand_flash_diagnostic_block_reclaim_attempts++;
|
||||
|
||||
/* Determine the next block to erase. */
|
||||
_lx_nand_flash_next_block_to_erase_find(nand_flash, &erase_block, &erase_count, &mapped_pages, &obsolete_pages);
|
||||
|
||||
/* Setup pointer to page memory. */
|
||||
page_word_ptr = nand_flash -> lx_nand_flash_page_buffer;
|
||||
|
||||
/* Determine if the search pointer is set for this block. */
|
||||
if (nand_flash -> lx_nand_flash_free_block_search == erase_block)
|
||||
{
|
||||
|
||||
/* Ensure the search block is not the block we are trying to free. */
|
||||
nand_flash -> lx_nand_flash_free_block_search = erase_block + 1;
|
||||
|
||||
/* Check for wrap condition. */
|
||||
if (nand_flash -> lx_nand_flash_free_block_search >= nand_flash -> lx_nand_flash_total_blocks)
|
||||
nand_flash -> lx_nand_flash_free_block_search = 0;
|
||||
}
|
||||
|
||||
/* Determine if this block is completely obsolete. */
|
||||
if (obsolete_pages == nand_flash -> lx_nand_flash_pages_per_block)
|
||||
{
|
||||
|
||||
/* Read page 0 of the block, which has the erase count in the first 4 bytes. */
|
||||
status = _lx_nand_flash_driver_read(nand_flash, erase_block, 0, page_word_ptr, (nand_flash -> lx_nand_flash_pages_per_block + 1));
|
||||
|
||||
/* Check for an error from flash driver. */
|
||||
if (status)
|
||||
{
|
||||
|
||||
/* Call system error handler. */
|
||||
_lx_nand_flash_system_error(nand_flash, status, erase_block, 0);
|
||||
}
|
||||
|
||||
/* Write the erased started indication. */
|
||||
page_word_ptr[0] = LX_BLOCK_ERASE_STARTED;
|
||||
status = _lx_nand_flash_driver_write(nand_flash, erase_block, 0, page_word_ptr, LX_NAND_ERASE_COUNT_WRITE_SIZE);
|
||||
|
||||
/* Check for an error from flash driver. */
|
||||
if (status)
|
||||
{
|
||||
|
||||
/* Call system error handler. */
|
||||
_lx_nand_flash_system_error(nand_flash, status, erase_block, 0);
|
||||
}
|
||||
|
||||
/* Erase the entire block. */
|
||||
status = _lx_nand_flash_driver_block_erase(nand_flash, erase_block, erase_count+1);
|
||||
|
||||
/* Check for an error from flash driver. */
|
||||
if (status)
|
||||
{
|
||||
|
||||
/* Call system error handler. */
|
||||
_lx_nand_flash_system_error(nand_flash, status, erase_block, 0);
|
||||
|
||||
/* Attempt to mark this block as bad. */
|
||||
status = _lx_nand_flash_driver_block_status_set(nand_flash, erase_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, erase_block, 0);
|
||||
}
|
||||
|
||||
/* Increment the bad block count. */
|
||||
nand_flash -> lx_nand_flash_bad_blocks++;
|
||||
|
||||
/* Update number of obsolete pages but not free pages since this block is now bad. */
|
||||
nand_flash -> lx_nand_flash_obsolete_pages = nand_flash -> lx_nand_flash_obsolete_pages - obsolete_pages;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
/* Increment the erase count. */
|
||||
erase_count++;
|
||||
|
||||
/* Determine if the new erase count exceeds the maximum. */
|
||||
if (erase_count > ((ULONG) LX_BLOCK_ERASE_COUNT_MAX))
|
||||
{
|
||||
|
||||
/* Yes, erase count is in overflow. Stay at the maximum count. */
|
||||
erase_count = ((ULONG) LX_BLOCK_ERASE_COUNT_MAX);
|
||||
}
|
||||
|
||||
/* Determine if we need to update the maximum erase count. */
|
||||
if (erase_count > nand_flash -> lx_nand_flash_maximum_erase_count)
|
||||
{
|
||||
|
||||
/* Yes, a new maximum is present. */
|
||||
nand_flash -> lx_nand_flash_maximum_erase_count = erase_count;
|
||||
}
|
||||
|
||||
/* Set the buffer to all ones. */
|
||||
for (i = 0; i < nand_flash -> lx_nand_flash_words_per_page; i++)
|
||||
{
|
||||
|
||||
/* Set word to all ones. */
|
||||
page_word_ptr[i] = LX_ALL_ONES;
|
||||
}
|
||||
|
||||
/* Now store the erase count. */
|
||||
page_word_ptr[0] = (erase_count | LX_BLOCK_ERASED);
|
||||
|
||||
/* Write the erase count for the block. */
|
||||
status = _lx_nand_flash_driver_write(nand_flash, erase_block, 0, page_word_ptr, LX_NAND_ERASE_COUNT_WRITE_SIZE);
|
||||
|
||||
/* Check the status. */
|
||||
if (status == LX_SUCCESS)
|
||||
{
|
||||
|
||||
/* Now store the erase count. */
|
||||
page_word_ptr[0] = erase_count;
|
||||
|
||||
/* Write the erase count for the block. */
|
||||
status = _lx_nand_flash_driver_write(nand_flash, erase_block, 0, page_word_ptr, LX_NAND_ERASE_COUNT_WRITE_SIZE);
|
||||
}
|
||||
|
||||
/* Check for an error from flash driver. */
|
||||
if (status)
|
||||
{
|
||||
|
||||
/* Call system error handler. */
|
||||
_lx_nand_flash_system_error(nand_flash, status, erase_block, 0);
|
||||
|
||||
/* Attempt to mark this block as bad. */
|
||||
status = _lx_nand_flash_driver_block_status_set(nand_flash, erase_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, erase_block, 0);
|
||||
}
|
||||
|
||||
/* Increment the bad block count. */
|
||||
nand_flash -> lx_nand_flash_bad_blocks++;
|
||||
|
||||
/* Update number of obsolete pages but not free pages since this block is now bad. */
|
||||
nand_flash -> lx_nand_flash_obsolete_pages = nand_flash -> lx_nand_flash_obsolete_pages - obsolete_pages;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
/* Update parameters of this flash. */
|
||||
nand_flash -> lx_nand_flash_free_pages = nand_flash -> lx_nand_flash_free_pages + obsolete_pages;
|
||||
nand_flash -> lx_nand_flash_obsolete_pages = nand_flash -> lx_nand_flash_obsolete_pages - obsolete_pages;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
/* Calculate the number of free pages in this block. */
|
||||
free_pages = nand_flash -> lx_nand_flash_pages_per_block - (obsolete_pages + mapped_pages);
|
||||
|
||||
/* Determine if there are enough free pages outside of this block to reclaim this block. */
|
||||
if (mapped_pages <= (nand_flash -> lx_nand_flash_free_pages - free_pages))
|
||||
{
|
||||
|
||||
/* Now search through the list to find mapped logical sectors to move. */
|
||||
for (i = 1; i < nand_flash -> lx_nand_flash_pages_per_block; i++)
|
||||
{
|
||||
|
||||
/* Read the logical sector mapping for this page. */
|
||||
status = _lx_nand_flash_driver_extra_bytes_get(nand_flash, erase_block, i, (UCHAR *) &old_extra_info, sizeof(old_extra_info));
|
||||
|
||||
/* Check for an error from flash driver. */
|
||||
if (status)
|
||||
{
|
||||
|
||||
/* Call system error handler. */
|
||||
_lx_nand_flash_system_error(nand_flash, status, erase_block, i);
|
||||
|
||||
/* Return the error. */
|
||||
return(status);
|
||||
}
|
||||
|
||||
/* Determine if the entry hasn't been used. */
|
||||
if (old_extra_info.lx_nand_page_extra_info_logical_sector == LX_NAND_PAGE_FREE)
|
||||
{
|
||||
|
||||
/* Since allocations are done sequentially in the block, we know nothing
|
||||
else exists after this point. */
|
||||
break;
|
||||
}
|
||||
|
||||
/* Is this entry mapped? */
|
||||
if (old_extra_info.lx_nand_page_extra_info_logical_sector & LX_NAND_PAGE_VALID)
|
||||
{
|
||||
|
||||
/* Pickup the logical sector associated with this mapped page. */
|
||||
logical_sector = old_extra_info.lx_nand_page_extra_info_logical_sector & LX_NAND_LOGICAL_SECTOR_MASK;
|
||||
|
||||
/* Invalidate the old logical sector mapping cache entry. */
|
||||
_lx_nand_flash_sector_mapping_cache_invalidate(nand_flash, logical_sector);
|
||||
|
||||
/* Allocate a new page for this write. */
|
||||
_lx_nand_flash_physical_page_allocate(nand_flash, &new_block, &new_page, &new_erase_count);
|
||||
|
||||
/* Check to see if the new block is the same as the block we are trying to reclaim. */
|
||||
if (new_block == erase_block)
|
||||
{
|
||||
|
||||
/* Yes, the new page was found in the block to be erased. Simply move the search pointer
|
||||
to the block after the erase block and search for another page from there. */
|
||||
nand_flash -> lx_nand_flash_free_block_search = erase_block + 1;
|
||||
|
||||
/* Check for wrap condition. */
|
||||
if (nand_flash -> lx_nand_flash_free_block_search >= nand_flash -> lx_nand_flash_total_blocks)
|
||||
nand_flash -> lx_nand_flash_free_block_search = 0;
|
||||
|
||||
/* Allocate new page again. */
|
||||
_lx_nand_flash_physical_page_allocate(nand_flash, &new_block, &new_page, &new_erase_count);
|
||||
|
||||
/* Check again for the new page inside of the block to erase. This should be impossible, since
|
||||
we check previously if there are enough free pages outside of this block needed to reclaim
|
||||
this block. */
|
||||
if (new_block == erase_block)
|
||||
{
|
||||
|
||||
/* System error, a new page is not available outside of the erase block.
|
||||
Clear the new page so we fall through to the error handling. */
|
||||
new_page = 0;
|
||||
}
|
||||
}
|
||||
|
||||
/* Determine if the new page allocation was successful. */
|
||||
if (new_page)
|
||||
{
|
||||
|
||||
/* Yes, we were able to allocate a new page for the logical sector. */
|
||||
|
||||
/* Read the existing page into the internal buffer. */
|
||||
status = _lx_nand_flash_driver_read(nand_flash, erase_block, i, page_word_ptr, nand_flash -> lx_nand_flash_words_per_page);
|
||||
|
||||
/* Check for an error from flash driver. */
|
||||
if (status)
|
||||
{
|
||||
|
||||
/* Call system error handler. */
|
||||
_lx_nand_flash_system_error(nand_flash, status, erase_block, i);
|
||||
|
||||
/* Determine if the error is fatal. */
|
||||
if (status != LX_NAND_ERROR_CORRECTED)
|
||||
{
|
||||
|
||||
/* Return the error. */
|
||||
return(status);
|
||||
}
|
||||
}
|
||||
|
||||
/* Write the logical sector data to the new page. */
|
||||
status = _lx_nand_flash_driver_write(nand_flash, new_block, new_page, page_word_ptr, nand_flash -> lx_nand_flash_words_per_page);
|
||||
|
||||
/* Check for an error from flash driver. */
|
||||
if (status)
|
||||
{
|
||||
|
||||
/* Call system error handler. */
|
||||
_lx_nand_flash_system_error(nand_flash, status, new_block, new_page);
|
||||
|
||||
/* Return the error. */
|
||||
return(status);
|
||||
}
|
||||
|
||||
/* Now deprecate the old logical sector mapping. */
|
||||
|
||||
/* Clear bit 30, which indicates this page is being superceded. */
|
||||
old_extra_info.lx_nand_page_extra_info_logical_sector = old_extra_info.lx_nand_page_extra_info_logical_sector & ~((ULONG) LX_NAND_PAGE_SUPERCEDED);
|
||||
|
||||
/* Write the value back to the flash to clear bit 30. */
|
||||
status = _lx_nand_flash_driver_extra_bytes_set(nand_flash, erase_block, i, (UCHAR *) &old_extra_info, sizeof(old_extra_info));
|
||||
|
||||
/* Check for an error from flash driver. */
|
||||
if (status)
|
||||
{
|
||||
|
||||
/* Call system error handler. */
|
||||
_lx_nand_flash_system_error(nand_flash, status, erase_block, i);
|
||||
|
||||
/* Return the error. */
|
||||
return(status);
|
||||
}
|
||||
|
||||
/* Now build the new mapping entry - with the not valid bit set initially. */
|
||||
new_extra_info.lx_nand_page_extra_info_logical_sector = ((ULONG) LX_NAND_PAGE_VALID) | ((ULONG) LX_NAND_PAGE_SUPERCEDED) | ((ULONG) LX_NAND_PAGE_MAPPING_NOT_VALID) | logical_sector;
|
||||
|
||||
/* Write out the new mapping entry. */
|
||||
status = _lx_nand_flash_driver_extra_bytes_set(nand_flash, new_block, new_page, (UCHAR *) &new_extra_info, sizeof(new_extra_info));
|
||||
|
||||
/* Check for an error from flash driver. */
|
||||
if (status)
|
||||
{
|
||||
|
||||
/* Call system error handler. */
|
||||
_lx_nand_flash_system_error(nand_flash, status, new_block, new_page);
|
||||
|
||||
/* Return the error. */
|
||||
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
|
||||
be interrupted and we need to make sure this can be detected when the flash is opened again. */
|
||||
new_extra_info.lx_nand_page_extra_info_logical_sector = new_extra_info.lx_nand_page_extra_info_logical_sector & ~((ULONG) LX_NAND_PAGE_MAPPING_NOT_VALID);
|
||||
|
||||
/* Clear the not valid bit. */
|
||||
status = _lx_nand_flash_driver_extra_bytes_set(nand_flash, new_block, new_page, (UCHAR *) &new_extra_info, sizeof(new_extra_info));
|
||||
|
||||
/* Check for an error from flash driver. */
|
||||
if (status)
|
||||
{
|
||||
|
||||
/* Call system error handler. */
|
||||
_lx_nand_flash_system_error(nand_flash, status, new_block, new_page);
|
||||
|
||||
/* Return the error. */
|
||||
return(status);
|
||||
}
|
||||
|
||||
#ifdef LX_NAND_FLASH_DIRECT_MAPPING_CACHE
|
||||
|
||||
/* Determine if this logical sector fits in the logical sector direct cache mapping. */
|
||||
if (logical_sector < LX_NAND_SECTOR_MAPPING_CACHE_SIZE)
|
||||
{
|
||||
|
||||
/* Remember the mapping for this logical sector. */
|
||||
nand_flash -> lx_nand_flash_sector_mapping_cache[logical_sector].lx_nand_sector_mapping_cache_block = (USHORT) new_block;
|
||||
nand_flash -> lx_nand_flash_sector_mapping_cache[logical_sector].lx_nand_sector_mapping_cache_page = (USHORT) new_page;
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Now clear bit 31, which indicates this sector is now obsoleted. */
|
||||
old_extra_info.lx_nand_page_extra_info_logical_sector = old_extra_info.lx_nand_page_extra_info_logical_sector & ~((ULONG) LX_NAND_PAGE_VALID);
|
||||
|
||||
/* Write the value back to the flash to clear bit 31. */
|
||||
status = _lx_nand_flash_driver_extra_bytes_set(nand_flash, erase_block, i, (UCHAR *) &old_extra_info, sizeof(old_extra_info));
|
||||
|
||||
/* Check for an error from flash driver. */
|
||||
if (status)
|
||||
{
|
||||
|
||||
/* Call system error handler. */
|
||||
_lx_nand_flash_system_error(nand_flash, status, erase_block, i);
|
||||
|
||||
/* Return the error. */
|
||||
return(status);
|
||||
}
|
||||
|
||||
/* Increment the number of moved pages. */
|
||||
nand_flash -> lx_nand_flash_diagnostic_moved_pages++;
|
||||
|
||||
/* Determine if the new page is the last page of the block. */
|
||||
if (new_page == (nand_flash -> lx_nand_flash_pages_per_block - 1))
|
||||
{
|
||||
|
||||
/* Yes, we need to update page 0 of the block with the list of mapped
|
||||
pages for this block. */
|
||||
_lx_nand_flash_block_full_update(nand_flash, new_block, new_erase_count);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
/* Call system error handler - the allocation should always succeed at this point. */
|
||||
_lx_nand_flash_system_error(nand_flash, LX_SYSTEM_ALLOCATION_FAILED, erase_block, i);
|
||||
|
||||
/* System error... break! */
|
||||
break;
|
||||
}
|
||||
|
||||
/* Decrement the number of mapped pages. */
|
||||
mapped_pages--;
|
||||
|
||||
/* Determine if we are done. */
|
||||
if (mapped_pages == 0)
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/* Read page 0 of the block, which has the erase count in the first 4 bytes. */
|
||||
status = _lx_nand_flash_driver_read(nand_flash, erase_block, 0, page_word_ptr, (nand_flash -> lx_nand_flash_pages_per_block + 1));
|
||||
|
||||
/* Check for an error from flash driver. */
|
||||
if (status)
|
||||
{
|
||||
|
||||
/* Call system error handler. */
|
||||
_lx_nand_flash_system_error(nand_flash, status, erase_block, 0);
|
||||
}
|
||||
|
||||
/* Write the erased started indication. */
|
||||
page_word_ptr[0] = LX_BLOCK_ERASE_STARTED;
|
||||
status = _lx_nand_flash_driver_write(nand_flash, erase_block, 0, page_word_ptr, LX_NAND_ERASE_COUNT_WRITE_SIZE);
|
||||
|
||||
/* Check for an error from flash driver. */
|
||||
if (status)
|
||||
{
|
||||
|
||||
/* Call system error handler. */
|
||||
_lx_nand_flash_system_error(nand_flash, status, erase_block, 0);
|
||||
}
|
||||
|
||||
/* Erase the entire block. */
|
||||
status = _lx_nand_flash_driver_block_erase(nand_flash, erase_block, erase_count+1);
|
||||
|
||||
/* Check for an error from flash driver. */
|
||||
if (status)
|
||||
{
|
||||
|
||||
/* Call system error handler. */
|
||||
_lx_nand_flash_system_error(nand_flash, status, erase_block, 0);
|
||||
|
||||
/* Attempt to mark this block as bad. */
|
||||
status = _lx_nand_flash_driver_block_status_set(nand_flash, erase_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, erase_block, 0);
|
||||
}
|
||||
|
||||
/* Increment the bad block count. */
|
||||
nand_flash -> lx_nand_flash_bad_blocks++;
|
||||
|
||||
/* Update number of obsolete pages but not free pages since this block is now bad. */
|
||||
nand_flash -> lx_nand_flash_obsolete_pages = nand_flash -> lx_nand_flash_obsolete_pages - obsolete_pages;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
/* Increment the erase count. */
|
||||
erase_count++;
|
||||
|
||||
/* Determine if the new erase count exceeds the maximum. */
|
||||
if (erase_count > ((ULONG) LX_BLOCK_ERASE_COUNT_MAX))
|
||||
{
|
||||
|
||||
/* Yes, erase count is in overflow. Stay at the maximum count. */
|
||||
erase_count = ((ULONG) LX_BLOCK_ERASE_COUNT_MAX);
|
||||
}
|
||||
|
||||
/* Determine if we need to update the maximum erase count. */
|
||||
if (erase_count > nand_flash -> lx_nand_flash_maximum_erase_count)
|
||||
{
|
||||
|
||||
/* Yes, a new maximum is present. */
|
||||
nand_flash -> lx_nand_flash_maximum_erase_count = erase_count;
|
||||
}
|
||||
|
||||
/* Set the buffer to all ones. */
|
||||
for (i = 0; i < nand_flash -> lx_nand_flash_words_per_page; i++)
|
||||
{
|
||||
|
||||
/* Set word to all ones. */
|
||||
page_word_ptr[i] = LX_ALL_ONES;
|
||||
}
|
||||
|
||||
/* Now store the erase count. */
|
||||
page_word_ptr[0] = (erase_count | LX_BLOCK_ERASED);
|
||||
|
||||
/* Write the erase count for the block. */
|
||||
status = _lx_nand_flash_driver_write(nand_flash, erase_block, 0, page_word_ptr, LX_NAND_ERASE_COUNT_WRITE_SIZE);
|
||||
|
||||
/* Determine if the write was successful. */
|
||||
if (status == LX_SUCCESS)
|
||||
{
|
||||
|
||||
/* Now store the erase count. */
|
||||
page_word_ptr[0] = erase_count;
|
||||
|
||||
/* Write the erase count for the block. */
|
||||
status = _lx_nand_flash_driver_write(nand_flash, erase_block, 0, page_word_ptr, LX_NAND_ERASE_COUNT_WRITE_SIZE);
|
||||
}
|
||||
|
||||
/* Check for an error from flash driver. */
|
||||
if (status)
|
||||
{
|
||||
|
||||
/* Call system error handler. */
|
||||
_lx_nand_flash_system_error(nand_flash, status, erase_block, 0);
|
||||
|
||||
/* Attempt to mark this block as bad. */
|
||||
status = _lx_nand_flash_driver_block_status_set(nand_flash, erase_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, erase_block, 0);
|
||||
|
||||
/* Return the error. */
|
||||
return(status);
|
||||
}
|
||||
|
||||
/* Increment the bad block count. */
|
||||
nand_flash -> lx_nand_flash_bad_blocks++;
|
||||
|
||||
/* Update number of obsolete pages but not free pages since this block is now bad. */
|
||||
nand_flash -> lx_nand_flash_obsolete_pages = nand_flash -> lx_nand_flash_obsolete_pages - obsolete_pages;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
/* Update parameters of this flash. */
|
||||
nand_flash -> lx_nand_flash_free_pages = nand_flash -> lx_nand_flash_free_pages + obsolete_pages;
|
||||
nand_flash -> lx_nand_flash_obsolete_pages = nand_flash -> lx_nand_flash_obsolete_pages - obsolete_pages;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Return status. */
|
||||
return(LX_SUCCESS);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,91 @@
|
||||
/***************************************************************************
|
||||
* Copyright (c) 2024 Microsoft Corporation
|
||||
* Copyright (c) 2026-present Eclipse ThreadX contributors
|
||||
*
|
||||
* This program and the accompanying materials are made available under the
|
||||
* terms of the MIT License which is available at
|
||||
* https://opensource.org/licenses/MIT.
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
**************************************************************************/
|
||||
|
||||
|
||||
/**************************************************************************/
|
||||
/**************************************************************************/
|
||||
/** */
|
||||
/** LevelX Component */
|
||||
/** */
|
||||
/** NAND Flash */
|
||||
/** */
|
||||
/**************************************************************************/
|
||||
/**************************************************************************/
|
||||
|
||||
#define LX_SOURCE_CODE
|
||||
|
||||
|
||||
/* Disable ThreadX error checking. */
|
||||
|
||||
#ifndef LX_DISABLE_ERROR_CHECKING
|
||||
#define LX_DISABLE_ERROR_CHECKING
|
||||
#endif
|
||||
|
||||
|
||||
/* Include necessary system files. */
|
||||
|
||||
#include "lx_api.h"
|
||||
|
||||
|
||||
/**************************************************************************/
|
||||
/* */
|
||||
/* FUNCTION RELEASE */
|
||||
/* */
|
||||
/* _lx_nand_flash_block_status_set PORTABLE C */
|
||||
/* 6.2.1 */
|
||||
/* AUTHOR */
|
||||
/* */
|
||||
/* Xiuwen Cai, Microsoft Corporation */
|
||||
/* */
|
||||
/* 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 */
|
||||
/* */
|
||||
/**************************************************************************/
|
||||
UINT _lx_nand_flash_block_status_set(LX_NAND_FLASH *nand_flash, ULONG block, ULONG block_status)
|
||||
{
|
||||
|
||||
UCHAR page_number;
|
||||
UINT status;
|
||||
|
||||
|
||||
/* Save the block status to status table. */
|
||||
nand_flash -> lx_nand_flash_block_status_table[block] = (USHORT)block_status;
|
||||
|
||||
/* Get the page number to write. */
|
||||
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. */
|
||||
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);
|
||||
|
||||
/* Return status. */
|
||||
return(status);
|
||||
}
|
||||
|
||||
@@ -1,19 +1,19 @@
|
||||
/**************************************************************************/
|
||||
/* */
|
||||
/* Copyright (c) Microsoft Corporation. All rights reserved. */
|
||||
/* */
|
||||
/* This software is licensed under the Microsoft Software License */
|
||||
/* Terms for Microsoft Azure RTOS. Full text of the license can be */
|
||||
/* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */
|
||||
/* and in the root directory of this software. */
|
||||
/* */
|
||||
/**************************************************************************/
|
||||
/***************************************************************************
|
||||
* Copyright (c) 2024 Microsoft Corporation
|
||||
* Copyright (c) 2026-present Eclipse ThreadX contributors
|
||||
*
|
||||
* This program and the accompanying materials are made available under the
|
||||
* terms of the MIT License which is available at
|
||||
* https://opensource.org/licenses/MIT.
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
**************************************************************************/
|
||||
|
||||
|
||||
/**************************************************************************/
|
||||
/**************************************************************************/
|
||||
/** */
|
||||
/** LevelX Component */
|
||||
/** */
|
||||
/** LevelX Component */
|
||||
/** */
|
||||
/** NAND Flash */
|
||||
/** */
|
||||
@@ -25,8 +25,8 @@
|
||||
|
||||
/* Disable ThreadX error checking. */
|
||||
|
||||
#ifndef TX_DISABLE_ERROR_CHECKING
|
||||
#define TX_DISABLE_ERROR_CHECKING
|
||||
#ifndef LX_DISABLE_ERROR_CHECKING
|
||||
#define LX_DISABLE_ERROR_CHECKING
|
||||
#endif
|
||||
|
||||
|
||||
@@ -35,51 +35,45 @@
|
||||
#include "lx_api.h"
|
||||
|
||||
|
||||
/**************************************************************************/
|
||||
/* */
|
||||
/* FUNCTION RELEASE */
|
||||
/* */
|
||||
/* _lx_nand_flash_close PORTABLE C */
|
||||
/* 6.0 */
|
||||
/**************************************************************************/
|
||||
/* */
|
||||
/* FUNCTION RELEASE */
|
||||
/* */
|
||||
/* _lx_nand_flash_close PORTABLE C */
|
||||
/* 6.1.7 */
|
||||
/* AUTHOR */
|
||||
/* */
|
||||
/* William E. Lamie, Microsoft Corporation */
|
||||
/* */
|
||||
/* 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 */
|
||||
/* DESCRIPTION */
|
||||
/* */
|
||||
/* 05-19-2020 William E. Lamie Initial Version 6.0 */
|
||||
/* 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 */
|
||||
/* */
|
||||
/**************************************************************************/
|
||||
UINT _lx_nand_flash_close(LX_NAND_FLASH *nand_flash)
|
||||
{
|
||||
|
||||
TX_INTERRUPT_SAVE_AREA
|
||||
LX_INTERRUPT_SAVE_AREA
|
||||
|
||||
|
||||
/* Lockout interrupts for NAND flash close. */
|
||||
TX_DISABLE
|
||||
LX_DISABLE
|
||||
|
||||
/* See if the media is the only one on the media opened list. */
|
||||
if ((_lx_nand_flash_opened_ptr == nand_flash) &&
|
||||
@@ -102,9 +96,9 @@ TX_INTERRUPT_SAVE_AREA
|
||||
/* See if we have to update the opened list head pointer. */
|
||||
if (_lx_nand_flash_opened_ptr == 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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -113,9 +107,9 @@ TX_INTERRUPT_SAVE_AREA
|
||||
|
||||
/* Finally, indicate that this NAND flash is closed. */
|
||||
nand_flash -> lx_nand_flash_state = LX_NAND_FLASH_CLOSED;
|
||||
|
||||
|
||||
/* Restore interrupt posture. */
|
||||
TX_RESTORE
|
||||
LX_RESTORE
|
||||
|
||||
#ifdef LX_THREAD_SAFE_ENABLE
|
||||
|
||||
|
||||
@@ -0,0 +1,246 @@
|
||||
/***************************************************************************
|
||||
* Copyright (c) 2024 Microsoft Corporation
|
||||
* Copyright (c) 2026-present Eclipse ThreadX contributors
|
||||
*
|
||||
* This program and the accompanying materials are made available under the
|
||||
* terms of the MIT License which is available at
|
||||
* https://opensource.org/licenses/MIT.
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
**************************************************************************/
|
||||
|
||||
|
||||
/**************************************************************************/
|
||||
/**************************************************************************/
|
||||
/** */
|
||||
/** LevelX Component */
|
||||
/** */
|
||||
/** NAND Flash */
|
||||
/** */
|
||||
/**************************************************************************/
|
||||
/**************************************************************************/
|
||||
|
||||
#define LX_SOURCE_CODE
|
||||
|
||||
|
||||
/* Disable ThreadX error checking. */
|
||||
|
||||
#ifndef LX_DISABLE_ERROR_CHECKING
|
||||
#define LX_DISABLE_ERROR_CHECKING
|
||||
#endif
|
||||
|
||||
|
||||
/* Include necessary system files. */
|
||||
|
||||
#include "lx_api.h"
|
||||
|
||||
|
||||
/**************************************************************************/
|
||||
/* */
|
||||
/* FUNCTION RELEASE */
|
||||
/* */
|
||||
/* _lx_nand_flash_data_page_copy PORTABLE C */
|
||||
/* 6.4.0 */
|
||||
/* AUTHOR */
|
||||
/* */
|
||||
/* Xiuwen Cai, Microsoft Corporation */
|
||||
/* */
|
||||
/* 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 */
|
||||
/* */
|
||||
/**************************************************************************/
|
||||
UINT _lx_nand_flash_data_page_copy(LX_NAND_FLASH* nand_flash, ULONG logical_sector, ULONG source_block, USHORT src_block_status,
|
||||
ULONG destination_block, USHORT* dest_block_status_ptr, ULONG sectors)
|
||||
{
|
||||
|
||||
LONG source_page;
|
||||
ULONG destination_page;
|
||||
UINT status = LX_SUCCESS;
|
||||
UINT i;
|
||||
ULONG available_pages;
|
||||
ULONG spare_data1;
|
||||
UCHAR *spare_buffer_ptr;
|
||||
ULONG dest_block_status;
|
||||
ULONG number_of_pages;
|
||||
|
||||
|
||||
/* Get the destination block status. */
|
||||
dest_block_status = *dest_block_status_ptr;
|
||||
|
||||
/* Get the current page number of the destination block. */
|
||||
destination_page = dest_block_status & LX_NAND_BLOCK_STATUS_PAGE_NUMBER_MASK;
|
||||
|
||||
/* Get the available pages in the source block. */
|
||||
available_pages = (src_block_status & LX_NAND_BLOCK_STATUS_FULL) ? (nand_flash -> lx_nand_flash_pages_per_block) : (src_block_status & LX_NAND_BLOCK_STATUS_PAGE_NUMBER_MASK);
|
||||
|
||||
/* Check if pages in the source block are sequential. */
|
||||
if (src_block_status & LX_NAND_BLOCK_STATUS_NON_SEQUENTIAL)
|
||||
{
|
||||
|
||||
/* Get buffer for spare data. */
|
||||
spare_buffer_ptr = nand_flash -> lx_nand_flash_page_buffer + nand_flash -> lx_nand_flash_bytes_per_page;
|
||||
|
||||
/* Loop to copy the data. */
|
||||
for (i = 0; i < sectors; i++)
|
||||
{
|
||||
|
||||
/* Loop to search the page. */
|
||||
for (source_page = (LONG)(available_pages - 1); source_page >= 0; source_page--)
|
||||
{
|
||||
|
||||
/* Read one page. */
|
||||
#ifdef LX_NAND_ENABLE_CONTROL_BLOCK_FOR_DRIVER_INTERFACE
|
||||
status = (nand_flash -> lx_nand_flash_driver_pages_read)(nand_flash, source_block, (ULONG)source_page, LX_NULL, spare_buffer_ptr, 1);
|
||||
#else
|
||||
status = (nand_flash -> lx_nand_flash_driver_pages_read)(source_block, (ULONG)source_page, LX_NULL, 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, source_block, 0);
|
||||
|
||||
/* Return an error. */
|
||||
return(LX_ERROR);
|
||||
}
|
||||
|
||||
/* Get the spare data. */
|
||||
spare_data1 = LX_UTILITY_LONG_GET(&spare_buffer_ptr[nand_flash -> lx_nand_flash_spare_data1_offset]);
|
||||
|
||||
/* Check the address match. */
|
||||
if ((spare_data1 & LX_NAND_PAGE_TYPE_USER_DATA_MASK) == (logical_sector + i))
|
||||
{
|
||||
|
||||
/* Check if the page contains valid data. */
|
||||
if ((spare_data1 & (~LX_NAND_PAGE_TYPE_USER_DATA_MASK)) == (LX_NAND_PAGE_TYPE_USER_DATA))
|
||||
{
|
||||
|
||||
/* Call the driver to copy the page. */
|
||||
#ifdef LX_NAND_ENABLE_CONTROL_BLOCK_FOR_DRIVER_INTERFACE
|
||||
status = (nand_flash -> lx_nand_flash_driver_pages_copy)(nand_flash, source_block, (ULONG)source_page, destination_block, destination_page, 1, nand_flash -> lx_nand_flash_page_buffer);
|
||||
#else
|
||||
status = (nand_flash -> lx_nand_flash_driver_pages_copy)(source_block, (ULONG)source_page, destination_block, destination_page, 1, nand_flash -> lx_nand_flash_page_buffer);
|
||||
#endif
|
||||
|
||||
/* Check for an error from flash driver. */
|
||||
if (status)
|
||||
{
|
||||
|
||||
/* Call system error handler. */
|
||||
_lx_nand_flash_system_error(nand_flash, status, source_block, 0);
|
||||
|
||||
/* Return an error. */
|
||||
return(LX_ERROR);
|
||||
}
|
||||
|
||||
/* Check if the pages in destination block is still sequential. */
|
||||
if (destination_page != ((logical_sector + i) % nand_flash -> lx_nand_flash_pages_per_block))
|
||||
{
|
||||
/* Mark the block status as non sequential. */
|
||||
dest_block_status |= LX_NAND_BLOCK_STATUS_NON_SEQUENTIAL;
|
||||
}
|
||||
|
||||
/* Update the available pages. */
|
||||
destination_page++;
|
||||
|
||||
/* Check if available page count reaches pages per block. */
|
||||
if (destination_page == nand_flash -> lx_nand_flash_pages_per_block)
|
||||
{
|
||||
|
||||
/* Set block full flag. */
|
||||
dest_block_status |= LX_NAND_BLOCK_STATUS_FULL;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
/* Get the source page number. */
|
||||
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. */
|
||||
number_of_pages = ((ULONG)source_page + sectors) > available_pages ?
|
||||
(available_pages > (ULONG)source_page ? available_pages - (ULONG)source_page : 0) : sectors;
|
||||
|
||||
/* Check if there is any pages to be copied. */
|
||||
if (number_of_pages)
|
||||
{
|
||||
|
||||
/* Call the driver to copy pages. */
|
||||
#ifdef LX_NAND_ENABLE_CONTROL_BLOCK_FOR_DRIVER_INTERFACE
|
||||
status = (nand_flash -> lx_nand_flash_driver_pages_copy)(nand_flash, source_block, (ULONG)source_page, destination_block, destination_page, number_of_pages, nand_flash -> lx_nand_flash_page_buffer);
|
||||
#else
|
||||
status = (nand_flash -> lx_nand_flash_driver_pages_copy)(source_block, (ULONG)source_page, destination_block, destination_page, number_of_pages, nand_flash -> lx_nand_flash_page_buffer);
|
||||
#endif
|
||||
|
||||
/* Check for an error from flash driver. */
|
||||
if (status)
|
||||
{
|
||||
|
||||
/* Call system error handler. */
|
||||
_lx_nand_flash_system_error(nand_flash, status, source_block, 0);
|
||||
|
||||
/* Return an error. */
|
||||
return(LX_ERROR);
|
||||
}
|
||||
|
||||
/* Check if the pages in destination block is still sequential. */
|
||||
if ((ULONG)source_page != destination_page)
|
||||
{
|
||||
|
||||
/* Mark the block status as non sequential. */
|
||||
dest_block_status |= LX_NAND_BLOCK_STATUS_NON_SEQUENTIAL;
|
||||
}
|
||||
|
||||
/* Update the available pages. */
|
||||
destination_page += number_of_pages;
|
||||
|
||||
/* Check if available page count reaches pages per block. */
|
||||
if (destination_page == nand_flash -> lx_nand_flash_pages_per_block)
|
||||
{
|
||||
|
||||
/* Set block full flag. */
|
||||
dest_block_status |= LX_NAND_BLOCK_STATUS_FULL;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Return the block status. */
|
||||
*dest_block_status_ptr = (USHORT)(destination_page | (dest_block_status & ~LX_NAND_BLOCK_STATUS_PAGE_NUMBER_MASK));
|
||||
|
||||
/* Return status. */
|
||||
return(status);
|
||||
}
|
||||
|
||||
@@ -1,19 +1,20 @@
|
||||
/**************************************************************************/
|
||||
/* */
|
||||
/* Copyright (c) Microsoft Corporation. All rights reserved. */
|
||||
/* */
|
||||
/* This software is licensed under the Microsoft Software License */
|
||||
/* Terms for Microsoft Azure RTOS. Full text of the license can be */
|
||||
/* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */
|
||||
/* and in the root directory of this software. */
|
||||
/* */
|
||||
/**************************************************************************/
|
||||
/***************************************************************************
|
||||
* 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 */
|
||||
/** */
|
||||
/** LevelX Component */
|
||||
/** */
|
||||
/** NAND Flash */
|
||||
/** */
|
||||
@@ -25,8 +26,8 @@
|
||||
|
||||
/* Disable ThreadX error checking. */
|
||||
|
||||
#ifndef TX_DISABLE_ERROR_CHECKING
|
||||
#define TX_DISABLE_ERROR_CHECKING
|
||||
#ifndef LX_DISABLE_ERROR_CHECKING
|
||||
#define LX_DISABLE_ERROR_CHECKING
|
||||
#endif
|
||||
|
||||
|
||||
@@ -35,78 +36,75 @@
|
||||
#include "lx_api.h"
|
||||
|
||||
|
||||
/**************************************************************************/
|
||||
/* */
|
||||
/* FUNCTION RELEASE */
|
||||
/* */
|
||||
/* _lx_nand_flash_defragment PORTABLE C */
|
||||
/* 6.0 */
|
||||
/**************************************************************************/
|
||||
/* */
|
||||
/* FUNCTION RELEASE */
|
||||
/* */
|
||||
/* _lx_nand_flash_defragment PORTABLE C */
|
||||
/* 6.2.1 */
|
||||
/* AUTHOR */
|
||||
/* */
|
||||
/* William E. Lamie, Microsoft Corporation */
|
||||
/* */
|
||||
/* 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 */
|
||||
/* DESCRIPTION */
|
||||
/* */
|
||||
/* 05-19-2020 William E. Lamie Initial Version 6.0 */
|
||||
/* 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 */
|
||||
/* */
|
||||
/**************************************************************************/
|
||||
UINT _lx_nand_flash_defragment(LX_NAND_FLASH *nand_flash)
|
||||
{
|
||||
|
||||
ULONG i;
|
||||
|
||||
#ifdef LX_NAND_FLASH_ENABLE_LAZY_SECTOR_RELEASE
|
||||
|
||||
#ifdef LX_THREAD_SAFE_ENABLE
|
||||
UINT status;
|
||||
ULONG lg;
|
||||
|
||||
/* Obtain the thread safe mutex. */
|
||||
tx_mutex_get(&nand_flash -> lx_nand_flash_mutex, TX_WAIT_FOREVER);
|
||||
#endif
|
||||
|
||||
/* Loop for max number of blocks, while there are obsolete count. */
|
||||
for (i = 0; i < nand_flash -> lx_nand_flash_total_blocks; i++)
|
||||
/* Compact every logical group that has a deferred compaction pending. */
|
||||
for (lg = 0; lg < nand_flash -> lx_nand_flash_total_blocks; lg++)
|
||||
{
|
||||
|
||||
/* Determine if there is any more defragment work. */
|
||||
if (nand_flash -> lx_nand_flash_obsolete_pages == 0)
|
||||
break;
|
||||
|
||||
/* Call the block reclaim function to defragment. */
|
||||
_lx_nand_flash_block_reclaim(nand_flash);
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef LX_THREAD_SAFE_ENABLE
|
||||
|
||||
/* Release the thread safe mutex. */
|
||||
tx_mutex_put(&nand_flash -> lx_nand_flash_mutex);
|
||||
#endif
|
||||
|
||||
/* Return successful completion. */
|
||||
return(LX_SUCCESS);
|
||||
|
||||
#else
|
||||
|
||||
LX_PARAMETER_NOT_USED(nand_flash);
|
||||
|
||||
/* Return not supported. */
|
||||
return(LX_NOT_SUPPORTED);
|
||||
|
||||
#endif /* LX_NAND_FLASH_ENABLE_LAZY_SECTOR_RELEASE */
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -1,19 +1,19 @@
|
||||
/**************************************************************************/
|
||||
/* */
|
||||
/* Copyright (c) Microsoft Corporation. All rights reserved. */
|
||||
/* */
|
||||
/* This software is licensed under the Microsoft Software License */
|
||||
/* Terms for Microsoft Azure RTOS. Full text of the license can be */
|
||||
/* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */
|
||||
/* and in the root directory of this software. */
|
||||
/* */
|
||||
/**************************************************************************/
|
||||
/***************************************************************************
|
||||
* Copyright (c) 2024 Microsoft Corporation
|
||||
* Copyright (c) 2026-present Eclipse ThreadX contributors
|
||||
*
|
||||
* This program and the accompanying materials are made available under the
|
||||
* terms of the MIT License which is available at
|
||||
* https://opensource.org/licenses/MIT.
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
**************************************************************************/
|
||||
|
||||
|
||||
/**************************************************************************/
|
||||
/**************************************************************************/
|
||||
/** */
|
||||
/** LevelX Component */
|
||||
/** */
|
||||
/** LevelX Component */
|
||||
/** */
|
||||
/** NAND Flash */
|
||||
/** */
|
||||
@@ -25,8 +25,8 @@
|
||||
|
||||
/* Disable ThreadX error checking. */
|
||||
|
||||
#ifndef TX_DISABLE_ERROR_CHECKING
|
||||
#define TX_DISABLE_ERROR_CHECKING
|
||||
#ifndef LX_DISABLE_ERROR_CHECKING
|
||||
#define LX_DISABLE_ERROR_CHECKING
|
||||
#endif
|
||||
|
||||
|
||||
@@ -35,100 +35,54 @@
|
||||
#include "lx_api.h"
|
||||
|
||||
|
||||
/**************************************************************************/
|
||||
/* */
|
||||
/* FUNCTION RELEASE */
|
||||
/* */
|
||||
/* _lx_nand_flash_driver_block_erase PORTABLE C */
|
||||
/* 6.0 */
|
||||
/**************************************************************************/
|
||||
/* */
|
||||
/* FUNCTION RELEASE */
|
||||
/* */
|
||||
/* _lx_nand_flash_driver_block_erase PORTABLE C */
|
||||
/* 6.2.1 */
|
||||
/* AUTHOR */
|
||||
/* */
|
||||
/* William E. Lamie, Microsoft Corporation */
|
||||
/* */
|
||||
/* 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 */
|
||||
/* DESCRIPTION */
|
||||
/* */
|
||||
/* 05-19-2020 William E. Lamie Initial Version 6.0 */
|
||||
/* 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 */
|
||||
/* */
|
||||
/**************************************************************************/
|
||||
UINT _lx_nand_flash_driver_block_erase(LX_NAND_FLASH *nand_flash, ULONG block, ULONG erase_count)
|
||||
{
|
||||
|
||||
ULONG cache_index;
|
||||
ULONG i;
|
||||
UINT status;
|
||||
|
||||
|
||||
/* Determine if the block status cache is enabled. */
|
||||
if (nand_flash -> lx_nand_flash_block_status_cache != LX_NULL)
|
||||
{
|
||||
|
||||
/* Save the block status value in the cache. */
|
||||
nand_flash -> lx_nand_flash_block_status_cache[block] = 0xFF;
|
||||
}
|
||||
|
||||
/* Determine if the page extra byte cache is enabled. */
|
||||
if (nand_flash -> lx_nand_flash_page_extra_bytes_cache != LX_NULL)
|
||||
{
|
||||
|
||||
/* Calculate the cache index. */
|
||||
cache_index = (block * nand_flash -> lx_nand_flash_pages_per_block);
|
||||
|
||||
/* Loop to clear the entries in the page extra bytes cache. */
|
||||
for (i = 0; i < nand_flash -> lx_nand_flash_pages_per_block; i++)
|
||||
{
|
||||
|
||||
/* Clear each cache entry. */
|
||||
nand_flash -> lx_nand_flash_page_extra_bytes_cache[cache_index+i].lx_nand_page_extra_info_logical_sector = (ULONG) 0xFFFFFFFF;
|
||||
}
|
||||
}
|
||||
|
||||
/* Determine if the page 0 cache is enabled. */
|
||||
if (nand_flash -> lx_nand_flash_page_0_cache != LX_NULL)
|
||||
{
|
||||
|
||||
/* Yes, the page 0 cache is enabled. */
|
||||
|
||||
/* Build index to page 0 cache. */
|
||||
cache_index = block * (nand_flash -> lx_nand_flash_pages_per_block + 1);
|
||||
|
||||
/* Clear the associated page 0 cache. */
|
||||
for (i = 0; i < (nand_flash -> lx_nand_flash_pages_per_block + 1); i++)
|
||||
{
|
||||
|
||||
/* Clear each cache entry. */
|
||||
nand_flash -> lx_nand_flash_page_0_cache[cache_index+i] = (ULONG) 0xFFFFFFFF;
|
||||
}
|
||||
}
|
||||
|
||||
/* Increment the block erases count. */
|
||||
nand_flash -> lx_nand_flash_diagnostic_block_erases++;
|
||||
|
||||
/* Call driver erase block function. */
|
||||
#ifdef LX_NAND_ENABLE_CONTROL_BLOCK_FOR_DRIVER_INTERFACE
|
||||
status = (nand_flash -> lx_nand_flash_driver_block_erase)(nand_flash, block, erase_count);
|
||||
#else
|
||||
status = (nand_flash -> lx_nand_flash_driver_block_erase)(block, erase_count);
|
||||
#endif
|
||||
|
||||
/* Return status. */
|
||||
return(status);
|
||||
|
||||
@@ -1,19 +1,19 @@
|
||||
/**************************************************************************/
|
||||
/* */
|
||||
/* Copyright (c) Microsoft Corporation. All rights reserved. */
|
||||
/* */
|
||||
/* This software is licensed under the Microsoft Software License */
|
||||
/* Terms for Microsoft Azure RTOS. Full text of the license can be */
|
||||
/* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */
|
||||
/* and in the root directory of this software. */
|
||||
/* */
|
||||
/**************************************************************************/
|
||||
/***************************************************************************
|
||||
* Copyright (c) 2024 Microsoft Corporation
|
||||
* Copyright (c) 2026-present Eclipse ThreadX contributors
|
||||
*
|
||||
* This program and the accompanying materials are made available under the
|
||||
* terms of the MIT License which is available at
|
||||
* https://opensource.org/licenses/MIT.
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
**************************************************************************/
|
||||
|
||||
|
||||
/**************************************************************************/
|
||||
/**************************************************************************/
|
||||
/** */
|
||||
/** LevelX Component */
|
||||
/** */
|
||||
/** LevelX Component */
|
||||
/** */
|
||||
/** NAND Flash */
|
||||
/** */
|
||||
@@ -25,8 +25,8 @@
|
||||
|
||||
/* Disable ThreadX error checking. */
|
||||
|
||||
#ifndef TX_DISABLE_ERROR_CHECKING
|
||||
#define TX_DISABLE_ERROR_CHECKING
|
||||
#ifndef LX_DISABLE_ERROR_CHECKING
|
||||
#define LX_DISABLE_ERROR_CHECKING
|
||||
#endif
|
||||
|
||||
|
||||
@@ -35,44 +35,38 @@
|
||||
#include "lx_api.h"
|
||||
|
||||
|
||||
/**************************************************************************/
|
||||
/* */
|
||||
/* FUNCTION RELEASE */
|
||||
/* */
|
||||
/* _lx_nand_flash_driver_block_erased_verify PORTABLE C */
|
||||
/* 6.0 */
|
||||
/**************************************************************************/
|
||||
/* */
|
||||
/* FUNCTION RELEASE */
|
||||
/* */
|
||||
/* _lx_nand_flash_driver_block_erased_verify PORTABLE C */
|
||||
/* 6.2.1 */
|
||||
/* AUTHOR */
|
||||
/* */
|
||||
/* William E. Lamie, Microsoft Corporation */
|
||||
/* */
|
||||
/* 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 */
|
||||
/* DESCRIPTION */
|
||||
/* */
|
||||
/* 05-19-2020 William E. Lamie Initial Version 6.0 */
|
||||
/* 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 */
|
||||
/* */
|
||||
/**************************************************************************/
|
||||
UINT _lx_nand_flash_driver_block_erased_verify(LX_NAND_FLASH *nand_flash, ULONG block)
|
||||
@@ -84,8 +78,11 @@ UINT status;
|
||||
nand_flash -> lx_nand_flash_diagnostic_block_erased_verifies++;
|
||||
|
||||
/* Call driver block erased verify function. */
|
||||
#ifdef LX_NAND_ENABLE_CONTROL_BLOCK_FOR_DRIVER_INTERFACE
|
||||
status = (nand_flash -> lx_nand_flash_driver_block_erased_verify)(nand_flash, block);
|
||||
#else
|
||||
status = (nand_flash -> lx_nand_flash_driver_block_erased_verify)(block);
|
||||
|
||||
#endif
|
||||
/* Return status. */
|
||||
return(status);
|
||||
}
|
||||
|
||||
@@ -1,19 +1,19 @@
|
||||
/**************************************************************************/
|
||||
/* */
|
||||
/* Copyright (c) Microsoft Corporation. All rights reserved. */
|
||||
/* */
|
||||
/* This software is licensed under the Microsoft Software License */
|
||||
/* Terms for Microsoft Azure RTOS. Full text of the license can be */
|
||||
/* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */
|
||||
/* and in the root directory of this software. */
|
||||
/* */
|
||||
/**************************************************************************/
|
||||
/***************************************************************************
|
||||
* Copyright (c) 2024 Microsoft Corporation
|
||||
* Copyright (c) 2026-present Eclipse ThreadX contributors
|
||||
*
|
||||
* This program and the accompanying materials are made available under the
|
||||
* terms of the MIT License which is available at
|
||||
* https://opensource.org/licenses/MIT.
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
**************************************************************************/
|
||||
|
||||
|
||||
/**************************************************************************/
|
||||
/**************************************************************************/
|
||||
/** */
|
||||
/** LevelX Component */
|
||||
/** */
|
||||
/** LevelX Component */
|
||||
/** */
|
||||
/** NAND Flash */
|
||||
/** */
|
||||
@@ -25,8 +25,8 @@
|
||||
|
||||
/* Disable ThreadX error checking. */
|
||||
|
||||
#ifndef TX_DISABLE_ERROR_CHECKING
|
||||
#define TX_DISABLE_ERROR_CHECKING
|
||||
#ifndef LX_DISABLE_ERROR_CHECKING
|
||||
#define LX_DISABLE_ERROR_CHECKING
|
||||
#endif
|
||||
|
||||
|
||||
@@ -35,45 +35,39 @@
|
||||
#include "lx_api.h"
|
||||
|
||||
|
||||
/**************************************************************************/
|
||||
/* */
|
||||
/* FUNCTION RELEASE */
|
||||
/* */
|
||||
/* _lx_nand_flash_driver_block_status_get PORTABLE C */
|
||||
/* 6.0 */
|
||||
/**************************************************************************/
|
||||
/* */
|
||||
/* FUNCTION RELEASE */
|
||||
/* */
|
||||
/* _lx_nand_flash_driver_block_status_get PORTABLE C */
|
||||
/* 6.2.1 */
|
||||
/* AUTHOR */
|
||||
/* */
|
||||
/* William E. Lamie, Microsoft Corporation */
|
||||
/* */
|
||||
/* 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 */
|
||||
/* DESCRIPTION */
|
||||
/* */
|
||||
/* 05-19-2020 William E. Lamie Initial Version 6.0 */
|
||||
/* 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 */
|
||||
/* */
|
||||
/**************************************************************************/
|
||||
UINT _lx_nand_flash_driver_block_status_get(LX_NAND_FLASH *nand_flash, ULONG block, UCHAR *bad_block_flag)
|
||||
@@ -82,48 +76,15 @@ UINT _lx_nand_flash_driver_block_status_get(LX_NAND_FLASH *nand_flash, ULONG bl
|
||||
UINT status;
|
||||
|
||||
|
||||
/* Determine if the block status cache is disabled. */
|
||||
if (nand_flash -> lx_nand_flash_block_status_cache == LX_NULL)
|
||||
{
|
||||
|
||||
/* Increment the block status get count. */
|
||||
nand_flash -> lx_nand_flash_diagnostic_block_status_gets++;
|
||||
/* Increment the block status get count. */
|
||||
nand_flash -> lx_nand_flash_diagnostic_block_status_gets++;
|
||||
|
||||
/* Call driver block status get function. */
|
||||
status = (nand_flash -> lx_nand_flash_driver_block_status_get)(block, bad_block_flag);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
/* Determine if the block status cache entry is valid. */
|
||||
if (nand_flash -> lx_nand_flash_block_status_cache[block] != 0)
|
||||
{
|
||||
|
||||
/* Simply return this value. */
|
||||
*bad_block_flag = nand_flash -> lx_nand_flash_block_status_cache[block];
|
||||
|
||||
/* Increment the number of status byte cache hits. */
|
||||
nand_flash -> lx_nand_flash_diagnostic_block_status_cache_hits++;
|
||||
|
||||
/* Return successful status. */
|
||||
status = LX_SUCCESS;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
/* Increment the block status get count. */
|
||||
nand_flash -> lx_nand_flash_diagnostic_block_status_gets++;
|
||||
|
||||
/* Call driver block status get function. */
|
||||
status = (nand_flash -> lx_nand_flash_driver_block_status_get)(block, bad_block_flag);
|
||||
|
||||
/* Increment the number of status byte cache misses. */
|
||||
nand_flash -> lx_nand_flash_diagnostic_block_status_cache_misses++;
|
||||
|
||||
/* Save the block status value in the cache. */
|
||||
nand_flash -> lx_nand_flash_block_status_cache[block] = *bad_block_flag;
|
||||
}
|
||||
}
|
||||
/* Call driver block status get function. */
|
||||
#ifdef LX_NAND_ENABLE_CONTROL_BLOCK_FOR_DRIVER_INTERFACE
|
||||
status = (nand_flash -> lx_nand_flash_driver_block_status_get)(nand_flash, block, bad_block_flag);
|
||||
#else
|
||||
status = (nand_flash -> lx_nand_flash_driver_block_status_get)(block, bad_block_flag);
|
||||
#endif
|
||||
|
||||
/* Return status. */
|
||||
return(status);
|
||||
|
||||
@@ -1,19 +1,19 @@
|
||||
/**************************************************************************/
|
||||
/* */
|
||||
/* Copyright (c) Microsoft Corporation. All rights reserved. */
|
||||
/* */
|
||||
/* This software is licensed under the Microsoft Software License */
|
||||
/* Terms for Microsoft Azure RTOS. Full text of the license can be */
|
||||
/* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */
|
||||
/* and in the root directory of this software. */
|
||||
/* */
|
||||
/**************************************************************************/
|
||||
/***************************************************************************
|
||||
* Copyright (c) 2024 Microsoft Corporation
|
||||
* Copyright (c) 2026-present Eclipse ThreadX contributors
|
||||
*
|
||||
* This program and the accompanying materials are made available under the
|
||||
* terms of the MIT License which is available at
|
||||
* https://opensource.org/licenses/MIT.
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
**************************************************************************/
|
||||
|
||||
|
||||
/**************************************************************************/
|
||||
/**************************************************************************/
|
||||
/** */
|
||||
/** LevelX Component */
|
||||
/** */
|
||||
/** LevelX Component */
|
||||
/** */
|
||||
/** NAND Flash */
|
||||
/** */
|
||||
@@ -25,8 +25,8 @@
|
||||
|
||||
/* Disable ThreadX error checking. */
|
||||
|
||||
#ifndef TX_DISABLE_ERROR_CHECKING
|
||||
#define TX_DISABLE_ERROR_CHECKING
|
||||
#ifndef LX_DISABLE_ERROR_CHECKING
|
||||
#define LX_DISABLE_ERROR_CHECKING
|
||||
#endif
|
||||
|
||||
|
||||
@@ -35,45 +35,39 @@
|
||||
#include "lx_api.h"
|
||||
|
||||
|
||||
/**************************************************************************/
|
||||
/* */
|
||||
/* FUNCTION RELEASE */
|
||||
/* */
|
||||
/* _lx_nand_flash_driver_block_status_set PORTABLE C */
|
||||
/* 6.0 */
|
||||
/**************************************************************************/
|
||||
/* */
|
||||
/* FUNCTION RELEASE */
|
||||
/* */
|
||||
/* _lx_nand_flash_driver_block_status_set PORTABLE C */
|
||||
/* 6.2.1 */
|
||||
/* AUTHOR */
|
||||
/* */
|
||||
/* William E. Lamie, Microsoft Corporation */
|
||||
/* */
|
||||
/* 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 */
|
||||
/* DESCRIPTION */
|
||||
/* */
|
||||
/* 05-19-2020 William E. Lamie Initial Version 6.0 */
|
||||
/* 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 */
|
||||
/* */
|
||||
/**************************************************************************/
|
||||
UINT _lx_nand_flash_driver_block_status_set(LX_NAND_FLASH *nand_flash, ULONG block, UCHAR bad_block_flag)
|
||||
@@ -82,19 +76,15 @@ UINT _lx_nand_flash_driver_block_status_set(LX_NAND_FLASH *nand_flash, ULONG bl
|
||||
UINT status;
|
||||
|
||||
|
||||
/* Determine if the block status cache is enabled. */
|
||||
if (nand_flash -> lx_nand_flash_block_status_cache != LX_NULL)
|
||||
{
|
||||
|
||||
/* Save the block status value in the cache. */
|
||||
nand_flash -> lx_nand_flash_block_status_cache[block] = bad_block_flag;
|
||||
}
|
||||
|
||||
/* Increment the block status set count. */
|
||||
nand_flash -> lx_nand_flash_diagnostic_block_status_sets++;
|
||||
|
||||
/* Call driver block status set function. */
|
||||
#ifdef LX_NAND_ENABLE_CONTROL_BLOCK_FOR_DRIVER_INTERFACE
|
||||
status = (nand_flash -> lx_nand_flash_driver_block_status_set)(nand_flash, block, bad_block_flag);
|
||||
#else
|
||||
status = (nand_flash -> lx_nand_flash_driver_block_status_set)(block, bad_block_flag);
|
||||
#endif
|
||||
|
||||
/* Return status. */
|
||||
return(status);
|
||||
|
||||
@@ -1,148 +0,0 @@
|
||||
/**************************************************************************/
|
||||
/* */
|
||||
/* Copyright (c) Microsoft Corporation. All rights reserved. */
|
||||
/* */
|
||||
/* This software is licensed under the Microsoft Software License */
|
||||
/* Terms for Microsoft Azure RTOS. Full text of the license can be */
|
||||
/* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */
|
||||
/* and in the root directory of this software. */
|
||||
/* */
|
||||
/**************************************************************************/
|
||||
|
||||
|
||||
/**************************************************************************/
|
||||
/**************************************************************************/
|
||||
/** */
|
||||
/** LevelX Component */
|
||||
/** */
|
||||
/** NAND Flash */
|
||||
/** */
|
||||
/**************************************************************************/
|
||||
/**************************************************************************/
|
||||
|
||||
#define LX_SOURCE_CODE
|
||||
|
||||
|
||||
/* Disable ThreadX error checking. */
|
||||
|
||||
#ifndef TX_DISABLE_ERROR_CHECKING
|
||||
#define TX_DISABLE_ERROR_CHECKING
|
||||
#endif
|
||||
|
||||
|
||||
/* Include necessary system files. */
|
||||
|
||||
#include "lx_api.h"
|
||||
|
||||
|
||||
/**************************************************************************/
|
||||
/* */
|
||||
/* FUNCTION RELEASE */
|
||||
/* */
|
||||
/* _lx_nand_flash_driver_extra_bytes_get PORTABLE C */
|
||||
/* 6.0 */
|
||||
/* AUTHOR */
|
||||
/* */
|
||||
/* William E. Lamie, Microsoft Corporation */
|
||||
/* */
|
||||
/* DESCRIPTION */
|
||||
/* */
|
||||
/* This function calls the driver to get the extra bytes of a NAND */
|
||||
/* page. */
|
||||
/* */
|
||||
/* INPUT */
|
||||
/* */
|
||||
/* nand_flash NAND flash instance */
|
||||
/* block Block number */
|
||||
/* page Page number */
|
||||
/* destination Pointer to destination buffer */
|
||||
/* words Number of words to read */
|
||||
/* */
|
||||
/* OUTPUT */
|
||||
/* */
|
||||
/* Completion Status */
|
||||
/* */
|
||||
/* CALLS */
|
||||
/* */
|
||||
/* (lx_nand_flash_driver_extra_bytes_get)Get extra bytes from spare */
|
||||
/* */
|
||||
/* CALLED BY */
|
||||
/* */
|
||||
/* Internal LevelX */
|
||||
/* */
|
||||
/* RELEASE HISTORY */
|
||||
/* */
|
||||
/* DATE NAME DESCRIPTION */
|
||||
/* */
|
||||
/* 05-19-2020 William E. Lamie Initial Version 6.0 */
|
||||
/* */
|
||||
/**************************************************************************/
|
||||
UINT _lx_nand_flash_driver_extra_bytes_get(LX_NAND_FLASH *nand_flash, ULONG block, ULONG page, UCHAR *destination, UINT size)
|
||||
{
|
||||
|
||||
ULONG *source_ptr;
|
||||
ULONG *destination_ptr;
|
||||
ULONG cache_index;
|
||||
UINT status;
|
||||
|
||||
|
||||
/* Determine if the page extra bytes cache is disabled. */
|
||||
if (nand_flash -> lx_nand_flash_page_extra_bytes_cache == LX_NULL)
|
||||
{
|
||||
|
||||
/* Increment the page extra bytes get count. */
|
||||
nand_flash -> lx_nand_flash_diagnostic_page_extra_bytes_gets++;
|
||||
|
||||
/* Call driver extra bytes get function. */
|
||||
status = (nand_flash -> lx_nand_flash_driver_extra_bytes_get)(block, page, destination, size);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
/* Calculate the cache index. */
|
||||
cache_index = (block * nand_flash -> lx_nand_flash_pages_per_block) + page;
|
||||
|
||||
/* Setup the destination pointer. */
|
||||
destination_ptr = (ULONG *) destination;
|
||||
|
||||
/* Determine if this cache entry is valid. */
|
||||
if (nand_flash -> lx_nand_flash_page_extra_bytes_cache[cache_index].lx_nand_page_extra_info_logical_sector != 0)
|
||||
{
|
||||
|
||||
/* Simply return this value. */
|
||||
*destination_ptr = nand_flash -> lx_nand_flash_page_extra_bytes_cache[cache_index].lx_nand_page_extra_info_logical_sector;
|
||||
|
||||
/* Increment the number of page extra bytes cache hits. */
|
||||
nand_flash -> lx_nand_flash_diagnostic_page_extra_bytes_cache_hits++;
|
||||
|
||||
/* Return successful status. */
|
||||
status = LX_SUCCESS;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
/* Increment the page extra bytes get count. */
|
||||
nand_flash -> lx_nand_flash_diagnostic_page_extra_bytes_gets++;
|
||||
|
||||
/* Call driver extra bytes get function. */
|
||||
status = (nand_flash -> lx_nand_flash_driver_extra_bytes_get)(block, page, destination, size);
|
||||
|
||||
/* Increment the number of page extra bytes cache misses. */
|
||||
nand_flash -> lx_nand_flash_diagnostic_page_extra_bytes_cache_misses++;
|
||||
|
||||
/* Setup destination pointer. */
|
||||
destination_ptr = &nand_flash -> lx_nand_flash_page_extra_bytes_cache[cache_index].lx_nand_page_extra_info_logical_sector;
|
||||
|
||||
/* Setup source pointer. */
|
||||
source_ptr = (ULONG *) destination;
|
||||
|
||||
/* Save the value in the page extra bytes cache. */
|
||||
*destination_ptr = *source_ptr;
|
||||
}
|
||||
}
|
||||
|
||||
/* Return status. */
|
||||
return(status);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,113 +0,0 @@
|
||||
/**************************************************************************/
|
||||
/* */
|
||||
/* Copyright (c) Microsoft Corporation. All rights reserved. */
|
||||
/* */
|
||||
/* This software is licensed under the Microsoft Software License */
|
||||
/* Terms for Microsoft Azure RTOS. Full text of the license can be */
|
||||
/* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */
|
||||
/* and in the root directory of this software. */
|
||||
/* */
|
||||
/**************************************************************************/
|
||||
|
||||
|
||||
/**************************************************************************/
|
||||
/**************************************************************************/
|
||||
/** */
|
||||
/** LevelX Component */
|
||||
/** */
|
||||
/** NAND Flash */
|
||||
/** */
|
||||
/**************************************************************************/
|
||||
/**************************************************************************/
|
||||
|
||||
#define LX_SOURCE_CODE
|
||||
|
||||
|
||||
/* Disable ThreadX error checking. */
|
||||
|
||||
#ifndef TX_DISABLE_ERROR_CHECKING
|
||||
#define TX_DISABLE_ERROR_CHECKING
|
||||
#endif
|
||||
|
||||
|
||||
/* Include necessary system files. */
|
||||
|
||||
#include "lx_api.h"
|
||||
|
||||
|
||||
/**************************************************************************/
|
||||
/* */
|
||||
/* FUNCTION RELEASE */
|
||||
/* */
|
||||
/* _lx_nand_flash_driver_extra_bytes_set PORTABLE C */
|
||||
/* 6.0 */
|
||||
/* AUTHOR */
|
||||
/* */
|
||||
/* William E. Lamie, Microsoft Corporation */
|
||||
/* */
|
||||
/* DESCRIPTION */
|
||||
/* */
|
||||
/* This function calls the driver extra bytes set operation and */
|
||||
/* updates the internal cache. */
|
||||
/* */
|
||||
/* INPUT */
|
||||
/* */
|
||||
/* nand_flash NAND flash instance */
|
||||
/* block Block number */
|
||||
/* page Page number */
|
||||
/* source Pointer to source extra bytes */
|
||||
/* size Number of extra bytes */
|
||||
/* */
|
||||
/* OUTPUT */
|
||||
/* */
|
||||
/* Completion Status */
|
||||
/* */
|
||||
/* CALLS */
|
||||
/* */
|
||||
/* (lx_nand_flash_driver_extra_bytes_set) */
|
||||
/* NAND flash set extra bytes */
|
||||
/* */
|
||||
/* CALLED BY */
|
||||
/* */
|
||||
/* Internal LevelX */
|
||||
/* */
|
||||
/* RELEASE HISTORY */
|
||||
/* */
|
||||
/* DATE NAME DESCRIPTION */
|
||||
/* */
|
||||
/* 05-19-2020 William E. Lamie Initial Version 6.0 */
|
||||
/* */
|
||||
/**************************************************************************/
|
||||
UINT _lx_nand_flash_driver_extra_bytes_set(LX_NAND_FLASH *nand_flash, ULONG block, ULONG page, UCHAR *source, UINT size)
|
||||
{
|
||||
|
||||
ULONG cache_index;
|
||||
ULONG *destination_ptr;
|
||||
UINT status;
|
||||
|
||||
|
||||
/* Increment the page extra bytes set count. */
|
||||
nand_flash -> lx_nand_flash_diagnostic_page_extra_bytes_sets++;
|
||||
|
||||
/* Call driver extra bytes set function. */
|
||||
status = (nand_flash -> lx_nand_flash_driver_extra_bytes_set)(block, page, source, size);
|
||||
|
||||
/* Determine if the page extra bytes set cache is enabled. */
|
||||
if (nand_flash -> lx_nand_flash_page_extra_bytes_cache != LX_NULL)
|
||||
{
|
||||
|
||||
/* Calculate the cache index. */
|
||||
cache_index = (block * nand_flash -> lx_nand_flash_pages_per_block) + page;
|
||||
|
||||
/* Build destination address. */
|
||||
destination_ptr = &nand_flash -> lx_nand_flash_page_extra_bytes_cache[cache_index].lx_nand_page_extra_info_logical_sector;
|
||||
|
||||
/* Now save this in the cache. */
|
||||
*destination_ptr = *((ULONG *) source);
|
||||
}
|
||||
|
||||
/* Return status. */
|
||||
return(status);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,19 +1,19 @@
|
||||
/**************************************************************************/
|
||||
/* */
|
||||
/* Copyright (c) Microsoft Corporation. All rights reserved. */
|
||||
/* */
|
||||
/* This software is licensed under the Microsoft Software License */
|
||||
/* Terms for Microsoft Azure RTOS. Full text of the license can be */
|
||||
/* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */
|
||||
/* and in the root directory of this software. */
|
||||
/* */
|
||||
/**************************************************************************/
|
||||
/***************************************************************************
|
||||
* Copyright (c) 2024 Microsoft Corporation
|
||||
* Copyright (c) 2026-present Eclipse ThreadX contributors
|
||||
*
|
||||
* This program and the accompanying materials are made available under the
|
||||
* terms of the MIT License which is available at
|
||||
* https://opensource.org/licenses/MIT.
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
**************************************************************************/
|
||||
|
||||
|
||||
/**************************************************************************/
|
||||
/**************************************************************************/
|
||||
/** */
|
||||
/** LevelX Component */
|
||||
/** */
|
||||
/** LevelX Component */
|
||||
/** */
|
||||
/** NAND Flash */
|
||||
/** */
|
||||
@@ -25,8 +25,8 @@
|
||||
|
||||
/* Disable ThreadX error checking. */
|
||||
|
||||
#ifndef TX_DISABLE_ERROR_CHECKING
|
||||
#define TX_DISABLE_ERROR_CHECKING
|
||||
#ifndef LX_DISABLE_ERROR_CHECKING
|
||||
#define LX_DISABLE_ERROR_CHECKING
|
||||
#endif
|
||||
|
||||
|
||||
@@ -35,44 +35,38 @@
|
||||
#include "lx_api.h"
|
||||
|
||||
|
||||
/**************************************************************************/
|
||||
/* */
|
||||
/* FUNCTION RELEASE */
|
||||
/* */
|
||||
/* _lx_nand_flash_driver_page_erased_verify PORTABLE C */
|
||||
/* 6.0 */
|
||||
/**************************************************************************/
|
||||
/* */
|
||||
/* FUNCTION RELEASE */
|
||||
/* */
|
||||
/* _lx_nand_flash_driver_page_erased_verify PORTABLE C */
|
||||
/* 6.2.1 */
|
||||
/* AUTHOR */
|
||||
/* */
|
||||
/* William E. Lamie, Microsoft Corporation */
|
||||
/* */
|
||||
/* 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 */
|
||||
/* DESCRIPTION */
|
||||
/* */
|
||||
/* 05-19-2020 William E. Lamie Initial Version 6.0 */
|
||||
/* 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 */
|
||||
/* */
|
||||
/**************************************************************************/
|
||||
UINT _lx_nand_flash_driver_page_erased_verify(LX_NAND_FLASH *nand_flash, ULONG block, ULONG page)
|
||||
@@ -84,8 +78,11 @@ UINT status;
|
||||
nand_flash -> lx_nand_flash_diagnostic_page_erased_verifies++;
|
||||
|
||||
/* Call driver page erased verify function. */
|
||||
#ifdef LX_NAND_ENABLE_CONTROL_BLOCK_FOR_DRIVER_INTERFACE
|
||||
status = (nand_flash -> lx_nand_flash_driver_page_erased_verify)(nand_flash, block, page);
|
||||
#else
|
||||
status = (nand_flash -> lx_nand_flash_driver_page_erased_verify)(block, page);
|
||||
|
||||
#endif
|
||||
/* Return status. */
|
||||
return(status);
|
||||
}
|
||||
|
||||
@@ -1,180 +0,0 @@
|
||||
/**************************************************************************/
|
||||
/* */
|
||||
/* Copyright (c) Microsoft Corporation. All rights reserved. */
|
||||
/* */
|
||||
/* This software is licensed under the Microsoft Software License */
|
||||
/* Terms for Microsoft Azure RTOS. Full text of the license can be */
|
||||
/* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */
|
||||
/* and in the root directory of this software. */
|
||||
/* */
|
||||
/**************************************************************************/
|
||||
|
||||
|
||||
/**************************************************************************/
|
||||
/**************************************************************************/
|
||||
/** */
|
||||
/** LevelX Component */
|
||||
/** */
|
||||
/** NAND Flash */
|
||||
/** */
|
||||
/**************************************************************************/
|
||||
/**************************************************************************/
|
||||
|
||||
#define LX_SOURCE_CODE
|
||||
|
||||
|
||||
/* Disable ThreadX error checking. */
|
||||
|
||||
#ifndef TX_DISABLE_ERROR_CHECKING
|
||||
#define TX_DISABLE_ERROR_CHECKING
|
||||
#endif
|
||||
|
||||
|
||||
/* Include necessary system files. */
|
||||
|
||||
#include "lx_api.h"
|
||||
|
||||
|
||||
/**************************************************************************/
|
||||
/* */
|
||||
/* FUNCTION RELEASE */
|
||||
/* */
|
||||
/* _lx_nand_flash_driver_read PORTABLE C */
|
||||
/* 6.0 */
|
||||
/* AUTHOR */
|
||||
/* */
|
||||
/* William E. Lamie, Microsoft Corporation */
|
||||
/* */
|
||||
/* DESCRIPTION */
|
||||
/* */
|
||||
/* This function calls the driver to read data from a page. */
|
||||
/* */
|
||||
/* INPUT */
|
||||
/* */
|
||||
/* nand_flash NAND flash instance */
|
||||
/* block Block number */
|
||||
/* page Page number */
|
||||
/* destination Pointer to destination buffer */
|
||||
/* words Number of words to read */
|
||||
/* */
|
||||
/* OUTPUT */
|
||||
/* */
|
||||
/* Completion Status */
|
||||
/* */
|
||||
/* CALLS */
|
||||
/* */
|
||||
/* (lx_nand_flash_driver_read) Driver page read */
|
||||
/* */
|
||||
/* CALLED BY */
|
||||
/* */
|
||||
/* Internal LevelX */
|
||||
/* */
|
||||
/* RELEASE HISTORY */
|
||||
/* */
|
||||
/* DATE NAME DESCRIPTION */
|
||||
/* */
|
||||
/* 05-19-2020 William E. Lamie Initial Version 6.0 */
|
||||
/* */
|
||||
/**************************************************************************/
|
||||
UINT _lx_nand_flash_driver_read(LX_NAND_FLASH *nand_flash, ULONG block, ULONG page, ULONG *destination, ULONG words)
|
||||
{
|
||||
|
||||
ULONG cache_index;
|
||||
ULONG *source_ptr;
|
||||
ULONG *destination_ptr;
|
||||
ULONG i;
|
||||
UINT status;
|
||||
|
||||
|
||||
/* Determine if this is page 0. */
|
||||
if (page == 0)
|
||||
{
|
||||
|
||||
/* Determine if the page 0 cache is enabled. */
|
||||
if (nand_flash -> lx_nand_flash_page_0_cache != LX_NULL)
|
||||
{
|
||||
|
||||
/* Yes, the page 0 cache is enabled. */
|
||||
|
||||
/* Calculate the cache index. */
|
||||
cache_index = (block * (nand_flash -> lx_nand_flash_pages_per_block + 1));
|
||||
|
||||
/* Determine if this cache entry is valid. */
|
||||
if (nand_flash -> lx_nand_flash_page_0_cache[cache_index] != 0)
|
||||
{
|
||||
|
||||
/* Setup the destination pointer. */
|
||||
destination_ptr = (ULONG *) destination;
|
||||
|
||||
/* Setup the source pointer. */
|
||||
source_ptr = &nand_flash -> lx_nand_flash_page_0_cache[cache_index];
|
||||
|
||||
/* Simply copy the page 0 information to the destination. */
|
||||
i = 0;
|
||||
while (i < (nand_flash -> lx_nand_flash_pages_per_block + 1))
|
||||
{
|
||||
|
||||
/* Copy one word. */
|
||||
*destination_ptr++ = *source_ptr++;
|
||||
|
||||
/* Move to next word. */
|
||||
i++;
|
||||
}
|
||||
|
||||
/* Increment the number of page 0 cache hits. */
|
||||
nand_flash -> lx_nand_flash_diagnostic_page_0_cache_hits++;
|
||||
|
||||
/* Return successful status. */
|
||||
status = LX_SUCCESS;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
/* Increment the page read count. */
|
||||
nand_flash -> lx_nand_flash_diagnostic_page_reads++;
|
||||
|
||||
/* Increment the number of page 0 cache misses. */
|
||||
nand_flash -> lx_nand_flash_diagnostic_page_0_cache_misses++;
|
||||
|
||||
/* Call driver read function. */
|
||||
status = (nand_flash -> lx_nand_flash_driver_read)(block, page, destination, words);
|
||||
|
||||
/* Setup destination pointer. */
|
||||
destination_ptr = &nand_flash -> lx_nand_flash_page_0_cache[cache_index];
|
||||
|
||||
/* Setup source pointer. */
|
||||
source_ptr = (ULONG *) destination;
|
||||
|
||||
/* Simply copy the page 0 information to the destination. */
|
||||
for (i = 0; i < (nand_flash -> lx_nand_flash_pages_per_block + 1); i++)
|
||||
{
|
||||
|
||||
/* Copy one word. */
|
||||
*destination_ptr++ = *source_ptr++;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
/* Increment the page read count. */
|
||||
nand_flash -> lx_nand_flash_diagnostic_page_reads++;
|
||||
|
||||
/* Call driver read function. */
|
||||
status = (nand_flash -> lx_nand_flash_driver_read)(block, page, destination, words);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
/* Increment the page read count. */
|
||||
nand_flash -> lx_nand_flash_diagnostic_page_reads++;
|
||||
|
||||
/* Call driver read function. */
|
||||
status = (nand_flash -> lx_nand_flash_driver_read)(block, page, destination, words);
|
||||
}
|
||||
|
||||
/* Return status. */
|
||||
return(status);
|
||||
}
|
||||
|
||||
@@ -1,127 +0,0 @@
|
||||
/**************************************************************************/
|
||||
/* */
|
||||
/* Copyright (c) Microsoft Corporation. All rights reserved. */
|
||||
/* */
|
||||
/* This software is licensed under the Microsoft Software License */
|
||||
/* Terms for Microsoft Azure RTOS. Full text of the license can be */
|
||||
/* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */
|
||||
/* and in the root directory of this software. */
|
||||
/* */
|
||||
/**************************************************************************/
|
||||
|
||||
|
||||
/**************************************************************************/
|
||||
/**************************************************************************/
|
||||
/** */
|
||||
/** LevelX Component */
|
||||
/** */
|
||||
/** NAND Flash */
|
||||
/** */
|
||||
/**************************************************************************/
|
||||
/**************************************************************************/
|
||||
|
||||
#define LX_SOURCE_CODE
|
||||
|
||||
|
||||
/* Disable ThreadX error checking. */
|
||||
|
||||
#ifndef TX_DISABLE_ERROR_CHECKING
|
||||
#define TX_DISABLE_ERROR_CHECKING
|
||||
#endif
|
||||
|
||||
|
||||
/* Include necessary system files. */
|
||||
|
||||
#include "lx_api.h"
|
||||
|
||||
|
||||
/**************************************************************************/
|
||||
/* */
|
||||
/* FUNCTION RELEASE */
|
||||
/* */
|
||||
/* _lx_nand_flash_driver_write PORTABLE C */
|
||||
/* 6.0 */
|
||||
/* AUTHOR */
|
||||
/* */
|
||||
/* William E. Lamie, Microsoft Corporation */
|
||||
/* */
|
||||
/* DESCRIPTION */
|
||||
/* */
|
||||
/* This function calls the driver to write data to a NAND page. */
|
||||
/* */
|
||||
/* INPUT */
|
||||
/* */
|
||||
/* nand_flash NAND flash instance */
|
||||
/* block Block number */
|
||||
/* page Page number */
|
||||
/* source Pointer to source buffer */
|
||||
/* words Number of words to write */
|
||||
/* */
|
||||
/* OUTPUT */
|
||||
/* */
|
||||
/* Completion Status */
|
||||
/* */
|
||||
/* CALLS */
|
||||
/* */
|
||||
/* (lx_nand_flash_driver_write) Driver page write */
|
||||
/* */
|
||||
/* CALLED BY */
|
||||
/* */
|
||||
/* Internal LevelX */
|
||||
/* */
|
||||
/* RELEASE HISTORY */
|
||||
/* */
|
||||
/* DATE NAME DESCRIPTION */
|
||||
/* */
|
||||
/* 05-19-2020 William E. Lamie Initial Version 6.0 */
|
||||
/* */
|
||||
/**************************************************************************/
|
||||
UINT _lx_nand_flash_driver_write(LX_NAND_FLASH *nand_flash, ULONG block, ULONG page, ULONG *source, ULONG words)
|
||||
{
|
||||
|
||||
ULONG cache_index;
|
||||
ULONG *source_ptr;
|
||||
ULONG *destination_ptr;
|
||||
ULONG i;
|
||||
UINT status;
|
||||
|
||||
|
||||
/* Determine if this is page 0. */
|
||||
if (page == 0)
|
||||
{
|
||||
|
||||
/* Determine if the page 0 cache is enabled. */
|
||||
if (nand_flash -> lx_nand_flash_page_0_cache != LX_NULL)
|
||||
{
|
||||
|
||||
/* Yes, the page 0 cache is enabled. */
|
||||
|
||||
/* Calculate the cache index. */
|
||||
cache_index = (block * (nand_flash -> lx_nand_flash_pages_per_block + 1));
|
||||
|
||||
/* Setup destination pointer. */
|
||||
destination_ptr = &nand_flash -> lx_nand_flash_page_0_cache[cache_index];
|
||||
|
||||
/* Setup source pointer. */
|
||||
source_ptr = (ULONG *) source;
|
||||
|
||||
/* Simply copy the page 0 information to the destination. */
|
||||
for (i = 0; i < (nand_flash -> lx_nand_flash_pages_per_block + 1); i++)
|
||||
{
|
||||
|
||||
/* Copy one word. */
|
||||
*destination_ptr++ = *source_ptr++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Increment the page write count. */
|
||||
nand_flash -> lx_nand_flash_diagnostic_page_writes++;
|
||||
|
||||
/* Call driver write function. */
|
||||
status = (nand_flash -> lx_nand_flash_driver_write)(block, page, source, words);
|
||||
|
||||
/* Return status. */
|
||||
return(status);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,92 @@
|
||||
/***************************************************************************
|
||||
* Copyright (c) 2024 Microsoft Corporation
|
||||
* Copyright (c) 2026-present Eclipse ThreadX contributors
|
||||
*
|
||||
* This program and the accompanying materials are made available under the
|
||||
* terms of the MIT License which is available at
|
||||
* https://opensource.org/licenses/MIT.
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
**************************************************************************/
|
||||
|
||||
|
||||
/**************************************************************************/
|
||||
/**************************************************************************/
|
||||
/** */
|
||||
/** LevelX Component */
|
||||
/** */
|
||||
/** NAND Flash */
|
||||
/** */
|
||||
/**************************************************************************/
|
||||
/**************************************************************************/
|
||||
|
||||
#define LX_SOURCE_CODE
|
||||
|
||||
|
||||
/* Disable ThreadX error checking. */
|
||||
|
||||
#ifndef LX_DISABLE_ERROR_CHECKING
|
||||
#define LX_DISABLE_ERROR_CHECKING
|
||||
#endif
|
||||
|
||||
|
||||
/* Include necessary system files. */
|
||||
|
||||
#include "lx_api.h"
|
||||
|
||||
|
||||
/**************************************************************************/
|
||||
/* */
|
||||
/* FUNCTION RELEASE */
|
||||
/* */
|
||||
/* _lx_nand_flash_erase_count_set PORTABLE C */
|
||||
/* 6.2.1 */
|
||||
/* AUTHOR */
|
||||
/* */
|
||||
/* Xiuwen Cai, Microsoft Corporation */
|
||||
/* */
|
||||
/* 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 */
|
||||
/* */
|
||||
/**************************************************************************/
|
||||
UINT _lx_nand_flash_erase_count_set(LX_NAND_FLASH *nand_flash, ULONG block, UCHAR erase_count)
|
||||
{
|
||||
|
||||
UCHAR page_number;
|
||||
UINT status;
|
||||
|
||||
|
||||
/* Save the erase count to erase count table. */
|
||||
nand_flash -> lx_nand_flash_erase_count_table[block] = erase_count;
|
||||
|
||||
/* Get the page number to write. */
|
||||
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. */
|
||||
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,
|
||||
LX_NAND_PAGE_TYPE_ERASE_COUNT_TABLE | page_number);
|
||||
|
||||
/* Return sector not found status. */
|
||||
return(status);
|
||||
}
|
||||
|
||||
@@ -1,19 +1,19 @@
|
||||
/**************************************************************************/
|
||||
/* */
|
||||
/* Copyright (c) Microsoft Corporation. All rights reserved. */
|
||||
/* */
|
||||
/* This software is licensed under the Microsoft Software License */
|
||||
/* Terms for Microsoft Azure RTOS. Full text of the license can be */
|
||||
/* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */
|
||||
/* and in the root directory of this software. */
|
||||
/* */
|
||||
/**************************************************************************/
|
||||
/***************************************************************************
|
||||
* Copyright (c) 2024 Microsoft Corporation
|
||||
* Copyright (c) 2026-present Eclipse ThreadX contributors
|
||||
*
|
||||
* This program and the accompanying materials are made available under the
|
||||
* terms of the MIT License which is available at
|
||||
* https://opensource.org/licenses/MIT.
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
**************************************************************************/
|
||||
|
||||
|
||||
/**************************************************************************/
|
||||
/**************************************************************************/
|
||||
/** */
|
||||
/** LevelX Component */
|
||||
/** */
|
||||
/** LevelX Component */
|
||||
/** */
|
||||
/** NAND Flash */
|
||||
/** */
|
||||
@@ -25,8 +25,8 @@
|
||||
|
||||
/* Disable ThreadX error checking. */
|
||||
|
||||
#ifndef TX_DISABLE_ERROR_CHECKING
|
||||
#define TX_DISABLE_ERROR_CHECKING
|
||||
#ifndef LX_DISABLE_ERROR_CHECKING
|
||||
#define LX_DISABLE_ERROR_CHECKING
|
||||
#endif
|
||||
|
||||
|
||||
@@ -35,171 +35,50 @@
|
||||
#include "lx_api.h"
|
||||
|
||||
|
||||
/**************************************************************************/
|
||||
/* */
|
||||
/* FUNCTION RELEASE */
|
||||
/* */
|
||||
/* _lx_nand_flash_extended_cache_enable PORTABLE C */
|
||||
/* 6.0 */
|
||||
/**************************************************************************/
|
||||
/* */
|
||||
/* FUNCTION RELEASE */
|
||||
/* */
|
||||
/* _lx_nand_flash_extended_cache_enable PORTABLE C */
|
||||
/* 6.2.1 */
|
||||
/* AUTHOR */
|
||||
/* */
|
||||
/* William E. Lamie, Microsoft Corporation */
|
||||
/* */
|
||||
/* 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 */
|
||||
/* DESCRIPTION */
|
||||
/* */
|
||||
/* 05-19-2020 William E. Lamie Initial Version 6.0 */
|
||||
/* 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 */
|
||||
/* */
|
||||
/**************************************************************************/
|
||||
UINT _lx_nand_flash_extended_cache_enable(LX_NAND_FLASH *nand_flash, VOID *memory, ULONG size)
|
||||
{
|
||||
|
||||
UCHAR *working_ptr;
|
||||
ULONG adjust_size;
|
||||
ULONG i;
|
||||
LX_PARAMETER_NOT_USED(nand_flash);
|
||||
LX_PARAMETER_NOT_USED(memory);
|
||||
LX_PARAMETER_NOT_USED(size);
|
||||
|
||||
|
||||
/* Setup the working pointer. */
|
||||
working_ptr = (UCHAR *) memory;
|
||||
|
||||
/* Check for a NULL pointer. If NULL, disable all the caches. */
|
||||
if (working_ptr == TX_NULL)
|
||||
{
|
||||
|
||||
/* Disable all extended caches. */
|
||||
nand_flash -> lx_nand_flash_block_status_cache = TX_NULL;
|
||||
nand_flash -> lx_nand_flash_page_extra_bytes_cache = TX_NULL;
|
||||
nand_flash -> lx_nand_flash_page_0_cache = TX_NULL;
|
||||
|
||||
/* Return success! */
|
||||
return(LX_SUCCESS);
|
||||
}
|
||||
|
||||
/* Determine if there is not enough memory for the block status cache. */
|
||||
if (size < nand_flash -> lx_nand_flash_total_blocks)
|
||||
{
|
||||
|
||||
/* Return an error since there is not enough memory for even the smallest
|
||||
cache. */
|
||||
return(LX_ERROR);
|
||||
}
|
||||
|
||||
/* There is enough memory, setup the block status cache. */
|
||||
nand_flash -> lx_nand_flash_block_status_cache = working_ptr;
|
||||
|
||||
/* Clear the block status cache. */
|
||||
for (i = 0; i < nand_flash -> lx_nand_flash_total_blocks; i++)
|
||||
{
|
||||
|
||||
/* Clear the block status cache. */
|
||||
nand_flash -> lx_nand_flash_block_status_cache[i] = ((UCHAR) 0);
|
||||
}
|
||||
|
||||
/* Calculate the size to adjust to achieve ULONG alignment. */
|
||||
adjust_size = nand_flash -> lx_nand_flash_total_blocks + ((ULONG) (sizeof(ULONG) - 1));
|
||||
adjust_size = (adjust_size/sizeof(ULONG)) * sizeof(ULONG);
|
||||
|
||||
/* Adjust the size. */
|
||||
if (size >= adjust_size)
|
||||
{
|
||||
|
||||
/* Subtract the aligned size. */
|
||||
size = size - adjust_size;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
/* Just set size to 0. */
|
||||
size = 0;
|
||||
}
|
||||
|
||||
/* Determine if there is enough memory for the page extra bytes cache for each page. */
|
||||
if (size >= (nand_flash -> lx_nand_flash_total_pages * sizeof(LX_NAND_PAGE_EXTRA_INFO)))
|
||||
{
|
||||
|
||||
/* Yes, there is enough memory for the extra bytes cache. */
|
||||
|
||||
/* First adjust the working pointer to the start of this memory. */
|
||||
working_ptr = working_ptr + adjust_size;
|
||||
|
||||
/* Setup the pointer to page extra bytes cache. */
|
||||
nand_flash -> lx_nand_flash_page_extra_bytes_cache = (LX_NAND_PAGE_EXTRA_INFO *) working_ptr;
|
||||
|
||||
/* Clear the page extra bytes cache. */
|
||||
for (i = 0; i < nand_flash -> lx_nand_flash_total_pages; i++)
|
||||
{
|
||||
|
||||
/* Clear the block status cache. */
|
||||
nand_flash -> lx_nand_flash_page_extra_bytes_cache[i].lx_nand_page_extra_info_logical_sector = ((ULONG) 0);
|
||||
}
|
||||
|
||||
/* Calculate the size to adjust to achieve ULONG alignment. */
|
||||
adjust_size = (nand_flash -> lx_nand_flash_total_pages * sizeof(LX_NAND_PAGE_EXTRA_INFO) + ((ULONG) (sizeof(ULONG) - 1)));
|
||||
adjust_size = (adjust_size/sizeof(ULONG)) * sizeof(ULONG);
|
||||
|
||||
/* Adjust the size. */
|
||||
if (size >= adjust_size)
|
||||
{
|
||||
|
||||
/* Subtract the aligned size. */
|
||||
size = size - adjust_size;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
/* Just set size to 0. */
|
||||
size = 0;
|
||||
}
|
||||
}
|
||||
|
||||
/* Determine if there is enough memory for the page 0 cache for each block. */
|
||||
if (size >= ((nand_flash -> lx_nand_flash_total_blocks * (nand_flash -> lx_nand_flash_pages_per_block + 1)) * sizeof(ULONG)))
|
||||
{
|
||||
|
||||
/* Yes, there is enough memory for the page 0 cache. */
|
||||
|
||||
/* First adjust the working pointer to the start of this memory. */
|
||||
working_ptr = working_ptr + adjust_size;
|
||||
|
||||
/* Setup the pointer to page 0 cache. */
|
||||
nand_flash -> lx_nand_flash_page_0_cache = (ULONG *) working_ptr;
|
||||
|
||||
/* Clear the page 0 cache. */
|
||||
for (i = 0; i < (nand_flash -> lx_nand_flash_total_blocks * (nand_flash -> lx_nand_flash_pages_per_block + 1)); i++)
|
||||
{
|
||||
|
||||
/* Clear the block status cache. */
|
||||
nand_flash -> lx_nand_flash_page_0_cache[i] = ((ULONG) 0);
|
||||
}
|
||||
}
|
||||
|
||||
/* Return success. */
|
||||
return(LX_SUCCESS);
|
||||
/* Return not supported. */
|
||||
return(LX_NOT_SUPPORTED);
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,86 @@
|
||||
/***************************************************************************
|
||||
* 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 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 */
|
||||
/* 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 */
|
||||
/* _lx_nand_flash_format_extended */
|
||||
/* */
|
||||
/* CALLED BY */
|
||||
/* */
|
||||
/* Application Code */
|
||||
/* */
|
||||
/**************************************************************************/
|
||||
UINT _lx_nand_flash_format(LX_NAND_FLASH* nand_flash, CHAR* name,
|
||||
UINT(*nand_driver_initialize)(LX_NAND_FLASH*),
|
||||
ULONG* memory_ptr, UINT memory_size)
|
||||
{
|
||||
|
||||
UINT status;
|
||||
|
||||
status = _lx_nand_flash_format_extended(nand_flash, name, nand_driver_initialize, NULL, memory_ptr, memory_size);
|
||||
|
||||
return status;
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,115 @@
|
||||
/***************************************************************************
|
||||
* Copyright (c) 2024 Microsoft Corporation
|
||||
* Copyright (c) 2026-present Eclipse ThreadX contributors
|
||||
*
|
||||
* This program and the accompanying materials are made available under the
|
||||
* terms of the MIT License which is available at
|
||||
* https://opensource.org/licenses/MIT.
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
**************************************************************************/
|
||||
|
||||
|
||||
/**************************************************************************/
|
||||
/**************************************************************************/
|
||||
/** */
|
||||
/** LevelX Component */
|
||||
/** */
|
||||
/** NAND Flash */
|
||||
/** */
|
||||
/**************************************************************************/
|
||||
/**************************************************************************/
|
||||
|
||||
#define LX_SOURCE_CODE
|
||||
|
||||
|
||||
/* Disable ThreadX error checking. */
|
||||
|
||||
#ifndef LX_DISABLE_ERROR_CHECKING
|
||||
#define LX_DISABLE_ERROR_CHECKING
|
||||
#endif
|
||||
|
||||
|
||||
/* Include necessary system files. */
|
||||
|
||||
#include "lx_api.h"
|
||||
|
||||
|
||||
/**************************************************************************/
|
||||
/* */
|
||||
/* FUNCTION RELEASE */
|
||||
/* */
|
||||
/* _lx_nand_flash_free_block_list_add PORTABLE C */
|
||||
/* 6.2.1 */
|
||||
/* AUTHOR */
|
||||
/* */
|
||||
/* Xiuwen Cai, Microsoft Corporation */
|
||||
/* */
|
||||
/* 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 */
|
||||
/* */
|
||||
/**************************************************************************/
|
||||
UINT _lx_nand_flash_free_block_list_add(LX_NAND_FLASH* nand_flash, ULONG block)
|
||||
{
|
||||
|
||||
ULONG insert_position;
|
||||
INT search_position;
|
||||
UCHAR new_block_erase_count;
|
||||
|
||||
|
||||
/* Get insert position for the free block list. */
|
||||
insert_position = nand_flash -> lx_nand_flash_free_block_list_tail;
|
||||
|
||||
/* Check if the list if full. */
|
||||
if (insert_position > nand_flash -> lx_nand_flash_mapped_block_list_head)
|
||||
{
|
||||
|
||||
/* Return an error. */
|
||||
return(LX_ERROR);
|
||||
}
|
||||
|
||||
/* Get the erase count. */
|
||||
new_block_erase_count = nand_flash -> lx_nand_flash_erase_count_table[block];
|
||||
|
||||
/* Add one block to the free list. */
|
||||
nand_flash -> lx_nand_flash_free_block_list_tail++;
|
||||
|
||||
/* Initialize the search pointer. */
|
||||
search_position = (INT)insert_position - 1;
|
||||
|
||||
/* Loop to search the insert position by block erase count. */
|
||||
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))
|
||||
{
|
||||
|
||||
/* Move the item in the list. */
|
||||
nand_flash -> lx_nand_flash_block_list[insert_position] = nand_flash -> lx_nand_flash_block_list[search_position];
|
||||
search_position--;
|
||||
insert_position--;
|
||||
}
|
||||
|
||||
/* Insert the new block to the list. */
|
||||
nand_flash -> lx_nand_flash_block_list[insert_position] = (USHORT)block;
|
||||
|
||||
/* Return successful completion. */
|
||||
return(LX_SUCCESS);
|
||||
}
|
||||
|
||||
@@ -1,19 +1,19 @@
|
||||
/**************************************************************************/
|
||||
/* */
|
||||
/* Copyright (c) Microsoft Corporation. All rights reserved. */
|
||||
/* */
|
||||
/* This software is licensed under the Microsoft Software License */
|
||||
/* Terms for Microsoft Azure RTOS. Full text of the license can be */
|
||||
/* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */
|
||||
/* and in the root directory of this software. */
|
||||
/* */
|
||||
/**************************************************************************/
|
||||
/***************************************************************************
|
||||
* Copyright (c) 2024 Microsoft Corporation
|
||||
* Copyright (c) 2026-present Eclipse ThreadX contributors
|
||||
*
|
||||
* This program and the accompanying materials are made available under the
|
||||
* terms of the MIT License which is available at
|
||||
* https://opensource.org/licenses/MIT.
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
**************************************************************************/
|
||||
|
||||
|
||||
/**************************************************************************/
|
||||
/**************************************************************************/
|
||||
/** */
|
||||
/** LevelX Component */
|
||||
/** */
|
||||
/** LevelX Component */
|
||||
/** */
|
||||
/** NAND Flash */
|
||||
/** */
|
||||
@@ -34,41 +34,35 @@ LX_NAND_FLASH *_lx_nand_flash_opened_ptr;
|
||||
ULONG _lx_nand_flash_opened_count;
|
||||
|
||||
|
||||
/**************************************************************************/
|
||||
/* */
|
||||
/* FUNCTION RELEASE */
|
||||
/* */
|
||||
/* _lx_nand_flash_initialize PORTABLE C */
|
||||
/* 6.0 */
|
||||
/**************************************************************************/
|
||||
/* */
|
||||
/* FUNCTION RELEASE */
|
||||
/* */
|
||||
/* _lx_nand_flash_initialize PORTABLE C */
|
||||
/* 6.1 */
|
||||
/* AUTHOR */
|
||||
/* */
|
||||
/* William E. Lamie, Microsoft Corporation */
|
||||
/* */
|
||||
/* 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 */
|
||||
/* DESCRIPTION */
|
||||
/* */
|
||||
/* 05-19-2020 William E. Lamie Initial Version 6.0 */
|
||||
/* This function initializes the NAND flash data structures. */
|
||||
/* */
|
||||
/* INPUT */
|
||||
/* */
|
||||
/* None */
|
||||
/* */
|
||||
/* OUTPUT */
|
||||
/* */
|
||||
/* return status */
|
||||
/* */
|
||||
/* CALLS */
|
||||
/* */
|
||||
/* None */
|
||||
/* */
|
||||
/* CALLED BY */
|
||||
/* */
|
||||
/* Application Code */
|
||||
/* */
|
||||
/**************************************************************************/
|
||||
UINT _lx_nand_flash_initialize(void)
|
||||
@@ -77,7 +71,7 @@ UINT _lx_nand_flash_initialize(void)
|
||||
/* Clear open list head pointer and opened count. */
|
||||
_lx_nand_flash_opened_ptr = LX_NULL;
|
||||
_lx_nand_flash_opened_count = 0;
|
||||
|
||||
|
||||
/* Return 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,837 +0,0 @@
|
||||
/**************************************************************************/
|
||||
/* */
|
||||
/* Copyright (c) Microsoft Corporation. All rights reserved. */
|
||||
/* */
|
||||
/* This software is licensed under the Microsoft Software License */
|
||||
/* Terms for Microsoft Azure RTOS. Full text of the license can be */
|
||||
/* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */
|
||||
/* and in the root directory of this software. */
|
||||
/* */
|
||||
/**************************************************************************/
|
||||
|
||||
|
||||
/**************************************************************************/
|
||||
/**************************************************************************/
|
||||
/** */
|
||||
/** LevelX Component */
|
||||
/** */
|
||||
/** NAND Flash */
|
||||
/** */
|
||||
/**************************************************************************/
|
||||
/**************************************************************************/
|
||||
|
||||
#define LX_SOURCE_CODE
|
||||
|
||||
|
||||
/* Disable ThreadX error checking. */
|
||||
|
||||
#ifndef TX_DISABLE_ERROR_CHECKING
|
||||
#define TX_DISABLE_ERROR_CHECKING
|
||||
#endif
|
||||
|
||||
|
||||
/* Include necessary system files. */
|
||||
|
||||
#include "lx_api.h"
|
||||
|
||||
|
||||
/**************************************************************************/
|
||||
/* */
|
||||
/* FUNCTION RELEASE */
|
||||
/* */
|
||||
/* _lx_nand_flash_logical_sector_find PORTABLE C */
|
||||
/* 6.0 */
|
||||
/* AUTHOR */
|
||||
/* */
|
||||
/* William E. Lamie, Microsoft Corporation */
|
||||
/* */
|
||||
/* DESCRIPTION */
|
||||
/* */
|
||||
/* This function attempts to find the specified logical sector in */
|
||||
/* the NAND flash. */
|
||||
/* */
|
||||
/* 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 */
|
||||
/* */
|
||||
/* _lx_nand_flash_driver_block_status_get */
|
||||
/* Driver block status */
|
||||
/* _lx_nand_flash_driver_extra_bytes_get Driver get extra bytes */
|
||||
/* _lx_nand_flash_driver_extra_bytes_set NAND flash set extra bytes */
|
||||
/* _lx_nand_flash_driver_read Driver page read */
|
||||
/* _lx_nand_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 */
|
||||
/* */
|
||||
/**************************************************************************/
|
||||
UINT _lx_nand_flash_logical_sector_find(LX_NAND_FLASH *nand_flash, ULONG logical_sector, ULONG superceded_check, ULONG *block, ULONG *page)
|
||||
{
|
||||
|
||||
LX_NAND_PAGE_EXTRA_INFO extra_info;
|
||||
UCHAR block_status;
|
||||
ULONG *block_word_ptr;
|
||||
ULONG valid_pages;
|
||||
ULONG mapped_pages;
|
||||
ULONG total_blocks;
|
||||
ULONG total_pages;
|
||||
ULONG i, j;
|
||||
ULONG search_start;
|
||||
ULONG max_mapped_sector;
|
||||
#ifndef LX_NAND_FLASH_DIRECT_MAPPING_CACHE
|
||||
LX_NAND_SECTOR_MAPPING_CACHE_ENTRY *sector_mapping_cache_entry_ptr = LX_NULL;
|
||||
LX_NAND_SECTOR_MAPPING_CACHE_ENTRY temp_sector_mapping_cache_entry;
|
||||
#endif
|
||||
UINT status;
|
||||
|
||||
|
||||
/* Initialize the return parameters. */
|
||||
*block = (ULONG) 0;
|
||||
*page = (ULONG) 0;
|
||||
|
||||
/* Determine if there are any mapped pages. */
|
||||
if (nand_flash -> lx_nand_flash_mapped_pages == 0)
|
||||
{
|
||||
|
||||
/* No mapped pages so nothing can be found!. */
|
||||
return(LX_SECTOR_NOT_FOUND);
|
||||
}
|
||||
|
||||
/* Determine if this logical sector is greater than what has previously been mapped. */
|
||||
if (logical_sector > nand_flash -> lx_nand_flash_max_mapped_sector)
|
||||
{
|
||||
|
||||
/* Since this logical sector request is greater than what has been mapped previously,
|
||||
there is no point in searching any further. */
|
||||
|
||||
/* Return sector not found status. */
|
||||
return(LX_SECTOR_NOT_FOUND);
|
||||
}
|
||||
|
||||
/* Determine if the sector mapping cache is enabled. */
|
||||
if (nand_flash -> lx_nand_flash_sector_mapping_cache_enabled)
|
||||
{
|
||||
|
||||
#ifndef LX_NAND_FLASH_DIRECT_MAPPING_CACHE
|
||||
|
||||
/* Calculate the starting index of the sector cache for this sector entry. */
|
||||
i = (logical_sector & LX_NAND_SECTOR_MAPPING_CACHE_HASH_MASK) * LX_NAND_SECTOR_MAPPING_CACHE_DEPTH;
|
||||
|
||||
/* Build a pointer to the cache entry. */
|
||||
sector_mapping_cache_entry_ptr = &nand_flash -> lx_nand_flash_sector_mapping_cache[i];
|
||||
|
||||
/* Determine if the sector is in the sector mapping cache - assuming the depth of the sector
|
||||
mapping cache is LX_NAND_SECTOR_MAPPING_CACHE_DEPTH entries. */
|
||||
if ((sector_mapping_cache_entry_ptr -> lx_nand_sector_mapping_cache_logical_sector) == (logical_sector | LX_NAND_SECTOR_MAPPING_CACHE_ENTRY_VALID))
|
||||
{
|
||||
|
||||
/* Increment the sector mapping cache hit counter. */
|
||||
nand_flash -> lx_nand_flash_diagnostic_sector_mapping_cache_hits++;
|
||||
|
||||
/* Yes, return the cached values associated with the sector. */
|
||||
*block = (ULONG) sector_mapping_cache_entry_ptr -> lx_nand_sector_mapping_cache_block;
|
||||
*page = (ULONG) sector_mapping_cache_entry_ptr -> lx_nand_sector_mapping_cache_page;
|
||||
|
||||
/* Don't move anything since we found the entry at the top. */
|
||||
|
||||
/* Return a successful status. */
|
||||
return(LX_SUCCESS);
|
||||
}
|
||||
else if (((sector_mapping_cache_entry_ptr + 1) -> lx_nand_sector_mapping_cache_logical_sector) == (logical_sector | LX_NAND_SECTOR_MAPPING_CACHE_ENTRY_VALID))
|
||||
{
|
||||
|
||||
/* Increment the sector mapping cache hit counter. */
|
||||
nand_flash -> lx_nand_flash_diagnostic_sector_mapping_cache_hits++;
|
||||
|
||||
/* Yes, return the cached values associated with the sector. */
|
||||
*block = (ULONG) (sector_mapping_cache_entry_ptr + 1) -> lx_nand_sector_mapping_cache_block;
|
||||
*page = (ULONG) (sector_mapping_cache_entry_ptr + 1) -> lx_nand_sector_mapping_cache_page;
|
||||
|
||||
/* Just swap the first and second entry. */
|
||||
temp_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 + 1) = temp_sector_mapping_cache_entry;
|
||||
|
||||
/* Return a successful status. */
|
||||
return(LX_SUCCESS);
|
||||
}
|
||||
else if (((sector_mapping_cache_entry_ptr + 2) -> lx_nand_sector_mapping_cache_logical_sector) == (logical_sector | LX_NAND_SECTOR_MAPPING_CACHE_ENTRY_VALID))
|
||||
{
|
||||
|
||||
/* Increment the sector mapping cache hit counter. */
|
||||
nand_flash -> lx_nand_flash_diagnostic_sector_mapping_cache_hits++;
|
||||
|
||||
/* Yes, return the cached value. */
|
||||
*block = (ULONG) (sector_mapping_cache_entry_ptr + 2) -> lx_nand_sector_mapping_cache_block;
|
||||
*page = (ULONG) (sector_mapping_cache_entry_ptr + 2) -> lx_nand_sector_mapping_cache_page;
|
||||
|
||||
/* Move the third entry to the top and the first two entries down. */
|
||||
temp_sector_mapping_cache_entry = *(sector_mapping_cache_entry_ptr);
|
||||
*(sector_mapping_cache_entry_ptr) = *(sector_mapping_cache_entry_ptr + 2);
|
||||
*(sector_mapping_cache_entry_ptr + 2) = *(sector_mapping_cache_entry_ptr + 1);
|
||||
*(sector_mapping_cache_entry_ptr + 1) = temp_sector_mapping_cache_entry;
|
||||
|
||||
/* Return a successful status. */
|
||||
return(LX_SUCCESS);
|
||||
}
|
||||
else if (((sector_mapping_cache_entry_ptr + 3) -> lx_nand_sector_mapping_cache_logical_sector) == (logical_sector | LX_NAND_SECTOR_MAPPING_CACHE_ENTRY_VALID))
|
||||
{
|
||||
|
||||
/* Increment the sector mapping cache hit counter. */
|
||||
nand_flash -> lx_nand_flash_diagnostic_sector_mapping_cache_hits++;
|
||||
|
||||
/* Yes, return the cached value. */
|
||||
*block = (ULONG) (sector_mapping_cache_entry_ptr + 3) -> lx_nand_sector_mapping_cache_block;
|
||||
*page = (ULONG) (sector_mapping_cache_entry_ptr + 3) -> lx_nand_sector_mapping_cache_page;
|
||||
|
||||
/* Move the last entry to the top and the first three entries down. */
|
||||
temp_sector_mapping_cache_entry = *(sector_mapping_cache_entry_ptr);
|
||||
*(sector_mapping_cache_entry_ptr) = *(sector_mapping_cache_entry_ptr + 3);
|
||||
*(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 + 1) = temp_sector_mapping_cache_entry;
|
||||
|
||||
/* Return a successful status. */
|
||||
return(LX_SUCCESS);
|
||||
}
|
||||
|
||||
/* If we get here, we have a cache miss so increment the counter before we fall through to the search loop. */
|
||||
nand_flash -> lx_nand_flash_diagnostic_sector_mapping_cache_misses++;
|
||||
#else
|
||||
|
||||
/* Direct mapping cache is defined. */
|
||||
|
||||
/* See if we are still opening the flash. */
|
||||
if (nand_flash -> lx_nand_flash_state == LX_NAND_FLASH_OPENED)
|
||||
{
|
||||
|
||||
/* Flash instance is opened. */
|
||||
|
||||
/* Determine if this logical sector fits in the logical sector direct cache mapping. */
|
||||
if (logical_sector < LX_NAND_SECTOR_MAPPING_CACHE_SIZE)
|
||||
{
|
||||
|
||||
/* Yes, invalidate the logical sector cache. */
|
||||
if ((nand_flash -> lx_nand_flash_sector_mapping_cache[logical_sector].lx_nand_sector_mapping_cache_block == 0) &&
|
||||
(nand_flash -> lx_nand_flash_sector_mapping_cache[logical_sector].lx_nand_sector_mapping_cache_page == 0))
|
||||
{
|
||||
|
||||
/* Entry is not mapped. */
|
||||
|
||||
/* No, return sector not found status. */
|
||||
return(LX_SECTOR_NOT_FOUND);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
/* Sector is mapped, return the block and page of the mapping. */
|
||||
*block = nand_flash -> lx_nand_flash_sector_mapping_cache[logical_sector].lx_nand_sector_mapping_cache_block;
|
||||
*page = nand_flash -> lx_nand_flash_sector_mapping_cache[logical_sector].lx_nand_sector_mapping_cache_page;
|
||||
|
||||
/* Return a successful status. */
|
||||
return(LX_SUCCESS);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
/* If we get here, we have a cache miss so increment the counter before we fall through to the search loop. */
|
||||
nand_flash -> lx_nand_flash_diagnostic_sector_mapping_cache_misses++;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
/* Clear the maximum mapped sector. */
|
||||
max_mapped_sector = 0;
|
||||
|
||||
/* Setup the total number of mapped pages. */
|
||||
mapped_pages = nand_flash -> lx_nand_flash_mapped_pages;
|
||||
|
||||
/* Setup pointer to internal buffer. */
|
||||
block_word_ptr = nand_flash -> lx_nand_flash_page_buffer;
|
||||
|
||||
/* Start searching from the last found block. */
|
||||
i = nand_flash -> lx_nand_flash_found_block_search;
|
||||
|
||||
/* Setup the starting page to look at. */
|
||||
j = nand_flash -> lx_nand_flash_found_page_search;
|
||||
|
||||
/* Pickup the total number of blocks. */
|
||||
total_blocks = nand_flash -> lx_nand_flash_total_blocks;
|
||||
|
||||
/* Loop through the blocks to attempt to find the mapped logical sector. */
|
||||
while (total_blocks--)
|
||||
{
|
||||
|
||||
/* First, check to make sure this block is good. */
|
||||
status = _lx_nand_flash_driver_block_status_get(nand_flash, i, &block_status);
|
||||
|
||||
/* Check for an error from flash driver. */
|
||||
if (status)
|
||||
{
|
||||
|
||||
/* Call system error handler. */
|
||||
_lx_nand_flash_system_error(nand_flash, status, i, 0);
|
||||
|
||||
/* Return the error. */
|
||||
return(status);
|
||||
}
|
||||
|
||||
/* Is this block bad? */
|
||||
if (block_status != LX_NAND_GOOD_BLOCK)
|
||||
{
|
||||
|
||||
/* Yes, this block is bad. */
|
||||
|
||||
/* Move to the next block. */
|
||||
i++;
|
||||
|
||||
/* Check for wrap condition. */
|
||||
if (i >= nand_flash -> lx_nand_flash_total_blocks)
|
||||
{
|
||||
|
||||
/* Wrap to the first block. */
|
||||
i = 0;
|
||||
}
|
||||
|
||||
/* Start looking at the first page of the next block. */
|
||||
j = 1;
|
||||
|
||||
/* Continue to the next block. */
|
||||
continue;
|
||||
}
|
||||
|
||||
/* Read the extra bytes of page 0. This will tell us if the page has any valid mappings. */
|
||||
status = _lx_nand_flash_driver_extra_bytes_get(nand_flash, i, 0, (UCHAR *) &extra_info, sizeof(extra_info));
|
||||
|
||||
/* Check for an error from flash driver. */
|
||||
if (status)
|
||||
{
|
||||
|
||||
/* Call system error handler. */
|
||||
_lx_nand_flash_system_error(nand_flash, status, i, 0);
|
||||
|
||||
/* Return the error... no point in continuing. */
|
||||
return(status);
|
||||
}
|
||||
|
||||
/* Determine if there are any valid mappings. */
|
||||
if (((extra_info.lx_nand_page_extra_info_logical_sector & LX_NAND_BLOCK_VALID) == 0) ||
|
||||
((extra_info.lx_nand_page_extra_info_logical_sector & LX_NAND_BLOCK_EMPTY) != 0))
|
||||
{
|
||||
|
||||
/* Yes, this block is either no longer valid or is empty, i.e., no mappings. */
|
||||
|
||||
/* Move to the next block. */
|
||||
i++;
|
||||
|
||||
/* Check for wrap condition. */
|
||||
if (i >= nand_flash -> lx_nand_flash_total_blocks)
|
||||
{
|
||||
|
||||
/* Wrap to the first block. */
|
||||
i = 0;
|
||||
}
|
||||
|
||||
/* Reset to the first page of the next block. */
|
||||
j = 1;
|
||||
|
||||
/* Continue to the next block. */
|
||||
continue;
|
||||
}
|
||||
|
||||
/* Now read page 0 of the block, which has the erase count in the first 4 bytes. */
|
||||
status = _lx_nand_flash_driver_read(nand_flash, i, 0, block_word_ptr, (nand_flash -> lx_nand_flash_pages_per_block + 1));
|
||||
|
||||
/* Check for an error from flash driver. */
|
||||
if (status)
|
||||
{
|
||||
|
||||
/* Call system error handler. */
|
||||
_lx_nand_flash_system_error(nand_flash, status, i, 0);
|
||||
|
||||
/* Determine if the error is fatal. */
|
||||
if (status != LX_NAND_ERROR_CORRECTED)
|
||||
{
|
||||
|
||||
/* Return the error. */
|
||||
return(status);
|
||||
}
|
||||
}
|
||||
|
||||
/* Determine if we have a valid logical sector mapping list. */
|
||||
if ((block_word_ptr[1] != LX_NAND_PAGE_FREE) &&
|
||||
(block_word_ptr[nand_flash -> lx_nand_flash_pages_per_block] == LX_NAND_PAGE_LIST_VALID))
|
||||
{
|
||||
|
||||
/* Yes, we have a valid logical sector mapping list in page 0. */
|
||||
|
||||
/* Clear the valid entries counter. */
|
||||
valid_pages = 0;
|
||||
|
||||
/* Setup the total number of pages, less the metadata page. */
|
||||
total_pages = nand_flash -> lx_nand_flash_pages_per_block - 1;
|
||||
|
||||
/* Now search through the sector list to find a match. */
|
||||
while (total_pages--)
|
||||
{
|
||||
|
||||
/* Is this entry valid? */
|
||||
if ((block_word_ptr[j] & (LX_NAND_PAGE_VALID | LX_NAND_PAGE_MAPPING_NOT_VALID)) == LX_NAND_PAGE_VALID)
|
||||
{
|
||||
|
||||
/* Increment the valid entries counter. */
|
||||
valid_pages++;
|
||||
|
||||
/* Determine if this is a new maximum logical sector. */
|
||||
if ((block_word_ptr[j] & LX_NAND_LOGICAL_SECTOR_MASK) > max_mapped_sector)
|
||||
{
|
||||
|
||||
/* Yes, a new maximum mapped sectors - remember it! */
|
||||
max_mapped_sector = (block_word_ptr[j] & LX_NAND_LOGICAL_SECTOR_MASK);
|
||||
}
|
||||
|
||||
/* Do we have a valid sector match? */
|
||||
if ((block_word_ptr[j] & LX_NAND_LOGICAL_SECTOR_MASK) == logical_sector)
|
||||
{
|
||||
|
||||
/* Read in the actual page entry to make sure this logical sector mapping is still valid. */
|
||||
status = _lx_nand_flash_driver_extra_bytes_get(nand_flash, i, j, (UCHAR *) &extra_info, sizeof(extra_info));
|
||||
|
||||
/* Check for an error from flash driver. */
|
||||
if (status)
|
||||
{
|
||||
|
||||
/* Call system error handler. */
|
||||
_lx_nand_flash_system_error(nand_flash, status, i, j);
|
||||
|
||||
/* Return the error. */
|
||||
return(status);
|
||||
}
|
||||
|
||||
/* Verify that the actual page still has a valid sector mapping. */
|
||||
if (((extra_info.lx_nand_page_extra_info_logical_sector & (LX_NAND_PAGE_VALID | LX_NAND_PAGE_MAPPING_NOT_VALID)) == LX_NAND_PAGE_VALID) &&
|
||||
((extra_info.lx_nand_page_extra_info_logical_sector & LX_NAND_LOGICAL_SECTOR_MASK) == logical_sector))
|
||||
{
|
||||
|
||||
/* Decrement the number of mapped pages to examine. */
|
||||
mapped_pages--;
|
||||
|
||||
/* Determine if we care about the superceded bit. */
|
||||
if (superceded_check == LX_FALSE)
|
||||
{
|
||||
|
||||
/* Prepare the return information. */
|
||||
*block = i;
|
||||
*page = j;
|
||||
|
||||
/* Determine if the sector mapping cache is enabled. */
|
||||
if (nand_flash -> lx_nand_flash_sector_mapping_cache_enabled)
|
||||
{
|
||||
|
||||
#ifndef LX_NAND_FLASH_DIRECT_MAPPING_CACHE
|
||||
|
||||
/* Yes, update the cache with the logical sector mapping. */
|
||||
|
||||
/* 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 + 2) = *(sector_mapping_cache_entry_ptr + 1);
|
||||
*(sector_mapping_cache_entry_ptr + 1) = *(sector_mapping_cache_entry_ptr);
|
||||
|
||||
/* Setup the new sector information in the cache. */
|
||||
sector_mapping_cache_entry_ptr -> lx_nand_sector_mapping_cache_logical_sector = (logical_sector | LX_NAND_SECTOR_MAPPING_CACHE_ENTRY_VALID);
|
||||
sector_mapping_cache_entry_ptr -> lx_nand_sector_mapping_cache_block = (USHORT) i;
|
||||
sector_mapping_cache_entry_ptr -> lx_nand_sector_mapping_cache_page = (USHORT) j;
|
||||
#else
|
||||
|
||||
/* Determine if this logical sector fits in the logical sector cache mapping. */
|
||||
if (logical_sector < LX_NAND_SECTOR_MAPPING_CACHE_SIZE)
|
||||
{
|
||||
|
||||
/* Yes, store the logical sector to block/page mapping in the cache. */
|
||||
nand_flash -> lx_nand_flash_sector_mapping_cache[logical_sector].lx_nand_sector_mapping_cache_block = (USHORT) i;
|
||||
nand_flash -> lx_nand_flash_sector_mapping_cache[logical_sector].lx_nand_sector_mapping_cache_page = (USHORT) j;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
/* Move to the next page. */
|
||||
j++;
|
||||
|
||||
/* Determine if the page has wrapped around. */
|
||||
if (j >= nand_flash -> lx_nand_flash_pages_per_block)
|
||||
{
|
||||
|
||||
/* Yes, page wrapped. Move to page 1 of the next block. */
|
||||
j = 1;
|
||||
}
|
||||
|
||||
/* Remember the last found block and page for next search. */
|
||||
nand_flash -> lx_nand_flash_found_block_search = i;
|
||||
nand_flash -> lx_nand_flash_found_page_search = j;
|
||||
|
||||
/* Return success! */
|
||||
return(LX_SUCCESS);
|
||||
}
|
||||
|
||||
/* Check for the superceded bit being clear, which means the sector was superceded. */
|
||||
else if (extra_info.lx_nand_page_extra_info_logical_sector & LX_NAND_PAGE_SUPERCEDED)
|
||||
{
|
||||
|
||||
/* Prepare the return information. */
|
||||
*block = i;
|
||||
*page = j;
|
||||
|
||||
/* No need to update the cache here, since this condition only happens during initialization. */
|
||||
|
||||
/* Move to the next page. */
|
||||
j++;
|
||||
|
||||
/* Determine if the page has wrapped around. */
|
||||
if (j >= nand_flash -> lx_nand_flash_pages_per_block)
|
||||
{
|
||||
|
||||
/* Yes, page wrapped. Move to page 1 of the next block. */
|
||||
j = 1;
|
||||
}
|
||||
|
||||
/* Remember the last found block and page for next search. */
|
||||
nand_flash -> lx_nand_flash_found_block_search = i;
|
||||
nand_flash -> lx_nand_flash_found_page_search = j;
|
||||
|
||||
/* Return success! */
|
||||
return(LX_SUCCESS);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
/* The entry is not really valid anymore, decrement the valid entries counter. */
|
||||
valid_pages--;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Move to the next page. */
|
||||
j++;
|
||||
|
||||
/* Check for wrap condition. */
|
||||
if (j >= nand_flash -> lx_nand_flash_pages_per_block)
|
||||
{
|
||||
|
||||
/* Yes, page has wrapped, reset to page 1. */
|
||||
j = 1;
|
||||
}
|
||||
}
|
||||
|
||||
/* At this point we know that nothing matched in the mapping list. Now we need to check to see if there are any valid entries. */
|
||||
if (valid_pages)
|
||||
{
|
||||
|
||||
/* Reset the valid pages counter. */
|
||||
valid_pages = 0;
|
||||
|
||||
/* Setup the total number of pages, less the metadata page. */
|
||||
total_pages = nand_flash -> lx_nand_flash_pages_per_block - 1;
|
||||
|
||||
/* Now search through the sector list to find a match. */
|
||||
while (total_pages--)
|
||||
{
|
||||
|
||||
/* Is this entry valid? */
|
||||
if ((block_word_ptr[j] & (LX_NAND_PAGE_VALID | LX_NAND_PAGE_MAPPING_NOT_VALID)) == LX_NAND_PAGE_VALID)
|
||||
{
|
||||
|
||||
/* Read in the actual page entry to make sure this logical sector mapping is still valid. */
|
||||
status = _lx_nand_flash_driver_extra_bytes_get(nand_flash, i, j, (UCHAR *) &extra_info, sizeof(extra_info));
|
||||
|
||||
/* Check for an error from flash driver. */
|
||||
if (status)
|
||||
{
|
||||
|
||||
/* Call system error handler. */
|
||||
_lx_nand_flash_system_error(nand_flash, status, i, j);
|
||||
|
||||
/* Return the error. */
|
||||
return(status);
|
||||
}
|
||||
|
||||
/* Verify that the actual page still has a valid sector mapping. */
|
||||
if ((extra_info.lx_nand_page_extra_info_logical_sector & (LX_NAND_PAGE_VALID | LX_NAND_PAGE_MAPPING_NOT_VALID)) == LX_NAND_PAGE_VALID)
|
||||
{
|
||||
|
||||
/* Set the valid pages counter to 1 and break the loop. */
|
||||
valid_pages = 1;
|
||||
|
||||
/* If one entry is valid, we can stop looking. */
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/* Move to the next page. */
|
||||
j++;
|
||||
|
||||
/* Check for wrap condition. */
|
||||
if (j >= nand_flash -> lx_nand_flash_pages_per_block)
|
||||
{
|
||||
|
||||
/* Yes, page has wrapped, reset to page 1. */
|
||||
j = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Now, a final check for valid pages. */
|
||||
if (valid_pages == 0)
|
||||
{
|
||||
|
||||
/* There are no valid entries. We can now mark this block as not valid since there are no active
|
||||
mappings. This will prevent us from examining it again during the search process. */
|
||||
extra_info.lx_nand_page_extra_info_logical_sector = 0;
|
||||
status = _lx_nand_flash_driver_extra_bytes_set(nand_flash, i, 0, (UCHAR *) &extra_info, sizeof(extra_info));
|
||||
|
||||
/* Check for an error from flash driver. */
|
||||
if (status)
|
||||
{
|
||||
|
||||
/* Call system error handler. */
|
||||
_lx_nand_flash_system_error(nand_flash, status, i, 0);
|
||||
}
|
||||
|
||||
/* Reset the search page to 1. */
|
||||
j = 1;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
/* No, we don't have a valid logical sector mapping list. */
|
||||
|
||||
/* Setup the total number of pages, less the metadata page. */
|
||||
total_pages = nand_flash -> lx_nand_flash_pages_per_block - 1;
|
||||
|
||||
/* Remember the start of the search. */
|
||||
search_start = j;
|
||||
|
||||
/* Now search through the sector list to find a match. */
|
||||
while (total_pages--)
|
||||
{
|
||||
|
||||
/* Read in the actual page entry to look for the logical sector mapping. */
|
||||
status = _lx_nand_flash_driver_extra_bytes_get(nand_flash, i, j, (UCHAR *) &extra_info, sizeof(extra_info));
|
||||
|
||||
/* Check for an error from flash driver. */
|
||||
if (status)
|
||||
{
|
||||
|
||||
/* Call system error handler. */
|
||||
_lx_nand_flash_system_error(nand_flash, status, i, j);
|
||||
|
||||
/* Return the error. */
|
||||
return(status);
|
||||
}
|
||||
|
||||
/* Is there a logical page mapping? */
|
||||
if (extra_info.lx_nand_page_extra_info_logical_sector == LX_NAND_PAGE_FREE)
|
||||
{
|
||||
|
||||
/* Since the mapping is done sequentially in the block, we know nothing
|
||||
else exists after this point. */
|
||||
|
||||
/* Determine if the search started at the beginning of the block. */
|
||||
if (search_start == 1)
|
||||
{
|
||||
|
||||
/* Yes, we started at the beginning of the block. We are now done with this block. */
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
/* Setup the new total to the search start. */
|
||||
total_pages = (search_start - 1);
|
||||
|
||||
/* Clear search start. */
|
||||
search_start = 1;
|
||||
|
||||
/* Start search over. */
|
||||
j = 1;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
/* Is this page mapping valid? */
|
||||
if ((extra_info.lx_nand_page_extra_info_logical_sector & (LX_NAND_PAGE_VALID | LX_NAND_PAGE_MAPPING_NOT_VALID)) == LX_NAND_PAGE_VALID)
|
||||
{
|
||||
|
||||
/* Yes, this page mapping is valid. */
|
||||
|
||||
/* Decrease the number of pages to examine. */
|
||||
mapped_pages--;
|
||||
|
||||
|
||||
/* Determine if this is a new maximum logical sector. */
|
||||
if ((extra_info.lx_nand_page_extra_info_logical_sector & LX_NAND_LOGICAL_SECTOR_MASK) > max_mapped_sector)
|
||||
{
|
||||
|
||||
/* Yes, a new maximum mapped sectors - remember it! */
|
||||
max_mapped_sector = (extra_info.lx_nand_page_extra_info_logical_sector & LX_NAND_LOGICAL_SECTOR_MASK);
|
||||
}
|
||||
|
||||
/* Do we have a valid sector match? */
|
||||
if ((extra_info.lx_nand_page_extra_info_logical_sector & LX_NAND_LOGICAL_SECTOR_MASK) == logical_sector)
|
||||
{
|
||||
|
||||
/* Determine if we care about the superceded bit. */
|
||||
if (superceded_check == LX_FALSE)
|
||||
{
|
||||
|
||||
/* Prepare the return information. */
|
||||
*block = i;
|
||||
*page = j;
|
||||
|
||||
/* Determine if the sector mapping cache is enabled. */
|
||||
if (nand_flash -> lx_nand_flash_sector_mapping_cache_enabled)
|
||||
{
|
||||
|
||||
/* Yes, update the cache with the logical sector mapping. */
|
||||
|
||||
#ifndef LX_NAND_FLASH_DIRECT_MAPPING_CACHE
|
||||
|
||||
/* 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 + 2) = *(sector_mapping_cache_entry_ptr + 1);
|
||||
*(sector_mapping_cache_entry_ptr + 1) = *(sector_mapping_cache_entry_ptr);
|
||||
|
||||
/* Setup the new sector information in the cache. */
|
||||
sector_mapping_cache_entry_ptr -> lx_nand_sector_mapping_cache_logical_sector = (logical_sector | LX_NAND_SECTOR_MAPPING_CACHE_ENTRY_VALID);
|
||||
sector_mapping_cache_entry_ptr -> lx_nand_sector_mapping_cache_block = (USHORT) i;
|
||||
sector_mapping_cache_entry_ptr -> lx_nand_sector_mapping_cache_page = (USHORT) j;
|
||||
#else
|
||||
|
||||
/* Determine if this logical sector fits in the logical sector cache mapping. */
|
||||
if (logical_sector < LX_NAND_SECTOR_MAPPING_CACHE_SIZE)
|
||||
{
|
||||
|
||||
/* Yes, store the logical sector to block/page mapping in the cache. */
|
||||
nand_flash -> lx_nand_flash_sector_mapping_cache[logical_sector].lx_nand_sector_mapping_cache_block = (USHORT) i;
|
||||
nand_flash -> lx_nand_flash_sector_mapping_cache[logical_sector].lx_nand_sector_mapping_cache_page = (USHORT) j;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
/* Move to the next page. */
|
||||
j++;
|
||||
|
||||
/* Determine if the page has wrapped around. */
|
||||
if (j >= nand_flash -> lx_nand_flash_pages_per_block)
|
||||
{
|
||||
|
||||
/* Yes, page wrapped - move to page 1. */
|
||||
j = 1;
|
||||
}
|
||||
|
||||
/* Remember the last found block and page for next search. */
|
||||
nand_flash -> lx_nand_flash_found_block_search = i;
|
||||
nand_flash -> lx_nand_flash_found_page_search = j;
|
||||
|
||||
/* Return success! */
|
||||
return(LX_SUCCESS);
|
||||
}
|
||||
|
||||
/* Check for the superceded bit being clear, which means the sector was superceded. */
|
||||
else if (extra_info.lx_nand_page_extra_info_logical_sector & LX_NAND_PAGE_SUPERCEDED)
|
||||
{
|
||||
|
||||
/* Prepare the return information. */
|
||||
*block = i;
|
||||
*page = j;
|
||||
|
||||
/* No need to update the cache here, since this condition only happens during initialization. */
|
||||
|
||||
/* Move to the next page. */
|
||||
j++;
|
||||
|
||||
/* Determine if the page has wrapped around. */
|
||||
if (j >= nand_flash -> lx_nand_flash_pages_per_block)
|
||||
{
|
||||
|
||||
/* Yes, page wrapped - move to page 1. */
|
||||
j = 1;
|
||||
}
|
||||
|
||||
/* Remember the last found block and page for next search. */
|
||||
nand_flash -> lx_nand_flash_found_block_search = i;
|
||||
nand_flash -> lx_nand_flash_found_page_search = j;
|
||||
|
||||
/* Return success! */
|
||||
return(LX_SUCCESS);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Move to next page. */
|
||||
j++;
|
||||
|
||||
/* Determine if we have a wrap-around condition. */
|
||||
if (j >= nand_flash -> lx_nand_flash_pages_per_block)
|
||||
{
|
||||
|
||||
/* Yes, page wrapped - move to page 1. */
|
||||
j = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Determine if there are any more mapped sectors. */
|
||||
if (mapped_pages == 0)
|
||||
break;
|
||||
|
||||
/* Move to the next block. */
|
||||
i++;
|
||||
|
||||
/* Check for wrap condition. */
|
||||
if (i >= nand_flash -> lx_nand_flash_total_blocks)
|
||||
{
|
||||
|
||||
/* Wrap to the first block. */
|
||||
i = 0;
|
||||
}
|
||||
|
||||
/* Start at the first page in the next block. */
|
||||
j = 1;
|
||||
}
|
||||
|
||||
/* Determine if we should update the maximum mapped sector. */
|
||||
if (nand_flash -> lx_nand_flash_max_mapped_sector != 0xFFFFFFFF)
|
||||
{
|
||||
|
||||
/* Yes, update the maximum mapped sector. */
|
||||
nand_flash -> lx_nand_flash_max_mapped_sector = max_mapped_sector;
|
||||
}
|
||||
|
||||
/* Return sector not found status. */
|
||||
return(LX_SECTOR_NOT_FOUND);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,115 @@
|
||||
/***************************************************************************
|
||||
* Copyright (c) 2024 Microsoft Corporation
|
||||
* Copyright (c) 2026-present Eclipse ThreadX contributors
|
||||
*
|
||||
* This program and the accompanying materials are made available under the
|
||||
* terms of the MIT License which is available at
|
||||
* https://opensource.org/licenses/MIT.
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
**************************************************************************/
|
||||
|
||||
|
||||
/**************************************************************************/
|
||||
/**************************************************************************/
|
||||
/** */
|
||||
/** LevelX Component */
|
||||
/** */
|
||||
/** NAND Flash */
|
||||
/** */
|
||||
/**************************************************************************/
|
||||
/**************************************************************************/
|
||||
|
||||
#define LX_SOURCE_CODE
|
||||
|
||||
|
||||
/* Disable ThreadX error checking. */
|
||||
|
||||
#ifndef LX_DISABLE_ERROR_CHECKING
|
||||
#define LX_DISABLE_ERROR_CHECKING
|
||||
#endif
|
||||
|
||||
|
||||
/* Include necessary system files. */
|
||||
|
||||
#include "lx_api.h"
|
||||
|
||||
|
||||
/**************************************************************************/
|
||||
/* */
|
||||
/* FUNCTION RELEASE */
|
||||
/* */
|
||||
/* _lx_nand_flash_mapped_block_list_add PORTABLE C */
|
||||
/* 6.2.1 */
|
||||
/* AUTHOR */
|
||||
/* */
|
||||
/* Xiuwen Cai, Microsoft Corporation */
|
||||
/* */
|
||||
/* 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 */
|
||||
/* */
|
||||
/**************************************************************************/
|
||||
UINT _lx_nand_flash_mapped_block_list_add(LX_NAND_FLASH* nand_flash, ULONG block_mapping_index)
|
||||
{
|
||||
|
||||
ULONG insert_position;
|
||||
ULONG search_position;
|
||||
UCHAR new_block_erase_count;
|
||||
|
||||
|
||||
/* Get insert position for the mapped block list. */
|
||||
insert_position = nand_flash -> lx_nand_flash_mapped_block_list_head;
|
||||
|
||||
/* Check if the list if full. */
|
||||
if (insert_position < nand_flash -> lx_nand_flash_free_block_list_tail)
|
||||
{
|
||||
|
||||
/* Return an error. */
|
||||
return(LX_ERROR);
|
||||
}
|
||||
|
||||
/* Get the erase count. */
|
||||
new_block_erase_count = nand_flash -> lx_nand_flash_erase_count_table[nand_flash -> lx_nand_flash_block_mapping_table[block_mapping_index]];
|
||||
|
||||
/* Add one block to the free list. */
|
||||
nand_flash -> lx_nand_flash_mapped_block_list_head--;
|
||||
|
||||
/* Initialize the search pointer. */
|
||||
search_position = insert_position + 1;
|
||||
|
||||
/* Loop to search the insert position. */
|
||||
while ((search_position < nand_flash -> lx_nand_flash_block_list_size) &&
|
||||
(nand_flash -> lx_nand_flash_erase_count_table[nand_flash -> lx_nand_flash_block_mapping_table[nand_flash -> lx_nand_flash_block_list[search_position]]] < new_block_erase_count))
|
||||
{
|
||||
|
||||
/* Move the item in the list. */
|
||||
nand_flash -> lx_nand_flash_block_list[insert_position] = nand_flash -> lx_nand_flash_block_list[search_position];
|
||||
search_position++;
|
||||
insert_position++;
|
||||
}
|
||||
|
||||
/* Insert the new block to the list. */
|
||||
nand_flash -> lx_nand_flash_block_list[insert_position] = (USHORT)block_mapping_index;
|
||||
|
||||
/* Return successful completion. */
|
||||
return(LX_SUCCESS);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,92 @@
|
||||
/***************************************************************************
|
||||
* Copyright (c) 2024 Microsoft Corporation
|
||||
* Copyright (c) 2026-present Eclipse ThreadX contributors
|
||||
*
|
||||
* This program and the accompanying materials are made available under the
|
||||
* terms of the MIT License which is available at
|
||||
* https://opensource.org/licenses/MIT.
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
**************************************************************************/
|
||||
|
||||
|
||||
/**************************************************************************/
|
||||
/**************************************************************************/
|
||||
/** */
|
||||
/** LevelX Component */
|
||||
/** */
|
||||
/** NAND Flash */
|
||||
/** */
|
||||
/**************************************************************************/
|
||||
/**************************************************************************/
|
||||
|
||||
#define LX_SOURCE_CODE
|
||||
|
||||
|
||||
/* Disable ThreadX error checking. */
|
||||
|
||||
#ifndef LX_DISABLE_ERROR_CHECKING
|
||||
#define LX_DISABLE_ERROR_CHECKING
|
||||
#endif
|
||||
|
||||
|
||||
/* Include necessary system files. */
|
||||
|
||||
#include "lx_api.h"
|
||||
|
||||
|
||||
/**************************************************************************/
|
||||
/* */
|
||||
/* FUNCTION RELEASE */
|
||||
/* */
|
||||
/* _lx_nand_flash_mapped_block_list_get PORTABLE C */
|
||||
/* 6.2.1 */
|
||||
/* AUTHOR */
|
||||
/* */
|
||||
/* Xiuwen Cai, Microsoft Corporation */
|
||||
/* */
|
||||
/* 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 */
|
||||
/* */
|
||||
/**************************************************************************/
|
||||
UINT _lx_nand_flash_mapped_block_list_get(LX_NAND_FLASH* nand_flash, ULONG *block_mapping_index)
|
||||
{
|
||||
|
||||
|
||||
/* Check if the mapped block list is empty. */
|
||||
if (nand_flash -> lx_nand_flash_mapped_block_list_head == nand_flash -> lx_nand_flash_block_list_size - 1)
|
||||
{
|
||||
|
||||
/* Empty list, return error. */
|
||||
return(LX_NO_BLOCKS);
|
||||
}
|
||||
|
||||
/* Remove one block from the list. */
|
||||
nand_flash -> lx_nand_flash_mapped_block_list_head++;
|
||||
|
||||
/* Return the block number. */
|
||||
*block_mapping_index = nand_flash -> lx_nand_flash_block_list[nand_flash -> lx_nand_flash_mapped_block_list_head];
|
||||
|
||||
/* Return successful completion. */
|
||||
return(LX_SUCCESS);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,121 @@
|
||||
/***************************************************************************
|
||||
* Copyright (c) 2024 Microsoft Corporation
|
||||
* Copyright (c) 2026-present Eclipse ThreadX contributors
|
||||
*
|
||||
* This program and the accompanying materials are made available under the
|
||||
* terms of the MIT License which is available at
|
||||
* https://opensource.org/licenses/MIT.
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
**************************************************************************/
|
||||
|
||||
|
||||
/**************************************************************************/
|
||||
/**************************************************************************/
|
||||
/** */
|
||||
/** LevelX Component */
|
||||
/** */
|
||||
/** NAND Flash */
|
||||
/** */
|
||||
/**************************************************************************/
|
||||
/**************************************************************************/
|
||||
|
||||
#define LX_SOURCE_CODE
|
||||
|
||||
|
||||
/* Disable ThreadX error checking. */
|
||||
|
||||
#ifndef LX_DISABLE_ERROR_CHECKING
|
||||
#define LX_DISABLE_ERROR_CHECKING
|
||||
#endif
|
||||
|
||||
|
||||
/* Include necessary system files. */
|
||||
|
||||
#include "lx_api.h"
|
||||
|
||||
|
||||
/**************************************************************************/
|
||||
/* */
|
||||
/* FUNCTION RELEASE */
|
||||
/* */
|
||||
/* _lx_nand_flash_mapped_block_list_remove PORTABLE C */
|
||||
/* 6.2.1 */
|
||||
/* AUTHOR */
|
||||
/* */
|
||||
/* Xiuwen Cai, Microsoft Corporation */
|
||||
/* */
|
||||
/* 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 */
|
||||
/* */
|
||||
/**************************************************************************/
|
||||
UINT _lx_nand_flash_mapped_block_list_remove(LX_NAND_FLASH* nand_flash, ULONG block_mapping_index)
|
||||
{
|
||||
|
||||
ULONG search_position;
|
||||
|
||||
|
||||
/* Initialize the search pointer. */
|
||||
search_position = nand_flash -> lx_nand_flash_mapped_block_list_head + 1;
|
||||
|
||||
/* Loop to search the block in the list. */
|
||||
while (search_position < nand_flash -> lx_nand_flash_block_list_size)
|
||||
{
|
||||
|
||||
/* Check if there is a match in the list. */
|
||||
if (nand_flash -> lx_nand_flash_block_list[search_position] == block_mapping_index)
|
||||
{
|
||||
|
||||
/* Get out of the loop. */
|
||||
break;
|
||||
}
|
||||
|
||||
/* Move to next position. */
|
||||
search_position++;
|
||||
}
|
||||
|
||||
/* Check if the block is found. */
|
||||
if (search_position < nand_flash -> lx_nand_flash_block_list_size)
|
||||
{
|
||||
|
||||
/* Remove one item from the list. */
|
||||
nand_flash -> lx_nand_flash_mapped_block_list_head++;
|
||||
|
||||
/* Loop to move items in the list. */
|
||||
while (search_position > nand_flash -> lx_nand_flash_mapped_block_list_head)
|
||||
{
|
||||
|
||||
/* Move the item in the list. */
|
||||
nand_flash -> lx_nand_flash_block_list[search_position] = nand_flash -> lx_nand_flash_block_list[search_position - 1];
|
||||
search_position--;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
/* Return error. */
|
||||
return(LX_NO_BLOCKS);
|
||||
}
|
||||
|
||||
/* Return successful completion. */
|
||||
return(LX_SUCCESS);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,244 @@
|
||||
/***************************************************************************
|
||||
* 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_memory_initialize PORTABLE C */
|
||||
/* 6.2.1 */
|
||||
/* AUTHOR */
|
||||
/* */
|
||||
/* Xiuwen Cai, Microsoft Corporation */
|
||||
/* */
|
||||
/* DESCRIPTION */
|
||||
/* */
|
||||
/* This function imitialize memory buffer for NAND flash instance. */
|
||||
/* */
|
||||
/* INPUT */
|
||||
/* */
|
||||
/* nand_flash NAND flash instance */
|
||||
/* memory_ptr Pointer to memory used by the */
|
||||
/* LevelX for this NAND. */
|
||||
/* memory_size Size of memory */
|
||||
/* */
|
||||
/* OUTPUT */
|
||||
/* */
|
||||
/* return status */
|
||||
/* */
|
||||
/* CALLS */
|
||||
/* */
|
||||
/* LX_MEMSET Initialize memory */
|
||||
/* */
|
||||
/* CALLED BY */
|
||||
/* */
|
||||
/* Internal LevelX */
|
||||
/* */
|
||||
/**************************************************************************/
|
||||
UINT _lx_nand_flash_memory_initialize(LX_NAND_FLASH *nand_flash, ULONG* memory_ptr, UINT memory_size)
|
||||
{
|
||||
|
||||
UINT memory_offset;
|
||||
UINT buffer_size;
|
||||
|
||||
|
||||
/* Clear the memory buffer. */
|
||||
LX_MEMSET(memory_ptr, 0, memory_size);
|
||||
|
||||
/* Reset the memory offset. */
|
||||
memory_offset = 0;
|
||||
|
||||
/* Set memory size for block mapping table. */
|
||||
buffer_size = nand_flash -> lx_nand_flash_total_blocks * sizeof(*nand_flash -> lx_nand_flash_block_mapping_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 mapping table. */
|
||||
nand_flash -> lx_nand_flash_block_mapping_table = (USHORT*)(((UCHAR*)memory_ptr) + memory_offset);
|
||||
|
||||
/* Update block mapping table size. */
|
||||
nand_flash -> lx_nand_flash_block_mapping_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);
|
||||
}
|
||||
|
||||
/* Set memory size for erase count table. */
|
||||
buffer_size = nand_flash -> lx_nand_flash_total_blocks * sizeof(*nand_flash -> lx_nand_flash_erase_count_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 erase count table. */
|
||||
nand_flash -> lx_nand_flash_erase_count_table = (UCHAR*)(((UCHAR*)memory_ptr) + memory_offset);
|
||||
|
||||
/* Update memory offset. */
|
||||
memory_offset += buffer_size;
|
||||
|
||||
/* Update erase count table size. */
|
||||
nand_flash -> lx_nand_flash_erase_count_table_size = buffer_size;
|
||||
|
||||
/* Check if there is enough memory. */
|
||||
if (memory_offset > memory_size)
|
||||
{
|
||||
|
||||
/* No enough memory, return error. */
|
||||
return(LX_NO_MEMORY);
|
||||
}
|
||||
|
||||
/* Assign memory for block list. */
|
||||
nand_flash -> lx_nand_flash_block_list = (USHORT*)(((UCHAR*)memory_ptr) + memory_offset);
|
||||
|
||||
/* Update memory offset. */
|
||||
memory_offset += nand_flash -> lx_nand_flash_total_blocks * sizeof(*nand_flash -> lx_nand_flash_block_list);
|
||||
|
||||
/* Check if there is enough memory. */
|
||||
if (memory_offset > memory_size)
|
||||
{
|
||||
|
||||
/* No enough memory, return error. */
|
||||
return(LX_NO_MEMORY);
|
||||
}
|
||||
|
||||
/* Update block list size. */
|
||||
nand_flash -> lx_nand_flash_block_list_size = nand_flash -> lx_nand_flash_total_blocks;
|
||||
|
||||
/* Initialize block list. */
|
||||
nand_flash -> lx_nand_flash_free_block_list_tail = 0;
|
||||
nand_flash -> lx_nand_flash_mapped_block_list_head = nand_flash -> lx_nand_flash_block_list_size - 1;
|
||||
|
||||
/* Set memory size for block status table. */
|
||||
buffer_size = nand_flash -> lx_nand_flash_total_blocks * sizeof(*nand_flash -> lx_nand_flash_block_status_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 status table. */
|
||||
nand_flash -> lx_nand_flash_block_status_table = (USHORT*)(((UCHAR*)memory_ptr) + memory_offset);
|
||||
|
||||
/* Update memory offset. */
|
||||
memory_offset += buffer_size;
|
||||
|
||||
/* Update block status table size. */
|
||||
nand_flash -> lx_nand_flash_block_status_table_size = buffer_size;
|
||||
|
||||
/* Check if there is enough memory. */
|
||||
if (memory_offset > memory_size)
|
||||
{
|
||||
|
||||
/* No enough memory, return error. */
|
||||
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. */
|
||||
nand_flash -> lx_nand_flash_page_buffer = ((UCHAR*)memory_ptr) + memory_offset;
|
||||
|
||||
/* Update page buffer size. */
|
||||
nand_flash -> lx_nand_flash_page_buffer_size = memory_size - memory_offset;
|
||||
|
||||
/* Check if there is enough memory. */
|
||||
if (nand_flash -> lx_nand_flash_page_buffer_size < (nand_flash -> lx_nand_flash_bytes_per_page + nand_flash -> lx_nand_flash_spare_total_length) * 2)
|
||||
{
|
||||
|
||||
/* No enough memory, return error. */
|
||||
return(LX_NO_MEMORY);
|
||||
}
|
||||
|
||||
/* Return a successful completion. */
|
||||
return(LX_SUCCESS);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,368 @@
|
||||
/***************************************************************************
|
||||
* Copyright (c) 2024 Microsoft Corporation
|
||||
* Copyright (c) 2026-present Eclipse ThreadX contributors
|
||||
*
|
||||
* This program and the accompanying materials are made available under the
|
||||
* terms of the MIT License which is available at
|
||||
* https://opensource.org/licenses/MIT.
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
**************************************************************************/
|
||||
|
||||
|
||||
/**************************************************************************/
|
||||
/**************************************************************************/
|
||||
/** */
|
||||
/** LevelX Component */
|
||||
/** */
|
||||
/** NAND Flash */
|
||||
/** */
|
||||
/**************************************************************************/
|
||||
/**************************************************************************/
|
||||
|
||||
#define LX_SOURCE_CODE
|
||||
|
||||
|
||||
/* Disable ThreadX error checking. */
|
||||
|
||||
#ifndef LX_DISABLE_ERROR_CHECKING
|
||||
#define LX_DISABLE_ERROR_CHECKING
|
||||
#endif
|
||||
|
||||
|
||||
/* Include necessary system files. */
|
||||
|
||||
#include "lx_api.h"
|
||||
|
||||
|
||||
/**************************************************************************/
|
||||
/* */
|
||||
/* FUNCTION RELEASE */
|
||||
/* */
|
||||
/* _lx_nand_flash_metadata_allocate PORTABLE C */
|
||||
/* 6.2.1 */
|
||||
/* AUTHOR */
|
||||
/* */
|
||||
/* Xiuwen Cai, Microsoft Corporation */
|
||||
/* */
|
||||
/* DESCRIPTION */
|
||||
/* */
|
||||
/* This function allocates new blocks for metadata if current metadata */
|
||||
/* block is full. This function also frees metadata blocks if the chain*/
|
||||
/* is too long. */
|
||||
/* */
|
||||
/* INPUT */
|
||||
/* */
|
||||
/* nand_flash NAND flash instance */
|
||||
/* */
|
||||
/* OUTPUT */
|
||||
/* */
|
||||
/* return status */
|
||||
/* */
|
||||
/* CALLS */
|
||||
/* */
|
||||
/* _lx_nand_flash_metadata_build Build metadata */
|
||||
/* _lx_nand_flash_driver_block_erase Erase block */
|
||||
/* _lx_nand_flash_block_data_move Move block data */
|
||||
/* _lx_nand_flash_free_block_list_add Add free block list */
|
||||
/* _lx_nand_flash_block_allocate Allocate block */
|
||||
/* _lx_nand_flash_block_status_set Set block status */
|
||||
/* _lx_nand_flash_metadata_write Write metadata */
|
||||
/* _lx_nand_flash_system_error Internal system error handler */
|
||||
/* */
|
||||
/* CALLED BY */
|
||||
/* */
|
||||
/* Internal LevelX */
|
||||
/* */
|
||||
/**************************************************************************/
|
||||
UINT _lx_nand_flash_metadata_allocate(LX_NAND_FLASH *nand_flash)
|
||||
{
|
||||
|
||||
ULONG block;
|
||||
ULONG page;
|
||||
UINT status;
|
||||
UCHAR *page_buffer_ptr;
|
||||
UINT j;
|
||||
UCHAR min_erase_count;
|
||||
|
||||
|
||||
/* Get current page for metadata block. */
|
||||
page = nand_flash -> lx_nand_flash_metadata_block_current_page;
|
||||
|
||||
/* Check if new metadata block is required. */
|
||||
if (page < nand_flash -> lx_nand_flash_pages_per_block)
|
||||
{
|
||||
|
||||
/* No new block is required. Just return success. */
|
||||
return(LX_SUCCESS);
|
||||
}
|
||||
|
||||
/* Advance to next metadata block. */
|
||||
nand_flash -> lx_nand_flash_metadata_block_number_current = nand_flash -> lx_nand_flash_metadata_block_number_next;
|
||||
|
||||
/* Reset current page number. */
|
||||
nand_flash -> lx_nand_flash_metadata_block_current_page = 0;
|
||||
|
||||
/* Advance to next backup metadata block. */
|
||||
nand_flash -> lx_nand_flash_backup_metadata_block_number_current = nand_flash -> lx_nand_flash_backup_metadata_block_number_next;
|
||||
|
||||
/* Reset current page number for backup metadata block. */
|
||||
nand_flash -> lx_nand_flash_backup_metadata_block_current_page = 0;
|
||||
|
||||
/* Check if number of allocated blocks reaches maximum. */
|
||||
if (nand_flash -> lx_nand_flash_metadata_block_count == LX_NAND_FLASH_MAX_METADATA_BLOCKS)
|
||||
{
|
||||
|
||||
/* Loop to mark metadata blocks as free. */
|
||||
for (j = 0; j < LX_NAND_FLASH_MAX_METADATA_BLOCKS - 1; j++)
|
||||
{
|
||||
|
||||
/* Free metadata block. */
|
||||
nand_flash -> lx_nand_flash_block_status_table[nand_flash -> lx_nand_flash_metadata_block[j]] = LX_NAND_BLOCK_STATUS_FREE;
|
||||
|
||||
/* Free backup metadata block. */
|
||||
nand_flash -> lx_nand_flash_block_status_table[nand_flash -> lx_nand_flash_backup_metadata_block[j]] = LX_NAND_BLOCK_STATUS_FREE;
|
||||
|
||||
/* Increase erase count. */
|
||||
nand_flash -> lx_nand_flash_erase_count_table[nand_flash -> lx_nand_flash_metadata_block[j]]++;
|
||||
|
||||
/* Increase erase count for backup metadata block. */
|
||||
nand_flash -> lx_nand_flash_erase_count_table[nand_flash -> lx_nand_flash_backup_metadata_block[j]]++;
|
||||
}
|
||||
|
||||
/* Set new metadata block head. */
|
||||
nand_flash -> lx_nand_flash_metadata_block_number = nand_flash -> lx_nand_flash_metadata_block_number_current;
|
||||
|
||||
/* Set new backup metadata block head. */
|
||||
nand_flash -> lx_nand_flash_backup_metadata_block_number = nand_flash -> lx_nand_flash_backup_metadata_block_number_current;
|
||||
|
||||
/* Set erase count to maximum. */
|
||||
min_erase_count = 255;
|
||||
|
||||
/* Loop to find the minimum erase count. */
|
||||
for (j = 0; j < nand_flash -> lx_nand_flash_total_blocks; j++)
|
||||
{
|
||||
|
||||
/* Exclude erase count of bad block. */
|
||||
if(nand_flash -> lx_nand_flash_block_status_table[j] != LX_NAND_BLOCK_STATUS_BAD)
|
||||
{
|
||||
|
||||
/* Check if it has less erase count. */
|
||||
if (nand_flash -> lx_nand_flash_erase_count_table[j] < min_erase_count)
|
||||
{
|
||||
|
||||
/* Update the minimum erase count. */
|
||||
min_erase_count = nand_flash -> lx_nand_flash_erase_count_table[j];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Check if the minimum erase count is larger than zero. */
|
||||
if (min_erase_count > 0)
|
||||
{
|
||||
|
||||
/* Loop to update erase count. */
|
||||
for (j = 0; j < nand_flash -> lx_nand_flash_total_blocks; j++)
|
||||
{
|
||||
|
||||
/* Skip bad blocks. */
|
||||
if (nand_flash -> lx_nand_flash_block_status_table[j] != LX_NAND_BLOCK_STATUS_BAD)
|
||||
{
|
||||
|
||||
/* Update erase count. */
|
||||
nand_flash -> lx_nand_flash_erase_count_table[j] = (UCHAR)(nand_flash -> lx_nand_flash_erase_count_table[j] - min_erase_count);
|
||||
}
|
||||
}
|
||||
|
||||
/* Update base erase count. */
|
||||
nand_flash -> lx_nand_flash_base_erase_count += (ULONG)min_erase_count;
|
||||
}
|
||||
|
||||
/* Rebuild metadata pages. */
|
||||
status = _lx_nand_flash_metadata_build(nand_flash);
|
||||
|
||||
/* Check return status. */
|
||||
if (status != LX_SUCCESS)
|
||||
{
|
||||
|
||||
/* Return error status. */
|
||||
return(status);
|
||||
}
|
||||
|
||||
/* Loop to erase freed blocks. */
|
||||
for (j = 0; j < LX_NAND_FLASH_MAX_METADATA_BLOCKS - 1; j++)
|
||||
{
|
||||
|
||||
/* Get the block number to erase. */
|
||||
block = nand_flash -> lx_nand_flash_metadata_block[j];
|
||||
|
||||
/* 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]);
|
||||
|
||||
/* 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);
|
||||
}
|
||||
|
||||
/* Check if the block has too many erases. */
|
||||
if (nand_flash -> lx_nand_flash_erase_count_table[block] > LX_NAND_FLASH_MAX_ERASE_COUNT_DELTA)
|
||||
{
|
||||
|
||||
/* Move data from less worn block. */
|
||||
_lx_nand_flash_block_data_move(nand_flash, block);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
/* Add the block to free block list. */
|
||||
_lx_nand_flash_free_block_list_add(nand_flash, block);
|
||||
}
|
||||
|
||||
/* Get the block number from backup metadata blocks. */
|
||||
block = nand_flash -> lx_nand_flash_backup_metadata_block[j];
|
||||
|
||||
/* 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]);
|
||||
|
||||
/* 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);
|
||||
}
|
||||
|
||||
/* Check if the block has too many erases. */
|
||||
if (nand_flash -> lx_nand_flash_erase_count_table[block] > LX_NAND_FLASH_MAX_ERASE_COUNT_DELTA)
|
||||
{
|
||||
|
||||
/* Move data from less worn block. */
|
||||
_lx_nand_flash_block_data_move(nand_flash, block);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
/* Add the block to free block list. */
|
||||
_lx_nand_flash_free_block_list_add(nand_flash, block);
|
||||
}
|
||||
}
|
||||
|
||||
/* Update metadata block list. */
|
||||
nand_flash -> lx_nand_flash_metadata_block[0] = (USHORT)nand_flash -> lx_nand_flash_metadata_block_number_current;
|
||||
|
||||
/* Update metadata block list. */
|
||||
nand_flash -> lx_nand_flash_backup_metadata_block[0] = (USHORT)nand_flash -> lx_nand_flash_backup_metadata_block_number_current;
|
||||
|
||||
/* Set metadata block count to one. */
|
||||
nand_flash -> lx_nand_flash_metadata_block_count = 1;
|
||||
}
|
||||
|
||||
/* Allocate new block for metadata. */
|
||||
status = _lx_nand_flash_block_allocate(nand_flash, &block);
|
||||
|
||||
/* Check return status. */
|
||||
if (status != LX_SUCCESS)
|
||||
{
|
||||
|
||||
/* 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);
|
||||
}
|
||||
}
|
||||
|
||||
/* Update next metadata block number. */
|
||||
nand_flash -> lx_nand_flash_metadata_block_number_next = block;
|
||||
|
||||
/* Save the new block in metadata block list. */
|
||||
nand_flash -> lx_nand_flash_metadata_block[nand_flash -> lx_nand_flash_metadata_block_count] = (USHORT)block;
|
||||
|
||||
/* Set the block status to allocated. */
|
||||
status = _lx_nand_flash_block_status_set(nand_flash, block, LX_NAND_BLOCK_STATUS_ALLOCATED);
|
||||
|
||||
/* Check return status. */
|
||||
if (status != LX_SUCCESS)
|
||||
{
|
||||
|
||||
/* Return status. */
|
||||
return (status);
|
||||
}
|
||||
|
||||
/* Allocate new block for backup metadata. */
|
||||
status = _lx_nand_flash_block_allocate(nand_flash, &block);
|
||||
|
||||
/* Check return status. */
|
||||
if (status != LX_SUCCESS)
|
||||
{
|
||||
|
||||
/* 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);
|
||||
}
|
||||
}
|
||||
|
||||
/* Update next backup metadata block number. */
|
||||
nand_flash -> lx_nand_flash_backup_metadata_block_number_next = block;
|
||||
|
||||
/* Save the new block in metadata block list. */
|
||||
nand_flash -> lx_nand_flash_backup_metadata_block[nand_flash -> lx_nand_flash_metadata_block_count] = (USHORT)block;
|
||||
|
||||
/* Set the block status to allocated. */
|
||||
status = _lx_nand_flash_block_status_set(nand_flash, block, LX_NAND_BLOCK_STATUS_ALLOCATED);
|
||||
if (status != LX_SUCCESS)
|
||||
{
|
||||
return (status);
|
||||
}
|
||||
|
||||
/* Setup page buffer. */
|
||||
page_buffer_ptr = nand_flash -> lx_nand_flash_page_buffer;
|
||||
|
||||
/* Initialize page data. */
|
||||
LX_MEMSET(page_buffer_ptr, 0xFF, nand_flash -> lx_nand_flash_bytes_per_page);
|
||||
|
||||
/* Save next block number. */
|
||||
LX_UTILITY_LONG_SET(&page_buffer_ptr[LX_NAND_BLOCK_LINK_MAIN_METADATA_OFFSET], nand_flash -> lx_nand_flash_metadata_block_number_next);
|
||||
|
||||
/* Save next block number for backup metadata. */
|
||||
LX_UTILITY_LONG_SET(&page_buffer_ptr[LX_NAND_BLOCK_LINK_BACKUP_METADATA_OFFSET], nand_flash -> lx_nand_flash_backup_metadata_block_number_next);
|
||||
|
||||
/* Write metadata. */
|
||||
status = _lx_nand_flash_metadata_write(nand_flash, page_buffer_ptr, LX_NAND_PAGE_TYPE_BLOCK_LINK);
|
||||
|
||||
/* Increase metadata block count. */
|
||||
nand_flash -> lx_nand_flash_metadata_block_count++;
|
||||
|
||||
/* Return sector not found status. */
|
||||
return(status);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,164 @@
|
||||
/***************************************************************************
|
||||
* Copyright (c) 2024 Microsoft Corporation
|
||||
* Copyright (c) 2026-present Eclipse ThreadX contributors
|
||||
*
|
||||
* This program and the accompanying materials are made available under the
|
||||
* terms of the MIT License which is available at
|
||||
* https://opensource.org/licenses/MIT.
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
**************************************************************************/
|
||||
|
||||
|
||||
/**************************************************************************/
|
||||
/**************************************************************************/
|
||||
/** */
|
||||
/** LevelX Component */
|
||||
/** */
|
||||
/** NAND Flash */
|
||||
/** */
|
||||
/**************************************************************************/
|
||||
/**************************************************************************/
|
||||
|
||||
#define LX_SOURCE_CODE
|
||||
|
||||
|
||||
/* Disable ThreadX error checking. */
|
||||
|
||||
#ifndef LX_DISABLE_ERROR_CHECKING
|
||||
#define LX_DISABLE_ERROR_CHECKING
|
||||
#endif
|
||||
|
||||
|
||||
/* Include necessary system files. */
|
||||
|
||||
#include "lx_api.h"
|
||||
|
||||
|
||||
/**************************************************************************/
|
||||
/* */
|
||||
/* FUNCTION RELEASE */
|
||||
/* */
|
||||
/* _lx_nand_flash_metadata_build PORTABLE C */
|
||||
/* 6.2.1 */
|
||||
/* AUTHOR */
|
||||
/* */
|
||||
/* Xiuwen Cai, Microsoft Corporation */
|
||||
/* */
|
||||
/* 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 */
|
||||
/* */
|
||||
/**************************************************************************/
|
||||
UINT _lx_nand_flash_metadata_build(LX_NAND_FLASH *nand_flash)
|
||||
{
|
||||
|
||||
UINT status;
|
||||
LX_NAND_DEVICE_INFO *nand_device_info_page;
|
||||
UINT page_count;
|
||||
UINT i;
|
||||
|
||||
/* Build device info page. */
|
||||
nand_device_info_page = (LX_NAND_DEVICE_INFO*)nand_flash -> lx_nand_flash_page_buffer;
|
||||
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;
|
||||
nand_device_info_page -> lx_nand_device_info_major_version = LEVELX_MAJOR_VERSION;
|
||||
nand_device_info_page -> lx_nand_device_info_minor_version = LEVELX_MINOR_VERSION;
|
||||
nand_device_info_page -> lx_nand_device_info_patch_version = LEVELX_PATCH_VERSION;
|
||||
nand_device_info_page -> lx_nand_device_info_metadata_block_number = nand_flash -> lx_nand_flash_metadata_block_number;
|
||||
nand_device_info_page -> lx_nand_device_info_backup_metadata_block_number = nand_flash -> lx_nand_flash_backup_metadata_block_number;
|
||||
nand_device_info_page -> lx_nand_device_info_base_erase_count = nand_flash -> lx_nand_flash_base_erase_count;
|
||||
|
||||
/* Write metadata. */
|
||||
status = _lx_nand_flash_metadata_write(nand_flash, (UCHAR*)nand_device_info_page, LX_NAND_PAGE_TYPE_DEVICE_INFO);
|
||||
|
||||
/* Check return status. */
|
||||
if (status != LX_SUCCESS)
|
||||
{
|
||||
|
||||
/* Return error status. */
|
||||
return(status);
|
||||
}
|
||||
|
||||
/* Calculate page count for erase count table. */
|
||||
page_count = (nand_flash -> lx_nand_flash_erase_count_table_size + (nand_flash -> lx_nand_flash_bytes_per_page - 1)) / nand_flash -> lx_nand_flash_bytes_per_page;
|
||||
|
||||
/* Loop to write all the pages. */
|
||||
for (i = 0; i < page_count; i++)
|
||||
{
|
||||
|
||||
/* Write 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),
|
||||
LX_NAND_PAGE_TYPE_ERASE_COUNT_TABLE | i);
|
||||
|
||||
/* Check return status. */
|
||||
if (status != LX_SUCCESS)
|
||||
{
|
||||
|
||||
/* Return error status. */
|
||||
return(status);
|
||||
}
|
||||
}
|
||||
|
||||
/* Calculate page count for block mapping table. */
|
||||
page_count = (nand_flash -> lx_nand_flash_block_mapping_table_size + (nand_flash -> lx_nand_flash_bytes_per_page - 1)) / nand_flash -> lx_nand_flash_bytes_per_page;
|
||||
|
||||
/* Loop to write all the pages. */
|
||||
for (i = 0; i < page_count; i++)
|
||||
{
|
||||
|
||||
/* Write 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)),
|
||||
LX_NAND_PAGE_TYPE_BLOCK_MAPPING_TABLE | i);
|
||||
/* Check return status. */
|
||||
if (status != LX_SUCCESS)
|
||||
{
|
||||
|
||||
/* Return error status. */
|
||||
return(status);
|
||||
}
|
||||
}
|
||||
|
||||
/* Calculate page count for block status table. */
|
||||
page_count = (nand_flash -> lx_nand_flash_block_status_table_size + (nand_flash -> lx_nand_flash_bytes_per_page - 1)) / nand_flash -> lx_nand_flash_bytes_per_page;
|
||||
|
||||
/* Loop to write all the pages. */
|
||||
for (i = 0; i < page_count; i++)
|
||||
{
|
||||
|
||||
/* Write 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)),
|
||||
LX_NAND_PAGE_TYPE_BLOCK_STATUS_TABLE | i);
|
||||
|
||||
/* Check return status. */
|
||||
if (status != LX_SUCCESS)
|
||||
{
|
||||
|
||||
/* Return error status. */
|
||||
return(status);
|
||||
}
|
||||
}
|
||||
|
||||
/* Return status. */
|
||||
return(status);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,160 @@
|
||||
/***************************************************************************
|
||||
* Copyright (c) 2024 Microsoft Corporation
|
||||
* Copyright (c) 2026-present Eclipse ThreadX contributors
|
||||
*
|
||||
* This program and the accompanying materials are made available under the
|
||||
* terms of the MIT License which is available at
|
||||
* https://opensource.org/licenses/MIT.
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
**************************************************************************/
|
||||
|
||||
|
||||
/**************************************************************************/
|
||||
/**************************************************************************/
|
||||
/** */
|
||||
/** LevelX Component */
|
||||
/** */
|
||||
/** NAND Flash */
|
||||
/** */
|
||||
/**************************************************************************/
|
||||
/**************************************************************************/
|
||||
|
||||
#define LX_SOURCE_CODE
|
||||
|
||||
|
||||
/* Disable ThreadX error checking. */
|
||||
|
||||
#ifndef LX_DISABLE_ERROR_CHECKING
|
||||
#define LX_DISABLE_ERROR_CHECKING
|
||||
#endif
|
||||
|
||||
|
||||
/* Include necessary system files. */
|
||||
|
||||
#include "lx_api.h"
|
||||
|
||||
|
||||
/**************************************************************************/
|
||||
/* */
|
||||
/* FUNCTION RELEASE */
|
||||
/* */
|
||||
/* _lx_nand_flash_metadata_write PORTABLE C */
|
||||
/* 6.2.1 */
|
||||
/* AUTHOR */
|
||||
/* */
|
||||
/* Xiuwen Cai, Microsoft Corporation */
|
||||
/* */
|
||||
/* 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 */
|
||||
/* */
|
||||
/**************************************************************************/
|
||||
UINT _lx_nand_flash_metadata_write(LX_NAND_FLASH *nand_flash, UCHAR* main_buffer, ULONG spare_value)
|
||||
{
|
||||
|
||||
ULONG block;
|
||||
ULONG page;
|
||||
UINT status;
|
||||
UCHAR *spare_buffer_ptr;
|
||||
|
||||
|
||||
/* Setup spare buffer pointer. */
|
||||
spare_buffer_ptr = nand_flash -> lx_nand_flash_page_buffer + nand_flash -> lx_nand_flash_bytes_per_page;
|
||||
|
||||
/* Initialize the spare buffer. */
|
||||
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. */
|
||||
if (nand_flash -> lx_nand_flash_spare_data2_length >= 2)
|
||||
{
|
||||
|
||||
/* Save metadata block number in spare bytes. */
|
||||
LX_UTILITY_SHORT_SET(&spare_buffer_ptr[nand_flash -> lx_nand_flash_spare_data2_offset], nand_flash -> lx_nand_flash_metadata_block_number);
|
||||
}
|
||||
|
||||
/* Save metadata type data in spare bytes. */
|
||||
LX_UTILITY_LONG_SET(&spare_buffer_ptr[nand_flash -> lx_nand_flash_spare_data1_offset], spare_value);
|
||||
|
||||
/* Get current metadata block number. */
|
||||
block = nand_flash -> lx_nand_flash_metadata_block_number_current;
|
||||
|
||||
/* Get current metadata page number. */
|
||||
page = nand_flash -> lx_nand_flash_metadata_block_current_page;
|
||||
|
||||
/* Write the page. */
|
||||
#ifdef LX_NAND_ENABLE_CONTROL_BLOCK_FOR_DRIVER_INTERFACE
|
||||
status = (nand_flash -> lx_nand_flash_driver_pages_write)(nand_flash, block, page, main_buffer, spare_buffer_ptr, 1);
|
||||
#else
|
||||
status = (nand_flash -> lx_nand_flash_driver_pages_write)(block, page, main_buffer, 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);
|
||||
|
||||
/* Return an error. */
|
||||
return(status);
|
||||
}
|
||||
|
||||
/* Increase current page for metadata block. */
|
||||
nand_flash -> lx_nand_flash_metadata_block_current_page++;
|
||||
|
||||
/* Get current backup metadata block number. */
|
||||
block = nand_flash -> lx_nand_flash_backup_metadata_block_number_current;
|
||||
|
||||
/* Get current backup metadata page number. */
|
||||
page = nand_flash -> lx_nand_flash_backup_metadata_block_current_page;
|
||||
|
||||
/* Write the page. */
|
||||
#ifdef LX_NAND_ENABLE_CONTROL_BLOCK_FOR_DRIVER_INTERFACE
|
||||
status = (nand_flash -> lx_nand_flash_driver_pages_write)(nand_flash, block, page, main_buffer, spare_buffer_ptr, 1);
|
||||
#else
|
||||
status = (nand_flash -> lx_nand_flash_driver_pages_write)(block, page, main_buffer, 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);
|
||||
|
||||
/* Return an error. */
|
||||
return(status);
|
||||
}
|
||||
|
||||
/* Increase current page for backup metadata block. */
|
||||
nand_flash -> lx_nand_flash_backup_metadata_block_current_page++;
|
||||
|
||||
/* Allocate new block for metadata if necessary. */
|
||||
_lx_nand_flash_metadata_allocate(nand_flash);
|
||||
|
||||
/* Return sector not found status. */
|
||||
return(status);
|
||||
}
|
||||
|
||||
@@ -1,301 +0,0 @@
|
||||
/**************************************************************************/
|
||||
/* */
|
||||
/* Copyright (c) Microsoft Corporation. All rights reserved. */
|
||||
/* */
|
||||
/* This software is licensed under the Microsoft Software License */
|
||||
/* Terms for Microsoft Azure RTOS. Full text of the license can be */
|
||||
/* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */
|
||||
/* and in the root directory of this software. */
|
||||
/* */
|
||||
/**************************************************************************/
|
||||
|
||||
|
||||
/**************************************************************************/
|
||||
/**************************************************************************/
|
||||
/** */
|
||||
/** LevelX Component */
|
||||
/** */
|
||||
/** NAND Flash */
|
||||
/** */
|
||||
/**************************************************************************/
|
||||
/**************************************************************************/
|
||||
|
||||
#define LX_SOURCE_CODE
|
||||
|
||||
|
||||
/* Disable ThreadX error checking. */
|
||||
|
||||
#ifndef TX_DISABLE_ERROR_CHECKING
|
||||
#define TX_DISABLE_ERROR_CHECKING
|
||||
#endif
|
||||
|
||||
|
||||
/* Include necessary system files. */
|
||||
|
||||
#include "lx_api.h"
|
||||
|
||||
|
||||
/**************************************************************************/
|
||||
/* */
|
||||
/* FUNCTION RELEASE */
|
||||
/* */
|
||||
/* _lx_nand_flash_next_block_to_erase_find PORTABLE C */
|
||||
/* 6.0 */
|
||||
/* AUTHOR */
|
||||
/* */
|
||||
/* William E. Lamie, Microsoft Corporation */
|
||||
/* */
|
||||
/* DESCRIPTION */
|
||||
/* */
|
||||
/* This function finds the next block to erase in the NAND flash. */
|
||||
/* */
|
||||
/* INPUT */
|
||||
/* */
|
||||
/* nand_flash NAND flash instance */
|
||||
/* return_erase_block Returned block to erase */
|
||||
/* return_erase_count Returned erase count of block */
|
||||
/* return_mapped_pages Returned number of mapped */
|
||||
/* pages */
|
||||
/* return_obsolete_pages Returned number of obsolete */
|
||||
/* pages */
|
||||
/* */
|
||||
/* OUTPUT */
|
||||
/* */
|
||||
/* return status */
|
||||
/* */
|
||||
/* CALLS */
|
||||
/* */
|
||||
/* _lx_nand_flash_driver_extra_bytes_get Driver block extra bytes get */
|
||||
/* _lx_nand_flash_driver_block_status_get */
|
||||
/* Driver block status get */
|
||||
/* _lx_nand_flash_driver_read Driver page read */
|
||||
/* _lx_nand_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 */
|
||||
/* */
|
||||
/**************************************************************************/
|
||||
UINT _lx_nand_flash_next_block_to_erase_find(LX_NAND_FLASH *nand_flash, ULONG *return_erase_block, ULONG *return_erase_count, ULONG *return_mapped_pages, ULONG *return_obsolete_pages)
|
||||
{
|
||||
|
||||
LX_NAND_PAGE_EXTRA_INFO extra_info;
|
||||
UCHAR block_status;
|
||||
ULONG *block_word_ptr;
|
||||
ULONG block;
|
||||
ULONG page;
|
||||
ULONG mapped_pages;
|
||||
ULONG erase_count;
|
||||
ULONG obsolete_pages;
|
||||
ULONG min_block_erase = 0;
|
||||
ULONG min_block_erase_count = 0;
|
||||
ULONG min_block_obsolete_count = 0;
|
||||
ULONG min_block_mapped_count = 0;
|
||||
ULONG max_obsolete_pages = 0;
|
||||
ULONG max_obsolete_block = 0;
|
||||
ULONG max_obsolete_erase_count = 0;
|
||||
ULONG max_obsolete_mapped_count = 0;
|
||||
ULONG min_system_block_erase_count = 0;
|
||||
ULONG max_system_block_erase_count = 0;
|
||||
ULONG erase_count_threshold = 0;
|
||||
UINT status;
|
||||
|
||||
|
||||
/* Initialize the minimum erase count. */
|
||||
min_block_erase_count = LX_ALL_ONES;
|
||||
|
||||
/* Initialize the system minimum and maximum erase counts. */
|
||||
min_system_block_erase_count = LX_ALL_ONES;
|
||||
max_system_block_erase_count = 0;
|
||||
|
||||
/* Initialize the maximum obsolete page count. */
|
||||
max_obsolete_pages = 0;
|
||||
|
||||
/* Calculate the erase count threshold. */
|
||||
if (nand_flash -> lx_nand_flash_free_pages >= nand_flash -> lx_nand_flash_pages_per_block)
|
||||
{
|
||||
|
||||
/* Calculate erase count threshold by adding constant to the current minimum. */
|
||||
erase_count_threshold = nand_flash -> lx_nand_flash_minimum_erase_count + LX_NAND_FLASH_MAX_ERASE_COUNT_DELTA;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
/* When the number of free pages is low, simply pick the block that has the most number of obsolete sectors. */
|
||||
erase_count_threshold = LX_ALL_ONES;
|
||||
}
|
||||
|
||||
/* Set the block word pointer to the internal buffer. */
|
||||
block_word_ptr = nand_flash -> lx_nand_flash_page_buffer;
|
||||
|
||||
/* Loop through the blocks to attempt to find the block to erase. */
|
||||
for (block = 0; block < nand_flash -> lx_nand_flash_total_blocks; block++)
|
||||
{
|
||||
|
||||
/* First, check to see if 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 the error. */
|
||||
return(status);
|
||||
}
|
||||
|
||||
/* Determine if this block is bad. */
|
||||
if (block_status != LX_NAND_GOOD_BLOCK)
|
||||
{
|
||||
|
||||
/* Block is bad, move to the next block. */
|
||||
continue;
|
||||
}
|
||||
|
||||
/* Read page 0 of the block, the first word has the erase count. */
|
||||
status = _lx_nand_flash_driver_read(nand_flash, block, 0, block_word_ptr, (nand_flash -> lx_nand_flash_pages_per_block + 1));
|
||||
|
||||
/* 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 the error. */
|
||||
return(status);
|
||||
}
|
||||
}
|
||||
|
||||
/* Pickup the erase count from the first word of the block. */
|
||||
erase_count = block_word_ptr[0];
|
||||
|
||||
/* Update the system minimum and maximum erase counts. */
|
||||
if (erase_count < min_system_block_erase_count)
|
||||
min_system_block_erase_count = erase_count;
|
||||
if (erase_count > max_system_block_erase_count)
|
||||
max_system_block_erase_count = erase_count;
|
||||
|
||||
/* Compute the number of obsolete and mapped pages for this block. */
|
||||
obsolete_pages = 0;
|
||||
mapped_pages = 0;
|
||||
|
||||
/* Loop through the pages for this block. */
|
||||
for (page = 1; page < nand_flash -> lx_nand_flash_pages_per_block; page++)
|
||||
{
|
||||
|
||||
/* Read the logical sector mapping for this page. */
|
||||
status = _lx_nand_flash_driver_extra_bytes_get(nand_flash, block, page, (UCHAR *) &extra_info, sizeof(extra_info));
|
||||
|
||||
/* Check for an error from flash driver. */
|
||||
if (status)
|
||||
{
|
||||
|
||||
/* Call system error handler. */
|
||||
_lx_nand_flash_system_error(nand_flash, status, block, page);
|
||||
|
||||
/* Return the error. */
|
||||
return(status);
|
||||
}
|
||||
|
||||
/* Is this entry free? */
|
||||
if (extra_info.lx_nand_page_extra_info_logical_sector == LX_NAND_PAGE_FREE)
|
||||
{
|
||||
|
||||
/* Get out of the loop, we are done! */
|
||||
break;
|
||||
}
|
||||
|
||||
/* Is this entry obsolete? */
|
||||
else if ((extra_info.lx_nand_page_extra_info_logical_sector & LX_NAND_PAGE_VALID) == 0)
|
||||
{
|
||||
|
||||
/* Increment the number of obsolete pages. */
|
||||
obsolete_pages++;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
/* Increment the number of mapped pages. */
|
||||
mapped_pages++;
|
||||
}
|
||||
}
|
||||
|
||||
/* Determine if we have a block with a new maximum number of obsolete pages. */
|
||||
if ((obsolete_pages > max_obsolete_pages) && (erase_count <= erase_count_threshold))
|
||||
{
|
||||
|
||||
/* Update the new maximum obsolete pages and related information. */
|
||||
max_obsolete_pages = obsolete_pages;
|
||||
max_obsolete_block = block;
|
||||
max_obsolete_erase_count = erase_count;
|
||||
max_obsolete_mapped_count = mapped_pages;
|
||||
}
|
||||
else if ((max_obsolete_pages) && (obsolete_pages == max_obsolete_pages) && (erase_count <= erase_count_threshold))
|
||||
{
|
||||
|
||||
/* Another block has the same number of obsolete pages. Does this new block have a smaller erase
|
||||
count? */
|
||||
if (erase_count < max_obsolete_erase_count)
|
||||
{
|
||||
|
||||
/* Yes, choose the block with the smaller erase count. */
|
||||
max_obsolete_pages = obsolete_pages;
|
||||
max_obsolete_block = block;
|
||||
max_obsolete_erase_count = erase_count;
|
||||
max_obsolete_mapped_count = mapped_pages;
|
||||
}
|
||||
}
|
||||
|
||||
/* Determine if we have a new minimum erase count. */
|
||||
if (erase_count < min_block_erase_count)
|
||||
{
|
||||
|
||||
/* Update the new minimum erase count and related information. */
|
||||
min_block_erase_count = erase_count;
|
||||
min_block_erase = block;
|
||||
min_block_obsolete_count = obsolete_pages;
|
||||
min_block_mapped_count = mapped_pages;
|
||||
}
|
||||
}
|
||||
|
||||
/* Determine if we can erase the block with the most obsolete pages. */
|
||||
if (max_obsolete_pages)
|
||||
{
|
||||
|
||||
/* Erase the block with the most obsolete pages. */
|
||||
*return_erase_block = max_obsolete_block;
|
||||
*return_erase_count = max_obsolete_erase_count;
|
||||
*return_obsolete_pages = max_obsolete_pages;
|
||||
*return_mapped_pages = max_obsolete_mapped_count;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
/* Otherwise, erase the block with the smallest erase count. */
|
||||
*return_erase_block = min_block_erase;
|
||||
*return_erase_count = min_block_erase_count;
|
||||
*return_obsolete_pages = min_block_obsolete_count;
|
||||
*return_mapped_pages = min_block_mapped_count;
|
||||
}
|
||||
|
||||
/* Update the overall minimum and maximum erase count. */
|
||||
nand_flash -> lx_nand_flash_minimum_erase_count = min_system_block_erase_count;
|
||||
nand_flash -> lx_nand_flash_maximum_erase_count = max_system_block_erase_count;
|
||||
|
||||
/* Return success. */
|
||||
return(LX_SUCCESS);
|
||||
}
|
||||
|
||||
+53
-939
File diff suppressed because it is too large
Load Diff
@@ -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) Microsoft Corporation. All rights reserved. */
|
||||
/* */
|
||||
/* This software is licensed under the Microsoft Software License */
|
||||
/* Terms for Microsoft Azure RTOS. Full text of the license can be */
|
||||
/* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */
|
||||
/* and in the root directory of this software. */
|
||||
/* */
|
||||
/**************************************************************************/
|
||||
/***************************************************************************
|
||||
* Copyright (c) 2024 Microsoft Corporation
|
||||
* Copyright (c) 2026-present Eclipse ThreadX contributors
|
||||
*
|
||||
* This program and the accompanying materials are made available under the
|
||||
* terms of the MIT License which is available at
|
||||
* https://opensource.org/licenses/MIT.
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
**************************************************************************/
|
||||
|
||||
|
||||
/**************************************************************************/
|
||||
/**************************************************************************/
|
||||
/** */
|
||||
/** LevelX Component */
|
||||
/** */
|
||||
/** LevelX Component */
|
||||
/** */
|
||||
/** NAND Flash */
|
||||
/** */
|
||||
@@ -25,8 +25,8 @@
|
||||
|
||||
/* Disable ThreadX error checking. */
|
||||
|
||||
#ifndef TX_DISABLE_ERROR_CHECKING
|
||||
#define TX_DISABLE_ERROR_CHECKING
|
||||
#ifndef LX_DISABLE_ERROR_CHECKING
|
||||
#define LX_DISABLE_ERROR_CHECKING
|
||||
#endif
|
||||
|
||||
|
||||
@@ -35,44 +35,38 @@
|
||||
#include "lx_api.h"
|
||||
|
||||
|
||||
/**************************************************************************/
|
||||
/* */
|
||||
/* FUNCTION RELEASE */
|
||||
/* */
|
||||
/* _lx_nand_flash_page_ecc_check PORTABLE C */
|
||||
/* 6.0 */
|
||||
/**************************************************************************/
|
||||
/* */
|
||||
/* FUNCTION RELEASE */
|
||||
/* */
|
||||
/* _lx_nand_flash_page_ecc_check PORTABLE C */
|
||||
/* 6.1.7 */
|
||||
/* AUTHOR */
|
||||
/* */
|
||||
/* William E. Lamie, Microsoft Corporation */
|
||||
/* */
|
||||
/* 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 */
|
||||
/* DESCRIPTION */
|
||||
/* */
|
||||
/* 05-19-2020 William E. Lamie Initial Version 6.0 */
|
||||
/* 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 */
|
||||
/* */
|
||||
/**************************************************************************/
|
||||
UINT _lx_nand_flash_page_ecc_check(LX_NAND_FLASH *nand_flash, UCHAR *page_buffer, UCHAR *ecc_buffer)
|
||||
@@ -82,48 +76,48 @@ UINT bytes_checked;
|
||||
UINT status;
|
||||
UINT return_status = LX_SUCCESS;
|
||||
|
||||
|
||||
|
||||
/* Loop to check the entire NAND flash page. */
|
||||
bytes_checked = 0;
|
||||
while (bytes_checked < nand_flash -> lx_nand_flash_bytes_per_page)
|
||||
{
|
||||
|
||||
|
||||
/* Check this 256 byte piece of the NAND page. */
|
||||
status = _lx_nand_flash_256byte_ecc_check(page_buffer, ecc_buffer);
|
||||
|
||||
|
||||
/* Determine if there was an error. */
|
||||
if (status != LX_SUCCESS)
|
||||
{
|
||||
|
||||
|
||||
/* Determine if a non-correctable error is present. */
|
||||
if (status == LX_NAND_ERROR_NOT_CORRECTED)
|
||||
{
|
||||
|
||||
|
||||
/* Always return a non-correctable error, if present. */
|
||||
return_status = LX_NAND_ERROR_NOT_CORRECTED;
|
||||
return_status = LX_NAND_ERROR_NOT_CORRECTED;
|
||||
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. */
|
||||
else if (return_status == LX_SUCCESS)
|
||||
{
|
||||
|
||||
|
||||
/* Return a notice that the single bit error was corrected. */
|
||||
return_status = LX_NAND_ERROR_CORRECTED;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* Move to the next 256 byte portion of the page. */
|
||||
bytes_checked = bytes_checked + 256;
|
||||
|
||||
|
||||
/* Move the page buffer forward. */
|
||||
page_buffer = page_buffer + 256;
|
||||
|
||||
|
||||
/* Move the ECC buffer forward, note there are 3 bytes of ECC per page. */
|
||||
ecc_buffer = ecc_buffer + 3;
|
||||
}
|
||||
|
||||
|
||||
/* Return status. */
|
||||
return(return_status);
|
||||
}
|
||||
|
||||
@@ -1,19 +1,19 @@
|
||||
/**************************************************************************/
|
||||
/* */
|
||||
/* Copyright (c) Microsoft Corporation. All rights reserved. */
|
||||
/* */
|
||||
/* This software is licensed under the Microsoft Software License */
|
||||
/* Terms for Microsoft Azure RTOS. Full text of the license can be */
|
||||
/* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */
|
||||
/* and in the root directory of this software. */
|
||||
/* */
|
||||
/**************************************************************************/
|
||||
/***************************************************************************
|
||||
* Copyright (c) 2024 Microsoft Corporation
|
||||
* Copyright (c) 2026-present Eclipse ThreadX contributors
|
||||
*
|
||||
* This program and the accompanying materials are made available under the
|
||||
* terms of the MIT License which is available at
|
||||
* https://opensource.org/licenses/MIT.
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
**************************************************************************/
|
||||
|
||||
|
||||
/**************************************************************************/
|
||||
/**************************************************************************/
|
||||
/** */
|
||||
/** LevelX Component */
|
||||
/** */
|
||||
/** LevelX Component */
|
||||
/** */
|
||||
/** NAND Flash */
|
||||
/** */
|
||||
@@ -25,8 +25,8 @@
|
||||
|
||||
/* Disable ThreadX error checking. */
|
||||
|
||||
#ifndef TX_DISABLE_ERROR_CHECKING
|
||||
#define TX_DISABLE_ERROR_CHECKING
|
||||
#ifndef LX_DISABLE_ERROR_CHECKING
|
||||
#define LX_DISABLE_ERROR_CHECKING
|
||||
#endif
|
||||
|
||||
|
||||
@@ -35,43 +35,37 @@
|
||||
#include "lx_api.h"
|
||||
|
||||
|
||||
/**************************************************************************/
|
||||
/* */
|
||||
/* FUNCTION RELEASE */
|
||||
/* */
|
||||
/* _lx_nand_flash_page_ecc_compute PORTABLE C */
|
||||
/* 6.0 */
|
||||
/**************************************************************************/
|
||||
/* */
|
||||
/* FUNCTION RELEASE */
|
||||
/* */
|
||||
/* _lx_nand_flash_page_ecc_compute PORTABLE C */
|
||||
/* 6.1.7 */
|
||||
/* AUTHOR */
|
||||
/* */
|
||||
/* William E. Lamie, Microsoft Corporation */
|
||||
/* */
|
||||
/* 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 */
|
||||
/* DESCRIPTION */
|
||||
/* */
|
||||
/* 05-19-2020 William E. Lamie Initial Version 6.0 */
|
||||
/* 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 */
|
||||
/* */
|
||||
/**************************************************************************/
|
||||
UINT _lx_nand_flash_page_ecc_compute(LX_NAND_FLASH *nand_flash, UCHAR *page_buffer, UCHAR *ecc_buffer)
|
||||
@@ -79,25 +73,25 @@ UINT _lx_nand_flash_page_ecc_compute(LX_NAND_FLASH *nand_flash, UCHAR *page_buf
|
||||
|
||||
UINT bytes_computed;
|
||||
|
||||
|
||||
|
||||
/* Loop to compute the ECC over the entire NAND flash page. */
|
||||
bytes_computed = 0;
|
||||
while (bytes_computed < nand_flash -> lx_nand_flash_bytes_per_page)
|
||||
{
|
||||
|
||||
|
||||
/* Compute the ECC for this 256 byte piece of the page. */
|
||||
_lx_nand_flash_256byte_ecc_compute(page_buffer, ecc_buffer);
|
||||
|
||||
|
||||
/* Move to the next 256 byte portion of the page. */
|
||||
bytes_computed = bytes_computed + 256;
|
||||
|
||||
|
||||
/* Move the page buffer forward. */
|
||||
page_buffer = page_buffer + 256;
|
||||
|
||||
|
||||
/* Move the ECC buffer forward, note there are 3 bytes of ECC per page. */
|
||||
ecc_buffer = ecc_buffer + 3;
|
||||
}
|
||||
|
||||
|
||||
/* Return success. */
|
||||
return(LX_SUCCESS);
|
||||
}
|
||||
|
||||
@@ -1,19 +1,19 @@
|
||||
/**************************************************************************/
|
||||
/* */
|
||||
/* Copyright (c) Microsoft Corporation. All rights reserved. */
|
||||
/* */
|
||||
/* This software is licensed under the Microsoft Software License */
|
||||
/* Terms for Microsoft Azure RTOS. Full text of the license can be */
|
||||
/* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */
|
||||
/* and in the root directory of this software. */
|
||||
/* */
|
||||
/**************************************************************************/
|
||||
/***************************************************************************
|
||||
* Copyright (c) 2024 Microsoft Corporation
|
||||
* Copyright (c) 2026-present Eclipse ThreadX contributors
|
||||
*
|
||||
* This program and the accompanying materials are made available under the
|
||||
* terms of the MIT License which is available at
|
||||
* https://opensource.org/licenses/MIT.
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
**************************************************************************/
|
||||
|
||||
|
||||
/**************************************************************************/
|
||||
/**************************************************************************/
|
||||
/** */
|
||||
/** LevelX Component */
|
||||
/** */
|
||||
/** LevelX Component */
|
||||
/** */
|
||||
/** NAND Flash */
|
||||
/** */
|
||||
@@ -25,8 +25,8 @@
|
||||
|
||||
/* Disable ThreadX error checking. */
|
||||
|
||||
#ifndef TX_DISABLE_ERROR_CHECKING
|
||||
#define TX_DISABLE_ERROR_CHECKING
|
||||
#ifndef LX_DISABLE_ERROR_CHECKING
|
||||
#define LX_DISABLE_ERROR_CHECKING
|
||||
#endif
|
||||
|
||||
|
||||
@@ -35,89 +35,49 @@
|
||||
#include "lx_api.h"
|
||||
|
||||
|
||||
/**************************************************************************/
|
||||
/* */
|
||||
/* FUNCTION RELEASE */
|
||||
/* */
|
||||
/* _lx_nand_flash_partial_defragment PORTABLE C */
|
||||
/* 6.0 */
|
||||
/**************************************************************************/
|
||||
/* */
|
||||
/* FUNCTION RELEASE */
|
||||
/* */
|
||||
/* _lx_nand_flash_partial_defragment PORTABLE C */
|
||||
/* 6.2.1 */
|
||||
/* AUTHOR */
|
||||
/* */
|
||||
/* William E. Lamie, Microsoft Corporation */
|
||||
/* */
|
||||
/* 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 */
|
||||
/* */
|
||||
/* _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 */
|
||||
/* DESCRIPTION */
|
||||
/* */
|
||||
/* 05-19-2020 William E. Lamie Initial Version 6.0 */
|
||||
/* 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 */
|
||||
/* */
|
||||
/**************************************************************************/
|
||||
UINT _lx_nand_flash_partial_defragment(LX_NAND_FLASH *nand_flash, UINT max_blocks)
|
||||
{
|
||||
|
||||
ULONG i;
|
||||
|
||||
LX_PARAMETER_NOT_USED(nand_flash);
|
||||
LX_PARAMETER_NOT_USED(max_blocks);
|
||||
|
||||
#ifdef LX_THREAD_SAFE_ENABLE
|
||||
|
||||
/* Obtain the thread safe mutex. */
|
||||
tx_mutex_get(&nand_flash -> lx_nand_flash_mutex, TX_WAIT_FOREVER);
|
||||
#endif
|
||||
|
||||
/* Determine if the maximum number of blocks exceeds the total blocks in this flash instance. */
|
||||
if (max_blocks >= nand_flash -> lx_nand_flash_total_blocks)
|
||||
{
|
||||
|
||||
/* Adjust the maximum to the total number of blocks. */
|
||||
max_blocks = nand_flash -> lx_nand_flash_total_blocks;
|
||||
}
|
||||
|
||||
/* Loop for max number of blocks, while there are obsolete count. */
|
||||
for (i = 0; i < max_blocks; i++)
|
||||
{
|
||||
|
||||
/* Determine if there is any more defragment work. */
|
||||
if (nand_flash -> lx_nand_flash_obsolete_pages == 0)
|
||||
break;
|
||||
|
||||
/* Call the block reclaim function to defragment. */
|
||||
_lx_nand_flash_block_reclaim(nand_flash);
|
||||
}
|
||||
|
||||
#ifdef LX_THREAD_SAFE_ENABLE
|
||||
|
||||
/* Release the thread safe mutex. */
|
||||
tx_mutex_put(&nand_flash -> lx_nand_flash_mutex);
|
||||
#endif
|
||||
|
||||
/* Return successful completion. */
|
||||
return(LX_SUCCESS);
|
||||
/* Return not supported. */
|
||||
return(LX_NOT_SUPPORTED);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -1,392 +0,0 @@
|
||||
/**************************************************************************/
|
||||
/* */
|
||||
/* Copyright (c) Microsoft Corporation. All rights reserved. */
|
||||
/* */
|
||||
/* This software is licensed under the Microsoft Software License */
|
||||
/* Terms for Microsoft Azure RTOS. Full text of the license can be */
|
||||
/* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */
|
||||
/* and in the root directory of this software. */
|
||||
/* */
|
||||
/**************************************************************************/
|
||||
|
||||
|
||||
/**************************************************************************/
|
||||
/**************************************************************************/
|
||||
/** */
|
||||
/** LevelX Component */
|
||||
/** */
|
||||
/** NAND Flash */
|
||||
/** */
|
||||
/**************************************************************************/
|
||||
/**************************************************************************/
|
||||
|
||||
#define LX_SOURCE_CODE
|
||||
|
||||
|
||||
/* Disable ThreadX error checking. */
|
||||
|
||||
#ifndef TX_DISABLE_ERROR_CHECKING
|
||||
#define TX_DISABLE_ERROR_CHECKING
|
||||
#endif
|
||||
|
||||
|
||||
/* Include necessary system files. */
|
||||
|
||||
#include "lx_api.h"
|
||||
|
||||
|
||||
/**************************************************************************/
|
||||
/* */
|
||||
/* FUNCTION RELEASE */
|
||||
/* */
|
||||
/* _lx_nand_flash_physical_page_allocate PORTABLE C */
|
||||
/* 6.0 */
|
||||
/* AUTHOR */
|
||||
/* */
|
||||
/* William E. Lamie, Microsoft Corporation */
|
||||
/* */
|
||||
/* DESCRIPTION */
|
||||
/* */
|
||||
/* This function allocates a free page for mapping to a */
|
||||
/* logical sector. */
|
||||
/* */
|
||||
/* INPUT */
|
||||
/* */
|
||||
/* nand_flash NAND flash instance */
|
||||
/* block Destination for block */
|
||||
/* page Destination for page */
|
||||
/* erase_count Destination for erase count */
|
||||
/* */
|
||||
/* OUTPUT */
|
||||
/* */
|
||||
/* return status */
|
||||
/* */
|
||||
/* CALLS */
|
||||
/* */
|
||||
/* _lx_nand_flash_driver_extra_bytes_get Driver get extra bytes */
|
||||
/* _lx_nand_flash_driver_extra_bytes_set Driver set extra bytes */
|
||||
/* _lx_nand_flash_driver_block_status_get */
|
||||
/* Driver block status get */
|
||||
/* _lx_nand_flash_driver_page_erased_verify */
|
||||
/* Driver verify page erased */
|
||||
/* _lx_nand_flash_driver_read Driver page read */
|
||||
/* _lx_nand_flash_block_full_update Update page 0 with list of */
|
||||
/* mapped pages */
|
||||
/* _lx_nand_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 */
|
||||
/* */
|
||||
/**************************************************************************/
|
||||
UINT _lx_nand_flash_physical_page_allocate(LX_NAND_FLASH *nand_flash, ULONG *block, ULONG *page, ULONG *erase_count)
|
||||
{
|
||||
|
||||
LX_NAND_PAGE_EXTRA_INFO extra_info;
|
||||
UCHAR block_status;
|
||||
ULONG search_block;
|
||||
ULONG search_page;
|
||||
ULONG *word_ptr;
|
||||
ULONG i, j;
|
||||
UINT status;
|
||||
|
||||
|
||||
/* Increment the number of page allocation requests. */
|
||||
nand_flash -> lx_nand_flash_diagnostic_page_allocates++;
|
||||
|
||||
/* Initialize the return parameters. */
|
||||
*block = (ULONG) 0;
|
||||
*page = (ULONG) 0;
|
||||
*erase_count = nand_flash -> lx_nand_flash_minimum_erase_count;
|
||||
|
||||
/* Determine if there are any free pages. */
|
||||
if (nand_flash -> lx_nand_flash_free_pages == 0)
|
||||
{
|
||||
|
||||
/* Increment the number of failed allocations. */
|
||||
nand_flash -> lx_nand_flash_diagnostic_page_allocate_errors++;
|
||||
|
||||
/* No free pages, return . */
|
||||
return(LX_NO_PAGES);
|
||||
}
|
||||
|
||||
/* Pickup the search for a free page at the specified block. */
|
||||
search_block = nand_flash -> lx_nand_flash_free_block_search;
|
||||
|
||||
/* Loop through the blocks to find a free page. */
|
||||
for (i = 0; i < nand_flash -> lx_nand_flash_total_blocks; i++)
|
||||
{
|
||||
|
||||
/* First, check to see if this block is good. */
|
||||
status = _lx_nand_flash_driver_block_status_get(nand_flash, search_block, &block_status);
|
||||
|
||||
/* Check for an error from flash driver. */
|
||||
if (status)
|
||||
{
|
||||
|
||||
/* Call system error handler. */
|
||||
_lx_nand_flash_system_error(nand_flash, status, search_block, 0);
|
||||
|
||||
/* Return the error. */
|
||||
return(status);
|
||||
}
|
||||
|
||||
/* Determine if this block is bad. */
|
||||
if (block_status != LX_NAND_GOOD_BLOCK)
|
||||
{
|
||||
|
||||
/* Move to next search block. */
|
||||
search_block++;
|
||||
|
||||
/* Have we wrapped around yet? */
|
||||
if (search_block >= nand_flash -> lx_nand_flash_total_blocks)
|
||||
{
|
||||
|
||||
/* Reset the search block to the beginning. */
|
||||
search_block = 0;
|
||||
}
|
||||
|
||||
/* Block is bad, move to the next block. */
|
||||
continue;
|
||||
}
|
||||
|
||||
/* Read the extra bytes of page 0. This will tell us if the page has any free entries. */
|
||||
status = _lx_nand_flash_driver_extra_bytes_get(nand_flash, search_block, 0, (UCHAR *) &extra_info, sizeof(extra_info));
|
||||
|
||||
/* Check for an error from flash driver. */
|
||||
if (status)
|
||||
{
|
||||
|
||||
/* Call system error handler. */
|
||||
_lx_nand_flash_system_error(nand_flash, status, search_block, 0);
|
||||
|
||||
/* Return the error... no point in continuing. */
|
||||
return(status);
|
||||
}
|
||||
|
||||
/* Determine if there are any free entries. */
|
||||
if ((extra_info.lx_nand_page_extra_info_logical_sector & LX_NAND_BLOCK_FULL) == 0)
|
||||
{
|
||||
|
||||
/* This block is full... go to the next block. */
|
||||
search_block++;
|
||||
|
||||
/* Have we wrapped around yet? */
|
||||
if (search_block >= nand_flash -> lx_nand_flash_total_blocks)
|
||||
{
|
||||
|
||||
/* Reset the search block to the beginning. */
|
||||
search_block = 0;
|
||||
}
|
||||
|
||||
/* Block is bad, move to the next block. */
|
||||
continue;
|
||||
}
|
||||
|
||||
/* Now check to see if page 0 has been written to. When the block is full, page 0 is written with the mapping of pages
|
||||
to logical sectors in this block - only when the block becomes full. If the block has additional pages free, page 0 is all 0xFFs. */
|
||||
status = _lx_nand_flash_driver_read(nand_flash, search_block, 0, nand_flash -> lx_nand_flash_page_buffer, nand_flash -> lx_nand_flash_words_per_page);
|
||||
|
||||
/* Check for an error... an error here indicates the block does not have any free pages. */
|
||||
if (status)
|
||||
{
|
||||
|
||||
/* Call system error handler. */
|
||||
_lx_nand_flash_system_error(nand_flash, status, search_block, 0);
|
||||
|
||||
/* Determine if the error is fatal. */
|
||||
if (status != LX_NAND_ERROR_CORRECTED)
|
||||
{
|
||||
|
||||
/* Return the error. */
|
||||
return(status);
|
||||
}
|
||||
}
|
||||
|
||||
/* Setup pointer to the page 0 data. */
|
||||
word_ptr = nand_flash -> lx_nand_flash_page_buffer;
|
||||
|
||||
/* Pickup the block erase count (first word in the page 0 data area). */
|
||||
if (*word_ptr != LX_ALL_ONES)
|
||||
*erase_count = *word_ptr;
|
||||
|
||||
/* Now determine if the remaining words are all ones, i.e. haven't been written to. */
|
||||
j = 1;
|
||||
while (j < (nand_flash -> lx_nand_flash_pages_per_block + 1))
|
||||
{
|
||||
|
||||
/* Has this word been written to? */
|
||||
if (word_ptr[j] != LX_ALL_ONES)
|
||||
break;
|
||||
|
||||
/* Move to next word. */
|
||||
j++;
|
||||
}
|
||||
|
||||
/* Does this block have any free pages? */
|
||||
if (j < (nand_flash -> lx_nand_flash_pages_per_block + 1))
|
||||
{
|
||||
|
||||
/* Move to next search block. */
|
||||
search_block++;
|
||||
|
||||
/* Have we wrapped around yet? */
|
||||
if (search_block >= nand_flash -> lx_nand_flash_total_blocks)
|
||||
{
|
||||
|
||||
/* Reset the search block to the beginning. */
|
||||
search_block = 0;
|
||||
}
|
||||
|
||||
/* No, the data area has been written to. Simply move to the next block. */
|
||||
continue;
|
||||
}
|
||||
|
||||
/* Now search for an available page within the block. */
|
||||
search_page = 1;
|
||||
while (search_page < nand_flash -> lx_nand_flash_pages_per_block)
|
||||
{
|
||||
|
||||
/* Read the extra information for this page to see if there is a sector mapping. */
|
||||
status = _lx_nand_flash_driver_extra_bytes_get(nand_flash, search_block, search_page, (UCHAR *) &extra_info, sizeof(extra_info));
|
||||
|
||||
/* Check for an error from flash driver. */
|
||||
if (status)
|
||||
{
|
||||
|
||||
/* Call system error handler. */
|
||||
_lx_nand_flash_system_error(nand_flash, status, search_block, search_page);
|
||||
|
||||
/* Return the error. */
|
||||
return(status);
|
||||
}
|
||||
|
||||
/* Now determine if this page is mapped or free. */
|
||||
if (extra_info.lx_nand_page_extra_info_logical_sector == LX_NAND_PAGE_FREE)
|
||||
{
|
||||
|
||||
/* Now make sure the data area of this page is free. */
|
||||
status = _lx_nand_flash_driver_page_erased_verify(nand_flash, search_block, search_page);
|
||||
|
||||
/* Is the page free? */
|
||||
if (status != LX_SUCCESS)
|
||||
{
|
||||
|
||||
/* No, the page is not actually free. For now, simply mark the extra info area to indicate
|
||||
the page is not available and continue our search. */
|
||||
extra_info.lx_nand_page_extra_info_logical_sector = 0;
|
||||
|
||||
/* Decrease the number of free pages. */
|
||||
nand_flash -> lx_nand_flash_free_pages--;
|
||||
|
||||
/* Increase the number of obsolete pages. */
|
||||
nand_flash -> lx_nand_flash_obsolete_pages++;
|
||||
|
||||
/* Write out the extra info for this page. */
|
||||
status = _lx_nand_flash_driver_extra_bytes_set(nand_flash, search_block, search_page, (UCHAR *) &extra_info, sizeof(extra_info));
|
||||
|
||||
/* Check for an error from flash driver. */
|
||||
if (status)
|
||||
{
|
||||
|
||||
/* Call system error handler. */
|
||||
_lx_nand_flash_system_error(nand_flash, status, search_block, search_page);
|
||||
|
||||
/* Return the error. */
|
||||
return(status);
|
||||
}
|
||||
|
||||
/* Determine if this is the last entry of the block. */
|
||||
if (search_page == (nand_flash -> lx_nand_flash_pages_per_block - 1))
|
||||
{
|
||||
|
||||
/* Yes, we need to update page 0 of the block with the list of mapped
|
||||
pages for this block. */
|
||||
_lx_nand_flash_block_full_update(nand_flash, search_block, *erase_count);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
/* Yes, we have found a free page in this block. Get out of the page search loop. */
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/* Move to next search page. */
|
||||
search_page++;
|
||||
}
|
||||
|
||||
/* Determine if we have found the free block. */
|
||||
if (search_page < nand_flash -> lx_nand_flash_pages_per_block)
|
||||
{
|
||||
|
||||
/* Remember the block to search. */
|
||||
nand_flash -> lx_nand_flash_free_block_search = search_block;
|
||||
|
||||
/* Determine if the allocated page is the last one in this block. */
|
||||
if (search_page == (nand_flash -> lx_nand_flash_pages_per_block - 1))
|
||||
{
|
||||
|
||||
/* Yes, move to the next block. */
|
||||
nand_flash -> lx_nand_flash_free_block_search++;
|
||||
|
||||
/* Have we wrapped around yet? */
|
||||
if (nand_flash -> lx_nand_flash_free_block_search >= nand_flash -> lx_nand_flash_total_blocks)
|
||||
{
|
||||
|
||||
/* Wrap condition - reset the search block to the beginning. */
|
||||
nand_flash -> lx_nand_flash_free_block_search = 0;
|
||||
}
|
||||
}
|
||||
|
||||
/* Prepare the return information. */
|
||||
*block = search_block;
|
||||
*page = search_page;
|
||||
|
||||
/* Determine if this is the first data page of the block. */
|
||||
if (search_page == 1)
|
||||
{
|
||||
|
||||
/* Yes, we need to update the extra bytes of page 0 to indicate the block is no longer empty. */
|
||||
extra_info.lx_nand_page_extra_info_logical_sector = ((ULONG) LX_NAND_PAGE_FREE) & ~((ULONG) LX_NAND_BLOCK_EMPTY);
|
||||
status = _lx_nand_flash_driver_extra_bytes_set(nand_flash, search_block, 0, (UCHAR *) &extra_info, sizeof(extra_info));
|
||||
|
||||
/* Check for an error from flash driver. */
|
||||
if (status)
|
||||
{
|
||||
|
||||
/* Call system error handler. */
|
||||
_lx_nand_flash_system_error(nand_flash, status, search_block, 0);
|
||||
}
|
||||
}
|
||||
|
||||
/* Return success! */
|
||||
return(LX_SUCCESS);
|
||||
}
|
||||
|
||||
/* Move to next search block. */
|
||||
search_block++;
|
||||
|
||||
/* Have we wrapped around yet? */
|
||||
if (search_block >= nand_flash -> lx_nand_flash_total_blocks)
|
||||
{
|
||||
|
||||
/* Reset the search block to the beginning. */
|
||||
search_block = 0;
|
||||
}
|
||||
}
|
||||
|
||||
/* Increment the number of failed allocations. */
|
||||
nand_flash -> lx_nand_flash_diagnostic_page_allocate_errors++;
|
||||
|
||||
/* Return error. */
|
||||
return(LX_NO_PAGES);
|
||||
}
|
||||
|
||||
@@ -1,150 +0,0 @@
|
||||
/**************************************************************************/
|
||||
/* */
|
||||
/* Copyright (c) Microsoft Corporation. All rights reserved. */
|
||||
/* */
|
||||
/* This software is licensed under the Microsoft Software License */
|
||||
/* Terms for Microsoft Azure RTOS. Full text of the license can be */
|
||||
/* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */
|
||||
/* and in the root directory of this software. */
|
||||
/* */
|
||||
/**************************************************************************/
|
||||
|
||||
|
||||
/**************************************************************************/
|
||||
/**************************************************************************/
|
||||
/** */
|
||||
/** LevelX Component */
|
||||
/** */
|
||||
/** NAND Flash */
|
||||
/** */
|
||||
/**************************************************************************/
|
||||
/**************************************************************************/
|
||||
|
||||
#define LX_SOURCE_CODE
|
||||
|
||||
|
||||
/* Disable ThreadX error checking. */
|
||||
|
||||
#ifndef TX_DISABLE_ERROR_CHECKING
|
||||
#define TX_DISABLE_ERROR_CHECKING
|
||||
#endif
|
||||
|
||||
|
||||
/* Include necessary system files. */
|
||||
|
||||
#include "lx_api.h"
|
||||
|
||||
|
||||
/**************************************************************************/
|
||||
/* */
|
||||
/* FUNCTION RELEASE */
|
||||
/* */
|
||||
/* _lx_nand_flash_sector_mapping_cache_invalidate PORTABLE C */
|
||||
/* 6.0 */
|
||||
/* AUTHOR */
|
||||
/* */
|
||||
/* William E. Lamie, Microsoft Corporation */
|
||||
/* */
|
||||
/* DESCRIPTION */
|
||||
/* */
|
||||
/* This function invalidates the sector's entry in the NAND flash */
|
||||
/* cache. */
|
||||
/* */
|
||||
/* INPUT */
|
||||
/* */
|
||||
/* nand_flash NAND 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 */
|
||||
/* */
|
||||
/**************************************************************************/
|
||||
VOID _lx_nand_flash_sector_mapping_cache_invalidate(LX_NAND_FLASH *nand_flash, ULONG logical_sector)
|
||||
{
|
||||
|
||||
#ifndef LX_NAND_FLASH_DIRECT_MAPPING_CACHE
|
||||
ULONG i;
|
||||
LX_NAND_SECTOR_MAPPING_CACHE_ENTRY *sector_mapping_cache_entry_ptr;
|
||||
#endif
|
||||
|
||||
/* Determine if the sector mapping cache is enabled. */
|
||||
if (nand_flash -> lx_nand_flash_sector_mapping_cache_enabled)
|
||||
{
|
||||
|
||||
#ifndef LX_NAND_FLASH_DIRECT_MAPPING_CACHE
|
||||
|
||||
/* Calculate the starting index of the sector mapping cache for this sector entry. */
|
||||
i = (logical_sector & LX_NAND_SECTOR_MAPPING_CACHE_HASH_MASK) * LX_NAND_SECTOR_MAPPING_CACHE_DEPTH;
|
||||
|
||||
/* Build a pointer to the cache entry. */
|
||||
sector_mapping_cache_entry_ptr = &nand_flash -> lx_nand_flash_sector_mapping_cache[i];
|
||||
|
||||
/* Determine if the sector is in the sector mapping cache - assuming the depth of the sector
|
||||
mapping cache is LX_NAND_SECTOR_MAPPING_CACHE_DEPTH entries. */
|
||||
if ((sector_mapping_cache_entry_ptr -> lx_nand_sector_mapping_cache_logical_sector) == (logical_sector | LX_NAND_SECTOR_MAPPING_CACHE_ENTRY_VALID))
|
||||
{
|
||||
|
||||
/* Move all cache entries up and invalidate the last entry. */
|
||||
*(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 + 2) = *(sector_mapping_cache_entry_ptr + 3);
|
||||
|
||||
/* Invalidate the last entry. */
|
||||
(sector_mapping_cache_entry_ptr + 3) -> lx_nand_sector_mapping_cache_logical_sector = 0;
|
||||
}
|
||||
else if (((sector_mapping_cache_entry_ptr + 1) -> lx_nand_sector_mapping_cache_logical_sector) == (logical_sector | LX_NAND_SECTOR_MAPPING_CACHE_ENTRY_VALID))
|
||||
{
|
||||
|
||||
/* 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 + 2) = *(sector_mapping_cache_entry_ptr + 3);
|
||||
|
||||
/* Invalidate the last entry. */
|
||||
(sector_mapping_cache_entry_ptr + 3) -> lx_nand_sector_mapping_cache_logical_sector = 0;
|
||||
}
|
||||
else if (((sector_mapping_cache_entry_ptr + 2) -> lx_nand_sector_mapping_cache_logical_sector) == (logical_sector | LX_NAND_SECTOR_MAPPING_CACHE_ENTRY_VALID))
|
||||
{
|
||||
|
||||
/* Move all subsequent cache entries up and invalidate the last entry. */
|
||||
*(sector_mapping_cache_entry_ptr + 2) = *(sector_mapping_cache_entry_ptr + 3);
|
||||
|
||||
/* Invalidate the last entry. */
|
||||
(sector_mapping_cache_entry_ptr + 3) -> lx_nand_sector_mapping_cache_logical_sector = 0;
|
||||
}
|
||||
else if (((sector_mapping_cache_entry_ptr + 3) -> lx_nand_sector_mapping_cache_logical_sector) == (logical_sector | LX_NAND_SECTOR_MAPPING_CACHE_ENTRY_VALID))
|
||||
{
|
||||
|
||||
/* Simply invalidate the last entry. */
|
||||
(sector_mapping_cache_entry_ptr + 3) -> lx_nand_sector_mapping_cache_logical_sector = 0;
|
||||
}
|
||||
#else
|
||||
|
||||
/* Direct mapping cache is defined. */
|
||||
|
||||
/* Determine if this logical sector fits in the logical sector cache mapping. */
|
||||
if (logical_sector < LX_NAND_SECTOR_MAPPING_CACHE_SIZE)
|
||||
{
|
||||
|
||||
/* Yes, invalidate the logical sector cache. */
|
||||
nand_flash -> lx_nand_flash_sector_mapping_cache[logical_sector].lx_nand_sector_mapping_cache_block = 0;
|
||||
nand_flash -> lx_nand_flash_sector_mapping_cache[logical_sector].lx_nand_sector_mapping_cache_page = 0;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,19 +1,20 @@
|
||||
/**************************************************************************/
|
||||
/* */
|
||||
/* Copyright (c) Microsoft Corporation. All rights reserved. */
|
||||
/* */
|
||||
/* This software is licensed under the Microsoft Software License */
|
||||
/* Terms for Microsoft Azure RTOS. Full text of the license can be */
|
||||
/* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */
|
||||
/* and in the root directory of this software. */
|
||||
/* */
|
||||
/**************************************************************************/
|
||||
/***************************************************************************
|
||||
* 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 */
|
||||
/** */
|
||||
/** LevelX Component */
|
||||
/** */
|
||||
/** NAND Flash */
|
||||
/** */
|
||||
@@ -25,8 +26,8 @@
|
||||
|
||||
/* Disable ThreadX error checking. */
|
||||
|
||||
#ifndef TX_DISABLE_ERROR_CHECKING
|
||||
#define TX_DISABLE_ERROR_CHECKING
|
||||
#ifndef LX_DISABLE_ERROR_CHECKING
|
||||
#define LX_DISABLE_ERROR_CHECKING
|
||||
#endif
|
||||
|
||||
|
||||
@@ -35,60 +36,56 @@
|
||||
#include "lx_api.h"
|
||||
|
||||
|
||||
/**************************************************************************/
|
||||
/* */
|
||||
/* FUNCTION RELEASE */
|
||||
/* */
|
||||
/* _lx_nand_flash_sector_read PORTABLE C */
|
||||
/* 6.0 */
|
||||
/**************************************************************************/
|
||||
/* */
|
||||
/* FUNCTION RELEASE */
|
||||
/* */
|
||||
/* _lx_nand_flash_sector_read PORTABLE C */
|
||||
/* 6.2.1 */
|
||||
/* AUTHOR */
|
||||
/* */
|
||||
/* William E. Lamie, Microsoft Corporation */
|
||||
/* Xiuwen Cai, Microsoft Corporation */
|
||||
/* */
|
||||
/* 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_driver_read Driver page read */
|
||||
/* _lx_nand_flash_logical_sector_find Find logical sector */
|
||||
/* _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 */
|
||||
/* DESCRIPTION */
|
||||
/* */
|
||||
/* 05-19-2020 William E. Lamie Initial Version 6.0 */
|
||||
/* 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 status;
|
||||
ULONG found_block;
|
||||
ULONG found_page;
|
||||
ULONG i;
|
||||
ULONG *word_ptr;
|
||||
|
||||
ULONG block;
|
||||
USHORT block_status;
|
||||
UCHAR *spare_buffer_ptr;
|
||||
ULONG available_pages;
|
||||
LONG page;
|
||||
|
||||
#ifdef LX_THREAD_SAFE_ENABLE
|
||||
|
||||
@@ -100,67 +97,227 @@ ULONG *word_ptr;
|
||||
nand_flash -> lx_nand_flash_diagnostic_sector_read_requests++;
|
||||
|
||||
/* See if we can find the sector in the current mapping. */
|
||||
_lx_nand_flash_logical_sector_find(nand_flash, logical_sector, LX_FALSE, &found_block, &found_page);
|
||||
|
||||
/* Determine if the logical sector mapping was found. */
|
||||
if (found_page)
|
||||
{
|
||||
|
||||
/* Yes, we were able to find the logical sector to page mapping. */
|
||||
|
||||
/* Read the data from the page. */
|
||||
status = _lx_nand_flash_driver_read(nand_flash, found_block, found_page, buffer, nand_flash -> lx_nand_flash_words_per_page);
|
||||
status = _lx_nand_flash_block_find(nand_flash, logical_sector, &block, &block_status);
|
||||
|
||||
/* Check for an error from flash driver. */
|
||||
if (status)
|
||||
/* Check return status. */
|
||||
if (status != LX_SUCCESS)
|
||||
{
|
||||
|
||||
/* 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)
|
||||
{
|
||||
|
||||
/* Call system error handler. */
|
||||
_lx_nand_flash_system_error(nand_flash, status, found_block, found_page);
|
||||
|
||||
/* Determine if the error was corrected. */
|
||||
if (status == LX_NAND_ERROR_CORRECTED)
|
||||
#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);
|
||||
}
|
||||
}
|
||||
|
||||
/* Determine if the block is mapped. */
|
||||
if (block != LX_NAND_BLOCK_UNMAPPED)
|
||||
{
|
||||
|
||||
/* Setup spare buffer pointer. */
|
||||
spare_buffer_ptr = (UCHAR*)nand_flash -> lx_nand_flash_page_buffer;
|
||||
|
||||
/* Get available pages in this block. */
|
||||
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;
|
||||
|
||||
/* Determine if the pages are recorded sequentially. */
|
||||
if (block_status & LX_NAND_BLOCK_STATUS_NON_SEQUENTIAL)
|
||||
{
|
||||
|
||||
/* Loop to search the logical page. */
|
||||
for (page = (LONG)available_pages - 1; page >= 0; page--)
|
||||
{
|
||||
|
||||
/* Yes, we were able to read this page successfully with error correction. */
|
||||
|
||||
/* Change the status to LX_SUCCESS. */
|
||||
status = LX_SUCCESS;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
/* Adjust return status. */
|
||||
status = LX_ERROR;
|
||||
|
||||
/* Read a page. */
|
||||
#ifdef LX_NAND_ENABLE_CONTROL_BLOCK_FOR_DRIVER_INTERFACE
|
||||
status = (nand_flash -> lx_nand_flash_driver_pages_read)(nand_flash, block, (ULONG)page, (UCHAR*)NULL, spare_buffer_ptr, 1);
|
||||
#else
|
||||
status = (nand_flash -> lx_nand_flash_driver_pages_read)(block, (ULONG)page, (UCHAR*)NULL, 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);
|
||||
#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);
|
||||
}
|
||||
|
||||
/* 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)
|
||||
{
|
||||
#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
|
||||
|
||||
/* Release the thread safe mutex. */
|
||||
tx_mutex_put(&nand_flash -> lx_nand_flash_mutex);
|
||||
#endif
|
||||
/* Return successful completion. */
|
||||
return(LX_SUCCESS);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
/* Set the status to success. */
|
||||
status = LX_SUCCESS;
|
||||
/* Check if the logical sector is available. */
|
||||
if (logical_sector % nand_flash -> lx_nand_flash_pages_per_block < available_pages)
|
||||
{
|
||||
|
||||
/* Read a page. */
|
||||
#ifdef LX_NAND_ENABLE_CONTROL_BLOCK_FOR_DRIVER_INTERFACE
|
||||
status = (nand_flash -> lx_nand_flash_driver_pages_read)(nand_flash, block, logical_sector % nand_flash -> lx_nand_flash_pages_per_block, (UCHAR*)buffer, spare_buffer_ptr, 1);
|
||||
#else
|
||||
status = (nand_flash -> lx_nand_flash_driver_pages_read)(block, logical_sector % nand_flash -> lx_nand_flash_pages_per_block, (UCHAR*)buffer, 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);
|
||||
|
||||
#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
|
||||
|
||||
/* Release the thread safe mutex. */
|
||||
tx_mutex_put(&nand_flash -> lx_nand_flash_mutex);
|
||||
#endif
|
||||
/* Return successful completion. */
|
||||
return(LX_SUCCESS);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
|
||||
#ifdef LX_NAND_FLASH_ENABLE_LAZY_SECTOR_RELEASE
|
||||
{
|
||||
|
||||
/* Sector hasn't been written. Simply fill the destination buffer with ones and return success. */
|
||||
|
||||
/* Setup pointer to users buffer. */
|
||||
word_ptr = (ULONG *) buffer;
|
||||
|
||||
/* Put all ones in he buffer. */
|
||||
for (i = 0; i < nand_flash -> lx_nand_flash_words_per_page; i++)
|
||||
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--)
|
||||
{
|
||||
|
||||
/* Copy a word. */
|
||||
*word_ptr++ = LX_ALL_ONES;
|
||||
}
|
||||
|
||||
/* Set the status to success. */
|
||||
status = LX_SUCCESS;
|
||||
#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. */
|
||||
|
||||
/* Setup pointer to users buffer. */
|
||||
word_ptr = (ULONG *) buffer;
|
||||
|
||||
/* Put all ones in he buffer. */
|
||||
for (i = 0; i < nand_flash -> lx_nand_flash_words_per_page; i++)
|
||||
{
|
||||
|
||||
/* Copy a word. */
|
||||
*word_ptr++ = LX_ALL_ONES;
|
||||
}
|
||||
|
||||
/* Set the status to success. */
|
||||
status = LX_SUCCESS;
|
||||
|
||||
#ifdef LX_THREAD_SAFE_ENABLE
|
||||
|
||||
/* Release the thread safe mutex. */
|
||||
|
||||
@@ -1,19 +1,20 @@
|
||||
/**************************************************************************/
|
||||
/* */
|
||||
/* Copyright (c) Microsoft Corporation. All rights reserved. */
|
||||
/* */
|
||||
/* This software is licensed under the Microsoft Software License */
|
||||
/* Terms for Microsoft Azure RTOS. Full text of the license can be */
|
||||
/* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */
|
||||
/* and in the root directory of this software. */
|
||||
/* */
|
||||
/**************************************************************************/
|
||||
/***************************************************************************
|
||||
* 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 */
|
||||
/** */
|
||||
/** LevelX Component */
|
||||
/** */
|
||||
/** NAND Flash */
|
||||
/** */
|
||||
@@ -25,8 +26,8 @@
|
||||
|
||||
/* Disable ThreadX error checking. */
|
||||
|
||||
#ifndef TX_DISABLE_ERROR_CHECKING
|
||||
#define TX_DISABLE_ERROR_CHECKING
|
||||
#ifndef LX_DISABLE_ERROR_CHECKING
|
||||
#define LX_DISABLE_ERROR_CHECKING
|
||||
#endif
|
||||
|
||||
|
||||
@@ -35,66 +36,66 @@
|
||||
#include "lx_api.h"
|
||||
|
||||
|
||||
/**************************************************************************/
|
||||
/* */
|
||||
/* FUNCTION RELEASE */
|
||||
/* */
|
||||
/* _lx_nand_flash_sector_release PORTABLE C */
|
||||
/* 6.0 */
|
||||
/**************************************************************************/
|
||||
/* */
|
||||
/* FUNCTION RELEASE */
|
||||
/* */
|
||||
/* _lx_nand_flash_sector_release PORTABLE C */
|
||||
/* 6.2.1 */
|
||||
/* AUTHOR */
|
||||
/* */
|
||||
/* William E. Lamie, Microsoft Corporation */
|
||||
/* Xiuwen Cai, Microsoft Corporation */
|
||||
/* */
|
||||
/* DESCRIPTION */
|
||||
/* */
|
||||
/* This function releases a logical sector from being managed in the */
|
||||
/* NAND flash. */
|
||||
/* */
|
||||
/* INPUT */
|
||||
/* */
|
||||
/* nand_flash NAND flash instance */
|
||||
/* logical_sector Logical sector number */
|
||||
/* */
|
||||
/* OUTPUT */
|
||||
/* */
|
||||
/* return status */
|
||||
/* */
|
||||
/* CALLS */
|
||||
/* */
|
||||
/* _lx_nand_flash_driver_read Driver flash sector read */
|
||||
/* _lx_nand_flash_driver_write Driver flash sector write */
|
||||
/* _lx_nand_flash_driver_extra_bytes_get Get extra bytes from spare */
|
||||
/* _lx_nand_flash_driver_extra_bytes_set Set extra bytes in spare */
|
||||
/* _lx_nand_flash_block_obsoleted_check Check for block obsoleted */
|
||||
/* _lx_nand_flash_block_reclaim Reclaim one flash block */
|
||||
/* _lx_nand_flash_sector_mapping_cache_invalidate */
|
||||
/* Invalidate cache entry */
|
||||
/* _lx_nand_flash_logical_sector_find Find logical sector */
|
||||
/* _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 */
|
||||
/* DESCRIPTION */
|
||||
/* */
|
||||
/* 05-19-2020 William E. Lamie Initial Version 6.0 */
|
||||
/* This function releases a logical sector from being managed in the */
|
||||
/* NAND flash. */
|
||||
/* */
|
||||
/* INPUT */
|
||||
/* */
|
||||
/* nand_flash NAND flash instance */
|
||||
/* logical_sector Logical sector number */
|
||||
/* */
|
||||
/* OUTPUT */
|
||||
/* */
|
||||
/* return status */
|
||||
/* */
|
||||
/* CALLS */
|
||||
/* */
|
||||
/* _lx_nand_flash_block_find Find the mapped block */
|
||||
/* lx_nand_flash_driver_pages_read Read pages */
|
||||
/* _lx_nand_flash_block_allocate Allocate block */
|
||||
/* _lx_nand_flash_mapped_block_list_remove */
|
||||
/* Remove mapped block */
|
||||
/* _lx_nand_flash_data_page_copy Copy data pages */
|
||||
/* _lx_nand_flash_free_block_list_add Add free block to list */
|
||||
/* _lx_nand_flash_block_mapping_set Set block mapping */
|
||||
/* _lx_nand_flash_driver_block_erase Erase block */
|
||||
/* _lx_nand_flash_erase_count_set Set erase count */
|
||||
/* _lx_nand_flash_block_data_move Move block data */
|
||||
/* _lx_nand_flash_block_status_set Set block status */
|
||||
/* _lx_nand_flash_mapped_block_list_add Add mapped block to list */
|
||||
/* _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_release(LX_NAND_FLASH *nand_flash, ULONG logical_sector)
|
||||
{
|
||||
|
||||
LX_NAND_PAGE_EXTRA_INFO extra_info;
|
||||
UINT status;
|
||||
ULONG found_block;
|
||||
ULONG found_page;
|
||||
ULONG *block_word_ptr;
|
||||
ULONG i;
|
||||
|
||||
UINT status;
|
||||
ULONG block;
|
||||
USHORT block_status;
|
||||
UCHAR *spare_buffer_ptr;
|
||||
ULONG available_pages;
|
||||
LONG page;
|
||||
UINT release_sector = LX_FALSE;
|
||||
ULONG new_block;
|
||||
USHORT new_block_status;
|
||||
|
||||
#ifdef LX_THREAD_SAFE_ENABLE
|
||||
|
||||
@@ -105,38 +106,20 @@ ULONG i;
|
||||
/* Increment the number of release requests. */
|
||||
nand_flash -> lx_nand_flash_diagnostic_sector_release_requests++;
|
||||
|
||||
/* See if we can find the logical sector in the current mapping. */
|
||||
_lx_nand_flash_logical_sector_find(nand_flash, logical_sector, LX_FALSE, &found_block, &found_page);
|
||||
|
||||
/* Determine if the logical sector to page mapping was found. */
|
||||
if (found_page)
|
||||
|
||||
/* See if we can find the sector in the current mapping. */
|
||||
status = _lx_nand_flash_block_find(nand_flash, logical_sector, &block, &block_status);
|
||||
|
||||
/* Check return status. */
|
||||
if (status != LX_SUCCESS)
|
||||
{
|
||||
|
||||
/* Yes, we were able to find the logical sector. */
|
||||
|
||||
/* Determine if this sector is the current maximum sector. */
|
||||
if (nand_flash -> lx_nand_flash_max_mapped_sector == logical_sector)
|
||||
/* 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)
|
||||
{
|
||||
|
||||
/* Yes, this is the maximum sector. Reduce the maximum, if possible. */
|
||||
if (logical_sector)
|
||||
{
|
||||
|
||||
/* Decrement the logical sector. */
|
||||
nand_flash -> lx_nand_flash_max_mapped_sector--;
|
||||
}
|
||||
}
|
||||
|
||||
/* Read the extra information from the page. */
|
||||
status = _lx_nand_flash_driver_extra_bytes_get(nand_flash, found_block, found_page, (UCHAR *) &extra_info, sizeof(extra_info));
|
||||
|
||||
/* Check for an error from flash driver. */
|
||||
if (status)
|
||||
{
|
||||
|
||||
/* Call system error handler. */
|
||||
_lx_nand_flash_system_error(nand_flash, status, found_block, found_page);
|
||||
|
||||
#ifdef LX_THREAD_SAFE_ENABLE
|
||||
|
||||
/* Release the thread safe mutex. */
|
||||
@@ -146,116 +129,461 @@ ULONG i;
|
||||
/* Return an error. */
|
||||
return(LX_ERROR);
|
||||
}
|
||||
|
||||
/* Mark this sector as invalid. */
|
||||
|
||||
/* Now clear bits 31 and 30, which indicates this sector is now obsoleted. */
|
||||
extra_info.lx_nand_page_extra_info_logical_sector = extra_info.lx_nand_page_extra_info_logical_sector &
|
||||
~(((ULONG) LX_NAND_PAGE_VALID) | ((ULONG) LX_NAND_PAGE_SUPERCEDED));
|
||||
|
||||
/* Write the value back to the flash to clear bits 31 & 30. */
|
||||
status = _lx_nand_flash_driver_extra_bytes_set(nand_flash, found_block, found_page, (UCHAR *) &extra_info, sizeof(extra_info));
|
||||
|
||||
/* Check for an error from flash driver. */
|
||||
if (status)
|
||||
{
|
||||
|
||||
/* Call system error handler. */
|
||||
_lx_nand_flash_system_error(nand_flash, status, found_block, found_page);
|
||||
|
||||
#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);
|
||||
}
|
||||
|
||||
/* Increment the number of obsolete pages. */
|
||||
nand_flash -> lx_nand_flash_obsolete_pages++;
|
||||
|
||||
/* Decrement the number of mapped pages. */
|
||||
nand_flash -> lx_nand_flash_mapped_pages--;
|
||||
|
||||
/* Setup pointer to internal buffer. */
|
||||
block_word_ptr = nand_flash -> lx_nand_flash_page_buffer;
|
||||
|
||||
/* Now read page 0 of the block, which has the erase count in the first 4 bytes. */
|
||||
status = _lx_nand_flash_driver_read(nand_flash, found_block, 0, block_word_ptr, (nand_flash -> lx_nand_flash_pages_per_block + 1));
|
||||
|
||||
/* Check for an error from flash driver. */
|
||||
if (status)
|
||||
{
|
||||
|
||||
/* Call system error handler. */
|
||||
_lx_nand_flash_system_error(nand_flash, status, found_block, 0);
|
||||
|
||||
/* Determine if the error is fatal. */
|
||||
if (status != LX_NAND_ERROR_CORRECTED)
|
||||
{
|
||||
|
||||
#ifdef LX_THREAD_SAFE_ENABLE
|
||||
|
||||
/* Release the thread safe mutex. */
|
||||
tx_mutex_put(&nand_flash -> lx_nand_flash_mutex);
|
||||
#endif
|
||||
|
||||
/* Return the error. */
|
||||
return(status);
|
||||
}
|
||||
}
|
||||
|
||||
#ifndef LX_NAND_FLASH_MAPPING_LIST_UPDATE_DISABLE
|
||||
|
||||
/* Determine if the mapping list in page 0 is valid. */
|
||||
if ((block_word_ptr[1] != LX_NAND_PAGE_FREE) &&
|
||||
(block_word_ptr[nand_flash -> lx_nand_flash_pages_per_block] == LX_NAND_PAGE_LIST_VALID))
|
||||
{
|
||||
|
||||
/* Mark the entry as invalid. */
|
||||
block_word_ptr[found_page] &= ~LX_NAND_PAGE_VALID;
|
||||
|
||||
/* Write the invalid entry. */
|
||||
status = _lx_nand_flash_driver_write(nand_flash, found_block, 0, block_word_ptr, (nand_flash -> lx_nand_flash_pages_per_block + 1));
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Ensure the sector mapping cache no longer has this sector. */
|
||||
_lx_nand_flash_sector_mapping_cache_invalidate(nand_flash, logical_sector);
|
||||
|
||||
/* Call routine to see if this block is completely obsoleted. If so,
|
||||
we can reclaim it immediately. */
|
||||
_lx_nand_flash_block_obsoleted_check(nand_flash, found_block);
|
||||
|
||||
/* Determine if there are less than two block's worth of free pages. */
|
||||
i = 0;
|
||||
while (nand_flash -> lx_nand_flash_free_pages <= nand_flash -> lx_nand_flash_pages_per_block)
|
||||
{
|
||||
|
||||
/* Attempt to reclaim one block. */
|
||||
_lx_nand_flash_block_reclaim(nand_flash);
|
||||
|
||||
/* Increment the block count. */
|
||||
i++;
|
||||
|
||||
/* Have we exceeded the number of blocks in the system? */
|
||||
if (i >= nand_flash -> lx_nand_flash_total_blocks)
|
||||
{
|
||||
|
||||
/* Yes, break out of the loop. */
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
|
||||
/* Determine if the block is mapped. */
|
||||
if (block != LX_NAND_BLOCK_UNMAPPED)
|
||||
{
|
||||
|
||||
/* Could not find the logical sector. */
|
||||
status = LX_SECTOR_NOT_FOUND;
|
||||
/* Setup spare buffer pointer. */
|
||||
spare_buffer_ptr = (UCHAR*)nand_flash -> lx_nand_flash_page_buffer;
|
||||
|
||||
/* Get available pages in this block. */
|
||||
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;
|
||||
|
||||
/* Determine if the pages are recorded sequentially. */
|
||||
if (block_status & LX_NAND_BLOCK_STATUS_NON_SEQUENTIAL)
|
||||
{
|
||||
|
||||
/* Loop to search the logical page. */
|
||||
for (page = (LONG)available_pages - 1; page >= 0; page--)
|
||||
{
|
||||
|
||||
/* Read a 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)
|
||||
{
|
||||
|
||||
/* 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);
|
||||
}
|
||||
|
||||
/* 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)
|
||||
{
|
||||
|
||||
/* Make sure the sector is not released. */
|
||||
if ((LX_UTILITY_LONG_GET(&spare_buffer_ptr[nand_flash -> lx_nand_flash_spare_data1_offset]) & (~LX_NAND_PAGE_TYPE_USER_DATA_MASK)) == (LX_NAND_PAGE_TYPE_USER_DATA))
|
||||
{
|
||||
|
||||
/* Set release sector flag. */
|
||||
release_sector = LX_TRUE;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
/* Check if the logical sector is available. */
|
||||
if (logical_sector % nand_flash -> lx_nand_flash_pages_per_block < available_pages)
|
||||
{
|
||||
|
||||
/* Set release sector flag. */
|
||||
release_sector = LX_TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
/* Determine if the sector needs to be released. */
|
||||
if (release_sector)
|
||||
{
|
||||
|
||||
/* Check if the block is 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. */
|
||||
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 new block status to allocated. */
|
||||
new_block_status = LX_NAND_BLOCK_STATUS_ALLOCATED;
|
||||
|
||||
/* Remove the old block from mapped block list. */
|
||||
_lx_nand_flash_mapped_block_list_remove(nand_flash, logical_sector / nand_flash -> lx_nand_flash_pages_per_block);
|
||||
|
||||
/* Copy valid sector to new block. */
|
||||
status = _lx_nand_flash_data_page_copy(nand_flash, logical_sector - (logical_sector % nand_flash -> lx_nand_flash_pages_per_block), block, block_status, new_block, &new_block_status, (logical_sector % nand_flash -> lx_nand_flash_pages_per_block));
|
||||
|
||||
/* Check for an error from flash driver. */
|
||||
if (status)
|
||||
{
|
||||
|
||||
/* 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);
|
||||
}
|
||||
|
||||
/* Determine if there are sectors after the addressed sector need to be copied. */
|
||||
if (logical_sector % nand_flash -> lx_nand_flash_pages_per_block < nand_flash -> lx_nand_flash_pages_per_block - 1)
|
||||
{
|
||||
|
||||
/* Copy valid sector to new block. */
|
||||
status = _lx_nand_flash_data_page_copy(nand_flash, logical_sector + 1, block, block_status, new_block, &new_block_status, (nand_flash -> lx_nand_flash_pages_per_block - 1) - (logical_sector % nand_flash -> lx_nand_flash_pages_per_block));
|
||||
|
||||
/* Check for an error from flash driver. */
|
||||
if (status)
|
||||
{
|
||||
|
||||
/* 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);
|
||||
}
|
||||
}
|
||||
|
||||
/* Check new block status to see if there is valid pages in the block. */
|
||||
if ((new_block_status & LX_NAND_BLOCK_STATUS_PAGE_NUMBER_MASK) == 0)
|
||||
{
|
||||
|
||||
/* Add the block to free block list. */
|
||||
_lx_nand_flash_free_block_list_add(nand_flash, new_block);
|
||||
|
||||
/* Set new block to unmapped. */
|
||||
new_block = LX_NAND_BLOCK_UNMAPPED;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
/* Set new block status. */
|
||||
status = _lx_nand_flash_block_status_set(nand_flash, new_block, new_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);
|
||||
#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);
|
||||
}
|
||||
}
|
||||
|
||||
/* Update block mapping. */
|
||||
_lx_nand_flash_block_mapping_set(nand_flash, logical_sector, new_block);
|
||||
|
||||
/* Erase old 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] + 1);
|
||||
|
||||
/* 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);
|
||||
}
|
||||
|
||||
/* Update erase count for the old block. */
|
||||
status = _lx_nand_flash_erase_count_set(nand_flash, block, (UCHAR)(nand_flash -> lx_nand_flash_erase_count_table[block] + 1));
|
||||
|
||||
/* 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);
|
||||
}
|
||||
|
||||
/* Check if the block has too many erases. */
|
||||
if (nand_flash -> lx_nand_flash_erase_count_table[block] > LX_NAND_FLASH_MAX_ERASE_COUNT_DELTA)
|
||||
{
|
||||
|
||||
/* Move data from less worn block. */
|
||||
_lx_nand_flash_block_data_move(nand_flash, block);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
/* Set the block status to free. */
|
||||
status = _lx_nand_flash_block_status_set(nand_flash, block, LX_NAND_BLOCK_STATUS_FREE);
|
||||
|
||||
/* 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);
|
||||
}
|
||||
|
||||
/* Add the block to free block list. */
|
||||
_lx_nand_flash_free_block_list_add(nand_flash, block);
|
||||
}
|
||||
|
||||
/* Check if there is valid pages in the new block. */
|
||||
if ((new_block_status & LX_NAND_BLOCK_STATUS_PAGE_NUMBER_MASK) != 0)
|
||||
{
|
||||
|
||||
/* 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);
|
||||
}
|
||||
} /* end eager path else block */
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
/* 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);
|
||||
|
||||
/* Setup spare buffer pointer. */
|
||||
spare_buffer_ptr = nand_flash -> lx_nand_flash_page_buffer + nand_flash -> lx_nand_flash_bytes_per_page;
|
||||
|
||||
/* Check if there is enough spare data for metadata block number. */
|
||||
if (nand_flash -> lx_nand_flash_spare_data2_length >= sizeof(USHORT))
|
||||
{
|
||||
|
||||
/* Save metadata block number in spare bytes. */
|
||||
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 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);
|
||||
|
||||
/* Write the page. */
|
||||
#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);
|
||||
#else
|
||||
status = (nand_flash -> lx_nand_flash_driver_pages_write)(block, available_pages, (UCHAR*)nand_flash -> lx_nand_flash_page_buffer, 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);
|
||||
#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);
|
||||
}
|
||||
|
||||
/* Increase available pages count. */
|
||||
available_pages++;
|
||||
|
||||
/* Check if available pages count reaches total pages per block. */
|
||||
if (available_pages == nand_flash -> lx_nand_flash_pages_per_block)
|
||||
{
|
||||
|
||||
/* Set block full status flag. */
|
||||
block_status |= LX_NAND_BLOCK_STATUS_FULL;
|
||||
}
|
||||
|
||||
/* Build block status word. */
|
||||
block_status = (USHORT)(available_pages | (block_status & ~LX_NAND_BLOCK_STATUS_PAGE_NUMBER_MASK));
|
||||
|
||||
/* Set non sequential status flag. */
|
||||
block_status |= LX_NAND_BLOCK_STATUS_NON_SEQUENTIAL;
|
||||
|
||||
/* Set block status. */
|
||||
status = _lx_nand_flash_block_status_set(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);
|
||||
#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
|
||||
|
||||
/* Release the thread safe mutex. */
|
||||
|
||||
@@ -1,19 +1,20 @@
|
||||
/**************************************************************************/
|
||||
/* */
|
||||
/* Copyright (c) Microsoft Corporation. All rights reserved. */
|
||||
/* */
|
||||
/* This software is licensed under the Microsoft Software License */
|
||||
/* Terms for Microsoft Azure RTOS. Full text of the license can be */
|
||||
/* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */
|
||||
/* and in the root directory of this software. */
|
||||
/* */
|
||||
/**************************************************************************/
|
||||
/***************************************************************************
|
||||
* 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 */
|
||||
/** */
|
||||
/** LevelX Component */
|
||||
/** */
|
||||
/** NAND Flash */
|
||||
/** */
|
||||
@@ -25,8 +26,8 @@
|
||||
|
||||
/* Disable ThreadX error checking. */
|
||||
|
||||
#ifndef TX_DISABLE_ERROR_CHECKING
|
||||
#define TX_DISABLE_ERROR_CHECKING
|
||||
#ifndef LX_DISABLE_ERROR_CHECKING
|
||||
#define LX_DISABLE_ERROR_CHECKING
|
||||
#endif
|
||||
|
||||
|
||||
@@ -35,78 +36,68 @@
|
||||
#include "lx_api.h"
|
||||
|
||||
|
||||
/**************************************************************************/
|
||||
/* */
|
||||
/* FUNCTION RELEASE */
|
||||
/* */
|
||||
/* _lx_nand_flash_sector_write PORTABLE C */
|
||||
/* 6.0 */
|
||||
/**************************************************************************/
|
||||
/* */
|
||||
/* FUNCTION RELEASE */
|
||||
/* */
|
||||
/* _lx_nand_flash_sector_write PORTABLE C */
|
||||
/* 6.2.1 */
|
||||
/* AUTHOR */
|
||||
/* */
|
||||
/* William E. Lamie, Microsoft Corporation */
|
||||
/* Xiuwen Cai, Microsoft Corporation */
|
||||
/* */
|
||||
/* DESCRIPTION */
|
||||
/* */
|
||||
/* This function writes a logical sector to the NAND flash page. */
|
||||
/* */
|
||||
/* 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) */
|
||||
/* */
|
||||
/* OUTPUT */
|
||||
/* */
|
||||
/* return status */
|
||||
/* */
|
||||
/* CALLS */
|
||||
/* */
|
||||
/* _lx_nand_flash_driver_read Driver flash sector read */
|
||||
/* _lx_nand_flash_driver_write Driver flash sector write */
|
||||
/* _lx_nand_flash_driver_extra_bytes_get Get extra bytes from spare */
|
||||
/* _lx_nand_flash_driver_extra_bytes_set Set extra bytes in spare */
|
||||
/* _lx_nand_flash_block_full_update Update page 0 with list of */
|
||||
/* mapped pages */
|
||||
/* _lx_nand_flash_block_obsoleted_check Check for block obsoleted */
|
||||
/* _lx_nand_flash_block_reclaim Reclaim one flash block */
|
||||
/* _lx_nand_flash_logical_sector_find Find logical sector */
|
||||
/* _lx_nand_flash_physical_page_allocate Allocate new page */
|
||||
/* _lx_nand_flash_sector_mapping_cache_invalidate */
|
||||
/* Invalidate cache entry */
|
||||
/* _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 */
|
||||
/* DESCRIPTION */
|
||||
/* */
|
||||
/* 05-19-2020 William E. Lamie Initial Version 6.0 */
|
||||
/* This function writes a logical sector to the NAND flash page. */
|
||||
/* */
|
||||
/* 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) */
|
||||
/* */
|
||||
/* OUTPUT */
|
||||
/* */
|
||||
/* return status */
|
||||
/* */
|
||||
/* CALLS */
|
||||
/* */
|
||||
/* _lx_nand_flash_block_find Find the mapped block */
|
||||
/* _lx_nand_flash_block_allocate Allocate block */
|
||||
/* _lx_nand_flash_mapped_block_list_remove */
|
||||
/* Remove mapped block */
|
||||
/* _lx_nand_flash_data_page_copy Copy data pages */
|
||||
/* _lx_nand_flash_free_block_list_add Add free block to list */
|
||||
/* _lx_nand_flash_block_mapping_set Set block mapping */
|
||||
/* lx_nand_flash_driver_pages_write Write pages */
|
||||
/* _lx_nand_flash_block_status_set Set block status */
|
||||
/* _lx_nand_flash_driver_block_erase Erase block */
|
||||
/* _lx_nand_flash_erase_count_set Set erase count */
|
||||
/* _lx_nand_flash_block_data_move Move block data */
|
||||
/* _lx_nand_flash_mapped_block_list_add Add mapped block to list */
|
||||
/* _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_write(LX_NAND_FLASH *nand_flash, ULONG logical_sector, VOID *buffer)
|
||||
{
|
||||
|
||||
LX_NAND_PAGE_EXTRA_INFO old_extra_info;
|
||||
LX_NAND_PAGE_EXTRA_INFO new_extra_info;
|
||||
ULONG old_block;
|
||||
ULONG old_page;
|
||||
ULONG new_block;
|
||||
ULONG new_page;
|
||||
ULONG new_erase_count;
|
||||
ULONG i;
|
||||
#ifndef LX_NAND_FLASH_DIRECT_MAPPING_CACHE
|
||||
LX_NAND_SECTOR_MAPPING_CACHE_ENTRY *sector_mapping_cache_entry_ptr;
|
||||
#endif
|
||||
UINT status;
|
||||
ULONG *block_word_ptr;
|
||||
|
||||
ULONG block;
|
||||
ULONG new_block;
|
||||
ULONG page;
|
||||
USHORT block_status = 0;
|
||||
USHORT new_block_status = LX_NAND_BLOCK_STATUS_ALLOCATED;
|
||||
UCHAR *spare_buffer_ptr;
|
||||
UINT update_mapping = LX_FALSE;
|
||||
UINT copy_block = LX_FALSE;
|
||||
|
||||
#ifdef LX_THREAD_SAFE_ENABLE
|
||||
|
||||
@@ -114,62 +105,22 @@ ULONG *block_word_ptr;
|
||||
tx_mutex_get(&nand_flash -> lx_nand_flash_mutex, TX_WAIT_FOREVER);
|
||||
#endif
|
||||
|
||||
/* Determine if there are less than two block's worth of free pages. */
|
||||
i = 0;
|
||||
while (nand_flash -> lx_nand_flash_free_pages <= nand_flash -> lx_nand_flash_pages_per_block)
|
||||
{
|
||||
|
||||
/* Attempt to reclaim one block. */
|
||||
_lx_nand_flash_block_reclaim(nand_flash);
|
||||
|
||||
/* Increment the block count. */
|
||||
i++;
|
||||
|
||||
/* Have we exceeded the number of blocks in the system? */
|
||||
if (i >= nand_flash -> lx_nand_flash_total_blocks)
|
||||
{
|
||||
|
||||
/* Yes, break out of the loop. */
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/* Increment the number of write requests. */
|
||||
nand_flash -> lx_nand_flash_diagnostic_sector_write_requests++;
|
||||
|
||||
/* See if we can find the logical sector in the current mapping. */
|
||||
_lx_nand_flash_logical_sector_find(nand_flash, logical_sector, LX_FALSE, &old_block, &old_page);
|
||||
|
||||
/* Allocate a new page for this write. */
|
||||
_lx_nand_flash_physical_page_allocate(nand_flash, &new_block, &new_page, &new_erase_count);
|
||||
status = _lx_nand_flash_block_find(nand_flash, logical_sector, &block, &block_status);
|
||||
|
||||
/* Determine if the new page allocation was successful. */
|
||||
if (new_page)
|
||||
/* Check return status. */
|
||||
if(status != LX_SUCCESS)
|
||||
{
|
||||
|
||||
/* Yes, we were able to allocate a new page. */
|
||||
|
||||
/* Determine if this is the new maximum mapped sector. */
|
||||
if (logical_sector > nand_flash -> lx_nand_flash_max_mapped_sector)
|
||||
/* 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)
|
||||
{
|
||||
|
||||
/* Remember this maximum mapped sector. */
|
||||
nand_flash -> lx_nand_flash_max_mapped_sector = logical_sector;
|
||||
}
|
||||
|
||||
/* Update the number of free pages. */
|
||||
nand_flash -> lx_nand_flash_free_pages--;
|
||||
|
||||
/* Write the logical sector data to the new page. */
|
||||
status = _lx_nand_flash_driver_write(nand_flash, new_block, new_page, buffer, nand_flash -> lx_nand_flash_words_per_page);
|
||||
|
||||
/* Check for an error from flash driver. */
|
||||
if (status)
|
||||
{
|
||||
|
||||
/* Call system error handler. */
|
||||
_lx_nand_flash_system_error(nand_flash, status, new_block, new_page);
|
||||
|
||||
#ifdef LX_THREAD_SAFE_ENABLE
|
||||
|
||||
/* Release the thread safe mutex. */
|
||||
@@ -179,44 +130,74 @@ ULONG *block_word_ptr;
|
||||
/* Return an error. */
|
||||
return(LX_ERROR);
|
||||
}
|
||||
}
|
||||
|
||||
/* Determine if there was an old mapping. */
|
||||
if (old_page)
|
||||
#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)
|
||||
{
|
||||
|
||||
/* Read the extra info of the old page. */
|
||||
status = _lx_nand_flash_driver_extra_bytes_get(nand_flash, old_block, old_page, (UCHAR *) &old_extra_info, sizeof(old_extra_info));
|
||||
|
||||
/* Check for an error from flash driver. */
|
||||
if (status)
|
||||
if (status != LX_NAND_ERROR_CORRECTED)
|
||||
{
|
||||
|
||||
/* Call system error handler. */
|
||||
_lx_nand_flash_system_error(nand_flash, status, old_block, old_page);
|
||||
|
||||
#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);
|
||||
}
|
||||
|
||||
/* Clear bit 30, which indicates this sector is superceded. */
|
||||
old_extra_info.lx_nand_page_extra_info_logical_sector = old_extra_info.lx_nand_page_extra_info_logical_sector & (~((ULONG) LX_NAND_PAGE_SUPERCEDED));
|
||||
}
|
||||
}
|
||||
#endif /* LX_NAND_FLASH_ENABLE_LAZY_SECTOR_RELEASE */
|
||||
|
||||
/* Write the extra info to old page. */
|
||||
status = _lx_nand_flash_driver_extra_bytes_set(nand_flash, old_block, old_page, (UCHAR *) &old_extra_info, sizeof(old_extra_info));
|
||||
|
||||
/* Check for an error from flash driver. */
|
||||
if (status)
|
||||
/* Check if block is unmapped or block is full. */
|
||||
if (block == LX_NAND_BLOCK_UNMAPPED || block_status & LX_NAND_BLOCK_STATUS_FULL)
|
||||
{
|
||||
|
||||
/* Allocate a new block. */
|
||||
status = _lx_nand_flash_block_allocate(nand_flash, &new_block);
|
||||
|
||||
/* Check if there is no blocks. */
|
||||
if (status == LX_NO_BLOCKS)
|
||||
{
|
||||
#ifdef LX_THREAD_SAFE_ENABLE
|
||||
|
||||
/* Release the thread safe mutex. */
|
||||
tx_mutex_put(&nand_flash -> lx_nand_flash_mutex);
|
||||
#endif
|
||||
|
||||
/* Return error. */
|
||||
return(status);
|
||||
}
|
||||
|
||||
/* Check return status. */
|
||||
else if (status != LX_SUCCESS)
|
||||
{
|
||||
|
||||
/* Call system error handler. */
|
||||
_lx_nand_flash_system_error(nand_flash, status, new_block, 0);
|
||||
|
||||
/* Determine if the error is fatal. */
|
||||
if (status != LX_NAND_ERROR_CORRECTED)
|
||||
{
|
||||
|
||||
/* Call system error handler. */
|
||||
_lx_nand_flash_system_error(nand_flash, status, old_block, old_page);
|
||||
|
||||
#ifdef LX_THREAD_SAFE_ENABLE
|
||||
|
||||
/* Release the thread safe mutex. */
|
||||
@@ -228,221 +209,250 @@ ULONG *block_word_ptr;
|
||||
}
|
||||
}
|
||||
|
||||
/* Now build the new mapping entry - with the not valid bit set initially. */
|
||||
new_extra_info.lx_nand_page_extra_info_logical_sector = ((ULONG) LX_NAND_PAGE_VALID) | ((ULONG) LX_NAND_PAGE_SUPERCEDED) | ((ULONG) LX_NAND_PAGE_MAPPING_NOT_VALID) | logical_sector;
|
||||
|
||||
/* Write out the new mapping entry. */
|
||||
status = _lx_nand_flash_driver_extra_bytes_set(nand_flash, new_block, new_page, (UCHAR *) &new_extra_info, sizeof(new_extra_info));
|
||||
|
||||
/* Check for an error from flash driver. */
|
||||
if (status)
|
||||
{
|
||||
|
||||
/* Call system error handler. */
|
||||
_lx_nand_flash_system_error(nand_flash, status, new_block, new_page);
|
||||
|
||||
#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);
|
||||
}
|
||||
|
||||
/* 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. */
|
||||
new_extra_info.lx_nand_page_extra_info_logical_sector = new_extra_info.lx_nand_page_extra_info_logical_sector & ~((ULONG) LX_NAND_PAGE_MAPPING_NOT_VALID);
|
||||
|
||||
/* Clear the not valid bit. */
|
||||
status = _lx_nand_flash_driver_extra_bytes_set(nand_flash, new_block, new_page, (UCHAR *) &new_extra_info, sizeof(new_extra_info));
|
||||
|
||||
/* Check for an error from flash driver. */
|
||||
if (status)
|
||||
{
|
||||
|
||||
/* Call system error handler. */
|
||||
_lx_nand_flash_system_error(nand_flash, status, new_block, new_page);
|
||||
|
||||
#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);
|
||||
}
|
||||
|
||||
|
||||
/* Increment the number of mapped sectors. */
|
||||
nand_flash -> lx_nand_flash_mapped_pages++;
|
||||
|
||||
/* Was there a previously mapped sector? */
|
||||
if (old_page)
|
||||
{
|
||||
|
||||
/* Now clear bit 31, which indicates this sector is now obsoleted. */
|
||||
old_extra_info.lx_nand_page_extra_info_logical_sector = old_extra_info.lx_nand_page_extra_info_logical_sector & ~((ULONG) LX_NAND_PAGE_VALID);
|
||||
|
||||
/* Write the value back to the flash to clear bit 31. */
|
||||
status = _lx_nand_flash_driver_extra_bytes_set(nand_flash, old_block, old_page, (UCHAR *) &old_extra_info, sizeof(old_extra_info));
|
||||
|
||||
/* Check for an error from flash driver. */
|
||||
if (status)
|
||||
{
|
||||
|
||||
/* Call system error handler. */
|
||||
_lx_nand_flash_system_error(nand_flash, status, old_block, old_page);
|
||||
|
||||
#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);
|
||||
}
|
||||
|
||||
/* Setup pointer to internal buffer. */
|
||||
block_word_ptr = nand_flash -> lx_nand_flash_page_buffer;
|
||||
|
||||
/* Now read page 0 of the block, which has the erase count in the first 4 bytes. */
|
||||
status = _lx_nand_flash_driver_read(nand_flash, old_block, 0, block_word_ptr, (nand_flash -> lx_nand_flash_pages_per_block + 1));
|
||||
|
||||
/* Check for an error from flash driver. */
|
||||
if (status)
|
||||
{
|
||||
|
||||
/* Call system error handler. */
|
||||
_lx_nand_flash_system_error(nand_flash, status, old_block, 0);
|
||||
|
||||
/* Determine if the error is fatal. */
|
||||
if (status != LX_NAND_ERROR_CORRECTED)
|
||||
{
|
||||
|
||||
#ifdef LX_THREAD_SAFE_ENABLE
|
||||
|
||||
/* Release the thread safe mutex. */
|
||||
tx_mutex_put(&nand_flash -> lx_nand_flash_mutex);
|
||||
#endif
|
||||
|
||||
/* Return the error. */
|
||||
return(status);
|
||||
}
|
||||
}
|
||||
|
||||
#ifndef LX_NAND_FLASH_MAPPING_LIST_UPDATE_DISABLE
|
||||
|
||||
/* Determine if there is a valid mapping list. */
|
||||
if ((block_word_ptr[1] != LX_NAND_PAGE_FREE) &&
|
||||
(block_word_ptr[nand_flash -> lx_nand_flash_pages_per_block] == LX_NAND_PAGE_LIST_VALID))
|
||||
{
|
||||
|
||||
/* Mark the entry as invalid. */
|
||||
block_word_ptr[old_page] &= ~LX_NAND_PAGE_VALID;
|
||||
|
||||
/* Invalidate the page. */
|
||||
status = _lx_nand_flash_driver_write(nand_flash, old_block, 0, block_word_ptr, (nand_flash -> lx_nand_flash_pages_per_block + 1));
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Increment the number of obsolete pages. */
|
||||
nand_flash -> lx_nand_flash_obsolete_pages++;
|
||||
|
||||
/* Decrement the number of mapped pages. */
|
||||
nand_flash -> lx_nand_flash_mapped_pages--;
|
||||
|
||||
/* Invalidate the old sector mapping cache entry. */
|
||||
_lx_nand_flash_sector_mapping_cache_invalidate(nand_flash, logical_sector);
|
||||
|
||||
/* Call routine to see if this block is completely obsoleted. If so,
|
||||
we can reclaim it immediately. */
|
||||
_lx_nand_flash_block_obsoleted_check(nand_flash, old_block);
|
||||
}
|
||||
|
||||
/* Read the extra info of the old page. */
|
||||
status = _lx_nand_flash_driver_extra_bytes_get(nand_flash, new_block, new_page, (UCHAR *) &new_extra_info, sizeof(new_extra_info));
|
||||
|
||||
/* Check for an error from flash driver. */
|
||||
if (status)
|
||||
{
|
||||
|
||||
/* Call system error handler. */
|
||||
_lx_nand_flash_system_error(nand_flash, status, old_block, old_page);
|
||||
|
||||
#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);
|
||||
}
|
||||
|
||||
/* Check to see if the logical sector is still mapped to the same block/page. */
|
||||
if (((new_extra_info.lx_nand_page_extra_info_logical_sector & LX_NAND_LOGICAL_SECTOR_MASK) == logical_sector) &&
|
||||
(new_extra_info.lx_nand_page_extra_info_logical_sector & ((ULONG) LX_NAND_PAGE_VALID)))
|
||||
/* Check if the block is full. */
|
||||
if (block_status & LX_NAND_BLOCK_STATUS_FULL)
|
||||
{
|
||||
|
||||
/* Determine if the new page is the last page of the block. */
|
||||
if (new_page == (nand_flash -> lx_nand_flash_pages_per_block - 1))
|
||||
{
|
||||
|
||||
|
||||
/* Yes, we need to update page 0 of the block with the list of mapped
|
||||
pages for this block. */
|
||||
_lx_nand_flash_block_full_update(nand_flash, new_block, new_erase_count);
|
||||
}
|
||||
|
||||
/* Determine if the logical sector mapping cache is enabled. */
|
||||
if (nand_flash -> lx_nand_flash_sector_mapping_cache_enabled)
|
||||
{
|
||||
|
||||
/* Yes, sector mapping cache is enabled, place this logical sector mapping information in the cache. */
|
||||
|
||||
#ifndef LX_NAND_FLASH_DIRECT_MAPPING_CACHE
|
||||
|
||||
/* Calculate the starting index of the sector mapping cache for this sector entry. */
|
||||
i = (logical_sector & LX_NAND_SECTOR_MAPPING_CACHE_HASH_MASK) * LX_NAND_SECTOR_MAPPING_CACHE_DEPTH;
|
||||
|
||||
/* Build a pointer to the cache entry. */
|
||||
sector_mapping_cache_entry_ptr = &nand_flash -> lx_nand_flash_sector_mapping_cache[i];
|
||||
|
||||
/* 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 + 2) = *(sector_mapping_cache_entry_ptr + 1);
|
||||
*(sector_mapping_cache_entry_ptr + 1) = *(sector_mapping_cache_entry_ptr);
|
||||
|
||||
/* Setup the new logical sector information in the cache. */
|
||||
sector_mapping_cache_entry_ptr -> lx_nand_sector_mapping_cache_logical_sector = (logical_sector | LX_NAND_SECTOR_MAPPING_CACHE_ENTRY_VALID);
|
||||
sector_mapping_cache_entry_ptr -> lx_nand_sector_mapping_cache_block = (USHORT) new_block;
|
||||
sector_mapping_cache_entry_ptr -> lx_nand_sector_mapping_cache_page = (USHORT) new_page;
|
||||
#else
|
||||
|
||||
/* Determine if this logical sector fits in the logical sector cache mapping. */
|
||||
if (logical_sector < LX_NAND_SECTOR_MAPPING_CACHE_SIZE)
|
||||
{
|
||||
|
||||
/* Yes, store the logical sector to block/page mapping in the cache. */
|
||||
nand_flash -> lx_nand_flash_sector_mapping_cache[logical_sector].lx_nand_sector_mapping_cache_block = (USHORT) new_block;
|
||||
nand_flash -> lx_nand_flash_sector_mapping_cache[logical_sector].lx_nand_sector_mapping_cache_page = (USHORT) new_page;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
/* Set copy block flag. */
|
||||
copy_block = LX_TRUE;
|
||||
}
|
||||
|
||||
/* Indicate the write was successful. */
|
||||
status = LX_SUCCESS;
|
||||
/* Set update mapping flag. */
|
||||
update_mapping = LX_TRUE;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
/* Indicate the write was unsuccessful. */
|
||||
status = LX_NO_SECTORS;
|
||||
|
||||
/* Set new block to the same as old block. */
|
||||
new_block = block;
|
||||
new_block_status = block_status;
|
||||
}
|
||||
|
||||
/* Check if copy block flag is set. */
|
||||
if (copy_block)
|
||||
{
|
||||
|
||||
/* Remove the old block from mapped block list. */
|
||||
_lx_nand_flash_mapped_block_list_remove(nand_flash, logical_sector / nand_flash -> lx_nand_flash_pages_per_block);
|
||||
|
||||
/* Copy valid sector to new block. */
|
||||
status = _lx_nand_flash_data_page_copy(nand_flash, logical_sector - (logical_sector % nand_flash -> lx_nand_flash_pages_per_block), block, block_status, new_block, &new_block_status, (logical_sector % nand_flash -> lx_nand_flash_pages_per_block));
|
||||
|
||||
/* 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);
|
||||
}
|
||||
}
|
||||
|
||||
/* Check if update mapping flag is set. */
|
||||
if (update_mapping)
|
||||
{
|
||||
|
||||
/* Update block mapping. */
|
||||
_lx_nand_flash_block_mapping_set(nand_flash, logical_sector, new_block);
|
||||
}
|
||||
|
||||
/* Setup spare buffer pointer. */
|
||||
spare_buffer_ptr = nand_flash -> lx_nand_flash_page_buffer;
|
||||
|
||||
/* Set spare buffer to all 0xFF bytes. */
|
||||
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. */
|
||||
if (nand_flash -> lx_nand_flash_spare_data2_length >= sizeof(USHORT))
|
||||
{
|
||||
|
||||
/* Save metadata block number in spare bytes. */
|
||||
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 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);
|
||||
|
||||
/* Get page to write. */
|
||||
page = new_block_status & LX_NAND_BLOCK_STATUS_PAGE_NUMBER_MASK;
|
||||
|
||||
/* Write the page. */
|
||||
#ifdef LX_NAND_ENABLE_CONTROL_BLOCK_FOR_DRIVER_INTERFACE
|
||||
status = (nand_flash -> lx_nand_flash_driver_pages_write)(nand_flash, new_block, page, (UCHAR*)buffer, spare_buffer_ptr, 1);
|
||||
#else
|
||||
status = (nand_flash -> lx_nand_flash_driver_pages_write)(new_block, page, (UCHAR*)buffer, 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, 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);
|
||||
}
|
||||
|
||||
/* Determine if the sector number is sequential. */
|
||||
if ((new_block_status & LX_NAND_BLOCK_STATUS_PAGE_NUMBER_MASK) != (logical_sector % nand_flash -> lx_nand_flash_pages_per_block))
|
||||
{
|
||||
|
||||
/* Set non sequential status flag. */
|
||||
new_block_status |= LX_NAND_BLOCK_STATUS_NON_SEQUENTIAL;
|
||||
}
|
||||
|
||||
/* Increase page number. */
|
||||
page++;
|
||||
|
||||
/* Check if page number reaches total pages per block. */
|
||||
if (page == nand_flash -> lx_nand_flash_pages_per_block)
|
||||
{
|
||||
|
||||
/* Set block full status flag. */
|
||||
new_block_status |= LX_NAND_BLOCK_STATUS_FULL;
|
||||
}
|
||||
|
||||
/* Build block status word. */
|
||||
new_block_status = (USHORT)(page | (new_block_status & ~LX_NAND_BLOCK_STATUS_PAGE_NUMBER_MASK));
|
||||
|
||||
/* Determine if there are sectors after the addressed sector need to be copied. */
|
||||
if (copy_block && ((logical_sector % nand_flash -> lx_nand_flash_pages_per_block) < (nand_flash -> lx_nand_flash_pages_per_block - 1)))
|
||||
{
|
||||
|
||||
/* Copy valid sector to new block. */
|
||||
status = _lx_nand_flash_data_page_copy(nand_flash, logical_sector + 1, block, block_status, new_block, &new_block_status, (nand_flash -> lx_nand_flash_pages_per_block - 1) - (logical_sector % nand_flash -> lx_nand_flash_pages_per_block));
|
||||
|
||||
/* 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);
|
||||
}
|
||||
}
|
||||
|
||||
/* Set new block status. */
|
||||
status = _lx_nand_flash_block_status_set(nand_flash, new_block, new_block_status);
|
||||
|
||||
/* Check for an error from flash driver. */
|
||||
if (status)
|
||||
{
|
||||
|
||||
/* 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);
|
||||
}
|
||||
|
||||
/* Check if copy block flag is set. */
|
||||
if (copy_block)
|
||||
{
|
||||
|
||||
/* Erase old 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] + 1);
|
||||
|
||||
/* 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);
|
||||
}
|
||||
|
||||
/* Update erase count for the old block. */
|
||||
status = _lx_nand_flash_erase_count_set(nand_flash, block, (UCHAR)(nand_flash -> lx_nand_flash_erase_count_table[block] + 1));
|
||||
|
||||
/* 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);
|
||||
}
|
||||
|
||||
/* Check if the block has too many erases. */
|
||||
if (nand_flash -> lx_nand_flash_erase_count_table[block] > LX_NAND_FLASH_MAX_ERASE_COUNT_DELTA)
|
||||
{
|
||||
|
||||
/* Move data from less worn block. */
|
||||
_lx_nand_flash_block_data_move(nand_flash, block);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
/* Set the block status to free. */
|
||||
status = _lx_nand_flash_block_status_set(nand_flash, block, LX_NAND_BLOCK_STATUS_FREE);
|
||||
|
||||
/* 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);
|
||||
}
|
||||
|
||||
/* Add the block to free block list. */
|
||||
_lx_nand_flash_free_block_list_add(nand_flash, block);
|
||||
}
|
||||
}
|
||||
|
||||
/* Check if update mapping flag is set. */
|
||||
if (update_mapping)
|
||||
{
|
||||
|
||||
/* 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);
|
||||
}
|
||||
|
||||
#ifdef LX_THREAD_SAFE_ENABLE
|
||||
|
||||
@@ -0,0 +1,100 @@
|
||||
/***************************************************************************
|
||||
* Copyright (c) 2024 Microsoft Corporation
|
||||
* Copyright (c) 2026-present Eclipse ThreadX contributors
|
||||
*
|
||||
* This program and the accompanying materials are made available under the
|
||||
* terms of the MIT License which is available at
|
||||
* https://opensource.org/licenses/MIT.
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
**************************************************************************/
|
||||
|
||||
|
||||
/**************************************************************************/
|
||||
/**************************************************************************/
|
||||
/** */
|
||||
/** LevelX Component */
|
||||
/** */
|
||||
/** NAND Flash */
|
||||
/** */
|
||||
/**************************************************************************/
|
||||
/**************************************************************************/
|
||||
|
||||
#define LX_SOURCE_CODE
|
||||
|
||||
|
||||
/* Disable ThreadX error checking. */
|
||||
|
||||
#ifndef LX_DISABLE_ERROR_CHECKING
|
||||
#define LX_DISABLE_ERROR_CHECKING
|
||||
#endif
|
||||
|
||||
|
||||
/* Include necessary system files. */
|
||||
|
||||
#include "lx_api.h"
|
||||
|
||||
|
||||
/**************************************************************************/
|
||||
/* */
|
||||
/* FUNCTION RELEASE */
|
||||
/* */
|
||||
/* _lx_nand_flash_sectors_read PORTABLE C */
|
||||
/* 6.2.1 */
|
||||
/* AUTHOR */
|
||||
/* */
|
||||
/* Xiuwen Cai, Microsoft Corporation */
|
||||
/* */
|
||||
/* 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 */
|
||||
/* */
|
||||
/**************************************************************************/
|
||||
UINT _lx_nand_flash_sectors_read(LX_NAND_FLASH *nand_flash, ULONG logical_sector, VOID *buffer, ULONG sector_count)
|
||||
{
|
||||
|
||||
UINT status = LX_SUCCESS;
|
||||
UINT i;
|
||||
|
||||
|
||||
/* Loop to read all the sectors. */
|
||||
for (i = 0; i < sector_count; i++)
|
||||
{
|
||||
|
||||
/* Read one sector. */
|
||||
status = _lx_nand_flash_sector_read(nand_flash, logical_sector + i, ((UCHAR*)buffer) + i * nand_flash -> lx_nand_flash_bytes_per_page);
|
||||
|
||||
/* Check return status. */
|
||||
if (status)
|
||||
{
|
||||
|
||||
/* Error, break the loop. */
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/* Return status. */
|
||||
return(status);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,98 @@
|
||||
/***************************************************************************
|
||||
* Copyright (c) 2024 Microsoft Corporation
|
||||
* Copyright (c) 2026-present Eclipse ThreadX contributors
|
||||
*
|
||||
* This program and the accompanying materials are made available under the
|
||||
* terms of the MIT License which is available at
|
||||
* https://opensource.org/licenses/MIT.
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
**************************************************************************/
|
||||
|
||||
|
||||
/**************************************************************************/
|
||||
/**************************************************************************/
|
||||
/** */
|
||||
/** LevelX Component */
|
||||
/** */
|
||||
/** NAND Flash */
|
||||
/** */
|
||||
/**************************************************************************/
|
||||
/**************************************************************************/
|
||||
|
||||
#define LX_SOURCE_CODE
|
||||
|
||||
|
||||
/* Disable ThreadX error checking. */
|
||||
|
||||
#ifndef LX_DISABLE_ERROR_CHECKING
|
||||
#define LX_DISABLE_ERROR_CHECKING
|
||||
#endif
|
||||
|
||||
|
||||
/* Include necessary system files. */
|
||||
|
||||
#include "lx_api.h"
|
||||
|
||||
|
||||
/**************************************************************************/
|
||||
/* */
|
||||
/* FUNCTION RELEASE */
|
||||
/* */
|
||||
/* _lx_nand_flash_sectors_release PORTABLE C */
|
||||
/* 6.2.1 */
|
||||
/* AUTHOR */
|
||||
/* */
|
||||
/* Xiuwen Cai, Microsoft Corporation */
|
||||
/* */
|
||||
/* 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 */
|
||||
/* */
|
||||
/**************************************************************************/
|
||||
UINT _lx_nand_flash_sectors_release(LX_NAND_FLASH *nand_flash, ULONG logical_sector, ULONG sector_count)
|
||||
{
|
||||
|
||||
UINT status = LX_SUCCESS;
|
||||
UINT i;
|
||||
|
||||
|
||||
/* Loop to release all the sectors. */
|
||||
for (i = 0; i < sector_count; i++)
|
||||
{
|
||||
|
||||
/* Release one sector. */
|
||||
status = _lx_nand_flash_sector_release(nand_flash, logical_sector + i);
|
||||
|
||||
/* Check return status. */
|
||||
if (status)
|
||||
{
|
||||
|
||||
/* Error, break the loop. */
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/* Return status. */
|
||||
return(status);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,101 @@
|
||||
/***************************************************************************
|
||||
* Copyright (c) 2024 Microsoft Corporation
|
||||
* Copyright (c) 2026-present Eclipse ThreadX contributors
|
||||
*
|
||||
* This program and the accompanying materials are made available under the
|
||||
* terms of the MIT License which is available at
|
||||
* https://opensource.org/licenses/MIT.
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
**************************************************************************/
|
||||
|
||||
|
||||
/**************************************************************************/
|
||||
/**************************************************************************/
|
||||
/** */
|
||||
/** LevelX Component */
|
||||
/** */
|
||||
/** NAND Flash */
|
||||
/** */
|
||||
/**************************************************************************/
|
||||
/**************************************************************************/
|
||||
|
||||
#define LX_SOURCE_CODE
|
||||
|
||||
|
||||
/* Disable ThreadX error checking. */
|
||||
|
||||
#ifndef LX_DISABLE_ERROR_CHECKING
|
||||
#define LX_DISABLE_ERROR_CHECKING
|
||||
#endif
|
||||
|
||||
|
||||
/* Include necessary system files. */
|
||||
|
||||
#include "lx_api.h"
|
||||
|
||||
|
||||
/**************************************************************************/
|
||||
/* */
|
||||
/* FUNCTION RELEASE */
|
||||
/* */
|
||||
/* _lx_nand_flash_sectors_write PORTABLE C */
|
||||
/* 6.2.1 */
|
||||
/* AUTHOR */
|
||||
/* */
|
||||
/* Xiuwen Cai, Microsoft Corporation */
|
||||
/* */
|
||||
/* 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 */
|
||||
/* */
|
||||
/**************************************************************************/
|
||||
UINT _lx_nand_flash_sectors_write(LX_NAND_FLASH *nand_flash, ULONG logical_sector, VOID *buffer, ULONG sector_count)
|
||||
{
|
||||
|
||||
UINT status = LX_SUCCESS;
|
||||
UINT i;
|
||||
|
||||
|
||||
/* Loop to write all the sectors. */
|
||||
for (i = 0; i < sector_count; i++)
|
||||
{
|
||||
|
||||
/* 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);
|
||||
|
||||
/* Check return status. */
|
||||
if (status)
|
||||
{
|
||||
|
||||
/* Error, break the loop. */
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/* Return status. */
|
||||
return(status);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,19 +1,19 @@
|
||||
/**************************************************************************/
|
||||
/* */
|
||||
/* Copyright (c) Microsoft Corporation. All rights reserved. */
|
||||
/* */
|
||||
/* This software is licensed under the Microsoft Software License */
|
||||
/* Terms for Microsoft Azure RTOS. Full text of the license can be */
|
||||
/* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */
|
||||
/* and in the root directory of this software. */
|
||||
/* */
|
||||
/**************************************************************************/
|
||||
/***************************************************************************
|
||||
* Copyright (c) 2024 Microsoft Corporation
|
||||
* Copyright (c) 2026-present Eclipse ThreadX contributors
|
||||
*
|
||||
* This program and the accompanying materials are made available under the
|
||||
* terms of the MIT License which is available at
|
||||
* https://opensource.org/licenses/MIT.
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
**************************************************************************/
|
||||
|
||||
|
||||
/**************************************************************************/
|
||||
/**************************************************************************/
|
||||
/** */
|
||||
/** LevelX Component */
|
||||
/** */
|
||||
/** LevelX Component */
|
||||
/** */
|
||||
/** NAND Flash Simulator */
|
||||
/** */
|
||||
@@ -23,45 +23,49 @@
|
||||
|
||||
/* Include necessary files. */
|
||||
|
||||
#include "tx_api.h"
|
||||
#include "lx_api.h"
|
||||
|
||||
/* Define constants for the NAND flash simulation. */
|
||||
|
||||
#define TOTAL_BLOCKS 8
|
||||
#define PHYSICAL_PAGES_PER_BLOCK 16 /* Min value of 2 */
|
||||
#define BYTES_PER_PHYSICAL_PAGE 2048 /* 2048 bytes per page */
|
||||
#define WORDS_PER_PHYSICAL_PAGE 2048/4 /* Words per page */
|
||||
#define SPARE_BYTES_PER_PAGE 64 /* 64 "spare" bytes per page */
|
||||
/* For 2048 byte block spare area: */
|
||||
#define BAD_BLOCK_POSITION 0 /* 0 is the bad block byte postion */
|
||||
#define EXTRA_BYTE_POSITION 2 /* 2 is the extra bytes starting byte postion */
|
||||
#define ECC_BYTE_POSITION 40 /* 40 is the ECC starting byte position */
|
||||
#define TOTAL_BLOCKS 1024
|
||||
#define PHYSICAL_PAGES_PER_BLOCK 256 /* Min value of 2 */
|
||||
#define BYTES_PER_PHYSICAL_PAGE 512 /* 512 bytes per page */
|
||||
#define WORDS_PER_PHYSICAL_PAGE 512 / 4 /* Words per page */
|
||||
#define SPARE_BYTES_PER_PAGE 16 /* 16 "spare" bytes per page */
|
||||
/* For 2048 byte block spare area: */
|
||||
#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 ECC_BYTE_POSITION 8 /* 8 is the ECC starting byte position */
|
||||
#define SPARE_DATA1_OFFSET 4
|
||||
#define SPARE_DATA1_LENGTH 4
|
||||
#define SPARE_DATA2_OFFSET 2
|
||||
#define SPARE_DATA2_LENGTH 2
|
||||
|
||||
|
||||
/* 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:
|
||||
|
||||
|
||||
256 Byte Block
|
||||
|
||||
|
||||
Bytes Meaning
|
||||
|
||||
|
||||
0,1,2 ECC bytes
|
||||
3,4,6,7 Extra
|
||||
5 Bad block flag
|
||||
|
||||
|
||||
512 Byte Block
|
||||
|
||||
|
||||
Bytes Meaning
|
||||
|
||||
|
||||
0,1,2,3,6,7 ECC bytes
|
||||
8-15 Extra
|
||||
5 Bad block flag
|
||||
|
||||
|
||||
2048 Byte Block
|
||||
|
||||
|
||||
Bytes Meaning
|
||||
|
||||
|
||||
0 Bad block flag
|
||||
2-39 Extra
|
||||
40-63 ECC bytes
|
||||
@@ -101,19 +105,40 @@ ULONG *nand_flash_memory;
|
||||
|
||||
|
||||
UINT _lx_nand_flash_simulator_initialize(LX_NAND_FLASH *nand_flash);
|
||||
UINT _lx_nand_flash_simulator_erase_all(VOID);
|
||||
|
||||
#ifdef LX_NAND_ENABLE_CONTROL_BLOCK_FOR_DRIVER_INTERFACE
|
||||
UINT _lx_nand_flash_simulator_read(LX_NAND_FLASH *nand_flash, ULONG block, ULONG page, ULONG *destination, ULONG words);
|
||||
UINT _lx_nand_flash_simulator_write(LX_NAND_FLASH *nand_flash, ULONG block, ULONG page, ULONG *source, ULONG words);
|
||||
UINT _lx_nand_flash_simulator_block_erase(LX_NAND_FLASH *nand_flash, ULONG block, ULONG erase_count);
|
||||
UINT _lx_nand_flash_simulator_block_erased_verify(LX_NAND_FLASH *nand_flash, ULONG block);
|
||||
UINT _lx_nand_flash_simulator_page_erased_verify(LX_NAND_FLASH *nand_flash, ULONG block, ULONG page);
|
||||
UINT _lx_nand_flash_simulator_block_status_get(LX_NAND_FLASH *nand_flash, ULONG block, UCHAR *bad_block_byte);
|
||||
UINT _lx_nand_flash_simulator_block_status_set(LX_NAND_FLASH *nand_flash, ULONG block, UCHAR bad_block_byte);
|
||||
UINT _lx_nand_flash_simulator_extra_bytes_get(LX_NAND_FLASH *nand_flash, ULONG block, ULONG page, UCHAR *destination, UINT size);
|
||||
UINT _lx_nand_flash_simulator_extra_bytes_set(LX_NAND_FLASH *nand_flash, ULONG block, ULONG page, UCHAR *source, UINT size);
|
||||
UINT _lx_nand_flash_simulator_system_error(LX_NAND_FLASH *nand_flash, UINT error_code, ULONG block, ULONG page);
|
||||
|
||||
UINT _lx_nand_flash_simulator_pages_read(LX_NAND_FLASH *nand_flash, ULONG block, ULONG page, UCHAR* main_buffer, UCHAR* spare_buffer, ULONG pages);
|
||||
UINT _lx_nand_flash_simulator_pages_write(LX_NAND_FLASH *nand_flash, ULONG block, ULONG page, UCHAR* main_buffer, UCHAR* spare_buffer, ULONG pages);
|
||||
UINT _lx_nand_flash_simulator_pages_copy(LX_NAND_FLASH *nand_flash, ULONG source_block, ULONG source_page, ULONG destination_block, ULONG destination_page, ULONG pages, UCHAR* data_buffer);
|
||||
#else
|
||||
UINT _lx_nand_flash_simulator_read(ULONG block, ULONG page, ULONG *destination, ULONG words);
|
||||
UINT _lx_nand_flash_simulator_write(ULONG block, ULONG page, ULONG *source, ULONG words);
|
||||
UINT _lx_nand_flash_simulator_block_erase(ULONG block, ULONG erase_count);
|
||||
UINT _lx_nand_flash_simulator_block_erased_verify(ULONG block);
|
||||
UINT _lx_nand_flash_simulator_page_erased_verify(ULONG block, ULONG page);
|
||||
UINT _lx_nand_flash_simulator_erase_all(VOID);
|
||||
UINT _lx_nand_flash_simulator_block_status_get(ULONG block, UCHAR *bad_block_byte);
|
||||
UINT _lx_nand_flash_simulator_block_status_set(ULONG block, UCHAR bad_block_byte);
|
||||
UINT _lx_nand_flash_simulator_extra_bytes_get(ULONG block, ULONG page, UCHAR *destination, UINT size);
|
||||
UINT _lx_nand_flash_simulator_extra_bytes_set(ULONG block, ULONG page, UCHAR *source, UINT size);
|
||||
UINT _lx_nand_flash_simulator_system_error(UINT error_code, ULONG block, ULONG page);
|
||||
|
||||
|
||||
UINT _lx_nand_flash_simulator_pages_read(ULONG block, ULONG page, UCHAR* main_buffer, UCHAR* spare_buffer, ULONG pages);
|
||||
UINT _lx_nand_flash_simulator_pages_write(ULONG block, ULONG page, UCHAR* main_buffer, UCHAR* spare_buffer, ULONG pages);
|
||||
UINT _lx_nand_flash_simulator_pages_copy(ULONG source_block, ULONG source_page, ULONG destination_block, ULONG destination_page, ULONG pages, UCHAR* data_buffer);
|
||||
#endif
|
||||
UINT _lx_nand_flash_simulator_page_ecc_check(ULONG block, ULONG page);
|
||||
|
||||
UINT _lx_nand_flash_simulator_initialize(LX_NAND_FLASH *nand_flash)
|
||||
{
|
||||
@@ -138,19 +163,76 @@ UINT _lx_nand_flash_simulator_initialize(LX_NAND_FLASH *nand_flash)
|
||||
nand_flash -> lx_nand_flash_driver_extra_bytes_set = _lx_nand_flash_simulator_extra_bytes_set;
|
||||
nand_flash -> lx_nand_flash_driver_system_error = _lx_nand_flash_simulator_system_error;
|
||||
|
||||
/* Setup local buffer for NAND flash operation. This buffer must be the page size of the NAND flash memory. */
|
||||
nand_flash -> lx_nand_flash_page_buffer = &nand_flash_simulator_buffer[0];
|
||||
nand_flash -> lx_nand_flash_driver_pages_read = _lx_nand_flash_simulator_pages_read;
|
||||
nand_flash -> lx_nand_flash_driver_pages_write = _lx_nand_flash_simulator_pages_write;
|
||||
nand_flash -> lx_nand_flash_driver_pages_copy = _lx_nand_flash_simulator_pages_copy;
|
||||
|
||||
nand_flash -> lx_nand_flash_spare_data1_offset = SPARE_DATA1_OFFSET;
|
||||
nand_flash -> lx_nand_flash_spare_data1_length = SPARE_DATA1_LENGTH;
|
||||
|
||||
nand_flash -> lx_nand_flash_spare_data2_offset = SPARE_DATA2_OFFSET;
|
||||
nand_flash -> lx_nand_flash_spare_data2_length = SPARE_DATA2_LENGTH;
|
||||
|
||||
nand_flash -> lx_nand_flash_spare_total_length = SPARE_BYTES_PER_PAGE;
|
||||
|
||||
/* Return success. */
|
||||
return(LX_SUCCESS);
|
||||
}
|
||||
UINT _lx_nand_flash_simulator_page_ecc_check(ULONG block, ULONG page)
|
||||
{
|
||||
|
||||
UINT i;
|
||||
INT ecc_pos = 0;
|
||||
UINT ecc_status = LX_SUCCESS;
|
||||
UINT status;
|
||||
|
||||
|
||||
for (i = 0; i < BYTES_PER_PHYSICAL_PAGE; i += 256)
|
||||
{
|
||||
status = lx_nand_flash_256byte_ecc_check((UCHAR*)&nand_memory_area[block].physical_pages[page].memory[i / sizeof(ULONG)],
|
||||
&nand_memory_area[block].physical_pages[page].spare[ECC_BYTE_POSITION + ecc_pos]);
|
||||
|
||||
if (status == LX_NAND_ERROR_NOT_CORRECTED)
|
||||
{
|
||||
ecc_status = LX_NAND_ERROR_NOT_CORRECTED;
|
||||
break;
|
||||
}
|
||||
else if (status == LX_NAND_ERROR_CORRECTED)
|
||||
{
|
||||
ecc_status = LX_NAND_ERROR_CORRECTED;
|
||||
}
|
||||
|
||||
ecc_pos += 3;
|
||||
}
|
||||
|
||||
if (ecc_status == LX_NAND_ERROR_CORRECTED)
|
||||
{
|
||||
|
||||
return(LX_ERROR);
|
||||
}
|
||||
else if (ecc_status == LX_NAND_ERROR_NOT_CORRECTED)
|
||||
{
|
||||
|
||||
return(LX_ERROR);
|
||||
}
|
||||
return ecc_status;
|
||||
}
|
||||
|
||||
#ifdef LX_NAND_ENABLE_CONTROL_BLOCK_FOR_DRIVER_INTERFACE
|
||||
UINT _lx_nand_flash_simulator_read(LX_NAND_FLASH *nand_flash, ULONG block, ULONG page, ULONG *destination, ULONG words)
|
||||
#else
|
||||
UINT _lx_nand_flash_simulator_read(ULONG block, ULONG page, ULONG *destination, ULONG words)
|
||||
#endif
|
||||
{
|
||||
|
||||
ULONG *flash_address;
|
||||
UINT status;
|
||||
|
||||
#ifdef LX_NAND_ENABLE_CONTROL_BLOCK_FOR_DRIVER_INTERFACE
|
||||
LX_PARAMETER_NOT_USED(nand_flash);
|
||||
#endif
|
||||
|
||||
status = _lx_nand_flash_simulator_page_ecc_check(block, page);
|
||||
|
||||
/* Pickup the flash address. */
|
||||
flash_address = &(nand_memory_area[block].physical_pages[page].memory[0]);
|
||||
@@ -162,21 +244,80 @@ ULONG *flash_address;
|
||||
*destination++ = *flash_address++;
|
||||
}
|
||||
|
||||
return(LX_SUCCESS);
|
||||
return(status);
|
||||
}
|
||||
|
||||
#ifdef LX_NAND_ENABLE_CONTROL_BLOCK_FOR_DRIVER_INTERFACE
|
||||
UINT _lx_nand_flash_simulator_pages_read(LX_NAND_FLASH *nand_flash, ULONG block, ULONG page, UCHAR* main_buffer, UCHAR* spare_buffer, ULONG pages)
|
||||
#else
|
||||
UINT _lx_nand_flash_simulator_pages_read(ULONG block, ULONG page, UCHAR* main_buffer, UCHAR* spare_buffer, ULONG pages)
|
||||
#endif
|
||||
{
|
||||
|
||||
UINT i;
|
||||
UINT status;
|
||||
UINT ecc_status = LX_SUCCESS;
|
||||
|
||||
|
||||
for (i = 0; i < pages; i++)
|
||||
{
|
||||
if (main_buffer)
|
||||
{
|
||||
|
||||
#ifdef LX_NAND_ENABLE_CONTROL_BLOCK_FOR_DRIVER_INTERFACE
|
||||
status = _lx_nand_flash_simulator_read(nand_flash, block, page + i, (ULONG*)(main_buffer + i * BYTES_PER_PHYSICAL_PAGE), WORDS_PER_PHYSICAL_PAGE);
|
||||
#else
|
||||
status = _lx_nand_flash_simulator_read(block, page + i, (ULONG*)(main_buffer + i * BYTES_PER_PHYSICAL_PAGE), WORDS_PER_PHYSICAL_PAGE);
|
||||
#endif
|
||||
if (status == LX_NAND_ERROR_CORRECTED)
|
||||
{
|
||||
ecc_status = LX_NAND_ERROR_CORRECTED;
|
||||
}
|
||||
else if (status == LX_NAND_ERROR_NOT_CORRECTED)
|
||||
{
|
||||
ecc_status = LX_ERROR;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (spare_buffer)
|
||||
{
|
||||
|
||||
#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);
|
||||
#else
|
||||
status = _lx_nand_flash_simulator_extra_bytes_get(block, page + i, spare_buffer + i * SPARE_BYTES_PER_PAGE, SPARE_BYTES_PER_PAGE);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
return (ecc_status);
|
||||
}
|
||||
|
||||
#ifdef LX_NAND_ENABLE_CONTROL_BLOCK_FOR_DRIVER_INTERFACE
|
||||
UINT _lx_nand_flash_simulator_write(LX_NAND_FLASH *nand_flash, ULONG block, ULONG page, ULONG *source, ULONG words)
|
||||
#else
|
||||
UINT _lx_nand_flash_simulator_write(ULONG block, ULONG page, ULONG *source, ULONG words)
|
||||
#endif
|
||||
{
|
||||
|
||||
ULONG *flash_address;
|
||||
UCHAR *flash_spare_address;
|
||||
UINT bytes_computed;
|
||||
UINT ecc_bytes =0;
|
||||
UCHAR new_ecc_buffer[24];
|
||||
UCHAR *new_ecc_buffer_ptr = new_ecc_buffer;
|
||||
UCHAR *ecc_buffer_ptr = new_ecc_buffer_ptr;
|
||||
ULONG *page_ptr = &(nand_memory_area[block].physical_pages[page].memory[0]);
|
||||
|
||||
#ifdef LX_NAND_ENABLE_CONTROL_BLOCK_FOR_DRIVER_INTERFACE
|
||||
LX_PARAMETER_NOT_USED(nand_flash);
|
||||
#endif
|
||||
|
||||
|
||||
/* Increment the diag info. */
|
||||
nand_block_diag[block].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];
|
||||
|
||||
|
||||
/* Pickup the flash address. */
|
||||
flash_address = &(nand_memory_area[block].physical_pages[page].memory[0]);
|
||||
|
||||
@@ -188,15 +329,119 @@ ULONG *flash_address;
|
||||
in a NAND device. */
|
||||
if ((*source & *flash_address) != *source)
|
||||
return(LX_INVALID_WRITE);
|
||||
|
||||
|
||||
/* Copy word. */
|
||||
*flash_address++ = *source++;
|
||||
}
|
||||
|
||||
/* Loop to compute the ECC over the entire NAND flash page. */
|
||||
bytes_computed = 0;
|
||||
|
||||
while (bytes_computed < BYTES_PER_PHYSICAL_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);
|
||||
|
||||
/* Move to the next 256 byte portion of the page. */
|
||||
bytes_computed = bytes_computed + 256;
|
||||
|
||||
/* Move the page buffer forward. */
|
||||
page_ptr = page_ptr + 64;
|
||||
|
||||
ecc_bytes = ecc_bytes + 3;
|
||||
|
||||
/* Move the ECC buffer forward, note there are 3 bytes of ECC per page. */
|
||||
new_ecc_buffer_ptr = new_ecc_buffer_ptr + 3;
|
||||
}
|
||||
|
||||
/* Setup destination pointer in the spare area. */
|
||||
flash_spare_address = (UCHAR *) &(nand_memory_area[block].physical_pages[page].spare[ECC_BYTE_POSITION]);
|
||||
while(ecc_bytes--)
|
||||
{
|
||||
|
||||
/* Can the word be written? We can clear new bits, but just can't unclear
|
||||
in a NAND device. */
|
||||
if ((*ecc_buffer_ptr & *flash_spare_address) != *ecc_buffer_ptr)
|
||||
return(LX_INVALID_WRITE);
|
||||
|
||||
/* Set an ecc byte in the spare area. */
|
||||
*flash_spare_address++ = *ecc_buffer_ptr++;
|
||||
|
||||
}
|
||||
return(LX_SUCCESS);
|
||||
}
|
||||
|
||||
#ifdef LX_NAND_ENABLE_CONTROL_BLOCK_FOR_DRIVER_INTERFACE
|
||||
UINT _lx_nand_flash_simulator_pages_write(LX_NAND_FLASH *nand_flash, ULONG block, ULONG page, UCHAR* main_buffer, UCHAR* spare_buffer, ULONG pages)
|
||||
#else
|
||||
UINT _lx_nand_flash_simulator_pages_write(ULONG block, ULONG page, UCHAR* main_buffer, UCHAR* spare_buffer, ULONG pages)
|
||||
#endif
|
||||
{
|
||||
|
||||
UINT i;
|
||||
UINT status = LX_SUCCESS;
|
||||
|
||||
|
||||
for (i = 0; i < pages; i++)
|
||||
{
|
||||
#ifdef LX_NAND_ENABLE_CONTROL_BLOCK_FOR_DRIVER_INTERFACE
|
||||
_lx_nand_flash_simulator_extra_bytes_set(nand_flash, block, page + i, spare_buffer + i * SPARE_BYTES_PER_PAGE, SPARE_BYTES_PER_PAGE);
|
||||
status = _lx_nand_flash_simulator_write(nand_flash, block, page + i, (ULONG*)(main_buffer + i * BYTES_PER_PHYSICAL_PAGE), WORDS_PER_PHYSICAL_PAGE);
|
||||
#else
|
||||
_lx_nand_flash_simulator_extra_bytes_set(block, page + i, spare_buffer + i * SPARE_BYTES_PER_PAGE, SPARE_BYTES_PER_PAGE);
|
||||
status = _lx_nand_flash_simulator_write(block, page + i, (ULONG*)(main_buffer + i * BYTES_PER_PHYSICAL_PAGE), WORDS_PER_PHYSICAL_PAGE);
|
||||
#endif
|
||||
if (status == LX_INVALID_WRITE)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
return (status);
|
||||
}
|
||||
|
||||
#ifdef LX_NAND_ENABLE_CONTROL_BLOCK_FOR_DRIVER_INTERFACE
|
||||
UINT _lx_nand_flash_simulator_pages_copy(LX_NAND_FLASH *nand_flash, ULONG source_block, ULONG source_page, ULONG destination_block, ULONG destination_page, ULONG pages, UCHAR *data_buffer)
|
||||
#else
|
||||
UINT _lx_nand_flash_simulator_pages_copy(ULONG source_block, ULONG source_page, ULONG destination_block, ULONG destination_page, ULONG pages, UCHAR *data_buffer)
|
||||
#endif
|
||||
{
|
||||
UINT i;
|
||||
UINT status = LX_SUCCESS;
|
||||
|
||||
|
||||
for (i = 0; i < pages; i++)
|
||||
{
|
||||
#ifdef LX_NAND_ENABLE_CONTROL_BLOCK_FOR_DRIVER_INTERFACE
|
||||
status = _lx_nand_flash_simulator_pages_read(nand_flash, source_block, source_page + i, data_buffer, data_buffer + BYTES_PER_PHYSICAL_PAGE, 1);
|
||||
#else
|
||||
status = _lx_nand_flash_simulator_pages_read(source_block, source_page + i, data_buffer, data_buffer + BYTES_PER_PHYSICAL_PAGE, 1);
|
||||
#endif
|
||||
if (status != LX_SUCCESS && status != LX_NAND_ERROR_CORRECTED)
|
||||
{
|
||||
break;
|
||||
}
|
||||
#ifdef LX_NAND_ENABLE_CONTROL_BLOCK_FOR_DRIVER_INTERFACE
|
||||
status = _lx_nand_flash_simulator_pages_write(nand_flash, destination_block, destination_page + i, data_buffer, data_buffer + BYTES_PER_PHYSICAL_PAGE, 1);
|
||||
#else
|
||||
status = _lx_nand_flash_simulator_pages_write(destination_block, destination_page + i, data_buffer, data_buffer + BYTES_PER_PHYSICAL_PAGE, 1);
|
||||
#endif
|
||||
if (status != LX_SUCCESS)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
return (status);
|
||||
|
||||
}
|
||||
|
||||
#ifdef LX_NAND_ENABLE_CONTROL_BLOCK_FOR_DRIVER_INTERFACE
|
||||
UINT _lx_nand_flash_simulator_block_erase(LX_NAND_FLASH *nand_flash, ULONG block, ULONG erase_count)
|
||||
#else
|
||||
UINT _lx_nand_flash_simulator_block_erase(ULONG block, ULONG erase_count)
|
||||
#endif
|
||||
{
|
||||
|
||||
ULONG *pointer;
|
||||
@@ -204,6 +449,9 @@ ULONG words;
|
||||
UINT i;
|
||||
|
||||
LX_PARAMETER_NOT_USED(erase_count);
|
||||
#ifdef LX_NAND_ENABLE_CONTROL_BLOCK_FOR_DRIVER_INTERFACE
|
||||
LX_PARAMETER_NOT_USED(nand_flash);
|
||||
#endif
|
||||
|
||||
/* Increment the diag info. */
|
||||
nand_block_diag[block].erases++;
|
||||
@@ -217,7 +465,7 @@ UINT i;
|
||||
words = sizeof(NAND_FLASH_BLOCK)/sizeof(ULONG);
|
||||
while (words--)
|
||||
{
|
||||
|
||||
|
||||
/* Erase word of block. */
|
||||
*pointer++ = (ULONG) 0xFFFFFFFF;
|
||||
}
|
||||
@@ -241,15 +489,15 @@ UINT i, j;
|
||||
for (j = 0; j < PHYSICAL_PAGES_PER_BLOCK;j++)
|
||||
nand_block_diag[i].page_writes[j] = 0;
|
||||
}
|
||||
|
||||
|
||||
/* Setup pointer. */
|
||||
pointer = (ULONG *) &nand_memory_area[0];
|
||||
|
||||
/* Loop to erase block. */
|
||||
words = sizeof(nand_memory_area)/sizeof(ULONG);
|
||||
words = sizeof(nand_memory_area)/(sizeof(ULONG));
|
||||
while (words--)
|
||||
{
|
||||
|
||||
|
||||
/* Erase word of block. */
|
||||
*pointer++ = (ULONG) 0xFFFFFFFF;
|
||||
}
|
||||
@@ -258,97 +506,133 @@ UINT i, j;
|
||||
}
|
||||
|
||||
|
||||
#ifdef LX_NAND_ENABLE_CONTROL_BLOCK_FOR_DRIVER_INTERFACE
|
||||
UINT _lx_nand_flash_simulator_block_erased_verify(LX_NAND_FLASH *nand_flash, ULONG block)
|
||||
#else
|
||||
UINT _lx_nand_flash_simulator_block_erased_verify(ULONG block)
|
||||
#endif
|
||||
{
|
||||
|
||||
ULONG *word_ptr;
|
||||
ULONG words;
|
||||
|
||||
#ifdef LX_NAND_ENABLE_CONTROL_BLOCK_FOR_DRIVER_INTERFACE
|
||||
LX_PARAMETER_NOT_USED(nand_flash);
|
||||
#endif
|
||||
|
||||
/* Determine if the block is completely erased. */
|
||||
|
||||
|
||||
/* Pickup the pointer to the first word of the block. */
|
||||
word_ptr = (ULONG *) &nand_memory_area[block];
|
||||
|
||||
|
||||
/* Calculate the number of words in a block. */
|
||||
words = sizeof(NAND_FLASH_BLOCK)/sizeof(ULONG);
|
||||
|
||||
|
||||
/* Loop to check if the block is erased. */
|
||||
while (words--)
|
||||
{
|
||||
|
||||
|
||||
/* Is this word erased? */
|
||||
if (*word_ptr++ != 0xFFFFFFFF)
|
||||
return(LX_ERROR);
|
||||
}
|
||||
|
||||
|
||||
/* Return success. */
|
||||
return(LX_SUCCESS);
|
||||
}
|
||||
|
||||
|
||||
#ifdef LX_NAND_ENABLE_CONTROL_BLOCK_FOR_DRIVER_INTERFACE
|
||||
UINT _lx_nand_flash_simulator_page_erased_verify(LX_NAND_FLASH *nand_flash, ULONG block, ULONG page)
|
||||
#else
|
||||
UINT _lx_nand_flash_simulator_page_erased_verify(ULONG block, ULONG page)
|
||||
#endif
|
||||
{
|
||||
|
||||
ULONG *word_ptr;
|
||||
ULONG words;
|
||||
|
||||
#ifdef LX_NAND_ENABLE_CONTROL_BLOCK_FOR_DRIVER_INTERFACE
|
||||
LX_PARAMETER_NOT_USED(nand_flash);
|
||||
#endif
|
||||
|
||||
/* Determine if the block is completely erased. */
|
||||
|
||||
|
||||
/* Pickup the pointer to the first word of the block's page. */
|
||||
word_ptr = (ULONG *) &nand_memory_area[block].physical_pages[page];
|
||||
|
||||
|
||||
/* Calculate the number of words in a block. */
|
||||
words = WORDS_PER_PHYSICAL_PAGE;
|
||||
|
||||
|
||||
/* Loop to check if the page is erased. */
|
||||
while (words--)
|
||||
{
|
||||
|
||||
|
||||
/* Is this word erased? */
|
||||
if (*word_ptr++ != 0xFFFFFFFF)
|
||||
return(LX_ERROR);
|
||||
}
|
||||
|
||||
|
||||
/* Return success. */
|
||||
return(LX_SUCCESS);
|
||||
}
|
||||
|
||||
|
||||
#ifdef LX_NAND_ENABLE_CONTROL_BLOCK_FOR_DRIVER_INTERFACE
|
||||
UINT _lx_nand_flash_simulator_block_status_get(LX_NAND_FLASH *nand_flash, ULONG block, UCHAR *bad_block_byte)
|
||||
#else
|
||||
UINT _lx_nand_flash_simulator_block_status_get(ULONG block, UCHAR *bad_block_byte)
|
||||
#endif
|
||||
{
|
||||
|
||||
#ifdef LX_NAND_ENABLE_CONTROL_BLOCK_FOR_DRIVER_INTERFACE
|
||||
LX_PARAMETER_NOT_USED(nand_flash);
|
||||
#endif
|
||||
|
||||
/* Pickup the bad block byte and return it. */
|
||||
*bad_block_byte = nand_memory_area[block].physical_pages[0].spare[BAD_BLOCK_POSITION];
|
||||
|
||||
|
||||
/* Return success. */
|
||||
return(LX_SUCCESS);
|
||||
}
|
||||
|
||||
#ifdef LX_NAND_ENABLE_CONTROL_BLOCK_FOR_DRIVER_INTERFACE
|
||||
UINT _lx_nand_flash_simulator_block_status_set(LX_NAND_FLASH *nand_flash, ULONG block, UCHAR bad_block_byte)
|
||||
#else
|
||||
UINT _lx_nand_flash_simulator_block_status_set(ULONG block, UCHAR bad_block_byte)
|
||||
#endif
|
||||
{
|
||||
|
||||
#ifdef LX_NAND_ENABLE_CONTROL_BLOCK_FOR_DRIVER_INTERFACE
|
||||
LX_PARAMETER_NOT_USED(nand_flash);
|
||||
#endif
|
||||
|
||||
/* Set the bad block byte. */
|
||||
nand_memory_area[block].physical_pages[0].spare[BAD_BLOCK_POSITION] = bad_block_byte;
|
||||
|
||||
|
||||
/* Return success. */
|
||||
return(LX_SUCCESS);
|
||||
}
|
||||
|
||||
|
||||
|
||||
#ifdef LX_NAND_ENABLE_CONTROL_BLOCK_FOR_DRIVER_INTERFACE
|
||||
UINT _lx_nand_flash_simulator_extra_bytes_get(LX_NAND_FLASH *nand_flash, ULONG block, ULONG page, UCHAR *destination, UINT size)
|
||||
#else
|
||||
UINT _lx_nand_flash_simulator_extra_bytes_get(ULONG block, ULONG page, UCHAR *destination, UINT size)
|
||||
#endif
|
||||
{
|
||||
|
||||
UCHAR *source;
|
||||
|
||||
|
||||
#ifdef LX_NAND_ENABLE_CONTROL_BLOCK_FOR_DRIVER_INTERFACE
|
||||
LX_PARAMETER_NOT_USED(nand_flash);
|
||||
#endif
|
||||
|
||||
/* Setup source pointer in the spare area. */
|
||||
source = (UCHAR *) &(nand_memory_area[block].physical_pages[page].spare[EXTRA_BYTE_POSITION]);
|
||||
|
||||
|
||||
/* Loop to return the extra bytes requested. */
|
||||
while (size--)
|
||||
{
|
||||
|
||||
|
||||
/* Retrieve an extra byte from the spare area. */
|
||||
*destination++ = *source++;
|
||||
}
|
||||
@@ -357,25 +641,31 @@ UCHAR *source;
|
||||
return(LX_SUCCESS);
|
||||
}
|
||||
|
||||
|
||||
#ifdef LX_NAND_ENABLE_CONTROL_BLOCK_FOR_DRIVER_INTERFACE
|
||||
UINT _lx_nand_flash_simulator_extra_bytes_set(LX_NAND_FLASH *nand_flash, ULONG block, ULONG page, UCHAR *source, UINT size)
|
||||
#else
|
||||
UINT _lx_nand_flash_simulator_extra_bytes_set(ULONG block, ULONG page, UCHAR *source, UINT size)
|
||||
#endif
|
||||
{
|
||||
|
||||
UCHAR *destination;
|
||||
|
||||
|
||||
#ifdef LX_NAND_ENABLE_CONTROL_BLOCK_FOR_DRIVER_INTERFACE
|
||||
LX_PARAMETER_NOT_USED(nand_flash);
|
||||
#endif
|
||||
|
||||
/* Increment the diag info. */
|
||||
nand_block_diag[block].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];
|
||||
|
||||
|
||||
/* Setup destination pointer in the spare area. */
|
||||
destination = (UCHAR *) &(nand_memory_area[block].physical_pages[page].spare[EXTRA_BYTE_POSITION]);
|
||||
|
||||
|
||||
/* Loop to set the extra bytes. */
|
||||
while (size--)
|
||||
{
|
||||
|
||||
|
||||
/* Set an extra byte in the spare area. */
|
||||
*destination++ = *source++;
|
||||
}
|
||||
@@ -384,11 +674,18 @@ UCHAR *destination;
|
||||
return(LX_SUCCESS);
|
||||
}
|
||||
|
||||
#ifdef LX_NAND_ENABLE_CONTROL_BLOCK_FOR_DRIVER_INTERFACE
|
||||
UINT _lx_nand_flash_simulator_system_error(LX_NAND_FLASH *nand_flash, UINT error_code, ULONG block, ULONG page)
|
||||
#else
|
||||
UINT _lx_nand_flash_simulator_system_error(UINT error_code, ULONG block, ULONG page)
|
||||
#endif
|
||||
{
|
||||
LX_PARAMETER_NOT_USED(error_code);
|
||||
LX_PARAMETER_NOT_USED(block);
|
||||
LX_PARAMETER_NOT_USED(page);
|
||||
#ifdef LX_NAND_ENABLE_CONTROL_BLOCK_FOR_DRIVER_INTERFACE
|
||||
LX_PARAMETER_NOT_USED(nand_flash);
|
||||
#endif
|
||||
|
||||
/* Custom processing goes here... all errors except for LX_NAND_ERROR_CORRECTED are fatal. */
|
||||
return(LX_ERROR);
|
||||
|
||||
@@ -1,19 +1,19 @@
|
||||
/**************************************************************************/
|
||||
/* */
|
||||
/* Copyright (c) Microsoft Corporation. All rights reserved. */
|
||||
/* */
|
||||
/* This software is licensed under the Microsoft Software License */
|
||||
/* Terms for Microsoft Azure RTOS. Full text of the license can be */
|
||||
/* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */
|
||||
/* and in the root directory of this software. */
|
||||
/* */
|
||||
/**************************************************************************/
|
||||
/***************************************************************************
|
||||
* Copyright (c) 2024 Microsoft Corporation
|
||||
* Copyright (c) 2026-present Eclipse ThreadX contributors
|
||||
*
|
||||
* This program and the accompanying materials are made available under the
|
||||
* terms of the MIT License which is available at
|
||||
* https://opensource.org/licenses/MIT.
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
**************************************************************************/
|
||||
|
||||
|
||||
/**************************************************************************/
|
||||
/**************************************************************************/
|
||||
/** */
|
||||
/** LevelX Component */
|
||||
/** */
|
||||
/** LevelX Component */
|
||||
/** */
|
||||
/** NAND Flash */
|
||||
/** */
|
||||
@@ -25,8 +25,8 @@
|
||||
|
||||
/* Disable ThreadX error checking. */
|
||||
|
||||
#ifndef TX_DISABLE_ERROR_CHECKING
|
||||
#define TX_DISABLE_ERROR_CHECKING
|
||||
#ifndef LX_DISABLE_ERROR_CHECKING
|
||||
#define LX_DISABLE_ERROR_CHECKING
|
||||
#endif
|
||||
|
||||
|
||||
@@ -35,44 +35,38 @@
|
||||
#include "lx_api.h"
|
||||
|
||||
|
||||
/**************************************************************************/
|
||||
/* */
|
||||
/* FUNCTION RELEASE */
|
||||
/* */
|
||||
/* _lx_nand_flash_system_error PORTABLE C */
|
||||
/* 6.0 */
|
||||
/**************************************************************************/
|
||||
/* */
|
||||
/* FUNCTION RELEASE */
|
||||
/* */
|
||||
/* _lx_nand_flash_system_error PORTABLE C */
|
||||
/* 6.2.1 */
|
||||
/* AUTHOR */
|
||||
/* */
|
||||
/* William E. Lamie, Microsoft Corporation */
|
||||
/* */
|
||||
/* 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 */
|
||||
/* DESCRIPTION */
|
||||
/* */
|
||||
/* 05-19-2020 William E. Lamie Initial Version 6.0 */
|
||||
/* 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 */
|
||||
/* */
|
||||
/**************************************************************************/
|
||||
VOID _lx_nand_flash_system_error(LX_NAND_FLASH *nand_flash, UINT error_code, ULONG block, ULONG page)
|
||||
@@ -80,28 +74,32 @@ VOID _lx_nand_flash_system_error(LX_NAND_FLASH *nand_flash, UINT error_code, UL
|
||||
|
||||
/* Increment the system error counter. */
|
||||
nand_flash -> lx_nand_flash_diagnostic_system_errors++;
|
||||
|
||||
|
||||
/* Save the most recent system error code. */
|
||||
nand_flash -> lx_nand_flash_diagnostic_system_error = error_code;
|
||||
|
||||
|
||||
/* Determine if the system error is a NAND page corrected error. */
|
||||
if (error_code == LX_NAND_ERROR_CORRECTED)
|
||||
{
|
||||
|
||||
|
||||
/* Yes, increment error correction information. */
|
||||
nand_flash -> lx_nand_flash_page_corrections++;
|
||||
|
||||
|
||||
/* Remember the last block/page of corrected error. */
|
||||
nand_flash -> lx_nand_flash_last_block_correction = block;
|
||||
nand_flash -> lx_nand_flash_last_page_correction = page;
|
||||
}
|
||||
|
||||
|
||||
/* Determine if the driver has setup a system error handler. */
|
||||
if (nand_flash -> lx_nand_flash_driver_system_error)
|
||||
{
|
||||
|
||||
|
||||
/* Yes, call the driver's system error handler. */
|
||||
#ifdef LX_NAND_ENABLE_CONTROL_BLOCK_FOR_DRIVER_INTERFACE
|
||||
(nand_flash -> lx_nand_flash_driver_system_error)(nand_flash, error_code, block, page);
|
||||
#else
|
||||
(nand_flash -> lx_nand_flash_driver_system_error)(error_code, block, page);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,19 +1,19 @@
|
||||
/**************************************************************************/
|
||||
/* */
|
||||
/* Copyright (c) Microsoft Corporation. All rights reserved. */
|
||||
/* */
|
||||
/* This software is licensed under the Microsoft Software License */
|
||||
/* Terms for Microsoft Azure RTOS. Full text of the license can be */
|
||||
/* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */
|
||||
/* and in the root directory of this software. */
|
||||
/* */
|
||||
/**************************************************************************/
|
||||
/***************************************************************************
|
||||
* Copyright (c) 2024 Microsoft Corporation
|
||||
* Copyright (c) 2026-present Eclipse ThreadX contributors
|
||||
*
|
||||
* This program and the accompanying materials are made available under the
|
||||
* terms of the MIT License which is available at
|
||||
* https://opensource.org/licenses/MIT.
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
**************************************************************************/
|
||||
|
||||
|
||||
/**************************************************************************/
|
||||
/**************************************************************************/
|
||||
/** */
|
||||
/** LevelX Component */
|
||||
/** */
|
||||
/** LevelX Component */
|
||||
/** */
|
||||
/** NOR Flash */
|
||||
/** */
|
||||
@@ -25,8 +25,8 @@
|
||||
|
||||
/* Disable ThreadX error checking. */
|
||||
|
||||
#ifndef TX_DISABLE_ERROR_CHECKING
|
||||
#define TX_DISABLE_ERROR_CHECKING
|
||||
#ifndef LX_DISABLE_ERROR_CHECKING
|
||||
#define LX_DISABLE_ERROR_CHECKING
|
||||
#endif
|
||||
|
||||
|
||||
@@ -35,50 +35,44 @@
|
||||
#include "lx_api.h"
|
||||
|
||||
|
||||
/**************************************************************************/
|
||||
/* */
|
||||
/* FUNCTION RELEASE */
|
||||
/* */
|
||||
/* _lx_nor_flash_block_reclaim PORTABLE C */
|
||||
/* 6.0 */
|
||||
/**************************************************************************/
|
||||
/* */
|
||||
/* FUNCTION RELEASE */
|
||||
/* */
|
||||
/* _lx_nor_flash_block_reclaim PORTABLE C */
|
||||
/* 6.3.0 */
|
||||
/* AUTHOR */
|
||||
/* */
|
||||
/* William E. Lamie, Microsoft Corporation */
|
||||
/* */
|
||||
/* 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 */
|
||||
/* DESCRIPTION */
|
||||
/* */
|
||||
/* 05-19-2020 William E. Lamie Initial Version 6.0 */
|
||||
/* 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 */
|
||||
/* */
|
||||
/**************************************************************************/
|
||||
UINT _lx_nor_flash_block_reclaim(LX_NOR_FLASH *nor_flash)
|
||||
@@ -108,10 +102,10 @@ UINT status;
|
||||
/* Determine if the search pointer is set for this 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. */
|
||||
nor_flash -> lx_nor_flash_free_block_search = erase_block + 1;
|
||||
|
||||
|
||||
/* Check for wrap condition. */
|
||||
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;
|
||||
@@ -124,71 +118,79 @@ UINT status;
|
||||
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;
|
||||
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.. */
|
||||
if (status)
|
||||
{
|
||||
|
||||
|
||||
/* Call system error handler. */
|
||||
_lx_nor_flash_system_error(nor_flash, status);
|
||||
|
||||
/* Return the error. */
|
||||
return(status);
|
||||
}
|
||||
|
||||
|
||||
/* Erase the entire block. */
|
||||
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.. */
|
||||
if (status)
|
||||
{
|
||||
|
||||
|
||||
/* Call system error handler. */
|
||||
_lx_nor_flash_system_error(nor_flash, status);
|
||||
|
||||
|
||||
/* Return the error. */
|
||||
return(status);
|
||||
}
|
||||
|
||||
|
||||
/* Determine if the erase count is at the minimum. */
|
||||
if (erase_count == nor_flash -> lx_nor_flash_minimum_erase_count)
|
||||
{
|
||||
|
||||
/* Yes, decrement the minimum erased block count. */
|
||||
nor_flash -> lx_nor_flash_minimum_erased_blocks--;
|
||||
}
|
||||
|
||||
/* Increment the erase count. */
|
||||
erase_count++;
|
||||
erase_count++;
|
||||
|
||||
/* Determine if the new erase count exceeds the maximum. */
|
||||
if (erase_count > ((ULONG) LX_BLOCK_ERASE_COUNT_MAX))
|
||||
{
|
||||
|
||||
|
||||
/* Yes, erase count is in overflow. Stay at the maximum count. */
|
||||
erase_count = ((ULONG) LX_BLOCK_ERASE_COUNT_MAX);
|
||||
}
|
||||
|
||||
|
||||
/* Determine if we need to update the maximum erase count. */
|
||||
if (erase_count > nor_flash -> lx_nor_flash_maximum_erase_count)
|
||||
{
|
||||
|
||||
|
||||
/* Yes, a new maximum is present. */
|
||||
nor_flash -> lx_nor_flash_maximum_erase_count = erase_count;
|
||||
}
|
||||
|
||||
|
||||
/* 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 + (nor_flash -> lx_nor_flash_block_bit_map_words - 1)),
|
||||
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 + (nor_flash -> lx_nor_flash_block_bit_map_words - 1)),
|
||||
&(nor_flash -> lx_nor_flash_block_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 the error. */
|
||||
return(status);
|
||||
}
|
||||
|
||||
|
||||
/* Write the initial erase count for the block with upper bit set. */
|
||||
temp_erase_count = (erase_count | LX_BLOCK_ERASED);
|
||||
status = _lx_nor_flash_driver_write(nor_flash, block_word_ptr, &temp_erase_count, 1);
|
||||
@@ -196,7 +198,7 @@ UINT status;
|
||||
/* 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);
|
||||
|
||||
@@ -210,28 +212,38 @@ UINT status;
|
||||
/* 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 the error. */
|
||||
return(status);
|
||||
}
|
||||
|
||||
|
||||
/* 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_obsolete_physical_sectors = nor_flash -> lx_nor_flash_obsolete_physical_sectors - obsolete_sectors;
|
||||
#ifdef LX_NOR_ENABLE_OBSOLETE_COUNT_CACHE
|
||||
|
||||
/* Check if the block is cached by obsolete count cache. */
|
||||
if (erase_block < nor_flash -> lx_nor_flash_extended_cache_obsolete_count_max_block)
|
||||
{
|
||||
|
||||
/* Yes, clear the obsolete count for this block. */
|
||||
nor_flash -> lx_nor_flash_extended_cache_obsolete_count[erase_block] = 0;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
else
|
||||
else
|
||||
{
|
||||
|
||||
|
||||
/* Calculate the number of free sectors in this block. */
|
||||
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. */
|
||||
if (mapped_sectors <= (nor_flash -> lx_nor_flash_free_physical_sectors - free_sectors))
|
||||
{
|
||||
|
||||
|
||||
/* Setup a pointer to the mapped list. */
|
||||
list_word_ptr = block_word_ptr + nor_flash -> lx_nor_flash_block_physical_sector_mapping_offset;
|
||||
|
||||
@@ -241,7 +253,7 @@ UINT status;
|
||||
|
||||
/* Pickup the mapped sector list entry. */
|
||||
#ifdef LX_DIRECT_READ
|
||||
|
||||
|
||||
/* Read the word directly. */
|
||||
list_word = *(list_word_ptr);
|
||||
#else
|
||||
@@ -250,7 +262,7 @@ UINT status;
|
||||
/* 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);
|
||||
|
||||
@@ -262,33 +274,33 @@ UINT status;
|
||||
/* Determine if the entry hasn't been used. */
|
||||
if (list_word == LX_NOR_PHYSICAL_SECTOR_FREE)
|
||||
{
|
||||
|
||||
|
||||
/* Since allocations are done sequentially in the block, we know nothing
|
||||
else exists after this point. */
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
/* Is this entry mapped? */
|
||||
if (list_word & LX_NOR_PHYSICAL_SECTOR_VALID)
|
||||
{
|
||||
|
||||
|
||||
/* Pickup the logical sector associated with this mapped physical sector. */
|
||||
logical_sector = list_word & LX_NOR_LOGICAL_SECTOR_MASK;
|
||||
|
||||
/* Invalidate the old sector mapping cache entry. */
|
||||
_lx_nor_flash_sector_mapping_cache_invalidate(nor_flash, logical_sector);
|
||||
|
||||
|
||||
/* Allocate a new physical sector for this write. */
|
||||
_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. */
|
||||
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
|
||||
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;
|
||||
|
||||
|
||||
/* Check for wrap condition. */
|
||||
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;
|
||||
@@ -302,7 +314,7 @@ UINT status;
|
||||
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. */
|
||||
new_mapping_address = LX_NULL;
|
||||
}
|
||||
@@ -311,9 +323,9 @@ UINT status;
|
||||
/* Determine if the new sector allocation was successful. */
|
||||
if (new_mapping_address)
|
||||
{
|
||||
|
||||
|
||||
/* Yes, we were able to allocate a new physical sector. */
|
||||
|
||||
|
||||
#ifdef LX_DIRECT_READ
|
||||
/* 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) +
|
||||
@@ -322,7 +334,7 @@ UINT status;
|
||||
/* 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);
|
||||
|
||||
@@ -340,7 +352,7 @@ UINT status;
|
||||
/* 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);
|
||||
|
||||
@@ -354,7 +366,7 @@ UINT status;
|
||||
/* 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);
|
||||
|
||||
@@ -364,34 +376,34 @@ UINT status;
|
||||
#endif
|
||||
|
||||
/* Now deprecate the old sector mapping. */
|
||||
|
||||
|
||||
/* Clear bit 30, which indicates this sector is superceded. */
|
||||
list_word = list_word & ~((ULONG) LX_NOR_PHYSICAL_SECTOR_SUPERCEDED);
|
||||
|
||||
|
||||
/* 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);
|
||||
|
||||
|
||||
/* 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 the error. */
|
||||
return(status);
|
||||
}
|
||||
|
||||
|
||||
/* 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;
|
||||
|
||||
|
||||
/* Write out the new mapping entry. */
|
||||
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.. */
|
||||
if (status)
|
||||
{
|
||||
|
||||
|
||||
/* Call system error handler. */
|
||||
_lx_nor_flash_system_error(nor_flash, status);
|
||||
|
||||
@@ -399,17 +411,17 @@ UINT 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. */
|
||||
new_mapping_entry = new_mapping_entry & ~((ULONG) LX_NOR_PHYSICAL_SECTOR_MAPPING_NOT_VALID);
|
||||
|
||||
|
||||
/* Clear the not valid bit. */
|
||||
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.. */
|
||||
if (status)
|
||||
{
|
||||
|
||||
|
||||
/* Call system error handler. */
|
||||
_lx_nor_flash_system_error(nor_flash, status);
|
||||
|
||||
@@ -419,14 +431,14 @@ UINT status;
|
||||
|
||||
/* Now clear bit 31, which indicates this sector is now obsoleted. */
|
||||
list_word = list_word & ~((ULONG) LX_NOR_PHYSICAL_SECTOR_VALID);
|
||||
|
||||
|
||||
/* 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);
|
||||
|
||||
/* 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);
|
||||
|
||||
@@ -443,10 +455,10 @@ UINT status;
|
||||
/* Return the error. */
|
||||
return(status);
|
||||
}
|
||||
|
||||
|
||||
/* Decrement the number of mapped sectors. */
|
||||
mapped_sectors--;
|
||||
|
||||
|
||||
/* Determine if we are done. */
|
||||
if (mapped_sectors == 0)
|
||||
break;
|
||||
@@ -456,42 +468,50 @@ UINT status;
|
||||
list_word_ptr++;
|
||||
}
|
||||
|
||||
/* Write the erased started indication. */
|
||||
/* Write the erased started indication. */
|
||||
erase_started_value = LX_BLOCK_ERASE_STARTED;
|
||||
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.. */
|
||||
if (status)
|
||||
{
|
||||
|
||||
|
||||
/* Call system error handler. */
|
||||
_lx_nor_flash_system_error(nor_flash, status);
|
||||
|
||||
/* Return the error. */
|
||||
return(status);
|
||||
}
|
||||
|
||||
|
||||
/* Erase the entire block. */
|
||||
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.. */
|
||||
if (status)
|
||||
{
|
||||
|
||||
|
||||
/* Call system error handler. */
|
||||
_lx_nor_flash_system_error(nor_flash, status);
|
||||
|
||||
/* Return the error. */
|
||||
return(status);
|
||||
}
|
||||
|
||||
|
||||
/* Determine if the erase count is at the minimum. */
|
||||
if (erase_count == nor_flash -> lx_nor_flash_minimum_erase_count)
|
||||
{
|
||||
|
||||
/* Yes, decrement the minimum erased block count. */
|
||||
nor_flash -> lx_nor_flash_minimum_erased_blocks--;
|
||||
}
|
||||
|
||||
/* Increment the erase count. */
|
||||
erase_count++;
|
||||
erase_count++;
|
||||
|
||||
/* Determine if the new erase count exceeds the maximum. */
|
||||
if (erase_count > ((ULONG) LX_BLOCK_ERASE_COUNT_MAX))
|
||||
{
|
||||
|
||||
|
||||
/* Yes, erase count is in overflow. Stay at the maximum count. */
|
||||
erase_count = ((ULONG) LX_BLOCK_ERASE_COUNT_MAX);
|
||||
}
|
||||
@@ -499,21 +519,21 @@ UINT status;
|
||||
/* Determine if we need to update the maximum erase count. */
|
||||
if (erase_count > nor_flash -> lx_nor_flash_maximum_erase_count)
|
||||
{
|
||||
|
||||
|
||||
/* Yes, a new maximum is present. */
|
||||
nor_flash -> lx_nor_flash_maximum_erase_count = erase_count;
|
||||
}
|
||||
|
||||
|
||||
/* 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 + (nor_flash -> lx_nor_flash_block_bit_map_words - 1)) ,
|
||||
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 + (nor_flash -> lx_nor_flash_block_bit_map_words - 1)) ,
|
||||
&(nor_flash -> lx_nor_flash_block_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);
|
||||
|
||||
@@ -528,7 +548,7 @@ UINT status;
|
||||
/* 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);
|
||||
|
||||
@@ -542,7 +562,7 @@ UINT status;
|
||||
/* 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);
|
||||
|
||||
@@ -553,6 +573,16 @@ UINT status;
|
||||
/* 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_obsolete_physical_sectors = nor_flash -> lx_nor_flash_obsolete_physical_sectors - obsolete_sectors;
|
||||
#ifdef LX_NOR_ENABLE_OBSOLETE_COUNT_CACHE
|
||||
|
||||
/* Check if the block is cached by obsolete count cache. */
|
||||
if (erase_block < nor_flash -> lx_nor_flash_extended_cache_obsolete_count_max_block)
|
||||
{
|
||||
|
||||
/* Yes, clear the obsolete count for this block. */
|
||||
nor_flash -> lx_nor_flash_extended_cache_obsolete_count[erase_block] = 0;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,19 +1,19 @@
|
||||
/**************************************************************************/
|
||||
/* */
|
||||
/* Copyright (c) Microsoft Corporation. All rights reserved. */
|
||||
/* */
|
||||
/* This software is licensed under the Microsoft Software License */
|
||||
/* Terms for Microsoft Azure RTOS. Full text of the license can be */
|
||||
/* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */
|
||||
/* and in the root directory of this software. */
|
||||
/* */
|
||||
/**************************************************************************/
|
||||
/***************************************************************************
|
||||
* Copyright (c) 2024 Microsoft Corporation
|
||||
* Copyright (c) 2026-present Eclipse ThreadX contributors
|
||||
*
|
||||
* This program and the accompanying materials are made available under the
|
||||
* terms of the MIT License which is available at
|
||||
* https://opensource.org/licenses/MIT.
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
**************************************************************************/
|
||||
|
||||
|
||||
/**************************************************************************/
|
||||
/**************************************************************************/
|
||||
/** */
|
||||
/** LevelX Component */
|
||||
/** */
|
||||
/** LevelX Component */
|
||||
/** */
|
||||
/** NOR Flash */
|
||||
/** */
|
||||
@@ -25,8 +25,8 @@
|
||||
|
||||
/* Disable ThreadX error checking. */
|
||||
|
||||
#ifndef TX_DISABLE_ERROR_CHECKING
|
||||
#define TX_DISABLE_ERROR_CHECKING
|
||||
#ifndef LX_DISABLE_ERROR_CHECKING
|
||||
#define LX_DISABLE_ERROR_CHECKING
|
||||
#endif
|
||||
|
||||
|
||||
@@ -35,51 +35,45 @@
|
||||
#include "lx_api.h"
|
||||
|
||||
|
||||
/**************************************************************************/
|
||||
/* */
|
||||
/* FUNCTION RELEASE */
|
||||
/* */
|
||||
/* _lx_nor_flash_close PORTABLE C */
|
||||
/* 6.0 */
|
||||
/**************************************************************************/
|
||||
/* */
|
||||
/* FUNCTION RELEASE */
|
||||
/* */
|
||||
/* _lx_nor_flash_close PORTABLE C */
|
||||
/* 6.1.7 */
|
||||
/* AUTHOR */
|
||||
/* */
|
||||
/* William E. Lamie, Microsoft Corporation */
|
||||
/* */
|
||||
/* 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 */
|
||||
/* DESCRIPTION */
|
||||
/* */
|
||||
/* 05-19-2020 William E. Lamie Initial Version 6.0 */
|
||||
/* 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 */
|
||||
/* */
|
||||
/**************************************************************************/
|
||||
UINT _lx_nor_flash_close(LX_NOR_FLASH *nor_flash)
|
||||
{
|
||||
|
||||
TX_INTERRUPT_SAVE_AREA
|
||||
LX_INTERRUPT_SAVE_AREA
|
||||
|
||||
|
||||
/* Lockout interrupts for NOR flash close. */
|
||||
TX_DISABLE
|
||||
LX_DISABLE
|
||||
|
||||
/* See if the media is the only one on the media opened list. */
|
||||
if ((_lx_nor_flash_opened_ptr == nor_flash) &&
|
||||
@@ -102,9 +96,9 @@ TX_INTERRUPT_SAVE_AREA
|
||||
/* See if we have to update the opened list head pointer. */
|
||||
if (_lx_nor_flash_opened_ptr == 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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -113,9 +107,9 @@ TX_INTERRUPT_SAVE_AREA
|
||||
|
||||
/* Finally, indicate that this NOR flash is closed. */
|
||||
nor_flash -> lx_nor_flash_state = LX_NOR_FLASH_CLOSED;
|
||||
|
||||
|
||||
/* Restore interrupt posture. */
|
||||
TX_RESTORE
|
||||
LX_RESTORE
|
||||
|
||||
#ifdef LX_THREAD_SAFE_ENABLE
|
||||
|
||||
|
||||
@@ -1,19 +1,19 @@
|
||||
/**************************************************************************/
|
||||
/* */
|
||||
/* Copyright (c) Microsoft Corporation. All rights reserved. */
|
||||
/* */
|
||||
/* This software is licensed under the Microsoft Software License */
|
||||
/* Terms for Microsoft Azure RTOS. Full text of the license can be */
|
||||
/* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */
|
||||
/* and in the root directory of this software. */
|
||||
/* */
|
||||
/**************************************************************************/
|
||||
/***************************************************************************
|
||||
* Copyright (c) 2024 Microsoft Corporation
|
||||
* Copyright (c) 2026-present Eclipse ThreadX contributors
|
||||
*
|
||||
* This program and the accompanying materials are made available under the
|
||||
* terms of the MIT License which is available at
|
||||
* https://opensource.org/licenses/MIT.
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
**************************************************************************/
|
||||
|
||||
|
||||
/**************************************************************************/
|
||||
/**************************************************************************/
|
||||
/** */
|
||||
/** LevelX Component */
|
||||
/** */
|
||||
/** LevelX Component */
|
||||
/** */
|
||||
/** NOR Flash */
|
||||
/** */
|
||||
@@ -25,8 +25,8 @@
|
||||
|
||||
/* Disable ThreadX error checking. */
|
||||
|
||||
#ifndef TX_DISABLE_ERROR_CHECKING
|
||||
#define TX_DISABLE_ERROR_CHECKING
|
||||
#ifndef LX_DISABLE_ERROR_CHECKING
|
||||
#define LX_DISABLE_ERROR_CHECKING
|
||||
#endif
|
||||
|
||||
|
||||
@@ -35,49 +35,43 @@
|
||||
#include "lx_api.h"
|
||||
|
||||
|
||||
/**************************************************************************/
|
||||
/* */
|
||||
/* FUNCTION RELEASE */
|
||||
/* */
|
||||
/* _lx_nor_flash_defragment PORTABLE C */
|
||||
/* 6.0 */
|
||||
/**************************************************************************/
|
||||
/* */
|
||||
/* FUNCTION RELEASE */
|
||||
/* */
|
||||
/* _lx_nor_flash_defragment PORTABLE C */
|
||||
/* 6.1.7 */
|
||||
/* AUTHOR */
|
||||
/* */
|
||||
/* William E. Lamie, Microsoft Corporation */
|
||||
/* */
|
||||
/* 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 */
|
||||
/* DESCRIPTION */
|
||||
/* */
|
||||
/* 05-19-2020 William E. Lamie Initial Version 6.0 */
|
||||
/* 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 */
|
||||
/* */
|
||||
/**************************************************************************/
|
||||
UINT _lx_nor_flash_defragment(LX_NOR_FLASH *nor_flash)
|
||||
{
|
||||
|
||||
|
||||
ULONG i;
|
||||
|
||||
|
||||
@@ -90,11 +84,11 @@ ULONG i;
|
||||
/* Loop for max number of blocks, while there are obsolete count. */
|
||||
for (i = 0; i < nor_flash -> lx_nor_flash_total_blocks; i++)
|
||||
{
|
||||
|
||||
|
||||
/* Determine if there is any more defragment work. */
|
||||
if (nor_flash -> lx_nor_flash_obsolete_physical_sectors == 0)
|
||||
break;
|
||||
|
||||
break;
|
||||
|
||||
/* Call the block reclaim function to defragment. */
|
||||
_lx_nor_flash_block_reclaim(nor_flash);
|
||||
}
|
||||
@@ -105,7 +99,7 @@ ULONG i;
|
||||
tx_mutex_put(&nor_flash -> lx_nor_flash_mutex);
|
||||
#endif
|
||||
|
||||
/* Return successful completion. */
|
||||
/* Return successful completion. */
|
||||
return(LX_SUCCESS);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,19 +1,19 @@
|
||||
/**************************************************************************/
|
||||
/* */
|
||||
/* Copyright (c) Microsoft Corporation. All rights reserved. */
|
||||
/* */
|
||||
/* This software is licensed under the Microsoft Software License */
|
||||
/* Terms for Microsoft Azure RTOS. Full text of the license can be */
|
||||
/* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */
|
||||
/* and in the root directory of this software. */
|
||||
/* */
|
||||
/**************************************************************************/
|
||||
/***************************************************************************
|
||||
* Copyright (c) 2024 Microsoft Corporation
|
||||
* Copyright (c) 2026-present Eclipse ThreadX contributors
|
||||
*
|
||||
* This program and the accompanying materials are made available under the
|
||||
* terms of the MIT License which is available at
|
||||
* https://opensource.org/licenses/MIT.
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
**************************************************************************/
|
||||
|
||||
|
||||
/**************************************************************************/
|
||||
/**************************************************************************/
|
||||
/** */
|
||||
/** LevelX Component */
|
||||
/** */
|
||||
/** LevelX Component */
|
||||
/** */
|
||||
/** NOR Flash */
|
||||
/** */
|
||||
@@ -25,8 +25,8 @@
|
||||
|
||||
/* Disable ThreadX error checking. */
|
||||
|
||||
#ifndef TX_DISABLE_ERROR_CHECKING
|
||||
#define TX_DISABLE_ERROR_CHECKING
|
||||
#ifndef LX_DISABLE_ERROR_CHECKING
|
||||
#define LX_DISABLE_ERROR_CHECKING
|
||||
#endif
|
||||
|
||||
|
||||
@@ -35,43 +35,37 @@
|
||||
#include "lx_api.h"
|
||||
|
||||
|
||||
/**************************************************************************/
|
||||
/* */
|
||||
/* FUNCTION RELEASE */
|
||||
/* */
|
||||
/* _lx_nor_flash_driver_block_erase PORTABLE C */
|
||||
/* 6.0 */
|
||||
/**************************************************************************/
|
||||
/* */
|
||||
/* FUNCTION RELEASE */
|
||||
/* */
|
||||
/* _lx_nor_flash_driver_block_erase PORTABLE C */
|
||||
/* 6.2.1 */
|
||||
/* AUTHOR */
|
||||
/* */
|
||||
/* William E. Lamie, Microsoft Corporation */
|
||||
/* */
|
||||
/* 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 */
|
||||
/* DESCRIPTION */
|
||||
/* */
|
||||
/* 05-19-2020 William E. Lamie Initial Version 6.0 */
|
||||
/* 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 */
|
||||
/* */
|
||||
/**************************************************************************/
|
||||
UINT _lx_nor_flash_driver_block_erase(LX_NOR_FLASH *nor_flash, ULONG block, ULONG erase_count)
|
||||
@@ -91,21 +85,21 @@ ULONG *cache_entry_end;
|
||||
/* 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_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. */
|
||||
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. */
|
||||
|
||||
|
||||
/* 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_end = cache_entry_start + LX_NOR_SECTOR_SIZE;
|
||||
|
||||
|
||||
/* 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))
|
||||
{
|
||||
|
||||
|
||||
/* 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_access_count = 0;
|
||||
@@ -114,10 +108,14 @@ ULONG *cache_entry_end;
|
||||
#endif
|
||||
|
||||
/* Call the actual driver block erase function. */
|
||||
#ifdef LX_NOR_ENABLE_CONTROL_BLOCK_FOR_DRIVER_INTERFACE
|
||||
status = (nor_flash -> lx_nor_flash_driver_block_erase)(nor_flash, block, erase_count);
|
||||
#else
|
||||
status = (nor_flash -> lx_nor_flash_driver_block_erase)(block, erase_count);
|
||||
#endif
|
||||
|
||||
/* Return completion status. */
|
||||
return(status);
|
||||
return(status);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -1,19 +1,19 @@
|
||||
/**************************************************************************/
|
||||
/* */
|
||||
/* Copyright (c) Microsoft Corporation. All rights reserved. */
|
||||
/* */
|
||||
/* This software is licensed under the Microsoft Software License */
|
||||
/* Terms for Microsoft Azure RTOS. Full text of the license can be */
|
||||
/* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */
|
||||
/* and in the root directory of this software. */
|
||||
/* */
|
||||
/**************************************************************************/
|
||||
/***************************************************************************
|
||||
* Copyright (c) 2024 Microsoft Corporation
|
||||
* Copyright (c) 2026-present Eclipse ThreadX contributors
|
||||
*
|
||||
* This program and the accompanying materials are made available under the
|
||||
* terms of the MIT License which is available at
|
||||
* https://opensource.org/licenses/MIT.
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
**************************************************************************/
|
||||
|
||||
|
||||
/**************************************************************************/
|
||||
/**************************************************************************/
|
||||
/** */
|
||||
/** LevelX Component */
|
||||
/** */
|
||||
/** LevelX Component */
|
||||
/** */
|
||||
/** NOR Flash */
|
||||
/** */
|
||||
@@ -25,8 +25,8 @@
|
||||
|
||||
/* Disable ThreadX error checking. */
|
||||
|
||||
#ifndef TX_DISABLE_ERROR_CHECKING
|
||||
#define TX_DISABLE_ERROR_CHECKING
|
||||
#ifndef LX_DISABLE_ERROR_CHECKING
|
||||
#define LX_DISABLE_ERROR_CHECKING
|
||||
#endif
|
||||
|
||||
|
||||
@@ -35,44 +35,38 @@
|
||||
#include "lx_api.h"
|
||||
|
||||
|
||||
/**************************************************************************/
|
||||
/* */
|
||||
/* FUNCTION RELEASE */
|
||||
/* */
|
||||
/* _lx_nor_flash_extended_cache_read PORTABLE C */
|
||||
/* 6.0 */
|
||||
/**************************************************************************/
|
||||
/* */
|
||||
/* FUNCTION RELEASE */
|
||||
/* */
|
||||
/* _lx_nor_flash_extended_cache_read PORTABLE C */
|
||||
/* 6.2.1 */
|
||||
/* AUTHOR */
|
||||
/* */
|
||||
/* William E. Lamie, Microsoft Corporation */
|
||||
/* */
|
||||
/* 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 */
|
||||
/* DESCRIPTION */
|
||||
/* */
|
||||
/* 05-19-2020 William E. Lamie Initial Version 6.0 */
|
||||
/* 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 */
|
||||
/* */
|
||||
/**************************************************************************/
|
||||
UINT _lx_nor_flash_driver_read(LX_NOR_FLASH *nor_flash, ULONG *flash_address, ULONG *destination, ULONG words)
|
||||
@@ -92,57 +86,57 @@ UINT least_used_cache_entry;
|
||||
{
|
||||
|
||||
/* One word request, which implies that it is a NOR flash metadata read. */
|
||||
|
||||
|
||||
|
||||
|
||||
/* Initialize the least used cache entry. */
|
||||
least_used_cache_entry = 0;
|
||||
|
||||
|
||||
do
|
||||
{
|
||||
{
|
||||
|
||||
/* 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++)
|
||||
{
|
||||
|
||||
|
||||
/* Search through the cache to find the entry. */
|
||||
|
||||
|
||||
/* 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_end = cache_entry_start + LX_NOR_SECTOR_SIZE;
|
||||
|
||||
|
||||
/* Determine if the flash address in in the cache entry. */
|
||||
if ((cache_entry_start) && (flash_address >= cache_entry_start) && (flash_address < cache_entry_end))
|
||||
{
|
||||
|
||||
|
||||
/* Yes, we found the entry. */
|
||||
|
||||
|
||||
/* Increment the accessed count. */
|
||||
nor_flash -> lx_nor_flash_extended_cache[i].lx_nor_flash_extended_cache_entry_access_count++;
|
||||
|
||||
|
||||
/* Calculate the offset into the cache entry. */
|
||||
cache_offset = (ULONG)(flash_address - cache_entry_start);
|
||||
|
||||
|
||||
/* 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);
|
||||
|
||||
|
||||
/* Increment the number of cache hits. */
|
||||
nor_flash -> lx_nor_flash_extended_cache_hits++;
|
||||
|
||||
|
||||
/* Return success. */
|
||||
return(LX_SUCCESS);
|
||||
return(LX_SUCCESS);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
|
||||
/* Determine if we have a new least used sector. */
|
||||
if (i != least_used_cache_entry)
|
||||
{
|
||||
|
||||
|
||||
/* 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 <
|
||||
nor_flash -> lx_nor_flash_extended_cache[least_used_cache_entry].lx_nor_flash_extended_cache_entry_access_count)
|
||||
{
|
||||
|
||||
|
||||
/* New least used entry. */
|
||||
least_used_cache_entry = i;
|
||||
}
|
||||
@@ -154,53 +148,67 @@ UINT least_used_cache_entry;
|
||||
cache_offset = (ULONG)(flash_address - nor_flash -> lx_nor_flash_base_address);
|
||||
cache_offset = cache_offset & ~((ULONG) (LX_NOR_SECTOR_SIZE-1));
|
||||
cache_entry_start = nor_flash -> lx_nor_flash_base_address + cache_offset;
|
||||
|
||||
|
||||
/* Call the actual driver read function. */
|
||||
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,
|
||||
#ifdef LX_NOR_ENABLE_CONTROL_BLOCK_FOR_DRIVER_INTERFACE
|
||||
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,
|
||||
LX_NOR_SECTOR_SIZE);
|
||||
|
||||
#else
|
||||
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,
|
||||
LX_NOR_SECTOR_SIZE);
|
||||
#endif
|
||||
|
||||
/* Determine if there was an error. */
|
||||
if (status != LX_SUCCESS)
|
||||
{
|
||||
|
||||
|
||||
/* Return the error to the caller. */
|
||||
return(status);
|
||||
}
|
||||
|
||||
|
||||
/* 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_access_count = 0;
|
||||
|
||||
|
||||
/* Increment the number of 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. */
|
||||
nor_flash -> lx_nor_flash_extended_cache_hits--;
|
||||
|
||||
|
||||
} while (status == LX_SUCCESS);
|
||||
|
||||
|
||||
/* Return success. */
|
||||
return(LX_SUCCESS);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
|
||||
/* Call the actual driver read function. */
|
||||
#ifdef LX_NOR_ENABLE_CONTROL_BLOCK_FOR_DRIVER_INTERFACE
|
||||
status = (nor_flash -> lx_nor_flash_driver_read)(nor_flash, flash_address, destination, words);
|
||||
#else
|
||||
status = (nor_flash -> lx_nor_flash_driver_read)(flash_address, destination, words);
|
||||
#endif
|
||||
|
||||
/* Return completion status. */
|
||||
return(status);
|
||||
return(status);
|
||||
}
|
||||
#else
|
||||
UINT status;
|
||||
|
||||
|
||||
/* Call the actual driver read function. */
|
||||
#ifdef LX_NOR_ENABLE_CONTROL_BLOCK_FOR_DRIVER_INTERFACE
|
||||
status = (nor_flash -> lx_nor_flash_driver_read)(nor_flash, flash_address, destination, words);
|
||||
#else
|
||||
status = (nor_flash -> lx_nor_flash_driver_read)(flash_address, destination, words);
|
||||
#endif
|
||||
|
||||
/* Return completion status. */
|
||||
return(status);
|
||||
return(status);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
@@ -1,19 +1,19 @@
|
||||
/**************************************************************************/
|
||||
/* */
|
||||
/* Copyright (c) Microsoft Corporation. All rights reserved. */
|
||||
/* */
|
||||
/* This software is licensed under the Microsoft Software License */
|
||||
/* Terms for Microsoft Azure RTOS. Full text of the license can be */
|
||||
/* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */
|
||||
/* and in the root directory of this software. */
|
||||
/* */
|
||||
/**************************************************************************/
|
||||
/***************************************************************************
|
||||
* Copyright (c) 2024 Microsoft Corporation
|
||||
* Copyright (c) 2026-present Eclipse ThreadX contributors
|
||||
*
|
||||
* This program and the accompanying materials are made available under the
|
||||
* terms of the MIT License which is available at
|
||||
* https://opensource.org/licenses/MIT.
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
**************************************************************************/
|
||||
|
||||
|
||||
/**************************************************************************/
|
||||
/**************************************************************************/
|
||||
/** */
|
||||
/** LevelX Component */
|
||||
/** */
|
||||
/** LevelX Component */
|
||||
/** */
|
||||
/** NOR Flash */
|
||||
/** */
|
||||
@@ -25,8 +25,8 @@
|
||||
|
||||
/* Disable ThreadX error checking. */
|
||||
|
||||
#ifndef TX_DISABLE_ERROR_CHECKING
|
||||
#define TX_DISABLE_ERROR_CHECKING
|
||||
#ifndef LX_DISABLE_ERROR_CHECKING
|
||||
#define LX_DISABLE_ERROR_CHECKING
|
||||
#endif
|
||||
|
||||
|
||||
@@ -35,44 +35,38 @@
|
||||
#include "lx_api.h"
|
||||
|
||||
|
||||
/**************************************************************************/
|
||||
/* */
|
||||
/* FUNCTION RELEASE */
|
||||
/* */
|
||||
/* _lx_nor_flash_driver_write PORTABLE C */
|
||||
/* 6.0 */
|
||||
/**************************************************************************/
|
||||
/* */
|
||||
/* FUNCTION RELEASE */
|
||||
/* */
|
||||
/* _lx_nor_flash_driver_write PORTABLE C */
|
||||
/* 6.2.1 */
|
||||
/* AUTHOR */
|
||||
/* */
|
||||
/* William E. Lamie, Microsoft Corporation */
|
||||
/* */
|
||||
/* 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 */
|
||||
/* DESCRIPTION */
|
||||
/* */
|
||||
/* 05-19-2020 William E. Lamie Initial Version 6.0 */
|
||||
/* 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 */
|
||||
/* */
|
||||
/**************************************************************************/
|
||||
UINT _lx_nor_flash_driver_write(LX_NOR_FLASH *nor_flash, ULONG *flash_address, ULONG *source, ULONG words)
|
||||
@@ -96,46 +90,54 @@ ULONG cache_offset;
|
||||
/* 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++)
|
||||
{
|
||||
|
||||
|
||||
/* Search through the cache to see if there is a cache entry. */
|
||||
|
||||
|
||||
/* 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_end = cache_entry_start + LX_NOR_SECTOR_SIZE;
|
||||
|
||||
|
||||
/* Determine if the flash address in in the cache entry. */
|
||||
if ((cache_entry_start) && (flash_address >= cache_entry_start) && (flash_address < cache_entry_end))
|
||||
{
|
||||
|
||||
|
||||
/* Yes, we found the entry. */
|
||||
|
||||
|
||||
/* Calculate the offset into the cache entry. */
|
||||
cache_offset = (ULONG)(flash_address - cache_entry_start);
|
||||
|
||||
|
||||
/* 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;
|
||||
|
||||
|
||||
/* Get out of the loop. */
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* In any case, call the actual driver write function. */
|
||||
#ifdef LX_NOR_ENABLE_CONTROL_BLOCK_FOR_DRIVER_INTERFACE
|
||||
status = (nor_flash -> lx_nor_flash_driver_write)(nor_flash, flash_address, source, words);
|
||||
#else
|
||||
status = (nor_flash -> lx_nor_flash_driver_write)(flash_address, source, words);
|
||||
|
||||
#endif
|
||||
|
||||
/* Return completion status. */
|
||||
return(status);
|
||||
|
||||
return(status);
|
||||
|
||||
#else
|
||||
UINT status;
|
||||
|
||||
|
||||
/* Call the actual driver write function. */
|
||||
#ifdef LX_NOR_ENABLE_CONTROL_BLOCK_FOR_DRIVER_INTERFACE
|
||||
status = (nor_flash -> lx_nor_flash_driver_write)(nor_flash, flash_address, source, words);
|
||||
#else
|
||||
status = (nor_flash -> lx_nor_flash_driver_write)(flash_address, source, words);
|
||||
|
||||
#endif
|
||||
|
||||
/* Return completion status. */
|
||||
return(status);
|
||||
return(status);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
@@ -1,19 +1,19 @@
|
||||
/**************************************************************************/
|
||||
/* */
|
||||
/* Copyright (c) Microsoft Corporation. All rights reserved. */
|
||||
/* */
|
||||
/* This software is licensed under the Microsoft Software License */
|
||||
/* Terms for Microsoft Azure RTOS. Full text of the license can be */
|
||||
/* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */
|
||||
/* and in the root directory of this software. */
|
||||
/* */
|
||||
/**************************************************************************/
|
||||
/***************************************************************************
|
||||
* Copyright (c) 2024 Microsoft Corporation
|
||||
* Copyright (c) 2026-present Eclipse ThreadX contributors
|
||||
*
|
||||
* This program and the accompanying materials are made available under the
|
||||
* terms of the MIT License which is available at
|
||||
* https://opensource.org/licenses/MIT.
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
**************************************************************************/
|
||||
|
||||
|
||||
/**************************************************************************/
|
||||
/**************************************************************************/
|
||||
/** */
|
||||
/** LevelX Component */
|
||||
/** */
|
||||
/** LevelX Component */
|
||||
/** */
|
||||
/** NOR Flash */
|
||||
/** */
|
||||
@@ -25,8 +25,8 @@
|
||||
|
||||
/* Disable ThreadX error checking. */
|
||||
|
||||
#ifndef TX_DISABLE_ERROR_CHECKING
|
||||
#define TX_DISABLE_ERROR_CHECKING
|
||||
#ifndef LX_DISABLE_ERROR_CHECKING
|
||||
#define LX_DISABLE_ERROR_CHECKING
|
||||
#endif
|
||||
|
||||
|
||||
@@ -35,43 +35,37 @@
|
||||
#include "lx_api.h"
|
||||
|
||||
|
||||
/**************************************************************************/
|
||||
/* */
|
||||
/* FUNCTION RELEASE */
|
||||
/* */
|
||||
/* _lx_nor_flash_extended_cache_enable PORTABLE C */
|
||||
/* 6.0 */
|
||||
/**************************************************************************/
|
||||
/* */
|
||||
/* FUNCTION RELEASE */
|
||||
/* */
|
||||
/* _lx_nor_flash_extended_cache_enable PORTABLE C */
|
||||
/* 6.3.0 */
|
||||
/* AUTHOR */
|
||||
/* */
|
||||
/* William E. Lamie, Microsoft Corporation */
|
||||
/* */
|
||||
/* 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 */
|
||||
/* DESCRIPTION */
|
||||
/* */
|
||||
/* 05-19-2020 William E. Lamie Initial Version 6.0 */
|
||||
/* 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 */
|
||||
/* */
|
||||
/**************************************************************************/
|
||||
UINT _lx_nor_flash_extended_cache_enable(LX_NOR_FLASH *nor_flash, VOID *memory, ULONG size)
|
||||
@@ -81,12 +75,28 @@ UINT _lx_nor_flash_extended_cache_enable(LX_NOR_FLASH *nor_flash, VOID *memory,
|
||||
UINT i;
|
||||
ULONG cache_size;
|
||||
ULONG *cache_memory;
|
||||
#ifdef LX_NOR_ENABLE_MAPPING_BITMAP
|
||||
ULONG mapping_bitmap_words;
|
||||
ULONG mapping_bitmap_word;
|
||||
ULONG logical_sector;
|
||||
ULONG *mapping_bitmap_ptr;
|
||||
#endif
|
||||
#ifdef LX_NOR_ENABLE_OBSOLETE_COUNT_CACHE
|
||||
ULONG obsolete_count_words;
|
||||
ULONG obsolete_sectors;
|
||||
#endif
|
||||
#if defined(LX_NOR_ENABLE_MAPPING_BITMAP) || defined(LX_NOR_ENABLE_OBSOLETE_COUNT_CACHE)
|
||||
ULONG *block_word_ptr;
|
||||
UINT j;
|
||||
UINT status;
|
||||
ULONG block_word;
|
||||
#endif
|
||||
|
||||
|
||||
/* Determine if memory was specified but with an invalid size (less than one NOR sector). */
|
||||
if ((memory) && (size < LX_NOR_SECTOR_SIZE))
|
||||
{
|
||||
|
||||
|
||||
/* Error in memory size supplied. */
|
||||
return(LX_ERROR);
|
||||
}
|
||||
@@ -106,28 +116,188 @@ ULONG *cache_memory;
|
||||
/* Setup cache memory pointer. */
|
||||
cache_memory = (ULONG *) memory;
|
||||
|
||||
#if defined(LX_NOR_ENABLE_MAPPING_BITMAP) || defined(LX_NOR_ENABLE_OBSOLETE_COUNT_CACHE)
|
||||
|
||||
/* Check if the NOR flash is opened. */
|
||||
if (nor_flash -> lx_nor_flash_state == LX_NOR_FLASH_OPENED)
|
||||
{
|
||||
#if defined(LX_NOR_ENABLE_MAPPING_BITMAP)
|
||||
|
||||
/* Get the mapping bitmap cache size. */
|
||||
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. */
|
||||
if (cache_size < mapping_bitmap_words)
|
||||
{
|
||||
|
||||
/* Update the cache size. */
|
||||
mapping_bitmap_words = cache_size;
|
||||
}
|
||||
|
||||
/* Setup the mapping bitmap cache. */
|
||||
nor_flash -> lx_nor_flash_extended_cache_mapping_bitmap = cache_memory;
|
||||
|
||||
/* Setup the mapping bitmap cache size. */
|
||||
nor_flash -> lx_nor_flash_extended_cache_mapping_bitmap_max_logical_sector = mapping_bitmap_words * 32;
|
||||
|
||||
/* Clear the mapping bitmap cache. */
|
||||
for (i = 0; i < mapping_bitmap_words; i++)
|
||||
{
|
||||
cache_memory[i] = 0;
|
||||
}
|
||||
|
||||
/* Update the cache memory pointer. */
|
||||
mapping_bitmap_ptr = cache_memory;
|
||||
|
||||
/* Update the cache size. */
|
||||
cache_size = cache_size - mapping_bitmap_words;
|
||||
|
||||
/* Update the cache memory pointer. */
|
||||
cache_memory = cache_memory + mapping_bitmap_words;
|
||||
#endif
|
||||
|
||||
#if defined(LX_NOR_ENABLE_OBSOLETE_COUNT_CACHE)
|
||||
|
||||
/* Get the obsolete count cache size. */
|
||||
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. */
|
||||
if (cache_size < obsolete_count_words)
|
||||
{
|
||||
|
||||
/* Update the cache size. */
|
||||
obsolete_count_words = cache_size;
|
||||
}
|
||||
|
||||
/* Setup the obsolete count cache. */
|
||||
nor_flash -> lx_nor_flash_extended_cache_obsolete_count = (LX_NOR_OBSOLETE_COUNT_CACHE_TYPE*)cache_memory;
|
||||
|
||||
/* Setup the obsolete count cache size. */
|
||||
nor_flash -> lx_nor_flash_extended_cache_obsolete_count_max_block = obsolete_count_words * 4 / sizeof(LX_NOR_OBSOLETE_COUNT_CACHE_TYPE);
|
||||
|
||||
/* Update the cache size. */
|
||||
cache_size = cache_size - obsolete_count_words;
|
||||
|
||||
/* Update the cache memory pointer. */
|
||||
cache_memory = cache_memory + obsolete_count_words;
|
||||
#endif
|
||||
|
||||
/* Loop through the blocks. */
|
||||
for (i = 0; i < nor_flash -> lx_nor_flash_total_blocks; i++)
|
||||
{
|
||||
/* Setup the block word pointer to the first word of the block. */
|
||||
block_word_ptr = (nor_flash -> lx_nor_flash_base_address + (i * nor_flash -> lx_nor_flash_words_per_block));
|
||||
|
||||
#if defined(LX_NOR_ENABLE_OBSOLETE_COUNT_CACHE)
|
||||
|
||||
/* Initialize the obsolete count cache. */
|
||||
obsolete_sectors = 0;
|
||||
#endif
|
||||
|
||||
/* Now walk the list of logical-physical sector mapping. */
|
||||
for (j = 0; j < nor_flash ->lx_nor_flash_physical_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 the entry hasn't been used. */
|
||||
if (block_word == LX_NOR_PHYSICAL_SECTOR_FREE)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
/* 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 defined(LX_NOR_ENABLE_MAPPING_BITMAP)
|
||||
|
||||
/* Yes, get the logical sector. */
|
||||
logical_sector = block_word & LX_NOR_LOGICAL_SECTOR_MASK;
|
||||
|
||||
/* Get the mapping bitmap word. */
|
||||
mapping_bitmap_word = logical_sector >> 5;
|
||||
|
||||
/* Check if the mapping bitmap word is within the cache. */
|
||||
if (mapping_bitmap_word < mapping_bitmap_words)
|
||||
{
|
||||
|
||||
/* Set the bit in the mapping bitmap. */
|
||||
mapping_bitmap_ptr[mapping_bitmap_word] |= (ULONG)(1 << (logical_sector & 31));
|
||||
}
|
||||
#endif
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
#if defined(LX_NOR_ENABLE_OBSOLETE_COUNT_CACHE)
|
||||
|
||||
/* Increment the obsolete sector count. */
|
||||
obsolete_sectors++;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
#if defined(LX_NOR_ENABLE_OBSOLETE_COUNT_CACHE)
|
||||
|
||||
/* Check if the block is cached by obsolete count cache. */
|
||||
if (i < nor_flash -> lx_nor_flash_extended_cache_obsolete_count_max_block)
|
||||
{
|
||||
|
||||
/* Yes, cache the obsolete sector count. */
|
||||
nor_flash -> lx_nor_flash_extended_cache_obsolete_count[i] = (LX_NOR_OBSOLETE_COUNT_CACHE_TYPE)obsolete_sectors;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Loop through the memory supplied and assign to cache entries. */
|
||||
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. */
|
||||
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_access_count = 0;
|
||||
|
||||
|
||||
/* Move the cache memory forward. */
|
||||
cache_memory = cache_memory + LX_NOR_SECTOR_SIZE;
|
||||
|
||||
|
||||
/* Decrement the size. */
|
||||
cache_size = cache_size - LX_NOR_SECTOR_SIZE;
|
||||
|
||||
|
||||
/* Move to next cache entry. */
|
||||
i++;
|
||||
}
|
||||
|
||||
|
||||
/* Save the number of cache entries. */
|
||||
nor_flash -> lx_nor_flash_extended_cache_entries = i;
|
||||
if(i == LX_NOR_EXTENDED_CACHE_SIZE)
|
||||
{
|
||||
|
||||
nor_flash -> lx_nor_flash_extended_cache_entries = LX_NOR_EXTENDED_CACHE_SIZE;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
nor_flash -> lx_nor_flash_extended_cache_entries = i;
|
||||
}
|
||||
|
||||
#ifdef LX_THREAD_SAFE_ENABLE
|
||||
|
||||
@@ -139,6 +309,10 @@ ULONG *cache_memory;
|
||||
return(LX_SUCCESS);
|
||||
#else
|
||||
|
||||
LX_PARAMETER_NOT_USED(nor_flash);
|
||||
LX_PARAMETER_NOT_USED(memory);
|
||||
LX_PARAMETER_NOT_USED(size);
|
||||
|
||||
/* Return disabled error message. */
|
||||
return(LX_DISABLED);
|
||||
#endif
|
||||
|
||||
@@ -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) Microsoft Corporation. All rights reserved. */
|
||||
/* */
|
||||
/* This software is licensed under the Microsoft Software License */
|
||||
/* Terms for Microsoft Azure RTOS. Full text of the license can be */
|
||||
/* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */
|
||||
/* and in the root directory of this software. */
|
||||
/* */
|
||||
/**************************************************************************/
|
||||
/***************************************************************************
|
||||
* Copyright (c) 2024 Microsoft Corporation
|
||||
* Copyright (c) 2026-present Eclipse ThreadX contributors
|
||||
*
|
||||
* This program and the accompanying materials are made available under the
|
||||
* terms of the MIT License which is available at
|
||||
* https://opensource.org/licenses/MIT.
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
**************************************************************************/
|
||||
|
||||
|
||||
/**************************************************************************/
|
||||
/**************************************************************************/
|
||||
/** */
|
||||
/** LevelX Component */
|
||||
/** */
|
||||
/** LevelX Component */
|
||||
/** */
|
||||
/** NOR Flash */
|
||||
/** */
|
||||
@@ -34,41 +34,35 @@ LX_NOR_FLASH *_lx_nor_flash_opened_ptr;
|
||||
ULONG _lx_nor_flash_opened_count;
|
||||
|
||||
|
||||
/**************************************************************************/
|
||||
/* */
|
||||
/* FUNCTION RELEASE */
|
||||
/* */
|
||||
/* _lx_nor_flash_initialize PORTABLE C */
|
||||
/* 6.0 */
|
||||
/**************************************************************************/
|
||||
/* */
|
||||
/* FUNCTION RELEASE */
|
||||
/* */
|
||||
/* _lx_nor_flash_initialize PORTABLE C */
|
||||
/* 6.1.7 */
|
||||
/* AUTHOR */
|
||||
/* */
|
||||
/* William E. Lamie, Microsoft Corporation */
|
||||
/* */
|
||||
/* 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 */
|
||||
/* DESCRIPTION */
|
||||
/* */
|
||||
/* 05-19-2020 William E. Lamie Initial Version 6.0 */
|
||||
/* This function initializes the NOR flash data structures. */
|
||||
/* */
|
||||
/* INPUT */
|
||||
/* */
|
||||
/* None */
|
||||
/* */
|
||||
/* OUTPUT */
|
||||
/* */
|
||||
/* return status */
|
||||
/* */
|
||||
/* CALLS */
|
||||
/* */
|
||||
/* None */
|
||||
/* */
|
||||
/* CALLED BY */
|
||||
/* */
|
||||
/* Application Code */
|
||||
/* */
|
||||
/**************************************************************************/
|
||||
UINT _lx_nor_flash_initialize(void)
|
||||
@@ -77,7 +71,7 @@ UINT _lx_nor_flash_initialize(void)
|
||||
/* Clear open list head pointer and opened count. */
|
||||
_lx_nor_flash_opened_ptr = LX_NULL;
|
||||
_lx_nor_flash_opened_count = 0;
|
||||
|
||||
|
||||
/* Return success! */
|
||||
return(LX_SUCCESS);
|
||||
}
|
||||
|
||||
@@ -1,19 +1,19 @@
|
||||
/**************************************************************************/
|
||||
/* */
|
||||
/* Copyright (c) Microsoft Corporation. All rights reserved. */
|
||||
/* */
|
||||
/* This software is licensed under the Microsoft Software License */
|
||||
/* Terms for Microsoft Azure RTOS. Full text of the license can be */
|
||||
/* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */
|
||||
/* and in the root directory of this software. */
|
||||
/* */
|
||||
/**************************************************************************/
|
||||
/***************************************************************************
|
||||
* Copyright (c) 2024 Microsoft Corporation
|
||||
* Copyright (c) 2026-present Eclipse ThreadX contributors
|
||||
*
|
||||
* This program and the accompanying materials are made available under the
|
||||
* terms of the MIT License which is available at
|
||||
* https://opensource.org/licenses/MIT.
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
**************************************************************************/
|
||||
|
||||
|
||||
/**************************************************************************/
|
||||
/**************************************************************************/
|
||||
/** */
|
||||
/** LevelX Component */
|
||||
/** */
|
||||
/** LevelX Component */
|
||||
/** */
|
||||
/** NOR Flash */
|
||||
/** */
|
||||
@@ -25,8 +25,8 @@
|
||||
|
||||
/* Disable ThreadX error checking. */
|
||||
|
||||
#ifndef TX_DISABLE_ERROR_CHECKING
|
||||
#define TX_DISABLE_ERROR_CHECKING
|
||||
#ifndef LX_DISABLE_ERROR_CHECKING
|
||||
#define LX_DISABLE_ERROR_CHECKING
|
||||
#endif
|
||||
|
||||
|
||||
@@ -35,52 +35,47 @@
|
||||
#include "lx_api.h"
|
||||
|
||||
|
||||
/**************************************************************************/
|
||||
/* */
|
||||
/* FUNCTION RELEASE */
|
||||
/* */
|
||||
/* _lx_nor_flash_logical_sector_find PORTABLE C */
|
||||
/* 6.0 */
|
||||
/**************************************************************************/
|
||||
/* */
|
||||
/* FUNCTION RELEASE */
|
||||
/* */
|
||||
/* _lx_nor_flash_logical_sector_find PORTABLE C */
|
||||
/* 6.3.0 */
|
||||
/* AUTHOR */
|
||||
/* */
|
||||
/* William E. Lamie, Microsoft Corporation */
|
||||
/* */
|
||||
/* 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_system_error Internal system error handler */
|
||||
/* */
|
||||
/* CALLED BY */
|
||||
/* */
|
||||
/* Internal LevelX */
|
||||
/* */
|
||||
/* RELEASE HISTORY */
|
||||
/* */
|
||||
/* DATE NAME DESCRIPTION */
|
||||
/* DESCRIPTION */
|
||||
/* */
|
||||
/* 05-19-2020 William E. Lamie Initial Version 6.0 */
|
||||
/* 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 */
|
||||
/* */
|
||||
/**************************************************************************/
|
||||
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)
|
||||
@@ -98,7 +93,10 @@ ULONG i, j;
|
||||
ULONG search_start;
|
||||
LX_NOR_SECTOR_MAPPING_CACHE_ENTRY *sector_mapping_cache_entry_ptr = LX_NULL;
|
||||
LX_NOR_SECTOR_MAPPING_CACHE_ENTRY temp_sector_mapping_cache_entry;
|
||||
#ifndef LX_DIRECT_READ
|
||||
#ifndef LX_NOR_ENABLE_OBSOLETE_COUNT_CACHE
|
||||
ULONG valid_sector_found;
|
||||
#endif
|
||||
#if !defined(LX_DIRECT_READ) || !defined(LX_NOR_ENABLE_OBSOLETE_COUNT_CACHE)
|
||||
UINT status;
|
||||
#endif
|
||||
|
||||
@@ -106,7 +104,7 @@ UINT status;
|
||||
/* Initialize the return parameters. */
|
||||
*physical_sector_map_entry = (ULONG *) 0;
|
||||
*physical_sector_address = (ULONG *) 0;
|
||||
|
||||
|
||||
/* Determine if there are any mapped physical sectors. */
|
||||
if (nor_flash -> lx_nor_flash_mapped_physical_sectors == 0)
|
||||
{
|
||||
@@ -115,17 +113,35 @@ UINT status;
|
||||
return(LX_SECTOR_NOT_FOUND);
|
||||
}
|
||||
|
||||
#ifndef LX_NOR_DISABLE_EXTENDED_CACHE
|
||||
#ifdef LX_NOR_ENABLE_MAPPING_BITMAP
|
||||
|
||||
/* Determine if the logical sector is in the range of mapping bitmap cache. */
|
||||
if (logical_sector < nor_flash -> lx_nor_flash_extended_cache_mapping_bitmap_max_logical_sector)
|
||||
{
|
||||
|
||||
/* 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)
|
||||
{
|
||||
|
||||
/* Not mapped, return not found. */
|
||||
return(LX_SECTOR_NOT_FOUND);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/* Determine if the sector mapping cache is enabled. */
|
||||
if (nor_flash -> lx_nor_flash_sector_mapping_cache_enabled)
|
||||
{
|
||||
|
||||
|
||||
/* 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;
|
||||
|
||||
/* Build a pointer to the cache entry. */
|
||||
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. */
|
||||
if ((sector_mapping_cache_entry_ptr -> lx_nor_sector_mapping_cache_logical_sector) == (logical_sector | LX_NOR_SECTOR_MAPPING_CACHE_ENTRY_VALID))
|
||||
{
|
||||
@@ -199,7 +215,7 @@ UINT status;
|
||||
/* Return a successful status. */
|
||||
return(LX_SUCCESS);
|
||||
}
|
||||
|
||||
|
||||
/* 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++;
|
||||
}
|
||||
@@ -217,18 +233,48 @@ UINT status;
|
||||
total_blocks = nor_flash -> lx_nor_flash_total_blocks;
|
||||
|
||||
/* 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
|
||||
/* Determine if the obsolete sector count is available in the cache. */
|
||||
if (i < nor_flash -> lx_nor_flash_extended_cache_obsolete_count_max_block)
|
||||
{
|
||||
|
||||
/* Check if the block contains obsolete sectors only. */
|
||||
if ((ULONG)nor_flash -> lx_nor_flash_extended_cache_obsolete_count[i] == nor_flash -> lx_nor_flash_physical_sectors_per_block)
|
||||
{
|
||||
|
||||
/* Move to the next block. */
|
||||
i++;
|
||||
|
||||
/* Determine if we have wrapped. */
|
||||
if (i >= nor_flash -> lx_nor_flash_total_blocks)
|
||||
{
|
||||
|
||||
/* Yes, we have wrapped, set to block 0. */
|
||||
i = 0;
|
||||
}
|
||||
|
||||
/* Start at the first sector in the next block. */
|
||||
j = 0;
|
||||
|
||||
/* No point in looking further into this block, just continue the loop. */
|
||||
continue;
|
||||
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
/* 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));
|
||||
|
||||
/* 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. */
|
||||
|
||||
/* Read the minimum and maximum logical sector values in this block. */
|
||||
#ifdef LX_DIRECT_READ
|
||||
|
||||
|
||||
/* Read the word directly. */
|
||||
min_logical_sector = *(block_word_ptr + LX_NOR_FLASH_MIN_LOGICAL_SECTOR_OFFSET);
|
||||
#else
|
||||
@@ -237,7 +283,7 @@ UINT status;
|
||||
/* 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);
|
||||
|
||||
@@ -245,58 +291,74 @@ UINT status;
|
||||
return(status);
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Is the value valid? */
|
||||
if (min_logical_sector != LX_ALL_ONES)
|
||||
{
|
||||
#ifdef LX_DIRECT_READ
|
||||
|
||||
/* Read the word directly. */
|
||||
max_logical_sector = *(block_word_ptr + LX_NOR_FLASH_MAX_LOGICAL_SECTOR_OFFSET);
|
||||
|
||||
/* Read the word directly. */
|
||||
max_logical_sector = *(block_word_ptr + LX_NOR_FLASH_MAX_LOGICAL_SECTOR_OFFSET);
|
||||
#else
|
||||
status = _lx_nor_flash_driver_read(nor_flash, block_word_ptr + LX_NOR_FLASH_MAX_LOGICAL_SECTOR_OFFSET, &max_logical_sector, 1);
|
||||
status = _lx_nor_flash_driver_read(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.. */
|
||||
if (status)
|
||||
{
|
||||
|
||||
/* Call system error handler. */
|
||||
_lx_nor_flash_system_error(nor_flash, status);
|
||||
|
||||
/* Return the error. */
|
||||
return(status);
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Are the values valid? */
|
||||
if ((min_logical_sector != LX_ALL_ONES) && (max_logical_sector != LX_ALL_ONES))
|
||||
{
|
||||
|
||||
/* Now let's check to see if the search sector is within this range. */
|
||||
if ((logical_sector < min_logical_sector) || (logical_sector > max_logical_sector))
|
||||
/* Check for an error from flash driver. Drivers should never return an error.. */
|
||||
if (status)
|
||||
{
|
||||
|
||||
/* Move to the next block. */
|
||||
i++;
|
||||
|
||||
/* Determine if we have wrapped. */
|
||||
if (i >= nor_flash -> lx_nor_flash_total_blocks)
|
||||
{
|
||||
|
||||
/* Yes, we have wrapped, set to block 0. */
|
||||
i = 0;
|
||||
}
|
||||
/* Call system error handler. */
|
||||
_lx_nor_flash_system_error(nor_flash, status);
|
||||
|
||||
/* Start at the first sector in the next block. */
|
||||
j = 0;
|
||||
|
||||
/* No point in looking further into this block, just continue the loop. */
|
||||
continue;
|
||||
/* Return the error. */
|
||||
return(status);
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Is the value valid? */
|
||||
if (max_logical_sector != LX_ALL_ONES)
|
||||
{
|
||||
|
||||
/* Now let's check to see if the search sector is within this range. */
|
||||
if ((logical_sector < min_logical_sector) || (logical_sector > max_logical_sector))
|
||||
{
|
||||
|
||||
/* Move to the next block. */
|
||||
i++;
|
||||
|
||||
/* Determine if we have wrapped. */
|
||||
if (i >= nor_flash -> lx_nor_flash_total_blocks)
|
||||
{
|
||||
|
||||
/* Yes, we have wrapped, set to block 0. */
|
||||
i = 0;
|
||||
}
|
||||
|
||||
/* Start at the first sector in the next block. */
|
||||
j = 0;
|
||||
|
||||
/* No point in looking further into this block, just continue the loop. */
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
|
||||
/* Set the max logical sector to all ones. */
|
||||
max_logical_sector = LX_ALL_ONES;
|
||||
}
|
||||
#ifndef LX_NOR_ENABLE_OBSOLETE_COUNT_CACHE
|
||||
|
||||
/* Clear the valid sector found flag. */
|
||||
valid_sector_found = LX_FALSE;
|
||||
#endif
|
||||
|
||||
/* Setup the total number of sectors. */
|
||||
total_sectors = nor_flash -> lx_nor_flash_physical_sectors_per_block;
|
||||
|
||||
|
||||
/* Remember the start of the search. */
|
||||
search_start = j;
|
||||
|
||||
|
||||
/* Now search through the sector list to find a match. */
|
||||
while (total_sectors--)
|
||||
{
|
||||
@@ -304,10 +366,10 @@ UINT status;
|
||||
/* Setup a pointer to the mapped list. */
|
||||
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. */
|
||||
#ifdef LX_DIRECT_READ
|
||||
|
||||
|
||||
/* Read the word directly. */
|
||||
list_word = *(list_word_ptr);
|
||||
#else
|
||||
@@ -316,7 +378,7 @@ UINT status;
|
||||
/* 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);
|
||||
|
||||
@@ -324,42 +386,42 @@ UINT status;
|
||||
return(status);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
/* Determine if the entry hasn't been used. */
|
||||
if (list_word == LX_NOR_PHYSICAL_SECTOR_FREE)
|
||||
{
|
||||
|
||||
|
||||
/* Since the mapping is done sequentially in the block, we know nothing
|
||||
else exists after this point. */
|
||||
|
||||
|
||||
/* Determine if the search started at the beginning of the block. */
|
||||
if (search_start == 0)
|
||||
{
|
||||
|
||||
|
||||
/* Yes, we started at the beginning of the block. We are now done with this block. */
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
|
||||
/* Setup the new total to the search start. */
|
||||
total_sectors = search_start;
|
||||
|
||||
|
||||
/* Clear search start. */
|
||||
search_start = 0;
|
||||
|
||||
|
||||
/* Start search over. */
|
||||
j = 0;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* Is this entry 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. */
|
||||
mapped_sectors--;
|
||||
mapped_sectors--;
|
||||
|
||||
/* Do we have a valid sector match? */
|
||||
if ((list_word & LX_NOR_LOGICAL_SECTOR_MASK) == logical_sector)
|
||||
@@ -368,7 +430,7 @@ UINT status;
|
||||
/* Determine if we care about the superceded bit. */
|
||||
if (superceded_check == LX_FALSE)
|
||||
{
|
||||
|
||||
|
||||
/* Prepare the return information. */
|
||||
*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);
|
||||
@@ -378,7 +440,7 @@ UINT status;
|
||||
{
|
||||
|
||||
/* Yes, update the cache with the sector mapping. */
|
||||
|
||||
|
||||
/* 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 + 2) = *(sector_mapping_cache_entry_ptr + 1);
|
||||
@@ -392,26 +454,26 @@ UINT status;
|
||||
|
||||
/* Remember the last found block for next search. */
|
||||
nor_flash -> lx_nor_flash_found_block_search = i;
|
||||
|
||||
|
||||
/* Remember the last found sector. */
|
||||
nor_flash -> lx_nor_flash_found_sector_search = j+1;
|
||||
|
||||
|
||||
/* Has this wrapped around? */
|
||||
if (nor_flash -> lx_nor_flash_found_sector_search >= nor_flash -> lx_nor_flash_physical_sectors_per_block)
|
||||
{
|
||||
|
||||
|
||||
/* Reset to the beginning sector. */
|
||||
nor_flash -> lx_nor_flash_found_sector_search = 0;
|
||||
}
|
||||
|
||||
/* Return success! */
|
||||
return(LX_SUCCESS);
|
||||
return(LX_SUCCESS);
|
||||
}
|
||||
|
||||
/* Check for the superceded bit being clear, which means the sector was superceded. */
|
||||
else if (list_word & LX_NOR_PHYSICAL_SECTOR_SUPERCEDED)
|
||||
{
|
||||
|
||||
|
||||
/* Prepare the return information. */
|
||||
*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);
|
||||
@@ -423,44 +485,72 @@ UINT status;
|
||||
|
||||
/* Remember the last found sector. */
|
||||
nor_flash -> lx_nor_flash_found_sector_search = j+1;
|
||||
|
||||
|
||||
/* Has this wrapped around? */
|
||||
if (nor_flash -> lx_nor_flash_found_sector_search >= nor_flash -> lx_nor_flash_physical_sectors_per_block)
|
||||
{
|
||||
|
||||
|
||||
/* Reset to the beginning sector. */
|
||||
nor_flash -> lx_nor_flash_found_sector_search = 0;
|
||||
}
|
||||
|
||||
/* Return success! */
|
||||
return(LX_SUCCESS);
|
||||
return(LX_SUCCESS);
|
||||
}
|
||||
}
|
||||
#ifndef LX_NOR_ENABLE_OBSOLETE_COUNT_CACHE
|
||||
|
||||
/* Set the valid sector found flag. */
|
||||
valid_sector_found = LX_TRUE;
|
||||
#endif
|
||||
}
|
||||
|
||||
/* Move to the next list entry. */
|
||||
j++;
|
||||
|
||||
|
||||
/* Check for wrap around. */
|
||||
if (j >= nor_flash -> lx_nor_flash_physical_sectors_per_block)
|
||||
{
|
||||
|
||||
|
||||
/* Yes, wrap around, go back to the beginning. */
|
||||
j = 0;
|
||||
}
|
||||
}
|
||||
#ifndef LX_NOR_ENABLE_OBSOLETE_COUNT_CACHE
|
||||
/* Check if the block contains no valid sectors. */
|
||||
if ((valid_sector_found == LX_FALSE) && (max_logical_sector != LX_ALL_ONES))
|
||||
{
|
||||
|
||||
/* Clear max logical sector to indicate sectors are all obsoleted. */
|
||||
max_logical_sector = 0;
|
||||
|
||||
/* 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);
|
||||
|
||||
/* 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 the error. */
|
||||
return(status);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Determine if there are any more mapped sectors. */
|
||||
if (mapped_sectors == 0)
|
||||
break;
|
||||
|
||||
|
||||
/* Move to the next block. */
|
||||
i++;
|
||||
|
||||
|
||||
/* Determine if we have wrapped. */
|
||||
if (i >= nor_flash -> lx_nor_flash_total_blocks)
|
||||
{
|
||||
|
||||
|
||||
/* Yes, we have wrapped, set to block 0. */
|
||||
i = 0;
|
||||
}
|
||||
@@ -470,6 +560,6 @@ UINT status;
|
||||
}
|
||||
|
||||
/* Return sector not found status. */
|
||||
return(LX_SECTOR_NOT_FOUND);
|
||||
return(LX_SECTOR_NOT_FOUND);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,19 +1,19 @@
|
||||
/**************************************************************************/
|
||||
/* */
|
||||
/* Copyright (c) Microsoft Corporation. All rights reserved. */
|
||||
/* */
|
||||
/* This software is licensed under the Microsoft Software License */
|
||||
/* Terms for Microsoft Azure RTOS. Full text of the license can be */
|
||||
/* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */
|
||||
/* and in the root directory of this software. */
|
||||
/* */
|
||||
/**************************************************************************/
|
||||
/***************************************************************************
|
||||
* Copyright (c) 2024 Microsoft Corporation
|
||||
* Copyright (c) 2026-present Eclipse ThreadX contributors
|
||||
*
|
||||
* This program and the accompanying materials are made available under the
|
||||
* terms of the MIT License which is available at
|
||||
* https://opensource.org/licenses/MIT.
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
**************************************************************************/
|
||||
|
||||
|
||||
/**************************************************************************/
|
||||
/**************************************************************************/
|
||||
/** */
|
||||
/** LevelX Component */
|
||||
/** */
|
||||
/** LevelX Component */
|
||||
/** */
|
||||
/** NOR Flash */
|
||||
/** */
|
||||
@@ -25,8 +25,8 @@
|
||||
|
||||
/* Disable ThreadX error checking. */
|
||||
|
||||
#ifndef TX_DISABLE_ERROR_CHECKING
|
||||
#define TX_DISABLE_ERROR_CHECKING
|
||||
#ifndef LX_DISABLE_ERROR_CHECKING
|
||||
#define LX_DISABLE_ERROR_CHECKING
|
||||
#endif
|
||||
|
||||
|
||||
@@ -35,48 +35,42 @@
|
||||
#include "lx_api.h"
|
||||
|
||||
|
||||
/**************************************************************************/
|
||||
/* */
|
||||
/* FUNCTION RELEASE */
|
||||
/* */
|
||||
/* _lx_nor_flash_next_block_to_erase_find PORTABLE C */
|
||||
/* 6.0 */
|
||||
/**************************************************************************/
|
||||
/* */
|
||||
/* FUNCTION RELEASE */
|
||||
/* */
|
||||
/* _lx_nor_flash_next_block_to_erase_find PORTABLE C */
|
||||
/* 6.3.0 */
|
||||
/* AUTHOR */
|
||||
/* */
|
||||
/* William E. Lamie, Microsoft Corporation */
|
||||
/* */
|
||||
/* 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 */
|
||||
/* DESCRIPTION */
|
||||
/* */
|
||||
/* 05-19-2020 William E. Lamie Initial Version 6.0 */
|
||||
/* 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 */
|
||||
/* */
|
||||
/**************************************************************************/
|
||||
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)
|
||||
@@ -93,16 +87,23 @@ ULONG min_block_erase = 0;
|
||||
ULONG min_block_erase_count;
|
||||
ULONG min_block_obsolete_count = 0;
|
||||
ULONG min_block_mapped_count = 0;
|
||||
ULONG min_block_mapped_count_available = LX_FALSE;
|
||||
ULONG max_obsolete_sectors;
|
||||
ULONG max_obsolete_block = 0;
|
||||
ULONG max_obsolete_erase_count = 0;
|
||||
ULONG max_obsolete_mapped_count = 0;
|
||||
ULONG max_obsolete_mapped_count_available = LX_FALSE;
|
||||
ULONG min_system_block_erase_count;
|
||||
ULONG system_min_erased_blocks;
|
||||
ULONG max_system_block_erase_count;
|
||||
ULONG erase_count_threshold;
|
||||
ULONG min_logical_sector;
|
||||
ULONG max_logical_sector;
|
||||
#ifndef LX_DIRECT_READ
|
||||
UINT status;
|
||||
#endif
|
||||
UINT obsolete_sectors_available;
|
||||
UINT mapped_sectors_available;
|
||||
|
||||
|
||||
/* Setup the block word pointer to the first word of the search block. */
|
||||
@@ -110,35 +111,36 @@ UINT status;
|
||||
|
||||
/* Initialize the minimum erase count. */
|
||||
min_block_erase_count = LX_ALL_ONES;
|
||||
|
||||
|
||||
/* Initialize the system minimum and maximum erase counts. */
|
||||
min_system_block_erase_count = LX_ALL_ONES;
|
||||
system_min_erased_blocks = 0;
|
||||
max_system_block_erase_count = 0;
|
||||
|
||||
|
||||
/* Initialize the maximum obsolete sector count. */
|
||||
max_obsolete_sectors = 0;
|
||||
|
||||
|
||||
/* Calculate the erase count threshold. */
|
||||
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. */
|
||||
erase_count_threshold = nor_flash -> lx_nor_flash_minimum_erase_count + LX_NOR_FLASH_MAX_ERASE_COUNT_DELTA;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
|
||||
/* 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;
|
||||
}
|
||||
|
||||
|
||||
/* Loop through the blocks to attempt to find the mapped logical sector. */
|
||||
for (i = 0; i < nor_flash -> lx_nor_flash_total_blocks; i++)
|
||||
{
|
||||
|
||||
/* Read the erase count of this block. */
|
||||
#ifdef LX_DIRECT_READ
|
||||
|
||||
|
||||
/* Read the word directly. */
|
||||
erase_count = *(block_word_ptr);
|
||||
#else
|
||||
@@ -147,7 +149,7 @@ UINT status;
|
||||
/* 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);
|
||||
|
||||
@@ -157,25 +159,272 @@ UINT status;
|
||||
#endif
|
||||
|
||||
/* Update the system minimum and maximum erase counts. */
|
||||
if (erase_count == min_system_block_erase_count)
|
||||
{
|
||||
system_min_erased_blocks ++;
|
||||
}
|
||||
if (erase_count < min_system_block_erase_count)
|
||||
{
|
||||
min_system_block_erase_count = erase_count;
|
||||
system_min_erased_blocks = 1;
|
||||
}
|
||||
if (erase_count > max_system_block_erase_count)
|
||||
max_system_block_erase_count = erase_count;
|
||||
|
||||
/* Initialize the obsolete and mapped sector count available flags. */
|
||||
obsolete_sectors_available = LX_FALSE;
|
||||
mapped_sectors_available = LX_FALSE;
|
||||
|
||||
#ifdef LX_NOR_ENABLE_OBSOLETE_COUNT_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)
|
||||
{
|
||||
|
||||
/* Yes, the obsolete sector count is available. */
|
||||
obsolete_sectors_available = LX_TRUE;
|
||||
|
||||
/* Pickup the obsolete sector count from the cache. */
|
||||
obsolete_sectors = (ULONG)nor_flash -> lx_nor_flash_extended_cache_obsolete_count[i];
|
||||
}
|
||||
else
|
||||
{
|
||||
#endif
|
||||
/* Read the minimum and maximum logical sector values in this block. */
|
||||
#ifdef LX_DIRECT_READ
|
||||
|
||||
/* Read the word directly. */
|
||||
min_logical_sector = *(block_word_ptr + LX_NOR_FLASH_MIN_LOGICAL_SECTOR_OFFSET);
|
||||
#else
|
||||
status = _lx_nor_flash_driver_read(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.. */
|
||||
if (status)
|
||||
{
|
||||
|
||||
/* Call system error handler. */
|
||||
_lx_nor_flash_system_error(nor_flash, status);
|
||||
|
||||
/* Return the error. */
|
||||
return(status);
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Determine if the minimum logical sector is valid. */
|
||||
if (min_logical_sector != LX_ALL_ONES)
|
||||
{
|
||||
#ifdef LX_DIRECT_READ
|
||||
|
||||
/* Read the word directly. */
|
||||
max_logical_sector = *(block_word_ptr + LX_NOR_FLASH_MAX_LOGICAL_SECTOR_OFFSET);
|
||||
#else
|
||||
status = _lx_nor_flash_driver_read(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.. */
|
||||
if (status)
|
||||
{
|
||||
|
||||
/* Call system error handler. */
|
||||
_lx_nor_flash_system_error(nor_flash, status);
|
||||
|
||||
/* Return the error. */
|
||||
return(status);
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Are the values valid? */
|
||||
/* 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))
|
||||
{
|
||||
|
||||
obsolete_sectors_available = LX_TRUE;
|
||||
obsolete_sectors = nor_flash -> lx_nor_flash_physical_sectors_per_block;
|
||||
}
|
||||
}
|
||||
#ifdef LX_NOR_ENABLE_OBSOLETE_COUNT_CACHE
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Determine if the mapped sector count is available. */
|
||||
if (obsolete_sectors_available == LX_FALSE)
|
||||
{
|
||||
|
||||
/* Compute the number of obsolete and mapped sectors for this block. */
|
||||
|
||||
/* Initialize the obsolete and mapped sector counts. */
|
||||
obsolete_sectors = 0;
|
||||
mapped_sectors = 0;
|
||||
|
||||
/* Set the mapped sector count and obsolete sector count available flags. */
|
||||
mapped_sectors_available = LX_TRUE;
|
||||
obsolete_sectors_available = LX_TRUE;
|
||||
|
||||
/* Setup a pointer to the mapped list. */
|
||||
list_word_ptr = block_word_ptr + nor_flash -> lx_nor_flash_block_physical_sector_mapping_offset;
|
||||
|
||||
/* Loop through the mapped list for this block. */
|
||||
for (j = 0; j < nor_flash -> lx_nor_flash_physical_sectors_per_block; j++)
|
||||
{
|
||||
|
||||
/* Read the current mapping entry. */
|
||||
#ifdef LX_DIRECT_READ
|
||||
|
||||
/* Read the word directly. */
|
||||
list_word = *(list_word_ptr);
|
||||
#else
|
||||
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.. */
|
||||
if (status)
|
||||
{
|
||||
|
||||
/* Call system error handler. */
|
||||
_lx_nor_flash_system_error(nor_flash, status);
|
||||
|
||||
/* Return the error. */
|
||||
return(status);
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Determine if the entry hasn't been used. */
|
||||
if (list_word == LX_NOR_PHYSICAL_SECTOR_FREE)
|
||||
{
|
||||
|
||||
/* Since allocations are done sequentially in the block, we know nothing
|
||||
else exists after this point. */
|
||||
break;
|
||||
}
|
||||
|
||||
/* Is this entry obsolete? */
|
||||
if ((list_word & LX_NOR_PHYSICAL_SECTOR_VALID) == 0)
|
||||
{
|
||||
|
||||
/* Increment the number of obsolete sectors. */
|
||||
obsolete_sectors++;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
/* Increment the number of mapped sectors. */
|
||||
mapped_sectors++;
|
||||
}
|
||||
|
||||
/* Move the list pointer ahead. */
|
||||
list_word_ptr++;
|
||||
}
|
||||
}
|
||||
|
||||
/* 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) &&
|
||||
(erase_count == nor_flash -> lx_nor_flash_minimum_erase_count) &&
|
||||
(nor_flash -> lx_nor_flash_minimum_erased_blocks > 0))
|
||||
{
|
||||
|
||||
/* Yes, we have a full obsoleted block with minimum erase count. */
|
||||
*return_erase_block = i;
|
||||
*return_erase_count = erase_count;
|
||||
*return_obsolete_sectors = obsolete_sectors;
|
||||
*return_mapped_sectors = mapped_sectors;
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
/* 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))
|
||||
{
|
||||
|
||||
/* Update the new maximum obsolete sectors and related information. */
|
||||
max_obsolete_sectors = obsolete_sectors;
|
||||
max_obsolete_block = i;
|
||||
max_obsolete_erase_count = erase_count;
|
||||
max_obsolete_mapped_count = mapped_sectors;
|
||||
max_obsolete_mapped_count_available = mapped_sectors_available;
|
||||
|
||||
}
|
||||
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
|
||||
count? */
|
||||
if (erase_count < max_obsolete_erase_count)
|
||||
{
|
||||
|
||||
/* Yes, erase the block with the smaller erase count. */
|
||||
max_obsolete_sectors = obsolete_sectors;
|
||||
max_obsolete_block = i;
|
||||
max_obsolete_erase_count = erase_count;
|
||||
max_obsolete_mapped_count = mapped_sectors;
|
||||
max_obsolete_mapped_count_available = mapped_sectors_available;
|
||||
}
|
||||
}
|
||||
|
||||
/* Determine if we have a new minimum erase count. */
|
||||
if (erase_count < min_block_erase_count)
|
||||
{
|
||||
|
||||
/* Update the new minimum erase count and related information. */
|
||||
min_block_erase_count = erase_count;
|
||||
min_block_erase = i;
|
||||
min_block_obsolete_count = obsolete_sectors;
|
||||
min_block_mapped_count = mapped_sectors;
|
||||
min_block_mapped_count_available = mapped_sectors_available;
|
||||
}
|
||||
|
||||
/* Move to the next block. */
|
||||
block_word_ptr = block_word_ptr + nor_flash -> lx_nor_flash_words_per_block;
|
||||
}
|
||||
|
||||
/* Determine if we found a block with full obsoleted sector and the erase count is minimum. */
|
||||
if (i == nor_flash -> lx_nor_flash_total_blocks)
|
||||
{
|
||||
|
||||
/* Determine if we can erase the block with the most obsolete sectors. */
|
||||
if (max_obsolete_sectors)
|
||||
{
|
||||
|
||||
/* Erase the block with the most obsolete sectors. */
|
||||
*return_erase_block = max_obsolete_block;
|
||||
*return_erase_count = max_obsolete_erase_count;
|
||||
*return_obsolete_sectors = max_obsolete_sectors;
|
||||
*return_mapped_sectors = max_obsolete_mapped_count;
|
||||
mapped_sectors_available = max_obsolete_mapped_count_available;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
/* Otherwise, choose the block with the smallest erase count. */
|
||||
*return_erase_block = min_block_erase;
|
||||
*return_erase_count = min_block_erase_count;
|
||||
*return_obsolete_sectors = min_block_obsolete_count;
|
||||
*return_mapped_sectors = min_block_mapped_count;
|
||||
mapped_sectors_available = min_block_mapped_count_available;
|
||||
}
|
||||
|
||||
/* Update the overall minimum and maximum erase count. */
|
||||
nor_flash -> lx_nor_flash_minimum_erase_count = min_system_block_erase_count;
|
||||
nor_flash -> lx_nor_flash_minimum_erased_blocks = system_min_erased_blocks;
|
||||
nor_flash -> lx_nor_flash_maximum_erase_count = max_system_block_erase_count;
|
||||
}
|
||||
|
||||
/* Determine if the mapped sector count is available. */
|
||||
if (mapped_sectors_available == LX_FALSE)
|
||||
{
|
||||
|
||||
/* Compute the number of obsolete and mapped sectors for this block. */
|
||||
obsolete_sectors = 0;
|
||||
mapped_sectors = 0;
|
||||
|
||||
mapped_sectors = 0;
|
||||
|
||||
/* 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;
|
||||
list_word_ptr = block_word_ptr + nor_flash -> lx_nor_flash_block_physical_sector_mapping_offset;
|
||||
|
||||
/* Loop through the mapped list for this block. */
|
||||
for (j = 0; j < nor_flash -> lx_nor_flash_physical_sectors_per_block; j++)
|
||||
{
|
||||
|
||||
|
||||
/* Read the current mapping entry. */
|
||||
#ifdef LX_DIRECT_READ
|
||||
|
||||
|
||||
/* Read the word directly. */
|
||||
list_word = *(list_word_ptr);
|
||||
#else
|
||||
@@ -184,7 +433,7 @@ UINT status;
|
||||
/* 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);
|
||||
|
||||
@@ -192,26 +441,20 @@ UINT status;
|
||||
return(status);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
/* Determine if the entry hasn't been used. */
|
||||
if (list_word == LX_NOR_PHYSICAL_SECTOR_FREE)
|
||||
{
|
||||
|
||||
|
||||
/* Since allocations are done sequentially in the block, we know nothing
|
||||
else exists after this point. */
|
||||
else exists after this point. */
|
||||
break;
|
||||
}
|
||||
|
||||
/* Is this entry obsolete? */
|
||||
if ((list_word & LX_NOR_PHYSICAL_SECTOR_VALID) == 0)
|
||||
|
||||
/* Is this entry mapped? */
|
||||
if ((list_word & LX_NOR_PHYSICAL_SECTOR_VALID) != 0)
|
||||
{
|
||||
|
||||
/* Increment the number of obsolete sectors. */
|
||||
obsolete_sectors++;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
|
||||
/* Increment the number of mapped sectors. */
|
||||
mapped_sectors++;
|
||||
}
|
||||
@@ -220,71 +463,10 @@ UINT status;
|
||||
list_word_ptr++;
|
||||
}
|
||||
|
||||
/* 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))
|
||||
{
|
||||
|
||||
/* Update the new maximum obsolete sectors and related information. */
|
||||
max_obsolete_sectors = obsolete_sectors;
|
||||
max_obsolete_block = i;
|
||||
max_obsolete_erase_count = erase_count;
|
||||
max_obsolete_mapped_count = mapped_sectors;
|
||||
}
|
||||
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
|
||||
count? */
|
||||
if (erase_count < max_obsolete_erase_count)
|
||||
{
|
||||
|
||||
/* Yes, erase the block with the smaller erase count. */
|
||||
max_obsolete_sectors = obsolete_sectors;
|
||||
max_obsolete_block = i;
|
||||
max_obsolete_erase_count = erase_count;
|
||||
max_obsolete_mapped_count = mapped_sectors;
|
||||
}
|
||||
}
|
||||
|
||||
/* Determine if we have a new minimum erase count. */
|
||||
if (erase_count < min_block_erase_count)
|
||||
{
|
||||
|
||||
/* Update the new minimum erase count and related information. */
|
||||
min_block_erase_count = erase_count;
|
||||
min_block_erase = i;
|
||||
min_block_obsolete_count = obsolete_sectors;
|
||||
min_block_mapped_count = mapped_sectors;
|
||||
}
|
||||
|
||||
/* Move to the next block. */
|
||||
block_word_ptr = block_word_ptr + nor_flash -> lx_nor_flash_words_per_block;
|
||||
}
|
||||
/* Return the mapped sector count. */
|
||||
*return_mapped_sectors = mapped_sectors;
|
||||
|
||||
/* Determine if we can erase the block with the most obsolete sectors. */
|
||||
if (max_obsolete_sectors)
|
||||
{
|
||||
|
||||
/* Erase the block with the most obsolete sectors. */
|
||||
*return_erase_block = max_obsolete_block;
|
||||
*return_erase_count = max_obsolete_erase_count;
|
||||
*return_obsolete_sectors = max_obsolete_sectors;
|
||||
*return_mapped_sectors = max_obsolete_mapped_count;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
/* Otherwise, choose the block with the smallest erase count. */
|
||||
*return_erase_block = min_block_erase;
|
||||
*return_erase_count = min_block_erase_count;
|
||||
*return_obsolete_sectors = min_block_obsolete_count;
|
||||
*return_mapped_sectors = min_block_mapped_count;
|
||||
}
|
||||
|
||||
/* Update the overall minimum and maximum erase count. */
|
||||
nor_flash -> lx_nor_flash_minimum_erase_count = min_system_block_erase_count;
|
||||
nor_flash -> lx_nor_flash_maximum_erase_count = max_system_block_erase_count;
|
||||
|
||||
/* Return success. */
|
||||
return(LX_SUCCESS);
|
||||
}
|
||||
|
||||
+80
-844
@@ -1,19 +1,20 @@
|
||||
/**************************************************************************/
|
||||
/* */
|
||||
/* Copyright (c) Microsoft Corporation. All rights reserved. */
|
||||
/* */
|
||||
/* This software is licensed under the Microsoft Software License */
|
||||
/* Terms for Microsoft Azure RTOS. Full text of the license can be */
|
||||
/* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */
|
||||
/* and in the root directory of this software. */
|
||||
/* */
|
||||
/**************************************************************************/
|
||||
/***************************************************************************
|
||||
* Copyright (c) 2024 Microsoft Corporation
|
||||
* Copyright (c) 2026-present Eclipse ThreadX contributors
|
||||
* 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 */
|
||||
/** */
|
||||
/** LevelX Component */
|
||||
/** */
|
||||
/** NOR Flash */
|
||||
/** */
|
||||
@@ -25,8 +26,8 @@
|
||||
|
||||
/* Disable ThreadX error checking. */
|
||||
|
||||
#ifndef TX_DISABLE_ERROR_CHECKING
|
||||
#define TX_DISABLE_ERROR_CHECKING
|
||||
#ifndef LX_DISABLE_ERROR_CHECKING
|
||||
#define LX_DISABLE_ERROR_CHECKING
|
||||
#endif
|
||||
|
||||
|
||||
@@ -34,839 +35,74 @@
|
||||
|
||||
#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.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 */
|
||||
/* */
|
||||
/**************************************************************************/
|
||||
UINT _lx_nor_flash_open(LX_NOR_FLASH *nor_flash, CHAR *name, UINT (*nor_driver_initialize)(LX_NOR_FLASH *))
|
||||
{
|
||||
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;
|
||||
ULONG i, j, k;
|
||||
UINT status;
|
||||
#ifdef LX_FREE_SECTOR_DATA_VERIFY
|
||||
ULONG *sector_word_ptr;
|
||||
ULONG sector_word;
|
||||
#endif
|
||||
LX_NOR_FLASH *tail_ptr;
|
||||
TX_INTERRUPT_SAVE_AREA
|
||||
UINT status = LX_ERROR;
|
||||
|
||||
LX_PARAMETER_NOT_USED(name);
|
||||
status = _lx_nor_flash_open_extended(nor_flash, name, nor_driver_initialize, NULL);
|
||||
|
||||
/* Clear the NOR flash control block. */
|
||||
TX_MEMSET(nor_flash, 0, sizeof(LX_NOR_FLASH));
|
||||
|
||||
/* 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;
|
||||
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 (i = 0; i < nor_flash -> lx_nor_flash_total_blocks; i++)
|
||||
{
|
||||
|
||||
/* 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 this the new minimum? */
|
||||
if (erased_count < min_erased_count)
|
||||
{
|
||||
|
||||
/* Yes, remember the new minimum. */
|
||||
min_erased_count = erased_count;
|
||||
}
|
||||
|
||||
/* 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 (i = 0; i < nor_flash -> lx_nor_flash_total_blocks; i++)
|
||||
{
|
||||
|
||||
/* 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_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 (i = 0; i < nor_flash -> lx_nor_flash_total_blocks; i++)
|
||||
{
|
||||
|
||||
/* 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. */
|
||||
status = (nor_flash -> lx_nor_flash_driver_block_erased_verify)(i);
|
||||
|
||||
/* 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, i, 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 = i;
|
||||
}
|
||||
}
|
||||
|
||||
/* 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((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_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 != TX_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. */
|
||||
TX_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. */
|
||||
TX_RESTORE
|
||||
|
||||
/* Return a successful completion. */
|
||||
return(LX_SUCCESS);
|
||||
return status;
|
||||
}
|
||||
|
||||
|
||||
@@ -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) Microsoft Corporation. All rights reserved. */
|
||||
/* */
|
||||
/* This software is licensed under the Microsoft Software License */
|
||||
/* Terms for Microsoft Azure RTOS. Full text of the license can be */
|
||||
/* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */
|
||||
/* and in the root directory of this software. */
|
||||
/* */
|
||||
/**************************************************************************/
|
||||
/***************************************************************************
|
||||
* Copyright (c) 2024 Microsoft Corporation
|
||||
* Copyright (c) 2026-present Eclipse ThreadX contributors
|
||||
*
|
||||
* This program and the accompanying materials are made available under the
|
||||
* terms of the MIT License which is available at
|
||||
* https://opensource.org/licenses/MIT.
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
**************************************************************************/
|
||||
|
||||
|
||||
/**************************************************************************/
|
||||
/**************************************************************************/
|
||||
/** */
|
||||
/** LevelX Component */
|
||||
/** */
|
||||
/** LevelX Component */
|
||||
/** */
|
||||
/** NOR Flash */
|
||||
/** */
|
||||
@@ -25,8 +25,8 @@
|
||||
|
||||
/* Disable ThreadX error checking. */
|
||||
|
||||
#ifndef TX_DISABLE_ERROR_CHECKING
|
||||
#define TX_DISABLE_ERROR_CHECKING
|
||||
#ifndef LX_DISABLE_ERROR_CHECKING
|
||||
#define LX_DISABLE_ERROR_CHECKING
|
||||
#endif
|
||||
|
||||
|
||||
@@ -35,52 +35,46 @@
|
||||
#include "lx_api.h"
|
||||
|
||||
|
||||
/**************************************************************************/
|
||||
/* */
|
||||
/* FUNCTION RELEASE */
|
||||
/* */
|
||||
/* _lx_nor_flash_partial_defragment PORTABLE C */
|
||||
/* 6.0 */
|
||||
/**************************************************************************/
|
||||
/* */
|
||||
/* FUNCTION RELEASE */
|
||||
/* */
|
||||
/* _lx_nor_flash_partial_defragment PORTABLE C */
|
||||
/* 6.1.7 */
|
||||
/* AUTHOR */
|
||||
/* */
|
||||
/* William E. Lamie, Microsoft Corporation */
|
||||
/* */
|
||||
/* 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 */
|
||||
/* DESCRIPTION */
|
||||
/* */
|
||||
/* 05-19-2020 William E. Lamie Initial Version 6.0 */
|
||||
/* 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 */
|
||||
/* */
|
||||
/**************************************************************************/
|
||||
UINT _lx_nor_flash_partial_defragment(LX_NOR_FLASH *nor_flash, UINT max_blocks)
|
||||
{
|
||||
|
||||
|
||||
ULONG i;
|
||||
|
||||
|
||||
@@ -93,7 +87,7 @@ ULONG i;
|
||||
/* 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)
|
||||
{
|
||||
|
||||
|
||||
/* Adjust the maximum to the total number of blocks. */
|
||||
max_blocks = nor_flash -> lx_nor_flash_total_blocks;
|
||||
}
|
||||
@@ -101,11 +95,11 @@ ULONG i;
|
||||
/* Loop for max number of blocks, while there are obsolete count. */
|
||||
for (i = 0; i < max_blocks; i++)
|
||||
{
|
||||
|
||||
|
||||
/* Determine if there is any more defragment work. */
|
||||
if (nor_flash -> lx_nor_flash_obsolete_physical_sectors == 0)
|
||||
break;
|
||||
|
||||
break;
|
||||
|
||||
/* Call the block reclaim function to defragment. */
|
||||
_lx_nor_flash_block_reclaim(nor_flash);
|
||||
}
|
||||
@@ -116,7 +110,7 @@ ULONG i;
|
||||
tx_mutex_put(&nor_flash -> lx_nor_flash_mutex);
|
||||
#endif
|
||||
|
||||
/* Return successful completion. */
|
||||
/* Return successful completion. */
|
||||
return(LX_SUCCESS);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,19 +1,19 @@
|
||||
/**************************************************************************/
|
||||
/* */
|
||||
/* Copyright (c) Microsoft Corporation. All rights reserved. */
|
||||
/* */
|
||||
/* This software is licensed under the Microsoft Software License */
|
||||
/* Terms for Microsoft Azure RTOS. Full text of the license can be */
|
||||
/* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */
|
||||
/* and in the root directory of this software. */
|
||||
/* */
|
||||
/**************************************************************************/
|
||||
/***************************************************************************
|
||||
* Copyright (c) 2024 Microsoft Corporation
|
||||
* Copyright (c) 2026-present Eclipse ThreadX contributors
|
||||
*
|
||||
* This program and the accompanying materials are made available under the
|
||||
* terms of the MIT License which is available at
|
||||
* https://opensource.org/licenses/MIT.
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
**************************************************************************/
|
||||
|
||||
|
||||
/**************************************************************************/
|
||||
/**************************************************************************/
|
||||
/** */
|
||||
/** LevelX Component */
|
||||
/** */
|
||||
/** LevelX Component */
|
||||
/** */
|
||||
/** NOR Flash */
|
||||
/** */
|
||||
@@ -25,8 +25,8 @@
|
||||
|
||||
/* Disable ThreadX error checking. */
|
||||
|
||||
#ifndef TX_DISABLE_ERROR_CHECKING
|
||||
#define TX_DISABLE_ERROR_CHECKING
|
||||
#ifndef LX_DISABLE_ERROR_CHECKING
|
||||
#define LX_DISABLE_ERROR_CHECKING
|
||||
#endif
|
||||
|
||||
|
||||
@@ -35,47 +35,41 @@
|
||||
#include "lx_api.h"
|
||||
|
||||
|
||||
/**************************************************************************/
|
||||
/* */
|
||||
/* FUNCTION RELEASE */
|
||||
/* */
|
||||
/* _lx_nor_flash_physical_sector_allocate PORTABLE C */
|
||||
/* 6.0 */
|
||||
/**************************************************************************/
|
||||
/* */
|
||||
/* FUNCTION RELEASE */
|
||||
/* */
|
||||
/* _lx_nor_flash_physical_sector_allocate PORTABLE C */
|
||||
/* 6.1.7 */
|
||||
/* AUTHOR */
|
||||
/* */
|
||||
/* William E. Lamie, Microsoft Corporation */
|
||||
/* */
|
||||
/* 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 */
|
||||
/* DESCRIPTION */
|
||||
/* */
|
||||
/* 05-19-2020 William E. Lamie Initial Version 6.0 */
|
||||
/* 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 */
|
||||
/* */
|
||||
/**************************************************************************/
|
||||
UINT _lx_nor_flash_physical_sector_allocate(LX_NOR_FLASH *nor_flash, ULONG logical_sector, ULONG **physical_sector_map_entry, ULONG **physical_sector_address)
|
||||
@@ -98,7 +92,7 @@ UINT status;
|
||||
/* Initialize the return parameters. */
|
||||
*physical_sector_map_entry = (ULONG *) 0;
|
||||
*physical_sector_address = (ULONG *) 0;
|
||||
|
||||
|
||||
/* Determine if there are any free physical sectors. */
|
||||
if (nor_flash -> lx_nor_flash_free_physical_sectors == 0)
|
||||
{
|
||||
@@ -123,10 +117,10 @@ UINT status;
|
||||
/* 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++)
|
||||
{
|
||||
|
||||
|
||||
/* 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
|
||||
@@ -135,32 +129,32 @@ UINT status;
|
||||
/* 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 the error. */
|
||||
return(status);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
/* Are there any free sectors in this word? */
|
||||
if (block_word)
|
||||
{
|
||||
|
||||
|
||||
/* Yes, there are free sectors in this word. */
|
||||
for (k = 0; k < 32; k++)
|
||||
{
|
||||
|
||||
|
||||
/* Is this sector free? */
|
||||
if (block_word & 1)
|
||||
{
|
||||
|
||||
|
||||
/* 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. */
|
||||
#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
|
||||
@@ -169,7 +163,7 @@ UINT status;
|
||||
/* 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);
|
||||
|
||||
@@ -177,17 +171,17 @@ UINT status;
|
||||
return(status);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
/* Clear the bit associated with the free sector to indicate it is not free. */
|
||||
block_word = block_word & ~(((ULONG) 1) << k);
|
||||
|
||||
|
||||
/* 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);
|
||||
|
||||
/* 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);
|
||||
|
||||
@@ -198,14 +192,14 @@ UINT status;
|
||||
/* 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)))
|
||||
{
|
||||
|
||||
|
||||
/* 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. */
|
||||
|
||||
/* Setup the minimum and maximum logical sectors to the current logical sector. */
|
||||
min_logical_sector = logical_sector;
|
||||
max_logical_sector = logical_sector;
|
||||
|
||||
|
||||
/* Setup a pointer to the mapped list. */
|
||||
list_word_ptr = block_word_ptr + nor_flash -> lx_nor_flash_block_physical_sector_mapping_offset;
|
||||
|
||||
@@ -215,16 +209,16 @@ UINT status;
|
||||
|
||||
/* Read the mapped sector entry. */
|
||||
#ifdef LX_DIRECT_READ
|
||||
|
||||
|
||||
/* Read the word directly. */
|
||||
list_word = *(list_word_ptr);
|
||||
#else
|
||||
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.. */
|
||||
if (status)
|
||||
{
|
||||
|
||||
|
||||
/* Call system error handler. */
|
||||
_lx_nor_flash_system_error(nor_flash, status);
|
||||
|
||||
@@ -232,7 +226,7 @@ UINT status;
|
||||
return(status);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
/* Is this entry valid? */
|
||||
if (list_word & LX_NOR_PHYSICAL_SECTOR_VALID)
|
||||
{
|
||||
@@ -243,50 +237,50 @@ UINT status;
|
||||
/* Determine if a new minimum has been found. */
|
||||
if (list_word < min_logical_sector)
|
||||
min_logical_sector = list_word;
|
||||
|
||||
|
||||
/* Determine if a new maximum has been found. */
|
||||
if (list_word != LX_NOR_LOGICAL_SECTOR_MASK)
|
||||
{
|
||||
if (list_word > max_logical_sector)
|
||||
max_logical_sector = list_word;
|
||||
max_logical_sector = list_word;
|
||||
}
|
||||
}
|
||||
|
||||
/* Move the list pointer ahead. */
|
||||
list_word_ptr++;
|
||||
}
|
||||
|
||||
|
||||
/* Move the search pointer forward, since we know this block is exhausted. */
|
||||
search_block++;
|
||||
|
||||
|
||||
/* Check for wrap condition on the search block. */
|
||||
if (search_block >= nor_flash -> lx_nor_flash_total_blocks)
|
||||
{
|
||||
|
||||
|
||||
/* Reset search block to the beginning. */
|
||||
search_block = 0;
|
||||
}
|
||||
|
||||
|
||||
/* 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);
|
||||
|
||||
/* 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 the error. */
|
||||
return(status);
|
||||
}
|
||||
|
||||
|
||||
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.. */
|
||||
if (status)
|
||||
{
|
||||
|
||||
|
||||
/* Call system error handler. */
|
||||
_lx_nor_flash_system_error(nor_flash, status);
|
||||
|
||||
@@ -294,35 +288,35 @@ UINT status;
|
||||
return(status);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* Remember the block to search. */
|
||||
nor_flash -> lx_nor_flash_free_block_search = search_block;
|
||||
|
||||
|
||||
/* 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_address = block_word_ptr + (nor_flash -> lx_nor_flash_block_physical_sector_offset) + (((j * 32) + k) * LX_NOR_SECTOR_SIZE);
|
||||
|
||||
/* Return success! */
|
||||
return(LX_SUCCESS);
|
||||
return(LX_SUCCESS);
|
||||
}
|
||||
|
||||
|
||||
/* Shift down the bit map. */
|
||||
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. */
|
||||
if (block_word == 0)
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* Move to the next flash block. */
|
||||
search_block++;
|
||||
|
||||
|
||||
/* Determine if we have to wrap the search block. */
|
||||
if (search_block >= nor_flash -> lx_nor_flash_total_blocks)
|
||||
{
|
||||
|
||||
|
||||
/* Set the search block to the beginning. */
|
||||
search_block = 0;
|
||||
}
|
||||
|
||||
@@ -1,19 +1,19 @@
|
||||
/**************************************************************************/
|
||||
/* */
|
||||
/* Copyright (c) Microsoft Corporation. All rights reserved. */
|
||||
/* */
|
||||
/* This software is licensed under the Microsoft Software License */
|
||||
/* Terms for Microsoft Azure RTOS. Full text of the license can be */
|
||||
/* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */
|
||||
/* and in the root directory of this software. */
|
||||
/* */
|
||||
/**************************************************************************/
|
||||
/***************************************************************************
|
||||
* Copyright (c) 2024 Microsoft Corporation
|
||||
* Copyright (c) 2026-present Eclipse ThreadX contributors
|
||||
*
|
||||
* This program and the accompanying materials are made available under the
|
||||
* terms of the MIT License which is available at
|
||||
* https://opensource.org/licenses/MIT.
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
**************************************************************************/
|
||||
|
||||
|
||||
/**************************************************************************/
|
||||
/**************************************************************************/
|
||||
/** */
|
||||
/** LevelX Component */
|
||||
/** */
|
||||
/** LevelX Component */
|
||||
/** */
|
||||
/** NOR Flash */
|
||||
/** */
|
||||
@@ -25,8 +25,8 @@
|
||||
|
||||
/* Disable ThreadX error checking. */
|
||||
|
||||
#ifndef TX_DISABLE_ERROR_CHECKING
|
||||
#define TX_DISABLE_ERROR_CHECKING
|
||||
#ifndef LX_DISABLE_ERROR_CHECKING
|
||||
#define LX_DISABLE_ERROR_CHECKING
|
||||
#endif
|
||||
|
||||
|
||||
@@ -35,43 +35,37 @@
|
||||
#include "lx_api.h"
|
||||
|
||||
|
||||
/**************************************************************************/
|
||||
/* */
|
||||
/* FUNCTION RELEASE */
|
||||
/* */
|
||||
/* _lx_nor_flash_sector_mapping_cache_invalidate PORTABLE C */
|
||||
/* 6.0 */
|
||||
/**************************************************************************/
|
||||
/* */
|
||||
/* FUNCTION RELEASE */
|
||||
/* */
|
||||
/* _lx_nor_flash_sector_mapping_cache_invalidate PORTABLE C */
|
||||
/* 6.1.7 */
|
||||
/* AUTHOR */
|
||||
/* */
|
||||
/* William E. Lamie, Microsoft Corporation */
|
||||
/* */
|
||||
/* 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 */
|
||||
/* DESCRIPTION */
|
||||
/* */
|
||||
/* 05-19-2020 William E. Lamie Initial Version 6.0 */
|
||||
/* 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 */
|
||||
/* */
|
||||
/**************************************************************************/
|
||||
VOID _lx_nor_flash_sector_mapping_cache_invalidate(LX_NOR_FLASH *nor_flash, ULONG logical_sector)
|
||||
@@ -84,14 +78,14 @@ LX_NOR_SECTOR_MAPPING_CACHE_ENTRY *sector_mapping_cache_entry_ptr;
|
||||
/* Determine if the sector mapping cache is enabled. */
|
||||
if (nor_flash -> lx_nor_flash_sector_mapping_cache_enabled)
|
||||
{
|
||||
|
||||
|
||||
/* 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;
|
||||
|
||||
/* Build a pointer to the cache entry. */
|
||||
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. */
|
||||
if ((sector_mapping_cache_entry_ptr -> lx_nor_sector_mapping_cache_logical_sector) == (logical_sector | LX_NOR_SECTOR_MAPPING_CACHE_ENTRY_VALID))
|
||||
{
|
||||
@@ -100,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 + 1) = *(sector_mapping_cache_entry_ptr + 2);
|
||||
*(sector_mapping_cache_entry_ptr + 2) = *(sector_mapping_cache_entry_ptr + 3);
|
||||
|
||||
|
||||
/* Invalidate the last entry. */
|
||||
(sector_mapping_cache_entry_ptr + 3) -> lx_nor_sector_mapping_cache_logical_sector = 0;
|
||||
}
|
||||
@@ -110,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. */
|
||||
*(sector_mapping_cache_entry_ptr + 1) = *(sector_mapping_cache_entry_ptr + 2);
|
||||
*(sector_mapping_cache_entry_ptr + 2) = *(sector_mapping_cache_entry_ptr + 3);
|
||||
|
||||
|
||||
/* Invalidate the last entry. */
|
||||
(sector_mapping_cache_entry_ptr + 3) -> lx_nor_sector_mapping_cache_logical_sector = 0;
|
||||
}
|
||||
@@ -119,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. */
|
||||
*(sector_mapping_cache_entry_ptr + 2) = *(sector_mapping_cache_entry_ptr + 3);
|
||||
|
||||
|
||||
/* Invalidate the last entry. */
|
||||
(sector_mapping_cache_entry_ptr + 3) -> lx_nor_sector_mapping_cache_logical_sector = 0;
|
||||
}
|
||||
|
||||
@@ -1,19 +1,19 @@
|
||||
/**************************************************************************/
|
||||
/* */
|
||||
/* Copyright (c) Microsoft Corporation. All rights reserved. */
|
||||
/* */
|
||||
/* This software is licensed under the Microsoft Software License */
|
||||
/* Terms for Microsoft Azure RTOS. Full text of the license can be */
|
||||
/* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */
|
||||
/* and in the root directory of this software. */
|
||||
/* */
|
||||
/**************************************************************************/
|
||||
/***************************************************************************
|
||||
* Copyright (c) 2024 Microsoft Corporation
|
||||
* Copyright (c) 2026-present Eclipse ThreadX contributors
|
||||
*
|
||||
* This program and the accompanying materials are made available under the
|
||||
* terms of the MIT License which is available at
|
||||
* https://opensource.org/licenses/MIT.
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
**************************************************************************/
|
||||
|
||||
|
||||
/**************************************************************************/
|
||||
/**************************************************************************/
|
||||
/** */
|
||||
/** LevelX Component */
|
||||
/** */
|
||||
/** LevelX Component */
|
||||
/** */
|
||||
/** NOR Flash */
|
||||
/** */
|
||||
@@ -25,8 +25,8 @@
|
||||
|
||||
/* Disable ThreadX error checking. */
|
||||
|
||||
#ifndef TX_DISABLE_ERROR_CHECKING
|
||||
#define TX_DISABLE_ERROR_CHECKING
|
||||
#ifndef LX_DISABLE_ERROR_CHECKING
|
||||
#define LX_DISABLE_ERROR_CHECKING
|
||||
#endif
|
||||
|
||||
|
||||
@@ -35,51 +35,45 @@
|
||||
#include "lx_api.h"
|
||||
|
||||
|
||||
/**************************************************************************/
|
||||
/* */
|
||||
/* FUNCTION RELEASE */
|
||||
/* */
|
||||
/* _lx_nor_flash_sector_read PORTABLE C */
|
||||
/* 6.0 */
|
||||
/**************************************************************************/
|
||||
/* */
|
||||
/* FUNCTION RELEASE */
|
||||
/* */
|
||||
/* _lx_nor_flash_sector_read PORTABLE C */
|
||||
/* 6.3.0 */
|
||||
/* AUTHOR */
|
||||
/* */
|
||||
/* William E. Lamie, Microsoft Corporation */
|
||||
/* */
|
||||
/* 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 */
|
||||
/* DESCRIPTION */
|
||||
/* */
|
||||
/* 05-19-2020 William E. Lamie Initial Version 6.0 */
|
||||
/* 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 */
|
||||
/* */
|
||||
/**************************************************************************/
|
||||
UINT _lx_nor_flash_sector_read(LX_NOR_FLASH *nor_flash, ULONG logical_sector, VOID *buffer)
|
||||
@@ -102,23 +96,23 @@ ULONG *sector_address;
|
||||
|
||||
/* 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);
|
||||
|
||||
|
||||
/* Determine if the logical sector was found. */
|
||||
if (mapping_address)
|
||||
{
|
||||
|
||||
|
||||
/* Yes, we were able to find the logical sector. */
|
||||
|
||||
|
||||
/* Read the sector data from the physical sector. */
|
||||
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.. */
|
||||
if (status)
|
||||
{
|
||||
|
||||
|
||||
/* Call system error handler. */
|
||||
_lx_nor_flash_system_error(nor_flash, status);
|
||||
|
||||
|
||||
/* Adjust return status. */
|
||||
status = LX_ERROR;
|
||||
}
|
||||
@@ -131,7 +125,7 @@ ULONG *sector_address;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
|
||||
/* Allocate a new physical sector for this write. */
|
||||
_lx_nor_flash_physical_sector_allocate(nor_flash, logical_sector, &mapping_address, §or_address);
|
||||
|
||||
@@ -141,31 +135,31 @@ ULONG *sector_address;
|
||||
|
||||
/* Update the number of free physical sectors. */
|
||||
nor_flash -> lx_nor_flash_free_physical_sectors--;
|
||||
|
||||
|
||||
/* Read the sector data from the physical sector. */
|
||||
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.. */
|
||||
if (status)
|
||||
{
|
||||
|
||||
|
||||
/* Call system error handler. */
|
||||
_lx_nor_flash_system_error(nor_flash, status);
|
||||
}
|
||||
|
||||
/* Now build the new mapping entry. */
|
||||
mapping_entry = ((ULONG) LX_NOR_PHYSICAL_SECTOR_VALID) | ((ULONG) LX_NOR_PHYSICAL_SECTOR_SUPERCEDED) | logical_sector;
|
||||
|
||||
|
||||
/* Write out the new mapping entry. */
|
||||
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.. */
|
||||
if (status)
|
||||
{
|
||||
|
||||
|
||||
/* Call system error handler. */
|
||||
_lx_nor_flash_system_error(nor_flash, status);
|
||||
|
||||
|
||||
#ifdef LX_THREAD_SAFE_ENABLE
|
||||
|
||||
/* Release the thread safe mutex. */
|
||||
@@ -175,6 +169,18 @@ ULONG *sector_address;
|
||||
/* Return status. */
|
||||
return(LX_ERROR);
|
||||
}
|
||||
#ifndef LX_NOR_DISABLE_EXTENDED_CACHE
|
||||
#ifdef LX_NOR_ENABLE_MAPPING_BITMAP
|
||||
|
||||
/* Determine if the logical sector is within the mapping bitmap. */
|
||||
if (logical_sector < nor_flash -> lx_nor_flash_extended_cache_mapping_bitmap_max_logical_sector)
|
||||
{
|
||||
|
||||
/* Set the bit in the mapping bitmap. */
|
||||
nor_flash -> lx_nor_flash_extended_cache_mapping_bitmap[logical_sector >> 5] |= (ULONG)(1 << (logical_sector & 31));
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/* Increment the number of mapped physical sectors. */
|
||||
nor_flash -> lx_nor_flash_mapped_physical_sectors++;
|
||||
@@ -184,12 +190,12 @@ ULONG *sector_address;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
|
||||
/* Could not find the logical sector. */
|
||||
status = LX_SECTOR_NOT_FOUND;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#ifdef LX_THREAD_SAFE_ENABLE
|
||||
|
||||
/* Release the thread safe mutex. */
|
||||
|
||||
@@ -1,19 +1,19 @@
|
||||
/**************************************************************************/
|
||||
/* */
|
||||
/* Copyright (c) Microsoft Corporation. All rights reserved. */
|
||||
/* */
|
||||
/* This software is licensed under the Microsoft Software License */
|
||||
/* Terms for Microsoft Azure RTOS. Full text of the license can be */
|
||||
/* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */
|
||||
/* and in the root directory of this software. */
|
||||
/* */
|
||||
/**************************************************************************/
|
||||
/***************************************************************************
|
||||
* Copyright (c) 2024 Microsoft Corporation
|
||||
* Copyright (c) 2026-present Eclipse ThreadX contributors
|
||||
*
|
||||
* This program and the accompanying materials are made available under the
|
||||
* terms of the MIT License which is available at
|
||||
* https://opensource.org/licenses/MIT.
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
**************************************************************************/
|
||||
|
||||
|
||||
/**************************************************************************/
|
||||
/**************************************************************************/
|
||||
/** */
|
||||
/** LevelX Component */
|
||||
/** */
|
||||
/** LevelX Component */
|
||||
/** */
|
||||
/** NOR Flash */
|
||||
/** */
|
||||
@@ -25,8 +25,8 @@
|
||||
|
||||
/* Disable ThreadX error checking. */
|
||||
|
||||
#ifndef TX_DISABLE_ERROR_CHECKING
|
||||
#define TX_DISABLE_ERROR_CHECKING
|
||||
#ifndef LX_DISABLE_ERROR_CHECKING
|
||||
#define LX_DISABLE_ERROR_CHECKING
|
||||
#endif
|
||||
|
||||
|
||||
@@ -35,51 +35,45 @@
|
||||
#include "lx_api.h"
|
||||
|
||||
|
||||
/**************************************************************************/
|
||||
/* */
|
||||
/* FUNCTION RELEASE */
|
||||
/* */
|
||||
/* _lx_nor_flash_sector_release PORTABLE C */
|
||||
/* 6.0 */
|
||||
/**************************************************************************/
|
||||
/* */
|
||||
/* FUNCTION RELEASE */
|
||||
/* */
|
||||
/* _lx_nor_flash_sector_release PORTABLE C */
|
||||
/* 6.3.0 */
|
||||
/* AUTHOR */
|
||||
/* */
|
||||
/* William E. Lamie, Microsoft Corporation */
|
||||
/* */
|
||||
/* 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 */
|
||||
/* DESCRIPTION */
|
||||
/* */
|
||||
/* 05-19-2020 William E. Lamie Initial Version 6.0 */
|
||||
/* 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 */
|
||||
/* */
|
||||
/**************************************************************************/
|
||||
UINT _lx_nor_flash_sector_release(LX_NOR_FLASH *nor_flash, ULONG logical_sector)
|
||||
@@ -90,6 +84,9 @@ ULONG *mapping_address;
|
||||
ULONG mapping_entry;
|
||||
ULONG *sector_address;
|
||||
ULONG i;
|
||||
#ifdef LX_NOR_ENABLE_OBSOLETE_COUNT_CACHE
|
||||
ULONG block;
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef LX_THREAD_SAFE_ENABLE
|
||||
@@ -103,16 +100,16 @@ ULONG i;
|
||||
|
||||
/* 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);
|
||||
|
||||
|
||||
/* Determine if the logical sector was found. */
|
||||
if (mapping_address)
|
||||
{
|
||||
|
||||
|
||||
/* Yes, we were able to find the logical sector. */
|
||||
|
||||
|
||||
/* Read in the old sector mapping. */
|
||||
#ifdef LX_DIRECT_READ
|
||||
|
||||
|
||||
/* Read the word directly. */
|
||||
mapping_entry = *(mapping_address);
|
||||
#else
|
||||
@@ -121,7 +118,7 @@ ULONG i;
|
||||
/* 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);
|
||||
|
||||
@@ -139,14 +136,14 @@ ULONG i;
|
||||
/* Mark this sector as invalid. */
|
||||
/* 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));
|
||||
|
||||
|
||||
/* 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);
|
||||
|
||||
|
||||
/* 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);
|
||||
|
||||
@@ -160,12 +157,39 @@ ULONG i;
|
||||
return(LX_ERROR);
|
||||
}
|
||||
|
||||
#ifndef LX_NOR_DISABLE_EXTENDED_CACHE
|
||||
#ifdef LX_NOR_ENABLE_MAPPING_BITMAP
|
||||
|
||||
/* Determine if the logical sector is within the mapping bitmap. */
|
||||
if (logical_sector < nor_flash -> lx_nor_flash_extended_cache_mapping_bitmap_max_logical_sector)
|
||||
{
|
||||
|
||||
/* Set the bit in the mapping bitmap. */
|
||||
nor_flash -> lx_nor_flash_extended_cache_mapping_bitmap[logical_sector >> 5] &= (ULONG)~(1 << (logical_sector & 31));
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/* Increment the number of obsolete physical sectors. */
|
||||
nor_flash -> lx_nor_flash_obsolete_physical_sectors++;
|
||||
|
||||
#ifdef LX_NOR_ENABLE_OBSOLETE_COUNT_CACHE
|
||||
|
||||
/* 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;
|
||||
|
||||
/* 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)
|
||||
{
|
||||
|
||||
/* Increment the obsolete count for this block. */
|
||||
nor_flash -> lx_nor_flash_extended_cache_obsolete_count[block] ++;
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Decrement the number of mapped physical sectors. */
|
||||
nor_flash -> lx_nor_flash_mapped_physical_sectors--;
|
||||
|
||||
|
||||
/* Ensure the sector mapping cache no longer has this sector. */
|
||||
_lx_nor_flash_sector_mapping_cache_invalidate(nor_flash, logical_sector);
|
||||
|
||||
@@ -173,7 +197,7 @@ ULONG i;
|
||||
i = 0;
|
||||
while (nor_flash -> lx_nor_flash_free_physical_sectors <= nor_flash -> lx_nor_flash_physical_sectors_per_block)
|
||||
{
|
||||
|
||||
|
||||
/* Attempt to reclaim one physical block. */
|
||||
_lx_nor_flash_block_reclaim(nor_flash);
|
||||
|
||||
@@ -182,8 +206,8 @@ ULONG i;
|
||||
|
||||
/* Have we exceeded the number of blocks in the system? */
|
||||
if (i >= nor_flash -> lx_nor_flash_total_blocks)
|
||||
{
|
||||
|
||||
{
|
||||
|
||||
/* Yes, break out of the loop. */
|
||||
break;
|
||||
}
|
||||
@@ -198,7 +222,7 @@ ULONG i;
|
||||
/* Could not find the logical sector. */
|
||||
status = LX_SECTOR_NOT_FOUND;
|
||||
}
|
||||
|
||||
|
||||
#ifdef LX_THREAD_SAFE_ENABLE
|
||||
|
||||
/* Release the thread safe mutex. */
|
||||
|
||||
@@ -1,19 +1,19 @@
|
||||
/**************************************************************************/
|
||||
/* */
|
||||
/* Copyright (c) Microsoft Corporation. All rights reserved. */
|
||||
/* */
|
||||
/* This software is licensed under the Microsoft Software License */
|
||||
/* Terms for Microsoft Azure RTOS. Full text of the license can be */
|
||||
/* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */
|
||||
/* and in the root directory of this software. */
|
||||
/* */
|
||||
/**************************************************************************/
|
||||
/***************************************************************************
|
||||
* Copyright (c) 2024 Microsoft Corporation
|
||||
* Copyright (c) 2026-present Eclipse ThreadX contributors
|
||||
*
|
||||
* This program and the accompanying materials are made available under the
|
||||
* terms of the MIT License which is available at
|
||||
* https://opensource.org/licenses/MIT.
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
**************************************************************************/
|
||||
|
||||
|
||||
/**************************************************************************/
|
||||
/**************************************************************************/
|
||||
/** */
|
||||
/** LevelX Component */
|
||||
/** */
|
||||
/** LevelX Component */
|
||||
/** */
|
||||
/** NOR Flash */
|
||||
/** */
|
||||
@@ -25,8 +25,8 @@
|
||||
|
||||
/* Disable ThreadX error checking. */
|
||||
|
||||
#ifndef TX_DISABLE_ERROR_CHECKING
|
||||
#define TX_DISABLE_ERROR_CHECKING
|
||||
#ifndef LX_DISABLE_ERROR_CHECKING
|
||||
#define LX_DISABLE_ERROR_CHECKING
|
||||
#endif
|
||||
|
||||
|
||||
@@ -35,54 +35,48 @@
|
||||
#include "lx_api.h"
|
||||
|
||||
|
||||
/**************************************************************************/
|
||||
/* */
|
||||
/* FUNCTION RELEASE */
|
||||
/* */
|
||||
/* _lx_nor_flash_sector_write PORTABLE C */
|
||||
/* 6.0 */
|
||||
/**************************************************************************/
|
||||
/* */
|
||||
/* FUNCTION RELEASE */
|
||||
/* */
|
||||
/* _lx_nor_flash_sector_write PORTABLE C */
|
||||
/* 6.3.0 */
|
||||
/* AUTHOR */
|
||||
/* */
|
||||
/* William E. Lamie, Microsoft Corporation */
|
||||
/* */
|
||||
/* 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 */
|
||||
/* DESCRIPTION */
|
||||
/* */
|
||||
/* 05-19-2020 William E. Lamie Initial Version 6.0 */
|
||||
/* 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 */
|
||||
/* */
|
||||
/**************************************************************************/
|
||||
UINT _lx_nor_flash_sector_write(LX_NOR_FLASH *nor_flash, ULONG logical_sector, VOID *buffer)
|
||||
@@ -97,7 +91,9 @@ ULONG new_mapping_entry;
|
||||
ULONG i;
|
||||
LX_NOR_SECTOR_MAPPING_CACHE_ENTRY *sector_mapping_cache_entry_ptr;
|
||||
UINT status;
|
||||
|
||||
#ifdef LX_NOR_ENABLE_OBSOLETE_COUNT_CACHE
|
||||
ULONG block;
|
||||
#endif
|
||||
|
||||
#ifdef LX_THREAD_SAFE_ENABLE
|
||||
|
||||
@@ -109,7 +105,7 @@ UINT status;
|
||||
i = 0;
|
||||
while (nor_flash -> lx_nor_flash_free_physical_sectors <= nor_flash -> lx_nor_flash_physical_sectors_per_block)
|
||||
{
|
||||
|
||||
|
||||
/* Attempt to reclaim one physical block. */
|
||||
_lx_nor_flash_block_reclaim(nor_flash);
|
||||
|
||||
@@ -118,8 +114,8 @@ UINT status;
|
||||
|
||||
/* Have we exceeded the number of blocks in the system? */
|
||||
if (i >= nor_flash -> lx_nor_flash_total_blocks)
|
||||
{
|
||||
|
||||
{
|
||||
|
||||
/* Yes, break out of the loop. */
|
||||
break;
|
||||
}
|
||||
@@ -130,14 +126,14 @@ UINT status;
|
||||
|
||||
/* 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);
|
||||
|
||||
|
||||
/* Allocate a new physical sector for this write. */
|
||||
_lx_nor_flash_physical_sector_allocate(nor_flash, logical_sector, &new_mapping_address, &new_sector_address);
|
||||
|
||||
/* Determine if the new sector allocation was successful. */
|
||||
if (new_mapping_address)
|
||||
{
|
||||
|
||||
|
||||
/* Yes, we were able to allocate a new physical sector. */
|
||||
|
||||
/* Update the number of free physical sectors. */
|
||||
@@ -149,7 +145,7 @@ UINT status;
|
||||
/* 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);
|
||||
|
||||
@@ -168,10 +164,10 @@ UINT status;
|
||||
{
|
||||
|
||||
/* Now deprecate the old sector mapping. */
|
||||
|
||||
|
||||
/* Read in the old sector mapping. */
|
||||
#ifdef LX_DIRECT_READ
|
||||
|
||||
|
||||
/* Read the word directly. */
|
||||
old_mapping_entry = *(old_mapping_address);
|
||||
#else
|
||||
@@ -180,7 +176,7 @@ UINT status;
|
||||
/* 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);
|
||||
|
||||
@@ -194,17 +190,17 @@ UINT status;
|
||||
return(LX_ERROR);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
/* Clear bit 30, which indicates this sector is superceded. */
|
||||
old_mapping_entry = old_mapping_entry & ~((ULONG) LX_NOR_PHYSICAL_SECTOR_SUPERCEDED);
|
||||
|
||||
|
||||
/* 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);
|
||||
|
||||
/* 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);
|
||||
|
||||
@@ -218,17 +214,17 @@ UINT status;
|
||||
return(LX_ERROR);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* 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;
|
||||
|
||||
|
||||
/* Write out the new mapping entry. */
|
||||
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.. */
|
||||
if (status)
|
||||
{
|
||||
|
||||
|
||||
/* Call system error handler. */
|
||||
_lx_nor_flash_system_error(nor_flash, status);
|
||||
|
||||
@@ -242,17 +238,17 @@ UINT status;
|
||||
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. */
|
||||
new_mapping_entry = new_mapping_entry & ~((ULONG) LX_NOR_PHYSICAL_SECTOR_MAPPING_NOT_VALID);
|
||||
|
||||
|
||||
/* Clear the not valid bit. */
|
||||
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.. */
|
||||
if (status)
|
||||
{
|
||||
|
||||
|
||||
/* Call system error handler. */
|
||||
_lx_nor_flash_system_error(nor_flash, status);
|
||||
|
||||
@@ -265,24 +261,36 @@ UINT status;
|
||||
/* Return status. */
|
||||
return(LX_ERROR);
|
||||
}
|
||||
#ifndef LX_NOR_DISABLE_EXTENDED_CACHE
|
||||
#ifdef LX_NOR_ENABLE_MAPPING_BITMAP
|
||||
|
||||
/* Determine if the logical sector is within the mapping bitmap. */
|
||||
if (logical_sector < nor_flash -> lx_nor_flash_extended_cache_mapping_bitmap_max_logical_sector)
|
||||
{
|
||||
|
||||
/* Set the bit in the mapping bitmap. */
|
||||
nor_flash -> lx_nor_flash_extended_cache_mapping_bitmap[logical_sector >> 5] |= (ULONG)(1 << (logical_sector & 31));
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/* Increment the number of mapped physical sectors. */
|
||||
nor_flash -> lx_nor_flash_mapped_physical_sectors++;
|
||||
|
||||
|
||||
/* Was there a previously mapped sector? */
|
||||
if (old_mapping_address)
|
||||
{
|
||||
|
||||
|
||||
/* Now clear bit 31, which indicates this sector is now obsoleted. */
|
||||
old_mapping_entry = old_mapping_entry & ~((ULONG) LX_NOR_PHYSICAL_SECTOR_VALID);
|
||||
|
||||
|
||||
/* 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);
|
||||
|
||||
|
||||
/* 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);
|
||||
|
||||
@@ -299,9 +307,23 @@ UINT status;
|
||||
/* Increment the number of obsolete physical sectors. */
|
||||
nor_flash -> lx_nor_flash_obsolete_physical_sectors++;
|
||||
|
||||
#ifdef LX_NOR_ENABLE_OBSOLETE_COUNT_CACHE
|
||||
|
||||
/* Get the block number from mapping address. */
|
||||
block = (ULONG)(old_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. */
|
||||
if (block < nor_flash -> lx_nor_flash_extended_cache_obsolete_count_max_block)
|
||||
{
|
||||
|
||||
/* Increment the obsolete count for this block. */
|
||||
nor_flash -> lx_nor_flash_extended_cache_obsolete_count[block] ++;
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Decrement the number of mapped physical sectors. */
|
||||
nor_flash -> lx_nor_flash_mapped_physical_sectors--;
|
||||
|
||||
|
||||
/* Invalidate the old sector mapping cache entry. */
|
||||
_lx_nor_flash_sector_mapping_cache_invalidate(nor_flash, logical_sector);
|
||||
}
|
||||
@@ -309,9 +331,9 @@ UINT status;
|
||||
/* Determine if the sector mapping cache is enabled. */
|
||||
if (nor_flash -> lx_nor_flash_sector_mapping_cache_enabled)
|
||||
{
|
||||
|
||||
|
||||
/* 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. */
|
||||
i = (logical_sector & LX_NOR_SECTOR_MAPPING_CACHE_HASH_MASK) * LX_NOR_SECTOR_MAPPING_CACHE_DEPTH;
|
||||
|
||||
@@ -322,7 +344,7 @@ UINT status;
|
||||
*(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 + 1) = *(sector_mapping_cache_entry_ptr);
|
||||
|
||||
|
||||
/* 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_physical_sector_map_entry = new_mapping_address;
|
||||
@@ -330,11 +352,11 @@ UINT status;
|
||||
}
|
||||
|
||||
/* Indicate the write was successful. */
|
||||
status = LX_SUCCESS;
|
||||
status = LX_SUCCESS;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
|
||||
/* Indicate the write was unsuccessful. */
|
||||
status = LX_NO_SECTORS;
|
||||
}
|
||||
|
||||
@@ -1,19 +1,19 @@
|
||||
/**************************************************************************/
|
||||
/* */
|
||||
/* Copyright (c) Microsoft Corporation. All rights reserved. */
|
||||
/* */
|
||||
/* This software is licensed under the Microsoft Software License */
|
||||
/* Terms for Microsoft Azure RTOS. Full text of the license can be */
|
||||
/* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */
|
||||
/* and in the root directory of this software. */
|
||||
/* */
|
||||
/**************************************************************************/
|
||||
/***************************************************************************
|
||||
* Copyright (c) 2024 Microsoft Corporation
|
||||
* Copyright (c) 2026-present Eclipse ThreadX contributors
|
||||
*
|
||||
* This program and the accompanying materials are made available under the
|
||||
* terms of the MIT License which is available at
|
||||
* https://opensource.org/licenses/MIT.
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
**************************************************************************/
|
||||
|
||||
|
||||
/**************************************************************************/
|
||||
/**************************************************************************/
|
||||
/** */
|
||||
/** LevelX Component */
|
||||
/** */
|
||||
/** LevelX Component */
|
||||
/** */
|
||||
/** NOR Flash Simulator */
|
||||
/** */
|
||||
@@ -23,7 +23,6 @@
|
||||
|
||||
/* Include necessary files. */
|
||||
|
||||
#include "tx_api.h"
|
||||
#include "lx_api.h"
|
||||
|
||||
/* Define constants for the NOR flash simulation. */
|
||||
@@ -61,13 +60,20 @@ FLASH_BLOCK nor_memory_area[TOTAL_BLOCKS];
|
||||
ULONG nor_sector_memory[WORDS_PER_PHYSICAL_SECTOR];
|
||||
|
||||
UINT _lx_nor_flash_simulator_initialize(LX_NOR_FLASH *nor_flash);
|
||||
UINT _lx_nor_flash_simulator_erase_all(VOID);
|
||||
#ifdef LX_NOR_ENABLE_CONTROL_BLOCK_FOR_DRIVER_INTERFACE
|
||||
UINT _lx_nor_flash_simulator_read(LX_NOR_FLASH *nor_flash, ULONG *flash_address, ULONG *destination, ULONG words);
|
||||
UINT _lx_nor_flash_simulator_write(LX_NOR_FLASH *nor_flash, ULONG *flash_address, ULONG *source, ULONG words);
|
||||
UINT _lx_nor_flash_simulator_block_erase(LX_NOR_FLASH *nor_flash, ULONG block, ULONG erase_count);
|
||||
UINT _lx_nor_flash_simulator_block_erased_verify(LX_NOR_FLASH *nor_flash, ULONG block);
|
||||
UINT _lx_nor_flash_simulator_system_error(LX_NOR_FLASH *nor_flash, UINT error_code, ULONG block, ULONG sector);
|
||||
#else
|
||||
UINT _lx_nor_flash_simulator_read(ULONG *flash_address, ULONG *destination, ULONG words);
|
||||
UINT _lx_nor_flash_simulator_write(ULONG *flash_address, ULONG *source, ULONG words);
|
||||
UINT _lx_nor_flash_simulator_block_erase(ULONG block, ULONG erase_count);
|
||||
UINT _lx_nor_flash_simulator_block_erased_verify(ULONG block);
|
||||
UINT _lx_nor_flash_simulator_erase_all(VOID);
|
||||
UINT _lx_nor_flash_simulator_system_error(UINT error_code, ULONG block, ULONG sector);
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
UINT _lx_nor_flash_simulator_initialize(LX_NOR_FLASH *nor_flash)
|
||||
@@ -93,10 +99,17 @@ UINT _lx_nor_flash_simulator_initialize(LX_NOR_FLASH *nor_flash)
|
||||
return(LX_SUCCESS);
|
||||
}
|
||||
|
||||
|
||||
#ifdef LX_NOR_ENABLE_CONTROL_BLOCK_FOR_DRIVER_INTERFACE
|
||||
UINT _lx_nor_flash_simulator_read(LX_NOR_FLASH *nor_flash, ULONG *flash_address, ULONG *destination, ULONG words)
|
||||
#else
|
||||
UINT _lx_nor_flash_simulator_read(ULONG *flash_address, ULONG *destination, ULONG words)
|
||||
#endif
|
||||
{
|
||||
|
||||
#ifdef LX_NOR_ENABLE_CONTROL_BLOCK_FOR_DRIVER_INTERFACE
|
||||
LX_PARAMETER_NOT_USED(nor_flash);
|
||||
#endif
|
||||
|
||||
/* Loop to read flash. */
|
||||
while (words--)
|
||||
{
|
||||
@@ -108,13 +121,21 @@ UINT _lx_nor_flash_simulator_read(ULONG *flash_address, ULONG *destination, ULO
|
||||
}
|
||||
|
||||
|
||||
#ifdef LX_NOR_ENABLE_CONTROL_BLOCK_FOR_DRIVER_INTERFACE
|
||||
UINT _lx_nor_flash_simulator_write(LX_NOR_FLASH *nor_flash, ULONG *flash_address, ULONG *source, ULONG words)
|
||||
#else
|
||||
UINT _lx_nor_flash_simulator_write(ULONG *flash_address, ULONG *source, ULONG words)
|
||||
#endif
|
||||
{
|
||||
|
||||
#ifdef LX_NOR_ENABLE_CONTROL_BLOCK_FOR_DRIVER_INTERFACE
|
||||
LX_PARAMETER_NOT_USED(nor_flash);
|
||||
#endif
|
||||
|
||||
/* Loop to write flash. */
|
||||
while (words--)
|
||||
{
|
||||
|
||||
|
||||
/* Copy word. */
|
||||
*flash_address++ = *source++;
|
||||
}
|
||||
@@ -122,12 +143,19 @@ UINT _lx_nor_flash_simulator_write(ULONG *flash_address, ULONG *source, ULONG w
|
||||
return(LX_SUCCESS);
|
||||
}
|
||||
|
||||
#ifdef LX_NOR_ENABLE_CONTROL_BLOCK_FOR_DRIVER_INTERFACE
|
||||
UINT _lx_nor_flash_simulator_block_erase(LX_NOR_FLASH *nor_flash, ULONG block, ULONG erase_count)
|
||||
#else
|
||||
UINT _lx_nor_flash_simulator_block_erase(ULONG block, ULONG erase_count)
|
||||
#endif
|
||||
{
|
||||
|
||||
ULONG *pointer;
|
||||
ULONG words;
|
||||
|
||||
#ifdef LX_NOR_ENABLE_CONTROL_BLOCK_FOR_DRIVER_INTERFACE
|
||||
LX_PARAMETER_NOT_USED(nor_flash);
|
||||
#endif
|
||||
LX_PARAMETER_NOT_USED(erase_count);
|
||||
|
||||
/* Setup pointer. */
|
||||
@@ -137,7 +165,7 @@ ULONG words;
|
||||
words = sizeof(FLASH_BLOCK)/sizeof(ULONG);
|
||||
while (words--)
|
||||
{
|
||||
|
||||
|
||||
/* Erase word of block. */
|
||||
*pointer++ = (ULONG) 0xFFFFFFFF;
|
||||
}
|
||||
@@ -157,10 +185,10 @@ ULONG words;
|
||||
pointer = (ULONG *) &nor_memory_area[0];
|
||||
|
||||
/* Loop to erase block. */
|
||||
words = sizeof(nor_memory_area)/sizeof(ULONG);
|
||||
words = sizeof(nor_memory_area)/(sizeof(ULONG));
|
||||
while (words--)
|
||||
{
|
||||
|
||||
|
||||
/* Erase word of block. */
|
||||
*pointer++ = (ULONG) 0xFFFFFFFF;
|
||||
}
|
||||
@@ -169,35 +197,51 @@ ULONG words;
|
||||
}
|
||||
|
||||
|
||||
#ifdef LX_NOR_ENABLE_CONTROL_BLOCK_FOR_DRIVER_INTERFACE
|
||||
UINT _lx_nor_flash_simulator_block_erased_verify(LX_NOR_FLASH *nor_flash, ULONG block)
|
||||
#else
|
||||
UINT _lx_nor_flash_simulator_block_erased_verify(ULONG block)
|
||||
#endif
|
||||
{
|
||||
|
||||
ULONG *word_ptr;
|
||||
ULONG words;
|
||||
|
||||
#ifdef LX_NOR_ENABLE_CONTROL_BLOCK_FOR_DRIVER_INTERFACE
|
||||
LX_PARAMETER_NOT_USED(nor_flash);
|
||||
#endif
|
||||
|
||||
/* Determine if the block is completely erased. */
|
||||
|
||||
|
||||
/* Pickup the pointer to the first word of the block. */
|
||||
word_ptr = (ULONG *) &nor_memory_area[block].erase_count;
|
||||
|
||||
|
||||
/* Calculate the number of words in a block. */
|
||||
words = sizeof(FLASH_BLOCK)/sizeof(ULONG);
|
||||
|
||||
|
||||
/* Loop to check if the block is erased. */
|
||||
while (words--)
|
||||
{
|
||||
|
||||
|
||||
/* Is this word erased? */
|
||||
if (*word_ptr++ != 0xFFFFFFFF)
|
||||
return(LX_ERROR);
|
||||
}
|
||||
|
||||
|
||||
/* Return success. */
|
||||
return(LX_SUCCESS);
|
||||
}
|
||||
|
||||
#ifdef LX_NOR_ENABLE_CONTROL_BLOCK_FOR_DRIVER_INTERFACE
|
||||
UINT _lx_nor_flash_simulator_system_error(LX_NOR_FLASH *nor_flash, UINT error_code, ULONG block, ULONG sector)
|
||||
#else
|
||||
UINT _lx_nor_flash_simulator_system_error(UINT error_code, ULONG block, ULONG sector)
|
||||
#endif
|
||||
{
|
||||
|
||||
#ifdef LX_NOR_ENABLE_CONTROL_BLOCK_FOR_DRIVER_INTERFACE
|
||||
LX_PARAMETER_NOT_USED(nor_flash);
|
||||
#endif
|
||||
LX_PARAMETER_NOT_USED(error_code);
|
||||
LX_PARAMETER_NOT_USED(block);
|
||||
LX_PARAMETER_NOT_USED(sector);
|
||||
|
||||
@@ -1,19 +1,19 @@
|
||||
/**************************************************************************/
|
||||
/* */
|
||||
/* Copyright (c) Microsoft Corporation. All rights reserved. */
|
||||
/* */
|
||||
/* This software is licensed under the Microsoft Software License */
|
||||
/* Terms for Microsoft Azure RTOS. Full text of the license can be */
|
||||
/* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */
|
||||
/* and in the root directory of this software. */
|
||||
/* */
|
||||
/**************************************************************************/
|
||||
/***************************************************************************
|
||||
* Copyright (c) 2024 Microsoft Corporation
|
||||
* Copyright (c) 2026-present Eclipse ThreadX contributors
|
||||
*
|
||||
* This program and the accompanying materials are made available under the
|
||||
* terms of the MIT License which is available at
|
||||
* https://opensource.org/licenses/MIT.
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
**************************************************************************/
|
||||
|
||||
|
||||
/**************************************************************************/
|
||||
/**************************************************************************/
|
||||
/** */
|
||||
/** LevelX Component */
|
||||
/** */
|
||||
/** LevelX Component */
|
||||
/** */
|
||||
/** NOR Flash */
|
||||
/** */
|
||||
@@ -25,8 +25,8 @@
|
||||
|
||||
/* Disable ThreadX error checking. */
|
||||
|
||||
#ifndef TX_DISABLE_ERROR_CHECKING
|
||||
#define TX_DISABLE_ERROR_CHECKING
|
||||
#ifndef LX_DISABLE_ERROR_CHECKING
|
||||
#define LX_DISABLE_ERROR_CHECKING
|
||||
#endif
|
||||
|
||||
|
||||
@@ -35,42 +35,36 @@
|
||||
#include "lx_api.h"
|
||||
|
||||
|
||||
/**************************************************************************/
|
||||
/* */
|
||||
/* FUNCTION RELEASE */
|
||||
/* */
|
||||
/* _lx_nor_flash_system_error PORTABLE C */
|
||||
/* 6.0 */
|
||||
/**************************************************************************/
|
||||
/* */
|
||||
/* FUNCTION RELEASE */
|
||||
/* */
|
||||
/* _lx_nor_flash_system_error PORTABLE C */
|
||||
/* 6.2.1 */
|
||||
/* AUTHOR */
|
||||
/* */
|
||||
/* William E. Lamie, Microsoft Corporation */
|
||||
/* */
|
||||
/* 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 */
|
||||
/* DESCRIPTION */
|
||||
/* */
|
||||
/* 05-19-2020 William E. Lamie Initial Version 6.0 */
|
||||
/* 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 */
|
||||
/* */
|
||||
/**************************************************************************/
|
||||
VOID _lx_nor_flash_system_error(LX_NOR_FLASH *nor_flash, UINT error_code)
|
||||
@@ -78,16 +72,20 @@ VOID _lx_nor_flash_system_error(LX_NOR_FLASH *nor_flash, UINT error_code)
|
||||
|
||||
/* Increment the system error counter. */
|
||||
nor_flash -> lx_nor_flash_diagnostic_system_errors++;
|
||||
|
||||
|
||||
/* Save the most recent system error code. */
|
||||
nor_flash -> lx_nor_flash_diagnostic_system_error = error_code;
|
||||
|
||||
|
||||
/* Determine if the driver has setup a system error handler. */
|
||||
if (nor_flash -> lx_nor_flash_driver_system_error)
|
||||
{
|
||||
|
||||
|
||||
/* Yes, call the driver's system error handler. */
|
||||
#ifdef LX_NOR_ENABLE_CONTROL_BLOCK_FOR_DRIVER_INTERFACE
|
||||
(nor_flash -> lx_nor_flash_driver_system_error)(nor_flash, error_code);
|
||||
#else
|
||||
(nor_flash -> lx_nor_flash_driver_system_error)(error_code);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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. */
|
||||
|
||||
#include <stdio.h>
|
||||
@@ -9,7 +20,7 @@
|
||||
#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. */
|
||||
|
||||
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. */
|
||||
|
||||
UINT _lx_nand_flash_simulator_erase_all(VOID);
|
||||
|
||||
|
||||
|
||||
|
||||
/* Define thread prototypes. */
|
||||
|
||||
void thread_0_entry(ULONG thread_input);
|
||||
@@ -40,20 +51,34 @@ FX_FILE my_file1;
|
||||
|
||||
/* Define ThreadX global data structures. */
|
||||
|
||||
#ifndef LX_STANDALONE_ENABLE
|
||||
TX_THREAD thread_0;
|
||||
#endif
|
||||
ULONG thread_0_counter;
|
||||
|
||||
|
||||
int main(void)
|
||||
{
|
||||
|
||||
/* Enter the ThreadX kernel. */
|
||||
#ifndef LX_STANDALONE_ENABLE
|
||||
tx_kernel_enter();
|
||||
#else
|
||||
|
||||
/* Initialize NAND flash. */
|
||||
lx_nand_flash_initialize();
|
||||
|
||||
/* Initialize FileX. */
|
||||
fx_system_initialize();
|
||||
|
||||
thread_0_entry(0);
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
|
||||
/* Define what the initial system looks like. */
|
||||
|
||||
#ifndef LX_STANDALONE_ENABLE
|
||||
void tx_application_define(void *first_unused_memory)
|
||||
{
|
||||
|
||||
@@ -62,17 +87,17 @@ void tx_application_define(void *first_unused_memory)
|
||||
create information. */
|
||||
|
||||
/* Create the main thread. */
|
||||
tx_thread_create(&thread_0, "thread 0", thread_0_entry, 0,
|
||||
thread_0_stack, DEMO_STACK_SIZE,
|
||||
tx_thread_create(&thread_0, "thread 0", thread_0_entry, 0,
|
||||
thread_0_stack, DEMO_STACK_SIZE,
|
||||
1, 1, TX_NO_TIME_SLICE, TX_AUTO_START);
|
||||
|
||||
/* Initialize NAND flash. */
|
||||
lx_nand_flash_initialize();
|
||||
|
||||
lx_nand_flash_initialize();
|
||||
|
||||
/* Initialize FileX. */
|
||||
fx_system_initialize();
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
void thread_0_entry(ULONG thread_input)
|
||||
@@ -83,27 +108,27 @@ ULONG actual;
|
||||
CHAR local_buffer[30];
|
||||
|
||||
LX_PARAMETER_NOT_USED(thread_input);
|
||||
|
||||
|
||||
/* Erase the simulated NAND flash. */
|
||||
_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
|
||||
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_NULL, // Unused
|
||||
media_memory, // Media buffer pointer
|
||||
sizeof(media_memory), // Media buffer size
|
||||
sizeof(media_memory), // Media buffer size
|
||||
"MY_NAND_DISK", // Volume Name
|
||||
1, // Number of FATs
|
||||
32, // Directory Entries
|
||||
0, // Hidden sectors
|
||||
120, // Total sectors
|
||||
2048, // Sector size
|
||||
120, // Total sectors
|
||||
2048, // Sector size
|
||||
1, // Sectors per cluster
|
||||
1, // Heads
|
||||
1); // Sectors per track
|
||||
1); // Sectors per track
|
||||
|
||||
/* Loop to repeat the demo over and over! */
|
||||
do
|
||||
@@ -205,7 +230,7 @@ CHAR local_buffer[30];
|
||||
|
||||
/* Delete the file. */
|
||||
status = fx_file_delete(&nand_disk, "TEST.TXT");
|
||||
|
||||
|
||||
/* Check the file delete status. */
|
||||
if (status != FX_SUCCESS)
|
||||
{
|
||||
@@ -213,7 +238,7 @@ CHAR local_buffer[30];
|
||||
/* Error deleting the file, break the loop. */
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
/* Close the media. */
|
||||
status = fx_media_close(&nand_disk);
|
||||
|
||||
@@ -229,7 +254,7 @@ CHAR local_buffer[30];
|
||||
of successful passes through this loop. */
|
||||
thread_0_counter++;
|
||||
} while (1);
|
||||
|
||||
|
||||
/* If we get here the FileX test failed! */
|
||||
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. */
|
||||
|
||||
#include "fx_api.h"
|
||||
@@ -8,7 +19,7 @@
|
||||
#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. */
|
||||
|
||||
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. */
|
||||
|
||||
UINT _lx_nor_flash_simulator_erase_all(VOID);
|
||||
|
||||
|
||||
|
||||
|
||||
/* Define thread prototypes. */
|
||||
|
||||
void thread_0_entry(ULONG thread_input);
|
||||
@@ -39,20 +50,34 @@ FX_FILE my_file;
|
||||
|
||||
/* Define ThreadX global data structures. */
|
||||
|
||||
#ifndef LX_STANDALONE_ENABLE
|
||||
TX_THREAD thread_0;
|
||||
#endif
|
||||
ULONG thread_0_counter;
|
||||
|
||||
|
||||
int main(void)
|
||||
{
|
||||
|
||||
/* Enter the ThreadX kernel. */
|
||||
#ifndef LX_STANDALONE_ENABLE
|
||||
tx_kernel_enter();
|
||||
#else
|
||||
|
||||
/* Initialize NOR flash. */
|
||||
lx_nor_flash_initialize();
|
||||
|
||||
/* Initialize FileX. */
|
||||
fx_system_initialize();
|
||||
|
||||
thread_0_entry(0);
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
|
||||
/* Define what the initial system looks like. */
|
||||
|
||||
#ifndef LX_STANDALONE_ENABLE
|
||||
void tx_application_define(void *first_unused_memory)
|
||||
{
|
||||
|
||||
@@ -60,16 +85,17 @@ void tx_application_define(void *first_unused_memory)
|
||||
create information. */
|
||||
|
||||
/* Create the main thread. */
|
||||
tx_thread_create(&thread_0, "thread 0", thread_0_entry, 0,
|
||||
thread_0_stack, DEMO_STACK_SIZE,
|
||||
tx_thread_create(&thread_0, "thread 0", thread_0_entry, 0,
|
||||
thread_0_stack, DEMO_STACK_SIZE,
|
||||
1, 1, TX_NO_TIME_SLICE, TX_AUTO_START);
|
||||
|
||||
/* Initialize NOR flash. */
|
||||
lx_nor_flash_initialize();
|
||||
|
||||
lx_nor_flash_initialize();
|
||||
|
||||
/* Initialize FileX. */
|
||||
fx_system_initialize();
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
@@ -81,27 +107,27 @@ ULONG actual;
|
||||
CHAR local_buffer[30];
|
||||
|
||||
LX_PARAMETER_NOT_USED(thread_input);
|
||||
|
||||
|
||||
/* Erase the simulated NOR flash. */
|
||||
_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
|
||||
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_NULL, // Unused
|
||||
media_memory, // Media buffer pointer
|
||||
sizeof(media_memory), // Media buffer size
|
||||
sizeof(media_memory), // Media buffer size
|
||||
"MY_NOR_DISK", // Volume Name
|
||||
1, // Number of FATs
|
||||
32, // Directory Entries
|
||||
0, // Hidden sectors
|
||||
120, // Total sectors
|
||||
512, // Sector size
|
||||
120, // Total sectors
|
||||
512, // Sector size
|
||||
1, // Sectors per cluster
|
||||
1, // Heads
|
||||
1); // Sectors per track
|
||||
1); // Sectors per track
|
||||
|
||||
/* Loop to repeat the demo over and over! */
|
||||
do
|
||||
@@ -203,7 +229,7 @@ CHAR local_buffer[30];
|
||||
|
||||
/* Delete the file. */
|
||||
status = fx_file_delete(&nor_disk, "TEST.TXT");
|
||||
|
||||
|
||||
/* Check the file delete status. */
|
||||
if (status != FX_SUCCESS)
|
||||
{
|
||||
@@ -211,7 +237,7 @@ CHAR local_buffer[30];
|
||||
/* Error deleting the file, break the loop. */
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
/* Close the media. */
|
||||
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
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user