Contiki-Inga 3.x
cfs-coffee-arch.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2008, Swedish Institute of Computer Science
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  * notice, this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright
11  * notice, this list of conditions and the following disclaimer in the
12  * documentation and/or other materials provided with the distribution.
13  * 3. Neither the name of the Institute nor the names of its contributors
14  * may be used to endorse or promote products derived from this software
15  * without specific prior written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
18  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20  * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
21  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27  * SUCH DAMAGE.
28  *
29  * This file is part of the Contiki operating system.
30  *
31  */
32 
33 /**
34  * \file
35  * Coffee architecture-dependent header for the AVR-Raven 1284p platform.
36  * The 1284p has 4KB of onboard EEPROM and 128KB of program flash.
37  * \author
38  * Frederic Thepaut <frederic.thepaut@inooi.com>
39  * David Kopf <dak664@embarqmail.com>
40  */
41 
42 #ifndef CFS_COFFEE_ARCH_H
43 #define CFS_COFFEE_ARCH_H
44 
45 #include "contiki-conf.h"
46 
47 //Currently you may choose just one of the following for the coffee file sytem
48 //A static file sysstem allows file rewrites but no extensions or new files
49 //This allows a static linked list to index into the file system
50 #ifndef COFFEE_DEVICE
51 #define COFFEE_DEVICE 3
52 #endif
53 
54 #if COFFEE_DEVICE==1 //1=eeprom for static file system
55 #define COFFEE_INGA_EEPROM 1
56 #define COFFEE_STATIC 1
57 #elif COFFEE_DEVICE==2 //2=eeprom for full file system
58 #define COFFEE_INGA_EEPROM 1
59 #elif COFFEE_DEVICE==3 //3=program flash for static file system
60 #define COFFEE_INGA_FLASH 1
61 #define COFFEE_STATIC 1
62 #elif COFFEE_DEVICE==4 //4=program flash with full file system
63 #define COFFEE_INGA_FLASH 1
64 #elif COFFEE_DEVICE==5 //5=use external onboard flash with full file system
65 #define COFFEE_INGA_EXTERNAL 1
66 #elif COFFEE_DEVICE==6 //6=sdcard flash for full file system
67 #define COFFEE_INGA_SDCARD 1
68 #endif
69 
70 #ifdef COFFEE_INGA_EEPROM
71 #include "dev/eeprom.h"
72 //1284p EEPROM has 512 pages of 8 bytes each = 4KB
73 
74 #if COFFEE_ADDRESS==DEFAULT //Make can pass starting address with COFFEE_ADDRESS=0xnnnnnnnn
75 #undef COFFEE_ADDRESS
76 #ifdef CFS_EEPROM_CONF_OFFSET //Else use the platform default
77 #define COFFEE_ADDRESS CFS_EEPROM_CONF_OFFSET
78 #else //Use zero if no default defined
79 #define COFFEE_ADDRESS 0
80 #endif
81 #endif
82 
83 /* Byte page size, starting address, and size of the file system */
84 #define COFFEE_PAGE_SIZE 16UL
85 #define COFFEE_START COFFEE_ADDRESS
86 #define COFFEE_SIZE ((3 * 1024U) - COFFEE_START)
87 /* These must agree with the parameters passed to makefsdata */
88 #define COFFEE_SECTOR_SIZE (COFFEE_PAGE_SIZE*4)
89 #define COFFEE_NAME_LENGTH 16
90 /* These are used internally by the coffee file system */
91 #define COFFEE_MAX_OPEN_FILES 4
92 #define COFFEE_FD_SET_SIZE 8
93 #define COFFEE_LOG_TABLE_LIMIT 16
94 #define COFFEE_DYN_SIZE (COFFEE_PAGE_SIZE * 4)
95 #define COFFEE_LOG_SIZE 128
96 
97 typedef int16_t coffee_page_t;
98 typedef uint16_t coffee_offset_t;
99 
100 #define COFFEE_ERASE(sector) avr_eeprom_erase(sector)
101 void avr_eeprom_erase(uint16_t sector);
102 
103 #define COFFEE_WRITE(buf, size, offset) \
104  eeprom_write(COFFEE_START + (offset), (unsigned char *)(buf), (size))
105 
106 #define COFFEE_READ(buf, size, offset) \
107  eeprom_read (COFFEE_START + (offset), (unsigned char *)(buf), (size))
108 
109 
110 #elif defined COFFEE_INGA_FLASH /* COFFEE_INGA_EEPROM */
111 /* 1284p PROGMEM has 512 pages of 256 bytes each = 128KB
112  * Writing to the last 32 NRRW pages will halt the CPU.
113  * Take care not to overwrite the .bootloader section...
114  */
115 
116 /* Byte page size, starting address on page boundary, and size of the file system */
117 #define COFFEE_PAGE_SIZE (2*SPM_PAGESIZE)
118 #ifndef COFFEE_ADDRESS //Make can pass starting address with COFFEE_ADDRESS=0xnnnnnnnn, default is 64KB for webserver
119 #define COFFEE_ADDRESS 0x10000
120 #endif
121 #define COFFEE_PAGES (512-(COFFEE_ADDRESS/COFFEE_PAGE_SIZE)-32) /* COFFEE_ADDRESS undefined */
122 #define COFFEE_START (COFFEE_ADDRESS & ~(COFFEE_PAGE_SIZE-1))
123 //#define COFFEE_START (COFFEE_PAGE_SIZE*COFFEE_PAGES)
124 #define COFFEE_SIZE (COFFEE_PAGES*COFFEE_PAGE_SIZE) /* XXX */
125 
126 /* These must agree with the parameters passed to makefsdata */
127 #define COFFEE_SECTOR_SIZE (COFFEE_PAGE_SIZE*1)
128 #define COFFEE_NAME_LENGTH 16
129 
130 /* These are used internally by the AVR flash read routines */
131 /* Word reads are faster but take 130 bytes more PROGMEM */
132 #define FLASH_WORD_READS 1
133 /* 1=Slower reads, but no page writes after erase and 18 bytes less PROGMEM. Best for dynamic file system */
134 #define FLASH_COMPLEMENT_DATA 1
135 
136 /* These are used internally by the coffee file system */
137 /* Micro logs are not needed for single page sectors */
138 #define COFFEE_MAX_OPEN_FILES 4
139 #define COFFEE_FD_SET_SIZE 8
140 #define COFFEE_LOG_TABLE_LIMIT 16
141 #define COFFEE_DYN_SIZE (COFFEE_PAGE_SIZE*1)
142 #define COFFEE_MICRO_LOGS 0
143 #define COFFEE_LOG_SIZE 128
144 
145 /* coffee_page_t is used for page and sector numbering
146  * uint8_t can handle 511 pages.
147  * cfs_offset_t is used for full byte addresses
148  * If CFS_CONF_OFFSET_TYPE is not defined it defaults to int.
149  * uint16_t can handle up to a 65535 byte file system.
150  */
151 #define coffee_page_t uint8_t
152 #define CFS_CONF_OFFSET_TYPE uint16_t
153 
154 
155 #define COFFEE_WRITE(buf, size, offset) \
156  avr_flash_write(offset, (uint8_t *) buf, size)
157 
158 #define COFFEE_READ(buf, size, offset) \
159  avr_flash_read(offset, (uint8_t *) buf, size)
160 
161 #define COFFEE_ERASE(sector) avr_flash_erase(sector)
162 
163 void avr_flash_erase(coffee_page_t sector);
164 void avr_flash_read (CFS_CONF_OFFSET_TYPE addr, uint8_t *buf, CFS_CONF_OFFSET_TYPE size);
165 void avr_flash_write(CFS_CONF_OFFSET_TYPE addr, uint8_t *buf, CFS_CONF_OFFSET_TYPE size);
166 
167 
168 #elif defined COFFEE_INGA_EXTERNAL /* COFFEE_INGA_FLASH */
169 
170 /* Byte page size, starting address on page boundary, and size of the file system */
171 #define COFFEE_PAGE_SIZE 528UL
172 #ifndef COFFEE_ADDRESS
173 #define COFFEE_ADDRESS 0x0
174 #endif
175 #define COFFEE_PAGES 4096UL
176 #define COFFEE_START (COFFEE_ADDRESS)
177 #define COFFEE_SIZE 2162688UL
178 
179 /* These must agree with the parameters passed to makefsdata */
180 #define COFFEE_SECTOR_SIZE COFFEE_PAGE_SIZE
181 #define COFFEE_NAME_LENGTH 16
182 
183 /* These are used internally by the coffee file system */
184 /* Micro logs are not needed for single page sectors */
185 #define COFFEE_MAX_OPEN_FILES 6
186 #define COFFEE_FD_SET_SIZE 8
187 #define COFFEE_LOG_TABLE_LIMIT 16
188 #define COFFEE_DYN_SIZE (COFFEE_PAGE_SIZE*1)
189 #define COFFEE_MICRO_LOGS 0
190 #define COFFEE_LOG_SIZE 128
191 
192 /* coffee_page_t is used for page and sector numbering
193  * uint8_t can handle 511 pages.
194  * cfs_offset_t is used for full byte addresses
195  * If CFS_CONF_OFFSET_TYPE is not defined it defaults to int.
196  * uint16_t can handle up to a 65535 byte file system.
197  */
198 #define coffee_page_t uint16_t
199 #define CFS_CONF_OFFSET_TYPE uint32_t
200 
201 #define COFFEE_WRITE(buf, size, offset) \
202  external_flash_write((CFS_CONF_OFFSET_TYPE) offset, (uint8_t *) buf, (CFS_CONF_OFFSET_TYPE) size)
203 
204 #define COFFEE_READ(buf, size, offset) \
205  external_flash_read((CFS_CONF_OFFSET_TYPE) offset, (uint8_t *) buf, (CFS_CONF_OFFSET_TYPE) size)
206 
207 #define COFFEE_ERASE(sector) \
208  external_flash_erase((coffee_page_t) sector)
209 
210 void external_flash_write_page(coffee_page_t page, CFS_CONF_OFFSET_TYPE offset, uint8_t * buf, CFS_CONF_OFFSET_TYPE size);
211 
212 void external_flash_write(CFS_CONF_OFFSET_TYPE addr, uint8_t *buf, CFS_CONF_OFFSET_TYPE size);
213 
214 void external_flash_read(CFS_CONF_OFFSET_TYPE addr, uint8_t *buf, CFS_CONF_OFFSET_TYPE size);
215 
216 void external_flash_erase(coffee_page_t sector);
217 
218 
219 #elif defined COFFEE_INGA_SDCARD /* COFFEE_INGA_EXTERNAL */
220 /* Byte page size, starting address on page boundary, and size of the file system */
221 #define COFFEE_PAGE_SIZE 512
222 #ifndef COFFEE_ADDRESS
223 #define COFFEE_ADDRESS 0x0
224 #endif
225 #define COFFEE_PAGES 500UL
226 #define COFFEE_START (COFFEE_ADDRESS)
227 #define COFFEE_SIZE (COFFEE_PAGES * COFFEE_PAGE_SIZE)
228 
229 /* These must agree with the parameters passed to makefsdata */
230 #define COFFEE_SECTOR_SIZE COFFEE_PAGE_SIZE
231 #define COFFEE_NAME_LENGTH 16
232 
233 /* These are used internally by the coffee file system */
234 /* Micro logs are not needed for single page sectors */
235 #define COFFEE_MAX_OPEN_FILES 6
236 #define COFFEE_FD_SET_SIZE 8
237 #define COFFEE_LOG_TABLE_LIMIT 16
238 #define COFFEE_DYN_SIZE (COFFEE_PAGE_SIZE*1)
239 #define COFFEE_MICRO_LOGS 0
240 #define COFFEE_LOG_SIZE 128
241 
242 /* coffee_page_t is used for page and sector numbering
243  * uint8_t can handle 511 pages.
244  * cfs_offset_t is used for full byte addresses
245  * If CFS_CONF_OFFSET_TYPE is not defined it defaults to int.
246  * uint16_t can handle up to a 65535 byte file system.
247  */
248 #define coffee_page_t uint32_t
249 #define CFS_CONF_OFFSET_TYPE uint32_t
250 
251 #define COFFEE_WRITE(buf, size, offset) \
252  sd_write(offset, (uint8_t *) buf, size)
253 
254 #define COFFEE_READ(buf, size, offset) \
255  sd_read(offset, (uint8_t *) buf, size)
256 
257 #define COFFEE_ERASE(sector) \
258  sd_erase(sector)
259 
260 void sd_write(CFS_CONF_OFFSET_TYPE addr, uint8_t *buf, CFS_CONF_OFFSET_TYPE size);
261 
262 void sd_read(CFS_CONF_OFFSET_TYPE addr, uint8_t *buf, CFS_CONF_OFFSET_TYPE size);
263 
264 void sd_erase(coffee_page_t sector);
265 
266 #else /* COFFEE_INGA_SDCARD */
267 #error No coffee device defined
268 #endif /* COFFEE_INGA_SDCARD */
269 
270 int coffee_file_test(void);
271 #endif /* !COFFEE_ARCH_H */