34#include <sys/select.h>
77 static int pipe(
int pipefds[2]);
111 return (off_t)-ESPIPE;
153 if ((file->
flags & O_ACCMODE) == O_WRONLY)
158 uint8_t *data = (uint8_t*)buf;
170 bytes =
ring->
get(data, count);
185 if (file->
flags & O_NONBLOCK || result > 0)
196 ::select(fd + 1, &rdfds, NULL, NULL, NULL);
212 if ((file->
flags & O_ACCMODE) == O_RDONLY)
217 const uint8_t *data = (
const uint8_t*)buf;
229 bytes =
ring->
put(data, count);
244 if (file->
flags & O_NONBLOCK || result > 0)
255 ::select(fd + 1, NULL, &wrfds, NULL, NULL);
315 portENTER_CRITICAL();
327 portENTER_CRITICAL();
int pipe(int pipefds[2])
Create a Unix style pipe.
const size_t DEFAULT_PIPE_SIZE
Default value of the buffer size in the pipe implementation for FreeRTOS.
static void fd_free(int fd)
Free up a file descriptor.
static File * file_lookup(int fd)
Looks up a reference to a File corresponding to a given file descriptor.
static File files[]
File descriptor pool.
static int fd_lookup(File *file)
Looks up a file descriptor corresponding to a given File reference.
const char * name
device name
static int fd_alloc(void)
Allocate a free file descriptor.
static OSMutex mutex
mutual exclusion for fileio
unsigned int references_
number of open references
OSMutex lock_
protects internal structures.
mode_t mode_
File open mode, such as O_NONBLOCK.
Class to allow convenient locking and unlocking of mutexes in a C context.
void unlock()
Unlock a mutex.
Private data for a can device.
SelectInfo selInfoRd
called after disable
void flush_buffers() OVERRIDE
function to disable device
ssize_t write(File *file, const void *buf, size_t count) OVERRIDE
Write to a file or device.
static int pipe(int pipefds[2])
Create a Unix style pipe.
off_t lseek(File *f, off_t offset, int whence) override
Seek method.
Pipe(const char *name)
Constructor.
bool select(File *file, int mode) OVERRIDE
Device select method.
RingBuffer< uint8_t > * ring
ring buffer for storing the data
void disable() OVERRIDE
This will be called when reference count goes from non-zero to 0.
SelectInfo selInfoWr
select wakeup metadata for write active
int close(File *file) OVERRIDE
Close method.
void enable() OVERRIDE
function to enable device
int fcntl(File *file, int cmd, unsigned long data) OVERRIDE
Manipulate a file descriptor.
ssize_t read(File *file, void *buf, size_t count) OVERRIDE
Read from a file or device.
Implements a vanilla ring buffer.
size_t get(T *buf, size_t items)
remove a number of items from the buffer.
void destroy()
Destroy an existing ring buffer instance.
size_t space()
space left in buffer of buffer in number items.
size_t put(const T *buf, size_t items)
Insert a number of items to the buffer.
static RingBuffer * create(size_t size)
Factory method to create a ring buffer instance.
size_t items()
Number of items in the buffer.
#define FWRITE
Workaround for missing header defines on some newlib versions.
#define FREAD
Workaround for missing header defines on some newlib versions.
#define F_SETPIPE_SZ
ioctl to set the length of the internal fifo buffer.
#define OVERRIDE
Function attribute for virtual functions declaring that this funciton is overriding a funciton that s...
#define HASSERT(x)
Checks that the value of expression x is true, else terminates the current process.
#define DISALLOW_COPY_AND_ASSIGN(TypeName)
Removes default copy-constructor and assignment added by C++.
Select wakeup information.
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.
uint8_t device
true if this is a device, false if file system
FileIO * dev
file operations