diff --git a/Sts1CobcSw/FileSystem/CMakeLists.txt b/Sts1CobcSw/FileSystem/CMakeLists.txt index 87576075..63e4ddac 100644 --- a/Sts1CobcSw/FileSystem/CMakeLists.txt +++ b/Sts1CobcSw/FileSystem/CMakeLists.txt @@ -9,4 +9,5 @@ if(CMAKE_SYSTEM_NAME STREQUAL Generic) target_link_libraries(Sts1CobcSw_FileSystem PRIVATE rodos::rodos Sts1CobcSw_Periphery) else() target_sources(Sts1CobcSw_FileSystem PRIVATE LfsRam.cpp) + target_link_libraries(Sts1CobcSw_FileSystem PRIVATE rodos::without_main_on_linux) endif() diff --git a/Sts1CobcSw/FileSystem/LfsFlash.cpp b/Sts1CobcSw/FileSystem/LfsFlash.cpp index 20b0508e..02f4c133 100644 --- a/Sts1CobcSw/FileSystem/LfsFlash.cpp +++ b/Sts1CobcSw/FileSystem/LfsFlash.cpp @@ -5,6 +5,7 @@ #include #include +#include #include #include @@ -30,6 +31,12 @@ auto Lock(lfs_config const * config) -> int; auto Unlock(lfs_config const * config) -> int; +// TODO: Test with real HW +// max. 3.5 ms acc. W25Q01JV datasheet +constexpr auto pageProgramTimeout = 5 * RODOS::MILLISECONDS; +// max. 400 ms acc. W25Q01JV datasheet (lfs_config.block_size = flash::sectorSize) +constexpr auto blockEraseTimeout = 500 * RODOS::MILLISECONDS; + auto readBuffer = std::array{}; auto programBuffer = decltype(readBuffer){}; auto lookaheadBuffer = std::array{}; // NOLINT(*magic-numbers) @@ -63,11 +70,7 @@ lfs_config const lfsConfig = lfs_config{.context = nullptr, .metadata_max = flash::sectorSize, .inline_max = 0}; -// TODO: Test with real HW -// max. 3.5 ms acc. W25Q01JV datasheet -constexpr auto pageProgramTimeout = 5 * RODOS::MILLISECONDS; -// max. 400 ms acc. W25Q01JV datasheet (lfs_config.block_size = flash::sectorSize) -constexpr auto blockEraseTimeout = 500 * RODOS::MILLISECONDS; +auto semaphore = RODOS::Semaphore(); auto Initialize() -> void @@ -141,16 +144,16 @@ auto Sync([[maybe_unused]] lfs_config const * config) -> int } -// TODO: Add a proper implementation auto Lock([[maybe_unused]] lfs_config const * config) -> int { + semaphore.enter(); return 0; } -// TODO: Add a proper implementation auto Unlock([[maybe_unused]] lfs_config const * config) -> int { + semaphore.leave(); return 0; } } diff --git a/Sts1CobcSw/FileSystem/LfsRam.cpp b/Sts1CobcSw/FileSystem/LfsRam.cpp index f06aa423..f42cb3ca 100644 --- a/Sts1CobcSw/FileSystem/LfsRam.cpp +++ b/Sts1CobcSw/FileSystem/LfsRam.cpp @@ -6,6 +6,8 @@ #include // IWYU pragma: associated #include +#include + #include #include #include @@ -68,6 +70,8 @@ lfs_config const lfsConfig = lfs_config{.context = nullptr, .metadata_max = sectorSize, .inline_max = 0}; +auto semaphore = RODOS::Semaphore(); + auto Initialize() -> void { @@ -112,16 +116,16 @@ auto Sync([[maybe_unused]] lfs_config const * config) -> int } -// TODO: Add a proper implementation auto Lock([[maybe_unused]] lfs_config const * config) -> int { + semaphore.enter(); return 0; } -// TODO: Add a proper implementation auto Unlock([[maybe_unused]] lfs_config const * config) -> int { + semaphore.leave(); return 0; } } diff --git a/Tests/UnitTests/CMakeLists.txt b/Tests/UnitTests/CMakeLists.txt index 4ed583c3..1b7b56f5 100644 --- a/Tests/UnitTests/CMakeLists.txt +++ b/Tests/UnitTests/CMakeLists.txt @@ -14,11 +14,6 @@ target_link_libraries( Sts1CobcSw_Utility ) -add_program(LfsRam LfsRam.test.cpp) -target_link_libraries( - Sts1CobcSwTests_LfsRam PRIVATE Catch2::Catch2WithMain littlefs::littlefs Sts1CobcSw_FileSystem -) - add_program(MajorityVote MajorityVote.test.cpp) target_link_libraries( Sts1CobcSwTests_MajorityVote PRIVATE Catch2::Catch2WithMain Sts1CobcSw_Utility @@ -86,6 +81,11 @@ target_link_libraries( ) add_test(NAME FramRingArray COMMAND Sts1CobcSwTests_FramRingArray) +add_program(LfsRam LfsRam.test.cpp UnitTestThread.cpp) +target_link_libraries( + Sts1CobcSwTests_LfsRam PRIVATE rodos::rodos littlefs::littlefs Sts1CobcSw_FileSystem +) + add_program(LfsWrapper LfsWrapper.test.cpp UnitTestThread.cpp) target_link_libraries( Sts1CobcSwTests_LfsWrapper PRIVATE rodos::rodos littlefs::littlefs Sts1CobcSw_FileSystem diff --git a/Tests/UnitTests/LfsRam.test.cpp b/Tests/UnitTests/LfsRam.test.cpp index 42da8b06..1f42af58 100644 --- a/Tests/UnitTests/LfsRam.test.cpp +++ b/Tests/UnitTests/LfsRam.test.cpp @@ -1,47 +1,47 @@ -#include +#include -#include +#include #include -TEST_CASE("RAM memory device") +auto RunUnitTest() -> void { sts1cobcsw::fs::Initialize(); auto lfs = lfs_t{}; auto errorCode = lfs_format(&lfs, &sts1cobcsw::fs::lfsConfig); - REQUIRE(errorCode == 0); + Require(errorCode == 0); errorCode = lfs_mount(&lfs, &sts1cobcsw::fs::lfsConfig); - REQUIRE(errorCode == 0); + Require(errorCode == 0); auto const * directoryPath = "MyFolder"; errorCode = lfs_mkdir(&lfs, directoryPath); - REQUIRE(errorCode == 0); + Require(errorCode == 0); auto const * filePath = "MyFolder/MyFile"; auto file = lfs_file_t{}; errorCode = lfs_file_open(&lfs, &file, filePath, LFS_O_WRONLY | LFS_O_CREAT); - REQUIRE(errorCode == 0); + Require(errorCode == 0); int number = 123; errorCode = lfs_file_write(&lfs, &file, &number, sizeof(number)); - REQUIRE(errorCode == sizeof(number)); + Require(errorCode == sizeof(number)); errorCode = lfs_file_close(&lfs, &file); - REQUIRE(errorCode == 0); + Require(errorCode == 0); errorCode = lfs_unmount(&lfs); - REQUIRE(errorCode == 0); + Require(errorCode == 0); errorCode = lfs_mount(&lfs, &sts1cobcsw::fs::lfsConfig); - REQUIRE(errorCode == 0); + Require(errorCode == 0); errorCode = lfs_file_open(&lfs, &file, filePath, LFS_O_RDONLY); - REQUIRE(errorCode == 0); + Require(errorCode == 0); int readNumber = 0; errorCode = lfs_file_read(&lfs, &file, &readNumber, sizeof(number)); - REQUIRE(errorCode == sizeof(number)); - REQUIRE(readNumber == number); + Require(errorCode == sizeof(number)); + Require(readNumber == number); errorCode = lfs_file_close(&lfs, &file); - REQUIRE(errorCode == 0); + Require(errorCode == 0); } diff --git a/Tests/UnitTests/LfsWrapper.test.cpp b/Tests/UnitTests/LfsWrapper.test.cpp index 1204fb9e..a78f49c4 100644 --- a/Tests/UnitTests/LfsWrapper.test.cpp +++ b/Tests/UnitTests/LfsWrapper.test.cpp @@ -13,6 +13,7 @@ #include #include + using sts1cobcsw::Byte; using sts1cobcsw::Span; using sts1cobcsw::fs::Path;