cpu_util.c 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. // Copyright 2013-2016 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. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. #include "esp_attr.h"
  15. #include "soc/cpu.h"
  16. #include "soc/soc.h"
  17. #include "soc/rtc_periph.h"
  18. #include "sdkconfig.h"
  19. void IRAM_ATTR esp_cpu_stall(int cpu_id)
  20. {
  21. if (cpu_id == 1) {
  22. CLEAR_PERI_REG_MASK(RTC_CNTL_SW_CPU_STALL_REG, RTC_CNTL_SW_STALL_APPCPU_C1_M);
  23. SET_PERI_REG_MASK(RTC_CNTL_SW_CPU_STALL_REG, 0x21<<RTC_CNTL_SW_STALL_APPCPU_C1_S);
  24. CLEAR_PERI_REG_MASK(RTC_CNTL_OPTIONS0_REG, RTC_CNTL_SW_STALL_APPCPU_C0_M);
  25. SET_PERI_REG_MASK(RTC_CNTL_OPTIONS0_REG, 2<<RTC_CNTL_SW_STALL_APPCPU_C0_S);
  26. } else {
  27. CLEAR_PERI_REG_MASK(RTC_CNTL_SW_CPU_STALL_REG, RTC_CNTL_SW_STALL_PROCPU_C1_M);
  28. SET_PERI_REG_MASK(RTC_CNTL_SW_CPU_STALL_REG, 0x21<<RTC_CNTL_SW_STALL_PROCPU_C1_S);
  29. CLEAR_PERI_REG_MASK(RTC_CNTL_OPTIONS0_REG, RTC_CNTL_SW_STALL_PROCPU_C0_M);
  30. SET_PERI_REG_MASK(RTC_CNTL_OPTIONS0_REG, 2<<RTC_CNTL_SW_STALL_PROCPU_C0_S);
  31. }
  32. }
  33. void IRAM_ATTR esp_cpu_unstall(int cpu_id)
  34. {
  35. if (cpu_id == 1) {
  36. CLEAR_PERI_REG_MASK(RTC_CNTL_SW_CPU_STALL_REG, RTC_CNTL_SW_STALL_APPCPU_C1_M);
  37. CLEAR_PERI_REG_MASK(RTC_CNTL_OPTIONS0_REG, RTC_CNTL_SW_STALL_APPCPU_C0_M);
  38. } else {
  39. CLEAR_PERI_REG_MASK(RTC_CNTL_SW_CPU_STALL_REG, RTC_CNTL_SW_STALL_PROCPU_C1_M);
  40. CLEAR_PERI_REG_MASK(RTC_CNTL_OPTIONS0_REG, RTC_CNTL_SW_STALL_PROCPU_C0_M);
  41. }
  42. }
  43. void IRAM_ATTR esp_cpu_reset(int cpu_id)
  44. {
  45. SET_PERI_REG_MASK(RTC_CNTL_OPTIONS0_REG,
  46. cpu_id == 0 ? RTC_CNTL_SW_PROCPU_RST_M : RTC_CNTL_SW_APPCPU_RST_M);
  47. }
  48. bool IRAM_ATTR esp_cpu_in_ocd_debug_mode(void)
  49. {
  50. #if CONFIG_ESP32_DEBUG_OCDAWARE
  51. int dcr;
  52. int reg=0x10200C; //DSRSET register
  53. asm("rer %0,%1":"=r"(dcr):"r"(reg));
  54. return (dcr&0x1);
  55. #else
  56. return false; // Always return false if "OCD aware" is disabled
  57. #endif
  58. }