# HG changeset patch # User ideenmodellierer # Date 1586885224 -7200 # Node ID 538eb1c976e9c1b9f248022a9879a83e835ce62e # Parent 2c2df051e55479b9b01c3e42189969db79c9896e Removed invalidate header function because it is no lonnger needed Added new function allowing to read the profile length from sample data Added function which validates the wrap around detection In older versions a corruption of the sample index could occure reseting the sample index to its start. For some code sections this looks like a wrap around of the sample ring. To avoid problems a function to check this by reading the last bytes of the sample ring (should be != 0xff if used) has been added diff -r 2c2df051e554 -r 538eb1c976e9 Discovery/Inc/externLogbookFlash.h --- a/Discovery/Inc/externLogbookFlash.h Tue Apr 14 19:22:56 2020 +0200 +++ b/Discovery/Inc/externLogbookFlash.h Tue Apr 14 19:27:04 2020 +0200 @@ -168,6 +168,9 @@ uint32_t ext_flash_AnalyseSampleBuffer(char *pstrResult); void ext_flash_CloseSector(void); -void ext_flash_invalidate_sample_index(uint32_t sectorStart); + +uint32_t ext_flash_read_profilelength_small_header(uint32_t smallHeaderAddr); +uint8_t ext_flash_SampleOverrunValid(void); + #endif /* EXTERN_LOGBOOK_FLASH_H */ diff -r 2c2df051e554 -r 538eb1c976e9 Discovery/Src/externLogbookFlash.c --- a/Discovery/Src/externLogbookFlash.c Tue Apr 14 19:22:56 2020 +0200 +++ b/Discovery/Src/externLogbookFlash.c Tue Apr 14 19:27:04 2020 +0200 @@ -787,7 +787,6 @@ actualAddress = SAMPLESTART; } preparedPageAddress = actualAddress; - ext_flash_invalidate_sample_index(preparedPageAddress); ext_flash_erase64kB(); actualAddress = actualAdressBackup; } @@ -1761,7 +1760,6 @@ { uint32_t remaining_page_size, remaining_length, remaining_space_to_ring_end; uint32_t i=0; - uint32_t actualAddrBackup = 0; if(!length) return; @@ -1816,12 +1814,7 @@ if(do_not_erase == 0) { - actualAddrBackup = actualAddress; - if((ext_flash_erase_if_on_page_start()) && (type == EF_SAMPLE)) /* invalidate header sample information if needed */ - { - ext_flash_invalidate_sample_index(actualAddress); - actualAddress = actualAddrBackup; - } + ext_flash_erase_if_on_page_start(); } while( ilastDiveLogId + 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_hw_rough_delay_us(5); - wait_chip_not_busy(); - write_spi(0x06,RELEASE); /* WREN */ - write_spi(0x02,HOLDCS); /* write cmd */ - write_address(HOLDCS); - for(index=0; index<8; index++) - { - write_spi(emptySamples[index],HOLDCS);/* write data */ - actualAddress++; - } - /* byte with RELEASE */ - write_spi(emptySamples[index],RELEASE);/* write data */ - actualPointerHeader = HeaderAddrBackup; - } - } - diveidx++; - } + uint32_t profileLength = 0; + actualPointerSample = smallHeaderAddr; + actualAddress = actualPointerSample; + ext_flash_read_block_start(); + ext_flash_read_next_sample_part((uint8_t*)&profileLength, 3); + ext_flash_close_read_sample(); + return profileLength; } - /* uint8_t ext_flash_erase_firmware_if_not_empty(void) {