spiram.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  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. /**
  16. * @brief Initialize spiram interface/hardware. Normally called from cpu_start.c.
  17. *
  18. * @return ESP_OK on success
  19. */
  20. esp_err_t esp_spiram_init(void);
  21. /**
  22. * @brief Configure Cache/MMU for access to external SPI RAM.
  23. *
  24. * Normally this function is called from cpu_start, if CONFIG_SPIRAM_BOOT_INIT
  25. * option is enabled. Applications which need to enable SPI RAM at run time
  26. * can disable CONFIG_SPIRAM_BOOT_INIT, and call this function later.
  27. *
  28. * @attention this function must be called with flash cache disabled.
  29. */
  30. void esp_spiram_init_cache(void);
  31. /**
  32. * @brief Memory test for SPI RAM. Should be called after SPI RAM is initialized and
  33. * (in case of a dual-core system) the app CPU is online. This test overwrites the
  34. * memory with crap, so do not call after e.g. the heap allocator has stored important
  35. * stuff in SPI RAM.
  36. *
  37. * @return true on success, false on failed memory test
  38. */
  39. bool esp_spiram_test(void);
  40. /**
  41. * @brief Add the initialized SPI RAM to the heap allocator.
  42. */
  43. esp_err_t esp_spiram_add_to_heapalloc(void);
  44. /**
  45. * @brief Get the size of the attached SPI RAM chip selected in menuconfig
  46. *
  47. * @return Size in bytes, or 0 if no external RAM chip support compiled in.
  48. */
  49. size_t esp_spiram_get_size(void);
  50. /**
  51. * @brief Force a writeback of the data in the SPI RAM cache. This is to be called whenever
  52. * cache is disabled, because disabling cache on the ESP32 discards the data in the SPI
  53. * RAM cache.
  54. *
  55. * This is meant for use from within the SPI flash code.
  56. */
  57. void esp_spiram_writeback_cache(void);
  58. /**
  59. * @brief If SPI RAM(PSRAM) has been initialized
  60. *
  61. * @return
  62. * - true SPI RAM has been initialized successfully
  63. * - false SPI RAM hasn't been initialized or initialized failed
  64. */
  65. bool esp_spiram_is_initialized(void);
  66. /**
  67. * @brief get psram CS IO
  68. *
  69. * This interface should be called after PSRAM is enabled, otherwise it will
  70. * return an invalid value -1/0xff.
  71. *
  72. * @return psram CS IO or -1/0xff if psram not enabled
  73. */
  74. uint8_t esp_spiram_get_cs_io(void);
  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. #if CONFIG_SPIRAM_FETCH_INSTRUCTIONS
  94. extern int _instruction_reserved_start, _instruction_reserved_end;
  95. /**
  96. * @brief Get the start page number of the instruction in SPI flash
  97. *
  98. * @return start page number
  99. */
  100. uint32_t instruction_flash_start_page_get(void);
  101. /**
  102. * @brief Get the end page number of the instruction in SPI flash
  103. *
  104. * @return end page number
  105. */
  106. uint32_t instruction_flash_end_page_get(void);
  107. /**
  108. * @brief Get the offset of instruction from SPI flash to SPI RAM
  109. *
  110. * @return instruction offset
  111. */
  112. int instruction_flash2spiram_offset(void);
  113. #endif
  114. #if CONFIG_SPIRAM_RODATA
  115. extern int _rodata_reserved_start, _rodata_reserved_end;
  116. /**
  117. * @brief Get the start page number of the rodata in SPI flash
  118. *
  119. * @return start page number
  120. */
  121. uint32_t rodata_flash_start_page_get(void);
  122. /**
  123. * @brief Get the end page number of the rodata in SPI flash
  124. *
  125. * @return end page number
  126. */
  127. uint32_t rodata_flash_end_page_get(void);
  128. /**
  129. * @brief Get the offset number of rodata from SPI flash to SPI RAM
  130. *
  131. * @return rodata offset
  132. */
  133. int rodata_flash2spiram_offset(void);
  134. #endif
  135. #ifdef __cplusplus
  136. }
  137. #endif
  138. #endif