Skip to content

Commit

Permalink
Rename storage to memory
Browse files Browse the repository at this point in the history
  • Loading branch information
PatrickKa committed Jul 6, 2024
1 parent dd4690a commit ac96f14
Show file tree
Hide file tree
Showing 8 changed files with 17 additions and 17 deletions.
4 changes: 2 additions & 2 deletions Sts1CobcSw/FileSystem/LfsFlash.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//! @file
//! @brief Implement a flash storage device for littlefs.
//! @brief Implement a flash memory device for littlefs.

#include <Sts1CobcSw/FileSystem/LfsStorageDevice.hpp> // IWYU pragma: associated
#include <Sts1CobcSw/FileSystem/LfsMemoryDevice.hpp> // IWYU pragma: associated
#include <Sts1CobcSw/Periphery/Flash.hpp>
#include <Sts1CobcSw/Serial/Byte.hpp>

Expand Down
File renamed without changes.
18 changes: 9 additions & 9 deletions Sts1CobcSw/FileSystem/LfsRam.cpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
//! @file
//! @brief Simulate a storage device for littlefs in RAM.
//! @brief Simulate a memory device for littlefs in RAM.
//!
//! This is useful for testing the file system without using a real flash memory.

#include <Sts1CobcSw/FileSystem/LfsStorageDevice.hpp> // IWYU pragma: associated
#include <Sts1CobcSw/FileSystem/LfsMemoryDevice.hpp> // IWYU pragma: associated
#include <Sts1CobcSw/Serial/Byte.hpp>

#include <algorithm>
Expand All @@ -30,9 +30,9 @@ auto Sync(lfs_config const * config) -> int;

constexpr auto pageSize = 256;
constexpr auto sectorSize = 4 * 1024;
constexpr auto storageSize = 128 * 1024 * 1024;
constexpr auto memorySize = 128 * 1024 * 1024;

