欢迎您访问 最编程 本站为您分享编程语言代码,编程技术文章!
您现在的位置是: 首页

RH850 中断嵌套功能说明

最编程 2024-04-10 14:40:50
...
【直播预告】程序员逆袭 CEO 分几步?

1 背景说明

RH850使用CS+配置自动生成的代码,在进入中断程序后,通过观察中断寄存器,发现PSW.DI置为1,即EI全局中断关闭,在EI中断程序运行的时候,低优先级中断程序的运行无法被打断,从而导致更高优先级的中断程序无法抢占执行。

2 原因梳理

在《RH850F1K Group User Manual Hardware.pdf》手册的7.2.9.4 Interrupt Suspended by CPU章节,其中描述在产生中断应答后,PSW.ID标志会自动置1,该位在置1后,PSW.ID = 1的时候,所有的EI中断将会被屏蔽,即在中断中,所有的中断程序将会无法被响应。

具体参数如下原文描述

因此,如果要使用中断嵌套功能,需要在进入中断后手动的使能中断。

:此部分仅描述中断嵌套,针对中断优先级抢占,调度部分不做详细描述。

3 应对策略

按照官方文档,我们可以在中断后,手动的调用指令来使用EI中断,除了手动的方式外,各个编译器针对RH850在中断使能提供了相关的方案。

3.1 CS+编译器

在CS+编译器中,其在#pragma中断中提供相关配置属性项,其中enable属性用于配置中断嵌套。(参见CS+for CC--CC-RH 使用手册.pdf P316)

其语法结构如下:

enable参数的说明如下:

当配置为true的时候,其会产生代码去输出ei/di,并保存和恢复eipc/eipsw。

示例

#ifdef __CSP__
#pragma interrupt r_uart2_interrupt_receive(enable=true, channel=166, fpu=true, callt=false)
void r_uart2_interrupt_receive(void)
#endif /* __CSP__ */

3.2 GHS编译器

在GHS编译器中,#pragma ghs 中断指令可以有参数来指示编译器以不同的方式生成中断例程序言和尾声的代码。 (参见MULTI:Building Applications for Embedded V850 and RH850 v2021.1.chm Using the MULTI Compiler->Developing for V850 and RH850-> Other Topics -> Interrupt Routines -> Interrupt Pragma Directive Parameters.)

其语法结构如下:

#pragma ghs interrupt([parameter])

其通过增加parameter来针对中断函数的行为控制。其中,参数“enabled”用于配置进入中断后针对中断控制的行为。其原文描述如下:

enabled: Interrupts are already disabled when an interrupt routine is called, and are enabled immediately when it returns. The compiler does not normally insert code to enable interrupts; this is left to the implementation of the interrupt routine. To instruct the compiler to insert code that enables interrupts early on in the interrupt function's prologue, pass the enabled parameter to #pragma ghs interrupt

即在#pramga ghs interrupt后面追加enabled参数后,其在生成代码时候会生成相关中插入使能中断的代码。

示例

#ifdef __GHS__
#pragma ghs interrupt(enabled)
void INTRLIN32UR1(void)
#endif /* __GHS__ */

推荐阅读