Added target.c for common target routines.
This commit is contained in:
parent
8872315e82
commit
a16123997b
|
@ -30,6 +30,7 @@ SRC = gdb_if.c \
|
|||
stm32f4.c \
|
||||
crc32.c \
|
||||
sam3x.c \
|
||||
target.c \
|
||||
|
||||
include $(PLATFORM_DIR)/Makefile.inc
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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();
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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));
|
||||
|
|
|
@ -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)); \
|
||||
|
|
|
@ -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)); \
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
Loading…
Reference in New Issue