[go: up one dir, main page]

CN101582799B - Bus switch method based on CAN redundance - Google Patents

Bus switch method based on CAN redundance Download PDF

Info

Publication number
CN101582799B
CN101582799B CN 200910099831 CN200910099831A CN101582799B CN 101582799 B CN101582799 B CN 101582799B CN 200910099831 CN200910099831 CN 200910099831 CN 200910099831 A CN200910099831 A CN 200910099831A CN 101582799 B CN101582799 B CN 101582799B
Authority
CN
China
Prior art keywords
bus
sending
data
node
receiving
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Expired - Fee Related
Application number
CN 200910099831
Other languages
Chinese (zh)
Other versions
CN101582799A (en
Inventor
吴朝晖
吕攀
周丽
魏城炯
张吕红
赵民德
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
INSIGMA GROUP CO Ltd
Zhejiang University ZJU
Original Assignee
INSIGMA GROUP CO Ltd
Zhejiang University ZJU
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by INSIGMA GROUP CO Ltd, Zhejiang University ZJU filed Critical INSIGMA GROUP CO Ltd
Priority to CN 200910099831 priority Critical patent/CN101582799B/en
Publication of CN101582799A publication Critical patent/CN101582799A/en
Application granted granted Critical
Publication of CN101582799B publication Critical patent/CN101582799B/en
Expired - Fee Related legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Landscapes

  • Small-Scale Networks (AREA)

Abstract

本发明公开了一种基于CAN冗余的总线切换方法,包括以下步骤:1)、判断是发送节点还是接收节点;为发送节点,进入步骤2);为接收节点,进入步骤5);2)、判断发送节点是否发送超时;判断为“是”,进入步骤3),判断为“否”,则进入步骤4);3)、切换总线重新发送;4)、发送节点监视总线直至超时或者接收到接收节点的响应帧;5)、判断接收节点是否接收超时;判断为“是”,进入步骤6),判断为“否”,则进入步骤7);6)、通过广播切换总线,告知其他节点切换总线重新发送数据;7)、接收节点发送响应帧,作为对发送节点的响应,表示数据发送并接收成功。该方法能保证数据接收的可靠正确性和实时性。

Figure 200910099831

The invention discloses a bus switching method based on CAN redundancy, which comprises the following steps: 1), judging whether it is a sending node or a receiving node; if it is a sending node, enter step 2); if it is a receiving node, enter step 5); 2) , judging whether the sending node sends overtime; judged as "yes", enter step 3), judged as "no", then enter step 4); 3), switch bus to resend; 4), send node monitor bus until timeout or receive To the response frame of the receiving node; 5), judge whether the receiving node has received a timeout; if it is judged as "yes", enter step 6), if it is judged as "no", then enter step 7); 6), switch the bus by broadcasting, inform other The node switches the bus to resend the data; 7), the receiving node sends a response frame as a response to the sending node, indicating that the data is sent and received successfully. The method can guarantee reliable correctness and real-time performance of data reception.

Figure 200910099831

Description

基于CAN冗余的总线切换方法Bus Switching Method Based on CAN Redundancy

技术领域 technical field

本发明属于CAN网络通讯技术领域,特别涉及一种基于CAN冗余的总线切换方法。The invention belongs to the technical field of CAN network communication, in particular to a bus switching method based on CAN redundancy.

背景技术 Background technique

解决CAN网络可靠性通讯的一个有效的办法就是对总线进行不同程度的冗余。虽然CAN冗余是解决CAN网络可靠性的普遍方法,但是没有人研究基于CAN冗余的总线切换方法。诸多设计者是在发送失败或者接收失败导致超时的情况下,进行切换总线。无疑在等待超时的这段时间内,接收数据出错的节点将会错过很多有效数据帧,降低了总线利用率。然而,一种好的基于CAN冗余的总线切换方法应该是可以使接收节点尽量少的错过数据帧,从而提高了总线利用率,也保证了CAN网络的数据正确稳定传送,增强了CAN网络的实时性。An effective way to solve CAN network reliability communication is to carry out different degrees of redundancy on the bus. Although CAN redundancy is a common method to solve the reliability of CAN network, no one has studied the bus switching method based on CAN redundancy. Many designers switch the bus when sending or receiving fails to cause a timeout. Undoubtedly, during the period of waiting for the timeout, the node receiving the wrong data will miss a lot of valid data frames, which reduces the bus utilization. However, a good bus switching method based on CAN redundancy should be able to make the receiving node miss data frames as little as possible, thereby improving the bus utilization rate, ensuring the correct and stable transmission of data in the CAN network, and enhancing the reliability of the CAN network. real-time.

发明内容 Contents of the invention

本发明要解决的技术问题是提供一种能保证数据接收的可靠正确性和实时性的基于CAN冗余的总线切换方法。The technical problem to be solved by the present invention is to provide a bus switching method based on CAN redundancy that can ensure reliable correctness and real-time performance of data reception.

为了解决上述技术问题,本发明提供一种基于CAN冗余的总线切换方法,包括以下步骤:In order to solve the problems of the technologies described above, the present invention provides a bus switching method based on CAN redundancy, comprising the following steps:

1)、判断是发送节点还是接收节点;当为发送节点时,进入步骤2);当为接收节点时,进入步骤5);1), determine whether it is a sending node or a receiving node; when it is a sending node, enter step 2); when it is a receiving node, enter step 5);

2)、判断发送节点是否发送超时;当判断为“是”时,进入步骤3),当判断为“否”时,则进入步骤4);2), judge whether the sending node sends overtime; when it is judged as "yes", enter step 3), when judged as "no", then enter step 4);

3)、切换总线重新发送;3), switch the bus and resend;

4)、发送节点监视总线直至超时或者接收到接收节点的响应帧,表示成功发送数据;4), the sending node monitors the bus until it times out or receives a response frame from the receiving node, indicating that the data is successfully sent;

5)、判断接收节点是否接收超时;当判断为“是”时,进入步骤6),当判断为“否”时,则进入步骤7),5), determine whether the receiving node receives timeout; when it is judged as "yes", enter step 6), when it is judged as "no", then enter step 7),

6)、通过广播切换总线,告知其他节点切换总线重新发送数据;6) Switch the bus by broadcasting to inform other nodes to switch the bus and resend the data;

7)、接收节点发送响应帧,作为对发送节点的响应,表示数据发送并接收成功。7) The receiving node sends a response frame as a response to the sending node, indicating that the data is sent and received successfully.

作为本发明的基于CAN冗余的总线切换方法的改进:步骤2)中判断发送节点是否发送超时的标准为:发送节点的发送时间是否超过用户设定的最长的发送时间,超过该值认为该次数据发送失败。As the improvement of the bus switching method based on CAN redundancy of the present invention: in step 2), the criterion for judging whether the sending node sends overtime is: whether the sending time of the sending node exceeds the longest sending time set by the user, exceeding this value is considered The data sending failed this time.

作为本发明的基于CAN冗余的总线切换方法的进一步改进:步骤5)中判断接收节点是否发送超时的标准为:接收节点的接收错误是否超出设定的阈值,该阈值是用户定义的能够忍受的最大接收错误次数。As a further improvement of the bus switching method based on CAN redundancy of the present invention: in step 5), the criterion for judging whether the receiving node sends overtime is: whether the receiving error of the receiving node exceeds a set threshold, which is user-defined and can be tolerated The maximum number of receiving errors.

作为本发明的基于CAN冗余的总线切换方法的进一步改进:同一时刻只能有一条总线发送数据;使用软件缓冲区作为用户发送数据的缓冲池,使用开发板的三个硬件缓冲区加速数据帧的发送;设置阈值以及超时机制用于通信出现故障时重启控制器或者切换总线重新发送或继续接收数据帧;用节点指示灯提示用户总线故障,需要及时恢复总线。As a further improvement of the bus switching method based on CAN redundancy in the present invention: only one bus can send data at the same time; use the software buffer as the buffer pool for the user to send data, and use the three hardware buffers of the development board to accelerate data frames The transmission; set the threshold and timeout mechanism to restart the controller or switch the bus to resend or continue to receive data frames when the communication fails; use the node indicator to remind the user that the bus is faulty, and the bus needs to be restored in time.

作为本发明的基于CAN冗余的总线切换方法的进一步改进:步骤3)具体为依次进行以下步骤:As a further improvement of the bus switching method based on CAN redundancy of the present invention: step 3) is specifically to carry out the following steps in sequence:

A)、重启控制器重新发送;如发送成功,则进入步骤B);如仍旧发送不成功,以至发送超时,则进入步骤C);A), restart the controller and resend; if the sending is successful, go to step B); if the sending is still unsuccessful, so that the sending times out, go to step C);

B)、监听等待网络上的响应帧,当收到接收节点的响应帧时表示该次数据传送成功;B), monitor and wait for the response frame on the network, when receiving the response frame of the receiving node, it means that the data transmission is successful;

C)、判断其余总线是否可用,如其余总线有任意一条(至少一条)总线可用,则采用该总线重新发送;若其余总线均不能使用,则提示用户,等待用户恢复。C), judge whether all the other buses are available, if any one (at least one) of the other buses is available, then use this bus to resend; if all the other buses are unusable, then prompt the user and wait for the user to recover.

作为本发明的基于CAN冗余的总线切换方法的进一步改进:步骤6)具体为依次进行以下步骤:As a further improvement of the bus switching method based on CAN redundancy of the present invention: step 6) is specifically to carry out the following steps in sequence:

判断其余总线是否可用,如其余总线有任意一条(至少一条)总线可用,则广播切换总线、重启原控制器,(表示该节点在该总线上是接收不到有效数据帧的);若另一个总线不可用,则重启原控制器。Determine whether the rest of the buses are available. If any (at least one) of the rest of the buses is available, then broadcast to switch the bus and restart the original controller (indicating that the node cannot receive valid data frames on the bus); if another If the bus is not available, restart the original controller.

上述内容如图1所示:当切换总线时,也就是使用另一套控制器、收发器。在网络传送开始前,控制器已经初始化过,但是由于要初始化掉控制器的某些寄存器、或者某些软件计数错误,所以要重新初始化控制器,即是重启控制器。The above content is shown in Figure 1: when the bus is switched, another set of controllers and transceivers are used. Before the start of network transmission, the controller has been initialized, but because some registers of the controller have to be initialized, or some software counts errors, so the controller needs to be re-initialized, which means restarting the controller.

在本发明中的基于CAN冗余的总线切换方法中:在每个节点设计一个记录发送数据帧的软件缓冲区结构数组(Buffer),使得数据帧在总线切换时无需转移。判断软件缓冲区是否是满的条件是:数据缓冲区中的有效数据是否==NUM-1。NUM是软件缓冲区的最大容量。之所以减掉1,是要为特殊数据帧预留一个数据缓冲区;之所以为特殊帧预留一个数据缓冲区,是为了防止当软件缓冲区放满数据帧时,特殊帧无法及时发送。必须保证特殊数据帧能够及时的发送出去。当发送特殊帧时,将其插入到软件缓冲区的预留位置,可以保证其优先发送。特殊数据帧包括发送节点的总线切换帧Change_Send_Frame、接收节点的总线切换帧Change_REV_Frame。Change_Send_Frame是指发送节点超时时,发往各个节点的切换总线帧,通知各个节点原通道已经坏掉;而Change_REV_Frame是接收节点在接收错误超出阈值时广播的切换总线帧,并不意味着原总线出现故障,只是为了尽量减少接收节点丢失数据帧而采取的切换总线。In the bus switching method based on CAN redundancy in the present invention: a software buffer structure array (Buffer) for recording and sending data frames is designed at each node, so that the data frames do not need to be transferred when the bus is switched. The condition for judging whether the software buffer is full is: whether the valid data in the data buffer==NUM-1. NUM is the maximum size of the software buffer. The reason for subtracting 1 is to reserve a data buffer for the special data frame; the reason for reserving a data buffer for the special frame is to prevent the special frame from being unable to be sent in time when the software buffer is full of data frames. It must be ensured that special data frames can be sent out in time. When sending a special frame, insert it into the reserved position of the software buffer to ensure that it is sent first. The special data frame includes the bus switching frame Change_Send_Frame of the sending node and the bus switching frame Change_REV_Frame of the receiving node. Change_Send_Frame refers to the switching bus frame sent to each node when the sending node times out, notifying each node that the original channel has been broken; and Change_REV_Frame is the switching bus frame broadcast by the receiving node when the receiving error exceeds the threshold, which does not mean that the original bus appears Faults are just switching buses to minimize the loss of data frames at the receiving node.

在利用CAN冗余来提高CAN网络通讯的可靠性时,本发明的基于CAN冗余的总线切换方法有利于提高总线利用率、网络通讯可靠安全性以及网络实时性。本发明的基于CAN冗余的总线切换方法,用于保证发送节点能够成功发送数据,接收节点能够接收到数据,而且尽量少的丢失数据帧,从而保证了数据接收的可靠正确性、实时性、安全性。When CAN redundancy is used to improve the reliability of CAN network communication, the CAN redundancy-based bus switching method of the present invention is beneficial to improving bus utilization, network communication reliability and security, and network real-time performance. The bus switching method based on CAN redundancy of the present invention is used to ensure that the sending node can successfully send data, the receiving node can receive the data, and the data frame is lost as little as possible, thereby ensuring the reliability, correctness, real-time performance and accuracy of data reception. safety.

在本发明中,可以避免因总线硬件故障而平白一直等待到接收超时(在CAN网络中,超时周期设置肯定比错误数据超出阈值的时间长),在等待的这段时间里,可能错过其他节点在该故障总线上传送的数据。简单讲,就是接收节点没有设置超时时间,在接收错误超出阈值时就切换总线发送数据。注意:(1)接收错误计数值超过阈值则会切换总线,但是不表示该条总线坏掉,而是为了尽量减少丢失数据帧,使得该节点能够及时接到数据帧。(2)发送错误计数值超出阈值时,就会重启控制器,并不切换总线。毕竟切换总线的花销比重启控制器要大。当重启后仍不能发送成功,则会发生超时中断切换总线,重新发送。In the present invention, it is possible to avoid waiting until receiving overtime due to bus hardware failure (in a CAN network, the overtime period setting must be longer than the time when the error data exceeds the threshold), and during this period of waiting, other nodes may be missed Data transferred on the faulty bus. To put it simply, the receiving node does not set a timeout period, and switches the bus to send data when the receiving error exceeds the threshold. Note: (1) If the receiving error count exceeds the threshold, the bus will be switched, but it does not mean that the bus is broken, but to minimize the loss of data frames, so that the node can receive data frames in time. (2) When the sending error count exceeds the threshold, the controller will be restarted without switching the bus. After all, switching the bus is more expensive than restarting the controller. When the transmission is still not successful after restarting, a timeout interrupt will occur to switch the bus and resend.

以双CAN网络为例,本发明设置阈值以及超时机制用于通讯出现故障时重新启动CAN控制器或者切换总线,主要体现在:Taking the dual CAN network as an example, the present invention sets a threshold and a timeout mechanism for restarting the CAN controller or switching the bus when a communication failure occurs, which is mainly reflected in:

●当发送节点发送错误计数值超过某阈值时,则重启CAN控制器重新发送;如果重启控制器仍旧发送不成功,以至发送超时的时候,那么:若另一总线可用则切换总线重新发送;若另一总线不可用则两总线均停用,并通知用户(等待用户恢复)。●When the sending node sending error count value exceeds a certain threshold, restart the CAN controller to resend; if restarting the controller still fails to send, so that when the sending timeout occurs, then: if another bus is available, switch the bus and resend; if If the other bus is unavailable, both buses are disabled, and the user is notified (waiting for user recovery).

●当接收节点在接收错误计数值超过某阈值时:若另一总线可用,则重启该节点正在使用的CAN控制器、广播切换总线,(在CAN网络上广播发送特殊数据帧,通知各个节点:该节点在该总线上是接收不到有效数据帧的,所有节点需要切换到另一条总线上发送数据);若另一个总线不可用,则重启该节点的CAN控制器。●When the receiving node receives an error count value exceeding a certain threshold: If another bus is available, restart the CAN controller that the node is using, broadcast to switch the bus, (broadcast and send special data frames on the CAN network, and notify each node: The node cannot receive valid data frames on the bus, and all nodes need to switch to another bus to send data); if another bus is unavailable, restart the CAN controller of the node.

发送节点的发送计时器是利用系统时钟计时的,在将数据帧放入软件缓冲区时开始计时,将该数据帧的成员变量time值赋值为此时的系统时钟tick值加上阈值周期tick数。每当tick++时就会判断软件缓冲区首的数据帧time是否超时。CAN控制器内部自动记录发送错误、接收错误次数。通过对CAN控制器的相关寄存器的设置,使发送器、接收器在错误计数超过某阈值时,触发中断。接收错误计数值超过阈值则会切换总线,但是不表示另一条总线坏掉,而是为了尽量减少丢失数据帧,不必等待到超时再切换总线。发送错误计数值超出阈值时,就会重启控制器,并不切换总线。因为切换总线的花销比重启控制器要大。当重启后仍不能发送成功,则会发生超时中断切换总线重新发送。The sending timer of the sending node is timed by the system clock. It starts timing when the data frame is put into the software buffer, and assigns the member variable time value of the data frame to the current system clock tick value plus the threshold cycle tick number. . Every tick++ will judge whether the data frame time at the head of the software buffer has timed out. The number of sending errors and receiving errors is automatically recorded inside the CAN controller. By setting the relevant registers of the CAN controller, the transmitter and receiver trigger an interrupt when the error count exceeds a certain threshold. If the receiving error count value exceeds the threshold, the bus will be switched, but it does not mean that the other bus is broken, but to minimize the loss of data frames, it is not necessary to wait until the timeout before switching the bus. When the transmit error count exceeds the threshold, the controller is restarted without switching the bus. Because switching the bus is more expensive than restarting the controller. When the transmission is still not successful after restarting, a timeout interrupt will occur to switch the bus and resend.

每个节点设计一个记录数据帧的软件缓冲区结构数组(Buffer),使得数据帧在总线切换时无需转移。软件缓冲区数据帧Soft_Frame的数据结构(即数组元素的数据结构)如下:Each node designs a software buffer structure array (Buffer) for recording data frames, so that the data frames do not need to be transferred when the bus is switched. The data structure of the software buffer data frame Soft_Frame (that is, the data structure of the array elements) is as follows:

  typedef struct Soft_Frame{INT32U id;//发送节点发送的总线切换帧、接收节点发送的总线切换帧//总线恢复帧的ID分别为0、1、2INT8U type;//数据帧的类型(扩张帧、标准帧、数据帧、远程帧、)INT8U data[8];INT8U datalen;INT8U prio;//缓冲区优先级(即数据帧优先级) typedef struct Soft_Frame{INT32U id;//The bus switching frame sent by the sending node, the bus switching frame sent by the receiving node //The IDs of the bus recovery frame are 0, 1, 2 INT8U type; //The type of data frame (extended frame, Standard frame, data frame, remote frame,) INT8U data[8]; INT8U datalen; INT8U prio;//buffer priority (that is, data frame priority)

判断软件缓冲区是否是满的条件是:缓冲区中的有效数据个数是否等于NUM-1(NUM是软件缓冲区的最大容量)。为了防止当软件缓冲区放满数据帧时,特殊帧无法发送,我们要为特殊帧在软件缓冲区中预留一个数据缓冲区。当发送切换总线帧时,我们将其插入到软件缓冲区的预留位置,并且优先发送。所以,当软件缓冲区中的数据帧的个数为NUM-1个时,就表示软件缓冲区已满。The condition for judging whether the software buffer is full is: whether the number of valid data in the buffer is equal to NUM-1 (NUM is the maximum capacity of the software buffer). In order to prevent the special frame from being unable to be sent when the software buffer is full of data frames, we need to reserve a data buffer in the software buffer for the special frame. When sending a switch bus frame, we insert it into the reserved position of the software buffer and send it first. Therefore, when the number of data frames in the software buffer is NUM-1, it means that the software buffer is full.

我们按照到达软件缓冲区的次序,递增地为普通数据帧分配优先级。为保证数据帧的发送按照先到达先发送的原则,当优先级递增到255时(硬件缓冲区中的优先级寄存器为8位,最多有256个不同优先级),用户继续往软件缓冲区中放入数据帧则会返回错误,直至优先级为255的数据帧发送完毕,软件缓冲区才能够再接收用户的数据帧,而且数据帧的优先级从1开始递增。We assign priority to normal data frames incrementally in the order they arrive in the software buffer. In order to ensure that the data frames are sent according to the principle of first-come-first-send, when the priority increases to 255 (the priority register in the hardware buffer is 8 bits, there are at most 256 different priorities), the user continues to the software buffer Putting in a data frame will return an error, and the software buffer will not be able to receive the user's data frame until the data frame with a priority of 255 is sent, and the priority of the data frame will increase from 1.

特殊数据帧包括发送节点的总线切换帧Change_Send_Frame、接收节点的总线切换帧Change_REV_Frame以及总线恢复帧Recov_Frame。发送节点的总线切换帧是指发送节点超时时,发往各个节点的切换总线帧,通知各个节点原通道已经坏掉;而接收节点的总线切换帧是接收节点在接收错误超出阈值时广播的切换总线帧,并不意味着原总线出现故障,只是为了尽量减少接收节点丢失数据帧而采取的切换总线措施;总线恢复帧是用户通知各个节点原来已坏的通道已经可以恢复使用。其ID分别为0,1,2;而且Change_REV_Frame、Change_Send_Frame的优先级为0(这两种数据帧不会同时出现,所以优先级可以相同),意味着当该类帧到达软件缓冲区的预留位置时,将会是第一个被成功发送的数据帧(因为当前软件缓冲区的其他数据帧的发送被阻塞在另一条总线上);其他帧的优先级绝对不能为0;Recov_Frame的优先级跟一般数据帧相同,否则将会影响发送成功中断的去除软件缓冲区的队首数据帧的操作,因为发送成功中断总会删除软件缓冲区预留位置或者首位置(如果预留位置为空),Recov_Frame是在其他数据帧正常发送的期间到达软件缓冲区的,如果放在特殊帧位置上,则会被成功发送ISR错误地删除该特殊帧,而实际上该数据帧还没有发送。最好的解决办法是将总线恢复帧放置第四帧位置,但是开销太大,需要把第五位置后的所有数据帧后移。本设计做如下处理:切换总线帧直接插入到软件缓冲区的链首,保证其优先发送;总线恢复帧作为一般数据帧处理,插入到软件缓冲区数组末尾。The special data frames include the bus switching frame Change_Send_Frame of the sending node, the bus switching frame Change_REV_Frame of the receiving node, and the bus recovery frame Recov_Frame. The bus switching frame of the sending node refers to the switching bus frame sent to each node when the sending node times out, notifying each node that the original channel has been broken; the bus switching frame of the receiving node is the switching broadcasted by the receiving node when the receiving error exceeds the threshold The bus frame does not mean that the original bus is faulty, but it is just a measure to switch the bus to minimize the loss of data frames of the receiving node; the bus recovery frame is the user's notification to each node that the original broken channel can be restored. Its IDs are 0, 1, 2 respectively; and the priority of Change_REV_Frame and Change_Send_Frame is 0 (these two data frames will not appear at the same time, so the priority can be the same), which means that when this type of frame reaches the reserved software buffer position, it will be the first data frame to be successfully sent (because the sending of other data frames in the current software buffer is blocked on another bus); the priority of other frames must not be 0; the priority of Recov_Frame It is the same as the general data frame, otherwise it will affect the operation of removing the first data frame of the software buffer for sending successful interrupts, because sending successful interrupts will always delete the reserved position or the first position of the software buffer (if the reserved position is empty) , Recov_Frame arrives at the software buffer during the normal transmission of other data frames. If it is placed in the position of a special frame, it will be successfully sent and the ISR will mistakenly delete the special frame, but in fact the data frame has not been sent yet. The best solution is to place the bus recovery frame at the fourth frame position, but the overhead is too large, and all data frames after the fifth position need to be moved backwards. This design does the following processing: switch the bus frame directly into the chain head of the software buffer to ensure that it is sent first; the bus recovery frame is treated as a general data frame and inserted into the end of the software buffer array.

实验证明:当正在使用的总线出现故障,该设计能够正常发送数据帧,并且采用了该总线切换方法的接收节点丢失的数据帧比没采用该总线切换方法的节点少。该方法能够保证发送节点能够成功发送数据,接收节点能够正确接收数据,而且尽量少的丢失数据帧,从而保证了数据接收的可靠正确性、实时性。The experiment proves that: when the bus in use fails, the design can send data frames normally, and the receiving node using the bus switching method loses less data frames than the nodes not using the bus switching method. The method can ensure that the sending node can successfully send data, the receiving node can correctly receive data, and the data frame is lost as little as possible, thereby ensuring the reliability, correctness and real-time performance of data reception.

附图说明 Description of drawings

下面结合附图对本发明的具体实施方式作进一步详细说明。The specific implementation manners of the present invention will be described in further detail below in conjunction with the accompanying drawings.

图1是CAN冗余结构图;Figure 1 is a CAN redundancy structure diagram;

图2是图1发送数据时的流程图;Fig. 2 is a flow chart when Fig. 1 sends data;

图3是图1接收数据时的流程图;Fig. 3 is the flow chart when Fig. 1 receives data;

图4是图1重新发送数据时的流程图;Fig. 4 is a flowchart when Fig. 1 resends data;

图5是图1数据发送成功时的中断流程图;Fig. 5 is the interrupt flowchart when Fig. 1 data is sent successfully;

图6是图1错误超出阈值处理的流程图;Fig. 6 is a flowchart of Fig. 1 error exceeding threshold processing;

图7是图1超时切换总线的流程图。FIG. 7 is a flow chart of bus switching over time in FIG. 1 .

具体实施方式 Detailed ways

实施例1、如图1所示的一个双CAN网络,采用两套总线(即总线A和总线B),每套总线都包含完整的总线电缆、总线驱动器、总线控制器。Embodiment 1, a double CAN network as shown in Figure 1, adopts two sets of buses (i.e. bus A and bus B), and each set of buses includes complete bus cables, bus drivers, and bus controllers.

为了在上述双CAN网络中实现本发明的基于CAN冗余的总线切换方法,因此需要进行如下处理:In order to realize the bus switching method based on CAN redundancy of the present invention in above-mentioned double CAN network, therefore need to carry out following processing:

当发送节点发送错误计数值超过某阈值时,则重启CAN控制器重新发送,重启CAN控制器主要是清除控制器中的某些寄存器错误;如果重启控制器仍旧发送不成功,以至发送超时时,那么:若另一总线可用则切换总线重新发送;若另一总线不可用则两总线均停用,并用该节点指示灯提示用户,等待用户检测该节点的总线通路并及时恢复。When the sending node sending error count value exceeds a certain threshold, restart the CAN controller to resend. Restarting the CAN controller is mainly to clear some register errors in the controller; Then: if another bus is available, switch the bus and resend; if the other bus is not available, both buses will be disabled, and the node indicator light will be used to prompt the user, waiting for the user to detect the bus path of the node and recover in time.

当接收节点在接收错误计数值超过某阈值时:若另一总线可用,则重启该节点正在使用的CAN控制器、广播切换总线(在CAN网络上广播发送特殊数据帧,通知各个节点:该节点在该总线上是接收不到有效数据帧的,所有节点需要切换到另一条总线上发送数据);若另一个总线不可用,则重启该节点的CAN控制器,直至超时,节点停用并等待用户恢复。When the receiving node receives an error count value exceeding a certain threshold: if another bus is available, restart the CAN controller that the node is using, broadcast the switching bus (broadcast and send special data frames on the CAN network, and notify each node: the node Valid data frames cannot be received on this bus, and all nodes need to switch to another bus to send data); if another bus is unavailable, restart the CAN controller of the node until it times out, the node stops and waits User recovery.

实施例2、对实施例1所述的双CAN网络进行的基于CAN冗余的总线切换方法,两条CAN总线同时开启,但是某一时刻最多只有一条总线发送数据,以避免不同步问题造成的接收数据错误。使用软件缓冲区作为用户发送数据的缓冲池,当节点的三个硬件缓冲区有空闲时,就将软件缓冲区中的数据放入硬件缓冲区中,进行数据帧的发送;设置阈值以及超时机制用于通信出现故障时重新启动CAN控制器或者切换总线;利用每个总线节点的LED灯的亮灭来提示用户总线故障,及时恢复总线。Embodiment 2, the bus switching method based on CAN redundancy that is carried out to the dual CAN network described in embodiment 1, two CAN buses are opened simultaneously, but at most only one bus sends data at a time, in order to avoid problems caused by asynchronous Received data error. Use the software buffer as the buffer pool for the user to send data. When the three hardware buffers of the node are free, put the data in the software buffer into the hardware buffer to send the data frame; set the threshold and timeout mechanism It is used to restart the CAN controller or switch the bus when there is a communication failure; use the on and off of the LED lights of each bus node to prompt the user for bus failure and restore the bus in time.

具体依次进行以下步骤:Specifically, follow the steps below:

1)、判断该节点是属于发送节点还是接收节点,如果属于发送节点进入步骤2),如果属于接收节点进入步骤7);1), determine whether the node belongs to the sending node or the receiving node, if it belongs to the sending node, enter step 2), if it belongs to the receiving node, enter step 7);

2)、发送节点发送数据的流程具体如图2所示:在数据帧发送命令开始时记录数据的发送超时点deadline,然后将数据帧放入软件缓冲区,如果硬件缓冲区有空闲的话则进一步放入硬件缓冲区等待发送,硬件寄存器会自动记录发送过程中的发送错误数目。当发送错误超出用户设定的阈值后,就会进入步骤3);否则当收到接收节点的响应帧时即是发送成功,进入步骤4)。2), the flow of the sending node sending data is shown in Figure 2: record the data sending timeout point deadline at the beginning of the data frame sending command, then put the data frame into the software buffer, if the hardware buffer is free, then further Put it into the hardware buffer and wait for sending, and the hardware register will automatically record the number of sending errors during the sending process. When the transmission error exceeds the threshold set by the user, it will enter step 3); otherwise, when the response frame from the receiving node is received, the transmission is successful, and it will enter step 4).

3)错误计数超出阈值的中断处理程序,具体如图6:当是发送错误超出阈值时,判断发送节点是否发送超时,即判断发送节点的发送时间是否超过用户设定的最长的发送时间,超过该值则进入步骤5),否则重启控制器,重新发送数据,进入步骤6);当是接收错误超出阈值时,即判断另一条总线是否可用,如另一条总线可用,则广播切换至可用总线,发送接收数据,并重新启动原来总线的控制器;若另一条也不可用,则重启原控制器并提示用户(例如以指示灯的形式),等待用户恢复,用户在第一条CAN总线停用时,就应该想办法及时恢复总线。3) The interrupt processing program of the error count exceeding the threshold, as shown in Figure 6: When the sending error exceeds the threshold, it is judged whether the sending node has timed out, that is, it is judged whether the sending time of the sending node exceeds the longest sending time set by the user, If the value exceeds the value, go to step 5), otherwise restart the controller, resend the data, and go to step 6); when the receiving error exceeds the threshold, it is judged whether another bus is available. If another bus is available, the broadcast switches to available bus, send and receive data, and restart the controller of the original bus; if the other one is not available, restart the original controller and prompt the user (for example, in the form of an indicator light), waiting for the user to recover, the user is on the first CAN bus When deactivated, you should find a way to restore the bus in time.

4)成功发送数据中断处理具体如图5所示:去除软件buffer中已发送的数据帧,并读取软件缓冲区,如果能够读取到待发送的数据帧,则将其放入产生该中断的硬件buffer中等待发送,并清除硬件buffer空标志位;如果读取不到数据帧,说明软件缓冲区空,没有等待发送到数据帧,则禁能硬件buffer空中断。4) Successfully sent data interrupt processing is specifically shown in Figure 5: remove the data frame sent in the software buffer, and read the software buffer, if the data frame to be sent can be read, put it into the interrupt to generate the The hardware buffer is waiting to be sent, and the hardware buffer empty flag is cleared; if no data frame is read, it means that the software buffer is empty, and there is no data frame waiting to be sent, and the hardware buffer empty interrupt is disabled.

5)切换总线处理流程具体如图7所示:如果另一总线可用则重新初始化原来的控制器,并置指示灯提示用户原总线挂掉,等待用户及时恢复,然后切换至可用总线重新发送数据帧,即进入步骤6);如果另一总线不可用,则重新初始化该控制器并设置通道挂掉,点亮指示灯提示用户节点可能挂掉,及时恢复。5) The processing flow of bus switching is shown in Figure 7: if another bus is available, re-initialize the original controller, set the indicator light to remind the user that the original bus is down, wait for the user to recover in time, and then switch to the available bus to resend data frame, that is, enter step 6); if another bus is unavailable, reinitialize the controller and set the channel to hang up, light on the indicator to prompt the user node may hang up, and recover in time.

6)重新发送数据流程具体如图4所示:当软件缓冲区数据大小为0时,返回错误;当数据不为0时,如果存在特殊帧,则对特殊帧开始计时并将特殊帧首先放入硬件缓冲区中等待发送;如果不存在特殊帧,则将buffer+head位置处的数据帧放入硬件缓冲区中等待发送。6) The process of resending data is shown in Figure 4: when the data size of the software buffer is 0, an error is returned; when the data is not 0, if there is a special frame, start timing the special frame and put the special frame first If there is no special frame, put the data frame at the buffer+head position into the hardware buffer and wait to be sent.

7)接收节点的接收流程具体如图3所示:当在接收错误计数未超出阈值时,就已经成功接受到数据,则认为数据接收成功,会自动向发送者发送响应帧。接收节点根据数据帧的类型处理数据或者总线状态;如果接收错误超出阈值后就转向步骤3)。7) The receiving process of the receiving node is shown in Figure 3: when the receiving error count does not exceed the threshold, the data has been successfully received, and the data is considered to be received successfully, and a response frame will be automatically sent to the sender. The receiving node processes data or bus status according to the type of data frame; if the receiving error exceeds the threshold, it turns to step 3).

为了证明本发明的方法确实能保证数据接收的可靠正确性和实时性,发明人作了如下的对比实验:In order to prove that the method of the present invention can indeed guarantee reliable correctness and real-time performance of data reception, the inventor has done the following comparative experiments:

选用实施例1所述的CAN冗余网络。然后依照实施例2所述的方法,根据CAN通讯网络系统可能会造成的故障(如电缆的断线或短路、CAN总线驱动器的故障、总线控制器甚至单片机的故障、CAN网络外部磁场的干扰等),测试并对比采用了本发明提出的总线切换方法的网络,与不采用该方法的网络,在数据帧接收的稳定性、正确性、实时性的性能上的差别。The CAN redundant network described in Embodiment 1 is selected for use. Then according to the method described in embodiment 2, according to the fault that CAN communication network system may cause (such as the disconnection or short circuit of cable, the fault of CAN bus driver, the fault of bus controller or even single-chip microcomputer, the interference of CAN network external magnetic field etc. ), test and compare the network that has adopted the bus switching method that the present invention proposes, and the network that does not adopt this method, the difference on the stability of data frame reception, correctness, real-time performance.

本方法测试的硬件环境:The hardware environment tested by this method:

1.HCS12开发板三块:用作CAN节点(HCS12开发板将CAN控制器集成在该开发板中)。1. Three HCS12 development boards: used as CAN nodes (the HCS12 development board integrates the CAN controller into the development board).

2.CAN总线若干条:用来连接成CAN网络。2. Several CAN buses: used to connect to a CAN network.

3.烧写器:用来烧写应用程序至HCS12开发板。3. Programmer: used to program the application program to the HCS12 development board.

本设方法测试的软件环境:The software environment tested by this method:

1.CAN调试工具ZLGCANTest:用来测试CAN接收到的数据帧。1. CAN debugging tool ZLGCANTest: used to test the data frames received by CAN.

2.CodeWarrior IDE:用来编译烧写至HCS12中的代码。2.CodeWarrior IDE: used to compile the code programmed into HCS12.

通过该测试可以证明,本发明的方法能够使得发送节点成功发送数据,接收节点接收到数据,而且尽量少的丢失数据帧,从而保证了数据接收的可靠正确性、实时性。The test can prove that the method of the present invention can enable the sending node to successfully send data, the receiving node to receive the data, and lose data frames as little as possible, thereby ensuring the reliability, correctness and real-time performance of data reception.

最后,还需要注意的是,以上列举的仅是本发明的若干个具体实施例。显然,本发明不限于以上实施例,还可以有许多变形。本领域的普通技术人员能从本发明公开的内容直接导出或联想到的所有变形,均应认为是本发明的保护范围。Finally, it should be noted that the above examples are only some specific embodiments of the present invention. Obviously, the present invention is not limited to the above embodiments, and many variations are possible. All deformations that can be directly derived or associated by those skilled in the art from the content disclosed in the present invention should be considered as the protection scope of the present invention.

Claims (6)

1.一种基于CAN冗余的总线切换方法,其特征是包括以下步骤:1. A bus switching method based on CAN redundancy, characterized in comprising the following steps: 1)、判断是发送节点还是接收节点;当为发送节点时,进入步骤2);当为接收节点时,进入步骤5);1), determine whether it is a sending node or a receiving node; when it is a sending node, enter step 2); when it is a receiving node, enter step 5); 2)、判断发送节点是否发送超时;当判断为“是”时,进入步骤3),当判断为“否”时,则进入步骤4);2), judge whether the sending node sends overtime; when it is judged as "yes", enter step 3), when judged as "no", then enter step 4); 3)、切换总线重新发送,流程结束;3), switch the bus and resend, and the process ends; 4)、发送节点监视总线直至超时或者接收到接收节点的响应帧,表示成功发送数据,流程结束;4) The sending node monitors the bus until it times out or receives a response frame from the receiving node, indicating that the data is successfully sent and the process ends; 5)、判断接收节点是否接收超时;当判断为“是”时,进入步骤6),当判断为“否”时,则进入步骤7);5), determine whether the receiving node receives timeout; when it is judged as "yes", enter step 6), when it is judged as "no", then enter step 7); 6)、通过广播切换总线,告知其他节点切换总线重新发送数据,流程结束;6) Switch the bus by broadcasting, inform other nodes to switch the bus and resend the data, and the process ends; 7)、接收节点发送响应帧,作为对发送节点的响应,表示数据发送并接收成功,流程结束。7) The receiving node sends a response frame as a response to the sending node, indicating that the data is sent and received successfully, and the process ends. 2.根据权利要求1所述的一种基于CAN冗余的总线切换方法,其特征是:所述步骤2)中判断发送节点是否发送超时的标准为:发送节点的发送时间是否超过用户设定的最长的发送时间,超过该值认为该次数据发送失败。2. a kind of bus switching method based on CAN redundancy according to claim 1 is characterized in that: the standard of judging whether sending node sends overtime in described step 2) is: whether the sending time of sending node exceeds user setting The longest sending time, if it exceeds this value, it will be considered that the data sending failed. 3.根据权利要求1所述的一种基于CAN冗余的总线切换方法,其特征是:所述步骤5)中判断接收节点是否发送超时的标准为:接收节点的接收错误是否超出设定的阈值,该阈值是用户定义的能够忍受的最大接收错误次数。3. a kind of bus switching method based on CAN redundancy according to claim 1, it is characterized in that: in the described step 5), the standard of judging whether the receiving node sends overtime is: whether the receiving error of the receiving node exceeds the set Threshold, which is the user-defined maximum number of receiving errors that can be tolerated. 4.根据权利要求1、2或3所述的一种基于CAN冗余的总线切换方法,其特征是:同一时刻只能有一条总线发送数据;使用软件缓冲区作为用户发送数据的缓冲池,使用开发板的三个硬件缓冲区加速数据帧的发送;设置阈值以及超时机制用于通信出现故障时重启控制器或者切换总线重新发送或继续接收数据帧;用节点指示灯提示用户总线故障,需要及时恢复总线。4. according to claim 1,2 or 3 described a kind of bus switching method based on CAN redundancy, it is characterized in that: there can only be a bus to send data at the same moment; Use software buffer as the buffer pool of user sending data, Use the three hardware buffers of the development board to speed up the sending of data frames; set the threshold and timeout mechanism to restart the controller or switch the bus to resend or continue to receive data frames when the communication fails; Restore the bus in time. 5.根据权利要求4所述的一种基于CAN冗余的总线切换方法,其特征是:所述步骤3)具体为依次进行以下步骤:5. a kind of bus switching method based on CAN redundancy according to claim 4, is characterized in that: described step 3) is specifically to carry out following steps successively: A)、重启控制器重新发送:如发送成功,则进入步骤B);如仍旧发送不成功,以至发送超时,则进入步骤C);A), restart the controller and resend: if the sending is successful, go to step B); if the sending is still unsuccessful, so that the sending times out, go to step C); B)、监听等待网络上的响应帧,当收到接收节点的响应帧时表示该次数据传送成功,流程结束;B), monitor and wait for the response frame on the network, when receiving the response frame from the receiving node, it means that the data transmission is successful, and the process ends; C)、判断其余总线是否可用,如其余总线有至少一条总线可用,则采用该总线重新发送;若其余总线均不能使用,则提示用户,等待用户恢复,流程结束。C), judging whether the remaining buses are available, if at least one of the remaining buses is available, then use this bus to resend; if the remaining buses are not available, then prompt the user, wait for the user to recover, and the process ends. 6.根据权利要求5所述的一种基于CAN冗余的总线切换方法,其特征是:所述步骤6)具体为依次进行以下步骤:6. a kind of bus switching method based on CAN redundancy according to claim 5, is characterized in that: described step 6) is specifically to carry out following steps successively: 判断其余总线是否可用,如其余总线有至少一条总线可用,则广播切换总线、重启原控制器,表示该节点在该总线上是接收不到有效数据帧的;若另一个总线不可用,则重启原控制器,流程结束。Determine whether the remaining buses are available. If at least one of the remaining buses is available, broadcast the switching bus and restart the original controller, indicating that the node cannot receive valid data frames on this bus; if another bus is unavailable, restart The original controller, the process ends.
CN 200910099831 2009-06-22 2009-06-22 Bus switch method based on CAN redundance Expired - Fee Related CN101582799B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN 200910099831 CN101582799B (en) 2009-06-22 2009-06-22 Bus switch method based on CAN redundance

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN 200910099831 CN101582799B (en) 2009-06-22 2009-06-22 Bus switch method based on CAN redundance

Publications (2)

Publication Number Publication Date
CN101582799A CN101582799A (en) 2009-11-18
CN101582799B true CN101582799B (en) 2013-03-06

Family

ID=41364774

Family Applications (1)

Application Number Title Priority Date Filing Date
CN 200910099831 Expired - Fee Related CN101582799B (en) 2009-06-22 2009-06-22 Bus switch method based on CAN redundance

Country Status (1)

Country Link
CN (1) CN101582799B (en)

Families Citing this family (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN102611695A (en) * 2012-01-18 2012-07-25 武汉光庭科技有限公司 Method for designing general-type SAE J1939 protocol stack
CN106292385A (en) * 2015-05-13 2017-01-04 北京电子工程总体研究所 The hot redundancy control system of a kind of dual CAN bus and method
CN105323133A (en) * 2015-11-12 2016-02-10 浙江大学 CAN bus redundant communication method and system
CN105589826B (en) * 2016-02-01 2019-08-16 国网福建省电力有限公司 Power distribution network multi-level bus information interacting method based on plug and play
CN107426072A (en) * 2017-06-29 2017-12-01 北京电子工程总体研究所 A kind of CAN redundancy retransmits the fault-tolerant means of communication
CN114968890A (en) * 2022-05-27 2022-08-30 中国第一汽车股份有限公司 Synchronous communication control method, device, system and storage medium

Citations (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US5784547A (en) * 1995-03-16 1998-07-21 Abb Patent Gmbh Method for fault-tolerant communication under strictly real-time conditions
CN200990401Y (en) * 2006-05-12 2007-12-12 上海神力科技有限公司 Double-machine redundancy control system based on CAN bus
CN101282301A (en) * 2008-05-12 2008-10-08 北京邮电大学 Dual redundant CAN bus controller and its message processing method

Patent Citations (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US5784547A (en) * 1995-03-16 1998-07-21 Abb Patent Gmbh Method for fault-tolerant communication under strictly real-time conditions
CN200990401Y (en) * 2006-05-12 2007-12-12 上海神力科技有限公司 Double-machine redundancy control system based on CAN bus
CN101282301A (en) * 2008-05-12 2008-10-08 北京邮电大学 Dual redundant CAN bus controller and its message processing method

Also Published As

Publication number Publication date
CN101582799A (en) 2009-11-18

Similar Documents

Publication Publication Date Title
CN101582799B (en) Bus switch method based on CAN redundance
EP2630745B1 (en) System and method for power saving modes in high speed serial interface communication systems utilizing selective byte synchronization
RU2606053C2 (en) Method of controlling change in state interconnection node
CN1111994C (en) Method for fault-tolerant communication under strictly real-time conditions
US7693070B2 (en) Congestion reducing reliable transport packet retry engine
CN101197651B (en) Method, equipment, master control board and interface plate of communication between plates
CN107534592B (en) Method for protecting configuration data of a data bus transceiver, data bus transceiver and data bus system
JP2002064518A (en) Error correcting communication method to transmit data packet in network communication system
WO2011131081A1 (en) Method and apparatus for implementing redundancy serial bus
CN109768907A (en) A kind of CAN bus baud rate self-adapting setting method
WO2007063482A2 (en) Bus station and system and method of maintaining synchronizing of a bus station
WO2013097642A1 (en) Data packet retransmission method and node in quick path interconnect system
WO2015032048A1 (en) Method for internal communication of mobile terminal
CN102436430B (en) Memory device, host controller and memory system
JP6458494B2 (en) Information processing apparatus, information processing system, and communication apparatus
CN201846346U (en) Dual-redundancy heat switching system of controller area network (CAN) bus
US20090300452A1 (en) Error identifying method, data processing device, and semiconductor device
CN104714909A (en) Device, method, bus structure and system for dealing with hang-up death of buses
KR101566640B1 (en) Fault-tolerant dual-can (ft-dcan) device and method to tolerate arbitrary network faults, recording medium for performing the method
CN1756377A (en) A method for detecting single board failure
CN112187408A (en) Data processing method, system, device, storage medium and processor
JPH08185329A (en) Data processor
JP6442974B2 (en) Information processing apparatus and information processing system
CN112769591B (en) Effective anti-interference and error-proof daisy chain communication processing method
JP2581013B2 (en) Bus fault handling circuit

Legal Events

Date Code Title Description
C06 Publication
PB01 Publication
C10 Entry into substantive examination
SE01 Entry into force of request for substantive examination
C41 Transfer of patent application or patent right or utility model
TA01 Transfer of patent application right

Effective date of registration: 20091225

Address after: 38, Da Da Lu, Xihu District, Zhejiang, Hangzhou Province, China: 310027

Applicant after: Zhejiang University

Co-applicant after: INSIGMA GROUP CO., LTD.

Address before: 38, Da Da Lu, Xihu District, Zhejiang, Hangzhou Province, China: 310027

Applicant before: Zhejiang University

C14 Grant of patent or utility model
GR01 Patent grant
CF01 Termination of patent right due to non-payment of annual fee

Granted publication date: 20130306

Termination date: 20180622

CF01 Termination of patent right due to non-payment of annual fee