A database based on a single-chip machine FLASH and a database operation method

By dividing the FLASH memory into functional areas and recording the time and overwrite count bit by bit, the problem of limited FLASH memory capacity of the microcontroller is solved, achieving efficient data storage and retrieval, and extending the lifespan of the FLASH memory.

CN115329167BActive Publication Date: 2025-12-16HENAN HANWEI ELECTRONICS
View PDF 3 Cites 0 Cited by

Patent Information

Application Number
CN202210883464.6
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-07-26
Publication Date
2025-12-16
Estimated Expiration
2042-07-26

AI Technical Summary

Technical Problem

In existing technologies, the Flash capacity of microcontrollers is limited, making it difficult to store a large amount of data and resulting in low access efficiency, which affects the product development cycle.

Method used

The database based on microcontroller FLASH achieves classified storage and compression of data records by dividing functional areas and recording time and overwrite times by bit encoding. It also improves access efficiency by using sequential, time, or event retrieval methods.

Benefits of technology

It enables the classified storage and compression of data records, improves data access efficiency, and extends the lifespan of Flash memory.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure 197964DEST_PATH_IMAGE002
    Figure 197964DEST_PATH_IMAGE002
Patent Text Reader

Abstract

This invention provides a database based on a microcontroller's FLASH memory and a method for operating the database. The database is constructed as follows: based on the page capacity of the microcontroller's FLASH memory, the internal storage area of ​​the Flash memory is divided into functional areas according to data types. Each functional area consists of two consecutive pages. n Page structure; after partitioning, a write-to-zero operation is performed on the entire storage unit of the database area; each data record stored in the microcontroller's FLASH memory includes the record time, record overwrite count, and record content, encoded bit by bit, with each record having a capacity of 1 / 2 of a page. m Each data record is stored in the corresponding functional area according to its content; within each functional area, each data record is stored page by page in the order it was generated; when the storage reaches the end of the functional area, it automatically jumps to the beginning of the functional area for cyclic storage and automatically overwrites the original data.
Need to check novelty before this filing date? Find Prior Art

Description

TECHNICAL FIELD

[0001] The present application belongs to the technical field of data storage, and particularly relates to a database based on a single-chip microcomputer FLASH and a running method of the database. BACKGROUND

[0002] As a core device of embedded development, the single-chip microcomputer plays an indispensable role in the development of electronic products. In the process of working, the single-chip microcomputer collects a large amount of data for developers to use, analyze and solve problems, and provide the basis for product development. Therefore, developers often save these data in the FLASH of the single-chip microcomputer. However, the types of data collected by the single-chip microcomputer are various, and the existing method only stores them in fixed addresses, and the data has no obvious classification, so the efficiency of storing and reading data is low, which undoubtedly slows down the development cycle of the product.

[0003] For example, CN102819468A discloses a small data backup and query method based on FLASH. A time tag is written before writing data in each data storage page, by using the mapping relationship between the time point of storing data and the storage location. When storing data, a sector is used as an operation unit, and each sector has a similar storage structure. The order before and after is identified by the sector number and the page time tag. When a sector is full of data, the earliest used sector is found, and the sector is cleared and used as the current working sector, so that uniform wear is achieved, and data storage and query are simple and fast.

[0004] For example, CN106202276A discloses a Bluetooth OBD long-time data saving implementation method. A small database management system is created by software. The database management system performs function area division, data erasing, updating, reading and writing operations according to the saving requirements of different data information stored in the FLASH. Through the balance writing processing of the FLASH and the historical data rollback mechanism, the data amount saved in the working condition data area is increased, the number of FLASH erasing times is reduced, the service life of the FLASH is prolonged, and the long-time data saving of the Bluetooth OBD is realized.

[0005] The above two patents both propose solutions in some aspects, but the capacity of the single-chip microcomputer FLASH is not very large at present, and in some application scenarios, the single-chip microcomputer FLASH needs to store a large amount of data and meet the requirement of fast access.

[0006] In order to solve the above problems, people have been seeking an ideal technical solution. SUMMARY

[0007] The present application aims at the deficiencies of the prior art, and provides a database based on a single-chip microcomputer FLASH and a running method of the database.

[0008] To achieve the above object, the technical scheme adopted by the present application is:

[0009] The first aspect of the present application provides a database based on single-chip microcomputer FLASH, which is constructed according to the following method:

[0010] According to the capacity of each page of the single-chip microcomputer FLASH, the internal storage area of the FLASH is divided into functional areas according to data types, each functional area is composed of continuous 2 n pages, and n is a positive integer; the functional areas include an alarm record area, an alarm record release area, a fault record area, a fault record release area, a power-on record area, and a power-off record area;

[0011] After the partitioning is completed, the storage units of the database area are subjected to an overall write-0 operation;

[0012] Each data record stored in the single-chip microcomputer FLASH includes a record time, a record overwrite number, and a record content, and the record time, the record overwrite number, and the record content are encoded by bits; the capacity of each record is 1 / 2 m of a page, and m is a positive integer, which is a fixed value in the entire database system; wherein the record time is the time when the data record is generated; the record content is an alarm, an alarm release, a fault, a fault release, power-on, or power-off; and the record overwrite number indicates the newness or oldness of the data record;

[0013] Each data record is stored in the corresponding functional area according to the record content; in each functional area, each data record is stored in sequence according to the generation order; when the storage reaches the end of the functional area, the storage is automatically switched to the beginning of the functional area for cyclic storage, and the original data is automatically overwritten.

[0014] The second aspect of the present application provides a running method of the database based on single-chip microcomputer FLASH:

[0015] Each time when the database has a data read-write requirement, the page number of the corresponding partition is determined according to the data type of the read-write data, and the record overwrite number of each data record is traversed in the order from front to back in these pages to find the demarcation point where the number changes from large to small; if the record overwrite numbers of all data records are consistent, the first address of the first page of the functional area is marked as the demarcation point; the overwrite number k of the next record of the demarcation point is read, the last data record before the demarcation point is set as the newest data record, and the first data record after the demarcation point is set as the oldest data record;

[0016] If the database needs to query a data record, the newest data record is searched forward;

[0017] If the database needs to write a data record, the data record to be written is overwritten in the storage area where the oldest data record is located, and the record overwriting number of the latest record is marked as k+1.

[0018] Based on the above, the retrieval of the database further includes using time retrieval or event retrieval on the basis of sequential retrieval, wherein the events include alarm events, alarm cancellation events, fault events, fault cancellation events, power-on events and power-off events.

[0019] Based on the above, the retrieval of the database further includes using time retrieval or event retrieval alone, wherein the events include alarm events, alarm cancellation events, fault events, fault cancellation events, power-on events and power-off events.

[0020] The beneficial effects of the present application are:

[0021] 1) Data record classified storage, facilitating sequential query;

[0022] 2) Data encoding by bit, realizing data record compression;

[0023] 3) Only the latest data record is retained, reducing storage space;

[0024] 4) No database index and pointer are set, increasing the service life of FLASH memory. DETAILED DESCRIPTION

[0025] The technical solutions of the present application will be further described in detail through specific embodiments.

[0026] Embodiment 1

[0027] The present embodiment provides a database based on single-chip microcomputer FLASH, and the database is constructed according to the following method:

[0028] Based on the capacity of each page of the single-chip microcomputer FLASH, the internal storage area of the Flash is divided into functional areas according to data types, each functional area is composed of 2 n pages in succession, and n is a positive integer; the functional areas include alarm record area, alarm record cancellation area, fault record area, fault record cancellation area, power-on record area and power-off record area;

[0029] After the partitioning is completed, the storage units of the database area are subjected to overall 0 writing operation;

[0030] Each data record stored in the single-chip microcomputer FLASH includes record time, record overwriting number and record content, and the record time, the record overwriting number and the record content are encoded by bit, and the capacity of each record is 1 / 2 m, m is a positive integer, m is a fixed value in the whole database system; wherein, the record time is the time when the data record is generated; the record content is alarm, alarm cancellation, failure, failure cancellation, power on or power off; the record overwriting times indicate the new and old of the data record;

[0031] Each data record is stored in the corresponding functional area according to the record content; in each functional area, each data record is stored in sequence according to the generation order, and is stored in pages in turn; when stored to the end of the functional area, it is automatically switched to the beginning of the functional area for circular storage, and the original data is automatically overwritten.

[0032] Embodiment 2

[0033] The embodiment provides a running method of the database based on the single-chip machine FLASH in embodiment 1, and specifically includes the following steps.

[0034] Each time when the database has data reading and writing requirements, firstly, the page number of the corresponding partition is determined according to the data type of reading and writing, and the record overwriting times of each data record are traversed in the pages in the order from front to back to find the demarcation point in which the number changes from large to small; if the record overwriting times of all data records are consistent, the first address of the first page of the functional area is marked as the demarcation point; the overwriting times k of the next record of the demarcation point are read, the last data record before the demarcation point is set as the newest data record, and the first data record after the demarcation point is set as the oldest data record;

