⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 sd_protocol.c

📁 TI的DM6446的硬件平台搭建的相关例子
💻 C
📖 第 1 页 / 共 2 页
字号:
		  {
			  lockCardDataStructure[i+2]= currentPassword[i];
		  }

		  status = MMCSD_sendCmd( (0x2880 | SD_LOCK_UNLOCK), MMCSD_STUFF_BITS, (Bool)0, MMCSD_STAT0_RSPDNE );
		  if( status == E_PASS ) {
			 status = MMCSD_writeNWords( (Uint32*)lockCardDataStructure, (2+currentPasswordSize)/2,cardMemAddr,DM_FALSE );
 	 		 if( status == E_PASS )
  		        status = MMCSD_checkStatus( MMCSD_STAT0_DATDNE, 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 SD_forcedErase(Uint32 cardMemAddr )
{
	STATUS status;
	Uint8 lockCardDataStructure;

      MMCSD_setDataSize( 1, 512 );  /* Number of blocks = 1; Block Length = 512 bytes */

      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( (0x2880 | SD_LOCK_UNLOCK), MMCSD_STUFF_BITS, (Bool)0, MMCSD_STAT0_RSPDNE );
		  if( status == E_PASS ) {
			 status = MMCSD_writeNWords( (Uint32*)&lockCardDataStructure, 1,cardMemAddr,DM_FALSE );
 	 		 if( status == E_PASS )
  		        status = MMCSD_checkStatus( MMCSD_STAT0_DATDNE, 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 transfer a block of data for application specific commands, from/to SD

    \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 SD

    \return if success, \c E_PASS, else error code

*/
STATUS SD_genCmd( DM_BOOL read, Uint16 *data, Uint32 numWords,Uint32 cardMemAddr)
{
	STATUS status;

      if( numWords >= 256 )
	      MMCSD_setDataSize( numWords/256, numWords*2 );  /* Number of blocks = numWords/256; Block Length = (numWords*2) bytes */
      else
          MMCSD_setDataSize( 1, numWords*2 );  /* Number of blocks = 1; Block Length = (numWords*2) bytes */

  	  status = MMCSD_sendCmd( (0xA000| (~read)<<11 | SD_GEN_CMD), read, (Bool)1, (MMCSD_STAT0_RSPDNE|MMCSD_STAT0_BSYDNE));
	  if( status == E_PASS ) {
	    if(read) {
          status = MMCSD_readNWords((Uint32*)data,numWords,cardMemAddr,DM_FALSE );
        } else {
          status = MMCSD_writeNWords((Uint32 *)data,numWords,cardMemAddr,DM_FALSE);
        }
		//if( status == E_PASS )
  		    //status = MMCSD_checkStatus( MMCSD_STAT0_DATDNE, 0, 0 );  //> TimeOut = 0
      }

	  return ( status );
}

/**
    \brief  Send command to set the Bus Width for SD Card (1 or 4 data lines)

    \param  rca  Relative Card Address assigned to the card
    \param  busWidth  0: 1 data line; 1: 4 data line
     \param  opTimeOut  timeout value for resending the command

    \return if success, \c E_PASS, else error code

*/
STATUS SD_setBusWidth( Uint32 rca, Uint8 busWidth, Uint32 opTimeOut )
{
	STATUS status;

      do{
		  /* Send CMD55 */
		  status = MMCSD_appCmd( rca );
	      if ( status != E_PASS )
			  return ( E_MISC );

		  status = MMCSD_sendCmd( SD_SET_BUS_WIDTH, (Uint32)busWidth, (Bool)1, MMCSD_STAT0_RSPDNE );

	  } while( (status != E_PASS) && opTimeOut-- );

	  if( status == E_PASS ){
	    if( busWidth == 0 )
	  		//MMCSD_FSET( MMCCTL, WIDTH, MMCSD_DATA_BUS_1 );
	  		CSL_FINS(CSL_MMCSD_0_REGS->MMCCTL,MMCSD_MMCCTL_WIDTH, MMCSD_DATA_BUS_1);
	  	else
	  		//MMCSD_FSET( MMCCTL, WIDTH, MMCSD_DATA_BUS_4 );
	  		CSL_FINS(CSL_MMCSD_0_REGS->MMCCTL,MMCSD_MMCCTL_WIDTH, MMCSD_DATA_BUS_4);
	  }

	  return ( status );
}

/**
    \brief  Send command to read the SD Status Register contents

    \param  rca  Relative Card Address assigned to the card
    \param  sdStatus Buffer for storing the 512 bytes of SD Status, received from the card

    \return if success, \c E_PASS, else error code

*/
STATUS SD_readSDStatus( Uint32 rca, Uint16 *sdStatus,Uint32 cardMemAddr)
{
	STATUS status;

	  status = MMCSD_sendCmd( MMCSD_SET_BLOCKLEN, 64, (Bool)1, MMCSD_STAT0_RSPDNE);
 	  if( status != E_PASS )
		return ( E_MISC );

      status = MMCSD_setDataSize( 1, 64 );  /* Number of blocks = 1; Block Length = 512 bytes */

      if( status == E_PASS ){
		  /* Send CMD55 */
		  status = MMCSD_appCmd( rca );
		  if( status != E_PASS )
			  return ( E_MISC );

		  status = MMCSD_sendCmd( (0xA080 |SD_SD_STATUS), rca<<16, (Bool)1, MMCSD_STAT0_RSPDNE );
		  if( status == E_PASS ) {
			status = MMCSD_readNWords( (Uint32 *)sdStatus, 64/2,cardMemAddr,FALSE );
			if( status == E_PASS )
				status = MMCSD_checkStatus( MMCSD_STAT0_DATDNE, 0, 0 );  //> TimeOut = 0
		  }
	  }

	  return ( status );
}

/**
    \brief  Send command to read the number of blocks written without error on SD card

    \param  rca  Relative Card Address assigned to the card
    \param  numWrBlks Buffer for storing the 32 bit data received from the card

    \return if success, \c E_PASS, else error code

*/
STATUS SD_sendNumWrBlks( Uint32 rca, Uint32 *numWrBlks,Uint32 cardMemAddr )
{
	STATUS status;

	  status = MMCSD_sendCmd( MMCSD_SET_BLOCKLEN, 4, (Bool)1, MMCSD_STAT0_RSPDNE);
 	  if( status != E_PASS )
		return ( E_MISC );

 	  status = MMCSD_setDataSize( 1, 4 );  /* Number of blocks = 1; Block Length = 4 bytes */

      if( status == E_PASS ){
		  /* Send CMD55 */
		  status = MMCSD_appCmd( rca );
		  if ( status != E_PASS )
			  return ( E_MISC );

		  status = MMCSD_sendCmd( (0xA080 |SD_SEND_NUM_WR_BLKS), MMCSD_STUFF_BITS, (Bool)1, MMCSD_STAT0_RSPDNE );
		  if( status == E_PASS ) {
			status = MMCSD_readNWords( (Uint32*)numWrBlks, 2,cardMemAddr,FALSE );

		  }
	  }

	  return ( status );
}

/**
    \brief  Send command to set the number of blocks to be pre-erased before multiple blk write

    \param  rca  Relative Card Address assigned to the card
    \param  numBlksToPreErase Number of blocks to Pre-Erase before writing, for faster Multiple Blk Write operation

    \return if success, \c E_PASS, else error code

*/
STATUS SD_setWrBlkEraseCnt( Uint32 rca, Uint16 numBlksToPreErase )
{
	STATUS status;

	  /* Send CMD55 */
	  status = MMCSD_appCmd( rca );
	  if ( status != E_PASS )
		  return ( E_MISC );

	  status = MMCSD_sendCmd( SD_SET_WR_BLK_ERASE_CNT, (Uint32)numBlksToPreErase, (Bool)1, MMCSD_STAT0_RSPDNE );

	  return ( status );
}

/**
    \brief  Send command to connect or disconnect the pull up resistor used for card detect on pin 1 of SD

    \param  rca  Relative Card Address assigned to the card
    \param  setSD 1: Connect, 0: Disconnect - the pull up resistor on CD/DAT3(pin1)

    \return if success, \c E_PASS, else error code

*/
STATUS SD_setClrCardDetect( Uint32 rca, Uint8 setSD )
{
	STATUS status;

      if( setSD > 1)
		  return E_INVALID_INPUT;

	  /* Send CMD55 */
	  status = MMCSD_appCmd( rca );
	  if ( status != E_PASS )
		  return ( E_MISC );

	  status = MMCSD_sendCmd( SD_SET_CLR_CARD_DETECT, (Uint32)setSD, (Bool)1, MMCSD_STAT0_RSPDNE );

	  return ( status );
}

 /**
    \brief  Send command to read the contents of SD Configuration Register (SCR)

    \param  rca  Relative Card Address assigned to the card
    \param  scr  64-bit buffer for storing the SCR

    \return if success, \c E_PASS, else error code

*/
STATUS SD_sendSCR( Uint32 rca, Uint16 *scr,Uint32 cardMemAddr )
{
	STATUS status;

	  status = MMCSD_sendCmd( MMCSD_SET_BLOCKLEN, 8, (Bool)1, MMCSD_STAT0_RSPDNE);
 	  if( status != E_PASS )
		return ( E_MISC );

 	  status = MMCSD_setDataSize( 1, 8 );  /* Number of blocks = 1; Block Length = 8 bytes */

      if( status == E_PASS ){
		  /* Send CMD55 */
		  status = MMCSD_appCmd( rca );
		  if ( status != E_PASS )
			  return ( E_MISC );

		  status = MMCSD_sendCmd( (0xA080 |SD_SEND_SCR), MMCSD_STUFF_BITS, (Bool)1, MMCSD_STAT0_RSPDNE );
		  if( status == E_PASS ) {
			status = MMCSD_readNWords( (Uint32*)scr, 4,cardMemAddr,FALSE );

		  }
	  }

	  return ( status );
}

/**
  \brief SD Card Detect

  \param rca Relative Card Address

  \return if card present, E_PASS else \c E_DEVICE
*/

STATUS SD_cardDetect(Uint32 rca)
{
  STATUS status;
  Uint8 cardStatus;

  /* Connect the CD/DAT3 pin to a pull-up resistor */
  status = SD_setClrCardDetect(rca, 1);

  /* Check whether card is present by reading the DAT3St field of MMCST1 */
  cardStatus = CSL_FEXT(CSL_MMCSD_0_REGS->MMCST1, MMCSD_MMCST1_DAT3ST);
  /* Disconnect the pull up resistor */
  status = SD_setClrCardDetect(rca, 0);

  if(cardStatus){
    return(E_PASS);
  }else{
    return(E_DEVICE);
  }
}

/* Rev.No.   Date/Time               ECN No.          Modifier      */
/* -------   ---------               -------          --------      */

/* 1         24 Jun 2004 14:41:06    1864             xjarlika      */
/*                                                                  */
/* Checking in MMCSD drv include and src files                      */
/********************************************************************/
/* Rev.No.   Date/Time               ECN No.          Modifier      */
/* -------   ---------               -------          --------      */

/* 2          Jul 15:22:23 8         2049             xjarlika      */
/*                                                                  */
/* FIFOCTL renamed as MMCFIFOCTL                                    */
/* Update due to Register Name Change                               */
/********************************************************************/
/* Rev.No.   Date/Time               ECN No.          Modifier      */
/* -------   ---------               -------          --------      */

/* 3         24 Aug 2004 14:45:33    2401             xjarlika      */
/*                                                                  */
/* Updating MMCSD drv include and src files after testing on Hibari */
/********************************************************************/

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -