fatfs/mmcbb.c
static
BYTE send_cmd (		/* Returns command response (bit7==1:Send failed)*/
	BYTE cmd,		/* Command byte */
	DWORD arg		/* Argument */
)
{
	BYTE n, d, buf[6];


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

	/* Select the card and wait for ready */
	deselect();
	if (!select()) return 0xFF;

	/* Send a command packet */
	buf[0] = 0x40 | cmd;			/* Start + Command index */
	buf[1] = (BYTE)(arg >> 24);		/* Argument[31..24] */
	buf[2] = (BYTE)(arg >> 16);		/* Argument[23..16] */
	buf[3] = (BYTE)(arg >> 8);		/* Argument[15..8] */
	buf[4] = (BYTE)arg;				/* Argument[7..0] */
	n = 0x01;						/* Dummy CRC + Stop */
	if (cmd == CMD0) n = 0x95;		/* (valid CRC for CMD0(0)) */
	if (cmd == CMD8) n = 0x87;		/* (valid CRC for CMD8(0x1AA)) */
	buf[5] = n;
	xmit_mmc(buf, 6);

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

	return d;			/* Return with the response value */
}
/*-----------------------------------------------------------------------*/
/* Send a command packet to the card                                     */
/*-----------------------------------------------------------------------*/
Send a command packet to the card
Send a command packet to the card
static
BYTE send_cmd (		
	BYTE cmd,		
	DWORD arg		
)
{
	BYTE n, d, buf[6];
	if (cmd & 0x80) {	
		cmd &= 0x7F;
		n = send_cmd(CMD55, 0);
		if (n > 1) return n;
	}
	deselect();
	if (!select()) return 0xFF;
	buf[0] = 0x40 | cmd;			
	buf[1] = (BYTE)(arg >> 24);		
	buf[2] = (BYTE)(arg >> 16);		
	buf[3] = (BYTE)(arg >> 8);		
	buf[4] = (BYTE)arg;				
	n = 0x01;						
	if (cmd == CMD0) n = 0x95;		
	if (cmd == CMD8) n = 0x87;		
	buf[5] = n;
	xmit_mmc(buf, 6);
	if (cmd == CMD12) rcvr_mmc(&d, 1);	
	n = 10;								
	do
		rcvr_mmc(&d, 1);
	while ((d & 0x80) && --n);
	return d;			
}
static BYTE send_cmd ( BYTE cmd , DWORD arg ) { BYTE n , d , buf [ 6 ] ; if ( cmd & 0x80 ) { cmd &= 0x7F ; n = send_cmd ( CMD55 , 0 ) ; if ( n > 1 ) return n ; } deselect ( ) ; if ( ! select ( ) ) return 0xFF ; buf [ 0 ] = 0x40 | cmd ; buf [ 1 ] = ( BYTE ) ( arg >> 24 ) ; buf [ 2 ] = ( BYTE ) ( arg >> 16 ) ; buf [ 3 ] = ( BYTE ) ( arg >> 8 ) ; buf [ 4 ] = ( BYTE ) arg ; n = 0x01 ; if ( cmd == CMD0 ) n = 0x95 ; if ( cmd == CMD8 ) n = 0x87 ; buf [ 5 ] = n ; xmit_mmc ( buf , 6 ) ; if ( cmd == CMD12 ) rcvr_mmc ( & d , 1 ) ; n = 10 ; do rcvr_mmc ( & d , 1 ) ; while ( ( d & 0x80 ) && -- n ) ; return d ; }
Send a command packet to the card
Send a command packet to the card
/* Returns command response (bit7==1:Send failed)*/ /* Command byte */ /* Argument */ /* ACMD<n> is the command sequense of CMD55-CMD<n> */ /* Select the card and wait for ready */ /* Send a 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)) */ /* (valid CRC for CMD8(0x1AA)) */ /* 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 */