Interrupt management method and device
By adopting the interrupt management method based on the RAM framework in automotive electronic systems, the pointer of the interrupt service function is obtained and verified, and the problem that the static interrupt vector table is easily tampered with is solved, improving the stability and security of the system.
Patent Information
- Application Number
- CN202411017075.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-07-26
- Publication Date
- 2024-11-08
AI Technical Summary
In existing automotive electronic systems, the static interrupt vector table is not easy to change and there is a security risk of being tampered with, affecting the stability and security of the system.
Using the interrupt management method based on the RAM framework, by obtaining hardware interrupt signals, using offset registers to obtain pointers of intermediate software layer functions from the pre-constructed interrupt vector table, and load them in the interrupt active status register, and call the lower software layer functions. Determine the pointer of the interrupt service function and perform the validity check. If it passes, perform the interrupt operation.
It improves the security and easy maintenance of the interrupt vector table, reduces the possibility of being tampered with, and enhances the stability and security of the system.
Smart Images

Figure CN118916136A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of automotive electronic technology, and in particular to an interrupt management method and device. Background Art
[0002] In automotive electronic systems, microcontroller platforms are often widely used in various control units and modules. Among them, interrupt management is an important function in the microcontroller platform. In automotive electronic systems, interrupt management is often used to process input signals from various sensors and control units. At the same time, in the microcontroller platform, interrupt management also needs to consider the stability and security of the system to avoid the negative impact of interrupt service programs on the normal operation of the system. To this end, developers need to write efficient, stable and reliable interrupt service programs.
[0003] Since there is no clear definition of the interrupt management method on the MCU platform, software development kits usually use the simplest and most classic interrupt management method, which is to index the corresponding interrupt service function (ISR) address in the static interrupt vector table based on the interrupt sequence number (IRQn) of the hardware interrupt, load the address into the CPU program counter (PC), and then save the static interrupt vector table through the non-volatile memory flash FLASH to achieve interrupt management.
[0004] However, the disadvantage of the static interrupt vector table is that it is difficult to change and maintain, and there may even be security risks involving the risk of the interrupt vector table being tampered with. Summary of the invention
[0005] Based on the above-mentioned deficiencies of the prior art, the present application provides an interrupt management method and device to solve the problem that the interrupt vector table is easily tampered with brought about by the prior art.
[0006] In order to achieve the above objectives, this application provides the following technical solutions:
[0007] The first aspect of the present application provides an interruption management method, comprising:
[0008] Get the interrupt signal generated by the hardware;
[0009] Based on the interrupt signal, using an offset register to obtain a pointer to an intermediate software layer function from a pre-built interrupt vector table, and loading the pointer to the intermediate software layer function into an interrupt active status register;
[0010] Calling a lower software layer function to determine a pointer to an interrupt service function in the interrupt active status register and a pre-built sub-interrupt vector table;
[0011] Performing validity check on the pointer of the interrupt service function;
[0012] If the pointer of the interrupt service function passes the validity check, the interrupt service function is called through the pointer of the interrupt service function to perform an interrupt operation.
[0013] Optionally, in the above interrupt management method, the method for constructing the interrupt vector table includes:
[0014] Get the pointer and interrupt sequence number corresponding to the non-kernel event, as well as the pointer and interrupt sequence number corresponding to the kernel event;
[0015] Build arrays;
[0016] Filling the pointer corresponding to the kernel event with the pointer of the default kernel event processing function, and filling the pointer corresponding to the non-kernel event with the pointer of the intermediate software layer function;
[0017] Storing the filled kernel events and non-kernel events into the array;
[0018] According to the interrupt sequence numbers corresponding to the non-kernel events, the non-kernel events filled in the array are sorted, and according to the interrupt sequence numbers corresponding to the kernel events, the kernel events filled in the array are sorted to obtain a memory array;
[0019] The memory array is used as an interrupt vector table.
[0020] Optionally, in the above interrupt management method, the method for constructing the sub-interrupt vector table includes:
[0021] Get multiple interrupt sequence numbers of the hardware and pointers to their corresponding interrupt service functions;
[0022] According to each of the interrupt sequence numbers, the pointers of each of the interrupt service functions are sorted to obtain a target sequence, and the target sequence is used as a vector table;
[0023] Inputting a plurality of interrupt sequence numbers and pointers of their corresponding interrupt service functions into the interface function to construct elements of the vector table;
[0024] The elements of the vector table are stored in the vector table to obtain a sub-interrupt vector table.
[0025] Optionally, in the above interrupt management method, the calling of the lower software layer function to determine the pointer of the interrupt service function in the interrupt active status register and the pre-built sub-interrupt vector table includes:
[0026] Calling a lower software layer function to query the currently active target interrupt sequence number in the interrupt active status register;
[0027] A pointer to an interrupt service function corresponding to the target interrupt sequence number is determined from a pre-constructed sub-interrupt vector table.
[0028] Optionally, in the above interrupt management method, the checking the validity of the pointer of the interrupt service function includes:
[0029] Detect whether the pointer of the interrupt service function is a null pointer;
[0030] If the pointer of the interrupt service function is a non-null pointer, detecting whether the pointer of the interrupt service function is in a valid range;
[0031] If the pointer of the interrupt service function is within the valid range, determining that the pointer of the interrupt service function passes the validity check;
[0032] If the pointer of the interrupt service function is a null pointer, or the pointer of the interrupt service function is not in the valid range, it is determined that the pointer of the interrupt service function fails the validity check.
[0033] Optionally, in the above interrupt management method, it also includes:
[0034] Check whether all Mcal software has been initialized;
[0035] If all the Mcal software are not initialized, the interface function is used to call the configuration set to execute the interrupt registration function; wherein the configuration set is preliminarily obtained by calling the generation tool through the Platform module to configure the configuration file;
[0036] If all the Mcal software have been initialized, it is determined that the initialization of all the Mcal software is completed.
[0037] A second aspect of the present application provides an interrupt management device, including:
[0038] A signal acquisition unit, used to acquire an interrupt signal generated by hardware;
[0039] A loading unit, configured to obtain a pointer of an intermediate software layer function from a pre-built interrupt vector table using an offset register based on the interrupt signal, and load the pointer of the intermediate software layer function into an interrupt active status register;
[0040] A pointer determination unit, used to call a lower software layer function to determine a pointer of an interrupt service function in the interrupt active status register and a pre-built sub-interrupt vector table;
[0041] A pointer checking unit, used for checking the validity of the pointer of the interrupt service function;
[0042] The function calling unit is used to call the interrupt service function to perform an interrupt operation through the pointer of the interrupt service function if the pointer of the interrupt service function passes the validity check.
[0043] Optionally, the above-mentioned interrupt management device further includes:
[0044] A first acquisition unit, used for acquiring a pointer and an interrupt sequence number corresponding to a non-kernel event, and a pointer and an interrupt sequence number corresponding to a kernel event;
[0045] Construction unit, used to build arrays;
[0046] A filling unit, used to fill the pointer corresponding to the kernel event with the pointer of the default kernel event processing function, and to fill the pointer corresponding to the non-kernel event with the pointer of the intermediate software layer function;
[0047] A first storage unit, used for storing the filled kernel events and non-kernel events into the array;
[0048] A first sorting unit is used to sort the non-kernel events filled in the array according to the interrupt sequence numbers corresponding to the non-kernel events, and sort the kernel events filled in the array according to the interrupt sequence numbers corresponding to the kernel events, so as to obtain a memory array;
[0049] As a unit, it is used to use the memory array as an interrupt vector table.
[0050] Optionally, the above-mentioned interrupt management device further includes:
[0051] A second acquisition unit is used to acquire a plurality of interrupt sequence numbers of the hardware and pointers of their corresponding interrupt service functions;
[0052] A second sorting unit is used to sort the pointers of each interrupt service function according to each interrupt sequence number to obtain a target sequence, and use the target sequence as a vector table;
[0053] An input unit, used for inputting a plurality of interrupt sequence numbers and pointers of their corresponding interrupt service functions into the interface function to construct elements of the vector table;
[0054] The second storage unit is used to store the elements of the vector table into the vector table to obtain a sub-interrupt vector table.
[0055] Optionally, in the above-mentioned interrupt management device, the pointer determination unit includes:
[0056] A query unit, used for calling a lower software layer function to query the currently active target interrupt sequence number in the interrupt active status register;
[0057] The first determining unit is used to determine a pointer of an interrupt service function corresponding to the target interrupt sequence number from a pre-built sub-interrupt vector table.
[0058] Optionally, in the above-mentioned interrupt management device, the pointer checking unit includes:
[0059] A first detection unit, used for detecting whether the pointer of the interrupt service function is a null pointer;
[0060] A second detection unit, configured to detect whether the pointer of the interrupt service function is in a valid range if the pointer of the interrupt service function is a non-null pointer;
[0061] a second determining unit, configured to determine that the pointer of the interrupt service function passes the validity check if the pointer of the interrupt service function is within the valid range;
[0062] The third determining unit is configured to determine that the pointer of the interrupt service function fails the validity check if the pointer of the interrupt service function is a null pointer or the pointer of the interrupt service function is not within the valid range.
[0063] Optionally, the above-mentioned interrupt management device further includes:
[0064] Checking unit, used to check whether all Mcal software have been initialized;
[0065] An execution unit, used for, if all the Mcal software are not initialized, using an interface function to call a configuration set to execute an interrupt registration function; wherein the configuration set is obtained by configuring a configuration file in advance by calling a generation tool through a Platform module;
[0066] The fourth determining unit is used to determine that the initialization of all the Mcal software is completed if all the Mcal software have been initialized.
[0067] The present application provides a method for managing interrupts, which obtains an interrupt signal generated by hardware, and then obtains a pointer to an intermediate software layer function from a pre-built interrupt vector table using an offset register based on the interrupt signal, and loads the pointer to the intermediate software layer function into an interrupt active status register, and then calls the lower software layer function to determine the pointer to the interrupt service function in the interrupt active status register and the pre-built sub-interrupt vector table, and finally performs a validity check on the pointer to the interrupt service function. If the pointer to the interrupt service function passes the validity check, the interrupt service function is called through the pointer to the interrupt service function to perform an interrupt operation. Since the present application is based on a RAM framework, the interrupt vector table and the sub-interrupt vector table are stored in RAM, and the RAM storage is safer than the FLASH storage of the prior art, so the interrupt vector table is not easily tampered with in RAM. BRIEF DESCRIPTION OF THE DRAWINGS
[0068] In order to more clearly illustrate the embodiments of the present application or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are only embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on the provided drawings without paying any creative work.
[0069] Figure 1 A flowchart of an interrupt management method provided in an embodiment of the present application;
[0070] Figure 2 A flowchart of a method for initializing Mcal software provided in another embodiment of the present application;
[0071] Figure 3 A flowchart of a method for constructing an interrupt vector table provided in an embodiment of the present application;
[0072] Figure 4 A flowchart of a method for constructing a sub-interrupt vector table provided in an embodiment of the present application;
[0073] Figure 5 A flowchart of a method for determining a pointer of an interrupt service function provided in an embodiment of the present application;
[0074] Figure 6 A flowchart of a method for checking a pointer of an interrupt service function provided in an embodiment of the present application;
[0075] Figure 7 A schematic diagram of the structure of an interrupt management device provided in another embodiment of the present application. DETAILED DESCRIPTION
[0076] The following will be combined with the drawings in the embodiments of the present application to clearly and completely describe the technical solutions in the embodiments of the present application. Obviously, the described embodiments are only part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of this application.
[0077] In this application, relational terms such as first and second, etc. are used only to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Moreover, the terms "comprise", "include" or any other variants thereof are intended to cover non-exclusive inclusion, so that a process, method, article or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or device. In the absence of further restrictions, an element defined by the statement "comprises a ..." does not exclude the presence of other identical elements in the process, method, article or device including the element.
[0078] The present application embodiment provides a method for managing interruptions, such as Figure 1 As shown, the specific steps include:
[0079] S101. Obtain an interrupt signal generated by hardware.
[0080] Specifically, obtaining interrupt signals generated by hardware is controlled by the CPU and related hardware. When a hardware device needs to be processed by the CPU, an interrupt request (IRQ) signal is sent to the CPU to notify the CPU to terminate the current task and start processing the interrupt request. When the CPU receives the IRQ signal, it immediately suspends the current task, saves relevant status information, and starts the interrupt service function (ISR) to handle the interrupt event.
[0081] It should be noted that in operating systems and embedded systems, an interrupt mechanism can be used to handle hardware interrupts. The interrupt mechanism can obtain and process hardware interrupt signals by writing interrupt handlers, and enable the system to respond and process interrupt signals in a timely manner when they are received.
[0082] It should also be noted that the embodiment of the present application is applied to the Platform module of the Mcal software in the Autosar architecture, and the interrupts are centrally managed by the Platform module. However, the initialization of the Mcal software (including the Platform module) needs to be completed first before the interrupt event can be managed by the Platform module. Therefore, optionally, before executing step S101, another embodiment of the present application also provides an initialization method for the Mcal software, such as Figure 2 As shown, the specific steps include:
[0083] S201, check whether all Mcal software has been initialized.
[0084] It should be noted that since this application is for the interrupt management of Mcal software, if Mcal software wants to call the interrupt management method of this application, it needs to be initialized first, so that it can call the interrupt management method through the "interrupt registration function" interface. Therefore, it is necessary to check whether all Mcal (MicrocontrollerAbstraction Layer) software has been initialized.
[0085] It can be understood that Mcal (Microcontroller Abstraction Layer) software is a general software layer for embedded systems. It provides a set of abstract interfaces for accessing underlying hardware resources and peripherals, and can use the interfaces provided by Mcal software to complete interrupt management methods.
[0086] Therefore, before Mcal software calls the "interrupt registration function" interface, it is necessary to initialize the internal interface of Mcal software first. Specifically, Mcal software is usually composed of multiple modules, each of which is responsible for managing a specific type of hardware resources or peripherals. It is necessary to first determine the Mcal software module that needs to be initialized according to actual needs. Then before initializing the Mcal software module, it may be necessary to configure related registers and parameters to ensure that Mcal software can correctly access and control hardware resources or peripherals. Finally, when the configuration is completed, any Mcal software can be called to initialize the internal interface to initialize the required Mcal software.
[0087] Optionally, you can check the initialization flag, that is, during the MCAL software initialization process, an initialization flag is usually set to indicate whether the MCAL software has completed initialization. Where you need to check whether the MCAL software has been initialized, you can read the flag to make a judgment. Or check the configuration data: MCAL software usually uses configuration data for initialization. When checking whether the MCAL software has been initialized, you can check whether the relevant configuration data has been correctly loaded and configured. Or call the initialization function: MCAL software usually provides an initialization function to initialize hardware and peripherals. Where you need to check whether the MCAL software has been initialized, you can try to call the corresponding initialization function and judge whether it has been successfully initialized based on the return value.
[0088] Therefore, if all Mcal software has been initialized, it means that all Mcal software can complete interrupt management by calling the "interrupt registration function" interface of this application, so step S203 is executed. If all Mcal software has not been initialized, it is necessary to use the "interrupt registration function" interface to register all interrupts at one time, but the one-time registration process requires a configuration set to complete, so as to complete the initialization of all Mcal software, so step S202 is executed.
[0089] S202: Use the interface function to call the configuration set to execute the interrupt registration function.
[0090] It should be emphasized that when all Mcal software is not initialized, it is necessary to assist in completing it by executing the interrupt registration function. Among them, the interrupt registration function refers to registering the corresponding interrupt service function for a specific interrupt event in the embedded system. When an interrupt event occurs, the system will automatically call the corresponding interrupt service function to respond to and handle the interrupt.
[0091] It should be noted that the purpose of executing the interrupt registration function is to associate the interrupt service function with the corresponding interrupt event, so that when the interrupt event occurs, the system can accurately find and call the corresponding interrupt service function. Through the interrupt registration function, flexible processing and response to specific interrupt events can be achieved. Therefore, in an embodiment of the present application, the interrupt registration function will be called autonomously by the Mcal software or uniformly called by the Platform module. When it is uniformly called by the Platform module, a visual configuration file generation tool is generally used to generate a configuration set, and the interrupt registration function is called by the Platform module initialization interface function at runtime. At the same time, during the registration process, when the pointer of a certain interrupt service function has been used by a certain interrupt sequence number, re-registration will trigger the DevelopmentError of the Det (DefaultErrorTracer) module, which is convenient for Mcal software developers to quickly locate the problem. Among them, DevelopmentError is an error type used to find problems.
[0092] It should also be noted that the configuration set is obtained by calling the generation tool of the Platform module to configure the configuration file in advance. And when configuring the configuration set, it is also necessary to determine the "pointer of the interrupt service function" and its corresponding "target interrupt sequence number" of all Mcal software that use the interrupt function, so as to ensure that the interrupt event can be handled correctly and flexibly handle the subsequent interrupt processing process.
[0093] S203, confirm that all Mcal software initialization is completed.
[0094] Specifically, when all Mcal software has been initialized, it means that all Mcal software or devices included in the Mcal software can use the interrupt management method of the present application through the "interrupt registration function" interface.
[0095] S102 . Based on the interrupt signal, obtain the pointer of the middle software layer function from the pre-built interrupt vector table using the offset register, and load the pointer of the middle software layer function into the interrupt active status register.
[0096] It should be noted that in the embodiment of the present application, a control method of a CPU interrupt controller (such as NVIC in a RAM architecture and CVIC in a RISCV architecture) is utilized to control the CPU's response to interrupts.
[0097] Therefore, when an external interrupt event occurs in the peripherals of the CPU, that is, when the hardware generates an interrupt signal, the interrupt controller (NVIC / CVIC) inside the CPU will promptly detect the external interrupt event, and automatically search for the pointer of the intermediate software layer function from the interrupt vector table through the offset register inside the CPU itself, and load the pointer of the intermediate software layer function into the interrupt active status register, so that the Platform module can take over all peripheral events. Among them, the interrupt signal of step S201 is equivalent to a prompt signal, that is, it prompts the offset register inside the CPU itself to find the pointer of the intermediate software layer function from the interrupt vector table at this time.
[0098] An interrupt is a mechanism that interrupts the normal program flow when a certain event or condition occurs during system operation. For example, input from an external device, timer overflow, data reception from a communication interface, etc. can all be considered interrupt events.
[0099] Optionally, the present application embodiment provides a method for constructing an interrupt vector table, such as Figure 3 As shown, the following steps are included:
[0100] S301, obtaining a pointer and an interrupt sequence number corresponding to a non-kernel event, and a pointer and an interrupt sequence number corresponding to a kernel event.
[0101] It should be noted that the interrupt vector table will be composed of pointers corresponding to processed non-kernel events and pointers corresponding to kernel events, so it is necessary to obtain the pointers corresponding to non-kernel events and kernel events in advance. The interrupt sequence numbers corresponding to all events are used for subsequent sorting, so it is also necessary to obtain the interrupt sequence numbers of all events in advance.
[0102] S302: construct an array.
[0103] Specifically, an array with pointer size as the unit can be constructed, and the length of the array is determined by the platform (MCU interrupt) characteristics. Among them, the values in the array are pointer types.
[0104] S303: Fill the pointer corresponding to the kernel event with the pointer of the default kernel event processing function, and fill the pointer corresponding to the non-kernel event with the pointer of the intermediate software layer function.
[0105] It should be noted that since the array is composed of a pointer to the "default kernel event processing function", a pointer to the "intermediate software layer function" and an interrupt sequence number, and the pointers corresponding to non-kernel events and the pointers corresponding to kernel events are not pointers to the "default kernel event processing function" and the pointers to the "intermediate software layer function", in the embodiment of the present application, the pointer corresponding to the kernel event is filled with the pointer to the default kernel event processing function, and the pointer corresponding to the non-kernel event is filled with the pointer to the above-mentioned "intermediate software layer function".
[0106] Specifically, the value corresponding to the kernel event is filled with the pointer of the default kernel event processing function, which can be completed by assigning the pointer (address) of the default kernel event processing function to the corresponding exception vector table item. The exception vector table is a special table that stores the addresses of the processing functions corresponding to different exception types. It can be implemented by writing scripts, but it is not limited to the following implementation logic:
[0107] typedefvoid(*ExceptionFunctionPointer)(void);
[0108] / / Define kernel exception handling function
[0109] voidkernelExceptionHandler(void){
[0110] / / Kernel exception handling logic
[0111] }
[0112] / / Fill the kernel exception handling function pointer into the exception vector table
[0113] ExceptionFunctionPointer exceptionVectorTable[]={
[0114] kernelExceptionHandler, / / kernel exception 0
[0115] kernelExceptionHandler, / / kernel exception 1
[0116] kernelExceptionHandler, / / kernel exception 2
[0117] / / ...
[0118] };
[0119] In the above code, ExceptionFunctionPointer is a function pointer type, which is used to point to the processing function. kernelExceptionHandler is an example of a kernel processing function, and the specific implementation can be written according to actual needs. exceptionVectorTable is an exception vector table, which uses an array to store the address of the exception handling function.
[0120] It should also be noted that by filling the pointer corresponding to the non-kernel event with the pointer of the middle software layer function, it can be realized that when any interrupt occurs, the hardware will automatically call the middle software layer first, and the middle software layer will respond to the interrupt. Therefore, it can be filled by writing a script, but it is not limited to the following implementation logic:
[0121] typedefvoid(*MiddlewareFunctionPointer)(void);
[0122] / / Define the middleware layer function
[0123] void middlewareEventHandler(void){
[0124] / / Non-kernel exception event processing logic
[0125] }
[0126] / / Fill the intermediate software layer function pointer to the value corresponding to the non-kernel exception
[0127] MiddlewareFunctionPointermiddlewareEventTable[]={
[0128] middlewareEventHandler, / / non-kernel exception event 0
[0129] middlewareEventHandler, / / non-kernel exception event 1
[0130] middlewareEventHandler, / / non-kernel exception event 2
[0131] / / ...
[0132] };
[0133] In the above code, MiddlewareFunctionPointer is a function pointer type, which is used to point to the middleware layer function. middlewareEventHandler is an example of a middleware layer function, and the specific implementation can be written according to actual needs. middlewareEventTable is a table that uses an array to store the addresses of middleware layer functions, and each address corresponds to a non-kernel event.
[0134] Through the above operations, kernel events and non-kernel events can be associated with corresponding processing functions, and the corresponding processing functions can be called for processing when an exception occurs. Optionally, developers can add more entries to the exception vector table and non-kernel event table according to specific needs and system design, and select appropriate processing functions for each exception or event.
[0135] S304: Store the filled kernel events and non-kernel events into an array.
[0136] Specifically, based on the filled kernel events and the filled non-kernel events, a pointer corresponding to the array is constructed.
[0137] S305 , sorting the non-kernel events filled in the array according to the interrupt sequence numbers corresponding to the non-kernel events, and sorting the kernel events filled in the array according to the interrupt sequence numbers corresponding to the kernel events, to obtain a memory array.
[0138] It can be understood that sorting the filled kernel events according to the interrupt sequence number can ensure that the interrupt vector table is arranged in the order of the interrupt sequence number, so that the interrupt service function and the interrupt event correspond to each other in order.
[0139] It should be noted that the "interrupt sequence number" of all non-kernel events corresponds to the pointer of the "middle software layer function", and the "interrupt sequence number" of the kernel event corresponds one-to-one with the pointer of its "default kernel event processing function".
[0140] Optionally, in order of interrupt sequence numbers, the array can be arranged as follows:
[0141] Pointer to "default kernel event processing function 0",
[0142] Pointer to "default kernel event processing function 1",
[0143] Pointer to "default kernel event processing function 2",
[0144] …
[0145] Pointer to "default kernel event processing function 15",
[0146] Pointer to the "middle software layer function",
[0147] Pointer to the "middle software layer function",
[0148] …
[0149] Pointer to the "middle software layer function".
[0150] S306, using the memory array as an interrupt vector table.
[0151] S103: Call the lower software layer function to determine the pointer of the interrupt service function in the interrupt active status register and the pre-built sub-interrupt vector table.
[0152] It should be noted that the lower software layer function depends on the CPU architecture, and the sub-interrupt vector table stores a large number of interrupt service function pointers. Specifically, when using the pre-built sub-interrupt vector table, the currently active interrupt vector number (IRQn) can be determined by calling the lower software layer function to read the value of the interrupt active status register, and then the interrupt vector number (IRQn) is used to determine the pointer of the interrupt service function from the pre-built sub-interrupt vector table.
[0153] Optionally, the embodiment of the present application provides a method for constructing a sub-interrupt vector table, such as Figure 4 As shown, the following steps are included:
[0154] S401. Obtain multiple interrupt sequence numbers of hardware and pointers to their corresponding interrupt service functions.
[0155] It should be noted that an interrupt sequence number corresponds to a pointer to an interrupt service function (ISR, provided by other Mcal software). Since the sub-interrupt vector table is composed of the interrupt sequence number and the pointer to the corresponding interrupt service function, it is necessary to obtain multiple interrupt sequence numbers of the hardware and the pointer to the corresponding interrupt service function in advance.
[0156] S402 , sorting the pointers of the interrupt service functions according to the interrupt sequence numbers to obtain a target sequence, and using the target sequence as a vector table.
[0157] It can be understood that the pointers of each interrupt service function are sorted in a one-to-one and orderly manner according to the order of the hardware interrupt sequence number (IRQn), and the sequence obtained after sorting is called a "vector table".
[0158] S403: Input multiple interrupt sequence numbers and the pointers of their corresponding interrupt service functions into the interface function to construct elements of a vector table.
[0159] Specifically, after obtaining the vector table, it is necessary to construct the elements in the vector table, so an interface (not dependent on the CPU architecture) function is added to the Platform module: input parameter 1 is the hardware interrupt sequence number, and input parameter 2 is the pointer to the interrupt service function. The elements of the "vector table" are constructed by inputting parameters 1 and 2 into the interface function.
[0160] S404: Store the elements of the vector table into the vector table to obtain a sub-interrupt vector table.
[0161] Specifically, by storing the elements of the constructed vector table in the vector table, a sub-interrupt vector table can be finally obtained.
[0162] Optionally, in another embodiment of the present application, a specific implementation of step S103 is as follows: Figure 5 As shown, the following steps are included:
[0163] S501 , calling a lower software layer function to query the currently active target interrupt sequence number in the interrupt activity status register.
[0164] It should be emphasized that the lower software layer function is used to query the interrupt activity status register for the currently active interrupt sequence number. Therefore, after the interrupt controller requests an interrupt from the kernel, the interrupt activity status register in the kernel can reflect the currently active target interrupt sequence number (IRQn).
[0165] S502: Determine a pointer to an interrupt service function corresponding to the target interrupt sequence number from a pre-built sub-interrupt vector table.
[0166] Specifically, based on the target interrupt sequence number (IRQn) obtained in step S501, the pre-built sub-interrupt vector table is indexed by the target interrupt sequence number (IRQn), and the pointer of the interrupt service function corresponding to the target interrupt sequence number can be determined from the sub-interrupt vector table.
[0167] S104: Check the validity of the pointer to the interrupt service function.
[0168] Specifically, in the execution step S104, an intermediate software layer (not dependent on the CPU architecture) function needs to be added to prevent the interrupt service function (ISR) pointer from being directly loaded when an interrupt occurs. Therefore, in this intermediate software layer function, the validity and security check of the pointer of the interrupt service function determined by the lower software layer function needs to be performed to prevent the CPU from erroneously jumping into an abnormal state.
[0169] Optionally, in another embodiment of the present application, a specific implementation of step S104 is as follows: Figure 6 As shown, the following steps are included:
[0170] S601, detecting whether the pointer of the interrupt service function is a null pointer.
[0171] Specifically, the purpose of checking whether the pointer of the interrupt service function is a null pointer is to ensure that it has been correctly initialized before calling the interrupt service function. If the pointer of the interrupt service function is a null pointer, it means that the interrupt handler is not associated with the corresponding interrupt sequence number, or an error occurs during the initialization process.
[0172] Because in actual applications, when an interrupt occurs, the system will find the pointer of the corresponding interrupt service function according to the interrupt sequence number and call the function to handle the interrupt. If the pointer of the interrupt service function is a null pointer, the system will not be able to handle the interrupt event correctly, which may cause unexpected errors and even cause the system to crash.
[0173] Therefore, by detecting whether the pointer of the interrupt service function is a null pointer, potential problems can be discovered in advance to avoid errors in the interrupt processing process. Therefore, if the pointer of the interrupt service function is a non-null pointer, it means that the interrupt service function has been correctly initialized, so step S602 is executed. If the pointer of the interrupt service function is a null pointer, it means that the interrupt service function has not been correctly initialized, so step S604 is executed.
[0174] S602: Check whether the pointer of the interrupt service function is in a valid range.
[0175] It should be noted that when the pointer of the interrupt service function is a non-null pointer, it is necessary to further detect whether the pointer of the interrupt service function is in a valid range, in order to ensure that when the interrupt service function is called, the function pointed to by the pointer does exist in the memory and can be executed correctly. Because under normal circumstances, the pointer of the interrupt service function should point to a defined and implemented function. If the function pointed to by the pointer does not exist or is not implemented correctly, it will cause an error when calling the function, which may cause a system crash or other problems. Therefore, if the pointer of the interrupt service function is in a valid range, it means that the function pointed to by the pointer can be executed correctly, so step S603 is executed. If the pointer of the interrupt service function is not in a valid range, it means that the function pointed to by the pointer cannot be executed correctly, so step S604 is executed.
[0176] S603: Determine whether the pointer of the interrupt service function passes the validity check.
[0177] S604: Determine whether the pointer to the interrupt service function fails the validity check.
[0178] Optionally, when the pointer of the interrupt service function is a null pointer, or the pointer of the interrupt service function is not in a valid range, it means that the pointer of the interrupt service function has not passed the validity check. At this time, feedback can be given to the front end so that the pointer of the interrupt service function can be processed accordingly.
[0179] S105: Determine whether the pointer of the interrupt service function passes the validity check.
[0180] It is understandable that if the pointer of the interrupt service function passes the validity check, step S106 is executed. Alternatively, if the pointer of the interrupt service function fails the validity check, the interrupt response is terminated.
[0181] S106. Call the interrupt service function through the pointer of the interrupt service function to execute the interrupt operation.
[0182] It should be noted that when the pointer of the interrupt service function passes the validity check, the interrupt service function (ISR) is called through the pointer of the interrupt service function to execute the upper-level functions of other Mcal software, thereby realizing the call of the upper-level software interrupt service function (ISR).
[0183] The present application provides a method for managing interrupts, which obtains an interrupt signal generated by hardware, and then based on the interrupt signal, uses an offset register to obtain a pointer to an intermediate software layer function from a pre-built interrupt vector table, and loads the pointer to the intermediate software layer function into an interrupt active status register, and then calls the lower software layer function to determine the pointer to the interrupt service function in the interrupt active status register and the pre-built sub-interrupt vector table, and finally performs a validity check on the pointer to the interrupt service function. If the pointer to the interrupt service function passes the validity check, the interrupt service function is called through the pointer to the interrupt service function to perform an interrupt operation. Since the present application is based on a RAM framework, the interrupt vector table and the sub-interrupt vector table are stored in RAM, and the RAM storage is safer than the FLASH storage of the prior art, so the interrupt vector table is not easily tampered with in RAM.
[0184] Another embodiment of the present application provides an interrupt management device, such as Figure 7 As shown, it includes the following units:
[0185] The signal acquisition unit 701 is used to acquire an interrupt signal generated by hardware.
[0186] The loading unit 702 is used to obtain the pointer of the middle software layer function from the pre-built interrupt vector table by using the offset register based on the interrupt signal, and load the pointer of the middle software layer function into the interrupt active status register.
[0187] The pointer determination unit 703 is used to call the lower software layer function to determine the pointer of the interrupt service function in the interrupt active status register and the pre-built sub-interrupt vector table.
[0188] The pointer checking unit 704 is used to check the validity of the pointer of the interrupt service function.
[0189] The function calling unit 705 is used to call the interrupt service function to execute the interrupt operation through the pointer of the interrupt service function if the pointer of the interrupt service function passes the validity check.
[0190] It should be noted that the specific working process of the above-mentioned units in the embodiment of the present application can refer to steps S101 to S106 in the above-mentioned method embodiment, and will not be repeated here.
[0191] Optionally, in another embodiment of the present application, an interrupt management device is provided, further comprising:
[0192] The first acquisition unit is used to acquire a pointer and an interrupt sequence number corresponding to a non-kernel event, and a pointer and an interrupt sequence number corresponding to a kernel event.
[0193] Building blocks, used to construct arrays.
[0194] The filling unit is used to fill the pointer corresponding to the kernel event with the pointer of the default kernel event processing function, and to fill the pointer corresponding to the non-kernel event with the pointer of the intermediate software layer function.
[0195] The first storage unit is used to store the filled kernel events and non-kernel events into an array.
[0196] The first sorting unit is used to sort the non-kernel events filled in the array according to the interrupt sequence numbers corresponding to the non-kernel events, and sort the kernel events filled in the array according to the interrupt sequence numbers corresponding to the kernel events to obtain a memory array.
[0197] As a unit, used to use the memory array as an interrupt vector table.
[0198] Optionally, in another embodiment of the present application, an interrupt management device is provided, further comprising:
[0199] The second acquisition unit is used to acquire multiple interrupt sequence numbers of the hardware and pointers of their corresponding interrupt service functions.
[0200] The second sorting unit is used to sort the pointers of each interrupt service function according to each interrupt sequence number to obtain a target sequence, and use the target sequence as a vector table.
[0201] The input unit is used to input multiple interrupt sequence numbers and pointers of their corresponding interrupt service functions into the interface function to construct elements of the vector table.
[0202] The second storage unit is used to store the elements of the vector table into the vector table to obtain a sub-interrupt vector table.
[0203] Optionally, in an interrupt management device provided in another embodiment of the present application, the pointer determination unit 703 includes:
[0204] The query unit is used to call the lower software layer function to query the currently active target interrupt sequence number in the interrupt active status register.
[0205] The first determining unit is used to determine a pointer of an interrupt service function corresponding to a target interrupt sequence number from a pre-built sub-interrupt vector table.
[0206] Optionally, in an interrupt management device provided in another embodiment of the present application, the pointer checking unit 704 includes:
[0207] The first detection unit is used to detect whether the pointer of the interrupt service function is a null pointer.
[0208] The second detection unit is used to detect whether the pointer of the interrupt service function is in a valid range if the pointer of the interrupt service function is not a null pointer.
[0209] The second determining unit is used to determine whether the pointer of the interrupt service function passes the validity check if the pointer of the interrupt service function is in a valid range.
[0210] The third determining unit is used to determine that the pointer of the interrupt service function fails the validity check if the pointer of the interrupt service function is a null pointer or the pointer of the interrupt service function is not in a valid range.
[0211] Optionally, in another embodiment of the present application, an interrupt management device is provided, further comprising:
[0212] The checking unit is used to check whether all Mcal software have been initialized.
[0213] The execution unit is used to use the interface function to call the configuration set to execute the interrupt registration function if all Mcal software are not initialized. The configuration set is preliminarily obtained by calling the generation tool through the Platform module to configure the configuration file.
[0214] The fourth determining unit is used to determine that the initialization of all Mcal software is completed if all Mcal software has been initialized.
[0215] It should be noted that the specific working process of each unit provided in the above embodiments of the present application can refer to the corresponding steps in the above method embodiments, and will not be repeated here.
[0216] In summary, another embodiment of the present application provides an interrupt management device, a Mcal software interrupt management method based on the Autosar architecture, which centrally manages interrupts by the Platform module, effectively avoiding the conflict problem when the same external interrupt is used by multiple Mcal software, and the interrupt vector table is maliciously tampered with, which is difficult to detect and leads to potential safety issues in the product.
[0217] Professionals may further appreciate that the units and algorithm steps of each example described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, computer software, or a combination of the two. In order to clearly illustrate the interchangeability of hardware and software, the composition and steps of each example have been generally described in the above description according to function. Whether these functions are performed in hardware or software depends on the specific application and design constraints of the technical solution. Professionals and technicians may use different methods to implement the described functions for each specific application, but such implementation should not be considered to be beyond the scope of this application.
[0218] The above description of the disclosed embodiments enables those skilled in the art to implement or use the present application. Various modifications to these embodiments will be apparent to those skilled in the art, and the general principles defined herein may be implemented in other embodiments without departing from the spirit or scope of the present application. Therefore, the present application will not be limited to the embodiments shown herein, but will conform to the widest scope consistent with the principles and novel features disclosed herein.
Claims
1. A method for managing interruption, characterized in that: include: Get the interrupt signal generated by the hardware; Based on the interrupt signal, using an offset register to obtain a pointer to an intermediate software layer function from a pre-built interrupt vector table, and loading the pointer to the intermediate software layer function into an interrupt active status register; Calling a lower software layer function to determine a pointer to an interrupt service function in the interrupt active status register and a pre-built sub-interrupt vector table; Performing validity check on the pointer of the interrupt service function; If the pointer of the interrupt service function passes the validity check, the interrupt service function is called through the pointer of the interrupt service function to perform an interrupt operation.
2. The method according to claim 1, characterized in that The method for constructing the interrupt vector table comprises: Get the pointer and interrupt sequence number corresponding to the non-kernel event, as well as the pointer and interrupt sequence number corresponding to the kernel event; Build arrays; Filling the pointer corresponding to the kernel event with the pointer of the default kernel event processing function, and filling the pointer corresponding to the non-kernel event with the pointer of the intermediate software layer function; Storing the filled kernel events and non-kernel events into the array; The non-kernel events filled in the array are sorted according to the interrupt sequence numbers corresponding to the non-kernel events, and the kernel events filled in the array are sorted according to the interrupt sequence numbers corresponding to the kernel events to obtain a memory array; The memory array is used as an interrupt vector table.
3. The method according to claim 1, characterized in that The method for constructing the sub-interrupt vector table includes: Get multiple interrupt sequence numbers of the hardware and pointers to their corresponding interrupt service functions; According to each of the interrupt sequence numbers, the pointers of each of the interrupt service functions are sorted to obtain a target sequence, and the target sequence is used as a vector table; Inputting a plurality of interrupt sequence numbers and pointers of their corresponding interrupt service functions into the interface function to construct elements of the vector table; The elements of the vector table are stored in the vector table to obtain a sub-interrupt vector table.
4. The method according to claim 1, characterized in that: The calling of the lower software layer function to determine the pointer of the interrupt service function in the interrupt active status register and the pre-built sub-interrupt vector table includes: Calling a lower software layer function to query the currently active target interrupt sequence number in the interrupt active status register; A pointer to an interrupt service function corresponding to the target interrupt sequence number is determined from a pre-constructed sub-interrupt vector table.
5. The method according to claim 1, characterized in that The checking of the validity of the pointer of the interrupt service function comprises: Detect whether the pointer of the interrupt service function is a null pointer; If the pointer of the interrupt service function is a non-null pointer, detecting whether the pointer of the interrupt service function is in a valid range; If the pointer of the interrupt service function is within the valid range, determining that the pointer of the interrupt service function passes the validity check; If the pointer of the interrupt service function is a null pointer, or the pointer of the interrupt service function is not in the valid range, it is determined that the pointer of the interrupt service function fails the validity check.
6. The method according to claim 1, characterized in that Also includes: Check whether all Mcal software has been initialized; If all the Mcal software are not initialized, the interface function is used to call the configuration set to execute the interrupt registration function; wherein the configuration set is preliminarily obtained by calling the generation tool through the Platform module to configure the configuration file; If all the Mcal software have been initialized, it is determined that the initialization of all the Mcal software is completed.
7. An interrupt management device, characterized in that: include: A signal acquisition unit, used to acquire an interrupt signal generated by hardware; A loading unit, configured to obtain a pointer of an intermediate software layer function from a pre-built interrupt vector table using an offset register based on the interrupt signal, and load the pointer of the intermediate software layer function into an interrupt active status register; A pointer determination unit, used to call a lower software layer function to determine a pointer of an interrupt service function in the interrupt active status register and a pre-built sub-interrupt vector table; A pointer checking unit, used for checking the validity of the pointer of the interrupt service function; The function calling unit is used to call the interrupt service function to perform an interrupt operation through the pointer of the interrupt service function if the pointer of the interrupt service function passes the validity check.
8. The device according to claim 7, characterized in that Also includes: A first acquisition unit, used for acquiring a pointer and an interrupt sequence number corresponding to a non-kernel event, and a pointer and an interrupt sequence number corresponding to a kernel event; Construction unit, used to build arrays; A filling unit, used to fill the pointer corresponding to the kernel event with the pointer of the default kernel event processing function, and to fill the pointer corresponding to the non-kernel event with the pointer of the intermediate software layer function; A first storage unit, used for storing the filled kernel events and non-kernel events into the array; A first sorting unit is used to sort the non-kernel events filled in the array according to the interrupt sequence numbers corresponding to the non-kernel events, and sort the kernel events filled in the array according to the interrupt sequence numbers corresponding to the kernel events, so as to obtain a memory array; The memory array is used as an interrupt vector table.
9. The device according to claim 7, characterized in that Also includes: A second acquisition unit is used to acquire a plurality of interrupt sequence numbers of the hardware and pointers of their corresponding interrupt service functions; A second sorting unit is used to sort the pointers of each interrupt service function according to each interrupt sequence number to obtain a target sequence, and use the target sequence as a vector table; An input unit, used for inputting a plurality of interrupt sequence numbers and pointers of their corresponding interrupt service functions into the interface function to construct elements of the vector table; The second storage unit is used to store the elements of the vector table into the vector table to obtain a sub-interrupt vector table.
10. The device according to claim 7, characterized in that The pointer determination unit comprises: A query unit, used for calling a lower software layer function to query the currently active target interrupt sequence number in the interrupt active status register; The first determining unit is used to determine a pointer of an interrupt service function corresponding to the target interrupt sequence number from a pre-built sub-interrupt vector table.
Citation Information
Cited By
Hardware equipment management system based on resource sovereign model and control method thereof
CN122470423A
A hardware device management system based on a resource sovereignty model and a control method thereof
CN122470423B
