Compare commits

...

6 Commits

Author SHA1 Message Date
Tim Newsome fe8a1f8c58 Fix 2 more bitbang drivers.
Change-Id: Ib7257d1d113871a9f57ba3b899cb029bb595035a
2018-01-22 14:46:11 -08:00
Tim Newsome 26fadc7ef7 Update parport to return errors.
Change-Id: I6c6bf75809cd3222c7680e10ac6ee6073050ed07
2018-01-22 14:33:21 -08:00
Tim Newsome 9a817e7c1c Propagate errors from remote_bitbang; don't exit()
Change requested by Paul Fertser at
http://openocd.zylin.com/#/c/4312/4/src/jtag/drivers/remote_bitbang.c

Change-Id: I44d97bd1198821d2e8afdc7a237ed3c3825cd319
Signed-off-by: Tim Newsome <tim@sifive.com>
2018-01-22 13:58:53 -08:00
Tim Newsome ba6c65f2bc Format comments to be doxygen style.
Change-Id: I7a757b92926b9cd65846551893f78ffb5e462370
2018-01-22 12:11:36 -08:00
Tim Newsome 2fc53c1faa fdopen() for writing and reading.
Since that's what we're doing. Doesn't seem like this affected anything,
though.

Change-Id: I0fa915fe2a311d4b3e6e72a9a9a19f52018258c3
2018-01-22 11:48:24 -08:00
Tim Newsome fb2291421b Incorporate review feedback from OpenOCD team
Remove unused file handle, and rename the only remaining one to make
more sense.
Close file descriptor if initialization fails.

Change-Id: I383567aaadb1aa59d86f814eba8bc65f24e91928
2018-01-19 13:13:25 -08:00
6 changed files with 202 additions and 140 deletions

View File

@ -41,7 +41,7 @@ extern struct jtag_interface *jtag_interface;
* this function checks the current stable state to decide on the value of TMS
* to use.
*/
static void bitbang_stableclocks(int num_cycles);
static int bitbang_stableclocks(int num_cycles);
static void bitbang_swd_write_reg(uint8_t cmd, uint32_t value, uint32_t ap_delay_clk);
@ -70,15 +70,11 @@ struct bitbang_interface *bitbang_interface;
/* The bitbang driver leaves the TCK 0 when in idle */
static void bitbang_end_state(tap_state_t state)
{
if (tap_is_state_stable(state))
assert(tap_is_state_stable(state));
tap_set_end_state(state);
else {
LOG_ERROR("BUG: %i is not a valid end state", state);
exit(-1);
}
}
static void bitbang_state_move(int skip)
static int bitbang_state_move(int skip)
{
int i = 0, tms = 0;
uint8_t tms_scan = tap_get_tms_path(tap_get_state(), tap_get_end_state());
@ -86,12 +82,16 @@ static void bitbang_state_move(int skip)
for (i = skip; i < tms_count; i++) {
tms = (tms_scan >> i) & 1;
bitbang_interface->write(0, tms, 0);
bitbang_interface->write(1, tms, 0);
if (bitbang_interface->write(0, tms, 0) != ERROR_OK)
return ERROR_FAIL;
if (bitbang_interface->write(1, tms, 0) != ERROR_OK)
return ERROR_FAIL;
}
bitbang_interface->write(CLOCK_IDLE(), tms, 0);
if (bitbang_interface->write(CLOCK_IDLE(), tms, 0) != ERROR_OK)
return ERROR_FAIL;
tap_set_state(tap_get_end_state());
return ERROR_OK;
}
/**
@ -108,15 +108,18 @@ static int bitbang_execute_tms(struct jtag_command *cmd)
int tms = 0;
for (unsigned i = 0; i < num_bits; i++) {
tms = ((bits[i/8] >> (i % 8)) & 1);
bitbang_interface->write(0, tms, 0);
bitbang_interface->write(1, tms, 0);
if (bitbang_interface->write(0, tms, 0) != ERROR_OK)
return ERROR_FAIL;
if (bitbang_interface->write(1, tms, 0) != ERROR_OK)
return ERROR_FAIL;
}
bitbang_interface->write(CLOCK_IDLE(), tms, 0);
if (bitbang_interface->write(CLOCK_IDLE(), tms, 0) != ERROR_OK)
return ERROR_FAIL;
return ERROR_OK;
}
static void bitbang_path_move(struct pathmove_command *cmd)
static int bitbang_path_move(struct pathmove_command *cmd)
{
int num_states = cmd->num_states;
int state_count;
@ -135,20 +138,24 @@ static void bitbang_path_move(struct pathmove_command *cmd)
exit(-1);
}
bitbang_interface->write(0, tms, 0);
bitbang_interface->write(1, tms, 0);
if (bitbang_interface->write(0, tms, 0) != ERROR_OK)
return ERROR_FAIL;
if (bitbang_interface->write(1, tms, 0) != ERROR_OK)
return ERROR_FAIL;
tap_set_state(cmd->path[state_count]);
state_count++;
num_states--;
}
bitbang_interface->write(CLOCK_IDLE(), tms, 0);
if (bitbang_interface->write(CLOCK_IDLE(), tms, 0) != ERROR_OK)
return ERROR_FAIL;
tap_set_end_state(tap_get_state());
return ERROR_OK;
}
static void bitbang_runtest(int num_cycles)
static int bitbang_runtest(int num_cycles)
{
int i;
@ -157,35 +164,46 @@ static void bitbang_runtest(int num_cycles)
/* only do a state_move when we're not already in IDLE */
if (tap_get_state() != TAP_IDLE) {
bitbang_end_state(TAP_IDLE);
bitbang_state_move(0);
if (bitbang_state_move(0) != ERROR_OK)
return ERROR_FAIL;
}
/* execute num_cycles */
for (i = 0; i < num_cycles; i++) {
bitbang_interface->write(0, 0, 0);
bitbang_interface->write(1, 0, 0);
if (bitbang_interface->write(0, 0, 0) != ERROR_OK)
return ERROR_FAIL;
if (bitbang_interface->write(1, 0, 0) != ERROR_OK)
return ERROR_FAIL;
}
bitbang_interface->write(CLOCK_IDLE(), 0, 0);
if (bitbang_interface->write(CLOCK_IDLE(), 0, 0) != ERROR_OK)
return ERROR_FAIL;
/* finish in end_state */
bitbang_end_state(saved_end_state);
if (tap_get_state() != tap_get_end_state())
bitbang_state_move(0);
if (bitbang_state_move(0) != ERROR_OK)
return ERROR_FAIL;
return ERROR_OK;
}
static void bitbang_stableclocks(int num_cycles)
static int bitbang_stableclocks(int num_cycles)
{
int tms = (tap_get_state() == TAP_RESET ? 1 : 0);
int i;
/* send num_cycles clocks onto the cable */
for (i = 0; i < num_cycles; i++) {
bitbang_interface->write(1, tms, 0);
bitbang_interface->write(0, tms, 0);
}
if (bitbang_interface->write(1, tms, 0) != ERROR_OK)
return ERROR_FAIL;
if (bitbang_interface->write(0, tms, 0) != ERROR_OK)
return ERROR_FAIL;
}
static void bitbang_scan(bool ir_scan, enum scan_type type, uint8_t *buffer,
return ERROR_OK;
}
static int bitbang_scan(bool ir_scan, enum scan_type type, uint8_t *buffer,
unsigned scan_size)
{
tap_state_t saved_end_state = tap_get_end_state();
@ -199,7 +217,8 @@ static void bitbang_scan(bool ir_scan, enum scan_type type, uint8_t *buffer,
else
bitbang_end_state(TAP_DRSHIFT);
bitbang_state_move(0);
if (bitbang_state_move(0) != ERROR_OK)
return ERROR_FAIL;
bitbang_end_state(saved_end_state);
}
@ -218,31 +237,45 @@ static void bitbang_scan(bool ir_scan, enum scan_type type, uint8_t *buffer,
if ((type != SCAN_IN) && (buffer[bytec] & bcval))
tdi = 1;
bitbang_interface->write(0, tms, tdi);
if (bitbang_interface->write(0, tms, tdi) != ERROR_OK)
return ERROR_FAIL;
if (type != SCAN_OUT) {
if (bitbang_interface->buf_size) {
bitbang_interface->sample();
if (bitbang_interface->sample() != ERROR_OK)
return ERROR_FAIL;
buffered++;
} else {
int val = bitbang_interface->read();
if (val)
buffer[bytec] |= bcval;
else
switch (bitbang_interface->read()) {
case BB_LOW:
buffer[bytec] &= ~bcval;
break;
case BB_HIGH:
buffer[bytec] |= bcval;
break;
default:
return ERROR_FAIL;
}
}
}
bitbang_interface->write(1, tms, tdi);
if (bitbang_interface->write(1, tms, tdi) != ERROR_OK)
return ERROR_FAIL;
if (type != SCAN_OUT && bitbang_interface->buf_size &&
(buffered == bitbang_interface->buf_size ||
bit_cnt == scan_size - 1)) {
for (unsigned i = bit_cnt + 1 - buffered; i <= bit_cnt; i++) {
if (bitbang_interface->read_sample())
buffer[i/8] |= 1 << (i % 8);
else
switch (bitbang_interface->read_sample()) {
case BB_LOW:
buffer[i/8] &= ~(1 << (i % 8));
break;
case BB_HIGH:
buffer[i/8] |= 1 << (i % 8);
break;
default:
return ERROR_FAIL;
}
}
buffered = 0;
}
@ -253,8 +286,10 @@ static void bitbang_scan(bool ir_scan, enum scan_type type, uint8_t *buffer,
* the shift state, so we skip the first state
* and move directly to the end state.
*/
bitbang_state_move(1);
if (bitbang_state_move(1) != ERROR_OK)
return ERROR_FAIL;
}
return ERROR_OK;
}
int bitbang_execute_queue(void)
@ -275,8 +310,10 @@ int bitbang_execute_queue(void)
*/
retval = ERROR_OK;
if (bitbang_interface->blink)
bitbang_interface->blink(1);
if (bitbang_interface->blink) {
if (bitbang_interface->blink(1) != ERROR_OK)
return ERROR_FAIL;
}
while (cmd) {
switch (cmd->type) {
@ -289,7 +326,9 @@ int bitbang_execute_queue(void)
if ((cmd->cmd.reset->trst == 1) ||
(cmd->cmd.reset->srst && (jtag_get_reset_config() & RESET_SRST_PULLS_TRST)))
tap_set_state(TAP_RESET);
bitbang_interface->reset(cmd->cmd.reset->trst, cmd->cmd.reset->srst);
if (bitbang_interface->reset(cmd->cmd.reset->trst,
cmd->cmd.reset->srst) != ERROR_OK)
return ERROR_FAIL;
break;
case JTAG_RUNTEST:
#ifdef _DEBUG_JTAG_IO_
@ -298,14 +337,16 @@ int bitbang_execute_queue(void)
tap_state_name(cmd->cmd.runtest->end_state));
#endif
bitbang_end_state(cmd->cmd.runtest->end_state);
bitbang_runtest(cmd->cmd.runtest->num_cycles);
if (bitbang_runtest(cmd->cmd.runtest->num_cycles) != ERROR_OK)
return ERROR_FAIL;
break;
case JTAG_STABLECLOCKS:
/* this is only allowed while in a stable state. A check for a stable
* state was done in jtag_add_clocks()
*/
bitbang_stableclocks(cmd->cmd.stableclocks->num_cycles);
if (bitbang_stableclocks(cmd->cmd.stableclocks->num_cycles) != ERROR_OK)
return ERROR_FAIL;
break;
case JTAG_TLR_RESET:
@ -314,7 +355,8 @@ int bitbang_execute_queue(void)
tap_state_name(cmd->cmd.statemove->end_state));
#endif
bitbang_end_state(cmd->cmd.statemove->end_state);
bitbang_state_move(0);
if (bitbang_state_move(0) != ERROR_OK)
return ERROR_FAIL;
break;
case JTAG_PATHMOVE:
#ifdef _DEBUG_JTAG_IO_
@ -322,7 +364,8 @@ int bitbang_execute_queue(void)
cmd->cmd.pathmove->num_states,
tap_state_name(cmd->cmd.pathmove->path[cmd->cmd.pathmove->num_states - 1]));
#endif
bitbang_path_move(cmd->cmd.pathmove);
if (bitbang_path_move(cmd->cmd.pathmove) != ERROR_OK)
return ERROR_FAIL;
break;
case JTAG_SCAN:
bitbang_end_state(cmd->cmd.scan->end_state);
@ -334,7 +377,9 @@ int bitbang_execute_queue(void)
tap_state_name(cmd->cmd.scan->end_state));
#endif
type = jtag_scan_type(cmd->cmd.scan);
bitbang_scan(cmd->cmd.scan->ir_scan, type, buffer, scan_size);
if (bitbang_scan(cmd->cmd.scan->ir_scan, type, buffer,
scan_size) != ERROR_OK)
return ERROR_FAIL;
if (jtag_read_buffer(buffer, cmd->cmd.scan) != ERROR_OK)
retval = ERROR_JTAG_QUEUE_FAILED;
if (buffer)
@ -355,8 +400,10 @@ int bitbang_execute_queue(void)
}
cmd = cmd->next;
}
if (bitbang_interface->blink)
bitbang_interface->blink(0);
if (bitbang_interface->blink) {
if (bitbang_interface->blink(0) != ERROR_OK)
return ERROR_FAIL;
}
return retval;
}

