CN109542811B - Data communication processing method - Google Patents
Data communication processing method Download PDFInfo
- Publication number
- CN109542811B CN109542811B CN201811193759.0A CN201811193759A CN109542811B CN 109542811 B CN109542811 B CN 109542811B CN 201811193759 A CN201811193759 A CN 201811193759A CN 109542811 B CN109542811 B CN 109542811B
- Authority
- CN
- China
- Prior art keywords
- dma
- data
- interrupt
- buffer
- soft
- 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
Links
Images
Classifications
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F13/00—Interconnection of, or transfer of information or other signals between, memories, input/output devices or central processing units
- G06F13/14—Handling requests for interconnection or transfer
- G06F13/20—Handling requests for interconnection or transfer for access to input/output bus
- G06F13/28—Handling requests for interconnection or transfer for access to input/output bus using burst mode transfer, e.g. direct memory access DMA, cycle steal
- G06F13/285—Halt processor DMA
Abstract
The technical scheme of the invention comprises a data communication processing method, which realizes a large amount of real-time data communication based on DMA double buffering combined with soft interrupt, in a DMA interrupt program, only the operation of switching a destination address of a DMA channel and triggering the soft interrupt is executed, and the data carrying operation is carried out in the soft interrupt program, but the DMA interrupt can cause CPU interrupt, and the soft interrupt can not cause CPU interrupt, so that the DMA interrupt cost is low, less CPU resources can be occupied when the CPU transaction is busy as much as possible, and the method has strong advantages in a system with resource shortage and busy transactions.
Description
Technical Field
The invention relates to a data communication processing method, and belongs to the technical field of data communication.
Background
In the existing embedded system, the MCU has more and more tasks, and the speed of the communication data interface is faster and faster, so the burden of communication is heavier and heavier. Under the condition of full load communication, a communication interface of the MCU occupies more resources of the processor and is easy to cause communication data loss.
Although the traditional DMA double-buffer data can solve the problem of data loss, when the data volume is large, the time consumption for carrying data is high when the DMA is interrupted, and more resources of a processor are occupied, so that the data communication requirements of system resources shortage and various tasks are difficult to meet.
Disclosure of Invention
In order to solve the above problems, an object of the present invention is to provide a data communication processing method, which implements a large amount of real-time data communication based on DMA double-buffer combined with soft interrupt, in a DMA interrupt program, only switching a destination address of a DMA channel and triggering soft interrupt, and then carrying data in the soft interrupt program, where the DMA interrupt will cause CPU interrupt, and the soft interrupt will not cause CPU interrupt, so that the DMA interrupt overhead is small, and the method can occupy a small CPU resource when the CPU transaction is busy as much as possible, and has a strong advantage in a system with resource shortage and busy transaction.
The technical scheme adopted by the invention for solving the problems is as follows: a data communication processing method is based on DMA double buffering combined with soft interruption to realize data communication between an MCU and an external device, wherein the MCU comprises a serial port, an FIFO memory, a DMA controller, an internal memory and a CPU; the method comprises the following steps:
s1, starting a serial port DMA receiving mode, configuring a FIFO memory and setting a receiving threshold value of the FIFO memory;
s2, opening up two receiving buffer areas in the memory, namely a first buffer area and a second buffer area;
s3, initializing the DMA controller, configuring a DMA channel between the peripheral and the memory, and setting the source address of the DMA channel as the data storage address of the peripheral;
s4, setting the destination address of the DMA channel as the address of the first buffer area, and enabling the DMA channel to receive data;
s5, when the data capacity received by the first buffer reaches the buffer capacity threshold, generating DMA interruption, the CPU executing the DMA interruption program, switching the destination address of the DMA channel to the address of the second buffer, enabling the DMA channel to receive data, and triggering the first soft interruption;
s6, in the first soft interrupt program, after transferring the data of the first buffer area to the FIFO memory, the DMA controller quits the first soft interrupt program and returns to the main program, and the data in the FIFO memory is processed by the CPU;
s7, when the data capacity received by the second buffer reaches the buffer capacity threshold, generating DMA interruption, the CPU executing the DMA interruption program, switching the destination address of the DMA channel to the address of the first buffer, enabling the DMA channel to receive data, and triggering a second soft interruption;
s8, in the second soft interrupt program, after transferring the data of the second buffer area to the FIFO memory, the DMA controller quits the second soft interrupt program and returns to the main program, and the data in the FIFO memory is processed by the CPU;
s9, executing steps S5-S8 in a circulating way until the communication is finished.
Further, the buffer capacity thresholds of the first buffer and the second buffer are equal.
Further, the DMA interrupt is a hard interrupt generated by the peripheral, and the first soft interrupt and the second soft interrupt are soft interrupts generated by the MCU process.
Further, the DMA interrupt has a higher priority than the first soft interrupt and the second soft interrupt.
Further, the FIFO memory includes a FIFO controller having a read pointer and a write pointer, and when the DMA controller performs a read or write operation on the FIFO memory, the FIFO controller changes the value of the read pointer or the write pointer accordingly.
Further, the FIFO controller reads or writes a FIFO memory reception threshold of data at a time.
The invention has the beneficial effects that: the data communication processing method adopted by the invention realizes a large amount of real-time data communication based on the combination of DMA double buffering and soft interruption, in a DMA interruption program, only the operation of switching the destination address of a DMA channel and triggering the soft interruption is executed, the data carrying operation is carried out in the soft interruption program, the CPU interruption can be caused by the DMA interruption, and the CPU interruption can not be caused by the soft interruption, so the DMA interruption cost is lower, the smaller CPU resource can be occupied when the CPU transaction is busy as much as possible, and the method has stronger advantages in a system with resource shortage and busy transactions.
Drawings
FIG. 1 is a data flow block diagram of an embodiment of the present disclosure;
FIG. 2 is a flow chart of the basic steps of an embodiment of the present disclosure;
fig. 3 is a block diagram of a specific implementation of an embodiment of the present disclosure.
Detailed Description
In order to make the objects, technical solutions and advantages of the present invention more apparent, the present invention will be described in detail with reference to the accompanying drawings and specific embodiments. The data communication processing method is suitable for real-time data communication of a system with resource shortage and busy affairs.
Referring to fig. 1-3, a data communication processing method of the present invention, based on DMA double buffering combined with soft interrupt, implements data communication between an MCU and an external device, where the MCU includes a serial port, an FIFO memory, a DMA controller, a memory, and a CPU, and the data flow direction is as shown in fig. 1, and data is transmitted between the memory of the MCU and the external device through a data bus; as shown in fig. 2, the method comprises the following steps:
s1, starting a serial port DMA receiving mode, configuring a FIFO memory and setting a receiving threshold value of the FIFO memory;
s2, opening up two receiving buffer areas in the memory, namely a first buffer area and a second buffer area;
s3, initializing the DMA controller, configuring a DMA channel between the peripheral and the memory, and setting the source address of the DMA channel as the data storage address of the peripheral;
s4, setting the destination address of the DMA channel as the address of the first buffer area, and enabling the DMA channel to receive data;
s5, when the data capacity received by the first buffer reaches the buffer capacity threshold, generating DMA interruption, the CPU executing the DMA interruption program, switching the destination address of the DMA channel to the address of the second buffer, enabling the DMA channel to receive data, and triggering the first soft interruption;
s6, in the first soft interrupt program, after transferring the data of the first buffer area to the FIFO memory, the DMA controller quits the first soft interrupt program and returns to the main program, and the data in the FIFO memory is processed by the CPU;
s7, when the data capacity received by the second buffer reaches the buffer capacity threshold, generating DMA interruption, the CPU executing the DMA interruption program, switching the destination address of the DMA channel to the address of the first buffer, enabling the DMA channel to receive data, and triggering a second soft interruption;
s8, in the second soft interrupt program, after transferring the data of the second buffer area to the FIFO memory, the DMA controller quits the second soft interrupt program and returns to the main program, and the data in the FIFO memory is processed by the CPU;
s9, executing steps S5-S8 in a circulating way until the communication is finished.
Further, the buffer capacity threshold of the first buffer and the second buffer are equal.
Further, the DMA interrupt is a hard interrupt generated by the peripheral, and the first soft interrupt and the second soft interrupt are soft interrupts generated by the MCU process.
Further, the DMA interrupt has a higher priority than the first soft interrupt and the second soft interrupt. The first soft interrupt and the second soft interrupt may be interrupted by other DMA interrupts to allow the system to process in time when a transaction request with a higher real-time requirement is received.
Further, the FIFO memory includes a FIFO controller, wherein the FIFO controller has a read pointer and a write pointer, and when the DMA controller performs a read or write operation on the FIFO memory, the FIFO controller changes the value of the read pointer or the write pointer accordingly.
Further, the FIFO controller therein reads or writes the data of the FIFO memory reception threshold value at a time.
When the received data of the FIFO memory does not reach the receiving threshold and new data is not received within a preset time period, the FIFO controller reads or writes all the existing data.
As shown in fig. 3, taking an STM32F103RCT6 chip as an example, a serial port is configured in a DMA reception mode, the first buffer and the second buffer are set to have capacity thresholds of 512 bytes, a DMA interrupt program executes switching of a destination address of a DMA channel and triggering of a soft interrupt, and the soft interrupt program executes transferring data from the first buffer or the second buffer to a FIFO memory.
The above description is only a preferred embodiment of the present invention, and the present invention is not limited to the above embodiment, and the present invention shall fall within the protection scope of the present invention as long as the technical effects of the present invention are achieved by the same means. The invention is capable of other modifications and variations in its technical solution and/or its implementation, within the scope of protection of the invention.
Claims (6)
1. A data communication processing method is based on DMA double buffering combined with soft interruption to realize data communication between an MCU and an external device, wherein the MCU comprises a serial port, an FIFO memory, a DMA controller, an internal memory and a CPU; the method is characterized by comprising the following steps:
s1, starting a serial port DMA receiving mode, configuring a FIFO memory and setting a receiving threshold value of the FIFO memory;
s2, opening up two receiving buffer areas in the memory, namely a first buffer area and a second buffer area;
s3, initializing the DMA controller, configuring a DMA channel between the peripheral and the memory, and setting the source address of the DMA channel as the data storage address of the peripheral;
s4, setting the destination address of the DMA channel as the address of the first buffer area, and enabling the DMA channel to receive data;
s5, when the data capacity received by the first buffer reaches the buffer capacity threshold, generating DMA interruption, the CPU executing the DMA interruption program, switching the destination address of the DMA channel to the address of the second buffer, enabling the DMA channel to receive data, and triggering the first soft interruption;
s6, in the first soft interrupt program, after transferring the data of the first buffer area to the FIFO memory, the DMA controller quits the first soft interrupt program and returns to the main program, and the data in the FIFO memory is processed by the CPU;
s7, when the data capacity received by the second buffer reaches the buffer capacity threshold, generating DMA interruption, the CPU executing the DMA interruption program, switching the destination address of the DMA channel to the address of the first buffer, enabling the DMA channel to receive data, and triggering a second soft interruption;
s8, in the second soft interrupt program, after transferring the data of the second buffer area to the FIFO memory, the DMA controller quits the second soft interrupt program and returns to the main program, and the data in the FIFO memory is processed by the CPU;
s9, executing steps S5-S8 in a circulating way until the communication is finished.
2. The data communication processing method according to claim 1, wherein: the buffer capacity thresholds of the first buffer and the second buffer are equal.
3. The data communication processing method according to claim 1, wherein: the DMA interrupt is a hard interrupt generated by a peripheral, and the first soft interrupt and the second soft interrupt are soft interrupts generated by an MCU process.
4. The data communication processing method according to claim 1, wherein: the DMA interrupt has a higher priority than the first soft interrupt and the second soft interrupt.
5. The data communication processing method according to claim 1, wherein: the FIFO memory comprises a FIFO controller, the FIFO controller is provided with a reading pointer and a writing pointer, and when the DMA controller reads or writes the FIFO memory, the FIFO controller correspondingly changes the value of the reading pointer or the writing pointer.
6. The data communication processing method according to claim 5, wherein: the FIFO controller reads or writes a FIFO memory receive threshold of data at a time.
Priority Applications (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN201811193759.0A CN109542811B (en) | 2018-10-15 | 2018-10-15 | Data communication processing method |
Applications Claiming Priority (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN201811193759.0A CN109542811B (en) | 2018-10-15 | 2018-10-15 | Data communication processing method |
Publications (2)
Publication Number | Publication Date |
---|---|
CN109542811A CN109542811A (en) | 2019-03-29 |
CN109542811B true CN109542811B (en) | 2021-12-07 |
Family
ID=65843772
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
CN201811193759.0A Active CN109542811B (en) | 2018-10-15 | 2018-10-15 | Data communication processing method |
Country Status (1)
Country | Link |
---|---|
CN (1) | CN109542811B (en) |
Citations (7)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN101441271A (en) * | 2008-12-05 | 2009-05-27 | 航天恒星科技有限公司 | SAR real time imaging processing device based on GPU |
CN102541780A (en) * | 2011-12-15 | 2012-07-04 | 苏州国芯科技有限公司 | Multi-data stream channel DMA (Direct Memory Access) system |
CN102831091A (en) * | 2012-07-31 | 2012-12-19 | 宁波成电泰克电子信息技术发展有限公司 | Serial port-based ship radar echo data collecting method |
CN102866971A (en) * | 2012-08-28 | 2013-01-09 | 华为技术有限公司 | Data transmission device, system and method |
CN103049336A (en) * | 2013-01-06 | 2013-04-17 | 浪潮电子信息产业股份有限公司 | Hash-based network card soft interrupt and load balancing method |
WO2017212524A1 (en) * | 2016-06-06 | 2017-12-14 | オリンパス株式会社 | Data transfer device, image processing device, and image pickup device |
CN108227572A (en) * | 2017-12-21 | 2018-06-29 | 中国船舶重工集团公司第七0七研究所 | A kind of serial data recording device based on FATFS32 file system |
Family Cites Families (3)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
US7421694B2 (en) * | 2003-02-18 | 2008-09-02 | Microsoft Corporation | Systems and methods for enhancing performance of a coprocessor |
KR101706201B1 (en) * | 2010-12-15 | 2017-02-15 | 한국전자통신연구원 | Direct memory access controller and operating method thereof |
KR20120108564A (en) * | 2011-03-24 | 2012-10-05 | 삼성전자주식회사 | Data processing system, and method of operating the same |
-
2018
- 2018-10-15 CN CN201811193759.0A patent/CN109542811B/en active Active
Patent Citations (7)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN101441271A (en) * | 2008-12-05 | 2009-05-27 | 航天恒星科技有限公司 | SAR real time imaging processing device based on GPU |
CN102541780A (en) * | 2011-12-15 | 2012-07-04 | 苏州国芯科技有限公司 | Multi-data stream channel DMA (Direct Memory Access) system |
CN102831091A (en) * | 2012-07-31 | 2012-12-19 | 宁波成电泰克电子信息技术发展有限公司 | Serial port-based ship radar echo data collecting method |
CN102866971A (en) * | 2012-08-28 | 2013-01-09 | 华为技术有限公司 | Data transmission device, system and method |
CN103049336A (en) * | 2013-01-06 | 2013-04-17 | 浪潮电子信息产业股份有限公司 | Hash-based network card soft interrupt and load balancing method |
WO2017212524A1 (en) * | 2016-06-06 | 2017-12-14 | オリンパス株式会社 | Data transfer device, image processing device, and image pickup device |
CN108227572A (en) * | 2017-12-21 | 2018-06-29 | 中国船舶重工集团公司第七0七研究所 | A kind of serial data recording device based on FATFS32 file system |
Also Published As
Publication number | Publication date |
---|---|
CN109542811A (en) | 2019-03-29 |
Similar Documents
Publication | Publication Date | Title |
---|---|---|
CN106874224B (en) | Multi-line SPI-Flash controller capable of automatically carrying and adapting to device | |
CN102841869B (en) | Multi-channel I2C controller based on FPGA | |
CN109308283B (en) | SoC (system on chip) system and peripheral bus switching method thereof | |
CN108768884A (en) | A kind of wireless communication data processing method based on buffer circle | |
CN112035388B (en) | High-performance encryption and decryption method based on PCI-e channel | |
CN106095604A (en) | The communication method between cores of a kind of polycaryon processor and device | |
US10372379B2 (en) | Command processing method and storage controller using the same | |
US11010094B2 (en) | Task management method and host for electronic storage device | |
US9239804B2 (en) | Back-off mechanism for a peripheral page request log | |
CN103106164A (en) | Highly efficient direct memory access (DMA) controller | |
CN104239232A (en) | Ping-Pong cache operation structure based on DPRAM (Dual Port Random Access Memory) in FPGA (Field Programmable Gate Array) | |
CN109542811B (en) | Data communication processing method | |
CN110399219B (en) | Memory access method, DMC and storage medium | |
CN103838694A (en) | FPGA high-speed USB interface data reading method | |
CN114879584B (en) | DMA controller boundary alignment method based on FPGA and circuit thereof | |
CN114564420A (en) | Method for sharing parallel bus by multi-core processor | |
CN114328350A (en) | Communication method, device and medium based on AXI bus | |
US11552892B2 (en) | Dynamic control of latency tolerance reporting values | |
CN103049409A (en) | One-way high-speed data transmission control method | |
CN109684245B (en) | Method and device for accessing SPI FLASH through APB bus | |
CN116601616A (en) | Data processing device, method and related equipment | |
CN107807888B (en) | Data prefetching system and method for SOC architecture | |
CN113190331B (en) | Interrupt delay optimization method for time system card on virtual machine | |
CN111782563A (en) | DVP controller system for RISC-V microcontroller | |
CN104951237A (en) | High-speed storage device based on SATA interface solid state disk |
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 |