diff --git a/avr/usbload/Makefile b/avr/usbload/Makefile index ac14318..03a7ec2 100644 --- a/avr/usbload/Makefile +++ b/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) diff --git a/avr/usbload/command.c b/avr/usbload/command.c index f61e1fe..0b109c5 100644 --- a/avr/usbload/command.c +++ b/avr/usbload/command.c @@ -29,8 +29,12 @@ #include "info.h" #include "irq.h" #include "usbdrv.h" +#include "rle.h" +#include "loader.h" -extern uint32_t req_bank_size; +extern usb_transaction_t usb_trans; + +extern const char _rom[] PROGMEM; void usb_connect() { @@ -73,7 +77,7 @@ void send_irq() void set_rom_mode() { - if (req_bank_size == 0x8000) { + if (usb_trans.req_bank_size == 0x8000) { snes_lorom(); info_P(PSTR("Set SNES lowrom \n")); } else { @@ -81,3 +85,63 @@ 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); + +} + +void transaction_status(){ + info_P(PSTR("\nAddr 0x%06lx\n"),usb_trans.req_addr); + info_P(PSTR("Bank 0x%02x\n"),usb_trans.req_bank); + info_P(PSTR("Banksize 0x%06lx\n"),usb_trans.req_bank_size); + info_P(PSTR("Bankcount 0x%02x\n"),usb_trans.req_bank_cnt); + info_P(PSTR("Status 0x%02x\n"),usb_trans.req_state); + info_P(PSTR("Percent %02i\n"),usb_trans.req_percent); + info_P(PSTR("TX buffer %02i\n"),usb_trans.tx_remaining); + info_P(PSTR("RX buffer %02i\n"),usb_trans.rx_remaining); + info_P(PSTR("Syncerr %02i\n"),usb_trans.sync_errors); +} \ No newline at end of file diff --git a/avr/usbload/command.h b/avr/usbload/command.h index 4c6b633..e985c98 100644 --- a/avr/usbload/command.h +++ b/avr/usbload/command.h @@ -26,5 +26,9 @@ void send_reset(); void send_irq(); void set_rom_mode(); void usb_connect(); +void boot_startup_rom(uint16_t init_delay); +void banner(); +void transaction_status(); + #endif diff --git a/avr/usbload/config.h b/avr/usbload/config.h index 5759072..ace6b64 100644 --- a/avr/usbload/config.h +++ b/avr/usbload/config.h @@ -43,7 +43,8 @@ #define USB_CRC_CHECK 0x01 #define TRANSFER_BUFFER_SIZE 0x000 -#define FORMAT_BUFFER_LEN 0x100 +#define FORMAT_BUFFER_LEN 0x080 +#define RECEIVE_BUF_LEN 0x030 #define HW_VERSION "2.6" #define SW_VERSION "1.0" @@ -51,5 +52,6 @@ #define DO_CRC_CHECK 0 #define DO_SHM_SCRATCHPAD 1 #define DO_SHM 1 +#define DO_TIMER 1 #endif diff --git a/avr/usbload/main.c b/avr/usbload/main.c index 0db4444..cbde83c 100644 --- a/avr/usbload/main.c +++ b/avr/usbload/main.c @@ -26,6 +26,7 @@ #include #include #include +#include #include "usbdrv.h" #include "oddebug.h" @@ -51,31 +52,17 @@ -extern const char _rom[] PROGMEM; extern FILE uart_stdout; uint8_t debug_level = (DEBUG | DEBUG_USB | DEBUG_CRC | DEBUG_SHM ); -uint8_t read_buffer[TRANSFER_BUFFER_SIZE]; -uint32_t req_addr = 0; -uint32_t req_addr_end = 0; -uint32_t req_size; -uint8_t req_bank; -uint32_t req_bank_size; -uint16_t req_bank_cnt; -uint8_t req_percent; -uint8_t req_percent_last; -uint8_t req_state = REQ_STATUS_IDLE; -uint8_t rx_remaining = 0; -uint8_t tx_remaining = 0; -uint16_t sync_errors = 0; -uint8_t tx_buffer[32]; -uint8_t data_buffer[4]; -uint32_t addr; -uint16_t crc = 0; -uint8_t loader_enabled = 1; - +typedef struct system_t { + uint8_t bus_mode; + uint8_t rom_mode; + uint8_t req_bank; +} system_t; +usb_transaction_t usb_trans; usbMsgLen_t usbFunctionSetup(uchar data[8]) { @@ -85,129 +72,139 @@ usbMsgLen_t usbFunctionSetup(uchar data[8]) if (rq->bRequest == USB_BULK_UPLOAD_INIT) { - req_bank = 0; - rx_remaining = 0; + usb_trans.req_bank = 0; + usb_trans.rx_remaining = 0; debug_P(DEBUG_USB, PSTR("USB_BULK_UPLOAD_INIT: %i %i\n"), rq->wValue.word, rq->wIndex.word); - req_bank_size = (uint32_t) (1L << rq->wValue.word); - req_bank_cnt = rq->wIndex.word; - req_addr_end = (uint32_t) req_bank_size *req_bank_cnt; - req_percent = 0; - req_percent_last = 0; - sync_errors = 0; + usb_trans.req_bank_size = (uint32_t) (1L << rq->wValue.word); + usb_trans.req_bank_cnt = rq->wIndex.word; + usb_trans.req_addr_end = (uint32_t) usb_trans.req_bank_size * usb_trans.req_bank_cnt; + usb_trans.req_percent = 0; + usb_trans.req_percent_last = 0; + usb_trans.sync_errors = 0; debug_P(DEBUG_USB, PSTR("USB_BULK_UPLOAD_INIT: bank_size=0x%08lx bank_cnt=0x%x end_addr=0x%08lx\n"), - req_bank_size, req_bank_cnt, req_addr_end); + usb_trans.req_bank_size, usb_trans.req_bank_cnt, usb_trans.req_addr_end); shared_memory_write(SHARED_MEM_TX_CMD_UPLOAD_START, 0); - shared_memory_write(SHARED_MEM_TX_CMD_BANK_COUNT, req_bank_cnt); - if (req_addr == 0x000000) { + shared_memory_write(SHARED_MEM_TX_CMD_BANK_COUNT, usb_trans.req_bank_cnt); +#if DO_TIMER + if (usb_trans.req_addr == 0x000000) { timer_start(); } +#endif /* * ------------------------------------------------------------------------- */ } else if (rq->bRequest == USB_BULK_UPLOAD_ADDR) { - req_state = REQ_STATUS_BULK_UPLOAD; - req_addr = rq->wValue.word; - req_addr = req_addr << 16; - req_addr = req_addr | rq->wIndex.word; - rx_remaining = rq->wLength.word; + usb_trans.req_state = REQ_STATUS_BULK_UPLOAD; + usb_trans.req_addr = rq->wValue.word; + usb_trans.req_addr = usb_trans.req_addr << 16; + usb_trans.req_addr = usb_trans.req_addr | rq->wIndex.word; + usb_trans.rx_remaining = rq->wLength.word; - if (req_addr && req_addr % req_bank_size == 0) { + if (usb_trans.req_addr && usb_trans.req_addr % usb_trans.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"), - req_bank, req_addr, timer_stop()); + usb_trans.req_bank, usb_trans.req_addr, timer_stop()); #else 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()); + usb_trans.req_bank, usb_trans.req_addr, timer_stop_int()); #endif - req_bank++; - timer_start(); + timer_start(); +#endif + usb_trans.req_bank++; + } else { + sram_bulk_write_start(usb_trans.req_addr); } - sram_bulk_write_start(req_addr); - ret_len = USB_MAX_TRANS; /* * ------------------------------------------------------------------------- */ } else if (rq->bRequest == USB_BULK_UPLOAD_NEXT) { - req_state = REQ_STATUS_BULK_UPLOAD; - req_addr = rq->wValue.word; - req_addr = req_addr << 16; - req_addr = req_addr | rq->wIndex.word; - rx_remaining = rq->wLength.word; + usb_trans.req_state = REQ_STATUS_BULK_UPLOAD; + usb_trans.req_addr = rq->wValue.word; + usb_trans.req_addr = usb_trans.req_addr << 16; + usb_trans.req_addr = usb_trans.req_addr | rq->wIndex.word; + usb_trans.rx_remaining = rq->wLength.word; - req_percent = (uint32_t)( 100 * req_addr ) / req_addr_end; - if (req_percent!=req_percent_last){ - shared_memory_write(SHARED_MEM_TX_CMD_UPLOAD_PROGESS, req_percent); +#if DO_SHM + usb_trans.req_percent = (uint32_t)( 100 * usb_trans.req_addr ) / usb_trans.req_addr_end; + if (usb_trans.req_percent!=usb_trans.req_percent_last){ + shared_memory_write(SHARED_MEM_TX_CMD_UPLOAD_PROGESS, usb_trans.req_percent); } - req_percent_last = req_percent; + usb_trans.req_percent_last = usb_trans.req_percent; + shared_memory_scratchpad_region_save_helper(usb_trans.req_addr); +#endif + if (usb_trans.req_addr && (usb_trans.req_addr % usb_trans.req_bank_size) == 0) { +#if DO_TIMER - shared_memory_scratchpad_region_save_helper(req_addr); - - if (req_addr && (req_addr % req_bank_size) == 0) { #ifdef FLT_DEBUG debug_P(DEBUG_USB, PSTR("USB_BULK_UPLOAD_NEXT: req_bank=0x%02x addr=0x%08lx time=%.4f\n"), - req_bank, req_addr, timer_stop()); + usb_trans.req_bank, usb_trans.req_addr, timer_stop()); #else 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()); + usb_trans.req_bank, usb_trans.req_addr, timer_stop_int()); +#endif + timer_start(); +#endif + usb_trans.req_bank++; +#if DO_SHM + shared_memory_write(SHARED_MEM_TX_CMD_BANK_CURRENT, usb_trans.req_bank); #endif - req_bank++; - timer_start(); - shared_memory_write(SHARED_MEM_TX_CMD_BANK_CURRENT, req_bank); - } ret_len = USB_MAX_TRANS; /* * ------------------------------------------------------------------------- */ } else if (rq->bRequest == USB_BULK_UPLOAD_END) { - if (req_state != REQ_STATUS_BULK_UPLOAD) { + if (usb_trans.req_state != REQ_STATUS_BULK_UPLOAD) { debug_P(DEBUG_USB, PSTR("USB_BULK_UPLOAD_END: ERROR state is not REQ_STATUS_BULK_UPLOAD\n")); return 0; } debug_P(DEBUG_USB, PSTR("USB_BULK_UPLOAD_END:\n")); - req_state = REQ_STATUS_IDLE; + usb_trans.req_state = REQ_STATUS_IDLE; sram_bulk_write_end(); +#if DO_SHM shared_memory_write(SHARED_MEM_TX_CMD_UPLOAD_END, 0); +#endif ret_len = 0; /* * ------------------------------------------------------------------------- */ } else if (rq->bRequest == USB_CRC) { - req_addr = rq->wValue.word; - req_addr = req_addr << 16; - req_addr = req_addr | rq->wIndex.word; - debug_P(DEBUG_USB, PSTR("USB_CRC: addr=0x%08lx \n"), req_addr); - crc_check_bulk_memory(0x000000, req_addr, req_bank_size); + usb_trans.req_addr = rq->wValue.word; + usb_trans.req_addr = usb_trans.req_addr << 16; + usb_trans.req_addr = usb_trans.req_addr | rq->wIndex.word; + debug_P(DEBUG_USB, PSTR("USB_CRC: addr=0x%08lx \n"), usb_trans.req_addr); + crc_check_bulk_memory(0x000000, usb_trans.req_addr, usb_trans.req_bank_size); ret_len = 0; /* * ------------------------------------------------------------------------- */ } else if (rq->bRequest == USB_MODE_SNES) { - req_state = REQ_STATUS_SNES; + usb_trans.req_state = REQ_STATUS_SNES; debug_P(DEBUG_USB, PSTR("USB_MODE_SNES:\n")); ret_len = 0; - pwm_stop(); /* * ------------------------------------------------------------------------- */ } else if (rq->bRequest == USB_MODE_AVR) { - req_state = REQ_STATUS_AVR; + usb_trans.req_state = REQ_STATUS_AVR; debug_P(DEBUG_USB, PSTR("USB_MODE_AVR:\n")); ret_len = 0; /* @@ -220,96 +217,29 @@ usbMsgLen_t usbFunctionSetup(uchar data[8]) /* * ------------------------------------------------------------------------- */ - - } else if (rq->bRequest == USB_CRC_ADDR) { - req_state = REQ_STATUS_CRC; - req_addr = rq->wValue.word; - req_addr = req_addr << 16; - req_addr = req_addr | rq->wIndex.word; - debug_P(DEBUG_USB, PSTR("USB_CRC_ADDR: addr=0x%lx size=%i\n"), req_addr, - rq->wLength.word); - req_size = rq->wLength.word; - req_size = req_size << 2; - tx_remaining = 2; - debug_P(DEBUG_USB, PSTR("USB_CRC_ADDR: addr=0x%lx size=%li\n"), req_addr, - req_size); - - crc = crc_check_memory_range(req_addr, req_size, read_buffer); - tx_buffer[0] = crc & 0xff; - tx_buffer[1] = (crc >> 8) & 0xff; - ret_len = 2; - req_state = REQ_STATUS_IDLE; - - } else if (rq->bRequest == USB_SET_LAODER) { - loader_enabled = rq->wValue.word; + usb_trans.loader_enabled = rq->wValue.word; ret_len = 0; } - - usbMsgPtr = data_buffer; - return ret_len; /* default for not implemented requests: return no data back to host */ + usbMsgPtr = usb_trans.rx_buffer; + return ret_len; } - /* * ------------------------------------------------------------------------- */ -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; - req_state = REQ_STATUS_IDLE; - rx_remaining = 0; - tx_remaining = 0; - sync_errors = 0; + memset(&usb_trans,0,sizeof(usb_transaction_t)); + + usb_trans.req_addr = 0; + usb_trans.req_addr_end = 0; + usb_trans.req_state = REQ_STATUS_IDLE; + usb_trans.rx_remaining = 0; + usb_trans.tx_remaining = 0; + usb_trans.sync_errors = 0; + usb_trans.loader_enabled = 1; } int main(void) @@ -341,13 +271,15 @@ int main(void) snes_wr_disable(); sei(); info_P(PSTR("USB poll\n")); - while (req_state != REQ_STATUS_SNES) { + while (usb_trans.req_state != REQ_STATUS_SNES) { usbPoll(); shell_run(); } +#if DO_SHM shared_memory_write(SHARED_MEM_TX_CMD_TERMINATE, 0); +#endif #if DO_SHM_SCRATCHPAD shared_memory_scratchpad_region_tx_restore(); @@ -356,7 +288,7 @@ int main(void) #if DO_CRC_CHECK info_P(PSTR("-->CRC Check\n")); - crc_check_bulk_memory(0x000000, req_bank_size * req_bank_cnt, req_bank_size); + crc_check_bulk_memory(0x000000, usb_trans.req_bank_size * usb_trans.req_bank_cnt, usb_trans.req_bank_size); #endif info_P(PSTR("-->Switch TO SNES\n")); @@ -368,24 +300,20 @@ int main(void) irq_stop(); send_reset(); info_P(PSTR("Poll USB\n")); - while ((req_state != REQ_STATUS_AVR)) { + while ((usb_trans.req_state != REQ_STATUS_AVR)) { usbPoll(); shell_run(); } info_P(PSTR("-->Switch TO AVR\n")); - shared_memory_init(); irq_init(); - - if(loader_enabled) + if(usb_trans.loader_enabled) boot_startup_rom(500); else { avr_bus_active(); send_reset(); } - - } return 0; } diff --git a/avr/usbload/pwm.c b/avr/usbload/pwm.c index 3c0a180..f1073d4 100644 --- a/avr/usbload/pwm.c +++ b/avr/usbload/pwm.c @@ -30,17 +30,17 @@ #define PWM_SINE_MAX 64 #define PWM_OVERFLOW_MAX 1024 -uint8_t pwm_sine_table[] = { +uint8_t pwm_sine_table[] = { 0x7f,0x8b,0x97,0xa4,0xaf,0xbb,0xc5,0xcf,0xd9,0xe1,0xe8,0xef,0xf4,0xf8,0xfb,0xfd, 0xfd,0xfd,0xfb,0xf8,0xf3,0xee,0xe7,0xe0,0xd7,0xce,0xc4,0xb9,0xae,0xa2,0x96,0x89, 0x7e,0x71,0x65,0x59,0x4d,0x42,0x37,0x2d,0x24,0x1c,0x15,0x0f,0x09,0x05,0x03,0x01, 0x01,0x01,0x03,0x07,0x0b,0x11,0x17,0x1f,0x28,0x31,0x3b,0x46,0x52,0x5e,0x6a,0x76 }; - volatile uint8_t pwm_setting; // Einstellungen für die einzelnen PWM-Kanäle - volatile uint16_t pwm_overflow; // Einstellungen für die einzelnen PWM-Kanäle - volatile uint8_t pwm_idx; // Einstellungen für die einzelnen PWM-Kanäle - volatile uint16_t pwm_overflow_max; // Einstellungen für die einzelnen PWM-Kanäle +volatile uint8_t pwm_setting; +volatile uint16_t pwm_overflow; +volatile uint8_t pwm_idx; +volatile uint16_t pwm_overflow_max; ISR(TIMER2_COMPA_vect) { static uint8_t pwm_cnt=0; @@ -67,6 +67,19 @@ void pwm_speed(uint16_t val) { pwm_overflow_max = val; } +void pwm_speed_slow(uint16_t val) { + pwm_overflow_max = PWM_OVERFLOW_MAX * 2 ; +} + +void pwm_speed_fast(uint16_t val) { + pwm_overflow_max = PWM_OVERFLOW_MAX / 2; +} + +void pwm_speed_normal(uint16_t val) { + pwm_overflow_max = PWM_OVERFLOW_MAX; +} + + void pwm_set(uint8_t val) { pwm_setting = val; } diff --git a/avr/usbload/requests.h b/avr/usbload/requests.h index 9604dc1..851dd6f 100644 --- a/avr/usbload/requests.h +++ b/avr/usbload/requests.h @@ -40,4 +40,21 @@ #define USB_AVR_RESET 12 #define USB_SET_LAODER 13 +typedef struct usb_transaction_t { + uint32_t req_addr; + uint32_t req_addr_end; + uint8_t req_bank; + uint32_t req_bank_size; + uint16_t req_bank_cnt; + uint8_t req_percent; + uint8_t req_percent_last; + uint8_t req_state; + uint8_t rx_remaining; + uint8_t tx_remaining ; + uint16_t sync_errors; + uint8_t tx_buffer[32]; + uint8_t rx_buffer[8]; + uint8_t loader_enabled; +} usb_transaction_t; + #endif /* __REQUESTS_H_INCLUDED__ */ diff --git a/avr/usbload/shared_memory.h b/avr/usbload/shared_memory.h index 249cd51..6b8bd92 100644 --- a/avr/usbload/shared_memory.h +++ b/avr/usbload/shared_memory.h @@ -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 diff --git a/avr/usbload/shell.c b/avr/usbload/shell.c index 0999be0..2b9dedc 100644 --- a/avr/usbload/shell.c +++ b/avr/usbload/shell.c @@ -35,10 +35,17 @@ #include "uart.h" #include "dump.h" #include "irq.h" +#include "config.h" +#include "crc.h" +#include "command.h" +#include "shared_memory.h" + -#define RECEIVE_BUF_LEN 40 + -uint8_t recv_buf[RECEIVE_BUF_LEN]; +uint8_t command_buf[RECEIVE_BUF_LEN]; +uint8_t recv_buf[RECEIVE_BUF_LEN]; + volatile uint8_t recv_counter = 0; volatile uint8_t cr = 0; @@ -54,11 +61,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 +86,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; } @@ -107,7 +112,7 @@ uint8_t get_hex_arg3(uint32_t *hexval1, uint32_t *hexval2, uint32_t *hexval3) static uint8_t get_int32(uint32_t *val) { if (!get_hex(val)){ - printf("Invalid argument!\n"); + info_P(PSTR("Invalid argument!\n")); return 0; } else { return 1; @@ -118,7 +123,7 @@ static uint8_t get_int32(uint32_t *val) { uint32_t ret; if (!get_hex(&ret) ||ret > 0xff){ - printf("Invalid argument!\n"); + info_P(PSTR("Invalid argument!\n")); return 0; }else{ *val = (uint8_t)ret; @@ -135,14 +140,13 @@ static uint8_t get_int32(uint32_t *val) if (result >= 0) return result; } - printf("Invalid argument (should be 0 or 1)!\n"); + info_P(PSTR("Invalid argument (should be 0 or 1)!\n")); return -1; } void prompt(void){ uart_putc('\r'); uart_putc('\n'); - uart_putc(':'); uart_putc('>'); } @@ -176,8 +180,55 @@ ISR(USART0_RX_vect) // Interrupt for UART Byte received UCSR0B |= (1< %i %i\n",arg1,arg2); - } - else if (strcmp((char*)t, "RESET") == 0) { - leave_application(); - } - prompt(); + info_P(PSTR("DUMP \n")); + }else if (strcmp_P((char*)t, (PGM_P)cmdlist[CMD_CRC]) == 0) { + if (get_hex_arg2(&arg1,&arg2)){ + crc = crc_check_bulk_memory(arg1,arg2,0x8000); + info_P(PSTR("0x%06lx - 0x%06lx crc=0x%04x\n"),arg1,arg2,crc); + } else + info_P(PSTR("CRC \n")); + }else if (strcmp_P((char*)t, (PGM_P)cmdlist[CMD_EXIT]) == 0) { + leave_application(); + }else if (strcmp_P((char*)t, (PGM_P)cmdlist[CMD_RESET]) == 0) { + send_reset(); + }else if (strcmp_P((char*)t, (PGM_P)cmdlist[CMD_IRQ]) == 0) { + info_P(PSTR("Send IRQ\n")); + snes_irq_on(); + snes_irq_lo(); + _delay_us(20); + snes_irq_hi(); + snes_irq_off(); + }else if (strcmp_P((char*)t, (PGM_P)cmdlist[CMD_AVR]) == 0) { + info_P(PSTR("Activate AVR bus\n")); + avr_bus_active(); + snes_irq_lo(); + snes_irq_off(); + }else if (strcmp_P((char*)t, (PGM_P)cmdlist[CMD_SNES]) == 0) { + info_P(PSTR("Activate SNES bus\n")); + snes_irq_lo(); + snes_irq_off(); + snes_wr_disable(); + snes_bus_active(); + }else if (strcmp_P((char*)t, (PGM_P)cmdlist[CMD_LOROM]) == 0) { + info_P(PSTR("Set LOROM\n")); + snes_lorom(); + snes_wr_disable(); + }else if (strcmp_P((char*)t, (PGM_P)cmdlist[CMD_HIROM]) == 0) { + info_P(PSTR("Set HIROM\n")); + snes_hirom(); + snes_wr_disable(); + }else if (strcmp_P((char*)t, (PGM_P)cmdlist[CMD_WR]) == 0) { + arg1 = get_bool(); + if(arg1==1){ + info_P(PSTR("Set WR enable")); + snes_wr_enable(); + }else if (arg1==0){ + info_P(PSTR("Set WR disable")); + snes_wr_disable(); + } + }else if (strcmp_P((char*)t, (PGM_P)cmdlist[CMD_SHMWR]) == 0) { + if (get_hex_arg2(&arg1,&arg2)) + shared_memory_write((uint8_t)arg1, (uint8_t)arg1); + else + info_P(PSTR("SHMWR \n")); + }else if (strcmp_P((char*)t, (PGM_P)cmdlist[CMD_SHMSAVE]) == 0) { + shared_memory_scratchpad_region_tx_save(); + shared_memory_scratchpad_region_rx_save(); + info_P(PSTR("Save scratchpad\n")); + }else if (strcmp_P((char*)t, (PGM_P)cmdlist[CMD_SHMRESTORE]) == 0) { + shared_memory_scratchpad_region_tx_restore(); + shared_memory_scratchpad_region_rx_restore(); + info_P(PSTR("Restore scratchpad\n")); + }else if (strcmp_P((char*)t, (PGM_P)cmdlist[CMD_LOADER]) == 0) { + boot_startup_rom(500); + }else if (strcmp_P((char*)t, (PGM_P)cmdlist[CMD_RECONNECT]) == 0) { + usb_connect(); + }else if (strcmp_P((char*)t, (PGM_P)cmdlist[CMD_STATUS]) == 0) { + transaction_status(); + }else if (strcmp_P((char*)t, (PGM_P)cmdlist[CMD_HELP]) == 0) { + shell_help(); + } + 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 */ - - - } diff --git a/avr/usbload/sram.c b/avr/usbload/sram.c index 435ae40..a36682f 100644 --- a/avr/usbload/sram.c +++ b/avr/usbload/sram.c @@ -232,8 +232,8 @@ void sram_bulk_write_start(uint32_t addr) inline void sram_bulk_write_next(void) { + AVR_WR_PORT &= ~(1 << AVR_WR_PIN); addr_current++; - AVR_WR_PORT |= (1 << AVR_WR_PIN); counter_up(); } @@ -241,6 +241,7 @@ inline void sram_bulk_write( uint8_t data) { AVR_WR_PORT &= ~(1 << AVR_WR_PIN); AVR_DATA_PORT = data; + AVR_WR_PORT |= (1 << AVR_WR_PIN); } void sram_bulk_write_end(void) diff --git a/avr/usbload/usb_bulk.c b/avr/usbload/usb_bulk.c index ec01668..afbad42 100644 --- a/avr/usbload/usb_bulk.c +++ b/avr/usbload/usb_bulk.c @@ -39,32 +39,24 @@ #include "crc.h" #include "usb_bulk.h" -extern uint8_t read_buffer[TRANSFER_BUFFER_SIZE]; -extern uint32_t req_addr; -extern uint32_t req_size; -extern uint8_t req_bank; -extern uint32_t req_bank_size; -extern uint8_t req_state; -extern uint8_t rx_remaining; -extern uint8_t tx_remaining; -extern uint8_t tx_buffer[32]; -extern uint16_t crc; + +extern usb_transaction_t usb_trans; uint8_t usbFunctionWrite(uint8_t * data, uint8_t len) { uint8_t *ptr; uint8_t i; - if (len > rx_remaining) { + if (len > usb_trans.rx_remaining) { info_P(PSTR("ERROR:usbFunctionWrite more data than expected remain: %i len: %i\n"), - rx_remaining, len); - len = rx_remaining; + usb_trans.rx_remaining, len); + len = usb_trans.rx_remaining; } - if (req_state == REQ_STATUS_BULK_UPLOAD) { + if (usb_trans.req_state == REQ_STATUS_BULK_UPLOAD) { - rx_remaining -= len; + usb_trans.rx_remaining -= len; debug_P(DEBUG_USB_TRANS, PSTR("usbFunctionWrite REQ_STATUS_BULK_UPLOAD addr: 0x%08lx len: %i rx_remaining=%i\n"), - req_addr, len, rx_remaining); + usb_trans.req_addr, len, usb_trans.rx_remaining); ptr = data; i = len; while(i--){ @@ -78,13 +70,13 @@ uint8_t usbFunctionWrite(uint8_t * data, uint8_t len) uint8_t usbFunctionRead(uint8_t * data, uint8_t len) { uint8_t i; - if (len > tx_remaining) - len = tx_remaining; - tx_remaining -= len; - debug_P(DEBUG_USB_TRANS, PSTR("usbFunctionRead len=%i tx_remaining=%i \n"), len, tx_remaining); + if (len > usb_trans.tx_remaining) + len = usb_trans.tx_remaining; + usb_trans.tx_remaining -= len; + debug_P(DEBUG_USB_TRANS, PSTR("usbFunctionRead len=%i tx_remaining=%i \n"), len, usb_trans.tx_remaining); for (i = 0; i < len; i++) { - *data = tx_buffer[len]; + *data = usb_trans.tx_buffer[len]; data++; } return len; diff --git a/avr/usbload/usbconfig.h b/avr/usbload/usbconfig.h index d35e64b..1799753 100644 --- a/avr/usbload/usbconfig.h +++ b/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. diff --git a/avr/usbload/util.c b/avr/usbload/util.c index 84bf7d6..a6d7347 100644 --- a/avr/usbload/util.c +++ b/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; diff --git a/quickdev16.tmproj b/quickdev16.tmproj index c409dac..28b8263 100644 --- a/quickdev16.tmproj +++ b/quickdev16.tmproj @@ -21,6 +21,48 @@ 271 metaData + avr/usbload/command.c + + caret + + column + 0 + line + 141 + + firstVisibleColumn + 0 + firstVisibleLine + 94 + + avr/usbload/command.h + + caret + + column + 26 + line + 30 + + firstVisibleColumn + 0 + firstVisibleLine + 0 + + avr/usbload/config.h + + caret + + column + 5 + line + 45 + + firstVisibleColumn + 0 + firstVisibleLine + 10 + avr/usbload/crc.c caret @@ -40,61 +82,131 @@ caret column - 0 + 5 line 26 - columnSelection - firstVisibleColumn 0 firstVisibleLine 0 - selectFrom + + avr/usbload/debug.h + + caret column 0 line - 25 - - selectTo - - column 0 - line - 26 + firstVisibleColumn + 0 + firstVisibleLine + 2 avr/usbload/dump.c caret column - 12 + 15 line - 67 + 28 + + firstVisibleColumn + 0 + firstVisibleLine + 36 + + avr/usbload/dump.h + + caret + + column + 0 + line + 3 + + firstVisibleColumn + 0 + firstVisibleLine + 0 + + avr/usbload/irq.c + + caret + + column + 10 + line + 53 columnSelection firstVisibleColumn 0 firstVisibleLine - 35 + 25 selectFrom column 5 line - 67 + 53 selectTo column - 16 + 22 line - 67 + 53 + avr/usbload/irq.h + + caret + + column + 19 + line + 26 + + columnSelection + + firstVisibleColumn + 0 + firstVisibleLine + 0 + selectFrom + + column + 5 + line + 26 + + selectTo + + column + 22 + line + 26 + + + avr/usbload/loader.c + + caret + + column + 80 + line + 18 + + firstVisibleColumn + 0 + firstVisibleLine + 734 + avr/usbload/main.c caret @@ -102,28 +214,68 @@ column 0 line - 28 + 74 + + firstVisibleColumn + 0 + firstVisibleLine + 46 + + avr/usbload/pwm.c + + caret + + column + 25 + line + 32 + + firstVisibleColumn + 0 + firstVisibleLine + 20 + + avr/usbload/pwm.h + + caret + + column + 20 + line + 33 - columnSelection - firstVisibleColumn 0 firstVisibleLine 0 - selectFrom + + avr/usbload/requests.h + + caret column - 0 + 20 line - 22 + 56 - selectTo + firstVisibleColumn + 0 + firstVisibleLine + 9 + + avr/usbload/rle.c + + caret column - 0 + 40 line - 28 + 99 + firstVisibleColumn + 0 + firstVisibleLine + 55 avr/usbload/rle.h @@ -155,40 +307,70 @@ 0 + avr/usbload/shared_memory.c + + caret + + column + 0 + line + 70 + + columnSelection + + firstVisibleColumn + 0 + firstVisibleLine + 61 + selectFrom + + column + 0 + line + 64 + + selectTo + + column + 0 + line + 70 + + avr/usbload/shared_memory.h caret column - 45 + 52 line - 24 + 50 firstVisibleColumn 0 firstVisibleLine - 0 + 29 avr/usbload/shell.c caret column - 41 + 0 line - 177 + 43 firstVisibleColumn 0 firstVisibleLine - 154 + 30 avr/usbload/shell.h caret column - 0 + 22 line 23 @@ -211,7 +393,7 @@ firstVisibleColumn 0 firstVisibleLine - 206 + 215 selectFrom column @@ -227,6 +409,34 @@ 287 + avr/usbload/timer.c + + caret + + column + 6 + line + 80 + + firstVisibleColumn + 0 + firstVisibleLine + 47 + + avr/usbload/timer.h + + caret + + column + 0 + line + 29 + + firstVisibleColumn + 0 + firstVisibleLine + 0 + avr/usbload/uart.c caret @@ -241,6 +451,36 @@ firstVisibleLine 26 + avr/usbload/usb_bulk.c + + caret + + column + 0 + line + 43 + + columnSelection + + firstVisibleColumn + 0 + firstVisibleLine + 16 + selectFrom + + column + 0 + line + 42 + + selectTo + + column + 0 + line + 43 + + avr/usbload/usb_bulk.h caret @@ -255,49 +495,61 @@ firstVisibleLine 0 + avr/usbload/usbconfig.h + + caret + + column + 42 + line + 129 + + firstVisibleColumn + 0 + firstVisibleLine + 88 + avr/usbload/util.c caret column - 1 + 0 line - 25 + 116 firstVisibleColumn 0 firstVisibleLine - 0 + 84 avr/usbload/util.h caret column - 0 + 1 line - 0 + 29 - columnSelection - firstVisibleColumn 0 firstVisibleLine 0 - selectFrom + + scripts/check_rle.py + + caret column - 3 + 14 line - 18 - - selectTo - - column - 0 - line - 0 + 9 + firstVisibleColumn + 0 + firstVisibleLine + 0 snes/banktest/LoadGraphics.asm @@ -327,17 +579,96 @@ firstVisibleLine 211 + tools/ucon64/src/backup/quickdev16.c + + caret + + column + 30 + line + 71 + + firstVisibleColumn + 0 + firstVisibleLine + 181 + + tools/ucon64/src/backup/smsgg-pro.h + + caret + + column + 0 + line + 0 + + firstVisibleColumn + 0 + firstVisibleLine + 0 + + tools/ucon64/src/console/snes.c + + caret + + column + 0 + line + 2695 + + columnSelection + + firstVisibleColumn + 0 + firstVisibleLine + 3814 + selectFrom + + column + 1 + line + 2887 + + selectTo + + column + 0 + line + 2695 + + openDocuments avr/usbload/sram.c avr/usbload/main.c + avr/usbload/usb_bulk.c + avr/usbload/usbconfig.h + avr/usbload/requests.h + avr/usbload/debug.h avr/usbload/shell.c + tools/ucon64/src/backup/smsgg-pro.h + tools/ucon64/src/console/snes.c + tools/ucon64/src/backup/quickdev16.c + avr/usbload/config.h + avr/usbload/timer.c + avr/usbload/rle.c + avr/usbload/pwm.c + avr/usbload/loader.c + scripts/check_rle.py + avr/usbload/pwm.h + avr/usbload/shared_memory.c + avr/usbload/command.c + avr/usbload/command.h + avr/usbload/irq.c + avr/usbload/irq.h avr/usbload/crc.c avr/usbload/dump.c avr/usbload/debug.c + avr/usbload/dump.h avr/usbload/uart.c avr/usbload/util.c + avr/usbload/timer.h avr/usbload/util.h avr/usbload/usb_bulk.h avr/usbload/rle.h @@ -378,6 +709,37 @@ subItems + tools + + isExpanded + + subItems + + ucon64 + + isExpanded + + subItems + + src + + isExpanded + + subItems + + console + + isExpanded + + subItems + + + + + + + + diff --git a/roms/anime.smc b/roms/anime.smc deleted file mode 100644 index d99a3c5..0000000 Binary files a/roms/anime.smc and /dev/null differ diff --git a/roms/arkanoid.smc b/roms/arkanoid.smc deleted file mode 100644 index 7edcbde..0000000 Binary files a/roms/arkanoid.smc and /dev/null differ diff --git a/roms/dezaemon.smc b/roms/dezaemon.smc deleted file mode 100644 index e69de29..0000000 diff --git a/roms/dump256.smc b/roms/dump256.smc deleted file mode 100644 index ede836e..0000000 Binary files a/roms/dump256.smc and /dev/null differ diff --git a/roms/dump512.smc b/roms/dump512.smc deleted file mode 100644 index fade1f1..0000000 Binary files a/roms/dump512.smc and /dev/null differ diff --git a/roms/eric.smc b/roms/eric.smc deleted file mode 100644 index 75f82af..0000000 Binary files a/roms/eric.smc and /dev/null differ diff --git a/roms/hungry.smc b/roms/hungry.smc deleted file mode 100644 index 01cec01..0000000 Binary files a/roms/hungry.smc and /dev/null differ diff --git a/roms/kirby.smc b/roms/kirby.smc deleted file mode 100644 index f200ad1..0000000 Binary files a/roms/kirby.smc and /dev/null differ diff --git a/roms/spacei.smc b/roms/spacei.smc deleted file mode 100644 index 8a31399..0000000 Binary files a/roms/spacei.smc and /dev/null differ diff --git a/roms/super01.smc b/roms/super01.smc deleted file mode 100644 index 88001d7..0000000 Binary files a/roms/super01.smc and /dev/null differ diff --git a/roms/super02.smc b/roms/super02.smc deleted file mode 100644 index 2943e7a..0000000 Binary files a/roms/super02.smc and /dev/null differ diff --git a/roms/supert.smc b/roms/supert.smc deleted file mode 100644 index 54d977e..0000000 Binary files a/roms/supert.smc and /dev/null differ diff --git a/roms/turrican.smc b/roms/turrican.smc deleted file mode 100644 index e094961..0000000 Binary files a/roms/turrican.smc and /dev/null differ diff --git a/roms/vortex.smc b/roms/vortex.smc deleted file mode 100644 index 74a54ce..0000000 Binary files a/roms/vortex.smc and /dev/null differ diff --git a/scripts/check_rle.py b/scripts/check_rle.py index 84b6b59..d1d02a5 100644 --- a/scripts/check_rle.py +++ b/scripts/check_rle.py @@ -7,7 +7,7 @@ import glob import zlib -TARGET="/home/david/Dropbox/Tech/Quickdev16/roms/08" +TARGET="/Users/david/Dropbox/Tech/Quickdev16/roms/08" count = 0 total_zip_len = 0 diff --git a/todo.txt b/todo.txt index c09dcac..83eb393 100644 --- a/todo.txt +++ b/todo.txt @@ -8,3 +8,5 @@ Package for Quickdev16 Bootloader lockbits Flash all cartridge with latest firmware and bootloader Email to seeed about the retour package +Add structs for machine state +Add struct for usb and communcations flags