From 935c1d6f7f89e78682dcd46c978e75ec5f98b8e9 Mon Sep 17 00:00:00 2001 From: optixx Date: Thu, 17 Sep 2009 19:29:40 +0200 Subject: [PATCH 01/15] make bootloader jumper bridge optional --- avr/bootloader/bootloader.c | 5 ++- quickdev16.tmproj | 74 ++++--------------------------------- todo.txt | 12 +++++- 3 files changed, 20 insertions(+), 71 deletions(-) diff --git a/avr/bootloader/bootloader.c b/avr/bootloader/bootloader.c index 8a677f4..8852b65 100644 --- a/avr/bootloader/bootloader.c +++ b/avr/bootloader/bootloader.c @@ -83,7 +83,7 @@ #define AVR_BTLDR_EN_PIN PC1 #define AVR_BTLDR_EN_IN PINC - +#undef AVR_BTLDR_SWITCH /* * some predefined signatures, taken from the original USBasp sourcecode */ @@ -471,7 +471,7 @@ int __attribute__ ((noreturn, OS_main)) main(void) jump_to_app(); } - +#ifdef AVR_BTLDR_SWITCH ENABLE if ((AVR_BTLDR_EN_IN & ( 1 << AVR_BTLDR_EN_PIN)) == 0){ banner(); uart_puts("Bootloader flashing is disabled\n\r"); @@ -479,6 +479,7 @@ int __attribute__ ((noreturn, OS_main)) main(void) leave_bootloader(); } +#endif /* * if power-on reset, quit bootloader via watchdog reset diff --git a/quickdev16.tmproj b/quickdev16.tmproj index df54438..eea636f 100644 --- a/quickdev16.tmproj +++ b/quickdev16.tmproj @@ -3,7 +3,7 @@ currentDocument - avr/usbload/irq.c + avr/usbload/sram.h documents @@ -393,7 +393,7 @@ firstVisibleColumn 0 firstVisibleLine - 11 + 21 avr/usbload/irq.h @@ -521,21 +521,21 @@ firstVisibleColumn 0 firstVisibleLine - 0 + 141 avr/usbload/sram.h caret column - 0 + 66 line - 183 + 154 firstVisibleColumn 0 firstVisibleLine - 118 + 132 avr/usbload/testing.c @@ -825,62 +825,6 @@ firstVisibleLine 211 - tools/ucon64/2.0/src/backup/f2a.c - - caret - - column - 0 - line - 0 - - firstVisibleColumn - 0 - firstVisibleLine - 558 - - tools/ucon64/2.0/src/backup/fal.c - - caret - - column - 0 - line - 0 - - firstVisibleColumn - 0 - firstVisibleLine - 0 - - tools/ucon64/2.0/src/backup/snesram.h - - caret - - column - 38 - line - 70 - - firstVisibleColumn - 0 - firstVisibleLine - 30 - - tools/ucon64/2.0/src/console/snes.c - - caret - - column - 28 - line - 1135 - - firstVisibleColumn - 0 - firstVisibleLine - 1952 - openDocuments @@ -915,11 +859,9 @@ avr/usbload/debug.h avr/usbload/rle.h avr/usbload/config.h - tools/ucon64/2.0/src/console/snes.c poc/avr_sdcard/main.c poc/avr_usbload/sram.c avr/usbload/sram.h - tools/ucon64/2.0/src/backup/snesram.h avr/usbload/shared_memory.h avr/usbload/checksize avr/usbload/shared_memory.c @@ -928,8 +870,6 @@ avr/usbload/fifo.h avr/usbload/main.c avr/usbload/sram.c - tools/ucon64/2.0/src/backup/fal.c - tools/ucon64/2.0/src/backup/f2a.c avr/usbload/usbconfig.h avr/usbload/crc.h @@ -971,6 +911,6 @@ windowFrame - {{0, 60}, {936, 818}} + {{0, 72}, {936, 806}} diff --git a/todo.txt b/todo.txt index 833b4c5..c09dcac 100644 --- a/todo.txt +++ b/todo.txt @@ -1,2 +1,10 @@ - -Checkout nootloader lock fuses +Send PCB to seeed +RS232 cable add programm header and sio lines +SDcard header +Rework No. 002 +Assemble No. 006 & No. 007 +Mail snega2usb about OEM +Package for Quickdev16 +Bootloader lockbits +Flash all cartridge with latest firmware and bootloader +Email to seeed about the retour package From db616a1637e5b796d27ffb9bc831494d9cb40606 Mon Sep 17 00:00:00 2001 From: optixx Date: Thu, 17 Sep 2009 19:57:25 +0200 Subject: [PATCH 02/15] make crc check optional --- avr/usbload/config.h | 2 ++ avr/usbload/main.c | 7 ++++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/avr/usbload/config.h b/avr/usbload/config.h index 0eb647e..2c9f7be 100644 --- a/avr/usbload/config.h +++ b/avr/usbload/config.h @@ -47,4 +47,6 @@ #define HW_VERSION "2.6" #define SW_VERSION "1.0" +#define DO_CRC_CHECK 1 + #endif diff --git a/avr/usbload/main.c b/avr/usbload/main.c index 73fc651..52be688 100644 --- a/avr/usbload/main.c +++ b/avr/usbload/main.c @@ -278,7 +278,7 @@ void boot_startup_rom(uint16_t init_delay) rle_decode(&_rom, ROM_BUFFER_SIZE, 0x000000); info_P(PSTR("\n")); -#if 0 +#if DO_CRC_CHECK dump_memory(0x010000 - 0x100, 0x010000); uint16_t crc; crc = crc_check_bulk_memory((uint32_t)0x000000,0x010000, 0x010000); @@ -355,6 +355,11 @@ int main(void) shared_memory_scratchpad_region_tx_restore(); shared_memory_scratchpad_region_rx_restore(); #endif + +#if DO_CRC_CHECK + info_P(PSTR("-->CRC Checkn")); + crc_check_bulk_memory(0x000000, req_addr, req_bank_size); +#endif info_P(PSTR("-->Switch TO SNES\n")); set_rom_mode(); From f8599fb60a1da164bde049ff1c4a61690f00b636 Mon Sep 17 00:00:00 2001 From: optixx Date: Thu, 17 Sep 2009 19:57:43 +0200 Subject: [PATCH 03/15] fix defines --- avr/usbload/sram.h | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/avr/usbload/sram.h b/avr/usbload/sram.h index 7ff7d8f..623d01c 100644 --- a/avr/usbload/sram.h +++ b/avr/usbload/sram.h @@ -86,22 +86,22 @@ #define AVR_ADDR_LATCH_DIR DDRC #define AVR_ADDR_LATCH_PIN PC6 -#define avr_addr_latch_hi() (AVR_ADDR_LATCH_PORT |= (1 << AVR_ADDR_LATCH_PIN))) -#define avr_addr_latch_lo() (AVR_ADDR_LATCH_PORT &= ~(1 << AVR_ADDR_LATCH_PIN))) +#define avr_addr_latch_hi() (AVR_ADDR_LATCH_PORT |= (1 << AVR_ADDR_LATCH_PIN)) +#define avr_addr_latch_lo() (AVR_ADDR_LATCH_PORT &= ~(1 << AVR_ADDR_LATCH_PIN)) #define AVR_ADDR_SCK_PORT PORTC #define AVR_ADDR_SCK_DIR DDRC #define AVR_ADDR_SCK_PIN PC5 -#define avr_addr_sck_hi() (AVR_ADDR_SCK_PORT |= (1 << AVR_ADDR_SCK_PIN))) -#define avr_addr_sck_lo() (AVR_ADDR_SCK_PORT &= ~(1 << AVR_ADDR_SCK_PIN))) +#define avr_addr_sck_hi() (AVR_ADDR_SCK_PORT |= (1 << AVR_ADDR_SCK_PIN)) +#define avr_addr_sck_lo() (AVR_ADDR_SCK_PORT &= ~(1 << AVR_ADDR_SCK_PIN)) #define AVR_ADDR_SER_PORT PORTC #define AVR_ADDR_SER_DIR DDRC #define AVR_ADDR_SER_PIN PC4 -#define avr_addr_ser_hi() (AVR_ADDR_SER_PORT |= (1 << AVR_ADDR_SER_PIN))) -#define avr_addr_ser_lo() (AVR_ADDR_SER_PORT &= ~(1 << AVR_ADDR_SER_PIN))) +#define avr_addr_ser_hi() (AVR_ADDR_SER_PORT |= (1 << AVR_ADDR_SER_PIN)) +#define avr_addr_ser_lo() (AVR_ADDR_SER_PORT &= ~(1 << AVR_ADDR_SER_PIN)) #define AVR_ADDR_LOAD_PORT PORTC #define AVR_ADDR_LOAD_DIR DDRC From 2d601dac1786e781298131d0785cc869771a998e Mon Sep 17 00:00:00 2001 From: optixx Date: Thu, 17 Sep 2009 20:06:01 +0200 Subject: [PATCH 04/15] change req end addr for crc dump --- avr/usbload/main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/avr/usbload/main.c b/avr/usbload/main.c index 52be688..2b0bdde 100644 --- a/avr/usbload/main.c +++ b/avr/usbload/main.c @@ -358,7 +358,7 @@ int main(void) #if DO_CRC_CHECK info_P(PSTR("-->CRC Checkn")); - crc_check_bulk_memory(0x000000, req_addr, req_bank_size); + crc_check_bulk_memory(0x000000, req_bank_size * req_bank_cnt, req_bank_size); #endif info_P(PSTR("-->Switch TO SNES\n")); From 8650109879b9f9a18d627c8977e73dafb2ac8acb Mon Sep 17 00:00:00 2001 From: optixx Date: Thu, 17 Sep 2009 20:25:08 +0200 Subject: [PATCH 05/15] support files with copy header --- avr/usbload/main.c | 2 +- scripts/crc_xmodem.py | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/avr/usbload/main.c b/avr/usbload/main.c index 2b0bdde..f00fa9b 100644 --- a/avr/usbload/main.c +++ b/avr/usbload/main.c @@ -357,7 +357,7 @@ int main(void) #endif #if DO_CRC_CHECK - info_P(PSTR("-->CRC Checkn")); + info_P(PSTR("-->CRC Check\n")); crc_check_bulk_memory(0x000000, req_bank_size * req_bank_cnt, req_bank_size); #endif diff --git a/scripts/crc_xmodem.py b/scripts/crc_xmodem.py index af764bd..dac1108 100644 --- a/scripts/crc_xmodem.py +++ b/scripts/crc_xmodem.py @@ -41,9 +41,16 @@ def test_algo(): def main(): #import cProfile #cProfile.run('test_performance()') + if sys.argv[1].endswith(".smc"): + copy_header= True size = os.stat(sys.argv[1])[6] fd = open(sys.argv[1]) + + if copy_header: + fd.seek(512) + size = size - 512 + addr = 0x0000 step = 2**15 result = [] From a28a7e928af664c9e808b9a5b4dbf2a5b8524b4e Mon Sep 17 00:00:00 2001 From: optixx Date: Thu, 17 Sep 2009 20:42:21 +0200 Subject: [PATCH 06/15] fix uart compile error --- avr/usbload/uart.c | 5 +++++ avr/usbload/uart.h | 1 - 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/avr/usbload/uart.c b/avr/usbload/uart.c index 00cc86f..f336d2f 100644 --- a/avr/usbload/uart.c +++ b/avr/usbload/uart.c @@ -25,6 +25,8 @@ #include "uart.h" #include "fifo.h" + + volatile struct { uint8_t tmr_int:1; uint8_t adc_int:1; @@ -35,6 +37,9 @@ volatile struct { volatile char rxbuff; + +static int uart_stream(char c, FILE *stream); + FILE uart_stdout = FDEV_SETUP_STREAM(uart_stream, NULL, _FDEV_SETUP_WRITE); void uart_init(void) diff --git a/avr/usbload/uart.h b/avr/usbload/uart.h index a8ec5e7..ef044ce 100644 --- a/avr/usbload/uart.h +++ b/avr/usbload/uart.h @@ -32,7 +32,6 @@ void uart_init(void); void uart_putc(const uint8_t); void uart_puts(const char *s); void uart_puts_P(PGM_P s); -static int uart_stream(char c, FILE *stream); #endif From 0d2c2c274bb925843dc56f0d051c7f4c33d73646 Mon Sep 17 00:00:00 2001 From: optixx Date: Thu, 17 Sep 2009 20:46:00 +0200 Subject: [PATCH 07/15] fix minor compile errors --- avr/usbload/debug.c | 7 ++++--- avr/usbload/info.c | 4 ++-- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/avr/usbload/debug.c b/avr/usbload/debug.c index 9a25ad7..ccd26f3 100644 --- a/avr/usbload/debug.c +++ b/avr/usbload/debug.c @@ -59,10 +59,11 @@ void debug_P(int level, PGM_P format, ...) { va_list args; if (!(debug_level & level)) return; - strlcpy_P(buffer_debug,format,FORMAT_BUFFER_LEN); + strlcpy_P((char*)buffer_debug,format,FORMAT_BUFFER_LEN); va_start(args, format); - vprintf(buffer_debug, args); + vprintf((char*)buffer_debug, args); va_end(args); #endif } -#endif \ No newline at end of file +#endif + diff --git a/avr/usbload/info.c b/avr/usbload/info.c index bcfc7b8..63a97ec 100644 --- a/avr/usbload/info.c +++ b/avr/usbload/info.c @@ -63,10 +63,10 @@ void info_P(PGM_P format, ...) { #ifdef NO_INFO #else - strlcpy_P(buffer_info,format,FORMAT_BUFFER_LEN); + strlcpy_P((char*)buffer_info,format,FORMAT_BUFFER_LEN); va_list args; va_start(args, format); - vprintf(buffer_info, args); + vprintf((char*)buffer_info, args); va_end(args); #endif } From d0085519684de3c1048c62d9880bf8d11fbb3cdb Mon Sep 17 00:00:00 2001 From: optixx Date: Sat, 19 Sep 2009 18:07:32 +0200 Subject: [PATCH 08/15] track down scratchpad bug and hacked a fix into sram_bulk_copy_from_buffer --- avr/usbload/Makefile | 8 ++-- avr/usbload/config.h | 3 ++ avr/usbload/crc.c | 2 +- avr/usbload/main.c | 8 ++-- avr/usbload/shared_memory.c | 75 +++++++++++++++++++++++++++---------- avr/usbload/shared_memory.h | 9 +++-- avr/usbload/sram.c | 13 ++++--- 7 files changed, 82 insertions(+), 36 deletions(-) diff --git a/avr/usbload/Makefile b/avr/usbload/Makefile index 09ac036..e882406 100644 --- a/avr/usbload/Makefile +++ b/avr/usbload/Makefile @@ -28,15 +28,15 @@ SIZE = avr-size ifeq ($(DEBUG),1) - LDFLAGS = -Wl,-u,vfprintf -lprintf_flt - CFLAGS = -Iusbdrv -I. -DDEBUG_LEVEL=0 + LDFLAGS =-Wl,-u,vfprintf -lprintf_flt + CFLAGS =-Iusbdrv -I. -DDEBUG_LEVEL=0 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 info.o shared_memory.o \ irq.o command.o testing.o else - LDFLAGS = -Wl,-u - CFLAGS = -Iusbdrv -I. -DDEBUG_LEVEL=0 -DNO_DEBUG -DNO_INFO + LDFLAGS =-Wl,-u + 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 \ info.o shared_memory.o command.o irq.o diff --git a/avr/usbload/config.h b/avr/usbload/config.h index 2c9f7be..2a92a73 100644 --- a/avr/usbload/config.h +++ b/avr/usbload/config.h @@ -47,6 +47,9 @@ #define HW_VERSION "2.6" #define SW_VERSION "1.0" +#define DO_CRC_CHECK_LOADER 0 #define DO_CRC_CHECK 1 +#define DO_SHM_SCRATCHPAD 1 +#define DO_SHM 1 #endif diff --git a/avr/usbload/crc.c b/avr/usbload/crc.c index 87cc25e..bfdc7cc 100644 --- a/avr/usbload/crc.c +++ b/avr/usbload/crc.c @@ -75,7 +75,7 @@ uint16_t crc_check_bulk_memory(uint32_t bottom_addr, uint32_t top_addr, uint32_t bottom_addr,top_addr); for (addr = bottom_addr; addr < top_addr; addr++) { - if (addr && addr % bank_size == 0) { + if (addr && ((addr % bank_size) == 0)) { debug_P(DEBUG_CRC, PSTR("crc_check_bulk_memory: bank=0x%02x addr=0x%08lx crc=0x%04x\n"), req_bank,addr,crc); req_bank++; diff --git a/avr/usbload/main.c b/avr/usbload/main.c index f00fa9b..b75e096 100644 --- a/avr/usbload/main.c +++ b/avr/usbload/main.c @@ -113,6 +113,7 @@ usbMsgLen_t usbFunctionSetup(uchar data[8]) req_addr = req_addr | rq->wIndex.word; rx_remaining = rq->wLength.word; + if (req_addr && req_addr % req_bank_size == 0) { #ifdef FLT_DEBUG @@ -149,7 +150,7 @@ usbMsgLen_t usbFunctionSetup(uchar data[8]) req_percent_last = req_percent; shared_memory_scratchpad_region_save_helper(req_addr); - + if (req_addr && (req_addr % req_bank_size) == 0) { #ifdef FLT_DEBUG debug_P(DEBUG_USB, @@ -278,7 +279,7 @@ void boot_startup_rom(uint16_t init_delay) rle_decode(&_rom, ROM_BUFFER_SIZE, 0x000000); info_P(PSTR("\n")); -#if DO_CRC_CHECK +#if DO_CRC_CHECK_LOADER dump_memory(0x010000 - 0x100, 0x010000); uint16_t crc; crc = crc_check_bulk_memory((uint32_t)0x000000,0x010000, 0x010000); @@ -351,7 +352,8 @@ int main(void) shared_memory_write(SHARED_MEM_TX_CMD_TERMINATE, 0); -#if 0 + +#if DO_SHM_SCRATCHPAD shared_memory_scratchpad_region_tx_restore(); shared_memory_scratchpad_region_rx_restore(); #endif diff --git a/avr/usbload/shared_memory.c b/avr/usbload/shared_memory.c index 9a97057..68b3796 100644 --- a/avr/usbload/shared_memory.c +++ b/avr/usbload/shared_memory.c @@ -56,66 +56,81 @@ void shared_memory_init(void){ uint8_t shared_memory_scratchpad_region_save_helper(uint32_t addr){ - - if(addr > (SHARED_MEM_TX_LOC_STATE + SHARED_MEM_TX_LOC_SIZE) && scratchpad_locked_tx){ + + + +#if DO_SHM_SCRATCHPAD + if(addr > (SHARED_MEM_TX_LOC_STATE + (SHARED_MEM_TX_LOC_SIZE )) && scratchpad_locked_tx){ debug_P(DEBUG_SHM, PSTR("shared_memory_scratchpad_region_save_helper: open tx addr=0x%06lx\n"),addr); shared_memory_scratchpad_region_tx_save(); return 0; } - if(addr > (SHARED_MEM_RX_LOC_STATE + SHARED_MEM_RX_LOC_SIZE) && scratchpad_locked_rx){ + if(addr > (SHARED_MEM_RX_LOC_STATE + ( SHARED_MEM_RX_LOC_SIZE )) && scratchpad_locked_rx){ debug_P(DEBUG_SHM, PSTR("shared_memory_scratchpad_region_save_helper: open rx addr=0x%06lx\n"),addr); shared_memory_scratchpad_region_rx_save(); return 0; } +#endif return 1; } void shared_memory_scratchpad_region_tx_save() { + sram_bulk_addr_save(); -#if SHARED_SCRATCHPAD_DUMP +#if SHARED_SCRATCHPAD_CRC uint16_t crc; crc = crc_check_bulk_memory((uint32_t)SHARED_MEM_TX_LOC_STATE, (uint32_t)(SHARED_MEM_TX_LOC_STATE + SHARED_MEM_TX_LOC_SIZE), 0x8000); debug_P(DEBUG_SHM, PSTR("shared_memory_scratchpad_region_tx_save: crc=%x\n"),crc); + #endif - sram_bulk_addr_save(); debug_P(DEBUG_SHM, PSTR("shared_memory_scratchpad_region_tx_save: unlock\n")); sram_bulk_copy_into_buffer((uint32_t)SHARED_MEM_TX_LOC_STATE,scratchpad_region_tx, (uint32_t)SHARED_MEM_TX_LOC_SIZE); - sram_bulk_addr_restore(); scratchpad_locked_tx = 0; +#if SHARED_SCRATCHPAD_CRC + do_crc_update(0, scratchpad_region_tx,SHARED_MEM_TX_LOC_SIZE); + debug_P(DEBUG_SHM, PSTR("shared_memory_scratchpad_region_tx_save: crc=%x\n"),crc); +#endif + #if SHARED_SCRATCHPAD_DUMP dump_packet(SHARED_MEM_TX_LOC_STATE, SHARED_MEM_TX_LOC_SIZE, scratchpad_region_tx); dump_memory(SHARED_MEM_TX_LOC_STATE, SHARED_MEM_TX_LOC_STATE + SHARED_MEM_TX_LOC_SIZE); #endif + sram_bulk_addr_restore(); } void shared_memory_scratchpad_region_rx_save() { -#if SHARED_SCRATCHPAD_DUMP + sram_bulk_addr_save(); +#if SHARED_SCRATCHPAD_CRC uint16_t crc; crc = crc_check_bulk_memory((uint32_t)SHARED_MEM_RX_LOC_STATE, (uint32_t)(SHARED_MEM_RX_LOC_STATE + SHARED_MEM_RX_LOC_SIZE), 0x8000); - debug_P(DEBUG_SHM, PSTR("shared_memory_scratchpad_region_tx_save: crc=%x\n"),crc); + debug_P(DEBUG_SHM, PSTR("shared_memory_scratchpad_region_rx_save: crc=%x\n"),crc); #endif - sram_bulk_addr_save(); debug_P(DEBUG_SHM, PSTR("shared_memory_scratchpad_region_rx_save: unlock\n")); sram_bulk_copy_into_buffer((uint32_t)SHARED_MEM_RX_LOC_STATE,scratchpad_region_rx, (uint32_t)SHARED_MEM_RX_LOC_SIZE); - sram_bulk_addr_restore(); scratchpad_locked_rx = 0; +#if SHARED_SCRATCHPAD_CRC + do_crc_update(0, scratchpad_region_rx,SHARED_MEM_RX_LOC_SIZE); + debug_P(DEBUG_SHM, PSTR("shared_memory_scratchpad_region_rx_save: crc=%x\n"),crc); +#endif + #if SHARED_SCRATCHPAD_DUMP - dump_packet(SHARED_MEM_RX_LOC_STATE, SHARED_MEM_RX_LOC_SIZE, scratchpad_region_tx); + dump_packet(SHARED_MEM_RX_LOC_STATE, SHARED_MEM_RX_LOC_SIZE, scratchpad_region_rx); dump_memory(SHARED_MEM_RX_LOC_STATE, SHARED_MEM_RX_LOC_STATE + SHARED_MEM_RX_LOC_SIZE); #endif + sram_bulk_addr_restore(); } @@ -123,18 +138,25 @@ void shared_memory_scratchpad_region_tx_restore() { if (scratchpad_locked_tx) return; - debug_P(DEBUG_SHM, PSTR("shared_memory_scratchpad_region_tx_restore: lock\n")); + +#if SHARED_SCRATCHPAD_DUMP + debug_P(DEBUG_SHM, PSTR("shared_memory_scratchpad_region_tx_restore: memory\n")); + dump_memory(SHARED_MEM_TX_LOC_STATE, SHARED_MEM_TX_LOC_STATE + SHARED_MEM_TX_LOC_SIZE); +#endif + sram_bulk_copy_from_buffer((uint32_t)SHARED_MEM_TX_LOC_STATE,scratchpad_region_tx, (uint32_t)SHARED_MEM_TX_LOC_SIZE); scratchpad_locked_tx = 1; #if SHARED_SCRATCHPAD_DUMP + debug_P(DEBUG_SHM, PSTR("shared_memory_scratchpad_region_tx_restore: buffer\n")); dump_packet(SHARED_MEM_TX_LOC_STATE, SHARED_MEM_TX_LOC_SIZE, scratchpad_region_tx); + debug_P(DEBUG_SHM, PSTR("shared_memory_scratchpad_region_tx_restore: memory\n")); dump_memory(SHARED_MEM_TX_LOC_STATE, SHARED_MEM_TX_LOC_STATE + SHARED_MEM_TX_LOC_SIZE); #endif -#if SHARED_SCRATCHPAD_DUMP +#if SHARED_SCRATCHPAD_CRC uint16_t crc; crc = crc_check_bulk_memory((uint32_t)SHARED_MEM_TX_LOC_STATE, (uint32_t)(SHARED_MEM_TX_LOC_STATE + SHARED_MEM_TX_LOC_SIZE), 0x8000); @@ -147,17 +169,26 @@ void shared_memory_scratchpad_region_rx_restore() { if (scratchpad_locked_rx) return; - debug_P(DEBUG_SHM, PSTR("shared_memory_scratchpad_region_tx_save: lock\n")); + + + debug_P(DEBUG_SHM, PSTR("shared_memory_scratchpad_region_rx_restore: lock\n")); +#if SHARED_SCRATCHPAD_DUMP + debug_P(DEBUG_SHM, PSTR("shared_memory_scratchpad_region_rx_restore: memory\n")); + dump_memory(SHARED_MEM_RX_LOC_STATE - 0x10, SHARED_MEM_RX_LOC_STATE + SHARED_MEM_RX_LOC_SIZE); +#endif + sram_bulk_copy_from_buffer((uint32_t)SHARED_MEM_RX_LOC_STATE,scratchpad_region_rx, (uint32_t)SHARED_MEM_RX_LOC_SIZE); scratchpad_locked_rx = 1; #if SHARED_SCRATCHPAD_DUMP - dump_packet(SHARED_MEM_RX_LOC_STATE, SHARED_MEM_TX_LOC_SIZE, scratchpad_region_rx); - dump_memory(SHARED_MEM_RX_LOC_STATE, SHARED_MEM_TX_LOC_STATE + SHARED_MEM_RX_LOC_SIZE); + debug_P(DEBUG_SHM, PSTR("shared_memory_scratchpad_region_rx_restore: buffer\n")); + dump_packet(SHARED_MEM_RX_LOC_STATE, SHARED_MEM_RX_LOC_SIZE, scratchpad_region_rx); + debug_P(DEBUG_SHM, PSTR("shared_memory_scratchpad_region_rx_restore: memory\n")); + dump_memory(SHARED_MEM_RX_LOC_STATE - 0x10, SHARED_MEM_RX_LOC_STATE + SHARED_MEM_RX_LOC_SIZE); #endif -#if SHARED_SCRATCHPAD_DUMP +#if SHARED_SCRATCHPAD_CRC uint16_t crc; crc = crc_check_bulk_memory((uint32_t)SHARED_MEM_RX_LOC_STATE, (uint32_t)(SHARED_MEM_RX_LOC_STATE + SHARED_MEM_RX_LOC_SIZE), 0x8000); @@ -197,10 +228,13 @@ void shared_memory_irq_restore() void shared_memory_write(uint8_t cmd, uint8_t value) { +#if DO_SHM +#if DO_SHM_SCRATCHPAD if (scratchpad_locked_tx){ debug_P(DEBUG_SHM, PSTR("shared_memory_write: locked_tx\n")); //return 1; } +#endif debug_P(DEBUG_SHM, PSTR("shared_memory_write: 0x%04x=0x%02x 0x%04x=0x%02x \n"), SHARED_MEM_TX_LOC_CMD, cmd, SHARED_MEM_TX_LOC_PAYLOAD, value); @@ -235,7 +269,7 @@ void shared_memory_write(uint8_t cmd, uint8_t value) shared_memory_scratchpad_tx_restore(); shared_memory_irq_restore(); sram_bulk_addr_restore(); - +#endif } void shared_memory_yield() @@ -255,11 +289,13 @@ void shared_memory_yield() int shared_memory_read(uint8_t *cmd, uint8_t *len,uint8_t *buffer) { uint8_t state; - +#if DO_SHM +#if DO_SHM_SCRATCHPAD if (scratchpad_locked_rx){ debug_P(DEBUG_SHM, PSTR("shared_memory_write: locked_tx\n")); return 1; } +#endif sram_bulk_addr_save(); state = sram_read(SHARED_MEM_RX_LOC_STATE); @@ -294,5 +330,6 @@ int shared_memory_read(uint8_t *cmd, uint8_t *len,uint8_t *buffer) snes_lorom(); snes_wr_disable(); sram_bulk_addr_restore(); +#endif return 0; } diff --git a/avr/usbload/shared_memory.h b/avr/usbload/shared_memory.h index 0e1ba38..11dd9da 100644 --- a/avr/usbload/shared_memory.h +++ b/avr/usbload/shared_memory.h @@ -22,7 +22,7 @@ #define __SHARED_MEMORY_H__ -#define SHARED_MEM_SWITCH_IRQ 0 +#define SHARED_MEM_SWITCH_IRQ 1 #define SHARED_MEM_SWITCH_DELAY 20 #define SHARED_MEM_TX_SNES_ACK 0xa5 @@ -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 0x000020 #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 0x000020 #define SHARED_MEM_RX_LOC_CMD 0x001001 #define SHARED_MEM_RX_LOC_LEN 0x001002 #define SHARED_MEM_RX_LOC_PAYLOAD 0x001003 @@ -61,7 +61,8 @@ #define SHARED_IRQ_HANDLER_HI 0x0ffe5 #define SHARED_SCRATCHPAD_DUMP 0 - +#define SHARED_SCRATCHPAD_CRC 0 + void shared_memory_init(void); uint8_t shared_memory_scratchpad_region_save_helper(uint32_t addr); diff --git a/avr/usbload/sram.c b/avr/usbload/sram.c index afea2a7..5bd48ad 100644 --- a/avr/usbload/sram.c +++ b/avr/usbload/sram.c @@ -114,7 +114,7 @@ void sreg_set(uint32_t addr) } -inline void sram_bulk_addr_save() + void sram_bulk_addr_save() { addr_stash = addr_current; debug_P(DEBUG_SRAM, PSTR("sram_bulk_addr_save: addr=0x%08lx\n\r"), addr_stash); @@ -243,7 +243,7 @@ inline void sram_bulk_write_next(void) inline void sram_bulk_write( uint8_t data) { AVR_DATA_PORT = data; - } +} void sram_bulk_write_end(void) { @@ -294,8 +294,11 @@ void sram_bulk_copy_from_buffer(uint32_t addr, uint8_t * src, uint32_t len) addr, src, len); sram_bulk_write_start(addr); for (i = addr; i < (addr + len); i++){ - sram_bulk_write(*ptr++); - sram_bulk_write_next(); + sram_bulk_write(*ptr); +//hack + if ((i+1) < (addr + len)) + sram_bulk_write_next(); + ptr++; } sram_bulk_write_end(); } @@ -309,7 +312,7 @@ void sram_bulk_copy_into_buffer(uint32_t addr, uint8_t * dst, uint32_t len) addr, dst, len); sram_bulk_read_start(addr); for (i = addr; i < (addr + len); i++) { - *ptr = sram_bulk_read(); + dst[i] = sram_bulk_read(); sram_bulk_read_next(); ptr++; } From f5cdf71fb1b9d10ece6081df75fb38d70dd34e18 Mon Sep 17 00:00:00 2001 From: optixx Date: Sun, 20 Sep 2009 09:38:56 +0200 Subject: [PATCH 09/15] cleanup shared mem code --- avr/usbload/config.h | 4 ++-- avr/usbload/loader.c | 4 ++-- avr/usbload/loader.h | 2 -- avr/usbload/main.c | 6 +++++- avr/usbload/shared_memory.c | 9 +++++++++ avr/usbload/shared_memory.h | 6 +++--- 6 files changed, 21 insertions(+), 10 deletions(-) diff --git a/avr/usbload/config.h b/avr/usbload/config.h index 2a92a73..53c7d42 100644 --- a/avr/usbload/config.h +++ b/avr/usbload/config.h @@ -47,8 +47,8 @@ #define HW_VERSION "2.6" #define SW_VERSION "1.0" -#define DO_CRC_CHECK_LOADER 0 -#define DO_CRC_CHECK 1 +#define DO_CRC_CHECK_LOADER 1 +#define DO_CRC_CHECK 0 #define DO_SHM_SCRATCHPAD 1 #define DO_SHM 1 diff --git a/avr/usbload/loader.c b/avr/usbload/loader.c index 310419f..4b4687a 100644 --- a/avr/usbload/loader.c +++ b/avr/usbload/loader.c @@ -1,6 +1,6 @@ /* -File: main.smc -Time: Thu, 06 Aug 2009 20:01:38 +File: ../snes/quickdevloader/main.smc +Time: Sat, 19 Sep 2009 18:19:26 */ #include #include diff --git a/avr/usbload/loader.h b/avr/usbload/loader.h index c617f46..49d54f9 100644 --- a/avr/usbload/loader.h +++ b/avr/usbload/loader.h @@ -6,6 +6,4 @@ #define ROM_HUFFMAN_SIZE 0 #define ROM_RLE_SIZE 31091 -void irq_init(); - #endif diff --git a/avr/usbload/main.c b/avr/usbload/main.c index b75e096..5f711e7 100644 --- a/avr/usbload/main.c +++ b/avr/usbload/main.c @@ -286,8 +286,12 @@ void boot_startup_rom(uint16_t init_delay) info(PSTR("crc=%x\n"),crc); #endif + snes_irq_lo(); + snes_irq_off(); snes_hirom(); snes_wr_disable(); + irq_stop(); + snes_bus_active(); info_P(PSTR("Activate SNES bus\n")); send_reset(); @@ -332,7 +336,7 @@ int main(void) snes_reset_hi(); snes_reset_off(); irq_init(); - boot_startup_rom(50); + boot_startup_rom(500); globals_init(); usbInit(); diff --git a/avr/usbload/shared_memory.c b/avr/usbload/shared_memory.c index 68b3796..2d55744 100644 --- a/avr/usbload/shared_memory.c +++ b/avr/usbload/shared_memory.c @@ -239,8 +239,13 @@ void shared_memory_write(uint8_t cmd, uint8_t value) SHARED_MEM_TX_LOC_CMD, cmd, SHARED_MEM_TX_LOC_PAYLOAD, value); sram_bulk_addr_save(); + +#if (DO_SHM_SCRATCHPAD==0) shared_memory_scratchpad_tx_save(); +#endif +#if SHARED_MEM_SWITCH_IRQ shared_memory_irq_hook(); +#endif sram_write(SHARED_MEM_TX_LOC_STATE, SHARED_MEM_TX_SNES_ACK); sram_write(SHARED_MEM_TX_LOC_CMD, cmd); @@ -266,8 +271,12 @@ void shared_memory_write(uint8_t cmd, uint8_t value) snes_lorom(); snes_wr_disable(); +#if (DO_SHM_SCRATCHPAD==0) shared_memory_scratchpad_tx_restore(); +#endif +#if SHARED_MEM_SWITCH_IRQ shared_memory_irq_restore(); +#endif sram_bulk_addr_restore(); #endif } diff --git a/avr/usbload/shared_memory.h b/avr/usbload/shared_memory.h index 11dd9da..249cd51 100644 --- a/avr/usbload/shared_memory.h +++ b/avr/usbload/shared_memory.h @@ -22,7 +22,7 @@ #define __SHARED_MEMORY_H__ -#define SHARED_MEM_SWITCH_IRQ 1 +#define SHARED_MEM_SWITCH_IRQ 0 #define SHARED_MEM_SWITCH_DELAY 20 #define SHARED_MEM_TX_SNES_ACK 0xa5 @@ -37,7 +37,7 @@ #define SHARED_MEM_TX_CMD_TERMINATE 0x06 #define SHARED_MEM_TX_LOC_STATE 0x000000 -#define SHARED_MEM_TX_LOC_SIZE 0x000020 +#define SHARED_MEM_TX_LOC_SIZE 0x000100 #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 0x000020 +#define SHARED_MEM_RX_LOC_SIZE 0x000100 #define SHARED_MEM_RX_LOC_CMD 0x001001 #define SHARED_MEM_RX_LOC_LEN 0x001002 #define SHARED_MEM_RX_LOC_PAYLOAD 0x001003 From d9b729754c0270fa287dd740175c05734a531d66 Mon Sep 17 00:00:00 2001 From: optixx Date: Sun, 20 Sep 2009 11:25:43 +0200 Subject: [PATCH 10/15] add led pwm --- avr/usbload/Makefile | 4 +- avr/usbload/main.c | 5 +++ avr/usbload/pwm.c | 93 ++++++++++++++++++++++++++++++++++++++++++++ avr/usbload/pwm.h | 37 ++++++++++++++++++ avr/usbload/sram.h | 2 + 5 files changed, 139 insertions(+), 2 deletions(-) create mode 100644 avr/usbload/pwm.c create mode 100644 avr/usbload/pwm.h diff --git a/avr/usbload/Makefile b/avr/usbload/Makefile index e882406..ded3f75 100644 --- a/avr/usbload/Makefile +++ b/avr/usbload/Makefile @@ -33,13 +33,13 @@ ifeq ($(DEBUG),1) 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 info.o shared_memory.o \ - irq.o command.o testing.o + pwm.o irq.o command.o testing.o else LDFLAGS =-Wl,-u 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 \ - info.o shared_memory.o command.o irq.o + pwm.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/main.c b/avr/usbload/main.c index 5f711e7..dc38db4 100644 --- a/avr/usbload/main.c +++ b/avr/usbload/main.c @@ -45,6 +45,7 @@ #include "command.h" #include "shared_memory.h" #include "irq.h" +#include "pwm.h" #include "testing.h" @@ -199,6 +200,8 @@ usbMsgLen_t usbFunctionSetup(uchar data[8]) req_state = REQ_STATUS_SNES; debug_P(DEBUG_USB, PSTR("USB_MODE_SNES:\n")); ret_len = 0; + pwm_stop(); + /* * ------------------------------------------------------------------------- */ @@ -332,6 +335,7 @@ int main(void) banner(); system_init(); + //pwm_init(); shared_memory_init(); snes_reset_hi(); snes_reset_off(); @@ -339,6 +343,7 @@ int main(void) boot_startup_rom(500); globals_init(); + usbInit(); usb_connect(); diff --git a/avr/usbload/pwm.c b/avr/usbload/pwm.c new file mode 100644 index 0000000..7086c9e --- /dev/null +++ b/avr/usbload/pwm.c @@ -0,0 +1,93 @@ +/* + * ===================================================================================== + * + * ________ .__ __ ________ ____ ________ + * \_____ \ __ __|__| ____ | | __\______ \ _______ _/_ |/ _____/ + * / / \ \| | \ |/ ___\| |/ / | | \_/ __ \ \/ /| / __ \ + * / \_/. \ | / \ \___| < | ` \ ___/\ / | \ |__\ \ + * \_____\ \_/____/|__|\___ >__|_ \/_______ /\___ >\_/ |___|\_____ / + * \__> \/ \/ \/ \/ \/ + * + * www.optixx.org + * + * + * Version: 1.0 + * Created: 07/21/2009 03:32:16 PM + * Author: david@optixx.org + * + * ===================================================================================== + */ +#include +#include +#include +#include + +#include "pwm.h" +#include "debug.h" +#include "info.h" +#include "sram.h" + + +#define PWM_SINE_MAX 255 +uint8_t pwm_sine_table[] = { +0x7f,0x82,0x85,0x88,0x8b,0x8e,0x91,0x94,0x97,0x9b,0x9e,0xa1,0xa4,0xa7,0xaa,0xad, +0xaf,0xb2,0xb5,0xb8,0xbb,0xbe,0xc0,0xc3,0xc6,0xc8,0xcb,0xcd,0xd0,0xd2,0xd4,0xd7, +0xd9,0xdb,0xdd,0xdf,0xe1,0xe3,0xe5,0xe7,0xe9,0xea,0xec,0xee,0xef,0xf0,0xf2,0xf3, +0xf4,0xf5,0xf6,0xf7,0xf8,0xf9,0xfa,0xfb,0xfb,0xfc,0xfc,0xfd,0xfd,0xfd,0xfd,0xfd, +0xfd,0xfd,0xfd,0xfd,0xfd,0xfc,0xfc,0xfb,0xfb,0xfa,0xf9,0xf8,0xf7,0xf6,0xf5,0xf4, +0xf3,0xf2,0xf0,0xef,0xee,0xec,0xea,0xe9,0xe7,0xe5,0xe3,0xe1,0xdf,0xdd,0xdb,0xd9, +0xd7,0xd4,0xd2,0xd0,0xcd,0xcb,0xc8,0xc6,0xc3,0xc0,0xbe,0xbb,0xb8,0xb5,0xb2,0xaf, +0xad,0xaa,0xa7,0xa4,0xa1,0x9e,0x9b,0x97,0x94,0x91,0x8e,0x8b,0x88,0x85,0x82,0x7f, +0x7c,0x79,0x76,0x73,0x70,0x6d,0x6a,0x67,0x63,0x60,0x5d,0x5a,0x57,0x54,0x51,0x4f, +0x4c,0x49,0x46,0x43,0x40,0x3e,0x3b,0x38,0x36,0x33,0x31,0x2e,0x2c,0x2a,0x27,0x25, +0x23,0x21,0x1f,0x1d,0x1b,0x19,0x17,0x15,0x14,0x12,0x10,0x0f,0x0e,0x0c,0x0b,0x0a, +0x09,0x08,0x07,0x06,0x05,0x04,0x03,0x03,0x02,0x02,0x01,0x01,0x01,0x01,0x01,0x01, +0x01,0x01,0x01,0x01,0x02,0x02,0x03,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0a,0x0b, +0x0c,0x0e,0x0f,0x10,0x12,0x14,0x15,0x17,0x19,0x1b,0x1d,0x1f,0x21,0x23,0x25,0x27, +0x2a,0x2c,0x2e,0x31,0x33,0x36,0x38,0x3b,0x3e,0x40,0x43,0x46,0x49,0x4c,0x4f,0x51, +0x54,0x57,0x5a,0x5d,0x60,0x63,0x67,0x6a,0x6d,0x70,0x73,0x76,0x79,0x7c,0x7f +}; + + volatile uint8_t pwm_setting; // Einstellungen für die einzelnen PWM-Kanäle + volatile uint8_t pwm_overflow; // Einstellungen für die einzelnen PWM-Kanäle + volatile uint8_t pwm_idx; // Einstellungen für die einzelnen PWM-Kanäle + + ISR(TIMER2_COMPA_vect) { + static uint8_t pwm_cnt=0; + OCR2A += (uint16_t)T_PWM; + + if (pwm_setting> pwm_cnt) + led_pwm_on(); + else + led_pwm_off(); + + if (pwm_cnt==(uint8_t)(PWM_STEPS-1)) + pwm_cnt=0; + else + pwm_cnt++; + if (!pwm_overflow++){ + pwm_setting = pwm_sine_table[pwm_idx++]; + if (PWM_SINE_MAX == pwm_idx) + pwm_idx = 0; + } +} + +void pwm_set(uint8_t val) { + pwm_setting = val; +} + +void pwm_stop(void) { + while(pwm_setting!=0xfd); + //cli(); + TIMSK2 = 0; + //sei(); +} + +void pwm_init(void) { + pwm_setting = 0x7f; + pwm_overflow = 0; + //cli(); + TCCR2B = 1; + TIMSK2 |= (1<__|_ \/_______ /\___ >\_/ |___|\_____ / + * \__> \/ \/ \/ \/ \/ + * + * www.optixx.org + * + * + * Version: 1.0 + * Created: 07/21/2009 03:32:16 PM + * Author: david@optixx.org + * + * ===================================================================================== + */ + +#ifndef __PWM_H__ +#define __PWM_H__ + +#define F_PWM 100 // PWM-Frequenz in Hz +#define PWM_STEPS 256 // PWM-Schritte pro Zyklus(1..256) + +#define T_PWM (F_CPU/(F_PWM*PWM_STEPS)) // Systemtakte pro PWM-Takt + +#if (T_PWM<(93+5)) + #error T_PWM zu klein, F_CPU muss vergrösst werden oder F_PWM oder PWM_STEPS verkleinert werden +#endif + + void pwm_init(void); +void pwm_stop(void); + + +#endif diff --git a/avr/usbload/sram.h b/avr/usbload/sram.h index 623d01c..02f3d57 100644 --- a/avr/usbload/sram.h +++ b/avr/usbload/sram.h @@ -137,6 +137,8 @@ #define led_off() ((LED_PORT &=~ (1 << LED_PIN)),\ (LED_DIR |= (1 << LED_PIN))) +#define led_pwm_on() (LED_DIR &=~ (1 << LED_PIN)) +#define led_pwm_off() (LED_DIR |= (1 << LED_PIN)) /* ---------------------------- PORT D ---------------------------- */ From d86f0ad5a9ad6b7b7646d408fb8c182ef593e719 Mon Sep 17 00:00:00 2001 From: optixx Date: Sun, 20 Sep 2009 12:09:13 +0200 Subject: [PATCH 11/15] add simple pwm to start --- avr/usbload/command.c | 18 ++++++++++++++++++ avr/usbload/command.h | 1 + avr/usbload/main.c | 26 +++----------------------- avr/usbload/pwm.c | 38 ++++++++++++++++---------------------- 4 files changed, 38 insertions(+), 45 deletions(-) diff --git a/avr/usbload/command.c b/avr/usbload/command.c index def7a31..f61e1fe 100644 --- a/avr/usbload/command.c +++ b/avr/usbload/command.c @@ -28,9 +28,27 @@ #include "sram.h" #include "info.h" #include "irq.h" +#include "usbdrv.h" extern uint32_t req_bank_size; +void usb_connect() +{ + uint8_t i = 0; + info_P(PSTR("USB init\n")); + usbDeviceDisconnect(); /* enforce re-enumeration, do this while */ + cli(); + info_P(PSTR("USB disconnect\n")); + i = 10; + while (--i) { /* fake USB disconnect for > 250 ms */ + _delay_ms(50); + } + led_on(); + usbDeviceConnect(); + info_P(PSTR("USB connect\n")); +} + + void send_reset() { diff --git a/avr/usbload/command.h b/avr/usbload/command.h index 6d8b504..4c6b633 100644 --- a/avr/usbload/command.h +++ b/avr/usbload/command.h @@ -25,5 +25,6 @@ void send_reset(); void send_irq(); void set_rom_mode(); +void usb_connect(); #endif diff --git a/avr/usbload/main.c b/avr/usbload/main.c index dc38db4..2354de0 100644 --- a/avr/usbload/main.c +++ b/avr/usbload/main.c @@ -250,26 +250,6 @@ usbMsgLen_t usbFunctionSetup(uchar data[8]) */ -void usb_connect() -{ - uint8_t i = 0; - info_P(PSTR("USB init\n")); - usbDeviceDisconnect(); /* enforce re-enumeration, do this while */ - cli(); - info_P(PSTR("USB disconnect\n")); - i = 10; - while (--i) { /* fake USB disconnect for > 250 ms */ - led_on(); - _delay_ms(15); - led_off(); - _delay_ms(35); - } - led_on(); - usbDeviceConnect(); - info_P(PSTR("USB connect\n")); -} - - void boot_startup_rom(uint16_t init_delay) { info_P(PSTR("Fetch loader rom\n")); @@ -293,7 +273,6 @@ void boot_startup_rom(uint16_t init_delay) snes_irq_off(); snes_hirom(); snes_wr_disable(); - irq_stop(); snes_bus_active(); info_P(PSTR("Activate SNES bus\n")); @@ -335,14 +314,15 @@ int main(void) banner(); system_init(); - //pwm_init(); + pwm_init(); shared_memory_init(); snes_reset_hi(); snes_reset_off(); irq_init(); - boot_startup_rom(500); + boot_startup_rom(50); globals_init(); + pwm_stop(); usbInit(); usb_connect(); diff --git a/avr/usbload/pwm.c b/avr/usbload/pwm.c index 7086c9e..3c0a180 100644 --- a/avr/usbload/pwm.c +++ b/avr/usbload/pwm.c @@ -28,29 +28,19 @@ #include "sram.h" -#define PWM_SINE_MAX 255 +#define PWM_SINE_MAX 64 +#define PWM_OVERFLOW_MAX 1024 uint8_t pwm_sine_table[] = { -0x7f,0x82,0x85,0x88,0x8b,0x8e,0x91,0x94,0x97,0x9b,0x9e,0xa1,0xa4,0xa7,0xaa,0xad, -0xaf,0xb2,0xb5,0xb8,0xbb,0xbe,0xc0,0xc3,0xc6,0xc8,0xcb,0xcd,0xd0,0xd2,0xd4,0xd7, -0xd9,0xdb,0xdd,0xdf,0xe1,0xe3,0xe5,0xe7,0xe9,0xea,0xec,0xee,0xef,0xf0,0xf2,0xf3, -0xf4,0xf5,0xf6,0xf7,0xf8,0xf9,0xfa,0xfb,0xfb,0xfc,0xfc,0xfd,0xfd,0xfd,0xfd,0xfd, -0xfd,0xfd,0xfd,0xfd,0xfd,0xfc,0xfc,0xfb,0xfb,0xfa,0xf9,0xf8,0xf7,0xf6,0xf5,0xf4, -0xf3,0xf2,0xf0,0xef,0xee,0xec,0xea,0xe9,0xe7,0xe5,0xe3,0xe1,0xdf,0xdd,0xdb,0xd9, -0xd7,0xd4,0xd2,0xd0,0xcd,0xcb,0xc8,0xc6,0xc3,0xc0,0xbe,0xbb,0xb8,0xb5,0xb2,0xaf, -0xad,0xaa,0xa7,0xa4,0xa1,0x9e,0x9b,0x97,0x94,0x91,0x8e,0x8b,0x88,0x85,0x82,0x7f, -0x7c,0x79,0x76,0x73,0x70,0x6d,0x6a,0x67,0x63,0x60,0x5d,0x5a,0x57,0x54,0x51,0x4f, -0x4c,0x49,0x46,0x43,0x40,0x3e,0x3b,0x38,0x36,0x33,0x31,0x2e,0x2c,0x2a,0x27,0x25, -0x23,0x21,0x1f,0x1d,0x1b,0x19,0x17,0x15,0x14,0x12,0x10,0x0f,0x0e,0x0c,0x0b,0x0a, -0x09,0x08,0x07,0x06,0x05,0x04,0x03,0x03,0x02,0x02,0x01,0x01,0x01,0x01,0x01,0x01, -0x01,0x01,0x01,0x01,0x02,0x02,0x03,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0a,0x0b, -0x0c,0x0e,0x0f,0x10,0x12,0x14,0x15,0x17,0x19,0x1b,0x1d,0x1f,0x21,0x23,0x25,0x27, -0x2a,0x2c,0x2e,0x31,0x33,0x36,0x38,0x3b,0x3e,0x40,0x43,0x46,0x49,0x4c,0x4f,0x51, -0x54,0x57,0x5a,0x5d,0x60,0x63,0x67,0x6a,0x6d,0x70,0x73,0x76,0x79,0x7c,0x7f +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 uint8_t pwm_overflow; // 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 ISR(TIMER2_COMPA_vect) { static uint8_t pwm_cnt=0; @@ -65,29 +55,33 @@ uint8_t pwm_sine_table[] = { pwm_cnt=0; else pwm_cnt++; - if (!pwm_overflow++){ + if (pwm_overflow_max == pwm_overflow++ ){ pwm_setting = pwm_sine_table[pwm_idx++]; + pwm_overflow = 0; if (PWM_SINE_MAX == pwm_idx) pwm_idx = 0; } } +void pwm_speed(uint16_t val) { + pwm_overflow_max = val; +} + void pwm_set(uint8_t val) { pwm_setting = val; } void pwm_stop(void) { while(pwm_setting!=0xfd); - //cli(); TIMSK2 = 0; - //sei(); } void pwm_init(void) { + pwm_overflow_max = PWM_OVERFLOW_MAX; pwm_setting = 0x7f; pwm_overflow = 0; //cli(); TCCR2B = 1; TIMSK2 |= (1< Date: Sun, 20 Sep 2009 13:03:03 +0200 Subject: [PATCH 12/15] add buffered rx uart --- avr/usbload/Makefile | 4 +-- avr/usbload/config.h | 2 +- avr/usbload/shell.c | 65 ++++++++++++++++++++++++++++++++++++++++++++ avr/usbload/shell.h | 24 ++++++++++++++++ avr/usbload/uart.c | 4 +-- 5 files changed, 94 insertions(+), 5 deletions(-) create mode 100644 avr/usbload/shell.c create mode 100644 avr/usbload/shell.h diff --git a/avr/usbload/Makefile b/avr/usbload/Makefile index ded3f75..8bc5e17 100644 --- a/avr/usbload/Makefile +++ b/avr/usbload/Makefile @@ -33,13 +33,13 @@ ifeq ($(DEBUG),1) 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 info.o shared_memory.o \ - pwm.o irq.o command.o testing.o + pwm.o shell.o irq.o command.o testing.o else LDFLAGS =-Wl,-u 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 info.o shared_memory.o command.o irq.o + pwm.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/config.h b/avr/usbload/config.h index 53c7d42..5759072 100644 --- a/avr/usbload/config.h +++ b/avr/usbload/config.h @@ -47,7 +47,7 @@ #define HW_VERSION "2.6" #define SW_VERSION "1.0" -#define DO_CRC_CHECK_LOADER 1 +#define DO_CRC_CHECK_LOADER 0 #define DO_CRC_CHECK 0 #define DO_SHM_SCRATCHPAD 1 #define DO_SHM 1 diff --git a/avr/usbload/shell.c b/avr/usbload/shell.c new file mode 100644 index 0000000..9cadb15 --- /dev/null +++ b/avr/usbload/shell.c @@ -0,0 +1,65 @@ +/* + * ===================================================================================== + * + * ________ .__ __ ________ ____ ________ + * \_____ \ __ __|__| ____ | | __\______ \ _______ _/_ |/ _____/ + * / / \ \| | \ |/ ___\| |/ / | | \_/ __ \ \/ /| / __ \ + * / \_/. \ | / \ \___| < | ` \ ___/\ / | \ |__\ \ + * \_____\ \_/____/|__|\___ >__|_ \/_______ /\___ >\_/ |___|\_____ / + * \__> \/ \/ \/ \/ \/ + * + * www.optixx.org + * + * + * Version: 1.0 + * Created: 07/21/2009 03:32:16 PM + * Author: david@optixx.org + * + * ===================================================================================== + */ + #include + #include + #include + #include + + #include "pwm.h" + #include "debug.h" + #include "info.h" + #include "sram.h" + + #define RECEIVE_BUF_LEN 40 + + uint8_t recv_buf[RECEIVE_BUF_LEN]; + volatile uint8_t recv_counter = 0; + volatile uint8_t cr = 0; + +ISR(USART0_RX_vect) // Interrupt for UART Byte received +{ + UCSR0B &= (255 - (1<'); + } + recv_buf[recv_counter] = UDR0; + uart_putc(recv_buf[recv_counter]); /* do a echo, maybe should reside not in interrupt */ + if (recv_buf[recv_counter] == 0x0d) { + /* recv_buf[recv_counter] = 0; */ + cr = 1; // found a CR, so the application should do something + recv_buf[++recv_counter]='\0'; // terminate string + recv_counter = 0; + uart_putc('\n'); + } else { + // we accept backspace or delete + if ((recv_buf[recv_counter] == 0x08 || recv_buf[recv_counter] == 0x7f) && recv_counter > 0) { + recv_counter--; + } else { + recv_counter++; + } + } + UCSR0B |= (1<__|_ \/_______ /\___ >\_/ |___|\_____ / + * \__> \/ \/ \/ \/ \/ + * + * www.optixx.org + * + * + * Version: 1.0 + * Created: 07/21/2009 03:32:16 PM + * Author: david@optixx.org + * + * ===================================================================================== + */ + +#ifndef __SHELL_H__ +#define __SHELL_H__ + + #endif diff --git a/avr/usbload/uart.c b/avr/usbload/uart.c index f336d2f..14a03a1 100644 --- a/avr/usbload/uart.c +++ b/avr/usbload/uart.c @@ -52,7 +52,7 @@ void uart_init(void) } - +/* ISR(USART0_RX_vect) { uint8_t c; @@ -62,7 +62,7 @@ ISR(USART0_RX_vect) intflags.rx_int = 1; } } - +*/ void uart_putc(uint8_t c) { From 6db781d12d472a362b75ed0f82e7a5601ff309f2 Mon Sep 17 00:00:00 2001 From: optixx Date: Sun, 20 Sep 2009 14:53:41 +0200 Subject: [PATCH 13/15] add string and token helpers --- avr/usbload/Makefile | 4 +- avr/usbload/shell.c | 107 ++++++ avr/usbload/util.c | 132 +++++++ avr/usbload/util.h | 32 ++ quickdev16.tmproj | 877 +++++++------------------------------------ 5 files changed, 409 insertions(+), 743 deletions(-) create mode 100644 avr/usbload/util.c create mode 100644 avr/usbload/util.h diff --git a/avr/usbload/Makefile b/avr/usbload/Makefile index 8bc5e17..ac14318 100644 --- a/avr/usbload/Makefile +++ b/avr/usbload/Makefile @@ -33,13 +33,13 @@ ifeq ($(DEBUG),1) 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 info.o shared_memory.o \ - pwm.o shell.o irq.o command.o testing.o + pwm.o util.o shell.o irq.o command.o testing.o else LDFLAGS =-Wl,-u 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 shell.o info.o shared_memory.o command.o irq.o + pwm.o uril.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/shell.c b/avr/usbload/shell.c index 9cadb15..962478d 100644 --- a/avr/usbload/shell.c +++ b/avr/usbload/shell.c @@ -33,6 +33,109 @@ volatile uint8_t recv_counter = 0; volatile uint8_t cr = 0; + + static char *token_ptr; + + static char *get_token(void) + { + char *p = token_ptr; + while (*p == ' ') + p++; + if (*p == '\0') + return NULL; + token_ptr = p; + do { + token_ptr++; + if (*token_ptr == ' ') { + *token_ptr++ = '\0'; + break; + } + } while (*token_ptr != '\0'); + return p; + } + + static int get_dec(int *decval) + { + const char *t; + t = get_token(); + if (t != NULL) { + int x = Util_sscandec(t); + if (x < 0) + return FALSE; + *decval = x; + return TRUE; + } + return FALSE; + } + + static int parse_hex(const char *s, UWORD *hexval) + { + int x = Util_sscanhex(s); + #ifdef MONITOR_HINTS + int y = find_label_value(s); + if (y >= 0) { + if (x < 0 || x > 0xffff || x == y) { + *hexval = (UWORD) y; + return TRUE; + } + /* s can be a hex number or a label name */ + printf("%s is ambiguous. Use 0%X or %X instead.\n", s, x, y); + return FALSE; + } + #endif + if (x < 0 || x > 0xffff) + return FALSE; + *hexval = (UWORD) x; + return TRUE; + } + + static int get_hex(UWORD *hexval) + { + const char *t; + t = get_token(); + if (t != NULL) + return parse_hex(t, hexval); + return FALSE; + } + + static int get_hex2(UWORD *hexval1, UWORD *hexval2) + { + return get_hex(hexval1) && get_hex(hexval2); + } + + static int get_hex3(UWORD *hexval1, UWORD *hexval2, UWORD *hexval3) + { + return get_hex(hexval1) && get_hex(hexval2) && get_hex(hexval3); + } + + static void get_uword(UWORD *val) + { + if (!get_hex(val)) + printf("Invalid argument!\n"); + } + + static void get_ubyte(UBYTE *val) + { + UWORD uword; + if (!get_hex(&uword) || uword > 0xff) + printf("Invalid argument!\n"); + else + *val = (UBYTE) uword; + } + + static int get_bool(void) + { + const char *t; + t = get_token(); + if (t != NULL) { + int result = Util_sscanbool(t); + if (result >= 0) + return result; + } + printf("Invalid argument (should be 0 or 1)!\n"); + return -1; + } + ISR(USART0_RX_vect) // Interrupt for UART Byte received { UCSR0B &= (255 - (1<'); @@ -52,7 +156,10 @@ ISR(USART0_RX_vect) // Interrupt for UART Byte received cr = 1; // found a CR, so the application should do something recv_buf[++recv_counter]='\0'; // terminate string recv_counter = 0; + uart_putc('\r'); uart_putc('\n'); + uart_putc(':'); + uart_putc('>'); } else { // we accept backspace or delete if ((recv_buf[recv_counter] == 0x08 || recv_buf[recv_counter] == 0x7f) && recv_counter > 0) { diff --git a/avr/usbload/util.c b/avr/usbload/util.c new file mode 100644 index 0000000..84bf7d6 --- /dev/null +++ b/avr/usbload/util.c @@ -0,0 +1,132 @@ +/* + * ===================================================================================== + * + * ________ .__ __ ________ ____ ________ + * \_____ \ __ __|__| ____ | | __\______ \ _______ _/_ |/ _____/ + * / / \ \| | \ |/ ___\| |/ / | | \_/ __ \ \/ /| / __ \ + * / \_/. \ | / \ \___| < | ` \ ___/\ / | \ |__\ \ + * \_____\ \_/____/|__|\___ >__|_ \/_______ /\___ >\_/ |___|\_____ / + * \__> \/ \/ \/ \/ \/ + * + * www.optixx.org + * + * + * Version: 1.0 + * Created: 07/21/2009 03:32:16 PM + * Author: david@optixx.org + * + * ===================================================================================== + */ + +#include +#include +#include + +uint8_t *util_strupper(uint8_t *s) +{ + uint8_t *p; + for (p = s; *p != '\0'; p++) + if (*p >= 'a' && *p <= 'z') + *p += 'A' - 'a'; + return s; +} + +uint8_t *util_strlower(uint8_t *s) +{ + uint8_t *p; + for (p = s; *p != '\0'; p++) + if (*p >= 'A' && *p <= 'Z') + *p += 'a' - 'A'; + return s; +} + +void util_chomp(uint8_t *s) +{ + uint16_t len; + + len = strlen((char*)s); + if (len >= 2 && s[len - 1] == '\n' && s[len - 2] == '\r') + s[len - 2] = '\0'; + else if (len >= 1 && (s[len - 1] == '\n' || s[len - 1] == '\r')) + s[len - 1] = '\0'; +} + +void util_trim(uint8_t *s) +{ + uint8_t *p = s; + uint8_t *q; + /* skip leading whitespace */ + while (*p == ' ' || *p == '\t' || *p == '\r' || *p == '\n') + p++; + /* now p points at the first non-whitespace uint8_tacter */ + + if (*p == '\0') { + /* only whitespace */ + *s = '\0'; + return; + } + + q = s + strlen((char*)s); + /* skip trailing whitespace */ + /* we have found p < q such that *p is non-whitespace, + so this loop terminates with q >= p */ + do + q--; + while (*q == ' ' || *q == '\t' || *q == '\r' || *q == '\n'); + + /* now q points at the last non-whitespace uint8_tacter */ + /* cut off trailing whitespace */ + *++q = '\0'; + + /* move to string */ + memmove(s, p, q + 1 - p); +} + +uint32_t util_sscandec(const uint8_t *s) +{ + uint32_t result; + if (*s == '\0') + return -1; + result = 0; + for (;;) { + if (*s >= '0' && *s <= '9') + result = 10 * result + *s - '0'; + else if (*s == '\0') + return result; + else + return -1; + s++; + } +} + +uint32_t util_sscanhex(const uint8_t *s) +{ + uint32_t result; + if (*s == '\0') + return -1; + result = 0; + for (;;) { + if (*s >= '0' && *s <= '9') + result = 16 * result + *s - '0'; + else if (*s >= 'A' && *s <= 'F') + result = 16 * result + *s - 'A' + 10; + else if (*s >= 'a' && *s <= 'f') + result = 16 * result + *s - 'a' + 10; + else if (*s == '\0') + return result; + else + return -1; + s++; + } +} + +uint8_t util_sscanbool(const uint8_t *s) +{ + if (*s == '0' && s[1] == '\0') + return 0; + if (*s == '1' && s[1] == '\0') + return 1; + return -1; +} + + diff --git a/avr/usbload/util.h b/avr/usbload/util.h new file mode 100644 index 0000000..0afd213 --- /dev/null +++ b/avr/usbload/util.h @@ -0,0 +1,32 @@ +/* + * ===================================================================================== + * + * ________ .__ __ ________ ____ ________ + * \_____ \ __ __|__| ____ | | __\______ \ _______ _/_ |/ _____/ + * / / \ \| | \ |/ ___\| |/ / | | \_/ __ \ \/ /| / __ \ + * / \_/. \ | / \ \___| < | ` \ ___/\ / | \ |__\ \ + * \_____\ \_/____/|__|\___ >__|_ \/_______ /\___ >\_/ |___|\_____ / + * \__> \/ \/ \/ \/ \/ + * + * www.optixx.org + * + * + * Version: 1.0 + * Created: 07/21/2009 03:32:16 PM + * Author: david@optixx.org + * + * ===================================================================================== + */ + +#ifndef __UTIL_H__ +#define __UTIL_H__ + + uint8_t *util_strupper(uint8_t *s); +uint8_t *util_strlower(uint8_t *s); +void util_chomp(uint8_t *s); +void util_trim(uint8_t *s); +uint32_t util_sscandec(const uint8_t *s); +uint32_t util_sscanhex(const uint8_t *s); +uint8_t util_sscanbool(const uint8_t *s); + +#endif diff --git a/quickdev16.tmproj b/quickdev16.tmproj index eea636f..76bee95 100644 --- a/quickdev16.tmproj +++ b/quickdev16.tmproj @@ -3,7 +3,7 @@ currentDocument - avr/usbload/sram.h + avr/usbload/util.c documents @@ -21,451 +21,19 @@ 271 metaData - README - - caret - - column - 49 - line - 7 - - columnSelection - - firstVisibleColumn - 0 - firstVisibleLine - 0 - selectFrom - - column - 1 - line - 7 - - selectTo - - column - 49 - line - 7 - - - avr/bootloader/bootloader.c - - caret - - column - 0 - line - 31 - - columnSelection - - firstVisibleColumn - 0 - firstVisibleLine - 0 - selectFrom - - column - 0 - line - 30 - - selectTo - - column - 0 - line - 31 - - - avr/bootloader/bootloader.hex - - caret - - column - 0 - line - 0 - - firstVisibleColumn - 0 - firstVisibleLine - 0 - - avr/bootloader/config.h - - caret - - column - 0 - line - 22 - - firstVisibleColumn - 0 - firstVisibleLine - 0 - - avr/bootloader/interrupts.S - - caret - - column - 0 - line - 0 - - firstVisibleColumn - 0 - firstVisibleLine - 0 - - avr/bootloader/usbconfig.h - - caret - - column - 39 - line - 50 - - firstVisibleColumn - 0 - firstVisibleLine - 144 - - avr/usbload/checksize - - caret - - column - 0 - line - 12 - - firstVisibleColumn - 0 - firstVisibleLine - 0 - - avr/usbload/command.c - - caret - - column - 0 - line - 22 - - firstVisibleColumn - 0 - firstVisibleLine - 14 - - avr/usbload/command.h - - caret - - column - 16 - line - 25 - - columnSelection - - firstVisibleColumn - 0 - firstVisibleLine - 0 - selectFrom - - column - 0 - line - 0 - - selectTo - - column - 0 - line - 29 - - - avr/usbload/config.h - - caret - - column - 38 - line - 46 - - firstVisibleColumn - 0 - firstVisibleLine - 0 - - avr/usbload/crc.c - - caret - - column - 20 - line - 81 - - firstVisibleColumn - 0 - firstVisibleLine - 41 - - avr/usbload/crc.h - - caret - - column - 26 - line - 6 - - firstVisibleColumn - 0 - firstVisibleLine - 0 - - avr/usbload/debug.c - - caret - - column - 31 - line - 39 - - firstVisibleColumn - 0 - firstVisibleLine - 0 - - avr/usbload/debug.h - - caret - - column - 0 - line - 33 - - columnSelection - - firstVisibleColumn - 0 - firstVisibleLine - 0 - selectFrom - - column - 0 - line - 31 - - selectTo - - column - 0 - line - 33 - - - avr/usbload/dump.c - - caret - - column - 13 - line - 67 - - columnSelection - - firstVisibleColumn - 0 - firstVisibleLine - 31 - selectFrom - - column - 5 - line - 67 - - selectTo - - column - 16 - line - 67 - - - avr/usbload/dump.h - - caret - - column - 0 - line - 0 - - firstVisibleColumn - 0 - firstVisibleLine - 0 - - avr/usbload/fifo.c - - caret - - column - 17 - line - 22 - - firstVisibleColumn - 0 - firstVisibleLine - 0 - - avr/usbload/fifo.h - - caret - - column - 0 - line - 19 - - firstVisibleColumn - 0 - firstVisibleLine - 0 - - avr/usbload/info.c - - caret - - column - 4 - line - 33 - - firstVisibleColumn - 0 - firstVisibleLine - 0 - - avr/usbload/info.h - - caret - - column - 22 - line - 32 - - firstVisibleColumn - 0 - firstVisibleLine - 0 - - avr/usbload/irq.c - - caret - - column - 0 - line - 28 - - firstVisibleColumn - 0 - firstVisibleLine - 21 - - avr/usbload/irq.h - - caret - - column - 13 - line - 22 - - firstVisibleColumn - 0 - firstVisibleLine - 0 - - avr/usbload/loader.c - - caret - - column - 0 - line - 0 - - firstVisibleColumn - 0 - firstVisibleLine - 443 - - avr/usbload/loader.h - - caret - - column - 0 - line - 9 - - firstVisibleColumn - 0 - firstVisibleLine - 0 - avr/usbload/main.c caret column - 0 + 42 line - 30 + 252 - columnSelection - firstVisibleColumn 0 firstVisibleLine - 0 - selectFrom - - column - 0 - line - 29 - - selectTo - - column - 0 - line - 30 - + 247 avr/usbload/rle.h @@ -476,154 +44,28 @@ line 0 - firstVisibleColumn - 0 - firstVisibleLine - 0 - - avr/usbload/shared_memory.c - - caret - - column - 41 - line - 135 - - firstVisibleColumn - 0 - firstVisibleLine - 108 - - avr/usbload/shared_memory.h - - caret - - column - 50 - line - 50 - - firstVisibleColumn - 0 - firstVisibleLine - 22 - - avr/usbload/sram.c - - caret - - column - 24 - line - 34 - - firstVisibleColumn - 0 - firstVisibleLine - 141 - - avr/usbload/sram.h - - caret - - column - 66 - line - 154 - - firstVisibleColumn - 0 - firstVisibleLine - 132 - - avr/usbload/testing.c - - caret - - column - 0 - line - 106 - - firstVisibleColumn - 0 - firstVisibleLine - 25 - - avr/usbload/testing.h - - caret - - column - 0 - line - 0 - - firstVisibleColumn - 0 - firstVisibleLine - 0 - - avr/usbload/timer.c - - caret - - column - 41 - line - 61 - columnSelection firstVisibleColumn 0 firstVisibleLine - 28 + 0 selectFrom column - 0 + 17 line - 0 + 21 selectTo column 0 line - 94 - - - avr/usbload/timer.h - - caret - - column 0 - line - 29 - firstVisibleColumn - 0 - firstVisibleLine - 0 - avr/usbload/uart.c - - caret - - column - 0 - line - 34 - - firstVisibleColumn - 0 - firstVisibleLine - 44 - - avr/usbload/usb_bulk.c + avr/usbload/shell.c caret @@ -632,171 +74,159 @@ line 74 - firstVisibleColumn - 0 - firstVisibleLine - 40 - - avr/usbload/usbconfig.h - - caret - - column - 80 - line - 251 - columnSelection firstVisibleColumn 0 firstVisibleLine - 231 + 80 selectFrom column - 32 + 0 line - 251 + 73 selectTo column - 80 + 0 line - 251 + 74 - avr/usbload/watchdog.c + avr/usbload/shell.h caret column 0 line + 0 + + columnSelection + + firstVisibleColumn + 0 + firstVisibleLine + 0 + selectFrom + + column + 0 + line + 19 + + selectTo + + column + 0 + line + 0 + + + avr/usbload/sram.c + + caret + + column 22 - - firstVisibleColumn - 0 - firstVisibleLine - 0 - - avr/usbload/watchdog.h - - caret - - column - 0 line - 0 - - firstVisibleColumn - 0 - firstVisibleLine - 0 - - poc/avr_sdcard/fat.c - - caret - - column - 0 - line - 38 - - firstVisibleColumn - 0 - firstVisibleLine - 0 - - poc/avr_sdcard/fat.h - - caret - - column - 4 - line - 63 + 287 columnSelection firstVisibleColumn 0 firstVisibleLine - 23 + 206 selectFrom column - 1 - line - 63 - - selectTo - - column - 9 - line - 63 - - - poc/avr_sdcard/main.c - - caret - - column - 12 - line - 170 - - columnSelection - - firstVisibleColumn - 0 - firstVisibleLine - 137 - selectFrom - - column - 1 - line - 170 - - selectTo - - column - 20 - line - 170 - - - poc/avr_sdcard/main.lst - - caret - - column - 0 - line - 0 - - firstVisibleColumn - 0 - firstVisibleLine - 0 - - poc/avr_usbload/sram.c - - caret - - column - 17 - line 5 + line + 287 + + selectTo + + column + 31 + line + 287 + + + avr/usbload/uart.c + + caret + + column + 0 + line + 20 + + firstVisibleColumn + 0 + firstVisibleLine + 26 + + avr/usbload/usb_bulk.h + + caret + + column + 0 + line + 0 firstVisibleColumn 0 firstVisibleLine 0 + avr/usbload/util.c + + caret + + column + 15 + line + 46 + + firstVisibleColumn + 0 + firstVisibleLine + 14 + + avr/usbload/util.h + + caret + + column + 0 + line + 0 + + columnSelection + + firstVisibleColumn + 0 + firstVisibleLine + 0 + selectFrom + + column + 3 + line + 18 + + selectTo + + column + 0 + line + 0 + + snes/banktest/LoadGraphics.asm caret @@ -828,50 +258,15 @@ openDocuments - avr/usbload/testing.h - avr/usbload/testing.c - avr/usbload/timer.c - avr/usbload/irq.c - avr/bootloader/bootloader.hex - avr/usbload/irq.h - avr/usbload/timer.h - avr/usbload/uart.c - avr/usbload/usb_bulk.c - avr/usbload/watchdog.c - avr/usbload/watchdog.h - poc/avr_sdcard/fat.c - poc/avr_sdcard/fat.h - poc/avr_sdcard/main.lst - avr/bootloader/config.h - avr/bootloader/bootloader.c - README - avr/bootloader/usbconfig.h - avr/usbload/debug.c - avr/usbload/dump.h - avr/usbload/crc.c - avr/usbload/command.h - avr/usbload/dump.c - avr/usbload/loader.h - avr/usbload/info.h - avr/usbload/loader.c - avr/usbload/fifo.c - avr/usbload/command.c - avr/usbload/debug.h - avr/usbload/rle.h - avr/usbload/config.h - poc/avr_sdcard/main.c - poc/avr_usbload/sram.c - avr/usbload/sram.h - avr/usbload/shared_memory.h - avr/usbload/checksize - avr/usbload/shared_memory.c - avr/bootloader/interrupts.S - avr/usbload/info.c - avr/usbload/fifo.h - avr/usbload/main.c avr/usbload/sram.c - avr/usbload/usbconfig.h - avr/usbload/crc.h + avr/usbload/main.c + avr/usbload/shell.c + avr/usbload/uart.c + avr/usbload/util.c + avr/usbload/util.h + avr/usbload/usb_bulk.h + avr/usbload/rle.h + avr/usbload/shell.h showFileHierarchyDrawer @@ -891,13 +286,6 @@ subItems - bootloader - - isExpanded - - subItems - - usbload isExpanded @@ -907,6 +295,13 @@ + scripts + + isExpanded + + subItems + + From 8beb0bbb4fff3cdb7be186266948f4f2af9f462a Mon Sep 17 00:00:00 2001 From: optixx Date: Sun, 20 Sep 2009 20:45:44 +0200 Subject: [PATCH 14/15] add simple shell comomand parsr --- avr/usbload/dump.c | 1 + avr/usbload/shell.c | 168 ++++++++++++++++++++++++++------------------ avr/usbload/shell.h | 2 +- quickdev16.tmproj | 162 ++++++++++++++++++++++++++++++------------ 4 files changed, 220 insertions(+), 113 deletions(-) diff --git a/avr/usbload/dump.c b/avr/usbload/dump.c index d13d689..b9ab93d 100644 --- a/avr/usbload/dump.c +++ b/avr/usbload/dump.c @@ -26,6 +26,7 @@ #include "info.h" #include "uart.h" #include "sram.h" +#include "dump.h" extern FILE uart_stdout; diff --git a/avr/usbload/shell.c b/avr/usbload/shell.c index 962478d..b941d26 100644 --- a/avr/usbload/shell.c +++ b/avr/usbload/shell.c @@ -17,28 +17,34 @@ * * ===================================================================================== */ - #include - #include - #include - #include +#include +#include +#include +#include +#include +#include +#include +#include - #include "pwm.h" - #include "debug.h" - #include "info.h" - #include "sram.h" - - #define RECEIVE_BUF_LEN 40 - - uint8_t recv_buf[RECEIVE_BUF_LEN]; - volatile uint8_t recv_counter = 0; - volatile uint8_t cr = 0; - - - static char *token_ptr; - static char *get_token(void) - { - char *p = token_ptr; +#include "pwm.h" +#include "debug.h" +#include "info.h" +#include "sram.h" +#include "util.h" +#include "uart.h" + +#define RECEIVE_BUF_LEN 40 + +uint8_t recv_buf[RECEIVE_BUF_LEN]; +volatile uint8_t recv_counter = 0; +volatile uint8_t cr = 0; + +uint8_t *token_ptr; + +uint8_t *get_token(void) +{ + uint8_t *p = token_ptr; while (*p == ' ') p++; if (*p == '\0') @@ -52,83 +58,78 @@ } } while (*token_ptr != '\0'); return p; - } +} - static int get_dec(int *decval) - { - const char *t; +uint8_t get_dec(uint32_t *decval) +{ + const uint8_t *t; t = get_token(); if (t != NULL) { - int x = Util_sscandec(t); + int x = util_sscandec(t); if (x < 0) - return FALSE; + return 0; *decval = x; - return TRUE; + return 1; } - return FALSE; + return 0; } - static int parse_hex(const char *s, UWORD *hexval) - { - int x = Util_sscanhex(s); - #ifdef MONITOR_HINTS - int y = find_label_value(s); - if (y >= 0) { - if (x < 0 || x > 0xffff || x == y) { - *hexval = (UWORD) y; - return TRUE; - } - /* s can be a hex number or a label name */ - printf("%s is ambiguous. Use 0%X or %X instead.\n", s, x, y); - return FALSE; - } - #endif - if (x < 0 || x > 0xffff) - return FALSE; - *hexval = (UWORD) x; - return TRUE; +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; } - static int get_hex(UWORD *hexval) - { - const char *t; +uint8_t get_hex(uint32_t *hexval) +{ + const uint8_t *t; t = get_token(); if (t != NULL) return parse_hex(t, hexval); - return FALSE; + return 0; } - static int get_hex2(UWORD *hexval1, UWORD *hexval2) - { +uint8_t get_hex_arg2(uint32_t *hexval1, uint32_t *hexval2) +{ return get_hex(hexval1) && get_hex(hexval2); - } +} - static int get_hex3(UWORD *hexval1, UWORD *hexval2, UWORD *hexval3) - { +uint8_t get_hex_arg3(uint32_t *hexval1, uint32_t *hexval2, uint32_t *hexval3) +{ return get_hex(hexval1) && get_hex(hexval2) && get_hex(hexval3); +} + +static uint8_t get_int32(uint32_t *val) + { + if (!get_hex(val)){ + printf("Invalid argument!\n"); + return 0; + } else { + return 1; + } } - static void get_uword(UWORD *val) + static uint8_t get_int8(uint8_t *val) { - if (!get_hex(val)) + uint32_t ret; + if (!get_hex(&ret) ||ret > 0xff){ printf("Invalid argument!\n"); - } - - static void get_ubyte(UBYTE *val) - { - UWORD uword; - if (!get_hex(&uword) || uword > 0xff) - printf("Invalid argument!\n"); - else - *val = (UBYTE) uword; + return 0; + }else{ + *val = (uint8_t)ret; + return 1; + } } static int get_bool(void) { - const char *t; + const uint8_t *t; t = get_token(); if (t != NULL) { - int result = Util_sscanbool(t); + int result = util_sscanbool(t); if (result >= 0) return result; } @@ -170,3 +171,32 @@ ISR(USART0_RX_vect) // Interrupt for UART Byte received } UCSR0B |= (1< currentDocument - avr/usbload/util.c + avr/usbload/shell.c documents @@ -21,19 +21,109 @@ 271 metaData + avr/usbload/crc.c + + caret + + column + 0 + line + 59 + + firstVisibleColumn + 0 + firstVisibleLine + 15 + + avr/usbload/debug.c + + caret + + column + 0 + line + 26 + + columnSelection + + firstVisibleColumn + 0 + firstVisibleLine + 0 + selectFrom + + column + 0 + line + 25 + + selectTo + + column + 0 + line + 26 + + + avr/usbload/dump.c + + caret + + column + 12 + line + 67 + + columnSelection + + firstVisibleColumn + 0 + firstVisibleLine + 35 + selectFrom + + column + 5 + line + 67 + + selectTo + + column + 16 + line + 67 + + avr/usbload/main.c caret column - 42 + 0 line - 252 + 28 + columnSelection + firstVisibleColumn 0 firstVisibleLine - 247 + 0 + selectFrom + + column + 0 + line + 22 + + selectTo + + column + 0 + line + 28 + avr/usbload/rle.h @@ -65,35 +155,33 @@ 0 + avr/usbload/shared_memory.h + + caret + + column + 45 + line + 24 + + firstVisibleColumn + 0 + firstVisibleLine + 0 + avr/usbload/shell.c caret column - 0 + 41 line - 74 + 177 - columnSelection - firstVisibleColumn 0 firstVisibleLine - 80 - selectFrom - - column - 0 - line - 73 - - selectTo - - column - 0 - line - 74 - + 154 avr/usbload/shell.h @@ -102,28 +190,12 @@ column 0 line - 0 + 23 - columnSelection - firstVisibleColumn 0 firstVisibleLine 0 - selectFrom - - column - 0 - line - 19 - - selectTo - - column - 0 - line - 0 - avr/usbload/sram.c @@ -188,14 +260,14 @@ caret column - 15 + 1 line - 46 + 25 firstVisibleColumn 0 firstVisibleLine - 14 + 0 avr/usbload/util.h @@ -261,12 +333,16 @@ avr/usbload/sram.c avr/usbload/main.c avr/usbload/shell.c + avr/usbload/crc.c + avr/usbload/dump.c + avr/usbload/debug.c avr/usbload/uart.c avr/usbload/util.c avr/usbload/util.h avr/usbload/usb_bulk.h avr/usbload/rle.h avr/usbload/shell.h + avr/usbload/shared_memory.h showFileHierarchyDrawer From 105575bc375460313e8bbf720e9193962f4c73c5 Mon Sep 17 00:00:00 2001 From: optixx Date: Mon, 21 Sep 2009 08:32:17 +0200 Subject: [PATCH 15/15] add reset command --- avr/usbload/main.c | 3 +++ avr/usbload/shell.c | 52 ++++++++++++++++++++++++++++++++++----------- avr/usbload/shell.h | 2 ++ 3 files changed, 45 insertions(+), 12 deletions(-) diff --git a/avr/usbload/main.c b/avr/usbload/main.c index 2354de0..2257f5d 100644 --- a/avr/usbload/main.c +++ b/avr/usbload/main.c @@ -47,6 +47,7 @@ #include "irq.h" #include "pwm.h" #include "testing.h" +#include "shell.h" @@ -337,6 +338,7 @@ int main(void) info_P(PSTR("USB poll\n")); while (req_state != REQ_STATUS_SNES) { usbPoll(); + shell_run(); } @@ -363,6 +365,7 @@ int main(void) info_P(PSTR("Poll USB\n")); while ((req_state != REQ_STATUS_AVR)) { usbPoll(); + shell_run(); } info_P(PSTR("-->Switch TO AVR\n")); diff --git a/avr/usbload/shell.c b/avr/usbload/shell.c index b941d26..a522bb7 100644 --- a/avr/usbload/shell.c +++ b/avr/usbload/shell.c @@ -33,6 +33,8 @@ #include "sram.h" #include "util.h" #include "uart.h" +#include "dump.h" +#include "irq.h" #define RECEIVE_BUF_LEN 40 @@ -136,6 +138,14 @@ static uint8_t get_int32(uint32_t *val) printf("Invalid argument (should be 0 or 1)!\n"); return -1; } + void prompt(void){ + + uart_putc('\r'); + uart_putc('\n'); + uart_putc(':'); + uart_putc('>'); + + } ISR(USART0_RX_vect) // Interrupt for UART Byte received { @@ -145,10 +155,7 @@ ISR(USART0_RX_vect) // Interrupt for UART Byte received cr=1; recv_buf[recv_counter]='\0'; recv_counter=0; - uart_putc('\r'); - uart_putc('\n'); - uart_putc(':'); - uart_putc('>'); + prompt(); } recv_buf[recv_counter] = UDR0; uart_putc(recv_buf[recv_counter]); /* do a echo, maybe should reside not in interrupt */ @@ -157,10 +164,7 @@ ISR(USART0_RX_vect) // Interrupt for UART Byte received cr = 1; // found a CR, so the application should do something recv_buf[++recv_counter]='\0'; // terminate string recv_counter = 0; - uart_putc('\r'); - uart_putc('\n'); - uart_putc(':'); - uart_putc('>'); + prompt(); } else { // we accept backspace or delete if ((recv_buf[recv_counter] == 0x08 || recv_buf[recv_counter] == 0x7f) && recv_counter > 0) { @@ -173,9 +177,10 @@ ISR(USART0_RX_vect) // Interrupt for UART Byte received } -void shellrun(void) +uint8_t command_buf[RECEIVE_BUF_LEN]; + +void shell_run(void) { - uint8_t command_buf[RECEIVE_BUF_LEN]; uint8_t *t; uint32_t arg1; uint32_t arg2; @@ -188,6 +193,7 @@ void shellrun(void) token_ptr = command_buf; t = get_token(); + if (t == NULL) return; @@ -197,6 +203,28 @@ void shellrun(void) if (get_hex_arg2(&arg1,&arg2)) dump_memory(arg1,arg2); else - printf("ERROR: arg parsing\n"); + printf("DUMP %i %i\n",arg1,arg2); } -} \ No newline at end of file + else if (strcmp((char*)t, "RESET") == 0) { + leave_application(); + } + 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 + + + + +} + + diff --git a/avr/usbload/shell.h b/avr/usbload/shell.h index 536aaab..db67b27 100644 --- a/avr/usbload/shell.h +++ b/avr/usbload/shell.h @@ -21,4 +21,6 @@ #ifndef __SHELL_H__ #define __SHELL_H__ + void shell_run(void); + #endif