small code optimisation after looking through the generated ASM listings
This commit is contained in:
parent
546554bcda
commit
f898e0fdb8
|
|
@ -117,7 +117,7 @@ OUTPUT_FILE_DEP:= ./makedep.mk
|
||||||
./%.o: .././%.c
|
./%.o: .././%.c
|
||||||
@echo Building file: $<
|
@echo Building file: $<
|
||||||
@echo Invoking: AVR/GNU C Compiler : (AVR_8_bit_GNU_Toolchain_3.4.0_663) 4.6.2
|
@echo Invoking: AVR/GNU C Compiler : (AVR_8_bit_GNU_Toolchain_3.4.0_663) 4.6.2
|
||||||
$(QUOTE)C:\Program Files (x86)\Atmel\Atmel Studio 6.0\extensions\Atmel\AVRGCC\3.4.0.65\AVRToolchain\bin\avr-gcc.exe$(QUOTE) -funsigned-char -funsigned-bitfields -O1 -ffunction-sections -fpack-struct -fshort-enums -Wall -Wundef -Werror -pedantic -pedantic-errors -c -std=gnu99 -MD -MP -MF "$(@:%.o=%.d)" -MT"$(@:%.o=%.d)" -MT"$(@:%.o=%.o)" -mmcu=atmega1284p -o"$@" "$<"
|
$(QUOTE)C:\Program Files (x86)\Atmel\Atmel Studio 6.0\extensions\Atmel\AVRGCC\3.4.0.65\AVRToolchain\bin\avr-gcc.exe$(QUOTE) -funsigned-char -funsigned-bitfields -O1 -ffunction-sections -fpack-struct -fshort-enums -Wall -Wundef -Werror -pedantic -pedantic-errors -c -std=gnu99 -save-temps -MD -MP -MF "$(@:%.o=%.d)" -MT"$(@:%.o=%.d)" -MT"$(@:%.o=%.o)" -mmcu=atmega1284p -o"$@" "$<"
|
||||||
@echo Finished building: $<
|
@echo Finished building: $<
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -45,28 +45,29 @@
|
||||||
<PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
|
<PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
|
||||||
<ToolchainSettings>
|
<ToolchainSettings>
|
||||||
<AvrGcc>
|
<AvrGcc>
|
||||||
<avrgcc.common.outputfiles.hex>True</avrgcc.common.outputfiles.hex>
|
<avrgcc.common.outputfiles.hex>True</avrgcc.common.outputfiles.hex>
|
||||||
<avrgcc.common.outputfiles.lss>True</avrgcc.common.outputfiles.lss>
|
<avrgcc.common.outputfiles.lss>True</avrgcc.common.outputfiles.lss>
|
||||||
<avrgcc.common.outputfiles.eep>True</avrgcc.common.outputfiles.eep>
|
<avrgcc.common.outputfiles.eep>True</avrgcc.common.outputfiles.eep>
|
||||||
<avrgcc.compiler.general.ChangeDefaultCharTypeUnsigned>True</avrgcc.compiler.general.ChangeDefaultCharTypeUnsigned>
|
<avrgcc.compiler.general.ChangeDefaultCharTypeUnsigned>True</avrgcc.compiler.general.ChangeDefaultCharTypeUnsigned>
|
||||||
<avrgcc.compiler.general.ChangeDefaultBitFieldUnsigned>True</avrgcc.compiler.general.ChangeDefaultBitFieldUnsigned>
|
<avrgcc.compiler.general.ChangeDefaultBitFieldUnsigned>True</avrgcc.compiler.general.ChangeDefaultBitFieldUnsigned>
|
||||||
<avrgcc.compiler.optimization.level>Optimize (-O1)</avrgcc.compiler.optimization.level>
|
<avrgcc.compiler.optimization.level>Optimize (-O1)</avrgcc.compiler.optimization.level>
|
||||||
<avrgcc.compiler.optimization.PrepareFunctionsForGarbageCollection>True</avrgcc.compiler.optimization.PrepareFunctionsForGarbageCollection>
|
<avrgcc.compiler.optimization.PrepareFunctionsForGarbageCollection>True</avrgcc.compiler.optimization.PrepareFunctionsForGarbageCollection>
|
||||||
<avrgcc.compiler.optimization.PackStructureMembers>True</avrgcc.compiler.optimization.PackStructureMembers>
|
<avrgcc.compiler.optimization.PackStructureMembers>True</avrgcc.compiler.optimization.PackStructureMembers>
|
||||||
<avrgcc.compiler.optimization.AllocateBytesNeededForEnum>True</avrgcc.compiler.optimization.AllocateBytesNeededForEnum>
|
<avrgcc.compiler.optimization.AllocateBytesNeededForEnum>True</avrgcc.compiler.optimization.AllocateBytesNeededForEnum>
|
||||||
<avrgcc.compiler.warnings.AllWarnings>True</avrgcc.compiler.warnings.AllWarnings>
|
<avrgcc.compiler.warnings.AllWarnings>True</avrgcc.compiler.warnings.AllWarnings>
|
||||||
<avrgcc.compiler.warnings.Undefined>True</avrgcc.compiler.warnings.Undefined>
|
<avrgcc.compiler.warnings.Undefined>True</avrgcc.compiler.warnings.Undefined>
|
||||||
<avrgcc.compiler.warnings.WarningsAsErrors>True</avrgcc.compiler.warnings.WarningsAsErrors>
|
<avrgcc.compiler.warnings.WarningsAsErrors>True</avrgcc.compiler.warnings.WarningsAsErrors>
|
||||||
<avrgcc.compiler.warnings.Pedantic>True</avrgcc.compiler.warnings.Pedantic>
|
<avrgcc.compiler.warnings.Pedantic>True</avrgcc.compiler.warnings.Pedantic>
|
||||||
<avrgcc.compiler.warnings.PedanticWarningsAsErrors>True</avrgcc.compiler.warnings.PedanticWarningsAsErrors>
|
<avrgcc.compiler.warnings.PedanticWarningsAsErrors>True</avrgcc.compiler.warnings.PedanticWarningsAsErrors>
|
||||||
<avrgcc.linker.libraries.Libraries>
|
<avrgcc.compiler.miscellaneous.DoNotDeleteTemporaryFiles>True</avrgcc.compiler.miscellaneous.DoNotDeleteTemporaryFiles>
|
||||||
<ListValues>
|
<avrgcc.linker.libraries.Libraries>
|
||||||
<Value>m</Value>
|
<ListValues>
|
||||||
</ListValues>
|
<Value>m</Value>
|
||||||
</avrgcc.linker.libraries.Libraries>
|
</ListValues>
|
||||||
<avrgcc.linker.optimization.GarbageCollectUnusedSections>True</avrgcc.linker.optimization.GarbageCollectUnusedSections>
|
</avrgcc.linker.libraries.Libraries>
|
||||||
<avrgcc.linker.optimization.RelaxBranches>True</avrgcc.linker.optimization.RelaxBranches>
|
<avrgcc.linker.optimization.GarbageCollectUnusedSections>True</avrgcc.linker.optimization.GarbageCollectUnusedSections>
|
||||||
</AvrGcc>
|
<avrgcc.linker.optimization.RelaxBranches>True</avrgcc.linker.optimization.RelaxBranches>
|
||||||
|
</AvrGcc>
|
||||||
</ToolchainSettings>
|
</ToolchainSettings>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
/*
|
/*
|
||||||
* P8000 WDC Emulator
|
* P8000 WDC Emulator
|
||||||
*
|
*
|
||||||
* $Id: wdc_drv_mmc.c,v 1.6 2012/06/05 19:46:26 olivleh1 Exp $
|
* $Id: wdc_drv_mmc.c,v 1.7 2012/06/07 00:34:36 olivleh1 Exp $
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
@ -36,6 +36,16 @@
|
||||||
uint8_t mmc_read_block ( uint8_t *, uint8_t *, uint16_t );
|
uint8_t mmc_read_block ( uint8_t *, uint8_t *, uint16_t );
|
||||||
uint8_t mmc_cmd ( uint8_t * );
|
uint8_t mmc_cmd ( uint8_t * );
|
||||||
|
|
||||||
|
typedef union {
|
||||||
|
uint32_t value32;
|
||||||
|
struct {
|
||||||
|
uint8_t ll;
|
||||||
|
uint8_t lh;
|
||||||
|
uint8_t hl;
|
||||||
|
uint8_t hh;
|
||||||
|
} value8;
|
||||||
|
} sint32;
|
||||||
|
|
||||||
#ifdef SPI_CRC
|
#ifdef SPI_CRC
|
||||||
const uint16_t crc16_table[256] = {
|
const uint16_t crc16_table[256] = {
|
||||||
0x0000, 0x1021, 0x2042, 0x3063, 0x4084, 0x50a5, 0x60c6, 0x70e7,
|
0x0000, 0x1021, 0x2042, 0x3063, 0x4084, 0x50a5, 0x60c6, 0x70e7,
|
||||||
|
|
@ -226,8 +236,10 @@ uint8_t mmc_cmd ( uint8_t *cmd )
|
||||||
|
|
||||||
uint8_t mmc_write_sector ( uint32_t addr, uint8_t *Buffer )
|
uint8_t mmc_write_sector ( uint32_t addr, uint8_t *Buffer )
|
||||||
{
|
{
|
||||||
|
sint32 x;
|
||||||
uint8_t tmp;
|
uint8_t tmp;
|
||||||
uint8_t cmd[] = {CMD24, 0x00, 0x00, 0x00, 0x00, 0xFF};
|
uint8_t cmd[] = {CMD24, 0x00, 0x00, 0x00, 0x00, 0xFF};
|
||||||
|
uint16_t i;
|
||||||
#ifdef SPI_CRC
|
#ifdef SPI_CRC
|
||||||
uint16_t crc;
|
uint16_t crc;
|
||||||
uint8_t crcl, crch;
|
uint8_t crcl, crch;
|
||||||
|
|
@ -236,11 +248,11 @@ uint8_t mmc_write_sector ( uint32_t addr, uint8_t *Buffer )
|
||||||
MMC_Enable();
|
MMC_Enable();
|
||||||
|
|
||||||
// convert blocks to bytes
|
// convert blocks to bytes
|
||||||
addr = addr << 9; //addr = addr * 512
|
addr = addr * MMC_BLOCKLEN;
|
||||||
|
x.value32 = addr;
|
||||||
cmd[1] = ( ( addr & 0xFF000000 ) >> 24 );
|
cmd[1] = x.value8.hh;
|
||||||
cmd[2] = ( ( addr & 0x00FF0000 ) >> 16 );
|
cmd[2] = x.value8.hl;
|
||||||
cmd[3] = ( ( addr & 0x0000FF00 ) >> 8 );
|
cmd[3] = x.value8.lh;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* send CMD24
|
* send CMD24
|
||||||
|
|
@ -255,13 +267,13 @@ uint8_t mmc_write_sector ( uint32_t addr, uint8_t *Buffer )
|
||||||
xmit_byte ( SB_START );
|
xmit_byte ( SB_START );
|
||||||
|
|
||||||
#ifdef SPI_CRC
|
#ifdef SPI_CRC
|
||||||
crc = crc16 ( Buffer, 512 );
|
crc = crc16 ( Buffer, MMC_BLOCKLEN );
|
||||||
crch = crc >> 8;
|
crch = crc >> 8;
|
||||||
crcl = crc & 0xff;
|
crcl = crc & 0xff;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
//write a single block
|
//write a single block
|
||||||
for ( uint16_t a = 0; a < 512; a++ ) {
|
for ( i = MMC_BLOCKLEN ; i ; i-- ) {
|
||||||
uint8_t data = *Buffer;
|
uint8_t data = *Buffer;
|
||||||
Buffer++;
|
Buffer++;
|
||||||
wait_till_send_done();
|
wait_till_send_done();
|
||||||
|
|
@ -296,6 +308,7 @@ uint8_t mmc_write_sector ( uint32_t addr, uint8_t *Buffer )
|
||||||
|
|
||||||
uint8_t mmc_read_block ( uint8_t *cmd, uint8_t *Buffer, uint16_t Bytes )
|
uint8_t mmc_read_block ( uint8_t *cmd, uint8_t *Buffer, uint16_t Bytes )
|
||||||
{
|
{
|
||||||
|
uint16_t i = Bytes;
|
||||||
#ifdef SPI_CRC
|
#ifdef SPI_CRC
|
||||||
uint16_t crc;
|
uint16_t crc;
|
||||||
#endif
|
#endif
|
||||||
|
|
@ -320,12 +333,13 @@ uint8_t mmc_read_block ( uint8_t *cmd, uint8_t *Buffer, uint16_t Bytes )
|
||||||
*Buffer = recv_byte();
|
*Buffer = recv_byte();
|
||||||
|
|
||||||
//read the remaining 511 bytes
|
//read the remaining 511 bytes
|
||||||
for ( uint16_t a = 0; a < Bytes - 1; a++ ) {
|
do {
|
||||||
xmit_byte ( 0xff ); // send dummy byte
|
xmit_byte ( 0xff ); // send dummy byte
|
||||||
Buffer++;
|
Buffer++;
|
||||||
|
i--;
|
||||||
wait_till_send_done();
|
wait_till_send_done();
|
||||||
*Buffer = recv_byte();
|
*Buffer = recv_byte();
|
||||||
}
|
} while ( i );
|
||||||
|
|
||||||
Buffer = Buffer - ( Bytes - 1 );
|
Buffer = Buffer - ( Bytes - 1 );
|
||||||
|
|
||||||
|
|
@ -352,25 +366,35 @@ uint8_t mmc_read_block ( uint8_t *cmd, uint8_t *Buffer, uint16_t Bytes )
|
||||||
|
|
||||||
uint8_t mmc_read_sector ( uint32_t addr, uint8_t *Buffer )
|
uint8_t mmc_read_sector ( uint32_t addr, uint8_t *Buffer )
|
||||||
{
|
{
|
||||||
|
sint32 x;
|
||||||
/*
|
/*
|
||||||
* send CMD17
|
* send CMD17
|
||||||
*/
|
*/
|
||||||
uint8_t cmd[] = {CMD17, 0x00, 0x00, 0x00, 0x00, 0xFF};
|
uint8_t cmd[] = {CMD17, 0x00, 0x00, 0x00, 0x00, 0xFF};
|
||||||
|
|
||||||
// convert blocks to bytes
|
// convert blocks to bytes
|
||||||
addr = addr << 9; //addr = addr * 512
|
addr = addr * MMC_BLOCKLEN;
|
||||||
cmd[1] = ( ( addr & 0xFF000000 ) >> 24 );
|
x.value32 = addr;
|
||||||
cmd[2] = ( ( addr & 0x00FF0000 ) >> 16 );
|
cmd[1] = x.value8.hh;
|
||||||
cmd[3] = ( ( addr & 0x0000FF00 ) >> 8 );
|
cmd[2] = x.value8.hl;
|
||||||
|
cmd[3] = x.value8.lh;
|
||||||
|
|
||||||
return mmc_read_block ( cmd, Buffer, 512 );
|
/*
|
||||||
|
cmd[1] = ( ( addr & 0xFF000000 ) >> 24 );
|
||||||
|
cmd[2] = ( ( addr & 0x00FF0000 ) >> 16 );
|
||||||
|
cmd[3] = ( ( addr & 0x0000FF00 ) >> 8 );
|
||||||
|
*/
|
||||||
|
return mmc_read_block ( cmd, Buffer, MMC_BLOCKLEN );
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t mmc_read_multiblock ( uint32_t addr, uint8_t *Buffer, uint8_t numblocks )
|
uint8_t mmc_read_multiblock ( uint32_t addr, uint8_t *Buffer, uint8_t numblocks )
|
||||||
{
|
{
|
||||||
|
sint32 x;
|
||||||
uint8_t resp;
|
uint8_t resp;
|
||||||
uint8_t cmd[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF };
|
uint8_t cmd[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF };
|
||||||
|
uint8_t n = numblocks;
|
||||||
|
uint16_t i;
|
||||||
#ifdef SPI_CRC
|
#ifdef SPI_CRC
|
||||||
uint16_t crc;
|
uint16_t crc;
|
||||||
#endif
|
#endif
|
||||||
|
|
@ -397,12 +421,13 @@ uint8_t mmc_read_multiblock ( uint32_t addr, uint8_t *Buffer, uint8_t numblocks
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// convert blocks to bytes
|
// convert blocks to bytes
|
||||||
addr = addr << 9; //addr = addr * 512
|
addr = addr * MMC_BLOCKLEN;
|
||||||
|
x.value32 = addr;
|
||||||
cmd[0] = CMD18;
|
cmd[0] = CMD18;
|
||||||
cmd[1] = ( ( addr & 0xFF000000 ) >> 24 );
|
cmd[1] = x.value8.hh;
|
||||||
cmd[2] = ( ( addr & 0x00FF0000 ) >> 16 );
|
cmd[2] = x.value8.hl;
|
||||||
cmd[3] = ( ( addr & 0x0000FF00 ) >> 8 );
|
cmd[3] = x.value8.lh;
|
||||||
cmd[4] = ( addr & 0x000000FF );
|
cmd[4] = 0;
|
||||||
|
|
||||||
wait_till_card_ready();
|
wait_till_card_ready();
|
||||||
|
|
||||||
|
|
@ -415,7 +440,9 @@ uint8_t mmc_read_multiblock ( uint32_t addr, uint8_t *Buffer, uint8_t numblocks
|
||||||
return ( 1 );
|
return ( 1 );
|
||||||
}
|
}
|
||||||
|
|
||||||
for ( uint8_t n = numblocks; n > 0; n-- ) {
|
do {
|
||||||
|
n--;
|
||||||
|
i = MMC_BLOCKLEN - 1;
|
||||||
// wait for startbyte
|
// wait for startbyte
|
||||||
while ( 1 ) {
|
while ( 1 ) {
|
||||||
send_dummy_byte();
|
send_dummy_byte();
|
||||||
|
|
@ -426,31 +453,32 @@ uint8_t mmc_read_multiblock ( uint32_t addr, uint8_t *Buffer, uint8_t numblocks
|
||||||
send_dummy_byte();
|
send_dummy_byte();
|
||||||
*Buffer = recv_byte();
|
*Buffer = recv_byte();
|
||||||
// receive the block
|
// receive the block
|
||||||
for ( uint16_t a = 0; a < 512 - 1; a++ ) {
|
do {
|
||||||
xmit_byte ( 0xff );
|
xmit_byte ( 0xff );
|
||||||
Buffer++;
|
Buffer++;
|
||||||
|
i--;
|
||||||
wait_till_send_done();
|
wait_till_send_done();
|
||||||
*Buffer = recv_byte();
|
*Buffer = recv_byte();
|
||||||
}
|
} while ( i );
|
||||||
// handle CRC
|
// handle CRC
|
||||||
#ifdef SPI_CRC
|
#ifdef SPI_CRC
|
||||||
Buffer = Buffer - ( 512 - 1 );
|
Buffer = Buffer - ( MMC_BLOCKLEN - 1 );
|
||||||
send_dummy_byte();
|
send_dummy_byte();
|
||||||
crc = recv_byte() << 8;
|
crc = recv_byte() << 8;
|
||||||
send_dummy_byte();
|
send_dummy_byte();
|
||||||
crc |= recv_byte();
|
crc |= recv_byte();
|
||||||
if ( crc != crc16 ( Buffer, 512 ) ) {
|
if ( crc != crc16 ( Buffer, MMC_BLOCKLEN ) ) {
|
||||||
MMC_Disable();
|
MMC_Disable();
|
||||||
return ( 1 );
|
return ( 1 );
|
||||||
}
|
}
|
||||||
Buffer = Buffer + 512;
|
Buffer = Buffer + MMC_BLOCKLEN;
|
||||||
#else
|
#else
|
||||||
send_dummy_byte();
|
send_dummy_byte();
|
||||||
send_dummy_byte();
|
send_dummy_byte();
|
||||||
Buffer++;
|
Buffer++;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
}
|
} while ( n );
|
||||||
|
|
||||||
wait_till_card_ready();
|
wait_till_card_ready();
|
||||||
|
|
||||||
|
|
@ -478,8 +506,11 @@ uint8_t mmc_read_multiblock ( uint32_t addr, uint8_t *Buffer, uint8_t numblocks
|
||||||
|
|
||||||
uint8_t mmc_write_multiblock ( uint32_t addr, uint8_t *Buffer, uint8_t numblocks )
|
uint8_t mmc_write_multiblock ( uint32_t addr, uint8_t *Buffer, uint8_t numblocks )
|
||||||
{
|
{
|
||||||
|
sint32 x;
|
||||||
uint8_t resp;
|
uint8_t resp;
|
||||||
uint8_t cmd[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF };
|
uint8_t cmd[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF };
|
||||||
|
uint8_t n = numblocks;
|
||||||
|
uint16_t i;
|
||||||
#ifdef SPI_CRC
|
#ifdef SPI_CRC
|
||||||
uint16_t crc;
|
uint16_t crc;
|
||||||
uint8_t crcl, crch;
|
uint8_t crcl, crch;
|
||||||
|
|
@ -507,11 +538,12 @@ uint8_t mmc_write_multiblock ( uint32_t addr, uint8_t *Buffer, uint8_t numblocks
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// convert blocks to bytes
|
// convert blocks to bytes
|
||||||
addr = addr << 9;
|
addr = addr * MMC_BLOCKLEN;
|
||||||
|
x.value32 = addr;
|
||||||
cmd[0] = CMD25;
|
cmd[0] = CMD25;
|
||||||
cmd[1] = ( ( addr & 0xFF000000 ) >> 24 );
|
cmd[1] = x.value8.hh;
|
||||||
cmd[2] = ( ( addr & 0x00FF0000 ) >> 16 );
|
cmd[2] = x.value8.hl;
|
||||||
cmd[3] = ( ( addr & 0x0000FF00 ) >> 8 );
|
cmd[3] = x.value8.lh;
|
||||||
cmd[4] = 0;
|
cmd[4] = 0;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
@ -523,9 +555,9 @@ uint8_t mmc_write_multiblock ( uint32_t addr, uint8_t *Buffer, uint8_t numblocks
|
||||||
return ( 1 );
|
return ( 1 );
|
||||||
}
|
}
|
||||||
|
|
||||||
for ( uint8_t n = numblocks; n > 0; n-- ) {
|
do {
|
||||||
#ifdef SPI_CRC
|
#ifdef SPI_CRC
|
||||||
crc = crc16 ( Buffer, 512 );
|
crc = crc16 ( Buffer, MMC_BLOCKLEN );
|
||||||
crch = crc >> 8;
|
crch = crc >> 8;
|
||||||
crcl = crc & 0xff;
|
crcl = crc & 0xff;
|
||||||
#endif
|
#endif
|
||||||
|
|
@ -535,13 +567,13 @@ uint8_t mmc_write_multiblock ( uint32_t addr, uint8_t *Buffer, uint8_t numblocks
|
||||||
xmit_byte ( MB_START );
|
xmit_byte ( MB_START );
|
||||||
|
|
||||||
//actually transfer the data
|
//actually transfer the data
|
||||||
for ( uint16_t i = 512; i; i-- ) {
|
for ( i = MMC_BLOCKLEN; i; i-- ) {
|
||||||
uint8_t data = *Buffer;
|
uint8_t data = *Buffer;
|
||||||
Buffer++;
|
Buffer++;
|
||||||
wait_till_send_done();
|
wait_till_send_done();
|
||||||
xmit_byte ( data );
|
xmit_byte ( data );
|
||||||
}
|
}
|
||||||
|
n--;
|
||||||
wait_till_send_done();
|
wait_till_send_done();
|
||||||
// handle CRC
|
// handle CRC
|
||||||
#ifdef SPI_CRC
|
#ifdef SPI_CRC
|
||||||
|
|
@ -568,7 +600,7 @@ uint8_t mmc_write_multiblock ( uint32_t addr, uint8_t *Buffer, uint8_t numblocks
|
||||||
MMC_Disable();
|
MMC_Disable();
|
||||||
return ( 2 );
|
return ( 2 );
|
||||||
}
|
}
|
||||||
}
|
} while ( n );
|
||||||
|
|
||||||
wait_till_card_ready();
|
wait_till_card_ready();
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
/*
|
/*
|
||||||
* P8000 WDC Emulator
|
* P8000 WDC Emulator
|
||||||
*
|
*
|
||||||
* $Id: wdc_drv_mmc.h,v 1.4 2012/06/05 19:46:26 olivleh1 Exp $
|
* $Id: wdc_drv_mmc.h,v 1.5 2012/06/07 00:34:36 olivleh1 Exp $
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
@ -16,6 +16,7 @@ extern uint8_t mmc_write_sector ( uint32_t addr, uint8_t *Buffer );
|
||||||
extern uint8_t mmc_read_multiblock ( uint32_t addr, uint8_t *Buffer, uint8_t numblocks );
|
extern uint8_t mmc_read_multiblock ( uint32_t addr, uint8_t *Buffer, uint8_t numblocks );
|
||||||
extern uint8_t mmc_write_multiblock ( uint32_t addr, uint8_t *Buffer, uint8_t numblocks );
|
extern uint8_t mmc_write_multiblock ( uint32_t addr, uint8_t *Buffer, uint8_t numblocks );
|
||||||
|
|
||||||
|
#define MMC_BLOCKLEN 512
|
||||||
|
|
||||||
#endif /* MMC_H_ */
|
#endif /* MMC_H_ */
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
/*
|
/*
|
||||||
* P8000 WDC Emulator
|
* P8000 WDC Emulator
|
||||||
*
|
*
|
||||||
* $Id: wdc_if_disk.h,v 1.4 2012/06/05 18:21:48 olivleh1 Exp $
|
* $Id: wdc_if_disk.h,v 1.5 2012/06/07 00:34:36 olivleh1 Exp $
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
@ -15,4 +15,7 @@ extern uint8_t wdc_write_sector ( uint32_t addr, uint8_t *sector );
|
||||||
extern uint8_t wdc_read_sector ( uint32_t addr, uint8_t *sector );
|
extern uint8_t wdc_read_sector ( uint32_t addr, uint8_t *sector );
|
||||||
extern uint8_t wdc_read_multiblock ( uint32_t addr, uint8_t *sector, uint8_t numblocks );
|
extern uint8_t wdc_read_multiblock ( uint32_t addr, uint8_t *sector, uint8_t numblocks );
|
||||||
extern uint8_t wdc_write_multiblock ( uint32_t addr, uint8_t *sector, uint8_t numblocks );
|
extern uint8_t wdc_write_multiblock ( uint32_t addr, uint8_t *sector, uint8_t numblocks );
|
||||||
|
|
||||||
|
#define WDC_BLOCKLEN 512
|
||||||
|
|
||||||
#endif /* WDC_IF_SDCARD_H_ */
|
#endif /* WDC_IF_SDCARD_H_ */
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
/*
|
/*
|
||||||
* P8000 WDC Emulator
|
* P8000 WDC Emulator
|
||||||
*
|
*
|
||||||
* $Id: wdc_main.c,v 1.14 2012/06/06 23:10:31 olivleh1 Exp $
|
* $Id: wdc_main.c,v 1.15 2012/06/07 00:34:36 olivleh1 Exp $
|
||||||
*
|
*
|
||||||
* TODO: - Different Errorcodes in the MMC layer (use defines)
|
* TODO: - Different Errorcodes in the MMC layer (use defines)
|
||||||
* - errorchecking in several places
|
* - errorchecking in several places
|
||||||
|
|
@ -54,7 +54,6 @@ main ( void )
|
||||||
uint32_t blockno;
|
uint32_t blockno;
|
||||||
uint8_t errorcode;
|
uint8_t errorcode;
|
||||||
uint8_t i8;
|
uint8_t i8;
|
||||||
uint16_t i16;
|
|
||||||
#endif
|
#endif
|
||||||
atmega_setup();
|
atmega_setup();
|
||||||
|
|
||||||
|
|
@ -66,7 +65,7 @@ main ( void )
|
||||||
|
|
||||||
/* load Parameter Table into RAM if valid */
|
/* load Parameter Table into RAM if valid */
|
||||||
blockno = 0;
|
blockno = 0;
|
||||||
data_counter = 512;
|
data_counter = WDC_BLOCKLEN;
|
||||||
while ( wdc_read_sector ( blockno, data_buffer ) ) {
|
while ( wdc_read_sector ( blockno, data_buffer ) ) {
|
||||||
#if DEBUG >= 1
|
#if DEBUG >= 1
|
||||||
uart_puts_p ( PSTR ( "Block 0 of SD-Card not readable" ) );
|
uart_puts_p ( PSTR ( "Block 0 of SD-Card not readable" ) );
|
||||||
|
|
@ -114,18 +113,12 @@ main ( void )
|
||||||
, data_counter
|
, data_counter
|
||||||
);
|
);
|
||||||
errorcode = 1;
|
errorcode = 1;
|
||||||
if ( data_counter / 512 == 1 ) {
|
if ( data_counter == WDC_BLOCKLEN ) {
|
||||||
errorcode = wdc_write_sector ( blockno, data_buffer );
|
errorcode = wdc_write_sector ( blockno, data_buffer );
|
||||||
} else {
|
} else {
|
||||||
errorcode = wdc_write_multiblock ( blockno, data_buffer, data_counter / 512 );
|
errorcode = wdc_write_multiblock ( blockno, data_buffer, data_counter / WDC_BLOCKLEN );
|
||||||
}
|
}
|
||||||
/* check if this really works - this must be used if the card does not support multiblock-access (there are some)
|
|
||||||
for ( i16 = 0; i16 < data_counter; i16 += 512 ) {
|
|
||||||
errorcode = wdc_write_sector ( blockno, &data_buffer[i16] );
|
|
||||||
if ( errorcode ) break;
|
|
||||||
blockno++;
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
if ( errorcode )
|
if ( errorcode )
|
||||||
wdc_send_error();
|
wdc_send_error();
|
||||||
break;
|
break;
|
||||||
|
|
@ -136,18 +129,12 @@ main ( void )
|
||||||
blockno = wdc_p8kblock2sdblock ( ( ( uint32_t ) cmd_buffer[5] << 24 ) | ( ( uint32_t ) cmd_buffer[4] << 16 ) | ( ( uint16_t ) cmd_buffer[3] << 8 ) | cmd_buffer[2] );
|
blockno = wdc_p8kblock2sdblock ( ( ( uint32_t ) cmd_buffer[5] << 24 ) | ( ( uint32_t ) cmd_buffer[4] << 16 ) | ( ( uint16_t ) cmd_buffer[3] << 8 ) | cmd_buffer[2] );
|
||||||
|
|
||||||
errorcode = 1;
|
errorcode = 1;
|
||||||
if ( data_counter / 512 == 1 ) {
|
if ( data_counter == WDC_BLOCKLEN ) {
|
||||||
errorcode = wdc_read_sector ( blockno, data_buffer );
|
errorcode = wdc_read_sector ( blockno, data_buffer );
|
||||||
} else {
|
} else {
|
||||||
errorcode = wdc_read_multiblock ( blockno, data_buffer, data_counter / 512 );
|
errorcode = wdc_read_multiblock ( blockno, data_buffer, data_counter / WDC_BLOCKLEN );
|
||||||
}
|
}
|
||||||
/* check if this really works - this must be used if the card does not support multiblock-access (there are some)
|
|
||||||
for ( i16 = 0; i16 < data_counter; i16 += 512 ) {
|
|
||||||
errorcode = wdc_read_sector ( blockno, &data_buffer[i16] );
|
|
||||||
if ( errorcode ) break;
|
|
||||||
blockno++;
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
if ( errorcode ) {
|
if ( errorcode ) {
|
||||||
wdc_send_error();
|
wdc_send_error();
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -232,7 +219,7 @@ main ( void )
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case CMD_FMTBTT_TRACK:
|
case CMD_FMTBTT_TRACK:
|
||||||
data_counter = 512;
|
data_counter = WDC_BLOCKLEN;
|
||||||
|
|
||||||
memset ( &data_buffer[0], 0x00, data_counter );
|
memset ( &data_buffer[0], 0x00, data_counter );
|
||||||
blockno = wdc_sector2sdblock ( cmd_buffer[2] | ( cmd_buffer[3] << 8 )
|
blockno = wdc_sector2sdblock ( cmd_buffer[2] | ( cmd_buffer[3] << 8 )
|
||||||
|
|
@ -263,7 +250,7 @@ main ( void )
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case CMD_ST_PARBTT:
|
case CMD_ST_PARBTT:
|
||||||
data_counter = 512;
|
data_counter = WDC_BLOCKLEN;
|
||||||
|
|
||||||
blockno = 0;
|
blockno = 0;
|
||||||
wdc_read_par_table ( data_buffer
|
wdc_read_par_table ( data_buffer
|
||||||
|
|
@ -284,7 +271,7 @@ main ( void )
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case CMD_VER_TRACK:
|
case CMD_VER_TRACK:
|
||||||
data_counter = 512;
|
data_counter = WDC_BLOCKLEN;
|
||||||
|
|
||||||
blockno = wdc_sector2sdblock ( cmd_buffer[2] | ( cmd_buffer[3] << 8 )
|
blockno = wdc_sector2sdblock ( cmd_buffer[2] | ( cmd_buffer[3] << 8 )
|
||||||
, cmd_buffer[4]
|
, cmd_buffer[4]
|
||||||
|
|
@ -308,11 +295,13 @@ main ( void )
|
||||||
, cmd_buffer[5]
|
, cmd_buffer[5]
|
||||||
);
|
);
|
||||||
errorcode = 1;
|
errorcode = 1;
|
||||||
for ( i16 = 0; i16 < data_counter; i16 += 512 ) {
|
|
||||||
errorcode = wdc_read_sector ( blockno, &data_buffer[i16] );
|
if ( data_counter == WDC_BLOCKLEN ) {
|
||||||
if ( errorcode ) break;
|
errorcode = wdc_write_sector ( blockno, data_buffer );
|
||||||
blockno++;
|
} else {
|
||||||
|
errorcode = wdc_write_multiblock ( blockno, data_buffer, data_counter / WDC_BLOCKLEN );
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( errorcode )
|
if ( errorcode )
|
||||||
wdc_send_error();
|
wdc_send_error();
|
||||||
break;
|
break;
|
||||||
|
|
@ -372,7 +361,7 @@ void measure_performance()
|
||||||
uart_puts_p ( PSTR ( "Timer is initialized with a Prescaler 8" ) );
|
uart_puts_p ( PSTR ( "Timer is initialized with a Prescaler 8" ) );
|
||||||
uart_putc ( '\n' );
|
uart_putc ( '\n' );
|
||||||
|
|
||||||
uart_puts_p ( PSTR ( "Test Read 5000 512B-Blocks with Multiblock-Read (4KB Blocksize):" ) );
|
uart_puts_p ( PSTR ( "Test Read 5000 WDC_BLOCKLENB-Blocks with Multiblock-Read (4KB Blocksize):" ) );
|
||||||
uart_putc ( '\n' );
|
uart_putc ( '\n' );
|
||||||
|
|
||||||
for ( i8 = 0; i8 < nr_of_tests; i8++ ) {
|
for ( i8 = 0; i8 < nr_of_tests; i8++ ) {
|
||||||
|
|
@ -389,9 +378,9 @@ void measure_performance()
|
||||||
uart_putc ( '\n' );
|
uart_putc ( '\n' );
|
||||||
}
|
}
|
||||||
|
|
||||||
uart_puts_p ( PSTR ( "Test Write 5000 512B-Blocks with Multiblock-Write (4KB Blocksize):" ) );
|
uart_puts_p ( PSTR ( "Test Write 5000 WDC_BLOCKLENB-Blocks with Multiblock-Write (4KB Blocksize):" ) );
|
||||||
uart_putc ( '\n' );
|
uart_putc ( '\n' );
|
||||||
memset ( &data_buffer[0], 0xCC, 512 * numblocks );
|
memset ( &data_buffer[0], 0xCC, WDC_BLOCKLEN * numblocks );
|
||||||
for ( i8 = 0; i8 < nr_of_tests; i8++ ) {
|
for ( i8 = 0; i8 < nr_of_tests; i8++ ) {
|
||||||
blockno = BLOCKNO;
|
blockno = BLOCKNO;
|
||||||
for ( starttime = overflow; blockno < ( BLOCKNO + 5000 ); blockno += numblocks ) {
|
for ( starttime = overflow; blockno < ( BLOCKNO + 5000 ); blockno += numblocks ) {
|
||||||
|
|
@ -406,7 +395,7 @@ void measure_performance()
|
||||||
uart_putc ( '\n' );
|
uart_putc ( '\n' );
|
||||||
}
|
}
|
||||||
|
|
||||||
uart_puts_p ( PSTR ( "Test Read 5000 512B-Blocks with Singleblock-Read (512B Blocksize):" ) );
|
uart_puts_p ( PSTR ( "Test Read 5000 WDC_BLOCKLENB-Blocks with Singleblock-Read (WDC_BLOCKLENB Blocksize):" ) );
|
||||||
uart_putc ( '\n' );
|
uart_putc ( '\n' );
|
||||||
|
|
||||||
for ( i8 = 0; i8 < nr_of_tests; i8++ ) {
|
for ( i8 = 0; i8 < nr_of_tests; i8++ ) {
|
||||||
|
|
@ -423,9 +412,9 @@ void measure_performance()
|
||||||
uart_putc ( '\n' );
|
uart_putc ( '\n' );
|
||||||
}
|
}
|
||||||
|
|
||||||
uart_puts_p ( PSTR ( "Test Write 5000 512B-Blocks with Singleblock-Write (512B Blocksize):" ) );
|
uart_puts_p ( PSTR ( "Test Write 5000 WDC_BLOCKLENB-Blocks with Singleblock-Write (WDC_BLOCKLENB Blocksize):" ) );
|
||||||
uart_putc ( '\n' );
|
uart_putc ( '\n' );
|
||||||
memset ( &data_buffer[0], 0xCC, 512 * numblocks );
|
memset ( &data_buffer[0], 0xCC, WDC_BLOCKLEN * numblocks );
|
||||||
for ( i8 = 0; i8 < nr_of_tests; i8++ ) {
|
for ( i8 = 0; i8 < nr_of_tests; i8++ ) {
|
||||||
blockno = BLOCKNO;
|
blockno = BLOCKNO;
|
||||||
for ( starttime = overflow; blockno < ( BLOCKNO + 5000 ); blockno++ ) {
|
for ( starttime = overflow; blockno < ( BLOCKNO + 5000 ); blockno++ ) {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue