This non-provisional application claims priority under 35 U.S.C. § 119(a) to Patent Application No. 109142693 in Taiwan, R.O.C. on Dec. 3, 2020, the entire contents of which are hereby incorporated by reference.
The present invention relates to a data transmission technology, and in particular to a data buffer method and a device.
In order to avoid power consumption caused by frequent storage and reading of the memory during data transfer between two electronic components, a buffer can be connected in series between the two electronic components for a data transmitting end to store data to be transferred, and for a data receiving end to read data stored in the buffer. However, the problem of data loss will inevitably occur when the two electronic components store and read the same buffer at the same time. For example, data is written into a certain area of the buffer and then new data is written into the area before the area is read. Especially when the two electronic components have different access orders for the buffer, this problem is particularly prone to occur.
In order to solve this problem, there is a method of using two buffers, in which the data transmitting end alternately writes data into the two buffers for the data reading end to read. In this way, although the problem of data loss can be solved, twice the buffer cost is required.
In view of the above problem, the present invention provides a data buffer method applied to a device. The device includes an upstream module, a downstream module and a buffer circuit which includes a plurality of storage units coupled between the upstream module and the downstream module. The pipelining data transmission method includes: performing a plurality of write/read rounds on the buffer circuit. Each of write/read rounds further comprises: performing a write operation on the buffer circuit in a writing order by the upstream module; and performing a read operation on the buffer circuit in a reading order by the downstream module; where the writing order and the reading order in the same write/read round are different.
An embodiment of the present invention further provides a data buffer method applied to a device. The device includes an upstream module, a downstream module and a buffer circuit which includes a plurality of storage units coupled between the upstream module and the downstream module. The pipelining data transmission method includes: performing a plurality of write/read rounds on the buffer circuit. Each of write/read rounds further comprises: performing a write operation on the buffer circuit in a writing order by the upstream module; and performing a read operation on the buffer circuit in a reading order by the downstream module; where in consecutive two of the write/read rounds, the writing order corresponding to the following write/read rounds is the same as the reading order corresponding to the previous write/read rounds.
An embodiment of the present invention further provides a device, including an upstream module, a downstream module and a buffer circuit. The buffer coupled between the upstream module and the downstream module, includes a plurality of storage units. The device performs a plurality of write/read rounds. In each of the write/read rounds, the upstream module performs a write operation on the buffer circuit in a writing order, and the downstream module performs a read operation on the buffer circuit in a reading order. The writing order and the reading order in the same write/read round are different.
According to the device and the data buffer method provided by the embodiments of the present invention, in the case of using a single buffer, the upstream module and the downstream module can use the respective writing order and reading order to access the buffer, and at the same time, the problem of data loss caused by overwriting of unread data can be avoided.
Referring to
Referring
In step S210, a plurality of write/read rounds are performed. One write/read round means that the upstream module 110 completely writes a piece of data into the buffer circuit 130 and the downstream module 120 completely reads the piece of data from the buffer circuit 130. The piece of data, taking image data as an example, may be, for example, an image, a slice of an image, or the like. In some embodiments, in one write/read round, the read operation is started after the write operation is completed. In two consecutive write/read rounds, the write operation of the next round may be started before the read operation of the previous round is completed.
Referring to
In step S220, the upstream module 110 performs a write operation on each of the storage units 131 in a writing order in each of the write/read rounds. As shown in
In step S230, the downstream module 120 performs a read operation on each of the storage units 131 in a reading order in each of the write/read rounds. Referring to
For the convenience of description, the address of the storage unit 131 is defined as the ordinal as shown in
Referring to Table 1, Table 1 shows a writing order and a reading order of a plurality of write/read rounds according to an embodiment of the present invention. It can be seen that in consecutive two of the write/read rounds, the writing order corresponding to the following write/read rounds is the same as the reading order corresponding to the previous write/read rounds. For example, the writing order of the second write/read round is the same as the reading order of the first write/read round, and the writing order of the third write/read round is the same as the reading order of the second write/read round. Thus, in consecutive two of the write/read rounds, if the performing ordinal of the writing order corresponding to the following write/read rounds is smaller than the performing ordinal of the reading order corresponding to the previous write/read rounds, new data will not be written into the storage unit 131 that has not been read, causing data loss. For example, when the performing ordinal of the reading order is “5”, the performing ordinal of the writing order can be “1”, “2”, “3” or “4”, but cannot be “5” or its subsequent ordinal. The performing ordinal refers to the ordinal of the address of the storage unit 131 in the writing order that is currently to perform the write operation. For example, in the writing order in the second write/read round, if the write operation is to be performed on the storage unit 131 with the address “16” currently, then the performing ordinal is “4”.
Referring to Table 1, the writing order and the reading order in the same write/read round are different. Thereby, the upstream module 110 and the downstream module 120 can write and read respectively according to their needs. For example, the upstream module 110 as an image sensor writes the image data into the buffer circuit 130 row by row, and the downstream module 120 as an image encoder needs to read the image data from the buffer circuit 130 tile by tile to perform encoding.
Referring to Table 1, there is a mapping relationship between the writing order and the reading order in the same write/read round, and the mapping relationship in each of the write/read rounds is the same. That is, in the same write/read round, there is a mapping relationship between the two addresses of the same ordinal in the writing order and the reading order. In each of the write/read rounds, the address in the writing order is mapped into the same address in the reading order. For example, in the first write/read round, the address with the ordinal “2” is “2” in the writing order, and the address also with the ordinal “2” is “6” in the reading order, while in other write/read rounds, the address “2” in the writing order is all mapped to the address “6” in the reading order (for example, the ordinal “5” in the second write/read round). Table 2 shows the mapping relationship between the addresses in the writing order and the addresses in the reading order according to an embodiment of the present invention.
Referring
In step S520, the upstream module 110 performs a write operation on the storage unit 131 of the current address; and the downstream module 120 performs a read operation on the storage unit 131 of the current address. For the upstream module 110, the current address is the address corresponding to the current performing ordinal in the writing order. For the downstream module 120, the current address is the address corresponding to the current performing ordinal in the reading order. The current performing ordinal of the upstream module 110 and the current performing ordinal of the downstream module 120 may be different.
After step S520 is completed, the process proceeds to step S530. The address of the next performing ordinal is obtained, and used as the current address of the write or read operation performed next time. The calculation formula is shown as formula (1). Add(n) is the write address or read address of the current ordinal, and Add(n+1) is the write address or read address of the next ordinal. n is the current ordinal. p is the displacement between the current address and the next address. If Add(n+1) obtained by formula (1) is greater than z, then Add(n+1) is updated according to formula (2). z is the number of storage units 131. In this example, z is 20. n, p and z are positive integers. In addition, the initial values of the parameters set in step S510 are as follows: n is 1, Add(1) is 1, the initial value of p of the upstream module 110 is 1, and the initial value of p of the downstream module 120 is 5.
Add(n+1)=Add(n)+p formula (1)
Add(n+1)=Add(n+1)−z+1 formula (2)
In step S540, it is determined that whether the write or read of the image data is completed. If so, the process proceeds to step S550; and if not, the process returns to step S520 to continue performing the next write or read operation.
In step S550, it is determined whether to perform the next write/read round (that is, it is determined whether the writing order or reading order of the current write/read round is completed). If so, the process proceeds to step S560 to update the parameter values, the calculation formula is shown as formula (3); and if not, the process is ended. Formula (3) is the largest integer less than or equal to the product of p and s divided by z (or referred to as “floor”), plus the remainder of the product of p and s divided by z, which is used as the value of p of the next write/read round. s is a positive integer. In this example, s is positively correlated with a stride of the image data. Specifically, s is the number of storage units 131 in one row (here, 5), but the embodiments of the present invention are not limited to this, and s may also be set to other values. The value of p corresponding to the writing order and the reading order in each of the write/read rounds is shown in Table 1.
p=└p*s/z┘+(p*s)mod z formula (3)
In another embodiment, the parameter values are updated through formula (3-1) to formula (3-3) instead of formula (3), which can avoid multiplication and division calculations and can enhance calculation efficacy or reduce hardware cost. Before formula (3-1) is performed, formula (3-2) is performed p times to obtain the value of q. In the process of performing formula (3-2) p times, the result of performing formula (3-2) each time is checked. If the calculated value of q is greater than z, then the value of q is updated according to formula (3-3), and then the next calculation of formula (3-2) is performed. Finally, the calculated final value of q is used as the new value of p (that is, formula (3-1)), and the value of q is reset to 0. In addition, the initial values of the parameters set in step S510 mentioned above further include: the initial value of q is 0.
p=q formula (3-1)
q=q+ formula (3-2)
q=z+1 formula (3-3)
Based on the above, according to the device 100 and the data buffer method provided by the embodiments of the present invention, in the case of using a single buffer circuit 130, the upstream module 110 and the downstream module 120 can use the respective writing order and reading order to access the buffer circuit 130, and at the same time, the problem of data loss caused by overwriting of unread data can be avoided.
Number | Date | Country | Kind |
---|---|---|---|
109142693 | Dec 2020 | TW | national |