arch/xtensa/src/esp32/esp32_spiflash.c&esp32_spi.c: Allocate a buffer from DRAM

when the given buffer is from PSRAM.

Signed-off-by: Abdelatif Guettouche <abdelatif.guettouche@espressif.com>
This commit is contained in:
Abdelatif Guettouche
2020-09-17 21:35:09 +01:00
committed by Alan Carvalho de Assis
parent 7ac5f7a35b
commit 1b12d20225
5 changed files with 342 additions and 88 deletions
+7 -7
View File
@@ -95,18 +95,18 @@ config XTENSA_CP_INITSET
coprocessor with the same bit layout as for the CPENABLE register.
config XTENSA_USE_SEPERATE_IMEM
bool "Use a seperate heap for internal memory"
default n
bool "Use a seperate heap for internal memory"
default n
config XTENSA_IMEM_REGION_SIZE
hex "DRAM region size for internal use"
depends on XTENSA_USE_SEPERATE_IMEM
hex "DRAM region size for internal use"
depends on XTENSA_USE_SEPERATE_IMEM
range 0x2000 0x28000
default 0x28000
default 0x28000
config XTENSA_IMEM_PROCFS
bool "Internal memory PROCFS support"
default n
bool "Internal memory PROCFS support"
default n
depends on XTENSA_USE_SEPERATE_IMEM && !DISABLE_MOUNTPOINT && FS_PROCFS && FS_PROCFS_REGISTER
source arch/xtensa/src/lx6/Kconfig
+67 -14
View File
@@ -31,6 +31,7 @@
#include <stdlib.h>
#include <stdint.h>
#include <stdbool.h>
#include <string.h>
#include <errno.h>
#include <debug.h>
#include <time.h>
@@ -57,7 +58,7 @@
#include "rom/esp32_gpio.h"
/****************************************************************************
* Private Types
* Pre-processor Definitions
****************************************************************************/
/* SPI DMA RX/TX description number */
@@ -77,6 +78,14 @@
#define SPI_FREQ_DEFAULT 400000
#ifndef MIN
# define MIN(a, b) (((a) < (b)) ? (a) : (b))
#endif
/****************************************************************************
* Private Types
****************************************************************************/
/* SPI Device hardware configuration */
struct esp32_spi_config_s
@@ -157,8 +166,7 @@ struct esp32_spi_priv_s
static int esp32_spi_lock(FAR struct spi_dev_s *dev, bool lock);
#ifndef CONFIG_ESP32_SPI_UDCS
static void esp32_spi_select(FAR struct spi_dev_s *dev,
uint32_t devid,
bool selected);
uint32_t devid, bool selected);
#endif
static uint32_t esp32_spi_setfrequency(FAR struct spi_dev_s *dev,
uint32_t frequency);
@@ -411,8 +419,7 @@ static inline uint32_t esp32_spi_get_reg(struct esp32_spi_priv_s *priv,
****************************************************************************/
static inline void esp32_spi_set_regbits(struct esp32_spi_priv_s *priv,
int offset,
uint32_t bits)
int offset, uint32_t bits)
{
uint32_t tmp = getreg32(priv->config->reg_base + offset);
@@ -436,8 +443,7 @@ static inline void esp32_spi_set_regbits(struct esp32_spi_priv_s *priv,
****************************************************************************/
static inline void esp32_spi_reset_regbits(struct esp32_spi_priv_s *priv,
int offset,
uint32_t bits)
int offset, uint32_t bits)
{
uint32_t tmp = getreg32(priv->config->reg_base + offset);
@@ -550,7 +556,7 @@ static int esp32_spi_sem_waitdone(FAR struct esp32_spi_priv_s *priv)
* Name: esp32_spi_select
*
* Description:
* Enable/disable the SPI chip select. The implementation of this method
* Enable/disable the SPI chip select. The implementation of this method
* must include handshaking: If a device is selected, it must hold off
* all other attempts to select the device until the device is deselected.
*
@@ -560,8 +566,8 @@ static int esp32_spi_sem_waitdone(FAR struct esp32_spi_priv_s *priv)
* the function will do nothing.
*
* Input Parameters:
* priv - Private SPI device structure
* devid - Identifies the device to select
* priv - Private SPI device structure
* devid - Identifies the device to select
* selected - true: slave selected, false: slave de-selected
*
* Returned Value:
@@ -571,8 +577,7 @@ static int esp32_spi_sem_waitdone(FAR struct esp32_spi_priv_s *priv)
#ifndef CONFIG_ESP32_SPI_UDCS
static void esp32_spi_select(FAR struct spi_dev_s *dev,
uint32_t devid,
bool selected)
uint32_t devid, bool selected)
{
#ifdef CONFIG_ESP32_SPI_SWCS
FAR struct esp32_spi_priv_s *priv = (FAR struct esp32_spi_priv_s *)dev;
@@ -861,11 +866,43 @@ static void esp32_spi_dma_exchange(FAR struct esp32_spi_priv_s *priv,
uint32_t nwords)
{
uint32_t bytes = nwords * (priv->nbits / 8);
uint8_t *tp = (uint8_t *)txbuffer;
uint8_t *rp = (uint8_t *)rxbuffer;
uint8_t *tp;
uint8_t *rp;
uint32_t n;
uint32_t regval;
/* If the buffer comes from PSRAM, allocate a new one from DRAM */
#ifdef CONFIG_XTENSA_USE_SEPERATE_IMEM
if (esp32_ptr_extram(txbuffer))
{
tp = up_imm_malloc(bytes);
if (tp == NULL)
{
return;
}
}
else
#endif
{
tp = (uint8_t *)txbuffer;
}
#ifdef CONFIG_XTENSA_USE_SEPERATE_IMEM
if (esp32_ptr_extram(rxbuffer))
{
rp = up_imm_malloc(bytes);
if (rp == NULL)
{
goto error_with_tp;
}
}
else
#endif
{
rp = (uint8_t *)rxbuffer;
}
if (!tp)
{
tp = rp;
@@ -924,6 +961,22 @@ static void esp32_spi_dma_exchange(FAR struct esp32_spi_priv_s *priv,
tp += n;
rp += n;
}
#ifdef CONFIG_XTENSA_USE_SEPERATE_IMEM
if (esp32_ptr_extram(rxbuffer))
{
memcpy(rxbuffer, rp, bytes);
up_imm_free(rp);
}
#endif
#ifdef CONFIG_XTENSA_USE_SEPERATE_IMEM
error_with_tp:
if (esp32_ptr_extram(txbuffer))
{
up_imm_free(tp);
}
#endif
}
/****************************************************************************
File diff suppressed because it is too large Load Diff
@@ -32,6 +32,9 @@
****************************************************************************/
#include <stdint.h>
#include <stdbool.h>
#include "xtensa_attr.h"
/****************************************************************************
* Pre-processor Definitions
@@ -774,4 +777,22 @@ extern int rom_i2c_writeReg(int block, int block_id, int reg_add,
#define PIN_CTRL (DR_REG_IO_MUX_BASE +0x00)
/****************************************************************************
* Inline Functions
****************************************************************************/
/****************************************************************************
* Name: esp32_ptr_extram
*
* Description:
* Check if the buffer comes from the external RAM
*
****************************************************************************/
static inline bool IRAM_ATTR esp32_ptr_extram(const void *p)
{
return ((intptr_t)p >= SOC_EXTRAM_DATA_LOW &&
(intptr_t)p < SOC_EXTRAM_DATA_HIGH);
}
#endif /* __ARCH_XTENSA_SRC_ESP32_HARDWARE_ESP32_SOC_H */
@@ -49,3 +49,4 @@ CONFIG_START_YEAR=2011
CONFIG_SYSTEM_NSH=y
CONFIG_UART0_SERIAL_CONSOLE=y
CONFIG_USER_ENTRYPOINT="nsh_main"
CONFIG_XTENSA_USE_SEPERATE_IMEM=y