A method, apparatus, system, and storage medium for preventing microcontroller crashes.

By determining variable cycles based on business in the microcontroller and sending dog feeding signals to the driver layer and hardware layer, the traditional watchdog cannot adapt to complex applications is solved, and the adaptability to multi-service abnormal restart of the microcontroller is achieved and Working normally.

CN112948162BActive Publication Date: 2024-12-31NANJING NENGRUI AUTOMATION EQUIP
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202110275623.X
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2021-03-15
Publication Date
2024-12-31
Estimated Expiration
2041-03-15

AI Technical Summary

Technical Problem

Traditional watchdogs cannot adapt to the time-consuming and unfixed situations in complex microcontroller applications within a fixed cycle, resulting in the inability to effectively prevent crashes.

Method used

The application layer determines a variable cycle based on the current service, and sends a dog feeding signal to the driver layer and the hardware layer within this cycle. If the signal is not received, a reset signal will be sent to the microcontroller, which solves the fixed small-period reset mechanism in traditional watchdogs. limitations.

Benefits of technology

It realizes adaptability to multi-service, multi-system and multi-scheduling abnormal restart of microcontrollers, avoids crashes, and ensures the normal operation of microcontrollers.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN112948162B_ABST
    Figure CN112948162B_ABST
Patent Text Reader

Abstract

The embodiment of the present invention discloses a method, device, system and storage medium for preventing a single-chip microcomputer from freezing. The method includes: the application layer determines the first cycle according to the current business, and sends a dog-feeding signal to the driver layer within the first cycle; the driver layer receives the dog-feeding signal sent by the application layer within the first cycle, and then sends the dog-feeding signal to the hardware layer within the second cycle; the hardware layer does not receive the dog-feeding signal sent by the driver layer within the second cycle, and then sends a reset signal to the single-chip microcomputer. The technical solution provided by the embodiment of the present invention can solve the limitations of the fixed small-cycle reset mechanism in the traditional watchdog, thereby adapting to the various abnormal restart requirements of the single-chip microcomputer with multiple businesses, multiple systems and multiple scheduling, and ensuring the normal operation of the single-chip microcomputer.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The embodiments of the present invention relate to the application field of single-chip microcomputers, and in particular to a method, device, system and storage medium for preventing a single-chip microcomputer from freezing. Background Art

[0002] With the development of single-chip microcomputer (MCU) technology, MCU has been widely used in industrial control, communication, aviation, smart home appliances, medical and military fields. However, if the MCU is interfered by external electromagnetic fields during operation, it will freeze, causing the entire device system to stagnate, resulting in unpredictable consequences. Watchdog is an important means to prevent MCU freezes and cause system paralysis.

[0003] If a traditional watchdog does not receive a feeding signal within a fixed period, it will send a reset signal to the microcontroller. However, the fixed period is very short and cannot adapt to the complex and time-consuming big data applications of the microcontroller. In addition, many advanced applications of the microcontroller have the phenomenon of non-fixed time consumption and exceeding the fixed period. For example, when a microcontroller with an operating system application is started, the system loading time takes 5 to 20 seconds. For another example, the uneven allocation of time resources during the operation of a microcontroller with complex multi-process and multi-threaded applications will cause some applications to stagnate for more than a fixed period, and the traditional watchdog cannot solve the above problems.

[0004] At present, there is no better way to solve the problem of microcontroller crashes. Summary of the invention

[0005] The embodiments of the present invention provide a method, device, system and storage medium for preventing a single-chip microcomputer from freezing, which can solve the limitations of the fixed small-cycle reset mechanism in the traditional watchdog, thereby adapting to various abnormal restart requirements of the single-chip microcomputer with multiple services, multiple systems and multiple scheduling, and ensuring the normal operation of the single-chip microcomputer.

[0006] In a first aspect, an embodiment of the present invention provides a method for preventing a single-chip computer from crashing, which is applied to a system for preventing a single-chip computer from crashing. The system for preventing a single-chip computer from crashing includes a single-chip computer and a hardware layer. The single-chip computer includes an application layer and a driver layer. The application layer is connected to the driver layer in communication. The driver layer is connected to the hardware layer in communication. The hardware layer is connected to the single-chip computer in communication. The method includes:

[0007] The application layer determines a first cycle according to the current service, and sends a dog feeding signal to the driver layer within the first cycle;

[0008] The driver layer receives the dog-feeding signal sent by the application layer in the first cycle, and then sends the dog-feeding signal to the hardware layer in the second cycle;

[0009] If the hardware layer does not receive the dog feeding signal sent by the driving layer within the second period, a reset signal is sent to the single chip microcomputer.

[0010] In a second aspect, an embodiment of the present invention provides a device for preventing a single-chip computer from crashing, which is integrated into a system for preventing a single-chip computer from crashing. The system for preventing a single-chip computer from crashing includes a single-chip computer and a hardware layer. The single-chip computer includes an application layer and a driver layer. The application layer is connected to the driver layer in communication. The driver layer is connected to the hardware layer in communication. The hardware layer is connected to the single-chip computer in communication. The device includes:

[0011] A first signal sending module configured in the application layer, used to determine a first period according to the current service, and send a dog feeding signal to the driver layer within the first period;

[0012] A second signal sending module configured in the driver layer, configured to receive a dog-feeding signal sent by the application layer in the first cycle, and then send a dog-feeding signal to the hardware layer in a second cycle;

[0013] The third signal sending module configured in the hardware layer is used to send a reset signal to the single-chip microcomputer if the dog feeding signal sent by the driving layer is not received within the second period.

[0014] In a third aspect, an embodiment of the present invention provides a system for preventing a single-chip computer from freezing, the system comprising:

[0015] A single-chip microcomputer and a hardware layer, wherein the single-chip microcomputer includes an application layer and a driver layer, wherein the application layer is connected to the driver layer for communication, wherein the driver layer is connected to the hardware layer for communication, and wherein the hardware layer is connected to the single-chip microcomputer for communication;

[0016] The system for preventing a single-chip computer from crashing is used to execute the method for preventing a single-chip computer from crashing described in any embodiment of the present invention.

[0017] In a fourth aspect, an embodiment of the present invention provides a computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements the method for preventing a single-chip computer from crashing as described in any embodiment of the present invention.

[0018] The embodiment of the present invention provides a method, device, system and storage medium for preventing a single-chip microcomputer from freezing. First, the application layer determines the first cycle according to the current business, and sends a dog-feeding signal to the driver layer in the first cycle. Then, if the driver layer receives the dog-feeding signal sent by the application layer in the first cycle, it sends the dog-feeding signal to the hardware layer in the second cycle. Finally, if the hardware layer does not receive the dog-feeding signal sent by the driver layer in the second cycle, it sends a reset signal to the single-chip microcomputer. The technical solution provided by the embodiment of the present invention can solve the limitations of the fixed small cycle reset mechanism in the traditional watchdog, thereby adapting to the requirements of various abnormal restarts of the single-chip microcomputer with multiple businesses, multiple systems and multiple scheduling, and ensuring the normal operation of the single-chip microcomputer. BRIEF DESCRIPTION OF THE DRAWINGS

[0019] Figure 1 A flowchart of a method for preventing a single-chip computer from freezing provided in the first embodiment of the present invention;

[0020] Figure 2A A flowchart of a method for preventing a single-chip computer from freezing provided in Embodiment 2 of the present invention;

[0021] Figure 2B A flow chart of the interaction between the application layer, the driver layer, the hardware layer and the single-chip microcomputer in the method provided in the second embodiment of the present invention;

[0022] Figure 3 A schematic diagram of the structure of a device for preventing a single-chip computer from freezing provided in Embodiment 3 of the present invention;

[0023] Figure 4 A schematic diagram of the structure of a system for preventing a single-chip computer from freezing provided in a fourth embodiment of the present invention. DETAILED DESCRIPTION

[0024] The present invention will be further described in detail below in conjunction with the accompanying drawings and embodiments. It is to be understood that the specific embodiments described herein are only used to explain the present invention, rather than to limit the present invention. It should also be noted that, for ease of description, only parts related to the present invention, rather than all structures, are shown in the accompanying drawings.

[0025] Embodiment 1

[0026] Figure 1 This is a flow chart of a method for preventing a single-chip computer from crashing provided in the first embodiment of the present invention. This embodiment can be applied to preventing a single-chip computer from crashing and ensuring the normal operation of the single-chip computer. The method for preventing a single-chip computer from crashing provided in this embodiment can be executed by a device for preventing a single-chip computer from crashing provided in an embodiment of the present invention. The device can be implemented in software and / or hardware and integrated in a system for preventing a single-chip computer from crashing that executes this method.

[0027] See also Figure 1The method of this embodiment includes but is not limited to the following steps:

[0028] S110, the application layer determines a first cycle according to the current service, and sends a dog-feeding signal to the driver layer within the first cycle.

[0029] Among them, the application layer in the single-chip microcomputer can be understood as writing key function programs according to different projects. It belongs to the top-level program and uses the message interface provided by the driver layer. The driver layer in the single-chip microcomputer mainly operates the value of the register, that is, no matter how the hardware layer is wired, the driver layer does not need to consider it, but only needs to consider the value of the register. Its other function is to provide a message interface for the driver layer.

[0030] Specifically, if the single-chip microcomputer is interfered by the external electromagnetic field during operation, it will freeze, causing the entire device system to stagnate, resulting in unpredictable consequences. The watchdog is an important means to prevent the single-chip microcomputer from freezing and causing system paralysis, and it monitors the operation status of the single-chip microcomputer system through a combination of software and hardware. The working principle of the watchdog is: the stable running software will feed the dog after executing a specific instruction. If the watchdog does not receive the dog feeding signal from the software within a certain period, it is considered that the system is faulty and will enter the interrupt processing program or force the system to reset. Since the application layer contains a variety of services, and the period corresponding to each service may be different, the application layer can determine the first period corresponding to the current service according to the current service, and send a dog feeding signal to the driver layer in the first period, so that the subsequent driver layer receives the dog feeding signal sent by the application layer in the first period, and then sends the dog feeding signal to the hardware layer in the second period.

[0031] S120, the driver layer receives the dog feeding signal sent by the application layer in the first cycle, and then sends the dog feeding signal to the hardware layer in the second cycle.

[0032] Among them, the hardware layer is the basis of the driver layer, which can be understood as the hardware facilities related to the realization of the functions of the microcontroller.

[0033] After the application layer sends the dog-feeding signal to the driver layer in the first cycle, the driver layer determines that it has received the dog-feeding signal sent by the application layer in the first cycle, and then sends the dog-feeding signal to the hardware layer in the second cycle, so that the subsequent hardware layer determines that it has not received the dog-feeding signal sent by the driver layer in the second cycle, and then sends a reset signal to the microcontroller, thereby avoiding the microcontroller from freezing, causing the system of the entire device to stagnate and cause losses.

[0034] S130, if the hardware layer does not receive the dog feeding signal sent by the driver layer within the second cycle, a reset signal is sent to the single chip microcomputer.

[0035] After the driver layer sends the dog feeding signal to the hardware layer in the second cycle, the hardware layer determines that it has not received the dog feeding signal sent by the driver layer in the second cycle, indicating that the hardware layer or the single-chip microcomputer may have a fault, and then sends a reset signal to the single-chip microcomputer.

[0036] The technical solution provided by this embodiment is that the application layer first determines the first cycle according to the current business, and sends a dog-feeding signal to the driver layer within the first cycle. Then, if the driver layer receives the dog-feeding signal sent by the application layer within the first cycle, it sends the dog-feeding signal to the hardware layer within the second cycle. Finally, if the hardware layer does not receive the dog-feeding signal sent by the driver layer within the second cycle, it sends a reset signal to the microcontroller. This can solve the limitations of the fixed small-cycle reset mechanism in the traditional watchdog, thereby adapting to various abnormal restart requirements of the microcontroller for multiple businesses, multiple systems and multiple scheduling, and ensuring the normal operation of the microcontroller.

[0037] In some embodiments, the application layer determines the first period based on the current business, which may specifically include: the application layer detects whether the current business has changed; if so, the application layer determines the execution time corresponding to the changed business based on the changed business, determines the first period based on the execution time, and sends a command to configure the first period to the driver layer, so that the driver layer configures the first period.

[0038] Among them, the first cycle can be understood as the cycle of the watchdog.

[0039] Specifically, there are various services in the application layer, and the execution time of each service is long or short, so it is necessary to configure the first cycle of the watchdog according to the execution time of different services. The application layer can detect whether the current service has changed. If the application layer detects that the current service has changed, the execution time corresponding to the changed service is determined according to the changed service. The method for determining the execution time corresponding to the changed service can be: according to the historical execution of the changed service, the time spent in each historical execution process is determined, and then the average of these times is calculated to obtain the execution time corresponding to the changed service, or the time corresponding to the execution process that takes the longest time in the historical execution process of the changed service is determined as the execution time corresponding to the changed service; it can also be: storing the execution times corresponding to different services in the application layer, for example, in the form of a corresponding relationship table. When it is necessary to determine the first cycle corresponding to the changed service, it can be obtained by directly querying this table. The corresponding relationship table can be set in advance according to actual business needs. After obtaining the execution time corresponding to the changed service, the first period can be determined according to the execution time, for example, the value obtained by adding the preset time to the execution time is determined as the first period, wherein the preset time can be pre-set or determined according to the actual situation, and this embodiment does not make specific restrictions. And the application layer will send a command to configure the first period to the driver layer, so that the driver layer configures the first period according to the received command. On the contrary, if the application layer detects that the current service has not changed, the corresponding first period does not need to be changed.

[0040] It should be noted that there are many other ways to determine the execution time corresponding to the changed service, and the embodiment of the present invention does not make any specific limitation.

[0041] In this embodiment, the application layer detects whether the current business has changed, and redetermines the first period when the change occurs, and does not change the first period when the change does not occur, so that the fixed period in the traditional watchdog becomes a variable period, thereby adapting to the situation where the time consumption is not fixed and exceeds the fixed period in many advanced applications of single-chip microcomputers. For example, when a single-chip microcomputer with an operating system application is started, the system loading time takes between 5 and 20 seconds. In another example, when a single-chip microcomputer with a multi-process and multi-threaded complex application is running, the uneven allocation of time resources causes some applications to stagnate for more than a fixed period.

[0042] In some embodiments, if the driver layer does not receive the dog feeding signal sent by the application layer in the first cycle, it will not send the dog feeding signal to the hardware layer in the second cycle to reset the single chip microcomputer.

[0043] In the embodiment of the present invention, if the driver layer does not receive the dog-feeding signal sent by the application layer in the first cycle, it will not send the dog-feeding signal to the hardware layer in the second cycle. Then the hardware layer will not receive the dog-feeding signal sent by the driver layer. As a result, the hardware layer will send a reset signal to the microcontroller to reset the microcontroller, thereby avoiding the microcontroller from freezing.

[0044] In some embodiments, after the hardware layer sends a reset signal to the single-chip microcomputer, the method may further specifically include: the single-chip microcomputer controls the single-chip microcomputer to perform a restart operation according to the received reset signal.

[0045] In the embodiment of the present invention, the single chip microcomputer controls the single chip microcomputer to execute a restart operation according to the received reset signal, thereby avoiding system paralysis caused by the single chip microcomputer freezing, and saving time and efficiency for users.

[0046] Embodiment 2

[0047] Figure 2A A flowchart of a method for preventing a single-chip computer from freezing is provided for the second embodiment of the present invention. The embodiment of the present invention is optimized on the basis of the above embodiment. Optionally, this embodiment provides a detailed explanation of the process before the driver layer receives the dog-feeding signal sent by the application layer in the first cycle and the process before the hardware layer does not receive the dog-feeding signal sent by the driver layer in the second cycle.

[0048] See also Figure 2A The method of this embodiment includes but is not limited to the following steps:

[0049] S210, the application layer determines a first cycle according to the current service, and sends a dog feeding signal to the driver layer within the first cycle.

[0050] Optionally, before the application layer determines the first period according to the current service, the process may further specifically include: the application layer starts the driver layer.

[0051] Specifically, the application layer may send a start signal to the driver layer, thereby starting the driver layer.

[0052] In the embodiment of the present invention, by starting the driver layer in the application layer, it is convenient for the subsequent driver layer to manage the software watchdog, configure the watchdog cycle, detect whether the driver layer receives the dog feeding signal from the application layer, and the driver layer determines whether to send the dog feeding signal to the hardware layer based on the first difference.

[0053] Furthermore, after the application layer sends the dog feeding signal to the driver layer in the first cycle, the following may be specifically included: the application layer performs service scheduling.

[0054] In the embodiment of the present invention, different services can be executed by performing service scheduling through the application layer, thereby realizing corresponding functions. Meanwhile, after the application layer performs service scheduling, it is necessary to continue to detect whether the current service has changed.

[0055] S220, the driver layer starts an interrupt timer and detects whether a dog feeding signal sent by the application layer is received in the interrupt timer scheduling.

[0056] Among them, the interrupt timer can be an interrupt requested by the overflow of the timer in the microcontroller. The driver layer runs an independent cycle scheduling by turning on the interrupt timer with the highest priority. In the interrupt timer scheduling, it detects whether the driver layer receives the dog feeding signal sent by the application layer and whether the driver layer wants to send the dog feeding signal to the hardware layer.

[0057] It should be noted that: in this embodiment, the interrupt timer scheduling can be executed repeatedly, so as to continuously detect whether the driver layer receives the dog feeding signal sent by the application layer.

[0058] Specifically, the driver layer can start an interrupt timer and continuously detect whether the dog-feeding signal sent by the application layer is received in the interrupt timer scheduling, so that if the driver layer receives the dog-feeding signal sent by the application layer later, it can obtain and record the first moment when the application layer sends the dog-feeding signal to the driver layer.

[0059] Optionally, before the driver layer starts the interrupt timer, the process may further specifically include: the driver layer starts the hardware layer.

[0060] Specifically, the driver layer may send a start signal to the hardware layer, thereby starting the hardware layer.

[0061] In the embodiment of the present invention, by starting the hardware layer in the driver layer, it is convenient for the subsequent hardware layer to manage the hardware watchdog, detect whether the hardware layer receives the dog feeding signal from the driver layer, and whether the hardware layer sends a reset signal to the single-chip microcomputer.

[0062] S230: If the driving layer receives the dog-feeding signal sent by the application layer, obtain and record the first moment when the application layer sends the dog-feeding signal to the driving layer.

[0063] Specifically, if the driving layer receives a dog-feeding signal sent by the application layer, the first moment when the application layer sends the dog-feeding signal to the driving layer is obtained and recorded. The first moment can be used to calculate how long the driving layer has not received the dog-feeding signal sent by the application layer, so that the driving layer can subsequently subtract the current moment from the first moment to obtain a first difference, and compare the first difference with the size of the first period to determine whether the driving layer has received the dog-feeding signal sent by the application layer within the first period.

[0064] It should be noted that: since the time difference between the moment when the application layer sends the dog-feeding signal to the driver layer and the moment when the driver layer receives the dog-feeding signal sent by the application layer is very small, it can be ignored. Therefore, the moment when the application layer sends the dog-feeding signal to the driver layer can be equivalent to the moment when the driver layer receives the dog-feeding signal sent by the application layer.

[0065] Optionally, if the driver layer does not receive the dog feeding signal sent by the application layer, the time when the application layer last sent the dog feeding signal to the driver layer is taken as the first time to avoid errors in the recording of the first time, which affects the subsequent execution of S240.

[0066] S240, the driving layer subtracts the current moment from the first moment to obtain a first difference, and compares the first difference with the size of the first cycle to determine whether the driving layer receives a dog feeding signal sent by the application layer within the first cycle.

[0067] The driver layer can obtain the first difference after subtracting the current moment from the first moment. The driver layer compares the first difference with the size of the first period to determine whether the driver layer receives the dog-feeding signal sent by the application layer within the first period. Specifically, if the first difference is smaller than the first period, it means that the driver layer receives the dog-feeding signal sent by the application layer within the first period; otherwise, it means that the driver layer does not receive the dog-feeding signal sent by the application layer within the first period.

[0068] S250, the driver layer receives the dog-feeding signal sent by the application layer in the first cycle, and then sends the dog-feeding signal to the hardware layer in the second cycle.

[0069] S260, if the hardware layer does not receive the dog feeding signal sent by the driver layer within the second cycle, a reset signal is sent to the single chip microcomputer.

[0070] Optionally, before the hardware layer fails to receive the dog-feeding signal sent by the driver layer within the second cycle, the process may further specifically include: the hardware layer controls the watchdog enable, determines that the cycle of the watchdog enable is the second cycle, and detects whether the dog-feeding signal sent by the driver layer is received; if the hardware layer receives the dog-feeding signal sent by the driver layer, obtains and records the second moment when the driver layer sends the dog-feeding signal to the hardware layer; the hardware layer subtracts the current moment from the second moment to obtain a second difference, and compares the second difference with the size of the second cycle to determine whether the hardware layer receives the dog-feeding signal sent by the driver layer within the second cycle.

[0071] Here, enabling can be understood as starting.

[0072] Specifically, if the second difference is greater than the second period, it means that the hardware layer has not received the dog feeding signal sent by the driver layer within the second period; if the second difference is less than or equal to the second period, it means that the hardware layer has received the dog feeding signal sent by the driver layer within the second period.

[0073] In the embodiment of the present invention, the hardware layer subtracts the current moment from the second moment to continuously obtain the second difference, and then compares the second difference with the size of the second period to determine whether the hardware layer receives the dog feeding signal sent by the driver layer within the second period. The final result is more accurate and more in line with the actual situation.

[0074] Furthermore, if the hardware layer does not receive the dog-feeding signal sent by the driver layer, the time when the driver layer last sent the dog-feeding signal to the hardware layer is taken as the second time, so as to avoid errors in the recording of the second time, which will affect the accuracy of the result of determining whether the hardware layer has received the dog-feeding signal sent by the driver layer within the second cycle.

[0075] Furthermore, when the hardware layer receives the dog feeding signal sent by the driver layer in the second cycle, it does not send a reset signal to the single-chip microcomputer, and re-detects whether the dog feeding signal sent by the driver layer is received.

[0076] In the embodiment of the present invention, the hardware layer receives the dog-feeding signal sent by the driver layer within the second cycle, indicating that the single-chip microcomputer is working normally at this time, and no reset signal is sent to the single-chip microcomputer, and re-detection is performed to determine whether the dog-feeding signal sent by the driver layer is received. Through the continuous detection process, missed detection and misjudgment can be avoided.

[0077] Specifically, Figure 2B This is a flowchart of the interaction between the application layer, the driver layer, the hardware layer and the single-chip microcomputer in the method provided in the second embodiment of the present invention, see Figure 2B The interaction process includes but is not limited to the following steps:

[0078] S2001, sending a start signal.

[0079] S2002, detecting whether the current business has changed.

[0080] If yes, execute S2003; if no, execute S2005.

[0081] S2003, determining a corresponding execution time according to the changed business, and determining a first period according to the execution time.

[0082] S2004, sending a command to configure the first cycle, and sending a dog feeding signal in the first cycle.

[0083] S2005, the first cycle is not changed.

[0084] S2006, sending a dog feeding signal in the first cycle.

[0085] S2007, perform business scheduling.

[0086] S2008, sending a start signal.

[0087] S2009, start the interrupt timer.

[0088] S2010, detecting whether a dog feeding signal is received.

[0089] If so, execute S2011; if not, execute S2012.

[0090] S2011, obtaining and recording the first moment when the application layer sends a dog-feeding signal to the driver layer.

[0091] S2012, taking the time when the application layer last sent a dog-feeding signal to the driver layer as the first time.

[0092] S2013, subtract the current moment from the first moment to obtain a first difference, and compare the first difference with the size of the first period to determine whether a dog-feeding signal sent by the application layer is received within the first period.

[0093] S2014: If received, send a dog feeding signal in the second cycle.

[0094] S2015, controlling the watchdog enable, and determining that the cycle of the watchdog enable is the second cycle.

[0095] S2016, detecting whether a dog feeding signal is received.

[0096] If yes, execute S2017; if no, execute S2018.

[0097] S2017, obtaining and recording the second moment when the driver layer sends a dog-feeding signal to the hardware layer.

[0098] S2018, taking the time when the driver layer last sent a dog feeding signal to the application layer as the second time.

