?? romdrv_old_back.c
字號:
/***************************************************************************************\
*
* Copyright (c) 2001 National ASIC Center, All Rights Reserved
*
* File Name : romdrv.c
* Version : 1.0
* Programmer : longn_qi
*
* Date of Creation: 2001/11/26
* Date of Last Modify: 2001/11/27
*
* Description: This is an application file for simulating ROM.
*
* Local Function List:
* void InitROM( )
* void FlashUnlockBlock( U32 Address ) (empty)
* void FlashLockBlock( U32 Address ) (empty)
* void FlashEraseBlock( U32 Address )
* unsigned char FlashWriteByte( U32 Address, unsigned char Data )
* U32 FlashWriteBlock( U32 Address, U32 Data, unsigned long len )
* void CopyFlashProgram( ) (empty)
* void WriteFlashProgram( U32 address, U32 data, unsigned long len ) (empty)
* unsigned long FlashReadByte( U32 Address, unsigned char buffer )
* unsigned long FlashReadBlock( U32 Address, U32 buffer, unsigned long len )
*
* Global Variable List:
* None
*
* Note: Further file description refers to simdrv.txt
*
***************************************************************************************
*
* Modification History
*
* 2001/11/27 by longn_qi add functions "FlashReadByte" and "FlashReadBlock".
* 2001/11/26 by longn_qi create file
*
\***************************************************************************************/
/* System or Standard Header */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>//2002
#include "cdevice.h"
//#include <hardware\drball\reg.h>
//#include <hardware\drball\m68328.h>
#include "ppsmtype.h"
#include "ppsmmsg.h"
//#include <ppsm\ppsm.h>
////#include <hardware\drball\reg.h>
#include "m68328.h"
#include "asixsys.h"
#include "flash.h"
#include "lmalloc.h"
#include "Nucleus.h"
#include "pcdisk.h"
#include "fs.h"
#define FLASH_WRITE_ENABLE // *(P_U16)CSA0 &=0x7fff;
#define FLASH_WRITE_DISABLE // *(P_U16)CSA0 |=0x8000;
U32 g_nor_blknum; //gfd Nor flash buffer blk num;
UINT8 g_nor_buf[256*1024];
UINT8 *nor_rd_pages[NUM_RAMDISK_PAGES];
UINT16 nor_rd_opencount = 0;
typedef void (* FBP)(U32 Address);
typedef unsigned char (* FWP)(U32 Address,unsigned char Data);
typedef U32 (* FWBP)(U32 Address,U32 Data,unsigned long len);
typedef unsigned long (* FRP)(unsigned char buffer, U32 Address);
typedef unsigned long (* FRBP)(U32 buffer,U32 Address,unsigned long len);
FBP FlashUnlockBlockP = (FBP)FlashUnlockBlock;
FBP FlashLockBlockP = (FBP)FlashLockBlock;
FBP FlashEraseBlockP = (FBP)FlashEraseBlock;
FWP FlashWriteByteP = (FWP)FlashWriteByte;
FWBP FlashWriteBlockWordP = (FWBP)FlashWriteBlockWord;
////FWBP FlashWriteBlockP = (FWBP)FlashWriteBlock;
FWBP FlashWriteBlockP = (FWBP)FlashWriteBlockWord;
void InitROM(void )
{
g_nor_blknum = 0;
drv_flash_read(( unsigned char *)g_nor_buf, (unsigned int *)(g_nor_blknum*512*512 + FAT_FLASH_STARTADD), FLASH_AREA_SIZE);
}
void FlashUnlockBlock(U32 Address)
{
U32 Sr,i;
R_U32 tempAddr;
U32 mid;
U32 IMRTemp;
U32 counter;
U32 temp = 0;
/*
mid = Address;
mid = mid-(mid& 0x00000003);
tempAddr = (R_U32)mid;
*tempAddr = 0x600060;
*tempAddr = 0xd000d0; //Write the control word in
for(i=0; i<1000; i++);
counter = 0;
*tempAddr = 0x700070;
mid = *tempAddr;
while( mid != 0x800080)
{
*tempAddr = 0x700070;
mid = *tempAddr;
counter++;
if(counter > 10000)
break;
} //Wait for the status register
*tempAddr = 0xff00ff;
*/
*(R_U32)Address = 0x600060;
*(R_U32)Address = 0xd000d0;
*(R_U32)Address = 0x700070;
temp = *(R_U32)Address;
//// while( temp != 0x800080 )
while( (*(R_U32)Address) != 0x800080 )
{
temp = *(R_U32)Address ;
}
}
void FlashLockBlock(U32 Address)
{
U32 Sr,i;
R_U32 tempAddr;
U32 mid;
U32 IMRTemp;
U32 counter;
mid = Address;
mid = mid-(mid&0x00000003);
tempAddr = (R_U32)mid;
*tempAddr = 0x600060;
*tempAddr = 0x010001;
for(i=0; i<100000; i++);
counter = 0;
*tempAddr = 0x700070;
mid = *tempAddr;
while( mid != 0x800080)
{
*tempAddr = 0x700070;
mid = *tempAddr;
counter++;
if(counter > 100000)
break;
}
*tempAddr = 0xff00ff;
}
void FlashEraseBlock(U32 Address)
{
U32 Sr;
R_U32 tempAddr;
U32 mid;
U32 IMRTemp;
U32 counter;
mid = Address;
mid = mid-(mid& 0x00000003) ;
tempAddr = (R_U32)mid;
*tempAddr = 0x200020;
*tempAddr = 0xd000d0;
for(Sr=0; Sr<80000; Sr++);
counter = 0;
*tempAddr = 0x700070;
mid = *tempAddr;
while( mid != 0x800080)
{
*tempAddr = 0x700070;
for(Sr=0; Sr<20000; Sr++);
mid = *tempAddr;
counter++;
if(counter > 10000)
break;
}
*tempAddr = 0xff00ff;
}
U8 FlashWriteByte(U32 Address, U8 Data)
{
U32 IMRTemp,datatemp,k;
U32 temp,mid;
R_U32 tempAddr;
U32 counter;
U32 tempdata = Data;
U32 retrytimes = 0;
RETRY_WRITE_BYTE:
datatemp = *(R_U32)(Address - (Address&0x00000003));
if( (Address&0x00000003 ) == 0)
{
temp = tempdata | (datatemp & 0xffffff00);
}
else if( (Address&0x00000003 ) == 0x1)
{
temp = (tempdata << 8) | (datatemp & 0xffff00ff);
}
else if( (Address &0x00000003 ) == 0x2)
{
temp = (tempdata << 16) | (datatemp & 0xff00ffff);
}
else if( (Address&0x00000003) == 0x3)
{
temp = (tempdata << 24) | (datatemp & 0x00ffffff);
}
tempAddr = (R_U32)( Address - (Address&0x00000003));
counter = 0;
*tempAddr = 0x400040;
*tempAddr = temp;
for(k=0; k<600; k++);
*tempAddr = 0x700070;
mid = *tempAddr;
while( mid != 0x800080)
{
*tempAddr = 0x700070;
mid = *tempAddr;
counter++;
if(counter > 100000)
break;
}
*tempAddr = 0x500050;
*tempAddr = 0xff00ff;
if(*tempAddr != temp) //judge
{
if(retrytimes++ <5)
goto RETRY_WRITE_BYTE; ////gfd
return(Address);
}
}
U32 FlashWriteBlockWord(U32 Address, U32 DataPoint, U32 len) //len--byte numbers; need modify deeplier
{
U32 i,mid,rawAddress,k;
S32 lenX;
U32 num, r;
R_U32 tempAddr;
U32 temp, temp32;
U32 counter;
U32 retrytimes=0;
rawAddress = Address;
if( len==0 )
return(0);
if(len < 4)
{
for(i = 0; i < len; i++)
{
FlashWriteByte(Address,*(P_U8)DataPoint);
DataPoint += 1;
Address += 1;
}
return( 0);
}
if( (Address & 0x00000003) != 0x0) //judge adress end
{
if(len > 0)
{
if( (Address & 0x00000003) == 0x1)
{
FlashWriteByte(Address,*(P_U8)DataPoint);
DataPoint += 1;
Address += 1;
FlashWriteByte(Address,*(P_U8)DataPoint);
DataPoint+= 1;
Address += 1;
FlashWriteByte(Address,*(P_U8)DataPoint);
DataPoint += 1;
Address += 1;
}
else if( (Address & 0x00000003) == 0x2)
{
FlashWriteByte(Address,*(P_U8)DataPoint);
DataPoint += 1;
Address += 1;
FlashWriteByte(Address,*(P_U8)DataPoint);
DataPoint += 1;
Address += 1;
}
else if( (Address & 0x00000003 ) == 0x3)
{
FlashWriteByte(Address,*(P_U8)DataPoint);
DataPoint += 1;
Address += 1;
}
len = len -(rawAddress & 0x00000003);
}
}
lenX = len;
num = lenX>>2;
r = lenX & 0x00000003;
for(i = 0; i < num; i++)
{
RETRY_WRITE:
tempAddr = (R_U32)(Address);
if(DataPoint & 0x3)
{
temp = *(P_U8)DataPoint;
DataPoint +=1;
temp32= *(P_U8)DataPoint;
temp |= (temp32 <<8);
DataPoint +=1;
temp32= *(P_U8)DataPoint;
temp |= (temp32 <<16);
DataPoint +=1;
temp32= *(P_U8)DataPoint;
temp |= (temp32 <<24);
DataPoint +=1;
}
else temp = *(R_U32)DataPoint;
*tempAddr = 0x400040;
*tempAddr = temp;
for(k=0; k<600; k++);
counter = 0;
*tempAddr = 0x700070;
mid = *tempAddr;
while( mid != 0x800080)
{
*tempAddr = 0x700070;
mid = *tempAddr;
counter++;
if(counter > 10000000)
break;
}
*tempAddr = 0xff00ff;
if(*tempAddr != temp) //judge
{
if(retrytimes++ <5)
goto RETRY_WRITE; ////gfd
return(Address);
}
Address += 4 ;
DataPoint += 4;
}
for(i = 0; i < r; i++) //fill left butes of lenX
{
FlashWriteByte(Address,*(P_U8)DataPoint);
DataPoint += 1;
Address += 1;
}
*tempAddr = 0xff00ff;
return(0);
}
U32 FlashWriteBlock(U32 Address, U32 DataPoint, U32 len)
{
U32 i;
S32 lenX;
U32 IMRTemp, rawAddress;
R_U32 tempAddr;
U16 x,y,temp;
U32 mid;
P_U8 addr8;
U8 temp8;
U32 counter, BufferCount,counter1;
rawAddress = Address;
lenX = len;
if( lenX==0 )
return(0);
if( (Address % 4) != 0x0) //judge adress end, and fill fore superabundance bytes.
{
if(lenX > 0)
{
if( (Address % 4 ) == 0x1)
{
FlashWriteByte(Address,*(P_U8)DataPoint);
DataPoint++;
Address++;
FlashWriteByte(Address,*(P_U8)DataPoint);
DataPoint++;
Address++;
FlashWriteByte(Address,*(P_U8)DataPoint);
DataPoint++;
Address++;
}
else if( (Address % 4 ) == 0x2)
{
FlashWriteByte(Address,*(P_U8)DataPoint);
DataPoint++;
Address++;
FlashWriteByte(Address,*(P_U8)DataPoint);
DataPoint++;
Address++;
}
else if( (Address % 4 ) == 0x3)
{
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -