# HG changeset patch # User ideenmodellierer # Date 1581964989 -3600 # Node ID 7f351c25608adba92eeaef8c874f91bd63e68910 # Parent 0e53419510797e7f5f3776fd4387dee63dc521ff Marked possible code improvment for future activities: parameters stored in the settings were not trusted. LastDive ID and Sample index are usually calculated at startup. This calculation could be avoided, nevertheless the implementation works => only TODO Removed function without effect: Calling writeblock with legth 0 has no effect diff -r 0e5341951079 -r 7f351c25608a Discovery/Src/externLogbookFlash.c --- a/Discovery/Src/externLogbookFlash.c Mon Feb 17 19:04:10 2020 +0100 +++ b/Discovery/Src/externLogbookFlash.c Mon Feb 17 19:43:09 2020 +0100 @@ -660,7 +660,7 @@ void ext_flash_create_new_dive_log(uint8_t *pHeaderPreDive) { SSettings *settings; - uint8_t id, id_next; + uint8_t id; uint8_t header1, header2; settings = settingsGetPointer(); @@ -668,10 +668,12 @@ actualAddress = HEADERSTART + (0x800 * id); ext_flash_read_block_start(); - ext_flash_read_block(&header1, EF_SAMPLE); - ext_flash_read_block(&header2, EF_SAMPLE); + ext_flash_read_block(&header1, EF_SAMPLE); /* the sample ring is increased instead of header... not sure if that is planned intention */ + ext_flash_read_block(&header2, EF_SAMPLE); /* does not matter because actual address is reset in write_block call */ ext_flash_read_block_stop(); + /* TODO Cleanup_Ref_2: The code below should not be necessary in case of a proper shutdown and startup */ + /* the implementation fixes an issue which might happen at Cleanup_Ref_1 (in case of more then 254 dives) */ if((header1 == 0xFA) && (header2 == 0xFA)) { id += 1; /* 0-255, auto rollover */ @@ -691,11 +693,6 @@ id = 0; } - /* delete next header */ - id_next = id + 1; - actualPointerHeader = HEADERSTART + (0x800 * id_next); - ef_write_block(0,0, EF_HEADER, 0); - settings->lastDiveLogId = id; actualPointerHeader = HEADERSTART + (0x800 * id); @@ -1407,6 +1404,9 @@ uint8_t header1, header2; convert_Type dataStart, dataEnd; + /* TODO Cleanup_Ref_1: cleanup logFlashNextSampleStartAddress and lastDiveLogId */ + /* The implementation below would cause problems in case more then 254 dives would be done. */ + /* This is avoided by Cleanup_Ref2 */ for(id = 0; id < 255;id++) { actualAddress = HEADERSTART + (0x800 * id) + HEADER2OFFSET;