From 94e49755af3fe7b66f7da531502f3cc5e1ad71b0 Mon Sep 17 00:00:00 2001 From: GuEe-GUI <2991707448@qq.com> Date: Wed, 11 Sep 2024 12:59:55 +0800 Subject: [PATCH] [FEATURE/PIC] support PIC cancel (only in debug) PIC may free because some wrongs in debug. We should remove in PIC list or there are some undefined behavior will happen. Signed-off-by: GuEe-GUI <2991707448@qq.com> --- components/drivers/include/drivers/pic.h | 1 + components/drivers/pic/pic.c | 24 ++++++++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/components/drivers/include/drivers/pic.h b/components/drivers/include/drivers/pic.h index fa1941abbc..c624d249d1 100755 --- a/components/drivers/include/drivers/pic.h +++ b/components/drivers/include/drivers/pic.h @@ -148,6 +148,7 @@ void rt_pic_default_name(struct rt_pic *pic); struct rt_pic *rt_pic_dynamic_cast(void *ptr); rt_err_t rt_pic_linear_irq(struct rt_pic *pic, rt_size_t irq_nr); +rt_err_t rt_pic_cancel_irq(struct rt_pic *pic); int rt_pic_config_ipi(struct rt_pic *pic, int ipi_index, int hwirq); int rt_pic_config_irq(struct rt_pic *pic, int irq_index, int hwirq); diff --git a/components/drivers/pic/pic.c b/components/drivers/pic/pic.c index 8893f974c2..9f8f6f3cf7 100644 --- a/components/drivers/pic/pic.c +++ b/components/drivers/pic/pic.c @@ -173,6 +173,30 @@ rt_err_t rt_pic_linear_irq(struct rt_pic *pic, rt_size_t irq_nr) return err; } +rt_err_t rt_pic_cancel_irq(struct rt_pic *pic) +{ + rt_err_t err = RT_EOK; + + if (pic && pic->pirqs) + { + rt_ubase_t level = rt_spin_lock_irqsave(&_pic_lock); + + /* + * This is only to make system runtime safely, + * we don't recommend PICs to unregister. + */ + rt_list_remove(&pic->list); + + rt_spin_unlock_irqrestore(&_pic_lock, level); + } + else + { + err = -RT_EINVAL; + } + + return err; +} + static void config_pirq(struct rt_pic *pic, struct rt_pic_irq *pirq, int irq, int hwirq) { rt_ubase_t level = rt_spin_lock_irqsave(&pirq->rw_lock);