The code in jtag.c currently manipulates the command queue pointers
directly in every function. This increases potential for errors and
makes the code less readable by distracting the reader from the core
algorithm contained in every function.
This patch removes the (repetitive) direct command queue manipulation
from the functions in jtag and packs it into a function called
jtag_queue_command().
The main change looks like this:
- jtag_command_t **last_cmd;
- last_cmd = jtag_get_last_command_p();
-
- *last_cmd = cmd_queue_alloc(sizeof(jtag_command_t));
- (*last_cmd)->next = NULL;
- last_comand_pointer = &((*last_cmd)->next);
- (*last_cmd)->type = JTAG_SCAN;
+ jtag_command_t * cmd = cmd_queue_alloc(sizeof(jtag_command_t));
+
+ jtag_queue_command(cmd);
+
+ cmd->type = JTAG_SCAN;
Patch 1 adds jtag_queue_command()
Patches 2-7 rewrite the functions in jtag.c to use jtag_queue_command()
They can be applied in any order. 2-6 are larger functions, 7 includes
all the remaining short functions
Patch 8 rewrites the direct jtag queue manipulation in svf/svf.c to
use jtag_queue_command()
Patch 9 can only be applied after 1-8 were applied. It changes
last_comand_pointer to last_command_pointer.
The patches should not change any algorithms.
Michael
diff --git a/src/jtag/jtag.c b/src/jtag/jtag.c
index dd3cbf2..0777a3a 100644
--- a/src/jtag/jtag.c
+++ b/src/jtag/jtag.c
@@ -439,6 +439,21 @@ jtag_command_t** jtag_get_last_command_p(void)
return last_comand_pointer;
}
+
+void jtag_queue_command(jtag_command_t * cmd)
+{
+ jtag_command_t **last_cmd;
+
+ last_cmd = jtag_get_last_command_p();
+
+ *last_cmd = cmd;
+
+ (*last_cmd)->next = NULL;
+
+ last_comand_pointer = &((*last_cmd)->next);
+}
+
+
void* cmd_queue_alloc(size_t size)
{
cmd_queue_page_t **p_page = &cmd_queue_pages;
diff --git a/src/jtag/jtag.c b/src/jtag/jtag.c
index 0777a3a..0a0153d 100644
--- a/src/jtag/jtag.c
+++ b/src/jtag/jtag.c
@@ -590,28 +590,26 @@ void jtag_add_ir_scan(int num_fields, scan_field_t
*fields, tap_state_t state)
int MINIDRIVER(interface_jtag_add_ir_scan)(int num_fields, scan_field_t
*fields, tap_state_t state)
{
- jtag_command_t **last_cmd;
jtag_tap_t *tap;
int j;
int x;
int nth_tap;
int scan_size = 0;
- last_cmd = jtag_get_last_command_p();
-
/* allocate memory for a new list member */
- *last_cmd = cmd_queue_alloc(sizeof(jtag_command_t));
- (*last_cmd)->next = NULL;
- last_comand_pointer = &((*last_cmd)->next);
- (*last_cmd)->type = JTAG_SCAN;
+ jtag_command_t * cmd = cmd_queue_alloc(sizeof(jtag_command_t));
+
+ jtag_queue_command(cmd);
+
+ cmd->type = JTAG_SCAN;
/* allocate memory for ir scan command */
- (*last_cmd)->cmd.scan = cmd_queue_alloc(sizeof(scan_command_t));
- (*last_cmd)->cmd.scan->ir_scan = true;
+ cmd->cmd.scan = cmd_queue_alloc(sizeof(scan_command_t));
+ cmd->cmd.scan->ir_scan = true;
x = jtag_NumEnabledTaps();
- (*last_cmd)->cmd.scan->num_fields = x; /* one field per device */
- (*last_cmd)->cmd.scan->fields = cmd_queue_alloc(x *
sizeof(scan_field_t));
- (*last_cmd)->cmd.scan->end_state = state;
+ cmd->cmd.scan->num_fields = x; /* one field per device */
+ cmd->cmd.scan->fields = cmd_queue_alloc(x * sizeof(scan_field_t));
+ cmd->cmd.scan->end_state = state;
nth_tap = -1;
tap = NULL;
@@ -628,9 +626,9 @@ int MINIDRIVER(interface_jtag_add_ir_scan)(int num_fields,
scan_field_t *fields,
assert(nth_tap < x );
scan_size = tap->ir_length;
- (*last_cmd)->cmd.scan->fields[nth_tap].tap = tap;
- (*last_cmd)->cmd.scan->fields[nth_tap].num_bits = scan_size;
- (*last_cmd)->cmd.scan->fields[nth_tap].in_value = NULL; /* do
not collect input for tap's in bypass */
+ cmd->cmd.scan->fields[nth_tap].tap = tap;
+ cmd->cmd.scan->fields[nth_tap].num_bits = scan_size;
+ cmd->cmd.scan->fields[nth_tap].in_value = NULL; /* do not
collect input for tap's in bypass */
/* search the list */
for (j = 0; j < num_fields; j++)
@@ -638,8 +636,8 @@ int MINIDRIVER(interface_jtag_add_ir_scan)(int num_fields,
scan_field_t *fields,
if (tap == fields[j].tap)
{
found = 1;
- (*last_cmd)->cmd.scan->fields[nth_tap].in_value
= fields[j].in_value;
-
(*last_cmd)->cmd.scan->fields[nth_tap].out_value = buf_cpy(fields[j].out_value,
cmd_queue_alloc(CEIL(scan_size, 8)), scan_size);
+ cmd->cmd.scan->fields[nth_tap].in_value =
fields[j].in_value;
+ cmd->cmd.scan->fields[nth_tap].out_value =
buf_cpy(fields[j].out_value, cmd_queue_alloc(CEIL(scan_size, 8)), scan_size);
tap->bypass = 0;
break;
@@ -649,12 +647,12 @@ int MINIDRIVER(interface_jtag_add_ir_scan)(int
num_fields, scan_field_t *fields,
if (!found)
{
/* if a tap isn't listed, set it to BYPASS */
- (*last_cmd)->cmd.scan->fields[nth_tap].out_value =
buf_set_ones(cmd_queue_alloc(CEIL(scan_size, 8)), scan_size);
+ cmd->cmd.scan->fields[nth_tap].out_value =
buf_set_ones(cmd_queue_alloc(CEIL(scan_size, 8)), scan_size);
tap->bypass = 1;
}
/* update device information */
- buf_cpy((*last_cmd)->cmd.scan->fields[nth_tap].out_value,
tap->cur_instr, scan_size);
+ buf_cpy(cmd->cmd.scan->fields[nth_tap].out_value,
tap->cur_instr, scan_size);
}
assert(nth_tap == (x-1));
diff --git a/src/jtag/jtag.c b/src/jtag/jtag.c
index 0a0153d..b0eb994 100644
--- a/src/jtag/jtag.c
+++ b/src/jtag/jtag.c
@@ -672,32 +672,31 @@ void jtag_add_plain_ir_scan(int num_fields, scan_field_t
*fields, tap_state_t st
int MINIDRIVER(interface_jtag_add_plain_ir_scan)(int num_fields, scan_field_t
*fields, tap_state_t state)
{
- int i;
- jtag_command_t **last_cmd;
+ /* allocate memory for a new list member */
- last_cmd = jtag_get_last_command_p();
+ jtag_command_t * cmd = cmd_queue_alloc(sizeof(jtag_command_t));
+
+ jtag_queue_command(cmd);
- /* allocate memory for a new list member */
- *last_cmd = cmd_queue_alloc(sizeof(jtag_command_t));
- (*last_cmd)->next = NULL;
- last_comand_pointer = &((*last_cmd)->next);
- (*last_cmd)->type = JTAG_SCAN;
+ cmd->type = JTAG_SCAN;
/* allocate memory for ir scan command */
- (*last_cmd)->cmd.scan = cmd_queue_alloc(sizeof(scan_command_t));
- (*last_cmd)->cmd.scan->ir_scan = true;
- (*last_cmd)->cmd.scan->num_fields = num_fields;
- (*last_cmd)->cmd.scan->fields = cmd_queue_alloc(num_fields *
sizeof(scan_field_t));
- (*last_cmd)->cmd.scan->end_state = state;
+ cmd->cmd.scan = cmd_queue_alloc(sizeof(scan_command_t));
+ cmd->cmd.scan->ir_scan = true;
+ cmd->cmd.scan->num_fields = num_fields;
+ cmd->cmd.scan->fields = cmd_queue_alloc(num_fields *
sizeof(scan_field_t));
+ cmd->cmd.scan->end_state = state;
- for( i = 0 ; i < num_fields ; i++ ){
+ for (int i = 0; i < num_fields; i++)
+ {
int num_bits = fields[i].num_bits;
int num_bytes = CEIL(fields[i].num_bits, 8);
- (*last_cmd)->cmd.scan->fields[i].tap = fields[i].tap;
- (*last_cmd)->cmd.scan->fields[i].num_bits = num_bits;
- (*last_cmd)->cmd.scan->fields[i].out_value =
buf_cpy(fields[i].out_value, cmd_queue_alloc(num_bytes), num_bits);
- (*last_cmd)->cmd.scan->fields[i].in_value = fields[i].in_value;
+ cmd->cmd.scan->fields[i].tap = fields[i].tap;
+ cmd->cmd.scan->fields[i].num_bits = num_bits;
+ cmd->cmd.scan->fields[i].out_value =
buf_cpy(fields[i].out_value, cmd_queue_alloc(num_bytes), num_bits);
+ cmd->cmd.scan->fields[i].in_value = fields[i].in_value;
}
+
return ERROR_OK;
}
diff --git a/src/jtag/jtag.c b/src/jtag/jtag.c
index b0eb994..f30af81 100644
--- a/src/jtag/jtag.c
+++ b/src/jtag/jtag.c
@@ -785,7 +785,6 @@ int MINIDRIVER(interface_jtag_add_dr_scan)(int num_fields,
scan_field_t *fields,
int field_count = 0;
int scan_size;
- jtag_command_t **last_cmd = jtag_get_last_command_p();
jtag_tap_t *tap;
/* count devices in bypass */
@@ -802,17 +801,19 @@ int MINIDRIVER(interface_jtag_add_dr_scan)(int
num_fields, scan_field_t *fields,
}
/* allocate memory for a new list member */
- *last_cmd = cmd_queue_alloc(sizeof(jtag_command_t));
- last_comand_pointer = &((*last_cmd)->next);
- (*last_cmd)->next = NULL;
- (*last_cmd)->type = JTAG_SCAN;
+
+ jtag_command_t * cmd = cmd_queue_alloc(sizeof(jtag_command_t));
+
+ jtag_queue_command(cmd);
+
+ cmd->type = JTAG_SCAN;
/* allocate memory for dr scan command */
- (*last_cmd)->cmd.scan = cmd_queue_alloc(sizeof(scan_command_t));
- (*last_cmd)->cmd.scan->ir_scan = false;
- (*last_cmd)->cmd.scan->num_fields = num_fields + bypass_devices;
- (*last_cmd)->cmd.scan->fields = cmd_queue_alloc((num_fields +
bypass_devices) * sizeof(scan_field_t));
- (*last_cmd)->cmd.scan->end_state = state;
+ cmd->cmd.scan = cmd_queue_alloc(sizeof(scan_command_t));
+ cmd->cmd.scan->ir_scan = false;
+ cmd->cmd.scan->num_fields = num_fields + bypass_devices;
+ cmd->cmd.scan->fields = cmd_queue_alloc((num_fields + bypass_devices) *
sizeof(scan_field_t));
+ cmd->cmd.scan->end_state = state;
tap = NULL;
nth_tap = -1;
@@ -823,7 +824,7 @@ int MINIDRIVER(interface_jtag_add_dr_scan)(int num_fields,
scan_field_t *fields,
break;
}
int found = 0;
- (*last_cmd)->cmd.scan->fields[field_count].tap = tap;
+ cmd->cmd.scan->fields[field_count].tap = tap;
for (j = 0; j < num_fields; j++)
{
@@ -831,9 +832,9 @@ int MINIDRIVER(interface_jtag_add_dr_scan)(int num_fields,
scan_field_t *fields,
{
found = 1;
scan_size = fields[j].num_bits;
-
(*last_cmd)->cmd.scan->fields[field_count].num_bits = scan_size;
-
(*last_cmd)->cmd.scan->fields[field_count].out_value =
buf_cpy(fields[j].out_value, cmd_queue_alloc(CEIL(scan_size, 8)), scan_size);
-
(*last_cmd)->cmd.scan->fields[field_count].in_value = fields[j].in_value;
+ cmd->cmd.scan->fields[field_count].num_bits =
scan_size;
+ cmd->cmd.scan->fields[field_count].out_value =
buf_cpy(fields[j].out_value, cmd_queue_alloc(CEIL(scan_size, 8)), scan_size);
+ cmd->cmd.scan->fields[field_count].in_value =
fields[j].in_value;
field_count++;
}
}
@@ -848,9 +849,9 @@ int MINIDRIVER(interface_jtag_add_dr_scan)(int num_fields,
scan_field_t *fields,
}
#endif
/* program the scan field to 1 bit length, and ignore
it's value */
- (*last_cmd)->cmd.scan->fields[field_count].num_bits = 1;
- (*last_cmd)->cmd.scan->fields[field_count].out_value =
NULL;
- (*last_cmd)->cmd.scan->fields[field_count].in_value =
NULL;
+ cmd->cmd.scan->fields[field_count].num_bits = 1;
+ cmd->cmd.scan->fields[field_count].out_value = NULL;
+ cmd->cmd.scan->fields[field_count].in_value = NULL;
field_count++;
}
else
diff --git a/src/jtag/jtag.c b/src/jtag/jtag.c
index f30af81..eacecf8 100644
--- a/src/jtag/jtag.c
+++ b/src/jtag/jtag.c
@@ -880,7 +880,6 @@ void MINIDRIVER(interface_jtag_add_dr_out)(jtag_tap_t
*target_tap,
int scan_size;
int bypass_devices = 0;
- jtag_command_t **last_cmd = jtag_get_last_command_p();
jtag_tap_t *tap;
/* count devices in bypass */
@@ -897,17 +896,18 @@ void MINIDRIVER(interface_jtag_add_dr_out)(jtag_tap_t
*target_tap,
}
/* allocate memory for a new list member */
- *last_cmd = cmd_queue_alloc(sizeof(jtag_command_t));
- last_comand_pointer = &((*last_cmd)->next);
- (*last_cmd)->next = NULL;
- (*last_cmd)->type = JTAG_SCAN;
+ jtag_command_t * cmd = cmd_queue_alloc(sizeof(jtag_command_t));
+
+ jtag_queue_command(cmd);
+
+ cmd->type = JTAG_SCAN;
/* allocate memory for dr scan command */
- (*last_cmd)->cmd.scan = cmd_queue_alloc(sizeof(scan_command_t));
- (*last_cmd)->cmd.scan->ir_scan = false;
- (*last_cmd)->cmd.scan->num_fields = num_fields + bypass_devices;
- (*last_cmd)->cmd.scan->fields = cmd_queue_alloc((num_fields +
bypass_devices) * sizeof(scan_field_t));
- (*last_cmd)->cmd.scan->end_state = end_state;
+ cmd->cmd.scan = cmd_queue_alloc(sizeof(scan_command_t));
+ cmd->cmd.scan->ir_scan = false;
+ cmd->cmd.scan->num_fields = num_fields + bypass_devices;
+ cmd->cmd.scan->fields = cmd_queue_alloc((num_fields + bypass_devices) *
sizeof(scan_field_t));
+ cmd->cmd.scan->end_state = end_state;
tap = NULL;
nth_tap = -1;
@@ -917,7 +917,7 @@ void MINIDRIVER(interface_jtag_add_dr_out)(jtag_tap_t
*target_tap,
break;
}
nth_tap++;
- (*last_cmd)->cmd.scan->fields[field_count].tap = tap;
+ cmd->cmd.scan->fields[field_count].tap = tap;
if (tap == target_tap)
{
@@ -935,9 +935,9 @@ void MINIDRIVER(interface_jtag_add_dr_out)(jtag_tap_t
*target_tap,
u8 out_value[4];
scan_size = num_bits[j];
buf_set_u32(out_value, 0, scan_size, value[j]);
-
(*last_cmd)->cmd.scan->fields[field_count].num_bits = scan_size;
-
(*last_cmd)->cmd.scan->fields[field_count].out_value = buf_cpy(out_value,
cmd_queue_alloc(CEIL(scan_size, 8)), scan_size);
-
(*last_cmd)->cmd.scan->fields[field_count].in_value = NULL;
+ cmd->cmd.scan->fields[field_count].num_bits =
scan_size;
+ cmd->cmd.scan->fields[field_count].out_value =
buf_cpy(out_value, cmd_queue_alloc(CEIL(scan_size, 8)), scan_size);
+ cmd->cmd.scan->fields[field_count].in_value =
NULL;
field_count++;
}
} else
@@ -951,9 +951,9 @@ void MINIDRIVER(interface_jtag_add_dr_out)(jtag_tap_t
*target_tap,
}
#endif
/* program the scan field to 1 bit length, and ignore
it's value */
- (*last_cmd)->cmd.scan->fields[field_count].num_bits = 1;
- (*last_cmd)->cmd.scan->fields[field_count].out_value =
NULL;
- (*last_cmd)->cmd.scan->fields[field_count].in_value =
NULL;
+ cmd->cmd.scan->fields[field_count].num_bits = 1;
+ cmd->cmd.scan->fields[field_count].out_value = NULL;
+ cmd->cmd.scan->fields[field_count].in_value = NULL;
field_count++;
}
}
diff --git a/src/jtag/jtag.c b/src/jtag/jtag.c
index eacecf8..83ea50e 100644
--- a/src/jtag/jtag.c
+++ b/src/jtag/jtag.c
@@ -972,30 +972,28 @@ void jtag_add_plain_dr_scan(int num_fields, scan_field_t
*fields, tap_state_t st
int MINIDRIVER(interface_jtag_add_plain_dr_scan)(int num_fields, scan_field_t
*fields, tap_state_t state)
{
- int i;
- jtag_command_t **last_cmd = jtag_get_last_command_p();
-
/* allocate memory for a new list member */
- *last_cmd = cmd_queue_alloc(sizeof(jtag_command_t));
- last_comand_pointer = &((*last_cmd)->next);
- (*last_cmd)->next = NULL;
- (*last_cmd)->type = JTAG_SCAN;
+ jtag_command_t * cmd = cmd_queue_alloc(sizeof(jtag_command_t));
+
+ jtag_queue_command(cmd);
+
+ cmd->type = JTAG_SCAN;
/* allocate memory for scan command */
- (*last_cmd)->cmd.scan = cmd_queue_alloc(sizeof(scan_command_t));
- (*last_cmd)->cmd.scan->ir_scan = false;
- (*last_cmd)->cmd.scan->num_fields = num_fields;
- (*last_cmd)->cmd.scan->fields = cmd_queue_alloc(num_fields *
sizeof(scan_field_t));
- (*last_cmd)->cmd.scan->end_state = state;
+ cmd->cmd.scan = cmd_queue_alloc(sizeof(scan_command_t));
+ cmd->cmd.scan->ir_scan = false;
+ cmd->cmd.scan->num_fields = num_fields;
+ cmd->cmd.scan->fields = cmd_queue_alloc(num_fields *
sizeof(scan_field_t));
+ cmd->cmd.scan->end_state = state;
- for (i = 0; i < num_fields; i++)
+ for (int i = 0; i < num_fields; i++)
{
int num_bits = fields[i].num_bits;
int num_bytes = CEIL(fields[i].num_bits, 8);
- (*last_cmd)->cmd.scan->fields[i].tap = fields[i].tap;
- (*last_cmd)->cmd.scan->fields[i].num_bits = num_bits;
- (*last_cmd)->cmd.scan->fields[i].out_value =
buf_cpy(fields[i].out_value, cmd_queue_alloc(num_bytes), num_bits);
- (*last_cmd)->cmd.scan->fields[i].in_value = fields[i].in_value;
+ cmd->cmd.scan->fields[i].tap = fields[i].tap;
+ cmd->cmd.scan->fields[i].num_bits = num_bits;
+ cmd->cmd.scan->fields[i].out_value =
buf_cpy(fields[i].out_value, cmd_queue_alloc(num_bytes), num_bits);
+ cmd->cmd.scan->fields[i].in_value = fields[i].in_value;
}
return ERROR_OK;
diff --git a/src/jtag/jtag.c b/src/jtag/jtag.c
index 83ea50e..96b1c68 100644
--- a/src/jtag/jtag.c
+++ b/src/jtag/jtag.c
@@ -1012,16 +1012,16 @@ void jtag_add_tlr(void)
int MINIDRIVER(interface_jtag_add_tlr)(void)
{
tap_state_t state = TAP_RESET;
- jtag_command_t **last_cmd = jtag_get_last_command_p();
/* allocate memory for a new list member */
- *last_cmd = cmd_queue_alloc(sizeof(jtag_command_t));
- last_comand_pointer = &((*last_cmd)->next);
- (*last_cmd)->next = NULL;
- (*last_cmd)->type = JTAG_STATEMOVE;
+ jtag_command_t * cmd = cmd_queue_alloc(sizeof(jtag_command_t));
+
+ jtag_queue_command(cmd);
+
+ cmd->type = JTAG_STATEMOVE;
- (*last_cmd)->cmd.statemove =
cmd_queue_alloc(sizeof(statemove_command_t));
- (*last_cmd)->cmd.statemove->end_state = state;
+ cmd->cmd.statemove = cmd_queue_alloc(sizeof(statemove_command_t));
+ cmd->cmd.statemove->end_state = state;
return ERROR_OK;
}
@@ -1066,38 +1066,35 @@ void jtag_add_pathmove(int num_states, tap_state_t
*path)
int MINIDRIVER(interface_jtag_add_pathmove)(int num_states, tap_state_t *path)
{
- jtag_command_t **last_cmd = jtag_get_last_command_p();
- int i;
-
/* allocate memory for a new list member */
- *last_cmd = cmd_queue_alloc(sizeof(jtag_command_t));
- last_comand_pointer = &((*last_cmd)->next);
- (*last_cmd)->next = NULL;
- (*last_cmd)->type = JTAG_PATHMOVE;
+ jtag_command_t * cmd = cmd_queue_alloc(sizeof(jtag_command_t));
- (*last_cmd)->cmd.pathmove = cmd_queue_alloc(sizeof(pathmove_command_t));
- (*last_cmd)->cmd.pathmove->num_states = num_states;
- (*last_cmd)->cmd.pathmove->path = cmd_queue_alloc(sizeof(tap_state_t) *
num_states);
+ jtag_queue_command(cmd);
+
+ cmd->type = JTAG_PATHMOVE;
+
+ cmd->cmd.pathmove = cmd_queue_alloc(sizeof(pathmove_command_t));
+ cmd->cmd.pathmove->num_states = num_states;
+ cmd->cmd.pathmove->path = cmd_queue_alloc(sizeof(tap_state_t) *
num_states);
- for (i = 0; i < num_states; i++)
- (*last_cmd)->cmd.pathmove->path[i] = path[i];
+ for (int i = 0; i < num_states; i++)
+ cmd->cmd.pathmove->path[i] = path[i];
return ERROR_OK;
}
int MINIDRIVER(interface_jtag_add_runtest)(int num_cycles, tap_state_t state)
{
- jtag_command_t **last_cmd = jtag_get_last_command_p();
-
/* allocate memory for a new list member */
- *last_cmd = cmd_queue_alloc(sizeof(jtag_command_t));
- (*last_cmd)->next = NULL;
- last_comand_pointer = &((*last_cmd)->next);
- (*last_cmd)->type = JTAG_RUNTEST;
+ jtag_command_t * cmd = cmd_queue_alloc(sizeof(jtag_command_t));
+
+ jtag_queue_command(cmd);
- (*last_cmd)->cmd.runtest = cmd_queue_alloc(sizeof(runtest_command_t));
- (*last_cmd)->cmd.runtest->num_cycles = num_cycles;
- (*last_cmd)->cmd.runtest->end_state = state;
+ cmd->type = JTAG_RUNTEST;
+
+ cmd->cmd.runtest = cmd_queue_alloc(sizeof(runtest_command_t));
+ cmd->cmd.runtest->num_cycles = num_cycles;
+ cmd->cmd.runtest->end_state = state;
return ERROR_OK;
}
@@ -1117,16 +1114,16 @@ void jtag_add_runtest(int num_cycles, tap_state_t state)
int MINIDRIVER(interface_jtag_add_clocks)( int num_cycles )
{
- jtag_command_t **last_cmd = jtag_get_last_command_p();
-
/* allocate memory for a new list member */
- *last_cmd = cmd_queue_alloc(sizeof(jtag_command_t));
- (*last_cmd)->next = NULL;
- last_comand_pointer = &((*last_cmd)->next);
- (*last_cmd)->type = JTAG_STABLECLOCKS;
+ jtag_command_t * cmd = cmd_queue_alloc(sizeof(jtag_command_t));
+
+ jtag_queue_command(cmd);
+
+ cmd->type = JTAG_STABLECLOCKS;
+
+ cmd->cmd.stableclocks = cmd_queue_alloc(sizeof(stableclocks_command_t));
+ cmd->cmd.stableclocks->num_cycles = num_cycles;
- (*last_cmd)->cmd.stableclocks =
cmd_queue_alloc(sizeof(stableclocks_command_t));
- (*last_cmd)->cmd.stableclocks->num_cycles = num_cycles;
return ERROR_OK;
}
@@ -1257,17 +1254,16 @@ void jtag_add_reset(int req_tlr_or_trst, int req_srst)
int MINIDRIVER(interface_jtag_add_reset)(int req_trst, int req_srst)
{
- jtag_command_t **last_cmd = jtag_get_last_command_p();
-
/* allocate memory for a new list member */
- *last_cmd = cmd_queue_alloc(sizeof(jtag_command_t));
- (*last_cmd)->next = NULL;
- last_comand_pointer = &((*last_cmd)->next);
- (*last_cmd)->type = JTAG_RESET;
+ jtag_command_t * cmd = cmd_queue_alloc(sizeof(jtag_command_t));
- (*last_cmd)->cmd.reset = cmd_queue_alloc(sizeof(reset_command_t));
- (*last_cmd)->cmd.reset->trst = req_trst;
- (*last_cmd)->cmd.reset->srst = req_srst;
+ jtag_queue_command(cmd);
+
+ cmd->type = JTAG_RESET;
+
+ cmd->cmd.reset = cmd_queue_alloc(sizeof(reset_command_t));
+ cmd->cmd.reset->trst = req_trst;
+ cmd->cmd.reset->srst = req_srst;
return ERROR_OK;
}
@@ -1283,16 +1279,15 @@ void jtag_add_end_state(tap_state_t state)
int MINIDRIVER(interface_jtag_add_sleep)(u32 us)
{
- jtag_command_t **last_cmd = jtag_get_last_command_p();
-
/* allocate memory for a new list member */
- *last_cmd = cmd_queue_alloc(sizeof(jtag_command_t));
- (*last_cmd)->next = NULL;
- last_comand_pointer = &((*last_cmd)->next);
- (*last_cmd)->type = JTAG_SLEEP;
+ jtag_command_t * cmd = cmd_queue_alloc(sizeof(jtag_command_t));
+
+ jtag_queue_command(cmd);
+
+ cmd->type = JTAG_SLEEP;
- (*last_cmd)->cmd.sleep = cmd_queue_alloc(sizeof(sleep_command_t));
- (*last_cmd)->cmd.sleep->us = us;
+ cmd->cmd.sleep = cmd_queue_alloc(sizeof(sleep_command_t));
+ cmd->cmd.sleep->us = us;
return ERROR_OK;
}
diff --git a/src/svf/svf.c b/src/svf/svf.c
index a68cfae..1267755 100644
--- a/src/svf/svf.c
+++ b/src/svf/svf.c
@@ -695,9 +695,8 @@ static int svf_execute_tap(void)
}
// not good to use this
-extern jtag_command_t** jtag_get_last_command_p(void);
extern void* cmd_queue_alloc(size_t size);
-extern jtag_command_t **last_comand_pointer;
+extern void jtag_queue_command(jtag_command_t * cmd);
static int svf_run_command(struct command_context_s *cmd_ctx, char *cmd_str)
{
@@ -707,9 +706,6 @@ static int svf_run_command(struct command_context_s
*cmd_ctx, char *cmd_str)
// tmp variable
int i_tmp;
- // not good to use this
- jtag_command_t **last_cmd;
-
// for RUNTEST
int run_count;
float min_time, max_time;
@@ -1180,15 +1176,15 @@ static int svf_run_command(struct command_context_s
*cmd_ctx, char *cmd_str)
// enter into run_state if necessary
if (last_state != svf_para.runtest_run_state)
{
- last_cmd = jtag_get_last_command_p();
- *last_cmd =
cmd_queue_alloc(sizeof(jtag_command_t));
- last_comand_pointer =
&((*last_cmd)->next);
- (*last_cmd)->next = NULL;
- (*last_cmd)->type = JTAG_STATEMOVE;
- (*last_cmd)->cmd.statemove =
cmd_queue_alloc(sizeof(statemove_command_t));
- (*last_cmd)->cmd.statemove->end_state =
svf_para.runtest_run_state;
-
- cmd_queue_end_state =
cmd_queue_cur_state = (*last_cmd)->cmd.statemove->end_state;
+ jtag_command_t * cmd =
cmd_queue_alloc(sizeof(jtag_command_t));
+
+ jtag_queue_command(cmd);
+
+ cmd->type = JTAG_STATEMOVE;
+ cmd->cmd.statemove =
cmd_queue_alloc(sizeof(statemove_command_t));
+ cmd->cmd.statemove->end_state =
svf_para.runtest_run_state;
+
+ cmd_queue_end_state =
cmd_queue_cur_state = cmd->cmd.statemove->end_state;
}
// call jtag_add_clocks
@@ -1197,15 +1193,14 @@ static int svf_run_command(struct command_context_s
*cmd_ctx, char *cmd_str)
if (svf_para.runtest_end_state !=
svf_para.runtest_run_state)
{
// move to end_state
- last_cmd = jtag_get_last_command_p();
- *last_cmd =
cmd_queue_alloc(sizeof(jtag_command_t));
- last_comand_pointer =
&((*last_cmd)->next);
- (*last_cmd)->next = NULL;
- (*last_cmd)->type = JTAG_STATEMOVE;
- (*last_cmd)->cmd.statemove =
cmd_queue_alloc(sizeof(statemove_command_t));
- (*last_cmd)->cmd.statemove->end_state =
svf_para.runtest_end_state;
-
- cmd_queue_end_state =
cmd_queue_cur_state = (*last_cmd)->cmd.statemove->end_state;
+ jtag_command_t * cmd =
cmd_queue_alloc(sizeof(jtag_command_t));
+
+ jtag_queue_command(cmd);
+ cmd->type = JTAG_STATEMOVE;
+ cmd->cmd.statemove =
cmd_queue_alloc(sizeof(statemove_command_t));
+ cmd->cmd.statemove->end_state =
svf_para.runtest_end_state;
+
+ cmd_queue_end_state =
cmd_queue_cur_state = cmd->cmd.statemove->end_state;
}
last_state = svf_para.runtest_end_state;
#else
@@ -1294,15 +1289,15 @@ static int svf_run_command(struct command_context_s
*cmd_ctx, char *cmd_str)
if (svf_tap_state_is_stable(state))
{
// TODO: move to state
- last_cmd = jtag_get_last_command_p();
- *last_cmd =
cmd_queue_alloc(sizeof(jtag_command_t));
- last_comand_pointer = &((*last_cmd)->next);
- (*last_cmd)->next = NULL;
- (*last_cmd)->type = JTAG_STATEMOVE;
- (*last_cmd)->cmd.statemove =
cmd_queue_alloc(sizeof(statemove_command_t));
- (*last_cmd)->cmd.statemove->end_state = state;
-
- cmd_queue_end_state = cmd_queue_cur_state =
(*last_cmd)->cmd.statemove->end_state;
+ jtag_command_t * cmd =
cmd_queue_alloc(sizeof(jtag_command_t));
+
+ jtag_queue_command(cmd);
+
+ cmd->type = JTAG_STATEMOVE;
+ cmd->cmd.statemove =
cmd_queue_alloc(sizeof(statemove_command_t));
+ cmd->cmd.statemove->end_state = state;
+
+ cmd_queue_end_state = cmd_queue_cur_state =
cmd->cmd.statemove->end_state;
last_state = state;
LOG_DEBUG("\tmove to %s by state_move",
svf_tap_state_name[state]);
diff --git a/src/jtag/jtag.c b/src/jtag/jtag.c
index 96b1c68..2dde2d9 100644
--- a/src/jtag/jtag.c
+++ b/src/jtag/jtag.c
@@ -89,7 +89,7 @@ static struct jtag_callback_entry *jtag_callback_queue_tail =
NULL;
jtag_command_t *jtag_command_queue = NULL;
-jtag_command_t **last_comand_pointer = &jtag_command_queue;
+jtag_command_t **last_command_pointer = &jtag_command_queue;
static jtag_tap_t *jtag_all_taps = NULL;
enum reset_types jtag_reset_config = RESET_NONE;
@@ -436,7 +436,7 @@ jtag_command_t** jtag_get_last_command_p(void)
return &cmd->next;*/
- return last_comand_pointer;
+ return last_command_pointer;
}
@@ -450,7 +450,7 @@ void jtag_queue_command(jtag_command_t * cmd)
(*last_cmd)->next = NULL;
- last_comand_pointer = &((*last_cmd)->next);
+ last_command_pointer = &((*last_cmd)->next);
}
@@ -1554,7 +1554,7 @@ int interface_jtag_execute_queue(void)
jtag_callback_queue_tail = NULL;
jtag_command_queue = NULL;
- last_comand_pointer = &jtag_command_queue;
+ last_command_pointer = &jtag_command_queue;
return retval;
}
_______________________________________________
Openocd-development mailing list
[email protected]
https://lists.berlios.de/mailman/listinfo/openocd-development