#include "kfile_debug.h"
-#include <kern/kfile.h>
+#include <io/kfile.h>
#include <string.h>
#ifndef CFG_KFILE_DEBUG
#define CFG_KFILE_DEBUG
-#include <kern/kfile.h>
+#include <io/kfile.h>
/**
* Context for KFile over debug console.
#include <cpu/attr.h>
#include <cpu/power.h>
-#include <kern/kfile.h>
+#include <io/kfile.h>
#include <io/arm.h>
#include <cpu/types.h>
-#include <kern/kfile.h>
+#include <io/kfile.h>
#include <io/arm.h>
#include "spi_dma_at91.h"
#include "hw/hw_spi_dma.h"
-#include <kern/kfile.h>
+#include <io/kfile.h>
#include <struct/fifobuf.h>
#include <struct/kfile_fifo.h>
#include <drv/timer.h>
#ifndef DRV_SPI_DMA_AT91_H
#define DRV_SPI_DMA_AT91_H
-#include <kern/kfile.h>
+#include <io/kfile.h>
typedef struct SpiDmaAt91
{
#include <drv/wdt.h>
#include <drv/flash.h>
-#include <kern/kfile.h>
+#include <io/kfile.h>
#include <avr/io.h>
#include <avr/boot.h>
#include <cfg/compiler.h>
-#include <kern/kfile.h>
+#include <io/kfile.h>
#include <avr/io.h>
#include <cfg/macros.h>
-#include <kern/kfile.h>
+#include <io/kfile.h>
#include <drv/timer.h>
#include <drv/flash.h>
#define FLASH_LM3S_H
#include <cpu/types.h>
-#include <kern/kfile.h>
+#include <io/kfile.h>
/* Flash memory mapping */
#define FLASH_MEM_SIZE 0x40000 //< 256KiB
#define SSI_LM3S_H
#include <cpu/power.h> /* cpu_relax() */
-#include <kern/kfile.h> /* KFile */
+#include <io/kfile.h> /* KFile */
#include <io/lm3s.h>
/**
#include <fs/battfs.h>
-#include <kern/kfile.h>
+#include <io/kfile.h>
#include <cpu/power.h> /* cpu_relax() */
#include <cfg/compiler.h>
-#include <kern/kfile.h>
+#include <io/kfile.h>
#include <fs/battfs.h>
/**
#include <drv/dataflash.h>
#include <kern/proc.h>
-#include <kern/kfile.h>
+#include <io/kfile.h>
#include <string.h>
#include <cfg/compiler.h>
-#include <kern/kfile.h>
+#include <io/kfile.h>
/**
#include <drv/timer.h>
#include <drv/flash25.h>
-#include <kern/kfile.h>
+#include <io/kfile.h>
#include <cpu/power.h> /* cpu_relax() */
#include "cfg/cfg_flash25.h"
#include <cfg/compiler.h>
-#include <kern/kfile.h>
+#include <io/kfile.h>
/**
* Type definition for serial flash memory.
*/
-#include <kern/kfile.h>
+#include <io/kfile.h>
#include <drv/flash25.h>
#include <drv/timer.h>
-#include <kern/kfile.h>
+#include <io/kfile.h>
#include <string.h>
#ifndef DRV_FT245RL_H
#define DRV_FT245RL_H
-#include <kern/kfile.h>
+#include <io/kfile.h>
#include <cfg/compiler.h>
/**
#include <drv/timer.h>
#include <drv/mcp41.h>
-#include <kern/kfile.h>
+#include <io/kfile.h>
static KFile *ch;
#include "hw/mcp41_map.h"
#include <cfg/compiler.h>
-#include <kern/kfile.h>
+#include <io/kfile.h>
#define MCP41_WRITE_DATA 0x11
#define MCP41_HW_MAX 255
#include "sd.h"
#include "hw/hw_sd.h"
-#include <kern/kfile.h>
+#include <io/kfile.h>
#include <drv/timer.h>
#include <fs/fat.h>
#include "cfg/cfg_fat.h"
-#include <kern/kfile.h>
+#include <io/kfile.h>
#include <fs/fatfs/diskio.h>
#ifndef DRV_SER_H
#define DRV_SER_H
-#include <kern/kfile.h>
+#include <io/kfile.h>
#include <struct/fifobuf.h>
#include <cfg/compiler.h>
#include <cfg/compiler.h>
#include <cfg/log.h>
-#include <kern/kfile.h>
+#include <io/kfile.h>
#include <string.h>
#include "hw/hw_sipo.h"
-#include <kern/kfile.h>
+#include <io/kfile.h>
#define SIPO_DATAORDER_START_LSB 1
#define SIPO_DATAORDER_START_MSB 0x80
#include "tlv5618.h"
#include "hw/hw_tlv5618.h"
-#include <kern/kfile.h>
+#include <io/kfile.h>
#include <string.h> //memset
#define DRV_TLV5618_H
#include <cfg/compiler.h>
-#include <kern/kfile.h>
+#include <io/kfile.h>
typedef struct Tlv5618
{
#include <cpu/byteorder.h>
-#include <kern/kfile.h>
+#include <io/kfile.h>
#include <drv/ntc.h> // Macro and data type to manage celsius degree
#include <cpu/types.h>
-#include <kern/kfile.h>
+#include <io/kfile.h>
#include <drv/ntc.h> // Macro and data type to manage celsius degree
#ifndef KFILE_POSIX_H
#define KFILE_POSIX_H
-#include <kern/kfile.h>
+#include <io/kfile.h>
#include <stdio.h>
typedef struct KFilePosix
#include <cpu/types.h> // CPU_BITS_PER_CHAR
#include <algo/rotating_hash.h>
#include <struct/list.h>
-#include <kern/kfile.h>
+#include <io/kfile.h>
#include <io/kblock.h>
typedef uint16_t fill_t; ///< Type for keeping trace of space filled inside a page
#ifndef FS_FAT_H
#define FS_FAT_H
-#include <kern/kfile.h>
+#include <io/kfile.h>
#include "fatfs/ff.h"
typedef struct FatFile
--- /dev/null
+/**
+ * \file
+ * <!--
+ * This file is part of BeRTOS.
+ *
+ * Bertos is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ * As a special exception, you may use this file as part of a free software
+ * library without restriction. Specifically, if other files instantiate
+ * templates or use macros or inline functions from this file, or you compile
+ * this file and link it with other files to produce an executable, this
+ * file does not by itself cause the resulting executable to be covered by
+ * the GNU General Public License. This exception does not however
+ * invalidate any other reasons why the executable file might be covered by
+ * 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 <batt@develer.com>
+ * \author Daniele Basile <asterix@develer.com>
+ */
+
+#include "kfile.h"
+
+#include "cfg/cfg_kfile.h"
+#include <cfg/debug.h>
+#include <cfg/log.h>
+
+#include <drv/timer.h>
+#include <mware/formatwr.h>
+
+#include <string.h>
+
+/*
+ * Sanity check for config parameters required by this module.
+ */
+#if !defined(CONFIG_KFILE_GETS) || ((CONFIG_KFILE_GETS != 0) && CONFIG_KFILE_GETS != 1)
+ #error CONFIG_KFILE_GETS must be set to either 0 or 1 in appconfig.h
+#endif
+#if !defined(CONFIG_PRINTF)
+ #error CONFIG_PRINTF missing in appconfig.h
+#endif
+
+
+/**
+ * Generic putc() implementation using \a fd->write.
+ */
+int kfile_putc(int _c, struct KFile *fd)
+{
+ unsigned char c = (unsigned char)_c;
+
+ if (kfile_write(fd, &c, sizeof(c)) == sizeof(c))
+ return (int)((unsigned char)_c);
+ else
+ return EOF;
+}
+
+/**
+ * Generic getc() implementation using \a fd->read.
+ */
+int kfile_getc(struct KFile *fd)
+{
+ unsigned char c;
+
+ if (kfile_read(fd, &c, sizeof(c)) == sizeof(c))
+ return (int)((unsigned char)c);
+ else
+ return EOF;
+}
+
+#if CONFIG_PRINTF
+/**
+ * Formatted write.
+ */
+int kfile_printf(struct KFile *fd, const char *format, ...)
+{
+ va_list ap;
+ int len;
+
+ va_start(ap, format);
+ len = _formatted_write(format, (void (*)(char, void *))kfile_putc, fd, ap);
+ va_end(ap);
+
+ return len;
+}
+#endif /* CONFIG_PRINTF */
+
+/**
+ * Write a string to kfile \a fd.
+ * \return 0 if OK, EOF in case of error.
+ */
+int kfile_print(struct KFile *fd, const char *s)
+{
+ while (*s)
+ {
+ if (kfile_putc(*s++, fd) == EOF)
+ return EOF;
+ }
+ return 0;
+}
+
+#if CONFIG_KFILE_GETS
+/**
+ * Read a line long at most as size and put it
+ * in buf.
+ * \return number of chars read or EOF in case
+ * of error.
+ */
+int kfile_gets(struct KFile *fd, char *buf, int size)
+{
+ return kfile_gets_echo(fd, buf, size, false);
+}
+
+
+/**
+ * Read a line long at most as size and put it
+ * in buf, with optional echo.
+ *
+ * \return number of chars read, or EOF in case
+ * of error.
+ */
+int kfile_gets_echo(struct KFile *fd, char *buf, int size, bool echo)
+{
+ int i = 0;
+ int c;
+
+ for (;;)
+ {
+ if ((c = kfile_getc(fd)) == EOF)
+ {
+ buf[i] = '\0';
+ return -1;
+ }
+
+ /* FIXME */
+ if (c == '\r' || c == '\n' || i >= size-1)
+ {
+ buf[i] = '\0';
+ if (echo)
+ kfile_print(fd, "\r\n");
+ break;
+ }
+ buf[i++] = c;
+ if (echo)
+ kfile_putc(c, fd);
+ }
+
+ return i;
+}
+#endif /* !CONFIG_KFILE_GETS */
+
+
+/**
+ * Move \a fd file seek position of \a offset bytes from \a whence.
+ *
+ * This is a generic implementation of seek function, you can redefine
+ * it in your local module if needed.
+ */
+kfile_off_t kfile_genericSeek(struct KFile *fd, kfile_off_t offset, KSeekMode whence)
+{
+ kfile_off_t seek_pos;
+
+ switch (whence)
+ {
+
+ case KSM_SEEK_SET:
+ seek_pos = 0;
+ break;
+ case KSM_SEEK_END:
+ seek_pos = fd->size;
+ break;
+ case KSM_SEEK_CUR:
+ seek_pos = fd->seek_pos;
+ break;
+ default:
+ ASSERT(0);
+ return EOF;
+ break;
+ }
+
+ #if LOG_LEVEL >= LOG_LVL_INFO
+ /* Bound check */
+ if (seek_pos + offset > fd->size)
+ LOG_INFO("seek outside EOF\n");
+ #endif
+
+ fd->seek_pos = seek_pos + offset;
+
+ return fd->seek_pos;
+}
+
+/**
+ * Reopen file \a fd.
+ * This is a generic implementation that only flush file
+ * and reset seek_pos to 0.
+ */
+struct KFile * kfile_genericReopen(struct KFile *fd)
+{
+ kfile_flush(fd);
+ kfile_seek(fd, 0, KSM_SEEK_SET);
+ 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;
+}
+
--- /dev/null
+/**
+ * \file
+ * <!--
+ * This file is part of BeRTOS.
+ *
+ * Bertos is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ * As a special exception, you may use this file as part of a free software
+ * library without restriction. Specifically, if other files instantiate
+ * templates or use macros or inline functions from this file, or you compile
+ * this file and link it with other files to produce an executable, this
+ * file does not by itself cause the resulting executable to be covered by
+ * the GNU General Public License. This exception does not however
+ * invalidate any other reasons why the executable file might be covered by
+ * the GNU General Public License.
+ *
+ * Copyright 2004 Develer S.r.l. (http://www.develer.com/)
+ * Copyright 1999, 2000, 2001, 2003 Bernie Innocenti <bernie@codewiz.org>
+ *
+ * -->
+ *
+ * \brief Virtual KFile I/O interface.
+ *
+ * KFile is a simple, generic interface for file I/O. It uses an
+ * object-oriented model to supply a device-neutral interface to
+ * communicate with drivers.
+ *
+ * This module contains only definitions, the instance structure
+ * and the common API.
+ * Each KFile subclass can override one or more methods of the interface,
+ * and can extend the base KFile structure with its own private data.
+ * For instance, a serial driver might implement the KFile interface by
+ * declaring a context structure like this:
+ *
+ * \code
+ * typedef struct Serial
+ * {
+ * // base class instance
+ * KFile fd;
+ *
+ * // private instance data
+ * FIFOBuffer txfifo, rxfifo;
+ * } Serial;
+ * \endcode
+ *
+ * You should also supply a macro for casting KFile to Serial:
+ *
+ * \code
+ * INLINE Serial * SERIAL_CAST(KFile *fd)
+ * {
+ * ASSERT(fd->_type == KFT_SERIAL);
+ * return (Serial *)fd;
+ * }
+ * \endcode
+ *
+ * Then you can implement as many interface functions as needed
+ * and leave the rest to NULL.
+ *
+ * Example implementation of the close KFile method for Serial:
+ *
+ * \code
+ * static int ser_kfile_close(struct KFile *fd)
+ * {
+ * Serial *fds = SERIAL_CAST(fd);
+ * // [driver specific code here]
+ * return 0;
+ * }
+ * \endcode
+ *
+ * The SERIAL_CAST() macro helps ensure that the passed object is
+ * really of type Serial.
+ *
+ * The KFile interface does not supply an open function: this is deliberate,
+ * because in embedded systems each device has its own init parameters.
+ * For the same reason, specific device settings like, for example,
+ * the baudrate, are not part of interface and should be handled by the
+ * driver-specific API.
+ *
+ * \version $Id$
+ * \author Bernie Innocenti <bernie@codewiz.org>
+ * \author Francesco Sacchi <batt@develer.com>
+ * \author Daniele Basile <asterix@develer.com>
+ *
+ * $WIZ$ module_name = "kfile"
+ * $WIZ$ module_configuration = "bertos/cfg/cfg_kfile.h"
+ * $WIZ$ module_depends = "timer", "formatwr"
+ */
+
+#ifndef KERN_KFILE_H
+#define KERN_KFILE_H
+
+#include <cfg/compiler.h>
+#include <cfg/debug.h>
+#include <cfg/macros.h>
+
+/* fwd decl */
+struct KFile;
+
+typedef int32_t kfile_off_t; ///< KFile offset type, used by kfile_seek().
+
+/**
+ * Costants for repositioning read/write file offset.
+ * These are needed because on some embedded platforms
+ * ANSI I/O library may not be present.
+ */
+typedef enum KSeekMode
+{
+ KSM_SEEK_SET, ///< Seek from file beginning.
+ KSM_SEEK_CUR, ///< Seek from file current position.
+ KSM_SEEK_END, ///< Seek from file end.
+} KSeekMode;
+
+/**
+ * Prototypes for KFile access functions.
+ * I/O file functions must be ANSI compliant.
+ * \note A KFile user can choose which function subset to implement,
+ * but has to set to NULL unimplemented features.
+ * \{
+ */
+
+/**
+ * Read from file.
+ * \return the number of bytes read.
+ */
+typedef size_t (*ReadFunc_t) (struct KFile *fd, void *buf, size_t size);
+
+/**
+ * Write to file.
+ * \return the number of bytes written.
+ */
+typedef size_t (*WriteFunc_t) (struct KFile *fd, const void *buf, size_t size);
+
+/**
+ * Seek into file (if seekable).
+ * \return the new file offset or EOF on errors.
+ */
+typedef kfile_off_t (*SeekFunc_t) (struct KFile *fd, kfile_off_t offset, KSeekMode whence);
+
+/**
+ * Close and reopen file \a fd.
+ * The reopening is done with the former file parameters and access modes.
+ */
+typedef struct KFile * (*ReOpenFunc_t) (struct KFile *fd);
+
+/**
+ * Close file.
+ * \return 0 on success, EOF on errors.
+ */
+typedef int (*CloseFunc_t) (struct KFile *fd);
+
+/**
+ * Flush file I/O.
+ * \return 0 on success, EOF on errors.
+ */
+typedef int (*FlushFunc_t) (struct KFile *fd);
+
+/**
+ * Get file error mask.
+ * \return 0 on success or file error code, device specific.
+ */
+typedef int (*ErrorFunc_t) (struct KFile *fd);
+
+/**
+ * Clear errors.
+ */
+typedef void (*ClearErrFunc_t) (struct KFile *fd);
+/* \} */
+
+/**
+ * Context data for callback functions which operate on
+ * pseudo files.
+ *
+ * \note Remember to add the corresponding accessor functions
+ * when extending this interface.
+ */
+typedef struct KFile
+{
+ ReadFunc_t read;
+ WriteFunc_t write;
+ ReOpenFunc_t reopen;
+ CloseFunc_t close;
+ SeekFunc_t seek;
+ FlushFunc_t flush;
+ ErrorFunc_t error;
+ ClearErrFunc_t clearerr;
+ DB(id_t _type); ///< Used to keep track, at runtime, of the class type.
+
+ /* NOTE: these must _NOT_ be size_t on 16bit CPUs! */
+ kfile_off_t seek_pos;
+ kfile_off_t size;
+} KFile;
+
+/**
+ * Generic implementation of kfile_seek.
+ */
+kfile_off_t kfile_genericSeek(struct KFile *fd, kfile_off_t offset, KSeekMode whence);
+
+/**
+ * Generic implementation of kfile_reopen.
+ */
+struct KFile * kfile_genericReopen(struct KFile *fd);
+
+int kfile_genericClose(struct KFile *fd);
+
+int kfile_putc(int c, struct KFile *fd); ///< Generic putc implementation using kfile_write.
+int kfile_getc(struct KFile *fd); ///< Generic getc implementation using kfile_read.
+int kfile_printf(struct KFile *fd, const char *format, ...);
+int kfile_print(struct KFile *fd, const char *s);
+int kfile_gets(struct KFile *fd, char *buf, int size);
+int kfile_gets_echo(struct KFile *fd, char *buf, int size, bool echo);
+void kfile_resync(KFile *fd, mtime_t delay);
+void kfile_init(struct KFile *fd);
+
+/**
+ * Interface functions for KFile access.
+ * \note Remember to change following functions if KFile interface changes.
+ * \{
+ */
+INLINE size_t kfile_read(struct KFile *fd, void *buf, size_t size)
+{
+ ASSERT(fd->read);
+ return fd->read(fd, buf, size);
+}
+
+INLINE size_t kfile_write(struct KFile *fd, const void *buf, size_t size)
+{
+ ASSERT(fd->write);
+ return fd->write(fd, buf, size);
+}
+
+INLINE KFile * kfile_reopen(struct KFile *fd)
+{
+ ASSERT(fd->reopen);
+ return fd->reopen(fd);
+}
+
+INLINE int kfile_close(struct KFile *fd)
+{
+ ASSERT(fd->close);
+ return fd->close(fd);
+}
+
+INLINE kfile_off_t kfile_seek(struct KFile *fd, kfile_off_t offset, KSeekMode whence)
+{
+ ASSERT(fd->seek);
+ return fd->seek(fd, offset, whence);
+}
+
+INLINE int kfile_flush(struct KFile *fd)
+{
+ ASSERT(fd->flush);
+ return fd->flush(fd);
+}
+
+INLINE int kfile_error(struct KFile *fd)
+{
+ ASSERT(fd->error);
+ return fd->error(fd);
+}
+
+INLINE void kfile_clearerr(struct KFile *fd)
+{
+ ASSERT(fd->clearerr);
+ fd->clearerr(fd);
+}
+/* \} */
+
+/**
+ * Kfile test function.
+ */
+int kfile_testSetup(void);
+int kfile_testRun(void);
+int kfile_testRunGeneric(KFile *fd, uint8_t *test_buf, uint8_t *save_buf, size_t size);
+int kfile_testTearDown(void);
+
+
+#endif /* KERN_KFILE_H */
--- /dev/null
+/**
+ * \file
+ * <!--
+ * This file is part of BeRTOS.
+ *
+ * Bertos is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ * As a special exception, you may use this file as part of a free software
+ * library without restriction. Specifically, if other files instantiate
+ * templates or use macros or inline functions from this file, or you compile
+ * this file and link it with other files to produce an executable, this
+ * file does not by itself cause the resulting executable to be covered by
+ * the GNU General Public License. This exception does not however
+ * invalidate any other reasons why the executable file might be covered by
+ * the GNU General Public License.
+ *
+ * Copyright 2007 Develer S.r.l. (http://www.develer.com/)
+ *
+ * -->
+ *
+ * \brief Test suite for virtual KFile I/O interface.
+ *
+ * This module implements a test for some generic I/O interfaces for kfile.
+ *
+ * \version $Id$
+ * \author Francesco Sacchi <batt@develer.com>
+ * \author Daniele Basile <asterix@develer.com>
+ */
+
+
+#include "kfile.h"
+#include <struct/kfile_mem.h>
+
+#include "cfg/cfg_kfile.h"
+#include <cfg/debug.h>
+#include <cfg/test.h>
+#include <cfg/module.h>
+
+// Define logging setting (for cfg/log.h module).
+#define LOG_LEVEL KFILE_LOG_LEVEL
+#define LOG_FORMAT KFILE_LOG_FORMAT
+#include <cfg/log.h>
+
+#include <mware/formatwr.h>
+
+#include <string.h>
+
+MOD_DEFINE(kfile_test);
+
+// Size of the "virtual" disk that
+// we want to test.
+#define BUF_TEST_LEN 3209
+
+// Buffer for test
+uint8_t test_buf[BUF_TEST_LEN];
+uint8_t test_buf_save[BUF_TEST_LEN];
+
+uint8_t test_disk[BUF_TEST_LEN];
+KFileMem mem;
+
+/*
+ * Help function to init disk and the buffers.
+ */
+static void init_testBuf(void)
+{
+
+ kprintf("Init fake buffer..\n");
+ for (int i = 0; i < BUF_TEST_LEN; i++)
+ {
+ test_disk[i] = i;
+ kprintf("%d ", test_disk[i]);
+ }
+ kprintf("\nend\n");
+
+ memset(test_buf, 0, sizeof(test_buf));
+ memset(test_buf_save, 0, sizeof(test_buf_save));
+}
+
+/**
+ * KFile read/write subtest.
+ * Try to write/read in the same \a f file location \a size bytes.
+ * \return true if all is ok, false otherwise
+ * \note Restore file position at exit (if no error)
+ * \note Test buffer \a buf must be filled with
+ * the following statement:
+ * <pre>
+ * buf[i] = i & 0xff
+ * </pre>
+ */
+static bool kfile_rwTest(KFile *f, uint8_t *buf, size_t size)
+{
+ /*
+ * Write test buffer
+ */
+ if (kfile_write(f, buf, size) != size)
+ {
+ LOG_ERR("error writing buf");
+ return false;
+ }
+
+ kfile_seek(f, -(kfile_off_t)size, KSM_SEEK_CUR);
+
+ /*
+ * Reset test buffer
+ */
+ memset(buf, 0, size);
+
+ /*
+ * Read file in test buffer
+ */
+ if (kfile_read(f, buf, size) != size)
+ {
+ LOG_ERR("error reading buf");
+ return false;
+ }
+
+
+ kfile_seek(f, -(kfile_off_t)size, KSM_SEEK_CUR);
+
+ /*
+ * Check test result
+ */
+ for (size_t i = 0; i < size; i++)
+ {
+ if (buf[i] != (i & 0xff))
+ {
+ LOG_ERR("error comparing at index [%d] read [%02x] expected [%02x]\n", i, buf[i], i);
+ return false;
+ }
+ }
+
+ return true;
+}
+
+/**
+ * KFile read/write test.
+ * This function write and read \a test_buf long \a size
+ * on \a fd handler.
+ * \a save_buf can be NULL or a buffer where to save previous file content.
+ */
+int kfile_testRunGeneric(KFile *fd, uint8_t *test_buf, uint8_t *save_buf, size_t size)
+{
+
+ /*
+ * Part of test buf size that you would write.
+ * This var is used in test 3 to check kfile_write
+ * when writing beyond filesize limit.
+ */
+ kfile_off_t len = size / 2;
+
+
+ /* Fill test buffer */
+ for (size_t i = 0; i < size; i++)
+ test_buf[i] = (i & 0xff);
+
+ /*
+ * If necessary, user can save content,
+ * for later restore.
+ */
+ if (save_buf)
+ {
+ LOG_INFO("Saved content..form [%ld] to [%ld]\n", fd->seek_pos, fd->seek_pos + size);
+ kfile_read(fd, save_buf, size);
+ }
+
+ /* TEST 1 BEGIN. */
+ LOG_INFO("Test 1: write from pos 0 to [%ld]\n", (long)size);
+
+ /*
+ * Seek to addr 0.
+ */
+ if (kfile_seek(fd, 0, KSM_SEEK_SET) != 0)
+ goto kfile_test_end;
+
+ /*
+ * Test read/write to address 0..size
+ */
+ if (!kfile_rwTest(fd, test_buf, size))
+ goto kfile_test_end;
+
+ LOG_INFO("Test 1: ok!\n");
+
+ /*
+ * Restore previous read content.
+ */
+ if (save_buf)
+ {
+ kfile_seek(fd, 0, KSM_SEEK_SET);
+
+ if (kfile_write(fd, save_buf, size) != size)
+ goto kfile_test_end;
+
+ LOG_INFO("Restore content..form [%ld] to [%ld]\n", fd->seek_pos, fd->seek_pos + size);
+ }
+ /* TEST 1 END. */
+
+ /* TEST 2 BEGIN. */
+ LOG_INFO("Test 2: write from pos [%ld] to [%ld]\n", fd->size/2 , fd->size/2 + size);
+
+ /*
+ * Go to half test size.
+ */
+ kfile_seek(fd, (fd->size / 2), KSM_SEEK_SET);
+
+ /*
+ * If necessary, user can save content
+ * for later restore.
+ */
+ if (save_buf)
+ {
+ kfile_read(fd, save_buf, size);
+ kfile_seek(fd, -(kfile_off_t)size, KSM_SEEK_CUR);
+ LOG_INFO("Saved content..form [%ld] to [%ld]\n", fd->seek_pos, fd->seek_pos + size);
+ }
+
+ /*
+ * Test read/write to address filesize/2 ... filesize/2 + size
+ */
+ if (!kfile_rwTest(fd, test_buf, size))
+ goto kfile_test_end;
+
+ LOG_INFO("Test 2: ok!\n");
+
+ /*
+ * Restore previous content.
+ */
+ if (save_buf)
+ {
+ kfile_seek(fd, -(kfile_off_t)size, KSM_SEEK_CUR);
+
+ if (kfile_write(fd, save_buf, size) != size)
+ goto kfile_test_end;
+
+ LOG_INFO("Restore content..form [%ld] to [%ld]\n", fd->seek_pos, fd->seek_pos + size);
+ }
+
+ /* TEST 2 END. */
+
+ /* TEST 3 BEGIN. */
+ LOG_INFO("Test 3: write outside of fd->size limit [%ld]\n", fd->size);
+
+ /*
+ * Go to the Flash end
+ */
+ kfile_seek(fd, -len, KSM_SEEK_END);
+
+ /*
+ * If necessary, user can save content,
+ * for later restore.
+ */
+ if (save_buf)
+ {
+ kfile_read(fd, save_buf, len);
+ kfile_seek(fd, -len, KSM_SEEK_CUR);
+ LOG_INFO("Saved content..form [%ld] to [%ld]\n", fd->seek_pos, fd->seek_pos + len);
+ }
+
+ /*
+ * Test read/write to address (filesize - size) ... filesize
+ */
+ if (kfile_rwTest(fd, test_buf, size))
+ goto kfile_test_end;
+
+ kprintf("Test 3: ok!\n");
+
+ /*
+ * Restore previous read content
+ */
+ if (save_buf)
+ {
+ kfile_seek(fd, -len, KSM_SEEK_END);
+
+ if ((kfile_off_t)kfile_write(fd, save_buf, len) != len)
+ goto kfile_test_end;
+
+ LOG_INFO("Restore content..form [%ld] to [%ld]\n", fd->seek_pos, fd->seek_pos + len);
+ }
+
+ /* TEST 3 END. */
+
+ kfile_close(fd);
+ return 0;
+
+kfile_test_end:
+ kfile_close(fd);
+ LOG_ERR("One kfile_test failed!\n");
+ return EOF;
+}
+
+
+
+
+/**
+ * Setup all needed for kfile test
+ */
+int kfile_testSetup(void)
+{
+ MOD_INIT(kfile_test);
+ LOG_INFO("Mod init..ok\n");
+
+ // Init our backend and the buffers
+ kfilemem_init(&mem, test_disk, BUF_TEST_LEN);
+ init_testBuf();
+
+ return 0;
+}
+
+int kfile_testRun(void)
+{
+ return kfile_testRunGeneric(&mem.fd, test_buf, test_buf_save, BUF_TEST_LEN);
+}
+
+/**
+ * End a dataflash Test.
+ * (Unused)
+ */
+int kfile_testTearDown(void)
+{
+ return 0;
+}
+
+TEST_MAIN(kfile);
+
-/**
- * \file
- * <!--
- * This file is part of BeRTOS.
- *
- * Bertos is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
- *
- * As a special exception, you may use this file as part of a free software
- * library without restriction. Specifically, if other files instantiate
- * templates or use macros or inline functions from this file, or you compile
- * this file and link it with other files to produce an executable, this
- * file does not by itself cause the resulting executable to be covered by
- * the GNU General Public License. This exception does not however
- * invalidate any other reasons why the executable file might be covered by
- * 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 <batt@develer.com>
- * \author Daniele Basile <asterix@develer.com>
- */
-
-#include "kfile.h"
-
-#include "cfg/cfg_kfile.h"
-#include <cfg/debug.h>
-#include <cfg/log.h>
-
-#include <drv/timer.h>
-#include <mware/formatwr.h>
-
-#include <string.h>
-
-/*
- * Sanity check for config parameters required by this module.
- */
-#if !defined(CONFIG_KFILE_GETS) || ((CONFIG_KFILE_GETS != 0) && CONFIG_KFILE_GETS != 1)
- #error CONFIG_KFILE_GETS must be set to either 0 or 1 in appconfig.h
-#endif
-#if !defined(CONFIG_PRINTF)
- #error CONFIG_PRINTF missing in appconfig.h
-#endif
-
-
-/**
- * Generic putc() implementation using \a fd->write.
- */
-int kfile_putc(int _c, struct KFile *fd)
-{
- unsigned char c = (unsigned char)_c;
-
- if (kfile_write(fd, &c, sizeof(c)) == sizeof(c))
- return (int)((unsigned char)_c);
- else
- return EOF;
-}
-
-/**
- * Generic getc() implementation using \a fd->read.
- */
-int kfile_getc(struct KFile *fd)
-{
- unsigned char c;
-
- if (kfile_read(fd, &c, sizeof(c)) == sizeof(c))
- return (int)((unsigned char)c);
- else
- return EOF;
-}
-
-#if CONFIG_PRINTF
-/**
- * Formatted write.
- */
-int kfile_printf(struct KFile *fd, const char *format, ...)
-{
- va_list ap;
- int len;
-
- va_start(ap, format);
- len = _formatted_write(format, (void (*)(char, void *))kfile_putc, fd, ap);
- va_end(ap);
-
- return len;
-}
-#endif /* CONFIG_PRINTF */
-
-/**
- * Write a string to kfile \a fd.
- * \return 0 if OK, EOF in case of error.
- */
-int kfile_print(struct KFile *fd, const char *s)
-{
- while (*s)
- {
- if (kfile_putc(*s++, fd) == EOF)
- return EOF;
- }
- return 0;
-}
-
-#if CONFIG_KFILE_GETS
-/**
- * Read a line long at most as size and put it
- * in buf.
- * \return number of chars read or EOF in case
- * of error.
- */
-int kfile_gets(struct KFile *fd, char *buf, int size)
-{
- return kfile_gets_echo(fd, buf, size, false);
-}
-
-
-/**
- * Read a line long at most as size and put it
- * in buf, with optional echo.
- *
- * \return number of chars read, or EOF in case
- * of error.
- */
-int kfile_gets_echo(struct KFile *fd, char *buf, int size, bool echo)
-{
- int i = 0;
- int c;
-
- for (;;)
- {
- if ((c = kfile_getc(fd)) == EOF)
- {
- buf[i] = '\0';
- return -1;
- }
-
- /* FIXME */
- if (c == '\r' || c == '\n' || i >= size-1)
- {
- buf[i] = '\0';
- if (echo)
- kfile_print(fd, "\r\n");
- break;
- }
- buf[i++] = c;
- if (echo)
- kfile_putc(c, fd);
- }
-
- return i;
-}
-#endif /* !CONFIG_KFILE_GETS */
-
-
-/**
- * Move \a fd file seek position of \a offset bytes from \a whence.
- *
- * This is a generic implementation of seek function, you can redefine
- * it in your local module if needed.
- */
-kfile_off_t kfile_genericSeek(struct KFile *fd, kfile_off_t offset, KSeekMode whence)
-{
- kfile_off_t seek_pos;
-
- switch (whence)
- {
-
- case KSM_SEEK_SET:
- seek_pos = 0;
- break;
- case KSM_SEEK_END:
- seek_pos = fd->size;
- break;
- case KSM_SEEK_CUR:
- seek_pos = fd->seek_pos;
- break;
- default:
- ASSERT(0);
- return EOF;
- break;
- }
-
- #if LOG_LEVEL >= LOG_LVL_INFO
- /* Bound check */
- if (seek_pos + offset > fd->size)
- LOG_INFO("seek outside EOF\n");
- #endif
-
- fd->seek_pos = seek_pos + offset;
-
- return fd->seek_pos;
-}
-
-/**
- * Reopen file \a fd.
- * This is a generic implementation that only flush file
- * and reset seek_pos to 0.
- */
-struct KFile * kfile_genericReopen(struct KFile *fd)
-{
- kfile_flush(fd);
- kfile_seek(fd, 0, KSM_SEEK_SET);
- 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;
-}
+// notest: all
+#warning "This file is deprecated, use the new io/kfile.c"
+#error analc
+#include <io/kfile.c>
-/**
- * \file
- * <!--
- * This file is part of BeRTOS.
- *
- * Bertos is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
- *
- * As a special exception, you may use this file as part of a free software
- * library without restriction. Specifically, if other files instantiate
- * templates or use macros or inline functions from this file, or you compile
- * this file and link it with other files to produce an executable, this
- * file does not by itself cause the resulting executable to be covered by
- * the GNU General Public License. This exception does not however
- * invalidate any other reasons why the executable file might be covered by
- * the GNU General Public License.
- *
- * Copyright 2004 Develer S.r.l. (http://www.develer.com/)
- * Copyright 1999, 2000, 2001, 2003 Bernie Innocenti <bernie@codewiz.org>
- *
- * -->
- *
- * \brief Virtual KFile I/O interface.
- *
- * KFile is a simple, generic interface for file I/O. It uses an
- * object-oriented model to supply a device-neutral interface to
- * communicate with drivers.
- *
- * This module contains only definitions, the instance structure
- * and the common API.
- * Each KFile subclass can override one or more methods of the interface,
- * and can extend the base KFile structure with its own private data.
- * For instance, a serial driver might implement the KFile interface by
- * declaring a context structure like this:
- *
- * \code
- * typedef struct Serial
- * {
- * // base class instance
- * KFile fd;
- *
- * // private instance data
- * FIFOBuffer txfifo, rxfifo;
- * } Serial;
- * \endcode
- *
- * You should also supply a macro for casting KFile to Serial:
- *
- * \code
- * INLINE Serial * SERIAL_CAST(KFile *fd)
- * {
- * ASSERT(fd->_type == KFT_SERIAL);
- * return (Serial *)fd;
- * }
- * \endcode
- *
- * Then you can implement as many interface functions as needed
- * and leave the rest to NULL.
- *
- * Example implementation of the close KFile method for Serial:
- *
- * \code
- * static int ser_kfile_close(struct KFile *fd)
- * {
- * Serial *fds = SERIAL_CAST(fd);
- * // [driver specific code here]
- * return 0;
- * }
- * \endcode
- *
- * The SERIAL_CAST() macro helps ensure that the passed object is
- * really of type Serial.
- *
- * The KFile interface does not supply an open function: this is deliberate,
- * because in embedded systems each device has its own init parameters.
- * For the same reason, specific device settings like, for example,
- * the baudrate, are not part of interface and should be handled by the
- * driver-specific API.
- *
- * \version $Id$
- * \author Bernie Innocenti <bernie@codewiz.org>
- * \author Francesco Sacchi <batt@develer.com>
- * \author Daniele Basile <asterix@develer.com>
- *
- * $WIZ$ module_name = "kfile"
- * $WIZ$ module_configuration = "bertos/cfg/cfg_kfile.h"
- * $WIZ$ module_depends = "timer", "formatwr"
- */
-
-#ifndef KERN_KFILE_H
-#define KERN_KFILE_H
-
-#include <cfg/compiler.h>
-#include <cfg/debug.h>
-#include <cfg/macros.h>
-
-/* fwd decl */
-struct KFile;
-
-typedef int32_t kfile_off_t; ///< KFile offset type, used by kfile_seek().
-
-/**
- * Costants for repositioning read/write file offset.
- * These are needed because on some embedded platforms
- * ANSI I/O library may not be present.
- */
-typedef enum KSeekMode
-{
- KSM_SEEK_SET, ///< Seek from file beginning.
- KSM_SEEK_CUR, ///< Seek from file current position.
- KSM_SEEK_END, ///< Seek from file end.
-} KSeekMode;
-
-/**
- * Prototypes for KFile access functions.
- * I/O file functions must be ANSI compliant.
- * \note A KFile user can choose which function subset to implement,
- * but has to set to NULL unimplemented features.
- * \{
- */
-
-/**
- * Read from file.
- * \return the number of bytes read.
- */
-typedef size_t (*ReadFunc_t) (struct KFile *fd, void *buf, size_t size);
-
-/**
- * Write to file.
- * \return the number of bytes written.
- */
-typedef size_t (*WriteFunc_t) (struct KFile *fd, const void *buf, size_t size);
-
-/**
- * Seek into file (if seekable).
- * \return the new file offset or EOF on errors.
- */
-typedef kfile_off_t (*SeekFunc_t) (struct KFile *fd, kfile_off_t offset, KSeekMode whence);
-
-/**
- * Close and reopen file \a fd.
- * The reopening is done with the former file parameters and access modes.
- */
-typedef struct KFile * (*ReOpenFunc_t) (struct KFile *fd);
-
-/**
- * Close file.
- * \return 0 on success, EOF on errors.
- */
-typedef int (*CloseFunc_t) (struct KFile *fd);
-
-/**
- * Flush file I/O.
- * \return 0 on success, EOF on errors.
- */
-typedef int (*FlushFunc_t) (struct KFile *fd);
-
-/**
- * Get file error mask.
- * \return 0 on success or file error code, device specific.
- */
-typedef int (*ErrorFunc_t) (struct KFile *fd);
-
-/**
- * Clear errors.
- */
-typedef void (*ClearErrFunc_t) (struct KFile *fd);
-/* \} */
-
-/**
- * Context data for callback functions which operate on
- * pseudo files.
- *
- * \note Remember to add the corresponding accessor functions
- * when extending this interface.
- */
-typedef struct KFile
-{
- ReadFunc_t read;
- WriteFunc_t write;
- ReOpenFunc_t reopen;
- CloseFunc_t close;
- SeekFunc_t seek;
- FlushFunc_t flush;
- ErrorFunc_t error;
- ClearErrFunc_t clearerr;
- DB(id_t _type); ///< Used to keep track, at runtime, of the class type.
-
- /* NOTE: these must _NOT_ be size_t on 16bit CPUs! */
- kfile_off_t seek_pos;
- kfile_off_t size;
-} KFile;
-
-/**
- * Generic implementation of kfile_seek.
- */
-kfile_off_t kfile_genericSeek(struct KFile *fd, kfile_off_t offset, KSeekMode whence);
-
-/**
- * Generic implementation of kfile_reopen.
- */
-struct KFile * kfile_genericReopen(struct KFile *fd);
-
-int kfile_genericClose(struct KFile *fd);
-
-int kfile_putc(int c, struct KFile *fd); ///< Generic putc implementation using kfile_write.
-int kfile_getc(struct KFile *fd); ///< Generic getc implementation using kfile_read.
-int kfile_printf(struct KFile *fd, const char *format, ...);
-int kfile_print(struct KFile *fd, const char *s);
-int kfile_gets(struct KFile *fd, char *buf, int size);
-int kfile_gets_echo(struct KFile *fd, char *buf, int size, bool echo);
-void kfile_resync(KFile *fd, mtime_t delay);
-void kfile_init(struct KFile *fd);
-
-/**
- * Interface functions for KFile access.
- * \note Remember to change following functions if KFile interface changes.
- * \{
- */
-INLINE size_t kfile_read(struct KFile *fd, void *buf, size_t size)
-{
- ASSERT(fd->read);
- return fd->read(fd, buf, size);
-}
-
-INLINE size_t kfile_write(struct KFile *fd, const void *buf, size_t size)
-{
- ASSERT(fd->write);
- return fd->write(fd, buf, size);
-}
-
-INLINE KFile * kfile_reopen(struct KFile *fd)
-{
- ASSERT(fd->reopen);
- return fd->reopen(fd);
-}
-
-INLINE int kfile_close(struct KFile *fd)
-{
- ASSERT(fd->close);
- return fd->close(fd);
-}
-
-INLINE kfile_off_t kfile_seek(struct KFile *fd, kfile_off_t offset, KSeekMode whence)
-{
- ASSERT(fd->seek);
- return fd->seek(fd, offset, whence);
-}
-
-INLINE int kfile_flush(struct KFile *fd)
-{
- ASSERT(fd->flush);
- return fd->flush(fd);
-}
-
-INLINE int kfile_error(struct KFile *fd)
-{
- ASSERT(fd->error);
- return fd->error(fd);
-}
-
-INLINE void kfile_clearerr(struct KFile *fd)
-{
- ASSERT(fd->clearerr);
- fd->clearerr(fd);
-}
-/* \} */
-
-/**
- * Kfile test function.
- */
-int kfile_testSetup(void);
-int kfile_testRun(void);
-int kfile_testRunGeneric(KFile *fd, uint8_t *test_buf, uint8_t *save_buf, size_t size);
-int kfile_testTearDown(void);
-
-
-#endif /* KERN_KFILE_H */
+#warning "This file is deprecated, include the new <io/kfile.h>"
+#error anal
+#include <io/kfile.h>
+++ /dev/null
-/**
- * \file
- * <!--
- * This file is part of BeRTOS.
- *
- * Bertos is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
- *
- * As a special exception, you may use this file as part of a free software
- * library without restriction. Specifically, if other files instantiate
- * templates or use macros or inline functions from this file, or you compile
- * this file and link it with other files to produce an executable, this
- * file does not by itself cause the resulting executable to be covered by
- * the GNU General Public License. This exception does not however
- * invalidate any other reasons why the executable file might be covered by
- * the GNU General Public License.
- *
- * Copyright 2007 Develer S.r.l. (http://www.develer.com/)
- *
- * -->
- *
- * \brief Test suite for virtual KFile I/O interface.
- *
- * This module implements a test for some generic I/O interfaces for kfile.
- *
- * \version $Id$
- * \author Francesco Sacchi <batt@develer.com>
- * \author Daniele Basile <asterix@develer.com>
- */
-
-
-#include "kfile.h"
-#include <struct/kfile_mem.h>
-
-#include "cfg/cfg_kfile.h"
-#include <cfg/debug.h>
-#include <cfg/test.h>
-#include <cfg/module.h>
-
-// Define logging setting (for cfg/log.h module).
-#define LOG_LEVEL KFILE_LOG_LEVEL
-#define LOG_FORMAT KFILE_LOG_FORMAT
-#include <cfg/log.h>
-
-#include <mware/formatwr.h>
-
-#include <string.h>
-
-MOD_DEFINE(kfile_test);
-
-// Size of the "virtual" disk that
-// we want to test.
-#define BUF_TEST_LEN 3209
-
-// Buffer for test
-uint8_t test_buf[BUF_TEST_LEN];
-uint8_t test_buf_save[BUF_TEST_LEN];
-
-uint8_t test_disk[BUF_TEST_LEN];
-KFileMem mem;
-
-/*
- * Help function to init disk and the buffers.
- */
-static void init_testBuf(void)
-{
-
- kprintf("Init fake buffer..\n");
- for (int i = 0; i < BUF_TEST_LEN; i++)
- {
- test_disk[i] = i;
- kprintf("%d ", test_disk[i]);
- }
- kprintf("\nend\n");
-
- memset(test_buf, 0, sizeof(test_buf));
- memset(test_buf_save, 0, sizeof(test_buf_save));
-}
-
-/**
- * KFile read/write subtest.
- * Try to write/read in the same \a f file location \a size bytes.
- * \return true if all is ok, false otherwise
- * \note Restore file position at exit (if no error)
- * \note Test buffer \a buf must be filled with
- * the following statement:
- * <pre>
- * buf[i] = i & 0xff
- * </pre>
- */
-static bool kfile_rwTest(KFile *f, uint8_t *buf, size_t size)
-{
- /*
- * Write test buffer
- */
- if (kfile_write(f, buf, size) != size)
- {
- LOG_ERR("error writing buf");
- return false;
- }
-
- kfile_seek(f, -(kfile_off_t)size, KSM_SEEK_CUR);
-
- /*
- * Reset test buffer
- */
- memset(buf, 0, size);
-
- /*
- * Read file in test buffer
- */
- if (kfile_read(f, buf, size) != size)
- {
- LOG_ERR("error reading buf");
- return false;
- }
-
-
- kfile_seek(f, -(kfile_off_t)size, KSM_SEEK_CUR);
-
- /*
- * Check test result
- */
- for (size_t i = 0; i < size; i++)
- {
- if (buf[i] != (i & 0xff))
- {
- LOG_ERR("error comparing at index [%d] read [%02x] expected [%02x]\n", i, buf[i], i);
- return false;
- }
- }
-
- return true;
-}
-
-/**
- * KFile read/write test.
- * This function write and read \a test_buf long \a size
- * on \a fd handler.
- * \a save_buf can be NULL or a buffer where to save previous file content.
- */
-int kfile_testRunGeneric(KFile *fd, uint8_t *test_buf, uint8_t *save_buf, size_t size)
-{
-
- /*
- * Part of test buf size that you would write.
- * This var is used in test 3 to check kfile_write
- * when writing beyond filesize limit.
- */
- kfile_off_t len = size / 2;
-
-
- /* Fill test buffer */
- for (size_t i = 0; i < size; i++)
- test_buf[i] = (i & 0xff);
-
- /*
- * If necessary, user can save content,
- * for later restore.
- */
- if (save_buf)
- {
- LOG_INFO("Saved content..form [%ld] to [%ld]\n", fd->seek_pos, fd->seek_pos + size);
- kfile_read(fd, save_buf, size);
- }
-
- /* TEST 1 BEGIN. */
- LOG_INFO("Test 1: write from pos 0 to [%ld]\n", (long)size);
-
- /*
- * Seek to addr 0.
- */
- if (kfile_seek(fd, 0, KSM_SEEK_SET) != 0)
- goto kfile_test_end;
-
- /*
- * Test read/write to address 0..size
- */
- if (!kfile_rwTest(fd, test_buf, size))
- goto kfile_test_end;
-
- LOG_INFO("Test 1: ok!\n");
-
- /*
- * Restore previous read content.
- */
- if (save_buf)
- {
- kfile_seek(fd, 0, KSM_SEEK_SET);
-
- if (kfile_write(fd, save_buf, size) != size)
- goto kfile_test_end;
-
- LOG_INFO("Restore content..form [%ld] to [%ld]\n", fd->seek_pos, fd->seek_pos + size);
- }
- /* TEST 1 END. */
-
- /* TEST 2 BEGIN. */
- LOG_INFO("Test 2: write from pos [%ld] to [%ld]\n", fd->size/2 , fd->size/2 + size);
-
- /*
- * Go to half test size.
- */
- kfile_seek(fd, (fd->size / 2), KSM_SEEK_SET);
-
- /*
- * If necessary, user can save content
- * for later restore.
- */
- if (save_buf)
- {
- kfile_read(fd, save_buf, size);
- kfile_seek(fd, -(kfile_off_t)size, KSM_SEEK_CUR);
- LOG_INFO("Saved content..form [%ld] to [%ld]\n", fd->seek_pos, fd->seek_pos + size);
- }
-
- /*
- * Test read/write to address filesize/2 ... filesize/2 + size
- */
- if (!kfile_rwTest(fd, test_buf, size))
- goto kfile_test_end;
-
- LOG_INFO("Test 2: ok!\n");
-
- /*
- * Restore previous content.
- */
- if (save_buf)
- {
- kfile_seek(fd, -(kfile_off_t)size, KSM_SEEK_CUR);
-
- if (kfile_write(fd, save_buf, size) != size)
- goto kfile_test_end;
-
- LOG_INFO("Restore content..form [%ld] to [%ld]\n", fd->seek_pos, fd->seek_pos + size);
- }
-
- /* TEST 2 END. */
-
- /* TEST 3 BEGIN. */
- LOG_INFO("Test 3: write outside of fd->size limit [%ld]\n", fd->size);
-
- /*
- * Go to the Flash end
- */
- kfile_seek(fd, -len, KSM_SEEK_END);
-
- /*
- * If necessary, user can save content,
- * for later restore.
- */
- if (save_buf)
- {
- kfile_read(fd, save_buf, len);
- kfile_seek(fd, -len, KSM_SEEK_CUR);
- LOG_INFO("Saved content..form [%ld] to [%ld]\n", fd->seek_pos, fd->seek_pos + len);
- }
-
- /*
- * Test read/write to address (filesize - size) ... filesize
- */
- if (kfile_rwTest(fd, test_buf, size))
- goto kfile_test_end;
-
- kprintf("Test 3: ok!\n");
-
- /*
- * Restore previous read content
- */
- if (save_buf)
- {
- kfile_seek(fd, -len, KSM_SEEK_END);
-
- if ((kfile_off_t)kfile_write(fd, save_buf, len) != len)
- goto kfile_test_end;
-
- LOG_INFO("Restore content..form [%ld] to [%ld]\n", fd->seek_pos, fd->seek_pos + len);
- }
-
- /* TEST 3 END. */
-
- kfile_close(fd);
- return 0;
-
-kfile_test_end:
- kfile_close(fd);
- LOG_ERR("One kfile_test failed!\n");
- return EOF;
-}
-
-
-
-
-/**
- * Setup all needed for kfile test
- */
-int kfile_testSetup(void)
-{
- MOD_INIT(kfile_test);
- LOG_INFO("Mod init..ok\n");
-
- // Init our backend and the buffers
- kfilemem_init(&mem, test_disk, BUF_TEST_LEN);
- init_testBuf();
-
- return 0;
-}
-
-int kfile_testRun(void)
-{
- return kfile_testRunGeneric(&mem.fd, test_buf, test_buf_save, BUF_TEST_LEN);
-}
-
-/**
- * End a dataflash Test.
- * (Unused)
- */
-int kfile_testTearDown(void)
-{
- return 0;
-}
-
-TEST_MAIN(kfile);
-
#ifndef INI_READER_H
#define INI_READER_H
-#include <kern/kfile.h>
+#include <io/kfile.h>
/**
* \brief Returns the value for the given string in char* format.
#include "cfg/cfg_parser.h"
-#include <kern/kfile.h>
+#include <io/kfile.h>
#include <struct/hashtable.h>
#include <stdlib.h> // atol(), NULL
#include "cfg/cfg_afsk.h"
#include "hw/hw_afsk.h"
-#include <kern/kfile.h>
+#include <io/kfile.h>
#include <cfg/compiler.h>
#include <struct/fifobuf.h>
#include "cfg/cfg_ax25.h"
#include <cfg/compiler.h>
-#include <kern/kfile.h>
+#include <io/kfile.h>
/**
* Maximum size of a AX25 frame.
#include <cfg/log.h>
#include <cfg/macros.h>
-#include <kern/kfile.h>
+#include <io/kfile.h>
#include <string.h>
/**
#include <cfg/cfg_keytag.h>
-#include <kern/kfile.h>
+#include <io/kfile.h>
/**
#include <net/nmeap/inc/nmeap.h>
-#include <kern/kfile.h>
+#include <io/kfile.h>
#include <time.h>
#include <cfg/debug.h>
#include <cfg/macros.h>
-#include <kern/kfile.h>
+#include <io/kfile.h>
#include <cpu/byteorder.h>
#include <algo/rotating_hash.h>
-#include <kern/kfile.h>
+#include <io/kfile.h>
/**
* pocketBus special characters definitions.
#define NET_XMODEM_H
#include <cfg/compiler.h>
-#include <kern/kfile.h>
+#include <io/kfile.h>
/**
* Called to know if we want to abort data tranfer.
#include "kfile_fifo.h"
#include "fifobuf.h"
-#include <kern/kfile.h>
+#include <io/kfile.h>
#include <string.h>
#define STRUCT_KFILE_FIFO
#include "fifobuf.h"
-#include <kern/kfile.h>
+#include <io/kfile.h>
typedef struct KFileFifo
{
#include "kfile_mem.h"
-#include <kern/kfile.h>
+#include <io/kfile.h>
#include <string.h>
#ifndef STRUCT_KFILE_MEM
#define STRUCT_KFILE_MEM
-#include <kern/kfile.h>
+#include <io/kfile.h>
/**
* Context for KFile over memory buffer.
#include <cfg/compiler.h>
#include <cfg/debug.h>
-#include <kern/kfile.h>
+#include <io/kfile.h>
#include <stdlib.h>
#include <string.h>
#include <drv/sipo.h>
-#include <kern/kfile.h>
+#include <io/kfile.h>
void protocol_init(KFile *fd);
void protocol_run(KFile *fd);
bertos/algo/ramp.c
bertos/drv/kdebug.c
bertos/drv/timer.c
- bertos/kern/kfile.c
bertos/kern/monitor.c
bertos/kern/proc.c
bertos/kern/signal.c
bertos/io/kblock.c
bertos/io/kblock_ram.c
bertos/io/kblock_file.c
+ bertos/io/kfile.c
"
buildout='/dev/null'