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 #else //4=program flash with full file system
59 #define COFFEE_AVR_FLASH 1
60 #endif
61 
62 #ifdef COFFEE_AVR_EEPROM
63 #include "dev/eeprom.h"
64 //1284p EEPROM has 512 pages of 8 bytes each = 4KB
65 
66 #if COFFEE_ADDRESS==DEFAULT //Make can pass starting address with COFFEE_ADDRESS=0xnnnnnnnn
67 #undef COFFEE_ADDRESS
68 #ifdef CFS_EEPROM_CONF_OFFSET //Else use the platform default
69 #define COFFEE_ADDRESS CFS_EEPROM_CONF_OFFSET
70 #else //Use zero if no default defined
71 #define COFFEE_ADDRESS 0
72 #endif
73 #endif
74 
75 /* Byte page size, starting address, and size of the file system */
76 #define COFFEE_PAGE_SIZE 16UL
77 #define COFFEE_START COFFEE_ADDRESS
78 #define COFFEE_SIZE ((3 * 1024U) - COFFEE_START)
79 /* These must agree with the parameters passed to makefsdata */
80 #define COFFEE_SECTOR_SIZE (COFFEE_PAGE_SIZE*4)
81 #define COFFEE_NAME_LENGTH 16
82 /* These are used internally by the coffee file system */
83 #define COFFEE_MAX_OPEN_FILES 4
84 #define COFFEE_FD_SET_SIZE 8
85 #define COFFEE_LOG_TABLE_LIMIT 16
86 #define COFFEE_DYN_SIZE (COFFEE_PAGE_SIZE * 4)
87 #define COFFEE_LOG_SIZE 128
88 
89 typedef int16_t coffee_page_t;
90 typedef uint16_t coffee_offset_t;
91 
92 #define COFFEE_ERASE(sector) avr_eeprom_erase(sector)
93 void avr_eeprom_erase(uint16_t sector);
94 
95 #define COFFEE_WRITE(buf, size, offset) \
96  eeprom_write(COFFEE_START + (offset), (unsigned char *)(buf), (size))
97 
98 #define COFFEE_READ(buf, size, offset) \
99  eeprom_read (COFFEE_START + (offset), (unsigned char *)(buf), (size))
100 
101 #endif /* COFFEE_AVR_EEPROM */
102 
103 #ifdef COFFEE_AVR_FLASH
104 /* 1284p PROGMEM has 512 pages of 256 bytes each = 128KB
105  * Writing to the last 32 NRRW pages will halt the CPU.
106  * Take care not to overwrite the .bootloader section...
107  */
108 
109 /* Byte page size, starting address on page boundary, and size of the file system */
110 #define COFFEE_PAGE_SIZE (2*SPM_PAGESIZE)
111 #ifndef COFFEE_ADDRESS //Make can pass starting address with COFFEE_ADDRESS=0xnnnnnnnn, default is 64KB for webserver
112 #define COFFEE_ADDRESS 0x10000
113 #endif
114 #define COFFEE_PAGES (512-(COFFEE_ADDRESS/COFFEE_PAGE_SIZE)-32)
115 #define COFFEE_START (COFFEE_ADDRESS & ~(COFFEE_PAGE_SIZE-1))
116 //#define COFFEE_START (COFFEE_PAGE_SIZE*COFFEE_PAGES)
117 #define COFFEE_SIZE (COFFEE_PAGES*COFFEE_PAGE_SIZE)
118 
119 /* These must agree with the parameters passed to makefsdata */
120 #define COFFEE_SECTOR_SIZE (COFFEE_PAGE_SIZE*1)
121 #define COFFEE_NAME_LENGTH 16
122 
123 /* These are used internally by the AVR flash read routines */
124 /* Word reads are faster but take 130 bytes more PROGMEM */
125 #define FLASH_WORD_READS 1
126 /* 1=Slower reads, but no page writes after erase and 18 bytes less PROGMEM. Best for dynamic file system */
127 #define FLASH_COMPLEMENT_DATA 1
128 
129 /* These are used internally by the coffee file system */
130 /* Micro logs are not needed for single page sectors */
131 #define COFFEE_MAX_OPEN_FILES 4
132 #define COFFEE_FD_SET_SIZE 8
133 #define COFFEE_LOG_TABLE_LIMIT 16
134 #define COFFEE_DYN_SIZE (COFFEE_PAGE_SIZE*1)
135 #define COFFEE_MICRO_LOGS 0
136 #define COFFEE_LOG_SIZE 128
137 
138 /* coffee_page_t is used for page and sector numbering
139  * uint8_t can handle 511 pages.
140  * cfs_offset_t is used for full byte addresses
141  * If CFS_CONF_OFFSET_TYPE is not defined it defaults to int.
142  * uint16_t can handle up to a 65535 byte file system.
143  */
144 #define coffee_page_t uint8_t
145 #define CFS_CONF_OFFSET_TYPE uint16_t
146 
147 
148 #define COFFEE_WRITE(buf, size, offset) \
149  avr_flash_write(offset, (uint8_t *) buf, size)
150 
151 #define COFFEE_READ(buf, size, offset) \
152  avr_flash_read(offset, (uint8_t *) buf, size)
153 
154 #define COFFEE_ERASE(sector) avr_flash_erase(sector)
155 
156 void avr_flash_erase(coffee_page_t sector);
157 void avr_flash_read (CFS_CONF_OFFSET_TYPE addr, uint8_t *buf, CFS_CONF_OFFSET_TYPE size);
158 void avr_flash_write(CFS_CONF_OFFSET_TYPE addr, uint8_t *buf, CFS_CONF_OFFSET_TYPE size);
159 
160 #define avr_httpd_fs_cpy(dest,addr,size) avr_flash_read((CFS_CONF_OFFSET_TYPE) addr, (uint8_t *)dest, (CFS_CONF_OFFSET_TYPE) size)
161 char avr_httpd_fs_getchar(char *addr);
162 char * avr_httpd_fs_strchr (char *ram, int character);
163 int avr_httpd_fs_strcmp (char *addr,char *ram);
164 
165 
166 #endif /* COFFEE_AVR_FLASH */
167 int coffee_file_test(void);
168 #endif /* !COFFEE_ARCH_H */