示例#1
0
CSL_Status configSdCard(CSL_MMCSDOpMode opMode) {
    CSL_Status status;
    Uint16 actCard;
    Uint16 clockDiv;
    Uint16 rca;

    /* Get the clock divider value for the current CPU frequency */
    clockDiv = computeClkRate();

    /* Initialize MMCSD CSL module */
    status = MMC_init();

    status = SYS_setEBSR(CSL_EBSR_FIELD_SP0MODE, CSL_EBSR_SP0MODE_0);
    status |= SYS_setEBSR(CSL_EBSR_FIELD_SP1MODE, CSL_EBSR_SP1MODE_0);
    if (CSL_SOK != status) {
        printf("SYS_setEBSR failed\n");
        return (status);
    }

    /* Open MMCSD CSL module */
#ifdef C5515_EZDSP
    mmcsdHandle = MMC_open(&pMmcsdContObj, CSL_MMCSD1_INST,
                           opMode, &status);
#else
    mmcsdHandle = MMC_open(&pMmcsdContObj, CSL_MMCSD1_INST, opMode, &status);
#endif
    if (mmcsdHandle == NULL) {
        printf("MMC_open Failed\n");
        return (status);
    }

    /* Configure the DMA in case of operating mode is set to DMA */
    if (opMode == CSL_MMCSD_OPMODE_DMA) {
        /* Initialize Dma */
        status = DMA_init();
        if (status != CSL_SOK) {
            printf("DMA_init Failed!\n");
            return (status);
        }

        /* Open Dma channel for MMCSD write */
        dmaWrHandle = DMA_open(CSL_DMA_CHAN0, &dmaWrChanObj, &status);
        if ((dmaWrHandle == NULL) || (status != CSL_SOK)) {
            printf("DMA_open for MMCSD Write Failed!\n");
            return (status);
        }

        /* Open Dma channel for MMCSD read */
        dmaRdHandle = DMA_open(CSL_DMA_CHAN1, &dmaRdChanObj, &status);
        if ((dmaRdHandle == NULL) || (status != CSL_SOK)) {
            printf("DMA_open for MMCSD Read Failed!\n");
            return (status);
        }

        /* Set the DMA handle for MMC read */
        status = MMC_setDmaHandle(mmcsdHandle, dmaWrHandle, dmaRdHandle);
        if (status != CSL_SOK) {
            printf("API: MMC_setDmaHandle for MMCSD Failed\n");
            return (status);
        }
    }

    /* Reset the SD card */
    status = MMC_sendGoIdle(mmcsdHandle);
    if (status != CSL_SOK) {
        printf("MMC_sendGoIdle Failed\n");
        return (status);
    }

    /* Check for the card */
    status = MMC_selectCard(mmcsdHandle, &mmcCardObj);
    if ((status == CSL_ESYS_BADHANDLE) || (status == CSL_ESYS_INVPARAMS)) {
        printf("MMC_selectCard Failed\n");
        return (status);
    }

    /* Verify whether the SD card is detected or not */
    if (mmcCardObj.cardType == CSL_SD_CARD) {
        printf("SD Card detected\n");

        /* Check if the card is high capacity card */
        if (mmcsdHandle->cardObj->sdHcDetected == TRUE) {
            printf("SD card is High Capacity Card\n");
            printf("Memory Access will use Block Addressing\n");
        } else {
            printf("SD card is Standard Capacity Card\n");
            printf("Memory Access will use Byte Addressing\n");
        }
    } else {
        if (mmcCardObj.cardType == CSL_CARD_NONE) {
            printf("No Card detected\n");
        } else {
            printf("SD Card not detected\n");
        }
        printf("Please Insert SD Card\n");
        return (CSL_ESYS_FAIL);
    }

    /* Set the init clock */
    status = MMC_sendOpCond(mmcsdHandle, 70);
    if (status != CSL_SOK) {
        printf("MMC_sendOpCond Failed\n");
        return (status);
    }

    /* Send the card identification Data */
    status = SD_sendAllCID(mmcsdHandle, &sdCardIdObj);
    if (status != CSL_SOK) {
        printf("SD_sendAllCID Failed\n");
        return (status);
    }

    /* Set the Relative Card Address */
    status = SD_sendRca(mmcsdHandle, &mmcCardObj, &rca);
    if (status != CSL_SOK) {
        printf("SD_sendRca Failed\n");
        return (status);
    }

    /* Read the SD Card Specific Data */
    status = SD_getCardCsd(mmcsdHandle, &sdCardCsdObj);
    if (status != CSL_SOK) {
        printf("SD_getCardCsd Failed\n");
        return (status);
    }

    /* Set the card type in internal data structures */
    status = MMC_setCardType(&mmcCardObj, CSL_SD_CARD);
    if (status != CSL_SOK) {
        printf("MMC_setCardType Failed\n");
        return (status);
    }

    /* Set the card pointer in internal data structures */
    status = MMC_setCardPtr(mmcsdHandle, &mmcCardObj);
    if (status != CSL_SOK) {
        printf("MMC_setCardPtr Failed\n");
        return (status);
    }

    /* Get the number of cards */
    status = MMC_getNumberOfCards(mmcsdHandle, &actCard);
    if (status != CSL_SOK) {
        printf("MMC_getNumberOfCards Failed\n");
        return (status);
    }

    /* Set clock for read-write access */
    status = MMC_sendOpCond(mmcsdHandle, clockDiv);
    if (status != CSL_SOK) {
        printf("MMC_sendOpCond Failed\n");
        return (status);
    }

    /* Set Endian mode for read and write operations */
    status = MMC_setEndianMode(mmcsdHandle, CSL_MMCSD_ENDIAN_LITTLE,
                               CSL_MMCSD_ENDIAN_LITTLE);
    if (status != CSL_SOK) {
        printf("MMC_setEndianMode Failed\n");
        return (status);
    }

    /* Set block length for the memory card
     * For high capacity cards setting the block length will have
     * no effect
     */
    status = MMC_setBlockLength(mmcsdHandle, CSL_MMCSD_BLOCK_LENGTH);
    if (status != CSL_SOK) {
        printf("MMC_setBlockLength Failed\n");
        return (status);
    }

    return (status);
}
/**
 *  \brief  Tests MMC card operation in POLLED mode
 *
 *   This function configures the MMCSD module in POLLED mode and
 *   verifies the operation with MMC Card. Function returns failure
 *   incase of no MMC card is detected.
 *
 *  \param  none
 *
 *  \return Test result
 */
