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

📄 mmccmd.c

📁 How to control MMC interface under SZ platform
💻 C
📖 第 1 页 / 共 3 页
字号:
/******************************************************************************

 C   H E A D E R   F I L E

 (c) Copyright Motorola Semiconductors Hong Kong Limited 1999 - 2002
 ALL RIGHTS RESERVED

*******************************************************************************

 Project Name : Portable Personal System Manager - GT version 2.0
 Project No.  : PDAPSM05
 Title        : 
 File Name    : MMCCMD.h	
 Last Modified: Jan 31, 2002

 Description  : Functions set of MMC Command process.

 Assumptions  : 
 
 Dependency Comments :

 Project Specific Data :

******************************************************************************/

#include "mmclocal.h"

#include "DMA_def.h"
#include "DMA_pptt.h"
/******************************************************************************

 Function Name    : _MMCGoIdleState()

 Input Parameters : VOID
 
 Output Parameters: VOID

 Value returned   : int    0: Sucessful operation, others: meet Error

 Description      : CMD0:	Resets all cards to idle state

 Cautions         : 
 
 Prev Condition   : VOID

 Post Condition   : VOID

******************************************************************************/
MMC_STATUS _MMCGoIdleState()
{
	MMC_STATUS ret;
	ret=_MMCNoDataCommand(MMC_CMD0,0,MMCB_INIT);
	return ret;
}

/******************************************************************************

 Function Name    : _MMCSendOpCond(U32 voltage)

 Input Parameters : U32 voltage
 
 Output Parameters: VOID

 Value returned   : int    0: Sucessful operation, others: meet Error

 Description      : CMD1:   Ask all cards in idle state to send their operation 
 						  coditions register content in response on the CMD line.
 Cautions         : 
 
 Prev Condition   : VOID

 Post Condition   : VOID

******************************************************************************/
MMC_STATUS _MMCSendOpCond(U32 voltage)
{
	 MMC_RESPONSES rp;
	 MMC_STATUS ret;
	 
	 ret=_MMCNoDataCommand(MMC_CMD1,voltage,MMCB_R3);

	 if(ret) 
	 	return ret; //meet some error 
	 	
	 _MMCGetResponses(&rp,MMCB_R3);
     if( !(rp.OCR&0x80000000))
     	return MMC_CARD_BUSY;
     else 
     	return 0;
	
}
/******************************************************************************

 Function Name    : _MMCAllSendCID(P_U8 pCidBuff)

 Input Parameters : P_U8 pCidBuff         CID buffer
 
 Output Parameters: VOID

 Value returned   : int    0: Sucessful operation, others: meet Error

 Description      : CMD2:  Ask all cards to send their CID numbers on rhe CMD line	

 Cautions         : 
 
 Prev Condition   : VOID

 Post Condition   : VOID

******************************************************************************/
/*****************************************************************************  
                  
    CID Register:(Bit)    127   119 111  103 95  87   79  71    63  55  47  39  31  15  7   0
    ------------------------------------------------------------------------------------------
	CID Register          |MID  |  OID   |        PNM               |     PSN       |MDT| CRC|
	-------------------------------------------------------------------------------------------
	pCidBuff    :(BYTE)   |  0  | 1 |  2 | 4 | 5 | 7 | 8  |  9  | 10| 11| 12|13| 14 | 15 | 16|
	

******************************************************************************/
MMC_STATUS _MMCAllSendCID(P_U8 pCidBuff)
{
	MMC_RESPONSES rp;
	MMC_STATUS ret;
	int i;
		
	ret=_MMCNoDataCommand(MMC_CMD2,0,MMCB_R2);
	
	if(ret)
		return ret;
	
	_MMCGetResponses(&rp,MMCB_R2);

	for(i=0;i<16;i++)
	{
		pCidBuff[i]=rp.CID[i];
	}
	return 0;
}

/******************************************************************************

 Function Name    : _MMCSetRelativeAddr(U32 addr)

 Input Parameters : U32 addr       relative address
 
 Output Parameters: VOID

 Value returned   : int    0: Sucessful operation, others: meet Error

 Description      : CMD3	Assigns relative address to the card

 Cautions         : 
 
 Prev Condition   : VOID

 Post Condition   : VOID

******************************************************************************/
MMC_STATUS _MMCSetRelativeAddr(U32 addr)
{
	MMC_RESPONSES rp;
	MMC_STATUS ret;

	ret=_MMCNoDataCommand(MMC_CMD3,addr<<16,MMCB_R1);

	if(ret)
		return ret;
	
	_MMCGetResponses(&rp,MMCB_R1);
	

	return rp.status&MMC_STATUS_NOERROR;

}

/******************************************************************************

 Function Name    : _SDGetRelativeAddr(U32 *pRca)

 Input Parameters : U32 pRca       relative address
 
 Output Parameters: VOID

 Value returned   : int    0: Sucessful operation, others: meet Error

 Description      : CMD3	Get SD Card relative address to the card

 Cautions         : 
 
 Prev Condition   : VOID

 Post Condition   : VOID

******************************************************************************/
MMC_STATUS _SDGetRelativeAddr(U32 *addr)
{
	MMC_RESPONSES rp;
	MMC_STATUS ret;

	ret=_MMCNoDataCommand(MMC_CMD3,0,MMCB_R6);

	if(ret)
		return ret;
	
	_MMCGetResponses(&rp,MMCB_R6);
	
	*addr=rp.status>>16;
	ret=0;
	if(rp.status&0x8000)
		ret|=0x800000;

	if(rp.status&0x4000)
		ret|=0x400000;

	if(rp.status&0x2000)
		ret|=0x80000;
		
	return ret;
}

/******************************************************************************

 Function Name    : _SDSetBusWidth(U8 buswidth)

 Input Parameters : U8 buswidth, 0x0 1bit, 0x2 4bits
 
 Output Parameters: VOID

 Value returned   : int    0: Sucessful operation, others: meet Error

 Description      : ACMD6	Define the data bus width to be used for data transfer.

 Cautions         : 
 
 Prev Condition   : VOID

 Post Condition   : VOID

******************************************************************************/
MMC_STATUS _SDSetBusWidth(U8 buswidth)
{
	MMC_RESPONSES rp;
	MMC_STATUS ret;

	ret=_MMCNoDataCommand(MMC_CMD6,buswidth,MMCB_R1);

	if(ret)
		return ret;
	
	_MMCGetResponses(&rp,MMCB_R6);
	
	return rp.status>>16;
			
}
/******************************************************************************

 Function Name    : _MMCSetRelativeAddr(U32 addr)

 Input Parameters : U32 addr       relative address
 
 Output Parameters: VOID

 Value returned   : int    0: Sucessful operation, others: meet Error

 Description      : CMD7:  		Command toggles a card between the stand-by and 
 							transfer states or between the programming and 
 							disconnect states. In both case the card is selected 
 							by its own relative address and gets deselected by 
 							any other address; address 0 deselects all
 Cautions         : 
 
 Prev Condition   : VOID

 Post Condition   : VOID

******************************************************************************/
MMC_STATUS _MMCSelectDeselectCard(U32 addr)
{
	MMC_RESPONSES rp;
	MMC_STATUS ret;

	if(addr!=0)
		ret=_MMCNoDataCommand(MMC_CMD7,addr<<16,0x40|MMCB_R1);
	else
		ret=_MMCNoDataCommand(MMC_CMD7,0,0x40);
	
	if(ret)
		return ret;
	
	_MMCGetResponses(&rp,MMCB_R1);
	

	return rp.status&MMC_STATUS_NOERROR;

}

/******************************************************************************

 Function Name    : _MMCSendCSD(U32 addr,P_U8 pBuff)

 Input Parameters : U32 addr       relative address
 					P_U8 pbuff     CSD buffer
 
 Output Parameters: VOID

 Value returned   : int    0: Sucessful operation, others: meet Error

 Description      : CMD9:       Addressed card sends its card-specific data(CSD) 
 							on the line
 Cautions         : 
 
 Prev Condition   : VOID

 Post Condition   : VOID

******************************************************************************/
/*****************************************************************************

CSD Register                                         
-----------------------------------------------------------------------------
Name                        | Width| CSD_Slice|    pCsdbuff (BYTE)   
-----------------------------------------------------------------------------
CSD struction				   2     127:126       
System spec. version           4     125:122           0
reserved                       2     121:120 
-----------------------------------------------------------------------------
data read access time 1        8     119:112           1
-----------------------------------------------------------------------------
data read access time 2        8     111:104           2
-----------------------------------------------------------------------------
Max data transfer rate         8     103:96            3
-----------------------------------------------------------------------------
card command classes           12     95:84            4
max read data block length     4      83:80            5
------------------------------------------------------------------------------
partial blocks for read length  1     79:79         
wirte block misalignment        1     78:78         
read block misalignment         1     77:77
DSR implemented                 1     76:76
reserved                        2     75:74
device size                    12     73:62            6-7
max read current                3     61:69
max read current                3     58-56            8
------------------------------------------------------------------------------
max write current               3     55-53
max write current               3     52-50
device size multiplier          3     49-47            9
erase sector size               5     46-42            
erase group size                5     41-37            10
write protect group size        5     36-32            11
------------------------------------------------------------------------------
write protect group enable      1     31:31
manufactuter default ECC        2     30:29
write speed factor              3     28:26
max. write data block length    4     25:22             12
partial blocks for write allowed 1    21:21
reserved                         5    20:16             13
------------------------------------------------------------------------------
File format group               1     15:15            
copy flag                       1     14:14
permanent write protection      1     13:13 
temporary write protection      1     12:12
file format                     2     11:10
ECC code                        2      9:8              14
--------------------------------------------------------------------------------
CRC                             7      7:1
Not used   always '1'           1      0:0              15
-------------------------------------------------------------------------------
 
******************************************************************************/
MMC_STATUS _MMCSendCSD(U32 addr,P_U8 pBuff)
{
	MMC_RESPONSES rp;
	MMC_STATUS ret;
	int i;
	
	ret=_MMCNoDataCommand(MMC_CMD9,addr<<16,MMCB_R2);
	
	if(ret)
		return ret;
	
	_MMCGetResponses(&rp,MMCB_R2);

	for(i=0;i<16;i++)
	{
		pBuff[i]=rp.CSD[i];
	}
	
	return 0;
}
/******************************************************************************

 Function Name    : _MMCSendCID(U32 addr,P_U8 pBuff)

 Input Parameters : U32 addr       relative address
 					P_U8 pbuff     CID buffer
 
 Output Parameters: VOID

 Value returned   : int    0: Sucessful operation, others: meet Error

 Description      : CMD10:		Addressed card sends its card-specific data(CSD) 
 							on the line
 Cautions         : 
 
 Prev Condition   : VOID

 Post Condition   : VOID

******************************************************************************/
MMC_STATUS _MMCSendCID(U32 addr,P_U8 pBuff)
{
	MMC_RESPONSES rp;
	MMC_STATUS ret;
	int i;
	
	ret=_MMCNoDataCommand(MMC_CMD10,addr<<16,MMCB_R2);

⌨️ 快捷键说明

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