mirror of
https://github.com/espressif/esp-idf.git
synced 2024-10-05 20:47:46 -04:00
rtc_time.c: simplify the rtc_time_get with LL function
This commit is contained in:
parent
f95ccb09f2
commit
4b4491e736
@ -7,6 +7,7 @@
|
|||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include "esp_rom_sys.h"
|
#include "esp_rom_sys.h"
|
||||||
#include "hal/clk_tree_ll.h"
|
#include "hal/clk_tree_ll.h"
|
||||||
|
#include "hal/rtc_cntl_ll.h"
|
||||||
#include "soc/rtc.h"
|
#include "soc/rtc.h"
|
||||||
#include "soc/timer_periph.h"
|
#include "soc/timer_periph.h"
|
||||||
#include "esp_hw_log.h"
|
#include "esp_hw_log.h"
|
||||||
@ -152,20 +153,7 @@ uint64_t rtc_time_slowclk_to_us(uint64_t rtc_cycles, uint32_t period)
|
|||||||
|
|
||||||
uint64_t rtc_time_get(void)
|
uint64_t rtc_time_get(void)
|
||||||
{
|
{
|
||||||
SET_PERI_REG_MASK(RTC_CNTL_TIME_UPDATE_REG, RTC_CNTL_TIME_UPDATE);
|
return rtc_cntl_ll_get_rtc_time();
|
||||||
int attempts = 1000;
|
|
||||||
while (GET_PERI_REG_MASK(RTC_CNTL_TIME_UPDATE_REG, RTC_CNTL_TIME_VALID) == 0) {
|
|
||||||
esp_rom_delay_us(1); // might take 1 RTC slowclk period, don't flood RTC bus
|
|
||||||
if (attempts) {
|
|
||||||
if (--attempts == 0 && clk_ll_xtal32k_digi_is_enabled()) {
|
|
||||||
ESP_HW_LOGE(TAG, "rtc_time_get() 32kHz xtal has been stopped");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
SET_PERI_REG_MASK(RTC_CNTL_INT_CLR_REG, RTC_CNTL_TIME_VALID_INT_CLR);
|
|
||||||
uint64_t t = READ_PERI_REG(RTC_CNTL_TIME0_REG);
|
|
||||||
t |= ((uint64_t) READ_PERI_REG(RTC_CNTL_TIME1_REG)) << 32;
|
|
||||||
return t;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void rtc_clk_wait_for_slow_cycle(void)
|
void rtc_clk_wait_for_slow_cycle(void)
|
||||||
|
@ -9,6 +9,7 @@
|
|||||||
#include "soc/rtc.h"
|
#include "soc/rtc.h"
|
||||||
#include "soc/rtc_cntl_reg.h"
|
#include "soc/rtc_cntl_reg.h"
|
||||||
#include "hal/clk_tree_ll.h"
|
#include "hal/clk_tree_ll.h"
|
||||||
|
#include "hal/rtc_cntl_ll.h"
|
||||||
#include "soc/timer_group_reg.h"
|
#include "soc/timer_group_reg.h"
|
||||||
#include "esp_rom_sys.h"
|
#include "esp_rom_sys.h"
|
||||||
|
|
||||||
@ -166,10 +167,7 @@ uint64_t rtc_time_slowclk_to_us(uint64_t rtc_cycles, uint32_t period)
|
|||||||
|
|
||||||
uint64_t rtc_time_get(void)
|
uint64_t rtc_time_get(void)
|
||||||
{
|
{
|
||||||
SET_PERI_REG_MASK(RTC_CNTL_TIME_UPDATE_REG, RTC_CNTL_TIME_UPDATE);
|
return rtc_cntl_ll_get_rtc_time();
|
||||||
uint64_t t = READ_PERI_REG(RTC_CNTL_TIME0_REG);
|
|
||||||
t |= ((uint64_t) READ_PERI_REG(RTC_CNTL_TIME1_REG)) << 32;
|
|
||||||
return t;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
uint64_t rtc_light_slp_time_get(void)
|
uint64_t rtc_light_slp_time_get(void)
|
||||||
|
@ -9,6 +9,7 @@
|
|||||||
#include "soc/rtc.h"
|
#include "soc/rtc.h"
|
||||||
#include "soc/rtc_cntl_reg.h"
|
#include "soc/rtc_cntl_reg.h"
|
||||||
#include "hal/clk_tree_ll.h"
|
#include "hal/clk_tree_ll.h"
|
||||||
|
#include "hal/rtc_cntl_ll.h"
|
||||||
#include "soc/timer_group_reg.h"
|
#include "soc/timer_group_reg.h"
|
||||||
#include "esp_rom_sys.h"
|
#include "esp_rom_sys.h"
|
||||||
|
|
||||||
@ -169,10 +170,7 @@ uint64_t rtc_time_slowclk_to_us(uint64_t rtc_cycles, uint32_t period)
|
|||||||
|
|
||||||
uint64_t rtc_time_get(void)
|
uint64_t rtc_time_get(void)
|
||||||
{
|
{
|
||||||
SET_PERI_REG_MASK(RTC_CNTL_TIME_UPDATE_REG, RTC_CNTL_TIME_UPDATE);
|
return rtc_cntl_ll_get_rtc_time();
|
||||||
uint64_t t = READ_PERI_REG(RTC_CNTL_TIME0_REG);
|
|
||||||
t |= ((uint64_t) READ_PERI_REG(RTC_CNTL_TIME1_REG)) << 32;
|
|
||||||
return t;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
uint64_t rtc_light_slp_time_get(void)
|
uint64_t rtc_light_slp_time_get(void)
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* SPDX-FileCopyrightText: 2022 Espressif Systems (Shanghai) CO LTD
|
* SPDX-FileCopyrightText: 2022-2023 Espressif Systems (Shanghai) CO LTD
|
||||||
*
|
*
|
||||||
* SPDX-License-Identifier: Apache-2.0
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
*/
|
*/
|
||||||
@ -9,6 +9,7 @@
|
|||||||
#include "soc/rtc.h"
|
#include "soc/rtc.h"
|
||||||
#include "soc/lp_timer_reg.h"
|
#include "soc/lp_timer_reg.h"
|
||||||
#include "hal/clk_tree_ll.h"
|
#include "hal/clk_tree_ll.h"
|
||||||
|
#include "hal/rtc_cntl_ll.h"
|
||||||
#include "soc/timer_group_reg.h"
|
#include "soc/timer_group_reg.h"
|
||||||
#include "esp_rom_sys.h"
|
#include "esp_rom_sys.h"
|
||||||
#include "assert.h"
|
#include "assert.h"
|
||||||
@ -206,10 +207,7 @@ uint64_t rtc_time_slowclk_to_us(uint64_t rtc_cycles, uint32_t period)
|
|||||||
|
|
||||||
uint64_t rtc_time_get(void)
|
uint64_t rtc_time_get(void)
|
||||||
{
|
{
|
||||||
SET_PERI_REG_MASK(LP_TIMER_UPDATE_REG, LP_TIMER_MAIN_TIMER_UPDATE);
|
return rtc_cntl_ll_get_rtc_time();
|
||||||
uint64_t t = READ_PERI_REG(LP_TIMER_MAIN_BUF0_LOW_REG);
|
|
||||||
t |= ((uint64_t) READ_PERI_REG(LP_TIMER_MAIN_BUF0_HIGH_REG)) << 32;
|
|
||||||
return t;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
uint64_t rtc_light_slp_time_get(void)
|
uint64_t rtc_light_slp_time_get(void)
|
||||||
|
@ -9,6 +9,7 @@
|
|||||||
#include "soc/rtc.h"
|
#include "soc/rtc.h"
|
||||||
#include "soc/rtc_cntl_reg.h"
|
#include "soc/rtc_cntl_reg.h"
|
||||||
#include "hal/clk_tree_ll.h"
|
#include "hal/clk_tree_ll.h"
|
||||||
|
#include "hal/rtc_cntl_ll.h"
|
||||||
#include "soc/timer_group_reg.h"
|
#include "soc/timer_group_reg.h"
|
||||||
#include "esp_rom_sys.h"
|
#include "esp_rom_sys.h"
|
||||||
|
|
||||||
@ -163,10 +164,7 @@ uint64_t rtc_time_slowclk_to_us(uint64_t rtc_cycles, uint32_t period)
|
|||||||
|
|
||||||
uint64_t rtc_time_get(void)
|
uint64_t rtc_time_get(void)
|
||||||
{
|
{
|
||||||
SET_PERI_REG_MASK(RTC_CNTL_TIME_UPDATE_REG, RTC_CNTL_TIME_UPDATE);
|
return rtc_cntl_ll_get_rtc_time();
|
||||||
uint64_t t = READ_PERI_REG(RTC_CNTL_TIME0_REG);
|
|
||||||
t |= ((uint64_t) READ_PERI_REG(RTC_CNTL_TIME1_REG)) << 32;
|
|
||||||
return t;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
uint64_t rtc_light_slp_time_get(void)
|
uint64_t rtc_light_slp_time_get(void)
|
||||||
|
@ -9,6 +9,7 @@
|
|||||||
#include "soc/rtc.h"
|
#include "soc/rtc.h"
|
||||||
#include "soc/rtc_cntl_reg.h"
|
#include "soc/rtc_cntl_reg.h"
|
||||||
#include "hal/clk_tree_ll.h"
|
#include "hal/clk_tree_ll.h"
|
||||||
|
#include "hal/rtc_cntl_ll.h"
|
||||||
#include "soc/timer_group_reg.h"
|
#include "soc/timer_group_reg.h"
|
||||||
|
|
||||||
/* Calibration of RTC_SLOW_CLK is performed using a special feature of TIMG0.
|
/* Calibration of RTC_SLOW_CLK is performed using a special feature of TIMG0.
|
||||||
@ -234,10 +235,7 @@ uint64_t rtc_time_slowclk_to_us(uint64_t rtc_cycles, uint32_t period)
|
|||||||
|
|
||||||
uint64_t rtc_time_get(void)
|
uint64_t rtc_time_get(void)
|
||||||
{
|
{
|
||||||
SET_PERI_REG_MASK(RTC_CNTL_TIME_UPDATE_REG, RTC_CNTL_TIME_UPDATE);
|
return rtc_cntl_ll_get_rtc_time();
|
||||||
uint64_t t = READ_PERI_REG(RTC_CNTL_TIME0_REG);
|
|
||||||
t |= ((uint64_t) READ_PERI_REG(RTC_CNTL_TIME1_REG)) << 32;
|
|
||||||
return t;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
uint64_t rtc_light_slp_time_get(void)
|
uint64_t rtc_light_slp_time_get(void)
|
||||||
|
@ -9,6 +9,7 @@
|
|||||||
#include "soc/rtc.h"
|
#include "soc/rtc.h"
|
||||||
#include "soc/rtc_cntl_reg.h"
|
#include "soc/rtc_cntl_reg.h"
|
||||||
#include "hal/clk_tree_ll.h"
|
#include "hal/clk_tree_ll.h"
|
||||||
|
#include "hal/rtc_cntl_ll.h"
|
||||||
#include "soc/timer_group_reg.h"
|
#include "soc/timer_group_reg.h"
|
||||||
|
|
||||||
/* Calibration of RTC_SLOW_CLK is performed using a special feature of TIMG0.
|
/* Calibration of RTC_SLOW_CLK is performed using a special feature of TIMG0.
|
||||||
@ -168,10 +169,7 @@ uint64_t rtc_time_slowclk_to_us(uint64_t rtc_cycles, uint32_t period)
|
|||||||
|
|
||||||
uint64_t rtc_time_get(void)
|
uint64_t rtc_time_get(void)
|
||||||
{
|
{
|
||||||
SET_PERI_REG_MASK(RTC_CNTL_TIME_UPDATE_REG, RTC_CNTL_TIME_UPDATE);
|
return rtc_cntl_ll_get_rtc_time();
|
||||||
uint64_t t = READ_PERI_REG(RTC_CNTL_TIME0_REG);
|
|
||||||
t |= ((uint64_t) READ_PERI_REG(RTC_CNTL_TIME1_REG)) << 32;
|
|
||||||
return t;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
uint64_t rtc_light_slp_time_get(void)
|
uint64_t rtc_light_slp_time_get(void)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user