瀏覽代碼

add first batch of commands to shell

optixx 14 年之前
父節點
當前提交
ec68a9a1a1
共有 8 個文件被更改,包括 122 次插入73 次删除
  1. 1 1
      avr/usbload/Makefile
  2. 54 0
      avr/usbload/command.c
  3. 1 0
      avr/usbload/command.h
  4. 3 2
      avr/usbload/config.h
  5. 10 50
      avr/usbload/main.c
  6. 51 18
      avr/usbload/shell.c
  7. 1 1
      avr/usbload/usbconfig.h
  8. 1 1
      avr/usbload/util.c

+ 1 - 1
avr/usbload/Makefile

@@ -39,7 +39,7 @@ else
     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 \
-              pwm.o uril.o shell.o info.o shared_memory.o command.o irq.o
+              pwm.o util.o shell.o info.o shared_memory.o command.o irq.o
 endif
 
 COMPILE = avr-gcc -Wall -Os -DF_CPU=$(F_CPU) $(CFLAGS) -mmcu=$(DEVICE)

+ 54 - 0
avr/usbload/command.c

@@ -29,8 +29,11 @@
 #include "info.h"
 #include "irq.h"
 #include "usbdrv.h"
+#include "rle.h"
+#include "loader.h"
 
 extern uint32_t req_bank_size;
+extern const char _rom[] PROGMEM;
 
 void usb_connect()
 {
@@ -81,3 +84,54 @@ void set_rom_mode()
         info_P(PSTR("Set SNES hirom \n"));
     }
 }
+
+
+void boot_startup_rom(uint16_t init_delay)
+{
+    info_P(PSTR("Fetch loader rom\n"));
+    info_P(PSTR("Activate AVR bus\n"));
+    avr_bus_active();
+    info_P(PSTR("IRQ off\n"));
+    snes_irq_lo();
+    snes_irq_off();
+    snes_lorom();
+    rle_decode(&_rom, ROM_BUFFER_SIZE, 0x000000);
+    info_P(PSTR("\n"));
+
+#if DO_CRC_CHECK_LOADER     
+    dump_memory(0x010000 - 0x100, 0x010000);
+    uint16_t crc;
+    crc = crc_check_bulk_memory((uint32_t)0x000000,0x010000, 0x010000);
+    info(PSTR("crc=%x\n"),crc);
+#endif
+
+    snes_irq_lo();
+    snes_irq_off();
+    snes_hirom();
+    snes_wr_disable();
+    
+    snes_bus_active();
+    info_P(PSTR("Activate SNES bus\n"));
+    send_reset();
+    _delay_ms(init_delay);
+}
+
+
+
+
+void banner(){
+    uint8_t i;
+    for (i=0;i<40;i++)
+        info_P(PSTR("\n"));
+    info_P(PSTR(" ________        .__        __    ________               ____  ________\n"));
+    info_P(PSTR(" \\_____  \\  __ __|__| ____ |  | __\\______ \\   _______  _/_   |/  _____/\n"));
+    info_P(PSTR("  /  / \\  \\|  |  \\  |/ ___\\|  |/ / |    |  \\_/ __ \\  \\/ /|   /   __  \\ \n"));
+    info_P(PSTR(" /   \\_/.  \\  |  /  \\  \\___|    <  |    `   \\  ___/\\   / |   \\  |__\\  \\ \n"));
+    info_P(PSTR(" \\_____\\ \\_/____/|__|\\___  >__|_ \\/_______  /\\___  >\\_/  |___|\\_____  / \n"));
+    info_P(PSTR("        \\__>             \\/     \\/        \\/     \\/                 \\/ \n"));
+    info_P(PSTR("\n"));
+    info_P(PSTR("                               www.optixx.org\n"));
+    info_P(PSTR("\n"));
+    info_P(PSTR("System Hw: %s Sw: %s\n"),HW_VERSION,SW_VERSION);
+    
+}

+ 1 - 0
avr/usbload/command.h

@@ -26,5 +26,6 @@ void send_reset();
 void send_irq();
 void set_rom_mode();
 void usb_connect();
+void boot_startup_rom(uint16_t init_delay);
 
 #endif

+ 3 - 2
avr/usbload/config.h

@@ -49,7 +49,8 @@
 
 #define DO_CRC_CHECK_LOADER         0
 #define DO_CRC_CHECK                0
-#define DO_SHM_SCRATCHPAD           1
-#define DO_SHM                      1
+#define DO_SHM_SCRATCHPAD           0
+#define DO_SHM                      0
+#define DO_TIMER                    0
 
 #endif 

+ 10 - 50
avr/usbload/main.c

@@ -51,7 +51,6 @@
 
 
 
-extern const char _rom[] PROGMEM;
 extern FILE uart_stdout;
 
 uint8_t debug_level = (DEBUG | DEBUG_USB | DEBUG_CRC | DEBUG_SHM );
@@ -101,9 +100,11 @@ usbMsgLen_t usbFunctionSetup(uchar data[8])
 
         shared_memory_write(SHARED_MEM_TX_CMD_UPLOAD_START, 0);
         shared_memory_write(SHARED_MEM_TX_CMD_BANK_COUNT, req_bank_cnt);
+#if DO_TIMER
         if (req_addr == 0x000000) {
             timer_start();
         }
+#endif       
         /*
          * -------------------------------------------------------------------------
          */
@@ -118,6 +119,8 @@ usbMsgLen_t usbFunctionSetup(uchar data[8])
         
 
         if (req_addr && req_addr % req_bank_size == 0) {
+#if DO_TIMER
+
 #ifdef FLT_DEBUG
             debug_P(DEBUG_USB,
                   PSTR("USB_BULK_UPLOAD_ADDR: req_bank=0x%02x addr=0x%08lx time=%.4f\n"),
@@ -126,9 +129,10 @@ usbMsgLen_t usbFunctionSetup(uchar data[8])
             debug_P(DEBUG_USB,
                   PSTR("USB_BULK_UPLOAD_ADDR: req_bank=0x%02x addr=0x%08lx time=%i\n"),
                   req_bank, req_addr, timer_stop_int());
+#endif
+              timer_start();
 #endif
             req_bank++;
-            timer_start();
 
         } else {
             sram_bulk_write_start(req_addr);
@@ -154,6 +158,8 @@ usbMsgLen_t usbFunctionSetup(uchar data[8])
         shared_memory_scratchpad_region_save_helper(req_addr);
         
         if (req_addr && (req_addr % req_bank_size) == 0) {
+#if DO_TIMER
+
 #ifdef FLT_DEBUG
             debug_P(DEBUG_USB,
                   PSTR("USB_BULK_UPLOAD_NEXT: req_bank=0x%02x addr=0x%08lx time=%.4f\n"),
@@ -162,9 +168,10 @@ usbMsgLen_t usbFunctionSetup(uchar data[8])
             debug_P(DEBUG_USB,
                   PSTR("USB_BULK_UPLOAD_NEXT: req_bank=0x%02x addr=0x%08lx time=%i\n"),
                   req_bank, req_addr, timer_stop_int());
+#endif
+              timer_start();
 #endif
             req_bank++;
-            timer_start();
             shared_memory_write(SHARED_MEM_TX_CMD_BANK_CURRENT, req_bank);
 
         }
@@ -251,53 +258,6 @@ usbMsgLen_t usbFunctionSetup(uchar data[8])
  */
 
 
-void boot_startup_rom(uint16_t init_delay)
-{
-    info_P(PSTR("Fetch loader rom\n"));
-    info_P(PSTR("Activate AVR bus\n"));
-    avr_bus_active();
-    info_P(PSTR("IRQ off\n"));
-    snes_irq_lo();
-    snes_irq_off();
-    snes_lorom();
-    rle_decode(&_rom, ROM_BUFFER_SIZE, 0x000000);
-    info_P(PSTR("\n"));
-
-#if DO_CRC_CHECK_LOADER     
-    dump_memory(0x010000 - 0x100, 0x010000);
-    uint16_t crc;
-    crc = crc_check_bulk_memory((uint32_t)0x000000,0x010000, 0x010000);
-    info(PSTR("crc=%x\n"),crc);
-#endif
-
-    snes_irq_lo();
-    snes_irq_off();
-    snes_hirom();
-    snes_wr_disable();
-    
-    snes_bus_active();
-    info_P(PSTR("Activate SNES bus\n"));
-    send_reset();
-    _delay_ms(init_delay);
-}
-
-void banner(){
-    uint8_t i;
-    for (i=0;i<40;i++)
-        info_P(PSTR("\n"));
-    info_P(PSTR(" ________        .__        __    ________               ____  ________\n"));
-    info_P(PSTR(" \\_____  \\  __ __|__| ____ |  | __\\______ \\   _______  _/_   |/  _____/\n"));
-    info_P(PSTR("  /  / \\  \\|  |  \\  |/ ___\\|  |/ / |    |  \\_/ __ \\  \\/ /|   /   __  \\ \n"));
-    info_P(PSTR(" /   \\_/.  \\  |  /  \\  \\___|    <  |    `   \\  ___/\\   / |   \\  |__\\  \\ \n"));
-    info_P(PSTR(" \\_____\\ \\_/____/|__|\\___  >__|_ \\/_______  /\\___  >\\_/  |___|\\_____  / \n"));
-    info_P(PSTR("        \\__>             \\/     \\/        \\/     \\/                 \\/ \n"));
-    info_P(PSTR("\n"));
-    info_P(PSTR("                               www.optixx.org\n"));
-    info_P(PSTR("\n"));
-    info_P(PSTR("System Hw: %s Sw: %s\n"),HW_VERSION,SW_VERSION);
-    
-}
-
 void globals_init(){
     req_addr = 0;
     req_addr_end = 0;

+ 51 - 18
avr/usbload/shell.c

@@ -35,10 +35,12 @@
 #include "uart.h"
 #include "dump.h"
 #include "irq.h"
+#include "crc.h"
+#include "command.h"
  
 #define RECEIVE_BUF_LEN 40
  
-uint8_t			recv_buf[RECEIVE_BUF_LEN];
+uint8_t	recv_buf[RECEIVE_BUF_LEN];
 volatile uint8_t	recv_counter = 0;
 volatile uint8_t	cr = 0;
 
@@ -54,11 +56,11 @@ uint8_t *get_token(void)
  	token_ptr = p;
  	do {
  		token_ptr++;
- 		if (*token_ptr == ' ') {
+ 		if (*token_ptr == ' ' || *token_ptr == '\n' || *token_ptr == '\r') {
  			*token_ptr++ = '\0';
  			break;
  		}
- 	} while (*token_ptr != '\0');
+ 	} while (*token_ptr != ' ' && *token_ptr != '\n' && *token_ptr != '\r');
  	return p;
 }
 
@@ -79,8 +81,6 @@ uint8_t get_dec(uint32_t *decval)
 uint8_t parse_hex(const uint8_t *s, uint32_t *hexval)
 {
  	uint32_t x = util_sscanhex(s);
- 	if (x > 0xffffff)
- 		return 0;
  	*hexval = (uint32_t) x;
  	return 1;
  }
@@ -142,7 +142,6 @@ static uint8_t get_int32(uint32_t *val)
      
      uart_putc('\r');
      uart_putc('\n');
-     uart_putc(':');
      uart_putc('>');
      
  }
@@ -185,6 +184,7 @@ void shell_run(void)
     uint32_t arg1;
     uint32_t arg2;
     uint32_t arg3;
+	uint16_t crc;
     
 	if (!cr)
         return;
@@ -203,25 +203,58 @@ void shell_run(void)
         if (get_hex_arg2(&arg1,&arg2))
             dump_memory(arg1,arg2);
         else 
-            printf("DUMP <start addr> <end addr> %i %i\n",arg1,arg2);
-    }
-	else if (strcmp((char*)t, "RESET") == 0) {
+            printf("DUMP <start addr> <end addr>\n");
+    
+    }else if (strcmp((char*)t, "CRC") == 0) {
+        if (get_hex_arg2(&arg1,&arg2)){
+            crc = crc_check_bulk_memory(arg1,arg2,0x8000);
+            printf("0x%06lx - 0x%06lx crc=0x%04x\n",arg1,arg2,crc);
+        } else 
+            printf("CRC <start addr> <end addr>\n");
+    }else if (strcmp((char*)t, "EXIT") == 0) {
         leave_application();
-    }
+    }else if (strcmp((char*)t, "RESET") == 0) {
+        send_reset();
+    }else if (strcmp((char*)t, "IRQ") == 0) {
+        printf("Send IRQ\n");
+        snes_irq_on();
+        snes_irq_lo();
+        _delay_us(20);
+        snes_irq_hi();
+        snes_irq_off();
+    }else if (strcmp((char*)t, "AVR") == 0) {
+         printf("Activate AVR bus\n");
+         avr_bus_active();
+         snes_irq_lo();
+         snes_irq_off();
+    }else if (strcmp((char*)t, "SNES") == 0) {
+        printf("Activate SNES bus\n");
+        snes_irq_lo();
+        snes_irq_off();
+        snes_wr_disable();
+        snes_bus_active();
+    }else if (strcmp((char*)t, "LOROM") == 0) {
+        printf("Set LOROM\n");
+        snes_lorom();
+        snes_wr_disable();
+    }else if (strcmp((char*)t, "HIROM") == 0) {
+        printf("Set HIROM\n");
+        snes_hirom();
+        snes_wr_disable();
+    }else if (strcmp((char*)t, "LOADER") == 0) {
+        boot_startup_rom(500);    
+    }else if (strcmp((char*)t, "RECONNECT") == 0) {
+        usb_connect();
+    }    
+    
     prompt();
     
     /*
-    reset
-    reset snes
     dias
-    switch to avr mode
-    swicth to snes mode
-    send irq
-    crc
     set irq vector
     set reset vector
-    set rom mode
-
+    dump cart header
+    */
     
     
     

+ 1 - 1
avr/usbload/usbconfig.h

@@ -127,7 +127,7 @@ section at the end of this file).
  * (e.g. HID), but never want to send any data. This option saves a couple
  * of bytes in flash memory and the transmit buffers in RAM.
  */
-#define USB_CFG_INTR_POLL_INTERVAL      200
+#define USB_CFG_INTR_POLL_INTERVAL      20
 /* If you compile a version with endpoint 1 (interrupt-in), this is the poll
  * interval. The value is in milliseconds and must not be less than 10 ms for
  * low speed devices.

+ 1 - 1
avr/usbload/util.c

@@ -101,7 +101,7 @@ uint32_t util_sscandec(const uint8_t *s)
 
 uint32_t util_sscanhex(const uint8_t *s)
 {
-	uint32_t result;
+	int32_t result;
 	if (*s == '\0')
 		return -1;
 	result = 0;