Invention content
The technical problem to be solved in the present invention is to provide a kind of synchronous method of controller local area network, can determine message
The precise time that data reach is conducive to eliminate time deviation, improves synchronization accuracy.
In order to solve the above technical problems, the present invention provides a kind of synchronous method of controller local area network, the control
Device local area network includes host node and from node, and each node includes main control device and coupled network controller, described
Method includes:
The encapsulation of the data frame of each node:In the network controller of each node number is received from controller local area network
According to when, the first current clock value of the clock unit being arranged on the network controller of the node is encapsulated as with the data
Data frame;
Time coordination between the main control device and network controller:Master clock based on the main control device when
Second current clock value of the clock unit of clock value or the network controller, coordinate the master clock of the main control device with
The clock of the clock unit of the network controller;
The host node is synchronous with the time between node:Message is triggered based on synchronous, with the host node
Network controller clock unit third current clock value on the basis of, by the clock unit of the network controller of host node
Third current clock value is broadcasted to the network controller from node, when current according to the third received from meshed network controller
Clock value updates the clock of the clock unit of itself.
Optionally, the host node and the time between node synchronization include:
Step a records the network control of host node in the controller local area network respectively based on the synchronous triggering message
4th present clock of the third current clock value of the clock unit of device processed and clock unit from the network controller of node
Value is denoted as host node synchronised clock value tm_sync and from node synchronised clock value ts-sync respectively;
Step b broadcasts the host node synchronised clock value tm_sync to from node;
Step c, it is described to be synchronized from node from node synchronised clock value ts_sync and the host node received according to described
Clock value tm_sync updates the clock of the clock unit of itself.
Optionally, the step c includes:
Step c1, it is described after node receives the host node synchronised clock value tm_sync, using following formula reset from
The clock ts of the clock unit of body:Ts=ts_sync+ Δ tm_ts/n+ Δs ts, wherein Δ tm_ts=tm_sync-ts_sync,
From section when Δ ts=ts_recv-ts_sync, ts_recv receive the host node synchronised clock value tm_sync for described in from node
5th current clock value of the clock unit of point, n are the positive integer more than 1;
More times of step c2, repeating said steps a, b, c1.
Optionally, it is based on the synchronous triggering message, records the network of host node in the controller local area network respectively
4th current clock value of the third current clock value of controller and clock unit from the network controller of node includes:
The synchronous triggering is received in the host node from controller local area network with the network controller from node to disappear
When breath, by the third current clock value and the 4th current clock value of the host node and clock unit from node itself respectively with
The synchronous triggering message is encapsulated as data frame;
By the data frame by communications interface transmission to the host node and from the respective main control device of node.
Optionally, the time coordination between the main control device and network controller includes:
It is second current to read the clock unit from the node clock unit of itself for the main control device timing of each node
Clock value;
Each node updates the master clock of itself main control device with the second current clock value of the clock unit read.
Optionally, the main control device reads second current clock value from the clock unit in the following way:
The clock unit timing reports second current clock value to the main control device.
Optionally, the time coordination between the main control device and network controller includes:
The clock value timing of the master clock of the main control device of each node is written into the clock unit of itself with to it
It is updated.
Optionally, the main control device is the computer with host bus, and the main control device in the following way will
The clock value of the master clock is written to the clock unit:
The Central Shanxi Plain is disconnected;
Read the clock value of the master clock;
Lock the host bus of the main control device;
The clock value of the master clock is written via the host bus into the clock unit;
Release the locking to the host bus;
Open interruption.
Optionally, the synchronous triggering message is sent out by any node in the controller local area network.
Optionally, the method further includes:After the encapsulation of the data frame of each node, the data frame is passed through logical
Letter interface is transmitted to the main control device.
Compared with prior art, the present invention has the following advantages:
In the synchronous method of the controller local area network of the embodiment of the present invention, the net of each node in controller local area network
Independent clock unit is set at network controller, is based on synchronous triggering message later, records the third of the clock unit of host node
4th current clock value of current clock value and clock unit from node, is denoted as respectively as host node synchronised clock value tm_
Sync and from node synchronised clock value ts_sync, and host node synchronised clock value tm_sync is broadcasted to respectively from node, from section
Put the slave node synchronised clock value ts_sync according to precedence record and the host node synchronised clock value tm_sync received more
The new work clock of itself.Due to being provided with independent clock unit on network controller, thus synchronous triggering can be disappeared
The precise time that breath reaches each node is recorded, and uncertainty and unstability of the operating system to interrupt response are avoided,
So that the synchronization between each node is more accurate.
Further, the synchronous method of the controller local area network of the embodiment of the present invention further includes the envelope of the data frame of node
Dress, when network controller receives data from controller local area network, the first of the data received and clock unit is worked as
Preceding clock value is encapsulated as data frame, and via communications interface transmission to main control device, due to including that data reach in data frame
When correct time, thus the interrupt response in main control device be not necessarily to carry out timestamp addition action, the load of main control device
And external event can't impact the data arrival time of record.
In addition, in the embodiment of the present invention, the main control device of controller local area network's node and the clock portion of network controller
The clock of part can be coordinated, can be on the basis of clock unit, can also be on the basis of the master clock of main control device so that whole
A node is based on the same clock work.
Specific implementation mode
With reference to specific embodiments and the drawings, the invention will be further described, but the guarantor of the present invention should not be limited with this
Protect range.
Controller local area network includes host node and from node, wherein each node includes main control device and coupled
Network controller, the synchronous method of the controller local area network of the present embodiment includes that the encapsulation of the data frame of node, master control are set
Standby time coordination and host node between network controller and the synchronization from the time between node.Wherein, each node
The encapsulation of data frame include:When the network controller of each node receives data from controller local area network, will be arranged
First current clock value of the clock unit on the network controller of the node is encapsulated as data frame with the data;Master control
Time coordination between equipment and network controller includes:The clock value of master clock based on the main control device is described
Second current clock value of the clock unit of network controller coordinates the master clock of the main control device and the network-control
The clock of the clock unit of device;Host node and from the synchronization of the time between node include:Message is triggered based on synchronous, with described
On the basis of the third current clock value of the clock unit of the network controller of host node, by the clock of the network controller of host node
The third current clock value of component is broadcasted to the network controller from node, from meshed network controller according to the third received
Current clock value updates the clock of the clock unit of itself.
Fig. 2 shows the flow diagrams synchronous with what it is from the time between node of host node in the present embodiment, including:
Controller local area network step a is recorded based on the synchronous triggering message in the controller local area network respectively
The clock unit of the third current clock value of the network controller of host node and clock unit from the network controller of node
The 4th current clock value, be denoted as host node synchronised clock value tm_sync respectively and from node synchronised clock value ts_sync;
Step b broadcasts the host node synchronised clock value tm_sync to from node;
Step c, it is described to be synchronized from node from node synchronised clock value ts_sync and the host node received according to described
Clock value tm_sync updates the clock of the clock unit of itself.
Fig. 3 shows the structure diagram of each node in the controller local area network of the present embodiment, includes mainly network-control
Device 22, clock unit 21, logging modle 23, communication interface 24 and main control device 25.
Clock unit 21 is arranged on network controller 22, such as can be arranged in the outside of network controller 22 or collection
It is realized at various dedicated high accurate calculagraphs or programming device inside it, specifically may be used.It is non-as one
Restrictive example, in the present embodiment, clock unit 21 is using the field programmable gate array outside network controller 22
(FPGA)To realize.Clock unit 21 is independent high precision clock, and the automatic running when node starts can provide for node
Independent high precision reference clock.
Logging modle 23 is able to record clock when network controller 22 receives network data from controller local area network
The current clock value of component 21.Such as when network controller 22 receives synchronous triggering message, by the of clock unit 21
One current clock value triggering message synchronous with what is received is packaged together, and forms data frame.Certainly, according to specific embodiment
Difference can also remember the first current clock value of clock unit 21 when network controller 22 receives synchronous triggering message
Record is the associated data of triggering message synchronous with this, but the two is not packaged together.
In the present embodiment, the FPGA outside controller local area network's controller 22 may be used to realize in logging modle 23,
Preferably, same FPGA device may be used to realize clock unit 21 and logging modle 23.
The data frame that encapsulation is formed is transmitted to main control device 25 by communication interface 24.Communication interface 24 can be various strings
Capable, parallel data transmission interface is capable of providing using PCIe interface, double either simplex connection of PCIe interface in the present embodiment
Higher transmission rate and quality, third generation PCIe can reach the transmission rate of every channel 1GB/s, be connect using the high broadband of high speed
It mouthful realizes communication interface 24, can realize the transmission real-time of controller local area network's data.Main control device 25 can be with
The various computer equipments etc. that controller local area network's controller 22 is used cooperatively, main control device 25 for example can be in the present embodiment
It is personal computer(PC).
As a unrestricted example, Fig. 4 shows the timestamp acquisition process of CAN frames in a specific embodiment,
CAN controller in CAN cards 31(It is not shown)CAN frames 300 are received from CAN network 30, host node with from the synchronous of node
In the process, which can be above-mentioned synchronous triggering message.It is high-precision from 32 in CAN cards 31 when receiving CAN frames 300
Spend timer 311(That is clock unit)The first current clock value of middle acquisition, and as hardware timestamping 312 and CAN frames 300
It is packaged together.CAN frames 300 and hardware timestamping 312 after encapsulation are transmitted to main control device 32, via straight after driving layer 321
The application layer 322 for being transmitted to upper layer is connect, driving layer 321 does not need to carry out the addition action of timestamp.Due to hardware timestamping
312 encapsulation process is in CAN cards 31 by independent clock unit(That is 32 high accurate calculagraphs 311)And record mould
For block come what is be automatically performed, driving layer 321 is no longer responsible for addition timestamp, mutually independent with the system operation of main control device 32, to
Influence caused by system load, scheduling etc. in the main control devices such as PC 32 is avoided, farthest reduces interference so that shake
And delay minimization.
With reference to figure 5, using above-mentioned recording mechanism, each node in network(Including host node and it is one or more from
Node)Based on same synchronous triggering message sync, the network controller of host node when synchronization triggering message reaches is recorded respectively
Clock unit third current clock value and clock unit from the network controller of node the 4th current clock value, point
It is not denoted as host node synchronised clock value tm_sync and from node synchronised clock value ts_sync, that is, completes the step a in Fig. 1.Its
In, it can be that any one node is sent out in network which, which triggers message sync,.
In conjunction with Fig. 1 and Fig. 5, execute step b, host node by the host node synchronised clock value tm_sync of record broadcast to from
Node;Step c is executed later, when from node according to being synchronized from node synchronised clock value ts_sync and the host node received
Clock value tm_sync updates the clock ts of the clock unit of itself.
Preferably, step c includes the following steps in the present embodiment, step c1:Host node synchronised clock value is received from node
After tm_sync, the clock ts of the clock unit of itself is reseted using following formula:Ts=ts_sync+ Δ tm_ts/n+ Δ ts,
In, Δ tm_ts=tm_sync-ts_sync, Δ ts=ts_recv-ts_sync, ts_recv are to receive host node from node to synchronize
From the 5th current clock value of the clock unit of node when clock value tm_sync, n is the positive integer more than 1, such as can be chosen
10;Step c2:Repeat the above steps more times of b, c, d1 so that gradually levels off to host node from the clock ts of the clock unit of node
Clock unit clock tm.
Referring still to Fig. 3, in the present embodiment, it is provided with clock unit 21 on the network controller 22 in each node,
The clock value of its clock value and the master clock of main control device 25 is mutually independent, in order to realize better Network Synchronization effect, master control
Time between equipment 25 and network controller 22 is coordinated, when the master control that coordination process can be based on main control device 25
Second current clock value of the clock value of clock or the clock unit of network controller 22.
Difference according to specific embodiment can specifically include on the basis of clock unit 21 into the coordination of row clock:It is main
Control the second current clock value that clock unit 21 is read in 25 timing of equipment from clock unit 21;Work as using the second of clock unit 21
The master clock of preceding clock value update main control device 25 itself main control device 25(Such as PC clocks).It wherein, can be in the node
Including dedicated clock interface, so that main control device 25 passes through the current clock value of clock interface reading clock unit 21.
The acquisition modes of the current clock value of clock unit 21 are at least following two:
Clock unit 21 is mapped in the memory of master control unit 25 when initialization, and an I/O operation is provided in driving
It realizes the read-write to clock unit 21, obtains the promptness of clock in order to prevent and accuracy is affected, can take ratio
Compared with the method for setting, that is, the second current clock value → acquisition master clock of master clock → acquisition clock unit 21 is obtained, such as
The master clock obtained twice before and after fruit is relatively, then it is assumed that the second current clock value of the clock unit 21 this time obtained has
Effect.The second current clock value for obtaining clock unit 21 may include following two data transmission procedures:First, reading clock request
Data reach the process of communication interface 24;Second is that clock data reaches the process of requestor from communication interface 24, two acted
Cheng Douhui is influenced by system, and this mode needs repeatedly to attempt if failure;
Clock unit 21 is configured, the data packet or direct of a specific format is periodically reported according to preset frequency
It is packaged into the format of CAN frames, wherein including the second current clock value of clock unit 21, main control device 25 is receiving the number
According to rear, that is, obtain the second current clock value of clock unit 21.Due to this mode only once data transmission procedure, thus can
It is a kind of preferred mode to reduce probability impacted in clock acquisition process.
Difference according to specific embodiment, can also be on the basis of main control device 25 master clock of itself into row clock
Coordinate, specifically includes:The clock value timing of the master clock of main control device 25 is written into the clock unit 21 of itself, with right
Clock unit 21 is updated.
By taking main control device 25 is personal computer as an example, there cannot be too big delay to the ablation process of clock unit 21,
Otherwise it can lead to whole system entanglement synchronization time.Ablation process is influenced by factors, for example, terminal, multi-core CPU and
Bursty data in bus etc. can all cause the delay of write operation.Modern mainstream processor includes that the traditional front ends Intel are total
Line(FSB), QPI buses and AMD HT buses, generally there are two layers of buses:Host(host)Bus and pci bus or other
IO buses.Host buses connect multiple CPU and memory(Or Memory Controller Hub is integrated in inside processor), host/PCI bridges
(North bridge), pci bus connects host/PCI bridges and PCI master-slave equipments and PCI/ISA bridges, that is, common south bridge.No matter which kind of mode
Device PCI in the register mappings to memory of oneself, will need to access host buses by north bridge, then reach memory.It is interior
The mapping and access deposited are completed by bridge+DMA, and in multiprocessor, and CPU is also shared bus.IA32 systems
The #lock pins of CPU are connected to the #lock pins of north bridge chips, and when the instruction execution with lock prefixes, north bridge chips can be drawn
#lock level is played to decontrol again until the instruction execution finishes to lock bus.Avoiding problems in the mistake synchronized to clock
Cheng Zhong occurs delay caused by a large amount of data interaction or bus are occupied by other CPU in bus.So being carried out to clock same
It can be influenced caused by by locking bus and avoiding bus occupied when step.
Specifically, may include by the processing procedure that the current value of master clock is written to clock unit 21:The Central Shanxi Plain is disconnected;It reads
Take the clock value of master clock;Lock the host buses of main control device 25;The current value of master clock is passed through into host buses, logical
Letter interface 24, which is written in clock unit 21, is updated it;Release the locking to host buses;It opens and interrupts.
It will can improve synchronous effect in master clock timing write-in to clock unit 21, such as can be in drive load
Start timer, and carry out above-mentioned action in timer processing function, refresh clock is periodically carried out on the basis of master clock
Component.But since to be related to locking host bus and the Central Shanxi Plain disconnected for the above process, thus in order to avoid on the system reform at influence,
Its frequency generally should not be too high.
The synchronous method of the controller local area network of the present embodiment includes the encapsulation of the data frame of node, in network controller
When receiving data from controller local area network, the data and node are arranged first of the clock unit on network controller
Current clock value is encapsulated as data frame;Later, which can be passed through communications interface transmission to main control device.
Due to obtaining and encapsulating when the first current clock value in data frame receives data from network, thus it is accurate
Exactness is very high, and in addition main control device need not also add timestamp in interrupt function, avoid current system load and
External time influences the problem of caused timestamp deviation.More details about the data receiver method can also join
The associated description being admitted in the synchronous method for stating controller local area network.
It should be noted that those skilled in the art it is recognised that the first current clock value in above description to
Five current clock values can be numerically identical, can also be different.
Although the present invention is disclosed as above with preferred embodiment, it is not for limiting the present invention, any this field skill
Art personnel without departing from the spirit and scope of the present invention, can make possible variation and modification, therefore the guarantor of the present invention
Shield range should be subject to the range that the claims in the present invention are defined.