[0099] S2019, subtract the current moment from the second moment to obtain a second difference, and compare the second difference with the size of the second cycle to determine whether the hardware layer receives the dog feeding signal sent by the driver layer within the second cycle.

[0100] S2020: If not received, send a reset signal.

[0101] The technical solution provided by this embodiment is that first, the application layer determines the first cycle according to the current business, and sends a dog feeding signal to the driver layer within the first cycle. Then the driver layer starts the interrupt timer and detects whether the dog feeding signal sent by the application layer is received in the interrupt timer scheduling. If the driver layer receives the dog feeding signal sent by the application layer, the first moment when the application layer sends the dog feeding signal to the driver layer is obtained and recorded. The driver layer subtracts the current moment from the first moment to obtain a first difference, and compares the first difference with the size of the first cycle to determine whether the driver layer receives the dog feeding signal sent by the application layer within the first cycle. Then, if the driver layer receives the dog feeding signal sent by the application layer within the first cycle, it sends the dog feeding signal to the hardware layer within the second cycle. Finally, if the hardware layer does not receive the dog feeding signal sent by the driver layer within the second cycle, it sends a reset signal to the single-chip microcomputer. The interrupt timer in the driver layer can continuously detect whether the driver layer receives the dog feeding signal sent by the application layer, thereby determining whether the driver layer sends the dog feeding signal to the hardware layer. The limitations of the fixed small cycle reset mechanism in the traditional watchdog are solved, thereby adapting to the requirements of various abnormal restarts of multi-business, multi-system and multi-scheduling of the single-chip microcomputer, and ensuring the normal operation of the single-chip microcomputer.

[0102] Embodiment 3

[0103] Figure 3 A schematic diagram of the structure of a device for preventing a single-chip computer from freezing provided by the third embodiment of the present invention is shown in FIG. Figure 3 As shown, the device may include:

[0104] A first signal sending module 310 configured in the application layer, used to determine a first cycle according to the current service, and send a dog feeding signal to the driver layer within the first cycle;

[0105] A second signal sending module 320 configured in the driver layer is used to receive a dog-feeding signal sent by the application layer in the first cycle, and then send a dog-feeding signal to the hardware layer in a second cycle;

[0106] The third signal sending module 330 configured in the hardware layer is used to send a reset signal to the single chip microcomputer if the dog feeding signal sent by the driving layer is not received within the second period.

[0107] The technical solution provided by this embodiment is that the application layer first determines the first cycle according to the current business, and sends a dog-feeding signal to the driver layer within the first cycle. Then, if the driver layer receives the dog-feeding signal sent by the application layer within the first cycle, it sends the dog-feeding signal to the hardware layer within the second cycle. Finally, if the hardware layer does not receive the dog-feeding signal sent by the driver layer within the second cycle, it sends a reset signal to the microcontroller. This can solve the limitations of the fixed small-cycle reset mechanism in the traditional watchdog, thereby adapting to various abnormal restart requirements of the microcontroller for multiple businesses, multiple systems and multiple scheduling, and ensuring the normal operation of the microcontroller.

[0108] Furthermore, the above-mentioned first signal sending module 310 can be specifically used for: the application layer detects whether the current business has changed; if so, the application layer determines the execution time corresponding to the changed business according to the changed business, determines the first cycle according to the execution time, and sends a command to configure the first cycle to the driver layer, so that the driver layer configures the first cycle.

[0109] Furthermore, the above-mentioned device for preventing the single-chip computer from crashing may also include: a detection module, which is used for the driver layer to start the interrupt timer and detect whether the dog-feeding signal sent by the application layer is received in the interrupt timer scheduling; a first moment acquisition module, which is used for if the driver layer receives the dog-feeding signal sent by the application layer, to obtain and record the first moment when the application layer sends the dog-feeding signal to the driver layer; a comparison module, which is used for the driver layer to subtract the current moment from the first moment to obtain a first difference, and compare the first difference with the size of the first period to determine whether the driver layer receives the dog-feeding signal sent by the application layer within the first period.

[0110] Furthermore, the above-mentioned device for preventing the microcontroller from crashing may also include: a reset module, which is used for not sending a dog feeding signal to the hardware layer in the second cycle if the driver layer does not receive the dog feeding signal sent by the application layer in the first cycle, so as to reset the microcontroller.

[0111] Furthermore, the above-mentioned device for preventing the single-chip computer from crashing may also include: an enabling module, which is used for the hardware layer to control the watchdog enabling, determine that the cycle of the watchdog enabling is the second cycle, and detect whether the dog feeding signal sent by the driver layer is received; a second moment acquisition module, which is used for if the hardware layer receives the dog feeding signal sent by the driver layer, to obtain and record the second moment when the driver layer sends the dog feeding signal to the hardware layer; a signal receiving module, which is used for the hardware layer to subtract the current moment from the second moment to obtain a second difference, and compare the second difference with the size of the second cycle to determine whether the hardware layer receives the dog feeding signal sent by the driver layer within the second cycle.

[0112] Furthermore, the above-mentioned device for preventing the microcontroller from crashing may also include: a first detection module, which is used for not sending a reset signal to the microcontroller when the hardware layer receives the dog-feeding signal sent by the driver layer within the second period, and re-detecting whether the dog-feeding signal sent by the driver layer is received.

[0113] Furthermore, the above-mentioned device for preventing the single-chip computer from freezing may also include: a restart module, which is used for the single-chip computer to control the single-chip computer to perform a restart operation according to the reset signal received.

[0114] The device for preventing a single-chip computer from crashing provided in this embodiment can be applied to the method for preventing a single-chip computer from crashing provided in any of the above embodiments, and has corresponding functions and beneficial effects.

[0115] Embodiment 4

[0116] Figure 4 A schematic diagram of the structure of a system for preventing a single-chip computer from freezing is provided in Embodiment 4 of the present invention. Figure 4 As shown, the system includes a single-chip microcomputer 410 and a hardware layer 420. The single-chip microcomputer 410 includes an application layer 4101 and a driver layer 4102. The application layer 4101 and the driver layer 4102 are connected in communication, the driver layer 4102 and the hardware layer 420 are connected in communication, and the hardware layer 420 and the single-chip microcomputer 410 are connected in communication. In this embodiment, the application layer 4101 and the driver layer 4102, the driver layer 4102 and the hardware layer 420, and the hardware layer 420 and the single-chip microcomputer 410 can be connected through a bus or other means. Figure 4 The example of connecting through bus is taken in the following.

[0117] The system for preventing a single-chip computer from crashing provided in this embodiment can be used to execute the method for preventing a single-chip computer from crashing provided in any of the above embodiments, and has corresponding functions and beneficial effects.

[0118] Embodiment 5

[0119] Embodiment 5 of the present invention further provides a computer-readable storage medium on which a computer program is stored. When the program is executed by a processor, the method for preventing a single-chip computer from crashing in any embodiment of the present invention is implemented. The method specifically includes:

[0120] The application layer determines a first cycle according to the current service, and sends a dog feeding signal to the driver layer within the first cycle;

[0121] The driver layer receives the dog-feeding signal sent by the application layer in the first cycle, and then sends the dog-feeding signal to the hardware layer in the second cycle;

[0122] If the hardware layer does not receive the dog feeding signal sent by the driving layer within the second period, a reset signal is sent to the single chip microcomputer.

[0123] Of course, the computer executable instructions of a storage medium including computer executable instructions provided by an embodiment of the present invention are not limited to the operations of the method described above, but can also execute related operations in the method for preventing a single chip computer from crashing provided by any embodiment of the present invention.

[0124] Through the above description of the implementation methods, the technicians in the relevant field can clearly understand that the present invention can be implemented by means of software and necessary general hardware, and of course it can also be implemented by hardware, but in many cases the former is a better implementation method. Based on such an understanding, the technical solution of the present invention, in essence, or the part that contributes to the prior art, can be embodied in the form of a software product, and the computer software product can be stored in a computer-readable storage medium, such as a computer floppy disk, a read-only memory (ROM), a random access memory (RAM), a flash memory (FLASH), a hard disk or an optical disk, etc., including a number of instructions for a computer device (which can be a personal computer, a server or a network device, etc.) to execute the methods described in each embodiment of the present invention.

[0125] It is worth noting that in the above-mentioned embodiment of the device for preventing the single-chip computer from freezing, the various units and modules included are only divided according to functional logic, but are not limited to the above-mentioned division, as long as the corresponding functions can be achieved; in addition, the specific names of the functional units are only for the convenience of distinguishing each other, and are not used to limit the scope of protection of the present invention.

[0126] The above description is only a preferred embodiment of the present invention and is not intended to limit the present invention. For those skilled in the art, the present invention may have various modifications and variations. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present invention shall be included in the protection scope of the present invention.

Claims

1. A method for preventing a single chip computer from freezing, characterized in that: A system for preventing a single-chip computer from freezing, the system comprising a single-chip computer and a hardware layer, the single-chip computer comprising an application layer and a driver layer, the application layer and the driver layer are connected in communication, the driver layer and the hardware layer are connected in communication, the hardware layer and the single-chip computer are connected in communication, and the method comprises: The application layer determines a first cycle according to the current service, and sends a dog feeding signal to the driver layer within the first cycle; The driver layer receives the dog-feeding signal sent by the application layer in the first cycle, and then sends the dog-feeding signal to the hardware layer in the second cycle; If the hardware layer does not receive the dog feeding signal sent by the driver layer within the second period, a reset signal is sent to the single chip microcomputer; The application layer determines the first period according to the current service, including: The application layer detects whether the current service has changed; If yes, the application layer determines the execution time corresponding to the changed service according to the changed service, determines the first cycle according to the execution time, and sends a command for configuring the first cycle to the driver layer, so that the driver layer configures the first cycle; The application layer determines the execution time corresponding to the changed service according to the changed service, including: The average value of the historical execution time corresponding to the changed service is used as the execution time corresponding to the changed service; or, The longest historical execution time of the changed service in the historical execution process is used as the execution time corresponding to the changed service; or, Querying a preset correspondence table, and determining the execution time corresponding to the changed service from the correspondence table; Before the application layer determines the first cycle according to the current business, the method further includes: the application layer starts the driver layer, so that the driver layer manages the software watchdog, configures the watchdog cycle, detects whether the driver layer receives the watchdog feeding signal from the application layer, and the driver layer determines whether to send the watchdog feeding signal to the hardware layer according to the first difference; After the application layer sends the dog feeding signal to the driving layer in the first cycle, the method further includes: the application layer performs service scheduling to execute different services.

