esp_spiram.h 3.2 KB

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