Mercurial > public > ostc4
comparison Discovery/Src/externLogbookFlash.c @ 466:538eb1c976e9 Improve_Logtansfer
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
author | ideenmodellierer |
---|---|
date | Tue, 14 Apr 2020 19:27:04 +0200 |
parents | e4f6afd9c96b |
children | b1eee27cd02b |
comparison
equal
deleted
inserted
replaced
465:2c2df051e554 | 466:538eb1c976e9 |
---|---|
785 if(actualAddress >= SAMPLESTOP) | 785 if(actualAddress >= SAMPLESTOP) |
786 { | 786 { |
787 actualAddress = SAMPLESTART; | 787 actualAddress = SAMPLESTART; |
788 } | 788 } |
789 preparedPageAddress = actualAddress; | 789 preparedPageAddress = actualAddress; |
790 ext_flash_invalidate_sample_index(preparedPageAddress); | |
791 ext_flash_erase64kB(); | 790 ext_flash_erase64kB(); |
792 actualAddress = actualAdressBackup; | 791 actualAddress = actualAdressBackup; |
793 } | 792 } |
794 } | 793 } |
795 } | 794 } |
1759 | 1758 |
1760 static void ef_write_block(uint8_t * sendByte, uint32_t length, uint8_t type, uint8_t do_not_erase) | 1759 static void ef_write_block(uint8_t * sendByte, uint32_t length, uint8_t type, uint8_t do_not_erase) |
1761 { | 1760 { |
1762 uint32_t remaining_page_size, remaining_length, remaining_space_to_ring_end; | 1761 uint32_t remaining_page_size, remaining_length, remaining_space_to_ring_end; |
1763 uint32_t i=0; | 1762 uint32_t i=0; |
1764 uint32_t actualAddrBackup = 0; | |
1765 | 1763 |
1766 if(!length) | 1764 if(!length) |
1767 return; | 1765 return; |
1768 | 1766 |
1769 uint32_t ringStart, ringStop; | 1767 uint32_t ringStart, ringStop; |
1814 if(actualAddress < ringStart) | 1812 if(actualAddress < ringStart) |
1815 actualAddress = ringStart; | 1813 actualAddress = ringStart; |
1816 | 1814 |
1817 if(do_not_erase == 0) | 1815 if(do_not_erase == 0) |
1818 { | 1816 { |
1819 actualAddrBackup = actualAddress; | 1817 ext_flash_erase_if_on_page_start(); |
1820 if((ext_flash_erase_if_on_page_start()) && (type == EF_SAMPLE)) /* invalidate header sample information if needed */ | |
1821 { | |
1822 ext_flash_invalidate_sample_index(actualAddress); | |
1823 actualAddress = actualAddrBackup; | |
1824 } | |
1825 } | 1818 } |
1826 | 1819 |
1827 while( i<length) | 1820 while( i<length) |
1828 { | 1821 { |
1829 ef_hw_rough_delay_us(5); | 1822 ef_hw_rough_delay_us(5); |
2200 /* byte with RELEASE */ | 2193 /* byte with RELEASE */ |
2201 write_spi(0xA5,RELEASE);/* write data */ | 2194 write_spi(0xA5,RELEASE);/* write data */ |
2202 actualAddress = actualAddressBackup; | 2195 actualAddress = actualAddressBackup; |
2203 closeSectorAddress = 0; | 2196 closeSectorAddress = 0; |
2204 } | 2197 } |
2198 } | |
2199 | |
2200 /* This function validates a potential jump of sample address by checking the last sector for empty memory cells */ | |
2201 uint8_t ext_flash_SampleOverrunValid(void) | |
2202 { | |
2203 uint8_t jumpvalid = 1; | |
2204 uint32_t curAddress, actualaddrbackup; | |
2205 uint8_t tmpBuffer; | |
2206 uint8_t emptyCellCnt = 0; | |
2207 | |
2208 actualaddrbackup = actualAddress; | |
2209 curAddress = SAMPLESTOP - 20; /* check the last 10 bytes of the last sample sector */ | |
2210 actualAddress = curAddress; | |
2211 ext_flash_read_block_start(); | |
2212 while(actualAddress < SAMPLESTOP) | |
2213 { | |
2214 tmpBuffer = read_spi(HOLDCS);/* read data */ | |
2215 if(tmpBuffer == 0xFF) | |
2216 { | |
2217 emptyCellCnt++; | |
2218 } | |
2219 actualAddress++; | |
2220 } | |
2221 ext_flash_read_block_stop(); | |
2222 | |
2223 if(emptyCellCnt == 20) | |
2224 { | |
2225 jumpvalid = 0; | |
2226 } | |
2227 actualAddress = actualaddrbackup; | |
2228 return jumpvalid; | |
2205 } | 2229 } |
2206 | 2230 |
2207 uint32_t ext_flash_AnalyseSampleBuffer(char *pstrResult) | 2231 uint32_t ext_flash_AnalyseSampleBuffer(char *pstrResult) |
2208 { | 2232 { |
2209 uint8_t sectorState[16]; /* samples are stored in 16 sector / 64k each */ | 2233 uint8_t sectorState[16]; /* samples are stored in 16 sector / 64k each */ |
2300 actualAddress = actualAddressBackup; | 2324 actualAddress = actualAddressBackup; |
2301 *(pstrResult+i) = 0; | 2325 *(pstrResult+i) = 0; |
2302 return startedSectors; | 2326 return startedSectors; |
2303 } | 2327 } |
2304 | 2328 |
2305 /* In case of a sample ring overrun the headers of the dive which will no longer have sample data needs to be updated */ | 2329 uint32_t ext_flash_read_profilelength_small_header(uint32_t smallHeaderAddr) |
2306 void ext_flash_invalidate_sample_index(uint32_t sectorStart) | 2330 { |
2307 { | 2331 uint32_t profileLength = 0; |
2308 uint8_t emptySamples[] = {0,0,0, 0,0,0, 0,0,0}; /* entry of start, stop and length */ | 2332 actualPointerSample = smallHeaderAddr; |
2309 uint8_t diveidx; | 2333 actualAddress = actualPointerSample; |
2310 uint8_t index; | 2334 ext_flash_read_block_start(); |
2311 | 2335 ext_flash_read_next_sample_part((uint8_t*)&profileLength, 3); |
2312 uint8_t header1, header2; | 2336 ext_flash_close_read_sample(); |
2313 | 2337 return profileLength; |
2314 SSettings *settings = settingsGetPointer(); | 2338 } |
2315 diveidx = settings->lastDiveLogId + 1; | |
2316 convert_Type dataStart, dataEnd; | |
2317 | |
2318 uint32_t HeaderAddrBackup = actualPointerHeader; | |
2319 | |
2320 while(diveidx != settings->lastDiveLogId) | |
2321 { | |
2322 actualAddress = HEADERSTART + (0x800 * diveidx) + HEADER2OFFSET; | |
2323 ext_flash_read_block_start(); | |
2324 ext_flash_read_block(&header1, EF_HEADER); | |
2325 ext_flash_read_block(&header2, EF_HEADER); | |
2326 dataStart.u8bit.byteHigh = 0; | |
2327 ext_flash_read_block(&dataStart.u8bit.byteLow, EF_HEADER); | |
2328 ext_flash_read_block(&dataStart.u8bit.byteMidLow, EF_HEADER); | |
2329 ext_flash_read_block(&dataStart.u8bit.byteMidHigh, EF_HEADER); | |
2330 dataEnd.u8bit.byteHigh = 0; | |
2331 ext_flash_read_block(&dataEnd.u8bit.byteLow, EF_HEADER); | |
2332 ext_flash_read_block(&dataEnd.u8bit.byteMidLow, EF_HEADER); | |
2333 ext_flash_read_block(&dataEnd.u8bit.byteMidHigh, EF_HEADER); | |
2334 ext_flash_read_block_stop(); | |
2335 | |
2336 if((header1 == 0xFA) && (header2 == 0xFA)) /* Dive ID is in use */ | |
2337 { | |
2338 if(((dataStart.u32bit >= sectorStart) && (dataStart.u32bit <= sectorStart+0xFFFF)) /* Sample start is within erased sector */ | |
2339 || ((dataEnd.u32bit >= sectorStart) && (dataEnd.u32bit <= sectorStart+0xFFFF))) /* End of sample data is within erased sector */ | |
2340 { | |
2341 actualAddress = HEADERSTART + (0x800 * diveidx) + HEADER2OFFSET; | |
2342 ext_flash_incf_address(EF_HEADER); /* skip header bytes */ | |
2343 ext_flash_incf_address(EF_HEADER); | |
2344 actualPointerHeader = actualAddress; | |
2345 | |
2346 ef_hw_rough_delay_us(5); | |
2347 wait_chip_not_busy(); | |
2348 write_spi(0x06,RELEASE); /* WREN */ | |
2349 write_spi(0x02,HOLDCS); /* write cmd */ | |
2350 write_address(HOLDCS); | |
2351 for(index=0; index<8; index++) | |
2352 { | |
2353 write_spi(emptySamples[index],HOLDCS);/* write data */ | |
2354 actualAddress++; | |
2355 } | |
2356 /* byte with RELEASE */ | |
2357 write_spi(emptySamples[index],RELEASE);/* write data */ | |
2358 actualPointerHeader = HeaderAddrBackup; | |
2359 } | |
2360 } | |
2361 diveidx++; | |
2362 } | |
2363 } | |
2364 | |
2365 | 2339 |
2366 | 2340 |
2367 /* | 2341 /* |
2368 uint8_t ext_flash_erase_firmware_if_not_empty(void) | 2342 uint8_t ext_flash_erase_firmware_if_not_empty(void) |
2369 { | 2343 { |