1 /* 2 * SPDX-FileCopyrightText: 2015-2021 Espressif Systems (Shanghai) CO LTD 3 * 4 * SPDX-License-Identifier: Apache-2.0 5 */ 6 7 #pragma once 8 9 #include "esp_err.h" 10 #include "sdkconfig.h" 11 12 #ifdef __cplusplus 13 extern "C" { 14 #endif 15 16 #define PSRAM_SIZE_2MB (2 * 1024 * 1024) 17 #define PSRAM_SIZE_4MB (4 * 1024 * 1024) 18 #define PSRAM_SIZE_8MB (8 * 1024 * 1024) 19 #define PSRAM_SIZE_16MB (16 * 1024 * 1024) 20 #define PSRAM_SIZE_32MB (32 * 1024 * 1024) 21 22 23 /* 24 See the TRM, chapter PID/MPU/MMU, header 'External RAM' for the definitions of these modes. 25 26 Important is that NORMAL works with the app CPU cache disabled, but gives huge cache coherency 27 issues when both app and pro CPU are enabled. LOWHIGH and EVENODD do not have these coherency 28 issues but cannot be used when the app CPU cache is disabled. 29 */ 30 typedef enum { 31 PSRAM_VADDR_MODE_NORMAL=0, ///< App and pro CPU use their own flash cache for external RAM access 32 PSRAM_VADDR_MODE_LOWHIGH, ///< App and pro CPU share external RAM caches: pro CPU has low 2M, app CPU has high 2M 33 PSRAM_VADDR_MODE_EVENODD, ///< App and pro CPU share external RAM caches: pro CPU does even 32yte ranges, app does odd ones. 34 } psram_vaddr_mode_t; 35 36 /** 37 * @brief To get the physical psram size in bytes. 38 * 39 * @param[out] out_size_bytes physical psram size in bytes. 40 */ 41 esp_err_t esp_psram_impl_get_physical_size(uint32_t *out_size_bytes); 42 43 /** 44 * @brief To get the available physical psram size in bytes. 45 * 46 * @param[out] out_size_bytes availabe physical psram size in bytes. 47 */ 48 esp_err_t esp_psram_impl_get_available_size(uint32_t *out_size_bytes); 49 50 /** 51 * @brief Enable psram and configure it to a ready state 52 * 53 * @param vaddrmode Mode the psram cache works in. 54 * @return 55 * - ESP_OK: On success 56 * - ESP_ERR_NOT_SUPPORTED: PSRAM ID / vendor ID check fail 57 * - ESP_ERR_INVALID_STATE: On esp32, when VSPI peripheral is needed but cannot be claimed 58 */ 59 esp_err_t esp_psram_impl_enable(psram_vaddr_mode_t vaddrmode); 60 61 /** 62 * @brief get psram CS IO 63 * 64 * @return psram CS IO 65 */ 66 uint8_t esp_psram_impl_get_cs_io(void); 67