comparison 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
comparison
equal deleted inserted replaced
451:c2e02b87774f 452:b90ddf57f7f1
1351 releaseFrame(97,logCopyDataPtr); 1351 releaseFrame(97,logCopyDataPtr);
1352 settingsGetPointer()->totalDiveCounter = startCount; 1352 settingsGetPointer()->totalDiveCounter = startCount;
1353 } 1353 }
1354 */ 1354 */
1355 1355
1356 uint8_t ext_dive_log_consistent(void)
1357 {
1358 uint8_t ret = 0;
1359 uint8_t header1, header2;
1360 uint8_t id;
1361 convert_Type dataStart;
1362
1363 SSettings *settings = settingsGetPointer();
1364 id = settings->lastDiveLogId;
1365
1366 actualAddress = HEADERSTART + (0x800 * id);
1367 ext_flash_read_block_start();
1368 ext_flash_read_block(&header1, EF_HEADER);
1369 ext_flash_read_block(&header2, EF_HEADER);
1370 dataStart.u8bit.byteHigh = 0;
1371 ext_flash_read_block(&dataStart.u8bit.byteLow, EF_HEADER);
1372 ext_flash_read_block(&dataStart.u8bit.byteMidLow, EF_HEADER);
1373 ext_flash_read_block(&dataStart.u8bit.byteMidHigh, EF_HEADER);
1374 ext_flash_read_block_stop();
1375 if((header1 == 0xFA) && (header2 == 0xFA)) /* Header is indicating the start of a dive */
1376 {
1377 actualAddress = HEADERSTART + (0x800 * id) + HEADER2OFFSET;
1378 ext_flash_read_block_start();
1379 ext_flash_read_block(&header1, EF_HEADER);
1380 ext_flash_read_block(&header2, EF_HEADER);
1381 ext_flash_read_block_stop();
1382 if((header1 == 0xFA) && (header2 == 0xFA)) /* Secondary header was written at the end of a dive */
1383 {
1384 ret = 1; /* => lastDiveLogID points to a valid dive entry */
1385 }
1386 }
1387 return ret;
1388 }
1389
1356 // =============================================================================== 1390 // ===============================================================================
1357 // ext_flash_repair_dive_log 1391 // ext_flash_repair_dive_log
1358 /// @brief This function 1392 /// @brief This function
1359 /// does set 1393 /// does set
1360 /// logFlashNextSampleStartAddress 1394 /// logFlashNextSampleStartAddress
1361 /// and 1395 /// and
1362 /// lastDiveLogId 1396 /// lastDiveLogId
1363 /// 1397 ///
1398
1364 void ext_flash_repair_dive_log(void) 1399 void ext_flash_repair_dive_log(void)
1365 { 1400 {
1366 uint8_t header1, header2; 1401 uint8_t header1, header2;
1367 convert_Type dataStart; 1402 convert_Type dataStart;
1368 1403
2238 actualAddress = actualAddressBackup; 2273 actualAddress = actualAddressBackup;
2239 *(pstrResult+i) = 0; 2274 *(pstrResult+i) = 0;
2240 return startedSectors; 2275 return startedSectors;
2241 } 2276 }
2242 2277
2278 /* In case of a sample ring overrun the headers of the dive which will no longer have sample data needs to be updated */
2279 void ext_flash_invalidate_sample_index(uint32_t sectorStart)
2280 {
2281 uint8_t emptySamples[] = {0,0,0, 0,0,0, 0,0,0}; /* entry of start, stop and length */
2282 uint8_t diveidx;
2283
2284 uint8_t header1, header2;
2285
2286 SSettings *settings = settingsGetPointer();
2287 diveidx = settings->lastDiveLogId + 1;
2288 convert_Type dataStart, dataEnd;
2289
2290 uint32_t HeaderAddrBackup = actualPointerHeader;
2291
2292 while(diveidx != settings->lastDiveLogId)
2293 {
2294 actualAddress = HEADERSTART + (0x800 * diveidx) + HEADER2OFFSET;
2295 ext_flash_read_block_start();
2296 ext_flash_read_block(&header1, EF_HEADER);
2297 ext_flash_read_block(&header2, EF_HEADER);
2298 dataStart.u8bit.byteHigh = 0;
2299 ext_flash_read_block(&dataStart.u8bit.byteLow, EF_HEADER);
2300 ext_flash_read_block(&dataStart.u8bit.byteMidLow, EF_HEADER);
2301 ext_flash_read_block(&dataStart.u8bit.byteMidHigh, EF_HEADER);
2302 dataEnd.u8bit.byteHigh = 0;
2303 ext_flash_read_block(&dataEnd.u8bit.byteLow, EF_HEADER);
2304 ext_flash_read_block(&dataEnd.u8bit.byteMidLow, EF_HEADER);
2305 ext_flash_read_block(&dataEnd.u8bit.byteMidHigh, EF_HEADER);
2306 ext_flash_read_block_stop();
2307
2308 if((header1 == 0xFA) && (header2 == 0xFA)) /* Dive ID is in use */
2309 {
2310 if(((dataStart.u32bit >= sectorStart) && (dataStart.u32bit <= sectorStart+0xFFFF)) /* Sample start is within erased sector */
2311 || ((dataEnd.u32bit >= sectorStart) && (dataEnd.u32bit <= sectorStart+0xFFFF))) /* End of sample data is within erased sector */
2312 {
2313 actualAddress = HEADERSTART + (0x800 * diveidx) + HEADER2OFFSET;
2314 ext_flash_incf_address(EF_HEADER); /* skip header bytes */
2315 ext_flash_incf_address(EF_HEADER);
2316 actualPointerHeader = actualAddress;
2317 ef_write_block(emptySamples,9,EF_HEADER,1); /* clear start, stop and length data */
2318 actualPointerHeader = HeaderAddrBackup;
2319 }
2320 #if 0
2321 else /* no sample part within erased sector => stop search */
2322 {
2323 break;
2324 }
2325 #endif
2326 }
2327 #if 0
2328 else /* ID not in use => stop search */
2329 {
2330 break;
2331 }
2332 #endif
2333 diveidx++;
2334 }
2335 }
2336
2337
2338
2243 /* 2339 /*
2244 uint8_t ext_flash_erase_firmware_if_not_empty(void) 2340 uint8_t ext_flash_erase_firmware_if_not_empty(void)
2245 { 2341 {
2246 const uint8_t TESTSIZE_FW = 4; 2342 const uint8_t TESTSIZE_FW = 4;
2247 2343