Merge pull request #4666 from chrissnow/tests-mbed_hal-flash-Timing_fix

Fix timing issues found in "Flash - clock and cache test"
pull/4754/head
Martin Kojtal 2017-07-13 16:48:32 +02:00 committed by GitHub
commit 5a5d159a3c
2 changed files with 64 additions and 3 deletions

View File

@ -52,7 +52,48 @@ static void erase_range(flash_t *flash, uint32_t addr, uint32_t size)
size = size > sector_size ? size - sector_size : 0;
}
}
#ifdef __CC_ARM
MBED_NOINLINE
__asm static void delay_loop(uint32_t count)
{
1
SUBS a1, a1, #1
BCS %BT1
BX lr
}
#elif defined (__ICCARM__)
MBED_NOINLINE
static void delay_loop(uint32_t count)
{
__asm volatile(
"loop: \n"
" SUBS %0, %0, #1 \n"
" BCS.n loop\n"
: "+r" (count)
:
: "cc"
);
}
#else // GCC
MBED_NOINLINE
static void delay_loop(uint32_t count)
{
__asm__ volatile (
"%=:\n\t"
#if defined(__thumb__) && !defined(__thumb2__)
"SUB %0, #1\n\t"
#else
"SUBS %0, %0, #1\n\t"
#endif
"BCS %=b\n\t"
: "+l" (count)
:
: "cc"
);
}
#endif
MBED_NOINLINE
static int time_cpu_cycles(uint32_t cycles)
{
Timer timer;
@ -60,9 +101,8 @@ static int time_cpu_cycles(uint32_t cycles)
int timer_start = timer.read_us();
volatile uint32_t delay = (volatile uint32_t)cycles;
while (delay--);
uint32_t delay = cycles;
delay_loop(delay);
int timer_end = timer.read_us();
timer.stop();

View File

@ -137,6 +137,27 @@
#endif
#endif
/** MBED_NOINLINE
* Declare a function that must not be inlined.
*
* @code
* #include "mbed_toolchain.h"
*
* MBED_NOINLINE void foo() {
*
* }
* @endcode
*/
#ifndef MBED_NOINLINE
#if defined(__GNUC__) || defined(__clang__) || defined(__CC_ARM)
#define MBED_NOINLINE __attribute__((noinline))
#elif defined(__ICCARM__)
#define MBED_NOINLINE _Pragma("inline=never")
#else
#define MBED_NOINLINE
#endif
#endif
/** MBED_FORCEINLINE
* Declare a function that must always be inlined. Failure to inline
* such a function will result in an error.