Skip to content

Commit

Permalink
✨ (ext-flash): Add getSize method
Browse files Browse the repository at this point in the history
  • Loading branch information
YannLocatelli committed Sep 21, 2021
1 parent d563fed commit eab36f7
Show file tree
Hide file tree
Showing 9 changed files with 31 additions and 4 deletions.
2 changes: 1 addition & 1 deletion drivers/CoreFlashMemory/include/CoreFlashMemory.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ class CoreFlashMemory : public interface::FlashMemory
explicit CoreFlashMemory(interface::FlashMemory &driver) : _driver(driver) {};

void initialize() final;

void setFrequency(int hz) final;
auto getSize() -> size_t final;

auto read(uint32_t address, char *buffer, const size_t buffer_length) -> size_t final;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ class CoreFlashMemoryIS25LP016D : public interface::FlashMemory
explicit CoreFlashMemoryIS25LP016D(interface::QSPI &qspi) : _qspi(qspi) {};

void initialize() final;

void setFrequency(int hz = 133'000'000) final;
auto getSize() -> size_t final;

auto read(uint32_t address, char *buffer, const size_t buffer_length) -> size_t final;

Expand Down
1 change: 1 addition & 0 deletions drivers/CoreFlashMemory/include/interface/FlashMemory.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ class FlashMemory

virtual void initialize() = 0;
virtual void setFrequency(int hz) = 0;
virtual auto getSize() -> size_t = 0;

virtual auto read(uint32_t address, char *buffer, const size_t buffer_length) -> size_t = 0;
};
Expand Down
5 changes: 5 additions & 0 deletions drivers/CoreFlashMemory/source/CoreFlashMemory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ void CoreFlashMemory::setFrequency(int hz)
_driver.setFrequency(hz);
}

auto CoreFlashMemory::getSize() -> size_t
{
return _driver.getSize();
}

auto CoreFlashMemory::read(uint32_t address, char *buffer, const size_t buffer_length) -> size_t
{
return _driver.read(address, buffer, buffer_length);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ void CoreFlashMemoryIS25LP016D::setFrequency(int hz)
_qspi.setFrequency(hz);
}

auto CoreFlashMemoryIS25LP016D::getSize() -> size_t
{
return flash_memory::is25lp016d::size;
}

void CoreFlashMemoryIS25LP016D::configureDataTransmissionFormat()
{
_qspi.configureDataTransmissionFormat(QSPI_CFG_BUS_SINGLE, QSPI_CFG_BUS_SINGLE, QSPI_CFG_ADDR_SIZE_24,
Expand All @@ -25,7 +30,7 @@ void CoreFlashMemoryIS25LP016D::configureDataTransmissionFormat()

auto CoreFlashMemoryIS25LP016D::read(uint32_t address, char *buffer, const size_t bytes_to_read) -> size_t
{
if (address + bytes_to_read > flash_memory::is25lp016d::size) {
if (address + bytes_to_read > getSize()) {
return 0;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,14 @@ TEST_F(CoreFlashMemoryIS25LP016DTest, initialize)
flash_memory_is25lp.initialize();
}

TEST_F(CoreFlashMemoryIS25LP016DTest, getSize)
{
auto expected_size = flash_memory::is25lp016d::size;
auto actual_size = flash_memory_is25lp.getSize();

ASSERT_EQ(expected_size, actual_size);
}

TEST_F(CoreFlashMemoryIS25LP016DTest, read)
{
const size_t bytes_to_read = 0x10;
Expand Down
7 changes: 7 additions & 0 deletions drivers/CoreFlashMemory/tests/CoreFlashMemory_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,13 @@ TEST_F(CoreFlashMemoryTest, setFrequency)
flash_memory.setFrequency(expected_value);
}

TEST_F(CoreFlashMemoryTest, getSize)
{
EXPECT_CALL(flash_memory_driver_mock, getSize).Times(1);

flash_memory.getSize();
}

TEST_F(CoreFlashMemoryTest, read)
{
const size_t bytes_to_read = 0x10;
Expand Down
2 changes: 1 addition & 1 deletion spikes/lk_flash_memory/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,6 @@ auto main() -> int
auto bytes_read = coreflashmemory.read(address, buffer, bytes_to_read);
log_info("Content at 0x%x (%dB): %s", address, bytes_read, buffer);

address = address + bytes_to_read < flash_memory::is25lp016d::size ? address + bytes_to_read : 0x00;
address = address + bytes_to_read < coreflashmemory.getSize() ? address + bytes_to_read : 0x00;
}
}
1 change: 1 addition & 0 deletions tests/unit/mocks/mocks/leka/CoreFlashMemoryDriver.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ class CoreFlashMemoryDriver : public interface::FlashMemory
public:
MOCK_METHOD(void, initialize, (), (override));
MOCK_METHOD(void, setFrequency, (int), (override));
MOCK_METHOD(size_t, getSize, (), (override));

MOCK_METHOD(size_t, read, (uint32_t, char *, const size_t), (override));
};
Expand Down

0 comments on commit eab36f7

Please sign in to comment.