diff --git a/BUSSide/BUSSide.h b/BUSSide/BUSSide.h old mode 100755 new mode 100644 index 596d848..f7e66d7 --- a/BUSSide/BUSSide.h +++ b/BUSSide/BUSSide.h @@ -1,9 +1,24 @@ #ifndef BUSSIDE_H #define BUSSIDE_H +// Doesn't compile if included in UART +#include + #define FREQ 160 #define N_GPIO 9 +typedef void prog_void; +typedef char prog_char; +typedef unsigned char prog_uchar; +typedef int8_t prog_int8_t; +typedef uint8_t prog_uint8_t; +typedef int16_t prog_int16_t; +typedef uint16_t prog_uint16_t; +typedef int32_t prog_int32_t; +typedef uint32_t prog_uint32_t; +typedef int64_t prog_int64_t; +typedef uint64_t prog_uint64_t; + unsigned long crc_update(unsigned long crc, byte data); unsigned long crc_mem(char *s, int n); void delay_us(int us); @@ -80,4 +95,4 @@ struct bs_reply_s { uint32_t bs_checksum; }; -#endif +#endif diff --git a/BUSSide/BUSSide.ino b/BUSSide/BUSSide.ino old mode 100755 new mode 100644 index 85c033b..4c4486f --- a/BUSSide/BUSSide.ino +++ b/BUSSide/BUSSide.ino @@ -81,7 +81,7 @@ send_reply(int rv, struct bs_request_s *request, struct bs_reply_s *reply) reply->bs_sequence_number = request->bs_sequence_number; if (rv == 0) { reply->bs_checksum = crc_mem((char *)reply, BS_REPLY_SIZE - 4); - Serial.write((char *)reply, BS_REPLY_SIZE); + Serial.write((const unsigned char *)reply, BS_REPLY_SIZE); } } @@ -172,4 +172,4 @@ loop() send_reply(rv, &request, &reply); reset_gpios(); -} +} diff --git a/BUSSide/I2C.ino b/BUSSide/I2C.ino old mode 100755 new mode 100644 index db2bee6..79f734d --- a/BUSSide/I2C.ino +++ b/BUSSide/I2C.ino @@ -49,8 +49,7 @@ read_I2C_eeprom(struct bs_request_s *request, struct bs_reply_s *reply) return 0; } -static void -I2C_active_scan1(struct bs_request_s *request, struct bs_reply_s *reply, int sdaPin, int sclPin) +static void I2C_active_scan1(struct bs_request_s *request, struct bs_reply_s *reply, int sdaPin, int sclPin) { Wire.begin(gpioIndex[sdaPin], gpioIndex[sclPin]); for (int slaveAddress = 0; slaveAddress < 128; slaveAddress++) { @@ -104,5 +103,3 @@ discover_I2C_slaves(struct bs_request_s *request, struct bs_reply_s *reply) } return 0; } - - diff --git a/BUSSide/JTAG.ino b/BUSSide/JTAG.ino old mode 100755 new mode 100644 index e7dbb55..b07601d --- a/BUSSide/JTAG.ino +++ b/BUSSide/JTAG.ino @@ -71,8 +71,7 @@ static long DELAYUS = 5; //5000; // 5 MillisecondsHTAGboolea /* * Set the JTAG TAP state machine */ -static void -tap_state(char tap_state[], int tck, int tms) +static void tap_state(char tap_state[], int tck, int tms) { #ifdef DEBUGTAP Serial.print("tap_state: tms set to: "); @@ -93,8 +92,7 @@ tap_state(char tap_state[], int tck, int tms) #endif } -static int -JTAG_clock(int tck, int tms, int tdi, int tdo, int tms_state, int tdi_state) +static int JTAG_clock(int tck, int tms, int tdi, int tdo, int tms_state, int tdi_state) { int tdo_state; @@ -108,8 +106,7 @@ JTAG_clock(int tck, int tms, int tdi, int tdo, int tms_state, int tdi_state) return tdo_state; } -static uint32_t -JTAG_read32(int tck, int tms, int tdi, int tdo) +static uint32_t JTAG_read32(int tck, int tms, int tdi, int tdo) { uint32_t r; @@ -121,8 +118,7 @@ JTAG_read32(int tck, int tms, int tdi, int tdo) return r; } -static int -JTAG_ndevices(int tck, int tms, int tdi, int tdo) +static int JTAG_ndevices(int tck, int tms, int tdi, int tdo) { int nbDevices; int i; @@ -172,8 +168,7 @@ JTAG_ndevices(int tck, int tms, int tdi, int tdo) return nbDevices; } -static void -JTAG_scan_chain(int tck, int tms, int tdi, int tdo, int ndevices) +static void JTAG_scan_chain(int tck, int tms, int tdi, int tdo, int ndevices) { // go to reset state (that loads IDCODE into IR of all the devices) for(int i=0; i<5; i++) JTAG_clock(tck, tms, tdi, tdo, 1, 0); @@ -191,16 +186,14 @@ JTAG_scan_chain(int tck, int tms, int tdi, int tdo, int ndevices) } } -static void -pulse_tms(int tck, int tms, int s_tms) +static void pulse_tms(int tck, int tms, int s_tms) { if (tck == IGNOREPIN) return; digitalWrite(pins[tck], LOW); digitalWrite(pins[tms], s_tms); digitalWrite(pins[tck], HIGH); } -static void -pulse_tdi(int tck, int tdi, int s_tdi) +static void pulse_tdi(int tck, int tdi, int s_tdi) { if (DELAY) delayMicroseconds(50); if (tck != IGNOREPIN) digitalWrite(pins[tck], LOW); @@ -208,8 +201,7 @@ pulse_tdi(int tck, int tdi, int s_tdi) if (tck != IGNOREPIN) digitalWrite(pins[tck], HIGH); } -byte -pulse_tdo(int tck, int tdo) +byte pulse_tdo(int tck, int tdo) { byte tdo_read; if (DELAY) delayMicroseconds(50); @@ -223,8 +215,7 @@ pulse_tdo(int tck, int tdo) * Initialize all pins to a default state * default with no arguments: all pins as INPUTs */ -void -init_pins(int tck = IGNOREPIN, int tms = IGNOREPIN, int tdi = IGNOREPIN, int ntrst = IGNOREPIN) +void init_pins(int tck = IGNOREPIN, int tms = IGNOREPIN, int tdi = IGNOREPIN, int ntrst = IGNOREPIN) { ESP.wdtFeed(); // default all to INPUT state @@ -260,8 +251,7 @@ init_pins(int tck = IGNOREPIN, int tms = IGNOREPIN, int tdi = IGNOREPIN, int ntr * * if retval == 1, *reglen returns the length of the register */ -static int -check_data(char pattern[], int iterations, int tck, int tdi, int tdo, int *reg_len) +static int check_data(char pattern[], int iterations, int tck, int tdi, int tdo, int *reg_len) { int i; int w = 0; @@ -310,8 +300,7 @@ check_data(char pattern[], int iterations, int tck, int tdi, int tdo, int *reg_l return nr_toggle > 1 ? nr_toggle : 0; } -static void -print_pins(int tck, int tms, int tdo, int tdi, int ntrst) +static void print_pins(int tck, int tms, int tdo, int tdi, int ntrst) { if (VERBOSE) { if (ntrst != IGNOREPIN) { @@ -335,8 +324,7 @@ print_pins(int tck, int tms, int tdo, int tdi, int ntrst) * Shift JTAG TAP to ShiftIR state. Send pattern to TDI and check * for output on TDO */ -static int -scan(int *tck_pin, int *tms_pin, int *tdi_pin, int *tdo_pin, int *ntrst_pin) +static int scan(int *tck_pin, int *tms_pin, int *tdi_pin, int *tdo_pin, int *ntrst_pin) { int tck, tms, tdo, tdi, ntrst; int checkdataret = 0; @@ -410,8 +398,7 @@ scan(int *tck_pin, int *tms_pin, int *tdi_pin, int *tdo_pin, int *ntrst_pin) * the test again without the cable connected between controller * and target. Run with the verbose flag to examine closely. */ -static void -loopback_check() +static void loopback_check() { int tdo, tdi; int checkdataret = 0; @@ -459,8 +446,7 @@ loopback_check() } #if 0 -static void -list_pin_names() +static void list_pin_names() { int pin; Serial.print("The configured pins are:\r\n"); @@ -480,8 +466,7 @@ list_pin_names() * (oppposite to the old code). * If we get an IDCODE of all ones, we assume that the pins are wrong. */ -static void -scan_idcode() +static void scan_idcode() { int tck, tms, tdo, tdi, ntrst; int i, j; @@ -563,8 +548,7 @@ scan_idcode() } /* for(trst=0; ...) */ } -static void -shift_bypass() +static void shift_bypass() { int tdi, tdo, tck; int checkdataret; @@ -626,8 +610,7 @@ shift_bypass() * Shift in state[] as IR value. * Switch to ShiftDR state and end. */ -static void -ir_state(char state[], int tck, int tms, int tdi) +static void ir_state(char state[], int tck, int tms, int tdi) { #ifdef DEBUGIR Serial.println("ir_state: set TAP to ShiftIR:"); @@ -682,8 +665,7 @@ sample(int iterations, int tck, int tms, int tdi, int tdo, int ntrst=IGNOREPIN) } char ir_buf[IR_LEN+1]; -static void -brute_ir(int iterations, int tck, int tms, int tdi, int tdo, int ntrst=IGNOREPIN) +static void brute_ir(int iterations, int tck, int tms, int tdi, int tdo, int ntrst=IGNOREPIN) { init_pins(tck, tms ,tdi, ntrst); int iractive; @@ -725,8 +707,7 @@ brute_ir(int iterations, int tck, int tms, int tdi, int tdo, int ntrst=IGNOREPIN } #if 0 -static void -set_pattern() +static void set_pattern() { int i; char c; @@ -758,8 +739,7 @@ set_pattern() } #endif -int -JTAG_scan(struct bs_request_s *request, struct bs_reply_s *reply) +int JTAG_scan(struct bs_request_s *request, struct bs_reply_s *reply) { int tck, tms, tdo, tdi, ntrst; int rv; @@ -778,8 +758,7 @@ JTAG_scan(struct bs_request_s *request, struct bs_reply_s *reply) return 0; } -void -JTAG_reset(int ntrst) +void JTAG_reset(int ntrst) { digitalWrite(pins[ntrst], HIGH); delay_us(50); @@ -788,5 +767,3 @@ JTAG_reset(int ntrst) digitalWrite(pins[ntrst], HIGH); delay_us(50); } - - diff --git a/BUSSide/UART.ino b/BUSSide/UART.ino old mode 100755 new mode 100644 index 27e68e5..c5058c8 --- a/BUSSide/UART.ino +++ b/BUSSide/UART.ino @@ -1,6 +1,5 @@ #include #include "BUSSide.h" -#include //#define min(a,b) (((a)<(b))?(a):(b)) @@ -13,24 +12,23 @@ static int gpioVal[N_GPIO]; struct uartInfo_s { int baudRate; float microsDelay; -} uartInfo[] = { - { 300, 3333.3 }, // 0 - { 600, 1666.7 }, // 1 - { 1200, 833.3 }, // 2 - { 2400, 416.7 }, // 3 - { 4800, 208.3 }, // 4 - { 9600, 104.2 }, // 5 - { 19200, 52.1 }, // 6 - { 38400, 26.0 }, // 7 - { 57600, 17.4 }, // 8 - { 115200, 8.68 }, // 9 - { 0, 0 }, + } uartInfo[] = { + { 300, 3333.3 }, // 0 + { 600, 1666.7 }, // 1 + { 1200, 833.3 }, // 2 + { 2400, 416.7 }, // 3 + { 4800, 208.3 }, // 4 + { 9600, 104.2 }, // 5 + { 19200, 52.1 }, // 6 + { 38400, 26.0 }, // 7 + { 57600, 17.4 }, // 8 + { 115200, 8.68 }, // 9 + { 0, 0 }, }; static int uartSpeedIndex; -static unsigned int -findNumberOfUartSpeeds(void) +static unsigned int findNumberOfUartSpeeds(void) { unsigned int i; @@ -38,8 +36,7 @@ findNumberOfUartSpeeds(void) return i; } -static int -waitForIdle(int pin) +static int waitForIdle(int pin) { unsigned long startTime; unsigned long bitTime10; @@ -60,8 +57,7 @@ start: return 0; } -static int -buildwidths(int pin, int *widths, int nwidths) +static int buildwidths(int pin, int *widths, int nwidths) { int val; int32_t startTime; @@ -90,8 +86,7 @@ buildwidths(int pin, int *widths, int nwidths) return 0; } -static unsigned int -findminwidth(int *widths, int nwidths) +static unsigned int findminwidth(int *widths, int nwidths) { int minIndex1; unsigned int min1; @@ -107,8 +102,7 @@ findminwidth(int *widths, int nwidths) } -static float -autobaud(int pin, int *widths, int nwidths) +static float autobaud(int pin, int *widths, int nwidths) { int sum; int c = 0; @@ -123,8 +117,7 @@ autobaud(int pin, int *widths, int nwidths) return (float)sum/(float)c; } -static int -tryFrameSize(int framesize, int stopbits, int *widths, int nwidths) +static int tryFrameSize(int framesize, int stopbits, int *widths, int nwidths) { float width_timepos = 0.0; float bitTime = uartInfo[uartSpeedIndex].microsDelay; @@ -149,8 +142,7 @@ tryFrameSize(int framesize, int stopbits, int *widths, int nwidths) return 1; } -static int -calcBaud(int pin, int *widths, int nwidths) +static int calcBaud(int pin, int *widths, int nwidths) { char fstr[6]; char s[100]; @@ -179,8 +171,7 @@ calcBaud(int pin, int *widths, int nwidths) return baudIndex; } -static int -calcParity(int frameSize, int stopBits, int *widths, int nwidths) +static int calcParity(int frameSize, int stopBits, int *widths, int nwidths) { float width_timepos = 0.0; float bitTime = uartInfo[uartSpeedIndex].microsDelay; @@ -243,8 +234,7 @@ static float bitTime; #define NWIDTHS 200 -static int -UART_line_settings_direct(struct bs_request_s *request, struct bs_reply_s *reply, int index) +static int UART_line_settings_direct(struct bs_request_s *request, struct bs_reply_s *reply, int index) { int widths[NWIDTHS]; char s[100]; @@ -321,8 +311,7 @@ UART_line_settings_direct(struct bs_request_s *request, struct bs_reply_s *reply return 0; } -static int -UART_all_line_settings_direct(struct bs_request_s *request, struct bs_reply_s *reply) +static int UART_all_line_settings_direct(struct bs_request_s *request, struct bs_reply_s *reply) { int u = 0; @@ -351,14 +340,12 @@ UART_all_line_settings_direct(struct bs_request_s *request, struct bs_reply_s *r return 0; } -int -UART_all_line_settings(struct bs_request_s *request, struct bs_reply_s *reply) +int UART_all_line_settings(struct bs_request_s *request, struct bs_reply_s *reply) { return UART_all_line_settings_direct(request, reply); } -int -data_discovery(struct bs_request_s *request, struct bs_reply_s *reply) +int data_discovery(struct bs_request_s *request, struct bs_reply_s *reply) { int32_t startTime; @@ -390,8 +377,7 @@ data_discovery(struct bs_request_s *request, struct bs_reply_s *reply) return 0; } -int -UART_passthrough(struct bs_request_s *request, struct bs_reply_s *reply) +int UART_passthrough(struct bs_request_s *request, struct bs_reply_s *reply) { int rxpin, txpin; int baudrate; @@ -417,8 +403,7 @@ UART_passthrough(struct bs_request_s *request, struct bs_reply_s *reply) return 0; } -int -UART_testtx(SoftwareSerial *ser, int testChar) +int UART_testtx(SoftwareSerial *ser, int testChar) { ser->write(testChar); for (int i = 0; i < 10000; i++) { @@ -437,8 +422,7 @@ UART_testtx(SoftwareSerial *ser, int testChar) return 0; } -int -UART_discover_tx(struct bs_request_s *request, struct bs_reply_s *reply) +int UART_discover_tx(struct bs_request_s *request, struct bs_reply_s *reply) { int rxpin, txpin; int baudrate; @@ -473,4 +457,4 @@ UART_discover_tx(struct bs_request_s *request, struct bs_reply_s *reply) } reply->bs_reply_data[0] = -1; return 0; -} +}