Mercurial > public > ostc4
changeset 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 | b67327177159 |
children | 2b31cf1ebbcc |
files | Discovery/Src/externLogbookFlash.c |
diffstat | 1 files changed, 32 insertions(+), 4 deletions(-) [+] |
line wrap: on
line diff
--- a/Discovery/Src/externLogbookFlash.c Mon Feb 10 19:29:12 2020 +0100 +++ b/Discovery/Src/externLogbookFlash.c Mon Feb 10 19:40:33 2020 +0100 @@ -116,6 +116,7 @@ /* Private variables ---------------------------------------------------------*/ static uint32_t actualAddress = 0; +static uint32_t preparedPageAddress = 0; static uint32_t entryPoint = 0; static uint32_t actualPointerHeader = 0; @@ -753,10 +754,28 @@ void ext_flash_write_sample(uint8_t *pSample, uint16_t length) { + uint32_t actualAdressBackup = 0; + ef_write_block(pSample,length, EF_SAMPLE, 0); SSettings *settings = settingsGetPointer(); settings->logFlashNextSampleStartAddress = actualPointerSample; + + if(0xFFFF - (actualAddress & 0x0000FFFF) < 255) /* are we close to a sector border? */ + { + if (((actualAddress & 0x0000FFFF) != 0) && (preparedPageAddress == 0)) /* only prepare if not already at start of sector */ + { + actualAdressBackup = actualAddress; + actualAddress = (actualAddress & 0xFFFF0000) + 0x00010000; /* Set to start of next 64k sector */ + if(actualAddress >= SAMPLESTOP) + { + actualAddress = SAMPLESTART; + } + preparedPageAddress = actualAddress; + ext_flash_erase64kB(); + actualAddress = actualAdressBackup; + } + } } static void ext_flash_overwrite_sample_without_erase(uint8_t *pSample, uint16_t length) @@ -1605,7 +1624,7 @@ ext_flash_erase4kB(); return 1; } - } + } else if(actualAddress < 0x00010000) { @@ -1615,16 +1634,25 @@ ext_flash_erase32kB(); return 1; } - } + } else { /* 64K Byte is 0x10000 */ if((actualAddress & 0xFFFF) == 0) { - ext_flash_erase64kB(); + if(preparedPageAddress == actualAddress) /* has page already been prepared before? (at the moment for samples only) */ + { + preparedPageAddress = 0; + + } + else + { + ext_flash_erase64kB(); + } return 1; } - } + } + return 0; }