esp_memory_utils.c 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. /*
  2. * SPDX-FileCopyrightText: 2010-2022 Espressif Systems (Shanghai) CO LTD
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. */
  6. #include <stdlib.h>
  7. #include <stdint.h>
  8. #include <stdbool.h>
  9. #include "sdkconfig.h"
  10. #include "soc/soc.h"
  11. #include "soc/soc_caps.h"
  12. #include "esp_attr.h"
  13. #include "esp_memory_utils.h"
  14. #if CONFIG_SPIRAM
  15. #include "esp_private/esp_psram_extram.h"
  16. #endif
  17. bool esp_ptr_dma_ext_capable(const void *p)
  18. {
  19. #if !SOC_PSRAM_DMA_CAPABLE
  20. return false;
  21. #endif //!SOC_PSRAM_DMA_CAPABLE
  22. #if CONFIG_SPIRAM
  23. return esp_psram_check_ptr_addr(p);
  24. #else
  25. return false;
  26. #endif //CONFIG_SPIRAM
  27. }
  28. bool esp_ptr_byte_accessible(const void *p)
  29. {
  30. intptr_t ip = (intptr_t) p;
  31. bool r;
  32. r = (ip >= SOC_BYTE_ACCESSIBLE_LOW && ip < SOC_BYTE_ACCESSIBLE_HIGH);
  33. #if CONFIG_ESP_SYSTEM_ALLOW_RTC_FAST_MEM_AS_HEAP
  34. /* For ESP32 case, RTC fast memory is accessible to PRO cpu only and hence
  35. * for single core configuration (where it gets added to system heap) following
  36. * additional check is required */
  37. r |= (ip >= SOC_RTC_DRAM_LOW && ip < SOC_RTC_DRAM_HIGH);
  38. #endif
  39. #if CONFIG_SPIRAM
  40. r |= esp_psram_check_ptr_addr(p);
  41. #endif
  42. return r;
  43. }
  44. bool esp_ptr_external_ram(const void *p)
  45. {
  46. #if !SOC_SPIRAM_SUPPORTED
  47. return false;
  48. #endif //!SOC_SPIRAM_SUPPORTED
  49. #if CONFIG_SPIRAM
  50. return esp_psram_check_ptr_addr(p);
  51. #else
  52. return false;
  53. #endif //CONFIG_SPIRAM
  54. }
  55. #if CONFIG_SPIRAM_ALLOW_STACK_EXTERNAL_MEMORY
  56. bool esp_stack_ptr_in_extram(uint32_t sp)
  57. {
  58. //Check if stack ptr is on PSRAM, and 16 byte aligned.
  59. return (esp_psram_check_ptr_addr((void *)sp) && ((sp & 0xF) == 0));
  60. }
  61. #endif