An external flash-based ring history data storage and reading method

CN122985654APending Publication Date: 2026-10-27HANGZHOU LIVOLTEK POWER CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202611089183.8
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2026-07-22
Publication Date
2026-10-27

AI Technical Summary

Technical Problem

[0003]现有外部Flash的数据存储方法存在以下问题:在频繁、高速写入场景下,若直接每笔数据均触发Flash写操作,会因Flash写入延迟(通常为毫秒级)导致后续数据无法及时处理而丢失

Benefits of technology

[0030]1. 本说明书实施例提供的方法及装置,通过读指针、写指针以及缓存区,有效隔离了数据产生的高速、随机过程与数据存储的低速、确定性过程,避免因Flash写入延迟导致的数据丢失,即使在写入过程中掉电,已存入Flash的数据完整,未写入数据存于缓存区,以保证数据完整。

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN122985654A_ABST
    Figure CN122985654A_ABST
Patent Text Reader

Abstract

The embodiment of the specification discloses a ring history data storage and reading method based on external Flash, which comprises the following steps: temporarily storing history data into a cache area in response to the history data generated by equipment operation; performing an accumulation operation based on the current value corresponding to a preset write pointer to determine the total number of generated history data; obtaining the current value corresponding to a preset read pointer; comparing the current value corresponding to the read pointer with the value obtained after the accumulation operation of the write pointer; if the current value corresponding to the read pointer is equal to the value obtained after the accumulation operation of the write pointer, it is determined that there is no data to be stored in the cache area, and the storage operation of the history data is skipped; if the current value corresponding to the read pointer is not equal to the value obtained after the accumulation operation of the write pointer, it is determined that there is data to be stored in the cache area, and the storage operation of the history data is performed. The high-speed and random process of data generation and the low-speed and deterministic process of data storage are isolated, and data loss caused by Flash write delay is avoided.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of power equipment data storage technology, and in particular to a method, apparatus, electronic device, and storage medium for storing and retrieving circular historical data based on external Flash memory. Background Technology

[0002] In fields such as industrial control, the Internet of Things (IoT), and smart meters, devices need to record historical information such as operating status, event logs, and sensor data over long periods. External Flash memory (such as SPI NOR Flash and NAND Flash) is widely used as a storage medium for historical data due to its advantages such as large capacity, low cost, and non-volatility when power is off.

[0003] Existing external Flash data storage methods have the following problems: In frequent, high-speed write scenarios, if each piece of data triggers a Flash write operation, subsequent data may be lost due to Flash write latency (typically on the order of milliseconds) failing to be processed in time. Furthermore, if a system power failure occurs during the write process, the ongoing operation may be incomplete. In summary, existing external Flash data storage methods pose a risk of data loss. Summary of the Invention

[0004] To address the problems existing in the prior art, this specification describes one or more embodiments of a method, apparatus, electronic device, and storage medium for storing and retrieving circular historical data based on external Flash memory.

[0005] According to the first aspect, a method for storing and retrieving circular historical data based on external Flash memory is provided, the method comprising:

[0006] In response to the historical data generated during device operation, the historical data is temporarily stored in the cache area, and an accumulation operation is performed based on the current value corresponding to the preset write pointer to determine the total number of historical data entries generated.

[0007] Obtain the current value corresponding to the preset read pointer, and compare the current value corresponding to the read pointer with the value after the write pointer is incremented. If the current value corresponding to the read pointer is equal to the value after the write pointer is incremented, it is determined that there is no data to be stored in the buffer area, and the storage operation of the historical data is skipped. If the current value corresponding to the read pointer is not equal to the value after the write pointer is incremented, it is determined that there is data to be stored in the buffer area, and the storage operation of the historical data is performed.

[0008] The storage operation of the historical data includes: based on the read / write address mapping relationship of the external Flash and the target write address, writing the historical data into the physical storage area of ​​the external Flash in a circular overlay manner, and updating the cumulative storage quantity of the historical data;

[0009] The receiving device sends a data read instruction, which carries a target number of reads. Based on the current value corresponding to the read pointer, the receiving device sequentially reads historical data that matches the target number of reads from the external Flash memory and sends the read historical data to the receiving device.

[0010] Preferably, the read / write address mapping relationship of the external Flash includes the write address and the start and end addresses of the storage area allocated for the historical data. The historical data has a corresponding fixed length. The step of writing the historical data into the physical storage area of ​​the external Flash in a circular overlay manner and updating the cumulative storage quantity of the historical data includes:

[0011] Determine whether the sum of the write address and the fixed length is less than or equal to the end address;

[0012] If so, the write address is shifted backward by the fixed length, and the cumulative storage quantity of historical data is updated;

[0013] If not, then perform a circular overwrite write operation, and update the write address and the cumulative storage quantity of the historical data after the write is completed.

[0014] Preferably, the updated write address = the starting address of the storage area allocated by the external Flash for historical data + (the current write address + the fixed length corresponding to the historical data - the starting address of the storage area allocated by the external Flash for historical data - (the ending address of the storage area allocated by the external Flash for historical data - the starting address of the storage area allocated by the external Flash for historical data + 1)).

[0015] Preferably, the method further includes: upon power-on, recovering the write address, write count, and read count from the information area of ​​the external Flash, determining the read / write address mapping relationship of the external Flash based on the write address, write count, and read count, wherein the write count is used to represent the number of historical data entries stored in the external Flash, and the read count is used to represent the number of historical data entries read by the external Flash.

[0016] Preferably, the method further includes: dividing the storage space of the external Flash into multiple storage blocks, and configuring the multiple storage blocks to perform a circular storage operation, wherein the circular storage operation includes: writing data to the current storage block in a preset order, and after the current storage block is full, jumping to the next storage block to continue writing, until the last storage block is full and returning to the first storage block to write in a circular manner.

[0017] Preferably, the method further includes: configuring storage variables for storing the read pointer and the write pointer, and updating the read pointer and the write pointer based on the modulo operation and the storage variables.

[0018] Preferably, the storage variable corresponding to the read pointer is equal to the storage variable corresponding to the write pointer.

[0019] According to the second aspect, a ring-shaped historical data storage and retrieval device based on external Flash is provided, the device comprising:

[0020] The data caching module is used to temporarily store the historical data generated during device operation in the cache area, and perform an accumulation operation based on the current value corresponding to the preset write pointer to determine the total number of historical data entries generated.

[0021] The storage determination module is used to obtain the current value corresponding to a preset read pointer and compare the current value corresponding to the read pointer with the value after the write pointer is accumulated. If the current value corresponding to the read pointer is equal to the value after the write pointer is accumulated, it is determined that there is no data to be stored in the cache area and the storage operation of the historical data is skipped. If the current value corresponding to the read pointer is not equal to the value after the write pointer is accumulated, it is determined that there is data to be stored in the cache area and the storage operation of the historical data is performed.

[0022] The data storage module, used to perform the storage operation of the historical data, includes: writing the historical data into the physical storage area of ​​the external Flash in a circular overlay manner based on the read / write address mapping relationship of the external Flash and the target write address, and updating the cumulative storage quantity of the historical data;

[0023] The data reading module is used to receive data reading instructions sent by the device. The data reading instructions carry a target number of data entries to be read. Based on the current value corresponding to the read pointer, the module sequentially reads historical data that matches the target number of data entries from the external Flash memory and sends the read historical data to the device.

[0024] According to a third aspect, an electronic device is provided, including a processor and a memory;

[0025] The processor is connected to the memory;

[0026] The memory is used to store executable program code;

[0027] The processor runs a program corresponding to the executable program code stored in the memory to perform the steps of the method provided as in the first aspect or any possible implementation thereof.

[0028] According to a fourth aspect, a computer-readable storage medium is provided having a computer program stored thereon, the computer-readable storage medium storing instructions that, when executed on a computer or processor, cause the computer or processor to perform the method provided as in the first aspect or any possible implementation thereof.

[0029] The beneficial effects of this invention are as follows:

[0030] 1. The methods and apparatus provided in the embodiments of this specification effectively isolate the high-speed, random process of data generation from the low-speed, deterministic process of data storage through read pointers, write pointers, and buffers, avoiding data loss due to Flash write delays. Even if power is lost during the writing process, the data already stored in Flash remains intact, and the unwritten data is stored in the buffer to ensure data integrity. Attached Figure Description

[0031] To more clearly illustrate the technical solutions in the embodiments of this application, the accompanying drawings used in the embodiments will be briefly introduced below. Obviously, the drawings described below are only some embodiments of this application. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.

[0032] Figure 1 This is a flowchart illustrating a method for storing and retrieving circular historical data based on external Flash memory, as specifically implemented in this manual.

[0033] Figure 2 This is a schematic diagram of a ring-shaped historical data storage and retrieval device based on external Flash in a specific implementation of this specification;

[0034] Figure 3 This is a schematic diagram of the structure of an electronic device used in a specific implementation of this specification. Detailed Implementation

[0035] The technical solutions in the embodiments of this application will be clearly and completely described below with reference to the accompanying drawings.

[0036] In the following description, the terms "first" and "second" are used for descriptive purposes only and should not be construed as indicating or implying relative importance. The following description provides multiple embodiments of this application, which can be substituted or combined with each other. Therefore, this application can also be considered to include all possible combinations of the same and / or different embodiments described. Thus, if one embodiment includes features A, B, and C, and another embodiment includes features B and D, then this application should also be considered to include embodiments containing one or more other possible combinations of A, B, C, and D, even if such embodiments are not explicitly described in the following text.

[0037] The following description provides examples and does not limit the scope, applicability, or examples set forth in the claims. Changes may be made to the function and arrangement of the described elements without departing from the scope of this application. Various processes or components may be appropriately omitted, substituted, or added to the examples. For example, the described methods may be performed in a different order than described, and various steps may be added, omitted, or combined. Furthermore, features described with respect to some examples may be combined into other examples.

[0038] See Figure 1 , Figure 1 This is a flowchart illustrating a method for storing and retrieving circular historical data based on external Flash memory, as provided in an embodiment of this application. In this embodiment, the method includes:

[0039] S101. In response to the historical data generated during device operation, the historical data is temporarily stored in the cache area, and an accumulation operation is performed based on the current value corresponding to the preset write pointer to determine the total number of historical data items generated.

[0040] The entity executing this application may be a cloud server.

[0041] In the embodiments of this specification, when a piece of historical data is generated during device operation, the cloud server reorganizes the historical data according to a preset format and temporarily stores the historical data in the cache area. At the same time, it increments the write pointer of the pre-set unsigned integer variable by one. The write pointer is used to determine the total number of historical data items generated.

[0042] In one possible implementation, the method further includes: configuring storage variables for storing the read pointer and the write pointer, and updating the read pointer and the write pointer based on the modulo operation and the storage variables.

[0043] Erasing operations in Flash memory are very time-consuming (typically hundreds of milliseconds for NOR Flash and tens of milliseconds for NAND Flash). If an erase operation is triggered during the writing process, the CPU will be blocked, resulting in the loss of the high-speed sensor data generated during this period. To ensure the integrity of historical data, this application sets a storage variable, such as 100, and updates the read and write pointers by performing a modulo operation on the read and write pointers relative to the storage variable, i.e., read pointer % 100.

[0044] Preferably, the storage variable corresponding to the read pointer is equal to the storage variable corresponding to the write pointer.

[0045] S102. Obtain the current value corresponding to the preset read pointer, and compare the current value corresponding to the read pointer with the value after the write pointer is accumulated. If the current value corresponding to the read pointer is equal to the value after the write pointer is accumulated, it is determined that there is no data to be stored in the buffer area, and the storage operation of the historical data is skipped. If the current value corresponding to the read pointer is not equal to the value after the write pointer is accumulated, it is determined that there is data to be stored in the buffer area, and the storage operation of the historical data is performed.

[0046] In the embodiments of this specification, the cloud server periodically or based on an interrupt event obtains the current value corresponding to a preset read pointer. Both the read pointer and the write pointer are unsigned integer variables. The read pointer is used to determine the total number of historical data entries successfully written to the external Flash. It is determined whether the current value corresponding to the read pointer is equal to the value after the write pointer is incremented. If the current value corresponding to the read pointer is equal to the value after the write pointer is incremented, it means that there is no new data to be stored in the buffer, so the storage operation of historical data is skipped. If the current value corresponding to the read pointer is not equal to the value after the write pointer is incremented, it means that there is historical data in the buffer that has not yet been written to the external Flash, so the storage operation of historical data is performed.

[0047] S103. The storage operation of the historical data includes: based on the read and write address mapping relationship of the external Flash and the target write address, writing the historical data into the physical storage area of ​​the external Flash in a circular overlay manner, and updating the cumulative storage quantity of the historical data;

[0048] In the embodiments of this specification, the storage operation of historical data specifically includes: batch transferring one or more pieces of historical data from the buffer to the current write address of the external Flash, and incrementing the current value corresponding to the read pointer after successful writing, while updating the read pointer and write pointer in the buffer. Before or after each writing of historical data to the external Flash, based on the read / write address of the external Flash, the fixed length of a single piece of historical data, and the starting and ending addresses of the storage area allocated by the external Flash for historical data, wherein the read / write address of the external Flash includes the positions corresponding to the read pointer and write pointer set on the external Flash, the fixed length of a single piece of historical data is the exact number of bytes occupied by each piece of historical data in the external Flash, and the starting and ending addresses are the physical boundaries (security areas) in the external Flash specifically used to store historical data, the historical data is written to the physical storage area of ​​the external Flash in a circular overlay manner, and the cumulative number of updated historical data is calculated.

[0049] In one possible implementation, the read / write address mapping relationship of the external Flash includes the write address and the start and end addresses of the storage area allocated for the historical data. The historical data has a corresponding fixed length. The step of writing the historical data into the physical storage area of ​​the external Flash in a circular overlay manner and updating the cumulative storage quantity of the historical data includes:

[0050] Determine whether the sum of the write address and the fixed length is less than or equal to the end address;

[0051] If so, the write address is shifted backward by the fixed length, and the cumulative storage quantity of historical data is updated;

