Data storage method applicable to various embedded platforms
By designing a unified data management framework, the compatibility problem of embedded device data management on different platforms is solved, and the high portability of embedded programs and efficient and reliable data storage is achieved.
Patent Information
- Application Number
- CN202411966885.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-12-30
- Publication Date
- 2025-05-06
AI Technical Summary
The existing embedded device data management mechanism is difficult to adapt to the differences between different embedded platforms, resulting in complex data management and poor platform portability.
A data storage system including a storage management module, an underlying storage media interface module, a data backup module, a device storage space management module, a power outage detection and data protection module, and a unified data management interface module is designed to shield the differences between the underlying operating system and the hardware platform through a unified data management framework and provide a unified data management interface.
It realizes the convenient switching and operation of embedded programs on different platforms, improves the portability and flexibility of programs, ensures efficient storage and access of data, extends the service life of storage media, and provides data integrity and reliability guarantees.
Smart Images

Figure CN119937919A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of embedded device data storage, and in particular to a data storage method applicable to a variety of embedded platforms. Background Art
[0002] On many embedded devices, it is necessary to support data collection and storage, operation parameter maintenance, 4G wireless dial-up, TCP data communication, metering data collection, remote signal detection, Bluetooth communication, 232 communication, infrared communication, 485 communication, CAN communication, security encryption, LCD screen display and other functions. So many functional modules belong to different management tasks, and there is a large amount of data that needs to be shared by each module.
[0003] Common platforms for traditional embedded devices include microcontrollers, real-time operating systems, Linux and other categories. Real-time operating systems can be further subdivided into specific operating systems such as FreeRTOS, VXWorks, RT-Thread, and QNX. Data management generally uses files, databases, or directly operates flash. Data synchronization and management operations are relatively complex, and platform portability is poor. The data management mechanism used by most embedded devices cannot adapt well to the differences between various embedded platforms. Therefore, a method is needed to solve the problem of data management compatibility and adaptation on different platforms. As a unified data management mechanism, the upper-level application is shielded from the differences in the lower-level operating system and hardware platform, so that embedded programs can be easily switched and run on different platforms. Summary of the invention
[0004] In order to solve the problems existing in the background technology, the present invention provides a data storage system applicable to a variety of embedded platforms, which includes: a storage management module, an underlying storage medium interface module, a data backup module, a device storage space management module, a power-off detection and data protection module and a unified data management interface module, wherein the storage management module directly communicates with the underlying storage medium interface module to receive the storage service provided by it; at the same time, a unified data management interface is provided to the upper-level application; the storage management module formulates and executes the overall storage strategy, including structured processing, compression, write cache management, and erase and write balancing of data.
[0005] The bottom storage media interface module communicates with the storage management module, receives the storage instructions issued by it, and returns the execution results; at the same time, according to the platform characteristics, it communicates with the hardware driver layer or the operating system layer; the bottom storage media interface module interacts with the storage media, including flash, file system, and database, and provides data read, write, and erase operations;
[0006] The data backup module communicates with the storage management module, receives the backup instructions triggered by it, and calls the underlying storage media interface module to perform backup operations; at the same time, it may need to communicate with the device storage space management module to obtain storage space information; the data backup module provides data backup, including scheduled migration backup, cache write simultaneous backup, and data accumulation to threshold backup;
[0007] The device storage space management module communicates with the underlying storage media interface module to obtain the capacity and usage information of the storage media; communicates with the data backup module to provide storage space information to support the formulation of backup strategies; the device storage space management module manages the storage space of the device, including space allocation, release, and monitoring;
[0008] The power failure detection and data protection module communicates with the storage management module, receives the power failure detection instruction triggered by it, and performs data protection operations when power failure is detected; at the same time, it may need to communicate with the hardware driver layer or the power management module to obtain the power failure signal; the power failure detection and data protection module detects the power failure of the device and writes the data in the cache to the storage medium before the power failure;
[0009] The unified data management interface module communicates with the storage management module, receives data management requests from upper-level applications, and forwards them to the storage management module for processing. At the same time, the processing results are returned to the upper-level applications. The unified data management interface module provides a unified data management interface for upper-level applications, including data reading, writing, querying, and deleting operations.
[0010] A data storage method applicable to a variety of embedded platforms is performed in the following steps:
[0011] S1. Configure storage methods according to different embedded platforms;
[0012] S2. Structural processing is performed on the stored data, and the data is stored and retrieved in batches, and structural conversion is performed during storage and access;
[0013] S3: For non-database storage methods, the stored data is compressed again after being structured;
[0014] S4, perform write cache and erase-write balance operations;
[0015] S5. If the write cache mechanism is enabled, a power failure detection module is configured to write the data in the cache to the storage medium immediately after detecting a power failure;
[0016] S6. The storage framework uses scheduled migration backup, cache write simultaneous backup, or data accumulation to threshold backup for backup.
[0017] In the preferred solution, in step S1, the storage mode is configured according to different embedded platforms, the embedded platforms include single chip microcomputer, Linu and RTOS, the storage mode includes flash storage mode, file storage mode and database storage mode; including flash, file and database, wherein:
[0018] For flash storage, it is limited to single-chip microcomputer platforms, and the erase and read modes are pre-configured;
[0019] For file storage, support MCU, RTOS, and Linux with file system;
[0020] For the database mode, microcontroller, RTOS, and Linux are supported.
[0021] In a preferred solution, the specific process of step S2 includes:
[0022] S21. Define appropriate data structures, including database tables, file or directory structures in the file system, and specific data formats, based on data storage requirements and the characteristics of the embedded platform; map raw data to defined data structures through data analysis, conversion, and reorganization; perform data integrity and consistency checks during data mapping to ensure data accuracy and reliability;
[0023] S22. When storing data, related data items are packaged as a whole for storage. When the data needs to be accessed, the entire data packet is read at one time; and multiple write operations are merged into one write operation and multiple read operations are merged into one read operation in a batch processing manner;
[0024] S23. When reading data, the data is parsed according to the data structure when stored, and converted into the data format required by the application; when storing data, the data provided by the application is encapsulated into the data structure required for storage.
[0025] In a preferred solution, the specific process of step S3 includes:
[0026] S31, determining whether the currently used storage mode is non-database type; if yes, continuing to perform the compression operation; if no, skipping this step;
[0027] S32, identifying and removing redundant information in the data, including repeated patterns and predictable data, and performing data compression;
[0028] S33, storing the compressed data in an underlying storage medium;
[0029] S34. When storing compressed data, record compression-related information, including compression algorithm and compression ratio.
[0030] In a preferred solution, the specific process of step S4 includes:
[0031] S41, the system allocates a portion of memory as a write cache area; when data needs to be written to the storage medium, the data is first written to the cache area;
[0032] S42, preset write conditions, including cache size reaching a threshold value and a certain time interval strategy; the system writes the data in the cache in batches to the storage medium according to the preset write conditions;
[0033] S43, the system sets an erase counter to record the number of erases and writes of each storage area. When performing a write operation, the system preferentially selects an area with a smaller number of erases and writes for writing;
[0034] S44. If the number of erase and write times of all areas approaches or reaches the upper limit, the system starts garbage collection or wear leveling algorithm, migrates valid data to new areas, and erases old areas for reuse; the wear leveling algorithm monitors the number of erase and write times of each area of the storage medium, and gives priority to areas with fewer erase and write times for writing. When all areas approach or reach the erase and write upper limit, the storage space is reallocated through data migration and erasing operations to achieve uniform wear of the storage medium.
[0035] In a preferred solution, the specific process of step S5 includes:
[0036] S51, the system checks whether the write cache mechanism is enabled; if yes, continue to configure the power failure detection module; if no, skip this step;
[0037] S52, the power failure detection module communicates with the hardware driver layer or the power management module to obtain the power status of the device in real time;
[0038] S52, when the power failure detection module detects a power failure, sending a signal to the storage management module to indicate that the data in the cache needs to be written to the storage medium immediately;
[0039] S53: After receiving the signal, the storage management module suspends other operations and prioritizes the writing task of cache data;
[0040] S54, data is read from the cache and written into the storage medium through the underlying storage medium interface module;
[0041] S55. After the data is written, a data integrity check is performed to determine whether the written data is damaged or lost. If so, the data is rewritten.
[0042] In a preferred embodiment, in step S6:
[0043] The scheduled migration backup process includes: the system sets a fixed time interval T, and when the time interval T is reached, the system migrates the data in the primary storage medium to the backup storage medium;
[0044] The cache write and backup process includes that while the data is being written to the primary storage medium, the system also copies the data to the backup storage medium;
[0045] The data accumulation to threshold backup process includes that the system monitors the amount of data in the primary storage medium. When the accumulated data volume reaches a preset threshold, the backup operation is automatically triggered to migrate the data to the backup storage medium.
[0046] The beneficial effects achieved by the present invention are:
[0047] First, the present invention shields the differences between the underlying operating system and the hardware platform through a unified data storage management framework, so that embedded programs can be easily switched and run on different platforms, thereby improving the portability and flexibility of the program. By structuring the stored data and adopting the method of whole storage and whole retrieval, the time of data processing is reduced and the efficiency of data storage and access is improved. At the same time, the application of data compression technology further reduces the data volume, saves storage space, and indirectly reduces the number of disk erasures and prolongs the service life of the storage medium.
[0048] Second, the present invention provides multiple data backup methods (timed migration backup, cache write simultaneous backup, data accumulation to threshold backup), as well as power failure detection and data protection mechanisms. These measures ensure the integrity and reliability of data, and can effectively protect data from loss even in emergencies (such as power failure).
[0049] Third, through the application of write cache and erase-write leveling technology, the present invention effectively reduces the erase frequency of the disk, especially when directly operating the flash storage medium, the erase-write leveling mechanism can ensure uniform wear of the storage medium, thereby extending the service life of the storage medium.
[0050] Fourth, the unified data management interface of the present invention provides a concise and clear operation mode for upper-layer applications. Developers do not need to pay attention to the underlying storage details and only need to perform data operations through standard interfaces, which greatly reduces the difficulty and complexity of development and improves development efficiency. BRIEF DESCRIPTION OF THE DRAWINGS
[0051] Figure 1 The structure diagram of a data system applicable to various embedded platforms of the present invention is shown in FIG. DETAILED DESCRIPTION
[0052] The technical solution of the present invention will be clearly and completely described below in conjunction with the accompanying drawings in the present invention. In addition, the forms of the various structures recorded in the following embodiments are merely illustrative, and the present invention is not limited to the various structures recorded in the following embodiments. All other embodiments obtained by ordinary technicians in this field without making creative work belong to the scope of protection of the present invention.
[0053] Reference Figure 1 The present invention provides a data storage system applicable to a variety of embedded platforms, which includes a storage management module, an underlying storage medium interface module, a data backup module, a device storage space management module, a power failure detection and data protection module, and a unified data management interface module.
[0054] The storage management module communicates directly with the underlying storage media interface module and receives the storage services it provides. At the same time, it provides a unified data management interface to upper-level applications. The storage management module formulates and executes the overall storage strategy, including data structured processing, compression, write cache management, and erase and write balance.
[0055] The bottom storage media interface module communicates with the storage management module, receives the storage instructions issued by it, and returns the execution results; at the same time, according to the platform characteristics, it communicates with the hardware driver layer or the operating system layer; the bottom storage media interface module interacts with the storage media, including flash, file system, and database, and provides data read, write, and erase operations;
[0056] The data backup module communicates with the storage management module, receives the backup instructions triggered by it, and calls the underlying storage media interface module to perform backup operations; at the same time, it may need to communicate with the device storage space management module to obtain storage space information; the data backup module provides data backup, including scheduled migration backup, cache write simultaneous backup, and data accumulation to threshold backup;
[0057] The device storage space management module communicates with the underlying storage media interface module to obtain the capacity and usage information of the storage media; communicates with the data backup module to provide storage space information to support the formulation of backup strategies; the device storage space management module manages the storage space of the device, including space allocation, release, and monitoring;
[0058] The power failure detection and data protection module communicates with the storage management module, receives the power failure detection instruction triggered by it, and performs data protection operations when power failure is detected; at the same time, it may need to communicate with the hardware driver layer or the power management module to obtain the power failure signal; the power failure detection and data protection module detects the power failure of the device and writes the data in the cache to the storage medium before the power failure;
[0059] The unified data management interface module communicates with the storage management module, receives data management requests from upper-level applications, and forwards them to the storage management module for processing. At the same time, the processing results are returned to the upper-level applications. The unified data management interface module provides a unified data management interface for upper-level applications, including data reading, writing, querying, and deleting operations.
[0060] The present invention also designs a data storage method applicable to a variety of embedded platforms. The method includes configuring the storage mode (such as flash, file, database) according to the platform type, performing structured processing on the stored data to ensure integrity and consistency, compressing non-database storage to reduce the volume, using write cache and erase and write balance to improve write efficiency, configuring power-off detection to protect cache data, and using multiple backup strategies to ensure data security. Through these steps, the method ensures data reliability and performance optimization of embedded systems on different platforms. The details are as follows:
[0061] S1: Configure storage mode according to different embedded platforms;
[0062] Embedded platform: including microcontroller, Linux and RTOS.
[0063] Storage methods: flash storage method, file storage method and database storage method.
[0064] Flash storage method: limited to the microcontroller platform, and pre-configured erase and read methods.
[0065] File storage method: Supports MCU, RTOS, and Linux with file system.
[0066] Database mode: supports single-chip microcomputer, RTOS, and Linux.
[0067] S2: Structural processing of stored data;
[0068] S21: Define data structures, including database tables, file or directory structures in the file system, and specific data formats. Map the original data to the defined data structure through parsing, conversion, and reorganization, and perform data integrity and consistency verification.
[0069] S22: Whole-storage and whole-retrieval, which packages related data items into a whole for storage and reading, and uses batch processing to merge multiple read and write operations.
[0070] S23: Parse the data and convert it into the format required by the application when reading, and encapsulate the data into the required data structure when storing.
[0071] S3: compresses data for non-database storage methods;
[0072] S31: Determine whether it is a non-database storage method, and if so, continue.
[0073] S32: Identify and remove redundant information and perform data compression.
[0074] S33: Store the compressed data.
[0075] S34: Record compression related information, such as compression algorithm and compression ratio.
[0076] S4: perform write cache and erase-write balance operations;
[0077] S41: Allocate memory as a write cache area, and write data into the cache first.
[0078] S42: Preset writing conditions (cache size threshold, time interval), and write in batches to the storage medium.
[0079] S43: Set the erase counter and give priority to writing to the area with less erase times.
[0080] S44: If the number of erase times of all areas is close to the upper limit, the garbage collection or wear leveling algorithm is started.
[0081] S5: Configure the power-off detection module (if the write cache mechanism is enabled);
[0082] S51: Check whether the write cache mechanism is enabled, and continue if so.
[0083] S52: The power failure detection module communicates with the hardware driver layer or the power management module to obtain the power status.
[0084] S53: When power failure is detected, a signal is sent to the storage management module.
[0085] S54: The storage management module suspends other operations and gives priority to cache data writing.
[0086] S55: The data is written from the cache to the storage medium and an integrity check is performed.
[0087] S6: Use multiple backup methods to back up data;
[0088] Scheduled migration backup: Set a fixed time interval T to migrate data to the backup storage medium at that time.
[0089] Cache write and backup simultaneously: When data is written to the primary storage medium, it is simultaneously copied to the backup storage medium.
[0090] Backup when data accumulates to a threshold: Monitors the amount of data on the primary storage medium and automatically triggers a backup when the preset threshold is reached.
[0091] Through the above steps, this data storage method ensures efficient and reliable storage of data on different embedded platforms, while providing flexible data management and backup strategies.
[0092] Embodiment 1, in this embodiment, an embedded device based on RTOS (real-time operating system) is used, and the device needs to support data acquisition, wireless communication and local storage functions at the same time. In order to ensure reliable storage and efficient management of data, we adopt the above data storage method.
[0093] Specific implementation steps:
[0094] 1. Platform and storage configuration;
[0095] Choosing an RTOS as an embedded platform:
[0096] According to the requirements of the device and the characteristics of the RTOS, select the appropriate RTOS version for development.
[0097] Configure RTOS kernel, task scheduling, interrupt processing and other related parameters.
[0098] Configuration storage method:
[0099] Flash storage method:
[0100] Choose flash chips with high durability and low latency.
[0101] Configure flash partitions to ensure that critical data and common data are stored separately.
[0102] Pre-set the flash erase and read modes to optimize read and write efficiency.
[0103] File storage method:
[0104] Use a file system supported by the RTOS, such as FAT or YAFFS, to manage file storage.
[0105] Configure the file system's mount point, file system type, cache size and other parameters.
[0106] 2. Data structured processing;
[0107] Define the data structure:
[0108] Data collection form:
[0109] The fields include: sensor ID (integer), collection time (timestamp), collection value (floating point), etc.
[0110] Depending on actual needs, you may need to add other fields, such as status code, check code, etc.
[0111] Other related data sheets:
[0112] Define corresponding data structures based on requirements such as wireless communication and device status.
[0113] Data mapping and verification:
[0114] When writing data, the raw data (such as data packets obtained from sensors) are mapped into a defined data structure.
[0115] During the mapping process, data integrity and consistency checks are performed to ensure data accuracy.
[0116] The verification method may include CRC verification, hash verification, etc.
[0117] 3. Data compression;
[0118] Compression processing:
[0119] For non-database storage methods (such as file storage), compression is performed before data is written.
[0120] Select a suitable compression algorithm (such as LZW, Huffman coding, etc.) and perform compression based on the characteristics of the data.
[0121] Remove redundant information from the data, such as repeated patterns, predictable data, etc.
[0122] After compression, the compression algorithm, compression ratio and other related information are recorded for subsequent decompression.
[0123] 4. Write cache and erase balance;
[0124] Write cache configuration:
[0125] Allocate a portion of memory as a write cache area, the size of which is determined by the device memory and cache requirements.
[0126] Set the cache write policy, such as batch write, scheduled write, etc.
[0127] Cache write and erase balance:
[0128] When data needs to be written, the data is first written to the cache area.
[0129] When the cache size reaches a preset threshold or a certain time interval, the data in the cache is written to the flash storage medium in batches.
[0130] Monitor the number of erase and write times of each area of the flash, and give priority to writing to areas with fewer erase and write times.
[0131] When the number of erase and write times of all areas approaches or reaches the upper limit, the garbage collection or wear leveling algorithm is started to migrate valid data to new areas and erase the old areas for reuse.
[0132] 5. Power-off detection and data protection;
[0133] Power-off detection configuration:
[0134] Configure the power-off detection module to communicate with the power management module to obtain the power status.
[0135] Set the power-off detection threshold and time window to ensure timely response when power supply is abnormal.
[0136] Data protection operations:
[0137] When power failure is detected, the data in the cache is immediately written to the flash storage medium.
[0138] After the data is written, a data integrity check is performed to ensure that the data is not damaged or lost.
[0139] If the data verification fails, the data is read again from the cache and written to the flash until the data is complete and correct.
[0140] 6. Data backup;
[0141] Scheduled migration backup:
[0142] Set a scheduled task to migrate data from the primary storage medium to the backup storage medium at 2 a.m. every day.
[0143] During the backup process, ensure data integrity and consistency.
[0144] Record the backup time, data volume, backup results and other information for subsequent query and management.
[0145] Data cumulative backup:
[0146] Monitor the amount of data in the primary storage medium and trigger an immediate backup operation when the accumulated data volume reaches a preset threshold.
[0147] The backup operation is similar to scheduled migration backup, ensuring data reliability and integrity.
[0148] On devices with scarce resources, you can choose whether to enable the data accumulation backup function based on actual conditions.
[0149] By implementing the above steps, it is possible to ensure that the RTOS-based embedded device can achieve reliable storage and efficient management of data in functions such as data acquisition, wireless communication and local storage. It can be seen from this embodiment that the method of the present invention also has good cross-platform and portability, and can adapt to the needs of different embedded platforms.
[0150] The above description is only a preferred embodiment of the present invention and is not intended to limit the present invention. Any modifications, equivalent substitutions, improvements, etc. made within the spirit and principles of the present invention should be included in the protection scope of the present invention.
Claims
1. A data storage system applicable to a variety of embedded platforms, characterized in that: It includes: storage management module, bottom storage medium interface module, data backup module, device storage space management module, power failure detection and data protection module and unified data management interface module, among which: The storage management module communicates directly with the underlying storage media interface module and receives the storage services it provides. At the same time, it provides a unified data management interface to upper-level applications. The storage management module formulates and executes the overall storage strategy, including data structured processing, compression, write cache management, and erase and write balance. The bottom storage media interface module communicates with the storage management module, receives the storage instructions issued by it, and returns the execution results; at the same time, according to the platform characteristics, it communicates with the hardware driver layer or the operating system layer; the bottom storage media interface module interacts with the storage media, including flash, file system, and database, and provides data read, write, and erase operations; The data backup module communicates with the storage management module, receives the backup instructions triggered by it, and calls the underlying storage media interface module to perform backup operations; at the same time, it may need to communicate with the device storage space management module to obtain storage space information; the data backup module provides data backup, including scheduled migration backup, cache write simultaneous backup, and data accumulation to threshold backup; The device storage space management module communicates with the underlying storage media interface module to obtain the capacity and usage information of the storage media; communicates with the data backup module to provide storage space information to support the formulation of backup strategies; the device storage space management module manages the storage space of the device, including space allocation, release, and monitoring; The power failure detection and data protection module communicates with the storage management module, receives the power failure detection instruction triggered by it, and performs data protection operations when power failure is detected; at the same time, it may need to communicate with the hardware driver layer or the power management module to obtain the power failure signal; the power failure detection and data protection module detects the power failure of the device and writes the data in the cache to the storage medium before the power failure; The unified data management interface module communicates with the storage management module, receives data management requests from upper-level applications, and forwards them to the storage management module for processing. At the same time, the processing results are returned to the upper-level applications. The unified data management interface module provides a unified data management interface for upper-level applications, including data reading, writing, querying, and deleting operations.
2. A data storage method applicable to a variety of embedded platforms, characterized in that: The data storage system applicable to a variety of embedded platforms as claimed in claim 1 is used and carried out in the following steps: S1. Configure storage methods according to different embedded platforms; S2. Structural processing is performed on the stored data, and the data is stored and retrieved in batches, and structural conversion is performed during storage and access; S3: For non-database storage methods, the stored data is compressed again after being structured; S4, perform write cache and erase-write balance operations; S5. If the write cache mechanism is enabled, a power failure detection module is configured to write the data in the cache to the storage medium immediately after detecting a power failure; S6. The storage framework uses scheduled migration backup, cache write simultaneous backup, or data accumulation to threshold backup for backup.
3. The data storage method applicable to a variety of embedded platforms according to claim 2, characterized in that: In step S1, storage modes are configured according to different embedded platforms, the embedded platforms include single chip microcomputer, Linu and RTOS, and the storage modes include flash storage mode, file storage mode and database storage mode; Includes flash, files, and databases, including: For flash storage, it is limited to single-chip microcomputer platforms, and the erase and read modes are pre-configured; For file storage, support MCU, RTOS, and Linux with file system; For the database mode, microcontroller, RTOS, and Linux are supported.
4. The data storage method applicable to a variety of embedded platforms according to claim 2, characterized in that: The specific process of step S2 includes: S21. Define appropriate data structures, including database tables, file or directory structures in the file system, and specific data formats, based on data storage requirements and the characteristics of the embedded platform; map raw data to defined data structures through data analysis, conversion, and reorganization; perform data integrity and consistency checks during data mapping to ensure data accuracy and reliability; S22. When storing data, related data items are packaged as a whole for storage. When the data needs to be accessed, the entire data packet is read at one time; and multiple write operations are merged into one write operation and multiple read operations are merged into one read operation in a batch processing manner; S23. When reading data, the data is parsed according to the data structure when stored, and converted into the data format required by the application; when storing data, the data provided by the application is encapsulated into the data structure required for storage.
5. The data storage method applicable to a variety of embedded platforms according to claim 2, characterized in that: The specific process of step S3 includes: S31, determining whether the currently used storage mode is non-database type; if yes, continuing to perform the compression operation; if no, skipping this step; S32, identifying and removing redundant information in the data, including repeated patterns and predictable data, and performing data compression; S33, storing the compressed data in an underlying storage medium; S34. When storing compressed data, record compression-related information, including compression algorithm and compression ratio.
6. The data storage method applicable to a variety of embedded platforms according to claim 2, characterized in that: The specific process of step S4 includes: S41, the system allocates a portion of memory as a write cache area; when data needs to be written to the storage medium, the data is first written to the cache area; S42, preset write conditions, including cache size reaching a threshold value and a certain time interval strategy; the system writes the data in the cache in batches to the storage medium according to the preset write conditions; S43, the system sets an erase counter to record the number of erases and writes of each storage area. When performing a write operation, the system preferentially selects an area with a smaller number of erases and writes for writing; S44. If the number of erase and write times of all areas approaches or reaches the upper limit, the system starts garbage collection or wear leveling algorithm, migrates valid data to new areas, and erases old areas for reuse; the wear leveling algorithm monitors the number of erase and write times of each area of the storage medium, and gives priority to areas with fewer erase and write times for writing. When all areas approach or reach the erase and write upper limit, the storage space is reallocated through data migration and erasing operations to achieve uniform wear of the storage medium.
7. The data storage method applicable to a variety of embedded platforms according to claim 2, characterized in that: The specific process of step S5 includes: S51, the system checks whether the write cache mechanism is enabled; if yes, continue to configure the power failure detection module; if no, skip this step; S52, the power failure detection module communicates with the hardware driver layer or the power management module to obtain the power status of the device in real time; S52, when the power failure detection module detects a power failure, sending a signal to the storage management module to indicate that the data in the cache needs to be written to the storage medium immediately; S53: After receiving the signal, the storage management module suspends other operations and prioritizes the writing task of cache data; S54, data is read from the cache and written into the storage medium through the underlying storage medium interface module; S55. After the data is written, a data integrity check is performed to determine whether the written data is damaged or lost. If so, the data is rewritten.
8. The data storage method applicable to a variety of embedded platforms according to claim 1, characterized in that: In step S6: The scheduled migration backup process includes: the system sets a fixed time interval T, and when the time interval T is reached, the system migrates the data in the primary storage medium to the backup storage medium; The cache write and backup process includes that while the data is being written to the primary storage medium, the system also copies the data to the backup storage medium; The data accumulation to threshold backup process includes that the system monitors the amount of data in the primary storage medium. When the accumulated data volume reaches a preset threshold, the backup operation is automatically triggered to migrate the data to the backup storage medium.