diff --git a/P8000_WDC_Emulator/P8000_WDC_Emulator/Debug/Makefile b/P8000_WDC_Emulator/P8000_WDC_Emulator/Debug/Makefile index 7437ee3..ad3c0c9 100755 --- a/P8000_WDC_Emulator/P8000_WDC_Emulator/Debug/Makefile +++ b/P8000_WDC_Emulator/P8000_WDC_Emulator/Debug/Makefile @@ -39,7 +39,7 @@ C_SRCS += \ ../wdc_drv_pata.c \ ../wdc_main.c \ ../wdc_drv_mmc.c \ -../wdc_drv_mmc_perf.c \ +../wdc_if_disk_perf.c \ ../uart.c \ ../wdc_if_p8000.c \ ../wdc_if_disk.c \ @@ -58,7 +58,7 @@ wdc_avr.o \ wdc_drv_pata.o \ wdc_main.o \ wdc_drv_mmc.o \ -wdc_drv_mmc_perf.o \ +wdc_if_disk_perf.o \ uart.o \ wdc_if_p8000.o \ wdc_if_disk.o \ @@ -71,7 +71,7 @@ wdc_avr.o \ wdc_drv_pata.o \ wdc_main.o \ wdc_drv_mmc.o \ -wdc_drv_mmc_perf.o \ +wdc_if_disk_perf.o \ uart.o \ wdc_if_p8000.o \ wdc_if_disk.o \ @@ -84,7 +84,7 @@ wdc_avr.d \ wdc_drv_pata.d \ wdc_main.d \ wdc_drv_mmc.d \ -wdc_drv_mmc_perf.d \ +wdc_if_disk_perf.d \ uart.d \ wdc_if_p8000.d \ wdc_if_disk.d \ @@ -97,7 +97,7 @@ wdc_avr.d \ wdc_drv_pata.d \ wdc_main.d \ wdc_drv_mmc.d \ -wdc_drv_mmc_perf.d \ +wdc_if_disk_perf.d \ uart.d \ wdc_if_p8000.d \ wdc_if_disk.d \ @@ -138,7 +138,7 @@ 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 - $(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=c99 -save-temps -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 -c -std=gnu99 -save-temps -MD -MP -MF "$(@:%.o=%.d)" -MT"$(@:%.o=%.d)" -MT"$(@:%.o=%.o)" -mmcu=atmega1284p -o"$@" "$<" @echo Finished building: $< diff --git a/P8000_WDC_Emulator/P8000_WDC_Emulator/Debug/makedep.mk b/P8000_WDC_Emulator/P8000_WDC_Emulator/Debug/makedep.mk index 879e2b8..6a3775d 100755 --- a/P8000_WDC_Emulator/P8000_WDC_Emulator/Debug/makedep.mk +++ b/P8000_WDC_Emulator/P8000_WDC_Emulator/Debug/makedep.mk @@ -10,7 +10,7 @@ wdc_main.c wdc_drv_mmc.c -wdc_drv_mmc_perf.c +wdc_if_disk_perf.c uart.c diff --git a/P8000_WDC_Emulator/P8000_WDC_Emulator/Hardware/P8000_WDC_Emulator.pdf b/P8000_WDC_Emulator/P8000_WDC_Emulator/Hardware/P8000_WDC_Emulator.pdf index ebd1b87..f0df6ee 100644 Binary files a/P8000_WDC_Emulator/P8000_WDC_Emulator/Hardware/P8000_WDC_Emulator.pdf and b/P8000_WDC_Emulator/P8000_WDC_Emulator/Hardware/P8000_WDC_Emulator.pdf differ diff --git a/P8000_WDC_Emulator/P8000_WDC_Emulator/Hardware/P8000_WDC_Emulator.sch b/P8000_WDC_Emulator/P8000_WDC_Emulator/Hardware/P8000_WDC_Emulator.sch index 98660f2..ee95129 100755 --- a/P8000_WDC_Emulator/P8000_WDC_Emulator/Hardware/P8000_WDC_Emulator.sch +++ b/P8000_WDC_Emulator/P8000_WDC_Emulator/Hardware/P8000_WDC_Emulator.sch @@ -174,7 +174,7 @@ T 67100 33100 9 8 1 0 0 0 1 T 68500 33100 9 8 1 0 0 0 1 1 T 71000 33400 9 7 1 0 0 0 1 -$Revision: 1.16 $ / $Date: 2012/06/16 10:49:19 $ +$Revision: 1.17 $ / $Date: 2012/06/16 19:34:40 $ T 71000 33100 9 8 1 0 0 0 1 Oliver Lehmann N 50600 59400 51200 59400 4 @@ -930,14 +930,14 @@ C 45100 50300 1 0 1 busripper-1.sym T 45100 50700 5 8 0 0 0 6 1 device=none T 45200 50400 5 10 1 1 0 0 1 -pinlabel=DA1 +pinlabel=DA2 } C 45100 50000 1 0 1 busripper-1.sym { T 45100 50400 5 8 0 0 0 6 1 device=none T 45200 50100 5 10 1 1 0 0 1 -pinlabel=DA2 +pinlabel=DA1 } C 45100 56300 1 0 1 busripper-1.sym { @@ -1179,7 +1179,7 @@ pinlabel=DA0 N 66000 39600 69800 39600 4 { T 66000 39700 5 10 1 1 0 0 1 -pinlabel=DA2 +pinlabel=DA1 } N 67500 41200 66000 41200 4 { @@ -1204,7 +1204,7 @@ pinlabel=\_CS1\_ N 62700 39200 64600 39200 4 { T 64600 39300 5 10 1 1 0 6 1 -pinlabel=DA1 +pinlabel=DA2 } N 64600 40400 63500 40400 4 { diff --git a/P8000_WDC_Emulator/P8000_WDC_Emulator/Makefile b/P8000_WDC_Emulator/P8000_WDC_Emulator/Makefile index 79f8fb7..46363c9 100644 --- a/P8000_WDC_Emulator/P8000_WDC_Emulator/Makefile +++ b/P8000_WDC_Emulator/P8000_WDC_Emulator/Makefile @@ -15,10 +15,11 @@ OBJS += \ wdc_avr.o \ wdc_main.o \ wdc_drv_mmc.o \ -wdc_drv_mmc_perf.o \ +wdc_drv_pata.o \ uart.o \ wdc_if_p8000.o \ wdc_if_disk.o \ +wdc_if_disk_perf.o \ wdc_par.o \ wdc_ram.o diff --git a/P8000_WDC_Emulator/P8000_WDC_Emulator/P8000_WDC_Emulator.cproj b/P8000_WDC_Emulator/P8000_WDC_Emulator/P8000_WDC_Emulator.cproj index 1bd8594..31527f4 100644 --- a/P8000_WDC_Emulator/P8000_WDC_Emulator/P8000_WDC_Emulator.cproj +++ b/P8000_WDC_Emulator/P8000_WDC_Emulator/P8000_WDC_Emulator.cproj @@ -54,12 +54,6 @@ True True True - True - True - True - True - True - -std=c99 True @@ -98,7 +92,7 @@ compile - + compile diff --git a/P8000_WDC_Emulator/P8000_WDC_Emulator/wdc_config.h b/P8000_WDC_Emulator/P8000_WDC_Emulator/wdc_config.h index 735f975..aabab43 100644 --- a/P8000_WDC_Emulator/P8000_WDC_Emulator/wdc_config.h +++ b/P8000_WDC_Emulator/P8000_WDC_Emulator/wdc_config.h @@ -26,7 +26,7 @@ */ /* - * $Id: wdc_config.h,v 1.16 2012/06/14 20:24:24 olivleh1 Exp $ + * $Id: wdc_config.h,v 1.17 2012/06/16 19:34:39 olivleh1 Exp $ */ @@ -107,8 +107,8 @@ #define PIN_ATACS_CS0 PINB0 #define PIN_ATACS_CS1 PINB1 #define PIN_ATADA_DA0 PIND2 -#define PIN_ATADA_DA1 PIND3 -#define PIN_ATADA_DA2 PIND4 +#define PIN_ATADA_DA1 PIND4 +#define PIN_ATADA_DA2 PIND3 /* * maximum performance with both turned off @@ -120,8 +120,8 @@ #define MMC_MULTIBLOCK 1 -#define MEASURE_SDCARD_TIME 1 -#undef MEASURE_SDCARD_TIME +#define MEASURE_DISK_PERFORMANCE 1 +#undef MEASURE_DISK_PERFORMANCE #define DEBUG 1 diff --git a/P8000_WDC_Emulator/P8000_WDC_Emulator/wdc_drv_pata.c b/P8000_WDC_Emulator/P8000_WDC_Emulator/wdc_drv_pata.c index b0ca22e..3d9f1b9 100644 --- a/P8000_WDC_Emulator/P8000_WDC_Emulator/wdc_drv_pata.c +++ b/P8000_WDC_Emulator/P8000_WDC_Emulator/wdc_drv_pata.c @@ -26,7 +26,7 @@ */ /* - * $Id: wdc_drv_pata.c,v 1.6 2012/06/16 08:39:01 olivleh1 Exp $ + * $Id: wdc_drv_pata.c,v 1.7 2012/06/16 19:34:39 olivleh1 Exp $ */ #include "wdc_config.h" @@ -56,11 +56,17 @@ void pata_read_bytes ( uint8_t *buffer, uint16_t bytes ); * ||+--- DA0 * |||+-- DA1 * ||||+- DA2 - * |||||*/ -#define PATA_RD_STATUS_REGISTER 0x0F /* 0b01111*/ -#define PATA_WR_COMMAND_REGISTER 0x0F /* 0b01111*/ -#define PATA_WR_DEVICE_CONTROL_REGISTER 0x0B /* 0b01011*/ -#define PATA_RD_DATA_REGISTER 0x08 /* 0b01000*/ + * ||||| */ +#define PATA_R_STATUS_REGISTER 0x0F /* 0b01111 */ +#define PATA_W_COMMAND_REGISTER 0x0F /* 0b01111 */ +#define PATA_W_DEVICE_CONTROL_REGISTER 0x0B /* 0b01011 */ + +#define PATA_RW_DATA_REGISTER 0x08 /* 0b01000 */ +#define PATA_RW_SECTOR_COUNT_REGISTER 0b00001010 +#define PATA_RW_SECTOR_NUMBER_REGISTER 0b00001110 +#define PATA_RW_CYLINDER_LOW_REGISTER 0b00001001 +#define PATA_RW_CYLINDER_HIGH_REGISTER 0b00001101 +#define PATA_RW_DEVICE_HEAD_REGISTER 0b00001011 #define ata_ctl_high() ata_cs0_disable();ata_cs1_disable();ata_da0_disable();ata_da1_disable();ata_da2_disable(); @@ -72,17 +78,17 @@ void pata_read_bytes ( uint8_t *buffer, uint16_t bytes ); uint8_t pata_rdy() { - return ( read_io_register ( PATA_RD_STATUS_REGISTER ) & ATA_STAT_RDY ) ? 1 : 0; + return ( read_io_register ( PATA_R_STATUS_REGISTER ) & ATA_STAT_RDY ) ? 1 : 0; } uint8_t pata_bsy() { - return ( read_io_register ( PATA_RD_STATUS_REGISTER ) & ATA_STAT_BSY ) ? 1 : 0; + return ( read_io_register ( PATA_R_STATUS_REGISTER ) & ATA_STAT_BSY ) ? 1 : 0; } uint8_t pata_drq() { - return ( read_io_register ( PATA_RD_STATUS_REGISTER ) & ATA_STAT_DRQ ) ? 1 : 0; + return ( read_io_register ( PATA_R_STATUS_REGISTER ) & ATA_STAT_DRQ ) ? 1 : 0; } void set_io_register ( uint8_t ioreg ) @@ -115,6 +121,7 @@ void pata_set_highbyte ( uint8_t byte ) enable_atalatch(); nop(); nop(); + nop(); disable_atalatch(); } @@ -172,21 +179,55 @@ void write_io_register ( uint8_t ioreg, uint8_t byte ) void pata_read_bytes ( uint8_t *buffer, uint16_t bytes ) { - uint8_t byte_l, byte_h; uint16_t i; + uint8_t blocks; configure_port_data_read(); - set_io_register ( PATA_RD_DATA_REGISTER ); - ata_rd_enable(); - for ( i = 0; i < bytes / 2; i++ ) { - byte_l = pata_get_lowbyte(); - byte_h = pata_get_highbyte(); - *buffer++ = byte_h; - *buffer++ = byte_l; + for ( blocks = bytes / PATA_BLOCKLEN ; blocks ; blocks-- ) { + /* Wait for BSY goes low and DRQ goes high */ + while ( pata_bsy() & !pata_drq() ); + + set_io_register ( PATA_RW_DATA_REGISTER ); + ata_rd_enable(); + + for ( i = 0; i < PATA_BLOCKLEN / 2; i++ ) { + *buffer++ = pata_get_lowbyte(); + *buffer++ = pata_get_highbyte(); + } + + ata_rd_disable(); + ata_ctl_high(); + } +} + + +void pata_write_bytes ( uint8_t *buffer, uint16_t bytes ) +{ + uint16_t i, a; + uint8_t blocks; + + a = 0; + for ( blocks = bytes / PATA_BLOCKLEN ; blocks ; blocks-- ) { + /* Wait for BSY goes low and DRQ goes high */ + while ( pata_bsy() & !pata_drq() ); + + configure_port_data_write(); + + set_io_register ( PATA_RW_DATA_REGISTER ); + ata_wr_enable(); + + for ( i = 0; i < PATA_BLOCKLEN / 2; i++ ) { + pata_set_highbyte ( buffer[a + 1] ); + pata_set_lowbyte ( buffer[a] ); + a += 2; + } + ata_wr_disable(); + ata_ctl_high(); + + configure_port_data_read(); + } - ata_rd_disable(); - ata_ctl_high(); } void ata_identify() @@ -195,16 +236,13 @@ void ata_identify() uint16_t word[256], n; while ( pata_bsy() ); - write_io_register ( PATA_WR_COMMAND_REGISTER, CMD_IDENTIFY_DEVICE ); - - /* Wait for BSY goes low and DRQ goes high */ - while ( pata_bsy() & !pata_drq() ); + write_io_register ( PATA_W_COMMAND_REGISTER, CMD_IDENTIFY_DEVICE ); pata_read_bytes ( buffer, 512 ); i = 0; for ( n = 0; n < 512; n += 2 ) { - word[i] = ( ( buffer[n] << 8 ) | buffer[n + 1] ); + word[i] = ( ( buffer[n + 1] << 8 ) | buffer[n] ); i++; } @@ -231,6 +269,8 @@ void ata_identify() uart_putc ( '\n' ); uart_puts_p ( PSTR ( "Model number: " ) ); for ( uint8_t i = 27; i <= 46; i++ ) { + uart_putc ( word[i] >> 8 ); + uart_putc ( word[i] & 0x00FF ); } uart_putc ( '\n' ); uart_puts_p ( PSTR ( "Number of current logical cylinders: " ) ); @@ -256,6 +296,7 @@ void ata_identify() * Public functions */ +uint8_t data2_buffer[4096]; uint8_t pata_init () { @@ -266,36 +307,58 @@ uint8_t pata_init () while ( ( !pata_rdy() ) & pata_bsy() ); /*set drive 0 to LBA mode*/ - write_io_register ( PATA_WR_DEVICE_CONTROL_REGISTER, ATA_LBA_DRIVE_0 ); + write_io_register ( PATA_W_DEVICE_CONTROL_REGISTER, ATA_LBA_DRIVE_0 ); while ( ( !pata_rdy() ) & pata_bsy() ); /*recalibrate*/ - write_io_register ( PATA_WR_COMMAND_REGISTER, CMD_RECALIBRATE ); + write_io_register ( PATA_W_COMMAND_REGISTER, CMD_RECALIBRATE ); while ( pata_bsy() ); uart_puts_p ( PSTR ( "disk is now ready\n" ) ); ata_identify(); - return 1; + return 0; } uint8_t pata_read_block ( uint32_t addr, uint8_t *buffer ) { - return 1; + return pata_read_multiblock ( addr, buffer, 1 ); } uint8_t pata_write_block ( uint32_t addr, uint8_t *buffer ) { - return 1; + return pata_write_multiblock ( addr, buffer, 1 ); } uint8_t pata_read_multiblock ( uint32_t addr, uint8_t *buffer, uint8_t numblocks ) { - return 1; + write_io_register ( PATA_RW_SECTOR_COUNT_REGISTER, numblocks ); + + write_io_register ( PATA_RW_SECTOR_NUMBER_REGISTER, ( uint8_t ) addr ); + write_io_register ( PATA_RW_CYLINDER_LOW_REGISTER, ( uint8_t ) ( addr >> 8 ) ); + write_io_register ( PATA_RW_CYLINDER_HIGH_REGISTER, ( uint8_t ) ( addr >> 16 ) ); + write_io_register ( PATA_RW_DEVICE_HEAD_REGISTER, ( ( uint8_t ) ( addr >> 24 ) & 0x0F ) | ATA_LBA_DRIVE_0 ); + + write_io_register ( PATA_W_COMMAND_REGISTER, CMD_READ_SECTORS ); + + pata_read_bytes ( buffer, numblocks * PATA_BLOCKLEN ); + + return 0; } uint8_t pata_write_multiblock ( uint32_t addr, uint8_t *buffer, uint8_t numblocks ) { - return 1; -} + write_io_register ( PATA_RW_SECTOR_COUNT_REGISTER, numblocks ); + + write_io_register ( PATA_RW_SECTOR_NUMBER_REGISTER, ( uint8_t ) addr ); + write_io_register ( PATA_RW_CYLINDER_LOW_REGISTER, ( uint8_t ) ( addr >> 8 ) ); + write_io_register ( PATA_RW_CYLINDER_HIGH_REGISTER, ( uint8_t ) ( addr >> 16 ) ); + write_io_register ( PATA_RW_DEVICE_HEAD_REGISTER, ( ( uint8_t ) ( addr >> 24 ) & 0x0F ) | ATA_LBA_DRIVE_0 ); + + write_io_register ( PATA_W_COMMAND_REGISTER, CMD_WRITE_SECTORS ); + + pata_write_bytes ( buffer, numblocks * PATA_BLOCKLEN ); + + return 0; +} \ No newline at end of file diff --git a/P8000_WDC_Emulator/P8000_WDC_Emulator/wdc_drv_pata.h b/P8000_WDC_Emulator/P8000_WDC_Emulator/wdc_drv_pata.h index a927a20..2bf3ac2 100644 --- a/P8000_WDC_Emulator/P8000_WDC_Emulator/wdc_drv_pata.h +++ b/P8000_WDC_Emulator/P8000_WDC_Emulator/wdc_drv_pata.h @@ -26,7 +26,7 @@ */ /* - * $Id: wdc_drv_pata.h,v 1.5 2012/06/16 00:33:26 olivleh1 Exp $ + * $Id: wdc_drv_pata.h,v 1.6 2012/06/16 19:34:39 olivleh1 Exp $ */ #ifndef WDC_DRV_PATA_H_ @@ -99,6 +99,8 @@ extern uint8_t pata_write_multiblock ( uint32_t addr, uint8_t *buffer, uint8_t n #define CMD_WRITE_SECTORS 0x30 #define CMD_WRITE_VERIFY 0x3C +#define PATA_BLOCKLEN 512 + // CB_DH bits 7-4 OF THE DEVICE/HEAD REGISTER #define ATA_DH_DEV0 0xE0 // select device 0 LBA MODE #define ATA_DH_DEV1 0xF0 // select device 1 LBA MODE diff --git a/P8000_WDC_Emulator/P8000_WDC_Emulator/wdc_if_disk_perf.c b/P8000_WDC_Emulator/P8000_WDC_Emulator/wdc_if_disk_perf.c index 7d72f10..2aa7c8a 100644 --- a/P8000_WDC_Emulator/P8000_WDC_Emulator/wdc_if_disk_perf.c +++ b/P8000_WDC_Emulator/P8000_WDC_Emulator/wdc_if_disk_perf.c @@ -26,7 +26,7 @@ */ /* - * $Id: wdc_if_disk_perf.c,v 1.5 2012/06/12 17:34:14 olivleh1 Exp $ + * $Id: wdc_if_disk_perf.c,v 1.6 2012/06/16 19:34:39 olivleh1 Exp $ */ #include @@ -41,7 +41,7 @@ #include "wdc_ram.h" #include "uart.h" -#ifdef MEASURE_SDCARD_TIME +#ifdef MEASURE_DISK_PERFORMANCE #define BLOCKNO 300000 extern uint32_t overflow; diff --git a/P8000_WDC_Emulator/P8000_WDC_Emulator/wdc_main.c b/P8000_WDC_Emulator/P8000_WDC_Emulator/wdc_main.c index 7ba394a..e78a0cd 100644 --- a/P8000_WDC_Emulator/P8000_WDC_Emulator/wdc_main.c +++ b/P8000_WDC_Emulator/P8000_WDC_Emulator/wdc_main.c @@ -29,7 +29,7 @@ /* * P8000 WDC Emulator * - * $Id: wdc_main.c,v 1.28 2012/06/13 20:17:45 olivleh1 Exp $ + * $Id: wdc_main.c,v 1.29 2012/06/16 19:34:39 olivleh1 Exp $ * * TODO: - right now, BTT entries are not taken into account */ @@ -54,7 +54,7 @@ void atmega_setup ( void ); -#ifdef MEASURE_SDCARD_TIME +#ifdef MEASURE_DISK_PERFORMANCE extern void measure_performance(); volatile uint32_t overflow = 0; ISR ( TIMER0_OVF_vect ) @@ -74,7 +74,7 @@ extern uint8_t valid_disk; int __attribute__ ( ( OS_main ) ) main ( void ) { -#ifndef MEASURE_SDCARD_TIME +#ifndef MEASURE_DISK_PERFORMANCE uint16_t cmd_counter = 9; uint16_t data_counter; uint32_t blockno; @@ -85,7 +85,7 @@ main ( void ) uart_puts_p ( PSTR ( "P8000 WDC Emulator 0.90\n" ) ); -#ifdef MEASURE_SDCARD_TIME +#ifdef MEASURE_DISK_PERFORMANCE measure_performance(); #else