2012-06-23 20:08:56 +02:00
|
|
|
#include "diskio.h"
|
|
|
|
#include "string.h"
|
2012-08-09 02:17:50 +02:00
|
|
|
#include "sdmmc.h"
|
2012-06-23 20:08:56 +02:00
|
|
|
#include "memory.h"
|
|
|
|
|
|
|
|
DSTATUS disk_initialize( BYTE drv )
|
|
|
|
{
|
2012-08-09 02:17:50 +02:00
|
|
|
if (sdmmc_check_card() == SDMMC_NO_CARD)
|
|
|
|
return STA_NOINIT;
|
2012-06-24 00:07:03 +02:00
|
|
|
|
2012-08-09 02:17:50 +02:00
|
|
|
sdmmc_ack_card();
|
|
|
|
return disk_status(drv);
|
2012-06-23 20:08:56 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
DSTATUS disk_status( BYTE drv )
|
|
|
|
{
|
|
|
|
(void)drv;
|
2012-08-09 02:17:50 +02:00
|
|
|
if (sdmmc_check_card() == SDMMC_INSERTED)
|
|
|
|
return 0;
|
|
|
|
else
|
|
|
|
return STA_NODISK;
|
2012-06-23 20:08:56 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
DRESULT disk_read( BYTE drv, BYTE *buff, DWORD sector, BYTE count )
|
|
|
|
{
|
|
|
|
u8 *buffer = (u8*)buff;
|
2012-08-09 02:17:50 +02:00
|
|
|
//dbgprintf("sdmmc_read( %d, %d, %p, %p)\n", sector, count, buff, buffer );
|
2012-06-23 20:08:56 +02:00
|
|
|
|
|
|
|
if( (u32)buff & 0xF0000000 )
|
|
|
|
{
|
|
|
|
buffer = (u8*)0x1000;
|
|
|
|
u32 i=0;
|
|
|
|
u32 Blocks = 3;
|
|
|
|
while(1)
|
|
|
|
{
|
|
|
|
if( (count-i) < Blocks )
|
|
|
|
Blocks = (count-i);
|
|
|
|
|
2012-08-09 02:17:50 +02:00
|
|
|
sdmmc_read( sector + i, Blocks, buffer );
|
2012-06-23 20:08:56 +02:00
|
|
|
memcpy( buff + i * 512, buffer, Blocks * 512 );
|
|
|
|
|
|
|
|
i+=Blocks;
|
|
|
|
|
|
|
|
if( i >= count )
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
} else {
|
2012-08-09 02:17:50 +02:00
|
|
|
sdmmc_read( sector, count, buffer );
|
2012-06-23 20:08:56 +02:00
|
|
|
dc_flushrange( buffer, count*512 );
|
|
|
|
ahb_flush_from( AHB_SDHC );
|
|
|
|
}
|
|
|
|
|
|
|
|
return RES_OK;
|
|
|
|
}
|
|
|
|
// Write Sector(s)
|
|
|
|
DRESULT disk_write( BYTE drv, const BYTE *buff, DWORD sector, BYTE count )
|
|
|
|
{
|
|
|
|
u8 *buffer = (u8*)buff;
|
|
|
|
|
|
|
|
if( (u32)buff & 0xF0000000 )
|
|
|
|
{
|
|
|
|
buffer = (u8*)0x1000;
|
|
|
|
u32 i;
|
|
|
|
for( i=0; i < count; ++i )
|
|
|
|
{
|
|
|
|
memcpy( buffer, (void*)buff + i * 512, 512 );
|
2012-08-09 02:17:50 +02:00
|
|
|
sdmmc_write( sector + i, 1, buffer );
|
2012-06-23 20:08:56 +02:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
|
|
|
|
ahb_flush_to( AHB_SDHC );
|
2012-08-09 02:17:50 +02:00
|
|
|
sdmmc_write( sector, count, buffer );
|
2012-06-23 20:08:56 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return RES_OK;
|
|
|
|
}
|