spiram_psram.h 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. // Copyright 2015-2016 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. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. #ifndef _PSRAM_H
  15. #define _PSRAM_H
  16. #include "soc/spi_mem_reg.h"
  17. #include "esp_err.h"
  18. #include "sdkconfig.h"
  19. typedef enum {
  20. PSRAM_CACHE_S80M = 1,
  21. PSRAM_CACHE_S40M,
  22. PSRAM_CACHE_S26M,
  23. PSRAM_CACHE_S20M,
  24. PSRAM_CACHE_MAX,
  25. } psram_cache_mode_t;
  26. typedef enum {
  27. PSRAM_SIZE_16MBITS = 0,
  28. PSRAM_SIZE_32MBITS = 1,
  29. PSRAM_SIZE_64MBITS = 2,
  30. PSRAM_SIZE_MAX,
  31. } psram_size_t;
  32. /*
  33. See the TRM, chapter PID/MPU/MMU, header 'External RAM' for the definitions of these modes.
  34. Important is that NORMAL works with the app CPU cache disabled, but gives huge cache coherency
  35. issues when both app and pro CPU are enabled. LOWHIGH and EVENODD do not have these coherency
  36. issues but cannot be used when the app CPU cache is disabled.
  37. */
  38. typedef enum {
  39. PSRAM_VADDR_MODE_NORMAL=0, ///< App and pro CPU use their own flash cache for external RAM access
  40. PSRAM_VADDR_MODE_LOWHIGH, ///< App and pro CPU share external RAM caches: pro CPU has low 2M, app CPU has high 2M
  41. PSRAM_VADDR_MODE_EVENODD, ///< App and pro CPU share external RAM caches: pro CPU does even 32yte ranges, app does odd ones.
  42. } psram_vaddr_mode_t;
  43. /**
  44. * @brief get psram size
  45. * @return
  46. * - PSRAM_SIZE_MAX if psram not enabled or not valid
  47. * - PSRAM size
  48. */
  49. psram_size_t psram_get_size(void);
  50. /**
  51. * @brief psram cache enable function
  52. *
  53. * Esp-idf uses this to initialize cache for psram, mapping it into the main memory
  54. * address space.
  55. *
  56. * @param mode SPI mode to access psram in
  57. * @param vaddrmode Mode the psram cache works in.
  58. * @return ESP_OK on success, ESP_ERR_INVALID_STATE when VSPI peripheral is needed but cannot be claimed.
  59. */
  60. esp_err_t psram_enable(psram_cache_mode_t mode, psram_vaddr_mode_t vaddrmode);
  61. typedef enum {
  62. SPIRAM_WRAP_MODE_16B,
  63. SPIRAM_WRAP_MODE_32B,
  64. SPIRAM_WRAP_MODE_64B,
  65. SPIRAM_WRAP_MODE_DISABLE
  66. } spiram_wrap_mode_t;
  67. esp_err_t esp_spiram_wrap_set(spiram_wrap_mode_t mode);
  68. /**
  69. * @brief get psram CS IO
  70. *
  71. * @return psram CS IO
  72. */
  73. uint8_t psram_get_cs_io(void);
  74. #endif