mirror of
https://bitbucket.org/librepilot/librepilot.git
synced 2025-01-19 04:52:12 +01:00
Flashfs: Whenever failing out of a transaction unlock the semaphore
This commit is contained in:
parent
85bfa7dcf9
commit
f311700804
@ -239,8 +239,10 @@ int32_t PIOS_FLASHFS_ObjSave(UAVObjHandle obj, uint16_t instId, uint8_t * data)
|
|||||||
addr = PIOS_FLASHFS_GetNewAddress(objId, instId);
|
addr = PIOS_FLASHFS_GetNewAddress(objId, instId);
|
||||||
|
|
||||||
// Could not allocate a sector
|
// Could not allocate a sector
|
||||||
if(addr < 0)
|
if(addr < 0) {
|
||||||
|
PIOS_Flash_Jedec_EndTransaction();
|
||||||
return -1;
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
struct fileHeader header = {
|
struct fileHeader header = {
|
||||||
.id = objId,
|
.id = objId,
|
||||||
@ -252,8 +254,10 @@ int32_t PIOS_FLASHFS_ObjSave(UAVObjHandle obj, uint16_t instId, uint8_t * data)
|
|||||||
crc = PIOS_CRC_updateCRC(0, (uint8_t *) &header, sizeof(header));
|
crc = PIOS_CRC_updateCRC(0, (uint8_t *) &header, sizeof(header));
|
||||||
crc = PIOS_CRC_updateCRC(crc, (uint8_t *) data, UAVObjGetNumBytes(obj));
|
crc = PIOS_CRC_updateCRC(crc, (uint8_t *) data, UAVObjGetNumBytes(obj));
|
||||||
|
|
||||||
if(PIOS_Flash_Jedec_EraseSector(addr) != 0)
|
if(PIOS_Flash_Jedec_EraseSector(addr) != 0) {
|
||||||
|
PIOS_Flash_Jedec_EndTransaction();
|
||||||
return -2;
|
return -2;
|
||||||
|
}
|
||||||
|
|
||||||
struct pios_flash_chunk chunks[3] = {
|
struct pios_flash_chunk chunks[3] = {
|
||||||
{
|
{
|
||||||
@ -270,11 +274,15 @@ int32_t PIOS_FLASHFS_ObjSave(UAVObjHandle obj, uint16_t instId, uint8_t * data)
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
if(PIOS_Flash_Jedec_WriteChunks(addr, chunks, NELEMENTS(chunks)) != 0)
|
if(PIOS_Flash_Jedec_WriteChunks(addr, chunks, NELEMENTS(chunks)) != 0) {
|
||||||
|
PIOS_Flash_Jedec_EndTransaction();
|
||||||
return -1;
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
if(PIOS_Flash_Jedec_EndTransaction() != 0)
|
if(PIOS_Flash_Jedec_EndTransaction() != 0) {
|
||||||
|
PIOS_Flash_Jedec_EndTransaction();
|
||||||
return -1;
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -308,21 +316,27 @@ int32_t PIOS_FLASHFS_ObjLoad(UAVObjHandle obj, uint16_t instId, uint8_t * data)
|
|||||||
int32_t addr = PIOS_FLASHFS_GetObjAddress(objId, instId);
|
int32_t addr = PIOS_FLASHFS_GetObjAddress(objId, instId);
|
||||||
|
|
||||||
// Object currently not saved
|
// Object currently not saved
|
||||||
if(addr < 0)
|
if(addr < 0) {
|
||||||
|
PIOS_Flash_Jedec_EndTransaction();
|
||||||
return -1;
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
struct fileHeader header;
|
struct fileHeader header;
|
||||||
|
|
||||||
// Load header
|
// Load header
|
||||||
// This information IS redundant with the object table id. Oh well. Better safe than sorry.
|
// This information IS redundant with the object table id. Oh well. Better safe than sorry.
|
||||||
if(PIOS_Flash_Jedec_ReadData(addr, (uint8_t *) &header, sizeof(header)) != 0)
|
if(PIOS_Flash_Jedec_ReadData(addr, (uint8_t *) &header, sizeof(header)) != 0) {
|
||||||
|
PIOS_Flash_Jedec_EndTransaction();
|
||||||
return -2;
|
return -2;
|
||||||
|
}
|
||||||
|
|
||||||
// Update CRC
|
// Update CRC
|
||||||
crc = PIOS_CRC_updateCRC(0, (uint8_t *) &header, sizeof(header));
|
crc = PIOS_CRC_updateCRC(0, (uint8_t *) &header, sizeof(header));
|
||||||
|
|
||||||
if((header.id != objId) || (header.instId != instId))
|
if((header.id != objId) || (header.instId != instId)) {
|
||||||
|
PIOS_Flash_Jedec_EndTransaction();
|
||||||
return -3;
|
return -3;
|
||||||
|
}
|
||||||
|
|
||||||
// To avoid having to allocate the RAM for a copy of the object, we read by chunks
|
// To avoid having to allocate the RAM for a copy of the object, we read by chunks
|
||||||
// and compute the CRC
|
// and compute the CRC
|
||||||
@ -333,15 +347,21 @@ int32_t PIOS_FLASHFS_ObjLoad(UAVObjHandle obj, uint16_t instId, uint8_t * data)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Read CRC (written so will work when CRC changes to uint16)
|
// Read CRC (written so will work when CRC changes to uint16)
|
||||||
if(PIOS_Flash_Jedec_ReadData(addr + sizeof(header) + objSize, (uint8_t *) &crcFlash, sizeof(crcFlash)) != 0)
|
if(PIOS_Flash_Jedec_ReadData(addr + sizeof(header) + objSize, (uint8_t *) &crcFlash, sizeof(crcFlash)) != 0) {
|
||||||
|
PIOS_Flash_Jedec_EndTransaction();
|
||||||
return -5;
|
return -5;
|
||||||
|
}
|
||||||
|
|
||||||
if(crc != crcFlash)
|
if(crc != crcFlash) {
|
||||||
|
PIOS_Flash_Jedec_EndTransaction();
|
||||||
return -6;
|
return -6;
|
||||||
|
}
|
||||||
|
|
||||||
// Read the instance data
|
// Read the instance data
|
||||||
if (PIOS_Flash_Jedec_ReadData(addr + sizeof(header), data, objSize) != 0)
|
if (PIOS_Flash_Jedec_ReadData(addr + sizeof(header), data, objSize) != 0) {
|
||||||
|
PIOS_Flash_Jedec_EndTransaction();
|
||||||
return -4;
|
return -4;
|
||||||
|
}
|
||||||
|
|
||||||
if(PIOS_Flash_Jedec_EndTransaction() != 0)
|
if(PIOS_Flash_Jedec_EndTransaction() != 0)
|
||||||
return -1;
|
return -1;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user