📄 l2_mmc.c
字号:
/*++
Copyright (c) 2001 Sunplus Technology Co., Ltd.
Module Name:
L2_MMC.C
Abstract:
Module related to L2 MMC functions
Environment:
Keil C51 Compiler
Revision History:
04/10/2002 Leeada created
--*/
//=============================================================================
//Header file
//=============================================================================
#include "general.h"
//=============================================================================
//Symbol
//=============================================================================
//-----------------------------------------------------------------------------
//Constant
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
//Variable
//-----------------------------------------------------------------------------
//=============================================================================
//Program
//=============================================================================
#if (MMC)
//-----------------------------------------------------------------------------
//L2_MMCInit
//-----------------------------------------------------------------------------
/*
routine description:
MMC interface initialization
arguments:
None
return value:
None
*/
void L2_MMCInit(void) USING_0
{
XBYTE[0x2450] = 0x03; // MMC reset, CRC reset
XBYTE[0x2457] = 0xff; // Rsp timer setting
XBYTE[0x2458] = 0x08; // CRC timer setting
XBYTE[0x2451] = 0x71; // enable Rsp timer & CRC timer
}
//-----------------------------------------------------------------------------
//L2_MMCConfig
//-----------------------------------------------------------------------------
/*
routine description:
Set MMC operation frequency , data bus width , Response type
arguments:
OpFreq 0:24MHz, 1:12MHz, 2:6MHz 3:375KHz
DataBusWidth 0:1 bit data bus, 1:4 bits data bus
return value:
None
*/
void L2_MMCConfig(UCHAR OpFreq,UCHAR DataBusWidth) USING_0
{
UCHAR tmp;
tmp = XBYTE[0x2451];
tmp = (tmp & 0xf0) | (OpFreq & 0x03) | ((DataBusWidth & 0x01) << 2);
XBYTE[0x2451] = tmp;
}
//-----------------------------------------------------------------------------
//L2_MMCBlockSize
//-----------------------------------------------------------------------------
/*
routine description:
Set MMC data length of read/write one block
arguments:
BlockSize : the length of read/write one block
return value:
None
*/
void L2_MMCBlockSize(USHORT BlockSize) USING_0
{
XBYTE[0x2455] = (UCHAR)(BlockSize);
XBYTE[0x2456] = (UCHAR)(BlockSize >> 8);
}
//-----------------------------------------------------------------------------
//L2_MMCReset
//-----------------------------------------------------------------------------
/*
routine description:
reset the MMC interface
arguments:
None
return value:
None
*/
void L2_MMCReset(void) USING_0
{
XBYTE[0x2450] = 0x03;
}
//-----------------------------------------------------------------------------
//L2_MMCTxCommand
//-----------------------------------------------------------------------------
/*
routine description:
Send command to MMC card
arguments:
CmdBuf : the command to be x'fer
return value:
None
*/
//patch4.5@ada@Add timeout count begin
UCHAR L2_MMCTxCommand(UCHAR* CmdBuf) USING_0
//void L2_MMCTxCommand(UCHAR* CmdBuf) USING_0
{
USHORT timeout_count = 0xffff;
XBYTE[0x245B] = CmdBuf[0];
XBYTE[0x245C] = CmdBuf[1];
XBYTE[0x245D] = CmdBuf[2];
XBYTE[0x245E] = CmdBuf[3];
XBYTE[0x245F] = CmdBuf[4];
XBYTE[0x2452] = 0x01; // trigger to TX command
while ((XBYTE[0x2454] & 0x0F) != 0x00)
{
if (timeout_count > 0)
{
timeout_count--;
}
else
{
return L2K_ERROR_GENERAL;
}
}
return L2K_SUCCESS;
//printf("CRC7=%x\n",(USHORT)XBYTE[0x2466]);
}
//patch4.5@ada@Add timeout count end
//-----------------------------------------------------------------------------
//L2_MMCRxResponse
//-----------------------------------------------------------------------------
/*
routine description:
receive MMC card response
arguments:
RspType - 0: length of 6 bytes, 1: length of 17 bytes
return value:
0x00 - No error
0x01 - crc7 error
0x02 - response timeout
*/
//patch4.5@ada@Add timeout count begin
UCHAR L2_MMCRxResponse(UCHAR* RspBuf, UCHAR RspType, UCHAR CrcExist) USING_0
{
UCHAR crc7;
UCHAR status = L2K_SUCCESS;
UCHAR i;
UCHAR value;
USHORT timeout_count = 0xffff;
if (RspType == 0)
{
XBYTE[0x2451] &= 0xF7; // Set response type to 6 bytes
}
else
{
XBYTE[0x2451] |= 0x08; // Set response type to 17 bytes
}
XBYTE[0x2452] = 0x02; // start receiving response
do
{
value = XBYTE[0x2453] & 0x02 ; // wait until response buffer full
} while ((value == 0) && ((XBYTE[0x2453] & 0x40) == 0));
if ((value & 0x20) && (XBYTE[0x2453] & 0x40))
{ // timeout
XBYTE[0x2450] = 0x03;
status = 2;
return status; // return
}
RspBuf[0] = XBYTE[0x2460];
RspBuf[1] = XBYTE[0x2461];
RspBuf[2] = XBYTE[0x2462];
RspBuf[3] = XBYTE[0x2463];
RspBuf[4] = XBYTE[0x2464];
RspBuf[5] = XBYTE[0x2465];
if (CrcExist)
{
crc7 = RspBuf[5];
}
if (RspType == 1)
{
for (i = 6; i < 17; i++)
{
do
{
value = XBYTE[0x2453] & 0x02 ; // wait until response buffer full
} while ((value == 0) && ((XBYTE[0x2453] & 0x40) == 0));
if ((value & 0x20) && (XBYTE[0x2453] & 0x40))
{ // timeout
XBYTE[0x2450] = 0x03;
return 0x02; // return
}
RspBuf[i] = XBYTE[0x2465];
}
if (CrcExist)
{
crc7 = RspBuf[16];
}
}
if ((crc7 != XBYTE[0x2466]) && (CrcExist))
{
status=0x01; // CRC7 error
}
XBYTE[0x2452] = 0x20;
while ((XBYTE[0x2454] & 0x0F) != 0x00) // send dummy
{
if (timeout_count > 0)
{
timeout_count--;
}
else
{
status = 2;
return status;
}
}
return status;
}
//patch4.5@ada@Add timeout count end
//-----------------------------------------------------------------------------
//L2_MMCReadRspBuf
//-----------------------------------------------------------------------------
/*
routine description:
Read the MMC response buffer data
arguments:
Number : the number of buffer data is to be read (1-6)
Value : nth response buffer value (n is the given Number)
return value:
None
*/
void L2_MMCReadRspBuf(UCHAR Number, UCHAR* Value) USING_0
{
// PRINT_L2(" L2_MMCReadRspBuf: Enter L2_MMCReadRspBuf\n");
switch(Number)
{
case 1: *Value = XBYTE[0x2460];
break;
case 2: *Value = XBYTE[0x2461];
break;
case 3: *Value = XBYTE[0x2462];
break;
case 4: *Value = XBYTE[0x2463];
break;
case 5: *Value = XBYTE[0x2464];
break;
case 6: *Value = XBYTE[0x2465];
break;
}
// PRINT_L2(" L2_MMCReadRspBuf: Exit L2_MMCReadRspBuf\n");
}
//-----------------------------------------------------------------------------
//L2_MMCRspBufState
//-----------------------------------------------------------------------------
/*
routine description:
Get MMC response buffer status
arguments:
Status 0: response buffer is not full
1: response buffer is full
return value:
None
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -