[go: up one dir, main page]

CN107678977B - Reading and writing method and device of counter - Google Patents

Reading and writing method and device of counter Download PDF

Info

Publication number
CN107678977B
CN107678977B CN201710944123.4A CN201710944123A CN107678977B CN 107678977 B CN107678977 B CN 107678977B CN 201710944123 A CN201710944123 A CN 201710944123A CN 107678977 B CN107678977 B CN 107678977B
Authority
CN
China
Prior art keywords
storage page
counter
page
storage
operation request
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
CN201710944123.4A
Other languages
Chinese (zh)
Other versions
CN107678977A (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.)
State Grid Information and Telecommunication Group Co Ltd
Beijing Smartchip Microelectronics Technology Co Ltd
State Grid Corp of China SGCC
Original Assignee
State Grid Information and Telecommunication Group Co Ltd
Beijing Smartchip Microelectronics Technology Co Ltd
State Grid Corp of China SGCC
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 State Grid Information and Telecommunication Group Co Ltd, Beijing Smartchip Microelectronics Technology Co Ltd, State Grid Corp of China SGCC filed Critical State Grid Information and Telecommunication Group Co Ltd
Priority to CN201710944123.4A priority Critical patent/CN107678977B/en
Publication of CN107678977A publication Critical patent/CN107678977A/en
Priority to PCT/CN2018/087174 priority patent/WO2019062147A1/en
Application granted granted Critical
Publication of CN107678977B publication Critical patent/CN107678977B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING OR CALCULATING; COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F12/00Accessing, addressing or allocating within memory systems or architectures
    • G06F12/02Addressing or allocation; Relocation
    • G06F12/0223User address space allocation, e.g. contiguous or non contiguous base addressing
    • G06F12/023Free address space management
    • G06F12/0238Memory management in non-volatile memory, e.g. resistive RAM or ferroelectric memory
    • G06F12/0246Memory management in non-volatile memory, e.g. resistive RAM or ferroelectric memory in block erasable memory, e.g. flash memory
    • GPHYSICS
    • G06COMPUTING OR CALCULATING; COUNTING
    • G06MCOUNTING MECHANISMS; COUNTING OF OBJECTS NOT OTHERWISE PROVIDED FOR
    • G06M3/00Counters with additional facilities

Landscapes

  • Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Physics & Mathematics (AREA)
  • General Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • Techniques For Improving Reliability Of Storages (AREA)

Abstract

本发明涉及一种计数器的读写方法及装置,方法包括:接收操作请求,其中操作请求包括第一存储页的地址;获取第一存储页以及第二存储页中存储的计数器信息,其中,计数器信息包括:序列号、校验值以及计数器值,第二存储页为在闪存FLASH芯片中与计数器对应的第一存储页的下一存储页;根据第一存储页以及第二存储页中存储的计数器信息,确定有效存储页;根据操作请求以及有效存储页中的计数器信息,执行与操作请求对应的操作处理。本发明提供的计数器的读写方法及装置,可以实现计数器信息的断电保护,减少了备份操作所需要的多次操作,提高了计数器的读写速率。

Figure 201710944123

The invention relates to a method and device for reading and writing a counter. The method includes: receiving an operation request, wherein the operation request includes an address of a first storage page; acquiring counter information stored in the first storage page and the second storage page, wherein the counter The information includes: serial number, check value and counter value, and the second storage page is the next storage page of the first storage page corresponding to the counter in the flash FLASH chip; The counter information is used to determine the valid storage page; according to the operation request and the counter information in the valid storage page, the operation processing corresponding to the operation request is performed. The method and device for reading and writing a counter provided by the invention can realize the power-off protection of the counter information, reduce the multiple operations required for the backup operation, and improve the reading and writing rate of the counter.

Figure 201710944123

Description

Reading and writing method and device of counter
Technical Field
The present invention relates to the field of communications technologies, and in particular, to a method and an apparatus for reading and writing a counter.
Background
At present, with the development of power communication, terminal devices such as a concentrator and a collection terminal are increasingly used. In order to ensure the security of the device, a Terminal Embedded security control Module (TESAM) is usually installed in a Terminal device such as a concentrator and an acquisition Terminal, and is used as a security authentication Module of the device. When the terminal equipment interacts with the application platform through the TESAM, various counters can be used, and the reading and writing speed of the counters can seriously affect the processing efficiency of the concentrator, the acquisition terminal and other terminal equipment.
The counter generally occupies 4 bytes of storage in a Flash Memory (Flash EEPROM Memory for short). In the prior art, when a counter is read, the counter is directly read to a FLASH address corresponding to the counter; when updating the counter, according to the existing power-down protection mode, data needs to be backed up to the write protection area, data marks of the write protection area are marked in the write protection control area, data is written in a written actual address, and the write protection control area is erased for 4 times.
Based on this, the inventor of the present invention finds that, in the existing counter read-write method in the prior art, multiple times of erasing and writing are required when the counter is updated, so that the execution time of the instruction is increased, and the processing efficiency of the terminal devices such as the concentrator and the acquisition terminal is reduced.
The information disclosed in this background section is only for enhancement of understanding of the general background of the invention and should not be taken as an acknowledgement or any form of suggestion that this information forms the prior art already known to a person skilled in the art.
Disclosure of Invention
In view of the above, the technical problem to be solved by the present invention is how to provide a method and an apparatus for reading and writing a counter, so as to solve the problems of long instruction execution time and low reading and writing efficiency of the counter in the prior art.
In order to solve the above technical problem, the present invention provides, in a first aspect, a method for reading and writing a counter, including: receiving an operation request, wherein the operation request comprises an address of a first storage page, and the first storage page is a first page in a plurality of storage pages corresponding to the counter in a FLASH chip; acquiring counter information stored in the first storage page and the second storage page, wherein the counter information includes: the second storage page is the next storage page of the first storage page corresponding to the counter in the FLASH chip; determining an effective storage page according to the counter information stored in the first storage page and the second storage page; and executing operation processing corresponding to the operation request according to the operation request and the counter information in the effective storage page.
In a possible implementation manner, the determining a valid storage page according to the counter information stored in the first storage page and the second storage page includes: respectively judging whether the first storage page and the second storage page are empty or not according to the counter information stored in the first storage page and the second storage page; and if the first storage page and the second storage page are both empty, the first storage page is a valid storage page.
In a possible implementation manner, after respectively determining whether the first storage page and the second storage page are empty according to the counter information stored in the first storage page and the second storage page, the method further includes: if at least one of the first storage page and the second storage page is not empty, respectively judging whether the check values of the first storage page and the second storage page are valid; if the check value of only one storage page is valid, the storage page with the valid check value is a valid storage page.
In a possible implementation manner, the respectively determining whether the check values of the first storage page and the second storage page are valid includes: respectively judging whether the check values of the counter information stored in the first storage page and the second storage page are correct or not; if at least one of the check values of the counter information stored in the first storage page is correct, the check value of the first storage page is valid; and if at least one of the check values of the counter information stored in the second storage page is correct, the check value of the second storage page is valid.
In a possible implementation manner, after respectively determining whether the check values of the first storage page and the second storage page are valid, the method further includes: if the check values of the first storage page and the second storage page are both valid, respectively determining the maximum value of the serial number of the counter in the first storage page and the second storage page according to the counter information stored in the first storage page and the second storage page; and comparing the maximum value of the counter serial numbers in the first storage page with the maximum value of the counter serial numbers in the second storage page, and taking the storage page stored with the maximum value of the counter serial numbers as a valid storage page.
In a possible implementation manner, when the operation request is a read operation request, before executing operation processing corresponding to the operation request according to the operation request and counter information in the valid storage page, the method further includes: respectively determining the maximum value of the serial number of the counter in the first storage page and the second storage page according to the counter information stored in the first storage page and the second storage page; respectively determining offset addresses of the maximum value of the counter sequence numbers in the first storage page and the second storage page relative to the first address of the first storage page; the executing, according to the operation request and the counter information in the valid storage page, operation processing corresponding to the operation request includes: and reading the value of the counter according to the operation request and the offset address of the maximum value of the serial number of the counter in the effective storage page relative to the first address of the first storage page.
In a possible implementation manner, when the operation request is a write operation request, the operation request further includes counter information to be written; before the executing the operation processing corresponding to the operation request according to the operation request and the counter information in the valid storage page, the method further includes: respectively acquiring offset addresses of the next available address of the first storage page and the second storage page relative to the first address of the first storage page; the executing, according to the operation request and the counter information in the valid storage page, operation processing corresponding to the operation request includes: if the check value of only one storage page is valid, erasing the storage page with the invalid check value; and writing the counter information into the next available address of the effective storage page according to the counter information to be written in the operation request.
In a possible implementation manner, the executing, according to the operation request and the counter information in the valid memory page, operation processing corresponding to the operation request further includes: and if the check values of the first storage page and the second storage page are valid, erasing the storage page stored with the maximum value of the small counter serial number.
In order to solve the above technical problem, the present invention provides, in a second aspect, a reading/writing apparatus for a counter, including: a receiving module, configured to receive an operation request, where the operation request includes an address of a first storage page, where the first storage page is a first page of a plurality of storage pages corresponding to the counter in a FLASH chip; an obtaining module, configured to obtain counter information stored in the first storage page and the second storage page, where the counter information includes: the second storage page is the next storage page of the first storage page corresponding to the counter in the FLASH chip; the calculation module is used for determining an effective storage page according to the counter information stored in the first storage page and the second storage page; and the processing module is used for executing operation processing corresponding to the operation request according to the operation request and the counter information in the effective storage page.
The reading and writing method and device for the counter provided by the invention can be used for acquiring the counter information stored in the first storage page and the second storage page, wherein the counter information comprises the following steps: a serial number, a check value, and a counter value; determining an effective storage page according to the counter information stored in the first storage page and the second storage page; and executing operation processing corresponding to the operation request according to the operation request and the counter information in the effective storage page, so that power-off protection of the counter information can be realized, multiple operations required by backup operation are reduced, and the reading and writing speed of the counter is improved.
Other features and aspects of the present invention will become apparent from the following detailed description of exemplary embodiments, which proceeds with reference to the accompanying drawings.
Drawings
The accompanying drawings, which are incorporated in and constitute a part of this specification, illustrate exemplary embodiments, features, and aspects of the invention and, together with the description, serve to explain the principles of the invention.
Fig. 1 is a flowchart illustrating a method for reading and writing a counter according to an embodiment of the present invention;
fig. 2 is a flowchart of a method for reading and writing a counter according to another embodiment of the present invention;
FIG. 3 is a flowchart of a method for reading and writing a counter according to a next embodiment of the present invention;
FIG. 4 is a flowchart illustrating a method for reading from and writing to a counter according to yet another embodiment of the present invention;
fig. 5 is a schematic structural diagram of a read/write apparatus of a counter according to another embodiment of the present invention.
Detailed Description
The following detailed description of the present invention is provided in conjunction with the accompanying drawings, but it should be understood that the scope of the present invention is not limited to the specific embodiments.
In order to make the objects, technical solutions and advantages of the embodiments of the present invention clearer, the technical solutions in the embodiments of the present invention will be clearly and completely described below with reference to the drawings in the embodiments of the present invention, and it is obvious that the described embodiments are some, but not all, embodiments of the present invention. All other embodiments, which can be derived by a person skilled in the art from the embodiments given herein without making any creative effort, shall fall within the protection scope of the present invention. Throughout the specification and claims, unless explicitly stated otherwise, the word "comprise", or variations such as "comprises" or "comprising", will be understood to imply the inclusion of a stated element or component but not the exclusion of any other element or component.
The word "exemplary" is used exclusively herein to mean "serving as an example, embodiment, or illustration. Any embodiment described herein as "exemplary" is not necessarily to be construed as preferred or advantageous over other embodiments.
Furthermore, in the following detailed description, numerous specific details are set forth in order to provide a better understanding of the present invention. It will be understood by those skilled in the art that the present invention may be practiced without some of these specific details. In some instances, methods, means, elements well known to those skilled in the art have not been described in detail so as not to obscure the present invention.
Example 1
The read and write operations of the FLASH chip are generally performed in blocks or pages, and even if the write data only has 1 byte, the entire block or page data including the byte needs to be erased and written during actual write. The read-write characteristic of the FLASH chip can greatly increase the data write-in time, and has great influence on the execution time of some instructions which need to frequently update FLASH. When the counter is updated according to the conventional power-down protection scheme, in the case of requiring updating of 4 bytes of data, the operations of erasing and writing 4 pages of data are actually performed, and the time of these operations becomes a key factor of the length of the instruction execution time.
FLASH chips are classified into two categories based on their differences in their erase and write performance. The first type of chip is to erase the rewrite as long as the data at a certain position is modified; and in the second type of chips, the bits of the support data are written from 1 to 0, and the bits of the support data are written from 0 to 1. The proposal is optimized for the second type of chip.
The method has the advantages that the correctness and the validity of the counter are guaranteed, meanwhile, the erasing times are reduced, a plurality of complete pages are used for storing one counter, and the legality of the counter is guaranteed by increasing the storage space and the storage content.
Fig. 1 is a flowchart illustrating a method for reading and writing a counter according to an embodiment of the present invention, as shown in fig. 1, the method includes the following steps.
Step S1, receiving an operation request, where the operation request includes an address of a first storage page, where the first storage page is a first page of a plurality of storage pages corresponding to the counter in the FLASH chip.
Step S2, obtaining counter information stored in the first storage page and the second storage page, where the counter information includes: the second storage page is the next storage page of the first storage page corresponding to the counter in the FLASH chip.
Specifically, the memory page is a memory unit divided by the FLASH chip for the convenience of management, and a plurality of pieces of counter information are stored in one memory page. When reading and writing, a page address and an offset address in a page need to be specified at the same time. The storage space corresponding to the counter in this embodiment may be a plurality of pages, and in this embodiment, the first storage page and the second storage page are specifically described as an example, but not limited to two pages.
The counter information includes: a sequence number, a check value to verify the validity of the counter, the counter value, and may also include reserved bytes. The structure of the counter information can be seen in table 1:
element(s) Length of Description of the invention
num 1byte Counter serial number
counter 4byte Actual valid counter value
crc 1byte CRC checksum of num and counter
rf 2byte Reserved bytes for alignment
TABLE 1
When the chip initialization instruction is executed, a plurality of memory pages corresponding to the counter need to be initialized. The storage space of a plurality of storage pages corresponding to the counter is initialized to 0xFF, and the first piece of counter information of the first storage page is initialized to 0100000000010000 to ensure that the page is valid.
Step S3, determining a valid storage page according to the counter information stored in the first storage page and the second storage page.
The counter information stored in the valid storage page is correct counter information.
Step S4, executing an operation process corresponding to the operation request according to the operation request and the counter information in the valid memory page.
Specifically, the value of the counter is read or updated according to a read operation request or a write operation request.
Thereby, by acquiring counter information stored in the first storage page and the second storage page, the counter information includes: a serial number, a check value, and a counter value; determining an effective storage page according to the counter information stored in the first storage page and the second storage page; and executing operation processing corresponding to the operation request according to the operation request and the counter information in the effective storage page, so that power-off protection of the counter information can be realized, multiple operations required by backup operation are reduced, and the reading and writing speed of the counter is improved.
Example 2
Fig. 2 is a flowchart of a read-write method of a counter according to another embodiment of the present invention, please refer to fig. 2, and this embodiment further limits step S3 based on the first embodiment.
Step S3 in this embodiment may include:
s31, respectively determining whether the first storage page and the second storage page are empty according to the counter information stored in the first storage page and the second storage page.
Specifically, when the FLASH chip is shipped from the factory, the storage space in the storage page is initialized to 0xFF, that is, whether the storage page is empty can be determined by determining whether the data of the entire page is 0 xFF. And obtaining the counter information stored in the storage page, wherein if the counter information stored in the current storage page is all 0xFF, the current storage page is empty.
S32, if the first storage page and the second storage page are both empty, the first storage page is a valid storage page.
S33, if at least one of the first storage page and the second storage page is not empty, determining whether the check values of the first storage page and the second storage page are valid.
Specifically, it is judged by the check value in the counter information.
The method can comprise the following steps:
s331, respectively determining whether check values of counter information stored in the first storage page and the second storage page are correct;
the method specifically comprises the following steps: when the operation is executed, the current counter value is checked and calculated, and if the check value calculated according to the counter value is the same as the check value of the counter information, the check value of the counter information is correct.
S332, if at least one of the check values of the counter information stored in the first storage page is correct, the check value of the first storage page is valid.
S333, if at least one of the check values of the counter information stored in the second storage page is correct, the check value of the second storage page is valid.
Thus, the validity of the counter value is guaranteed by whether the check value of the memory page is correct. The problem that the counter value is inaccurate when updating or writing is not finished in the power failure process is solved.
S34, if the check value of only one storage page is valid, the storage page with the valid check value is a valid storage page.
Specifically, when at least one of the first storage page and the second storage page is not empty and only one storage page has a correct check value, the first storage page is not empty and valid, and the second storage page is empty or invalid; the second memory page is not empty and valid, the first memory page is empty or invalid; neither the first memory page nor the second memory page is empty, but there is only one valid case.
S35, if the check values of the first storage page and the second storage page are both valid, determining maximum values of the counter numbers in the first storage page and the second storage page according to the counter information stored in the first storage page and the second storage page, respectively.
Specifically, the maximum values of the counter serial numbers in the first storage page and the second storage page are respectively determined, all the counter serial numbers in the first storage page are obtained, the counter serial numbers in the storage pages are compared, and the maximum value is selected as the maximum value of the counter serial numbers of the first storage page; and acquiring all the counter serial numbers in the second storage page, comparing the counter serial numbers in the storage page, and selecting the maximum value as the maximum value of the counter serial numbers of the second storage page. It should be noted that, when updating the counter value, the system automatically allocates the counter number, and the largest counter number is the latest stored counter value.
S36, comparing the maximum value of the counter numbers in the first memory page with the maximum value of the counter numbers in the second memory page, and setting the memory page storing the maximum value of the counter numbers as a valid memory page.
Specifically, if the maximum value of the counter serial number in the first storage page is greater than the maximum value of the counter serial number in the second storage page, the first storage page is a valid storage page; and if the maximum value of the counter serial number in the first storage page is smaller than the maximum value of the counter serial number in the second storage page, the second storage page is a valid storage page.
Therefore, in the embodiment, by judging whether the first storage page and the second storage page are empty or not, and determining the effective storage page by judging the check value of the storage page when the first storage page and the second storage page are not empty, the power-off protection of the counter information can be realized, the multiple operations required by the backup operation are reduced, and the read-write speed of the counter is further improved.
Example 3
Fig. 3 is a flowchart of a method for reading and writing a counter according to a next embodiment of the present invention, please refer to fig. 3, in which an operation request is a read operation request, and the method is further defined based on the above embodiment.
Before step S4, the method further includes:
step S51, determining maximum values of the counter numbers in the first storage page and the second storage page respectively according to the counter information stored in the first storage page and the second storage page;
step S52, determining offset addresses of the maximum value of the counter numbers in the first storage page and the second storage page with respect to the first address of the first storage page, respectively;
step S4 includes:
step S41, reading the value of the counter according to the operation request and the offset address of the maximum value of the counter sequence number in the valid storage page relative to the first address of the first storage page.
The method may further include erasing the memory page in which the largest value of the small counter numbers is stored if the check values of the first memory page and the second memory page are both correct.
It should be noted that step S51 in this embodiment has the same function as step S35 in the second embodiment in determining the maximum value of the counter numbers in the first storage page and the second storage page, respectively, based on the counter information stored in the first storage page and the second storage page.
Thereby, the offset addresses of the maximum value of the counter sequence numbers in the first storage page and the second storage page relative to the first address of the first storage page are respectively determined; reading the value of the counter according to the operation request and the offset address of the maximum value of the serial number of the counter in the effective storage page relative to the first address of the first storage page, so that the power-off protection of the counter information can be realized, the multiple operations required by the backup operation are reduced, and the reading and writing speed of the counter is further improved.
Example 4
Fig. 4 is a flowchart of a method for reading from and writing to a counter according to yet another embodiment of the present invention, please refer to fig. 4, in which in the present embodiment, when the operation request is a write operation request, further limitations are performed on the basis of the above embodiments. The operation request also comprises counter information to be written;
before step S4, the method further includes:
step S53, respectively obtaining offset addresses of the next available address of the first storage page and the second storage page relative to the first address of the first storage page.
Step S4 includes:
in step S42, if the check value of only one storage page is valid, the storage page with the invalid check value is erased.
Step S43, writing the counter information in the next available address of the valid storage page according to the counter information to be written in the operation request.
In step S44, if the check values of the first storage page and the second storage page are both valid, the storage page storing the largest value of the small counter numbers is erased.
Specifically, when the first storage page space is used up, the counter information needing to be updated is saved to the second page, and then the first page is subjected to whole-page erasing.
Therefore, when only the check value of one storage page is valid, the storage page with the invalid check value is erased, and the counter information is written in the next available address of the valid storage page according to the counter information to be written in the operation request; if the check values of the first storage page and the second storage page are both valid, the storage page storing the maximum value of the small counter serial number is erased, so that when the counter is updated, only the counter information, namely 8 bytes, is updated, and only one erasing operation needs to be performed when a page is completely written, thereby reducing the updating time of the counter and further improving the instruction execution efficiency.
Example 5
Fig. 5 is a schematic structural diagram of a read/write apparatus for a counter according to another embodiment of the present invention, and as shown in fig. 5, the apparatus includes a receiving module 1, an obtaining module 2, a calculating module 3, and a processing module 4.
The receiving module 1 is configured to receive an operation request, where the operation request includes a read operation request or a write operation request, and an address of a first storage page, where the first storage page is a first page of a plurality of storage pages corresponding to the counter in the FLASH chip.
An obtaining module 2, configured to obtain counter information stored in the first storage page and the second storage page, where the counter information includes: the second storage page is the next storage page of the first storage page corresponding to the counter in the FLASH chip.
And the calculating module 3 is used for determining an effective storage page according to the counter information stored in the first storage page and the second storage page.
And the processing module 4 is configured to execute operation processing corresponding to the operation request according to the operation request and the counter information in the valid storage page.
Thereby, by acquiring counter information stored in the first storage page and the second storage page, the counter information includes: a serial number, a check value, and a counter value; determining an effective storage page according to the counter information stored in the first storage page and the second storage page; and executing operation processing corresponding to the operation request according to the operation request and the counter information in the effective storage page, so that power-off protection of the counter information can be realized, multiple operations required by backup operation are reduced, and the reading and writing speed of the counter is improved.
The foregoing descriptions of specific exemplary embodiments of the present invention have been presented for purposes of illustration and description. It is not intended to limit the invention to the precise form disclosed, and obviously many modifications and variations are possible in light of the above teaching. The exemplary embodiments were chosen and described in order to explain certain principles of the invention and its practical application to enable one skilled in the art to make and use various exemplary embodiments of the invention and various alternatives and modifications as are suited to the particular use contemplated. It is intended that the scope of the invention be defined by the claims and their equivalents.
The above-described embodiments of the apparatus are merely illustrative, and the units described as separate parts may or may not be physically separate, and parts displayed as units may or may not be physical units, may be located in one place, or may be distributed on a plurality of network units. Some or all of the modules may be selected according to actual needs to achieve the purpose of the solution of the present embodiment. One of ordinary skill in the art can understand and implement it without inventive effort.

