35#ifndef _FREERTOS_DRIVER_TI_TIVAEEPROMFILE_HXX_
36#define _FREERTOS_DRIVER_TI_TIVAEEPROMFILE_HXX_
38#include "driverlib/rom.h"
39#include "driverlib/rom_map.h"
41#include "driverlib/eeprom.h"
42#include "driverlib/sysctl.h"
54 MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_EEPROM0);
58 HASSERT(byte_offset % (8 * 64) == 0);
59 HASSERT(byte_size % (8 * 64) == 0);
76 ssize_t
write(
unsigned int index,
const void *buf,
size_t len)
override
79 uint8_t *b = (uint8_t *)buf;
84 MAP_EEPROMRead(&rd, (index +
byteOffset_) & ~0x3, 4);
85 size_t actual_len = 4 - (index & 0x3);
86 actual_len = std::min(len, actual_len);
87 memcpy(((uint8_t*)&rd) + (index & 0x3), b, actual_len);
88 MAP_EEPROMProgram(&rd, (index +
byteOffset_) & ~0x3, 4);
95 size_t word_len = len & ~0x3;
99 MAP_EEPROMProgram((uint32_t *)b, index +
byteOffset_, word_len);
123 ssize_t
read(
unsigned int index,
void *buf,
size_t len)
override
126 uint8_t *b = (uint8_t *)buf;
131 MAP_EEPROMRead(&rd, (index +
byteOffset_) & ~0x3, 4);
132 size_t actual_len = 4 - (index & 0x3);
133 actual_len = std::min(len, actual_len);
134 memcpy(b, ((uint8_t *)&rd) + (index & 0x3), actual_len);
141 size_t word_len = len & ~0x3;
145 MAP_EEPROMRead((uint32_t *)b, index +
byteOffset_, word_len);
Base class for implementing block devices and other file drivers which can be seeked and addressed by...
DeviceFile()
Default constructor.
static int fstat(struct _reent *reent, int fd, struct stat *stat)
Get the status information of a file or device.
const char * name
device name
ssize_t read(unsigned int index, void *buf, size_t len) override
Read from the eeprom.
uint16_t byteSize_
Total number of bytes in this file.
uint16_t byteOffset_
Address in the EEPROM of the first byte of this file.
ssize_t write(unsigned int index, const void *buf, size_t len) override
Write to the eeprom.
int fstat(File *file, struct stat *stat) override
Implements querying the file size.
#define HASSERT(x)
Checks that the value of expression x is true, else terminates the current process.
static int stat(struct _reent *reent, const char *path, struct stat *stat)
Get the status information of a file or device.