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

Emulates EEPROM in FLASH for the Tiva platform. More...

#include <TivaEEPROMEmulation.hxx>

Inheritance diagram for TivaEEPROMEmulation:
EEPROMEmulation EEPROM Node Device FileIO

Public Types

enum  Family { TM4C123 = 1024 , TM4C129 = 1024 * 16 }
 Product family. More...
 

Public Member Functions

 TivaEEPROMEmulation (const char *name, size_t file_size_bytes)
 Constructor.
 
 ~TivaEEPROMEmulation ()
 Destructor.
 
- 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 start_block, uint32_t *data, uint32_t byte_count) override
 Simple hardware abstraction for FLASH program API.
 
const uint32_t * block (unsigned sector, unsigned offset) override
 Computes the pointer to load the data stored in a specific block from.
 
 TivaEEPROMEmulation ()
 Default constructor.
 
 DISALLOW_COPY_AND_ASSIGN (TivaEEPROMEmulation)
 

Static Private Member Functions

static const uint32_t * get_block (unsigned sector, unsigned offset)
 

Static Private Attributes

static const unsigned FAMILY
 Family that device belongs to
 

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

Emulates EEPROM in FLASH for the Tiva platform.

Todo:
there is a known bug whereby the ADDRESS_SPACE cannot be larger than (block size - 4).

Definition at line 48 of file TivaEEPROMEmulation.hxx.

Member Enumeration Documentation

◆ Family

Product family.

We use this to determine details, such as sector size, specific to a given family and relevant to the agorithm.

Enumerator
TM4C123 

Tiva TM4C123 devices, 1K block size.

TM4C129 

Tiva TM4C129 devices, 16K block Size.

Definition at line 54 of file TivaEEPROMEmulation.hxx.

Constructor & Destructor Documentation

◆ TivaEEPROMEmulation()

TivaEEPROMEmulation::TivaEEPROMEmulation ( const char *  name,
size_t  file_size_bytes 
)

Constructor.

Parameters
namedevice name
file_size_bytesmaximum file size that we can grow to.

Definition at line 45 of file TivaEEPROMEmulation.cxx.

◆ ~TivaEEPROMEmulation()

TivaEEPROMEmulation::~TivaEEPROMEmulation ( )
inline

Destructor.

Definition at line 68 of file TivaEEPROMEmulation.hxx.

Member Function Documentation

◆ block()

const uint32_t * TivaEEPROMEmulation::block ( unsigned  sector,
unsigned  offset 
)
overrideprivatevirtual

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 64 of file TivaEEPROMEmulation.cxx.

◆ flash_erase()

void TivaEEPROMEmulation::flash_erase ( unsigned  sector)
overrideprivatevirtual

Simple hardware abstraction for FLASH erase API.

Parameters
addressthe start address of the flash block to be erased

Implements EEPROMEmulation.

Definition at line 72 of file TivaEEPROMEmulation.cxx.

◆ flash_program()

void TivaEEPROMEmulation::flash_program ( unsigned  sector,
unsigned  start_block,
uint32_t *  data,
uint32_t  byte_count 
)
overrideprivatevirtual

Simple hardware abstraction for FLASH program API.

Parameters
sectorthe sector to write to
start_blockthe block index to start writing to
dataa pointer to the data to be programmed
byte_countthe number of bytes to be programmed. Must be a multiple of BLOCK_SIZE

Implements EEPROMEmulation.

Definition at line 103 of file TivaEEPROMEmulation.cxx.

◆ get_block()

const uint32_t * TivaEEPROMEmulation::get_block ( unsigned  sector,
unsigned  offset 
)
inlinestaticprivate

Definition at line 52 of file TivaEEPROMEmulation.cxx.

Member Data Documentation

◆ FAMILY

const unsigned TivaEEPROMEmulation::FAMILY
staticprivate

Family that device belongs to

Definition at line 76 of file TivaEEPROMEmulation.hxx.


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