2024-01-02 11:16:55 +08:00
|
|
|
/*
|
|
|
|
* SPDX-FileCopyrightText: 2023-2024 Espressif Systems (Shanghai) CO LTD
|
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "sdkconfig.h"
|
|
|
|
#include "esp_private/systimer.h"
|
2024-06-07 21:29:44 +08:00
|
|
|
#include "hal/clk_tree_ll.h"
|
2024-01-02 11:16:55 +08:00
|
|
|
|
2024-06-07 21:29:44 +08:00
|
|
|
#if CONFIG_IDF_TARGET_ESP32C5_BETA3_VERSION
|
2024-01-02 11:16:55 +08:00
|
|
|
#if CONFIG_XTAL_FREQ_40
|
|
|
|
/**
|
|
|
|
* @brief systimer's clock source is fixed to XTAL (40MHz), and has a fixed fractional divider (2.5).
|
|
|
|
* So the resolution of the systimer is 40MHz/2.5 = 16MHz.
|
|
|
|
*/
|
|
|
|
|
|
|
|
uint64_t systimer_ticks_to_us(uint64_t ticks)
|
|
|
|
{
|
|
|
|
return ticks / 16;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint64_t systimer_us_to_ticks(uint64_t us)
|
|
|
|
{
|
|
|
|
return us * 16;
|
|
|
|
}
|
|
|
|
#elif CONFIG_XTAL_FREQ_48
|
|
|
|
uint64_t systimer_ticks_to_us(uint64_t ticks)
|
|
|
|
{
|
|
|
|
return ticks * 5 / 96;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint64_t systimer_us_to_ticks(uint64_t us)
|
|
|
|
{
|
|
|
|
return us * 96 / 5;
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
#error "Unsupported XTAL frequency by systimer"
|
|
|
|
#endif // CONFIG_XTAL_FREQ_xx
|
2024-06-07 21:29:44 +08:00
|
|
|
|
|
|
|
#else // !CONFIG_IDF_TARGET_ESP32C5_BETA3_VERSION
|
|
|
|
/**
|
|
|
|
* @brief systimer's clock source is fixed to XTAL, the fixed fractional divider is changed according to
|
|
|
|
* EFUSE_XTAL_48M_SEL. No matter 48MHz or 40MHz XTAL, the resolution of the systimer is always 16MHz.
|
|
|
|
*/
|
|
|
|
|
|
|
|
uint64_t systimer_ticks_to_us(uint64_t ticks)
|
|
|
|
{
|
|
|
|
return ticks / 16;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint64_t systimer_us_to_ticks(uint64_t us)
|
|
|
|
{
|
|
|
|
return us * 16;
|
|
|
|
}
|
|
|
|
#endif
|