CROSS-REFERENCE TO RELATED APPLICATION

This application claims the priority benefit of Taiwan application serial no. 109125983, filed on Jul. 31, 2020. The entirety of the above-mentioned patent application is hereby incorporated by reference herein and made a part of this specification.

BACKGROUND

1. Technical Field

The disclosure relates to a byte stuffing circuit and a byte stuffing method.

2. Description of Related Art

The high-level data link control (HDLC) protocol is an Ethernet data format used in wide area network (WAN).FIG. 1is a schematic diagram of an HDLC data stream. The HDLC data stream may include several HDLC frames, and two HDLC frames may be separated by a flag byte. In general, HDLC data stream uses a hexadecimal value “7E” as the flag byte. In order for the receiving end of the HDLC data stream to correctly recognize the difference between the payload in the HDLC frame and the flag, the hexadecimal value “7E” in the HDLC frame needs to be replaced with other hexadecimal values.

FIG. 2is a schematic diagram of converting a data stream to an HDLC data stream by byte stuffing. The flag byte containing the hexadecimal value “7E” will be added to both ends of the data stream, the hexadecimal value “7E” in the data stream will be replaced with the hexadecimal value “7D5E”, and the hexadecimal value “7D” in the data stream will be replaced with the hexadecimal value “7D5D”. Therefore, after byte stuffing, the size of the payload of the HDLC data stream will be larger than the size of the original data stream.

On the other hand, as the carrier frequency of Ethernet increases, many common field programmable gate array (FPGA) or very large scale integrated circuit (VLSI) technologies have gradually become incapable of supporting the carrier frequency of Ethernet. For example, common FPGA or VLSI technologies may not support operating frequencies exceeding 500 megahertz (MHz), but the current carrier frequency of Ethernet may be as high as 10 gigahertz (GHz). In order to reduce the operating frequency, serial data of Ethernet may be changed to parallel data. For example, converting 64-byte serial data of 10 GHz to 64-byte parallel data may reduce the operating frequency from 10 GHz to 156.25 MHz.

However, if byte stuffing is performed on the parallel data to convert the parallel data to HDLC data, the size of the HDLC data may increase to exceed the size supported by the data bus of the parallel data.

SUMMARY

The disclosure provides a byte stuffing circuit and a byte stuffing method for performing byte stuffing on parallel data.

The byte stuffing circuit of the disclosure includes an input gate, a logic circuit, a remnant register, a remnant gate, and an output gate. The input gate receives a first data stream and generates a second data stream according to the first data stream; a first size of the first data stream is N bytes, and a second size of the second data stream is 2N bytes, in which N is a positive integer. A logic circuit is coupled to the input gate, and includes an Xth stage logic gate. The Xth stage logic gate overwrites the Xth byte with a first stuffing byte in response to the Xth byte of the second data stream matching a first flag byte and inserts a second stuffing byte into an (X+1)th byte of the second data stream, in which X is a positive integer between 1 and 2N−1. A remnant register stores a remnant data stream. A remnant gate is coupled to the logic circuit and the remnant register, in which the remnant gate combines the remnant data stream and a first part of the second data stream to generate a third data stream and configures a second part of the second data stream as the remnant data stream. An output gate is coupled to the remnant gate and outputs the third data stream.

In an embodiment of the disclosure, the Xth stage logic gate inserts a third stuffing byte into the (X+1)th byte in response to the Xth byte matching a second flag byte.

In an embodiment of the disclosure, a third size of the third data stream is N bytes, in which the remnant gate determines the first part of the second data stream according to a fourth size of the remnant data stream and the third size.

In an embodiment of the disclosure, the byte stuffing circuit further includes a remnant counter and a controller. The remnant counter stores a remnant count value corresponding to a fourth size of the remnant data stream. The controller is coupled to the input gate, the Xth stage logic gate, and the remnant gate, in which the controller stops the operation of the input gate and the Xth stage logic gate in response to the remnant count value being larger than or equal to N until the remnant count value updated is smaller than N.

In an embodiment of the disclosure, the Xth stage logic gate increases a count value by one in response to the Xth byte matching one of the first flag byte or a second flag byte, in which the remnant gate generates the remnant count value updated according to a count value and the remnant count value.

In an embodiment of the disclosure, the first flag byte is a hexadecimal value “7E”, the first stuffing byte is a hexadecimal value “7D”, and the second stuffing byte is a hexadecimal value “5E”, in which the second flag byte is the hexadecimal value “7D”, and the third stuffing byte is a hexadecimal value “5D”.

In an embodiment of the disclosure, the third data stream is parallel data.

In an embodiment of the disclosure, the input gate performs zero stuffing on the first data stream to generate the second data stream.

In an embodiment of the disclosure, the Xth stage logic gate shifts the (X+1)th to a (2N)th byte of the second data stream to insert the second stuffing byte into the (X+1) byte.

The byte stuffing method of the disclosure includes: receiving a first data stream and generating a second data stream according to the first data stream; a first size of the first data stream is N bytes, and a second size of the second data stream is 2N bytes, where N is a positive integer; in response to an Xth byte of the second data stream matching a first flag byte, overwriting the Xth byte with a first stuffing byte, and inserting a second stuffing byte into an (X+1)th byte of the second data stream, where X is a positive integer between 1 and 2N−1; combining a remnant data stream and a first part of the second data stream to generate a third data stream, and configuring a second part of the second data stream as the remnant data stream; and outputting the third data stream.

In summary, according to the disclosure, byte stuffing may be performed on parallel data, and the bit-width of the byte-stuffed parallel data will not increase.

