From bb46bd958ed2efa013473b7c7522b0243650b3b1 Mon Sep 17 00:00:00 2001 From: Daniel Beer Date: Wed, 19 May 2010 11:08:41 +1200 Subject: [PATCH] Implemented FET message database. --- Makefile | 2 +- fet_db.c | 349 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ fet_db.h | 55 +++++++++ 3 files changed, 405 insertions(+), 1 deletion(-) create mode 100644 fet_db.c create mode 100644 fet_db.h diff --git a/Makefile b/Makefile index 603b311..d8a1390 100644 --- a/Makefile +++ b/Makefile @@ -43,7 +43,7 @@ install: mspdebug mspdebug.man mspdebug: main.o fet.o rf2500.o dis.o uif.o ihex.o elf32.o stab.o util.o \ bsl.o sim.o symmap.o gdb.o btree.o device.o rtools.o sym.o devcmd.o \ - cproc.o vector.o cproc_util.o expr.o fet_error.o binfile.o + cproc.o vector.o cproc_util.o expr.o fet_error.o binfile.o fet_db.o $(CC) $(LDFLAGS) -o $@ $^ -lusb $(READLINE_LIBS) .c.o: diff --git a/fet_db.c b/fet_db.c new file mode 100644 index 0000000..3954975 --- /dev/null +++ b/fet_db.c @@ -0,0 +1,349 @@ +/* MSPDebug - debugging tool for MSP430 MCUs + * Copyright (C) 2009, 2010 Daniel Beer + * + * 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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include +#include "fet_db.h" +#include "util.h" + +static const struct fet_db_record fet_db[] = { + { + .name = "MSP430F147", + .msg28_data = { + 0xf1, 0x49, 0x00, 0x43, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x01, 0x10, 0x00, 0x00, 0xf0, 0x1a, + 0x12, 0x00 + }, + .msg29_params = {0x00, 0x05, 0x05}, + .msg29_data = { + 0x00, 0x80, 0xff, 0xff, 0x00, 0x00, 0x00, 0x10, + 0xff, 0x10, 0x80, 0x00, 0x00, 0x02, 0xff, 0x05, + 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x02, 0x00, + 0x00, 0x00, 0xd7, 0x60, 0x00, 0x00, 0x00, 0x00, + 0x08, 0x07, 0x10, 0x0e, 0xc4, 0x09, 0x70, 0x17, + 0x58, 0x1b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0xf3, 0x30, 0xd3, 0x30, + 0xc0, 0x30, + }, + .msg2b_data = { + 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, + }, + }, + { + .name = "MSP430F148", + .msg28_data = { + 0xf1, 0x49, 0x00, 0x60, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x01, 0x10, 0x00, 0x00, 0xf0, 0x39, + 0x11, 0x00 + }, + .msg29_params = {0x00, 0x06, 0x06}, + .msg29_data = { + 0x00, 0x40, 0xff, 0xff, 0x00, 0x00, 0x00, 0x10, + 0xff, 0x10, 0x80, 0x00, 0x00, 0x02, 0xff, 0x09, + 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x02, 0x00, + 0x00, 0x00, 0xd7, 0x60, 0x00, 0x00, 0x00, 0x00, + 0x08, 0x07, 0x10, 0x0e, 0xc4, 0x09, 0x70, 0x17, + 0x58, 0x1b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0xf3, 0x30, 0xd3, 0x30, + 0xc0, 0x30 + }, + .msg2b_data = { + 0x00, 0x0c, 0xff, 0x0f, 0x00, 0x02, 0x00, 0x00, + 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, + } + }, + { + .name = "MSP430F149", + .msg28_data = { + 0xF1, 0x49, 0x00, 0x43, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x01, 0x10, 0x00, 0x00, 0xF0, 0x1A, + 0x10, 0x00 + }, + .msg29_params = {0x00, 0x07, 0x07}, + .msg29_data = { + 0x00, 0x11, 0xff, 0xff, 0x00, 0x00, 0x00, 0x10, + 0xff, 0x10, 0x80, 0x00, 0x00, 0x02, 0xff, 0x09, + 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x02, 0x00, + 0x00, 0x00, 0xd7, 0x60, 0x00, 0x00, 0x00, 0x00, + 0x08, 0x07, 0x10, 0x0e, 0xc4, 0x09, 0x70, 0x17, + 0x58, 0x1b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0xf3, 0x30, 0xd3, 0x30, + 0xc0, 0x30 + }, + .msg2b_data = { + 0x00, 0x0c, 0xff, 0x0f, 0x00, 0x02, 0x00, 0x00, + 0x03, 0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00 + }, + }, + { + .name = "MSP430F1611", + .msg28_data = { + 0xF1, 0x6C, 0x20, 0x40, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x01, 0x61, 0x01, 0x00, 0xD1, 0x4D, + 0x80, 0x00 + }, + .msg29_params = {0x00, 0x2a, 0x23}, + .msg29_data = { + 0x00, 0x40, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x10, + 0xFF, 0x10, 0x80, 0x00, 0x00, 0x02, 0xFF, 0x09, + 0x00, 0x11, 0xFF, 0x38, 0x08, 0x00, 0x03, 0x00, + 0x02, 0x00, 0xD7, 0x60, 0x00, 0x00, 0x00, 0x00, + 0x08, 0x07, 0x10, 0x0E, 0xC4, 0x09, 0x70, 0x17, + 0x58, 0x1B, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0xF3, 0x30, 0xD3, 0x30, + 0xC0, 0x30 + }, + .msg2b_data = { + 0x00, 0x0C, 0xFF, 0x0F, 0x00, 0x02, 0x02, 0x00, + 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00 + } + }, + { + .name = "MSP430F249", + .msg28_data = { + 0xF2, 0x49, 0x02, 0x60, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x02, 0x02, 0x01, 0x00, 0xF3, 0x2B, + 0x80, 0x00 + }, + .msg29_params = {0x00, 0x4f, 0x47}, + .msg29_data = { + 0x00, 0x11, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x10, + 0xFF, 0x10, 0x40, 0x00, 0x00, 0x02, 0xFF, 0x09, + 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x02, 0x00, + 0x02, 0x00, 0xD7, 0x60, 0x00, 0x00, 0x00, 0x00, + 0x08, 0x07, 0x10, 0x0E, 0xC4, 0x09, 0x70, 0x17, + 0x58, 0x1B, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, + 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x33, 0x0F, 0x1F, 0x0F, + 0xFF, 0xFF + }, + .msg2b_data = { + 0x00, 0x0C, 0xFF, 0x0F, 0x00, 0x02, 0x00, 0x00, + 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00 + } + }, + { + .name = "MSP430F2616", + .msg28_data = { + 0xf2, 0x6f, 0x04, 0x60, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x02, 0x12, 0x01, 0x00, 0xf5, 0x1d, + 0x88, 0x00 + }, + .msg29_params = {0x00, 0x41, 0x39}, + .msg29_data = { + 0x00, 0x21, 0xff, 0xff, 0x01, 0x00, 0x00, 0x10, + 0xff, 0x10, 0x40, 0x00, 0x00, 0x02, 0xff, 0x09, + 0x00, 0x11, 0xff, 0x20, 0x08, 0x00, 0x03, 0x00, + 0x02, 0x00, 0xd7, 0x60, 0x00, 0x00, 0x00, 0x00, + 0x08, 0x07, 0x10, 0x0e, 0xc4, 0x09, 0x70, 0x17, + 0x58, 0x1b, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x01, 0x00, + 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x33, 0x0f, 0x1f, 0x0f, + 0xff, 0xff + }, + .msg2b_data = { + 0x00, 0x0c, 0xff, 0x0f, 0x00, 0x02, 0x02, 0x00, + 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00 + } + }, + { + .name = "MSP430F5437A", + .msg28_data = { + 0x04, 0x80, 0x11, 0x11, 0x08, 0x0a, 0x26, 0x87, + 0xb4, 0x46, 0x18, 0x0c, 0xec, 0x0f, 0xf8, 0xfe, + 0x30, 0x41 + }, + .msg29_params = {0x00, 0x5c, 0x54}, + .msg29_data = { + 0x00, 0x5c, 0xff, 0x5b, 0x04, 0x00, 0x00, 0x18, + 0xff, 0x19, 0x80, 0x00, 0x00, 0x1c, 0xff, 0x5b, + 0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x03, 0x00, + 0x02, 0x00, 0x0f, 0x04, 0x00, 0x00, 0x00, 0x00, + 0x08, 0x07, 0x10, 0x0e, 0xc4, 0x09, 0x70, 0x17, + 0x58, 0x1b, 0x01, 0x00, 0x03, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x01, 0x00, + 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, + 0xff, 0xff + }, + .msg2b_data = { + 0x00, 0x10, 0xff, 0x17, 0x00, 0x02, 0x02, 0x00, + 0x0a, 0x00, 0x40, 0x00, 0x0a, 0x91, 0x8e, 0x9d, + 0x00, 0x00, 0x28, 0x29, 0x2a, 0x2b, 0x80, 0xd8, + 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00 + }, + }, + { + .name = "MSP430F5438", + .msg28_data = { + 0x54, 0x38, 0x10, 0x10, 0x08, 0x0a, 0x03, 0x05, + 0xca, 0x47, 0x1a, 0x00, 0x19, 0x00, 0xf8, 0xfe, + 0x00, 0x00, + }, + .msg29_params = {0x00, 0x5c, 0x54}, + .msg29_data = { + 0x00, 0x5c, 0xff, 0x5b, 0x04, 0x00, 0x00, 0x18, + 0xff, 0x19, 0x80, 0x00, 0x00, 0x1c, 0xff, 0x5b, + 0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x03, 0x00, + 0x02, 0x00, 0x17, 0x04, 0x00, 0x00, 0x00, 0x00, + 0x08, 0x07, 0x10, 0x0e, 0xc4, 0x09, 0x70, 0x17, + 0x58, 0x1b, 0x01, 0x00, 0x03, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x01, 0x00, + 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, + 0xff, 0xff + }, + .msg2b_data = { + 0x00, 0x10, 0xff, 0x17, 0x00, 0x02, 0x02, 0x00, + 0x0a, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00 + } + } +}; + +const struct fet_db_record *fet_db_find_by_msg28(uint8_t *data, int len) +{ + int i; + int best_score = 0; + int best = -1; + + if (len < 2) + return NULL; + + if (len > FET_DB_MSG28_LEN) + len = FET_DB_MSG28_LEN; + + for (i = 0; i < ARRAY_LEN(fet_db); i++) { + const struct fet_db_record *r = &fet_db[i]; + + if (r->msg28_data[0] == data[0] && + r->msg28_data[1] == data[1]) { + int score = 0; + int j; + + for (j = 0; j < len; j++) + if (r->msg28_data[j] == data[j]) + score++; + + if (best < 0 || score > best_score) { + best = i; + best_score = score; + } + } + } + + if (best) + return &fet_db[best]; + + return NULL; +} + +const struct fet_db_record *fet_db_find_by_name(const char *name) +{ + int i; + + for (i = 0; i < ARRAY_LEN(fet_db); i++) { + const struct fet_db_record *r = &fet_db[i]; + + if (!strcasecmp(r->name, name)) + return r; + } + + return NULL; +} + +int fet_db_enum(fet_db_enum_func_t func, void *user_data) +{ + int i; + + for (i = 0; i < ARRAY_LEN(fet_db); i++) + if (func(user_data, &fet_db[i]) < 0) + return -1; + + return 0; +} diff --git a/fet_db.h b/fet_db.h new file mode 100644 index 0000000..c535b4a --- /dev/null +++ b/fet_db.h @@ -0,0 +1,55 @@ +/* MSPDebug - debugging tool for MSP430 MCUs + * Copyright (C) 2009, 2010 Daniel Beer + * + * 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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#ifndef FET_DB_H_ +#define FET_DB_H_ + +#include + +#define FET_DB_MSG28_LEN 0x12 +#define FET_DB_MSG29_PARAMS 3 +#define FET_DB_MSG29_LEN 0x4a +#define FET_DB_MSG2B_LEN 0x4a + +struct fet_db_record { + const char *name; + + uint8_t msg28_data[FET_DB_MSG28_LEN]; + int msg29_params[FET_DB_MSG29_PARAMS]; + uint8_t msg29_data[FET_DB_MSG29_LEN]; + uint8_t msg2b_data[FET_DB_MSG2B_LEN]; +}; + +/* Find a record in the database by its response to message 0x28. The + * first two bytes _must_ match, and the remaining bytes should match + * as much as possible. + */ +const struct fet_db_record *fet_db_find_by_msg28(uint8_t *data, int len); + +/* Find a record in the database by name. The search is case-insensitive. + */ +const struct fet_db_record *fet_db_find_by_name(const char *name); + +/* Call the given enumeration function for all records in the database. + */ +typedef int (*fet_db_enum_func_t)(void *user_data, + const struct fet_db_record *rec); + +int fet_db_enum(fet_db_enum_func_t func, void *user_data); + +#endif