From 4fa167a61dccd44a2ef243e0b27e697f80ac169c Mon Sep 17 00:00:00 2001 From: optixx Date: Thu, 27 Aug 2009 22:05:43 +0200 Subject: [PATCH] add snes reset line sniffer and trigger watchdog reset --- avr/usbload/Makefile | 4 ++-- avr/usbload/command.c | 4 ++++ avr/usbload/loader.h | 2 ++ avr/usbload/main.c | 14 +++++++------- avr/usbload/sram.c | 2 -- avr/usbload/sram.h | 2 ++ avr/usbload/timer.c | 5 +++++ 7 files changed, 22 insertions(+), 11 deletions(-) diff --git a/avr/usbload/Makefile b/avr/usbload/Makefile index b6781dc..09ac036 100644 --- a/avr/usbload/Makefile +++ b/avr/usbload/Makefile @@ -33,13 +33,13 @@ ifeq ($(DEBUG),1) OBJECTS = usbdrv/usbdrv.o usbdrv/usbdrvasm.o usbdrv/oddebug.o \ main.o usb_bulk.o uart.o fifo.o sram.o crc.o debug.o \ dump.o timer.o watchdog.o rle.c loader.o info.o shared_memory.o \ - command.o testing.o + irq.o command.o testing.o else LDFLAGS = -Wl,-u CFLAGS = -Iusbdrv -I. -DDEBUG_LEVEL=0 -DNO_DEBUG -DNO_INFO OBJECTS = usbdrv/usbdrv.o usbdrv/usbdrvasm.o usbdrv/oddebug.o main.o usb_bulk.o \ uart.o fifo.o sram.o crc.o debug.o dump.o timer.o watchdog.o rle.c loader.o \ - info.o shared_memory.o command.o + info.o shared_memory.o command.o irq.o endif COMPILE = avr-gcc -Wall -Os -DF_CPU=$(F_CPU) $(CFLAGS) -mmcu=$(DEVICE) diff --git a/avr/usbload/command.c b/avr/usbload/command.c index daeb17f..915b965 100644 --- a/avr/usbload/command.c +++ b/avr/usbload/command.c @@ -19,6 +19,7 @@ */ #include +#include #include #include @@ -33,11 +34,14 @@ extern uint32_t req_bank_size; void send_reset() { info("Reset SNES\n"); + cli(); snes_reset_on(); snes_reset_lo(); _delay_ms(2); snes_reset_hi(); snes_reset_off(); + sei(); + } void send_irq() diff --git a/avr/usbload/loader.h b/avr/usbload/loader.h index 49d54f9..c617f46 100644 --- a/avr/usbload/loader.h +++ b/avr/usbload/loader.h @@ -6,4 +6,6 @@ #define ROM_HUFFMAN_SIZE 0 #define ROM_RLE_SIZE 31091 +void irq_init(); + #endif diff --git a/avr/usbload/main.c b/avr/usbload/main.c index 94a2182..017e6f4 100644 --- a/avr/usbload/main.c +++ b/avr/usbload/main.c @@ -302,13 +302,13 @@ void boot_startup_rom() #if 0 dump_memory(0x10000 - 0x100, 0x10000); #endif - snes_reset_hi(); - snes_reset_off(); snes_hirom(); snes_wr_disable(); snes_bus_active(); info("Activate SNES bus\n"); + _delay_ms(50); send_reset(); + _delay_ms(50); } void banner(){ @@ -335,8 +335,11 @@ int main(void) stdout = &uart_stdout; banner(); system_init(); + snes_reset_hi(); + snes_reset_off(); info("Boot startup rom\n"); boot_startup_rom(); + irq_init(); usbInit(); usb_connect(); while (1) { @@ -347,11 +350,9 @@ int main(void) snes_wr_disable(); sei(); info("USB poll\n"); - while (req_state != REQ_STATUS_SNES) { + while ((req_state != REQ_STATUS_SNES)) { usbPoll(); } - - shared_memory_write(SHARED_MEM_TX_CMD_TERMINATE, 0); //shared_memory_scratchpad_region_tx_restore(); //shared_memory_scratchpad_region_rx_restore(); @@ -363,7 +364,7 @@ int main(void) info("Activate SNES bus\n"); send_reset(); info("Poll USB\n"); - while (req_state != REQ_STATUS_AVR) { + while ((req_state != REQ_STATUS_AVR)) { usbPoll(); #ifdef DO_IRQ @@ -402,6 +403,5 @@ int main(void) info("Boot startup rom\n"); boot_startup_rom(); } - return 0; } diff --git a/avr/usbload/sram.c b/avr/usbload/sram.c index 38eac31..9f5063a 100644 --- a/avr/usbload/sram.c +++ b/avr/usbload/sram.c @@ -34,7 +34,6 @@ uint32_t addr_current = 0; uint32_t addr_stash = 0; - void system_init(void) { /*-------------------------------------------------*/ @@ -92,7 +91,6 @@ void system_init(void) } - void sreg_set(uint32_t addr) { uint8_t i = 24; diff --git a/avr/usbload/sram.h b/avr/usbload/sram.h index 178e104..404cd68 100644 --- a/avr/usbload/sram.h +++ b/avr/usbload/sram.h @@ -171,6 +171,7 @@ #define SNES_RESET_PORT PORTD #define SNES_RESET_DIR DDRD #define SNES_RESET_PIN PD3 +#define SNES_RESET_INP PIND #define snes_reset_on() (SNES_RESET_DIR |= (1 << SNES_RESET_PIN)) #define snes_reset_hi() (SNES_RESET_PORT |= (1 << SNES_RESET_PIN)) @@ -178,6 +179,7 @@ #define snes_reset_off() (SNES_RESET_DIR &= ~(1 << SNES_RESET_PIN)) #define snes_reset_lo() (SNES_RESET_PORT &= ~(1 << SNES_RESET_PIN)) +#define snes_reset_test() ((SNES_RESET_INP & (1 << SNES_RESET_PIN)) == 0) #define MMC_PORT PORTB #define MMC_DIR DDRB diff --git a/avr/usbload/timer.c b/avr/usbload/timer.c index 7034a08..a7bb721 100644 --- a/avr/usbload/timer.c +++ b/avr/usbload/timer.c @@ -29,7 +29,11 @@ #include "debug.h" #include "info.h" +#include "sram.h" + +extern uint8_t snes_reset_line; + #ifndef OCR1A #define OCR1A OCR1 // 2313 support #endif @@ -52,6 +56,7 @@ uint16_t volatile second; // count seconds ISR (SIG_OUTPUT_COMPARE1A) { + #if XTAL % DEBOUNCE // bei rest OCR1A = 20000000UL / DEBOUNCE - 1; // compare DEBOUNCE - 1 times