WO2019062147A1 - 一种计数器的读写方法及装置、设备、存储介质 - Google Patents

一种计数器的读写方法及装置、设备、存储介质 Download PDF

Info

Publication number
WO2019062147A1
WO2019062147A1 PCT/CN2018/087174 CN2018087174W WO2019062147A1 WO 2019062147 A1 WO2019062147 A1 WO 2019062147A1 CN 2018087174 W CN2018087174 W CN 2018087174W WO 2019062147 A1 WO2019062147 A1 WO 2019062147A1
Authority
WO
WIPO (PCT)
Prior art keywords
storage page
counter
page
storage
valid
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.)
Ceased
Application number
PCT/CN2018/087174
Other languages
English (en)
French (fr)
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
Publication of WO2019062147A1 publication Critical patent/WO2019062147A1/zh
Anticipated expiration legal-status Critical
Ceased legal-status Critical Current

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

Definitions

  • the present invention relates to the field of communications technologies, and in particular, to a counter reading and writing method, device, device, and storage medium.
  • the Terminal Embedded Secure Access Module (TESAM) is usually installed in the terminal device such as the concentrator and the collection terminal as the security authentication module of the device.
  • TESAM Terminal Embedded Secure Access Module
  • various counters are used, and the read/write speed of the counter seriously affects the processing efficiency of the terminal devices such as the concentrator and the collection terminal.
  • the counter generally takes up 4 bytes of storage in Flash EEPROM Memory (FLASH).
  • FLASH Flash EEPROM Memory
  • the FLASH address corresponding to the counter is directly read; when the counter is updated, the data needs to be backed up to the write protection area and the write protection area to the write protection area according to the existing power failure protection mode. Mark, write data in the write real address, and erase the write protection control area 4 times.
  • the inventors of the present invention have found that the existing counter reading and writing method in the prior art needs to perform multiple erasing when updating the counter, increasing the execution time of the instruction, and reducing the terminal devices such as the concentrator and the collecting terminal. Processing efficiency.
  • the embodiments of the present invention provide a method for reading and writing a counter, a device, a device, and a storage medium.
  • An embodiment of the present invention provides a method for reading and writing a counter, including: receiving an operation request, wherein the operation request includes an address of a first storage page, wherein the first storage page is in a FLASH chip a first page of the plurality of storage pages corresponding to the counter; acquiring counter information stored in the first storage page and the second storage page, wherein the counter information comprises: a serial number, a check value, and a counter value,
  • the second storage page is a next storage page of the first storage page corresponding to the counter in the FLASH chip; determining a valid storage page according to the counter information stored in the first storage page and the second storage page And performing an operation process corresponding to the operation request according to the operation request and the counter information in the valid storage page.
  • the determining, according to the counter information stored in the first storage page and the second storage page, that the valid storage page comprises: according to the first storage page and the second storage page
  • the stored counter information is respectively determined whether the first storage page and the second storage page are empty; if the first storage page and the second storage page are both empty, the first storage page is Effectively store pages.
  • the determining whether the check value of the first storage page and the second storage page is valid includes: respectively determining the first storage page and the second storage page Whether the check value of the stored counter information is correct; if the check value of the counter information stored in the first storage page is at least one correct, the check value of the first storage page is valid; if the second storage If the check value of the counter information stored in the page is at least one correct, the check value of the second memory page is valid.
  • the method further includes: if the first storage page and the second storage And determining, by the first storage page and the counter information stored in the second storage page, a maximum number of counter numbers in the first storage page and the second storage page, respectively. a value; comparing a maximum value of a counter number in the first storage page with a maximum value of a counter number in the second storage page, and storing, as a valid storage page, a storage page storing a maximum value of the maximum of the counter number .
  • the method further includes: determining, according to the first storage page and the counter information stored in the second storage page, maximum values of counter numbers in the first storage page and the second storage page; respectively determining Determining, by the first storage page, an offset address of a maximum value of a counter number in the second storage page relative to a first address of the first storage page; the counter information according to the operation request and the valid storage page And performing an operation process corresponding to the operation request, including: reading the operation request and an offset address of a maximum value of a counter number in the valid storage page with respect to a first address of the first storage page, The value of the counter.
  • the operation request when the operation request is a write operation request, the operation request further includes counter information to be written; the counter according to the operation request and the valid storage page The information, before performing the operation processing corresponding to the operation request, further comprising: respectively acquiring the offset addresses of the first storage page and the next available address of the second storage page relative to the first address of the first storage page And performing, according to the operation request and the counter information in the valid storage page, operation processing corresponding to the operation request, including: if only one stored page check value is valid, the verification is performed The memory page whose value is invalid is erased; the counter information is written in the next available address of the valid memory page according to the counter information to be written in the operation request.
  • the performing the operation processing corresponding to the operation request according to the operation request and the counter information in the valid storage page further comprising: if the first storage page and the When the check value of the second memory page is valid, the memory page storing the small value of the counter number is erased.
  • the embodiment of the present invention provides a read/write device for a counter, comprising: a receiving module, configured to receive an operation request, wherein the operation request includes an address of a first storage page, wherein the first storage page is a first page of the plurality of storage pages corresponding to the counter in the FLASH chip; the acquiring module configured to acquire counter information stored in the first storage page and the second storage page, wherein the counter information includes: a sequence Number, a check value, and a counter value, the second memory page is a next memory page of the first memory page corresponding to the counter in the FLASH chip; and the calculating module is configured to be according to the first memory page And determining, by the counter information stored in the second storage page, a valid storage page; and the processing module is configured to perform an operation process corresponding to the operation request according to the operation request and the counter information in the valid storage page.
  • An embodiment of the present invention provides a terminal device, including a memory and a processor, where the memory stores a computer program executable on a processor, and when the processor executes the program, the implementation in the foregoing embodiment is implemented.
  • the steps in the counter reading and writing method are described in detail below.
  • An embodiment of the present invention provides a computer readable storage medium having stored thereon a computer program, the computer program being executed by a processor to implement the steps in the method for reading and writing the counter in the foregoing embodiment.
  • the method for reading and writing a counter, the device, and the storage medium obtained the counter information stored in the first storage page and the second storage page, wherein the counter information includes: a serial number, a school And a counter value; determining, according to the first storage page and the counter information stored in the second storage page, a valid storage page; performing and operating according to the operation request and counter information in the valid storage page Requesting the corresponding operation processing can realize the power-off protection of the counter information, reduce the multiple operations required for the backup operation, and improve the read/write rate of the counter.
  • FIG. 1 is a flowchart of 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 second embodiment of the present invention.
  • FIG. 4 is a flowchart of a method for reading and writing a counter according to still another embodiment of the present invention.
  • FIG. 5 is a schematic structural diagram of a read/write device for a counter according to another embodiment of the present invention.
  • FIG. 6 is a schematic diagram of a hardware entity of a terminal device according to an embodiment of the present invention.
  • the reading and writing of the FALSH chip is generally performed in blocks or pages. Even if the write data is only 1 byte, the entire block or page data containing the byte is erased when actually writing. This read and write feature of the FLASH chip will greatly increase the data write time, which will have a great impact on the execution time of some instructions that need to update the FLASH frequently.
  • the counter is updated according to the conventional power-down protection scheme, when 4 bytes of data are required to be updated, 4 pages of data are erased and written, and the time of these operations becomes a key factor in the execution time of the instruction. .
  • FLASH chips are divided into two categories according to the difference in their erasing performance.
  • the first type of chip as long as the data is modified somewhere, the rewriting is erased.
  • the second type of chip the bit supporting the data is written from 1 to 0, and the bit is not supported from 0 to 1. This proposal is optimized for the second type of chip.
  • FIG. 1 is a flowchart of 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 Receive an operation request, where the operation request includes an address of the first storage page, wherein the first storage page is a first page of the plurality of storage pages corresponding to the counter in the FLASH chip.
  • Step S2 acquiring counter information stored in the first storage page and the second storage page, wherein the counter information includes: a serial number, a check value, and a counter value, where the second storage page is in the FLASH chip. The next memory page of the first memory page corresponding to the counter.
  • the storage page is a FALSH chip for conveniently managing the divided storage units, and a plurality of counter information is stored in one storage page.
  • a plurality of counter information is stored in one storage page.
  • the storage space corresponding to the counter in this embodiment may be multiple pages.
  • the first storage page and the second storage page are taken as an example, but are not limited to two pages.
  • the counter information includes: a serial number, a check value used to verify the validity of the counter, a counter value, and may also include a reserved byte.
  • the structure of the counter information can be seen in Table 1:
  • the storage space of the plurality of storage pages corresponding to the counter is initialized to 0xFF, and the first 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 the correct counter information.
  • Step S4 performing an operation process corresponding to the operation request according to the operation request and the counter information in the valid storage page.
  • the value of the counter is read or updated based on a read operation request or a write operation request.
  • the counter information comprises: a serial number, a check value, and a counter value; according to the first storage page and the second Storing the counter information stored in the page, determining a valid storage page; performing operation processing corresponding to the operation request according to the operation request and counter information in the valid storage page, thereby implementing power-off protection of the counter information, reducing The multiple operations required for the backup operation increase the read/write rate of the counter.
  • FIG. 2 is a flowchart of a method for reading and writing a counter according to another embodiment of the present invention. Referring to FIG. 2, the embodiment further defines step S3 on the basis of the first embodiment.
  • Step S3 in this embodiment may include:
  • Step S31 Determine, according to the first storage page and the counter information stored in the second storage page, whether the first storage page and the second storage page are empty.
  • the storage space in the memory page is initialized to 0xFF, that is, whether the memory page is empty can be determined by determining whether the entire page data is 0xFF.
  • the counter information stored in the storage page is obtained. If the counter information stored in the current storage page is 0xFF, the current storage page is empty.
  • Step S32 If the first storage page and the second storage page are both empty, the first storage page is a valid storage page.
  • Step 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 respectively.
  • the check value in the counter information is used to determine.
  • Can include:
  • Step S331 respectively, determining whether the check value of the counter information stored in the first storage page and the second storage page is correct
  • the step S331 includes: performing a check calculation on the current counter value when the operation is performed, and if the check value calculated according to the counter value is the same as the check value of the counter information, the counter information is The check value is correct.
  • Step S332 if at least one check value of the counter information stored in the first storage page is correct, the check value of the first storage page is valid.
  • Step S333 if at least one check value of the counter information stored in the second storage page is correct, the check value of the second storage page is valid.
  • the counter value is guaranteed to be valid by checking whether the check value of the page is correct. Avoid the problem that the counter value is not accurate during the power-down process without updating or writing completion.
  • step S34 if only the check value of one stored page is valid, the stored page whose check value is valid is a valid storage page.
  • the first storage page and the second storage page have at least one check value that is not empty and only one storage page is correct, the first storage page is not empty and Valid, the second memory page is empty or invalid; the second memory page is not empty and valid, the first memory page is empty or invalid; the first memory page and the second memory page are not empty, but only one valid case .
  • Step S35 if the check values of the first storage page and the second storage page are all valid, determining the first according to the counter information stored in the first storage page and the second storage page. a storage page and a maximum value of a counter number in the second storage page.
  • the maximum values of the counter numbers in the first storage page and the second storage page are respectively determined, and all counter numbers in the first storage page are obtained, and the counter serial number in the storage page is performed.
  • the maximum value is selected as the maximum value of the counter number of the first storage page; all counter numbers in the second storage page are obtained, the counter numbers in the storage page are compared, and the maximum value is selected as the first The maximum value of the counter number of the second memory page. It should be noted that when the counter value is updated, the system automatically assigns the counter number, and the counter number is the latest stored counter value.
  • Step S36 comparing the maximum value of the counter serial number in the first storage page with the maximum value of the counter serial number in the second storage page, and storing the storage page storing the largest maximum value of the counter serial number as effective storage. page.
  • the first storage page is a valid storage page; if the counter in the first storage page The maximum value of the serial number is smaller than the maximum value of the counter number in the second storage page, and the second storage page is a valid storage page.
  • the power-off protection of the counter information can be implemented. Reduces the number of operations required for backup operations, further increasing the read and write rate of the counter.
  • FIG. 3 is a flowchart of a method for reading and writing a counter according to a second embodiment of the present invention.
  • the operation request is a read operation request, which is further defined based on the foregoing embodiment.
  • step S4 the method further includes:
  • Step S51 determining, according to the first storage page and the counter information stored in the second storage page, maximum values of counter numbers in the first storage page and the second storage page, respectively;
  • Step S52 respectively determining an offset address of a maximum value of the counter serial number in the first storage page and the second storage page with respect to a first address of the first storage page;
  • step S4 includes:
  • Step S41 reading the value of the counter according to the operation request and the offset value of the maximum value of the counter number in the valid storage page with respect to the first address of the first storage page.
  • the method may further include erasing, when the check values of the first storage page and the second storage page are correct, erasing the storage page storing the maximum value of the counter serial number.
  • step S51 in this embodiment and S35 in the second embodiment respectively determine the first storage page and the location according to the counter information stored in the first storage page and the second storage page.
  • the maximum value of the counter number in the second memory page has the same effect.
  • FIG. 4 is a flowchart of a method for reading and writing a counter according to still another embodiment of the present invention.
  • the operation request when the operation request is a write operation request, further limiting is performed on the basis of the foregoing embodiment. .
  • the operation request further includes counter information to be written;
  • step S4 the method further includes:
  • Step S53 respectively acquiring an offset address of the first storage page and the next available address of the second storage page with respect to the first address of the first storage page.
  • Step S4 includes steps S42 to S44, wherein:
  • step S42 if only the check value of one stored page is valid, the stored page whose check value is invalid 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.
  • Step S44 If the check values of the first storage page and the second storage page are both valid, the storage page storing the smallest value of the counter serial number is erased.
  • the counter information that needs to be updated is saved to the second page, and then the entire page is erased.
  • the valid memory page By erasing the memory page whose check value is invalid when the check value of only one memory page is valid, according to the counter information to be written in the operation request, the valid memory page The counter information is written in the next available address; 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 counter serial number is stored
  • erasing it is possible to update only the counter information, that is, 8 bytes when the counter is updated, and an erasing operation is required when the page is full, which reduces the time for counter update and further improves the instruction execution efficiency.
  • FIG. 5 is a schematic structural diagram of a read/write device for a counter according to another embodiment of the present invention. As shown in FIG. 5, the device 10 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 the first storage page, wherein the first storage page corresponds to the counter in the FLASH chip The first page of multiple storage pages.
  • the obtaining module 2 is configured to acquire the counter information stored in the first storage page and the second storage page, wherein the counter information comprises: a serial number, a check value, and a counter value, where the second storage page is The next memory page of the first memory page corresponding to the counter in the FLASH chip.
  • the calculation module 3 is configured to determine a valid storage page according to the counter information stored in the first storage page and the second storage page.
  • the processing module 4 is configured to perform an operation process corresponding to the operation request according to the operation request and the counter information in the valid storage page.
  • the counter information comprises: a serial number, a check value, and a counter value; according to the first storage page and the second Storing the counter information stored in the page, determining a valid storage page; performing operation processing corresponding to the operation request according to the operation request and counter information in the valid storage page, thereby implementing power-off protection of the counter information, reducing The multiple operations required for the backup operation increase the read/write rate of the counter.
  • the above-mentioned counter reading and writing method is implemented in the form of a software function module, and is sold or used as an independent product, it may also be stored in a computer readable storage medium.
  • the technical solution of the embodiments of the present invention may be embodied in the form of a software product in essence or in the form of a software product stored in a storage medium, including a plurality of instructions.
  • One terminal device is caused to perform all or part of the method described in various embodiments of the present invention.
  • the foregoing storage medium includes various media that can store program codes, such as a USB flash drive, a mobile hard disk, a read only memory (ROM), a magnetic disk, or an optical disk.
  • embodiments of the invention are not limited to any specific combination of hardware and software.
  • an embodiment of the present invention provides a terminal device, including a memory and a processor, where the memory stores a computer program executable on a processor, and when the processor executes the program, the counter in the foregoing embodiment is implemented.
  • the steps in the read and write methods are performed by the processor.
  • a computer readable storage medium storing a computer program thereon, when the computer program is executed by the processor, implements the steps in the method for reading and writing the counter in the above embodiment.
  • FIG. 6 is a schematic diagram of a hardware entity of a terminal device according to an embodiment of the present invention.
  • the hardware entity of the terminal device 600 includes: a processor 601, a communication interface 602, and a memory 603.
  • the processor 601 typically controls the overall operation of the terminal device 600.
  • Communication interface 602 can enable a terminal device to communicate with other terminals or servers over a network.
  • the memory 603 is configured to store instructions and applications executable by the processor 601, and may also cache data to be processed or processed by the processor 601 and each module in the terminal device 600 (eg, image data, audio data, voice communication data, and Video communication data) can be realized by flash memory (FLASH) or random access memory (RAM).
  • FLASH flash memory
  • RAM random access memory
  • the disclosed apparatus and method may be implemented in other manners.
  • the device embodiments described above are merely illustrative.
  • the division of the unit is only a logical function division.
  • there may be another division manner such as: multiple units or components may be combined, or Can be integrated into another system, or some features can be ignored or not executed.
  • the coupling, or direct coupling, or communication connection of the components shown or discussed may be indirect coupling or communication connection through some interfaces, devices or units, and may be electrical, mechanical or other forms. of.
  • the units described above as separate components may or may not be physically separated, and the components displayed as the unit may or may not be physical units; they may be located in one place or distributed on multiple network units; Some or all of the units may be selected according to actual needs to achieve the purpose of the solution of the embodiment.
  • the foregoing program may be stored in a computer readable storage medium, and when executed, the program includes The foregoing steps of the method embodiment; and the foregoing storage medium includes: a removable storage device, a read only memory, a magnetic disk, or an optical disk, and the like, which can store program codes.
  • the above-described integrated unit of the present invention may be stored in a computer readable storage medium if it is implemented in the form of a software function module and sold or used as a standalone product.
  • the technical solution of the embodiments of the present invention may be embodied in the form of a software product in essence or in the form of a software product stored in a storage medium, including a plurality of instructions.
  • One terminal device is caused to perform all or part of the method described in various embodiments of the present invention.
  • the foregoing storage medium includes various media that can store program codes, such as a mobile storage device, a ROM, a magnetic disk, or an optical disk.
  • the counter information stored in the first storage page and the second storage page is obtained, wherein the counter information includes: a serial number, a check value, and a counter value; according to the first storage page And the counter information stored in the second storage page, determining a valid storage page; performing operation processing corresponding to the operation request according to the operation request and the counter information in the valid storage page, and the power of the counter information can be implemented Protection reduces the number of operations required for backup operations and increases the read/write rate of the counter.

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芯片中与计数器对应的第一存储页的下一存储页;根据第一存储页以及第二存储页中存储的计数器信息,确定有效存储页;根据操作请求以及有效存储页中的计数器信息,执行与操作请求对应的操作处理。

Description

一种计数器的读写方法及装置、设备、存储介质
相关申请的交叉引用
本申请基于申请号为201710944123.4、申请日为2017年09月30日的中国专利申请提出,并要求该中国专利申请的优先权,该中国专利申请的全部内容在此以全文引入的方式引入本申请。
技术领域
本发明涉及通信技术领域,尤其涉及一种计数器的读写方法及装置、设备、存储介质。
背景技术
目前,随着电力通信的发展,集中器、采集终端等终端设备的使用越来越多。为了保证设备的安全,通常会将终端嵌入式安全控制模块,(Terminal Embedded Secure Access Module,TESAM)安装到集中器和采集终端等终端设备中,作为设备的安全认证模块。在终端设备通过TESAM与应用平台之间进行交互时会用到各种不同的计数器,计数器的读写速度会严重影响集中器和采集终端等终端设备等的处理效率。
计数器一般在闪存(Flash EEPROM Memory,FLASH)中实际占用4个字节存储。现有技术中,读计数器时直接到计数器对应的FLASH地址读取;更新计数器时,按照现有的掉电保护方式需要将数据备份到写保护区、在写保护控制区对写保护区的数据标记、在写实际地址中写入数据以及擦除写保护控制区4次擦写。
基于此,本发明的发明人发现,现有技术中现有的计数器读写方法,更新计数器时需要进行多次擦写,增加了指令的执行时间,降低了集中器 和采集终端等终端设备等的处理效率。
公开于该背景技术部分的信息仅仅旨在增加对本发明的总体背景的理解,而不应当被视为承认或以任何形式暗示该信息构成已为本领域一般技术人员所公知的现有技术。
发明内容
有鉴于此,本发明实施例提供一种计数器的读写方法及装置、设备、存储介质。
本发明实施例在第一方面提供一种计数器的读写方法,包括:接收操作请求,其中所述操作请求包括第一存储页的地址,其中,所述第一存储页为在FLASH芯片中与所述计数器对应的多个存储页中的首页;获取所述第一存储页以及第二存储页中存储的计数器信息,其中,所述计数器信息包括:序列号、校验值以及计数器值,所述第二存储页为在FLASH芯片中与所述计数器对应的所述第一存储页的下一存储页;根据所述第一存储页以及第二存储页中存储的计数器信息,确定有效存储页;根据所述操作请求以及所述有效存储页中的计数器信息,执行与所述操作请求对应的操作处理。
在一种可能的实现方式中,所述根据所述第一存储页以及第二存储页中存储的计数器信息,确定有效存储页包括:根据所述第一存储页以及所述第二存储页中存储的计数器信息,分别判断所述第一存储页以及所述第二存储页是否为空;若所述第一存储页以及所述第二存储页都为空,则所述第一存储页为有效存储页。
在一种可能的实现方式中,所述根据所述第一存储页以及所述第二存储页中存储的计数器信息,分别判断所述第一存储页以及所述第二存储页是否为空之后,还包括:若所述第一存储页以及所述第二存储页至少有一个不为空,则分别判断所述第一存储页以及所述第二存储页的校验值是否 有效;若仅存在一个存储页的校验值有效,则校验值有效的存储页为有效存储页。
在一种可能的实现方式中,所述分别判断所述第一存储页以及所述第二存储页的校验值是否有效包括:分别判断所述第一存储页以及所述第二存储页中存储的计数器信息的校验值是否正确;若所述第一存储页中存储的计数器信息的校验值至少一个正确,则所述第一存储页的校验值有效;若所述第二存储页中存储的计数器信息的校验值至少一个正确,则所述第二存储页的校验值有效。
在一种可能的实现方式中,所述分别判断所述第一存储页以及所述第二存储页的校验值是否有效之后,还包括:若所述第一存储页以及所述第二存储页的校验值均有效,则根据所述第一存储页以及所述第二存储页中存储的计数器信息,分别确定所述第一存储页以及所述第二存储页中的计数器序号的最大值;比较所述第一存储页中的计数器序号的最大值以及所述第二存储页中的计数器序号的最大值,将存储有最大的所述计数器序号的最大值的存储页作为有效存储页。
在一种可能的实现方式中,当所述操作请求为读操作请求时,在所述根据所述操作请求以及所述有效存储页中的计数器信息,执行与所述操作请求对应的操作处理之前,还包括:根据所述第一存储页以及所述第二存储页中存储的计数器信息,分别确定所述第一存储页以及所述第二存储页中的计数器序号的最大值;分别确定所述第一存储页以及所述第二存储页中的计数器序号的最大值相对于第一存储页的首地址的偏移地址;所述根据所述操作请求以及所述有效存储页中的计数器信息,执行与所述操作请求对应的操作处理,包括:根据所述操作请求以及所述有效存储页中的计数器序号的最大值相对于第一存储页的首地址的偏移地址,读取所述计数器的值。
在一种可能的实现方式中,当所述操作请求为写操作请求时,所述操作请求还包括待写入的计数器信息;在所述根据所述操作请求以及所述有效存储页中的计数器信息,执行与所述操作请求对应的操作处理之前,还包括:分别获取所述第一存储页以及所述第二存储页的下一可用地址相对于第一存储页的首地址的偏移地址;所述根据所述操作请求以及所述有效存储页中的计数器信息,执行与所述操作请求对应的操作处理,包括:若仅存在一个存储页的校验值有效,则对所述校验值无效的存储页进行擦除;根据所述操作请求中待写入的计数器信息,在所述有效存储页的下一可用地址中写入所述计数器信息。
在一种可能的实现方式中,所述根据所述操作请求以及所述有效存储页中的计数器信息,执行与所述操作请求对应的操作处理,还包括:若所述第一存储页以及所述第二存储页的校验值均有效,则对存储有小的所述计数器序号的最大值的存储页进行擦除。
本发明实施例在第二方面提供一种计数器的读写装置,包括:接收模块,配置为接收操作请求,其中所述操作请求包括第一存储页的地址,其中,所述第一存储页为在FLASH芯片中与所述计数器对应的多个存储页中的首页;获取模块,配置为获取所述第一存储页以及第二存储页中存储的计数器信息,其中,所述计数器信息包括:序列号、校验值以及计数器值,所述第二存储页为在FLASH芯片中与所述计数器对应的所述第一存储页的下一存储页;计算模块,配置为根据所述第一存储页以及第二存储页中存储的计数器信息,确定有效存储页;处理模块,配置为根据所述操作请求以及所述有效存储页中的计数器信息,执行与所述操作请求对应的操作处理。
本发明实施例在第三方面提供一种终端设备,包括存储器和处理器,所述存储器存储有可在处理器上运行的计算机程序,所述处理器执行所述 程序时实现上述实施例中的计数器的读写方法中的步骤。
本发明实施例在第四方面提供一种计算机可读存储介质,其上存储有计算机程序,该计算机程序被处理器执行时实现上述实施例中的计数器的读写方法中的步骤。
本发明实施例提供的计数器的读写方法及装置、设备、存储介质,通过获取所述第一存储页以及第二存储页中存储的计数器信息,其中,所述计数器信息包括:序列号、校验值以及计数器值;根据所述第一存储页以及第二存储页中存储的计数器信息,确定有效存储页;根据所述操作请求以及所述有效存储页中的计数器信息,执行与所述操作请求对应的操作处理,可以实现计数器信息的断电保护,减少了备份操作所需要的多次操作,提高了计数器的读写速率。
根据下面参考附图对示例性实施例的详细说明,本发明的其它特征及方面将变得清楚。
附图说明
包含在说明书中并且构成说明书的一部分的附图与说明书一起示出了本发明的示例性实施例、特征和方面,并且用于解释本发明的原理。
图1示出本发明一实施例提供的计数器的读写方法的流程图;
图2为本发明又一实施例提供的计数器的读写方法的流程图;
图3为本发明下一实施例提供的计数器的读写方法的流程图;
图4为本发明再一实施例提供的计数器的读写方法的流程图;
图5示出本发明另一实施例提供的计数器的读写装置的结构示意图;
图6为本发明实施例中终端设备的一种硬件实体示意图。
具体实施方式
下面结合附图,对本发明实施例的实施方式进行详细描述,但应当理 解本发明的保护范围并不受实施方式的限制。
为使本发明实施例的目的、技术方案和优点更加清楚,下面将结合本发明实施例中的附图,对本发明实施例中的技术方案进行清楚、完整地描述,显然,所描述的实施例是本发明一部分实施例,而不是全部的实施例。基于本发明中的实施例,本领域普通技术人员在没有作出创造性劳动前提下所获得的所有其他实施例,都属于本发明保护的范围。除非另有其它明确表示,否则在整个说明书和权利要求书中,术语“包括”或其变换如“包含”或“包括有”等等将被理解为包括所陈述的元件或组成部分,而并未排除其它元件或其它组成部分。
在这里专用的词“示例性”意为“用作例子、实施例或说明性”。这里作为“示例性”所说明的任何实施例不必解释为优于或好于其它实施例。
另外,为了更好的说明本发明的技术方案,在下文的实施方式中给出了众多的细节。本领域技术人员应当理解,没有某些细节,本发明同样可以实施。在一些实例中,对于本领域技术人员熟知的方法、手段、元件未作详细描述,以便于凸显本发明的主旨。
实施例1
FALSH芯片的读写一般是按块或页操作,即使写入数据只有1字节,实际写入时也要对包含该字节的整块或页数据进行擦写。FLASH芯片的这种读写特性,会大大增加数据写入时间,对一些需要频繁更新FLASH的指令的执行时间会产生很大影响。按照常规的掉电保护方案对计数器进行更新时,在要求更新4字节数据的情况下,实际进行了4页数据的擦除和写入操作,这些操作的时间成为指令执行时间长短的关键因素。
FLASH芯片根据其擦写性能的区别分成了两类。第一类芯片,只要修改某处的数据,就要擦掉重写;第二类芯片,支持数据的比特位由1写到0,不支持比特位由0写到1。本提案针对第二类芯片进行优化。
在保证计数器的正确性和有效性,同时减少擦除次数,使用多个完整的页来保存一个计数器,通过增加存储空间和存储内容来保证计数器的合法性。
图1示出本发明一实施例提供的计数器的读写方法的流程图,如图1所示,该方法包括以下步骤。
步骤S1,接收操作请求,其中所述操作请求包括第一存储页的地址,其中,所述第一存储页为在FLASH芯片中与所述计数器对应的多个存储页中的首页。
步骤S2,获取所述第一存储页以及第二存储页中存储的计数器信息,其中,所述计数器信息包括:序列号、校验值以及计数器值,所述第二存储页为在FLASH芯片中与所述计数器对应的所述第一存储页的下一存储页。
在其他的实施例中,存储页为FALSH芯片是为了方便管理划分的存储单位,一个存储页中存储了多条计数器信息。读写时需要同时指定页地址和页内的偏移地址。本实施例中计数器对应的存储空间可以为多页,本实施例中以第一存储页和第二存储页为例进行说明,但并不限于两页。
计数器信息包括:序列号,用来验证计数器的合法性的校验值,计数器值,还可以包括预留字节。计数器信息的结构可以参阅表1:
元素 长度 说明
num 1字节(byte) 计数器序列号
counter 4byte 实际有效的计数器值
crc 1byte num和counter的CRC校验和
rf 2byte 为了对齐的预留字节
表1
在执行芯片初始化指令时,需要对计数器对应的多个存储页进行初始 化。将计数器对应的多个存储页的存储空间初始化为0xFF,并将第一存储页的第一条计数器信息初始化为0100000000010000,以保证页有效。
步骤S3,根据所述第一存储页以及第二存储页中存储的计数器信息,确定有效存储页。
其中,有效存储页中存储的计数器信息均为正确的计数器信息。
步骤S4,根据所述操作请求以及所述有效存储页中的计数器信息,执行与所述操作请求对应的操作处理。
在其他的实施例中,根据读操作请求或写操作请求,对计数器的值进行读取或者更新。
由此,通过获取所述第一存储页以及第二存储页中存储的计数器信息,其中,所述计数器信息包括:序列号、校验值以及计数器值;根据所述第一存储页以及第二存储页中存储的计数器信息,确定有效存储页;根据所述操作请求以及所述有效存储页中的计数器信息,执行与所述操作请求对应的操作处理,可以实现计数器信息的断电保护,减少了备份操作所需要的多次操作,提高了计数器的读写速率。
实施例2
图2为本发明又一实施例提供的计数器的读写方法的流程图,请参阅图2,本实施例在实施例一的基础上,对步骤S3进行进一步限定。
本实施例中步骤S3可以包括:
步骤S31,根据所述第一存储页以及所述第二存储页中存储的计数器信息,分别判断所述第一存储页以及所述第二存储页是否为空。
在其他的实施例中,在FLASH芯片出厂时,存储页中的存储空间被初始化为0xFF,也就是说,可以通过判断是否整页数据都为0xFF来判断储页是否为空。获取存储页中存储的计数器信息,若当前存储页中存储的计数器信息都为0xFF,则当前存储页为空。
步骤S32,若所述第一存储页以及所述第二存储页都为空,则所述第一存储页为有效存储页。
步骤S33,若所述第一存储页以及所述第二存储页至少有一个不为空,则分别判断所述第一存储页以及所述第二存储页的校验值是否有效。
在其他的实施例中,通过计数器信息中的校验值来判断。
可以包括:
步骤S331,分别判断所述第一存储页以及所述第二存储页中存储的计数器信息的校验值是否正确;
在其他的实施例中,该步骤S331包括:在执行操作时,对当前的计数器值进行校验计算,若根据计数器值计算出的校验值与计数器信息的校验值相同,则该计数器信息的校验值正确。
步骤S332,若所述第一存储页中存储的计数器信息的校验值至少一个正确,则所述第一存储页的校验值有效。
步骤S333,若所述第二存储页中存储的计数器信息的校验值至少一个正确,则所述第二存储页的校验值有效。
由此,通过存储页的校验值是否正确来保证计数器值得有效性。避免在掉电过程中,没有更新或写入完成时,计数器值不准确的问题。
步骤S34,若仅存在一个存储页的校验值有效,则校验值有效的存储页为有效存储页。
在其他的实施例中,当所述第一存储页以及所述第二存储页至少有一个不为空且仅存在一个存储页的校验值正确时,包括了第一存储页不为空且有效,第二存储页为空或无效;第二存储页不为空且有效,第一存储页为空或无效;第一存储页、第二存储页都不为空,但只有一个有效的情况。
步骤S35,若所述第一存储页以及所述第二存储页的校验值均有效,则根据所述第一存储页以及所述第二存储页中存储的计数器信息,分别确定 所述第一存储页以及所述第二存储页中的计数器序号的最大值。
在其他的实施例中,分别确定所述第一存储页以及所述第二存储页中的计数器序号的最大值,获取第一存储页中所有的计数器序号,将该存储页中的计数器序号进行对比,选择其中的最大值,作为第一存储页的计数器序号的最大值;获取第二存储页中所有的计数器序号,将该存储页中的计数器序号进行对比,选择其中的最大值,作为第二存储页的计数器序号的最大值。需要说明的是,在对计数器值更新时,系统自动分配计数器序号,计数器序号最大的即为最新存储的计数器值。
步骤S36,比较所述第一存储页中的计数器序号的最大值以及所述第二存储页中的计数器序号的最大值,将存储有最大的所述计数器序号的最大值的存储页作为有效存储页。
在其他的实施例中,若第一存储页中的计数器序号的最大值大于第二存储页中的计数器序号的最大值,则第一存储页为有效存储页;若第一存储页中的计数器序号的最大值小于第二存储页中的计数器序号的最大值,则第二存储页为有效存储页。
由此,本实施例通过判断第一存储页、第二存储页是否为空,当不为空时,通过判断存储页的校验值来确定有效存储页,可以实现计数器信息的断电保护,减少了备份操作所需要的多次操作,进一步提高了计数器的读写速率。
实施例3
图3为本发明下一实施例提供的计数器的读写方法的流程图,请参阅图3,本实施例中,操作请求为读操作请求,在上述实施例的基础上进行进一步限定。
在步骤S4之前,还包括:
步骤S51,根据所述第一存储页以及所述第二存储页中存储的计数器信 息,分别确定所述第一存储页以及所述第二存储页中的计数器序号的最大值;
步骤S52,分别确定所述第一存储页以及所述第二存储页中的计数器序号的最大值相对于第一存储页的首地址的偏移地址;
则步骤S4包括:
步骤S41,根据所述操作请求以及所述有效存储页中的计数器序号的最大值相对于第一存储页的首地址的偏移地址,读取所述计数器的值。
还可以包括,若所述第一存储页以及所述第二存储页的校验值均正确,则对存储有小的所述计数器序号的最大值的存储页进行擦除。
需要说明的是,本实施例中的步骤S51与实施例二中的S35的根据所述第一存储页以及所述第二存储页中存储的计数器信息,分别确定所述第一存储页以及所述第二存储页中的计数器序号的最大值,作用相同。
由此,通过分别确定所述第一存储页以及所述第二存储页中的计数器序号的最大值相对于第一存储页的首地址的偏移地址;根据所述操作请求以及所述有效存储页中的计数器序号的最大值相对于第一存储页的首地址的偏移地址,读取所述计数器的值,可以实现计数器信息的断电保护,减少了备份操作所需要的多次操作,进一步提高了计数器的读写速率。
实施例4
图4为本发明再一实施例提供的计数器的读写方法的流程图,请参阅图4,本实施例中,所述操作请求为写操作请求时,在上述实施例的基础上进行进一步限定。其中,操作请求还包括待写入的计数器信息;
在步骤S4之前还包括:
步骤S53,分别获取所述第一存储页以及所述第二存储页的下一可用地址相对于第一存储页的首地址的偏移地址。
步骤S4包括步骤S42至步骤S44,其中:
步骤S42,若仅存在一个存储页的校验值有效,则对所述校验值无效的存储页进行擦除。
步骤S43,根据所述操作请求中待写入的计数器信息,在所述有效存储页的下一可用地址中写入所述计数器信息。
步骤S44,若所述第一存储页以及所述第二存储页的校验值均有效,则对存储有小的所述计数器序号的最大值的存储页进行擦除。
在其他的实施例中,当第一存储页空间用完时,把需要更新的计数器信息保存到第二页,然后再对第一页进行整页擦除。
由此,通过当仅存在一个存储页的校验值有效时,对所述校验值无效的存储页进行擦除,根据所述操作请求中待写入的计数器信息,在所述有效存储页的下一可用地址中写入所述计数器信息;若所述第一存储页以及所述第二存储页的校验值均有效,则对存储有小的所述计数器序号的最大值的存储页进行擦除,可以实现当更新计数器时,只更新计数器信息也就是8个字节,写满一页时才需要进行一次擦除操作,减少了计数器更新的时间,进一步提高了指令执行效率。
实施例5
图5示出本发明另一实施例提供的计数器的读写装置的结构示意图,如图5所示,该装置10包括接收模块1、获取模块2、计算模块3和处理模块4。
接收模块1,配置为接收操作请求,其中所述操作请求包括读操作请求或写操作请求,以及第一存储页的地址,其中,所述第一存储页为在FLASH芯片中与所述计数器对应的多个存储页中的首页。
获取模块2,配置为获取所述第一存储页以及第二存储页中存储的计数器信息,其中,所述计数器信息包括:序列号、校验值以及计数器值,所述第二存储页为在FLASH芯片中与所述计数器对应的所述第一存储页的 下一存储页。
计算模块3,配置为根据所述第一存储页以及第二存储页中存储的计数器信息,确定有效存储页。
处理模块4,配置为根据所述操作请求以及所述有效存储页中的计数器信息,执行与所述操作请求对应的操作处理。
由此,通过获取所述第一存储页以及第二存储页中存储的计数器信息,其中,所述计数器信息包括:序列号、校验值以及计数器值;根据所述第一存储页以及第二存储页中存储的计数器信息,确定有效存储页;根据所述操作请求以及所述有效存储页中的计数器信息,执行与所述操作请求对应的操作处理,可以实现计数器信息的断电保护,减少了备份操作所需要的多次操作,提高了计数器的读写速率。
前述对本发明实施例的示例性实施方案的描述是为了说明和例证的目的。这些描述并非想将本发明实施例限定为所公开的精确形式,并且很显然,根据上述教导,可以进行很多改变和变化。对示例性实施例进行选择和描述的目的在于解释本发明实施例的特定原理及其实际应用,从而使得本领域的技术人员能够实现并利用本发明实施例的各种不同的示例性实施方案以及各种不同的选择和改变。本发明实施例的范围意在由权利要求书及其等同形式所限定。
以上装置实施例的描述,与上述方法实施例的描述是类似的,具有同方法实施例相似的有益效果。对于本发明装置实施例中未披露的技术细节,请参照本发明方法实施例的描述而理解。
需要说明的是,本发明实施例中,如果以软件功能模块的形式实现上述的计数器的读写方法,并作为独立的产品销售或使用时,也可以存储在一个计算机可读取存储介质中。基于这样的理解,本发明实施例的技术方案本质上或者说对现有技术做出贡献的部分可以以软件产品的形式体现出 来,该计算机软件产品存储在一个存储介质中,包括若干指令用以使得一台终端设备执行本发明各个实施例所述方法的全部或部分。而前述的存储介质包括:U盘、移动硬盘、只读存储器(Read Only Memory,ROM)、磁碟或者光盘等各种可以存储程序代码的介质。这样,本发明实施例不限制于任何特定的硬件和软件结合。
对应地,本发明实施例提供一种终端设备,包括存储器和处理器,所述存储器存储有可在处理器上运行的计算机程序,所述处理器执行所述程序时实现上述实施例中的计数器的读写方法中的步骤。
对应地,本发明实施例一种计算机可读存储介质,其上存储有计算机程序,该计算机程序被处理器执行时实现上述实施例中的计数器的读写方法中的步骤。
这里需要指出的是:以上存储介质和设备实施例的描述,与上述方法实施例的描述是类似的,具有同方法实施例相似的有益效果。对于本发明存储介质和设备实施例中未披露的技术细节,请参照本发明方法实施例的描述而理解。
需要说明的是,图6为本发明实施例中终端设备的一种硬件实体示意图,如图6所示,该终端设备600的硬件实体包括:处理器601、通信接口602和存储器603,其中
处理器601通常控制终端设备600的总体操作。
通信接口602可以使终端设备通过网络与其他终端或服务器通信。
存储器603配置为存储由处理器601可执行的指令和应用,还可以缓存待处理器601以及终端设备600中各模块待处理或已经处理的数据(例如,图像数据、音频数据、语音通信数据和视频通信数据),可以通过闪存(FLASH)或随机访问存储器(Random Access Memory,RAM)实现。
应理解,说明书通篇中提到的“一个实施例”或“一实施例”意味着 与实施例有关的特定特征、结构或特性包括在本发明的至少一个实施例中。因此,在整个说明书各处出现的“在一个实施例中”或“在一实施例中”未必一定指相同的实施例。此外,这些特定的特征、结构或特性可以任意适合的方式结合在一个或多个实施例中。应理解,在本发明的各种实施例中,上述各过程的序号的大小并不意味着执行顺序的先后,各过程的执行顺序应以其功能和内在逻辑确定,而不应对本发明实施例的实施过程构成任何限定。上述本发明实施例序号仅仅为了描述,不代表实施例的优劣。
需要说明的是,在本文中,术语“包括”、“包含”或者其任何其他变体意在涵盖非排他性的包含,从而使得包括一系列要素的过程、方法、物品或者装置不仅包括那些要素,而且还包括没有明确列出的其他要素,或者是还包括为这种过程、方法、物品或者装置所固有的要素。在没有更多限制的情况下,由语句“包括一个……”限定的要素,并不排除在包括该要素的过程、方法、物品或者装置中还存在另外的相同要素。
在本申请所提供的几个实施例中,应该理解到,所揭露的设备和方法,可以通过其它的方式实现。以上所描述的设备实施例仅仅是示意性的,例如,所述单元的划分,仅仅为一种逻辑功能划分,实际实现时可以有另外的划分方式,如:多个单元或组件可以结合,或可以集成到另一个系统,或一些特征可以忽略,或不执行。另外,所显示或讨论的各组成部分相互之间的耦合、或直接耦合、或通信连接可以是通过一些接口,设备或单元的间接耦合或通信连接,可以是电性的、机械的或其它形式的。
上述作为分离部件说明的单元可以是、或也可以不是物理上分开的,作为单元显示的部件可以是、或也可以不是物理单元;既可以位于一个地方,也可以分布到多个网络单元上;可以根据实际的需要选择其中的部分或全部单元来实现本实施例方案的目的。
本领域普通技术人员可以理解:实现上述方法实施例的全部或部分步 骤可以通过程序指令相关的硬件来完成,前述的程序可以存储于计算机可读取存储介质中,该程序在执行时,执行包括上述方法实施例的步骤;而前述的存储介质包括:移动存储设备、只读存储器、磁碟或者光盘等各种可以存储程序代码的介质。或者,本发明上述集成的单元如果以软件功能模块的形式实现并作为独立的产品销售或使用时,也可以存储在一个计算机可读取存储介质中。基于这样的理解,本发明实施例的技术方案本质上或者说对现有技术做出贡献的部分可以以软件产品的形式体现出来,该计算机软件产品存储在一个存储介质中,包括若干指令用以使得一台终端设备执行本发明各个实施例所述方法的全部或部分。而前述的存储介质包括:移动存储设备、ROM、磁碟或者光盘等各种可以存储程序代码的介质。
以上所述,仅为本发明的实施方式,但本发明的保护范围并不局限于此,任何熟悉本技术领域的技术人员在本发明揭露的技术范围内,可轻易想到变化或替换,都应涵盖在本发明的保护范围之内。因此,本发明的保护范围应以所述权利要求的保护范围为准。
工业实用性
本发明实施例中,通过获取所述第一存储页以及第二存储页中存储的计数器信息,其中,所述计数器信息包括:序列号、校验值以及计数器值;根据所述第一存储页以及第二存储页中存储的计数器信息,确定有效存储页;根据所述操作请求以及所述有效存储页中的计数器信息,执行与所述操作请求对应的操作处理,可以实现计数器信息的断电保护,减少了备份操作所需要的多次操作,提高了计数器的读写速率。

Claims (11)

  1. 一种计数器的读写方法,包括:
    接收操作请求,其中所述操作请求包括第一存储页的地址,其中,所述第一存储页为在闪存FLASH芯片中与所述计数器对应的多个存储页中的首页;
    获取所述第一存储页以及第二存储页中存储的计数器信息,其中,所述计数器信息包括:序列号、校验值以及计数器值,所述第二存储页为在FLASH芯片中与所述计数器对应的所述第一存储页的下一存储页;
    根据所述第一存储页以及第二存储页中存储的计数器信息,确定有效存储页;
    根据所述操作请求以及所述有效存储页中的计数器信息,执行与所述操作请求对应的操作处理。
  2. 根据权利要求1所述的计数器的读写方法,所述根据所述第一存储页以及第二存储页中存储的计数器信息,确定有效存储页包括:
    根据所述第一存储页以及所述第二存储页中存储的计数器信息,分别判断所述第一存储页以及所述第二存储页是否为空;
    若所述第一存储页以及所述第二存储页都为空,则所述第一存储页为有效存储页。
  3. 根据权利要求2所述的计数器的读写方法,所述根据所述第一存储页以及所述第二存储页中存储的计数器信息,分别判断所述第一存储页以及所述第二存储页是否为空之后,还包括:
    若所述第一存储页以及所述第二存储页至少有一个不为空,则分别判断所述第一存储页以及所述第二存储页的校验值是否有效;
    若仅存在一个存储页的校验值有效,则校验值有效的存储页为有效存储页。
  4. 根据权利要求3所述的计数器的读写方法,所述分别判断所述第一存储页以及所述第二存储页的校验值是否有效包括:
    分别判断所述第一存储页以及所述第二存储页中存储的计数器信息的校验值是否正确;
    若所述第一存储页中存储的计数器信息的校验值至少一个正确,则所述第一存储页的校验值有效;
    若所述第二存储页中存储的计数器信息的校验值至少一个正确,则所述第二存储页的校验值有效。
  5. 根据权利要求3所述的计数器的读写方法,所述分别判断所述第一存储页以及所述第二存储页的校验值是否有效之后,还包括:
    若所述第一存储页以及所述第二存储页的校验值均有效,则根据所述第一存储页以及所述第二存储页中存储的计数器信息,分别确定所述第一存储页以及所述第二存储页中的计数器序号的最大值;
    比较所述第一存储页中的计数器序号的最大值以及所述第二存储页中的计数器序号的最大值,将存储有最大的所述计数器序号的最大值的存储页作为有效存储页。
  6. 根据权利要求1至5任一项所述的计数器的读写方法,当所述操作请求为读操作请求时,在所述根据所述操作请求以及所述有效存储页中的计数器信息,执行与所述操作请求对应的操作处理之前,还包括:根据所述第一存储页以及所述第二存储页中存储的计数器信息,分别确定所述第一存储页以及所述第二存储页中的计数器序号的最大值;
    分别确定所述第一存储页以及所述第二存储页中的计数器序号的最大值相对于第一存储页的首地址的偏移地址;
    所述根据所述操作请求以及所述有效存储页中的计数器信息,执行与所述操作请求对应的操作处理,包括:
    根据所述操作请求以及所述有效存储页中的计数器序号的最大值相对于第一存储页的首地址的偏移地址,读取所述计数器的值。
  7. 根据权利要求3或5所述的计数器的读写方法,当所述操作请求为写操作请求时,所述操作请求还包括待写入的计数器信息;在所述根据所述操作请求以及所述有效存储页中的计数器信息,执行与所述操作请求对应的操作处理之前,还包括:
    分别获取所述第一存储页以及所述第二存储页的下一可用地址相对于第一存储页的首地址的偏移地址;
    所述根据所述操作请求以及所述有效存储页中的计数器信息,执行与所述操作请求对应的操作处理,包括:
    若仅存在一个存储页的校验值有效,则对所述校验值无效的存储页进行擦除;
    根据所述操作请求中待写入的计数器信息,在所述有效存储页的下一可用地址中写入所述计数器信息。
  8. 根据权利要求7所述的计数器的读写方法,所述根据所述操作请求以及所述有效存储页中的计数器信息,执行与所述操作请求对应的操作处理,还包括:
    若所述第一存储页以及所述第二存储页的校验值均有效,则对存储有小的所述计数器序号的最大值的存储页进行擦除。
  9. 一种计数器的读写装置,包括:
    接收模块,配置为接收操作请求,其中所述操作请求包括第一存储页的地址,其中,所述第一存储页为在FLASH芯片中与所述计数器对应的多个存储页中的首页;
    获取模块,配置为获取所述第一存储页以及第二存储页中存储的计数器信息,其中,所述计数器信息包括:序列号、校验值以及计数器值, 所述第二存储页为在FLASH芯片中与所述计数器对应的所述第一存储页的下一存储页;
    计算模块,配置为根据所述第一存储页以及第二存储页中存储的计数器信息,确定有效存储页;
    处理模块,配置为根据所述操作请求以及所述有效存储页中的计数器信息,执行与所述操作请求对应的操作处理。
  10. 一种终端设备,包括存储器和处理器,所述存储器存储有可在处理器上运行的计算机程序,所述处理器执行所述程序时实现权利要求1至8任一项所述计数器的读写方法中的步骤。
  11. 一种计算机可读存储介质,其上存储有计算机程序,该计算机程序被处理器执行时实现权利要求1至8任一项所述计数器的读写方法中的步骤。
PCT/CN2018/087174 2017-09-30 2018-05-16 一种计数器的读写方法及装置、设备、存储介质 Ceased WO2019062147A1 (zh)

Applications Claiming Priority (2)

Application Number Priority Date Filing Date Title
CN201710944123.4 2017-09-30
CN201710944123.4A CN107678977B (zh) 2017-09-30 2017-09-30 一种计数器的读写方法及装置

Publications (1)

Publication Number Publication Date
WO2019062147A1 true WO2019062147A1 (zh) 2019-04-04

Family

ID=61140710

Family Applications (1)

Application Number Title Priority Date Filing Date
PCT/CN2018/087174 Ceased WO2019062147A1 (zh) 2017-09-30 2018-05-16 一种计数器的读写方法及装置、设备、存储介质

Country Status (2)

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

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN110276213A (zh) * 2019-06-24 2019-09-24 恒宝股份有限公司 一种智能卡及其敏感结果的存储和校验方法

Families Citing this family (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN107678977B (zh) * 2017-09-30 2021-01-05 北京智芯微电子科技有限公司 一种计数器的读写方法及装置
CN110729014A (zh) * 2019-10-17 2020-01-24 深圳忆联信息系统有限公司 Ssd存储擦除计数表备份的方法、装置、计算机设备及存储介质

Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN101089878A (zh) * 2006-06-16 2007-12-19 索尼株式会社 集成电路芯片、数据读取方法,和数据写入方法
US20130282961A1 (en) * 2012-04-19 2013-10-24 Kabushiki Kaisha Toshiba Semiconductor memory device and method of control thereof
CN105023612A (zh) * 2014-04-30 2015-11-04 质子世界国际公司 闪存中的双向计数器
CN107678977A (zh) * 2017-09-30 2018-02-09 北京智芯微电子科技有限公司 一种计数器的读写方法及装置

Family Cites Families (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US7093101B2 (en) * 2002-11-21 2006-08-15 Microsoft Corporation Dynamic data structures for tracking file system free space in a flash memory device
CN101079009A (zh) * 2007-07-06 2007-11-28 北京飞天诚信科技有限公司 一种限制读取敏感信息的方法和存储装置
KR20130042236A (ko) * 2011-10-18 2013-04-26 에스케이하이닉스 주식회사 메모리 시스템
US9330736B2 (en) * 2012-11-09 2016-05-03 Qualcomm Incorporated Processor memory optimization via page access counting
US9703492B2 (en) * 2015-05-19 2017-07-11 International Business Machines Corporation Page replacement algorithms for use with solid-state drives

Patent Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN101089878A (zh) * 2006-06-16 2007-12-19 索尼株式会社 集成电路芯片、数据读取方法,和数据写入方法
US20130282961A1 (en) * 2012-04-19 2013-10-24 Kabushiki Kaisha Toshiba Semiconductor memory device and method of control thereof
CN105023612A (zh) * 2014-04-30 2015-11-04 质子世界国际公司 闪存中的双向计数器
CN107678977A (zh) * 2017-09-30 2018-02-09 北京智芯微电子科技有限公司 一种计数器的读写方法及装置

Cited By (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN110276213A (zh) * 2019-06-24 2019-09-24 恒宝股份有限公司 一种智能卡及其敏感结果的存储和校验方法
CN110276213B (zh) * 2019-06-24 2021-03-16 恒宝股份有限公司 一种智能卡及其敏感结果的存储和校验方法

Also Published As

Publication number Publication date
CN107678977A (zh) 2018-02-09
CN107678977B (zh) 2021-01-05

Similar Documents

Publication Publication Date Title
CN101427323B (zh) 读取非易失性计算机存储器的系统和方法
JP5528782B2 (ja) 停電後の不揮発性メモリの回復
US10922234B2 (en) Method and system for online recovery of logical-to-physical mapping table affected by noise sources in a solid state drive
US20110231713A1 (en) Flash memory module
US9811275B2 (en) Memory system and data control method
US9058255B2 (en) Solid state drive and method for constructing logical-to-physical table thereof
US9563553B2 (en) Data storing method and embedded system
US20130262810A1 (en) Memory space management method and memory controller and memory storage device using the same
US10896125B2 (en) Garbage collection methods and memory systems for hybrid address mapping
TW201217968A (en) Data writing method, memory controller and memory storage apparatus
US20090259796A1 (en) Data writing method for non-volatile memory and storage system and controller using the same
CN104978154A (zh) 一种基于缓存操作的flash快速读写方法及系统
CN113885808A (zh) 映射信息记录方法以及存储器控制电路单元与存储装置
CN105808378B (zh) 元数据修复方法及装置
CN107045423B (zh) 存储器装置及其数据存取方法
JPH09198884A (ja) フラッシュメモリ管理方法
WO2019062147A1 (zh) 一种计数器的读写方法及装置、设备、存储介质
CN109685190B (zh) 一种ic卡掉电保护方法及装置
CN109960611B (zh) 数据恢复的方法、装置、电子设备及机器可读存储介质
US20080162782A1 (en) Using Transacted Writes and Caching Mechanism to Improve Write Performance in Multi-Level Cell Flash Memory
WO2018041151A1 (zh) 数据存储的方法、装置以及非易失性存储器
US10613973B1 (en) Garbage collection in solid state drives
CN107257281B (zh) Nor flash存储密钥记录的方法、装置及计算机可读存储介质
CN113434086B (zh) 数据存储方法、装置、非易失性存储器件和存储器
CN112433959B (zh) 实现数据存储处理的方法、装置、计算机存储介质及终端

Legal Events

Date Code Title Description
121 Ep: the epo has been informed by wipo that ep was designated in this application

Ref document number: 18860021

Country of ref document: EP

Kind code of ref document: A1

NENP Non-entry into the national phase

Ref country code: DE

122 Ep: pct application non-entry in european phase

Ref document number: 18860021

Country of ref document: EP

Kind code of ref document: A1