A time synchronization method, comprising:
- searching, at a Serializer Deserializer (SERDES) parallel interface, a synchronized block matching a preset code pattern in a data stream;
- determining a position of a bit of the synchronized block in the SERDES parallel interface as a first position;
- determining a time point when the synchronized block passes through the SERDES parallel interface as a first time point;
- searching the synchronized block and a Precision Time Protocol (PTP) packet in the data stream at an interface between a Physical (PHY) layer and a Media Access Control (MAC) layer, and determining a distance between the synchronized block and the PTP packet;
- and
- determining a second time point according to the first position, the first time point and the distance, and the second time point being a time point when the PTP packet passes through a SERDES serial interface;
- wherein determining a second time point according to the first position, the first time point and the distance comprises:
- adjusting the number of bits corresponding to the distance according to M preset ratios, taking the obtained M adjusted values as a number set, M being an integer greater than 1;
- determining, from the number set, the number of bits matching the type of a Media Independent Interface (MII) in the interface between the PHY layer and the MAC layer as a matching number of bits;
- and
- determining the second time point according to the matching number of bits, the first time point and the first position;
- wherein determining the second time point according to the matching number of bits, the first time point and the first position further comprises:
- adjusting a preset number of bits according to the number of bits corresponding to the first position to obtain a first number of bits, the preset number of bits being a bit width of the SERDES parallel interface;
- determining a second number of bits according to the matching number of bits and the first number of bits, the second number of bits being the number of bits between the first bit of the synchronized block and the first bit of the PTP packet in the SERDES serial interface;
- adjusting a standard rate corresponding to the SERDES serial interface according to a rate deviation to obtain the actual rate at which the second number of bits is transmitted in the SERDES serial interface, the rate deviation being a difference between the actual bit rate in the SERDES serial interface and the standard bit rate of the SERDES serial interface;
- dividing the second number of bits by the actual rate to obtain a first delay, the first delay being a time period between the time point when the first bit of the PTP packet passes through the SERDES serial interface and the time point when the first bit of the synchronized block passes through the SERDES serial interface;
- and
- determining the second time point according to the first delay, the first time point and the corresponding delay of the synchronized block from the SERDES serial interface to the SERDES parallel interface.