📄 mmc_protocol.c
字号:
if( (oldPasswordSize != 0 ) && (newPasswordSize != 0) ) {
lockCardDataStructure[1] = newPasswordSize+oldPasswordSize;
for ( i=0; i<oldPasswordSize; i++)
{
lockCardDataStructure[i+2]= oldPassword[i];
}
for ( i=0; i<newPasswordSize; i++)
{
lockCardDataStructure[i+2+oldPasswordSize]= newPassword[i];
}
} else if( newPasswordSize == 0 ) {
lockCardDataStructure[1] = oldPasswordSize;
for ( i=0; i<oldPasswordSize; i++)
{
lockCardDataStructure[i+2]= oldPassword[i];
}
} else if( oldPasswordSize == 0 ) {
lockCardDataStructure[1] = newPasswordSize;
for ( i=0; i<newPasswordSize; i++)
{
lockCardDataStructure[i+2]= newPassword[i];
}
}
status = MMCSD_sendCmd( (0xB900 | MMC_LOCK_UNLOCK), MMCSD_STUFF_BITS, (Bool)1, MMCSD_STAT0_RSPDNE );
if( status == E_PASS ) {
status = MMCSD_writeNWords( (Uint32*)lockCardDataStructure, numWords,cardMemAddr,FALSE );
if( status == E_PASS )
status = MMCSD_checkStatus( (MMCSD_STAT0_DATDNE | MMCSD_STAT0_BSYDNE), 0, 0 );
if( status == E_PASS )
//< If 00: Card unlocked, passwd no error; 01: Card unlocked, passwd error; 10: Card locked, passwd no error; 11: Card locked; passwd error
status = MMCSD_CARD_LOCK_AND_PASSWD_CHK();
}
}
return ( status );
}
/**
\brief Send command to unlock the MMC
\param cardLockMode Card lock mode - 1: set passwd, 2: clr passwd, 4: lock; 8: forced erase
\param currentPasswordSize Size in bytes of the existing password
\param currentPassword Existing password
\return if success, \c E_PASS or \c CardLock and Passwd Set status, else error code
*/
Uint8 MMC_cardUnlock( Uint8 cardLockMode, Uint8 currentPasswordSize, Uint8 *currentPassword,Uint32 cardMemAddr )
{
STATUS status;
Uint8 lockCardDataStructure[18];
int i=0;
status = MMCSD_sendCmd( MMCSD_SET_BLOCKLEN, 2+currentPasswordSize, (Bool)1, MMCSD_STAT0_RSPDNE);
if( status == E_PASS ) {
//< Set the lockCardDataStructure elements
lockCardDataStructure[0] = cardLockMode;
lockCardDataStructure[1] = currentPasswordSize;
for ( i=0; i<currentPasswordSize; i++)
{
lockCardDataStructure[i+2]= currentPassword[i];
}
status = MMCSD_sendCmd( (0xB900 | MMC_LOCK_UNLOCK), MMCSD_STUFF_BITS, (Bool)1, MMCSD_STAT0_RSPDNE );
if( status == E_PASS ) {
status = MMCSD_writeNWords( (Uint32*)lockCardDataStructure, 2+currentPasswordSize,cardMemAddr,FALSE );
if( status == E_PASS )
status = MMCSD_checkStatus( (MMCSD_STAT0_DATDNE | MMCSD_STAT0_BSYDNE), 0, 0 );
if( status == E_PASS )
//< If 00: Card unlocked, passwd no error; 01: Card unlocked, passwd error; 10: Card locked, passwd no error; 11: Card locked; passwd error
status = MMCSD_CARD_LOCK_AND_PASSWD_CHK();
}
}
return ( status );
}
/**
\brief Send command to force erase on a locked card
\return if success, \c E_PASS, else error code
*/
Uint8 MMC_forcedErase( Uint32 cardMemAddr )
{
STATUS status;
Uint8 lockCardDataStructure;
status = MMCSD_sendCmd( MMCSD_SET_BLOCKLEN, 1, (Bool)1, MMCSD_STAT0_RSPDNE);
if( status == E_PASS ) {
//< Set the lockCardDataStructure elements
lockCardDataStructure = (Uint8)MMCSD_FORCED_ERASE;
status = MMCSD_sendCmd( (0xB900 | MMC_LOCK_UNLOCK), MMCSD_STUFF_BITS, (Bool)1, MMCSD_STAT0_RSPDNE );
if( status == E_PASS ) {
status = MMCSD_writeNWords( (Uint32*)&lockCardDataStructure, 1,cardMemAddr,FALSE );
if( status == E_PASS )
status = MMCSD_checkStatus( (MMCSD_STAT0_DATDNE | MMCSD_STAT0_BSYDNE), 0, 0 );
if( status == E_PASS )
//< If 00: Card unlocked, passwd no error; 01: Card unlocked, passwd error; 10: Card locked, passwd no error; 11: Card locked; passwd error
status = MMCSD_CARD_LOCK_AND_PASSWD_CHK();
}
}
return ( status );
}
/*
** Application Specific Commands - refer to the product manuals while using these commands
*/
/**
\brief Send command to read/write 8bit application dependant registers
\param rca Relative Card Address assigned to the card
\param regWriteFlag 0: read register; 1: write register
\param regAddr Address of the application dependant register on MMC to read/write
\param regData Buffer to read/write data from 'regAddr' register on MMC
\return if success, \c E_PASS, else error code
*/
STATUS MMC_fastIO( Uint32 rca, Uint8 regWriteFlag, Uint8 regAddr, Uint8 *regData )
{
STATUS status;
Uint32 argumentBits;
argumentBits = (rca<<16) | ((Uint32)(regWriteFlag&0x1)<<15) | ((Uint32)(regAddr&0x7F)<<8) | (Uint32)((*regData)&0x7F);
status = MMCSD_sendCmd( MMC_FAST_IO, argumentBits, (Bool)1, MMCSD_STAT0_RSPDNE);
if( status == E_PASS ) {
if( regWriteFlag == 0 ){
*regData = MMCSD_FASTIO_DATA();
}
}
return ( status );
}
/**
\brief Send command to transfer a block of data for application specific commands, from/to MMC
\param read 0: write, 1: read
\param data Buffer to read/write for application specific commands
\param numWords Number of words to be read/written to the MMC
\return if success, \c E_PASS, else error code
*/
STATUS MMC_genCmd( Bool read, Uint16 *data, Uint32 numWords,Uint32 cardMemAddr )
{
STATUS status;
status = MMCSD_sendCmd( MMCSD_SET_BLOCKLEN, 1, (Bool)1, MMCSD_STAT0_RSPDNE);
if( status == E_PASS ) {
status = MMCSD_sendCmd( (0xA000| (~read)<<11 | MMC_GEN_CMD), read, (Bool)1, (MMCSD_STAT0_RSPDNE|MMCSD_STAT0_BSYDNE));
if( status == E_PASS ) {
status = MMCSD_readNWords( (Uint32 *)data, numWords,cardMemAddr,FALSE );
if( status == E_PASS )
status = MMCSD_checkStatus( (MMCSD_STAT0_DATDNE|MMCSD_STAT0_BSYDNE), 0, 0 ); //> TimeOut = 0
}
}
return ( status );
}
/**
\brief Send command to read data from the MMC/SD card in the streaming mode
\param cardAddr Address of the location on the card to be read (should be a multiple of )
\param dest Buffer to read data into, from MMC/SD card
\param datalength Number of bytes, to be read from MMC/SD card
\param dmaEnable Whether DMA enabled or not
\param endian Whether word swap enabled or not
\return if success, \c E_PASS, else error code
*/
STATUS MMC_streamRead( Uint32 cardMemAddr, Uint32 *dest, Uint32 datalength, Uint32 dmaEnable, Uint32 endian)
{
STATUS status;
Uint32 numBlks;
int num_extra_words;
//Check whether address is valid
if( cardMemAddr%512 ){
if( mmcsdCSDRegInfo.readBlkMisalign != 1 )
return E_INVALID_INPUT;
}
//Clear the response
MMCSD_clearResponse();
//Determine the minimum number of extra bytes
num_extra_words = datalength % (mmcsdCSDRegInfo.readBlkLenBytes);
numBlks = datalength / (mmcsdCSDRegInfo.readBlkLenBytes);
//Check whether partial reads are supported
if(num_extra_words != 0) {
if( mmcsdCSDRegInfo.readBlkPartial != 1 ) {
return E_INVALID_INPUT;
}
}
//Set the blocklength and size
status = MMCSD_setDataSize(0, mmcsdCSDRegInfo.readBlkLenBytes);
/* Send the Read Command with a response check */
status = MMCSD_sendCmd( 0x13080 | MMC_READ_DAT_UNTIL_STOP, cardMemAddr, (Bool)0, MMCSD_STAT0_RSPDNE);
if( status == E_PASS ){ /* Command sent */
/* Read Data, every time Data Rd Reg full, till all words read */
status = MMC_StreamReadNWords( (Uint32*)dest, datalength,dmaEnable);
}
return ( status );
}
/**
\brief Send command to write data to the MMC/SD card in the streaming mode
\param cardAddr Address of the location on the card to be read (should be a multiple of )
\param src Buffer to write data from, into MMC/SD card
\param datalength Number of bytes, to be written into MMC/SD card
\param dmaEnable Whether DMA enabled or not
\param endian Whether word swap enabled or not
\return if success, \c E_PASS, else error code
*/
STATUS MMC_streamWrite( Uint32 cardMemAddr, Uint32 *src, Uint32 datalength, Uint32 dmaEnable, Uint32 endian)
{
STATUS status,i=0;
Uint32 numBlks;
int num_extra_words;
//Check whether address is valid
if(cardMemAddr%512){
if(mmcsdCSDRegInfo.writeBlkMisalign != 1)
return E_INVALID_INPUT;
}
//Check whether the specified address is in a write protected zone
//Clear the response
MMCSD_clearResponse();
//Determine the minimum number of extra bytes
num_extra_words = datalength % (mmcsdCSDRegInfo.writeBlkLenBytes);
numBlks = datalength / (mmcsdCSDRegInfo.writeBlkLenBytes);
//Check whether partial reads are supported
if(num_extra_words != 0) {
if(mmcsdCSDRegInfo.writeBlkPartial != 1) {
return E_INVALID_INPUT;
}
}
MMCSD_setDataSize(0,512); /* 0: infinite num of blocks , blk length */
/* Write Data */
status = MMC_StreamWriteNWords(cardMemAddr,(Uint32*)src,datalength,dmaEnable);
return ( status );
}
/* Rev.No. Date/Time ECN No. Modifier */
/* ------- --------- ------- -------- */
/* 1 24 Jun 2004 14:41:03 1864 xjarlika */
/* */
/* Checking in MMCSD drv include and src files */
/********************************************************************/
/* Rev.No. Date/Time ECN No. Modifier */
/* ------- --------- ------- -------- */
/* 2 Jul 15:22:21 8 2049 xjarlika */
/* */
/* FIFOCTL renamed as MMCFIFOCTL */
/* Update due to Register Name Change */
/********************************************************************/
/* Rev.No. Date/Time ECN No. Modifier */
/* ------- --------- ------- -------- */
/* 3 13 Aug 2004 18:21:55 2296 xjarlika */
/* */
/* Updating MMCSD include and src file after inital testing on Hibari*/
/* Updating MMCSD include and src file after inital testing on Hibari*/
/********************************************************************/
/* Rev.No. Date/Time ECN No. Modifier */
/* ------- --------- ------- -------- */
/* 4 24 Aug 2004 14:45:33 2401 xjarlika */
/* */
/* Updating MMCSD drv include and src files after testing on Hibari */
/********************************************************************/
/* Rev.No. Date/Time ECN No. Modifier */
/* ------- --------- ------- -------- */
/* 5 14 Jan 2005 11:28:33 5879 xjarlika */
/* */
/* Updating after testing on DaVinci QT */
/********************************************************************/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -