[En-Nut-Discussion] saving data to the eeprom
Peter Sodermanns
peter.sodermanns at aixcon.de
Wed Aug 17 08:46:10 CEST 2005
Peter Gaskell schrieb:
> I wish to save some data in the EEPROM so it will load at startup, in
> case of power failure etc. I've looked in the API, it mentions
> NutSaveConfig(), how can i give my data a home in the Config?
>
> -peter
>
> _______________________________________________
> En-Nut-Discussion mailing list
> En-Nut-Discussion at egnite.de
> http://www.egnite.de/mailman/listinfo.cgi/en-nut-discussion
>
Hi Peter,
I found the clue in the nutpiper example, file config.c.
My parameter values are defined in a global struct gp, and I use these
(modified) functions to read them at startup and to save them on change:
//----------------------------------------------------------------------------------------
// Load configuration from EEPROM.
// return 0 on success, -1 if no configuration data had been found.
//----------------------------------------------------------------------------------------
int ConfigLoad(void)
{
int rc;
int addr;
char *buf;
int oldaddr;
rc = -1;
addr = CONFAPP_EE_OFFSET;
buf = malloc(MAXLEN_URL + 1);
if (NULL != buf) {
addr += ConfigLoadString(addr, buf, sizeof(CONFAPP_EE_NAME));
// printf(" Anwendung = %s\n", buf);
if (strcmp(buf, CONFAPP_EE_NAME) == 0) {
rc = 0;
oldaddr = addr;
addr += ConfigLoadBinary(addr, gp, sizeof(TGlobalPar));
// printf(" %d Konfigurationsbytes vom EEPROM gelesen.\n", addr-oldaddr);
}
free(buf);
}
// printf(" %d WR\n", gp->AnzWr);
// printf(" Gruppe %s\n", gp->Name);
return rc;
}
//----------------------------------------------------------------------------------------
// Save configuration into EEPROM.
//----------------------------------------------------------------------------------------
void ConfigSave(void)
{
int addr = CONFAPP_EE_OFFSET;
int oldaddr;
NutNetSaveConfig();
/* Save our name. */
oldaddr = addr;
addr += ConfigSaveString(addr, CONFAPP_EE_NAME);
/* Save radio control. */
oldaddr = addr;
addr += ConfigSaveBinary(addr, gp, sizeof(TGlobalPar));
// printf("Anwendung %s: %d Bytes ins EEPROM gesichert.\n",
CONFAPP_EE_NAME, addr-oldaddr);
}
More information about the En-Nut-Discussion
mailing list