AVRCpp::EEPROM Namespace Reference

Functionality of EEPROM memory. More...


Classes

struct  ReadyInterrupt
 The EEPROM Ready interrupt generates a constant interrupt when the write access time has elapsed. More...

Namespaces

namespace  Internal
 Only for library's internal use.

Enumerations

enum  Mode {
  EraseOnly = 0x10,
  WriteOnly = 0x20,
  EraseAndWrite = 0x10 | 0x20
}

Functions

static bool IsWritingFlash ()
static void WaitWhileWritingFlash ()
static void WriteOperation ()
bool MoveNext ()
 Increments current address unless it is pointing to the last byte in EEPROM memory.
void Write (uint8_t data)
 Writes data to previously set address. It must not be interrupted by another request to read or write.
void Write (uint16_t address, uint8_t data)
 Writes data to given address. It must not be interrupted by another request to read or write.
static bool ErasingProcess (uint16_t lastByteAddr)
static bool EraseOperation (uint16_t numberOfBytes)
bool Erase (uint16_t numberOfBytes)
 Erase array of data from previously set address. After this operation, the address is set to the byte after last erased byte.
bool IsWriting ()
 Returns true if writing proccess is taking place.
void WaitWhileWriting ()
 Blocks while writing proccess is present.
void SetAddressUnsafe (uint16_t address)
 Tries to set address even if previous writing operation has not finished.
void SetAddress (uint16_t address)
 Waits for previous writing operation to finish, then sets address.
uint16_t GetAddress ()
 Returns current address.
uint8_t Read ()
 Read one byte from previously set (current) address.
uint8_t Read (uint16_t address)
 Read one byte from given address.
void SetMode (Mode mode)
 Sets EEPROM writing mode.
uint8_t GetMode ()
 Returns EEPROM writing mode.
template<typename T>
bool Save (T data)
 Saves data to EEPROM to the current address.
template<typename T>
bool Load (T &data)
 Reads data from EEPROM from the current address.
template<typename T>
bool SaveArray (T *data, uint16_t elementsCount)
 Save array of data to previously set address.
template<typename T>
bool LoadArray (T *data, uint16_t elementsCount)
 Load array of data from previously set address.


Detailed Description

Functionality of EEPROM memory.

Enumeration Type Documentation

enum AVRCpp::EEPROM::Mode

Enumerator:
EraseOnly  In Erase Mode, data is being erased instead of written.
WriteOnly  In Write Only Mode, data is being written without erasing the memory first. Erase memory explicitly if necessary.
EraseAndWrite  In Erase Write Mode, memory at the specified address is erased and filled with new data in one operation.

Definition at line 160 of file EEPROM.h.

00161                 {
00163                         EraseOnly               = _EEPM0,
00165                         WriteOnly               = _EEPM1,
00167                         EraseAndWrite   = _EEPM0 |_EEPM1
00168 
00169                 }; // enum Mode


Function Documentation

bool AVRCpp::EEPROM::Erase ( uint16_t  numberOfBytes  ) 

Erase array of data from previously set address. After this operation, the address is set to the byte after last erased byte.

Definition at line 210 of file EEPROM.cpp.

00211                 {
00212                         uint8_t savedEECR = EECR;
00213                         
00214                         SetMode(EraseOnly);
00215                         
00216                         {
00217                                 bool result = EraseOperation(numberOfBytes);
00218                                 
00219                                 ChangeBits<_EECR>(_EEPM1 | _EEPM0, savedEECR);
00220                                 
00221                                 return result;
00222                         }
00223 
00224                 } // Erase

static bool AVRCpp::EEPROM::EraseOperation ( uint16_t  numberOfBytes  )  [inline, static]

Definition at line 195 of file EEPROM.cpp.

00196                 {
00197                         // Is there anything to read or write ?
00198                         if (numberOfBytes == 0)
00199                                 return true;
00200                         
00201                         {
00202                                 uint16_t lastByteAddr = EEAR + numberOfBytes - 1;
00203                                 
00204                                 return ErasingProcess(lastByteAddr);
00205                         }
00206                         
00207                 } // EraseOperation

static bool AVRCpp::EEPROM::ErasingProcess ( uint16_t  lastByteAddr  )  [inline, static]

Definition at line 163 of file EEPROM.cpp.

00164                 {
00165                         // Enough space ?
00166                         if (lastByteAddr >= EEPROM_SIZE)
00167                                 return false;
00168                         
00169                         // Erase byte by byte
00170                         while (true)
00171                         {
00172                                 
00173                                 WaitWhileWriting();
00174                                 
00175                                 WaitWhileWritingFlash();
00176                                 
00177                                 WriteOperation();
00178                                 
00179                                 // Done ?
00180                                 if (EEAR == lastByteAddr)
00181                                         break;
00182                                 
00183                                 WaitWhileWriting();
00184                                 
00185                                 EEAR++;
00186                         }
00187                         
00188                         MoveNext();
00189                         
00190                         return true;
00191                         
00192                 } // ErasingProcess

uint16_t AVRCpp::EEPROM::GetAddress (  )  [inline]

Returns current address.

Definition at line 128 of file EEPROM.h.

00128 {       return EEAR; }

uint8_t AVRCpp::EEPROM::GetMode (  )  [inline]

Returns EEPROM writing mode.

Definition at line 174 of file EEPROM.h.

00174 { return SelectBits<_EECR>(_EEPM0 | _EEPM1); }

bool AVRCpp::EEPROM::IsWriting (  )  [inline]

Returns true if writing proccess is taking place.

Definition at line 120 of file EEPROM.h.

00120 {       return IsBitsSet<_EECR>(__EEPE__); }

static bool AVRCpp::EEPROM::IsWritingFlash (  )  [inline, static]

Definition at line 38 of file EEPROM.cpp.

00038 {       return IsBitsSet<__SPMCSR__>(__SPMEN__); }

template<typename T>
bool AVRCpp::EEPROM::Load ( T &  data  )  [inline]

Reads data from EEPROM from the current address.

Data can be from any type specified with template parameter 'T'.

Returns:
true on success.

Definition at line 218 of file EEPROM.h.

00218 { return Internal::LoadSaveOperation<T>(false, &data, 1); }

template<typename T>
bool AVRCpp::EEPROM::LoadArray ( T *  data,
uint16_t  elementsCount 
) [inline]

Load array of data from previously set address.

After this operation, the address points to the first byte after the written array.

Returns:
true on success.

Definition at line 230 of file EEPROM.h.

00230 { return Internal::LoadSaveOperation<T>(false, data, elementsCount); }

bool AVRCpp::EEPROM::MoveNext (  ) 

Increments current address unless it is pointing to the last byte in EEPROM memory.

Definition at line 58 of file EEPROM.cpp.

00059                 {
00060                         if (EEAR < EEPROM_SIZE - 1)
00061                         {
00062                                 WaitWhileWriting();
00063                                 EEAR++;
00064                                 
00065                                 return true;
00066                         }
00067                         
00068                         return false;
00069                         
00070                 } // MoveNext

uint8_t AVRCpp::EEPROM::Read ( uint16_t  address  )  [inline]

Read one byte from given address.

Definition at line 148 of file EEPROM.h.

00149                 {
00150                         SetAddress(address);
00151                         
00152                         SetBits<_EECR>(_EERE);
00153                         
00154                         return EEDR;
00155                         
00156                 } // Read 2

uint8_t AVRCpp::EEPROM::Read (  )  [inline]

Read one byte from previously set (current) address.

Definition at line 137 of file EEPROM.h.

00138                 {
00139                         WaitWhileWriting();
00140                         
00141                         SetBits<_EECR>(_EERE);
00142                         
00143                         return EEDR;
00144                         
00145                 } // Read 1

template<typename T>
bool AVRCpp::EEPROM::Save ( data  )  [inline]

Saves data to EEPROM to the current address.

Data can be from any type specified with template parameter 'T'.

Returns:
true on success.

Definition at line 212 of file EEPROM.h.

00212 { return Internal::LoadSaveOperation<T>(true, &data, 1); }

template<typename T>
bool AVRCpp::EEPROM::SaveArray ( T *  data,
uint16_t  elementsCount 
) [inline]

Save array of data to previously set address.

After this operation, the address points to the first byte after the written array.

Returns:
true on success.

Definition at line 224 of file EEPROM.h.

00224 { return Internal::LoadSaveOperation<T>(true, data, elementsCount); }

void AVRCpp::EEPROM::SetAddress ( uint16_t  address  )  [inline]

Waits for previous writing operation to finish, then sets address.

Definition at line 126 of file EEPROM.h.

00126 { WaitWhileWriting(); SetAddressUnsafe(address); }

void AVRCpp::EEPROM::SetAddressUnsafe ( uint16_t  address  )  [inline]

Tries to set address even if previous writing operation has not finished.

Definition at line 124 of file EEPROM.h.

00124 { EEAR = address; }

void AVRCpp::EEPROM::SetMode ( Mode  mode  )  [inline]

Sets EEPROM writing mode.

Definition at line 172 of file EEPROM.h.

00172 { ChangeBits<_EECR>(_EEPM0 | _EEPM1, mode); }

void AVRCpp::EEPROM::WaitWhileWriting (  )  [inline]

Blocks while writing proccess is present.

Definition at line 122 of file EEPROM.h.

00122 { while (IsWriting() ); }

static void AVRCpp::EEPROM::WaitWhileWritingFlash (  )  [inline, static]

Definition at line 39 of file EEPROM.cpp.

00039 { while (IsWritingFlash() ); }

void AVRCpp::EEPROM::Write ( uint16_t  address,
uint8_t  data 
)

Writes data to given address. It must not be interrupted by another request to read or write.

Definition at line 86 of file EEPROM.cpp.

00087                 {
00088                         WaitWhileWriting();
00089                         
00090                         WaitWhileWritingFlash();
00091                         
00092                         SetAddressUnsafe(address);
00093                         
00094                         EEDR = data;
00095                         
00096                         WriteOperation();
00097 
00098                 } // Write 2

void AVRCpp::EEPROM::Write ( uint8_t  data  ) 

Writes data to previously set address. It must not be interrupted by another request to read or write.

Definition at line 73 of file EEPROM.cpp.

00074                 {
00075                         WaitWhileWriting();
00076                         
00077                         WaitWhileWritingFlash();
00078                         
00079                         EEDR = data;
00080                         
00081                         WriteOperation();
00082 
00083                 } // Write 1

static void AVRCpp::EEPROM::WriteOperation (  )  [static]

Definition at line 41 of file EEPROM.cpp.

00042                 {
00043                         // Save SREG_I bit.
00044                         uint8_t savedSREG = SREG;
00045                         
00046                         // __EEPE__ must be set immediately after setting __EEMPE__
00047                         GlobalInterrupts::Disable();
00048                         
00049                         SetBits<_EECR>(__EEMPE__);
00050                         SetBits<_EECR>(__EEPE__);
00051                         
00052                         // Restore the interrupt bit in Status Register
00053                         SREG = savedSREG;
00054 
00055                 } // WriteOperation


Generated on Sat Sep 15 23:41:17 2007 for AVR C++ Lib for ATmega644 by  doxygen 1.5.2
SourceForge.net Logo MTÜ TTÜ Robotiklubi