kfile_fifo.c
Go to the documentation of this file.00001
00038 #include "kfile_fifo.h"
00039 #include "fifobuf.h"
00040
00041 #include <io/kfile.h>
00042
00043 #include <string.h>
00044
00045 static size_t kfilefifo_read(struct KFile *_fd, void *_buf, size_t size)
00046 {
00047 KFileFifo *fd = KFILEFIFO_CAST(_fd);
00048 uint8_t *buf = (uint8_t *)_buf;
00049
00050 while (size-- && !fifo_isempty_locked(fd->fifo))
00051 *buf++ = fifo_pop_locked(fd->fifo);
00052
00053 return buf - (uint8_t *)_buf;
00054 }
00055
00056 static size_t kfilefifo_write(struct KFile *_fd, const void *_buf, size_t size)
00057 {
00058 KFileFifo *fd = KFILEFIFO_CAST(_fd);
00059 const uint8_t *buf = (const uint8_t *)_buf;
00060
00061 while (size-- && !fifo_isfull_locked(fd->fifo))
00062 fifo_push_locked(fd->fifo, *buf++);
00063
00064 return buf - (const uint8_t *)_buf;
00065 }
00066
00067 void kfilefifo_init(KFileFifo *kf, FIFOBuffer *fifo)
00068 {
00069 memset(kf, 0, sizeof(*kf));
00070
00071 kf->fifo = fifo;
00072 kf->fd.read = kfilefifo_read;
00073 kf->fd.write = kfilefifo_write;
00074 DB(kf->fd._type = KFT_KFILEFIFO);
00075 }