From 07af6b5c8018b2c0f0a2802e361b570dc7b52f29 Mon Sep 17 00:00:00 2001 From: Alessio Morale Date: Tue, 7 May 2013 01:29:30 +0200 Subject: [PATCH] Added LogFS support for OPLinkMini with internal flash --- .../modules/RadioComBridge/RadioComBridge.c | 39 ++++++++++--------- .../oplinkmini/firmware/inc/pios_config.h | 2 +- .../boards/oplinkmini/firmware/pios_board.c | 16 +++----- 3 files changed, 27 insertions(+), 30 deletions(-) diff --git a/flight/modules/RadioComBridge/RadioComBridge.c b/flight/modules/RadioComBridge/RadioComBridge.c index 8e047b3b8..d31be7362 100644 --- a/flight/modules/RadioComBridge/RadioComBridge.c +++ b/flight/modules/RadioComBridge/RadioComBridge.c @@ -471,38 +471,41 @@ static void ProcessInputStream(UAVTalkConnection connectionHandle, uint8_t rxbyt switch (obj_per.Operation) { case OBJECTPERSISTENCE_OPERATION_LOAD: { -#if defined(PIOS_INCLUDE_FLASH_EEPROM) +#if defined(PIOS_INCLUDE_FLASH_SECTOR_SETTINGS) // Load the settings. - OPLinkSettingsData oplinkSettings; - if (PIOS_EEPROM_Load((uint8_t*)&oplinkSettings, sizeof(OPLinkSettingsData)) == 0) - OPLinkSettingsSet(&oplinkSettings); - else + void *obj = UAVObjGetByID(obj_per.ObjectID); + if (obj == 0) { success = false; + } else { + // Load selected instance + success = (UAVObjLoad(obj, obj_per.InstanceID) == 0); + } #endif break; } case OBJECTPERSISTENCE_OPERATION_SAVE: { -#if defined(PIOS_INCLUDE_FLASH_EEPROM) - // Save the settings. - OPLinkSettingsData oplinkSettings; - OPLinkSettingsGet(&oplinkSettings); - int32_t ret = PIOS_EEPROM_Save((uint8_t*)&oplinkSettings, sizeof(OPLinkSettingsData)); - if (ret != 0) +#if defined(PIOS_INCLUDE_FLASH_SECTOR_SETTINGS) + void *obj = UAVObjGetByID(obj_per.ObjectID); + if (obj == 0) { success = false; + } else { + // Save selected instance + success = UAVObjSave(obj, obj_per.InstanceID) == 0; + } #endif break; } case OBJECTPERSISTENCE_OPERATION_DELETE: { -#if defined(PIOS_INCLUDE_FLASH_EEPROM) - // Erase the settings. - OPLinkSettingsData oplinkSettings; - uint8_t *ptr = (uint8_t*)&oplinkSettings; - memset(ptr, 0, sizeof(OPLinkSettingsData)); - int32_t ret = PIOS_EEPROM_Save(ptr, sizeof(OPLinkSettingsData)); - if (ret != 0) +#if defined(PIOS_INCLUDE_FLASH_SECTOR_SETTINGS) + void *obj = UAVObjGetByID(obj_per.ObjectID); + if (obj == 0) { success = false; + } else { + // Save selected instance + success = UAVObjDelete(obj, obj_per.InstanceID) == 0; + } #endif break; } diff --git a/flight/targets/boards/oplinkmini/firmware/inc/pios_config.h b/flight/targets/boards/oplinkmini/firmware/inc/pios_config.h index 8e58eda34..b8e0a346e 100644 --- a/flight/targets/boards/oplinkmini/firmware/inc/pios_config.h +++ b/flight/targets/boards/oplinkmini/firmware/inc/pios_config.h @@ -109,7 +109,7 @@ #define PIOS_INCLUDE_FLASH_INTERNAL #define PIOS_INCLUDE_FLASH_SECTOR_SETTINGS /* #define FLASH_FREERTOS */ -#define PIOS_INCLUDE_FLASH_EEPROM +//#define PIOS_INCLUDE_FLASH_EEPROM /* PIOS radio modules */ #define PIOS_INCLUDE_RFM22B diff --git a/flight/targets/boards/oplinkmini/firmware/pios_board.c b/flight/targets/boards/oplinkmini/firmware/pios_board.c index 26675e7f5..dcee1a2ee 100644 --- a/flight/targets/boards/oplinkmini/firmware/pios_board.c +++ b/flight/targets/boards/oplinkmini/firmware/pios_board.c @@ -117,8 +117,6 @@ void PIOS_Board_Init(void) { #endif /* PIOS_INCLUDE_LED */ OPLinkSettingsData oplinkSettings; -#if defined(PIOS_INCLUDE_FLASH_EEPROM) - PIOS_EEPROM_Init(&pios_eeprom_cfg); /* IAP System Setup */ PIOS_IAP_Init(); @@ -128,7 +126,8 @@ void PIOS_Board_Init(void) { PIOS_IAP_ReadBootCmd(2) == PIOS_IAP_CLEAR_FLASH_CMD_2) { OPLinkSettingsGet(&oplinkSettings); OPLinkSettingsSetDefaults(&oplinkSettings,0); - PIOS_EEPROM_Save((uint8_t*)&oplinkSettings, sizeof(OPLinkSettingsData)); + OPLinkSettingsSet(&oplinkSettings); + //PIOS_EEPROM_Save((uint8_t*)&oplinkSettings, sizeof(OPLinkSettingsData)); for (uint32_t i = 0; i < 10; i++) { PIOS_DELAY_WaitmS(100); PIOS_LED_Toggle(PIOS_LED_HEARTBEAT); @@ -137,15 +136,10 @@ void PIOS_Board_Init(void) { PIOS_IAP_WriteBootCmd(1,0); PIOS_IAP_WriteBootCmd(2,0); } - /* Read the settings from flash. */ - /* NOTE: We probably need to save/restore the objID here incase the object changed but the size doesn't */ - if (PIOS_EEPROM_Load((uint8_t*)&oplinkSettings, sizeof(OPLinkSettingsData)) == 0) - OPLinkSettingsSet(&oplinkSettings); - else - OPLinkSettingsGet(&oplinkSettings); -#else OPLinkSettingsGet(&oplinkSettings); -#endif /* PIOS_INCLUDE_FLASH_EEPROM */ +//#else +// OPLinkSettingsGet(&oplinkSettings); +//#endif /* PIOS_INCLUDE_FLASH_EEPROM */ /* Initialize the task monitor library */ TaskMonitorInitialize();