Contiki 3.x
cfs-coffee-arch.h
Go to the documentation of this file.
1 /**
2  * \addtogroup mbxxx-platform
3  *
4  * @{
5  */
6 
7 /*
8  * Copyright (c) 2010, STMicroelectronics.
9  * All rights reserved.
10  *
11  * Redistribution and use in source and binary forms, with or without
12  * modification, are permitted provided that the following conditions
13  * are met:
14  * 1. Redistributions of source code must retain the above copyright
15  * notice, this list of conditions and the following disclaimer.
16  * 2. Redistributions in binary form must reproduce the above copyright
17  * notice, this list of conditions and the following disclaimer in the
18  * documentation and/or other materials provided with the distribution.
19  * 3. Neither the name of the Institute nor the names of its contributors
20  * may be used to endorse or promote products derived from this software
21  * without specific prior written permission.
22  *
23  * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
24  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26  * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
27  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33  * SUCH DAMAGE.
34  *
35  */
36 
37 /**
38  * \file
39  * Coffee architecture-dependent header for the STM32W108-based mb851
40  * platform. STM32W108 has 128KB of program flash.
41  * \author
42  * Salvatore Pitrulli <salvopitru@users.sourceforge.net>
43  */
44 
45 #ifndef CFS_COFFEE_ARCH_H
46 #define CFS_COFFEE_ARCH_H
47 
48 #include "contiki-conf.h"
49 
50 #include "hal/error.h"
52 
53 /*
54  * STM32W108 has 128KB of program flash in 128 pages of 1024 bytes each = 128KB.
55  * The smallest erasable unit is one page and the smallest writable
56  * unit is an aligned 16-bit half-word.
57  */
58 /* Byte page size, starting address on page boundary, and size of file system */
59 #define FLASH_START 0x8000000
60 /* Minimum erasable unit. */
61 #define FLASH_PAGE_SIZE 1024
62 /* Last 3 pages reserved for NVM. */
63 #define FLASH_PAGES 125
64 
65 /* Minimum reservation unit for Coffee. It can be changed by the user. */
66 #define COFFEE_PAGE_SIZE (FLASH_PAGE_SIZE/4)
67 
68 /*
69  * If using IAR, COFFEE_ADDRESS reflects the static value in the linker script
70  * iar-cfg-coffee.icf, so it can't be passed as a parameter for Make.
71  */
72 #ifdef __ICCARM__
73 #define COFFEE_ADDRESS 0x8010c00
74 #endif
75 #if (COFFEE_ADDRESS & 0x3FF) != 0
76 #error "COFFEE_ADDRESS not aligned to a 1024-bytes page boundary."
77 #endif
78 
79 #define COFFEE_PAGES ((FLASH_PAGES*FLASH_PAGE_SIZE- \
80  (COFFEE_ADDRESS-FLASH_START))/COFFEE_PAGE_SIZE)
81 #define COFFEE_START (COFFEE_ADDRESS & ~(COFFEE_PAGE_SIZE-1))
82 #define COFFEE_SIZE (COFFEE_PAGES*COFFEE_PAGE_SIZE)
83 
84 /* These must agree with the parameters passed to makefsdata */
85 #define COFFEE_SECTOR_SIZE FLASH_PAGE_SIZE
86 #define COFFEE_NAME_LENGTH 20
87 
88 /* These are used internally by the AVR flash read routines */
89 /* Word reads are faster but take 130 bytes more PROGMEM */
90  /* #define FLASH_WORD_READS 1 */
91 /*
92  * 1 = Slower reads, but no page writes after erase and 18 bytes less PROGMEM.
93  * Best for dynamic file system
94  */
95  /* #define FLASH_COMPLEMENT_DATA 0 */
96 
97 /* These are used internally by the coffee file system */
98 #define COFFEE_MAX_OPEN_FILES 4
99 #define COFFEE_FD_SET_SIZE 8
100 #define COFFEE_DYN_SIZE (COFFEE_PAGE_SIZE*1)
101 /* Micro logs are not needed for single page sectors */
102 #define COFFEE_MICRO_LOGS 0
103 #define COFFEE_LOG_TABLE_LIMIT 16 /* It doesnt' matter as */
104 #define COFFEE_LOG_SIZE 128 /* COFFEE_MICRO_LOGS is 0. */
105 
106 #if COFFEE_PAGES <= 127
107 #define coffee_page_t int8_t
108 #elif COFFEE_PAGES <= 0x7FFF
109 #define coffee_page_t int16_t
110 #endif
111 
112 #define COFFEE_WRITE(buf, size, offset) \
113  stm32w_flash_write(COFFEE_START + offset, buf, size)
114 
115 #define COFFEE_READ(buf, size, offset) \
116  stm32w_flash_read(COFFEE_START + offset, buf, size)
117 
118 #define COFFEE_ERASE(sector) \
119  stm32w_flash_erase(sector)
120 
121 
122 void stm32w_flash_read(uint32_t address, void *data, uint32_t length);
123 
124 void stm32w_flash_write(uint32_t address, const void *data, uint32_t length);
125 
126 void stm32w_flash_erase(uint8_t sector);
127 
128 int coffee_file_test(void);
129 
130 #endif /* !COFFEE_ARCH_H */
131 /** @} */
Header for flash for APIs.
Return codes for API functions and module definitions.