Communication method and system, device, and computer-readable storage medium
A communication method is applied to a first device and a second device. The first device and the second device implement data communication through a target signal cable. The method includes: The first device constructs to-be-sent multi-bit target data into at least one target data packet based on a preset format, where each target data packet includes at least one bit of target data and multi-bit identification data, and the multi-bit identification data in each target data packet is used to indicate a quantity and locations of target data in a corresponding target data packet. The first device packs each bit of data in the at least one target data packet, so that different data has different signal waveforms after being packed. The first device sequentially sends each bit of packed data to the second device through the target signal cable.
1 . A method, comprising:
constructing, by a first device, multi-bit target data into at least one target data packet based on a preset format, wherein each target data packet of the at least one target data packet comprises at least one bit of the multi-bit target data and multi-bit identification data, and the multi-bit identification data in each target data packet indicates a quantity and locations of target data in a corresponding target data packet;
packing, by the first device, each bit of data in the at least one target data packet in a manner that different data has different signal waveforms after being packed, to obtain packed data; and
sequentially sending, by the first device, each bit of the packed data to a second device through a single target signal line, wherein the single target signal line connects an input/output port of the first device to an input/output port of the second device and excludes transmission of a clock signal.
2 . The method according to claim 1 , wherein:
when a bit of data in the at least one target data packet is binary data 0, in a data period, a signal waveform corresponding to the bit of data comprises a signal rising edge and a signal falling edge; and
when a bit of data in the at least one target data packet is binary data 1, in a data period, a signal waveform corresponding to the bit of data comprises a signal rising edge and does not comprise a signal falling edge.
3 . The method according to claim 1 , wherein at least one multi-bit identification data comprises multi-bit first identification data and multi-bit second identification data, and the multi-bit first identification data is different from the multi-bit second identification data; and
wherein the preset format comprises: each target data packet of the at least one target data packet comprises a data packet header and at least one data segment, the data packet header of a respective target data packet comprises consecutive multi-bit first identification data and at least one bit of the multi-bit second identification data, each data segment in the at least one data segment of the respective target data packet comprises at least one bit of the target data and at least one bit of the multi-bit second identification data, and a quantity of the consecutive multi-bit first identification data in the data packet header of the respective target data packet is greater than a quantity of the at least one bit of the target data in each data segment of the respective target data packet.
4 . The method according to claim 1 , further comprising:
receiving, by the second device through the single target signal line, each bit of the packed data sent by the first device, and determining each bit of the packed data based on a signal waveform corresponding to each bit of the packed data, to obtain the at least one target data packet; and
parsing, by the second device, the at least one target data packet based on the preset format, to obtain the multi-bit target data.
5 . The method according to claim 4 , wherein determining each bit of the packed data based on the signal waveform corresponding to each bit of the packed data comprises:
when the second device detects that the signal waveform corresponding to each bit of the packed data is on a rising edge, starting, by the second device, timing, and collecting data at a preset moment;
when the second device collects a low level, determining, by the second device, that the collected data is binary data 0; and
when the second device collects a high level, determining, by the second device, that the collected data is binary data 1.
6 . The method according to claim 1 , wherein the method is applied to data communication between chips, the first device comprises a first chip, and the second device comprises a second chip.
7 . The method according to claim 1 , wherein the method is applied to determining whether the single target signal line is correctly connected, the multi-bit target data comprises identification information of the single target signal line, the identification information of the single target signal line indicates the single target signal line, and after the second device obtains the multi-bit target data in the target data packet, the method further comprises:
determining, by the second device, whether the identification information of the single target signal line comprised in the multi-bit target data matches preset information;
when the identification information of the single target signal line matches the preset information, determining, by the second device, that the single target signal line is correctly connected; and
when the identification information of the single target signal line does not match the preset information, determining, by the second device, that the single target signal line is incorrectly connected.
8 . A device, comprising:
a processor; and
a memory, wherein the processor is configured to execute code stored in the memory, and executing the code causes the device to perform the following:
constructing multi-bit target data into at least one target data packet based on a preset format, wherein each target data packet comprises at least one bit of the multi-bit target data and multi-bit identification data, and the multi-bit identification data in each target data packet of the at least one target data packet indicates a quantity and locations of target data in a corresponding target data packet;
packing each bit of data in the at least one target data packet in a manner that different data has different signal waveforms after being packed, to obtain packed data; and
sequentially sending each bit of the packed data to a second device through a single target signal line, wherein the single target signal line connects an input/output port of the device to an input/output port of the second device and excludes transmission of a clock signal.
9 . The device of claim 8 , wherein:
when a bit of data in the at least one target data packet is binary data 0, in a data period, a signal waveform corresponding to the bit of data comprises a signal rising edge and a signal falling edge; and
when a bit of data in the at least one target data packet is binary data 1, in a data period, a signal waveform corresponding to the bit of data comprises a signal rising edge and does not comprise a signal falling edge.
10 . The device of claim 8 , wherein the multi-bit identification data comprises multi-bit first identification data and multi-bit second identification data, and the multi-bit first identification data is different from the multi-bit second identification data; and
the preset format comprises: each target data packet of the at least one target data packet comprises a data packet header and at least one data segment, the data packet header of a respective target data packet comprises consecutive multi-bit first identification data and at least one bit of the multi-bit second identification data, each data segment in the at least one data segment of the respective target data packet comprises at least one bit of the target data and at least one bit of the multi-bit second identification data, and a quantity of the consecutive multi-bit first identification data in the data packet header of the respective target data packet is greater than a quantity of the at least one bit of the target data in each data segment of the respective target data packet.
11 . A system, comprising:
a first device; and
a second device;
wherein the first device is configured to:
construct multi-bit target data into at least one target data packet based on a preset format, wherein each target data packet in the at least one target data packet comprises at least one bit of the multi-bit target data and multi-bit identification data, and the multi-bit identification data in each target data packet indicates a quantity and locations of target data in a corresponding target data packet;
pack each bit of data in the at least one target data packet in a manner that different data has different signal waveforms after being packed, to obtain packed data; and
sequentially send each bit of the packed data to the second device through a single target signal line, wherein the single target signal line connects an input/output port of the first device to an input/output port of the second device and excludes transmission of a clock signal.
12 . The system of claim 11 , wherein:
when a bit of data in the at least one target data packet is binary data 0, in a data period, a signal waveform corresponding to the bit of data comprises a signal rising edge and a signal falling edge; and
when a bit of data in the at least one target data packet is binary data 1, in a data period, a signal waveform corresponding to the bit of data comprises a signal rising edge and does not comprise a signal falling edge.
13 . The system of claim 11 , wherein the multi-bit identification data comprises multi-bit first identification data and multi-bit second identification data, and the multi-bit first identification data is different from the multi-bit second identification data; and
wherein the preset format comprises: each target data packet in the at least one target data packet comprises a data packet header and at least one data segment, the data packet header of a respective target data packet comprises consecutive multi-bit first identification data and at least one bit of the multi-bit second identification data, each data segment in the at least one data segment of the respective target data packet comprises at least one bit of the target data and at least one bit of the multi-bit second identification data, and a quantity of the consecutive multi-bit first identification data in the data packet header of the respective target data packet is greater than a quantity of the at least one bit of the target data in each data segment of the respective target data packet.
14 . The system of claim 11 , wherein the second device is configured to:
receive, through the single target signal line, each bit of the packed data sent by the first device, and determining each bit of the data based on a signal waveform corresponding to each bit of the packed data, to obtain the at least one target data packet; and
parse the at least one target data packet based on the preset format, to obtain the multi-bit target data.
15 . The system of claim 14 , wherein the second device is configured to:
when the second device detects that the signal waveform corresponding to each bit of the packed data is on a rising edge, start timing, and collect data at a preset moment;
when the second device collects a low level, determine the collected data is binary data 0; and
when the second device collects a high level, determine the collected data is binary data 1.
16 . The system of claim 11 , wherein the system is applied to determining whether the single target signal line is correctly connected, the multi-bit target data comprises identification information of the single target signal line, the identification information of the single target signal line indicates the single target signal line, and the second device is configured to:
determine whether the identification information of the single target signal line comprised in the multi-bit target data matches preset information;
when the identification information of the single target signal line matches the preset information, determine that the single target signal line is correctly connected; and
when the identification information of the single target signal line does not match the preset information, determine that the single target signal line is incorrectly connected.
17 . The system of claim 11 , wherein the first device comprises a first chip, and the second device comprises a second chip.
18 . The system of claim 17 , wherein the first device and the second device each comprise a complex programming logic device (CPLD) chip.
19 . The system of claim 18 , wherein internal master clocks of the first device and the second device are the same.
20 . The system of claim 18 , wherein a first working clock of the first device is equal to a second working clock of the second device in a frequency multiplication manner, and the first working clock and the second working clock are used for communication between the first device and the second device.