2021-06-03 07:40:09 -04:00
|
|
|
/*
|
|
|
|
* SPDX-FileCopyrightText: 2015-2021 Espressif Systems (Shanghai) CO LTD
|
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
|
|
*/
|
2019-03-18 03:46:15 -04:00
|
|
|
|
|
|
|
|
|
|
|
#ifndef __ESP_SPIRAM_H
|
|
|
|
#define __ESP_SPIRAM_H
|
|
|
|
|
|
|
|
#include <stddef.h>
|
|
|
|
#include <stdint.h>
|
|
|
|
#include <stdbool.h>
|
|
|
|
#include "esp_err.h"
|
|
|
|
|
2021-03-04 06:56:59 -05:00
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
2022-03-23 08:16:08 -04:00
|
|
|
//TODO: IDF-4382, unify `target/spiram.h`, update migration guide as well
|
2019-03-18 03:46:15 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Initialize spiram interface/hardware. Normally called from cpu_start.c.
|
|
|
|
*
|
|
|
|
* @return ESP_OK on success
|
|
|
|
*/
|
2019-07-16 05:33:30 -04:00
|
|
|
esp_err_t esp_spiram_init(void);
|
2019-03-18 03:46:15 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Configure Cache/MMU for access to external SPI RAM.
|
|
|
|
*
|
|
|
|
* Normally this function is called from cpu_start, if CONFIG_SPIRAM_BOOT_INIT
|
|
|
|
* option is enabled. Applications which need to enable SPI RAM at run time
|
|
|
|
* can disable CONFIG_SPIRAM_BOOT_INIT, and call this function later.
|
|
|
|
*
|
|
|
|
* @attention this function must be called with flash cache disabled.
|
|
|
|
*/
|
2019-07-16 05:33:30 -04:00
|
|
|
void esp_spiram_init_cache(void);
|
2019-03-18 03:46:15 -04:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Memory test for SPI RAM. Should be called after SPI RAM is initialized and
|
|
|
|
* (in case of a dual-core system) the app CPU is online. This test overwrites the
|
|
|
|
* memory with crap, so do not call after e.g. the heap allocator has stored important
|
|
|
|
* stuff in SPI RAM.
|
|
|
|
*
|
|
|
|
* @return true on success, false on failed memory test
|
|
|
|
*/
|
2019-07-16 05:33:30 -04:00
|
|
|
bool esp_spiram_test(void);
|
2019-03-18 03:46:15 -04:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Add the initialized SPI RAM to the heap allocator.
|
|
|
|
*/
|
2019-07-16 05:33:30 -04:00
|
|
|
esp_err_t esp_spiram_add_to_heapalloc(void);
|
2019-03-18 03:46:15 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Force a writeback of the data in the SPI RAM cache. This is to be called whenever
|
|
|
|
* cache is disabled, because disabling cache on the ESP32 discards the data in the SPI
|
|
|
|
* RAM cache.
|
|
|
|
*
|
|
|
|
* This is meant for use from within the SPI flash code.
|
|
|
|
*/
|
2019-07-16 05:33:30 -04:00
|
|
|
void esp_spiram_writeback_cache(void);
|
2019-03-18 03:46:15 -04:00
|
|
|
|
2021-07-02 09:46:49 -04:00
|
|
|
/**
|
|
|
|
* @brief get psram CS IO
|
|
|
|
*
|
|
|
|
* This interface should be called after PSRAM is enabled, otherwise it will
|
|
|
|
* return an invalid value -1/0xff.
|
|
|
|
*
|
|
|
|
* @return psram CS IO or -1/0xff if psram not enabled
|
|
|
|
*/
|
|
|
|
uint8_t esp_spiram_get_cs_io(void);
|
2019-03-18 03:46:15 -04:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Reserve a pool of internal memory for specific DMA/internal allocations
|
|
|
|
*
|
|
|
|
* @param size Size of reserved pool in bytes
|
|
|
|
*
|
|
|
|
* @return
|
|
|
|
* - ESP_OK on success
|
|
|
|
* - ESP_ERR_NO_MEM when no memory available for pool
|
|
|
|
*/
|
|
|
|
esp_err_t esp_spiram_reserve_dma_pool(size_t size);
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief If SPI RAM(PSRAM) has been initialized
|
|
|
|
*
|
|
|
|
* @return
|
|
|
|
* - true SPI RAM has been initialized successfully
|
|
|
|
* - false SPI RAM hasn't been initialized or initialized failed
|
|
|
|
*/
|
|
|
|
bool esp_spiram_is_initialized(void);
|
|
|
|
|
2021-03-04 06:56:59 -05:00
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
2021-03-19 03:54:30 -04:00
|
|
|
|
|
|
|
#endif // __ESP_SPIRAM_H
|