add reset line irq handling

This commit is contained in:
optixx 2009-08-28 07:55:06 +02:00
parent a741a2ff3a
commit 507957f7cc
6 changed files with 131 additions and 17 deletions

View File

@ -27,6 +27,7 @@
#include "requests.h"
#include "sram.h"
#include "info.h"
#include "irq.h"
extern uint32_t req_bank_size;
@ -41,7 +42,6 @@ void send_reset()
snes_reset_hi();
snes_reset_off();
sei();
}
void send_irq()

72
avr/usbload/irq.c Normal file
View File

@ -0,0 +1,72 @@
/*
* =====================================================================================
*
* ________ .__ __ ________ ____ ________
* \_____ \ __ __|__| ____ | | __\______ \ _______ _/_ |/ _____/
* / / \ \| | \ |/ ___\| |/ / | | \_/ __ \ \/ /| / __ \
* / \_/. \ | / \ \___| < | ` \ ___/\ / | \ |__\ \
* \_____\ \_/____/|__|\___ >__|_ \/_______ /\___ >\_/ |___|\_____ /
* \__> \/ \/ \/ \/ \/
*
* www.optixx.org
*
*
* Version: 1.0
* Created: 07/21/2009 03:32:16 PM
* Author: david@optixx.org
*
* =====================================================================================
*/
#include <stdint.h>
#include <stdio.h>
#include <avr/io.h>
#include <avr/interrupt.h> /* for sei() */
#include <avr/wdt.h>
#include "usbdrv.h"
#include "oddebug.h" /* This is also an example for using debug
* macros */
#include "debug.h"
#include "info.h"
#include "sram.h"
void (*jump_to_app) (void) = 0x0000;
void irq_init(){
cli();
PCMSK3 |=(1<<PCINT27);
PCICR |= (1<<PCIE3);
sei();
}
void irq_stop(){
cli();
PCMSK3 &=~(1<<PCINT27);
sei();
}
void leave_application(void)
{
cli();
usbDeviceDisconnect();
wdt_enable(WDTO_15MS);
while (1);
}
ISR (SIG_PIN_CHANGE3)
{
if (snes_reset_test()){
info("Catch SNES reset button\n");
info("Set watchdog...\n");
leave_application();
}
}

25
avr/usbload/irq.h Normal file
View File

@ -0,0 +1,25 @@
/*
* =====================================================================================
*
* ________ .__ __ ________ ____ ________
* \_____ \ __ __|__| ____ | | __\______ \ _______ _/_ |/ _____/
* / / \ \| | \ |/ ___\| |/ / | | \_/ __ \ \/ /| / __ \
* / \_/. \ | / \ \___| < | ` \ ___/\ / | \ |__\ \
* \_____\ \_/____/|__|\___ >__|_ \/_______ /\___ >\_/ |___|\_____ /
* \__> \/ \/ \/ \/ \/
*
* www.optixx.org
*
*
* Version: 1.0
* Created: 07/21/2009 03:32:16 PM
* Author: david@optixx.org
*
* =====================================================================================
*/
#ifndef __IRQ_H__
#define __IRQ_H__
#endif

View File

