From e7fa5fc599a441389b3f583ed81d4f6ab2ad343b Mon Sep 17 00:00:00 2001 From: Przemyslaw Stekiel Date: Mon, 21 May 2018 10:08:40 +0200 Subject: [PATCH] tests-mbed_hal-flash: optimieze time_cpu_cycles() function This function should perform instruction cycles count in critical section. Additionally remove redundant code. --- TESTS/mbed_hal/flash/functional_tests/main.cpp | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/TESTS/mbed_hal/flash/functional_tests/main.cpp b/TESTS/mbed_hal/flash/functional_tests/main.cpp index bbcf85c779..b5bdc51aff 100644 --- a/TESTS/mbed_hal/flash/functional_tests/main.cpp +++ b/TESTS/mbed_hal/flash/functional_tests/main.cpp @@ -98,16 +98,18 @@ MBED_NOINLINE static int time_cpu_cycles(uint32_t cycles) { Timer timer; + + core_util_critical_section_enter(); + timer.start(); - int timer_start = timer.read_us(); - - uint32_t delay = cycles; - delay_loop(delay); - int timer_end = timer.read_us(); + delay_loop(cycles); timer.stop(); - return timer_end - timer_start; + + core_util_critical_section_exit(); + + return timer.read_us(); } void flash_init_test()