comparison Discovery/Src/externLogbookFlash.c @ 423:a560afdaadbf ImprovmentNVM_2

ext_Flash_write_sample erase sector optimization: The previous function erased a sector while writing sample data causing a delay of up to 200ms. The new implementation checks at the end of a write sample call if we are close to a sector end. In case we are a erase sector command will be send to the flash for the next sector. At the time of the next sample write (2 seconds later) the next sector is already erased and no busy wait of 200ms is needed => max write time for samples is not less than 5ms.
author ideenmodellierer
date Mon, 10 Feb 2020 19:40:33 +0100
parents 3f7d80f37bfc
children 86fcac4cc43a
comparison
equal deleted inserted replaced
422:b67327177159 423:a560afdaadbf
114 114
115 /* Exported variables --------------------------------------------------------*/ 115 /* Exported variables --------------------------------------------------------*/
116 116
117 /* Private variables ---------------------------------------------------------*/ 117 /* Private variables ---------------------------------------------------------*/
118 static uint32_t actualAddress = 0; 118 static uint32_t actualAddress = 0;
119 static uint32_t preparedPageAddress = 0;
119 static uint32_t entryPoint = 0; 120 static uint32_t entryPoint = 0;
120 121
121 static uint32_t actualPointerHeader = 0; 122 static uint32_t actualPointerHeader = 0;
122 static uint32_t actualPointerSample = 0; 123 static uint32_t actualPointerSample = 0;
123 static uint32_t LengthLeftSampleRead = 0; 124 static uint32_t LengthLeftSampleRead = 0;
751 } 752 }
752 753
753 754
754 void ext_flash_write_sample(uint8_t *pSample, uint16_t length) 755 void ext_flash_write_sample(uint8_t *pSample, uint16_t length)
755 { 756 {
757 uint32_t actualAdressBackup = 0;
758
756 ef_write_block(pSample,length, EF_SAMPLE, 0); 759 ef_write_block(pSample,length, EF_SAMPLE, 0);
757 760
758 SSettings *settings = settingsGetPointer(); 761 SSettings *settings = settingsGetPointer();
759 settings->logFlashNextSampleStartAddress = actualPointerSample; 762 settings->logFlashNextSampleStartAddress = actualPointerSample;
763
764 if(0xFFFF - (actualAddress & 0x0000FFFF) < 255) /* are we close to a sector border? */
765 {
766 if (((actualAddress & 0x0000FFFF) != 0) && (preparedPageAddress == 0)) /* only prepare if not already at start of sector */
767 {
768 actualAdressBackup = actualAddress;
769 actualAddress = (actualAddress & 0xFFFF0000) + 0x00010000; /* Set to start of next 64k sector */
770 if(actualAddress >= SAMPLESTOP)
771 {
772 actualAddress = SAMPLESTART;
773 }
774 preparedPageAddress = actualAddress;
775 ext_flash_erase64kB();
776 actualAddress = actualAdressBackup;
777 }
778 }
760 } 779 }
761 780
762 static void ext_flash_overwrite_sample_without_erase(uint8_t *pSample, uint16_t length) 781 static void ext_flash_overwrite_sample_without_erase(uint8_t *pSample, uint16_t length)
763 { 782 {
764 ef_write_block(pSample,length, EF_SAMPLE, 1); 783 ef_write_block(pSample,length, EF_SAMPLE, 1);
1603 if((actualAddress & 0xFFF) == 0) 1622 if((actualAddress & 0xFFF) == 0)
1604 { 1623 {
1605 ext_flash_erase4kB(); 1624 ext_flash_erase4kB();
1606 return 1; 1625 return 1;
1607 } 1626 }
1608 } 1627 }
1609 else 1628 else
1610 if(actualAddress < 0x00010000) 1629 if(actualAddress < 0x00010000)
1611 { 1630 {
1612 /* 32K Byte is only one page */ 1631 /* 32K Byte is only one page */
1613 if(actualAddress == 0x00010000) 1632 if(actualAddress == 0x00010000)
1614 { 1633 {
1615 ext_flash_erase32kB(); 1634 ext_flash_erase32kB();
1616 return 1; 1635 return 1;
1617 } 1636 }
1618 } 1637 }
1619 else 1638 else
1620 { 1639 {
1621 /* 64K Byte is 0x10000 */ 1640 /* 64K Byte is 0x10000 */
1622 if((actualAddress & 0xFFFF) == 0) 1641 if((actualAddress & 0xFFFF) == 0)
1623 { 1642 {
1624 ext_flash_erase64kB(); 1643 if(preparedPageAddress == actualAddress) /* has page already been prepared before? (at the moment for samples only) */
1644 {
1645 preparedPageAddress = 0;
1646
1647 }
1648 else
1649 {
1650 ext_flash_erase64kB();
1651 }
1625 return 1; 1652 return 1;
1626 } 1653 }
1627 } 1654 }
1655
1628 return 0; 1656 return 0;
1629 } 1657 }
1630 1658
1631 1659
1632 static void ext_flash_read_block(uint8_t *getByte, uint8_t type) 1660 static void ext_flash_read_block(uint8_t *getByte, uint8_t type)