feat: Added rt_interrupt_context* family for nested interrupt handling

These changes introduce the rt_interrupt_context family, providing a
mechanism for managing nested interrupts. The context management
ensures proper storage and retrieval of interrupt states, improving
reliability in nested interrupt scenarios by enabling context tracking
across different interrupt levels. This enhancement is essential for
platforms where nested interrupt handling is crucial, such as in real-
time or multi-threaded applications.

Changes:
- Defined rt_interrupt_context structure with context and node fields
  in `rtdef.h` to support nested interrupts.
- Added rt_slist_pop function in `rtservice.h` for simplified node
  removal in singly linked lists.
- Declared rt_interrupt_context_push, rt_interrupt_context_pop, and
  rt_interrupt_context_get functions in `rtthread.h` to manage the
  interrupt/exception stack.
- Modified AArch64 CPU support in `cpuport.h` to include
  rt_hw_show_register for debugging registers.
- Refactored `_rt_hw_trap_irq` in `trap.c` for context-aware IRQ
  handling, with stack push/pop logic to handle nested contexts.
- Implemented interrupt context push, pop, and retrieval logic in
  `irq.c` to manage context at the CPU level.

Signed-off-by: Shell <smokewood@qq.com>
This commit is contained in:
Shell
2024-10-30 16:57:42 +08:00
committed by Rbb666
parent 3a696ebc67
commit 40cd8cce99
7 changed files with 76 additions and 2 deletions

View File

@@ -723,6 +723,9 @@ struct rt_cpu
#ifdef RT_USING_CPU_USAGE_TRACER
struct rt_cpu_usage_stats cpu_stat;
#endif /* RT_USING_CPU_USAGE_TRACER */
#ifdef ARCH_USING_IRQ_CTX_LIST
rt_slist_t irq_ctx_head;
#endif /* ARCH_USING_IRQ_CTX_LIST */
};
#else /* !RT_USING_SMP */
@@ -734,6 +737,9 @@ struct rt_cpu
#ifdef RT_USING_CPU_USAGE_TRACER
struct rt_cpu_usage_stats cpu_stat;
#endif /* RT_USING_CPU_USAGE_TRACER */
#ifdef ARCH_USING_IRQ_CTX_LIST
rt_slist_t irq_ctx_head;
#endif /* ARCH_USING_IRQ_CTX_LIST */
};
#endif /* RT_USING_SMP */
@@ -744,6 +750,16 @@ typedef struct rt_cpu *rt_cpu_t;
struct rt_thread;
/**
* interrupt/exception frame handling
*
*/
typedef struct rt_interrupt_context {
void *context; /**< arch specific context */
rt_slist_t node; /**< node for nested interrupt */
} *rt_interrupt_context_t;
#ifdef RT_USING_SMART
typedef rt_err_t (*rt_wakeup_func_t)(void *object, struct rt_thread *thread);

View File

@@ -11,6 +11,7 @@
* 2012-03-22 Bernard rename kservice.h to rtservice.h
* 2017-11-15 JasonJia Modify rt_slist_foreach to rt_slist_for_each_entry.
* Make code cleanup.
* 2024-01-03 Shell add rt_slist_pop()
*/
#ifndef __RT_SERVICE_H__
@@ -224,6 +225,20 @@ rt_inline unsigned int rt_slist_len(const rt_slist_t *l)
return len;
}
rt_inline rt_slist_t *rt_slist_pop(rt_slist_t *l)
{
struct rt_slist_node *node = l;
/* remove node */
node = node->next;
if (node != (rt_slist_t *)0)
{
((struct rt_slist_node *)l)->next = node->next;
}
return node;
}
rt_inline rt_slist_t *rt_slist_remove(rt_slist_t *l, rt_slist_t *n)
{
/* remove slist head */

View File

@@ -713,6 +713,10 @@ rt_err_t rt_device_control(rt_device_t dev, int cmd, void *arg);
void rt_interrupt_enter(void);
void rt_interrupt_leave(void);
void rt_interrupt_context_push(rt_interrupt_context_t this_ctx);
void rt_interrupt_context_pop(void);
void *rt_interrupt_context_get(void);
/**
* CPU object
*/