ulp_riscv_utils.c 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. /*
  2. * SPDX-FileCopyrightText: 2015-2022 Espressif Systems (Shanghai) CO LTD
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. */
  6. #include "ulp_riscv_utils.h"
  7. #include "ulp_riscv_register_ops.h"
  8. #include "soc/soc.h"
  9. #include "soc/rtc_cntl_reg.h"
  10. #include "soc/soc_ulp.h"
  11. void ulp_riscv_rescue_from_monitor(void)
  12. {
  13. /* Rescue RISCV from monitor state. */
  14. CLEAR_PERI_REG_MASK(RTC_CNTL_COCPU_CTRL_REG, RTC_CNTL_COCPU_DONE | RTC_CNTL_COCPU_SHUT_RESET_EN);
  15. }
  16. void ulp_riscv_wakeup_main_processor(void)
  17. {
  18. SET_PERI_REG_MASK(RTC_CNTL_STATE0_REG, RTC_CNTL_SW_CPU_INT);
  19. }
  20. void ulp_riscv_halt(void)
  21. {
  22. /* Setting the delay time after RISCV recv `DONE` signal, Ensure that action `RESET` can be executed in time. */
  23. REG_SET_FIELD(RTC_CNTL_COCPU_CTRL_REG, RTC_CNTL_COCPU_SHUT_2_CLK_DIS, 0x3F);
  24. /* suspends the ulp operation*/
  25. SET_PERI_REG_MASK(RTC_CNTL_COCPU_CTRL_REG, RTC_CNTL_COCPU_DONE);
  26. /* Resets the processor */
  27. SET_PERI_REG_MASK(RTC_CNTL_COCPU_CTRL_REG, RTC_CNTL_COCPU_SHUT_RESET_EN);
  28. while(1);
  29. }
  30. void ulp_riscv_delay_cycles(uint32_t cycles)
  31. {
  32. uint32_t start = ULP_RISCV_GET_CCOUNT();
  33. while ((ULP_RISCV_GET_CCOUNT() - start) < cycles) {
  34. /* Wait */
  35. }
  36. }
  37. void ulp_riscv_timer_stop(void)
  38. {
  39. CLEAR_PERI_REG_MASK(RTC_CNTL_ULP_CP_TIMER_REG, RTC_CNTL_ULP_CP_SLP_TIMER_EN);
  40. }
  41. void ulp_riscv_timer_resume(void)
  42. {
  43. SET_PERI_REG_MASK(RTC_CNTL_ULP_CP_TIMER_REG, RTC_CNTL_ULP_CP_SLP_TIMER_EN);
  44. }
  45. void ulp_riscv_gpio_wakeup_clear(void)
  46. {
  47. SET_PERI_REG_MASK(RTC_CNTL_ULP_CP_TIMER_REG, RTC_CNTL_ULP_CP_GPIO_WAKEUP_CLR);
  48. }