Sfoglia il codice sorgente

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

David Voswinkel 15 anni fa
parent
commit
0f9ebb146e

+ 1 - 1
avr/usbload/Makefile

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

+ 10 - 2
avr/usbload/commandline/snesuploader.c

@@ -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);
         
 

+ 2 - 1
avr/usbload/config.h

@@ -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

+ 69 - 43
avr/usbload/main.c

@@ -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;
 /*
  * -------------------------------------------------------------------------
@@ -305,9 +323,15 @@ 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,58 +352,60 @@ int main(void)
         _delay_ms(35);
         led_off();
         _delay_ms(65);
-        
     }
     led_on();
     
     usbDeviceConnect();
     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");
-    snes_lorom();
+    while (1){
+        avr_bus_active();
+        printf("Activate AVR bus\n");
 
-    printf("Disable snes WR\n");
-    snes_wr_disable(); 
-    
-    sei();
-    printf("USB poll\n");
-    while (req_state != REQ_STATUS_BOOT){
-        usbPoll();
-    }
-    printf("USB poll done\n");
+        printf("IRQ off\n");
+        snes_irq_lo();
+        snes_irq_off();
+
+        printf("Set Snes lowrom\n");
+        snes_lorom();
+
+        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");
     
-    usbDeviceDisconnect();      
-    printf("USB disconnect\n");
 
-#if 0    
-    crc_check_bulk_memory(0x000000, req_addr_end, req_bank_size);
-#endif
+    #if 0    
+        crc_check_bulk_memory(0x000000, req_addr_end, req_bank_size);
+    #endif
 
-    snes_irq_lo();
-    snes_irq_off();
+        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");
+        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");
+        snes_bus_active();
+        printf("Activate Snes bus\n");
 
-    while(1);
+        while (req_state != REQ_STATUS_AVR){
+            usbPoll();
+        }
+    }
      
     return 0;
 }

+ 3 - 1
avr/usbload/requests.h

@@ -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__ */

+ 6 - 1
tools/ucon64/2.0/src/backup/snesram.c

@@ -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);
 
 

+ 3 - 1
tools/ucon64/2.0/src/backup/snesram.h

@@ -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 --------------------------- */