diff --git a/avr/usbload/config.h b/avr/usbload/config.h index d8e7465..ee530ed 100644 --- a/avr/usbload/config.h +++ b/avr/usbload/config.h @@ -3,9 +3,10 @@ #define __config_h__ #define DEBUG_USB 1 -#define DEBUG_USB_RAW 1 -#define DEBUG_SRAM 1 -#define DEBUG_SREG 1 +#undef DEBUG_USB_RAW 1 +#undef DEBUG_SRAM 1 +#undef DEBUG_SRAM_RAW +#undef DEBUG_SREG #define DEBUG 1 diff --git a/avr/usbload/crc.c b/avr/usbload/crc.c index ab0b09f..1e5e968 100644 --- a/avr/usbload/crc.c +++ b/avr/usbload/crc.c @@ -62,7 +62,6 @@ uint16_t crc_check_memory_range(uint32_t start_addr, uint32_t size,uint8_t *buff { uint16_t crc = 0; uint32_t addr; - uint8_t req_bank = 0; for (addr = start_addr; addr < start_addr + size; addr += TRANSFER_BUFFER_SIZE) { sram_read_buffer(addr, buffer, TRANSFER_BUFFER_SIZE); crc = do_crc_update(crc, buffer, TRANSFER_BUFFER_SIZE); @@ -71,4 +70,4 @@ uint16_t crc_check_memory_range(uint32_t start_addr, uint32_t size,uint8_t *buff printf("crc_check_memory_range: Addr: 0x%08lx CRC: 0x%04x\n", addr, crc); #endif return crc; -} \ No newline at end of file +} diff --git a/avr/usbload/crc.h b/avr/usbload/crc.h index 9139c20..a09b75d 100644 --- a/avr/usbload/crc.h +++ b/avr/usbload/crc.h @@ -6,4 +6,4 @@ uint16_t crc_xmodem_update (uint16_t crc, uint8_t data); uint16_t do_crc(uint8_t * data,uint16_t size); uint16_t do_crc_update(uint16_t crc,uint8_t * data,uint16_t size); void crc_check_memory(uint32_t top_addr,uint8_t *buffer); -uint16_t crc_check_memory_range(uint32_t start_addr, uint32_t size,uint8_t *buffer); \ No newline at end of file +uint16_t crc_check_memory_range(uint32_t start_addr, uint32_t size,uint8_t *buffer); diff --git a/avr/usbload/debug.c b/avr/usbload/debug.c index 6ae1782..c453efa 100644 --- a/avr/usbload/debug.c +++ b/avr/usbload/debug.c @@ -41,3 +41,4 @@ void dump_packet(uint32_t addr, uint32_t len, uint8_t * packet) printf("|\n"); } } + diff --git a/avr/usbload/main.c b/avr/usbload/main.c index 9bfb06e..e9be090 100644 --- a/avr/usbload/main.c +++ b/avr/usbload/main.c @@ -1,5 +1,4 @@ #include -#include #include /* for sei() */ #include /* for _delay_ms() */ #include @@ -60,12 +59,6 @@ usbMsgLen_t usbFunctionSetup(uchar data[8]) * ------------------------------------------------------------------------- */ } else if (rq->bRequest == USB_UPLOAD_ADDR) { - if (req_state != REQ_STATUS_IDLE){ -#if DEBUG_USB - printf("USB_UPLOAD_ADDR: ERROR state is not REQ_STATUS_IDLE\n"); -#endif - return 0; - } req_state = REQ_STATUS_UPLOAD; req_addr = rq->wValue.word; @@ -244,6 +237,48 @@ usbMsgLen_t usbFunctionSetup(uchar data[8]) * ------------------------------------------------------------------------- */ +void test_read_write(){ + + uint8_t i; + uint32_t addr; + avr_bus_active(); + addr = 0x000000; + i = 1; + while (addr++ <= 0x0000ff){ + sram_write(addr,i++); + } + + addr = 0x000000; + while (addr++ <= 0x0000ff){ + printf("read addr=0x%08lx %x\n",addr,sram_read(addr)); + } +} + + +void test_bulk_read_write(){ + + uint8_t i; + uint32_t addr; + avr_bus_active(); + addr = 0x000000; + i = 0; + sram_bulk_write_start(addr); + while (addr++ <= 0x3fffff){ + sram_bulk_write(i++); + sram_bulk_write_next(); + } + sram_bulk_write_end(); + + addr = 0x000000; + sram_bulk_read_start(addr); + while (addr <= 0x3fffff){ + printf("addr=0x%08lx %x\n",addr,sram_bulk_read()); + sram_bulk_read_next(); + addr ++; + } + sram_bulk_read_end(); +} + int main(void) { uint8_t i; @@ -255,19 +290,9 @@ int main(void) system_init(); printf("Sytem Init\n"); - avr_bus_active(); - - addr = 0x000000; - i = 0; - while (addr++ <= 0x00ffff){ - sram_write(addr,i++); - } + //while(1); - addr = 0x000000; - while (addr++ <= 0x00ffff){ - printf("read addr=0x%08lx %x\n",addr,sram_read(addr)); - } - + avr_bus_active(); usbInit(); printf("USB Init\n"); usbDeviceDisconnect(); /* enforce re-enumeration, do this while @@ -276,7 +301,6 @@ int main(void) printf("USB disconnect\n"); i = 10; while (--i) { /* fake USB disconnect for > 250 ms */ - wdt_reset(); led_on(); _delay_ms(35); led_off(); diff --git a/avr/usbload/sram.c b/avr/usbload/sram.c index bec497f..706a7a8 100644 --- a/avr/usbload/sram.c +++ b/avr/usbload/sram.c @@ -1,7 +1,6 @@ #include #include #include -#include #include /* for _delay_ms() */ @@ -97,6 +96,7 @@ void sreg_set(uint32_t addr) } + void sram_bulk_read_start(uint32_t addr) { #ifdef DEBUG_SRAM @@ -105,7 +105,6 @@ void sram_bulk_read_start(uint32_t addr) avr_data_in(); AVR_CS_PORT &= ~(1 << AVR_CS_PIN); - AVR_WR_PORT |= (1 << AVR_WR_PIN); AVR_RD_PORT |= (1 << AVR_RD_PIN); @@ -113,15 +112,7 @@ void sram_bulk_read_start(uint32_t addr) AVR_RD_PORT &= ~(1 << AVR_RD_PIN); asm volatile ("nop"); - asm volatile ("nop"); - asm volatile ("nop"); - asm volatile ("nop"); - asm volatile ("nop"); - asm volatile ("nop"); - asm volatile ("nop"); - asm volatile ("nop"); - -} + } inline void sram_bulk_read_next(void) { @@ -130,24 +121,12 @@ inline void sram_bulk_read_next(void) AVR_RD_PORT &= ~(1 << AVR_RD_PIN); asm volatile ("nop"); - asm volatile ("nop"); - asm volatile ("nop"); - asm volatile ("nop"); - asm volatile ("nop"); - asm volatile ("nop"); - asm volatile ("nop"); - asm volatile ("nop"); - } inline uint8_t sram_bulk_read(void) { - uint8_t byte; - - byte = AVR_DATA_PIN; - AVR_RD_PORT |= (1 << AVR_RD_PIN); - return byte; + return AVR_DATA_PIN; } void sram_bulk_read_end(void) @@ -155,6 +134,7 @@ void sram_bulk_read_end(void) #ifdef DEBUG_SRAM printf("sram_bulk_read_end:"); #endif + AVR_RD_PORT |= (1 << AVR_RD_PIN); AVR_CS_PORT |= (1 << AVR_CS_PIN); avr_data_in(); } @@ -162,7 +142,7 @@ void sram_bulk_read_end(void) uint8_t sram_read(uint32_t addr) { uint8_t byte; -#ifdef DEBUG_SRAM +#ifdef DEBUG_SRAM_RAW printf("sram_read: addr=0x%08lx\n\r", addr); #endif @@ -177,13 +157,6 @@ uint8_t sram_read(uint32_t addr) AVR_RD_PORT &= ~(1 << AVR_RD_PIN); - asm volatile ("nop"); - asm volatile ("nop"); - asm volatile ("nop"); - asm volatile ("nop"); - asm volatile ("nop"); - asm volatile ("nop"); - asm volatile ("nop"); asm volatile ("nop"); byte = AVR_DATA_PIN; @@ -216,17 +189,13 @@ void sram_bulk_write_start(uint32_t addr) inline void sram_bulk_write_next(void) { AVR_RD_PORT |= (1 << AVR_RD_PIN); - counter_up(); - AVR_WR_PORT &= ~(1 << AVR_WR_PIN); } inline void sram_bulk_write( uint8_t data) { AVR_DATA_PORT = data; - - AVR_WR_PORT |= (1 << AVR_WR_PIN); } void sram_bulk_write_end(void) @@ -234,8 +203,8 @@ void sram_bulk_write_end(void) #ifdef DEBUG_SRAM printf("sram_bulk_write_end:"); #endif + AVR_WR_PORT |= (1 << AVR_WR_PIN); AVR_CS_PORT |= (1 << AVR_CS_PIN); - avr_data_in(); } @@ -243,7 +212,7 @@ void sram_bulk_write_end(void) void sram_write(uint32_t addr, uint8_t data) { -#ifdef DEBUG_SRAM +#ifdef DEBUG_SRAM_RAW printf("sram_write: addr=0x%08lx data=%x\n\r", addr, data); #endif diff --git a/avr/usbload/sram.h b/avr/usbload/sram.h index 47d53dd..861e5e6 100644 --- a/avr/usbload/sram.h +++ b/avr/usbload/sram.h @@ -155,7 +155,7 @@ inline void sram_bulk_read_end(void); uint8_t sram_bulk_read(void); void sram_bulk_write_start(uint32_t addr); -inline void sram_bulk_read_next(void); +inline void sram_bulk_write_next(void); inline void sram_bulk_write_end(void); void sram_bulk_write(uint8_t data); diff --git a/avr/usbload/usb_bulk.c b/avr/usbload/usb_bulk.c index cab5eea..ff140c4 100644 --- a/avr/usbload/usb_bulk.c +++ b/avr/usbload/usb_bulk.c @@ -43,9 +43,9 @@ uint8_t usbFunctionWrite(uint8_t * data, uint8_t len) printf("usbFunctionWrite REQ_STATUS_UPLOAD addr: 0x%08lx len: %i rx_remaining=%i\n", req_addr, len, rx_remaining); #endif - cli(); + //cli(); sram_copy(req_addr, data, len); - sei(); + //sei(); req_addr += len; } else if (req_state == REQ_STATUS_BULK_UPLOAD) { diff --git a/scripts/query_romsize.py b/scripts/query_romsize.py index 9dc3e85..0f28308 100644 --- a/scripts/query_romsize.py +++ b/scripts/query_romsize.py @@ -9,15 +9,20 @@ import popen2 import glob import sys import pprint +from subprocess import Popen +path = "/Users/david/Devel/arch/avr/code/snesram/roms/" +def shellquote(s): + return "'" + s.replace("'", "'\\''") + "'" + def main(): conn = sqlite3.connect('roms.sqlite3') c = conn.cursor() for i in [(4,),(8,),(16,),(32,)]: - dirname = "%02i" % i + dirname = os.path.join(path,"%02i" % i) if not os.path.isdir(dirname): os.mkdir(dirname) print "#" * 60 @@ -42,8 +47,13 @@ def main(): for row in c: name,size,filename = row if '[' not in filename: - cmd = 'scp burst:"%s" %s/' % ( filename,dirname) - print cmd + src = "david@burst:%s" % filename + command = ["scp",shellquote(src), dirname] + proc = Popen(command) + print dir(proc) + proc.communicate() + + raise if __name__ == '__main__': main()