中断管理接口
更多...
中断管理接口
RT-Thread的中断管理功能主要是管理中断设备、中断服务例程、中断嵌套、中断栈的维护、 线程切换时的现场保护和恢复等。
当CPU正在处理内部数据时,外界发生了紧急情况,要求CPU暂停当前的工作转去处理这个异步事件。 处理完毕后,再回到原来被中断的地址,继续原来的工作,这样的过程称为中断。实现这一功能的 系统称为中断系统,申请CPU中断的请求源称为中断源,当多个中断源同时向CPU请求中断时,就存在 一个中断优先权的问题。通常根据中断源的优先级别,优先处理最紧急事件的中断请求源,即最先 响应级别最高的中断请求。
当中断产生时,CPU将按如下的顺序执行:
- (1)保存当前处理机状态信息;
- (2)载入异常或中断处理函数到PC寄存器;
- (3)把控制权转交给处理函数并开始执行;
- (4)当处理函数执行完成时,恢复处理器状态信息;
- (5)从异常或中断中返回到前一个程序执行点。
中断使得CPU可以在事件发生时才进行处理,而不必让CPU连续不断地查询是否有相应的事件发生。
| void rt_interrupt_enter |
( |
void |
| ) |
|
| void rt_interrupt_leave |
( |
void |
| ) |
|
中断嵌套层数获取
该函数将返回中断嵌套。
用户应用程序可以调用此函数来获取当前上下文是否是中断上下文。
- 返回
- 嵌套中断的数量。
| void rt_hw_interrupt_enable |
( |
rt_base_t |
level | ) |
|
打开系统中断
该功能将设置指定的中断状态,该状态应由rt_hw_intterrupt_disable函数保存。 如果保存的中断状态是中断打开,该功能将打开系统中断状态。
- 示例:
- interrupt_sample.c.
| void rt_hw_interrupt_init |
( |
void |
| ) |
|
初始化中断
初始化中断控制器
该函数初始化中断。
该函数初始化中断控制器
| void rt_hw_interrupt_mask |
( |
int |
vector | ) |
|
禁用指定中断
此函数屏蔽指定的中断。
- 参数
-
- 注解
- 并非所有平台都提供此函数。
| void rt_hw_interrupt_umask |
( |
int |
vector | ) |
|
打开指定中断
该函数打开指定的中断。
- 参数
-
- 注解
- 并非所有平台都提供此函数。
| rt_isr_handler_t rt_hw_interrupt_install |
( |
int |
vector, |
|
|
rt_isr_handler_t |
handler, |
|
|
void * |
param, |
|
|
const char * |
name |
|
) |
| |
安装中断处理程序
注册中断服务函数.
该函数将安装指定的中断处理程序。
- 参数
-
| vector | 要安装的中断号。 |
| handler | 新的中断处理程序。 |
| param | 中断处理程序的参数。 |
| name | 中断名称。 |
- 返回
- 旧的中断处理程序。
- 注解
- 并非所有平台都提供此函数。
- 参数
-
| vector | 中断号 |
| handler | 新注册的中断服务函数 |
| param | 中断服务函数的参数 |
| name | 中断服务名 |
- 返回
- 旧的中断服务函数
- 注解
- 并非所有平台都提供此函数。
| int rt_hw_interrupt_get_irq |
( |
void |
| ) |
|
获取激活中断号.
- 返回
- 激活中断号
- 注解
- 并非所有平台都提供此函数。
| void rt_hw_interrupt_ack |
( |
int |
vector | ) |
|
| void rt_hw_interrupt_set_target_cpus |
( |
int |
vector, |
|
|
unsigned int |
cpu_mask |
|
) |
| |
设置中断上报目标CPU.
- 参数
-
| vector | 中断号 |
| cpu_mask | CPU掩码,一个bit对应一个cpu |
- 注解
- 并非所有平台都提供此函数。
| unsigned int rt_hw_interrupt_get_target_cpus |
( |
int |
vector | ) |
|
获取中断上报目标CPU.
- 参数
-
- 返回
- CPU掩码,一个bit对应一个cpu
- 注解
- 并非所有平台都提供此函数。
| void rt_hw_interrupt_set_triger_mode |
( |
int |
vector, |
|
|
unsigned int |
mode |
|
) |
| |
设置中断触发模式.
- 参数
-
| vector | 中断号 |
| mode | 中断触发模式; 0: level triger, 1: edge triger |
- 注解
- 并非所有平台都提供此函数。
| unsigned int rt_hw_interrupt_get_triger_mode |
( |
int |
vector | ) |
|
获取中断触发模式.
- 参数
-
- 返回
- 中断触发模式; 0: level triger, 1: edge triger
- 注解
- 并非所有平台都提供此函数。
| void rt_hw_interrupt_set_pending |
( |
int |
vector | ) |
|
设置中断pending标志.
- 参数
-
- 注解
- 并非所有平台都提供此函数。
| unsigned int rt_hw_interrupt_get_pending |
( |
int |
vector | ) |
|
获取中断pending标志.
- 参数
-
- 返回
- 中断pending标志, 0: not pending; 1: pending
- 注解
- 并非所有平台都提供此函数。
| void rt_hw_interrupt_clear_pending |
( |
int |
vector | ) |
|
清除中断pending标志.
- 参数
-
- 注解
- 并非所有平台都提供此函数。
| void rt_hw_interrupt_set_priority |
( |
int |
vector, |
|
|
unsigned int |
priority |
|
) |
| |
设置中断优先级.
- 参数
-
- 注解
- 并非所有平台都提供此函数。
| unsigned int rt_hw_interrupt_get_priority |
( |
int |
vector | ) |
|
获取中断优先级.
- 参数
-
- 返回
- 中断优先级
- 注解
- 并非所有平台都提供此函数。
| void rt_hw_interrupt_set_priority_mask |
( |
unsigned int |
priority | ) |
|
设置优先级屏蔽阈值.
- 参数
-
- 注解
- 并非所有平台都提供此函数。
| unsigned int rt_hw_interrupt_get_priority_mask |
( |
void |
| ) |
|
获取优先级屏蔽阈值.
- 返回
- 优先级屏蔽阈值
- 注解
- 并非所有平台都提供此函数。
| int rt_hw_interrupt_set_prior_group_bits |
( |
unsigned int |
bits | ) |
|
设置优先级组分隔点.
- 参数
-
- 返回
- 0: success; -1: failed
- 注解
- 并非所有平台都提供此函数。
| unsigned int rt_hw_interrupt_get_prior_group_bits |
( |
void |
| ) |
|
获取优先级组分隔点.
- 返回
- 优先级组分隔点
- 注解
- 并非所有平台都提供此函数。
| void rt_hw_ipi_send |
( |
int |
ipi_vector, |
|
|
unsigned int |
cpu_mask |
|
) |
| |
发送核间IPI中断.
- 参数
-
| ipi_vector | ipi中断号 |
| cpu_mask | 目标cpu target,一个bit对应一个cpu |
- 注解
- 并非所有平台都提供此函数。
| void rt_hw_ipi_handler_install |
( |
int |
ipi_vector, |
|
|
rt_isr_handler_t |
ipi_isr_handler |
|
) |
| |
注册核间中断服务函数.
- 参数
-
| ipi_vector | ipi中断号 |
| ipi_isr_handler | ipi中断服务函数 |
- 注解
- 并非所有平台都提供此函数。