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 实时操作系统中断(上)
- 下一篇: Nucleus SE RTOS初始化和启