comparison src/cs/drivers/drv_app/ffs/board/drv.h @ 0:b6a5e36de839

src/cs: initial import from Magnetite
author Mychaela Falconia <falcon@freecalypso.org>
date Sun, 15 Jul 2018 04:39:26 +0000
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:b6a5e36de839
1 /******************************************************************************
2 * Flash File System (ffs)
3 * Idea, design and coding by Mads Meisner-Jensen, mmj@ti.com
4 *
5 * ffs low level flash driver
6 *
7 * $Id: drv.h 1.15.1.25.1.1.1.20 Mon, 17 Nov 2003 08:51:37 +0100 tsj $
8 *
9 ******************************************************************************/
10
11 #ifndef TARGET
12 #include "ffs.cfg"
13 #endif
14
15 #if (TARGET == 1)
16 #include "chipset.cfg"
17 #endif
18
19
20 /******************************************************************************
21 * Compile constants
22 ******************************************************************************/
23
24 // FFS driver version (in four-digit BCD format). Format is MMID, where MM
25 // is major revision number, incremented e.g. for major revision or support
26 // for new flash family/driver. I is minor revision that is incremented for
27 // minor changes or when a bug is corrected. D is incremented when support
28 // of another device is added.
29 #define FFS_DRV_VERSION ((uint16) 0x1011)
30
31 // Default Allocation granularity of ffs data sectors (as power of two)
32 #define FFS_ATOM_LOG2 4
33
34
35 /******************************************************************************
36 * Macros
37 ******************************************************************************/
38
39 // Convert between address and block index. Only works if all blocks are the
40 // same size!
41 #define block2addr(block) (dev.base + dev.binfo[block].offset)
42
43 // Note that it is *VERY* important that pointers to hardware and flash are
44 // declared volatile, otherwise the compiler optimizes some reads and writes
45 // out and this results in non-working code!
46 #define FLASH_WRITE_HALFWORD(addr, data) *(volatile uint16 *) (addr) = (data)
47 #define FLASH_READ_HALFWORD(addr) *((volatile uint16 *) (addr))
48
49 #if (TARGET == 1)
50
51 #include "memif/mem.h"
52 #if (CHIPSET == 12)
53 #include "sys_inth.h"
54 #else
55 #include "inth/inth.h"
56 #endif
57
58 #if (CHIPSET == 3)
59 #define INT_REQUESTED (*(volatile uint16 *) INTH_IT_REG) & \
60 ~(*(volatile uint16 *) INTH_MASK_REG)
61 #elif (CHIPSET == 4 || CHIPSET == 5 || CHIPSET == 6 || CHIPSET == 7 || CHIPSET == 8 || CHIPSET == 9 || CHIPSET == 10 || CHIPSET == 11)
62 #define INT_REQUESTED ((*(volatile uint16 *) INTH_IT_REG1) & \
63 ~(*(volatile uint16 *) INTH_MASK_REG1)) || \
64 ((*(volatile uint16 *) INTH_IT_REG2) & \
65 ~(*(volatile uint16 *) INTH_MASK_REG2))
66 #elif (CHIPSET == 12)
67 #define INT_REQUESTED ((*(volatile uint16 *) C_INTH_IT_REG1) & \
68 ~(*(volatile uint16 *) C_INTH_MASK_REG1)) || \
69 ((*(volatile uint16 *) C_INTH_IT_REG2) & \
70 ~(*(volatile uint16 *) C_INTH_MASK_REG2))
71 #endif
72 #endif // (TARGET == 1)
73
74
75 /******************************************************************************
76 * Types
77 ******************************************************************************/
78
79 // Flash driver identifiers.
80 enum FFS_DRIVER {
81 FFS_DRIVER_NULL = 0, // Null driver
82
83 FFS_DRIVER_AMD = 2, // AMD dual/multi-bank driver
84 FFS_DRIVER_AMD_SB = 3, // AMD single-bank driver
85
86 FFS_DRIVER_SST = 8, // SST dual/multi-bank driver
87 FFS_DRIVER_SST_SB = 9, // SST single-bank driver
88
89 FFS_DRIVER_INTEL = 16, // Intel dual/multi-bank driver
90 FFS_DRIVER_INTEL_SB = 17, // Intel single-bank driver
91
92 FFS_DRIVER_AMD_PSEUDO_SB = 32, // Test driver
93 FFS_DRIVER_TEST = 34, // Test driver
94
95 FFS_DRIVER_RAM = 64 // Ram driver
96 };
97
98
99 // Manufacturer identifiers. These should never have to be changed. They are
100 // ordered in alphabetically ascending order.
101 enum FFS_MANUFACTURER {
102 MANUFACT_AMD = 0x01,
103 MANUFACT_ATMEL = 0x1F,
104 MANUFACT_FUJITSU = 0x04,
105 MANUFACT_INTEL = 0x89,
106 MANUFACT_MXIC = 0xC2,
107 MANUFACT_SAMSUNG = 0xEC,
108 MANUFACT_SHARP = 0xB0,
109 MANUFACT_SST = 0xBF,
110 MANUFACT_TOSHIBA = 0x98,
111 MANUFACT_RAM = 0xFE, // Ram
112 MANUFACT_TEST = 0x54 // 'T'est manufacturer
113 };
114
115
116 // Flash block information for one ffs block (flash sector). Note that the
117 // ffs block definition might be of a smaller size then the physical flash
118 // sector. The ffs blocks must be defined in ascending order of addresses.
119 struct block_info_s {
120 uint32 offset;
121 uint8 size_ld; // log2 of block size
122 uint8 unused1;
123 uint8 unused2;
124 uint8 unused3;
125 };
126
127
128 // General flash information for one flash device
129 struct flash_info_s {
130 const struct block_info_s *binfo; // block info array for this device
131 char *base; // base flash address of ffs blocks
132 uint16 manufact; // read with flash A0 = 0
133 uint16 device; // read with flash A0 = 1
134 uint8 driver; // flash driver type
135 uint8 numblocks; // number of blocks defined for use by ffs
136 };
137 extern const struct flash_info_s flash_info[];
138
139 enum DEVICE_STATE {
140 DEV_READ,
141 DEV_ERASE,
142 DEV_ERASE_SUSPEND,
143 DEV_WRITE
144 };
145
146
147 // Note that it is *VERY* important that pointers to hardware and flash are
148 // declared volatile, otherwise the compiler optimizes some reads and writes
149 // out and this results in non-working code!
150 struct dev_s {
151 char *base; // base flash address of ffs blocks
152 struct block_info_s *binfo;
153 uint16 manufact;
154 uint16 device;
155 volatile uint16 *addr; // address being written or erased
156 uint16 data; // data currently being written (dev.state = WRITE)
157 uint32 blocksize;
158 uint8 blocksize_ld;
159 uint8 atomlog2;
160 uint8 driver;
161 uint8 state; // state of device (DEVICE_STATE)
162 uint8 numblocks;
163 uint8 atomsize;
164 uint8 atomnotmask;
165 };
166 extern struct dev_s dev;
167
168
169 // Flash low level driver function pointers
170 struct ffsdrv_s {
171 int (* init)(void);
172 void (* erase)(uint8 block);
173 void (* write_halfword)(volatile uint16 *dst, uint16 value);
174 void (* write)(void *dst, const void *src, uint16 size);
175 void (* write_end)(void);
176 void (* erase_suspend)(void);
177 void (* erase_resume)(void);
178 };
179 extern struct ffsdrv_s ffsdrv;
180
181
182 /******************************************************************************
183 * Function Prototypes
184 ******************************************************************************/
185
186 void ffsdrv_write_byte(void *dst, uint8 value);
187 effs_t ffsdrv_init(void);
188
189 extern int ffs_ram_image_address;