This application claims the priority benefit of Taiwan application serial no. 92129878, filed Oct. 28, 2003.
1. Field of the Invention
The present invention relates to a method for updating data, and more particularly, to a method for updating data in a non-volatile memory.
2. Description of the Related Art
In various memory media, pen drives have the advantages of small size, high capacity, and portability and have become increasingly popular. Generally, pen drives use flash memories installed therein for storing data. Flash memories comprise a plurality of blocks. Every block comprises a plurality of pages. Before data are written in the flash memory, where data were saved, these data stored in the block should be erased first. In the conventional method, the incoming data are written in the blank block, and the un-updated data stored in the original block are copied back to the newly written block. The address matching table, which matches the physical addresses to the logic addresses, is then updated to correspond the physical addresses to the block where the data are written.
Accordingly, the present invention is directed to a method for updating data in a non-volatile memory, wherein after the packet which comprises the to-be-updated data is received, the write-in address of the packet is checked to determine whether or not the un-updated data should be copied back. Accordingly, the data-updating efficiency can be improved.
In order to achieve the object described above, the present invention discloses a method for updating data, suitable for updating data in a non-volatile memory. The method includes receiving a data packet comprising the to-be-updated data. It is then determined whether or not a write-in address of the received packet is in a same block with a last-updated data, and whether or not the write-in address follows behind the last-updated data. When the write-in address of the packet is in the same block with the last-updated data and behind the last-updated data, the data of the packet are directly written in.
When the write-in address of the packet is in the same block with the last-updated data and behind the last-updated data, but the write-in address is not series behind an updated address of the last-updated data, the data of this non-series address are copied back and then the data of the packet are directly written in.
When the write-in address of the packet is in the same block with the last-updated data and in front of the last-updated data, the un-updated data are copied back, an address matching table is updated and the data of the packet are written in another block.
When the write-in address of the packet is not in the same block with the last-updated data, the un-updated data are copied back, an address matching table is updated and the data of the received packet are written in another block.
When no pocket is received in a preset time, the un-updated data are copied back and an address matching table is updated. Accordingly, even if the pen drive with the non-volatile memory is powered-off, the updated data can still be stored.
The present invention discloses a method for updating data, suitable for updating data in a non-volatile memory. The method includes receiving a packet comprising the to-be-updated data. It is then determined whether or not a write-in address of the packet is in a same block with a last-updated data, and whether or not the write-in address is at an address of un-updated data in the same block. The data of the packet are directly written when the write-in address of the packet is in the same block with the last-updated data and at the address of un-updated data.
When the write-in address of the packet is in the same block with the last-updated data but at the address of updated data, the un-updated data are copied back, an address matching table is updated and the data of the packet are written in another block.
When the write-in address of the packet is not in the same block with the last-updated data, the un-updated data are copied back, an address matching table is updated and the data of the packet are written in another block.
When no pocket is received in a preset time, the un-updated data are copied back and an address matching table is updated. Accordingly, even if the pen drive with the non-volatile memory is powered-off, the updated data are not lost.
Accordingly, the present invention provides a method for updating data in a non-volatile memory, wherein after the packet which comprises the to-be-updated data is received, the write-in address of the packet is checked to determine whether or not the un-updated data should be copied back. Since most of the data are written in series, the data of the packet can be written directly. Therefore, the data updating efficiency can be substantially improved.
In order to make the aforementioned and other objects, features and advantages of the present invention understandable, embodiments accompanied with figures are described in detail below.
As shown in
For example, the last received packet is used to update the first block. In the last data updating process, the data are stored in the erased 11th block. When the incoming packet is used to update the second block, the un-updated data stored in the first block are copied back to the 11th block. The logic address corresponding to the first block is updated for referring to the 11th block. The data stored in the first block are then erased for subsequent use. Then an erased block, such as the 12th block, is selected and the data of the received packet are written therein.
In step S220, it is determined whether or not the write-in address of the packet is in a same block with the last-updated data. If so, step S230 determines whether the write-in address is behind the address of the last-updated data. If the write-in address is in front of the address of the last-updated data, steps S280 and S290 are performed to copy back the un-updated data and to update the address matching table. The step S260 is then performed to write the data of the received packet in another block.
For example, the last received packet is used to update pages 1-10 of the first block. In the last data updating process, the data are written in the erased 11th block. The incoming packet is used to update pages 1-5 of the first block. The un-updated data stored in pages 11-64 of the first block are copied back to the 11th block. The logic address corresponding to the first block is referred to the 11th block. The data stored in the first block are then erased for subsequent use. Then an erased block, such as the 12th block, is selected and the data of the received packet are written in pages 1-5. One of ordinary skill in the art should know that step S230 is required only when the pen drive uses a flash memory where data must be written sequentially. When using a flash memory where data can be written randomly, it only needs to determine whether the write-in address is at the address of the un-updated data.
The step S230 determines whether or not the write-in address is behind the address of the last-updated data. If so, step S240 determines whether the write-in address is series behind the last-updated data. If so, in step S260, the data of the receive packet are written. If the write-in address is not series with the address of the last-updated data, in step S250, the non-series data are copied back. Then the procedure goes to step S260, and the data of the received packet are then written.
For example, the last received packet is used to update pages 1-10 of the first block. In the last data updating process, the data are written in the erased 11th block. The incoming packet is used to update pages 11-15 of the first block. The received data can be written in pages 11-15 of the 11th block. If the incoming packet is used to update pages 16-20 of the first block, the data stored in pages 11-15 of the first block are copied back to the 11th block and the data are then written in pages 16-20 of the 11th block. One of ordinary skill in the art should know that steps S240 and S250 are required only when the pen drive uses a flash memory where data must be written sequentially. When using a flash memory where data can be written randomly, steps S240 and S250 can be spared.
To prevent data loss when the pen drive is powered-off while the up-updated data are being copied back, step S270 is added. When no packet is received during a preset time, the un-updated data are copied back and the address matching table is updated in steps S273 and S275 to maintain the integrity of the data.
Although the present invention has been described in terms of exemplary embodiments, it is not limited thereto. Rather, the appended claims should be constructed broadly to include other variants and embodiments of the invention which may be made by those skilled in the field of this art without departing from the scope and range of equivalents of the invention.
Number | Date | Country | Kind |
---|---|---|---|
92129878 | Oct 2003 | TW | national |