Changeset ae6395f in umon


Ignore:
Timestamp:
Aug 4, 2015, 6:03:26 PM (4 years ago)
Author:
Jarielle Catbagan <jcatbagan93@…>
Branches:
master
Children:
0511e58
Parents:
d8325a1
git-author:
Jarielle Catbagan <jcatbagan93@…> (08/04/15 18:03:26)
git-committer:
Ed Sutter <edsutterjr@…> (08/04/15 22:45:34)
Message:

BBB: am335x_mmc.c: Integrate reading and writing functionality in "mmc" command

File:
1 edited

Legend:

Unmodified
Added
Removed
  • ports/beagleboneblack/am335x_mmc.c

    rd8325a1 rae6395f  
    332332mmcRead(int interface, char *buf, int blknum, int blkcnt)
    333333{
    334         return(-1);
     334        uint32_t cmd, arg, resp[4];
     335        uint32_t *wordptr = (uint32_t *) buf;
     336        int byteindex;
     337
     338        /* Get the SD card's status via CMD13 */
     339        arg = (mmcrca << 16) & 0xFFFF0000;
     340        cmd = SD_CMD_CMD13_SEND_STATUS | SD_CMD_CMD_TYPE_NORMAL | SD_CMD_DP_NO_DATA_PRESENT |
     341                SD_CMD_CICE_ENABLE | SD_CMD_CCCE_ENABLE | SD_CMD_RSP_TYPE_R1;
     342        if (mmccmd(cmd, arg, resp) == -1)
     343                return(-1);
     344
     345        /* Ensure that the card is in Transfer State before proceeding */
     346        if ((resp[0] & SD_RSP10_R1_CURRENT_STATE) != SD_RSP10_R1_CURRENT_STATE_TRANSFER) {
     347                arg = (mmcrca << 16) & 0xFFFF0000;
     348                cmd = SD_CMD_CMD7_SELECT_DESELECT_CARD | SD_CMD_CMD_TYPE_NORMAL |
     349                        SD_CMD_DP_NO_DATA_PRESENT | SD_CMD_CICE_ENABLE | SD_CMD_CCCE_ENABLE |
     350                        SD_CMD_RSP_TYPE_R1B;
     351                if (mmccmd(cmd, arg, resp) == -1)
     352                        return(-1);
     353
     354                /* Wait for the SD card to enter Transfer State */
     355                do {
     356                        arg = (mmcrca << 16) & 0xFFFF0000;
     357                        cmd = SD_CMD_CMD13_SEND_STATUS | SD_CMD_CMD_TYPE_NORMAL |
     358                                SD_CMD_DP_NO_DATA_PRESENT | SD_CMD_CICE_ENABLE | SD_CMD_CCCE_ENABLE |
     359                                SD_CMD_RSP_TYPE_R1;
     360                        if (mmccmd(cmd, arg, resp) == -1)
     361                                return(-1);
     362                } while ((resp[0] & SD_RSP10_R1_CURRENT_STATE) != SD_RSP10_R1_CURRENT_STATE_TRANSFER);
     363        }
     364
     365        /* Set the block length and the number of blocks to read */
     366        MMC1_REG(SD_BLK) = 0x200 | (blkcnt << 16);
     367        /* Read multiple blocks via CMD18 */
     368        arg = blknum;
     369        cmd = SD_CMD_CMD18_READ_MULTIPLE_BLOCK | SD_CMD_CMD_TYPE_NORMAL | SD_CMD_DP_DATA_PRESENT |
     370                SD_CMD_CICE_ENABLE | SD_CMD_CCCE_ENABLE | SD_CMD_RSP_TYPE_R1 | SD_CMD_MSBS_MULTIPLE |
     371                SD_CMD_DDIR_READ | SD_CMD_ACEN_CMD12_ENABLE | SD_CMD_BCE_ENABLE;
     372        if (mmccmd(cmd, arg, resp) == -1)
     373                return(-1);
     374
     375        /* Check the data buffer to see if there is data to be read */
     376        do {
     377                while (!(MMC1_REG(SD_STAT) & SD_STAT_BRR));
     378
     379                /* Clear the BRR status bit in SD_STAT */
     380                MMC1_REG(SD_STAT) |= SD_STAT_BRR;
     381
     382                for (byteindex = 0; byteindex < (0x200 / 4); byteindex++) {
     383                        *wordptr = MMC1_REG(SD_DATA);
     384                        wordptr++;
     385                }
     386        } while (!(MMC1_REG(SD_STAT) & SD_STAT_TC));
     387
     388        /* Put the eMMC into Stand-by State */
     389        arg = 0;
     390        cmd = SD_CMD_CMD7_SELECT_DESELECT_CARD | SD_CMD_CMD_TYPE_NORMAL | SD_CMD_DP_NO_DATA_PRESENT |
     391                SD_CMD_CICE_DISABLE | SD_CMD_CCCE_DISABLE | SD_CMD_RSP_TYPE_NO_RESPONSE;
     392        if (mmccmd(cmd, arg, resp) == -1)
     393                return(-1);
     394
     395        /* Wait for the eMMC to enter Stand-by State */
     396        do {
     397                arg = (mmcrca << 16) & 0xFFFF0000;
     398                cmd = SD_CMD_CMD13_SEND_STATUS | SD_CMD_CMD_TYPE_NORMAL | SD_CMD_DP_NO_DATA_PRESENT |
     399                        SD_CMD_CICE_ENABLE | SD_CMD_CCCE_ENABLE | SD_CMD_RSP_TYPE_R1;
     400                if (mmccmd(cmd, arg, resp) == -1)
     401                        return(-1);
     402        } while ((resp[0] & SD_RSP10_R1_CURRENT_STATE) != SD_RSP10_R1_CURRENT_STATE_STANDBY);
     403
     404        return(0);
    335405}
    336406
     
    338408mmcWrite(int interface, char *buf, int blknum, int blkcnt)
    339409{
    340         return(-1);
     410        uint32_t cmd, arg, resp[4];
     411        uint32_t *wordptr = (uint32_t *) buf;
     412        int byteindex;
     413
     414        /* Get the eMMC status by sending CMD13 */
     415        arg = (mmcrca << 16) & 0xFFFF0000;
     416        cmd = SD_CMD_CMD13_SEND_STATUS | SD_CMD_CMD_TYPE_NORMAL | SD_CMD_DP_NO_DATA_PRESENT |
     417                SD_CMD_CICE_ENABLE | SD_CMD_CCCE_ENABLE | SD_CMD_RSP_TYPE_R1;
     418        if (mmccmd(cmd, arg, resp) == -1)
     419                return(-1);
     420
     421        /* Ensure that the eMMC is in the Transfer State before proceeding */
     422        if ((resp[0] & SD_RSP10_R1_CURRENT_STATE) != SD_RSP10_R1_CURRENT_STATE_TRANSFER) {
     423                arg = (mmcrca << 16) & 0xFFFF0000;
     424                cmd  = SD_CMD_CMD7_SELECT_DESELECT_CARD | SD_CMD_CMD_TYPE_NORMAL |
     425                        SD_CMD_DP_NO_DATA_PRESENT | SD_CMD_CICE_ENABLE | SD_CMD_CCCE_ENABLE |
     426                        SD_CMD_RSP_TYPE_R1B;
     427                if (mmccmd(cmd, arg, resp) == -1)
     428                        return(-1);
     429
     430                /* Wait for eMMC to enter Transfer State */
     431                do {
     432                        arg = (mmcrca << 16) & 0xFFFF0000;
     433                        cmd = SD_CMD_CMD13_SEND_STATUS | SD_CMD_CMD_TYPE_NORMAL |
     434                                SD_CMD_DP_NO_DATA_PRESENT | SD_CMD_CICE_ENABLE | SD_CMD_CCCE_ENABLE |
     435                                SD_CMD_RSP_TYPE_R1;
     436                        if (mmccmd(cmd, arg, resp) == -1)
     437                                return(-1);
     438                } while ((resp[0] & SD_RSP10_R1_CURRENT_STATE) != SD_RSP10_R1_CURRENT_STATE_TRANSFER);
     439        }
     440
     441        /* Set the block length in bytes and the number of blocks to write to the SD card */
     442        MMC1_REG(SD_BLK) = 0x200 | (blkcnt << 16);
     443        /* Send CMD25, that is write the number of blocks specified in 'blkcount' from 'buf' to the
     444         * location that is 512 byte aligned in the SD card specified by the block number 'blknum'
     445         */
     446        arg = blknum;
     447        cmd = SD_CMD_CMD25_WRITE_MULTIPLE_BLOCK | SD_CMD_CMD_TYPE_NORMAL | SD_CMD_DP_DATA_PRESENT |
     448                SD_CMD_CICE_ENABLE | SD_CMD_CCCE_ENABLE | SD_CMD_RSP_TYPE_R1 | SD_CMD_MSBS_MULTIPLE |
     449                SD_CMD_DDIR_WRITE | SD_CMD_ACEN_CMD12_ENABLE | SD_CMD_BCE_ENABLE;
     450        if (mmccmd(cmd, arg, resp) == -1)
     451                return(-1);
     452
     453        /* Write the data */
     454        do {
     455                /* Wait until data is ready to be written */
     456                while (!(MMC1_REG(SD_STAT) & (SD_STAT_BWR | SD_STAT_TC)));
     457
     458                if (MMC1_REG(SD_STAT) & SD_STAT_TC)
     459                        break;
     460
     461                /* Clear the BWR status bit in SD_STAT */
     462                MMC1_REG(SD_STAT) |= SD_STAT_BWR;
     463
     464                for (byteindex = 0; byteindex < (0x200 / 4); byteindex++)
     465                        MMC1_REG(SD_DATA) = *wordptr++;
     466        } while (!(MMC1_REG(SD_STAT) & SD_STAT_TC));
     467
     468        /* Put the eMMC into Stand-by State */
     469        arg = 0x00000000;
     470        cmd = SD_CMD_CMD7_SELECT_DESELECT_CARD | SD_CMD_CMD_TYPE_NORMAL | SD_CMD_DP_NO_DATA_PRESENT |
     471                SD_CMD_CICE_ENABLE | SD_CMD_CCCE_ENABLE | SD_CMD_RSP_TYPE_NO_RESPONSE;
     472        if (mmccmd(cmd, arg, resp) == -1)
     473                return(-1);
     474
     475        /* Wait for eMMC to enter Stand-by State */
     476        do {
     477                arg = (mmcrca << 16) & 0xFFFF0000;
     478                cmd  = SD_CMD_CMD13_SEND_STATUS | SD_CMD_CMD_TYPE_NORMAL | SD_CMD_DP_NO_DATA_PRESENT |
     479                        SD_CMD_CICE_ENABLE | SD_CMD_CCCE_ENABLE | SD_CMD_RSP_TYPE_R1;
     480                if (mmccmd(cmd, arg, resp) == -1)
     481                        return(-1);
     482        } while ((resp[0] & SD_RSP10_R1_CURRENT_STATE) != SD_RSP10_R1_CURRENT_STATE_STANDBY);
     483
     484        return(0);
    341485}
    342486
Note: See TracChangeset for help on using the changeset viewer.