Forum Discussion
Altera_Forum
Honored Contributor
13 years agoHi San,
--- Quote Start --- Can u make it simple for me to understand please ? --- Quote End --- I'll try. Here's what your code needs to be able to do: 1) Processor boots. 2) Processor looks in the user area in flash for the user configured frequency value. If it finds it, it uses it. If there is no user value, it uses a default. 3) If the user enters a new frequency value, the processor writes it to flash. Flash memory starts out set to 0xFF. Lets say your frequency value is two bytes, i.e., a 16-bit value. In your C-code you can have something like this;
int16_t *user_flash = 0x12340000; /* Start of user flash area */
int16_t frequency = -1;
uint16_t user_len = 0x100; /* Number of frequency values per sector */
uint16_t i;
/* Seach for a value that is not 0xFFFF = -1 */
for (i = 0; i < user_len; i++) {
frequency = user_flash;
if (frequency != -1)
break;
}
if (frequency == -1) {
/* No user value specified, so use default */
frequency = 123;
}
....
This is an extremely simple example, so that you get the concept. Now that you know what you are looking for, try and look at actual implementations. If you were using a bootloader like U-Boot, then this type of variable is saved in the environment section in flash. Cheers, Dave