diff --git a/P8000_WDC_Emulator/P8000_WDC_Emulator/Debug/Makefile b/P8000_WDC_Emulator/P8000_WDC_Emulator/Debug/Makefile
index 83e1a91..ef86d7a 100755
--- a/P8000_WDC_Emulator/P8000_WDC_Emulator/Debug/Makefile
+++ b/P8000_WDC_Emulator/P8000_WDC_Emulator/Debug/Makefile
@@ -82,7 +82,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 -fpack-struct -fshort-enums -g2 -Wall -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 -fpack-struct -fshort-enums -g2 -Wall -Werror -pedantic -pedantic-errors -c -std=gnu99 -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/Hardware/fuses.txt b/P8000_WDC_Emulator/P8000_WDC_Emulator/Hardware/fuses.txt
new file mode 100755
index 0000000..0c0ea83
--- /dev/null
+++ b/P8000_WDC_Emulator/P8000_WDC_Emulator/Hardware/fuses.txt
@@ -0,0 +1,15 @@
+BODLEVEL = 4V3
+OCDEN = [ ]
+JTAGEN = [ ]
+SPIEN = [X]
+WDTON = [ ]
+EESAVE = [ ]
+BOOTSZ = 4096W_F000
+BOOTRST = [ ]
+CKDIV8 = [ ]
+CKOUT = [ ]
+SUT_CKSEL = FSOSC_16KCK_65MS_XOSC_SLOWPWR
+
+EXTENDED = 0xFC (valid)
+HIGH = 0xD9 (valid)
+LOW = 0xF7 (valid)
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 8259f5e..029362b 100644
--- a/P8000_WDC_Emulator/P8000_WDC_Emulator/P8000_WDC_Emulator.cproj
+++ b/P8000_WDC_Emulator/P8000_WDC_Emulator/P8000_WDC_Emulator.cproj
@@ -25,21 +25,21 @@
- True
- True
- True
- True
- True
- Optimize for size (-Os)
- True
- True
- True
-
-
- m
-
-
-
+ True
+ True
+ True
+ True
+ True
+ Optimize for size (-Os)
+ True
+ True
+ True
+
+
+ m
+
+
+
@@ -55,6 +55,9 @@
True
Default (-g2)
True
+ True
+ True
+ True
m
diff --git a/P8000_WDC_Emulator/P8000_WDC_Emulator/uart.c b/P8000_WDC_Emulator/P8000_WDC_Emulator/uart.c
index 6e58225..c0baf9c 100644
--- a/P8000_WDC_Emulator/P8000_WDC_Emulator/uart.c
+++ b/P8000_WDC_Emulator/P8000_WDC_Emulator/uart.c
@@ -14,6 +14,7 @@
#include
#include "uart.h"
+#include "config.h"
/* some mcus have multiple uarts */
#ifdef UDR0
@@ -58,9 +59,7 @@
#endif
#define BAUD 9600UL
-#warning "CPU frequency hardcoded here"
-#define UBRRVAL (18432000UL/(BAUD*16)-1)
-/*define UBRRVAL (2304000UL/(BAUD*16)-1) mit 8er Teiler */
+#define UBRRVAL (CPU_FREQ/(BAUD*16)-1)
#define USE_SLEEP 1
void uart_init()
diff --git a/P8000_WDC_Emulator/P8000_WDC_Emulator/wdc_config.h b/P8000_WDC_Emulator/P8000_WDC_Emulator/wdc_config.h
index e21b0e5..f193166 100644
--- a/P8000_WDC_Emulator/P8000_WDC_Emulator/wdc_config.h
+++ b/P8000_WDC_Emulator/P8000_WDC_Emulator/wdc_config.h
@@ -1,7 +1,7 @@
/*
* P8000 WDC Emulator
*
- * $Id: wdc_config.h,v 1.2 2012/05/29 20:23:09 olivleh1 Exp $
+ * $Id: wdc_config.h,v 1.3 2012/05/30 16:41:00 olivleh1 Exp $
*
*/
@@ -9,6 +9,8 @@
#ifndef CONFIG_H_
#define CONFIG_H_
+#define CPU_FREQ 18432000UL
+
#define PORT_DATA PORTA
#define PIN_DATA PINA
#define DDR_DATA DDRA
diff --git a/P8000_WDC_Emulator/P8000_WDC_Emulator/wdc_main.c b/P8000_WDC_Emulator/P8000_WDC_Emulator/wdc_main.c
index ad104a1..ad8f12a 100644
--- a/P8000_WDC_Emulator/P8000_WDC_Emulator/wdc_main.c
+++ b/P8000_WDC_Emulator/P8000_WDC_Emulator/wdc_main.c
@@ -1,7 +1,7 @@
/*
* P8000 WDC Emulator
*
- * $Id: wdc_main.c,v 1.2 2012/05/29 20:23:09 olivleh1 Exp $
+ * $Id: wdc_main.c,v 1.3 2012/05/30 16:41:00 olivleh1 Exp $
*
*/
@@ -11,8 +11,9 @@
#include
#include
#include
-#include "uart.h"
+#include "config.h"
#include "main.h"
+#include "uart.h"
void atmega_setup(void);
@@ -20,10 +21,14 @@ int main(void)
{
uint8_t cmdbuffer[9];
uint8_t cmdcnt;
+ uint8_t buffer[9];
+ uint8_t datacnt;
+ uint16_t data_counter;
+ uint16_t data_address;
atmega_setup();
- uart_puts_p(PSTR("P8000 WDC Emulator 1.0\n"));
+ uart_puts_p(PSTR("P8000 WDC Emulator 0.01\n"));
while(1)
{
@@ -49,8 +54,105 @@ int main(void)
while ( !isset_info_wdardy() );
cmdcnt++;
}
-
- uart_puts_p(PSTR("CMD Buffer:"));
+ port_info_set( INFO_CLEAR );
+
+ switch( cmdbuffer[0] )
+ {
+ case CMD_WR_WDC_RAM:
+
+ for(data_counter=1000;data_counter>0;data_counter--) asm("nop");
+
+ data_counter = (cmdbuffer[7]<<8)|cmdbuffer[6];
+
+ configure_port_data_read();
+ datacnt = 0;
+ port_info_set( INFO_STAT_RDATA );
+ while ( !isset_info_te() );
+ while ( !isset_info_wdardy() );
+ while ( datacnt < data_counter )
+ {
+ while ( isset_info_wdardy() );
+ port_info_set( INFO_ASTB | INFO_STAT_RDATA );
+ buffer[datacnt] = port_data_get();
+ port_info_set( INFO_STAT_RDATA );
+ while ( !isset_info_wdardy() );
+
+ datacnt++;
+ }
+
+ port_info_set( INFO_CLEAR );
+
+ data_address = convert_ram_address((cmdbuffer[2]<<8)+cmdbuffer[1]);
+ do
+ {
+ data_counter--;
+ wdc_ram[data_address+data_counter] = buffer[+data_counter];
+ } while (data_counter > 0);
+
+ uart_puts_p(PSTR("DATA Buffer:"));
+ uart_putc_hex(wdc_ram[data_address+0]);
+ uart_putc_hex(wdc_ram[data_address+1]);
+ break;
+
+ case CMD_RD_WDC_RAM:
+
+ data_counter = (cmdbuffer[7]<<8)|cmdbuffer[6];
+ data_address = convert_ram_address((cmdbuffer[2]<<8)+cmdbuffer[1]);
+ do
+ {
+ data_counter--;
+ buffer[+data_counter] = wdc_ram[data_address+data_counter];
+ } while (data_counter > 0);
+
+ for(data_counter=1000;data_counter>0;data_counter--) asm("nop");
+
+ data_counter = (cmdbuffer[7]<<8)|cmdbuffer[6];
+ datacnt = 0;
+
+ port_info_set( INFO_TR |INFO_STAT_WDATA );
+ while ( isset_info_te() );
+ configure_port_data_write();
+ while ( !isset_info_wdardy() );
+ while ( datacnt < data_counter )
+ {
+ while ( isset_info_wdardy() );
+ port_info_set( INFO_TR | INFO_ASTB | INFO_STAT_WDATA );
+ port_data_set(buffer[datacnt]);
+ port_info_set( INFO_TR |INFO_STAT_WDATA );
+ while ( !isset_info_wdardy() );
+
+ datacnt++;
+ }
+ while ( isset_info_wdardy() );
+ port_info_set( INFO_TR | INFO_ASTB | INFO_STAT_WDATA );
+ asm("nop");
+ port_info_set( INFO_TR |INFO_STAT_WDATA );
+ configure_port_data_read();
+ port_info_set( INFO_CLEAR );
+ break;
+ default:
+ for(data_counter=1000;data_counter>0;data_counter--) asm("nop");
+ port_info_set( INFO_TR | INFO_STAT_ERROR );
+ while ( isset_info_te() );
+ configure_port_data_write();
+ while ( !isset_info_wdardy() );
+ while ( isset_info_wdardy() );
+ port_info_set( INFO_TR | INFO_ASTB | INFO_STAT_ERROR );
+ port_data_set(0x01);
+ port_info_set( INFO_TR | INFO_STAT_ERROR );
+ while ( !isset_info_wdardy() );
+ while ( isset_info_wdardy() );
+ port_info_set( INFO_TR | INFO_ASTB | INFO_STAT_ERROR );
+ asm("nop");
+ asm("nop");
+ port_info_set( INFO_TR | INFO_STAT_ERROR );
+ configure_port_data_read();
+ while ( !isset_info_wdardy() );
+ port_info_set( INFO_CLEAR );
+ break;
+ }
+
+ uart_puts_p(PSTR(" CMD Buffer:"));
uart_putc_hex(cmdbuffer[0]);
uart_putc_hex(cmdbuffer[1]);
uart_putc_hex(cmdbuffer[2]);
@@ -61,6 +163,7 @@ int main(void)
uart_putc_hex(cmdbuffer[7]);
uart_putc_hex(cmdbuffer[8]);
uart_putc('\n');
+
}
return 0;
}
diff --git a/P8000_WDC_Emulator/P8000_WDC_Emulator/wdc_main.h b/P8000_WDC_Emulator/P8000_WDC_Emulator/wdc_main.h
index 4a4c492..c05fc79 100644
--- a/P8000_WDC_Emulator/P8000_WDC_Emulator/wdc_main.h
+++ b/P8000_WDC_Emulator/P8000_WDC_Emulator/wdc_main.h
@@ -1,7 +1,7 @@
/*
* P8000 WDC Emulator
*
- * $Id: wdc_main.h,v 1.3 2012/05/29 20:23:59 olivleh1 Exp $
+ * $Id: wdc_main.h,v 1.4 2012/05/30 16:41:00 olivleh1 Exp $
*
*/
@@ -9,9 +9,6 @@
#ifndef MAIN_H_
#define MAIN_H_
-#include "config.h"
-
-
#define configure_port_data_read() DDR_DATA = 0x00 /* programs the DATA-Port as Input-only for reading from the P8000*/
#define configure_port_data_write() DDR_DATA = 0xff /* programs the DATA-Port as Out-only for writing to the P8000*/
@@ -43,5 +40,12 @@
#define INFO_STAT_RDATA (1 << PIN_INFO_STATUS1) /* 0x02 */
#define INFO_STAT_WDATA ((1 << PIN_INFO_STATUS0) | (1 << PIN_INFO_STATUS1)) /* 0x03 */
#define INFO_STAT_ERROR ((1 << PIN_INFO_STATUS0) | (1 << PIN_INFO_STATUS1) | (1 << PIN_INFO_STATUS2)) /* 0x07 */
+#define INFO_TR 0x40
+#define CMD_WR_WDC_RAM 0x18 /* P8000 Command: write data to WDC RAM */
+#define CMD_RD_WDC_RAM 0x08 /* P8000 Command: read data from WDC RAM */
+
+unsigned char wdc_ram[2048];
+#define convert_ram_address(x) ((x) - 0x2000) /* The S-RAM of the original WDC hardware starts at 0x2000.
+ We use an array as RAM here and no direct RAM access */
#endif /* MAIN_H_ */