Contiki 2.5
cfs-coffee-arch.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2010, STMicroelectronics.
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 STM32W108-based mb851
36  * platform.
37  * STM32W108 has 128KB of program flash.
38  * \author
39  * Salvatore Pitrulli <salvopitru@users.sourceforge.net>
40  */
41 
42 #ifndef CFS_COFFEE_ARCH_H
43 #define CFS_COFFEE_ARCH_H
44 
45 #include "contiki-conf.h"
46 
47 #include "hal/error.h"
49 
50 /* STM32W108 has 128 pages of 1024 bytes each = 128KB
51  * The smallest erasable unit is one page and the smallest writable
52  * unit is an aligned 16-bit half-word.
53  */
54 
55 /* Byte page size, starting address on page boundary, and size of the file system */
56 #define FLASH_START 0x8000000
57 /* Minimum erasable unit. */
58 #define FLASH_PAGE_SIZE 1024
59 /* Last 3 pages reserved for NVM. */
60 #define FLASH_PAGES 125
61 
62 
63 /* Minimum reservation unit for Coffee. It can be changed by the user. */
64 #define COFFEE_PAGE_SIZE (FLASH_PAGE_SIZE/4)
65 
66 
67 /* If using IAR, COFFEE_ADDRESS reflects the static value in the linker script
68  iar-cfg-coffee.icf, so it can't be passed as a parameter for Make.*/
69 #ifdef __ICCARM__
70 #define COFFEE_ADDRESS 0x8010c00
71 #endif
72 #if (COFFEE_ADDRESS & 0x3FF) !=0
73  #error "COFFEE_ADDRESS not aligned to a 1024-bytes page boundary."
74 #endif
75 #define COFFEE_PAGES ((FLASH_PAGES*FLASH_PAGE_SIZE-(COFFEE_ADDRESS-FLASH_START))/COFFEE_PAGE_SIZE)
76 #define COFFEE_START (COFFEE_ADDRESS & ~(COFFEE_PAGE_SIZE-1))
77 #define COFFEE_SIZE (COFFEE_PAGES*COFFEE_PAGE_SIZE)
78 
79 /* These must agree with the parameters passed to makefsdata */
80 #define COFFEE_SECTOR_SIZE FLASH_PAGE_SIZE
81 #define COFFEE_NAME_LENGTH 20
82 
83 ///* These are used internally by the AVR flash read routines */
84 ///* Word reads are faster but take 130 bytes more PROGMEM */
85 //#define FLASH_WORD_READS 1
86 ///* 1=Slower reads, but no page writes after erase and 18 bytes less PROGMEM. Best for dynamic file system */
87 //#define FLASH_COMPLEMENT_DATA 0
88 
89 /* These are used internally by the coffee file system */
90 /* Micro logs are not needed for single page sectors */
91 #define COFFEE_MAX_OPEN_FILES 4
92 #define COFFEE_FD_SET_SIZE 8
93 #define COFFEE_DYN_SIZE (COFFEE_PAGE_SIZE*1)
94 #define COFFEE_MICRO_LOGS 0
95 #define COFFEE_LOG_TABLE_LIMIT 16 // It doesnt' matter as
96 #define COFFEE_LOG_SIZE 128 // COFFEE_MICRO_LOGS is 0.
97 
98 
99 #if COFFEE_PAGES <= 127
100 #define coffee_page_t int8_t
101 #elif COFFEE_PAGES <= 0x7FFF
102 #define coffee_page_t int16_t
103 #endif
104 
105 
106 #define COFFEE_WRITE(buf, size, offset) \
107  stm32w_flash_write(COFFEE_START + offset, buf, size)
108 
109 #define COFFEE_READ(buf, size, offset) \
110  stm32w_flash_read(COFFEE_START + offset, buf, size)
111 
112 #define COFFEE_ERASE(sector) \
113  stm32w_flash_erase(sector)
114 
115 
116 void stm32w_flash_read(int32u address, void * data, int32u length);
117 void stm32w_flash_write(int32u address, const void * data, int32u length);
118 void stm32w_flash_erase(int8u sector);
119 
120 int coffee_file_test(void);
121 
122 #endif /* !COFFEE_ARCH_H */