📄 mmc_cmd.c
字号:
/* * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * * Copyright (C) 2002 Freescale Semiconductors HK Ltd * *//****************************************************************************** * * Copyright (C) 2001, Freescale All Rights Reserved * * File Name: mmcsd_cmd.c * * Progammers: Yiwei Zhao * * Date of Creations: 30 DEC,2001 * * Synopsis: * * Modification History: * 30 DEC, 2001 * *****************************************************************************/#include "dbmx1_type.h"#include "mmc_def.h"#include "mmc_main.h"/* Functions List: * *//****************************************************************************** * Function Name: _MMCSD_GoIdleState * * Input: None. * * Value Returned: * * MMCSD_STATUS * * Description: * Resets all cards to idle state * * Modification History: * 30 DEC,2001, Initial version. Yiwei Zhao *****************************************************************************/MMCSD_STATUS _MMCSD_GoIdleState(int port){ MMCSD_STATUS ret; ret=_MMCSD_NoDataCommand(MMCSD_CMD0,0,MMCSDB_INIT,port); return ret;}/****************************************************************************** * Function Name: _MMCSD_SendOpCond * * Input: * voltage * * Value Returned: * * Description: * Ask all cards in idle state to send their operation conditions register * contern in response on the CMD line. * * Modification History: * 30 DEC,2001, Initial version. Yiwei Zhao *****************************************************************************/MMCSD_STATUS _MMCSD_SendOpCond(u32 voltage,int port){ MMCSD_Responses rp; MMCSD_STATUS ret; //voltage = 0xFFFFFF0; ret=_MMCSD_NoDataCommand(MMCSD_CMD1,voltage,MMCSDB_R3,port); //TRACE("The Response is ..."); _MMCSD_GetResponses(&rp,MMCSDB_R3,port); if(ret) { TRACE("CMD1 failed with ret = 0x%lx",ret); return ret; //meet some error } if((rp.OCR&0x80000000)==0) return MMCSD_CARD_BUSY; else { //TRACE("OCR is %lx",rp.OCR); return 0; } }/****************************************************************************** * Function Name: _MMCSD_AllSendCID * * Input: * UINT8 * pCidBuff * * Value Returned: * * MMCSD_STATUS * * Description: * * CMD2: Ask all cards to send their CID numbers on rhe CMD line * * Modification History: * 30 DEC,2001, Initial version. Yiwei Zhao *****************************************************************************//***************************************************************************** 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| ******************************************************************************/MMCSD_STATUS _MMCSD_AllSendCID(u8 *pCidBuff,int port){ MMCSD_Responses rp; MMCSD_STATUS ret; int i; ret=_MMCSD_NoDataCommand(MMCSD_CMD2,0,MMCSDB_R2,port); if(ret) { FAILED("Command 2 returns with 0x%x \n",ret); return ret; } _MMCSD_GetResponses(&rp,MMCSDB_R2,port); for(i=0;i<16;i++) { pCidBuff[i]=rp.CID[i]; } return 0;}/****************************************************************************** * Function Name: _MMCSD_SetRelativeAddr * * Input: * addr relative address * * Value Returned: * * MMCSD_STATUS * * Description: * * Assigns relative address to the card * * Modification History: * 30 DEC,2001, Initial version. Yiwei Zhao * * Qeustion: * * assigned or generated by itself? * *****************************************************************************/MMCSD_STATUS _MMCSD_SetRelativeAddr(u32 addr,int port){ MMCSD_Responses rp; MMCSD_STATUS ret; ret=_MMCSD_NoDataCommand(MMCSD_CMD3,addr<<16,MMCSDB_R1,port); if(ret) return ret; _MMCSD_GetResponses(&rp,MMCSDB_R1,port); return rp.status&MMCSD_STATUS_NOERROR;}/****************************************************************************** * Function Name: _MMCSD_SelectDeselectCard * * Input: * * addr: relative address * * Value Returned: * * MMCSD_STATUS * * Description: * * Modification History: * 30 DEC,2001, Initial version. Yiwei Zhao *****************************************************************************/MMCSD_STATUS _MMCSD_SelectDeselectCard(u32 addr,u32 port){ MMCSD_Responses rp; MMCSD_STATUS ret; if(addr!=0) ret=_MMCSD_NoDataCommand(MMCSD_CMD7,addr<<16,0x40|MMCSDB_R1,port); else ret=_MMCSD_NoDataCommand(MMCSD_CMD7,0,0x40,port); if(ret) return ret; _MMCSD_GetResponses(&rp,MMCSDB_R1,port); return rp.status&MMCSD_STATUS_NOERROR;}/****************************************************************************** * Function Name: _MMCSD_SendCSD * * Input: * addr: relative address. * * Value Returned: * * MMCSD_STATUS * * Description: * CMD9: Addressed card sends its card-specific data(CSD) * Modification History: * 30 DEC,2001, Initial version. Yiwei Zhao *****************************************************************************//*****************************************************************************CSD Register -----------------------------------------------------------------------------Name | Width| CSD_Slice| pCsdbuff (BYTE) -----------------------------------------------------------------------------CSD struction 2 127:126 System spec. version 4 125:122 0reserved 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 4max 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:77DSR implemented 1 76:76reserved 2 75:74device size 12 73:62 6-7max read current 3 61:69max read current 3 58-56 8------------------------------------------------------------------------------max write current 3 55-53max write current 3 52-50device size multiplier 3 49-47 9erase sector size 5 46-42 erase group size 5 41-37 10write protect group size 5 36-32 11------------------------------------------------------------------------------write protect group enable 1 31:31manufactuter default ECC 2 30:29write speed factor 3 28:26max. write data block length 4 25:22 12partial blocks for write allowed 1 21:21reserved 5 20:16 13------------------------------------------------------------------------------File format group 1 15:15 copy flag 1 14:14permanent write protection 1 13:13 temporary write protection 1 12:12file format 2 11:10ECC code 2 9:8 14--------------------------------------------------------------------------------CRC 7 7:1Not used always '1' 1 0:0 15------------------------------------------------------------------------------- ******************************************************************************/MMCSD_STATUS _MMCSD_SendCSD(u32 addr,u8* pBuff,u32 port){ MMCSD_Responses rp; MMCSD_STATUS ret; int i; ret=_MMCSD_NoDataCommand(MMCSD_CMD9,addr<<16,MMCSDB_R2,port); if(ret) return ret; _MMCSD_GetResponses(&rp,MMCSDB_R2,port); for(i=0;i<16;i++) { pBuff[i]=rp.CSD[i]; TRACE(" %02x", pBuff[i]); } return 0;}/****************************************************************************** * Function Name: _MMCSD_SendCID * * Input: * addr: relative address. * * Value Returned: * * MMCSD_STATUS * * Description: * CMD10: Addressed card sends its card-specific data(CSD) * * Modification History: * 30 DEC,2001, Initial version. Yiwei Zhao *****************************************************************************/MMCSD_STATUS _MMCSD_SendCID(u32 addr,u8 * pBuff,u32 port){ MMCSD_Responses rp; MMCSD_STATUS ret; int i; ret=_MMCSD_NoDataCommand(MMCSD_CMD10,addr<<16,MMCSDB_R2,port); if(ret) return ret; _MMCSD_GetResponses(&rp,MMCSDB_R2,port); for(i=0;i<16;i++) { pBuff[i]=rp.CID[i]; } return 0;}/****************************************************************************** * Function Name: _MMCSD_SendStatus * * Input: . * * Value Returned: * * MMCSD_STATUS * * Description: CMD13 addressed card sends its status register * * Modification History: * 30 DEC,2001, Initial version. Yiwei Zhao *****************************************************************************/MMCSD_STATUS _MMCSD_SendStatus(u32 addr,u32 *pStatus,u32 port){ MMCSD_Responses rp; MMCSD_STATUS ret; ret=_MMCSD_NoDataCommand(MMCSD_CMD13,addr<<16,MMCSDB_R1,port); if(ret) { //FAILED("CMD13 Failed with ret = 0x%x",ret); *pStatus = ret; return ret; } _MMCSD_GetResponses(&rp,MMCSDB_R1,port); *pStatus=rp.status; return ((rp.status)&MMCSD_STATUS_NOERROR);}/****************************************************************************** * Function Name: _MMCSD_SetBlockLen * * Input: None. * * Value Returned: * * MMCSD_STATUS * * Description: * * Modification History: * 30 DEC,2001, Initial version. Yiwei Zhao *****************************************************************************/MMCSD_STATUS _MMCSD_SetBlockLen(u32 size, u32 num,u32 port){ MMCSD_Responses rp; MMCSD_STATUS ret; _MMCSD_SetBlockLenReg(size,port); _MMCSD_SetNumberOfBlockReg(num,port); ret=_MMCSD_NoDataCommand(MMCSD_CMD16,size,MMCSDB_R1,port); if(ret) { FAILED("setBlockLen ret= %x \n",ret); return ret; } _MMCSD_GetResponses(&rp,MMCSDB_R1,port); return rp.status&MMCSD_STATUS_NOERROR;}/****************************************************************************** * Function Name: _MMCSD_TagSectorStart * * Input: U32 addr address * * Value Returned: * * MMCSD_STATUS * * Description: * CMD33 Sets the address of the first sector of the erase group * * Modification History: * 30 DEC,2001, Initial version. Yiwei Zhao *****************************************************************************/MMCSD_STATUS _MMCSD_TagSectorStart(u32 addr){ MMCSD_Responses rp; MMCSD_STATUS ret; ret=_MMCSD_NoDataCommand(MMCSD_CMD32,addr,MMCSDB_R1,0); if(ret) return ret; _MMCSD_GetResponses(&rp,MMCSDB_R1,0);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -