1 /* 2 This file is part of UFFS, the Ultra-low-cost Flash File System. 3 4 Copyright (C) 2005-2009 Ricky Zheng <[email protected]> 5 6 UFFS is free software; you can redistribute it and/or modify it under 7 the GNU Library General Public License as published by the Free Software 8 Foundation; either version 2 of the License, or (at your option) any 9 later version. 10 11 UFFS is distributed in the hope that it will be useful, but WITHOUT 12 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 or GNU Library General Public License, as applicable, for more details. 15 16 You should have received a copy of the GNU General Public License 17 and GNU Library General Public License along with UFFS; if not, write 18 to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 19 Boston, MA 02110-1301, USA. 20 21 As a special exception, if other files instantiate templates or use 22 macros or inline functions from this file, or you compile this file 23 and link it with other works to produce a work based on this file, 24 this file does not by itself cause the resulting work to be covered 25 by the GNU General Public License. However the source code for this 26 file must still be made available in accordance with section (3) of 27 the GNU General Public License v2. 28 29 This exception does not invalidate any other reasons why a work based 30 on this file might be covered by the GNU General Public License. 31 */ 32 33 /** 34 * \file uffs_device.h 35 * \brief uffs device structures definition 36 * \author Ricky Zheng 37 */ 38 39 #ifndef UFFS_DEVICE_H 40 #define UFFS_DEVICE_H 41 42 #include "uffs/uffs_types.h" 43 #include "uffs/uffs_buf.h" 44 #include "uffs/uffs_blockinfo.h" 45 #include "uffs/uffs_pool.h" 46 #include "uffs/uffs_tree.h" 47 #include "uffs/uffs_mem.h" 48 #include "uffs/uffs_core.h" 49 #include "uffs/uffs_flash.h" 50 51 #ifdef __cplusplus 52 extern "C"{ 53 #endif 54 55 /** 56 * \def MAX_DIRTY_BUF_GROUPS 57 */ 58 #define MAX_DIRTY_BUF_GROUPS 3 59 60 61 /** 62 * \struct uffs_BlockInfoCacheSt 63 * \brief block information structure, used to manager block information caches 64 */ 65 struct uffs_BlockInfoCacheSt { 66 uffs_BlockInfo *head; //!< buffer head of block info(spares) 67 uffs_BlockInfo *tail; //!< buffer tail 68 void *mem_pool; //!< internal memory pool, used for release whole buffer 69 }; 70 71 /** 72 * \struct uffs_PartitionSt 73 * \brief partition basic information 74 */ 75 struct uffs_PartitionSt { 76 u16 start; //!< start block number of partition 77 u16 end; //!< end block number of partition 78 }; 79 80 /** 81 * \struct uffs_LockSt 82 * \brief lock stuffs 83 */ 84 struct uffs_LockSt { 85 OSSEM sem; 86 int task_id; 87 int counter; 88 }; 89 90 /** 91 * \struct uffs_DirtyGroupSt 92 * \brief manager dirty page buffers 93 */ 94 struct uffs_DirtyGroupSt { 95 int count; //!< dirty buffers count 96 int lock; //!< dirty group lock (0: unlocked, >0: locked) 97 uffs_Buf *dirty; //!< dirty buffer list 98 }; 99 100 /** 101 * \struct uffs_PageBufDescSt 102 * \brief uffs page buffers descriptor 103 */ 104 struct uffs_PageBufDescSt { 105 uffs_Buf *head; //!< head of buffers 106 uffs_Buf *tail; //!< tail of buffers 107 struct uffs_DirtyGroupSt dirtyGroup[MAX_DIRTY_BUF_GROUPS]; //!< dirty buffer groups 108 int buf_max; //!< maximum buffers 109 int dirty_buf_max; //!< maximum dirty buffer allowed 110 void *pool; //!< memory pool for buffers 111 }; 112 113 114 /** 115 * \struct uffs_PageCommInfoSt 116 * \brief common data for device, should be initialised at early 117 * \note it is possible that pg_size is smaller than physical page size, but normally they are the same. 118 * \note page data layout: [HEADER] + [DATA] 119 */ 120 struct uffs_PageCommInfoSt { 121 u16 pg_data_size; //!< page data size 122 u16 header_size; //!< header size 123 u16 pg_size; //!< page size 124 }; 125 126 /** 127 * \struct uffs_NewBadBlockSt 128 * \brief holding new discovered bad block 129 */ 130 struct uffs_NewBadBlockSt { 131 u16 block; //!< bad block, FIX ME to process more than one bad block 132 }; 133 134 /** 135 * \struct uffs_FlashStatSt 136 * \typedef uffs_FlashStat 137 * \brief statistic data of flash read/write/erase activities 138 */ 139 typedef struct uffs_FlashStatSt { 140 int block_erase_count; 141 int page_write_count; 142 int page_read_count; 143 int page_header_read_count; 144 int spare_write_count; 145 int spare_read_count; 146 unsigned long io_read; 147 unsigned long io_write; 148 } uffs_FlashStat; 149 150 151 /** 152 * \struct uffs_ConfigSt 153 * \typedef uffs_Config 154 * \brief uffs config parameters 155 */ 156 typedef struct uffs_ConfigSt { 157 int bc_caches; 158 int page_buffers; 159 int dirty_pages; 160 int dirty_groups; 161 int reserved_free_blocks; 162 } uffs_Config; 163 164 165 /** 166 * \struct uffs_DeviceSt 167 * \brief The core data structure of UFFS, all information needed by manipulate UFFS object 168 * \note one partition corresponding one uffs device. 169 */ 170 struct uffs_DeviceSt { 171 URET (*Init)(uffs_Device *dev); //!< low level initialisation 172 URET (*Release)(uffs_Device *dev); //!< low level release 173 void *_private; //!< private data for device 174 175 struct uffs_StorageAttrSt *attr; //!< storage attribute 176 struct uffs_PartitionSt par; //!< partition information 177 struct uffs_FlashOpsSt *ops; //!< flash operations 178 struct uffs_BlockInfoCacheSt bc; //!< block info cache 179 struct uffs_LockSt lock; //!< lock data structure 180 struct uffs_PageBufDescSt buf; //!< page buffers 181 struct uffs_PageCommInfoSt com; //!< common information 182 struct uffs_TreeSt tree; //!< tree list of block 183 struct uffs_NewBadBlockSt bad; //!< new discovered bad block 184 struct uffs_FlashStatSt st; //!< statistic (counters) 185 struct uffs_memAllocatorSt mem; //!< uffs memory allocator 186 struct uffs_ConfigSt cfg; //!< uffs config 187 u32 ref_count; //!< device reference count 188 int dev_num; //!< device number (partition number) 189 }; 190 191 192 /** create the lock for uffs device */ 193 void uffs_DeviceInitLock(uffs_Device *dev); 194 195 /** delete the lock of uffs device */ 196 void uffs_DeviceReleaseLock(uffs_Device *dev); 197 198 /** lock uffs device */ 199 void uffs_DeviceLock(uffs_Device *dev); 200 201 /** unlock uffs device */ 202 void uffs_DeviceUnLock(uffs_Device *dev); 203 204 205 #ifdef __cplusplus 206 } 207 #endif 208 209 210 #endif 211 212