From: batt Date: Fri, 16 Apr 2010 22:44:16 +0000 (+0000) Subject: New module: kfile_debug. Now you can redirect output to the debug console. X-Git-Tag: 2.5.0~465 X-Git-Url: https://codewiz.org/gitweb?a=commitdiff_plain;h=74c7bb68260444eee2831f758b1a9296d6d4ac4e;p=bertos.git New module: kfile_debug. Now you can redirect output to the debug console. git-svn-id: https://src.develer.com/svnoss/bertos/trunk@3443 38d2e660-2303-0410-9eaa-f027e97ec537 --- diff --git a/bertos/cfg/kfile_debug.c b/bertos/cfg/kfile_debug.c new file mode 100644 index 00000000..e358c485 --- /dev/null +++ b/bertos/cfg/kfile_debug.c @@ -0,0 +1,63 @@ +/** + * \file + * + * + * \brief KFile interface over debug. + * + * \author Francesco Sacchi + */ + +#include "kfile_debug.h" + +#include + +#include + + +static size_t kfiledebug_write(struct KFile *_fd, const void *buf, size_t size) +{ + KFILEDEBUG_CAST(_fd); + + kprintf("%.*s", size, (const char *)buf); + + return size; +} + +void kfiledebug_init(KFileDebug *kd) +{ + ASSERT(kd); + + memset(kd, 0, sizeof(*kd)); + + kfile_init(&kd->fd); + kd->fd.write = kfiledebug_write; + DB(kd->fd._type = KFT_KFILEDEBUG); +} diff --git a/bertos/cfg/kfile_debug.h b/bertos/cfg/kfile_debug.h new file mode 100644 index 00000000..4cd31ddf --- /dev/null +++ b/bertos/cfg/kfile_debug.h @@ -0,0 +1,76 @@ +/** + * \file + * + * + * \brief KFile interface over a debug console. + * + * + * \author Francesco Sacchi + * + * $WIZ$ module_name = "kfiledebug" + * $WIZ$ module_depends = "kfile" + */ + +#ifndef CFG_KFILE_DEBUG +#define CFG_KFILE_DEBUG + +#include + +/** + * Context for KFile over debug console. + */ +typedef struct KFileDebug +{ + KFile fd; ///< KFile base class +} KFileDebug; + +/** + * ID for KFileDebug. + */ +#define KFT_KFILEDEBUG MAKE_ID('K', 'D', 'B', 'G') + +/** + * Convert + ASSERT from generic KFile to KFileDebug. + */ +INLINE KFileDebug * KFILEDEBUG_CAST(KFile *fd) +{ + ASSERT(fd->_type == KFT_KFILEDEBUG); + return (KFileDebug *)fd; +} + +/** + * Initialize KFileMem struct. + * + * \param km Interface to initialize. + */ +void kfiledebug_init(KFileDebug *km); + +#endif /* CFG_KFILE_DEBUG */