Ejemplo n.º 1
0
int main( void )
{
  WDTCTL = WDTPW + WDTHOLD;

  //Initialisation of the MMC/SD-card
  while (status != 0)                       // if return in not NULL an error did occur and the
                                            // MMC/SD-card will be initialized again 
  {
    status = mmcInit();
    timeout++;
    if (timeout == 150)                      // Try 50 times till error
    {
      //printf ("No MMC/SD-card found!! %x\n", status);
      break;
    }
  }

  while ((mmcPing() != MMC_SUCCESS));      // Wait till card is inserted

  // Read the Card Size from the CSD Register
  cardSize =  mmcReadCardSize();
    
// Clear Sectors on MMC
  for (i = 0; i < 50; i++) buffer[i] = 1;
  mmcWriteSector(0, buffer);                // write a 50 Byte big block beginning at the (aligned) adress

  for (i = 0; i < 50; i++) buffer[i] = 0;
  mmcWriteSector(1, buffer);                // write a 50 Byte big block beginning at the (aligned) adress

  mmcReadSector(0, buffer);                 // read a size Byte big block beginning at the address.
  for (i = 0; i < 50; i++) if(buffer[i] != 0) P1OUT |= 0x01;
  
  mmcReadSector(1, buffer);                 // read a size Byte big block beginning at the address.
  for (i = 0; i < 50; i++) if(buffer[i] != 0) P1OUT |= 0x02;


// Write Data to MMC  
  for (i = 0; i < 50; i++) buffer[i] = i;
  mmcWriteSector(0, buffer);                // write a 50 Byte big block beginning at the (aligned) adress

  for (i = 0; i < 50; i++) buffer[i] = i+64;
  mmcWriteSector(1, buffer);                // write a 50 Byte big block beginning at the (aligned) adress

  mmcReadSector(0, buffer);                 // read a size Byte big block beginning at the address.
  for (i = 0; i < 50; i++) if(buffer[i] != (unsigned char)i) P1OUT |= 0x04;

  mmcReadSector(1, buffer);                 // read a size Byte big block beginning at the address.
  for (i = 0; i < 50; i++) if(buffer[i] != (unsigned char)(i+64)) P1OUT |= 0x08;

  for (i = 0; i < 50; i++)
    mmcReadSector(i, buffer);               // read a size Byte big block beginning at the address.

  mmcGoIdle();                              // set MMC in Idle mode

  while (1);
}
Ejemplo n.º 2
0
/**************************************************************************//**
 * \brief Write a single sector to the flash card
 *
 * Attempt to write a full sector (including computed checksum)
 *
 * Provides a clean read wrapper separating the rest of the codebase from
 * the MMC library.
 *
 * \param			sectorNum	The sector number to read in (0 to 4194303
 * 								for a 2GB MMC card with 512B sector sizes).
 * \param[in,out]	sector		Pointer to sector to write. Will have a newly
 * 								computed checksum written into it. Most
 * 								likely you will be casting a more specific
 * 								sector type or a simple array to this
 * 								interface
 * \retval		0 success
 * \retval		-1 failure (MMC library returned an error)
 * \see			secureFlashWrite() for more thorough write validation
 *****************************************************************************/
int flashWrite(unsigned long sectorNum, struct Sector *sector)
{
	sector->checksum = fletcherChecksum(sector->data, SECTOR_CRC_SIZE, 0);

	if(mmcWriteSector(sectorNum, (unsigned char *) sector) == MMC_SUCCESS) {
		return FLASH_SUCCESS;
	}
	else {
		return FLASH_FAIL;
	}
}
Ejemplo n.º 3
0
/**************************************************************************//**
 * \brief Write a sector and read it back to verify correctness
 *
 * Write a sector and, if successful, read it back to verify that it passes
 * a checksum check and has the same checksum as before After #WRITE_RETRIES
 * failed write-verify attempts exit
 *
 * \param			sectorNum	The sector number to read in (0 to 4194303
 * 								for a 2GB MMC card with 512B sector sizes).
 * \param[in,out]	sector		Pointer to sector to write. Will have a newly
 * 								computed checksum written into it. Most
 * 								likely you will be casting a more specific
 * 								sector type or a simple array to this
 * 								interface
 * \retval		0 success
 * \retval		-1 failure
 *****************************************************************************/
int secureFlashWrite(unsigned long sectorNum, struct Sector *sector){
	int postChecksum = 0;
	struct Sector tmpSector;
	int i = 0;

	sector->checksum = fletcherChecksum(sector->data, SECTOR_CRC_SIZE, 0);

	for( i = 0; i < WRITE_RETRIES; i++)
	{
		if(mmcWriteSector(sectorNum, (unsigned char *) sector)==MMC_SUCCESS) {
			mmcReadSector(sectorNum, (unsigned char *) &tmpSector);
			postChecksum = fletcherChecksum(tmpSector.data, SECTOR_CRC_SIZE, 0);

			if(tmpSector.checksum == postChecksum &&		// Read-back data passes checksum
					sector->checksum == postChecksum) {		// && Read-back matches original
					return FLASH_SUCCESS;
			}
		}
	}
	// If checksums do not agree and we have tried multiple times, then..
	return FLASH_TIMEOUT;						// Return failure

}
Ejemplo n.º 4
0
void WriteBlock(uint32 LBA)
{
	mmcWriteSector(LBA,BUFFER);
        return;
}