From 3326c2fb345a91685cfad8c3aae04ae2106ca81b Mon Sep 17 00:00:00 2001 From: Paul Molloy Date: Tue, 29 Nov 2016 18:27:54 -0600 Subject: [PATCH] payload buffers working with some early testing. Had a good lesson on what static means... :/ everything working now as previously designed speed testing on windows10 PC yeilded ~21KBps when transferring 128-512KB payloads and 128Byte transfer size. Going to bump to 256 and see how that does after 128KB speed tests on linux machine. created host test.c/.h file for general testing of new features. that way I can start working on erase/write.h files and just use test.c as scratch code space for tinkering and still call with -t flag on command line. modified dictionary calls to include pointers to data and lengths. --- firmware/source/buffer.c | 16 +-- firmware/source/buffer.h | 4 +- firmware/source/usb.c | 2 +- host/source/dictionary.c | 20 +++- host/source/dictionary.h | 2 +- host/source/erase.c | 76 -------------- host/source/inlprog.c | 8 +- host/source/test.c | 194 +++++++++++++++++++++++++++++++++++ host/source/test.h | 31 ++++++ host/source/usb_operations.c | 1 + 10 files changed, 261 insertions(+), 93 deletions(-) create mode 100644 host/source/test.c create mode 100644 host/source/test.h diff --git a/firmware/source/buffer.c b/firmware/source/buffer.c index d1eb5d2..45402c0 100644 --- a/firmware/source/buffer.c +++ b/firmware/source/buffer.c @@ -1,12 +1,5 @@ #include "buffer.h" -//max raw buffer size is only limited based on buffer struct -//raw buffer memory to which smaller buffers will be created from -//set pointers and lengths to prevent buffer conflicts -static uint8_t raw_buffer[NUM_RAW_BANKS * RAW_BANK_SIZE]; //8 banks of 32bytes each 256Bytes total - -//buffer status stores allocation status of each raw buffer 32Byte bank -static uint8_t raw_bank_status[NUM_RAW_BANKS]; //min define of two buffers static buffer buff0; @@ -22,6 +15,15 @@ static buffer buff6; static buffer buff7; #endif +//max raw buffer size is only limited based on buffer struct +//raw buffer memory to which smaller buffers will be created from +//set pointers and lengths to prevent buffer conflicts +static uint8_t raw_buffer[NUM_RAW_BANKS * RAW_BANK_SIZE]; //8 banks of 32bytes each 256Bytes total + +//buffer status stores allocation status of each raw buffer 32Byte bank +static uint8_t raw_bank_status[NUM_RAW_BANKS]; + + /* Desc:Bridge between usb.c and buffer.c functions * usb.c calls this function providing setup packet info diff --git a/firmware/source/buffer.h b/firmware/source/buffer.h index 430fd88..465f0d0 100644 --- a/firmware/source/buffer.h +++ b/firmware/source/buffer.h @@ -19,9 +19,9 @@ uint8_t allocate_buffer( buffer *buff, uint8_t new_id, uint8_t base_bank, uint8_ //used to communicate to usbFunctionWrite which buffer object //it should be filling -static buffer *cur_usb_load_buff; +buffer *cur_usb_load_buff; //used to determine number of bytes left to finish current //OUT transfer utilized by usbFunctionWrite -static uint16_t incoming_bytes_remain; +uint16_t incoming_bytes_remain; #endif diff --git a/firmware/source/usb.c b/firmware/source/usb.c index 7a8405a..abd4677 100644 --- a/firmware/source/usb.c +++ b/firmware/source/usb.c @@ -229,7 +229,7 @@ USB_PUBLIC uchar usbFunctionWrite(uchar *data, uchar len) { uint8_t data_cur = 0; //current incoming byte to copy uint8_t buf_cur = cur_usb_load_buff->cur_byte; //current buffer byte uint8_t *buf_data = cur_usb_load_buff->data; //current buffer data array - + //copy 1-8bytes of payload into buffer while ( data_cur < len ) { buf_data[ buf_cur ] = data[data_cur]; diff --git a/host/source/dictionary.c b/host/source/dictionary.c index d38296f..c231dfa 100644 --- a/host/source/dictionary.c +++ b/host/source/dictionary.c @@ -6,6 +6,7 @@ * provide opcode from the dictionary (wValueLSB) * provide 16bit addr used for usb transfer index (optional, can also send 8bits applied to wIndexLSB) * provide miscdata optional to be used for wValueMSB + * provide data buffer pointer and length * * makes call to usb_transfer after determining: * endpoint direction @@ -14,7 +15,7 @@ * debug print of call and return values */ -int dictionary_call( USBtransfer *transfer, uint8_t dictionary, uint8_t opcode, uint16_t addr, uint8_t miscdata) +int dictionary_call( USBtransfer *transfer, uint8_t dictionary, uint8_t opcode, uint16_t addr, uint8_t miscdata, uint8_t endpoint, uint8_t *buffer, uint16_t length) { transfer->request = dictionary; transfer->wValueMSB = miscdata; @@ -23,7 +24,7 @@ int dictionary_call( USBtransfer *transfer, uint8_t dictionary, uint8_t opcode, transfer->wIndexLSB = addr; //default IN for now reading back error codes from short commands - transfer->endpoint = USB_IN; + transfer->endpoint = endpoint; //default length of zero transfer->wLength = 0; @@ -126,7 +127,11 @@ int dictionary_call( USBtransfer *transfer, uint8_t dictionary, uint8_t opcode, break; case BUFF_OPCODE_BUFN_RV_MIN ... BUFF_OPCODE_BUFN_RV_MAX: debug("BUFF_OPCODE_RV"); - //TODO + break; + case BUFF_OPCODE_PAYLOAD_MIN ... BUFF_OPCODE_PAYLOAD_MAX: + debug("BUFF_OPCODE_PAYLOAD"); + transfer->data = (unsigned char *)buffer; + transfer->wLength = length; break; default: //snes opcode min/max definition error sentinel("bad BUFFER opcode min/max err:%d",ERR_BAD_BUFF_OP_MINMAX); @@ -142,6 +147,9 @@ int dictionary_call( USBtransfer *transfer, uint8_t dictionary, uint8_t opcode, int xfr_cnt; xfr_cnt = usb_transfer( transfer ); + + //print transfer details if small xfr + if (xfr_cnt <= 8) { printf(" xf: %d er: %d rv:",xfr_cnt, rbuf[0]); int i ; for (i=1; i0; i--) { + dictionary_call( transfer, BUFFER, BUFF_PAYLOAD0, 0, 0, USB_OUT, load_out, 128); + } + tstop = clock(); + float timediff = ( (float)(tstop-tstart) / CLOCKS_PER_SEC); + printf("total time: %fsec, speed: %fKBps", timediff, (512/timediff)); + //128byte transfers currently clocking in around 21KBps + + +// dictionary_call( transfer, BUFFER, ALLOCATE_BUFFER2, 0x3508, 4); +// dictionary_call( transfer, BUFFER, ALLOCATE_BUFFER3, 0x4A0C, 4); +// dictionary_call( transfer, BUFFER, RAW_BANK_STATUS, 0, 0); +// dictionary_call( transfer, BUFFER, RAW_BANK_STATUS, 1, 0); +// dictionary_call( transfer, BUFFER, RAW_BANK_STATUS, 2, 0); +// dictionary_call( transfer, BUFFER, RAW_BANK_STATUS, 3, 0); +// dictionary_call( transfer, BUFFER, RAW_BANK_STATUS, 4, 0); +// dictionary_call( transfer, BUFFER, RAW_BANK_STATUS, 5, 0); +// dictionary_call( transfer, BUFFER, RAW_BANK_STATUS, 6, 0); +// dictionary_call( transfer, BUFFER, RAW_BANK_STATUS, 7, 0); +// dictionary_call( transfer, BUFFER, RAW_BANK_STATUS, 8, 0); +// dictionary_call( transfer, BUFFER, RAW_BANK_STATUS, 9, 0); +// dictionary_call( transfer, BUFFER, RAW_BANK_STATUS, 10, 0); +// dictionary_call( transfer, BUFFER, RAW_BANK_STATUS, 11, 0); +// dictionary_call( transfer, BUFFER, RAW_BANK_STATUS, 12, 0); +// dictionary_call( transfer, BUFFER, RAW_BANK_STATUS, 13, 0); +// dictionary_call( transfer, BUFFER, RAW_BANK_STATUS, 14, 0); +// dictionary_call( transfer, BUFFER, RAW_BANK_STATUS, 15, 0); + + //dict opcode addr data + //dictionary_call( transfer, BUFFER, RAW_BANK_STATUS, 0, 0); + //dictionary_call( transfer, BUFFER, RAW_BANK_STATUS, 1, 0); + //debug("reset"); + //dictionary_call( transfer, BUFFER, RAW_BUFFER_RESET, 0, 0); + //debug("read status"); + //dictionary_call( transfer, BUFFER, RAW_BANK_STATUS, 0, 0); + //dictionary_call( transfer, BUFFER, RAW_BANK_STATUS, 1, 0); + //debug("allocate 0"); + //dictionary_call( transfer, BUFFER, ALLOCATE_BUFFER0, 0x1A00, 1); + //dictionary_call( transfer, BUFFER, ALLOCATE_BUFFER1, 0x2A01, 1); + //dictionary_call( transfer, BUFFER, ALLOCATE_BUFFER2, 0x3A02, 1); + //dictionary_call( transfer, BUFFER, ALLOCATE_BUFFER3, 0x4A03, 1); + //dictionary_call( transfer, BUFFER, ALLOCATE_BUFFER4, 0x5A04, 1); + //dictionary_call( transfer, BUFFER, ALLOCATE_BUFFER5, 0x6A05, 1); + //dictionary_call( transfer, BUFFER, ALLOCATE_BUFFER6, 0x7A06, 1); + //dictionary_call( transfer, BUFFER, ALLOCATE_BUFFER7, 0x8A07, 1); + //debug("read status"); + //dictionary_call( transfer, BUFFER, RAW_BANK_STATUS, 0, 0); + //dictionary_call( transfer, BUFFER, RAW_BANK_STATUS, 1, 0); + //dictionary_call( transfer, BUFFER, RAW_BANK_STATUS, 2, 0); + //dictionary_call( transfer, BUFFER, RAW_BANK_STATUS, 3, 0); + //dictionary_call( transfer, BUFFER, RAW_BANK_STATUS, 4, 0); + //dictionary_call( transfer, BUFFER, RAW_BANK_STATUS, 5, 0); + //dictionary_call( transfer, BUFFER, RAW_BANK_STATUS, 6, 0); + //dictionary_call( transfer, BUFFER, RAW_BANK_STATUS, 7, 0); + + //dictionary_call( transfer, BUFFER, ALLOCATE_BUFFER7, 0x8A07, 1); + //debug("reset"); + //dictionary_call( transfer, BUFFER, RAW_BUFFER_RESET, 0, 0); + //dictionary_call( transfer, BUFFER, RAW_BANK_STATUS, 7, 0); + //dictionary_call( transfer, BUFFER, ALLOCATE_BUFFER7, 0x8A07, 1); + //dictionary_call( transfer, BUFFER, RAW_BANK_STATUS, 7, 0); + //dictionary_call( transfer, BUFFER, ALLOCATE_BUFFER7, 0x5A05, 1); + + + //dictionary_call( transfer, IO, IO_RESET, 0, 0); + //dictionary_call( transfer, IO, NES_INIT, 0, 0); + //dictionary_call( transfer, IO, EXP0_PULLUP_TEST, 0, 0); + //dictionary_call( transfer, PINPORT, AUX_RD, 0, 0); + //dictionary_call( transfer, PINPORT, AUX_RD, 0, 0); + //dictionary_call( transfer, PINPORT, AUX_RD, 0, 0); + //dictionary_call( transfer, PINPORT, AUX_RD, 0, 0); + //dictionary_call( transfer, PINPORT, AUX_RD, 0, 0); + //dictionary_call( transfer, PINPORT, AUX_RD, 0, 0); + //dictionary_call( transfer, PINPORT, AUX_RD, 0, 0); + +////software mode +// dictionary_call( transfer, NES, DISCRETE_EXP0_PRGROM_WR, 0x5555, 0xAA); +// dictionary_call( transfer, NES, DISCRETE_EXP0_PRGROM_WR, 0x2AAA, 0x55); +// dictionary_call( transfer, NES, DISCRETE_EXP0_PRGROM_WR, 0x5555, 0x90); +// dictionary_call( transfer, NES, NES_CPU_RD, 0x8000, 0); +// dictionary_call( transfer, NES, NES_CPU_RD, 0x8001, 0); +// dictionary_call( transfer, NES, NES_CPU_RD, 0x8000, 0); +// dictionary_call( transfer, NES, NES_CPU_RD, 0x8001, 0); +////exit software +// dictionary_call( transfer, NES, DISCRETE_EXP0_PRGROM_WR, 0x8000, 0xF0); +// dictionary_call( transfer, NES, NES_CPU_RD, 0x8000, 0); +// dictionary_call( transfer, NES, NES_CPU_RD, 0x8001, 0); + +//erase +// dictionary_call( transfer, NES, DISCRETE_EXP0_PRGROM_WR, 0x5555, 0xAA); +// dictionary_call( transfer, NES, DISCRETE_EXP0_PRGROM_WR, 0x2AAA, 0x55); +// dictionary_call( transfer, NES, DISCRETE_EXP0_PRGROM_WR, 0x5555, 0x80); +// dictionary_call( transfer, NES, DISCRETE_EXP0_PRGROM_WR, 0x5555, 0xAA); +// dictionary_call( transfer, NES, DISCRETE_EXP0_PRGROM_WR, 0x2AAA, 0x55); +// dictionary_call( transfer, NES, DISCRETE_EXP0_PRGROM_WR, 0x5555, 0x10); +// dictionary_call( transfer, NES, NES_CPU_RD, 0x8000, 0); +// dictionary_call( transfer, NES, NES_CPU_RD, 0x8000, 0); +// dictionary_call( transfer, NES, NES_CPU_RD, 0x8000, 0); +// dictionary_call( transfer, NES, NES_CPU_RD, 0x8000, 0); +// dictionary_call( transfer, NES, NES_CPU_RD, 0x8000, 0); +// dictionary_call( transfer, NES, NES_CPU_RD, 0x8000, 0); +// dictionary_call( transfer, NES, NES_CPU_RD, 0x8000, 0); +// dictionary_call( transfer, NES, NES_CPU_RD, 0x8000, 0); +// dictionary_call( transfer, NES, NES_CPU_RD, 0x8000, 0); +// dictionary_call( transfer, NES, NES_CPU_RD, 0x8000, 0); +// dictionary_call( transfer, NES, NES_CPU_RD, 0x8000, 0); +// dictionary_call( transfer, NES, NES_CPU_RD, 0x8000, 0); +// dictionary_call( transfer, NES, NES_CPU_RD, 0x8000, 0); +// dictionary_call( transfer, NES, NES_CPU_RD, 0x8000, 0); +// dictionary_call( transfer, NES, NES_CPU_RD, 0x8000, 0); +// dictionary_call( transfer, NES, NES_CPU_RD, 0x8000, 0); +// dictionary_call( transfer, NES, NES_CPU_RD, 0x8000, 0); +// dictionary_call( transfer, NES, NES_CPU_RD, 0x8000, 0); +// dictionary_call( transfer, NES, NES_CPU_RD, 0x8000, 0); +// dictionary_call( transfer, NES, NES_CPU_RD, 0x8000, 0); + +//program byte +// dictionary_call( transfer, NES, DISCRETE_EXP0_PRGROM_WR, 0x5555, 0xAA); +// dictionary_call( transfer, NES, DISCRETE_EXP0_PRGROM_WR, 0x2AAA, 0x55); +// dictionary_call( transfer, NES, DISCRETE_EXP0_PRGROM_WR, 0x5555, 0xA0); +// dictionary_call( transfer, NES, DISCRETE_EXP0_PRGROM_WR, 0x8000, 0x00); +// dictionary_call( transfer, NES, NES_CPU_RD, 0x8000, 0); +// dictionary_call( transfer, NES, NES_CPU_RD, 0x8000, 0); + + return 0; + +} diff --git a/host/source/test.h b/host/source/test.h new file mode 100644 index 0000000..8d0ef20 --- /dev/null +++ b/host/source/test.h @@ -0,0 +1,31 @@ +#ifndef _test_h +#define _test_h + +#include +#include +#include +#include +#include +#include +#include + +//include prior to other file includes +//that way DEBUG can be turned on/off for this file alone +//uncomment to DEBUG this file alone +#define DEBUG +//"make debug" to get DEBUG msgs on entire program +#include "dbg.h" + +#include "usb_operations.h" +#include "shared_errors.h" +#include "shared_dictionaries.h" +#include "dictionary.h" + +//uncomment to DEBUG this file alone +#define DEBUG +//"make debug" to get DEBUG msgs on entire program +#include "dbg.h" + +int test_function( USBtransfer *transfer ); + +#endif diff --git a/host/source/usb_operations.c b/host/source/usb_operations.c index b31376f..568a931 100644 --- a/host/source/usb_operations.c +++ b/host/source/usb_operations.c @@ -253,6 +253,7 @@ int usb_transfer( USBtransfer *transfer ) wIndex = wIndex << 8; wIndex |= transfer->wIndexLSB; + debug("reqtype h: %x \n", ( LIBUSB_REQUEST_TYPE_VENDOR | LIBUSB_RECIPIENT_DEVICE | transfer->endpoint)); debug("request h: %x d: %d", transfer->request, transfer->request); debug("wValueMSB h: %x d: %d", transfer->wValueMSB, transfer->wValueMSB); debug("wValueLSB h: %x d: %d", transfer->wValueLSB, transfer->wValueLSB);