1 /*
2  * SPDX-FileCopyrightText: 2022 Espressif Systems (Shanghai) CO LTD
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  */
6 
7 #pragma once
8 
9 #include <stddef.h>
10 #include <stdbool.h>
11 #include "esp_err.h"
12 
13 #ifdef __cplusplus
14 extern "C" {
15 #endif
16 
17 /**
18  * @brief Check if the pointer is on PSRAM
19  *
20  * @param[in] p  The pointer to check
21  *
22  * @return
23  *        - False: the pointer isn't on PSRAM, or PSRAM isn't initialised successfully
24  *        - True:  the pointer is on PSRAM
25  */
26 bool esp_psram_check_ptr_addr(const void *p);
27 
28 /**
29  * @brief Add the initialized PSRAM to the heap allocator.
30  *
31  * @return
32  *        - ESP_OK: On success
33  *        Other error type, see `heap_caps_add_region`.
34  */
35 esp_err_t esp_psram_extram_add_to_heap_allocator(void);
36 
37 /**
38  * @brief Reserve a pool of internal memory for specific DMA/internal allocations
39  *
40  * @param size Size of reserved pool in bytes
41  *
42  * @return
43  *          - ESP_OK:         On success
44  *          - ESP_ERR_NO_MEM: When no memory available for pool
45  */
46 esp_err_t esp_psram_extram_reserve_dma_pool(size_t size);
47 
48 /**
49  * @brief Memory test for PSRAM. Should be called after PSRAM is initialized and
50  * (in case of a dual-core system) the app CPU is online. This test overwrites the
51  * memory with crap, so do not call after e.g. the heap allocator has stored important
52  * stuff in PSRAM.
53  *
54  * @return true on success, false on failed memory test
55  */
56 bool esp_psram_extram_test(void);
57 
58 #if CONFIG_IDF_TARGET_ESP32
59 /**
60  * @brief Force a writeback of the data in the PSRAM cache. This is to be called whenever
61  * cache is disabled, because disabling cache on the ESP32 discards the data in the PSRAM
62  * cache.
63  *
64  * This is meant for use from within the SPI flash code.
65  */
66 void esp_psram_extram_writeback_cache(void);
67 #endif
68 
69 #ifdef __cplusplus
70 }
71 #endif
72