l2_nand.c

来自「凌阳MP3 spSPCA755yuanma」· C语言 代码 · 共 199 行

C
199
字号
/*++

Copyright (c) 2001 Sunplus Technology Co., Ltd.

Module Name:

        L2_nand.c

Abstract:

        Module related to L2 NAND flash functions

Environment:

        Keil C51 Compiler

Revision History:

        11/12/2001      WZH    created                 
--*/
//=============================================================================
//Header file
//=============================================================================
#include "general.h"

#if (SMC || NAND)	// 110102@wyeo
//=============================================================================
//Symbol
//=============================================================================
//-----------------------------------------------------------------------------
//Constant
//-----------------------------------------------------------------------------

//-----------------------------------------------------------------------------
//Variable
//-----------------------------------------------------------------------------

//=============================================================================
//Program       
//=============================================================================

//-----------------------------------------------------------------------------
//L2_NANDInit
//-----------------------------------------------------------------------------
/* 
routine description:
        NAND gate flash interface initialization
arguments:
        ActiveCycle : the read/write strobe pulse widht in DMA
                0 - 15:  from 1T(20.83ns) to 16T(333.28ns)
        RecoverCycle: the recovery time in DMA
                0 - 15:  from 1T(20.83ns) to 16T(333.28ns)
return value:
        0x00   - success
        others - error
*/
UCHAR L2_NANDInit(UCHAR ActiveCycle, UCHAR RecovCycle) USING_0
{
        //PRINT_L2("        L2_NANDInit: Enter L2_NANDInit(ActiveCycle=8'h%x,RecovCycle=8'h%x)\n",(USHORT)ActiveCycle,(USHORT)RecovCycle);

        XBYTE[0x2421] = (RecovCycle<<4)|ActiveCycle;
        XBYTE[0x2423] = 0x02;
	XBYTE[0x2421] = 0x9d;	//WWTEST
		
        //PRINT_L2("        L2_NANDInit: Exit L2_NANDInit\n");
        return L2K_SUCCESS;
}

//-----------------------------------------------------------------------------
//L2_NANDSendCmd
//-----------------------------------------------------------------------------
/* 
routine description:
        Do the send command phase
arguments:
        Cmd : the command to be sent
return value:
        None
*/
UCHAR L2_NANDSendCmd(UCHAR Cmd) USING_0
{
        //PRINT_L2("        L2_NANDSendCmd: Enter L2_NANDSendCmd(Cmd=8'h%x)\n",(USHORT)Cmd);
        XBYTE[0x2423] = 0x0A;
	XBYTE[0x2420] = Cmd;
        XBYTE[0x2423] = 0x02;

        //PRINT_L2("        L2_NANDSendCmd: Exit L2_NANDSendCmd\n");

        return L2K_SUCCESS;
}

//-----------------------------------------------------------------------------
//L2_NANDSendAddr
//-----------------------------------------------------------------------------
/* 
routine description:
        Do the NAND gate flash address phase
arguments:
        Count: the number of byte for address
        Addr: the address to be sent 
                if Count = 1, Addr[7:0] is sent
		if Count = 2, Addr[7:0], Addr[15:8] is sent
		if Count = 3, Addr[7:0], Addr[15:8], Addr[23:16] is sent
		if Count = 4, Addr[7:0], Addr[15:8], Addr[23:16], Addr[31:24] is sent
return value:
        None
*/
UCHAR L2_NANDSendAddr(UCHAR Count, ULONG Addr) USING_0
{
        //PRINT_L2("        L2_NANDSendAddr: Enter L2_NANDSendAddr(Addr=32'h%lx)\n",Addr);
        XBYTE[0x2423] = 0x06;
	if(Count==0) ;
	else if(Count==1) XBYTE[0x2420] = (UCHAR)Addr&0xff;
	else if(Count==2)
        {
                XBYTE[0x2420] = (UCHAR)Addr&0xff;
                XBYTE[0x2420] = (UCHAR)(Addr>>8)&0xff;
        }
        else if(Count==3)
        {
                XBYTE[0x2420] = (UCHAR)Addr&0xff;
                XBYTE[0x2420] = (UCHAR)(Addr>>8)&0xff;
                XBYTE[0x2420] = (UCHAR)(Addr>>16)&0xff;
        }
	else if(Count==4)
        {
                XBYTE[0x2420] = (UCHAR)Addr&0xff;
                XBYTE[0x2420] = (UCHAR)(Addr>>8)&0xff;
                XBYTE[0x2420] = (UCHAR)(Addr>>16)&0xff;
                XBYTE[0x2420] = (UCHAR)(Addr>>24)&0xff;
        }
	else return 0x01;

        XBYTE[0x2423] = 0x02;

        //PRINT_L2("        L2_NANDSendAddr: Exit L2_NANDSendAddr\n");

        return L2K_SUCCESS;
}

//-----------------------------------------------------------------------------
//L2_NANDCheckRdy
//-----------------------------------------------------------------------------
/* 
routine description:
        Check the NAND gate flash ready pin
arguments:
        Ready: 
                0: busy
                1: ready
return value:
        None
*/
void L2_NANDCheckRdy(UCHAR* Ready) USING_0
{
        UCHAR tmp0;
        WORD  timeOut = 6000;

        //PRINT_L2("        L2_NANDCheckRdy: Enter L2_NANDCheckRdy\n");

	tmp0 = 0x00;

        while ((XBYTE[0x2424] & 0x01) == 0x00)
        {
                timeOut--;
                if (timeOut == 0)
                {
						tmp0 = 0x02;
                        break;
                }
        }
//		 DbgPrint(" %d \n",timeOut);

        *Ready = tmp0;

        //PRINT_L2("            L2_NANDCheckRdy: Ready = 8'h%x (0 is for ready)\n",(USHORT)tmp0);
        //PRINT_L2("        L2_NANDCheckRdy: Exit L2_NANDCheckRdy\n");
}

//-----------------------------------------------------------------------------
//L2_NANDCompleteOperation
//-----------------------------------------------------------------------------
/* 
routine description:
        when operation complete, disable NAND gate flash chip select pin
arguments:
        None
return value:
        None
*/
void L2_NANDCompleteOperation(void) USING_0  //ada@0227
{
                            // CLE  ALE  /WP  /CE
    XBYTE[0x2423] = 0x03;   //   0    0    1    1
}

#endif 	// 110102@wyeo

⌨️ 快捷键说明

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