Improve encapsulation of JTAG event handling:
[fw/openocd] / src / jtag / core.c
index 0a587487e88a3cacd32d3ee65edd2e5231b5a0d6..d45fd67ee7515538c9eec187e20f610f5b37617c 100644 (file)
@@ -46,23 +46,23 @@ static int jtag_flush_queue_count;
 static void jtag_add_scan_check(void (*jtag_add_scan)(int in_num_fields, const scan_field_t *in_fields, tap_state_t state),
                int in_num_fields, scan_field_t *in_fields, tap_state_t state);
 
-/* note that this is not marked as static as it must be available from outside core.c for those
-   that implement the jtag_xxx() minidriver layer
-*/
-int jtag_error=ERROR_OK;
+/**
+ * The jtag_error variable is set when an error occurs while executing
+ * the queue.  Application code may set this using jtag_set_error(),
+ * when an error occurs during processing that should be reported during
+ * jtag_execute_queue().
+ *
+ * Tts value may be checked with jtag_get_error() and cleared with
+ * jtag_error_clear().  This value is returned (and cleared) by
+ * jtag_execute_queue().
+ */
+static int jtag_error = ERROR_OK;
 
-char* jtag_event_strings[] =
+static char* jtag_event_strings[] =
 {
        "JTAG controller reset (RESET or TRST)"
 };
 
-const Jim_Nvp nvp_jtag_tap_event[] = {
-       { .value = JTAG_TAP_EVENT_ENABLE,       .name = "tap-enable" },
-       { .value = JTAG_TAP_EVENT_DISABLE,      .name = "tap-disable" },
-
-       { .name = NULL, .value = -1 }
-};
-
 static int jtag_trst = 0;
 static int jtag_srst = 0;
 
@@ -76,12 +76,12 @@ static jtag_tap_t *__jtag_all_taps = NULL;
  */
 static unsigned jtag_num_taps = 0;
 
-enum reset_types jtag_reset_config = RESET_NONE;
-tap_state_t cmd_queue_end_state = TAP_RESET;
+static enum reset_types jtag_reset_config = RESET_NONE;
+static tap_state_t cmd_queue_end_state = TAP_RESET;
 tap_state_t cmd_queue_cur_state = TAP_RESET;
 
-int jtag_verify_capture_ir = 1;
-int jtag_verify = 1;
+static bool jtag_verify_capture_ir = true;
+static int jtag_verify = 1;
 
 /* how long the OpenOCD should wait before attempting JTAG communication after reset lines deasserted (in ms) */
 static int jtag_nsrst_delay = 0; /* default to no nSRST delay */
@@ -93,13 +93,31 @@ static jtag_event_callback_t *jtag_event_callbacks;
 /* speed in kHz*/
 static int speed_khz = 0;
 /* flag if the kHz speed was defined */
-bool hasKHz = false;
+static bool hasKHz = false;
+static int jtag_speed = 0;
 
 struct jtag_interface_s *jtag = NULL;
 
 /* configuration */
 jtag_interface_t *jtag_interface = NULL;
-int jtag_speed = 0;
+
+void jtag_set_error(int error)
+{
+       if ((error == ERROR_OK) || (jtag_error != ERROR_OK))
+               return;
+       jtag_error = error;
+}
+int jtag_get_error(void)
+{
+       return jtag_error;
+}
+int jtag_error_clear(void)
+{
+       int temp = jtag_error;
+       jtag_error = ERROR_OK;
+       return temp;
+}
+
 
 jtag_tap_t *jtag_all_taps(void)
 {
@@ -1163,6 +1181,7 @@ int jtag_set_speed(int speed)
        jtag_speed = speed;
        /* this command can be called during CONFIG,
         * in which case jtag isn't initialized */
+       hasKHz = !jtag;
        return jtag ? jtag->speed(speed) : ERROR_OK;
 }
 
@@ -1176,6 +1195,15 @@ bool jtag_will_verify()
        return jtag_verify;
 }
 
+void jtag_set_verify_capture_ir(bool enable)
+{
+       jtag_verify_capture_ir = enable;
+}
+
+bool jtag_will_verify_capture_ir()
+{
+       return jtag_verify_capture_ir;
+}
 
 int jtag_power_dropout(int *dropout)
 {
@@ -1187,37 +1215,6 @@ int jtag_srst_asserted(int *srst_asserted)
        return jtag->srst_asserted(srst_asserted);
 }
 
-void jtag_tap_handle_event( jtag_tap_t * tap, enum jtag_tap_event e)
-{
-       jtag_tap_event_action_t * jteap;
-       int done;
-
-       jteap = tap->event_action;
-
-       done = 0;
-       while (jteap) {
-               if (jteap->event == e) {
-                       done = 1;
-                       LOG_DEBUG( "JTAG tap: %s event: %d (%s) action: %s\n",
-                                       tap->dotted_name,
-                                       e,
-                                       Jim_Nvp_value2name_simple(nvp_jtag_tap_event, e)->name,
-                                       Jim_GetString(jteap->body, NULL) );
-                       if (Jim_EvalObj(interp, jteap->body) != JIM_OK) {
-                               Jim_PrintErrorMessage(interp);
-                       }
-               }
-
-               jteap = jteap->next;
-       }
-
-       if (!done) {
-               LOG_DEBUG( "event %d %s - no action",
-                               e,
-                               Jim_Nvp_value2name_simple( nvp_jtag_tap_event, e)->name);
-       }
-}
-
 int jtag_add_statemove(tap_state_t goal_state)
 {
        tap_state_t cur_state = cmd_queue_cur_state;