FreeBSD/sys/boot/arm/at91/libat91/sd-card.c
//*----------------------------------------------------------------------------
//* \fn    MCI_readblocks
//* \brief Read one or more blocks
//*----------------------------------------------------------------------------
\fn    MCI_readblocks
\brief Read one or more blocks
\ fn MCI_readblocks \ brief Read one or more blocks
int
MCI_readblocks(char* dest, unsigned blknum, unsigned blkcount)
{
	unsigned int status;
	unsigned int *walker;
	if (MCI_Device.state != AT91C_MCI_IDLE) {
		return 1;
	}
	if ((MCI_GetStatus() & AT91C_SR_READY_FOR_DATA) == 0) {
		return 1;
	}
	while (blkcount)
	{
		if (MCI_StartReadBlock(blknum, dest))
			return -1;
		status = MCIDeviceWaitReady(AT91C_MCI_TIMEOUT);
		if (status & AT91C_MCI_SR_ERROR)
			return 1;
		for (walker = (unsigned int *)dest;
		     walker < (unsigned int *)(dest + SD_BLOCK_SIZE); walker++)
		    *walker = swap(*walker);
		++blknum;
		--blkcount;
		dest += SD_BLOCK_SIZE;
	}
	return 0;
}
int MCI_readblocks ( char * dest , unsigned blknum , unsigned blkcount ) { unsigned int status ; unsigned int * walker ; if ( MCI_Device . state != AT91C_MCI_IDLE ) { return 1 ; } if ( ( MCI_GetStatus ( ) & AT91C_SR_READY_FOR_DATA ) == 0 ) { return 1 ; } while ( blkcount ) { if ( MCI_StartReadBlock ( blknum , dest ) ) return -1 ; status = MCIDeviceWaitReady ( AT91C_MCI_TIMEOUT ) ; if ( status & AT91C_MCI_SR_ERROR ) return 1 ; for ( walker = ( unsigned int * ) dest ; walker < ( unsigned int * ) ( dest + SD_BLOCK_SIZE ) ; walker ++ ) * walker = swap ( * walker ) ; ++ blknum ; -- blkcount ; dest += SD_BLOCK_SIZE ; } return 0 ; }
\fn    MCI_readblocks
\brief Read one or more blocks
\ fn MCI_readblocks \ brief Read one or more blocks
// As long as there is data to read //Do the reading // Wait MCI Device Ready // Fix erratum in MCI part - endian-swap all data. // Update counters & pointers