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

📄 sd_test.c

📁 TI的DM6446的硬件平台搭建的相关例子
💻 C
字号:
/*
 *  Copyright 2005 by Spectrum Digital Incorporated.
 *  All rights reserved. Property of Spectrum Digital Incorporated.
 *
 *  Not for distribution.
 */

/*
 *  SD Card Test
 *
 */

#include "stdio.h"
#include "mmcsdTest.h"

#include "davincievm.h"
#include "davincievm_msp430.h"
#include "davincievm_pmx.h"
#include "davincievm_gpio.h"


Uint8 id[512];
Uint8 tx[512];
Uint8 rx[512];

/* ------------------------------------------------------------------------ *
 *                                                                          *
 *  SD Init                                                                 *
 *                                                                          *
 * ------------------------------------------------------------------------ */
void sd_init( )
{
    DAVINCIEVM_PMX_init( );
    DAVINCIEVM_PMX_clear( 0, 0x00000200 ); // Enable SD Card
}

/* ------------------------------------------------------------------------ *
 *                                                                          *
 *  SD Card Detect                                                          *
 *                                                                          *
 * ------------------------------------------------------------------------ */
Int16 sd_card_detect( )
{
    Uint8 current_state1, current_state2;

    /*
     *  Grab the current state
     */
    PINMUX0&=0xffffffe0;
	DAVINCIEVM_GPIO_setDirection(21,1);
	DAVINCIEVM_GPIO_setDirection(25,1);
    current_state1=DAVINCIEVM_GPIO_getInput(21);
	current_state2=DAVINCIEVM_GPIO_getInput(25);
    if (current_state1== 0 )
    {
        printf( "    SD/MMC Found\n" );

        if (current_state2== 0 )
		{
		    printf( "    SD/MMC.WP is OFF\n" );
            return 0;
		}
		else
		{
		    printf( "    SD/MMC.WP is ON\n" );
	        return 1;

		}
    }
    else
    {
        printf( "    SD/MMC Not Found\n" );
        return 1;
    }
}

/* ------------------------------------------------------------------------ *
 *                                                                          *
 *  SD Test                                                                 *
 *                                                                          *
 * ------------------------------------------------------------------------ */
Uint16 sd_test( )
{
	Uint16 i;
	Uint16 errorflag    = 0;
	Uint32 relCardAddr  = 2;
    Uint32 cardAddr     = 4096;
	Uint32 blkLength    = 512;

	MMCSD_cardStatusReg cardStatus;
	MMCSD_ConfigData    mmcsdConfig2 = {
		MMCSD_LITTLE_ENDIAN,  // write Endian
		MMCSD_LITTLE_ENDIAN,  // read Endian
		MMCSD_DAT3_DISABLE,   // Edge Detection disbale
		FALSE,                // SpiModeEnable
		FALSE,                // csEnable
		FALSE,                // spiCrcEnable
		0,
		FALSE,                // SpiModeEnable
		FALSE,                // csEnable
		FALSE,                // spiCrcEnable
		MMCSD_DATA_BUS_4,     // data bus width
		0xFF,                 // response timeout
		0xFFFF                // data read timeout
	};

	/*
	 *  Fill tx buffer and clear rx buffer
	 */
	for( i = 0 ; i < 512 ; i++ )
	{
		tx[i]= i;
		rx[i]= 0;
	}

	if ( sd_card_detect( ) )
	{
		return 1;
	}


	if ( MMCSD_initCard( &relCardAddr, &cardStatus, &mmcsdConfig2,
						 MMCSD_FIFOLEVEL_32BYTES, MMCSD_SECUREDIGITALCARD ) )
	{
		printf( "SD Card Initialization failed\n" );
		return 1;
	}

	/*
	 *  Write Block
	 */
	if ( MMCSD_singleBlkWrite( cardAddr, ( Uint32* )tx, blkLength, FALSE, 0 ) )
	{
		printf( "ERROR : SD Write block\n" );
		return 1;
	}

	/*
	 *  Read Block
	 */
	if ( MMCSD_singleBlkRead( cardAddr, ( Uint32* )rx, blkLength, FALSE, 0 ) )
	{
		printf( "ERROR : SD Read block\n" );
		return 1;
	}

	/*
	 * Compare tx and Rx Buffers
	 */
	for ( i = 0 ; i < 512 ; i++ )
	{
		if ( rx[i] != tx[i] )
		{
			errorflag++;
			break;
		}
	}

	return errorflag;
}

⌨️ 快捷键说明

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