Contiki 2.5
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 #if COFFEE_FILES==1 //1=eeprom for static file system
51 #define COFFEE_AVR_EEPROM 1
52 #define COFFEE_STATIC 1
53 #elif COFFEE_FILES==2 //2=eeprom for full file system
54 #define COFFEE_AVR_EEPROM 1
55 #elif COFFEE_FILES==3 //3=program flash for static file system
56 #define COFFEE_AVR_FLASH 1
57 #define COFFEE_STATIC 1
58 #elif COFFEE_FILES==4 //4=program flash with full file system
59 #define COFFEE_AVR_FLASH 1
60 #else
61 #define COFFEE_AVR_EXTERNAL 1
62 #endif
63 
64 #ifdef COFFEE_AVR_EEPROM
65 #include "dev/eeprom.h"
66 //1284p EEPROM has 512 pages of 8 bytes each = 4KB
67 
68 #if COFFEE_ADDRESS==DEFAULT //Make can pass starting address with COFFEE_ADDRESS=0xnnnnnnnn
69 #undef COFFEE_ADDRESS
70 #ifdef CFS_EEPROM_CONF_OFFSET //Else use the platform default
71 #define COFFEE_ADDRESS CFS_EEPROM_CONF_OFFSET
72 #else //Use zero if no default defined
73 #define COFFEE_ADDRESS 0
74 #endif
75 #endif
76 
77 /* Byte page size, starting address, and size of the file system */
78 #define COFFEE_PAGE_SIZE 16UL
79 #define COFFEE_START COFFEE_ADDRESS
80 #define COFFEE_SIZE ((3 * 1024U) - COFFEE_START)
81 /* These must agree with the parameters passed to makefsdata */
82 #define COFFEE_SECTOR_SIZE (COFFEE_PAGE_SIZE*4)
83 #define COFFEE_NAME_LENGTH 16
84 /* These are used internally by the coffee file system */
85 #define COFFEE_MAX_OPEN_FILES 4
86 #define COFFEE_FD_SET_SIZE 8
87 #define COFFEE_LOG_TABLE_LIMIT 16
88 #define COFFEE_DYN_SIZE (COFFEE_PAGE_SIZE * 4)
89 #define COFFEE_LOG_SIZE 128
90 
91 typedef int16_t coffee_page_t;
92 typedef uint16_t coffee_offset_t;
93 
94 #define COFFEE_ERASE(sector) avr_eeprom_erase(sector)
95 void avr_eeprom_erase(uint16_t sector);
96 
97 #define COFFEE_WRITE(buf, size, offset) \
98  eeprom_write(COFFEE_START + (offset), (unsigned char *)(buf), (size))
99 
100 #define COFFEE_READ(buf, size, offset) \
101  eeprom_read (COFFEE_START + (offset), (unsigned char *)(buf), (size))
102 
103 #endif /* COFFEE_AVR_EEPROM */
104 
105 #ifdef COFFEE_AVR_FLASH
106 /* 1284p PROGMEM has 512 pages of 256 bytes each = 128KB
107  * Writing to the last 32 NRRW pages will halt the CPU.
108  * Take care not to overwrite the .bootloader section...
109  */
110 
111 /* Byte page size, starting address on page boundary, and size of the file system */
112 #define COFFEE_PAGE_SIZE (2*SPM_PAGESIZE)
113 #ifndef COFFEE_ADDRESS //Make can pass starting address with COFFEE_ADDRESS=0xnnnnnnnn, default is 64KB for webserver
114 #define COFFEE_ADDRESS 0x10000
115 #endif
116 #define COFFEE_PAGES (512-(COFFEE_ADDRESS/COFFEE_PAGE_SIZE)-32)
117 #define COFFEE_START (COFFEE_ADDRESS & ~(COFFEE_PAGE_SIZE-1))
118 //#define COFFEE_START (COFFEE_PAGE_SIZE*COFFEE_PAGES)
119 #define COFFEE_SIZE (COFFEE_PAGES*COFFEE_PAGE_SIZE)
120 
121 /* These must agree with the parameters passed to makefsdata */
122 #define COFFEE_SECTOR_SIZE (COFFEE_PAGE_SIZE*1)
123 #define COFFEE_NAME_LENGTH 16
124 
125 /* These are used internally by the AVR flash read routines */
126 /* Word reads are faster but take 130 bytes more PROGMEM */
127 #define FLASH_WORD_READS 1
128 /* 1=Slower reads, but no page writes after erase and 18 bytes less PROGMEM. Best for dynamic file system */
129 #define FLASH_COMPLEMENT_DATA 1
130 
131 /* These are used internally by the coffee file system */
132 /* Micro logs are not needed for single page sectors */
133 #define COFFEE_MAX_OPEN_FILES 4
134 #define COFFEE_FD_SET_SIZE 8
135 #define COFFEE_LOG_TABLE_LIMIT 16
136 #define COFFEE_DYN_SIZE (COFFEE_PAGE_SIZE*1)
137 #define COFFEE_MICRO_LOGS 0
138 #define COFFEE_LOG_SIZE 128
139 
140 /* coffee_page_t is used for page and sector numbering
141  * uint8_t can handle 511 pages.
142  * cfs_offset_t is used for full byte addresses
143  * If CFS_CONF_OFFSET_TYPE is not defined it defaults to int.
144  * uint16_t can handle up to a 65535 byte file system.
145  */
146 #define coffee_page_t uint8_t
147 #define CFS_CONF_OFFSET_TYPE uint16_t
148 
149 
150 #define COFFEE_WRITE(buf, size, offset) \
151  avr_flash_write(offset, (uint8_t *) buf, size)
152 
153 #define COFFEE_READ(buf, size, offset) \
154  avr_flash_read(offset, (uint8_t *) buf, size)
155 
156 #define COFFEE_ERASE(sector) avr_flash_erase(sector)
157 
158 void avr_flash_erase(coffee_page_t sector);
159 void avr_flash_read (CFS_CONF_OFFSET_TYPE addr, uint8_t *buf, CFS_CONF_OFFSET_TYPE size);
160 void avr_flash_write(CFS_CONF_OFFSET_TYPE addr, uint8_t *buf, CFS_CONF_OFFSET_TYPE size);
161 
162 #define avr_httpd_fs_cpy(dest,addr,size) avr_flash_read((CFS_CONF_OFFSET_TYPE) addr, (uint8_t *)dest, (CFS_CONF_OFFSET_TYPE) size)
163 char avr_httpd_fs_getchar(char *addr);
164 char * avr_httpd_fs_strchr (char *ram, int character);
165 int avr_httpd_fs_strcmp (char *addr,char *ram);
166 
167 
168 #endif /* COFFEE_AVR_FLASH */
169 
170 
171 #ifdef COFFEE_AVR_EXTERNAL
172 
173 /* Byte page size, starting address on page boundary, and size of the file system */
174 #define COFFEE_PAGE_SIZE 528UL
175 #ifndef COFFEE_ADDRESS
176 #define COFFEE_ADDRESS 0x0
177 #endif
178 #define COFFEE_PAGES 4096UL
179 #define COFFEE_START (COFFEE_ADDRESS)
180 #define COFFEE_SIZE 2162688UL
181 
182 /* These must agree with the parameters passed to makefsdata */
183 #define COFFEE_SECTOR_SIZE COFFEE_PAGE_SIZE
184 #define COFFEE_NAME_LENGTH 16
185 
186 /* These are used internally by the coffee file system */
187 /* Micro logs are not needed for single page sectors */
188 #define COFFEE_MAX_OPEN_FILES 6
189 #define COFFEE_FD_SET_SIZE 8
190 #define COFFEE_LOG_TABLE_LIMIT 16
191 #define COFFEE_DYN_SIZE (COFFEE_PAGE_SIZE*1)
192 #define COFFEE_MICRO_LOGS 0
193 #define COFFEE_LOG_SIZE 128
194 
195 /* coffee_page_t is used for page and sector numbering
196  * uint8_t can handle 511 pages.
197  * cfs_offset_t is used for full byte addresses
198  * If CFS_CONF_OFFSET_TYPE is not defined it defaults to int.
199  * uint16_t can handle up to a 65535 byte file system.
200  */
201 #define coffee_page_t uint16_t
202 #define CFS_CONF_OFFSET_TYPE uint32_t
203 
204 #define COFFEE_WRITE(buf, size, offset) \
205  external_flash_write((CFS_CONF_OFFSET_TYPE) offset, (uint8_t *) buf, (CFS_CONF_OFFSET_TYPE) size)
206 
207 #define COFFEE_READ(buf, size, offset) \
208  external_flash_read((CFS_CONF_OFFSET_TYPE) offset, (uint8_t *) buf, (CFS_CONF_OFFSET_TYPE) size)
209 
210 #define COFFEE_ERASE(sector) \
211  external_flash_erase((coffee_page_t) sector)
212 
213 void external_flash_write_page(coffee_page_t page, CFS_CONF_OFFSET_TYPE offset, uint8_t * buf, CFS_CONF_OFFSET_TYPE size);
214 
215 void external_flash_write(CFS_CONF_OFFSET_TYPE addr, uint8_t *buf, CFS_CONF_OFFSET_TYPE size);
216 
217 void external_flash_read(CFS_CONF_OFFSET_TYPE addr, uint8_t *buf, CFS_CONF_OFFSET_TYPE size);
218 
219 void external_flash_erase(coffee_page_t sector);
220 
221 #endif /* COFFEE_AVR_EXTERNAL */
222 
223 int coffee_file_test(void);
224 #endif /* !COFFEE_ARCH_H */