sync_mmc.c
上传用户:dahaojd
上传日期:2008-01-29
资源大小:14357k
文件大小:7k
- /*
- * Copyright 2003 by Texas Instruments Incorporated.
- * All rights reserved. Property of Texas Instruments Incorporated.
- * Restricted rights to use, duplicate or disclose this code are
- * granted through contract.
- *
- */
- /* "@(#) DDK 1.10.00.23 07-02-03 (ddk-b12)" */
- /*
- * ======== mmcsync.c ========
- * Raw MMC soak test. Write/Readback of sequential MMC media sectors.
- */
-
- #include <std.h>
- #include <stdio.h>
- #include <stdlib.h>
- #include <log.h>
- #include <sys.h>
- #include <sem.h>
- #include <hwi.h>
- #include <gio.h>
- #include <tsk.h>
- #include <c5509_mmc.h>
- /*
- * The following are test attributes.
- */
- #define VERIFYDATA /* Perform readback data verification */
- #undef TESTFOREVER /* Repeat test forever or until failure */
- //#define RUNSILENT /* Suppress output during test */
-
-
- /* Number of Channels that need to be opened */
- #define CHANCOUNT 2
- #define INITIALVALUE 0x0 /* initial buffer value */
- #define MAXSECTORNUM 3200 /* Max sector number to test */
- /* interrupt mask definitions */
- #define C5509_MMC_IER0_MASK_DEFAULT 1
- #define C5509_MMC_IER1_MASK_DEFAULT 1
- static C5509_MMC_ChanObj chan[CHANCOUNT];
- /* Buffers to be used with requests */
- static MdUns bufWrite[C5509_MMC_SECLEN];
- static MdUns bufRead[C5509_MMC_SECLEN];
- /* Globals */
- C5509_MMC_DevObj C5509_MMC_devObj;
- /* Bind Parameters */
- C5509_MMC_DevParams C5509_MMC_devParams = {
- /* devParams */
- C5509_MMC_VERSION_1, /* Version number */
- 0, /* Enable/disable DMA for data read/write */
- 0, /* dat3EdgeDetection -- DUMMY */
- 0, /* Determines if MMC goes IDLE during IDLE instr */
- 0, /* enableClkPin -- DUMMY */
- 2, /* CPU CLK to MMC function clk divide down */
- 3, /* MMC function clk to memory clk divide down */
- 0, /*
- * No. memory clks to wait before response timeout
- * Zero indicates no timeout.
- */
- 0, /*
- * No. memory clks to wait before data timeout
- * Zero indicates no timeout.
- */
- 512, /* Length of DATA block to be read in BYTEs*/
- /* drvrParams */
- 2, /* RCA - set by the application */
- CHANCOUNT, /* maximum number of channels required */
- MEDIA_BYTENORMAL, /* MEDIA_[BYTESWAP|BYTENORMAL] */
- 0, /* DMA channel number used for READ operations */
- 0, /* DMA channel number used for WRITE operations */
- NULL, /* Buffer for DMA read */
- NULL, /* Buffer for DMA write */
- chan, /* Array of (noChan number of) Channel Objs */
- C5509_MMC_IER0_MASK_DEFAULT,
- C5509_MMC_IER1_MASK_DEFAULT
- };
-
- /* Media Read/Write structure. */
- static MEDIA_RdWrObj mediaObj;
- /* Task helper functions*/
- static Int issue_read(GIO_Handle chan,Uns sectornum);
- static Int issue_write(GIO_Handle chan,Uns sectornum, MdUns charval);
- #ifdef TESTFOREVER
- static Uns scanCnt = 0; /* total # of sector sweeps of MAXSECTORNUM sectors */
- #endif
- /*
- * ======== main ========
- * Main function.
- */
- main()
- {
- }
- /*
- * ======== initTask ========
- *
- * This is the TASK function.
- */
- Void initTask()
- {
- Int status = IOM_COMPLETED;
- GIO_Handle chanHandle;
- Int sect; /* sector */
-
- printf("DATA VERIFICATION : ");
- #ifdef VERIFYDATA
- printf("ENABLEDn");
- #else
- printf("DISABLEDn");
- #endif
-
- /* Create a channel for accessing MMC. */
- chanHandle = GIO_create("/udevMmc0", IOM_INOUT, &status, NULL, NULL);
- /*
- * Note in the call to GIO_create, the last parameter is NULL
- * This basically means use the default GIO Attrs which are:
- * npackets = 1, timeout = SYS_FOREVER
- */
- printf("Channel create status %dn", status);
- #ifdef TESTFOREVER
- printf("TEST FOREVER ENABLEDn");
- for(;;) {
- #endif
- for (sect = 1; sect <= MAXSECTORNUM; sect++) {
- /* Issue Write. */
- status = issue_write(chanHandle, sect, INITIALVALUE);
- if (status != IOM_COMPLETED) {
- printf("ERROR - write failure, status = %dn", status);
- break;
- }
- #ifndef RUNSILENT
- printf("Wrote to sector %d: buf[0]=%x , buf[1]=%x , buf[255]=%xn",
- sect, bufWrite[0], bufWrite[1], bufWrite[255]);
- #endif
- /* Issue Read. */
- status = issue_read(chanHandle, sect);
- if (status != IOM_COMPLETED) {
- printf("ERROR - read failure, status = %dn", status);
- break;
- }
- #ifndef RUNSILENT
- printf("Read from sector %d: buf[0]=%x , buf[1]=%x , buf[255]=%xn",
- sect, bufRead[0], bufRead[1], bufRead[255]);
- #endif
- }
- #ifdef TESTFOREVER
- scanCnt++; /* bump total scan cnt */
- printf("Scanned %d sectors a total of %d timesn", MAXSECTORNUM, scanCnt);
- if (status != IOM_COMPLETED) {
- printf("FAILED : sector = %dn", sect);
- break;
- }
- }
- #endif
- /* Delete the created channel. */
- status = GIO_delete(chanHandle);
- printf("Channel delete status %dn", status);
- }
- /*
- * ======== issue_write ========
- *
- * Issues write command.
- */
-
- static Int issue_write(GIO_Handle chan, Uns sectornum, MdUns charval)
- {
- Uns size;
- Int i;
- Int status = IOM_COMPLETED;
- Int index = sectornum;
-
- for (i = 0; i < C5509_MMC_SECLEN; i++, index++) {
- bufWrite[i] = charval + index; /* add index to charval*/
-
- }
- mediaObj.buf = bufWrite;
- mediaObj.address = sectornum;
- mediaObj.subAddress = 0;
- mediaObj.length = C5509_MMC_SECLEN;
- size = sizeof(mediaObj);
-
- /* Submit request */
- if ((status = GIO_write(chan, &mediaObj, &size)) < 0) {
- printf("ERROR in writting data at sector %d, status = %dn",
- sectornum, status);
- }
-
- return status;
- }
- /*
- * ======== issue_read ========
- *
- * Issues read command.
- */
-
- static Int issue_read(GIO_Handle chan, Uns sectornum)
- {
- Uns size;
- Int i;
- Int status = IOM_COMPLETED;
- for (i = 0; i < C5509_MMC_SECLEN; i++) {
- bufRead[i] = 0; /* zero readback buffer */
- }
- mediaObj.buf = bufRead;
- mediaObj.address = sectornum;
- mediaObj.subAddress = 0;
- mediaObj.length = C5509_MMC_SECLEN;
- size = sizeof(mediaObj);
-
- /* Submit request */
- status = GIO_read(chan, &mediaObj, &size);
- if (status < 0) {
- printf("ERROR - in reading data at sector %d, status = %dn",
- sectornum, status);
- }
- else if (size != sizeof(mediaObj)) {
- printf("ERROR - Unexpected size returned");
- status = IOM_EBADIO;
- }
- #ifdef VERIFYDATA
- if (status == IOM_COMPLETED) {
- /* Verify data written is the same as read */
- for(i=0; i < C5509_MMC_SECLEN; i++ ) {
- if (bufWrite[i] != bufRead[i]) {
- printf("ERROR - Sector=%d, Wr=%x, Rd=%x, Offset=%dn",
- sectornum, bufWrite[i], bufRead[i], i );
- status = IOM_EBADIO;
- break;
- }
- }
- }
- #endif
- return status;
- }