add some waits for the sd-card to be ready and remove some other

put the performance measuring in another C-File
This commit is contained in:
Oliver Lehmann 2012-06-07 20:25:46 +00:00
parent 30dbd18ad6
commit e2fda1fd0d
6 changed files with 73 additions and 149 deletions

View File

@ -37,6 +37,7 @@ SUBDIRS :=
C_SRCS += \
../main.c \
../mmc.c \
../mmc_perf.c \
../uart.c \
../wdc_if_pio.c \
../wdc_if_sdcard.c \
@ -53,6 +54,7 @@ ASM_SRCS +=
OBJS += \
main.o \
mmc.o \
mmc_perf.o \
uart.o \
wdc_if_pio.o \
wdc_if_sdcard.o \
@ -63,6 +65,7 @@ wdc_ram.o
OBJS_AS_ARGS += \
main.o \
mmc.o \
mmc_perf.o \
uart.o \
wdc_if_pio.o \
wdc_if_sdcard.o \
@ -73,6 +76,7 @@ wdc_ram.o
C_DEPS += \
main.d \
mmc.d \
mmc_perf.d \
uart.d \
wdc_if_pio.d \
wdc_if_sdcard.d \
@ -83,6 +87,7 @@ wdc_ram.d
C_DEPS_AS_ARGS += \
main.d \
mmc.d \
mmc_perf.d \
uart.d \
wdc_if_pio.d \
wdc_if_sdcard.d \
@ -114,6 +119,8 @@ OUTPUT_FILE_DEP:= ./makedep.mk
./%.o: .././%.c
@echo Building file: $<
@echo Invoking: AVR/GNU C Compiler : (AVR_8_bit_GNU_Toolchain_3.4.0_663) 4.6.2

View File

@ -6,6 +6,8 @@ main.c
mmc.c
mmc_perf.c
uart.c
wdc_if_pio.c

View File

@ -45,30 +45,30 @@
<PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
<ToolchainSettings>
<AvrGcc>
<avrgcc.common.outputfiles.hex>True</avrgcc.common.outputfiles.hex>
<avrgcc.common.outputfiles.lss>True</avrgcc.common.outputfiles.lss>
<avrgcc.common.outputfiles.eep>True</avrgcc.common.outputfiles.eep>
<avrgcc.compiler.general.ChangeDefaultCharTypeUnsigned>True</avrgcc.compiler.general.ChangeDefaultCharTypeUnsigned>
<avrgcc.compiler.general.ChangeDefaultBitFieldUnsigned>True</avrgcc.compiler.general.ChangeDefaultBitFieldUnsigned>
<avrgcc.compiler.optimization.level>Optimize (-O1)</avrgcc.compiler.optimization.level>
<avrgcc.compiler.optimization.PrepareFunctionsForGarbageCollection>True</avrgcc.compiler.optimization.PrepareFunctionsForGarbageCollection>
<avrgcc.compiler.optimization.PackStructureMembers>True</avrgcc.compiler.optimization.PackStructureMembers>
<avrgcc.compiler.optimization.AllocateBytesNeededForEnum>True</avrgcc.compiler.optimization.AllocateBytesNeededForEnum>
<avrgcc.compiler.warnings.AllWarnings>True</avrgcc.compiler.warnings.AllWarnings>
<avrgcc.compiler.warnings.Undefined>True</avrgcc.compiler.warnings.Undefined>
<avrgcc.compiler.warnings.WarningsAsErrors>True</avrgcc.compiler.warnings.WarningsAsErrors>
<avrgcc.compiler.warnings.Pedantic>True</avrgcc.compiler.warnings.Pedantic>
<avrgcc.compiler.warnings.PedanticWarningsAsErrors>True</avrgcc.compiler.warnings.PedanticWarningsAsErrors>
<avrgcc.compiler.miscellaneous.OtherFlags>-std=c99</avrgcc.compiler.miscellaneous.OtherFlags>
<avrgcc.compiler.miscellaneous.DoNotDeleteTemporaryFiles>True</avrgcc.compiler.miscellaneous.DoNotDeleteTemporaryFiles>
<avrgcc.linker.libraries.Libraries>
<ListValues>
<Value>m</Value>
</ListValues>
</avrgcc.linker.libraries.Libraries>
<avrgcc.linker.optimization.GarbageCollectUnusedSections>True</avrgcc.linker.optimization.GarbageCollectUnusedSections>
<avrgcc.linker.optimization.RelaxBranches>True</avrgcc.linker.optimization.RelaxBranches>
</AvrGcc>
<avrgcc.common.outputfiles.hex>True</avrgcc.common.outputfiles.hex>
<avrgcc.common.outputfiles.lss>True</avrgcc.common.outputfiles.lss>
<avrgcc.common.outputfiles.eep>True</avrgcc.common.outputfiles.eep>
<avrgcc.compiler.general.ChangeDefaultCharTypeUnsigned>True</avrgcc.compiler.general.ChangeDefaultCharTypeUnsigned>
<avrgcc.compiler.general.ChangeDefaultBitFieldUnsigned>True</avrgcc.compiler.general.ChangeDefaultBitFieldUnsigned>
<avrgcc.compiler.optimization.level>Optimize (-O1)</avrgcc.compiler.optimization.level>
<avrgcc.compiler.optimization.PrepareFunctionsForGarbageCollection>True</avrgcc.compiler.optimization.PrepareFunctionsForGarbageCollection>
<avrgcc.compiler.optimization.PackStructureMembers>True</avrgcc.compiler.optimization.PackStructureMembers>
<avrgcc.compiler.optimization.AllocateBytesNeededForEnum>True</avrgcc.compiler.optimization.AllocateBytesNeededForEnum>
<avrgcc.compiler.warnings.AllWarnings>True</avrgcc.compiler.warnings.AllWarnings>
<avrgcc.compiler.warnings.Undefined>True</avrgcc.compiler.warnings.Undefined>
<avrgcc.compiler.warnings.WarningsAsErrors>True</avrgcc.compiler.warnings.WarningsAsErrors>
<avrgcc.compiler.warnings.Pedantic>True</avrgcc.compiler.warnings.Pedantic>
<avrgcc.compiler.warnings.PedanticWarningsAsErrors>True</avrgcc.compiler.warnings.PedanticWarningsAsErrors>
<avrgcc.compiler.miscellaneous.OtherFlags>-std=c99</avrgcc.compiler.miscellaneous.OtherFlags>
<avrgcc.compiler.miscellaneous.DoNotDeleteTemporaryFiles>True</avrgcc.compiler.miscellaneous.DoNotDeleteTemporaryFiles>
<avrgcc.linker.libraries.Libraries>
<ListValues>
<Value>m</Value>
</ListValues>
</avrgcc.linker.libraries.Libraries>
<avrgcc.linker.optimization.GarbageCollectUnusedSections>True</avrgcc.linker.optimization.GarbageCollectUnusedSections>
<avrgcc.linker.optimization.RelaxBranches>True</avrgcc.linker.optimization.RelaxBranches>
</AvrGcc>
</ToolchainSettings>
</PropertyGroup>
<ItemGroup>
@ -87,6 +87,9 @@
<Compile Include="mmc.h">
<SubType>compile</SubType>
</Compile>
<Compile Include="mmc_perf.c">
<SubType>compile</SubType>
</Compile>
<Compile Include="uart.c">
<SubType>compile</SubType>
</Compile>

View File

@ -26,7 +26,7 @@
*/
/*
* $Id: wdc_config.h,v 1.8 2012/06/07 18:01:02 olivleh1 Exp $
* $Id: wdc_config.h,v 1.9 2012/06/07 20:25:46 olivleh1 Exp $
*/
@ -77,4 +77,8 @@
#define MMC_MULTIBLOCK 1
#undef MEASURE_SDCARD_TIME
#define MEASURE_SDCARD_TIME 1
#endif /* CONFIG_H_ */

View File

