diff --git a/perf_counter.c b/perf_counter.c index f50180c..d038cfa 100644 --- a/perf_counter.c +++ b/perf_counter.c @@ -218,9 +218,10 @@ void init_cycle_counter(bool bSysTickIsOccupied) s_nOffset = stop_cycle_counter(); s_nUnit = SystemCoreClock / 1000000ul; - +#if !(defined(__IS_COMPILER_GCC__) && __IS_COMPILER_GCC__) extern void __ensure_systick_wrapper(void); __ensure_systick_wrapper(); +#endif } /*! \brief try to start the performance counter diff --git a/perf_counter.h b/perf_counter.h index 3926097..401867c 100644 --- a/perf_counter.h +++ b/perf_counter.h @@ -30,6 +30,54 @@ /*============================ MACROS ========================================*/ +//! \name The macros to identify the compiler +//! @{ + +//! \note for IAR +#ifdef __IS_COMPILER_IAR__ +# undef __IS_COMPILER_IAR__ +#endif +#if defined(__IAR_SYSTEMS_ICC__) +# define __IS_COMPILER_IAR__ 1 +#endif + +//! \note for arm compiler 5 +#ifdef __IS_COMPILER_ARM_COMPILER_5__ +# undef __IS_COMPILER_ARM_COMPILER_5__ +#endif +#if ((__ARMCC_VERSION >= 5000000) && (__ARMCC_VERSION < 6000000)) +# define __IS_COMPILER_ARM_COMPILER_5__ 1 +#endif +//! @} + +//! \note for arm compiler 6 +#ifdef __IS_COMPILER_ARM_COMPILER_6__ +# undef __IS_COMPILER_ARM_COMPILER_6__ +#endif +#if defined(__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050) +# define __IS_COMPILER_ARM_COMPILER_6__ 1 +#endif + +#ifdef __IS_COMPILER_LLVM__ +# undef __IS_COMPILER_LLVM__ +#endif +#if defined(__clang__) && !__IS_COMPILER_ARM_COMPILER_6__ +# define __IS_COMPILER_LLVM__ 1 +#else +//! \note for gcc +# ifdef __IS_COMPILER_GCC__ +# undef __IS_COMPILER_GCC__ +# endif +# if defined(__GNUC__) && !( defined(__IS_COMPILER_ARM_COMPILER_5__) \ + || defined(__IS_COMPILER_ARM_COMPILER_6__) \ + || defined(__IS_COMPILER_LLVM__)) +# define __IS_COMPILER_GCC__ 1 +# endif +//! @} +#endif +//! @} + + #ifndef __PLOOC_VA_NUM_ARGS_IMPL # define __PLOOC_VA_NUM_ARGS_IMPL( _0,_1,_2,_3,_4,_5,_6,_7,_8,_9,_10,_11, \ _12,_13,_14,_15,_16,__N,...) __N @@ -170,14 +218,16 @@ #ifndef safe_atom_code # define safe_atom_code() \ - using( uint32_t CONNECT2(temp,__LINE__) = __disable_irq(), \ - __set_PRIMASK(CONNECT2(temp,__LINE__))) + using( uint32_t CONNECT2(temp,__LINE__) = \ + ({uint32_t temp=__get_PRIMASK();__disable_irq();temp;}),\ + __set_PRIMASK(CONNECT2(temp,__LINE__))) #endif #ifndef __IRQ_SAFE # define __IRQ_SAFE \ - using( uint32_t CONNECT2(temp,__LINE__) = __disable_irq(), \ - __set_PRIMASK(CONNECT2(temp,__LINE__))) + using( uint32_t CONNECT2(temp,__LINE__) = \ + ({uint32_t temp=__get_PRIMASK();__disable_irq();temp;}),\ + __set_PRIMASK(CONNECT2(temp,__LINE__))) #endif /*============================ MACROFIED FUNCTIONS ===========================*/