📄 jbijtag.c
字号:
case DRSELECT:
case DRCAPTURE:
case DRSHIFT:
case DREXIT1:
case DRPAUSE:
case DREXIT2:
case DRUPDATE:
start_code = 1;
start_state = DRPAUSE;
break;
case IRSELECT:
case IRCAPTURE:
case IRSHIFT:
case IREXIT1:
case IRPAUSE:
case IREXIT2:
case IRUPDATE:
start_code = 2;
start_state = IRPAUSE;
break;
default:
status = JBIC_INTERNAL_ERROR;
break;
}
if (status == JBIC_SUCCESS)
{
if (jbi_jtag_state != start_state)
{
status = jbi_goto_jtag_state(start_state);
}
}
if (status == JBIC_SUCCESS)
{
if (jbi_workspace != NULL)
{
if (shift_count > JBIC_MAX_JTAG_IR_LENGTH)
{
status = JBIC_OUT_OF_MEMORY;
}
}
else if (shift_count > jbi_ir_length)
{
alloc_chars = (shift_count + 7) >> 3;
jbi_free(jbi_ir_buffer);
jbi_ir_buffer = (unsigned char *) jbi_malloc(alloc_chars);
if (jbi_ir_buffer == NULL)
{
status = JBIC_OUT_OF_MEMORY;
}
else
{
jbi_ir_length = alloc_chars * 8;
}
}
}
if (status == JBIC_SUCCESS)
{
/*
* Copy preamble data, IR data, and postamble data into a buffer
*/
jbi_jtag_concatenate_data
(
jbi_ir_buffer,
jbi_ir_preamble_data,
jbi_ir_preamble,
in_data,
in_index,
count,
jbi_ir_postamble_data,
jbi_ir_postamble
);
/*
* Do the IRSCAN
*/
jbi_jtag_irscan
(
start_code,
shift_count,
jbi_ir_buffer,
jbi_ir_buffer
);
/* jbi_jtag_irscan() always ends in IRPAUSE state */
jbi_jtag_state = IRPAUSE;
}
if (status == JBIC_SUCCESS)
{
if (jbi_irstop_state != IRPAUSE)
{
status = jbi_goto_jtag_state(jbi_irstop_state);
}
}
if (status == JBIC_SUCCESS)
{
/*
* Now extract the returned data from the buffer
*/
jbi_jtag_extract_target_data
(
jbi_ir_buffer,
out_data,
out_index,
jbi_ir_preamble,
count
);
}
return (status);
}
/****************************************************************************/
/* */
JBI_RETURN_TYPE jbi_do_drscan
(
unsigned int count,
unsigned char *tdi_data,
unsigned long start_index
)
/* */
/* Description: Shifts data into data register (ignoring output data) */
/* */
/* Returns: JBIC_SUCCESS for success, else appropriate error code */
/* */
/****************************************************************************/
{
int start_code = 0;
unsigned int alloc_chars = 0;
unsigned int shift_count = jbi_dr_preamble + count + jbi_dr_postamble;
JBI_RETURN_TYPE status = JBIC_SUCCESS;
JBIE_JTAG_STATE start_state = JBI_ILLEGAL_JTAG_STATE;
switch (jbi_jtag_state)
{
case JBI_ILLEGAL_JTAG_STATE:
case RESET:
case IDLE:
start_code = 0;
start_state = IDLE;
break;
case DRSELECT:
case DRCAPTURE:
case DRSHIFT:
case DREXIT1:
case DRPAUSE:
case DREXIT2:
case DRUPDATE:
start_code = 1;
start_state = DRPAUSE;
break;
case IRSELECT:
case IRCAPTURE:
case IRSHIFT:
case IREXIT1:
case IRPAUSE:
case IREXIT2:
case IRUPDATE:
start_code = 2;
start_state = IRPAUSE;
break;
default:
status = JBIC_INTERNAL_ERROR;
break;
}
if (status == JBIC_SUCCESS)
{
if (jbi_jtag_state != start_state)
{
status = jbi_goto_jtag_state(start_state);
}
}
if (status == JBIC_SUCCESS)
{
if (jbi_workspace != NULL)
{
if (shift_count > JBIC_MAX_JTAG_DR_LENGTH)
{
status = JBIC_OUT_OF_MEMORY;
}
}
else if (shift_count > jbi_dr_length)
{
alloc_chars = (shift_count + 7) >> 3;
jbi_free(jbi_dr_buffer);
jbi_dr_buffer = (unsigned char *) jbi_malloc(alloc_chars);
if (jbi_dr_buffer == NULL)
{
status = JBIC_OUT_OF_MEMORY;
}
else
{
jbi_dr_length = alloc_chars * 8;
}
}
}
if (status == JBIC_SUCCESS)
{
/*
* Copy preamble data, DR data, and postamble data into a buffer
*/
jbi_jtag_concatenate_data
(
jbi_dr_buffer,
jbi_dr_preamble_data,
jbi_dr_preamble,
tdi_data,
start_index,
count,
jbi_dr_postamble_data,
jbi_dr_postamble
);
/*
* Do the DRSCAN
*/
jbi_jtag_drscan
(
start_code,
shift_count,
jbi_dr_buffer,
NULL
);
/* jbi_jtag_drscan() always ends in DRPAUSE state */
jbi_jtag_state = DRPAUSE;
}
if (status == JBIC_SUCCESS)
{
if (jbi_drstop_state != DRPAUSE)
{
status = jbi_goto_jtag_state(jbi_drstop_state);
}
}
return (status);
}
/****************************************************************************/
/* */
JBI_RETURN_TYPE jbi_swap_dr
(
unsigned int count,
unsigned char *in_data,
unsigned long in_index,
unsigned char *out_data,
unsigned int out_index
)
/* */
/* Description: Shifts data into data register, capturing output data */
/* */
/* Returns: JBIC_SUCCESS for success, else appropriate error code */
/* */
/****************************************************************************/
{
int start_code = 0;
unsigned int alloc_chars = 0;
unsigned int shift_count = jbi_dr_preamble + count + jbi_dr_postamble;
JBI_RETURN_TYPE status = JBIC_SUCCESS;
JBIE_JTAG_STATE start_state = JBI_ILLEGAL_JTAG_STATE;
switch (jbi_jtag_state)
{
case JBI_ILLEGAL_JTAG_STATE:
case RESET:
case IDLE:
start_code = 0;
start_state = IDLE;
break;
case DRSELECT:
case DRCAPTURE:
case DRSHIFT:
case DREXIT1:
case DRPAUSE:
case DREXIT2:
case DRUPDATE:
start_code = 1;
start_state = DRPAUSE;
break;
case IRSELECT:
case IRCAPTURE:
case IRSHIFT:
case IREXIT1:
case IRPAUSE:
case IREXIT2:
case IRUPDATE:
start_code = 2;
start_state = IRPAUSE;
break;
default:
status = JBIC_INTERNAL_ERROR;
break;
}
if (status == JBIC_SUCCESS)
{
if (jbi_jtag_state != start_state)
{
status = jbi_goto_jtag_state(start_state);
}
}
if (status == JBIC_SUCCESS)
{
if (jbi_workspace != NULL)
{
if (shift_count > JBIC_MAX_JTAG_DR_LENGTH)
{
status = JBIC_OUT_OF_MEMORY;
}
}
else if (shift_count > jbi_dr_length)
{
alloc_chars = (shift_count + 7) >> 3;
jbi_free(jbi_dr_buffer);
jbi_dr_buffer = (unsigned char *) jbi_malloc(alloc_chars);
if (jbi_dr_buffer == NULL)
{
status = JBIC_OUT_OF_MEMORY;
}
else
{
jbi_dr_length = alloc_chars * 8;
}
}
}
if (status == JBIC_SUCCESS)
{
/*
* Copy preamble data, DR data, and postamble data into a buffer
*/
jbi_jtag_concatenate_data
(
jbi_dr_buffer,
jbi_dr_preamble_data,
jbi_dr_preamble,
in_data,
in_index,
count,
jbi_dr_postamble_data,
jbi_dr_postamble
);
/*
* Do the DRSCAN
*/
jbi_jtag_drscan
(
start_code,
shift_count,
jbi_dr_buffer,
jbi_dr_buffer
);
/* jbi_jtag_drscan() always ends in DRPAUSE state */
jbi_jtag_state = DRPAUSE;
}
if (status == JBIC_SUCCESS)
{
if (jbi_drstop_state != DRPAUSE)
{
status = jbi_goto_jtag_state(jbi_drstop_state);
}
}
if (status == JBIC_SUCCESS)
{
/*
* Now extract the returned data from the buffer
*/
jbi_jtag_extract_target_data
(
jbi_dr_buffer,
out_data,
out_index,
jbi_dr_preamble,
count
);
}
return (status);
}
/****************************************************************************/
/* */
void jbi_free_jtag_padding_buffers(int reset_jtag)
/* */
/* Description: Frees memory allocated for JTAG IR and DR buffers */
/* */
/* Returns: nothing */
/* */
/****************************************************************************/
{
/*
* If the JTAG interface was used, reset it to TLR
*/
if (reset_jtag && (jbi_jtag_state != JBI_ILLEGAL_JTAG_STATE))
{
jbi_jtag_reset_idle();
}
if (jbi_workspace == NULL)
{
if (jbi_dr_preamble_data != NULL)
{
jbi_free(jbi_dr_preamble_data);
jbi_dr_preamble_data = NULL;
}
if (jbi_dr_postamble_data != NULL)
{
jbi_free(jbi_dr_postamble_data);
jbi_dr_postamble_data = NULL;
}
if (jbi_dr_buffer != NULL)
{
jbi_free(jbi_dr_buffer);
jbi_dr_buffer = NULL;
}
if (jbi_ir_preamble_data != NULL)
{
jbi_free(jbi_ir_preamble_data);
jbi_ir_preamble_data = NULL;
}
if (jbi_ir_postamble_data != NULL)
{
jbi_free(jbi_ir_postamble_data);
jbi_ir_postamble_data = NULL;
}
if (jbi_ir_buffer != NULL)
{
jbi_free(jbi_ir_buffer);
jbi_ir_buffer = NULL;
}
}
}
#if PORT==DOS
/****************************************************************************/
/* */
JBI_RETURN_TYPE jbi_do_drscan_multi_page
(
unsigned int variable_id,
unsigned long count,
unsigned long start_index,
int version
)
/* */
/* Description: Shifts data into data register (ignoring output data) */
/* Scan data comes from compressed Boolean array. */
/* */
/* Returns: JBIC_SUCCESS for success, else appropriate error code */
/* */
/****************************************************************************/
{
JBI_RETURN_TYPE status = JBIC_SUCCESS;
unsigned long shift_count = jbi_dr_preamble + count + jbi_dr_postamble;
unsigned long i;
unsigned long j;
unsigned long k;
unsigned int bi;
if (status == JBIC_SUCCESS)
{
status = jbi_goto_jtag_state(DRSHIFT);
}
if (status == JBIC_SUCCESS)
{
/*
* Get preamble data, DR data, and postamble data one bit at a time
* and immediately scan it into the JTAG chain
*/
for (i = 0L; i < jbi_dr_preamble; ++i)
{
jbi_jtag_io((i == shift_count - 1),
(int) (jbi_dr_preamble_data[i >> 3L] & (1L << (i & 7L))), 0);
}
j = start_index;
k = jbi_dr_preamble + count;
jbi_uncompress_page(variable_id, (unsigned int) (j >> 16L), version);
for (; i < k; ++i, ++j)
{
bi = (unsigned int) (j & 0x0000ffffL);
/* check for page boundary - load next page if necessary */
if (bi == 0)
{
jbi_uncompress_page(variable_id, (unsigned int) (j >> 16L), version);
}
jbi_jtag_io((i == shift_count - 1),
(int) (jbi_aca_out_buffer[bi >> 3] & (1 << (bi & 7))), 0);
}
j = 0L;
k = jbi_dr_preamble + count + jbi_dr_postamble;
for (; i < k; ++i, ++j)
{
jbi_jtag_io((i == shift_count - 1),
(int) (jbi_dr_postamble_data[j >> 3L] & (1L << (j & 7L))), 0);
}
jbi_jtag_io(0, 0, 0); /* DRPAUSE */
/* jbi_jtag_drscan() always ends in DRPAUSE state */
jbi_jtag_state = DRPAUSE;
if (jbi_drstop_state != DRPAUSE)
{
status = jbi_goto_jtag_state(jbi_drstop_state);
}
}
return (status);
}
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -