2022-01-18 21:57:31 -05:00
|
|
|
/*
|
|
|
|
* SPDX-FileCopyrightText: 2015-2022 Espressif Systems (Shanghai) CO LTD
|
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
|
|
*/
|
2020-04-17 15:34:56 -04:00
|
|
|
|
2022-01-21 04:13:48 -05:00
|
|
|
#include "ulp_riscv_utils.h"
|
|
|
|
#include "ulp_riscv_register_ops.h"
|
|
|
|
#include "soc/soc.h"
|
|
|
|
#include "soc/rtc_cntl_reg.h"
|
|
|
|
#include "soc/soc_ulp.h"
|
2020-04-17 15:34:56 -04:00
|
|
|
|
|
|
|
void ulp_riscv_rescue_from_monitor(void)
|
|
|
|
{
|
|
|
|
/* Rescue RISCV from monitor state. */
|
2022-05-25 23:38:21 -04:00
|
|
|
CLEAR_PERI_REG_MASK(RTC_CNTL_COCPU_CTRL_REG, RTC_CNTL_COCPU_DONE | RTC_CNTL_COCPU_SHUT_RESET_EN);
|
2020-04-17 15:34:56 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void ulp_riscv_wakeup_main_processor(void)
|
|
|
|
{
|
2020-11-10 02:40:01 -05:00
|
|
|
SET_PERI_REG_MASK(RTC_CNTL_STATE0_REG, RTC_CNTL_SW_CPU_INT);
|
2020-04-17 15:34:56 -04:00
|
|
|
}
|
|
|
|
|
2022-01-18 21:57:31 -05:00
|
|
|
void ulp_riscv_halt(void)
|
2020-04-17 15:34:56 -04:00
|
|
|
{
|
|
|
|
/* Setting the delay time after RISCV recv `DONE` signal, Ensure that action `RESET` can be executed in time. */
|
|
|
|
REG_SET_FIELD(RTC_CNTL_COCPU_CTRL_REG, RTC_CNTL_COCPU_SHUT_2_CLK_DIS, 0x3F);
|
|
|
|
|
|
|
|
/* suspends the ulp operation*/
|
|
|
|
SET_PERI_REG_MASK(RTC_CNTL_COCPU_CTRL_REG, RTC_CNTL_COCPU_DONE);
|
2020-11-10 02:40:01 -05:00
|
|
|
|
2020-04-17 15:34:56 -04:00
|
|
|
/* Resets the processor */
|
|
|
|
SET_PERI_REG_MASK(RTC_CNTL_COCPU_CTRL_REG, RTC_CNTL_COCPU_SHUT_RESET_EN);
|
|
|
|
|
|
|
|
while(1);
|
|
|
|
}
|
2021-06-23 02:54:36 -04:00
|
|
|
|
|
|
|
void ulp_riscv_delay_cycles(uint32_t cycles)
|
|
|
|
{
|
|
|
|
uint32_t start = ULP_RISCV_GET_CCOUNT();
|
|
|
|
|
|
|
|
while ((ULP_RISCV_GET_CCOUNT() - start) < cycles) {
|
|
|
|
/* Wait */
|
|
|
|
}
|
|
|
|
}
|
2022-01-18 21:57:31 -05:00
|
|
|
|
|
|
|
void ulp_riscv_timer_stop(void)
|
|
|
|
{
|
|
|
|
CLEAR_PERI_REG_MASK(RTC_CNTL_ULP_CP_TIMER_REG, RTC_CNTL_ULP_CP_SLP_TIMER_EN);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ulp_riscv_timer_resume(void)
|
|
|
|
{
|
|
|
|
SET_PERI_REG_MASK(RTC_CNTL_ULP_CP_TIMER_REG, RTC_CNTL_ULP_CP_SLP_TIMER_EN);
|
|
|
|
}
|
2022-02-27 23:05:48 -05:00
|
|
|
|
|
|
|
void ulp_riscv_gpio_wakeup_clear(void)
|
|
|
|
{
|
|
|
|
SET_PERI_REG_MASK(RTC_CNTL_ULP_CP_TIMER_REG, RTC_CNTL_ULP_CP_GPIO_WAKEUP_CLR);
|
|
|
|
}
|