add compenstation, PERF_CNT_DELAY_US_COMPENSATION, to delay_us

This commit is contained in:
Gabriel Wang 2021-01-14 12:49:23 +00:00
parent e14804538f
commit e8f3f02300

View File

@ -26,6 +26,10 @@
# define PERF_CNT_COMPENSATION_THRESHOLD 16
#endif
#ifndef PERF_CNT_DELAY_US_COMPENSATION
# define PERF_CNT_DELAY_US_COMPENSATION 20
#endif
/*============================ MACROS ========================================*/
/* IO definitions (access restrictions to peripheral registers) */
/**
@ -297,6 +301,12 @@ void delay_us(int32_t iUs)
{
iUs *= SystemCoreClock / 1000000ul;
if (iUs <= PERF_CNT_DELAY_US_COMPENSATION) {
return ;
}
iUs -= PERF_CNT_DELAY_US_COMPENSATION;
start_cycle_counter();
while(stop_cycle_counter() < iUs);
}