diff --git a/P8000_WDC_Emulator/P8000_WDC_Emulator.atsln b/P8000_WDC_Emulator/P8000_WDC_Emulator.atsln new file mode 100755 index 0000000..43bdeb7 --- /dev/null +++ b/P8000_WDC_Emulator/P8000_WDC_Emulator.atsln @@ -0,0 +1,20 @@ + +Microsoft Visual Studio Solution File, Format Version 11.00 +# Atmel Studio Solution File, Format Version 11.00 +Project("{54F91283-7BC4-4236-8FF9-10F437C3AD48}") = "P8000_WDC_Emulator", "P8000_WDC_Emulator\P8000_WDC_Emulator.cproj", "{257C9A83-A686-455C-AC90-D649B30AA14D}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|AVR = Debug|AVR + Release|AVR = Release|AVR + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {257C9A83-A686-455C-AC90-D649B30AA14D}.Debug|AVR.ActiveCfg = Debug|AVR + {257C9A83-A686-455C-AC90-D649B30AA14D}.Debug|AVR.Build.0 = Debug|AVR + {257C9A83-A686-455C-AC90-D649B30AA14D}.Release|AVR.ActiveCfg = Release|AVR + {257C9A83-A686-455C-AC90-D649B30AA14D}.Release|AVR.Build.0 = Release|AVR + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/P8000_WDC_Emulator/P8000_WDC_Emulator.atsuo b/P8000_WDC_Emulator/P8000_WDC_Emulator.atsuo new file mode 100755 index 0000000..468a8af Binary files /dev/null and b/P8000_WDC_Emulator/P8000_WDC_Emulator.atsuo differ diff --git a/P8000_WDC_Emulator/P8000_WDC_Emulator/Debug/Makefile b/P8000_WDC_Emulator/P8000_WDC_Emulator/Debug/Makefile new file mode 100755 index 0000000..83e1a91 --- /dev/null +++ b/P8000_WDC_Emulator/P8000_WDC_Emulator/Debug/Makefile @@ -0,0 +1,129 @@ +################################################################################ +# Automatically-generated file. Do not edit! +################################################################################ + +SHELL := cmd.exe +RM := rm -rf + +USER_OBJS := + +LIBS := +PROJ := + +O_SRCS := +C_SRCS := +S_SRCS := +S_UPPER_SRCS := +OBJ_SRCS := +ASM_SRCS := +PREPROCESSING_SRCS := +OBJS := +OBJS_AS_ARGS := +C_DEPS := +C_DEPS_AS_ARGS := +EXECUTABLES := +OUTPUT_FILE_PATH := +OUTPUT_FILE_PATH_AS_ARGS := +AVR_APP_PATH :=$$$AVR_APP_PATH$$$ +QUOTE := " +ADDITIONAL_DEPENDENCIES:= +OUTPUT_FILE_DEP:= + +# Every subdirectory with source files must be described here +SUBDIRS := + + +# Add inputs and outputs from these tool invocations to the build variables +C_SRCS += \ +../main.c \ +../uart.c + + +PREPROCESSING_SRCS += + + +ASM_SRCS += + + +OBJS += \ +main.o \ +uart.o + + +OBJS_AS_ARGS += \ +main.o \ +uart.o + + +C_DEPS += \ +main.d \ +uart.d + + +C_DEPS_AS_ARGS += \ +main.d \ +uart.d + + +OUTPUT_FILE_PATH +=P8000_WDC_Emulator.elf + +OUTPUT_FILE_PATH_AS_ARGS +=P8000_WDC_Emulator.elf + +ADDITIONAL_DEPENDENCIES:= + +OUTPUT_FILE_DEP:= ./makedep.mk + +# AVR32/GNU C Compiler + + + + + +./%.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"$@" "$<" + @echo Finished building: $< + + + +# AVR32/GNU Preprocessing Assembler + + + +# AVR32/GNU Assembler + + + + +ifneq ($(MAKECMDGOALS),clean) +ifneq ($(strip $(C_DEPS)),) +-include $(C_DEPS) +endif +endif + +# Add inputs and outputs from these tool invocations to the build variables + +# All Target +all: $(OUTPUT_FILE_PATH) $(ADDITIONAL_DEPENDENCIES) + +$(OUTPUT_FILE_PATH): $(OBJS) $(USER_OBJS) $(OUTPUT_FILE_DEP) + @echo Building target: $@ + @echo Invoking: AVR/GNU Linker : (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) -o$(OUTPUT_FILE_PATH_AS_ARGS) $(OBJS_AS_ARGS) $(USER_OBJS) $(LIBS) -Wl,-Map="P8000_WDC_Emulator.map" -Wl,--start-group -Wl,-lm -Wl,--end-group -mmcu=atmega1284p + @echo Finished building target: $@ + "C:\Program Files (x86)\Atmel\Atmel Studio 6.0\extensions\Atmel\AVRGCC\3.4.0.65\AVRToolchain\bin\avr-objcopy.exe" -O ihex -R .eeprom -R .fuse -R .lock -R .signature "P8000_WDC_Emulator.elf" "P8000_WDC_Emulator.hex" + "C:\Program Files (x86)\Atmel\Atmel Studio 6.0\extensions\Atmel\AVRGCC\3.4.0.65\AVRToolchain\bin\avr-objcopy.exe" -j .eeprom --set-section-flags=.eeprom=alloc,load --change-section-lma .eeprom=0 --no-change-warnings -O ihex "P8000_WDC_Emulator.elf" "P8000_WDC_Emulator.eep" || exit 0 + "C:\Program Files (x86)\Atmel\Atmel Studio 6.0\extensions\Atmel\AVRGCC\3.4.0.65\AVRToolchain\bin\avr-objdump.exe" -h -S "P8000_WDC_Emulator.elf" > "P8000_WDC_Emulator.lss" + "C:\Program Files (x86)\Atmel\Atmel Studio 6.0\extensions\Atmel\AVRGCC\3.4.0.65\AVRToolchain\bin\avr-size.exe" "P8000_WDC_Emulator.elf" + + + + + + +# Other Targets +clean: + -$(RM) $(OBJS_AS_ARGS)$(C_DEPS_AS_ARGS) $(EXECUTABLES) + rm -rf "P8000_WDC_Emulator.elf" "P8000_WDC_Emulator.a" "P8000_WDC_Emulator.hex" "P8000_WDC_Emulator.lss" "P8000_WDC_Emulator.eep" "P8000_WDC_Emulator.map" + \ No newline at end of file diff --git a/P8000_WDC_Emulator/P8000_WDC_Emulator/Debug/makedep.mk b/P8000_WDC_Emulator/P8000_WDC_Emulator/Debug/makedep.mk new file mode 100755 index 0000000..d365230 --- /dev/null +++ b/P8000_WDC_Emulator/P8000_WDC_Emulator/Debug/makedep.mk @@ -0,0 +1,8 @@ +################################################################################ +# Automatically-generated file. Do not edit or delete the file +################################################################################ + +main.c + +uart.c + diff --git a/P8000_WDC_Emulator/P8000_WDC_Emulator/P8000_WDC_Emulator.cproj b/P8000_WDC_Emulator/P8000_WDC_Emulator/P8000_WDC_Emulator.cproj new file mode 100644 index 0000000..8259f5e --- /dev/null +++ b/P8000_WDC_Emulator/P8000_WDC_Emulator/P8000_WDC_Emulator.cproj @@ -0,0 +1,85 @@ + + + + 2.0 + 6.0 + com.Atmel.AVRGCC8 + {257c9a83-a686-455c-ac90-d649b30aa14d} + ATmega1284P + none + Executable + C + $(MSBuildProjectName) + .elf + $(MSBuildProjectDirectory)\$(Configuration) + P8000_WDC_Emulator + P8000_WDC_Emulator + P8000_WDC_Emulator + Native + true + false + + 0 + 3.1.3 + + + + + True + True + True + True + True + Optimize for size (-Os) + True + True + True + + + m + + + + + + + + + True + True + True + True + True + Optimize (-O1) + True + True + Default (-g2) + True + + + m + + + Default (-Wa,-g) + + + + + + compile + + + compile + + + compile + + + compile + + + compile + + + + \ No newline at end of file diff --git a/P8000_WDC_Emulator/P8000_WDC_Emulator/uart.c b/P8000_WDC_Emulator/P8000_WDC_Emulator/uart.c new file mode 100644 index 0000000..6e58225 --- /dev/null +++ b/P8000_WDC_Emulator/P8000_WDC_Emulator/uart.c @@ -0,0 +1,198 @@ +/* + * Copyright (c) 2006-2011 by Roland Riegel + * + * This file is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + */ + +#include +#include +#include +#include +#include +#include + +#include "uart.h" + +/* some mcus have multiple uarts */ +#ifdef UDR0 +#define UBRRH UBRR0H +#define UBRRL UBRR0L +#define UDR UDR0 + +#define UCSRA UCSR0A +#define UDRE UDRE0 +#define RXC RXC0 + +#define UCSRB UCSR0B +#define RXEN RXEN0 +#define TXEN TXEN0 +#define RXCIE RXCIE0 + +#define UCSRC UCSR0C +#define URSEL +#define UCSZ0 UCSZ00 +#define UCSZ1 UCSZ01 +#define UCSRC_SELECT 0 +#else +#define UCSRC_SELECT (1 << URSEL) +#endif + +#ifndef USART_RXC_vect +#if defined(UART0_RX_vect) +#define USART_RXC_vect UART0_RX_vect +#elif defined(UART_RX_vect) +#define USART_RXC_vect UART_RX_vect +#elif defined(USART0_RX_vect) +#define USART_RXC_vect USART0_RX_vect +#elif defined(USART_RX_vect) +#define USART_RXC_vect USART_RX_vect +#elif defined(USART0_RXC_vect) +#define USART_RXC_vect USART0_RXC_vect +#elif defined(USART_RXC_vect) +#define USART_RXC_vect USART_RXC_vect +#else +#error "Uart receive complete interrupt not defined!" +#endif +#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 USE_SLEEP 1 + +void uart_init() +{ + /* set baud rate */ + UBRRH = UBRRVAL >> 8; + UBRRL = UBRRVAL & 0xff; + /* set frame format: 8 bit, no parity, 1 bit */ + UCSRC = UCSRC_SELECT | (1 << UCSZ1) | (1 << UCSZ0); + /* enable serial receiver and transmitter */ +#if !USE_SLEEP + UCSRB = (1 << RXEN) | (1 << TXEN); +#else + UCSRB = (1 << RXEN) | (1 << TXEN) | (1 << RXCIE); +#endif +} + +void uart_putc(uint8_t c) +{ + if(c == '\n') + uart_putc('\r'); + + /* wait until transmit buffer is empty */ + while(!(UCSRA & (1 << UDRE))); + + /* send next byte */ + UDR = c; +} + +void uart_putc_hex(uint8_t b) +{ + /* upper nibble */ + if((b >> 4) < 0x0a) + uart_putc((b >> 4) + '0'); + else + uart_putc((b >> 4) - 0x0a + 'a'); + + /* lower nibble */ + if((b & 0x0f) < 0x0a) + uart_putc((b & 0x0f) + '0'); + else + uart_putc((b & 0x0f) - 0x0a + 'a'); +} + +void uart_putw_hex(uint16_t w) +{ + uart_putc_hex((uint8_t) (w >> 8)); + uart_putc_hex((uint8_t) (w & 0xff)); +} + +void uart_putdw_hex(uint32_t dw) +{ + uart_putw_hex((uint16_t) (dw >> 16)); + uart_putw_hex((uint16_t) (dw & 0xffff)); +} + +void uart_putw_dec(uint16_t w) +{ + uint16_t num = 10000; + uint8_t started = 0; + + while(num > 0) + { + uint8_t b = w / num; + if(b > 0 || started || num == 1) + { + uart_putc('0' + b); + started = 1; + } + w -= b * num; + + num /= 10; + } +} + +void uart_putdw_dec(uint32_t dw) +{ + uint32_t num = 1000000000; + uint8_t started = 0; + + while(num > 0) + { + uint8_t b = dw / num; + if(b > 0 || started || num == 1) + { + uart_putc('0' + b); + started = 1; + } + dw -= b * num; + + num /= 10; + } +} + +void uart_puts(const char* str) +{ + while(*str) + uart_putc(*str++); +} + +void uart_puts_p(PGM_P str) +{ + while(1) + { + uint8_t b = pgm_read_byte_near(str++); + if(!b) + break; + + uart_putc(b); + } +} + +uint8_t uart_getc() +{ + /* wait until receive buffer is full */ +#if USE_SLEEP + uint8_t sreg = SREG; + sei(); + + while(!(UCSRA & (1 << RXC))) + sleep_mode(); + + SREG = sreg; +#else + while(!(UCSRA & (1 << RXC))); +#endif + + uint8_t b = UDR; + if(b == '\r') + b = '\n'; + + return b; +} + +EMPTY_INTERRUPT(USART_RXC_vect) \ No newline at end of file diff --git a/P8000_WDC_Emulator/P8000_WDC_Emulator/uart.h b/P8000_WDC_Emulator/P8000_WDC_Emulator/uart.h new file mode 100644 index 0000000..15658ca --- /dev/null +++ b/P8000_WDC_Emulator/P8000_WDC_Emulator/uart.h @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2006-2011 by Roland Riegel + * + * This file is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + */ + +#ifndef UART_H +#define UART_H + +#include +#include + +#ifdef __cplusplus +extern "C" +{ +#endif + +void uart_init(); + +void uart_putc(uint8_t c); + +void uart_putc_hex(uint8_t b); +void uart_putw_hex(uint16_t w); +void uart_putdw_hex(uint32_t dw); + +void uart_putw_dec(uint16_t w); +void uart_putdw_dec(uint32_t dw); + +void uart_puts(const char* str); +void uart_puts_p(PGM_P str); + +uint8_t uart_getc(); + +#ifdef __cplusplus +} +#endif + +#endif \ No newline at end of file diff --git a/P8000_WDC_Emulator/P8000_WDC_Emulator/wdc_config.h b/P8000_WDC_Emulator/P8000_WDC_Emulator/wdc_config.h new file mode 100644 index 0000000..0795f47 --- /dev/null +++ b/P8000_WDC_Emulator/P8000_WDC_Emulator/wdc_config.h @@ -0,0 +1,29 @@ +/* + * P8000 WDC Emulator + * + * $Id: wdc_config.h,v 1.1 2012/05/29 20:13:00 olivleh1 Exp $ + * + */ + + +#ifndef CONFIG_H_ +#define CONFIG_H_ + +#define PORT_DATA PORTA +#define PIN_DATA PINA +#define DDR_DATA DDRA + +#define PORT_INFO PORTC +#define PIN_INFO PINC +#define DDR_INFO DDRC + +#define PIN_INFO_STATUS0 PINC0 +#define PIN_INFO_STATUS1 PINC1 +#define PIN_INFO_STATUS2 PINC2 +#define PIN_INFO_ASTB PINC3 +#define PIN_INFO_TE PINC4 +#define PIN_INFO_WDARDY PINC5 +#define PIN_INFO_TR PINC6 +#define PIN_INFO_RST PINC7 + +#endif /* CONFIG_H_ */ \ No newline at end of file diff --git a/P8000_WDC_Emulator/P8000_WDC_Emulator/wdc_main.c b/P8000_WDC_Emulator/P8000_WDC_Emulator/wdc_main.c new file mode 100644 index 0000000..42d5295 --- /dev/null +++ b/P8000_WDC_Emulator/P8000_WDC_Emulator/wdc_main.c @@ -0,0 +1,84 @@ +/* + * P8000 WDC Emulator + * + * $Id: wdc_main.c,v 1.1 2012/05/29 20:13:00 olivleh1 Exp $ + * + */ + + +#include +#include +#include +#include +#include +#include "uart.h" +#include "main.h" + +void atmega_setup(void); + +int main(void) +{ + uint8_t cmdbuffer[9]; + uint8_t cmdcnt; + + atmega_setup(); + + uart_puts_p(PSTR("P8000 WDC Emulator 1.0\n")); + + while(1) + { + + while( !isset_info_reset() ) + { + port_data_set( DATA_CLEAR ); + port_info_set( INFO_CLEAR ); + } + + configure_port_data_read(); + cmdcnt = 0; + port_info_set( INFO_STAT_GCMD ); + + while ( !isset_info_te() ); + while ( !isset_info_wdardy() ); + while ( cmdcnt < 9 ) + { + while ( isset_info_wdardy() ); + port_info_set( INFO_ASTB | INFO_STAT_GCMD ); + cmdbuffer[cmdcnt] = port_data_get(); + port_info_set( INFO_STAT_GCMD ); + while ( !isset_info_wdardy() ); + cmdcnt++; + } + + uart_puts_p(PSTR("CMD Buffer:")); + uart_putc_hex(cmdbuffer[0]); + uart_putc_hex(cmdbuffer[1]); + uart_putc_hex(cmdbuffer[2]); + uart_putc_hex(cmdbuffer[3]); + uart_putc_hex(cmdbuffer[4]); + uart_putc_hex(cmdbuffer[5]); + uart_putc_hex(cmdbuffer[6]); + uart_putc_hex(cmdbuffer[7]); + uart_putc_hex(cmdbuffer[8]); + uart_putc('\n'); + } + return 0; +} + +void atmega_setup(void) +{ + set_sleep_mode(SLEEP_MODE_IDLE); + + configure_pin_status0(); + configure_pin_status1(); + configure_pin_status2(); + configure_pin_astb(); + configure_pin_te(); + configure_pin_wdardy(); + configure_pin_tr(); + configure_pin_reset(); + + configure_port_data_read(); + + uart_init(); +} \ No newline at end of file diff --git a/P8000_WDC_Emulator/P8000_WDC_Emulator/wdc_main.h b/P8000_WDC_Emulator/P8000_WDC_Emulator/wdc_main.h new file mode 100644 index 0000000..69204f9 --- /dev/null +++ b/P8000_WDC_Emulator/P8000_WDC_Emulator/wdc_main.h @@ -0,0 +1,44 @@ +/* + * P8000 WDC Emulator + * + * $Id: wdc_main.h,v 1.1 2012/05/29 20:13:00 olivleh1 Exp $ + * + */ + + +#ifndef MAIN_H_ +#define MAIN_H_ + +#include "config.h" + +#define isset_info_reset() ((PIN_INFO) & (1 << PIN_INFO_RST)) +#define isset_info_te() ((PIN_INFO) & (1 << PIN_INFO_TE)) +#define isset_info_wdardy() ((PIN_INFO) & (1 << PIN_INFO_WDARDY)) + +#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*/ + +#define configure_pin_status0() DDR_INFO |= (1 << PIN_INFO_STATUS0) +#define configure_pin_status1() DDR_INFO |= (1 << PIN_INFO_STATUS1) +#define configure_pin_status2() DDR_INFO |= (1 << PIN_INFO_STATUS2) +#define configure_pin_astb() DDR_INFO |= (1 << PIN_INFO_ASTB) +#define configure_pin_te() DDR_INFO &= ~(1 << PIN_INFO_TE) +#define configure_pin_wdardy() DDR_INFO &= ~(1 << PIN_INFO_WDARDY) +#define configure_pin_tr() DDR_INFO |= (1 << PIN_INFO_TR) +#define configure_pin_reset() DDR_INFO &= ~(1 << PIN_INFO_RST) + +#define port_data_set(x) (PORT_DATA = x) +#define port_info_set(x) (PORT_INFO = x) +#define port_data_get(x) PIN_DATA +#define port_info_get(x) PIN_INFO + +#define DATA_CLEAR 0x00 +#define INFO_CLEAR 0x00 + +#define INFO_ASTB (1 << PIN_INFO_ASTB) +#define INFO_STAT_GCMD (1 << PIN_INFO_STATUS0) /* 0x01 */ +#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_STATUS1)) /* 0x07 */ + +#endif /* MAIN_H_ */ \ No newline at end of file