comparison packages/io/flash/current/src/flash.c @ 160:0d0f03f76f6a

Merge from eCos master repository on 2001-06-01-18:52:13-BST
author jlarmour
date Fri, 01 Jun 2001 22:16:29 +0000
parents b65ec671dd4c
children 2395031e7a66
comparison
equal deleted inserted replaced
159:511f4dc167f6 160:0d0f03f76f6a
56 // This can be used for running the function in place (RAM startup only), 56 // This can be used for running the function in place (RAM startup only),
57 // allowing calls to diag_printf() and similar. 57 // allowing calls to diag_printf() and similar.
58 #undef RAM_FLASH_DEV_DEBUG 58 #undef RAM_FLASH_DEV_DEBUG
59 #if !defined(CYG_HAL_STARTUP_RAM) && defined(RAM_FLASH_DEV_DEBUG) 59 #if !defined(CYG_HAL_STARTUP_RAM) && defined(RAM_FLASH_DEV_DEBUG)
60 # warning "Can only enable the flash debugging when configured for RAM startup" 60 # warning "Can only enable the flash debugging when configured for RAM startup"
61 # undef CYGHWR_IO_FLASH_DEVICE_IN_RAM 61 # undef CYGHWR_IO_FLASH_DEVICE_NOT_IN_RAM
62 # define CYGHWR_IO_FLASH_DEVICE_IN_RAM 1
63 #endif 62 #endif
64 63
65 struct flash_info flash_info; 64 struct flash_info flash_info;
66 65
67 int 66 int
78 flash_info.block_mask = ~(flash_info.block_size-1); 77 flash_info.block_mask = ~(flash_info.block_size-1);
79 flash_info.init = 1; 78 flash_info.init = 1;
80 return FLASH_ERR_OK; 79 return FLASH_ERR_OK;
81 } 80 }
82 81
83 #ifdef CYGHWR_IO_FLASH_DEVICE_IN_RAM 82 #ifndef CYGHWR_IO_FLASH_DEVICE_NOT_IN_RAM
84 // Use this function to make function pointers anonymous - forcing the 83 // Use this function to make function pointers anonymous - forcing the
85 // compiler to use jumps instead of branches when calling driver 84 // compiler to use jumps instead of branches when calling driver
86 // services. 85 // services.
87 static void* __anonymizer(void* p) 86 static void* __anonymizer(void* p)
88 { 87 {
98 { 97 {
99 typedef void code_fun(void*); 98 typedef void code_fun(void*);
100 code_fun *_flash_query; 99 code_fun *_flash_query;
101 int d_cache, i_cache; 100 int d_cache, i_cache;
102 101
103 #ifdef CYGHWR_IO_FLASH_DEVICE_IN_RAM 102 #ifdef CYGHWR_IO_FLASH_DEVICE_NOT_IN_RAM
104 {
105 externC code_fun flash_query;
106 _flash_query = (code_fun*) __anonymizer(&flash_query);
107 }
108 #else
109 { 103 {
110 extern char flash_query[], flash_query_end[]; 104 extern char flash_query[], flash_query_end[];
111 int code_len; 105 int code_len;
112 106
113 // Query the device driver - copy 'query' code to RAM for execution 107 // Query the device driver - copy 'query' code to RAM for execution
114 code_len = (unsigned long)&flash_query_end - (unsigned long)&flash_query; 108 code_len = (unsigned long)&flash_query_end - (unsigned long)&flash_query;
115 _flash_query = (code_fun *)flash_info.work_space; 109 _flash_query = (code_fun *)flash_info.work_space;
116 memcpy(_flash_query, &flash_query, code_len); 110 memcpy(_flash_query, &flash_query, code_len);
111 }
112 #else
113 {
114 externC code_fun flash_query;
115 _flash_query = (code_fun*) __anonymizer(&flash_query);
117 } 116 }
118 #endif 117 #endif
119 118
120 HAL_FLASH_CACHES_OFF(d_cache, i_cache); 119 HAL_FLASH_CACHES_OFF(d_cache, i_cache);
121 (*_flash_query)(data); 120 (*_flash_query)(data);
169 168
170 if (!flash_info.init) { 169 if (!flash_info.init) {
171 return FLASH_ERR_NOT_INIT; 170 return FLASH_ERR_NOT_INIT;
172 } 171 }
173 172
174 #ifdef CYGHWR_IO_FLASH_DEVICE_IN_RAM 173 #ifdef CYGHWR_IO_FLASH_DEVICE_NOT_IN_RAM
175 {
176 externC code_fun flash_erase_block;
177 _flash_erase_block = (code_fun*) __anonymizer(&flash_erase_block);
178 }
179 #else
180 { 174 {
181 extern char flash_erase_block[], flash_erase_block_end[]; 175 extern char flash_erase_block[], flash_erase_block_end[];
182 int code_len; 176 int code_len;
183 177
184 // Copy 'erase' code to RAM for execution 178 // Copy 'erase' code to RAM for execution
185 code_len = (unsigned long)&flash_erase_block_end - (unsigned long)&flash_erase_block; 179 code_len = (unsigned long)&flash_erase_block_end - (unsigned long)&flash_erase_block;
186 _flash_erase_block = (code_fun *)flash_info.work_space; 180 _flash_erase_block = (code_fun *)flash_info.work_space;
187 memcpy(_flash_erase_block, &flash_erase_block, code_len); 181 memcpy(_flash_erase_block, &flash_erase_block, code_len);
182 }
183 #else
184 {
185 externC code_fun flash_erase_block;
186 _flash_erase_block = (code_fun*) __anonymizer(&flash_erase_block);
188 } 187 }
189 #endif 188 #endif
190 189
191 block = (unsigned short *)((unsigned long)addr & flash_info.block_mask); 190 block = (unsigned short *)((unsigned long)addr & flash_info.block_mask);
192 end_addr = (unsigned short *)((unsigned long)addr+len); 191 end_addr = (unsigned short *)((unsigned long)addr+len);
225 224
226 if (!flash_info.init) { 225 if (!flash_info.init) {
227 return FLASH_ERR_NOT_INIT; 226 return FLASH_ERR_NOT_INIT;
228 } 227 }
229 228
230 #ifdef CYGHWR_IO_FLASH_DEVICE_IN_RAM 229 #ifdef CYGHWR_IO_FLASH_DEVICE_NOT_IN_RAM
231 {
232 externC code_fun flash_program_buf;
233 _flash_program_buf = (code_fun*) __anonymizer(&flash_program_buf);
234 }
235 #else
236 { 230 {
237 int code_len; 231 int code_len;
238 extern char flash_program_buf[], flash_program_buf_end[]; 232 extern char flash_program_buf[], flash_program_buf_end[];
239 // Copy 'program' code to RAM for execution 233 // Copy 'program' code to RAM for execution
240 code_len = (unsigned long)&flash_program_buf_end - (unsigned long)&flash_program_buf; 234 code_len = (unsigned long)&flash_program_buf_end - (unsigned long)&flash_program_buf;
241 _flash_program_buf = (code_fun *)flash_info.work_space; 235 _flash_program_buf = (code_fun *)flash_info.work_space;
242 memcpy(_flash_program_buf, &flash_program_buf, code_len); 236 memcpy(_flash_program_buf, &flash_program_buf, code_len);
237 }
238 #else
239 {
240 externC code_fun flash_program_buf;
241 _flash_program_buf = (code_fun*) __anonymizer(&flash_program_buf);
243 } 242 }
244 #endif 243 #endif
245 244
246 printf("... Program from %p-%p at %p: ", (void*)data, 245 printf("... Program from %p-%p at %p: ", (void*)data,
247 (void*)(((unsigned long)data)+len), (void*)addr); 246 (void*)(((unsigned long)data)+len), (void*)addr);
289 288
290 if (!flash_info.init) { 289 if (!flash_info.init) {
291 return FLASH_ERR_NOT_INIT; 290 return FLASH_ERR_NOT_INIT;
292 } 291 }
293 292
294 #ifdef CYGHWR_IO_FLASH_DEVICE_IN_RAM 293 #ifdef CYGHWR_IO_FLASH_DEVICE_NOT_IN_RAM
295 {
296 externC code_fun flash_lock_block;
297 _flash_lock_block = (code_fun*) __anonymizer(&flash_lock_block);
298 }
299 #else
300 { 294 {
301 extern char flash_lock_block[], flash_lock_block_end[]; 295 extern char flash_lock_block[], flash_lock_block_end[];
302 int code_len; 296 int code_len;
303 // Copy 'lock' code to RAM for execution 297 // Copy 'lock' code to RAM for execution
304 code_len = (unsigned long)&flash_lock_block_end - (unsigned long)&flash_lock_block; 298 code_len = (unsigned long)&flash_lock_block_end - (unsigned long)&flash_lock_block;
305 _flash_lock_block = (code_fun *)flash_info.work_space; 299 _flash_lock_block = (code_fun *)flash_info.work_space;
306 memcpy(_flash_lock_block, &flash_lock_block, code_len); 300 memcpy(_flash_lock_block, &flash_lock_block, code_len);
301 }
302 #else
303 {
304 externC code_fun flash_lock_block;
305 _flash_lock_block = (code_fun*) __anonymizer(&flash_lock_block);
307 } 306 }
308 #endif 307 #endif
309 308
310 block = (unsigned short *)((unsigned long)addr & flash_info.block_mask); 309 block = (unsigned short *)((unsigned long)addr & flash_info.block_mask);
311 end_addr = (unsigned short *)((unsigned long)addr+len); 310 end_addr = (unsigned short *)((unsigned long)addr+len);
341 340
342 if (!flash_info.init) { 341 if (!flash_info.init) {
343 return FLASH_ERR_NOT_INIT; 342 return FLASH_ERR_NOT_INIT;
344 } 343 }
345 344
346 #ifdef CYGHWR_IO_FLASH_DEVICE_IN_RAM 345 #ifdef CYGHWR_IO_FLASH_DEVICE_NOT_IN_RAM
347 {
348 externC code_fun flash_unlock_block;
349 _flash_unlock_block = (code_fun*) __anonymizer(&flash_unlock_block);
350 }
351 #else
352 { 346 {
353 extern char flash_unlock_block[], flash_unlock_block_end[]; 347 extern char flash_unlock_block[], flash_unlock_block_end[];
354 int code_len; 348 int code_len;
355 // Copy 'lock' code to RAM for execution 349 // Copy 'lock' code to RAM for execution
356 code_len = (unsigned long)&flash_unlock_block_end - (unsigned long)&flash_unlock_block; 350 code_len = (unsigned long)&flash_unlock_block_end - (unsigned long)&flash_unlock_block;
357 _flash_unlock_block = (code_fun *)flash_info.work_space; 351 _flash_unlock_block = (code_fun *)flash_info.work_space;
358 memcpy(_flash_unlock_block, &flash_unlock_block, code_len); 352 memcpy(_flash_unlock_block, &flash_unlock_block, code_len);
353 }
354 #else
355 {
356 externC code_fun flash_unlock_block;
357 _flash_unlock_block = (code_fun*) __anonymizer(&flash_unlock_block);
359 } 358 }
360 #endif 359 #endif
361 360
362 block = (unsigned short *)((unsigned long)addr & flash_info.block_mask); 361 block = (unsigned short *)((unsigned long)addr & flash_info.block_mask);
363 end_addr = (unsigned short *)((unsigned long)addr+len); 362 end_addr = (unsigned short *)((unsigned long)addr+len);