示例#1
0
int SD_card_init(void)
{
//-- SD controller & card initialize
    int i;

    /* Important notice for MMC test condition */
    /* Cmd & Data lines must be enabled by pull up resister */

    rSDIPRE=PCLK/(INICLK)-1;	// 400KHz
	Uart_Printf("Init. Frequency is %dHz\n",(PCLK/(rSDIPRE+1)));

	rSDICON=(1<<4)|1;	// Type B, clk enable
	rSDIFSTA=rSDIFSTA|(1<<16);	//YH 040223 FIFO reset
    rSDIBSIZE=0x200;		// 512byte(128word)
    rSDIDTIMER=0x7fffff;		// Set timeout count

    for(i=0;i<0x1000;i++);  // Wait 74SDCLK for MMC card

    CMD0();
    Uart_Printf("In idle\n");

    //-- Check MMC card OCR
    if(Chk_MMC_OCR())
    {
	Uart_Printf("In MMC ready\n");
	MMC=1;
	goto RECMD2;
    }

    Uart_Printf("MMC check end!!\n");
    //-- Check SD card OCR
    if(Chk_SD_OCR())
        Uart_Printf("In SD ready\n");

    else
    {
		Uart_Printf("Initialize fail\nNo Card assertion\n");
        return 0;
    }

RECMD2:
    //-- Check attaced cards, it makes card identification state
    rSDICARG=0x0;   // CMD2(stuff bit)
    rSDICCON=(0x1<<10)|(0x1<<9)|(0x1<<8)|0x42; //lng_resp, wait_resp, start, CMD2

    //-- Check end of CMD2
    if(!Chk_CMDend(2, 1))
	goto RECMD2;
    rSDICSTA=0xa00;	// Clear cmd_end(with rsp)

    Uart_Printf("End id\n");

RECMD3:
    //--Send RCA
    rSDICARG=MMC<<16;	    // CMD3(MMC:Set RCA, SD:Ask RCA-->SBZ)
    rSDICCON=(0x1<<9)|(0x1<<8)|0x43;	// sht_resp, wait_resp, start, CMD3

    //-- Check end of CMD3
    if(!Chk_CMDend(3, 1))
	goto RECMD3;
    rSDICSTA=0xa00;	// Clear cmd_end(with rsp)

    //--Publish RCA
    if(MMC) {
	RCA=1;
        rSDIPRE=(PCLK/MMCCLK)-1;
        Uart_Printf("MMC Frequency is %dHz\n",(PCLK/(rSDIPRE+1)));
    	}
    else
    	{
			RCA=( rSDIRSP0 & 0xffff0000 )>>16;
		    Uart_Printf("RCA=0x%x\n",RCA);

			rSDIPRE=PCLK/(SDCLK)-1;	// Normal clock=25MHz
			Uart_Printf("SD Frequency is %dHz\n",(PCLK/(rSDIPRE+1)));
    	}	    //--State(stand-by) check
    if( rSDIRSP0 & 0x1e00!=0x600 )  // CURRENT_STATE check
	goto RECMD3;

    Uart_Printf("In stand-by\n");


    Card_sel_desel(1);	// Select

    if(!MMC)
	Set_4bit_bus();
    else
	Set_1bit_bus();

    return 1;
}
示例#2
0
int SD_card_init(void)
{
//-- SD controller & card initialize 
	int i;

	/* Important notice for MMC test condition */
	/* Cmd & Data lines must be enabled by pull up resister */

	SDIPRE=PCLK/(INICLK)-1;	// 400KHz
	//Uart_Printf("Init. Frequency is %dHz\n",(PCLK/(SDIPRE+1)));
    
	SDICON=(1<<4)|1;	// Type B, clk enable
	SDIFSTA=SDIFSTA|(1<<16);	//YH 040223 FIFO reset
	SDIBSIZE=0x200;		// 512byte(128word)
	SDIDTIMER=0x7fffff;		// Set timeout count

	for(i=0;i<0x1000;i++);  // Wait 74SDCLK for MMC card

	CMD0();
	//Uart_Printf("In idle\n");

	//-- Check SD card OCR
	if(!Chk_SD_OCR())
	{
		// fail
		GPBDAT = (~(2<<5));	 	// 点亮LED2
		//Uart_Printf("Initialize fail\nNo Card assertion\n");
		return 0;
	}

//	Uart_Printf("In SD ready\n");
	GPBDAT = (~(1<<5));	 	// 点亮LED1

	do
	{
		//-- Check attaced cards, it makes card identification state
		SDICARG = 0x0; // CMD2(stuff bit)
		SDICCON = (0x1 << 10) | (0x1 << 9) | (0x1 << 8) | (MAGIC_NUMBER | 2); //lng_resp, wait_resp, start, CMD2

		//-- Check end of CMD2
	} while (!Chk_CMDend(2, 1));

	SDICSTA=0xa00;	// Clear cmd_end(with rsp)

	//Uart_Printf("End id\n");

	do
	{
		//--Send RCA
		SDICARG = MMC << 16; // CMD3(MMC:Set RCA, SD:Ask RCA-->SBZ)
		SDICCON = (0x1 << 9) | (0x1 << 8) | (MAGIC_NUMBER | 3); // sht_resp, wait_resp, start, CMD3

		//-- Check end of CMD3
		if (!Chk_CMDend(3, 1))
			continue;
		SDICSTA = 0xa00; // Clear cmd_end(with rsp)

		//--Publish RCA
		RCA = (SDIRSP0 & 0xffff0000) >> 16;
		//Uart_Printf("RCA=0x%x\n",RCA);
		SDIPRE = PCLK / (SDCLK) - 1; // Normal clock=25MHz
		//Uart_Printf("SD Frequency is %dHz\n",(PCLK/(SDIPRE+1)));

		//--State(stand-by) check
		if (SDIRSP0 & 0x1e00 != 0x600) // CURRENT_STATE check
			continue;

	} while (0);
    
	//Uart_Printf("In stand-by\n");
    
	Card_sel_desel(1);	// Select

	Set_4bit_bus();

	return 1;
}