├── test ├── CMakeLists.txt └── build-combination │ ├── README.md │ ├── CMakeLists.txt │ ├── DefaultConf │ └── FreeRTOSFATConfig.h │ └── Common │ ├── main.c │ └── include │ └── FreeRTOSConfig.h ├── ReadMe.url ├── .github ├── ISSUE_TEMPLATE │ ├── config.yml │ ├── documentation-issue.md │ ├── feature-request.md │ └── bug_report.md ├── CODE_OF_CONDUCT.md ├── SECURITY.md ├── pull_request_template.md ├── CODEOWNERS ├── .cSpellWords.txt ├── workflows │ ├── ci.yml │ └── release.yml └── CONTRIBUTING.md ├── portable ├── README_DRIVER_DISCLAIMER.txt ├── Zynq │ ├── xsdps_info.h │ ├── xsdps_g.c │ ├── xsdps_sinit.c │ └── xsdps.h ├── Zynq.2019.3 │ ├── xsdps_info.h │ ├── xsdps_g.c │ └── xsdps_sinit.c ├── avr32_uc3 │ ├── ff_flush.c │ └── ff_flush.h ├── common │ ├── ff_ramdisk.h │ └── ff_sddisk.h ├── CMakeLists.txt └── linux │ └── ff_sddisk.c ├── cspell.config.yaml ├── LICENSE.md ├── include ├── ff_crc.h ├── ff_headers.h ├── ff_devices.h ├── ff_time.h ├── ff_locking.h ├── ff_format.h ├── ff_sys.h ├── ff_fatdef.h ├── FreeRTOS_errno_FAT.h ├── ff_string.h ├── ff_memory.h ├── ff_fat.h ├── ff_old_config_defines.h └── ff_file.h ├── README.md ├── History.txt ├── History2.txt ├── ff_memory.c ├── ff_dev_support.c ├── CMakeLists.txt ├── ff_sys.c └── ff_time.c /test/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_subdirectory(build-combination) 2 | -------------------------------------------------------------------------------- /ReadMe.url: -------------------------------------------------------------------------------- 1 | [{000214A0-0000-0000-C000-000000000046}] 2 | Prop3=19,2 3 | [InternetShortcut] 4 | URL=http://www.freertos.org/fat 5 | IDList= 6 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/config.yml: -------------------------------------------------------------------------------- 1 | blank_issues_enabled: false 2 | contact_links: 3 | - name: FreeRTOS Community Support Forum 4 | url: https://forums.freertos.org/ 5 | about: Please ask and answer questions about FreeRTOS-Plus-FAT here. 6 | -------------------------------------------------------------------------------- /.github/CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | ## Code of Conduct 2 | This project has adopted the [Amazon Open Source Code of Conduct](https://aws.github.io/code-of-conduct). 3 | For more information see the [Code of Conduct FAQ](https://aws.github.io/code-of-conduct-faq) or contact 4 | opensource-codeofconduct@amazon.com with any additional questions or comments. 5 | -------------------------------------------------------------------------------- /.github/SECURITY.md: -------------------------------------------------------------------------------- 1 | ## Reporting a Vulnerability 2 | 3 | If you discover a potential security issue in this project we ask that you notify AWS/Amazon Security 4 | via our [vulnerability reporting page](http://aws.amazon.com/security/vulnerability-reporting/) or directly via email to aws-security@amazon.com. 5 | Please do **NOT** create a public github issue. 6 | -------------------------------------------------------------------------------- /portable/README_DRIVER_DISCLAIMER.txt: -------------------------------------------------------------------------------- 1 | Disk drivers are provided as examples only, and do not form part of the 2 | FreeRTOS+FAT itself. They: 3 | 4 | + May be based on driver code provided by the chip vendors, 5 | + May not have been tested in all possible configurations, 6 | + Will not necessarily be optimised. 7 | + May not necessarily comply with any particular coding standard. 8 | + May have dependencies on chip company libraries. 9 | + May include other hardware board dependencies. 10 | 11 | 12 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/documentation-issue.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Documentation issue 3 | about: Create a report to help us improve our documentation. 4 | title: "[DOC] " 5 | labels: '' 6 | assignees: '' 7 | 8 | --- 9 | 10 | **Describe the issue** 11 | Please describe the issue and expected clarification in concise language. 12 | 13 | **Reference** 14 | Please attach the URL at which you are experiencing the issue. 15 | 16 | **Screenshot** 17 | If applicable, please attach screenshot. 18 | 19 | **Browser** 20 | - Browser: [e.g. Chrome] 21 | - Version: [e.g. 80.0.3987.132] 22 | 23 | 24 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/feature-request.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Feature Request 3 | about: Suggest an idea for this project 4 | title: "[Feature Request] " 5 | labels: '' 6 | assignees: '' 7 | 8 | --- 9 | 10 | **Is your feature request related to a problem? Please describe.** 11 | A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] 12 | 13 | **Describe the solution you'd like** 14 | A clear and concise description of what you want to happen. 15 | 16 | **Describe alternatives you've considered** 17 | A clear and concise description of any alternative solutions or features you've considered. 18 | 19 | **Additional context** 20 | Add any other context or screenshots about the feature request here. 21 | -------------------------------------------------------------------------------- /cspell.config.yaml: -------------------------------------------------------------------------------- 1 | --- 2 | $schema: https://raw.githubusercontent.com/streetsidesoftware/cspell/main/cspell.schema.json 3 | version: '0.2' 4 | # Allows things like stringLength 5 | allowCompoundWords: true 6 | 7 | # Read files not to spell check from the git ignore 8 | useGitignore: true 9 | 10 | # Language settings for C 11 | languageSettings: 12 | - caseSensitive: false 13 | enabled: true 14 | languageId: c 15 | locale: "*" 16 | 17 | # Add a dictionary, and the path to the word list 18 | dictionaryDefinitions: 19 | - name: freertos-words 20 | path: '.github/.cSpellWords.txt' 21 | addWords: true 22 | 23 | dictionaries: 24 | - freertos-words 25 | 26 | # Paths and files to ignore 27 | ignorePaths: 28 | - 'dependency' 29 | - 'docs' 30 | - 'ThirdParty' 31 | - 'History.txt' 32 | -------------------------------------------------------------------------------- /.github/pull_request_template.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | Description 4 | ----------- 5 | 6 | 7 | Test Steps 8 | ----------- 9 | 10 | 11 | Checklist: 12 | ---------- 13 | 14 | 15 | - [ ] I have tested my changes. No regression in existing tests. 16 | - [ ] I have modified and/or added unit-tests to cover the code changes in this Pull Request. 17 | 18 | Related Issue 19 | ----------- 20 | 21 | 22 | By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice. 23 | -------------------------------------------------------------------------------- /test/build-combination/README.md: -------------------------------------------------------------------------------- 1 | # Build Instructions 2 | 3 | This test aims at finding only compilation issues and as a result, the 4 | generated binary is not runnable. 5 | 6 | ## UNIX (Linux and Mac) 7 | 8 | All the CMake commands are to be run from the root of the repository. 9 | 10 | * Build checks (Default configuration) 11 | ``` 12 | cmake -S . -B build -DFREERTOS_PLUS_FAT_TEST_CONFIGURATION=DEFAULT_CONF 13 | make -C . 14 | ``` 15 | 16 | ## Windows 17 | 18 | All the CMake commands are to be run from the root of the repository. 19 | 20 | * Build checks (Default configuration) 21 | ``` 22 | cmake -S . -B build -DFREERTOS_PLUS_FAT_TEST_CONFIGURATION=DEFAULT_CONF -DCMAKE_GENERATOR_PLATFORM=Win32 23 | ``` 24 | Open the generated Visual Studio Solution file `test\build-combination\build\FreeRTOS-Plus-FAT Build Combination.sln` 25 | in Visual Studio and click `Build --> Build Solution`. 26 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy 4 | of this software and associated documentation files (the "Software"), to deal 5 | in the Software without restriction, including without limitation the rights 6 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | copies of the Software, and to permit persons to whom the Software is 8 | furnished to do so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in all 11 | copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 19 | SOFTWARE. 20 | -------------------------------------------------------------------------------- /.github/CODEOWNERS: -------------------------------------------------------------------------------- 1 | # Each line is a file pattern followed by one or more owners. 2 | 3 | # These owners will be the default owners for everything in 4 | # the repo. Unless a later match takes precedence, 5 | # @global-owner1 and @global-owner2 will be requested for 6 | # review when someone opens a pull request. 7 | * @FreeRTOS/pr-bar-raiser 8 | 9 | # Order is important; the last matching pattern takes the most 10 | # precedence. When someone opens a pull request that only 11 | # modifies JS files, only @js-owner and not the global 12 | # owner(s) will be requested for a review. 13 | # *.c FreeRTOS/pr-bar-raiser 14 | 15 | # You can also use email addresses if you prefer. They'll be 16 | # used to look up users just like we do for commit author 17 | # emails. 18 | # *.go docs@example.com 19 | 20 | # In this example, @doctocat owns any files in the build/logs 21 | # directory at the root of the repository and any of its 22 | # subdirectories. 23 | # /build/logs/ @doctocat 24 | 25 | # The `docs/*` pattern will match files like 26 | # `docs/getting-started.md` but not further nested files like 27 | # `docs/build-app/troubleshooting.md`. 28 | # docs/* docs@example.com 29 | 30 | # In this example, @octocat owns any file in an apps directory 31 | # anywhere in your repository. 32 | # apps/ @octocat 33 | 34 | # In this example, @doctocat owns any file in the `/docs` 35 | # directory in the root of your repository and any of its 36 | # subdirectories. 37 | # /docs/ @doctocat 38 | 39 | 40 | -------------------------------------------------------------------------------- /test/build-combination/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_library( freertos_plus_fat_config_common INTERFACE ) 2 | target_include_directories(freertos_plus_fat_config_common INTERFACE Common/include ) 3 | 4 | # ------------------------------------------------------------------- 5 | add_library( freertos_plus_fat_config_default INTERFACE) 6 | target_include_directories(freertos_plus_fat_config_default INTERFACE DefaultConf) 7 | target_link_libraries(freertos_plus_fat_config_default INTERFACE freertos_plus_fat_config_common) 8 | 9 | # ------------------------------------------------------------------- 10 | # Configuration for FreeRTOS-Plus-FAT tests 11 | if(FREERTOS_PLUS_FAT_TEST_CONFIGURATION STREQUAL "CUSTOM" ) 12 | # Check Config target is available. And then do nothing. 13 | if(NOT TARGET freertos_config ) 14 | message(FATAL_ERROR "FREERTOS_PLUS_FAT_TEST_CONFIGURATION = CUSTOM, but no freertos_config target defined.") 15 | endif() 16 | else() 17 | add_library( freertos_config ALIAS freertos_plus_fat_config_default) 18 | endif() 19 | 20 | add_executable(freertos_plus_fat_build_test EXCLUDE_FROM_ALL) 21 | 22 | target_sources(freertos_plus_fat_build_test 23 | PRIVATE 24 | Common/main.c 25 | ) 26 | 27 | target_compile_options(freertos_plus_fat_build_test 28 | PRIVATE 29 | $<$:-Wno-missing-noreturn> 30 | $<$:-Wno-missing-prototypes> 31 | ) 32 | 33 | target_link_libraries(freertos_plus_fat_build_test 34 | PRIVATE 35 | freertos_plus_fat 36 | freertos_plus_fat_port 37 | freertos_kernel 38 | ) 39 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/bug_report.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Bug report 3 | about: Create a report to help us improve FreeRTOS-Plus-FAT. This should only be used 4 | for confirmed bugs. If you suspect something it is best to first discuss it on the 5 | FreeRTOS forums linked below. 6 | title: "[BUG]" 7 | labels: bug 8 | assignees: '' 9 | 10 | --- 11 | 12 | **Describe the bug** 13 | A concise description of what the bug is. If possible, that is the code is not proprietary, please upload the code in a [GitHub fork](https://docs.github.com/en/get-started/quickstart/fork-a-repo) such that we can reproduce the bug. 14 | 15 | **Target** 16 | - Development board: [e.g. HiFive11 RevB] 17 | - Instruction Set Architecture: [e.g. RV32IMAC] 18 | - IDE and version: [e.g. Freedom Studio 4.12.0.2019-08-2] 19 | - Toolchain and version: [e.g. riscv64-unknown-elf-gcc-8.3.0-2019.08.0] 20 | 21 | **Host** 22 | - Host OS: [e.g. MacOS] 23 | - Version: [e.g. Mojave 10.14.6] 24 | 25 | **To Reproduce** 26 | - Use project ... and configure with ... 27 | - Run on ... and could observe ... 28 | 29 | **Expected behavior** 30 | A concise description of what you expected to happen. 31 | 32 | **Screenshots** 33 | If applicable, add screenshots to help explain your problem. 34 | 35 | **Wireshark logs** 36 | To help us identify the issue and/or reproduce it, please attach Wireshark logs if applicable. 37 | 38 | **Additional context** 39 | Add any other context about the problem here. 40 | e.g. code snippet to reproduce the issue. 41 | e.g. stack trace, memory dump, debugger log, and many etc. 42 | 43 | 44 | -------------------------------------------------------------------------------- /portable/Zynq/xsdps_info.h: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * 3 | * mmc_decode_cid() and sd_decode_csd() 4 | * 5 | * analyse the meta data of an SD-card to read its capacity and some other properties. 6 | * 7 | * CID and CSD Analysis borrowed from the Linux kernel. 8 | * 9 | ******************************************************************************/ 10 | 11 | #ifndef SDPS_INFO_H_ 12 | 13 | #define SDPS_INFO_H_ 1 14 | 15 | #include 16 | 17 | struct mmc_cid 18 | { 19 | uint32_t manfid; 20 | char prod_name[ 8 ]; 21 | uint32_t serial; 22 | uint16_t oemid; 23 | uint16_t year; 24 | uint8_t hwrev; 25 | uint8_t fwrev; 26 | uint8_t month; 27 | }; 28 | 29 | struct mmc_csd 30 | { 31 | volatile uint64_t capacity_bytes; 32 | uint32_t sd_last_block_address; 33 | uint8_t mmca_vsn; 34 | uint16_t erase_size; 35 | uint8_t spare; 36 | uint16_t cmdclass; 37 | uint16_t tacc_clks; 38 | int32_t erase_shift; 39 | uint32_t tacc_ns; 40 | uint32_t r2w_factor; 41 | uint32_t max_dtr; 42 | uint32_t read_blkbits; 43 | uint32_t write_blkbits; 44 | uint32_t capacity; 45 | uint32_t pref_erase; 46 | uint32_t read_partial : 1, 47 | read_misalign : 1, 48 | write_partial : 1, 49 | write_misalign : 1; 50 | }; 51 | 52 | extern struct mmc_cid myCID; 53 | extern struct mmc_csd myCSD; 54 | 55 | int mmc_decode_cid( const struct mmc_csd * pxCSD, 56 | struct mmc_cid * pxCID, 57 | uint32_t * raw_data ); 58 | int sd_decode_csd( struct mmc_csd * pxCSD, 59 | uint32_t * ulResponse ); 60 | 61 | #endif /* SDPS_INFO_H_ */ 62 | -------------------------------------------------------------------------------- /portable/Zynq.2019.3/xsdps_info.h: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * 3 | * mmc_decode_cid() and sd_decode_csd() 4 | * 5 | * analyse the meta data of an SD-card to read its capacity and some other properties. 6 | * 7 | * CID and CSD Analysis borrowed from the Linux kernel. 8 | * 9 | ******************************************************************************/ 10 | 11 | #ifndef SDPS_INFO_H_ 12 | 13 | #define SDPS_INFO_H_ 1 14 | 15 | #include 16 | 17 | struct mmc_cid 18 | { 19 | uint32_t manfid; 20 | char prod_name[ 8 ]; 21 | uint32_t serial; 22 | uint16_t oemid; 23 | uint16_t year; 24 | uint8_t hwrev; 25 | uint8_t fwrev; 26 | uint8_t month; 27 | }; 28 | 29 | struct mmc_csd 30 | { 31 | volatile uint64_t capacity_bytes; 32 | uint32_t sd_last_block_address; 33 | uint8_t mmca_vsn; 34 | uint16_t erase_size; 35 | uint8_t spare; 36 | uint16_t cmdclass; 37 | uint16_t tacc_clks; 38 | int32_t erase_shift; 39 | uint32_t tacc_ns; 40 | uint32_t r2w_factor; 41 | uint32_t max_dtr; 42 | uint32_t read_blkbits; 43 | uint32_t write_blkbits; 44 | uint32_t capacity; 45 | uint32_t pref_erase; 46 | uint32_t read_partial : 1, 47 | read_misalign : 1, 48 | write_partial : 1, 49 | write_misalign : 1; 50 | }; 51 | 52 | extern struct mmc_cid myCID; 53 | extern struct mmc_csd myCSD; 54 | 55 | int mmc_decode_cid( const struct mmc_csd * pxCSD, 56 | struct mmc_cid * pxCID, 57 | uint32_t * raw_data ); 58 | int sd_decode_csd( struct mmc_csd * pxCSD, 59 | uint32_t * ulResponse ); 60 | 61 | #endif /* SDPS_INFO_H_ */ 62 | -------------------------------------------------------------------------------- /include/ff_crc.h: -------------------------------------------------------------------------------- 1 | /* 2 | * FreeRTOS+FAT V2.3.3 3 | * Copyright (C) 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved. 4 | * 5 | * Permission is hereby granted, free of charge, to any person obtaining a copy of 6 | * this software and associated documentation files (the "Software"), to deal in 7 | * the Software without restriction, including without limitation the rights to 8 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 9 | * the Software, and to permit persons to whom the Software is furnished to do so, 10 | * 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, FITNESS 17 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 18 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 19 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 20 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | * 22 | * https://www.FreeRTOS.org 23 | * https://github.com/FreeRTOS 24 | * 25 | */ 26 | 27 | /** 28 | * @file ff_crc.h 29 | * @ingroup CRC 30 | * 31 | **/ 32 | 33 | #ifndef _FF_CRC_H_ 34 | 35 | #define _FF_CRC_H_ 36 | 37 | uint8_t FF_GetCRC8( uint8_t * pbyData, 38 | uint32_t stLength ); 39 | uint16_t FF_GetCRC16( uint8_t * pbyData, 40 | uint32_t stLength ); 41 | uint32_t FF_GetCRC32( uint8_t * pbyData, 42 | uint32_t stLength ); 43 | extern const uint32_t crc32_table[ 256 ]; 44 | 45 | #endif /* ifndef _FF_CRC_H_ */ 46 | -------------------------------------------------------------------------------- /test/build-combination/DefaultConf/FreeRTOSFATConfig.h: -------------------------------------------------------------------------------- 1 | /* 2 | * FreeRTOS+FAT V2.3.3 3 | * Copyright (C) 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved. 4 | * 5 | * Permission is hereby granted, free of charge, to any person obtaining a copy of 6 | * this software and associated documentation files (the "Software"), to deal in 7 | * the Software without restriction, including without limitation the rights to 8 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 9 | * the Software, and to permit persons to whom the Software is furnished to do so, 10 | * 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, FITNESS 17 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 18 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 19 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 20 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | * 22 | * https://www.FreeRTOS.org 23 | * https://github.com/FreeRTOS 24 | * 25 | */ 26 | 27 | #ifndef FREERTOS_FAT_CONFIG_H 28 | #define FREERTOS_FAT_CONFIG_H 29 | 30 | #define ffconfigBYTE_ORDER ( pdFREERTOS_LITTLE_ENDIAN ) 31 | 32 | #define ffconfigCWD_THREAD_LOCAL_INDEX ( 0 ) 33 | 34 | /* Note - must be deifined */ 35 | #if !defined( portINLINE ) 36 | #define portINLINE __inline 37 | #endif 38 | 39 | /* Note: All other ffconfig values will be defined in FreeRTOSFATConfigDefaults.h when not defined here */ 40 | 41 | #endif /*FREERTOS_FAT_CONFIG_H */ 42 | -------------------------------------------------------------------------------- /portable/avr32_uc3/ff_flush.c: -------------------------------------------------------------------------------- 1 | /* */ 2 | /* */ 3 | /* */ 4 | 5 | #define SD_MMC_SPI_MEM 1 6 | 7 | #include "ff_headers.h" 8 | 9 | #include "logbuf.h" 10 | #include "secCache.h" 11 | 12 | #include "ff_flush.h" 13 | 14 | extern BaseType_t FF_SemaphoreTaken( void * pxSemaphore ); 15 | 16 | FF_Error_t FF_FlushWrites( FF_IOManager_t * pxIOManager, 17 | BaseType_t xForced ) 18 | { 19 | FF_Error_t xRetValue; 20 | 21 | if( ( pxIOManager == NULL ) || ( cache_dirt_count() == 0 ) ) 22 | { 23 | xRetValue = FF_ERR_NONE; 24 | } 25 | else if( ( pxIOManager->ucPreventFlush != pdFALSE ) && ( xForced == pdFALSE ) ) 26 | { 27 | xRetValue = FF_ERR_IOMAN_PARTITION_MOUNTED | FF_ERRFLAG; 28 | } 29 | else 30 | { 31 | BaseType_t rc = 0; 32 | 33 | if( xForced != pdFALSE ) 34 | { 35 | FF_FlushCache( pxIOManager ); 36 | } 37 | 38 | /* if( FF_TrySemaphore( pxIOManager->pvSemaphore, xForced ? 5000 : 0 ) != pdFALSE ) */ 39 | if( ( xForced != pdFALSE ) || ( FF_SemaphoreTaken( pxIOManager->pvSemaphore ) == pdFALSE ) ) 40 | { 41 | rc = cache_flush( xForced ); 42 | /* FF_ReleaseSemaphore( pxIOManager->pvSemaphore ); */ 43 | } 44 | 45 | xRetValue = rc; 46 | } 47 | 48 | return xRetValue; 49 | } 50 | 51 | FF_Error_t FF_StopFlush( FF_IOManager_t * pxIOManager, 52 | BaseType_t xFlag ) 53 | { 54 | FF_Error_t xRetValue; 55 | 56 | if( pxIOManager == NULL ) 57 | { 58 | xRetValue = 0; 59 | } 60 | else 61 | { 62 | vTaskSuspendAll(); 63 | { 64 | xRetValue = pxIOManager->ucPreventFlush; 65 | 66 | if( xFlag != FLUSH_ENABLE ) 67 | { 68 | xRetValue++; 69 | } 70 | else if( xRetValue > 0 ) 71 | { 72 | xRetValue--; 73 | } 74 | 75 | pxIOManager->ucPreventFlush = xRetValue; 76 | } 77 | xTaskResumeAll(); 78 | } 79 | 80 | return xRetValue; 81 | } 82 | -------------------------------------------------------------------------------- /portable/avr32_uc3/ff_flush.h: -------------------------------------------------------------------------------- 1 | /* 2 | * FreeRTOS+FAT V2.3.3 3 | * Copyright (C) 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved. 4 | * 5 | * Permission is hereby granted, free of charge, to any person obtaining a copy of 6 | * this software and associated documentation files (the "Software"), to deal in 7 | * the Software without restriction, including without limitation the rights to 8 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 9 | * the Software, and to permit persons to whom the Software is furnished to do so, 10 | * 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, FITNESS 17 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 18 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 19 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 20 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | * 22 | * https://www.FreeRTOS.org 23 | * https://github.com/FreeRTOS 24 | * 25 | */ 26 | 27 | #if !defined( __FF_FLUSH_H__ ) 28 | 29 | #define __FF_FLUSH_H__ 30 | 31 | #ifdef __cplusplus 32 | extern "C" { 33 | #endif 34 | 35 | /* HT addition: call FF_FlushCache and in addition call cache_write_flush (see secCache.cpp) */ 36 | FF_Error_t FF_FlushWrites( FF_IOManager_t * pxIOManager, 37 | BaseType_t xForced ); 38 | 39 | #define FLUSH_DISABLE 1 40 | #define FLUSH_ENABLE 0 41 | 42 | /* HT addition: prevent flushing temporarily FF_StopFlush(pIoMan, true) */ 43 | FF_Error_t FF_StopFlush( FF_IOManager_t * pxIOManager, 44 | BaseType_t xFlag ); 45 | #ifdef __cplusplus 46 | } /* extern "C" */ 47 | #endif 48 | 49 | 50 | #endif /* !defined(__FF_FLUSH_H__) */ 51 | -------------------------------------------------------------------------------- /portable/common/ff_ramdisk.h: -------------------------------------------------------------------------------- 1 | /* 2 | * FreeRTOS+FAT V2.3.3 3 | * Copyright (C) 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved. 4 | * 5 | * Permission is hereby granted, free of charge, to any person obtaining a copy of 6 | * this software and associated documentation files (the "Software"), to deal in 7 | * the Software without restriction, including without limitation the rights to 8 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 9 | * the Software, and to permit persons to whom the Software is furnished to do so, 10 | * 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, FITNESS 17 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 18 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 19 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 20 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | * 22 | * https://www.FreeRTOS.org 23 | * https://github.com/FreeRTOS 24 | * 25 | */ 26 | 27 | #ifndef __RAMDISK_H__ 28 | 29 | #define __RAMDISK_H__ 30 | 31 | #ifdef __cplusplus 32 | extern "C" { 33 | #endif 34 | 35 | #include "ff_headers.h" 36 | 37 | /* Create a RAM disk, supplying enough memory to hold N sectors of 512 bytes each */ 38 | FF_Disk_t * FF_RAMDiskInit( char * pcName, 39 | uint8_t * pucDataBuffer, 40 | uint32_t ulSectorCount, 41 | size_t xIOManagerCacheSize ); 42 | 43 | /* Release all resources */ 44 | BaseType_t FF_RAMDiskDelete( FF_Disk_t * pxDisk ); 45 | 46 | /* Show some partition information */ 47 | BaseType_t FF_RAMDiskShowPartition( FF_Disk_t * pxDisk ); 48 | 49 | #ifdef __cplusplus 50 | } /* extern "C" */ 51 | #endif 52 | 53 | #endif /* __RAMDISK_H__ */ 54 | -------------------------------------------------------------------------------- /include/ff_headers.h: -------------------------------------------------------------------------------- 1 | /* 2 | * FreeRTOS+FAT V2.3.3 3 | * Copyright (C) 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved. 4 | * 5 | * Permission is hereby granted, free of charge, to any person obtaining a copy of 6 | * this software and associated documentation files (the "Software"), to deal in 7 | * the Software without restriction, including without limitation the rights to 8 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 9 | * the Software, and to permit persons to whom the Software is furnished to do so, 10 | * 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, FITNESS 17 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 18 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 19 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 20 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | * 22 | * https://www.FreeRTOS.org 23 | * https://github.com/FreeRTOS 24 | * 25 | */ 26 | 27 | #ifndef PLUS_FAT_H 28 | #define PLUS_FAT_H 29 | 30 | #include 31 | 32 | #ifdef __cplusplus 33 | extern "C" { 34 | #endif 35 | 36 | #include "FreeRTOS.h" 37 | #include "task.h" 38 | #include "semphr.h" 39 | 40 | #include "FreeRTOSFATConfig.h" 41 | #include "FreeRTOSFATConfigDefaults.h" 42 | #include "ff_error.h" 43 | #include "ff_string.h" 44 | #include "ff_ioman.h" 45 | #include "ff_fat.h" 46 | #include "ff_fatdef.h" 47 | #include "ff_memory.h" 48 | #include "ff_time.h" 49 | #include "ff_crc.h" 50 | #include "ff_file.h" 51 | #include "ff_dir.h" 52 | #include "ff_format.h" 53 | #include "ff_locking.h" 54 | 55 | /* See if any older defines with a prefix "FF_" are still defined: */ 56 | #include "ff_old_config_defines.h" 57 | 58 | #ifdef __cplusplus 59 | } /* extern "C" */ 60 | #endif 61 | 62 | #endif /* ifndef PLUS_FAT_H */ 63 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # FreeRTOS+FAT: DOS Compatible Embedded FAT File System 2 | 3 | FreeRTOS+FAT is an open source, thread aware and scalable FAT12/FAT16/FAT32 DOS 4 | /Windows compatible embedded FAT file system which was recently acquired by 5 | [Real Time Engineers ltd](). for use with and without FreeRTOS. 6 | 7 | FreeRTOS+FAT is already used in commercial products, and is the file system 8 | used in the 9 | [FTP](https://www.freertos.org/FreeRTOS-Plus/FreeRTOS_Plus_TCP/FTP_Server.html) 10 | and 11 | [HTTP](https://www.freertos.org/FreeRTOS-Plus/FreeRTOS_Plus_TCP/HTTP_web_Server.html) 12 | server examples that are documented on the 13 | [FreeRTOS+TCP](https://www.freertos.org/FreeRTOS-Plus/FreeRTOS_Plus_TCP/index.html) 14 | pages. 15 | 16 | The 17 | [standard C library style API](https://www.freertos.org/Documentation/03-Libraries/05-FreeRTOS-labs/04-FreeRTOS-plus-FAT/05-Standard_Native_File_System_API) 18 | includes a thread local errno value, and the lower level native API provides a 19 | rich set of detailed error codes. 20 | 21 | For more details, please visit 22 | [FreeRTOS+FAT](https://www.freertos.org/FreeRTOS-Plus/FreeRTOS_Plus_FAT/index.html) page. 23 | 24 | ## To consume FreeRTOS+FAT 25 | 26 | ### Consume with CMake 27 | 28 | If using CMake, it is recommended to use this repository using FetchContent. 29 | Add the following into your project's main or a subdirectory's `CMakeLists.txt`: 30 | 31 | ```cmake 32 | include(FetchContent) 33 | 34 | FetchContent_Declare( freertos_plus_fat 35 | GIT_REPOSITORY "https://github.com/FreeRTOS/Lab-Project-FreeRTOS-FAT.git" 36 | GIT_TAG main #Note: Best practice to use specific git-hash or tagged version 37 | GIT_SUBMODULES "" # Don't grab any submodules since not latest 38 | ) 39 | 40 | # ... 41 | 42 | set( FREERTOS_PLUS_FAT_DEV_SUPPORT OFF CACHE BOOL "" FORCE) 43 | # Select the native compile PORT 44 | set( FREERTOS_PLUS_FAT_PORT "POSIX" CACHE STRING "" FORCE) 45 | # Select the cross-compile PORT 46 | if (CMAKE_CROSSCOMPILING) 47 | # Eg. Zynq 2019_3 version of port 48 | set(FREERTOS_PLUS_FAT_PORT "ZYNQ_2019_3" CACHE STRING "" FORCE) 49 | endif() 50 | 51 | FetchContent_MakeAvailable(freertos_plus_fat) 52 | ``` 53 | 54 | If you already have FreeRTOS in your project, you may skip the fetch content by setting 55 | `FREERTOS_PLUS_FAT_FETCH_FREERTOS` to `OFF`. 56 | 57 | ### Consuming stand-alone 58 | 59 | It is recommended to use this repository as a submodule. Please refer to 60 | [Git Tools — Submodules](https://git-scm.com/book/en/v2/Git-Tools-Submodules). 61 | 62 | ## Notes 63 | 64 | This project is undergoing optimizations or refactoring to improve memory usage, 65 | modularity, documentation, demo usability, or test coverage. 66 | -------------------------------------------------------------------------------- /portable/Zynq/xsdps_g.c: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * 3 | * Copyright (C) 2013 - 2014 Xilinx, Inc. All rights reserved. 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 13 | * all copies or substantial portions of the Software. 14 | * 15 | * Use of the Software is limited solely to applications: 16 | * (a) running on a Xilinx device, or 17 | * (b) that interact with a Xilinx device through a bus or interconnect. 18 | * 19 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 20 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 21 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 22 | * XILINX CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 23 | * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF 24 | * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 25 | * SOFTWARE. 26 | * 27 | * Except as contained in this notice, the name of the Xilinx shall not be used 28 | * in advertising or otherwise to promote the sale, use or other dealings in 29 | * this Software without prior written authorization from Xilinx. 30 | * 31 | ******************************************************************************/ 32 | /*****************************************************************************/ 33 | 34 | /** 35 | * 36 | * @file xsdps_g.c 37 | * 38 | * This file contains a configuration table that specifies the configuration of 39 | * SD devices in the system. 40 | * 41 | *
42 |  * MODIFICATION HISTORY:
43 |  *
44 |  * Ver   Who    Date     Changes
45 |  * ----- ---    -------- -----------------------------------------------
46 |  * 1.00a hk/sg  10/17/13 Initial release
47 |  *
48 |  * 
49 | * 50 | ******************************************************************************/ 51 | 52 | 53 | 54 | #include "xparameters.h" 55 | #include "xsdps.h" 56 | 57 | /* 58 | * The configuration table for devices 59 | */ 60 | 61 | XSdPs_Config XSdPs_ConfigTable[] = 62 | { 63 | { 64 | XPAR_XSDPS_0_DEVICE_ID, 65 | XPAR_XSDPS_0_BASEADDR, 66 | XPAR_XSDPS_0_SDIO_CLK_FREQ_HZ, 67 | 0, 68 | 0 69 | } 70 | }; 71 | -------------------------------------------------------------------------------- /include/ff_devices.h: -------------------------------------------------------------------------------- 1 | /* 2 | * FreeRTOS+FAT V2.3.3 3 | * Copyright (C) 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved. 4 | * 5 | * Permission is hereby granted, free of charge, to any person obtaining a copy of 6 | * this software and associated documentation files (the "Software"), to deal in 7 | * the Software without restriction, including without limitation the rights to 8 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 9 | * the Software, and to permit persons to whom the Software is furnished to do so, 10 | * 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, FITNESS 17 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 18 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 19 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 20 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | * 22 | * https://www.FreeRTOS.org 23 | * https://github.com/FreeRTOS 24 | * 25 | */ 26 | 27 | /** 28 | * @file ff_devices.h 29 | **/ 30 | #ifndef FF_DEVICES_H 31 | #define FF_DEVICES_H 32 | 33 | #ifndef PLUS_FAT_H 34 | #error this header will be included from "ff_headers.h" 35 | #endif 36 | 37 | #ifdef __cplusplus 38 | extern "C" { 39 | #endif 40 | 41 | #define FF_DEV_NO_DEV 0 42 | #define FF_DEV_CHAR_DEV 1 43 | #define FF_DEV_BLOCK_DEV 2 44 | 45 | BaseType_t xCheckDevicePath( const char * pcPath ); 46 | 47 | int FF_Device_Seek( FF_FILE * pxStream, 48 | long lOffset, 49 | int iWhence ); 50 | 51 | BaseType_t FF_Device_Open( const char * pcPath, 52 | FF_FILE * pxStream ); 53 | 54 | void FF_Device_Close( FF_FILE * pxStream ); 55 | 56 | size_t FF_Device_Read( void * pvBuf, 57 | size_t lSize, 58 | size_t lCount, 59 | FF_FILE * pxStream ); 60 | 61 | size_t FF_Device_Write( const void * pvBuf, 62 | size_t lSize, 63 | size_t lCount, 64 | FF_FILE * pxStream ); 65 | 66 | 67 | int FF_Device_GetDirEnt( const char * pcPath, 68 | FF_DirEnt_t * pxDirEnt ); 69 | 70 | #ifdef __cplusplus 71 | } /* extern "C" */ 72 | #endif 73 | 74 | #endif /* FF_DEVICES_H */ 75 | -------------------------------------------------------------------------------- /.github/.cSpellWords.txt: -------------------------------------------------------------------------------- 1 | ACDM 2 | ACMD 3 | AMCD 4 | ARGMT 5 | ARMA 6 | ARMR 7 | ASSD 8 | ATSAM 9 | Adma 10 | Appli 11 | Atmel 12 | BTST 13 | CBMC 14 | CBOR 15 | CCRC 16 | CCRCFAIL 17 | CEATA 18 | CEATAEND 19 | CLKCR 20 | CLKDIV 21 | CLKEN 22 | CLUS 23 | CMOCK 24 | CMock 25 | CNTR 26 | CPSECURE 27 | CPSM 28 | CREATELFNS 29 | CSDK 30 | CTOUTF 31 | Chrs 32 | Cmock 33 | Comd 34 | Coverity 35 | Cplt 36 | DBCKEND 37 | DBLOCKSIZE 38 | DCMAKE 39 | DCMOCK 40 | DCOUNT 41 | DCRC 42 | DCRCE 43 | DCRCFAIL 44 | DCTRL 45 | DESEL 46 | DESTROYIOMAN 47 | DFREERTOS 48 | DIREC 49 | DMAEN 50 | DNDEBUG 51 | DPSM 52 | DTDIR 53 | DTIMEOUT 54 | DTIMER 55 | DTMODE 56 | DTOE 57 | DUNITY 58 | Defl 59 | ECAPS 60 | EMIO 61 | EMMC 62 | ENCMDCOMPL 63 | ENMFILE 64 | EXTI 65 | FFERRTAB 66 | FFFUNCTIONTAB 67 | FFMODULETAB 68 | FSEL 69 | GPIO 70 | GPIOC 71 | GPIOD 72 | HSMCI 73 | HWFC 74 | Hein 75 | Hidd 76 | IDEN 77 | ILGL 78 | INSRT 79 | IRAM 80 | ISDIREMPTY 81 | ISEOF 82 | ITAPCHGWIN 83 | ITAPDLY 84 | ITAPDLYENA 85 | ITAPDLYSEL 86 | MBURST 87 | MINC 88 | MISRA 89 | MISRAC 90 | MMCA 91 | MMIO 92 | MQTT 93 | MSMCI 94 | MSWIN 95 | Misra 96 | NIEN 97 | NODISK 98 | NOINIT 99 | NOMEDIUM 100 | NSAC 101 | NVIC 102 | OPTIMISE 103 | OTAPDLY 104 | OTAPDLYENA 105 | OTAPDLYSEL 106 | OVRE 107 | OVRWR 108 | Optimised 109 | PBURST 110 | PCLK 111 | PERIPH 112 | PFCTRL 113 | PINC 114 | PTABLE 115 | PTBL 116 | PWRCTRL 117 | PWRSAV 118 | PWRUP 119 | Periph 120 | REGD 121 | RPBM 122 | RPMB 123 | RTOSFAT 124 | RWMOD 125 | RWSTART 126 | RWSTOP 127 | RXACT 128 | RXBUFF 129 | RXDAVL 130 | RXFIFOE 131 | RXFIFOF 132 | RXFIFOHF 133 | RXOVERR 134 | Resvd 135 | Rsvd 136 | SCUGIC 137 | SDCLK 138 | SDCOMBO 139 | SDHC 140 | SDHS 141 | SDID 142 | SDIDCOUNT 143 | SDIF 144 | SDIO 145 | SDIOCK 146 | SDIOCLK 147 | SDIOEN 148 | SDIOIT 149 | SDIOSUSPEND 150 | SDMA 151 | SDMMC 152 | SDMMCCLK 153 | SDPS 154 | SDSC 155 | SDXC 156 | STBITERR 157 | STBY 158 | SWRST 159 | TAAC 160 | TFXFIFOHE 161 | TPASTE 162 | TXACT 163 | TXBUFF 164 | TXDAVL 165 | TXFIFOE 166 | TXFIFOF 167 | TXFIFOHE 168 | TXUNDERR 169 | Tibosch 170 | UNACKED 171 | UNRE 172 | UNSTUFF 173 | VSEL 174 | Walmsley 175 | Wunused 176 | XPAR 177 | ZYNQ 178 | Zynd 179 | blocknr 180 | capitalised 181 | cbmc 182 | cbor 183 | clks 184 | cmock 185 | coremqtt 186 | coverity 187 | cstrntowcs 188 | cstrtowcs 189 | ctest 190 | evsetup 191 | ffconfig 192 | fwrev 193 | getpacketid 194 | hdma 195 | hdmarx 196 | hdmatx 197 | hsdio 198 | hwreset 199 | hwrev 200 | ioman 201 | isdirempty 202 | isystem 203 | lcov 204 | misra 205 | msdelay 206 | msdely 207 | mypy 208 | mytoken 209 | oemid 210 | optimise 211 | optimised 212 | optimising 213 | pxhandle 214 | pylint 215 | pytest 216 | pyyaml 217 | sddisk 218 | sdtype 219 | sinclude 220 | sinit 221 | tacc 222 | tobe 223 | utest 224 | xilffs 225 | xsdps 226 | -------------------------------------------------------------------------------- /History.txt: -------------------------------------------------------------------------------- 1 | Changes between 160112 and 160908 releases 2 | 3 | NOTE: The 160908 release is a maintenance release for the 160112 single 4 | interface labs release - not a release of the current development branch. 5 | 6 | + ff-deltree() now correctly handles deleted file entries. 7 | + Simplified mapping of standard library functions to their Visual Studio 8 | equivalents. 9 | + ffconfigMIN_CLUSTERS_FAT32 and ffconfigMIN_CLUSTERS_FAT16 introduced to 10 | allow the minimum disk sizes for the two FAT file system types to be 11 | smaller than is permitted by Windows. 12 | 13 | Changes between 150825 and 160111 releases 14 | 15 | + New device support: Demo applications and example drivers are provided 16 | for Atmel SAM4E and ST STM32F4 microcontrollers. 17 | + Various updates to improve compliance with the FreeRTOS coding standard. 18 | + Modified the stdio tests so they can be executed on SD cards, where the 19 | test files might already exists on power on - previously the tests were 20 | only executed on RAM disks which are always known to be empty on power on. 21 | + Added ff_deltree() implementation, with note of caution about its use as 22 | it uses recursion ( ff_deltree() recursively removes a directory and 23 | everything contained by it). 24 | + Update the Zynq project to use version 2015.4 of the Xilinx SDK. This 25 | driver dynamically recognises all types of memory cards. 26 | + The path cache is cleared when a disk is re-mounted, allowing a disk to be 27 | hot swapped. 28 | 29 | Bug fixes resulting from testing performed while converting the acquired 30 | component to be FreeRTOS+ compliant: 31 | 32 | + Fix bug in FF_FindNext() when using 'ffconfigFINDAPI_ALLOW_WILDCARDS'. 33 | + Fix bug in ff_fat.c when using 'ffconfigFSINFO_TRUSTED' and when the 34 | stored free cluster count equals ~0ul (which means: not filled in) as this 35 | was interpreted as having 4294967295 free clusters. 36 | + FF_Open() now checks file permissions before truncating a file, previously 37 | the file was truncated first. 38 | + Fix typo in source of FF_isEOF(). 39 | + FF_ExtendFile() now only attempts to reserve new clusters if it is 40 | actually necessary. 41 | + FF_Format() now correctly fills in the number of free clusters for FAT32. 42 | + FF_Partition() has been updated to use ffconfigMAX_PARTITIONS in all 43 | cases, whereas previously some legacy code was assuming a fixed maximum 44 | number of partitions. 45 | + FF_DeleteIOManager() now deletes the IO manager! 46 | 47 | 48 | Changes for 150825 (?) 49 | 50 | + Issue fixed in FF_Move(). 51 | + Improved handling of files and directories that start with a '.' character. 52 | + Changed the locking mechanisms from mutexes to an event group. 53 | + Add FF_ERR_DRIVER_NOMEDIUM to better handle media being removed and 54 | re-inserted. 55 | + Fix re-entrancy issue in FF_CheckValid(). 56 | + Remove hashes for deleted files. 57 | + General structural work. 58 | 59 | -------------------------------------------------------------------------------- /portable/Zynq.2019.3/xsdps_g.c: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * 3 | * Copyright (C) 2013 - 2019 Xilinx, Inc. All rights reserved. 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 13 | * all 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 18 | * THE 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 21 | * THE SOFTWARE. 22 | * 23 | * 24 | * 25 | ******************************************************************************/ 26 | /*****************************************************************************/ 27 | 28 | /** 29 | * 30 | * @file xsdps_g.c 31 | * @addtogroup sdps_v3_8 32 | * @{ 33 | * 34 | * This file contains a configuration table that specifies the configuration of 35 | * SD devices in the system. 36 | * 37 | *
38 |  * MODIFICATION HISTORY:
39 |  *
40 |  * Ver   Who    Date     Changes
41 |  * ----- ---    -------- -----------------------------------------------
42 |  * 1.00a hk/sg  10/17/13 Initial release
43 |  * 3.6   mn     07/06/18 Add initialization macros in sdps
44 |  *       mn     07/13/18 Add initializer macro for HasEMIO
45 |  *
46 |  * 
47 | * 48 | ******************************************************************************/ 49 | 50 | 51 | 52 | #include "xparameters.h" 53 | #include "xsdps.h" 54 | 55 | /* 56 | * The configuration table for devices 57 | */ 58 | 59 | #define XPAR_XSDPS_0_BUS_WIDTH 0 /* XSDPS_4_BIT_WIDTH */ 60 | #define XPAR_XSDPS_0_MIO_BANK 0 61 | #define XPAR_XSDPS_0_HAS_EMIO 0 62 | #ifndef XPAR_XSDPS_0_IS_CACHE_COHERENT 63 | #define XPAR_XSDPS_0_IS_CACHE_COHERENT 1 /* 0 Tables are located in uncached memory */ 64 | #endif 65 | 66 | XSdPs_Config XSdPs_ConfigTable[] = 67 | { 68 | { 69 | XPAR_XSDPS_0_DEVICE_ID, 70 | XPAR_XSDPS_0_BASEADDR, 71 | XPAR_XSDPS_0_SDIO_CLK_FREQ_HZ, 72 | XPAR_XSDPS_0_HAS_CD, 73 | XPAR_XSDPS_0_HAS_WP, 74 | XPAR_XSDPS_0_BUS_WIDTH, 75 | XPAR_XSDPS_0_MIO_BANK, 76 | XPAR_XSDPS_0_HAS_EMIO, 77 | XPAR_XSDPS_0_IS_CACHE_COHERENT 78 | } 79 | }; 80 | /** @} */ 81 | -------------------------------------------------------------------------------- /include/ff_time.h: -------------------------------------------------------------------------------- 1 | /* 2 | * FreeRTOS+FAT V2.3.3 3 | * Copyright (C) 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved. 4 | * 5 | * Permission is hereby granted, free of charge, to any person obtaining a copy of 6 | * this software and associated documentation files (the "Software"), to deal in 7 | * the Software without restriction, including without limitation the rights to 8 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 9 | * the Software, and to permit persons to whom the Software is furnished to do so, 10 | * 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, FITNESS 17 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 18 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 19 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 20 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | * 22 | * https://www.FreeRTOS.org 23 | * https://github.com/FreeRTOS 24 | * 25 | */ 26 | 27 | /** 28 | * @file ff_time.h 29 | * @ingroup TIME 30 | * 31 | * Provides a means for receiving the time on any platform. 32 | **/ 33 | 34 | #ifndef _FF_TIME_H_ 35 | #define _FF_TIME_H_ 36 | 37 | #include 38 | 39 | #include "FreeRTOSFATConfig.h" 40 | 41 | /* _HT_ 42 | * The following declarations and functions may be moved to a common directory? 43 | */ 44 | typedef struct xTIME_STRUCT 45 | { 46 | int tm_sec; /* Seconds */ 47 | int tm_min; /* Minutes */ 48 | int tm_hour; /* Hour (0--23) */ 49 | int tm_mday; /* Day of month (1--31) */ 50 | int tm_mon; /* Month (0--11) */ 51 | int tm_year; /* Year (calendar year minus 1900) */ 52 | int tm_wday; /* Weekday (0--6; Sunday = 0) */ 53 | int tm_yday; /* Day of year (0--365) */ 54 | int tm_isdst; /* 0 if daylight savings time is not in effect) */ 55 | } FF_TimeStruct_t; 56 | 57 | /* Equivalent of time() : returns the number of seconds after 1-1-1970. */ 58 | time_t FreeRTOS_time( time_t * pxTime ); 59 | 60 | /* Equivalent of mktime() : calculates the number of seconds after 1-1-1970. */ 61 | time_t FreeRTOS_mktime( const FF_TimeStruct_t * pxTimeBuf ); 62 | 63 | /* Equivalent of gmtime_r() : Fills a 'struct tm'. */ 64 | FF_TimeStruct_t * FreeRTOS_gmtime_r( const time_t * pxTime, 65 | FF_TimeStruct_t * pxTimeBuf ); 66 | 67 | /** 68 | * @public 69 | * @brief A TIME and DATE object for FreeRTOS+FAT. A FreeRTOS+FAT time driver must populate these values. 70 | * 71 | **/ 72 | typedef struct 73 | { 74 | uint16_t Year; /* Year (e.g. 2009). */ 75 | uint16_t Month; /* Month (e.g. 1 = Jan, 12 = Dec). */ 76 | uint16_t Day; /* Day (1 - 31). */ 77 | uint16_t Hour; /* Hour (0 - 23). */ 78 | uint16_t Minute; /* Min (0 - 59). */ 79 | uint16_t Second; /* Second (0 - 59). */ 80 | } FF_SystemTime_t; 81 | 82 | /*---------- PROTOTYPES */ 83 | 84 | int32_t FF_GetSystemTime( FF_SystemTime_t * pxTime ); 85 | 86 | #endif /* ifndef _FF_TIME_H_ */ 87 | -------------------------------------------------------------------------------- /History2.txt: -------------------------------------------------------------------------------- 1 | > is there a repository I should be aware of when it comes to FreeRTOS Labs? 2 | 3 | Unfortunately there isn't. FreeRTOS+FAT has become a bit of an orphan. All time and energy goes to the products in the [AWS/FreeRTOS release](https://github.com/aws/amazon-freertos) 4 | But I am still actively maintaining FreeRTOS+FAT: implementing requests and fixes. 5 | 6 | Please comment your findings with the above +FAT release. 7 | 8 | Here is a complete list of all changes since the 160919 Labs release: 9 | 10 | ● `ff_dir.c : FF_MkDir()` 11 | refuse to create a directory with an empty name 12 | 13 | ● `ff_fat.c : FF_GetFreeSize()` 14 | in case of an error, return 0 15 | 16 | ● `ff_file.c : FF_FileSize()` 17 | This function returns the size of a file, or a negative number in case of an error. 18 | Hence, the maximum size returned was returned is 2 GB. 19 | We've added a new function: 20 | `FF_Error_t FF_GetFileSize( FF_FILE *pxFile, uint32_t *pulSize );` 21 | which separates the length from the error code. 22 | 23 | ● `ff_file.c : FF_ExtendFile()` 24 | Sometimes while building up a file, it may be more efficient not to flush the changes immediately. When defining `ffconfigFILE_EXTEND_FLUSHES_BUFFERS` as `0`, there is no immediate flushing. 25 | 26 | ● `ff_file.c : FF_Seek()` 27 | Seeking didn't work for sizes larger than 2 GB. Although the parameter `int32_t lOffset` is signed, it will now be casted to 32-bits unsigned: 28 | `ulPosition = ( uint32_t )lOffset;` 29 | All options (`SET`, `CUR`, and `END` ) re-tested. 30 | 31 | ● `ff_file.c : FF_Close()` 32 | `FF_FlushCache()` is now called at the end of the function in order to also write the last changes. 33 | 34 | ● `ff_format.c : FF_Format()` 35 | A variable `lRemaining` should have been declared unsigned: `uint32_t`. 36 | Also: a small optimisation for large SD-cards: 37 | "Putting the FAT-table into the second 4MB erase block gives a higher performance and a longer life-time" 38 | 39 | ● `ff_format.c : FF_Partition()` 40 | `ulHiddenSectors` must be at least `1` 41 | ( see [this post](https://sourceforge.net/p/freertos/discussion/382005/thread/d2b6524a/?limit=250#e1ea) ) 42 | 43 | ● `ff_ioman.c : FF_CreateIOManger()` 44 | `FF_CreateEvents` shall only be called in case an `pxIOManager` was successfully created. 45 | 46 | ● `ff_ioman.c : FF_DeleteIOManager()` 47 | Added a call to `FF_DeleteEvents()`, which will delete the event group belonging to the I/O manager. 48 | 49 | ● `ff_ioman.c : FF_FlushCache()` 50 | Added a user application hook per disk: `fnFlushApplicationHook()`. This is useful for e.g. NAND-drivers. 51 | 52 | ● `ff_ioman.c : FF_Mount()` 53 | Make sure that `pcVolumeLabel` is null-terminated. 54 | 55 | ● `ff_ioman.c : FF_IncreaseFreeClusters()` 56 | A lock is needed before `ulLastFreeCluster` can be changed. But before taking this lock, check if has already been taken to avoid a dead lock. 57 | 58 | ● `ff_locking.c : FF_DeleteEvents` 59 | This is a new function which deletes ( frees up ) the event group belonging to an I/O manager. 60 | 61 | ● `ff_stdio.c : ff_filelength()` 62 | This function will now call `FF_GetFileSize()` in order to get the `unsigned` length of a file, increasing the maximum reported size from 2 to 4 GB. 63 | 64 | ● `ff_sys.c : *` 65 | This module combines several I/O managers ( = disks ) into a single file system that starts with a root `"/"`. 66 | All code has been re-written ( re-styled ) and re-tested. 67 | -------------------------------------------------------------------------------- /portable/common/ff_sddisk.h: -------------------------------------------------------------------------------- 1 | /* 2 | * FreeRTOS+FAT V2.3.3 3 | * Copyright (C) 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved. 4 | * 5 | * Permission is hereby granted, free of charge, to any person obtaining a copy of 6 | * this software and associated documentation files (the "Software"), to deal in 7 | * the Software without restriction, including without limitation the rights to 8 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 9 | * the Software, and to permit persons to whom the Software is furnished to do so, 10 | * 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, FITNESS 17 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 18 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 19 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 20 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | * 22 | * https://www.FreeRTOS.org 23 | * https://github.com/FreeRTOS 24 | * 25 | */ 26 | 27 | #ifndef __SDDISK_H__ 28 | 29 | #define __SDDISK_H__ 30 | 31 | #include "ff_headers.h" 32 | 33 | #ifdef __cplusplus 34 | extern "C" { 35 | #endif 36 | 37 | /* @brief Initialization settings for more granular control on init. */ 38 | typedef struct FFInitSettings_s 39 | { 40 | BaseType_t xMountFailIgnore; /**< Ignore failure when mounting */ 41 | BaseType_t xDiskPartition; /**< Default disk partition number */ 42 | } FFInitSettings_t; 43 | 44 | 45 | /* Return non-zero if the SD-card is present. 46 | * The parameter 'pxDisk' may be null, unless device locking is necessary. */ 47 | BaseType_t FF_SDDiskDetect( FF_Disk_t * pxDisk ); 48 | 49 | /* Create a RAM disk, supplying enough memory to hold N sectors of 512 bytes each */ 50 | FF_Disk_t * FF_SDDiskInitWithSettings( const char * pcName, 51 | const FFInitSettings_t * pxSettings ); 52 | 53 | FF_Disk_t * FF_SDDiskInit( const char * pcName ); 54 | 55 | BaseType_t FF_SDDiskReinit( FF_Disk_t * pxDisk ); 56 | 57 | /* Unmount the volume */ 58 | BaseType_t FF_SDDiskUnmount( FF_Disk_t * pDisk ); 59 | 60 | /* Mount the volume */ 61 | BaseType_t FF_SDDiskMount( FF_Disk_t * pDisk ); 62 | 63 | /* Release all resources */ 64 | BaseType_t FF_SDDiskDelete( FF_Disk_t * pDisk ); 65 | 66 | /* Show some partition information */ 67 | BaseType_t FF_SDDiskShowPartition( FF_Disk_t * pDisk ); 68 | 69 | /* Flush changes from the driver's buf to disk */ 70 | void FF_SDDiskFlush( FF_Disk_t * pDisk ); 71 | 72 | /* Format a given partition on an SD-card. */ 73 | BaseType_t FF_SDDiskFormat( FF_Disk_t * pxDisk, 74 | BaseType_t aPart ); 75 | 76 | /* Return non-zero if an SD-card is detected in a given slot. */ 77 | BaseType_t FF_SDDiskInserted( BaseType_t xDriveNr ); 78 | 79 | /* _RB_ Temporary function - ideally the application would not need the IO 80 | * manager structure, just a handle to a disk. */ 81 | FF_IOManager_t * sddisk_ioman( FF_Disk_t * pxDisk ); 82 | 83 | #ifdef __cplusplus 84 | } /* extern "C" */ 85 | #endif 86 | 87 | #endif /* __SDDISK_H__ */ 88 | -------------------------------------------------------------------------------- /include/ff_locking.h: -------------------------------------------------------------------------------- 1 | /* 2 | * FreeRTOS+FAT V2.3.3 3 | * Copyright (C) 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved. 4 | * 5 | * Permission is hereby granted, free of charge, to any person obtaining a copy of 6 | * this software and associated documentation files (the "Software"), to deal in 7 | * the Software without restriction, including without limitation the rights to 8 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 9 | * the Software, and to permit persons to whom the Software is furnished to do so, 10 | * 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, FITNESS 17 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 18 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 19 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 20 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | * 22 | * https://www.FreeRTOS.org 23 | * https://github.com/FreeRTOS 24 | * 25 | */ 26 | 27 | /** 28 | * @file ff_locking.h 29 | * @ingroup LOCKING 30 | **/ 31 | 32 | #ifndef _FF_LOCKING_H_ 33 | #define _FF_LOCKING_H_ 34 | 35 | #ifdef __cplusplus 36 | extern "C" { 37 | #endif 38 | 39 | #include 40 | 41 | /*---------- PROTOTYPES (in order of appearance). */ 42 | 43 | /* PUBLIC: */ 44 | 45 | 46 | /* PRIVATE: */ 47 | void FF_PendSemaphore( void * pSemaphore ); 48 | BaseType_t FF_TrySemaphore( void * pSemaphore, 49 | uint32_t TimeMs ); 50 | void FF_ReleaseSemaphore( void * pSemaphore ); 51 | void FF_Sleep( uint32_t TimeMs ); 52 | 53 | /* Create an event group and bind it to an I/O manager. */ 54 | BaseType_t FF_CreateEvents( FF_IOManager_t * pxIOManager ); 55 | 56 | /* Delete an event group. */ 57 | void FF_DeleteEvents( FF_IOManager_t * pxIOManager ); 58 | 59 | /* Get a lock on all DIR operations for a given I/O manager. */ 60 | void FF_LockDirectory( FF_IOManager_t * pxIOManager ); 61 | 62 | /* Release the lock on all DIR operations. */ 63 | void FF_UnlockDirectory( FF_IOManager_t * pxIOManager ); 64 | 65 | /* Get a lock on all FAT operations for a given I/O manager. */ 66 | void FF_LockFAT( FF_IOManager_t * pxIOManager ); 67 | 68 | /* Release the lock on all FAT operations. */ 69 | void FF_UnlockFAT( FF_IOManager_t * pxIOManager ); 70 | 71 | /* Called from FF_GetBuffer() as long as no buffer is available. */ 72 | BaseType_t FF_BufferWait( FF_IOManager_t * pxIOManager, 73 | uint32_t xWaitMS ); 74 | 75 | /* Called from FF_ReleaseBuffer(). */ 76 | void FF_BufferProceed( FF_IOManager_t * pxIOManager ); 77 | 78 | /* Check if the current task already has locked the FAT. */ 79 | int FF_Has_Lock( FF_IOManager_t * pxIOManager, 80 | uint32_t aBits ); 81 | 82 | /* 83 | * Throw a configASSERT() in case the FAT has not been locked 84 | * by this task. 85 | */ 86 | /* _HT_ This function is only necessary while testing. */ 87 | void FF_Assert_Lock( FF_IOManager_t * pxIOManager, 88 | uint32_t aBits ); 89 | 90 | #ifdef __cplusplus 91 | } /* extern "C" */ 92 | #endif 93 | 94 | #endif /* _FF_LOCKING_H_ */ 95 | -------------------------------------------------------------------------------- /.github/workflows/ci.yml: -------------------------------------------------------------------------------- 1 | name: CI Checks 2 | 3 | on: 4 | push: 5 | branches: ["**"] 6 | pull_request: 7 | branches: ["**"] 8 | workflow_dispatch: 9 | 10 | jobs: 11 | # Currently no unit tests 12 | formatting: 13 | runs-on: ubuntu-latest 14 | steps: 15 | - uses: actions/checkout@v3 16 | - name: Check Formatting of Files 17 | uses: FreeRTOS/CI-CD-Github-Actions/formatting@main 18 | 19 | spell-check: 20 | runs-on: ubuntu-latest 21 | steps: 22 | - name: Clone This Repo 23 | uses: actions/checkout@v3 24 | - name: Run spellings check 25 | uses: FreeRTOS/CI-CD-Github-Actions/spellings@main 26 | 27 | link-verifier: 28 | runs-on: ubuntu-latest 29 | steps: 30 | - name: Clone This Repo 31 | uses: actions/checkout@v3 32 | - name: Link Verification 33 | uses: FreeRTOS/CI-CD-Github-Actions/link-verifier@main 34 | 35 | # doxygen: 36 | # runs-on: ubuntu-latest 37 | # steps: 38 | # - uses: actions/checkout@v3 39 | # - name: Run doxygen build 40 | # uses: FreeRTOS/CI-CD-Github-Actions/doxygen@main 41 | # with: 42 | # path: ./ 43 | 44 | build-checks: 45 | runs-on: ubuntu-latest 46 | steps: 47 | - uses: actions/checkout@v3 48 | - name: Install Dependencies 49 | run: | 50 | sudo apt install build-essential cmake ninja-build 51 | - name: Build checks (Default configuration) 52 | run: | 53 | cmake -E env CFLAGS="-DffconfigFAT12_SUPPORT=1" \ 54 | cmake -S . -B build -DFREERTOS_PLUS_FAT_TEST_CONFIGURATION=DEFAULT_CONF -GNinja 55 | cmake --build build --target freertos_plus_fat_build_test 56 | 57 | # complexity: 58 | # runs-on: ubuntu-latest 59 | # steps: 60 | # - uses: actions/checkout@v3 61 | # - name: Setup 62 | # run: sudo apt-get install complexity 63 | # - name: Install Uncrustify 64 | # run: sudo apt-get install uncrustify 65 | # - name: Complexity 66 | # run: | 67 | # COMPLEXITY_PARAMS="--scores --threshold=10 --horrid-threshold=283" 68 | # TEMP_DIR=./temp 69 | # mkdir -p ${TEMP_DIR} 70 | # for SOURCE_FILE in source/portable/BufferManagement/*.c source/*.c 71 | # do 72 | # TARGET_DIR=${TEMP_DIR}/`dirname ${SOURCE_FILE}` 73 | # TARGET_FILE=${TARGET_DIR}/`basename ${SOURCE_FILE}` 74 | # mkdir -p ${TARGET_DIR} 75 | # uncrustify -c tools/uncrustify.complexity.cfg -f ${SOURCE_FILE} > ${TARGET_FILE} 76 | # done 77 | # find ${TEMP_DIR} -iname '*.c' | xargs complexity ${COMPLEXITY_PARAMS} 78 | # RESULT=$? 79 | # rm -rf ${TEMP_DIR} 80 | # if [ "${RESULT}" = "0" ]; then 81 | # echo "All is good." 82 | # exit 0 83 | # else 84 | # echo "Sources are too complex, rc = " ${RESULT} 85 | # exit 1 86 | # fi 87 | 88 | git-secrets: 89 | runs-on: ubuntu-latest 90 | steps: 91 | - uses: actions/checkout@v3 92 | with: 93 | submodules: recursive 94 | - name: Checkout awslabs/git-secrets 95 | uses: actions/checkout@v3 96 | with: 97 | repository: awslabs/git-secrets 98 | ref: master 99 | path: git-secrets 100 | - name: Install git-secrets 101 | run: cd git-secrets && sudo make install && cd .. 102 | - name: Run git-secrets 103 | run: | 104 | git-secrets --register-aws 105 | git-secrets --scan 106 | -------------------------------------------------------------------------------- /include/ff_format.h: -------------------------------------------------------------------------------- 1 | /* 2 | * FreeRTOS+FAT V2.3.3 3 | * Copyright (C) 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved. 4 | * 5 | * Permission is hereby granted, free of charge, to any person obtaining a copy of 6 | * this software and associated documentation files (the "Software"), to deal in 7 | * the Software without restriction, including without limitation the rights to 8 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 9 | * the Software, and to permit persons to whom the Software is furnished to do so, 10 | * 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, FITNESS 17 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 18 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 19 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 20 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | * 22 | * https://www.FreeRTOS.org 23 | * https://github.com/FreeRTOS 24 | * 25 | */ 26 | 27 | /** 28 | * @file ff_format.c 29 | * @ingroup FORMAT 30 | * 31 | **/ 32 | 33 | 34 | #ifndef _FF_FORMAT_H_ 35 | #define _FF_FORMAT_H_ 36 | 37 | #ifdef __cplusplus 38 | extern "C" { 39 | #endif 40 | 41 | 42 | #ifndef PLUS_FAT_H 43 | #error this header will be included from "ff_headers.h" 44 | #endif 45 | 46 | /*---------- PROTOTYPES */ 47 | /* PUBLIC (Interfaces): */ 48 | 49 | typedef enum _FF_SizeType 50 | { 51 | eSizeIsQuota, /* Assign a quotum (sum of xSizes is free, all disk space will be allocated) */ 52 | eSizeIsPercent, /* Assign a percentage of the available space (sum of xSizes must be <= 100) */ 53 | eSizeIsSectors, /* Assign fixed number of sectors (sum of xSizes must be < ulSectorCount) */ 54 | } eSizeType_t; 55 | 56 | typedef struct _FF_PartitionParameters 57 | { 58 | uint32_t ulSectorCount; /* Total number of sectors on the disk, including hidden/reserved */ 59 | /* Must be obtained from the block driver */ 60 | uint32_t ulHiddenSectors; /* Keep at least these initial sectors free */ 61 | uint32_t ulInterSpace; /* Number of sectors to keep free between partitions (when 0 -> 2048) */ 62 | BaseType_t xSizes[ ffconfigMAX_PARTITIONS ]; /* E.g. 80, 20, 0, 0 (see eSizeType) */ 63 | BaseType_t xPrimaryCount; /* The number of partitions that must be "primary" */ 64 | eSizeType_t eSizeType; 65 | } FF_PartitionParameters_t; 66 | 67 | FF_Error_t FF_Partition( FF_Disk_t * pxDisk, 68 | FF_PartitionParameters_t * pParams ); 69 | 70 | FF_Error_t FF_Format( FF_Disk_t * pxDisk, 71 | BaseType_t xPartitionNumber, 72 | BaseType_t xPreferFAT16, 73 | BaseType_t xSmallClusters ); 74 | 75 | FF_Error_t FF_FormatDisk( FF_Disk_t * pxDisk, 76 | BaseType_t xPartitionNumber, 77 | BaseType_t xPreferFAT16, 78 | BaseType_t xSmallClusters, 79 | const char * pcVolumeName ); 80 | 81 | /* Private : */ 82 | 83 | #ifdef __cplusplus 84 | } /* extern "C" */ 85 | #endif 86 | 87 | #endif /* ifndef _FF_FORMAT_H_ */ 88 | -------------------------------------------------------------------------------- /portable/Zynq.2019.3/xsdps_sinit.c: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * 3 | * Copyright (C) 2013 - 2019 Xilinx, Inc. All rights reserved. 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 13 | * all 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 18 | * THE 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 21 | * THE SOFTWARE. 22 | * 23 | * 24 | * 25 | ******************************************************************************/ 26 | /*****************************************************************************/ 27 | 28 | /** 29 | * 30 | * @file xsdps_sinit.c 31 | * @addtogroup sdps_v3_8 32 | * @{ 33 | * 34 | * The implementation of the XSdPs component's static initialization 35 | * functionality. 36 | * 37 | *
 38 |  * MODIFICATION HISTORY:
 39 |  *
 40 |  * Ver   Who    Date     Changes
 41 |  * ----- ---    -------- -----------------------------------------------
 42 |  * 1.00a hk/sg  10/17/13 Initial release
 43 |  *       kvn    07/15/15 Modified the code according to MISRAC-2012.
 44 |  * 3.7   aru    03/12/19 Modified the code according to MISRAC-2012.
 45 |  *
 46 |  * 
47 | * 48 | ******************************************************************************/ 49 | 50 | /***************************** Include Files *********************************/ 51 | #include "xstatus.h" 52 | #include "xsdps.h" 53 | #include "xparameters.h" 54 | /************************** Constant Definitions *****************************/ 55 | 56 | /**************************** Type Definitions *******************************/ 57 | 58 | /***************** Macros (Inline Functions) Definitions *********************/ 59 | 60 | /************************** Function Prototypes ******************************/ 61 | 62 | /************************** Variable Definitions *****************************/ 63 | extern XSdPs_Config XSdPs_ConfigTable[ XPAR_XSDPS_NUM_INSTANCES ]; 64 | 65 | /*****************************************************************************/ 66 | 67 | /** 68 | * 69 | * Looks up the device configuration based on the unique device ID. A table 70 | * contains the configuration info for each device in the system. 71 | * 72 | * @param DeviceId contains the ID of the device to look up the 73 | * configuration for. 74 | * 75 | * @return 76 | * 77 | * A pointer to the configuration found or NULL if the specified device ID was 78 | * not found. See xsdps.h for the definition of XSdPs_Config. 79 | * 80 | * @note None. 81 | * 82 | ******************************************************************************/ 83 | XSdPs_Config * XSdPs_LookupConfig( u16 DeviceId ) 84 | { 85 | XSdPs_Config * CfgPtr = NULL; 86 | u32 Index; 87 | 88 | for( Index = 0U; Index < ( u32 ) XPAR_XSDPS_NUM_INSTANCES; Index++ ) 89 | { 90 | if( XSdPs_ConfigTable[ Index ].DeviceId == DeviceId ) 91 | { 92 | CfgPtr = &XSdPs_ConfigTable[ Index ]; 93 | break; 94 | } 95 | } 96 | 97 | return ( XSdPs_Config * ) CfgPtr; 98 | } 99 | /** @} */ 100 | -------------------------------------------------------------------------------- /ff_memory.c: -------------------------------------------------------------------------------- 1 | /* 2 | * FreeRTOS+FAT V2.3.3 3 | * Copyright (C) 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved. 4 | * 5 | * Permission is hereby granted, free of charge, to any person obtaining a copy of 6 | * this software and associated documentation files (the "Software"), to deal in 7 | * the Software without restriction, including without limitation the rights to 8 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 9 | * the Software, and to permit persons to whom the Software is furnished to do so, 10 | * 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, FITNESS 17 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 18 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 19 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 20 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | * 22 | * https://www.FreeRTOS.org 23 | * https://github.com/FreeRTOS 24 | * 25 | */ 26 | 27 | /** 28 | * @file ff_memory.c 29 | * @ingroup MEMORY 30 | * 31 | * @defgroup MEMORY FreeRTOS+FAT Memory Access Routines 32 | * @brief Handles memory access in a portable way. 33 | * 34 | * Provides simple, fast, and portable access to memory routines. 35 | * These are only used to read data from buffers. That are LITTLE ENDIAN 36 | * due to the FAT specification. 37 | * 38 | * These routines may need to be modified to your platform. 39 | * 40 | **/ 41 | 42 | #include "ff_headers.h" 43 | 44 | /* 45 | * Here below 3 x 2 access functions that allow the code 46 | * not to worry about the endianness of the MCU. 47 | */ 48 | 49 | 50 | #if ( ffconfigINLINE_MEMORY_ACCESS == 0 ) 51 | 52 | uint8_t FF_getChar( const uint8_t * pBuffer, 53 | uint32_t aOffset ) 54 | { 55 | return ( uint8_t ) ( pBuffer[ aOffset ] ); 56 | } 57 | 58 | uint16_t FF_getShort( const uint8_t * pBuffer, 59 | uint32_t aOffset ) 60 | { 61 | FF_T_UN16 u16; 62 | 63 | pBuffer += aOffset; 64 | u16.bytes.u8_1 = pBuffer[ 1 ]; 65 | u16.bytes.u8_0 = pBuffer[ 0 ]; 66 | 67 | return u16.u16; 68 | } 69 | 70 | uint32_t FF_getLong( const uint8_t * pBuffer, 71 | uint32_t aOffset ) 72 | { 73 | FF_T_UN32 u32; 74 | 75 | pBuffer += aOffset; 76 | u32.bytes.u8_3 = pBuffer[ 3 ]; 77 | u32.bytes.u8_2 = pBuffer[ 2 ]; 78 | u32.bytes.u8_1 = pBuffer[ 1 ]; 79 | u32.bytes.u8_0 = pBuffer[ 0 ]; 80 | 81 | return u32.u32; 82 | } 83 | 84 | void FF_putChar( uint8_t * pBuffer, 85 | uint32_t aOffset, 86 | uint32_t Value ) 87 | { 88 | pBuffer[ aOffset ] = ( uint8_t ) Value; 89 | } 90 | 91 | void FF_putShort( uint8_t * pBuffer, 92 | uint32_t aOffset, 93 | uint32_t Value ) 94 | { 95 | FF_T_UN16 u16; 96 | 97 | u16.u16 = ( uint16_t ) Value; 98 | pBuffer += aOffset; 99 | pBuffer[ 0 ] = u16.bytes.u8_0; 100 | pBuffer[ 1 ] = u16.bytes.u8_1; 101 | } 102 | 103 | void FF_putLong( uint8_t * pBuffer, 104 | uint32_t aOffset, 105 | uint32_t Value ) 106 | { 107 | FF_T_UN32 u32; 108 | 109 | u32.u32 = Value; 110 | pBuffer += aOffset; 111 | pBuffer[ 0 ] = u32.bytes.u8_0; 112 | pBuffer[ 1 ] = u32.bytes.u8_1; 113 | pBuffer[ 2 ] = u32.bytes.u8_2; 114 | pBuffer[ 3 ] = u32.bytes.u8_3; 115 | } 116 | 117 | #endif /* if ( ffconfigINLINE_MEMORY_ACCESS == 0 ) */ 118 | -------------------------------------------------------------------------------- /portable/Zynq/xsdps_sinit.c: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * 3 | * Copyright (C) 2013 - 2014 Xilinx, Inc. All rights reserved. 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 13 | * all copies or substantial portions of the Software. 14 | * 15 | * Use of the Software is limited solely to applications: 16 | * (a) running on a Xilinx device, or 17 | * (b) that interact with a Xilinx device through a bus or interconnect. 18 | * 19 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 20 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 21 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 22 | * XILINX CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 23 | * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF 24 | * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 25 | * SOFTWARE. 26 | * 27 | * Except as contained in this notice, the name of the Xilinx shall not be used 28 | * in advertising or otherwise to promote the sale, use or other dealings in 29 | * this Software without prior written authorization from Xilinx. 30 | * 31 | ******************************************************************************/ 32 | /*****************************************************************************/ 33 | 34 | /** 35 | * 36 | * @file xsdps_sinit.c 37 | * 38 | * The implementation of the XSdPs component's static initialization 39 | * functionality. 40 | * 41 | *
 42 |  * MODIFICATION HISTORY:
 43 |  *
 44 |  * Ver   Who    Date     Changes
 45 |  * ----- ---    -------- -----------------------------------------------
 46 |  * 1.00a hk/sg  10/17/13 Initial release
 47 |  *
 48 |  * 