auto storage = std::vector<Byte>();
auto memory = std::vector<Byte>();
auto readBuffer = std::array<Byte, lfsCacheSize>{};
auto programBuffer = decltype(readBuffer){};
auto lookaheadBuffer = std::array<Byte, 64>{}; // NOLINT(*magic-numbers)
Expand All @@ -50,7 +50,7 @@ lfs_config const lfsConfig = lfs_config{.context = nullptr,
.read_size = pageSize,
.prog_size = pageSize,
.block_size = sectorSize,
.block_count = storageSize / sectorSize,
.block_count = memorySize / sectorSize,
.block_cycles = 200,
.cache_size = readBuffer.size(),
.lookahead_size = lookaheadBuffer.size(),
Expand All @@ -67,7 +67,7 @@ lfs_config const lfsConfig = lfs_config{.context = nullptr,

auto Initialize() -> void
{
storage.resize(storageSize, 0xFF_b); // NOLINT(*magic-numbers*)
memory.resize(memorySize, 0xFF_b); // NOLINT(*magic-numbers*)
}


Expand All @@ -78,7 +78,7 @@ auto Read(lfs_config const * config,
lfs_size_t size) -> int
{
auto start = static_cast<int>(blockNo * config->block_size + offset);
std::copy_n(storage.begin() + start, size, static_cast<Byte *>(buffer));
std::copy_n(memory.begin() + start, size, static_cast<Byte *>(buffer));
return 0;
}

Expand All @@ -89,15 +89,15 @@ auto Program(lfs_config const * config,
lfs_size_t size) -> int
{
auto start = static_cast<int>(blockNo * config->block_size + offset);
std::copy_n(static_cast<Byte const *>(buffer), size, storage.begin() + start);
std::copy_n(static_cast<Byte const *>(buffer), size, memory.begin() + start);
return 0;
}


auto Erase(lfs_config const * config, lfs_block_t blockNo) -> int
{
auto start = static_cast<int>(blockNo * config->block_size);
std::fill_n(storage.begin() + start, config->block_size, 0xFF_b); // NOLINT(*magic-numbers*)
std::fill_n(memory.begin() + start, config->block_size, 0xFF_b); // NOLINT(*magic-numbers*)
return 0;
}

Expand Down
2 changes: 1 addition & 1 deletion Sts1CobcSw/FileSystem/LfsWrapper.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@


#include <Sts1CobcSw/FileSystem/ErrorsAndResult.hpp>
#include <Sts1CobcSw/FileSystem/LfsStorageDevice.hpp>
#include <Sts1CobcSw/FileSystem/LfsMemoryDevice.hpp>
#include <Sts1CobcSw/Serial/Byte.hpp>

#include <littlefs/lfs.h>
Expand Down
4 changes: 2 additions & 2 deletions Tests/UnitTests/LfsRam.test.cpp
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
#include <Sts1CobcSw/FileSystem/LfsStorageDevice.hpp>
#include <Sts1CobcSw/FileSystem/LfsMemoryDevice.hpp>

#include <catch2/catch_test_macros.hpp>

#include <littlefs/lfs.h>


TEST_CASE("RAM storage device")
TEST_CASE("RAM memory device")
{
sts1cobcsw::fs::Initialize();
auto lfs = lfs_t{};
Expand Down
2 changes: 1 addition & 1 deletion Tests/UnitTests/LfsWrapper.test.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include <Sts1CobcSw/FileSystem/ErrorsAndResult.hpp>
#include <Sts1CobcSw/FileSystem/LfsStorageDevice.hpp>
#include <Sts1CobcSw/FileSystem/LfsMemoryDevice.hpp>
#include <Sts1CobcSw/FileSystem/LfsWrapper.hpp>

#include <catch2/catch_test_macros.hpp>
Expand Down
2 changes: 1 addition & 1 deletion Tests/UnitTests/LfsWrapperExecutable.test.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include <Sts1CobcSw/FileSystem/ErrorsAndResult.hpp>
#include <Sts1CobcSw/FileSystem/LfsStorageDevice.hpp>
#include <Sts1CobcSw/FileSystem/LfsMemoryDevice.hpp>
#include <Sts1CobcSw/FileSystem/LfsWrapper.hpp>

// #include <catch2/catch_test_macros.hpp>
Expand Down
2 changes: 1 addition & 1 deletion iwyu.imp
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
{ include: ["\"Sts1CobcSw/Edu/Types.hpp\"", "public", "<Sts1CobcSw/Edu/Types.hpp>", "public"] },
{ include: ["\"Sts1CobcSw/FileSystem/ErrorsAndResult.hpp\"", "public", "<Sts1CobcSw/FileSystem/ErrorsAndResult.hpp>", "public"] },
{ include: ["\"Sts1CobcSw/FileSystem/FileSystem.hpp\"", "public", "<Sts1CobcSw/FileSystem/FileSystem.hpp>", "public"] },
{ include: ["\"Sts1CobcSw/FileSystem/LfsStorageDevice.hpp\"", "public", "<Sts1CobcSw/FileSystem/LfsStorageDevice.hpp>", "public"] },
{ include: ["\"Sts1CobcSw/FileSystem/LfsMemoryDevice.hpp\"", "public", "<Sts1CobcSw/FileSystem/LfsMemoryDevice.hpp>", "public"] },
{ include: ["\"Sts1CobcSw/FileSystem/LfsWrapper.hpp\"", "public", "<Sts1CobcSw/FileSystem/LfsWrapper.hpp>", "public"] },
{ include: ["\"Sts1CobcSw/Hal/GpioPin.hpp\"", "public", "<Sts1CobcSw/Hal/GpioPin.hpp>", "public"] },
{ include: ["\"Sts1CobcSw/Hal/IoNames.hpp\"", "public", "<Sts1CobcSw/Hal/IoNames.hpp>", "public"] },
Expand Down

0 comments on commit ac96f14

Please sign in to comment.