📄 l2_cf.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;
tmp2 = XBYTE[0x2024];
XBYTE[0x2024] = 0x01; // 24 MHz cpu clock
//PRINT_L2(" L2_CFReset: Enter \"L2_CFReset\"\n");
if(TrueIDE)
{
XBYTE[0x243A] = 0x00;
for(tmp0=0;tmp0<0xff;tmp0++) // 1.5 ms
for(tmp1=0;tmp1<0xA0;tmp1++) ;
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;
}
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
{
//patch4.5@ada@Add timeout count begin
USHORT timeout_count = 0xffff;
//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
{
if (timeout_count > 0)
{
timeout_count--;
}
else
{
return L2K_ERROR_GENERAL;
}
}
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;
//patch4.5@ada@Add timeout count end
}
//-----------------------------------------------------------------------------
//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
{
//patch4.5@ada@Add timeout count begin
USHORT timeout_count = 0xffff;
//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
{
if (timeout_count > 0)
{
timeout_count--;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -