SmoothDriving/FatFs/mmc_avr.c
static
BYTE send_cmd (		/* Returns R1 resp (bit7==1:Send failed) */
	BYTE cmd,		/* Command index */
	DWORD arg		/* Argument */
)
{
	BYTE n, res;


	if (cmd & 0x80) {	/* ACMD<n> is the command sequense of CMD55-CMD<n> */
		cmd &= 0x7F;
		res = send_cmd(CMD55, 0);
		if (res > 1) return res;
	}

	/* Select the card and wait for ready except to stop multiple block read */
	if (cmd != CMD12) {
		deselect();
		if (!select()) return 0xFF;
	}

	/* Send command packet */
	xchg_spi(0x40 | cmd);				/* Start + Command index */
	xchg_spi((BYTE)(arg >> 24));		/* Argument[31..24] */
	xchg_spi((BYTE)(arg >> 16));		/* Argument[23..16] */
	xchg_spi((BYTE)(arg >> 8));			/* Argument[15..8] */
	xchg_spi((BYTE)arg);				/* Argument[7..0] */
	n = 0x01;							/* Dummy CRC + Stop */
	if (cmd == CMD0) n = 0x95;			/* Valid CRC for CMD0(0) + Stop */
	if (cmd == CMD8) n = 0x87;			/* Valid CRC for CMD8(0x1AA) Stop */
	xchg_spi(n);

	/* Receive command response */
	if (cmd == CMD12) xchg_spi(0xFF);		/* Skip a stuff byte when stop reading */
	n = 10;								/* Wait for a valid response in timeout of 10 attempts */
	do
		res = xchg_spi(0xFF);
	while ((res & 0x80) && --n);

	return res;			/* Return with the response value */
}
/*-----------------------------------------------------------------------*/
/* Send a command packet to MMC                                          */
/*-----------------------------------------------------------------------*/
Send a command packet to MMC
Send a command packet to MMC
static
BYTE send_cmd (		
	BYTE cmd,		
	DWORD arg		
)
{
	BYTE n, res;
	if (cmd & 0x80) {	
		cmd &= 0x7F;
		res = send_cmd(CMD55, 0);
		if (res > 1) return res;
	}
	if (cmd != CMD12) {
		deselect();
		if (!select()) return 0xFF;
	}
	xchg_spi(0x40 | cmd);				
	xchg_spi((BYTE)(arg >> 24));		
	xchg_spi((BYTE)(arg >> 16));		
	xchg_spi((BYTE)(arg >> 8));			
	xchg_spi((BYTE)arg);				
	n = 0x01;							
	if (cmd == CMD0) n = 0x95;			
	if (cmd == CMD8) n = 0x87;			
	xchg_spi(n);
	if (cmd == CMD12) xchg_spi(0xFF);		
	n = 10;								
	do
		res = xchg_spi(0xFF);
	while ((res & 0x80) && --n);
	return res;			
}
static BYTE send_cmd ( BYTE cmd , DWORD arg ) { BYTE n , res ; if ( cmd & 0x80 ) { cmd &= 0x7F ; res = send_cmd ( CMD55 , 0 ) ; if ( res > 1 ) return res ; } if ( cmd != CMD12 ) { deselect ( ) ; if ( ! select ( ) ) return 0xFF ; } xchg_spi ( 0x40 | cmd ) ; xchg_spi ( ( BYTE ) ( arg >> 24 ) ) ; xchg_spi ( ( BYTE ) ( arg >> 16 ) ) ; xchg_spi ( ( BYTE ) ( arg >> 8 ) ) ; xchg_spi ( ( BYTE ) arg ) ; n = 0x01 ; if ( cmd == CMD0 ) n = 0x95 ; if ( cmd == CMD8 ) n = 0x87 ; xchg_spi ( n ) ; if ( cmd == CMD12 ) xchg_spi ( 0xFF ) ; n = 10 ; do res = xchg_spi ( 0xFF ) ; while ( ( res & 0x80 ) && -- n ) ; return res ; }
Send a command packet to MMC
Send a command packet to MMC
/* Returns R1 resp (bit7==1:Send failed) */ /* Command index */ /* Argument */ /* ACMD<n> is the command sequense of CMD55-CMD<n> */ /* Select the card and wait for ready except to stop multiple block read */ /* Send command packet */ /* Start + Command index */ /* Argument[31..24] */ /* Argument[23..16] */ /* Argument[15..8] */ /* Argument[7..0] */ /* Dummy CRC + Stop */ /* Valid CRC for CMD0(0) + Stop */ /* Valid CRC for CMD8(0x1AA) Stop */ /* Receive command response */ /* Skip a stuff byte when stop reading */ /* Wait for a valid response in timeout of 10 attempts */ /* Return with the response value */