34#ifndef _FREERTOS_DRIVERS_COMMON_DEVTAB_HXX_
35#define _FREERTOS_DRIVERS_COMMON_DEVTAB_HXX_
40#include <sys/select.h>
83 static ssize_t
read(
struct _reent *reent,
int fd,
void *buf,
size_t count);
93 static ssize_t
write(
struct _reent *reent,
int fd,
const void *buf,
size_t count);
103 static _off_t
lseek(
struct _reent *reent,
int fd, _off_t offset,
int whence);
111 static int fstat(
struct _reent *reent,
int fd,
struct stat *stat);
119 static int ioctl(
int fd,
unsigned long int key,
unsigned long data);
128 static int fcntl(
int fd,
int cmd,
unsigned long data);
161 virtual int open(
File *file,
const char *path,
int flags,
int mode) = 0;
176 virtual ssize_t
read(
File *file,
void *buf,
size_t count) = 0;
185 virtual ssize_t
write(
File *file,
const void *buf,
size_t count) = 0;
194 virtual off_t
lseek(
File* f, off_t offset,
int whence);
209 virtual int ioctl(
File *file,
unsigned long int key,
unsigned long data);
218 virtual int fcntl(
File *file,
int cmd,
unsigned long data);
298 virtual void mount(
const char *mount_point) = 0;
312 static int open(
struct _reent *reent,
const char *path,
int flags,
320 static int close(
struct _reent *reent,
int fd);
327 static int unlink(
struct _reent *reent,
const char *path);
335 static int stat(
struct _reent *reent,
const char *path,
struct stat *
stat);
341 static int fsync(
int fd);
367 virtual int unlink(
const char *path) = 0;
450 static int open(
struct _reent *reent,
const char *path,
int flags,
458 static int close(
struct _reent *reent,
int fd);
466 static int stat(
struct _reent *reent,
const char *path,
struct stat *
stat);
479 static int select(
int nfds, fd_set *readfds, fd_set *writefds,
480 fd_set *exceptfds,
long long timeout);
Helper for DeviceBuffer which allows for methods to not be inlined.
Base class for both Device and FileSystem objects.
static void fd_free(int fd)
Free up a file descriptor.
FileIO(const char *name)
Constructor.
static File * file_lookup(int fd)
Looks up a reference to a File corresponding to a given file descriptor.
static int fstat(struct _reent *reent, int fd, struct stat *stat)
Get the status information of a file or device.
friend class Device
Allow access from Device class.
static int fcntl(int fd, int cmd, unsigned long data)
Manipulate a file descriptor.
virtual int close(File *file)=0
Close a file or device.
static const unsigned int numOpenFiles
static ssize_t read(struct _reent *reent, int fd, void *buf, size_t count)
Read from a file or device.
static bool is_device(int fd)
Test if the file descriptor belongs to a 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 File files[]
File descriptor pool.
virtual ssize_t write(File *file, const void *buf, size_t count)=0
Write to a file or device.
virtual int fstat(File *file, struct stat *stat)=0
Get the status information of 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 int fd_lookup(File *file)
Looks up a file descriptor corresponding to a given File reference.
static int ioctl(int fd, unsigned long int key, unsigned long data)
Request and ioctl transaction.
virtual ssize_t read(File *file, void *buf, size_t count)=0
Read from a file or device.
const char * name
device name
virtual bool select(File *file, int mode)
Device select method.
virtual ~FileIO()
Destructor.
virtual int open(File *file, const char *path, int flags, int mode)=0
Open a file or device.
static int fd_alloc(void)
Allocate a free file descriptor.
static OSMutex mutex
mutual exclusion for fileio
Base class for all File systems.
virtual int closedir(File *file)=0
Close a directory.
static int open(struct _reent *reent, const char *path, int flags, int mode)
Open a file or device.
virtual int fsync(File *file)=0
Synchronize (flush) a file to disk.
virtual File * opendir(File *file, const char *name)=0
Open a directory.
FileSystem * next
next device in linked list
virtual int fstat(File *file, struct stat *stat) override
Get the status information of a file or device.
virtual struct dirent * readdir(File *file)=0
Read the next entry in a directory.
static DIR * opendir(const char *name)
Open a directory.
static struct dirent * readdir(DIR *dirp)
Read the next entry in a directory.
FileSystem * prev
previous device in linked list
static int fsync(int fd)
Synchronize (flush) a file to disk.
virtual ~FileSystem()
Destructor.
virtual void format()=0
Format the file system, all data will be lost.
static int close(struct _reent *reent, int fd)
Close a file or device.
virtual int stat(const char *path, struct stat *stat)=0
Get the status information of a file or device.
static FileSystem * fs_lookup(const char *path)
Locate the file system for a given path.
virtual void mount(const char *mount_point)=0
Mount the file system.
static int closedir(DIR *dirp)
Close a directory.
static FileSystem * first
first device in linked list
static int stat(struct _reent *reent, const char *path, struct stat *stat)
Get the status information of a file or device.
static int unlink(struct _reent *reent, const char *path)
Remove a file.
virtual int unlink(const char *path)=0
Remove a file.
virtual void flush_buffers()=0
Instructs the device driver to drop all TX and RX queues.
Node(const char *name)
Constructor.
virtual int fstat(File *file, struct stat *stat) override
Get the status information of a file or device.
virtual void enable()=0
This will be called once when reference-count goes from 0 to positive.
mode_t get_mode() override
Get the mode of the device.
unsigned int references_
number of open references
int close(File *) OVERRIDE
Close method.
virtual void disable()=0
This will be called when reference count goes from non-zero to 0.
int open(File *, const char *, int, int) OVERRIDE
Open method.
OSMutex lock_
protects internal structures.
mode_t mode_
File open mode, such as O_NONBLOCK.
virtual ~Node()
Destructor.
Node information for a device node in the filesystem that has support for nonblocking mode via Notifi...
virtual bool has_rx_buffer_data()=0
Called under a critical section.
NonBlockNode(const char *name)
Constructor.
int ioctl(File *file, unsigned long int key, unsigned long data) OVERRIDE
Request an ioctl transaction.
Notifiable * readableNotify_
This will be notified if the device has data avilable for read.
Notifiable * writableNotify_
This will be notified if the device has buffer avilable for write.
virtual bool has_tx_buffer_space()=0
Called under a critical section.
An object that can schedule itself on an executor to run.
This class provides a mutex API.
Helper class that allows a select to be asynchronously woken up.
uintptr_t DIR
DIR typedef.
#define OVERRIDE
Function attribute for virtual functions declaring that this funciton is overriding a funciton that s...
#define DISALLOW_COPY_AND_ASSIGN(TypeName)
Removes default copy-constructor and assignment added by C++.
Select wakeup information.
SelectInfo()
Default constructor.
OSEventType event
bit mask of clients that need woken
static void select_wakeup_from_isr(SelectInfo *info, int *woken)
Wakeup the list of clients needing woken.
static void select_insert(SelectInfo *info)
Add client to list of clients needing woken.
virtual mode_t get_mode()
Get the mode of the device.
static Device * first
first device in linked list
static void select_wakeup(SelectInfo *info)
Wakeup the list of clients needing woken.
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 int stat(struct _reent *reent, const char *path, struct stat *stat)
Get the status information of a file or device.
Device * next
next device in linked list
virtual ~Device()
Destructor.
static int close(struct _reent *reent, int fd)
Close a file or device.
static int open(struct _reent *reent, const char *path, int flags, int mode)
Open a file or device.
Device * prev
previous device in linked list
uint8_t dirty
true if this file is dirty and needs flush
uint8_t inshdn
true if this fd is in shutdown.
void * privPtr
file reference specific data "pointer"
off_t offset
current offset within file
uint8_t dir
true if this is a directory, else false
int privInt
file reference specific data "int"
void * priv
file reference specific data "pointer"
uint8_t device
true if this is a device, false if file system
unsigned privUint
file reference specific data "unsigned"
FileIO * dev
file operations
uint8_t inuse
true if this is an open fd.
Directory entry structure.