2019-05-10 03:34:06 +00:00
|
|
|
// Copyright 2015-2017 Espressif Systems (Shanghai) PTE LTD
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
//
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
|
|
|
|
|
|
|
/*
|
|
|
|
The cache has an interrupt that can be raised as soon as an access to a cached
|
|
|
|
region (flash, psram) is done without the cache being enabled. We use that here
|
|
|
|
to panic the CPU, which from a debugging perspective is better than grabbing bad
|
|
|
|
data from the bus.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdint.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdbool.h>
|
2020-02-16 13:20:58 +00:00
|
|
|
|
2019-05-10 03:34:06 +00:00
|
|
|
#include "esp_err.h"
|
|
|
|
#include "esp_attr.h"
|
2020-02-16 13:20:58 +00:00
|
|
|
|
|
|
|
#include "esp_intr_alloc.h"
|
|
|
|
|
2019-12-26 07:25:24 +00:00
|
|
|
#include "soc/extmem_reg.h"
|
2019-05-10 03:34:06 +00:00
|
|
|
#include "soc/dport_reg.h"
|
|
|
|
#include "soc/periph_defs.h"
|
2020-02-16 13:20:58 +00:00
|
|
|
#include "hal/cpu_hal.h"
|
|
|
|
|
2020-01-17 03:47:08 +00:00
|
|
|
#include "esp32s2/dport_access.h"
|
2020-07-21 05:07:34 +00:00
|
|
|
#include "esp32s2/rom/ets_sys.h" // for intr_matrix_set
|
2020-02-16 13:20:58 +00:00
|
|
|
|
|
|
|
#include "sdkconfig.h"
|
2019-05-10 03:34:06 +00:00
|
|
|
|
2019-08-12 02:06:07 +00:00
|
|
|
void esp_cache_err_int_init(void)
|
2019-05-10 03:34:06 +00:00
|
|
|
{
|
2020-02-16 13:20:58 +00:00
|
|
|
uint32_t core_id = cpu_hal_get_core_id();
|
2020-03-10 15:46:10 +00:00
|
|
|
ESP_INTR_DISABLE(ETS_MEMACCESS_ERR_INUM);
|
2019-05-10 03:34:06 +00:00
|
|
|
|
|
|
|
// We do not register a handler for the interrupt because it is interrupt
|
|
|
|
// level 4 which is not serviceable from C. Instead, xtensa_vectors.S has
|
|
|
|
// a call to the panic handler for
|
|
|
|
// this interrupt.
|
2020-03-10 15:46:10 +00:00
|
|
|
intr_matrix_set(core_id, ETS_CACHE_IA_INTR_SOURCE, ETS_MEMACCESS_ERR_INUM);
|
2019-05-10 03:34:06 +00:00
|
|
|
|
|
|
|
// Enable invalid cache access interrupt when the cache is disabled.
|
2020-05-04 04:46:19 +00:00
|
|
|
// The status bits are cleared first, in case we are restarting after
|
|
|
|
// a cache error has triggered.
|
2019-12-26 07:25:24 +00:00
|
|
|
DPORT_SET_PERI_REG_MASK(EXTMEM_CACHE_DBG_INT_CLR_REG,
|
|
|
|
EXTMEM_MMU_ENTRY_FAULT_INT_CLR |
|
|
|
|
EXTMEM_DCACHE_REJECT_INT_CLR |
|
|
|
|
EXTMEM_DCACHE_WRITE_FLASH_INT_CLR |
|
|
|
|
EXTMEM_DC_PRELOAD_SIZE_FAULT_INT_CLR |
|
|
|
|
EXTMEM_DC_SYNC_SIZE_FAULT_INT_CLR |
|
|
|
|
EXTMEM_ICACHE_REJECT_INT_CLR |
|
|
|
|
EXTMEM_IC_PRELOAD_SIZE_FAULT_INT_CLR |
|
|
|
|
EXTMEM_IC_SYNC_SIZE_FAULT_INT_CLR);
|
|
|
|
DPORT_SET_PERI_REG_MASK(EXTMEM_CACHE_DBG_INT_ENA_REG,
|
|
|
|
EXTMEM_MMU_ENTRY_FAULT_INT_ENA |
|
|
|
|
EXTMEM_DCACHE_REJECT_INT_ENA |
|
|
|
|
EXTMEM_DCACHE_WRITE_FLASH_INT_ENA |
|
|
|
|
EXTMEM_DC_PRELOAD_SIZE_FAULT_INT_ENA |
|
|
|
|
EXTMEM_DC_SYNC_SIZE_FAULT_INT_ENA |
|
|
|
|
EXTMEM_ICACHE_REJECT_INT_ENA |
|
|
|
|
EXTMEM_IC_PRELOAD_SIZE_FAULT_INT_ENA |
|
|
|
|
EXTMEM_IC_SYNC_SIZE_FAULT_INT_ENA |
|
|
|
|
EXTMEM_CACHE_DBG_EN);
|
2019-07-17 02:05:18 +00:00
|
|
|
|
2020-03-10 15:46:10 +00:00
|
|
|
ESP_INTR_ENABLE(ETS_MEMACCESS_ERR_INUM);
|
2019-05-10 03:34:06 +00:00
|
|
|
}
|
|
|
|
|
2019-08-12 02:06:07 +00:00
|
|
|
int IRAM_ATTR esp_cache_err_get_cpuid(void)
|
2019-05-10 03:34:06 +00:00
|
|
|
{
|
2020-05-04 04:46:19 +00:00
|
|
|
if (REG_READ(EXTMEM_CACHE_DBG_STATUS0_REG) != 0 ||
|
|
|
|
REG_READ(EXTMEM_CACHE_DBG_STATUS1_REG) != 0) {
|
|
|
|
return PRO_CPU_NUM;
|
|
|
|
}
|
|
|
|
return -1;
|
2019-05-10 03:34:06 +00:00
|
|
|
}
|