Use fet_db to find magic messages.

This commit is contained in:
Daniel Beer 2010-05-19 11:29:16 +12:00
parent 7e3109e4c8
commit d69b48bd89
1 changed files with 29 additions and 143 deletions

172
fet.c
View File

@ -30,6 +30,7 @@
#include "util.h"
#include "fet.h"
#include "fet_error.h"
#include "fet_db.h"
#define MAX_PARAMS 16
@ -456,9 +457,9 @@ static int xfer(struct fet_device *dev,
static int do_identify(struct fet_device *dev)
{
char idtext[64];
if (dev->version < 20300000) {
char idtext[64];
if (xfer(dev, C_IDENTIFY, NULL, 0, 2, 70, 0) < 0)
return -1;
@ -469,8 +470,10 @@ static int do_identify(struct fet_device *dev)
memcpy(idtext, dev->fet_reply.data + 4, 32);
idtext[32] = 0;
printf("Device: %s\n", idtext);
} else {
uint16_t id;
const struct fet_db_record *r;
if (xfer(dev, 0x28, NULL, 0, 2, 0, 0) < 0) {
fprintf(stderr, "fet: command 0x28 failed\n");
@ -482,14 +485,32 @@ static int do_identify(struct fet_device *dev)
return -1;
}
id = (dev->fet_reply.data[0] << 8) | dev->fet_reply.data[1];
if (device_id_text(id, idtext, sizeof(idtext)) < 0) {
printf("Unknown device ID: 0x%04x\n", id);
return 0;
printf("Device ID: 0x%02x%02x\n",
dev->fet_reply.data[0], dev->fet_reply.data[1]);
r = fet_db_find_by_msg28(dev->fet_reply.data,
dev->fet_reply.datalen);
printf("Device: %s\n", r->name);
if (!r) {
fprintf(stderr, "fet: unknown device\n");
return -1;
}
if (xfer(dev, 0x2b, r->msg2b_data, FET_DB_MSG2B_LEN, 0) < 0) {
fprintf(stderr, "fet: message 0x2b failed\n");
return -1;
}
if (xfer(dev, 0x29, r->msg29_data, FET_DB_MSG29_LEN,
3, r->msg29_params[0], r->msg29_params[1],
r->msg29_params[2]) < 0) {
fprintf(stderr, "fet: message 0x29 failed\n");
return -1;
}
}
printf("Device: %s\n", idtext);
return 0;
}
@ -722,135 +743,6 @@ static int fet_breakpoint(device_t dev_base, int enabled, uint16_t addr)
return 0;
}
#define MAGIC_DATA_SIZE 0x4a
#define MAGIC_PARAM_COUNT 3
#define MAGIC_SEND_29 0x01
#define MAGIC_SEND_2B 0x02
struct magic_record {
int min_version;
int flags;
uint32_t param_29[MAGIC_PARAM_COUNT];
const uint8_t data_29[MAGIC_DATA_SIZE];
const uint8_t data_2b[MAGIC_DATA_SIZE];
};
/* The first entry in this table whose version exceeds the version
* reported by the FET is used. Therefore, it must be kept in descending
* order of version.
*/
const static struct magic_record magic_table[] = {
{ /* TI Chronos */
.min_version = 30001000,
.flags = MAGIC_SEND_29 | MAGIC_SEND_2B,
.param_29 = {0x77, 0x6f, 0x4a},
.data_29 = {
0x00, 0x80, 0xff, 0xff, 0x00, 0x00, 0x00, 0x18,
0xff, 0x19, 0x80, 0x00, 0x00, 0x1c, 0xff, 0x2b,
0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x02, 0x00,
0x02, 0x00, 0x07, 0x24, 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
},
.data_2b = {
0x00, 0x10, 0xff, 0x17, 0x00, 0x02, 0x01, 0x00,
0x04, 0x00, 0x40, 0x00, 0x0a, 0x91, 0x8e, 0x00,
0x00, 0xb0, 0x28, 0x29, 0x2a, 0x2b, 0x80, 0xd8,
0xa8, 0x60, 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
}
},
{ /* RF2500 */
.min_version = 30000000,
.flags = MAGIC_SEND_29,
.param_29 = {0, 0x39, 0x31},
.data_29 = {
0x00, 0x80, 0xff, 0xff, 0x00, 0x00, 0x00, 0x10,
0xff, 0x10, 0x40, 0x00, 0x00, 0x02, 0xff, 0x05,
0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x01, 0x00,
0x01, 0x00, 0xd7, 0x60, 0x00, 0x00, 0x00, 0x00,
0x08, 0x07, 0x10, 0x0e, 0xc4, 0x09, 0x70, 0x17,
0x58, 0x1b, 0x01, 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
}
},
{ /* FET430UIF */
.min_version = 20404000,
.flags = MAGIC_SEND_29 | MAGIC_SEND_2B,
.param_29 = {0, 7, 7},
.data_29 = {
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
},
.data_2b = {
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
}
}
};
static int do_magic(struct fet_device *dev)
{
int i;
for (i = 0; i < ARRAY_LEN(magic_table); i++) {
const struct magic_record *r = &magic_table[i];
if (dev->version >= r->min_version) {
printf("Sending magic messages for >= %d\n",
r->min_version);
if ((r->flags & MAGIC_SEND_2B) &&
xfer(dev, 0x2b, r->data_2b,
MAGIC_DATA_SIZE, 0) < 0) {
fprintf(stderr, "fet: command 0x2b failed\n");
return -1;
}
if ((r->flags & MAGIC_SEND_29) &&
xfer(dev, 0x29, r->data_29, MAGIC_DATA_SIZE,
3, r->param_29[0], r->param_29[1],
r->param_29[2]) < 0) {
fprintf(stderr, "fet: command 0x29 failed\n");
return -1;
}
return 0;
}
}
return 0;
}
device_t fet_open(transport_t transport, int proto_flags, int vcc_mv)
{
struct fet_device *dev = malloc(sizeof(*dev));
@ -912,12 +804,6 @@ device_t fet_open(transport_t transport, int proto_flags, int vcc_mv)
goto fail;
}
/* Send the magic required by RF2500 and Chronos FETs */
if (do_magic(dev) < 0) {
fprintf(stderr, "fet: init magic failed\n");
goto fail;
}
return (device_t)dev;
fail: