Storage method and device capable of being applied to optical module and storage medium

By dividing functional areas in the Flash sector of the optical module and making effective sector judgments, the problems of slow Flash data storage speed and easy data loss in the prior art are solved, and fast and secure data storage is achieved.

CN119536647APending Publication Date: 2025-02-28LINKTEL TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202411627420.2
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-11-14
Publication Date
2025-02-28

AI Technical Summary

Technical Problem

When existing optical modules save Flash data, the erase speed is slow due to the inability to perform single-byte erasing, which increases the risk of data loss, especially in abnormal power failure.

Method used

By dividing three functional areas in the Flash sector, the use flag area and the data frame area, and performing effective sector judgment and data updates when the module is powered on, a fast and secure Flash data storage is achieved.

Benefits of technology

Shorten the Flash operation time, extend the Flash service life, and ensures data security and integrity through enhanced backup table usage status management mechanism.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119536647A_ABST
    Figure CN119536647A_ABST
Patent Text Reader

Abstract

The invention discloses a data storage method and device capable of being applied to an optical module and a storage medium, and the method comprises the steps: initializing a Flash sector, dividing the Flash sector into three functional regions, namely an initial data region, a use mark region and a data frame region in advance, and determining the activation states of the three functional regions; the module is powered on for effective sector judgment, an initial data area and a data frame area are scanned, and data in the RAM are updated; during data writing, when the required space is smaller than the residual space of the data frame area, new data frames are sequentially written behind the tail data frame of the current sector; when the required space is larger than the residual space of the data frame area, copying the latest data of the RAM corresponding to the Page to the initial data area of another sector, updating the use mark and erasing the original sector; through a specific data storage structure and a Flash writing rule, the Flash operation time is shortened, the service life of the Flash is prolonged, and the data security is ensured by adding a backup table use state management mechanism.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention belongs to the field of embedded software design, and specifically relates to a data storage method applicable to an optical module Background Art

[0002] In the field of optical modules, data is exchanged in the form of protocol tables (Pages), which are 128 bytes in size. The number and function of Pages are specified by the protocols referenced by each module. Some protocols have high requirements on the timing of Flash write operations and need to prevent the loss of original data after abnormal power failure.

[0003] However, the existing technology mainly has the following defects: the Flash storage time is too long. Due to the physical characteristics of the Flash memory of the single-chip microcomputer, it is impossible to perform a single-byte erase operation, but erase in sectors (the sector is the smallest unit of Flash erasure). Therefore, before writing to the Flash each time, the entire Flash sector needs to be erased first, and then new data can be written; for some single-chip microcomputers, the erasing speed is slow due to the large sector, which leads to a long Flash storage operation time and easy data loss. If there is an abnormal situation during the erasing process, such as abnormal power failure of the optical module, the data stored in the Flash will be easily lost. Summary of the invention

[0004] The present invention provides a storage method, a device and a storage medium for an optical module, which can solve at least one of the technical problems in the background technology.

[0005] To achieve the above object, the present invention adopts the following technical solutions:

[0006] A data storage method applicable to an optical module, characterized in that the specific steps include:

[0007] S100, pre-dividing the initial data area, the usage flag area, and the data frame area in the initialization Flash sector, and determining the activation status of the three functional areas;

[0008] S200, the optical module is powered on to determine the valid sectors;

[0009] S300, scanning the data frame area and updating the data in the RAM;

[0010] S400, the data frame determines the storage address and writes it into Flash.

[0011] Furthermore, the initial data area in step S100 of the present invention is used to record a complete set of data of the table;

[0012] The usage flag area is located in the last 4 bytes of the sector and is used to manage the usage status of the backup table. The usage flag is an increasing number, and the usage flag increases by 1 every time a sector jumps;

[0013] The data frame area is used to store data frames. A data frame must at least contain address information and data information.

[0014] Furthermore, the data frame format of the present invention adds a frame header, a frame trailer and a check bit according to requirements.

[0015] Furthermore, the method for determining the valid sectors when the module is powered on in step S200 of the present invention is as follows:

[0016] 1) If the usage flags of sectors A and B are not written, the currently used sector is defined as sector A, and the usage flag of sector A is initialized to 1;

[0017] 2) If the A sector usage flag is not written, the currently used sector is specified as the B sector;

[0018] 3) If the B sector usage flag is not written, the currently used sector is specified as the A sector;

[0019] 4) If both sectors A and B have usage flags, and the usage flag of sector A is greater than that of sector B, then sector A is specified as the currently used sector, and sector B is erased;

