spiram_psram.h 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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_periph.h"
  17. #include "esp_err.h"
  18. #include "sdkconfig.h"
  19. typedef enum {
  20. PSRAM_CACHE_F80M_S40M = 0,
  21. PSRAM_CACHE_F40M_S40M,
  22. PSRAM_CACHE_F80M_S80M,
  23. PSRAM_CACHE_MAX,
  24. } psram_cache_mode_t;
  25. typedef enum {
  26. PSRAM_SIZE_16MBITS = 0,
  27. PSRAM_SIZE_32MBITS = 1,
  28. PSRAM_SIZE_64MBITS = 2,
  29. PSRAM_SIZE_MAX,
  30. } psram_size_t;
  31. /*
  32. See the TRM, chapter PID/MPU/MMU, header 'External RAM' for the definitions of these modes.
  33. Important is that NORMAL works with the app CPU cache disabled, but gives huge cache coherency
  34. issues when both app and pro CPU are enabled. LOWHIGH and EVENODD do not have these coherency
  35. issues but cannot be used when the app CPU cache is disabled.
  36. */
  37. typedef enum {
  38. PSRAM_VADDR_MODE_NORMAL=0, ///< App and pro CPU use their own flash cache for external RAM access
  39. PSRAM_VADDR_MODE_LOWHIGH, ///< App and pro CPU share external RAM caches: pro CPU has low 2M, app CPU has high 2M
  40. PSRAM_VADDR_MODE_EVENODD, ///< App and pro CPU share external RAM caches: pro CPU does even 32yte ranges, app does odd ones.
  41. } psram_vaddr_mode_t;
  42. /**
  43. * @brief get psram size
  44. * @return
  45. * - PSRAM_SIZE_MAX if psram not enabled or not valid
  46. * - PSRAM size
  47. */
  48. psram_size_t psram_get_size(void);
  49. /**
  50. * @brief psram cache enable function
  51. *
  52. * Esp-idf uses this to initialize cache for psram, mapping it into the main memory
  53. * address space.
  54. *
  55. * @param mode SPI mode to access psram in
  56. * @param vaddrmode Mode the psram cache works in.
  57. * @return ESP_OK on success, ESP_ERR_INVALID_STATE when VSPI peripheral is needed but cannot be claimed.
  58. */
  59. esp_err_t psram_enable(psram_cache_mode_t mode, psram_vaddr_mode_t vaddrmode);
  60. /**
  61. * @brief get psram CS IO
  62. *
  63. * @return psram CS IO
  64. */
  65. uint8_t psram_get_cs_io(void);
  66. #endif