Disclosure of Invention
The invention aims to provide an SPI data transmission method and device, which can improve the data transmission efficiency on the premise of ensuring the integrity of data transmission.
In order to solve the above technical problem, an embodiment of the present invention provides an SPI data transmission method, including:
distributing data to be sent to N data sending buffer areas, wherein N is an integer larger than 1;
sending the data to be sent of each data sending buffer area to a data receiving buffer area corresponding to the data sending buffer area so that a receiving end screens the data from at least one data receiving buffer area to obtain a complete data consistent with the data to be sent; wherein, the data sending buffer and the data receiving buffer are both circular buffers.
Before distributing the data to be transmitted to the N data transmission buffers, the method further includes:
generating a check code for each frame of data to be transmitted, and adding a frame number to each frame of data, wherein the frame number is represented by M, and M is an integer greater than 0;
after the data to be sent in each data sending buffer is sent to the data receiving buffer corresponding to the data sending buffer, the method further includes:
so that the receiving end checks the check code of each frame data received by each data receiving buffer and discards the data frame which fails the check.
The enabling the receiving end to screen data from at least one data receiving buffer includes: so that the receiving end takes out the buffered data frame from the first data receiving buffer, and then screens the data according to the mode of taking out the missing data frame in the N-1 data receiving buffer from the Nth data receiving buffer.
At the receiving end, screening data from at least one data receiving buffer, further comprising: when the receiving end takes out the data from the previous data receiving buffer and skips the next data receiving buffer, the receiving end clears all the data in the previous data receiving buffer; and when the receiving end can not obtain a complete data consistent with the data to be sent after screening the data from the first data receiving buffer area to the Nth data receiving buffer area in sequence, repeating the steps until obtaining a complete data consistent with the data to be sent.
And each frame data of the data sending buffer area and the data receiving buffer area is arranged according to the ascending sequence of the frame number.
In order to solve the same technical problem, an embodiment of the present invention further provides an SPI data transmission method, including: receiving data to be sent from N data sending buffer areas of a sending end, and caching the data to be sent in a data receiving buffer area corresponding to each data sending buffer area;
screening data from at least one data receiving buffer area so as to obtain a complete data consistent with the data to be sent; wherein, the data sending buffer and the data receiving buffer are both circular buffers.
The check code of each frame of data received by each data receiving buffer is checked, and the data frames failing the check are discarded.
The screening data from at least one data receiving buffer comprises: and taking out the buffered data frames from the first data receiving buffer, and then screening the data in a mode of taking out the missing data frames in the (N-1) th data receiving buffer from the Nth data receiving buffer.
Screening data from the at least one data receive buffer, further comprising: when the previous data receiving buffer zone takes out data and skips the next data receiving buffer zone, all the data of the previous data receiving buffer zone is cleared; and when the data are screened from the first data receiving buffer area to the Nth data receiving buffer area in sequence, and a complete data consistent with the data to be sent cannot be obtained, repeating the steps until the complete data consistent with the data to be sent is obtained.
As an improvement of the foregoing solution, another embodiment of the present invention correspondingly provides an SPI data transmission device, including:
the data distribution unit is used for distributing data to be sent to N data sending buffer areas, wherein N is an integer larger than 1;
the data sending unit is used for sending the data to be sent of each data sending buffer area to the data receiving buffer area corresponding to the data sending buffer area so that the receiving end screens the data from at least one data receiving buffer area to obtain a complete data consistent with the data to be sent; wherein, the data sending buffer and the data receiving buffer are both circular buffers.
The device comprises a preprocessing unit, a detection unit and a processing unit, wherein the preprocessing unit is used for generating a check code for each frame of data to be sent and adding a frame number to each frame of data, the frame number is represented by M, and M is an integer greater than 0;
the data sending unit is further configured to enable the receiving end to check the check code of each frame of data received by each data receiving buffer, and discard the data frames failing in checking.
As an improvement of the foregoing solution, another embodiment of the present invention correspondingly provides an SPI data transmission device, including:
the data receiving unit is used for receiving data to be sent from N data sending buffer areas of the sending end and caching the data to be sent in a data receiving buffer area corresponding to each data sending buffer area;
the data screening unit is used for screening data from at least one data receiving buffer area so as to obtain a complete data consistent with the data to be sent; wherein, the data sending buffer and the data receiving buffer are both circular buffers.
And the data checking unit is used for checking the check code of each frame of data received by each data receiving buffer area and discarding the data frames which fail to be checked.
Compared with the prior art, the SPI data transmission method and the SPI data transmission device have the advantages that a double-buffer mechanism is realized by adopting N data sending buffer areas and N data receiving buffer areas, and a receiving end is enabled to screen data from at least one data receiving buffer area until complete data consistent with the data to be transmitted is obtained, so that the integrity of data transmission is guaranteed; when the data packet loss occurs, the packet loss data can be screened from the standby data receiving buffer area, so that the problem of low efficiency caused by adopting a response mechanism under the packet loss condition in the prior art is solved, and the data transmission efficiency is further improved.
Another embodiment of the present invention provides a terminal device, including a processor, a memory, and a computer program stored in the memory and configured to be executed by the processor, wherein the processor, when executing the computer program, implements the SPI data transmission method according to any one of the above.
Another embodiment of the present invention provides a server, including:
one or more processors;
storage means for storing one or more programs;
when executed by the one or more processors, cause the one or more processors to implement the SPI data transmission method as in any one of the above.
Another embodiment of the present invention provides a computer-readable storage medium, which includes a stored computer program, where when the computer program runs, the apparatus where the computer-readable storage medium is located is controlled to execute any one of the SPI data transmission methods described above.
Detailed Description
The technical solutions in the embodiments of the present invention will be clearly and completely described below with reference to the drawings in the embodiments of the present invention, and it is obvious that the described embodiments are only a part of the embodiments of the present invention, and not all of the embodiments. All other embodiments, which can be derived by a person skilled in the art from the embodiments given herein without making any creative effort, shall fall within the protection scope of the present invention.
Referring to fig. 1, 3 and 4, the method comprises:
s001: distributing data to be sent to N data sending buffer areas, wherein N is an integer larger than 1;
s002: sending the data to be sent of each data sending buffer area to a data receiving buffer area corresponding to the data sending buffer area so that a receiving end screens the data from at least one data receiving buffer area to obtain a complete data consistent with the data to be sent; the data sending buffer area and the data receiving buffer area are both circular buffer areas, wherein the circular buffer areas are used for sending, receiving, checking and the like of data in a first-in first-out mode.
In this embodiment, before step S001, a check code is generated for each frame of data to be transmitted, so that the receiving end checks whether the received data is correct according to the check code; and adding a frame number to each frame of data, wherein the frame number is represented by M, and M is an integer greater than 0.
In this embodiment, the step S002 further includes: after the data to be sent in each data sending buffer area is sent to the data receiving buffer area corresponding to the data sending buffer area, the receiving end verifies the check code of each frame of data received by each data receiving buffer area according to the ascending sequence of the frame number, and discards the data frame which fails in verification.
In this embodiment, the step S002 further includes: the receiving end takes out the buffered data frame from the first data receiving buffer area, and then screens the data according to the mode of taking out the missing data frame in the N-1 th data receiving buffer area from the Nth data receiving buffer area, so as to screen the lost data in the next data receiving buffer area when the lost packet occurs, thereby realizing the integrity of data transmission, and no response mechanism is needed, thereby improving the efficiency of data transmission.
In this embodiment, the step S002 further includes: when the receiving end takes out the data from the previous data receiving buffer and skips the next data receiving buffer, all the data in the previous data receiving buffer is removed to realize the circular buffer, thereby ensuring the integrity of the data transmission; when the receiving end can not obtain a complete data consistent with the data to be sent after screening the data from the first data receiving buffer area to the Nth data receiving buffer area in sequence, the steps are repeatedly executed until a complete data consistent with the data to be sent is obtained, so that the completeness of data transmission is ensured, and the efficiency of data transmission is further improved by utilizing a double-buffer mechanism.
In this embodiment, each frame data of the data sending buffer and the data receiving buffer is arranged in an ascending order according to the frame number, so as to realize the orderly data transmission process, thereby improving the transmission efficiency.
The SPI data transmission method provided by the embodiment of the invention has the following beneficial effects: the method comprises the steps that data to be sent are distributed to N data sending buffer areas, so that a mode that the N paths carry out SPI data transmission is achieved, and the data sending buffer areas play a buffering role, and therefore the data transmission efficiency is improved; meanwhile, the receiving end screens data from at least one data receiving buffer area to obtain a complete data consistent with the data to be transmitted, so that the completeness of data transmission is ensured, and the buffering effect is realized by setting N data receiving buffer areas, so that the efficiency of data transmission is further improved.
Referring to fig. 2, 3 and 5, the method comprises:
s011: receiving data to be sent from N data sending buffer areas of a sending end, and caching the data to be sent in a data receiving buffer area corresponding to each data sending buffer area;
s012: screening data from at least one data receiving buffer area so as to obtain a complete data consistent with the data to be sent; wherein, the data sending buffer and the data receiving buffer are both circular buffers.
In this embodiment, a double buffering mechanism is implemented by the data sending buffer and the data receiving buffer to implement a buffering function, thereby improving the efficiency of the data transmission process; and screening data from at least one of the N data receiving buffers to obtain a complete data consistent with the data to be sent, so as to ensure the integrity of data transmission, and further improve the efficiency of data transmission on the premise of ensuring the integrity of data transmission.
In this embodiment, the check code of each frame of data received by each data receiving buffer is checked, and the data frame failing to be checked is discarded, so as to ensure that the received data is consistent with the data to be transmitted.
In this embodiment, the step S012 further includes: taking out the buffered data frame from the first data receiving buffer area, and then screening the data according to the mode of taking out the missing data frame in the (N-1) th data receiving buffer area from the Nth data receiving buffer area; when packet loss occurs, the packet loss data can be screened in the next data receiving buffer area, so that the integrity of data transmission is realized, a response mechanism is not required, and the efficiency of data transmission is improved.
In this embodiment, the step S012 further includes: when the previous data receiving buffer zone takes out data and skips the next data receiving buffer zone, all the data of the previous data receiving buffer zone is cleared; when data are screened from the first data receiving buffer area to the Nth data receiving buffer area in sequence, and a complete data consistent with the data to be sent still can not be obtained, the steps are repeatedly executed until a complete data consistent with the data to be sent is obtained, so that the completeness of data transmission is ensured, and the efficiency of data transmission is further improved by utilizing a double-buffer mechanism.
The SPI data transmission method provided by the embodiment of the invention has the following beneficial effects: the method comprises the steps that data to be transmitted sent by N data sending buffer areas of a sending end are received, so that the mode of SPI data transmission through a plurality of paths is realized, when packet loss occurs in a main path in the plurality of paths, general selection of the packet loss data can be performed from a standby path, and therefore the data transmission efficiency is improved on the premise that the data transmission is complete; and the data sending buffer zone plays a buffering role, and the efficiency of data transmission is further improved.
Referring to fig. 6, a flow chart of an SPI data transmission device according to an embodiment of the present invention includes:
the preprocessing unit 61 is configured to generate a check code for each frame of data to be transmitted, and add a frame number to each frame of data, where the frame number is represented by M, and M is an integer greater than 0.
A data distributing unit 62, configured to distribute data to be sent to N data sending buffers, where N is an integer greater than 1.
A data sending unit 63, configured to send the data to be sent in each data sending buffer to a data receiving buffer corresponding to the data sending buffer, so that the receiving end screens data from at least one data receiving buffer, thereby obtaining a complete data that is consistent with the data to be sent; wherein, the data sending buffer and the data receiving buffer are both circular buffers.
The data sending unit 63 is further configured to enable the receiving end to check the check code of each frame of data received by each data receiving buffer, and discard the data frame that fails in checking.
The SPI data transmission device provided by the embodiment of the invention has the following beneficial effects: generating a check code for each frame of the data to be transmitted and adding a frame serial number through the processing unit 61, so that the receiving end carries out sequential verification on the received data according to the sequence of the frame serial numbers to verify that the received data is consistent with the data to be transmitted, thereby ensuring the accuracy and the integrity of the data; meanwhile, data are distributed to N data sending buffer areas through the data distribution unit to achieve multi-path data transmission, data are screened from the data receiving buffer areas in at least one path through the data sending unit, lost data can be screened from the data receiving buffer areas in other paths when packet loss occurs, the data are not required to be fed back to a sender to resend the lost data, and therefore the data transmission efficiency is improved.
Referring to fig. 7, an SPI data transmission device according to another embodiment of the present invention includes:
a data receiving unit 71, configured to receive data to be sent from N data sending buffers at a sending end, and buffer the data to be sent in a data receiving buffer corresponding to each data sending buffer;
a data screening unit 72, configured to screen data from at least one data receiving buffer, so as to obtain a complete data that is consistent with the data to be sent; wherein, the data sending buffer and the data receiving buffer are both circular buffers.
And a data checking unit 73 for checking the check code of each frame of data received by each data receiving buffer and discarding the data frames failing the checking.
The SPI data transmission device provided by the embodiment of the invention has the following beneficial effects: the data receiving unit receives data sent by N data sending buffer areas of a sending end to realize a multi-channel data transmission mode, and buffers the data in the data sending buffer area and the data receiving buffer area to realize a buffering effect, so that the data transmission efficiency is improved; meanwhile, data screening is carried out on the data receiving buffer area in at least one of the multiple channels through the data screening unit so as to obtain a piece of complete data consistent with the data to be sent, and when packet loss occurs, packet loss data can be screened from other data receiving buffer areas, so that a response mechanism is reduced, and the efficiency of data transmission can be improved on the premise of ensuring the integrity of data transmission.
An embodiment of the present invention further provides a terminal device, which includes a processor, a memory, and a computer program stored in the memory and configured to be executed by the processor, where the processor implements the SPI data transmission method according to any one of the above descriptions when executing the computer program. Such as step S001 shown in fig. 1. Alternatively, the processor implements the functions of the modules/units in the above device embodiments, such as the data transmission unit, when executing the computer program.
Illustratively, the computer program may be partitioned into one or more modules/units that are stored in the memory and executed by the processor to implement the invention. The one or more modules/units may be a series of computer program instruction segments capable of performing specific functions, which are used for describing the execution process of the computer program in the SPI data transmission terminal device.
The SPI data transmission terminal equipment can be computing equipment such as a desktop computer, a notebook computer, a palm computer and an intelligent tablet. The SPI data transmission terminal equipment can comprise, but is not limited to, a processor and a memory. Those skilled in the art will appreciate that the above components are merely examples of the SPI data transmission terminal device, and do not constitute a limitation of the SPI data transmission terminal device, and may include more or less components than the above, or combine some components, or different components, for example, the SPI data transmission terminal device may further include an input-output device, a network access device, a bus, and the like.
An embodiment of the present invention further provides a server, including:
one or more processors;
storage means for storing one or more programs;
when executed by the one or more processors, cause the one or more processors to implement the SPI data transmission method as in any one of the above.
The Processor may be a Central Processing Unit (CPU), other general purpose Processor, a Digital Signal Processor (DSP), an Application Specific Integrated Circuit (ASIC), an off-the-shelf Programmable Gate Array (FPGA) or other Programmable logic device, discrete Gate or transistor logic, discrete hardware components, etc. The general-purpose processor may be a microprocessor or the processor may be any conventional processor, etc., and the processor is a control center of the SPI data transmission terminal device and connects various parts of the entire SPI data transmission device by using various interfaces and lines.
The storage device may be configured to store the computer program and/or module, and the processor may implement various functions of the voice endpoint detection apparatus by running or executing the computer program and/or module stored in the memory and calling data stored in the memory. The storage device may mainly include a storage program area and a storage data area, wherein the storage program area may store an operating system, an application program (such as a sound playing function, an image playing function, etc.) required by at least one function, and the like; the storage data area may store data (such as audio data, a phonebook, etc.) created according to the use of the cellular phone, and the like. In addition, the memory may include high speed random access memory, and may also include non-volatile memory, such as a hard disk, a memory, a plug-in hard disk, a Smart Media Card (SMC), a Secure Digital (SD) Card, a Flash memory Card (Flash Card), at least one magnetic disk storage device, a Flash memory device, or other volatile solid state storage device.
Wherein, the module/unit integrated with the SPI data transmission terminal device may be stored in a computer readable storage medium if it is implemented in the form of a software functional unit and sold or used as an independent product. Based on such understanding, all or part of the flow of the method according to the embodiments of the present invention may also be implemented by a computer program, which may be stored in a computer-readable storage medium, and when the computer program is executed by a processor, the steps of the method embodiments may be implemented. Wherein the computer program comprises computer program code, which may be in the form of source code, object code, an executable file or some intermediate form, etc. The computer-readable medium may include: any entity or device capable of carrying the computer program code, recording medium, usb disk, removable hard disk, magnetic disk, optical disk, computer Memory, Read-only Memory (ROM), Random Access Memory (RAM), electrical carrier wave signals, telecommunications signals, software distribution medium, etc. It should be noted that the computer readable medium may contain content that is subject to appropriate increase or decrease as required by legislation and patent practice in jurisdictions, for example, in some jurisdictions, computer readable media does not include electrical carrier signals and telecommunications signals as is required by legislation and patent practice.
It should be noted that the above-described device embodiments are merely illustrative, where the units described as separate parts may or may not be physically separate, and the parts displayed as units may or may not be physical units, may be located in one place, or may be distributed on multiple network units. Some or all of the modules may be selected according to actual needs to achieve the purpose of the solution of the present embodiment. In addition, in the drawings of the embodiment of the apparatus provided by the present invention, the connection relationship between the modules indicates that there is a communication connection between them, and may be specifically implemented as one or more communication buses or signal lines. One of ordinary skill in the art can understand and implement it without inventive effort.
While the foregoing is directed to the preferred embodiment of the present invention, it will be understood by those skilled in the art that various changes and modifications may be made without departing from the spirit and scope of the invention.