comparison packages/io/flash/current/include/flash.h @ 141:450e4e1f1e80 ecos-sw-2000-11-27

Merge from eCos master repository on 2000-11-27-23:09:27-GMT
author jlarmour
date Tue, 28 Nov 2000 00:03:34 +0000
parents a9ac27ec7abc
children 6b5f480c6929
comparison
equal deleted inserted replaced
140:b9721305fd46 141:450e4e1f1e80
43 43
44 #ifndef _IO_FLASH_H_ 44 #ifndef _IO_FLASH_H_
45 #define _IO_FLASH_H_ 45 #define _IO_FLASH_H_
46 46
47 #include <pkgconf/io_flash.h> 47 #include <pkgconf/io_flash.h>
48 #include <cyg/hal/hal_cache.h>
48 49
49 #define FLASH_MIN_WORKSPACE 0x10000 // Space used by FLASH code 50 #define FLASH_MIN_WORKSPACE 0x10000 // Space used by FLASH code
50 51
51 extern int flash_init(void *work_space, int work_space_length); 52 externC int flash_init(void *work_space, int work_space_length);
52 extern int flash_erase(void *base, int len, void **err_address); 53 externC int flash_erase(void *base, int len, void **err_address);
53 extern int flash_program(void *flash_base, void *ram_base, int len, void **err_address); 54 externC int flash_program(void *flash_base, void *ram_base, int len, void **err_address);
54 #if 0 < CYGHWR_IO_FLASH_BLOCK_LOCKING // This is an *interface* 55 #if 0 < CYGHWR_IO_FLASH_BLOCK_LOCKING // This is an *interface*
55 extern int flash_lock(void *base, int len, void **err_address); 56 externC int flash_lock(void *base, int len, void **err_address);
56 extern int flash_unlock(void *base, int len, void **err_address); 57 externC int flash_unlock(void *base, int len, void **err_address);
57 #endif 58 #endif
58 extern int flash_verify_addr(void *base); 59 externC int flash_verify_addr(void *base);
59 extern int flash_get_limits(void *base, void **start, void **end); 60 externC int flash_get_limits(void *base, void **start, void **end);
60 extern int flash_get_block_info(int *block_size, int *blocks); 61 externC int flash_get_block_info(int *block_size, int *blocks);
61 extern bool flash_code_overlaps(void *start, void *end); 62 externC bool flash_code_overlaps(void *start, void *end);
62 extern char *flash_errmsg(int err); 63 externC char *flash_errmsg(int err);
64
65 externC int printf(char* fmt, ...);
63 66
64 #define FLASH_ERR_OK 0x00 // No error - operation complete 67 #define FLASH_ERR_OK 0x00 // No error - operation complete
65 #define FLASH_ERR_INVALID 0x01 // Invalid FLASH address 68 #define FLASH_ERR_INVALID 0x01 // Invalid FLASH address
66 #define FLASH_ERR_ERASE 0x02 // Error trying to erase 69 #define FLASH_ERR_ERASE 0x02 // Error trying to erase
67 #define FLASH_ERR_LOCK 0x03 // Error trying to lock/unlock 70 #define FLASH_ERR_LOCK 0x03 // Error trying to lock/unlock
87 90
88 extern struct flash_info flash_info; 91 extern struct flash_info flash_info;
89 extern int flash_hwr_init(void); 92 extern int flash_hwr_init(void);
90 extern int flash_hwr_map_error(int err); 93 extern int flash_hwr_map_error(int err);
91 94
92 #endif 95
96 //---------------------------------------------------------------------------
97 //Execution of relocated code must be done inside a
98 //HAL_FLASH_CACHES_OFF/HAL_FLASH_CACHES_ON region - disabling the
99 //cache on unified cache systems is necessary to prevent burst access
100 //to the flash area being programmed. With Harvard style caches, only
101 //the data cache needs to be disabled, but the instruction cache must
102 //still be invalidated to ensure the relocated code is properly
103 //fetched from memory.
104
105 // Targets may provide alternative implementations for these macros in
106 // the hal_cache.h (or var/plf) files.
107
108 // The first part below is the optimal implementation, but it does not
109 // always work. The second part is a more safe implementation that has
110 // been tested to work on some targets - it may not be suitable for
111 // targets that would do burst access to the flash (data cache needs
112 // disabling as well).
113
114 // NOTE: Do _not_ change any of the below macros without checking that
115 // the changed code still works on _all_ platforms that rely on these
116 // macros. There is no such thing as logical and correct when dealing
117 // with different cache and IO models, so _do not_ mess with this code
118 // unless you test it properly afterwards.
119
120 #ifndef HAL_FLASH_CACHES_OFF
121
122 #ifdef HAL_FLASH_CACHES_WANT_OPTIMAL // Optimal implementation
123
124 #ifdef HAL_CACHE_UNIFIED
125
126 // Note: the ucache code has not been tested yet on any target.
127 #define HAL_FLASH_CACHES_OFF(_d_, _i_) \
128 CYG_MACRO_START \
129 _i_ = 0; /* avoids warning */ \
130 HAL_UCACHE_IS_ENABLED(_d_); \
131 HAL_UCACHE_SYNC(); \
132 HAL_UCACHE_INVALIDATE_ALL(); \
133 HAL_UCACHE_DISABLE(); \
134 CYG_MACRO_END
135
136 #define HAL_FLASH_CACHES_ON(_d_, _i_) \
137 CYG_MACRO_START \
138 if (_d_) HAL_UCACHE_ENABLE(); \
139 CYG_MACRO_END
140
141 #else // HAL_CACHE_UNIFIED
142
143 #define HAL_FLASH_CACHES_OFF(_d_, _i_) \
144 CYG_MACRO_START \
145 _i_ = 0; /* avoids warning */ \
146 HAL_DCACHE_IS_ENABLED(_d_); \
147 HAL_DCACHE_SYNC(); \
148 HAL_DCACHE_INVALIDATE_ALL(); \
149 HAL_DCACHE_DISABLE(); \
150 HAL_ICACHE_INVALIDATE_ALL(); \
151 CYG_MACRO_END
152
153 #define HAL_FLASH_CACHES_ON(_d_, _i_) \
154 CYG_MACRO_START \
155 if (_d_) HAL_DCACHE_ENABLE(); \
156 CYG_MACRO_END
157
158 #endif // HAL_CACHE_UNIFIED
159
160 #else // HAL_FLASH_CACHES_WANT_OPTIMAL
161
162 // Note: This implementation is broken as it will always enable the i-cache
163 // even if it was not enabled before. It also doesn't work if the
164 // target uses burst access to flash since the d-cache is left enabled.
165 // However, this does not mean you can change this code! Leave it as
166 // is - if you want a different implementation, provide it in the
167 // arch/var/platform cache header file.
168
169 #define HAL_FLASH_CACHES_OFF(_d_, _i_) \
170 _d_ = 0; /* avoids warning */ \
171 _i_ = 0; /* avoids warning */ \
172 HAL_DCACHE_SYNC(); \
173 HAL_ICACHE_DISABLE();
174
175 #define HAL_FLASH_CACHES_ON(_d_, _i_) \
176 HAL_ICACHE_ENABLE();
177
178 #endif // HAL_FLASH_CACHES_WANT_OPTIMAL
179
180 #endif // HAL_FLASH_CACHES_OFF
181
182 #endif // _FLASH_PRIVATE_
93 183
94 #endif // _IO_FLASH_H_ 184 #endif // _IO_FLASH_H_