diff --git a/jtag/src/Makefile.am b/jtag/src/Makefile.am index 10dc0fbc..2084121e 100644 --- a/jtag/src/Makefile.am +++ b/jtag/src/Makefile.am @@ -27,7 +27,7 @@ SUBDIRS = \ bin_PROGRAMS = jtag -jtag_SOURCES = jtag.c detect.c readmem.c detect.h pxa250.c pxa250.h sa1110.c sa1110.h flash.c +jtag_SOURCES = jtag.c detect.c readmem.c detect.h bus.h pxa250.c sa1110.c flash.c jtag_DEPENDENCIES = tap/libtap.a part/libpart.a diff --git a/jtag/src/pxa250.h b/jtag/src/bus.h similarity index 56% rename from jtag/src/pxa250.h rename to jtag/src/bus.h index 9a08dc9f..73e5931c 100644 --- a/jtag/src/pxa250.h +++ b/jtag/src/bus.h @@ -1,6 +1,7 @@ /* * $Id$ * + * Bus driver interface * Copyright (C) 2002 ETC s.r.o. * * This program is free software; you can redistribute it and/or @@ -22,17 +23,28 @@ * */ -#ifndef PXA250_H -#define PXA250_H +#ifndef BUS_H +#define BUS_H #include - #include "part.h" -void pxa250_bus_read_start( parts *ps, uint32_t adr ); -uint32_t pxa250_bus_read_next( parts *ps, uint32_t adr ); -uint32_t pxa250_bus_read_end( parts *ps ); -uint32_t pxa250_bus_read( parts *ps, uint32_t adr ); -void pxa250_bus_write( parts *ps, uint32_t adr, uint32_t data ); +typedef struct { + void (*bus_read_start)( parts *, uint32_t ); + uint32_t (*bus_read_next)( parts *, uint32_t ); + uint32_t (*bus_read_end)( parts * ); + uint32_t (*bus_read)( parts *, uint32_t ); + void (*bus_write)( parts *, uint32_t, uint32_t ); +} bus_driver_t; + +extern bus_driver_t *bus_driver; +#define bus_read_start bus_driver->bus_read_start +#define bus_read_next bus_driver->bus_read_next +#define bus_read_end bus_driver->bus_read_end +#define bus_read bus_driver->bus_read +#define bus_write bus_driver->bus_write + +extern bus_driver_t sa1110_bus_driver; +extern bus_driver_t pxa250_bus_driver; -#endif /* PXA250_H */ +#endif /* BUS_H */ diff --git a/jtag/src/flash.c b/jtag/src/flash.c index 13dbcc42..b9659219 100644 --- a/jtag/src/flash.c +++ b/jtag/src/flash.c @@ -36,15 +36,7 @@ #include #include "part.h" - -#include "sa1110.h" -#include "pxa250.h" - -void (*bus_read_start)( parts *, uint32_t ); -uint32_t (*bus_read_next)( parts *, uint32_t ); -uint32_t (*bus_read_end)( parts * ); -uint32_t (*bus_read)( parts *, uint32_t ); -void (*bus_write)( parts *, uint32_t, uint32_t ); +#include "bus.h" int flash_erase_block( parts *ps, uint32_t adr ); int flash_unlock_block( parts *ps, uint32_t adr ); @@ -67,20 +59,12 @@ flashmem( parts *ps, FILE *f ) if (strcmp( p->part, "SA1110" ) == 0) { printf( "SA1110 detected\n" ); d = D_SA1110; - bus_read_start = sa1110_bus_read_start; - bus_read_next = sa1110_bus_read_next; - bus_read_end = sa1110_bus_read_end; - bus_read = sa1110_bus_read; - bus_write = sa1110_bus_write; + bus_driver = &sa1110_bus_driver; } if (strcmp( p->part, "PXA250" ) == 0) { printf( "PXA250 detected\n" ); d = D_PXA250; - bus_read_start = pxa250_bus_read_start; - bus_read_next = pxa250_bus_read_next; - bus_read_end = pxa250_bus_read_end; - bus_read = pxa250_bus_read; - bus_write = pxa250_bus_write; + bus_driver = &pxa250_bus_driver; } if (!d) { diff --git a/jtag/src/pxa250.c b/jtag/src/pxa250.c index b54e6e93..2b9c0c82 100644 --- a/jtag/src/pxa250.c +++ b/jtag/src/pxa250.c @@ -25,8 +25,7 @@ #include #include "part.h" - -#include "pxa250.h" +#include "bus.h" /* PXA250 must be at position 0 in JTAG chain */ @@ -170,3 +169,11 @@ pxa250_bus_write( parts *ps, uint32_t adr, uint32_t data ) part_set_signal( p, "nWE", 1, 1 ); parts_shift_data_registers( ps ); } + +bus_driver_t pxa250_bus_driver = { + pxa250_bus_read_start, + pxa250_bus_read_next, + pxa250_bus_read_end, + pxa250_bus_read, + pxa250_bus_write +}; diff --git a/jtag/src/readmem.c b/jtag/src/readmem.c index 804edfca..3e42e76c 100644 --- a/jtag/src/readmem.c +++ b/jtag/src/readmem.c @@ -38,15 +38,9 @@ #include #include "part.h" +#include "bus.h" -#include "sa1110.h" -#include "pxa250.h" - -void (*bus_read_start)( parts *, uint32_t ); -uint32_t (*bus_read_next)( parts *, uint32_t ); -uint32_t (*bus_read_end)( parts * ); -uint32_t (*bus_read)( parts *, uint32_t ); -void (*bus_write)( parts *, uint32_t, uint32_t ); +bus_driver_t *bus_driver = NULL; void readmem( parts *ps ) @@ -61,20 +55,12 @@ readmem( parts *ps ) if (strcmp( p->part, "SA1110" ) == 0) { printf( "SA1110 detected\n" ); d = D_SA1110; - bus_read_start = sa1110_bus_read_start; - bus_read_next = sa1110_bus_read_next; - bus_read_end = sa1110_bus_read_end; - bus_read = sa1110_bus_read; - bus_write = sa1110_bus_write; + bus_driver = &sa1110_bus_driver; } if (strcmp( p->part, "PXA250" ) == 0) { printf( "PXA250 detected\n" ); d = D_PXA250; - bus_read_start = pxa250_bus_read_start; - bus_read_next = pxa250_bus_read_next; - bus_read_end = pxa250_bus_read_end; - bus_read = pxa250_bus_read; - bus_write = pxa250_bus_write; + bus_driver = &pxa250_bus_driver; } if (!d) { diff --git a/jtag/src/sa1110.c b/jtag/src/sa1110.c index 380a9872..28505274 100644 --- a/jtag/src/sa1110.c +++ b/jtag/src/sa1110.c @@ -25,8 +25,7 @@ #include #include "part.h" - -#include "sa1110.h" +#include "bus.h" /* SA1110 must be at position 0 in JTAG chain */ @@ -168,3 +167,11 @@ sa1110_bus_write( parts *ps, uint32_t adr, uint32_t data ) part_set_signal( p, "nWE", 1, 1 ); parts_shift_data_registers( ps ); } + +bus_driver_t sa1110_bus_driver = { + sa1110_bus_read_start, + sa1110_bus_read_next, + sa1110_bus_read_end, + sa1110_bus_read, + sa1110_bus_write +}; diff --git a/jtag/src/sa1110.h b/jtag/src/sa1110.h deleted file mode 100644 index 45766171..00000000 --- a/jtag/src/sa1110.h +++ /dev/null @@ -1,38 +0,0 @@ -/* - * $Id$ - * - * Copyright (C) 2002 ETC s.r.o. - * - * 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 2 - * 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, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA - * 02111-1307, USA. - * - * Written by Marcel Telka , 2002. - * - */ - -#ifndef SA1110_H -#define SA1110_H - -#include - -#include "part.h" - -void sa1110_bus_read_start( parts *ps, uint32_t adr ); -uint32_t sa1110_bus_read_next( parts *ps, uint32_t adr ); -uint32_t sa1110_bus_read_end( parts *ps ); -uint32_t sa1110_bus_read( parts *ps, uint32_t adr ); -void sa1110_bus_write( parts *ps, uint32_t adr, uint32_t data ); - -#endif /* SA1110_H */