Mercurial > ecos-v2_0-branch
comparison packages/devs/flash/intel/strata/current/src/flash_program_buf.c @ 156:b939e9cada46
Merge from eCos master repository on 2001-03-29-21:44:39-BST
| author | jlarmour |
|---|---|
| date | Fri, 06 Apr 2001 17:20:13 +0000 |
| parents | |
| children | 0d2b193a635f |
comparison
equal
deleted
inserted
replaced
| 155:70a4cc6d69d2 | 156:b939e9cada46 |
|---|---|
| 1 //========================================================================== | |
| 2 // | |
| 3 // flash_program_buf.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, 2001 Red Hat, Inc. | |
| 27 // All Rights Reserved. | |
| 28 // ------------------------------------------- | |
| 29 // | |
| 30 //####COPYRIGHTEND#### | |
| 31 //========================================================================== | |
| 32 //#####DESCRIPTIONBEGIN#### | |
| 33 // | |
| 34 // Author(s): gthomas, hmt | |
| 35 // Contributors: gthomas | |
| 36 // Date: 2001-02-14 | |
| 37 // Purpose: | |
| 38 // Description: | |
| 39 // | |
| 40 //####DESCRIPTIONEND#### | |
| 41 // | |
| 42 //========================================================================== | |
| 43 | |
| 44 #include "strata.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 | |
| 56 flash_program_buf(volatile flash_t *addr, flash_t *data, int len, | |
| 57 unsigned long block_mask, int buffer_size) | |
| 58 { | |
| 59 volatile flash_t *ROM; | |
| 60 volatile flash_t *BA; | |
| 61 flash_t stat = 0; | |
| 62 int timeout = 50000; | |
| 63 int cache_on; | |
| 64 #ifdef FLASH_Write_Buffer | |
| 65 int i, wc; | |
| 66 #endif | |
| 67 | |
| 68 HAL_DCACHE_IS_ENABLED(cache_on); | |
| 69 if (cache_on) { | |
| 70 HAL_DCACHE_SYNC(); | |
| 71 HAL_DCACHE_DISABLE(); | |
| 72 } | |
| 73 | |
| 74 // Get base address and map addresses to virtual addresses | |
| 75 ROM = FLASH_P2V( CYGNUM_FLASH_BASE_MASK & (unsigned int)addr ); | |
| 76 BA = FLASH_P2V( block_mask & (unsigned int)addr ); | |
| 77 addr = FLASH_P2V(addr); | |
| 78 | |
| 79 // Clear any error conditions | |
| 80 ROM[0] = FLASH_Clear_Status; | |
| 81 | |
| 82 #ifdef FLASH_Write_Buffer | |
| 83 // Write any big chunks first | |
| 84 while (len >= buffer_size) { | |
| 85 wc = buffer_size; | |
| 86 if (wc > len) wc = len; | |
| 87 len -= wc; | |
| 88 wc = wc / (CYGNUM_FLASH_DEVICES*2); // Word count | |
| 89 *BA = FLASH_Write_Buffer; | |
| 90 timeout = 5000000; | |
| 91 while(((stat = ROM[0]) & FLASH_Status_Ready) != FLASH_Status_Ready) { | |
| 92 if (--timeout == 0) { | |
| 93 goto bad; | |
| 94 } | |
| 95 *BA = FLASH_Write_Buffer; | |
| 96 } | |
| 97 *BA = FLASHWORD(wc-1); // Count is 0..N-1 | |
| 98 for (i = 0; i < wc; i++) { | |
| 99 *addr++ = *data++; | |
| 100 } | |
| 101 *BA = FLASH_Confirm; | |
| 102 | |
| 103 ROM[0] = FLASH_Read_Status; | |
| 104 timeout = 5000000; | |
| 105 while(((stat = ROM[0]) & FLASH_Status_Ready) != FLASH_Status_Ready) { | |
| 106 if (--timeout == 0) { | |
| 107 goto bad; | |
| 108 } | |
| 109 } | |
| 110 } | |
| 111 #endif | |
| 112 | |
| 113 while (len > 0) { | |
| 114 ROM[0] = FLASH_Program; | |
| 115 *addr = *data; | |
| 116 timeout = 5000000; | |
| 117 while(((stat = ROM[0]) & FLASH_Status_Ready) != FLASH_Status_Ready) { | |
| 118 if (--timeout == 0) { | |
| 119 goto bad; | |
| 120 } | |
| 121 } | |
| 122 if (stat & FLASH_ErrorMask) { | |
| 123 break; | |
| 124 } | |
| 125 ROM[0] = FLASH_Reset; | |
| 126 if (*addr++ != *data++) { | |
| 127 stat = FLASH_ErrorNotVerified; | |
| 128 break; | |
| 129 } | |
| 130 len -= sizeof( flash_t ); | |
| 131 } | |
| 132 | |
| 133 // Restore ROM to "normal" mode | |
| 134 bad: | |
| 135 ROM[0] = FLASH_Reset; | |
| 136 | |
| 137 if (cache_on) { | |
| 138 HAL_DCACHE_ENABLE(); | |
| 139 } | |
| 140 | |
| 141 return stat; | |
| 142 } |
