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

📄 mcitest.c

📁 ARM7的lpc23xx的外设资源接口的所有驱动
💻 C
字号:
/*****************************************************************************
 *   mcitest.c:  main C entry file for NXP LPC23xx/24xx Family Microprocessors
 *
 *   Copyright(C) 2006, NXP Semiconductor
 *   All rights reserved.
 *
 *   History
 *   2006.07.20  ver 1.00    Prelimnary version, first Release
 *
******************************************************************************/
#include "LPC23xx.h"                       /* LPC23xx/24xx definitions */
#include "type.h"
#include "irq.h"
#include "mci.h"
#include "dma.h"

extern volatile DWORD CardType;

/* Below buffer allocation could be simplier, if the buffer used for DMA and non-DMA 
are shared. Future clear up will be needed. For now, leave as it's. */
#if MCI_DMA_ENABLED
DWORD *src_addr; 
DWORD *dest_addr;
#else
volatile BYTE WriteBlock[BLOCK_LENGTH], ReadBlock[BLOCK_LENGTH];
volatile DWORD TXBlockCounter, RXBlockCounter;
#endif

/******************************************************************************
**   Main Function  main()
******************************************************************************/
int main (void)
{
	DWORD i, j;

	/* Fill block data pattern in write buffer and clear everything 
	in read buffer. */
#if MCI_DMA_ENABLED
	/* on DMA channel 0, source is memory, destination is MCI FIFO. */
	/* On DMA channel 1, source is MCI FIFO, destination is memory. */
	PCONP |= (1 << 29);	/* Enable GPDMA clock */

	src_addr = (DWORD *)DMA_SRC;
	dest_addr = (DWORD *)DMA_DST;
	for ( i = 0; i < DMA_SIZE; i++ )
	{
		*src_addr = i;
		*dest_addr = 0;
		src_addr++;
		dest_addr++;
	}
#else
	for ( i = 0; i < BLOCK_LENGTH; i++ )
	{
		WriteBlock[i] = i;
		ReadBlock[i] = 0;
	}
#endif
	
	/* For the SD card I tested, the minimum required block length is 512 */
	/* For MMC, the restriction is loose, due to the variety of SD and MMC
	card support, ideally, the driver should read CSD register to find the 
	right speed and block length for the card, and set them accordingly.
	In this driver example, it will support both MMC and SD cards, and it
	does read the information by send SEND_CSD to poll the card status,
	however, to simplify the example, it doesn't configure them accordingly
	based on the CSD register value. This is not intended to support all 
	the SD and MMC cards. */
    if ( MCI_Init() != TRUE )
    {
		while( 1 );			/* fatal error */
    }

	if ( (CardType = MCI_CardInit()) == CARD_UNKNOWN )
	{
		while ( 1 );		/* fatal error */
	}

	if ( MCI_Check_CID() != TRUE )
	{
		while ( 1 );		/* fatal error */
	}

	if ( MCI_Set_Address() != TRUE )
	{
		while ( 1 );		/* fatal error */
	}

	if ( MCI_Send_CSD() != TRUE )
	{
		while ( 1 );		/* fatal error */
	}

	if ( MCI_Select_Card() != TRUE )
	{
		while ( 1 );		/* fatal error */
	}

	if ( CardType == SD_CARD )
	{
		MCI_CLOCK |= (1 << 11);		/* Use wide bus for SD */
		for ( i = 0; i < 0x20; i++ );
		if ( MCI_Send_ACMD_Bus_Width( BUS_WIDTH_4BITS ) == FALSE )
		{
			while ( 1 );	/* fatal error */
		}
	}

	if ( MCI_Set_BlockLen( BLOCK_LENGTH ) != TRUE )
	{
		while ( 1 );		/* fatal error */
	}

	for ( i = 0; i < BLOCK_NUM; i++ )
    {
#if !MCI_DMA_ENABLED
		TXBlockCounter = 0;
		RXBlockCounter = 0;
#endif
		if ( MCI_Write_Block( i ) != TRUE )
		{
			while ( 1 );		/* Fatal error */
		}

		/* When TX_ACTIVE is not set, it indicates TX is done from 
		Interrupt_Write_Block, now, Interrupt_Read_Block can start. */
		while ( MCI_STATUS & MCI_TX_ACTIVE );
		/* Note TXEnable() is called in the Interrupt_Write_Block(). */
		MCI_TXDisable();

		if ( MCI_Read_Block( i ) != TRUE )
		{
			while ( 1 );		/* Fatal error */
		}
		/* When RX_ACTIVE is not set, it indicates RX is done from 
		Interrupt_Read_Block, now, validation of RX and TX buffer can start. */
		while ( MCI_STATUS & MCI_RX_ACTIVE );
		/* Note RXEnable() is called in the Interrupt_Read_Block(). */
		MCI_RXDisable();
		
#if MCI_DMA_ENABLED
		src_addr = (DWORD *)DMA_SRC;
		dest_addr = (DWORD *)DMA_DST;	
		for ( j = 0; j < BLOCK_LENGTH; j++ )
		{
			if ( *src_addr != *dest_addr )
			{
				while ( 1 );	/* Data comparison failure, fatal error */
			}
		}
		/* clear read buffer for next comparison */
		for ( j = 0; j < BLOCK_LENGTH; j++ )
		{
			*dest_addr = 0;
		}	 
#else	
		for ( j = 0; j < BLOCK_LENGTH; j++ )
		{
			if ( WriteBlock[j] != ReadBlock[j] )
			{
				while ( 1 );	/* Data comparison failure, fatal error */
			}
		}
		/* clear read buffer for next comparison */
		for ( j = 0; j < BLOCK_LENGTH; j++ )
		{
			ReadBlock[j] = 0;
		}
#endif			 
	}
    return 0;
}

/******************************************************************************
**                            End Of File
******************************************************************************/

⌨️ 快捷键说明

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