1 // Copyright 2015-2017 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 15 16 #ifndef __ESP_SPIRAM_H 17 #define __ESP_SPIRAM_H 18 19 #include <stddef.h> 20 #include <stdint.h> 21 #include <stdbool.h> 22 #include "esp_err.h" 23 24 typedef enum { 25 ESP_SPIRAM_SIZE_16MBITS = 0, /*!< SPI RAM size is 16 MBits */ 26 ESP_SPIRAM_SIZE_32MBITS = 1, /*!< SPI RAM size is 32 MBits */ 27 ESP_SPIRAM_SIZE_64MBITS = 2, /*!< SPI RAM size is 64 MBits */ 28 ESP_SPIRAM_SIZE_INVALID, /*!< SPI RAM size is invalid */ 29 } esp_spiram_size_t; 30 31 /** 32 * @brief get SPI RAM size 33 * @return 34 * - ESP_SPIRAM_SIZE_INVALID if SPI RAM not enabled or not valid 35 * - SPI RAM size 36 */ 37 esp_spiram_size_t esp_spiram_get_chip_size(void); 38 39 /** 40 * @brief Initialize spiram interface/hardware. Normally called from cpu_start.c. 41 * 42 * @return ESP_OK on success 43 */ 44 esp_err_t esp_spiram_init(void); 45 46 /** 47 * @brief Configure Cache/MMU for access to external SPI RAM. 48 * 49 * Normally this function is called from cpu_start, if CONFIG_SPIRAM_BOOT_INIT 50 * option is enabled. Applications which need to enable SPI RAM at run time 51 * can disable CONFIG_SPIRAM_BOOT_INIT, and call this function later. 52 * 53 * @attention this function must be called with flash cache disabled. 54 */ 55 void esp_spiram_init_cache(void); 56 57 58 /** 59 * @brief Memory test for SPI RAM. Should be called after SPI RAM is initialized and 60 * (in case of a dual-core system) the app CPU is online. This test overwrites the 61 * memory with crap, so do not call after e.g. the heap allocator has stored important 62 * stuff in SPI RAM. 63 * 64 * @return true on success, false on failed memory test 65 */ 66 bool esp_spiram_test(void); 67 68 69 /** 70 * @brief Add the initialized SPI RAM to the heap allocator. 71 */ 72 esp_err_t esp_spiram_add_to_heapalloc(void); 73 74 75 /** 76 * @brief Get the size of the attached SPI RAM chip selected in menuconfig 77 * 78 * @return Size in bytes, or 0 if no external RAM chip support compiled in. 79 */ 80 size_t esp_spiram_get_size(void); 81 82 83 /** 84 * @brief Force a writeback of the data in the SPI RAM cache. This is to be called whenever 85 * cache is disabled, because disabling cache on the ESP32 discards the data in the SPI 86 * RAM cache. 87 * 88 * This is meant for use from within the SPI flash code. 89 */ 90 void esp_spiram_writeback_cache(void); 91 92 93 94 /** 95 * @brief Reserve a pool of internal memory for specific DMA/internal allocations 96 * 97 * @param size Size of reserved pool in bytes 98 * 99 * @return 100 * - ESP_OK on success 101 * - ESP_ERR_NO_MEM when no memory available for pool 102 */ 103 esp_err_t esp_spiram_reserve_dma_pool(size_t size); 104 105 106 /** 107 * @brief If SPI RAM(PSRAM) has been initialized 108 * 109 * @return 110 * - true SPI RAM has been initialized successfully 111 * - false SPI RAM hasn't been initialized or initialized failed 112 */ 113 bool esp_spiram_is_initialized(void); 114 115 116 #endif 117