Mercurial > ecos-v2_0-branch
comparison packages/devs/flash/intel/bootblock/current/src/flash_erase_block.c @ 136:a9ac27ec7abc ecos-sw-2000-11-17
Merge from eCos master repository on 2000-11-17-18:24:25-GMT
| author | jlarmour |
|---|---|
| date | Fri, 17 Nov 2000 23:16:43 +0000 |
| parents | |
| children | e0c0827131d1 |
comparison
equal
deleted
inserted
replaced
| 135:3bc2abeae9ff | 136:a9ac27ec7abc |
|---|---|
| 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 short *block) | |
| 56 { | |
| 57 volatile unsigned short *ROM, *sb; | |
| 58 unsigned long stat; | |
| 59 int timeout = 50000; | |
| 60 int len, block_size; | |
| 61 | |
| 62 GO_SLOW | |
| 63 | |
| 64 ROM = (volatile unsigned short *)((unsigned long)block & 0xFF800000); | |
| 65 | |
| 66 // Clear any error conditions | |
| 67 ROM[0] = FLASH_Clear_Status; | |
| 68 | |
| 69 len = FLASH_BLOCK_SIZE; | |
| 70 if (((unsigned long)block - (unsigned long)ROM) < FLASH_BLOCK_SIZE) { | |
| 71 block_size = FLASH_BOOT_BLOCK_SIZE; // First 8 blocks are only 8Kx2 each | |
| 72 } else { | |
| 73 block_size = FLASH_BLOCK_SIZE; | |
| 74 } | |
| 75 sb = block; | |
| 76 while (len > 0) { | |
| 77 // Erase block | |
| 78 ROM[0] = FLASH_Block_Erase; | |
| 79 *block = FLASH_Confirm; | |
| 80 timeout = 5000000; | |
| 81 while(((stat = ROM[0]) & FLASH_Status_Ready) != FLASH_Status_Ready) { | |
| 82 if (--timeout == 0) break; | |
| 83 } | |
| 84 | |
| 85 len -= block_size; | |
| 86 block += block_size / sizeof(*block); | |
| 87 } | |
| 88 | |
| 89 // Restore ROM to "normal" mode | |
| 90 ROM[0] = FLASH_Reset; | |
| 91 | |
| 92 // If an error was reported, see if the block erased anyway | |
| 93 if (stat & 0x007E007E) { | |
| 94 len = FLASH_BLOCK_SIZE; | |
| 95 block = sb; | |
| 96 while (len > 0) { | |
| 97 if (*block++ != 0xFFFFFFFF) break; | |
| 98 len -= sizeof(*block); | |
| 99 } | |
| 100 if (len == 0) stat = 0; | |
| 101 } | |
| 102 | |
| 103 GO_FAST | |
| 104 | |
| 105 return stat; | |
| 106 } |
