@ -187,6 +187,7 @@ void mmc_write_byte (unsigned char Byte)
# endif
}
#if 0
//############################################################################
//Routine zum schreiben eines Blocks(512Byte) auf die MMC/SD-Karte
unsigned char mmc_write_sector ( unsigned long addr , unsigned char * Buffer )
@ -243,6 +244,7 @@ unsigned char mmc_write_sector (unsigned long addr,unsigned char *Buffer)
return ( 0 ) ;
}
# endif
//############################################################################
//Routine zum lesen des CID Registers von der MMC/SD-Karte (16Bytes)
@ -297,6 +299,111 @@ unsigned char mmc_read_sector (unsigned long addr,unsigned char *Buffer)
return ( 0 ) ;
}
//############################################################################
//Routine zum lesen des CID Registers von der MMC/SD-Karte (16Bytes)
void mmc_read_block_part ( unsigned char * cmd , unsigned char * Buffer , uint16_t count , unsigned int Bytes )
//############################################################################
{
//Sendet Commando cmd an MMC/SD-Karte
if ( mmc_write_command ( cmd ) ! = 0 )
{
return ;
}
//Wartet auf Start Byte von der MMC/SD-Karte (FEh/Start Byte)
while ( mmc_read_byte ( ) ! = 0xfe ) { } ;
//Lesen des Bolcks (normal 512Bytes) von MMC/SD-Karte
for ( unsigned int a = 0 ; a < Bytes ; a + + )
{
if ( Bytes < count ) { * Buffer + + = mmc_read_byte ( ) ; }
else { mmc_read_byte ( ) ; }
}
//CRC-Byte auslesen
mmc_read_byte ( ) ; //CRC - Byte wird nicht ausgewertet
mmc_read_byte ( ) ; //CRC - Byte wird nicht ausgewertet
//set MMC_Chip_Select to high (MMC/SD-Karte Inaktiv)
MMC_Disable ( ) ;
return ;
}
//############################################################################
//Routine zum lesen eines Blocks(512Byte) von der MMC/SD-Karte
void mmc_read_part ( unsigned long addr , unsigned char * Buffer , uint16_t count )
//############################################################################
{
//Commando 16 zum lesen eines Blocks von der MMC/SD - Karte
unsigned char cmd [ ] = { 0x51 , 0x00 , 0x00 , 0x00 , 0x00 , 0xFF } ;
/*Die Adressierung der MMC/SD-Karte wird in Bytes angegeben,
addr wird von Blocks zu Bytes umgerechnet danach werden
diese in das Commando eingef ü gt */
addr = addr < < 9 ; //addr = addr * 512
cmd [ 1 ] = ( ( addr & 0xFF000000 ) > > 24 ) ;
cmd [ 2 ] = ( ( addr & 0x00FF0000 ) > > 16 ) ;
cmd [ 3 ] = ( ( addr & 0x0000FF00 ) > > 8 ) ;
mmc_read_block_part ( cmd , Buffer , count , 512 ) ;
}
//############################################################################
//Routine zum lesen des CID Registers von der MMC/SD-Karte (16Bytes)
void mmc_read_block_to_ringbuffer ( unsigned char * cmd , ringbuf_t * buffer , unsigned int Bytes )
//############################################################################
{
//Sendet Commando cmd an MMC/SD-Karte
if ( mmc_write_command ( cmd ) ! = 0 )
{
return ;
}
//Wartet auf Start Byte von der MMC/SD-Karte (FEh/Start Byte)
while ( mmc_read_byte ( ) ! = 0xfe ) { ; }
uint16_t data = 0 ;
//Lesen des Bolcks (normal 512Bytes) von MMC/SD-Karte
for ( unsigned int a = 0 ; a < Bytes ; a + + )
{
data < < = 8 ;
data | = mmc_read_byte ( ) ;
if ( a & 1 ) { while ( ringbuf_put ( buffer , data ) ) { ; } }
}
//CRC-Byte auslesen
mmc_read_byte ( ) ; //CRC - Byte wird nicht ausgewertet
mmc_read_byte ( ) ; //CRC - Byte wird nicht ausgewertet
//set MMC_Chip_Select to high (MMC/SD-Karte Inaktiv)
MMC_Disable ( ) ;
return ;
}
//############################################################################
//Routine zum lesen eines Blocks(512Byte) von der MMC/SD-Karte
void mmc_read_to_ringbuffer ( unsigned long addr , ringbuf_t * buffer )
//############################################################################
{
//Commando 16 zum lesen eines Blocks von der MMC/SD - Karte
unsigned char cmd [ ] = { 0x51 , 0x00 , 0x00 , 0x00 , 0x00 , 0xFF } ;
/*Die Adressierung der MMC/SD-Karte wird in Bytes angegeben,
addr wird von Blocks zu Bytes umgerechnet danach werden
diese in das Commando eingef ü gt */
addr = addr < < 9 ; //addr = addr * 512
cmd [ 1 ] = ( ( addr & 0xFF000000 ) > > 24 ) ;
cmd [ 2 ] = ( ( addr & 0x00FF0000 ) > > 16 ) ;
cmd [ 3 ] = ( ( addr & 0x0000FF00 ) > > 8 ) ;
mmc_read_block_to_ringbuffer ( cmd , buffer , 512 ) ;
}
//############################################################################
//Routine zum lesen des CID Registers von der MMC/SD-Karte (16Bytes)
unsigned char mmc_read_cid ( unsigned char * Buffer )