Add wrappers for target->type->examined:

- replace all checks of target->type->examined with target_was_examined().
- replace all setting of target->type->examined with target_set_examined().
- replace clearing of target->type->examined with target_reset_examined().
- add documentation in target_s to warn not to access field directly.


git-svn-id: svn://svn.berlios.de/openocd/trunk@1962 b42882b7-edfa-0310-969c-e2dbd0fdcd60
This commit is contained in:
zwelch 2009-05-31 09:38:43 +00:00
parent fbe8cf72a5
commit 9cb3af610a
10 changed files with 62 additions and 33 deletions

View File

@ -1631,7 +1631,7 @@ int arm11_examine(struct target_s *target)
arm11_check_init(arm11, NULL);
target->type->examined = 1;
target_set_examined(target);
return ERROR_OK;
}

View File

@ -818,7 +818,7 @@ int arm7_9_handle_target_request(void *priv)
{
int retval = ERROR_OK;
target_t *target = priv;
if (!target->type->examined)
if (!target_was_examined(target))
return ERROR_OK;
armv4_5_common_t *armv4_5 = target->arch_info;
arm7_9_common_t *arm7_9 = armv4_5->arch_info;

View File

@ -718,7 +718,7 @@ int arm7tdmi_examine(struct target_s *target)
int retval;
armv4_5_common_t *armv4_5 = target->arch_info;
arm7_9_common_t *arm7_9 = armv4_5->arch_info;
if (!target->type->examined)
if (!target_was_examined(target))
{
/* get pointers to arch-specific information */
reg_cache_t **cache_p = register_get_last_cache_p(&target->reg_cache);
@ -735,7 +735,7 @@ int arm7tdmi_examine(struct target_s *target)
(*cache_p)->next = etm_build_reg_cache(target, jtag_info, arm7_9->etm_ctx);
arm7_9->etm_ctx->reg_cache = (*cache_p)->next;
}
target->type->examined = 1;
target_set_examined(target);
}
if ((retval=embeddedice_setup(target))!=ERROR_OK)
return retval;

View File

@ -810,7 +810,7 @@ int arm9tdmi_examine(struct target_s *target)
int retval;
armv4_5_common_t *armv4_5 = target->arch_info;
arm7_9_common_t *arm7_9 = armv4_5->arch_info;
if (!target->type->examined)
if (!target_was_examined(target))
{
reg_cache_t **cache_p = register_get_last_cache_p(&target->reg_cache);
reg_cache_t *t;
@ -827,7 +827,7 @@ int arm9tdmi_examine(struct target_s *target)
(*cache_p)->next = etm_build_reg_cache(target, jtag_info, arm7_9->etm_ctx);
arm7_9->etm_ctx->reg_cache = (*cache_p)->next;
}
target->type->examined = 1;
target_set_examined(target);
}
if ((retval=embeddedice_setup(target))!=ERROR_OK)
return retval;

View File

@ -168,7 +168,7 @@ int cortex_a8_write_memory(struct target_s *target, u32 address, u32 size, u32 c
int cortex_a8_handle_target_request(void *priv)
{
target_t *target = priv;
if (!target->type->examined)
if (!target_was_examined(target))
return ERROR_OK;
armv7m_common_t *armv7m = target->arch_info;
swjdp_common_t *swjdp = &armv7m->swjdp_info;

View File

@ -1429,9 +1429,9 @@ int cortex_m3_examine(struct target_s *target)
if ((retval = ahbap_debugport_init(swjdp)) != ERROR_OK)
return retval;
if (!target->type->examined)
if (!target_was_examined(target))
{
target->type->examined = 1;
target_set_examined(target);
/* Read from Device Identification Registers */
if ((retval = target_read_u32(target, CPUID, &cpuid)) != ERROR_OK)
@ -1526,7 +1526,7 @@ int cortex_m3_target_request_data(target_t *target, u32 size, u8 *buffer)
int cortex_m3_handle_target_request(void *priv)
{
target_t *target = priv;
if (!target->type->examined)
if (!target_was_examined(target))
return ERROR_OK;
armv7m_common_t *armv7m = target->arch_info;
swjdp_common_t *swjdp = &armv7m->swjdp_info;

View File

@ -346,9 +346,9 @@ int mips32_examine(struct target_s *target)
{
mips32_common_t *mips32 = target->arch_info;
if (!target->type->examined)
if (target_was_examined(target))
{
target->type->examined = 1;
target_set_examined(target);
/* we will configure later */
mips32->bp_scanned = 0;

View File

@ -854,7 +854,7 @@ int mips_m4k_examine(struct target_s *target)
mips_ejtag_t *ejtag_info = &mips32->ejtag_info;
u32 idcode = 0;
if (!target->type->examined)
if (!target_was_examined(target))
{
mips_ejtag_get_idcode(ejtag_info, &idcode, NULL);
ejtag_info->idcode = idcode;

View File

@ -384,7 +384,7 @@ target_t* get_current_target(command_context_t *cmd_ctx)
int target_poll(struct target_s *target)
{
/* We can't poll until after examine */
if (!target->type->examined)
if (!target_was_examined(target))
{
/* Fail silently lest we pollute the log */
return ERROR_FAIL;
@ -395,7 +395,7 @@ int target_poll(struct target_s *target)
int target_halt(struct target_s *target)
{
/* We can't poll until after examine */
if (!target->type->examined)
if (!target_was_examined(target))
{
LOG_ERROR("Target not examined yet");
return ERROR_FAIL;
@ -408,7 +408,7 @@ int target_resume(struct target_s *target, int current, u32 address, int handle_
int retval;
/* We can't poll until after examine */
if (!target->type->examined)
if (!target_was_examined(target))
{
LOG_ERROR("Target not examined yet");
return ERROR_FAIL;
@ -463,7 +463,7 @@ static int default_mmu(struct target_s *target, int *enabled)
static int default_examine(struct target_s *target)
{
target->type->examined = 1;
target_set_examined(target);
return ERROR_OK;
}
@ -487,7 +487,7 @@ int target_examine(void)
static int target_write_memory_imp(struct target_s *target, u32 address, u32 size, u32 count, u8 *buffer)
{
if (!target->type->examined)
if (!target_was_examined(target))
{
LOG_ERROR("Target not examined yet");
return ERROR_FAIL;
@ -497,7 +497,7 @@ static int target_write_memory_imp(struct target_s *target, u32 address, u32 siz
static int target_read_memory_imp(struct target_s *target, u32 address, u32 size, u32 count, u8 *buffer)
{
if (!target->type->examined)
if (!target_was_examined(target))
{
LOG_ERROR("Target not examined yet");
return ERROR_FAIL;
@ -507,7 +507,7 @@ static int target_read_memory_imp(struct target_s *target, u32 address, u32 size
static int target_soft_reset_halt_imp(struct target_s *target)
{
if (!target->type->examined)
if (!target_was_examined(target))
{
LOG_ERROR("Target not examined yet");
return ERROR_FAIL;
@ -517,7 +517,7 @@ static int target_soft_reset_halt_imp(struct target_s *target)
static int target_run_algorithm_imp(struct target_s *target, int num_mem_params, mem_param_t *mem_params, int num_reg_params, reg_param_t *reg_param, u32 entry_point, u32 exit_point, int timeout_ms, void *arch_info)
{
if (!target->type->examined)
if (!target_was_examined(target))
{
LOG_ERROR("Target not examined yet");
return ERROR_FAIL;
@ -548,6 +548,22 @@ int target_run_algorithm(struct target_s *target,
entry_point, exit_point, timeout_ms, arch_info);
}
/// @returns @c true if the target has been examined.
bool target_was_examined(struct target_s *target)
{
return target->type->examined;
}
/// Sets the @c examined flag for the given target.
void target_set_examined(struct target_s *target)
{
target->type->examined = true;
}
// Reset the @c examined flag for the given target.
void target_reset_examined(struct target_s *target)
{
target->type->examined = false;
}
int target_init(struct command_context_s *cmd_ctx)
{
@ -556,7 +572,7 @@ int target_init(struct command_context_s *cmd_ctx)
while (target)
{
target->type->examined = 0;
target_reset_examined(target);
if (target->type->examine == NULL)
{
target->type->examine = default_examine;
@ -1003,7 +1019,7 @@ int target_write_buffer(struct target_s *target, u32 address, u32 size, u8 *buff
int retval;
LOG_DEBUG("writing buffer of %i byte at 0x%8.8x", size, address);
if (!target->type->examined)
if (!target_was_examined(target))
{
LOG_ERROR("Target not examined yet");
return ERROR_FAIL;
@ -1082,7 +1098,7 @@ int target_read_buffer(struct target_s *target, u32 address, u32 size, u8 *buffe
int retval;
LOG_DEBUG("reading buffer of %i byte at 0x%8.8x", size, address);
if (!target->type->examined)
if (!target_was_examined(target))
{
LOG_ERROR("Target not examined yet");
return ERROR_FAIL;
@ -1149,7 +1165,7 @@ int target_checksum_memory(struct target_s *target, u32 address, u32 size, u32*
int retval;
u32 i;
u32 checksum = 0;
if (!target->type->examined)
if (!target_was_examined(target))
{
LOG_ERROR("Target not examined yet");
return ERROR_FAIL;
@ -1191,7 +1207,7 @@ int target_checksum_memory(struct target_s *target, u32 address, u32 size, u32*
int target_blank_check_memory(struct target_s *target, u32 address, u32 size, u32* blank)
{
int retval;
if (!target->type->examined)
if (!target_was_examined(target))
{
LOG_ERROR("Target not examined yet");
return ERROR_FAIL;
@ -1208,7 +1224,7 @@ int target_blank_check_memory(struct target_s *target, u32 address, u32 size, u3
int target_read_u32(struct target_s *target, u32 address, u32 *value)
{
u8 value_buf[4];
if (!target->type->examined)
if (!target_was_examined(target))
{
LOG_ERROR("Target not examined yet");
return ERROR_FAIL;
@ -1233,7 +1249,7 @@ int target_read_u32(struct target_s *target, u32 address, u32 *value)
int target_read_u16(struct target_s *target, u32 address, u16 *value)
{
u8 value_buf[2];
if (!target->type->examined)
if (!target_was_examined(target))
{
LOG_ERROR("Target not examined yet");
return ERROR_FAIL;
@ -1258,7 +1274,7 @@ int target_read_u16(struct target_s *target, u32 address, u16 *value)
int target_read_u8(struct target_s *target, u32 address, u8 *value)
{
int retval = target_read_memory(target, address, 1, 1, value);
if (!target->type->examined)
if (!target_was_examined(target))
{
LOG_ERROR("Target not examined yet");
return ERROR_FAIL;
@ -1281,7 +1297,7 @@ int target_write_u32(struct target_s *target, u32 address, u32 value)
{
int retval;
u8 value_buf[4];
if (!target->type->examined)
if (!target_was_examined(target))
{
LOG_ERROR("Target not examined yet");
return ERROR_FAIL;
@ -1302,7 +1318,7 @@ int target_write_u16(struct target_s *target, u32 address, u16 value)
{
int retval;
u8 value_buf[2];
if (!target->type->examined)
if (!target_was_examined(target))
{
LOG_ERROR("Target not examined yet");
return ERROR_FAIL;
@ -1322,7 +1338,7 @@ int target_write_u16(struct target_s *target, u32 address, u16 value)
int target_write_u8(struct target_s *target, u32 address, u8 value)
{
int retval;
if (!target->type->examined)
if (!target_was_examined(target))
{
LOG_ERROR("Target not examined yet");
return ERROR_FAIL;
@ -3682,7 +3698,7 @@ static int tcl_target_func( Jim_Interp *interp, int argc, Jim_Obj *const *argv )
Jim_WrongNumArgs( goi.interp, 2, argv, "[no parameters]");
return JIM_ERR;
}
if( !(target->type->examined) ){
if( !(target_was_examined(target)) ){
e = ERROR_TARGET_NOT_EXAMINED;
} else {
e = target->type->poll( target );

View File

@ -109,6 +109,12 @@ typedef struct target_type_s
{
char *name;
/**
* Indicates whether this target has been examined.
*
* Do @b not access this field directly, use target_was_examined()
* target_set_examined(), and target_reset_examined().
*/
int examined;
/* poll current target status */
@ -383,6 +389,13 @@ extern target_t* get_current_target(struct command_context_s *cmd_ctx);
extern int get_num_by_target(target_t *query_target);
extern target_t *get_target(const char *id);
/// @returns @c true if the target has been examined.
extern bool target_was_examined(struct target_s *target);
/// Sets the @c examined flag for the given target.
extern void target_set_examined(struct target_s *target);
/// Reset the @c examined flag for the given target.
extern void target_reset_examined(struct target_s *target);
/**
* Run an algorithm on the @a target given.
*