CN104375952A - Method for reading data from ring buffer - Google Patents

Method for reading data from ring buffer Download PDF

Info

Publication number
CN104375952A
CN104375952A CN201310352488.XA CN201310352488A CN104375952A CN 104375952 A CN104375952 A CN 104375952A CN 201310352488 A CN201310352488 A CN 201310352488A CN 104375952 A CN104375952 A CN 104375952A
Authority
CN
China
Prior art keywords
data
read
pointer
timer
timing
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.)
Pending
Application number
CN201310352488.XA
Other languages
Chinese (zh)
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.)
NANJING YOLONG TECHNOLOGY Co Ltd
Original Assignee
NANJING YOLONG TECHNOLOGY Co Ltd
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 NANJING YOLONG TECHNOLOGY Co Ltd filed Critical NANJING YOLONG TECHNOLOGY Co Ltd
Priority to CN201310352488.XA priority Critical patent/CN104375952A/en
Publication of CN104375952A publication Critical patent/CN104375952A/en
Pending legal-status Critical Current

Links

Landscapes

  • Information Transfer Systems (AREA)

Abstract

The invention discloses a method for reading data from a ring buffer. The method is characterized by including steps of defining a write-in pointer and a read-out pointer, wherein the write-in pointer is used for marking the ring buffer when data are written in, and the read-out pointer is used for marking the ring buffer when the data are read out; setting a timer used for triggering to generate interruption so as to read out the data from a storage unit of the ring buffer; shortening timing time of the timer triggering the read-out data when it is judged that the next storage unit pointed by the write-in pointer is the same as the storage unit pointed by the read-out pointer. By dynamically adjusting the read-out frequency of the data in the ring buffer, approximate synchronism of data write-in and read-out is ensured, thus, not only overflow and missing of the write-in data but reading empty or null data can be prevented, and reliability of serial port communication can be improved.

Description

A kind of method reading data from buffer circle
Technical field
The present invention relates to digital independent control technology, especially relate to a kind of method reading data from buffer circle.
Background technology
Buffer circle (Ring Buffer) is data structure conventional in producers and consumers's model.Data are put into the tail end of array by the producer, and consumer removes data from the other end of array, and when reaching the afterbody of array, the producer raps around to the head of array.If only have a producer and a consumer, so just can accomplish to exempt from lock access buffer circle.Write index only allows the producer access and revise, as long as new value was saved in buffer zone by writer before renewal index, then reader will see consistent data structure all the time.In like manner, reading index also only allows consumer access and revise.
In the algorithm of existing microcontroller serial port buffer zone, the reading for buffer data all adopts the mode of equivalent access interval time always.When the buffer zone producer (data enter) is equal with the speed of consumer's (reading buffer data), this is ideal situation.Now the balancing with the consumer spending of producer produces.When producer's speed is accelerated, and consumer's speed is constant, now shows a small surplus, and because there is buffer circle to exist, now also can not cause data congestion.When producer's speed near consumer spending not in time, now can produce data congestion.And when producer produces slows, not necessarily all can have again production output during the access at equal intervals of consumer, cause consumer to access waste, waste the waste of software cycles time load.Certain the above results may there will not be, and prerequisite enough littlely under meeting maximum communication load, still will can keep certain consumption at the time interval of consumer, or the data buffer storage space defined is enough large.
Summary of the invention
The present invention proposes a kind of method reading data from buffer circle, to solve the data of current buffer circle stored in the technical matters that cause data easily lose asynchronous with digital independent.
The present invention adopts following technical scheme to realize: a kind of method reading data from buffer circle, and it comprises step:
In the storer of single-chip microcomputer, set buffer circle, and in buffer circle, set several respectively each write data or storage unit corresponding to sense data;
Definition be used for stored in during data to buffer circle mark stored in pointer and the reading pointer for marking buffer circle when sense data;
Arrange one and trigger generation interruption with the timer of sense data from a storage unit of buffer circle;
When judging identical with the storage unit read pointed by pointer stored in the next storage unit pointed by pointer, the timing triggering the timer of sense data is shortened.
Wherein, a kind of described method reading data from buffer circle also comprises step: judge whether the next storage unit read pointed by pointer is empty or does not have new data, is if so, extended by the timing triggering the timer of sense data.
Wherein, a kind of described method reading data from buffer circle also comprises step: the initial timing time T presetting this timer 0, and the adjusting range T of timing 1.
Wherein, the current timing of timer is deducted adjusting range T1 as new timing, with this, timing of timer is shortened.
Wherein, the current timing of timer is added that adjusting range T1 is as new timing, with this, timing of timer is extended.
Compared with prior art, the present invention has following beneficial effect:
The present invention is by the read frequency of data in dynamic conditioning buffer circle, guarantee that data are stored in roughly synchronous with data reading, not only can prevent write data from overflow from losing but also can prevent from reading as empty or invalid data, thus the reliability of serial communication can be improved.
Accompanying drawing explanation
Fig. 1 is the schematic diagram of buffer circle;
Fig. 2 is the schematic flow sheet of one embodiment of the invention.
Embodiment
The present invention realizes reading to defined serial data buffer data, realize communication busy time and communication idle scan the change of secondary frequencies.This law utilizes timer timing to read buffer data, and in communication busy, timer can be made to shorten, and increases in the unit interval to data buffer access times, ensures the data reading communication in time.When communication is comparatively idle, timer will increase, and reduces, thus reach the object of Optimization Software cyclic load in the unit interval to buffer zone access times.
As shown in Figure 1, define a buffer zone array A [0, n], length n+1 is can by actual definition.N be greater than 1 natural number.The storage unit of each read-write in the corresponding buffer circle of each element in the array of reception buffer zone.While defining arrays, in turn define stored in pointer and read pointer, stored in pointer be used in when stored in during data to the mark between buffer empty, reading pointer be used in when reading the data to the mark between buffer empty.Popular saying be exactly stored in pointed be I the concrete space filled out, what read pointed is space read-out by me.Two pointers all point to the 1st space (0 subscript) of array time initial.
When timer triggers, be now the reading to buffer data and processing procedure.From the concrete space, buffer zone reading pointed, data are read out, and read successively, until last space, array buffer zone, pointer turns to first space, continue to read, and go down successively, define an annular circulation to the access between buffer empty.When data are filled to consistent with reading pointed stored in pointed, illustrate stored in buffer zone full, if restore, because read pointer position to move forward (also not reading preceding data), data cover will be caused, cause data be destroyed, if not stored in, then data can be overflowed and lose.
Shown in composition graphs 2, in an embodiment of the invention, data are prevented to be capped or data from overflow by the cycle of dynamic conditioning reading data.Specifically, the present embodiment comprises following performing step:
Step S1, in the storer of single-chip microcomputer, set buffer circle, define a buffer zone array A [0, n], n be greater than 1 natural number.Each elements A 0, A1 in the array of reception buffer zone ... with the storage unit of read-write each in An respectively corresponding buffer circle.
Step S2, define stored in pointer and read pointer, stored in pointer be used in stored in during data to the mark of buffer circle, reading pointer is mark to buffer circle when being used in sense data.
In an initial condition, all point in buffer zone array [0, n] stored in pointer and reading pointer the storage unit being numbered 0.
Step S3, arrange one and trigger the timer of sense data, when being timed to, producing and interrupting reading data from buffer circle, and presetting the initial timing time T of this timer 0, and the adjusting range T of timing 1.
Step S4, judge to be whether the storage unit of a non-sense data stored in the next storage unit pointed by pointer, if so, then proceed to step S5, otherwise return step S4.
Wherein, a numbering continuous print storage unit is connected from the n+1 of 0 ~ n, therefore owing to comprising in buffer zone array [0, n], when add stored in pointer 1 be more than or equal to read pointer time, just think stored in the next storage unit pointed by pointer to be the storage unit of non-sense data.
Step S5, will trigger sense data timer timing shorten, namely perhaps the current timing of current timing T(is initial timing time T 0) deduct default adjusting range T 1.Increased the frequency of sense data by the timing shortening timer, thus accelerate sense data.
Step S6, judge to read next storage unit pointed by pointer and whether be empty or do not have new data, if so, then proceed to step S7, otherwise return step S6.
When read into pointer add 1 be more than or equal to stored in pointer time, just think that the next one read pointed by pointer is empty or does not have new data.
Step S7, will trigger sense data timer timing extend, namely perhaps the current timing of current timing T(is initial timing time T 0) add default adjusting range T 1.Reduced the frequency of sense data by the timing of prolonging timer, thus reduce the frequency of sense data, to guarantee that data are stored in roughly synchronous with data reading.
Such as, in the microcomputer series interface communication of reality, single-chip microcomputer communicates with upper PC, and PC uses debugging assistant to send.Every 1ms, 10ms, 100ms, 200ms and 500ms are defined as successively to the interval of buffer zone reading read access is carried out to buffer zone.PC host computer does not send data to single-chip microcomputer, now be spaced apart 500ms to the reading of buffer zone, when PC utilizes serial ports assistant to send data at certain intervals, single-chip microcomputer can from 1ms interval scan, by judging, corresponding gear can be jumped to from 1ms and buffer zone is scanned.
The foregoing is only preferred embodiment of the present invention, not in order to limit the present invention, all any amendments done within the spirit and principles in the present invention, equivalent replacement and improvement etc., all should be included within protection scope of the present invention.

Claims (5)

1. read a method for data from buffer circle, it is characterized in that, comprise step:
In the storer of single-chip microcomputer, set buffer circle, and in buffer circle, set several respectively each write data or storage unit corresponding to sense data;
Definition be used for stored in during data to buffer circle mark stored in pointer and the reading pointer for marking buffer circle when sense data;
Arrange one and trigger generation interruption with the timer of sense data from a storage unit of buffer circle;
When judging identical with the storage unit read pointed by pointer stored in the next storage unit pointed by pointer, the timing triggering the timer of sense data is shortened.
2. a kind ofly according to claim 1 read the method for data from buffer circle, it is characterized in that, also comprise step: judge whether the next storage unit read pointed by pointer is empty or does not have new data, is if so, extended by the timing triggering the timer of sense data.
3. a kind of method reading data from buffer circle according to claim 1 or 2, is characterized in that, also comprise step: the initial timing time T presetting this timer 0, and the adjusting range T of timing 1.
4. a kind ofly according to claim 3 read the method for data from buffer circle, it is characterized in that, the current timing of timer is deducted adjusting range T1 as new timing, with this, timing of timer is shortened.
5. a kind ofly according to claim 3 read the method for data from buffer circle, it is characterized in that, the current timing of timer is added that adjusting range T1 is as new timing, with this, timing of timer is extended.
CN201310352488.XA 2013-08-14 2013-08-14 Method for reading data from ring buffer Pending CN104375952A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201310352488.XA CN104375952A (en) 2013-08-14 2013-08-14 Method for reading data from ring buffer

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201310352488.XA CN104375952A (en) 2013-08-14 2013-08-14 Method for reading data from ring buffer

Publications (1)

Publication Number Publication Date
CN104375952A true CN104375952A (en) 2015-02-25

Family

ID=52554884

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201310352488.XA Pending CN104375952A (en) 2013-08-14 2013-08-14 Method for reading data from ring buffer

Country Status (1)

Country Link
CN (1) CN104375952A (en)

Cited By (10)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN106131580A (en) * 2015-11-18 2016-11-16 苏州踪视通信息技术有限公司 The video data using buffer circle processes
CN106776393A (en) * 2016-12-26 2017-05-31 北京旋极信息技术股份有限公司 A kind of serial data method of reseptance and device without interruption
CN106909513A (en) * 2017-03-20 2017-06-30 杭州朔天科技有限公司 A kind of asynchronous asymmetrical read-write memory area management method
CN106980271A (en) * 2016-01-19 2017-07-25 南京南瑞继保电气有限公司 Signal communication delay analogy method based on PSCAD/EMTDC
CN107302531A (en) * 2017-06-19 2017-10-27 青岛华潞佳电子科技有限公司 A kind of serial port command analytic method based on state machine and circle queue
CN108037931A (en) * 2017-12-06 2018-05-15 广州路派电子科技有限公司 A kind of method that file programming is carried out to microprocessor storage unit
US10506283B2 (en) 2015-11-18 2019-12-10 Cybrook Inc. Video decoding and rendering using combined jitter and frame buffer
CN111290709A (en) * 2020-01-19 2020-06-16 成都中嵌自动化工程有限公司 Dynamically adjustable annular buffer area
CN111866581A (en) * 2020-07-23 2020-10-30 杭州国芯科技股份有限公司 Method for rapidly switching digital television programs
CN113613058A (en) * 2021-07-19 2021-11-05 青岛海信移动通信技术股份有限公司 Local storage method, equipment and medium for network video stream