View File

@ -24,30 +24,35 @@
#include <jtag/swd.h>
typedef enum {
BB_LOW,
BB_HIGH,
BB_ERROR
} bb_value_t;
/** Low level callbacks (for bitbang).
*
* Either read(), or sample() and read_sample() must be implemented.
*
* The sample functions allow an interface to batch a number of writes and
* sample requests together. Not waiting for a value to come back can greatly
* increase throughput. */
struct bitbang_interface {
/* low level callbacks (for bitbang)
*/
/** Sample TDO. */
bb_value_t (*read)(void);
/* Either read() or sample()/read_sample() must be implemented. */
/* Sample TDO and return 0 or 1. */
int (*read)(void);
/* The sample functions allow an interface to batch a number of writes and
* sample requests together. Not waiting for a value to come back can
* greatly increase throughput. */
/* The number of TDO samples that can be buffered up before the caller has
/** The number of TDO samples that can be buffered up before the caller has
* to call read_sample. */
size_t buf_size;
/* Sample TDO and put the result in a buffer. */
void (*sample)(void);
/* Return the next unread value from the buffer. */
int (*read_sample)(void);
/** Sample TDO and put the result in a buffer. */
int (*sample)(void);
/** Return the next unread value from the buffer. */
bb_value_t (*read_sample)(void);
/* Set TCK, TMS, and TDI to the given values. */
void (*write)(int tck, int tms, int tdi);
void (*reset)(int trst, int srst);
void (*blink)(int on);
/** Set TCK, TMS, and TDI to the given values. */
int (*write)(int tck, int tms, int tdi);
int (*reset)(int trst, int srst);
int (*blink)(int on);
int (*swdio_read)(void);
void (*swdio_drive)(bool on);
};

View File

@ -33,14 +33,14 @@ static int clock_count; /* count clocks in any stable state, only stable states
static uint32_t dummy_data;
static int dummy_read(void)
static bb_value_t dummy_read(void)
{
int data = 1 & dummy_data;
dummy_data = (dummy_data >> 1) | (1 << 31);
return data;
return data ? BB_HIGH : BB_LOW;
}
static void dummy_write(int tck, int tms, int tdi)
static int dummy_write(int tck, int tms, int tdi)
{
/* TAP standard: "state transitions occur on rising edge of clock" */
if (tck != dummy_clock) {
@ -69,9 +69,10 @@ static void dummy_write(int tck, int tms, int tdi)
}
dummy_clock = tck;
}
return ERROR_OK;
}
static void dummy_reset(int trst, int srst)
static int dummy_reset(int trst, int srst)
{
dummy_clock = 0;
@ -79,10 +80,12 @@ static void dummy_reset(int trst, int srst)
dummy_state = TAP_RESET;
LOG_DEBUG("reset to: %s", tap_state_name(dummy_state));
return ERROR_OK;
}
static void dummy_led(int on)
static int dummy_led(int on)
{
return ERROR_OK;
}
static struct bitbang_interface dummy_bitbang = {

View File

@ -116,7 +116,7 @@ static unsigned long dataport;
static unsigned long statusport;
#endif
static int parport_read(void)
static bb_value_t parport_read(void)
{
int data = 0;
@ -127,9 +127,9 @@ static int parport_read(void)
#endif
if ((data ^ cable->INPUT_INVERT) & cable->TDO_MASK)
return 1;
return BB_HIGH;
else
return 0;
return BB_LOW;
}
static inline void parport_write_data(void)
@ -148,7 +148,7 @@ static inline void parport_write_data(void)
#endif
}
static void parport_write(int tck, int tms, int tdi)
static int parport_write(int tck, int tms, int tdi)
{
int i = wait_states + 1;
@ -169,10 +169,12 @@ static void parport_write(int tck, int tms, int tdi)
while (i-- > 0)
parport_write_data();
return ERROR_OK;
}
/* (1) assert or (0) deassert reset lines */
static void parport_reset(int trst, int srst)
static int parport_reset(int trst, int srst)
{
LOG_DEBUG("trst: %i, srst: %i", trst, srst);
@ -187,10 +189,12 @@ static void parport_reset(int trst, int srst)
dataport_value &= ~cable->SRST_MASK;
parport_write_data();
return ERROR_OK;
}
/* turn LED on parport adapter on (1) or off (0) */
static void parport_led(int on)
static int parport_led(int on)
{
if (on)
dataport_value |= cable->LED_MASK;
@ -198,6 +202,8 @@ static void parport_led(int on)
dataport_value &= ~cable->LED_MASK;
parport_write_data();
return ERROR_OK;
}
static int parport_speed(int speed)
@ -365,9 +371,12 @@ static int parport_init(void)
#endif /* PARPORT_USE_PPDEV */
parport_reset(0, 0);
parport_write(0, 0, 0);
parport_led(1);
if (parport_reset(0, 0) != ERROR_OK)
return ERROR_FAIL;
if (parport_write(0, 0, 0) != ERROR_OK)
return ERROR_FAIL;
if (parport_led(1) != ERROR_OK)
return ERROR_FAIL;
bitbang_interface = &parport_bitbang;
@ -376,7 +385,8 @@ static int parport_init(void)
static int parport_quit(void)
{
parport_led(0);
if (parport_led(0) != ERROR_OK)
return ERROR_FAIL;
if (parport_exit) {
dataport_value = cable->PORT_EXIT;

View File

@ -30,18 +30,10 @@
/* arbitrary limit on host name length: */
#define REMOTE_BITBANG_HOST_MAX 255
#define REMOTE_BITBANG_RAISE_ERROR(expr ...) \
do { \
LOG_ERROR(expr); \
LOG_ERROR("Terminating openocd."); \
exit(-1); \
} while (0)
static char *remote_bitbang_host;
static char *remote_bitbang_port;
static FILE *remote_bitbang_in;
static FILE *remote_bitbang_out;
static FILE *remote_bitbang_file;
static int remote_bitbang_fd;
/* Circular buffer. When start == end, the buffer is empty. */
@ -57,7 +49,7 @@ static int remote_bitbang_buf_full(void)
}
/* Read any incoming data, placing it into the buffer. */
static void remote_bitbang_fill_buf(void)
static int remote_bitbang_fill_buf(void)
{
socket_nonblock(remote_bitbang_fd);
while (!remote_bitbang_buf_full()) {
@ -79,39 +71,45 @@ static void remote_bitbang_fill_buf(void)
if (remote_bitbang_end == sizeof(remote_bitbang_buf))
remote_bitbang_end = 0;
} else if (count == 0) {
return;
return ERROR_OK;
} else if (count < 0) {
if (errno == EAGAIN) {
return;
return ERROR_OK;
} else {
REMOTE_BITBANG_RAISE_ERROR("remote_bitbang_fill_buf: %s (%d)",
LOG_ERROR("remote_bitbang_fill_buf: %s (%d)",
strerror(errno), errno);
}
return ERROR_FAIL;
}
}
}
static void remote_bitbang_putc(int c)
return ERROR_OK;
}
static int remote_bitbang_putc(int c)
{
if (EOF == fputc(c, remote_bitbang_out))
REMOTE_BITBANG_RAISE_ERROR("remote_bitbang_putc: %s", strerror(errno));
if (EOF == fputc(c, remote_bitbang_file)) {
LOG_ERROR("remote_bitbang_putc: %s", strerror(errno));
return ERROR_FAIL;
}
return ERROR_OK;
}
static int remote_bitbang_quit(void)
{
if (EOF == fputc('Q', remote_bitbang_out)) {
if (EOF == fputc('Q', remote_bitbang_file)) {
LOG_ERROR("fputs: %s", strerror(errno));
return ERROR_FAIL;
}
if (EOF == fflush(remote_bitbang_out)) {
if (EOF == fflush(remote_bitbang_file)) {
LOG_ERROR("fflush: %s", strerror(errno));
return ERROR_FAIL;
}
/* We only need to close one of the FILE*s, because they both use the same */
/* underlying file descriptor. */
if (EOF == fclose(remote_bitbang_out)) {
if (EOF == fclose(remote_bitbang_file)) {
LOG_ERROR("fclose: %s", strerror(errno));
return ERROR_FAIL;
}
@ -123,26 +121,27 @@ static int remote_bitbang_quit(void)
return ERROR_OK;
}
static int char_to_int(int c)
static bb_value_t char_to_int(int c)
{
switch (c) {
case '0':
return 0;
return BB_LOW;
case '1':
return 1;
return BB_HIGH;
default:
remote_bitbang_quit();
REMOTE_BITBANG_RAISE_ERROR(
"remote_bitbang: invalid read response: %c(%i)", c, c);
LOG_ERROR("remote_bitbang: invalid read response: %c(%i)", c, c);
return BB_ERROR;
}
}
/* Get the next read response. */
static int remote_bitbang_rread(void)
static bb_value_t remote_bitbang_rread(void)
{
if (EOF == fflush(remote_bitbang_out)) {
if (EOF == fflush(remote_bitbang_file)) {
remote_bitbang_quit();
REMOTE_BITBANG_RAISE_ERROR("fflush: %s", strerror(errno));
LOG_ERROR("fflush: %s", strerror(errno));
return BB_ERROR;
}
/* Enable blocking access. */
@ -153,19 +152,20 @@ static int remote_bitbang_rread(void)
return char_to_int(c);
} else {
remote_bitbang_quit();
REMOTE_BITBANG_RAISE_ERROR("read: count=%d, error=%s", (int) count,
strerror(errno));
LOG_ERROR("read: count=%d, error=%s", (int) count, strerror(errno));
return BB_ERROR;
}
}
static void remote_bitbang_sample(void)
static int remote_bitbang_sample(void)
{
remote_bitbang_fill_buf();
if (remote_bitbang_fill_buf() != ERROR_OK)
return ERROR_FAIL;
assert(!remote_bitbang_buf_full());
remote_bitbang_putc('R');
return remote_bitbang_putc('R');
}
static int remote_bitbang_read_sample(void)
static bb_value_t remote_bitbang_read_sample(void)
{
if (remote_bitbang_start != remote_bitbang_end) {
int c = remote_bitbang_buf[remote_bitbang_start];
@ -176,22 +176,22 @@ static int remote_bitbang_read_sample(void)
return remote_bitbang_rread();
}
static void remote_bitbang_write(int tck, int tms, int tdi)
static int remote_bitbang_write(int tck, int tms, int tdi)
{
char c = '0' + ((tck ? 0x4 : 0x0) | (tms ? 0x2 : 0x0) | (tdi ? 0x1 : 0x0));
remote_bitbang_putc(c);
return remote_bitbang_putc(c);
}
static void remote_bitbang_reset(int trst, int srst)
static int remote_bitbang_reset(int trst, int srst)
{
char c = 'r' + ((trst ? 0x2 : 0x0) | (srst ? 0x1 : 0x0));
remote_bitbang_putc(c);
return remote_bitbang_putc(c);
}
static void remote_bitbang_blink(int on)
static int remote_bitbang_blink(int on)
{
char c = on ? 'B' : 'b';
remote_bitbang_putc(c);
return remote_bitbang_putc(c);
}
static struct bitbang_interface remote_bitbang_bitbang = {
@ -289,17 +289,10 @@ static int remote_bitbang_init(void)
if (remote_bitbang_fd < 0)
return remote_bitbang_fd;
remote_bitbang_in = fdopen(remote_bitbang_fd, "r");
if (remote_bitbang_in == NULL) {
LOG_ERROR("fdopen: failed to open read stream");
close(remote_bitbang_fd);
return ERROR_FAIL;
}
remote_bitbang_out = fdopen(remote_bitbang_fd, "w");
if (remote_bitbang_out == NULL) {
remote_bitbang_file = fdopen(remote_bitbang_fd, "w+");
if (remote_bitbang_file == NULL) {
LOG_ERROR("fdopen: failed to open write stream");
fclose(remote_bitbang_in);
close(remote_bitbang_fd);
return ERROR_FAIL;
}

View File

@ -244,7 +244,7 @@ static void sysfsgpio_swdio_write(int swclk, int swdio)
* The sysfs value will read back either '0' or '1'. The trick here is to call
* lseek to bypass buffering in the sysfs kernel driver.
*/
static int sysfsgpio_read(void)
static bb_value_t sysfsgpio_read(void)
{
char buf[1];
@ -257,7 +257,7 @@ static int sysfsgpio_read(void)
return 0;
}
return buf[0] != '0';
return buf[0] == '0' ? BB_LOW : BB_HIGH;
}
/*
@ -266,11 +266,11 @@ static int sysfsgpio_read(void)
* Seeing as this is the only function where the outputs are changed,
* we can cache the old value to avoid needlessly writing it.
*/
static void sysfsgpio_write(int tck, int tms, int tdi)
static int sysfsgpio_write(int tck, int tms, int tdi)
{
if (swd_mode) {
sysfsgpio_swdio_write(tck, tdi);
return;
return ERROR_OK;
}
const char one[] = "1";
@ -312,6 +312,8 @@ static void sysfsgpio_write(int tck, int tms, int tdi)
last_tdi = tdi;
last_tms = tms;
last_tck = tck;
return ERROR_OK;
}
/*
@ -319,7 +321,7 @@ static void sysfsgpio_write(int tck, int tms, int tdi)
*
* (1) assert or (0) deassert reset lines
*/
static void sysfsgpio_reset(int trst, int srst)
static int sysfsgpio_reset(int trst, int srst)
{
LOG_DEBUG("sysfsgpio_reset");
const char one[] = "1";
@ -339,6 +341,8 @@ static void sysfsgpio_reset(int trst, int srst)
if (bytes_written != 1)
LOG_WARNING("writing trst failed");
}
return ERROR_OK;
}
COMMAND_HANDLER(sysfsgpio_handle_jtag_gpionums)