2. The method according to claim 1, characterized in that Before the driver layer receives the dog feeding signal sent by the application layer in the first cycle, the method further includes: The driver layer starts an interrupt timer and detects whether a dog feeding signal sent by the application layer is received in the interrupt timer scheduling; If the driver layer receives the dog-feeding signal sent by the application layer, acquiring and recording the first time when the application layer sends the dog-feeding signal to the driver layer; The driving layer subtracts the current time from the first time to obtain a first difference, and compares the first difference with the size of the first period to determine whether the driving layer receives the dog feeding signal sent by the application layer within the first period.

3. The method according to claim 1, characterized in that Also includes: If the driver layer does not receive the dog feeding signal sent by the application layer in the first cycle, it will not send the dog feeding signal to the hardware layer in the second cycle, so as to reset the single chip microcomputer.

4. The method according to claim 1, characterized in that: Before the hardware layer fails to receive the dog feeding signal sent by the driver layer in the second cycle, the method further includes: The hardware layer controls the watchdog enable, determines that the watchdog enable cycle is the second cycle, and detects whether the watchdog feeding signal sent by the driver layer is received; If the hardware layer receives the dog-feeding signal sent by the driver layer, acquiring and recording the second time when the driver layer sends the dog-feeding signal to the hardware layer; The hardware layer subtracts the current time from the second time to obtain a second difference, and compares the second difference with the size of the second period to determine whether the hardware layer receives the dog feeding signal sent by the driver layer within the second period.

5. The method according to claim 4, characterized in that Also includes: If the hardware layer receives the dog feeding signal sent by the driver layer in the second cycle, it does not send a reset signal to the single-chip microcomputer, and re-detects whether the dog feeding signal sent by the driver layer is received.

6. The method according to claim 1, characterized in that After the hardware layer sends a reset signal to the single-chip microcomputer, the method further includes: The single chip microcomputer controls the single chip microcomputer to perform a restart operation according to the received reset signal.

7. A device for preventing a single-chip computer from freezing, characterized in that: Integrated in a system for preventing a single-chip computer from freezing, the system for preventing a single-chip computer from freezing comprises a single-chip computer and a hardware layer, the single-chip computer comprises an application layer and a driver layer, the application layer is connected to the driver layer in communication, the driver layer is connected to the hardware layer in communication, the hardware layer is connected to the single-chip computer in communication, and the device comprises: A first signal sending module configured in the application layer, used to determine a first period according to the current service, and send a dog feeding signal to the driver layer within the first period; A second signal sending module configured in the driver layer, configured to receive a dog-feeding signal sent by the application layer in the first cycle, and then send a dog-feeding signal to the hardware layer in a second cycle; A third signal sending module configured in the hardware layer is used to send a reset signal to the single-chip microcomputer if the dog feeding signal sent by the driver layer is not received within the second period; The first signal sending module may be specifically used for: The application layer detects whether the current service has changed; If yes, the application layer determines the execution time corresponding to the changed service according to the changed service, determines the first cycle according to the execution time, and sends a command for configuring the first cycle to the driver layer, so that the driver layer configures the first cycle; The application layer determines the execution time corresponding to the changed service according to the changed service, including: The average value of the historical execution time corresponding to the changed service is used as the execution time corresponding to the changed service; or, The longest historical execution time of the changed service in the historical execution process is used as the execution time corresponding to the changed service; or, Querying a preset correspondence table, and determining the execution time corresponding to the changed service from the correspondence table; The device also includes a startup module, which is used for: before the application layer determines the first cycle according to the current business, the application layer starts the driver layer, so that the driver layer manages the software watchdog, configures the watchdog cycle, detects whether the driver layer receives the dog feeding signal of the application layer, and the driver layer determines whether to send the dog feeding signal to the hardware layer according to the first difference; The device further comprises a service scheduling module, which is used for: the application layer to perform service scheduling to execute different services after the application layer sends a dog feeding signal to the driving layer in the first cycle.

8. A system for preventing a single-chip computer from freezing, characterized in that: include: A single-chip microcomputer and a hardware layer, wherein the single-chip microcomputer includes an application layer and a driver layer, wherein the application layer is connected to the driver layer for communication, wherein the driver layer is connected to the hardware layer for communication, and wherein the hardware layer is connected to the single-chip microcomputer for communication; The system for preventing a single chip computer from freezing is used to execute the method according to any one of claims 1 to 6.

9. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the program is executed by a processor, the method according to any one of claims 1 to 6 is implemented.