⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 nordrv.c

📁 最近在國外網站抓到的作業系統 以Arm為基礎去開發的
💻 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"
#include "ha_typedef.h"


#if 0														//wuer

#define	FLASH_WRITE_ENABLE	// *(P_U16)CSA0 &=0x7fff;

#define	FLASH_WRITE_DISABLE	// *(P_U16)CSA0 |=0x8000;

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;

#endif  

UINT8 *nor_rd_alloc_page(VOID)
{
        return((UINT8 *)0);
}

VOID   nor_rd_free_page(UINT8 *page)
{

}

INT nor_rd_open(UINT16 driveno)
{
    return(YES);
}

INT nor_rd_close(UINT16 driveno)
{
    return(YES);
}

int nor_rd_io(U16 driveno, U32 page, void FAR *buffer, U16 count, int do_read)
{
	U32 status = YES;
	U32 lenth;
	U32 *tmpbuffer;
	U32 tmpaddr;

	tmpbuffer = (U32 *)buffer;
	tmpaddr = (U32 )((page<<9) + FAT_FLASH_STARTADD);
	lenth = count<<9;

	if(do_read == YES){
		*(U32 *)tmpaddr = 0xff00ff;					//gfd read status
		//judge idle!
		memcpy( (void *)tmpbuffer, (void *)tmpaddr, lenth);
		return YES;		
	}
	else
	{
		status = nor_erase_block (page);
		if(status != YES)
		{
			printf("Nor erase fail!\n");
			return NO;
		}
		status = nor_wr_block (page, (U32*)tmpbuffer,  NO);
		if(status != YES)
		{
			printf("Nor write fail!\n");
			return NO;
		}

		return YES;
	}
	
}


INT nor_rd_raw_open(UINT16 driveno)
{
}
INT nor_rd_ioctl(UINT16 driveno, UINT16 command, VOID *buffer)
{
}

void nor_flush(void)
{
	//drv_flash_write (( unsigned char *) g_nor_buf,( unsigned int *) (g_nor_blknum*512*512 + FAT_FLASH_STARTADD), FLASH_AREA_SIZE );
}

int nor_write_page_format(U32 page, U32 *buffer,  U32 do_read)
{
	U32 status = 0x0L;
	
	status = nor_wr_page(page,buffer);
	if(status != YES)
	{
		printf("nor_write_page_format():fail!\n");
		return NO;
	}
	return YES;
}

int nor_erase_block(U32 page)
{
	U32 i = 0x0L;
	U32 count = 0x0L;
	U32 ststus = 0x0Ll;
	U32 tmpaddr;

	tmpaddr = (U32)(page<<9) + FAT_FLASH_STARTADD;
	
	*(RP)tmpaddr = 0x200020;
	*(RP)tmpaddr = 0xd000d0;
	
	for(i=0; i<80000; i++);
	
	*(RP)tmpaddr = 0x700070;
	//for(i=0; i<100; i++);
	ststus  = *(RP)tmpaddr;
	while( ststus != 0x800080)
	{	
		*(RP)tmpaddr = 0x700070;
		for(i=0; i<20000; i++);				//0x2000
		ststus  = *(RP)tmpaddr;
		count++;
		if(count > 10000)
			break;
	}
	if(count > 10000) 
		return NO;					//time out error
	
	*(RP)tmpaddr = 0xff00ff;
	
	return YES;
	
}


int nor_wr_block (U32 page, U32*buffer,  U32 do_read)
{
	int i,status;
	U32 *tempbuff;
		
	tempbuff = buffer;
	
	for(i=0; i<512; i++){
		status = nor_wr_page(page, (U32*)tempbuff);
		if(status != YES)
		{
			printf("Nor write fail!at 0x%x\n",page);
			return NO;
		}
		page ++;
		tempbuff += 128;
	}

	//printf("NOR_rd_block():page [%08d] [0x%08x] [%s]\n",page, (U32)buffer, do_read?"R":"W");
	return YES;
	
}

int nor_wr_page(U32 page, U32*buffer)		//	ONLY WRITE!
{
	U32 temp,i,j,counter,retrytime;
	U32 tempaddr = (U32)(page<<9) + FAT_FLASH_STARTADD;
	U32 *tempbuff = buffer;
	U32 data;
	
	for(j=0;j<128;j++)
	{
		data = *(RP)tempbuff;
		
		*(RP)tempaddr = 0x400040;
		*(RP)tempaddr = data;
		for(i=0; i<600; i++);
		
		counter = 0;
		*(RP)tempaddr = 0x700070;
		//for(i=0; i<100; i++);
		temp  = *(RP)tempaddr;
		while( temp != 0x800080)
		{	
			*(RP)tempaddr = 0x700070;
			//for(i=0; i<100; i++);
			counter++;
			if(counter > 10000)
			{
				printf("write time out\tpage=%d\n",page);
				return NO;
			}
			temp  = *(RP)tempaddr;
		}
		*(RP)tempaddr = 0x500050;
		*(RP)tempaddr = 0xff00ff;
		//for(i=0; i<100; i++);
		temp= *(RP)tempaddr;
		if(temp != *(RP)tempbuff)					//judge
		{
			printf("write err addr=0x%x\n\n",tempaddr);
			//return NO;
		}
		tempaddr += 4 ;
		tempbuff ++;
	}

	return YES;
}

#if 0
int nor_write_word(U32 page, U32*buffer, U32 num)
{
	U32	j,i = 0x0L;
	U32	status = 0x0L;
	U32	counter = 0x0L;
	U32  tempAddr = (U32)(page<<9) + FAT_FLASH_STARTADD;
	U32 *tempbuff = buffer;
	U32 retrytimes = 0;
	U32 data;
	
	for(j = 0; j<num; j++)
	{
		data = *(RP)tempbuff;
	RETRY_WRITE_BYTE:
		
		counter = 0;
		
		*(RP)tempAddr = 0x400040;
		*(RP)tempAddr = data;
		
		for(i=0; i<600; i++);	
		*(RP)tempAddr = 0x700070;
		//for(i=0; i<100; i++);
		status  = *(RP)tempAddr;
		while( status != 0x800080)
		{	
			*(RP)tempAddr = 0x700070;
			//for(i=0; i<100; i++);
			status  = *(RP)tempAddr;			
			counter++;
			if(counter > 10000)
			 	break;
		}
		if(counter > 10000)
		{	
			printf("nor_write_word():timeout at 0x%x\n",tempAddr);
			return NO;
		}
		
		*(RP)tempAddr = 0x500050;
		*(RP)tempAddr = 0xff00ff;
		for(i=0; i<100; i++);
		if(*(RP)tempAddr != data)						//judge
		{
			if(retrytimes++ <5)
			goto	RETRY_WRITE_BYTE;					////gfd
			printf("nor_write_word():at 0x%x error\n",tempAddr);
			return NO;
		}

		tempbuff++;
		tempAddr += 0X4 ;
		}
	return YES;
}
#endif

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -