+int jtag_check_value(u8 *captured, void *priv, scan_field_t *field)
+{
+ int retval = ERROR_OK;
+ int num_bits = field->num_bits;
+
+ int compare_failed = 0;
+
+ if (field->in_check_mask)
+ compare_failed = buf_cmp_mask(captured, field->in_check_value, field->in_check_mask, num_bits);
+ else
+ compare_failed = buf_cmp(captured, field->in_check_value, num_bits);
+
+ if (compare_failed)
+ {
+ /* An error handler could have caught the failing check
+ * only report a problem when there wasn't a handler, or if the handler
+ * acknowledged the error
+ */
+ if (compare_failed)
+ {
+ char *captured_char = buf_to_str(captured, (num_bits > 64) ? 64 : num_bits, 16);
+ char *in_check_value_char = buf_to_str(field->in_check_value, (num_bits > 64) ? 64 : num_bits, 16);
+
+ if (field->in_check_mask)
+ {
+ char *in_check_mask_char;
+ in_check_mask_char = buf_to_str(field->in_check_mask, (num_bits > 64) ? 64 : num_bits, 16);
+ WARNING("value captured during scan didn't pass the requested check: captured: 0x%s check_value: 0x%s check_mask: 0x%s", captured_char, in_check_value_char, in_check_mask_char);
+ free(in_check_mask_char);
+ }
+ else
+ {
+ WARNING("value captured during scan didn't pass the requested check: captured: 0x%s check_value: 0x%s", captured_char, in_check_value_char);
+ }
+
+ free(captured_char);
+ free(in_check_value_char);
+
+ retval = ERROR_JTAG_QUEUE_FAILED;
+ }
+
+ }
+ return retval;
+}
+
+/*
+ set up checking of this field using the in_handler. The values passed in must be valid until
+ after jtag_execute() has completed.
+ */
+void jtag_set_check_value(scan_field_t *field, u8 *value, u8 *mask, error_handler_t *in_error_handler)
+{
+ if (value)
+ field->in_handler = jtag_check_value;
+ else
+ field->in_handler = NULL; /* No check, e.g. embeddedice uses value==NULL to indicate no check */
+ field->in_handler_priv = NULL; /* this will be filled in at the invocation site to point to the field duplicate */
+ field->in_check_value = value;
+ field->in_check_mask = mask;
+}
+