esp_spiram.h 2.5 KB

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