2021-08-05 11:35:07 -04:00
|
|
|
/*
|
2023-11-22 04:53:59 -05:00
|
|
|
* SPDX-FileCopyrightText: 2015-2024 Espressif Systems (Shanghai) CO LTD
|
2021-08-05 11:35:07 -04:00
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
|
|
*/
|
2016-11-25 04:33:51 -05:00
|
|
|
|
|
|
|
#include <stdint.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdbool.h>
|
|
|
|
#include <string.h>
|
2020-09-29 19:44:12 -04:00
|
|
|
#include <esp_types.h>
|
|
|
|
#include <limits.h>
|
|
|
|
#include <assert.h>
|
2020-12-28 23:31:54 -05:00
|
|
|
#include "sdkconfig.h"
|
2016-11-25 04:33:51 -05:00
|
|
|
#include "freertos/FreeRTOS.h"
|
|
|
|
#include "freertos/task.h"
|
|
|
|
#include "esp_err.h"
|
|
|
|
#include "esp_log.h"
|
2022-07-21 07:14:41 -04:00
|
|
|
#include "esp_memory_utils.h"
|
2019-03-26 04:30:43 -04:00
|
|
|
#include "esp_intr_alloc.h"
|
2016-11-25 04:33:51 -05:00
|
|
|
#include "esp_attr.h"
|
2022-07-21 07:24:42 -04:00
|
|
|
#include "esp_cpu.h"
|
2022-05-30 04:47:14 -04:00
|
|
|
#include "esp_private/rtc_ctrl.h"
|
2023-05-22 14:57:31 -04:00
|
|
|
#include "soc/interrupts.h"
|
|
|
|
#include "soc/soc_caps.h"
|
|
|
|
#include "sdkconfig.h"
|
2016-11-25 04:33:51 -05:00
|
|
|
|
2019-08-15 03:05:59 -04:00
|
|
|
#if !CONFIG_FREERTOS_UNICORE
|
|
|
|
#include "esp_ipc.h"
|
|
|
|
#endif
|
2016-11-25 04:33:51 -05:00
|
|
|
|
2023-08-14 03:44:24 -04:00
|
|
|
/* For targets that uses a CLIC as their interrupt controller, CPU_INT_LINES_COUNT represents the external interrupts count */
|
|
|
|
#define CPU_INT_LINES_COUNT 32
|
|
|
|
|
2016-11-25 04:33:51 -05:00
|
|
|
static const char* TAG = "intr_alloc";
|
|
|
|
|
|
|
|
#define ETS_INTERNAL_TIMER0_INTR_NO 6
|
|
|
|
#define ETS_INTERNAL_TIMER1_INTR_NO 15
|
|
|
|
#define ETS_INTERNAL_TIMER2_INTR_NO 16
|
|
|
|
#define ETS_INTERNAL_SW0_INTR_NO 7
|
|
|
|
#define ETS_INTERNAL_SW1_INTR_NO 29
|
|
|
|
#define ETS_INTERNAL_PROFILING_INTR_NO 11
|
|
|
|
|
|
|
|
/*
|
|
|
|
Define this to debug the choices made when allocating the interrupt. This leads to much debugging
|
|
|
|
output within a critical region, which can lead to weird effects like e.g. the interrupt watchdog
|
|
|
|
being triggered, that is why it is separate from the normal LOG* scheme.
|
|
|
|
*/
|
2020-12-28 23:31:54 -05:00
|
|
|
// #define DEBUG_INT_ALLOC_DECISIONS
|
|
|
|
|
2016-11-25 04:33:51 -05:00
|
|
|
#ifdef DEBUG_INT_ALLOC_DECISIONS
|
|
|
|
# define ALCHLOG(...) ESP_EARLY_LOGD(TAG, __VA_ARGS__)
|
|
|
|
#else
|
|
|
|
# define ALCHLOG(...) do {} while (0)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
typedef struct shared_vector_desc_t shared_vector_desc_t;
|
|
|
|
typedef struct vector_desc_t vector_desc_t;
|
|
|
|
|
|
|
|
struct shared_vector_desc_t {
|
2016-12-07 08:30:21 -05:00
|
|
|
int disabled: 1;
|
|
|
|
int source: 8;
|
2016-11-25 04:33:51 -05:00
|
|
|
volatile uint32_t *statusreg;
|
|
|
|
uint32_t statusmask;
|
|
|
|
intr_handler_t isr;
|
|
|
|
void *arg;
|
|
|
|
shared_vector_desc_t *next;
|
|
|
|
};
|
|
|
|
|
|
|
|
#define VECDESC_FL_RESERVED (1<<0)
|
|
|
|
#define VECDESC_FL_INIRAM (1<<1)
|
|
|
|
#define VECDESC_FL_SHARED (1<<2)
|
|
|
|
#define VECDESC_FL_NONSHARED (1<<3)
|
|
|
|
|
2016-12-07 08:30:21 -05:00
|
|
|
//Pack using bitfields for better memory use
|
2016-11-25 04:33:51 -05:00
|
|
|
struct vector_desc_t {
|
2022-04-07 22:52:09 -04:00
|
|
|
int flags: 16; //OR of VECDESC_FL_* defines
|
2016-12-07 08:30:21 -05:00
|
|
|
unsigned int cpu: 1;
|
|
|
|
unsigned int intno: 5;
|
|
|
|
int source: 8; //Interrupt mux flags, used when not shared
|
2016-11-25 04:33:51 -05:00
|
|
|
shared_vector_desc_t *shared_vec_info; //used when VECDESC_FL_SHARED
|
|
|
|
vector_desc_t *next;
|
|
|
|
};
|
|
|
|
|
2023-07-12 22:44:06 -04:00
|
|
|
/** Interrupt handler associated data structure */
|
|
|
|
typedef struct intr_handle_data_t {
|
2016-11-25 04:33:51 -05:00
|
|
|
vector_desc_t *vector_desc;
|
|
|
|
shared_vector_desc_t *shared_vector_desc;
|
2023-07-12 22:44:06 -04:00
|
|
|
} intr_handle_data_t;
|
2016-11-25 04:33:51 -05:00
|
|
|
|
2017-03-21 23:07:37 -04:00
|
|
|
typedef struct non_shared_isr_arg_t non_shared_isr_arg_t;
|
|
|
|
|
|
|
|
struct non_shared_isr_arg_t {
|
|
|
|
intr_handler_t isr;
|
|
|
|
void *isr_arg;
|
|
|
|
int source;
|
|
|
|
};
|
2016-11-25 04:33:51 -05:00
|
|
|
|
2023-11-22 04:53:59 -05:00
|
|
|
static esp_err_t intr_free_for_current_cpu(intr_handle_t handle);
|
|
|
|
|
2016-12-07 08:30:21 -05:00
|
|
|
//Linked list of vector descriptions, sorted by cpu.intno value
|
2017-08-18 03:15:47 -04:00
|
|
|
static vector_desc_t *vector_desc_head = NULL;
|
2016-11-25 04:33:51 -05:00
|
|
|
|
|
|
|
//This bitmask has an 1 if the int should be disabled when the flash is disabled.
|
2020-09-29 19:44:12 -04:00
|
|
|
static uint32_t non_iram_int_mask[SOC_CPU_CORES_NUM];
|
|
|
|
|
2016-11-25 04:33:51 -05:00
|
|
|
//This bitmask has 1 in it if the int was disabled using esp_intr_noniram_disable.
|
2020-09-29 19:44:12 -04:00
|
|
|
static uint32_t non_iram_int_disabled[SOC_CPU_CORES_NUM];
|
|
|
|
static bool non_iram_int_disabled_flag[SOC_CPU_CORES_NUM];
|
2016-11-25 04:33:51 -05:00
|
|
|
|
|
|
|
static portMUX_TYPE spinlock = portMUX_INITIALIZER_UNLOCKED;
|
|
|
|
|
|
|
|
//Inserts an item into vector_desc list so that the list is sorted
|
2016-12-07 08:30:21 -05:00
|
|
|
//with an incrementing cpu.intno value.
|
2017-03-21 23:07:37 -04:00
|
|
|
static void insert_vector_desc(vector_desc_t *to_insert)
|
2016-11-25 04:33:51 -05:00
|
|
|
{
|
2022-07-21 07:41:54 -04:00
|
|
|
vector_desc_t *vd = vector_desc_head;
|
|
|
|
vector_desc_t *prev = NULL;
|
|
|
|
while(vd != NULL) {
|
2016-12-07 08:30:21 -05:00
|
|
|
if (vd->cpu > to_insert->cpu) break;
|
|
|
|
if (vd->cpu == to_insert->cpu && vd->intno >= to_insert->intno) break;
|
2022-07-21 07:41:54 -04:00
|
|
|
prev = vd;
|
|
|
|
vd = vd->next;
|
2016-11-25 04:33:51 -05:00
|
|
|
}
|
2022-07-21 07:41:54 -04:00
|
|
|
if ((vector_desc_head == NULL) || (prev == NULL)) {
|
2016-11-25 04:33:51 -05:00
|
|
|
//First item
|
2018-05-12 23:46:09 -04:00
|
|
|
to_insert->next = vd;
|
2022-07-21 07:41:54 -04:00
|
|
|
vector_desc_head = to_insert;
|
2016-11-25 04:33:51 -05:00
|
|
|
} else {
|
2022-07-21 07:41:54 -04:00
|
|
|
prev->next = to_insert;
|
|
|
|
to_insert->next = vd;
|
2016-11-25 04:33:51 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//Returns a vector_desc entry for an intno/cpu, or NULL if none exists.
|
2017-03-21 23:07:37 -04:00
|
|
|
static vector_desc_t *find_desc_for_int(int intno, int cpu)
|
2016-11-25 04:33:51 -05:00
|
|
|
{
|
2022-07-21 07:41:54 -04:00
|
|
|
vector_desc_t *vd = vector_desc_head;
|
|
|
|
while(vd != NULL) {
|
|
|
|
if (vd->cpu == cpu && vd->intno == intno) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
vd = vd->next;
|
2016-11-25 04:33:51 -05:00
|
|
|
}
|
|
|
|
return vd;
|
|
|
|
}
|
|
|
|
|
|
|
|
//Returns a vector_desc entry for an intno/cpu.
|
|
|
|
//Either returns a preexisting one or allocates a new one and inserts
|
2016-12-06 01:20:12 -05:00
|
|
|
//it into the list. Returns NULL on malloc fail.
|
2017-03-21 23:07:37 -04:00
|
|
|
static vector_desc_t *get_desc_for_int(int intno, int cpu)
|
2016-11-25 04:33:51 -05:00
|
|
|
{
|
2022-07-21 07:41:54 -04:00
|
|
|
vector_desc_t *vd = find_desc_for_int(intno, cpu);
|
|
|
|
if (vd == NULL) {
|
|
|
|
vector_desc_t *newvd = heap_caps_malloc(sizeof(vector_desc_t), MALLOC_CAP_INTERNAL | MALLOC_CAP_8BIT);
|
|
|
|
if (newvd == NULL) {
|
|
|
|
return NULL;
|
|
|
|
}
|
2016-11-25 04:33:51 -05:00
|
|
|
memset(newvd, 0, sizeof(vector_desc_t));
|
2022-07-21 07:41:54 -04:00
|
|
|
newvd->intno = intno;
|
|
|
|
newvd->cpu = cpu;
|
2016-11-25 04:33:51 -05:00
|
|
|
insert_vector_desc(newvd);
|
|
|
|
return newvd;
|
|
|
|
} else {
|
|
|
|
return vd;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-08-14 03:44:24 -04:00
|
|
|
//Returns a vector_desc entry for a source, the cpu parameter is used to tell GPIO_INT and GPIO_NMI from different CPUs
|
2017-08-18 03:15:47 -04:00
|
|
|
static vector_desc_t * find_desc_for_source(int source, int cpu)
|
|
|
|
{
|
2022-07-21 07:41:54 -04:00
|
|
|
vector_desc_t *vd = vector_desc_head;
|
|
|
|
while(vd != NULL) {
|
|
|
|
if (!(vd->flags & VECDESC_FL_SHARED)) {
|
|
|
|
if (vd->source == source && cpu == vd->cpu) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
} else if (vd->cpu == cpu) {
|
2017-08-18 03:15:47 -04:00
|
|
|
// check only shared vds for the correct cpu, otherwise skip
|
|
|
|
bool found = false;
|
|
|
|
shared_vector_desc_t *svd = vd->shared_vec_info;
|
2022-07-21 07:41:54 -04:00
|
|
|
assert(svd != NULL);
|
2017-08-18 03:15:47 -04:00
|
|
|
while(svd) {
|
2022-07-21 07:41:54 -04:00
|
|
|
if (svd->source == source) {
|
2017-08-18 03:15:47 -04:00
|
|
|
found = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
svd = svd->next;
|
|
|
|
}
|
2022-07-21 07:41:54 -04:00
|
|
|
if (found) {
|
|
|
|
break;
|
|
|
|
}
|
2017-08-18 03:15:47 -04:00
|
|
|
}
|
2022-07-21 07:41:54 -04:00
|
|
|
vd = vd->next;
|
2017-08-18 03:15:47 -04:00
|
|
|
}
|
|
|
|
return vd;
|
|
|
|
}
|
|
|
|
|
2016-11-25 04:33:51 -05:00
|
|
|
esp_err_t esp_intr_mark_shared(int intno, int cpu, bool is_int_ram)
|
|
|
|
{
|
2022-07-21 07:41:54 -04:00
|
|
|
if (intno>31) {
|
|
|
|
return ESP_ERR_INVALID_ARG;
|
|
|
|
}
|
|
|
|
if (cpu >= SOC_CPU_CORES_NUM) {
|
|
|
|
return ESP_ERR_INVALID_ARG;
|
|
|
|
}
|
2016-11-25 04:33:51 -05:00
|
|
|
|
|
|
|
portENTER_CRITICAL(&spinlock);
|
2022-07-21 07:41:54 -04:00
|
|
|
vector_desc_t *vd = get_desc_for_int(intno, cpu);
|
|
|
|
if (vd == NULL) {
|
2016-12-06 01:20:12 -05:00
|
|
|
portEXIT_CRITICAL(&spinlock);
|
|
|
|
return ESP_ERR_NO_MEM;
|
2017-03-21 23:07:37 -04:00
|
|
|
}
|
2022-07-21 07:41:54 -04:00
|
|
|
vd->flags = VECDESC_FL_SHARED;
|
|
|
|
if (is_int_ram) {
|
|
|
|
vd->flags |= VECDESC_FL_INIRAM;
|
|
|
|
}
|
2016-11-25 04:33:51 -05:00
|
|
|
portEXIT_CRITICAL(&spinlock);
|
|
|
|
|
|
|
|
return ESP_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
esp_err_t esp_intr_reserve(int intno, int cpu)
|
|
|
|
{
|
2022-07-21 07:41:54 -04:00
|
|
|
if (intno > 31) {
|
|
|
|
return ESP_ERR_INVALID_ARG;
|
|
|
|
}
|
|
|
|
if (cpu >= SOC_CPU_CORES_NUM) {
|
|
|
|
return ESP_ERR_INVALID_ARG;
|
|
|
|
}
|
2016-11-25 04:33:51 -05:00
|
|
|
|
|
|
|
portENTER_CRITICAL(&spinlock);
|
2022-07-21 07:41:54 -04:00
|
|
|
vector_desc_t *vd = get_desc_for_int(intno, cpu);
|
|
|
|
if (vd == NULL) {
|
2016-12-06 01:20:12 -05:00
|
|
|
portEXIT_CRITICAL(&spinlock);
|
|
|
|
return ESP_ERR_NO_MEM;
|
2017-03-21 23:07:37 -04:00
|
|
|
}
|
2022-07-21 07:41:54 -04:00
|
|
|
vd->flags = VECDESC_FL_RESERVED;
|
2016-11-25 04:33:51 -05:00
|
|
|
portEXIT_CRITICAL(&spinlock);
|
|
|
|
|
|
|
|
return ESP_OK;
|
|
|
|
}
|
|
|
|
|
2017-08-18 03:15:47 -04:00
|
|
|
static bool is_vect_desc_usable(vector_desc_t *vd, int flags, int cpu, int force)
|
|
|
|
{
|
|
|
|
//Check if interrupt is not reserved by design
|
|
|
|
int x = vd->intno;
|
2022-07-21 07:24:42 -04:00
|
|
|
esp_cpu_intr_desc_t intr_desc;
|
|
|
|
esp_cpu_intr_get_desc(cpu, x, &intr_desc);
|
|
|
|
|
|
|
|
if (intr_desc.flags & ESP_CPU_INTR_DESC_FLAG_RESVD) {
|
2017-08-23 23:46:19 -04:00
|
|
|
ALCHLOG("....Unusable: reserved");
|
2017-08-18 03:15:47 -04:00
|
|
|
return false;
|
|
|
|
}
|
2022-07-21 07:41:54 -04:00
|
|
|
if (intr_desc.flags & ESP_CPU_INTR_DESC_FLAG_SPECIAL && force == -1) {
|
2017-08-23 23:46:19 -04:00
|
|
|
ALCHLOG("....Unusable: special-purpose int");
|
2017-08-18 03:15:47 -04:00
|
|
|
return false;
|
|
|
|
}
|
2020-12-16 12:20:38 -05:00
|
|
|
|
|
|
|
#ifndef SOC_CPU_HAS_FLEXIBLE_INTC
|
2022-07-21 07:41:54 -04:00
|
|
|
//Check if the interrupt priority is acceptable
|
|
|
|
if (!(flags & (1 << intr_desc.priority))) {
|
|
|
|
ALCHLOG("....Unusable: incompatible priority");
|
2020-12-16 12:20:38 -05:00
|
|
|
return false;
|
2017-08-18 03:15:47 -04:00
|
|
|
}
|
|
|
|
//check if edge/level type matches what we want
|
2022-07-21 07:41:54 -04:00
|
|
|
if (((flags & ESP_INTR_FLAG_EDGE) && (intr_desc.type == ESP_CPU_INTR_TYPE_LEVEL)) ||
|
2023-11-22 04:53:59 -05:00
|
|
|
(((!(flags & ESP_INTR_FLAG_EDGE)) && (intr_desc.type == ESP_CPU_INTR_TYPE_EDGE)))) {
|
2020-12-28 23:31:54 -05:00
|
|
|
ALCHLOG("....Unusable: incompatible trigger type");
|
2017-08-18 03:15:47 -04:00
|
|
|
return false;
|
|
|
|
}
|
2020-12-16 12:20:38 -05:00
|
|
|
#endif
|
|
|
|
|
2017-08-18 03:15:47 -04:00
|
|
|
//check if interrupt is reserved at runtime
|
2022-07-21 07:41:54 -04:00
|
|
|
if (vd->flags & VECDESC_FL_RESERVED) {
|
2017-08-23 23:46:19 -04:00
|
|
|
ALCHLOG("....Unusable: reserved at runtime.");
|
2017-08-18 03:15:47 -04:00
|
|
|
return false;
|
|
|
|
}
|
2019-04-08 06:02:05 -04:00
|
|
|
|
2017-08-18 03:15:47 -04:00
|
|
|
//Ints can't be both shared and non-shared.
|
2022-07-21 07:41:54 -04:00
|
|
|
assert(!((vd->flags & VECDESC_FL_SHARED) && (vd->flags & VECDESC_FL_NONSHARED)));
|
2017-08-18 03:15:47 -04:00
|
|
|
//check if interrupt already is in use by a non-shared interrupt
|
2022-07-21 07:41:54 -04:00
|
|
|
if (vd->flags & VECDESC_FL_NONSHARED) {
|
2017-08-23 23:46:19 -04:00
|
|
|
ALCHLOG("....Unusable: already in (non-shared) use.");
|
2017-08-18 03:15:47 -04:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
// check shared interrupt flags
|
2022-07-21 07:41:54 -04:00
|
|
|
if (vd->flags & VECDESC_FL_SHARED) {
|
|
|
|
if (flags & ESP_INTR_FLAG_SHARED) {
|
|
|
|
bool in_iram_flag = ((flags & ESP_INTR_FLAG_IRAM) != 0);
|
|
|
|
bool desc_in_iram_flag = ((vd->flags & VECDESC_FL_INIRAM) != 0);
|
2017-08-18 03:15:47 -04:00
|
|
|
//Bail out if int is shared, but iram property doesn't match what we want.
|
2022-07-21 07:41:54 -04:00
|
|
|
if ((vd->flags & VECDESC_FL_SHARED) && (desc_in_iram_flag != in_iram_flag)) {
|
2017-08-23 23:46:19 -04:00
|
|
|
ALCHLOG("....Unusable: shared but iram prop doesn't match");
|
2017-08-18 03:15:47 -04:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
//We need an unshared IRQ; can't use shared ones; bail out if this is shared.
|
2017-08-23 23:46:19 -04:00
|
|
|
ALCHLOG("...Unusable: int is shared, we need non-shared.");
|
2017-08-18 03:15:47 -04:00
|
|
|
return false;
|
|
|
|
}
|
2022-07-21 07:24:42 -04:00
|
|
|
} else if (esp_cpu_intr_has_handler(x)) {
|
|
|
|
//Check if interrupt already is allocated by esp_cpu_intr_set_handler
|
2017-08-23 23:46:19 -04:00
|
|
|
ALCHLOG("....Unusable: already allocated");
|
2017-08-18 03:15:47 -04:00
|
|
|
return false;
|
|
|
|
}
|
2019-04-08 06:02:05 -04:00
|
|
|
|
2017-08-18 03:15:47 -04:00
|
|
|
return true;
|
|
|
|
}
|
2016-11-25 04:33:51 -05:00
|
|
|
|
|
|
|
//Locate a free interrupt compatible with the flags given.
|
|
|
|
//The 'force' argument can be -1, or 0-31 to force checking a certain interrupt.
|
2022-07-21 07:24:42 -04:00
|
|
|
//When a CPU is forced, the ESP_CPU_INTR_DESC_FLAG_SPECIAL marked interrupts are also accepted.
|
2017-08-18 03:15:47 -04:00
|
|
|
static int get_available_int(int flags, int cpu, int force, int source)
|
2016-11-25 04:33:51 -05:00
|
|
|
{
|
|
|
|
int x;
|
|
|
|
int best=-1;
|
2022-07-21 07:41:54 -04:00
|
|
|
int bestPriority=9;
|
2016-11-25 04:33:51 -05:00
|
|
|
int bestSharedCt=INT_MAX;
|
2020-09-29 19:44:12 -04:00
|
|
|
|
2016-11-25 04:33:51 -05:00
|
|
|
//Default vector desc, for vectors not in the linked list
|
|
|
|
vector_desc_t empty_vect_desc;
|
|
|
|
memset(&empty_vect_desc, 0, sizeof(vector_desc_t));
|
2017-08-18 03:15:47 -04:00
|
|
|
|
2016-11-25 04:33:51 -05:00
|
|
|
//Level defaults to any low/med interrupt
|
2022-07-21 07:41:54 -04:00
|
|
|
if (!(flags & ESP_INTR_FLAG_LEVELMASK)) {
|
|
|
|
flags |= ESP_INTR_FLAG_LOWMED;
|
|
|
|
}
|
2016-11-25 04:33:51 -05:00
|
|
|
|
2017-08-23 23:46:19 -04:00
|
|
|
ALCHLOG("get_available_int: try to find existing. Cpu: %d, Source: %d", cpu, source);
|
2017-08-18 03:15:47 -04:00
|
|
|
vector_desc_t *vd = find_desc_for_source(source, cpu);
|
2022-07-21 07:41:54 -04:00
|
|
|
if (vd) {
|
2017-08-18 03:15:47 -04:00
|
|
|
// if existing vd found, don't need to search any more.
|
2023-08-14 03:44:24 -04:00
|
|
|
ALCHLOG("get_available_int: existing vd found. intno: %d", vd->intno);
|
2017-08-18 03:15:47 -04:00
|
|
|
if ( force != -1 && force != vd->intno ) {
|
2023-08-14 03:44:24 -04:00
|
|
|
ALCHLOG("get_available_int: intr forced but does not match existing. existing intno: %d, force: %d", vd->intno, force);
|
2022-07-21 07:41:54 -04:00
|
|
|
} else if (!is_vect_desc_usable(vd, flags, cpu, force)) {
|
2023-08-14 03:44:24 -04:00
|
|
|
ALCHLOG("get_available_int: existing vd invalid.");
|
2017-08-18 03:15:47 -04:00
|
|
|
} else {
|
|
|
|
best = vd->intno;
|
|
|
|
}
|
|
|
|
return best;
|
|
|
|
}
|
2022-07-21 07:41:54 -04:00
|
|
|
if (force != -1) {
|
2017-08-23 23:46:19 -04:00
|
|
|
ALCHLOG("get_available_int: try to find force. Cpu: %d, Source: %d, Force: %d", cpu, source, force);
|
2017-08-18 03:15:47 -04:00
|
|
|
//if force assigned, don't need to search any more.
|
|
|
|
vd = find_desc_for_int(force, cpu);
|
2022-07-21 07:41:54 -04:00
|
|
|
if (vd == NULL) {
|
2017-08-18 03:15:47 -04:00
|
|
|
//if existing vd not found, just check the default state for the intr.
|
|
|
|
empty_vect_desc.intno = force;
|
2019-04-08 06:02:05 -04:00
|
|
|
vd = &empty_vect_desc;
|
2017-08-18 03:15:47 -04:00
|
|
|
}
|
2022-07-21 07:41:54 -04:00
|
|
|
if (is_vect_desc_usable(vd, flags, cpu, force)) {
|
2017-08-18 03:15:47 -04:00
|
|
|
best = vd->intno;
|
|
|
|
} else {
|
2023-08-14 03:44:24 -04:00
|
|
|
ALCHLOG("get_avalaible_int: forced vd invalid.");
|
2019-04-08 06:02:05 -04:00
|
|
|
}
|
2017-08-18 03:15:47 -04:00
|
|
|
return best;
|
|
|
|
}
|
|
|
|
|
2017-08-23 23:46:19 -04:00
|
|
|
ALCHLOG("get_free_int: start looking. Current cpu: %d", cpu);
|
2023-08-14 03:44:24 -04:00
|
|
|
/* No allocated handlers as well as forced intr, iterate over the 32 possible interrupts */
|
|
|
|
for (x = 0; x < CPU_INT_LINES_COUNT; x++) {
|
2016-11-25 04:33:51 -05:00
|
|
|
//Grab the vector_desc for this vector.
|
2022-07-21 07:41:54 -04:00
|
|
|
vd = find_desc_for_int(x, cpu);
|
|
|
|
if (vd == NULL) {
|
2017-08-18 03:15:47 -04:00
|
|
|
empty_vect_desc.intno = x;
|
2022-07-21 07:41:54 -04:00
|
|
|
vd = &empty_vect_desc;
|
2016-11-25 04:33:51 -05:00
|
|
|
}
|
2017-08-18 03:15:47 -04:00
|
|
|
|
2022-07-21 07:24:42 -04:00
|
|
|
esp_cpu_intr_desc_t intr_desc;
|
|
|
|
esp_cpu_intr_get_desc(cpu, x, &intr_desc);
|
|
|
|
|
2022-07-21 07:41:54 -04:00
|
|
|
ALCHLOG("Int %d reserved %d priority %d %s hasIsr %d",
|
2023-11-22 04:53:59 -05:00
|
|
|
x, intr_desc.flags & ESP_CPU_INTR_DESC_FLAG_RESVD, intr_desc.priority,
|
|
|
|
intr_desc.type == ESP_CPU_INTR_TYPE_LEVEL? "LEVEL" : "EDGE", esp_cpu_intr_has_handler(x));
|
2019-04-08 06:02:05 -04:00
|
|
|
|
2022-07-21 07:41:54 -04:00
|
|
|
if (!is_vect_desc_usable(vd, flags, cpu, force)) {
|
|
|
|
continue;
|
|
|
|
}
|
2017-08-18 03:15:47 -04:00
|
|
|
|
2022-07-21 07:41:54 -04:00
|
|
|
if (flags & ESP_INTR_FLAG_SHARED) {
|
2016-11-25 04:33:51 -05:00
|
|
|
//We're allocating a shared int.
|
2019-04-08 06:02:05 -04:00
|
|
|
|
2016-11-25 04:33:51 -05:00
|
|
|
//See if int already is used as a shared interrupt.
|
2022-07-21 07:41:54 -04:00
|
|
|
if (vd->flags & VECDESC_FL_SHARED) {
|
2016-11-25 04:33:51 -05:00
|
|
|
//We can use this already-marked-as-shared interrupt. Count the already attached isrs in order to see
|
|
|
|
//how useful it is.
|
2022-07-21 07:41:54 -04:00
|
|
|
int no = 0;
|
|
|
|
shared_vector_desc_t *svdesc = vd->shared_vec_info;
|
|
|
|
while (svdesc != NULL) {
|
2016-11-25 04:33:51 -05:00
|
|
|
no++;
|
2022-07-21 07:41:54 -04:00
|
|
|
svdesc = svdesc->next;
|
2016-11-25 04:33:51 -05:00
|
|
|
}
|
2022-07-21 07:41:54 -04:00
|
|
|
if (no<bestSharedCt || bestPriority > intr_desc.priority) {
|
2016-11-25 04:33:51 -05:00
|
|
|
//Seems like this shared vector is both okay and has the least amount of ISRs already attached to it.
|
2022-07-21 07:41:54 -04:00
|
|
|
best = x;
|
|
|
|
bestSharedCt = no;
|
|
|
|
bestPriority = intr_desc.priority;
|
2017-08-23 23:46:19 -04:00
|
|
|
ALCHLOG("...int %d more usable as a shared int: has %d existing vectors", x, no);
|
2016-11-25 04:33:51 -05:00
|
|
|
} else {
|
2017-08-23 23:46:19 -04:00
|
|
|
ALCHLOG("...worse than int %d", best);
|
2016-11-25 04:33:51 -05:00
|
|
|
}
|
|
|
|
} else {
|
2022-07-21 07:41:54 -04:00
|
|
|
if (best == -1) {
|
2017-03-21 23:07:37 -04:00
|
|
|
//We haven't found a feasible shared interrupt yet. This one is still free and usable, even if
|
2016-11-25 04:33:51 -05:00
|
|
|
//not marked as shared.
|
|
|
|
//Remember it in case we don't find any other shared interrupt that qualifies.
|
2022-07-21 07:41:54 -04:00
|
|
|
if (bestPriority > intr_desc.priority) {
|
|
|
|
best = x;
|
|
|
|
bestPriority = intr_desc.priority;
|
2017-08-23 23:46:19 -04:00
|
|
|
ALCHLOG("...int %d usable as a new shared int", x);
|
2016-11-25 04:33:51 -05:00
|
|
|
}
|
|
|
|
} else {
|
2017-08-23 23:46:19 -04:00
|
|
|
ALCHLOG("...already have a shared int");
|
2016-11-25 04:33:51 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
//Seems this interrupt is feasible. Select it and break out of the loop; no need to search further.
|
2022-07-21 07:41:54 -04:00
|
|
|
if (bestPriority > intr_desc.priority) {
|
|
|
|
best = x;
|
|
|
|
bestPriority = intr_desc.priority;
|
2016-11-25 04:33:51 -05:00
|
|
|
} else {
|
2017-08-23 23:46:19 -04:00
|
|
|
ALCHLOG("...worse than int %d", best);
|
2016-11-25 04:33:51 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2017-08-23 23:46:19 -04:00
|
|
|
ALCHLOG("get_available_int: using int %d", best);
|
2016-11-25 04:33:51 -05:00
|
|
|
|
|
|
|
//Okay, by now we have looked at all potential interrupts and hopefully have selected the best one in best.
|
|
|
|
return best;
|
|
|
|
}
|
|
|
|
|
|
|
|
//Common shared isr handler. Chain-call all ISRs.
|
2017-03-21 23:07:37 -04:00
|
|
|
static void IRAM_ATTR shared_intr_isr(void *arg)
|
2016-11-25 04:33:51 -05:00
|
|
|
{
|
2022-07-21 07:41:54 -04:00
|
|
|
vector_desc_t *vd = (vector_desc_t*)arg;
|
|
|
|
shared_vector_desc_t *sh_vec = vd->shared_vec_info;
|
2019-03-25 06:39:55 -04:00
|
|
|
portENTER_CRITICAL_ISR(&spinlock);
|
2016-11-25 04:33:51 -05:00
|
|
|
while(sh_vec) {
|
2016-12-07 08:30:21 -05:00
|
|
|
if (!sh_vec->disabled) {
|
|
|
|
if ((sh_vec->statusreg == NULL) || (*sh_vec->statusreg & sh_vec->statusmask)) {
|
2022-07-21 07:41:54 -04:00
|
|
|
traceISR_ENTER(sh_vec->source + ETS_INTERNAL_INTR_SOURCE_OFF);
|
2016-12-07 08:30:21 -05:00
|
|
|
sh_vec->isr(sh_vec->arg);
|
2017-03-21 23:07:37 -04:00
|
|
|
// check if we will return to scheduler or to interrupted task after ISR
|
2022-07-21 07:24:42 -04:00
|
|
|
if (!os_task_switch_is_pended(esp_cpu_get_core_id())) {
|
2017-03-21 23:07:37 -04:00
|
|
|
traceISR_EXIT();
|
|
|
|
}
|
2016-12-07 08:30:21 -05:00
|
|
|
}
|
2016-11-25 04:33:51 -05:00
|
|
|
}
|
2022-07-21 07:41:54 -04:00
|
|
|
sh_vec = sh_vec->next;
|
2016-11-25 04:33:51 -05:00
|
|
|
}
|
2019-03-25 06:39:55 -04:00
|
|
|
portEXIT_CRITICAL_ISR(&spinlock);
|
2016-11-25 04:33:51 -05:00
|
|
|
}
|
|
|
|
|
2020-12-21 12:17:42 -05:00
|
|
|
#if CONFIG_APPTRACE_SV_ENABLE
|
2017-03-21 23:07:37 -04:00
|
|
|
//Common non-shared isr handler wrapper.
|
|
|
|
static void IRAM_ATTR non_shared_intr_isr(void *arg)
|
|
|
|
{
|
2022-07-21 07:41:54 -04:00
|
|
|
non_shared_isr_arg_t *ns_isr_arg = (non_shared_isr_arg_t*)arg;
|
2019-03-25 06:39:55 -04:00
|
|
|
portENTER_CRITICAL_ISR(&spinlock);
|
2022-07-21 07:41:54 -04:00
|
|
|
traceISR_ENTER(ns_isr_arg->source + ETS_INTERNAL_INTR_SOURCE_OFF);
|
2020-12-21 12:17:42 -05:00
|
|
|
// FIXME: can we call ISR and check os_task_switch_is_pended() after releasing spinlock?
|
|
|
|
// when CONFIG_APPTRACE_SV_ENABLE = 0 ISRs for non-shared IRQs are called without spinlock
|
2017-03-21 23:07:37 -04:00
|
|
|
ns_isr_arg->isr(ns_isr_arg->isr_arg);
|
|
|
|
// check if we will return to scheduler or to interrupted task after ISR
|
2022-07-21 07:24:42 -04:00
|
|
|
if (!os_task_switch_is_pended(esp_cpu_get_core_id())) {
|
2017-03-21 23:07:37 -04:00
|
|
|
traceISR_EXIT();
|
|
|
|
}
|
2019-03-25 06:39:55 -04:00
|
|
|
portEXIT_CRITICAL_ISR(&spinlock);
|
2017-03-21 23:07:37 -04:00
|
|
|
}
|
|
|
|
#endif
|
2016-11-25 04:33:51 -05:00
|
|
|
|
2024-08-02 05:51:15 -04:00
|
|
|
|
|
|
|
bool esp_intr_ptr_in_isr_region(void* ptr)
|
|
|
|
{
|
|
|
|
return esp_ptr_in_iram(ptr) || esp_ptr_in_rtc_iram_fast(ptr) || esp_ptr_in_rom(ptr);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-11-25 04:33:51 -05:00
|
|
|
//We use ESP_EARLY_LOG* here because this can be called before the scheduler is running.
|
2017-03-21 23:07:37 -04:00
|
|
|
esp_err_t esp_intr_alloc_intrstatus(int source, int flags, uint32_t intrstatusreg, uint32_t intrstatusmask, intr_handler_t handler,
|
2023-11-22 04:53:59 -05:00
|
|
|
void *arg, intr_handle_t *ret_handle)
|
2016-11-25 04:33:51 -05:00
|
|
|
{
|
2016-12-07 08:30:21 -05:00
|
|
|
intr_handle_data_t *ret=NULL;
|
2022-07-21 07:41:54 -04:00
|
|
|
int force = -1;
|
2022-07-21 07:24:42 -04:00
|
|
|
ESP_EARLY_LOGV(TAG, "esp_intr_alloc_intrstatus (cpu %u): checking args", esp_cpu_get_core_id());
|
2016-11-25 04:33:51 -05:00
|
|
|
//Shared interrupts should be level-triggered.
|
2022-07-21 07:41:54 -04:00
|
|
|
if ((flags & ESP_INTR_FLAG_SHARED) && (flags & ESP_INTR_FLAG_EDGE)) {
|
|
|
|
return ESP_ERR_INVALID_ARG;
|
|
|
|
}
|
2016-11-25 04:33:51 -05:00
|
|
|
//You can't set an handler / arg for a non-C-callable interrupt.
|
2022-07-21 07:41:54 -04:00
|
|
|
if ((flags & ESP_INTR_FLAG_HIGH) && (handler)) {
|
|
|
|
return ESP_ERR_INVALID_ARG;
|
|
|
|
}
|
2016-12-07 08:30:21 -05:00
|
|
|
//Shared ints should have handler and non-processor-local source
|
2022-07-21 07:41:54 -04:00
|
|
|
if ((flags & ESP_INTR_FLAG_SHARED) && (!handler || source<0)) {
|
|
|
|
return ESP_ERR_INVALID_ARG;
|
|
|
|
}
|
2016-11-25 04:33:51 -05:00
|
|
|
//Statusreg should have a mask
|
2022-07-21 07:41:54 -04:00
|
|
|
if (intrstatusreg && !intrstatusmask) {
|
|
|
|
return ESP_ERR_INVALID_ARG;
|
|
|
|
}
|
2017-01-10 12:14:18 -05:00
|
|
|
//If the ISR is marked to be IRAM-resident, the handler must not be in the cached region
|
2019-04-08 06:02:05 -04:00
|
|
|
//ToDo: if we are to allow placing interrupt handlers into the 0x400c0000—0x400c2000 region,
|
|
|
|
//we need to make sure the interrupt is connected to the CPU0.
|
|
|
|
//CPU1 does not have access to the RTC fast memory through this region.
|
2024-08-02 05:51:15 -04:00
|
|
|
if ((flags & ESP_INTR_FLAG_IRAM) && handler && !esp_intr_ptr_in_isr_region(handler)) {
|
2017-01-10 12:14:18 -05:00
|
|
|
return ESP_ERR_INVALID_ARG;
|
|
|
|
}
|
2016-11-25 04:33:51 -05:00
|
|
|
|
|
|
|
//Default to prio 1 for shared interrupts. Default to prio 1, 2 or 3 for non-shared interrupts.
|
2022-07-21 07:41:54 -04:00
|
|
|
if ((flags & ESP_INTR_FLAG_LEVELMASK) == 0) {
|
|
|
|
if (flags & ESP_INTR_FLAG_SHARED) {
|
|
|
|
flags |= ESP_INTR_FLAG_LEVEL1;
|
2016-11-25 04:33:51 -05:00
|
|
|
} else {
|
2022-07-21 07:41:54 -04:00
|
|
|
flags |= ESP_INTR_FLAG_LOWMED;
|
2016-11-25 04:33:51 -05:00
|
|
|
}
|
|
|
|
}
|
2022-07-21 07:24:42 -04:00
|
|
|
ESP_EARLY_LOGV(TAG, "esp_intr_alloc_intrstatus (cpu %u): Args okay. Resulting flags 0x%X", esp_cpu_get_core_id(), flags);
|
2017-03-21 23:07:37 -04:00
|
|
|
|
2016-11-25 04:33:51 -05:00
|
|
|
//Check 'special' interrupt sources. These are tied to one specific interrupt, so we
|
|
|
|
//have to force get_free_int to only look at that.
|
2022-07-21 07:41:54 -04:00
|
|
|
if (source == ETS_INTERNAL_TIMER0_INTR_SOURCE) {
|
|
|
|
force = ETS_INTERNAL_TIMER0_INTR_NO;
|
|
|
|
}
|
|
|
|
if (source == ETS_INTERNAL_TIMER1_INTR_SOURCE) {
|
|
|
|
force = ETS_INTERNAL_TIMER1_INTR_NO;
|
|
|
|
}
|
|
|
|
if (source == ETS_INTERNAL_TIMER2_INTR_SOURCE) {
|
|
|
|
force = ETS_INTERNAL_TIMER2_INTR_NO;
|
|
|
|
}
|
|
|
|
if (source == ETS_INTERNAL_SW0_INTR_SOURCE) {
|
|
|
|
force = ETS_INTERNAL_SW0_INTR_NO;
|
|
|
|
}
|
|
|
|
if (source == ETS_INTERNAL_SW1_INTR_SOURCE) {
|
|
|
|
force = ETS_INTERNAL_SW1_INTR_NO;
|
|
|
|
}
|
|
|
|
if (source == ETS_INTERNAL_PROFILING_INTR_SOURCE) {
|
|
|
|
force = ETS_INTERNAL_PROFILING_INTR_NO;
|
|
|
|
}
|
2016-11-25 04:33:51 -05:00
|
|
|
|
2016-12-07 08:30:21 -05:00
|
|
|
//Allocate a return handle. If we end up not needing it, we'll free it later on.
|
2022-07-21 07:41:54 -04:00
|
|
|
ret = heap_caps_malloc(sizeof(intr_handle_data_t), MALLOC_CAP_INTERNAL | MALLOC_CAP_8BIT);
|
|
|
|
if (ret == NULL) {
|
|
|
|
return ESP_ERR_NO_MEM;
|
|
|
|
}
|
2016-12-06 01:20:12 -05:00
|
|
|
|
2016-11-25 04:33:51 -05:00
|
|
|
portENTER_CRITICAL(&spinlock);
|
2022-07-21 07:24:42 -04:00
|
|
|
uint32_t cpu = esp_cpu_get_core_id();
|
2016-11-25 04:33:51 -05:00
|
|
|
//See if we can find an interrupt that matches the flags.
|
2022-07-21 07:41:54 -04:00
|
|
|
int intr = get_available_int(flags, cpu, force, source);
|
|
|
|
if (intr == -1) {
|
2016-11-25 04:33:51 -05:00
|
|
|
//None found. Bail out.
|
|
|
|
portEXIT_CRITICAL(&spinlock);
|
2016-12-06 01:20:12 -05:00
|
|
|
free(ret);
|
2023-07-12 05:28:45 -04:00
|
|
|
ESP_LOGE(TAG, "No free interrupt inputs for %s interrupt (flags 0x%X)", esp_isr_names[source], flags);
|
2016-11-25 04:33:51 -05:00
|
|
|
return ESP_ERR_NOT_FOUND;
|
|
|
|
}
|
|
|
|
//Get an int vector desc for int.
|
2022-07-21 07:41:54 -04:00
|
|
|
vector_desc_t *vd = get_desc_for_int(intr, cpu);
|
|
|
|
if (vd == NULL) {
|
2016-12-06 01:20:12 -05:00
|
|
|
portEXIT_CRITICAL(&spinlock);
|
|
|
|
free(ret);
|
|
|
|
return ESP_ERR_NO_MEM;
|
|
|
|
}
|
2016-11-25 04:33:51 -05:00
|
|
|
|
|
|
|
//Allocate that int!
|
2022-07-21 07:41:54 -04:00
|
|
|
if (flags & ESP_INTR_FLAG_SHARED) {
|
2016-11-25 04:33:51 -05:00
|
|
|
//Populate vector entry and add to linked list.
|
2023-09-20 23:41:06 -04:00
|
|
|
shared_vector_desc_t *sh_vec = heap_caps_malloc(sizeof(shared_vector_desc_t), MALLOC_CAP_INTERNAL | MALLOC_CAP_8BIT);
|
2022-07-21 07:41:54 -04:00
|
|
|
if (sh_vec == NULL) {
|
2016-12-06 01:20:12 -05:00
|
|
|
portEXIT_CRITICAL(&spinlock);
|
|
|
|
free(ret);
|
|
|
|
return ESP_ERR_NO_MEM;
|
|
|
|
}
|
2016-11-25 04:33:51 -05:00
|
|
|
memset(sh_vec, 0, sizeof(shared_vector_desc_t));
|
2022-07-21 07:41:54 -04:00
|
|
|
sh_vec->statusreg = (uint32_t*)intrstatusreg;
|
|
|
|
sh_vec->statusmask = intrstatusmask;
|
|
|
|
sh_vec->isr = handler;
|
|
|
|
sh_vec->arg = arg;
|
|
|
|
sh_vec->next = vd->shared_vec_info;
|
|
|
|
sh_vec->source = source;
|
|
|
|
sh_vec->disabled = 0;
|
|
|
|
vd->shared_vec_info = sh_vec;
|
|
|
|
vd->flags |= VECDESC_FL_SHARED;
|
2016-11-25 04:33:51 -05:00
|
|
|
//(Re-)set shared isr handler to new value.
|
2022-07-21 07:24:42 -04:00
|
|
|
esp_cpu_intr_set_handler(intr, (esp_cpu_intr_handler_t)shared_intr_isr, vd);
|
2016-11-25 04:33:51 -05:00
|
|
|
} else {
|
|
|
|
//Mark as unusable for other interrupt sources. This is ours now!
|
2022-07-21 07:41:54 -04:00
|
|
|
vd->flags = VECDESC_FL_NONSHARED;
|
2016-11-25 04:33:51 -05:00
|
|
|
if (handler) {
|
2020-12-21 12:17:42 -05:00
|
|
|
#if CONFIG_APPTRACE_SV_ENABLE
|
2023-09-20 23:41:06 -04:00
|
|
|
non_shared_isr_arg_t *ns_isr_arg = heap_caps_malloc(sizeof(non_shared_isr_arg_t), MALLOC_CAP_INTERNAL | MALLOC_CAP_8BIT);
|
2017-03-21 23:07:37 -04:00
|
|
|
if (!ns_isr_arg) {
|
|
|
|
portEXIT_CRITICAL(&spinlock);
|
|
|
|
free(ret);
|
|
|
|
return ESP_ERR_NO_MEM;
|
|
|
|
}
|
2022-07-21 07:41:54 -04:00
|
|
|
ns_isr_arg->isr = handler;
|
|
|
|
ns_isr_arg->isr_arg = arg;
|
|
|
|
ns_isr_arg->source = source;
|
2022-07-21 07:24:42 -04:00
|
|
|
esp_cpu_intr_set_handler(intr, (esp_cpu_intr_handler_t)non_shared_intr_isr, ns_isr_arg);
|
2017-03-21 23:07:37 -04:00
|
|
|
#else
|
2022-07-21 07:24:42 -04:00
|
|
|
esp_cpu_intr_set_handler(intr, (esp_cpu_intr_handler_t)handler, arg);
|
2017-03-21 23:07:37 -04:00
|
|
|
#endif
|
2016-11-25 04:33:51 -05:00
|
|
|
}
|
2020-11-11 11:21:49 -05:00
|
|
|
|
2020-12-29 00:20:24 -05:00
|
|
|
if (flags & ESP_INTR_FLAG_EDGE) {
|
2022-07-21 07:24:42 -04:00
|
|
|
esp_cpu_intr_edge_ack(intr);
|
2020-12-28 23:31:54 -05:00
|
|
|
}
|
2020-11-11 11:21:49 -05:00
|
|
|
|
2022-07-21 07:41:54 -04:00
|
|
|
vd->source = source;
|
2016-11-25 04:33:51 -05:00
|
|
|
}
|
2022-07-21 07:41:54 -04:00
|
|
|
if (flags & ESP_INTR_FLAG_IRAM) {
|
|
|
|
vd->flags |= VECDESC_FL_INIRAM;
|
|
|
|
non_iram_int_mask[cpu] &= ~(1<<intr);
|
2016-11-25 04:33:51 -05:00
|
|
|
} else {
|
2022-07-21 07:41:54 -04:00
|
|
|
vd->flags &= ~VECDESC_FL_INIRAM;
|
|
|
|
non_iram_int_mask[cpu] |= (1<<intr);
|
2016-11-25 04:33:51 -05:00
|
|
|
}
|
|
|
|
if (source>=0) {
|
2022-01-17 04:44:25 -05:00
|
|
|
esp_rom_route_intr_matrix(cpu, source, intr);
|
2016-11-25 04:33:51 -05:00
|
|
|
}
|
2016-12-07 08:30:21 -05:00
|
|
|
|
|
|
|
//Fill return handle data.
|
2022-07-21 07:41:54 -04:00
|
|
|
ret->vector_desc = vd;
|
|
|
|
ret->shared_vector_desc = vd->shared_vec_info;
|
2016-12-07 08:30:21 -05:00
|
|
|
|
|
|
|
//Enable int at CPU-level;
|
|
|
|
ESP_INTR_ENABLE(intr);
|
|
|
|
|
|
|
|
//If interrupt has to be started disabled, do that now; ints won't be enabled for real until the end
|
|
|
|
//of the critical section.
|
2022-07-21 07:41:54 -04:00
|
|
|
if (flags & ESP_INTR_FLAG_INTRDISABLED) {
|
2016-12-07 08:30:21 -05:00
|
|
|
esp_intr_disable(ret);
|
|
|
|
}
|
|
|
|
|
2024-03-11 23:01:51 -04:00
|
|
|
#if SOC_CPU_HAS_FLEXIBLE_INTC
|
2020-11-19 13:14:54 -05:00
|
|
|
//Extract the level from the interrupt passed flags
|
2020-12-28 23:31:54 -05:00
|
|
|
int level = esp_intr_flags_to_level(flags);
|
2022-07-21 07:24:42 -04:00
|
|
|
esp_cpu_intr_set_priority(intr, level);
|
2020-11-11 11:21:49 -05:00
|
|
|
|
2020-11-19 13:14:54 -05:00
|
|
|
if (flags & ESP_INTR_FLAG_EDGE) {
|
2022-07-21 07:24:42 -04:00
|
|
|
esp_cpu_intr_set_type(intr, ESP_CPU_INTR_TYPE_EDGE);
|
2020-11-19 13:14:54 -05:00
|
|
|
} else {
|
2022-07-21 07:24:42 -04:00
|
|
|
esp_cpu_intr_set_type(intr, ESP_CPU_INTR_TYPE_LEVEL);
|
2020-11-19 13:14:54 -05:00
|
|
|
}
|
2020-12-16 12:20:38 -05:00
|
|
|
#endif
|
2020-12-30 02:33:03 -05:00
|
|
|
|
2024-03-11 23:01:51 -04:00
|
|
|
#if SOC_INT_PLIC_SUPPORTED
|
|
|
|
/* Make sure the interrupt is not delegated to user mode (IDF uses machine mode only) */
|
|
|
|
RV_CLEAR_CSR(mideleg, BIT(intr));
|
|
|
|
#endif
|
|
|
|
|
2016-12-07 08:30:21 -05:00
|
|
|
portEXIT_CRITICAL(&spinlock);
|
|
|
|
|
|
|
|
//Fill return handle if needed, otherwise free handle.
|
2022-07-21 07:41:54 -04:00
|
|
|
if (ret_handle != NULL) {
|
|
|
|
*ret_handle = ret;
|
2016-12-07 08:30:21 -05:00
|
|
|
} else {
|
|
|
|
free(ret);
|
2016-11-25 04:33:51 -05:00
|
|
|
}
|
|
|
|
|
2023-09-13 07:15:53 -04:00
|
|
|
ESP_EARLY_LOGD(TAG, "Connected src %d to int %d (cpu %"PRIu32")", source, intr, cpu);
|
2016-11-25 04:33:51 -05:00
|
|
|
return ESP_OK;
|
|
|
|
}
|
|
|
|
|
2017-03-21 23:07:37 -04:00
|
|
|
esp_err_t esp_intr_alloc(int source, int flags, intr_handler_t handler, void *arg, intr_handle_t *ret_handle)
|
2016-11-25 04:33:51 -05:00
|
|
|
{
|
|
|
|
/*
|
|
|
|
As an optimization, we can create a table with the possible interrupt status registers and masks for every single
|
2017-03-21 23:07:37 -04:00
|
|
|
source there is. We can then add code here to look up an applicable value and pass that to the
|
2016-11-25 04:33:51 -05:00
|
|
|
esp_intr_alloc_intrstatus function.
|
|
|
|
*/
|
|
|
|
return esp_intr_alloc_intrstatus(source, flags, 0, 0, handler, arg, ret_handle);
|
|
|
|
}
|
|
|
|
|
2017-11-09 06:21:39 -05:00
|
|
|
esp_err_t IRAM_ATTR esp_intr_set_in_iram(intr_handle_t handle, bool is_in_iram)
|
|
|
|
{
|
2022-07-21 07:41:54 -04:00
|
|
|
if (!handle) {
|
|
|
|
return ESP_ERR_INVALID_ARG;
|
|
|
|
}
|
2017-11-09 06:21:39 -05:00
|
|
|
vector_desc_t *vd = handle->vector_desc;
|
|
|
|
if (vd->flags & VECDESC_FL_SHARED) {
|
2023-11-22 04:53:59 -05:00
|
|
|
return ESP_ERR_INVALID_ARG;
|
2017-11-09 06:21:39 -05:00
|
|
|
}
|
|
|
|
portENTER_CRITICAL(&spinlock);
|
|
|
|
uint32_t mask = (1 << vd->intno);
|
|
|
|
if (is_in_iram) {
|
|
|
|
vd->flags |= VECDESC_FL_INIRAM;
|
|
|
|
non_iram_int_mask[vd->cpu] &= ~mask;
|
|
|
|
} else {
|
|
|
|
vd->flags &= ~VECDESC_FL_INIRAM;
|
|
|
|
non_iram_int_mask[vd->cpu] |= mask;
|
|
|
|
}
|
|
|
|
portEXIT_CRITICAL(&spinlock);
|
|
|
|
return ESP_OK;
|
|
|
|
}
|
2016-11-25 04:33:51 -05:00
|
|
|
|
2019-08-15 03:05:59 -04:00
|
|
|
#if !CONFIG_FREERTOS_UNICORE
|
2023-11-22 04:53:59 -05:00
|
|
|
static void intr_free_for_other_cpu(void *arg)
|
2018-10-13 02:38:48 -04:00
|
|
|
{
|
2023-11-22 04:53:59 -05:00
|
|
|
(void)intr_free_for_current_cpu((intr_handle_t)arg);
|
2018-10-13 02:38:48 -04:00
|
|
|
}
|
2019-08-15 03:05:59 -04:00
|
|
|
#endif /* !CONFIG_FREERTOS_UNICORE */
|
2018-10-13 02:38:48 -04:00
|
|
|
|
2017-03-21 23:07:37 -04:00
|
|
|
esp_err_t esp_intr_free(intr_handle_t handle)
|
2016-11-25 04:33:51 -05:00
|
|
|
{
|
2022-07-21 07:41:54 -04:00
|
|
|
if (!handle) {
|
|
|
|
return ESP_ERR_INVALID_ARG;
|
|
|
|
}
|
2019-08-15 03:05:59 -04:00
|
|
|
|
|
|
|
#if !CONFIG_FREERTOS_UNICORE
|
2018-09-20 00:13:43 -04:00
|
|
|
//Assign this routine to the core where this interrupt is allocated on.
|
2023-11-22 04:53:59 -05:00
|
|
|
|
|
|
|
bool task_can_be_run_on_any_core;
|
|
|
|
#if CONFIG_FREERTOS_SMP
|
|
|
|
UBaseType_t core_affinity = vTaskCoreAffinityGet(NULL);
|
|
|
|
task_can_be_run_on_any_core = (__builtin_popcount(core_affinity) > 1);
|
|
|
|
#else
|
|
|
|
UBaseType_t core_affinity = xTaskGetCoreID(NULL);
|
|
|
|
task_can_be_run_on_any_core = (core_affinity == tskNO_AFFINITY);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if (task_can_be_run_on_any_core || handle->vector_desc->cpu != esp_cpu_get_core_id()) {
|
|
|
|
// If the task can be run on any core then we can not rely on the current CPU id (in case if task switching occurs).
|
|
|
|
// It is safer to call intr_free_for_current_cpu() from a pinned to a certain CPU task. It is done through the IPC call.
|
|
|
|
esp_err_t ret = esp_ipc_call_blocking(handle->vector_desc->cpu, &intr_free_for_other_cpu, (void *)handle);
|
2018-09-20 00:13:43 -04:00
|
|
|
return ret == ESP_OK ? ESP_OK : ESP_FAIL;
|
|
|
|
}
|
2019-08-15 03:05:59 -04:00
|
|
|
#endif /* !CONFIG_FREERTOS_UNICORE */
|
|
|
|
|
2023-11-22 04:53:59 -05:00
|
|
|
return intr_free_for_current_cpu(handle);
|
|
|
|
}
|
|
|
|
|
|
|
|
static esp_err_t intr_free_for_current_cpu(intr_handle_t handle)
|
|
|
|
{
|
|
|
|
bool free_shared_vector = false;
|
|
|
|
|
2016-11-25 04:33:51 -05:00
|
|
|
portENTER_CRITICAL(&spinlock);
|
2016-12-07 23:04:26 -05:00
|
|
|
esp_intr_disable(handle);
|
2022-07-21 07:41:54 -04:00
|
|
|
if (handle->vector_desc->flags & VECDESC_FL_SHARED) {
|
2017-03-21 23:07:37 -04:00
|
|
|
//Find and kill the shared int
|
2022-07-21 07:41:54 -04:00
|
|
|
shared_vector_desc_t *svd = handle->vector_desc->shared_vec_info;
|
|
|
|
shared_vector_desc_t *prevsvd = NULL;
|
2016-11-25 04:33:51 -05:00
|
|
|
assert(svd); //should be something in there for a shared int
|
2022-07-21 07:41:54 -04:00
|
|
|
while (svd != NULL) {
|
|
|
|
if (svd == handle->shared_vector_desc) {
|
2016-11-25 04:33:51 -05:00
|
|
|
//Found it. Now kill it.
|
|
|
|
if (prevsvd) {
|
2022-07-21 07:41:54 -04:00
|
|
|
prevsvd->next = svd->next;
|
2016-11-25 04:33:51 -05:00
|
|
|
} else {
|
2022-07-21 07:41:54 -04:00
|
|
|
handle->vector_desc->shared_vec_info = svd->next;
|
2016-11-25 04:33:51 -05:00
|
|
|
}
|
|
|
|
free(svd);
|
|
|
|
break;
|
|
|
|
}
|
2022-07-21 07:41:54 -04:00
|
|
|
prevsvd = svd;
|
|
|
|
svd = svd->next;
|
2016-11-25 04:33:51 -05:00
|
|
|
}
|
|
|
|
//If nothing left, disable interrupt.
|
2022-07-21 07:41:54 -04:00
|
|
|
if (handle->vector_desc->shared_vec_info == NULL) {
|
|
|
|
free_shared_vector = true;
|
|
|
|
}
|
|
|
|
ESP_EARLY_LOGV(TAG,
|
|
|
|
"esp_intr_free: Deleting shared int: %s. Shared int is %s",
|
|
|
|
svd ? "not found or last one" : "deleted",
|
|
|
|
free_shared_vector ? "empty now." : "still in use");
|
2016-11-25 04:33:51 -05:00
|
|
|
}
|
|
|
|
|
2022-07-21 07:41:54 -04:00
|
|
|
if ((handle->vector_desc->flags & VECDESC_FL_NONSHARED) || free_shared_vector) {
|
2019-12-18 04:11:24 -05:00
|
|
|
ESP_EARLY_LOGV(TAG, "esp_intr_free: Disabling int, killing handler");
|
2020-12-21 12:17:42 -05:00
|
|
|
#if CONFIG_APPTRACE_SV_ENABLE
|
2017-03-21 23:07:37 -04:00
|
|
|
if (!free_shared_vector) {
|
2022-07-21 07:24:42 -04:00
|
|
|
void *isr_arg = esp_cpu_intr_get_handler_arg(handle->vector_desc->intno);
|
2017-03-21 23:07:37 -04:00
|
|
|
if (isr_arg) {
|
|
|
|
free(isr_arg);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
2020-09-29 19:44:12 -04:00
|
|
|
//Reset to normal handler:
|
2022-07-21 07:24:42 -04:00
|
|
|
esp_cpu_intr_set_handler(handle->vector_desc->intno, NULL, (void*)((int)handle->vector_desc->intno));
|
2016-11-25 04:33:51 -05:00
|
|
|
//Theoretically, we could free the vector_desc... not sure if that's worth the few bytes of memory
|
2017-03-21 23:07:37 -04:00
|
|
|
//we save.(We can also not use the same exit path for empty shared ints anymore if we delete
|
|
|
|
//the desc.) For now, just mark it as free.
|
2022-07-21 07:41:54 -04:00
|
|
|
handle->vector_desc->flags &= ~(VECDESC_FL_NONSHARED|VECDESC_FL_RESERVED|VECDESC_FL_SHARED);
|
2022-11-04 02:01:22 -04:00
|
|
|
handle->vector_desc->source = ETS_INTERNAL_UNUSED_INTR_SOURCE;
|
|
|
|
|
2016-11-25 04:33:51 -05:00
|
|
|
//Also kill non_iram mask bit.
|
2022-07-21 07:41:54 -04:00
|
|
|
non_iram_int_mask[handle->vector_desc->cpu] &= ~(1<<(handle->vector_desc->intno));
|
2016-11-25 04:33:51 -05:00
|
|
|
}
|
|
|
|
portEXIT_CRITICAL(&spinlock);
|
|
|
|
free(handle);
|
|
|
|
return ESP_OK;
|
|
|
|
}
|
|
|
|
|
2016-12-07 08:30:21 -05:00
|
|
|
int esp_intr_get_intno(intr_handle_t handle)
|
2016-11-25 04:33:51 -05:00
|
|
|
{
|
2016-12-07 08:30:21 -05:00
|
|
|
return handle->vector_desc->intno;
|
2016-11-25 04:33:51 -05:00
|
|
|
}
|
|
|
|
|
2016-12-07 08:30:21 -05:00
|
|
|
int esp_intr_get_cpu(intr_handle_t handle)
|
2016-11-25 04:33:51 -05:00
|
|
|
{
|
2016-12-07 08:30:21 -05:00
|
|
|
return handle->vector_desc->cpu;
|
2016-11-25 04:33:51 -05:00
|
|
|
}
|
|
|
|
|
2016-12-07 08:30:21 -05:00
|
|
|
/*
|
|
|
|
Interrupt disabling strategy:
|
|
|
|
If the source is >=0 (meaning a muxed interrupt), we disable it by muxing the interrupt to a non-connected
|
|
|
|
interrupt. If the source is <0 (meaning an internal, per-cpu interrupt), we disable it using ESP_INTR_DISABLE.
|
|
|
|
This allows us to, for the muxed CPUs, disable an int from the other core. It also allows disabling shared
|
|
|
|
interrupts.
|
|
|
|
*/
|
|
|
|
|
|
|
|
//Muxing an interrupt source to interrupt 6, 7, 11, 15, 16 or 29 cause the interrupt to effectively be disabled.
|
|
|
|
#define INT_MUX_DISABLED_INTNO 6
|
|
|
|
|
2016-12-19 01:28:28 -05:00
|
|
|
esp_err_t IRAM_ATTR esp_intr_enable(intr_handle_t handle)
|
2016-11-25 04:33:51 -05:00
|
|
|
{
|
2022-07-21 07:41:54 -04:00
|
|
|
if (!handle) {
|
|
|
|
return ESP_ERR_INVALID_ARG;
|
|
|
|
}
|
2019-03-25 06:39:55 -04:00
|
|
|
portENTER_CRITICAL_SAFE(&spinlock);
|
2016-12-07 08:30:21 -05:00
|
|
|
int source;
|
|
|
|
if (handle->shared_vector_desc) {
|
2022-07-21 07:41:54 -04:00
|
|
|
handle->shared_vector_desc->disabled = 0;
|
2016-12-07 08:30:21 -05:00
|
|
|
source=handle->shared_vector_desc->source;
|
|
|
|
} else {
|
|
|
|
source=handle->vector_desc->source;
|
|
|
|
}
|
|
|
|
if (source >= 0) {
|
|
|
|
//Disabled using int matrix; re-connect to enable
|
2022-01-17 04:44:25 -05:00
|
|
|
esp_rom_route_intr_matrix(handle->vector_desc->cpu, source, handle->vector_desc->intno);
|
2016-12-07 08:30:21 -05:00
|
|
|
} else {
|
|
|
|
//Re-enable using cpu int ena reg
|
2022-07-21 07:41:54 -04:00
|
|
|
if (handle->vector_desc->cpu != esp_cpu_get_core_id()) {
|
2022-09-27 03:37:06 -04:00
|
|
|
portEXIT_CRITICAL_SAFE(&spinlock);
|
2022-07-21 07:41:54 -04:00
|
|
|
return ESP_ERR_INVALID_ARG; //Can only enable these ints on this cpu
|
|
|
|
}
|
2016-12-07 08:30:21 -05:00
|
|
|
ESP_INTR_ENABLE(handle->vector_desc->intno);
|
|
|
|
}
|
2019-03-25 06:39:55 -04:00
|
|
|
portEXIT_CRITICAL_SAFE(&spinlock);
|
2016-11-25 04:33:51 -05:00
|
|
|
return ESP_OK;
|
|
|
|
}
|
|
|
|
|
2016-12-19 01:28:28 -05:00
|
|
|
esp_err_t IRAM_ATTR esp_intr_disable(intr_handle_t handle)
|
2016-11-25 04:33:51 -05:00
|
|
|
{
|
2023-08-14 03:44:24 -04:00
|
|
|
if (handle == NULL) {
|
2022-07-21 07:41:54 -04:00
|
|
|
return ESP_ERR_INVALID_ARG;
|
|
|
|
}
|
2023-08-14 03:44:24 -04:00
|
|
|
|
2019-03-25 06:39:55 -04:00
|
|
|
portENTER_CRITICAL_SAFE(&spinlock);
|
2016-12-07 08:30:21 -05:00
|
|
|
int source;
|
2023-08-14 03:44:24 -04:00
|
|
|
bool disabled = true;
|
2016-12-07 08:30:21 -05:00
|
|
|
if (handle->shared_vector_desc) {
|
2022-07-21 07:41:54 -04:00
|
|
|
handle->shared_vector_desc->disabled = 1;
|
2016-12-07 08:30:21 -05:00
|
|
|
source=handle->shared_vector_desc->source;
|
2017-08-18 03:15:47 -04:00
|
|
|
|
2022-07-21 07:41:54 -04:00
|
|
|
shared_vector_desc_t *svd = handle->vector_desc->shared_vec_info;
|
|
|
|
assert(svd != NULL);
|
|
|
|
while(svd) {
|
2023-08-14 03:44:24 -04:00
|
|
|
if (svd->source == source && !svd->disabled) {
|
|
|
|
disabled = false;
|
2017-08-18 03:15:47 -04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
svd = svd->next;
|
|
|
|
}
|
2016-12-07 08:30:21 -05:00
|
|
|
} else {
|
|
|
|
source=handle->vector_desc->source;
|
|
|
|
}
|
2017-08-18 03:15:47 -04:00
|
|
|
|
2016-12-07 08:30:21 -05:00
|
|
|
if (source >= 0) {
|
2022-07-21 07:41:54 -04:00
|
|
|
if (disabled) {
|
2017-08-18 03:15:47 -04:00
|
|
|
//Disable using int matrix
|
2022-01-17 04:44:25 -05:00
|
|
|
esp_rom_route_intr_matrix(handle->vector_desc->cpu, source, INT_MUX_DISABLED_INTNO);
|
2017-08-18 03:15:47 -04:00
|
|
|
}
|
2016-12-07 08:30:21 -05:00
|
|
|
} else {
|
|
|
|
//Disable using per-cpu regs
|
2022-07-21 07:41:54 -04:00
|
|
|
if (handle->vector_desc->cpu != esp_cpu_get_core_id()) {
|
2019-10-20 01:23:47 -04:00
|
|
|
portEXIT_CRITICAL_SAFE(&spinlock);
|
2016-12-07 08:30:21 -05:00
|
|
|
return ESP_ERR_INVALID_ARG; //Can only enable these ints on this cpu
|
|
|
|
}
|
|
|
|
ESP_INTR_DISABLE(handle->vector_desc->intno);
|
|
|
|
}
|
2019-03-25 06:39:55 -04:00
|
|
|
portEXIT_CRITICAL_SAFE(&spinlock);
|
2016-11-25 04:33:51 -05:00
|
|
|
return ESP_OK;
|
|
|
|
}
|
|
|
|
|
2019-07-16 05:33:30 -04:00
|
|
|
void IRAM_ATTR esp_intr_noniram_disable(void)
|
2016-11-25 04:33:51 -05:00
|
|
|
{
|
2021-02-23 23:07:11 -05:00
|
|
|
portENTER_CRITICAL_SAFE(&spinlock);
|
2020-09-29 19:44:12 -04:00
|
|
|
uint32_t oldint;
|
2022-07-21 07:24:42 -04:00
|
|
|
uint32_t cpu = esp_cpu_get_core_id();
|
2021-02-23 23:07:11 -05:00
|
|
|
uint32_t non_iram_ints = non_iram_int_mask[cpu];
|
|
|
|
if (non_iram_int_disabled_flag[cpu]) {
|
|
|
|
abort();
|
|
|
|
}
|
|
|
|
non_iram_int_disabled_flag[cpu] = true;
|
2022-07-21 07:24:42 -04:00
|
|
|
oldint = esp_cpu_intr_get_enabled_mask();
|
|
|
|
esp_cpu_intr_disable(non_iram_ints);
|
2022-05-30 04:47:14 -04:00
|
|
|
// Disable the RTC bit which don't want to be put in IRAM.
|
|
|
|
rtc_isr_noniram_disable(cpu);
|
2021-02-23 23:07:11 -05:00
|
|
|
// Save disabled ints
|
|
|
|
non_iram_int_disabled[cpu] = oldint & non_iram_ints;
|
|
|
|
portEXIT_CRITICAL_SAFE(&spinlock);
|
2016-11-25 04:33:51 -05:00
|
|
|
}
|
|
|
|
|
2019-07-16 05:33:30 -04:00
|
|
|
void IRAM_ATTR esp_intr_noniram_enable(void)
|
2016-11-25 04:33:51 -05:00
|
|
|
{
|
2021-02-23 23:07:11 -05:00
|
|
|
portENTER_CRITICAL_SAFE(&spinlock);
|
2022-07-21 07:24:42 -04:00
|
|
|
uint32_t cpu = esp_cpu_get_core_id();
|
2021-02-23 23:07:11 -05:00
|
|
|
int non_iram_ints = non_iram_int_disabled[cpu];
|
|
|
|
if (!non_iram_int_disabled_flag[cpu]) {
|
|
|
|
abort();
|
|
|
|
}
|
|
|
|
non_iram_int_disabled_flag[cpu] = false;
|
2022-07-21 07:24:42 -04:00
|
|
|
esp_cpu_intr_enable(non_iram_ints);
|
2022-05-30 04:47:14 -04:00
|
|
|
rtc_isr_noniram_enable(cpu);
|
2021-02-23 23:07:11 -05:00
|
|
|
portEXIT_CRITICAL_SAFE(&spinlock);
|
2016-11-25 04:33:51 -05:00
|
|
|
}
|
|
|
|
|
2016-12-12 07:05:58 -05:00
|
|
|
//These functions are provided in ROM, but the ROM-based functions use non-multicore-capable
|
|
|
|
//virtualized interrupt levels. Thus, we disable them in the ld file and provide working
|
|
|
|
//equivalents here.
|
2016-11-25 04:33:51 -05:00
|
|
|
|
|
|
|
|
2020-11-05 23:00:07 -05:00
|
|
|
void IRAM_ATTR ets_isr_unmask(uint32_t mask) {
|
2022-07-21 07:24:42 -04:00
|
|
|
esp_cpu_intr_enable(mask);
|
2016-12-12 07:05:58 -05:00
|
|
|
}
|
|
|
|
|
2020-11-05 23:00:07 -05:00
|
|
|
void IRAM_ATTR ets_isr_mask(uint32_t mask) {
|
2022-07-21 07:24:42 -04:00
|
|
|
esp_cpu_intr_disable(mask);
|
2016-12-12 07:05:58 -05:00
|
|
|
}
|
|
|
|
|
2023-06-25 05:12:43 -04:00
|
|
|
void IRAM_ATTR esp_intr_enable_source(int inum)
|
2020-09-29 19:44:12 -04:00
|
|
|
{
|
2022-07-21 07:24:42 -04:00
|
|
|
esp_cpu_intr_enable(1 << inum);
|
2020-09-29 19:44:12 -04:00
|
|
|
}
|
2016-11-25 04:33:51 -05:00
|
|
|
|
2023-06-25 05:12:43 -04:00
|
|
|
void IRAM_ATTR esp_intr_disable_source(int inum)
|
2020-09-29 19:44:12 -04:00
|
|
|
{
|
2022-07-21 07:24:42 -04:00
|
|
|
esp_cpu_intr_disable(1 << inum);
|
2020-11-10 02:40:01 -05:00
|
|
|
}
|
2023-05-22 14:57:31 -04:00
|
|
|
|
|
|
|
esp_err_t esp_intr_dump(FILE *stream)
|
|
|
|
{
|
|
|
|
if (stream == NULL) {
|
|
|
|
stream = stdout;
|
|
|
|
}
|
|
|
|
#ifdef CONFIG_ESP_SYSTEM_SINGLE_CORE_MODE
|
|
|
|
const int cpu_num = 1;
|
|
|
|
#else
|
|
|
|
const int cpu_num = SOC_CPU_CORES_NUM;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
int general_use_ints_free = 0;
|
|
|
|
int shared_ints = 0;
|
|
|
|
|
|
|
|
for (int cpu = 0; cpu < cpu_num; ++cpu) {
|
|
|
|
fprintf(stream, "CPU %d interrupt status:\n", cpu);
|
|
|
|
fprintf(stream, " Int Level Type Status\n");
|
2023-08-14 03:44:24 -04:00
|
|
|
for (int i_num = 0; i_num < CPU_INT_LINES_COUNT; ++i_num) {
|
2023-05-22 14:57:31 -04:00
|
|
|
fprintf(stream, " %2d ", i_num);
|
|
|
|
esp_cpu_intr_desc_t intr_desc;
|
|
|
|
esp_cpu_intr_get_desc(cpu, i_num, &intr_desc);
|
|
|
|
bool is_general_use = true;
|
|
|
|
vector_desc_t *vd = find_desc_for_int(i_num, cpu);
|
|
|
|
|
|
|
|
#ifndef SOC_CPU_HAS_FLEXIBLE_INTC
|
|
|
|
fprintf(stream, " %d %s ",
|
|
|
|
intr_desc.priority,
|
|
|
|
intr_desc.type == ESP_CPU_INTR_TYPE_EDGE ? "Edge " : "Level");
|
|
|
|
|
|
|
|
is_general_use = (intr_desc.type == ESP_CPU_INTR_TYPE_LEVEL) && (intr_desc.priority <= XCHAL_EXCM_LEVEL);
|
|
|
|
#else // SOC_CPU_HAS_FLEXIBLE_INTC
|
|
|
|
if (vd == NULL) {
|
|
|
|
fprintf(stream, " * * ");
|
|
|
|
} else {
|
2024-03-13 07:34:33 -04:00
|
|
|
// # TODO: IDF-9512
|
2023-05-22 14:57:31 -04:00
|
|
|
// esp_cpu_intr_get_* functions need to be extended with cpu parameter.
|
|
|
|
// Showing info for the current cpu only, in the meantime.
|
|
|
|
if (esp_cpu_get_core_id() == cpu) {
|
|
|
|
fprintf(stream, " %d %s ",
|
|
|
|
esp_cpu_intr_get_priority(i_num),
|
|
|
|
esp_cpu_intr_get_type(i_num) == ESP_CPU_INTR_TYPE_EDGE ? "Edge " : "Level");
|
|
|
|
} else {
|
|
|
|
fprintf(stream, " ? ? ");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif // SOC_CPU_HAS_FLEXIBLE_INTC
|
|
|
|
|
|
|
|
if (intr_desc.flags & ESP_CPU_INTR_DESC_FLAG_RESVD) {
|
|
|
|
fprintf(stream, "Reserved");
|
|
|
|
} else if (intr_desc.flags & ESP_CPU_INTR_DESC_FLAG_SPECIAL) {
|
|
|
|
fprintf(stream, "CPU-internal");
|
|
|
|
} else {
|
|
|
|
if (vd == NULL || (vd->flags & (VECDESC_FL_RESERVED | VECDESC_FL_NONSHARED | VECDESC_FL_SHARED)) == 0) {
|
|
|
|
fprintf(stream, "Free");
|
|
|
|
if (is_general_use) {
|
|
|
|
++general_use_ints_free;
|
|
|
|
} else {
|
|
|
|
fprintf(stream, " (not general-use)");
|
|
|
|
}
|
|
|
|
} else if (vd->flags & VECDESC_FL_RESERVED) {
|
|
|
|
fprintf(stream, "Reserved (run-time)");
|
|
|
|
} else if (vd->flags & VECDESC_FL_NONSHARED) {
|
|
|
|
fprintf(stream, "Used: %s", esp_isr_names[vd->source]);
|
|
|
|
} else if (vd->flags & VECDESC_FL_SHARED) {
|
|
|
|
fprintf(stream, "Shared: ");
|
|
|
|
for (shared_vector_desc_t *svd = vd->shared_vec_info; svd != NULL; svd = svd->next) {
|
|
|
|
fprintf(stream, "%s ", esp_isr_names[svd->source]);
|
|
|
|
}
|
|
|
|
++shared_ints;
|
|
|
|
} else {
|
|
|
|
fprintf(stream, "Unknown, flags = 0x%x", vd->flags);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fprintf(stream, "\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
fprintf(stream, "Interrupts available for general use: %d\n", general_use_ints_free);
|
|
|
|
fprintf(stream, "Shared interrupts: %d\n", shared_ints);
|
|
|
|
return ESP_OK;
|
|
|
|
}
|