X-Git-Url: https://codewiz.org/gitweb?a=blobdiff_plain;f=bertos%2Fkern%2Fkfile.c;h=d98f15484ef6a3a7c71c1832f5b7c9d95c91892a;hb=35be7aa348f671b0ed50ee43d903444edc4892af;hp=1ec3266488e4970d1ec611c4d8e6594d4cd8a5b1;hpb=791e167e053bdd9250d34a9a5ccae6ccde4d6679;p=bertos.git diff --git a/bertos/kern/kfile.c b/bertos/kern/kfile.c index 1ec32664..d98f1548 100644 --- a/bertos/kern/kfile.c +++ b/bertos/kern/kfile.c @@ -27,24 +27,26 @@ * the GNU General Public License. * * Copyright 2007 Develer S.r.l. (http://www.develer.com/) - * * --> * * \brief Virtual KFile I/O interface. + * * This module implements some generic I/O interfaces for kfile. * * \version $Id$ * \author Francesco Sacchi * \author Daniele Basile - * */ - #include "kfile.h" -#include +#include "cfg/cfg_kfile.h" #include +#include + +#include #include + #include /* @@ -174,7 +176,7 @@ int kfile_gets_echo(struct KFile *fd, char *buf, int size, bool echo) */ kfile_off_t kfile_genericSeek(struct KFile *fd, kfile_off_t offset, KSeekMode whence) { - uint32_t seek_pos; + kfile_off_t seek_pos; switch (whence) { @@ -194,12 +196,11 @@ kfile_off_t kfile_genericSeek(struct KFile *fd, kfile_off_t offset, KSeekMode wh break; } + #if LOG_LEVEL >= LOG_LVL_INFO /* Bound check */ if (seek_pos + offset > fd->size) - { - ASSERT(0); - return EOF; - } + LOG_INFO("seek outside EOF\n"); + #endif fd->seek_pos = seek_pos + offset; @@ -218,4 +219,66 @@ struct KFile * kfile_genericReopen(struct KFile *fd) return fd; } +/** + * Close file \a fd. + * This is a generic implementation that only return 0. + */ +int kfile_genericClose(UNUSED_ARG(struct KFile *, fd)) +{ + return 0; +}; + + +/** + * Discard input to resynchronize with remote end. + * + * Discard incoming data until the kfile_getc stops receiving + * characters for at least \a delay milliseconds. + * + * \note If the timeout occur, we reset the error before to + * quit. + */ +void kfile_resync(KFile *fd, mtime_t delay) +{ + ticks_t start_time = timer_clock(); + for(;;) + { + if(kfile_getc(fd) != EOF) + start_time = timer_clock(); + + if ((timer_clock() - start_time) > ms_to_ticks(delay)) + { + kfile_clearerr(fd); + break; + } + + } +} + +/** + * Stub function that does nothing. + * This is a generic implementation that only return 0. + */ +static int kfile_generic(UNUSED_ARG(struct KFile *, fd)) +{ + return 0; +}; + + +/** + * Base class KFile constructor. + */ +void kfile_init(struct KFile *fd) +{ + ASSERT(fd); + memset(fd, 0, sizeof(*fd)); + fd->clearerr = (ClearErrFunc_t)kfile_generic; + fd->close = kfile_genericClose; + fd->error = kfile_generic; + fd->flush = kfile_generic; + fd->read = (ReadFunc_t)kfile_generic; + fd->reopen = kfile_genericReopen; + fd->seek = kfile_genericSeek; + fd->write = (WriteFunc_t)kfile_generic; +}