From 94ea3fd474e053af7da17e7d9e1c8b73a6da0fd9 Mon Sep 17 00:00:00 2001 From: paul eeepc Date: Sat, 26 Nov 2016 14:17:34 -0600 Subject: [PATCH] modified: host/source/inlprog.c new file: host/source/erase.c new file: host/source/erase.h creating erase files called from main with e_flag modified: firmware/source/usb.c introducing switch statement with range of values of opcode type detection. modified: host/source/usb_operations.h turning off debug modified: shared/shared_errors.h renumbering some error codes thinking I'll have codes which can come from avr set to 128+ --- firmware/source/usb.c | 43 +++++++++++++-------------- host/source/erase.c | 57 ++++++++++++++++++++++++++++++++++++ host/source/erase.h | 29 ++++++++++++++++++ host/source/inlprog.c | 28 ++++++++++-------- host/source/usb_operations.h | 2 +- shared/shared_errors.h | 5 +++- 6 files changed, 128 insertions(+), 36 deletions(-) create mode 100644 host/source/erase.c create mode 100644 host/source/erase.h diff --git a/firmware/source/usb.c b/firmware/source/usb.c index 6eb2373..e52eb35 100644 --- a/firmware/source/usb.c +++ b/firmware/source/usb.c @@ -84,29 +84,28 @@ USB_PUBLIC usbMsgLen_t usbFunctionSetup(uchar data[8]) { switch(spacket->bRequest) { case PINPORT: - if((spacket->opcode > PP_OPCODE_ONLY_MIN) - & (spacket->opcode < PP_OPCODE_ONLY_MAX)) { - rv[0] = pinport_opcode_only( spacket->opcode ); - - } else if ((spacket->opcode > PP_OPCODE_8BOP_MIN) - & (spacket->opcode < PP_OPCODE_8BOP_MAX)) { - rv[0] = pinport_opcode_8b_operand( spacket->opcode, spacket->wIndexLSB ); - - } else if ((spacket->opcode > PP_OPCODE_16BOP_MIN) - & (spacket->opcode < PP_OPCODE_16BOP_MAX)) { - rv[0] = pinport_opcode_16b_operand( spacket->opcode, - spacket->wIndexMSB, spacket->wIndexLSB ); - - } else if ((spacket->opcode > PP_OPCODE_24BOP_MIN) - & (spacket->opcode < PP_OPCODE_24BOP_MAX)) { - rv[0] = pinport_opcode_24b_operand( spacket->opcode, + switch (spacket->opcode) { + case PP_OPCODE_ONLY_MIN ... PP_OPCODE_ONLY_MAX: + rv[0] = pinport_opcode_only( spacket->opcode ); + break; + case PP_OPCODE_8BOP_MIN ... PP_OPCODE_8BOP_MAX: + rv[0] = pinport_opcode_8b_operand( + spacket->opcode, spacket->wIndexLSB ); + break; + case PP_OPCODE_16BOP_MIN ... PP_OPCODE_16BOP_MAX: + rv[0] = pinport_opcode_16b_operand( + spacket->opcode, spacket->wIndexMSB, spacket->wIndexLSB ); + break; + case PP_OPCODE_24BOP_MIN ... PP_OPCODE_24BOP_MAX: + rv[0] = pinport_opcode_24b_operand( spacket->opcode, spacket->wValueMSB, spacket->wIndexMSB, spacket->wIndexLSB ); - - } else if ((spacket->opcode > PP_OPCODE_8BRV_MIN) - & (spacket->opcode < PP_OPCODE_8BRV_MAX)) { - rv[0] = pinport_opcode_8b_return( spacket->opcode, &rv[1]); - //return error code plus opcode return value - rlen ++; + break; + case PP_OPCODE_8BRV_MIN ... PP_OPCODE_8BRV_MAX: + rv[0] = pinport_opcode_8b_return( spacket->opcode, &rv[1]); + rlen ++; + break; + default: //pinport opcode min/max definition error + rv[0] = ERR_BAD_PP_OP_MINMAX; } break; //end of PINPORT default: diff --git a/host/source/erase.c b/host/source/erase.c new file mode 100644 index 0000000..cc3c3d4 --- /dev/null +++ b/host/source/erase.c @@ -0,0 +1,57 @@ +#include "erase.h" + +int erase_nes( USBtransfer *transfer ) +{ + + debug("erasing"); + + int xfr_cnt; + uint8_t rbuf[2]; + rbuf[0] = 0; + rbuf[1] = 0; + int i; + + transfer->endpoint = USB_IN; + transfer->request = PINPORT; + transfer->data = rbuf; + + uint8_t c[20]; + uint8_t o[20]; + + c[0] = LED_ON; + c[1] = ADDR_OP; + c[2] = DATA_IP; + c[3] = M2_OP; + c[4] = ROMSEL_OP; + c[5] = PRGRW_OP; + c[6] = CSRD_OP; + c[7] = CSWR_OP; + c[8] = AHL_OP; + c[9] = AXLOE_OP; + c[10] = AXL_CLK; + c[11] = ADDR_RD; + c[12] = ADDR_LO; + c[13] = ADDR_RD; + c[14] = LED_OFF; + c[15] = LED_OFF; + c[16] = LED_OFF; + c[17] = LED_OFF; + c[18] = LED_OFF; + c[19] = LED_OFF; + + for ( i = 0; i < 20; i++) { + transfer->wValueLSB = c[i]; + if (c[i] >= 0xc0) transfer->wLength = 2; + else transfer->wLength = 1; + xfr_cnt = usb_transfer( transfer ); + debug("xf: %d OP: %d/%x er: %d rv: %x",xfr_cnt, c[i], c[i], rbuf[0], rbuf[1]); + rbuf[0] = 0xAA; + rbuf[1] = 0; + + //send command + } + + + return 0; + +} diff --git a/host/source/erase.h b/host/source/erase.h new file mode 100644 index 0000000..1d890b1 --- /dev/null +++ b/host/source/erase.h @@ -0,0 +1,29 @@ +#ifndef _erase_h +#define _erase_h + +#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" + +//uncomment to DEBUG this file alone +#define DEBUG +//"make debug" to get DEBUG msgs on entire program +#include "dbg.h" + +int erase_nes( USBtransfer *transfer ); + +#endif diff --git a/host/source/inlprog.c b/host/source/inlprog.c index 2cc4d31..f396751 100644 --- a/host/source/inlprog.c +++ b/host/source/inlprog.c @@ -14,6 +14,7 @@ #include "usb_operations.h" #include "write_operations.h" +#include "erase.h" #include "shared_dictionaries.h" @@ -101,15 +102,17 @@ int main(int argc, char *argv[]) uint8_t rbuf[8]; int i; - printf("before return buffer: "); - for (i = 0; i < 8; i++) { - rbuf[i] = 7; - printf("%x ", rbuf[i]); - } - printf("\n"); + + if (e_flag) erase_nes( transfer ); //handle simple LED ON/OFF within main for now if (o_flag | f_flag) { + printf("before return buffer: "); + for (i = 0; i < 8; i++) { + rbuf[i] = 7; + printf("%x ", rbuf[i]); + } + printf("\n"); transfer->endpoint = USB_IN; transfer->request = PINPORT; if (o_flag) transfer->wValueLSB = LED_ON; @@ -119,14 +122,15 @@ int main(int argc, char *argv[]) //send command xfr_cnt = usb_transfer( transfer ); + + printf("total bytes xfrd: %d \n", xfr_cnt); + printf("after buffer: "); + for (i = 0; i < 8; i++) { + printf("%x ", rbuf[i]); + } + printf("\n"); } - printf("total bytes xfrd: %d \n", xfr_cnt); - printf("after buffer: "); - for (i = 0; i < 8; i++) { - printf("%x ", rbuf[i]); - } - printf("\n"); //if (o_flag) { //ON send REQ_LED_ON diff --git a/host/source/usb_operations.h b/host/source/usb_operations.h index f85a002..c732acf 100644 --- a/host/source/usb_operations.h +++ b/host/source/usb_operations.h @@ -12,7 +12,7 @@ #include "shared_dictionaries.h" //uncomment to DEBUG this file alone -#define DEBUG +//#define DEBUG //"make debug" to get DEBUG msgs on entire program #include "dbg.h" diff --git a/shared/shared_errors.h b/shared/shared_errors.h index a17b906..b38073b 100644 --- a/shared/shared_errors.h +++ b/shared/shared_errors.h @@ -5,11 +5,14 @@ //greater than 128 are possible avr return codes #define ERR_UNKN_DICTIONARY 128 +#define ERR_BAD_PP_OP_MINMAX 129 -#define ERR_UNKN_PP_OPCODE_ONLY 129 + +#define ERR_UNKN_PP_OPCODE_ONLY 139 #define ERR_UNKN_PP_OPCODE_8BOP 130 #define ERR_UNKN_PP_OPCODE_16BOP 131 #define ERR_UNKN_PP_OPCODE_24BOP 132 #define ERR_UNKN_PP_OPCODE_8BRV 133 + #endif