[0035] If the database needs to query a data record, the newest data record is searched forward;

[0036] If the database needs to write a data record, the data record is written in the storage area of the oldest data record, and the record overwriting times of the newest record are marked as k+1.

[0037] Embodiment 3

[0038] The difference between the embodiment and embodiment 2 lies in that the database retrieval further includes time retrieval on the basis of sequential retrieval.

[0039] Embodiment 4

[0040] The difference between the embodiment and embodiment 2 lies in that the database retrieval further includes event retrieval on the basis of sequential retrieval, wherein the events include alarm events, alarm cancellation events, failure events, failure cancellation events, power on events and power off events.

[0041] Embodiment 5

[0042] The difference between the embodiment and embodiment 2 lies in that the database retrieval further includes time retrieval alone.

[0043] Embodiment 6

[0044] The difference between this embodiment and embodiment 2 is that the retrieval of the database further includes retrieval using events alone, wherein the events include alarm events, alarm cancellation events, fault events, fault cancellation events, power-on events and power-off events.

[0045] Embodiment 7

[0046] This embodiment provides a specific method for establishing a database based on a single-chip microcomputer FLASH, and a method for running the database, comprising:

[0047] A Establishing a database

[0048] A1, the operating system of the single-chip microcomputer acquires the page capacity of the flash memory chip as 512 bytes, so that the page size of the established database system is defined as 512 bytes (it can also be set as 1024 bytes, 2048 bytes, etc. according to needs);

[0049] A2, the operating system of the single-chip microcomputer divides the flash memory chip from the initial address, and continuously divides an alarm record area, an alarm record cancellation area, a fault record area, a fault record cancellation area, a power-on record area and a power-off record area, each of which occupies 16 consecutive pages (the number of pages occupied by each area can be different, but must satisfy 2n pages, and the pages must be consecutive);

[0050] A3, the operating system of the single-chip microcomputer performs a 0 filling operation on all the divided pages.

[0051] Setting record coding

[0052] B1, set each data record as 64 bits, or set as 1 / 2m of the capacity of each page (m is a positive integer, and m is a fixed value in the entire database system), and the following will be introduced taking 64 bits as an example;

[0053] B2, in 64 bits, 2 bits are occupied by the number of overwrites, 0x00 is not recorded, 0x01 is recorded once, 0x10 is overwritten once, and 0x11 is overwritten twice;

[0054] Record time 30 bits, of which 4 bits are year, 0x0000 is 2022, 0x0001 is 2023, 0x0010 is 2024, 0x0011 is 2025, and so on; 4 bits are month, 0x0000 is not recorded, 0x0001 is January, 0x0010 is February, 0x0011 is March, and so on; 5 bits are date, 0x0000 is not recorded, 0x00001 is 1st, 0x00010 is 2nd, and so on; 5 bits are hours, 0x00000 is 0 o'clock, 0x00001 is 1 o'clock, and so on; 6 bits are minutes and seconds, 0x000000 is 00 minutes (seconds), 0x000001 is 01 minutes (seconds), and so on;

[0055] The record content occupies 32 bits, and binary code is compiled according to specific needs.

[0056] The encoding is as follows:

[0057]

[0058] C Database runtime operation

[0059] C1 Preparation before database read-write operation

[0060] C11, before each database operation (including reading and writing and other operations), the operating system of the single-chip microcomputer first determines the type of record to be processed, and finds the start and end addresses of the corresponding partition according to the type; for example, the start address of the alarm record release area is the start address of the 17th page, which is 0x2000; the end address is the end address of the 32nd page, which is 0x3FFF;

[0061] C12, the operating system of the single-chip microcomputer traverses the first two bits k0k1 (i.e. the overwrite times of each record) of the bytes with the start address as the base address and j*8 (j is a natural number) as the variable address, that is, the first two bits of the bytes at addresses such as 0x2000, 0x2008, 0x2010, 0x2018, and so on, until the end of the end address of the partition;

[0062] C13, mark the node where the k0k1 of each data record changes from large to small as the demarcation point (for k0k1, this embodiment considers that 00>11), if the overwrite times of all data records in the partition are consistent, mark the start address of the function area as the demarcation point;

[0063] C14, identify the last data record before the demarcation point as the latest data record, and identify the first data record after the demarcation point as the oldest data record;

[0064] C15, record the overwrite times k of the last data record before the demarcation point;

[0065] Write of C2 database

[0066] C21, the single-chip computer calculates k+1 in C15 (addition in the domain of 2-bit binary number), writes the first two bits of the first byte after the boundary point, and writes the time code and record content in turn after the boundary point, to complete a data record;

