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

📄 l2_nand.c

📁 台湾凌阳方案300万数码相机源代码
💻 C
字号:
/*++

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"

//=============================================================================
//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;
		
        //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;
                }
        }

        *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
}

//-----------------------------------------------------------------------------
//L2_NANDWritePort
//-----------------------------------------------------------------------------
/* 
routine description:
        Write the NAND gate flash data port
arguments:
        PortData : write data
return value:
        None
*/
void L2_NANDWritePort(UCHAR PortData) USING_0
{
        //PRINT_L2("        L2_NANDWritePort: Enter L2_NANDWritePort(PortData=8'h%x)\n",(USHORT)PortData);

        XBYTE[0x2420] = PortData;

        //PRINT_L2("        L2_NANDWritePort: Exit L2_NANDWritePort\n");
}

//-----------------------------------------------------------------------------
//L2_NANDReadPort
//-----------------------------------------------------------------------------
/* 
routine description:
        Read the NAND gate flash data port
arguments:
        PortData : read data
return value:
        None
*/
void L2_NANDReadPort(UCHAR* PortData) USING_0
{
        UCHAR tmp0;

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

        tmp0 = XBYTE[0x2420];
        *PortData = tmp0;

        //PRINT_L2("            L2_NANDReadPort: PortData = 8'h%x \n",(USHORT)tmp0);
        //PRINT_L2("        L2_NANDReadPort: Exit L2_NANDReadPort\n");         
}

⌨️ 快捷键说明

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