📄 mmc_cmd.c
字号:
* 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); return rp.status&MMCSD_STATUS_NOERROR;}/****************************************************************************** * Function Name: _MMCSD_TagSectorEnd * * Input: U32 addr address * * Value Returned: * * MMCSD_STATUS * * Description: * CMD33 Sets the address of the last sector of the erase group * * Modification History: * 30 DEC,2001, Initial version. Yiwei Zhao *****************************************************************************/MMCSD_STATUS _MMCSD_TagSectorEnd(u32 addr){ MMCSD_Responses rp; MMCSD_STATUS ret; ret=_MMCSD_NoDataCommand(MMCSD_CMD33,addr,MMCSDB_R1,0); if(ret) return ret; _MMCSD_GetResponses(&rp,MMCSDB_R1,0); return rp.status&MMCSD_STATUS_NOERROR;}/****************************************************************************** * Function Name: _MMCSD_Erase * * Input: * * Value Returned: * * MMCSD_STATUS * * Description: * Erase all previous selected blocks. * * Modification History: * 30 DEC,2001, Initial version. Yiwei Zhao *****************************************************************************/MMCSD_STATUS _MMCSD_Erase(){ MMCSD_Responses rp; MMCSD_STATUS ret; ret=_MMCSD_NoDataCommand(MMCSD_CMD38,0,MMCSDB_R1,0); if(ret) return ret; _MMCSD_GetResponses(&rp,MMCSDB_R1,0); return rp.status&MMCSD_STATUS_NOERROR;}/****************************************************************************** * Function Name: _MMCSD_NoDataCommand * * Input: * cmd Command Number * arg Command argument * ctrl Command control value inculding response type * * Value Returned: * * MMCSD_STATUS * * Description: * Send commend to MMC card and wait for response * * Modification History: * 30 DEC,2001, Initial version. Yiwei Zhao *****************************************************************************/extern u8 g_mmcsd_cmd[2];MMCSD_STATUS _MMCSD_NoDataCommand(u8 cmd, u32 arg,u32 ctrl,int port){ MMCSD_STATUS ret; u32 int_mask; int timeout = 100; switch(cmd) { case MMCSD_CMD16: timeout =50 ; break; case MMCSD_CMD6: timeout = 3; break; case MMCSD_CMD25: timeout = 50; break; case MMCSD_CMD38: timeout = 100*60*5; break; default : timeout = 100; } g_mmcsd_cmd[port] = cmd; _MMCSD_Mask_interrupt(0x7b,&int_mask,port); _MMCSD_StopClk(port); _MMCSD_SetCmd(cmd,arg,ctrl,port); _MMCSD_StartClk(port); if((cmd==MMCSD_CMD13)||(cmd==MMCSD_CMD55)) { ret=_MMCSD_WaitUntil(MMCSD_CMD_DONE,port); } else { ret=_MMCSD_irq_WaitUntil(MMCSD_CMD_DONE,cmd,timeout,port); } _MMCSD_Restore_Mask(int_mask,port); return ret; }MMCSD_STATUS _MMCSD_irq_WaitUntil(u32 EndCondition,u8 cmd,int timeout,int port){ MMCSD_Dev *device; u32 status,timeleft; device = g_selected_lock[port].device; if(device==NULL) { //polling //TRACE("device is NULL"); do { if(port == 1) status = mmcsdr_status_2; else status = mmcsdr_status; } while ((status&0x2002)==0); if(status&MMCSD_CMD_TIMEOUT) { if(port == 1) { FAILED("CMD Result: 0x%lx",mmcsdr_status_2); } else { FAILED("CMD Result: 0x%lx",mmcsdr_status); } } return (status&MMCSD_CMD_TIMEOUT); } if(port == 1) status = mmcsdr_status_2; // Sometimes, the interrupt has happened. else status = mmcsdr_status; // Sometimes, the interrupt has happened. if((status&(MMCSD_STATUS_ERR|MMCSD_END_CMD_RESP))==0) { timeleft = interruptible_sleep_on_timeout(&(device->select_wait),timeout); if(!timeleft) { if(port == 1) status = mmcsdr_status_2; // Sometimes, the interrupt has happened. else status = mmcsdr_status; // Sometimes, the interrupt has happened. if((status&(MMCSD_STATUS_ERR|MMCSD_END_CMD_RESP))==0) { FAILED("Time Out, mmcsdr_status = 0x%lx, cmd%d",(unsigned long)status,cmd); return MMCSD_ERROR; } TRACE("Time Out!,cmd%d",cmd); } else { status = device->result; } } if(status&MMCSD_STATUS_ERR) { //FAILED("error, status is 0x%0lX,(cmd%d) ",status,cmd); return(status&MMCSD_STATUS_ERR); } if(EndCondition == MMCSD_CMD_DONE) { if((status&MMCSD_END_CMD_RESP)==0) { FAILED("error, status is 0x%0lX,(cmd%d)",(unsigned long)status,cmd); return(MMCSD_ERROR); } } return (MMCSD_OK); }void _MMCSD_Mask_interrupt(u32 mask, u32 *orig, int port){ if(port == 1) { *orig = mmcsdr_int_mask_2; mmcsdr_int_mask_2 = mask; TRACE("Int_mask is 0x%0X",(unsigned long)mmcsdr_int_mask_2); } else { *orig = mmcsdr_int_mask; mmcsdr_int_mask = mask; TRACE("Int_mask is 0x%0X",(unsigned long)mmcsdr_int_mask); }}void _MMCSD_Restore_Mask(u32 orig,int port){ if(port == 1) mmcsdr_int_mask_2 = orig; else mmcsdr_int_mask = orig;// TRACE("*mmcsdr_int_mask = 0x%x",*mmcsdr_int_mask);}/****************************************************************************** * Function Name: _MMCSD_WaitUntil * * Input: * * Value Returned: * * MMCSD_STATUS * * Description: * Wait until Command done * * Modification History: * 30 DEC,2001, Initial version. Yiwei Zhao *****************************************************************************/MMCSD_STATUS _MMCSD_WaitUntil(u32 EndCondition,int port){ //waiting for the End Cmd Response volatile u32 status; u32 counter = 0xFFFFFFFF; do{ if(port == 1) status = mmcsdr_status_2; else status = mmcsdr_status; counter--; if(counter==0) { TRACE("Time Out."); return MMCSD_ERROR; } //TRACE("staus is %lx",status); } while ((status&(MMCSD_END_CMD_RESP|MMCSD_STATUS_ERR))==0); // if(status&MMCSD_STATUS_ERR) if(status&(MMCSD_READ_TIMEOUT|MMCSD_WRITE_CRC) != 0) { if(port == 1) { FAILED(" CMD Result: 0x%lx",mmcsdr_status_2); } else { FAILED(" CMD Result: 0x%lx",mmcsdr_status); } }// return (status&MMCSD_STATUS_ERR); return (status&(MMCSD_READ_TIMEOUT|MMCSD_WRITE_CRC)); }/****************************************************************************** * Function Name: _MMCSD_SetWriteProt * * Input: * * Value Returned: * * MMCSD_STATUS * * Description: * this routine will set the write protection bit for the addressed * group. * * Modification History: * 30 DEC,2001, Initial version. Yiwei Zhao *****************************************************************************/MMCSD_STATUS _MMCSD_SetWriteProt(u32 addr){ MMCSD_Responses rp; MMCSD_STATUS ret; ret=_MMCSD_NoDataCommand(MMCSD_CMD28,addr,MMCSDB_R1,0); if(ret) return ret; _MMCSD_GetResponses(&rp,MMCSDB_R1,0); return rp.status&MMCSD_STATUS_NOERROR;}/****************************************************************************** * Function Name: _MMCSD_ClearWriteProt * * Input: * * Value Returned: * * MMCSD_STATUS * * Description: * This routine will clear the write protection bit for the addressed * group. * * Modification History: * 30 DEC,2001, Initial version. Yiwei Zhao *****************************************************************************/MMCSD_STATUS _MMCSD_ClearWriteProt(u32 addr){ MMCSD_Responses rp; MMCSD_STATUS ret; ret=_MMCSD_NoDataCommand(MMCSD_CMD29,addr,MMCSDB_R1,0); if(ret) return ret; _MMCSD_GetResponses(&rp,MMCSDB_R1,0); return rp.status&MMCSD_STATUS_NOERROR;}MMCSD_STATUS _MMCSD_SetBusWidth(u32 rca, u32 width,u32 port){ MMCSD_Responses rp; MMCSD_STATUS ret; u32 para; //TRACE("Set Bus Width =%d",width); ret=_MMCSD_NoDataCommand(MMCSD_CMD55,rca<<16,MMCSDB_R1,port); if(ret) { TRACE("CMD55 failed with ret = 0x%lx",ret); return ret; } _MMCSD_GetResponses(&rp,MMCSDB_R1,port);// para = (rca<<16)|width; para = width; ret=_MMCSD_NoDataCommand(MMCSD_ACMD6,para,MMCSDB_R1,port); if(ret) { TRACE("ACMD6 failed with ret = 0x%lx",ret); return ret; //meet some error } _MMCSD_GetResponses(&rp,MMCSDB_R1,port); return MMCSD_OK;}/*MMCSD_STATUS _MMCSD_SendSCR(UINT32 rca,MMCSD_Responses *rp){ MMCSD_STATUS ret; ret=_MMCSD_NoDataCommand(MMCSD_CMD55,rca<<16,MMCSDB_R1); if(ret) { FAILED("CMD55 failed with ret = 0x%lx",ret); return ret; } _MMCSD_GetResponses(rp,MMCSDB_R1); ret=_MMCSD_NoDataCommand(MMCSD_ACMD51,0,MMCSDB_R1); if(ret) { FAILED("ACMD6 failed with ret = 0x%lx",ret); return ret; //meet some error } _MMCSD_GetResponses(rp,MMCSDB_R1); return MMCSD_OK;}*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -