mirror of
				https://github.com/thelsing/knx.git
				synced 2025-10-26 10:26:25 +01:00 
			
		
		
		
	worked on flash implementation
This commit is contained in:
		
							parent
							
								
									aff7a4d661
								
							
						
					
					
						commit
						266287e2d1
					
				| @ -135,7 +135,7 @@ void Platform::commitNonVolatileMemory() | ||||
| { | ||||
|     if(_bufferedEraseblockNumber > -1 && _bufferedEraseblockDirty) | ||||
|     { | ||||
|         writeBufferedEraseBlock(_bufferedEraseblockNumber); | ||||
|         writeBufferedEraseBlock(); | ||||
|          | ||||
|         // _bufferedEraseblockNumber = -1;  // does that make sense?
 | ||||
|     } | ||||
| @ -198,9 +198,11 @@ void Platform::writeBufferedEraseBlock() | ||||
|     if(_bufferedEraseblockNumber > -1 && _bufferedEraseblockDirty) | ||||
|     { | ||||
|         flashErase(_bufferedEraseblockNumber); | ||||
|         for(int i = 0; i< ; i++) | ||||
|         {   // ToDo
 | ||||
|             flashWritePage(); | ||||
|         for(int i = 0; i < flashEraseBlockSize(); i++) | ||||
|         {    | ||||
|             int32_t pageNumber = _bufferedEraseblockNumber * flashEraseBlockSize() + i; | ||||
|             uint8_t *data = _eraseblockBuffer + flashPageSize() * i; | ||||
|             flashWritePage(pageNumber, data); | ||||
|         } | ||||
|         _bufferedEraseblockDirty = false; | ||||
|     } | ||||
|  | ||||
| @ -57,7 +57,7 @@ class Platform | ||||
|     void NonVolatileMemoryType(NvMemoryType type); | ||||
| 
 | ||||
|   protected: | ||||
|         // Flash memory
 | ||||
|     // Flash memory
 | ||||
|      | ||||
|     // size of one EraseBlock in pages
 | ||||
|     virtual size_t flashEraseBlockSize(); | ||||
| @ -65,19 +65,21 @@ class Platform | ||||
|     virtual size_t flashPageSize(); | ||||
|     // start of user flash aligned to start of an erase block
 | ||||
|     virtual uint8_t* userFlashStart(); | ||||
|     virtual size_t userFlashSizeEraseBlocks(); // in eraseBlocks
 | ||||
|     virtual void flashErase(uint16_t eraseBlockNum); //relativ to userFlashStart
 | ||||
|     virtual void flashWritePage(uint16_t pageNumber, uint8_t* data); //write a single page to flash (pageNumber relative to userFashStart
 | ||||
|     // size of the user flash in EraseBlocks
 | ||||
|     virtual size_t userFlashSizeEraseBlocks(); | ||||
|     //relativ to userFlashStart
 | ||||
|     virtual void flashErase(uint16_t eraseBlockNum); | ||||
|     //write a single page to flash (pageNumber relative to userFashStart
 | ||||
|     virtual void flashWritePage(uint16_t pageNumber, uint8_t* data);  | ||||
|      | ||||
|     NvMemoryType _memoryType = Eeprom; | ||||
| 
 | ||||
|   private: | ||||
|     void loadEraseblockContaining(uint32_t relativeAddress); | ||||
|     uint32_t bufferedEraseBlockStart(); | ||||
|     uint32_t bufferedEraseBlockEnd(); | ||||
|     int32_t getEraseBlockNumberOf(uint32_t relativeAddress); | ||||
|     // writes _eraseblockBuffer to flash
 | ||||
|     void writeBufferedEraseBlock(); | ||||
|     virtual void writeBufferedEraseBlock(); | ||||
|     // copies a EraseBlock into the _eraseblockBuffer
 | ||||
|     void bufferEraseBlock(uint32_t eraseBlockNumber); | ||||
| 
 | ||||
|  | ||||
| @ -92,9 +92,7 @@ size_t RP2040ArduinoPlatform::flashPageSize() | ||||
| 
 | ||||
| uint8_t* RP2040ArduinoPlatform::userFlashStart() | ||||
| { | ||||
|     // TODO
 | ||||
|     // XIP_BASE + KNX_FLASH_OFFSET
 | ||||
|     return nullptr; | ||||
|     return (uint8_t*)XIP_BASE + KNX_FLASH_OFFSET; | ||||
| } | ||||
| 
 | ||||
| size_t RP2040ArduinoPlatform::userFlashSizeEraseBlocks() | ||||
| @ -110,8 +108,7 @@ void RP2040ArduinoPlatform::flashErase(uint16_t eraseBlockNum) | ||||
|     noInterrupts(); | ||||
|     rp2040.idleOtherCore(); | ||||
| 
 | ||||
|     // TODO: calculate position in flash
 | ||||
|     flash_range_erase (0x100, flashPageSize() * flashEraseBlockSize()); | ||||
|     flash_range_erase (KNX_FLASH_OFFSET + eraseBlockNum * flashPageSize() * flashEraseBlockSize(), flashPageSize() * flashEraseBlockSize()); | ||||
| 
 | ||||
|     rp2040.resumeOtherCore(); | ||||
|     interrupts(); | ||||
| @ -122,12 +119,28 @@ void RP2040ArduinoPlatform::flashWritePage(uint16_t pageNumber, uint8_t* data) | ||||
|     noInterrupts(); | ||||
|     rp2040.idleOtherCore(); | ||||
| 
 | ||||
|     // TODO: calculate position in flash
 | ||||
|     flash_range_program(0x100, data, flashPageSize()); | ||||
|     flash_range_program(KNX_FLASH_OFFSET + pageNumber * flashPageSize(), data, flashPageSize()); | ||||
| 
 | ||||
|     rp2040.resumeOtherCore(); | ||||
|     interrupts(); | ||||
| } | ||||
| 
 | ||||
| void RP2040ArduinoPlatform::writeBufferedEraseBlock() | ||||
| { | ||||
|     if(_bufferedEraseblockNumber > -1 && _bufferedEraseblockDirty) | ||||
|     { | ||||
|         noInterrupts(); | ||||
|         rp2040.idleOtherCore(); | ||||
| 
 | ||||
|         flash_range_erase (KNX_FLASH_OFFSET + _bufferedEraseblockNumber * flashPageSize() * flashEraseBlockSize(), flashPageSize() * flashEraseBlockSize()); | ||||
|         flash_range_program(KNX_FLASH_OFFSET + _bufferedEraseblockNumber * flashPageSize() * flashEraseBlockSize(), _eraseblockBuffer, flashPageSize() * flashEraseBlockSize()); | ||||
| 
 | ||||
|         rp2040.resumeOtherCore(); | ||||
|         interrupts(); | ||||
| 
 | ||||
|         _bufferedEraseblockDirty = false; | ||||
|     } | ||||
| } | ||||
| #endif | ||||
| 
 | ||||
| 
 | ||||
|  | ||||
| @ -26,13 +26,21 @@ public: | ||||
|     void commitToEeprom(); | ||||
| 
 | ||||
| 
 | ||||
| 
 | ||||
|     size_t flashEraseBlockSize(); // in bytes
 | ||||
|     size_t flashPageSize();       // in bytes
 | ||||
|     uint8_t* userFlashStart();   // start of user flash aligned to start of an erase block
 | ||||
|     size_t userFlashSizeEraseBlocks(); // in eraseBlocks
 | ||||
|     void flashErase(uint16_t eraseBlockNum); //relativ to userFlashStart
 | ||||
|     void flashWritePage(uint16_t pageNumber, uint8_t* data); //write a single page to flash (pageNumber relative to userFashStart
 | ||||
|     // size of one EraseBlock in pages
 | ||||
|     virtual size_t flashEraseBlockSize(); | ||||
|     // size of one flash page in bytes
 | ||||
|     virtual size_t flashPageSize(); | ||||
|     // start of user flash aligned to start of an erase block
 | ||||
|     virtual uint8_t* userFlashStart(); | ||||
|     // size of the user flash in EraseBlocks
 | ||||
|     virtual size_t userFlashSizeEraseBlocks(); | ||||
|     //relativ to userFlashStart
 | ||||
|     virtual void flashErase(uint16_t eraseBlockNum); | ||||
|     //write a single page to flash (pageNumber relative to userFashStart
 | ||||
|     virtual void flashWritePage(uint16_t pageNumber, uint8_t* data);  | ||||
|      | ||||
|     // writes _eraseblockBuffer to flash - overrides Plattform::writeBufferedEraseBlock()
 | ||||
|     void writeBufferedEraseBlock(); | ||||
| }; | ||||
| 
 | ||||
| #endif | ||||
|  | ||||
		Loading…
	
		Reference in New Issue
	
	Block a user