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

📄 sdmmc.c

📁 intel xscale pxa270的完整wince4.2 BSP包
💻 C
📖 第 1 页 / 共 5 页
字号:
                0,
                R1 );

#if (USE_SD)
 #if (USE_SPI || USE_SPI_EMULATION)
    /* DeSelect the card */
        deSelectChip( RCA );
 #endif
#endif
    pc->error_code = (UINT16)resErr;
//	RETAILMSG(1, (TEXT("mmcBlkLengthConfiguration -- error code %d\r\n"), resErr));
    return (resErr);
}
#endif /* (USE_SD || USE_MMC || USE_MMC_EMULATION) */


/***********************************************************************************
* Name: mmcRead - Reads one sector from card
*                                                                                                                                                                       |
* Description:
*       This function will (unless already selecetd) select
*       an mmc card using the given RCA (CMD7) set the block
*       length to 512 bytes (CMD16) and read one data
*       block using single block read (CMD17)
* 
* Input:
*       dataAddress -    Sector address
*       RCA         -    card address
*
* Output:
*       bufPtr      -    read data
*
* Returns:
*       Completion code
*
************************************************************************************/
MMC_CC mmcRead( PDEVICE_CONTROLLER pc,
        ULONG dataAddress,
                UINT16 RCA,
        UINT16 noBlocks )
{
    MMC_CC  resErr;

#if (USE_SPI || USE_SPI_EMULATION)
        selectChip( RCA );
#else   /* This is for MMC */

        /* Set the card to transfer state */
        resErr = mmcSetXferState( pc, RCA );
#endif

//		RETAILMSG(1, (TEXT(" mmcRead -- B4 Command&Resp stat is %x\r\n"),v_pMMCReg->stat));
    resErr = mmcCommandAndResponse ( pc,
                (dataAddress * (ULONG)pc->block_size), 
                READ_BLOCK, 
                noBlocks,
                R1 );
//	RETAILMSG(1, (TEXT(" mmcRead -- after mmcCommandAndResponse, resErr is %d\r\n"),resErr));
    if (resErr == MMC_NO_ERROR)
    {
                resErr = receive_data( pc, pc->block_size, 1, NO );
    }

#if (USE_SPI || USE_SPI_EMULATION)
    /* DeSelect the card */
        deSelectChip( RCA );
#endif

    pc->error_code = (UINT16)resErr;
    return resErr;
}



/***********************************************************************************
* Name: mmcWrite
*
* Description:
*       Writes one block of data to the device card sector
*
*       This function will (unless already selecetd) select an
*       mmc card using the given RCA (CMD7) set the block
*       length to 512 bytes (CMD16) and write one data
*       block using single block write (CMD24) 
* 
* Input:
*       dataAddress     -       Sector address
*       RCA             -       Card address.
* 
* Output:
*       None.
*                                                                                                     
* Returns:
*       Completion code
*
************************************************************************************/
MMC_CC mmcWrite ( PDEVICE_CONTROLLER pc,
        ULONG dataAddress,
                UINT16 RCA,
        UINT16 noBlocks )
{
    MMC_CC  resErr;

#if (USE_SPI || USE_SPI_EMULATION)
        selectChip( RCA );
#else   /* This is for MMC */

        /* Set the card to transfer state */
        resErr = mmcSetXferState( pc, RCA );
#endif

    resErr = mmcCommandAndResponse ( pc,
                (dataAddress * (ULONG)pc->block_size), 
                WRITE_BLOCK, 
                noBlocks,
                R1 );
    if ( resErr == MMC_NO_ERROR )
                resErr = send_data( pc, pc->block_size, 1, NO );

#if (USE_SPI || USE_SPI_EMULATION)
    /* DeSelect the card */
        deSelectChip( RCA );
#endif

    pc->error_code = (UINT16)resErr;
    return resErr;
}


