From 6dc2c2ce970863a079f101d84a0c47b37b682c76 Mon Sep 17 00:00:00 2001 From: zwelch Date: Tue, 9 Jun 2009 08:40:31 +0000 Subject: Encapsulate jtag_reset_config using accessors: - Update handle_reset_config_command in tcl.c to use new helpers. - Replace direct accesses in JTAG interface and target drivers. git-svn-id: svn://svn.berlios.de/openocd/trunk@2161 b42882b7-edfa-0310-969c-e2dbd0fdcd60 --- src/jtag/amt_jtagaccel.c | 1 + src/jtag/bitbang.c | 2 +- src/jtag/bitq.c | 2 +- src/jtag/core.c | 9 +++++++++ src/jtag/dummy.c | 2 +- src/jtag/ft2232.c | 9 +++++++++ src/jtag/jtag.h | 3 ++- src/jtag/rlink/rlink.c | 2 +- src/jtag/tcl.c | 6 ++++-- src/jtag/zy1000/zy1000.c | 2 +- src/target/arm7_9_common.c | 3 +++ src/target/cortex_m3.c | 3 ++- src/target/mips_m4k.c | 3 ++- 13 files changed, 37 insertions(+), 10 deletions(-) diff --git a/src/jtag/amt_jtagaccel.c b/src/jtag/amt_jtagaccel.c index 4071c25c..7d0dd53c 100644 --- a/src/jtag/amt_jtagaccel.c +++ b/src/jtag/amt_jtagaccel.c @@ -500,6 +500,7 @@ static int amt_jtagaccel_init(void) amt_jtagaccel_speed(jtag_get_speed()); + enum reset_types jtag_reset_config = jtag_get_reset_config(); if (jtag_reset_config & RESET_TRST_OPEN_DRAIN) aw_control_rst &= ~0x8; else diff --git a/src/jtag/bitbang.c b/src/jtag/bitbang.c index 4e8dd2e3..f5bfd15e 100644 --- a/src/jtag/bitbang.c +++ b/src/jtag/bitbang.c @@ -258,7 +258,7 @@ int bitbang_execute_queue(void) #ifdef _DEBUG_JTAG_IO_ LOG_DEBUG("reset trst: %i srst %i", cmd->cmd.reset->trst, cmd->cmd.reset->srst); #endif - if ((cmd->cmd.reset->trst == 1) || (cmd->cmd.reset->srst && (jtag_reset_config & RESET_SRST_PULLS_TRST))) + if ((cmd->cmd.reset->trst == 1) || (cmd->cmd.reset->srst && (jtag_get_reset_config() & RESET_SRST_PULLS_TRST))) { tap_set_state(TAP_RESET); } diff --git a/src/jtag/bitq.c b/src/jtag/bitq.c index 9e0f4947..83e14e66 100644 --- a/src/jtag/bitq.c +++ b/src/jtag/bitq.c @@ -298,7 +298,7 @@ int bitq_execute_queue(void) #ifdef _DEBUG_JTAG_IO_ LOG_DEBUG("reset trst: %i srst %i", cmd->cmd.reset->trst, cmd->cmd.reset->srst); #endif - if ( (cmd->cmd.reset->trst == 1) || ( cmd->cmd.reset->srst && (jtag_reset_config & RESET_SRST_PULLS_TRST) ) ) + if ( (cmd->cmd.reset->trst == 1) || ( cmd->cmd.reset->srst && (jtag_get_reset_config() & RESET_SRST_PULLS_TRST) ) ) { tap_set_state(TAP_RESET); } diff --git a/src/jtag/core.c b/src/jtag/core.c index f6db00a5..0a587487 100644 --- a/src/jtag/core.c +++ b/src/jtag/core.c @@ -1262,6 +1262,15 @@ int jtag_add_statemove(tap_state_t goal_state) return ERROR_OK; } +enum reset_types jtag_get_reset_config(void) +{ + return jtag_reset_config; +} +void jtag_set_reset_config(enum reset_types type) +{ + jtag_reset_config = type; +} + int jtag_get_trst(void) { return jtag_trst; diff --git a/src/jtag/dummy.c b/src/jtag/dummy.c index 9d4a436b..2ad8c10f 100644 --- a/src/jtag/dummy.c +++ b/src/jtag/dummy.c @@ -123,7 +123,7 @@ static void dummy_reset(int trst, int srst) { dummy_clock = 0; - if (trst || (srst && (jtag_reset_config & RESET_SRST_PULLS_TRST))) + if (trst || (srst && (jtag_get_reset_config() & RESET_SRST_PULLS_TRST))) dummy_state = TAP_RESET; LOG_DEBUG("reset to: %s", tap_state_name(dummy_state) ); diff --git a/src/jtag/ft2232.c b/src/jtag/ft2232.c index 734833b1..4bc2f3fe 100644 --- a/src/jtag/ft2232.c +++ b/src/jtag/ft2232.c @@ -1193,6 +1193,7 @@ static int ft2232_predict_scan_in(int scan_size, enum scan_type type) static void usbjtag_reset(int trst, int srst) { + enum reset_types jtag_reset_config = jtag_get_reset_config(); if (trst == 1) { if (jtag_reset_config & RESET_TRST_OPEN_DRAIN) @@ -1232,6 +1233,7 @@ static void usbjtag_reset(int trst, int srst) static void jtagkey_reset(int trst, int srst) { + enum reset_types jtag_reset_config = jtag_get_reset_config(); if (trst == 1) { if (jtag_reset_config & RESET_TRST_OPEN_DRAIN) @@ -1273,6 +1275,7 @@ static void jtagkey_reset(int trst, int srst) static void olimex_jtag_reset(int trst, int srst) { + enum reset_types jtag_reset_config = jtag_get_reset_config(); if (trst == 1) { if (jtag_reset_config & RESET_TRST_OPEN_DRAIN) @@ -2155,6 +2158,7 @@ static int usbjtag_init(void) return ERROR_JTAG_INIT_FAILED; } + enum reset_types jtag_reset_config = jtag_get_reset_config(); if (jtag_reset_config & RESET_TRST_OPEN_DRAIN) { low_direction &= ~nTRSTnOE; /* nTRST input */ @@ -2229,6 +2233,7 @@ static int axm0432_jtag_init(void) high_output = 0x0; high_direction = 0x0c; + enum reset_types jtag_reset_config = jtag_get_reset_config(); if (jtag_reset_config & RESET_TRST_OPEN_DRAIN) { LOG_ERROR("can't set nTRSTOE to push-pull on the Dicarlo jtag"); @@ -2307,6 +2312,7 @@ static int jtagkey_init(void) high_output = 0x0; high_direction = 0x0f; + enum reset_types jtag_reset_config = jtag_get_reset_config(); if (jtag_reset_config & RESET_TRST_OPEN_DRAIN) { high_output |= nTRSTnOE; @@ -2373,6 +2379,7 @@ static int olimex_jtag_init(void) high_output = 0x0; high_direction = 0x0f; + enum reset_types jtag_reset_config = jtag_get_reset_config(); if (jtag_reset_config & RESET_TRST_OPEN_DRAIN) { high_output |= nTRSTnOE; @@ -2944,6 +2951,7 @@ static int icebear_jtag_init(void) { nTRST = 0x10; nSRST = 0x20; + enum reset_types jtag_reset_config = jtag_get_reset_config(); if ((jtag_reset_config & RESET_TRST_OPEN_DRAIN) != 0) { low_direction &= ~nTRST; /* nTRST high impedance */ } @@ -2991,6 +2999,7 @@ static void icebear_jtag_reset(int trst, int srst) { low_output &= ~nTRST; } else if (trst == 0) { + enum reset_types jtag_reset_config = jtag_get_reset_config(); if ((jtag_reset_config & RESET_TRST_OPEN_DRAIN) != 0) low_direction &= ~nTRST; else diff --git a/src/jtag/jtag.h b/src/jtag/jtag.h index 1b0bed0e..515f2969 100644 --- a/src/jtag/jtag.h +++ b/src/jtag/jtag.h @@ -277,7 +277,8 @@ enum reset_types { RESET_SRST_PUSH_PULL = 0x20, }; -extern enum reset_types jtag_reset_config; +enum reset_types jtag_get_reset_config(void); +void jtag_set_reset_config(enum reset_types type); /** * Initialize interface upon startup. Return a successful no-op upon diff --git a/src/jtag/rlink/rlink.c b/src/jtag/rlink/rlink.c index 121de01f..554cca29 100644 --- a/src/jtag/rlink/rlink.c +++ b/src/jtag/rlink/rlink.c @@ -1419,7 +1419,7 @@ int rlink_execute_queue(void) #ifdef _DEBUG_JTAG_IO_ LOG_DEBUG("reset trst: %i srst %i", cmd->cmd.reset->trst, cmd->cmd.reset->srst); #endif - if ((cmd->cmd.reset->trst == 1) || (cmd->cmd.reset->srst && (jtag_reset_config & RESET_SRST_PULLS_TRST))) + if ((cmd->cmd.reset->trst == 1) || (cmd->cmd.reset->srst && (jtag_get_reset_config() & RESET_SRST_PULLS_TRST))) { tap_set_state(TAP_RESET); } diff --git a/src/jtag/tcl.c b/src/jtag/tcl.c index ed24498b..121c19ab 100644 --- a/src/jtag/tcl.c +++ b/src/jtag/tcl.c @@ -921,8 +921,10 @@ next: } /* clear previous values of those bits, save new values */ - jtag_reset_config &= ~mask; - jtag_reset_config |= new_cfg; + enum reset_types old_cfg = jtag_get_reset_config(); + old_cfg &= ~mask; + new_cfg |= old_cfg; + jtag_set_reset_config(new_cfg); return ERROR_OK; } diff --git a/src/jtag/zy1000/zy1000.c b/src/jtag/zy1000/zy1000.c index 05bbd4c5..4dbdef24 100644 --- a/src/jtag/zy1000/zy1000.c +++ b/src/jtag/zy1000/zy1000.c @@ -164,7 +164,7 @@ void zy1000_reset(int trst, int srst) ZY1000_POKE(ZY1000_JTAG_BASE+0x10, 0x00000002); } - if (trst||(srst&&(jtag_reset_config & RESET_SRST_PULLS_TRST))) + if (trst||(srst&&(jtag_get_reset_config() & RESET_SRST_PULLS_TRST))) { waitIdle(); /* we're now in the RESET state until trst is deasserted */ diff --git a/src/target/arm7_9_common.c b/src/target/arm7_9_common.c index 9ec3e6c8..493cf02d 100644 --- a/src/target/arm7_9_common.c +++ b/src/target/arm7_9_common.c @@ -905,6 +905,7 @@ int arm7_9_poll(target_t *target) { if (target->reset_halt) { + enum reset_types jtag_reset_config = jtag_get_reset_config(); if ((jtag_reset_config & RESET_SRST_PULLS_TRST)==0) { check_pc = 1; @@ -975,6 +976,7 @@ int arm7_9_assert_reset(target_t *target) LOG_DEBUG("target->state: %s", Jim_Nvp_value2name_simple( nvp_target_state,target->state)->name); + enum reset_types jtag_reset_config = jtag_get_reset_config(); if (!(jtag_reset_config & RESET_HAS_SRST)) { LOG_ERROR("Can't assert SRST"); @@ -1047,6 +1049,7 @@ int arm7_9_deassert_reset(target_t *target) /* deassert reset lines */ jtag_add_reset(0, 0); + enum reset_types jtag_reset_config = jtag_get_reset_config(); if (target->reset_halt&&(jtag_reset_config & RESET_SRST_PULLS_TRST)!=0) { LOG_WARNING("srst pulls trst - can not reset into halted mode. Issuing halt after reset."); diff --git a/src/target/cortex_m3.c b/src/target/cortex_m3.c index efa94ea4..ab2c8f8e 100644 --- a/src/target/cortex_m3.c +++ b/src/target/cortex_m3.c @@ -544,7 +544,7 @@ int cortex_m3_halt(target_t *target) if (target->state == TARGET_RESET) { - if ((jtag_reset_config & RESET_SRST_PULLS_TRST) && jtag_get_srst()) + if ((jtag_get_reset_config() & RESET_SRST_PULLS_TRST) && jtag_get_srst()) { LOG_ERROR("can't request a halt while in reset if nSRST pulls nTRST"); return ERROR_TARGET_FAILURE; @@ -753,6 +753,7 @@ int cortex_m3_assert_reset(target_t *target) LOG_DEBUG("target->state: %s", Jim_Nvp_value2name_simple( nvp_target_state, target->state )->name ); + enum reset_types jtag_reset_config = jtag_get_reset_config(); if (!(jtag_reset_config & RESET_HAS_SRST)) { LOG_ERROR("Can't assert SRST"); diff --git a/src/target/mips_m4k.c b/src/target/mips_m4k.c index 466e0a2d..5e98a2a0 100644 --- a/src/target/mips_m4k.c +++ b/src/target/mips_m4k.c @@ -235,7 +235,7 @@ int mips_m4k_halt(struct target_s *target) if (target->state == TARGET_RESET) { - if ((jtag_reset_config & RESET_SRST_PULLS_TRST) && jtag_get_srst()) + if ((jtag_get_reset_config() & RESET_SRST_PULLS_TRST) && jtag_get_srst()) { LOG_ERROR("can't request a halt while in reset if nSRST pulls nTRST"); return ERROR_TARGET_FAILURE; @@ -267,6 +267,7 @@ int mips_m4k_assert_reset(target_t *target) LOG_DEBUG("target->state: %s", Jim_Nvp_value2name_simple( nvp_target_state, target->state )->name); + enum reset_types jtag_reset_config = jtag_get_reset_config(); if (!(jtag_reset_config & RESET_HAS_SRST)) { LOG_ERROR("Can't assert SRST"); -- cgit v1.2.3