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

📄 sdi.c

📁 samsung2410 s SD card opinion diver
💻 C
📖 第 1 页 / 共 4 页
字号:
	rSDIDSTA=0xff;

STWCMD12:    
    //--Stop cmd(CMD12)
	//SDIDCON  BlkNum                           [11: 0] = block : Block Number (0~4095).
    //SDIDCON  Data Transfer Mode (DatMode)     [13:12] = 1     : only busy check start
    //SDIDCON  Stop by force (STOP)             [14   ] = 0     : normal
    //SDIDCON  DMA Enable(EnDMA)			    [15   ] = 0     : disable(polling),
    //SDIDCON  Wide bus enable (WideBus)        [16   ] = 0     : standard bus mode(only SDIDAT[0] used),
    //SDIDCON  Block mode (BlkMode)  		    [17   ] = 1     : blk 
    //SDIDCON  Busy AfterCommand(BACMD)         [18   ] = 1     : after command sent (assume DatMode sets to 2’b01)
    //SDIDCON  Receive After Command (RACMD)    [19   ] = 1     : Rx after cmd
    //SDIDCON  Transmit After Response(TARSP)   [20   ] = 0     : directly after DatMode set,
    //SDIDCON  SDIO InterruptPeriodType(PrdType)[21   ] = 0     : exactly 2 cycle,
	rSDIDCON=(1<<18)|(1<<17)|(0<<16)|(1<<12);

	//SDICARG CmdArg [31:0] = 0 : Command Argument
    rSDICARG=0x0;	    //CMD12(stuff bit)

	//SDICCON CmdIndex              [7:0] = 0X4c : CMD12
	//SDICCON Command Start(CMST)   [8  ] = 1    : command start
	//SDICCON WaitRsp               [9  ] = 1    : wait_resp
	//SDICCON LongRsp               [10 ] = 0    : short response
	rSDICCON=(0x1<<9)|(0x1<<8)|0x4c;   //sht_resp, wait_resp, start, CMD12

    //-- Check end of CMD12
    if(!Chk_CMDend(12, 1)) 
	goto STWCMD12;
    //rSDICSTA=0xa00;	// Clear cmd_end(with rsp)

    //-- Check end of DATA(with busy state)
    if(!Chk_BUSYend()) 
	Uart_Printf("error\n");

	//SDIDSTA  Rx Data Progress On (RxDatOn) [0 ]  R  : Data receive in progress.
	//SDIDSTA  Tx Data progress On (TxDatOn) [1 ]  R  : Data transmit in progress.
	//SDIDSTA  Start Bit Error (SbitErr)     [2 ] =0  : not detect,
	//SDIDSTA  Busy Finish (BusyFin)         [3 ] =1  : busy finish detect
	//SDIDSTA  Data Transfer Finish (DatFin) [4 ] =0  : not detect,
	//SDIDSTA  Data Time Out (DatTout)       [5 ] =0  : not detect,
	//SDIDSTA  Data Receive CRC Fail (DatCrc)[6 ] =0  : not detect,
	//SDIDSTA  CRC Status Fail(CrcSta)       [7 ] =0  : not detect,
	//SDIDSTA  FIFO Fail error (FFfail)      [8 ] =0  : not detect,
	//SDIDSTA  SDIO InterruptDetect(IOIntDet)[9 ] =0  : not detect,
	//SDIDSTA  Data Time Out (DatTout)       [10] =0  : not occur,
	rSDIDSTA=0x08;

    Uart_Printf("\n--End Stream write test\n");
}


int Chk_CMDend(int cmd, int be_resp)
//0: Timeout
{
    int finish0;

    if(!be_resp)    // No response
    {	

		//SDICSTA  RspIndex                     [7:0]  R    Response index 6bit with start 2bit (8bit)
	    //SDICSTA  CMD line progress On (CmdOn) [8  ]  R    Command transfer in progress.
	    //SDICSTA  Response Receive End (RspFin)[9  ] = 1 : response end
	    //											  = 0 : not detect,
	    //SDICSTA  Command Time Out (CmdTout)   [10 ] = 1 : timeout
	    //											  = 0 : not detect
	    //SDICSTA  Command Sent (CmdSent)       [11 ] = 1 : command end
	    //											  = 0 : not detect
   		//SDICSTA  Response CRC Fail(RspCrc     [12 ] = 1 : crc fail
   		//											  = 0 : not detect
    	finish0=rSDICSTA;
	while((finish0&0x800)!=0x800)	// Check cmdend==1,
	    finish0=rSDICSTA;

	rSDICSTA=finish0;// Clear cmd end state

	return 1;
    }
    else	// With response
    {
    	finish0=rSDICSTA;
	while( !( ((finish0&0x200)==0x200) | ((finish0&0x400)==0x400) ))    // Check cmd/rsp end
    	    finish0=rSDICSTA;

	if(cmd==1 | cmd==9 | cmd==41)	// CRC no check
	{
	    if( (finish0&0xf00) != 0xa00 )  // Check error
	    {
		rSDICSTA=finish0;   // Clear error state

		if(((finish0&0x400)==0x400))
		    return 0;	// Timeout error
    	    }
	    rSDICSTA=finish0;	// Clear cmd & rsp end state
	}
	else	// CRC check
	{
	    if( (finish0&0x1f00) != 0xa00 )	// Check error
	    {
		Uart_Printf("CMD%d:rSDICSTA=0x%x, rSDIRSP0=0x%x\n",cmd, rSDICSTA, rSDIRSP0);
		rSDICSTA=finish0;   // Clear error state

		if(((finish0&0x400)==0x400))
		    return 0;	// Timeout error
    	    }
	    rSDICSTA=finish0;
	}
	return 1;
    }
}

int Chk_DATend(void)
{
    int finish;

    finish=rSDIDSTA;
    while( !( ((finish&0x10)==0x10) | ((finish&0x20)==0x20) ))	
	// Chek timeout or data end
	finish=rSDIDSTA;

    if( (finish&0xfc) != 0x10 )
    {
        Uart_Printf("DATA:finish=0x%x\n", finish);
        rSDIDSTA=0xec;  // Clear error state
        return 0;
    }
    return 1;
}

int Chk_BUSYend(void)
{
    int finish;

    finish=rSDIDSTA;
    while( !( ((finish&0x08)==0x08) | ((finish&0x20)==0x20) ))
	finish=rSDIDSTA;

    if( (finish&0xfc) != 0x08 )
    {
        Uart_Printf("DATA:finish=0x%x\n", finish);
        rSDIDSTA=0xf4;  //clear error state
        return 0;
    }
    return 1;
}

void CMD0(void)
{
    //-- Make card idle state 
	//SDICARG CmdArg [31:0] = 0 : Command Argument
	rSDICARG=0x0;	    // CMD0(stuff bit)

	//SDICCON CmdIndex              [7:0] = 0X40 : CMD0
	//SDICCON Command Start(CMST)   [8  ] = 1    : command start
	rSDICCON=(1<<8)|0x40;   
    //-- Check end of CMD0
    Chk_CMDend(0, 0);
    //rSDICSTA=0x800;	    // Clear cmd_end(no rsp)
}

int Chk_MMC_OCR(void)
{
    int i;

    //-- Negotiate operating condition for MMC, it makes card ready state
    for(i=0;i<15;i++)
    {
		//SDICARG CmdArg [31:0] = 0 : Command Argument
		rSDICARG=0xffc000;	    	    //CMD1(OCR:2.6V~3.6V)
//	rSDICARG=0xff8000;	    	    //CMD1(OCR:2.7V~3.6V)

		//SDICCON CmdIndex              [7:0] = 0X41 : CMD1
		//SDICCON Command Start(CMST)   [8  ] = 1    : command start
		//SDICCON WaitRsp               [9  ] = 1    : wait_resp
		//SDICCON LongRsp               [10 ] = 0    : short response
		rSDICCON=(0x1<<9)|(0x1<<8)|0x41;    

    	//-- Check end of CMD1
    	if(Chk_CMDend(1, 1) & rSDIRSP0==0x80ffc000) 
//	if(Chk_CMDend(1, 1) & rSDIRSP0==0x80ff8000) 
	{
	    //rSDICSTA=0xa00;	// Clear cmd_end(with rsp)
	    return 1;	// Success
	}
    }
    //rSDICSTA=0xa00;	// Clear cmd_end(with rsp)
    return 0;		// Fail
}

int Chk_SD_OCR(void)
{
    int i,j=0;

    //-- Negotiate operating condition for SD, it makes card ready state
    for(i=0;i<15;i++)
    {
    	CMD55();    // Make ACMD

    	rSDICARG=0xff8000;	//ACMD41(OCR:2.7V~3.6V)
    	rSDICCON=(0x1<<9)|(0x1<<8)|0x69;//sht_resp, wait_resp, start, ACMD41

	//-- Check end of ACMD41
    	if( Chk_CMDend(41, 1) & rSDIRSP0==0x80ff8000 ) 
	{
	    //rSDICSTA=0xa00;	// Clear cmd_end(with rsp)

	    return 1;	// Success	    
	}
	Delay(200); // Wait Card power up status
    }
    //Uart_Printf("SDIRSP0=0x%x\n",rSDIRSP0);
    //rSDICSTA=0xa00;	// Clear cmd_end(with rsp)
    return 0;		// Fail
}

int CMD55(void)
{
    //--Make ACMD

	//SDICARG CmdArg [31:0] = 0 : Command Argument
	rSDICARG=RCA<<16;			//CMD7(RCA,stuff bit)

	//SDICCON CmdIndex              [7:0] = 0X77 : CMD55
	//SDICCON Command Start(CMST)   [8  ] = 1    : command start
	//SDICCON WaitRsp               [9  ] = 1    : wait_resp
	//SDICCON LongRsp               [10 ] = 0    : short response
	rSDICCON=(0x1<<9)|(0x1<<8)|0x77;	//sht_resp, wait_resp, start, CMD55

    //-- Check end of CMD55
    if(!Chk_CMDend(55, 1)) 
	return 0;

    //rSDICSTA=0xa00;	// Clear cmd_end(with rsp)
    return 1;
}

int CMD13(void)//SEND_STATUS
{
    int response0;

	//SDICARG CmdArg [31:0] = 0 : Command Argument
    rSDICARG=RCA<<16;			// CMD13(RCA,stuff bit)

	//SDICCON CmdIndex              [7:0] = 0X4d : CMD13
	//SDICCON Command Start(CMST)   [8  ] = 1    : command start
	//SDICCON WaitRsp               [9  ] = 1    : wait_resp
	//SDICCON LongRsp               [10 ] = 0    : short response
	rSDICCON=(0x1<<9)|(0x1<<8)|0x4d;	// sht_resp, wait_resp, start, CMD13

    //-- Check end of CMD13
    if(!Chk_CMDend(13, 1)) 
	return 0;
    //Uart_Printf("rSDIRSP0=0x%x\n", rSDIRSP0);
    if(rSDIRSP0&0x100)
	Uart_Printf("Ready for Data\n");
    else 
	Uart_Printf("Not Ready\n");
    response0=rSDIRSP0;
    response0 &= 0x3c00;
    response0 = response0 >> 9;
    Uart_Printf("Current Status=%d\n", response0);
    if(response0==6)
	Test_SDI();

    //rSDICSTA=0xa00;	// Clear cmd_end(with rsp)
    return 1;
}

int CMD9(void)//SEND_CSD
{
	//SDICARG CmdArg [31:0] = 0 : Command Argument
	rSDICARG=RCA<<16;				// CMD9(RCA,stuff bit)

	//SDICCON CmdIndex              [7:0] = 0X49 : CMD9
	//SDICCON Command Start(CMST)   [8  ] = 1    : command start
	//SDICCON WaitRsp               [9  ] = 1    : wait_resp
	//SDICCON LongRsp               [10 ] = 1    : long response
	rSDICCON=(0x1<<10)|(0x1<<9)|(0x1<<8)|0x49;	

    Uart_Printf("\n****CSD register****\n");
    //-- Check end of CMD9
    if(!Chk_CMDend(9, 1)) 
	return 0;

    Uart_Printf(" SDIRSP0=0x%x\n SDIRSP1=0x%x\n SDIRSP2=0x%x\n SDIRSP3=0x%x\n", rSDIRSP0,rSDIRSP1,rSDIRSP2,rSDIRSP3);
    return 1;
}

void Set_1bit_bus(void)
{
    Wide=0;
    if(!MMC)
	SetBus();
    Uart_Printf("\n****1bit bus****\n");
}

void Set_4bit_bus(void)
{
    Wide=1;
    SetBus();
    Uart_Printf("\n****4bit bus****\n");
}

void SetBus(void)
{
SET_BUS:
    CMD55();	// Make ACMD
    //-- CMD6 implement
	//SDICARG CmdArg [31:0] = 0 : Command Argument
    rSDICARG=Wide<<1;	    //Wide 0: 1bit, 1: 4bit

    //SDICCON CmdIndex              [7:0] = 0X46 : CMD55
	//SDICCON Command Start(CMST)   [8  ] = 1    : command start
	//SDICCON WaitRsp               [9  ] = 1    : wait_resp
	//SDICCON LongRsp               [10 ] = 0    : short response
	rSDICCON=(0x1<<9)|(0x1<<8)|0x46;	//sht_resp, wait_resp, start, CMD55

    if(!Chk_CMDend(6, 1))   // ACMD6
	goto SET_BUS;
    //rSDICSTA=0xa00;	    // Clear cmd_end(with rsp)
}

void Set_Prt(void)
{
    //-- Set protection addr.0 ~ 262144(32*16*512) 
    Uart_Printf("[Set protection(addr.0 ~ 262144) test]\n");

RECMD28:
    //--Make ACMD
	//SDICARG CmdArg [31:0] = 0 : Command Argument
    rSDICARG=0;	    // CMD28(addr) 

	//SDICCON CmdIndex              [7:0] = 0X5c : CMD28
	//SDICCON Command Start(CMST)   [8  ] = 1    : command start
	//SDICCON WaitRsp               [9  ] = 1    : wait_resp
	//SDICCON LongRsp               [10 ] = 0    : short response
	rSDICCON=(0x1<<9)|(0x1<<8)|0x5c;	//sht_resp, wait_resp, start, CMD28

    //-- Check end of CMD28
    if(!Chk_CMDend(28, 1)) 
	goto RECMD28;
    //rSDICSTA=0xa00;	// Clear cmd_end(with rsp)
}

void Clr_Prt(void)
{
    //-- Clear protection addr.0 ~ 262144(32*16*512) 
    Uart_Printf("[Clear protection(addr.0 ~ 262144) test]\n");

RECMD29:
    //--Make ACMD
    //SDICARG CmdArg [31:0] = 0 : Command Argument
    rSDICARG=0;	    // CMD29(addr)

	//SDICCON CmdIndex              [7:0] = 0X5d : CMD29
	//SDICCON Command Start(CMST)   [8  ] = 1    : command start
	//SDICCON WaitRsp               [9  ] = 1    : wait_resp
	//SDICCON LongRsp               [10 ] = 0    : short response
	rSDICCON=(0x1<<9)|(0x1<<8)|0x5d;	//sht_resp, wait_resp, start, CMD29

    //-- Check end of CMD29
    if(!Chk_CMDend(29, 1)) 
	goto RECMD29;
    //rSDICSTA=0xa00;	// Clear cmd_end(with rsp)
}

⌨️ 快捷键说明

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