Data access method, system, computer device and storage medium
By dividing the non-volatile memory of the microcontroller into control and data areas, and using status bytes to indicate the data storage status, the data partition to be accessed can be directly determined, thus solving the problem of low data access efficiency in the prior art and achieving more efficient data access.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- SHENZHEN OURUIBO ELECTRONICS
- Filing Date
- 2022-12-27
- Publication Date
- 2026-07-24
AI Technical Summary
In existing technologies, data access by traversing and accessing sectors of non-volatile memory is inefficient.
In the non-volatile memory of the microcontroller unit, a control area and a data area are divided. Status bytes correspond to data partitions. The data storage status is indicated by the byte value, and the data partition to be accessed is directly determined and accessed.
This reduces the time spent determining the data partition to be accessed, thus improving data access efficiency.
Smart Images

Figure CN116204119B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of data processing technology, and in particular to a data access method, system, computer device, and storage medium. Background Technology
[0002] During the operation of a microcontroller unit (MCU), to ensure that the data generated by the MCU is not lost, data synchronization is usually performed through non-volatile memory (NDRAM), and the data in the NDRAM is accessed, such as for write or read operations. Currently, the common approach is to traverse and access each region of the NDRAM sectors to access the data based on the traversal results, but this data access method is very inefficient. Summary of the Invention
[0003] Therefore, it is necessary to provide a data access method, system, computer device, and storage medium that can improve data access efficiency in response to the above-mentioned technical problems.
[0004] Firstly, this application provides a data access method, the method comprising:
[0005] The status data is read from the control area partitioned in the non-volatile memory; the non-volatile memory is integrated on the microcontroller unit; the non-volatile memory is also divided into a data area; the data area has multiple data partitions; the status data includes byte values corresponding to multiple status bytes, and the status bytes correspond to the data partitions; the byte values are used to indicate the data storage status of the corresponding data partitions.
[0006] The data partition to be accessed is determined from multiple data partitions based on the byte values corresponding to multiple status bytes;
[0007] Perform appropriate data access processing on the data partition to be accessed.
[0008] Secondly, this application provides a data access system, which includes: a microcontroller unit, the microcontroller unit integrating non-volatile memory; the non-volatile memory is divided into a control area and a data area; the data area has multiple data partitions;
[0009] The microcontroller unit is used to read the status data of the control area; the status data includes byte values corresponding to multiple status bytes, and the status bytes correspond to data partitions; the byte values are used to indicate the data storage status of the corresponding data partition; based on the byte values corresponding to the multiple status bytes, the data partition to be accessed is determined from multiple data partitions; and the corresponding data access processing is performed on the data partition to be accessed.
[0010] In some embodiments, the microcontroller is further configured to, when write processing is required for non-volatile memory, determine a data partition to be stored from multiple data partitions based on the byte values corresponding to multiple status bytes; the data storage state of the data partition to be stored is an unstored state; write the data to be written to the data partition to be stored, and modify the byte value of the status byte corresponding to the data partition to be stored, so that the modified byte value indicates that the data storage state of the data partition to be stored is a stored state.
[0011] In some embodiments, the microcontroller unit also integrates volatile memory; the volatile memory includes a state mapping area and a data mapping area opened when the microcontroller unit starts running; the state mapping area is synchronized with byte values corresponding to multiple state bytes stored in non-volatile memory. The microcontroller unit is also configured to determine a data partition to be stored from multiple data partitions based on the byte values corresponding to the multiple state bytes synchronized in the state mapping area; write the data to be written synchronized in the data mapping area to the data partition to be stored; modify the byte value of the state byte corresponding to the data partition to be stored in the state mapping area; and synchronize the modified byte value to the control area, so that the modified and synchronized byte values indicate that the data storage state of the data partition to be stored is a stored state.
[0012] In some embodiments, the control area and the data area are obtained by dividing a specified sector of a non-volatile memory. The microcontroller is also configured to: erase the data already stored in the specified sector when the byte value of each status byte in the control area indicates that the data storage status of the corresponding data partition is stored; determine the data partition corresponding to the first status byte in the control area as the data partition to be stored; write the data to be written to the data partition to be stored; and modify the byte values corresponding to multiple status bytes so that the byte value of the first status byte indicates that the data storage status of the data partition to be stored is stored, and the byte values of the other status bytes indicate that the data storage status of the corresponding data partition is not stored; the other status bytes are the status bytes in the control area other than the first status byte.
[0013] In some embodiments, the microcontroller is further configured to, when read processing of non-volatile memory is required, determine the data partition to be read from multiple data partitions based on the byte values corresponding to multiple status bytes; the data storage state of the data partition to be read is a stored state; and read the data stored in the data partition to be read.
[0014] In some embodiments, the microcontroller unit is further configured to determine the data partition to be read from multiple data partitions based on the byte values corresponding to multiple state bytes synchronized in the state mapping area of the volatile memory;
[0015] The data stored in the data partition to be read is read into the data mapping area of the volatile memory.
[0016] In some embodiments, the microcontroller is further configured to traverse the byte values corresponding to multiple status bytes, and if the byte value of each traversed status byte indicates that the data storage status of the corresponding data partition is stored, then the data partition corresponding to the byte value of the last traversed status byte is determined as the data partition to be read; if the byte value of the currently traversed status byte indicates that the data storage status of the corresponding data partition is stored, and the byte value of the next to be traversed status byte indicates that the data storage status of the corresponding data partition is stored, then the data partition corresponding to the byte value of the last traversed status byte is determined as the data partition to be read.
[0017] If the data partition is in an unstored state, the data partition corresponding to the byte value of the current traversed state word 0 is determined as the data partition to be read.
[0018] Thirdly, this application provides a computing device, including a memory and a processor, wherein the memory stores a computer program, and the processor executes the computer program to implement the steps of the above-described data access method.
[0019] Fourthly, this application provides a computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements the steps of the data access method described above.
[0020] 5. In a fifth aspect, this application also provides a computer program product. The computer program product includes a computer program that, when executed by a processor, implements the steps in the data access method described above.
[0021] The aforementioned data access methods, systems, computer devices, storage media, and computer program products obtain control areas and data access areas by pre-dividing the non-volatile memory integrated on the microcontroller unit.
[0022] The control area's status data is mapped one-to-one with each data partition in the data area. The byte values indicate the data storage status of the corresponding data partition. This allows direct determination of whether each data partition stores data based on the control area's status data, eliminating the need to traverse each data partition and reducing the time consumed by data traversal. Specifically, the status data of the control area partitioned in non-volatile memory is read; based on the byte values corresponding to multiple status bytes, the partitions to be accessed are determined.
[0023] The application determines the data partition to be accessed based on the byte values of multiple status bytes stored in the control area. After determining the data partition to be accessed, the data access is performed. Compared with the method of traversing each area in the sector of the non-volatile memory to determine whether data is stored, the time spent determining the data partition to be accessed can be reduced, thereby improving the data access efficiency. Attached Figure Description
[0024] Figure 1 A flowchart illustrating a data access method provided in an embodiment of this application;
[0025] Figure 2 This is a schematic diagram of sector partitioning in a non-volatile memory provided in an embodiment of this application;
[0026] Figure 3 A flowchart illustrating another data access method provided in an embodiment of this application;
[0027] Figure 4 A flowchart illustrating another data access method provided in an embodiment of this application;
[0028] Figure 5 This is a schematic diagram of the structure of a data access system provided in an embodiment of this application;
[0029] Figure 6 An internal structural diagram of a computer device provided in an embodiment of this application;
[0030] Figure 7 This is an internal structural diagram of another computer device provided in an embodiment of this application. Detailed Implementation
[0031] To make the objectives, technical solutions, and advantages of this application clearer, the following detailed description is provided in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are merely illustrative and not intended to limit the scope of this application.
[0032] In some embodiments, such as Figure 1 As shown, a data access method is provided. This embodiment illustrates the application of this method to a microcontroller unit in a computer device. It is understood that the computer device can be a server or a terminal, and the method can be implemented independently by the server or the terminal, or through interaction between the server and the terminal. In this embodiment, the method includes, but is not limited to, the following steps:
[0033] Step 102: Read the status data of the control area partitioned in the non-volatile memory.
[0034] Among them, the microcontroller unit (MCU), also known as a single-chip microcomputer or microcontroller, is a chip-level computer that appropriately reduces the frequency and specifications of the central processing unit (CPU) and integrates memory, timer, USB, A / D conversion, UART, PLC, DMA and other peripheral interfaces, and even LCD driver circuits, onto a single chip to form a chip-level computer, which can perform different combinations of control for different applications.
[0035] Non-volatile memory (NVM) refers to computer memory whose stored data is preserved even when the power is turned off. The definition of non-volatile memory depends on whether the data within it can be rewritten at any time while the computer is in use. In some embodiments, non-volatile memory includes at least one of read-only memory (ROM) and flash memory. ROM operates in a non-destructive read-only manner; information can only be read, not written. Once information is written, it is fixed and will not be lost even when the power is cut off; therefore, it is also called fixed memory. Flash memory refers to a type of storage chip whose data can be modified through a specific program. It not only has electronic erasable and programmable capabilities but also allows for fast data retrieval, ensuring that data is not lost due to power outages.
[0036] It should be noted that the non-volatile memory is integrated on the microcontroller unit. The non-volatile memory is further divided into a data area for storing data. This data area has multiple data partitions, and the status data includes multiple status bytes corresponding to byte values. The status bytes correspond to data partitions, and the byte values indicate the data storage status of the corresponding data partition. The data storage status includes a stored state and an unstored state. A stored state indicates that data is stored in the corresponding data partition, while an unstored state indicates that no data is stored in the corresponding partition.
[0037] In some embodiments, such as Figure 2 As shown, the non-volatile memory is divided into a control area and a data area. The control area stores N status bytes, and each of these N status bytes corresponds to a specific byte value. It can be understood that status byte 1 in the control area corresponds to data partition 1 in the data area, and the byte value of status byte 1 indicates whether data partition 1 stores data; status byte 2 in the control area corresponds to data partition 2 in the data area, and the byte value of status byte 2 indicates whether data partition 2 stores data; and status byte N in the control area corresponds to data partition N in the data area, and the byte value of status byte N indicates whether data partition N stores data.
[0038] It can be understood that when the byte value is the first byte value, it means that the data partition corresponding to the status byte does not store data; when the byte value is the second byte value, it means that the data partition corresponding to the status byte stores data. For example, the first byte value can be set to the hexadecimal number OXFF, and the second byte value can be set to the hexadecimal number OXCC.
[0039] Specifically, the microcontroller reads the status data in the control area partitioned in the non-volatile memory, that is, it reads multiple status bytes and the byte values corresponding to the multiple status bytes in the control area, thereby confirming whether the data partition corresponding to each of the multiple status bytes stores data.
[0040] Step 104: Determine the data partition to be accessed from multiple data partitions based on the byte values corresponding to multiple status bytes.
[0041] The data partition to be accessed refers to at least one of the data partitions for which data is to be read or data is to be stored.
[0042] Specifically, the microcontroller determines the data partition from multiple data partitions based on the byte values corresponding to multiple status bytes in the control area.
[0043] Step 106: Perform the corresponding data access processing on the data partition to be accessed.
[0044] Specifically, after the microcontroller determines the data partition to be accessed, if the data partition to be accessed is the data partition to which data is to be read, the microcontroller reads the data stored in the corresponding data partition; if the data partition to be accessed is the data partition to which data is to be stored, the microcontroller stores the data to be written to the corresponding data partition.
[0045] The aforementioned data access method pre-divides the non-volatile memory integrated on the microcontroller unit into a control area and a data area. This allows for a one-to-one mapping of status bytes in the control area's status data to each data partition in the data area. The byte values indicate the data storage status of the corresponding data partition. This enables direct determination of whether each data partition stores data based on the control area's status data, eliminating the need to traverse each data partition and reducing the time consumed by data traversal. Specifically, the method involves reading the status data of the control area partitioned in the non-volatile memory; determining the data partition to be accessed from among the data partitions based on the byte values corresponding to multiple status bytes; and performing appropriate data access processing on the data partition to be accessed. This application can determine the data partition to be accessed based on the byte values of multiple status bytes stored in the control area, and then perform data access after determining the data partition. Compared to traversing each area of the non-volatile memory sectors to determine whether data is stored, this method reduces the time consumed in determining the data partition to be accessed, thereby improving data access efficiency.
[0046] In some embodiments, step 104 specifically includes, but is not limited to, determining the data partition to be stored from multiple data partitions based on the byte values corresponding to multiple status bytes when write processing for non-volatile memory is required.
[0047] In this case, the data storage status of the data partition to be stored is "unstored," meaning that there is no data stored in the data partition to be stored.
[0048] Specifically, when the microcontroller needs to perform write operations on the non-volatile memory, that is, when the microcontroller needs to store the data to be written into the non-volatile memory, the microcontroller determines the data partition that does not store data, i.e. the data partition to be stored, from multiple data partitions based on the byte values corresponding to multiple status bytes.
[0049] In some embodiments, step 106 specifically includes, but is not limited to: writing the data to be written to the data partition to be stored, and modifying the byte value of the status byte corresponding to the data partition to be stored, so that the modified byte value indicates that the data storage status of the data partition to be stored is a stored state.
[0050] Data to be written refers to operational data that the microcontroller needs to save during operation. This includes power-on or power-off status data, or data related to critical states. For example, if a smart switch loses power while the light is on, the microcontroller will write the light's state (e.g., whether it's on) to non-volatile memory before the power outage. When power is restored, the microcontroller can read the light's state from the non-volatile memory. If the light is on, it will be turned back on; if it's off, it will be turned off, thus maintaining the light's state consistent with before the power outage.
[0051] Specifically, the microcontroller unit can use runtime-related data that needs to be saved during operation as data to be written, and write this data to a pre-defined data partition to be stored. Simultaneously, it modifies the byte value of the status byte corresponding to the data partition to be stored, so that the modified byte value indicates that the data storage status of the data partition to be stored is "stored". By updating the status byte in a timely manner, this application ensures that the microcontroller unit will not store data in the data partition that already contains data the next time it performs data storage, but will directly store it in another data partition that does not yet contain data, thereby avoiding storage failure and improving data storage efficiency.
[0052] In some embodiments, the step "determine the data partition to be stored from multiple data partitions based on the byte values corresponding to multiple status bytes" specifically includes, but is not limited to, determining the data partition to be stored from multiple data partitions based on the byte values corresponding to multiple status bytes synchronized in the status mapping area.
[0053] The microcontroller also integrates volatile memory, which includes a state mapping area and a data mapping area allocated when the microcontroller starts running. Volatile memory is similar to portable storage in a PC, used to store and save data. It can be read and written at any time and is typically used as temporary storage for the operating system or other running programs.
[0054] It is understandable that the state mapping area synchronizes the byte values corresponding to multiple state bytes stored in non-volatile memory, while the data mapping area is used to save some operation-related data of the microcontroller during operation and to synchronize the saved data to the corresponding data partition of the non-volatile memory.
[0055] Specifically, the microcontroller determines the data partition that does not store data, i.e. the data partition to be stored, from multiple data partitions of the non-volatile memory based on the byte values corresponding to multiple state bytes synchronized in the state mapping area of the volatile memory.
[0056] In some embodiments, the step "writing the data to be written to the data partition to be stored and modifying the byte value of the status byte corresponding to the data partition to be stored so that the modified byte value indicates that the data storage status of the data partition to be stored is a stored state" specifically includes, but is not limited to: writing the data to be written synchronized in the data mapping area to the data partition to be stored, modifying the byte value of the status byte corresponding to the data partition to be stored in the status mapping area, and synchronizing the modified byte value to the control area so that the modified and synchronized byte values indicate that the data storage status of the data partition to be stored is a stored state.
[0057] Specifically, the microcontroller unit can store runtime-related data that needs to be saved during operation, i.e., the data to be written, in the data mapping area of volatile memory. After determining the data partition to be stored based on the byte values corresponding to multiple status bytes synchronized in volatile memory, the data to be written, synchronized in the data mapping area, is written to the previously determined data partition to be stored. The microcontroller unit also modifies the byte values of the status bytes corresponding to the data partition to be stored in the status mapping area so that the modified byte values indicate that the data storage status of the data partition to be stored is "stored". Afterwards, the modified byte values also need to be synchronized to the control area so that the corresponding byte values in the control area also indicate that the data storage status of the data partition to be stored is "stored". Because volatile memory has a high processing speed, by using volatile memory for specific data partition determination and for storing synchronized data to be written to the corresponding data partition in non-volatile memory, data storage efficiency can be improved.
[0058] In some embodiments, the control area and the data area are obtained by dividing a specified sector of the non-volatile memory into regions. The step "determining the data partition to be stored from multiple data partitions based on the byte values corresponding to multiple status bytes" specifically includes, but is not limited to, erasing the data already stored in the specified sector when the byte value of each status byte in the control area indicates that the data storage status of the corresponding data partition is stored; and determining the data partition corresponding to the first status byte in the control area as the data partition to be stored.
[0059] Here, a sector refers to a region partitioned on non-volatile memory, while a specified sector refers to at least one region partitioned on non-volatile memory.
[0060] Specifically, if the byte value of each status byte in the control area indicates that the corresponding data partition's data storage status is "stored," it means that all data partitions have already stored data. In this case, the microcontroller unit cannot directly store data; instead, it erases all stored data in the specified sector. Afterward, the microcontroller unit determines the data partition corresponding to the first status byte in the control area as the data partition to be stored. This application erases the specified sector only after the data partition is full, reducing the number of erase operations and extending the erase / write life of the non-volatile memory.
[0061] In some embodiments, the step "writing the data to be written to the data partition to be stored, and modifying the byte value of the status byte corresponding to the data partition to be stored, so that the modified byte value indicates that the data storage status of the data partition to be stored is a stored state" specifically includes, but is not limited to: writing the data to be written to the data partition to be stored, and modifying the byte values corresponding to multiple status bytes, so that the byte value of the first status byte indicates that the data storage status of the data partition to be stored is a stored state, and the byte values of the other status bytes indicate that the data storage status of the corresponding data partition is an unstored state.
[0062] Among them, the other status bytes are the status bytes in the control area excluding the first status byte. It can be understood that if the control area has N status bytes, the first status byte is the 1st status byte, and the other status bytes are the 2nd to Nth status bytes.
[0063] Specifically, the microcontroller writes the data to be written to the data partition to be stored, and modifies the byte value of the first status byte to the second byte value, so that the modified byte value of the first status byte indicates that the data storage status of the corresponding data partition is stored. In addition, the microcontroller also modifies the byte values of other status bytes to the first byte value, so that the byte values of the other status bytes indicate that the data storage status of the corresponding data partition is not stored.
[0064] In some embodiments, such as Figure 3 As shown, the data access method of this application also includes, but is not limited to, the following data storage process:
[0065] The microcontroller copies the data to be written to the data mapping area. This data mapping area can be understood as a storage space allocated by the microcontroller in volatile memory after power-on; it can be an array. The microcontroller determines whether the value of the current status byte in the status mapping area of volatile memory is the second byte value. The status mapping area can be another array storing the byte values corresponding to multiple status bytes in non-volatile memory. The second byte value indicates that the data status of the data partition in the non-volatile memory corresponding to the current status byte is unstored. If the value of the current status byte in the status mapping area of volatile memory is the second byte value, the value of the current status byte in the status mapping area is changed to the first byte value, the first byte value is synchronously updated to the corresponding position in the non-volatile memory mapping, and the data to be written from the data mapping area is written to the position in the non-volatile memory corresponding to the current status byte, thus ending the data storage process. If the value of the current status byte in the status mapping area of volatile memory is not the second byte value, then continue to determine whether the current status byte is the last byte. If not, continue to determine whether the next status byte is the second byte and subsequent steps. If the value of the current status byte in the status mapping area of volatile memory is not the second byte value, and the next status byte is the last status byte, then erase the data already stored in the sector of non-volatile memory, update the value of the first status byte in the status mapping area to the first byte value, update the values of the other status bytes to the second byte value, make the current status byte point to the first status byte, write all status bytes in the status mapping area to the non-volatile memory mapping, write the data to be written in the data mapping area to the position in the non-volatile memory corresponding to the current status byte, and end the data storage process.
[0066] In some embodiments, step 104 may include, but is not limited to, determining the data partition to be read from multiple data partitions based on the byte values corresponding to multiple status bytes when a read operation is required for the non-volatile memory.
[0067] In this case, the data storage status of the data partition to be read is "stored", which means that the microcontroller can read the stored data from this data partition.
[0068] Specifically, when the microcontroller unit needs to read data from non-volatile memory (NDRAM), that is, when it needs to perform read operations on NDRAM, the microcontroller unit determines the data partition with stored data from multiple data partitions based on the byte values corresponding to multiple status bytes, and then determines the data partition to be read from these data partitions. By determining the data partition to be read first, and then performing the data read, compared to traversing each area of the NDRAM sectors to check for data storage, the time spent determining the data partition to be read is reduced, thereby improving data read efficiency.
[0069] In some embodiments, step 106 specifically includes, but is not limited to, reading the data stored in the data partition to be read.
[0070] Specifically, after the microcontroller unit determines the data partition to be read, it directly reads the data stored in that data partition.
[0071] In some embodiments, the step "determining the data partition to be read from multiple data partitions based on the byte values corresponding to multiple status bytes" includes, but is not limited to, determining the data partition to be read from multiple data partitions based on the byte values corresponding to multiple status bytes synchronized in the state mapping area of volatile memory. The step "reading the data stored in the data partition to be read" specifically includes, but is not limited to, reading the data stored in the data partition to be read into the data mapping area of volatile memory.
[0072] Specifically, the microcontroller determines the most recently stored data partition (i.e., the data partition to be read) from multiple data partitions based on the byte values corresponding to multiple state bytes synchronized in the state mapping area of the volatile memory. After determining the data partition to be read, the microcontroller reads the data stored in that partition into the data mapping area of the volatile memory. Because the volatile memory has a high processing speed, using it for specific data partition determination and data reading operations can improve the efficiency of data reading.
[0073] In some embodiments, the step "determining the data partition to be read from multiple data partitions based on the byte values corresponding to multiple status bytes" includes, but is not limited to: traversing the byte values corresponding to multiple status bytes; if the byte value of each traversed status byte indicates that the data storage status of the corresponding data partition is stored, determining the data partition corresponding to the byte value of the last traversed status byte as the data partition to be read; if the byte value of the currently traversed status byte indicates that the data storage status of the corresponding data partition is stored, and the byte value of the next to be traversed status byte indicates that the data storage status of the corresponding data partition is not stored, determining the data partition corresponding to the byte value of the currently traversed status byte as the data partition to be read.
[0074] Specifically, when the microcontroller traverses multiple status bytes, if the byte value of each traversed status byte indicates that the corresponding data partition's data storage status is "stored," it means that all data partitions have already stored data. Therefore, the data partition corresponding to the last traversed status byte is directly identified as the data partition to be read, and the data in the last data partition is read. Furthermore, if the byte value of the currently traversed status byte indicates that the corresponding data partition's data storage status is "stored," and the byte value of the next to be traversed status byte indicates that the corresponding data partition's data storage status is "not stored," it means that the data partition corresponding to the currently traversed status byte is the data partition that most recently stored data. Therefore, the data partition corresponding to the currently traversed status byte needs to be identified as the data partition to be read, and the data stored in that data partition needs to be read.
[0075] In some embodiments, such as Figure 4 As shown, the data access method of this application also includes, but is not limited to, the following data reading process:
[0076] After the microcontroller unit (MCU) is powered on, it allocates a state mapping area and a data mapping area in volatile memory. The state mapping area can be an array, and the data mapping area can be another array. The MCU copies the byte values corresponding to multiple state bytes from non-volatile memory to the state mapping area. The MCU determines whether the value of the current state byte in the state mapping area is the first byte value. The first byte value indicates that the data state of the data partition in the non-volatile memory corresponding to the current state byte is stored. If the value of the current state byte in the state mapping area is not the first byte value, the data reading process ends directly. If the value of the current state byte in the state mapping area is the first byte value, it continues to determine whether the current state byte is the last state byte in the state mapping area. If so, the content of the data partition in the non-volatile memory corresponding to the current state byte is copied to the data mapping area, and the data reading process ends. If the value of the current state byte in the state mapping area is the first byte value, and the current state byte is not the last state byte in the state mapping area, then continue to determine whether the next state byte is the second byte value. If it is, then copy the contents of the data partition in the non-volatile memory corresponding to the next state byte to the data mapping area and end the data reading process. If not, continue to determine whether the value of the next state byte is the first byte value and the subsequent steps. It can be understood that the second byte value indicates that the data status of the data partition in the non-volatile memory corresponding to the next state byte is an unstored state.
[0077] In some embodiments, the data access method of this application further includes, but is not limited to, the following steps:
[0078] The status data in the control area partitioned in the non-volatile memory is read. If a write operation to the non-volatile memory is required, either the first storage step or the second storage step is executed. If a read operation to the non-volatile memory is required, either the first read step or the second read step is executed.
[0079] The first storage step includes: determining the data partition to be stored from multiple data partitions based on the byte values corresponding to multiple status bytes synchronized in the status mapping area; writing the data to be written synchronized in the data mapping area to the data partition to be stored; modifying the byte value of the status byte corresponding to the data partition to be stored in the status mapping area; and synchronizing the modified byte value to the control area so that the modified and synchronized byte values indicate that the data storage status of the data partition to be stored is a stored state.
[0080] The second storage step includes: erasing the stored data in a specified sector when the byte value of each status byte in the control area indicates that the data storage status of the corresponding data partition is stored; determining the data partition corresponding to the byte value of the first status byte in the control area as the data partition to be stored; writing the data to be written to the data partition to be stored, and modifying the byte values corresponding to multiple status bytes so that the byte value of the first status byte indicates that the data storage status of the data partition to be stored is stored, and the byte values of the other status bytes indicate that the data storage status of the corresponding data partition is unstored.
[0081] The first reading step includes: determining the data partition to be read from multiple data partitions based on the byte values corresponding to multiple state bytes synchronized in the state mapping area of the volatile memory; and reading the data stored in the data partition to be read into the data mapping area of the volatile memory.
[0082] The second reading step includes: traversing the byte values corresponding to multiple status bytes; if the byte value of each traversed status byte indicates that the data storage status of the corresponding data partition is "stored", then the data partition corresponding to the byte value of the last traversed status byte is determined as the data partition to be read; if the byte value of the currently traversed status byte indicates that the data storage status of the corresponding data partition is "stored" and the byte value of the next to be traversed status byte indicates that the data storage status of the corresponding data partition is "unstored", then the data partition corresponding to the byte value of the currently traversed status byte is determined as the data partition to be read; and reading the data stored in the data partition to be read.
[0083] It should be understood that although the steps in the flowcharts of the embodiments described above are shown sequentially according to the arrows, these steps are not necessarily executed in the order indicated by the arrows. Unless explicitly stated herein, there is no strict order restriction on the execution of these steps, and they can be executed in other orders. Moreover, at least some steps in the flowcharts of the embodiments described above may include multiple steps or multiple stages. These steps or stages are not necessarily completed at the same time, but can be executed at different times. The execution order of these steps or stages is not necessarily sequential, but can be performed alternately or in turn with other steps or at least some of the steps or stages of other steps.
[0084] Based on the same inventive concept, this application also provides a data access system for implementing the data access method described above. The solution provided by this system is similar to the implementation scheme described in the above method; therefore, the specific limitations in one or more data access system embodiments provided below can be found in the limitations of the data access method described above, and will not be repeated here.
[0085] In some embodiments, such as Figure 5 As shown, a data access system is provided, including: a microcontroller unit 502, which integrates a non-volatile memory 504. The non-volatile memory 504 is divided into a control area 506 and a data area 508. The data area 508 has multiple data partitions, wherein:
[0086] The microcontroller unit 502 is used to read the status data of the control area 506; the status data includes byte values corresponding to multiple status bytes, and the status bytes correspond to data partitions; the byte values are used to indicate the data storage status of the corresponding data partition; based on the byte values corresponding to the multiple status bytes, the data partition to be accessed is determined from the multiple data partitions; and the corresponding data access processing is performed on the data partition to be accessed.
[0087] The aforementioned data access system pre-divides the non-volatile memory 504 integrated on the microcontroller unit 502 into a control area 506 and a data area 508. This ensures that the status bytes in the status data of the control area 506 are mapped one-to-one with each data partition in the data area 508, and the byte values indicate the data storage status of the corresponding data partition. This allows for direct determination of whether each data partition stores data based on the status data of the control area 506, eliminating the need to traverse each data partition and reducing the time consumed by data traversal. Specifically, by reading the status data of the control area 506 divided in the non-volatile memory 504; determining the data partition to be accessed from each data partition based on the byte values corresponding to multiple status bytes; and performing corresponding data access processing on the data partition to be accessed, this application can determine the data partition to be accessed based on the byte values of multiple status bytes stored in the control area 506. Data access is performed only after the data partition to be accessed is determined. Compared to traversing the sectors of the non-volatile memory 504 to determine whether each area stores data, this reduces the time consumed in determining the data partition to be accessed, thereby improving data access efficiency.
[0088] In some embodiments, the microcontroller unit 502 is further configured to, when write processing is required for the non-volatile memory 504, determine a data partition to be stored from multiple data partitions based on the byte values corresponding to multiple status bytes; the data storage state of the data partition to be stored is an unstored state; write the data to be written to the data partition to be stored, and modify the byte value of the status byte corresponding to the data partition to be stored, so that the modified byte value indicates that the data storage state of the data partition to be stored is a stored state.
[0089] In some embodiments, the microcontroller 502 also integrates volatile memory; the volatile memory includes a state mapping area and a data mapping area opened when the microcontroller 502 starts running; the state mapping area is synchronized with the byte values corresponding to multiple state bytes stored in the non-volatile memory 504. The microcontroller 502 is also configured to determine the data partition to be stored from multiple data partitions based on the byte values corresponding to the multiple state bytes synchronized in the state mapping area; write the data to be written synchronized in the data mapping area to the data partition to be stored; modify the byte value of the state byte corresponding to the data partition to be stored in the state mapping area; and synchronize the modified byte value to the control area 506 so that the modified and synchronized byte values indicate that the data storage state of the data partition to be stored is a stored state.
[0090] In some embodiments, the control area 506 and the data area 508 are obtained by dividing a designated sector of the non-volatile memory 504 into regions. The microcontroller unit 502 is further configured to: erase the data already stored in the designated sector when the byte value of each status byte in the control area 506 indicates that the data storage status of the corresponding data partition is stored; determine the data partition corresponding to the byte value of the first status byte in the control area 506 as the data partition to be stored; write the data to be written to the data partition to be stored, and modify the byte values corresponding to multiple status bytes so that the first status byte indicates that the data storage status of the data partition to be stored is stored, and the byte values of other status bytes indicate that the data storage status of the corresponding data partition is not stored; the other status bytes are the status bytes in the control area 506 other than the first status byte.
[0091] In some embodiments, the microcontroller unit 502 is further configured to, when read processing is required for the non-volatile memory 504, determine the data partition to be read from multiple data partitions based on the byte values corresponding to multiple status bytes; the data storage state of the data partition to be read is a stored state; and read the data stored in the data partition to be read.
[0092] In some embodiments, the microcontroller unit 502 is further configured to determine the data partition to be read from multiple data partitions based on the byte values corresponding to multiple state bytes synchronized in the state mapping area of the volatile memory; and to read the data stored in the data partition to be read into the data mapping area of the volatile memory.
[0093] In some embodiments, the microcontroller unit 502 is further configured to traverse the byte values corresponding to multiple status bytes. If the byte value of each traversed status byte indicates that the data storage status of the corresponding data partition is stored, the data partition corresponding to the byte value of the last traversed status byte is determined as the data partition to be read. If the byte value of the currently traversed status byte indicates that the data storage status of the corresponding data partition is stored, and the byte value of the next to be traversed status byte indicates that the data storage status of the corresponding data partition is not stored, the data partition corresponding to the byte value of the currently traversed status byte is determined as the data partition to be read.
[0094] In some embodiments, a computer device is provided, which may be a server, and its internal structure diagram may be as follows: Figure 6 As shown, the computer device includes a processor, memory, and a network interface connected via a system bus. The processor provides computing and control capabilities. The memory includes non-volatile storage media and internal memory. The non-volatile storage media stores the operating system, computer programs, and a database. The internal memory provides an environment for the operation of the operating system and computer programs stored in the non-volatile storage media. The database stores data related to data access. The network interface communicates with external terminals via a network connection. When executed by the processor, the computer program implements a data access method.
[0095] In some embodiments, a computer device is provided, which may be a terminal, and its internal structure diagram may be as follows: Figure 7As shown, the computer device includes a processor, memory, input / output interfaces, a communication interface, a display unit, and an input device. The processor, memory, and input / output interfaces are connected via a system bus, and the communication interface, display unit, and input device are also connected to the system bus via the input / output interfaces. The processor provides computing and control capabilities. The memory includes non-volatile storage media and internal memory. The non-volatile storage media stores the operating system and computer programs. The internal memory provides an environment for the operation of the operating system and computer programs stored in the non-volatile storage media. The input / output interfaces are used for exchanging information between the processor and external devices. The communication interface is used for wired or wireless communication with external terminals; wireless communication can be achieved through Wi-Fi, mobile cellular networks, NFC (Near Field Communication), or other technologies. When the computer program is executed by the processor, it implements a data access method. The display unit is used to form a visually visible image and can be a display screen, a projection device, or a virtual reality imaging device. The display screen can be an LCD screen or an e-ink screen. The input device of the computer device can be a touch layer covering the display screen, or buttons, trackballs, or touchpads set on the casing of the computer device, or external keyboards, touchpads, or mice, etc.
[0096] Those skilled in the art will understand that Figure 6 and Figure 7 The structure shown is merely a block diagram of a portion of the structure related to the present application and does not constitute a limitation on the computer device to which the present application is applied. Specific computer devices may include more or fewer components than those shown in the figure, or combine certain components, or have different component arrangements.
[0097] In some embodiments, a computer device is also provided, the computer device including a memory and a processor, the memory storing a computer program, the processor executing the computer program to implement the steps in the above method embodiments.
[0098] In some embodiments, a computer-readable storage medium is provided having a computer program stored thereon that, when executed by a processor, implements the steps in the above method embodiments.
[0099] In some embodiments, a computer program product is provided, which includes a computer program that, when executed by a processor, implements the steps in the above method embodiments.
[0100] It should be noted that the user information (including but not limited to user device information, user personal information, etc.) and data (including but not limited to data used for analysis, data stored, data displayed, etc.) involved in this application are all information and data authorized by the user or fully authorized by all parties.
[0101] Those skilled in the art will understand that all or part of the processes in the methods of the above embodiments can be implemented by a computer program instructing related hardware. The computer program can be stored in a non-volatile computer-readable storage medium, and when executed, it can include the processes of the embodiments of the above methods. Any references to memory, databases, or other media used in the embodiments provided in this application can include at least one of non-volatile and volatile memory. Non-volatile memory can include read-only memory (ROM), magnetic tape, floppy disk, flash memory, optical memory, high-density embedded non-volatile memory, resistive random access memory (ReRAM), magnetic random access memory (MRAM), ferroelectric random access memory (FRAM), phase change memory (PCM), graphene memory, etc. Volatile memory can include random access memory (RAM) or external cache memory, etc. By way of illustration and not limitation, RAM can take many forms, such as Static Random Access Memory (SRAM) or Dynamic Random Access Memory (DRAM). The databases involved in the embodiments provided in this application may include at least one type of relational database and non-relational database. Non-relational databases may include, but are not limited to, blockchain-based distributed databases. The processors involved in the embodiments provided in this application may be general-purpose processors, central processing units, graphics processing units, digital signal processors, programmable logic devices, quantum computing-based data processing logic devices, etc., and are not limited to these.
[0102] The technical features of the above embodiments can be combined in any way. For the sake of brevity, not all possible combinations of the technical features in the above embodiments are described. However, as long as there is no contradiction in the combination of these technical features, they should be considered to be within the scope of this specification.
[0103] The embodiments described above are merely illustrative of several implementation methods of this application, and while the descriptions are specific and detailed, they should not be construed as limiting the scope of this patent application. It should be noted that those skilled in the art can make various modifications and improvements without departing from the concept of this application, and these all fall within the protection scope of this application. Therefore, the protection scope of this application should be determined by the appended claims.
Claims
1. A data access method, characterized in that, The method includes: The non-volatile memory is divided into a control area and a data area, and the status data of the control area is read. The non-volatile memory is integrated on the microcontroller unit. The data area has multiple data partitions. The status data includes byte values corresponding to multiple status bytes. The status bytes correspond to the data partitions, and the byte values are used to indicate the data storage status of the corresponding data partitions. The microcontroller unit also integrates volatile memory, which includes a status mapping area and a data mapping area opened when the microcontroller unit starts running. The status mapping area synchronously stores byte values corresponding to the multiple status bytes stored in the non-volatile memory. When a write operation is required for the non-volatile memory, and the byte value of each status byte in the control area indicates that the data storage status of the corresponding data partition is stored, the data stored in the specified sector is erased. Based on the byte values corresponding to multiple state bytes synchronized in the state mapping area, the data partition corresponding to the first state byte in the control area is determined as the data partition to be stored; the data storage state of the data partition to be stored is the unstored state; The data to be written, synchronized in the data mapping area, is written to the data partition to be stored. The byte value of the status byte corresponding to the data partition to be stored is modified in the status mapping area, and the modified byte value is synchronized to the control area. This is so that the byte value of the first status byte that is modified and synchronized indicates that the data storage status of the data partition to be stored is stored, and the byte values of the other status bytes indicate that the data storage status of the corresponding data partition is not stored. The other status bytes are the status bytes in the control area other than the first status byte.
2. The method according to claim 1, characterized in that, The method further includes: When a read operation is required for the non-volatile memory, the data partition to be read is determined from the multiple data partitions based on the byte values corresponding to the multiple status bytes; the data storage status of the data partition to be read is the stored state. Read the data stored in the data partition to be read.
3. The method according to claim 2, characterized in that, The step of determining the data partition to be read from the plurality of data partitions based on the byte values corresponding to the plurality of status bytes includes: Based on the byte values corresponding to multiple state bytes synchronized in the state mapping area of the volatile memory, the data partition to be read is determined from the multiple data partitions; The reading of the data stored in the data partition to be read includes: The data stored in the data partition to be read is read into the data mapping area of the volatile memory.
4. The method according to claim 2, characterized in that, The step of determining the data partition to be read from the plurality of data partitions based on the byte values corresponding to the plurality of status bytes includes: The byte values corresponding to the multiple status bytes are traversed. If the byte value of each traversed status byte indicates that the data storage status of the corresponding data partition is stored, the data partition corresponding to the byte value of the last traversed status byte is determined as the data partition to be read. If the byte value of the currently traversed status byte indicates that the data storage status of the corresponding data partition is stored, and the byte value of the next status byte to be traversed indicates that the data storage status of the corresponding data partition is not stored, then the data partition corresponding to the byte value of the currently traversed status byte is determined as the data partition to be read.
5. The method according to claim 1, characterized in that, The volatile memory is a temporary storage medium.
6. A data access system, characterized in that, The system includes: a microcontroller unit, which integrates non-volatile memory; the non-volatile memory is divided into a control area and a data area; the data area has multiple data partitions. The microcontroller unit is used to divide a designated sector of the non-volatile memory into a control area and a data area, and read the status data of the control area; the status data includes byte values corresponding to multiple status bytes, and the status bytes correspond to the data partition; the byte values are used to indicate the data storage status of the corresponding data partition; the microcontroller unit also integrates volatile memory, which includes a status mapping area and a data mapping area opened when the microcontroller unit starts running, and the status mapping area synchronously contains byte values corresponding to the multiple status bytes stored in the non-volatile memory; The microcontroller unit is used to erase the data already stored in the specified sector when write processing of the non-volatile memory is required, provided that the byte value of each status byte in the control area indicates that the data storage status of the corresponding data partition is stored; determine the data partition corresponding to the first status byte in the control area as the data partition to be stored based on the byte values corresponding to multiple status bytes synchronized in the status mapping area; the data storage status of the data partition to be stored is unstored; write the data to be written synchronized in the data mapping area to the data partition to be stored, modify the byte value of the status byte corresponding to the data partition to be stored in the status mapping area, and synchronize the modified byte value to the control area, so that the byte value of the modified and synchronized first status byte indicates that the data storage status of the data partition to be stored is stored, and the byte values of other status bytes indicate that the data storage status of the corresponding data partition is unstored; the other status bytes are the status bytes in the control area other than the first status byte.
7. The system according to claim 6, characterized in that, The volatile memory is a temporary storage medium.
8. A computer device comprising a memory and a processor, wherein the memory stores a computer program, characterized in that, When the processor executes the computer program, it implements the steps of the method according to any one of claims 1 to 5.
9. A computer-readable storage medium having a computer program stored thereon, characterized in that, When the computer program is executed by a processor, it implements the steps of the method according to any one of claims 1 to 5.
10. A computer program product comprising a computer program that, when executed by a processor, implements the steps of the method according to any one of claims 1 to 5.