49 | * 50 | ******************************************************************************/ 51 | 52 | /***************************** Include Files *********************************/ 53 | #include "xstatus.h" 54 | #include "xsdps.h" 55 | #include "xparameters.h" 56 | /************************** Constant Definitions *****************************/ 57 | 58 | /**************************** Type Definitions *******************************/ 59 | 60 | /***************** Macros (Inline Functions) Definitions *********************/ 61 | 62 | /************************** Function Prototypes ******************************/ 63 | 64 | /************************** Variable Definitions *****************************/ 65 | extern XSdPs_Config XSdPs_ConfigTable[]; 66 | 67 | /*****************************************************************************/ 68 | 69 | /** 70 | * 71 | * Looks up the device configuration based on the unique device ID. A table 72 | * contains the configuration info for each device in the system. 73 | * 74 | * @param DeviceId contains the ID of the device to look up the 75 | * configuration for. 76 | * 77 | * @return 78 | * 79 | * A pointer to the configuration found or NULL if the specified device ID was 80 | * not found. See xsdps.h for the definition of XSdPs_Config. 81 | * 82 | * @note None. 83 | * 84 | ******************************************************************************/ 85 | XSdPs_Config * XSdPs_LookupConfig( u16 DeviceId ) 86 | { 87 | XSdPs_Config * CfgPtr = NULL; 88 | int Index; 89 | 90 | for( Index = 0; Index < XPAR_XSDPS_NUM_INSTANCES; Index++ ) 91 | { 92 | if( XSdPs_ConfigTable[ Index ].DeviceId == DeviceId ) 93 | { 94 | CfgPtr = &XSdPs_ConfigTable[ Index ]; 95 | break; 96 | } 97 | } 98 | 99 | return CfgPtr; 100 | } 101 | -------------------------------------------------------------------------------- /portable/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_library( freertos_plus_fat_port_common STATIC ) 2 | 3 | target_sources( freertos_plus_fat_port_common 4 | PRIVATE 5 | common/ff_ramdisk.c 6 | common/ff_ramdisk.h 7 | common/ff_sddisk.h 8 | ) 9 | 10 | target_include_directories( freertos_plus_fat_port_common SYSTEM 11 | PUBLIC 12 | common 13 | ) 14 | 15 | target_compile_options( freertos_plus_fat_port_common 16 | PRIVATE 17 | $<$:-Wno-missing-prototypes> 18 | $<$:-Wno-reserved-macro-identifier> 19 | $<$:-Wno-shorten-64-to-32> 20 | $<$:-Wno-sign-conversion> 21 | ) 22 | 23 | target_link_libraries( freertos_plus_fat_port_common 24 | PRIVATE 25 | freertos_kernel 26 | freertos_plus_fat 27 | ) 28 | 29 | # ------------------------------------------------------------------- 30 | 31 | if (FREERTOS_PLUS_FAT_PORT STREQUAL "A_CUSTOM_PORT") 32 | message(STATUS "Using a custom FREERTOS_PLUS_FAT_PORT.") 33 | return() 34 | endif() 35 | 36 | add_library( freertos_plus_fat_port STATIC ) 37 | 38 | target_sources( freertos_plus_fat_port 39 | PRIVATE 40 | $<$: 41 | ATSAM4E/ff_sddisk_r.c 42 | ATSAM4E/ff_sddisk.c> 43 | $<$: 44 | avr32_uc3/ff_flush.c 45 | avr32_uc3/ff_flush.h 46 | avr32_uc3/ff_locking.c> 47 | $<$: 48 | lpc18xx/ff_sddisk.c> 49 | $<$: 50 | linux/ff_sddisk.c> 51 | $<$: 52 | STM32F4xx/ff_sddisk.c 53 | STM32F4xx/stm32f4xx_hal_sd.c 54 | STM32F4xx/stm32f4xx_hal_sd.h 55 | STM32F4xx/stm32f4xx_ll_sdmmc.c 56 | STM32F4xx/stm32f4xx_ll_sdmmc.h> 57 | $<$: 58 | STM32F7xx/ff_sddisk.c 59 | STM32F7xx/stm32f7xx_hal_sd.c 60 | STM32F7xx/stm32f7xx_hal_sd.h> 61 | $<$: 62 | Zynq/ff_sddisk.c 63 | Zynq/xsdps_g.c 64 | Zynq/xsdps_hw.h 65 | Zynq/xsdps_info.c 66 | Zynq/xsdps_info.h 67 | Zynq/xsdps_options.c 68 | Zynq/xsdps_sinit.c 69 | Zynq/xsdps.c 70 | Zynq/xsdps.h> 71 | $<$: 72 | Zynq.2019.3/ff_sddisk.c 73 | Zynq.2019.3/xsdps_g.c 74 | Zynq.2019.3/xsdps_hw.h 75 | Zynq.2019.3/xsdps_info.c 76 | Zynq.2019.3/xsdps_info.h 77 | Zynq.2019.3/xsdps_options.c 78 | Zynq.2019.3/xsdps_sinit.c 79 | Zynq.2019.3/xsdps.c 80 | Zynq.2019.3/xsdps.h> 81 | ) 82 | 83 | target_include_directories( freertos_plus_fat_port 84 | PRIVATE 85 | $<$:${CMAKE_CURRENT_SOURCE_DIR}/avr32_uc3> 86 | $<$:${CMAKE_CURRENT_SOURCE_DIR}/STM32F4xx> 87 | $<$:${CMAKE_CURRENT_SOURCE_DIR}/STM32F7xx> 88 | $<$:${CMAKE_CURRENT_SOURCE_DIR}/Zynq> 89 | $<$:${CMAKE_CURRENT_SOURCE_DIR}/Zynq.2019.3> 90 | ) 91 | 92 | target_compile_options( freertos_plus_fat_port 93 | PRIVATE 94 | $<$:-Wno-gnu-statement-expression> 95 | $<$:-Wno-unused-parameter> 96 | ) 97 | 98 | if( (FREERTOS_PLUS_FAT_PORT STREQUAL ZYNQ_2019_3) AND NOT TARGET freertos_xil_uncached_memory ) 99 | # Note: the ZYNQ_2019_3 - assumes the use of freertos_xil_uncached_memory.h from F 100 | message(FATAL_ERROR "For FREERTOS_PLUS_FAT_PORT=ZYNQ_2019_3, must have a freertos_xil_uncached_memory target" 101 | "This can be found in FreeRTOS-Plus-TCP NetworkInterface/Zynq/uncached_memory.*") 102 | endif() 103 | 104 | target_link_libraries( freertos_plus_fat_port 105 | PUBLIC 106 | freertos_plus_fat_port_common 107 | PRIVATE 108 | freertos_plus_fat 109 | freertos_kernel 110 | 111 | $<$:freertos_xil_uncached_memory> 112 | ) 113 | -------------------------------------------------------------------------------- /include/ff_sys.h: -------------------------------------------------------------------------------- 1 | /* 2 | * FreeRTOS+FAT V2.3.3 3 | * Copyright (C) 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved. 4 | * 5 | * Permission is hereby granted, free of charge, to any person obtaining a copy of 6 | * this software and associated documentation files (the "Software"), to deal in 7 | * the Software without restriction, including without limitation the rights to 8 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 9 | * the Software, and to permit persons to whom the Software is furnished to do so, 10 | * 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, FITNESS 17 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 18 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 19 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 20 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | * 22 | * https://www.FreeRTOS.org 23 | * https://github.com/FreeRTOS 24 | * 25 | */ 26 | 27 | /* 28 | * ff_sys.h 29 | * 30 | * This module allow to map several separate file-sub-systems into a root directory 31 | * 32 | * For instance, a system with 3 sub sytems: 33 | * 34 | * /flash : NAND flash driver 35 | * /ram : RAM-disk driver 36 | * / : SD-card driver 37 | * 38 | * In this example, the SD-card driver handles ALL files and directories which 39 | * do not match /flash/ * or /ram/ * 40 | * 41 | * Now for instance a file call "/flash/etc/network.ini" 42 | * will be stored as "/etc/network.ini" on the NAND drive 43 | * 44 | * This module along with ff_stdio.c make translations between absolute 45 | * and relative paths 46 | */ 47 | 48 | #ifndef FF_SYS_H 49 | #define FF_SYS_H 50 | 51 | #ifdef __cplusplus 52 | extern "C" { 53 | #endif 54 | 55 | typedef struct FILE_SUB_SYSTEM 56 | { 57 | char pcPath[ 16 ]; 58 | BaseType_t xPathlen; 59 | FF_IOManager_t * pxManager; 60 | } FF_SubSystem_t; 61 | 62 | typedef struct FF_DIR_HANDLER 63 | { 64 | union 65 | { 66 | struct 67 | { 68 | unsigned 69 | bEndOfDir : 1, 70 | bFirstCalled : 1, 71 | bIsValid : 1, 72 | bAddDotEntries : 2; 73 | } bits; 74 | unsigned uFlags; 75 | } u; 76 | 77 | /* 78 | * path will contain the relative path. It will be used when calling +FAT functions 79 | * like FF_FindFirst() / FF_FindNext() 80 | * For instance, for "/flash/etc" path will become "/etc" 81 | */ 82 | const char * pcPath; 83 | FF_IOManager_t * pxManager; /* Will point to handler of this partition. */ 84 | BaseType_t xFSIndex; /* The index of this entry, where 0 always means: the root system. */ 85 | } FF_DirHandler_t; 86 | 87 | /* 88 | * Initialise (clear) the file system table 89 | * This will also called by FF_FS_Add() 90 | */ 91 | void FF_FS_Init( void ); 92 | 93 | /* 94 | * Add a file system 95 | * The path must be absolute, e.g. start with a slash 96 | * The second argument is the FF_Disk_t structure that is handling the driver 97 | */ 98 | int FF_FS_Add( const char * pcPath, 99 | FF_Disk_t * pxDisk ); 100 | 101 | /* 102 | * Remove a file system 103 | * which ws earlier added by ff_fs_ad() 104 | */ 105 | void FF_FS_Remove( const char * pcPath ); 106 | 107 | /* 108 | * Internally used by ff_stdio: 109 | * The ff_dir_handler helps to iterate through a mounted directory 110 | * 111 | * FF_FS_Find() will find a ff_dir_handler for a given path 112 | */ 113 | int FF_FS_Find( const char * pcPath, 114 | FF_DirHandler_t * pxHandler ); 115 | 116 | /* 117 | * For internal use: 118 | * Get the file system information, based on an index 119 | */ 120 | int FF_FS_Get( int iIndex, 121 | FF_SubSystem_t * pxSystem ); 122 | 123 | /* 124 | * Returns the number of registered 125 | * file systems 126 | */ 127 | int FF_FS_Count( void ); 128 | 129 | #ifdef __cplusplus 130 | } /* extern "C" */ 131 | #endif 132 | 133 | #endif /* FF_SYS_H */ 134 | -------------------------------------------------------------------------------- /include/ff_fatdef.h: -------------------------------------------------------------------------------- 1 | /* 2 | * FreeRTOS+FAT V2.3.3 3 | * Copyright (C) 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved. 4 | * 5 | * Permission is hereby granted, free of charge, to any person obtaining a copy of 6 | * this software and associated documentation files (the "Software"), to deal in 7 | * the Software without restriction, including without limitation the rights to 8 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 9 | * the Software, and to permit persons to whom the Software is furnished to do so, 10 | * 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, FITNESS 17 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 18 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 19 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 20 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | * 22 | * https://www.FreeRTOS.org 23 | * https://github.com/FreeRTOS 24 | * 25 | */ 26 | 27 | #ifndef _FF_FATDEF_H_ 28 | #define _FF_FATDEF_H_ 29 | 30 | /* 31 | * This file defines offsets to various data for the FAT specification. 32 | */ 33 | 34 | /* MBR / PBR Offsets. */ 35 | 36 | #define FF_FAT_BYTES_PER_SECTOR 0x00B 37 | #define FF_FAT_SECTORS_PER_CLUS 0x00D 38 | #define FF_FAT_RESERVED_SECTORS 0x00E 39 | #define FF_FAT_NUMBER_OF_FATS 0x010 40 | #define FF_FAT_ROOT_ENTRY_COUNT 0x011 41 | #define FF_FAT_16_TOTAL_SECTORS 0x013 42 | #define FF_FAT_MEDIA_TYPE 0x015 43 | 44 | #define FF_FAT_32_TOTAL_SECTORS 0x020 45 | #define FF_FAT_16_SECTORS_PER_FAT 0x016 46 | #define FF_FAT_32_SECTORS_PER_FAT 0x024 47 | #define FF_FAT_ROOT_DIR_CLUSTER 0x02C 48 | #define FF_FAT_EXT_BOOT_SIGNATURE 0x042 49 | 50 | #define FF_FAT_16_VOL_LABEL 0x02B 51 | #define FF_FAT_32_VOL_LABEL 0x047 52 | 53 | #define FF_FAT_PTBL 0x1BE 54 | #define FF_FAT_PTBL_LBA 0x008 55 | #define FF_FAT_PTBL_SECT_COUNT 0x00C 56 | #define FF_FAT_PTBL_ACTIVE 0x000 57 | #define FF_FAT_PTBL_ID 0x004 58 | 59 | #define FF_DOS_EXT_PART 0x05 60 | #define FF_LINUX_EXT_PART 0x85 61 | #define FF_WIN98_EXT_PART 0x0f 62 | 63 | #define FF_FAT_MBR_SIGNATURE 0x1FE 64 | 65 | #define FF_FAT_DELETED 0xE5 66 | 67 | /* Directory Entry Offsets. */ 68 | #define FF_FAT_DIRENT_SHORTNAME 0x000 69 | #define FF_FAT_DIRENT_ATTRIB 0x00B 70 | #define FF_FAT_DIRENT_CREATE_TIME 0x00E /* Creation Time. */ 71 | #define FF_FAT_DIRENT_CREATE_DATE 0x010 /* Creation Date. */ 72 | #define FF_FAT_DIRENT_LASTACC_DATE 0x012 /* Date of Last Access. */ 73 | #define FF_FAT_DIRENT_CLUS_HIGH 0x014 74 | #define FF_FAT_DIRENT_LASTMOD_TIME 0x016 /* Time of Last modification. */ 75 | #define FF_FAT_DIRENT_LASTMOD_DATE 0x018 /* Date of Last modification. */ 76 | #define FF_FAT_DIRENT_CLUS_LOW 0x01A 77 | #define FF_FAT_DIRENT_FILESIZE 0x01C 78 | #define FF_FAT_LFN_ORD 0x000 79 | #define FF_FAT_LFN_NAME_1 0x001 80 | #define FF_FAT_LFN_CHECKSUM 0x00D 81 | #define FF_FAT_LFN_NAME_2 0x00E 82 | #define FF_FAT_LFN_NAME_3 0x01C 83 | 84 | /* Dirent Attributes. */ 85 | #define FF_FAT_ATTR_READONLY 0x01 86 | #define FF_FAT_ATTR_HIDDEN 0x02 87 | #define FF_FAT_ATTR_SYSTEM 0x04 88 | #define FF_FAT_ATTR_VOLID 0x08 89 | #define FF_FAT_ATTR_DIR 0x10 90 | #define FF_FAT_ATTR_ARCHIVE 0x20 91 | #define FF_FAT_ATTR_LFN 0x0F 92 | 93 | /** 94 | * -- Hein_Tibosch additions for mixed case in shortnames -- 95 | * 96 | * Specifically, bit 4 means lowercase extension and bit 3 lowercase basename, 97 | * which allows for combinations such as "example.TXT" or "HELLO.txt" but not "Mixed.txt" 98 | */ 99 | 100 | #define FF_FAT_CASE_OFFS 0x0C /* After NT/XP : 2 case bits. */ 101 | #define FF_FAT_CASE_ATTR_BASE 0x08 102 | #define FF_FAT_CASE_ATTR_EXT 0x10 103 | 104 | #if ( ffconfigLFN_SUPPORT != 0 ) && ( ffconfigINCLUDE_SHORT_NAME != 0 ) 105 | #define FF_FAT_ATTR_IS_LFN 0x40 /* artificial attribute, for debugging only. */ 106 | #endif 107 | 108 | #endif /* ifndef _FF_FATDEF_H_ */ 109 | -------------------------------------------------------------------------------- /test/build-combination/Common/main.c: -------------------------------------------------------------------------------- 1 | /* 2 | * FreeRTOS+FAT 3 | * Copyright (C) 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved. 4 | * 5 | * SPDX-License-Identifier: MIT 6 | * 7 | * Permission is hereby granted, free of charge, to any person obtaining a copy of 8 | * this software and associated documentation files (the "Software"), to deal in 9 | * the Software without restriction, including without limitation the rights to 10 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 11 | * the Software, and to permit persons to whom the Software is furnished to do so, 12 | * subject to the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be included in all 15 | * copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 19 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 20 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 21 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 22 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 23 | * 24 | * http://aws.amazon.com/freertos 25 | * http://www.FreeRTOS.org 26 | */ 27 | 28 | /** 29 | * @file main.c 30 | * @brief Implements the main function. 31 | */ 32 | 33 | /* FreeRTOS include. */ 34 | #include 35 | #include "task.h" 36 | 37 | /* System application includes. */ 38 | #include "FreeRTOSConfig.h" 39 | #include "ff_headers.h" 40 | #include "ff_stdio.h" 41 | #include "ff_ramdisk.h" 42 | 43 | /* The number and size of sectors that will make up the RAM disk. The RAM disk 44 | * is huge to allow some verbose FTP tests used in previous demos. */ 45 | #define mainRAM_DISK_SECTOR_SIZE 512UL /* Currently fixed! */ 46 | #define mainRAM_DISK_SECTORS ( ( 5UL * 1024UL * 1024UL ) / mainRAM_DISK_SECTOR_SIZE ) /* 5M bytes. */ 47 | #define mainIO_MANAGER_CACHE_SIZE ( 15UL * mainRAM_DISK_SECTOR_SIZE ) 48 | 49 | /* Where the RAM disk is mounted. */ 50 | #define mainRAM_DISK_NAME "/ram" 51 | 52 | /*-----------------------------------------------------------*/ 53 | int main( void ) 54 | { 55 | /* Initialize the FAT RamDisk */ 56 | static uint8_t ucRAMDisk[ mainRAM_DISK_SECTORS * mainRAM_DISK_SECTOR_SIZE ]; 57 | FF_Disk_t * pxDisk; 58 | 59 | /* Create the RAM disk. */ 60 | pxDisk = FF_RAMDiskInit( mainRAM_DISK_NAME, ucRAMDisk, mainRAM_DISK_SECTORS, mainIO_MANAGER_CACHE_SIZE ); 61 | configASSERT( pxDisk ); 62 | 63 | vTaskStartScheduler(); 64 | 65 | return 0; 66 | } 67 | /*-----------------------------------------------------------*/ 68 | #if ( configUSE_IDLE_HOOK != 0 ) 69 | 70 | void vApplicationIdleHook( void ) 71 | { 72 | /* Exit. Just a stub. */ 73 | } 74 | #endif 75 | /*-----------------------------------------------------------*/ 76 | 77 | #if ( configSUPPORT_STATIC_ALLOCATION == 1 ) 78 | 79 | void vApplicationGetIdleTaskMemory( StaticTask_t ** ppxIdleTaskTCBBuffer, 80 | StackType_t ** ppxIdleTaskStackBuffer, 81 | configSTACK_DEPTH_TYPE * puxIdleTaskStackSize ) 82 | { 83 | /* Provide a stub for this function. */ 84 | ( void ) ppxIdleTaskTCBBuffer; 85 | ( void ) ppxIdleTaskStackBuffer; 86 | ( void ) puxIdleTaskStackSize; 87 | } 88 | #endif /* if ( configSUPPORT_STATIC_ALLOCATION == 1 ) */ 89 | 90 | /*-----------------------------------------------------------*/ 91 | #if ( configUSE_TICK_HOOK != 0 ) 92 | void vApplicationTickHook( void ) 93 | { 94 | /* Provide a stub for this function. */ 95 | } 96 | #endif 97 | 98 | /*-----------------------------------------------------------*/ 99 | #if ( configUSE_DAEMON_TASK_STARTUP_HOOK != 0 ) 100 | void vApplicationDaemonTaskStartupHook( void ) 101 | { 102 | /* Provide a stub for this function. */ 103 | } 104 | #endif 105 | 106 | #if ( configSUPPORT_STATIC_ALLOCATION == 1 ) 107 | 108 | /* 109 | * Callback that provides the inputs necessary to generate a randomized TCP 110 | * Initial Sequence Number per RFC 6528. THIS IS ONLY A DUMMY IMPLEMENTATION 111 | * THAT RETURNS A PSEUDO RANDOM NUMBER SO IS NOT INTENDED FOR USE IN PRODUCTION 112 | * SYSTEMS. 113 | */ 114 | void vApplicationGetTimerTaskMemory( StaticTask_t ** ppxTimerTaskTCBBuffer, 115 | StackType_t ** ppxTimerTaskStackBuffer, 116 | uint32_t * pulTimerTaskStackSize ) 117 | { 118 | /* Provide a stub for this function. */ 119 | ( void ) ppxTimerTaskTCBBuffer; 120 | ( void ) ppxTimerTaskStackBuffer; 121 | ( void ) pulTimerTaskStackSize; 122 | } 123 | #endif /* if ( configSUPPORT_STATIC_ALLOCATION == 1 ) */ 124 | 125 | void vApplicationMallocFailedHook( void ) 126 | { 127 | /* Provide a stub for this function. */ 128 | } 129 | -------------------------------------------------------------------------------- /include/FreeRTOS_errno_FAT.h: -------------------------------------------------------------------------------- 1 | /* 2 | * FreeRTOS+FAT V2.3.3 3 | * Copyright (C) 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved. 4 | * 5 | * Permission is hereby granted, free of charge, to any person obtaining a copy of 6 | * this software and associated documentation files (the "Software"), to deal in 7 | * the Software without restriction, including without limitation the rights to 8 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 9 | * the Software, and to permit persons to whom the Software is furnished to do so, 10 | * 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, FITNESS 17 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 18 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 19 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 20 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | * 22 | * https://www.FreeRTOS.org 23 | * https://github.com/FreeRTOS 24 | * 25 | */ 26 | 27 | #ifndef FREERTOS_ERRNO_FAT 28 | #define FREERTOS_ERRNO_FAT 29 | 30 | /* The following definitions will be included in the core FreeRTOS code in 31 | * future versions of FreeRTOS - hence the 'pd' (ProjDefs) prefix - at which time 32 | * this file will be removed. */ 33 | 34 | /* The following errno values are used by FreeRTOS+ components, not FreeRTOS 35 | * itself. */ 36 | 37 | /* For future compatibility (see comment above), check the definitions have not 38 | * already been made. */ 39 | #ifndef pdFREERTOS_ERRNO_NONE 40 | #define pdFREERTOS_ERRNO_NONE 0 /* No errors */ 41 | #define pdFREERTOS_ERRNO_ENOENT 2 /* No such file or directory */ 42 | #define pdFREERTOS_ERRNO_EIO 5 /* I/O error */ 43 | #define pdFREERTOS_ERRNO_ENXIO 6 /* No such device or address */ 44 | #define pdFREERTOS_ERRNO_EBADF 9 /* Bad file number */ 45 | #define pdFREERTOS_ERRNO_EAGAIN 11 /* No more processes */ 46 | #define pdFREERTOS_ERRNO_EWOULDBLOCK 11 /* Operation would block */ 47 | #define pdFREERTOS_ERRNO_ENOMEM 12 /* Not enough memory */ 48 | #define pdFREERTOS_ERRNO_EACCES 13 /* Permission denied */ 49 | #define pdFREERTOS_ERRNO_EFAULT 14 /* Bad address */ 50 | #define pdFREERTOS_ERRNO_EBUSY 16 /* Mount device busy */ 51 | #define pdFREERTOS_ERRNO_EEXIST 17 /* File exists */ 52 | #define pdFREERTOS_ERRNO_EXDEV 18 /* Cross-device link */ 53 | #define pdFREERTOS_ERRNO_ENODEV 19 /* No such device */ 54 | #define pdFREERTOS_ERRNO_ENOTDIR 20 /* Not a directory */ 55 | #define pdFREERTOS_ERRNO_EISDIR 21 /* Is a directory */ 56 | #define pdFREERTOS_ERRNO_EINVAL 22 /* Invalid argument */ 57 | #define pdFREERTOS_ERRNO_ENOSPC 28 /* No space left on device */ 58 | #define pdFREERTOS_ERRNO_ESPIPE 29 /* Illegal seek */ 59 | #define pdFREERTOS_ERRNO_EROFS 30 /* Read only file system */ 60 | #define pdFREERTOS_ERRNO_EUNATCH 42 /* Protocol driver not attached */ 61 | #define pdFREERTOS_ERRNO_EBADE 50 /* Invalid exchange */ 62 | #define pdFREERTOS_ERRNO_EFTYPE 79 /* Inappropriate file type or format */ 63 | #define pdFREERTOS_ERRNO_ENMFILE 89 /* No more files */ 64 | #define pdFREERTOS_ERRNO_ENOTEMPTY 90 /* Directory not empty */ 65 | #define pdFREERTOS_ERRNO_ENAMETOOLONG 91 /* File or path name too long */ 66 | #define pdFREERTOS_ERRNO_EOPNOTSUPP 95 /* Operation not supported on transport endpoint */ 67 | #define pdFREERTOS_ERRNO_ENOBUFS 105 /* No buffer space available */ 68 | #define pdFREERTOS_ERRNO_ENOPROTOOPT 109 /* Protocol not available */ 69 | #define pdFREERTOS_ERRNO_EADDRINUSE 112 /* Address already in use */ 70 | #define pdFREERTOS_ERRNO_ETIMEDOUT 116 /* Connection timed out */ 71 | #define pdFREERTOS_ERRNO_EINPROGRESS 119 /* Connection already in progress */ 72 | #define pdFREERTOS_ERRNO_EALREADY 120 /* Socket already connected */ 73 | #define pdFREERTOS_ERRNO_EADDRNOTAVAIL 125 /* Address not available */ 74 | #define pdFREERTOS_ERRNO_EISCONN 127 /* Socket is already connected */ 75 | #define pdFREERTOS_ERRNO_ENOTCONN 128 /* Socket is not connected */ 76 | #define pdFREERTOS_ERRNO_ENOMEDIUM 135 /* No medium inserted */ 77 | #define pdFREERTOS_ERRNO_EILSEQ 138 /* An invalid UTF-16 sequence was encountered. */ 78 | #define pdFREERTOS_ERRNO_ECANCELED 140 /* Operation canceled. */ 79 | 80 | /* The following endian values are used by FreeRTOS+ components, not FreeRTOS 81 | * itself. */ 82 | #define pdFREERTOS_LITTLE_ENDIAN 0 83 | #define pdFREERTOS_BIG_ENDIAN 1 84 | 85 | #endif /* pdFREERTOS_ERRNO_NONE */ 86 | 87 | #endif /* FREERTOS_ERRNO_FAT */ 88 | -------------------------------------------------------------------------------- /.github/CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contribution guidelines 2 | 3 | Thank you for your interest in contributing to our project. Whether it's a bug 4 | report, new feature, code, or documentation, we welcome our community to be 5 | involved in this project. 6 | 7 | Please read through this document before submitting any issues or pull requests 8 | to ensure we are able to help you and all members of the community as 9 | effectively as possible. 10 | 11 | ## Code of conduct 12 | 13 | This project has adopted the 14 | [Amazon Open Source Code of Conduct](https://aws.github.io/code-of-conduct). 15 | For more information see the 16 | [Code of Conduct FAQ](https://aws.github.io/code-of-conduct-faq) or contact 17 | opensource-codeofconduct@amazon.com with any additional questions or comments. 18 | 19 | ## Security issue notifications 20 | 21 | If you discover a potential security issue in this project we ask that you 22 | notify AWS/Amazon Security via our 23 | [vulnerability reporting page](http://aws.amazon.com/security/vulnerability-reporting/). 24 | Please do **not** create a public github issue. 25 | 26 | ## Submitting a bugs/feature request 27 | 28 | Have a bug to report or feature to request? Follow these steps: 29 | 30 | 1. Search on the 31 | [FreeRTOS Community Support Forums](https://forums.freertos.org/), 32 | [FreeRTOS-Plus-FAT issue tracker](https://github.com/FreeRTOS/Lab-Project-FreeRTOS-FAT/issues?utf8=%E2%9C%93&q=is%3Aissue) 33 | and 34 | [FreeRTOS GitHub issue tracker](https://github.com/FreeRTOS/FreeRTOS/issues?utf8=%E2%9C%93&q=is%3Aissue) 35 | to be sure this hasn't been already reported or discussed. 36 | 2. If your search turns up empty, create a new topic in the 37 | [forums](https://forums.freertos.org/) and work with the community to help 38 | clarify issues or refine the idea. Include as many of the details listed below. 39 | 3. Once the community has had time to discuss and digest, we welcome you to 40 | create an [issue](https://github.com/FreeRTOS/Lab-Project-FreeRTOS-FAT/issues) 41 | to report bugs or suggest features. 42 | 43 | When creating a new topic on the forums or filing an issue, please include as many relevant details as possible. Examples include: 44 | 45 | * A clear description of the situation — what you observe, what you expect, 46 | and your view on how the two differ. 47 | * A reproducible test case or sequence of steps. 48 | * The version of our code being used. 49 | * Any modifications you've made relevant to the bug. 50 | * Details of your environment or deployment. Highlight anything unusual. 51 | 52 | ## Contributing via pull request 53 | 54 | Contributions via pull requests are much appreciated. Before sending us a pull 55 | request, please ensure that: 56 | 57 | 1. You are working against the latest source on the *main* branch. 58 | 2. You check existing open, and recently merged, pull requests to make sure 59 | someone else hasn't addressed the problem already. 60 | 3. You open an issue to discuss any significant work - we would hate for your 61 | time to be wasted. 62 | 63 | To send us a pull request, please: 64 | 65 | 1. Fork the repository. 66 | 2. Modify the source; focus on the specific change you are contributing. 67 | If you also reformat all the code, it will be hard for us to focus on your 68 | change. 69 | 3. Follow the 70 | [coding style guide](https://www.freertos.org/FreeRTOS-Coding-Standard-and-Style-Guide.html). 71 | 4. Commit to your fork using clear commit messages. 72 | 5. Send us a pull request, answering any default questions in the pull request interface. 73 | NOTE: Please make sure the default option (Allow edits from maintainers) is left checked. 74 | 6. Pay attention to any automated CI failures reported in the pull request, and stay involved in the conversation. 75 | 76 | GitHub provides additional document on 77 | [forking a repository](https://help.github.com/articles/fork-a-repo/) and 78 | [creating a pull request](https://help.github.com/articles/creating-a-pull-request/). 79 | 80 | ## Coding style 81 | 82 | * Please ensure that your code complies to the 83 | [FreeRTOS coding style guidelines](https://www.freertos.org/FreeRTOS-Coding-Standard-and-Style-Guide.html). 84 | 85 | ## Getting your pull request merged 86 | 87 | All pull requests must be approved by our review team before it can be merged 88 | in. We appreciate your patience while pull requests are reviewed. The time it 89 | takes to review will depend on complexity and consideration of wider 90 | implications. 91 | 92 | ## Finding contributions to work on 93 | 94 | Looking at the existing issues is a great way to find something to contribute 95 | on. As our projects, by default, use the default GitHub issue labels 96 | (enhancement/ bug/duplicate/help wanted/invalid/question/wontfix), tackling open 97 | 'help wanted' issues is a great place to start. 98 | 99 | ## Licensing 100 | 101 | The FreeRTOS-Plus-FAT library is released under the MIT open source license, 102 | the text of which can be found 103 | [here](https://github.com/FreeRTOS/Lab-Project-FreeRTOS-FAT/blob/main/LICENSE.md) 104 | 105 | Additional license files can be found in the folders containing any 106 | supplementary libraries licensed by their respective copyright owners where 107 | applicable. 108 | 109 | We may ask you to sign a 110 | [Contributor License Agreement (CLA)](http://en.wikipedia.org/wiki/Contributor_License_Agreement) 111 | for larger changes. 112 | -------------------------------------------------------------------------------- /include/ff_string.h: -------------------------------------------------------------------------------- 1 | /* 2 | * FreeRTOS+FAT V2.3.3 3 | * Copyright (C) 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved. 4 | * 5 | * Permission is hereby granted, free of charge, to any person obtaining a copy of 6 | * this software and associated documentation files (the "Software"), to deal in 7 | * the Software without restriction, including without limitation the rights to 8 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 9 | * the Software, and to permit persons to whom the Software is furnished to do so, 10 | * 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, FITNESS 17 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 18 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 19 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 20 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | * 22 | * https://www.FreeRTOS.org 23 | * https://github.com/FreeRTOS 24 | * 25 | */ 26 | 27 | /** 28 | * @file ff_string.c 29 | * @ingroup STRING 30 | * 31 | * @defgroup STRING FreeRTOS+FAT String Library 32 | * @brief Portable String Library for FreeRTOS+FAT 33 | * 34 | * 35 | **/ 36 | 37 | #ifndef _FF_STRING_H_ 38 | #define _FF_STRING_H_ 39 | 40 | #include "FreeRTOSFATConfig.h" 41 | #include 42 | 43 | #if ( ffconfigUNICODE_UTF16_SUPPORT != 0 ) 44 | #include 45 | typedef wchar_t FF_T_WCHAR; /*/< Unicode UTF-16 Character type, for FreeRTOS+FAT when UNICODE is enabled. */ 46 | #endif 47 | 48 | #if defined( _MSC_VER ) && ( _MSC_VER <= 1600 ) 49 | #define FF_stricmp _stricmp 50 | #else 51 | #define FF_stricmp strcasecmp 52 | #endif 53 | 54 | #if ( ffconfigUNICODE_UTF16_SUPPORT != 0 ) 55 | void FF_tolower( FF_T_WCHAR * string, 56 | uint32_t strLen ); 57 | void FF_toupper( FF_T_WCHAR * string, 58 | uint32_t strLen ); 59 | BaseType_t FF_strmatch( const FF_T_WCHAR * str1, 60 | const FF_T_WCHAR * str2, 61 | BaseType_t len ); 62 | FF_T_WCHAR * FF_strtok( const FF_T_WCHAR * string, 63 | FF_T_WCHAR * token, 64 | uint16_t * tokenNumber, 65 | BaseType_t * last, 66 | BaseType_t xLength ); 67 | BaseType_t FF_wildcompare( const FF_T_WCHAR * pcWildCard, 68 | const FF_T_WCHAR * pszString ); 69 | 70 | /* ASCII to UTF16 and UTF16 to ASCII routines. -- These are lossy routines, and are only for converting ASCII to UTF-16 */ 71 | /* and the equivalent back to ASCII. Do not use them for international text. */ 72 | void FF_cstrtowcs( FF_T_WCHAR * wcsDest, 73 | const char * szpSource ); 74 | void FF_wcstocstr( char * szpDest, 75 | const FF_T_WCHAR * wcsSource ); 76 | void FF_cstrntowcs( FF_T_WCHAR * wcsDest, 77 | const char * szpSource, 78 | uint32_t len ); 79 | void FF_wcsntocstr( char * szpDest, 80 | const FF_T_WCHAR * wcsSource, 81 | uint32_t len ); 82 | #else /* if ( ffconfigUNICODE_UTF16_SUPPORT != 0 ) */ 83 | void FF_tolower( char * string, 84 | uint32_t strLen ); 85 | void FF_toupper( char * string, 86 | uint32_t strLen ); 87 | BaseType_t FF_strmatch( const char * str1, 88 | const char * str2, 89 | BaseType_t len ); 90 | char * FF_strtok( const char * string, 91 | char * token, 92 | uint16_t * tokenNumber, 93 | BaseType_t * last, 94 | BaseType_t xLength ); 95 | BaseType_t FF_wildcompare( const char * pcWildCard, 96 | const char * pszString ); 97 | #endif /* ffconfigUNICODE_UTF16_SUPPORT */ 98 | 99 | /* UTF8 / UTF16 Transformation Functions. */ 100 | 101 | #if ( ( ffconfigUNICODE_UTF16_SUPPORT != 0 ) && ( WCHAR_MAX > 0xFFFF ) ) || ( ffconfigUNICODE_UTF8_SUPPORT != 0 ) 102 | UBaseType_t FF_GetUtf16SequenceLen( uint16_t usLeadChar ); 103 | #endif 104 | 105 | #if ( ffconfigUNICODE_UTF8_SUPPORT != 0 ) 106 | int32_t FF_Utf8ctoUtf16c( uint16_t * utf16Dest, 107 | const uint8_t * utf8Source, 108 | uint32_t ulSize ); 109 | int32_t FF_Utf16ctoUtf8c( uint8_t * utf8Dest, 110 | const uint16_t * utf16Source, 111 | uint32_t ulSize ); 112 | #endif /* ffconfigUNICODE_UTF8_SUPPORT */ 113 | 114 | /* UTF16 / UTF32 Transformation Functions. */ 115 | 116 | #if ( ffconfigNOT_USED_FOR_NOW != 0 ) 117 | int32_t FF_Utf16ctoUtf32c( uint32_t * utf32Dest, 118 | const uint16_t * utf16Source ); 119 | #endif 120 | 121 | #if ( ffconfigUNICODE_UTF16_SUPPORT != 0 ) && ( WCHAR_MAX > 0xFFFF ) 122 | int32_t FF_Utf32ctoUtf16c( uint16_t * utf16Dest, 123 | uint32_t utf32char, 124 | uint32_t ulSize ); 125 | #endif 126 | 127 | /* String transformations. */ 128 | int32_t FF_Utf32stoUtf8s( uint8_t * Utf8String, 129 | uint32_t * Utf32String ); 130 | 131 | #if ( ffconfigUNICODE_UTF16_SUPPORT != 0 ) 132 | #define STRNCPY( target, src, maxlen ) wcsncpy( ( target ), ( src ), ( maxlen ) ) 133 | #define STRLEN( string ) wcslen( ( string ) ) 134 | #else 135 | #define STRNCPY( target, src, maxlen ) strncpy( ( target ), ( src ), ( maxlen ) ) 136 | #define STRLEN( string ) strlen( ( string ) ) 137 | #endif 138 | 139 | #endif /* ifndef _FF_STRING_H_ */ 140 | -------------------------------------------------------------------------------- /include/ff_memory.h: -------------------------------------------------------------------------------- 1 | /* 2 | * FreeRTOS+FAT V2.3.3 3 | * Copyright (C) 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved. 4 | * 5 | * Permission is hereby granted, free of charge, to any person obtaining a copy of 6 | * this software and associated documentation files (the "Software"), to deal in 7 | * the Software without restriction, including without limitation the rights to 8 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 9 | * the Software, and to permit persons to whom the Software is furnished to do so, 10 | * 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, FITNESS 17 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 18 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 19 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 20 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | * 22 | * https://www.FreeRTOS.org 23 | * https://github.com/FreeRTOS 24 | * 25 | */ 26 | 27 | /** 28 | * @file ff_memory.h 29 | * @ingroup MEMORY 30 | **/ 31 | 32 | #ifndef _FF_MEMORY_H_ 33 | #define _FF_MEMORY_H_ 34 | 35 | /* 36 | * When sector data is written or analysed, some values might be stored unaligned. 37 | * The routines below treat all values as little arrays of either 2 or 4 bytes. 38 | * Also on big endian platforms, the order of bytes will be swapped. 39 | */ 40 | /*---------- PROTOTYPES */ 41 | 42 | #if ( ffconfigBYTE_ORDER == pdFREERTOS_LITTLE_ENDIAN ) 43 | 44 | /* 45 | * FAT is little endian. 46 | * On a little endian CPU, bytes will be copied to the structures below 1-to-1 : 47 | */ 48 | typedef struct 49 | { 50 | uint8_t u8_0; /* the first byte */ 51 | uint8_t u8_1; /* the second byte */ 52 | } FF_TShort_t; 53 | 54 | typedef struct 55 | { 56 | uint8_t u8_0; 57 | uint8_t u8_1; 58 | uint8_t u8_2; 59 | uint8_t u8_3; 60 | } FF_TLong_t; 61 | #elif ( ffconfigBYTE_ORDER == pdFREERTOS_BIG_ENDIAN ) 62 | 63 | /* 64 | * On a big endian CPU, all bytes will be swapped, either 2 or 4 bytes: 65 | */ 66 | typedef struct 67 | { 68 | uint8_t u8_1; /* the second byte */ 69 | uint8_t u8_0; /* the first byte */ 70 | } FF_TShort_t; 71 | 72 | typedef struct 73 | { 74 | uint8_t u8_3; 75 | uint8_t u8_2; 76 | uint8_t u8_1; 77 | uint8_t u8_0; 78 | } FF_TLong_t; 79 | #else /* if ( ffconfigBYTE_ORDER == pdFREERTOS_LITTLE_ENDIAN ) */ 80 | #error Little or Big Endian? - Please set ffconfigBYTE_ORDER to either pdFREERTOS_LITTLE_ENDIAN or pdFREERTOS_BIG_ENDIAN 1 in FreeRTOSFATConfig.h 81 | #endif /* if ( ffconfigBYTE_ORDER == pdFREERTOS_LITTLE_ENDIAN ) */ 82 | 83 | /*! 16-bit union. */ 84 | typedef union 85 | { 86 | uint16_t u16; 87 | FF_TShort_t bytes; 88 | } FF_T_UN16; 89 | 90 | /*! 32-bit union. */ 91 | typedef union 92 | { 93 | uint32_t u32; 94 | FF_TLong_t bytes; 95 | } FF_T_UN32; 96 | 97 | /* HT inlined these functions: 98 | */ 99 | 100 | #if ( ffconfigINLINE_MEMORY_ACCESS != 0 ) 101 | 102 | static portINLINE uint8_t FF_getChar( const uint8_t * pBuffer, 103 | uint32_t aOffset ) 104 | { 105 | return ( uint8_t ) ( pBuffer[ aOffset ] ); 106 | } 107 | 108 | static portINLINE uint16_t FF_getShort( const uint8_t * pBuffer, 109 | uint32_t aOffset ) 110 | { 111 | FF_T_UN16 u16; 112 | 113 | pBuffer += aOffset; 114 | u16.bytes.u8_1 = pBuffer[ 1 ]; 115 | u16.bytes.u8_0 = pBuffer[ 0 ]; 116 | 117 | return u16.u16; 118 | } 119 | 120 | static portINLINE uint32_t FF_getLong( const uint8_t * pBuffer, 121 | uint32_t aOffset ) 122 | { 123 | FF_T_UN32 u32; 124 | 125 | pBuffer += aOffset; 126 | u32.bytes.u8_3 = pBuffer[ 3 ]; 127 | u32.bytes.u8_2 = pBuffer[ 2 ]; 128 | u32.bytes.u8_1 = pBuffer[ 1 ]; 129 | u32.bytes.u8_0 = pBuffer[ 0 ]; 130 | 131 | return u32.u32; 132 | } 133 | 134 | static portINLINE void FF_putChar( uint8_t * pBuffer, 135 | uint32_t aOffset, 136 | uint32_t Value ) 137 | { 138 | pBuffer[ aOffset ] = ( uint8_t ) Value; 139 | } 140 | 141 | static portINLINE void FF_putShort( uint8_t * pBuffer, 142 | uint32_t aOffset, 143 | uint32_t Value ) 144 | { 145 | FF_T_UN16 u16; 146 | 147 | u16.u16 = ( uint16_t ) Value; 148 | pBuffer += aOffset; 149 | pBuffer[ 0 ] = u16.bytes.u8_0; 150 | pBuffer[ 1 ] = u16.bytes.u8_1; 151 | } 152 | 153 | static portINLINE void FF_putLong( uint8_t * pBuffer, 154 | uint32_t aOffset, 155 | uint32_t Value ) 156 | { 157 | FF_T_UN32 u32; 158 | 159 | u32.u32 = Value; 160 | pBuffer += aOffset; 161 | pBuffer[ 0 ] = u32.bytes.u8_0; 162 | pBuffer[ 1 ] = u32.bytes.u8_1; 163 | pBuffer[ 2 ] = u32.bytes.u8_2; 164 | pBuffer[ 3 ] = u32.bytes.u8_3; 165 | } 166 | 167 | #else /* ffconfigINLINE_MEMORY_ACCESS */ 168 | 169 | uint8_t FF_getChar( const uint8_t * pBuffer, 170 | uint32_t aOffset ); 171 | uint16_t FF_getShort( const uint8_t * pBuffer, 172 | uint32_t aOffset ); 173 | uint32_t FF_getLong( const uint8_t * pBuffer, 174 | uint32_t aOffset ); 175 | void FF_putChar( uint8_t * pBuffer, 176 | uint32_t aOffset, 177 | uint32_t Value ); 178 | void FF_putShort( uint8_t * pBuffer, 179 | uint32_t aOffset, 180 | uint32_t Value ); 181 | void FF_putLong( uint8_t * pBuffer, 182 | uint32_t aOffset, 183 | uint32_t Value ); 184 | 185 | #endif /* ffconfigINLINE_MEMORY_ACCESS */ 186 | 187 | #endif /* _FF_MEMORY_H_ */ 188 | -------------------------------------------------------------------------------- /.github/workflows/release.yml: -------------------------------------------------------------------------------- 1 | name: Release automation 2 | 3 | on: 4 | workflow_dispatch: 5 | inputs: 6 | commit_id: 7 | description: 'Commit ID to tag and create a release for' 8 | required: true 9 | version_number: 10 | description: 'Release Version Number (Eg, v1.0.0)' 11 | required: true 12 | 13 | jobs: 14 | tag-commit: 15 | name: Tag commit 16 | runs-on: ubuntu-latest 17 | steps: 18 | - name: Checkout code 19 | uses: actions/checkout@v4 20 | with: 21 | ref: ${{ github.event.inputs.commit_id }} 22 | - name: Configure git identity 23 | env: 24 | ACTOR: ${{ github.actor }} 25 | run: | 26 | git config --global user.name "$ACTOR" 27 | git config --global user.email "$ACTOR"@users.noreply.github.com 28 | - name: create a new branch that references commit id 29 | env: 30 | VERSION_NUMBER: ${{ github.event.inputs.version_number }} 31 | COMMIT_ID: ${{ github.event.inputs.commit_id }} 32 | run: git checkout -b "$VERSION_NUMBER" "$COMMIT_ID" 33 | - name: Generate SBOM 34 | uses: FreeRTOS/CI-CD-Github-Actions/sbom-generator@main 35 | with: 36 | repo_path: ./ 37 | source_path: ./source 38 | - name: commit SBOM file 39 | env: 40 | VERSION_NUMBER: ${{ github.event.inputs.version_number }} 41 | run: | 42 | git add . 43 | git commit -m 'Update SBOM' 44 | git push -u origin "$VERSION_NUMBER" 45 | - name: Tag Commit and Push to remote 46 | env: 47 | VERSION_NUMBER: ${{ github.event.inputs.version_number }} 48 | run: | 49 | git tag "$VERSION_NUMBER" -a -m "FreeRTOS-Plus-FAT Library $VERSION_NUMBER" 50 | git push origin --tags 51 | - name: Verify tag on remote 52 | env: 53 | VERSION_NUMBER: ${{ github.event.inputs.version_number }} 54 | COMMIT_ID: ${{ github.event.inputs.commit_id }} 55 | run: | 56 | git tag -d "$VERSION_NUMBER" 57 | git remote update 58 | git checkout tags/"$VERSION_NUMBER" 59 | git diff "$COMMIT_ID" tags/"$VERSION_NUMBER" 60 | create-zip: 61 | needs: tag-commit 62 | name: Create ZIP and verify package for release asset. 63 | runs-on: ubuntu-latest 64 | steps: 65 | - name: Install ZIP tools 66 | run: sudo apt-get install zip unzip 67 | - name: Checkout code 68 | uses: actions/checkout@v4 69 | with: 70 | ref: ${{ github.event.inputs.version_number }} 71 | path: FreeRTOS-Plus-FAT 72 | submodules: recursive 73 | - name: Checkout disabled submodules 74 | run: | 75 | cd FreeRTOS-Plus-FAT 76 | git submodule update --init --checkout --recursive 77 | - name: Create ZIP 78 | env: 79 | VERSION_NUMBER: ${{ github.event.inputs.version_number }} 80 | run: | 81 | zip -r FreeRTOS-Plus-FAT-"$VERSION_NUMBER".zip FreeRTOS-Plus-FAT -x "*.git*" 82 | ls ./ 83 | - name: Validate created ZIP 84 | env: 85 | VERSION_NUMBER: ${{ github.event.inputs.version_number }} 86 | run: | 87 | mkdir zip-check 88 | mv FreeRTOS-Plus-FAT-"$VERSION_NUMBER".zip zip-check 89 | cd zip-check 90 | unzip FreeRTOS-Plus-FAT-"$VERSION_NUMBER".zip -d FreeRTOS-Plus-FAT-"$VERSION_NUMBER" 91 | ls FreeRTOS-Plus-FAT-"$VERSION_NUMBER" 92 | diff -r -x "*.git*" FreeRTOS-Plus-FAT-"$VERSION_NUMBER"/FreeRTOS-Plus-FAT/ ../FreeRTOS-Plus-FAT/ 93 | cd ../ 94 | - name: Build 95 | env: 96 | VERSION_NUMBER: ${{ github.event.inputs.version_number }} 97 | run: | 98 | cd zip-check/FreeRTOS-Plus-FAT-"$VERSION_NUMBER"/FreeRTOS-Plus-FAT 99 | sudo apt-get install -y lcov 100 | sudo apt-get install unifdef 101 | cmake -S test/unit-test -B test/unit-test/build/ 102 | make -C test/unit-test/build/ all 103 | - name: Test 104 | env: 105 | VERSION_NUMBER: ${{ github.event.inputs.version_number }} 106 | run: | 107 | cd zip-check/FreeRTOS-Plus-FAT-"$VERSION_NUMBER"/FreeRTOS-Plus-FAT 108 | pushd test/unit-test/build/ 109 | ctest -E system --output-on-failure 110 | popd 111 | make -C test/unit-test/build/ coverage 112 | lcov --list --rc lcov_branch_coverage=1 test/unit-test/build/coverage.info 113 | cd .. 114 | - name: Create artifact of ZIP 115 | uses: actions/upload-artifact@v4 116 | with: 117 | name: FreeRTOS-Plus-FAT-${{ github.event.inputs.version_number }}.zip 118 | path: zip-check/FreeRTOS-Plus-FAT-${{ github.event.inputs.version_number }}.zip 119 | deploy-doxygen: 120 | needs: tag-commit 121 | name: Deploy doxygen documentation 122 | runs-on: ubuntu-latest 123 | steps: 124 | - name: Doxygen generation 125 | uses: FreeRTOS/CI-CD-Github-Actions/doxygen-generation@main 126 | with: 127 | ref: ${{ github.event.inputs.version_number }} 128 | add_release: "true" 129 | create-release: 130 | needs: 131 | - create-zip 132 | - deploy-doxygen 133 | name: Create Release and Upload Release Asset 134 | runs-on: ubuntu-latest 135 | steps: 136 | - name: Create Release 137 | id: create_release 138 | uses: actions/create-release@v1 139 | env: 140 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} 141 | with: 142 | tag_name: ${{ github.event.inputs.version_number }} 143 | release_name: ${{ github.event.inputs.version_number }} 144 | body: Release ${{ github.event.inputs.version_number }} of the FreeRTOS-Plus-FAT Library. 145 | draft: false 146 | prerelease: false 147 | - name: Download ZIP artifact 148 | uses: actions/download-artifact@v4 149 | with: 150 | name: FreeRTOS-Plus-FAT-${{ github.event.inputs.version_number }}.zip 151 | - name: Upload Release Asset 152 | id: upload-release-asset 153 | uses: actions/upload-release-asset@v1 154 | env: 155 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} 156 | with: 157 | upload_url: ${{ steps.create_release.outputs.upload_url }} 158 | asset_path: ./FreeRTOS-Plus-FAT-${{ github.event.inputs.version_number }}.zip 159 | asset_name: FreeRTOS-Plus-FAT-${{ github.event.inputs.version_number }}.zip 160 | asset_content_type: application/zip 161 | cleanup: 162 | needs: 163 | - create-release 164 | name: Cleanup 165 | runs-on: ubuntu-latest 166 | steps: 167 | - name: Checkout code 168 | uses: actions/checkout@v4 169 | - name: Delete branch created for Tag by SBOM generator 170 | env: 171 | VERSION_NUMBER: ${{ github.event.inputs.version_number }} 172 | run: | 173 | # Delete the branch created for Tag by SBOM generator 174 | git push -u origin --delete refs/heads/"$VERSION_NUMBER" 175 | -------------------------------------------------------------------------------- /include/ff_fat.h: -------------------------------------------------------------------------------- 1 | /* 2 | * FreeRTOS+FAT V2.3.3 3 | * Copyright (C) 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved. 4 | * 5 | * Permission is hereby granted, free of charge, to any person obtaining a copy of 6 | * this software and associated documentation files (the "Software"), to deal in 7 | * the Software without restriction, including without limitation the rights to 8 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 9 | * the Software, and to permit persons to whom the Software is furnished to do so, 10 | * 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, FITNESS 17 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 18 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 19 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 20 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | * 22 | * https://www.FreeRTOS.org 23 | * https://github.com/FreeRTOS 24 | * 25 | */ 26 | 27 | /** 28 | * @file ff_fat.h 29 | * @ingroup FAT 30 | **/ 31 | 32 | #ifndef _FF_FAT_H_ 33 | #define _FF_FAT_H_ 34 | 35 | #ifndef PLUS_FAT_H 36 | #error this header will be included from "ff_headers.h" 37 | #endif 38 | 39 | /*---------- ERROR CODES */ 40 | 41 | 42 | /*---------- PROTOTYPES */ 43 | 44 | /* HT statistics Will be taken away after testing: */ 45 | #if ( ffconfigFAT_USES_STAT != 0 ) 46 | struct SFatStat 47 | { 48 | unsigned initCount; 49 | unsigned clearCount; 50 | unsigned getCount[ 2 ]; /* Index 0 for READ counts, index 1 for WRITE counts. */ 51 | unsigned reuseCount[ 2 ]; 52 | unsigned missCount[ 2 ]; 53 | }; 54 | 55 | extern struct SFatStat fatStat; 56 | #endif /* if ( ffconfigFAT_USES_STAT != 0 ) */ 57 | 58 | #if ( ffconfigWRITE_BOTH_FATS != 0 ) 59 | #define ffconfigBUF_STORE_COUNT 2 60 | #else 61 | #define ffconfigBUF_STORE_COUNT 1 62 | #endif 63 | 64 | typedef struct _FatBuffers 65 | { 66 | FF_Buffer_t * pxBuffers[ ffconfigBUF_STORE_COUNT ]; 67 | uint8_t ucMode; /* FF_MODE_READ or WRITE. */ 68 | } FF_FATBuffers_t; 69 | 70 | uint32_t FF_getClusterPosition( FF_IOManager_t * pxIOManager, 71 | uint32_t ulEntry, 72 | uint32_t ulEntrySize ); 73 | uint32_t FF_getClusterChainNumber( FF_IOManager_t * pxIOManager, 74 | uint32_t ulEntry, 75 | uint32_t ulEntrySize ); 76 | uint32_t FF_getMajorBlockNumber( FF_IOManager_t * pxIOManager, 77 | uint32_t ulEntry, 78 | uint32_t ulEntrySize ); 79 | uint32_t FF_getMinorBlockNumber( FF_IOManager_t * pxIOManager, 80 | uint32_t ulEntry, 81 | uint32_t ulEntrySize ); 82 | uint32_t FF_getMinorBlockEntry( FF_IOManager_t * pxIOManager, 83 | uint32_t ulEntry, 84 | uint32_t ulEntrySize ); 85 | 86 | /* A partition may define a block size larger than 512 bytes (at offset 0x0B of the PBR). 87 | * This function translates a block address to an address based on 'pxIOManager->usBlkSize', 88 | * which is usually 512 bytes. 89 | */ 90 | static portINLINE uint32_t FF_getRealLBA( FF_IOManager_t * pxIOManager, 91 | uint32_t LBA ) 92 | { 93 | return LBA * pxIOManager->xPartition.ucBlkFactor; 94 | } 95 | 96 | uint32_t FF_Cluster2LBA( FF_IOManager_t * pxIOManager, 97 | uint32_t ulCluster ); 98 | uint32_t FF_LBA2Cluster( FF_IOManager_t * pxIOManager, 99 | uint32_t ulAddress ); 100 | uint32_t FF_getFATEntry( FF_IOManager_t * pxIOManager, 101 | uint32_t ulCluster, 102 | FF_Error_t * pxError, 103 | FF_FATBuffers_t * pxFATBuffers ); 104 | FF_Error_t FF_putFATEntry( FF_IOManager_t * pxIOManager, 105 | uint32_t ulCluster, 106 | uint32_t ulValue, 107 | FF_FATBuffers_t * pxFATBuffers ); 108 | BaseType_t FF_isEndOfChain( FF_IOManager_t * pxIOManager, 109 | uint32_t ulFatEntry ); 110 | uint32_t FF_FindFreeCluster( FF_IOManager_t * pxIOManager, 111 | FF_Error_t * pxError, 112 | BaseType_t aDoClaim ); 113 | uint32_t FF_ExtendClusterChain( FF_IOManager_t * pxIOManager, 114 | uint32_t ulStartCluster, 115 | uint32_t ulCount ); 116 | FF_Error_t FF_UnlinkClusterChain( FF_IOManager_t * pxIOManager, 117 | uint32_t ulStartCluster, 118 | BaseType_t xDoTruncate ); 119 | uint32_t FF_TraverseFAT( FF_IOManager_t * pxIOManager, 120 | uint32_t ulStart, 121 | uint32_t ulCount, 122 | FF_Error_t * pxError ); 123 | uint32_t FF_CreateClusterChain( FF_IOManager_t * pxIOManager, 124 | FF_Error_t * pxError ); 125 | uint32_t FF_GetChainLength( FF_IOManager_t * pxIOManager, 126 | uint32_t pa_nStartCluster, 127 | uint32_t * piEndOfChain, 128 | FF_Error_t * pxError ); 129 | uint32_t FF_FindEndOfChain( FF_IOManager_t * pxIOManager, 130 | uint32_t Start, 131 | FF_Error_t * pxError ); 132 | FF_Error_t FF_ClearCluster( FF_IOManager_t * pxIOManager, 133 | uint32_t ulCluster ); 134 | 135 | #if ( ffconfig64_NUM_SUPPORT != 0 ) 136 | uint64_t FF_GetFreeSize( FF_IOManager_t * pxIOManager, 137 | FF_Error_t * pxError ); 138 | #else 139 | uint32_t FF_GetFreeSize( FF_IOManager_t * pxIOManager, 140 | FF_Error_t * pxError ); 141 | #endif 142 | 143 | /* WARNING: If this prototype changes, it must be updated in ff_ioman.c also! */ 144 | uint32_t FF_CountFreeClusters( FF_IOManager_t * pxIOManager, 145 | FF_Error_t * pxError ); 146 | 147 | FF_Error_t FF_ReleaseFATBuffers( FF_IOManager_t * pxIOManager, 148 | FF_FATBuffers_t * pxFATBuffers ); 149 | 150 | static portINLINE void FF_InitFATBuffers( FF_FATBuffers_t * pxFATBuffers, 151 | uint8_t ucMode ) 152 | { 153 | pxFATBuffers->pxBuffers[ 0 ] = NULL; 154 | #if ffconfigBUF_STORE_COUNT > 1 155 | pxFATBuffers->pxBuffers[ 1 ] = NULL; 156 | #endif 157 | #if ffconfigBUF_STORE_COUNT > 2 158 | #error Please check this code, maybe it is time to use memset 159 | #endif 160 | pxFATBuffers->ucMode = ucMode; /* FF_MODE_READ/WRITE */ 161 | #if ffconfigFAT_USES_STAT 162 | { 163 | fatStat.initCount++; 164 | } 165 | #endif 166 | } 167 | 168 | #endif /* ifndef _FF_FAT_H_ */ 169 | -------------------------------------------------------------------------------- /ff_dev_support.c: -------------------------------------------------------------------------------- 1 | /* 2 | * FreeRTOS+FAT V2.3.3 3 | * Copyright (C) 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved. 4 | * 5 | * Permission is hereby granted, free of charge, to any person obtaining a copy of 6 | * this software and associated documentation files (the "Software"), to deal in 7 | * the Software without restriction, including without limitation the rights to 8 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 9 | * the Software, and to permit persons to whom the Software is furnished to do so, 10 | * 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, FITNESS 17 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 18 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 19 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 20 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | * 22 | * https://www.FreeRTOS.org 23 | * https://github.com/FreeRTOS 24 | * 25 | */ 26 | 27 | #include 28 | #include 29 | 30 | /* FreeRTOS includes. */ 31 | #include "FreeRTOS.h" 32 | #include "task.h" 33 | #include "portable.h" 34 | 35 | #include "ff_headers.h" 36 | #include "ff_devices.h" 37 | 38 | #ifndef ARRAY_SIZE 39 | #define ARRAY_SIZE( x ) ( int ) ( sizeof( x ) / sizeof( x )[ 0 ] ) 40 | #endif 41 | 42 | #if ( ffconfigDEV_SUPPORT == 0 ) 43 | #error No use to include this module if ffconfigDEV_SUPPORT is disabled 44 | #endif /* ffconfigDEV_SUPPORT == 0 */ 45 | 46 | struct SFileCache 47 | { 48 | char pcFileName[ 16 ]; 49 | uint32_t ulFileLength; 50 | uint32_t ulFilePointer; 51 | }; 52 | 53 | struct SFileCache xFiles[ 16 ]; 54 | 55 | enum eCACHE_ACTION 56 | { 57 | eCACHE_LOOKUP, 58 | eCACHE_ADD, 59 | eCACHE_REMOVE, 60 | }; 61 | 62 | const char pcDevicePath[] = ffconfigDEV_PATH; 63 | 64 | struct SFileCache * pxFindFile( const char * pcFname, 65 | enum eCACHE_ACTION eAction ) 66 | { 67 | BaseType_t xIndex, xFreeIndex = -1; 68 | struct SFileCache * pxResult = NULL; 69 | 70 | for( xIndex = 0; xIndex < ARRAY_SIZE( xFiles ); xIndex++ ) 71 | { 72 | if( xFiles[ xIndex ].pcFileName[ 0 ] == '\0' ) 73 | { 74 | if( xFreeIndex < 0 ) 75 | { 76 | xFreeIndex = xIndex; 77 | } 78 | } 79 | else if( strcmp( xFiles[ xIndex ].pcFileName, pcFname ) == 0 ) 80 | { 81 | if( eAction == eCACHE_REMOVE ) 82 | { 83 | xFiles[ xIndex ].pcFileName[ 0 ] = '\0'; 84 | } 85 | 86 | pxResult = xFiles + xIndex; 87 | break; 88 | } 89 | } 90 | 91 | if( ( pxResult == NULL ) && ( eAction == eCACHE_ADD ) && ( xFreeIndex >= 0 ) ) 92 | { 93 | pxResult = xFiles + xFreeIndex; 94 | snprintf( pxResult->pcFileName, sizeof( pxResult->pcFileName ), "%s", pcFname ); 95 | pxResult->ulFileLength = 0; 96 | pxResult->ulFilePointer = 0; 97 | } 98 | 99 | return pxResult; 100 | } 101 | 102 | BaseType_t xCheckDevicePath( const char * pcPath ) 103 | { 104 | BaseType_t xDevLength; 105 | BaseType_t xPathLength; 106 | BaseType_t xIsDevice; 107 | 108 | xDevLength = sizeof( pcDevicePath ) - 1; 109 | xPathLength = strlen( pcPath ); 110 | 111 | /* System "/dev" should not match with "/device/etc". */ 112 | if( ( xPathLength >= xDevLength ) && 113 | ( memcmp( pcDevicePath, pcPath, xDevLength ) == 0 ) && 114 | ( ( pcPath[ xDevLength ] == '\0' ) || ( pcPath[ xDevLength ] == '/' ) ) ) 115 | { 116 | xIsDevice = FF_DEV_CHAR_DEV; 117 | } 118 | else 119 | { 120 | xIsDevice = FF_DEV_NO_DEV; 121 | } 122 | 123 | return xIsDevice; 124 | } 125 | 126 | BaseType_t FF_Device_Open( const char * pcPath, 127 | FF_FILE * pxStream ) 128 | { 129 | uint8_t ucIsDevice; 130 | 131 | ucIsDevice = xCheckDevicePath( pcPath ); 132 | 133 | if( ucIsDevice != pdFALSE ) 134 | { 135 | const char * pcBaseName = pcPath; 136 | 137 | if( memcmp( pcBaseName, pcDevicePath, sizeof( pcDevicePath ) - 1 ) == 0 ) 138 | { 139 | pcBaseName = pcBaseName + sizeof( pcDevicePath ); 140 | } 141 | 142 | pxStream->pxDevNode = pxFindFile( pcBaseName, eCACHE_ADD ); 143 | 144 | if( pxStream->pxDevNode != NULL ) 145 | { 146 | pxStream->pxDevNode->ulFilePointer = 0; 147 | 148 | if( ( pxStream->ucMode & ( FF_MODE_WRITE | FF_MODE_APPEND | FF_MODE_CREATE ) ) == 0 ) 149 | { 150 | pxStream->ulFileSize = pxStream->pxDevNode->ulFileLength; 151 | } 152 | } 153 | } 154 | 155 | return ucIsDevice; 156 | } 157 | 158 | void FF_Device_Close( FF_FILE * pxStream ) 159 | { 160 | if( pxStream->pxDevNode != NULL ) 161 | { 162 | pxStream->ulFileSize = 0ul; 163 | pxStream->ulFilePointer = 0ul; 164 | } 165 | } 166 | 167 | size_t FF_Device_Read( void * pvBuf, 168 | size_t lSize, 169 | size_t lCount, 170 | FF_FILE * pxStream ) 171 | { 172 | lCount *= lSize; 173 | return lCount; 174 | } 175 | 176 | size_t FF_Device_Write( const void * pvBuf, 177 | size_t lSize, 178 | size_t lCount, 179 | FF_FILE * pxStream ) 180 | { 181 | lCount *= lSize; 182 | 183 | if( pxStream->pxDevNode != NULL ) 184 | { 185 | pxStream->pxDevNode->ulFilePointer += lCount; 186 | 187 | if( pxStream->pxDevNode->ulFileLength < pxStream->pxDevNode->ulFilePointer ) 188 | { 189 | pxStream->pxDevNode->ulFileLength = pxStream->pxDevNode->ulFilePointer; 190 | } 191 | } 192 | 193 | return lCount; 194 | } 195 | 196 | int FF_Device_Seek( FF_FILE * pxStream, 197 | long lOffset, 198 | int iWhence ) 199 | { 200 | if( pxStream->pxDevNode != NULL ) 201 | { 202 | if( iWhence == FF_SEEK_SET ) 203 | { 204 | pxStream->pxDevNode->ulFilePointer = lOffset; 205 | } 206 | else if( iWhence == FF_SEEK_END ) 207 | { 208 | pxStream->pxDevNode->ulFilePointer = pxStream->pxDevNode->ulFileLength - lOffset; 209 | } 210 | } 211 | 212 | return 0; 213 | } 214 | 215 | int FF_Device_GetDirEnt( const char * pcPath, 216 | FF_DirEnt_t * pxDirEnt ) 217 | { 218 | BaseType_t xIsDotDir = 0; 219 | 220 | if( pxDirEnt->pcFileName[ 0 ] == '.' ) 221 | { 222 | if( ( pxDirEnt->pcFileName[ 1 ] == '.' ) && 223 | ( pxDirEnt->pcFileName[ 2 ] == '\0' ) ) 224 | { 225 | xIsDotDir = 2; 226 | } 227 | else if( pxDirEnt->pcFileName[ 1 ] == '\0' ) 228 | { 229 | xIsDotDir = 1; 230 | } 231 | } 232 | 233 | if( xIsDotDir == 0 ) 234 | { 235 | struct SFileCache * pxDevNode; 236 | 237 | pxDevNode = pxFindFile( pxDirEnt->pcFileName, eCACHE_LOOKUP ); 238 | 239 | pxDirEnt->ucIsDeviceDir = FF_DEV_CHAR_DEV; 240 | 241 | if( pxDevNode != NULL ) 242 | { 243 | pxDirEnt->ulFileSize = pxDevNode->ulFileLength; 244 | } 245 | else if( pxDirEnt->ulFileSize < 2048 ) 246 | { 247 | pxDirEnt->ulFileSize = 2048; 248 | } 249 | } 250 | 251 | return 1024; 252 | } 253 | -------------------------------------------------------------------------------- /test/build-combination/Common/include/FreeRTOSConfig.h: -------------------------------------------------------------------------------- 1 | /* 2 | * FreeRTOS+FAT 3 | * Copyright (C) 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved. 4 | * 5 | * Permission is hereby granted, free of charge, to any person obtaining a copy of 6 | * this software and associated documentation files (the "Software"), to deal in 7 | * the Software without restriction, including without limitation the rights to 8 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 9 | * the Software, and to permit persons to whom the Software is furnished to do so, 10 | * 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, FITNESS 17 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 18 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 19 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 20 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | * 22 | * http://aws.amazon.com/freertos 23 | * http://www.FreeRTOS.org 24 | */ 25 | 26 | #ifndef FREERTOS_CONFIG_H 27 | #define FREERTOS_CONFIG_H 28 | 29 | /*----------------------------------------------------------- 30 | * Application specific definitions. 31 | * 32 | * These definitions should be adjusted for your particular hardware and 33 | * application requirements. 34 | * 35 | * THESE PARAMETERS ARE DESCRIBED WITHIN THE 'CONFIGURATION' SECTION OF THE 36 | * FreeRTOS API DOCUMENTATION AVAILABLE ON THE FreeRTOS.org WEB SITE. 37 | * http://www.freertos.org/a00110.html 38 | * 39 | * The bottom of this file contains some constants specific to running the UDP 40 | * stack in this demo. Constants specific to FreeRTOS+FAT itself (rather than 41 | * the demo) are contained in FreeRTOSFATConfig.h. 42 | *----------------------------------------------------------*/ 43 | #define configENABLE_BACKWARD_COMPATIBILITY 1 44 | #define configUSE_PREEMPTION 1 45 | #define configUSE_PORT_OPTIMISED_TASK_SELECTION 0 46 | #define configMAX_PRIORITIES ( 7 ) 47 | #define configTICK_RATE_HZ ( 1000 ) /* In this non-real time simulated environment the tick frequency has to be at least a multiple of the Win32 tick frequency, and therefore very slow. */ 48 | #define configMINIMAL_STACK_SIZE ( ( unsigned short ) 60 ) /* In this simulated case, the stack only has to hold one small structure as the real stack is part of the Win32 thread. */ 49 | #define configTOTAL_HEAP_SIZE ( ( size_t ) ( 2048U * 1024U ) ) 50 | #define configMAX_TASK_NAME_LEN ( 15 ) 51 | #define configUSE_TRACE_FACILITY 1 52 | #define configUSE_16_BIT_TICKS 0 53 | #define configIDLE_SHOULD_YIELD 1 54 | #define configUSE_CO_ROUTINES 0 55 | #define configUSE_MUTEXES 1 56 | #define configUSE_RECURSIVE_MUTEXES 1 57 | #define configQUEUE_REGISTRY_SIZE 0 58 | #define configUSE_APPLICATION_TASK_TAG 1 59 | #define configUSE_COUNTING_SEMAPHORES 1 60 | #define configUSE_ALTERNATIVE_API 0 61 | #define configNUM_THREAD_LOCAL_STORAGE_POINTERS 3 /* FreeRTOS+FAT requires 2 pointers if a CWD is supported. */ 62 | #define configRECORD_STACK_HIGH_ADDRESS 1 63 | 64 | /* Hook function related definitions. */ 65 | #define configUSE_TICK_HOOK 0 66 | #define configUSE_IDLE_HOOK 1 67 | #define configUSE_MALLOC_FAILED_HOOK 1 68 | #define configCHECK_FOR_STACK_OVERFLOW 0 /* Not applicable to the Win32 port. */ 69 | 70 | /* Software timer related definitions. */ 71 | #define configUSE_TIMERS 1 72 | #define configTIMER_TASK_PRIORITY ( configMAX_PRIORITIES - 1 ) 73 | #define configTIMER_QUEUE_LENGTH 5 74 | #define configTIMER_TASK_STACK_DEPTH ( configMINIMAL_STACK_SIZE * 2 ) 75 | 76 | /* Event group related definitions. */ 77 | #define configUSE_EVENT_GROUPS 1 78 | 79 | /* Co-routine definitions. */ 80 | #define configUSE_CO_ROUTINES 0 81 | #define configMAX_CO_ROUTINE_PRIORITIES ( 2 ) 82 | 83 | /* Currently the TCP/IP stack is using dynamic allocation, and the MQTT task is 84 | * using static allocation. */ 85 | #define configSUPPORT_DYNAMIC_ALLOCATION 1 86 | #define configSUPPORT_STATIC_ALLOCATION 1 87 | 88 | /* Set the following definitions to 1 to include the API function, or zero 89 | * to exclude the API function. */ 90 | #define INCLUDE_vTaskPrioritySet 1 91 | #define INCLUDE_uxTaskPriorityGet 1 92 | #define INCLUDE_vTaskDelete 1 93 | #define INCLUDE_vTaskCleanUpResources 0 94 | #define INCLUDE_vTaskSuspend 1 95 | #define INCLUDE_vTaskDelayUntil 1 96 | #define INCLUDE_vTaskDelay 1 97 | #define INCLUDE_uxTaskGetStackHighWaterMark 1 98 | #define INCLUDE_xTaskGetSchedulerState 1 99 | #define INCLUDE_xTimerGetTimerTaskHandle 0 100 | #define INCLUDE_xTaskGetIdleTaskHandle 0 101 | #define INCLUDE_xQueueGetMutexHolder 1 102 | #define INCLUDE_eTaskGetState 1 103 | #define INCLUDE_xEventGroupSetBitsFromISR 1 104 | #define INCLUDE_xTimerPendFunctionCall 1 105 | #define INCLUDE_xTaskGetCurrentTaskHandle 1 106 | #define INCLUDE_xTaskAbortDelay 1 107 | 108 | /* This demo makes use of one or more example stats formatting functions. These 109 | * format the raw data provided by the uxTaskGetSystemState() function in to human 110 | * readable ASCII form. See the notes in the implementation of vTaskList() within 111 | * FreeRTOS/Source/tasks.c for limitations. configUSE_STATS_FORMATTING_FUNCTIONS 112 | * is set to 2 so the formatting functions are included without the stdio.h being 113 | * included in tasks.c. That is because this project defines its own sprintf() 114 | * functions. */ 115 | #define configUSE_STATS_FORMATTING_FUNCTIONS 1 116 | 117 | /* Assert call defined for debug builds. */ 118 | void vAssertCalled( const char * pcFile, 119 | unsigned long ulLine ); 120 | 121 | /* The function that implements FreeRTOS printf style output, and the macro 122 | * that maps the configPRINTF() macros to that function. */ 123 | #define configPRINTF( X ) 124 | 125 | /* Non-format version thread-safe print. */ 126 | extern void vLoggingPrint( const char * pcMessage ); 127 | 128 | /* Non-format version thread-safe print. */ 129 | #define configPRINT_STRING( X ) 130 | 131 | /* Application specific definitions follow. **********************************/ 132 | 133 | /* If configINCLUDE_DEMO_DEBUG_STATS is set to one, then a few basic IP trace 134 | * macros are defined to gather some UDP stack statistics that can then be viewed 135 | * through the CLI interface. */ 136 | #define configINCLUDE_DEMO_DEBUG_STATS 1 137 | 138 | /* The size of the global output buffer that is available for use when there 139 | * are multiple command interpreters running at once (for example, one on a UART 140 | * and one on TCP/IP). This is done to prevent an output buffer being defined by 141 | * each implementation - which would waste RAM. In this case, there is only one 142 | * command interpreter running, and it has its own local output buffer, so the 143 | * global buffer is just set to be one byte long as it is not used and should not 144 | * take up unnecessary RAM. */ 145 | #define configCOMMAND_INT_MAX_OUTPUT_SIZE ( 1 ) 146 | 147 | #define configPROFILING ( 0 ) 148 | 149 | /* Pseudo random number generator used by some tasks. */ 150 | extern uint32_t ulRand( void ); 151 | #define configRAND32() ulRand() 152 | 153 | /* / * The platform that FreeRTOS is running on. * / */ 154 | /* #define configPLATFORM_NAME "WinSim" */ 155 | 156 | 157 | #endif /* FREERTOS_CONFIG_H */ 158 | -------------------------------------------------------------------------------- /include/ff_old_config_defines.h: -------------------------------------------------------------------------------- 1 | /* 2 | * FreeRTOS+FAT V2.3.3 3 | * Copyright (C) 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved. 4 | * 5 | * Permission is hereby granted, free of charge, to any person obtaining a copy of 6 | * this software and associated documentation files (the "Software"), to deal in 7 | * the Software without restriction, including without limitation the rights to 8 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 9 | * the Software, and to permit persons to whom the Software is furnished to do so, 10 | * 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, FITNESS 17 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 18 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 19 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 20 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | * 22 | * https://www.FreeRTOS.org 23 | * https://github.com/FreeRTOS 24 | * 25 | */ 26 | 27 | /* 28 | * As of 15/3/2015 all +FAT configuration items changed their prefix, 29 | * e.g. FF_LITTLE_ENDIAN has become ffconfigLITTLE_ENDIAN 30 | * This temporary header file checks for the presence old configuration items 31 | * and issue a compiler error if any is defined. 32 | */ 33 | 34 | #ifdef FF_LITTLE_ENDIAN 35 | #error FF_LITTLE_ENDIAN was dropped and replaced with 'ffconfigBYTE_ORDER == pdFREERTOS_LITTLE_ENDIAN' 36 | #endif 37 | 38 | #ifdef FF_BIG_ENDIAN 39 | #error FF_BIG_ENDIAN was dropped and replaced with 'ffconfigBYTE_ORDER == pdFREERTOS_BIG_ENDIAN' 40 | #endif 41 | 42 | #ifdef ffconfigLITTLE_ENDIAN 43 | #error ffconfigLITTLE_ENDIAN was dropped. 44 | #endif 45 | 46 | #ifdef ffconfigBIG_ENDIAN 47 | #error ffconfigBIG_ENDIAN was dropped. 48 | #endif 49 | 50 | #ifdef FF_HAS_CWD 51 | #error FF_HAS_CWD still defined. Please use ffconfig prefix. 52 | #endif 53 | 54 | #if !defined( pdFREERTOS_LITTLE_ENDIAN ) || !defined( pdFREERTOS_BIG_ENDIAN ) 55 | #error Missing defines from FreeRTOS 56 | #endif 57 | 58 | #ifdef FF_LFN_SUPPORT 59 | #error FF_LFN_SUPPORT still defined. Please use ffconfig prefix. 60 | #endif 61 | 62 | #ifdef FF_INCLUDE_SHORT_NAME 63 | #error FF_INCLUDE_SHORT_NAME still defined. Please use ffconfig prefix. 64 | #endif 65 | 66 | #ifdef FF_SHORTNAME_CASE 67 | #error FF_SHORTNAME_CASE still defined. Please use ffconfig prefix. 68 | #endif 69 | 70 | #ifdef FF_UNICODE_UTF16_SUPPORT 71 | #error FF_UNICODE_UTF16_SUPPORT still defined. Please use ffconfig prefix. 72 | #endif 73 | 74 | #ifdef FF_UNICODE_UTF8_SUPPORT 75 | #error FF_UNICODE_UTF8_SUPPORT still defined. Please use ffconfig prefix. 76 | #endif 77 | 78 | #ifdef FF_FAT12_SUPPORT 79 | #error FF_FAT12_SUPPORT still defined. Please use ffconfig prefix. 80 | #endif 81 | 82 | #ifdef FF_OPTIMISE_UNALIGNED_ACCESS 83 | #error FF_OPTIMISE_UNALIGNED_ACCESS still defined. Please use ffconfig prefix. 84 | #endif 85 | 86 | #ifdef FF_CACHE_WRITE_THROUGH 87 | #error FF_CACHE_WRITE_THROUGH still defined. Please use ffconfig prefix. 88 | #endif 89 | 90 | #ifdef FF_WRITE_BOTH_FATS 91 | #error FF_WRITE_BOTH_FATS still defined. Please use ffconfig prefix. 92 | #endif 93 | 94 | #ifdef FF_WRITE_FREE_COUNT 95 | #error FF_WRITE_FREE_COUNT still defined. Please use ffconfig prefix. 96 | #endif 97 | 98 | #ifdef FF_TIME_SUPPORT 99 | #error FF_TIME_SUPPORT still defined. Please use ffconfig prefix. 100 | #endif 101 | 102 | #ifdef FF_REMOVABLE_MEDIA 103 | #error FF_REMOVABLE_MEDIA still defined. Please use ffconfig prefix. 104 | #endif 105 | 106 | #ifdef FF_MOUNT_FIND_FREE 107 | #error FF_MOUNT_FIND_FREE still defined. Please use ffconfig prefix. 108 | #endif 109 | 110 | #ifdef FF_FINDAPI_ALLOW_WILDCARDS 111 | #error FF_FINDAPI_ALLOW_WILDCARDS still defined. Please use ffconfig prefix. 112 | #endif 113 | 114 | #ifdef FF_WILDCARD_CASE_INSENSITIVE 115 | #error FF_WILDCARD_CASE_INSENSITIVE still defined. Please use ffconfig prefix. 116 | #endif 117 | 118 | #ifdef FF_PATH_CACHE 119 | #error FF_PATH_CACHE still defined. Please use ffconfig prefix. 120 | #endif 121 | 122 | #ifdef FF_PATH_CACHE_DEPTH 123 | #error FF_PATH_CACHE_DEPTH still defined. Please use ffconfig prefix. 124 | #endif 125 | 126 | #ifdef FF_HASH_CACHE 127 | #error FF_HASH_CACHE still defined. Please use ffconfig prefix. 128 | #endif 129 | 130 | #ifdef FF_HASH_FUNCTION 131 | #error FF_HASH_FUNCTION still defined. Please use ffconfig prefix. 132 | #endif 133 | 134 | #ifdef FF_HASH_TABLE_SIZE 135 | #error FF_HASH_TABLE_SIZE still defined. Please use ffconfig prefix. 136 | #endif 137 | 138 | #ifdef FF_HASH_TABLE_SIZE 139 | #error FF_HASH_TABLE_SIZE still defined. Please use ffconfig prefix. 140 | #endif 141 | 142 | #ifdef FF_MKDIR_RECURSIVE 143 | #error FF_MKDIR_RECURSIVE still defined. Please use ffconfig prefix. 144 | #endif 145 | 146 | #ifdef FF_BLKDEV_USES_SEM 147 | #error FF_BLKDEV_USES_SEM is not used any more 148 | #endif 149 | 150 | #ifdef ffconfigBLKDEV_USES_SEM 151 | #error ffconfigBLKDEV_USES_SEM is not used any more 152 | #endif 153 | 154 | #ifdef FF_MALLOC 155 | #error FF_MALLOC still defined. Please use ffconfig prefix. 156 | #endif 157 | 158 | #ifdef FF_FREE 159 | #error FF_FREE still defined. Please use ffconfig prefix. 160 | #endif 161 | 162 | #ifdef FF_64_NUM_SUPPORT 163 | #error FF_64_NUM_SUPPORT still defined. Please use ffconfig prefix. 164 | #endif 165 | 166 | #ifdef FF_MAX_PARTITIONS 167 | #error FF_MAX_PARTITIONS still defined. Please use ffconfig prefix. 168 | #endif 169 | 170 | #ifdef FF_MAX_FILE_SYS 171 | #error FF_MAX_FILE_SYS still defined. Please use ffconfig prefix. 172 | #endif 173 | 174 | #ifdef FF_DRIVER_BUSY_SLEEP_MS 175 | #error FF_DRIVER_BUSY_SLEEP_MS still defined. Please use ffconfig prefix. 176 | #endif 177 | 178 | #ifdef FF_FPRINTF_SUPPORT 179 | #error FF_FPRINTF_SUPPORT still defined. Please use ffconfig prefix. 180 | #endif 181 | 182 | #ifdef FF_FPRINTF_BUFFER_LENGTH 183 | #error FF_FPRINTF_BUFFER_LENGTH still defined. Please use ffconfig prefix. 184 | #endif 185 | 186 | #ifdef FF_DEBUG 187 | #error FF_DEBUG still defined. Please use ffconfig prefix. 188 | #endif 189 | 190 | #ifdef FF_HAS_FUNCTION_TAB 191 | #error FF_HAS_FUNCTION_TAB still defined. Please use ffconfig prefix. 192 | #endif 193 | 194 | #ifdef FF_FAT_CHECK 195 | #error FF_FAT_CHECK still defined. Please use ffconfig prefix. 196 | #endif 197 | 198 | #ifdef FF_MAX_FILENAME 199 | #error FF_MAX_FILENAME still defined. Please use ffconfig prefix. 200 | #endif 201 | 202 | #ifdef FF_PRINTFFF_PRINTF 203 | #error FF_PRINTFFF_PRINTF still defined. Please use ffconfig prefix. 204 | #endif 205 | 206 | #ifdef FF_FAT_USES_STAT 207 | #error FF_FAT_USES_STAT still defined. Please use ffconfig prefix. 208 | #endif 209 | 210 | #ifdef BUF_STORE_COUNT 211 | #error BUF_STORE_COUNT still defined. Please use ffconfig prefix. 212 | #endif 213 | 214 | #ifdef FF_USE_NOTIFY 215 | #error FF_USE_NOTIFY still defined. Please use ffconfig prefix. 216 | #endif 217 | 218 | #ifdef FF_DEV_SUPPORT 219 | #error FF_DEV_SUPPORT still defined. Please use ffconfig prefix. 220 | #endif 221 | 222 | #ifdef FF_FSINFO_TRUSTED 223 | #error FF_FSINFO_TRUSTED still defined. Please use ffconfig prefix. 224 | #endif 225 | 226 | #ifdef FF_LONG_ERR_MSG 227 | #error FF_LONG_ERR_MSG still defined. Please use ffconfig prefix. 228 | #endif 229 | 230 | #ifdef FF_INLINE_MEMORY_ACCESS 231 | #error FF_INLINE_MEMORY_ACCESS still defined. Please use ffconfig prefix. 232 | #endif 233 | 234 | #ifdef FF_MIRROR_FATS_UMOUNT 235 | #error FF_MIRROR_FATS_UMOUNT still defined. Please use ffconfig prefix. 236 | #endif 237 | 238 | #ifdef FF_HASH_CACHE_DEPTH 239 | #error FF_HASH_CACHE_DEPTH still defined. Please use ffconfig prefix. 240 | #endif 241 | 242 | #ifdef FF_HASH_TABLE_SUPPORT 243 | #error FF_HASH_TABLE_SUPPORT was dropped 244 | #endif 245 | 246 | #ifdef FF_INLINE_BLOCK_CALCULATIONS 247 | #error FF_INLINE_BLOCK_CALCULATIONS was dropped 248 | #endif 249 | 250 | #ifdef FF_CWD_THREAD_LOCAL_INDEX 251 | #error FF_CWD_THREAD_LOCAL_INDEX is now called ffconfigCWD_THREAD_LOCAL_INDEX 252 | #endif 253 | 254 | #ifdef FF_DEV_PATH 255 | #error FF_DEV_PATH was dropped 256 | #endif 257 | -------------------------------------------------------------------------------- /include/ff_file.h: -------------------------------------------------------------------------------- 1 | /* 2 | * FreeRTOS+FAT V2.3.3 3 | * Copyright (C) 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved. 4 | * 5 | * Permission is hereby granted, free of charge, to any person obtaining a copy of 6 | * this software and associated documentation files (the "Software"), to deal in 7 | * the Software without restriction, including without limitation the rights to 8 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 9 | * the Software, and to permit persons to whom the Software is furnished to do so, 10 | * 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, FITNESS 17 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 18 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 19 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 20 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | * 22 | * https://www.FreeRTOS.org 23 | * https://github.com/FreeRTOS 24 | * 25 | */ 26 | 27 | /** 28 | * @file ff_file.h 29 | * @ingroup FILEIO 30 | **/ 31 | #ifndef _FF_FILE_H_ 32 | #define _FF_FILE_H_ 33 | 34 | #ifndef PLUS_FAT_H 35 | #error this header will be included from "ff_headers.h" 36 | #endif 37 | 38 | #define FF_SEEK_SET 0 39 | #define FF_SEEK_CUR 1 40 | #define FF_SEEK_END 2 41 | 42 | #if ( ffconfigOPTIMISE_UNALIGNED_ACCESS != 0 ) 43 | #define FF_BUFSTATE_INVALID 0x00 /* Data in file handle buffer is invalid. */ 44 | #define FF_BUFSTATE_VALID 0x01 /* Valid data in pBuf (Something has been read into it). */ 45 | #define FF_BUFSTATE_WRITTEN 0x02 /* Data was written into pBuf, this must be saved when leaving sector. */ 46 | #endif 47 | 48 | #if ( ffconfigDEV_SUPPORT != 0 ) 49 | struct xDEV_NODE 50 | { 51 | uint8_t 52 | ucIsDevice; 53 | }; 54 | #endif 55 | 56 | typedef struct _FF_FILE 57 | { 58 | FF_IOManager_t * pxIOManager; /* Ioman Pointer! */ 59 | uint32_t ulFileSize; /* File's Size. */ 60 | uint32_t ulObjectCluster; /* File's Start Cluster. */ 61 | uint32_t ulChainLength; /* Total Length of the File's cluster chain. */ 62 | uint32_t ulCurrentCluster; /* Prevents FAT Thrashing. */ 63 | uint32_t ulAddrCurrentCluster; /* Address of the current cluster. */ 64 | uint32_t ulEndOfChain; /* Address of the last cluster in the chain. */ 65 | uint32_t ulFilePointer; /* Current Position Pointer. */ 66 | uint32_t ulDirCluster; /* Cluster Number that the Dirent is in. */ 67 | uint32_t ulValidFlags; /* Handle validation flags. */ 68 | 69 | #if ( ffconfigOPTIMISE_UNALIGNED_ACCESS != 0 ) 70 | uint8_t * pucBuffer; /* A buffer for providing fast unaligned access. */ 71 | uint8_t ucState; /* State information about the buffer. */ 72 | #endif 73 | uint8_t ucMode; /* Mode that File Was opened in. */ 74 | uint16_t usDirEntry; /* Dirent Entry Number describing this file. */ 75 | 76 | #if ( ffconfigDEV_SUPPORT != 0 ) 77 | struct SFileCache * pxDevNode; 78 | #endif 79 | struct _FF_FILE * pxNext; /* Pointer to the next file object in the linked list. */ 80 | } FF_FILE; 81 | 82 | #define FF_VALID_FLAG_INVALID 0x00000001U 83 | #define FF_VALID_FLAG_DELETED 0x00000002U 84 | #define FF_VALID_FLAG_EXTENDED 0x00000004U 85 | 86 | /*---------- PROTOTYPES */ 87 | /* PUBLIC (Interfaces): */ 88 | 89 | #if ( ffconfigUNICODE_UTF16_SUPPORT != 0 ) 90 | FF_FILE * FF_Open( FF_IOManager_t * pxIOManager, 91 | const FF_T_WCHAR * path, 92 | uint8_t Mode, 93 | FF_Error_t * pError ); 94 | BaseType_t FF_isDirEmpty( FF_IOManager_t * pxIOManager, 95 | const FF_T_WCHAR * Path ); 96 | FF_Error_t FF_RmFile( FF_IOManager_t * pxIOManager, 97 | const FF_T_WCHAR * path ); 98 | FF_Error_t FF_RmDir( FF_IOManager_t * pxIOManager, 99 | const FF_T_WCHAR * path ); 100 | FF_Error_t FF_Move( FF_IOManager_t * pxIOManager, 101 | const FF_T_WCHAR * szSourceFile, 102 | const FF_T_WCHAR * szDestinationFile, 103 | BaseType_t bDeleteIfExists ); 104 | #else /* ffconfigUNICODE_UTF16_SUPPORT */ 105 | FF_FILE * FF_Open( FF_IOManager_t * pxIOManager, 106 | const char * path, 107 | uint8_t Mode, 108 | FF_Error_t * pError ); 109 | BaseType_t FF_isDirEmpty( FF_IOManager_t * pxIOManager, 110 | const char * Path ); 111 | FF_Error_t FF_RmFile( FF_IOManager_t * pxIOManager, 112 | const char * path ); 113 | FF_Error_t FF_RmDir( FF_IOManager_t * pxIOManager, 114 | const char * path ); 115 | FF_Error_t FF_Move( FF_IOManager_t * pxIOManager, 116 | const char * szSourceFile, 117 | const char * szDestinationFile, 118 | BaseType_t bDeleteIfExists ); 119 | #endif /* ffconfigUNICODE_UTF16_SUPPORT */ 120 | 121 | #if ( ffconfigTIME_SUPPORT != 0 ) 122 | enum 123 | { 124 | ETimeCreate = 1, 125 | ETimeMod = 2, 126 | ETimeAccess = 4, 127 | ETimeAll = 7 128 | }; 129 | FF_Error_t FF_SetFileTime( FF_FILE * pFile, 130 | FF_SystemTime_t * pxTime, 131 | UBaseType_t uxWhat ); 132 | #if ( ffconfigUNICODE_UTF16_SUPPORT != 0 ) 133 | FF_Error_t FF_SetTime( FF_IOManager_t * pxIOManager, 134 | const FF_T_WCHAR * path, 135 | FF_SystemTime_t * pxTime, 136 | UBaseType_t uxWhat ); 137 | #else 138 | FF_Error_t FF_SetTime( FF_IOManager_t * pxIOManager, 139 | const char * path, 140 | FF_SystemTime_t * pxTime, 141 | UBaseType_t uxWhat ); 142 | #endif /* ffconfigUNICODE_UTF16_SUPPORT */ 143 | #endif /* ffconfigTIME_SUPPORT */ 144 | 145 | #if ( ffconfigUNICODE_UTF16_SUPPORT != 0 ) 146 | FF_Error_t FF_SetPerm( FF_IOManager_t * pxIOManager, 147 | const FF_T_WCHAR * path, 148 | UBaseType_t aPerm ); 149 | #else 150 | FF_Error_t FF_SetPerm( FF_IOManager_t * pxIOManager, 151 | const char * path, 152 | UBaseType_t aPerm ); 153 | #endif 154 | 155 | FF_Error_t FF_SetEof( FF_FILE * pFile ); 156 | 157 | FF_Error_t FF_Close( FF_FILE * pFile ); 158 | int32_t FF_GetC( FF_FILE * pFile ); 159 | int32_t FF_GetLine( FF_FILE * pFile, 160 | char * szLine, 161 | uint32_t ulLimit ); 162 | int32_t FF_Read( FF_FILE * pFile, 163 | uint32_t ElementSize, 164 | uint32_t Count, 165 | uint8_t * buffer ); 166 | int32_t FF_Write( FF_FILE * pFile, 167 | uint32_t ElementSize, 168 | uint32_t Count, 169 | uint8_t * buffer ); 170 | BaseType_t FF_isEOF( FF_FILE * pFile ); 171 | int32_t FF_BytesLeft( FF_FILE * pFile ); /* Returns # of bytes left to read. */ 172 | 173 | /* FF_FileSize is an earlier version of FF_GetFileSize(). For files 174 | * equal to or larger than 2GB, the return value is negative. 175 | * Function is deprecated. Please use FF_GetFileSize(). */ 176 | int32_t FF_FileSize( FF_FILE * pFile ); /* Returns # of bytes in a file. */ 177 | 178 | /* Use the following function in case files may get larger than 2 GB. 179 | * Writes the size of a file to the parameter. 180 | * Returns 0 or error code. */ 181 | FF_Error_t FF_GetFileSize( FF_FILE * pFile, 182 | uint32_t * pulSize ); 183 | 184 | FF_Error_t FF_Seek( FF_FILE * pFile, 185 | int32_t Offset, 186 | BaseType_t xOrigin ); 187 | int32_t FF_PutC( FF_FILE * pFile, 188 | uint8_t Value ); 189 | 190 | static portINLINE uint32_t FF_Tell( FF_FILE * pFile ) 191 | { 192 | return pFile ? pFile->ulFilePointer : 0; 193 | } 194 | 195 | uint8_t FF_GetModeBits( const char * Mode ); 196 | 197 | FF_Error_t FF_CheckValid( FF_FILE * pFile ); /* Check if pFile is a valid FF_FILE pointer. */ 198 | 199 | #if ( ffconfigREMOVABLE_MEDIA != 0 ) 200 | int32_t FF_Invalidate( FF_IOManager_t * pxIOManager ); /* Invalidate all handles belonging to pxIOManager. */ 201 | #endif 202 | 203 | /* Private : */ 204 | 205 | #endif /* ifndef _FF_FILE_H_ */ 206 | -------------------------------------------------------------------------------- /portable/linux/ff_sddisk.c: -------------------------------------------------------------------------------- 1 | /* 2 | * FreeRTOS+FAT Labs Build 160919 (C) 2016 Real Time Engineers ltd. 3 | * Authors include James Walmsley, Hein Tibosch and Richard Barry 4 | * 5 | * 6 | * FreeRTOS+FAT can be used under two different free open source licenses. The 7 | * license that applies is dependent on the processor on which FreeRTOS+FAT is 8 | * executed, as follows: 9 | * 10 | * If FreeRTOS+FAT is executed on one of the processors listed under the Special 11 | * License Arrangements heading of the FreeRTOS+FAT license information web 12 | * page, then it can be used under the terms of the FreeRTOS Open Source 13 | * License. If FreeRTOS+FAT is used on any other processor, then it can be used 14 | * under the terms of the GNU General Public License V2. Links to the relevant 15 | * licenses follow: 16 | * 17 | * The FreeRTOS+FAT License Information Page: https://www.freertos.org/Documentation/03-Libraries/05-FreeRTOS-labs/04-FreeRTOS-plus-FAT/FreeRTOS_Plus_FAT_License 18 | * The FreeRTOS Open Source License: https://www.freertos.org/Documentation/03-Libraries/01-Library-overview/04-Licensing 19 | * 20 | * FreeRTOS+FAT is distributed in the hope that it will be useful. You cannot 21 | * use FreeRTOS+FAT unless you agree that you use the software 'as is'. 22 | * FreeRTOS+FAT is provided WITHOUT ANY WARRANTY; without even the implied 23 | * warranties of NON-INFRINGEMENT, MERCHANTABILITY or FITNESS FOR A PARTICULAR 24 | * PURPOSE. Real Time Engineers Ltd. disclaims all conditions and terms, be they 25 | * implied, expressed, or statutory. 26 | * 27 | * This is a stub for allowing linux to compile. should just make it save to a file. 28 | * 29 | * 30 | */ 31 | 32 | #include "ff_sddisk.h" 33 | 34 | /* Standard includes. */ 35 | #include 36 | #include 37 | #include 38 | #include 39 | 40 | /* FreeRTOS includes. */ 41 | #include "FreeRTOS.h" 42 | #include "task.h" 43 | #include "semphr.h" 44 | #include "portmacro.h" 45 | 46 | /* FreeRTOS+FAT includes. */ 47 | #include "ff_headers.h" 48 | #include "ff_sys.h" 49 | 50 | /* Dummy variables. */ 51 | #define HUNDRED_64_BIT ( 100U ) 52 | #define BYTES_PER_MB ( 1024U * 1024U ) 53 | #define SECTORS_PER_MB ( BYTES_PER_MB / 512U ) 54 | 55 | /*-----------------------------------------------------------*/ 56 | 57 | BaseType_t FF_SDDiskDetect( FF_Disk_t * pxDisk ) 58 | { 59 | ( void ) pxDisk; /* Unused */ 60 | return pdTRUE; 61 | } 62 | 63 | /*-----------------------------------------------------------*/ 64 | 65 | void FF_SDDiskFlush( FF_Disk_t * pxDisk ) 66 | { 67 | if( ( pxDisk != NULL ) && 68 | ( pxDisk->xStatus.bIsInitialised != pdFALSE ) && 69 | ( pxDisk->pxIOManager != NULL ) ) 70 | { 71 | /*flush cache*/ 72 | } 73 | } 74 | /*-----------------------------------------------------------*/ 75 | 76 | FF_Disk_t * FF_SDDiskInitWithSettings( const char * pcName, 77 | const FFInitSettings_t * pxSettings ) 78 | { 79 | ( void ) pxSettings; /* Unused */ 80 | 81 | return FF_SDDiskInit( pcName ); 82 | } 83 | /*-----------------------------------------------------------*/ 84 | 85 | FF_Disk_t * FF_SDDiskInit( const char * pcName ) 86 | { 87 | FF_Disk_t * pxDisk = NULL; 88 | 89 | ( void ) pcName; /* Unused */ 90 | 91 | pxDisk = ( FF_Disk_t * ) pvPortMalloc( sizeof( *pxDisk ) ); 92 | 93 | if( pxDisk == NULL ) 94 | { 95 | FF_PRINTF( "FF_SDDiskInit: Malloc failed\n" ); 96 | return NULL; 97 | } 98 | 99 | /* Initialise the created disk structure. */ 100 | memset( pxDisk, '\0', sizeof( *pxDisk ) ); 101 | 102 | /* Other stuff here*/ 103 | 104 | pxDisk->xStatus.bIsInitialised = pdTRUE; 105 | 106 | return pxDisk; 107 | } 108 | /*-----------------------------------------------------------*/ 109 | 110 | BaseType_t FF_SDDiskFormat( FF_Disk_t * pxDisk, 111 | BaseType_t aPart ) 112 | { 113 | ( void ) aPart; /* Unused */ 114 | 115 | if( pxDisk != NULL ) 116 | { 117 | FF_PRINTF( "FF_SDDISKFormat \n" ); 118 | return pdPASS; 119 | } 120 | 121 | return pdFAIL; 122 | } 123 | /*-----------------------------------------------------------*/ 124 | 125 | /* Unmount the volume */ 126 | BaseType_t FF_SDDiskUnmount( FF_Disk_t * pxDisk ) 127 | { 128 | if( ( pxDisk != NULL ) && ( pxDisk->xStatus.bIsMounted != pdFALSE ) ) 129 | { 130 | pxDisk->xStatus.bIsMounted = pdFALSE; 131 | FF_PRINTF( "FF_SDDiskUnmount: Drive unmounted\n" ); 132 | return pdPASS; 133 | } 134 | 135 | return pdFAIL; 136 | } 137 | /*-----------------------------------------------------------*/ 138 | 139 | BaseType_t FF_SDDiskReinit( FF_Disk_t * pxDisk ) 140 | { 141 | ( void ) pxDisk; 142 | FF_PRINTF( "FF_SDDiskReinit: rc %08x\n", 0U ); 143 | return pdPASS; 144 | } 145 | /*-----------------------------------------------------------*/ 146 | 147 | BaseType_t FF_SDDiskMount( FF_Disk_t * pxDisk ) 148 | { 149 | if( pxDisk != NULL ) 150 | { 151 | pxDisk->xStatus.bIsMounted = pdTRUE; 152 | FF_PRINTF( "****** FreeRTOS+FAT initialized %u sectors\n", ( unsigned ) pxDisk->pxIOManager->xPartition.ulTotalSectors ); 153 | return pdPASS; 154 | } 155 | 156 | return pdFAIL; 157 | } 158 | /*-----------------------------------------------------------*/ 159 | 160 | /* Get a pointer to IOMAN, which can be used for all FreeRTOS+FAT functions */ 161 | FF_IOManager_t * sddisk_ioman( FF_Disk_t * pxDisk ) 162 | { 163 | FF_IOManager_t * pxReturn; 164 | 165 | if( ( pxDisk != NULL ) && ( pxDisk->xStatus.bIsInitialised != pdFALSE ) ) 166 | { 167 | pxReturn = pxDisk->pxIOManager; 168 | } 169 | else 170 | { 171 | pxReturn = NULL; 172 | } 173 | 174 | return pxReturn; 175 | } 176 | /*-----------------------------------------------------------*/ 177 | 178 | /* Release all resources */ 179 | BaseType_t FF_SDDiskDelete( FF_Disk_t * pxDisk ) 180 | { 181 | if( pxDisk != NULL ) 182 | { 183 | vPortFree( pxDisk ); 184 | } 185 | 186 | return pdTRUE; 187 | } 188 | /*-----------------------------------------------------------*/ 189 | 190 | BaseType_t FF_SDDiskShowPartition( FF_Disk_t * pxDisk ) 191 | { 192 | FF_Error_t xError; 193 | uint64_t ullFreeSectors; 194 | uint32_t ulTotalSizeMB, ulFreeSizeMB; 195 | int iPercentageFree; 196 | FF_IOManager_t * pxIOManager; 197 | const char * pcTypeName = "unknown type"; 198 | BaseType_t xReturn = pdPASS; 199 | 200 | if( pxDisk == NULL ) 201 | { 202 | xReturn = pdFAIL; 203 | } 204 | else 205 | { 206 | pxIOManager = pxDisk->pxIOManager; 207 | 208 | FF_PRINTF( "Reading FAT and calculating Free Space\n" ); 209 | 210 | switch( pxIOManager->xPartition.ucType ) 211 | { 212 | case FF_T_FAT12: 213 | pcTypeName = "FAT12"; 214 | break; 215 | 216 | case FF_T_FAT16: 217 | pcTypeName = "FAT16"; 218 | break; 219 | 220 | case FF_T_FAT32: 221 | pcTypeName = "FAT32"; 222 | break; 223 | 224 | default: 225 | pcTypeName = "UNKOWN"; 226 | break; 227 | } 228 | 229 | FF_GetFreeSize( pxIOManager, &xError ); 230 | 231 | ullFreeSectors = pxIOManager->xPartition.ulFreeClusterCount * pxIOManager->xPartition.ulSectorsPerCluster; 232 | iPercentageFree = ( int ) ( ( HUNDRED_64_BIT * ullFreeSectors + pxIOManager->xPartition.ulDataSectors / 2 ) / 233 | ( ( uint64_t ) pxIOManager->xPartition.ulDataSectors ) ); 234 | 235 | ulTotalSizeMB = pxIOManager->xPartition.ulDataSectors / SECTORS_PER_MB; 236 | ulFreeSizeMB = ( uint32_t ) ( ullFreeSectors / SECTORS_PER_MB ); 237 | 238 | /* It is better not to use the 64-bit format such as %Lu because it 239 | * might not be implemented. */ 240 | FF_PRINTF( "Partition Nr %8u\n", pxDisk->xStatus.bPartitionNumber ); 241 | FF_PRINTF( "Type %8s (%u)\n", pcTypeName, pxIOManager->xPartition.ucType ); 242 | FF_PRINTF( "VolLabel '%8s' \n", pxIOManager->xPartition.pcVolumeLabel ); 243 | FF_PRINTF( "TotalSectors %8u x 512 = %u\n", 244 | ( unsigned ) pxIOManager->xPartition.ulTotalSectors, 245 | ( unsigned ) pxIOManager->xPartition.ulTotalSectors * 512U ); 246 | FF_PRINTF( "DataSectors %8u\n", ( unsigned ) pxIOManager->xPartition.ulDataSectors ); 247 | FF_PRINTF( "SecsPerCluster %8u\n", ( unsigned ) pxIOManager->xPartition.ulSectorsPerCluster ); 248 | FF_PRINTF( "Size %8u MB\n", ( unsigned ) ulTotalSizeMB ); 249 | FF_PRINTF( "FreeSize %8u MB ( %d percent free )\n", ( unsigned ) ulFreeSizeMB, ( int ) iPercentageFree ); 250 | FF_PRINTF( "BeginLBA %8u\n", ( unsigned ) pxIOManager->xPartition.ulBeginLBA ); 251 | FF_PRINTF( "FATBeginLBA %8u\n", ( unsigned ) pxIOManager->xPartition.ulFATBeginLBA ); 252 | } 253 | 254 | return xReturn; 255 | } 256 | 257 | /*-----------------------------------------------------------*/ 258 | 259 | BaseType_t FF_SDDiskInserted( BaseType_t xDriveNr ) 260 | { 261 | ( void ) xDriveNr; 262 | return pdFALSE; 263 | } 264 | -------------------------------------------------------------------------------- /CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.15) 2 | cmake_policy(SET CMP0048 NEW) # project version 3 | cmake_policy(SET CMP0076 NEW) # full paths 4 | 5 | ######################################################################## 6 | # Project Details 7 | project(FreeRTOS-Plus-FAT 8 | VERSION 0.0.1 9 | DESCRIPTION "FreeRTOS DOS Compatible Embedded FAT File System" 10 | HOMEPAGE_URL https://www.freertos.org/FreeRTOS-Plus/FreeRTOS_Plus_FAT/index.html 11 | LANGUAGES C) 12 | 13 | # Do not allow in-source build. 14 | if( ${PROJECT_SOURCE_DIR} STREQUAL ${PROJECT_BINARY_DIR} ) 15 | message( FATAL_ERROR "In-source build is not allowed. Please build in a separate directory, such as ${PROJECT_SOURCE_DIR}/build." ) 16 | endif() 17 | 18 | ######################################################################## 19 | # Options 20 | 21 | # Optional: FREERTOS_PLUS_FAT_DEV_SUPPORT 22 | # - when OFF - device support is disabled and not used. 23 | # - When ON - device support is enabled and the ff_devices.h API is used. 24 | # Optional: FREERTOS_PLUS_FAT_PORT 25 | # - When not defined - identifies native platform Linux or MinGW and uses that port. 26 | # - When defined as A_CUSTOM_PORT - the port library must be defined in advance. 27 | # - When any of the other supported ports - the port library is defined by portable source files. 28 | option(FREERTOS_PLUS_FAT_DEV_SUPPORT "FreeRTOS Plus FAT Device selection support" OFF) 29 | 30 | # Select the appropriate FAT Port 31 | # This will fail the CMake preparation step if not set to one of those values. 32 | set(FREERTOS_PLUS_FAT_PORT "" CACHE STRING "FreeRTOS Plus FAT Port selection") 33 | set(FREERTOS_PLUS_FAT_PORT_LIST 34 | A_CUSTOM_PORT 35 | ATSAM4E 36 | AVR32_UC3 37 | LPC18XX 38 | POSIX 39 | STM32F4XX 40 | STM32F7XX 41 | ZYNQ 42 | ZYNQ_2019_3 43 | ) 44 | if(NOT FREERTOS_PLUS_FAT_PORT) 45 | # Attempt to detect the system. 46 | if(UNIX) 47 | message(STATUS "Detected UNIX/Posix system setting FREERTOS_PLUS_FAT_PORT = POSIX") 48 | set(FREERTOS_PLUS_FAT_PORT POSIX) 49 | elseif(MINGW) 50 | message(STATUS "Detected Windows MinGW system setting FREERTOS_PLUS_FAT_PORT = WIN_MGW") 51 | set(FREERTOS_PLUS_FAT_PORT WIN_PCAP) 52 | endif() 53 | endif() 54 | 55 | if(NOT FREERTOS_PLUS_FAT_PORT IN_LIST FREERTOS_PLUS_FAT_PORT_LIST ) 56 | message(FATAL_ERROR " FREERTOS_PLUS_FAT_PORT is '${FREERTOS_PLUS_FAT_PORT}'.\n" 57 | " Please specify it from top-level CMake file (example):\n" 58 | " set(FREERTOS_PLUS_FAT_PORT POSIX CACHE STRING \"\")\n" 59 | " or from CMake command line option:\n" 60 | " -DFREERTOS_PLUS_FAT_PORT=POSIX\n" 61 | " \n" 62 | " Available port options: (Tested means compiled with that variant)\n" 63 | " A_CUSTOM_PORT Target: User Defined\n" 64 | " ATSAM4E Target: ATSAM4E Tested: TODO\n" 65 | " AVR32_UC3 Target: avr32_uc3 Tested: TODO\n" 66 | " LPC18XX Target: lpc18xx Tested: TODO\n" 67 | " POSIX Target: linux/Posix\n" 68 | " STM32F4XX Target: STM32F4xx Tested: TODO\n" 69 | " STM32F7XX Target: STM32F7xx Tested: TODO\n" 70 | " ZYNQ Target: Xilinx Zynq Tested: TODO\n" 71 | " ZYNQ_2019_3 Target: Xilinx Zynq 2019.3") 72 | elseif((FREERTOS_PLUS_FAT_PORT STREQUAL "A_CUSTOM_PORT") AND (NOT TARGET freertos_plus_fat_port) ) 73 | message(FATAL_ERROR " FREERTOS_PLUS_FAT_PORT is set to A_CUSTOM_PORT.\n" 74 | " Please specify the custom port target with all necessary files.\n" 75 | " For example, assuming a directory of:\n" 76 | " FreeRTOSPlusFatPort/\n" 77 | " CMakeLists.txt\n" 78 | " ff_sddisk.c\n" 79 | " Where FreeRTOSPlusFatPort/CMakeLists.txt is a modified version of:\n" 80 | " add_library(freertos_plus_fat_port STATIC)\n" 81 | " target_sources(freertos_plus_fat_port\n" 82 | " PRIVATE\n" 83 | " ff_sddisk.c)\n" 84 | " target_link_libraries(freertos_plus_fat_port\n" 85 | " PUBLIC\n" 86 | " freertos_plus_fat_port_common\n" 87 | " PRIVATE\n" 88 | " freertos_kernel\n" 89 | " freertos_plus_fat)") 90 | endif() 91 | 92 | # This library requires access to a heap 93 | # FreeRTOS/FreeRTOS-Kernel previously defaulted to heap4.c 94 | if(NOT DEFINED FREERTOS_HEAP) 95 | message(STATUS "FREERTOS_HEAP not set, setting FREERTOS_HEAP=4") 96 | set(FREERTOS_HEAP 4) 97 | endif() 98 | 99 | # Select the appropriate Build Test configuration 100 | # This is only used when freertos_config is not defined, otherwise the build test will be performed 101 | # on the config defined in the freertos_config 102 | set(FREERTOS_PLUS_FAT_TEST_CONFIGURATION "CUSTOM" CACHE STRING "FreeRTOS Plus FAT Build Test configuration") 103 | set(FREERTOS_PLUS_FAT_TEST_CONFIGURATION_LIST 104 | CUSTOM # Custom (external) configuration -eg from a top-level project 105 | DEFAULT_CONF # Default (typical) configuration) 106 | ) 107 | if(NOT FREERTOS_PLUS_FAT_TEST_CONFIGURATION IN_LIST FREERTOS_PLUS_FAT_TEST_CONFIGURATION_LIST) 108 | message(FATAL_ERROR "Invalid FREERTOS_PLUS_FAT_TEST_CONFIGURATION value '${FREERTOS_PLUS_FAT_TEST_CONFIGURATION}' should be one of: ${FREERTOS_PLUS_FAT_TEST_CONFIGURATION_LIST}") 109 | else() 110 | message(STATUS "Using FreeRTOS-Plus-FAT Test Configuration : ${FREERTOS_PLUS_FAT_TEST_CONFIGURATION}") 111 | if (NOT FREERTOS_PLUS_FAT_TEST_CONFIGURATION STREQUAL "CUSTOM") 112 | message(WARNING "FreeRTOS-Kernel configuration settings are configured by FreeRTOS-Plus-FAT") 113 | endif() 114 | endif() 115 | 116 | # Optional: FREERTOS_PLUS_FAT_FETCH_FREERTOS 117 | # - when OFF - disable automatic fetch of FreeRTOS-kernel, user must make sure that 118 | # target freertos_kernel is available 119 | # - When ON - FreeRTOS-kernel will be fetch using CMake FetchContent_Declare function. 120 | # Optional: FREERTOS_PLUS_FAT_FETCH_FREERTOS_GIT_REPO 121 | # Optional: FREERTOS_PLUS_FAT_FETCH_FREERTOS_GIT_TAG 122 | option(FREERTOS_PLUS_FAT_FETCH_FREERTOS "FreeRTOS-Kernel automatic fetch support" ON) 123 | set(FREERTOS_PLUS_FAT_FETCH_FREERTOS_GIT_REPO "https://github.com/FreeRTOS/FreeRTOS-Kernel.git" CACHE STRING "") 124 | set(FREERTOS_PLUS_FAT_FETCH_FREERTOS_GIT_TAG "main" CACHE STRING "") 125 | 126 | ######################################################################## 127 | # External Dependencies 128 | # Note: For backwards compatibility - still have .gitmodules defining submodules 129 | # To support fetching content in a higher level project see 130 | # README.md `Consume with CMake` 131 | # This will allow you to upgrade submodules and have one common submodule for 132 | # all your builds despite multiple submodules having different versions. 133 | if(FREERTOS_PLUS_FAT_FETCH_FREERTOS) 134 | include(FetchContent) 135 | 136 | FetchContent_Declare( freertos_kernel 137 | GIT_REPOSITORY ${FREERTOS_PLUS_FAT_FETCH_FREERTOS_GIT_REPO} 138 | GIT_TAG ${FREERTOS_PLUS_FAT_FETCH_FREERTOS_GIT_TAG} 139 | ) 140 | endif() 141 | 142 | ######################################################################## 143 | add_library( freertos_plus_fat STATIC ) 144 | 145 | target_sources( freertos_plus_fat 146 | PRIVATE 147 | include/ff_crc.h 148 | include/ff_devices.h 149 | include/ff_dir.h 150 | include/ff_error.h 151 | include/ff_fat.h 152 | include/ff_fatdef.h 153 | include/ff_file.h 154 | include/ff_format.h 155 | include/ff_headers.h 156 | include/ff_ioman.h 157 | include/ff_locking.h 158 | include/ff_memory.h 159 | include/ff_old_config_defines.h 160 | include/ff_stdio.h 161 | include/ff_string.h 162 | include/ff_sys.h 163 | include/ff_time.h 164 | include/FreeRTOS_errno_FAT.h 165 | include/FreeRTOSFATConfigDefaults.h 166 | 167 | ff_crc.c 168 | $<$:ff_dev_support.c> 169 | ff_dir.c 170 | ff_error.c 171 | ff_fat.c 172 | ff_file.c 173 | ff_format.c 174 | ff_ioman.c 175 | ff_locking.c 176 | ff_memory.c 177 | ff_stdio.c 178 | ff_string.c 179 | ff_sys.c 180 | ff_time.c 181 | ) 182 | 183 | target_include_directories( freertos_plus_fat SYSTEM 184 | PUBLIC 185 | include 186 | ) 187 | 188 | target_compile_definitions( freertos_plus_fat 189 | PUBLIC 190 | ffconfigDEV_SUPPORT=$ 191 | ) 192 | 193 | target_compile_options( freertos_plus_fat 194 | PRIVATE 195 | $<$:-Wno-array-bounds> 196 | $<$:-Wno-cast-qual> 197 | $<$:-Wno-constant-conversion> 198 | $<$:-Wno-covered-switch-default> 199 | $<$:-Wno-declaration-after-statement> 200 | $<$:-Wno-format> 201 | $<$:-Wno-overflow> 202 | $<$:-Wno-padded> 203 | $<$:-Wno-pedantic> 204 | 205 | $<$:-Wno-tautological-constant-out-of-range-compare> 206 | $<$:-Wno-type-limits> 207 | $<$:-Wno-undef> 208 | $<$:-Wno-unused-macros> 209 | ) 210 | 211 | target_link_libraries( freertos_plus_fat 212 | PUBLIC 213 | freertos_config 214 | PRIVATE 215 | freertos_plus_fat_port 216 | freertos_kernel 217 | ) 218 | 219 | add_subdirectory(portable) 220 | add_subdirectory(test) 221 | 222 | # This library requires access to a heap 223 | # FreeRTOS/FreeRTOS-Kernel previously defaulted to heap_4.c 224 | if(NOT DEFINED FREERTOS_HEAP) 225 | message(STATUS "FREERTOS_HEAP not set, setting FREERTOS_HEAP=4") 226 | set(FREERTOS_HEAP 4) 227 | endif() 228 | 229 | if(FREERTOS_PLUS_FAT_FETCH_FREERTOS) 230 | FetchContent_MakeAvailable(freertos_kernel) 231 | endif() 232 | -------------------------------------------------------------------------------- /ff_sys.c: -------------------------------------------------------------------------------- 1 | /* 2 | * FreeRTOS+FAT V2.3.3 3 | * Copyright (C) 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved. 4 | * 5 | * Permission is hereby granted, free of charge, to any person obtaining a copy of 6 | * this software and associated documentation files (the "Software"), to deal in 7 | * the Software without restriction, including without limitation the rights to 8 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 9 | * the Software, and to permit persons to whom the Software is furnished to do so, 10 | * 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, FITNESS 17 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 18 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 19 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 20 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | * 22 | * https://www.FreeRTOS.org 23 | * https://github.com/FreeRTOS 24 | * 25 | */ 26 | 27 | #include 28 | #include 29 | 30 | /* FreeRTOS includes. */ 31 | #include "FreeRTOS.h" 32 | #include "task.h" 33 | #include "portable.h" 34 | 35 | #include "ff_headers.h" 36 | #include "ff_sys.h" 37 | 38 | #ifndef ARRAY_SIZE 39 | #define ARRAY_SIZE( x ) ( int ) ( sizeof( x ) / sizeof( x )[ 0 ] ) 40 | #endif 41 | 42 | /* 43 | * Define a collection of 'file systems' as a simple array 44 | */ 45 | typedef struct xSYSTEM 46 | { 47 | FF_SubSystem_t xSystems[ ffconfigMAX_FILE_SYS ]; 48 | volatile BaseType_t xFileSystemCount; 49 | } ff_sys_t; 50 | 51 | 52 | static ff_sys_t file_systems; 53 | static const char rootDir[] = "/"; 54 | 55 | int FF_FS_Count( void ) 56 | { 57 | return ( int ) file_systems.xFileSystemCount; 58 | } 59 | /*-----------------------------------------------------------*/ 60 | 61 | void FF_FS_Init( void ) 62 | { 63 | memset( &file_systems, '\0', sizeof( file_systems ) ); 64 | 65 | /* There is always a root file system, even if it doesn't have a 66 | * IO manager. */ 67 | file_systems.xFileSystemCount = ( BaseType_t ) 1; 68 | /* Set to "/", second byte is already zero. */ 69 | file_systems.xSystems[ 0 ].pcPath[ 0 ] = ( char ) '/'; 70 | 71 | file_systems.xSystems[ 0 ].xPathlen = 1; 72 | } 73 | /*-----------------------------------------------------------*/ 74 | 75 | int FF_FS_Add( const char * pcPath, 76 | FF_Disk_t * pxDisk ) 77 | { 78 | int iReturn = pdFALSE; 79 | 80 | configASSERT( pxDisk ); 81 | 82 | if( *pcPath != ( char ) '/' ) 83 | { 84 | FF_PRINTF( "FF_FS_Add: Need a \"/\": '%s'\n", pcPath ); 85 | } 86 | else 87 | { 88 | BaseType_t xUseIndex = -1; 89 | size_t uxPathLength = strlen( pcPath ); 90 | 91 | vTaskSuspendAll(); 92 | { 93 | if( file_systems.xFileSystemCount == ( BaseType_t ) 0 ) 94 | { 95 | FF_FS_Init(); 96 | } 97 | 98 | if( uxPathLength == ( size_t ) 1u ) 99 | { 100 | /* This is the "/" path 101 | * and will always be put at index 0 */ 102 | xUseIndex = ( BaseType_t ) 0; 103 | } 104 | else 105 | { 106 | BaseType_t xIndex, xFreeIndex = -1; 107 | FF_SubSystem_t * pxSubSystem = file_systems.xSystems + 1; /* Skip the root entry */ 108 | 109 | for( xIndex = ( BaseType_t ) 1; xIndex < file_systems.xFileSystemCount; xIndex++, pxSubSystem++ ) 110 | { 111 | if( ( pxSubSystem->xPathlen == ( BaseType_t ) uxPathLength ) && 112 | ( memcmp( pxSubSystem->pcPath, pcPath, uxPathLength ) == 0 ) ) 113 | { 114 | /* A system is updated with a new handler. */ 115 | xUseIndex = xIndex; 116 | break; 117 | } 118 | 119 | if( ( pxSubSystem->pxManager == NULL ) && ( xFreeIndex < 0 ) ) 120 | { 121 | /* Remember the first free slot. */ 122 | xFreeIndex = xIndex; 123 | } 124 | } 125 | 126 | if( xUseIndex < ( BaseType_t ) 0 ) 127 | { 128 | if( xFreeIndex >= ( BaseType_t ) 0 ) 129 | { 130 | /* Use the first free slot. */ 131 | xUseIndex = xFreeIndex; 132 | } 133 | else if( file_systems.xFileSystemCount < ARRAY_SIZE( file_systems.xSystems ) ) 134 | { 135 | /* Fill a new entry. */ 136 | xUseIndex = file_systems.xFileSystemCount++; 137 | } 138 | } 139 | } /* uxPathLength != 1 */ 140 | 141 | if( xUseIndex >= ( BaseType_t ) 0 ) 142 | { 143 | iReturn = pdTRUE; 144 | strncpy( file_systems.xSystems[ xUseIndex ].pcPath, pcPath, sizeof( file_systems.xSystems[ xUseIndex ].pcPath ) - 1 ); 145 | file_systems.xSystems[ xUseIndex ].pcPath[ sizeof( file_systems.xSystems[ xUseIndex ].pcPath ) - 1 ] = 0; 146 | file_systems.xSystems[ xUseIndex ].xPathlen = ( BaseType_t ) uxPathLength; 147 | file_systems.xSystems[ xUseIndex ].pxManager = pxDisk->pxIOManager; 148 | } 149 | } 150 | xTaskResumeAll(); 151 | 152 | if( iReturn == pdFALSE ) 153 | { 154 | FF_PRINTF( "FF_FS_Add: Table full '%s' (max = %d)\n", pcPath, ( int ) ARRAY_SIZE( file_systems.xSystems ) ); 155 | } 156 | } 157 | 158 | return iReturn; 159 | } 160 | /*-----------------------------------------------------------*/ 161 | 162 | void FF_FS_Remove( const char * pcPath ) 163 | { 164 | BaseType_t xUseIndex, xIndex; 165 | size_t uxPathLength; 166 | 167 | if( pcPath[ 0 ] == ( char ) '/' ) 168 | { 169 | xUseIndex = -1; 170 | uxPathLength = strlen( pcPath ); 171 | 172 | /* Is it the "/" path ? */ 173 | if( uxPathLength == ( size_t ) 1u ) 174 | { 175 | xUseIndex = 0; 176 | } 177 | else 178 | { 179 | FF_SubSystem_t * pxSubSystem = file_systems.xSystems + 1; 180 | 181 | for( xIndex = 1; xIndex < file_systems.xFileSystemCount; xIndex++, pxSubSystem++ ) 182 | { 183 | if( ( pxSubSystem->xPathlen == ( BaseType_t ) uxPathLength ) && 184 | ( memcmp( pxSubSystem->pcPath, pcPath, uxPathLength ) == 0 ) ) 185 | { 186 | xUseIndex = xIndex; 187 | break; 188 | } 189 | } 190 | } 191 | 192 | if( xUseIndex >= 0 ) 193 | { 194 | vTaskSuspendAll(); 195 | { 196 | file_systems.xSystems[ xUseIndex ].pxManager = NULL; 197 | file_systems.xSystems[ xUseIndex ].xPathlen = ( BaseType_t ) 0; 198 | 199 | for( xIndex = file_systems.xFileSystemCount - 1; xIndex > 0; xIndex-- ) 200 | { 201 | if( file_systems.xSystems[ xIndex ].pxManager != NULL ) 202 | { 203 | /* The slot at 'xIndex' is still in use. */ 204 | break; 205 | } 206 | } 207 | 208 | file_systems.xFileSystemCount = xIndex + 1; 209 | } 210 | xTaskResumeAll(); 211 | } 212 | } 213 | } 214 | /*-----------------------------------------------------------*/ 215 | 216 | int FF_FS_Find( const char * pcPath, 217 | FF_DirHandler_t * pxHandler ) 218 | { 219 | FF_SubSystem_t * pxSubSystem; 220 | size_t uxPathLength; 221 | BaseType_t xUseIndex; 222 | int iReturn; 223 | 224 | pxSubSystem = file_systems.xSystems + 1; 225 | uxPathLength = strlen( pcPath ); 226 | 227 | memset( pxHandler, '\0', sizeof( *pxHandler ) ); 228 | 229 | for( xUseIndex = 1; xUseIndex < file_systems.xFileSystemCount; xUseIndex++, pxSubSystem++ ) 230 | { 231 | /* System "/ram" should not match with "/ram/etc". */ 232 | if( ( uxPathLength >= ( size_t ) pxSubSystem->xPathlen ) && 233 | ( memcmp( pxSubSystem->pcPath, pcPath, ( size_t ) pxSubSystem->xPathlen ) == 0 ) && 234 | ( ( pcPath[ pxSubSystem->xPathlen ] == '\0' ) || ( pcPath[ pxSubSystem->xPathlen ] == '/' ) ) ) 235 | { 236 | if( pcPath[ pxSubSystem->xPathlen ] == '\0' ) 237 | { 238 | pxHandler->pcPath = rootDir; 239 | } 240 | else 241 | { 242 | pxHandler->pcPath = pcPath + pxSubSystem->xPathlen; 243 | } 244 | 245 | pxHandler->pxManager = pxSubSystem->pxManager; 246 | break; 247 | } 248 | } 249 | 250 | if( xUseIndex == file_systems.xFileSystemCount ) 251 | { 252 | pxHandler->pcPath = pcPath; 253 | pxHandler->pxManager = file_systems.xSystems[ 0 ].pxManager; 254 | } 255 | 256 | if( FF_Mounted( pxHandler->pxManager ) ) 257 | { 258 | iReturn = pdTRUE; 259 | } 260 | else 261 | { 262 | iReturn = pdFALSE; 263 | } 264 | 265 | return iReturn; 266 | } 267 | /*-----------------------------------------------------------*/ 268 | 269 | int FF_FS_Get( int xIndex, 270 | FF_SubSystem_t * pxSystem ) 271 | { 272 | int iReturn; 273 | 274 | /* Get a copy of a fs info. */ 275 | if( ( xIndex < 0 ) || ( xIndex >= file_systems.xFileSystemCount ) ) 276 | { 277 | iReturn = pdFALSE; 278 | } 279 | else 280 | { 281 | /* Note: it will copy the contents of 'FF_SubSystem_t'. */ 282 | *pxSystem = file_systems.xSystems[ xIndex ]; 283 | iReturn = pdTRUE; 284 | } 285 | 286 | return iReturn; 287 | } 288 | /*-----------------------------------------------------------*/ 289 | -------------------------------------------------------------------------------- /ff_time.c: -------------------------------------------------------------------------------- 1 | /* 2 | * FreeRTOS+FAT V2.3.3 3 | * Copyright (C) 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved. 4 | * 5 | * Permission is hereby granted, free of charge, to any person obtaining a copy of 6 | * this software and associated documentation files (the "Software"), to deal in 7 | * the Software without restriction, including without limitation the rights to 8 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 9 | * the Software, and to permit persons to whom the Software is furnished to do so, 10 | * 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, FITNESS 17 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 18 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 19 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 20 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | * 22 | * https://www.FreeRTOS.org 23 | * https://github.com/FreeRTOS 24 | * 25 | */ 26 | 27 | #include 28 | #include 29 | #include 30 | 31 | #include "FreeRTOS.h" 32 | #include "task.h" 33 | 34 | #include "ff_time.h" 35 | 36 | /** 37 | * @file ff_time.c 38 | * @ingroup TIME 39 | * 40 | * @defgroup TIME Real-Time Clock Interface 41 | * @brief Allows FreeRTOS+FAT to time-stamp files. 42 | * 43 | * Provides a means for receiving the time on any platform. 44 | **/ 45 | 46 | #if ( ffconfigTIME_SUPPORT != 0 ) /* This if-block spans the rest of the source file. */ 47 | 48 | /** 49 | * @brief Populates an FF_SystemTime_t object with the current time from the system. 50 | * 51 | * The developer must modify this function so that it is suitable for their platform. 52 | * The function must return with 0, and if the time is not available all elements of the 53 | * FF_SystemTime_t object must be zero'd, as in the examples provided. 54 | * 55 | * @param pxTime Pointer to an FF_TIME object. 56 | * 57 | * @return Always returns 0. 58 | **/ 59 | 60 | int32_t FF_GetSystemTime( FF_SystemTime_t * pxTime ) 61 | { 62 | FF_TimeStruct_t xTimeStruct; 63 | 64 | /* Fetch the current time. */ 65 | time_t secs = FreeRTOS_time( NULL ); 66 | 67 | /* Fill the fields in 'xTimeStruct'. */ 68 | FreeRTOS_gmtime_r( &secs, &xTimeStruct ); 69 | 70 | pxTime->Hour = ( uint16_t ) xTimeStruct.tm_hour; 71 | pxTime->Minute = ( uint16_t ) xTimeStruct.tm_min; 72 | pxTime->Second = ( uint16_t ) xTimeStruct.tm_sec; 73 | pxTime->Day = ( uint16_t ) xTimeStruct.tm_mday; 74 | pxTime->Month = ( uint16_t ) xTimeStruct.tm_mon + 1; 75 | pxTime->Year = ( uint16_t ) xTimeStruct.tm_year + 1900; 76 | 77 | return 0; 78 | } /* FF_GetSystemTime() */ 79 | /*-----------------------------------------------------------*/ 80 | 81 | /* 82 | * FreeRTOS+FAT 83 | * Time conversion functions: 84 | * 85 | * FF_TimeStruct_t *FreeRTOS_gmtime_r( const time_t *pxTime, FF_TimeStruct_t *pxTimeBuf ) 86 | * time_t FreeRTOS_mktime(FF_TimeStruct_t *pxTimeBuf) 87 | */ 88 | 89 | #define GMTIME_FIRST_YEAR ( 1970 ) 90 | #define TM_STRUCT_FIRST_YEAR ( 1900 ) 91 | #define SECONDS_PER_MINUTE ( 60 ) 92 | #define MINUTES_PER_HOUR ( 60 ) 93 | #define HOURS_PER_DAY ( 24 ) 94 | #define SECONDS_PER_HOUR ( MINUTES_PER_HOUR * SECONDS_PER_MINUTE ) 95 | #define SECONDS_PER_DAY ( HOURS_PER_DAY * SECONDS_PER_HOUR ) 96 | 97 | /* The first weekday in 'FF_TimeStruct_t' is Sunday. */ 98 | #define WEEK_DAY_SUNDAY 0 99 | #define WEEK_DAY_MONDAY 1 100 | #define WEEK_DAY_TUESDAY 2 101 | #define WEEK_DAY_WEDNESDAY 3 102 | #define WEEK_DAY_THURSDAY 4 103 | #define WEEK_DAY_FRIDAY 5 104 | #define WEEK_DAY_SATURDAY 6 105 | 106 | /* Make a bitmask with a '1' for each 31-day month. */ 107 | #define MM_( month ) ( 1u << ( month - 1 ) ) 108 | #define MASK_LONG_MONTHS ( MM_( 1 ) | MM_( 3 ) | MM_( 5 ) | MM_( 7 ) | MM_( 8 ) | MM_( 10 ) | MM_( 12 ) ) 109 | 110 | #define DAYS_UNTIL_1970 ( ( 1970 * 365 ) + ( 1970 / 4 ) - ( 1970 / 100 ) + ( 1970 / 400 ) ) 111 | #define DAYS_BEFORE_MARCH ( 59 ) 112 | 113 | static portINLINE int iIsLeapyear( int iYear ) 114 | { 115 | int iReturn; 116 | 117 | if( ( iYear % 4 ) != 0 ) 118 | { 119 | /* Not a multiple of 4 years. */ 120 | iReturn = pdFALSE; 121 | } 122 | else if( ( iYear % 400 ) == 0 ) 123 | { 124 | /* Every 4 centuries there is a leap year */ 125 | iReturn = pdTRUE; 126 | } 127 | else if( ( iYear % 100 ) == 0 ) 128 | { 129 | /* Other centuries are not a leap year */ 130 | iReturn = pdFALSE; 131 | } 132 | else 133 | { 134 | /* Otherwise every fourth year. */ 135 | iReturn = pdTRUE; 136 | } 137 | 138 | return iReturn; 139 | } 140 | 141 | static portINLINE unsigned long ulDaysPerYear( int iYear ) 142 | { 143 | unsigned long iDays; 144 | 145 | if( iIsLeapyear( iYear ) ) 146 | { 147 | iDays = 366; 148 | } 149 | else 150 | { 151 | iDays = 365; 152 | } 153 | 154 | return iDays; 155 | } 156 | 157 | static unsigned long iDaysPerMonth( int iYear, 158 | int iMonth ) 159 | { 160 | unsigned long iDays; 161 | 162 | /* Month is zero-based, 1 is February. */ 163 | if( iMonth != 1 ) 164 | { 165 | /* 30 or 31 days? */ 166 | if( ( MASK_LONG_MONTHS & ( 1u << iMonth ) ) != 0 ) 167 | { 168 | iDays = 31; 169 | } 170 | else 171 | { 172 | iDays = 30; 173 | } 174 | } 175 | else if( iIsLeapyear( iYear ) == pdFALSE ) 176 | { 177 | /* February, non leap year. */ 178 | iDays = 28; 179 | } 180 | else 181 | { 182 | /* February, leap year. */ 183 | iDays = 29; 184 | } 185 | 186 | return iDays; 187 | } 188 | 189 | FF_TimeStruct_t * FreeRTOS_gmtime_r( const time_t * pxTime, 190 | FF_TimeStruct_t * pxTimeBuf ) 191 | { 192 | time_t xTime = *pxTime; 193 | unsigned long ulDaySeconds, ulDayNumber; 194 | int iYear = GMTIME_FIRST_YEAR; 195 | int iMonth; 196 | 197 | /* Clear all fields, some might not get set here. */ 198 | memset( ( void * ) pxTimeBuf, '\0', sizeof( *pxTimeBuf ) ); 199 | 200 | /* Seconds since last midnight. */ 201 | ulDaySeconds = ( unsigned long ) ( xTime % SECONDS_PER_DAY ); 202 | 203 | /* Days since 1 Jan 1970. */ 204 | ulDayNumber = ( unsigned long ) ( xTime / SECONDS_PER_DAY ); 205 | 206 | /* Today's HH:MM:SS */ 207 | pxTimeBuf->tm_hour = ( int ) ulDaySeconds / SECONDS_PER_HOUR; 208 | pxTimeBuf->tm_min = ( ulDaySeconds % SECONDS_PER_HOUR ) / 60; 209 | pxTimeBuf->tm_sec = ulDaySeconds % 60; 210 | 211 | /* Today's week day, knowing that 1-1-1970 was a THursday. */ 212 | pxTimeBuf->tm_wday = ( ulDayNumber + WEEK_DAY_THURSDAY ) % 7; 213 | 214 | for( ; ; ) 215 | { 216 | /* Keep subtracting 365 (or 366) days while possible. */ 217 | unsigned long ulDays = ulDaysPerYear( iYear ); 218 | 219 | if( ulDayNumber < ulDays ) 220 | { 221 | break; 222 | } 223 | 224 | ulDayNumber -= ulDays; 225 | iYear++; 226 | } 227 | 228 | /* Subtract 1900. */ 229 | pxTimeBuf->tm_year = iYear - TM_STRUCT_FIRST_YEAR; 230 | 231 | /* The day within this year. */ 232 | pxTimeBuf->tm_yday = ( int ) ulDayNumber; 233 | 234 | /* Month are counted as 0..11 */ 235 | iMonth = 0; 236 | 237 | for( ; ; ) 238 | { 239 | unsigned long ulDays = iDaysPerMonth( iYear, iMonth ); 240 | 241 | /* Keep subtracting 30 (or 28, 29, or 31) days while possible. */ 242 | if( ulDayNumber < ulDays ) 243 | { 244 | break; 245 | } 246 | 247 | ulDayNumber -= ulDays; 248 | iMonth++; 249 | } 250 | 251 | pxTimeBuf->tm_mon = iMonth; 252 | 253 | /* Month days are counted as 1..31 */ 254 | pxTimeBuf->tm_mday = ( int ) ulDayNumber + 1; 255 | 256 | return pxTimeBuf; 257 | } 258 | 259 | time_t FreeRTOS_mktime( const FF_TimeStruct_t * pxTimeBuf ) 260 | { 261 | /* Get year AD. */ 262 | int iYear = 1900 + pxTimeBuf->tm_year; /* 20xx */ 263 | /* Get month zero-based. */ 264 | int iMonth = pxTimeBuf->tm_mon; /* 0..11 */ 265 | time_t ulDays; 266 | time_t ulResult; 267 | 268 | ulDays = ( time_t ) ( pxTimeBuf->tm_mday - 1 ); /* 1..31 */ 269 | 270 | /* Make March the first month. */ 271 | iMonth -= 2; 272 | 273 | if( iMonth < 0 ) 274 | { 275 | /* January or February: leap day has yet to come for this year. */ 276 | iYear--; 277 | iMonth += 12; 278 | } 279 | 280 | /* Add the number of days past until this month. */ 281 | ulDays += ( time_t ) ( ( ( 306 * iMonth ) + 5 ) / 10 ); 282 | 283 | /* Add days past before this year: */ 284 | ulDays += 285 | +( time_t ) ( iYear * 365 ) /* Every normal year. */ 286 | + ( time_t ) ( iYear / 4 ) /* Plus a day for every leap year. */ 287 | - ( time_t ) ( iYear / 100 ) /* Minus the centuries. */ 288 | + ( time_t ) ( iYear / 400 ) /* Except every fourth century. */ 289 | - ( time_t ) ( DAYS_UNTIL_1970 ) /* Minus the days before 1-1-1970 */ 290 | + ( time_t ) ( DAYS_BEFORE_MARCH ); /* Because 2 months were subtracted. */ 291 | 292 | ulResult = 293 | ( ulDays * SECONDS_PER_DAY ) + 294 | ( time_t ) ( ( pxTimeBuf->tm_hour * SECONDS_PER_HOUR ) + 295 | ( pxTimeBuf->tm_min * SECONDS_PER_MINUTE ) + 296 | ( pxTimeBuf->tm_sec ) ); 297 | 298 | return ulResult; 299 | } 300 | 301 | #endif /* ffconfigTIME_SUPPORT */ 302 | -------------------------------------------------------------------------------- /portable/Zynq/xsdps.h: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * 3 | * Copyright (C) 2013 - 2015 Xilinx, Inc. All rights reserved. 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 13 | * all copies or substantial portions of the Software. 14 | * 15 | * Use of the Software is limited solely to applications: 16 | * (a) running on a Xilinx device, or 17 | * (b) that interact with a Xilinx device through a bus or interconnect. 18 | * 19 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 20 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 21 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 22 | * XILINX BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 23 | * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF 24 | * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 25 | * SOFTWARE. 26 | * 27 | * Except as contained in this notice, the name of the Xilinx shall not be used 28 | * in advertising or otherwise to promote the sale, use or other dealings in 29 | * this Software without prior written authorization from Xilinx. 30 | * 31 | ******************************************************************************/ 32 | /*****************************************************************************/ 33 | 34 | /** 35 | * 36 | * @file xsdps.h 37 | * @addtogroup sdps_v2_5 38 | * @{ 39 | * @details 40 | * 41 | * This file contains the implementation of XSdPs driver. 42 | * This driver is used initialize read from and write to the SD card. 43 | * Features such as switching bus width to 4-bit and switching to high speed, 44 | * changing clock frequency, block size etc. are supported. 45 | * SD 2.0 uses 1/4 bus width and speeds of 25/50KHz. Initialization, however 46 | * is done using 1-bit bus width and 400KHz clock frequency. 47 | * SD commands are classified as broadcast and addressed. Commands can be 48 | * those with response only (using only command line) or 49 | * response + data (using command and data lines). 50 | * Only one command can be sent at a time. During a data transfer however, 51 | * when data lines are in use, certain commands (which use only the command 52 | * line) can be sent, most often to obtain status. 53 | * This driver does not support multi card slots at present. 54 | * 55 | * Initialization: 56 | * This includes initialization on the host controller side to select 57 | * clock frequency, bus power and default transfer related parameters. 58 | * The default voltage is 3.3V. 59 | * On the SD card side, the initialization and identification state diagram is 60 | * implemented. This resets the card, gives it a unique address/ID and 61 | * identifies key card related specifications. 62 | * 63 | * Data transfer: 64 | * The SD card is put in tranfer state to read from or write to it. 65 | * The default block size is 512 bytes and if supported, 66 | * default bus width is 4-bit and bus speed is High speed. 67 | * The read and write functions are implemented in polled mode using ADMA2. 68 | * 69 | * At any point, when key parameters such as block size or 70 | * clock/speed or bus width are modified, this driver takes care of 71 | * maintaining the same selection on host and card. 72 | * All error bits in host controller are monitored by the driver and in the 73 | * event one of them is set, driver will clear the interrupt status and 74 | * communicate failure to the upper layer. 75 | * 76 | * File system use: 77 | * This driver can be used with xilffs library to read and write files to SD. 78 | * (Please refer to procedure in diskio.c). The file system read/write example 79 | * in polled mode can used for reference. 80 | * 81 | * There is no example for using SD driver without file system at present. 82 | * However, the driver can be used without the file system. The glue layer 83 | * in file system can be used as reference for the same. The block count 84 | * passed to the read/write function in one call is limited by the ADMA2 85 | * descriptor table and hence care will have to be taken to call read/write 86 | * API's in a loop for large file sizes. 87 | * 88 | * Interrupt mode is not supported because it offers no improvement when used 89 | * with file system. 90 | * 91 | * eMMC support: 92 | * SD driver supports SD and eMMC based on the "enable MMC" parameter in SDK. 93 | * The features of eMMC supported by the driver will depend on those supported 94 | * by the host controller. The current driver supports read/write on eMMC card 95 | * using 4-bit and high speed mode currently. 96 | * 97 | * Features not supported include - card write protect, password setting, 98 | * lock/unlock, interrupts, SDMA mode, programmed I/O mode and 99 | * 64-bit addressed ADMA2, erase/pre-erase commands. 100 | * 101 | *
102 |  * MODIFICATION HISTORY:
103 |  *
104 |  * Ver   Who    Date     Changes
105 |  * ----- ---    -------- -----------------------------------------------
106 |  * 1.00a hk/sg  10/17/13 Initial release
107 |  * 2.0   hk      03/07/14 Version number revised.
108 |  * 2.1   hk     04/18/14 Increase sleep for eMMC switch command.
109 |  *                       Add sleep for microblaze designs. CR# 781117.
110 |  * 2.2   hk     07/28/14 Make changes to enable use of data cache.
111 |  * 2.3   sk     09/23/14 Send command for relative card address
112 |  *                       when re-initialization is done.CR# 819614.
113 |  *						Use XSdPs_Change_ClkFreq API whenever changing
114 |  *						clock.CR# 816586.
115 |  * 2.4	sk	   12/04/14 Added support for micro SD without
116 |  *                      WP/CD. CR# 810655.
117 |  *						Checked for DAT Inhibit mask instead of CMD
118 |  *                      Inhibit mask in Cmd Transfer API.
119 |  *						Added Support for SD Card v1.0
120 |  * 2.5  sg		07/09/15 Added SD 3.0 features
121 |  *       kvn     07/15/15 Modified the code according to MISRAC-2012.
122 |  * 2.6   sk     10/12/15 Added support for SD card v1.0 CR# 840601.
123 |  *
124 |  * 
125 | * 126 | ******************************************************************************/ 127 | 128 | 129 | #ifndef SDPS_H_ 130 | #define SDPS_H_ 131 | 132 | #ifdef __cplusplus 133 | extern "C" { 134 | #endif 135 | 136 | #include "xstatus.h" 137 | #include "xsdps_hw.h" 138 | #include 139 | 140 | /************************** Constant Definitions *****************************/ 141 | 142 | #define XSDPS_CT_ERROR 0x2U /**< Command timeout flag */ 143 | 144 | /**************************** Type Definitions *******************************/ 145 | 146 | /** 147 | * This typedef contains configuration information for the device. 148 | */ 149 | typedef struct 150 | { 151 | u16 DeviceId; /**< Unique ID of device */ 152 | u32 BaseAddress; /**< Base address of the device */ 153 | u32 InputClockHz; /**< Input clock frequency */ 154 | u32 CardDetect; /**< Card Detect */ 155 | u32 WriteProtect; /**< Write Protect */ 156 | } XSdPs_Config; 157 | 158 | /* ADMA2 descriptor table */ 159 | typedef struct 160 | { 161 | u16 Attribute; /**< Attributes of descriptor */ 162 | u16 Length; /**< Length of current dma transfer */ 163 | u32 Address; /**< Address of current dma transfer */ 164 | } XSdPs_Adma2Descriptor; 165 | 166 | /** 167 | * The XSdPs driver instance data. The user is required to allocate a 168 | * variable of this type for every SD device in the system. A pointer 169 | * to a variable of this type is then passed to the driver API functions. 170 | */ 171 | typedef struct 172 | { 173 | XSdPs_Config Config; /**< Configuration structure */ 174 | u32 IsReady; /**< Device is initialized and ready */ 175 | u32 Host_Caps; /**< Capabilities of host controller */ 176 | u32 Host_CapsExt; /**< Extended Capabilities */ 177 | u32 HCS; /**< High capacity support in card */ 178 | u8 CardType; /**< Type of card - SD/MMC/eMMC */ 179 | u8 Card_Version; /**< Card version */ 180 | u8 HC_Version; /**< Host controller version */ 181 | u8 BusWidth; /**< Current operating bus width */ 182 | u32 BusSpeed; /**< Current operating bus speed */ 183 | u8 Switch1v8; /**< 1.8V Switch support */ 184 | u32 CardID[ 4 ]; /**< Card ID Register */ 185 | u32 RelCardAddr; /**< Relative Card Address */ 186 | u32 CardSpecData[ 4 ]; /**< Card Specific Data Register */ 187 | u32 SdCardConfig; /**< Sd Card Configuration Register */ 188 | /**< ADMA Descriptors */ 189 | #ifdef __ICCARM__ 190 | #pragma data_alignment = 32 191 | XSdPs_Adma2Descriptor Adma2_DescrTbl[ 32 ]; 192 | #pragma data_alignment = 4 193 | #else 194 | XSdPs_Adma2Descriptor Adma2_DescrTbl[ 32 ] __attribute__( ( aligned( 32 ) ) ); 195 | #endif 196 | } XSdPs; 197 | 198 | /***************** Macros (Inline Functions) Definitions *********************/ 199 | 200 | /************************** Function Prototypes ******************************/ 201 | XSdPs_Config * XSdPs_LookupConfig( u16 DeviceId ); 202 | s32 XSdPs_CfgInitialize( XSdPs * InstancePtr, 203 | XSdPs_Config * ConfigPtr, 204 | u32 EffectiveAddr ); 205 | s32 XSdPs_SdCardInitialize( XSdPs * InstancePtr ); 206 | s32 XSdPs_ReadPolled( XSdPs * InstancePtr, 207 | u32 Arg, 208 | u32 BlkCnt, 209 | u8 * Buff ); 210 | s32 XSdPs_WritePolled( XSdPs * InstancePtr, 211 | u32 Arg, 212 | u32 BlkCnt, 213 | const u8 * Buff ); 214 | s32 XSdPs_SetBlkSize( XSdPs * InstancePtr, 215 | u16 BlkSize ); 216 | s32 XSdPs_Select_Card( XSdPs * InstancePtr ); 217 | s32 XSdPs_Change_ClkFreq( XSdPs * InstancePtr, 218 | u32 SelFreq ); 219 | s32 XSdPs_Change_BusWidth( XSdPs * InstancePtr ); 220 | s32 XSdPs_Change_BusSpeed( XSdPs * InstancePtr ); 221 | s32 XSdPs_Get_BusWidth( XSdPs * InstancePtr, 222 | u8 * SCR ); 223 | s32 XSdPs_Get_BusSpeed( XSdPs * InstancePtr, 224 | u8 * ReadBuff ); 225 | s32 XSdPs_Pullup( XSdPs * InstancePtr ); 226 | s32 XSdPs_MmcCardInitialize( XSdPs * InstancePtr ); 227 | s32 XSdPs_CardInitialize( XSdPs * InstancePtr ); 228 | s32 XSdPs_Get_Mmc_ExtCsd( XSdPs * InstancePtr, 229 | u8 * ReadBuff ); 230 | /* Wait for Command/Transfer Complete. */ 231 | s32 XSdPs_Wait_For( XSdPs * InstancePtr, 232 | u32 Mask, 233 | u32 Wait ); 234 | 235 | #ifdef __cplusplus 236 | } 237 | #endif 238 | 239 | #endif /* SD_H_ */ 240 | /** @} */ 241 | --------------------------------------------------------------------------------