comparison Discovery/Src/externLogbookFlash.c @ 429:7f351c25608a ImprovmentNVM_2

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
author ideenmodellierer
date Mon, 17 Feb 2020 19:43:09 +0100
parents b1091e183d52
children 9a9e4908ce2e b90ddf57f7f1
comparison
equal deleted inserted replaced
428:0e5341951079 429:7f351c25608a
658 * the following func writes to header to the ext_flash 658 * the following func writes to header to the ext_flash
659 */ 659 */
660 void ext_flash_create_new_dive_log(uint8_t *pHeaderPreDive) 660 void ext_flash_create_new_dive_log(uint8_t *pHeaderPreDive)
661 { 661 {
662 SSettings *settings; 662 SSettings *settings;
663 uint8_t id, id_next; 663 uint8_t id;
664 uint8_t header1, header2; 664 uint8_t header1, header2;
665 665
666 settings = settingsGetPointer(); 666 settings = settingsGetPointer();
667 id = settings->lastDiveLogId; 667 id = settings->lastDiveLogId;
668 668
669 actualAddress = HEADERSTART + (0x800 * id); 669 actualAddress = HEADERSTART + (0x800 * id);
670 ext_flash_read_block_start(); 670 ext_flash_read_block_start();
671 ext_flash_read_block(&header1, EF_SAMPLE); 671 ext_flash_read_block(&header1, EF_SAMPLE); /* the sample ring is increased instead of header... not sure if that is planned intention */
672 ext_flash_read_block(&header2, EF_SAMPLE); 672 ext_flash_read_block(&header2, EF_SAMPLE); /* does not matter because actual address is reset in write_block call */
673 ext_flash_read_block_stop(); 673 ext_flash_read_block_stop();
674 674
675 /* TODO Cleanup_Ref_2: The code below should not be necessary in case of a proper shutdown and startup */
676 /* the implementation fixes an issue which might happen at Cleanup_Ref_1 (in case of more then 254 dives) */
675 if((header1 == 0xFA) && (header2 == 0xFA)) 677 if((header1 == 0xFA) && (header2 == 0xFA))
676 { 678 {
677 id += 1; /* 0-255, auto rollover */ 679 id += 1; /* 0-255, auto rollover */
678 if(id & 1) 680 if(id & 1)
679 { 681 {
688 } 690 }
689 else 691 else
690 { 692 {
691 id = 0; 693 id = 0;
692 } 694 }
693
694 /* delete next header */
695 id_next = id + 1;
696 actualPointerHeader = HEADERSTART + (0x800 * id_next);
697 ef_write_block(0,0, EF_HEADER, 0);
698 695
699 settings->lastDiveLogId = id; 696 settings->lastDiveLogId = id;
700 actualPointerHeader = HEADERSTART + (0x800 * id); 697 actualPointerHeader = HEADERSTART + (0x800 * id);
701 698
702 if(pHeaderPreDive != 0) 699 if(pHeaderPreDive != 0)
1405 { 1402 {
1406 uint8_t id; 1403 uint8_t id;
1407 uint8_t header1, header2; 1404 uint8_t header1, header2;
1408 convert_Type dataStart, dataEnd; 1405 convert_Type dataStart, dataEnd;
1409 1406
1407 /* TODO Cleanup_Ref_1: cleanup logFlashNextSampleStartAddress and lastDiveLogId */
1408 /* The implementation below would cause problems in case more then 254 dives would be done. */
1409 /* This is avoided by Cleanup_Ref2 */
1410 for(id = 0; id < 255;id++) 1410 for(id = 0; id < 255;id++)
1411 { 1411 {
1412 actualAddress = HEADERSTART + (0x800 * id) + HEADER2OFFSET; 1412 actualAddress = HEADERSTART + (0x800 * id) + HEADER2OFFSET;
1413 ext_flash_read_block_start(); 1413 ext_flash_read_block_start();
1414 ext_flash_read_block(&header1, EF_HEADER); 1414 ext_flash_read_block(&header1, EF_HEADER);