[0020] 5) If any one of steps 1)-4) is not satisfied, the currently used sector is defined as sector B, and sector A is erased.

[0021] Furthermore, the process of updating the data in the RAM in step S300 of the present invention adopts a table information initialization method, and the specific method is:

[0022] S310: The module is powered on, and the data in the initial data area of ​​the valid sector is copied to the RAM;

[0023] S311: Scan the entire data frame area starting from the lowest address;

[0024] S312: Determine whether the scanning is completed; if so, the valid sector initialization is completed, otherwise determine whether the data frame is a legal data frame;

[0025] S313: If the data frame is a legal data frame, the frame data is updated to the corresponding address RAM; otherwise, the process jumps to the next data frame header position and performs the next scan.

[0026] Furthermore, writing Flash data in step S400 of the present invention is specifically divided into two situations:

[0027] If the space required for this writing is less than the remaining space in the data frame area, the new data frame will be written in sequence after the last data frame;

[0028] If the space required for this write is larger than the remaining space in the data frame area, first copy all the data stored in the RAM corresponding to the Page to the initial data area of ​​the new sector, update the new sector usage flag, and finally erase the entire original sector.

[0029] Furthermore, when the sector usage flag is updated in the present invention, the usage flag of the original sector is incremented and written into the new sector usage flag area.

[0030] On the other hand, the present invention further discloses a computer-readable storage medium storing a computer program, wherein when the computer program is executed by a processor, the processor executes the steps of the above method.

[0031] On the other hand, the present invention further discloses a computer device, including a memory and a processor, wherein the memory stores a computer program, and when the computer program is executed by the processor, the processor executes the steps of the above method.

[0032] It can be seen from the above technical scheme that the present invention divides the Flash sector into three functional areas and determines the activation status of the three functional areas; when the module is powered on, the initial data area and the data frame area are scanned to update the data in the Flash; when writing data, when the required space is less than the remaining space in the data frame area, the new data frames are written in sequence after the data frame at the end of the current sector; when the required space is greater than the remaining space in the data frame area, the latest data of the RAM corresponding to the Page is copied to the initial data area of ​​another sector, the use flag is updated and the original sector is erased; through a specific data storage structure and Flash writing rules, the Flash operation time is shortened, the Flash service life is extended, and a backup table usage status management mechanism is added to ensure data security. BRIEF DESCRIPTION OF THE DRAWINGS

[0033] Figure 1 It is a Flash sector division structure diagram of the present invention;

[0034] Figure 2 Use a state management method flow chart for the backup table;

[0035] Figure 3 Flowchart of table information initialization method;

[0036] Figure 4 Write a flowchart for the data frame. DETAILED DESCRIPTION

[0037] In order to make the purpose, technical solutions and advantages of the embodiments of the present invention clearer, the technical solutions in the embodiments of the present invention will be clearly and completely described below in conjunction with the drawings in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments.

[0038] like Figure 1 As shown, the storage method of the optical module described in this embodiment specifically includes the following steps:

[0039] S100, pre-dividing the initial data area, the usage flag area, and the data frame area in the initialization Flash sector, and determining the activation status of the three functional areas;

[0040] S200, the module is powered on to determine the valid sectors;

[0041] S300, scanning the data frame area and updating the data in the RAM;

[0042] S400, the data frame determines the storage address and writes it into Flash.

[0043] The following are detailed instructions for each step:

[0044] S100, pre-dividing the initial data area, the usage flag area, and the data frame area in the initialization Flash sector, and determining the activation status of the three functional areas;

[0045] like Figure 1 As shown, the initial data area is located at the first 128 bytes of the sector, and its size is equal to the size of the RAM occupied by the protocol table. The initial data area is used to record a complete set of data of the table (but not necessarily the latest data of this table).

[0046] The usage flag area is located in the last 4 bytes of the sector and is used to manage the usage status of the backup table. The usage flag is an incremental number, which increases by 1 for each jump to a sector, so the usage flag of the sector containing the latest data is always larger (except when the usage flag is 0xFFFFFFFF, which means the sector is erased).

[0047] The data frame area is used to store data frames. The specific format of the data frame is not limited. A data frame must at least contain address information and data information. A frame header, frame trailer, and check bit can also be added as required.

[0048] S200, the module is powered on to determine the valid sectors;

[0049] When the module is powered on, all the data in the initial data area of ​​the valid sector is copied to the RAM to obtain a set of initial data for the management backup table, ensuring that the system can start working from a known state even after power failure.

[0050] The method for determining the valid sectors when the module is powered on is as follows: Figure 2 As shown, the details are as follows:

[0051] 1) If the usage flags of sectors A and B have not been written, the currently used sector is specified as sector A, and the usage flag of sector A is initialized to 1.

[0052] 2) If the A sector usage flag has not been written, the currently used sector is specified as the B sector.

[0053] 3) If the B sector usage flag has not been written, the currently used sector is specified as the A sector.

[0054] 4) If both sectors A and B have usage flags, and the usage flag of sector A is greater than that of sector B, then sector A is specified as the currently used sector and sector B is erased.

[0055] 5) If 1-4 are not met, the currently used sector is specified as sector B and sector A is erased.

[0056] The valid area determination method can determine the valid sector by determining the size of the usage flag when an erase failure occurs due to abnormal power failure of the module.

[0057] S300, scanning the data frame area and updating the data in the RAM;

[0058] According to the address order from low to high in the table information, the entire data frame area is scanned in sequence to find all legal data frames, and the data of all legal data frames are updated to the corresponding addresses in RAM in this order. After the data frame area is completely scanned and updated, the latest data saved in the Flash before power failure can be obtained from the RAM.

[0059] Table information initialization method is as follows Figure 3 As shown, specifically:

[0060] S310: The module is powered on, and the data in the initial data area of ​​the valid sector is copied to the RAM;

[0061] S311: Scan the entire data frame area starting from the lowest address;

[0062] S312: Determine whether the scanning is completed; if so, the valid sector initialization is completed, otherwise determine whether the data frame is a legal data frame;

[0063] S313: If the data frame is a legal data frame, the frame data is updated to the corresponding address RAM; otherwise, the process jumps to the next data frame header position and performs the next scan.

[0064] S400, the data frame determines the storage address and writes it into Flash;

[0065] like Figure 4 As shown in the figure, writing Flash data is divided into two cases:

[0066] If the space required for this write is less than the remaining space in the data frame area, the new data frame will be written in sequence after the last data frame; if the space required for this write is greater than the remaining space in the data frame area, all the data stored in the RAM corresponding to the Page will be copied to the initial data area of ​​the new sector, the new sector usage flag will be updated, and finally the entire original sector will be erased. When updating the sector usage flag, the usage flag of the original sector will be incremented and written to the new sector usage flag area.

[0067] In summary, the data storage method of the present invention that can be applied to optical modules is as follows: the initialization Flash sector is pre-divided into three functional areas: the initial data area, the usage flag area, and the data frame area, and the activation status of the three functional areas is determined; the module is powered on, the data area is initialized, the data frame area is scanned, and the data in the RAM is updated; then all legal data frame data is updated to the corresponding address of the RAM, so as to obtain the latest data of the Page before power failure. When writing data, when the required space is less than the remaining space in the data frame area, the new data frame is written in sequence after the data frame at the end of the current sector; when the required space is greater than the remaining space in the data frame area, the latest data of the RAM corresponding to the Page is copied to the initial data area of ​​another sector, the usage flag is updated and the original sector is erased; through a specific data storage structure and Flash writing rules, the Flash operation time is shortened, the Flash service life is extended, and a backup table usage status management mechanism is added to ensure data security.

[0068] On the other hand, the present invention further discloses a computer-readable storage medium storing a computer program, wherein when the computer program is executed by a processor, the processor executes the steps of the above method.

[0069] In another embodiment provided in the present application, a computer program product including instructions is also provided. When the computer program product is run on a computer, the computer executes the storage method of any optical module in the above embodiments.

[0070] It is understandable that the system, device and storage medium provided in the embodiments of the present invention correspond to the method provided in the embodiments of the present invention, and the explanation, examples and beneficial effects of the relevant contents can refer to the corresponding parts in the above methods.

[0071] In the above embodiments, it can be implemented in whole or in part by software, hardware, firmware or any combination thereof. When implemented using software, it can be implemented in whole or in part in the form of a computer program product. The computer program product includes one or more computer instructions. When the computer program instructions are loaded and executed on a computer, the process or function described in the embodiment of the present application is generated in whole or in part. The computer may be a general-purpose computer, a special-purpose computer, a computer network, or other programmable device. The computer instructions may be stored in a computer-readable storage medium, or transmitted from one computer-readable storage medium to another computer-readable storage medium, for example, the computer instructions may be transmitted from a website site, computer, server or data center by wired (e.g., coaxial cable, optical fiber, digital subscriber line (DSL)) or wireless (e.g., infrared, wireless, microwave, etc.) mode to another website site, computer, server or data center. The computer-readable storage medium may be any available medium that a computer can access or a data storage device such as a server or data center that includes one or more available media integrated. The available medium may be a magnetic medium, (e.g., a floppy disk, a hard disk, a tape), an optical medium (e.g., a DVD), or a semiconductor medium (e.g., a solid-state drive Solid State Disk (SSD)), etc.

[0072] It should be noted that, in this article, relational terms such as first and second, etc. are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Moreover, the terms "include", "comprise" or any other variants thereof are intended to cover non-exclusive inclusion, so that a process, method, article or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or device. In the absence of further restrictions, the elements defined by the sentence "comprise a ..." do not exclude the existence of other identical elements in the process, method, article or device including the elements.

[0073] Each embodiment in this specification is described in a related manner, and the same or similar parts between the embodiments can be referred to each other, and each embodiment focuses on the differences from other embodiments. In particular, for the system embodiment, since it is basically similar to the method embodiment, the description is relatively simple, and the relevant parts can be referred to the partial description of the method embodiment.

[0074] The above embodiments are only used to illustrate the technical solutions of the present invention, rather than to limit the same. Although the present invention has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that the technical solutions described in the aforementioned embodiments may still be modified, or some of the technical features may be replaced by equivalents. However, these modifications or replacements do not deviate the essence of the corresponding technical solutions from the spirit and scope of the technical solutions of the embodiments of the present invention.

Claims

1. A data storage method applicable to an optical module, characterized in that: The specific steps include: S100, pre-dividing the initial data area, the usage flag area, and the data frame area in the initialization Flash sector, and determining the activation status of the three functional areas; S200, the optical module is powered on to determine the valid sectors; S300, scanning the data frame area and updating the data in the RAM; S400, the data frame determines the storage address and writes it into Flash.

2. The storage method of the optical module according to claim 1, characterized in that: The initial data area in step S100 is used to record a complete set of data of the table; The usage flag area is located in the last 4 bytes of the sector and is used to manage the usage status of the backup table. The usage flag is an increasing number, and the usage flag increases by 1 every time a sector jumps; The data frame area is used to store data frames. A data frame must at least contain address information and data information.

3. The storage method of the optical module according to claim 1, characterized in that: The data frame format adds a frame header, frame trailer, and check bit as needed.

4. The storage method of the optical module according to claim 1, characterized in that: The method for determining the valid sectors when the module is powered on in step S200 is as follows: 1) If the usage flags of sectors A and B are not written, the currently used sector is defined as sector A, and the usage flag of sector A is initialized to 1; 2) If the A sector usage flag is not written, the currently used sector is specified as the B sector; 3) If the B sector usage flag is not written, the currently used sector is specified as the A sector; 4) If both sectors A and B have usage flags, and the usage flag of sector A is greater than that of sector B, then sector A is specified as the currently used sector, and sector B is erased; 5) If any one of steps 1)-4) is not satisfied, the currently used sector is defined as sector B, and sector A is erased.

5. The optical module storage method according to claim 1, characterized in that: The process of updating the data in the RAM in step S300 adopts a table information initialization method, and the specific method is: S310: The module is powered on, and the data in the initial data area of ​​the valid sector is copied to the RAM; S311: Scan the entire data frame area starting from the lowest address; S312: Determine whether the scanning is completed; if so, the valid sector initialization is completed, otherwise determine whether the data frame is a legal data frame; S313: If the data frame is a legal data frame, the frame data is updated to the corresponding address RAM; Otherwise, it jumps to the next data frame header position and performs the next scan.

6. The optical module storage method according to claim 1, characterized in that: Writing Flash data in step S400 is specifically divided into two situations: If the space required for this writing is less than the remaining space in the data frame area, the new data frame will be written in sequence after the last data frame; If the space required for this write is larger than the remaining space in the data frame area, first copy all the data stored in the RAM corresponding to the Page to the initial data area of ​​the new sector, update the new sector usage flag, and finally erase the entire original sector.

7. The optical module storage method according to claim 6, characterized in that: When updating the sector usage flag, the usage flag of the original sector is incremented and written into the new sector usage flag area.

8. A computer-readable storage medium storing a computer program, wherein when the computer program is executed by a processor, the processor is caused to perform the steps of the method according to any one of claims 1 to 7.

9. A computer device comprising a memory and a processor, characterized in that: The memory stores a computer program, and when the computer program is executed by the processor, the processor is caused to perform the steps of the method according to any one of claims 1 to 7.