comparison Discovery/Src/externLogbookFlash.c @ 461:b3f684cea9c0

Merged in Ideenmodellierer/ostc4/minor_improvments (pull request #41) Minor improvments
author heinrichsweikamp <bitbucket@heinrichsweikamp.com>
date Mon, 30 Mar 2020 13:16:11 +0000
parents 2effe85f1a9b
children e4f6afd9c96b
comparison
equal deleted inserted replaced
441:9a9e4908ce2e 461:b3f684cea9c0
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);
790 ext_flash_erase64kB(); 791 ext_flash_erase64kB();
791 actualAddress = actualAdressBackup; 792 actualAddress = actualAdressBackup;
792 } 793 }
793 } 794 }
794 } 795 }
1351 releaseFrame(97,logCopyDataPtr); 1352 releaseFrame(97,logCopyDataPtr);
1352 settingsGetPointer()->totalDiveCounter = startCount; 1353 settingsGetPointer()->totalDiveCounter = startCount;
1353 } 1354 }
1354 */ 1355 */
1355 1356
1357 uint8_t ext_dive_log_consistent(void)
1358 {
1359 uint8_t ret = 0;
1360 uint8_t header1, header2;
1361 uint8_t id;
1362 convert_Type dataStart;
1363
1364 SSettings *settings = settingsGetPointer();
1365 id = settings->lastDiveLogId;
1366
1367 actualAddress = HEADERSTART + (0x800 * id);
1368 ext_flash_read_block_start();
1369 ext_flash_read_block(&header1, EF_HEADER);
1370 ext_flash_read_block(&header2, EF_HEADER);
1371 dataStart.u8bit.byteHigh = 0;
1372 ext_flash_read_block(&dataStart.u8bit.byteLow, EF_HEADER);
1373 ext_flash_read_block(&dataStart.u8bit.byteMidLow, EF_HEADER);
1374 ext_flash_read_block(&dataStart.u8bit.byteMidHigh, EF_HEADER);
1375 ext_flash_read_block_stop();
1376 if((header1 == 0xFA) && (header2 == 0xFA)) /* Header is indicating the start of a dive */
1377 {
1378 actualAddress = HEADERSTART + (0x800 * id) + HEADER2OFFSET;
1379 ext_flash_read_block_start();
1380 ext_flash_read_block(&header1, EF_HEADER);
1381 ext_flash_read_block(&header2, EF_HEADER);
1382 ext_flash_read_block_stop();
1383 if((header1 == 0xFA) && (header2 == 0xFA)) /* Secondary header was written at the end of a dive */
1384 {
1385 ret = 1; /* => lastDiveLogID points to a valid dive entry */
1386 }
1387 }
1388 return ret;
1389 }
1390
1356 // =============================================================================== 1391 // ===============================================================================
1357 // ext_flash_repair_dive_log 1392 // ext_flash_repair_dive_log
1358 /// @brief This function 1393 /// @brief This function
1359 /// does set 1394 /// does set
1360 /// logFlashNextSampleStartAddress 1395 /// logFlashNextSampleStartAddress
1361 /// and 1396 /// and
1362 /// lastDiveLogId 1397 /// lastDiveLogId
1363 /// 1398 ///
1399
1364 void ext_flash_repair_dive_log(void) 1400 void ext_flash_repair_dive_log(void)
1365 { 1401 {
1366 uint8_t header1, header2; 1402 uint8_t header1, header2;
1367 convert_Type dataStart; 1403 convert_Type dataStart;
1368 1404
1758 /* safety */ 1794 /* safety */
1759 if(actualAddress < ringStart) 1795 if(actualAddress < ringStart)
1760 actualAddress = ringStart; 1796 actualAddress = ringStart;
1761 1797
1762 if(do_not_erase == 0) 1798 if(do_not_erase == 0)
1763 ext_flash_erase_if_on_page_start(); 1799 {
1800 if((ext_flash_erase_if_on_page_start()) && (type == EF_SAMPLE)) /* invalidate header sample information if needed */
1801 {
1802 ext_flash_invalidate_sample_index(actualAddress);
1803 }
1804 }
1764 1805
1765 while( i<length) 1806 while( i<length)
1766 { 1807 {
1767 ef_hw_rough_delay_us(5); 1808 ef_hw_rough_delay_us(5);
1768 wait_chip_not_busy(); 1809 wait_chip_not_busy();
2238 actualAddress = actualAddressBackup; 2279 actualAddress = actualAddressBackup;
2239 *(pstrResult+i) = 0; 2280 *(pstrResult+i) = 0;
2240 return startedSectors; 2281 return startedSectors;
2241 } 2282 }
2242 2283
2284 /* In case of a sample ring overrun the headers of the dive which will no longer have sample data needs to be updated */
2285 void ext_flash_invalidate_sample_index(uint32_t sectorStart)
2286 {
2287 uint8_t emptySamples[] = {0,0,0, 0,0,0, 0,0,0}; /* entry of start, stop and length */
2288 uint8_t diveidx;
2289
2290 uint8_t header1, header2;
2291
2292 SSettings *settings = settingsGetPointer();
2293 diveidx = settings->lastDiveLogId + 1;
2294 convert_Type dataStart, dataEnd;
2295
2296 uint32_t HeaderAddrBackup = actualPointerHeader;
2297
2298 while(diveidx != settings->lastDiveLogId)
2299 {
2300 actualAddress = HEADERSTART + (0x800 * diveidx) + HEADER2OFFSET;
2301 ext_flash_read_block_start();
2302 ext_flash_read_block(&header1, EF_HEADER);
2303 ext_flash_read_block(&header2, EF_HEADER);
2304 dataStart.u8bit.byteHigh = 0;
2305 ext_flash_read_block(&dataStart.u8bit.byteLow, EF_HEADER);
2306 ext_flash_read_block(&dataStart.u8bit.byteMidLow, EF_HEADER);
2307 ext_flash_read_block(&dataStart.u8bit.byteMidHigh, EF_HEADER);
2308 dataEnd.u8bit.byteHigh = 0;
2309 ext_flash_read_block(&dataEnd.u8bit.byteLow, EF_HEADER);
2310 ext_flash_read_block(&dataEnd.u8bit.byteMidLow, EF_HEADER);
2311 ext_flash_read_block(&dataEnd.u8bit.byteMidHigh, EF_HEADER);
2312 ext_flash_read_block_stop();
2313
2314 if((header1 == 0xFA) && (header2 == 0xFA)) /* Dive ID is in use */
2315 {
2316 if(((dataStart.u32bit >= sectorStart) && (dataStart.u32bit <= sectorStart+0xFFFF)) /* Sample start is within erased sector */
2317 || ((dataEnd.u32bit >= sectorStart) && (dataEnd.u32bit <= sectorStart+0xFFFF))) /* End of sample data is within erased sector */
2318 {
2319 actualAddress = HEADERSTART + (0x800 * diveidx) + HEADER2OFFSET;
2320 ext_flash_incf_address(EF_HEADER); /* skip header bytes */
2321 ext_flash_incf_address(EF_HEADER);
2322 actualPointerHeader = actualAddress;
2323 ef_write_block(emptySamples,9,EF_HEADER,1); /* clear start, stop and length data */
2324 actualPointerHeader = HeaderAddrBackup;
2325 }
2326 }
2327 diveidx++;
2328 }
2329 }
2330
2331
2332
2243 /* 2333 /*
2244 uint8_t ext_flash_erase_firmware_if_not_empty(void) 2334 uint8_t ext_flash_erase_firmware_if_not_empty(void)
2245 { 2335 {
2246 const uint8_t TESTSIZE_FW = 4; 2336 const uint8_t TESTSIZE_FW = 4;
2247 2337