Contiki 2.6
|
00001 /* 00002 * Copyright (c) 2008, Swedish Institute of Computer Science 00003 * All rights reserved. 00004 * 00005 * Redistribution and use in source and binary forms, with or without 00006 * modification, are permitted provided that the following conditions 00007 * are met: 00008 * 1. Redistributions of source code must retain the above copyright 00009 * notice, this list of conditions and the following disclaimer. 00010 * 2. Redistributions in binary form must reproduce the above copyright 00011 * notice, this list of conditions and the following disclaimer in the 00012 * documentation and/or other materials provided with the distribution. 00013 * 3. Neither the name of the Institute nor the names of its contributors 00014 * may be used to endorse or promote products derived from this software 00015 * without specific prior written permission. 00016 * 00017 * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND 00018 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 00019 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 00020 * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE 00021 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 00022 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 00023 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 00024 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 00025 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 00026 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 00027 * SUCH DAMAGE. 00028 * 00029 * This file is part of the Contiki operating system. 00030 * 00031 */ 00032 00033 /** 00034 * \file 00035 * Coffee architecture-dependent header for the AVR-Raven 1284p platform. 00036 * The 1284p has 4KB of onboard EEPROM and 128KB of program flash. 00037 * \author 00038 * Frederic Thepaut <frederic.thepaut@inooi.com> 00039 * David Kopf <dak664@embarqmail.com> 00040 */ 00041 00042 #ifndef CFS_COFFEE_ARCH_H 00043 #define CFS_COFFEE_ARCH_H 00044 00045 #include "contiki-conf.h" 00046 00047 //Currently you may choose just one of the following for the coffee file sytem 00048 //A static file sysstem allows file rewrites but no extensions or new files 00049 //This allows a static linked list to index into the file system 00050 #if COFFEE_FILES==1 //1=eeprom for static file system 00051 #define COFFEE_AVR_EEPROM 1 00052 #define COFFEE_STATIC 1 00053 #elif COFFEE_FILES==2 //2=eeprom for full file system 00054 #define COFFEE_AVR_EEPROM 1 00055 #elif COFFEE_FILES==3 //3=program flash for static file system 00056 #define COFFEE_AVR_FLASH 1 00057 #define COFFEE_STATIC 1 00058 #else //4=program flash with full file system 00059 #define COFFEE_AVR_FLASH 1 00060 #endif 00061 00062 #ifdef COFFEE_AVR_EEPROM 00063 #include "dev/eeprom.h" 00064 //1284p EEPROM has 512 pages of 8 bytes each = 4KB 00065 00066 #if COFFEE_ADDRESS==DEFAULT //Make can pass starting address with COFFEE_ADDRESS=0xnnnnnnnn 00067 #undef COFFEE_ADDRESS 00068 #ifdef CFS_EEPROM_CONF_OFFSET //Else use the platform default 00069 #define COFFEE_ADDRESS CFS_EEPROM_CONF_OFFSET 00070 #else //Use zero if no default defined 00071 #define COFFEE_ADDRESS 0 00072 #endif 00073 #endif 00074 00075 /* Byte page size, starting address, and size of the file system */ 00076 #define COFFEE_PAGE_SIZE 16UL 00077 #define COFFEE_START COFFEE_ADDRESS 00078 #define COFFEE_SIZE ((3 * 1024U) - COFFEE_START) 00079 /* These must agree with the parameters passed to makefsdata */ 00080 #define COFFEE_SECTOR_SIZE (COFFEE_PAGE_SIZE*4) 00081 #define COFFEE_NAME_LENGTH 16 00082 /* These are used internally by the coffee file system */ 00083 #define COFFEE_MAX_OPEN_FILES 4 00084 #define COFFEE_FD_SET_SIZE 8 00085 #define COFFEE_LOG_TABLE_LIMIT 16 00086 #define COFFEE_DYN_SIZE (COFFEE_PAGE_SIZE * 4) 00087 #define COFFEE_LOG_SIZE 128 00088 00089 typedef int16_t coffee_page_t; 00090 typedef uint16_t coffee_offset_t; 00091 00092 #define COFFEE_ERASE(sector) avr_eeprom_erase(sector) 00093 void avr_eeprom_erase(uint16_t sector); 00094 00095 #define COFFEE_WRITE(buf, size, offset) \ 00096 eeprom_write(COFFEE_START + (offset), (unsigned char *)(buf), (size)) 00097 00098 #define COFFEE_READ(buf, size, offset) \ 00099 eeprom_read (COFFEE_START + (offset), (unsigned char *)(buf), (size)) 00100 00101 #endif /* COFFEE_AVR_EEPROM */ 00102 00103 #ifdef COFFEE_AVR_FLASH 00104 /* 1284p PROGMEM has 512 pages of 256 bytes each = 128KB 00105 * Writing to the last 32 NRRW pages will halt the CPU. 00106 * Take care not to overwrite the .bootloader section... 00107 */ 00108 00109 /* Byte page size, starting address on page boundary, and size of the file system */ 00110 #define COFFEE_PAGE_SIZE (2*SPM_PAGESIZE) 00111 #ifndef COFFEE_ADDRESS //Make can pass starting address with COFFEE_ADDRESS=0xnnnnnnnn, default is 64KB for webserver 00112 #define COFFEE_ADDRESS 0x10000 00113 #endif 00114 #define COFFEE_PAGES (512-(COFFEE_ADDRESS/COFFEE_PAGE_SIZE)-32) 00115 #define COFFEE_START (COFFEE_ADDRESS & ~(COFFEE_PAGE_SIZE-1)) 00116 //#define COFFEE_START (COFFEE_PAGE_SIZE*COFFEE_PAGES) 00117 #define COFFEE_SIZE (COFFEE_PAGES*COFFEE_PAGE_SIZE) 00118 00119 /* These must agree with the parameters passed to makefsdata */ 00120 #define COFFEE_SECTOR_SIZE (COFFEE_PAGE_SIZE*1) 00121 #define COFFEE_NAME_LENGTH 16 00122 00123 /* These are used internally by the AVR flash read routines */ 00124 /* Word reads are faster but take 130 bytes more PROGMEM */ 00125 #define FLASH_WORD_READS 1 00126 /* 1=Slower reads, but no page writes after erase and 18 bytes less PROGMEM. Best for dynamic file system */ 00127 #define FLASH_COMPLEMENT_DATA 0 00128 00129 /* These are used internally by the coffee file system */ 00130 /* Micro logs are not needed for single page sectors */ 00131 #define COFFEE_MAX_OPEN_FILES 4 00132 #define COFFEE_FD_SET_SIZE 8 00133 #define COFFEE_LOG_TABLE_LIMIT 16 00134 #define COFFEE_DYN_SIZE (COFFEE_PAGE_SIZE*1) 00135 #define COFFEE_MICRO_LOGS 0 00136 #define COFFEE_LOG_SIZE 128 00137 00138 /* coffee_page_t is used for page and sector numbering 00139 * uint8_t can handle 511 pages. 00140 * cfs_offset_t is used for full byte addresses 00141 * If CFS_CONF_OFFSET_TYPE is not defined it defaults to int. 00142 * uint16_t can handle up to a 65535 byte file system. 00143 */ 00144 #define coffee_page_t uint8_t 00145 #define CFS_CONF_OFFSET_TYPE uint16_t 00146 00147 00148 #define COFFEE_WRITE(buf, size, offset) \ 00149 avr_flash_write(offset, (uint8_t *) buf, size) 00150 00151 #define COFFEE_READ(buf, size, offset) \ 00152 avr_flash_read(offset, (uint8_t *) buf, size) 00153 00154 #define COFFEE_ERASE(sector) avr_flash_erase(sector) 00155 00156 void avr_flash_erase(coffee_page_t sector); 00157 void avr_flash_read (CFS_CONF_OFFSET_TYPE addr, uint8_t *buf, CFS_CONF_OFFSET_TYPE size); 00158 void avr_flash_write(CFS_CONF_OFFSET_TYPE addr, uint8_t *buf, CFS_CONF_OFFSET_TYPE size); 00159 00160 #define avr_httpd_fs_cpy(dest,addr,size) avr_flash_read((CFS_CONF_OFFSET_TYPE) addr, (uint8_t *)dest, (CFS_CONF_OFFSET_TYPE) size) 00161 char avr_httpd_fs_getchar(char *addr); 00162 char * avr_httpd_fs_strchr (char *ram, int character); 00163 int avr_httpd_fs_strcmp (char *addr,char *ram); 00164 00165 00166 #endif /* COFFEE_AVR_FLASH */ 00167 00168 #endif /* !COFFEE_ARCH_H */