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

📄 sdmmc.c

📁 intel xscale pxa270的完整wince4.2 BSP包
💻 C
📖 第 1 页 / 共 5 页
字号:
# if (USE_SPI || USE_SPI_EMULATION)

    pc->user_address = (USERADDRESS)mmcIdent;

        selectChip( RCA );

    resErr = mmcCommandAndResponse ( pc,
                0L,
                SEND_CID, 
                0,
                R1 );
    if ( resErr == MMC_NO_ERROR )
	{
                resErr = receive_data( pc, (CID_BYTE_LENGTH - 1), 1, NO );
//				RETAILMSG(1, (TEXT("mmcGetCardIdentification() NO_ERROR\r\n")));
	}

    /* De-select the card */
        deSelectChip ( RCA );

#else   /* This is for MMC */
    INT16   ij;

    resp_bytes = (UCHAR *)pc->LastResponse;

        /* Set the card to stanby state */
        resErr = mmcSetStandbyState( pc, RCA );
        resErr = mmcCommandAndResponse ( pc,
                                (((ULONG)RCA) << 16),
                SEND_CID,
                0,
                R2 );

    if ( resErr == MMC_NO_ERROR )
    {
//		RETAILMSG(1, (TEXT("mmcGetCardIdentification() NO_ERROR\r\n")));

        for (ij = 0; ij < (CID_BYTE_LENGTH-1); ij++)
        {
            mmcIdent[ij] = resp_bytes[ij+1];
        }
    }
#endif
        
    pc->error_code = (UINT16)resErr;
//	RETAILMSG(1, (TEXT("mmcGetCardIdentification---Error code is %d\r\n"), resErr));
    return resErr;
}



/*******************************************************************************
* Name: mmcGetConfiguration - Card CSD
* 
* Description:
*       Get the card configuration parameters (reads the card CSD reg.)
* 
* Input:
*       pc                      Device Controller structure
*       UINT16  RCA             Card address.
*       UCHAR   respCSD         Pointer to CSD information
*
* Output:
*       respCSD         Card configuration record.
*
* Returns:
*       Completion code 
* 
********************************************************************************/
MMC_CC mmcGetConfiguration( PDEVICE_CONTROLLER pc,
                        UCHAR *respCSD,
                        UINT16 RCA )
{
#if (USE_MMC || USE_MMC_EMULATION)
    UCHAR   *resp_bytes;
#endif
    MMC_CC  resErr;

#if (USE_SPI || USE_SPI_EMULATION)

    pc->user_address = (USERADDRESS)respCSD;
    /* Select the card */
        selectChip( RCA );
    resErr = mmcCommandAndResponse ( pc,
                0L,
                SEND_CSD, 
                0,
                R1 );
    if ( resErr == MMC_NO_ERROR )
                resErr = receive_data( pc, (CID_BYTE_LENGTH - 1), 1, NO );

    /* De-select the card */
        deSelectChip ( RCA );

#else   /* This is for MMC */
    UINT16  ij;

    resp_bytes = (UCHAR *)pc->LastResponse;

        /* Correct RCA when assigned the ID to the card */
        /* Set the card to standby state */
        resErr = mmcSetStandbyState( pc, RCA );
        resErr = mmcCommandAndResponse ( pc,
                                (((ULONG)RCA) << 16),
                SEND_CSD, 
                0,
                R2 );     

    if ( resErr == MMC_NO_ERROR )
    {
        /* Get all CSD data field */
        for (ij = 0; ij < (CID_BYTE_LENGTH - 1); ij++)
            respCSD[ij] = resp_bytes[ij+1];
    }
#endif

    pc->error_code = (UINT16)resErr;
//	RETAILMSG(1, (TEXT("SEND_CSD command with error return %d\r\n"), resErr));
    return resErr;
}

/*******************************************************************************
* Name: mmcSetTempWP - Set/Clear temporary write protected
*
* Description:
*       Sets/Clears the temporary WP bit of the card.
*
* Input:
*       pc              Device controller structure
*       RCA             card address
*       temp_wp         Set reset flag.
*
* Output:
*       The card is set to a desired mode.
*
* Returns:
*       Completion code
*
********************************************************************************/
MMC_CC mmcSetTempWP ( PDEVICE_CONTROLLER pc, UINT16 RCA, SDBOOL temp_WP )
{
    MMC_CC  resErr;
    UCHAR   resp_bytes[18];

#if (USE_SPI || USE_SPI_EMULATION)
    /* Select the card */
        selectChip( RCA );
    resErr = mmcCommandAndResponse ( pc,
                0L,
                SEND_CSD, 
                0,
                R1 );

    pc->user_address = (USERADDRESS)resp_bytes;
    if ( resErr == MMC_NO_ERROR )
                resErr = receive_data( pc, 16, 1, NO );

    /* DeSelect the card */
        deSelectChip( RCA );

#else   /* This is for MMC */

    UINT16  i;

        /* Set the card to standby state */
        resErr = mmcSetStandbyState( pc, RCA );
        resErr = mmcCommandAndResponse ( pc,
                                (((ULONG)RCA) << 16),
                SEND_CSD, 
                0,
                R2 );

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

        for (i = 0; i < (CID_BYTE_LENGTH - 1); i++)
        resp_bytes[i] = ((UCHAR *)pc->LastResponse)[i+1];
#endif

    /* Check for error */
    if ( resErr )
    {
        pc->error_code = (UINT16)resErr;
        return resErr;
    }

    if ( temp_WP )    
        /* Set temporary write protection bit to 1 */
        resp_bytes[14]= (UCHAR)(resp_bytes[14] | (UCHAR)TMPWPBIT_ON);
    else
        /* Clear temporary write protection */
        resp_bytes[14]= (UCHAR)(resp_bytes[14] & (UCHAR)TMPWPBIT_OFF);

#if (USE_SPI || USE_SPI_EMULATION)
        selectChip( RCA );
#else   /* This is for MMC */
        i = appendCmdCRC( resp_bytes, (CID_BYTE_LENGTH - 1) ); /* calculated new CRC */
    resp_bytes[15] = (UCHAR)i;

        resErr = mmcSetXferState( pc, RCA );
#endif

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

    pc->user_address = (USERADDRESS)resp_bytes;
    if ( resErr == MMC_NO_ERROR )
                resErr = send_data( pc, 16, 1, NO );


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

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

/*******************************************************************************
* Name: mmcGetWPMap
*
* Description:
*       Reads the card's group-write-protect map. It will return the
*       WP state of 32 groups starting ast the addressed group. A '1'
*       In the returned block means group is write protected.
*
* Input:
*       pc              Device controller structure
*       dataAddress     WP group address
*       RCA             card address
* 
* Output:
*       bufPtr                  read data
*
* Returns:
*       Completion code.
*
********************************************************************************/
MMC_CC mmcGetWPMap ( PDEVICE_CONTROLLER pc,
        ULONG dataAddress,
                UINT16 RCA )
{
    MMC_CC  resErr;

#if (USE_SPI || USE_SPI_EMULATION)
    /* Select the card */
    selectChip( RCA );
    resErr = MMC_NO_ERROR;
#else
    UINT16  saveBlkLen;

        resErr = mmcSetXferState( pc, RCA );
        saveBlkLen = pc->block_size;
        resErr = mmcCommandAndResponse ( pc,
                4L,
                SET_BLOCKLEN, 
                0,
                R1 );
#endif
    if ( resErr == MMC_NO_ERROR )
    {
        resErr = mmcCommandAndResponse ( pc,
                (dataAddress << 18),
                SEND_WRITE_PROT, 
                0,
                R1 );

        if ( resErr == MMC_NO_ERROR )
                        resErr = receive_data( pc, 4, 1, NO );
    }

#if (USE_MMC || USE_MMC_EMULATION)
    if ( resErr == MMC_NO_ERROR )
    {
                resErr = mmcSetXferState( pc, RCA );
                pc->block_size = saveBlkLen;
                resErr = mmcCommandAndResponse ( pc,
                (ULONG)saveBlkLen,
                SET_BLOCKLEN, 
                0,
                R1 );
    }
#endif

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

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

/*******************************************************************************
* Name: mmcSetGroupWP
*
* Description:
*       Sets the write protection bit of the addressed group
*
* Input:
*       dataAddress     Write protect group address
*       RCA             Card address.
*
* Output:
*       None.
*
* Returns:
*       Completion code
*
********************************************************************************/
MMC_CC mmcSetGroupWP ( PDEVICE_CONTROLLER pc,
            ULONG dataAddress,
                        UINT16 RCA )
{
    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 << 18),
                SET_WRITE_PROT, 
                0,
                R1 );

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

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

/*******************************************************************************
* Name: mmcClearGroupWP
*
* Description:
*       Clears the write protection bit of the addressed group
* 
*
* Input:
*       dataAddress     Write protect group address
*       RCA             Card address.
*
* Output:
*       None.
*
* Returns:
*       Completion code
*
************************************************************************************/
MMC_CC mmcClearGroupWP ( PDEVICE_CONTROLLER pc,
            ULONG dataAddress,
                        UINT16 RCA )
{
    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 << 18),
                CLR_WRITE_PROT, 
                0,
                R1 );

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

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

#if (USE_SD || USE_MMC || USE_MMC_EMULATION)
/*******************************************************************************
* Name: mmcBlkLengthConfiguration - Set the card block length
*
* Description:
*       Set the block length
* 
* Input:
*       pc                      Device structure information
*       RCA                     Card address.
*
* Output:
*       The card block length is set.
*
* Returns:
*       Completion code
*
************************************************************************************/
MMC_CC mmcBlkLengthConfiguration( PDEVICE_CONTROLLER pc, UINT16 RCA )
{
    MMC_CC  resErr;

#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,
                (ULONG)pc->block_size,
                SET_BLOCKLEN, 

⌨️ 快捷键说明

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