📄 mmcfs.c
字号:
// // Set the block length to 512 bytes. // MMCSendCommand(SET_BLOCKLEN, 512); if(MMCReadResponse(ucRes, 6) == 0) { break; } // // Clock the MMC bus. // MMCClock(8); // // Increment the address. // ulAddress += 0x00010000; // // Increment the number of cards found. // sMMC.usNumCards++; } // // Clock the MMC bus. // MMCClock(8); // // Speed up the MMC clock. // pulPtr[HwMMCMemConfig >> 2] |= HwMMCMemValue; // // Success. // return(1);}//****************************************************************************//// MMCSelectCardOne selects the first MMC card found during the enumeration// process. Selecting the card a second time will de-select it, which must// be done before another card can be selected.////****************************************************************************static voidMMCSelectCardOne(void){ unsigned char ucRes[6]; // // Activate the first card found. // MMCSendCommand(SELECT_CARD, 0x00010000); MMCReadResponse(ucRes, 6); // // Clock the MMC bus. // MMCClock(8);}//****************************************************************************//// MMCSelectCardTwo selects the second MMC card found during the enumeration// process. Selecting the card a second time will de-select it, which must// be done before another card can be selected.////****************************************************************************static voidMMCSelectCardTwo(void){ unsigned char ucRes[6]; // // Activate the first card found. // MMCSendCommand(SELECT_CARD, 0x00020000); if(MMCReadResponse(ucRes, 6) == 0) { return; } // // Clock the MMC bus. // MMCClock(8);}//****************************************************************************//// MMCRead reads one or more pages from the MMC card, performing byte swapping// if necessary.////****************************************************************************static unsigned longMMCRead(unsigned long ulStart, unsigned long ulCount, unsigned long *pulBuffer, unsigned long bByteSwap){ volatile unsigned long *pulPtr = (unsigned long *)HwBaseAddress; unsigned char ucRes[6]; unsigned long ulData = 0, ulLoop, ulCRC = 0; // // See if we are to read only one page. // if(ulCount == 1) { // // Configure the data line as an output. // MMCDatOutput; // // Tell the MMC card that we want to read a single block. // MMCSendCommand(READ_SINGLE_BLOCK, ulStart * 512); // // Read back the response. // if(MMCReadResponse(ucRes, 6) == 0) { return(0); } // // Configure the data line as an input. // MMCDatInput; // // Clock the MMC bus until the card is ready to send back the data (as // indicated by it pulling the data line low). // do { MMCClock(1); } while((pulPtr[MMC_DAT_PORT >> 2] & MMC_DAT_BIT) != 0); // // See if the data should be byte swapped as it is read. // if(bByteSwap) { // // Loop through the 128 words (512 bytes) of this block. // for(ulLoop = 0; ulLoop < 128; ulLoop++) { // // Read four bytes, byte swapping them and packing them into a // word. // ulData = (unsigned long)MMCReadByte() << 24; ulData |= (unsigned long)MMCReadByte() << 16; ulData |= (unsigned long)MMCReadByte() << 8; ulData |= (unsigned long)MMCReadByte(); // // Write this word to the data buffer. // pulBuffer[ulLoop] = ulData; } // // Compute the CRC16 of this block. // ulCRC = MMCGetCRC16(pulBuffer, 1); } else { // // Loop through the 128 words (512 bytes) of this block. // for(ulLoop = 0; ulLoop < 128; ulLoop++) { // // Read four bytes, packing them into a word. // ulData = (unsigned long)MMCReadByte(); ulData |= (unsigned long)MMCReadByte() << 8; ulData |= (unsigned long)MMCReadByte() << 16; ulData |= (unsigned long)MMCReadByte() << 24; // // Write this word to the data buffer. // pulBuffer[ulLoop] = ulData; } // // Compute the CRC16 of this block. // ulCRC = MMCGetCRC16(pulBuffer, 0); } // // Read the CRC from the card. // ulData = (unsigned long)MMCReadByte() << 8; ulData |= (unsigned long)MMCReadByte(); // // Clock the MMC bus. // MMCClock(9); // // See if the CRC matched. // if(ulCRC != ulData) { // // The CRC did not match, so return a failure. // return(0); } // // Success. // return(1); } else { // // Configure the data line as an output. // MMCDatOutput; // // Tell the MMC card that we want to start reading a set of sequential // blocks. // MMCSendCommand(READ_MULTIPLE_BLOCK, ulStart * 512); // // Read back the response. // if(MMCReadResponse(ucRes, 6) == 0) { return(0); } // // Configure the data line as an input. // MMCDatInput; // // Loop through the requested number of blocks. // while(ulCount--) { // // Clock the MMC bus until the card is ready to send back the data // (as indicated by it pulling the data line low). // do { MMCClock(1); } while((pulPtr[MMC_DAT_PORT >> 2] & MMC_DAT_BIT) != 0); // // See if the data should be byte swapped as it is read. // if(bByteSwap) { // // Loop through the 128 words (512 bytes) of this block. // for(ulLoop = 0; ulLoop < 128; ulLoop++) { // // Read four bytes, byte swapping them and packing them // into a word. // ulData = (unsigned long)MMCReadByte() << 24; ulData |= (unsigned long)MMCReadByte() << 16; ulData |= (unsigned long)MMCReadByte() << 8; ulData |= (unsigned long)MMCReadByte(); // // Write this word to the data buffer. // pulBuffer[ulLoop] = ulData; } // // Compute the CRC16 of this block. // ulCRC = MMCGetCRC16(pulBuffer, 1); } else { // // Loop through the 128 words (512 bytes) of this block. // for(ulLoop = 0; ulLoop < 128; ulLoop++) { // // Read four bytes, packing them into a word. // ulData = (unsigned long)MMCReadByte(); ulData |= (unsigned long)MMCReadByte() << 8; ulData |= (unsigned long)MMCReadByte() << 16; ulData |= (unsigned long)MMCReadByte() << 24; // // Write this word to the data buffer. // pulBuffer[ulLoop] = ulData; } // // Compute the CRC16 of this block. // ulCRC = MMCGetCRC16(pulBuffer, 0); } // // Read the CRC from the card. // ulData = (unsigned long)MMCReadByte() << 8; ulData |= (unsigned long)MMCReadByte(); // // See if the CRC matched. // if(ulCRC != ulData) { // // The CRC did not match, so break out of this loop. // break; } // // Skip to the next portion of the data buffer. // pulBuffer += 128; } // // Configure the data line as an output. // MMCDatOutput; // // Tell the MMC card that we are done reading data. // MMCSendCommand(STOP_TRANSMISSION, 0); // // Read back the response. // if(MMCReadResponse(ucRes, 6) == 0) { return(0); } // // Clock the MMC bus. // MMCClock(8); // // See if the CRC matched. // if(ulCRC != ulData) { // // The CRC did not match, so return a failure. // return(0); } // // Success. // return(1); }}//****************************************************************************//// MMCWrite writes one or more pages to the MMC card.////****************************************************************************static unsigned longMMCWrite(unsigned long ulStart, unsigned long ulCount, unsigned long *pulBuffer){ volatile unsigned long *pulPtr = (unsigned long *)HwBaseAddress; unsigned char ucRes[6]; unsigned long ulData, ulLoop; // // Loop through the requested number of blocks. // while(ulCount--) { // // Configure the data line as an output. // MMCDatOutput; // // Tell the MMC card that we want to write a single page. // MMCSendCommand(WRITE_BLOCK, ulStart * 512); // // Read back the response. // if(MMCReadResponse(ucRes, 6) == 0) { return(0); } // // Check the response to see that the card is ready to write a page. // if((ucRes[3] & 0x01) == 0) { MMCClock(8); return(0); } // // The card is expecting at least two clocks, and then will start // clocking in data the bit after it sees the first zero bit. // Therefore, send 0xFE to generate 7 clocks and then a start bit. // MMCWriteByte(0xfe); // // Loop through the 128 words (512 bytes) of this page. // for(ulLoop = 0; ulLoop < 128; ulLoop++) { // // Get the next word. // ulData = pulBuffer[ulLoop]; // // Write the four bytes of this word. // MMCWriteByte(ulData & 0x000000ff); MMCWriteByte((ulData & 0x0000ff00) >> 8); MMCWriteByte((ulData & 0x00ff0000) >> 16); MMCWriteByte((ulData & 0xff000000) >> 24); } // // Compute the CRC16 for this block. // ulData = MMCGetCRC16(pulBuffer, 0);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -