diff --git a/drivers/CoreFlashMemory/include/CoreFlashMemory.h b/drivers/CoreFlashMemory/include/CoreFlashMemory.h index 9e83ad2e59..054f0e8353 100644 --- a/drivers/CoreFlashMemory/include/CoreFlashMemory.h +++ b/drivers/CoreFlashMemory/include/CoreFlashMemory.h @@ -15,8 +15,8 @@ class CoreFlashMemory : public interface::FlashMemory explicit CoreFlashMemory(interface::FlashMemory &driver) : _driver(driver) {}; void initialize() final; - void setFrequency(int hz) final; + size_t getSize() final; size_t read(uint32_t address, char *buffer, const size_t buffer_length) final; diff --git a/drivers/CoreFlashMemory/include/CoreFlashMemoryDriverIS25LP016D.h b/drivers/CoreFlashMemory/include/CoreFlashMemoryDriverIS25LP016D.h index 63bddf008b..81a9d6561f 100644 --- a/drivers/CoreFlashMemory/include/CoreFlashMemoryDriverIS25LP016D.h +++ b/drivers/CoreFlashMemory/include/CoreFlashMemoryDriverIS25LP016D.h @@ -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; + size_t getSize() final; size_t read(uint32_t address, char *buffer, const size_t buffer_length); diff --git a/drivers/CoreFlashMemory/include/interface/FlashMemory.h b/drivers/CoreFlashMemory/include/interface/FlashMemory.h index 6eb3c7b25c..0d6c30f3a7 100644 --- a/drivers/CoreFlashMemory/include/interface/FlashMemory.h +++ b/drivers/CoreFlashMemory/include/interface/FlashMemory.h @@ -17,6 +17,7 @@ class FlashMemory virtual void initialize() = 0; virtual void setFrequency(int hz) = 0; + virtual size_t getSize() = 0; virtual size_t read(uint32_t address, char *buffer, const size_t buffer_length) = 0; }; diff --git a/drivers/CoreFlashMemory/source/CoreFlashMemory.cpp b/drivers/CoreFlashMemory/source/CoreFlashMemory.cpp index 3dbd132fae..6def528767 100644 --- a/drivers/CoreFlashMemory/source/CoreFlashMemory.cpp +++ b/drivers/CoreFlashMemory/source/CoreFlashMemory.cpp @@ -16,6 +16,11 @@ void CoreFlashMemory::setFrequency(int hz) _driver.setFrequency(hz); } +size_t CoreFlashMemory::getSize() +{ + return _driver.getSize(); +} + size_t CoreFlashMemory::read(uint32_t address, char *buffer, const size_t buffer_length) { return _driver.read(address, buffer, buffer_length); diff --git a/drivers/CoreFlashMemory/source/CoreFlashMemoryDriverIS25LP016D.cpp b/drivers/CoreFlashMemory/source/CoreFlashMemoryDriverIS25LP016D.cpp index eb9634bc25..3fb6a6400f 100644 --- a/drivers/CoreFlashMemory/source/CoreFlashMemoryDriverIS25LP016D.cpp +++ b/drivers/CoreFlashMemory/source/CoreFlashMemoryDriverIS25LP016D.cpp @@ -17,6 +17,11 @@ void CoreFlashMemoryIS25LP016D::setFrequency(int hz) _qspi.setFrequency(hz); } +size_t CoreFlashMemoryIS25LP016D::getSize() +{ + return flash_memory::is25lp016d::size; +} + void CoreFlashMemoryIS25LP016D::configureDataTransmissionFormat() { _qspi.configureDataTransmissionFormat(QSPI_CFG_BUS_SINGLE, QSPI_CFG_BUS_SINGLE, QSPI_CFG_ADDR_SIZE_24, @@ -25,7 +30,7 @@ void CoreFlashMemoryIS25LP016D::configureDataTransmissionFormat() size_t CoreFlashMemoryIS25LP016D::read(uint32_t address, char *buffer, const size_t bytes_to_read) { - if (address + bytes_to_read > flash_memory::is25lp016d::size) { + if (address + bytes_to_read > getSize()) { return 0; } diff --git a/drivers/CoreFlashMemory/tests/CoreFlashMemoryDriverIS25LP016D_test.cpp b/drivers/CoreFlashMemory/tests/CoreFlashMemoryDriverIS25LP016D_test.cpp index b2edc7b445..c04a7202dc 100644 --- a/drivers/CoreFlashMemory/tests/CoreFlashMemoryDriverIS25LP016D_test.cpp +++ b/drivers/CoreFlashMemory/tests/CoreFlashMemoryDriverIS25LP016D_test.cpp @@ -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; diff --git a/drivers/CoreFlashMemory/tests/CoreFlashMemory_test.cpp b/drivers/CoreFlashMemory/tests/CoreFlashMemory_test.cpp index a45960856f..5633879b18 100644 --- a/drivers/CoreFlashMemory/tests/CoreFlashMemory_test.cpp +++ b/drivers/CoreFlashMemory/tests/CoreFlashMemory_test.cpp @@ -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; diff --git a/spikes/lk_flash_memory/main.cpp b/spikes/lk_flash_memory/main.cpp index f1776c611c..1cb4bcc9af 100644 --- a/spikes/lk_flash_memory/main.cpp +++ b/spikes/lk_flash_memory/main.cpp @@ -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; } } diff --git a/tests/unit/mocks/mocks/leka/CoreFlashMemoryDriver.h b/tests/unit/mocks/mocks/leka/CoreFlashMemoryDriver.h index a0eec62f16..3a684e7f01 100644 --- a/tests/unit/mocks/mocks/leka/CoreFlashMemoryDriver.h +++ b/tests/unit/mocks/mocks/leka/CoreFlashMemoryDriver.h @@ -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)); };