1.3.5. User Flash Memory Data Save and Retrieval Method
The design writes the data into the UFM before the device is powered down, and reads back the data from the UFM when the device is powered up again. The challenge is to determine which location or address in the UFM the design should write the data into, and then be able to go back to the same address upon power-up to read back the data.
The erased UFM has all 1’s as the content. When you write any data to the UFM, the data is written to the existing content in the UFM through an AND logic. In other words, if a 0 is written into a location that has 1, the content becomes 0. If a 1 is written into a location that has 1, the content remains 1. When the content becomes 0, you cannot write 1 to that location again, except when the entire sector of the UFM is erased.
Alternatively, the controller uses only one address in the UFM for data storage. Every time before the device is powered down, the controller writes the data to a fixed address in the UFM. When the device is powered up, the controller goes directly to that address to read back the data.
Using the same address allows the address to be hard-coded in the design, thus making the design simpler. However, one drawback is that every time before the write operation occurs, the entire sector of the UFM must be erased before new data can be written into it. This process slows down the operation as erase time is much longer as compared to the duration for read or write operations.
Because the supported Altera device is SRAM-based, any data not stored in the flash memory is lost when a power cycle occurs. Although the data is safely stored in the UFM, the device cannot recall the location in the UFM where the data is stored. Searching all of the addresses in the UFM is time-consuming and does not actually tell the controller which data is the most recent data written into the UFM.
In this example application, a new method is used. Instead of using only one address from the total of 256 addresses from sector 0 of the UFM, this method uses 240 addresses for data storage, and another 15 addresses to store header information.
The header section is used to keep track of the most recent address into which the controller has written. Upon power-up, the controller only checks the header section to determine the location where the data is stored just before the device is powered down. The header section spans from address 0x000 to address 0x00E—15 addresses total.
Each bit in the header section represents the validity of the data in one address in the data section. The first bit in the header section, which is the least significant bit (LSB) of address 0x000, represents address 0x010 in the data section, and so on. If the header bit is 0, this means that the address in the data section contains valid data. Header bit 1 means the address in the data section is blank.
During power-up, the controller reads the header address one by one. Data is written into addresses in the data section sequentially, from address 0x000 to address 0x015, from LSB to MSB of each address. The controller can determine which addresses in the data section has been used based on the number of 0’s in the header section.
If the controller identifies that the MSB in a particular header address is 0’s, it recognizes that the header address contains 16 bits of 0’s and proceeds to read from the next header address. If the controller identifies that the MSB in the header address is 1, the controller then proceeds to check how many 0’s are in that header address to determine the exact location in which the data is stored. However, if the data in this header address is all 1’s, the controller recognizes that the previous header address has all 0’s.
By checking the header section, the controller can determine the exact location where the data was stored before the device was powered down.
When the device is powered down, the controller writes the counter data into the next blank data address, and then writes a 0 in the subsequent header bit location. If the UFM sector is full, the controller first erases the sector before writing the data into the first address in the data section, and then writes 0 into the first bit in the header section.
The benefits of using header data include the following:
- The controller does not need to search all the addresses in sector 0 of the UFM to find the correct data. The header section only occupies a total of 15 addresses in sector 0 of the UFM. The controller does not have to search for more than 15 addresses to determine where the most recent data is located.
- The header indicates to the controller whether the data in a particular location is valid. If the data written into an address is coincidentally all 1’s, it will appear that the address is blank, because erasing the UFM sets all the data in all addresses to all 1’s. In this case, the header bit shows that the data is valid.
Did you find the information on this page useful?