CSL_Status CSL_mmcPollTest(void)
{
	CSL_Status	    mmcStatus;
	Uint16          looper;
	Uint16		    actCard;
	Uint16          clockDiv;

    callBckFun.isr[CSL_MMCSD_ISR_TXMT] = isr_txmt;
    callBckFun.isr[CSL_MMCSD_ISR_RCV]  = isr_rcv;

	/* Initialize data buffers */
	for(looper = 0; looper < (BUFFER_MAX_SIZE/2); looper++)
	{
	    gMmcReadBuff[looper]   = 0;
		gMmcWriteBuff[looper] = looper;
	}

	/* Get the clock divider value for the current CPU frequency */
	clockDiv = computeClkRate();

	/* Initialize the CSL MMCSD module */
	mmcStatus = MMC_init();
	if(mmcStatus != CSL_SOK)
	{
		printf("API: MMC_init Failed\n");
		return(mmcStatus);
	}

    /* Initialize the config parameter */
	mmcConfig.mmcblen = CSL_MMCSD_BLOCK_LENGTH;
	mmcConfig.mmcclk  = 0x10 |CSL_MMCSD_MMCCLK_CLKEN_ENABLE;
	mmcConfig.mmcctl  = CSL_MMCSD_MMCCTL_DATEG_F_EDGE;
	mmcConfig.mmcim   = 0x0;
	mmcConfig.mmcnblk = 0x1;
	mmcConfig.mmctod  = CSL_MMCSD_DATA_RW_TIMEOUT;
	mmcConfig.mmctor  = CSL_MMCSD_RESPONSE_TIMEOUT;

    /* assign the value to setup native structure */
	setupNative.blockLen		  = CSL_MMCSD_BLOCK_LENGTH;
	setupNative.cdiv			  = 0x10;
	setupNative.dat3EdgeDetection = CSL_MMCSD_MMCCTL_DATEG_F_EDGE;
	setupNative.dataTimeout 	  = CSL_MMCSD_DATA_RW_TIMEOUT;
	setupNative.dmaEnable		  = 0x1;
	setupNative.enableClkPin	  = 0x1;
	setupNative.rspTimeout		  = CSL_MMCSD_RESPONSE_TIMEOUT;

	/* Open the MMCSD module in POLLED mode */
#ifdef C5515_EZDSP
	mmcsdHandle = MMC_open(&pMmcsdContObj, CSL_MMCSD1_INST,
	                       CSL_MMCSD_OPMODE_POLLED, &mmcStatus);
#else
	mmcsdHandle = MMC_open(&pMmcsdContObj, CSL_MMCSD0_INST,
	                       CSL_MMCSD_OPMODE_POLLED, &mmcStatus);
#endif
	if(mmcStatus != CSL_SOK)
	{
		printf("API: MMC_open Failed\n");
		return(mmcStatus);
	}
	else
	{
		printf("API: MMC_open Successful\n");
	}

	/* Send CMD0 to the card */
	mmcStatus = MMC_sendGoIdle(mmcsdHandle);
	if(mmcStatus != CSL_SOK)
	{
		printf("API: MMC_sendGoIdle Failed\n");
		return(mmcStatus);
	}

	/* Check for the card */
    mmcStatus = MMC_selectCard(mmcsdHandle, &mmcCardObj);
	if((mmcStatus == CSL_ESYS_BADHANDLE) ||
	   (mmcStatus == CSL_ESYS_INVPARAMS))
	{
		printf("API: MMC_selectCard Failed\n");
		return(mmcStatus);
	}

	/* Verify whether the MMC card is detected or not */
	if(mmcCardObj.cardType == CSL_MMC_CARD)
	{
		printf("MMC Card Detected!\n\n");
	}
	else
	{
		/* Check if No card is inserted */
		if(mmcCardObj.cardType == CSL_CARD_NONE)
		{
			printf("No Card Detected!\n");
		}
		else
		{
			printf("MMC Card not Detected!\n");
		}

		printf("Please Insert MMC Card!!\n");
		return(CSL_ESYS_FAIL);
	}

 	/* Send the card identification Data */
	mmcStatus = MMC_sendAllCID(mmcsdHandle, &mmcCardIdObj);
	if(mmcStatus != CSL_SOK)
	{
		printf("API: MMC_sendAllCID Failed\n");
		return(mmcStatus);
	}

	/* Set the Relative Card Address */
	mmcStatus = MMC_setRca(mmcsdHandle, &mmcCardObj, 0x0001);
	if(mmcStatus != CSL_SOK)
	{
		printf("API: MMC_setRca Failed\n");
		return(CSL_ESYS_FAIL);
	}

	/* Read the MMC Card Specific Data */
	mmcStatus = MMC_getCardCsd(mmcsdHandle, &mmcCardCsdObj);
	if(mmcStatus != CSL_SOK)
	{
		printf("API: MMC_getCardCsd Failed\n");
		return(mmcStatus);
	}

	/* Set the card type in internal data structures */
	mmcStatus = MMC_setCardType(&mmcCardObj, CSL_MMC_CARD);
	if(mmcStatus != CSL_SOK)
	{
		printf("API: MMC_setCardType Failed\n");
		return(mmcStatus);
	}

	/* Set the card pointer in internal data structures */
	mmcStatus = MMC_setCardPtr(mmcsdHandle, &mmcCardObj);
	if(mmcStatus != CSL_SOK)
	{
		printf("API: MMC_setCardPtr Failed\n");
		return(mmcStatus);
	}

	/* Get the number of cards */
	mmcStatus = MMC_getNumberOfCards(mmcsdHandle, &actCard);
	if(mmcStatus != CSL_SOK)
	{
		printf("API: MMC_getNumberOfCards Failed\n");
		return(mmcStatus);
	}

	/* Set the MMC operating clock */
    mmcStatus = MMC_sendOpCond(mmcsdHandle, clockDiv);
	if(mmcStatus != CSL_SOK)
	{
	   printf("API: MMC_sendOpCond Failed\n");
	   return(mmcStatus);
	}

	/* Set the endian mode */
	mmcStatus = MMC_setEndianMode(mmcsdHandle, CSL_MMCSD_ENDIAN_LITTLE,
	                              CSL_MMCSD_ENDIAN_LITTLE);
	if(mmcStatus != CSL_SOK)
	{
		printf("API: MMC_setEndianMode Failed\n");
		return(mmcStatus);
	}

	/* Set block length for the memory card
	 * For high capacity cards setting the block length will have
	 * no effect
	 */
	mmcStatus = MMC_setBlockLength(mmcsdHandle, CSL_MMCSD_BLOCK_LENGTH);
	if(mmcStatus != CSL_SOK)
	{
		printf("API: MMC_setBlockLength Failed\n");
		return(mmcStatus);
	}

	/* Write data to the MMC card */
	mmcStatus = MMC_write(mmcsdHandle, CARD_START_ADDR, BUFFER_MAX_SIZE,
	                      gMmcWriteBuff);
	if(mmcStatus != CSL_SOK)
	{
		printf("API: MMC_write Failed\n");
		return(mmcStatus);
	}
	else
	{
		printf("API: MMC_write Successful\n");
	}

	/* Read data from the MMC card */
	mmcStatus = MMC_read(mmcsdHandle, CARD_START_ADDR, BUFFER_MAX_SIZE,
	                     gMmcReadBuff);
	if(mmcStatus != CSL_SOK)
	{
		printf("API: MMC_read Failed\n");
		return(mmcStatus);
	}
	else
	{
		printf("API: MMC_read Successful\n");
	}

	/* Deselect the MMC card */
	mmcStatus = MMC_deselectCard(mmcsdHandle, &mmcCardObj);
	if(mmcStatus != CSL_SOK)
	{
		printf("API: MMC_deselectCard Failed\n");
		return(mmcStatus);
	}

	/* Following APIs have nothing to do with the test sequence
	   They are called to verify their basic functionality */

	/* Save the MMC status */
	mmcStatus = MMC_saveStatus(mmcsdHandle);
	if(mmcStatus != CSL_SOK)
	{
		printf("API: MMC_saveStatus Failed\n");
		return(mmcStatus);
	}

	/* Read the MMC status */
	MMC_getStatus(mmcsdHandle, 0xFFFF, &mmcStatus);
	if(mmcStatus != CSL_SOK)
	{
		printf("API: MMC_getStatus Failed\n");
		return(mmcStatus);
	}

	/* Configure the MMC module */
	mmcStatus = MMC_config(mmcsdHandle, &mmcConfig);
	if(mmcStatus != CSL_SOK)
	{
		printf("API: MMC_config Failed\n");
		return(mmcStatus);
	}

	/* Read the configurations from the MMC module */
	mmcStatus = MMC_getConfig(mmcsdHandle, &mmcConfig);
	if(mmcStatus != CSL_SOK)
	{
		printf("API: MMC_getConfig Failed\n");
		return(mmcStatus);
	}

	/* Setup the MMCSD native structure */
	mmcStatus = MMC_setupNative(mmcsdHandle, &setupNative);
	if(mmcStatus != CSL_SOK)
	{
		printf("API: MMC_setupNative Failed\n");
		return(mmcStatus);
	}

	/* Read the Receive Data Ready Status bit */
	MMC_drrdy(mmcsdHandle, &mmcStatus);
	if(mmcStatus != CSL_SOK)
	{
		printf("API: MMC_drrdy Failed\n");
		return(mmcStatus);
	}

	/* Read the Transmit Data Ready Status bit */
	MMC_dxrdy(mmcsdHandle, &mmcStatus);
	if(mmcStatus != CSL_SOK)
	{
		printf("API: MMC_dxrdy Failed\n");
		return(mmcStatus);
	}

	/* Set the MMCSD Callback functions */
	mmcStatus = MMC_setCallBack(mmcsdHandle, &callBckFun);
	if(mmcStatus != CSL_SOK)
	{
		printf("API: MMC_setCallBack Failed\n");
		return(mmcStatus);
	}

	/* Clear the MMCSD card response registers */
	mmcStatus = MMC_clearResponse(mmcsdHandle);
	if(mmcStatus != CSL_SOK)
	{
		printf("API: MMC_clearResponse Failed\n");
		return(mmcStatus);
	}

	/* Configure the MMCSD Interrupts  */
	mmcStatus = MMC_intEnable(mmcsdHandle, 0x0000);
	if(mmcStatus != CSL_SOK)
	{
		printf("API: MMC_intEnable Failed\n");
		return(mmcStatus);
	}

	/* Enable the Data transfer done Interrupt */
	mmcStatus = MMC_eventEnable(mmcsdHandle, CSL_MMCSD_EDATDNE_INTERRUPT);
	if(mmcStatus != CSL_SOK)
	{
		printf("API: MMC_eventEnable Failed\n");
		return(mmcStatus);
	}

	/* Disable the Data transfer done Interrupt */
	mmcStatus = MMC_eventDisable(mmcsdHandle, CSL_MMCSD_EDATDNE_INTERRUPT);
	if(mmcStatus != CSL_SOK)
	{
		printf("API: MMC_eventDisable Failed\n");
		return(mmcStatus);
	}

	/* Close the MMCSD module */
	mmcStatus = MMC_close(mmcsdHandle);
	if(mmcStatus != CSL_SOK)
	{
		printf("API: MMC_close Failed\n");
		return(mmcStatus);
	}
	else
	{
		printf("API: MMC_close Successful\n");
	}

	/* Compare the MMC read and write buffers */
	for(looper = 0; looper < (BUFFER_MAX_SIZE/2); ++looper)
	{
		if(gMmcReadBuff[looper] != gMmcWriteBuff[looper])
		{
			printf("\nBuffer Miss Matched at Position %d\n",looper);
			return(CSL_ESYS_FAIL);
		}
	}

	printf("\nMMC Card Read & Write Buffer Matched\n");

	return(CSL_SOK);
}
示例#3
0
/*
 *  EZDSP5535_SDCARD_init( )
 *
 *      Initalize SD card interface
 */
Int16 EZDSP5535_SDCARD_init()
{
	Uint16		 actCard;
	Uint16       rca;

	/* Initialize the CSL MMCSD module */
//	mmcStatus = MMC_init();		// never failed

	/* Open the MMCSD module in POLLED mode */
	mmcsdHandle = MMC_open(&pMmcsdContObj, CSL_MMCSD0_INST,
			CSL_MMCSD_OPMODE_POLLED, &mmcStatus);
	if(mmcStatus != CSL_SOK)		// open failed
	{
		return(mmcStatus);
	}

	/* Send CMD0 to the card */
	mmcStatus = MMC_sendGoIdle(mmcsdHandle);
	if(mmcStatus != CSL_SOK)		// idle failed
	{
		return(mmcStatus);
	}

	/* Check for the card */
    mmcStatus = MMC_selectCard(mmcsdHandle, &mmcCardObj);
	if((mmcStatus == CSL_ESYS_BADHANDLE) ||
	   (mmcStatus == CSL_ESYS_INVPARAMS))		// select failed
	{
		return(mmcStatus);
	}

	/* Set the init clock */
    mmcStatus = MMC_sendOpCond(mmcsdHandle, 70);
	if(mmcStatus != CSL_SOK)	// send op cond failed
	{
		return(mmcStatus);
	}

	/* Send the card identification Data */
	mmcStatus = SD_sendAllCID(mmcsdHandle, &sdCardIdObj);
	if(mmcStatus != CSL_SOK)	// send all CID failed
	{
		return(mmcStatus);
	}

	/* Set the Relative Card Address */
	mmcStatus = SD_sendRca(mmcsdHandle, &mmcCardObj, &rca);
	if(mmcStatus != CSL_SOK)
	{
		return(mmcStatus);
	}

	/* Read the SD Card Specific Data */
	mmcStatus = SD_getCardCsd(mmcsdHandle, &sdCardCsdObj);
	if(mmcStatus != CSL_SOK)
	{
		return(mmcStatus);
	}

	/* Set bus width - Optional */
	mmcStatus = SD_setBusWidth(mmcsdHandle, 1);
	if(mmcStatus != CSL_SOK)
	{
		return(mmcStatus);
	}

	/* Disable SD card pull-up resistors - Optional */
	mmcStatus = SD_configurePullup(mmcsdHandle, 0);
	if(mmcStatus != CSL_SOK)
	{
		return(mmcStatus);
	}

	/* Set the card type in internal data structures */
	mmcStatus = MMC_setCardType(&mmcCardObj, mmcCardObj.cardType);
	if(mmcStatus != CSL_SOK)
	{
		return(mmcStatus);
	}

	/* Set the card pointer in internal data structures */
	mmcStatus = MMC_setCardPtr(mmcsdHandle, &mmcCardObj);
	if(mmcStatus != CSL_SOK)
	{
		return(mmcStatus);
	}

	/* Get the number of cards */
	mmcStatus = MMC_getNumberOfCards(mmcsdHandle, &actCard);
	if(mmcStatus != CSL_SOK)
	{
		return(mmcStatus);
	}

	/* Set clock for read-write access */
    mmcStatus = MMC_sendOpCond(mmcsdHandle, 2);
	if(mmcStatus != CSL_SOK)
	{
		return(mmcStatus);
	}

	/* Set block length for the memory card
	 * For high capacity cards setting the block length will have
	 * no effect
	 */
	mmcStatus = MMC_setBlockLength(mmcsdHandle, CSL_MMCSD_BLOCK_LENGTH);
	if(mmcStatus != CSL_SOK)
		return(mmcStatus);
	
	return 0;
}