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

📄 pu_irom_mmc.c

📁 freescale atk source code
💻 C
📖 第 1 页 / 共 2 页
字号:
   	}		/* Configure start erase command to set first block*/	card_command_config(&cmd,startEraseBlockCmd, startBlock, SD_COMMAND, RESPONSE_48,                    DATA_PRESENT_NONE, ENABLE,ENABLE);    	/* wait response */	if ((ret = interface_send_cmd_wait_resp(&cmd)) == SUCCESS)    {    	/* Configure end erase command to set end block*/		card_command_config(&cmd, endEraseBlockCmd, endBlock, SD_COMMAND,                         RESPONSE_48, DATA_PRESENT_NONE, ENABLE,ENABLE);    	if ((ret = interface_send_cmd_wait_resp(&cmd)) == SUCCESS)        {		    /* Comfigure command to start erase*/	        	card_command_config(&cmd, CMD38, 0, SD_COMMAND, RESPONSE_48,	                              DATA_PRESENT_NONE, ENABLE, ENABLE);	    	if ((ret = interface_send_cmd_wait_resp(&cmd)) == SUCCESS)            {	    		//wait for completion				return ret;             	           	}	   	}	}		return ret;}/*==========================================================================                                     LOCAL FUNCTIONS==========================================================================*//*! * validate the operating volatge range of the card. * 1.Issue CMD1 to MMC card. * 2.Read the command response. * 3.Compare the response value with standard value specified in specification. * @return * UINT32 */UINT32 mmc_voltage_validation (void){    command_t cmd;    command_response_t response;    UINT32 voltage_validation_command=0;    UINT32 ocr_val=0;    UINT32 voltage_validation = FAIL;	    ocr_val = (UINT32) ((MMC_OCR_VALUE) & 0xFFFFFFFF);	    while((voltage_validation_command < MMCSD_READY_TIMEOUT ) && (voltage_validation != SUCCESS))     {  	        /* Configure CMD1 for MMC card */        /* Argument will be expected OCR value */        card_command_config(&cmd, CMD1, ocr_val, READ, RESPONSE_48_WITHOUT_CRC,                                  DATA_PRESENT_NONE, DISABLE, DISABLE);                         /* Issue CMD1 to MMC card to determine OCR value */        if(interface_send_cmd_wait_resp(&cmd) == FAIL)        {             voltage_validation = FAIL;             break;        }        else        {            /* Read Response from CMDRSP0 Register */            response.format = RESPONSE_48;            interface_read_response(&response);		            /* Check if card busy bit is cleared or not */            if(!(response.cmd_rsp0 & CARD_BUSY_BIT))            {                /* Iterate One more time */                voltage_validation_command++;            }            else            {                if((response.cmd_rsp0 & MMC_OCR_HC_RES) == MMC_OCR_HC_RES)                {                      address_mode = SECT_MODE;                     voltage_validation = SUCCESS;                }                else if((response.cmd_rsp0 & MMC_OCR_LC_RES) == MMC_OCR_LC_RES)                {                    address_mode = BYTE_MODE;                     voltage_validation = SUCCESS;                }            }                             }    }	    return voltage_validation;}/*! * set RCA of MMC card. * 1.Set RCA value to relative card address. * 2.Send Command CMD3 with argument of 16 bits which will be used as RCA value. * 3.This will set the RCA of the card as desired value. * @return   SUCCESS / FAILURE */static UINT32 mmc_set_rca (void){    command_t cmd;    UINT32 card_state=0;    UINT32 rca_request=0;    command_response_t response;    UINT32 card_address = (Card_rca << RCA_SHIFT);	    /* Configure CMD3 for MMC card */    /* 32bit card address is expected as Argument */    card_command_config(&cmd,CMD3,card_address,READ,RESPONSE_48,                    DATA_PRESENT_NONE,ENABLE,ENABLE);	                    	                        /* Assigns relative address to the card    */         if(interface_send_cmd_wait_resp(&cmd) == FAIL)    {        rca_request = FAIL;    } 	    else    {        /* Read Command response */        response.format = RESPONSE_48;        interface_read_response (&response);			card_state = (((UINT32) (response.cmd_rsp0 & MMCSD_R1_STATUS_CURR_STATE)) >> CURR_STATE_SHIFT);		if(card_state == IDENT)	{            rca_request = SUCCESS;				}	else	{            rca_request = FAIL;        }    }		    return rca_request;}/*! * read MMC CSD register and return SPEC_VER. * 1.Send CMD9 to get CSD value of MMC Card.  * 2.Extract CSD value from CMDRSP0,CMDRSP1,CMDRSP2,CMDRSP3 registers. * 3.Return Spec version of MMC card.  * @return  * UINT32 */static UINT32 mmc_get_spec_ver (void){		    command_t cmd;    command_response_t response;    card_specific_data csd;    UINT32 mmc_spec_version;    UINT32 card_address = (Card_rca << RCA_SHIFT);	    /* Configure CMD9 for MMC card */    /* 16bit card address is expected as Argument */    card_command_config(&cmd,CMD9,card_address,READ,RESPONSE_136,                    DATA_PRESENT_NONE,ENABLE,DISABLE);		    /* Issue Command CMD9 to Extrace CSD register contents     */         if(interface_send_cmd_wait_resp(&cmd) == FAIL)    {        mmc_spec_version = 0;    }	    else    {        /* Read Command response */        response.format = RESPONSE_136;        interface_read_response (&response);		        /* Assign Response to CSD Strcuture */        csd.csd0 = response.cmd_rsp0;	csd.csd1 = response.cmd_rsp1;	csd.csd2 = response.cmd_rsp2;	csd.csd3 = response.cmd_rsp3;			mmc_spec_version = ((csd.csd3 && MMC_SPEC_VER) >> MMC_SPEC_VER_SHIFT);    }	    return mmc_spec_version;		}/*! * will set bus width of MMC Card. * 1. Check if the value of SPEC_VER is 4 or above  * 2. if bus width request is 4 or 8 and spec verison less than 4 * 3. Report error that MMC doesnt support multiple bit width pattern. * 4. send CMD6 with argument 0x3B70x00; (8-bit, x=2; 4-bit, x=1; 1-bit, x=0) * 5. send CMD13 to wait card ready (busy line released) * @spec_version * @bus_width * @return * UINT32 */static UINT32 mmc_set_bus_width (UINT32 spec_version,UINT32 bus_width){    command_t cmd;    UINT32 switch_error;    UINT32 bus_size;    UINT32 set_bus_width_status;    command_response_t response;       UINT32 card_address = (Card_rca << RCA_SHIFT);	    if ((bus_width == FOUR || bus_width == EIGHT) && (spec_version < FOUR ))    {        set_bus_width_status = FAIL;    }    else    {        bus_size = (bus_width >> BUS_SIZE_SHIFT);		        /* Configure CMD6 to write to EXT_CSD register for BUS_WIDTH */	card_command_config(&cmd,CMD6,((BUS_WIDTH)|(bus_size<<EIGHT)),READ,RESPONSE_48,	                    DATA_PRESENT_NONE,ENABLE,ENABLE);						        /* Sending the card from stand-by to transfer state        */		        if(interface_send_cmd_wait_resp(&cmd) == FAIL)        {            set_bus_width_status = FAIL;        }        else        {            /* Configure CMD13 to read status of the card becuase CMD6 has R1b response */            card_command_config(&cmd,CMD13,card_address,READ,RESPONSE_48,	                    DATA_PRESENT_NONE,ENABLE,ENABLE);			            if(interface_send_cmd_wait_resp(&cmd) == FAIL)            {                set_bus_width_status = FAIL;            }			            else            {                /* Read Command response */                response.format = RESPONSE_48;                interface_read_response (&response);                switch_error = ((UINT32) (response.cmd_rsp0 & MMC_R1_SWITCH_ERROR_MASK) >> SWITCH_ERROR_SHIFT);				                if(!switch_error)                {                    set_bus_width_status = SUCCESS;                }            }	        }    }	    return set_bus_width_status;}

⌨️ 快捷键说明

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