A method and apparatus for recording accumulated working time using Flash memory.

By using Flash memory to record accumulated working time in an embedded computer system and employing address and data consistency write and read verification, the problems of large size, high cost, slow speed, and erasure risk of traditional counters are solved, achieving fast and secure recording of working time.

CN117908786BActive Publication Date: 2026-11-17TAIYUAN AERO INSTR
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202311848891.1
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2023-12-29
Publication Date
2026-11-17
Estimated Expiration
2043-12-29

AI Technical Summary

Technical Problem

Traditional cumulative working time counters cannot record faults and are bulky. FRAM is expensive and slow, while EEPROM is fast and low-cost. Flash requires erasing the entire page when writing, which poses an unacceptable risk for real-time processing.

Method used

By using Flash to record accumulated working time, and verifying the consistency of storage address and data during write and read operations, erasure operations are avoided, ensuring data integrity and real-time performance.

Benefits of technology

It enables fast data writing in embedded computer systems, improves data security and operational security, reduces costs, and maintains real-time processing capabilities.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN117908786B_ABST
    Figure CN117908786B_ABST
Patent Text Reader

Abstract

This invention provides a method and apparatus for recording accumulated working time using Flash memory. The method includes: during the initialization period after the embedded computer system is powered on, reading the first address data of each page of the accumulated working time storage page, determining whether all pages are in an erase state; if so, starting the timer from the first address of the first page; if not, finding the valid address of the last recorded data, starting the timer from the valid address, and erasing the other addresses. This method has advantages over using EEPROM in terms of speed and cost; the multi-page approach effectively reduces the number of Flash erases; and the method of using a correlation between stored data and storage address values ​​improves data security and integrity.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention belongs to the field of electronic technology, and specifically relates to a method and apparatus for recording accumulated working time using Flash memory. Background Technology

[0002] Embedded computer systems typically need to be easy to maintain, so product fault information and runtime need to be recorded in non-volatile memory to facilitate quick troubleshooting when system failures occur.

[0003] Traditional cumulative working time counters are unable to record faults and are bulky, leading to their gradual obsolescence and withdrawal from new design applications. Currently, Electrically Erasable Memory (EEPROM) and Ferroelectric RAM (FRAM) chips are widely used. These recording methods can utilize EEPROM or FRAM within a microcontroller (MCU) or externally. While FRAM offers faster access speeds, it is also expensive and only a few manufacturers possess the capability to use it. EEPROM, on the other hand, is cheaper and has more manufacturers capable of producing it, but its slower access speed limits its widespread application as a working time accumulation memory chip.

[0004] With the development of electronic technology, Flash memory has been widely used and integrated with MCUs, offering advantages such as low cost and fast write speed. Widely used Flash memory can achieve write speeds of approximately 16µs / 32bit. However, before writing, it is necessary to confirm that the memory has already been erased, and erasure can only be done page-by-page or as a whole. Erasing a 1kB page typically takes about 5ms. Millisecond-level erase times, coupled with the risk of interrupts during the erase process, are generally unacceptable for real-time processing in embedded computer systems. Summary of the Invention

[0005] This invention proposes a method and apparatus for recording accumulated working time using Flash memory. It employs a verification method for writing and reading data with consistent storage address, which solves the problems of fast data writing and data integrity verification in real-time processing systems. At the same time, it avoids erasing Flash memory during real-time processing in embedded computer systems, thereby improving the operational security of embedded computer systems.

[0006] The first aspect of this invention provides a method for recording accumulated working time using Flash memory, comprising:

[0007] Step 1: During the initialization period after the embedded computer system is powered on, read the first address data of each page of the accumulated storage page for the set working time, and determine whether all pages are in the erase state (0xFFFFFFFF). If yes, proceed to step 2; otherwise, proceed to step 3.

[0008] Step 2: Check if each Flash page is in erase state. If not, erase it. Set the initial power-on cumulative working time status data and assign the page address and the page number of the page containing the address to the set global variable for timing. Proceed to Step 4.

[0009] Step 3: Find the page number and address of the valid current cumulative working time record, assign the page number and address to the set global variable for timing, and erase the page when other pages are not in the erase state; proceed to step 4;

[0010] Step 4: After initialization, the real-time running code increments the address of the global variable used for timing by 1 at each preset timing interval and writes the accumulated working time to the new address.

[0011] Optionally, find the page number and address of the record for the current cumulative working time, including:

[0012] Starting from the first page, obtain the lower N bits of the starting address of each page. If it is not in an erased state and the lower N bits of the starting address match the lower N bits of the stored content, starting from the current page number, traverse and search each storage unit where the lower N bits of the address match the lower N bits of the stored content, search for the maximum stored value and its address, and continue until the last address of the last page; use the searched address and value and its page number as the page number and address of the current cumulative working time.

[0013] Where N is log2(L) + log2(M), L is the number of addresses per page, and M is the total number of pages.

[0014] Optionally, the method of using Flash to record the accumulated working time before incrementing the address in the global variable used for timing also includes:

[0015] The address has been confirmed to be within the maximum page address.

[0016] If it exceeds the limit, increment the page address by 1 and set the address to 0x00000000.

[0017] Optionally, set the initial power-on cumulative working time status data, including:

[0018] Write the cumulative working time of 0 to the first address 0x00000000 of the first Flash page.

[0019] Optionally, methods for using Flash to record accumulated work time also include:

[0020] If the first address data of all pages is in the erased state 0xFFFFFFFF, then set the record working time data status to 1;

[0021] If the starting address data of all pages is not in the erased state of 0xFFFFFFFF, then set the record working time data status to 2.

[0022] Optionally, methods for using Flash to record accumulated work time also include:

[0023] During each timing cycle, check whether the last N bits of the address and the written address are consistent;

[0024] If there is a discrepancy, report the error.

[0025] A second aspect of the present invention provides an apparatus for recording accumulated working time using Flash memory, comprising:

[0026] The first address erase status judgment module is used to read the first address data of each page of the accumulated storage page during the initialization period after the embedded computer system is powered on, and to determine whether all of them are erased in the state of 0xFFFFFFFF.

[0027] The page erase status judgment module is used to check whether each Flash page is in an erase state when the first address erase status judgment module determines that the first address data of each page is in an erase state of 0xFFFFFFFF. If it is not in an erase state, it will erase the page. The module also sets the cumulative working time status data for the first power-on and assigns the page address and the page number of the page to the set global variable for timing.

[0028] The lookup module is used to find the page number and address of the current cumulative working time when the first address erasure status judgment module determines that not every page's first address data is in the erasure status of 0xFFFFFFFF. The page number and address are then assigned to the set global variable for timing. When other pages that are not currently valid pages are in the non-erasure status, erasure is performed.

[0029] The timing module is used to run code in real time at preset timing intervals. At each timing interval, the address of the global variable used for timing is incremented by 1, and the accumulated working time is written to the new address.

[0030] Optionally, the search module is specifically used for:

[0031] Starting from the first page, obtain the lower N bits of the starting address of each page. If it is not in an erased state and the lower N bits of the starting address match the lower N bits of the stored content, starting from the current page number, traverse and search each storage unit where the lower N bits of the address match the lower N bits of the stored content, search for the maximum stored value and its address, and continue until the last address of the last page; use the searched address and value and its page number as the page number and address of the current cumulative working time.

[0032] Where N is log2(L) + log2(M), L is the number of addresses per page, and M is the total number of pages.

[0033] This invention proposes a method and apparatus for recording accumulated working time using Flash memory. It utilizes the Flash memory within an MCU as the cumulative memory for power-on time, offering advantages such as low cost, reliability, and high speed. In embedded computer systems, the continuity of accumulated working time is maintained by ensuring consistency and correlation between storage address order values, thus improving the security and integrity of the recorded working time. During power-on initialization of the embedded computer system, data is erased to prepare for writing. During real-time processing, pages are not erased; only data is written, ensuring the real-time performance of the embedded computer system. This invention uses the Flash memory built into the MCU in the embedded computer system as the storage for accumulated working time, offering advantages over FRAM in terms of lower cost and comparable speed; and over EEPROM in terms of speed and lower cost. The multi-page approach effectively reduces the number of Flash erases, and the correlation between stored data and storage address values ​​improves data security and integrity. Attached Figure Description

[0034] Figure 1 This is a flowchart illustrating the method for recording accumulated working time using Flash, as proposed in this invention. Detailed Implementation

[0035] The technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present invention, and not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those of ordinary skill in the art without creative effort are within the scope of protection of the present invention.

[0036] The method for recording accumulated working time using Flash, provided by the present invention, will be explained below with reference to the accompanying drawings.

[0037] This invention utilizes the on-chip Flash memory of an MCU in an embedded computer system as the storage medium for recording cumulative working time. Typically, the on-chip Flash memory of an MCU has a large capacity and is configured in pages. To avoid erasing the Flash memory during real-time processing, the algorithm proposed in this invention is used during power-on initialization to determine writable pages and erase any pages that are already full. The value written each time can be set to represent a specific time period based on the longest duration of a single operation, for example, 1 minute, meaning the working time counter increments by 1 every minute. This allows for the calculation of how many pages are needed for recording the cumulative working time. Assuming four pages of 256 DW (32-bit DW) are used, the longest cumulative working time in a single power-on operation can reach 256 × 4 = 1024 min ≈ 17 hours. The number of Flash pages used for recording can be calculated based on the accuracy of the cumulative working time recording and the longest working time in a single power-on operation.

[0038] For ease of writing to Flash memory, a 32-bit writing method is used. Typically, the lower 24 bits are used for accumulating operating time, which meets the needs of most applications, while the higher 8 bits are used for recording important fault information. By incrementing by 1 every minute, the cumulative operating time of the embedded computer system can be recorded up to 2E24 × 1 minute ≈ 32 years.

[0039] Currently, the write / erase cycles of Flash memory are generally limited to 100,000. A balance needs to be struck between the frequency of writing and the cumulative time. Assuming that each 256DW page of Flash memory is written in 4 minutes, the usable time would be approximately 100,000 times × 256DW × 4 Pages × 1 minute ≈ 195 years. Even with a 50% reduction in the write speed, it could still last up to 100 years.

[0040] The following example illustrates the method for recording accumulated working time using Flash, as provided by this invention, with four Flash pages, each 256 DW. The flowchart is shown below. Figure 1 The specific steps are as follows:

[0041] Step 1: During the initialization period after the embedded computer system is powered on, read the first address data of each page of the cumulative storage page for the set working time. If the first address data of all four pages are in the erase state 0xFFFFFFFF, then set the recording working time data state to A (state 1) and go to step 2; otherwise, set the recording working time data state to B (state 2) and go to step 3.

[0042] Step 2: Check if each of the four Flash pages is in erase state. If not, erase them. Set the initial power-on cumulative working time status data to 0. Write the 0 data to the address 0x00000000 of the first Flash page. Assign the address, value, and page to the set global variable for use during writing. Proceed to Step 4.

[0043] Step 3: Find the current page number being written;

[0044] 1) Locate the page number, address, and value of the current cumulative working time that is valid;

[0045] The design sets the cumulative working time value per page to 256 (i.e., 0-255), and uses 4 pages. Therefore, the value and address have 10 bits that are consistent, meaning the lower 10 bits of each address are consistent with the lower 10 bits of the stored content. Thus, when the lower 10 bits of the first address of each page match the lower 10 bits of the cumulative working time stored at that address and are not 0xFFFFFFFF, the page is set to begin traversing to find the valid page number, address, and value. This method, which uses a correlation between address and value, offers significantly higher data security than other unrelated methods.

[0046] Starting from the current page number, iterate through each memory cell where the lower 10 bits of the search address match the lower 10 bits of the content stored at that address, search for the maximum stored value and its address, and continue until the last address of the last page; assign the searched address and value, along with their page number, to a designated global variable for use during writing;

[0047] 2) Check if the non-current valid page is in an erase state; if not, erase it.

[0048] Step 4: After initialization, the real-time running code can be called at any time to write the accumulated working time to the preset storage unit.

[0049] The above description is merely a specific embodiment of the present invention, providing a detailed description of the invention. Parts not covered herein are conventional techniques. However, the scope of protection of the present invention is not limited thereto. Any variations or substitutions that can be easily conceived by those skilled in the art within the scope of the technology disclosed in the present invention should be included within the scope of protection of the present invention. The scope of protection of the present invention should be determined by the scope of the claims.

Claims

1. A method for recording accumulated working time using Flash memory, characterized in that, include: Step 1: During the initialization period after the embedded computer system is powered on, read the first address data of each page of the accumulated storage page for the set working time, and determine whether they are all in the erase state of 0xFFFFFFFF; if so, proceed to step 2. Otherwise, proceed to step 3; Step 2: Check if each Flash page is in the erase state. If it is not in the erase state, erase it. Set the initial power-on cumulative working time status data and assign the page address and the page number of the page where the address is located to the set global variable for timing. Proceed to step 4; Step 3: Find the page number and address of the valid current cumulative working time record, assign the page number and address to the set global variable for timing, and erase the page when other pages other than the current valid page are in a non-erase state; proceed to step 4; Step 4: After initialization, the real-time running code increments the address of the global variable used for timing by 1 at each preset timing interval and writes the accumulated working time to the new address. Find the page number and address of the record containing the current cumulative working time, including: Starting from the first page, obtain the lower N bits of the starting address of each page. If it is not in an erased state and the lower N bits of the starting address match the lower N bits of the stored content, starting from the current page number, traverse and search each storage unit where the lower N bits of the address match the lower N bits of the stored content, search for the maximum stored value and its address, and continue until the last address of the last page; use the searched address and value and its page number as the page number and address of the current cumulative working time. Where N takes the value log2(L)+log2(M), L is the number of addresses per page, and M is the total number of pages; The method further includes: During each timing cycle, check whether the last N bits of the address and the written address are consistent; If there is a discrepancy, a fault will be reported.

2. The method for recording accumulated working time using Flash memory according to claim 1, characterized in that, Before incrementing the address of the global variable used for timing by 1, the method further includes: The address has been confirmed to be within the maximum page address. If it exceeds the limit, increment the page address by 1 and set the address to 0x00000000.

3. The method for recording accumulated working time using Flash memory according to claim 1, characterized in that, Set the initial power-on cumulative working time status data, including: Write the cumulative working time of 0 to the first address 0x00000000 of the first Flash page.

4. The method for recording accumulated working time using Flash memory according to claim 1, characterized in that, The method further includes: If the first address data of all pages is in the erased state 0xFFFFFFFF, then set the record working time data status to 1; If the starting address data of all pages is not in the erased state of 0xFFFFFFFF, then set the record working time data status to 2.

5. A device for recording accumulated working time using Flash memory, characterized in that, include: The first address erase status judgment module is used to read the first address data of each page of the accumulated storage page during the initialization period after the embedded computer system is powered on, and to determine whether all of them are erased in the state of 0xFFFFFFFF. The page erase status judgment module is used to check whether each Flash page is in an erase state when the first address erase status judgment module determines that the first address data of each page is in an erase state of 0xFFFFFFFF. If it is not in an erase state, it will erase the page. The module also sets the cumulative working time status data for the first power-on and assigns the page address and the page number of the page to the set global variable for timing. The lookup module is used to find the page number and address of the current cumulative working time when the first address erasure status judgment module determines that not every page's first address data is in the erasure status of 0xFFFFFFFF. The page number and address are then assigned to the set global variable for timing. When other pages that are not currently valid pages are in the non-erasure status, erasure is performed. The timing module is used to run code in real time at preset timing intervals. At each timing interval, the address of the global variable used for timing is incremented by 1, and the accumulated working time is written to the new address. The search module is specifically used for: Starting from the first page, obtain the lower N bits of the starting address of each page. If it is not in an erased state and the lower N bits of the starting address match the lower N bits of the stored content, starting from the current page number, traverse and search each storage unit where the lower N bits of the address match the lower N bits of the stored content, search for the maximum stored value and its address, and continue until the last address of the last page; use the searched address and value and its page number as the page number and address of the current cumulative working time. Where N takes the value log2(L)+log2(M), L is the number of addresses per page, and M is the total number of pages; The device further includes: The detection module is used to check whether the last N bits of the address and the written address are consistent during each timing; if they are inconsistent, a fault is reported.

Citation Information

Patent Citations

  • FLASH data reading / writing method and system

    CN107168647A

  • Method for logging embedded device events

    CN109002399A