mirror of
https://bitbucket.org/librepilot/librepilot.git
synced 2024-12-02 10:24:11 +01:00
REVONANO - Flash fs fixes
This commit is contained in:
parent
632a14023c
commit
fb11b312c5
@ -173,32 +173,25 @@ int32_t PIOS_Flash_EEPROM_WriteSinglePage(struct flash_eeprom_dev *flash_dev, co
|
|||||||
uint8_t i2c_addr = flash_dev->i2c_address;
|
uint8_t i2c_addr = flash_dev->i2c_address;
|
||||||
uint32_t bus = flash_dev->i2c_adapter;
|
uint32_t bus = flash_dev->i2c_adapter;
|
||||||
|
|
||||||
|
|
||||||
if (address > 0xFFFF) {
|
if (address > 0xFFFF) {
|
||||||
return -2;
|
return -2;
|
||||||
}
|
}
|
||||||
uint16_t address16 = address & 0xFFFF;
|
uint16_t address16 = address & 0xFFFF;
|
||||||
|
|
||||||
uint8_t mem_address[] = {
|
uint8_t tmp[len + 2];
|
||||||
(address16 & 0xff00) >> 8, // MSB
|
tmp[0] = (address16 & 0xFF00) >> 8; // MSB
|
||||||
(address16 & 0xFF) // LSB
|
tmp[1] = (address16 & 0xFF); // LSB
|
||||||
};
|
|
||||||
|
|
||||||
|
memcpy(&tmp[2], buffer, len);
|
||||||
|
|
||||||
const struct pios_i2c_txn txn_list[] = {
|
const struct pios_i2c_txn txn_list[] = {
|
||||||
{
|
{
|
||||||
.info = __func__,
|
.info = __func__,
|
||||||
.addr = i2c_addr,
|
.addr = i2c_addr,
|
||||||
.rw = PIOS_I2C_TXN_WRITE,
|
.rw = PIOS_I2C_TXN_WRITE,
|
||||||
.len = 2,
|
.len = len + 2,
|
||||||
.buf = mem_address,
|
.buf = tmp,
|
||||||
}
|
|
||||||
,
|
|
||||||
{
|
|
||||||
.info = __func__,
|
|
||||||
.addr = i2c_addr,
|
|
||||||
.rw = PIOS_I2C_TXN_WRITE,
|
|
||||||
.len = len,
|
|
||||||
.buf = (uint8_t *)buffer,
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -223,21 +216,21 @@ int32_t PIOS_Flash_EEPROM_Read(struct flash_eeprom_dev *flash_dev, const uint32_
|
|||||||
// split the operation into several page operations
|
// split the operation into several page operations
|
||||||
uint8_t bytes_read = 0;
|
uint8_t bytes_read = 0;
|
||||||
|
|
||||||
const uint8_t page_len = flash_dev->cfg->page_len;
|
const uint16_t page_len = flash_dev->cfg->page_len;
|
||||||
|
|
||||||
while (bytes_read < len) {
|
while (bytes_read < len) {
|
||||||
// all is fine, wait until memory is not busy
|
// all is fine, wait until memory is not busy
|
||||||
int32_t status;
|
int32_t status;
|
||||||
while ((status = PIOS_Flash_EEPROM_Busy(flash_dev)) == 1) {
|
while ((status = PIOS_Flash_EEPROM_Busy(flash_dev)) == 1) {
|
||||||
#ifdef PIOS_INCLUDE_FREERTOS
|
#ifdef PIOS_INCLUDE_FREERTOS
|
||||||
vTaskDelay(1);
|
vTaskDelay(0);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
// An error occurred while probing the status, return and report
|
// An error occurred while probing the status, return and report
|
||||||
if (status < 0) {
|
if (status < 0) {
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
uint8_t current_block_len = len - bytes_read;
|
uint16_t current_block_len = len - bytes_read;
|
||||||
uint16_t index_within_page = (address16 + bytes_read) % page_len;
|
uint16_t index_within_page = (address16 + bytes_read) % page_len;
|
||||||
// prevent overflowing the page boundary
|
// prevent overflowing the page boundary
|
||||||
current_block_len = MIN(page_len - index_within_page, current_block_len);
|
current_block_len = MIN(page_len - index_within_page, current_block_len);
|
||||||
@ -248,6 +241,7 @@ int32_t PIOS_Flash_EEPROM_Read(struct flash_eeprom_dev *flash_dev, const uint32_
|
|||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -121,7 +121,6 @@ int32_t PIOS_FLASHFS_Init(uintptr_t *fs_id, const struct flashfs_cfg *cfg, const
|
|||||||
|
|
||||||
// Check for valid object table or create one
|
// Check for valid object table or create one
|
||||||
uint32_t object_table_magic;
|
uint32_t object_table_magic;
|
||||||
uint32_t magic_fail_count = 0;
|
|
||||||
bool magic_good = false;
|
bool magic_good = false;
|
||||||
*fs_id = (uintptr_t)dev;
|
*fs_id = (uintptr_t)dev;
|
||||||
|
|
||||||
@ -130,18 +129,13 @@ int32_t PIOS_FLASHFS_Init(uintptr_t *fs_id, const struct flashfs_cfg *cfg, const
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
if (object_table_magic != dev->cfg->table_magic) {
|
if (object_table_magic != dev->cfg->table_magic) {
|
||||||
if (magic_fail_count++ > MAX_BADMAGIC) {
|
|
||||||
if (PIOS_FLASHFS_Format(*fs_id) != 0) {
|
if (PIOS_FLASHFS_Format(*fs_id) != 0) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
#if defined(PIOS_LED_HEARTBEAT)
|
#if defined(PIOS_LED_HEARTBEAT)
|
||||||
PIOS_LED_Toggle(PIOS_LED_HEARTBEAT);
|
PIOS_LED_Toggle(PIOS_LED_HEARTBEAT);
|
||||||
#endif /* PIOS_LED_HEARTBEAT */
|
#endif /* PIOS_LED_HEARTBEAT */
|
||||||
magic_fail_count = 0;
|
|
||||||
magic_good = true;
|
magic_good = true;
|
||||||
} else {
|
|
||||||
PIOS_DELAY_WaituS(1000);
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
magic_good = true;
|
magic_good = true;
|
||||||
}
|
}
|
||||||
@ -182,21 +176,15 @@ int32_t PIOS_FLASHFS_Format(uintptr_t fs_id)
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!dev->driver->start_transaction(dev->flash_id)) {
|
if (dev->driver->start_transaction(dev->flash_id)) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if (dev->driver->erase_chip) {
|
|
||||||
if (dev->driver->erase_chip(dev->flash_id) != 0) {
|
|
||||||
dev->driver->end_transaction(dev->flash_id);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (PIOS_FLASHFS_ClearObjectTableHeader(dev) != 0) {
|
if (PIOS_FLASHFS_ClearObjectTableHeader(dev) != 0) {
|
||||||
|
dev->driver->end_transaction(dev->flash_id);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
dev->driver->end_transaction(dev->flash_id);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -227,7 +215,7 @@ static int32_t PIOS_FLASHFS_ClearObjectTableHeader(struct flashfs_dev *dev)
|
|||||||
* @brief Get the address of an object
|
* @brief Get the address of an object
|
||||||
* @param obj UAVObjHandle for that object
|
* @param obj UAVObjHandle for that object
|
||||||
* @parma instId Instance id for that object
|
* @parma instId Instance id for that object
|
||||||
* @return address if successful, -1 if not found
|
* @return address if successful, -1 if not found, -2 if failure occurred while reading
|
||||||
*/
|
*/
|
||||||
static int32_t PIOS_FLASHFS_GetObjAddress(struct flashfs_dev *dev, uint32_t objId, uint16_t instId)
|
static int32_t PIOS_FLASHFS_GetObjAddress(struct flashfs_dev *dev, uint32_t objId, uint16_t instId)
|
||||||
{
|
{
|
||||||
@ -238,7 +226,7 @@ static int32_t PIOS_FLASHFS_GetObjAddress(struct flashfs_dev *dev, uint32_t objI
|
|||||||
while (addr < dev->cfg->obj_table_end) {
|
while (addr < dev->cfg->obj_table_end) {
|
||||||
// Read the instance data
|
// Read the instance data
|
||||||
if (dev->driver->read_data(dev->flash_id, addr, (uint8_t *)&header, sizeof(header)) != 0) {
|
if (dev->driver->read_data(dev->flash_id, addr, (uint8_t *)&header, sizeof(header)) != 0) {
|
||||||
return -1;
|
return -2;
|
||||||
}
|
}
|
||||||
if (header.objMagic != dev->cfg->obj_magic) {
|
if (header.objMagic != dev->cfg->obj_magic) {
|
||||||
break; // stop searching once hit first non-object header
|
break; // stop searching once hit first non-object header
|
||||||
|
Loading…
Reference in New Issue
Block a user