microbit: Minor improvmeents to reduce uneccessary erasures of FLASH pages

master
Joe Finney 7 years ago
parent 052b6d206f
commit 1484fce941

@ -124,7 +124,8 @@ uint32_t* MicroBitFileSystem::getFreePage()
return address;
}
// Nothing available at all.
// Nothing available at all. Use the default.
flash.erase_page(defaultScratchPage);
return defaultScratchPage;
}
@ -532,9 +533,6 @@ int MicroBitFileSystem::recycleBlock(uint16_t block, int type)
flash.erase_page(page);
flash.flash_write(page, scratch, PAGE_SIZE);
// Recycle the scratch page for later use.
flash.erase_page(scratch);
return MICROBIT_OK;
}
@ -908,7 +906,7 @@ int MicroBitFileSystem::close(int fd)
d.length = file->length;
// Do some optimising to reduce FLASH churn if this is the first write to a file. No need then to create a new dirent...
if (file->dirent->flags & MBFS_DIRECTORY_ENTRY_NEW)
if (file->dirent->flags == MBFS_DIRECTORY_ENTRY_NEW)
{
d.flags = MBFS_DIRECTORY_ENTRY_VALID;
flash.flash_write(file->dirent, &d, sizeof(DirectoryEntry));
@ -1140,7 +1138,7 @@ int MicroBitFileSystem::writeBuffer(FileDescriptor *file, uint8_t *buffer, int s
segmentLength = min(size - bytesCopied, MBFS_BLOCK_SIZE - offset);
if (segmentLength != 0)
flash.flash_write(writePointer, readPointer, segmentLength);
flash.flash_write(writePointer, readPointer, segmentLength, file->seek + bytesCopied < file->length ? getFreePage() : NULL);
offset += segmentLength;
bytesCopied += segmentLength;
@ -1290,25 +1288,29 @@ int MicroBitFileSystem::remove(char const * filename)
void MicroBitFileSystem::debugFAT()
{
int index = 0;
int col = 0;
SERIAL_DEBUG->printf("------ FAT ------\n");
for (int j = 0; j < fileSystemSize / 16; j++)
{
for (int i = 0; i < 16; i++)
{
if (fileSystemTable[index] == MBFS_UNUSED)
SERIAL_DEBUG->printf(" ---- ");
else if (fileSystemTable[index] == MBFS_EOF)
SERIAL_DEBUG->printf(" _EOF ");
else if (fileSystemTable[index] == MBFS_DELETED)
SERIAL_DEBUG->printf(" _XX_ ");
else
SERIAL_DEBUG->printf(" %.4X ", fileSystemTable[index]);
index++;
while(index < fileSystemSize)
{
if (fileSystemTable[index] == MBFS_UNUSED)
SERIAL_DEBUG->printf(" ---- ");
else if (fileSystemTable[index] == MBFS_EOF)
SERIAL_DEBUG->printf(" _EOF ");
else if (fileSystemTable[index] == MBFS_DELETED)
SERIAL_DEBUG->printf(" _XX_ ");
else
SERIAL_DEBUG->printf(" %.4X ", fileSystemTable[index]);
index++;
col++;
if (col == 16)
{
col = 0;
SERIAL_DEBUG->printf("\n");
}
SERIAL_DEBUG->printf("\n");
}
SERIAL_DEBUG->printf("\n\n");

@ -1,3 +1,4 @@
#include "MicroBitConfig.h"
#include "MicroBitFlash.h"
#include "mbed.h" // NVIC
@ -42,7 +43,6 @@ int MicroBitFlash::need_erase(uint8_t* source, uint8_t* flash_addr, int len)
*/
void MicroBitFlash::erase_page(uint32_t* pg_addr)
{
// Turn on flash erase enable and wait until the NVMC is ready:
NRF_NVMC->CONFIG = (NVMC_CONFIG_WEN_Een);
while (NRF_NVMC->READY == NVMC_READY_READY_Busy) { }
@ -174,12 +174,6 @@ int MicroBitFlash::flash_write_mem(uint8_t* address, uint8_t* from_buffer,
}
}
// If the scratch page was used, reset it to 0xFF.
if(erase)
{
this->erase_page((uint32_t*)scratch_addr);
}
return 1;
}

Loading…
Cancel
Save