Mercurial > public > ostc4
diff Discovery/Src/externLogbookFlash.c @ 452:b90ddf57f7f1 minor_improvments
Added compile variant enabling the reset of profile sample information:
In case the sample ring has an overrun prior to the header ring then header will point to no longer available sample locations causing problems when the no longer existing samples are read. To avoid this also in earlier versions a variant has been added which enables the user to reset the invalid sample information by selecting the problematic dive in the infolog menu and pressing the middle button.
Added function which confirms consistency of dive log settings:
Meaning last dive and dive header are valid at startup. Repair and find lastDiveID are only called in case a inconsistency is detected
author | ideenmodellierer |
---|---|
date | Tue, 24 Mar 2020 21:59:11 +0100 |
parents | 7f351c25608a |
children | 7ac0e76dbd6a |
line wrap: on
line diff
--- a/Discovery/Src/externLogbookFlash.c Tue Mar 24 21:49:52 2020 +0100 +++ b/Discovery/Src/externLogbookFlash.c Tue Mar 24 21:59:11 2020 +0100 @@ -1353,6 +1353,40 @@ } */ +uint8_t ext_dive_log_consistent(void) +{ + uint8_t ret = 0; + uint8_t header1, header2; + uint8_t id; + convert_Type dataStart; + + SSettings *settings = settingsGetPointer(); + id = settings->lastDiveLogId; + + actualAddress = HEADERSTART + (0x800 * id); + ext_flash_read_block_start(); + ext_flash_read_block(&header1, EF_HEADER); + ext_flash_read_block(&header2, EF_HEADER); + dataStart.u8bit.byteHigh = 0; + ext_flash_read_block(&dataStart.u8bit.byteLow, EF_HEADER); + ext_flash_read_block(&dataStart.u8bit.byteMidLow, EF_HEADER); + ext_flash_read_block(&dataStart.u8bit.byteMidHigh, EF_HEADER); + ext_flash_read_block_stop(); + if((header1 == 0xFA) && (header2 == 0xFA)) /* Header is indicating the start of a dive */ + { + actualAddress = HEADERSTART + (0x800 * id) + HEADER2OFFSET; + ext_flash_read_block_start(); + ext_flash_read_block(&header1, EF_HEADER); + ext_flash_read_block(&header2, EF_HEADER); + ext_flash_read_block_stop(); + if((header1 == 0xFA) && (header2 == 0xFA)) /* Secondary header was written at the end of a dive */ + { + ret = 1; /* => lastDiveLogID points to a valid dive entry */ + } + } + return ret; +} + // =============================================================================== // ext_flash_repair_dive_log /// @brief This function @@ -1361,6 +1395,7 @@ /// and /// lastDiveLogId /// + void ext_flash_repair_dive_log(void) { uint8_t header1, header2; @@ -2240,6 +2275,67 @@ return startedSectors; } +/* In case of a sample ring overrun the headers of the dive which will no longer have sample data needs to be updated */ +void ext_flash_invalidate_sample_index(uint32_t sectorStart) +{ + uint8_t emptySamples[] = {0,0,0, 0,0,0, 0,0,0}; /* entry of start, stop and length */ + uint8_t diveidx; + + uint8_t header1, header2; + + SSettings *settings = settingsGetPointer(); + diveidx = settings->lastDiveLogId + 1; + convert_Type dataStart, dataEnd; + + uint32_t HeaderAddrBackup = actualPointerHeader; + + while(diveidx != settings->lastDiveLogId) + { + actualAddress = HEADERSTART + (0x800 * diveidx) + HEADER2OFFSET; + ext_flash_read_block_start(); + ext_flash_read_block(&header1, EF_HEADER); + ext_flash_read_block(&header2, EF_HEADER); + dataStart.u8bit.byteHigh = 0; + ext_flash_read_block(&dataStart.u8bit.byteLow, EF_HEADER); + ext_flash_read_block(&dataStart.u8bit.byteMidLow, EF_HEADER); + ext_flash_read_block(&dataStart.u8bit.byteMidHigh, EF_HEADER); + dataEnd.u8bit.byteHigh = 0; + ext_flash_read_block(&dataEnd.u8bit.byteLow, EF_HEADER); + ext_flash_read_block(&dataEnd.u8bit.byteMidLow, EF_HEADER); + ext_flash_read_block(&dataEnd.u8bit.byteMidHigh, EF_HEADER); + ext_flash_read_block_stop(); + + if((header1 == 0xFA) && (header2 == 0xFA)) /* Dive ID is in use */ + { + if(((dataStart.u32bit >= sectorStart) && (dataStart.u32bit <= sectorStart+0xFFFF)) /* Sample start is within erased sector */ + || ((dataEnd.u32bit >= sectorStart) && (dataEnd.u32bit <= sectorStart+0xFFFF))) /* End of sample data is within erased sector */ + { + actualAddress = HEADERSTART + (0x800 * diveidx) + HEADER2OFFSET; + ext_flash_incf_address(EF_HEADER); /* skip header bytes */ + ext_flash_incf_address(EF_HEADER); + actualPointerHeader = actualAddress; + ef_write_block(emptySamples,9,EF_HEADER,1); /* clear start, stop and length data */ + actualPointerHeader = HeaderAddrBackup; + } +#if 0 + else /* no sample part within erased sector => stop search */ + { + break; + } +#endif + } +#if 0 + else /* ID not in use => stop search */ + { + break; + } +#endif + diveidx++; + } +} + + + /* uint8_t ext_flash_erase_firmware_if_not_empty(void) {