add reset via usb and usb triggered avr/snes mode switching

This commit is contained in:
David Voswinkel 2009-07-09 00:54:02 +02:00
parent d7b82e2503
commit 0f9ebb146e
7 changed files with 97 additions and 53 deletions

View File

@ -8,7 +8,7 @@ AVRDUDE = avrdude -c usbasp -p $(DEVICE)
CFLAGS = -Iusbdrv -I. -DDEBUG_LEVEL=0 CFLAGS = -Iusbdrv -I. -DDEBUG_LEVEL=0
#-std=gnu99 #-std=gnu99
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 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
COMPILE = avr-gcc -Wall -Os -DF_CPU=$(F_CPU) $(CFLAGS) -mmcu=$(DEVICE) COMPILE = avr-gcc -Wall -Os -DF_CPU=$(F_CPU) $(CFLAGS) -mmcu=$(DEVICE)

View File

@ -15,7 +15,7 @@
*/ */
#define BANK_SIZE_SHIFT 16 #define BANK_SIZE_SHIFT 15
#define BANK_SIZE (1<<BANK_SIZE_SHIFT) #define BANK_SIZE (1<<BANK_SIZE_SHIFT)
#define READ_BUFFER_SIZE (1<<BANK_SIZE_SHIFT) #define READ_BUFFER_SIZE (1<<BANK_SIZE_SHIFT)
#define SEND_BUFFER_SIZE 128 #define SEND_BUFFER_SIZE 128
@ -192,6 +192,14 @@ int main(int argc, char **argv)
crc_buffer = (unsigned char *) malloc(0x1000); crc_buffer = (unsigned char *) malloc(0x1000);
memset(crc_buffer, 0, 0x1000); memset(crc_buffer, 0, 0x1000);
addr = 0x000000; addr = 0x000000;
cnt = usb_control_msg(handle,
USB_TYPE_VENDOR | USB_RECIP_DEVICE |
USB_ENDPOINT_OUT, USB_MODE_AVR, 0, 0, NULL,
0, 5000);
cnt = usb_control_msg(handle, cnt = usb_control_msg(handle,
USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_ENDPOINT_OUT, USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_ENDPOINT_OUT,
USB_BULK_UPLOAD_INIT, BANK_SIZE_SHIFT , bank_cnt, NULL, 0, 5000); USB_BULK_UPLOAD_INIT, BANK_SIZE_SHIFT , bank_cnt, NULL, 0, 5000);
@ -261,7 +269,7 @@ int main(int argc, char **argv)
cnt = usb_control_msg(handle, cnt = usb_control_msg(handle,
USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_TYPE_VENDOR | USB_RECIP_DEVICE |
USB_ENDPOINT_OUT, USB_SNES_BOOT, 0, 0, NULL, USB_ENDPOINT_OUT, USB_MODE_SNES, 0, 0, NULL,
0, 5000); 0, 5000);

View File

@ -15,7 +15,8 @@
#define REQ_STATUS_BULK_UPLOAD 0x03 #define REQ_STATUS_BULK_UPLOAD 0x03
#define REQ_STATUS_BULK_NEXT 0x04 #define REQ_STATUS_BULK_NEXT 0x04
#define REQ_STATUS_CRC 0x05 #define REQ_STATUS_CRC 0x05
#define REQ_STATUS_BOOT 0x06 #define REQ_STATUS_SNES 0x06
#define REQ_STATUS_AVR 0x07
#define USB_MAX_TRANS 0xff #define USB_MAX_TRANS 0xff
#define USB_CRC_CHECK 0x01 #define USB_CRC_CHECK 0x01

View File

@ -16,6 +16,7 @@
#include "crc.h" #include "crc.h"
#include "usb_bulk.h" #include "usb_bulk.h"
#include "timer.h" #include "timer.h"
#include "watchdog.h"
extern FILE uart_stdout; extern FILE uart_stdout;
@ -37,6 +38,9 @@ uint8_t data_buffer[4];
uint32_t addr; uint32_t addr;
uint16_t crc = 0; uint16_t crc = 0;
usbMsgLen_t usbFunctionSetup(uchar data[8]) usbMsgLen_t usbFunctionSetup(uchar data[8])
{ {
@ -193,9 +197,23 @@ usbMsgLen_t usbFunctionSetup(uchar data[8])
/* /*
* ------------------------------------------------------------------------- * -------------------------------------------------------------------------
*/ */
} else if (rq->bRequest == USB_SNES_BOOT) { } else if (rq->bRequest == USB_MODE_SNES) {
req_state = REQ_STATUS_BOOT; req_state = REQ_STATUS_SNES;
debug(DEBUG_USB,"USB_SNES_BOOT:\n"); debug(DEBUG_USB,"USB_MODE_SNES:\n");
ret_len = 0;
/*
* -------------------------------------------------------------------------
*/
} else if (rq->bRequest == USB_MODE_AVR) {
req_state = REQ_STATUS_AVR;
debug(DEBUG_USB,"USB_MODE_AVR:\n");
ret_len = 0;
/*
* -------------------------------------------------------------------------
*/
} else if (rq->bRequest == USB_AVR_RESET) {
debug(DEBUG_USB,"USB_AVR_RESET:\n");
soft_reset();
ret_len = 0; ret_len = 0;
/* /*
* ------------------------------------------------------------------------- * -------------------------------------------------------------------------
@ -305,9 +323,15 @@ int main(void)
uart_init(); uart_init();
stdout = &uart_stdout; stdout = &uart_stdout;
system_init(); system_init();
printf("Sytem Init\n"); printf("Sytem start\n");
#if 0
wdt_init();
printf("Watchdog init\n");
#endif
#if 0 #if 0
test_read_write(); test_read_write();
@ -317,7 +341,7 @@ int main(void)
#endif #endif
usbInit(); usbInit();
printf("USB Init\n"); printf("USB init\n");
usbDeviceDisconnect(); /* enforce re-enumeration, do this while usbDeviceDisconnect(); /* enforce re-enumeration, do this while
* interrupts are disabled! */ * interrupts are disabled! */
cli(); cli();
@ -328,58 +352,60 @@ int main(void)
_delay_ms(35); _delay_ms(35);
led_off(); led_off();
_delay_ms(65); _delay_ms(65);
} }
led_on(); led_on();
usbDeviceConnect(); usbDeviceConnect();
printf("USB connect\n"); printf("USB connect\n");
avr_bus_active();
printf("Activate AVR bus\n");
printf("IRQ off\n");
snes_irq_lo();
snes_irq_off();
printf("Set Snes lowrom\n"); while (1){
snes_lorom(); avr_bus_active();
printf("Activate AVR bus\n");
printf("Disable snes WR\n"); printf("IRQ off\n");
snes_wr_disable(); snes_irq_lo();
snes_irq_off();
sei();
printf("USB poll\n");
while (req_state != REQ_STATUS_BOOT){
usbPoll();
}
printf("USB poll done\n");
usbDeviceDisconnect();
printf("USB disconnect\n");
#if 0 printf("Set Snes lowrom\n");
crc_check_bulk_memory(0x000000, req_addr_end, req_bank_size);
#endif
snes_irq_lo();
snes_irq_off();
printf("IRQ off\n");
if (req_bank_size == 0x8000){
snes_lorom(); snes_lorom();
printf("Set Snes lowrom \n");
} else {
snes_hirom();
printf("Set Snes hirom \n");
}
snes_wr_disable();
printf("Disable snes WR\n");
snes_bus_active();
printf("Activate Snes bus\n");
while(1); printf("Disable snes WR\n");
snes_wr_disable();
sei();
printf("USB poll\n");
while (req_state != REQ_STATUS_SNES){
usbPoll();
}
printf("USB poll done\n");
#if 0
crc_check_bulk_memory(0x000000, req_addr_end, req_bank_size);
#endif
snes_irq_lo();
snes_irq_off();
printf("IRQ off\n");
if (req_bank_size == 0x8000){
snes_lorom();
printf("Set Snes lowrom \n");
} else {
snes_hirom();
printf("Set Snes hirom \n");
}
snes_wr_disable();
printf("Disable snes WR\n");
snes_bus_active();
printf("Activate Snes bus\n");
while (req_state != REQ_STATUS_AVR){
usbPoll();
}
}
return 0; return 0;
} }

View File

@ -29,6 +29,8 @@
#define USB_BULK_UPLOAD_ADDR 7 #define USB_BULK_UPLOAD_ADDR 7
#define USB_BULK_UPLOAD_NEXT 8 #define USB_BULK_UPLOAD_NEXT 8
#define USB_BULK_UPLOAD_END 9 #define USB_BULK_UPLOAD_END 9
#define USB_SNES_BOOT 10 #define USB_MODE_SNES 10
#define USB_MODE_AVR 11
#define USB_AVR_RESET 12
#endif /* __REQUESTS_H_INCLUDED__ */ #endif /* __REQUESTS_H_INCLUDED__ */

View File

@ -141,6 +141,11 @@ snesram_write_rom (const char *filename)
printf ("Press q to abort\n\n"); printf ("Press q to abort\n\n");
starttime = time (NULL); starttime = time (NULL);
cnt = usb_control_msg(handle,
USB_TYPE_VENDOR | USB_RECIP_DEVICE |
USB_ENDPOINT_OUT, USB_MODE_AVR, 0, 0, NULL,
0, 5000);
cnt = usb_control_msg(handle, cnt = usb_control_msg(handle,
USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_ENDPOINT_OUT, USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_ENDPOINT_OUT,
@ -197,7 +202,7 @@ snesram_write_rom (const char *filename)
#endif #endif
cnt = usb_control_msg(handle, cnt = usb_control_msg(handle,
USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_TYPE_VENDOR | USB_RECIP_DEVICE |
USB_ENDPOINT_OUT, USB_SNES_BOOT, 0, 0, NULL, USB_ENDPOINT_OUT, USB_MODE_SNES, 0, 0, NULL,
0, 5000); 0, 5000);

View File

@ -34,7 +34,9 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
#define USB_BULK_UPLOAD_ADDR 7 #define USB_BULK_UPLOAD_ADDR 7
#define USB_BULK_UPLOAD_NEXT 8 #define USB_BULK_UPLOAD_NEXT 8
#define USB_BULK_UPLOAD_END 9 #define USB_BULK_UPLOAD_END 9
#define USB_SNES_BOOT 10 #define USB_MODE_SNES 10
#define USB_MODE_AVR 11
#define USB_AVR_RESET 12
/* -------------------------- Device Description --------------------------- */ /* -------------------------- Device Description --------------------------- */