comparison packages/devs/flash/arm/edb7xxx/current/src/flash_erase_block.c @ 115:6ed91473a1cd ecos-sw-2000-08-21

Merge from eCos master repository on 2000-08-21-22:40:54-BST
author jlarmour
date Fri, 25 Aug 2000 17:32:38 +0000
parents
children e0c0827131d1
comparison
equal deleted inserted replaced
114:5ad2b71d525e 115:6ed91473a1cd
1 //==========================================================================
2 //
3 // flash_erase_block.c
4 //
5 // Flash programming
6 //
7 //==========================================================================
8 //####COPYRIGHTBEGIN####
9 //
10 // -------------------------------------------
11 // The contents of this file are subject to the Red Hat eCos Public License
12 // Version 1.1 (the "License"); you may not use this file except in
13 // compliance with the License. You may obtain a copy of the License at
14 // http://www.redhat.com/
15 //
16 // Software distributed under the License is distributed on an "AS IS"
17 // basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
18 // License for the specific language governing rights and limitations under
19 // the License.
20 //
21 // The Original Code is eCos - Embedded Configurable Operating System,
22 // released September 30, 1998.
23 //
24 // The Initial Developer of the Original Code is Red Hat.
25 // Portions created by Red Hat are
26 // Copyright (C) 1998, 1999, 2000 Red Hat, Inc.
27 // All Rights Reserved.
28 // -------------------------------------------
29 //
30 //####COPYRIGHTEND####
31 //==========================================================================
32 //#####DESCRIPTIONBEGIN####
33 //
34 // Author(s): gthomas
35 // Contributors: gthomas
36 // Date: 2000-07-14
37 // Purpose:
38 // Description:
39 //
40 //####DESCRIPTIONEND####
41 //
42 //==========================================================================
43
44 #include "flash.h"
45
46 #include <pkgconf/hal.h>
47 #include <cyg/hal/hal_arch.h>
48 #include <cyg/hal/hal_cache.h>
49
50 //
51 // CAUTION! This code must be copied to RAM before execution. Therefore,
52 // it must not contain any code which might be position dependent!
53 //
54
55 int flash_erase_block(volatile unsigned long *block)
56 {
57 volatile unsigned long *ROM, *sb;
58 unsigned long stat;
59 int timeout = 50000;
60 int cache_on;
61 int len, block_size;
62
63 HAL_DCACHE_IS_ENABLED(cache_on);
64 if (cache_on) {
65 HAL_DCACHE_SYNC();
66 HAL_DCACHE_DISABLE();
67 }
68
69 ROM = (volatile unsigned long *)((unsigned long)block & 0xFF800000);
70
71 // Clear any error conditions
72 ROM[0] = FLASH_Clear_Status;
73
74 len = FLASH_BLOCK_SIZE;
75 if (((unsigned long)block - (unsigned long)ROM) < FLASH_BLOCK_SIZE) {
76 block_size = FLASH_BOOT_BLOCK_SIZE; // First 8 blocks are only 8Kx2 each
77 } else {
78 block_size = FLASH_BLOCK_SIZE;
79 }
80 sb = block;
81 while (len > 0) {
82 // Erase block
83 ROM[0] = FLASH_Block_Erase;
84 *block = FLASH_Confirm;
85 timeout = 5000000;
86 while(((stat = ROM[0]) & FLASH_Status_Ready) != FLASH_Status_Ready) {
87 if (--timeout == 0) break;
88 }
89
90 len -= block_size;
91 block += block_size / sizeof(*block);
92 }
93
94 // Restore ROM to "normal" mode
95 ROM[0] = FLASH_Reset;
96
97 // If an error was reported, see if the block erased anyway
98 if (stat & 0x007E007E) {
99 len = FLASH_BLOCK_SIZE;
100 block = sb;
101 while (len > 0) {
102 if (*block++ != 0xFFFFFFFF) break;
103 len -= sizeof(*block);
104 }
105 if (len == 0) stat = 0;
106 }
107
108 if (cache_on) {
109 HAL_DCACHE_ENABLE();
110 }
111
112 return stat;
113 }