Open Model Railroad Network (OpenMRN)
Loading...
Searching...
No Matches
MyEEPROM Class Reference

Test EEPROM emulation HAL implementation that writes to a block of (RAM) memory. More...

#include <EEPROMEmuTest.hxx>

Inheritance diagram for MyEEPROM:
EEPROMEmulation EEPROM Node Device FileIO

Public Member Functions

 MyEEPROM (size_t file_size, bool clear=true)
 Contructor.
 
unsigned avail ()
 
- Public Member Functions inherited from EEPROM
 EEPROM (const char *name, size_t file_size)
 Constructor.
 
size_t file_size ()
 
- Public Member Functions inherited from Device
 Device (const char *name)
 Constructor.
 
virtual ~Device ()
 Destructor.
 

Private Member Functions

void flash_erase (unsigned sector) override
 Simple hardware abstraction for FLASH erase API.
 
void flash_program (unsigned sector, unsigned block, uint32_t *data, uint32_t byte_count) override
 Simple hardware abstraction for FLASH program API.
 
const uint32_t * block (unsigned sector, unsigned index) override
 Computes the pointer to load the data stored in a specific block from.
 

Additional Inherited Members

- Static Public Member Functions inherited from Device
static int open (struct _reent *reent, const char *path, int flags, int mode)
 Open a file or device.
 
static int close (struct _reent *reent, int fd)
 Close a file or device.
 
static int stat (struct _reent *reent, const char *path, struct stat *stat)
 Get the status information of a file or device.
 
static int select (int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, long long timeout)
 POSIX select().
 
static void select_clear ()
 Clears the current thread's select bits.
 
- Static Public Member Functions inherited from FileIO
static ssize_t read (struct _reent *reent, int fd, void *buf, size_t count)
 Read from a file or device.
 
static ssize_t write (struct _reent *reent, int fd, const void *buf, size_t count)
 Write to a file or device.
 
static _off_t lseek (struct _reent *reent, int fd, _off_t offset, int whence)
 Change the offset index of a file or device.
 
static int fstat (struct _reent *reent, int fd, struct stat *stat)
 Get the status information of a file or device.
 
static int ioctl (int fd, unsigned long int key, unsigned long data)
 Request and ioctl transaction.
 
static int fcntl (int fd, int cmd, unsigned long data)
 Manipulate a file descriptor.
 
static bool is_device (int fd)
 Test if the file descriptor belongs to a device.
 
- Protected Types inherited from EEPROMEmulation
enum  MagicBlockIndex {
  MAGIC_FIRST_INDEX = 0 , MAGIC_DIRTY_INDEX = 0 , MAGIC_INTACT_INDEX , MAGIC_USED_INDEX ,
  MAGIC_COUNT
}
 Raw block indexes within a sector to mark the state of the sector. More...
 
- Protected Member Functions inherited from EEPROMEmulation
 EEPROMEmulation (const char *name, size_t file_size)
 Constructor.
 
 ~EEPROMEmulation ()
 Destructor.
 
void mount ()
 Mount the EEPROM file.
 
 EEPROMEmulation ()
 Default constructor.
 
 DISALLOW_COPY_AND_ASSIGN (EEPROMEmulation)
 
- Protected Member Functions inherited from EEPROM
 EEPROM (const char *name, size_t file_size)
 Constructor.
 
 ~EEPROM ()
 Destructor.
 
size_t file_size ()
 Get the maximum file size of the EEPROM file.
 
- Protected Member Functions inherited from Node
 Node (const char *name)
 Constructor.
 
virtual ~Node ()
 Destructor.
 
int open (File *, const char *, int, int) OVERRIDE
 Open method.
 
int close (File *) OVERRIDE
 Close method.
 
virtual int fstat (File *file, struct stat *stat) override
 Get the status information of a file or device.
 
- Protected Member Functions inherited from FileIO
 FileIO (const char *name)
 Constructor.
 
virtual ~FileIO ()
 Destructor.
 
virtual int ioctl (File *file, unsigned long int key, unsigned long data)
 Request an ioctl transaction.
 
virtual int fcntl (File *file, int cmd, unsigned long data)
 Manipulate a file descriptor.
 
virtual bool select (File *file, int mode)
 Device select method.
 
- Static Protected Member Functions inherited from Device
static void select_insert (SelectInfo *info)
 Add client to list of clients needing woken.
 
static void select_wakeup (SelectInfo *info)
 Wakeup the list of clients needing woken.
 
static void select_wakeup_from_isr (SelectInfo *info, int *woken)
 Wakeup the list of clients needing woken.
 
- Static Protected Member Functions inherited from FileIO
static int fd_alloc (void)
 Allocate a free file descriptor.
 
static void fd_free (int fd)
 Free up a file descriptor.
 
static Filefile_lookup (int fd)
 Looks up a reference to a File corresponding to a given file descriptor.
 
static int fd_lookup (File *file)
 Looks up a file descriptor corresponding to a given File reference.
 
- Protected Attributes inherited from EEPROMEmulation
const uint8_t sectorCount_ {(uint8_t)(EEPROMEMU_FLASH_SIZE / SECTOR_SIZE)}
 Total number of sectors available.
 
uint8_t activeSector_ {0}
 Index of the active sector.
 
const uint16_t rawBlockCount_ {(uint16_t)(SECTOR_SIZE / BLOCK_SIZE)}
 How many blocks are there in a sector.
 
size_t availableSlots_ {0}
 Number of available (writable) slots for new data in the active sector.
 
bool shadowInRam_ {false}
 local copy of SHADOW_IN_RAM which we can manipulate at run time.
 
uint8_t * shadow_ {nullptr}
 pointer to RAM for shadowing EEPROM.
 
- Protected Attributes inherited from Node
OSMutex lock_
 protects internal structures.
 
mode_t mode_
 File open mode, such as O_NONBLOCK.
 
unsigned int references_
 number of open references
 
- Protected Attributes inherited from FileIO
const char * name
 device name
 
- Static Protected Attributes inherited from EEPROMEmulation
static const size_t SECTOR_SIZE = (4 * 1024)
 Sector size in bytes.
 
static const size_t BLOCK_SIZE = 16
 block size in bytes
 
static constexpr unsigned MAX_BLOCK_SIZE = 16
 Maximum byte size of a single block.
 
static const uint32_t MAGIC_INTACT = 0xaa558001
 magic marker for an intact block
 
static const uint32_t MAGIC_DIRTY = 0xaa55aa55
 magic marker for a block that we are transitioning to intact
 
static const uint32_t MAGIC_USED = 0x00000000
 magic marker for a used block
 
static const uint32_t MAGIC_ERASED = 0xFFFFFFFF
 magic marker for an erased block
 
- Static Protected Attributes inherited from FileIO
static const unsigned int numOpenFiles = 20
 
static File files []
 File descriptor pool.
 
static OSMutex mutex
 mutual exclusion for fileio
 

Detailed Description

Test EEPROM emulation HAL implementation that writes to a block of (RAM) memory.

Used for unittesting the EEPROM Emulation code.

Definition at line 84 of file EEPROMEmuTest.hxx.

Constructor & Destructor Documentation

◆ MyEEPROM()

MyEEPROM::MyEEPROM ( size_t  file_size,
bool  clear = true 
)
inline

Contructor.

Parameters
file_sizehow many bytes
clearif true, the EEPROM will be initialized with all 0xFF bytes.

Definition at line 89 of file EEPROMEmuTest.hxx.

Member Function Documentation

◆ avail()

unsigned MyEEPROM::avail ( )
inline
Returns
how many blocks are available in the current sector.

Definition at line 102 of file EEPROMEmuTest.hxx.

◆ block()

const uint32_t * MyEEPROM::block ( unsigned  sector,
unsigned  offset 
)
inlineoverrideprivatevirtual

Computes the pointer to load the data stored in a specific block from.

Parameters
sectorsector number [0..sectorCount_ - 1]
offsetblock index within sector, [0..rawBlockCount_ - 1]
Returns
pointer to the beginning of the data in the block. Must be alive until the next call to this function.

Implements EEPROMEmulation.

Definition at line 124 of file EEPROMEmuTest.hxx.

◆ flash_erase()

void MyEEPROM::flash_erase ( unsigned  sector)
inlineoverrideprivatevirtual

Simple hardware abstraction for FLASH erase API.

Parameters
sectorNumber of sector [0.. sectorCount_ - 1] to erase

Implements EEPROMEmulation.

Definition at line 107 of file EEPROMEmuTest.hxx.

◆ flash_program()

void MyEEPROM::flash_program ( unsigned  sector,
unsigned  start_block,
uint32_t *  data,
uint32_t  byte_count 
)
inlineoverrideprivatevirtual

Simple hardware abstraction for FLASH program API.

Parameters
sectorthe sector to write to [0..sectorCount_ - 1]
start_blockthe block index to start writing to [0..rawBlockCount_ - 1]
dataa pointer to the data to be programmed
byte_countthe number of bytes to be programmed. Must be a multiple of BLOCK_SIZE

The bytes to program cannot overflow beyond the end of sector, so start_block + byte_count / BLOCK_SIZE <= rawBlockCount_ must hold.

Implements EEPROMEmulation.

Definition at line 114 of file EEPROMEmuTest.hxx.


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