access and allocate memory for interface-objects trough the memory class

This commit is contained in:
Thomas Kunze 2019-10-29 21:15:12 +01:00
parent 4ef513410a
commit 94b91278bd
13 changed files with 70 additions and 36 deletions

View File

@ -5,9 +5,8 @@
using namespace std; using namespace std;
AddressTableObject::AddressTableObject(Memory& memory)
AddressTableObject::AddressTableObject(Platform& platform) : TableObject(memory)
: TableObject(platform)
{ {
} }

View File

@ -15,9 +15,9 @@ class AddressTableObject : public TableObject
/** /**
* The contructor. * The contructor.
* *
* @param platform This parameter is only passed to the custructor of TableObject an not used by this class. * @param memory This parameter is only passed to the custructor of TableObject an not used by this class.
*/ */
AddressTableObject(Platform& platform); AddressTableObject(Memory& memory);
void readProperty(PropertyID id, uint32_t start, uint32_t& count, uint8_t* data); void readProperty(PropertyID id, uint32_t start, uint32_t& count, uint8_t* data);
uint8_t* save(uint8_t* buffer); uint8_t* save(uint8_t* buffer);
uint8_t* restore(uint8_t* buffer); uint8_t* restore(uint8_t* buffer);

View File

@ -1,8 +1,8 @@
#include "application_program_object.h" #include "application_program_object.h"
#include "bits.h" #include "bits.h"
ApplicationProgramObject::ApplicationProgramObject(Platform& platform) ApplicationProgramObject::ApplicationProgramObject(Memory& memory)
: TableObject(platform) : TableObject(memory)
{ {
} }

View File

@ -5,7 +5,7 @@
class ApplicationProgramObject : public TableObject class ApplicationProgramObject : public TableObject
{ {
public: public:
ApplicationProgramObject(Platform& platform); ApplicationProgramObject(Memory& memory);
void readProperty(PropertyID id, uint32_t start, uint32_t& count, uint8_t* data); void readProperty(PropertyID id, uint32_t start, uint32_t& count, uint8_t* data);
void writeProperty(PropertyID id, uint8_t start, uint8_t* data, uint8_t count); void writeProperty(PropertyID id, uint8_t start, uint8_t* data, uint8_t count);
uint8_t propertySize(PropertyID id); uint8_t propertySize(PropertyID id);

View File

@ -5,9 +5,8 @@
using namespace std; using namespace std;
AssociationTableObject::AssociationTableObject(Memory& memory)
AssociationTableObject::AssociationTableObject(Platform& platform) : TableObject(memory)
: TableObject(platform)
{ {
} }

View File

@ -5,7 +5,7 @@
class AssociationTableObject : public TableObject class AssociationTableObject : public TableObject
{ {
public: public:
AssociationTableObject(Platform& platform); AssociationTableObject(Memory& memory);
void readProperty(PropertyID id, uint32_t start, uint32_t& count, uint8_t* data); void readProperty(PropertyID id, uint32_t start, uint32_t& count, uint8_t* data);
uint8_t* save(uint8_t* buffer); uint8_t* save(uint8_t* buffer);

View File

@ -11,8 +11,8 @@ enum NmReadSerialNumberType
NM_Read_SerialNumber_By_ManufacturerSpecific = 0xFE, NM_Read_SerialNumber_By_ManufacturerSpecific = 0xFE,
}; };
BauSystemB::BauSystemB(Platform& platform): _memory(platform), _addrTable(platform), BauSystemB::BauSystemB(Platform& platform): _memory(platform), _addrTable(_memory),
_assocTable(platform), _groupObjTable(platform), _appProgram(platform), _assocTable(_memory), _groupObjTable(_memory), _appProgram(_memory),
_platform(platform), _appLayer(_assocTable, *this), _platform(platform), _appLayer(_assocTable, *this),
_transLayer(_appLayer, _addrTable), _netLayer(_transLayer) _transLayer(_appLayer, _addrTable), _netLayer(_transLayer)
{ {
@ -149,8 +149,7 @@ void BauSystemB::deviceDescriptorReadIndication(Priority priority, HopCountType
void BauSystemB::memoryWriteIndication(Priority priority, HopCountType hopType, uint16_t asap, uint8_t number, void BauSystemB::memoryWriteIndication(Priority priority, HopCountType hopType, uint16_t asap, uint8_t number,
uint16_t memoryAddress, uint8_t * data) uint16_t memoryAddress, uint8_t * data)
{ {
memcpy(_platform.memoryReference() + memoryAddress, data, number); _memory.writeMemory(memoryAddress, number, data);
_memory.memoryModified();
if (_deviceObj.verifyMode()) if (_deviceObj.verifyMode())
memoryReadIndication(priority, hopType, asap, number, memoryAddress); memoryReadIndication(priority, hopType, asap, number, memoryAddress);
@ -160,7 +159,7 @@ void BauSystemB::memoryReadIndication(Priority priority, HopCountType hopType, u
uint16_t memoryAddress) uint16_t memoryAddress)
{ {
_appLayer.memoryReadResponse(AckRequested, priority, hopType, asap, number, memoryAddress, _appLayer.memoryReadResponse(AckRequested, priority, hopType, asap, number, memoryAddress,
_platform.memoryReference() + memoryAddress); _memory.toAbsolute(memoryAddress));
} }
void BauSystemB::restartRequestIndication(Priority priority, HopCountType hopType, uint16_t asap) void BauSystemB::restartRequestIndication(Priority priority, HopCountType hopType, uint16_t asap)
@ -178,13 +177,12 @@ void BauSystemB::authorizeIndication(Priority priority, HopCountType hopType, ui
void BauSystemB::userMemoryReadIndication(Priority priority, HopCountType hopType, uint16_t asap, uint8_t number, uint32_t memoryAddress) void BauSystemB::userMemoryReadIndication(Priority priority, HopCountType hopType, uint16_t asap, uint8_t number, uint32_t memoryAddress)
{ {
_appLayer.userMemoryReadResponse(AckRequested, priority, hopType, asap, number, memoryAddress, _appLayer.userMemoryReadResponse(AckRequested, priority, hopType, asap, number, memoryAddress,
_platform.memoryReference() + memoryAddress); _memory.toAbsolute(memoryAddress));
} }
void BauSystemB::userMemoryWriteIndication(Priority priority, HopCountType hopType, uint16_t asap, uint8_t number, uint32_t memoryAddress, uint8_t* data) void BauSystemB::userMemoryWriteIndication(Priority priority, HopCountType hopType, uint16_t asap, uint8_t number, uint32_t memoryAddress, uint8_t* data)
{ {
memcpy(_platform.memoryReference() + memoryAddress, data, number); _memory.writeMemory(memoryAddress, number, data);
_memory.memoryModified();
if (_deviceObj.verifyMode()) if (_deviceObj.verifyMode())
userMemoryReadIndication(priority, hopType, asap, number, memoryAddress); userMemoryReadIndication(priority, hopType, asap, number, memoryAddress);

View File

@ -4,8 +4,8 @@
#include "group_object.h" #include "group_object.h"
#include "bits.h" #include "bits.h"
GroupObjectTableObject::GroupObjectTableObject(Platform& platform) GroupObjectTableObject::GroupObjectTableObject(Memory& memory)
: TableObject(platform) : TableObject(memory)
{ {
} }

View File

@ -8,7 +8,7 @@ class GroupObjectTableObject : public TableObject
friend class GroupObject; friend class GroupObject;
public: public:
GroupObjectTableObject(Platform& platform); GroupObjectTableObject(Memory& memory);
virtual ~GroupObjectTableObject(); virtual ~GroupObjectTableObject();
void readProperty(PropertyID id, uint32_t start, uint32_t& count, uint8_t* data); void readProperty(PropertyID id, uint32_t start, uint32_t& count, uint8_t* data);
uint16_t entryCount(); uint16_t entryCount();

View File

@ -1,4 +1,5 @@
#include "memory.h" #include "memory.h"
#include <string.h>
Memory::Memory(Platform & platform): _platform(platform) Memory::Memory(Platform & platform): _platform(platform)
{ {
@ -54,3 +55,33 @@ void Memory::addSaveRestore(SaveRestore * obj)
_saveRestores[_saveCount] = obj; _saveRestores[_saveCount] = obj;
_saveCount += 1; _saveCount += 1;
} }
uint8_t* Memory::allocMemory(size_t size)
{
return _platform.allocMemory(size);
}
void Memory::freeMemory(uint8_t* ptr)
{
return _platform.freeMemory(ptr);
}
void Memory::writeMemory(uint32_t relativeAddress, size_t size, uint8_t* data)
{
memcpy(toAbsolute(relativeAddress), data, size);
memoryModified();
}
uint8_t* Memory::toAbsolute(uint32_t relativeAddress)
{
return _platform.memoryReference() + (ptrdiff_t)relativeAddress;
}
uint32_t Memory::toRelative(uint8_t* absoluteAddress)
{
return absoluteAddress - _platform.memoryReference();
}

View File

@ -15,7 +15,14 @@ public:
void readMemory(); void readMemory();
void writeMemory(); void writeMemory();
void addSaveRestore(SaveRestore* obj); void addSaveRestore(SaveRestore* obj);
private:
uint8_t* allocMemory(size_t size);
void freeMemory(uint8_t* ptr);
void writeMemory(uint32_t relativeAddress, size_t size, uint8_t* data);
uint8_t* toAbsolute(uint32_t relativeAddress);
uint32_t toRelative(uint8_t* absoluteAddress);
private:
Platform& _platform; Platform& _platform;
bool _modified = false; bool _modified = false;
SaveRestore* _saveRestores[MAXSAVE] = {0}; SaveRestore* _saveRestores[MAXSAVE] = {0};

View File

@ -3,7 +3,7 @@
#include "table_object.h" #include "table_object.h"
#include "bits.h" #include "bits.h"
TableObject::TableObject(Platform& platform): _platform(platform) TableObject::TableObject(Memory& memory): _memory(memory)
{ {
} }
@ -65,7 +65,7 @@ uint8_t TableObject::propertySize(PropertyID id)
TableObject::~TableObject() TableObject::~TableObject()
{ {
if (_data != 0) if (_data != 0)
_platform.freeMemory(_data); _memory.freeMemory(_data);
} }
LoadState TableObject::loadState() LoadState TableObject::loadState()
@ -105,10 +105,10 @@ uint8_t* TableObject::restore(uint8_t* buffer)
buffer = popInt(_size, buffer); buffer = popInt(_size, buffer);
if (_data) if (_data)
_platform.freeMemory(_data); _memory.freeMemory(_data);
if (_size > 0) if (_size > 0)
_data = _platform.allocMemory(_size); _data = _memory.allocMemory(_size);
else else
_data = 0; _data = 0;
@ -119,14 +119,14 @@ uint8_t* TableObject::restore(uint8_t* buffer)
uint32_t TableObject::tableReference() uint32_t TableObject::tableReference()
{ {
return (uint32_t)(_data - _platform.memoryReference()); return (uint32_t)_memory.toRelative(_data);
} }
bool TableObject::allocTable(uint32_t size, bool doFill, uint8_t fillByte) bool TableObject::allocTable(uint32_t size, bool doFill, uint8_t fillByte)
{ {
if (_data) if (_data)
{ {
_platform.freeMemory(_data); _memory.freeMemory(_data);
_data = 0; _data = 0;
_size = 0; _size = 0;
} }
@ -134,7 +134,7 @@ bool TableObject::allocTable(uint32_t size, bool doFill, uint8_t fillByte)
if (size == 0) if (size == 0)
return true; return true;
_data = _platform.allocMemory(size); _data = _memory.allocMemory(size);
if (!_data) if (!_data)
return false; return false;

View File

@ -1,7 +1,7 @@
#pragma once #pragma once
#include "interface_object.h" #include "interface_object.h"
#include "platform.h" #include "memory.h"
/** /**
* This class provides common functionality for interface objects that are configured by ETS with MemorWrite. * This class provides common functionality for interface objects that are configured by ETS with MemorWrite.
@ -11,9 +11,9 @@ class TableObject: public InterfaceObject
public: public:
/** /**
* The constuctor. * The constuctor.
* @param platform the Platform on which the software runs. The class uses the memory management features of Platform. * @param memory The instance of the memory management class to use.
*/ */
TableObject(Platform& platform); TableObject(Memory& memory);
virtual void readProperty(PropertyID id, uint32_t start, uint32_t& count, uint8_t* data); virtual void readProperty(PropertyID id, uint32_t start, uint32_t& count, uint8_t* data);
virtual void writeProperty(PropertyID id, uint8_t start, uint8_t* data, uint8_t count); virtual void writeProperty(PropertyID id, uint8_t start, uint8_t* data, uint8_t count);
virtual uint8_t propertySize(PropertyID id); virtual uint8_t propertySize(PropertyID id);
@ -67,7 +67,7 @@ protected:
*/ */
void loadState(LoadState newState); void loadState(LoadState newState);
LoadState _state = LS_UNLOADED; LoadState _state = LS_UNLOADED;
Platform& _platform; Memory& _memory;
uint8_t *_data = 0; uint8_t *_data = 0;
uint32_t _size = 0; uint32_t _size = 0;
ErrorCode _errorCode = E_NO_FAULT; ErrorCode _errorCode = E_NO_FAULT;