diff options
author | zwelch <zwelch@b42882b7-edfa-0310-969c-e2dbd0fdcd60> | 2009-06-04 23:26:58 +0000 |
---|---|---|
committer | zwelch <zwelch@b42882b7-edfa-0310-969c-e2dbd0fdcd60> | 2009-06-04 23:26:58 +0000 |
commit | d3d02f478946415660f9d641283a3fefb97d6899 (patch) | |
tree | 0d0f43aa9f5744a7f1ab2578657051ece7d94110 | |
parent | 82a5f6ff3e77396fc80cde29a16b320544e0bc8f (diff) | |
download | openocd+libswd-d3d02f478946415660f9d641283a3fefb97d6899.tar.gz openocd+libswd-d3d02f478946415660f9d641283a3fefb97d6899.tar.bz2 openocd+libswd-d3d02f478946415660f9d641283a3fefb97d6899.tar.xz openocd+libswd-d3d02f478946415660f9d641283a3fefb97d6899.zip |
Clean up the core JTAG TAP APIs:
- Move jtag_tap_name to same location as other TAP functions; export it.
- Factor new jtag_tap_add() from jim_newtap_cmd(); appends TAP to global list.
- Move static chain position counter to global; use in jtag_NumTotalTaps().
- Use jtag_AllTaps for reading tap list, instead of accessing global directly.
git-svn-id: svn://svn.berlios.de/openocd/trunk@2055 b42882b7-edfa-0310-969c-e2dbd0fdcd60
-rw-r--r-- | src/jtag/jtag.c | 65 | ||||
-rw-r--r-- | src/jtag/jtag.h | 1 |
2 files changed, 34 insertions, 32 deletions
diff --git a/src/jtag/jtag.c b/src/jtag/jtag.c index f1dc6828..bdee21a8 100644 --- a/src/jtag/jtag.c +++ b/src/jtag/jtag.c @@ -63,7 +63,15 @@ const Jim_Nvp nvp_jtag_tap_event[] = { int jtag_trst = 0; int jtag_srst = 0; +/** + * List all TAPs that have been created. + */ static jtag_tap_t *jtag_all_taps = NULL; +/** + * The number of TAPs in the jtag_all_taps list, used to track the + * assigned chain position to new TAPs + */ +static int jtag_num_taps = 0; enum reset_types jtag_reset_config = RESET_NONE; tap_state_t cmd_queue_end_state = TAP_RESET; @@ -235,16 +243,7 @@ jtag_tap_t *jtag_AllTaps(void) int jtag_NumTotalTaps(void) { - jtag_tap_t *t; - int n; - - n = 0; - t = jtag_AllTaps(); - while(t){ - n++; - t = t->next_tap; - } - return n; + return jtag_num_taps; } int jtag_NumEnabledTaps(void) @@ -263,6 +262,17 @@ int jtag_NumEnabledTaps(void) return n; } +/// Append a new TAP to the chain of all taps. +static void jtag_tap_add(struct jtag_tap_s *t) +{ + t->abs_chain_position = jtag_num_taps++; + + jtag_tap_t **tap = &jtag_all_taps; + while(*tap != NULL) + tap = &(*tap)->next_tap; + *tap = t; +} + jtag_tap_t *jtag_TapByString( const char *s ) { jtag_tap_t *t; @@ -324,6 +334,12 @@ jtag_tap_t * jtag_TapByAbsPosition( int n ) return t; } +const char *jtag_tap_name(const jtag_tap_t *tap) +{ + return (tap == NULL) ? "(unknown)" : tap->dotted_name; +} + + int jtag_register_event_callback(int (*callback)(enum jtag_event event, void *priv), void *priv) { jtag_event_callback_t **callbacks_p = &jtag_event_callbacks; @@ -798,11 +814,6 @@ void jtag_add_sleep(u32 us) return; } -static const char *jtag_tap_name(const jtag_tap_t *tap) -{ - return (tap == NULL) ? "(unknown)" : tap->dotted_name; -} - int jtag_check_value_inner(u8 *captured, u8 *in_check_value, u8 *in_check_mask, int num_bits) { int retval = ERROR_OK; @@ -1262,7 +1273,6 @@ static int jtag_tap_configure_cmd( Jim_GetOptInfo *goi, jtag_tap_t * tap) static int jim_newtap_cmd( Jim_GetOptInfo *goi ) { jtag_tap_t *pTap; - jtag_tap_t **ppTap; jim_wide w; int x; int e; @@ -1429,21 +1439,12 @@ static int jim_newtap_cmd( Jim_GetOptInfo *goi ) jtag_register_event_callback(jtag_reset_callback, pTap ); - ppTap = &(jtag_all_taps); - while( (*ppTap) != NULL ){ - ppTap = &((*ppTap)->next_tap); - } - *ppTap = pTap; - { - static int n_taps = 0; - pTap->abs_chain_position = n_taps++; - } - LOG_DEBUG( "Created Tap: %s @ abs position %d, irlen %d, capture: 0x%x mask: 0x%x", - (*ppTap)->dotted_name, - (*ppTap)->abs_chain_position, - (*ppTap)->ir_length, - (*ppTap)->ir_capture_value, - (*ppTap)->ir_capture_mask ); + jtag_tap_add(pTap); + + LOG_DEBUG("Created Tap: %s @ abs position %d, " + "irlen %d, capture: 0x%x mask: 0x%x", pTap->dotted_name, + pTap->abs_chain_position, pTap->ir_length, + pTap->ir_capture_value, pTap->ir_capture_mask); return ERROR_OK; } @@ -1914,7 +1915,7 @@ static int handle_scan_chain_command(struct command_context_s *cmd_ctx, char *cm { jtag_tap_t *tap; - tap = jtag_all_taps; + tap = jtag_AllTaps(); command_print(cmd_ctx, " TapName | Enabled | IdCode Expected IrLen IrCap IrMask Instr "); command_print(cmd_ctx, "---|--------------------|---------|------------|------------|------|------|------|---------"); diff --git a/src/jtag/jtag.h b/src/jtag/jtag.h index ffcab42a..a63aa371 100644 --- a/src/jtag/jtag.h +++ b/src/jtag/jtag.h @@ -176,6 +176,7 @@ struct jtag_tap_s jtag_tap_t* next_tap; }; extern jtag_tap_t* jtag_AllTaps(void); +extern const char *jtag_tap_name(const jtag_tap_t *tap); extern jtag_tap_t* jtag_TapByPosition(int n); extern jtag_tap_t* jtag_TapByString(const char* dotted_name); extern jtag_tap_t* jtag_TapByJimObj(Jim_Interp* interp, Jim_Obj* obj); |