diff --git a/firmware/Makefile b/firmware/Makefile index 20e7acc..c61aa50 100644 --- a/firmware/Makefile +++ b/firmware/Makefile @@ -61,8 +61,8 @@ main.elf: shared $(OBJECTS) main.hex: main.elf rm -f main.hex main.eep.hex avr-objcopy -j .text -j .data -O ihex main.elf main.hex - avr-size -C --mcu=${DEVICE} main.elf -# avr-size main.hex +# avr-size -C --mcu=${DEVICE} main.elf + avr-size main.elf # debugging targets: diff --git a/host/inlretro_commited.exe b/host/inlretro_commited.exe index cddc5cd..979b8f8 100644 Binary files a/host/inlretro_commited.exe and b/host/inlretro_commited.exe differ diff --git a/host/source/buffer.c b/host/source/buffer.c index 849c98a..c08eafd 100644 --- a/host/source/buffer.c +++ b/host/source/buffer.c @@ -214,6 +214,24 @@ int get_buff_elements( USBtransfer *transfer, int buff_num ) return SUCCESS; } +/* Desc:Get buffer element and return value + * Pre: buffers are allocated + * Post: sets value to requested value + * Rtn: SUCCESS if no errors + */ +int get_buff_element_value( USBtransfer *transfer, int buff_num, int pri_sec, int element_num, int *value ) +{ + int rv; + uint8_t data[8]; + + rv = dictionary_call( transfer, DICT_BUFFER, pri_sec, NILL, buff_num, + USB_IN, data, 8); + + *value = data[element_num]; + + return rv; +} + ///* Desc:Get buffer opertationt // * Pre: // * Post: diff --git a/host/source/buffer.h b/host/source/buffer.h index ed4272e..a4b273c 100644 --- a/host/source/buffer.h +++ b/host/source/buffer.h @@ -29,5 +29,6 @@ int set_map_n_mapvar( USBtransfer *transfer, int buff_num, int mapper, int map_v int payload_in( USBtransfer *transfer, uint8_t *data, int length ); int payload_out( USBtransfer *transfer, uint8_t *data, int length ); int get_buff_elements( USBtransfer *transfer, int buff_num ); +int get_buff_element_value( USBtransfer *transfer, int buff_num, int pri_sec, int element_num, int *value ); #endif diff --git a/host/source/flash.c b/host/source/flash.c index c5ee222..1aff228 100644 --- a/host/source/flash.c +++ b/host/source/flash.c @@ -101,26 +101,6 @@ int flash_cart( USBtransfer* transfer, rom_image *rom, cartridge *cart ) // //once the next payload request happens manager knows last buffer can start dumping again // //buffer updates it's elements and goes off to dump next page // -// debug("first payload"); -// check(! read_from_file( rom, data, buff_size ), "Error with file read"); -// //check(! payload_out( transfer, data, buff_size ), "Error with payload OUT"); -// payload_out( transfer, data, buff_size ); -// get_operation( transfer ); -// get_buff_elements( transfer, buff0 ); -// get_buff_elements( transfer, buff1 ); -// -// debug("first payload done"); -//// get_operation( transfer ); -//// get_buff_elements( transfer, buff0 ); -//// get_buff_elements( transfer, buff1 ); -//// -// debug("second payload"); -// check(! read_from_file( rom, data, buff_size ), "Error with file read"); -// check(! payload_out( transfer, data, buff_size ), "Error with payload OUT"); - -// get_operation( transfer ); -// get_buff_elements( transfer, buff0 ); -// get_buff_elements( transfer, buff1 ); clock_t tstart, tstop; tstart = clock(); @@ -128,13 +108,6 @@ int flash_cart( USBtransfer* transfer, rom_image *rom, cartridge *cart ) //now just need to call series of payload IN transfers to retrieve data for( i=0; i<(32*KByte/buff_size); i++) { - //for( i=0; i<8; i++) { - //debug("\n\npayload out #%d", i); - //get_operation( transfer ); - //get_buff_elements( transfer, buff0 ); - //get_buff_elements( transfer, buff1 ); - //get_buff_elements( transfer, buff0 ); - //get_buff_elements( transfer, buff1 ); //The device doesn't have a good way to respond if the last buffer is flashing //and the current one is full. We can only send a payload if the current buffer @@ -156,14 +129,16 @@ int flash_cart( USBtransfer* transfer, rom_image *rom, cartridge *cart ) if ( i % 32 == 0 ) debug("payload out #%d", i); } 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 + //debug("\n\n\ncur_buff->status: %x\n", cur_buff_status); + + //add check to ensure both buffers are done and operation is okay + //need to get status of buff1 and make sure it's flashed + while (cur_buff_status != FLASHED ) { + check(! get_buff_element_value( transfer, buff1, GET_PRI_ELEMENTS, BUFF_STATUS, &cur_buff_status ), + "Error retrieving buffer status post flashing"); + // debug("\n\n\ncur_buff->status: %x\n", cur_buff_status); + } - get_operation( transfer ); - get_buff_elements( transfer, buff0 ); - get_buff_elements( transfer, buff1 ); - get_operation( transfer ); debug("payload done"); //end operation at reset @@ -178,8 +153,11 @@ int flash_cart( USBtransfer* transfer, rom_image *rom, cartridge *cart ) //tell buffer manager when to stop // or not..? just reset buffers and start next memory or quit //reset buffers and setup to dump CHR-ROM + + //load operation elements into buff0 and then copy buff0 to oper_info + load_oper_info_elements_chr( transfer, cart ); + get_oper_info_elements( transfer ); -/* 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"); @@ -191,16 +169,44 @@ int flash_cart( USBtransfer* transfer, rom_image *rom, cartridge *cart ) //inform buffer manager to start dumping operation now that buffers are initialized check(! set_operation( transfer, STARTFLASH ), "Unable to set buffer operation"); + + tstart = clock(); + + //now just need to call series of payload IN transfers to retrieve data + for( i=0; i<(8*KByte/buff_size); i++) { + + //Read next chunk from file check(! read_from_file( rom, data, buff_size ), "Error with file read"); + + //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); + check(! get_cur_buff_status( transfer, &cur_buff_status ), "Error retrieving cur_buff->status"); + } + + //send data 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"); -*/ + 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); + + //check to ensure both buffers are done and operation is okay before resetting + //need to get status of buff1 and make sure it's flashed + while (cur_buff_status != FLASHED ) { + check(! get_buff_element_value( transfer, buff1, GET_PRI_ELEMENTS, BUFF_STATUS, &cur_buff_status ), + "Error retrieving buffer status post flashing"); + // debug("\n\n\ncur_buff->status: %x\n", cur_buff_status); + } + debug("payload done"); //close file in main + + //end operation at reset + check(! set_operation( transfer, RESET ), "Unable to set buffer operation"); //reset io at end io_reset( transfer ); diff --git a/host/source/operation.c b/host/source/operation.c index d9317bc..97fd143 100644 --- a/host/source/operation.c +++ b/host/source/operation.c @@ -75,6 +75,81 @@ error: return ~SUCCESS; } +/* Desc:Set all oper_info elements based on cartridge + * Pre: buff0 must be initialized + * Post:oper_info elements loaded + * Rtn: SUCCESS if no errors + */ +int load_oper_info_elements_chr( USBtransfer *transfer, cartridge *cart ) +{ + uint8_t rv[RETURN_BUFF_SIZE]; + uint8_t buff_num = 0; //buffer used to load elements according to shared_dict_operation.h + uint8_t oper_info[OPER_DATA_NUM_BYTE_ELEMENTS]; +// int i; + + //first make sure buff0 is big enough + dictionary_call_debug( transfer, DICT_BUFFER, GET_PRI_ELEMENTS, NILL, buff_num, + USB_IN, rv, RETURN_BUFF_SIZE); + check( rv[BUFF_LASTIDX] >= OPER_DATA_NUM_BYTE_ELEMENTS, + "buff0 not large enough to load oper_info. Only %d available, need %d", + rv[BUFF_LASTIDX], OPER_DATA_NUM_BYTE_ELEMENTS ); + + //fill array with oper_info elements then payload to buff0 + //overall type of operation being performed + oper_info[OPERATION] = PREPARING, + //mask page_num lower byte to get directly addressable A15:A8 bits + oper_info[ADDRH_DMASK] = MSK_8KB, + //shift page_num to right this many bits to get cur bank value + oper_info[PG2BANK_SHRIGHT] = PG2B_8KB, + //most significant bit that must be valid for operation (ie A14 SST) + oper_info[VALID_ADDR_MSB] = 12, + //unlock sequence SST $5555 0xAA + //unlock sequence #1 bank number for mapper reg + oper_info[UNLOCK1_BANK] = 0, + //unlock sequence #1 A15:A8 + oper_info[UNLOCK1_AH] = 0x15, + //unlock sequence #1 A7:A0 + oper_info[UNLOCK1_AL] = 0x55, + //unlock sequence #1 D7:D0 + oper_info[UNLOCK1_DATA] = 0xAA, + ////unlock sequence SST $2AAA 0x55 + //unlock sequence #1 bank number for mapper reg + oper_info[UNLOCK2_BANK] = 0, + //unlock sequence #2 A15:A8 + oper_info[UNLOCK2_AH] = 0x0A, + //unlock sequence #2 A7:A0 + oper_info[UNLOCK2_AL] = 0xAA, + //unlock sequence #2 D7:D0 + oper_info[UNLOCK2_DATA] = 0x55, + //command SST byte write $5555 0xA0, SST sector/chip erase $5555 0x80 + //flash command bank (ie bank to write byte write, sector erase cmd) + oper_info[COMMAND_BANK] = 0, + //flash command A15:A8 + oper_info[COMMAND_AH] = 0x15, + //flash command A7:A0 + oper_info[COMMAND_AL] = 0x55, + ///flash command D7:D0 command 1 data (ie SST sect erase 0x80) + oper_info[COMMAND1_DATA]= 0xA0, + //flash command D7:D0 command 2 data (ie SST sect erase 0x30) + oper_info[COMMAND2_DATA]= 0, + //actual byte operation (ie Byte address bank and addr) + //current bank value for actual operation to be done (ie write byte) + oper_info[OPER_BANK] = 0, + //operation A15:A8 (ie actual byte write address) + oper_info[OPER_AH] = 0, + + //load byte element data into buff0 + dictionary_call( transfer, DICT_BUFFER, BUFF_PAYLOADN, + NILL, buff_num, USB_OUT, + oper_info, OPER_DATA_NUM_BYTE_ELEMENTS); + //now that elements are in buff0 instruct them to be copied over + dictionary_call_debug( transfer, DICT_OPER, COPY_BUFF0_TO_ELEMENTS, + NILL, NILL, USB_IN, NULL, RV_ERR_IDX+1); + +error: + return ~SUCCESS; +} + /* Desc:Get all oper_info elements * Pre: buff0 must be initialized * Post: diff --git a/host/source/operation.h b/host/source/operation.h index 635cbfd..75ce9c8 100644 --- a/host/source/operation.h +++ b/host/source/operation.h @@ -22,6 +22,7 @@ #include "pindef.h" int load_oper_info_elements( USBtransfer *transfer, cartridge *cart ); +int load_oper_info_elements_chr( USBtransfer *transfer, cartridge *cart ); int get_oper_info_elements( USBtransfer *transfer ); int set_operation( USBtransfer *transfer, int operation ); int get_operation( USBtransfer *transfer );