spiram.h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. /*
  2. * SPDX-FileCopyrightText: 2015-2021 Espressif Systems (Shanghai) CO LTD
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. */
  6. #ifndef __ESP_SPIRAM_H
  7. #define __ESP_SPIRAM_H
  8. #include <stddef.h>
  9. #include <stdint.h>
  10. #include <stdbool.h>
  11. #include "esp_err.h"
  12. #ifdef __cplusplus
  13. extern "C" {
  14. #endif
  15. typedef enum {
  16. ESP_SPIRAM_SIZE_16MBITS = 0, /*!< SPI RAM size is 16 MBits */
  17. ESP_SPIRAM_SIZE_32MBITS = 1, /*!< SPI RAM size is 32 MBits */
  18. ESP_SPIRAM_SIZE_64MBITS = 2, /*!< SPI RAM size is 64 MBits */
  19. ESP_SPIRAM_SIZE_INVALID, /*!< SPI RAM size is invalid */
  20. } esp_spiram_size_t;
  21. /**
  22. * @brief get SPI RAM size
  23. * @return
  24. * - ESP_SPIRAM_SIZE_INVALID if SPI RAM not enabled or not valid
  25. * - SPI RAM size
  26. */
  27. esp_spiram_size_t esp_spiram_get_chip_size(void);
  28. /**
  29. * @brief Initialize spiram interface/hardware. Normally called from cpu_start.c.
  30. *
  31. * @return ESP_OK on success
  32. */
  33. esp_err_t esp_spiram_init(void);
  34. /**
  35. * @brief Configure Cache/MMU for access to external SPI RAM.
  36. *
  37. * Normally this function is called from cpu_start, if CONFIG_SPIRAM_BOOT_INIT
  38. * option is enabled. Applications which need to enable SPI RAM at run time
  39. * can disable CONFIG_SPIRAM_BOOT_INIT, and call this function later.
  40. *
  41. * @attention this function must be called with flash cache disabled.
  42. */
  43. void esp_spiram_init_cache(void);
  44. /**
  45. * @brief Memory test for SPI RAM. Should be called after SPI RAM is initialized and
  46. * (in case of a dual-core system) the app CPU is online. This test overwrites the
  47. * memory with crap, so do not call after e.g. the heap allocator has stored important
  48. * stuff in SPI RAM.
  49. *
  50. * @return true on success, false on failed memory test
  51. */
  52. bool esp_spiram_test(void);
  53. /**
  54. * @brief Add the initialized SPI RAM to the heap allocator.
  55. */
  56. esp_err_t esp_spiram_add_to_heapalloc(void);
  57. /**
  58. * @brief Get the size of the attached SPI RAM chip selected in menuconfig
  59. *
  60. * @return Size in bytes, or 0 if no external RAM chip support compiled in.
  61. */
  62. size_t esp_spiram_get_size(void);
  63. /**
  64. * @brief Force a writeback of the data in the SPI RAM cache. This is to be called whenever
  65. * cache is disabled, because disabling cache on the ESP32 discards the data in the SPI
  66. * RAM cache.
  67. *
  68. * This is meant for use from within the SPI flash code.
  69. */
  70. void esp_spiram_writeback_cache(void);
  71. /**
  72. * @brief get psram CS IO
  73. *
  74. * This interface should be called after PSRAM is enabled, otherwise it will
  75. * return an invalid value -1/0xff.
  76. *
  77. * @return psram CS IO or -1/0xff if psram not enabled
  78. */
  79. uint8_t esp_spiram_get_cs_io(void);
  80. /**
  81. * @brief Reserve a pool of internal memory for specific DMA/internal allocations
  82. *
  83. * @param size Size of reserved pool in bytes
  84. *
  85. * @return
  86. * - ESP_OK on success
  87. * - ESP_ERR_NO_MEM when no memory available for pool
  88. */
  89. esp_err_t esp_spiram_reserve_dma_pool(size_t size);
  90. /**
  91. * @brief If SPI RAM(PSRAM) has been initialized
  92. *
  93. * @return
  94. * - true SPI RAM has been initialized successfully
  95. * - false SPI RAM hasn't been initialized or initialized failed
  96. */
  97. bool esp_spiram_is_initialized(void);
  98. #ifdef __cplusplus
  99. }
  100. #endif
  101. #endif // __ESP_SPIRAM_H