/** * \file * * * \brief KFile interface over a FIFO buffer. * * \author Francesco Sacchi */ #include "kfile_fifo.h" #include "fifobuf.h" #include #include static size_t kfilefifo_read(struct KFile *_fd, void *_buf, size_t size) { KFileFifo *fd = KFILEFIFO_CAST(_fd); uint8_t *buf = (uint8_t *)_buf; while (size-- && !fifo_isempty_locked(fd->fifo)) *buf++ = fifo_pop_locked(fd->fifo); return buf - (uint8_t *)_buf; } static size_t kfilefifo_write(struct KFile *_fd, const void *_buf, size_t size) { KFileFifo *fd = KFILEFIFO_CAST(_fd); const uint8_t *buf = (const uint8_t *)_buf; while (size-- && !fifo_isfull_locked(fd->fifo)) fifo_push_locked(fd->fifo, *buf++); return buf - (const uint8_t *)_buf; } void kfilefifo_init(KFileFifo *kf, FIFOBuffer *fifo) { memset(kf, 0, sizeof(*kf)); kf->fifo = fifo; kf->fd.read = kfilefifo_read; kf->fd.write = kfilefifo_write; DB(kf->fd._type = KFT_KFILEFIFO); }