Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * \brief Initialize and config the SD Card
- *
- * \param none
- *
- * \return Init Result
- */
- Int16 sdInit()
- {
- Uint16 actCard;
- Uint32 sectCount;
- Uint16 rca;
- sectCount = 0;
- /* Initialize the CSL MMCSD module */
- mmcStatus = MMC_init();
- if(mmcStatus != CSL_SOK)
- {
- printf(" MMC_init Failed\n");
- return(mmcStatus);
- }
- /* Open the MMCSD module in POLLED mode */
- // mmcsdHandle = MMC_open(&pMmcsdContObj, CSL_MMCSD1_INST, CSL_MMCSD_OPMODE_POLLED, &mmcStatus);
- mmcsdHandle = MMC_open(&pMmcsdContObj, CSL_MMCSD0_INST, CSL_MMCSD_OPMODE_POLLED, &mmcStatus);
- if(mmcStatus != CSL_SOK)
- {
- printf(" MMC_open Failed\n");
- return(mmcStatus);
- }
- else
- {
- printf(" MMC_open Successful\n");
- }
- /* Send CMD0 to the card */
- mmcStatus = MMC_sendGoIdle(mmcsdHandle);
- if(mmcStatus != CSL_SOK)
- {
- printf(" 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(" MMC_selectCard Failed\n");
- return(mmcStatus);
- }
- /* 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\n");
- /* For the SDHC card Block addressing will be used.
- Sector address will be same as sector number */
- cardAddr = sectCount;
- }
- else
- {
- printf(" SD card is Standard Capacity Card\n");
- printf(" Memory Access will use Byte Addressing\n\n");
- /* For the SD card Byte addressing will be used.
- Sector address will be product of sector number
- and sector size */
- cardAddr = (sectCount)*(CSL_MMCSD_BLOCK_LENGTH);
- }
- }
- else
- {
- /* Check if No card is inserted */
- if(mmcCardObj.cardType == CSL_CARD_NONE)
- {
- printf("No Card Detected!\n");
- }
- else
- {
- printf("SD card is not Detected!\n");
- }
- printf("Please Insert SD card!!\n");
- return(CSL_ESYS_FAIL);
- }
- /* Set the init clock */
- mmcStatus = MMC_sendOpCond(mmcsdHandle, 70);
- if(mmcStatus != CSL_SOK)
- {
- printf(" MMC_sendOpCond Failed\n");
- return(mmcStatus);
- }
- /* Send the card identification Data */
- mmcStatus = SD_sendAllCID(mmcsdHandle, &sdCardIdObj);
- if(mmcStatus != CSL_SOK)
- {
- printf(" SD_sendAllCID Failed\n");
- return(mmcStatus);
- }
- /* Set the Relative Card Address */
- mmcStatus = SD_sendRca(mmcsdHandle, &mmcCardObj, &rca);
- if(mmcStatus != CSL_SOK)
- {
- printf(" SD_sendRca Failed\n");
- return(mmcStatus);
- }
- /* Read the SD Card Specific Data */
- mmcStatus = SD_getCardCsd(mmcsdHandle, &sdCardCsdObj);
- if(mmcStatus != CSL_SOK)
- {
- printf(" SD_getCardCsd Failed\n");
- return(mmcStatus);
- }
- /* Set bus width - Optional */
- mmcStatus = SD_setBusWidth(mmcsdHandle, 1);
- if(mmcStatus != CSL_SOK)
- {
- printf(" SD_setBusWidth Failed\n");
- return(mmcStatus);
- }
- /* Disable SD card pull-up resistors - Optional */
- mmcStatus = SD_configurePullup(mmcsdHandle, 0);
- if(mmcStatus != CSL_SOK)
- {
- printf(" SD_configurePullup Failed\n");
- return(mmcStatus);
- }
- /* Set the card type in internal data structures */
- mmcStatus = MMC_setCardType(&mmcCardObj, mmcCardObj.cardType);
- if(mmcStatus != CSL_SOK)
- {
- printf(" MMC_setCardType Failed\n");
- return(mmcStatus);
- }
- /* Set the card pointer in internal data structures */
- mmcStatus = MMC_setCardPtr(mmcsdHandle, &mmcCardObj);
- if(mmcStatus != CSL_SOK)
- {
- printf(" MMC_setCardPtr Failed\n");
- return(mmcStatus);
- }
- /* Get the number of cards */
- mmcStatus = MMC_getNumberOfCards(mmcsdHandle, &actCard);
- if(mmcStatus != CSL_SOK)
- {
- printf(" MMC_getNumberOfCards Failed\n");
- return(mmcStatus);
- }
- /* Set clock for read-write access */
- mmcStatus = MMC_sendOpCond(mmcsdHandle, 2);
- if(mmcStatus != CSL_SOK)
- {
- printf(" MMC_sendOpCond Failed\n");
- return(mmcStatus);
- }
- /* Set Endian mode for read and write operations */
- mmcStatus = MMC_setEndianMode(mmcsdHandle, CSL_MMCSD_ENDIAN_LITTLE,
- CSL_MMCSD_ENDIAN_LITTLE);
- if(mmcStatus != CSL_SOK)
- {
- printf(" 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(" MMC_setBlockLength Failed\n");
- return(mmcStatus);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement