update porting prototype

This commit is contained in:
Gabriel Wang 2024-01-27 14:04:03 +00:00
parent 72e5eb9e1b
commit 142a2415b9
5 changed files with 55 additions and 33 deletions

View File

@ -86,7 +86,7 @@ int64_t perfc_port_get_system_timer_top(void);
extern extern
bool perfc_port_is_system_timer_ovf_pending(void); bool perfc_port_is_system_timer_ovf_pending(void);
extern extern
void perfc_port_init_system_timer(bool bTimerOccupied); bool perfc_port_init_system_timer(bool bTimerOccupied);
extern extern
int64_t perfc_port_get_system_timer_elapsed(void); int64_t perfc_port_get_system_timer_elapsed(void);
extern extern
@ -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 { __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(); perfc_port_clear_system_timer_ovf_pending();
} }
@ -158,6 +159,8 @@ void init_cycle_counter(bool bIsSysTickOccupied)
s_lSystemUS = 0; // reset system microsecond counter s_lSystemUS = 0; // reset system microsecond counter
__perf_os_patch_init(); __perf_os_patch_init();
return bResult;
} }
/*! \note this function should only be called when irq is disabled /*! \note this function should only be called when irq is disabled

View File

@ -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 * \param[in] bIsSysTickOccupied A boolean value which indicates whether SysTick
* is already used by user application. * 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);
/*! /*!

View File

@ -160,23 +160,27 @@ extern uint32_t SystemCoreClock;
#if !__PERFC_CFG_DISABLE_DEFAULT_SYSTICK_PORTING__ #if !__PERFC_CFG_DISABLE_DEFAULT_SYSTICK_PORTING__
__WEAK __WEAK
void perfc_port_init_system_timer(bool bTimerOccupied) bool perfc_port_init_system_timer(bool bTimerOccupied)
{ {
if (bTimerOccupied) { do {
return ; if (bTimerOccupied) {
} break;
}
__IRQ_SAFE { __IRQ_SAFE {
SysTick->CTRL = 0; SysTick->CTRL = 0;
SysTick->LOAD = SysTick_LOAD_RELOAD_Msk; /* set reload register */ SysTick->LOAD = SysTick_LOAD_RELOAD_Msk; /* set reload register */
//NVIC_SetPriority (SysTick_IRQn, (1UL << __NVIC_PRIO_BITS) - 1UL); /* set Priority for Systick Interrupt */ //NVIC_SetPriority (SysTick_IRQn, (1UL << __NVIC_PRIO_BITS) - 1UL); /* set Priority for Systick Interrupt */
SysTick->VAL = 0UL; /* Load the SysTick Counter Value */ SysTick->VAL = 0UL; /* Load the SysTick Counter Value */
SysTick->CTRL = SysTick_CTRL_CLKSOURCE_Msk | SysTick->CTRL = SysTick_CTRL_CLKSOURCE_Msk |
SysTick_CTRL_TICKINT_Msk | SysTick_CTRL_TICKINT_Msk |
SysTick_CTRL_ENABLE_Msk; /* Enable SysTick IRQ and SysTick Timer */ SysTick_CTRL_ENABLE_Msk; /* Enable SysTick IRQ and SysTick Timer */
//SCB->ICSR = SCB_ICSR_PENDSTCLR_Msk; //SCB->ICSR = SCB_ICSR_PENDSTCLR_Msk;
} }
} while(0);
retun true;
} }
__WEAK __WEAK

View File

@ -859,7 +859,7 @@ int64_t perfc_port_get_system_timer_top(void);
extern extern
bool perfc_port_is_system_timer_ovf_pending(void); bool perfc_port_is_system_timer_ovf_pending(void);
extern extern
void perfc_port_init_system_timer(bool bTimerOccupied); bool perfc_port_init_system_timer(bool bTimerOccupied);
extern extern
int64_t perfc_port_get_system_timer_elapsed(void); int64_t perfc_port_get_system_timer_elapsed(void);
extern extern
@ -878,10 +878,14 @@ void perfc_port_clear_system_timer_counter(void);
#if __PERFC_USE_PMU_PORTING__ #if __PERFC_USE_PMU_PORTING__
void perfc_port_init_system_timer(bool bIsTimeOccupied) bool perfc_port_init_system_timer(bool bIsTimeOccupied)
{ {
UNUSED_PARAM(bIsTimeOccupied); UNUSED_PARAM(bIsTimeOccupied);
if (!(PMU->TYPE & PMU_TYPE_CYCCNT_PRESENT_Msk)) {
return false;
}
__IRQ_SAFE { __IRQ_SAFE {
ARM_PMU_Disable(); ARM_PMU_Disable();
@ -892,6 +896,8 @@ void perfc_port_init_system_timer(bool bIsTimeOccupied)
ARM_PMU_CNTR_Enable(PMU_CNTENSET_CCNTR_ENABLE_Msk); ARM_PMU_CNTR_Enable(PMU_CNTENSET_CCNTR_ENABLE_Msk);
ARM_PMU_Enable(); ARM_PMU_Enable();
} }
return true;
} }
uint32_t perfc_port_get_system_timer_freq(void) uint32_t perfc_port_get_system_timer_freq(void)

View File

@ -52,7 +52,7 @@ int64_t perfc_port_get_system_timer_top(void);
extern extern
bool perfc_port_is_system_timer_ovf_pending(void); bool perfc_port_is_system_timer_ovf_pending(void);
extern extern
void perfc_port_init_system_timer(bool bTimerOccupied); bool perfc_port_init_system_timer(bool bTimerOccupied);
extern extern
int64_t perfc_port_get_system_timer_elapsed(void); int64_t perfc_port_get_system_timer_elapsed(void);
extern extern
@ -67,20 +67,25 @@ void perfc_port_clear_system_timer_counter(void);
#if __PERFC_USE_USER_CUSTOM_PORTING__ #if __PERFC_USE_USER_CUSTOM_PORTING__
void perfc_port_init_system_timer(bool bIsTimeOccupied) bool perfc_port_init_system_timer(bool bIsTimeOccupied)
{ {
if (bIsTimeOccupied) { bool bResult = true;
return ; do {
} if (bIsTimeOccupied) {
break;
}
__IRQ_SAFE { __IRQ_SAFE {
/* Configure the system timer count with the longest possible period /* Configure the system timer count with the longest possible period
* clear counter * clear counter
* Clear overflow pending flag * Clear overflow pending flag
* Enable interrupt if required * Enable interrupt if required
* start counting * start counting
*/ */
} }
} while(0);
return true;
} }
uint32_t perfc_port_get_system_timer_freq(void) uint32_t perfc_port_get_system_timer_freq(void)