esp_spiram.h 3.2 KB

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