mirror of
https://bitbucket.org/librepilot/librepilot.git
synced 2025-03-02 19:29:15 +01:00
OP-216: Some small bugs where things were stored
This commit is contained in:
parent
d883c8af9f
commit
d312e876c4
@ -78,20 +78,22 @@ int32_t PIOS_FLASHFS_Init()
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool found = true;
|
|
||||||
int32_t addr = OBJECT_TABLE_START;
|
int32_t addr = OBJECT_TABLE_START;
|
||||||
struct objectHeader header;
|
struct objectHeader header;
|
||||||
numObjects = 0;
|
numObjects = 0;
|
||||||
|
|
||||||
// Loop through header area while objects detect to count how many saved
|
// Loop through header area while objects detect to count how many saved
|
||||||
while(found && addr < OBJECT_TABLE_END) {
|
while(addr < OBJECT_TABLE_END) {
|
||||||
// Read the instance data
|
// Read the instance data
|
||||||
if (PIOS_Flash_W25X_ReadData(addr, (uint8_t *)&header, sizeof(header)) != 0)
|
if (PIOS_Flash_W25X_ReadData(addr, (uint8_t *)&header, sizeof(header)) != 0)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
|
// Counting number of valid headers
|
||||||
if(header.objMagic != OBJ_MAGIC)
|
if(header.objMagic != OBJ_MAGIC)
|
||||||
found = false;
|
break;
|
||||||
else
|
|
||||||
numObjects++;
|
numObjects++;
|
||||||
|
addr += sizeof(header);
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
@ -121,22 +123,22 @@ static int32_t PIOS_FLAHFS_CleabObjectTableHeader()
|
|||||||
*/
|
*/
|
||||||
static int32_t PIOS_FLASHFS_GetObjAddress(uint32_t objId, uint16_t instId)
|
static int32_t PIOS_FLASHFS_GetObjAddress(uint32_t objId, uint16_t instId)
|
||||||
{
|
{
|
||||||
bool found = true;
|
|
||||||
int32_t addr = OBJECT_TABLE_START;
|
int32_t addr = OBJECT_TABLE_START;
|
||||||
struct objectHeader header;
|
struct objectHeader header;
|
||||||
|
|
||||||
// Loop through header area while objects detect to count how many saved
|
// Loop through header area while objects detect to count how many saved
|
||||||
while(found && addr < OBJECT_TABLE_END) {
|
while(addr < OBJECT_TABLE_END) {
|
||||||
// Read the instance data
|
// Read the instance data
|
||||||
if (PIOS_Flash_W25X_ReadData(addr, (uint8_t *) &header, sizeof(header)) != 0)
|
if (PIOS_Flash_W25X_ReadData(addr, (uint8_t *) &header, sizeof(header)) != 0)
|
||||||
return -1;
|
return -1;
|
||||||
if(header.objMagic != OBJ_MAGIC)
|
if(header.objMagic != OBJ_MAGIC)
|
||||||
found = false;
|
break; // stop searching once hit first non-object header
|
||||||
else if (header.objId == objId && header.instId == instId)
|
else if (header.objId == objId && header.instId == instId)
|
||||||
break;
|
break;
|
||||||
|
addr += sizeof(header);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (found)
|
if (header.objId == objId && header.instId == instId)
|
||||||
return header.address;
|
return header.address;
|
||||||
|
|
||||||
return -1;
|
return -1;
|
||||||
@ -154,7 +156,6 @@ static int32_t PIOS_FLASHFS_GetObjAddress(uint32_t objId, uint16_t instId)
|
|||||||
*/
|
*/
|
||||||
int32_t PIOS_FLASHFS_GetNewAddress(uint32_t objId, uint16_t instId)
|
int32_t PIOS_FLASHFS_GetNewAddress(uint32_t objId, uint16_t instId)
|
||||||
{
|
{
|
||||||
int32_t addr = OBJECT_TABLE_START;
|
|
||||||
struct objectHeader header;
|
struct objectHeader header;
|
||||||
|
|
||||||
if(numObjects < 0)
|
if(numObjects < 0)
|
||||||
@ -164,7 +165,9 @@ int32_t PIOS_FLASHFS_GetNewAddress(uint32_t objId, uint16_t instId)
|
|||||||
header.objMagic = OBJ_MAGIC;
|
header.objMagic = OBJ_MAGIC;
|
||||||
header.objId = objId;
|
header.objId = objId;
|
||||||
header.instId = instId;
|
header.instId = instId;
|
||||||
header.address = SECTOR_SIZE * numObjects;
|
header.address = OBJECT_TABLE_END + SECTOR_SIZE * numObjects;
|
||||||
|
|
||||||
|
int32_t addr = OBJECT_TABLE_START + sizeof(header) * numObjects;
|
||||||
|
|
||||||
// No room for this header in object table
|
// No room for this header in object table
|
||||||
if((addr + sizeof(header)) > OBJECT_TABLE_END)
|
if((addr + sizeof(header)) > OBJECT_TABLE_END)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user