Nucleus 实时操作系统中断(下)

Posted wujianming-110117

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Nucleus 实时操作系统中断(下)相关的知识,希望对你有一定的参考价值。

Nucleus 实时操作系统中断(下)

Nucleus RTOS兼容性              

由于中断在Nucleus SE中的实现方式与Nucleus rto截然不同,因此不应期望有特定的兼容性。Nucleus RTOS有一个本机/低级/高级中断方案,这在某种程度上类似于Nucleus SE中的本机中断和管理中断。             

低级和高级ISR             

低级ISR             

低级中断服务程序(LISR)作为普通ISR执行,包括使用当前堆栈。Nucleus RTOS在调用LISR之前保存上下文,并在LISR返回后恢复上下文。因此,lisr可以用C编写,并且可以调用其他C例程。然而,只有少数Nucleus RTOS服务可用于LISR。如果中断处理需要额外的Nucleus RTOS服务,则必须激活高级中断服务程序(HISR)。Nucleus RTOS支持多个lisr的嵌套。             

高级ISR             

HISR是动态创建和删除的。每个HISR都有自己的堆栈空间和自己的控制块。每个内存都由应用程序提供。当然,HISR必须在LISR激活之前创建。             

由于HISR有自己的堆栈和控制块,所以如果它试图访问已经被访问的Nucleus RTOS数据结构,则可以暂时阻止HISR。             

HISR有三个优先级。如果在处理低优先级HISR期间激活了高优先级HISR,则低优先级HISR被抢占的方式与任务被抢占的方式大致相同。相同优先级的hisr按照它们最初激活的顺序执行。在恢复正常任务调度之前,将处理所有激活的HISR。             

Nucleus RTOS中断API调用             

Nucleus RTOS有许多API调用来支持其中断结构。这些都不是在Nucleus SE中实现的。             

对于本机中断,API调用提供以下功能:             

控制(启用/禁用)中断(本地和全局)             

设置中断向量             

对于低电平中断:             

向内核注册一个低级ISR             

对于高级中断:             

创建/删除高级中断             

激活高级中断             

获取应用程序中(当前)的高级中断数              

获取指向所有高级中断的控制块的指针             

获取指向当前高级中断控制块的指针             

获取有关高级中断的信息             

全局控制中断             

此服务以独立于任务的方式启用或禁用中断。因此,由该服务禁用的中断将保持禁用状态,直到随后对此服务的调用启用为止。             

服务调用原型:

INT NU_Control_Interrupts(INT new_level);

参数:             

new_level–系统的新中断级别。菜单禁用中断(禁用所有中断)和菜单启用中断(启用所有中断)选项始终可用。根据体系结构,还可以使用其他选项。             

返回:             

此服务返回以前级别的已启用中断。             

本地控制中断             

此服务以依赖于任务的方式启用或禁用中断。此服务将状态寄存器更改为指定的值。状态寄存器将被设置回下一个上下文开关上一次调用NU_Control_Interrupts()时设置的值。             

服务调用原型:

INT NU_Local_Control_Interrupts(INT new_level);

参数:             

new_level–当前任务的新中断级别。菜单禁用中断(禁用所有中断)和菜单启用中断(启用所有中断)选项始终可用。根据体系结构,还可以使用其他选项。             

返回:             

此服务返回以前级别的已启用中断。             

设置中断向量             

此服务用自定义中断服务例程(ISR)替换vector指定的中断向量。              

服务调用原型:

VOID *NU_Setup_Vector(INT vector, VOID *new);

参数:             

vector–用于注册中断的中断向量             

新–ISR将在vector注册             

返回:             

此服务返回一个指向先前在中断向量上注册的ISR的指针。             

注册LISR中断             

此服务将LISR函数与中断向量相关联。系统上下文在调用指定的LISR之前自动保存,并在LISR返回后恢复。             

服务调用原型:

STATUS NU_Register_LISR(INT vector, VOID(*lisr_entry)(INT), 
VOID (**old_lisr)(INT));

Parameters:

vector – the interrupt vector at which to register the interrupt
lisr_entry – the function to register at the vector; a value of NU_NULL clears the vector
old_lisr – the subroutine previously registered at the specified vector

Returns:

NU_SUCCESS – successful completion of the service
NU_INVALID_VECTOR – the specified vector is invalid
NU_NOT_REGISTERED – the vector is not currently registered as de-registration was specified by lisr_entry 
NU_NO_MORE_LISRS – the maximum number of registered LISRs has been exceeded

Create a HISR

This service creates a High-Level Interrupt Service Routine (HISR).

Service call prototype:

STATUS NU_Create_HISR(NU_HISR *hisr, CHAR *name, 
VOID (*hisr_entry)(VOID), OPTION priority, VOID  *stack_pointer, UNSIGNED stack_size);

Parameters:

hisr – pointer to a user-supplied HISR control block
name – pointer to a 7-character, null-terminated name for the HISR
hisr_entry – the function entry point of the HISR
priority – there are three HISR priorities (0-2); priority 0 is the highest
stack_pointer – pointer to the HISR’s stack area
stack_size – number of bytes in the HISR stack

Returns:

NU_SUCCESS – successful completion of the service
NU_INVALID_HISR – the HISR control block pointer is NULL or is already in use
NU_INVALID_ENTRY – the HISR entry pointer is NULL 
NU_INVALID_PRIORITY – the HISR priority is invalid
NU_INVALID_MEMORY – the stack pointer is NULL 
NU_INVALID_SIZE – the stack size is too small

Delete a HISR

This service deletes a previously created HISR.

Service call prototype:

STATUS NU_Delete_HISR(NU_HISR *hisr);

Parameters:

hisr – pointer to a user-supplied HISR control block

Returns:

NU_SUCCESS – successful completion of the service
NU_INVALID_HISR – the HISR pointer is invalid

激活HISR             

此服务将激活HISR。如果指定的HISR当前正在执行,则在当前执行完成之前不会处理此激活请求。每个激活请求执行一次HISR。             

服务调用原型:

TATUS NU_Activate_HISR (NU_HISR *hisr);

Parameters:

hisr – pointer to the HISR control block

Returns:

NU_SUCCESS – successful completion of the service
NU_INVALID_HISR – the HISR control block pointer is not valid

Obtain the Number of HISRs in a System

This service returns the number of established HISRs. All created HISRs are considered established. Deleted HISRs are no longer considered established.

Service call prototype:

UNSIGNED NU_Established_HISRs(VOID);

Parameters:

none

Returns:

This service call returns the number of established HISRs in the system

Obtain Pointers to HISR Control Blocks

This service builds a sequential list of pointers to all established HISRs in the system.

Service call prototype:

UNSIGNED  NU_HISR_Pointers(NU_HISR  **pointer_list, 
UNSIGNED maximum_pointers);

Parameters:

pointer_list – pointer to an array of NU_HISR pointers; this array will be filled with pointers of established HISRs in the system
maximum_pointers – the maximum number of NU_HISR pointers to place into the array; typically, this will be the size of the pointer_list array

Returns:

This service call returns the number of HISRS that are active in the system

Obtain a Pointer to the Current HISR

This service returns the currently executing HISR’s pointer.

Service call prototype:

NU_HISR *NU_Current_HISR_Pointer(VOID);

Parameters:

none

Returns:

This service call returns a pointer the currently executing HISR’s control block. If the caller is not an HISR, the value returned is NU_NULL .

Obtain Information About a HISR

This service returns various information about the specified HISR.

Service call prototype:

STATUS NU_HISR_Information(NU_HISR *hisr, char *name, 
UNSIGNED  *scheduled_count, DATA_ELEMENT  *priority, 
VOID  **stack_base, UNSIGNED *stack_size, 
UNSIGNED *minimum_stack);

Parameters:

hisr – pointer to the HISR
name – pointer to an 8-character destination area for the HISR’s name; this includes space for the null terminator
scheduled_count – pointer to a variable for holding the total number of times this HISR has been scheduled
priority – pointer to a variable for holding the HISR’s priority
stack_base – pointer to a pointer for holding the original stack pointer; this is the same pointer supplied during creation of the HISR
stack_size – pointer to a variable for holding the total size of the HISR’s stack
minimum_stack – pointer to a variable for holding the minimum amount of available stack space detected during HISR execution

Returns:

NU_SUCCESS – successful completion of the service
NU_INVALID_HISR – the HISR pointer is invalid

API Calls from ISRs

API Calls from LISRs

A LISR may only make use of the following Nucleus RTOS services:

NU_Activate_HISR()
NU_Local_Control_Interrupts()
NU_Current_HISR_Pointer()
NU_Current_Task_Pointer()
NU_Retrieve_Clock()

API Calls from HISRs

HISRs are allowed access to most Nucleus RTOS services, with the exception of self-suspension services. Additionally, since an HISR cannot suspend on a Nucleus RTOS service, the “suspend” parameter must always be set to NU_NO_SUSPEND .

以上是关于Nucleus 实时操作系统中断(下)的主要内容,如果未能解决你的问题,请参考以下文章

嵌入式实时操作系统Nucleus PLUS综述

Nucleus-SE迁移:未实现的设施和兼容性

嵌入式操作系统综述

学嵌入式必知的9种实时操作系统

嵌入式实时系统的几个关键点

实战技能分享,减小开关中断对系统实时性的影响,提升系统响应速度