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); }
/* * 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; }