[0067] Read of C3 database

[0068] C31, complete reading of the last data record before the boundary point;

[0069] C32, judging whether other data records need to be read and the search needs to be continued according to the content of the last data record before the boundary point.

[0070] Example 8

[0071] This example provides a specific search method of the database:

[0072] D1, sequential search according to the number of entries

[0073] D11, first determine the number q of the sequential search, q is not greater than the total number of data record entries in the partition;

[0074] D12, continuously read multiple data records from the boundary point forward;

[0075] D13, if the month code is 0000 during the reading process, abandon the current entry reading and exit;

[0076] D14, if the reading is not completed to the first address of the partition, jump to the last address of the partition to continue reading from back to front;

[0077] D2, search according to time

[0078] D21, continuously read p (the preferred value is 8) records in the order of entries into the single-chip computer memory to search and analyze the time code; if no valid record is searched, continue to read p records into the single-chip computer memory to search and analyze the time code; until a suitable record is searched or the total number of reading reaches the maximum value of the partition;

[0079] D3, search according to event content

[0080] D31, continuously read p (the preferred value is 8) records in the order of entries into the single-chip computer memory to search and analyze the content code; if no valid record is searched, continue to read p records into the single-chip computer memory to search and analyze the content code; until a suitable record is searched or the total number of reading reaches the maximum value of the partition.

[0081] It should be pointed out finally that the above examples are only used to illustrate the technical solutions of the present application but not to limit it; although the present application has been described in detail with reference to the preferred embodiments, it should be understood by those skilled in the art that the specific embodiments of the present application can be modified or some technical features can be replaced by equivalent ones without departing from the spirit of the technical solutions of the present application, and all of them should be covered in the technical solution range claimed by the present application.

Claims

1. A database based on a microcontroller's FLASH memory, characterized in that, The database is constructed using the following method: Based on the single-chip microcontroller's FLASH page capacity, the internal Flash storage area is divided into functional areas according to data type. Each functional area consists of two consecutive pages. n Page structure, where n is a positive integer; functional areas include alarm record area, alarm record cancellation area, fault record area, fault record cancellation area, power-on record area and power-off record area; After partitioning is complete, perform a write-to-zero operation on the entire storage unit of the database area; Each data record stored in the microcontroller's FLASH memory includes the recording time, the number of times the record has been overwritten, and the recording content. The recording time, the number of times the record has been overwritten, and the recording content are encoded bit by bit. The capacity of each record is 1 / 2 of a page. m m is a positive integer, and m is a fixed value throughout the database system; the record time is the time when the data record is generated; the record content is alarm, alarm cleared, fault, fault cleared, power on or power off; the record overwrite count indicates the age of the data record. Each data record is stored in the corresponding functional area according to its content; within each functional area, each data record is stored page by page in the order it was generated; when the storage reaches the end of the functional area, it automatically jumps to the beginning of the functional area for cyclic storage and automatically overwrites the original data.

2. A method for operating a database based on a microcontroller FLASH as described in claim 1, characterized in that: Whenever the database has a data read / write requirement, the page number of the corresponding partition is first determined according to the type of data to be read / written. In these pages, the record overwrite count of each data record is traversed in reverse order to find the dividing point where the count changes from large to small. If the record overwrite count of all data records is the same, the first address of the home page of this functional area is marked as the dividing point. The overwrite count k of the record next to the dividing point is read, and the last data record before the dividing point is set as the latest data record, and the first data record after the dividing point is set as the oldest data record. If the database needs to query a data record, it searches backwards from the latest data record. If the database needs to write a data record, the data record to be written will be overwritten in the storage area where the oldest data record is located, and the overwrite count of the record to be written to the latest record will be marked as k+1.

3. The method for operating a database based on a microcontroller FLASH according to claim 2, characterized in that: Database retrieval also includes the use of time-based or event-based retrieval on top of sequential retrieval. Events include alarm events, alarm clearing events, fault events, fault clearing events, power-on events, and power-off events.

4. The method for operating a database based on a microcontroller FLASH according to claim 2, characterized in that: Database retrieval also includes time-based retrieval or event-based retrieval, where events include alarm events, alarm clearing events, fault events, fault clearing events, power-on events, and power-off events.

Citation Information

Patent Citations

  • Backup and query method of FLASH-based small data

    CN102819468A

  • Bluetooth OBD long-time data storage implementation method

    CN106202276A

  • Storage method for NAND FLASH data

    CN104391804A