[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>
This commit is contained in:
GuEe-GUI 2024-09-11 12:59:55 +08:00 committed by Rbb666
parent 04cdbc647c
commit 94e49755af
2 changed files with 25 additions and 0 deletions

View File

@ -148,6 +148,7 @@ void rt_pic_default_name(struct rt_pic *pic);
struct rt_pic *rt_pic_dynamic_cast(void *ptr); 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_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_ipi(struct rt_pic *pic, int ipi_index, int hwirq);
int rt_pic_config_irq(struct rt_pic *pic, int irq_index, int hwirq); int rt_pic_config_irq(struct rt_pic *pic, int irq_index, int hwirq);

View File

@ -173,6 +173,30 @@ rt_err_t rt_pic_linear_irq(struct rt_pic *pic, rt_size_t irq_nr)
return err; 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) 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); rt_ubase_t level = rt_spin_lock_irqsave(&pirq->rw_lock);