Claims (9)

1. A method for reading and writing a counter is characterized by comprising the following steps:
receiving an operation request, wherein the operation request comprises an address of a first storage page, and the first storage page is a first page of a plurality of storage pages corresponding to the counter in a FLASH memory FLASH chip;
acquiring counter information stored in the first storage page and the second storage page, wherein the counter information includes: the second storage page is the next storage page of the first storage page corresponding to the counter in the FLASH chip;
determining an effective storage page according to the counter information stored in the first storage page and the second storage page;
and executing operation processing corresponding to the operation request according to the operation request and the counter information in the effective storage page.
2. The method of claim 1, wherein the determining the valid memory page according to the counter information stored in the first memory page and the second memory page comprises:
respectively judging whether the first storage page and the second storage page are empty or not according to the counter information stored in the first storage page and the second storage page;
and if the first storage page and the second storage page are both empty, the first storage page is a valid storage page.
3. The method according to claim 2, wherein after determining whether the first storage page and the second storage page are empty according to the counter information stored in the first storage page and the second storage page, respectively, the method further comprises:
if at least one of the first storage page and the second storage page is not empty, respectively judging whether the check values of the first storage page and the second storage page are valid;
if the check value of only one storage page is valid, the storage page with the valid check value is a valid storage page.
4. The method of claim 3, wherein the determining whether the check values of the first storage page and the second storage page are valid respectively comprises:
respectively judging whether the check values of the counter information stored in the first storage page and the second storage page are correct or not;
if at least one of the check values of the counter information stored in the first storage page is correct, the check value of the first storage page is valid;
and if at least one of the check values of the counter information stored in the second storage page is correct, the check value of the second storage page is valid.
5. The method of claim 3, wherein after determining whether the check values of the first storage page and the second storage page are valid, the method further comprises:
if the check values of the first storage page and the second storage page are both valid, respectively determining the maximum value of the serial number of the counter in the first storage page and the second storage page according to the counter information stored in the first storage page and the second storage page;
and comparing the maximum value of the counter serial numbers in the first storage page with the maximum value of the counter serial numbers in the second storage page, and taking the storage page stored with the maximum value of the counter serial numbers as a valid storage page.
6. The method according to any one of claims 1 to 5, wherein when the operation request is a read operation request, before performing operation processing corresponding to the operation request according to the operation request and the counter information in the valid memory page, the method further includes: respectively determining the maximum value of the serial number of the counter in the first storage page and the second storage page according to the counter information stored in the first storage page and the second storage page;
respectively determining offset addresses of the maximum value of the counter sequence numbers in the first storage page and the second storage page relative to the first address of the first storage page;
the executing, according to the operation request and the counter information in the valid storage page, operation processing corresponding to the operation request includes:
and reading the value of the counter according to the operation request and the offset address of the maximum value of the serial number of the counter in the effective storage page relative to the first address of the first storage page.
7. The method according to claim 5, wherein when the operation request is a write operation request, the operation request further includes counter information to be written; before the executing the operation processing corresponding to the operation request according to the operation request and the counter information in the valid storage page, the method further includes:
respectively acquiring offset addresses of the next available address of the first storage page and the second storage page relative to the first address of the first storage page;
the executing, according to the operation request and the counter information in the valid storage page, operation processing corresponding to the operation request includes:
if the check value of only one storage page is valid, erasing the storage page with the invalid check value;
and writing the counter information into the next available address of the effective storage page according to the counter information to be written in the operation request.
8. The method according to claim 7, wherein the executing, according to the operation request and the counter information in the valid memory page, an operation process corresponding to the operation request further comprises:
and if the check values of the first storage page and the second storage page are valid, erasing the storage page stored with the maximum value of the small counter serial number.
9. A device for reading from and writing to a counter, comprising:
a receiving module, configured to receive an operation request, where the operation request includes an address of a first storage page, where the first storage page is a first page of a plurality of storage pages corresponding to the counter in a FLASH chip;
an obtaining module, configured to obtain counter information stored in the first storage page and the second storage page, where the counter information includes: the second storage page is the next storage page of the first storage page corresponding to the counter in the FLASH chip;
the calculation module is used for determining an effective storage page according to the counter information stored in the first storage page and the second storage page;
and the processing module is used for executing operation processing corresponding to the operation request according to the operation request and the counter information in the effective storage page.
CN201710944123.4A 2017-09-30 2017-09-30 Reading and writing method and device of counter Active CN107678977B (en)

Priority Applications (2)

Application Number Priority Date Filing Date Title
CN201710944123.4A CN107678977B (en) 2017-09-30 2017-09-30 Reading and writing method and device of counter
PCT/CN2018/087174 WO2019062147A1 (en) 2017-09-30 2018-05-16 Reading and writing method and apparatus for counter, device, and storage medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201710944123.4A CN107678977B (en) 2017-09-30 2017-09-30 Reading and writing method and device of counter

Publications (2)

Publication Number Publication Date
CN107678977A CN107678977A (en) 2018-02-09
CN107678977B true CN107678977B (en) 2021-01-05

Family

ID=61140710

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201710944123.4A Active CN107678977B (en) 2017-09-30 2017-09-30 Reading and writing method and device of counter

Country Status (2)

Country Link
CN (1) CN107678977B (en)
WO (1) WO2019062147A1 (en)

Families Citing this family (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN107678977B (en) * 2017-09-30 2021-01-05 北京智芯微电子科技有限公司 Reading and writing method and device of counter
CN110276213B (en) * 2019-06-24 2021-03-16 恒宝股份有限公司 Smart card and storage and verification method for sensitive result thereof
CN110729014A (en) * 2019-10-17 2020-01-24 深圳忆联信息系统有限公司 Method and device for backing up erase count table in SSD (solid State disk) storage, computer equipment and storage medium

Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN101079009A (en) * 2007-07-06 2007-11-28 北京飞天诚信科技有限公司 Method and storage device for limiting read of sensitive information
CN103065675A (en) * 2011-10-18 2013-04-24 海力士半导体有限公司 Memory system
CN104769557A (en) * 2012-11-09 2015-07-08 高通股份有限公司 Processor memory optimization via page access counting
CN105023612A (en) * 2014-04-30 2015-11-04 质子世界国际公司 bidirectional counter in flash memory
US9442841B2 (en) * 2012-04-19 2016-09-13 Kabushiki Kaisha Toshiba Semiconductor memory device and method for logging monitored events into a buffer

Family Cites Families (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US7082512B2 (en) * 2002-11-21 2006-07-25 Microsoft Corporation Dynamic data structures for tracking file system free space in a flash memory device
JP4229140B2 (en) * 2006-06-16 2009-02-25 ソニー株式会社 Integrated circuit chip, data reading method, data writing method, IC card, and mobile phone
US9703492B2 (en) * 2015-05-19 2017-07-11 International Business Machines Corporation Page replacement algorithms for use with solid-state drives
CN107678977B (en) * 2017-09-30 2021-01-05 北京智芯微电子科技有限公司 Reading and writing method and device of counter

Patent Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN101079009A (en) * 2007-07-06 2007-11-28 北京飞天诚信科技有限公司 Method and storage device for limiting read of sensitive information
CN103065675A (en) * 2011-10-18 2013-04-24 海力士半导体有限公司 Memory system
US9442841B2 (en) * 2012-04-19 2016-09-13 Kabushiki Kaisha Toshiba Semiconductor memory device and method for logging monitored events into a buffer
CN104769557A (en) * 2012-11-09 2015-07-08 高通股份有限公司 Processor memory optimization via page access counting
CN105023612A (en) * 2014-04-30 2015-11-04 质子世界国际公司 bidirectional counter in flash memory

Non-Patent Citations (1)

* Cited by examiner, † Cited by third party
Title
基于ARM+FPGA的PLC计数器的设计;徐晓宇等;《计算机测量与控制》;20160229;全文 *

Also Published As

Publication number Publication date
WO2019062147A1 (en) 2019-04-04
CN107678977A (en) 2018-02-09

Similar Documents

Publication Publication Date Title
US9372750B2 (en) Method and apparatus for non-volatile RAM error re-mapping
US10403372B2 (en) Memory system with adaptive read-threshold scheme and method of operating such memory system
US8041883B2 (en) Restoring storage devices based on flash memories and related circuit, system, and method
US10102146B2 (en) Memory system and operating method for improving rebuild efficiency
US8954705B2 (en) Memory space management method and memory controller and memory storage device and memory storage using the same
US20080046778A1 (en) Memory controller and semiconductor memory device
CN102163155A (en) Upgrade controlling device and method for upgrading memory device
US9442797B2 (en) Memory system
US10261876B2 (en) Memory management
CN107678977B (en) Reading and writing method and device of counter
CN104679672A (en) Data storage device and flash memory control method
CN103823642A (en) Method and system used for Flash balance storage
CN110209349B (en) Data processing method and terminal equipment
CN101727401A (en) Link table recovery method
US10509565B2 (en) Apparatuses, methods, and computer-readable non-transitory recording mediums for erasure in data processing
CN106528441B (en) Data processing method and device for simulating EEPROM (electrically erasable programmable read-Only memory) and electronic equipment
US10423524B2 (en) Memory storage device, control circuit unit and method including storing logical-to-physical table bit map information in a management unit and not storing identical data content
US10176876B2 (en) Memory control method and apparatus for programming and erasing areas
CN110910938A (en) Data correction method and device, storage equipment and storage medium
CN110111829B (en) A method, device and medium for channel correction of flash memory
CN105867833A (en) Data storage apparatus and data storage method
CN113409867B (en) Nonvolatile memory programming method, nonvolatile memory programming device, electronic equipment and storage medium
CN118262776A (en) LPDDR DBI function test method, device, equipment and medium
US20150012688A1 (en) Computer system and operating method thereof
CN110908825A (en) Data reading method and device, storage equipment and storage medium

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