EEPROMextent
Arduino EEPROM library
CircularBuffer Class Reference

#include "CircularBuffer.hpp"

Public Member Functions

 CircularBuffer ()
 
int begin (int inStartListPos, byte inElementSize, byte inReplicaNumber)
 
void * read (void *outpObject)
 
void write (void *inpObject, bool inUpdate = false)
 
void update (void *inpObject)
 
int getStartRead ()
 
int startWrite ()
 
void clear () const
 

Detailed Description

This class implements the Atmel solution to avoid writing in EEPROM always in the same area to improve lifetime of this memory : a Circular Buffer. See http://www.atmel.com/images/doc2526.pdf . Part of the pdf file :

By having a circular buffer (O-buffer) in EEPROM it is possible to increase the number of times that a parameter can be stored in EEPROM. If the buffer has two levels the number of times that the parameter can be stored is twice the endurance of one single EEPROM cell: 200 k erase/writes. By using this approach it is possible to increase the number of times a parameter can be stored by increasing the O-buffer size. In other word, the idea is to distribute the storage of the parameter over several EEPROM locations to achieve increased parameter storage endurance. When using the Obuffer approach the parameter storage endurance equal the number of memory locations used in the O-buffer times the endurance of a single EEPROM location.

A circular buffer is a way to reduce the use of each EEPROM cell, and improve life time of the full EEPROM memory. An index of bytes is stored at the beginning of the area. Each index represents a data area.

|0|1|2|3|4||---0---|---1---|---2---|---3---|---4---|

Definition at line 31 of file CircularBuffer.hpp.

Constructor & Destructor Documentation

CircularBuffer::CircularBuffer ( )
inline

Basic constructor.

Definition at line 40 of file CircularBuffer.hpp.

Member Function Documentation

int CircularBuffer::begin ( int  inStartListPos,
byte  inElementSize,
byte  inReplicaNumber 
)
inline

Initialize the instance.

Parameters
inStartListPosEEPROM address of the begginning of the memory used for the storage
inElementSizeSize in bytes of one item to save.
inReplicaNumberNumber of copies of the element can be reserved for the buffer. 2 is a minimum, 255 a maximum.
Returns
Number of EEPROM bytes reserved for the circular buffer.

Definition at line 48 of file CircularBuffer.hpp.

void CircularBuffer::clear ( ) const

Fill with 0s the area reserved for the buffer. Use with care !

Definition at line 78 of file CircularBuffer.cpp.

int CircularBuffer::getStartRead ( )

If data cannot be loaded with a single call to a 'read', this function can be called to know where to read the current good element.

Returns
EEPROM address to start reading data.

Definition at line 83 of file CircularBuffer.cpp.

void * CircularBuffer::read ( void *  outpObject)

Read the last saved element in the buffer.

Parameters
outpObjectobject to fill with the content of the EEPROM memory.
Returns
outpObject address.

Definition at line 49 of file CircularBuffer.cpp.

int CircularBuffer::startWrite ( )

If data cannot be stored with a single call to a 'write', this function can be called to prepare the saving of the next good element.

Returns
EEPROM address to start writing data. Be careful, do not store more bytes than the inElementSize given during begin() call !

Definition at line 89 of file CircularBuffer.cpp.

void CircularBuffer::update ( void *  inpObject)
inline

Write a new element in the buffer, checking for byte to update or not.

Parameters
inpObjectobject to write to the EEPROM memory.

Definition at line 68 of file CircularBuffer.hpp.

void CircularBuffer::write ( void *  inpObject,
bool  inUpdate = false 
)

Write a new element in the buffer.

Parameters
inpObjectobject to write to the EEPROM memory.
inUpdateif true, an upadte is made, avoiding writing bytes already good in the memory. If false (the default), each byte is written at its place, even if the content was good.

Definition at line 57 of file CircularBuffer.cpp.


The documentation for this class was generated from the following files: