📄 l2_sd.c
字号:
routine description:
Read the SD 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_SDReadRspBuf(UCHAR Number, UCHAR* Value) USING_0
{
//PRINT_L2(" L2_SDReadRspBuf: Enter L2_SDReadRspBuf\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_SDReadRspBuf: Exit L2_SDReadRspBuf\n");
}
//-----------------------------------------------------------------------------
//L2_SDRspBufState
//-----------------------------------------------------------------------------
/*
routine description:
Get SD response buffer status
arguments:
Status 0: response buffer is not full
1: response buffer is full
return value:
None
*/
void L2_SDRspBufState(UCHAR* Status) USING_0
{
//PRINT_L2(" L2_SDRspBufState: Enter L2_SDRspBufState\n");
*Status = (XBYTE[0x2453]&0x02)>>1;
//PRINT_L2(" L2_SDRspBufState: Exit L2_SDRspBufState\n");
}
//-----------------------------------------------------------------------------
//L2_SDDataBufState
//-----------------------------------------------------------------------------
/*
routine description:
Get SD data buffer status
arguments:
Status 0: data buffer is not full nor empty
1: data buffer is empty
2: data buffer is full
return value:
None
*/
void L2_SDDataBufState(UCHAR* Status) USING_0
{
//PRINT_L2(" L2_SDDataBufState: Enter L2_SDDataBufState\n");
*Status = (XBYTE[0x2453]&0x0C)>>2;
//PRINT_L2(" L2_SDDataBufState: Exit L2_SDDataBufState\n");
}
//-----------------------------------------------------------------------------
//L2_SDReadCRC7
//-----------------------------------------------------------------------------
/*
routine description:
Read the SD CRC7 value
arguments:
Value : nth response buffer value (n is the given Number)
return value:
None
*/
void L2_SDReadCRC7(UCHAR* Value) USING_0
{
//PRINT_L2(" L2_SDReadCRC7: Enter L2_SDReadCRC7\n");
*Value = XBYTE[0x2466];
//PRINT_L2(" L2_SDReadCRC7: Exit L2_SDReadCRC7\n");
}
//-----------------------------------------------------------------------------
//L2_SDCheckCRC16
//-----------------------------------------------------------------------------
/*
routine description:
Check CRC16 is correct or not
arguments:
Status: 0: error
1: correct
return value:
None
*/
void L2_SDCheckCRC16(UCHAR* Status) USING_0
{
//PRINT_L2(" L2_SDCheckCRC16: Enter L2_SDCheckCRC16\n");
*Status = XBYTE[0x246F];
//PRINT_L2(" L2_SDCheckCRC16: Exit L2_SDCheckCRC16\n");
}
//-----------------------------------------------------------------------------
//L2_SDCardCRCStat
//-----------------------------------------------------------------------------
/*
routine description:
The CRC check result of the SD card
arguments:
Status: 0: error
1: correct
return value:
None
*/
void L2_SDCardCRCStat(UCHAR* Status) USING_0
{
UCHAR tmp;
//PRINT_L2(" L2_SDCardCRCStat: Enter L2_SDCardCRCStat\n");
tmp = (XBYTE[0x2454] &0xf0)>>4;
if(tmp == 0x02) *Status = 1;
else *Status = 0;
//PRINT_L2(" L2_SDCardCRCStat: Exit L2_SDCardCRCStat\n");
}
//-----------------------------------------------------------------------------
//L2_SDTimeOut
//-----------------------------------------------------------------------------
/*
routine description:
Check SD response time out and SD CRC time out
arguments:
Status: 0: correct
bit[0]=1: Response time out
bit[1]=1: CRC time out
return value:
None
*/
void L2_SDTimeOut(UCHAR* Status) USING_0
{
//PRINT_L2(" L2_SDTimeOut: Enter L2_SDTimeOut\n");
*Status = (UCHAR)(XBYTE[0x2453]>>6);
//PRINT_L2(" L2_SDTimeOut: Exit L2_SDTimeOut\n");
}
//-----------------------------------------------------------------------------
//L2_SDTxData
//-----------------------------------------------------------------------------
/*
routine description:
Trigger hardware to transmit one block data to SD card
arguments:
None
return value:
None
*/
void L2_SDTxData(void) USING_0
{
//PRINT_L2(" L2_SDTxData: Enter L2_SDTxData\n");
XBYTE[0x2452] = 0x04;
//PRINT_L2(" L2_SDTxData: Exit L2_SDTxData\n");
}
//-----------------------------------------------------------------------------
//L2_SDRxData
//-----------------------------------------------------------------------------
/*
routine description:
Trigger hardware to receive one block data from SD card
arguments:
None
return value:
None
*/
void L2_SDRxData(void) USING_0
{
//PRINT_L2(" L2_SDRxData: Enter L2_SDRxData\n");
XBYTE[0x2452] = 0x08; //ada@0207
//PRINT_L2(" L2_SDRxData: Exit L2_SDRxData\n");
}
//-----------------------------------------------------------------------------
//L2_SDRxCRC
//-----------------------------------------------------------------------------
/*
routine description:
Trigger hardware to receive the CRC check result of the card
arguments:
None
return value:
None
*/
void L2_SDRxCRC(void) USING_0
{
//PRINT_L2(" L2_SDRxCRC: Enter L2_SDRxCRC\n");
XBYTE[0x2452] = 0x10;
//PRINT_L2(" L2_SDRxCRC: Exit L2_SDRxCRC\n");
}
//-----------------------------------------------------------------------------
//L2_SDTxDummy
//-----------------------------------------------------------------------------
/*
routine description:
Trigger hardware to transmit 8 dummy clock cycles
arguments:
None
return value:
None
*/
void L2_SDTxDummy(void) USING_0
{
//PRINT_L2(" L2_SDTxDummy: Enter L2_SDTxDummy\n");
XBYTE[0x2452] = 0x20;
//PRINT_L2(" L2_SDTxDummy: Exit L2_SDTxDummy\n");
}
//-----------------------------------------------------------------------------
//L2_SDWaitIdle
//-----------------------------------------------------------------------------
/*
routine description:
Wait SPCA533 SD interface to idle state
arguments:
None
return value:
None
*/
//patch4.5@ada@Add timeout count begin
UCHAR L2_SDWaitIdle(void) USING_0
//void L2_SDWaitIdle(void) USING_0
{
USHORT timeout_count = 0xffff;
//PRINT_L2(" L2_SDWaitIdle: Enter L2_SDWaitIdle\n");
while ((XBYTE[0x2454] & 0x0F) != 0x00)
{
if (timeout_count > 0)
{
timeout_count--;
}
else
{
return L2K_ERROR_GENERAL;
}
}
return L2K_SUCCESS;
//PRINT_L2(" L2_SDWaitIdle: Exit L2_SDWaitIdle\n");
}
//patch4.5@ada@Add timeout count end
//-----------------------------------------------------------------------------
//L2_SDCheckDat0
//-----------------------------------------------------------------------------
/*
routine description:
Check the status of pin "dat0"
arguments:
Status : 0: dat0 is low
1: dat0 is high
return value:
None
*/
void L2_SDCheckDat0(UCHAR* Status) USING_0
{
//PRINT_L2(" L2_SDCheckDat0: Enter L2_SDCheckDat0\n");
*Status = (XBYTE[0x2453]&0x20)>>5;
//PRINT_L2(" L2_SDCheckDat0: Exit L2_SDCheckDat0\n");
}
//-----------------------------------------------------------------------------
//L2_SDReadPort
//-----------------------------------------------------------------------------
/*
routine description:
Read the SD card data port
arguments:
PortData : read data
return value:
None
*/
void L2_SDReadPort(UCHAR* PortData) USING_0
{
UCHAR tmp0;
//PRINT_L2(" L2_SDReadPort: Enter L2_SDReadPort\n");
tmp0 = XBYTE[0x245A];
*PortData = tmp0;
//PRINT_L2(" L2_SDReadPort: PortData = 8'h%x \n",(USHORT)tmp0);
//PRINT_L2(" L2_SDReadPort: Exit L2_SDReadPort\n");
}
//-----------------------------------------------------------------------------
//L2_SDWritePort
//-----------------------------------------------------------------------------
/*
routine description:
Write the SD card data port
arguments:
PortData : write data
return value:
None
*/
void L2_SDWritePort(UCHAR PortData) USING_0
{
//PRINT_L2(" L2_SDWritePort: Enter L2_SDWritePort(PortData=8'h%x)\n",(USHORT)PortData);
XBYTE[0x2459] = PortData;
//PRINT_L2(" L2_SDWritePort: Exit L2_SDWritePort\n");
}
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -