CN107766265B - Serial port data extraction method supporting fixed-length packets, variable-length packets and mixed packets - Google Patents

Serial port data extraction method supporting fixed-length packets, variable-length packets and mixed packets Download PDF

Info

Publication number
CN107766265B
CN107766265B CN201710796835.6A CN201710796835A CN107766265B CN 107766265 B CN107766265 B CN 107766265B CN 201710796835 A CN201710796835 A CN 201710796835A CN 107766265 B CN107766265 B CN 107766265B
Authority
CN
China
Prior art keywords
packet
length
data
serial port
packets
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Active
Application number
CN201710796835.6A
Other languages
Chinese (zh)
Other versions
CN107766265A (en
Inventor
回永利
刘武
曹新强
杨佳君
侯国超
何昊
曹井连
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Xian Flight Automatic Control Research Institute of AVIC
Original Assignee
Xian Flight Automatic Control Research Institute of AVIC
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Xian Flight Automatic Control Research Institute of AVIC filed Critical Xian Flight Automatic Control Research Institute of AVIC
Priority to CN201710796835.6A priority Critical patent/CN107766265B/en
Publication of CN107766265A publication Critical patent/CN107766265A/en
Application granted granted Critical
Publication of CN107766265B publication Critical patent/CN107766265B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F13/00Interconnection of, or transfer of information or other signals between, memories, input/output devices or central processing units
    • G06F13/10Program control for peripheral devices
    • G06F13/12Program control for peripheral devices using hardware independent of the central processor, e.g. channel or peripheral processor
    • G06F13/124Program control for peripheral devices using hardware independent of the central processor, e.g. channel or peripheral processor where hardware is a sequential transfer control unit, e.g. microprocessor, peripheral processor or state-machine
    • G06F13/126Program control for peripheral devices using hardware independent of the central processor, e.g. channel or peripheral processor where hardware is a sequential transfer control unit, e.g. microprocessor, peripheral processor or state-machine and has means for transferring I/O instructions and statuses between control unit and main processor
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F13/00Interconnection of, or transfer of information or other signals between, memories, input/output devices or central processing units
    • G06F13/38Information transfer, e.g. on bus
    • G06F13/382Information transfer, e.g. on bus using universal interface adapter
    • G06F13/387Information transfer, e.g. on bus using universal interface adapter for adaptation of different data processing systems to different peripheral devices, e.g. protocol converters for incompatible systems, open system
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F13/00Interconnection of, or transfer of information or other signals between, memories, input/output devices or central processing units
    • G06F13/38Information transfer, e.g. on bus
    • G06F13/42Bus transfer protocol, e.g. handshake; Synchronisation
    • G06F13/4282Bus transfer protocol, e.g. handshake; Synchronisation on a serial bus, e.g. I2C bus, SPI bus

Landscapes

  • Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Computer Hardware Design (AREA)
  • Microelectronics & Electronic Packaging (AREA)
  • Data Exchanges In Wide-Area Networks (AREA)

Abstract

The invention relates to a general method for extracting a serial port data packet, which supports three frame formats of a fixed length packet, a variable length packet and a mixed packet. The scheme used by the invention is as follows: and detecting whether the transmission of the serial port data packet is finished or not based on an idle trigger mechanism, and extracting the required serial port data packet from the received serial port data according to a configured packet format when the transmission is judged to be finished.

Description

Serial port data extraction method supporting fixed-length packets, variable-length packets and mixed packets
Technical Field
The invention belongs to the field of embedded system serial port data processing, and relates to a serial port data extraction method supporting fixed-length packets, variable-length packets and mixed packets.
Background
In embedded applications, data interaction between devices is often performed in the form of serial data packets. Generally, a receiving party receives a serial port data packet in the following two ways: the CPU of the embedded system integrates a serial port controller with an idle interrupt characteristic, when the transmission of a data packet is finished, the interrupt is triggered, and an interrupt service program reads data in the controller; the embedded system integrates a single serial port coprocessor which can be in the forms of FPGA, SOC, special IC and the like, the package format is set through software, the coprocessor automatically processes serial port data and transmits the data conforming to the package format to a CPU for further processing.
The two data packet receiving modes have special requirements on hardware, so that the material cost is increased, and other influences such as power consumption and the like are brought to later-stage application. The invention completes the data packet receiving through software, and the software dynamically configures the packet format to complete the rapid deployment of the system.
Disclosure of Invention
The invention aims to provide a method for extracting a serial port data packet, which finishes the receiving of the serial port data packet through the dynamic configuration of software, and the packet format supports a fixed-length packet, a variable-length packet and a mixed packet.
The technical scheme of the invention is as follows: a serial port data extraction method supporting fixed-length packets, variable-length packets and mixed packets comprises the following steps:
step 1, initial configuration;
step 2, checking port numbers: when the input port number is in the system serial port list, continuing the subsequent operation; otherwise, returning an abnormal code;
step 3, serial port data overflow: when the system cannot process the data in the FIFO of the serial port controller in time, the data overflow occurs, FIFO data clearing operation is executed, and overflow flag words in the serial port controller are cleared;
step 4, judging whether the data count in the FIFO changes, if the count value is increased, backing up the count value, counting and resetting the counter; otherwise, the counter is accumulated by 1;
step 5, judging whether to be idle triggered: the timer is overtime, and the data count of the FIFO is greater than 0; if the conditions are met, the data transmission is judged to be finished, the data in the FIFO is in a state of being capable of being extracted and further processed, and the internal interruption of the CPU is triggered; if the timer is overtime but the FIFO count value is 0, setting the value of the timer as 'threshold value + 1';
and 6, resetting the timer, and finishing the data packet extraction according to the set packet format.
The method for extracting the serial port data supporting the fixed-length packet, the variable-length packet and the mixed packet comprises the following steps in the step 1:
step 1.1, configuring a packet format and a serial port channel number, wherein the packet format comprises a fixed-length packet, a variable-length packet and a mixed packet;
step 1.2, configuring the length of a packet head, the length of a packet tail and the total length;
step 1.3, configuring the header characters, the tail characters and the overtime threshold.
The method for extracting serial port data supporting fixed-length packets, variable-length packets and mixed packets comprises the following specific steps, when the packet format in step 6 is the fixed-length packet, step 6 specifically comprises the following steps:
6.1a, reading all data in the FIFO of the serial port controller to a software buffer area;
6.2a according to the set packet header, searching the packet header in the software buffer area, when the packet header is searched, returning the software buffer area index of the first packet header, and executing the step 3; if the packet header is not found, returning an abnormal code;
6.3a, judging the data length conformity, if the data length in the software buffer area is less than the packet length, returning an abnormal code; and if the data length in the software buffer area meets the condition, sequentially reading the data in the software buffer area according to the specified length, and returning the actually read data length and the data packet.
The method for extracting serial port data supporting fixed-length packets, variable-length packets and mixed packets comprises the following specific steps in step 6 when the packet format is the variable-length packet:
6.1b, reading all data in the FIFO of the serial port controller to a software buffer area;
6.2b according to the set packet header, searching the packet header in the software buffer area, when the packet header is searched, returning the software buffer area index of the first packet header, and executing the step 3; if the packet header is not found, returning an abnormal code;
6.3b, searching the packet tail backwards from the position of the packet head in the software buffer area according to the set packet tail, returning the software buffer area index of the first packet tail when the packet tail is searched, and executing the step 4; if the packet tail is not found, returning an abnormal code;
6.4b read all data between the header and the trailer in the software buffer, and return the actual length and all data read.
The serial port data extraction method supporting the fixed-length packet, the variable-length packet and the mixed packet comprises the following steps, in step 6, the packet format is the mixed packet, the mixed packet is composed of a plurality of variable-length packets, and the step 6 specifically comprises the following steps:
6.1c, reading all data in the FIFO of the serial port controller to a software buffer area;
and 6.2c, sequentially extracting the variable length packets from the software buffer according to the defined variable length packet sequence and the data extraction steps of the variable length packets, generating corresponding variable length packet updating marks, and setting the variable length packet updating marks if a certain variable length packet is extracted.
The invention has the beneficial effects that: the invention provides a serial port data packet receiving scheme with the characteristics of high real-time performance, strong universality, outstanding flexibility and the like for embedded system design, can be applied to occasions with variable external cross-linked data protocols, and completes serial port receiving reconstruction through dynamic configuration. Meanwhile, the hardware cost is reduced, and the overall power consumption of the embedded system can also be reduced.
Drawings
FIG. 1 "Idle trigger" process flow;
FIG. 2 is a main flow of data reception;
FIG. 3 is a fixed length packet data reception flow;
FIG. 4 is a variable length packet data receiving flow;
fig. 5 shows a flow of hybrid packet data reception.
Detailed Description
The invention has the following constraints on the packet format of the serial port controller and the communication:
1) the "idle trigger" mechanism: and setting a threshold of idle time as Ts, and after serial port data is detected, if new data is not received within the Ts time of the data bus, judging that one-time data packet transmission is finished and triggering internal interruption of the CPU. And after idle triggering, reading the data in the serial port FIFO by the interrupt service program, finishing the extraction of a data packet (any one of a fixed-length packet, a variable-length packet and a mixed packet) according to a configured packet format, returning the extracted data if the extraction is successful, and otherwise returning an abnormal code.
2) A fixed-length bag: the data frame is composed of a frame header of fixed length and data of fixed length.
3) A variable-length bag: the data frame is fully proved by a frame head with fixed length, a frame tail with fixed length and data, and the data length between the frame head and the frame tail is variable.
4) Mixing and packaging: the updating period of the variable-length packets can be different. The length of the hybrid package is not fixed.
5) And (3) fixing the length of the packet, setting the packet format to be a fixed-length packet during initialization, and setting according to the actual length.
6) And (3) changing the length of the packet, setting the format of the packet into a variable length packet during initialization, and setting the lengths of the packet head and the packet tail according to the actual length, wherein the sum of the lengths of the packet head and the packet tail is used as the minimum packet length.
7) And (3) setting the packet header of the fixed-length packet, setting the packet format as the fixed-length packet during initialization, and setting the length of the packet header and the characters of each byte of the packet header.
8) And (3) changing the packet header, setting the packet format into a changed-length packet during initialization, and setting the length of the packet header and the character of each byte of the packet header.
9) And (3) changing the packet tail of the variable-length packet, setting the packet format into the variable-length packet during initialization, and setting the length of the packet tail and the character of each byte of the packet tail.
10) Software buffer area: the minimum length of a section of space opened in the RAM is consistent with the size of the FIFO of the serial port controller.
11) Hardware requirements: the embedded system of the integrated serial port controller, the serial port controller contains receiving FIFO of certain size, the system adopts the regular inquiry way to gather the serial port data, the inquiry cycle is Ts.
12) Packet 1, the first variable length packet in the hybrid packet sequence set at initialization.
13) And a data packet N, the last variable-length packet in the set mixed packet sequence during initialization.
The invention is described in detail below with reference to the drawings of the specification, and the main flow of idle triggering is shown in fig. 1 and fig. 2.
1. Initial configuration:
1.1 configuration packet format (fixed length packet, variable length packet, mixed packet) and serial port channel number.
1.2 configuring the length of the header, the length of the tail and the total length (including the header and the tail).
1.3 configuring header characters, tail characters and overtime threshold.
2. Checking a port number: when the input port number is in the system serial port list, continuing the subsequent operation; otherwise, an exception code is returned.
3. And (3) serial port data overflow: when the system can not process the data in the FIFO of the serial port controller in time, the data overflow can occur, the FIFO data clearing operation is executed, and the overflow flag word in the serial port controller is cleared.
4. Judging whether the data count in the FIFO changes, if the count value is increased, backing up the count value, counting and resetting the counter; otherwise the counter is incremented by 1.
5. Judging whether to be idle triggered: the timer times out and the data count of the FIFO is greater than 0. If the conditions are met, judging that the data transmission is finished, extracting the data in the FIFO for further processing, and triggering the internal interruption of the CPU; if the timer times out, but the FIFO count value is 0, the value of the timer is set to "threshold + 1".
6. The timer is reset, and data packet extraction is completed according to the following steps according to the set packet formats (fixed length packet, variable length packet and mixed packet).
Extracting fixed length bag, as shown in figure 3:
6.1a reading all data in the serial port controller FIFO to the software buffer area.
6.2a, searching the packet header in the software buffer area according to the set packet header, returning the software buffer area index of the first packet header when the packet header is searched, and executing the step 6.3 a; if the packet header is not found, returning an abnormal code.
6.3a, judging the data length conformity, if the data length in the software buffer area is less than the packet length, returning an abnormal code; and if the data length in the software buffer area meets the condition, sequentially reading the data in the software buffer area according to the specified length, and returning the actually read data length and the data packet.
Variable length packet extraction, see figure 4:
6.1b, reading all data in the serial port controller FIFO to a software buffer area.
6.2b, searching the packet header in the software buffer area according to the set packet header, returning the software buffer area index of the first packet header when the packet header is searched, and executing the step 6.3 b; if the packet header is not found, returning an abnormal code.
6.3b, searching the packet tail backwards from the position of the packet head in the software buffer area according to the set packet tail, returning the software buffer area index of the first packet tail when the packet tail is searched, and executing the step 6.4 b; and if the packet tail is not found, returning an exception code.
6.4b read all data between the header and the trailer in the software buffer, and return the actual length and all data read.
Mixed package extraction, see figure 5:
6.1c, reading all data in the serial port controller FIFO to a software buffer area.
And 6.2c, sequentially extracting the variable-length packets from the defined variable-length packet sequence (the data packets 1 to N) in the software buffer according to the data extraction mode of the variable-length packets, generating corresponding variable-length packet updating marks, and setting the variable-length packet updating marks if a certain variable-length packet is extracted.

Claims (5)

1. A serial port data extraction method supporting fixed-length packets, variable-length packets and mixed packets is characterized by comprising the following steps:
step 1, initial configuration;
step 2, checking port numbers: when the input port number is in the system serial port list, continuing the subsequent operation; otherwise, returning an abnormal code;
step 3, serial port data overflow: when the system cannot process the data in the FIFO of the serial port controller in time, the data overflow occurs, FIFO data clearing operation is executed, and overflow flag words in the serial port controller are cleared;
step 4, judging whether the data count in the FIFO changes, if the count value is increased, backing up the count value, counting and resetting the counter; otherwise, the counter is accumulated by 1;
step 5, judging whether to be idle triggered: the timer is overtime, and the data count of the FIFO is greater than 0; if the conditions are met, the data transmission is judged to be finished, the data in the FIFO is in a state of being capable of being extracted and further processed, and the internal interruption of the CPU is triggered; if the timer is overtime but the FIFO count value is 0, setting the value of the timer as 'threshold value + 1';
and 6, resetting the timer, and finishing the data packet extraction according to the set packet format.
2. The method for extracting serial port data supporting fixed-length packets, variable-length packets and mixed packets according to claim 1, wherein the step 1 comprises the following steps:
step 1.1, configuring a packet format and a serial port channel number, wherein the packet format comprises a fixed-length packet, a variable-length packet and a mixed packet;
step 1.2, configuring the length of a packet head, the length of a packet tail and the total length;
step 1.3, configuring the header characters, the tail characters and the overtime threshold.
3. The method for extracting serial port data supporting fixed-length packets, variable-length packets and mixed packets according to claim 2, wherein when the packet format in step 6 is the fixed-length packet, step 6 specifically includes the following steps:
6.1a, reading all data in the FIFO of the serial port controller to a software buffer area;
6.2a according to the set packet header, searching the packet header in the software buffer area, when the packet header is searched, returning the software buffer area index of the first packet header, and executing the step 3; if the packet header is not found, returning an abnormal code;
6.3a, judging the data length conformity, if the data length in the software buffer area is less than the packet length, returning an abnormal code; and if the data length in the software buffer area meets the condition, sequentially reading the data in the software buffer area according to the specified length, and returning the actually read data length and the data packet.
4. The method for extracting serial port data supporting fixed-length packets, variable-length packets and mixed packets according to claim 2, wherein when the packet format in step 6 is a variable-length packet, step 6 specifically includes the following steps:
6.1b, reading all data in the FIFO of the serial port controller to a software buffer area;
6.2b according to the set packet header, searching the packet header in the software buffer area, when the packet header is searched, returning the software buffer area index of the first packet header, and executing the step 3; if the packet header is not found, returning an abnormal code;
6.3b, searching the packet tail backwards from the position of the packet head in the software buffer area according to the set packet tail, returning the software buffer area index of the first packet tail when the packet tail is searched, and executing the step 4; if the packet tail is not found, returning an abnormal code;
6.4b read all data between the header and the trailer in the software buffer, and return the actual length and all data read.
5. The method for extracting serial port data supporting fixed-length packets, variable-length packets and mixed packets according to claim 2, wherein the packet format in step 6 is a mixed packet, the mixed packet is composed of a plurality of variable-length packets, and step 6 specifically includes the following steps:
6.1c, reading all data in the FIFO of the serial port controller to a software buffer area;
6.2c, according to the defined variable length packet sequence, sequentially extracting the variable length packets from the software buffer according to the following data extraction steps of the variable length packets, generating corresponding variable length packet updating marks, and if a certain variable length packet is extracted, setting the variable length packet updating mark;
6.1b, reading all data in the FIFO of the serial port controller to a software buffer area;
6.2b according to the set packet header, searching the packet header in the software buffer area, when the packet header is searched, returning the software buffer area index of the first packet header, and executing the step 3; if the packet header is not found, returning an abnormal code;
6.3b, searching the packet tail backwards from the position of the packet head in the software buffer area according to the set packet tail, returning the software buffer area index of the first packet tail when the packet tail is searched, and executing the step 4; if the packet tail is not found, returning an abnormal code;
6.4b read all data between the header and the trailer in the software buffer, and return the actual length and all data read.
CN201710796835.6A 2017-09-06 2017-09-06 Serial port data extraction method supporting fixed-length packets, variable-length packets and mixed packets Active CN107766265B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201710796835.6A CN107766265B (en) 2017-09-06 2017-09-06 Serial port data extraction method supporting fixed-length packets, variable-length packets and mixed packets

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201710796835.6A CN107766265B (en) 2017-09-06 2017-09-06 Serial port data extraction method supporting fixed-length packets, variable-length packets and mixed packets

Publications (2)

Publication Number Publication Date
CN107766265A CN107766265A (en) 2018-03-06
CN107766265B true CN107766265B (en) 2020-06-30

Family

ID=61265473

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201710796835.6A Active CN107766265B (en) 2017-09-06 2017-09-06 Serial port data extraction method supporting fixed-length packets, variable-length packets and mixed packets

Country Status (1)

Country Link
CN (1) CN107766265B (en)

Families Citing this family (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN111190851A (en) * 2019-12-11 2020-05-22 深圳市优必选科技股份有限公司 Analysis method, device, equipment and medium for variable length protocol
CN114301992A (en) * 2021-12-29 2022-04-08 北京半导体专用设备研究所(中国电子科技集团公司第四十五研究所) Data transmission method and storage medium

Citations (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN102724122A (en) * 2012-06-21 2012-10-10 广东威创视讯科技股份有限公司 Reliable serial port transmission method and device based on hardware system
CN105681134A (en) * 2016-03-04 2016-06-15 西安航天动力技术研究所 General multiple serial port communication protocol detection and identification method
CN107135200A (en) * 2017-03-29 2017-09-05 中国航空无线电电子研究所 High-speed serial bus data transmission method for uplink based on FPGA

Family Cites Families (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
WO2011160233A1 (en) * 2010-06-22 2011-12-29 Gennum Corporation High-speed interface for ancillary data for serial digital interface applications

Patent Citations (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN102724122A (en) * 2012-06-21 2012-10-10 广东威创视讯科技股份有限公司 Reliable serial port transmission method and device based on hardware system
CN105681134A (en) * 2016-03-04 2016-06-15 西安航天动力技术研究所 General multiple serial port communication protocol detection and identification method
CN107135200A (en) * 2017-03-29 2017-09-05 中国航空无线电电子研究所 High-speed serial bus data transmission method for uplink based on FPGA

Non-Patent Citations (1)

* Cited by examiner, † Cited by third party
Title
"数字影像采集定位系统双串口数据的提取及解析";方书山等;《测绘通报》;20131231(第2期);全文 *

Also Published As

Publication number Publication date
CN107766265A (en) 2018-03-06

Similar Documents

Publication Publication Date Title
CN101238383B (en) GPS processing arrangement
CN107766265B (en) Serial port data extraction method supporting fixed-length packets, variable-length packets and mixed packets
CN101119246B (en) Data packet sampling statistic method and apparatus
CN107771331B (en) Independent UARK BRK detection
CN111163018B (en) Network equipment and method for reducing transmission delay thereof
CN104899204B (en) Data storage method and device
CN102724122B (en) Reliable serial port transmission method and device based on hardware system
CN108123775A (en) The method and apparatus of transmission packet
EP1934761B1 (en) Dma transfer and hardware acceleration of ppp frame processing
CN114584560B (en) Method and device for reorganizing fragmented frames
CN106788888A (en) The method and system of Android mobile terminal communication success rate are improved under vulnerable network environment
CN107291647A (en) The method that DSP reads receiving channel data in extended serial port
CN106533976A (en) Data packet processing method and device
CN106254180A (en) Data transmission method and device
CN107168710B (en) Embedded Linux serial port driver development method based on blocking receiving mechanism
CN113038445A (en) Calibration method of Bluetooth sleep clock
CN114745330B (en) Data processing method and device
CN115396518A (en) Self-adaptive data synchronization method and system
CN111722940B (en) Message transmission method, terminal equipment and transmission system based on asynchronous serial port
CN105653207B (en) A kind of real time parsing method and system of flash interface information
CN114116583B (en) Serial communication method of double chips and system with double chips
CN105022712A (en) Data stream transmission based data packet extracting method
WO2016112646A1 (en) Data flow delimiting method, device and computer storage medium
US10892886B2 (en) Communications systems, methods and devices
CN116795756B (en) Frame data stream software receiving method based on serial port communication

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
GR01 Patent grant
GR01 Patent grant