diff --git a/flight/CopterControl/Makefile b/flight/CopterControl/Makefile index f499d549a..7c3895534 100644 --- a/flight/CopterControl/Makefile +++ b/flight/CopterControl/Makefile @@ -205,6 +205,7 @@ SRC += $(PIOSSTM32F10X)/pios_usb_hid_prop.c SRC += $(PIOSSTM32F10X)/pios_usb_hid_pwr.c ## PIOS Hardware (Common) +SRC += $(PIOSCOMMON)/pios_flashfs_objlist.c SRC += $(PIOSCOMMON)/pios_flash_w25x.c SRC += $(PIOSCOMMON)/pios_adxl345.c SRC += $(PIOSCOMMON)/pios_com.c diff --git a/flight/CopterControl/System/pios_board.c b/flight/CopterControl/System/pios_board.c index 45164052f..c5943ca3c 100644 --- a/flight/CopterControl/System/pios_board.c +++ b/flight/CopterControl/System/pios_board.c @@ -678,8 +678,10 @@ void PIOS_Board_Init(void) { PIOS_DEBUG_Assert(0); } - PIOS_Flash_W25X_Init(pios_spi_flash_accel_id); + PIOS_Flash_W25X_Init(pios_spi_flash_accel_id); PIOS_ADXL345_Attach(pios_spi_flash_accel_id); + + PIOS_FLASHFS_Init(); #if defined(PIOS_INCLUDE_SPEKTRUM) /* SPEKTRUM init must come before comms */ diff --git a/flight/PiOS/pios.h b/flight/PiOS/pios.h index cbf2a2249..0fdb03570 100644 --- a/flight/PiOS/pios.h +++ b/flight/PiOS/pios.h @@ -1,135 +1,136 @@ -/** - ****************************************************************************** - * - * @file pios.h - * @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010. - * @brief Main PiOS header. - * - Central header for the project. - * @see The GNU Public License (GPL) Version 3 - * - *****************************************************************************/ -/* - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY - * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - - -#ifndef PIOS_H -#define PIOS_H - -/* PIOS Feature Selection */ -#include "pios_config.h" - -#if defined(PIOS_INCLUDE_FREERTOS) -/* FreeRTOS Includes */ -#include "FreeRTOS.h" -#include "task.h" -#include "queue.h" -#include "semphr.h" -#endif - -/* C Lib Includes */ -#include -#include -#include -#include -#include - -/* STM32 Std Perf Lib */ -#include -#include - -#if defined(PIOS_INCLUDE_SDCARD) -/* Dosfs Includes */ -#include - -/* Mass Storage Device Includes */ -#include -#endif - -/* Generic initcall infrastructure */ -#include "pios_initcall.h" - -/* PIOS Board Specific Device Configuration */ -#include "pios_board.h" - -/* PIOS Hardware Includes (STM32F10x) */ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#if defined(PIOS_INCLUDE_EXTI) -#include -#endif -#include - -/* PIOS Hardware Includes (Common) */ -#include -#include -#if defined(PIOS_INCLUDE_BMP085) -#include -#endif -#if defined(PIOS_INCLUDE_HCSR04) -#include -#endif -#if defined(PIOS_INCLUDE_HMC5843) -#include -#endif -#if defined(PIOS_INCLUDE_HMC5883) -#include -#endif -#if defined(PIOS_INCLUDE_I2C_ESC) -#include -#endif -#if defined(PIOS_INCLUDE_IMU3000) -#include -#endif -#include - -#if defined(PIOS_INCLUDE_ADXL345) -#include -#endif - -#if defined(PIOS_INCLUDE_BMA180) -#include -#endif - -#if defined(PIOS_INCLUDE_FLASH) -#include -#endif - -#if defined(PIOS_INCLUDE_BL_HELPER) -#include -#endif - -#if defined(PIOS_INCLUDE_USB) -/* USB Libs */ -#include -#endif - -#define NELEMENTS(x) (sizeof(x) / sizeof(*(x))) - -#endif /* PIOS_H */ +/** + ****************************************************************************** + * + * @file pios.h + * @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010. + * @brief Main PiOS header. + * - Central header for the project. + * @see The GNU Public License (GPL) Version 3 + * + *****************************************************************************/ +/* + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + + +#ifndef PIOS_H +#define PIOS_H + +/* PIOS Feature Selection */ +#include "pios_config.h" + +#if defined(PIOS_INCLUDE_FREERTOS) +/* FreeRTOS Includes */ +#include "FreeRTOS.h" +#include "task.h" +#include "queue.h" +#include "semphr.h" +#endif + +/* C Lib Includes */ +#include +#include +#include +#include +#include + +/* STM32 Std Perf Lib */ +#include +#include + +#if defined(PIOS_INCLUDE_SDCARD) +/* Dosfs Includes */ +#include + +/* Mass Storage Device Includes */ +#include +#endif + +/* Generic initcall infrastructure */ +#include "pios_initcall.h" + +/* PIOS Board Specific Device Configuration */ +#include "pios_board.h" + +/* PIOS Hardware Includes (STM32F10x) */ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#if defined(PIOS_INCLUDE_EXTI) +#include +#endif +#include + +/* PIOS Hardware Includes (Common) */ +#include +#include +#if defined(PIOS_INCLUDE_BMP085) +#include +#endif +#if defined(PIOS_INCLUDE_HCSR04) +#include +#endif +#if defined(PIOS_INCLUDE_HMC5843) +#include +#endif +#if defined(PIOS_INCLUDE_HMC5883) +#include +#endif +#if defined(PIOS_INCLUDE_I2C_ESC) +#include +#endif +#if defined(PIOS_INCLUDE_IMU3000) +#include +#endif +#include + +#if defined(PIOS_INCLUDE_ADXL345) +#include +#endif + +#if defined(PIOS_INCLUDE_BMA180) +#include +#endif + +#if defined(PIOS_INCLUDE_FLASH) +#include +#include +#endif + +#if defined(PIOS_INCLUDE_BL_HELPER) +#include +#endif + +#if defined(PIOS_INCLUDE_USB) +/* USB Libs */ +#include +#endif + +#define NELEMENTS(x) (sizeof(x) / sizeof(*(x))) + +#endif /* PIOS_H */ diff --git a/flight/Project/OpenPilotOSX/OpenPilotOSX.xcodeproj/project.pbxproj b/flight/Project/OpenPilotOSX/OpenPilotOSX.xcodeproj/project.pbxproj index 5dd95349b..7095dfad5 100644 --- a/flight/Project/OpenPilotOSX/OpenPilotOSX.xcodeproj/project.pbxproj +++ b/flight/Project/OpenPilotOSX/OpenPilotOSX.xcodeproj/project.pbxproj @@ -3171,6 +3171,8 @@ 65FF4BE913791C3300146BE4 /* Makefile */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.make; path = Makefile; sourceTree = ""; }; 65FF4BEA13791C3300146BE4 /* op_dfu.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = op_dfu.c; sourceTree = ""; }; 65FF4BEB13791C3300146BE4 /* pios_board.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = pios_board.c; sourceTree = ""; }; + 65FF4D5E137EDEC100146BE4 /* pios_flashfs_objlist.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = pios_flashfs_objlist.c; sourceTree = ""; }; + 65FF4D61137EFA4F00146BE4 /* pios_flashfs_objlist.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = pios_flashfs_objlist.h; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXGroup section */ @@ -7657,6 +7659,7 @@ 65E8F03711EFF25C00BBF654 /* printf-stdarg.c */, 6528CCB412E406B800CF5144 /* pios_adxl345.c */, 6512D60712ED4CB8008175E5 /* pios_flash_w25x.c */, + 65FF4D5E137EDEC100146BE4 /* pios_flashfs_objlist.c */, ); name = Common; path = ../../PiOS/Common; @@ -7681,6 +7684,7 @@ 65E8F03E11EFF25C00BBF654 /* pios_debug.h */, 65E8F03F11EFF25C00BBF654 /* pios_delay.h */, 65E8F04011EFF25C00BBF654 /* pios_exti.h */, + 65FF4D61137EFA4F00146BE4 /* pios_flashfs_objlist.h */, 65E8F04111EFF25C00BBF654 /* pios_gpio.h */, 65E8F04211EFF25C00BBF654 /* pios_hmc5843.h */, 65E8F04311EFF25C00BBF654 /* pios_i2c.h */, diff --git a/flight/UAVObjects/uavobjectmanager.c b/flight/UAVObjects/uavobjectmanager.c index 50558d411..2d681ab3b 100644 --- a/flight/UAVObjects/uavobjectmanager.c +++ b/flight/UAVObjects/uavobjectmanager.c @@ -562,14 +562,6 @@ int32_t UAVObjSaveToFile(UAVObjHandle obj, uint16_t instId, FILEINFO* file) return 0; } -struct fileHeader { - uint32_t id; - uint16_t instId; - uint16_t size; -} __attribute__((packed)); - -#define FLASH_MASK 0x001ff000 /* Select a sector */ - /** * Save the data of the specified object to the file system (SD card). * If the object contains multiple instances, all of them will be saved. @@ -596,17 +588,8 @@ int32_t UAVObjSave(UAVObjHandle obj, uint16_t instId) if(instEntry->data == NULL) return -1; - - struct fileHeader header = { - .id = objEntry->id, - .instId = instId, - .size = objEntry->numBytes - }; - - uint32_t addr = (objEntry->id & FLASH_MASK); - PIOS_Flash_W25X_EraseSector(addr); - PIOS_Flash_W25X_WriteData(addr, (uint8_t *) &header, sizeof(header)); - PIOS_Flash_W25X_WriteData(addr + sizeof(header), instEntry->data,objEntry->numBytes); + if(PIOS_FLASHFS_ObjSave(obj, instId, instEntry->data) != 0) + return -1; #endif #if defined(PIOS_INCLUDE_SDCARD) FILEINFO file; @@ -758,19 +741,8 @@ int32_t UAVObjLoad(UAVObjHandle obj, uint16_t instId) if(instEntry->data == NULL) return -1; - struct fileHeader header; - uint32_t addr = (objEntry->id & FLASH_MASK); - - PIOS_Flash_W25X_ReadData(addr, (uint8_t *) &header, sizeof(header)); - - if(header.id != objEntry->id) - return -1; - - // Read the instance data - if (PIOS_Flash_W25X_ReadData(addr + sizeof(header) ,instEntry->data, objEntry->numBytes) != 0) - return -1; - - // Fire event + // Fire event on success + if(PIOS_FLASHFS_ObjSave(obj, instId, instEntry->data) == 0) sendEvent(objEntry, instId, EV_UNPACKED); #endif @@ -837,13 +809,7 @@ int32_t UAVObjLoad(UAVObjHandle obj, uint16_t instId) int32_t UAVObjDelete(UAVObjHandle obj, uint16_t instId) { #if defined(PIOS_INCLUDE_FLASH_SECTOR_SETTINGS) - ObjectList* objEntry = (ObjectList*)obj; - - if(objEntry == NULL) - return -1; - - uint32_t addr = (objEntry->id & FLASH_MASK); - PIOS_Flash_W25X_EraseSector(addr); + PIOS_FLASHFS_ObjDelete(obj, instId); #endif #if defined(PIOS_INCLUDE_SDCARD) ObjectList* objEntry;