├── .devcontainer └── devcontainer.json ├── CMakeLists.txt ├── CONTRIBUTING.md ├── LICENSE.txt ├── README.md ├── SECURITY.md ├── cmake ├── arm-none-eabi.cmake ├── cortex_m0.cmake ├── cortex_m3.cmake ├── cortex_m4.cmake ├── cortex_m7.cmake └── utilities.cmake ├── common ├── CMakeLists.txt ├── inc │ ├── lx_api.h │ └── lx_user_sample.h └── src │ ├── fx_nand_flash_simulated_driver.c │ ├── fx_nor_flash_simulator_driver.c │ ├── lx_nand_flash_256byte_ecc_check.c │ ├── lx_nand_flash_256byte_ecc_compute.c │ ├── lx_nand_flash_block_allocate.c │ ├── lx_nand_flash_block_data_move.c │ ├── lx_nand_flash_block_find.c │ ├── lx_nand_flash_block_mapping_set.c │ ├── lx_nand_flash_block_status_set.c │ ├── lx_nand_flash_close.c │ ├── lx_nand_flash_data_page_copy.c │ ├── lx_nand_flash_defragment.c │ ├── lx_nand_flash_driver_block_erase.c │ ├── lx_nand_flash_driver_block_erased_verify.c │ ├── lx_nand_flash_driver_block_status_get.c │ ├── lx_nand_flash_driver_block_status_set.c │ ├── lx_nand_flash_driver_page_erased_verify.c │ ├── lx_nand_flash_erase_count_set.c │ ├── lx_nand_flash_extended_cache_enable.c │ ├── lx_nand_flash_format.c │ ├── lx_nand_flash_free_block_list_add.c │ ├── lx_nand_flash_initialize.c │ ├── lx_nand_flash_mapped_block_list_add.c │ ├── lx_nand_flash_mapped_block_list_get.c │ ├── lx_nand_flash_mapped_block_list_remove.c │ ├── lx_nand_flash_memory_initialize.c │ ├── lx_nand_flash_metadata_allocate.c │ ├── lx_nand_flash_metadata_build.c │ ├── lx_nand_flash_metadata_write.c │ ├── lx_nand_flash_open.c │ ├── lx_nand_flash_page_ecc_check.c │ ├── lx_nand_flash_page_ecc_compute.c │ ├── lx_nand_flash_partial_defragment.c │ ├── lx_nand_flash_sector_read.c │ ├── lx_nand_flash_sector_release.c │ ├── lx_nand_flash_sector_write.c │ ├── lx_nand_flash_sectors_read.c │ ├── lx_nand_flash_sectors_release.c │ ├── lx_nand_flash_sectors_write.c │ ├── lx_nand_flash_simulator.c │ ├── lx_nand_flash_system_error.c │ ├── lx_nor_flash_block_reclaim.c │ ├── lx_nor_flash_close.c │ ├── lx_nor_flash_defragment.c │ ├── lx_nor_flash_driver_block_erase.c │ ├── lx_nor_flash_driver_read.c │ ├── lx_nor_flash_driver_write.c │ ├── lx_nor_flash_extended_cache_enable.c │ ├── lx_nor_flash_initialize.c │ ├── lx_nor_flash_logical_sector_find.c │ ├── lx_nor_flash_next_block_to_erase_find.c │ ├── lx_nor_flash_open.c │ ├── lx_nor_flash_partial_defragment.c │ ├── lx_nor_flash_physical_sector_allocate.c │ ├── lx_nor_flash_sector_mapping_cache_invalidate.c │ ├── lx_nor_flash_sector_read.c │ ├── lx_nor_flash_sector_release.c │ ├── lx_nor_flash_sector_write.c │ ├── lx_nor_flash_simulator.c │ └── lx_nor_flash_system_error.c ├── docs ├── deps.png └── revision_history.txt ├── samples ├── demo_filex_nand_flash.c └── demo_filex_nor_flash.c ├── scripts ├── build.sh ├── install.sh └── test.sh └── test ├── cmake ├── CMakeLists.txt ├── coverage.sh ├── libs │ └── CMakeLists.txt ├── regression │ └── CMakeLists.txt ├── run.sh └── samples │ └── CMakeLists.txt └── regression ├── levelx_nand_flash_test.c ├── levelx_nor_flash_test.c └── levelx_nor_flash_test_cache.c /.devcontainer/devcontainer.json: -------------------------------------------------------------------------------- 1 | { 2 | "image": "ghcr.io/tiejunms/azure_rtos_docker", 3 | 4 | // Add the IDs of extensions you want installed when the container is created. 5 | "extensions": [ 6 | "ms-vscode.cpptools", 7 | "ms-vscode.cmake-tools" 8 | ], 9 | 10 | "remoteUser": "vscode", 11 | 12 | "runArgs": [ "--cap-add=NET_ADMIN"] 13 | } -------------------------------------------------------------------------------- /CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.0.0 FATAL_ERROR) 2 | 3 | # Set up the project 4 | project(levelx 5 | LANGUAGES C ASM 6 | ) 7 | 8 | option(LX_STANDALONE_ENABLE "Enable LevelX in standalone mode" OFF) 9 | option(LX_ENABLE_FILE_SERVERS "Includes a dependency on FileX" ON) 10 | 11 | if(NOT DEFINED THREADX_ARCH) 12 | message(FATAL_ERROR "Error: THREADX_ARCH not defined") 13 | endif() 14 | if(NOT DEFINED THREADX_TOOLCHAIN) 15 | message(FATAL_ERROR "Error: THREADX_TOOLCHAIN not defined") 16 | endif() 17 | 18 | 19 | # Define our target library and an alias for consumers 20 | add_library(${PROJECT_NAME}) 21 | add_library("azrtos::${PROJECT_NAME}" ALIAS ${PROJECT_NAME}) 22 | 23 | # Define any required dependencies between this library and others 24 | if(NOT LX_STANDALONE_ENABLE) 25 | target_link_libraries(${PROJECT_NAME} PUBLIC 26 | "azrtos::threadx") 27 | endif() 28 | 29 | if(LX_ENABLE_FILE_SERVERS) 30 | message(STATUS "LX_ENABLE_FILE_SERVERS - defined") 31 | target_link_libraries(${PROJECT_NAME} PUBLIC "azrtos::filex") 32 | endif() 33 | 34 | # A place for generated/copied include files (no need to change) 35 | set(CUSTOM_INC_DIR ${CMAKE_CURRENT_BINARY_DIR}/custom_inc) 36 | 37 | # Pick up the common stuff 38 | add_subdirectory(${CMAKE_CURRENT_LIST_DIR}/common) 39 | 40 | # Include the user's override file if required 41 | if (NOT LX_USER_FILE) 42 | message(STATUS "Using default lx_user.h file") 43 | set(LX_USER_FILE ${CMAKE_CURRENT_LIST_DIR}/common/inc/lx_user_sample.h) 44 | else() 45 | message(STATUS "Using custom lx_user.h file from ${LX_USER_FILE}") 46 | endif() 47 | configure_file(${LX_USER_FILE} ${CUSTOM_INC_DIR}/lx_user.h COPYONLY) 48 | target_include_directories(${PROJECT_NAME} 49 | PUBLIC 50 | ${CUSTOM_INC_DIR} 51 | ) 52 | 53 | if(NOT LX_STANDALONE_ENABLE) 54 | target_compile_definitions(${PROJECT_NAME} PUBLIC "LX_INCLUDE_USER_DEFINE_FILE" ) 55 | else() 56 | # Enable LevelX and FileX standalone support (No Azure RTOS support) 57 | set(FX_STANDALONE_ENABLE ON CACHE BOOL "Standalone enable") 58 | target_compile_definitions(${PROJECT_NAME} PUBLIC "LX_INCLUDE_USER_DEFINE_FILE" -DLX_STANDALONE_ENABLE -DFX_STANDALONE_ENABLE) 59 | endif() 60 | 61 | # Enable a build target that produces a ZIP file of all sources 62 | set(CPACK_SOURCE_GENERATOR "ZIP") 63 | set(CPACK_SOURCE_IGNORE_FILES 64 | \\.git/ 65 | \\.github/ 66 | _build/ 67 | \\.git 68 | \\.gitattributes 69 | \\.gitignore 70 | ".*~$" 71 | ) 72 | set(CPACK_VERBATIM_VARIABLES YES) 73 | include(CPack) 74 | 75 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributing to Eclipse ThreadX 2 | 3 | Thanks for your interest in this project. 4 | 5 | ## Project description 6 | 7 | Eclipse ThreadX provides a vendor-neutral, open source, safety certified OS for 8 | real-time applications published on under a permissive license. The Eclipse 9 | ThreadX suite encompasses: 10 | * ThreadX - advanced real-time operating system (RTOS) designed specifically for deeply embedded applications 11 | * NetX Duo - advanced, industrial-grade TCP/IP network stack designed specifically for deeply embedded real-time and IoT applications 12 | * FileX - high-performance, FAT-compatible file system that’s fully integrated with ThreadX kernel 13 | * GUIX - provides a complete, embedded graphical user interface (GUI) library 14 | * USBX - high-performance USB host, device, and on-the-go (OTG) embedded stack, that is fully integrated with ThreadX kernel 15 | * LevelX - Flash Wear Leveling for FileX and stand-alone purposes 16 | * GuiX Studio - design environment, facilitating the creation and maintenance of all graphical elements for GUIX 17 | * TraceX - analysis tool that provides a graphical view of real-time system events to better understand the behavior of real-time systems 18 | 19 | Project site: https://projects.eclipse.org/projects/iot.threadx 20 | 21 | ## Terms of Use 22 | 23 | This repository is subject to the Terms of Use of the Eclipse Foundation 24 | https://www.eclipse.org/legal/termsofuse.php 25 | 26 | ## Developer resources 27 | 28 | Information regarding source code management, builds, coding standards, and more. 29 | https://projects.eclipse.org/projects/iot.threadx/developer 30 | 31 | The project maintains the following source code repositories 32 | 33 | * https://github.com/eclipse-threadx/.github 34 | * https://github.com/eclipse-threadx/cmsis-packs 35 | * https://github.com/eclipse-threadx/filex 36 | * https://github.com/eclipse-threadx/getting-started 37 | * https://github.com/eclipse-threadx/guix 38 | * https://github.com/eclipse-threadx/levelx 39 | * https://github.com/eclipse-threadx/netxduo 40 | * https://github.com/eclipse-threadx/rtos-docs 41 | * https://github.com/eclipse-threadx/samples 42 | * https://github.com/eclipse-threadx/threadx 43 | * https://github.com/eclipse-threadx/threadx-learn-samples 44 | * https://github.com/eclipse-threadx/tracex 45 | * https://github.com/eclipse-threadx/usbx 46 | 47 | ## Eclipse Development Process 48 | 49 | This Eclipse Foundation open project is governed by the Eclipse Foundation 50 | Development Process and operates under the terms of the Eclipse IP Policy. 51 | 52 | * https://eclipse.org/projects/dev_process 53 | * https://www.eclipse.org/org/documents/Eclipse_IP_Policy.pdf 54 | 55 | ## Eclipse Contributor Agreement 56 | 57 | In order to be able to contribute to Eclipse Foundation projects you must electronically sign the Eclipse Contributor Agreement (ECA). 58 | https://www.eclipse.org/legal/ECA.php 59 | 60 | The ECA provides the Eclipse Foundation with a permanent record that you agree 61 | that each of your contributions will comply with the commitments documented in 62 | the Developer Certificate of Origin (DCO). Having an ECA on file associated with 63 | the email address matching the "Author" field of your contribution's Git commits 64 | fulfills the DCO's requirement that you sign-off on your contributions. 65 | 66 | For more information, please see the Eclipse Committer Handbook: 67 | https://www.eclipse.org/projects/handbook/#resources-commit 68 | 69 | ## Contact 70 | 71 | Contact the project developers via the project's "dev" list. 72 | https://accounts.eclipse.org/mailing-list/threadx-dev 73 | -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2024 - present Microsoft Corporation 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /SECURITY.md: -------------------------------------------------------------------------------- 1 | # Security Policy 2 | 3 | ## Supported Versions 4 | 5 | | Version | Supported | 6 | | ------- | ------------------ | 7 | | 6.4.x | :white_check_mark: | 8 | 9 | ## Reporting a Vulnerability 10 | 11 | If you think you have found a vulnerability in you can report it using one of the following ways: 12 | 13 | * Contact the [Eclipse Foundation Security Team](mailto:security@eclipse-foundation.org) 14 | * [Report a Vulnerability](https://github.com/eclipse-threadx/levelx/security/advisories/new) 15 | 16 | You can find more information about reporting and disclosure at the [Eclipse Foundation Security page](https://www.eclipse.org/security/). 17 | 18 | ## Security Policy 19 | 20 | This project follows [Eclipse Foundation Vulnerability Reporting Policy](https://www.eclipse.org/security/policy/). 21 | -------------------------------------------------------------------------------- /cmake/arm-none-eabi.cmake: -------------------------------------------------------------------------------- 1 | # Toolchain settings 2 | set(CMAKE_C_COMPILER arm-none-eabi-gcc) 3 | set(CMAKE_CXX_COMPILER arm-none-eabi-g++) 4 | set(AS arm-none-eabi-as) 5 | set(AR arm-none-eabi-ar) 6 | set(OBJCOPY arm-none-eabi-objcopy) 7 | set(OBJDUMP arm-none-eabi-objdump) 8 | set(SIZE arm-none-eabi-size) 9 | 10 | set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) 11 | set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) 12 | set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) 13 | set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY) 14 | 15 | # this makes the test compiles use static library option so that we don't need to pre-set linker flags and scripts 16 | set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY) 17 | 18 | set(CMAKE_C_FLAGS "${MCPU_FLAGS} ${VFP_FLAGS} ${SPEC_FLAGS} -fdata-sections -ffunction-sections -mlong-calls" CACHE INTERNAL "c compiler flags") 19 | set(CMAKE_CXX_FLAGS "${MCPU_FLAGS} ${VFP_FLAGS} -fdata-sections -ffunction-sections -fno-rtti -fno-exceptions -mlong-calls" CACHE INTERNAL "cxx compiler flags") 20 | set(CMAKE_ASM_FLAGS "${MCPU_FLAGS} -x assembler-with-cpp" CACHE INTERNAL "asm compiler flags") 21 | set(CMAKE_EXE_LINKER_FLAGS "${MCPU_FLAGS} ${LD_FLAGS} -Wl,--gc-sections" CACHE INTERNAL "exe link flags") 22 | 23 | SET(CMAKE_C_FLAGS_DEBUG "-Og -g -ggdb3" CACHE INTERNAL "c debug compiler flags") 24 | SET(CMAKE_CXX_FLAGS_DEBUG "-Og -g -ggdb3" CACHE INTERNAL "cxx debug compiler flags") 25 | SET(CMAKE_ASM_FLAGS_DEBUG "-g -ggdb3" CACHE INTERNAL "asm debug compiler flags") 26 | 27 | SET(CMAKE_C_FLAGS_RELEASE "-O3" CACHE INTERNAL "c release compiler flags") 28 | SET(CMAKE_CXX_FLAGS_RELEASE "-O3" CACHE INTERNAL "cxx release compiler flags") 29 | SET(CMAKE_ASM_FLAGS_RELEASE "" CACHE INTERNAL "asm release compiler flags") -------------------------------------------------------------------------------- /cmake/cortex_m0.cmake: -------------------------------------------------------------------------------- 1 | # Name of the target 2 | set(CMAKE_SYSTEM_NAME Generic) 3 | set(CMAKE_SYSTEM_PROCESSOR cortex-m0) 4 | 5 | set(THREADX_ARCH "cortex_m0") 6 | set(THREADX_TOOLCHAIN "gnu") 7 | 8 | set(MCPU_FLAGS "-mthumb -mcpu=cortex-m0") 9 | set(VFP_FLAGS "") 10 | set(SPEC_FLAGS "--specs=nosys.specs") 11 | # set(LD_FLAGS "-nostartfiles") 12 | 13 | include(${CMAKE_CURRENT_LIST_DIR}/arm-none-eabi.cmake) -------------------------------------------------------------------------------- /cmake/cortex_m3.cmake: -------------------------------------------------------------------------------- 1 | # Name of the target 2 | set(CMAKE_SYSTEM_NAME Generic) 3 | set(CMAKE_SYSTEM_PROCESSOR cortex-m0) 4 | 5 | set(THREADX_ARCH "cortex_m3") 6 | set(THREADX_TOOLCHAIN "gnu") 7 | 8 | set(MCPU_FLAGS "-mthumb -mcpu=cortex-m3") 9 | set(VFP_FLAGS "") 10 | set(SPEC_FLAGS "--specs=nosys.specs") 11 | # set(LD_FLAGS "-nostartfiles") 12 | 13 | include(${CMAKE_CURRENT_LIST_DIR}/arm-none-eabi.cmake) -------------------------------------------------------------------------------- /cmake/cortex_m4.cmake: -------------------------------------------------------------------------------- 1 | # Name of the target 2 | set(CMAKE_SYSTEM_NAME Generic) 3 | set(CMAKE_SYSTEM_PROCESSOR cortex-m4) 4 | 5 | set(THREADX_ARCH "cortex_m4") 6 | set(THREADX_TOOLCHAIN "gnu") 7 | 8 | set(MCPU_FLAGS "-mthumb -mcpu=cortex-m4") 9 | set(VFP_FLAGS "") 10 | set(SPEC_FLAGS "--specs=nosys.specs") 11 | # set(LD_FLAGS "-nostartfiles") 12 | 13 | include(${CMAKE_CURRENT_LIST_DIR}/arm-none-eabi.cmake) -------------------------------------------------------------------------------- /cmake/cortex_m7.cmake: -------------------------------------------------------------------------------- 1 | # Name of the target 2 | set(CMAKE_SYSTEM_NAME Generic) 3 | set(CMAKE_SYSTEM_PROCESSOR cortex-m7) 4 | 5 | set(THREADX_ARCH "cortex_m7") 6 | set(THREADX_TOOLCHAIN "gnu") 7 | 8 | set(MCPU_FLAGS "-mthumb -mcpu=cortex-m7") 9 | set(VFP_FLAGS "") 10 | set(SPEC_FLAGS "--specs=nosys.specs") 11 | # set(LD_FLAGS "-nostartfiles") 12 | 13 | include(${CMAKE_CURRENT_LIST_DIR}/arm-none-eabi.cmake) -------------------------------------------------------------------------------- /cmake/utilities.cmake: -------------------------------------------------------------------------------- 1 | # Add the required subdirectory and register it for linkage 2 | function(add_azrtos_component_dir dirname) 3 | # Store the current list in a temp 4 | set(tmp ${azrtos_targets}) 5 | # Add the subdir 6 | add_subdirectory(${CMAKE_CURRENT_LIST_DIR}/lib/${dirname}) 7 | # If there is a linker script defined, use it 8 | if(EXISTS ${LINKER_SCRIPT}) 9 | target_link_options(${dirname} INTERFACE -T ${LINKER_SCRIPT}) 10 | endif() 11 | # Add this target into the temp 12 | list(APPEND tmp "azrtos::${dirname}") 13 | # Copy the temp back up to the parent list 14 | set(azrtos_targets ${tmp} PARENT_SCOPE) 15 | endfunction() -------------------------------------------------------------------------------- /common/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | target_sources(${PROJECT_NAME} PRIVATE 2 | # {{BEGIN_TARGET_SOURCES}} 3 | ${CMAKE_CURRENT_LIST_DIR}/src/fx_nand_flash_simulated_driver.c 4 | ${CMAKE_CURRENT_LIST_DIR}/src/fx_nor_flash_simulator_driver.c 5 | ${CMAKE_CURRENT_LIST_DIR}/src/lx_nand_flash_256byte_ecc_check.c 6 | ${CMAKE_CURRENT_LIST_DIR}/src/lx_nand_flash_256byte_ecc_compute.c 7 | ${CMAKE_CURRENT_LIST_DIR}/src/lx_nand_flash_block_allocate.c 8 | ${CMAKE_CURRENT_LIST_DIR}/src/lx_nand_flash_block_data_move.c 9 | ${CMAKE_CURRENT_LIST_DIR}/src/lx_nand_flash_block_find.c 10 | ${CMAKE_CURRENT_LIST_DIR}/src/lx_nand_flash_block_mapping_set.c 11 | ${CMAKE_CURRENT_LIST_DIR}/src/lx_nand_flash_block_status_set.c 12 | ${CMAKE_CURRENT_LIST_DIR}/src/lx_nand_flash_close.c 13 | ${CMAKE_CURRENT_LIST_DIR}/src/lx_nand_flash_data_page_copy.c 14 | ${CMAKE_CURRENT_LIST_DIR}/src/lx_nand_flash_defragment.c 15 | ${CMAKE_CURRENT_LIST_DIR}/src/lx_nand_flash_driver_block_erase.c 16 | ${CMAKE_CURRENT_LIST_DIR}/src/lx_nand_flash_driver_block_erased_verify.c 17 | ${CMAKE_CURRENT_LIST_DIR}/src/lx_nand_flash_driver_block_status_get.c 18 | ${CMAKE_CURRENT_LIST_DIR}/src/lx_nand_flash_driver_block_status_set.c 19 | ${CMAKE_CURRENT_LIST_DIR}/src/lx_nand_flash_driver_page_erased_verify.c 20 | ${CMAKE_CURRENT_LIST_DIR}/src/lx_nand_flash_erase_count_set.c 21 | ${CMAKE_CURRENT_LIST_DIR}/src/lx_nand_flash_extended_cache_enable.c 22 | ${CMAKE_CURRENT_LIST_DIR}/src/lx_nand_flash_format.c 23 | ${CMAKE_CURRENT_LIST_DIR}/src/lx_nand_flash_free_block_list_add.c 24 | ${CMAKE_CURRENT_LIST_DIR}/src/lx_nand_flash_initialize.c 25 | ${CMAKE_CURRENT_LIST_DIR}/src/lx_nand_flash_mapped_block_list_add.c 26 | ${CMAKE_CURRENT_LIST_DIR}/src/lx_nand_flash_mapped_block_list_get.c 27 | ${CMAKE_CURRENT_LIST_DIR}/src/lx_nand_flash_mapped_block_list_remove.c 28 | ${CMAKE_CURRENT_LIST_DIR}/src/lx_nand_flash_memory_initialize.c 29 | ${CMAKE_CURRENT_LIST_DIR}/src/lx_nand_flash_metadata_allocate.c 30 | ${CMAKE_CURRENT_LIST_DIR}/src/lx_nand_flash_metadata_build.c 31 | ${CMAKE_CURRENT_LIST_DIR}/src/lx_nand_flash_metadata_write.c 32 | ${CMAKE_CURRENT_LIST_DIR}/src/lx_nand_flash_open.c 33 | ${CMAKE_CURRENT_LIST_DIR}/src/lx_nand_flash_page_ecc_check.c 34 | ${CMAKE_CURRENT_LIST_DIR}/src/lx_nand_flash_page_ecc_compute.c 35 | ${CMAKE_CURRENT_LIST_DIR}/src/lx_nand_flash_partial_defragment.c 36 | ${CMAKE_CURRENT_LIST_DIR}/src/lx_nand_flash_sectors_read.c 37 | ${CMAKE_CURRENT_LIST_DIR}/src/lx_nand_flash_sectors_release.c 38 | ${CMAKE_CURRENT_LIST_DIR}/src/lx_nand_flash_sectors_write.c 39 | ${CMAKE_CURRENT_LIST_DIR}/src/lx_nand_flash_sector_read.c 40 | ${CMAKE_CURRENT_LIST_DIR}/src/lx_nand_flash_sector_release.c 41 | ${CMAKE_CURRENT_LIST_DIR}/src/lx_nand_flash_sector_write.c 42 | ${CMAKE_CURRENT_LIST_DIR}/src/lx_nand_flash_simulator.c 43 | ${CMAKE_CURRENT_LIST_DIR}/src/lx_nand_flash_system_error.c 44 | ${CMAKE_CURRENT_LIST_DIR}/src/lx_nor_flash_block_reclaim.c 45 | ${CMAKE_CURRENT_LIST_DIR}/src/lx_nor_flash_close.c 46 | ${CMAKE_CURRENT_LIST_DIR}/src/lx_nor_flash_defragment.c 47 | ${CMAKE_CURRENT_LIST_DIR}/src/lx_nor_flash_driver_block_erase.c 48 | ${CMAKE_CURRENT_LIST_DIR}/src/lx_nor_flash_driver_read.c 49 | ${CMAKE_CURRENT_LIST_DIR}/src/lx_nor_flash_driver_write.c 50 | ${CMAKE_CURRENT_LIST_DIR}/src/lx_nor_flash_extended_cache_enable.c 51 | ${CMAKE_CURRENT_LIST_DIR}/src/lx_nor_flash_initialize.c 52 | ${CMAKE_CURRENT_LIST_DIR}/src/lx_nor_flash_logical_sector_find.c 53 | ${CMAKE_CURRENT_LIST_DIR}/src/lx_nor_flash_next_block_to_erase_find.c 54 | ${CMAKE_CURRENT_LIST_DIR}/src/lx_nor_flash_open.c 55 | ${CMAKE_CURRENT_LIST_DIR}/src/lx_nor_flash_partial_defragment.c 56 | ${CMAKE_CURRENT_LIST_DIR}/src/lx_nor_flash_physical_sector_allocate.c 57 | ${CMAKE_CURRENT_LIST_DIR}/src/lx_nor_flash_sector_mapping_cache_invalidate.c 58 | ${CMAKE_CURRENT_LIST_DIR}/src/lx_nor_flash_sector_read.c 59 | ${CMAKE_CURRENT_LIST_DIR}/src/lx_nor_flash_sector_release.c 60 | ${CMAKE_CURRENT_LIST_DIR}/src/lx_nor_flash_sector_write.c 61 | ${CMAKE_CURRENT_LIST_DIR}/src/lx_nor_flash_simulator.c 62 | ${CMAKE_CURRENT_LIST_DIR}/src/lx_nor_flash_system_error.c 63 | 64 | # {{END_TARGET_SOURCES}} 65 | ) 66 | 67 | # Add the Common/inc directory to the project include list 68 | target_include_directories(${PROJECT_NAME} PUBLIC 69 | ${CMAKE_CURRENT_LIST_DIR}/inc 70 | ) 71 | 72 | -------------------------------------------------------------------------------- /common/inc/lx_user_sample.h: -------------------------------------------------------------------------------- 1 | /*************************************************************************** 2 | * Copyright (c) 2024 Microsoft Corporation 3 | * 4 | * This program and the accompanying materials are made available under the 5 | * terms of the MIT License which is available at 6 | * https://opensource.org/licenses/MIT. 7 | * 8 | * SPDX-License-Identifier: MIT 9 | **************************************************************************/ 10 | 11 | 12 | /**************************************************************************/ 13 | /**************************************************************************/ 14 | /** */ 15 | /** LevelX Component */ 16 | /** */ 17 | /** User Specific */ 18 | /** */ 19 | /**************************************************************************/ 20 | /**************************************************************************/ 21 | 22 | 23 | /**************************************************************************/ 24 | /* */ 25 | /* PORT SPECIFIC C INFORMATION RELEASE */ 26 | /* */ 27 | /* lx_user.h PORTABLE C */ 28 | /* 6.3.0 */ 29 | /* */ 30 | /* AUTHOR */ 31 | /* */ 32 | /* William E. Lamie, Microsoft Corporation */ 33 | /* */ 34 | /* DESCRIPTION */ 35 | /* */ 36 | /* This file contains user defines for configuring LevelX in specific */ 37 | /* ways. This file will have an effect only if the application and */ 38 | /* LevelX library are built with LX_INCLUDE_USER_DEFINE_FILE defined. */ 39 | /* Note that all the defines in this file may also be made on the */ 40 | /* command line when building LevelX library and application objects. */ 41 | /* */ 42 | /* RELEASE HISTORY */ 43 | /* */ 44 | /* DATE NAME DESCRIPTION */ 45 | /* */ 46 | /* 11-09-2020 William E. Lamie Initial Version 6.1.2 */ 47 | /* 06-02-2021 Bhupendra Naphade Modified comment(s), and */ 48 | /* added standalone support, */ 49 | /* resulting in version 6.1.7 */ 50 | /* 03-08-2023 Xiuwen Cai Modified comment(s), and */ 51 | /* added new NAND options, */ 52 | /* resulting in version 6.2.1 */ 53 | /* 10-31-2023 Xiuwen Cai Modified comment(s), */ 54 | /* added options for mapping , */ 55 | /* bitmap cache and obsolete */ 56 | /* count cache, */ 57 | /* resulting in version 6.3.0 */ 58 | /* */ 59 | /**************************************************************************/ 60 | 61 | #ifndef LX_USER_H 62 | #define LX_USER_H 63 | 64 | 65 | 66 | /* Defined, this option bypasses the NOR flash driver read routine in favor or reading 67 | the NOR memory directly, resulting in a significant performance increase. 68 | */ 69 | /* 70 | #define LX_DIRECT_READ 71 | */ 72 | 73 | 74 | /* Defined, this causes the LevelX NOR instance open logic to verify free NOR 75 | sectors are all ones. 76 | */ 77 | /* 78 | #define LX_FREE_SECTOR_DATA_VERIFY 79 | */ 80 | 81 | /* By default this value is 4, which represents a maximum of 4 blocks that 82 | can be allocated for metadata. 83 | */ 84 | /* 85 | #define LX_NAND_FLASH_MAX_METADATA_BLOCKS 4 86 | */ 87 | 88 | /* Defined, this disabled the extended NOR cache. */ 89 | /* 90 | #define LX_NOR_DISABLE_EXTENDED_CACHE 91 | */ 92 | 93 | /* By default this value is 8, which represents a maximum of 8 sectors that 94 | can be cached in a NOR instance. 95 | */ 96 | /* 97 | #define LX_NOR_EXTENDED_CACHE_SIZE 8 98 | */ 99 | 100 | 101 | /* By default this value is 16 and defines the logical sector mapping cache size. 102 | Large values improve performance, but cost memory. The minimum size is 8 and all 103 | values must be a power of 2. 104 | */ 105 | /* 106 | #define LX_NOR_SECTOR_MAPPING_CACHE_SIZE 16 107 | */ 108 | 109 | /* Defined, this makes LevelX thread-safe by using a ThreadX mutex object 110 | throughout the API. 111 | */ 112 | /* 113 | #define LX_THREAD_SAFE_ENABLE 114 | */ 115 | 116 | /* Defined, LevelX will be used in standalone mode (without Azure RTOS ThreadX) */ 117 | 118 | /* #define LX_STANDALONE_ENABLE */ 119 | 120 | /* 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. */ 121 | /* 122 | #define LX_NOR_FLASH_USER_EXTENSION ???? 123 | */ 124 | 125 | /* 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. */ 126 | /* 127 | #define LX_NAND_FLASH_USER_EXTENSION ???? 128 | */ 129 | 130 | /* Determine if logical sector mapping bitmap should be enabled in extended cache. 131 | Cache memory will be allocated to sector mapping bitmap first. One bit can be allocated for each physical sector. */ 132 | /* 133 | #define LX_NOR_ENABLE_MAPPING_BITMAP 134 | */ 135 | 136 | /* Determine if obsolete count cache should be enabled in extended cache. 137 | Cache memory will be allocated to obsolete count cache after the mapping bitmap if enabled, 138 | and the rest of the cache memory is allocated to sector cache. */ 139 | /* 140 | #define LX_NOR_ENABLE_OBSOLETE_COUNT_CACHE 141 | */ 142 | 143 | /* Defines obsolete count cache element size. If number of sectors per block is greater than 256, use USHORT instead of UCHAR. */ 144 | /* 145 | #define LX_NOR_OBSOLETE_COUNT_CACHE_TYPE UCHAR 146 | */ 147 | 148 | /* Define the logical sector size for NOR flash. The sector size is in units of 32-bit words. 149 | This sector size should match the sector size used in file system. */ 150 | /* 151 | #define LX_NOR_SECTOR_SIZE (512/sizeof(ULONG)) 152 | */ 153 | 154 | #endif 155 | 156 | -------------------------------------------------------------------------------- /common/src/lx_nand_flash_block_allocate.c: -------------------------------------------------------------------------------- 1 | /*************************************************************************** 2 | * Copyright (c) 2024 Microsoft Corporation 3 | * 4 | * This program and the accompanying materials are made available under the 5 | * terms of the MIT License which is available at 6 | * https://opensource.org/licenses/MIT. 7 | * 8 | * SPDX-License-Identifier: MIT 9 | **************************************************************************/ 10 | 11 | 12 | /**************************************************************************/ 13 | /**************************************************************************/ 14 | /** */ 15 | /** LevelX Component */ 16 | /** */ 17 | /** NAND Flash */ 18 | /** */ 19 | /**************************************************************************/ 20 | /**************************************************************************/ 21 | 22 | #define LX_SOURCE_CODE 23 | 24 | 25 | /* Disable ThreadX error checking. */ 26 | 27 | #ifndef LX_DISABLE_ERROR_CHECKING 28 | #define LX_DISABLE_ERROR_CHECKING 29 | #endif 30 | 31 | 32 | /* Include necessary system files. */ 33 | 34 | #include "lx_api.h" 35 | 36 | 37 | /**************************************************************************/ 38 | /* */ 39 | /* FUNCTION RELEASE */ 40 | /* */ 41 | /* _lx_nand_flash_block_allocate PORTABLE C */ 42 | /* 6.2.1 */ 43 | /* AUTHOR */ 44 | /* */ 45 | /* Xiuwen Cai, Microsoft Corporation */ 46 | /* */ 47 | /* DESCRIPTION */ 48 | /* */ 49 | /* This function attempts to get a block in the free block list. */ 50 | /* */ 51 | /* INPUT */ 52 | /* */ 53 | /* nand_flash NAND flash instance */ 54 | /* block Return block number */ 55 | /* */ 56 | /* OUTPUT */ 57 | /* */ 58 | /* return status */ 59 | /* */ 60 | /* CALLS */ 61 | /* */ 62 | /* None */ 63 | /* */ 64 | /* CALLED BY */ 65 | /* */ 66 | /* Internal LevelX */ 67 | /* */ 68 | /* RELEASE HISTORY */ 69 | /* */ 70 | /* DATE NAME DESCRIPTION */ 71 | /* */ 72 | /* 03-08-2023 Xiuwen Cai Initial Version 6.2.1 */ 73 | /* */ 74 | /**************************************************************************/ 75 | UINT _lx_nand_flash_block_allocate(LX_NAND_FLASH* nand_flash, ULONG* block) 76 | { 77 | 78 | 79 | /* Check if the free block list is empty. */ 80 | if (nand_flash -> lx_nand_flash_free_block_list_tail == 0) 81 | { 82 | 83 | /* Empty list, return error. */ 84 | return(LX_NO_BLOCKS); 85 | } 86 | 87 | /* Remove one block from the list. */ 88 | nand_flash -> lx_nand_flash_free_block_list_tail--; 89 | 90 | /* Return the block number. */ 91 | *block = nand_flash -> lx_nand_flash_block_list[nand_flash -> lx_nand_flash_free_block_list_tail]; 92 | 93 | /* Return successful completion. */ 94 | return(LX_SUCCESS); 95 | } 96 | 97 | -------------------------------------------------------------------------------- /common/src/lx_nand_flash_block_find.c: -------------------------------------------------------------------------------- 1 | /*************************************************************************** 2 | * Copyright (c) 2024 Microsoft Corporation 3 | * 4 | * This program and the accompanying materials are made available under the 5 | * terms of the MIT License which is available at 6 | * https://opensource.org/licenses/MIT. 7 | * 8 | * SPDX-License-Identifier: MIT 9 | **************************************************************************/ 10 | 11 | 12 | /**************************************************************************/ 13 | /**************************************************************************/ 14 | /** */ 15 | /** LevelX Component */ 16 | /** */ 17 | /** NAND Flash */ 18 | /** */ 19 | /**************************************************************************/ 20 | /**************************************************************************/ 21 | 22 | #define LX_SOURCE_CODE 23 | 24 | 25 | /* Disable ThreadX error checking. */ 26 | 27 | #ifndef LX_DISABLE_ERROR_CHECKING 28 | #define LX_DISABLE_ERROR_CHECKING 29 | #endif 30 | 31 | 32 | /* Include necessary system files. */ 33 | 34 | #include "lx_api.h" 35 | 36 | 37 | /**************************************************************************/ 38 | /* */ 39 | /* FUNCTION RELEASE */ 40 | /* */ 41 | /* _lx_nand_flash_block_find PORTABLE C */ 42 | /* 6.2.1 */ 43 | /* AUTHOR */ 44 | /* */ 45 | /* Xiuwen Cai, Microsoft Corporation */ 46 | /* */ 47 | /* DESCRIPTION */ 48 | /* */ 49 | /* This function attempts to find the mapped block for the logical */ 50 | /* sector in the mapping table. */ 51 | /* */ 52 | /* INPUT */ 53 | /* */ 54 | /* nand_flash NAND flash instance */ 55 | /* logical_sector Logical sector number */ 56 | /* superceded_check Check for page being */ 57 | /* superceded (can happen if */ 58 | /* on interruptions of page */ 59 | /* write) */ 60 | /* block Destination for block */ 61 | /* page Destination for page */ 62 | /* */ 63 | /* OUTPUT */ 64 | /* */ 65 | /* return status */ 66 | /* */ 67 | /* CALLS */ 68 | /* */ 69 | /* None */ 70 | /* */ 71 | /* CALLED BY */ 72 | /* */ 73 | /* Internal LevelX */ 74 | /* */ 75 | /* RELEASE HISTORY */ 76 | /* */ 77 | /* DATE NAME DESCRIPTION */ 78 | /* */ 79 | /* 03-08-2023 Xiuwen Cai Initial Version 6.2.1 */ 80 | /* */ 81 | /**************************************************************************/ 82 | UINT _lx_nand_flash_block_find(LX_NAND_FLASH *nand_flash, ULONG logical_sector, ULONG *block, USHORT *block_status) 83 | { 84 | 85 | UINT block_mapping_index; 86 | USHORT block_number; 87 | 88 | 89 | /* Get the mapping index from logic sector address. */ 90 | block_mapping_index = logical_sector / nand_flash -> lx_nand_flash_pages_per_block; 91 | 92 | /* Check the address range. */ 93 | if (block_mapping_index > nand_flash -> lx_nand_flash_block_mapping_table_size / sizeof(*nand_flash -> lx_nand_flash_block_mapping_table)) 94 | { 95 | 96 | /* Out of range, return an error. */ 97 | return(LX_ERROR); 98 | } 99 | 100 | /* Get the block number from mapping table. */ 101 | block_number = nand_flash -> lx_nand_flash_block_mapping_table[block_mapping_index]; 102 | 103 | /* Check if it is mapped. */ 104 | if (block_number != LX_NAND_BLOCK_UNMAPPED) 105 | { 106 | 107 | /* Return the block status. */ 108 | *block_status = nand_flash -> lx_nand_flash_block_status_table[block_number]; 109 | } 110 | 111 | /* Return the block number. */ 112 | *block = (ULONG)block_number; 113 | 114 | /* Return successful completion. */ 115 | return(LX_SUCCESS); 116 | } 117 | 118 | -------------------------------------------------------------------------------- /common/src/lx_nand_flash_block_mapping_set.c: -------------------------------------------------------------------------------- 1 | /*************************************************************************** 2 | * Copyright (c) 2024 Microsoft Corporation 3 | * 4 | * This program and the accompanying materials are made available under the 5 | * terms of the MIT License which is available at 6 | * https://opensource.org/licenses/MIT. 7 | * 8 | * SPDX-License-Identifier: MIT 9 | **************************************************************************/ 10 | 11 | 12 | /**************************************************************************/ 13 | /**************************************************************************/ 14 | /** */ 15 | /** LevelX Component */ 16 | /** */ 17 | /** NAND Flash */ 18 | /** */ 19 | /**************************************************************************/ 20 | /**************************************************************************/ 21 | 22 | #define LX_SOURCE_CODE 23 | 24 | 25 | /* Disable ThreadX error checking. */ 26 | 27 | #ifndef LX_DISABLE_ERROR_CHECKING 28 | #define LX_DISABLE_ERROR_CHECKING 29 | #endif 30 | 31 | 32 | /* Include necessary system files. */ 33 | 34 | #include "lx_api.h" 35 | 36 | 37 | /**************************************************************************/ 38 | /* */ 39 | /* FUNCTION RELEASE */ 40 | /* */ 41 | /* _lx_nand_flash_block_mapping_set PORTABLE C */ 42 | /* 6.2.1 */ 43 | /* AUTHOR */ 44 | /* */ 45 | /* Xiuwen Cai, Microsoft Corporation */ 46 | /* */ 47 | /* DESCRIPTION */ 48 | /* */ 49 | /* This function sets block mappings. */ 50 | /* */ 51 | /* INPUT */ 52 | /* */ 53 | /* nand_flash NAND flash instance */ 54 | /* logical_sector Logical sector number */ 55 | /* block Block number */ 56 | /* */ 57 | /* OUTPUT */ 58 | /* */ 59 | /* return status */ 60 | /* */ 61 | /* CALLS */ 62 | /* */ 63 | /* _lx_nand_flash_metadata_write Write metadata */ 64 | /* */ 65 | /* CALLED BY */ 66 | /* */ 67 | /* Internal LevelX */ 68 | /* */ 69 | /* RELEASE HISTORY */ 70 | /* */ 71 | /* DATE NAME DESCRIPTION */ 72 | /* */ 73 | /* 03-08-2023 Xiuwen Cai Initial Version 6.2.1 */ 74 | /* */ 75 | /**************************************************************************/ 76 | UINT _lx_nand_flash_block_mapping_set(LX_NAND_FLASH *nand_flash, ULONG logical_sector, ULONG block) 77 | { 78 | 79 | UINT block_mapping_index; 80 | UCHAR page_number; 81 | UINT status; 82 | 83 | 84 | /* Get the mapping index from logic sector address. */ 85 | block_mapping_index = logical_sector / nand_flash -> lx_nand_flash_pages_per_block; 86 | 87 | /* Check the address range. */ 88 | if (block_mapping_index > nand_flash -> lx_nand_flash_block_mapping_table_size / sizeof(*nand_flash -> lx_nand_flash_block_mapping_table)) 89 | { 90 | 91 | /* Out of range, return an error. */ 92 | return(LX_ERROR); 93 | } 94 | 95 | /* Save the block number to mapping table. */ 96 | nand_flash -> lx_nand_flash_block_mapping_table[block_mapping_index] = (USHORT)block; 97 | 98 | /* Get the page number to write. */ 99 | page_number = (UCHAR)(block_mapping_index * sizeof(*nand_flash -> lx_nand_flash_block_mapping_table) / nand_flash -> lx_nand_flash_bytes_per_page); 100 | 101 | /* Save the mapping table. */ 102 | status = _lx_nand_flash_metadata_write(nand_flash, ((UCHAR*)nand_flash -> lx_nand_flash_block_mapping_table) + 103 | page_number * nand_flash -> lx_nand_flash_bytes_per_page, 104 | LX_NAND_PAGE_TYPE_BLOCK_MAPPING_TABLE | page_number); 105 | 106 | /* Return status. */ 107 | return(status); 108 | } 109 | 110 | -------------------------------------------------------------------------------- /common/src/lx_nand_flash_block_status_set.c: -------------------------------------------------------------------------------- 1 | /*************************************************************************** 2 | * Copyright (c) 2024 Microsoft Corporation 3 | * 4 | * This program and the accompanying materials are made available under the 5 | * terms of the MIT License which is available at 6 | * https://opensource.org/licenses/MIT. 7 | * 8 | * SPDX-License-Identifier: MIT 9 | **************************************************************************/ 10 | 11 | 12 | /**************************************************************************/ 13 | /**************************************************************************/ 14 | /** */ 15 | /** LevelX Component */ 16 | /** */ 17 | /** NAND Flash */ 18 | /** */ 19 | /**************************************************************************/ 20 | /**************************************************************************/ 21 | 22 | #define LX_SOURCE_CODE 23 | 24 | 25 | /* Disable ThreadX error checking. */ 26 | 27 | #ifndef LX_DISABLE_ERROR_CHECKING 28 | #define LX_DISABLE_ERROR_CHECKING 29 | #endif 30 | 31 | 32 | /* Include necessary system files. */ 33 | 34 | #include "lx_api.h" 35 | 36 | 37 | /**************************************************************************/ 38 | /* */ 39 | /* FUNCTION RELEASE */ 40 | /* */ 41 | /* _lx_nand_flash_block_status_set PORTABLE C */ 42 | /* 6.2.1 */ 43 | /* AUTHOR */ 44 | /* */ 45 | /* Xiuwen Cai, Microsoft Corporation */ 46 | /* */ 47 | /* DESCRIPTION */ 48 | /* */ 49 | /* This function sets block status. */ 50 | /* */ 51 | /* INPUT */ 52 | /* */ 53 | /* nand_flash NAND flash instance */ 54 | /* block Block number */ 55 | /* block_status Block status */ 56 | /* */ 57 | /* OUTPUT */ 58 | /* */ 59 | /* return status */ 60 | /* */ 61 | /* CALLS */ 62 | /* */ 63 | /* _lx_nand_flash_metadata_write Write metadata */ 64 | /* */ 65 | /* CALLED BY */ 66 | /* */ 67 | /* Internal LevelX */ 68 | /* */ 69 | /* RELEASE HISTORY */ 70 | /* */ 71 | /* DATE NAME DESCRIPTION */ 72 | /* */ 73 | /* 03-08-2023 Xiuwen Cai Initial Version 6.2.1 */ 74 | /* */ 75 | /**************************************************************************/ 76 | UINT _lx_nand_flash_block_status_set(LX_NAND_FLASH *nand_flash, ULONG block, ULONG block_status) 77 | { 78 | 79 | UCHAR page_number; 80 | UINT status; 81 | 82 | 83 | /* Save the block status to status table. */ 84 | nand_flash -> lx_nand_flash_block_status_table[block] = (USHORT)block_status; 85 | 86 | /* Get the page number to write. */ 87 | page_number = (UCHAR)(block * sizeof(*nand_flash -> lx_nand_flash_block_status_table) / nand_flash -> lx_nand_flash_bytes_per_page); 88 | 89 | /* Save the status table. */ 90 | status = _lx_nand_flash_metadata_write(nand_flash, ((UCHAR*)nand_flash -> lx_nand_flash_block_status_table) + 91 | page_number * nand_flash -> lx_nand_flash_bytes_per_page, LX_NAND_PAGE_TYPE_BLOCK_STATUS_TABLE | page_number); 92 | 93 | /* Return status. */ 94 | return(status); 95 | } 96 | 97 | -------------------------------------------------------------------------------- /common/src/lx_nand_flash_close.c: -------------------------------------------------------------------------------- 1 | /*************************************************************************** 2 | * Copyright (c) 2024 Microsoft Corporation 3 | * 4 | * This program and the accompanying materials are made available under the 5 | * terms of the MIT License which is available at 6 | * https://opensource.org/licenses/MIT. 7 | * 8 | * SPDX-License-Identifier: MIT 9 | **************************************************************************/ 10 | 11 | 12 | /**************************************************************************/ 13 | /**************************************************************************/ 14 | /** */ 15 | /** LevelX Component */ 16 | /** */ 17 | /** NAND Flash */ 18 | /** */ 19 | /**************************************************************************/ 20 | /**************************************************************************/ 21 | 22 | #define LX_SOURCE_CODE 23 | 24 | 25 | /* Disable ThreadX error checking. */ 26 | 27 | #ifndef LX_DISABLE_ERROR_CHECKING 28 | #define LX_DISABLE_ERROR_CHECKING 29 | #endif 30 | 31 | 32 | /* Include necessary system files. */ 33 | 34 | #include "lx_api.h" 35 | 36 | 37 | /**************************************************************************/ 38 | /* */ 39 | /* FUNCTION RELEASE */ 40 | /* */ 41 | /* _lx_nand_flash_close PORTABLE C */ 42 | /* 6.1.7 */ 43 | /* AUTHOR */ 44 | /* */ 45 | /* William E. Lamie, Microsoft Corporation */ 46 | /* */ 47 | /* DESCRIPTION */ 48 | /* */ 49 | /* This function closes a NAND flash instance. */ 50 | /* */ 51 | /* INPUT */ 52 | /* */ 53 | /* nand_flash NAND flash instance */ 54 | /* */ 55 | /* OUTPUT */ 56 | /* */ 57 | /* return status */ 58 | /* */ 59 | /* CALLS */ 60 | /* */ 61 | /* tx_mutex_delete Delete thread-safe mutex */ 62 | /* */ 63 | /* CALLED BY */ 64 | /* */ 65 | /* Application Code */ 66 | /* */ 67 | /* RELEASE HISTORY */ 68 | /* */ 69 | /* DATE NAME DESCRIPTION */ 70 | /* */ 71 | /* 05-19-2020 William E. Lamie Initial Version 6.0 */ 72 | /* 09-30-2020 William E. Lamie Modified comment(s), */ 73 | /* resulting in version 6.1 */ 74 | /* 06-02-2021 Bhupendra Naphade Modified comment(s), */ 75 | /* resulting in version 6.1.7 */ 76 | /* */ 77 | /**************************************************************************/ 78 | UINT _lx_nand_flash_close(LX_NAND_FLASH *nand_flash) 79 | { 80 | 81 | LX_INTERRUPT_SAVE_AREA 82 | 83 | 84 | /* Lockout interrupts for NAND flash close. */ 85 | LX_DISABLE 86 | 87 | /* See if the media is the only one on the media opened list. */ 88 | if ((_lx_nand_flash_opened_ptr == nand_flash) && 89 | (_lx_nand_flash_opened_ptr == nand_flash -> lx_nand_flash_open_next) && 90 | (_lx_nand_flash_opened_ptr == nand_flash -> lx_nand_flash_open_previous)) 91 | { 92 | 93 | /* Only opened NAND flash, just set the opened list to NULL. */ 94 | _lx_nand_flash_opened_ptr = LX_NULL; 95 | } 96 | else 97 | { 98 | 99 | /* Otherwise, not the only opened NAND flash, link-up the neighbors. */ 100 | (nand_flash -> lx_nand_flash_open_next) -> lx_nand_flash_open_previous = 101 | nand_flash -> lx_nand_flash_open_previous; 102 | (nand_flash -> lx_nand_flash_open_previous) -> lx_nand_flash_open_next = 103 | nand_flash -> lx_nand_flash_open_next; 104 | 105 | /* See if we have to update the opened list head pointer. */ 106 | if (_lx_nand_flash_opened_ptr == nand_flash) 107 | { 108 | 109 | /* Yes, move the head pointer to the next opened NAND flash. */ 110 | _lx_nand_flash_opened_ptr = nand_flash -> lx_nand_flash_open_next; 111 | } 112 | } 113 | 114 | /* Decrement the opened NAND flash counter. */ 115 | _lx_nand_flash_opened_count--; 116 | 117 | /* Finally, indicate that this NAND flash is closed. */ 118 | nand_flash -> lx_nand_flash_state = LX_NAND_FLASH_CLOSED; 119 | 120 | /* Restore interrupt posture. */ 121 | LX_RESTORE 122 | 123 | #ifdef LX_THREAD_SAFE_ENABLE 124 | 125 | /* Delete the thread safe mutex. */ 126 | tx_mutex_delete(&nand_flash -> lx_nand_flash_mutex); 127 | #endif 128 | /* Return success. */ 129 | return(LX_SUCCESS); 130 | } 131 | 132 | 133 | -------------------------------------------------------------------------------- /common/src/lx_nand_flash_defragment.c: -------------------------------------------------------------------------------- 1 | /*************************************************************************** 2 | * Copyright (c) 2024 Microsoft Corporation 3 | * 4 | * This program and the accompanying materials are made available under the 5 | * terms of the MIT License which is available at 6 | * https://opensource.org/licenses/MIT. 7 | * 8 | * SPDX-License-Identifier: MIT 9 | **************************************************************************/ 10 | 11 | 12 | /**************************************************************************/ 13 | /**************************************************************************/ 14 | /** */ 15 | /** LevelX Component */ 16 | /** */ 17 | /** NAND Flash */ 18 | /** */ 19 | /**************************************************************************/ 20 | /**************************************************************************/ 21 | 22 | #define LX_SOURCE_CODE 23 | 24 | 25 | /* Disable ThreadX error checking. */ 26 | 27 | #ifndef LX_DISABLE_ERROR_CHECKING 28 | #define LX_DISABLE_ERROR_CHECKING 29 | #endif 30 | 31 | 32 | /* Include necessary system files. */ 33 | 34 | #include "lx_api.h" 35 | 36 | 37 | /**************************************************************************/ 38 | /* */ 39 | /* FUNCTION RELEASE */ 40 | /* */ 41 | /* _lx_nand_flash_defragment PORTABLE C */ 42 | /* 6.2.1 */ 43 | /* AUTHOR */ 44 | /* */ 45 | /* William E. Lamie, Microsoft Corporation */ 46 | /* */ 47 | /* DESCRIPTION */ 48 | /* */ 49 | /* This function defragments the NAND flash. */ 50 | /* */ 51 | /* INPUT */ 52 | /* */ 53 | /* nand_flash NAND flash instance */ 54 | /* */ 55 | /* OUTPUT */ 56 | /* */ 57 | /* return status */ 58 | /* */ 59 | /* CALLS */ 60 | /* */ 61 | /* _lx_nand_flash_block_reclaim Reclaim a NAND flash block */ 62 | /* tx_mutex_get Get thread protection */ 63 | /* tx_mutex_put Release thread protection */ 64 | /* */ 65 | /* CALLED BY */ 66 | /* */ 67 | /* Application Code */ 68 | /* Internal LevelX */ 69 | /* */ 70 | /* RELEASE HISTORY */ 71 | /* */ 72 | /* DATE NAME DESCRIPTION */ 73 | /* */ 74 | /* 05-19-2020 William E. Lamie Initial Version 6.0 */ 75 | /* 09-30-2020 William E. Lamie Modified comment(s), */ 76 | /* resulting in version 6.1 */ 77 | /* 06-02-2021 Bhupendra Naphade Modified comment(s), */ 78 | /* resulting in version 6.1.7 */ 79 | /* 03-08-2023 Xiuwen Cai Modified comment(s), */ 80 | /* deprecated this API, */ 81 | /* resulting in version 6.2.1 */ 82 | /* */ 83 | /**************************************************************************/ 84 | UINT _lx_nand_flash_defragment(LX_NAND_FLASH *nand_flash) 85 | { 86 | 87 | LX_PARAMETER_NOT_USED(nand_flash); 88 | 89 | /* Return not supported. */ 90 | return(LX_NOT_SUPPORTED); 91 | } 92 | 93 | 94 | -------------------------------------------------------------------------------- /common/src/lx_nand_flash_driver_block_erase.c: -------------------------------------------------------------------------------- 1 | /*************************************************************************** 2 | * Copyright (c) 2024 Microsoft Corporation 3 | * 4 | * This program and the accompanying materials are made available under the 5 | * terms of the MIT License which is available at 6 | * https://opensource.org/licenses/MIT. 7 | * 8 | * SPDX-License-Identifier: MIT 9 | **************************************************************************/ 10 | 11 | 12 | /**************************************************************************/ 13 | /**************************************************************************/ 14 | /** */ 15 | /** LevelX Component */ 16 | /** */ 17 | /** NAND Flash */ 18 | /** */ 19 | /**************************************************************************/ 20 | /**************************************************************************/ 21 | 22 | #define LX_SOURCE_CODE 23 | 24 | 25 | /* Disable ThreadX error checking. */ 26 | 27 | #ifndef LX_DISABLE_ERROR_CHECKING 28 | #define LX_DISABLE_ERROR_CHECKING 29 | #endif 30 | 31 | 32 | /* Include necessary system files. */ 33 | 34 | #include "lx_api.h" 35 | 36 | 37 | /**************************************************************************/ 38 | /* */ 39 | /* FUNCTION RELEASE */ 40 | /* */ 41 | /* _lx_nand_flash_driver_block_erase PORTABLE C */ 42 | /* 6.2.1 */ 43 | /* AUTHOR */ 44 | /* */ 45 | /* William E. Lamie, Microsoft Corporation */ 46 | /* */ 47 | /* DESCRIPTION */ 48 | /* */ 49 | /* This function calls the driver to erase a block. */ 50 | /* */ 51 | /* INPUT */ 52 | /* */ 53 | /* nand_flash NAND flash instance */ 54 | /* block Block number */ 55 | /* erase_count Erase count for this block */ 56 | /* */ 57 | /* OUTPUT */ 58 | /* */ 59 | /* Completion Status */ 60 | /* */ 61 | /* CALLS */ 62 | /* */ 63 | /* (lx_nand_flash_driver_block_erase) Driver erase block */ 64 | /* */ 65 | /* CALLED BY */ 66 | /* */ 67 | /* Internal LevelX */ 68 | /* */ 69 | /* RELEASE HISTORY */ 70 | /* */ 71 | /* DATE NAME DESCRIPTION */ 72 | /* */ 73 | /* 05-19-2020 William E. Lamie Initial Version 6.0 */ 74 | /* 09-30-2020 William E. Lamie Modified comment(s), */ 75 | /* resulting in version 6.1 */ 76 | /* 06-02-2021 Bhupendra Naphade Modified comment(s), */ 77 | /* resulting in version 6.1.7 */ 78 | /* 03-08-2023 Xiuwen Cai Modified comment(s), */ 79 | /* removed cache support, */ 80 | /* added new driver interface, */ 81 | /* resulting in version 6.2.1 */ 82 | /* */ 83 | /**************************************************************************/ 84 | UINT _lx_nand_flash_driver_block_erase(LX_NAND_FLASH *nand_flash, ULONG block, ULONG erase_count) 85 | { 86 | 87 | UINT status; 88 | 89 | 90 | /* Increment the block erases count. */ 91 | nand_flash -> lx_nand_flash_diagnostic_block_erases++; 92 | 93 | /* Call driver erase block function. */ 94 | #ifdef LX_NAND_ENABLE_CONTROL_BLOCK_FOR_DRIVER_INTERFACE 95 | status = (nand_flash -> lx_nand_flash_driver_block_erase)(nand_flash, block, erase_count); 96 | #else 97 | status = (nand_flash -> lx_nand_flash_driver_block_erase)(block, erase_count); 98 | #endif 99 | 100 | /* Return status. */ 101 | return(status); 102 | } 103 | 104 | 105 | -------------------------------------------------------------------------------- /common/src/lx_nand_flash_driver_block_erased_verify.c: -------------------------------------------------------------------------------- 1 | /*************************************************************************** 2 | * Copyright (c) 2024 Microsoft Corporation 3 | * 4 | * This program and the accompanying materials are made available under the 5 | * terms of the MIT License which is available at 6 | * https://opensource.org/licenses/MIT. 7 | * 8 | * SPDX-License-Identifier: MIT 9 | **************************************************************************/ 10 | 11 | 12 | /**************************************************************************/ 13 | /**************************************************************************/ 14 | /** */ 15 | /** LevelX Component */ 16 | /** */ 17 | /** NAND Flash */ 18 | /** */ 19 | /**************************************************************************/ 20 | /**************************************************************************/ 21 | 22 | #define LX_SOURCE_CODE 23 | 24 | 25 | /* Disable ThreadX error checking. */ 26 | 27 | #ifndef LX_DISABLE_ERROR_CHECKING 28 | #define LX_DISABLE_ERROR_CHECKING 29 | #endif 30 | 31 | 32 | /* Include necessary system files. */ 33 | 34 | #include "lx_api.h" 35 | 36 | 37 | /**************************************************************************/ 38 | /* */ 39 | /* FUNCTION RELEASE */ 40 | /* */ 41 | /* _lx_nand_flash_driver_block_erased_verify PORTABLE C */ 42 | /* 6.2.1 */ 43 | /* AUTHOR */ 44 | /* */ 45 | /* William E. Lamie, Microsoft Corporation */ 46 | /* */ 47 | /* DESCRIPTION */ 48 | /* */ 49 | /* This function calls the driver to verify the block was erased. */ 50 | /* */ 51 | /* INPUT */ 52 | /* */ 53 | /* nand_flash NAND flash instance */ 54 | /* block Block number */ 55 | /* page Page number */ 56 | /* */ 57 | /* OUTPUT */ 58 | /* */ 59 | /* Completion Status */ 60 | /* */ 61 | /* CALLS */ 62 | /* */ 63 | /* (lx_nand_flash_driver_block_erased_verify) */ 64 | /* Driver verify page erased */ 65 | /* */ 66 | /* CALLED BY */ 67 | /* */ 68 | /* Internal LevelX */ 69 | /* */ 70 | /* RELEASE HISTORY */ 71 | /* */ 72 | /* DATE NAME DESCRIPTION */ 73 | /* */ 74 | /* 05-19-2020 William E. Lamie Initial Version 6.0 */ 75 | /* 09-30-2020 William E. Lamie Modified comment(s), */ 76 | /* resulting in version 6.1 */ 77 | /* 06-02-2021 Bhupendra Naphade Modified comment(s), */ 78 | /* resulting in version 6.1.7 */ 79 | /* 03-08-2023 Xiuwen Cai Modified comment(s), */ 80 | /* added new driver interface, */ 81 | /* resulting in version 6.2.1 */ 82 | /* */ 83 | /**************************************************************************/ 84 | UINT _lx_nand_flash_driver_block_erased_verify(LX_NAND_FLASH *nand_flash, ULONG block) 85 | { 86 | 87 | UINT status; 88 | 89 | /* Increment the block erased verify count. */ 90 | nand_flash -> lx_nand_flash_diagnostic_block_erased_verifies++; 91 | 92 | /* Call driver block erased verify function. */ 93 | #ifdef LX_NAND_ENABLE_CONTROL_BLOCK_FOR_DRIVER_INTERFACE 94 | status = (nand_flash -> lx_nand_flash_driver_block_erased_verify)(nand_flash, block); 95 | #else 96 | status = (nand_flash -> lx_nand_flash_driver_block_erased_verify)(block); 97 | #endif 98 | /* Return status. */ 99 | return(status); 100 | } 101 | 102 | 103 | -------------------------------------------------------------------------------- /common/src/lx_nand_flash_driver_block_status_get.c: -------------------------------------------------------------------------------- 1 | /*************************************************************************** 2 | * Copyright (c) 2024 Microsoft Corporation 3 | * 4 | * This program and the accompanying materials are made available under the 5 | * terms of the MIT License which is available at 6 | * https://opensource.org/licenses/MIT. 7 | * 8 | * SPDX-License-Identifier: MIT 9 | **************************************************************************/ 10 | 11 | 12 | /**************************************************************************/ 13 | /**************************************************************************/ 14 | /** */ 15 | /** LevelX Component */ 16 | /** */ 17 | /** NAND Flash */ 18 | /** */ 19 | /**************************************************************************/ 20 | /**************************************************************************/ 21 | 22 | #define LX_SOURCE_CODE 23 | 24 | 25 | /* Disable ThreadX error checking. */ 26 | 27 | #ifndef LX_DISABLE_ERROR_CHECKING 28 | #define LX_DISABLE_ERROR_CHECKING 29 | #endif 30 | 31 | 32 | /* Include necessary system files. */ 33 | 34 | #include "lx_api.h" 35 | 36 | 37 | /**************************************************************************/ 38 | /* */ 39 | /* FUNCTION RELEASE */ 40 | /* */ 41 | /* _lx_nand_flash_driver_block_status_get PORTABLE C */ 42 | /* 6.2.1 */ 43 | /* AUTHOR */ 44 | /* */ 45 | /* William E. Lamie, Microsoft Corporation */ 46 | /* */ 47 | /* DESCRIPTION */ 48 | /* */ 49 | /* This function calls the driver to get the block status and */ 50 | /* updates the internal cache. */ 51 | /* */ 52 | /* INPUT */ 53 | /* */ 54 | /* nand_flash NAND flash instance */ 55 | /* block Block number */ 56 | /* bad_block_flag Pointer to Bad block flag */ 57 | /* */ 58 | /* OUTPUT */ 59 | /* */ 60 | /* Completion Status */ 61 | /* */ 62 | /* CALLS */ 63 | /* */ 64 | /* (lx_nand_flash_driver_block_status_get) */ 65 | /* NAND flash block status get */ 66 | /* */ 67 | /* CALLED BY */ 68 | /* */ 69 | /* Internal LevelX */ 70 | /* */ 71 | /* RELEASE HISTORY */ 72 | /* */ 73 | /* DATE NAME DESCRIPTION */ 74 | /* */ 75 | /* 05-19-2020 William E. Lamie Initial Version 6.0 */ 76 | /* 09-30-2020 William E. Lamie Modified comment(s), */ 77 | /* resulting in version 6.1 */ 78 | /* 06-02-2021 Bhupendra Naphade Modified comment(s), */ 79 | /* resulting in version 6.1.7 */ 80 | /* 03-08-2023 Xiuwen Cai Modified comment(s), */ 81 | /* removed cache support, */ 82 | /* added new driver interface, */ 83 | /* resulting in version 6.2.1 */ 84 | /* */ 85 | /**************************************************************************/ 86 | UINT _lx_nand_flash_driver_block_status_get(LX_NAND_FLASH *nand_flash, ULONG block, UCHAR *bad_block_flag) 87 | { 88 | 89 | UINT status; 90 | 91 | 92 | /* Increment the block status get count. */ 93 | nand_flash -> lx_nand_flash_diagnostic_block_status_gets++; 94 | 95 | /* Call driver block status get function. */ 96 | #ifdef LX_NAND_ENABLE_CONTROL_BLOCK_FOR_DRIVER_INTERFACE 97 | status = (nand_flash -> lx_nand_flash_driver_block_status_get)(nand_flash, block, bad_block_flag); 98 | #else 99 | status = (nand_flash -> lx_nand_flash_driver_block_status_get)(block, bad_block_flag); 100 | #endif 101 | 102 | /* Return status. */ 103 | return(status); 104 | } 105 | 106 | 107 | -------------------------------------------------------------------------------- /common/src/lx_nand_flash_driver_block_status_set.c: -------------------------------------------------------------------------------- 1 | /*************************************************************************** 2 | * Copyright (c) 2024 Microsoft Corporation 3 | * 4 | * This program and the accompanying materials are made available under the 5 | * terms of the MIT License which is available at 6 | * https://opensource.org/licenses/MIT. 7 | * 8 | * SPDX-License-Identifier: MIT 9 | **************************************************************************/ 10 | 11 | 12 | /**************************************************************************/ 13 | /**************************************************************************/ 14 | /** */ 15 | /** LevelX Component */ 16 | /** */ 17 | /** NAND Flash */ 18 | /** */ 19 | /**************************************************************************/ 20 | /**************************************************************************/ 21 | 22 | #define LX_SOURCE_CODE 23 | 24 | 25 | /* Disable ThreadX error checking. */ 26 | 27 | #ifndef LX_DISABLE_ERROR_CHECKING 28 | #define LX_DISABLE_ERROR_CHECKING 29 | #endif 30 | 31 | 32 | /* Include necessary system files. */ 33 | 34 | #include "lx_api.h" 35 | 36 | 37 | /**************************************************************************/ 38 | /* */ 39 | /* FUNCTION RELEASE */ 40 | /* */ 41 | /* _lx_nand_flash_driver_block_status_set PORTABLE C */ 42 | /* 6.2.1 */ 43 | /* AUTHOR */ 44 | /* */ 45 | /* William E. Lamie, Microsoft Corporation */ 46 | /* */ 47 | /* DESCRIPTION */ 48 | /* */ 49 | /* This function calls the driver to set the block status and */ 50 | /* updates the internal cache. */ 51 | /* */ 52 | /* INPUT */ 53 | /* */ 54 | /* nand_flash NAND flash instance */ 55 | /* block Block number */ 56 | /* bad_block_flag Bad block flag */ 57 | /* */ 58 | /* OUTPUT */ 59 | /* */ 60 | /* Completion Status */ 61 | /* */ 62 | /* CALLS */ 63 | /* */ 64 | /* (lx_nand_flash_driver_block_status_set) */ 65 | /* NAND flash block status set */ 66 | /* */ 67 | /* CALLED BY */ 68 | /* */ 69 | /* Internal LevelX */ 70 | /* */ 71 | /* RELEASE HISTORY */ 72 | /* */ 73 | /* DATE NAME DESCRIPTION */ 74 | /* */ 75 | /* 05-19-2020 William E. Lamie Initial Version 6.0 */ 76 | /* 09-30-2020 William E. Lamie Modified comment(s), */ 77 | /* resulting in version 6.1 */ 78 | /* 06-02-2021 Bhupendra Naphade Modified comment(s), */ 79 | /* resulting in version 6.1.7 */ 80 | /* 03-08-2023 Xiuwen Cai Modified comment(s), */ 81 | /* removed cache support, */ 82 | /* added new driver interface, */ 83 | /* resulting in version 6.2.1 */ 84 | /* */ 85 | /**************************************************************************/ 86 | UINT _lx_nand_flash_driver_block_status_set(LX_NAND_FLASH *nand_flash, ULONG block, UCHAR bad_block_flag) 87 | { 88 | 89 | UINT status; 90 | 91 | 92 | /* Increment the block status set count. */ 93 | nand_flash -> lx_nand_flash_diagnostic_block_status_sets++; 94 | 95 | /* Call driver block status set function. */ 96 | #ifdef LX_NAND_ENABLE_CONTROL_BLOCK_FOR_DRIVER_INTERFACE 97 | status = (nand_flash -> lx_nand_flash_driver_block_status_set)(nand_flash, block, bad_block_flag); 98 | #else 99 | status = (nand_flash -> lx_nand_flash_driver_block_status_set)(block, bad_block_flag); 100 | #endif 101 | 102 | /* Return status. */ 103 | return(status); 104 | } 105 | 106 | 107 | -------------------------------------------------------------------------------- /common/src/lx_nand_flash_driver_page_erased_verify.c: -------------------------------------------------------------------------------- 1 | /*************************************************************************** 2 | * Copyright (c) 2024 Microsoft Corporation 3 | * 4 | * This program and the accompanying materials are made available under the 5 | * terms of the MIT License which is available at 6 | * https://opensource.org/licenses/MIT. 7 | * 8 | * SPDX-License-Identifier: MIT 9 | **************************************************************************/ 10 | 11 | 12 | /**************************************************************************/ 13 | /**************************************************************************/ 14 | /** */ 15 | /** LevelX Component */ 16 | /** */ 17 | /** NAND Flash */ 18 | /** */ 19 | /**************************************************************************/ 20 | /**************************************************************************/ 21 | 22 | #define LX_SOURCE_CODE 23 | 24 | 25 | /* Disable ThreadX error checking. */ 26 | 27 | #ifndef LX_DISABLE_ERROR_CHECKING 28 | #define LX_DISABLE_ERROR_CHECKING 29 | #endif 30 | 31 | 32 | /* Include necessary system files. */ 33 | 34 | #include "lx_api.h" 35 | 36 | 37 | /**************************************************************************/ 38 | /* */ 39 | /* FUNCTION RELEASE */ 40 | /* */ 41 | /* _lx_nand_flash_driver_page_erased_verify PORTABLE C */ 42 | /* 6.2.1 */ 43 | /* AUTHOR */ 44 | /* */ 45 | /* William E. Lamie, Microsoft Corporation */ 46 | /* */ 47 | /* DESCRIPTION */ 48 | /* */ 49 | /* This function calls the driver to verify the page was erased. */ 50 | /* */ 51 | /* INPUT */ 52 | /* */ 53 | /* nand_flash NAND flash instance */ 54 | /* block Block number */ 55 | /* page Page number */ 56 | /* */ 57 | /* OUTPUT */ 58 | /* */ 59 | /* Completion Status */ 60 | /* */ 61 | /* CALLS */ 62 | /* */ 63 | /* (lx_nand_flash_driver_page_erased_verify) */ 64 | /* Driver verify page erased */ 65 | /* */ 66 | /* CALLED BY */ 67 | /* */ 68 | /* Internal LevelX */ 69 | /* */ 70 | /* RELEASE HISTORY */ 71 | /* */ 72 | /* DATE NAME DESCRIPTION */ 73 | /* */ 74 | /* 05-19-2020 William E. Lamie Initial Version 6.0 */ 75 | /* 09-30-2020 William E. Lamie Modified comment(s), */ 76 | /* resulting in version 6.1 */ 77 | /* 06-02-2021 Bhupendra Naphade Modified comment(s), */ 78 | /* resulting in version 6.1.7 */ 79 | /* 03-08-2023 Xiuwen Cai Modified comment(s), */ 80 | /* added new driver interface, */ 81 | /* resulting in version 6.2.1 */ 82 | /* */ 83 | /**************************************************************************/ 84 | UINT _lx_nand_flash_driver_page_erased_verify(LX_NAND_FLASH *nand_flash, ULONG block, ULONG page) 85 | { 86 | 87 | UINT status; 88 | 89 | /* Increment the page erased verify count. */ 90 | nand_flash -> lx_nand_flash_diagnostic_page_erased_verifies++; 91 | 92 | /* Call driver page erased verify function. */ 93 | #ifdef LX_NAND_ENABLE_CONTROL_BLOCK_FOR_DRIVER_INTERFACE 94 | status = (nand_flash -> lx_nand_flash_driver_page_erased_verify)(nand_flash, block, page); 95 | #else 96 | status = (nand_flash -> lx_nand_flash_driver_page_erased_verify)(block, page); 97 | #endif 98 | /* Return status. */ 99 | return(status); 100 | } 101 | 102 | -------------------------------------------------------------------------------- /common/src/lx_nand_flash_erase_count_set.c: -------------------------------------------------------------------------------- 1 | /*************************************************************************** 2 | * Copyright (c) 2024 Microsoft Corporation 3 | * 4 | * This program and the accompanying materials are made available under the 5 | * terms of the MIT License which is available at 6 | * https://opensource.org/licenses/MIT. 7 | * 8 | * SPDX-License-Identifier: MIT 9 | **************************************************************************/ 10 | 11 | 12 | /**************************************************************************/ 13 | /**************************************************************************/ 14 | /** */ 15 | /** LevelX Component */ 16 | /** */ 17 | /** NAND Flash */ 18 | /** */ 19 | /**************************************************************************/ 20 | /**************************************************************************/ 21 | 22 | #define LX_SOURCE_CODE 23 | 24 | 25 | /* Disable ThreadX error checking. */ 26 | 27 | #ifndef LX_DISABLE_ERROR_CHECKING 28 | #define LX_DISABLE_ERROR_CHECKING 29 | #endif 30 | 31 | 32 | /* Include necessary system files. */ 33 | 34 | #include "lx_api.h" 35 | 36 | 37 | /**************************************************************************/ 38 | /* */ 39 | /* FUNCTION RELEASE */ 40 | /* */ 41 | /* _lx_nand_flash_erase_count_set PORTABLE C */ 42 | /* 6.2.1 */ 43 | /* AUTHOR */ 44 | /* */ 45 | /* Xiuwen Cai, Microsoft Corporation */ 46 | /* */ 47 | /* DESCRIPTION */ 48 | /* */ 49 | /* This function sets block erase count. */ 50 | /* */ 51 | /* INPUT */ 52 | /* */ 53 | /* nand_flash NAND flash instance */ 54 | /* block Block number */ 55 | /* erase_count Erase count */ 56 | /* */ 57 | /* OUTPUT */ 58 | /* */ 59 | /* return status */ 60 | /* */ 61 | /* CALLS */ 62 | /* */ 63 | /* _lx_nand_flash_metadata_write Write metadata */ 64 | /* */ 65 | /* CALLED BY */ 66 | /* */ 67 | /* Internal LevelX */ 68 | /* */ 69 | /* RELEASE HISTORY */ 70 | /* */ 71 | /* DATE NAME DESCRIPTION */ 72 | /* */ 73 | /* 03-08-2023 Xiuwen Cai Initial Version 6.2.1 */ 74 | /* */ 75 | /**************************************************************************/ 76 | UINT _lx_nand_flash_erase_count_set(LX_NAND_FLASH *nand_flash, ULONG block, UCHAR erase_count) 77 | { 78 | 79 | UCHAR page_number; 80 | UINT status; 81 | 82 | 83 | /* Save the erase count to erase count table. */ 84 | nand_flash -> lx_nand_flash_erase_count_table[block] = erase_count; 85 | 86 | /* Get the page number to write. */ 87 | page_number = (UCHAR)(block * sizeof(*nand_flash -> lx_nand_flash_erase_count_table) / nand_flash -> lx_nand_flash_bytes_per_page); 88 | 89 | /* Save the erase count table. */ 90 | status = _lx_nand_flash_metadata_write(nand_flash, ((UCHAR*)nand_flash -> lx_nand_flash_erase_count_table) + 91 | page_number * nand_flash -> lx_nand_flash_bytes_per_page, 92 | LX_NAND_PAGE_TYPE_ERASE_COUNT_TABLE | page_number); 93 | 94 | /* Return sector not found status. */ 95 | return(status); 96 | } 97 | 98 | -------------------------------------------------------------------------------- /common/src/lx_nand_flash_extended_cache_enable.c: -------------------------------------------------------------------------------- 1 | /*************************************************************************** 2 | * Copyright (c) 2024 Microsoft Corporation 3 | * 4 | * This program and the accompanying materials are made available under the 5 | * terms of the MIT License which is available at 6 | * https://opensource.org/licenses/MIT. 7 | * 8 | * SPDX-License-Identifier: MIT 9 | **************************************************************************/ 10 | 11 | 12 | /**************************************************************************/ 13 | /**************************************************************************/ 14 | /** */ 15 | /** LevelX Component */ 16 | /** */ 17 | /** NAND Flash */ 18 | /** */ 19 | /**************************************************************************/ 20 | /**************************************************************************/ 21 | 22 | #define LX_SOURCE_CODE 23 | 24 | 25 | /* Disable ThreadX error checking. */ 26 | 27 | #ifndef LX_DISABLE_ERROR_CHECKING 28 | #define LX_DISABLE_ERROR_CHECKING 29 | #endif 30 | 31 | 32 | /* Include necessary system files. */ 33 | 34 | #include "lx_api.h" 35 | 36 | 37 | /**************************************************************************/ 38 | /* */ 39 | /* FUNCTION RELEASE */ 40 | /* */ 41 | /* _lx_nand_flash_extended_cache_enable PORTABLE C */ 42 | /* 6.2.1 */ 43 | /* AUTHOR */ 44 | /* */ 45 | /* William E. Lamie, Microsoft Corporation */ 46 | /* */ 47 | /* DESCRIPTION */ 48 | /* */ 49 | /* This function sets up the extended NAND cache for block status, */ 50 | /* page extra bytes, and page 0 contents. The routine will enable as */ 51 | /* many cache capabilities as possible until the supplied memory is */ 52 | /* exhausted. */ 53 | /* */ 54 | /* INPUT */ 55 | /* */ 56 | /* nand_flash NAND flash instance */ 57 | /* memory Pointer to memory for caches */ 58 | /* size Size of memory in bytes */ 59 | /* */ 60 | /* OUTPUT */ 61 | /* */ 62 | /* Completion Status */ 63 | /* */ 64 | /* CALLS */ 65 | /* */ 66 | /* None */ 67 | /* */ 68 | /* CALLED BY */ 69 | /* */ 70 | /* Internal LevelX */ 71 | /* */ 72 | /* RELEASE HISTORY */ 73 | /* */ 74 | /* DATE NAME DESCRIPTION */ 75 | /* */ 76 | /* 05-19-2020 William E. Lamie Initial Version 6.0 */ 77 | /* 09-30-2020 William E. Lamie Modified comment(s), */ 78 | /* resulting in version 6.1 */ 79 | /* 06-02-2021 Bhupendra Naphade Modified comment(s), */ 80 | /* resulting in version 6.1.7 */ 81 | /* 03-08-2023 Xiuwen Cai Modified comment(s), */ 82 | /* deprecated this API, */ 83 | /* resulting in version 6.2.1 */ 84 | /* */ 85 | /**************************************************************************/ 86 | UINT _lx_nand_flash_extended_cache_enable(LX_NAND_FLASH *nand_flash, VOID *memory, ULONG size) 87 | { 88 | 89 | LX_PARAMETER_NOT_USED(nand_flash); 90 | LX_PARAMETER_NOT_USED(memory); 91 | LX_PARAMETER_NOT_USED(size); 92 | 93 | /* Return not supported. */ 94 | return(LX_NOT_SUPPORTED); 95 | } 96 | 97 | -------------------------------------------------------------------------------- /common/src/lx_nand_flash_free_block_list_add.c: -------------------------------------------------------------------------------- 1 | /*************************************************************************** 2 | * Copyright (c) 2024 Microsoft Corporation 3 | * 4 | * This program and the accompanying materials are made available under the 5 | * terms of the MIT License which is available at 6 | * https://opensource.org/licenses/MIT. 7 | * 8 | * SPDX-License-Identifier: MIT 9 | **************************************************************************/ 10 | 11 | 12 | /**************************************************************************/ 13 | /**************************************************************************/ 14 | /** */ 15 | /** LevelX Component */ 16 | /** */ 17 | /** NAND Flash */ 18 | /** */ 19 | /**************************************************************************/ 20 | /**************************************************************************/ 21 | 22 | #define LX_SOURCE_CODE 23 | 24 | 25 | /* Disable ThreadX error checking. */ 26 | 27 | #ifndef LX_DISABLE_ERROR_CHECKING 28 | #define LX_DISABLE_ERROR_CHECKING 29 | #endif 30 | 31 | 32 | /* Include necessary system files. */ 33 | 34 | #include "lx_api.h" 35 | 36 | 37 | /**************************************************************************/ 38 | /* */ 39 | /* FUNCTION RELEASE */ 40 | /* */ 41 | /* _lx_nand_flash_free_block_list_add PORTABLE C */ 42 | /* 6.2.1 */ 43 | /* AUTHOR */ 44 | /* */ 45 | /* Xiuwen Cai, Microsoft Corporation */ 46 | /* */ 47 | /* DESCRIPTION */ 48 | /* */ 49 | /* This function adds a block to free block list. */ 50 | /* */ 51 | /* INPUT */ 52 | /* */ 53 | /* nand_flash NAND flash instance */ 54 | /* block Block number */ 55 | /* */ 56 | /* OUTPUT */ 57 | /* */ 58 | /* return status */ 59 | /* */ 60 | /* CALLS */ 61 | /* */ 62 | /* None */ 63 | /* */ 64 | /* CALLED BY */ 65 | /* */ 66 | /* Internal LevelX */ 67 | /* */ 68 | /* RELEASE HISTORY */ 69 | /* */ 70 | /* DATE NAME DESCRIPTION */ 71 | /* */ 72 | /* 03-08-2023 Xiuwen Cai Initial Version 6.2.1 */ 73 | /* */ 74 | /**************************************************************************/ 75 | UINT _lx_nand_flash_free_block_list_add(LX_NAND_FLASH* nand_flash, ULONG block) 76 | { 77 | 78 | ULONG insert_position; 79 | INT search_position; 80 | UCHAR new_block_erase_count; 81 | 82 | 83 | /* Get insert position for the free block list. */ 84 | insert_position = nand_flash -> lx_nand_flash_free_block_list_tail; 85 | 86 | /* Check if the list if full. */ 87 | if (insert_position > nand_flash -> lx_nand_flash_mapped_block_list_head) 88 | { 89 | 90 | /* Return an error. */ 91 | return(LX_ERROR); 92 | } 93 | 94 | /* Get the erase count. */ 95 | new_block_erase_count = nand_flash -> lx_nand_flash_erase_count_table[block]; 96 | 97 | /* Add one block to the free list. */ 98 | nand_flash -> lx_nand_flash_free_block_list_tail++; 99 | 100 | /* Initialize the search pointer. */ 101 | search_position = (INT)insert_position - 1; 102 | 103 | /* Loop to search the insert position by block erase count. */ 104 | while ((search_position >= 0) && 105 | (nand_flash -> lx_nand_flash_erase_count_table[nand_flash -> lx_nand_flash_block_list[search_position]] < new_block_erase_count)) 106 | { 107 | 108 | /* Move the item in the list. */ 109 | nand_flash -> lx_nand_flash_block_list[insert_position] = nand_flash -> lx_nand_flash_block_list[search_position]; 110 | search_position--; 111 | insert_position--; 112 | } 113 | 114 | /* Insert the new block to the list. */ 115 | nand_flash -> lx_nand_flash_block_list[insert_position] = (USHORT)block; 116 | 117 | /* Return successful completion. */ 118 | return(LX_SUCCESS); 119 | } 120 | 121 | -------------------------------------------------------------------------------- /common/src/lx_nand_flash_initialize.c: -------------------------------------------------------------------------------- 1 | /*************************************************************************** 2 | * Copyright (c) 2024 Microsoft Corporation 3 | * 4 | * This program and the accompanying materials are made available under the 5 | * terms of the MIT License which is available at 6 | * https://opensource.org/licenses/MIT. 7 | * 8 | * SPDX-License-Identifier: MIT 9 | **************************************************************************/ 10 | 11 | 12 | /**************************************************************************/ 13 | /**************************************************************************/ 14 | /** */ 15 | /** LevelX Component */ 16 | /** */ 17 | /** NAND Flash */ 18 | /** */ 19 | /**************************************************************************/ 20 | /**************************************************************************/ 21 | 22 | #define LX_SOURCE_CODE 23 | 24 | 25 | /* Include necessary system files. */ 26 | 27 | #include "lx_api.h" 28 | 29 | 30 | /* Define the NAND flash opened list head and opened count. */ 31 | 32 | LX_NAND_FLASH *_lx_nand_flash_opened_ptr; 33 | ULONG _lx_nand_flash_opened_count; 34 | 35 | 36 | /**************************************************************************/ 37 | /* */ 38 | /* FUNCTION RELEASE */ 39 | /* */ 40 | /* _lx_nand_flash_initialize PORTABLE C */ 41 | /* 6.1 */ 42 | /* AUTHOR */ 43 | /* */ 44 | /* William E. Lamie, Microsoft Corporation */ 45 | /* */ 46 | /* DESCRIPTION */ 47 | /* */ 48 | /* This function initializes the NAND flash data structures. */ 49 | /* */ 50 | /* INPUT */ 51 | /* */ 52 | /* None */ 53 | /* */ 54 | /* OUTPUT */ 55 | /* */ 56 | /* return status */ 57 | /* */ 58 | /* CALLS */ 59 | /* */ 60 | /* None */ 61 | /* */ 62 | /* CALLED BY */ 63 | /* */ 64 | /* Application Code */ 65 | /* */ 66 | /* RELEASE HISTORY */ 67 | /* */ 68 | /* DATE NAME DESCRIPTION */ 69 | /* */ 70 | /* 05-19-2020 William E. Lamie Initial Version 6.0 */ 71 | /* 09-30-2020 William E. Lamie Modified comment(s), */ 72 | /* resulting in version 6.1 */ 73 | /* */ 74 | /**************************************************************************/ 75 | UINT _lx_nand_flash_initialize(void) 76 | { 77 | 78 | /* Clear open list head pointer and opened count. */ 79 | _lx_nand_flash_opened_ptr = LX_NULL; 80 | _lx_nand_flash_opened_count = 0; 81 | 82 | /* Return success! */ 83 | return(LX_SUCCESS); 84 | } 85 | 86 | -------------------------------------------------------------------------------- /common/src/lx_nand_flash_mapped_block_list_add.c: -------------------------------------------------------------------------------- 1 | /*************************************************************************** 2 | * Copyright (c) 2024 Microsoft Corporation 3 | * 4 | * This program and the accompanying materials are made available under the 5 | * terms of the MIT License which is available at 6 | * https://opensource.org/licenses/MIT. 7 | * 8 | * SPDX-License-Identifier: MIT 9 | **************************************************************************/ 10 | 11 | 12 | /**************************************************************************/ 13 | /**************************************************************************/ 14 | /** */ 15 | /** LevelX Component */ 16 | /** */ 17 | /** NAND Flash */ 18 | /** */ 19 | /**************************************************************************/ 20 | /**************************************************************************/ 21 | 22 | #define LX_SOURCE_CODE 23 | 24 | 25 | /* Disable ThreadX error checking. */ 26 | 27 | #ifndef LX_DISABLE_ERROR_CHECKING 28 | #define LX_DISABLE_ERROR_CHECKING 29 | #endif 30 | 31 | 32 | /* Include necessary system files. */ 33 | 34 | #include "lx_api.h" 35 | 36 | 37 | /**************************************************************************/ 38 | /* */ 39 | /* FUNCTION RELEASE */ 40 | /* */ 41 | /* _lx_nand_flash_mapped_block_list_add PORTABLE C */ 42 | /* 6.2.1 */ 43 | /* AUTHOR */ 44 | /* */ 45 | /* Xiuwen Cai, Microsoft Corporation */ 46 | /* */ 47 | /* DESCRIPTION */ 48 | /* */ 49 | /* This function adds a block to mapped block list. */ 50 | /* */ 51 | /* INPUT */ 52 | /* */ 53 | /* nand_flash NAND flash instance */ 54 | /* block_mapping_index Block mapping index */ 55 | /* */ 56 | /* OUTPUT */ 57 | /* */ 58 | /* return status */ 59 | /* */ 60 | /* CALLS */ 61 | /* */ 62 | /* None */ 63 | /* */ 64 | /* CALLED BY */ 65 | /* */ 66 | /* Internal LevelX */ 67 | /* */ 68 | /* RELEASE HISTORY */ 69 | /* */ 70 | /* DATE NAME DESCRIPTION */ 71 | /* */ 72 | /* 03-08-2023 Xiuwen Cai Initial Version 6.2.1 */ 73 | /* */ 74 | /**************************************************************************/ 75 | UINT _lx_nand_flash_mapped_block_list_add(LX_NAND_FLASH* nand_flash, ULONG block_mapping_index) 76 | { 77 | 78 | ULONG insert_position; 79 | ULONG search_position; 80 | UCHAR new_block_erase_count; 81 | 82 | 83 | /* Get insert position for the mapped block list. */ 84 | insert_position = nand_flash -> lx_nand_flash_mapped_block_list_head; 85 | 86 | /* Check if the list if full. */ 87 | if (insert_position < nand_flash -> lx_nand_flash_free_block_list_tail) 88 | { 89 | 90 | /* Return an error. */ 91 | return(LX_ERROR); 92 | } 93 | 94 | /* Get the erase count. */ 95 | new_block_erase_count = nand_flash -> lx_nand_flash_erase_count_table[nand_flash -> lx_nand_flash_block_mapping_table[block_mapping_index]]; 96 | 97 | /* Add one block to the free list. */ 98 | nand_flash -> lx_nand_flash_mapped_block_list_head--; 99 | 100 | /* Initialize the search pointer. */ 101 | search_position = insert_position + 1; 102 | 103 | /* Loop to search the insert position. */ 104 | while ((search_position < nand_flash -> lx_nand_flash_block_list_size) && 105 | (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)) 106 | { 107 | 108 | /* Move the item in the list. */ 109 | nand_flash -> lx_nand_flash_block_list[insert_position] = nand_flash -> lx_nand_flash_block_list[search_position]; 110 | search_position++; 111 | insert_position++; 112 | } 113 | 114 | /* Insert the new block to the list. */ 115 | nand_flash -> lx_nand_flash_block_list[insert_position] = (USHORT)block_mapping_index; 116 | 117 | /* Return successful completion. */ 118 | return(LX_SUCCESS); 119 | } 120 | 121 | -------------------------------------------------------------------------------- /common/src/lx_nand_flash_mapped_block_list_get.c: -------------------------------------------------------------------------------- 1 | /*************************************************************************** 2 | * Copyright (c) 2024 Microsoft Corporation 3 | * 4 | * This program and the accompanying materials are made available under the 5 | * terms of the MIT License which is available at 6 | * https://opensource.org/licenses/MIT. 7 | * 8 | * SPDX-License-Identifier: MIT 9 | **************************************************************************/ 10 | 11 | 12 | /**************************************************************************/ 13 | /**************************************************************************/ 14 | /** */ 15 | /** LevelX Component */ 16 | /** */ 17 | /** NAND Flash */ 18 | /** */ 19 | /**************************************************************************/ 20 | /**************************************************************************/ 21 | 22 | #define LX_SOURCE_CODE 23 | 24 | 25 | /* Disable ThreadX error checking. */ 26 | 27 | #ifndef LX_DISABLE_ERROR_CHECKING 28 | #define LX_DISABLE_ERROR_CHECKING 29 | #endif 30 | 31 | 32 | /* Include necessary system files. */ 33 | 34 | #include "lx_api.h" 35 | 36 | 37 | /**************************************************************************/ 38 | /* */ 39 | /* FUNCTION RELEASE */ 40 | /* */ 41 | /* _lx_nand_flash_mapped_block_list_get PORTABLE C */ 42 | /* 6.2.1 */ 43 | /* AUTHOR */ 44 | /* */ 45 | /* Xiuwen Cai, Microsoft Corporation */ 46 | /* */ 47 | /* DESCRIPTION */ 48 | /* */ 49 | /* This function gets a block from mapped block list and removes it */ 50 | /* from the list. */ 51 | /* */ 52 | /* INPUT */ 53 | /* */ 54 | /* nand_flash NAND flash instance */ 55 | /* block_mapping_index Pointer to block mapping index*/ 56 | /* */ 57 | /* OUTPUT */ 58 | /* */ 59 | /* return status */ 60 | /* */ 61 | /* CALLS */ 62 | /* */ 63 | /* None */ 64 | /* */ 65 | /* CALLED BY */ 66 | /* */ 67 | /* Internal LevelX */ 68 | /* */ 69 | /* RELEASE HISTORY */ 70 | /* */ 71 | /* DATE NAME DESCRIPTION */ 72 | /* */ 73 | /* 03-08-2023 Xiuwen Cai Initial Version 6.2.1 */ 74 | /* */ 75 | /**************************************************************************/ 76 | UINT _lx_nand_flash_mapped_block_list_get(LX_NAND_FLASH* nand_flash, ULONG *block_mapping_index) 77 | { 78 | 79 | 80 | /* Check if the mapped block list is empty. */ 81 | if (nand_flash -> lx_nand_flash_mapped_block_list_head == nand_flash -> lx_nand_flash_block_list_size - 1) 82 | { 83 | 84 | /* Empty list, return error. */ 85 | return(LX_NO_BLOCKS); 86 | } 87 | 88 | /* Remove one block from the list. */ 89 | nand_flash -> lx_nand_flash_mapped_block_list_head++; 90 | 91 | /* Return the block number. */ 92 | *block_mapping_index = nand_flash -> lx_nand_flash_block_list[nand_flash -> lx_nand_flash_mapped_block_list_head]; 93 | 94 | /* Return successful completion. */ 95 | return(LX_SUCCESS); 96 | } 97 | 98 | -------------------------------------------------------------------------------- /common/src/lx_nand_flash_mapped_block_list_remove.c: -------------------------------------------------------------------------------- 1 | /*************************************************************************** 2 | * Copyright (c) 2024 Microsoft Corporation 3 | * 4 | * This program and the accompanying materials are made available under the 5 | * terms of the MIT License which is available at 6 | * https://opensource.org/licenses/MIT. 7 | * 8 | * SPDX-License-Identifier: MIT 9 | **************************************************************************/ 10 | 11 | 12 | /**************************************************************************/ 13 | /**************************************************************************/ 14 | /** */ 15 | /** LevelX Component */ 16 | /** */ 17 | /** NAND Flash */ 18 | /** */ 19 | /**************************************************************************/ 20 | /**************************************************************************/ 21 | 22 | #define LX_SOURCE_CODE 23 | 24 | 25 | /* Disable ThreadX error checking. */ 26 | 27 | #ifndef LX_DISABLE_ERROR_CHECKING 28 | #define LX_DISABLE_ERROR_CHECKING 29 | #endif 30 | 31 | 32 | /* Include necessary system files. */ 33 | 34 | #include "lx_api.h" 35 | 36 | 37 | /**************************************************************************/ 38 | /* */ 39 | /* FUNCTION RELEASE */ 40 | /* */ 41 | /* _lx_nand_flash_mapped_block_list_remove PORTABLE C */ 42 | /* 6.2.1 */ 43 | /* AUTHOR */ 44 | /* */ 45 | /* Xiuwen Cai, Microsoft Corporation */ 46 | /* */ 47 | /* DESCRIPTION */ 48 | /* */ 49 | /* This function removes mapped block from list. */ 50 | /* */ 51 | /* INPUT */ 52 | /* */ 53 | /* nand_flash NAND flash instance */ 54 | /* block_mapping_index Block mapping index */ 55 | /* */ 56 | /* OUTPUT */ 57 | /* */ 58 | /* return status */ 59 | /* */ 60 | /* CALLS */ 61 | /* */ 62 | /* None */ 63 | /* */ 64 | /* CALLED BY */ 65 | /* */ 66 | /* Internal LevelX */ 67 | /* */ 68 | /* RELEASE HISTORY */ 69 | /* */ 70 | /* DATE NAME DESCRIPTION */ 71 | /* */ 72 | /* 03-08-2023 Xiuwen Cai Initial Version 6.2.1 */ 73 | /* */ 74 | /**************************************************************************/ 75 | UINT _lx_nand_flash_mapped_block_list_remove(LX_NAND_FLASH* nand_flash, ULONG block_mapping_index) 76 | { 77 | 78 | ULONG search_position; 79 | 80 | 81 | /* Initialize the search pointer. */ 82 | search_position = nand_flash -> lx_nand_flash_mapped_block_list_head + 1; 83 | 84 | /* Loop to search the block in the list. */ 85 | while (search_position < nand_flash -> lx_nand_flash_block_list_size) 86 | { 87 | 88 | /* Check if there is a match in the list. */ 89 | if (nand_flash -> lx_nand_flash_block_list[search_position] == block_mapping_index) 90 | { 91 | 92 | /* Get out of the loop. */ 93 | break; 94 | } 95 | 96 | /* Move to next position. */ 97 | search_position++; 98 | } 99 | 100 | /* Check if the block is found. */ 101 | if (search_position < nand_flash -> lx_nand_flash_block_list_size) 102 | { 103 | 104 | /* Remove one item from the list. */ 105 | nand_flash -> lx_nand_flash_mapped_block_list_head++; 106 | 107 | /* Loop to move items in the list. */ 108 | while (search_position > nand_flash -> lx_nand_flash_mapped_block_list_head) 109 | { 110 | 111 | /* Move the item in the list. */ 112 | nand_flash -> lx_nand_flash_block_list[search_position] = nand_flash -> lx_nand_flash_block_list[search_position - 1]; 113 | search_position--; 114 | } 115 | } 116 | else 117 | { 118 | 119 | /* Return error. */ 120 | return(LX_NO_BLOCKS); 121 | } 122 | 123 | /* Return successful completion. */ 124 | return(LX_SUCCESS); 125 | } 126 | 127 | -------------------------------------------------------------------------------- /common/src/lx_nand_flash_page_ecc_check.c: -------------------------------------------------------------------------------- 1 | /*************************************************************************** 2 | * Copyright (c) 2024 Microsoft Corporation 3 | * 4 | * This program and the accompanying materials are made available under the 5 | * terms of the MIT License which is available at 6 | * https://opensource.org/licenses/MIT. 7 | * 8 | * SPDX-License-Identifier: MIT 9 | **************************************************************************/ 10 | 11 | 12 | /**************************************************************************/ 13 | /**************************************************************************/ 14 | /** */ 15 | /** LevelX Component */ 16 | /** */ 17 | /** NAND Flash */ 18 | /** */ 19 | /**************************************************************************/ 20 | /**************************************************************************/ 21 | 22 | #define LX_SOURCE_CODE 23 | 24 | 25 | /* Disable ThreadX error checking. */ 26 | 27 | #ifndef LX_DISABLE_ERROR_CHECKING 28 | #define LX_DISABLE_ERROR_CHECKING 29 | #endif 30 | 31 | 32 | /* Include necessary system files. */ 33 | 34 | #include "lx_api.h" 35 | 36 | 37 | /**************************************************************************/ 38 | /* */ 39 | /* FUNCTION RELEASE */ 40 | /* */ 41 | /* _lx_nand_flash_page_ecc_check PORTABLE C */ 42 | /* 6.1.7 */ 43 | /* AUTHOR */ 44 | /* */ 45 | /* William E. Lamie, Microsoft Corporation */ 46 | /* */ 47 | /* DESCRIPTION */ 48 | /* */ 49 | /* This function checks the NAND page and ECC for errors and */ 50 | /* attempts to correct 1 bit errors. */ 51 | /* */ 52 | /* INPUT */ 53 | /* */ 54 | /* nand_flash NAND flash instance */ 55 | /* page_buffer Page buffer */ 56 | /* ecc_buffer Returned ECC buffer */ 57 | /* */ 58 | /* OUTPUT */ 59 | /* */ 60 | /* return status */ 61 | /* */ 62 | /* CALLS */ 63 | /* */ 64 | /* _lx_nand_flash_256byte_ecc_check Check 256 bytes and ECC */ 65 | /* */ 66 | /* CALLED BY */ 67 | /* */ 68 | /* NAND flash driver */ 69 | /* */ 70 | /* RELEASE HISTORY */ 71 | /* */ 72 | /* DATE NAME DESCRIPTION */ 73 | /* */ 74 | /* 05-19-2020 William E. Lamie Initial Version 6.0 */ 75 | /* 09-30-2020 William E. Lamie Modified comment(s), */ 76 | /* resulting in version 6.1 */ 77 | /* 06-02-2021 Bhupendra Naphade Modified comment(s), */ 78 | /* resulting in version 6.1.7 */ 79 | /* */ 80 | /**************************************************************************/ 81 | UINT _lx_nand_flash_page_ecc_check(LX_NAND_FLASH *nand_flash, UCHAR *page_buffer, UCHAR *ecc_buffer) 82 | { 83 | 84 | UINT bytes_checked; 85 | UINT status; 86 | UINT return_status = LX_SUCCESS; 87 | 88 | 89 | /* Loop to check the entire NAND flash page. */ 90 | bytes_checked = 0; 91 | while (bytes_checked < nand_flash -> lx_nand_flash_bytes_per_page) 92 | { 93 | 94 | /* Check this 256 byte piece of the NAND page. */ 95 | status = _lx_nand_flash_256byte_ecc_check(page_buffer, ecc_buffer); 96 | 97 | /* Determine if there was an error. */ 98 | if (status != LX_SUCCESS) 99 | { 100 | 101 | /* Determine if a non-correctable error is present. */ 102 | if (status == LX_NAND_ERROR_NOT_CORRECTED) 103 | { 104 | 105 | /* Always return a non-correctable error, if present. */ 106 | return_status = LX_NAND_ERROR_NOT_CORRECTED; 107 | break; 108 | } 109 | 110 | /* A single-bit error was corrected, return this status 111 | if there is no LX_ERROR status already detected. */ 112 | else if (return_status == LX_SUCCESS) 113 | { 114 | 115 | /* Return a notice that the single bit error was corrected. */ 116 | return_status = LX_NAND_ERROR_CORRECTED; 117 | } 118 | } 119 | 120 | /* Move to the next 256 byte portion of the page. */ 121 | bytes_checked = bytes_checked + 256; 122 | 123 | /* Move the page buffer forward. */ 124 | page_buffer = page_buffer + 256; 125 | 126 | /* Move the ECC buffer forward, note there are 3 bytes of ECC per page. */ 127 | ecc_buffer = ecc_buffer + 3; 128 | } 129 | 130 | /* Return status. */ 131 | return(return_status); 132 | } 133 | 134 | -------------------------------------------------------------------------------- /common/src/lx_nand_flash_page_ecc_compute.c: -------------------------------------------------------------------------------- 1 | /*************************************************************************** 2 | * Copyright (c) 2024 Microsoft Corporation 3 | * 4 | * This program and the accompanying materials are made available under the 5 | * terms of the MIT License which is available at 6 | * https://opensource.org/licenses/MIT. 7 | * 8 | * SPDX-License-Identifier: MIT 9 | **************************************************************************/ 10 | 11 | 12 | /**************************************************************************/ 13 | /**************************************************************************/ 14 | /** */ 15 | /** LevelX Component */ 16 | /** */ 17 | /** NAND Flash */ 18 | /** */ 19 | /**************************************************************************/ 20 | /**************************************************************************/ 21 | 22 | #define LX_SOURCE_CODE 23 | 24 | 25 | /* Disable ThreadX error checking. */ 26 | 27 | #ifndef LX_DISABLE_ERROR_CHECKING 28 | #define LX_DISABLE_ERROR_CHECKING 29 | #endif 30 | 31 | 32 | /* Include necessary system files. */ 33 | 34 | #include "lx_api.h" 35 | 36 | 37 | /**************************************************************************/ 38 | /* */ 39 | /* FUNCTION RELEASE */ 40 | /* */ 41 | /* _lx_nand_flash_page_ecc_compute PORTABLE C */ 42 | /* 6.1.7 */ 43 | /* AUTHOR */ 44 | /* */ 45 | /* William E. Lamie, Microsoft Corporation */ 46 | /* */ 47 | /* DESCRIPTION */ 48 | /* */ 49 | /* This function computes the ECC for a NAND flash page. */ 50 | /* */ 51 | /* INPUT */ 52 | /* */ 53 | /* nand_flash NAND flash instance */ 54 | /* page_buffer Page buffer */ 55 | /* ecc_buffer Returned ECC buffer */ 56 | /* */ 57 | /* OUTPUT */ 58 | /* */ 59 | /* return status */ 60 | /* */ 61 | /* CALLS */ 62 | /* */ 63 | /* _lx_nand_flash_256byte_ecc_compute Compute ECC for 256 bytes */ 64 | /* */ 65 | /* CALLED BY */ 66 | /* */ 67 | /* NAND flash driver */ 68 | /* */ 69 | /* RELEASE HISTORY */ 70 | /* */ 71 | /* DATE NAME DESCRIPTION */ 72 | /* */ 73 | /* 05-19-2020 William E. Lamie Initial Version 6.0 */ 74 | /* 09-30-2020 William E. Lamie Modified comment(s), */ 75 | /* resulting in version 6.1 */ 76 | /* 06-02-2021 Bhupendra Naphade Modified comment(s), */ 77 | /* resulting in version 6.1.7 */ 78 | /* */ 79 | /**************************************************************************/ 80 | UINT _lx_nand_flash_page_ecc_compute(LX_NAND_FLASH *nand_flash, UCHAR *page_buffer, UCHAR *ecc_buffer) 81 | { 82 | 83 | UINT bytes_computed; 84 | 85 | 86 | /* Loop to compute the ECC over the entire NAND flash page. */ 87 | bytes_computed = 0; 88 | while (bytes_computed < nand_flash -> lx_nand_flash_bytes_per_page) 89 | { 90 | 91 | /* Compute the ECC for this 256 byte piece of the page. */ 92 | _lx_nand_flash_256byte_ecc_compute(page_buffer, ecc_buffer); 93 | 94 | /* Move to the next 256 byte portion of the page. */ 95 | bytes_computed = bytes_computed + 256; 96 | 97 | /* Move the page buffer forward. */ 98 | page_buffer = page_buffer + 256; 99 | 100 | /* Move the ECC buffer forward, note there are 3 bytes of ECC per page. */ 101 | ecc_buffer = ecc_buffer + 3; 102 | } 103 | 104 | /* Return success. */ 105 | return(LX_SUCCESS); 106 | } 107 | 108 | -------------------------------------------------------------------------------- /common/src/lx_nand_flash_partial_defragment.c: -------------------------------------------------------------------------------- 1 | /*************************************************************************** 2 | * Copyright (c) 2024 Microsoft Corporation 3 | * 4 | * This program and the accompanying materials are made available under the 5 | * terms of the MIT License which is available at 6 | * https://opensource.org/licenses/MIT. 7 | * 8 | * SPDX-License-Identifier: MIT 9 | **************************************************************************/ 10 | 11 | 12 | /**************************************************************************/ 13 | /**************************************************************************/ 14 | /** */ 15 | /** LevelX Component */ 16 | /** */ 17 | /** NAND Flash */ 18 | /** */ 19 | /**************************************************************************/ 20 | /**************************************************************************/ 21 | 22 | #define LX_SOURCE_CODE 23 | 24 | 25 | /* Disable ThreadX error checking. */ 26 | 27 | #ifndef LX_DISABLE_ERROR_CHECKING 28 | #define LX_DISABLE_ERROR_CHECKING 29 | #endif 30 | 31 | 32 | /* Include necessary system files. */ 33 | 34 | #include "lx_api.h" 35 | 36 | 37 | /**************************************************************************/ 38 | /* */ 39 | /* FUNCTION RELEASE */ 40 | /* */ 41 | /* _lx_nand_flash_partial_defragment PORTABLE C */ 42 | /* 6.2.1 */ 43 | /* AUTHOR */ 44 | /* */ 45 | /* William E. Lamie, Microsoft Corporation */ 46 | /* */ 47 | /* DESCRIPTION */ 48 | /* */ 49 | /* This function defragments the NAND flash up to the specified */ 50 | /* number of blocks. */ 51 | /* */ 52 | /* INPUT */ 53 | /* */ 54 | /* nand_flash NAND flash instance */ 55 | /* max_blocks Maximum number of blocks to */ 56 | /* defragment */ 57 | /* */ 58 | /* OUTPUT */ 59 | /* */ 60 | /* return status */ 61 | /* */ 62 | /* CALLS */ 63 | /* */ 64 | /* None */ 65 | /* */ 66 | /* CALLED BY */ 67 | /* */ 68 | /* Application Code */ 69 | /* Internal LevelX */ 70 | /* */ 71 | /* RELEASE HISTORY */ 72 | /* */ 73 | /* DATE NAME DESCRIPTION */ 74 | /* */ 75 | /* 05-19-2020 William E. Lamie Initial Version 6.0 */ 76 | /* 09-30-2020 William E. Lamie Modified comment(s), */ 77 | /* resulting in version 6.1 */ 78 | /* 06-02-2021 Bhupendra Naphade Modified comment(s), */ 79 | /* resulting in version 6.1.7 */ 80 | /* 03-08-2023 Xiuwen Cai Modified comment(s), */ 81 | /* deprecated this API, */ 82 | /* resulting in version 6.2.1 */ 83 | /* */ 84 | /**************************************************************************/ 85 | UINT _lx_nand_flash_partial_defragment(LX_NAND_FLASH *nand_flash, UINT max_blocks) 86 | { 87 | 88 | LX_PARAMETER_NOT_USED(nand_flash); 89 | LX_PARAMETER_NOT_USED(max_blocks); 90 | 91 | /* Return not supported. */ 92 | return(LX_NOT_SUPPORTED); 93 | } 94 | 95 | 96 | -------------------------------------------------------------------------------- /common/src/lx_nand_flash_sectors_read.c: -------------------------------------------------------------------------------- 1 | /*************************************************************************** 2 | * Copyright (c) 2024 Microsoft Corporation 3 | * 4 | * This program and the accompanying materials are made available under the 5 | * terms of the MIT License which is available at 6 | * https://opensource.org/licenses/MIT. 7 | * 8 | * SPDX-License-Identifier: MIT 9 | **************************************************************************/ 10 | 11 | 12 | /**************************************************************************/ 13 | /**************************************************************************/ 14 | /** */ 15 | /** LevelX Component */ 16 | /** */ 17 | /** NAND Flash */ 18 | /** */ 19 | /**************************************************************************/ 20 | /**************************************************************************/ 21 | 22 | #define LX_SOURCE_CODE 23 | 24 | 25 | /* Disable ThreadX error checking. */ 26 | 27 | #ifndef LX_DISABLE_ERROR_CHECKING 28 | #define LX_DISABLE_ERROR_CHECKING 29 | #endif 30 | 31 | 32 | /* Include necessary system files. */ 33 | 34 | #include "lx_api.h" 35 | 36 | 37 | /**************************************************************************/ 38 | /* */ 39 | /* FUNCTION RELEASE */ 40 | /* */ 41 | /* _lx_nand_flash_sectors_read PORTABLE C */ 42 | /* 6.2.1 */ 43 | /* AUTHOR */ 44 | /* */ 45 | /* Xiuwen Cai, Microsoft Corporation */ 46 | /* */ 47 | /* DESCRIPTION */ 48 | /* */ 49 | /* This function reads multiple logical sectors from NAND flash. */ 50 | /* */ 51 | /* INPUT */ 52 | /* */ 53 | /* nand_flash NAND flash instance */ 54 | /* logical_sector Logical sector number */ 55 | /* buffer Pointer to buffer to read into*/ 56 | /* (the size is number of */ 57 | /* bytes in a page) */ 58 | /* sector_count Number of sector to read */ 59 | /* */ 60 | /* OUTPUT */ 61 | /* */ 62 | /* return status */ 63 | /* */ 64 | /* CALLS */ 65 | /* */ 66 | /* _lx_nand_flash_sector_read Read a sector */ 67 | /* */ 68 | /* CALLED BY */ 69 | /* */ 70 | /* Application Code */ 71 | /* */ 72 | /* RELEASE HISTORY */ 73 | /* */ 74 | /* DATE NAME DESCRIPTION */ 75 | /* */ 76 | /* 03-08-2023 Xiuwen Cai Initial Version 6.2.1 */ 77 | /* */ 78 | /**************************************************************************/ 79 | UINT _lx_nand_flash_sectors_read(LX_NAND_FLASH *nand_flash, ULONG logical_sector, VOID *buffer, ULONG sector_count) 80 | { 81 | 82 | UINT status = LX_SUCCESS; 83 | UINT i; 84 | 85 | 86 | /* Loop to read all the sectors. */ 87 | for (i = 0; i < sector_count; i++) 88 | { 89 | 90 | /* Read one sector. */ 91 | status = _lx_nand_flash_sector_read(nand_flash, logical_sector + i, ((UCHAR*)buffer) + i * nand_flash -> lx_nand_flash_bytes_per_page); 92 | 93 | /* Check return status. */ 94 | if (status) 95 | { 96 | 97 | /* Error, break the loop. */ 98 | break; 99 | } 100 | } 101 | 102 | /* Return status. */ 103 | return(status); 104 | } 105 | 106 | -------------------------------------------------------------------------------- /common/src/lx_nand_flash_sectors_release.c: -------------------------------------------------------------------------------- 1 | /*************************************************************************** 2 | * Copyright (c) 2024 Microsoft Corporation 3 | * 4 | * This program and the accompanying materials are made available under the 5 | * terms of the MIT License which is available at 6 | * https://opensource.org/licenses/MIT. 7 | * 8 | * SPDX-License-Identifier: MIT 9 | **************************************************************************/ 10 | 11 | 12 | /**************************************************************************/ 13 | /**************************************************************************/ 14 | /** */ 15 | /** LevelX Component */ 16 | /** */ 17 | /** NAND Flash */ 18 | /** */ 19 | /**************************************************************************/ 20 | /**************************************************************************/ 21 | 22 | #define LX_SOURCE_CODE 23 | 24 | 25 | /* Disable ThreadX error checking. */ 26 | 27 | #ifndef LX_DISABLE_ERROR_CHECKING 28 | #define LX_DISABLE_ERROR_CHECKING 29 | #endif 30 | 31 | 32 | /* Include necessary system files. */ 33 | 34 | #include "lx_api.h" 35 | 36 | 37 | /**************************************************************************/ 38 | /* */ 39 | /* FUNCTION RELEASE */ 40 | /* */ 41 | /* _lx_nand_flash_sectors_release PORTABLE C */ 42 | /* 6.2.1 */ 43 | /* AUTHOR */ 44 | /* */ 45 | /* Xiuwen Cai, Microsoft Corporation */ 46 | /* */ 47 | /* DESCRIPTION */ 48 | /* */ 49 | /* This function releases multiple logical sectors from being managed */ 50 | /* in the NAND flash. */ 51 | /* */ 52 | /* INPUT */ 53 | /* */ 54 | /* nand_flash NAND flash instance */ 55 | /* logical_sector Logical sector number */ 56 | /* sector_count Number of sector to release */ 57 | /* */ 58 | /* OUTPUT */ 59 | /* */ 60 | /* return status */ 61 | /* */ 62 | /* CALLS */ 63 | /* */ 64 | /* _lx_nand_flash_sector_release Release one sector */ 65 | /* */ 66 | /* CALLED BY */ 67 | /* */ 68 | /* Application Code */ 69 | /* */ 70 | /* RELEASE HISTORY */ 71 | /* */ 72 | /* DATE NAME DESCRIPTION */ 73 | /* */ 74 | /* 03-08-2023 Xiuwen Cai Initial Version 6.2.1 */ 75 | /* */ 76 | /**************************************************************************/ 77 | UINT _lx_nand_flash_sectors_release(LX_NAND_FLASH *nand_flash, ULONG logical_sector, ULONG sector_count) 78 | { 79 | 80 | UINT status = LX_SUCCESS; 81 | UINT i; 82 | 83 | 84 | /* Loop to release all the sectors. */ 85 | for (i = 0; i < sector_count; i++) 86 | { 87 | 88 | /* Release one sector. */ 89 | status = _lx_nand_flash_sector_release(nand_flash, logical_sector + i); 90 | 91 | /* Check return status. */ 92 | if (status) 93 | { 94 | 95 | /* Error, break the loop. */ 96 | break; 97 | } 98 | } 99 | 100 | /* Return status. */ 101 | return(status); 102 | } 103 | 104 | -------------------------------------------------------------------------------- /common/src/lx_nand_flash_sectors_write.c: -------------------------------------------------------------------------------- 1 | /*************************************************************************** 2 | * Copyright (c) 2024 Microsoft Corporation 3 | * 4 | * This program and the accompanying materials are made available under the 5 | * terms of the MIT License which is available at 6 | * https://opensource.org/licenses/MIT. 7 | * 8 | * SPDX-License-Identifier: MIT 9 | **************************************************************************/ 10 | 11 | 12 | /**************************************************************************/ 13 | /**************************************************************************/ 14 | /** */ 15 | /** LevelX Component */ 16 | /** */ 17 | /** NAND Flash */ 18 | /** */ 19 | /**************************************************************************/ 20 | /**************************************************************************/ 21 | 22 | #define LX_SOURCE_CODE 23 | 24 | 25 | /* Disable ThreadX error checking. */ 26 | 27 | #ifndef LX_DISABLE_ERROR_CHECKING 28 | #define LX_DISABLE_ERROR_CHECKING 29 | #endif 30 | 31 | 32 | /* Include necessary system files. */ 33 | 34 | #include "lx_api.h" 35 | 36 | 37 | /**************************************************************************/ 38 | /* */ 39 | /* FUNCTION RELEASE */ 40 | /* */ 41 | /* _lx_nand_flash_sectors_write PORTABLE C */ 42 | /* 6.2.1 */ 43 | /* AUTHOR */ 44 | /* */ 45 | /* Xiuwen Cai, Microsoft Corporation */ 46 | /* */ 47 | /* DESCRIPTION */ 48 | /* */ 49 | /* This function writes multiple logical sectors to the NAND flash. */ 50 | /* */ 51 | /* INPUT */ 52 | /* */ 53 | /* nand_flash NAND flash instance */ 54 | /* logical_sector Logical sector number */ 55 | /* buffer Pointer to buffer to write */ 56 | /* (the size is number of */ 57 | /* bytes in a page) */ 58 | /* sector_count Number of sector to write */ 59 | /* */ 60 | /* OUTPUT */ 61 | /* */ 62 | /* return status */ 63 | /* */ 64 | /* CALLS */ 65 | /* */ 66 | /* _lx_nand_flash_sector_write Write one sector */ 67 | /* */ 68 | /* CALLED BY */ 69 | /* */ 70 | /* Application Code */ 71 | /* */ 72 | /* RELEASE HISTORY */ 73 | /* */ 74 | /* DATE NAME DESCRIPTION */ 75 | /* */ 76 | /* 03-08-2023 Xiuwen Cai Initial Version 6.2.1 */ 77 | /* */ 78 | /**************************************************************************/ 79 | UINT _lx_nand_flash_sectors_write(LX_NAND_FLASH *nand_flash, ULONG logical_sector, VOID *buffer, ULONG sector_count) 80 | { 81 | 82 | UINT status = LX_SUCCESS; 83 | UINT i; 84 | 85 | 86 | /* Loop to write all the sectors. */ 87 | for (i = 0; i < sector_count; i++) 88 | { 89 | 90 | /* Write one sector. */ 91 | status = _lx_nand_flash_sector_write(nand_flash, logical_sector + i, ((UCHAR*)buffer) + i * nand_flash -> lx_nand_flash_bytes_per_page); 92 | 93 | /* Check return status. */ 94 | if (status) 95 | { 96 | 97 | /* Error, break the loop. */ 98 | break; 99 | } 100 | } 101 | 102 | /* Return status. */ 103 | return(status); 104 | } 105 | 106 | 107 | -------------------------------------------------------------------------------- /common/src/lx_nand_flash_system_error.c: -------------------------------------------------------------------------------- 1 | /*************************************************************************** 2 | * Copyright (c) 2024 Microsoft Corporation 3 | * 4 | * This program and the accompanying materials are made available under the 5 | * terms of the MIT License which is available at 6 | * https://opensource.org/licenses/MIT. 7 | * 8 | * SPDX-License-Identifier: MIT 9 | **************************************************************************/ 10 | 11 | 12 | /**************************************************************************/ 13 | /**************************************************************************/ 14 | /** */ 15 | /** LevelX Component */ 16 | /** */ 17 | /** NAND Flash */ 18 | /** */ 19 | /**************************************************************************/ 20 | /**************************************************************************/ 21 | 22 | #define LX_SOURCE_CODE 23 | 24 | 25 | /* Disable ThreadX error checking. */ 26 | 27 | #ifndef LX_DISABLE_ERROR_CHECKING 28 | #define LX_DISABLE_ERROR_CHECKING 29 | #endif 30 | 31 | 32 | /* Include necessary system files. */ 33 | 34 | #include "lx_api.h" 35 | 36 | 37 | /**************************************************************************/ 38 | /* */ 39 | /* FUNCTION RELEASE */ 40 | /* */ 41 | /* _lx_nand_flash_system_error PORTABLE C */ 42 | /* 6.2.1 */ 43 | /* AUTHOR */ 44 | /* */ 45 | /* William E. Lamie, Microsoft Corporation */ 46 | /* */ 47 | /* DESCRIPTION */ 48 | /* */ 49 | /* This function handles system errors in the NAND flash. */ 50 | /* */ 51 | /* INPUT */ 52 | /* */ 53 | /* nand_flash NAND flash instance */ 54 | /* error_code System error code */ 55 | /* block Block where error occurred */ 56 | /* page Page where error occurred */ 57 | /* */ 58 | /* OUTPUT */ 59 | /* */ 60 | /* None */ 61 | /* */ 62 | /* CALLS */ 63 | /* */ 64 | /* (lx_nand_flash_driver_system_error) Driver system error handler */ 65 | /* */ 66 | /* CALLED BY */ 67 | /* */ 68 | /* Internal LevelX */ 69 | /* */ 70 | /* RELEASE HISTORY */ 71 | /* */ 72 | /* DATE NAME DESCRIPTION */ 73 | /* */ 74 | /* 05-19-2020 William E. Lamie Initial Version 6.0 */ 75 | /* 09-30-2020 William E. Lamie Modified comment(s), */ 76 | /* resulting in version 6.1 */ 77 | /* 06-02-2021 Bhupendra Naphade Modified comment(s), */ 78 | /* resulting in version 6.1.7 */ 79 | /* 03-08-2023 Xiuwen Cai Modified comment(s), */ 80 | /* added new driver interface, */ 81 | /* resulting in version 6.2.1 */ 82 | /* */ 83 | /**************************************************************************/ 84 | VOID _lx_nand_flash_system_error(LX_NAND_FLASH *nand_flash, UINT error_code, ULONG block, ULONG page) 85 | { 86 | 87 | /* Increment the system error counter. */ 88 | nand_flash -> lx_nand_flash_diagnostic_system_errors++; 89 | 90 | /* Save the most recent system error code. */ 91 | nand_flash -> lx_nand_flash_diagnostic_system_error = error_code; 92 | 93 | /* Determine if the system error is a NAND page corrected error. */ 94 | if (error_code == LX_NAND_ERROR_CORRECTED) 95 | { 96 | 97 | /* Yes, increment error correction information. */ 98 | nand_flash -> lx_nand_flash_page_corrections++; 99 | 100 | /* Remember the last block/page of corrected error. */ 101 | nand_flash -> lx_nand_flash_last_block_correction = block; 102 | nand_flash -> lx_nand_flash_last_page_correction = page; 103 | } 104 | 105 | /* Determine if the driver has setup a system error handler. */ 106 | if (nand_flash -> lx_nand_flash_driver_system_error) 107 | { 108 | 109 | /* Yes, call the driver's system error handler. */ 110 | #ifdef LX_NAND_ENABLE_CONTROL_BLOCK_FOR_DRIVER_INTERFACE 111 | (nand_flash -> lx_nand_flash_driver_system_error)(nand_flash, error_code, block, page); 112 | #else 113 | (nand_flash -> lx_nand_flash_driver_system_error)(error_code, block, page); 114 | #endif 115 | } 116 | } 117 | 118 | -------------------------------------------------------------------------------- /common/src/lx_nor_flash_close.c: -------------------------------------------------------------------------------- 1 | /*************************************************************************** 2 | * Copyright (c) 2024 Microsoft Corporation 3 | * 4 | * This program and the accompanying materials are made available under the 5 | * terms of the MIT License which is available at 6 | * https://opensource.org/licenses/MIT. 7 | * 8 | * SPDX-License-Identifier: MIT 9 | **************************************************************************/ 10 | 11 | 12 | /**************************************************************************/ 13 | /**************************************************************************/ 14 | /** */ 15 | /** LevelX Component */ 16 | /** */ 17 | /** NOR Flash */ 18 | /** */ 19 | /**************************************************************************/ 20 | /**************************************************************************/ 21 | 22 | #define LX_SOURCE_CODE 23 | 24 | 25 | /* Disable ThreadX error checking. */ 26 | 27 | #ifndef LX_DISABLE_ERROR_CHECKING 28 | #define LX_DISABLE_ERROR_CHECKING 29 | #endif 30 | 31 | 32 | /* Include necessary system files. */ 33 | 34 | #include "lx_api.h" 35 | 36 | 37 | /**************************************************************************/ 38 | /* */ 39 | /* FUNCTION RELEASE */ 40 | /* */ 41 | /* _lx_nor_flash_close PORTABLE C */ 42 | /* 6.1.7 */ 43 | /* AUTHOR */ 44 | /* */ 45 | /* William E. Lamie, Microsoft Corporation */ 46 | /* */ 47 | /* DESCRIPTION */ 48 | /* */ 49 | /* This function closes a NOR flash instance. */ 50 | /* */ 51 | /* INPUT */ 52 | /* */ 53 | /* nor_flash NOR flash instance */ 54 | /* */ 55 | /* OUTPUT */ 56 | /* */ 57 | /* return status */ 58 | /* */ 59 | /* CALLS */ 60 | /* */ 61 | /* tx_mutex_delete Delete thread-safe mutex */ 62 | /* */ 63 | /* CALLED BY */ 64 | /* */ 65 | /* Application Code */ 66 | /* */ 67 | /* RELEASE HISTORY */ 68 | /* */ 69 | /* DATE NAME DESCRIPTION */ 70 | /* */ 71 | /* 05-19-2020 William E. Lamie Initial Version 6.0 */ 72 | /* 09-30-2020 William E. Lamie Modified comment(s), */ 73 | /* resulting in version 6.1 */ 74 | /* 06-02-2021 Bhupendra Naphade Modified comment(s), */ 75 | /* resulting in version 6.1.7 */ 76 | /* */ 77 | /**************************************************************************/ 78 | UINT _lx_nor_flash_close(LX_NOR_FLASH *nor_flash) 79 | { 80 | 81 | LX_INTERRUPT_SAVE_AREA 82 | 83 | 84 | /* Lockout interrupts for NOR flash close. */ 85 | LX_DISABLE 86 | 87 | /* See if the media is the only one on the media opened list. */ 88 | if ((_lx_nor_flash_opened_ptr == nor_flash) && 89 | (_lx_nor_flash_opened_ptr == nor_flash -> lx_nor_flash_open_next) && 90 | (_lx_nor_flash_opened_ptr == nor_flash -> lx_nor_flash_open_previous)) 91 | { 92 | 93 | /* Only opened NOR flash, just set the opened list to NULL. */ 94 | _lx_nor_flash_opened_ptr = LX_NULL; 95 | } 96 | else 97 | { 98 | 99 | /* Otherwise, not the only opened NOR flash, link-up the neighbors. */ 100 | (nor_flash -> lx_nor_flash_open_next) -> lx_nor_flash_open_previous = 101 | nor_flash -> lx_nor_flash_open_previous; 102 | (nor_flash -> lx_nor_flash_open_previous) -> lx_nor_flash_open_next = 103 | nor_flash -> lx_nor_flash_open_next; 104 | 105 | /* See if we have to update the opened list head pointer. */ 106 | if (_lx_nor_flash_opened_ptr == nor_flash) 107 | { 108 | 109 | /* Yes, move the head pointer to the next opened NOR flash. */ 110 | _lx_nor_flash_opened_ptr = nor_flash -> lx_nor_flash_open_next; 111 | } 112 | } 113 | 114 | /* Decrement the opened NOR flash counter. */ 115 | _lx_nor_flash_opened_count--; 116 | 117 | /* Finally, indicate that this NOR flash is closed. */ 118 | nor_flash -> lx_nor_flash_state = LX_NOR_FLASH_CLOSED; 119 | 120 | /* Restore interrupt posture. */ 121 | LX_RESTORE 122 | 123 | #ifdef LX_THREAD_SAFE_ENABLE 124 | 125 | /* Delete the thread safe mutex. */ 126 | tx_mutex_delete(&nor_flash -> lx_nor_flash_mutex); 127 | #endif 128 | /* Return success. */ 129 | return(LX_SUCCESS); 130 | } 131 | 132 | 133 | -------------------------------------------------------------------------------- /common/src/lx_nor_flash_defragment.c: -------------------------------------------------------------------------------- 1 | /*************************************************************************** 2 | * Copyright (c) 2024 Microsoft Corporation 3 | * 4 | * This program and the accompanying materials are made available under the 5 | * terms of the MIT License which is available at 6 | * https://opensource.org/licenses/MIT. 7 | * 8 | * SPDX-License-Identifier: MIT 9 | **************************************************************************/ 10 | 11 | 12 | /**************************************************************************/ 13 | /**************************************************************************/ 14 | /** */ 15 | /** LevelX Component */ 16 | /** */ 17 | /** NOR Flash */ 18 | /** */ 19 | /**************************************************************************/ 20 | /**************************************************************************/ 21 | 22 | #define LX_SOURCE_CODE 23 | 24 | 25 | /* Disable ThreadX error checking. */ 26 | 27 | #ifndef LX_DISABLE_ERROR_CHECKING 28 | #define LX_DISABLE_ERROR_CHECKING 29 | #endif 30 | 31 | 32 | /* Include necessary system files. */ 33 | 34 | #include "lx_api.h" 35 | 36 | 37 | /**************************************************************************/ 38 | /* */ 39 | /* FUNCTION RELEASE */ 40 | /* */ 41 | /* _lx_nor_flash_defragment PORTABLE C */ 42 | /* 6.1.7 */ 43 | /* AUTHOR */ 44 | /* */ 45 | /* William E. Lamie, Microsoft Corporation */ 46 | /* */ 47 | /* DESCRIPTION */ 48 | /* */ 49 | /* This function defragments the NOR flash. */ 50 | /* */ 51 | /* INPUT */ 52 | /* */ 53 | /* nor_flash NOR flash instance */ 54 | /* */ 55 | /* OUTPUT */ 56 | /* */ 57 | /* return status */ 58 | /* */ 59 | /* CALLS */ 60 | /* */ 61 | /* _lx_nor_flash_block_reclaim Reclaim a NOR flash block */ 62 | /* tx_mutex_get Get thread protection */ 63 | /* tx_mutex_put Release thread protection */ 64 | /* */ 65 | /* CALLED BY */ 66 | /* */ 67 | /* Application Code */ 68 | /* Internal LevelX */ 69 | /* */ 70 | /* RELEASE HISTORY */ 71 | /* */ 72 | /* DATE NAME DESCRIPTION */ 73 | /* */ 74 | /* 05-19-2020 William E. Lamie Initial Version 6.0 */ 75 | /* 09-30-2020 William E. Lamie Modified comment(s), */ 76 | /* resulting in version 6.1 */ 77 | /* 06-02-2021 Bhupendra Naphade Modified comment(s), */ 78 | /* resulting in version 6.1.7 */ 79 | /* */ 80 | /**************************************************************************/ 81 | UINT _lx_nor_flash_defragment(LX_NOR_FLASH *nor_flash) 82 | { 83 | 84 | ULONG i; 85 | 86 | 87 | #ifdef LX_THREAD_SAFE_ENABLE 88 | 89 | /* Obtain the thread safe mutex. */ 90 | tx_mutex_get(&nor_flash -> lx_nor_flash_mutex, TX_WAIT_FOREVER); 91 | #endif 92 | 93 | /* Loop for max number of blocks, while there are obsolete count. */ 94 | for (i = 0; i < nor_flash -> lx_nor_flash_total_blocks; i++) 95 | { 96 | 97 | /* Determine if there is any more defragment work. */ 98 | if (nor_flash -> lx_nor_flash_obsolete_physical_sectors == 0) 99 | break; 100 | 101 | /* Call the block reclaim function to defragment. */ 102 | _lx_nor_flash_block_reclaim(nor_flash); 103 | } 104 | 105 | #ifdef LX_THREAD_SAFE_ENABLE 106 | 107 | /* Release the thread safe mutex. */ 108 | tx_mutex_put(&nor_flash -> lx_nor_flash_mutex); 109 | #endif 110 | 111 | /* Return successful completion. */ 112 | return(LX_SUCCESS); 113 | } 114 | 115 | 116 | -------------------------------------------------------------------------------- /common/src/lx_nor_flash_driver_block_erase.c: -------------------------------------------------------------------------------- 1 | /*************************************************************************** 2 | * Copyright (c) 2024 Microsoft Corporation 3 | * 4 | * This program and the accompanying materials are made available under the 5 | * terms of the MIT License which is available at 6 | * https://opensource.org/licenses/MIT. 7 | * 8 | * SPDX-License-Identifier: MIT 9 | **************************************************************************/ 10 | 11 | 12 | /**************************************************************************/ 13 | /**************************************************************************/ 14 | /** */ 15 | /** LevelX Component */ 16 | /** */ 17 | /** NOR Flash */ 18 | /** */ 19 | /**************************************************************************/ 20 | /**************************************************************************/ 21 | 22 | #define LX_SOURCE_CODE 23 | 24 | 25 | /* Disable ThreadX error checking. */ 26 | 27 | #ifndef LX_DISABLE_ERROR_CHECKING 28 | #define LX_DISABLE_ERROR_CHECKING 29 | #endif 30 | 31 | 32 | /* Include necessary system files. */ 33 | 34 | #include "lx_api.h" 35 | 36 | 37 | /**************************************************************************/ 38 | /* */ 39 | /* FUNCTION RELEASE */ 40 | /* */ 41 | /* _lx_nor_flash_driver_block_erase PORTABLE C */ 42 | /* 6.2.1 */ 43 | /* AUTHOR */ 44 | /* */ 45 | /* William E. Lamie, Microsoft Corporation */ 46 | /* */ 47 | /* DESCRIPTION */ 48 | /* */ 49 | /* This function performs a NOR flash block erase. */ 50 | /* */ 51 | /* INPUT */ 52 | /* */ 53 | /* nor_flash NOR flash instance */ 54 | /* block Block number to erase */ 55 | /* erase_count Erase count for this block */ 56 | /* */ 57 | /* OUTPUT */ 58 | /* */ 59 | /* return status */ 60 | /* */ 61 | /* CALLS */ 62 | /* */ 63 | /* (lx_nor_flash_driver_block_erase) Actual driver block erase */ 64 | /* */ 65 | /* CALLED BY */ 66 | /* */ 67 | /* Application Code */ 68 | /* */ 69 | /* RELEASE HISTORY */ 70 | /* */ 71 | /* DATE NAME DESCRIPTION */ 72 | /* */ 73 | /* 05-19-2020 William E. Lamie Initial Version 6.0 */ 74 | /* 09-30-2020 William E. Lamie Modified comment(s), */ 75 | /* resulting in version 6.1 */ 76 | /* 06-02-2021 Bhupendra Naphade Modified comment(s), */ 77 | /* resulting in version 6.1.7 */ 78 | /* 03-08-2023 Xiuwen Cai Modified comment(s), */ 79 | /* added new driver interface, */ 80 | /* resulting in version 6.2.1 */ 81 | /* */ 82 | /**************************************************************************/ 83 | UINT _lx_nor_flash_driver_block_erase(LX_NOR_FLASH *nor_flash, ULONG block, ULONG erase_count) 84 | { 85 | 86 | UINT status; 87 | 88 | #ifndef LX_NOR_DISABLE_EXTENDED_CACHE 89 | 90 | UINT i; 91 | ULONG *block_start_address; 92 | ULONG *block_end_address; 93 | ULONG *cache_entry_start; 94 | ULONG *cache_entry_end; 95 | 96 | 97 | /* Calculate the block starting address. */ 98 | block_start_address = nor_flash -> lx_nor_flash_base_address + (block * nor_flash -> lx_nor_flash_words_per_block); 99 | block_end_address = block_start_address + nor_flash -> lx_nor_flash_words_per_block; 100 | 101 | /* Loop through the cache entries to see if there is a sector in cache. */ 102 | for (i = 0; i < nor_flash -> lx_nor_flash_extended_cache_entries; i++) 103 | { 104 | 105 | /* Search through the cache to see if this cache entry needs to be invalidated. */ 106 | 107 | /* Determine the cache entry addresses. */ 108 | cache_entry_start = nor_flash -> lx_nor_flash_extended_cache[i].lx_nor_flash_extended_cache_entry_sector_address; 109 | cache_entry_end = cache_entry_start + LX_NOR_SECTOR_SIZE; 110 | 111 | /* Determine if the flash address in in the cache entry. */ 112 | if ((cache_entry_start) && (block_start_address <= cache_entry_start) && (block_end_address > cache_entry_end)) 113 | { 114 | 115 | /* Yes, this cache entry is in the block to be erased so invalidate it. */ 116 | nor_flash -> lx_nor_flash_extended_cache[i].lx_nor_flash_extended_cache_entry_sector_address = LX_NULL; 117 | nor_flash -> lx_nor_flash_extended_cache[i].lx_nor_flash_extended_cache_entry_access_count = 0; 118 | } 119 | } 120 | #endif 121 | 122 | /* Call the actual driver block erase function. */ 123 | #ifdef LX_NOR_ENABLE_CONTROL_BLOCK_FOR_DRIVER_INTERFACE 124 | status = (nor_flash -> lx_nor_flash_driver_block_erase)(nor_flash, block, erase_count); 125 | #else 126 | status = (nor_flash -> lx_nor_flash_driver_block_erase)(block, erase_count); 127 | #endif 128 | 129 | /* Return completion status. */ 130 | return(status); 131 | } 132 | 133 | 134 | -------------------------------------------------------------------------------- /common/src/lx_nor_flash_initialize.c: -------------------------------------------------------------------------------- 1 | /*************************************************************************** 2 | * Copyright (c) 2024 Microsoft Corporation 3 | * 4 | * This program and the accompanying materials are made available under the 5 | * terms of the MIT License which is available at 6 | * https://opensource.org/licenses/MIT. 7 | * 8 | * SPDX-License-Identifier: MIT 9 | **************************************************************************/ 10 | 11 | 12 | /**************************************************************************/ 13 | /**************************************************************************/ 14 | /** */ 15 | /** LevelX Component */ 16 | /** */ 17 | /** NOR Flash */ 18 | /** */ 19 | /**************************************************************************/ 20 | /**************************************************************************/ 21 | 22 | #define LX_SOURCE_CODE 23 | 24 | 25 | /* Include necessary system files. */ 26 | 27 | #include "lx_api.h" 28 | 29 | 30 | /* Define the NOR flash opened list head and opened count. */ 31 | 32 | LX_NOR_FLASH *_lx_nor_flash_opened_ptr; 33 | ULONG _lx_nor_flash_opened_count; 34 | 35 | 36 | /**************************************************************************/ 37 | /* */ 38 | /* FUNCTION RELEASE */ 39 | /* */ 40 | /* _lx_nor_flash_initialize PORTABLE C */ 41 | /* 6.1.7 */ 42 | /* AUTHOR */ 43 | /* */ 44 | /* William E. Lamie, Microsoft Corporation */ 45 | /* */ 46 | /* DESCRIPTION */ 47 | /* */ 48 | /* This function initializes the NOR flash data structures. */ 49 | /* */ 50 | /* INPUT */ 51 | /* */ 52 | /* None */ 53 | /* */ 54 | /* OUTPUT */ 55 | /* */ 56 | /* return status */ 57 | /* */ 58 | /* CALLS */ 59 | /* */ 60 | /* None */ 61 | /* */ 62 | /* CALLED BY */ 63 | /* */ 64 | /* Application Code */ 65 | /* */ 66 | /* RELEASE HISTORY */ 67 | /* */ 68 | /* DATE NAME DESCRIPTION */ 69 | /* */ 70 | /* 05-19-2020 William E. Lamie Initial Version 6.0 */ 71 | /* 09-30-2020 William E. Lamie Modified comment(s), */ 72 | /* resulting in version 6.1 */ 73 | /* 06-02-2021 Bhupendra Naphade Modified comment(s), */ 74 | /* resulting in version 6.1.7 */ 75 | /* */ 76 | /**************************************************************************/ 77 | UINT _lx_nor_flash_initialize(void) 78 | { 79 | 80 | /* Clear open list head pointer and opened count. */ 81 | _lx_nor_flash_opened_ptr = LX_NULL; 82 | _lx_nor_flash_opened_count = 0; 83 | 84 | /* Return success! */ 85 | return(LX_SUCCESS); 86 | } 87 | 88 | -------------------------------------------------------------------------------- /common/src/lx_nor_flash_partial_defragment.c: -------------------------------------------------------------------------------- 1 | /*************************************************************************** 2 | * Copyright (c) 2024 Microsoft Corporation 3 | * 4 | * This program and the accompanying materials are made available under the 5 | * terms of the MIT License which is available at 6 | * https://opensource.org/licenses/MIT. 7 | * 8 | * SPDX-License-Identifier: MIT 9 | **************************************************************************/ 10 | 11 | 12 | /**************************************************************************/ 13 | /**************************************************************************/ 14 | /** */ 15 | /** LevelX Component */ 16 | /** */ 17 | /** NOR Flash */ 18 | /** */ 19 | /**************************************************************************/ 20 | /**************************************************************************/ 21 | 22 | #define LX_SOURCE_CODE 23 | 24 | 25 | /* Disable ThreadX error checking. */ 26 | 27 | #ifndef LX_DISABLE_ERROR_CHECKING 28 | #define LX_DISABLE_ERROR_CHECKING 29 | #endif 30 | 31 | 32 | /* Include necessary system files. */ 33 | 34 | #include "lx_api.h" 35 | 36 | 37 | /**************************************************************************/ 38 | /* */ 39 | /* FUNCTION RELEASE */ 40 | /* */ 41 | /* _lx_nor_flash_partial_defragment PORTABLE C */ 42 | /* 6.1.7 */ 43 | /* AUTHOR */ 44 | /* */ 45 | /* William E. Lamie, Microsoft Corporation */ 46 | /* */ 47 | /* DESCRIPTION */ 48 | /* */ 49 | /* This function defragments the NOR flash up to the specified */ 50 | /* number of blocks. . */ 51 | /* */ 52 | /* INPUT */ 53 | /* */ 54 | /* nor_flash NOR flash instance */ 55 | /* max_blocks Maximum number of blocks to */ 56 | /* defragment */ 57 | /* */ 58 | /* OUTPUT */ 59 | /* */ 60 | /* return status */ 61 | /* */ 62 | /* CALLS */ 63 | /* */ 64 | /* _lx_nor_flash_block_reclaim Reclaim a NOR flash block */ 65 | /* tx_mutex_get Get thread protection */ 66 | /* tx_mutex_put Release thread protection */ 67 | /* */ 68 | /* CALLED BY */ 69 | /* */ 70 | /* Application Code */ 71 | /* Internal LevelX */ 72 | /* */ 73 | /* RELEASE HISTORY */ 74 | /* */ 75 | /* DATE NAME DESCRIPTION */ 76 | /* */ 77 | /* 05-19-2020 William E. Lamie Initial Version 6.0 */ 78 | /* 09-30-2020 William E. Lamie Modified comment(s), */ 79 | /* resulting in version 6.1 */ 80 | /* 06-02-2021 Bhupendra Naphade Modified comment(s), */ 81 | /* resulting in version 6.1.7 */ 82 | /* */ 83 | /**************************************************************************/ 84 | UINT _lx_nor_flash_partial_defragment(LX_NOR_FLASH *nor_flash, UINT max_blocks) 85 | { 86 | 87 | ULONG i; 88 | 89 | 90 | #ifdef LX_THREAD_SAFE_ENABLE 91 | 92 | /* Obtain the thread safe mutex. */ 93 | tx_mutex_get(&nor_flash -> lx_nor_flash_mutex, TX_WAIT_FOREVER); 94 | #endif 95 | 96 | /* Determine if the maximum number of blocks exceeds the total blocks in this flash instance. */ 97 | if (max_blocks >= nor_flash -> lx_nor_flash_total_blocks) 98 | { 99 | 100 | /* Adjust the maximum to the total number of blocks. */ 101 | max_blocks = nor_flash -> lx_nor_flash_total_blocks; 102 | } 103 | 104 | /* Loop for max number of blocks, while there are obsolete count. */ 105 | for (i = 0; i < max_blocks; i++) 106 | { 107 | 108 | /* Determine if there is any more defragment work. */ 109 | if (nor_flash -> lx_nor_flash_obsolete_physical_sectors == 0) 110 | break; 111 | 112 | /* Call the block reclaim function to defragment. */ 113 | _lx_nor_flash_block_reclaim(nor_flash); 114 | } 115 | 116 | #ifdef LX_THREAD_SAFE_ENABLE 117 | 118 | /* Release the thread safe mutex. */ 119 | tx_mutex_put(&nor_flash -> lx_nor_flash_mutex); 120 | #endif 121 | 122 | /* Return successful completion. */ 123 | return(LX_SUCCESS); 124 | } 125 | 126 | 127 | -------------------------------------------------------------------------------- /common/src/lx_nor_flash_system_error.c: -------------------------------------------------------------------------------- 1 | /*************************************************************************** 2 | * Copyright (c) 2024 Microsoft Corporation 3 | * 4 | * This program and the accompanying materials are made available under the 5 | * terms of the MIT License which is available at 6 | * https://opensource.org/licenses/MIT. 7 | * 8 | * SPDX-License-Identifier: MIT 9 | **************************************************************************/ 10 | 11 | 12 | /**************************************************************************/ 13 | /**************************************************************************/ 14 | /** */ 15 | /** LevelX Component */ 16 | /** */ 17 | /** NOR Flash */ 18 | /** */ 19 | /**************************************************************************/ 20 | /**************************************************************************/ 21 | 22 | #define LX_SOURCE_CODE 23 | 24 | 25 | /* Disable ThreadX error checking. */ 26 | 27 | #ifndef LX_DISABLE_ERROR_CHECKING 28 | #define LX_DISABLE_ERROR_CHECKING 29 | #endif 30 | 31 | 32 | /* Include necessary system files. */ 33 | 34 | #include "lx_api.h" 35 | 36 | 37 | /**************************************************************************/ 38 | /* */ 39 | /* FUNCTION RELEASE */ 40 | /* */ 41 | /* _lx_nor_flash_system_error PORTABLE C */ 42 | /* 6.2.1 */ 43 | /* AUTHOR */ 44 | /* */ 45 | /* William E. Lamie, Microsoft Corporation */ 46 | /* */ 47 | /* DESCRIPTION */ 48 | /* */ 49 | /* This function handles system errors in the NOR flash. */ 50 | /* */ 51 | /* INPUT */ 52 | /* */ 53 | /* nor_flash NOR flash instance */ 54 | /* error_code System error code */ 55 | /* */ 56 | /* OUTPUT */ 57 | /* */ 58 | /* None */ 59 | /* */ 60 | /* CALLS */ 61 | /* */ 62 | /* (lx_nor_flash_driver_system_error) Driver system error handler */ 63 | /* */ 64 | /* CALLED BY */ 65 | /* */ 66 | /* Internal LevelX */ 67 | /* */ 68 | /* RELEASE HISTORY */ 69 | /* */ 70 | /* DATE NAME DESCRIPTION */ 71 | /* */ 72 | /* 05-19-2020 William E. Lamie Initial Version 6.0 */ 73 | /* 09-30-2020 William E. Lamie Modified comment(s), */ 74 | /* resulting in version 6.1 */ 75 | /* 06-02-2021 Bhupendra Naphade Modified comment(s), */ 76 | /* resulting in version 6.1.7 */ 77 | /* 03-08-2023 Xiuwen Cai Modified comment(s), */ 78 | /* added new driver interface, */ 79 | /* resulting in version 6.2.1 */ 80 | /* */ 81 | /**************************************************************************/ 82 | VOID _lx_nor_flash_system_error(LX_NOR_FLASH *nor_flash, UINT error_code) 83 | { 84 | 85 | /* Increment the system error counter. */ 86 | nor_flash -> lx_nor_flash_diagnostic_system_errors++; 87 | 88 | /* Save the most recent system error code. */ 89 | nor_flash -> lx_nor_flash_diagnostic_system_error = error_code; 90 | 91 | /* Determine if the driver has setup a system error handler. */ 92 | if (nor_flash -> lx_nor_flash_driver_system_error) 93 | { 94 | 95 | /* Yes, call the driver's system error handler. */ 96 | #ifdef LX_NOR_ENABLE_CONTROL_BLOCK_FOR_DRIVER_INTERFACE 97 | (nor_flash -> lx_nor_flash_driver_system_error)(nor_flash, error_code); 98 | #else 99 | (nor_flash -> lx_nor_flash_driver_system_error)(error_code); 100 | #endif 101 | } 102 | } 103 | 104 | -------------------------------------------------------------------------------- /docs/deps.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/eclipse-threadx/levelx/04e385f3d5586efdd5dffb1dd4c8ffa50317d70a/docs/deps.png -------------------------------------------------------------------------------- /samples/demo_filex_nor_flash.c: -------------------------------------------------------------------------------- 1 | /* This is a small demo of the high-performance FileX FAT file system with LevelX 2 | and the NOR simulated driver. */ 3 | 4 | #include "fx_api.h" 5 | #include "lx_api.h" 6 | 7 | 8 | #define DEMO_STACK_SIZE 2048 9 | 10 | 11 | /* Buffer for FileX FX_MEDIA sector cache. This must be large enough for at least one 12 | sector, which are typically 512 bytes in size. */ 13 | 14 | unsigned char media_memory[512]; 15 | 16 | 17 | /* Define NOR simulated device driver entry. */ 18 | 19 | VOID _fx_nor_flash_simulator_driver(FX_MEDIA *media_ptr); 20 | 21 | 22 | /* Define LevelX NOR simulated flash erase. */ 23 | 24 | UINT _lx_nor_flash_simulator_erase_all(VOID); 25 | 26 | 27 | /* Define thread prototypes. */ 28 | 29 | void thread_0_entry(ULONG thread_input); 30 | UCHAR thread_0_stack[DEMO_STACK_SIZE]; 31 | 32 | 33 | /* Define FileX global data structures. */ 34 | 35 | FX_MEDIA nor_disk; 36 | FX_FILE my_file; 37 | 38 | 39 | 40 | /* Define ThreadX global data structures. */ 41 | 42 | #ifndef LX_STANDALONE_ENABLE 43 | TX_THREAD thread_0; 44 | #endif 45 | ULONG thread_0_counter; 46 | 47 | 48 | int main(void) 49 | { 50 | /* Enter the ThreadX kernel. */ 51 | #ifndef LX_STANDALONE_ENABLE 52 | tx_kernel_enter(); 53 | #else 54 | 55 | /* Initialize NOR flash. */ 56 | lx_nor_flash_initialize(); 57 | 58 | /* Initialize FileX. */ 59 | fx_system_initialize(); 60 | 61 | thread_0_entry(0); 62 | #endif 63 | 64 | } 65 | 66 | 67 | /* Define what the initial system looks like. */ 68 | 69 | #ifndef LX_STANDALONE_ENABLE 70 | void tx_application_define(void *first_unused_memory) 71 | { 72 | 73 | /* Put system definition stuff in here, e.g. thread creates and other assorted 74 | create information. */ 75 | 76 | /* Create the main thread. */ 77 | tx_thread_create(&thread_0, "thread 0", thread_0_entry, 0, 78 | thread_0_stack, DEMO_STACK_SIZE, 79 | 1, 1, TX_NO_TIME_SLICE, TX_AUTO_START); 80 | 81 | /* Initialize NOR flash. */ 82 | lx_nor_flash_initialize(); 83 | 84 | /* Initialize FileX. */ 85 | fx_system_initialize(); 86 | } 87 | #endif 88 | 89 | 90 | 91 | void thread_0_entry(ULONG thread_input) 92 | { 93 | 94 | UINT status; 95 | ULONG actual; 96 | CHAR local_buffer[30]; 97 | 98 | LX_PARAMETER_NOT_USED(thread_input); 99 | 100 | /* Erase the simulated NOR flash. */ 101 | _lx_nor_flash_simulator_erase_all(); 102 | 103 | /* Format the NOR disk - the memory for the NOR flash disk is setup in 104 | the NOR simulator. Note that for best performance, the format of the 105 | NOR flash should be less than one full NOR flash block of sectors. */ 106 | fx_media_format(&nor_disk, 107 | _fx_nor_flash_simulator_driver, // Driver entry 108 | FX_NULL, // Unused 109 | media_memory, // Media buffer pointer 110 | sizeof(media_memory), // Media buffer size 111 | "MY_NOR_DISK", // Volume Name 112 | 1, // Number of FATs 113 | 32, // Directory Entries 114 | 0, // Hidden sectors 115 | 120, // Total sectors 116 | 512, // Sector size 117 | 1, // Sectors per cluster 118 | 1, // Heads 119 | 1); // Sectors per track 120 | 121 | /* Loop to repeat the demo over and over! */ 122 | do 123 | { 124 | 125 | /* Open the NOR disk. */ 126 | status = fx_media_open(&nor_disk, "NOR DISK", _fx_nor_flash_simulator_driver, FX_NULL, media_memory, sizeof(media_memory)); 127 | 128 | /* Check the media open status. */ 129 | if (status != FX_SUCCESS) 130 | { 131 | 132 | /* Error, break the loop! */ 133 | break; 134 | } 135 | 136 | /* Create a file called TEST.TXT in the root directory. */ 137 | status = fx_file_create(&nor_disk, "TEST.TXT"); 138 | 139 | /* Check the create status. */ 140 | if (status != FX_SUCCESS) 141 | { 142 | 143 | /* Check for an already created status. This is expected on the 144 | second pass of this loop! */ 145 | if (status != FX_ALREADY_CREATED) 146 | { 147 | 148 | /* Create error, break the loop. */ 149 | break; 150 | } 151 | } 152 | 153 | /* Open the test file. */ 154 | status = fx_file_open(&nor_disk, &my_file, "TEST.TXT", FX_OPEN_FOR_WRITE); 155 | 156 | /* Check the file open status. */ 157 | if (status != FX_SUCCESS) 158 | { 159 | 160 | /* Error opening file, break the loop. */ 161 | break; 162 | } 163 | 164 | /* Seek to the beginning of the test file. */ 165 | status = fx_file_seek(&my_file, 0); 166 | 167 | /* Check the file seek status. */ 168 | if (status != FX_SUCCESS) 169 | { 170 | 171 | /* Error performing file seek, break the loop. */ 172 | break; 173 | } 174 | 175 | /* Write a string to the test file. */ 176 | status = fx_file_write(&my_file, " ABCDEFGHIJKLMNOPQRSTUVWXYZ\n", 28); 177 | 178 | /* Check the file write status. */ 179 | if (status != FX_SUCCESS) 180 | { 181 | 182 | /* Error writing to a file, break the loop. */ 183 | break; 184 | } 185 | 186 | /* Seek to the beginning of the test file. */ 187 | status = fx_file_seek(&my_file, 0); 188 | 189 | /* Check the file seek status. */ 190 | if (status != FX_SUCCESS) 191 | { 192 | 193 | /* Error performing file seek, break the loop. */ 194 | break; 195 | } 196 | 197 | /* Read the first 28 bytes of the test file. */ 198 | status = fx_file_read(&my_file, local_buffer, 28, &actual); 199 | 200 | /* Check the file read status. */ 201 | if ((status != FX_SUCCESS) || (actual != 28)) 202 | { 203 | 204 | /* Error reading file, break the loop. */ 205 | break; 206 | } 207 | 208 | /* Close the test file. */ 209 | status = fx_file_close(&my_file); 210 | 211 | /* Check the file close status. */ 212 | if (status != FX_SUCCESS) 213 | { 214 | 215 | /* Error closing the file, break the loop. */ 216 | break; 217 | } 218 | 219 | /* Delete the file. */ 220 | status = fx_file_delete(&nor_disk, "TEST.TXT"); 221 | 222 | /* Check the file delete status. */ 223 | if (status != FX_SUCCESS) 224 | { 225 | 226 | /* Error deleting the file, break the loop. */ 227 | break; 228 | } 229 | 230 | /* Close the media. */ 231 | status = fx_media_close(&nor_disk); 232 | 233 | /* Check the media close status. */ 234 | if (status != FX_SUCCESS) 235 | { 236 | 237 | /* Error closing the media, break the loop. */ 238 | break; 239 | } 240 | 241 | /* Increment the thread counter, which represents the number 242 | of successful passes through this loop. */ 243 | thread_0_counter++; 244 | 245 | } while (1); 246 | 247 | /* If we get here the FileX test failed! */ 248 | return; 249 | } 250 | 251 | -------------------------------------------------------------------------------- /scripts/build.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | $(dirname `realpath $0`)/../test/cmake/run.sh build all -------------------------------------------------------------------------------- /scripts/install.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # 3 | 4 | # Remove large folder 5 | rm -rf /opt/hostedtoolcache 6 | 7 | # Install necessary softwares for Ubuntu. 8 | 9 | sudo apt-get update 10 | sudo apt-get install -y \ 11 | gcc-multilib \ 12 | git \ 13 | g++ \ 14 | python3-pip \ 15 | ninja-build \ 16 | unifdef \ 17 | p7zip-full \ 18 | tofrodos \ 19 | gawk \ 20 | software-properties-common 21 | 22 | wget -O - https://apt.kitware.com/keys/kitware-archive-latest.asc 2>/dev/null | sudo apt-key add - 23 | CODENAME=$(lsb_release -c | cut -f2 -d':' | sed 's/\t//') 24 | apt-add-repository "deb https://apt.kitware.com/ubuntu/ $CODENAME main" 25 | 26 | python3 -m pip install --upgrade pip 27 | pip3 install gcovr==4.1 28 | pip install --upgrade cmake -------------------------------------------------------------------------------- /scripts/test.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | $(dirname `realpath $0`)/../test/cmake/run.sh test all -------------------------------------------------------------------------------- /test/cmake/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.13 FATAL_ERROR) 2 | cmake_policy(SET CMP0054 NEW) 3 | cmake_policy(SET CMP0057 NEW) 4 | 5 | project(levelx_test LANGUAGES C) 6 | 7 | # Set build configurations 8 | set(BUILD_CONFIGURATIONS default_build_coverage 9 | free_sector_verify_build 10 | full_build 11 | standalone_build 12 | standalone_free_sector_verify_build 13 | standalone_full_build 14 | new_driver_interface_build 15 | nor_obsolete_cache_build 16 | nor_mapping_cache_build 17 | nor_obsolete_mapping_cache_build) 18 | set(CMAKE_CONFIGURATION_TYPES 19 | ${BUILD_CONFIGURATIONS} 20 | CACHE STRING "list of supported configuration types" FORCE) 21 | set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS 22 | ${CMAKE_CONFIGURATION_TYPES}) 23 | list(GET CMAKE_CONFIGURATION_TYPES 0 BUILD_TYPE) 24 | if((NOT CMAKE_BUILD_TYPE) OR (NOT ("${CMAKE_BUILD_TYPE}" IN_LIST 25 | CMAKE_CONFIGURATION_TYPES))) 26 | set(CMAKE_BUILD_TYPE 27 | "${BUILD_TYPE}" 28 | CACHE STRING "Build Type of the project" FORCE) 29 | endif() 30 | 31 | message(STATUS "Build type: ${CMAKE_BUILD_TYPE}") 32 | message(STATUS "Using toolchain file: ${CMAKE_TOOLCHAIN_FILE}.") 33 | set(FX_FAULT_TOLERANT_DEFINITIONS 34 | -DFX_ENABLE_FAULT_TOLERANT -DFX_UPDATE_FILE_SIZE_ON_ALLOCATE 35 | -DFX_FAULT_TOLERANT_TRANSACTION_FAIL_FUNCTION) 36 | set(default_build_coverage "") 37 | set(free_sector_verify_build -DLX_FREE_SECTOR_DATA_VERIFY) 38 | set(full_build -DLX_FREE_SECTOR_DATA_VERIFY 39 | -DLX_DIRECT_READ 40 | -DLX_NAND_FLASH_DIRECT_MAPPING_CACHE 41 | -DLX_NOR_DISABLE_EXTENDED_CACHE 42 | -DLX_THREAD_SAFE_ENABLE) 43 | # For Standalone builds LX_STANADLONE_ENABLE is defined in line 61 44 | set(standalone_build -DLX_STANDALONE_ENABLE) 45 | set(standalone_free_sector_verify_build -DLX_STANDALONE_ENABLE ${free_sector_verify_build}) 46 | set(standalone_full_build -DLX_STANDALONE_ENABLE ${full_build}) 47 | set(new_driver_interface_build -DLX_NOR_ENABLE_CONTROL_BLOCK_FOR_DRIVER_INTERFACE 48 | -DLX_NAND_ENABLE_CONTROL_BLOCK_FOR_DRIVER_INTERFACE) 49 | set(nor_obsolete_cache_build -DLX_NOR_ENABLE_OBSOLETE_COUNT_CACHE) 50 | set(nor_mapping_cache_build -DLX_NOR_ENABLE_MAPPING_BITMAP) 51 | set(nor_obsolete_mapping_cache_build -DLX_NOR_ENABLE_MAPPING_BITMAP 52 | -DLX_NOR_ENABLE_OBSOLETE_COUNT_CACHE) 53 | 54 | add_compile_options( 55 | -m32 56 | -std=c99 57 | -ggdb 58 | -g3 59 | -gdwarf-2 60 | -fdiagnostics-color 61 | -Werror 62 | ${${CMAKE_BUILD_TYPE}}) 63 | add_link_options(-m32) 64 | 65 | enable_testing() 66 | 67 | if(CMAKE_BUILD_TYPE MATCHES "standalone.*") 68 | set(LX_STANDALONE_ENABLE 69 | ON 70 | CACHE BOOL "LevelX standalone enabled(No Azure RTOS ThreadX)" FORCE) 71 | set(FX_STANDALONE_ENABLE 72 | ON 73 | CACHE BOOL "FileX standalone enabled(No Azure RTOS ThreadX)" FORCE) 74 | endif() 75 | 76 | add_subdirectory(${CMAKE_CURRENT_LIST_DIR}/../.. levelx) 77 | add_subdirectory(regression) 78 | add_subdirectory(samples) 79 | 80 | # Coverage 81 | if(CMAKE_BUILD_TYPE MATCHES ".*_coverage") 82 | target_compile_options(levelx PRIVATE -fprofile-arcs -ftest-coverage) 83 | target_link_options(levelx PRIVATE -fprofile-arcs -ftest-coverage) 84 | endif() 85 | 86 | 87 | # Build ThreadX library once 88 | execute_process(COMMAND ${CMAKE_CURRENT_LIST_DIR}/run.sh build_libs) 89 | add_custom_target(build_libs ALL COMMAND ${CMAKE_CURRENT_LIST_DIR}/run.sh 90 | build_libs) 91 | add_dependencies(levelx build_libs) 92 | target_include_directories(levelx PUBLIC ${CMAKE_BINARY_DIR}/../libs/inc) 93 | if(NOT LX_STANDALONE_ENABLE) 94 | add_library(threadx SHARED IMPORTED GLOBAL) 95 | add_library("azrtos::threadx" ALIAS threadx) 96 | set_target_properties( 97 | threadx PROPERTIES IMPORTED_LOCATION 98 | ${CMAKE_BINARY_DIR}/../libs/threadx/libthreadx.so) 99 | add_library(filex SHARED IMPORTED GLOBAL) 100 | add_library("azrtos::filex" ALIAS filex) 101 | set_target_properties(filex PROPERTIES IMPORTED_LOCATION 102 | ${CMAKE_BINARY_DIR}/../libs/filex/libfilex.so) 103 | else() 104 | get_filename_component( 105 | externals ${CMAKE_CURRENT_SOURCE_DIR} ABSOLUTE) 106 | add_subdirectory(${externals}/filex filex) 107 | add_library("azrtos::filex" ALIAS filex) 108 | endif() 109 | 110 | target_compile_options( 111 | levelx 112 | PRIVATE -Werror 113 | -Wall 114 | -Wextra 115 | -pedantic 116 | -fmessage-length=0 117 | -fsigned-char 118 | -ffunction-sections 119 | -fdata-sections 120 | -Wunused 121 | -Wuninitialized 122 | -Wmissing-declarations 123 | -Wconversion 124 | -Wpointer-arith 125 | -Wshadow 126 | -Wlogical-op 127 | -Waggregate-return 128 | -Wfloat-equal) 129 | -------------------------------------------------------------------------------- /test/cmake/coverage.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set -e 4 | 5 | cd $(dirname $0) 6 | mkdir -p coverage_report/$1 7 | gcovr --object-directory=build/$1/levelx/CMakeFiles/levelx.dir/common/src -r ../../common/src --xml-pretty --output coverage_report/$1.xml 8 | gcovr --object-directory=build/$1/levelx/CMakeFiles/levelx.dir/common/src -r ../../common/src --html --html-details --output coverage_report/$1/index.html 9 | -------------------------------------------------------------------------------- /test/cmake/libs/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.13 FATAL_ERROR) 2 | 3 | project(libs LANGUAGES C) 4 | 5 | if($ENV{ENABLE_64}) 6 | message(STATUS "Building for 64bit") 7 | else() 8 | add_compile_options(-m32) 9 | add_link_options(-m32) 10 | message(STATUS "Building for 32bit") 11 | endif() 12 | message(STATUS "Using toolchain file: ${CMAKE_TOOLCHAIN_FILE}.") 13 | 14 | get_filename_component( 15 | externals ${CMAKE_CURRENT_SOURCE_DIR}/.. ABSOLUTE) 16 | 17 | if(NOT LX_STANDALONE_ENABLE) 18 | add_subdirectory(${externals}/threadx threadx) 19 | endif() 20 | add_subdirectory(${externals}/filex filex) 21 | target_compile_options(threadx PRIVATE -DTX_ENABLE_EVENT_TRACE) 22 | if(NOT DEFINED ENV{ENABLE_IDLE}) 23 | target_compile_options(threadx PRIVATE -DTX_LINUX_NO_IDLE_ENABLE) 24 | endif() 25 | 26 | 27 | if((NOT LX_STANDALONE_ENABLE) OR (NOT FX_STANDALONE_ENABLE)) 28 | foreach(lib threadx filex) 29 | get_target_property(dirs ${lib} INCLUDE_DIRECTORIES) 30 | execute_process(COMMAND mkdir -p ${CMAKE_BINARY_DIR}/inc) 31 | foreach(dir ${dirs}) 32 | file(GLOB header_files ${dir}/*.h) 33 | foreach(header_file ${header_files}) 34 | execute_process(COMMAND ln -sf ${header_file} ${CMAKE_BINARY_DIR}/inc) 35 | endforeach() 36 | endforeach() 37 | endforeach() 38 | endif() 39 | -------------------------------------------------------------------------------- /test/cmake/regression/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.0.0 FATAL_ERROR) 2 | cmake_policy(SET CMP0057 NEW) 3 | 4 | project(regression_test LANGUAGES C) 5 | 6 | set(SOURCE_DIR ${CMAKE_CURRENT_LIST_DIR}/../../regression) 7 | 8 | set(regression_test_cases 9 | ${SOURCE_DIR}/levelx_nand_flash_test.c 10 | ${SOURCE_DIR}/levelx_nor_flash_test.c 11 | ${SOURCE_DIR}/levelx_nor_flash_test_cache.c) 12 | 13 | foreach(test_case ${regression_test_cases} ${regression_test_cases_exfat}) 14 | get_filename_component(test_name ${test_case} NAME_WE) 15 | add_executable(${test_name} ${test_case}) 16 | target_link_libraries(${test_name} PRIVATE azrtos::filex) 17 | target_link_libraries(${test_name} PRIVATE azrtos::levelx) 18 | target_compile_definitions(${test_name} PRIVATE BATCH_TEST) 19 | add_test(${CMAKE_BUILD_TYPE}::${test_name} ${test_name}) 20 | endforeach() 21 | -------------------------------------------------------------------------------- /test/cmake/run.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | cd $(dirname $0) 4 | 5 | # if threadx repo does not exist, clone it 6 | [ -d threadx ] || git clone https://github.com/eclipse-threadx/threadx.git --depth 1 7 | [ -d filex ] || git clone https://github.com/eclipse-threadx/filex.git --depth 1 8 | [ -f .run.sh ] || ln -sf threadx/scripts/cmake_bootstrap.sh .run.sh 9 | ./.run.sh $* -------------------------------------------------------------------------------- /test/cmake/samples/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.0.0 FATAL_ERROR) 2 | cmake_policy(SET CMP0057 NEW) 3 | 4 | project(samples LANGUAGES C) 5 | 6 | set(SOURCE_DIR ${CMAKE_CURRENT_LIST_DIR}/../../../samples) 7 | 8 | set(sample_files 9 | ${SOURCE_DIR}/demo_filex_nand_flash.c 10 | ${SOURCE_DIR}/demo_filex_nor_flash.c) 11 | 12 | foreach(sample_file ${sample_files}) 13 | get_filename_component(sample_file_name ${sample_file} NAME_WE) 14 | add_executable(${sample_file_name} ${sample_file}) 15 | target_link_libraries(${sample_file_name} PRIVATE azrtos::filex) 16 | target_link_libraries(${sample_file_name} PRIVATE azrtos::levelx) 17 | endforeach() 18 | --------------------------------------------------------------------------------