Method and device for field protection triggered by interruption of single-chip microcomputer application program
By backing up the application and interrupt handler variables during the startup and interrupt process of microcontroller application, the instability of data variables during interrupt processing is solved, and data consistency and continuity protection before and after interrupt execution is achieved.
Patent Information
- Application Number
- CN202210900815.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-07-28
- Publication Date
- 2025-08-26
- Estimated Expiration
- 2042-07-28
AI Technical Summary
During the interrupt processing of microcontroller applications, application data and register variables may change unexpectedly, resulting in execution exceptions.
Read variables and backup when the application starts, stop running and back up again when the interrupt handler completes, and back up again by dividing memory space and using backup recovery identifiers to protect variables.
Ensure that the variable values of the application and interrupt handler are unchanged before and after interrupts, achieve complete data field protection, and ensure the continuity of the application and interrupt handler.
Smart Images

Figure CN115114006B_ABST
Abstract
Description
Technical Field
[0001] The present invention belongs to the technical field of program processing, and in particular relates to a method and device for triggering on-site protection by interruption of a single-chip microcomputer application program, as well as a storage medium and a computer device. Background Art
[0002] Applications for microcontrollers or embedded devices typically run directly on bare-metal hardware, without an operating system or management software coordinating the calls and responses between the hardware and the application. To implement various real-time functions, applications require external interaction through interrupts. Interrupts typically utilize interrupt pins in the system hardware and the processor's interrupt response function. When the interrupt pin level changes or other physical events occur, the interrupt handler is transmitted to the processor's interrupt response bus, invoking the programmed interrupt handler. Because the processor typically responds to external interrupts from the interrupt hardware while executing certain applications, and this response is typically required to be very fast, data variables and register variables used by the executing application may change after the interrupt completes. This is because the interrupt handler may access application data or registers during the execution of the interrupt. If data or registers change when the application resumes execution after the interrupt, unexpected issues may occur. Effectively addressing these issues and ensuring that applications continue to execute normally after an interrupt completes is a pressing issue. Summary of the Invention
[0003] In view of the defects in the prior art, the present invention provides a method for triggering field protection by interruption of a single-chip microcomputer application program, which can effectively solve the above problems.
[0004] The embodiment of the present invention provides a method and device for triggering field protection by interruption of a single-chip microcomputer application program, as well as a storage medium and a computer device.
[0005] According to one aspect of an embodiment of the present invention, a method for triggering context protection by interruption of a single-chip microcomputer application is provided, comprising the following steps:
[0006] When the application is started, the application variables that support the running of the application are read, and the application is run according to the read application variables;
[0007] When an interruption occurs during the running of an application, the application is stopped, the latest values of the application variables used in the running of the application are read and backed up, and the application site is protected;
[0008] Read the interrupt handler variables that support the execution of this interrupt handler, and execute the interrupt handler according to the read interrupt handler variables;
[0009] When the interrupt handler is finished executing, the latest value of the interrupt handler variable used by the interrupt handler is read and backed up to perform interrupt handler scene protection;
[0010] Read the latest values of the backed-up application variables and continue running the application.
[0011] Optionally, in the above-mentioned embodiments of the method of the present invention, the system memory space includes four areas, namely: an application site data storage area, an interruption persistent data storage area, an in-running data storage area, and a backup and recovery identification storage area;
[0012] A backup and recovery identification storage area for storing application variable identifications of application variables used in application program execution, and interrupt handler variable identifications of interrupt handler variables used in interrupt handler execution;
[0013] An application on-site data storage area is used to store application variables corresponding to the application variable identifier stored in the backup and recovery identifier storage area;
[0014] An interrupt persistent data storage area, used for storing interrupt handler variables corresponding to the interrupt handler variable identifier stored in the backup recovery identifier storage area;
[0015] The running data storage area is used to read the corresponding application variables stored in the application site data storage area according to the application variable identifier stored in the backup and recovery identification storage area, and write the read application variables into the running data storage area, thereby running the application; or to read the corresponding interrupt handler variables stored in the interrupt persistent data storage area according to the interrupt handler variable identifier stored in the backup and recovery identification storage area, and write the read interrupt handler variables into the running data storage area, thereby running the interrupt handler.
[0016] Optionally, in the above-mentioned embodiments of the method of the present invention, the backup and recovery identification storage area includes two sub-areas, namely: an application backup and recovery identification sub-area and an interrupted continuous data backup and recovery identification sub-area;
[0017] The application backup and recovery identification sub-area stores the application variable identification;
[0018] The interruption continuous data backup and recovery identification sub-area stores the interruption processing program variable identification.
[0019] Optionally, in the above-mentioned embodiments of the method of the present invention, the application variable identifier includes a data variable identifier and a register variable identifier that support the running of the application;
[0020] The interrupt handler variable identifier includes a data variable identifier and a register variable identifier that support the operation of the interrupt handler.
[0021] Optionally, in the above-mentioned method embodiments of the present invention, the register variable identifier of the application variable identifier and the register variable identifier of the interrupt handler variable identifier both include: a normal register variable identifier, a current instruction position register variable identifier, a top of stack register variable identifier and a control register variable identifier.
[0022] Optionally, in each of the above-mentioned method embodiments of the present invention, the application variable identifier includes: the application variable name, the address offset of the application variable in the application field data storage area, the interrupt number corresponding to the application variable, and the application variable state; wherein the application variable state includes: a state to be backed up and a state to be restored;
[0023] When the application starts, the application variables that support the application are read, and the application is run according to the read application variables, specifically:
[0024] When the application is started, the backup and recovery identification storage area is read to obtain the application variable identification corresponding to the current interrupt number and the status to be backed up;
[0025] According to each application variable identifier read, the address offset and application variable name of the corresponding application variable in the application site data storage area are obtained;
[0026] Read the corresponding application variable from the application on-site data storage area according to the obtained address offset of the application variable in the application on-site data storage area and the application variable name, and write the read application variable to the running data storage area;
[0027] Run the application based on the application variables in the running data store;
[0028] When an interruption occurs during the application's operation, the application is stopped, the latest values of the application variables used in the application are read and backed up, and the application site is protected. Specifically:
[0029] Set the interrupt number for this time;
[0030] When an interruption occurs during the running of the application, the running of the application is stopped, and the application variable identifiers of the application variables used in the current running of the application are obtained to form an application variable identifier set;
[0031] Modify the status of each application variable identifier belonging to the application variable identifier set in the backup recovery identifier storage area to the waiting-for-recovery status, and modify the interrupt number corresponding to the application variable to the current interrupt number;
[0032] According to the application variable identifiers corresponding to the interruption number in each state to be restored, the address offset and application variable name of the corresponding application variable in the application field data storage area are obtained;
[0033] Based on the address offset and application variable name of the obtained application variable in the application field data storage area, the corresponding application variable is read from the application field data storage area, and the content of each read application variable is updated to the current latest value. The current latest value of the application variable is stored in the application field data storage area to achieve backup and perform application field protection.
[0034] Optionally, in the above-mentioned method embodiments of the present invention, the latest value of the backed-up application variable is read and the application is continued to run, specifically:
[0035] Read the backup recovery identification storage area to obtain the application variable identification of each state to be restored corresponding to the current interrupt number;
[0036] According to each application variable identifier read, the address offset and application variable name of the corresponding application variable in the application site data storage area are obtained;
[0037] Read the corresponding application variables from the application on-site data storage area according to the address offset and application variable name of the application variables in the application on-site data storage area, and write the read application variables to the running data storage area; and modify the identifier of each read application variable to a state to be backed up;
[0038] Based on the application variables in the running data storage area, the application is restored and continued to run, completing the on-site recovery of the interruption.
[0039] Optionally, in each of the above-mentioned method embodiments of the present invention, the interrupt handler variable identifier includes: the interrupt handler variable name, the address offset of the interrupt handler variable in the interrupt persistent data storage area, the interrupt number corresponding to the interrupt handler variable, and the interrupt handler variable state; wherein the interrupt handler variable state includes: a state to be backed up and a state to be restored;
[0040] Read the interrupt handler variables that support the execution of this interrupt handler, and run the interrupt handler according to the read interrupt handler variables, specifically:
[0041] Read the backup recovery identification storage area to obtain the interrupt handler variable identification of the state to be restored;
[0042] Modify the interrupt number identified by the interrupt handler variable in the state to be restored to the current interrupt number;
[0043] According to the read interrupt handler variable identifier of the to-be-restored state, the address offset of the corresponding interrupt handler variable in the interrupt persistent data storage area and the interrupt handler variable name are obtained;
[0044] Read the corresponding interrupt handler variable from the interrupt persistent data storage area according to the obtained address offset of the interrupt handler variable in the interrupt persistent data storage area and the interrupt handler variable name, and write the read interrupt handler variable to the running data storage area; and modify the interrupt handler variable identifier in the backup and restore identifier storage area that belongs to the current interrupt number in the to-be-restored state to the to-be-backed-up state;
[0045] Run the interrupt handler according to the interrupt handler variables in the running data storage area;
[0046] When the interrupt handler is finished executing, the latest value of the interrupt handler variable used by the interrupt handler is read and backed up to perform interrupt handler scene protection, specifically:
[0047] When the execution of the current interrupt handler is completed, the interrupt handler variable identifier of the interrupt handler variable used by the current interrupt handler is obtained to form an interrupt handler variable identifier set;
[0048] According to each interrupt handler variable identifier in the interrupt handler variable identifier set, obtain the address offset and interrupt handler variable name of the corresponding interrupt handler variable in the interrupt persistent data storage area;
[0049] According to the obtained address offset of the interrupt handler variable in the interrupt persistent data storage area and the interrupt handler variable name, the corresponding interrupt handler variable is read from the interrupt persistent data storage area, and the content of the read interrupt handler variable is updated to the current latest value. The current latest value of the interrupt handler variable is stored in the interrupt persistent data storage area to complete the backup and realize the interrupt handler scene protection;
[0050] Then, the state of each interrupt processing program variable identifier in the interrupt processing program variable identifier set is modified to a to-be-recovered state.
[0051] According to another aspect of an embodiment of the present invention, a single-chip microcomputer application program interrupt-triggered field protection device is provided, comprising:
[0052] The application running module is used to read the application variables that support the application running when the application is started, and run the application according to the read application variables;
[0053] The application site protection module is used to stop the application when an interruption occurs during the application operation, read the latest values of the application variables used in the application operation, and back them up to perform application site protection;
[0054] The interrupt handler running module is used to read the interrupt handler variables that support the running of the current interrupt handler, and run the interrupt handler according to the read interrupt handler variables;
[0055] The interrupt handler scene protection module is used to read the latest value of the interrupt handler variable used by the interrupt handler when the interrupt handler is executed, and back it up to perform interrupt handler scene protection;
[0056] The application recovery module is used to read the latest values of the backed-up application variables and continue running the application.
[0057] According to another aspect of an embodiment of the present invention, a storage medium is provided, on which a computer program is stored. When a processor executes the computer program stored on the storage medium, the method for triggering field protection by an interruption of a microcontroller application program according to any of the above embodiments of the present invention is implemented, or the field protection device for triggering field protection by an interruption of a microcontroller application program according to any of the above embodiments of the present invention is implemented.
[0058] According to another aspect of an embodiment of the present invention, a computer device is provided, which includes a memory and a processor, wherein the memory is used to store a computer executable program, and the processor is used to run the computer executable program to implement the single-chip microcomputer application interrupt triggering field protection method of any one of the above embodiments of the present invention, or implement the single-chip microcomputer application interrupt triggering field protection device of the above embodiments of the present invention.
[0059] The method and device for triggering field protection by interruption of a single-chip microcomputer application provided by the present invention have the following advantages:
[0060] The present invention provides a method and device for field protection triggered by an interruption of a single-chip microcomputer application, which realizes a data field protection mechanism when the application of a single-chip microcomputer or an embedded system is interrupted. The application variables before the interruption are backed up, so that the application variable values before and after the interruption program are unchanged; the interruption processing program variables used by the interruption processing program during the interruption process are backed up at the end of the interruption, so that the continuity of the interruption processing program variables during multiple interruption executions is achieved, and finally a complete interruption execution data field protection technology is realized.
[0061] The technical solution of the present invention is further described in detail below through the accompanying drawings and embodiments. BRIEF DESCRIPTION OF THE DRAWINGS
[0062] The above and other objects, features, and advantages of the present invention will become more apparent through a more detailed description of the embodiments of the present invention in conjunction with the accompanying drawings. The accompanying drawings are provided to provide a further understanding of the embodiments of the present invention and constitute a part of the specification. Together with the embodiments of the present invention, they are used to explain the present invention and are not intended to limit the present invention. In the drawings, the same reference numerals generally represent the same components or steps.
[0063] Figure 1 It is a flow chart of a method for triggering a scene protection by interruption of a single-chip microcomputer application program provided by an exemplary embodiment of the present invention;
[0064] Figure 2 is a schematic diagram of a memory space partitioning method provided by an exemplary embodiment of the present invention;
[0065] Figure 3 1 is a schematic structural diagram of a single-chip microcomputer application program interrupt-triggered field protection device provided by an exemplary embodiment of the present invention;
[0066] Figure 4 It is a structural diagram of a computer device provided by an exemplary embodiment of the present invention. DETAILED DESCRIPTION
[0067] Below, the exemplary embodiments according to the present invention will be described in detail with reference to the accompanying drawings. Obviously, the described embodiments are only part of the embodiments of the present invention, rather than all the embodiments of the present invention, and it should be understood that the present invention is not limited to the exemplary embodiments described herein.
[0068] It should be noted that the relative arrangement of components and steps, the numerical expressions and numerical values set forth in these embodiments do not limit the scope of the present invention unless specifically stated otherwise.
[0069] Those skilled in the art will understand that the terms "first" and "second" in the embodiments of the present invention are only used to distinguish different steps, devices or modules, and neither represent any specific technical meaning nor indicate the necessary logical order between them.
[0070] It should also be understood that, in the embodiments of the present invention, “a plurality of” may refer to two or more than two, and “at least one” may refer to one, two or more than two.
[0071] It should also be understood that any component, data or structure mentioned in the embodiments of the present invention can generally be understood as one or more, unless explicitly limited or otherwise indicated in the context.
[0072] In addition, the term "and / or" in this invention merely describes an association relationship between related objects, indicating that three possible relationships exist. For example, A and / or B can represent: A exists alone, A and B exist simultaneously, and B exists alone. Furthermore, the character " / " in this invention generally indicates that the related objects are in an "or" relationship.
[0073] It should also be understood that the description of the various embodiments of the present invention focuses on the differences between the various embodiments, and the same or similar aspects thereof can be referenced with each other. For the sake of brevity, they will not be described one by one.
[0074] At the same time, it should be understood that for the convenience of description, the sizes of the various parts shown in the drawings are not drawn according to the actual proportional relationship.
[0075] The following description of at least one exemplary embodiment is merely illustrative in nature and is in no way intended to limit the invention, its application, or uses.
[0076] Technologies, methods, and equipment known to ordinary technicians in the relevant art may not be discussed in detail, but where appropriate, the technologies, methods, and equipment should be considered part of the specification.
[0077] It should be noted that like reference numerals and letters refer to like items in the following figures, and therefore, once an item is defined in one figure, it need not be further discussed in subsequent figures.
[0078] Embodiments of the present invention can be applied to electronic devices such as terminal devices, computer systems, and servers, and can operate in conjunction with numerous other general-purpose or specialized computing system environments or configurations. Examples of well-known terminal devices, computing systems, environments, and / or configurations suitable for use with terminal devices, computer systems, servers, and other electronic devices include, but are not limited to, personal computer systems, server computer systems, thin clients, thick clients, handheld or laptop devices, microprocessor-based systems, set-top boxes, programmable consumer electronics, network personal computers, minicomputer systems, mainframe computer systems, and distributed cloud computing technology environments including any of the above.
[0079] Electronic devices such as terminal devices, computer systems, and servers can be described in the general context of computer system-executable instructions (such as program modules) executed by a computer system. Generally, program modules can include routines, programs, object programs, components, logic, data structures, etc., which perform specific tasks or implement specific abstract data types. Computer systems / servers can be implemented in a distributed cloud computing environment, where tasks are performed by remote processing devices linked via a communication network. In a distributed cloud computing environment, program modules can be located on local or remote computing system storage media, including storage devices.
[0080] Exemplary Methods
[0081] Figure 1 The figure is a flow chart of a method for triggering context protection by interruption of a single-chip microcomputer application program provided by an exemplary embodiment of the present invention.
[0082] This embodiment provides a method for field protection triggered by an interruption of a single-chip microcomputer application program, which implements a data field protection mechanism when the application program of the single-chip microcomputer or embedded system is interrupted. The application program variables before the interruption is executed are backed up to ensure that the application program variable values remain unchanged before and after the interruption program is executed; the interruption program variables used by the interruption program during the interruption process are backed up at the end of the interruption to ensure the continuity of the interruption program variables during multiple interruption executions, and ultimately realize a complete interruption execution data field protection technology.
[0083] Specifically, this embodiment implements a data context protection mechanism when an application program of a single-chip microcomputer or embedded system is interrupted, which can solve the problem of data context protection during interrupt processing. This method is applicable to the following functional environments:
[0084] (1) The system interrupt handling process is based on hardware interrupt vectors and user-programmed interrupt handlers, without the support of the operating system;
[0085] (2) The memory system used by interrupt handlers and applications is uniformly allocated, and there is no access difference;
[0086] (3) When the application is running, with data variables and partial register support, the interrupt occurs between two instructions of any function execution;
[0087] (4) The interrupt handler requires some temporary data variables and registers to run, or there are interrupt persistence variables between multiple interrupts, and the application continues to execute after the interrupt ends;
[0088] (5) The core of the protection mechanism is: application backup and recovery identification and interruption continuous data backup and recovery identification; among them, the application backup and recovery identification and interruption continuous data backup and recovery identification both include data variable identification and register variable identification, the data variable identification points to the data variable, and the register variable identification points to the register variable; the data variable identification is used to identify the application address and backup address of the data variable, and the register variable identification is used to identify the application address and backup address of the register variable, supporting instant backup of interruption site data and recovery after interruption.
[0089] The present embodiment provides a method for triggering a field protection by interrupting a microcontroller application program, which can be applied to electronic devices such as Figure 1 As shown, the specific steps include:
[0090] Step 1: When the application is started, the application variables that support the application are read, and the application is run according to the read application variables;
[0091] Step 2: When an interruption occurs during the application program's operation, the application program is stopped, the latest values of the application program variables used in the application program are read and backed up, and the application program is protected on-site;
[0092] Step 3: Read the interrupt handler variables that support the execution of the current interrupt handler, and execute the interrupt handler according to the read interrupt handler variables;
[0093] Step 4, when the interrupt handler is executed, read the latest value of the interrupt handler variable used by the interrupt handler, back it up, and perform interrupt handler field protection;
[0094] Step 5: Read the latest value of the backed-up application variable and continue running the application.
[0095] In a specific implementation, in the process of implementing the above five steps, for the application: in order to enable the application to quickly and effectively read the required application variables, thereby running the application; and, when an interruption occurs, the application variables used in the application running can be effectively stored and backed up; and, when the application needs to be run again after the interruption, the application can quickly and effectively read the application variables backed up before the interruption; for the interrupt handler: in order to enable the interrupt handler to be executed after the interrupt handler is completed, the interrupt handler variables used in the interrupt handler running can be effectively stored and backed up; and, when the interrupt handler needs to be enabled again, the interrupt handler can quickly and effectively read the interrupt handler variables backed up during the previous interruption, the present invention specifically divides and designs the system memory space, and realizes the storage, backup and reading of the above application variables and interrupt handler variables by introducing the application backup recovery identifier and the interrupt continuous data backup recovery identifier.
[0096] It should be understood that those skilled in the art can adopt different methods according to actual needs to implement the single-chip microcomputer application interrupt triggering field protection method provided in this embodiment. The division of system memory space and backup recovery identification is only one specific implementation method, and other methods can also be used for implementation, which is not limited here.
[0097] As an example, refer to Figure 2 The system memory space consists of four areas: an application live data storage area, an interrupt persistent data storage area, an ongoing data storage area, and a backup and recovery flag storage area. In this embodiment, the system memory space refers to the operating system memory space that supports the running of applications and interrupt handlers, that is, the memory space of the microcontroller. Applications and interrupt handlers need to continuously read and write data in the system memory space to ensure their normal operation.
[0098] A backup and recovery identification storage area for storing application variable identifications of application variables used in application program execution, and interrupt handler variable identifications of interrupt handler variables used in interrupt handler execution;
[0099] Since the backup and recovery identification storage area needs to independently store the application variable identification and the interrupt handler variable identification, in order to speed up the reading and writing efficiency of the variable identification and facilitate the management of the variable identification, as a preferred method, the backup and recovery identification storage area can include two sub-areas, namely: the application backup and recovery identification sub-area and the interrupt persistence data backup and recovery identification sub-area; wherein, the application backup and recovery identification sub-area stores the application variable identification; the interrupt persistence data backup and recovery identification sub-area stores the interrupt handler variable identification.
[0100] As an embodiment, the application variable identification includes a data variable identification and a register variable identification that support the running of the application; the interrupt handler variable identification includes a data variable identification and a register variable identification that support the running of the interrupt handler.
[0101] Specifically, to run an application, the application needs to continuously read and write various data variables and register variables. Therefore, the identifiers of data variables and register variables are collectively referred to as application variable identifiers that support the operation of the application. Similarly, to run an interrupt handler, the interrupt handler needs to continuously read and write various data variables and register variables. Therefore, the identifiers of data variables and register variables are collectively referred to as interrupt handler variable identifiers that support the operation of the interrupt handler.
[0102] As an embodiment, the register variable identifier of the application variable identifier and the register variable identifier of the interrupt handler variable identifier both include: a common register variable identifier, a current instruction position register variable identifier, a stack top register variable identifier and a control register variable identifier.
[0103] Among them, the application variable identification and the interrupt handler variable identification are both composed of fields with different meanings. For example, the application variable identification includes: the application variable name, the address offset of the application variable in the application field data storage area, the interrupt number corresponding to the application variable, and the application variable status; wherein the application variable status includes: the to-be-backed-up state and the to-be-restored state; the interrupt handler variable identification includes: the interrupt handler variable name, the address offset of the interrupt handler variable in the interrupt persistent data storage area, the interrupt number corresponding to the interrupt handler variable, and the interrupt handler variable status; wherein the interrupt handler variable status includes: the to-be-backed-up state and the to-be-restored state.
[0104] The functions of each field can be simply described as:
[0105] Application variable name: the canonical name of the application variable;
[0106] Address offset of application variables in the application field data storage area: The required application variables can be quickly read from the application field data storage area through the address offset of application variables in the application field data storage area;
[0107] The interrupt number corresponding to the application variable and the application variable status; wherein the application variable status includes: a to-be-backed-up state and a to-be-restored state; the application variable status is divided into a to-be-backed-up state and a to-be-restored state, and for the same application variable, its status will change between the to-be-backed-up state and the to-be-restored state during the operation of the application at different stages. For example, when the application is started, the application variable identifier of the to-be-backed-up state is read; when an interruption occurs, the application variable is backed up for on-site protection, and the corresponding application variable identifier needs to be modified to the to-be-restored state; when the application needs to be continued to run after the interruption, the application variable identifier of the to-be-restored state is directly read, and the read application variable identifier of the to-be-restored state is modified to the to-be-backed-up state; therefore, the next time the application is run again, the application variable identifier of the to-be-backed-up state is read; thereby completing a cycle.
[0108] Interrupt handler variable name, which is the standard name of the interrupt handler variable;
[0109] The address offset of the interrupt handler variable in the interrupt persistent data storage area: The required interrupt handler variable can be quickly read from the interrupt persistent data storage area through the address offset of the interrupt handler variable in the interrupt persistent data storage area;
[0110] The interrupt number corresponding to the interrupt handler variable: This is the unique interrupt number for each interrupt. Through the interrupt number, the required variables corresponding to this interrupt can be read;
[0111] The interrupt handler variable status includes: a to-be-backed-up state and a to-be-restored state: the interrupt handler variable status is divided into a to-be-backed-up state and a to-be-restored state, and for the same interrupt handler variable, its status will change between the to-be-backed-up state and the to-be-restored state during the operation of different stages. For example, when the interrupt handler starts running, the interrupt handler variable identifier of the to-be-restored state is read, and then the interrupt handler is run; at the same time, the interrupt handler variable identifier of the to-be-restored state is modified to the to-be-backed-up state; when the interrupt handler is executed, the status of the corresponding interrupt handler variable identifier is modified to the to-be-restored state, and stored for interrupt scene protection; when the interrupt handler is run again, the interrupt handler variable identifier of the to-be-restored state is read, and then the interrupt handler is run; thus completing a cycle.
[0112] The functions of each field will be described in detail in the specific implementation of the method for triggering the scene protection by interruption of the microcontroller application program later, and will not be described in detail here.
[0113] An application on-site data storage area is used to store application variables corresponding to the application variable identifier stored in the backup and recovery identifier storage area;
[0114] An interrupt persistent data storage area, used for storing interrupt handler variables corresponding to the interrupt handler variable identifier stored in the backup recovery identifier storage area;
[0115] The running data storage area is used to read the corresponding application variables stored in the application site data storage area according to the application variable identifier stored in the backup and recovery identification storage area, and write the read application variables into the running data storage area, thereby running the application; or to read the corresponding interrupt handler variables stored in the interrupt persistent data storage area according to the interrupt handler variable identifier stored in the backup and recovery identification storage area, and write the read interrupt handler variables into the running data storage area, thereby running the interrupt handler.
[0116] The following describes how to complete the context protection triggered by the interrupt of the microcontroller application based on these four storage areas, as well as the application variable identifier and the interrupt handler variable identifier:
[0117] Application variable identification, including: application variable name, address offset of application variable in application on-site data storage area, interrupt number corresponding to application variable, and application variable status; wherein application variable status includes: pending backup status and pending recovery status;
[0118] An interrupt handler variable identifier, including: an interrupt handler variable name, an address offset of the interrupt handler variable in an interrupt persistent data storage area, an interrupt number corresponding to the interrupt handler variable, and an interrupt handler variable status; wherein the interrupt handler variable status includes a pending backup status and a pending restore status;
[0119] In step 1, when the application starts, the application variables that support the application are read, and the application is run according to the read application variables, specifically:
[0120] Step 1.1: When the application starts, read the backup and restore identification storage area to obtain the application variable identification corresponding to the status to be backed up and the current interrupt number:
[0121] Step 1.2, according to each application variable identifier read, obtain the address offset and application variable name of the corresponding application variable in the application site data storage area;
[0122] Step 1.3, reading the corresponding application variable from the application on-site data storage area according to the obtained address offset of the application variable in the application on-site data storage area and the application variable name, and writing the read application variable to the running data storage area;
[0123] Step 1.4, running the application according to the application variables in the running data storage area;
[0124] In step 2, when an interruption occurs during the application program execution, the application program is stopped, the latest values of the application variables used in the application program execution are read and backed up, and the application program is protected in-situ. Specifically, the following steps are performed:
[0125] Step 2.1, set the interrupt number;
[0126] Step 2.2, when an interruption occurs during the running of the application, the running of the application is stopped, and the application variable identifiers of the application variables currently used in the running of the application are obtained to form an application variable identifier set;
[0127] Step 2.3, changing the status of each application variable identifier belonging to the application variable identifier set in the backup recovery identifier storage area to a pending recovery state, and changing the interrupt number corresponding to the application variable to the current interrupt number;
[0128] Step 2.4, according to each application variable identifier corresponding to the interruption number and in the state to be restored, obtain the address offset and application variable name of the corresponding application variable in the application field data storage area;
[0129] Step 2.5, based on the address offset and application variable name of the obtained application variable in the application field data storage area, read the corresponding application variable from the application field data storage area, and update the content of each read application variable to the current latest value. The current latest value of the application variable is stored in the application field data storage area to achieve backup and perform application field protection.
[0130] In step 3, the interrupt handler variable that supports the execution of this interrupt handler is read, and the interrupt handler is executed according to the read interrupt handler variable, specifically:
[0131] Step 3.1, read the backup recovery identification storage area to obtain the interrupt handler variable identification of the state to be restored;
[0132] Step 3.2, modify the interrupt number identified by the interrupt handler variable in the state to be restored to the current interrupt number;
[0133] Step 3.3, according to the read interrupt handler variable identifier to be restored, obtain the address offset of the corresponding interrupt handler variable in the interrupt persistent data storage area and the interrupt handler variable name;
[0134] Step 3.4, based on the obtained address offset of the interrupt handler variable in the interrupt persistent data storage area and the interrupt handler variable name, read the corresponding interrupt handler variable from the interrupt persistent data storage area, and write the read interrupt handler variable to the running data storage area; and modify the interrupt handler variable identifier in the backup and restore identifier storage area that belongs to the current interrupt number in the to-be-restored state to the to-be-backed-up state;
[0135] Step 3.5, running the interrupt handler according to the interrupt handler variables in the running data storage area;
[0136] In step 4, when the interrupt handler is executed, the latest value of the interrupt handler variable used by the interrupt handler is read and backed up to perform interrupt handler context protection, specifically:
[0137] Step 4.1, when the execution of the current interrupt handler is completed, obtaining the interrupt handler variable identifier of the interrupt handler variable used by the current interrupt handler to form an interrupt handler variable identifier set;
[0138] Step 4.2, according to each interrupt handler variable identifier in the interrupt handler variable identifier set, obtain the address offset and interrupt handler variable name of the corresponding interrupt handler variable in the interrupt persistent data storage area;
[0139] Step 4.3, based on the obtained address offset of the interrupt handler variable in the interrupt persistent data storage area and the interrupt handler variable name, read the corresponding interrupt handler variable from the interrupt persistent data storage area, and update the content of the read interrupt handler variable to the current latest value. The current latest value of the interrupt handler variable is stored in the interrupt persistent data storage area to complete the backup and realize the interrupt handler scene protection;
[0140] Step 4.4: Modify the state of each interrupt handler variable identifier in the interrupt handler variable identifier set to a pending recovery state.
[0141] In step 5, read the latest value of the backed-up application variable and continue running the application. Specifically:
[0142] Step 5.1, read the backup recovery identification storage area to obtain the application variable identification of each state to be recovered corresponding to the current interrupt number;
[0143] Step 5.2, according to each application variable identifier read, obtain the address offset and application variable name of the corresponding application variable in the application site data storage area;
[0144] Step 5.3, based on the address offset and application variable name of the application variable in the application on-site data storage area, read the corresponding application variable from the application on-site data storage area, and write the read application variable to the running data storage area; and modify the identifier of each read application variable to the state to be backed up;
[0145] In step 5.4, the application is restored and continued to run according to the application variables in the running data storage area, completing the on-site recovery of this interruption.
[0146] A more specific embodiment is described below:
[0147] System memory storage space distribution is as follows Figure 2 As shown, it includes four areas: application site data storage area, with a length of APP_DATA_SIZE; interrupt persistent data storage area, with a length of INTER_DATA_SIZE; running data storage area; backup and recovery identification storage area, which uses INTER identification storage location.
[0148] The application backup and recovery identifier and the interrupt persistent data backup and recovery identifier are collectively referred to as the backup and recovery identifier. The backup and recovery identifier is stored in a fixed allocated location INTER in the memory space. The application variable corresponding to the application backup and recovery identifier is allocated a space length of APP_DATA_SIZE to store application site-protected data; the interrupt handler variable corresponding to the interrupt persistent data backup and recovery identifier is allocated a space length of INTER_DATA_SIZE to store interrupt handler site-protected data. The length value is determined based on the required data volume and system memory space. For example, if the embedded system application variable data is in the range of 1 to 10MB, the interrupt handler variable data is within 1MB, and the system memory is 64MB, APP_DATA_SIZE = 16MB and INTER_DATA_SIZE = 2MB can be allocated.
[0149] The memory space for application variable data must first store the stack data of the application variables, and then store the application variables. The memory space for interrupt handler variable data must first store the stack data of the interrupt handler variables, and then store the interrupt handler variables.
[0150] The backup and recovery flag, whose structure is defined in C language as follows:
[0151]
[0152]
[0153] Therefore, the backup and recovery identifier mainly includes the following: status, to be restored or to be backed up; interrupt number; type, including application backup and recovery identifier or interrupt continuous data backup and recovery identifier; whether it is a register; the attributes of the identification data are identified and run in the protection mechanism.
[0154] The identification structure definition is as follows:
[0155] Each identification structure corresponds to a field variable, recording information such as the variable's access method and application attributes.
[0156] addr_offset data application address offset, read or write application data
[0157] addr_bak_offset data backup address offset, read and write backup data
[0158] len data length, read and write identification data
[0159] status data status, indicating the state to be restored after backup or the state of empty data to be backed up
[0160] inter_no data interrupt number, which identifies the interruption of the backup data so that it can be restored
[0161] function data function, application data or interrupt handler data
[0162] reg register variable identifier
[0163] The interruption site variable identifier is stored in the backup recovery identifier storage area at location INTER. Before the interruption is executed, the application site data is backed up in the application site data storage area, and the application backup recovery identifier is written to the backup recovery identifier storage area. When the site data is restored after the interruption is executed, the application variable data in the application site data storage area is read out according to the application backup recovery identifier, thereby restoring the site and continuing to execute the application.
[0164] The implementation of the protection mechanism is based on the process of the embedded system interrupt hardware processing according to the interrupt vector. The hardware starts the interrupt notification processor. When the processor calls the firmware's interrupt lookup table and jump program, the assembler implements data judgment and jumps to execute the scene protection process. After execution, it continues to process the firmware's interrupt processing. After the user's interrupt handler is executed, the processor firmware program will look up the table and jump to the next instruction to execute. Before that, the assembler implements the result judgment and jumps to execute the scene recovery process.
[0165] The interrupt firmware assembly code is as follows:
[0166]
[0167] _irq_ is the firmware process executed by the system after the processor notifies the interrupt response pin when an interrupt occurs. Among them, int_entry is the interrupt hardware parameter process, which performs interrupt type judgment, interrupt vector table lookup processing, interrupt handler location and other tasks. irq_handler is the user interrupt handler, and its function implementation is determined by the system program. After these two processes, get_thread_info tsk and mov why,#0 are used to determine and restore the thread structure before the interrupt. Finally, ret_to_user_from_irq is used to return to the system function execution before the interrupt occurred.
[0168] The application site protection mechanism provided by the present invention modifies the above firmware assembly code, adds a procedure call instruction before int_entry and before ret_to_user_from_irq, jumps to the interrupt site protection process protect_spot and the interrupt site recovery process restore_spot for execution, realizes data backup and preservation of the application before interrupt execution, and data recovery after interrupt execution to continue executing the application before interruption.
[0169] Therefore, the on-site protection mechanism provided by the present invention has the following code:
[0170]
[0171]
[0172] Another part of the protection mechanism of the present invention is the protection of local variables and persistent data of the interrupt handler, which is also achieved by modifying the interrupt firmware assembly instructions. The modified pseudo code is as follows:
[0173]
[0174] Before the interrupt handler is executed, the data variables needed by the interrupt handler are restored. After the interrupt is executed, the interrupt persistence data is backed up and protected. The data variables of the interrupt handler are continuously protected by executing the remain_int and backup_int processes before and after irq_handler.
[0175] The present invention involves four processing processes, namely:
[0176] The on-site protection process protect_spot, the continuous data recovery process remain_int, the continuous data backup process backup_int and the on-site recovery process restore_spot are interrupted.
[0177] Among them: protect_spot and restore_spot are used to realize the protection of application site data. The data identification is stored in the memory INTER location. When the application site data is running, Figure 2 The third part of the space is the running data storage area, where application data is backed up. Figure 2 The first part of the space is the application site data storage area.
[0178] Continuous data protection during interruption is achieved through remain_int and backup_int. The data identifier is located at the start offset spot_size of INTER. The interruption data variable is backed up in Figure 1 The second part of the space is: interrupt persistent data storage area; after protect_spot backs up the data variables before the interrupt, remain_int puts Figure 2 The second part of the interrupt data recovery Figure 2 The third part is the running data, which covers the application's on-site running data; after the interrupt processing function is executed, backup_int backs up the interruption continuous data in Figure 2 The second part of the space is the interrupt persistent data storage area.
[0179] The four processing processes of the interruption site protection process protect_spot, the interruption continuous data recovery process remain_int, the interruption continuous data backup process backup_int and the interruption site recovery process restore_spot are as follows:
[0180] (1) Interrupt the site protection process protect_spot:
[0181] (1) Check the number of application variable identifiers in the INTER location data identifier structure and the length of each application variable identifier.
[0182] (2) Check whether the first application variable identifier is a register variable identifier and check the length of the register variable identifier. If it is not a register variable identifier, stop the process abnormally; otherwise, continue to the next step.
[0183] (3) Determine whether the register variable identifier length is the standard length of reg_size. If not, stop the process; otherwise, continue to the next step.
[0184] (4) register variable identifiers read from the application backup and recovery identifier, including multiple different register variable identifiers;
[0185] The data register variable that is read will be identified by the corresponding data register r0~r15, and the backup Figure 2 The first part of the space header backs up the application function register corresponding to the application function register variable identifier in the next 64-byte space.
[0186] (5) Back up the read function registers EAX, EBX, ECX, EDX, CS, DS, SS, FS Figure 2 The next 32 bytes of the first part.
[0187] (6) At the end of the previous step, there is a 32-byte space interval to store the application data variable, which is arranged in sequence according to the read application data variable identifier, confirming that the data function is application data and the interrupt number is the current interrupt number.
[0188] (7) The status of the application variable identifier after the backup is set to STATUS_TO_RESTORE to be restored.
[0189] (8) The current instruction position register EIP is pushed onto the stack, and the top register ESP and control registers ESI, EDI, and EBP are backed up to the 32-byte space separated in step (5).
[0190] (2) Interrupt the continuous data recovery process remain_int
[0191] (1) Check the number of interrupt handler variable identifiers at the INTER offset spot_size position and the length of each interrupt handler variable identifier.
[0192] (2) Check whether the first interrupt handler variable identifier at the INTER offset spot_size position is a register variable identifier, check the length of the register variable identifier, if it is not a register variable identifier, stop the process abnormally; otherwise, continue to the next step.
[0193] (3) Determine whether the register variable identifier length is the standard length of reg_size. If not, stop the process; otherwise, continue to the next step.
[0194] (4) The interrupt handler data, namely: Figure 2 The data at the first offset byte position stored in the second part is restored to Figure 2 The third part is space.
[0195] (5) The status of the interrupt handler variable after recovery is set to STATUS_TO_BACKUP to be backed up.
[0196] (6) Figure 2 The first 64 bytes of data registers r0 to r15 of the second part are restored to Figure 2 The third part is space.
[0197] (7) Figure 2 The next 32 bytes of the second part of the function registers EAX, EBX, ECX, EDX, CS, DS, SS, FS are restored to Figure 2 The third part is space.
[0198] (8) Figure 2 The second part of the stack top register ESP and control registers ESI, EDI, EBP, pop the interrupt handling function address stored on the top of the stack to the instruction position register EIP, and restore to Figure 2 The third part of the space continues to execute and jumps to the interrupt processing function entry.
[0199] Therefore, by reading Figure 2 The data in the third part of the space executes the interrupt processing function.
[0200] (3) Interrupting the continuous data backup process backup_int
[0201] (1) Check the number of interrupt handler variable identifiers at the INTER offset spot_size position and the length of each interrupt handler variable identifier.
[0202] (2) Check whether the variable identifier of the first interrupt handler is a register variable identifier and check the length of the register variable identifier. If it is not a register variable identifier, stop the process abnormally; otherwise, continue to the next step.
[0203] (3) Determine whether the register variable identifier length is the standard length of reg_size. If not, stop the process; otherwise, continue to the next step.
[0204] (4) Figure 2 The third part of the interrupted data is backed up to Figure 2 The second part is the header offset byte position.
[0205] (5) The status of the interrupt handler variable after the backup is set to STATUS_TO_RESTORE to be backed up.
[0206] (6) Figure 2 The data registers r0~r15 of the third part are backed up to Figure 2 The second part is a 64-byte header.
[0207] (7) Figure 2The third part of the function registers EAX, EBX, ECX, EDX, CS, DS, SS, FS are backed up to Figure 2 The next 32 bytes of the second part.
[0208] (8) Figure 2 The interrupt handler entry address of the third part is pushed onto the stack, and the top register ESP and control registers ESI, EDI, and EBP are backed up to Figure 2 The second part is space.
[0209] (IV) Interrupt the on-site recovery process restore_spot:
[0210] (1) Check the number of application variable identifiers at the INTER position and the length of each application variable identifier.
[0211] (2) Check whether the first application variable identifier is a register variable identifier and check the length of the register variable identifier. If it is not a register variable identifier, stop the process abnormally; otherwise, continue to the next step.
[0212] (3) Determine whether the register variable identifier length is the standard length of reg_size. If not, stop the process; otherwise, continue to the next step.
[0213] (4) Figure 2 The application data at the first part of the header offset 128 bytes is restored to Figure 2 In the third part, arrange them in sequence, confirm that the data function is application data and the interrupt number is the current interrupt number.
[0214] (5) The status of the restored application variable identifier is set to STATUS_TO_BACKUP to be backed up.
[0215] (6) Figure 2 The first part of the header 64 bytes, that is, data registers r0~r15, is restored to Figure 2 Part 3.
[0216] (7) Figure 2 The next 32 bytes of the first part, namely the function registers EAX, EBX, ECX, EDX, CS, DS, SS, FS, are restored to Figure 2 Part 3.
[0217] (8) Figure 2 The first part of the stack top register ESP and control registers ESI, EDI, EBP, the stack instruction position register EIP, is restored to Figure 2 Part 3.
[0218] Continue execution and jump to the next instruction of the application before the interruption, and execute the application.
[0219] The main innovations of the present invention include:
[0220] (1) Data variable identification corresponding method.
[0221] (2) A method for identifying data variables and backing up running data.
[0222] (3) Check the data variable identification method to restore data operation.
[0223] (4) Modify the interrupt response firmware to back up and restore data variables before and after the interrupt and the method of restoring the backup data variables at the beginning and end of the interrupt processing.
[0224] (5) On-site protection technology triggered by interruption of microcontroller or embedded program based on the above technology.
[0225] The data field protection mechanism of the present invention during interruption of program execution in a single-chip microcomputer or embedded system is as follows: application program variables before the interruption is executed are backed up, so that the application program data remains unchanged before and after the interruption program is executed; interruption processing program variables used in the interruption are backed up at the end of the interruption, so that the interruption processing program data remains unchanged during multiple interruption executions, and the data variables of the application program and the interruption processing program can be saved without any impact. When an interruption occurs randomly in real time, the program remains orderly and correctly processed; at the same time, the application program and the interruption processing program can use the same running memory space for execution, and the space utilization is relatively autonomous. In the interruption system execution, the data field protection mechanism of the present invention is applied to the embedded resource efficiency-required system, especially in the structure where there is no operating system support for directly running the application program, and the available data space, correctness and execution performance are all guaranteed and improved.
[0226] Exemplary devices
[0227] Figure 3 The present invention provides a single-chip microcomputer application interrupt triggering field protection device according to an exemplary embodiment of the present invention. Figure 3 As shown, this embodiment includes:
[0228] The application running module 31 is used to read application variables that support the running of the application when the application is started, and run the application according to the read application variables;
[0229] The application site protection module 32 is used to stop the application when an interruption occurs during the application operation, read the latest value of the application variables used in the application operation, and back up the values to perform application site protection;
[0230] The interrupt processing program running module 33 is used to read the interrupt processing program variables that support the execution of the current interrupt processing program, and run the interrupt processing program according to the read interrupt processing program variables;
[0231] The interrupt handler scene protection module 34 is used to read the latest value of the interrupt handler variable used by the interrupt handler when the interrupt handler is executed, and back it up to perform interrupt handler scene protection;
[0232] The application program recovery module 35 is configured to read the latest value of the backed-up application program variable and continue running the application program.
[0233] The single-chip microcomputer application program interruption-triggered scene protection device of the embodiment of the present invention corresponds to the single-chip microcomputer application program interruption-triggered scene protection method of another embodiment of the present invention, and the specific details are not repeated here.
[0234] Exemplary Computer Devices
[0235] Figure 4 This is the structure of a computer device provided by an exemplary embodiment of the present invention. The computer device includes a processor 41 and a processor 42;
[0236] The processor 42 may be a central processing unit (CPU) or other form of processing unit having data processing capabilities and / or instruction execution capabilities, and may control other components in a computer device to perform desired functions.
[0237] The memory 41 may include one or more computer program products, which may include various forms of computer-readable storage media, such as volatile memory and / or non-volatile memory. The volatile memory may include, for example, random access memory (RAM) and / or cache memory. The non-volatile memory may include, for example, read-only memory (ROM), a hard disk, a flash memory, etc. One or more computer program instructions may be stored on the computer-readable storage medium, and the processor may execute the program instructions to implement the single-chip microcomputer application interrupt triggering scene protection method and / or other desired functions of the software program of each embodiment disclosed above. In one example, the computer device may further include: an input device 43 and an output device 44, and these components are interconnected via a bus system and / or other forms of connection mechanisms (not shown).
[0238] In addition, the input device 43 may also include, for example, a keyboard, a mouse, and the like.
[0239] The output device 44 can output various information to the outside. The output device 44 can include, for example, a display, a speaker, a printer, a communication network and a remote output device connected thereto.
[0240] Of course, to simplify, Figure 4 Only some of the components related to the present disclosure in the computer device are shown, and components such as a bus, an input / output interface, etc. are omitted. In addition, the computer device may further include any other appropriate components according to specific application scenarios.
[0241] Exemplary computer program products and computer-readable storage media
[0242] In addition to the above-mentioned methods and devices, an embodiment of the present disclosure may also be a computer program product, which includes computer program instructions, which, when executed by a processor, enable the processor to execute the steps of the method for obtaining text information according to various embodiments of the present disclosure described in the above-mentioned "Exemplary Method" section of this specification.
[0243] The computer program product may be written in any combination of one or more programming languages to implement the operations of the disclosed embodiments, including object-oriented programming languages such as Java, C++, and conventional procedural programming languages such as C or similar programming languages. The program code may be executed entirely on the user's computing device, partially on the user's computing device, as a standalone software package, partially on the user's computing device and partially on a remote computing device, or entirely on a remote computing device or server.
[0244] In addition, an embodiment of the present disclosure may also be a computer-readable storage medium having computer program instructions stored thereon, which, when executed by a processor, causes the processor to execute the steps of the method for acquiring text information according to various embodiments of the present disclosure described in the above “Exemplary Method” section of this specification.
[0245] The computer-readable storage medium can adopt any combination of one or more readable media. The readable medium can be a readable signal medium or a readable storage medium. The readable storage medium can, for example, include but is not limited to a system, device or component of electricity, magnetism, light, electromagnetic, infrared, or semiconductor, or any combination thereof. More specific examples (non-exhaustive list) of readable storage media include: an electrical connection with one or more wires, a portable disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination thereof.
[0246] The basic principles of the present disclosure have been described above in conjunction with specific embodiments. However, it should be noted that the advantages, strengths, and effects mentioned in this disclosure are merely illustrative and not restrictive, and should not be construed as necessarily possessed by each embodiment of the present disclosure. Furthermore, the specific details disclosed above are provided for illustrative purposes and to facilitate understanding, rather than as limitations. These details do not limit the present disclosure to necessarily being implemented using these specific details.
[0247] Each embodiment in this specification is described in a progressive manner, with each embodiment focusing on its differences from the other embodiments. References to the same or similar parts between the various embodiments are sufficient. For system embodiments, since they largely correspond to method embodiments, their description is relatively simple. For relevant parts, references to the description of the method embodiments are sufficient.
[0248] The block diagrams of the devices, devices, equipment, and systems involved in this disclosure are intended to be illustrative examples only and are not intended to require or imply that they must be connected, arranged, or configured in the manner shown in the block diagrams. As will be appreciated by those skilled in the art, these devices, devices, equipment, and systems can be connected, arranged, or configured in any manner. Words such as "including," "comprising," "having," and the like are open-ended words, meaning "including but not limited to," and can be used interchangeably therewith. The words "or" and "and" used herein refer to the words "and / or" and can be used interchangeably therewith, unless the context clearly indicates otherwise. The word "such as" used herein refers to the phrase "such as but not limited to," and can be used interchangeably therewith.
[0249] The methods and apparatus of the present disclosure may be implemented in many ways. For example, the methods and apparatus of the present disclosure may be implemented by software, hardware, firmware, or any combination of software, hardware, and firmware. The above order of steps for the method is for illustration only, and the steps of the method of the present disclosure are not limited to the order specifically described above unless otherwise specified. In addition, in some embodiments, the present disclosure may also be implemented as programs recorded in a recording medium, which include machine-readable instructions for implementing the methods according to the present disclosure. Thus, the present disclosure also covers recording media that store programs for executing the methods according to the present disclosure.
[0250] It should also be noted that, in the apparatus, equipment and method of the present disclosure, each component or each step can be decomposed and / or recombined. These decompositions and / or recombinations should be regarded as equivalent schemes of the present disclosure. The above description of the disclosed aspects is provided to enable any technician in this field to make or use the present disclosure. Various modifications to these aspects will be very obvious to those skilled in the art, and the general principles defined herein can be applied to other aspects without departing from the scope of the present disclosure. Therefore, the present disclosure is not intended to be limited to the aspects shown here, but to the widest range consistent with the principles and novel features disclosed herein.
[0251] The above description has been provided for the purpose of illustration and description. In addition, this description is not intended to limit the embodiments of the present disclosure to the forms disclosed herein. Although a number of example aspects and embodiments have been discussed above, those skilled in the art will recognize certain variations, modifications, alterations, additions, and sub-combinations thereof.
Claims
1. A method for triggering field protection by interruption of a single-chip microcomputer application, characterized in that: The following steps are involved: When the application is started, the application variables that support the running of the application are read, and the application is run according to the read application variables; When an interruption occurs during the running of an application, the application is stopped, the latest values of the application variables used in the running of the application are read and backed up, and the application is protected on-site; Read the interrupt handler variables that support the execution of this interrupt handler, and execute the interrupt handler according to the read interrupt handler variables; When the interrupt handler is finished executing, the latest value of the interrupt handler variable used by the interrupt handler is read and backed up to perform interrupt handler scene protection; Read the latest value of the backed-up application variables and continue running the application; The system memory space includes four areas: application on-site data storage area, interrupt persistent data storage area, running data storage area and backup and recovery identification storage area; A backup and recovery identification storage area for storing application variable identifications of application variables used in application program execution, and interrupt handler variable identifications of interrupt handler variables used in interrupt handler execution; An application on-site data storage area is used to store application variables corresponding to the application variable identifier stored in the backup and recovery identifier storage area; An interrupt persistent data storage area, used for storing interrupt handler variables corresponding to the interrupt handler variable identifier stored in the backup recovery identifier storage area; The running data storage area is used to read the corresponding application variables stored in the application site data storage area according to the application variable identifier stored in the backup and recovery identifier storage area, and write the read application variables into the running data storage area, thereby running the application; or to read the corresponding interrupt handler variables stored in the interrupt persistent data storage area according to the interrupt handler variable identifier stored in the backup and recovery identifier storage area, and write the read interrupt handler variables into the running data storage area, thereby running the interrupt handler; Wherein: the application variable identification includes: the application variable name, the address offset of the application variable in the application site data storage area, the interrupt number corresponding to the application variable and the application variable state; wherein the application variable state includes: the state to be backed up and the state to be restored; When the application starts, the application variables that support the application are read, and the application is run according to the read application variables, specifically: When the application is started, the backup and recovery identification storage area is read to obtain the application variable identification corresponding to the current interrupt number and the status to be backed up; According to each application variable identifier read, the address offset and application variable name of the corresponding application variable in the application site data storage area are obtained; Read the corresponding application variable from the application on-site data storage area according to the obtained address offset of the application variable in the application on-site data storage area and the application variable name, and write the read application variable to the running data storage area; Run the application based on the application variables in the running data store; When an interruption occurs during the application's operation, the application is stopped, the latest values of the application variables used in the application are read and backed up, and the application site is protected. Specifically: Set the interrupt number for this time; When an interruption occurs during the running of the application, the running of the application is stopped, and the application variable identifiers of the application variables used in the current running of the application are obtained to form an application variable identifier set; Modify the status of each application variable identifier belonging to the application variable identifier set in the backup recovery identifier storage area to the waiting-for-recovery status, and modify the interrupt number corresponding to the application variable to the current interrupt number; According to the application variable identifiers corresponding to the interruption number in each state to be restored, the address offset and application variable name of the corresponding application variable in the application field data storage area are obtained; Based on the address offset and application variable name of the obtained application variable in the application field data storage area, the corresponding application variable is read from the application field data storage area, and the content of each read application variable is updated to the current latest value. The current latest value of the application variable is stored in the application field data storage area to achieve backup and perform application field protection.
2. The method for triggering field protection by interruption of a single-chip microcomputer application according to claim 1, characterized in that: The backup and recovery identification storage area includes two sub-areas: the application backup and recovery identification sub-area and the interrupted continuous data backup and recovery identification sub-area; The application backup and recovery identification sub-area stores the application variable identification; The interruption continuous data backup and recovery identification sub-area stores the interruption processing program variable identification.
3. The method for triggering scene protection by interruption of a single-chip microcomputer application according to claim 1, characterized in that: Application variable identifiers, including data variable identifiers and register variable identifiers that support application operation; The interrupt handler variable identifier includes a data variable identifier and a register variable identifier that support the operation of the interrupt handler.
4. The method for triggering scene protection by interruption of a single-chip microcomputer application according to claim 3, characterized in that: The register variable identifier of the application variable identifier and the register variable identifier of the interrupt handler variable identifier both include: a common register variable identifier, a current instruction position register variable identifier, a stack top register variable identifier and a control register variable identifier.
5. The method for triggering scene protection by interruption of a single-chip microcomputer application according to claim 1, characterized in that: Read the latest value of the backed-up application variables and continue running the application. Specifically: Read the backup recovery identification storage area to obtain the application variable identification of each state to be restored corresponding to the current interrupt number; According to each application variable identifier read, the address offset and application variable name of the corresponding application variable in the application site data storage area are obtained; Read the corresponding application variables from the application on-site data storage area according to the address offset and application variable name of the application variables in the application on-site data storage area, and write the read application variables to the running data storage area; and modify the identifier of each read application variable to a state to be backed up; Based on the application variables in the running data storage area, the application is restored and continued to run, completing the on-site recovery of the interruption.
6. The method for triggering scene protection by interruption of a single-chip microcomputer application according to claim 1, characterized in that: An interrupt handler variable identifier, including: an interrupt handler variable name, an address offset of the interrupt handler variable in an interrupt persistent data storage area, an interrupt number corresponding to the interrupt handler variable, and an interrupt handler variable status; wherein the interrupt handler variable status includes a pending backup status and a pending restore status; Read the interrupt handler variables that support the execution of this interrupt handler, and run the interrupt handler according to the read interrupt handler variables, specifically: Read the backup recovery identification storage area to obtain the interrupt handler variable identification of the state to be restored; Modify the interrupt number identified by the interrupt handler variable in the state to be restored to the current interrupt number; According to the read interrupt handler variable identifier of the to-be-restored state, the address offset of the corresponding interrupt handler variable in the interrupt persistent data storage area and the interrupt handler variable name are obtained; Read the corresponding interrupt handler variable from the interrupt persistent data storage area according to the obtained address offset of the interrupt handler variable in the interrupt persistent data storage area and the interrupt handler variable name, and write the read interrupt handler variable to the running data storage area; and modify the interrupt handler variable identifier in the backup and restore identifier storage area that belongs to the current interrupt number in the to-be-restored state to the to-be-backed-up state; Run the interrupt handler according to the interrupt handler variables in the running data storage area; When the interrupt handler is finished executing, the latest value of the interrupt handler variable used by the interrupt handler is read and backed up to perform interrupt handler scene protection, specifically: When the execution of the current interrupt handler is completed, the interrupt handler variable identifier of the interrupt handler variable used by the current interrupt handler is obtained to form an interrupt handler variable identifier set; According to each interrupt handler variable identifier in the interrupt handler variable identifier set, obtain the address offset and interrupt handler variable name of the corresponding interrupt handler variable in the interrupt persistent data storage area; According to the obtained address offset of the interrupt handler variable in the interrupt persistent data storage area and the interrupt handler variable name, the corresponding interrupt handler variable is read from the interrupt persistent data storage area, and the content of the read interrupt handler variable is updated to the current latest value. The current latest value of the interrupt handler variable is stored in the interrupt persistent data storage area to complete the backup and realize the interrupt handler scene protection; Then, the state of each interrupt processing program variable identifier in the interrupt processing program variable identifier set is modified to a to-be-recovered state.
7. A single-chip microcomputer application interrupt triggering field protection device, characterized in that: include: The application running module is used to read the application variables that support the application running when the application is started, and run the application according to the read application variables; The application site protection module is used to stop the application when an interruption occurs during the application operation, read the latest values of the application variables used in the application operation, and back them up to perform application site protection; The interrupt handler running module is used to read the interrupt handler variables that support the running of the current interrupt handler, and run the interrupt handler according to the read interrupt handler variables; The interrupt handler scene protection module is used to read the latest value of the interrupt handler variable used by the interrupt handler when the interrupt handler is executed, and back it up to perform interrupt handler scene protection; The application recovery module is used to read the latest values of the backed-up application variables and continue running the application; The system memory space includes four areas: application on-site data storage area, interrupt persistent data storage area, running data storage area and backup and recovery identification storage area; A backup and recovery identification storage area for storing application variable identifications of application variables used in application program execution, and interrupt handler variable identifications of interrupt handler variables used in interrupt handler execution; An application on-site data storage area is used to store application variables corresponding to the application variable identifier stored in the backup and recovery identifier storage area; An interrupt persistent data storage area, used for storing interrupt handler variables corresponding to the interrupt handler variable identifier stored in the backup recovery identifier storage area; The running data storage area is used to read the corresponding application variables stored in the application site data storage area according to the application variable identifier stored in the backup and recovery identifier storage area, and write the read application variables into the running data storage area, thereby running the application; or to read the corresponding interrupt handler variables stored in the interrupt persistent data storage area according to the interrupt handler variable identifier stored in the backup and recovery identifier storage area, and write the read interrupt handler variables into the running data storage area, thereby running the interrupt handler; Wherein: the application variable identification includes: the application variable name, the address offset of the application variable in the application site data storage area, the interrupt number corresponding to the application variable and the application variable state; wherein the application variable state includes: the state to be backed up and the state to be restored; When the application starts, the application variables that support the application are read, and the application is run according to the read application variables, specifically: When the application is started, the backup and recovery identification storage area is read to obtain the application variable identification corresponding to the current interrupt number and the status to be backed up; According to each application variable identifier read, the address offset and application variable name of the corresponding application variable in the application site data storage area are obtained; Read the corresponding application variable from the application on-site data storage area according to the obtained address offset of the application variable in the application on-site data storage area and the application variable name, and write the read application variable to the running data storage area; Run the application based on the application variables in the running data store; When an interruption occurs during the application's operation, the application is stopped, the latest values of the application variables used in the application are read and backed up, and the application site is protected. Specifically: Set the interrupt number for this time; When an interruption occurs during the running of the application, the running of the application is stopped, and the application variable identifiers of the application variables used in the current running of the application are obtained to form an application variable identifier set; Modify the status of each application variable identifier belonging to the application variable identifier set in the backup recovery identifier storage area to the waiting-for-recovery status, and modify the interrupt number corresponding to the application variable to the current interrupt number; According to the application variable identifiers corresponding to the interruption number in each state to be restored, the address offset and application variable name of the corresponding application variable in the application field data storage area are obtained; Based on the address offset and application variable name of the obtained application variable in the application field data storage area, the corresponding application variable is read from the application field data storage area, and the content of each read application variable is updated to the current latest value. The current latest value of the application variable is stored in the application field data storage area to achieve backup and perform application field protection.
8. A storage medium, characterized in that: A computer program is stored on the storage medium. When the processor executes the computer program stored on the storage medium, the method for triggering on-site protection by an interruption of a microcontroller application program as described in any one of claims 1 to 6 is implemented, or the device for triggering on-site protection by an interruption of a microcontroller application program as described in claim 7 is implemented.
9. A computer device, characterized in that: The computer device includes a memory and a processor, the memory is used to store a computer executable program, and the processor is used to run the computer executable program to implement the single-chip microcomputer application interrupt triggering field protection method described in any one of claims 1 to 6, or implement the single-chip microcomputer application interrupt triggering field protection device described in claim 7.
Citation Information
Patent Citations
Data protection method and computing device
CN110598406A
Processing apparatus, processing system, and processing method
CN114579264A