2021-08-30 21:04:34 +08:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2021 Espressif Systems (Shanghai) Co., Ltd.
|
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <soc/rtc_cntl_reg.h>
|
|
|
|
#include <soc/timer_group_reg.h>
|
|
|
|
#include <soc/gpio_reg.h>
|
|
|
|
#include <soc/syscon_reg.h>
|
|
|
|
#include <soc/system_reg.h>
|
|
|
|
#include <soc/cache_memory.h>
|
|
|
|
#include "hal/soc_ll.h"
|
|
|
|
#include <riscv/interrupt.h>
|
|
|
|
#include <soc/interrupt_reg.h>
|
|
|
|
#include <soc/periph_defs.h>
|
2022-05-06 17:11:04 +08:00
|
|
|
#include <zephyr/drivers/interrupt_controller/intc_esp32c3.h>
|
2021-08-30 21:04:34 +08:00
|
|
|
|
2022-05-06 17:11:04 +08:00
|
|
|
#include <zephyr/kernel_structs.h>
|
2021-08-30 21:04:34 +08:00
|
|
|
#include <string.h>
|
2022-05-06 17:11:04 +08:00
|
|
|
#include <zephyr/toolchain/gcc.h>
|
2021-08-30 21:04:34 +08:00
|
|
|
#include <soc.h>
|
2022-06-28 21:42:37 +08:00
|
|
|
#include <zephyr/arch/riscv/arch.h>
|
2021-08-30 21:04:34 +08:00
|
|
|
|
|
|
|
#define ESP32C3_INTSTATUS_SLOT1_THRESHOLD 32
|
|
|
|
|
|
|
|
void arch_irq_enable(unsigned int irq)
|
|
|
|
{
|
2022-03-10 10:06:33 +08:00
|
|
|
esp_intr_enable(irq);
|
2021-08-30 21:04:34 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void arch_irq_disable(unsigned int irq)
|
|
|
|
{
|
2022-03-10 10:06:33 +08:00
|
|
|
esp_intr_disable(irq);
|
2021-08-30 21:04:34 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
int arch_irq_is_enabled(unsigned int irq)
|
|
|
|
{
|
2022-03-10 10:06:33 +08:00
|
|
|
bool res = false;
|
|
|
|
uint32_t key = irq_lock();
|
|
|
|
|
|
|
|
if (irq < 32) {
|
|
|
|
res = esp_intr_get_enabled_intmask(0) & BIT(irq);
|
|
|
|
} else {
|
|
|
|
res = esp_intr_get_enabled_intmask(1) & BIT(irq - 32);
|
|
|
|
}
|
|
|
|
|
|
|
|
irq_unlock(key);
|
|
|
|
|
|
|
|
return res;
|
2021-08-30 21:04:34 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t soc_intr_get_next_source(void)
|
|
|
|
{
|
|
|
|
uint32_t status;
|
|
|
|
uint32_t source;
|
|
|
|
|
|
|
|
status = REG_READ(INTERRUPT_CORE0_INTR_STATUS_0_REG) &
|
|
|
|
esp_intr_get_enabled_intmask(0);
|
|
|
|
|
|
|
|
if (status) {
|
|
|
|
source = __builtin_ffs(status) - 1;
|
|
|
|
} else {
|
|
|
|
status = REG_READ(INTERRUPT_CORE0_INTR_STATUS_1_REG) &
|
|
|
|
esp_intr_get_enabled_intmask(1);
|
|
|
|
source = (__builtin_ffs(status) - 1 + ESP32C3_INTSTATUS_SLOT1_THRESHOLD);
|
|
|
|
}
|
|
|
|
|
|
|
|
return source;
|
|
|
|
}
|