Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion BUSSide/BUSSide.h
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,9 +1,24 @@
#ifndef BUSSIDE_H
#define BUSSIDE_H

// Doesn't compile if included in UART
#include <SoftwareSerial.h>

#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);
Expand Down Expand Up @@ -80,4 +95,4 @@ struct bs_reply_s {
uint32_t bs_checksum;
};

#endif
#endif
4 changes: 2 additions & 2 deletions BUSSide/BUSSide.ino
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand Down Expand Up @@ -172,4 +172,4 @@ loop()

send_reply(rv, &request, &reply);
reset_gpios();
}
}
5 changes: 1 addition & 4 deletions BUSSide/I2C.ino
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -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++) {
Expand Down Expand Up @@ -104,5 +103,3 @@ discover_I2C_slaves(struct bs_request_s *request, struct bs_reply_s *reply)
}
return 0;
}


65 changes: 21 additions & 44 deletions BUSSide/JTAG.ino
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -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: ");
Expand All @@ -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;

Expand All @@ -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;

Expand All @@ -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;
Expand Down Expand Up @@ -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);
Expand All @@ -191,25 +186,22 @@ 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);
digitalWrite(pins[tdi], 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);
Expand All @@ -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
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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");
Expand All @@ -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;
Expand Down Expand Up @@ -563,8 +548,7 @@ scan_idcode()
} /* for(trst=0; ...) */
}

static void
shift_bypass()
static void shift_bypass()
{
int tdi, tdo, tck;
int checkdataret;
Expand Down Expand Up @@ -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:");
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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);
Expand All @@ -788,5 +767,3 @@ JTAG_reset(int ntrst)
digitalWrite(pins[ntrst], HIGH);
delay_us(50);
}


Loading