34#ifndef _FREERTOS_DRIVERS_COMMON_RAMDISK_HXX_
35#define _FREERTOS_DRIVERS_COMMON_RAMDISK_HXX_
60 RamDiskBase(
const char *path,
void *data,
unsigned size,
bool read_only)
62 ,
data_((uint8_t *)data)
92 count = std::min(count, left);
93 memcpy(buf,
data_ + file->offset, count);
94 file->offset += count;
104 if (file->offset >=
size_)
108 size_t left =
size_ - file->offset;
109 count = std::min(count, left);
110 memcpy(
data_ + file->offset, buf, count);
111 file->offset += count;
157 :
RamDiskBase(path, new uint8_t[size], size, false)
170 RamDisk(
const char* path, T* data,
bool read_only =
false)
const char * name
device name
int open(File *, const char *, int, int) OVERRIDE
Open method.
A simple device driver that reads/write data from a block of memory in RAM.
RamDiskBase(const char *path, void *data, unsigned size, bool read_only)
Constructor.
unsigned actualSize_
What's the larget file offset that we received an actual write for.
unsigned owned_
1 if we own the data bytes and need to free()them upon exit.
unsigned readOnly_
1 ifreadonly file.
void flush_buffers() OVERRIDE
Instructs the device driver to drop all TX and RX queues.
int open(File *file, const char *name, int flags, int mode) OVERRIDE
Open method.
ssize_t write(File *file, const void *buf, size_t count) OVERRIDE
Write to a file or device.
void enable() OVERRIDE
This will be called once when reference-count goes from 0 to positive.
uint8_t * data_
Pointer to data content.
unsigned size_
How many bytes we are exporting.
ssize_t read(File *file, void *buf, size_t count) OVERRIDE
Read from a file or device.
void disable() OVERRIDE
This will be called when reference count goes from non-zero to 0.
A simple device driver that reads/write data from a block of memory in a typed array either staticall...
RamDisk(const char *path, size_t size)
Allocates space on the heap for the ramdisk of size ‘size’.
RamDisk(const char *path, T *data, bool read_only=false)
Uses an existing variable for backing the ramdisk structure.
#define OVERRIDE
Function attribute for virtual functions declaring that this funciton is overriding a funciton that s...