1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2024-12-29 04:50:03 +01:00
RIOT/boards/msba2-common/board_config.c

22 lines
584 B
C
Raw Normal View History

#include <stdint.h>
#include <string.h>
#include <config.h>
#include <flashrom.h>
2013-09-19 16:53:35 +02:00
void config_load(void) {
2010-12-06 13:19:31 +01:00
extern char configmem[];
/* cast it here for strict-aliasing */
2013-09-19 16:53:35 +02:00
uint16_t* tmp = (uint16_t*) configmem;
if (*tmp == CONFIG_KEY) {
memcpy(&sysconfig, (configmem + sizeof(CONFIG_KEY)), sizeof(sysconfig));
}
else {
config_save();
}
2010-12-06 13:19:31 +01:00
}
2013-09-19 16:53:35 +02:00
uint8_t config_save(void) {
configmem_t mem = { CONFIG_KEY, sysconfig };
2013-09-19 16:53:35 +02:00
return (flashrom_erase((uint8_t*) &configmem) && flashrom_write((uint8_t*) &configmem, (char*) &mem, sizeof(mem)));
}