[0052] If not, then perform a circular overwrite write operation, and update the write address and the cumulative storage quantity of the historical data after the write is completed.

[0053] In the embodiments of this specification, it is determined whether the current write address of the external Flash plus the fixed length corresponding to the historical data is less than or equal to the end address allocated by the external Flash for the historical data. If so, the write address is shifted backward until the offset length of the write address matches the fixed length corresponding to the historical data. The offset write address is equal to the current write address plus the fixed length corresponding to the historical data, and the cumulative storage quantity of the historical data is updated. The cumulative storage quantity of the historical data is equal to the offset write address minus the starting address of the storage area allocated by the external Flash for the historical data, divided by the fixed length corresponding to the historical data. If not, a wake-up overwrite write operation is performed, and the write address and the cumulative storage quantity of the historical data are updated after the write is completed.

[0054] In one possible implementation, the updated write address = the starting address of the storage area allocated by the external Flash for the historical data + (the current write address + the fixed length corresponding to the historical data - the starting address of the storage area allocated by the external Flash for the historical data - (the ending address of the storage area allocated by the external Flash for the historical data - the starting address of the storage area allocated by the external Flash for the historical data + 1)).

[0055] In the embodiments of this specification, performing a ring overwrite write operation specifically involves: updating the current write address, where the updated write address = the starting address of the storage area allocated by the external Flash for historical data + (current write address + fixed length corresponding to historical data - starting address of the storage area allocated by the external Flash for historical data - (ending address of the storage area allocated by the external Flash for historical data - starting address of the storage area allocated by the external Flash for historical data + 1)); updating the cumulative storage quantity of historical data, where the updated cumulative storage quantity of historical data equals (ending address of the storage area allocated by the external Flash for historical data - starting address of the storage area allocated by the external Flash for historical data + 1) / fixed length corresponding to historical data.

[0056] S104. Receive a data reading instruction sent by the receiving device. The data reading instruction carries a target number of data entries to be read. Based on the current value corresponding to the read pointer, sequentially read historical data matching the target number of data entries from the external Flash, and send the read historical data to the device.

[0057] In the embodiments of this specification, when a data read instruction is received from an external host computer or system main control unit through a communication interface, the data read instruction carries the number of historical data entries that the external host computer or system main control unit needs to read, which is the target number of entries to be read. First, the current valid historical data storage quantity is obtained from a predetermined position in the external Flash (or through the write pointer, read pointer, and address mapping relationship). Then, with the valid historical data storage quantity as the upper limit, the historical data matching the target number of entries is sequentially read from the current read pointer position (which is maintained independently or dynamically calculated according to the read request), and returned to the host computer through the communication interface.

[0058] In one possible implementation, upon power-on, the write address, write count, and read count are recovered from the information area of ​​the external Flash. The read / write address mapping relationship of the external Flash is determined based on the write address, write count, and read count. The write count is used to represent the number of historical data entries stored in the external Flash, and the read count is used to represent the number of historical data entries read by the external Flash.

[0059] In the embodiments described in this specification, after power-on, the current write address, write count, and read count before the last power failure are recovered from a designated information area of ​​the external Flash (or by scanning the entire storage area), or these parameters are reconstructed through calculation. The write count represents the number of historical data entries stored in the external Flash. A dedicated non-volatile area (such as an information area or EEPROM area) is allocated in the Flash. After each successful write of historical data, the system automatically performs a read-increment-write-back operation on the write counter of this area. This ensures that even if the system restarts after a power failure, the previous write count can be accurately recovered by reading this area. The read count represents the number of historical data entries read from the external Flash. A variable is defined in RAM, and it is incremented by 1 each time the read function is called and data is successfully retrieved. Finally, the read-write address mapping relationship of the external Flash is determined by the write address, write count, and read count, i.e., the read-write address of the external Flash. This ensures a perfect transition from the previous working state after power-on, preventing the overwriting of old data from the beginning and avoiding errors due to the inability to find the write location. This guarantees the absolute continuity and integrity of historical data during multiple power-on and power-off processes.

[0060] In one possible implementation, the storage space of the external Flash is divided into multiple storage blocks, and the multiple storage blocks are configured to perform a circular storage operation. The circular storage operation includes: writing data to the current storage block in a preset order, and after the current storage block is full, jumping to the next storage block to continue writing, until the last storage block is full and then returning to the first storage block to write in a loop.

[0061] In the embodiments of this specification, the blocks in the external Flash are divided into multiple storage blocks. Each storage block stores historical data in the manner described above, and a storage order is set for the aforementioned multiple storage blocks. When a storage block is full, the system jumps to the next storage block for storage according to the storage order, until the last storage block is full, and then returns to the first storage block for storage. This ensures that all blocks in the external Flash storage area are used cyclically and evenly, significantly extending the overall lifespan of the external Flash.

[0062] In the embodiments of this specification, if a storage block fails to write historical data during the historical data writing process, the writing of the failed historical data will be retried. If, after multiple attempts, the historical data is still not written to the storage block, a storage block fault will be reported, and read / write operations on the storage block will no longer be performed.

[0063] In summary, as an example, assume the external Flash memory is allocated the following area for historical data: the starting address of the storage area allocated for historical data in the external Flash is 0x0000, the ending address of the storage area allocated for historical data in the external Flash is 0x0FFF, and the total length is 4096 bytes. The length of a single historical data entry is 16 bytes. During initialization, the write address of the external Flash is 0x0000, the number of writes is 0, and the number of reads is 0.

[0064] The device generates the first piece of data, stores it in the buffer, and sets the write pointer to 1.

[0065] If the read pointer being 0 does not equal the write pointer being 1, the first piece of data in the buffer is written to Flash address 0x0000. After successful writing, the read pointer becomes 1. Then the address is updated: 0x0000 + 16 = 0x0010 ≤ 0x0FFF, so the current write address is 0x0010, and the cumulative number of historical data stored is (0x0010 - 0x0000) / 16 = 1.

[0066] Continue writing until the current write address is 0x0FF0. At this point, the 257th data item is generated (0x0FF0 is 15 bytes away from 0x0FFF, which is insufficient to store 16 bytes).

[0067] When the current write address is 0x0FF0 and new data is to be written, it is determined that 0x0FF0 + 16 = 0x1000, which is greater than the end address of the storage area allocated by the external Flash for historical data. A circular overwrite write operation is performed, and the updated write address = the starting address of the storage area allocated by the external Flash for historical data + (the current write address + the fixed length corresponding to the historical data - the starting address of the storage area allocated by the external Flash for the historical data - (the end address of the storage area allocated by the external Flash for the historical data - the starting address of the storage area allocated by the external Flash for the historical data + 1)). The new data will be written to 0x0000, overwriting the oldest first data entry.

[0068] The host computer requests to read 100 historical data entries. The system retrieves the number of currently valid historical data entries. If the number of historical data entries is 200, it reads 100 entries sequentially from the current read pointer (e.g., the last read end position or calculated based on parameters) and returns them. If the number of historical data entries is 50, it returns a maximum of 50 entries. If no read start offset is provided, it defaults to starting the read from the oldest valid data (the data written earliest and not overwritten).

[0069] The following will be combined with the appendix Figure 2 This application provides a detailed description of the circular historical data storage and retrieval device based on external Flash memory, as provided in the embodiments of this application. It should be noted that the appendix... Figure 2 The circular historical data storage and retrieval device based on external Flash shown is used to execute the present application. Figure 1 The methods shown in the embodiments are for illustrative purposes only, illustrating the parts relevant to the embodiments of this application. For specific technical details not disclosed, please refer to this application. Figure 1 The example shown.

[0070] Please see Figure 2 , Figure 2 This is a schematic diagram of the structure of a ring-shaped historical data storage and retrieval device based on external Flash provided in an embodiment of this application. Figure 2 As shown, the device includes:

[0071] The data caching module 201 is used to temporarily store the historical data generated during device operation in a cache area and perform an accumulation operation based on the current value corresponding to the preset write pointer to determine the total number of historical data items generated.

[0072] The storage judgment module 202 is used to obtain the current value corresponding to the preset read pointer, and compare the current value corresponding to the read pointer with the value after the write pointer is accumulated. If the current value corresponding to the read pointer is equal to the value after the write pointer is accumulated, it is determined that there is no data to be stored in the cache area, and the storage operation of the historical data is skipped. If the current value corresponding to the read pointer is not equal to the value after the write pointer is accumulated, it is determined that there is data to be stored in the cache area, and the storage operation of the historical data is performed.

[0073] The data storage module 203 is used to perform the storage operation of the historical data, including: writing the historical data into the physical storage area of ​​the external Flash in a ring-overlay manner based on the read and write address mapping relationship of the external Flash and the target write address, and updating the cumulative storage quantity of the historical data;

[0074] The data reading module 204 is used to receive a data reading instruction sent by the device. The data reading instruction carries a target number of reads. Based on the current value corresponding to the read pointer, it sequentially reads historical data that matches the target number of reads from the external Flash and sends the read historical data to the device.

[0075] In one possible implementation, the data storage module 203 is specifically used for:

[0076] The read / write address mapping relationship of the external Flash includes the write address and the start and end addresses of the storage area allocated for the historical data. The historical data has a corresponding fixed length. The step of writing the historical data into the physical storage area of ​​the external Flash in a circular overlay manner and updating the cumulative storage quantity of the historical data includes:

[0077] Determine whether the sum of the write address and the fixed length is less than or equal to the end address;

[0078] If so, the write address is shifted backward by the fixed length, and the cumulative storage quantity of historical data is updated;

[0079] If not, then perform a circular overwrite write operation, and update the write address and the cumulative storage quantity of the historical data after the write is completed.

[0080] In one possible implementation, the data storage module 203 is specifically used for:

[0081] The updated write address = the starting address of the storage area allocated by the external Flash for historical data + (the current write address + the fixed length corresponding to the historical data - the starting address of the storage area allocated by the external Flash for historical data - (the ending address of the storage area allocated by the external Flash for historical data - the starting address of the storage area allocated by the external Flash for historical data + 1)).

[0082] In one possible implementation, the data storage module 203 is specifically used for:

[0083] Upon power-on, the write address, write count, and read count are recovered from the information area of ​​the external Flash. Based on the write address, write count, and read count, the read-write address mapping relationship of the external Flash is determined. The write count is used to represent the number of historical data entries stored in the external Flash, and the read count is used to represent the number of historical data entries read by the external Flash.

[0084] In one possible implementation, the data storage module 203 is specifically used for:

[0085] The external Flash storage space is divided into multiple storage blocks, and the multiple storage blocks are configured to perform a circular storage operation. The circular storage operation includes: writing data to the current storage block in a preset order, and after the current storage block is full, jumping to the next storage block to continue writing, until the last storage block is full and then returning to the first storage block to write in a loop.

[0086] In one possible implementation, the data caching module 201 is specifically used for:

[0087] Configure storage variables for storing the read pointer and the write pointer, and update the read pointer and the write pointer based on the modulo operation and the storage variables.

[0088] In one possible implementation, the data caching module 201 is specifically used for:

[0089] The storage variable corresponding to the read pointer is equal to the storage variable corresponding to the write pointer.

[0090] Those skilled in the art will clearly understand that the technical solutions of the embodiments of this application can be implemented by means of software and / or hardware. In this specification, "unit" and "module" refer to software and / or hardware that can independently complete or cooperate with other components to complete a specific function, wherein the hardware may be, for example, a field-programmable gate array (FPGA), an integrated circuit (IC), etc.

[0091] Each processing unit and / or module in the embodiments of this application can be implemented by an analog circuit that implements the functions described in the embodiments of this application, or by software that executes the functions described in the embodiments of this application.

[0092] See Figure 3 It shows a schematic diagram of the structure of an electronic device according to an embodiment of this application, which can be used to implement... Figure 1 The method in the illustrated embodiment. (As shown) Figure 3 As shown, the electronic device 300 may include: at least one central processing unit 301, at least one network interface 304, user interface 303, memory 305, and at least one communication bus 302.

[0093] The communication bus 302 is used to enable communication between these components.

[0094] The user interface 303 may include a display screen and a camera. Optionally, the user interface 303 may also include a standard wired interface and a wireless interface.

[0095] The network interface 304 may optionally include a standard wired interface or a wireless interface (such as a Wi-Fi interface).

[0096] The central processing unit 301 may include one or more processing cores. The central processing unit 301 connects to various parts within the electronic device 300 using various interfaces and lines. It executes various functions of the terminal 300 and processes data by running or executing instructions, programs, code sets, or instruction sets stored in the memory 305, and by calling data stored in the memory 305. Optionally, the central processing unit 301 may be implemented using at least one hardware form of Digital Signal Processing (DSP), Field-Programmable Gate Array (FPGA), or Programmable Logic Array (PLA). The central processing unit 301 may integrate one or more of the following: a central processing unit (CPU), a graphics processing unit (GPU), and a modem. The CPU primarily handles the operating system, user interface, and applications; the GPU is responsible for rendering and drawing the content required for display; and the modem handles wireless communication. It is understood that the modem may also be implemented as a separate chip without being integrated into the central processing unit 301.

[0097] The memory 305 may include random access memory (RAM) or read-only memory. Optionally, the memory 305 may include a non-transitory computer-readable storage medium. The memory 305 may be used to store instructions, programs, code, code sets, or instruction sets. The memory 305 may include a program storage area and a data storage area, wherein the program storage area may store instructions for implementing an operating system, instructions for at least one function (such as touch function, sound playback function, image playback function, etc.), instructions for implementing the above-described method embodiments, etc.; the data storage area may store data involved in the above-described method embodiments, etc. Optionally, the memory 305 may also be at least one storage device located remotely from the aforementioned central processing unit 301. Figure 3 As shown, the memory 305, which serves as a computer storage medium, may include an operating system, a network communication module, a user interface module, and program instructions.

[0098] exist Figure 3 In the illustrated electronic device 300, the user interface 303 is mainly used to provide an input interface for the user and to acquire user input data; while the central processing unit 301 can be used to call the application program stored in the memory 305 and specifically perform the following operations:

[0099] S101. In response to the historical data generated during device operation, the historical data is temporarily stored in the cache area, and an accumulation operation is performed based on the current value corresponding to the preset write pointer to determine the total number of historical data items generated.

[0100] S102. Obtain the current value corresponding to the preset read pointer, and compare the current value corresponding to the read pointer with the value after the write pointer is accumulated. If the current value corresponding to the read pointer is equal to the value after the write pointer is accumulated, it is determined that there is no data to be stored in the buffer area, and the storage operation of the historical data is skipped. If the current value corresponding to the read pointer is not equal to the value after the write pointer is accumulated, it is determined that there is data to be stored in the buffer area, and the storage operation of the historical data is performed.

[0101] S103. The storage operation of the historical data includes: based on the read and write address mapping relationship of the external Flash and the target write address, writing the historical data into the physical storage area of ​​the external Flash in a circular overlay manner, and updating the cumulative storage quantity of the historical data;

[0102] S104. Receive a data reading instruction sent by the receiving device. The data reading instruction carries a target number of data entries to be read. Based on the current value corresponding to the read pointer, sequentially read historical data matching the target number of data entries from the external Flash, and send the read historical data to the device.

[0103] This application also provides a computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements the steps of the above-described method. The computer-readable storage medium may include, but is not limited to, any type of disk, including floppy disks, optical disks, DVDs, CD-ROMs, microdrives, as well as magneto-optical disks, ROMs, RAMs, EPROMs, EEPROMs, DRAMs, VRAMs, flash memory devices, magnetic cards or optical cards, nanosystems (including molecular memory ICs), or any type of medium or device suitable for storing instructions and / or data.

[0104] It should be noted that, for the sake of simplicity, the foregoing method embodiments are all described as a series of actions. However, those skilled in the art should understand that this application is not limited to the described order of actions, as some steps may be performed in other orders or simultaneously according to this application. Furthermore, those skilled in the art should also understand that the embodiments described in the specification are preferred embodiments, and the actions and modules involved are not necessarily essential to this application.

[0105] In the above embodiments, the descriptions of each embodiment have different focuses. For parts not described in detail in a certain embodiment, please refer to the relevant descriptions in other embodiments.

[0106] In the several embodiments provided in this application, it should be understood that the disclosed apparatus can be implemented in other ways. For example, the apparatus embodiments described above are merely illustrative; for instance, the division of units is only a logical functional division, and in actual implementation, there may be other division methods. For example, multiple units or components may be combined or integrated into another system, or some features may be ignored or not executed. Furthermore, the coupling or direct coupling or communication connection shown or discussed may be through some service interface; the indirect coupling or communication connection between devices or units may be electrical or other forms.

[0107] The units described as separate components may or may not be physically separate. The components shown as units may or may not be physical units; that is, they may be located in one place or distributed across multiple network units. Some or all of the units can be selected to achieve the purpose of this embodiment according to actual needs.

[0108] Furthermore, the functional units in the various embodiments of this application can be integrated into one processing unit, or each unit can exist physically separately, or two or more units can be integrated into one unit. The integrated unit can be implemented in hardware or as a software functional unit.

[0109] If the integrated unit is implemented as a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage device (CMD). Based on this understanding, the technical solution of this application, in essence, or the part that contributes to the prior art, or all or part of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a memory and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute all or part of the steps of the methods described in the various embodiments of this application. The aforementioned memory includes various media capable of storing program code, such as USB flash drives, read-only memory (ROM), random access memory (RAM), portable hard drives, magnetic disks, or optical disks.

[0110] Those skilled in the art will understand that all or part of the steps in the various methods of the above embodiments can be implemented by a program instructing related hardware. The program can be stored in a computer-readable storage medium, which may include: a flash drive, a read-only memory (ROM), a random access memory (RAM), a magnetic disk, or an optical disk, etc.

[0111] The foregoing description is merely an exemplary embodiment of this disclosure and should not be construed as limiting the scope of this disclosure. Any equivalent changes and modifications made in accordance with the teachings of this disclosure shall still fall within the scope of this disclosure. Those skilled in the art will readily conceive of embodiments of this disclosure upon considering the specification and practicing the disclosure herein. This application is intended to cover any variations, uses, or adaptations of this disclosure that follow the general principles of this disclosure and include common knowledge or customary techniques in the art not described herein. The specification and embodiments are to be considered exemplary only, and the scope and spirit of this disclosure are defined by the claims.

Claims

1. A method for storing and retrieving circular historical data based on external Flash memory, characterized in that, The method includes: In response to the historical data generated during device operation, the historical data is temporarily stored in the cache area, and an accumulation operation is performed based on the current value corresponding to the preset write pointer to determine the total number of historical data entries generated. Obtain the current value corresponding to the preset read pointer, and compare the current value corresponding to the read pointer with the value after the write pointer is incremented. If the current value corresponding to the read pointer is equal to the value after the write pointer is incremented, it is determined that there is no data to be stored in the buffer area, and the storage operation of the historical data is skipped. If the current value corresponding to the read pointer is not equal to the value after the write pointer is incremented, it is determined that there is data to be stored in the buffer area, and the storage operation of the historical data is performed. The storage operation of the historical data includes: based on the read / write address mapping relationship of the external Flash and the target write address, writing the historical data into the physical storage area of ​​the external Flash in a circular overlay manner, and updating the cumulative storage quantity of the historical data; The receiving device sends a data read instruction, which carries a target number of reads. Based on the current value corresponding to the read pointer, the receiving device sequentially reads historical data that matches the target number of reads from the external Flash memory and sends the read historical data to the receiving device.

2. The method for storing and retrieving circular historical data based on external Flash memory according to claim 1, characterized in that, The read / write address mapping relationship of the external Flash includes the write address and the start and end addresses of the storage area allocated for the historical data. The historical data has a corresponding fixed length. The step of writing the historical data into the physical storage area of ​​the external Flash in a circular overlay manner and updating the cumulative storage quantity of the historical data includes: Determine whether the sum of the write address and the fixed length is less than or equal to the end address; If so, the write address is shifted backward by the fixed length, and the cumulative storage quantity of historical data is updated; If not, then perform a circular overwrite write operation, and update the write address and the cumulative storage quantity of the historical data after the write is completed.

3. The method for storing and retrieving circular historical data based on external Flash memory according to claim 2, characterized in that, The updated write address = the starting address of the storage area allocated by the external Flash for historical data + (the current write address + the fixed length corresponding to the historical data - the starting address of the storage area allocated by the external Flash for historical data - (the ending address of the storage area allocated by the external Flash for historical data - the starting address of the storage area allocated by the external Flash for historical data + 1)).

4. The method for storing and retrieving circular historical data based on external Flash memory according to claim 2, characterized in that, The method further includes: upon power-on, recovering the write address, write count, and read count from the information area of ​​the external Flash, determining the read / write address mapping relationship of the external Flash based on the write address, write count, and read count, wherein the write count is used to represent the number of historical data entries stored in the external Flash, and the read count is used to represent the number of historical data entries read by the external Flash.

5. A method for storing and retrieving circular historical data based on external Flash memory according to claim 1, characterized in that, The method further includes: dividing the storage space of the external Flash into multiple storage blocks, and configuring the multiple storage blocks to perform a circular storage operation, wherein the circular storage operation includes: writing data to the current storage block in a preset order, and after the current storage block is full, jumping to the next storage block to continue writing, until the last storage block is full and returning to the first storage block to write in a loop.

6. The method for storing and retrieving circular historical data based on external Flash memory according to claim 1, characterized in that, The method further includes: configuring storage variables for storing the read pointer and the write pointer, and updating the read pointer and the write pointer based on the modulo operation and the storage variables.

7. A method for storing and retrieving circular historical data based on external Flash memory according to claim 6, characterized in that, The storage variable corresponding to the read pointer is equal to the storage variable corresponding to the write pointer.

8. A circular historical data storage and retrieval device based on external Flash memory, characterized in that, The device includes: The data caching module is used to temporarily store the historical data generated during device operation in the cache area, and perform an accumulation operation based on the current value corresponding to the preset write pointer to determine the total number of historical data items generated. The storage determination module is used to obtain the current value corresponding to a preset read pointer and compare the current value corresponding to the read pointer with the value after the write pointer is accumulated. If the current value corresponding to the read pointer is equal to the value after the write pointer is accumulated, it is determined that there is no data to be stored in the cache area and the storage operation of the historical data is skipped. If the current value corresponding to the read pointer is not equal to the value after the write pointer is accumulated, it is determined that there is data to be stored in the cache area and the storage operation of the historical data is performed. The data storage module, used to perform the storage operation of the historical data, includes: writing the historical data into the physical storage area of ​​the external Flash in a circular overlay manner based on the read / write address mapping relationship of the external Flash and the target write address, and updating the cumulative storage quantity of the historical data; The data reading module is used to receive data reading instructions sent by the device. The data reading instructions carry a target number of data entries to be read. Based on the current value corresponding to the read pointer, the module sequentially reads historical data that matches the target number of data entries from the external Flash memory and sends the read historical data to the device.

9. An electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that, When the processor executes the computer program, it implements the steps of the method as described in any one of claims 1-7.

10. A computer-readable storage medium having a computer program stored thereon, the computer-readable storage medium storing instructions that, when executed on a computer or processor, cause the computer or processor to perform the steps of the method as claimed in any one of claims 1-7.