]> git.sur5r.net Git - openocd/commitdiff
Add wrappers for target->type->examined:
authorzwelch <zwelch@b42882b7-edfa-0310-969c-e2dbd0fdcd60>
Sun, 31 May 2009 09:38:43 +0000 (09:38 +0000)
committerzwelch <zwelch@b42882b7-edfa-0310-969c-e2dbd0fdcd60>
Sun, 31 May 2009 09:38:43 +0000 (09:38 +0000)
- 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

src/target/arm11.c
src/target/arm7_9_common.c
src/target/arm7tdmi.c
src/target/arm9tdmi.c
src/target/cortex_a8.c
src/target/cortex_m3.c
src/target/mips32.c
src/target/mips_m4k.c
src/target/target.c
src/target/target.h

index 45deb60c5ec2d5a99e636249ec87061b09c97df2..0dc6bf4761607a23e8356cb8030eda8c7e8622b3 100644 (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;
 }
index 0d202d1ae46124bcb46e0599582f18389149c819..f6f277102fb63d0e8fc139a38940c10fd506563c 100644 (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;
index 93281ce58c12e9cdad3828ab81bb44552dfd54d2..93d053cf89cda01ae16905a0635931b6108b621e 100644 (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;
index 4bcffd07b2c352b8e2b465b0820f8b2e12536066..93b2d66c2d2b7b24552c96443dc5e1264172b6b8 100644 (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;
index 1e36f336bbc25bef5b76057b4b3ec20f33011306..e02545fb2759633ae544bf7af1baa7741797b06f 100644 (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;
index ab217f98a90588424bb9a593677099f6c8b3f112..8a5983be00a3649bfbb7db13c37e5fe789385f1c 100644 (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;
index 084e627681025702f8c29a29dbbf07547ed6868c..9eb7b0c9a23ffa22766842446851ee2024bf6b34 100644 (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;
index e9fcf43d1a8dfa9fba77e139e744b83f1e09e667..539cc56bd8ecffa532d9627ce119473476e9af83 100644 (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;
index 71eb9d2b104f4c67348f4daea369df7cb9c333ba..2209612cf180a2ef03c26b2560604a173d2653f2 100644 (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 );
index c319a25b2ea728a3656378918af7cba28be82e32..662c95b943ccb14884af3a0b3deb88ce64ce4902 100644 (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.
  *