@ -26,7 +26,7 @@
*/
/*
* $Id: wdc_drv_mmc.c,v 1.11 2012/06/07 18:38:08 olivleh1 Exp $
* $Id: wdc_drv_mmc.c,v 1.12 2012/06/07 20:25:46 olivleh1 Exp $
*/
#include <avr/io.h>
@ -340,12 +340,13 @@ 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 )
{
uint16_t i = 1;
uint8_t by;
#ifdef SPI_CRC
uint16_t crc;
#endif
MMC_Enable();
// wait_till_card_ready();
//wait_till_card_ready();
/* send command */
if ( mmc_cmd ( cmd ) != 0 ) {
@ -362,32 +363,34 @@ uint8_t mmc_read_block ( uint8_t *cmd, uint8_t *buffer, uint16_t bytes )
/* read first byte */
send_dummy_byte();
*buffer = recv_byte();
by = recv_byte();
xmit_byte ( 0xff );
/* read the remaining 511 bytes */
do {
xmit_byte ( 0xff ); /* send dummy byte */
buffer++;
wait_till_send_done();
*buffer = recv_byte();
*buffer++ = by;
i++;
wait_till_send_done();
by = recv_byte();
xmit_byte ( 0xff );
} while ( i<bytes );
/* handle CRC */
#ifdef SPI_CRC
buffer = buffer - ( bytes - 1 );
send_dummy_byte();
crc = recv_byte() << 8;
send_dummy_byte();
crc |= recv_byte();
*buffer = by;
/* handle CRC */
wait_till_send_done();
#ifdef SPI_CRC
crc = recv_byte() << 8;
xmit_byte ( 0xff );
buffer = buffer - (bytes-1);
wait_till_send_done();
crc |= recv_byte();
if ( crc != crc16 ( buffer, bytes ) ) {
MMC_Disable();
return ( 1 );
return ( 3 );
}
#else
send_dummy_byte();
send_dummy_byte();
#endif
MMC_Disable();
@ -426,7 +429,7 @@ uint8_t mmc_read_multiblock ( uint32_t addr, uint8_t *buffer, uint8_t numblocks
#endif
MMC_Enable();
wait_till_card_ready();
// wait_till_card_ready();
#ifdef MMC_MULTIBLOCK
#ifdef MMC_PRESET_MULTIBLOCKCOUNT
@ -518,7 +521,7 @@ uint8_t mmc_read_multiblock ( uint32_t addr, uint8_t *buffer, uint8_t numblocks
crc |= recv_byte();
if ( crc != crc16 ( buffer, MMC_BLOCKLEN ) ) {
MMC_Disable();
return ( 1 );
return ( 3 );
}
buffer = buffer + MMC_BLOCKLEN;
#else
@ -548,6 +551,7 @@ uint8_t mmc_read_multiblock ( uint32_t addr, uint8_t *buffer, uint8_t numblocks
/* Pad 8 */
send_dummy_byte();
#endif
MMC_Disable()
return ( 0 );
@ -567,7 +571,6 @@ uint8_t mmc_write_multiblock ( uint32_t addr, uint8_t *buffer, uint8_t numblocks
MMC_Enable();
wait_till_card_ready();
#ifdef MMC_MULTIBLOCK
#ifdef MMC_PRESET_MULTIBLOCKCOUNT
@ -690,8 +693,6 @@ uint8_t mmc_write_multiblock ( uint32_t addr, uint8_t *buffer, uint8_t numblocks
/* Pad 8 */
send_dummy_byte();
wait_till_card_ready();
#endif
MMC_Disable();

View File

@ -29,7 +29,7 @@
/*
* P8000 WDC Emulator
*
* $Id: wdc_main.c,v 1.19 2012/06/07 18:38:08 olivleh1 Exp $
* $Id: wdc_main.c,v 1.20 2012/06/07 20:25:46 olivleh1 Exp $
*
* TODO: - Different Errorcodes in the MMC layer (use defines)
* - errorchecking in several places
@ -54,24 +54,23 @@
#include "wdc_par.h"
#include "wdc_if_pio.h"
#include "wdc_if_sdcard.h"
#include "config.h"
#define DEBUG 1
#undef MEASURE_SDCARD_TIME
#define MEASURE_SDCARD_TIME 1
/* switched from local to global for keeping an eye on memory usage */
uint8_t data_buffer[4096];
uint8_t cmd_buffer[9];
void atmega_setup ( void );
#ifdef MEASURE_SDCARD_TIME
void measure_performance();
extern void measure_performance();
volatile uint32_t overflow = 0;
ISR ( TIMER0_OVF_vect )
{
overflow ++;
}
#else
/* switched from local to global for keeping an eye on memory usage */
uint8_t data_buffer[4096];
uint8_t cmd_buffer[9];
#endif
int __attribute__ ( ( OS_main ) )
@ -326,9 +325,9 @@ main ( void )
errorcode = 1;
if ( data_counter == WDC_BLOCKLEN ) {
errorcode = wdc_write_sector ( blockno, data_buffer );
errorcode = wdc_write_sector ( blockno, data_buffer );
} else {
errorcode = wdc_write_multiblock ( blockno, data_buffer, data_counter / WDC_BLOCKLEN );
errorcode = wdc_write_multiblock ( blockno, data_buffer, data_counter / WDC_BLOCKLEN );
}
if ( errorcode )
@ -369,95 +368,3 @@ void atmega_setup ( void )
}
}
#ifdef MEASURE_SDCARD_TIME
void measure_performance()
{
uint32_t starttime;
uint32_t blockno = 0;
// uint8_t numblocks = 4;
uint8_t i8, errorcode;
uint8_t nr_of_tests = 5;
#define BLOCKNO 355000
sei();
TIMSK0 |= ( 0x01 << TOIE0 );
TCCR0B = ( 1 << CS01 ); /* Prescaler 8 */
TCNT0 = 0x00;
uart_puts_p ( PSTR ( "Performance Measurement. Displayed are the Timer-Overflows." ) );
uart_putc ( '\n' );
uart_puts_p ( PSTR ( "Timer is initialized with a Prescaler 8" ) );
uart_putc ( '\n' );
#ifdef FOO
uart_puts_p ( PSTR ( "Test Read 5000 WDC_BLOCKLENB-Blocks with Multiblock-Read (4KB Blocksize):" ) );
uart_putc ( '\n' );
for ( i8 = 0; i8 < nr_of_tests; i8++ ) {
blockno = BLOCKNO;
for ( starttime = overflow; blockno < ( BLOCKNO + 5000 ); blockno += numblocks ) {
errorcode = wdc_read_multiblock ( blockno, data_buffer, numblocks );
if ( errorcode ) {
break;
}
}
if ( errorcode )
break;
uart_putdw_dec ( overflow - starttime );
uart_putc ( '\n' );
}
uart_puts_p ( PSTR ( "Test Write 5000 WDC_BLOCKLENB-Blocks with Multiblock-Write (4KB Blocksize):" ) );
uart_putc ( '\n' );
memset ( &data_buffer[0], 0xCC, WDC_BLOCKLEN * numblocks );
for ( i8 = 0; i8 < nr_of_tests; i8++ ) {
blockno = BLOCKNO;
for ( starttime = overflow; blockno < ( BLOCKNO + 5000 ); blockno += numblocks ) {
errorcode = wdc_write_multiblock ( blockno, data_buffer, numblocks );
if ( errorcode ) {
break;
}
}
if ( errorcode )
break;
uart_putdw_dec ( overflow - starttime );
uart_putc ( '\n' );
}
#endif
uart_puts_p ( PSTR ( "Test Read 5000 WDC_BLOCKLENB-Blocks with Singleblock-Read (WDC_BLOCKLENB Blocksize):" ) );
uart_putc ( '\n' );
for ( i8 = 0; i8 < nr_of_tests; i8++ ) {
blockno = BLOCKNO;
for ( starttime = overflow; blockno < ( BLOCKNO + 5000 ); blockno++ ) {
errorcode = wdc_read_sector ( blockno, data_buffer );
if ( errorcode ) {
break;
}
}
if ( errorcode )
break;
uart_putdw_dec ( overflow - starttime );
uart_putc ( '\n' );
}
#ifdef FOO
uart_puts_p ( PSTR ( "Test Write 5000 WDC_BLOCKLENB-Blocks with Singleblock-Write (WDC_BLOCKLENB Blocksize):" ) );
uart_putc ( '\n' );
memset ( &data_buffer[0], 0xCC, WDC_BLOCKLEN * numblocks );
for ( i8 = 0; i8 < nr_of_tests; i8++ ) {
blockno = BLOCKNO;
for ( starttime = overflow; blockno < ( BLOCKNO + 5000 ); blockno++ ) {
errorcode = wdc_write_sector ( blockno, data_buffer );
if ( errorcode ) {
break;
}
}
if ( errorcode )
break;
uart_putdw_dec ( overflow - starttime );
uart_putc ( '\n' );
}
#endif
while ( 1 );
}
#endif