An interrupt service method and device for startup loading of an embedded system

By defining global variable judgments in the embedded system to determine the running status of the Bootloader and App, it solves the problem that the processor without interrupt vector offset register cannot use interrupt resources, achieves accurate use of interrupt resources and improves system update efficiency. .

CN112395065BActive Publication Date: 2024-09-13HUBEI KAIT AUTOMOTIVE ELECTRONICS & ELECTRICAL SYST
View PDF 5 Cites 0 Cited by

Patent Information

Application Number
CN202011348632.9
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2020-11-26
Publication Date
2024-09-13
Estimated Expiration
2040-11-26

AI Technical Summary

Technical Problem

Processors without interrupt vector offset registers cannot use interrupt resources in the Bootloader segment and App segment respectively, resulting in low update efficiency and inaccurate interrupt program returns.

Method used

By defining a global variable judgment value in the program storage space of the Bootloader and App, initializing and changing its value to judge the current running status, and performing corresponding push and pop processing when an interrupt occurs, ensuring the accuracy and accuracy of interrupt service Proper use of resources.

Benefits of technology

It realizes the ability to use interrupt resources in both the Bootloader and App segments, improves the efficiency of system updates, and ensures the accurate return of interrupt programs.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN112395065B
    Figure CN112395065B
Patent Text Reader

Abstract

The present invention relates to an interrupt service method for startup loading of an embedded system, comprising the following steps: defining a global variable named a judgment value at the same absolute address in the program storage space of the Bootloader and the App; initializing the judgment value to a first set value when the Bootloader is running, and setting the judgment value to a second set value when it is necessary to jump to the App; setting the judgment value to the first set value when it is necessary to jump to the Bootloader when the App is running; and implementing the interrupt service for startup loading of the embedded system based on the judgment value. The present invention can realize the startup loading of a processor without an interrupt vector offset, and interrupt resources can be used in both the Bootloader segment and the App segment respectively.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the technical field of embedded system startup loading, and in particular to an interrupt service method, device and computer storage medium for embedded system startup loading. Background Art

[0002] Based on a processor with IAP function, by implementing the Bootloader function, the product can realize the function of updating software in the system through communication methods such as communication bus. The processor's on-chip Flash is divided into 2 parts (the size depends on the needs), the first half is the Bootloader area, and the second half is the App area. After the processor is powered on, it first enters the Bootloader segment to run, and checks whether there is a correct App segment program. If there is, it will immediately jump to the App to run; otherwise, it stays in the Bootloader segment and waits to communicate with the download device to update the App segment program. When the App segment is running, the processor can also jump to the Bootloader segment again through diagnostic commands and other means to start updating the App segment software.

[0003] For processors without interrupt vector offset registers, the interrupt entry can be relocated to the App segment by setting the offset address; however, for processors without interrupt vector offset registers, the interrupt entry address cannot be offset and can only remain in the Bootloader segment. Programs in the App segment generally need to use interrupt resources, which means that the Bootloader will not be able to use interrupt resources. And every time the App is updated, the interrupt vector table of the App must be copied and replaced with the interrupt vector table of the Bootloader segment. Figure 2a As shown in the figure, ① an interrupt occurs when the App segment is executed, ② jumps to the interrupt service function of the App, ③ the interrupt returns and the App segment continues to be executed, and ④ the interrupt vector table of the App is copied and replaced by the interrupt vector table of the Bootloader segment. At the same time, the Bootloader segment program should be locked after being burned in the factory to prevent accidental erasure, which is inconsistent with the point that "the interrupt vector table of the App copies and replaces the interrupt vector table of the Bootloader segment". In addition, the Bootloader cannot use interrupt resources, and the communication process can only be polled continuously, which will greatly reduce the efficiency. Summary of the invention

[0004] In view of this, it is necessary to provide an interrupt service method and device for startup loading of an embedded system, so as to solve the problem that a processor without an interrupt vector offset register cannot use interrupt resources in the Bootloader segment and the App segment respectively.

[0005] The present invention provides an interrupt service method for startup loading of an embedded system, comprising the following steps:

[0006] Define a global variable named judgment value at the same absolute address in the program storage space of Bootloader and App;

[0007] When the Bootloader is running, the judgment value is initialized to a first set value, and when it is necessary to jump to the App, the judgment value is set to a second set value;

[0008] When the App is running, when it is necessary to jump to the Bootloader, the judgment value is set to the first set value;

[0009] Based on the judgment amount, an interrupt service for startup loading of the embedded system is implemented.

[0010] Further, the first setting value is "0", and the second setting value is "1"; or, the first setting value is "1", and the second setting value is "0".

[0011] Further, based on the judgment amount, an interrupt service for startup loading of the embedded system is implemented, specifically including:

[0012] An interrupt service in the Bootloader and an interrupt service in the App are implemented based on the judgment amount.

[0013] Further, based on the judgment amount, the interrupt service in the Bootloader is implemented, specifically:

[0014] If an interruption occurs during the operation of the Bootloader, it is determined whether the judgment amount is a second set value: if so, the service function address corresponding to the interrupt vector table in the App is loaded, and then a jump instruction is used to jump to the service function address for execution; if not, the computing resources are manually pushed into the stack first, and then the interrupt service sub-function of the Bootloader is called, and finally the computing resources are manually popped out of the stack.

[0015] Further, using a jump instruction to jump to the service function address for execution also includes:

[0016] When jumping to the service function address and running, the interrupt resources used by the Bootloader are closed.

[0017] Further, based on the judgment amount, the interruption service in the App is implemented, specifically:

[0018] The compiler pushes the computing resources needed for the interrupt service in the App into the stack;

[0019] Call the interrupt service subroutine of the App, and use the compiler to pop the computing resources needed for the interrupt service in the App from the stack before the interrupt returns;

[0020] Use the linker to add the address of the interrupt service sub-function of the App to the address of the corresponding terminal type in the interrupt vector table of the App.

[0021] The present invention also provides an interrupt service device for startup loading of an embedded system, comprising a processor and a memory, wherein a computer program is stored in the memory, and when the computer program is executed by the processor, an interrupt service method for startup loading of the embedded system is implemented.

[0022] The present invention also provides a computer storage medium on which a computer program is stored. When the computer program is executed by a processor, the interrupt service method for startup loading of the embedded system is implemented.

[0023] Beneficial effect: The present invention sets a judgment amount, and the value of the judgment amount can be used to determine whether the interrupt occurs when the App is running or when the Bootloader is running, thereby facilitating accurate judgment of the interrupt location and corresponding stack push / pop processing when the interrupt occurs, thereby ensuring accurate return of the interrupt program and ensuring that both the Bootloader and the App can use interrupt resources. BRIEF DESCRIPTION OF THE DRAWINGS

[0024] Figure 1 A method flow chart of a first embodiment of an interrupt service method for startup loading of an embedded system provided by the present invention;

[0025] Figure 2a A schematic diagram of program counter pointing changes when implementing an interrupt service during startup loading for a processor without an interrupt vector offset register in the prior art;

[0026] Figure 2b A schematic diagram of program counter pointing changes for implementing Bootloader interrupts in the first embodiment of the interrupt service method for startup loading of an embedded system provided by the present invention;

[0027] Figure 2c A schematic diagram of program counter pointing changes for implementing App interrupts in the first embodiment of the interrupt service method for startup loading of an embedded system provided by the present invention;

[0028] Figure 3a A calling program diagram of the interrupt service sub-function of Bootloader when starting loading is implemented for the first embodiment of the interrupt service method for embedded system startup loading provided by the present invention;

[0029] Figure 3bThe present invention provides a disassembly diagram of the interrupt service sub-function of Bootloader that is called during startup loading in the first embodiment of the interrupt service method for embedded system startup loading. DETAILED DESCRIPTION

[0030] The preferred embodiments of the present invention are described in detail below in conjunction with the accompanying drawings, wherein the accompanying drawings constitute a part of this application and are used together with the embodiments of the present invention to illustrate the principles of the present invention, but are not used to limit the scope of the present invention.

[0031] Example 1

[0032] like Figure 1 As shown, embodiment 1 of the present invention provides an interrupt service method for startup loading of an embedded system, hereinafter referred to as the method, comprising the following steps:

[0033] S1. Define a global variable named judgment quantity at the same absolute address in the program storage space of Bootloader and App;

[0034] S2. When the Bootloader is running, the judgment value is initialized to a first set value, and when it is necessary to jump to the App, the judgment value is set to a second set value;

[0035] S3. When the App is running, when it is necessary to jump to the Bootloader, the judgment value is set to the first set value;

[0036] S4. Implementing an interrupt service for startup loading of the embedded system based on the judgment amount.

[0037] In this embodiment, a global variable named IsInApp (i.e., judgment value) is defined at the same absolute address in the Bootloader and App to indicate whether the current program is running in the Bootloader or in the App. In the Bootloader program, it is initialized to the first setting value, so when IsInApp is the first setting value, it means that it is running in the Bootloader. When it is necessary to jump to the App runtime, it is set to the second setting value, so when IsInApp is the second setting value, it means that it is running in the App. In the App program, it is defined as not initialized. In this way, when jumping from the Bootloader, its value is the second setting value. When it is necessary to jump to the Bootloader runtime, it is set to the first setting value, indicating that it returns to run in the Bootloader. For example, the sample code in the Bootloader project: unsigned char IsInApp@0x10=0; the sample code in the App project: __no_init unsigned char IsInApp@0x10.

[0038] Since the global variable IsInApp is set, when an interrupt occurs, it can be determined whether the interrupt occurs during the App runtime or the Bootloader runtime, thereby accurately determining the interrupt location and facilitating the corresponding stack push / pop processing when the interrupt occurs, thereby ensuring the accurate return of the interrupt program and ensuring that both the Bootloader and the App can use interrupt resources. This method aims to enable a processor based on a non-interrupt vector offset register to use interrupt resources in both the Bootloader segment and the App segment, and the Bootloader segment can also be locked.

[0039] Preferably, the first setting value is "0" and the second setting value is "1"; or, the first setting value is "1" and the second setting value is "0".

[0040] In this embodiment, the first set value is "0" and the second set value is "1".

[0041] Preferably, implementing the interrupt service of startup loading of the embedded system based on the judgment amount specifically includes:

[0042] An interrupt service in the Bootloader and an interrupt service in the App are implemented based on the judgment amount.

[0043] Preferably, the interrupt service in the Bootloader is implemented based on the judgment amount, specifically:

[0044] If an interruption occurs during the operation of the Bootloader, it is determined whether the judgment amount is a second set value: if so, the service function address corresponding to the interrupt vector table in the App is loaded, and then a jump instruction is used to jump to the service function address for execution; if not, the computing resources are manually pushed onto the stack first, and then the interrupt service sub-function of the Bootloader is called, and finally the computing resources are manually popped off the stack.

[0045] The interrupt service function in the Bootloader immediately determines the IsInApp variable after entering. If IsInApp is 1, the nested assembly code is used to load the address of the corresponding service function in the interrupt vector table of the App, and then the jump instruction is used to jump to the address to run. In this way, the interrupt service function of the App is executed, and the interrupt return is executed correctly after completion. Note: After loading the service function address of the App, the jump instruction must be used, and the CALL instruction cannot be used, otherwise the stack will be unbalanced when the function returns, and the processor will run away. If IsInApp is 0, the interrupt service sub-function of the Bootloader is called, but the direct call will cause the stack to be unbalanced when the interrupt service function of the App returns. When the interrupt service sub-function of the Bootloader is called directly, the compiler will first push the computing resources needed by the sub-function into the stack when compiling, and then determine IsInApp to decide the branch. So for the case where IsInApp is 1 and the App interrupt service is running, the interrupt return directly from the App interrupt service will cause the stack of this path to be unbalanced, and the processor will run away. Therefore, the interrupt service sub-function of the Bootloader cannot be called directly. To solve this problem, this embodiment first uses nested assembly to manually push all computing resources into the stack, then uses embedded assembly to call the service sub-function, and finally manually pops the stack to restore the computing resources. The computing resources are determined according to the characteristics of the processor and compiler. The specific implementation code is as follows: Figure 3a As shown, the disassembled code is as follows Figure 3b When an interrupt occurs in the Bootloader, the program counter points to the reverse change as shown in Figure 2b As shown, ① an interrupt occurs when the Bootloader segment is executed, ② jumps to the Bootloader's interrupt service function according to the interrupt vector table, ③ jumps to the Bootloader's interrupt service sub-function according to IsInApp, ④ the Bootloader's interrupt service sub-function completes execution and returns, ⑤ the interrupt returns and the Bootloader segment continues to execute.

[0046] Preferably, using a jump instruction to jump to the service function address for execution further includes:

[0047] When jumping to the service function address and running, the interrupt resources used by the Bootloader are closed.

[0048] Preferably, the interruption service in the App is implemented based on the judgment amount, specifically:

[0049] The compiler pushes the computing resources needed for the interrupt service in the App into the stack;

[0050] Call the interrupt service subroutine of the App, and use the compiler to pop the computing resources needed for the interrupt service in the App from the stack before the interrupt returns;

[0051] Use the linker to add the address of the interrupt service sub-function of the App to the address of the corresponding terminal type in the interrupt vector table of the App.

[0052] The interrupt service function is written normally in the App. The compiler will immediately push the computing resources that the interrupt service function will need to use into the stack and restore them before the interrupt returns; it will use the interrupt return instead of the normal return. The linker will add the address of the service function to the specified address of the corresponding interrupt type in the interrupt vector table of the App. When an interrupt occurs in the App, the program counter points to the reverse change. Figure 2c As shown in the figure, ① an interrupt occurs when the App segment is executed, ② jumps to the interrupt service function of the Bootloader according to the interrupt vector table, ③ jumps to the interrupt service function of the App according to IsInApp, ④ the interrupt returns and the App segment continues to be executed.

[0053] Example 2

[0054] Embodiment 2 of the present invention provides an interrupt service device for startup loading of an embedded system, comprising a processor and a memory, wherein the memory stores a computer program, and when the computer program is executed by the processor, the interrupt service method for startup loading of an embedded system provided in embodiment 1 is implemented.

[0055] The interrupt service device for startup loading of an embedded system provided in an embodiment of the present invention is used to implement the interrupt service method for startup loading of an embedded system. Therefore, the technical effects possessed by the interrupt service method for startup loading of an embedded system are also possessed by the interrupt service device for startup loading of an embedded system, which will not be repeated here.

[0056] Example 3

[0057] Embodiment 3 of the present invention provides a computer storage medium on which a computer program is stored. When the computer program is executed by a processor, the interrupt service method for startup loading of an embedded system provided in Embodiment 1 is implemented.

[0058] The computer storage medium provided by the embodiment of the present invention is used to implement the interrupt service method for startup loading of an embedded system. Therefore, the technical effects possessed by the interrupt service method for startup loading of an embedded system are also possessed by the computer storage medium and will not be described in detail here.

[0059] The above description is only a preferred specific implementation manner of the present invention, but the protection scope of the present invention is not limited thereto. Any changes or substitutions that can be easily conceived by any technician familiar with the technical field within the technical scope disclosed by the present invention should be covered within the protection scope of the present invention.

Claims

1. An interrupt service method for startup loading of an embedded system, It is characterized in that The following steps are involved: Define a global variable named judgment value at the same absolute address in the program storage space of Bootloader and App; When the Bootloader is running, the judgment value is initialized to a first set value, and when it is necessary to jump to the App, the judgment value is set to a second set value; When the App is running, when it is necessary to jump to the Bootloader, the judgment value is set to the first set value; Implementing an interrupt service for startup loading of the embedded system based on the judgment amount; Implementing an interrupt service for startup loading of an embedded system based on the judgment amount includes: Implementing an interrupt service in the Bootloader and an interrupt service in the App based on the judgment amount; Implementing an interrupt service in the Bootloader based on the judgment amount includes: If an interruption occurs during the operation of the Bootloader, it is determined whether the judgment amount is a second set value: if so, the service function address corresponding to the interrupt vector table in the App is loaded, and then a jump instruction is used to jump to the service function address for execution; if not, the computing resources are manually pushed into the stack first, and then the interrupt service sub-function of the Bootloader is called, and finally the computing resources are manually popped out of the stack.

2. The interrupt service method for startup loading of an embedded system according to claim 1, It is characterized in that The first setting value is "0" and the second setting value is "1"; or, the first setting value is "1" and the second setting value is "0".

3. The interrupt service method for booting and loading an embedded system according to claim 1, It is characterized in that Using a jump instruction to jump to the service function address for execution, further comprising: When jumping to the service function address and running, the interrupt resources used by the Bootloader are closed.

4. The interrupt service method for boot loading of an embedded system according to claim 1, It is characterized in that Implementing the interruption service in the App based on the judgment amount is specifically as follows: The compiler pushes the computing resources needed for the interrupt service in the App into the stack; Call the interrupt service subroutine of the App, and use the compiler to pop the computing resources needed for the interrupt service in the App from the stack before the interrupt returns; Use the linker to add the address of the App's interrupt service sub-function to the address of the corresponding interrupt type in the App's interrupt vector table.

5. An interrupt service device for startup loading of an embedded system, It is characterized in that The invention comprises a processor and a memory, wherein a computer program is stored in the memory, and when the computer program is executed by the processor, the interrupt service method for startup loading of an embedded system as claimed in any one of claims 1 to 4 is implemented.

6. A computer storage medium having a computer program stored thereon, It is characterized in that When the program of the computer is executed by the processor, the interrupt service method for startup loading of the embedded system as described in any one of claims 1 to 4 is implemented.

Citation Information

Patent Citations

  • Compiler optimization method based on vector interrupt

    CN105117269A

  • BootLoader program debugging method and system based on HCS12 single-chip microcomputer

    CN107153613A

  • Remote ARM online upgrading system and method based on RS422 interface

    CN110209531A

  • Program upgrading system, method and device based on NB-IoT module and storage medium

    CN111897560A

  • Methods and apparatus for software provisioning of a network device

    US20080134165A1