Dependencies: DM_FATFileSystem EthernetInterface HTTPClient mbed-rtos mbed-src
Fork of DMSupport by
Diff: Memory/InternalEEPROM.cpp
- Revision:
- 34:fc366bab393f
- Parent:
- 29:b1ec19000e15
--- a/Memory/InternalEEPROM.cpp Thu Feb 19 14:41:14 2015 +0100 +++ b/Memory/InternalEEPROM.cpp Mon Mar 09 11:15:56 2015 +0100 @@ -152,6 +152,14 @@ uint32_t pageAddr = addr/EEPROM_PAGE_SIZE; uint32_t readOffset = (addr & (EEPROM_PAGE_SIZE - 1)); uint32_t readSize = EEPROM_PAGE_SIZE - readOffset; + + // Prevent reading past the end of the memory + if (addr >= EEPROM_MEMORY_SIZE) { + return 0; + } + if ((size + addr) > EEPROM_MEMORY_SIZE) { + size = EEPROM_MEMORY_SIZE - addr; + } powerUp(); @@ -181,6 +189,14 @@ uint32_t writeOffset = (addr & (EEPROM_PAGE_SIZE - 1)); uint32_t writeSize = EEPROM_PAGE_SIZE - writeOffset; + // Prevent writing past the end of the memory + if (addr >= EEPROM_MEMORY_SIZE) { + return 0; + } + if ((size + addr) > EEPROM_MEMORY_SIZE) { + size = EEPROM_MEMORY_SIZE - addr; + } + powerUp(); // Read and store data in buffer @@ -202,17 +218,3 @@ } return numWritten; } - -//void InternalEEPROM::erasePage(uint32_t pageAddr) -//{ -// powerUp(); -// -// clearInterrupt(EEPROM_INT_ENDOFRW); -// setCmd(EEPROM_CMD_32BITS_WRITE); -// setAddr(pageAddr, 0); -// for (int i = 0; i < EEPROM_PAGE_SIZE; i+=4) { -// LPC_EEPROM->WDATA = 0; -// waitForInterrupt(EEPROM_INT_ENDOFRW); -// } -// eraseOrProgramPage(pageAddr); -//}