esp_spiram.h 2.6 KB

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