esp_system_chip.c 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. /*
  2. * SPDX-FileCopyrightText: 2022-2023 Espressif Systems (Shanghai) CO LTD
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. */
  6. #include <stdint.h>
  7. #include "esp_cpu.h"
  8. #include "soc/soc.h"
  9. #include "soc/soc_caps.h"
  10. #include "esp_private/rtc_clk.h"
  11. #include "esp_private/panic_internal.h"
  12. #include "esp_private/system_internal.h"
  13. #include "esp_private/mspi_timing_tuning.h"
  14. #include "esp_heap_caps.h"
  15. #include "esp_rom_uart.h"
  16. #include "esp_rom_sys.h"
  17. #include "sdkconfig.h"
  18. // used only by ESP32 panic handler
  19. #ifdef CONFIG_IDF_TARGET_ESP32
  20. void IRAM_ATTR esp_restart_noos_dig(void)
  21. {
  22. // In case any of the calls below results in re-enabling of interrupts
  23. // (for example, by entering a critical section), disable all the
  24. // interrupts (e.g. from watchdogs) here.
  25. #ifdef CONFIG_IDF_TARGET_ARCH_RISCV
  26. rv_utils_intr_global_disable();
  27. #else
  28. xt_ints_off(0xFFFFFFFF);
  29. #endif
  30. // make sure all the panic handler output is sent from UART FIFO
  31. if (CONFIG_ESP_CONSOLE_UART_NUM >= 0) {
  32. esp_rom_uart_tx_wait_idle(CONFIG_ESP_CONSOLE_UART_NUM);
  33. }
  34. #if !CONFIG_APP_BUILD_TYPE_PURE_RAM_APP
  35. /**
  36. * Turn down MSPI speed
  37. *
  38. * We set MSPI clock to a high speed one before, ROM doesn't have such high speed clock source option.
  39. * This function will change clock source to a ROM supported one when system restarts.
  40. */
  41. mspi_timing_change_speed_mode_cache_safe(true);
  42. #endif //#if !CONFIG_APP_BUILD_TYPE_PURE_RAM_APP
  43. // switch to XTAL (otherwise we will keep running from the PLL)
  44. rtc_clk_cpu_set_to_default_config();
  45. // esp_restart_noos_dig() will generates a core reset, which does not reset the
  46. // registers of the RTC domain, so the CPU's stall state remains after the reset,
  47. // we need to release them here
  48. #if !CONFIG_FREERTOS_UNICORE
  49. // unstall all other cores
  50. int core_id = esp_cpu_get_core_id();
  51. for (uint32_t i = 0; i < SOC_CPU_CORES_NUM; i++) {
  52. if (i != core_id) {
  53. esp_cpu_unstall(i);
  54. }
  55. }
  56. #endif
  57. // generate core reset
  58. esp_rom_software_reset_system();
  59. while (true) {
  60. ;
  61. }
  62. }
  63. #endif
  64. uint32_t esp_get_free_heap_size( void )
  65. {
  66. return heap_caps_get_free_size( MALLOC_CAP_DEFAULT );
  67. }
  68. uint32_t esp_get_free_internal_heap_size( void )
  69. {
  70. return heap_caps_get_free_size( MALLOC_CAP_8BIT | MALLOC_CAP_DMA | MALLOC_CAP_INTERNAL );
  71. }
  72. uint32_t esp_get_minimum_free_heap_size( void )
  73. {
  74. return heap_caps_get_minimum_free_size( MALLOC_CAP_DEFAULT );
  75. }
  76. const char *esp_get_idf_version(void)
  77. {
  78. return IDF_VER;
  79. }
  80. void __attribute__((noreturn)) esp_system_abort(const char *details)
  81. {
  82. panic_abort(details);
  83. }