resolve potential conflicts among macro definitions

This commit is contained in:
Gabriel Wang 2021-03-24 11:17:28 +00:00
parent f9a27d4ba0
commit f06324c00d
5 changed files with 122 additions and 24 deletions

View File

@ -157,34 +157,34 @@
<Bp>
<Number>0</Number>
<Type>0</Type>
<LineNumber>109</LineNumber>
<LineNumber>108</LineNumber>
<EnabledFlag>1</EnabledFlag>
<Address>1882</Address>
<Address>0</Address>
<ByteObject>0</ByteObject>
<HtxType>0</HtxType>
<ManyObjects>0</ManyObjects>
<SizeOfObject>0</SizeOfObject>
<BreakByAccess>0</BreakByAccess>
<BreakIfRCount>1</BreakIfRCount>
<BreakIfRCount>0</BreakIfRCount>
<Filename>.\main.c</Filename>
<ExecCommand></ExecCommand>
<Expression>\\example\main.c\109</Expression>
<Expression></Expression>
</Bp>
<Bp>
<Number>1</Number>
<Type>0</Type>
<LineNumber>314</LineNumber>
<LineNumber>109</LineNumber>
<EnabledFlag>1</EnabledFlag>
<Address>1516</Address>
<Address>0</Address>
<ByteObject>0</ByteObject>
<HtxType>0</HtxType>
<ManyObjects>0</ManyObjects>
<SizeOfObject>0</SizeOfObject>
<BreakByAccess>0</BreakByAccess>
<BreakIfRCount>1</BreakIfRCount>
<Filename>..\perf_counter.c</Filename>
<BreakIfRCount>0</BreakIfRCount>
<Filename>.\main.c</Filename>
<ExecCommand></ExecCommand>
<Expression>\\example\../perf_counter.c\314</Expression>
<Expression></Expression>
</Bp>
</Breakpoint>
<WatchWindow1>

View File

@ -97,7 +97,7 @@ int main (void)
//! demo of using clock() in timer.h
do {
clock_t tStart = clock();
safe_atom_code() {
__IRQ_SAFE {
printf("no interrupt \r\n");
}
printf("used clock cycle: %d", (int32_t)(clock() - tStart));

View File

@ -26,12 +26,38 @@
/*============================ MACROS ========================================*/
#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
#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
#endif
#ifndef __PLOOC_VA_NUM_ARGS
#define __PLOOC_VA_NUM_ARGS(...) \
__PLOOC_VA_NUM_ARGS_IMPL( 0,##__VA_ARGS__,16,15,14,13,12,11,10,9, \
8,7,6,5,4,3,2,1,0)
#endif
#undef __CONNECT2
#undef __CONNECT3
#undef __CONNECT4
#undef __CONNECT5
#undef __CONNECT6
#undef __CONNECT7
#undef __CONNECT8
#undef __CONNECT9
#undef CONNECT2
#undef CONNECT3
#undef CONNECT4
#undef CONNECT5
#undef CONNECT6
#undef CONNECT7
#undef CONNECT8
#undef CONNECT9
#undef CONNECT
#define __CONNECT2(__A, __B) __A##__B
#define __CONNECT3(__A, __B, __C) __A##__B##__C
#define __CONNECT4(__A, __B, __C, __D) __A##__B##__C##__D
@ -62,6 +88,13 @@
#undef __using1
#undef __using2
#undef __using3
#undef __using4
#undef using
#define __using1(__declare) \
for (__declare, *CONNECT3(__using_, __LINE__,_ptr) = NULL; \
CONNECT3(__using_, __LINE__,_ptr)++ == NULL; \
@ -90,6 +123,11 @@
#define using(...) \
CONNECT2(__using, __PLOOC_VA_NUM_ARGS(__VA_ARGS__))(__VA_ARGS__)
#undef __with2
#undef __with3
#undef with
#define __with2(__type, __addr) \
using(__type *_=(__addr))
#define __with3(__type, __addr, __item) \
@ -104,6 +142,11 @@
# define dimof(__array) (sizeof(__array)/sizeof(__array[0]))
#endif
#undef foreach2
#undef foreach3
#undef foreach
#define foreach2(__type, __array) \
using(__type *_ = __array) \
for ( uint_fast32_t CONNECT2(count,__LINE__) = dimof(__array); \
@ -126,7 +169,13 @@
using( uint32_t CONNECT2(temp,__LINE__) = __disable_irq(), \
__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__)))
#endif
/*============================ MACROFIED FUNCTIONS ===========================*/

View File

@ -179,8 +179,8 @@ static __attribute__((always_inline)) uint32_t SysTick_Config(uint32_t ticks)
return (1UL); /* Reload value impossible */
}
safe_atom_code(){
SysTick->CTRL = 0;
__IRQ_SAFE {
SysTick->CTRL = 0;
SysTick->LOAD = (uint32_t)(ticks - 1UL); /* set reload register */
//NVIC_SetPriority (SysTick_IRQn, (1UL << __NVIC_PRIO_BITS) - 1UL); /* set Priority for Systick Interrupt */
@ -188,7 +188,7 @@ static __attribute__((always_inline)) uint32_t SysTick_Config(uint32_t ticks)
SysTick->CTRL = SysTick_CTRL_CLKSOURCE_Msk |
SysTick_CTRL_TICKINT_Msk |
SysTick_CTRL_ENABLE_Msk; /* Enable SysTick IRQ and SysTick Timer */
SCB->ICSR = SCB_ICSR_PENDSTCLR_Msk;
SCB->ICSR = SCB_ICSR_PENDSTCLR_Msk;
}
return (0UL); /* Function successful */
}
@ -233,7 +233,7 @@ bool start_cycle_counter(void)
return false;
}
safe_atom_code(){
__IRQ_SAFE {
s_nCycleCounts = (int32_t)SysTick->VAL - (int32_t)SysTick->LOAD;
}
return true;
@ -286,7 +286,7 @@ int32_t stop_cycle_counter(void)
{
int32_t nTemp = 0;
safe_atom_code(){
__IRQ_SAFE {
nTemp = check_systick() + s_nCycleCounts;
}
@ -339,7 +339,7 @@ int64_t clock(void)
{
int64_t lTemp = 0;
safe_atom_code(){
__IRQ_SAFE {
lTemp = check_systick() + s_lSystemClockCounts;
}

View File

@ -26,12 +26,38 @@
/*============================ MACROS ========================================*/
#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
#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
#endif
#ifndef __PLOOC_VA_NUM_ARGS
#define __PLOOC_VA_NUM_ARGS(...) \
__PLOOC_VA_NUM_ARGS_IMPL( 0,##__VA_ARGS__,16,15,14,13,12,11,10,9, \
8,7,6,5,4,3,2,1,0)
#endif
#undef __CONNECT2
#undef __CONNECT3
#undef __CONNECT4
#undef __CONNECT5
#undef __CONNECT6
#undef __CONNECT7
#undef __CONNECT8
#undef __CONNECT9
#undef CONNECT2
#undef CONNECT3
#undef CONNECT4
#undef CONNECT5
#undef CONNECT6
#undef CONNECT7
#undef CONNECT8
#undef CONNECT9
#undef CONNECT
#define __CONNECT2(__A, __B) __A##__B
#define __CONNECT3(__A, __B, __C) __A##__B##__C
#define __CONNECT4(__A, __B, __C, __D) __A##__B##__C##__D
@ -62,6 +88,13 @@
#undef __using1
#undef __using2
#undef __using3
#undef __using4
#undef using
#define __using1(__declare) \
for (__declare, *CONNECT3(__using_, __LINE__,_ptr) = NULL; \
CONNECT3(__using_, __LINE__,_ptr)++ == NULL; \
@ -90,6 +123,11 @@
#define using(...) \
CONNECT2(__using, __PLOOC_VA_NUM_ARGS(__VA_ARGS__))(__VA_ARGS__)
#undef __with2
#undef __with3
#undef with
#define __with2(__type, __addr) \
using(__type *_=(__addr))
#define __with3(__type, __addr, __item) \
@ -104,6 +142,11 @@
# define dimof(__array) (sizeof(__array)/sizeof(__array[0]))
#endif
#undef foreach2
#undef foreach3
#undef foreach
#define foreach2(__type, __array) \
using(__type *_ = __array) \
for ( uint_fast32_t CONNECT2(count,__LINE__) = dimof(__array); \
@ -126,7 +169,13 @@
using( uint32_t CONNECT2(temp,__LINE__) = __disable_irq(), \
__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__)))
#endif
/*============================ MACROFIED FUNCTIONS ===========================*/