spiram.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  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 get psram CS IO
  60. *
  61. * This interface should be called after PSRAM is enabled, otherwise it will
  62. * return an invalid value -1/0xff.
  63. *
  64. * @return psram CS IO or -1/0xff if psram not enabled
  65. */
  66. uint8_t esp_spiram_get_cs_io(void);
  67. /**
  68. * @brief Reserve a pool of internal memory for specific DMA/internal allocations
  69. *
  70. * @param size Size of reserved pool in bytes
  71. *
  72. * @return
  73. * - ESP_OK on success
  74. * - ESP_ERR_NO_MEM when no memory available for pool
  75. */
  76. esp_err_t esp_spiram_reserve_dma_pool(size_t size);
  77. /**
  78. * @brief If SPI RAM(PSRAM) has been initialized
  79. *
  80. * @return
  81. * - true SPI RAM has been initialized successfully
  82. * - false SPI RAM hasn't been initialized or initialized failed
  83. */
  84. bool esp_spiram_is_initialized(void);
  85. #if CONFIG_SPIRAM_FETCH_INSTRUCTIONS
  86. extern int _instruction_reserved_start, _instruction_reserved_end;
  87. /**
  88. * @brief Get the start page number of the instruction in SPI flash
  89. *
  90. * @return start page number
  91. */
  92. uint32_t instruction_flash_start_page_get(void);
  93. /**
  94. * @brief Get the end page number of the instruction in SPI flash
  95. *
  96. * @return end page number
  97. */
  98. uint32_t instruction_flash_end_page_get(void);
  99. /**
  100. * @brief Get the offset of instruction from SPI flash to SPI RAM
  101. *
  102. * @return instruction offset
  103. */
  104. int instruction_flash2spiram_offset(void);
  105. #endif
  106. #if CONFIG_SPIRAM_RODATA
  107. extern int _rodata_reserved_start, _rodata_reserved_end;
  108. /**
  109. * @brief Get the start page number of the rodata in SPI flash
  110. *
  111. * @return start page number
  112. */
  113. uint32_t rodata_flash_start_page_get(void);
  114. /**
  115. * @brief Get the end page number of the rodata in SPI flash
  116. *
  117. * @return end page number
  118. */
  119. uint32_t rodata_flash_end_page_get(void);
  120. /**
  121. * @brief Get the offset number of rodata from SPI flash to SPI RAM
  122. *
  123. * @return rodata offset
  124. */
  125. int rodata_flash2spiram_offset(void);
  126. #endif
  127. #ifdef __cplusplus
  128. }
  129. #endif
  130. #endif