P8000 WDC Emulator
This commit is contained in:
parent
251a31c4b7
commit
878649dbdb
|
|
@ -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
|
||||||
Binary file not shown.
|
|
@ -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"
|
||||||
|
|
||||||
|
|
@ -0,0 +1,8 @@
|
||||||
|
################################################################################
|
||||||
|
# Automatically-generated file. Do not edit or delete the file
|
||||||
|
################################################################################
|
||||||
|
|
||||||
|
main.c
|
||||||
|
|
||||||
|
uart.c
|
||||||
|
|
||||||
|
|
@ -0,0 +1,85 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||||
|
<PropertyGroup>
|
||||||
|
<SchemaVersion>2.0</SchemaVersion>
|
||||||
|
<ProjectVersion>6.0</ProjectVersion>
|
||||||
|
<ToolchainName>com.Atmel.AVRGCC8</ToolchainName>
|
||||||
|
<ProjectGuid>{257c9a83-a686-455c-ac90-d649b30aa14d}</ProjectGuid>
|
||||||
|
<avrdevice>ATmega1284P</avrdevice>
|
||||||
|
<avrdeviceseries>none</avrdeviceseries>
|
||||||
|
<OutputType>Executable</OutputType>
|
||||||
|
<Language>C</Language>
|
||||||
|
<OutputFileName>$(MSBuildProjectName)</OutputFileName>
|
||||||
|
<OutputFileExtension>.elf</OutputFileExtension>
|
||||||
|
<OutputDirectory>$(MSBuildProjectDirectory)\$(Configuration)</OutputDirectory>
|
||||||
|
<AssemblyName>P8000_WDC_Emulator</AssemblyName>
|
||||||
|
<Name>P8000_WDC_Emulator</Name>
|
||||||
|
<RootNamespace>P8000_WDC_Emulator</RootNamespace>
|
||||||
|
<ToolchainFlavour>Native</ToolchainFlavour>
|
||||||
|
<KeepTimersRunning>true</KeepTimersRunning>
|
||||||
|
<OverrideVtor>false</OverrideVtor>
|
||||||
|
<OverrideVtorValue />
|
||||||
|
<eraseonlaunchrule>0</eraseonlaunchrule>
|
||||||
|
<AsfVersion>3.1.3</AsfVersion>
|
||||||
|
</PropertyGroup>
|
||||||
|
<PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
|
||||||
|
<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 for size (-Os)</avrgcc.compiler.optimization.level>
|
||||||
|
<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.linker.libraries.Libraries>
|
||||||
|
<ListValues>
|
||||||
|
<Value>m</Value>
|
||||||
|
</ListValues>
|
||||||
|
</avrgcc.linker.libraries.Libraries>
|
||||||
|
</AvrGcc>
|
||||||
|
</ToolchainSettings>
|
||||||
|
</PropertyGroup>
|
||||||
|
<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.PackStructureMembers>True</avrgcc.compiler.optimization.PackStructureMembers>
|
||||||
|
<avrgcc.compiler.optimization.AllocateBytesNeededForEnum>True</avrgcc.compiler.optimization.AllocateBytesNeededForEnum>
|
||||||
|
<avrgcc.compiler.optimization.DebugLevel>Default (-g2)</avrgcc.compiler.optimization.DebugLevel>
|
||||||
|
<avrgcc.compiler.warnings.AllWarnings>True</avrgcc.compiler.warnings.AllWarnings>
|
||||||
|
<avrgcc.linker.libraries.Libraries>
|
||||||
|
<ListValues>
|
||||||
|
<Value>m</Value>
|
||||||
|
</ListValues>
|
||||||
|
</avrgcc.linker.libraries.Libraries>
|
||||||
|
<avrgcc.assembler.debugging.DebugLevel>Default (-Wa,-g)</avrgcc.assembler.debugging.DebugLevel>
|
||||||
|
</AvrGcc>
|
||||||
|
</ToolchainSettings>
|
||||||
|
</PropertyGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<Compile Include="config.h">
|
||||||
|
<SubType>compile</SubType>
|
||||||
|
</Compile>
|
||||||
|
<Compile Include="main.c">
|
||||||
|
<SubType>compile</SubType>
|
||||||
|
</Compile>
|
||||||
|
<Compile Include="main.h">
|
||||||
|
<SubType>compile</SubType>
|
||||||
|
</Compile>
|
||||||
|
<Compile Include="uart.c">
|
||||||
|
<SubType>compile</SubType>
|
||||||
|
</Compile>
|
||||||
|
<Compile Include="uart.h">
|
||||||
|
<SubType>compile</SubType>
|
||||||
|
</Compile>
|
||||||
|
</ItemGroup>
|
||||||
|
<Import Project="$(AVRSTUDIO_EXE_PATH)\\Vs\\Compiler.targets" />
|
||||||
|
</Project>
|
||||||
|
|
@ -0,0 +1,198 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2006-2011 by Roland Riegel <feedback@roland-riegel.de>
|
||||||
|
*
|
||||||
|
* 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 <stdio.h>
|
||||||
|
#include <avr/interrupt.h>
|
||||||
|
#include <avr/io.h>
|
||||||
|
#include <avr/pgmspace.h>
|
||||||
|
#include <avr/sfr_defs.h>
|
||||||
|
#include <avr/sleep.h>
|
||||||
|
|
||||||
|
#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)
|
||||||
|
|
@ -0,0 +1,40 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2006-2011 by Roland Riegel <feedback@roland-riegel.de>
|
||||||
|
*
|
||||||
|
* 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 <stdint.h>
|
||||||
|
#include <avr/pgmspace.h>
|
||||||
|
|
||||||
|
#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
|
||||||
|
|
@ -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_ */
|
||||||
|
|
@ -0,0 +1,84 @@
|
||||||
|
/*
|
||||||
|
* P8000 WDC Emulator
|
||||||
|
*
|
||||||
|
* $Id: wdc_main.c,v 1.1 2012/05/29 20:13:00 olivleh1 Exp $
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
#include <string.h>
|
||||||
|
#include <avr/pgmspace.h>
|
||||||
|
#include <avr/sleep.h>
|
||||||
|
#include <avr/io.h>
|
||||||
|
#include <avr/interrupt.h>
|
||||||
|
#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();
|
||||||
|
}
|
||||||
|
|
@ -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_ */
|
||||||
Loading…
Reference in New Issue