ulp_riscv_utils.c 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. // Copyright 2015-2020 Espressif Systems (Shanghai) PTE LTD
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. // http://www.apache.org/licenses/LICENSE-2.0
  7. //
  8. // Unless required by applicable law or agreed to in writing, software
  9. // distributed under the License is distributed on an "AS IS" BASIS,
  10. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  11. // See the License for the specific language governing permissions and
  12. // limitations under the License.
  13. #include "ulp_riscv/ulp_riscv.h"
  14. #include "ulp_riscv/ulp_riscv_utils.h"
  15. void ulp_riscv_rescue_from_monitor(void)
  16. {
  17. /* Rescue RISCV from monitor state. */
  18. CLEAR_PERI_REG_MASK(RTC_CNTL_COCPU_CTRL_REG, RTC_CNTL_COCPU_DONE | RTC_CNTL_COCPU_SHUT_RESET_EN);
  19. }
  20. void ulp_riscv_wakeup_main_processor(void)
  21. {
  22. SET_PERI_REG_MASK(RTC_CNTL_STATE0_REG, RTC_CNTL_SW_CPU_INT);
  23. }
  24. void ulp_riscv_shutdown(void)
  25. {
  26. /* Setting the delay time after RISCV recv `DONE` signal, Ensure that action `RESET` can be executed in time. */
  27. REG_SET_FIELD(RTC_CNTL_COCPU_CTRL_REG, RTC_CNTL_COCPU_SHUT_2_CLK_DIS, 0x3F);
  28. /* suspends the ulp operation*/
  29. SET_PERI_REG_MASK(RTC_CNTL_COCPU_CTRL_REG, RTC_CNTL_COCPU_DONE);
  30. /* Resets the processor */
  31. SET_PERI_REG_MASK(RTC_CNTL_COCPU_CTRL_REG, RTC_CNTL_COCPU_SHUT_RESET_EN);
  32. while(1);
  33. }
  34. void ulp_riscv_delay_cycles(uint32_t cycles)
  35. {
  36. uint32_t start = ULP_RISCV_GET_CCOUNT();
  37. while ((ULP_RISCV_GET_CCOUNT() - start) < cycles) {
  38. /* Wait */
  39. }
  40. }