Fix bug I introduced in bsbit_alloc; fix error returns from API routines in cmd

git-svn-id: https://urjtag.svn.sourceforge.net/svnroot/urjtag/trunk@1559 b68d4a1b-bc3d-0410-92ed-d4ac073336b7
master
Rutger Hofman 16 years ago
parent 63295937a6
commit 05c742ca7a

@ -50,19 +50,19 @@ struct urj_bsbit
/**
* Define new BSR (Boundary Scan Register) bit for signal <code>name</code>.
*
* @param chain
* @param part
* @param bit
* @param name associated signal name
* @param type URJ_BSBIT_{INPUT|OUTPUT|BIDIR|CONTROL|INTERNAL}
* @param safe default (safe) value (0|1)
*/
urj_bsbit_t *urj_part_bsbit_alloc (urj_chain_t *chain, int bit,
urj_bsbit_t *urj_part_bsbit_alloc (urj_part_t *part, int bit,
const char *name, int type, int safe);
/**
* Define new BSR (Boundary Scan Register) bit for signal <code>name</code>.
* Additionally, define control bit.
*
* @param chain
* @param part
* @param bit
* @param name associated signal name
* @param type URJ_BSBIT_{INPUT|OUTPUT|BIDIR|CONTROL|INTERNAL}
@ -71,7 +71,7 @@ urj_bsbit_t *urj_part_bsbit_alloc (urj_chain_t *chain, int bit,
* @param ctrl_val control value
* @param ctrl_state control state; valid statis is only URJ_BSBIT_STATE_Z
*/
urj_bsbit_t *urj_part_bsbit_alloc_control (urj_chain_t *chain, int bit,
urj_bsbit_t *urj_part_bsbit_alloc_control (urj_part_t *part, int bit,
const char *name, int type, int safe,
int ctrl_num, int ctrl_val,
int ctrl_state);

@ -76,12 +76,12 @@ extern urj_error_state_t urj_error_state;
/**
* The top of the error stack. The caller must not modify the returned struct.
*/
const urj_error_state_t *urj_error_get(void);
const urj_error_state_t *urj_error_get (void);
/**
* Pop the top off the error stack.
* @return #URJ_ERROR_OK if the bottom of the error stack is reached
*/
urj_error_t urj_error_get_reset(void);
urj_error_t urj_error_get_reset (void);
/**
* The top of the error state in human-readable form.
*
@ -89,6 +89,6 @@ urj_error_t urj_error_get_reset(void);
*
* @return a pointer to a static area.
*/
const char *urj_error_describe(void);
const char *urj_error_describe (void);
#endif /* URJ_ERROR_H */

@ -28,7 +28,10 @@
#include <stdio.h>
#include <string.h>
#include <urjtag/error.h>
#include <urjtag/bsbit.h>
#include <urjtag/part.h>
#include <urjtag/chain.h>
#include <urjtag/cmd.h>
@ -52,12 +55,12 @@ cmd_bit_print_params (char *params[], unsigned int parameters, char *command,
static int
cmd_bit_run (urj_chain_t *chain, char *params[])
{
urj_part_t *part;
unsigned int bit;
int type;
int safe;
unsigned int control;
unsigned int parameters = urj_cmd_params (params);
urj_bsbit_t *bsbit;
char command[1024];
cmd_bit_print_params (params, parameters, command, sizeof command);
@ -76,6 +79,12 @@ cmd_bit_run (urj_chain_t *chain, char *params[])
return 1;
}
part = urj_tap_chain_active_part (chain);
if (part == NULL)
{
return 1;
}
/* bit number */
if (urj_cmd_get_number (params[1], &bit))
{
@ -129,10 +138,13 @@ cmd_bit_run (urj_chain_t *chain, char *params[])
/* test for control bit */
if (urj_cmd_params (params) == 5) {
bsbit = urj_part_bsbit_alloc (chain, bit, params[4], type, safe);
if (bsbit == NULL)
part->bsbits[bit] = urj_part_bsbit_alloc (part, bit, params[4], type,
safe);
if (part->bsbits[bit] == NULL)
{
return -1;
printf ("%s for command '%s'\n", urj_error_describe(), command);
urj_error_get_reset();
return 1;
}
} else {
@ -161,12 +173,15 @@ cmd_bit_run (urj_chain_t *chain, char *params[])
control_state = URJ_BSBIT_STATE_Z;
bsbit = urj_part_bsbit_alloc_control (chain, bit, params[4], type, safe,
control, control_value,
control_state);
if (bsbit == NULL)
part->bsbits[bit] = urj_part_bsbit_alloc_control (part, bit, params[4],
type, safe, control,
control_value,
control_state);
if (part->bsbits[bit] == NULL)
{
return -1;
printf ("%s for command '%s'\n", urj_error_describe(), command);
urj_error_get_reset();
return 1;
}
}

@ -27,6 +27,7 @@
#include <stdio.h>
#include <string.h>
#include <urjtag/error.h>
#include <urjtag/chain.h>
#include <urjtag/bus.h>
@ -54,7 +55,11 @@ cmd_bus_run (urj_chain_t *chain, char *params[])
if (urj_cmd_get_number (params[1], &n))
return -1;
(void)urj_bus_buses_set(n);
if (urj_bus_buses_set (n) != URJ_STATUS_OK)
{
printf ("%s\n", urj_error_describe());
urj_error_get_reset();
}
return 1;
}

@ -28,6 +28,7 @@
#include <string.h>
#include <urjtag/tap.h>
#include <urjtag/error.h>
#include <urjtag/cmd.h>
@ -44,6 +45,8 @@ cmd_detect_run (urj_chain_t *chain, char *params[])
if (urj_tap_detect (chain) != URJ_STATUS_OK)
{
printf ("%s\n", urj_error_describe());
urj_error_get_reset();
return -1;
}

@ -27,6 +27,7 @@
#include <stdio.h>
#include <string.h>
#include <urjtag/error.h>
#include <urjtag/part.h>
#include <urjtag/chain.h>
@ -65,7 +66,12 @@ cmd_instruction_run (urj_chain_t *chain, char *params[])
if (urj_cmd_get_number (params[2], &len))
return -1;
return urj_part_instruction_length_set (part, len);
if (urj_part_instruction_length_set (part, len) != URJ_STATUS_OK)
{
printf ("%s\n", urj_error_describe());
urj_error_get_reset();
}
return 1;
}
if (urj_cmd_params (params) == 4)
@ -75,6 +81,8 @@ cmd_instruction_run (urj_chain_t *chain, char *params[])
i = urj_part_instruction_define (part, params[1], params[2], params[3]);
if (!i)
{
printf ("%s\n", urj_error_describe());
urj_error_get_reset();
return 1;
}

@ -28,6 +28,7 @@
#include <stdlib.h>
#include <string.h>
#include <urjtag/error.h>
#include <urjtag/chain.h>
#include <urjtag/part.h>
#include <urjtag/bssignal.h>
@ -59,7 +60,12 @@ cmd_signal_run (urj_chain_t *chain, char *params[])
{
printf ("Defining pin for signal %s\n", s->name);
return urj_part_signal_redefine_pin(chain, s, params[2]);
if (urj_part_signal_redefine_pin(chain, s, params[2]) != URJ_STATUS_OK)
{
printf ("%s\n", urj_error_describe());
urj_error_get_reset();
}
return 1;
}
else
{
@ -77,6 +83,8 @@ cmd_signal_run (urj_chain_t *chain, char *params[])
s = urj_part_signal_define(chain, params[1]);
}
if (s == NULL) {
printf ("%s\n", urj_error_describe());
urj_error_get_reset();
return 1;
}

@ -29,3 +29,33 @@
urj_error_state_t urj_error_state;
int urj_debug_mode = 0;
int urj_big_endian = 0;
const urj_error_state_t *
urj_error_get (void)
{
return &urj_error_state;
}
urj_error_t
urj_error_get_reset (void)
{
urj_error_t e = urj_error_state.errnum;
urj_error_state.errnum = URJ_ERROR_OK;
return e;
}
const char *
urj_error_describe (void)
{
static char msg[URJ_ERROR_MSG_LEN + 1024 + 256 + 20];
snprintf (msg, sizeof msg, "%s:%d %s(): %s", urj_error_state.file,
urj_error_state.line, urj_error_state.function,
urj_error_state.msg);
return msg;
}

@ -35,28 +35,14 @@
#include <urjtag/bsbit.h>
urj_bsbit_t *
urj_part_bsbit_alloc_control (urj_chain_t *chain, int bit, const char *name,
urj_part_bsbit_alloc_control (urj_part_t *part, int bit, const char *name,
int type, int safe,
int ctrl_num, int ctrl_val, int ctrl_state)
{
urj_bsbit_t *b;
urj_part_t *part;
urj_data_register_t *bsr;
urj_part_signal_t *signal;
if (!chain->parts)
{
urj_error_set (URJ_ERROR_NO_ACTIVE_PART, _("Run \"detect\" first.\n"));
return NULL;
}
if (chain->active_part >= chain->parts->len)
{
urj_error_set (URJ_ERROR_NO_ACTIVE_PART,
_("%s: no active part\n"), "signal");
return NULL;
}
part = chain->parts->parts[chain->active_part];
bsr = urj_part_find_data_register (part, "BSR");
if (bsr == NULL)
{
@ -125,21 +111,21 @@ urj_part_bsbit_alloc_control (urj_chain_t *chain, int bit, const char *name,
urj_error_set(URJ_ERROR_INVALID, _("invalid control bit number\n"));
return NULL;
}
part->bsbits[bit]->control = ctrl_num;
part->bsbits[bit]->control_value = ctrl_val;
part->bsbits[bit]->control_state = URJ_BSBIT_STATE_Z;
b->control = ctrl_num;
b->control_value = ctrl_val;
b->control_state = URJ_BSBIT_STATE_Z;
}
return b;
}
urj_bsbit_t *
urj_part_bsbit_alloc (urj_chain_t *chain, int bit, const char *name, int type,
urj_part_bsbit_alloc (urj_part_t *part, int bit, const char *name, int type,
int safe)
{
urj_bsbit_t *b;
b = urj_part_bsbit_alloc_control (chain, bit, name, type, safe, -1, -1, -1);
b = urj_part_bsbit_alloc_control (part, bit, name, type, safe, -1, -1, -1);
return b;
}

@ -294,7 +294,7 @@ urj_part_instruction_length_set (urj_part_t *part, int length)
if (part->instructions != NULL)
{
urj_error_set (URJ_ERROR_ALREADY,
_("instruction length is already set and used\n"));
_("instruction length is already set and used"));
return URJ_STATUS_FAIL;
}
@ -314,14 +314,14 @@ urj_part_instruction_define (urj_part_t *part, const char *instruction,
if (strlen (code) != part->instruction_length)
{
urj_error_set (URJ_ERROR_INVALID,
_("invalid instruction length\n"));
_("invalid instruction length"));
return NULL;
}
if (urj_part_find_instruction (part, instruction) != NULL)
{
urj_error_set (URJ_ERROR_ALREADY,
_("Instruction '%s' already defined\n"), instruction);
_("Instruction '%s' already defined"), instruction);
return NULL;
}
@ -329,7 +329,7 @@ urj_part_instruction_define (urj_part_t *part, const char *instruction,
if (dr == NULL)
{
urj_error_set(URJ_ERROR_NOTFOUND,
_("unknown data register '%s'\n"), data_register);
_("unknown data register '%s'"), data_register);
return NULL;
}

@ -24,6 +24,8 @@
#include <urjtag/sysdep.h>
#include <stddef.h>
#include <urjtag/parport.h>
extern urj_parport_driver_t urj_tap_parport_direct_parport_driver;

@ -25,6 +25,7 @@
#include <urjtag/sysdep.h>
#include <strings.h>
#include <stddef.h>
#include <urjtag/usbconn.h>

Loading…
Cancel
Save