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

📄 mmcdev.c

📁 AT91RM9200 BSP with dual ethernet port
💻 C
📖 第 1 页 / 共 2 页
字号:
        return ERROR;    }/********************************************************************************* mmcBlkRd - read one or more blocks from a mmc disk** This routine reads one or more blocks from the specified device,* starting with the specified block number.** If any block offset was specified during mmcDevCreate(), it is added* to <startBlk> before the transfer takes place.** RETURNS: OK, ERROR if the read command didn't succeed.*/LOCAL STATUS mmcBlkRd    (    AT91PS_MciDevice pmmcDev,    int startBlk,    int nBlks,    char *pBuf    )    {    return (mmcBlkRW (pmmcDev, startBlk, nBlks, pBuf, O_RDONLY));    }/********************************************************************************* mmcBlkWrt - write one or more blocks to a mmc disk** This routine writes one or more blocks to the specified device,* starting with the specified block number.** If any block offset was specified during mmcDevCreate(), it is added* to <startBlk> before the transfer takes place.** RETURNS: OK, ERROR if the write command didn't succeed.*/LOCAL STATUS mmcBlkWrt    (    AT91PS_MciDevice pmmcDev,    int startBlk,    int nBlks,    char *pBuf    )    {    return (mmcBlkRW (pmmcDev, startBlk, nBlks, pBuf, O_WRONLY));    }/********************************************************************************* mmcReset - reset a mmc disk controller** This routine resets a mmc disk controller.** RETURNS: OK, always.*/LOCAL STATUS mmcReset    (    AT91PS_MciDevice pmmcDev    )    {        semTake (&mmcMuteSem, WAIT_FOREVER);   /*   mmcInit ();*/    semGive (&mmcMuteSem);    return (OK);    }/********************************************************************************* mmcIoctl - do device specific control function** This routine is called when the file system cannot handle an ioctl()* function.** RETURNS:  OK or ERROR.*/LOCAL STATUS mmcIoctl    (    AT91PS_MciDevice pmmcDev,    int function,    int arg    )    {    FAST int status = ERROR;    semTake (&mmcMuteSem, WAIT_FOREVER);    switch (function)	{	case FIODISKFORMAT:	    status = OK;	    break;	default:	    (void) errnoSet (S_ioLib_UNKNOWN_REQUEST);	}doneIoctl:    semGive (&mmcMuteSem);    return (status);    }/********************************************************************************* mmcBlkRW - read or write sectors to a mmc disk.** Read or write sectors to a mmc disk.** RETURNS: OK, ERROR if the command didn't succeed.*/LOCAL STATUS mmcBlkRW    (    AT91PS_MciDevice pMCI_Device,    int startBlk,    int nBlks,    char *pBuf,    int direction    )    {    BLK_DEV *pBlkDev = &pMCI_Device->blkDev;    int src,ix ;     int status = ERROR;    int semStatus = 0;    char databuf[1200];    int Max_Read_DataBlock_Length = pMCI_Device->pMCI_DeviceFeatures->Max_Read_DataBlock_Length;    startBlk+=pMCI_Device->blkOffset;    src = startBlk* Max_Read_DataBlock_Length;    semTake (&mmcMuteSem, WAIT_FOREVER);	memset(databuf,0,1200);if(direction==O_RDONLY){    for (ix = 0; ix < nBlks; ix ++)    {		/* ReadBlock & WriteBlock Test -> Entire Block	 Wait MCI Device Ready */			AT91F_MCI_ReadBlock(pMCI_Device,src,(unsigned int*)pBuf,Max_Read_DataBlock_Length);	semStatus = AT91F_MCmmcviceWaitReady(AT91C_MCI_TIMEOUT);	if ((mmcStatus & STAT_ERR) || (semStatus == ERROR))	        goto errorRW;        src += Max_Read_DataBlock_Length ;        pBuf += pBlkDev->bd_bytesPerBlk;    }}else{    for (ix = 0; ix < nBlks; ix ++)    {    memcpy(databuf,pBuf,pBlkDev->bd_bytesPerBlk);		AT91F_MCI_WriteBlock(pMCI_Device,(src),(unsigned int*) pBuf,Max_Read_DataBlock_Length);	semStatus = AT91F_MCmmcviceWaitReady(AT91C_MCI_TIMEOUT);	if ((mmcStatus & STAT_ERR) || (semStatus == ERROR))	        goto errorRW;        src += Max_Read_DataBlock_Length ;        pBuf += pBlkDev->bd_bytesPerBlk;     }}    status = OK;errorRW:    if (status == ERROR)        (void)errnoSet (S_ioLib_DEVICE_ERROR);    semGive (&mmcMuteSem);    return (status);    }/********************************************************************************* mmcIntr - mmc controller interrupt handler.** RETURNS: N/A*/LOCAL void mmcIntr    (    int ctrl    )    {mmcStatus = ( AT91C_BASE_MCI->MCI_SR & AT91C_BASE_MCI->MCI_IMR );AT91F_MCI_Device_Handler(pMCI_Device,mmcStatus);semGive (&mmcSyncSem);  }/********************************************************************************* mmcIntr - mmc controller watchdog handler.** RETURNS: N/A*/LOCAL void mmcWdog    (    int ctrl    )    {    mmcWaitForever = FALSE;    }/********************************************************************************* mmcWait - wait the drive ready** Wait the drive ready** RETURNS: OK, ERROR if the drive didn't become ready in certain period of time.*/LOCAL void mmcWait    (    int request    )    {	AT91F_MCmmcviceWaitReady(AT91C_MCI_TIMEOUT);	    if (mmcDebug)	printErr ("mmcWait end: \n");    }/********************************************************************************* mmcInit - init a mmc disk controller** This routine initializes a mmc disk controller.** RETURNS: OK, ERROR if the command didn't succeed.*/LOCAL void mmcInit (void)    {    /* Set up PIO SDC_TYPE to switch on MMC/SDCard and not DataFlash Card*/#ifdef __DK__    	AT91F_PIO_CfgOutput(AT91C_BASE_PIOB,AT91C_PIO_PB7);	AT91F_PIO_SetOutput(AT91C_BASE_PIOB,AT91C_PIO_PB7);#else	AT91F_PIO_CfgOutput(AT91C_BASE_PIOB,AT91C_PIO_PB22);	AT91F_PIO_SetOutput(AT91C_BASE_PIOB,AT91C_PIO_PB22);#endif		/* Init MCI for MMC and SDCard interface*/	AT91F_MCI_CfgPIO();		AT91F_MCI_CfgPMC();	AT91F_PDC_Open(AT91C_BASE_PDC_MCI);    /* Disable all the interrupts*/    AT91C_BASE_MCI->MCI_IDR = 0xFFFFFFFF;	/* Init MCI Device Structures*/	/*AT91F_CfgDevice();*/	/* Configure MCI interrupt *//*	AT91F_AIC_ConfigureIt(AT91C_BASE_AIC,						 AT91C_ID_MCI,						 AT91C_AIC_PRIOR_HIGHEST,						 AT91C_AIC_SRCTYPE_INT_LEVEL_SENSITIVE,						 AT91F_ASM_MCI_Handler);*/	/* Enable MCI interrupt*/	AT91F_AIC_EnableIt(AT91C_BASE_AIC,AT91C_ID_MCI);    if (mmcDebug)	printErr ("mmcInit end: \n");    }/********************************************************************************* mmcDiagnose - diagnose the drive** Diagnose the drive** RETURNS: OK, ERROR if the command didn't succeed.*/LOCAL STATUS mmcDiagnose (void)    {    return (OK);    }/********************************************************************************* mmcPinit - Initialize drive parameters** Initialize drive parameters.** RETURNS: OK, ERROR if the command didn't succeed.*/void AT91F_CfgDevice(AT91PS_MciDevice pmmcDev){	/* Init Device Structure*/	MCI_Device_Features.Relative_Card_Address 		= 0;	MCI_Device_Features.Card_Inserted 				= AT91C_CARD_REMOVED;	MCI_Device_Features.Max_Read_DataBlock_Length	= 0;	MCI_Device_Features.Max_Write_DataBlock_Length 	= 0;	MCI_Device_Features.Read_Partial 				= 0;	MCI_Device_Features.Write_Partial 				= 0;	MCI_Device_Features.Erase_Block_Enable 			= 0;	MCI_Device_Features.Sector_Size 				= 0;	MCI_Device_Features.Memory_Capacity 			= 0;		MCI_Device_Desc.state							= AT91C_MCI_IDLE;	MCI_Device_Desc.SDCard_bus_width				= AT91C_MCI_SCDBUS;		/* Init AT91S_DataFlash Global Structure, by default AT45DB choosen !!!*/	pmmcDev->pMCI_DeviceDesc 		= &MCI_Device_Desc;	pmmcDev->pMCI_DeviceFeatures 	= &MCI_Device_Features;}LOCAL STATUS mmcPinit    (AT91PS_MciDevice pmmcDev    )    {	/******************************/	/** For MMC Init*/	/******************************/		volatile int status;	int timeout = AT91C_MCI_TIMEOUT ; 	AT91F_CfgDevice(pmmcDev);		AT91F_MCI_Configure(AT91C_BASE_MCI,				AT91C_MCI_DTOR_1MEGA_CYCLES,				0x834A,						/* 400kHz for MCK = 60MHz*/				AT91C_MCI_MMC_SLOTA);		/** Wait MCI Device Ready*/	do	{		status = AT91C_BASE_MCI->MCI_SR;		timeout--;	}	while( !(status & AT91C_MCI_NOTBUSY)  && (timeout>0) );			if(AT91F_MCI_MMC_Init(pmmcDev) != AT91C_INIT_OK)		return FALSE;		/* Select MMC Card n

⌨️ 快捷键说明

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