From a8473262165a456e46b70e58ff36ef9712b3db2a Mon Sep 17 00:00:00 2001 From: zwelch Date: Thu, 4 Jun 2009 23:49:52 +0000 Subject: Clean up the JTAG TAP creation handler: - Factor jtag_tap_init() helper out of the end of jim_newtap_cmd. - Factor jtag_tap_free() helper out of the error case in jim_newtap_cmd. - Invert test to improve indentation at the end of jim_newtap_cmd. - Improve whitespace in the newly factored functions. git-svn-id: svn://svn.berlios.de/openocd/trunk@2056 b42882b7-edfa-0310-969c-e2dbd0fdcd60 --- src/jtag/jtag.c | 86 ++++++++++++++++++++++++++++++--------------------------- 1 file changed, 45 insertions(+), 41 deletions(-) (limited to 'src') diff --git a/src/jtag/jtag.c b/src/jtag/jtag.c index bdee21a8..e818e92f 100644 --- a/src/jtag/jtag.c +++ b/src/jtag/jtag.c @@ -1270,6 +1270,41 @@ static int jtag_tap_configure_cmd( Jim_GetOptInfo *goi, jtag_tap_t * tap) return JIM_OK; } + +static void jtag_tap_init(jtag_tap_t *tap) +{ + assert(0 != tap->ir_length); + + tap->expected = malloc(tap->ir_length); + tap->expected_mask = malloc(tap->ir_length); + tap->cur_instr = malloc(tap->ir_length); + + buf_set_u32(tap->expected, 0, tap->ir_length, tap->ir_capture_value); + buf_set_u32(tap->expected_mask, 0, tap->ir_length, tap->ir_capture_mask); + buf_set_ones(tap->cur_instr, tap->ir_length); + + // place TAP in bypass mode + tap->bypass = 1; + // register the reset callback for the TAP + jtag_register_event_callback(&jtag_reset_callback, tap); + + LOG_DEBUG("Created Tap: %s @ abs position %d, " + "irlen %d, capture: 0x%x mask: 0x%x", tap->dotted_name, + tap->abs_chain_position, tap->ir_length, + tap->ir_capture_value, tap->ir_capture_mask); + jtag_tap_add(tap); +} + +static void jtag_tap_free(jtag_tap_t *tap) +{ + /// @todo is anything missing? no memory leaks please + free((void *)tap->expected_ids); + free((void *)tap->chip); + free((void *)tap->tapname); + free((void *)tap->dotted_name); + free(tap); +} + static int jim_newtap_cmd( Jim_GetOptInfo *goi ) { jtag_tap_t *pTap; @@ -1404,49 +1439,18 @@ static int jim_newtap_cmd( Jim_GetOptInfo *goi ) } /* switch(n->value) */ } /* while( goi->argc ) */ - /* Did we get all the options? */ - if( reqbits ){ - // no - Jim_SetResult_sprintf( goi->interp, - "newtap: %s missing required parameters", - pTap->dotted_name); - /* TODO: Tell user what is missing :-( */ - /* no memory leaks pelase */ - free(((void *)(pTap->expected_ids))); - free(((void *)(pTap->chip))); - free(((void *)(pTap->tapname))); - free(((void *)(pTap->dotted_name))); - free(((void *)(pTap))); - return JIM_ERR; + /* Did all the required option bits get cleared? */ + if (0 == reqbits) + { + jtag_tap_init(pTap); + return ERROR_OK; } - pTap->expected = malloc( pTap->ir_length ); - pTap->expected_mask = malloc( pTap->ir_length ); - pTap->cur_instr = malloc( pTap->ir_length ); - - buf_set_u32( pTap->expected, - 0, - pTap->ir_length, - pTap->ir_capture_value ); - buf_set_u32( pTap->expected_mask, - 0, - pTap->ir_length, - pTap->ir_capture_mask ); - buf_set_ones( pTap->cur_instr, - pTap->ir_length ); - - pTap->bypass = 1; - - jtag_register_event_callback(jtag_reset_callback, pTap ); - - 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; + Jim_SetResult_sprintf(goi->interp, + "newtap: %s missing required parameters", + pTap->dotted_name); + jtag_tap_free(pTap); + return JIM_ERR; } static int jim_jtag_command( Jim_Interp *interp, int argc, Jim_Obj *const *argv ) -- cgit v1.2.3