1
6
7
8
9
10
11
12
13
14
15
16
17
18
24
25
26
27
28
29
30
31
34
35
36
37
41
42
47
48
49
57
68
69
73
74
79
/* ... */
#include "soc/dport_reg.h"
#include "esp_attr.h"
#include "esp_psram.h"
#include "esp_private/esp_psram_extram.h"
#if CONFIG_ESP_SYSTEM_SINGLE_CORE_MODE
#define PSRAM_MODE PSRAM_VADDR_MODE_NORMAL
#else
#define PSRAM_MODE PSRAM_VADDR_MODE_LOWHIGH
#endif
/* ... */
void IRAM_ATTR esp_psram_extram_writeback_cache(void)
{
int x;
volatile int i = 0;
volatile uint8_t *psram = (volatile uint8_t*)SOC_EXTRAM_DATA_LOW;
int cache_was_disabled = 0;
if (!esp_psram_is_initialized()) {
return;
}{...}
if (DPORT_REG_GET_BIT(DPORT_PRO_CACHE_CTRL_REG, DPORT_PRO_CACHE_ENABLE) == 0) {
cache_was_disabled |= (1 << 0);
DPORT_SET_PERI_REG_BITS(DPORT_PRO_CACHE_CTRL_REG, 1, 1, DPORT_PRO_CACHE_ENABLE_S);
}{...}
#ifndef CONFIG_ESP_SYSTEM_SINGLE_CORE_MODE
if (DPORT_REG_GET_BIT(DPORT_APP_CACHE_CTRL_REG, DPORT_APP_CACHE_ENABLE) == 0) {
cache_was_disabled |= (1 << 1);
DPORT_SET_PERI_REG_BITS(DPORT_APP_CACHE_CTRL_REG, 1, 1, DPORT_APP_CACHE_ENABLE_S);
}{...}
#endif/* ... */
#if (PSRAM_MODE != PSRAM_VADDR_MODE_LOWHIGH)
/* ... */
for (x = 0; x < 1024 * 64; x += 32) {
i += psram[x];
}{...}
#else/* ... */
/* ... */
for (x = 0; x < 1024 * 64; x += 32) {
i += psram[x];
i += psram[x + (1024 * 1024 * 2)];
}{...}
#endif/* ... */
if (cache_was_disabled & (1 << 0)) {
while (DPORT_GET_PERI_REG_BITS2(DPORT_PRO_DCACHE_DBUG0_REG, DPORT_PRO_CACHE_STATE, DPORT_PRO_CACHE_STATE_S) != 1) ;
DPORT_SET_PERI_REG_BITS(DPORT_PRO_CACHE_CTRL_REG, 1, 0, DPORT_PRO_CACHE_ENABLE_S);
}{...}
#ifndef CONFIG_ESP_SYSTEM_SINGLE_CORE_MODE
if (cache_was_disabled & (1 << 1)) {
while (DPORT_GET_PERI_REG_BITS2(DPORT_APP_DCACHE_DBUG0_REG, DPORT_APP_CACHE_STATE, DPORT_APP_CACHE_STATE_S) != 1);
DPORT_SET_PERI_REG_BITS(DPORT_APP_CACHE_CTRL_REG, 1, 0, DPORT_APP_CACHE_ENABLE_S);
}{...}
#endif/* ... */
}{ ... }