#if (USE_SD)
#if (USE_MMC || USE_MMC_EMULATION)
/* Select the BUS WIDTH */
MMC_CC mmcSelectBusWidth( PDEVICE_CONTROLLER pc, UINT16 RCA, UINT16 option )
{
        UINT32 multipp;        

        multipp = (0x0F & ((UINT32)option));
        return(mmcSDApplCmd(pc, SDNULL, multipp, 0, RCA, R1, SET_BUS_WIDTH));
}
#endif  /* (USE_MMC || USE_MMC_EMULATION) */
#endif /* USE_SD */


#if (USE_MULTI)
#if (USE_SD || USE_MMC || USE_MMC_EMULATION)
/***********************************************************************************
* Name: mmcStopTransmission
*
* Description:
*       Stop Read multiple card sectors (CMD12)
*
* Input:
*
* Output:
*
* Returns:
*       Completion code
*
************************************************************************************/
MMC_CC mmcStopTransmission ( PDEVICE_CONTROLLER pc, UINT16 RCA)
{
    MMC_CC  resErr;

        RCA = RCA;
#if (USE_SD)
 #if (USE_SPI || USE_SPI_EMULATION)
    selectChip( RCA );
 #endif
#endif /* (USE_SD) */

    resErr = mmcCommandAndResponse ( pc, 
                0L,
                STOP_TRANSMISSION,
                0,
                R1 );

#if (USE_SD)
 #if (USE_SPI || USE_SPI_EMULATION)
        deSelectChip( RCA );
 #endif
#endif /* (USE_SD) */

        multipleRdWr = NO;      /* Clear it */

    return resErr;
}

/*******************************************************************************
* Name: mmcReadMultiple -  (SD and MMC card in MMC mode only)
*
* Description:
*       Initiate a multiple block read operation and start data transfer.
*
*       This function will (unless already selecetd) select an SD/MMC
*       card using the given RCA (CMD7) and starts the multiple read (CMD18).
*
* Input:
*       dataAddress -    Sector address
*       dataAddress -    Location of data
*       RCA         -    card address
*       noBlocks    -    Number of blocks to tansfer 
* Output:
*       bufPtr      -    read data
*
* Returns:
*       Completion code
*
********************************************************************************/
MMC_CC mmcReadMultiple( PDEVICE_CONTROLLER pc,
            ULONG dataAddress,
                        UINT16 RCA,
            UINT16 noBlocks )
{
    MMC_CC  resErr;
        UINT16  option;

#if (USE_MMC || USE_MMC_EMULATION)
        /* Set the card to transfer state */
        resErr = mmcSetXferState( pc, RCA );
#else
 #if (USE_SD)
  #if (USE_SPI || USE_SPI_EMULATION)
    selectChip( RCA );
  #endif
 #endif /* (USE_SD) */
#endif
        
    resErr = mmcCommandAndResponse ( pc,
                (dataAddress * (ULONG)pc->block_size),
                READ_MULTIPLE_BLOCK,
                noBlocks,
                R1 );

    if ( resErr != MMC_NO_ERROR )
    {                
#if (USE_SD)
 #if (USE_SPI || USE_SPI_EMULATION)
        /* DeSelect the card */
        deSelectChip( RCA );
 #endif
#endif /* USE_SD */
        pc->error_code = (UINT16)resErr;
        return resErr;
    }

    /* Get data */
        option = (YES | 0xFF00); /* set SD user area or MMC card flag */
        resErr = receive_data( pc, pc->block_size, noBlocks, option );

#if (USE_SD)
 #if (USE_SPI || USE_SPI_EMULATION)
    /* DeSelect the card */
    deSelectChip( RCA );
#endif
#endif /* USE_SD */

#if (USE_MMC || USE_MMC_EMULATION)
    /* Stop receiving data */
        mmcStopTransmission( pc, RCA );

    if ( resErr )
    {
        pc->error_code = (UINT16)resErr;
        return resErr;
    }

    /* Get device status */
    pc->mmcRdyState = NO;
    pc->tempData = 0xFF;
    while ( (pc->mmcRdyState != YES) && (pc->tempData > 0) )
    {
        /* Get the device status */
        resErr = mmcGetStatus( pc, RCA );                               
        if ( resErr )
            break;

        pc->tempData--;
    }
#else

 #if (USE_SD)
  #if (USE_SPI || USE_SPI_EMULATION)
    selectChip( RCA );

    /* Make sure the device is ready for next command */
        if ( !checkCardBusy(0xFF) )
                resErr = MMC_CARD_IS_BUSY;
    
    deSelectChip( RCA );
  #endif
 #endif

#endif /* (USE_MMC || USE_MMC_EMULATION) */

    pc->error_code = (UINT16)resErr;
    return resErr;
}


/***********************************************************************************
* Name: mmcWriteMultiple (MMC mode only) 
*
* Description:
*       Initiates a multiple block write operation.              
*
*       This function will (unless already selecetd) select
*       an mmc card using the given RCA (CMD7) set the block
*       length to a specified block length (CMD16) and
*       starts the multiple write (CMD15).
*
* Input:
*       dataAddress     -       Sector address
*       bufPtr          -       Data to be written.
*       RCA             -       card address
*                                                                                                                                                                       |
*                                                                                                                                                                       |
* Returns:
*       Completion code                                 
*
************************************************************************************/
MMC_CC mmcWriteMultiple( PDEVICE_CONTROLLER pc,
            ULONG dataAddress,
                        UINT16 RCA,
            UINT16 noBlocks )
{
    MMC_CC  resErr;
        UINT16  option;

#if (USE_MMC || USE_MMC_EMULATION)
        /* Set the card to transfer state */
        resErr = mmcSetXferState( pc, RCA );
#else
 #if (USE_SD)
  #if (USE_SPI || USE_SPI_EMULATION)
    selectChip( RCA );
  #endif
 #endif
#endif
        
    resErr = mmcCommandAndResponse ( pc,
                (dataAddress * (ULONG)pc->block_size),
                WRITE_MULTIPLE_BLOCK,
                noBlocks,
                R1 );
    if ( resErr != MMC_NO_ERROR )
    {                
#if (USE_SD)
 #if (USE_SPI || USE_SPI_EMULATION)
        /* DeSelect the card */
        deSelectChip( RCA );
 #endif
#endif
        pc->error_code = (UINT16)resErr;
        return resErr;
    }

        /* Send data */
        option = (YES | 0xFF00); /* set SD user area or MMC card flag */
        resErr = send_data( pc, pc->block_size, noBlocks, option );

#if (USE_SD)
 #if (USE_SPI || USE_SPI_EMULATION)
    /* DeSelect the card */
    deSelectChip( RCA );
 #endif
#endif

#if (USE_MMC || USE_MMC_EMULATION)
    /* Stop sending data */
        mmcStopTransmission( pc, RCA );               

    if ( resErr )
    {
        pc->error_code = (UINT16)resErr;
        return resErr;
    }

    /* Get device status and check for READY state */
    pc->tempData = 0xFF;
    pc->mmcRdyState = NO;
    while ( (pc->mmcRdyState != YES) && (pc->tempData > 0) )
    {
        /* Get the device status */
        resErr = mmcGetStatus( pc, RCA );

        if ( resErr )
            break;

        pc->tempData--;

        OS_WAIT(1);
    }
#else

 #if (USE_SD)
  #if (USE_SPI || USE_SPI_EMULATION)
    selectChip( RCA );

    /* Make sure the device is ready for next command */
        if ( !checkCardBusy(0xFF) )
                resErr = MMC_CARD_IS_BUSY;
    
    deSelectChip( RCA );
  #endif
 #endif

#endif /* (USE_MMC || USE_MMC_EMULATION) */

        pc->error_code = (UINT16)resErr;
    return resErr;

}

#endif /* (USE_SD || USE_MMC || USE_MMC_EMULATION) */

#endif  /* (USE_MULTI) */


/************************************************************************************
* Name: mmcEraseSectors
*
* Description:
*       Erases a sector range on the card. The rane must be within
*       a single erase group.
*
* Input:
*       PDEVICE_CONTROLLER      pc
*       UINT16  RCA     Card address. 

⌨️ 快捷键说明

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