small refactoring of memory class

This commit is contained in:
Thomas Kunze 2019-11-04 21:51:52 +01:00
parent 2659824aa2
commit 07133807d8
2 changed files with 12 additions and 18 deletions

View File

@ -8,8 +8,6 @@ Memory::Memory(Platform& platform, DeviceObject& deviceObject)
{ {
} }
// TODO implement flash layout: manufacturerID, HarwareType, Version, addr[0], size[0], addr[1], size[1], ...
// reconstruct free flash list and used list on read
void Memory::readMemory() void Memory::readMemory()
{ {
if (_data != nullptr) if (_data != nullptr)
@ -20,10 +18,7 @@ void Memory::readMemory()
uint16_t metadataBlockSize = alignToPageSize(_metadataSize); uint16_t metadataBlockSize = alignToPageSize(_metadataSize);
MemoryBlock* allFreeFlash = new MemoryBlock(); _freeList = new MemoryBlock(_data + metadataBlockSize, flashSize - metadataBlockSize);
allFreeFlash->address = _data + metadataBlockSize;
allFreeFlash->size = flashSize - metadataBlockSize;
allFreeFlash->next = nullptr;
uint16_t manufacturerId = 0; uint16_t manufacturerId = 0;
uint8_t* buffer = popWord(manufacturerId, _data); uint8_t* buffer = popWord(manufacturerId, _data);
@ -131,9 +126,7 @@ uint8_t* Memory::allocMemory(size_t size)
else else
{ {
// split block // split block
MemoryBlock* newBlock = new MemoryBlock(); MemoryBlock* newBlock = new MemoryBlock(blockToUse->address, size);
newBlock->address = blockToUse->address;
newBlock->size = size;
addToUsedList(newBlock); addToUsedList(newBlock);
blockToUse->address += size; blockToUse->address += size;
@ -356,9 +349,6 @@ void Memory::addNewUsedBlock(uint8_t* address, size_t size)
} }
} }
MemoryBlock* newUsedBlock = new MemoryBlock(); MemoryBlock* newUsedBlock = new MemoryBlock(address, size);
newUsedBlock->address = address;
newUsedBlock->size = size;
newUsedBlock->next = nullptr;
addToUsedList(newUsedBlock); addToUsedList(newUsedBlock);
} }

View File

@ -7,12 +7,16 @@
#define MAXSAVE 10 #define MAXSAVE 10
typedef struct _memoryBlock class MemoryBlock
{ {
uint8_t* address; public:
size_t size; MemoryBlock(){};
struct _memoryBlock* next; MemoryBlock(uint8_t* address, size_t size)
} MemoryBlock; : address(address), size(size) {}
uint8_t* address = nullptr;
size_t size = 0;
MemoryBlock* next = nullptr;
};
class Memory class Memory
{ {