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
#-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)

View File

@ -15,7 +15,7 @@
*/
#define BANK_SIZE_SHIFT 16
#define BANK_SIZE_SHIFT 15
#define BANK_SIZE (1<<BANK_SIZE_SHIFT)
#define READ_BUFFER_SIZE (1<<BANK_SIZE_SHIFT)
#define SEND_BUFFER_SIZE 128
@ -192,6 +192,14 @@ int main(int argc, char **argv)
crc_buffer = (unsigned char *) malloc(0x1000);
memset(crc_buffer, 0, 0x1000);
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,
USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_ENDPOINT_OUT,
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,
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);

View File

@ -15,7 +15,8 @@
#define REQ_STATUS_BULK_UPLOAD 0x03
#define REQ_STATUS_BULK_NEXT 0x04
#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_CRC_CHECK 0x01

View File

@ -16,6 +16,7 @@
#include "crc.h"
#include "usb_bulk.h"
#include "timer.h"
#include "watchdog.h"
extern FILE uart_stdout;
@ -37,6 +38,9 @@ uint8_t data_buffer[4];
uint32_t addr;
uint16_t crc = 0;
usbMsgLen_t usbFunctionSetup(uchar data[8])
{
@ -193,9 +197,23 @@ usbMsgLen_t usbFunctionSetup(uchar data[8])
/*
* -------------------------------------------------------------------------
*/
} else if (rq->bRequest == USB_SNES_BOOT) {
req_state = REQ_STATUS_BOOT;
debug(DEBUG_USB,"USB_SNES_BOOT:\n");
} else if (rq->bRequest == USB_MODE_SNES) {
req_state = REQ_STATUS_SNES;
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;
/*
* -------------------------------------------------------------------------
@ -306,8 +324,14 @@ int main(void)
uart_init();
stdout = &uart_stdout;
system_init();
printf("Sytem Init\n");
printf("Sytem start\n");
#if 0
wdt_init();
printf("Watchdog init\n");
#endif
#if 0
test_read_write();
@ -317,7 +341,7 @@ int main(void)
#endif
usbInit();
printf("USB Init\n");
printf("USB init\n");
usbDeviceDisconnect(); /* enforce re-enumeration, do this while
* interrupts are disabled! */
cli();
@ -328,13 +352,14 @@ int main(void)
_delay_ms(35);
led_off();
_delay_ms(65);
}
led_on();
usbDeviceConnect();
printf("USB connect\n");
while (1){
avr_bus_active();
printf("Activate AVR bus\n");
@ -350,17 +375,15 @@ int main(void)
sei();
printf("USB poll\n");
while (req_state != REQ_STATUS_BOOT){
while (req_state != REQ_STATUS_SNES){
usbPoll();
}
printf("USB poll done\n");
usbDeviceDisconnect();
printf("USB disconnect\n");
#if 0
#if 0
crc_check_bulk_memory(0x000000, req_addr_end, req_bank_size);
#endif
#endif
snes_irq_lo();
snes_irq_off();
@ -379,7 +402,10 @@ int main(void)
snes_bus_active();
printf("Activate Snes bus\n");
while(1);
while (req_state != REQ_STATUS_AVR){
usbPoll();
}
}
return 0;
}

View File

@ -29,6 +29,8 @@
#define USB_BULK_UPLOAD_ADDR 7
#define USB_BULK_UPLOAD_NEXT 8
#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__ */

View File

@ -141,6 +141,11 @@ snesram_write_rom (const char *filename)
printf ("Press q to abort\n\n");
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,
USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_ENDPOINT_OUT,
@ -197,7 +202,7 @@ snesram_write_rom (const char *filename)
#endif
cnt = usb_control_msg(handle,
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);

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_NEXT 8
#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 --------------------------- */