Skip to content

Commit

Permalink
methods description added
Browse files Browse the repository at this point in the history
  • Loading branch information
shuvangkardas committed Mar 27, 2020
1 parent a91678b commit 9501153
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 8 deletions.
4 changes: 2 additions & 2 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ One more thing we need to clarify that 100k write/erase cycle for each cell, not
For solving the eeprom wear out problem, I have developed an Arduino library [RingEEPROM]().

## Solution
The idea is simple. I cannot write/erase safely each cell more than 100k times. Suppose I want to store a variable in EEPROM. What I will is, at First I will write the variable in first location, second time I will write the variable in the second location.Third time I will write the variable in the third location, Fourth time I will write the variable in the first location. I am repeating the pattern after 3 locatons. Thus I am getting 3 times endurance for a single variable.
The idea is simple. As I cannot write/erase safely each cell more than 100k times. what if multiple cells is used for the same variable. To clarify more, Suppose I want to store a variable in EEPROM. What I will is, at First I will write the variable in first location, second time I will write the variable in the second location.Third time I will write the variable in the third location, Fourth time I will write the variable in the first location. I am repeating the pattern after 3 locatons. Thus I am getting 3 times endurance for a single variable.

I will store my value in different cells in each write cycle. So let's consider our buffer size i 8. I am planning to write a byte in EEPROM. As I am using 8 cells for a single byte. Now I get 8*100k = 800k write cycles. That's huge. The bigger buffer size is, the more I get write cycles.
I will store my value in different cells in each write cycle. So let's consider our buffer size i 8. I am planning to write a byte in EEPROM. As I am using 8 cells for a single byte. Now I get 8*100k = 800k write cycles. That's huge. The bigger the buffer size is, the more write cycles I get.

In this library, I will not store a single variable, I have developed the library such a way so that I can handle any size of buffer.

Expand Down
41 changes: 35 additions & 6 deletions src/eep.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*
/************************************************************************
* The idea of the library is simple. I am Saving a particular parameters
* into multiple location of the eeprom. Suppose I want to store a variable
* in eeprom. Everytime I want to store the variable, I change my location.
Expand All @@ -8,7 +8,16 @@
*So for saving value in eeprom, we need two types of buffer
* 1. Parameter Buffer : This is the intended value we want to store in EEPROM
* 2. Status Buffer: This buffer keeps track of my current location in buffer.
*/
**************************************************************************/


/**************************************************************************
Author Information
***************************************************************************
Author : Shuvangkar Shuvo
email: sshuvo93[at]gmail.com
Dhaka, Bangladesh
**************************************************************************/


#include "eep.h"
Expand All @@ -27,12 +36,15 @@

EEProm::EEProm(int addrPtr, byte bufSz, byte paramSize)
{
_initAddr = addrPtr;
_bufSz = bufSz;
_paramPacketSz = paramSize;
_initAddr = addrPtr; //First address of the buffer
_bufSz = bufSz; //Total number of buffer
_paramPacketSz = paramSize;// Total byte in a parameter packet
//_clrStatusBuf();
}

/*************************************************************
* When status buffer becomes full, this method clears the status buffer
*************************************************************/
void EEProm::_clrStatusBuf()
{

Expand All @@ -43,6 +55,11 @@ void EEProm::_clrStatusBuf()
//Extra protection is needed here. after setting zero read and check
// whether all values are zero.
}

/************************************************************
*This methods scan the status buffer and find out the current
*location to write
*************************************************************/
byte EEProm::_getStatusPtr()
{
byte ptr;
Expand All @@ -51,20 +68,27 @@ byte EEProm::_getStatusPtr()
{
ptr = EEPROM.read( _initAddr + i);
//debugEepln(i);
} while (++i && ptr && i <= _bufSz);
} while (++i && ptr && (i <= _bufSz));
return i;
}

/************************************************************
*user call this methods to save the parameter packet
*************************************************************/
void EEProm::savePacket(byte *dataBuf)
{
byte statusPtr = _getStatusPtr();
if (statusPtr > _bufSz)
{
debugEepln(F("<<<<<<<<<Buf Full>>>>>"));
_clrStatusBuf();
//first value of status pointer is 1, zero indicates
// the location is not used yet
statusPtr = 1;
}

byte index = statusPtr - 1;
//Status pointer address ends, param pointer address starts
int paramInitAddr = _initAddr + _bufSz;
int paramPtr = paramInitAddr + (index * _paramPacketSz);
debugEep(F("Data Save Addr: ")); debugEepln(paramPtr);
Expand All @@ -76,6 +100,9 @@ void EEProm::savePacket(byte *dataBuf)
EEPROM.write(_initAddr + index, statusPtr); // update status pointer
}

/************************************************************
*user call this methods to read last saved value
*************************************************************/
void EEProm::readPacket(byte *dataBuf)
{
byte statusPtr = _getStatusPtr();
Expand All @@ -91,6 +118,8 @@ void EEProm::readPacket(byte *dataBuf)
}
//Serial.println();
}


void EEProm::printStatusBuf()
{
byte value;
Expand Down

0 comments on commit 9501153

Please sign in to comment.