#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 |
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.
|
inline |
Basic constructor.
Definition at line 40 of file CircularBuffer.hpp.
|
inline |
Initialize the instance.
inStartListPos | EEPROM address of the begginning of the memory used for the storage |
inElementSize | Size in bytes of one item to save. |
inReplicaNumber | Number of copies of the element can be reserved for the buffer. 2 is a minimum, 255 a maximum. |
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.
Definition at line 83 of file CircularBuffer.cpp.
void * CircularBuffer::read | ( | void * | outpObject | ) |
Read the last saved element in the buffer.
outpObject | object to fill with the content of the EEPROM memory. |
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.
Definition at line 89 of file CircularBuffer.cpp.
|
inline |
Write a new element in the buffer, checking for byte to update or not.
inpObject | object 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.
inpObject | object to write to the EEPROM memory. |
inUpdate | if 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.