📄 l2_sd.c
字号:
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];
}
crc7=RspBuf[16];
}
if(crc7!=XBYTE[0x2466]) status=0x01; // CRC7 error
XBYTE[0x2452] = 0x20; while ((XBYTE[0x2454] & 0x0F) != 0x00); // send dummy
return status;
}
#endif
/*UCHAR L2_SDRxResponse(UCHAR* RspBuf, UCHAR RspType) USING_0
{
UCHAR crc7;
UCHAR status=0;
UCHAR i;
UCHAR value;
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);
if((value & 0x20) !=0)
{ // timeout
XBYTE[0x2450] = 0x03;
return 0x02; // 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];
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);
if((value & 0x20) !=0)
{ // timeout
XBYTE[0x2450] = 0x03;
return 0x02; // return
}
RspBuf[i]=XBYTE[0x2465];
}
crc7=RspBuf[16];
}
if(crc7!=XBYTE[0x2466]) status=0x01; // CRC7 error
XBYTE[0x2452] = 0x20; while ((XBYTE[0x2454] & 0x0F) != 0x00); // send dummy
return status;
}
*/
//-----------------------------------------------------------------------------
//L2_SDReadRspBuf
//-----------------------------------------------------------------------------
/*
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_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_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
*/
void L2_SDWaitIdle(void) USING_0
{
//PRINT_L2(" L2_SDWaitIdle: Enter L2_SDWaitIdle\n");
while ((XBYTE[0x2454] & 0x0F) != 0x00) ;
//PRINT_L2(" L2_SDWaitIdle: Exit L2_SDWaitIdle\n");
}
//-----------------------------------------------------------------------------
//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");
}
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -