comparison Discovery/Src/externLogbookFlash.c @ 427:b1091e183d52 ImprovmentNVM_2

Activated ringbuffer for settings: In previous versions the settings have always been writte to the ring start address causing additional ~200ms for sector erase. The settings are now continously written (~8ms). At shutdown the settings are written to ring start for compability reasons. In case of a reset the SW will scan the ringbuffer for the latest available block and restore it.
author ideenmodellierer
date Sun, 16 Feb 2020 22:04:52 +0100
parents 86fcac4cc43a
children 7f351c25608a
comparison
equal deleted inserted replaced
426:514e6269256f 427:b1091e183d52
124 static uint32_t actualPointerSample = 0; 124 static uint32_t actualPointerSample = 0;
125 static uint32_t LengthLeftSampleRead = 0; 125 static uint32_t LengthLeftSampleRead = 0;
126 static uint32_t actualPointerDevicedata = DDSTART; 126 static uint32_t actualPointerDevicedata = DDSTART;
127 static uint32_t actualPointerDevicedata_Read = DDSTART; 127 static uint32_t actualPointerDevicedata_Read = DDSTART;
128 static uint32_t actualPointerVPM = 0; 128 static uint32_t actualPointerVPM = 0;
129 static uint32_t actualPointerSettings = 0; 129 static uint32_t actualPointerSettings = SETTINGSSTART;
130 static uint32_t actualPointerFirmware = 0; 130 static uint32_t actualPointerFirmware = 0;
131 static uint32_t actualPointerFirmware2 = 0; 131 static uint32_t actualPointerFirmware2 = 0;
132 132
133 /* Private function prototypes -----------------------------------------------*/ 133 /* Private function prototypes -----------------------------------------------*/
134 static void chip_unselect(void); 134 static void chip_unselect(void);
520 void ext_flash_write_settings(void) 520 void ext_flash_write_settings(void)
521 { 521 {
522 return; 522 return;
523 } 523 }
524 #else 524 #else
525 void ext_flash_write_settings(void) 525 void ext_flash_write_settings(uint8_t resetRing)
526 { 526 {
527 uint8_t *pData; 527 uint8_t *pData;
528 const uint16_t length = sizeof(SSettings); 528 const uint16_t length = sizeof(SSettings);
529 uint8_t length_lo, length_hi; 529 uint8_t length_lo, length_hi;
530 uint8_t dataLength[2] = { 0 }; 530 uint8_t dataLength[2] = { 0 };
538 settingsGetPointer()->backup_localtime_rtc_tr = stateRealGetPointer()->lifeData.timeBinaryFormat; 538 settingsGetPointer()->backup_localtime_rtc_tr = stateRealGetPointer()->lifeData.timeBinaryFormat;
539 settingsGetPointer()->backup_localtime_rtc_dr = stateRealGetPointer()->lifeData.dateBinaryFormat; 539 settingsGetPointer()->backup_localtime_rtc_dr = stateRealGetPointer()->lifeData.dateBinaryFormat;
540 540
541 pData = (uint8_t *)settingsGetPointer(); 541 pData = (uint8_t *)settingsGetPointer();
542 542
543 actualPointerSettings = SETTINGSSTART; 543 /* Reset the Ring to the start address if requested (e.g. because we write the default block during shutdown) */
544 if((resetRing) || ((actualPointerSettings + length) >= SETTINGSSTOP))
545 {
546 actualPointerSettings = SETTINGSSTART;
547 }
544 548
545 length_lo = (uint8_t)(length & 0xFF); 549 length_lo = (uint8_t)(length & 0xFF);
546 length_hi = (uint8_t)(length >> 8); 550 length_hi = (uint8_t)(length >> 8);
547 dataLength[0] = length_lo; 551 dataLength[0] = length_lo;
548 dataLength[1] = length_hi; 552 dataLength[1] = length_hi;
575 579
576 ext_flash_read_block_start(); 580 ext_flash_read_block_start();
577 ext_flash_read_block(&length_lo, EF_SETTINGS); 581 ext_flash_read_block(&length_lo, EF_SETTINGS);
578 ext_flash_read_block(&length_hi, EF_SETTINGS); 582 ext_flash_read_block(&length_hi, EF_SETTINGS);
579 583
580 lengthOnEEPROM = length_hi * 256; 584 while ((length_lo != 0xFF) && (length_hi != 0xFF)) /* get the latest stored setting block */
581 lengthOnEEPROM += length_lo; 585 {
582 if(lengthOnEEPROM <= lengthStandardNow) 586 lengthOnEEPROM = length_hi * 256;
583 { 587 lengthOnEEPROM += length_lo;
584 ext_flash_read_block_multi(&header, 4, EF_SETTINGS); 588 if(lengthOnEEPROM <= lengthStandardNow)
585 if((header <= pSettings->header) && (header >= pSettings->updateSettingsAllowedFromHeader)) 589 {
586 { 590 ext_flash_read_block_multi(&header, 4, EF_SETTINGS);
587 returnValue = HAL_OK; 591 if((header <= pSettings->header) && (header >= pSettings->updateSettingsAllowedFromHeader))
588 pSettings->header = header; 592 {
589 pData = (uint8_t *)pSettings + 4; /* header */ 593 returnValue = HAL_OK;
590 for(uint16_t i = 0; i < (lengthOnEEPROM-4); i++) 594 pSettings->header = header;
591 ext_flash_read_block(&pData[i], EF_SETTINGS); 595 pData = (uint8_t *)pSettings + 4; /* header */
592 } 596 for(uint16_t i = 0; i < (lengthOnEEPROM-4); i++)
593 else 597 ext_flash_read_block(&pData[i], EF_SETTINGS);
594 { 598 }
595 returnValue = HAL_ERROR; 599 else
596 } 600 {
601 returnValue = HAL_ERROR;
602 }
603 }
604 ext_flash_read_block(&length_lo, EF_SETTINGS);
605 ext_flash_read_block(&length_hi, EF_SETTINGS);
606 }
607 ext_flash_decf_address_ring(EF_SETTINGS); /* set pointer back to empty address */
608 ext_flash_decf_address_ring(EF_SETTINGS);
609 ext_flash_read_block_stop();
610
611 if(actualAddress > actualPointerSettings) /* the write pointer has not yet been set up probably */
612 {
613 actualPointerSettings = actualAddress;
597 } 614 }
598 ext_flash_read_block_stop(); 615 ext_flash_read_block_stop();
599 return returnValue; 616 return returnValue;
600 } 617 }
601 618