commit 9e69670da0cd3bcca17d2d9e9a7f464c2649cd9f Author: Olaf Rempel Date: Thu May 25 11:15:22 2017 +0200 initial commit diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..6d36148 --- /dev/null +++ b/.gitignore @@ -0,0 +1,6 @@ +*.o +*.elf +*.bin +*.hex +*.lst +*.map diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..751bce8 --- /dev/null +++ b/Makefile @@ -0,0 +1,56 @@ +PRG = epromsim +OBJ = main.o +MCU_TARGET = attiny2313 +OPTIMIZE = -Os + +#AVRDUDE_PROG = -c avr910 -b 115200 -P /dev/ispprog +AVRDUDE_PROG = -c dragon_isp -P usb +AVRDUDE_MCU = attiny2313 + +DEFS = +LIBS = + +# Override is only needed by avr-lib build system. +override CFLAGS = -g -Wall $(OPTIMIZE) -mmcu=$(MCU_TARGET) $(DEFS) +override LDFLAGS = -Wl,-Map,$(PRG).map + +CC = avr-gcc +OBJCOPY = avr-objcopy +OBJDUMP = avr-objdump +SIZE = avr-size + +all: $(PRG).elf lst text + $(SIZE) -x -A $(PRG).elf + +$(PRG).elf: $(OBJ) + $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $^ $(LIBS) + +%.o: %.c $(MAKEFILE_LIST) + $(CC) $(CFLAGS) -c $< -o $@ + +clean: + rm -rf *.o $(PRG).lst $(PRG).map $(PRG).elf $(PRG).hex $(PRG).bin + +lst: $(PRG).lst + +%.lst: %.elf + $(OBJDUMP) -h -S $< > $@ + +text: hex bin + +hex: $(PRG).hex +bin: $(PRG).bin + +%.hex: %.elf + $(OBJCOPY) -j .text -j .data -O ihex $< $@ + +%.bin: %.elf + $(OBJCOPY) -j .text -j .data -O binary $< $@ + +install: text + avrdude $(AVRDUDE_PROG) -p $(AVRDUDE_MCU) -V -U flash:w:$(PRG).hex + +fuses: + avrdude $(AVRDUDE_PROG) -p $(AVRDUDE_MCU) -U efuse:w:0xff:m + avrdude $(AVRDUDE_PROG) -p $(AVRDUDE_MCU) -U hfuse:w:0xdb:m + avrdude $(AVRDUDE_PROG) -p $(AVRDUDE_MCU) -U lfuse:w:0xff:m diff --git a/main.c b/main.c new file mode 100644 index 0000000..b0c96ac --- /dev/null +++ b/main.c @@ -0,0 +1,368 @@ +/*************************************************************************** + * Copyright (C) 04/2013 by Olaf Rempel * + * razzor@kopf-tisch.de * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; version 2 of the License, * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + ***************************************************************************/ +#include +#include + +#define F_CPU 11059200 +#include + +/* + * attiny2313 + * lfuse: 0xff (ext. crystal, slow rising power, max startup time) + * hfuse: 0xdb (2.7V BOD) + * efuse: 0xff (self Prog enabled) + * + * PB0 -> NC + * PB1 -> reset-out + * PB2 -> /WR SRAM + * PB3 -> SRCK (shift register clock) + * PB4 -> SER (shift register input) + * PB5 -> CCK (counter clock) + * PB6 -> RCK (counter and shift register store clock) + * PB7 -> /OE (output enable counter, shift register, reset-out, A16) + * PD0 <- RXD + * PD1 -> TXD + * PD2 <- /PowerFail + * PD3 -> A16 + * PD4 -> /LED_GN + * PD5 -> /LED_RT + * PD6 -> /OE (output enable RAM and address buffer, counter clear) + */ + +#define RESET_OUT PORTB1 +#define nRAM_WR PORTB2 +#define SREG_CLK PORTB3 +#define SREG_DAT PORTB4 +#define CNT_CLK PORTB5 +#define REG_STORE PORTB6 +#define nEMU_EN PORTB7 + +#define RXD PORTD0 +#define TXD PORTD1 +#define nPOWERFAIL PORTD2 +#define EMU_A16 PORTD3 +#define nLED_GN PORTD4 +#define nLED_RT PORTD5 +#define nTARGET_EN PORTD6 + +#define BAUDRATE 115200 + +#define UART_CALC_BAUDRATE(baudRate) (((uint32_t)F_CPU) / (((uint32_t)baudRate)*16) -1) + +struct _globdata { + uint8_t address_mask; + uint8_t reset_polarity; +}; + +static struct _globdata gdata = { 0 }; + + +/* ************************************************************************* + * send one byte to UART + * ************************************************************************* */ +static void ser_send(uint8_t data) +{ + loop_until_bit_is_set(UCSRA, UDRIE); + UDR = data; +} /* ser_send */ + + +/* ************************************************************************* + * receive one byte from UART + * ************************************************************************* */ +static uint8_t ser_recv(void) +{ + loop_until_bit_is_set(UCSRA, RXC); + return UDR; +} /* ser_recv */ + + +/* ************************************************************************* + * shift one byte out to register (LSB first) + * ************************************************************************* */ +static void shift_data(uint8_t data) +{ + uint8_t mask; + + for (mask = 0x01; mask != 0; mask <<= 1) { + if (data & mask) { + PORTB |= (1< 0xFFFF) { + PORTD |= (1<>8) & 0xFF; + UBRRL = (UART_CALC_BAUDRATE(BAUDRATE) & 0xFF); + UCSRC = (1<