📄 pu_irom_sd.c
字号:
{#ifdef TY_DBG { // Terry adds for debug, :-) U8 au8StrBuf[100] = { 0 }; sprintf(au8StrBuf, "Ty: Send CMD38 failed!\n"); atk_channel_send(au8StrBuf, sizeof(au8StrBuf)); }#endif } } else {#ifdef TY_DBG { // Terry adds for debug, :-) U8 au8StrBuf[100] = { 0 }; sprintf(au8StrBuf, "Ty: Send CMD33 failed!\n"); atk_channel_send(au8StrBuf, sizeof(au8StrBuf)); }#endif } } else {#ifdef TY_DBG { // Terry adds for debug, :-) U8 au8StrBuf[100] = { 0 }; sprintf(au8StrBuf, "Ty: Send CMD32 failed!\n"); atk_channel_send(au8StrBuf, sizeof(au8StrBuf)); }#endif } #ifdef TY_DBG { // Terry adds for debug, :-) U8 au8StrBuf[100] = { 0 }; sprintf(au8StrBuf, "Ty, Exit: sd_data_erase, ret:%d\n", ret); atk_channel_send(au8StrBuf, sizeof(au8StrBuf)); }#endif return ret;}/*! * validate the operating volatge range of the SD Memory card. * 1.Issue CMD55 to SD card with RCA value with default RCA i.e. 0x0000 * 2. Issue ACMD41 with argument value specified in specification. * 2.Read the command response. * 3.Compare the response value with standard value specified in specification. * 4.if it is not in the range send R15 command to put in in-active state. * @return int - voltage range */UINT32 sd_voltage_validation (void){ command_t cmd; command_response_t response; UINT32 voltage_validation_command =0; UINT32 default_rca = 0; UINT32 ocr_value=0; UINT32 voltage_validation = FAIL; //UINT32 voltage_validation = -30;#ifdef TY_DBG { // Terry adds for debug, :-) U8 au8StrBuf[100] = { 0 }; sprintf(au8StrBuf, "Ty, Entry: sd_voltage_validation\n"); atk_channel_send(au8StrBuf, sizeof(au8StrBuf)); }#endif while ((voltage_validation_command < MMCSD_READY_TIMEOUT) && (voltage_validation != SUCCESS)) { /* Configure CMD55 for SD card */ /* This command expects defualt RCA 0x0000 as argument.*/ card_command_config(&cmd,CMD55,default_rca,READ,RESPONSE_48, DATA_PRESENT_NONE,ENABLE,ENABLE); /* Issue CMD55 to SD Memory card*/ if(interface_send_cmd_wait_resp(&cmd) == FAIL) {#ifdef TY_DBG { // Terry adds for debug, :-) U8 au8StrBuf[100] = { 0 }; sprintf(au8StrBuf, "Ty, Use ACMD failed\n"); atk_channel_send(au8StrBuf, sizeof(au8StrBuf)); }#endif voltage_validation = FAIL; //voltage_validation = -31; break; } else { /* Configure ACMD41 for SD card */ /* This command expects operating voltage range as argument.*/#ifdef TY_DBG { // Terry adds for debug, :-) U8 au8StrBuf[100] = { 0 }; sprintf(au8StrBuf, "Ty, Use ACMD succeed!\n"); atk_channel_send(au8StrBuf, sizeof(au8StrBuf)); }#endif ocr_value = ((UINT32)(SD_OCR_VALUE) & 0xFFFFFFFF); card_command_config(&cmd,ACMD41,ocr_value,READ,RESPONSE_48_WITHOUT_CRC,DATA_PRESENT_NONE,DISABLE,DISABLE); /* Issue ACMD41 to SD Memory card to determine OCR value */ if(interface_send_cmd_wait_resp(&cmd) == FAIL) {#ifdef TY_DBG { // Terry adds for debug, :-) U8 au8StrBuf[100] = { 0 }; sprintf(au8StrBuf, "Ty, Get OCR failed!\n"); atk_channel_send(au8StrBuf, sizeof(au8StrBuf)); }#endif voltage_validation = FAIL; //voltage_validation = -32; break; } else { /* Read Response from CMDRSP0 Register */ response.format = RESPONSE_48; interface_read_response(&response); /* Obtain OCR Values from the response */ /* Obtain OCR value from the response buffer */ ocr_value = response.cmd_rsp0; /* Check if volatge lies in range or not*/ if((ocr_value & SD_OCR_VALUE_MASK) == SD_OCR_VALUE_MASK) {#ifdef TY_DBG { // Terry adds for debug, :-) U8 au8StrBuf[100] = { 0 }; sprintf(au8StrBuf, "Ty, Get OCR succeed!\n"); atk_channel_send(au8StrBuf, sizeof(au8StrBuf)); }#endif /* 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 & SD_OCR_HC_RES) == SD_OCR_HC_RES) { voltage_validation = SUCCESS; address_mode = SECT_MODE; } else if((response.cmd_rsp0 & SD_OCR_LC_RES) == SD_OCR_LC_RES) { voltage_validation = SUCCESS; address_mode = BYTE_MODE; } } } } } } #ifdef TY_DBG { // Terry adds for debug, :-) U8 au8StrBuf[100] = { 0 }; sprintf(au8StrBuf, "Ty, Exit: sd_voltage_validation, v_v:%d\n", voltage_validation); atk_channel_send(au8StrBuf, sizeof(au8StrBuf)); }#endif return voltage_validation;}/*! * return RCA published from SD Memory Card. * 1.Send Command CMD3 with No Argument * 2.SD Memory card will publish its RCA which will be used for future references. * 3. Check for card current state. * @return * UINT32 */static UINT32 sd_get_rca (void){ command_t cmd; UINT32 card_state=0; UINT32 rca_request=0; command_response_t response; /* Configure CMD3 for SD card */ /* 32bit card address is expected as Argument */ card_command_config(&cmd,CMD3,NO_ARG,READ,RESPONSE_48, DATA_PRESENT_NONE,ENABLE,ENABLE); /* Get relative address of 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_rca = ((UINT32) (response.cmd_rsp0 >> RCA_SHIFT)); #ifdef TY_DBG { // Terry adds for debug, :-) U8 au8StrBuf[100] = { 0 }; sprintf(au8StrBuf, "Ty, Card_rca:%d\n", Card_rca); atk_channel_send(au8StrBuf, sizeof(au8StrBuf)); }#endif card_state = (((UINT32) (response.cmd_rsp0 & SD_R6_STATUS_CURR_STATE)) >> CURR_STATE_SHIFT); if(card_state == IDENT) { rca_request = SUCCESS; } else { rca_request = FAIL; } } return rca_request;}/*! * read SD SCR register information. * @return * UINT32 */static UINT32 sd_get_bit_mode_support(void){ command_t cmd; UINT32 rd_data_buff[128]; UINT32 bit4_mode_support; command_response_t response; UINT32 card_address = (Card_rca << RCA_SHIFT); /* Configure CMD55 for SD card */ /* This command expects RCA as argument.*/ card_command_config(&cmd,CMD55,card_address,READ,RESPONSE_48, DATA_PRESENT_NONE,ENABLE,ENABLE); /* Issue CMD55 to SD Memory card*/ if(interface_send_cmd_wait_resp(&cmd) == FAIL) { bit4_mode_support = 0; } else { /* Read Command response */ response.format = RESPONSE_48; interface_read_response (&response); /* Afetr giving ACMD Command, the R1 response should have * STATUS_APP_CMD set */ if(response.cmd_rsp0 & SD_R1_STATUS_APP_CMD_MSK) { /* Configure ACMD51 for SD card */ /* This command expects No argument.*/ card_command_config(&cmd,ACMD51,NO_ARG,READ,RESPONSE_48,DATA_PRESENT,ENABLE,ENABLE); /* Issue ACMD51 to SD Memory card */ if(interface_send_cmd_wait_resp(&cmd) == FAIL) { bit4_mode_support = 0; } else { /* Read Response from e-SDHC buffer */ interface_data_read(rd_data_buff,512); /* Check for bus width supported */ bit4_mode_support = (rd_data_buff[SD_BUS_WIDTH_OFFSET] & BIT_MODE_4_SUPPORT); if(bit4_mode_support) { bit4_mode_support = BIT_4_MODE; } } } } return bit4_mode_support;}/*! * set bus width of SD Memory Card. * 1. Check if the value of data bus width 4 is supported or not? * 2. if bus width request is 4 ot 1 * 3. if request is for 4 bit and data bus width of 4 bit is * is not supported than Report error that SD Card doesnt support * multiple bit width pattern. * 4. send ACMD6 with argument 00 for 1 bit and 10 for 4 bit mode * 5. send ACMD13 to check whether required bus width is set or not. * @bus_width * @return * UINT32 */static UINT32 sd_set_bus_width (UINT32 bus_width){ command_t cmd; UINT32 set_bus_width_status=0; command_response_t response; UINT32 card_address = (Card_rca << RCA_SHIFT); if ((bus_width == FOUR ) || (bus_width == ONE)) { /* Configure CMD55 for SD card */ /* This command expects RCA as argument.*/ card_command_config(&cmd,CMD55,card_address,READ,RESPONSE_48, DATA_PRESENT_NONE,ENABLE,ENABLE); /* Issue CMD55 to SD Memory card*/ 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); /* Afetr giving ACMD Command, the R1 response should have * STATUS_APP_CMD set */ if(response.cmd_rsp0 & SD_R1_STATUS_APP_CMD_MSK) { bus_width = (bus_width>>ONE); /* Configure ACMD6 for SD card */ /* This command expects argument 00 for 1 bit mode support.*/ /* 10 for 4 bit mode support*/ card_command_config(&cmd,ACMD6,bus_width,READ,RESPONSE_48,DATA_PRESENT_NONE,ENABLE,ENABLE); /* Issue ACMD6 to SD Memory card*/ if(interface_send_cmd_wait_resp(&cmd) == FAIL) { set_bus_width_status = FAIL; } else { set_bus_width_status = SUCCESS; } } } } return set_bus_width_status; }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -