Resolved issue where final buffer wasn't getting fully flashed.

Added check to ensure buff1 is done before quitting and resetting buffers.
Currently have a hacked load_oper_info_elements_chr function to test
CHR-ROM flashing.
NROM PRG & CHR flashing and dumping tested and working on black ASUS
win10 machine.
Firmware still doesn't implement previously added feature for oper_info
rd/wr_func pointer.  flash/dump.c simply overrides by providing the
function pointer based on memory type.

A bit frustrated with how complicated everything is currently...
Feel like there's a lack of standard for function definition and calls.
Would like majority of host program flow to be determined solely by
script calls.  Firmware is getting more generic and versatile at the cost
of being SLOW!!!  Perhaps that's okay though as it's not terribly slow in
comparision to comparable AVR kazzo firmware builds.  And with current
target to migrate to STM32 device this generic setup is much cleaner and
easier to work with.  However complexity was added to the firmware code in
order to help make it faster.  Not sure the goal of faster should take
priority over speed.  Obsessing over speed will cause issues with race
conditions, and complicate code to the point where I won't reach my goal.

With the long break since I've been working on this project it's making me
more willing to scrap some previous work for a cleaner solution more
aligned with my end goal.  I had to write some of this code to get a
better idea of my what my end goal will look like anyway.  Going to make a
couple builds for UIROM, and action53 as they're urgently needed.  But
beyond that I need to start working on script features, and STM32 support!
This commit is contained in:
Paul Molloy 2017-06-04 20:13:58 -05:00
parent c25e9e7b39
commit a8124e8983
7 changed files with 140 additions and 39 deletions

View File

@ -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:

Binary file not shown.

View File

@ -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:

View File

@ -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

View File

@ -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 );

View File

@ -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:

View File

@ -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 );