Accessories
Arduino for motors and lights library.
AccessoriesCircularBuffer Class Reference

#include "AccessoriesCircularBuffer.hpp"

Public Member Functions

 AccessoriesCircularBuffer ()
 
int begin (int inStartListPos, byte inItemSize, byte inReplicaNumber)
 
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 29 of file AccessoriesCircularBuffer.hpp.

Constructor & Destructor Documentation

AccessoriesCircularBuffer::AccessoriesCircularBuffer ( )
inline

Basic constructor.

Definition at line 38 of file AccessoriesCircularBuffer.hpp.

Member Function Documentation

int AccessoriesCircularBuffer::begin ( int  inStartListPos,
byte  inItemSize,
byte  inReplicaNumber 
)
inline

Initialize the instance.

Parameters
inStartListPosEEPROM address of the beginning of the memory used for the storage
inItemSizeSize 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 46 of file AccessoriesCircularBuffer.hpp.

void AccessoriesCircularBuffer::clear ( ) const

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

int AccessoriesCircularBuffer::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.
int AccessoriesCircularBuffer::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 !

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