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

Emulates EEPROM in FLASH for the LPC17xx and LPC40xx platforms. More...

#include <Lpc17xx40xxEEPROMEmulation.hxx>

Inheritance diagram for LpcEEPROMEmulation:
EEPROMEmulation EEPROM Node Device FileIO

Public Member Functions

 LpcEEPROMEmulation (const char *name, size_t file_size)
 Constructor.
 
 ~LpcEEPROMEmulation ()
 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

const uint32_t * block (unsigned sector, unsigned offset) override
 Computes the pointer to load the data stored in a specific block from.
 
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.
 
 LpcEEPROMEmulation ()
 Default constructor.
 
 DISALLOW_COPY_AND_ASSIGN (LpcEEPROMEmulation)
 

Static Private Member Functions

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

Private Attributes

const uint8_t firstSector_
 Stores the IAP sector code for the first sector starting at __eeprom_start.
 
uint8_t scratch [WRITE_SIZE]
 scratchpad for performing write operations
 

Static Private Attributes

static constexpr unsigned WRITE_SIZE = 256
 write size in bytes, must be used as an array size
 

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 LPC17xx and LPC40xx platforms.

The EEPROM file size is limited to the SECTOR_SIZE / 2.

Definition at line 42 of file Lpc17xx40xxEEPROMEmulation.hxx.

Constructor & Destructor Documentation

◆ LpcEEPROMEmulation()

LpcEEPROMEmulation::LpcEEPROMEmulation ( const char *  name,
size_t  file_size 
)

Constructor.

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

Definition at line 62 of file Lpc17xx40xxEEPROMEmulation.cxx.

◆ ~LpcEEPROMEmulation()

LpcEEPROMEmulation::~LpcEEPROMEmulation ( )
inline

Destructor.

Definition at line 53 of file Lpc17xx40xxEEPROMEmulation.hxx.

Member Function Documentation

◆ block()

const uint32_t * LpcEEPROMEmulation::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 96 of file Lpc17xx40xxEEPROMEmulation.cxx.

◆ flash_erase()

void LpcEEPROMEmulation::flash_erase ( unsigned  sector)
overrideprivatevirtual

Simple hardware abstraction for FLASH erase API.

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

Implements EEPROMEmulation.

Definition at line 103 of file Lpc17xx40xxEEPROMEmulation.cxx.

◆ flash_program()

void LpcEEPROMEmulation::flash_program ( unsigned  relative_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 [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

Implements EEPROMEmulation.

Definition at line 122 of file Lpc17xx40xxEEPROMEmulation.cxx.

◆ get_block()

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

Definition at line 84 of file Lpc17xx40xxEEPROMEmulation.cxx.

Member Data Documentation

◆ firstSector_

const uint8_t LpcEEPROMEmulation::firstSector_
private

Stores the IAP sector code for the first sector starting at __eeprom_start.

Definition at line 87 of file Lpc17xx40xxEEPROMEmulation.hxx.

◆ scratch

uint8_t LpcEEPROMEmulation::scratch[WRITE_SIZE]
private

scratchpad for performing write operations

Definition at line 90 of file Lpc17xx40xxEEPROMEmulation.hxx.

◆ WRITE_SIZE

constexpr unsigned LpcEEPROMEmulation::WRITE_SIZE = 256
staticconstexprprivate

write size in bytes, must be used as an array size

Definition at line 59 of file Lpc17xx40xxEEPROMEmulation.hxx.


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