Skip to content

Commit cd6791f

Browse files
committed
introduce __PERFC_SAFE for internal use only
1 parent d7d330d commit cd6791f

File tree

6 files changed

+90
-17
lines changed

6 files changed

+90
-17
lines changed

perf_counter.c

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -117,12 +117,12 @@ void perfc_port_insert_to_system_timer_insert_ovf_handler(void)
117117
/* prevent high priority exceptions from preempting the system timer OVF
118118
* exception handling
119119
*/
120-
__IRQ_SAFE {
120+
__PERFC_SAFE {
121121
s_lSystemClockCounts += lLoad;
122122
}
123123

124124
// update system ms counter
125-
__IRQ_SAFE {
125+
__PERFC_SAFE {
126126
int64_t lTemp = s_wMSResidule + lLoad;
127127

128128
int64_t lMS = lTemp / s_wMSUnit;
@@ -132,7 +132,7 @@ void perfc_port_insert_to_system_timer_insert_ovf_handler(void)
132132
}
133133

134134
// update system us counter
135-
__IRQ_SAFE {
135+
__PERFC_SAFE {
136136
int64_t lTemp = s_wUSResidule + lLoad;
137137

138138
int64_t lUS = lTemp / s_wUSUnit;
@@ -160,7 +160,7 @@ void update_perf_counter(void)
160160
s_wUSUnit = wSystemFrequency / 1000000ul;
161161
s_wMSUnit = wSystemFrequency / 1000ul;
162162

163-
__IRQ_SAFE {
163+
__PERFC_SAFE {
164164
g_lLastTimeStamp = get_system_ticks();
165165
__perfc_sync_barrier__();
166166
g_nOffset = get_system_ticks() - g_lLastTimeStamp;
@@ -170,7 +170,7 @@ void update_perf_counter(void)
170170
bool perfc_init(bool bIsSysTimerOccupied)
171171
{
172172
bool bResult = false;
173-
__IRQ_SAFE {
173+
__PERFC_SAFE {
174174
s_bIsSysTimerOccupied = bIsSysTimerOccupied;
175175
bResult = perfc_port_init_system_timer(bIsSysTimerOccupied); // use the longest period
176176
perfc_port_clear_system_timer_ovf_pending();
@@ -238,7 +238,7 @@ __STATIC_INLINE int64_t check_systick(void)
238238

239239
void before_cycle_counter_reconfiguration(void)
240240
{
241-
__IRQ_SAFE {
241+
__PERFC_SAFE {
242242
perfc_port_stop_system_timer_counting();
243243

244244
if (perfc_port_is_system_timer_ovf_pending()) {
@@ -339,7 +339,7 @@ int64_t get_system_ticks(void)
339339
{
340340
int64_t lTemp = 0;
341341

342-
__IRQ_SAFE {
342+
__PERFC_SAFE {
343343
lTemp = check_systick() + s_lSystemClockCounts;
344344

345345
/* When calling get_system_ticks() in an exception handler that has a
@@ -395,7 +395,7 @@ int64_t get_system_ms(void)
395395
{
396396
int64_t lTemp = 0;
397397

398-
__IRQ_SAFE {
398+
__PERFC_SAFE {
399399
lTemp = s_lSystemMS
400400
+ ( (check_systick()
401401
+ (int64_t)s_wMSResidule) / s_wMSUnit);
@@ -414,7 +414,7 @@ int64_t get_system_us(void)
414414
{
415415
int64_t lTemp = 0;
416416

417-
__IRQ_SAFE {
417+
__PERFC_SAFE {
418418
lTemp = s_lSystemUS
419419
+ ( (check_systick()
420420
+ (int64_t)s_wUSResidule) / s_wUSUnit);
@@ -656,7 +656,7 @@ bool enable_task_cycle_info(task_cycle_info_t *ptInfo)
656656
return false;
657657
}
658658
bool bOrig;
659-
__IRQ_SAFE {
659+
__PERFC_SAFE {
660660
bOrig = ptInfo->bEnabled;
661661
ptInfo->bEnabled = true;
662662
}
@@ -669,7 +669,7 @@ bool disable_task_cycle_info(task_cycle_info_t *ptInfo)
669669
return false;
670670
}
671671
bool bOrig;
672-
__IRQ_SAFE {
672+
__PERFC_SAFE {
673673
bOrig = ptInfo->bEnabled;
674674
ptInfo->bEnabled = false;
675675
}
@@ -689,7 +689,7 @@ void resume_task_cycle_info(task_cycle_info_t *ptInfo, bool bEnabledStatus)
689689
task_cycle_info_agent_t *register_task_cycle_agent(task_cycle_info_t *ptInfo,
690690
task_cycle_info_agent_t *ptAgent)
691691
{
692-
__IRQ_SAFE {
692+
__PERFC_SAFE {
693693
do {
694694
if (NULL == ptAgent || NULL == ptInfo) {
695695
break;
@@ -727,7 +727,7 @@ task_cycle_info_agent_t *register_task_cycle_agent(task_cycle_info_t *ptInfo,
727727
task_cycle_info_agent_t *
728728
unregister_task_cycle_agent(task_cycle_info_agent_t *ptAgent)
729729
{
730-
__IRQ_SAFE {
730+
__PERFC_SAFE {
731731
do {
732732
if (NULL == ptAgent) {
733733
break;
@@ -814,7 +814,7 @@ void __start_task_cycle_counter(task_cycle_info_t *ptInfo)
814814
return ;
815815
}
816816

817-
__IRQ_SAFE {
817+
__PERFC_SAFE {
818818
ptRootAgent->lLastTimeStamp = get_system_ticks();
819819
ptRootAgent->tInfo.lUsedTotal = 0;
820820

@@ -836,7 +836,7 @@ int64_t __stop_task_cycle_counter(task_cycle_info_t *ptInfo)
836836

837837
int64_t lCycles = 0;
838838

839-
__IRQ_SAFE {
839+
__PERFC_SAFE {
840840
int64_t lCycleUsed = get_system_ticks() - ptRootAgent->lLastTimeStamp - g_nOffset;
841841
ptRootAgent->tInfo.lUsedTotal += lCycleUsed;
842842

perf_counter.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,14 @@ extern "C" {
140140
perfc_port_resume_global_interrupt(SAFE_NAME(temp)))
141141
#endif
142142

143+
144+
#ifndef __PERFC_SAFE
145+
# define __PERFC_SAFE \
146+
perfc_using( perfc_global_interrupt_status_t SAFE_NAME(temp) = \
147+
perfc_port_mask_systimer_interrupt(), \
148+
perfc_port_resume_systimer_interrupt(SAFE_NAME(temp)))
149+
#endif
150+
143151
/* deprecated macro for backward compatibility */
144152
#define user_code_insert_to_systick_handler \
145153
perfc_port_insert_to_system_timer_insert_ovf_handler

perfc_port_default.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ bool perfc_port_init_system_timer(bool bTimerOccupied)
167167
break;
168168
}
169169

170-
__IRQ_SAFE {
170+
__PERFC_SAFE {
171171
SysTick->CTRL = 0;
172172

173173
SysTick->LOAD = SysTick_LOAD_RELOAD_Msk; /* set reload register */

perfc_port_default.h

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,10 @@ typedef uint32_t perfc_global_interrupt_status_t;
106106
/*============================ PROTOTYPES ====================================*/
107107
/*============================ IMPLEMENTATION ================================*/
108108

109+
#ifndef __PERFC_SYSTIMER_PRIORITY__
110+
# define __PERFC_SYSTIMER_PRIORITY__ 0
111+
#endif
112+
109113
__STATIC_INLINE
110114
perfc_global_interrupt_status_t perfc_port_disable_global_interrupt(void)
111115
{
@@ -121,5 +125,39 @@ void perfc_port_resume_global_interrupt(perfc_global_interrupt_status_t tStatus)
121125
__set_PRIMASK(tStatus);
122126
}
123127

128+
__STATIC_INLINE
129+
perfc_global_interrupt_status_t perfc_port_mask_systimer_interrupt(void)
130+
{
131+
#if (defined(__ARM_ARCH) && __ARM_ARCH == 6 && __ARM_ARCH_PROFILE == 'M') || __PERFC_SYSTIMER_PRIORITY__ == 0
132+
perfc_global_interrupt_status_t tStatus = __get_PRIMASK();
133+
__disable_irq();
134+
135+
return tStatus;
136+
#elif __ARM_ARCH_PROFILE == 'M'
137+
perfc_global_interrupt_status_t tStatus = __get_BASEPRI();
138+
__set_BASEPRI_MAX(__PERFC_SYSTIMER_PRIORITY__);
139+
140+
return tStatus;
141+
142+
#else
143+
/* this should not happen */
144+
return 0;
145+
#endif
146+
}
147+
148+
__STATIC_INLINE
149+
void perfc_port_resume_systimer_interrupt(perfc_global_interrupt_status_t tStatus)
150+
{
151+
#if (defined(__ARM_ARCH) && __ARM_ARCH == 6 && __ARM_ARCH_PROFILE == 'M') || __PERFC_SYSTIMER_PRIORITY__ == 0
152+
__set_PRIMASK(tStatus);
153+
#elif __ARM_ARCH_PROFILE == 'M'
154+
__set_BASEPRI(tStatus);
155+
#else
156+
/* this should not happen */
157+
return 0;
158+
#endif
159+
160+
}
161+
124162

125163
#endif

template/perfc_port_user.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ bool perfc_port_init_system_timer(bool bIsTimeOccupied)
7575
break;
7676
}
7777

78-
__IRQ_SAFE {
78+
__PERFC_SAFE {
7979
/* Configure the system timer count with the longest possible period
8080
* clear counter
8181
* Clear overflow pending flag

template/perfc_port_user.h

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,11 @@
2020
#if __PERFC_USE_USER_CUSTOM_PORTING__
2121

2222
/*============================ MACROS ========================================*/
23+
24+
#ifndef __PERFC_SYSTIMER_PRIORITY__
25+
# define __PERFC_SYSTIMER_PRIORITY__ 0
26+
#endif
27+
2328
/*============================ MACROFIED FUNCTIONS ===========================*/
2429
/*============================ TYPES =========================================*/
2530
typedef uint32_t perfc_global_interrupt_status_t;
@@ -50,4 +55,26 @@ void perfc_port_resume_global_interrupt(perfc_global_interrupt_status_t tStatus)
5055
/* resume the stored global interrupt status */
5156
}
5257

58+
59+
static
60+
inline
61+
perfc_global_interrupt_status_t perfc_port_mask_systimer_interrupt(void)
62+
{
63+
perfc_global_interrupt_status_t tStatus;
64+
65+
/* get global interrupt priority */
66+
/* only mask the priority of the systimer */
67+
/* return the status */
68+
69+
return tStatus;
70+
}
71+
72+
static
73+
inline
74+
void perfc_port_resume_systimer_interrupt(perfc_global_interrupt_status_t tStatus)
75+
{
76+
/* resume the stored global interrupt priority */
77+
78+
}
79+
5380
#endif

0 commit comments

Comments
 (0)