From 36ba2f39c6edb8358e8395ee346eefb2446e35a9 Mon Sep 17 00:00:00 2001 From: batt Date: Tue, 19 Feb 2008 15:35:36 +0000 Subject: [PATCH] Remove kfile sub-classes aggregation. git-svn-id: https://src.develer.com/svnoss/bertos/trunk@1143 38d2e660-2303-0410-9eaa-f027e97ec537 --- cfg/macros.h | 15 +++++++++++++++ drv/dataflash.h | 5 +++++ drv/ser.h | 6 ++++++ fs/battfs.h | 7 ++++++- kern/kfile.h | 22 +--------------------- 5 files changed, 33 insertions(+), 22 deletions(-) diff --git a/cfg/macros.h b/cfg/macros.h index b3be457f..f0520eff 100644 --- a/cfg/macros.h +++ b/cfg/macros.h @@ -297,5 +297,20 @@ #define ROTL(var, rot) (((var) << (rot)) | ((var) >> ((sizeof(var) * 8) - (rot)))) /*\}*/ +/** + * Make an id from 4 letters, useful for + * file formats and kfile ids. + */ +#define MAKE_ID(a,b,c,d) \ + ( ((uint32_t)(a) << 24) \ + | ((uint32_t)(b) << 16) \ + | ((uint32_t)(c) << 8) \ + | ((uint32_t)(d) << 0) ) + +/** + * Type for id generated by MAKE_ID(). + */ +typedef uint32_t id_t; + #endif /* MACROS_H */ diff --git a/drv/dataflash.h b/drv/dataflash.h index c77cf496..61858167 100644 --- a/drv/dataflash.h +++ b/drv/dataflash.h @@ -93,6 +93,11 @@ typedef struct KFileDataflash dataflash_setCS_t *setCS; ///< Callback used to set CS pin of dataflash. } KFileDataflash; +/** + * ID for dataflash. + */ +#define KFT_DATAFLASH MAKE_ID('D', 'F', 'L', 'H') + /** * Convert + ASSERT from generic KFile to KFileDataflash. */ diff --git a/drv/ser.h b/drv/ser.h index f4edc684..c0f7b8bb 100644 --- a/drv/ser.h +++ b/drv/ser.h @@ -158,6 +158,12 @@ typedef struct KFileSerial Serial *ser; } KFileSerial; +/** + * ID for serial. + */ +#define KFT_SERIAL MAKE_ID('S', 'E', 'R', 'L') + + INLINE KFileSerial * KFILESERIAL(KFile *fd) { ASSERT(fd->_type == KFT_SERIAL); diff --git a/fs/battfs.h b/fs/battfs.h index 0456fcfb..59d8fece 100644 --- a/fs/battfs.h +++ b/fs/battfs.h @@ -207,7 +207,7 @@ typedef struct BattFsSuper disk_size_t disk_size; ///< Size of the disk, in bytes (page_count * page_size). disk_size_t free_bytes; ///< Free space on the disk. - + List file_opened_list; ///< List used to keep trace of open files. /* TODO add other fields. */ } BattFsSuper; @@ -238,6 +238,11 @@ typedef struct KFileBattFs pgcnt_t *start; ///< Pointer to page_array file start position. } KFileBattFs; +/** + * Id for battfs file descriptors. + */ +#define KFT_BATTFS MAKE_ID('B', 'T', 'F', 'S') + /** * Macro used to cast a KFile to a KFileBattFs. * Also perform dynamic type check. diff --git a/kern/kfile.h b/kern/kfile.h index 7d0009f5..60b0ad64 100644 --- a/kern/kfile.h +++ b/kern/kfile.h @@ -164,21 +164,6 @@ typedef int (*ErrorFunc_t) (struct KFile *fd); typedef void (*ClearErrFunc_t) (struct KFile *fd); /* \} */ -/** - * KFile type. - * Used at runtime and in debug mode only to check - * "dynamic casts". - * \note Add here new KFile types. - */ -typedef enum KFileType -{ - KFT_GENERIC, ///< Generic - KFT_SERIAL, ///< Serial driver - KFT_BATTFS, ///< BattFS file - KFT_DATAFLASH, ///< Dataflash - KFT_CNT -} KFileType; - /** * Context data for callback functions which operate on * pseudo files. @@ -194,18 +179,13 @@ typedef struct KFile FlushFunc_t flush; ErrorFunc_t error; ClearErrFunc_t clearerr; - DB(KFileType _type); ///< Used to keep trace, at runtime, of obj type. + DB(id_t _type); ///< Used to keep trace, at runtime, of obj type. /* NOTE: these must _NOT_ be size_t on 16bit CPUs! */ uint32_t seek_pos; uint32_t size; } KFile; -/** - * Check if \a fd is a generic KFile type. - */ -#define KFILE_ASSERT_GENERIC(fd) ASSERT(fd->_type == KFT_GENERIC) - /** * Generic implementation of kfile_seek. */ -- 2.25.1