ulp-riscv: made ulp_riscv_delay_cycles more accurate

This commit is contained in:
Marius Vikhammer 2022-07-25 14:02:23 +08:00
parent b823831a26
commit 4f1046a292
2 changed files with 10 additions and 10 deletions

View File

@ -94,7 +94,16 @@ void ulp_riscv_timer_resume(void);
*
* @param cycles Number of cycles to busy wait
*/
void ulp_riscv_delay_cycles(uint32_t cycles);
void static inline ulp_riscv_delay_cycles(uint32_t cycles)
{
uint32_t start = ULP_RISCV_GET_CCOUNT();
/* Off with an estimate of cycles in this function to improve accuracy */
uint32_t end = start + cycles - 20;
while (ULP_RISCV_GET_CCOUNT() < end) {
/* Wait */
}
}
/**
* @brief Clears the GPIO wakeup interrupt bit

View File

@ -35,15 +35,6 @@ void ulp_riscv_halt(void)
while(1);
}
void ulp_riscv_delay_cycles(uint32_t cycles)
{
uint32_t start = ULP_RISCV_GET_CCOUNT();
while ((ULP_RISCV_GET_CCOUNT() - start) < cycles) {
/* Wait */
}
}
void ulp_riscv_timer_stop(void)
{
CLEAR_PERI_REG_MASK(RTC_CNTL_ULP_CP_TIMER_REG, RTC_CNTL_ULP_CP_SLP_TIMER_EN);