Controller area network fault recovery method and device, equipment and storage medium
The method addresses CAN network fault recovery by reinitializing driver modules and employing fast and slow recovery modes to handle complex faults, ensuring reliable and rapid system recovery from CAN bus offline conditions.
Patent Information
- Application Number
- CN202411030686.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-07-30
- Publication Date
- 2024-12-13
AI Technical Summary
Existing CAN network fault recovery methods are inadequate in handling complex and changing fault conditions, often leading to misjudgment, instability, and unreliable system operation due to fixed threshold detection and simple restart strategies.
A method involving reinitialization of driver modules based on error indication pin status, combined with fast and slow recovery modes, where fast recovery aims for quick communication restoration and slow recovery ensures stability under extensive faults, using interrupt detection and status register analysis to manage CAN bus offline faults.
Enhances system reliability and rapid response to faults by minimizing downtime and ensuring stable recovery from both software and external anomalies, effectively restoring CAN network communication.
Smart Images

Figure CN119126737A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of automotive electronic technology, and in particular to a controller area network fault recovery method, device, equipment and storage medium. Background Art
[0002] With the increasing complexity and functionality of modern automotive electronic systems, the Controller Area Network (CAN), as the main communication method between various control units within the vehicle, undertakes the important task of transmitting real-time data and commands. In order to ensure vehicle safety, efficiency and reliability, the stable operation of the CAN network is essential. However, due to the complexity of the vehicle operating environment and the integration of various electronic devices, the CAN network may face a variety of faults, such as bus offline, communication interruption, etc., which require timely and effective fault recovery.
[0003] At present, the automotive industry usually adopts fixed fault detection methods and simple restart strategies to deal with CAN network faults. For example, a fixed threshold is used to detect the error counter. Once the error counter exceeds the threshold, the node is set to the controller area network bus offline (CAN BUS OFF) state, and then reset or restarted by software or hardware means. In addition, there are some simple error fast recovery strategies, such as waiting for a period of time and then retrying communication, but these methods can often only deal with simple fault scenarios and are difficult to deal with complex fault causes and changing actual application scenarios.
[0004] However, there are many problems with existing CAN network fault recovery methods. Fixed threshold detection methods cannot adapt to complex and changeable fault conditions, which may lead to misjudgment or miss the real fault. Although simple restart strategies can quickly restore communication, they lack effective countermeasures for some deep-seated hardware failures or network topology changes. In addition, these methods often lack adaptability and intelligence, and cannot accurately handle specific fault conditions, resulting in system stability and reliability being affected. Therefore, how to recover from network failures in controller area networks has become an urgent problem to be solved.
[0005] The above contents are only used to assist in understanding the technical solution of the present application and do not constitute an admission that the above contents are prior art. Summary of the invention
[0006] The purpose of the present application is to provide a controller area network fault recovery method, device, equipment and storage medium, aiming to solve the technical problem of how to recover from a controller area network network fault.
[0007] To achieve the above objectives, the present application proposes a controller area network failure recovery method, the method comprising:
[0008] Based on the state of the error indication pin of the controller area network, the driver module is reinitialized to complete the first fault recovery;
[0009] Based on the detection result of the bus offline fault of the controller local area network, the second fault recovery is completed through a fast recovery mode and a slow recovery mode, the fast recovery mode corresponds to a first preset time length, and the slow recovery mode corresponds to a second preset time length, and the first preset time length is less than the second preset time length.
[0010] In one embodiment, the step of completing the second fault recovery through a fast recovery mode and a slow recovery mode based on the detection result of the bus offline fault of the controller area network includes:
[0011] Performing interrupt detection on a bus offline fault of the controller area network through an interrupt mask register;
[0012] When the bus offline fault is detected, reading the status register of the controller area network;
[0013] Determine whether the bus is offline according to the status register, and obtain a determination result;
[0014] When the judgment result is yes, the state of the controller area network is set to a stopped state through the first driver module of the controller area network, and the second fault recovery is completed through a fast recovery mode and a slow recovery mode.
[0015] In one embodiment, the step of completing the second fault recovery through the fast recovery mode and the slow recovery mode includes:
[0016] After waiting for a first preset time, sending a test message to the controller area network to obtain a first sending result;
[0017] When the first sending result is failure, after waiting for the first preset time, repeating the step of sending the test message;
[0018] When the number of sending failures is greater than or equal to a second preset number, the second fault recovery is completed through the slow recovery mode.
[0019] In one embodiment, the step of completing the second fault recovery through the slow recovery mode includes:
[0020] After waiting for a second preset time, sending the test message to the controller area network to obtain a second sending result;
[0021] When the second sending result is failure, after waiting for the second preset time, repeating the step of sending the test message;
[0022] When the number of transmission failures is greater than or equal to a third preset number of times, the first driver module of the controller area network and the second driver module of the controller area network are reinitialized to complete the second fault recovery.
[0023] In one embodiment, the step of reinitializing the driver module based on the error indication pin state of the controller area network to complete the first fault recovery includes:
[0024] At preset intervals, detecting the state of an error indication pin of a controller area network to obtain a low level time of the error indication pin;
[0025] When the low level time is greater than or equal to a preset low level time threshold and the first preset number of consecutive detections are all established, the first driver module of the controller area network and the second driver module of the controller area network are reinitialized to complete the first fault recovery.
[0026] In one embodiment, the step of reinitializing the first driver module of the controller area network and the second driver module of the controller area network comprises:
[0027] Stop the data transmission operation with the controller area network and record the context information;
[0028] Initialize a first driver module of the controller area network through a first reset register of the controller area network;
[0029] reconfigure the setting parameters of its own second driver module, and initialize the second driver module through a second reset register;
[0030] The states of the first driving module and the second driving module are restored according to the context information.
[0031] In one embodiment, the step of determining whether the bus is offline fault according to the status register to obtain the determination result includes:
[0032] Read the status register to obtain status information;
[0033] By checking the offline flag, the error counter and the error warning flag in the status information, it is determined whether the bus offline fault exists, and a determination result is obtained.
[0034] In addition, to achieve the above purpose, the present application also proposes a controller area network failure recovery device, the device comprising:
[0035] A first fault recovery module, used for reinitializing the driver module based on the state of the error indication pin of the controller area network to complete the first fault recovery;
[0036] A second fault recovery module is used to complete a second fault recovery through a fast recovery mode and a slow recovery mode based on the detection result of the bus offline fault of the controller local area network, the fast recovery mode corresponds to a first preset time length, and the slow recovery mode corresponds to a second preset time length, and the first preset time length is less than the second preset time length.
[0037] In addition, to achieve the above-mentioned purpose, the present application also proposes a controller local area network fault recovery device, which includes: a memory, a processor, and a computer program stored in the memory and executable on the processor, and the computer program is configured to implement the steps of the controller local area network fault recovery method as described above.
[0038] In addition, to achieve the above-mentioned purpose, the present application also proposes a storage medium, which is a computer-readable storage medium, and a computer program is stored on the storage medium. When the computer program is executed by the processor, the steps of the controller local area network failure recovery method as described above are implemented.
[0039] One or more technical solutions proposed in this application have at least the following technical effects:
[0040] Based on the error indication pin status of the controller local area network, the drive module is reinitialized to complete the first fault recovery; based on the detection result of the bus offline fault of the controller local area network, the second fault recovery is completed through a fast recovery mode and a slow recovery mode, the fast recovery mode corresponds to a first preset time length, and the slow recovery mode corresponds to a second preset time length, and the first preset time length is less than the second preset time length. The present application first monitors and records the state of the error indication pin of CAN, stops the data transmission operation with CAN, and records the relevant context information in detail; then, initializes the first driver module through the first reset register of the controller local area network, and reconfigures its own second driver module and initializes it through the second reset register; restores the state of the first driver module and the second driver module according to the recorded context information to ensure that the system recovers quickly and runs stably; the second fault recovery is based on the detection result of the CAN bus offline fault, and adopts a fast recovery mode and a slow recovery mode, wherein the fast recovery mode corresponds to a shorter first preset time, and the slow recovery mode corresponds to a longer second preset time. The fast recovery mode aims to try to send CAN messages in the shortest time to restore communication, while the slow recovery mode waits for a longer time before trying in complex fault conditions to ensure the stability and reliability of the system under extensive fault conditions. These measures effectively reduce the unavailable time of the system, improve the system's rapid response and automatic recovery capabilities to faults, can automatically restore CAN network faults caused by software anomalies of the CAN node itself, and can automatically restore CAN network communication when external faults disappear, ensuring the safety and reliability of the overall system. BRIEF DESCRIPTION OF THE DRAWINGS
[0041] The accompanying drawings, which are incorporated in and constitute a part of this specification, illustrate embodiments consistent with the present application and, together with the description, serve to explain the principles of the present application.
[0042] In order to more clearly illustrate the embodiments of the present application or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, for ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative labor.
[0043] Figure 1 A flowchart of the first embodiment of the controller local area network failure recovery method of the present application is provided;
[0044] Figure 2 A flowchart of the second embodiment of the controller local area network failure recovery method of the present application is provided;
[0045] Figure 3 A schematic diagram of a brief process of a controller area network failure recovery method provided in Embodiment 2 of the present application;
[0046] Figure 4 This is a schematic diagram of the module structure of a controller local area network failure recovery device according to an embodiment of the present application;
[0047] Figure 5 It is a schematic diagram of the device structure of the hardware operating environment involved in the controller local area network failure recovery method in the embodiment of the present application.
[0048] The purpose, features and advantages of this application will be further described in conjunction with the embodiments and with reference to the accompanying drawings. DETAILED DESCRIPTION
[0049] It should be understood that the specific embodiments described herein are only used to explain the technical solutions of the present application and are not used to limit the present application.
[0050] In order to better understand the technical solution of the present application, a detailed description will be given below in conjunction with the accompanying drawings and specific implementation methods.
[0051] The current automotive industry usually uses fixed threshold detection and simple restart strategies to handle CAN network faults. For example, when the error counter exceeds the threshold, the node is set to the CAN BUS OFF state and software or hardware reset is attempted. However, these methods have limited effect on complex fault scenarios, because fixed thresholds are difficult to deal with variable faults, and simple restart strategies cannot effectively deal with deep hardware faults or network topology changes. At the same time, they lack adaptability and intelligence, affecting system stability and reliability.
[0052] The main solution of the embodiment of the present application is: first, fault detection is realized by monitoring and recording the error indication pin state of CAN, stopping the data transmission operation with CAN, and recording the relevant context information in detail for subsequent analysis and recovery. Subsequently, the system initializes the first driver module using the first reset register of the controller local area network, reconfigures its own second driver module, and initializes it through the second reset register to ensure that the driver module can operate normally after the fault is recovered. According to the recorded context information, the system restores the state of the first driver module and the second driver module to ensure that the system recovers quickly and runs stably. The second fault recovery is based on the detection result of the CAN bus offline fault, and the system adopts a fast recovery mode and a slow recovery mode. The fast recovery mode corresponds to a shorter first preset time, which aims to try to send CAN messages in the shortest time to restore communication; while the slow recovery mode corresponds to a longer second preset time, waiting for a longer time in complex fault conditions before trying again, so as to ensure the stability and reliability of the system in the case of extensive faults. These measures effectively reduce the unavailable time of the system and improve the system's ability to respond quickly to faults and its ability to automatically recover. It can automatically recover CAN network failures caused by software anomalies of the CAN node itself, and automatically restore CAN network communication when external failures disappear, ensuring the safety and reliability of the overall system.
[0053] It should be noted that the execution subject of the embodiment of the present application may be a computing service device with data processing, network communication and program running functions, such as a tablet computer, a personal computer, a mobile phone, etc., or an electronic device, a microcontroller, a vehicle system, etc. capable of realizing the above functions. The following takes a microcontroller as an example to illustrate this embodiment and the following embodiments.
[0054] Based on this, the embodiment of the present application provides a controller local area network failure recovery method, referring to Figure 1 , Figure 1 This is a flow chart of the first embodiment of the controller area network failure recovery method of the present application.
[0055] In this embodiment, the controller area network failure recovery method includes steps S10 to S20:
[0056] Step S10, reinitializing the driver module based on the error indication pin state of the controller area network to complete the first fault recovery;
[0057] It should be noted that the Controller Area Network (CAN) refers to a communication protocol and bus system used in vehicles or equipment to connect various control units and sensors. The error indication pin state refers to a specific pin or signal in the CAN controller or related hardware, which is used to indicate the signal of the CAN bus state or fault condition; in the CAN network, some specific pins or signal lines are usually designed to indicate or reflect the state or error condition of the network. The state of these pins or signal lines can be read by the microcontroller (MCU) or other monitoring devices to perform fault diagnosis and recovery operations. The error indication pin state is the ERR pin (Error Pin) in this embodiment: The CAN controller usually has a dedicated error pin to indicate the error state during the CAN communication process. For example, when the CAN controller detects a communication error, a specific level or signal can be output through the ERR pin to prompt the system that there is an error. The driver module refers to the CAN controller or related hardware module, which is responsible for driving and controlling CAN communication, including: (1) CAN transceiver: The CAN transceiver is the interface circuit between the CAN controller and the CAN bus. It is responsible for converting the electrical signals generated by the CAN controller into electrical signals that can be recognized by the CAN bus, and can receive signals on the CAN bus and convert them to the CAN controller. The CAN transceiver plays the role of physical layer signal conversion and transmission in the CAN network. (2) Controller: The CAN controller is the core component for processing the CAN protocol. It is responsible for processing functions such as sending and receiving data frames, error detection and management. The controller is closely integrated with the CAN transceiver to jointly complete data communication and protocol management. (3) Error handling driver: This refers to the software module or algorithm used to handle error situations on the CAN node. It can monitor and identify errors in CAN communication, such as transmission errors, format errors, etc., and can take appropriate measures to deal with these errors, such as error counting and triggering error interrupts. (4) Clock Driver: The clock driver in the CAN network usually refers to the hardware module or circuit responsible for generating the clock signal required by the CAN bus. The clock signal is crucial for the timing control of CAN communication, which ensures the accurate synchronization of data frames and the stability of communication. (5) Power Management Driver: In some advanced CAN nodes, there may also be software and hardware modules for managing node power supply and energy efficiency. These modules can optimize energy consumption by controlling the power status of the node, and can execute recovery strategies to deal with power anomalies or voltage instability when necessary.The first fault recovery refers to the recovery operation that is first performed after a CAN network fault is detected, such as reinitializing the drive module to try to restore the normal communication state.
[0058] It is understandable that in the controller area network, the error indication pin state indicates the abnormality of the CAN node, such as expressed by the level change of a specific pin. When this state is detected, the system will perform the operation of reinitializing the driver module, which includes resetting the CAN transceiver and the related microcontroller driver. This process is called first fault recovery, which aims to repair CAN network faults caused by software anomalies or external interference and ensure that the node can resume normal communication status.
[0059] As an example, based on the error indication pin status of the controller local area network, the driver module is reinitialized to complete the first fault recovery step, including: detecting the error indication pin status of the controller local area network at preset time intervals to obtain the low level time of the error indication pin; when the low level time is greater than or equal to a preset low level time threshold and the first preset number of consecutive detections are established, reinitializing the first driver module of the controller local area network and its own second driver module to complete the first fault recovery.
[0060] The time interval specified by the preset time is used to periodically detect the state of the error indication pin of the controller area network, for example, the state of the error indication pin of the controller area network is detected every 1 second. The low level time refers to the duration of the error indication pin maintaining a low level. For example, when an error occurs, the pin may maintain a low level for 50 milliseconds. The preset low level time threshold is the threshold of the set low level duration. When the low level time of the error indication pin reaches or exceeds this threshold, the subsequent fault recovery operation will be triggered. For example, when the low level is set to last for more than 30 milliseconds, it is considered that an error has occurred. The first preset number of times refers to the number of times the low level time of the error indication pin is continuously detected to be greater than or equal to the preset low level time threshold. For example, it is necessary to continuously detect more than 3 times of low level for more than 30 milliseconds before the subsequent fault recovery operation is triggered. The first driver module refers to the main driver module of the controller area network, such as the CAN transceiver driver and the controller driver. The second driver module refers to other driver modules indirectly related to CAN communication, such as the error handling driver, the clock driver, and the power management driver. The MCU periodically detects the state of the error indication pin of the controller area network. This period is determined by the preset time, for example, once per second. Once the MCU detects an error, it starts to calculate the specific time that the error indication pin remains at a low level. The preset low-level time threshold is used to determine whether the pin continues to be at a low level for more than the set time, such as 30 milliseconds. The MCU will also continuously detect the number of times the low level exceeds the threshold according to the preset number of requirements, such as 3 times. When the conditions of low-level time and number of times are met, the MCU will perform fault recovery measures, which involves reinitializing the main driver module (first driver module) of the controller LAN and other driver modules (second driver modules) that may be affected. These steps are designed to effectively resolve faults and restore normal operation of the system, ensuring that it can quickly self-repair in the face of abnormal situations.
[0061] As an example, the steps of reinitializing the first driver module of the controller area network and its own second driver module include: stopping the data transmission operation with the controller area network and recording context information; initializing the first driver module of the controller area network through the first reset register of the controller area network; reconfiguring the setting parameters of its own second driver module and initializing the second driver module through the second reset register; and restoring the status of the first driver module and the second driver module according to the context information.
[0062] Data transmission operation refers to the real-time data exchange and communication process between the microcontroller (MCU) and the controller area network, including operations such as sending and receiving data frames; context information refers to the operating status, configuration settings and other related environmental information of the current driver module, which usually needs to be recorded before reinitialization for subsequent recovery operations; the first reset register refers to the register in the controller area network used to control the reset of the first driver module. By operating this register, the first driver module can be restored to its initial state; setting parameters refer to the configuration options of the second driver module, such as communication rate, protocol settings, etc., which need to be reconfigured after reinitialization to ensure compatibility with the controller area network; the second reset register is a register used to control the reset of the second driver module. By operating this register, the second driver module can be restored to its initial settings; state recovery refers to restoring the states of the first driver module and the second driver module to the working state before the fault occurs according to the previously recorded context information after the reinitialization is completed, so as to ensure that the system can be restored to normal operation. First, the data transmission operation between the microcontroller and the controller area network is stopped, and the working status and configuration information of the current driver module are recorded in detail, which is called context information; then, the first driver module is initialized through the first reset register of the controller area network to ensure that it is restored to the initial state; then, the setting parameters of the second driver module, such as the communication rate and protocol settings, are reconfigured, and the second driver module is initialized through the second reset register; finally, according to the recorded context information, the state recovery operation is performed on the first driver module and the second driver module to ensure that they can be restored to the working state before the fault occurs, thereby ensuring that the controller area network can smoothly resume normal operation.
[0063] Step S20, based on the detection result of the bus offline fault of the controller local area network, complete the second fault recovery through the fast recovery mode and the slow recovery mode, the fast recovery mode corresponds to the first preset time length, the slow recovery mode corresponds to the second preset time length, and the first preset time length is less than the second preset time length.
[0064] It should be noted that bus offline fault (CAN BUS OFF) refers to a state in controller area network communication, indicating that the CAN node stops data transmission due to communication errors or other reasons and enters a state where it cannot work normally. The detection result refers to the periodic or event-triggered monitoring of the CAN bus state to determine whether a CAN BUS OFF fault has occurred, that is, whether the CAN node has entered an offline state. The fast recovery mode is a fault handling strategy. When a CAN BUS OFF fault is detected, the system attempts to restore the communication capability of the CAN node within a shorter preset time (first preset duration), which usually includes fault recovery steps, such as trying to resend CAN messages. The slow recovery mode is another fault handling strategy used to handle situations where the problem cannot be solved in the fast recovery mode. In the slow recovery mode, the system will wait for a longer preset time (second preset duration) and then try to restore the communication capability of the CAN node again, which usually includes more in-depth fault diagnosis and more complex recovery steps. The second fault recovery refers to the recovery operation for the CAN BUS OFF fault, including the fast recovery mode and the slow recovery mode. These operations are designed to ensure that the CAN node can quickly recover to a normal working state when facing a communication failure through different time intervals and strategies.
[0065] It is understandable that the controller area network (CAN) will first be detected in a periodic or event-triggered manner to see if a bus offline fault (CAN BUS OFF) occurs. Once a fault is detected, the system will initiate a second fault recovery process, including a fast recovery mode and a slow recovery mode. The fast recovery mode corresponds to a shorter first preset duration, during which the system attempts simple recovery measures, such as resending CAN messages. If the fast recovery mode fails to solve the problem, the system will switch to a slow recovery mode, which corresponds to a longer second preset duration. In the slow recovery mode, the system will perform more in-depth fault diagnosis and complex recovery steps to ensure that the CAN node can successfully restore its normal working state in the face of a communication failure.
[0066] The present embodiment provides a controller local area network fault recovery method, which reinitializes a drive module based on the error indication pin status of the controller local area network to complete a first fault recovery; based on the detection result of a bus offline fault of the controller local area network, completes a second fault recovery through a fast recovery mode and a slow recovery mode, the fast recovery mode corresponds to a first preset time length, and the slow recovery mode corresponds to a second preset time length, and the first preset time length is less than the second preset time length. This embodiment first monitors and records the state of the error indication pin of the CAN, stops the data transmission operation with the CAN, and records the relevant context information in detail; then, initializes the first driver module through the first reset register of the controller local area network, and reconfigures its own second driver module and initializes it through the second reset register; restores the state of the first driver module and the second driver module according to the recorded context information to ensure that the system recovers quickly and runs stably; the second fault recovery is based on the detection result of the CAN bus offline fault, and adopts a fast recovery mode and a slow recovery mode, wherein the fast recovery mode corresponds to a shorter first preset time, and the slow recovery mode corresponds to a longer second preset time. The fast recovery mode aims to try to send CAN messages in the shortest time to restore communication, while the slow recovery mode waits for a longer time before trying in complex fault conditions to ensure the stability and reliability of the system under extensive fault conditions. These measures effectively reduce the unavailable time of the system, improve the system's rapid response capability and automatic recovery capability to faults, can automatically restore CAN network faults caused by software anomalies of the CAN node itself, and can automatically restore CAN network communication when external faults disappear, ensuring the safety and reliability of the overall system.
[0067] Based on the first embodiment of the present application, in the second embodiment of the present application, the same or similar contents as those in the above-mentioned embodiment 1 can refer to the above introduction, and will not be repeated later. Figure 2 , Figure 2 This is a flow chart of the second embodiment of the controller area network failure recovery method of the present application. Step S20 of the controller area network failure recovery method includes steps S21 to S24:
[0068] Step S21, performing interrupt detection on a bus offline fault of the controller area network through an interrupt mask register;
[0069] It should be noted that the interrupt mask register is used to control and configure the interrupt function, especially to mask or enable specific interrupt signals. By configuring the interrupt mask register, the interrupt detection of CAN bus offline fault (CAN BUS OFF) can be selectively turned on or off. Interrupt detection refers to the MCU responding to and handling the abnormal situation of CAN bus offline by detecting specific interrupt signals or status register bits when a CAN bus offline fault occurs.
[0070] It is understandable that when interrupt detection of bus offline faults of the controller area network (CAN) is performed through interrupt mask registers, the microcontroller configures these registers to enable the interrupt detection function of the CAN bus offline fault. These registers allow the microcontroller to selectively monitor the state changes of the CAN bus, and when the bus is detected to enter the offline state (BUS OFF), it can immediately perceive this abnormal situation. By reading specific status register bits, the microcontroller can accurately determine the offline state of the CAN bus and can take necessary measures to deal with this problem, such as recording fault information or starting a preset fault recovery program to ensure the stability and reliability of the CAN communication system.
[0071] Step S22, when the bus offline fault is detected, reading the status register of the controller area network;
[0072] It should be noted that the status register refers to the register used to store and reflect the current status of the controller area network (CAN). These registers usually contain various bits to indicate various states of the CAN bus, such as error state, offline state (BUS OFF), sending completion state, etc.
[0073] It is understandable that when the microcontroller detects a Controller Area Network (CAN) bus offline fault, it will immediately execute the operation of reading the status registers of the Controller Area Network, which contain key information about the current status of the CAN bus, such as error counters, bus offline status (BUS OFF), sending and receiving status, etc. By reading these status registers, the microcontroller can obtain real-time CAN bus status data, providing the necessary information basis for subsequent fault diagnosis and recovery measures.
[0074] Step S23, judging whether the bus offline fault exists according to the status register, and obtaining a judgment result;
[0075] It should be noted that the judgment result refers to judging whether the current controller area network (CAN) bus is in an offline fault state (BUS OFF) based on the information in the read status register. This judgment result can be a Boolean value, which can be present or not, that is, judging whether the bus is offline or whether further recovery operations are required.
[0076] It is understandable that the step of determining whether the bus offline fault exists according to the status register includes reading the status register information of the controller area network (CAN), which generally contains detailed information about the current state of the CAN controller, such as error state, bus state, etc. By analyzing the content of the status register, the system can determine whether the current CAN bus is in an offline fault state (BUS OFF), and this determination result will directly affect the execution of subsequent fault recovery strategies, ensuring that corresponding measures can be taken in time to restore normal communication when a fault occurs.
[0077] As an example, judging whether the bus offline fault exists according to the status register, the steps of obtaining the judgment result include: reading the status register to obtain status information; judging whether the bus offline fault exists by checking the offline flag, error counter and error warning flag in the status information to obtain the judgment result.
[0078] Status information refers to the information read from the status register that contains the current status of the CAN controller; the offline flag is usually a specific bit in the status register, used to indicate whether the CAN bus is in the offline state (BUSOFF); the error counter is a counter used to record the number of errors that occurred in the communication, which can affect the normal operation of the bus; the error warning flag is a bit in another status register, used to indicate whether an error warning condition has occurred, such as an erroneous transmission or reception situation.
[0079] First, read the status register to obtain the current status information of the CAN controller; then, check the offline flag in the status information, which indicates whether the CAN bus is in the offline state (BUS OFF); then, check the value of the error counter, which records the number of errors that occurred during the communication process. If the error counter exceeds the set threshold, it may indicate a serious communication problem; finally, check the error warning flag, which is used to indicate whether an error warning condition has occurred, such as an erroneous transmission or reception; a comprehensive analysis of the status of the offline flag, error counter, and error warning flag can accurately determine whether there is a CAN bus offline fault, and take appropriate fault handling measures accordingly.
[0080] Step S24, when the judgment result is yes, the state of the controller area network is set to a stopped state through the first driver module of the controller area network, and the second fault recovery is completed through a fast recovery mode and a slow recovery mode.
[0081] It should be noted that the stop state refers to completely stopping the data transmission and communication operation of the controller area network (CAN) to prevent the continued sending or receiving of data in the fault state and avoid further communication errors or damage.
[0082] It is understandable that when a bus offline fault is detected in the controller area network (CAN), specific status information is first obtained by reading the status register, including an offline flag, an error counter, and an error warning flag. After determining the result of a bus offline fault based on this information, the first driver module of the controller area network is used to set the state of the LAN to a stopped state, that is, to stop all data transmission and communication operations to prevent further communication errors. Next, the second fault recovery is completed through a fast recovery mode and a slow recovery mode. The fast recovery mode corresponds to a shorter preset time, which is intended to quickly try to reconnect to the LAN; while the slow recovery mode corresponds to a longer preset time, which is used for more in-depth fault diagnosis and repair operations to ensure that the system is stably restored to a normal communication state.
[0083] As an example, the steps of completing the second fault recovery through the fast recovery mode and the slow recovery mode include: after waiting for a first preset period of time, sending a test message to the controller local area network to obtain a first sending result; when the first sending result is a failure, after waiting for the first preset period of time, repeating the step of sending the test message; when the number of sending failures is greater than or equal to a second preset number of times, completing the second fault recovery through the slow recovery mode.
[0084] The first preset duration is the set time interval that the system waits for, which is used to prepare and stabilize the system status before starting to send test messages to ensure the reliability and stability of communication. The test message is a specific data packet sent by the system to evaluate the communication line and device status of the controller LAN. The first sending result refers to the feedback result obtained after the MCU sends the test message in the fast recovery mode, which is used to determine whether the communication is successful. The second preset number is the maximum allowed sending failure threshold set by the system. If the first sending result is a failure, and the number of sending failures does not reach the second preset number, the MCU will wait for the first preset time and try to send the test message again to verify whether the communication is restored. When the number of sending failures reaches or exceeds the second preset number, the MCU will start the slow recovery mode, and will wait for the second preset time to continue sending test messages to further try to restore the normal operation of the communication line.
[0085] When performing the second fault recovery, first wait for the preset first time, which is used for system preparation and stabilization; then, the MCU will send a specific test message through the controller area network to detect the communication status; after the first transmission, the MCU will obtain and analyze the results of the transmission. For example, if the first transmission fails, the MCU will wait for the same preset time again, and then repeat the same test message; this process will continue until the number of transmission failures reaches or exceeds the second preset number. Once this threshold is reached, the slow recovery mode will be started. In the slow recovery mode, the MCU takes more in-depth and time-consuming recovery measures to ensure that the controller area network can resume normal communication as soon as possible. For example, a more complex reset procedure may be executed or communication parameters may be adjusted to eliminate the cause of the fault and ensure system stability. This two-stage recovery strategy can effectively deal with communication failures of varying degrees and ensure the reliability and stability of the system.
[0086] As an example, the steps of completing the second fault recovery through the slow recovery mode include: after waiting for a second preset time, sending the test message to the controller local area network to obtain a second sending result; when the second sending result is a failure, after waiting for the second preset time, repeating the step of sending the test message; when the number of sending failures is greater than or equal to a third preset number of times, reinitializing the first driver module of the controller local area network and its own second driver module to complete the second fault recovery.
[0087] The second preset duration refers to the time interval that the MCU waits for, which is used to prepare and stabilize the system status before starting to send test messages to ensure the reliability and stability of communication. The second sending result refers to the feedback result obtained after the MCU sends the test message in slow recovery mode, which is used to determine whether the communication has returned to normal. The third preset number of times is the maximum allowable sending failure threshold set in slow recovery mode. After reaching this number, the MCU will initiate the final fault recovery measure, reinitialize the controller LAN and related driver modules, and ensure the normal operation of the system.
[0088] This embodiment performs interrupt detection on the bus offline fault of the controller area network through an interrupt mask register; when the bus offline fault is detected, reads the status register of the controller area network; determines whether the bus offline fault exists according to the status register to obtain a determination result; when the determination result is that the bus offline fault exists, sets the state of the controller area network to a stopped state through a first driver module of the controller area network, and completes a second fault recovery through a fast recovery mode and a slow recovery mode. This embodiment detects interrupts to the controller area network through an interrupt mask register, effectively realizes timely monitoring of bus offline faults, and can quickly respond to fault conditions. Once a bus offline fault is detected, the MCU immediately reads the status register to obtain detailed operating status information, so that it can accurately determine whether there is an offline fault and quickly take countermeasures; after confirming that the fault exists, the MCU sets the controller area network state to a stopped state through the first driver module to prevent the fault from spreading and further affecting the communication error, thereby ensuring the stability and reliability of the system; then, the MCU attempts to send a test message within a shorter first preset time through a fast recovery mode. This process is intended to quickly restore the communication function, effectively reducing system downtime and production losses on the production line; if the fast recovery mode fails to solve the problem, the MCU will wait for a longer second preset time and then adopt a slow recovery mode. This hierarchical recovery strategy not only increases the flexibility of recovery, but also increases the probability of successful recovery, ensuring that normal communication can still be effectively restored under various complex fault conditions; finally, if multiple consecutive attempts are still unsuccessful, the MCU will reinitialize the driver module to completely restore the second fault and ensure that the system is restored to a normal working state. This automated fault recovery process greatly improves the maintainability and reliability of the system, reduces the need for human intervention, and reduces production interruptions and losses caused by faults.
[0089] For example, to help understand the implementation process of the controller local area network failure recovery method obtained by combining this embodiment with the above-mentioned embodiment 1, please refer to Figure 3 , Figure 3 A brief flowchart of a controller area network failure recovery method is provided, specifically:
[0090] First, the MCU starts the periodic detection task and detects network faults by checking the CAN ERR pin status. When the ERR pin status is low and the duration exceeds the preset low-level time threshold, such as 40ms, and the cumulative detection of the first preset number of times (for example, 3 times) is established, the MCU will reinitialize the CAN transceiver and related drivers to complete the first fault recovery. In parallel, the MCU performs periodic interrupt detection and turns on the BUS OFF interrupt detection. When the BUS OFF state is detected, the status register is read for confirmation. If it is confirmed to be the BUS OFF state, the CAN controller will enter the stop state and record the relevant fault code. Subsequently, the fast recovery mode is executed to try to send CAN messages; if the second preset number of attempts (for example, 3 times) fails, the slow recovery mode is entered, and the message is tried again after the waiting time is extended. If the slow recovery mode is still unsuccessful, the MCU will reinitialize the CAN transceiver and related drivers to complete the second fault recovery. By combining periodic detection and interruption detection, the efficiency and reliability of CAN network fault recovery are improved. It can automatically recover faults caused by software anomalies of the CAN node itself, and automatically restore CAN network communication when external faults disappear. It can not only handle CAN node abnormalities itself, but also deal with faults caused by external reasons (such as cable connection problems, power supply voltage abnormalities, etc.).
[0091] It should be noted that the above examples are only used to understand the present application and do not constitute a limitation on the controller LAN fault recovery method of the present application. More simple transformations based on this technical concept are all within the protection scope of the present application.
[0092] This application also provides a controller local area network failure recovery device, please refer to Figure 4 , the controller area network fault recovery device comprises:
[0093] A first fault recovery module 10, configured to reinitialize the driver module based on the state of the error indication pin of the controller area network to complete the first fault recovery;
[0094] The second fault recovery module 20 is used to complete the second fault recovery through a fast recovery mode and a slow recovery mode based on the detection result of the bus offline fault of the controller local area network, the fast recovery mode corresponds to a first preset time length, and the slow recovery mode corresponds to a second preset time length, and the first preset time length is less than the second preset time length.
[0095] The controller area network fault recovery device provided by the present application adopts the controller area network fault recovery method in the above embodiment, and can solve the technical problem of how to recover the network fault of the controller area network. Compared with the prior art, the beneficial effects of the controller area network fault recovery device provided by the present application are the same as the beneficial effects of the controller area network fault recovery method provided by the above embodiment, and other technical features in the controller area network fault recovery device are the same as the features disclosed in the above embodiment method, which will not be repeated here.
[0096] The present application provides a controller area network fault recovery device, which includes: at least one processor; and a memory that is communicatively connected to the at least one processor; wherein the memory stores instructions that can be executed by the at least one processor, and the instructions are executed by the at least one processor so that the at least one processor can execute the controller area network fault recovery method in the above-mentioned embodiment one.
[0097] Reference below Figure 5 , which shows a schematic diagram of the structure of a controller area network fault recovery device suitable for implementing the embodiment of the present application. The controller area network fault recovery device in the embodiment of the present application may include but is not limited to mobile terminals such as mobile phones, laptop computers, digital broadcast receivers, PDAs (Personal Digital Assistants), PADs (Portable Application Descriptions), PMPs (Portable Media Players), vehicle-mounted terminals (such as vehicle-mounted navigation terminals), etc., and fixed terminals such as digital TVs, desktop computers, etc. Figure 5 The controller area network failure recovery device shown is only an example and should not bring any limitation to the functions and scope of use of the embodiments of the present application.
[0098] like Figure 5As shown, the controller area network failure recovery device may include a processing device 1001 (such as a central processing unit, a graphics processor, etc.), which can perform various appropriate actions and processes according to a program stored in a read-only memory (ROM: Read Only Memory) 1002 or a program loaded from a storage device 1003 to a random access memory (RAM: Random Access Memory) 1004. Various programs and data required for the operation of the controller area network failure recovery device are also stored in the RAM 1004. The processing device 1001, the ROM 1002, and the RAM 1004 are connected to each other through a bus 1005. An input / output (I / O) interface 1006 is also connected to the bus. Typically, the following systems may be connected to the I / O interface 1006: input devices 1007 including, for example, a touch screen, a touchpad, a keyboard, a mouse, an image sensor, a microphone, an accelerometer, a gyroscope, etc.; output devices 1008 including, for example, a liquid crystal display (LCD), a speaker, a vibrator, etc.; storage devices 1003 including, for example, a magnetic tape, a hard disk, etc.; and communication devices 1009. The communication device 1009 may allow the controller area network failure recovery device to communicate wirelessly or wired with other devices to exchange data. Although the figure shows a controller area network failure recovery device with various systems, it should be understood that it is not required to implement or have all the systems shown. More or fewer systems may be implemented or have instead.
[0099] In particular, according to the embodiments disclosed in the present application, the process described above with reference to the flowchart can be implemented as a computer software program. For example, the embodiments disclosed in the present application include a computer program product, which includes a computer program carried on a computer-readable medium, and the computer program includes a program code for executing the method shown in the flowchart. In such an embodiment, the computer program can be downloaded and installed from a network through a communication device, or installed from a storage device 1003, or installed from a ROM 1002. When the computer program is executed by the processing device 1001, the above-mentioned functions defined in the method of the embodiment disclosed in the present application are executed.
[0100] The controller area network fault recovery device provided by the present application adopts the controller area network fault recovery method in the above embodiment, which can solve the technical problem of how to recover the network fault of the controller area network. Compared with the prior art, the beneficial effects of the controller area network fault recovery device provided by the present application are the same as the beneficial effects of the controller area network fault recovery method provided by the above embodiment, and other technical features in the controller area network fault recovery device are the same as the features disclosed in the method of the previous embodiment, which will not be repeated here.
[0101] It should be understood that the various parts disclosed in this application can be implemented by hardware, software, firmware or a combination thereof. In the description of the above embodiments, specific features, structures, materials or characteristics can be combined in any one or more embodiments or examples in a suitable manner.
[0102] The above is only a specific implementation of the present application, but the protection scope of the present application is not limited thereto. Any person skilled in the art who is familiar with the present technical field can easily think of changes or substitutions within the technical scope disclosed in the present application, which should be included in the protection scope of the present application. Therefore, the protection scope of the present application should be based on the protection scope of the claims.
[0103] The present application provides a computer-readable storage medium having computer-readable program instructions (ie, computer programs) stored thereon, and the computer-readable program instructions are used to execute the controller area network failure recovery method in the above-mentioned embodiment.
[0104] The computer-readable storage medium provided in the present application may be, for example, a USB flash drive, but is not limited to electrical, magnetic, optical, electromagnetic, infrared, or semiconductor systems, systems or devices, or any combination of the above. More specific examples of computer-readable storage media may include, but are not limited to: an electrical connection with one or more wires, a portable computer 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 of the above. In this embodiment, the computer-readable storage medium may be any tangible medium containing or storing a program that can be used by or in combination with an instruction execution system, system or device. The program code contained on the computer-readable storage medium may be transmitted using any appropriate medium, including but not limited to: wires, optical cables, RF (Radio Frequency), etc., or any suitable combination of the above.
[0105] The computer-readable storage medium may be included in the controller area network failure recovery device; or may exist independently without being assembled into the controller area network failure recovery device.
[0106] The above-mentioned computer-readable storage medium carries one or more programs. When the above-mentioned one or more programs are executed by the controller local area network fault recovery device, the controller local area network fault recovery device: based on the error indication pin status of the controller local area network, reinitializes the drive module to complete the first fault recovery; based on the detection result of the bus offline fault of the controller local area network, completes the second fault recovery through a fast recovery mode and a slow recovery mode, the fast recovery mode corresponds to a first preset time length, and the slow recovery mode corresponds to a second preset time length, and the first preset time length is less than the second preset time length.
[0107] Computer program code for performing the operations of the present application may be written in one or more programming languages or a combination thereof, including object-oriented programming languages such as Java, Smalltalk, C++, and conventional procedural programming languages such as "C" or similar programming languages. The program code may be executed entirely on the user's computer, partially on the user's computer, as a separate software package, partially on the user's computer and partially on a remote computer, or entirely on a remote computer or server. In the case of a remote computer, the remote computer may be connected to the user's computer through any type of network, including a local area network (LAN) or a wide area network (WAN), or may be connected to an external computer (e.g., via the Internet using an Internet service provider).
[0108] The flow chart and block diagram in the accompanying drawings illustrate the possible architecture, function and operation of the system, method and computer program product according to various embodiments of the present application. In this regard, each square box in the flow chart or block diagram can represent a module, a program segment or a part of a code, and the module, the program segment or a part of the code contains one or more executable instructions for realizing the specified logical function. It should also be noted that in some alternative implementations, the functions marked in the square box can also occur in a sequence different from that marked in the accompanying drawings. For example, two square boxes represented in succession can actually be executed substantially in parallel, and they can sometimes be executed in the opposite order, depending on the functions involved. It should also be noted that each square box in the block diagram and / or flow chart, and the combination of the square boxes in the block diagram and / or flow chart can be implemented with a dedicated hardware-based system that performs a specified function or operation, or can be implemented with a combination of dedicated hardware and computer instructions.
[0109] The modules involved in the embodiments described in this application may be implemented by software or hardware, wherein the name of the module does not constitute a limitation on the unit itself in some cases.
[0110] The readable storage medium provided by the present application is a computer-readable storage medium, which stores computer-readable program instructions (i.e., computer programs) for executing the above-mentioned controller local area network failure recovery method, and can solve the technical problem of how to recover the network failure of the controller local area network. Compared with the prior art, the beneficial effects of the computer-readable storage medium provided by the present application are the same as the beneficial effects of the controller local area network failure recovery method provided by the above-mentioned embodiment, and will not be repeated here.
[0111] The present application also provides a computer program product, including a computer program, wherein when the computer program is executed by a processor, the steps of the controller area network failure recovery method as described above are implemented.
[0112] The computer program product provided by the present application can solve the technical problem of how to recover a network failure of a controller area network. Compared with the prior art, the beneficial effects of the computer program product provided by the present application are the same as the beneficial effects of the controller area network failure recovery method provided by the above embodiment, which will not be repeated here.
[0113] The above descriptions are only some embodiments of the present application, and are not intended to limit the patent scope of the present application. All equivalent structural changes made using the contents of the present application specification and drawings under the technical concept of the present application, or direct / indirect applications in other related technical fields are included in the patent protection scope of the present application.
Claims
1. A controller area network failure recovery method, characterized in that: The method comprises: Based on the state of the error indication pin of the controller area network, the driver module is reinitialized to complete the first fault recovery; Based on the detection result of the bus offline fault of the controller local area network, the second fault recovery is completed through a fast recovery mode and a slow recovery mode, the fast recovery mode corresponds to a first preset time length, and the slow recovery mode corresponds to a second preset time length, and the first preset time length is less than the second preset time length.
2. The method according to claim 1, characterized in that The step of completing the second fault recovery by using a fast recovery mode and a slow recovery mode based on the detection result of the bus offline fault of the controller area network includes: Performing interrupt detection on a bus offline fault of the controller area network through an interrupt mask register; When the bus offline fault is detected, reading the status register of the controller area network; Determine whether the bus offline fault exists according to the status register, and obtain a determination result; When the judgment result is yes, the state of the controller area network is set to a stopped state through the first driver module of the controller area network, and the second fault recovery is completed through a fast recovery mode and a slow recovery mode.
3. The method according to claim 2, characterized in that The step of completing the second fault recovery by using the fast recovery mode and the slow recovery mode includes: After waiting for a first preset time, sending a test message to the controller area network to obtain a first sending result; When the first sending result is failure, after waiting for the first preset time, repeating the step of sending the test message; When the number of sending failures is greater than or equal to a second preset number, the second fault recovery is completed through the slow recovery mode.
4. The method according to claim 3, characterized in that The step of completing the second fault recovery by the slow recovery mode comprises: After waiting for a second preset time, sending the test message to the controller area network to obtain a second sending result; When the second sending result is failure, after waiting for the second preset time, repeating the step of sending the test message; When the number of transmission failures is greater than or equal to a third preset number of times, the first driver module of the controller area network and the second driver module of the controller area network are reinitialized to complete the second fault recovery.
5. The method according to claim 1, characterized in that The step of reinitializing the driver module based on the error indication pin state of the controller area network to complete the first fault recovery includes: At preset intervals, detecting the state of an error indication pin of a controller area network to obtain a low level time of the error indication pin; When the low level time is greater than or equal to a preset low level time threshold and the first preset number of consecutive detections are all established, the first driver module of the controller area network and the second driver module of the controller area network are reinitialized to complete the first fault recovery.
6. The method according to claim 5, characterized in that The step of reinitializing the first driver module of the controller area network and the second driver module of the controller area network comprises: Stop the data transmission operation with the controller area network and record the context information; Initialize a first driver module of the controller area network through a first reset register of the controller area network; reconfigure the setting parameters of its own second driver module, and initialize the second driver module through a second reset register; The states of the first driving module and the second driving module are restored according to the context information.
7. The method according to claim 2, characterized in that The step of determining whether the bus offline fault exists according to the status register and obtaining the determination result comprises: Read the status register to obtain status information; By checking the offline flag, the error counter and the error warning flag in the status information, it is determined whether the bus offline fault exists, and a determination result is obtained.
8. A controller local area network fault recovery device, characterized in that: The device comprises: A first fault recovery module, used for reinitializing the driver module based on the state of the error indication pin of the controller area network to complete the first fault recovery; A second fault recovery module is used to complete a second fault recovery through a fast recovery mode and a slow recovery mode based on the detection result of the bus offline fault of the controller local area network, the fast recovery mode corresponds to a first preset time length, and the slow recovery mode corresponds to a second preset time length, and the first preset time length is less than the second preset time length.
9. A controller area network failure recovery device, characterized in that: The device comprises: a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the computer program is configured to implement the steps of the controller area network failure recovery method according to any one of claims 1 to 7.
10. A storage medium, characterized in that: The storage medium is a computer-readable storage medium, and a computer program is stored on the storage medium. When the computer program is executed by a processor, the steps of the controller local area network failure recovery method according to any one of claims 1 to 7 are implemented.
Citation Information
Cited By
Method for monitoring controller area network interface, electronic equipment and robot
CN122437790A
