From 6b3d2cc8df81afd9a11df6209e6ec2a98d4a71b8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89milie=20Feral?= Date: Thu, 11 Jul 2019 11:13:29 +0200 Subject: [PATCH] [ion] test.external_flash: split this test target into two targets - test.external_flash.write and test.external_flash.read --- ion/test/device/n0110/Makefile | 14 +++- .../device/n0110/external_flash_helper.cpp | 26 ++++++++ ion/test/device/n0110/external_flash_helper.h | 22 +++++++ ...rnal_flash.cpp => external_flash_read.cpp} | 66 +------------------ .../device/n0110/external_flash_write.cpp | 26 ++++++++ quiz/Makefile | 3 +- scripts/targets.device.n0110.mak | 8 ++- 7 files changed, 93 insertions(+), 72 deletions(-) create mode 100644 ion/test/device/n0110/external_flash_helper.cpp create mode 100644 ion/test/device/n0110/external_flash_helper.h rename ion/test/device/n0110/{external_flash.cpp => external_flash_read.cpp} (57%) create mode 100644 ion/test/device/n0110/external_flash_write.cpp diff --git a/ion/test/device/n0110/Makefile b/ion/test/device/n0110/Makefile index c30ebdfc5..3acf290d9 100644 --- a/ion/test/device/n0110/Makefile +++ b/ion/test/device/n0110/Makefile @@ -1,4 +1,12 @@ -TEST_EXT_FLASH_REPROGRAM ?= 0 -SFLAGS += -DTEST_EXT_FLASH_REPROGRAM=$(TEST_EXT_FLASH_REPROGRAM) -test_ion_external_flash_src += ion/test/$(PLATFORM)/$(MODEL)/external_flash.cpp +test_ion_external_flash_read_src += $(addprefix ion/test/$(PLATFORM)/$(MODEL)/, \ + external_flash_helper.cpp \ + external_flash_read.cpp \ +) + +test_ion_external_flash_write_src += $(addprefix ion/test/$(PLATFORM)/$(MODEL)/, \ + external_flash_helper.cpp \ + external_flash_write.cpp \ +) + +test_ion_external_flash_src += $(test_ion_external_flash_read_src) $(test_ion_external_flash_write_src) $(call object_for,$(test_ion_external_flash_src)): SFLAGS += $(ION_DEVICE_SFLAGS) diff --git a/ion/test/device/n0110/external_flash_helper.cpp b/ion/test/device/n0110/external_flash_helper.cpp new file mode 100644 index 000000000..11d776784 --- /dev/null +++ b/ion/test/device/n0110/external_flash_helper.cpp @@ -0,0 +1,26 @@ +#include "ion/include/ion/timing.h" +#include +#include + +size_t uint64ToString(uint64_t n, char buffer[]) { + size_t len = 0; + do { + buffer[len++] = (n % 10) + '0'; + } while ((n /= 10) > 0); + int i = 0; + int j = len - 1; + while (i < j) { + char c = buffer[i]; + buffer[i++] = buffer[j]; + buffer[j--] = c; + } + return len; +} + +void printElapsedTime(uint64_t startTime) { + char buffer[7+26+2] = " time: "; + size_t len = uint64ToString((Ion::Timing::millis() - startTime)/1000, buffer+7); + buffer[7+len] = 's'; + buffer[7+len+1] = 0; + quiz_print(buffer); +} diff --git a/ion/test/device/n0110/external_flash_helper.h b/ion/test/device/n0110/external_flash_helper.h new file mode 100644 index 000000000..de84d3d0d --- /dev/null +++ b/ion/test/device/n0110/external_flash_helper.h @@ -0,0 +1,22 @@ +#include + +// Choose some not too uniform data to program and test the external flash memory with. + +inline uint8_t expected_value_at(uint8_t * ptr) { + uint32_t address = reinterpret_cast(ptr) - Ion::Device::ExternalFlash::Config::StartAddress; + return (address / 0x10000) + (address / 0x100) + address; + // Example: the value expected at the address 0x123456 is 0x12 + 0x34 + 0x56. +} + +inline uint16_t expected_value_at(uint16_t * ptr) { + uint8_t * ptr8 = reinterpret_cast(ptr); + return (static_cast(expected_value_at(ptr8+1)) << 8) | static_cast(expected_value_at(ptr8)); +} + +inline uint32_t expected_value_at(uint32_t * ptr) { + uint16_t * ptr16 = reinterpret_cast(ptr); + return (static_cast(expected_value_at(ptr16+1)) << 16) + static_cast(expected_value_at(ptr16)); +} + +size_t uint64ToString(uint64_t n, char buffer[]); +void printElapsedTime(uint64_t startTime); diff --git a/ion/test/device/n0110/external_flash.cpp b/ion/test/device/n0110/external_flash_read.cpp similarity index 57% rename from ion/test/device/n0110/external_flash.cpp rename to ion/test/device/n0110/external_flash_read.cpp index da74aff24..3b234f14c 100644 --- a/ion/test/device/n0110/external_flash.cpp +++ b/ion/test/device/n0110/external_flash_read.cpp @@ -3,25 +3,7 @@ #include #include #include -#include "ion/include/ion/timing.h" - -// Choose some not too uniform data to program and test the external flash memory with. - -static inline uint8_t expected_value_at(uint8_t * ptr) { - uint32_t address = reinterpret_cast(ptr) - Ion::Device::ExternalFlash::Config::StartAddress; - return (address / 0x10000) + (address / 0x100) + address; - // Example: the value expected at the address 0x123456 is 0x12 + 0x34 + 0x56. -} - -static inline uint16_t expected_value_at(uint16_t * ptr) { - uint8_t * ptr8 = reinterpret_cast(ptr); - return (static_cast(expected_value_at(ptr8+1)) << 8) | static_cast(expected_value_at(ptr8)); -} - -static inline uint32_t expected_value_at(uint32_t * ptr) { - uint16_t * ptr16 = reinterpret_cast(ptr); - return (static_cast(expected_value_at(ptr16+1)) << 16) + static_cast(expected_value_at(ptr16)); -} +#include "external_flash_helper.h" template static inline void check(volatile T * p, int repeat) { @@ -64,52 +46,6 @@ void test(int accessType, int repeat) { } } -static size_t uint64ToString(uint64_t n, char buffer[]) { - size_t len = 0; - do { - buffer[len++] = (n % 10) + '0'; - } while ((n /= 10) > 0); - int i = 0; - int j = len - 1; - while (i < j) { - char c = buffer[i]; - buffer[i++] = buffer[j]; - buffer[j--] = c; - } - return len; -} - -static void printElapsedTime(uint64_t startTime) { - char buffer[7+26+2] = " time: "; - size_t len = uint64ToString((Ion::Timing::millis() - startTime)/1000, buffer+7); - buffer[7+len] = 's'; - buffer[7+len+1] = 0; - quiz_print(buffer); -} - -QUIZ_CASE(ion_ext_flash_erase) { -#if TEST_EXT_FLASH_REPROGRAM - uint64_t startTime = Ion::Timing::millis(); - Ion::Device::ExternalFlash::MassErase(); - printElapsedTime(startTime); -#endif -} - -QUIZ_CASE(ion_ext_flash_program) { -#if TEST_EXT_FLASH_REPROGRAM - // Program separately each page of the flash memory - uint64_t startTime = Ion::Timing::millis(); - for (int page = 0; page < (1<<15); page++) { - uint8_t buffer[256]; - for (int byte = 0; byte < 256; byte++) { - buffer[byte] = expected_value_at(reinterpret_cast(Ion::Device::ExternalFlash::Config::StartAddress + page * 256 + byte)); - } - Ion::Device::ExternalFlash::WriteMemory(reinterpret_cast(page * 256), buffer, 256); - } - printElapsedTime(startTime); -#endif -} - QUIZ_CASE(ion_extflash_read_byte_fwd) { uint64_t startTime = Ion::Timing::millis(); test(0, 1); diff --git a/ion/test/device/n0110/external_flash_write.cpp b/ion/test/device/n0110/external_flash_write.cpp new file mode 100644 index 000000000..0585abd96 --- /dev/null +++ b/ion/test/device/n0110/external_flash_write.cpp @@ -0,0 +1,26 @@ +#include +#include +#include +#include "ion/include/ion/timing.h" +#include "external_flash_helper.h" + +// Choose some not too uniform data to program the external flash memory with. + +QUIZ_CASE(ion_ext_flash_erase) { + uint64_t startTime = Ion::Timing::millis(); + Ion::Device::ExternalFlash::MassErase(); + printElapsedTime(startTime); +} + +QUIZ_CASE(ion_ext_flash_program) { + // Program separately each page of the flash memory + uint64_t startTime = Ion::Timing::millis(); + for (int page = 0; page < (1<<15); page++) { + uint8_t buffer[256]; + for (int byte = 0; byte < 256; byte++) { + buffer[byte] = expected_value_at(reinterpret_cast(Ion::Device::ExternalFlash::Config::StartAddress + page * 256 + byte)); + } + Ion::Device::ExternalFlash::WriteMemory(reinterpret_cast(page * 256), buffer, 256); + } + printElapsedTime(startTime); +} diff --git a/quiz/Makefile b/quiz/Makefile index a04b4acfc..0ba932d45 100644 --- a/quiz/Makefile +++ b/quiz/Makefile @@ -10,7 +10,8 @@ $$(BUILD_DIR)/quiz/src/$(subst _src,,$(1))_symbols.c: $$($(1)) | $$$$(@D)/. endef $(eval $(call rule_for_quiz_symbols,tests)) -$(eval $(call rule_for_quiz_symbols,test_ion_external_flash_src)) +$(eval $(call rule_for_quiz_symbols,test_ion_external_flash_write_src)) +$(eval $(call rule_for_quiz_symbols,test_ion_external_flash_read_src)) runner_src += $(addprefix quiz/src/, \ assertions.cpp \ diff --git a/scripts/targets.device.n0110.mak b/scripts/targets.device.n0110.mak index c04045feb..d0ec23b97 100644 --- a/scripts/targets.device.n0110.mak +++ b/scripts/targets.device.n0110.mak @@ -1,4 +1,6 @@ -executables += test.external_flash +executables += test.external_flash.write test.external_flash.read -$(BUILD_DIR)/test.external_flash.$(EXE): LDSCRIPT = ion/test/device/n0110/external_flash_tests.ld -$(BUILD_DIR)/test.external_flash.$(EXE): $(BUILD_DIR)/quiz/src/test_ion_external_flash_symbols.o $(call object_for,$(src) $(ion_device_dfu_relocated_src) $(test_ion_external_flash_src) $(runner_src)) +$(BUILD_DIR)/test.external_flash.%.$(EXE): LDSCRIPT = ion/test/device/n0110/external_flash_tests.ld +test_external_flash_src = $(src) $(ion_device_dfu_relogated_src) $(runner_src) +$(BUILD_DIR)/test.external_flash.read.$(EXE): $(BUILD_DIR)/quiz/src/test_ion_external_flash_read_symbols.o $(call object_for,$(test_external_flash_src) $(test_ion_external_flash_read_src)) +$(BUILD_DIR)/test.external_flash.write.$(EXE): $(BUILD_DIR)/quiz/src/test_ion_external_flash_write_symbols.o $(call object_for,$(test_external_flash_src) $(test_ion_external_flash_write_src))