mirror of
https://github.com/espressif/esp-idf.git
synced 2025-08-24 01:25:36 +00:00
feat(ulp): add api to get lp_cpu wakeup cause and clear wakeup source at startup
Closes https://github.com/espressif/esp-idf/issues/12651
This commit is contained in:
@@ -12,6 +12,19 @@ extern "C" {
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
/**
|
||||
* @brief Traverse all possible wake-up sources and update the wake-up cause so that
|
||||
* ulp_lp_core_get_wakeup_cause can obtain the bitmap of the wake-up reasons.
|
||||
*/
|
||||
void ulp_lp_core_update_wakeup_cause(void);
|
||||
|
||||
/**
|
||||
* @brief Get the wakeup source which caused LP_CPU to wakeup from sleep
|
||||
*
|
||||
* @return Wakeup cause in bit map, for the meaning of each bit, refer
|
||||
* to the definition of wakeup source in lp_core_ll.h
|
||||
*/
|
||||
uint32_t ulp_lp_core_get_wakeup_cause(void);
|
||||
|
||||
/**
|
||||
* @brief Wakeup main CPU from sleep or deep sleep.
|
||||
|
@@ -14,6 +14,8 @@ extern void main();
|
||||
/* Initialize lp core related system functions before calling user's main*/
|
||||
void lp_core_startup()
|
||||
{
|
||||
ulp_lp_core_update_wakeup_cause();
|
||||
|
||||
main();
|
||||
|
||||
ulp_lp_core_memory_shared_cfg_t* shared_mem = ulp_lp_core_memory_shared_cfg_get();
|
||||
|
@@ -9,10 +9,57 @@
|
||||
#include "riscv/csr.h"
|
||||
#include "soc/soc.h"
|
||||
#include "soc/pmu_reg.h"
|
||||
#include "hal/misc.h"
|
||||
#include "ulp_lp_core.h"
|
||||
#include "hal/etm_ll.h"
|
||||
#include "hal/lp_timer_ll.h"
|
||||
#include "hal/pmu_ll.h"
|
||||
#include "hal/uart_ll.h"
|
||||
#include "hal/rtc_io_ll.h"
|
||||
|
||||
/* LP_FAST_CLK is not very accurate, for now use a rough estimate */
|
||||
#define LP_CORE_CPU_FREQUENCY_HZ 16000000
|
||||
|
||||
static uint32_t lp_wakeup_cause = 0;
|
||||
|
||||
void ulp_lp_core_update_wakeup_cause(void)
|
||||
{
|
||||
if ((REG_GET_FIELD(PMU_LP_CPU_PWR1_REG, PMU_LP_CPU_WAKEUP_EN) & ULP_LP_CORE_WAKEUP_SOURCE_HP_CPU) \
|
||||
&& (pmu_ll_lp_get_interrupt_raw(&PMU) & PMU_HP_SW_TRIGGER_INT_RAW)) {
|
||||
lp_wakeup_cause |= ULP_LP_CORE_WAKEUP_SOURCE_HP_CPU;
|
||||
pmu_ll_lp_clear_intsts_mask(&PMU, PMU_HP_SW_TRIGGER_INT_CLR);
|
||||
}
|
||||
|
||||
if ((REG_GET_FIELD(PMU_LP_CPU_PWR1_REG, PMU_LP_CPU_WAKEUP_EN) & ULP_LP_CORE_WAKEUP_SOURCE_LP_UART) \
|
||||
&& REG_GET_BIT(LP_UART_INT_RAW_REG, LP_UART_WAKEUP_INT_RAW)) {
|
||||
lp_wakeup_cause |= ULP_LP_CORE_WAKEUP_SOURCE_LP_UART;
|
||||
REG_SET_BIT(LP_UART_INT_CLR_REG, LP_UART_WAKEUP_INT_CLR);
|
||||
}
|
||||
|
||||
if ((REG_GET_FIELD(PMU_LP_CPU_PWR1_REG, PMU_LP_CPU_WAKEUP_EN) & ULP_LP_CORE_WAKEUP_SOURCE_LP_IO) \
|
||||
&& rtcio_ll_get_interrupt_status()) {
|
||||
lp_wakeup_cause |= ULP_LP_CORE_WAKEUP_SOURCE_LP_IO;
|
||||
rtcio_ll_clear_interrupt_status();
|
||||
}
|
||||
|
||||
if ((REG_GET_FIELD(PMU_LP_CPU_PWR1_REG, PMU_LP_CPU_WAKEUP_EN) & ULP_LP_CORE_WAKEUP_SOURCE_ETM) \
|
||||
&& etm_ll_is_lpcore_wakeup_triggered()) {
|
||||
lp_wakeup_cause |= ULP_LP_CORE_WAKEUP_SOURCE_ETM;
|
||||
etm_ll_clear_lpcore_wakeup_status();
|
||||
}
|
||||
|
||||
if ((REG_GET_FIELD(PMU_LP_CPU_PWR1_REG, PMU_LP_CPU_WAKEUP_EN) & ULP_LP_CORE_WAKEUP_SOURCE_LP_TIMER) \
|
||||
&& (lp_timer_ll_get_lp_intr_raw(&LP_TIMER) & LP_TIMER_MAIN_TIMER_LP_INT_RAW)) {
|
||||
lp_wakeup_cause |= ULP_LP_CORE_WAKEUP_SOURCE_LP_TIMER;
|
||||
lp_timer_ll_clear_lp_intsts_mask(&LP_TIMER, LP_TIMER_MAIN_TIMER_LP_INT_CLR);
|
||||
}
|
||||
}
|
||||
|
||||
uint32_t ulp_lp_core_get_wakeup_cause()
|
||||
{
|
||||
return lp_wakeup_cause;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Wakeup main CPU from sleep or deep sleep.
|
||||
*
|
||||
|
Reference in New Issue
Block a user