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

📄 l2_cf.c

📁 凌阳MP3 spSPCA755yuanma
💻 C
字号:
/*++

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

Module Name:

        L2_cf.c

Abstract:

        Module related to L2 CF card functions

Environment:

        Keil C51 Compiler

Revision History:

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

//=============================================================================
//Symbol
//=============================================================================
//-----------------------------------------------------------------------------
//Constant
//-----------------------------------------------------------------------------

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

//=============================================================================
//Program       
//=============================================================================
#if (CFA)
//-----------------------------------------------------------------------------
//L2_CFInit
//-----------------------------------------------------------------------------
/* 
routine description:
        CF card interface initialization
arguments:
        TrueIDE: 0 mem mode  (8 bits data transfer only)
                 1 IDE mode  (16 bits data DMA is supported)
        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_CFInit(UCHAR TrueIDE, UCHAR ActiveCycle, UCHAR RecovCycle) USING_0
{
        //PRINT_L2("        L2_CFInit: Enter \"L2_CFInit\"(ActiveCycle,RecovCycle)=(8'h%x,8'h%x) \n",(USHORT)ActiveCycle,(USHORT)RecovCycle);

        XBYTE[0x2405] &= 0xdf;            // fmgpio[5] is tri-state for card detect
        XBYTE[0x2435] = (RecovCycle<<4)|ActiveCycle;
	XBYTE[0x24C0] = 0x00;             // reset CFirq
	if(TrueIDE)
        {
                XBYTE[0x2434] = 0x09;
        }
        else
        {
                XBYTE[0x2434] = 0x04;
                XBYTE[0x2436] = 0x00;
                XBYTE[0x2439] = 0x01;
        }

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

	return L2K_SUCCESS;
}

//-----------------------------------------------------------------------------
//L2_CFCardDetect
//-----------------------------------------------------------------------------
/* 
routine description:
        Detect whether CF card is inserted
arguments:
        Detect: 
                0: CF card is not inserted
		1: CF card is inserted

return value:
        0x00   - success
        others - error
*/
/*UCHAR L2_CFCardDetect(UCHAR* Detect) USING_0
{
        *Detect = 0;

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

        XBYTE[0x2405] &= 0xdf;
        if(!(XBYTE[0x2409]&0x20)) *Detect = 1; 

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

	return L2K_SUCCESS;
}
*/
//-----------------------------------------------------------------------------
//L2_CFReset
//-----------------------------------------------------------------------------
/* 
routine description:
        reset CF card 
arguments:
        TrueIDE     : 0 mem mode  (8 bits data transfer only)
                      1 IDE mode  (16 bits data DMA is supported)
return value:
        None
*/
void L2_CFReset(UCHAR TrueIDE) USING_0
{
   	UCHAR  tmp0;
	UCHAR  tmp1;
	UCHAR  tmp2;

	#if (K_CHIP_SET == K_CHIP_533)
        tmp2 = XBYTE[0x2024];
        XBYTE[0x2024] = 0x01;                              // 24 MHz cpu clock
	#elif (K_CHIP_SET == K_CHIP_8591)
//			DbgPrint("CF Reset CPU Clk !!.... \n");
        tmp2 = XBYTE[0x2024];
        XBYTE[0x2024] = 0x02;                              // 24 MHz cpu clock
	#endif

        //PRINT_L2("        L2_CFReset: Enter \"L2_CFReset\"\n"); 
//        DbgPrint("        L2_CFReset: Enter \"L2_CFReset\"\n"); 

        if(TrueIDE)
        {
//			DbgPrint("CF I/F Reset  !!.... \n");
                XBYTE[0x243A] = 0x00;  
                for(tmp0=0;tmp0<0xff;tmp0++)          // 1.5 ms
                        for(tmp1=0;tmp1<0xA0;tmp1++) ;
//			DbgPrint("CF I/F Reset ok !!.... \n");
                XBYTE[0x243A] = 0x01;
        }
		else
        {
                XBYTE[0x243A] = 0x01;
                for(tmp0=0;tmp0<0x05;tmp0++)          // 1.5 ms
                        for(tmp1=0;tmp1<0xA0;tmp1++) ;
                XBYTE[0x243A] = 0x00;
        }

//		DbgPrint("CF Reset CPU Clk End !!.... \n");
		XBYTE[0x2024] = tmp2;

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

//-----------------------------------------------------------------------------
//L2_CFCheckRdy
//-----------------------------------------------------------------------------
/* 
routine description:
        Check if the CF card is ready
arguments:
        Ready:
                0: busy
                1: ready
*/
void L2_CFCheckRdy(UCHAR* Ready) USING_0
{
        //PRINT_L2("        L2_CFCheckRdy: Enter \"L2_CFCheckRdy\"\n");    

        *Ready = XBYTE[0x243B];

        //PRINT_L2("        L2_CFCheckRdy: Exit  \"L2_CFCheckRdy\"\n");
}
#endif


#if (CFAMEM)
//-----------------------------------------------------------------------------
//L2_CFSetMemA (for Memory mode only)
//-----------------------------------------------------------------------------
/* 
routine description:
        Set the CF card high address (Addr[10:3]) & low address (Addr[2:0])
        (for Memory mode only)
arguments:
        LowA:  low address (Addr[2:0])
        HighA: high address (Addr[10:3])
return value:
        0x00   - success
        others - error
*/
UCHAR L2_CFSetMemA(UCHAR HighA,UCHAR LowA) USING_0
{
        //PRINT_L2("        L2_CFSetMemA: Enter \"L2_CFSetMemA\"\n");    

        XBYTE[0x2432] = LowA;
        XBYTE[0x2433] = HighA;
   	
        //PRINT_L2("        L2_CFSetMemA: Exit  \"L2_CFSetMemA\"(Hihg address=8'h%x,Low address=8'h%x)\n",(USHORT)HighA,(USHORT)LowA); 

        return L2K_SUCCESS;
}

//-----------------------------------------------------------------------------
//L2_CFAttrMemWr (for Memory mode only)
//-----------------------------------------------------------------------------
/* 
routine description:
        CF card attribute memory write
        (for Memory mode only)
arguments:
        LowA:  low address (Addr[2:0])
        HighA: high address (Addr[10:3])
        Data
return value:
        0x00   - success
        others - error
*/
UCHAR L2_CFAttrMemWr(UCHAR HighA,UCHAR LowA,UCHAR Data) USING_0
{
        //PRINT_L2("        L2_CFAttrMemWr: Enter \"L2_CFAttrMemWr\"\n");    
    
	XBYTE[0x2439] = 0x00;       // set regnn to low
        XBYTE[0x2432] = LowA;
        XBYTE[0x2433] = HighA;
        XBYTE[0x2430] = Data;       // write data
	while(XBYTE[0x243B]==0) ;   // wait for ready
	XBYTE[0x2439] = 0x01;       // set regnn to high

        //PRINT_L2("        L2_CFAttrMemWr: Exit  \"L2_CFAttrMemWr\"(Hihg address=8'h%x,Low address=8'h%x,Data=8'h%x)\n",(USHORT)HighA,(USHORT)LowA,(USHORT)Data);

        return L2K_SUCCESS;
}

//-----------------------------------------------------------------------------
//L2_CFAttrMemRd (for Memory mode only)
//-----------------------------------------------------------------------------
/* 
routine description:
        CF card attribute memory read
        (for Memory mode only)
arguments:
        LowA:  low address (Addr[2:0])
        HighA: high address (Addr[10:3])
        Data
return value:
        0x00   - success
        others - error
*/
UCHAR L2_CFAttrMemRd(UCHAR HighA,UCHAR LowA,UCHAR* Data) USING_0
{
        //PRINT_L2("        L2_CFAttrMemRd: Enter L2_CFAttrMemRd\n");    
    
	XBYTE[0x2439] = 0x00;       // set regnn to low
	XBYTE[0x2434] = 0x06;       // prefetch byte access
        XBYTE[0x2432] = LowA;
        XBYTE[0x2433] = HighA;
        *Data = XBYTE[0x2430];      // dummy read pulse
        XBYTE[0x2434] = 0x04;       // disable prefetch 
	while(XBYTE[0x243B]==0) ;   // wait for ready
   	*Data = XBYTE[0x2430];      // read data

	XBYTE[0x2439] = 0x01;       // set regnn to high

        //PRINT_L2("        L2_CFAttrMemRd: Exit L2_CFAttrMemRd(Hihg address=8'h%x,Low address=8'h%x,Data=8'h%x)\n",(USHORT)HighA,(USHORT)LowA,(USHORT)*Data);

        return L2K_SUCCESS;
}

//-----------------------------------------------------------------------------
//L2_CFComMemWr (for Memory mode only)
//-----------------------------------------------------------------------------
/* 
routine description:
        CF card common memory write
        (for Memory mode only)
arguments:
        LowA:  low address (Addr[2:0])
        HighA: high address (Addr[10:3])
        Data
return value:
        0x00   - success
        others - error
*/
UCHAR L2_CFComMemWr(UCHAR HighA,UCHAR LowA,UCHAR Data) USING_0
{
        //PRINT_L2("        L2_CFComMemWr: Enter L2_CFComMemWr\n");    
    
	XBYTE[0x2432] = LowA;
        XBYTE[0x2433] = HighA;
        XBYTE[0x2430] = Data;       // write data
	while(XBYTE[0x243B]==0) ;   // wait for ready

        //PRINT_L2("        L2_CFComMemWr: Exit L2_CFComMemWr(Hihg address=8'h%x,Low address=8'h%x,Data=8'h%x)\n",(USHORT)HighA,(USHORT)LowA,(USHORT)Data); 

        return L2K_SUCCESS;
}

//-----------------------------------------------------------------------------
//L2_CFComMemRd (for Memory mode only)
//-----------------------------------------------------------------------------
/* 
routine description:
  CF card common memory read
  (for Memory mode only)
arguments:
        LowA:  low address (Addr[2:0])
        HighA: high address (Addr[10:3])
        Data
return value:
        0x00   - success
        others - error
*/
UCHAR L2_CFComMemRd(UCHAR HighA,UCHAR LowA,UCHAR* Data) USING_0
{
        //PRINT_L2("        L2_CFComMemRd: Enter L2_CFComMemRd\n");    
    
	XBYTE[0x2434] = 0x06;       // prefetch byte access
        XBYTE[0x2432] = LowA;
        XBYTE[0x2433] = HighA;
        *Data = XBYTE[0x2430];      // dummy read pulse
        XBYTE[0x2434] = 0x04;       // disable prefetch 
	while(XBYTE[0x243B]==0) ;   // wait for ready
   	*Data = XBYTE[0x2430];      // read data

        //PRINT_L2("        L2_CFComMemRd: Exit L2_CFComMemRd(Hihg address=8'h%x,Low address=8'h%x,Data=8'h%x)\n",(USHORT)HighA,(USHORT)LowA,(USHORT)*Data); 

        return L2K_SUCCESS;
}
#endif

#if (CFAIDE)
//-----------------------------------------------------------------------------
//L2_CFCheckIRQ (for True IDE mode only)
//-----------------------------------------------------------------------------
/* 
routine description:
        Check the CF card IRQ pin (for True IDE mode only)
arguments:
        ClearIRQ : 0 nothing
                   1 clear the IRQ flag
        IRQ : 0 IRQ pin is low
              1 IRQ pin is high
return value:
        None
*/
void L2_CFCheckIRQ(UCHAR ClearIRQ,UCHAR* IRQ) USING_0
{
        //PRINT_L2("        L2_CFCheckIRQ: Enter L2_CFCheckIRQ\n");

        if(ClearIRQ) XBYTE[0x24C0] = 0x00;
        *IRQ = XBYTE[0x24C0];

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

//-----------------------------------------------------------------------------
//L2_CFSetCsA (for True IDE mode only)
//-----------------------------------------------------------------------------
/* 
routine description:
        Set the CF card Cs & Addr[2:0] (for True IDE mode only)
arguments:
        CsA:
                [0]: Addr[0]
                [1]: Addr[1]
                [2]: Addr[2]
                [3]: Cs[0]
                [4]: Cs[1]
return value:
        0x00   - success
        others - error
*/
UCHAR L2_CFSetCsA(UCHAR CsA) USING_0
{
        UCHAR tmp0,tmp1;

        //PRINT_L2("        L2_CFSetCsA: Enter L2_CFSetCsA\n");
    
	tmp0 = CsA&0x07;
	XBYTE[0x2432] = tmp0;
	tmp1 = (CsA&0x18)>>3;
	XBYTE[0x2436] = tmp1;
   	
        //PRINT_L2("        L2_CFSetCsA: Exit L2_CFSetCsA(Cs=8'h%x,Addr=8'h%x)\n",(USHORT)tmp1,(USHORT)tmp0); 

        return L2K_SUCCESS;
}

//-----------------------------------------------------------------------------
//L2_CFSetWordCsAWr (for True IDE mode)
//-----------------------------------------------------------------------------
/* 
routine description:
        Set the CF card Cs/Addr[2:0] and then write a word to the data bus (for True IDE mode only)
arguments:
        CsA:
                [0]: Addr[0]
                [1]: Addr[1]
                [2]: Addr[2]
                [3]: Cs[0]
                [4]: Cs[1]
        Data: write data
return value:
        0x00   - success
        others - error
*/
UCHAR L2_CFSetWordCsAWr(UCHAR CsA, USHORT Data) USING_0
{
        UCHAR tmp0,tmp1;

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

	tmp0 = CsA&0x07;
	XBYTE[0x2432] = tmp0;
	tmp1 = (CsA&0x18)>>3;
	XBYTE[0x2436] = tmp1;
   	
	XBYTE[0x2430] = (UCHAR)Data&0xff;
	XBYTE[0x2431] = (UCHAR)(Data>>8)&0xff;

        //PRINT_L2("        L2_CFSetWordCsAWr: Exit L2_CFSetWordCsAWr(Cs=8'h%x,Addr=8'h%x,Data=16'h%x)\n",(USHORT)tmp1,(USHORT)tmp0,Data); 

        return L2K_SUCCESS;
}

//-----------------------------------------------------------------------------
//L2_CFSetWordCsARd (for True IDE mode only)
//-----------------------------------------------------------------------------
/* 
routine description:
        Set the CF card Cs/Addr[2:0] and then read a word from the data bus (for True IDE mode only)
arguments:
        CsA:
                [0]: Addr[0]
                [1]: Addr[1]
                [2]: Addr[2]
                [3]: Cs[0]
                [4]: Cs[1]
        Data: read data
return value:
        0x00   - success
        others - error
*/
UCHAR L2_CFSetWordCsARd(UCHAR CsA, USHORT* Data) USING_0
{
        UCHAR tmp0,tmp1,tmp2,tmp3;

//        DbgPrint("L2_CFSetWordCsARd: Enter L2_CFSetWordCsARd\n");
    
	tmp0 = CsA&0x07;
	XBYTE[0x2432] = tmp0;
	tmp1 = (CsA&0x18)>>3;
	XBYTE[0x2436] = tmp1;

	XBYTE[0x2434] = 0x0b;     // turn on prefetch to send read-pulse
    
	tmp2 = XBYTE[0x2431];     // dummy read for trigger read-pulse
	
	XBYTE[0x2434] = 0x09;    // turn off prefetch to read previous data

	while(XBYTE[0x243B]==0) ; // wait chip ready

	tmp2 = XBYTE[0x2430];
	
	//@wyeo@101602@fix samsung cf card, start
	if (CsA == 0x10) 
		tmp3 = XBYTE[0x2431];
	else	
		tmp3 = 0x00;	
	//end
		
        *Data = (tmp3<<8)|(tmp2);

//        DbgPrint("Exit L2_CFSetWordCsARd(Cs=8'h%x,Addr=8'h%x,Data=16'h%x)\n",(USHORT)tmp1,(USHORT)tmp0,*Data); 

        return L2K_SUCCESS;
}
#endif

⌨️ 快捷键说明

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