From 748c474ddba2e3932d2e9b43f88e7343bbf6f5f1 Mon Sep 17 00:00:00 2001 From: Paul Molloy Date: Mon, 20 Feb 2017 01:45:22 -0600 Subject: [PATCH] Flashing operations working, cleaning up a few items. usb_Func_write updates buffer status if bytes remaining is zero. Not the best solution as a buffer could be over/under run, define MAKECHECKS to have buffer mark itself if full. This method is faster and we always have transfer sizes match buffer sizes anyway. --- firmware/source/usb.c | 6 +++++- host/source/flash.c | 34 +++++++--------------------------- host/source/test.c | 19 ++++++++++--------- 3 files changed, 22 insertions(+), 37 deletions(-) diff --git a/firmware/source/usb.c b/firmware/source/usb.c index 512cc91..5f47ee9 100644 --- a/firmware/source/usb.c +++ b/firmware/source/usb.c @@ -303,12 +303,15 @@ USB_PUBLIC uchar usbFunctionWrite(uchar *data, uchar len) { data_cur++; } +#ifdef MAKECHECKS //need to account for the fact that cur_byte will roll over being 8bit value if ( cur_usb_load_buff->last_idx == (cur_usb_load_buff->cur_byte + len - 1) ) { //this signals to buffer.c so it can update cur_usb_load_buf //and start tasking this buffer to programming cur_usb_load_buff->status = USB_FULL; } +#endif + //update counters and status cur_usb_load_buff->cur_byte += len; @@ -320,7 +323,8 @@ USB_PUBLIC uchar usbFunctionWrite(uchar *data, uchar len) { if ( incoming_bytes_remain == 0 ) { //done with OUT transfer - // cur_usb_load_buff->status = USB_FULL; + //alternate to MAKECHECKS should be faster but require transfer sizes to match buffer size + cur_usb_load_buff->status = USB_FULL; return PAYLD_DONE; } else { //more data packets remain to complete OUT transfer return NOT_DONE; diff --git a/host/source/flash.c b/host/source/flash.c index 8a99efd..c5ee222 100644 --- a/host/source/flash.c +++ b/host/source/flash.c @@ -129,7 +129,7 @@ int flash_cart( USBtransfer* transfer, rom_image *rom, cartridge *cart ) for( i=0; i<(32*KByte/buff_size); i++) { //for( i=0; i<8; i++) { - debug("\n\npayload out #%d", i); + //debug("\n\npayload out #%d", i); //get_operation( transfer ); //get_buff_elements( transfer, buff0 ); //get_buff_elements( transfer, buff1 ); @@ -146,10 +146,9 @@ int flash_cart( USBtransfer* transfer, rom_image *rom, cartridge *cart ) //ensure cur_buff is EMPTY prior to sending data check(! get_cur_buff_status( transfer, &cur_buff_status ), "Error retrieving cur_buff->status"); while (cur_buff_status != EMPTY ) { - debug("cur_buff->status: %x ", cur_buff_status); + //debug("cur_buff->status: %x ", cur_buff_status); check(! get_cur_buff_status( transfer, &cur_buff_status ), "Error retrieving cur_buff->status"); } - debug("cur_buff->status: %x\n", cur_buff_status); //send data check(! payload_out( transfer, data, buff_size ), "Error with payload OUT"); @@ -158,41 +157,21 @@ int flash_cart( USBtransfer* transfer, rom_image *rom, cartridge *cart ) } check(! get_cur_buff_status( transfer, &cur_buff_status ), "Error retrieving cur_buff->status"); debug("\n\n\ncur_buff->status: %x\n", cur_buff_status); + //TODO add check to ensure both buffers are done and operation is okay + //currently just make a few extra get elements calls to waste time get_operation( transfer ); get_buff_elements( transfer, buff0 ); get_buff_elements( transfer, buff1 ); - get_buff_elements( transfer, buff0 ); - get_buff_elements( transfer, buff1 ); - get_buff_elements( transfer, buff0 ); - get_buff_elements( transfer, buff1 ); get_operation( transfer ); debug("payload done"); //end operation at reset - //check(! set_operation( transfer, RESET ), "Unable to set buffer operation"); - - -/* - //for( i=0; i<(512*KByte/buff_size); i++) { - for( i=0; i<(32*KByte/buff_size); i++) { - //for( i=0; i<(8*KByte/buff_size); i++) { - check(! read_from_file( rom, data, buff_size ), "Error with file read"); - check(! payload_out( transfer, data, buff_size ), "Error with payload OUT"); - //if ( i % 256 == 0 ) debug("payload in #%d", i); - if ( i % 32 == 0 ) debug("payload out #%d", i); - } - debug("payload done"); - //need to delay further USB commands until last buffer is flashed - //TODO spin while buff1 status == FLASHING - //currently this takes about as long as two get elements - get_buff_elements( transfer, buff1 ); - get_buff_elements( transfer, buff1 ); - get_buff_elements( transfer, buff1 ); + check(! set_operation( transfer, RESET ), "Unable to set buffer operation"); tstop = clock(); float timediff = ( (float)(tstop-tstart) / CLOCKS_PER_SEC); - printf("total time: %fsec, speed: %fKBps\n", timediff, (512/timediff)); + printf("total time: %fsec, speed: %fKBps\n", timediff, (32/timediff)); //TODO flush file from time to time..? @@ -200,6 +179,7 @@ int flash_cart( USBtransfer* transfer, rom_image *rom, cartridge *cart ) // or not..? just reset buffers and start next memory or quit //reset buffers and setup to dump CHR-ROM +/* check(! reset_buffers( transfer ), "Unable to reset device buffers"); check(! allocate_buffers( transfer, num_buffers, buff_size ), "Unable to allocate buffers"); check(! set_mem_n_part( transfer, buff0, CHRROM, SST_MANF_ID ), "Unable to set mem_type and part"); diff --git a/host/source/test.c b/host/source/test.c index fc20fa8..0566ebc 100644 --- a/host/source/test.c +++ b/host/source/test.c @@ -30,7 +30,6 @@ int test_function( cartridge *cart, USBtransfer *transfer ) dictionary_call( transfer, DICT_PINPORT, ROMSEL_HI, 0, 0, USB_IN, NULL, 1); */ -/* //spansion/cypress A18-11 are don't care, that translates to A19-12 for byte mode I think //$AAA / AA dictionary_call( transfer, DICT_NES, NES_CPU_WR, 0x8AAA, 0xAA, @@ -41,22 +40,24 @@ int test_function( cartridge *cart, USBtransfer *transfer ) //$AAA / 90 manf ID dictionary_call( transfer, DICT_NES, NES_CPU_WR, 0x8AAA, 0x90, USB_IN, NULL, 1); -*/ + + dictionary_call_debug( transfer, DICT_NES, EMULATE_NES_CPU_RD, 0x8000, 0, + USB_IN, NULL, 2); + dictionary_call_debug( transfer, DICT_NES, EMULATE_NES_CPU_RD, 0x8002, 0, + USB_IN, NULL, 2); + + /* dictionary_call_debug( transfer, DICT_NES, NES_PPU_RD, 0x0000, 0, USB_IN, NULL, 2); dictionary_call_debug( transfer, DICT_NES, NES_PPU_RD, 0x0055, 0, USB_IN, NULL, 2); dictionary_call_debug( transfer, DICT_NES, NES_PPU_RD, 0x00AA, 0, USB_IN, NULL, 2); - - dictionary_call_debug( transfer, DICT_NES, EMULATE_NES_CPU_RD, 0x8000, 0, - USB_IN, NULL, 2); - dictionary_call_debug( transfer, DICT_NES, EMULATE_NES_CPU_RD, 0x8002, 0, - USB_IN, NULL, 2); + */ //RESET write F0 anywhere -// dictionary_call( transfer, DICT_NES, NES_CPU_WR, 0x8000, 0xF0, -// USB_IN, NULL, 1); + dictionary_call( transfer, DICT_NES, NES_CPU_WR, 0x8000, 0xF0, + USB_IN, NULL, 1); dictionary_call_debug( transfer, DICT_NES, EMULATE_NES_CPU_RD, 0x8000, 0, USB_IN, NULL, 2);