Citations (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN101834978A (en) * 2009-12-23 2010-09-15 福建新大陆通信科技有限公司 Method for optimizing digital set-top box EPG system
CN102591815A (en) * 2011-12-27 2012-07-18 Tcl集团股份有限公司 Method and device for using annular data buffer to read and write batch data
US8291136B2 (en) * 2009-12-02 2012-10-16 International Business Machines Corporation Ring buffer

Patent Citations (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US8291136B2 (en) * 2009-12-02 2012-10-16 International Business Machines Corporation Ring buffer
CN101834978A (en) * 2009-12-23 2010-09-15 福建新大陆通信科技有限公司 Method for optimizing digital set-top box EPG system
CN102591815A (en) * 2011-12-27 2012-07-18 Tcl集团股份有限公司 Method and device for using annular data buffer to read and write batch data

Cited By (15)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN106131580B (en) * 2015-11-18 2019-04-05 苏州踪视通信息技术有限公司 It is handled using the video data of buffer circle
US10506283B2 (en) 2015-11-18 2019-12-10 Cybrook Inc. Video decoding and rendering using combined jitter and frame buffer
US10506245B2 (en) 2015-11-18 2019-12-10 Cybrook Inc. Video data processing using a ring buffer
CN106131580A (en) * 2015-11-18 2016-11-16 苏州踪视通信息技术有限公司 The video data using buffer circle processes
CN106980271A (en) * 2016-01-19 2017-07-25 南京南瑞继保电气有限公司 Signal communication delay analogy method based on PSCAD/EMTDC
CN106776393A (en) * 2016-12-26 2017-05-31 北京旋极信息技术股份有限公司 A kind of serial data method of reseptance and device without interruption
CN106776393B (en) * 2016-12-26 2020-01-31 北京旋极信息技术股份有限公司 uninterrupted serial port data receiving method and device
CN106909513A (en) * 2017-03-20 2017-06-30 杭州朔天科技有限公司 A kind of asynchronous asymmetrical read-write memory area management method
CN107302531A (en) * 2017-06-19 2017-10-27 青岛华潞佳电子科技有限公司 A kind of serial port command analytic method based on state machine and circle queue
CN108037931A (en) * 2017-12-06 2018-05-15 广州路派电子科技有限公司 A kind of method that file programming is carried out to microprocessor storage unit
CN108037931B (en) * 2017-12-06 2021-02-02 广州路派电子科技有限公司 Method for writing file in storage unit of microprocessor
CN111290709A (en) * 2020-01-19 2020-06-16 成都中嵌自动化工程有限公司 Dynamically adjustable annular buffer area
CN111290709B (en) * 2020-01-19 2022-12-06 成都中嵌自动化工程有限公司 Dynamically adjustable annular buffer area
CN111866581A (en) * 2020-07-23 2020-10-30 杭州国芯科技股份有限公司 Method for rapidly switching digital television programs
CN113613058A (en) * 2021-07-19 2021-11-05 青岛海信移动通信技术股份有限公司 Local storage method, equipment and medium for network video stream

Similar Documents

Publication Publication Date Title
CN104375952A (en) Method for reading data from ring buffer
CN105207678A (en) Hardware realizing system for improved LZ4 compression algorithm
CN104102690B (en) Storage structure based telemetry data processing method
CN101206614B (en) Simulator for simulating register with specific function
CN105427577A (en) Infrared data processing method, processing device and decoding method
CN102592665A (en) High-speed data writing structure and writing method for phase change memory
CN101483035B (en) Method and system for display text on graphical interface
CN105511806A (en) Method for processing write request and mobile terminal
CN102082577B (en) High-speed cyclic redundancy check (CRC) device and implementation method thereof
CN103544076A (en) Data backup method and device
CN104765266A (en) Simulation clock display method and device and LED display control card
CN105022667A (en) Embedded browser CSS (Cascading Style Sheets) based engine parallelization method
CN105550089B (en) A kind of FC network frame head error in data method for implanting based on digital circuit
CN102778645B (en) JTAG (joint test action group) main controller and realization method of JTAG main controller
CN105531681A (en) Storage apparatus, storage system, storage apparatus controlling method
CN104572019B (en) A kind of method and apparatus of inspection task
CN209590838U (en) A kind of SoC system
CN103294606A (en) Methods and devices for allocating memories and detecting overflow thereof
CN103226515B (en) A kind of partition storage method for electrical degree of digital meter
CN103576826B (en) Memory control methods, device and accumulator system
CN102467958B (en) Refresh frequency device for dynamic memory and method thereof
CN105574292A (en) Method for achieving multi-channel any-bandwidth packet sending based on dynamic arrays
CN104182218B (en) On-board computer time delay command storing and executing method
CN110083567A (en) A kind of chip architecture
CN110096256A (en) A kind of method and device using trusted root creation random value character device

Legal Events

Date Code Title Description
C06 Publication
PB01 Publication
C10 Entry into substantive examination
SE01 Entry into force of request for substantive examination
RJ01 Rejection of invention patent application after publication

Application publication date: 20150225

RJ01 Rejection of invention patent application after publication