Mercurial > public > ostc4
changeset 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 | c2e02b87774f |
children | 1c0b911c367f |
files | Discovery/Src/externLogbookFlash.c Discovery/Src/tInfoLog.c |
diffstat | 2 files changed, 119 insertions(+), 0 deletions(-) [+] |
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) {
--- a/Discovery/Src/tInfoLog.c Tue Mar 24 21:49:52 2020 +0100 +++ b/Discovery/Src/tInfoLog.c Tue Mar 24 21:59:11 2020 +0100 @@ -36,6 +36,8 @@ #include "tInfo.h" #include "tMenu.h" #include "unit.h" +#include "externLogbookFlash.h" +#include "configuration.h" /* Exported variables --------------------------------------------------------*/ @@ -64,6 +66,7 @@ void stepBackInfo(void); void stepForwardInfo(void); void showLogExit(void); +void resetDiveProfile(void); /* Exported functions --------------------------------------------------------*/ void tInfoLog_init(void) @@ -176,6 +179,9 @@ switch(sendAction) { case ACTION_BUTTON_ENTER: +#ifdef ENABLE_PROFILE_RESET + resetDiveProfile(); +#endif break; case ACTION_BUTTON_NEXT: showNextLogPage(); @@ -429,4 +435,21 @@ show_logbook_test(0, stepBack); } +#ifdef ENABLE_PROFILE_RESET +void resetDiveProfile() +{ + uint8_t stepBack; + SLogbookHeader logbookHeader; + convert_Type dataStart; + stepBack = (6 * (infolog.page - 1)) + infolog.line - 1; /* calculate current dive ID */ + logbook_getHeader(stepBack ,&logbookHeader); + dataStart.u8bit.byteHigh = 0; + dataStart.u8bit.byteLow = logbookHeader.pBeginProfileData[0]; + dataStart.u8bit.byteMidLow = logbookHeader.pBeginProfileData[1]; + dataStart.u8bit.byteMidHigh = logbookHeader.pBeginProfileData[2]; + + dataStart.u32bit &= 0xFFFF0000; /* set to sector start */ + ext_flash_invalidate_sample_index(dataStart.u32bit); +} +#endif