Skip to content

Commit

Permalink
update porting prototype
Browse files Browse the repository at this point in the history
  • Loading branch information
GorgonMeducer committed Jan 27, 2024
1 parent 72e5eb9 commit 142a241
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 36 deletions.
9 changes: 6 additions & 3 deletions perf_counter.c
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ int64_t perfc_port_get_system_timer_top(void);
extern
bool perfc_port_is_system_timer_ovf_pending(void);
extern
void perfc_port_init_system_timer(bool bTimerOccupied);
bool perfc_port_init_system_timer(bool bTimerOccupied);
extern
int64_t perfc_port_get_system_timer_elapsed(void);
extern
Expand Down Expand Up @@ -145,10 +145,11 @@ void update_perf_counter(void)
}
}

void init_cycle_counter(bool bIsSysTickOccupied)
bool init_cycle_counter(bool bIsSysTickOccupied)
{
bool bResult = false;
__IRQ_SAFE {
perfc_port_init_system_timer(bIsSysTickOccupied); // use the longest period
bResult = perfc_port_init_system_timer(bIsSysTickOccupied); // use the longest period
perfc_port_clear_system_timer_ovf_pending();
}

Expand All @@ -158,6 +159,8 @@ void init_cycle_counter(bool bIsSysTickOccupied)
s_lSystemUS = 0; // reset system microsecond counter

__perf_os_patch_init();

return bResult;
}

/*! \note this function should only be called when irq is disabled
Expand Down
6 changes: 5 additions & 1 deletion perf_counter.h
Original file line number Diff line number Diff line change
Expand Up @@ -900,8 +900,12 @@ extern int64_t __stop_task_cycle_counter(task_cycle_info_t *ptInfo);
*
* \param[in] bIsSysTickOccupied A boolean value which indicates whether SysTick
* is already used by user application.
*
* \return false Failed to initialize the timer counter, as the timer is not
* available or IO error.
* \return true initialization is successful.
*/
extern void init_cycle_counter(bool bIsSysTickOccupied);
extern bool init_cycle_counter(bool bIsSysTickOccupied);


/*!
Expand Down
36 changes: 20 additions & 16 deletions perfc_port_default.c
Original file line number Diff line number Diff line change
Expand Up @@ -160,23 +160,27 @@ extern uint32_t SystemCoreClock;

#if !__PERFC_CFG_DISABLE_DEFAULT_SYSTICK_PORTING__
__WEAK
void perfc_port_init_system_timer(bool bTimerOccupied)
bool perfc_port_init_system_timer(bool bTimerOccupied)
{
if (bTimerOccupied) {
return ;
}

__IRQ_SAFE {
SysTick->CTRL = 0;

SysTick->LOAD = SysTick_LOAD_RELOAD_Msk; /* set reload register */
//NVIC_SetPriority (SysTick_IRQn, (1UL << __NVIC_PRIO_BITS) - 1UL); /* set Priority for Systick Interrupt */
SysTick->VAL = 0UL; /* Load the SysTick Counter Value */
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;
}
do {
if (bTimerOccupied) {
break;
}

__IRQ_SAFE {
SysTick->CTRL = 0;

SysTick->LOAD = SysTick_LOAD_RELOAD_Msk; /* set reload register */
//NVIC_SetPriority (SysTick_IRQn, (1UL << __NVIC_PRIO_BITS) - 1UL); /* set Priority for Systick Interrupt */
SysTick->VAL = 0UL; /* Load the SysTick Counter Value */
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;
}
} while(0);

retun true;
}

__WEAK
Expand Down
10 changes: 8 additions & 2 deletions perfc_port_pmu.c
Original file line number Diff line number Diff line change
Expand Up @@ -859,7 +859,7 @@ int64_t perfc_port_get_system_timer_top(void);
extern
bool perfc_port_is_system_timer_ovf_pending(void);
extern
void perfc_port_init_system_timer(bool bTimerOccupied);
bool perfc_port_init_system_timer(bool bTimerOccupied);
extern
int64_t perfc_port_get_system_timer_elapsed(void);
extern
Expand All @@ -878,10 +878,14 @@ void perfc_port_clear_system_timer_counter(void);

#if __PERFC_USE_PMU_PORTING__

void perfc_port_init_system_timer(bool bIsTimeOccupied)
bool perfc_port_init_system_timer(bool bIsTimeOccupied)
{
UNUSED_PARAM(bIsTimeOccupied);

if (!(PMU->TYPE & PMU_TYPE_CYCCNT_PRESENT_Msk)) {
return false;
}

__IRQ_SAFE {
ARM_PMU_Disable();

Expand All @@ -892,6 +896,8 @@ void perfc_port_init_system_timer(bool bIsTimeOccupied)
ARM_PMU_CNTR_Enable(PMU_CNTENSET_CCNTR_ENABLE_Msk);
ARM_PMU_Enable();
}

return true;
}

uint32_t perfc_port_get_system_timer_freq(void)
Expand Down
33 changes: 19 additions & 14 deletions template/perfc_port_user.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ int64_t perfc_port_get_system_timer_top(void);
extern
bool perfc_port_is_system_timer_ovf_pending(void);
extern
void perfc_port_init_system_timer(bool bTimerOccupied);
bool perfc_port_init_system_timer(bool bTimerOccupied);
extern
int64_t perfc_port_get_system_timer_elapsed(void);
extern
Expand All @@ -67,20 +67,25 @@ void perfc_port_clear_system_timer_counter(void);

#if __PERFC_USE_USER_CUSTOM_PORTING__

void perfc_port_init_system_timer(bool bIsTimeOccupied)
bool perfc_port_init_system_timer(bool bIsTimeOccupied)
{
if (bIsTimeOccupied) {
return ;
}

__IRQ_SAFE {
/* Configure the system timer count with the longest possible period
* clear counter
* Clear overflow pending flag
* Enable interrupt if required
* start counting
*/
}
bool bResult = true;
do {
if (bIsTimeOccupied) {
break;
}

__IRQ_SAFE {
/* Configure the system timer count with the longest possible period
* clear counter
* Clear overflow pending flag
* Enable interrupt if required
* start counting
*/
}
} while(0);

return true;
}

uint32_t perfc_port_get_system_timer_freq(void)
Expand Down

0 comments on commit 142a241

Please sign in to comment.