esp_spiram.h 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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. //
  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. #ifndef __ESP_SPIRAM_H
  15. #define __ESP_SPIRAM_H
  16. #include <stddef.h>
  17. #include <stdint.h>
  18. #include "esp_err.h"
  19. /**
  20. * @brief Initialize spiram interface/hardware. Normally called from cpu_start.c.
  21. *
  22. * @return ESP_OK on success
  23. */
  24. esp_err_t esp_spiram_init(void);
  25. /**
  26. * @brief Configure Cache/MMU for access to external SPI RAM.
  27. *
  28. * Normally this function is called from cpu_start, if CONFIG_SPIRAM_BOOT_INIT
  29. * option is enabled. Applications which need to enable SPI RAM at run time
  30. * can disable CONFIG_SPIRAM_BOOT_INIT, and call this function later.
  31. *
  32. * @attention this function must be called with flash cache disabled.
  33. */
  34. void esp_spiram_init_cache(void);
  35. /**
  36. * @brief Memory test for SPI RAM. Should be called after SPI RAM is initialized and
  37. * (in case of a dual-core system) the app CPU is online. This test overwrites the
  38. * memory with crap, so do not call after e.g. the heap allocator has stored important
  39. * stuff in SPI RAM.
  40. *
  41. * @return true on success, false on failed memory test
  42. */
  43. bool esp_spiram_test(void);
  44. /**
  45. * @brief Add the initialized SPI RAM to the heap allocator.
  46. */
  47. esp_err_t esp_spiram_add_to_heapalloc(void);
  48. /**
  49. * @brief Get the size of the attached SPI RAM chip selected in menuconfig
  50. *
  51. * @return Size in bytes, or 0 if no external RAM chip support compiled in.
  52. */
  53. size_t esp_spiram_get_size(void);
  54. /**
  55. * @brief Force a writeback of the data in the SPI RAM cache. This is to be called whenever
  56. * cache is disabled, because disabling cache on the ESP32 discards the data in the SPI
  57. * RAM cache.
  58. *
  59. * This is meant for use from within the SPI flash code.
  60. */
  61. void esp_spiram_writeback_cache(void);
  62. /**
  63. * @brief Reserve a pool of internal memory for specific DMA/internal allocations
  64. *
  65. * @param size Size of reserved pool in bytes
  66. *
  67. * @return
  68. * - ESP_OK on success
  69. * - ESP_ERR_NO_MEM when no memory available for pool
  70. */
  71. esp_err_t esp_spiram_reserve_dma_pool(size_t size);
  72. #endif