mirror of
				https://github.com/thelsing/knx.git
				synced 2025-10-26 10:26:25 +01:00 
			
		
		
		
	access and allocate memory for interface-objects trough the memory class
This commit is contained in:
		
							parent
							
								
									4ef513410a
								
							
						
					
					
						commit
						94b91278bd
					
				| @ -5,9 +5,8 @@ | ||||
| 
 | ||||
| using namespace std; | ||||
| 
 | ||||
| 
 | ||||
| AddressTableObject::AddressTableObject(Platform& platform) | ||||
|     : TableObject(platform) | ||||
| AddressTableObject::AddressTableObject(Memory& memory) | ||||
|     : TableObject(memory) | ||||
| { | ||||
| 
 | ||||
| } | ||||
|  | ||||
| @ -15,9 +15,9 @@ class AddressTableObject : public TableObject | ||||
|     /**
 | ||||
|      * 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); | ||||
|     uint8_t* save(uint8_t* buffer); | ||||
|     uint8_t* restore(uint8_t* buffer); | ||||
|  | ||||
| @ -1,8 +1,8 @@ | ||||
| #include "application_program_object.h" | ||||
| #include "bits.h" | ||||
| 
 | ||||
| ApplicationProgramObject::ApplicationProgramObject(Platform& platform) | ||||
|     : TableObject(platform) | ||||
| ApplicationProgramObject::ApplicationProgramObject(Memory& memory) | ||||
|     : TableObject(memory) | ||||
| { | ||||
| 
 | ||||
| } | ||||
|  | ||||
| @ -5,7 +5,7 @@ | ||||
| class ApplicationProgramObject : public TableObject | ||||
| { | ||||
|   public: | ||||
|     ApplicationProgramObject(Platform& platform); | ||||
|     ApplicationProgramObject(Memory& memory); | ||||
|     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); | ||||
|     uint8_t propertySize(PropertyID id); | ||||
|  | ||||
| @ -5,9 +5,8 @@ | ||||
| 
 | ||||
| using namespace std; | ||||
| 
 | ||||
| 
 | ||||
| AssociationTableObject::AssociationTableObject(Platform& platform) | ||||
|     : TableObject(platform) | ||||
| AssociationTableObject::AssociationTableObject(Memory& memory) | ||||
|     : TableObject(memory) | ||||
| { | ||||
| 
 | ||||
| } | ||||
|  | ||||
| @ -5,7 +5,7 @@ | ||||
| class AssociationTableObject : public TableObject | ||||
| { | ||||
|   public: | ||||
|     AssociationTableObject(Platform& platform); | ||||
|     AssociationTableObject(Memory& memory); | ||||
|     void readProperty(PropertyID id, uint32_t start, uint32_t& count, uint8_t* data); | ||||
| 
 | ||||
|     uint8_t* save(uint8_t* buffer); | ||||
|  | ||||
| @ -11,8 +11,8 @@ enum NmReadSerialNumberType | ||||
|     NM_Read_SerialNumber_By_ManufacturerSpecific = 0xFE, | ||||
| }; | ||||
| 
 | ||||
| BauSystemB::BauSystemB(Platform& platform): _memory(platform), _addrTable(platform), | ||||
|     _assocTable(platform), _groupObjTable(platform), _appProgram(platform), | ||||
| BauSystemB::BauSystemB(Platform& platform): _memory(platform), _addrTable(_memory), | ||||
|     _assocTable(_memory), _groupObjTable(_memory), _appProgram(_memory), | ||||
|     _platform(platform), _appLayer(_assocTable, *this), | ||||
|     _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, | ||||
|     uint16_t memoryAddress, uint8_t * data) | ||||
| { | ||||
|     memcpy(_platform.memoryReference() + memoryAddress, data, number); | ||||
|     _memory.memoryModified(); | ||||
|     _memory.writeMemory(memoryAddress, number, data); | ||||
| 
 | ||||
|     if (_deviceObj.verifyMode()) | ||||
|         memoryReadIndication(priority, hopType, asap, number, memoryAddress); | ||||
| @ -160,7 +159,7 @@ void BauSystemB::memoryReadIndication(Priority priority, HopCountType hopType, u | ||||
|     uint16_t 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) | ||||
| @ -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) | ||||
| { | ||||
|     _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) | ||||
| { | ||||
|     memcpy(_platform.memoryReference() + memoryAddress, data, number); | ||||
|     _memory.memoryModified(); | ||||
|     _memory.writeMemory(memoryAddress, number, data); | ||||
| 
 | ||||
|     if (_deviceObj.verifyMode()) | ||||
|         userMemoryReadIndication(priority, hopType, asap, number, memoryAddress); | ||||
|  | ||||
| @ -4,8 +4,8 @@ | ||||
| #include "group_object.h" | ||||
| #include "bits.h" | ||||
| 
 | ||||
| GroupObjectTableObject::GroupObjectTableObject(Platform& platform) | ||||
|     : TableObject(platform) | ||||
| GroupObjectTableObject::GroupObjectTableObject(Memory& memory) | ||||
|     : TableObject(memory) | ||||
| { | ||||
| } | ||||
| 
 | ||||
|  | ||||
| @ -8,7 +8,7 @@ class GroupObjectTableObject : public TableObject | ||||
|     friend class GroupObject; | ||||
| 
 | ||||
|   public: | ||||
|     GroupObjectTableObject(Platform& platform); | ||||
|     GroupObjectTableObject(Memory& memory); | ||||
|     virtual ~GroupObjectTableObject(); | ||||
|     void readProperty(PropertyID id, uint32_t start, uint32_t& count, uint8_t* data); | ||||
|     uint16_t entryCount(); | ||||
|  | ||||
| @ -1,4 +1,5 @@ | ||||
| #include "memory.h" | ||||
| #include <string.h> | ||||
| 
 | ||||
| Memory::Memory(Platform & platform): _platform(platform) | ||||
| { | ||||
| @ -54,3 +55,33 @@ void Memory::addSaveRestore(SaveRestore * obj) | ||||
|     _saveRestores[_saveCount] = obj; | ||||
|     _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(); | ||||
| } | ||||
|  | ||||
| @ -15,7 +15,14 @@ public: | ||||
|     void readMemory(); | ||||
|     void writeMemory(); | ||||
|     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; | ||||
|     bool _modified = false; | ||||
|     SaveRestore* _saveRestores[MAXSAVE] = {0}; | ||||
|  | ||||
| @ -3,7 +3,7 @@ | ||||
| #include "table_object.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() | ||||
| { | ||||
|     if (_data != 0) | ||||
|         _platform.freeMemory(_data); | ||||
|         _memory.freeMemory(_data); | ||||
| } | ||||
| 
 | ||||
| LoadState TableObject::loadState() | ||||
| @ -105,10 +105,10 @@ uint8_t* TableObject::restore(uint8_t* buffer) | ||||
|     buffer = popInt(_size, buffer); | ||||
| 
 | ||||
|     if (_data) | ||||
|         _platform.freeMemory(_data); | ||||
|         _memory.freeMemory(_data); | ||||
| 
 | ||||
|     if (_size > 0) | ||||
|         _data = _platform.allocMemory(_size); | ||||
|         _data = _memory.allocMemory(_size); | ||||
|     else | ||||
|         _data = 0; | ||||
| 
 | ||||
| @ -119,22 +119,22 @@ uint8_t* TableObject::restore(uint8_t* buffer) | ||||
| 
 | ||||
| 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) | ||||
| { | ||||
|     if (_data) | ||||
|     { | ||||
|         _platform.freeMemory(_data); | ||||
|         _memory.freeMemory(_data); | ||||
|         _data = 0; | ||||
|         _size = 0; | ||||
|     } | ||||
| 
 | ||||
|     if (size == 0) | ||||
|         return true; | ||||
|      | ||||
|     _data = _platform.allocMemory(size); | ||||
| 
 | ||||
|     _data = _memory.allocMemory(size); | ||||
|     if (!_data) | ||||
|         return false; | ||||
| 
 | ||||
|  | ||||
| @ -1,7 +1,7 @@ | ||||
| #pragma once | ||||
| 
 | ||||
| #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. | ||||
| @ -11,9 +11,9 @@ class TableObject: public InterfaceObject | ||||
| public: | ||||
|     /**
 | ||||
|      * 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 writeProperty(PropertyID id, uint8_t start, uint8_t* data, uint8_t count); | ||||
|     virtual uint8_t propertySize(PropertyID id); | ||||
| @ -67,7 +67,7 @@ protected: | ||||
|      */ | ||||
|     void loadState(LoadState newState); | ||||
|     LoadState _state = LS_UNLOADED; | ||||
|     Platform& _platform; | ||||
|     Memory& _memory; | ||||
|     uint8_t *_data = 0; | ||||
|     uint32_t _size = 0; | ||||
|     ErrorCode _errorCode = E_NO_FAULT; | ||||
|  | ||||
		Loading…
	
		Reference in New Issue
	
	Block a user