esp_psram_extram.h 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. /*
  2. * SPDX-FileCopyrightText: 2022 Espressif Systems (Shanghai) CO LTD
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. */
  6. #pragma once
  7. #include <stddef.h>
  8. #include <stdbool.h>
  9. #include "esp_err.h"
  10. #ifdef __cplusplus
  11. extern "C" {
  12. #endif
  13. /**
  14. * @brief Get the psram mapped vaddr range
  15. *
  16. * @param[out] out_vstart PSRAM virtual address start
  17. * @param[out] out_vend PSRAM virtual address end
  18. *
  19. * @note [out_vstart, out_vend), `out_vend` isn't included.
  20. *
  21. * @return
  22. * - ESP_OK On success
  23. * - ESP_ERR_INVALID_STATE PSRAM is not initialized successfully
  24. */
  25. esp_err_t esp_psram_extram_get_mapped_range(intptr_t *out_vstart, intptr_t *out_vend);
  26. /**
  27. * @brief Get the psram alloced vaddr range
  28. *
  29. * @param[out] out_vstart PSRAM virtual address start
  30. * @param[out] out_vend PSRAM virtual address end
  31. *
  32. * @note [out_vstart, out_vend), `out_vend` isn't included.
  33. *
  34. * @return
  35. * - ESP_OK On success
  36. * - ESP_ERR_INVALID_STATE PSRAM is not initialized successfully
  37. */
  38. esp_err_t esp_psram_extram_get_alloced_range(intptr_t *out_vstart, intptr_t *out_vend);
  39. /**
  40. * @brief Add the initialized PSRAM to the heap allocator.
  41. *
  42. * @return
  43. * - ESP_OK: On success
  44. * Other error type, see `heap_caps_add_region`.
  45. */
  46. esp_err_t esp_psram_extram_add_to_heap_allocator(void);
  47. /**
  48. * @brief Reserve a pool of internal memory for specific DMA/internal allocations
  49. *
  50. * @param size Size of reserved pool in bytes
  51. *
  52. * @return
  53. * - ESP_OK: On success
  54. * - ESP_ERR_NO_MEM: When no memory available for pool
  55. */
  56. esp_err_t esp_psram_extram_reserve_dma_pool(size_t size);
  57. /**
  58. * @brief Memory test for PSRAM. Should be called after PSRAM is initialized and
  59. * (in case of a dual-core system) the app CPU is online. This test overwrites the
  60. * memory with crap, so do not call after e.g. the heap allocator has stored important
  61. * stuff in PSRAM.
  62. *
  63. * @return true on success, false on failed memory test
  64. */
  65. bool esp_psram_extram_test(void);
  66. #if CONFIG_IDF_TARGET_ESP32
  67. /**
  68. * @brief Force a writeback of the data in the PSRAM cache. This is to be called whenever
  69. * cache is disabled, because disabling cache on the ESP32 discards the data in the PSRAM
  70. * cache.
  71. *
  72. * This is meant for use from within the SPI flash code.
  73. */
  74. void esp_psram_extram_writeback_cache(void);
  75. #endif
  76. #ifdef __cplusplus
  77. }
  78. #endif