cfs-coffee-arch.h

Go to the documentation of this file.
00001 /*
00002  * Copyright (c) 2010, STMicroelectronics.
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 STM32W108-based mb851
00036  *  platform.
00037  *  STM32W108 has 128KB of program flash.
00038  * \author
00039  *  Salvatore Pitrulli <salvopitru@users.sourceforge.net>
00040  */
00041 
00042 #ifndef CFS_COFFEE_ARCH_H
00043 #define CFS_COFFEE_ARCH_H
00044 
00045 #include "contiki-conf.h"
00046 
00047 #include "hal/error.h"
00048 #include "hal/micro/cortexm3/flash.h"
00049 
00050 /* STM32W108 has 128 pages of 1024 bytes each = 128KB
00051  * The smallest erasable unit is one page and the smallest writable
00052  * unit is an aligned 16-bit half-word.
00053  */
00054 
00055 /* Byte page size, starting address on page boundary, and size of the file system */
00056 #define FLASH_START               0x8000000
00057 /* Minimum erasable unit. */
00058 #define FLASH_PAGE_SIZE           1024
00059 /* Last 3 pages reserved for NVM. */
00060 #define FLASH_PAGES               125
00061 
00062 
00063 /* Minimum reservation unit for Coffee. It can be changed by the user.  */
00064 #define COFFEE_PAGE_SIZE          (FLASH_PAGE_SIZE/4)
00065 
00066 
00067 /* If using IAR, COFFEE_ADDRESS reflects the static value in the linker script
00068    iar-cfg-coffee.icf, so it can't be passed as a parameter for Make.*/
00069 #ifdef __ICCARM__
00070 #define COFFEE_ADDRESS            0x8010c00
00071 #endif
00072 #if (COFFEE_ADDRESS & 0x3FF) !=0
00073  #error "COFFEE_ADDRESS not aligned to a 1024-bytes page boundary."
00074 #endif
00075 #define COFFEE_PAGES              ((FLASH_PAGES*FLASH_PAGE_SIZE-(COFFEE_ADDRESS-FLASH_START))/COFFEE_PAGE_SIZE)
00076 #define COFFEE_START              (COFFEE_ADDRESS & ~(COFFEE_PAGE_SIZE-1))
00077 #define COFFEE_SIZE               (COFFEE_PAGES*COFFEE_PAGE_SIZE)
00078 
00079 /* These must agree with the parameters passed to makefsdata */
00080 #define COFFEE_SECTOR_SIZE        FLASH_PAGE_SIZE
00081 #define COFFEE_NAME_LENGTH        20
00082 
00083 ///* These are used internally by the AVR flash read routines */
00084 ///* Word reads are faster but take 130 bytes more PROGMEM */
00085 //#define FLASH_WORD_READS          1
00086 ///* 1=Slower reads, but no page writes after erase and 18 bytes less PROGMEM. Best for dynamic file system */
00087 //#define FLASH_COMPLEMENT_DATA     0 
00088 
00089 /* These are used internally by the coffee file system */
00090 /* Micro logs are not needed for single page sectors */
00091 #define COFFEE_MAX_OPEN_FILES     4
00092 #define COFFEE_FD_SET_SIZE        8
00093 #define COFFEE_DYN_SIZE           (COFFEE_PAGE_SIZE*1)
00094 #define COFFEE_MICRO_LOGS         0
00095 #define COFFEE_LOG_TABLE_LIMIT    16    // It doesnt' matter as
00096 #define COFFEE_LOG_SIZE           128   // COFFEE_MICRO_LOGS is 0.
00097 
00098 
00099 #if COFFEE_PAGES <= 127
00100 #define coffee_page_t int8_t
00101 #elif COFFEE_PAGES <= 0x7FFF
00102 #define coffee_page_t int16_t
00103 #endif
00104 
00105 
00106 #define COFFEE_WRITE(buf, size, offset) \
00107         stm32w_flash_write(COFFEE_START + offset, buf, size)
00108 
00109 #define COFFEE_READ(buf, size, offset) \
00110         stm32w_flash_read(COFFEE_START + offset, buf, size)
00111 
00112 #define COFFEE_ERASE(sector) \
00113         stm32w_flash_erase(sector)
00114 
00115 
00116 void stm32w_flash_read(int32u address, void * data, int32u length);
00117 void stm32w_flash_write(int32u address, const void * data, int32u length);
00118 void stm32w_flash_erase(int8u sector);
00119 
00120 int coffee_file_test(void);
00121 
00122 #endif /* !COFFEE_ARCH_H */

Generated on Mon Apr 11 14:23:39 2011 for Contiki 2.5 by  doxygen 1.6.1