#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 */
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.
*/
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);
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;
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.
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.
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.
*/