diff --git a/lib/perf_counter.h b/lib/perf_counter.h index d99cc94..e6b4400 100644 --- a/lib/perf_counter.h +++ b/lib/perf_counter.h @@ -211,7 +211,7 @@ ) #define foreach3(__type, __array, __item) \ - using(__type *_ = __array, *__item = _, _ = _, ) \ + using(__type *_ = __array, *__item = _, _ = _, _ = _ ) \ for ( uint_fast32_t CONNECT2(count,__LINE__) = dimof(__array); \ CONNECT2(count,__LINE__) > 0; \ _++, __item = _, CONNECT2(count,__LINE__)-- \ @@ -238,7 +238,8 @@ #define __cycleof__(__STR, ...) \ - using(int64_t _ = get_system_ticks(), { \ + using(int64_t _ = get_system_ticks(), __cycle_count__ = _, \ + _=_, { \ _ = get_system_ticks() - _; \ if (__PLOOC_VA_NUM_ARGS(__VA_ARGS__) == 0) { \ printf("\r\n"); \ diff --git a/perf_counter.c b/perf_counter.c index 2ecc3fa..bc4529d 100644 --- a/perf_counter.c +++ b/perf_counter.c @@ -178,7 +178,7 @@ volatile static int64_t s_lSystemClockCounts = 0; function SysTick_Config is not included. In this case, the file device.h must contain a vendor-specific implementation of this function. */ -static __attribute__((always_inline)) uint32_t SysTick_Config(uint32_t ticks) +__STATIC_INLINE uint32_t SysTick_Config(uint32_t ticks) { if ((ticks - 1UL) > SysTick_LOAD_RELOAD_Msk) { @@ -256,7 +256,7 @@ bool start_cycle_counter(void) *! hence SysTick-LOAD and (SCB->ICSR & SCB_ICSR_PENDSTSET_Msk) *! won't change. */ -static __attribute__((always_inline)) int32_t check_systick(void) +__STATIC_INLINE int32_t check_systick(void) { int32_t nTemp = (int32_t)SysTick->LOAD - (int32_t)SysTick->VAL; @@ -306,7 +306,11 @@ int32_t stop_cycle_counter(void) return nTemp - s_nOffset; } +#if defined(__IS_COMPILER_IAR__) +__attribute__((constructor)) +#else __attribute__((constructor(255))) +#endif void __perf_counter_init(void) { init_cycle_counter(true); @@ -347,7 +351,9 @@ void delay_us(int32_t nUs) *! and 2) do not include system header file *! */ +#if !defined(__IS_COMPILER_IAR__) __attribute__((nothrow)) +#endif int64_t clock(void) { int64_t lTemp = 0; @@ -360,7 +366,9 @@ int64_t clock(void) } +#if !defined(__IS_COMPILER_IAR__) __attribute__((nothrow)) +#endif int64_t get_system_ticks(void) { int64_t lTemp = 0; diff --git a/perf_counter.h b/perf_counter.h index d99cc94..e6b4400 100644 --- a/perf_counter.h +++ b/perf_counter.h @@ -211,7 +211,7 @@ ) #define foreach3(__type, __array, __item) \ - using(__type *_ = __array, *__item = _, _ = _, ) \ + using(__type *_ = __array, *__item = _, _ = _, _ = _ ) \ for ( uint_fast32_t CONNECT2(count,__LINE__) = dimof(__array); \ CONNECT2(count,__LINE__) > 0; \ _++, __item = _, CONNECT2(count,__LINE__)-- \ @@ -238,7 +238,8 @@ #define __cycleof__(__STR, ...) \ - using(int64_t _ = get_system_ticks(), { \ + using(int64_t _ = get_system_ticks(), __cycle_count__ = _, \ + _=_, { \ _ = get_system_ticks() - _; \ if (__PLOOC_VA_NUM_ARGS(__VA_ARGS__) == 0) { \ printf("\r\n"); \