RT-Thread RTOS 1.2.0
An open source embedded real-time operating system
载入中...
搜索中...
未找到
irq.c
浏览该文件的文档.
1/*
2 * Copyright (c) 2006-2022, RT-Thread Development Team
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 *
6 * Change Logs:
7 * Date Author Notes
8 * 2006-02-24 Bernard first version
9 * 2006-05-03 Bernard add IRQ_DEBUG
10 * 2016-08-09 ArdaFu add interrupt enter and leave hook.
11 * 2018-11-22 Jesven rt_interrupt_get_nest function add disable irq
12 * 2021-08-15 Supperthomas fix the comment
13 * 2022-01-07 Gabriel Moving __on_rt_xxxxx_hook to irq.c
14 * 2022-07-04 Yunjie fix RT_DEBUG_LOG
15 * 2023-09-15 xqyjlj perf rt_hw_interrupt_disable/enable
16 * 2024-01-05 Shell Fixup of data racing in rt_interrupt_get_nest
17 * 2024-01-03 Shell Support for interrupt context
18 */
19
20#include <rthw.h>
21#include <rtthread.h>
22
23#define DBG_TAG "kernel.irq"
24#define DBG_LVL DBG_INFO
25#include <rtdbg.h>
26
27#if defined(RT_USING_HOOK) && defined(RT_HOOK_USING_FUNC_PTR)
28
29static void (*rt_interrupt_enter_hook)(void);
30static void (*rt_interrupt_leave_hook)(void);
31
41void rt_interrupt_enter_sethook(void (*hook)(void))
42{
43 rt_interrupt_enter_hook = hook;
44}
45
55void rt_interrupt_leave_sethook(void (*hook)(void))
56{
57 rt_interrupt_leave_hook = hook;
58}
59#endif /* RT_USING_HOOK */
60
64
66
67#ifdef RT_USING_SMP
68#define rt_interrupt_nest rt_cpu_self()->irq_nest
69#else
71#endif /* RT_USING_SMP */
72
73#ifdef ARCH_USING_IRQ_CTX_LIST
75{
76 struct rt_cpu *this_cpu = rt_cpu_self();
77 rt_slist_insert(&this_cpu->irq_ctx_head, &this_ctx->node);
78}
79
81{
82 struct rt_cpu *this_cpu = rt_cpu_self();
83 rt_slist_pop(&this_cpu->irq_ctx_head);
84}
85
87{
88 struct rt_cpu *this_cpu = rt_cpu_self();
89 return rt_slist_first_entry(&this_cpu->irq_ctx_head, struct rt_interrupt_context, node)->context;
90}
91#endif /* ARCH_USING_IRQ_CTX_LIST */
92
100rt_weak void rt_interrupt_enter(void)
101{
103 RT_OBJECT_HOOK_CALL(rt_interrupt_enter_hook,());
104 LOG_D("irq has come..., irq current nest:%d",
106}
108
109
117rt_weak void rt_interrupt_leave(void)
118{
119 LOG_D("irq is going to leave, irq current nest:%d",
121 RT_OBJECT_HOOK_CALL(rt_interrupt_leave_hook,());
123
124}
126
127
137{
138 rt_uint8_t ret;
139 rt_base_t level;
140
141 level = rt_hw_local_irq_disable();
144 return ret;
145}
147
150
152{
153 return RT_FALSE;
154}
157
struct rt_cpu * rt_cpu_self(void)
This fucntion will return current cpu object.
rt_weak void rt_interrupt_enter(void)
This function will be invoked by BSP, when enter interrupt service routine
定义 irq.c:100
rt_weak rt_bool_t rt_hw_interrupt_is_disabled(void)
定义 irq.c:151
rt_weak rt_uint8_t rt_interrupt_get_nest(void)
This function will return the nest of interrupt.
定义 irq.c:136
volatile rt_atomic_t rt_interrupt_nest
定义 irq.c:70
rt_weak void rt_interrupt_leave(void)
This function will be invoked by BSP, when leave interrupt service routine
定义 irq.c:117
#define RT_OBJECT_HOOK_CALL(func, argv)
rt_inline void rt_slist_insert(rt_slist_t *l, rt_slist_t *n)
#define rt_slist_first_entry(ptr, type, member)
rt_inline rt_slist_t * rt_slist_pop(rt_slist_t *l)
struct rt_interrupt_context * rt_interrupt_context_t
#define rt_atomic_sub(ptr, v)
#define rt_atomic_add(ptr, v)
#define rt_atomic_load(ptr)
#define LOG_D(...)
void rt_hw_interrupt_enable(rt_base_t level)
#define rt_hw_local_irq_disable
定义 rthw.h:152
rt_base_t rt_hw_interrupt_disable(void)
#define rt_hw_local_irq_enable
定义 rthw.h:153
#define RTM_EXPORT(symbol)
定义 rtm.h:33
void rt_interrupt_context_push(rt_interrupt_context_t this_ctx)
void rt_interrupt_enter_sethook(void(*hook)(void))
void rt_interrupt_leave_sethook(void(*hook)(void))
void rt_interrupt_context_pop(void)
void * rt_interrupt_context_get(void)
rt_int32_t rt_base_t
int rt_bool_t
unsigned char rt_uint8_t
rt_base_t rt_atomic_t
#define RT_FALSE
signed int rt_int32_t