aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGareth McMullin2012-06-24 16:53:13 +1200
committerGareth McMullin2012-06-24 19:08:49 +1200
commita16123997b77a5d3a137fcd80e6bf4134b7a4a23 (patch)
treefdef5d9e21fca06a0b9d06764d4c8545d78842f4
parent8872315e82c6ab92864020f2a05490c5f6df91cd (diff)
Added target.c for common target routines.
-rw-r--r--src/Makefile1
-rw-r--r--src/adiv5.c9
-rw-r--r--src/adiv5_swdp.c2
-rw-r--r--src/arm7tdmi.c5
-rw-r--r--src/include/target.h20
-rw-r--r--src/jtag_scan.c2
-rw-r--r--src/platforms/native/platform.h2
-rw-r--r--src/platforms/stlink/platform.h2
-rw-r--r--src/target.c48
9 files changed, 62 insertions, 29 deletions
diff --git a/src/Makefile b/src/Makefile
index 4f6dda5..b0933ec 100644
--- a/src/Makefile
+++ b/src/Makefile
@@ -30,6 +30,7 @@ SRC = gdb_if.c \
stm32f4.c \
crc32.c \
sam3x.c \
+ target.c \
include $(PLATFORM_DIR)/Makefile.inc
diff --git a/src/adiv5.c b/src/adiv5.c
index ee9ef56..a37afa1 100644
--- a/src/adiv5.c
+++ b/src/adiv5.c
@@ -40,11 +40,6 @@
#define DO_RESET_SEQ 0
#endif
-/* This belongs elsewhere... */
-target *target_list = NULL;
-target *cur_target = NULL;
-target *last_target = NULL;
-
static const char adiv5_driver_str[] = "ARM ADIv5 MEM-AP";
ADIv5_DP_t *adiv5_dp_list;
@@ -130,9 +125,7 @@ void adiv5_dp_init(ADIv5_DP_t *dp)
/* Should probe further here... */
/* Prepend to target list... */
- t = (void*)calloc(1, sizeof(struct target_ap_s));
- t->next = target_list;
- target_list = t;
+ t = target_new(sizeof(struct target_ap_s));
((struct target_ap_s *)t)->ap = ap;
t->driver = adiv5_driver_str;
diff --git a/src/adiv5_swdp.c b/src/adiv5_swdp.c
index ce19753..f1e4bf4 100644
--- a/src/adiv5_swdp.c
+++ b/src/adiv5_swdp.c
@@ -50,7 +50,7 @@ int adiv5_swdp_scan(void)
ADIv5_DP_t *dp;
uint8_t ack;
- TARGET_LIST_FREE();
+ target_list_free();
#warning "These should be elsewhere!"
adiv5_free_all();
diff --git a/src/arm7tdmi.c b/src/arm7tdmi.c
index f588160..e5f7acb 100644
--- a/src/arm7tdmi.c
+++ b/src/arm7tdmi.c
@@ -117,7 +117,7 @@ static void arm7_halt_resume(struct target_s *target, uint8_t step);
void arm7tdmi_jtag_handler(jtag_dev_t *dev)
{
- struct target_arm7_s *tj = calloc(1, sizeof(*tj));
+ struct target_arm7_s *tj = (void*)target_new(sizeof(*tj));
target *t = (target *)tj;
t->driver = arm7_driver_str;
@@ -143,9 +143,6 @@ void arm7tdmi_jtag_handler(jtag_dev_t *dev)
/* TODO: Breakpoint and watchpoint functions. */
/* TODO: Fault unwinder. */
/* TODO: Memory map / Flash programming. */
-
- t->next = target_list;
- target_list = t;
}
static void arm7_select_scanchain(struct target_arm7_s *target, uint8_t chain)
diff --git a/src/include/target.h b/src/include/target.h
index 37a712a..5f3a5ab 100644
--- a/src/include/target.h
+++ b/src/include/target.h
@@ -25,6 +25,11 @@
#ifndef __TARGET_H
#define __TARGET_H
+typedef struct target_s target;
+
+target *target_new(unsigned size);
+void target_list_free(void);
+
/* Halt/resume functions */
#define target_attach(target) \
(target)->attach(target)
@@ -106,18 +111,7 @@
#define target_flash_write(target, dest, src, len) \
(target)->flash_write((target), (dest), (src), (len))
-
-#define TARGET_LIST_FREE() { \
- while(target_list) { \
- target *t = target_list->next; \
- free(target_list); \
- target_list = t; \
- } \
- last_target = cur_target = NULL; \
-}
-
-
-typedef struct target_s {
+struct target_s {
/* Attach/Detach funcitons */
void (*attach)(struct target_s *target);
void (*detach)(struct target_s *target);
@@ -173,7 +167,7 @@ typedef struct target_s {
int size;
struct target_s *next;
-} target;
+};
extern target *target_list, *cur_target, *last_target;
diff --git a/src/jtag_scan.c b/src/jtag_scan.c
index a2b8029..df0579f 100644
--- a/src/jtag_scan.c
+++ b/src/jtag_scan.c
@@ -102,7 +102,7 @@ int jtag_scan(void)
int i;
uint32_t j;
- TARGET_LIST_FREE();
+ target_list_free();
jtag_dev_count = 0;
memset(&jtag_devs, 0, sizeof(jtag_devs));
diff --git a/src/platforms/native/platform.h b/src/platforms/native/platform.h
index 1f4416d..2258434 100644
--- a/src/platforms/native/platform.h
+++ b/src/platforms/native/platform.h
@@ -126,7 +126,7 @@ extern const char *morse_msg;
if(running_status) gdb_putpacketz("X1D"); \
else gdb_putpacketz("EFF"); \
running_status = 0; \
- TARGET_LIST_FREE(); \
+ target_list_free(); \
cur_target = last_target = NULL; \
morse("TARGET LOST.", 1); \
longjmp(fatal_error_jmpbuf, (error)); \
diff --git a/src/platforms/stlink/platform.h b/src/platforms/stlink/platform.h
index bef7cde..85f8f7a 100644
--- a/src/platforms/stlink/platform.h
+++ b/src/platforms/stlink/platform.h
@@ -98,7 +98,7 @@ extern const char *morse_msg;
if(running_status) gdb_putpacketz("X1D"); \
else gdb_putpacketz("EFF"); \
running_status = 0; \
- TARGET_LIST_FREE(); \
+ target_list_free(); \
cur_target = last_target = NULL; \
longjmp(fatal_error_jmpbuf, (error)); \
}
diff --git a/src/target.c b/src/target.c
new file mode 100644
index 0000000..1c70340
--- /dev/null
+++ b/src/target.c
@@ -0,0 +1,48 @@
+/*
+ * This file is part of the Black Magic Debug project.
+ *
+ * Copyright (C) 2012 Black Sphere Technologies Ltd.
+ * Written by Gareth McMullin <gareth@blacksphere.co.nz>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "general.h"
+#include "target.h"
+
+#include <stdlib.h>
+
+target *target_list = NULL;
+target *cur_target = NULL;
+target *last_target = NULL;
+
+target *target_new(unsigned size)
+{
+ target *t = (void*)calloc(1, size);
+ t->next = target_list;
+ target_list = t;
+
+ return t;
+}
+
+void target_list_free(void)
+{
+ while(target_list) {
+ target *t = target_list->next;
+ free(target_list);
+ target_list = t;
+ }
+ last_target = cur_target = NULL;
+}
+