In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-20 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly introduces "What is the NVM area data backup mechanism". In daily operation, I believe many people have doubts about what the NVM area data backup mechanism is. The editor has consulted all kinds of materials and sorted out simple and easy operation methods. I hope to help you answer the doubts about "What is the NVM area data backup mechanism"! Next, please follow the small series to learn together!
NVM area is the main feature of the write data power loss is not lost, can permanently save data, generally used to store data that is not often modified, this function is similar to FLASH. Writing data to NVM can be divided into three steps: the first step is to read the original data in the target sector into RAM; the second step is to erase the data in the NVM target sector; and the third step is to write the new data and the old data in RAM into the sector. Based on the characteristics of the above write operation, it can be seen that if the chip is powered off during the second or third step of the write operation in NVM area, the original data in NVM area will be lost, and the new data will fail to be written, showing the phenomenon of data disorder in NVM area. Although this is only a small probability event, it is necessary to add data backup mechanism for stability and product robustness.
There are two basic schemes for data backup, which are suitable for application scenarios with small and large data volumes respectively. This issue introduces a small data backup scheme, which requires that the amount of data updated each time is less than one sector size minus 1. In this example, the sector size is 256 bytes, so the maximum amount of updated data is 255 bytes. (Note: NVM sector size of different chip models will vary, you can contact Lingke Technology to confirm). The implementation idea is to select two areas from NVM area, and the last byte of each area records the operation times of this area. This flag determines which region should be selected for updating data. Cycle the two regions in turn. When operating region 1, region 2 acts as a backup, and vice versa.
First write data
Step 1: Define NVM area addresses 0x0000 ~ 0x00FF as Block1 and 0x0200 ~ 0x02FF as Block2.
#define Block1 0x0000
#define Block2 0x0200
Step 2: Define a 256-byte array databuf and a flag variable cnt, and assign cnt a value of 0.
unsigned char databuf[256];
Unsigned char cnt = 0;
Step 3: Copy the target data (data to be written) to the databuf array and copy cnt+1 to databuf+255.
databuf[255] = cnt+1;
Step 4: Call WriteNVM function to write data databuf to Block1, write length 256 bytes. Call WriteNVM function to write cnt to Block2+255 position, write length 1 byte
WriteNVM(Block1,databuf,256);
WriteNVM(Block2+255,&cnt,1);
update data
Step 1: Call ReadNVM function to read the flag bits (last byte) of Block1 and Block2 respectively.
unsigned char flag1,flag2;
ReadNVM(Block1+255,&flag1,1);
ReadNVM(Block2+255,&flag2,1);
Step 2: Judge the size of the flag bits of the two blocks, and select the Block with the small flag bit value to update. Copy the target data (data to be written) to the databuf array, and add 2 to the flag bit and copy it to the databuf+255 position.
if(flag1 > flag2)
{
cnt = flag2 + 2;
databuf[255] = cnt;
WriteNVM(Block2,databuf,256);
}else{
cnt = flag1 +2;
databuf[255] = cnt;
WriteNVM(Block1,databuf,256);
}
read data
Step 1: Read Block1 and Block2 flag data.
ReadNVM(Block1+255,&flag1,1);
ReadNVM(Block2+255,&flag2,1);
Step 2: Judge the size of the flag bit. Block with large value is new data, and Block with small value is old data.
if(flag1 > flag2)
{
ReadNVM(Block1,databuf,255);
}else{
ReadNVM(Block2,databuf,255);
}
At this point, the study of "what is the data backup mechanism of NVM area" is over, hoping to solve everyone's doubts. Theory and practice can better match to help you learn, go and try it! If you want to continue learning more relevant knowledge, please continue to pay attention to the website, Xiaobian will continue to strive to bring more practical articles for everyone!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.