@ -51,7 +51,7 @@
extern const char _rom[] PROGMEM;
extern FILE uart_stdout;
uint8_t debug_level = (DEBUG | DEBUG_USB | DEBUG_CRC | DEBUG_SHM );
uint8_t debug_level = (DEBUG | DEBUG_USB | DEBUG_CRC | DEBUG_SHM);
uint8_t read_buffer[TRANSFER_BUFFER_SIZE];
uint32_t req_addr = 0;
@ -164,11 +164,13 @@ usbMsgLen_t usbFunctionSetup(uchar data[8])
sram_bulk_write_start(req_addr);
#endif
#if SHM_SCRATCHPAD
if (!shared_memory_scratchpad_region_save_helper(req_addr)){
debug(DEBUG_USB,
"USB_BULK_UPLOAD_NEXT: scratchpad_region_save_helper was dirty\n");
sram_bulk_write_start(req_addr);
}
#endif
if (req_addr && (req_addr % req_bank_size) == 0) {
@ -278,9 +280,9 @@ void usb_connect()
i = 10;
while (--i) { /* fake USB disconnect for > 250 ms */
led_on();
_delay_ms(35);
_delay_ms(15);
led_off();
_delay_ms(65);
_delay_ms(35);
}
led_on();
usbDeviceConnect();
@ -290,7 +292,7 @@ void usb_connect()
void boot_startup_rom()
{
info("Boot startup rom\n");
info("Activate AVR bus\n");
avr_bus_active();
info("IRQ off\n");
@ -299,13 +301,14 @@ void boot_startup_rom()
snes_lorom();
rle_decode(&_rom, ROM_BUFFER_SIZE, 0x000000);
info("\n");
#if 0
#if 1
dump_memory(0x10000 - 0x100, 0x10000);
#endif
snes_hirom();
snes_wr_disable();
snes_bus_active();
info("Activate SNES bus\n");
send_reset();
_delay_ms(50);
send_reset();
_delay_ms(50);
@ -328,6 +331,15 @@ void banner(){
}
void globals_init(){
req_addr = 0;
req_addr_end = 0;
req_state = REQ_STATUS_IDLE;
rx_remaining = 0;
tx_remaining = 0;
sync_errors = 0;
}
int main(void)
{
@ -337,9 +349,9 @@ int main(void)
system_init();
snes_reset_hi();
snes_reset_off();
info("Boot startup rom\n");
irq_init();
boot_startup_rom();
//irq_init();
globals_init();
usbInit();
usb_connect();
while (1) {
@ -350,18 +362,22 @@ 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();
#if SHM_SCRATCHPAD
shared_memory_scratchpad_region_tx_restore();
shared_memory_scratchpad_region_rx_restore();
#endif
info("USB poll done\n");
set_rom_mode();
snes_wr_disable();
info("Disable SNES WR\n");
snes_bus_active();
info("Activate SNES bus\n");
irq_stop();
send_reset();
info("Poll USB\n");
while ((req_state != REQ_STATUS_AVR)) {
@ -400,8 +416,9 @@ int main(void)
info("Read 0x3000=%c\n", c);
#endif
}
info("Boot startup rom\n");
irq_init();
boot_startup_rom();
globals_init();
}
return 0;
}

View File

@ -64,7 +64,7 @@ uint8_t shared_memory_scratchpad_region_save_helper(uint32_t addr){
void shared_memory_scratchpad_region_tx_save()
{
#if 1
#if 0
uint16_t crc;
crc = crc_check_bulk_memory((uint32_t)SHARED_MEM_TX_LOC_STATE,
(uint32_t)(SHARED_MEM_TX_LOC_STATE + SHARED_MEM_TX_LOC_SIZE), 0x8000);
@ -86,7 +86,7 @@ void shared_memory_scratchpad_region_tx_save()
void shared_memory_scratchpad_region_rx_save()
{
#if 1
#if 0
uint16_t crc;
crc = crc_check_bulk_memory((uint32_t)SHARED_MEM_RX_LOC_STATE,
(uint32_t)(SHARED_MEM_RX_LOC_STATE + SHARED_MEM_RX_LOC_SIZE), 0x8000);
@ -118,7 +118,7 @@ void shared_memory_scratchpad_region_tx_restore()
dump_memory(SHARED_MEM_TX_LOC_STATE, SHARED_MEM_TX_LOC_STATE + SHARED_MEM_TX_LOC_SIZE);
#endif
#if 1
#if 0
uint16_t crc;
crc = crc_check_bulk_memory((uint32_t)SHARED_MEM_TX_LOC_STATE,
(uint32_t)(SHARED_MEM_TX_LOC_STATE + SHARED_MEM_TX_LOC_SIZE), 0x8000);

View File

@ -37,7 +37,7 @@
#define SHARED_MEM_TX_CMD_TERMINATE 0x06
#define SHARED_MEM_TX_LOC_STATE 0x000000
#define SHARED_MEM_TX_LOC_SIZE 0x000100
#define SHARED_MEM_TX_LOC_SIZE 0x000040
#define SHARED_MEM_TX_LOC_CMD 0x000001
#define SHARED_MEM_TX_LOC_PAYLOAD 0x000002
@ -48,7 +48,7 @@
#define SHARED_MEM_RX_CMD_FILESEL 0x01
#define SHARED_MEM_RX_LOC_STATE 0x001000
#define SHARED_MEM_RX_LOC_SIZE 0x000100
#define SHARED_MEM_RX_LOC_SIZE 0x000040
#define SHARED_MEM_RX_LOC_CMD 0x001001
#define SHARED_MEM_RX_LOC_LEN 0x001002
#define SHARED_MEM_RX_LOC_PAYLOAD 0x001003