1
0
mirror of https://bitbucket.org/librepilot/librepilot.git synced 2024-11-29 07:24:13 +01:00

CC-15 Gets settings saved to flash chip on CC using crude sector based storage.

Sector based on Object ID so could overlap :-(.

git-svn-id: svn://svn.openpilot.org/OpenPilot/trunk@2662 ebee16cc-31ac-478f-84a7-5cbb03baadba
This commit is contained in:
peabody124 2011-02-01 02:18:12 +00:00 committed by peabody124
parent ea91042f38
commit 97acaa2402
6 changed files with 73 additions and 6 deletions

View File

@ -183,7 +183,6 @@ SRC += $(OPUAVSYNTHDIR)/ratedesired.c
SRC += $(OPUAVSYNTHDIR)/manualcontrolsettings.c
SRC += $(OPUAVSYNTHDIR)/mixersettings.c
SRC += $(OPUAVSYNTHDIR)/mixerstatus.c
SRC += $(OPUAVSYNTHDIR)/ahrssettings.c
SRC += $(OPUAVSYNTHDIR)/firmwareiapobj.c
SRC += $(OPUAVSYNTHDIR)/uavobjectsinit.c
#${wildcard ${OBJ}/$(shell echo $(VAR) | tr A-Z a-z)/*.c}

View File

@ -55,12 +55,15 @@
#define PIOS_INCLUDE_FREERTOS
#define PIOS_INCLUDE_GPIO
#define PIOS_INCLUDE_EXTI
#define PIOS_INCLUDE_WDG
//#define PIOS_INCLUDE_WDG
#define PIOS_INCLUDE_I2C_ESC
#define PIOS_INCLUDE_ADXL345
#define PIOS_INCLUDE_FLASH
/* A really shitty setting saving implementation */
#define PIOS_INCLUDE_FLASH_SECTOR_SETTINGS
/* Defaults for Logging */
#define LOG_FILENAME "PIOS.LOG"
#define STARTUP_LOG_ENABLED 1

View File

@ -47,6 +47,7 @@ void PIOS_Board_Init(void) {
/* SPI Init */
PIOS_SPI_Init();
PIOS_Flash_W25X_Init();
#if defined(PIOS_INCLUDE_SPEKTRUM)
/* SPEKTRUM init must come before comms */

View File

@ -38,7 +38,6 @@ static int8_t PIOS_Flash_W25X_ClaimBus();
static void PIOS_Flash_W25X_ReleaseBus();
static uint8_t PIOS_Flash_W25X_WriteEnable();
static uint8_t PIOS_Flash_W25X_Busy() ;
//static uint8_t PIOS_Flash_W25X_EraseChip();
/**
* @brief Claim the SPI bus for flash use and assert CS pin
@ -129,7 +128,7 @@ uint8_t PIOS_Flash_W25X_ReadID()
int8_t PIOS_Flash_W25X_EraseSector(uint32_t addr)
{
uint8_t ret;
uint8_t out[] = {W25X_SECTOR_ERASE, (addr >> 16) && 0xff, (addr >> 8) && 0xff , addr && 0xff};
uint8_t out[] = {W25X_SECTOR_ERASE, (addr >> 16) & 0xff, (addr >> 8) & 0xff , addr & 0xff};
if((ret = PIOS_Flash_W25X_WriteEnable()) != 0)
return ret;
@ -153,7 +152,7 @@ int8_t PIOS_Flash_W25X_EraseSector(uint32_t addr)
* @brief Execute the whole chip
* @returns 0 if successful, -1 if unable to claim bus
*/
/*static uint8_t PIOS_Flash_W25X_EraseChip()
int8_t PIOS_Flash_W25X_EraseChip()
{
uint8_t ret;
uint8_t out[] = {W25X_CHIP_ERASE};
@ -172,7 +171,7 @@ int8_t PIOS_Flash_W25X_EraseSector(uint32_t addr)
#endif
}
return 0;
}*/
}
/**

View File

@ -10,6 +10,7 @@
int8_t PIOS_Flash_W25X_Init();
uint8_t PIOS_Flash_W25X_ReadStatus();
uint8_t PIOS_Flash_W25X_ReadID();
int8_t PIOS_Flash_W25X_EraseChip();
int8_t PIOS_Flash_W25X_EraseSector(uint32_t add);
int8_t PIOS_Flash_W25X_WriteData(uint32_t addr, uint8_t * data, uint16_t len);
int8_t PIOS_Flash_W25X_ReadData(uint32_t addr, uint8_t * data, uint16_t len);

View File

@ -562,6 +562,14 @@ 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.
@ -574,6 +582,32 @@ int32_t UAVObjSaveToFile(UAVObjHandle obj, uint16_t instId, FILEINFO* file)
*/
int32_t UAVObjSave(UAVObjHandle obj, uint16_t instId)
{
#if defined(PIOS_INCLUDE_FLASH_SECTOR_SETTINGS)
ObjectList* objEntry = (ObjectList*)obj;
if(objEntry == NULL)
return -1;
ObjectInstList* instEntry = getInstance(objEntry, instId);
if(instEntry == NULL)
return -1;
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);
#endif
#if defined(PIOS_INCLUDE_SDCARD)
FILEINFO file;
ObjectList* objEntry;
@ -710,6 +744,36 @@ UAVObjHandle UAVObjLoadFromFile(FILEINFO* file)
*/
int32_t UAVObjLoad(UAVObjHandle obj, uint16_t instId)
{
#if defined(PIOS_INCLUDE_FLASH_SECTOR_SETTINGS)
ObjectList* objEntry = (ObjectList*)obj;
if(objEntry == NULL)
return -1;
ObjectInstList* instEntry = getInstance(objEntry, instId);
if(instEntry == NULL)
return -1;
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
sendEvent(objEntry, instId, EV_UNPACKED);
#endif
#if defined(PIOS_INCLUDE_SDCARD)
FILEINFO file;
ObjectList* objEntry;