NonVolatileMemory Class Reference
|
yasimavr
|
Non-volatile memory model. More...
#include <sim_memory.h>
Public Member Functions | |
| NonVolatileMemory (size_t size) | |
| NonVolatileMemory (const NonVolatileMemory &other) | |
| ~NonVolatileMemory () | |
| size_t | size () const |
| bool | programmed (size_t pos) const |
| bytes_view_t | programmed (size_t base, size_t len) const |
| unsigned char | operator[] (size_t pos) const |
| bytes_view_t | view () const |
| bytes_view_t | view (size_t base, size_t len) const |
| bool | program (const bytes_view_t &mem_block, size_t base=0) |
| void | erase () |
| void | erase (size_t base, size_t size) |
| void | erase (const bytes_view_t &buf, size_t base) |
| int | read (size_t pos) const |
| size_t | readinto (unsigned char *buf, size_t base, size_t len) const |
| void | write (unsigned char v, size_t pos) |
| void | write (const bytes_view_t &buf, size_t base) |
| void | spm_write (unsigned char v, size_t pos) |
| void | spm_write (const bytes_view_t &buf, const bytes_view_t &bufset, size_t base) |
| NonVolatileMemory & | operator= (const NonVolatileMemory &other) |
Detailed Description
Non-volatile memory model.
Represents a block of non-volatile memory (such as flash or eeprom) of a AVR MCU. It has a memory block which simulates the NVM actual storage. Each byte has a state unprogrammed/programmed, i.e. it is erased or loaded with a meaningful value.
Constructor & Destructor Documentation
◆ NonVolatileMemory() [1/2]
|
explicit |
Construct a non-volatile memory. Initialise the memory block, setting it to unprogrammed and filling it with the default value 0xFF.
- Parameters
-
size size of the NVM in bytes
◆ NonVolatileMemory() [2/2]
| NonVolatileMemory::NonVolatileMemory | ( | const NonVolatileMemory & | other | ) |
◆ ~NonVolatileMemory()
| NonVolatileMemory::~NonVolatileMemory | ( | ) |
Member Function Documentation
◆ erase() [1/3]
| void NonVolatileMemory::erase | ( | ) |
Erase the entire NVM.
◆ erase() [2/3]
| void NonVolatileMemory::erase | ( | const bytes_view_t & | buf, |
| size_t | base | ||
| ) |
Selective erasing of a NVM block. Bytes in the block are erased only if the corresponding byte in the buffer argument is non-zero.
- Parameters
-
buf buffer for selecting the bytes that should be erased base first address to be erased
◆ erase() [3/3]
| void NonVolatileMemory::erase | ( | size_t | base, |
| size_t | len | ||
| ) |
Erases a NVM block, overwrite all bytes of the block with the default value 0xFF and set their state to unprogrammed.
- Parameters
-
base first address to be erased len length of the block to be erased, in bytes
◆ operator=()
| NonVolatileMemory & NonVolatileMemory::operator= | ( | const NonVolatileMemory & | other | ) |
◆ operator[]()
|
inline |
Read a single NVM byte with no boundary checks.
- Parameters
-
pos address of the byte to read
- Returns
- the byte value
◆ program()
| bool NonVolatileMemory::program | ( | const bytes_view_t & | mem_block, |
| size_t | base = 0 |
||
| ) |
Load the NVM with a 'program'. The memory block is copied into the NVM bytes and their state are set to programmed.
- Parameters
-
mem_block memory block with the data to be loaded into the NVM. base first address where the memory block should be copied.
- Returns
- true if the operation was completed.
◆ programmed() [1/2]
| bytes_view_t NonVolatileMemory::programmed | ( | size_t | base, |
| size_t | len | ||
| ) | const |
Return the unprogrammed/programmed state of the NVM into a buffer. Each byte in the buffer is set a value of 0 for "unprogrammed" and 1 for "programmed".
- Parameters
-
base first address to be read len length of the area to be read, in bytes
- Returns
- bytes indicating if the position is programmed (non-zero) or unprogrammed (zero)
◆ programmed() [2/2]
|
inline |
Return the unprogrammed/programmed state of one NVM byte.
- Parameters
-
pos address of the byte
- Returns
- true if the byte is programmed, false if unprogrammed
◆ read()
| int NonVolatileMemory::read | ( | size_t | pos | ) | const |
Read a single NVM byte
- Parameters
-
pos address of the byte to read
- Returns
- the byte value or -1 if the address is invalid
◆ readinto()
| size_t NonVolatileMemory::readinto | ( | unsigned char * | buf, |
| size_t | base, | ||
| size_t | len | ||
| ) | const |
Read the memory into a buffer.
- Parameters
-
buf buffer to copy the NVM data into base first address to be read len length of the area to be read, in bytes
- Returns
- length of data actually read
◆ size()
|
inline |
Return the size of the NVM.
◆ spm_write() [1/2]
| void NonVolatileMemory::spm_write | ( | const bytes_view_t & | buf, |
| const bytes_view_t & | bufset, | ||
| size_t | base | ||
| ) |
Selectively write bytes to the NVM and set their state to programmed.
- Parameters
-
buf data to be copied bufset tag for the data in 'buf'. When a tag byte is non-zero, the corresponding byte in buf is copied into the NVM. base first address to be written
- Note
- The writing of each byte is performed by a bitwise AND with the previous content of the byte.
- If bufset is empty, all bytes in 'buf' are copied.
- bufset should be either empty or the same length as buf.
◆ spm_write() [2/2]
| void NonVolatileMemory::spm_write | ( | unsigned char | v, |
| size_t | pos | ||
| ) |
Write a byte to the NVM and set its state to programmed.
- Parameters
-
v value to write pos address to write, in bytes
- Note
- The writing is performed by a bitwise AND with the previous content of the byte.
◆ view() [1/2]
| bytes_view_t NonVolatileMemory::view | ( | ) | const |
Return a mem_block_t struct representing the entire NVM.
◆ view() [2/2]
| bytes_view_t NonVolatileMemory::view | ( | size_t | base, |
| size_t | len | ||
| ) | const |
Return a mem_block_t struct representing a block of the NVM.
◆ write() [1/2]
| void NonVolatileMemory::write | ( | const bytes_view_t & | buf, |
| size_t | base | ||
| ) |
Write bytes of the NVM.
- Parameters
-
buf data to be copied into the NVM base first address to be written len length of data to write
◆ write() [2/2]
| void NonVolatileMemory::write | ( | unsigned char | v, |
| size_t | pos | ||
| ) |
Write a byte of the NVM.
- Parameters
-
v data to be written pos address to be written
The documentation for this class was generated from the following files:
Generated by