URL
https://opencores.org/ocsvn/openrisc_me/openrisc_me/trunk
Subversion Repositories openrisc_me
Compare Revisions
- This comparison shows the changes necessary to convert path
/openrisc/trunk/rtos/ecos-2.0/packages/devs/flash/mips/atlas/v2_0/src
- from Rev 27 to Rev 174
- ↔ Reverse comparison
Rev 27 → Rev 174
/flash_lock_block.c
0,0 → 1,89
//========================================================================== |
// |
// flash_lock_block.c |
// |
// Flash programming |
// |
//========================================================================== |
//####ECOSGPLCOPYRIGHTBEGIN#### |
// ------------------------------------------- |
// This file is part of eCos, the Embedded Configurable Operating System. |
// Copyright (C) 1998, 1999, 2000, 2001, 2002 Red Hat, Inc. |
// |
// eCos is free software; you can redistribute it and/or modify it under |
// the terms of the GNU General Public License as published by the Free |
// Software Foundation; either version 2 or (at your option) any later version. |
// |
// eCos is distributed in the hope that it will be useful, but WITHOUT ANY |
// WARRANTY; without even the implied warranty of MERCHANTABILITY or |
// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
// for more details. |
// |
// You should have received a copy of the GNU General Public License along |
// with eCos; if not, write to the Free Software Foundation, Inc., |
// 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. |
// |
// As a special exception, if other files instantiate templates or use macros |
// or inline functions from this file, or you compile this file and link it |
// with other works to produce a work based on this file, this file does not |
// by itself cause the resulting work to be covered by the GNU General Public |
// License. However the source code for this file must still be made available |
// in accordance with section (3) of the GNU General Public License. |
// |
// This exception does not invalidate any other reasons why a work based on |
// this file might be covered by the GNU General Public License. |
// |
// Alternative licenses for eCos may be arranged by contacting Red Hat, Inc. |
// at http://sources.redhat.com/ecos/ecos-license/ |
// ------------------------------------------- |
//####ECOSGPLCOPYRIGHTEND#### |
//========================================================================== |
//#####DESCRIPTIONBEGIN#### |
// |
// Author(s): gthomas |
// Contributors: gthomas, msalter |
// Date: 2000-12-07 |
// Purpose: |
// Description: |
// |
//####DESCRIPTIONEND#### |
// |
//========================================================================== |
|
#include "flash.h" |
#include <cyg/hal/hal_arch.h> |
|
// |
// CAUTION! This code must be copied to RAM before execution. Therefore, |
// it must not contain any code which might be position dependent! |
// |
|
int |
flash_lock_block(volatile unsigned long *block) |
{ |
volatile unsigned long *ROM; |
unsigned long stat; |
int timeout = 5000000; |
|
FLASH_WRITE_ENABLE(); |
|
block = (volatile unsigned long *)CYGARC_UNCACHED_ADDRESS((unsigned long)block); |
ROM = (volatile unsigned long *)((unsigned long)block & FLASH_BASE_MASK); |
|
// Clear any error conditions |
ROM[0] = FLASH_Clear_Status; |
|
// Set lock bit |
block[0] = FLASH_Set_Lock; |
block[0] = FLASH_Set_Lock_Confirm; // Confirmation |
while(((stat = ROM[0]) & FLASH_Status_Ready) != FLASH_Status_Ready) { |
if (--timeout == 0) break; |
} |
|
// Restore ROM to "normal" mode |
ROM[0] = FLASH_Reset; |
|
FLASH_WRITE_DISABLE(); |
|
return stat; |
} |
/flash_program_buf.c
0,0 → 1,105
//========================================================================== |
// |
// flash_program_buf.c |
// |
// Flash programming |
// |
//========================================================================== |
//####ECOSGPLCOPYRIGHTBEGIN#### |
// ------------------------------------------- |
// This file is part of eCos, the Embedded Configurable Operating System. |
// Copyright (C) 1998, 1999, 2000, 2001, 2002 Red Hat, Inc. |
// |
// eCos is free software; you can redistribute it and/or modify it under |
// the terms of the GNU General Public License as published by the Free |
// Software Foundation; either version 2 or (at your option) any later version. |
// |
// eCos is distributed in the hope that it will be useful, but WITHOUT ANY |
// WARRANTY; without even the implied warranty of MERCHANTABILITY or |
// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
// for more details. |
// |
// You should have received a copy of the GNU General Public License along |
// with eCos; if not, write to the Free Software Foundation, Inc., |
// 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. |
// |
// As a special exception, if other files instantiate templates or use macros |
// or inline functions from this file, or you compile this file and link it |
// with other works to produce a work based on this file, this file does not |
// by itself cause the resulting work to be covered by the GNU General Public |
// License. However the source code for this file must still be made available |
// in accordance with section (3) of the GNU General Public License. |
// |
// This exception does not invalidate any other reasons why a work based on |
// this file might be covered by the GNU General Public License. |
// |
// Alternative licenses for eCos may be arranged by contacting Red Hat, Inc. |
// at http://sources.redhat.com/ecos/ecos-license/ |
// ------------------------------------------- |
//####ECOSGPLCOPYRIGHTEND#### |
//========================================================================== |
//#####DESCRIPTIONBEGIN#### |
// |
// Author(s): gthomas |
// Contributors: gthomas, msalter |
// Date: 2000-12-07 |
// Purpose: |
// Description: |
// |
//####DESCRIPTIONEND#### |
// |
//========================================================================== |
|
#include "flash.h" |
|
#include <pkgconf/hal.h> |
#include <cyg/hal/hal_arch.h> |
|
// |
// CAUTION! This code must be copied to RAM before execution. Therefore, |
// it must not contain any code which might be position dependent! |
// |
|
int |
flash_program_buf(volatile unsigned long *addr, unsigned long *data, int len) |
{ |
volatile unsigned long *ROM; |
unsigned long stat = 0; |
int timeout = 50000; |
|
FLASH_WRITE_ENABLE(); |
|
addr = (volatile unsigned long *)CYGARC_UNCACHED_ADDRESS((unsigned long)addr); |
ROM = (volatile unsigned long *)((unsigned long)addr & FLASH_BASE_MASK); |
|
// Clear any error conditions |
ROM[0] = FLASH_Clear_Status; |
|
while (len > 0) { |
ROM[0] = FLASH_Program; |
*addr = *data; |
timeout = 5000000; |
while(((stat = ROM[0]) & FLASH_Status_Ready) != FLASH_Status_Ready) { |
if (--timeout == 0) { |
goto bad; |
} |
} |
if (stat & 0x007E007E) { |
break; |
} |
ROM[0] = FLASH_Reset; |
if (*addr++ != *data++) { |
stat = 0x99109910; |
break; |
} |
len -= 4; |
} |
|
// Restore ROM to "normal" mode |
bad: |
ROM[0] = FLASH_Reset; |
|
FLASH_WRITE_DISABLE(); |
|
return stat; |
} |
/atlas_flash.c
0,0 → 1,140
//========================================================================== |
// |
// atlas_flash.c |
// |
// Flash programming |
// |
//========================================================================== |
//####ECOSGPLCOPYRIGHTBEGIN#### |
// ------------------------------------------- |
// This file is part of eCos, the Embedded Configurable Operating System. |
// Copyright (C) 1998, 1999, 2000, 2001, 2002 Red Hat, Inc. |
// |
// eCos is free software; you can redistribute it and/or modify it under |
// the terms of the GNU General Public License as published by the Free |
// Software Foundation; either version 2 or (at your option) any later version. |
// |
// eCos is distributed in the hope that it will be useful, but WITHOUT ANY |
// WARRANTY; without even the implied warranty of MERCHANTABILITY or |
// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
// for more details. |
// |
// You should have received a copy of the GNU General Public License along |
// with eCos; if not, write to the Free Software Foundation, Inc., |
// 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. |
// |
// As a special exception, if other files instantiate templates or use macros |
// or inline functions from this file, or you compile this file and link it |
// with other works to produce a work based on this file, this file does not |
// by itself cause the resulting work to be covered by the GNU General Public |
// License. However the source code for this file must still be made available |
// in accordance with section (3) of the GNU General Public License. |
// |
// This exception does not invalidate any other reasons why a work based on |
// this file might be covered by the GNU General Public License. |
// |
// Alternative licenses for eCos may be arranged by contacting Red Hat, Inc. |
// at http://sources.redhat.com/ecos/ecos-license/ |
// ------------------------------------------- |
//####ECOSGPLCOPYRIGHTEND#### |
//========================================================================== |
//#####DESCRIPTIONBEGIN#### |
// |
// Author(s): gthomas |
// Contributors: gthomas, msalter |
// Date: 2000-12-06 |
// Purpose: |
// Description: |
// |
//####DESCRIPTIONEND#### |
// |
//========================================================================== |
|
#include <pkgconf/hal.h> |
#include <cyg/hal/hal_arch.h> |
#include <cyg/hal/hal_cache.h> |
|
#define _FLASH_PRIVATE_ |
#include <cyg/io/flash.h> |
|
#include "flash.h" |
|
#define _si(p) ((p[1]<<8)|p[0]) |
|
int |
flash_hwr_init(void) |
{ |
struct FLASH_query data, *qp; |
extern char flash_query, flash_query_end; |
typedef int code_fun(unsigned char *); |
code_fun *_flash_query; |
int code_len, stat, num_regions, region_size; |
|
// Copy 'program' code to RAM for execution |
code_len = (unsigned long)&flash_query_end - (unsigned long)&flash_query; |
_flash_query = (code_fun *)flash_info.work_space; |
memcpy(_flash_query, &flash_query, code_len); |
|
HAL_DCACHE_SYNC(); // Should guarantee this code will run |
HAL_ICACHE_INVALIDATE_ALL(); // is also required to avoid old contents |
stat = (*_flash_query)(&data); |
|
qp = &data; |
if (/*(qp->manuf_code == FLASH_Intel_code) && */ |
(strncmp(qp->id, "QRY", 3) == 0)) { |
num_regions = _si(qp->num_regions)+1; |
region_size = _si(qp->region_size)*256; |
|
flash_info.block_size = region_size*2; // Pairs of chips in parallel |
flash_info.blocks = num_regions*2; // and pairs of chips in serial |
flash_info.start = (void *)0x9c000000; |
flash_info.end = (void *)0x9e000000; |
return FLASH_ERR_OK; |
} else { |
(*flash_info.pf)("Can't identify FLASH, sorry\n"); |
diag_dump_buf(data, sizeof(data)); |
return FLASH_ERR_HWR; |
} |
} |
|
// Map a hardware status to a package error |
int |
flash_hwr_map_error(int err) |
{ |
if (err & 0x007E007E) { |
(*flash_info.pf)("Err = %x\n", err); |
if (err & 0x00100010) { |
return FLASH_ERR_PROGRAM; |
} else |
if (err & 0x00200020) { |
return FLASH_ERR_ERASE; |
} else |
return FLASH_ERR_HWR; // FIXME |
} else { |
return FLASH_ERR_OK; |
} |
} |
|
// See if a range of FLASH addresses overlaps currently running code |
bool |
flash_code_overlaps(void *start, void *end) |
{ |
extern char _stext[], _etext[]; |
unsigned long p_stext, pstart, p_etext, pend; |
|
p_stext = CYGARC_PHYSICAL_ADDRESS((unsigned long)&_stext); |
p_etext = CYGARC_PHYSICAL_ADDRESS((unsigned long)&_etext); |
|
// if _stext/_etext in boot shadow region, convert to |
// system flash address |
if ((p_stext >= 0x1fc00000) && (p_etext <= 0x20000000)) { |
p_stext -= 0x02000000; |
p_etext -= 0x02000000; |
} |
|
pstart = CYGARC_PHYSICAL_ADDRESS((unsigned long)start); |
pend = CYGARC_PHYSICAL_ADDRESS((unsigned long)end); |
|
return (((p_stext >= pstart) && (p_stext < pend)) || |
((p_etext >= pstart) && (p_etext < pend))); |
} |
/flash.h
0,0 → 1,105
//========================================================================== |
// |
// flash.h |
// |
// Flash programming - device constants, etc. |
// |
//========================================================================== |
//####ECOSGPLCOPYRIGHTBEGIN#### |
// ------------------------------------------- |
// This file is part of eCos, the Embedded Configurable Operating System. |
// Copyright (C) 1998, 1999, 2000, 2001, 2002 Red Hat, Inc. |
// |
// eCos is free software; you can redistribute it and/or modify it under |
// the terms of the GNU General Public License as published by the Free |
// Software Foundation; either version 2 or (at your option) any later version. |
// |
// eCos is distributed in the hope that it will be useful, but WITHOUT ANY |
// WARRANTY; without even the implied warranty of MERCHANTABILITY or |
// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
// for more details. |
// |
// You should have received a copy of the GNU General Public License along |
// with eCos; if not, write to the Free Software Foundation, Inc., |
// 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. |
// |
// As a special exception, if other files instantiate templates or use macros |
// or inline functions from this file, or you compile this file and link it |
// with other works to produce a work based on this file, this file does not |
// by itself cause the resulting work to be covered by the GNU General Public |
// License. However the source code for this file must still be made available |
// in accordance with section (3) of the GNU General Public License. |
// |
// This exception does not invalidate any other reasons why a work based on |
// this file might be covered by the GNU General Public License. |
// |
// Alternative licenses for eCos may be arranged by contacting Red Hat, Inc. |
// at http://sources.redhat.com/ecos/ecos-license/ |
// ------------------------------------------- |
//####ECOSGPLCOPYRIGHTEND#### |
//========================================================================== |
//#####DESCRIPTIONBEGIN#### |
// |
// Author(s): gthomas |
// Contributors: gthomas |
// Date: 2000-07-26 |
// Purpose: |
// Description: |
// |
//####DESCRIPTIONEND#### |
// |
//========================================================================== |
|
#ifndef _FLASH_HWR_H_ |
#define _FLASH_HWR_H_ |
|
#define FLASH_Intel_code 0x89 |
|
#define FLASH_Read_ID 0x00900090 |
#define FLASH_Read_Query 0x00980098 |
#define FLASH_Read_Status 0x00700070 |
#define FLASH_Clear_Status 0x00500050 |
#define FLASH_Status_Ready 0x00800080 |
#define FLASH_Write_Buffer 0x00E800E8 |
#define FLASH_Program 0x00100010 |
#define FLASH_Block_Erase 0x00200020 |
#define FLASH_Set_Lock 0x00600060 |
#define FLASH_Set_Lock_Confirm 0x00010001 |
#define FLASH_Clear_Locks 0x00600060 |
#define FLASH_Clear_Locks_Confirm 0x00D000D0 |
#define FLASH_Confirm 0x00D000D0 |
#define FLASH_Configure 0x00B800B8 |
#define FLASH_Configure_ReadyWait 0x00000000 |
#define FLASH_Configure_PulseOnErase 0x00010001 |
#define FLASH_Configure_PulseOnProgram 0x00020002 |
#define FLASH_Configure_PulseOnBoth 0x00030003 |
#define FLASH_Reset 0x00FF00FF |
|
#define FLASH_BLOCK_SIZE 0x40000 |
|
#define FLASH_Intel_code 0x89 |
|
#define FLASH_BASE_MASK 0xff000000 |
|
// Extended query information |
struct FLASH_query { |
unsigned char manuf_code; |
unsigned char device_code; |
unsigned char _unused0[14]; |
unsigned char id[3]; // Q R Y |
unsigned char _unused1[20]; |
unsigned char device_size; |
unsigned char device_interface[2]; |
unsigned char buffer_size[2]; |
unsigned char is_block_oriented; |
unsigned char num_regions[2]; |
unsigned char region_size[2]; |
}; |
|
#define ATLAS_SFWCTRL *((volatile unsigned *)0xbf000700) |
#define ATLAS_WEN_MAGIC 0xc7 |
|
#define FLASH_WRITE_ENABLE() (ATLAS_SFWCTRL = ATLAS_WEN_MAGIC) |
#define FLASH_WRITE_DISABLE() (ATLAS_SFWCTRL = 0) |
|
#endif // _FLASH_HWR_H_ |
/flash_unlock_block.c
0,0 → 1,130
//========================================================================== |
// |
// flash_unlock_block.c |
// |
// Flash programming |
// |
//========================================================================== |
//####ECOSGPLCOPYRIGHTBEGIN#### |
// ------------------------------------------- |
// This file is part of eCos, the Embedded Configurable Operating System. |
// Copyright (C) 1998, 1999, 2000, 2001, 2002 Red Hat, Inc. |
// |
// eCos is free software; you can redistribute it and/or modify it under |
// the terms of the GNU General Public License as published by the Free |
// Software Foundation; either version 2 or (at your option) any later version. |
// |
// eCos is distributed in the hope that it will be useful, but WITHOUT ANY |
// WARRANTY; without even the implied warranty of MERCHANTABILITY or |
// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
// for more details. |
// |
// You should have received a copy of the GNU General Public License along |
// with eCos; if not, write to the Free Software Foundation, Inc., |
// 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. |
// |
// As a special exception, if other files instantiate templates or use macros |
// or inline functions from this file, or you compile this file and link it |
// with other works to produce a work based on this file, this file does not |
// by itself cause the resulting work to be covered by the GNU General Public |
// License. However the source code for this file must still be made available |
// in accordance with section (3) of the GNU General Public License. |
// |
// This exception does not invalidate any other reasons why a work based on |
// this file might be covered by the GNU General Public License. |
// |
// Alternative licenses for eCos may be arranged by contacting Red Hat, Inc. |
// at http://sources.redhat.com/ecos/ecos-license/ |
// ------------------------------------------- |
//####ECOSGPLCOPYRIGHTEND#### |
//========================================================================== |
//#####DESCRIPTIONBEGIN#### |
// |
// Author(s): gthomas |
// Contributors: gthomas |
// Date: 2000-09-10 |
// Purpose: |
// Description: |
// |
//####DESCRIPTIONEND#### |
// |
//========================================================================== |
|
#include "flash.h" |
|
#include <cyg/hal/hal_arch.h> |
|
// |
// CAUTION! This code must be copied to RAM before execution. Therefore, |
// it must not contain any code which might be position dependent! |
// |
|
// |
// The difficulty with this operation is that the hardware does not support |
// unlocking single blocks. However, the logical layer would like this to |
// be the case, so this routine emulates it. The hardware can clear all of |
// the locks in the device at once. This routine will use that approach and |
// then reset the regions which are known to be locked. |
// |
|
#define MAX_FLASH_BLOCKS 128 |
|
int |
flash_unlock_block(volatile unsigned long *block, int block_size, int blocks) |
{ |
volatile unsigned long *ROM, *bp; |
unsigned long stat; |
int timeout = 5000000; |
unsigned char is_locked[MAX_FLASH_BLOCKS]; |
int i; |
|
FLASH_WRITE_ENABLE(); |
|
block = (volatile unsigned long *)CYGARC_UNCACHED_ADDRESS((unsigned long)block); |
ROM = (volatile unsigned long *)((unsigned long)block & FLASH_BASE_MASK); |
|
// Clear any error conditions |
ROM[0] = FLASH_Clear_Status; |
|
// Get current block lock state. This needs to access each block on |
// the device so currently locked blocks can be re-locked. |
bp = ROM; |
for (i = 0; i < (blocks/2); i++) { |
if (bp == block) { |
is_locked[i] = 0; |
} else { |
*bp = FLASH_Read_Query; |
is_locked[i] = bp[2]; |
} |
bp += block_size / sizeof(*bp); |
} |
|
// Clears all lock bits |
block[0] = FLASH_Clear_Locks; |
block[0] = FLASH_Clear_Locks_Confirm; // Confirmation |
timeout = 5000000; |
while(((stat = ROM[0]) & FLASH_Status_Ready) != FLASH_Status_Ready) { |
if (--timeout == 0) break; |
} |
|
// Restore the lock state |
bp = ROM; |
for (i = 0; i < (blocks/2); i++) { |
if (is_locked[i]) { |
*bp = FLASH_Set_Lock; |
*bp = FLASH_Set_Lock_Confirm; // Confirmation |
timeout = 5000000; |
while(((stat = ROM[0]) & FLASH_Status_Ready) != FLASH_Status_Ready) { |
if (--timeout == 0) break; |
} |
} |
bp += block_size / sizeof(*bp); |
} |
|
// Restore ROM to "normal" mode |
ROM[0] = FLASH_Reset; |
|
FLASH_WRITE_DISABLE(); |
|
return stat; |
} |
/flash_query.c
0,0 → 1,84
//========================================================================== |
// |
// flash_query.c |
// |
// Flash programming - query device |
// |
//========================================================================== |
//####ECOSGPLCOPYRIGHTBEGIN#### |
// ------------------------------------------- |
// This file is part of eCos, the Embedded Configurable Operating System. |
// Copyright (C) 1998, 1999, 2000, 2001, 2002 Red Hat, Inc. |
// |
// eCos is free software; you can redistribute it and/or modify it under |
// the terms of the GNU General Public License as published by the Free |
// Software Foundation; either version 2 or (at your option) any later version. |
// |
// eCos is distributed in the hope that it will be useful, but WITHOUT ANY |
// WARRANTY; without even the implied warranty of MERCHANTABILITY or |
// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
// for more details. |
// |
// You should have received a copy of the GNU General Public License along |
// with eCos; if not, write to the Free Software Foundation, Inc., |
// 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. |
// |
// As a special exception, if other files instantiate templates or use macros |
// or inline functions from this file, or you compile this file and link it |
// with other works to produce a work based on this file, this file does not |
// by itself cause the resulting work to be covered by the GNU General Public |
// License. However the source code for this file must still be made available |
// in accordance with section (3) of the GNU General Public License. |
// |
// This exception does not invalidate any other reasons why a work based on |
// this file might be covered by the GNU General Public License. |
// |
// Alternative licenses for eCos may be arranged by contacting Red Hat, Inc. |
// at http://sources.redhat.com/ecos/ecos-license/ |
// ------------------------------------------- |
//####ECOSGPLCOPYRIGHTEND#### |
//========================================================================== |
//#####DESCRIPTIONBEGIN#### |
// |
// Author(s): gthomas |
// Contributors: gthomas |
// Date: 2000-07-26 |
// Purpose: |
// Description: |
// |
//####DESCRIPTIONEND#### |
// |
//========================================================================== |
|
#include "flash.h" |
|
#include <pkgconf/hal.h> |
#include <cyg/hal/hal_arch.h> |
#include <cyg/hal/hal_cache.h> |
#include CYGHWR_MEMORY_LAYOUT_H |
|
// |
// CAUTION! This code must be copied to RAM before execution. Therefore, |
// it must not contain any code which might be position dependent! |
// |
|
#define CNT 20*1000*10 // Approx 20ms |
|
int |
flash_query(unsigned char *data) |
{ |
volatile unsigned long *ROM; |
int i, cnt; |
|
ROM = (volatile unsigned long *)0xBC000000; // base of system flash |
|
ROM[0] = FLASH_Read_Query; |
for (cnt = CNT; cnt > 0; cnt--) ; |
for (i = 0; i < sizeof(struct FLASH_query); i++) { |
*data++ = *ROM++; |
} |
|
ROM[0] = FLASH_Reset; |
|
return 0; |
} |
/flash_erase_block.c
0,0 → 1,103
//========================================================================== |
// |
// flash_erase_block.c |
// |
// Flash programming |
// |
//========================================================================== |
//####ECOSGPLCOPYRIGHTBEGIN#### |
// ------------------------------------------- |
// This file is part of eCos, the Embedded Configurable Operating System. |
// Copyright (C) 1998, 1999, 2000, 2001, 2002 Red Hat, Inc. |
// |
// eCos is free software; you can redistribute it and/or modify it under |
// the terms of the GNU General Public License as published by the Free |
// Software Foundation; either version 2 or (at your option) any later version. |
// |
// eCos is distributed in the hope that it will be useful, but WITHOUT ANY |
// WARRANTY; without even the implied warranty of MERCHANTABILITY or |
// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
// for more details. |
// |
// You should have received a copy of the GNU General Public License along |
// with eCos; if not, write to the Free Software Foundation, Inc., |
// 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. |
// |
// As a special exception, if other files instantiate templates or use macros |
// or inline functions from this file, or you compile this file and link it |
// with other works to produce a work based on this file, this file does not |
// by itself cause the resulting work to be covered by the GNU General Public |
// License. However the source code for this file must still be made available |
// in accordance with section (3) of the GNU General Public License. |
// |
// This exception does not invalidate any other reasons why a work based on |
// this file might be covered by the GNU General Public License. |
// |
// Alternative licenses for eCos may be arranged by contacting Red Hat, Inc. |
// at http://sources.redhat.com/ecos/ecos-license/ |
// ------------------------------------------- |
//####ECOSGPLCOPYRIGHTEND#### |
//========================================================================== |
//#####DESCRIPTIONBEGIN#### |
// |
// Author(s): gthomas |
// Contributors: gthomas, msalter |
// Date: 2000-12-07 |
// Purpose: |
// Description: |
// |
//####DESCRIPTIONEND#### |
// |
//========================================================================== |
|
#include "flash.h" |
|
#include <pkgconf/hal.h> |
#include <cyg/hal/hal_arch.h> |
#include <cyg/hal/hal_cache.h> |
|
// |
// CAUTION! This code must be copied to RAM before execution. Therefore, |
// it must not contain any code which might be position dependent! |
// |
|
int flash_erase_block(volatile unsigned long *block) |
{ |
volatile unsigned long *ROM; |
unsigned long stat; |
int timeout = 50000; |
int len; |
|
FLASH_WRITE_ENABLE(); |
|
block = (volatile unsigned long *)CYGARC_UNCACHED_ADDRESS((unsigned long)block); |
ROM = (volatile unsigned long *)((unsigned long)block & FLASH_BASE_MASK); |
|
// Clear any error conditions |
ROM[0] = FLASH_Clear_Status; |
|
// Erase block |
ROM[0] = FLASH_Block_Erase; |
*block = FLASH_Confirm; |
timeout = 5000000; |
while(((stat = ROM[0]) & FLASH_Status_Ready) != FLASH_Status_Ready) { |
if (--timeout == 0) break; |
} |
|
// Restore ROM to "normal" mode |
ROM[0] = FLASH_Reset; |
|
// If an error was reported, see if the block erased anyway |
if (stat & 0x007E007E) { |
len = FLASH_BLOCK_SIZE; |
while (len > 0) { |
if (*block++ != 0xFFFFFFFF) break; |
len -= sizeof(*block); |
} |
if (len == 0) stat = 0; |
} |
|
FLASH_WRITE_DISABLE(); |
|
return stat; |
} |