📄 flashspecificnab.c
字号:
/*
* COPYRIGHT (c) 1995,2000 TriMedia Technologies Inc.
*
* +-----------------------------------------------------------------+
* | THIS SOFTWARE IS FURNISHED UNDER A LICENSE AND MAY ONLY BE USED |
* | AND COPIED IN ACCORDANCE WITH THE TERMS AND CONDITIONS OF SUCH |
* | A LICENSE AND WITH THE INCLUSION OF THE THIS COPY RIGHT NOTICE. |
* | THIS SOFTWARE OR ANY OTHER COPIES OF THIS SOFTWARE MAY NOT BE |
* | PROVIDED OR OTHERWISE MADE AVAILABLE TO ANY OTHER PERSON. THE |
* | OWNERSHIP AND TITLE OF THIS SOFTWARE IS NOT TRANSFERRED. |
* +-----------------------------------------------------------------+
*
* Module name : FlashSpecificNAB.c 1.7
*
* Title : Low level flash manipulation routines
*
* Last update : 11:38:44 - 00/06/19
*
* Reviewed :
*
* Revision history :
*
* Description : Implementation of flash access functions
* for Philips NAB board (containing Am29f016B).
*
*/
/*------------------------------- Includes -----------------------------------*/
#include "tmlib/tmtypes.h"
/*************************** NAB Specific Defines *****************************/
#define MY_FLASH_BASE 0xFF400000
#define MY_SZOF_FLASH_BLOCK 0x40000
#define MY_NROF_FLASH_BLOCKS 32
#define FLASH_BASE ((Address)MY_FLASH_BASE)
Int SZOF_FLASH_BLOCK = (Int) MY_SZOF_FLASH_BLOCK;
Int NROF_FLASH_BLOCKS = (Int) MY_NROF_FLASH_BLOCKS;
#define RETRY_COUNT 20
/******************************************************************************/
/* FLASH erase */
/******************************************************************************/
Bool FLASH_block_erase(UInt ab, Bool check_if_necessary)
{
Int i;
volatile UInt32 *blockbase = (Pointer) ( FLASH_BASE + ab*SZOF_FLASH_BLOCK );
volatile UInt32 *flashbase = (Pointer) FLASH_BASE;
if (check_if_necessary) {
Int i;
UInt32 *pt = (Pointer)blockbase;
Bool necessary = False;
for (i = 0; i < (SZOF_FLASH_BLOCK / sizeof (Int)); i++) {
if (*(pt++) != 0xffffffff) {
necessary = True;
break;
}
}
if (!necessary) {
return True;
}
}
for (i=0; i<RETRY_COUNT; i++) {
flashbase[0x555] = 0xAAAAAAAA;
flashbase[0x2AA] = 0x55555555;
flashbase[0x555] = 0x80808080;
flashbase[0x555] = 0xAAAAAAAA;
flashbase[0x2AA] = 0x55555555;
blockbase[0x000] = 0x30303030;
while ( (*blockbase ^ *blockbase) & 0x40404040) {}
if ((*blockbase) == 0xffffffff) { return True; }
}
return False;
}
/******************************************************************************/
/* FLASH write */
/******************************************************************************/
Bool
FLASH_write(Pointer address, UInt32 data)
{
Int i;
volatile UInt32 *addr = (Pointer)(FLASH_BASE+(UInt)address);
volatile UInt32 *flashbase = (Pointer) FLASH_BASE;
UInt32 old_data = *addr;
UInt32 new_data = old_data & data;
if (new_data == old_data) {
return data == new_data;
}
for (i=0; i<RETRY_COUNT; i++) {
flashbase[0x555] = 0xAAAAAAAA;
flashbase[0x2AA] = 0x55555555;
flashbase[0x555] = 0xA0A0A0A0;
*addr = new_data;
while ( (*addr ^ *addr) & 0x40404040) {}
if (*addr == new_data) { return True; }
}
return False;
}
Bool
FLASH_block_write( Pointer flash, Pointer image, Int nrof_words )
{
Int32 *f = ((Int32*)flash) + nrof_words;
Int32 *i = ((Int32*)image) + nrof_words;
Bool result;
do {
result = FLASH_write( --f, *(--i) );
} while ((Pointer)f != flash && result);
return result;
}
/******************************************************************************/
/* FLASH read */
/******************************************************************************/
UInt32
FLASH_read(Pointer address)
{
UInt32 *addr= (Pointer)(FLASH_BASE+(UInt)address);
return *addr;
}
void
FLASH_block_read( Pointer flash, Pointer image, Int nrof_words )
{
Int32 *f = ((Int32*)flash);
Int32 *i = ((Int32*)image);
while (nrof_words--) {
*(i++) = FLASH_read( f++ );
}
}
Bool
FLASH_init()
{
return True;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -